Index: trunk/minix/commands/Makefile
===================================================================
--- trunk/minix/commands/Makefile	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-# Makefile for commands.
-
-MAKE	= exec make -$(MAKEFLAGS)
-BZIP2=bzip2-1.0.3
-
-SMALLPROGRAMS=`arch` aal advent ash autil awk bc byacc cawf cron de dhcpd dis88 elle elvis ftp ftpd200 httpd ibm indent m4 make mdb mined patch pax ps reboot rlogind scripts sh simple syslogd talk talkd telnet telnetd urlget yap zmodem
-
-usage:
-	@echo "Usage: make all          # Compile all commands" >&2
-	@echo "       make install      # Install the result (run as bin!)" >&2
-	@echo "       make clean        # Delete .o files and other junk" >&2
-	@echo "       make big          # Compile all big commands" >&2
-	@echo "       make biginstall   # Install all big commands" >&2
-	@echo "       make small        # Install all small commands" >&2
-	@echo "       make smallinstall # Install all small commands" >&2
-	@echo " "
-	@echo "big compiles the commands the require large compiler sizes."
-	@echo "small compiles the rest. all compiles all."
-	@false
-
-all: small big
-
-install: biginstall smallinstall
-
-big:
-	cd $(BZIP2) && /bin/sh build build
-
-biginstall: big
-	cd $(BZIP2) && make install
-
-clean::
-	cd $(BZIP2) && make clean
-	for p in $(SMALLPROGRAMS); do ( cd $$p && make clean ); done
-
-small::
-	set -e; for p in $(SMALLPROGRAMS); do ( cd $$p && make all ); done
-
-smallinstall::
-	set -e; for p in $(SMALLPROGRAMS); do ( cd $$p && make install ); done
-
Index: trunk/minix/commands/aal/Makefile
===================================================================
--- trunk/minix/commands/aal/Makefile	(revision 9)
+++ 	(revision )
@@ -1,56 +1,0 @@
-# Makefile for aal
-
-CC=exec cc
-CFLAGS=-I. -wo -DAAL -DSTB -DNDEBUG -DDISTRIBUTION -D_POSIX_SOURCE -D_MINIX
-LDFLAGS=-i
-
-all:	aal
-
-OFILES=	archiver.o \
-	print.o \
-	rd.o \
-	rd_arhdr.o \
-	rd_unsig2.o \
-	sprint.o \
-	wr_arhdr.o \
-	wr_bytes.o \
-	wr_int2.o \
-	wr_long.o \
-	wr_ranlib.o \
-	format.o \
-	rd_bytes.o \
-	system.o \
-	write.o \
-	long2str.o
-
-aal: $(OFILES)
-	$(CC) $(LDFLAGS) -o aal $(OFILES)
-	install -S 512k $@
-
-install:	/usr/bin/aal /usr/bin/ar
-
-/usr/bin/aal:	aal
-	install -cs -o bin aal $@
-
-/usr/bin/ar:	/usr/bin/aal
-	install -l $? $@
-
-archiver.o:
-print.o:
-rd.o:
-rd_arhdr.o:
-rd_unsig2.o:
-sprint.o:
-wr_arhdr.o:
-wr_bytes.o:
-wr_int2.o:
-wr_long.o:
-wr_ranlib.o:
-format.o:
-rd_bytes.o:
-system.o:
-write.o:
-long2str.o:
-
-clean:	
-	rm -f *.o core *.bak aal
Index: trunk/minix/commands/aal/arch.h
===================================================================
--- trunk/minix/commands/aal/arch.h	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/arch.h,v 1.1.1.1 2005/04/21 14:53:57 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-
-#ifndef __ARCH_H_INCLUDED
-#define __ARCH_H_INCLUDED
-
-#define	ARMAG	0177545
-#define AALMAG	0177454
-
-struct	ar_hdr {
-	char	ar_name[14];
-	long	ar_date;
-	char	ar_uid;
-	char	ar_gid;
-	short	ar_mode;
-	long	ar_size;
-};
-
-#define AR_TOTAL	26
-#define AR_SIZE		22
-
-#endif /* __ARCH_H_INCLUDED */
Index: trunk/minix/commands/aal/archiver.c
===================================================================
--- trunk/minix/commands/aal/archiver.c	(revision 9)
+++ 	(revision )
@@ -1,800 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* ar - archiver		Author: Michiel Huisjes */
-/* Made into arch/aal by Ceriel Jacobs
- */
-
-static char RcsId[] = "$Header: /cvsup/minix/src/commands/aal/archiver.c,v 1.1.1.1 2005/04/21 14:53:57 beng Exp $";
-
-/*
- * Usage: [arch|aal] [adprtvx] archive [file] ...
- *	  v: verbose
- *	  x: extract
- *	  a: append
- *	  r: replace (append when not in archive)
- *	  d: delete
- *	  t: print contents of archive
- *	  p: print named files
- *	  l: temporaries in current directory instead of /usr/tmp
- *	  c: don't give "create" message
- *	  u: replace only if dated later than member in archive
-#ifdef DISTRIBUTION
- *	  D: make distribution: use distr_time, uid=2, gid=2, mode=0644
-#endif
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifndef	S_IREAD
-#define	S_IREAD		S_IRUSR
-#endif
-#ifndef	S_IWRITE
-#define	S_IWRITE	S_IWUSR
-#endif
-#ifndef	S_IEXEC
-#define	S_IEXEC		S_IXUSR
-#endif
-#include <signal.h>
-#include <arch.h>
-#ifdef AAL
-#include <ranlib.h>
-#include <out.h>
-#define MAGIC_NUMBER	AALMAG
-long	offset;
-struct ranlib *tab;
-unsigned int	tnum = 0;
-char	*tstrtab;
-unsigned int	tssiz = 0;
-char	*malloc(), *realloc(), *strcpy(), *strncpy();
-long	time();
-unsigned int tabsz, strtabsz;
-#else
-#define MAGIC_NUMBER	ARMAG
-#endif
-long	lseek();
-
-#define odd(nr)		(nr & 01)
-#define even(nr)	(odd(nr) ? nr + 1 : nr)
-
-typedef char BOOL;
-#define FALSE		0
-#define TRUE		1
-
-#define READ		0
-#define APPEND		2
-#define CREATE		1
-
-#define MEMBER		struct ar_hdr
-
-#define NIL_PTR		((char *) 0)
-#define NIL_MEM		((MEMBER *) 0)
-#define NIL_LONG	((long *) 0)
-
-#define IO_SIZE		(10 * 1024)
-
-#define equal(str1, str2)	(!strncmp((str1), (str2), 14))
-#ifndef S_ISDIR
-#define S_ISDIR(m)	(m & S_IFDIR)		/* is a directory */
-#endif
-
-BOOL verbose;
-BOOL app_fl;
-BOOL ex_fl;
-BOOL show_fl;
-BOOL pr_fl;
-BOOL rep_fl;
-BOOL del_fl;
-BOOL nocr_fl;
-BOOL local_fl;
-BOOL update_fl;
-#ifdef DISTRIBUTION
-BOOL distr_fl;
-long distr_time;
-#endif
-
-int ar_fd;
-
-char io_buffer[IO_SIZE];
-
-char *progname;
-
-char temp_buf[32];
-char *temp_arch = &temp_buf[0];
-extern char *mktemp();
-extern char *ctime();
-
-usage()
-{
-	error(TRUE, "usage: %s %s archive [file] ...\n",
-		progname,
-#ifdef AAL
-		"[acdrtxvlu]"
-#else
-		"[acdprtxvlu]"
-#endif
-		);
-}
-
-/*VARARGS2*/
-error(quit, str1, str2, str3, str4)
-BOOL quit;
-char *str1, *str2, *str3, *str4;
-{
-	char errbuf[256];
-
-	sprint(errbuf, str1, str2, str3, str4);
-	write(2, errbuf, strlen(errbuf));
-  	if (quit) {
-		unlink(temp_arch);
-		_exit(1);
-  	}
-}
-
-char *basename(path)
-char *path;
-{
-  register char *ptr = path;
-  register char *last = NIL_PTR;
-
-  while (*ptr != '\0') {
-	if (*ptr == '/')
-		last = ptr;
-	ptr++;
-  }
-  if (last == NIL_PTR)
-	return path;
-  if (*(last + 1) == '\0') {
-	*last = '\0';
-	return basename(path);
-  }
-  return last + 1;
-}
-
-extern unsigned int rd_unsigned2();
-
-open_archive(name, mode)
-register char *name;
-register int mode;
-{
-  unsigned short magic = 0;
-  int fd;
-
-  if (mode == CREATE) {
-	if ((fd = creat(name, 0666)) < 0)
-		error(TRUE, "cannot creat %s\n", name);
-	magic = MAGIC_NUMBER;
-	wr_int2(fd, magic);
-	return fd;
-  }
-
-  if ((fd = open(name, mode)) < 0) {
-	if (mode == APPEND) {
-		close(open_archive(name, CREATE));
-		if (!nocr_fl) error(FALSE, "%s: creating %s\n", progname, name);
-		return open_archive(name, APPEND);
-	}
-	error(TRUE, "cannot open %s\n", name);
-  }
-  lseek(fd, 0L, 0);
-  magic = rd_unsigned2(fd);
-  if (magic != AALMAG && magic != ARMAG)
-	error(TRUE, "%s is not in ar format\n", name);
-  
-  return fd;
-}
-
-#if __STDC__
-void catch(int sig)
-#else
-catch()
-#endif
-{
-	unlink(temp_arch);
-	_exit (2);
-}
-
-main(argc, argv)
-int argc;
-char *argv[];
-{
-  register char *ptr;
-  int needs_arg = 0;
-
-  progname = argv[0];
-
-  if (argc < 3)
-	usage();
-  
-  for (ptr = argv[1]; *ptr; ptr++) {
-	switch (*ptr) {
-		case 't' :
-			show_fl = TRUE;
-			break;
-		case 'v' :
-			verbose = TRUE;
-			break;
-		case 'x' :
-			ex_fl = TRUE;
-			break;
-		case 'a' :
-			needs_arg = 1;
-			app_fl = TRUE;
-			break;
-		case 'c' :
-			nocr_fl = TRUE;
-			break;
-#ifndef AAL
-		case 'p' :
-			needs_arg = 1;
-			pr_fl = TRUE;
-			break;
-#endif
-		case 'd' :
-			needs_arg = 1;
-			del_fl = TRUE;
-			break;
-		case 'r' :
-			needs_arg = 1;
-			rep_fl = TRUE;
-			break;
-		case 'l' :
-			local_fl = TRUE;
-			break;
-		case 'u' :
-			update_fl = TRUE;
-			break;
-#ifdef DISTRIBUTION
-		case 'D' :
-			distr_fl = TRUE;
-			break;
-#endif
-		default :
-			usage();
-	}
-  }
-
-  if (needs_arg && argc <= 3)
-	usage();
-#ifdef DISTRIBUTION
-  if (distr_fl) {
-	struct stat statbuf;
-
-	stat(progname, &statbuf);
-	distr_time = statbuf.st_mtime;
-  }
-#endif
-  if (local_fl) strcpy(temp_arch, "ar.XXXXXX");
-  else	strcpy(temp_arch, "/usr/tmp/ar.XXXXXX");
-
-  if (app_fl + ex_fl + del_fl + rep_fl + show_fl + pr_fl != 1)
-	usage();
-
-  if (update_fl && !rep_fl)
-	usage();
-
-  if (rep_fl || del_fl
-#ifdef AAL
-	|| app_fl
-#endif
-     ) {
-	mktemp(temp_arch);
-  }
-#ifdef AAL
-  tab = (struct ranlib *) malloc(512 * sizeof(struct ranlib));
-  tstrtab = malloc(4096);
-  if (!tab || !tstrtab) error(TRUE,"Out of core\n");
-  tabsz = 512;
-  strtabsz = 4096;
-#endif
-
-  signal(SIGINT, catch);
-  get(argc, argv);
-  
-  return 0;
-}
-
-MEMBER *
-get_member()
-{
-  static MEMBER member;
-
-again:
-  if (rd_arhdr(ar_fd, &member) == 0)
-	return NIL_MEM;
-  if (member.ar_size < 0) {
-	error(TRUE, "archive has member with negative size\n");
-  }
-#ifdef AAL
-  if (equal(SYMDEF, member.ar_name)) {
-	lseek(ar_fd, member.ar_size, 1);
-	goto again;
-  }
-#endif
-  return &member;
-}
-
-char *get_mode();
-
-get(argc, argv)
-int argc;
-register char *argv[];
-{
-  register MEMBER *member;
-  int i = 0;
-  int temp_fd, read_chars;
-
-  ar_fd = open_archive(argv[2], (show_fl || pr_fl || ex_fl) ? READ : APPEND);
-  if (rep_fl || del_fl
-#ifdef AAL
-	|| app_fl
-#endif
-  )
-	temp_fd = open_archive(temp_arch, CREATE);
-  while ((member = get_member()) != NIL_MEM) {
-	if (argc > 3) {
-		for (i = 3; i < argc; i++) {
-			if (equal(basename(argv[i]), member->ar_name))
-				break;
-		}
-		if (i == argc || app_fl) {
-			if (rep_fl || del_fl
-#ifdef AAL
-				|| app_fl
-#endif
-			) {
-#ifdef AAL
-				if (i != argc) {
-					print("%s: already in archive\n", argv[i]);
-					argv[i] = "";
-				}
-#endif
-				wr_arhdr(temp_fd, member);
-				copy_member(member, ar_fd, temp_fd, 0);
-			}
-			else {
-#ifndef AAL
-				if (app_fl && i != argc) {
-					print("%s: already in archive\n", argv[i]);
-					argv[i] = "";
-				}
-#endif
-				lseek(ar_fd, even(member->ar_size),1);
-			}
-			continue;
-		}
-	}
-	if (ex_fl || pr_fl)
-		extract(member);
-	else {
-		if (rep_fl) {
-			int isold = 0;
-			if(update_fl) {
-				struct stat status;
-				if (stat(argv[i], &status) >= 0) {
-					if(status.st_mtime <= member->ar_date)
-						isold = 1;
-				}
-			}
-			if(!isold)
-				add(argv[i], temp_fd, "r - %s\n");
-			else {
-				wr_arhdr(temp_fd, member);
-				copy_member(member, ar_fd, temp_fd, 0);
-				if(verbose)
-					show("r - %s (old)\n", member->ar_name);
-			}
-		}
-		else if (show_fl) {
-			char buf[sizeof(member->ar_name) + 2];
-			register char *p = buf, *q = member->ar_name;
-
-			while (q <= &member->ar_name[sizeof(member->ar_name)-1] && *q) {
-				*p++ = *q++;
-			}
-			*p++ = '\n';
-			*p = '\0';
-			if (verbose) {
-				char *mode = get_mode(member->ar_mode);
-				char *date = ctime(&(member->ar_date));
-
-				*(date + 16) = '\0';
-				*(date + 24) = '\0';
-
-				print("%s%3u/%u%7ld %s %s %s",
-					mode,
-					(unsigned) (member->ar_uid & 0377),
-					(unsigned) (member->ar_gid & 0377),
-					member->ar_size,
-					date+4,
-					date+20,
-					buf);
-			}
-			else	print(buf);
-		}
-		else if (del_fl)
-			show("d - %s\n", member->ar_name);
-		lseek(ar_fd, even(member->ar_size), 1);
-	}
-	argv[i] = "";
-  }
-
-  if (argc > 3) {
-	for (i = 3; i < argc; i++)
-		if (argv[i][0] != '\0') {
-#ifndef AAL
-			if (app_fl)
-				add(argv[i], ar_fd, "a - %s\n");
-			else
-#endif
-			if (rep_fl
-#ifdef AAL
-				|| app_fl
-#endif
-			)
-				add(argv[i], temp_fd, "a - %s\n");
-			else {
-				print("%s: not found\n", argv[i]);
-			}
-		}
-  }
-
-  if (rep_fl || del_fl
-#ifdef AAL
-		|| app_fl
-#endif
-  ) {
-	signal(SIGINT, SIG_IGN);
-	close(ar_fd);
-	close(temp_fd);
-	ar_fd = open_archive(argv[2], CREATE);
-	temp_fd = open_archive(temp_arch, APPEND);
-#ifdef AAL
-	write_symdef();
-#endif
-	while ((read_chars = read(temp_fd, io_buffer, IO_SIZE)) > 0)
-		mwrite(ar_fd, io_buffer, read_chars);
-	close(temp_fd);
-	unlink(temp_arch);
-  }
-  close(ar_fd);
-}
-
-add(name, fd, mess)
-char *name;
-int fd;
-char *mess;
-{
-  static MEMBER member;
-  register int read_chars;
-  struct stat status;
-  int src_fd;
-
-  if (stat(name, &status) < 0) {
-	error(FALSE, "cannot find %s\n", name);
-	return;
-  }
-  else if (S_ISDIR(status.st_mode)) {
-	error(FALSE, "%s is a directory (ignored)\n", name);
-	return;
-  }
-  else if ((src_fd = open(name, 0)) < 0) {
-	error(FALSE, "cannot open %s\n", name);
-	return;
-  }
-
-  strncpy (member.ar_name, basename (name), sizeof(member.ar_name));
-  member.ar_uid = status.st_uid;
-  member.ar_gid = status.st_gid;
-  member.ar_mode = status.st_mode;
-  member.ar_date = status.st_mtime;
-  member.ar_size = status.st_size;
-#ifdef DISTRIBUTION
-  if (distr_fl) {
-	member.ar_uid = 2;
-	member.ar_gid = 2;
-	member.ar_mode = 0644;
-	member.ar_date = distr_time;
-  }
-#endif
-  wr_arhdr(fd, &member);
-#ifdef AAL
-  do_object(src_fd, member.ar_size);
-  lseek(src_fd, 0L, 0);
-  offset += AR_TOTAL + even(member.ar_size);
-#endif
-  while (status.st_size > 0) {
-	int x = IO_SIZE;
-
-	read_chars = x;
-	if (status.st_size < x) {
-		x = status.st_size;
-		read_chars = x;
-		status.st_size = 0;
-		x = even(x);
-	}
-	else	status.st_size -= x;
-  	if (read(src_fd, io_buffer, read_chars) != read_chars) {
-		error(FALSE,"%s seems to shrink\n", name);
-		break;
-	}
-	mwrite(fd, io_buffer, x);
-  }
-
-  if (verbose)
-	show(mess, member.ar_name);
-  close(src_fd);
-}
-
-extract(member)
-register MEMBER *member;
-{
-  int fd = 1;
-  char buf[sizeof(member->ar_name) + 1];
-
-  strncpy(buf, member->ar_name, sizeof(member->ar_name));
-  buf[sizeof(member->ar_name)] = 0;
-  if (pr_fl == FALSE && (fd = creat(buf, 0666)) < 0) {
-	error(FALSE, "cannot create %s\n", buf);
-	fd = -1;
-  }
-
-  if (verbose) {
-	if (pr_fl == FALSE) show("x - %s\n", buf);
-	else show("\n<%s>\n\n", buf);
-  }
-
-  copy_member(member, ar_fd, fd, 1);
-
-  if (fd >= 0 && fd != 1)
-  	close(fd);
-  if (pr_fl == FALSE) chmod(buf, member->ar_mode);
-}
-
-copy_member(member, from, to, extracting)
-register MEMBER *member;
-int from, to;
-{
-  register int rest;
-  long mem_size = member->ar_size;
-  BOOL is_odd = odd(mem_size) ? TRUE : FALSE;
-
-#ifdef AAL
-  if (! extracting) {
-  	long pos = lseek(from, 0L, 1);
-
-	do_object(from, mem_size);
-	offset += AR_TOTAL + even(mem_size);
-  	lseek(from, pos, 0);
-  }
-#endif
-  do {
-	rest = mem_size > (long) IO_SIZE ? IO_SIZE : (int) mem_size;
-	if (read(from, io_buffer, rest) != rest) {
-		char buf[sizeof(member->ar_name) + 1];
-
-		strncpy(buf, member->ar_name, sizeof(member->ar_name));
-		buf[sizeof(member->ar_name)] = 0;
-		error(TRUE, "read error on %s\n", buf);
-	}
-	if (to >= 0) mwrite(to, io_buffer, rest);
-	mem_size -= (long) rest;
-  } while (mem_size > 0L);
-
-  if (is_odd) {
-	lseek(from, 1L, 1);
-	if (to >= 0 && ! extracting)
-		lseek(to, 1L, 1);
-  }
-}
-
-char *
-get_mode(mode)
-register int mode;
-{
-  static char mode_buf[11];
-  register int tmp = mode;
-  int i;
-
-  mode_buf[9] = ' ';
-  for (i = 0; i < 3; i++) {
-	mode_buf[i * 3] = (tmp & S_IREAD) ? 'r' : '-';
-	mode_buf[i * 3 + 1] = (tmp & S_IWRITE) ? 'w' : '-';
-	mode_buf[i * 3 + 2] = (tmp & S_IEXEC) ? 'x' : '-';
-	tmp <<= 3;
-  }
-  if (mode & S_ISUID)
-	mode_buf[2] = 's';
-  if (mode & S_ISGID)
-	mode_buf[5] = 's';
-  return mode_buf;
-}
-
-wr_fatal()
-{
-	error(TRUE, "write error\n");
-}
-
-rd_fatal()
-{
-	error(TRUE, "read error\n");
-}
-
-mwrite(fd, address, bytes)
-int fd;
-register char *address;
-register int bytes;
-{
-  if (write(fd, address, bytes) != bytes)
-	error(TRUE, "write error\n");
-}
-
-show(s, name)
-char *s, *name;
-{
-  MEMBER x;
-  char buf[sizeof(x.ar_name)+1];
-  register char *p = buf, *q = name;
-
-  while (q <= &name[sizeof(x.ar_name)-1] && *q) *p++ = *q++;
-  *p++ = '\0';
-  print(s, buf);
-}
-
-#ifdef AAL
-/*
- * Write out the ranlib table: first 4 bytes telling how many ranlib structs
- * there are, followed by the ranlib structs,
- * then 4 bytes giving the size of the string table, followed by the string
- * table itself.
- */
-write_symdef()
-{
-	register struct ranlib	*ran;
-	register int	i;
-	register long	delta;
-	MEMBER	arbuf;
-
-	if (odd(tssiz))
-		tstrtab[tssiz++] = '\0';
-	for (i = 0; i < sizeof(arbuf.ar_name); i++)
-		arbuf.ar_name[i] = '\0';
-	strcpy(arbuf.ar_name, SYMDEF);
-	arbuf.ar_size = 4 + 2 * 4 * (long)tnum + 4 + (long)tssiz;
-	time(&arbuf.ar_date);
-	arbuf.ar_uid = getuid();
-	arbuf.ar_gid = getgid();
-	arbuf.ar_mode = 0444;
-#ifdef DISTRIBUTION
-	if (distr_fl) {
-		arbuf.ar_uid = 2;
-		arbuf.ar_gid = 2;
-		arbuf.ar_date = distr_time;
-	}
-#endif
-	wr_arhdr(ar_fd,&arbuf);
-	wr_long(ar_fd, (long) tnum);
-	/*
-	 * Account for the space occupied by the magic number
-	 * and the ranlib table.
-	 */
-	delta = 2 + AR_TOTAL + arbuf.ar_size;
-	for (ran = tab; ran < &tab[tnum]; ran++) {
-		ran->ran_pos += delta;
-	}
-
-	wr_ranlib(ar_fd, tab, (long) tnum);
-	wr_long(ar_fd, (long) tssiz);
-	wr_bytes(ar_fd, tstrtab, (long) tssiz);
-}
-
-/*
- * Return whether the bytes in `buf' form a good object header. 
- * The header is put in `headp'.
- */
-int
-is_outhead(headp)
-	register struct outhead	*headp;
-{
-
-	return !BADMAGIC(*headp) && headp->oh_nname != 0;
-}
-
-do_object(f, size)
-	long size;
-{
-	struct outhead	headbuf;
-
-	if (size < SZ_HEAD) {
-		/* It can't be an object file. */
-		return;
-	}
-	/*
-	 * Read a header to see if it is an object file.
-	 */
-	if (! rd_fdopen(f)) {
-		rd_fatal();
-	}
-	rd_ohead(&headbuf);
-	if (!is_outhead(&headbuf)) {
-		return;
-	}
-	do_names(&headbuf);
-}
-
-/*
- * First skip the names and read in the string table, then seek back to the
- * name table and read and write the names one by one. Update the ranlib table
- * accordingly.
- */
-do_names(headp)
-	struct outhead	*headp;
-{
-	register char	*strings;
-	register int	nnames = headp->oh_nname;
-#define NNAMES 100
-	struct outname	namebuf[NNAMES];
-	long xxx = OFF_CHAR(*headp);
-
-	if (	headp->oh_nchar != (unsigned int)headp->oh_nchar ||
-		(strings = malloc((unsigned int)headp->oh_nchar)) == (char *)0
-	   ) {
-		error(TRUE, "string table too big\n");
-	}
-	rd_string(strings, headp->oh_nchar);
-	while (nnames) {
-		int i = nnames >= NNAMES ? NNAMES : nnames;
-		register struct outname *p = namebuf;
-
-		nnames -= i;
-		rd_name(namebuf, i);
-		while (i--) {
-			long off = p->on_foff - xxx;
-			if (p->on_foff == (long)0) {
-				p++;
-				continue; /* An unrecognizable name. */
-			}
-			p->on_mptr = strings + off;
-			/*
-			 * Only enter names that are exported and are really
-			 * defined. Also enter common names. Note, that
-			 * this might cause problems when the name is really
-			 * defined in a later file, with a value != 0.
-			 * However, this problem also exists on the Unix
-			 * ranlib archives.
-			 */
-			if (	(p->on_type & S_EXT) &&
-				(p->on_type & S_TYP) != S_UND
-			   )
-				enter_name(p);
-			p++;
-		}
-	}
-	free(strings);
-}
-
-enter_name(namep)
-	struct outname *namep;
-{
-	register char	*cp;
-
-	if (tnum >= tabsz) {
-		tab = (struct ranlib *)
-			realloc((char *) tab, (tabsz += 512) * sizeof(struct ranlib));
-		if (! tab) error(TRUE, "Out of core\n");
-	}
-	tab[tnum].ran_off = tssiz;
-	tab[tnum].ran_pos = offset;
-
-	for (cp = namep->on_mptr;; cp++) {
-		if (tssiz >= strtabsz) {
-			tstrtab = realloc(tstrtab, (strtabsz += 4096));
-			if (! tstrtab) error(TRUE, "string table overflow\n");
-		}
-		tstrtab[tssiz++]  = *cp;
-		if (!*cp) break;
-	}
-	tnum++;
-}
-#endif AAL
Index: trunk/minix/commands/aal/build
===================================================================
--- trunk/minix/commands/aal/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/aal/byte_order.h
===================================================================
--- trunk/minix/commands/aal/byte_order.h	(revision 9)
+++ 	(revision )
@@ -1,9 +1,0 @@
-#if defined(mc68020) || defined(mc68000) || defined(sparc)
-#define BYTES_REVERSED 1
-#define WORDS_REVERSED 1
-#define CHAR_UNSIGNED 0
-#else
-#define BYTES_REVERSED 0
-#define WORDS_REVERSED 0
-#define CHAR_UNSIGNED 0
-#endif
Index: trunk/minix/commands/aal/format.c
===================================================================
--- trunk/minix/commands/aal/format.c	(revision 9)
+++ 	(revision )
@@ -1,112 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Header: /cvsup/minix/src/commands/aal/format.c,v 1.1.1.1 2005/04/21 14:53:57 beng Exp $ */
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-extern char *long2str();
-
-static int
-integral(c)
-{
-	switch (c) {
-	case 'b':
-		return -2;
-	case 'd':
-		return 10;
-	case 'o':
-		return -8;
-	case 'u':
-		return -10;
-	case 'x':
-		return -16;
-	}
-	return 0;
-}
-
-/*VARARGS2*/
-/*FORMAT1 $
-	%s = char *
-	%l = long
-	%c = int
-	%[uxbo] = unsigned int
-	%d = int
-$ */
-int
-_format(buf, fmt, argp)
-	char *buf, *fmt;
-	register va_list argp;
-{
-	register char *pf = fmt;
-	register char *pb = buf;
-
-	while (*pf) {
-		if (*pf == '%') {
-			register width, base, pad, npad;
-			char *arg;
-			char cbuf[2];
-			char *badformat = "<bad format>";
-			
-			/* get padder */
-			if (*++pf == '0') {
-				pad = '0';
-				++pf;
-			}
-			else
-				pad = ' ';
-			
-			/* get width */
-			width = 0;
-			while (*pf >= '0' && *pf <= '9')
-				width = 10 * width + *pf++ - '0';
-			
-			if (*pf == 's') {
-				arg = va_arg(argp, char *);
-			}
-			else
-			if (*pf == 'c') {
-				cbuf[0] = va_arg(argp, int);
-				cbuf[1] = '\0';
-				arg = &cbuf[0];
-			}
-			else
-			if (*pf == 'l') {
-				/* alignment ??? */
-				if (base = integral(*++pf)) {
-					arg = long2str(va_arg(argp,long), base);
-				}
-				else {
-					pf--;
-					arg = badformat;
-				}
-			}
-			else
-			if (base = integral(*pf)) {
-				arg = long2str((long)va_arg(argp,int), base);
-			}
-			else
-			if (*pf == '%')
-				arg = "%";
-			else
-				arg = badformat;
-
-			npad = width - strlen(arg);
-
-			while (npad-- > 0)
-				*pb++ = pad;
-			
-			while (*pb++ = *arg++);
-			pb--;
-			pf++;
-		}
-		else
-			*pb++ = *pf++;
-	}
-	return pb - buf;
-}
Index: trunk/minix/commands/aal/local.h
===================================================================
--- trunk/minix/commands/aal/local.h	(revision 9)
+++ 	(revision )
@@ -1,19 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/local.h,v 1.1.1.1 2005/04/21 14:53:57 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* collection of options, selected by including or excluding 'defines' */
-
-/* Version number of the EM object code */
-#	define	VERSION		3	/* 16 bits number */
-
-/* The default machine used by ack, acc, apc */
-#	define	ACKM		"minix"
-
-/* size of local machine, either 0 (for 16 bit address space), or 1 */
-#	undef BIGMACHINE	1
-
-/* operating system, SYS_5, V7, BSD4_1 or BSD4_2; Do NOT delete the comment
-   in the next line! */
-#	define V7  1       /* SYSTEM */
Index: trunk/minix/commands/aal/long2str.c
===================================================================
--- trunk/minix/commands/aal/long2str.c	(revision 9)
+++ 	(revision )
@@ -1,67 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/long2str.c,v 1.1.1.1 2005/04/21 14:53:57 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* Integer to String translator
-	-> base is a value from [-16,-2] V [2,16]
-	-> base < 0: see 'val' as unsigned value
-	-> no checks for buffer overflow and illegal parameters
-	(1985, EHB)
-*/
-
-#define MAXWIDTH 32
-
-char *
-long2str(val, base)
-	register long val;
-	register base;
-{
-	static char numbuf[MAXWIDTH];
-	static char vec[] = "0123456789ABCDEF";
-	register char *p = &numbuf[MAXWIDTH];
-	int sign = (base > 0);
-
-	*--p = '\0';		/* null-terminate string	*/
-	if (val) {
-		if (base > 0) {
-			if (val < 0L) {
-				long v1 = -val;
-				if (v1 == val)
-					goto overflow;
-				val = v1;
-			}
-			else
-				sign = 0;
-		}
-		else
-		if (base < 0) {			/* unsigned */
-			base = -base;
-			if (val < 0L) {	/* taken from Amoeba src */
-				register mod, i;
-			overflow:
-				mod = 0;
-				for (i = 0; i < 8 * sizeof val; i++) {
-					mod <<= 1;
-					if (val < 0)
-						mod++;
-					val <<= 1;
-					if (mod >= base) {
-						mod -= base;
-						val++;
-					}
-				}
-				*--p = vec[mod];
-			}
-		}
-		do {
-			*--p = vec[(int) (val % base)];
-			val /= base;
-		} while (val != 0L);
-		if (sign)
-			*--p = '-';	/* don't forget it !!	*/
-	}
-	else
-		*--p = '0';		/* just a simple 0	*/
-	return p;
-}
Index: trunk/minix/commands/aal/object.h
===================================================================
--- trunk/minix/commands/aal/object.h	(revision 9)
+++ 	(revision )
@@ -1,76 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/object.h,v 1.1.1.1 2005/04/21 14:53:57 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include "byte_order.h"
-#include <local.h>
-#include <stdio.h>
-
-#if CHAR_UNSIGNED
-#define Xchar(ch)	(ch)
-#else
-#define Xchar(ch)	((ch) & 0377)
-#endif
-
-#if ! defined(BYTES_REVERSED)
-#define BYTES_REVERSED 1
-#endif
-
-#if ! defined(WORDS_REVERSED)
-#define WORDS_REVERSED 1
-#endif
-
-#if BYTES_REVERSED
-#define uget2(c)	(Xchar((c)[0]) | ((unsigned) Xchar((c)[1]) << 8))
-#define Xput2(i, c)	(((c)[0] = (i)), ((c)[1] = (i) >> 8))
-#define put2(i, c)	{ register int j = (i); Xput2(j, c); }
-#else
-#define uget2(c)	(* ((unsigned short *) (c)))
-#define Xput2(i, c)	(* ((short *) (c)) = (i))
-#define put2(i, c)	Xput2(i, c)
-#endif
-
-#define get2(c)		((short) uget2(c))
-
-#if WORDS_REVERSED || BYTES_REVERSED
-#define get4(c)		(uget2(c) | ((long) uget2((c)+2) << 16))
-#define put4(l, c)	{ register long x=(l); \
-			  Xput2((int)x,c); \
-			  Xput2((int)(x>>16),(c)+2); \
-			}
-#else
-#define get4(c)		(* ((long *) (c)))
-#define put4(l, c)	(* ((long *) (c)) = (l))
-#endif
-
-#define SECTCNT	3	/* number of sections with own output buffer */
-#if BIGMACHINE
-#define WBUFSIZ	(8*BUFSIZ)
-#else
-#define WBUFSIZ	BUFSIZ
-#endif
-
-struct fil {
-	int	cnt;
-	char	*pnow;
-	char	*pbegin;
-	long	currpos;
-	int	fd;
-	char	pbuf[WBUFSIZ];
-};
-
-extern struct fil __parts[];
-
-#define	PARTEMIT	0
-#define	PARTRELO	(PARTEMIT+SECTCNT)
-#define	PARTNAME	(PARTRELO+1)
-#define	PARTCHAR	(PARTNAME+1)
-#ifdef SYMDBUG
-#define PARTDBUG	(PARTCHAR+1)
-#else
-#define PARTDBUG	(PARTCHAR+0)
-#endif
-#define	NPARTS		(PARTDBUG + 1)
-
-#define getsect(s)      (PARTEMIT+((s)>=(SECTCNT-1)?(SECTCNT-1):(s)))
Index: trunk/minix/commands/aal/out.h
===================================================================
--- trunk/minix/commands/aal/out.h	(revision 9)
+++ 	(revision )
@@ -1,126 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Header: /cvsup/minix/src/commands/aal/out.h,v 1.1.1.1 2005/04/21 14:53:57 beng Exp $ */
-
-#ifndef __OUT_H_INCLUDED
-#define __OUT_H_INCLUDED
-/*
- * output format for ACK assemblers
- */
-#ifndef ushort
-#define ushort	unsigned short
-#endif /* ushort */
-
-struct outhead {
-	ushort 	oh_magic;	/* magic number */
-	ushort 	oh_stamp;	/* version stamp */
-	ushort	oh_flags;	/* several format flags */
-	ushort	oh_nsect;	/* number of outsect structures */
-	ushort	oh_nrelo;	/* number of outrelo structures */
-	ushort	oh_nname;	/* number of outname structures */
-	long	oh_nemit;	/* sum of all os_flen */
-	long	oh_nchar;	/* size of string area */
-};
-
-#define O_MAGIC	0x0201		/* magic number of output file */
-#define	O_STAMP	0		/* version stamp */
-#define MAXSECT	64		/* Maximum number of sections */
-
-#define	HF_LINK	0x0004		/* unresolved references left */
-#define	HF_8086	0x0008		/* os_base specially encoded */
-
-struct outsect {
-	long 	os_base;	/* startaddress in machine */
-	long	os_size;	/* section size in machine */
-	long	os_foff;	/* startaddress in file */
-	long	os_flen;	/* section size in file */
-	long	os_lign;	/* section alignment */
-};
-
-struct outrelo {
-	char	or_type;	/* type of reference */
-	char	or_sect;	/* referencing section */
-	ushort	or_nami;	/* referenced symbol index */
-	long	or_addr;	/* referencing address */
-};
-
-struct outname {
-	union {
-	  char	*on_ptr;	/* symbol name (in core) */
-	  long	on_off;		/* symbol name (in file) */
-	}	on_u;
-#define on_mptr	on_u.on_ptr
-#define on_foff	on_u.on_off
-	ushort	on_type;	/* symbol type */
-	ushort	on_desc;	/* debug info */
-	long	on_valu;	/* symbol value */
-};
-
-/*
- * relocation type bits
- */
-#define RELSZ	0x07		/* relocation length */
-#define RELO1	   1		/* 1 byte */
-#define RELO2	   2		/* 2 bytes */
-#define RELO4	   4		/* 4 bytes */
-#define RELPC	0x08		/* pc relative */
-#define RELBR	0x10		/* High order byte lowest address. */
-#define RELWR	0x20		/* High order word lowest address. */
-
-/*
- * section type bits and fields
- */
-#define S_TYP	0x007F		/* undefined, absolute or relative */
-#define S_EXT	0x0080		/* external flag */
-#define S_ETC	0x7F00		/* for symbolic debug, bypassing 'as' */
-
-/*
- * S_TYP field values
- */
-#define S_UND	0x0000		/* undefined item */
-#define S_ABS	0x0001		/* absolute item */
-#define S_MIN	0x0002		/* first user section */
-#define S_MAX	(S_TYP-1)	/* last user section */
-#define S_CRS	S_TYP		/* on_valu is symbol index which contains value */
-
-/*
- * S_ETC field values
- */
-#define S_SCT	0x0100		/* section names */
-#define S_LIN	0x0200		/* hll source line item */
-#define S_FIL	0x0300		/* hll source file item */
-#define S_MOD	0x0400		/* ass source file item */
-#define S_COM	0x1000		/* Common name. */
-#define S_STB	0xe000		/* entries with any of these bits set are
-				   reserved for debuggers
-				*/
-
-/*
- * structure format strings
- */
-#define SF_HEAD		"22222244"
-#define SF_SECT		"44444"
-#define SF_RELO		"1124"
-#define SF_NAME		"4224"
-
-/*
- * structure sizes (bytes in file; add digits in SF_*)
- */
-#define SZ_HEAD		20
-#define SZ_SECT		20
-#define SZ_RELO		8
-#define SZ_NAME		12
-
-/*
- * file access macros
- */
-#define BADMAGIC(x)	((x).oh_magic!=O_MAGIC)
-#define OFF_SECT(x)	SZ_HEAD
-#define OFF_EMIT(x)	(OFF_SECT(x) + ((long)(x).oh_nsect * SZ_SECT))
-#define OFF_RELO(x)	(OFF_EMIT(x) + (x).oh_nemit)
-#define OFF_NAME(x)	(OFF_RELO(x) + ((long)(x).oh_nrelo * SZ_RELO))
-#define OFF_CHAR(x)	(OFF_NAME(x) + ((long)(x).oh_nname * SZ_NAME))
-
-#endif /* __OUT_H_INCLUDED */
Index: trunk/minix/commands/aal/param.h
===================================================================
--- trunk/minix/commands/aal/param.h	(revision 9)
+++ 	(revision )
@@ -1,7 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Header: /cvsup/minix/src/commands/aal/param.h,v 1.1.1.1 2005/04/21 14:53:57 beng Exp $ */
-
-#define SSIZE 1024
Index: trunk/minix/commands/aal/print.c
===================================================================
--- trunk/minix/commands/aal/print.c	(revision 9)
+++ 	(revision )
@@ -1,42 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Header: /cvsup/minix/src/commands/aal/print.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-#include <system.h>
-#include "param.h"
-
-/*VARARGS*/
-/*FORMAT0v $
-	%s = char *
-	%l = long
-	%c = int
-	%[uxbo] = unsigned int
-	%d = int
-$ */
-int
-#if __STDC__
-print(char *fmt, ...)
-#else
-print(fmt, va_alist)
-	char *fmt;
-	va_dcl
-#endif
-{
-	va_list args;
-	char buf[SSIZE];
-
-#if __STDC__
-	va_start(args, fmt);
-#else
-	va_start(args);
-#endif
-	sys_write(STDOUT, buf, _format(buf, fmt, args));
-	va_end(args);
-}
Index: trunk/minix/commands/aal/ranlib.h
===================================================================
--- trunk/minix/commands/aal/ranlib.h	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Header: /cvsup/minix/src/commands/aal/ranlib.h,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-
-#ifndef __RANLIB_H_INCLUDED
-#define __RANLIB_H_INCLUDED
-
-#ifndef SYMDEF
-#	define SYMDEF	"__.SYMDEF"
-#endif /* SYMDEF */
-
-/*
- * Structure of the SYMDEF table of contents for an archive.
- * SYMDEF begins with a long giving the number of ranlib
- * structures that immediately follow, and then continues with a string
- * table consisting of a long giving the number of bytes of
- * strings that follow and then the strings themselves.
- */
-struct ranlib {
-	union {
-	  char	*ran__ptr;	/* symbol name (in core) */
-	  long	ran__off;	/* symbol name (in file) */
-	}	ran_u;
-#define ran_ptr ran_u.ran__ptr
-#define ran_off ran_u.ran__off
-	long	ran_pos;	/* library member is at this position */
-};
-
-#define SZ_RAN	8
-#define SF_RAN	"44"
-
-#endif /* __RANLIB_H_INCLUDED */
Index: trunk/minix/commands/aal/rd.c
===================================================================
--- trunk/minix/commands/aal/rd.c	(revision 9)
+++ 	(revision )
@@ -1,254 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/rd.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include <out.h>
-#include "object.h"
-
-extern long		lseek();
-
-/*
- * Parts of the output file.
- */
-#undef PARTEMIT
-#undef PARTRELO
-#undef PARTNAME
-#undef PARTCHAR
-#undef PARTDBUG
-#undef NPARTS
-
-#define	PARTEMIT	0
-#define	PARTRELO	1
-#define	PARTNAME	2
-#define	PARTCHAR	3
-#ifdef SYMDBUG
-#define PARTDBUG	4
-#else
-#define PARTDBUG	3
-#endif
-#define	NPARTS		(PARTDBUG + 1)
-
-static long		offset[MAXSECT];
-
-static int		outfile;
-static long		outseek[NPARTS];
-static long		currpos;
-static long		rd_base;
-#define OUTSECT(i) \
-	(outseek[PARTEMIT] = offset[i])
-#define BEGINSEEK(p, o) \
-	(outseek[(p)] = (o))
-
-static int sectionnr;
-
-static
-OUTREAD(p, b, n)
-	char *b;
-	long n;
-{
-	register long l = outseek[p];
-
-	if (currpos != l) {
-		lseek(outfile, l, 0);
-	}
-	rd_bytes(outfile, b, n);
-	l += n;
-	currpos = l;
-	outseek[p] = l;
-}
-
-/*
- * Open the output file according to the chosen strategy.
- */
-int
-rd_open(f)
-	char *f;
-{
-
-	if ((outfile = open(f, 0)) < 0)
-		return 0;
-	return rd_fdopen(outfile);
-}
-
-static int offcnt;
-
-rd_fdopen(fd)
-{
-	register int i;
-
-	for (i = 0; i < NPARTS; i++) outseek[i] = 0;
-	offcnt = 0;
-	rd_base = lseek(fd, 0L, 1);
-	if (rd_base < 0) {
-		return 0;
-	}
-	currpos = rd_base;
-	outseek[PARTEMIT] = currpos;
-	outfile = fd;
-	sectionnr = 0;
-	return 1;
-}
-
-rd_close()
-{
-
-	close(outfile);
-	outfile = -1;
-}
-
-rd_fd()
-{
-	return outfile;
-}
-
-rd_ohead(head)
-	register struct outhead	*head;
-{
-	register long off;
-
-	OUTREAD(PARTEMIT, (char *) head, (long) SZ_HEAD);
-#if ! (BYTES_REVERSED || WORDS_REVERSED)
-	if (sizeof(struct outhead) != SZ_HEAD)
-#endif
-	{
-		register char *c = (char *) head + (SZ_HEAD-4);
-		
-		head->oh_nchar = get4(c);
-		c -= 4; head->oh_nemit = get4(c);
-		c -= 2; head->oh_nname = uget2(c);
-		c -= 2; head->oh_nrelo = uget2(c);
-		c -= 2; head->oh_nsect = uget2(c);
-		c -= 2; head->oh_flags = uget2(c);
-		c -= 2; head->oh_stamp = uget2(c);
-		c -= 2; head->oh_magic = uget2(c);
-	}
-	off = OFF_RELO(*head) + rd_base;
-	BEGINSEEK(PARTRELO, off);
-	off += (long) head->oh_nrelo * SZ_RELO;
-	BEGINSEEK(PARTNAME, off);
-	off += (long) head->oh_nname * SZ_NAME;
-	BEGINSEEK(PARTCHAR, off);
-#ifdef SYMDBUG
-	off += head->oh_nchar;
-	BEGINSEEK(PARTDBUG, off);
-#endif
-}
-
-rd_rew_relos(head)
-	register struct outhead *head;
-{
-	register long off = OFF_RELO(*head) + rd_base;
-
-	BEGINSEEK(PARTRELO, off);
-}
-
-rd_sect(sect, cnt)
-	register struct outsect	*sect;
-	register unsigned int	cnt;
-{
-	register char *c = (char *) sect + cnt * SZ_SECT;
-
-	OUTREAD(PARTEMIT, (char *) sect, (long)cnt * SZ_SECT);
-	sect += cnt;
-	offcnt += cnt;
-	while (cnt--) {
-		sect--;
-#if ! (BYTES_REVERSED || WORDS_REVERSED)
-		if (sizeof(struct outsect) != SZ_SECT)
-#endif
-		{
-			c -= 4; sect->os_lign = get4(c);
-			c -= 4; sect->os_flen = get4(c);
-			c -= 4; sect->os_foff = get4(c);
-		}
-		offset[--offcnt] = sect->os_foff + rd_base;
-#if ! (BYTES_REVERSED || WORDS_REVERSED)
-		if (sizeof(struct outsect) != SZ_SECT)
-#endif
-		{
-			c -= 4; sect->os_size = get4(c);
-			c -= 4; sect->os_base = get4(c);
-		}
-	}
-}
-
-rd_outsect(s)
-{
-	OUTSECT(s);
-	sectionnr = s;
-}
-
-/*
- * We don't have to worry about byte order here.
- */
-rd_emit(emit, cnt)
-	char		*emit;
-	long		cnt;
-{
-	OUTREAD(PARTEMIT, emit, cnt);
-	offset[sectionnr] += cnt;
-}
-
-rd_relo(relo, cnt)
-	register struct outrelo	*relo;
-	register unsigned int cnt;
-{
-
-	OUTREAD(PARTRELO, (char *) relo, (long) cnt * SZ_RELO);
-#if ! (BYTES_REVERSED || WORDS_REVERSED)
-	if (sizeof(struct outrelo) != SZ_RELO)
-#endif
-	{
-		register char *c = (char *) relo + (long) cnt * SZ_RELO;
-
-		relo += cnt;
-		while (cnt--) {
-			relo--;
-			c -= 4; relo->or_addr = get4(c);
-			c -= 2; relo->or_nami = uget2(c);
-			relo->or_sect = *--c;
-			relo->or_type = *--c;
-		}
-	}
-}
-
-rd_name(name, cnt)
-	register struct outname	*name;
-	register unsigned int cnt;
-{
-
-	OUTREAD(PARTNAME, (char *) name, (long) cnt * SZ_NAME);
-#if ! (BYTES_REVERSED || WORDS_REVERSED)
-	if (sizeof(struct outname) != SZ_NAME)
-#endif
-	{
-		register char *c = (char *) name + (long) cnt * SZ_NAME;
-
-		name += cnt;
-		while (cnt--) {
-			name--;
-			c -= 4; name->on_valu = get4(c);
-			c -= 2; name->on_desc = uget2(c);
-			c -= 2; name->on_type = uget2(c);
-			c -= 4; name->on_foff = get4(c);
-		}
-	}
-}
-
-rd_string(addr, len)
-	char *addr;
-	long len;
-{
-	
-	OUTREAD(PARTCHAR, addr, len);
-}
-
-#ifdef SYMDBUG
-rd_dbug(buf, size)
-	char		*buf;
-	long		size;
-{
-	OUTREAD(PARTDBUG, buf, size);
-}
-#endif
Index: trunk/minix/commands/aal/rd_arhdr.c
===================================================================
--- trunk/minix/commands/aal/rd_arhdr.c	(revision 9)
+++ 	(revision )
@@ -1,35 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/rd_arhdr.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include <arch.h>
-#include "object.h"
-
-int
-rd_arhdr(fd, arhdr)
-	register struct ar_hdr	*arhdr;
-{
-	char buf[AR_TOTAL];
-	register char *c = buf;
-	register char *p = arhdr->ar_name;
-	register int i;
-
-	i = read(fd, c, AR_TOTAL);
-	if (i == 0) return 0;
-	if (i != AR_TOTAL) {
-		rd_fatal();
-	}
-	i = 14;
-	while (i--) {
-		*p++ = *c++;
-	}
-	arhdr->ar_date = ((long) get2(c)) << 16; c += 2;
-	arhdr->ar_date |= ((long) get2(c)) & 0xffff; c += 2;
-	arhdr->ar_uid = *c++;
-	arhdr->ar_gid = *c++;
-	arhdr->ar_mode = get2(c); c += 2;
-	arhdr->ar_size = (long) get2(c) << 16; c += 2;
-	arhdr->ar_size |= (long) get2(c) & 0xffff;
-	return 1;
-}
Index: trunk/minix/commands/aal/rd_bytes.c
===================================================================
--- trunk/minix/commands/aal/rd_bytes.c	(revision 9)
+++ 	(revision )
@@ -1,32 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/rd_bytes.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#define MININT		(1 << (sizeof(int) * 8 - 1))
-#define MAXCHUNK	(~MININT)	/* Highest count we read(2).	*/
-/* Unfortunately, MAXCHUNK is too large with some  compilers. Put it in
-   an int!
-*/
-
-static int maxchunk = MAXCHUNK;
-
-/*
- * We don't have to worry about byte order here.
- * Just read "cnt" bytes from file-descriptor "fd".
- */
-int 
-rd_bytes(fd, string, cnt)
-	register char	*string;
-	register long	cnt;
-{
-
-	while (cnt) {
-		register int n = cnt >= maxchunk ? maxchunk : cnt;
-
-		if (read(fd, string, n) != n)
-			rd_fatal();
-		string += n;
-		cnt -= n;
-	}
-}
Index: trunk/minix/commands/aal/rd_unsig2.c
===================================================================
--- trunk/minix/commands/aal/rd_unsig2.c	(revision 9)
+++ 	(revision )
@@ -1,15 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/rd_unsig2.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include "object.h"
-
-unsigned int
-rd_unsigned2(fd)
-{
-	char buf[2];
-
-	rd_bytes(fd, buf, 2L);
-	return uget2(buf);
-}
Index: trunk/minix/commands/aal/sprint.c
===================================================================
--- trunk/minix/commands/aal/sprint.c	(revision 9)
+++ 	(revision )
@@ -1,42 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Header: /cvsup/minix/src/commands/aal/sprint.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-#include <system.h>
-#include "param.h"
-
-/*VARARGS*/
-/*FORMAT1v $
-	%s = char *
-	%l = long
-	%c = int
-	%[uxbo] = unsigned int
-	%d = int
-$ */
-char *
-#if __STDC__
-sprint(char *buf, char *fmt, ...)
-#else
-sprint(buf, fmt, va_alist)
-	char *buf, *fmt;
-	va_dcl
-#endif
-{
-	va_list args;
-
-#if __STDC__
-	va_start(args, fmt);
-#else
-	va_start(args);
-#endif
-	buf[_format(buf, fmt, args)] = '\0';
-	va_end(args);
-	return buf;
-}
Index: trunk/minix/commands/aal/system.c
===================================================================
--- trunk/minix/commands/aal/system.c	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* RCS: $Header: /cvsup/minix/src/commands/aal/system.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-
-#include <system.h>
-
-File _sys_ftab[SYS_NOPEN] = {
-	{ 0, OP_READ},
-	{ 1, OP_APPEND},
-	{ 2, OP_APPEND}
-};
-
-File *
-_get_entry()
-{
-	register File *fp;
-
-	for (fp = &_sys_ftab[0]; fp < &_sys_ftab[SYS_NOPEN]; fp++)
-		if (fp->o_flags == 0)
-			return fp;
-	return (File *)0;
-}
Index: trunk/minix/commands/aal/system.h
===================================================================
--- trunk/minix/commands/aal/system.h	(revision 9)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* RCS: $Header: /cvsup/minix/src/commands/aal/system.h,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-#ifndef __SYSTEM_INCLUDED__
-#define __SYSTEM_INCLUDED__
-
-struct _sys_fildes {
-	int o_fd;	/* UNIX filedescriptor */
-	int o_flags;	/* flags for open; 0 if not used */
-};
-
-typedef struct _sys_fildes File;
-
-extern File _sys_ftab[];
-
-/* flags for sys_open() */
-#define OP_READ		01
-#define OP_WRITE	02
-#define OP_APPEND	04
-
-/* flags for sys_access() */
-#define AC_EXIST	00
-#define AC_READ		04
-#define AC_WRITE	02
-#define AC_EXEC		01
-
-/* flags for sys_stop() */
-#define S_END	0
-#define S_EXIT	1
-#define S_ABORT	2
-
-/* standard file decsriptors */
-#define STDIN	&_sys_ftab[0]
-#define STDOUT	&_sys_ftab[1]
-#define STDERR	&_sys_ftab[2]
-
-/* maximum number of open files */
-#define SYS_NOPEN	20
-
-/* return value for sys_break */
-#define ILL_BREAK	((char *)0)
-
-/* system's idea of block */
-#define BUFSIZ	1024
-#endif __SYSTEM_INCLUDED__
Index: trunk/minix/commands/aal/varargs.h
===================================================================
--- trunk/minix/commands/aal/varargs.h	(revision 9)
+++ 	(revision )
@@ -1,16 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Header: /cvsup/minix/src/commands/aal/varargs.h,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-
-#ifndef _VARARGS_H
-#define _VARARGS_H
-
-typedef char *va_list;
-# define __va_sz(mode)	(((sizeof(mode) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
-# define va_dcl int va_alist;
-# define va_start(list) (list = (char *) &va_alist)
-# define va_end(list)
-# define va_arg(list,mode) (*((mode *)((list += __va_sz(mode)) - __va_sz(mode))))
-#endif /* _VARARGS_H */
Index: trunk/minix/commands/aal/wr_arhdr.c
===================================================================
--- trunk/minix/commands/aal/wr_arhdr.c	(revision 9)
+++ 	(revision )
@@ -1,28 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/wr_arhdr.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include <arch.h>
-#include "object.h"
-
-wr_arhdr(fd, arhdr)
-	register struct ar_hdr	*arhdr;
-{
-	char buf[AR_TOTAL];
-	register char *c = buf;
-	register char *p = arhdr->ar_name;
-	register int i = 14;
-
-	while (i--) {
-		*c++ = *p++;
-	}
-	put2((int)(arhdr->ar_date>>16),c); c += 2;
-	put2((int)(arhdr->ar_date),c); c += 2;
-	*c++ = arhdr->ar_uid;
-	*c++ = arhdr->ar_gid;
-	put2(arhdr->ar_mode,c); c += 2;
-	put2((int)(arhdr->ar_size>>16),c); c += 2;
-	put2((int)(arhdr->ar_size),c);
-	wr_bytes(fd, buf, (long) AR_TOTAL);
-}
Index: trunk/minix/commands/aal/wr_bytes.c
===================================================================
--- trunk/minix/commands/aal/wr_bytes.c	(revision 9)
+++ 	(revision )
@@ -1,30 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/wr_bytes.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#define MININT		(1 << (sizeof(int) * 8 - 1))
-#define MAXCHUNK	(~MININT)	/* Highest count we write(2).	*/
-/* Notice that MAXCHUNK itself might be too large with some compilers.
-   You have to put it in an int!
-*/
-
-static int maxchunk = MAXCHUNK;
-
-/*
- * Just write "cnt" bytes to file-descriptor "fd".
- */
-wr_bytes(fd, string, cnt)
-	register char	*string;
-	register long	cnt;
-{
-
-	while (cnt) {
-		register int n = cnt >= maxchunk ? maxchunk : cnt;
-
-		if (write(fd, string, n) != n)
-			wr_fatal();
-		string += n;
-		cnt -= n;
-	}
-}
Index: trunk/minix/commands/aal/wr_int2.c
===================================================================
--- trunk/minix/commands/aal/wr_int2.c	(revision 9)
+++ 	(revision )
@@ -1,14 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/wr_int2.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include "object.h"
-
-wr_int2(fd, i)
-{
-	char buf[2];
-
-	put2(i, buf);
-	wr_bytes(fd, buf, 2L);
-}
Index: trunk/minix/commands/aal/wr_long.c
===================================================================
--- trunk/minix/commands/aal/wr_long.c	(revision 9)
+++ 	(revision )
@@ -1,15 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/wr_long.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include "object.h"
-
-wr_long(fd, l)
-	long l;
-{
-	char buf[4];
-
-	put4(l, buf);
-	wr_bytes(fd, buf, 4L);
-}
Index: trunk/minix/commands/aal/wr_ranlib.c
===================================================================
--- trunk/minix/commands/aal/wr_ranlib.c	(revision 9)
+++ 	(revision )
@@ -1,36 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/aal/wr_ranlib.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include <ranlib.h>
-#include "object.h"
-
-wr_ranlib(fd, ran, cnt)
-	register struct ranlib	*ran;
-	register long	cnt;
-{
-#if ! (BYTES_REVERSED || WORDS_REVERSED)
-	if (sizeof (struct ranlib) != SZ_RAN)
-#endif
-	{
-		char buf[100 * SZ_RAN];
-
-		while (cnt) {
-			register int i = (cnt > 100) ? 100 : cnt;
-			register char *c = buf;
-			long j = i * SZ_RAN;
-
-			cnt -= i;
-			while (i--) {
-				put4(ran->ran_off,c); c += 4;
-				put4(ran->ran_pos,c); c += 4;
-				ran++;
-			}
-			wr_bytes(fd, buf, j);
-		}
-	}
-#if ! (BYTES_REVERSED || WORDS_REVERSED)
-	else	wr_bytes(fd, (char *) ran, cnt * SZ_RAN);
-#endif
-}
Index: trunk/minix/commands/aal/write.c
===================================================================
--- trunk/minix/commands/aal/write.c	(revision 9)
+++ 	(revision )
@@ -1,17 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Header: /cvsup/minix/src/commands/aal/write.c,v 1.1.1.1 2005/04/21 14:53:58 beng Exp $ */
-
-#include <system.h>
-
-int
-sys_write(fp, bufptr, nbytes)
-	File *fp;
-	char *bufptr;
-	int nbytes;
-{
-	if (! fp) return 0;
-	return write(fp->o_fd, bufptr, nbytes) == nbytes;
-}
Index: trunk/minix/commands/advent/Makefile
===================================================================
--- trunk/minix/commands/advent/Makefile	(revision 9)
+++ 	(revision )
@@ -1,63 +1,0 @@
-# Makefile for advent
-
-# Where to put the adventure text files, and the binary executable.
-# Need the trailing "/"s.
-TEXTDIR	= /usr/lib/advent/
-BINDIR	= /usr/bin
-
-# Flags you may want to add to CFLAGS:
-# -DHAS_STDC=0 or 1	We have Standard C.  Default=1 iff __STDC__ is nonzero.
-
-CC	= exec cc
-CFLAGS	= -D_POSIX_SOURCE
-LDFLAGS	=  -i
-
-OBJS	= advent.o database.o english.o initial.o itverb.o score.o\
-	travel.o turn.o utility.o verb.o vocab.o
-
-DAT	= advent1.dat advent2.dat advent3.dat advent4.dat
-INSTDAT	= $(TEXTDIR)advent1.dat $(TEXTDIR)advent2.dat \
-	  $(TEXTDIR)advent3.dat $(TEXTDIR)advent4.dat
-
-all:	$(DAT) advent
-
-install:	$(TEXTDIR) $(INSTDAT) $(BINDIR)/advent
-
-$(TEXTDIR):
-	install -d -o bin $(TEXTDIR)
-
-$(TEXTDIR)advent1.dat:	advent1.dat
-	install -c -o bin $? $@
-
-$(TEXTDIR)advent2.dat:	advent2.dat
-	install -c -o bin $? $@
-
-$(TEXTDIR)advent3.dat:	advent3.dat
-	install -c -o bin $? $@
-
-$(TEXTDIR)advent4.dat:	advent4.dat
-	install -c -o bin $? $@
-
-$(BINDIR)/advent:	advent
-	install -cs -o bin $? $@
-
-advent:	$(OBJS)
-	$(CC) $(LDFLAGS) -o advent $(OBJS)
-
-setup: setup.c advent.h
-	$(CC) $(CFLAGS) $(LDFLAGS) -o setup setup.c
- 
-advtext.h advent1.dat advent2.dat advent3.dat advent4.dat: \
-		setup advent1.txt advent2.txt advent3.txt advent4.txt
-	./setup
-
-advent.o: advent.h advdec.h advent.c
-	$(CC) -c $(CFLAGS) -DTEXTDIR='"$(TEXTDIR)"' advent.c
-
-database.o: advent.h advdec.h advtext.h
-travel.o: advent.h advdec.h advcave.h
-initial.o english.o itverb.o score.o turn.o utility.o\
-	verb.o vocab.o: advent.h advdec.h
-
-clean:	
-	@rm -f *.o *.BAK *.dat advtext.h core advent setup
Index: trunk/minix/commands/advent/advcave.h
===================================================================
--- trunk/minix/commands/advent/advcave.h	(revision 9)
+++ 	(revision )
@@ -1,1357 +1,0 @@
-/*	header ADVCAVE.H					*/
-
-
-/**	WARNING: the travel array for the cave is stored as an
- *   array of 1.. LONG INTEGERS.  This requires 32 bit LONG INTEGERS.
- *   These values are used in database.c "gettrav".
- *   tcond*1000000 + tdest*1000 + tverb = value stored
- */
-
-static long room1[] = {
-		       2002, 2044, 2029, 2056,
-		       3003, 3012, 3019, 3043,
-		       4005, 4013, 4014, 4046, 4030,
-		       5006, 5045, 5043,
-		       8063,
-		       147081,
-		       157052, 157084,
-		       0};
-static long room2[] = {
-		       1002, 1012, 1007, 1043, 1045, 1030,
-		       30146006,
-		       5006, 5045, 5046,
-		       146044,
-		       0};
-static long room3[] = {
-		       1011, 1032, 1044,
-		       11062,
-		       33065,
-		       467785085,
-		       202085,
-		       79005, 79014,
-		       238057, 238003, 238019,
-		       0};
-static long room4[] = {
-		       1004, 1012, 1045,
-		       5006, 5043, 5044, 5029,
-		       7005, 7046, 7030,
-		       8063,
-		       0};
-static long room5[] = {
-		       4009, 4043, 4030,
-		       50005006, 50005007, 50005045,
-		       6006,
-		       5044, 5046,
-		       0};
-static long room6[] = {
-		       1002, 1045,
-		       4009, 4043, 4044, 4030,
-		       5006, 5046,
-		       0};
-static long room7[] = {
-		       1012,
-		       4004, 4045,
-		       5006, 5043, 5044,
-		       8005, 8015, 8016, 8046,
-		       595060, 595014, 595030,
-		       0};
-static long room8[] = {
-		       5006, 5043, 5044, 5046,
-		       1012,
-		       7004, 7013, 7045,
-		       303009003, 303009019, 303009030,
-		       593003,
-		       0};
-static long room9[] = {
-		       303008011, 303008029,
-		       593011,
-		       10017, 10018, 10019, 10044,
-		       14031,
-		       11051,
-		       0};
-static long room10[] = {
-			9011, 9020, 9021, 9043,
-			11019, 11022, 11044, 11051,
-			14031,
-			0};
-static long room11[] = {
-			303008063,
-			9064,
-			10017, 10018, 10023, 10024, 10043,
-			12025, 12019, 12029, 12044,
-			3062,
-			14031,
-			0};
-static long room12[] = {
-			303008063,
-			9064,
-			11030, 11043, 11051,
-			13019, 13029, 13044,
-			14031,
-			0};
-static long room13[] = {
-			303008063,
-			9064,
-			11051,
-			12025, 12043,
-			14023, 14031, 14044,
-			0};
-static long room14[] = {
-			303008063,
-			9064,
-			11051,
-			13023, 13043,
-			150020030, 150020031, 150020034,
-			15030,
-			16033, 16044,
-			0};
-static long room15[] = {
-			18036, 18046,
-			17007, 17038, 17044,
-			19010, 19030, 19045,
-			150022029, 150022031, 150022034, 150022035,
-			150022023, 150022043, 150022056, 150022010,
-			14029,
-			33055,
-			0};
-static long room16[] = {
-			14001,
-			0};
-static long room17[] = {
-			15038, 15043,
-			312596039,
-			412021007,
-		412597041, 412597042, 412597044, 412597069, 412597089,
-			27041,
-			0};
-static long room18[] = {
-			15038, 15011, 15045,
-			0};
-static long room19[] = {
-			150237029, 150237031, 150237034, 150237035,
-			150237043, 150237056, 150237010,
-			15025,
-			15010, 15029, 15043,
-			75556047,
-			311143047,
-			311028045, 311028036,
-			311029046, 311029037,
-			311030044, 311030007,
-			32045,
-			15074049,
-			211032049,
-			74066,
-			0};
-static long room20[] = {
-			1,
-			0};
-static long room21[] = {
-			1,
-			0};
-static long room22[] = {
-			15001,
-			0};
-static long room23[] = {
-			67043, 67042,
-			68044, 68061,
-			25030, 25031,
-			648052,
-			0};
-static long room24[] = {
-			67029, 67011,
-			92027,
-			0};
-static long room25[] = {
-			23029, 23011,
-			724031056,
-			26056,
-			0};
-static long room26[] = {
-			88001,
-			0};
-static long room27[] = {
-			312596039,
-			412021007,
-		412597041, 412597042, 412597043, 412597069, 412597089,
-			17041,
-			40045,
-			41044,
-			0};
-static long room28[] = {
-			19038, 19011, 19046,
-			33045, 33055,
-			36030, 36052,
-			0};
-static long room29[] = {
-			19038, 19011, 19045,
-			0};
-static long room30[] = {
-			19038, 19011, 19043,
-			62044, 62029,
-			0};
-static long room31[] = {
-			524089001,
-			90001,
-			0};
-static long room32[] = {
-			19001,
-			0};
-static long room33[] = {
-			3065,
-			28046,
-			34043, 34053, 34054,
-			35044,
-			159302071,
-			100071,
-			0};
-static long room34[] = {
-			33030, 33055,
-			15029,
-			0};
-static long room35[] = {
-			33043, 33055,
-			20039,
-			0};
-static long room36[] = {
-			37043, 37017,
-			28029, 28052,
-			39044,
-			65070,
-			0};
-static long room37[] = {
-			36044, 36017,
-			38030, 38031, 38056,
-			0};
-static long room38[] = {
-			37056, 37029, 37011,
-			595060, 595014, 595030, 595004, 595005,
-			0};
-static long room39[] = {
-			36043, 36023,
-			64030, 64052, 64058,
-			65070,
-			0};
-static long room40[] = {
-			41001,
-			0};
-static long room41[] = {
-			42046, 42029, 42023, 42056,
-			27043,
-			59045,
-			60044, 60017,
-			0};
-static long room42[] = {
-			41029,
-			42045,
-			43043,
-			45046,
-			80044,
-			0};
-static long room43[] = {
-			42044,
-			44046,
-			45043,
-			0};
-static long room44[] = {
-			43043,
-			48030,
-			50046,
-			82045,
-			0};
-static long room45[] = {
-			42044,
-			43045,
-			46043,
-			47046,
-			87029, 87030,
-			0};
-static long room46[] = {
-			45044, 45011,
-			0};
-static long room47[] = {
-			45043, 45011,
-			0};
-static long room48[] = {
-			44029, 44011,
-			0};
-static long room49[] = {
-			50043,
-			51044,
-			0};
-static long room50[] = {
-			44043,
-			49044,
-			51030,
-			52046,
-			0};
-static long room51[] = {
-			49044,
-			50029,
-			52043,
-			53046,
-			0};
-static long room52[] = {
-			50044,
-			51043,
-			52046,
-			53029,
-			55045,
-			86030,
-			0};
-static long room53[] = {
-			51044,
-			52045,
-			54046,
-			0};
-static long room54[] = {
-			53044, 53011,
-			0};
-static long room55[] = {
-			52044,
-			55045,
-			56030,
-			57043,
-			0};
-static long room56[] = {
-			55029, 55011,
-			0};
-static long room57[] = {
-			13030, 13056,
-			55044,
-			58046,
-			83045,
-			84043,
-			0};
-static long room58[] = {
-			57043, 57011,
-			0};
-static long room59[] = {
-			27001,
-			0};
-static long room60[] = {
-			41043, 41029, 41017,
-			61044,
-			62045, 62030, 62052,
-			50191046, 50191033,
-			392173046, 392173033,
-			172046, 172033,
-			648056,
-			0};
-static long room61[] = {
-			60043,
-			62045,
-			100107046,
-			0};
-static long room62[] = {
-			60044,
-			63045,
-			30043,
-			61046,
-			0};
-static long room63[] = {
-			62046, 62011,
-			0};
-static long room64[] = {
-			39029, 39056, 39059,
-			65044, 65070,
-			103045, 103074,
-			106043,
-			0};
-static long room65[] = {
-			64043,
-			66044,
-			40556046,
-			68061,
-			40556029,
-			50070029,
-			39029,
-			40556045,
-			50072045,
-			71045,
-			50556030,
-			106030,
-			71025,
-			0};
-static long room66[] = {
-			65047,
-			67044,
-			80556046,
-			77025,
-			96043,
-			50556050,
-			97072,
-			0};
-static long room67[] = {
-			66043,
-			23044, 23042,
-			24030, 24031,
-			0};
-static long room68[] = {
-			23046,
-			69029, 69056,
-			65045,
-			0};
-static long room69[] = {
-			68030, 68061,
-			331120046,
-			119046,
-			109045,
-			113075,
-			0};
-static long room70[] = {
-			71045,
-			65030, 65023,
-			111046,
-			0};
-static long room71[] = {
-			65048,
-			70046,
-			110045,
-			0};
-static long room72[] = {
-			65070,
-			118047,
-			73045,
-			97049, 97072,
-			0};
-static long room73[] = {
-			72046, 72017, 72011,
-			0};
-static long room74[] = {
-			19043,
-			331120044,
-			121044,
-			75030,
-			0};
-static long room75[] = {
-			76046,
-			77045,
-			0};
-static long room76[] = {
-			75045,
-			0};
-static long room77[] = {
-			75043,
-			78044,
-			66045, 66017,
-			0};
-static long room78[] = {
-			77046,
-			0};
-static long room79[] = {
-			3001,
-			0};
-static long room80[] = {
-			42045,
-			80044, 80046,
-			81043,
-			0};
-static long room81[] = {
-			80044, 80011,
-			0};
-static long room82[] = {
-			44046, 44011,
-			0};
-static long room83[] = {
-			57046,
-			84043,
-			85044,
-			0};
-static long room84[] = {
-			57045,
-			83044,
-			114050,
-			0};
-static long room85[] = {
-			83043, 83011,
-			0};
-static long room86[] = {
-			52029, 52011,
-			0};
-static long room87[] = {
-			45029, 45030,
-			0};
-static long room88[] = {
-			25030, 25056, 25043,
-			20039,
-			92044, 92027,
-			0};
-static long room89[] = {
-			25001,
-			0};
-static long room90[] = {
-			23001,
-			0};
-static long room91[] = {
-			95045, 95073, 95023,
-			72030, 72056,
-			0};
-static long room92[] = {
-			88046,
-			93043,
-			94045,
-			0};
-static long room93[] = {
-			92046, 92027, 92011,
-			0};
-static long room94[] = {
-			92046, 92027, 92023,
-			341095045, 341095003, 341095073,
-			611045,
-			0};
-static long room95[] = {
-			94046, 94011,
-			92027,
-			91044,
-			145030, 145039, 145080, 145052,
-			0};
-static long room96[] = {
-			66044, 66011,
-			0};
-static long room97[] = {
-			66048,
-			72043, 72017,
-			98029, 98045, 98073,
-			0};
-static long room98[] = {
-			235047,
-			97046, 97072,
-			99044,
-			3142029, 3142049, 3142056, 3142079,
-			75702029, 75702049, 75702056, 75702079,
-			703029, 703049, 703056, 703079,
-			141078,
-			0};
-static long room99[] = {
-			98050, 98073,
-			301043, 301023,
-			100043,
-			0};
-static long room100[] = {
-			 301044, 301023, 301011,
-			 99044,
-			 159302071, 159302055,
-			 33071, 33055,
-			 101047, 101022,
-			 0};
-static long room101[] = {
-			 100046, 100071, 100011,
-			 0};
-static long room102[] = {
-			 103030, 103074, 103011,
-			 0};
-static long room103[] = {
-			 388196029, 388196038,
-			 102029, 102038,
-			 104030,
-			 114618046,
-			 115619046,
-			 64046,
-			 0};
-static long room104[] = {
-			 103029, 103074,
-			 105030,
-			 0};
-static long room105[] = {
-			 104029, 104011,
-			 103074,
-			 0};
-static long room106[] = {
-			 64029,
-			 65044,
-			 108043,
-			 0};
-static long room107[] = {
-			 131046,
-			 132049,
-			 133047,
-			 134048,
-			 135029,
-			 136050,
-			 137043,
-			 138044,
-			 139045,
-			 61030,
-			 0};
-static long room108[] = {
-			 90556043, 90556045, 90556046, 90556047,
-			 90556048, 90556049, 90556050, 90556029,
-			 90556030,
-			 106043,
-			 626044,
-			 0};
-static long room109[] = {
-			 69046,
-			 113045, 113075,
-			 0};
-static long room110[] = {
-			 71044,
-			 20039,
-			 0};
-static long room111[] = {
-			 70045,
-			 40050030, 40050039, 40050056,
-			 50053030,
-			 45030,
-			 0};
-static long room112[] = {
-			 131049,
-			 132045,
-			 133043,
-			 134050,
-			 135048,
-			 136047,
-			 137044,
-			 138030,
-			 139029,
-			 140046,
-			 0};
-static long room113[] = {
-			 109046, 109011,
-			 0};
-static long room114[] = {
-			 84048,
-			 0};
-static long room115[] = {
-			 116049, 116042, 116069,
-			 212019, 212003, 212045,
-			 0};
-static long room116[] = {
-			 115047, 115042, 115069,
-			 212019, 212003,
-			 593030,
-			 0};
-static long room117[] = {
-			 118049,
-		233660041, 233660042, 233660069, 233660047, 233660089,
-			 332661041,
-			 303041,
-			 332021039,
-			 596039,
-			 0};
-static long room118[] = {
-			 72030,
-			 117029,
-			 0};
-static long room119[] = {
-			 69045, 69011,
-			 653043, 65307,
-			 0};
-static long room120[] = {
-			 69045,
-			 74043,
-			 0};
-static long room121[] = {
-			 74043, 74011,
-			 653045, 653007,
-			 0};
-static long room122[] = {
-			 123047,
-		233660041, 233660042, 233660069, 233660049, 233660089,
-			 303041,
-			 596039,
-			 124077,
-			 126028,
-			 129040,
-			 0};
-static long room123[] = {
-			 122044,
-			 124043, 124077,
-			 126028,
-			 129040,
-			 0};
-static long room124[] = {
-			 123044,
-			 125047, 125036,
-			 128048, 128037, 128030,
-			 126028,
-			 129040,
-			 0};
-static long room125[] = {
-			 124046, 124077,
-			 126045, 126028,
-			 127043, 127017,
-			 0};
-static long room126[] = {
-			 125046, 125023, 125011,
-			 124077,
-			 610030, 610039,
-			 0};
-static long room127[] = {
-			 125044, 125011, 125017,
-			 124077,
-			 126028,
-			 0};
-static long room128[] = {
-			 124045, 124029, 124077,
-			 129046, 129030, 129040,
-			 126028,
-			 0};
-static long room129[] = {
-			 128044, 128029,
-			 124077,
-			 130043, 130019, 130040, 130003,
-			 126028,
-			 0};
-static long room130[] = {
-			 129044, 129011,
-			 124077,
-			 126028,
-			 0};
-static long room131[] = {
-			 107044,
-			 132048,
-			 133050,
-			 134049,
-			 135047,
-			 136029,
-			 137030,
-			 138045,
-			 139046,
-			 112043,
-			 0};
-static long room132[] = {
-			 107050,
-			 131029,
-			 133045,
-			 134046,
-			 135044,
-			 136049,
-			 137047,
-			 138043,
-			 139030,
-			 112048,
-			 0};
-static long room133[] = {
-			 107029,
-			 131030,
-			 132044,
-			 134047,
-			 135049,
-			 136043,
-			 137045,
-			 138050,
-			 139048,
-			 112046,
-			 0};
-static long room134[] = {
-			 107047,
-			 131045,
-			 132050,
-			 133048,
-			 135043,
-			 136030,
-			 137046,
-			 138029,
-			 139044,
-			 112049,
-			 0};
-static long room135[] = {
-			 107045,
-			 131048,
-			 132030,
-			 133046,
-			 134043,
-			 136044,
-			 137049,
-			 138047,
-			 139050,
-			 112029,
-			 0};
-static long room136[] = {
-			 107043,
-			 131044,
-			 132029,
-			 133049,
-			 134030,
-			 135046,
-			 137050,
-			 138048,
-			 139047,
-			 112045,
-			 0};
-static long room137[] = {
-			 107048,
-			 131047,
-			 132046,
-			 133030,
-			 134029,
-			 135050,
-			 136045,
-			 138049,
-			 139043,
-			 112044,
-			 0};
-static long room138[] = {
-			 107030,
-			 131043,
-			 132047,
-			 133029,
-			 134044,
-			 135045,
-			 136046,
-			 137048,
-			 139049,
-			 112050,
-			 0};
-static long room139[] = {
-			 107049,
-			 131050,
-			 132043,
-			 133044,
-			 134045,
-			 135030,
-			 136048,
-			 137029,
-			 138046,
-			 112047,
-			 0};
-static long room140[] = {
-			 112045, 112011,
-			 0};
-static long room141[] = {
-			 142029, 142043, 142056, 142078, 142079,
-			 0};
-static long room142[] = {
-			 98043, 98030, 98007, 98079,
-			 141008, 141044, 141078,
-			 0};
-static long room143[] = {
-			 19044, 19011,
-			 144043,
-			 0};
-static long room144[] = {
-			 143044, 143008,
-			 19011,
-			 0};
-static long room145[] = {
-			 141001,
-			 0};
-static long room146[] = {
-			 2043, 2029, 2002, 2056,
-			 50006046, 50006006,
-			 146046, 146006,
-			 147044,
-			 148045,
-			 0};
-static long room147[] = {
-			 146043, 146046,
-			 148045,
-			 153044,
-			 157052,
-			 3012,
-			 157084,
-			 0};
-static long room148[] = {
-			 50147046,
-			 146046,
-			 149043, 149044, 149045,
-			 3012,
-			 166091,
-			 0};
-static long room149[] = {
-			 149046,
-			 151043,
-			 150044,
-			 152045,
-			 0};
-static long room150[] = {
-			 151045, 151046,
-			 149043, 149044,
-			 0};
-static long room151[] = {
-			 148043,
-			 152044,
-			 150045,
-			 149046,
-			 0};
-static long room152[] = {
-			 151043,
-			 150046,
-			 0};
-static long room153[] = {
-			 154045,
-			 239046,
-			 147043,
-			 3012,
-			 0};
-static long room154[] = {
-			 50155045,
-			 157045, 157030,
-			 155029,
-			 153046,
-			 3012,
-			 0};
-static long room155[] = {
-			 154030, 154008, 154046,
-			 156039,
-			 3012,
-			 0};
-static long room156[] = {
-			 1,
-			 0};
-static long room157[] = {
-			 227019, 227043,
-			 154011, 154046, 154029,
-			 3012,
-			 0};
-static long room158[] = {
-			 229044, 229034, 229030,
-			 157011,
-			 161082,
-			 725056, 725029,
-			 726083,
-			 747003, 747019, 747043, 747064,
-			 0};
-static long room159[] = {
-			 732011, 732044, 732034,
-			 0};
-static long room160[] = {
-			 343167043, 343167019, 343167003,
-			 738043,
-			 162082,
-			 723044, 723056, 723030,
-			 165039,
-			 0};
-static long room161[] = {
-			 304001,
-			 0};
-static long room162[] = {
-			 304001,
-			 0};
-static long room163[] = {
-			 304001,
-			 0};
-static long room164[] = {
-			 304001,
-			 0};
-static long room165[] = {
-			 1,
-			 0};
-static long room166[] = {
-			 747003, 747011, 747019, 747044,
-			 148232043, 148232069, 148232041, 148232042,
-			 148169047,
-			 148233046,
-			 148234045,
-			 717043, 717069, 717041, 717042, 717047,
-			 448164082,
-			 720082,
-			 0};
-static long room167[] = {
-			 163082,
-			 343160044, 343160011, 343160003, 343160019,
-			 738044,
-			 722043, 722069, 722041, 722042,
-			 0};
-static long room168[] = {
-			 448170048, 448170029, 448170023,
-			 719048, 719029, 719023,
-			 148169045,
-			 148192046,
-			 148166044, 148166069, 148166041, 148166042,
-			 717044, 717045, 717046,
-			 0};
-static long room169[] = {
-			 148168046,
-			 148166049,
-			 717049, 717046,
-			 448179023, 448179043, 448179029,
-			 719023, 719029,
-			 0};
-static long room170[] = {
-			 171043, 171029,
-			 168044, 168030,
-			 0};
-static long room171[] = {
-			 170050, 170030,
-			 180043, 180029,
-			 0};
-static long room172[] = {
-			 60045,
-			 174046,
-			 0};
-static long room173[] = {
-			 60045,
-			 0};
-static long room174[] = {
-			 392178047,
-			 172047, 172033,
-			 175050,
-			 0};
-static long room175[] = {
-			 177045,
-			 174043,
-			 176031, 176030, 176056,
-			 0};
-static long room176[] = {
-			 175029, 175056, 175011, 175008,
-			 0};
-static long room177[] = {
-			 60030, 60056, 60039,
-			 175046, 175008,
-			 0};
-static long room178[] = {
-			 174001,
-			 0};
-static long room179[] = {
-			 169030, 169044,
-			 198029, 198043, 198014,
-			 0};
-static long room180[] = {
-			 171044,
-			 182029, 182056,
-			 213043,
-			 0};
-static long room181[] = {
-			 227001,
-			 0};
-static long room182[] = {
-			 180044,
-			 183043,
-			 0};
-static long room183[] = {
-			 182044,
-			 50184043,
-			 186043,
-			 185046,
-			 187045,
-			 0};
-static long room184[] = {
-			 183049,
-			 188048,
-			 0};
-static long room185[] = {
-			 183045,
-			 0};
-static long room186[] = {
-			 183050,
-			 188047,
-			 0};
-static long room187[] = {
-			 183044,
-			 188043,
-			 0};
-static long room188[] = {
-			 187045,
-			 184044,
-			 65190049, 65190030,
-			 186049,
-			 305019, 305003,
-			 0};
-static long room189[] = {
-			 188011, 188008,
-			 0};
-static long room190[] = {
-			 422306069, 422306045, 422306042, 422306089,
-			 661069,
-			 188029, 188008,
-			 0};
-static long room191[] = {
-			 60045,
-			 0};
-static long room192[] = {
-			 148166045,
-			 148168047,
-			 717045, 717047,
-			 448197043,
-			 720043,
-			 0};
-static long room193[] = {
-			 197044,
-			 0};
-static long room194[] = {
-			 224044,
-			 0};
-static long room195[] = {
-			 196052, 196053, 196046, 196069, 196036,
-			 224044,
-			 0};
-static long room196[] = {
-			 103030, 103074,
-			 114618052, 114618053, 114618045, 114618069,
-			 195052,
-			 0};
-static long room197[] = {
-			 193043,
-			 192044,
-			 0};
-static long room198[] = {
-			 179049, 179014, 179005, 179023,
-			 203030, 203043,
-			 402200046, 402200029,
-			 772046, 772029,
-			 0};
-static long room199[] = {
-			 198001,
-			 0};
-static long room200[] = {
-			 198044,
-			 201043, 201029,
-			 0};
-static long room201[] = {
-			 402200044, 402200030,
-			 772044, 772030,
-			 202043,
-			 230045,
-			 0};
-static long room202[] = {
-			 201044,
-			 467785085,
-			 205085,
-			 206043,
-			 0};
-static long room203[] = {
-			 447199030, 447199043, 447199088,
-			 204030, 204043, 204088,
-			 198029, 198044,
-			 0};
-static long room204[] = {
-			 203029, 203044, 203008, 203011,
-			 0};
-static long room205[] = {
-			 219045,
-			 467785085,
-			 202085,
-			 226039,
-			 0};
-static long room206[] = {
-			 207045, 207017,
-			 202044,
-			 648029, 648052,
-			 0};
-static long room207[] = {
-			 208045,
-			 206046,
-			 0};
-static long room208[] = {
-			 236043,
-			 207046, 207017,
-			 209044,
-			 793069, 793042, 793045,
-			 0};
-static long room209[] = {
-			 208043,
-			 210029, 210056,
-			 0};
-static long room210[] = {
-			 211030, 211043,
-			 209044,
-			 0};
-static long room211[] = {
-			 210029, 210008, 210044,
-			 72030, 72043,
-			 0};
-static long room212[] = {
-			 115011, 115008, 115046,
-			 0};
-static long room213[] = {
-			 206030, 206052,
-			 180044, 180008,
-			 0};
-static long room214[] = {
-			 148166046,
-			 148169048,
-			 717046, 717048,
-			 448215047,
-			 720047,
-			 0};
-static long room215[] = {
-			 214049,
-			 216029,
-			 0};
-static long room216[] = {
-			 215030,
-			 217043, 217029,
-			 0};
-static long room217[] = {
-			 216044, 216030, 216011,
-			 218043, 218031,
-			 0};
-static long room218[] = {
-			 217008, 217044,
-			 230029, 230056,
-			 0};
-static long room219[] = {
-			 205046, 205089,
-			 222045, 222090,
-			 220043,
-			 221044,
-			 3092,
-			 0};
-static long room220[] = {
-			 219044,
-			 225043,
-			 0};
-static long room221[] = {
-			 219043,
-			 0};
-static long room222[] = {
-			 219046,
-			 223029,
-			 3092,
-			 0};
-static long room223[] = {
-			 222030,
-			 224029,
-			 0};
-static long room224[] = {
-			 223030, 223052,
-			 338195043,
-			 194043,
-			 0};
-static long room225[] = {
-			 220044,
-			 0};
-static long room226[] = {
-			 1,
-			 0};
-static long room227[] = {
-			 157044, 157011, 157029,
-			 398228043, 398228019, 398228030,
-			 181043, 181019, 181030,
-			 0};
-static long room228[] = {
-			 792045, 792046, 792004, 792005, 792033,
-			 227029, 227044, 227011,
-			 229039,
-			 786043, 786019, 786042, 786069, 786041,
-			 0};
-static long room229[] = {
-			 792045, 792046, 792004, 792005, 792033,
-			 228039,
-			 786044, 786011, 786042, 786069, 796041,
-			 158043, 158019, 158034,
-			 0};
-static long room230[] = {
-			 65218030, 65218039,
-			 231030, 231039,
-			 201046, 201017,
-			 0};
-static long room231[] = {
-			 1,
-			 0};
-static long room232[] = {
-			 168001,
-			 0};
-static long room233[] = {
-			 192001,
-			 0};
-static long room234[] = {
-			 214001,
-			 0};
-static long room235[] = {
-			 422306069, 422306046, 422306042, 422306089,
-			 661069,
-			 98044,
-			 0};
-static long room236[] = {
-			 208044,
-			 0};
-static long room237[] = {
-			 19001,
-			 0};
-static long room238[] = {
-			 3011, 3064,
-			 0};
-static long room239[] = {
-			 153045, 153047,
-			 240093,
-			 0};
-static long room240[] = {
-			 239047, 239042, 239069, 239093,
-			 241030,
-			 0};
-static long room241[] = {
-			 240029,
-			 242044,
-			 0};
-static long room242[] = {
-			 241043,
-			 243049,
-			 244044,
-			 246050,
-			 0};
-static long room243[] = {
-			 242047,
-			 244045,
-			 247050,
-			 0};
-static long room244[] = {
-			 242043,
-			 243046,
-			 245044,
-			 246045,
-			 0};
-static long room245[] = {
-			 243046,
-			 244043,
-			 246045,
-			 247044,
-			 0};
-static long room246[] = {
-			 242048,
-			 245046,
-			 247049,
-			 0};
-static long room247[] = {
-			 243048,
-			 245043,
-			 246047,
-			 307044,
-			 0};
-static long room248[] = {
-			 247043,
-			 0};
-
-static long *cave[MAXLOC] = {
-			     room1, room2, room3, room4,
-			     room5, room6, room7, room8, room9,
-			     room10, room11, room12, room13, room14,
-			     room15, room16, room17, room18, room19,
-			     room20, room21, room22, room23, room24,
-			     room25, room26, room27, room28, room29,
-			     room30, room31, room32, room33, room34,
-			     room35, room36, room37, room38, room39,
-			     room40, room41, room42, room43, room44,
-			     room45, room46, room47, room48, room49,
-			     room50, room51, room52, room53, room54,
-			     room55, room56, room57, room58, room59,
-			     room60, room61, room62, room63, room64,
-			     room65, room66, room67, room68, room69,
-			     room70, room71, room72, room73, room74,
-			     room75, room76, room77, room78, room79,
-			     room80, room81, room82, room83, room84,
-			     room85, room86, room87, room88, room89,
-			     room90, room91, room92, room93, room94,
-			     room95, room96, room97, room98, room99,
-			  room100, room101, room102, room103, room104,
-			  room105, room106, room107, room108, room109,
-			  room110, room111, room112, room113, room114,
-			  room115, room116, room117, room118, room119,
-			  room120, room121, room122, room123, room124,
-			  room125, room126, room127, room128, room129,
-			  room130, room131, room132, room133, room134,
-			  room135, room136, room137, room138, room139,
-			  room140, room141, room142, room143, room144,
-			  room145, room146, room147, room148, room149,
-			  room150, room151, room152, room153, room154,
-			  room155, room156, room157, room158, room159,
-			  room160, room161, room162, room163, room164,
-			  room165, room166, room167, room168, room169,
-			  room170, room171, room172, room173, room174,
-			  room175, room176, room177, room178, room179,
-			  room180, room181, room182, room183, room184,
-			  room185, room186, room187, room188, room189,
-			  room190, room191, room192, room193, room194,
-			  room195, room196, room197, room198, room199,
-			  room200, room201, room202, room203, room204,
-			  room205, room206, room207, room208, room209,
-			  room210, room211, room212, room213, room214,
-			  room215, room216, room217, room218, room219,
-			  room220, room221, room222, room223, room224,
-			  room225, room226, room227, room228, room229,
-			  room230, room231, room232, room233, room234,
-			  room235, room236, room237, room238, room239,
-			  room240, room241, room242, room243, room244,
-			     room245, room246, room247, room248};
Index: trunk/minix/commands/advent/advdec.h
===================================================================
--- trunk/minix/commands/advent/advdec.h	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-/*	header ADVDEC.H						*
- *	WARNING: GLOBAL (EXTERNAL) declarations for adventure	*/
-
-#ifndef EXTERN			/* #define as '' to define the variables */
-#define EXTERN extern
-#endif
-
-EXTERN boolean gaveup;		/* TRUE if he quits early	*/
-EXTERN FILE *fd1, *fd2, *fd3, *fd4;
-
-/*
-  English variables
-*/
-EXTERN char *vtxt[MAXWORDS], *iotxt[MAXITEMS], *otxt[MAXITEMS];
-EXTERN int verbs[MAXWORDS], objs[MAXITEMS], iobjs[MAXITEMS];
-EXTERN int vrbx, objx, iobx;
-EXTERN int verb, object, motion, iobj, prep;
-EXTERN boolean newtravel, is_wiz;
-
-/*
-  Play variables
-*/
-extern int plac[MAXOBJ];	/* initial location	 */
-extern int fixd[MAXOBJ];
-struct playinfo {
-  int turns;
-  int loc, oldloc, oldloc2, newloc;	/* location variables */
-  long loc_attrib[MAXLOC+1];	/* location status	 */
-  int place[MAXOBJ];		/* object location	 */
-  int fixed[MAXOBJ];		/* second object loc	 */
-  int weight[MAXOBJ];
-  int atloc[MAXLOC+1];
-  int link[MAXOBJ * 2];
-  int holder[MAXOBJ];
-  int hlink[MAXOBJ];
-  int visited[MAXLOC+1];		/* >0 if has been here	 */
-  int prop[MAXOBJ];		/* status of object	 */
-  long obj_state[MAXOBJ];
-  long points[MAXOBJ];
-  int hinted[HNTMAX+1];
-  int hints[HNTMAX+1][5];
-  int hintlc[HNTMAX+1];
-  int tally, tally2;		/* item counts		 */
-  int limit;			/* time limit		 */
-  int lmwarn;			/* lamp warning flag	 */
-  int wzdark, closing, closed;	/* game state flags	 */
-  int holding;			/* count of held items	 */
-  int detail;			/* LOOK count		 */
-  int knfloc;			/* knife location	 */
-  int clock, clock2, panic;	/* timing variables	 */
-  int dloc[DWARFMAX+1];		/* dwarf locations	 */
-  int dflag;			/* dwarf flag		 */
-  int dseen[DWARFMAX+1];	/* dwarf seen flag	 */
-  int odloc[DWARFMAX+1];	/* dwarf old locations	 */
-  int daltloc;			/* alternate appearance	 */
-  int dkill;			/* dwarves killed	 */
-  int chloc, chloc2;		/* chest locations	 */
-  int bonus;			/* to pass to end	 */
-  int numdie;			/* number of deaths	 */
-  int foobar;			/* fee fie foe foo...	 */
-  int combo;			/* combination for safe  */
-  boolean terse;
-  int abbnum;
-  int health;
-  int chase;
-  boolean flg239;
-
-
-  int lastglob;			/* to get space req.	 */
-};
-extern struct playinfo g;
Index: trunk/minix/commands/advent/advent.c
===================================================================
--- trunk/minix/commands/advent/advent.c	(revision 9)
+++ 	(revision )
@@ -1,136 +1,0 @@
-/**     Adventure translated from Fortran to "C"
-  and ported to Minix by:
-  Robert R. Hall
-  San Diego,  Calif  92115
-  hall@crash.cts.com
- */
-
-/**	program ADVENT.C					*
- *		"advent.c" allocates GLOBAL storage space by	*
- *		#defining EXTERN before #including "advdec.h".	*/
-
-
-#include        <string.h>
-#include	<ctype.h>
-#include	<stdlib.h>
-#include	<time.h>
-#include        <stdio.h>
-#include	<errno.h>
-#include	"advent.h"		/* #define preprocessor equates	 */
-#include	"advdec.h"
-
-#ifndef TEXTDIR
-#define TEXTDIR ""
-#endif
-
-char textdir[] = TEXTDIR;		/* directory where text files
-					   live. */
-
-_PROTOTYPE(int main, (int, char **));
-_PROTOTYPE(static void opentxt, (void));
-_PROTOTYPE(static void file_error, (char *));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-    opentxt();
-    initialize();
-    rspeak(325);
-    if (argc == 2)
-	restore(argv[1]);
-    else {
-	g.hinted[3] = yes(65, 1, 0);
-	g.limit = (g.hinted[3] ? 800 : 550);
-    }
-    gaveup = FALSE;
-    srand((unsigned) time(NULL));	/* seed random	 */
-    while (!gaveup)
-	turn();
-    fclose(fd1);
-    fclose(fd2);
-    fclose(fd3);
-    fclose(fd4);
-    return (EXIT_SUCCESS);		/* exit = ok	 */
-}					/* main		 */
-
-/*
-  Open advent?.txt files
-*/
-static void opentxt()
-{
-    static char filename[sizeof(textdir) + 16];
-    static FILE **fp[] = {0, &fd1, &fd2, &fd3, &fd4};
-    int i;
-    for (i = 1; i <= 4; i++) {
-	sprintf(filename, "%sadvent%d.dat", textdir, i);
-	*fp[i] = fopen(filename, "r");
-	if (!*fp[i])
-	    file_error(filename);
-    }
-}
-
-/*
-  save adventure game
-*/
-void saveadv(username)
-char *username;
-{
-    int cnt;
-    FILE *savefd;
-
-    savefd = fopen(username, "wb");
-    if (savefd == NULL) {
-	perror(username);
-	return;
-    }
-    cnt = fwrite((void *) &g, 1, sizeof(struct playinfo), savefd);
-    if (cnt != sizeof(struct playinfo)) {
-	fprintf(stderr, "wrote %d of %u bytes\n",
-		cnt, (unsigned) sizeof(struct playinfo));
-	if (ferror(savefd)) {
-	    fprintf(stderr, "errno is: 0x%.4x\n", errno);
-	    perror(username);
-	}
-    }
-    if (fclose(savefd) == -1) {
-	perror(username);
-    }
-    printf("Saved in %s.\n", username);
-    return;
-}
-
-/*
-  restore saved game handler
-*/
-void restore(username)
-char *username;
-{
-    int cnt;
-    FILE *restfd;
-
-    restfd = fopen(username, "rb");
-    if (restfd == NULL)
-	file_error(username);
-    cnt = fread((void *) &g, 1, sizeof(struct playinfo), restfd);
-    if (cnt != sizeof(struct playinfo)) {
-	fprintf(stderr, "read %d bytes, expected %u\n",
-		cnt, (unsigned) sizeof(struct playinfo));
-	if (ferror(restfd)) {
-	    fprintf(stderr, "errno is: 0x%.4x\n", errno);
-	    perror(username);
-	}
-    }
-    if (fclose(restfd) == -1) {
-	perror(username);
-    }
-    printf("Restored from %s.\n", username);
-    return;
-}
-
-static void file_error(filename)
-char *filename;
-{
-    perror(filename);
-    exit(EXIT_FAILURE);
-}
Index: trunk/minix/commands/advent/advent.h
===================================================================
--- trunk/minix/commands/advent/advent.h	(revision 9)
+++ 	(revision )
@@ -1,405 +1,0 @@
-/*	header ADVENT.H						*
- *	WARNING: HEADER file for all adventure modules		*/
-
-#ifndef EXIT_FAILURE
-#define EXIT_FAILURE	1
-#define EXIT_SUCCESS	(!(EXIT_FAILURE))
-#endif
-
-#define INPUTBUFLEN	80	/* Max input line length	 */
-
-typedef int boolean;
-#define FALSE	(0)
-#define TRUE	(!FALSE)
-
-#define	MAXOBJ	123		/* max # of objects in cave	 */
-#define	MAXLOC	248		/* max # of cave locations	 */
-#define	WORDSIZE	20	/* max # of chars in commands	 */
-#define	MAXMSG	408		/* max # of long location descr	 */
-#define HNTMAX	 18		/* max # of hints		 */
-#define HNTMIN	  7		/* hints starting count		 */
-
-#define MAXWORDS 25
-#define MAXITEMS 45
-
-#define CLASS(word) ((word)<0 ? -((-(word)) / 1000) : (word) / 1000)
-#define VAL(word) ((word)<0 ? -((-(word)) % 1000) : (word) % 1000)
-#define	MAXTRAV	(23+1)		/* max # of travel directions from loc	 */
- /* +1 for terminator travel[x].tdest=-1	 */
-#define	DWARFMAX	6	/* max # of nasty dwarves	 */
-#define	MAXDIE	3		/* max # of deaths before close	 */
-#define	MAXTRS	79		/* max # of			 */
-
-#define Y2	33
-/*
-  Object definitions
-*/
-#define ANVIL	91
-#define AXE	28
-#define BATTERIES 39
-#define BEAR	35
-#define BEES	87
-#define BILLBD	116
-#define BIRD	101
-#define BOAT	48
-#define BOOK	110
-#define BOOK2	BOOK + 1
-#define BOOTH	93
-#define BOTTLE	20
-#define BRUSH	114
-#define	CAGE	4
-#define CAKES	107
-#define CARVNG	115
-#define CASK	71
-#define CHAIN	64
-#define CHASM	21
-#define CHASM2	CHASM + 1
-#define CHEST	55
-#define	CLAM	14
-#define CLOAK	47
-#define COINS	54
-#define CROWN	66
-#define DOG	98
-#define	DOOR	41		/* giant door */
-#define DRAGON	31
-#define DWARF	17
-#define EGGS	56
-#define EMERALD 59
-#define FISSURE 12
-#define FLOWER	46
-#define FLY	69
-#define FOOD	19
-#define GNOME	105
-#define GRAIL	70
-#define GRATE	3
-#define HIVE	97
-#define HONEY	96
-#define HORN	52
-#define JEWELS	53
-#define KEYS	102
-#define KNIFE	18
-#define LAMP	2
-#define LYRE	68
-#define MAGAZINE 16
-#define MESSAGE 36
-#define MIRROR	23
-#define MUSHRM	106
-#define NUGGET	50
-#define OIL	83
-#define OIL2	OIL + 1
-#define OYSTER	15
-#define PLAGUE	125
-#define PEARL	61
-#define PHONE	94
-#define PILLOW	10
-#define PLANT	24
-#define PLANT2	PLANT + 1
-#define POLE	9
-#define POSTER	113
-#define PYRAMID 60
-#define RADIUM	119
-#define RING	72
-#define ROCKS	92
-#define ROD	5
-#define ROD2	ROD + 1
-#define RUG	62
-#define	SAFE	112
-#define SAPPHIRE 69
-#define SHIELD	118
-#define SHOES	67
-#define SKEY	90
-#define SLUGS	95
-#define SNAKE	11
-#define SPHERE	120
-#define SPICES	63
-#define SPIDER	121
-#define STEPS	7
-#define STICKS	49
-#define SWORD	65
-#define TABLET	13
-#define TDOOR	42		/* tiny door */
-#define TDOOR2	TDOOR + 1	/* wrought-iron door */
-#define PDOOR	TDOOR2 + 1	/* door to phone booth */
-#define TRIDENT	57
-#define TROLL	33
-#define TROLL2	TROLL + 1
-#define VASE	58
-#define VEND	38
-#define WALL	88
-#define WALL2	WALL + 1
-#define WATER	81		/* in bottle */
-#define WATER2	WATER + 1	/* in cask */
-#define	WINE	85		/* in bottle */
-#define WINE2	WINE + 1	/* in cask */
-#define WUMPUS	99
-
-/*
-  Verb definitions
-*/
-#define	BACK	8
-#define	CAVE	67
-#define	DEPRESSION	63
-#define	ENTRANCE	64
-#define EXIT	11
-#define	NULLX	21
-
-/*
-  Action verb definitions
-*/
-#define TAKE	1
-#define DROP	2
-#define SAY	3
-#define OPEN	4
-#define NOTHING 5
-#define CLOSE   6
-#define ON	7
-#define OFF	8
-#define WAVE	9
-#define CALM	10
-#define WALK	11
-#define KILL	12
-#define POUR	13
-#define EAT	14
-#define DRINK	15
-#define RUB	16
-#define	THROW	17
-#define QUIT	18
-#define FIND	19
-#define INVENTORY 20
-#define FEED	21
-#define FILL	22
-#define BLAST	23
-#define SCORE	24
-#define FOO	25
-#define BRIEF	26
-#define READ	27
-#define BREAK	28
-#define WAKE	29
-#define SUSPEND 30
-#define RESTORE	31
-#define YANK	32
-#define WEAR	33
-#define HIT	34
-#define ANSWER 35
-#define BLOW	36
-#define LEAVE	37
-#define YELL	38
-#define DIAL	39
-#define PLAY	40
-#define PICK	41
-#define PUT	42
-#define TURN	43
-#define GET	44
-#define INSRT	45
-#define REMOVE  46
-#define BURN	47
-#define GRIPE	48
-#define LOCK	49
-#define UNLOCK	50
-#define HEALTH	51
-#define LOOK	52
-#define COMBO	53
-#define SWEEP	54
-#define TERSE	55
-#define	WIZ	56
-#define MAP	57
-#define GATE	58
-#define PIRLOC	59
-
-#define GO	11
-#define SHUT    6
-#define LOG     33
-
-#define MOTION	0			/* CLASSD */
-#define NOUN	1			/* CLASSN */
-#define ACTION	2			/* CLASSA */
-#define MISC	3			/* CLASSM */
-#define PREPOSITION 4			/* CLASSP */
-#define ADJACTIVE   5			/* CLASSJ */
-#define CONJUNCTION 6			/* CLASSC */
-
-/*
-   and a few preposition.  prefix PREP to distinguish them from
-   verbs or nouns
- */
-#define PREPAT	9
-#define PREPDN	8
-#define PREPIN	1
-#define PREPFR  5
-#define PREPOF  6
-#define PREPOFF 6
-#define PREPON	2
-
-/*
-  BIT mapping of "cond" array which indicates location status
-*/
-#define	LIGHT	1
-#define	WATOIL	2
-#define	LIQUID	4
-#define	NOPIRAT	16
-
-/* Object condition bit functions */
-#define OPENBT 2
-#define LOCKBT 4
-#define BURNBT 6
-#define DEADBT 10
-#define WEARBT 12
-/*
-  Structure definitions
-*/
-struct wac {
-  char *aword;
-  int acode;
-};
-
-struct trav {
-  int tdest;
-  int tverb;
-  int tcond;
-};
-
-/* Function prototypes.
-   "#if (__STDC__)" should have been be enough,
-   but some compilers are stupid, so allow Makefile to say -DHAS_STDC=whatever.
-*/
-#if defined(HAS_STDC) ? (HAS_STDC) : (__STDC__)
-#undef	HAS_STDC
-#define HAS_STDC 1
-#define	_PROTOTYPE(function, params)	function params
-#define _CONST				const
-#else
-#define	_PROTOTYPE(function, params)	function ()
-#define _CONST
-#endif
-
-/* Advent.c */
-
-_PROTOTYPE(void saveadv, (char *username));
-_PROTOTYPE(void restore, (char *username));
-
-/* Initialize.c */
-
-_PROTOTYPE(void initialize, (void));
-
-/* Database.c */
-
-_PROTOTYPE(int yes, (int msg1, int msg2, int msg3));
-_PROTOTYPE(void rspeak, (int msg));
-_PROTOTYPE(void pspeak, (int item, int state));
-_PROTOTYPE(void desclg, (int loc));
-_PROTOTYPE(void descsh, (int loc));
-
-/* English.c */
-
-_PROTOTYPE(int english, (void));
-_PROTOTYPE(int analyze, (char *word, int *type, int *value));
-
-/* Itverb.c */
-
-_PROTOTYPE(void itverb, (void));
-_PROTOTYPE(void ivblast, (void));
-_PROTOTYPE(void ivlook, (void));
-
-/* Turn.c */
-
-_PROTOTYPE(void turn, (void));
-_PROTOTYPE(void describe, (void));
-_PROTOTYPE(void descitem, (void));
-_PROTOTYPE(void dwarfend, (void));
-_PROTOTYPE(void normend, (void));
-_PROTOTYPE(void score, (int));
-_PROTOTYPE(void death, (void));
-_PROTOTYPE(char *probj, (void));
-_PROTOTYPE(void trobj, (void));
-_PROTOTYPE(void dwarves, (void));
-_PROTOTYPE(void dopirate, (void));
-_PROTOTYPE(int stimer, (void));
-
-/* Verb.c */
-
-_PROTOTYPE(void trverb, (void));
-_PROTOTYPE(void vtake, (void));
-_PROTOTYPE(void vdrop, (void));
-_PROTOTYPE(void vopen, (void));
-_PROTOTYPE(void vsay, (void));
-_PROTOTYPE(void von, (void));
-_PROTOTYPE(void voff, (void));
-_PROTOTYPE(void vwave, (void));
-_PROTOTYPE(void vkill, (void));
-_PROTOTYPE(void vpour, (void));
-_PROTOTYPE(void veat, (void));
-_PROTOTYPE(void vdrink, (void));
-_PROTOTYPE(void vthrow, (void));
-_PROTOTYPE(void vfind, (void));
-_PROTOTYPE(void vfill, (void));
-_PROTOTYPE(void vfeed, (void));
-_PROTOTYPE(void vread, (void));
-_PROTOTYPE(void vbreak, (void));
-_PROTOTYPE(void vwake, (void));
-_PROTOTYPE(void actspk, (int verb));
-_PROTOTYPE(void vyank, (void));
-_PROTOTYPE(void vwear, (void));
-_PROTOTYPE(void vlock, (void));
-_PROTOTYPE(void vunlock, (void));
-_PROTOTYPE(void vclose, (void));
-
-/* Utility.c */
-
-_PROTOTYPE(boolean ajar, (int));
-_PROTOTYPE(boolean at, (int item));
-_PROTOTYPE(boolean athand, (int));
-_PROTOTYPE(void bitoff, (int, int));
-_PROTOTYPE(void biton, (int, int));
-_PROTOTYPE(boolean bitset, (long, int));
-_PROTOTYPE(boolean blind, (void));
-_PROTOTYPE(int burden, (int));
-_PROTOTYPE(void carry, (int obj, int where));
-_PROTOTYPE(int confuz, (void));
-_PROTOTYPE(boolean dark, (void));
-_PROTOTYPE(boolean dcheck, (void));
-_PROTOTYPE(boolean dead, (int));
-_PROTOTYPE(void drop, (int obj, int where));
-_PROTOTYPE(void destroy, (int obj));
-_PROTOTYPE(boolean edible, (int));
-_PROTOTYPE(boolean enclosed, (int));
-_PROTOTYPE(void extract, (int));
-_PROTOTYPE(boolean forced, (int atloc));
-_PROTOTYPE(boolean here, (int item));
-_PROTOTYPE(boolean hinged, (int));
-_PROTOTYPE(boolean holding, (int));
-_PROTOTYPE(void insert, (int, int));
-_PROTOTYPE(boolean inside, (int));
-_PROTOTYPE(void juggle, (int loc));
-_PROTOTYPE(int liq, (int));
-_PROTOTYPE(int liqloc, (int loc));
-_PROTOTYPE(int liq2, (int pbottle));
-_PROTOTYPE(boolean living, (int));
-_PROTOTYPE(boolean locked, (int));
-_PROTOTYPE(boolean locks, (int));
-_PROTOTYPE(void lookin, (int));
-_PROTOTYPE(void move, (int obj, int where));
-_PROTOTYPE(int noway, (void));
-_PROTOTYPE(boolean opaque, (int));
-_PROTOTYPE(boolean outside, (int));
-_PROTOTYPE(boolean pct, (int x));
-_PROTOTYPE(boolean plural, (int));
-_PROTOTYPE(boolean portal, (int));
-_PROTOTYPE(boolean printed, (int));
-_PROTOTYPE(int put, (int obj, int where, int pval));
-_PROTOTYPE(int ranz, (int));
-_PROTOTYPE(boolean small, (int));
-_PROTOTYPE(boolean toting, (int item));
-_PROTOTYPE(boolean treasr, (int));
-_PROTOTYPE(boolean vessel, (int));
-_PROTOTYPE(boolean wearng, (int));
-_PROTOTYPE(boolean worn, (int));
-_PROTOTYPE(void bug, (unsigned int n));
-_PROTOTYPE(char *ask, (char *prompt, char *buf, int buflen));
-_PROTOTYPE(void panic, (char *msg, boolean save));
-
-/* travel.c */
-_PROTOTYPE(void domove, (void));
-_PROTOTYPE(void gettrav, (int loc, struct trav *travel));
-
-/* vocab.c */
-_PROTOTYPE(int vocab, (char *word, int val));
Index: trunk/minix/commands/advent/advent1.txt
===================================================================
--- trunk/minix/commands/advent/advent1.txt	(revision 9)
+++ 	(revision )
@@ -1,827 +1,0 @@
-#1
-You are standing at the end of a road before a small brick building.
-Around you is a forest.  A small stream flows out of the building and
-down a gully.
-#2
-You have walked up a hill, still in the forest.  The road slopes back
-down the other side of the hill.  There is a building in the distance.
-#3
-You are inside a building, a well house for a large spring.  Off
-to one side is a small pantry.
-#4
-You are in a valley in the forest beside a stream tumbling along a
-rocky bed.
-#5
-You are in open forest, with a deep valley to one side.  Not far
-is a large billboard.
-#6
-You are in open forest near both a valley and a road.
-#7
-At your feet all the water of the stream splashes into a 2-inch slit
-in the rock.  Downstream the stream bed is bare rock.
-#8
-You are in a 20-foot depression floored with bare dirt.  Set into the
-dirt is a strong steel grate mounted in concrete.  A dry stream bed
-leads into the depression.
-#9
-You are in a small chamber beneath a 3x3 steel grate to the surface.
-A low crawl over cobbles leads inward to the west.
-#10
-You are crawling over cobbles in a low passage.  There is a dim light
-at the east end of the passage.
-#11
-You are in a debris room filled with stuff washed in from the surface.
-A low wide passage with cobbles becomes plugged with mud and debris
-here, but an awkward canyon leads upward and west.  A note on the wall
-says "Magic Word XYZZY".
-#12
-You are in an awkward sloping east/west canyon.
-#13
-You are in a splendid chamber thirty feet high.  The walls are frozen
-rivers of orange stone.  An awkward canyon and a good passage exit
-from east and west sides of the chamber.
-#14
-At your feet is a small pit breathing traces of white mist.  An east
-passage ends here except for a small crack leading on.
-#15
-You are at one end of a vast hall stretching forward out of sight to
-the west.  There are openings to either side.  Nearby, a wide stone
-staircase leads downward.  The hall is filled with wisps of white mist
-swaying to and fro almost as if alive.  A cold wind blows up the
-staircase.  There is a passage at the top of a dome behind you.
-#16
-The crack is far too small for you to follow.
-#17
-You are on the east bank of a fissure slicing clear across the hall.
-The mist is quite thick here, and the fissure is too wide to jump.
-#18
-This is a low room with a crude note on the wall.  The note says,
-"You won't get it up the steps".
-#19
-You are in the Hall of the Mountain King, with passages off in all
-directions.
-#20
-You are at the bottom of the pit with a broken neck.
-#21
-You didn't make it.
-#22
-The dome is unclimbable.
-#23
-You are at the west end of the Twopit Room.  There is a large hole in
-the wall above the pit at this end of the room.
-#24
-You are at the bottom of the eastern pit in the Twopit Room.  There is
-a small pool of oil in one corner of the pit.
-#25
-You are at the bottom of the western pit in the Twopit Room.  There is
-a large hole in the wall about 25 feet above you.
-#26
-You clamber up the plant and scurry through the hole at the top.
-#27
-You are on the west side of the fissure in the Hall of Mists.
-#28
-You are in a low N/S passage at a hole in the floor.  The hole goes
-down to an E/W passage.
-#29
-You are in the South Side Chamber.
-#30
-You are in the West Side Chamber of the Hall of the Mountain King.
-A passage continues west and up here.
-#31
-<$$<
-#32
-You can't get by the snake.
-#33
-You are in a large room, with a passage to the south, a passage to the
-west, and a wall of broken rock to the east.  There is a large "Y2" on
-a rock in the room's center.
-#34
-You are in a jumble of rock, with cracks everywhere.
-#35
-You're at a low window overlooking a huge pit, which extends up out of
-sight.  A floor is indistinctly visible over 50 feet below.  Traces of
-white mist cover the floor of the pit, becoming thicker to the right.
-Marks in the dust around the window would seem to indicate that
-someone has been here recently.  Directly across the pit from you and
-25 feet away there is a similar window looking into a lighted room.  A
-shadowy figure can be seen there peering back at you.
-#36
-You are in a dirty broken passage.  To the east is a crawl.  To the
-west is a large passage.  Above you is a hole to another passage.
-#37
-You are on the brink of a small clean climbable pit.  A crawl leads
-west.
-#38
-You are in the bottom of a small pit with a little stream, which
-enters and exits through tiny slits.
-#39
-You are in a large room full of dusty rocks.  There is a big hole in
-the floor.  There are cracks everywhere, and a passage leading east.
-#40
-You have crawled through a very low wide passage parallel to and north
-of the Hall of Mists.
-#41
-You are at the west end of Hall of Mists.  A low wide crawl continues
-west and another goes north.  To the south is a little passage 6 feet
-off the floor.
-#42
-You are in a maze of twisty little passages, all alike.
-#43
-You are in a maze of twisty little passages, all alike.
-#44
-You are in a maze of twisty little passages, all alike.
-#45
-You are in a maze of twisty little passages, all alike.
-#46
-Dead end.
-#47
-Dead end.
-#48
-Dead end.
-#49
-You are in a maze of twisty little passages, all alike.
-#50
-You are in a maze of twisty little passages, all alike.
-#51
-You are in a maze of twisty little passages, all alike.
-#52
-You are in a maze of twisty little passages, all alike.
-#53
-You are in a maze of twisty little passages, all alike.
-#54
-Dead end.
-#55
-You are in a maze of twisty little passages, all alike.
-#56
-Dead end.
-#57
-You are on the brink of a thirty foot pit with a massive orange column
-down one wall.  You could climb down here but you could not get back
-up.  The maze continues at this level.
-#58
-Dead end.
-#59
-You have crawled through a very low wide passage parallel to and north
-of the Hall of Mists.
-#60
-You are at the east end of a very long hall apparently without side
-chambers.  In the south wall are several wide cracks and a high
-hole, but the hole is far above your head.  To the east a wide
-crawl slants up.  To the north a round two foot hole slants down.
-#61
-You are at the west end of a very long featureless hall.  The hall
-joins up with a narrow north/south passage.
-#62
-You are at a crossover of a high N/S passage and a low E/W one.
-#63
-Dead end.
-#64
-You are at a complex junction.  A low hands and knees passage from the
-north joins a higher crawl from the east to make a walking passage
-going west.  There is also a large room above.  The air is damp here.
-#65
-You are in Bedquilt, a long east/west passage with holes everywhere.
-To explore at random select north, south, up, or down.
-#66
-You are in a room whose walls resemble swiss cheese.  Obvious passages
-go west, east, NE, and NW.  Part of the room is occupied by a large
-bedrock block.
-#67
-You are at the east end of the Twopit Room.  The floor here is
-littered with thin rock slabs, which make it easy to descend the pits.
-There is a path here bypassing the pits to connect passages from east
-and west.  There are holes all over, but the only big one is on the
-wall directly over the west pit where you can't get to it.
-#68
-You are in a large low circular chamber whose floor is an immense slab
-fallen from the ceiling (Slab Room).  East and west there once were
-large passages, but they are now filled with boulders.  Low small
-passages go north and south, and the south one quickly bends west
-around the boulders.
-#69
-You are in a secret N/S canyon above a large room.
-#70
-You are in a secret N/S canyon above a sizable passage.
-#71
-You are in a secret canyon at a junction of three canyons, bearing
-north, south, and SE.  The north one is as tall as the other two
-combined.
-#72
-You are in a large low room.  Crawls lead north, NE, and SW.
-#73
-Dead end crawl.
-#74
-You are in a secret canyon which here runs E/W.  It crosses over a
-very tight canyon 15 feet below.  If you go down you may not be able
-to get back up.
-#75
-You are at a wide place in a very tight N/S canyon.
-#76
-The canyon here becomes too tight to go further south.
-#77
-You are in a tall E/W canyon.  A low tight crawl goes 3 feet north and
-seems to open up.
-#78
-The canyon runs into a mass of boulders -- dead end.
-#79
-The stream flows out through a pair of 1 foot diameter sewer pipes.
-It would be advisable to use the exit.
-#80
-You are in a maze of twisty little passages, all alike.
-#81
-Dead end.
-#82
-Dead end.
-#83
-You are in a maze of twisty little passages, all alike.
-#84
-You are in a maze of twisty little passages, all alike.
-#85
-Dead end.
-#86
-Dead end.
-#87
-You are in a maze of twisty little passages, all alike.
-#88
-You are in a long, narrow corridor stretching out of sight to the
-west.  At the eastern end is a hole through which you can see a
-profusion of leaves.
-#89
-There is nothing here to climb.  Use "up" or "out" to leave the pit.
-#90
-You have climbed up the plant and out of the pit.
-#91
-You are at the top of a steep incline above a large room.  You could
-climb down here, but you would not be able to climb up.  There is a
-passage leading back to the north.
-#92
-You are in the Giant Room.  The ceiling here is too high up for your
-lamp to show it.  Cavernous passages lead east, north, and south.  On
-the west wall is scrawled the inscription, "FEE FIE FOE FOO" [sic].
-#93
-The passage here is blocked by a recent cave-in.
-#94
-You are at one end of an immense north/south passage.
-#95
-You are in a magnificent cavern with a rushing stream, which cascades
-over a sparkling waterfall into a roaring whirlpool which disappears
-through a hole in the floor.  Passages exit to the south and west.
-#96
-You are in the Soft Room.  The walls are covered with heavy curtains,
-the floor with a thick pile carpet.  Moss covers the ceiling.
-#97
-This is the Oriental Room.  Ancient oriental cave drawings cover the
-walls.  A gently sloping passage leads upward to the north, another
-passage leads SE, and a hands and knees crawl leads east.
-#98
-You are following a wide path around the outer edge of a large cavern.
-Far below, through a heavy white mist, strange splashing noises can be
-heard.  The mist rises up through a fissure in the ceiling.  The path
-hugs the cavern's rim to the NE and south, while another branch forks
-west.  A round chute with extremely smooth walls angles sharply up
-to the southwest.
-#99
-You are in an alcove.  A small NW path seems to widen after a short
-distance.  An extremely tight tunnel leads east.  It looks like a very
-tight squeeze.  An eerie light can be seen at the other end.
-#100
-You're in a small chamber lit by an eerie green light.  An extremely
-narrow tunnel exits to the west, and a dark corridor leads NE.
-#101
-You're in the Dark-Room.  A corridor leading south is the only exit.
-#102
-You are in an arched hall.  A coral passage once continued up and east
-from here, but is now blocked by debris.  The air smells of sea water.
-#103
-You're in a large room carved out of sedimentary rock.  The floor and
-walls are littered with bits of shells imbedded in the stone.  A
-shallow passage proceeds downward, and a somewhat steeper one leads
-up.  A low hands and knees passage enters from the south.
-#104
-You are in a long sloping corridor with ragged sharp walls.
-#105
-You are in a cul-de-sac about eight feet across.
-#106
-You are in an anteroom leading to a large passage to the east.  Small
-passages go west and up.  The remnants of recent digging are evident.
-A sign in midair here says "Cave under construction beyond this point.
-Proceed at own risk.  [Witt Construction Company]".
-#107
-You are in a maze of twisty little passages, all different.
-#108
-You are at Witt's End.  Passages lead off in *ALL* directions.
-#109
-You are in a north/south canyon about 25 feet across.  The floor is
-covered by white mist seeping in from the north.  The walls extend
-upward for well over 100 feet.  Suspended from some unseen point far
-above you, an enormous two-sided mirror is hanging parallel to and
-midway between the canyon walls.  (The mirror is obviously provided
-for the use of the dwarves, who as you know, are extremely vain.)  A
-small window can be seen in either wall, some fifty feet up.
-#110
-You're at a low window overlooking a huge pit, which extends up out of
-sight.  A floor is indistinctly visible over 50 feet below.  Traces of
-white mist cover the floor of the pit, becoming thicker to the left.
-Marks in the dust around the window would seem to indicate that
-someone has been here recently.  Directly across the pit from you and
-25 feet away there is a similar window looking into a lighted room.  A
-shadowy figure can be seen there peering back at you.
-#111
-A large stalactite extends from the roof and almost reaches the floor
-below.  You could climb down it, and jump from it to the floor, but
-having done so you would be unable to reach it to climb back up.
-#112
-You are in a little maze of twisting passages, all different.
-#113
-You are at the edge of a large underground reservoir.  An opaque cloud
-of white mist fills the room and rises rapidly upward.  The lake is
-fed by a stream, which tumbles out of a hole in the wall about 10 feet
-overhead and splashes noisily into the water somewhere within the
-mist.  The indistinct shape of the opposite shore can be dimly seen
-through the mist.  The only passage goes back toward the south.
-#114
-Dead end.
-#115
-You are at the northeast end of an immense room, even larger than the
-Giant Room.  It appears to be a repository for the "ADVENTURE"
-program.  Massive torches far overhead bathe the room with smoky
-yellow light.  Scattered about you can be seen a pile of bottles (all
-of them empty), a nursery of young beanstalks murmuring quietly, a bed
-of oysters, a bundle of black rods with rusty stars on their ends, and
-a collection of brass lanterns.  Off to one side a great many dwarves
-are sleeping on the floor, snoring loudly.  A sign nearby reads: "Do
-not disturb the dwarves!"  An immense mirror is hanging against one
-wall, and stretches to the other end of the room, where various other
-sundry objects can be glimpsed dimly in the distance.  An unoccupied
-telephone booth stands against the north wall.
-#116
-You are at the southwest end of the repository.  To one side is a pit
-full of fierce green snakes.  On the other side is a row of small
-wicker cages, each of which contains a little sulking bird.  In one
-corner is a bundle of black rods with rusty marks on their ends.  A
-large number of velvet pillows are scattered about on the floor. 
-Beside one of the pillows is a large, dusty, leather-bound volume
-with the title "History of Adventure" embossed in pure gold.
-A vast mirror stretches off to the northeast, almost reaching the
-phone booth.  At your feet is a large steel grate, next to which is
-a sign which reads, "Treasure Vault. Keys in Main Office."
-#117
-You are on one side of a large, deep chasm.  A heavy white mist rising
-up from below obscures all view of the far side.  A SW path leads away
-from the chasm into a winding corridor.
-#118
-You are in a long winding corridor sloping out of sight in both
-directions.
-#119
-You are in a secret canyon which exits to the north and east.
-#120
-You are in a secret canyon which exits to the north and east.
-#121
-You are in a secret canyon which exits to the north and east.
-#122
-You are on the northeast side of a deep chasm.  A NE path leads away
-from the chasm on this side.
-#123
-You're in a long east/west corridor.  A faint rumbling noise can be
-heard in the distance.
-#124
-The path forks here.  The left fork leads northeast.  A dull rumbling
-seems to get louder in that direction.  The right fork leads southeast
-down a gentle slope.  The main corridor enters from the west.
-#125
-The walls are quite warm here.  From the north can be heard a steady
-roar, so loud that the entire cave seems to be trembling.  Another
-passage leads south, and a low crawl goes east.
-#126
-You are on the edge of a breathtaking view.  Far below you is an
-active volcano, from which great gouts of molten lava come surging
-out, cascading back down into the depths.  The glowing rock fills the
-farthest reaches of the cavern with a blood-red glare, giving every-
-thing an eerie, macabre appearance.  The air is filled with flickering
-sparks of ash and a heavy smell of brimstone.  The walls are hot to
-the touch, and the thundering of the volcano drowns out all other
-sounds.  Embedded in the jagged roof far overhead are myriad twisted
-formations composed of pure white alabaster, which scatter the murky
-light into sinister apparitions upon the walls.  To one side is a deep
-gorge, filled with a bizarre chaos of tortured rock which seems to
-have been crafted by the devil himself.  An immense river of fire
-crashes out from the depths of the volcano, burns its way through the
-gorge, and plummets into a bottomless pit far off to your left.  To
-the right, an immense geyser of blistering steam erupts continuously
-from a barren island in the center of a sulfurous lake, which bubbles
-ominously.  The far right wall is aflame with an incandescence of its
-own, which lends an additional infernal splendor to the already
-hellish scene.  A dark, foreboding passage exits to the south.
-#127
-You are in a small chamber filled with large boulders.  The walls are
-very warm, causing the air in the room to be almost stifling from the
-heat.  The only exit is a crawl heading west, through which is coming
-a low rumbling.
-#128
-You are walking along a gently sloping north/south passage lined with
-oddly shaped limestone formations.
-#129
-You are standing at the entrance to a large, barren room.  A sign
-posted above the entrance reads:  "Caution!  Bear in room!"
-#130
-You are inside a barren room.  The center of the room is completely
-empty except for some dust.  Marks in the dust lead away toward the
-far end of the room.  The only exit is the way you came in.
-#131
-You are in a maze of twisting little passages, all different.
-#132
-You are in a little maze of twisty passages, all different.
-#133
-You are in a twisting maze of little passages, all different.
-#134
-You are in a twisting little maze of passages, all different.
-#135
-You are in a twisty little maze of passages, all different.
-#136
-You are in a twisty maze of little passages, all different.
-#137
-You are in a little twisty maze of passages, all different.
-#138
-You are in a maze of little twisting passages, all different.
-#139
-You are in a maze of little twisty passages, all different.
-#140
-Dead end.
-#141
-You are on a narrow promontory at the foot of a waterfall, which
-spurts from an overhead hole in the rock wall and splashes into a
-large reservoir, sending up clouds of mist and spray.
-Through the thick white mist looms a polished marble slab, to
-which is affixed an enormous rusty iron anvil.  In golden letters
-are written the words: "Whoso Pulleth Out This Sword of This
-Stone and Anvil, is Right wise King-Born of All This Mountain."
-There is a narrow chimney on the east side of the promontory.
-#142
-You are on a narrow shelf above and east of the top of a very steep
-chimney.  A long smooth granite slide curves down out of sight
-to the east.  If you go down the slide, you may not be able to
-climb back up.
-#143
-You are in the private chamber of the Mountain King.  Hewn into the
-solid rock of the east wall of the chamber is an intricately-wrought
-throne of elvish design.  There is an exit to the west.
-#144
-You are on the east side of the throne room.  On the arm of the throne
-has been hung a sign which reads "Gone for the day: visiting
-sick snake. --M.K."
-#145
-You are dragged down, down, into the depths of the whirlpool.
-Just as you can no longer hold your breath, you are shot out over
-a waterfall into the shallow end of a large reservoir.  Gasping
-and sputtering, you crawl weakly towards the shore....
-#146
-You are in dense forest, with a hill to one side.  The trees appear
-to thin out towards the north and east.
-#147
-You are at the high point of a wide grassy knoll, partially surrounded
-by dense forest.  The land rises to the south and east, and drops off
-sharply to the north and west.  The air smells of sea water.
-#148
-You are at the edge of a trackless salt marsh.  Tall reeds obscure
-the view.
-#149
-You're in salt marsh.
-#150
-You're in salty marsh.
-#151
-You are in salt marsh.
-#152
-Dead end.
-#153
-You're on a sandy beach at the edge of the open sea.  The beach
-ends a short distance south and the land rises to a point. To
-the north, the beach ends cliffs and broken rocks.
-#154
-You are at a jumble of large broken rocks.  A gentle path leads up
-to the top of the nearby cliffs.  A narrow treacherous path
-disappears among the rocks at the foot of the cliff.
-#155
-You are on a high cliff overlooking the sea.  Far below the
-rolling breakers smash into a jumble of large broken rocks.
-The thunder of the surf is deafening.
-#156
-You're at the bottom of the cliff, smashed to smithereens by the
-pounding surf.
-#157
-You are at Thunder Hole, a funnel shaped cavern opening onto the sea.
-The noise of the surf pounding against the outer rocks of the cave is
-amplified by the peculiar shape of the cave, causing a thunder-like
-booming sound to reverberate throughout the cave.  Outside, a narrow
-path leads south towards some large rocks.
-#158
-You are at the top of some arched steps.  On one side is a blank wall
-with a tiny door at the base and a shelf overhead.  On the other side
-a westward passage leads to the sea.
-#159
-You are in a low cramped chamber at the back of a small cave.
-There is a shelf in the rock wall at about the height of your
-shoulder.
-#160
-You are on a wide ledge, bounded on one side by a rock wall,
-and on the other by a sheer cliff.  The only way past is through
-a large wrought-iron door.
-#161
-You feel dizzy...Everything around you is spinning, expanding,
-growing larger....  Dear me!  Is the cave bigger or are you smaller?
-#162
-You are again overcome by a sickening vertigo, but this time
-everything around you is shrinking...Shrinking...
-#163
-You are again overcome by a sickening vertigo, but this time
-everything is shrinking... I mean, you are growing.  This is
-terribly confusing!
-#164
-You feel dizzy...Everything around you is spinning, expanding,
-growing larger....
-#165
-You're at the bottom of the cliff with a broken neck.
-#166
-You are at the western tip of the Blue Grotto.  A large lake almost
-covers the cavern floor, except for where you are standing.  Small
-holes high in the rock wall to the east admit a dim light.  The
-reflection of the light from the water suffuses the cavern with
-a hazy bluish glow.
-#167
-You are on the shore of an underground sea.  A high wooden
-structure of vast proportions extends out into the water to the
-east.  The way west is through a wrought-iron door.
-#168
-You are on the eastern shore of the Blue Grotto.  An ascending
-tunnel disappears into the darkness to the SE.
-#169
-You are at a high rock on the NE side of a watery chamber at the mouth
-of a small brook.  An unknown gas bubbles up through the water from
-the chamber floor.  A bluish light can be seen to the southwest.
-#170
-You are in a windy tunnel between two large rooms.
-#171
-You are in the Bat Cave.  The walls and ceiling are covered with
-sleeping bats.  The floor is buried by a mass of dry, foul-smelling
-guano.  The stench is overpowering.  Exits to the NW and east.
-#172
-You are in a very tight N/S crack.  The passage seems to widen to
-the south.
-#173
-You are in a very tight N/S crack.  The passage south is blocked
-by a recent cave-in.
-#174
-You're in the Cloakroom.  This is where the dreaded Wumpus repairs
-to sleep off heavy meals.  (Adventurers are his favorite dinner!)
-Two very narrow passages exit NW and NE.
-#175
-You're in a room containing several small climbable pits.  Passages
-exit to the east and north.
-#176
-You are at the bottom of a small featureless pit.
-#177
-You are at a high hole in a rock wall.
-#178
-The NE passage is blocked by a recent cave-in.
-#179
-You are in a sloping muddy defile, next to a tumbling brook.
-#180
-You are in a level E/W passage partially blocked by an overhanging
-tongue of rock.  A steep scramble would take you up over the tongue,
-whence continues an upward crawl.
-#181
-The dog won't let you pass.
-#182
-You're in the Upper Passage, a long level E/W tunnel.
-#183
-You are in a star-shaped chamber.  Passages exit north, east, south,
-and west.
-#184
-You are at an elbow in a winding E/W passage.
-#185
-Dead end.
-#186
-You're at the intersection of two long tunnels.  One goes NW,
-the other NE.
-#187
-You're in a long narrow east-west passage which curves out of sight
-at both ends.
-#188
-You're in the Rotunda.  Corridors radiate in all directions.
-There is a telephone booth standing against the north wall.
-#189
-You are standing in a telephone booth at the side of a large chamber.
-Hung on the wall is a banged-up pay telephone of ancient design.
-#190
-You're at the Devil's Chair, a large crystallization shaped like a
-seat, at the edge of a black abyss.  You can't see the bottom.
-An upward path leads away from the abyss.
-#191
-You're in a dead-end crack.
-#192
-You're on a small gravel beach at the south wall of the Blue Grotto.
-A gravelly path leads east.
-#193
-You are in the Flower Room.  The walls are covered with colorful,
-intricate, flowerlike patterns of crystallized gypsum. A hole leads
-to the west.
-#194
-You are at the end of a short E/W corridor.
-#195
-You are looking west from the end of a short E/W corridor.  At your
-feet is a pile of loose rubble.  On your left is a hole into another
-chamber.
-#196
-You are in an arched hall.  The remnants of a now-plugged coral
-passage lie to the east.  The north wall has partially crumbled,
-exposing a large connecting hole to another room.
-#197
-You're in the Vestibule, a short east-west passage between two rooms.
-#198
-You are in the Fairy Grotto.  All around you innumerable stalactites,
-arranged in immense colonnades, form elegant arches.  On every side
-you hear the dripping of water, like the footsteps of a thousand
-fairies.  A small stream runs from the SW corner.  A bright glow
-emanates from the south side of the grotto, and a steep passage
-descends to the east.
-#199
-You have approached the lower end of a steep passage, but it is
-just too cold here to hang around, and you aren't properly equipped
-to continue.  With teeth chattering, you climb back up....
-#200
-You are in the Crystal Palace.  An overhead vein of phosphorescent
-quartz casts a luminous glow which is reflected by countless chips of
-mica embedded in both walls, which consist of some sort of highly
-reflective glass, apparently of volcanic origin.  A winding path
-of yellow sandstone leads west and rises steeply to the east.
-#201
-You are following a yellow sandstone path.  There is a glow
-to the west.
-#202
-You are in a very tall chamber whose walls are comprised of many
-different rock strata.  Layers of red and yellow sandstone
-intertwine with bright bands of calcareous limestone in a rainbow-
-like profusion of color.  The rainbow effect is so real, you
-are almost tempted to look for a pot of gold!  Poised far over
-your head, a gigantic slab, wedged tightly between the north and
-south walls, forms a natural bridge across the roof of the chamber.
-A trail leads east and west.
-#203
-You're in a steeply sloping passage.  It is very cold here.
-#204
-You are in the Hall of Ice, in the deepest part of the caverns.
-During winter, frigid outside air settles here, making this room
-extremely cold all year round.  The walls and ceilings are covered
-with a thick coating of ice.  An upward passage exits to the west.
-#205
-You are standing on a natural bridge far above the floor of a circular
-chamber whose walls are a rainbow of multicolored rock.  The bridge
-was formed eons ago by a huge slab which fell from the ceiling and
-is now jammed between the north and south walls of the chamber.
-#206
-You are in a low, wide room below another chamber.  A small green
-pond fills the center of the room.  The lake is apparently spring
-fed.  A small stream exits through a narrow passage to the north.
-A larger passage continues west.
-#207
-You are in a tight north/south crawl through a stratum of red
-colored rock.  The air is damp with mist.
-#208
-You are in a tall canyon on the south side of a swift, wide river.
-Written in the mud in crude letters are the words: "You Have Found
-Lost River."  A wide path leads east and west along the bank.  A tight
-crawl way would take you south out of the canyon.
-#209
-You are standing on a large flat rock table at the western end of
-Lost River Canyon.  Beneath your feet, the river disappears amidst
-foam and spray into a large sinkhole.  A gentle path leads east
-along the river's south shore.  Another leads sharply upward along
-the river's north side.
-#210
-You are at a niche in the canyon wall, far above a raging river.
-The air is filled with mist and spray, making it difficult to see
-ahead.  A downward sloping ledge narrows to the east. The path
-to the west is easier.
-#211
-The ledge is growing very narrow and treacherous, and falls off almost
-vertically.  You could go down, but you won't be able to climb back.
-#212
-You are standing in a telephone booth at the side of the Repository.
-#213
-You're at the east end of a level passage at a hole in the floor.
-#214
-You're at the north edge of a dark cove.
-#215
-You are in a dry granite basin, worn smooth eons ago by water
-swirling down from a now-dry spillway.
-#216
-You're in a dry spillway east of and above a smooth rock basin.
-#217
-You are in the Winery, a cool dark room which extends some
-distance off to the east.
-#218
-You are to the east of the Winery, where the room ends in a thicket
-of high, sharp, pointed, climbable limestone pinnacles.  There is a
-narrow ledge just above the top of the spires.  If you go up, it
-might be difficult to get back down.
-#219
-You are in a high-vaulted cavern whose roof rises over fifty
-meters to culminate in a series of pointed arches directly over
-your head.  There are also two low arches to either side, forming
-side portals.  The whole effect is that of a gothic cathedral.
-You can proceed north, south, east, or west.
-#220
-You're at the east portal of the Gothic Cathedral. The path leads
-east and west.
-#221
-You're at the west portal of the Gothic Cathedral.
-#222
-You are at the foot of the Altar, an immense, broad stalagmite.
-An opening leads south.
-#223
-You're on top of an enormous, broad stalagmite.  There is a hole
-in the ceiling overhead.
-#224
-You are in a room the size and shape of a small crypt.  A narrow
-cut exits east.  There is a hole in the floor.
-#225
-You are in the Gothic Chapel, a small chamber adjoining the Gothic
-Cathedral. A path leads west.
-#226
-You are on the floor of the Rainbow Room.  In fact, you are spread
-*ALL OVER* the floor of the Rainbow Room.
-#227
-You are in a dimly lit passage behind Thunder Hole.  Etched into
-the rock wall are the ominous words:
-*       "You are approaching the River Styx.      *
-*        Laciate Ogni Speranza Voi Ch'Entrate."   *
-#228
-You are at the River Styx, a narrow little stream cutting directly
-across the passageway.  The edge of the stream is littered with sticks
-and other debris washed in by a recent rainfall.  On the far side
-of the river, the passage continues east.
-#229
-You're on the east side of the river's sticks.
-#230
-You are on a ledge at the northern end of a long N/S crawl.  The
-ledge is above a large number of sharp vertical limestone spires.
-An attempt to climb down could be dangerous, if you get my *point*!
-#231
-You are very neatly skewered on the point of a sharp rock.
-#232
-You have poled your boat across the calm water.
-#233
-You have poled your boat across the dark water.
-#234
-You have poled your boat across the Blue Grotto.
-#235
-You're at Dante's Rest, on the north side of a yawning dark chasm.
-A passage continues west along the chasm's edge.
-#236
-You are at the east end of a river bank path in Lost River Canyon.
-#237
-The staircase is now unclimbable.
-#238
-You're in the caretaker's pantry.
-#239
-You are on a small rise overlooking a beautiful bay. In the center
-of the bay is the castle of the elves.
-#240
-You are on the highest pinnacle of the castle in the bay.
-Steps lead down into the garden.
-#241
-You are in the outer courtyard of the garden of the elves.
-Steps lead up to the tower, and to the west, separating you
-from the inner courtyard, is a maze of hedges, living things,
-but almost crystalline in their multicolored splendor.
-#242
-From the inside the maze looks like a kaleidoscope, with
-swatches of color dancing as you move. In this part the colors
-are produced by shining red berries on the branches.
-#243
-You are surrounded by a tall hedge with sharp iridescent leaves
-and metallic orange flowers.
-#244
-You are in the center of the living maze. The plants here are
-dormant this season, but still carry brilliant yellow leaves.
-#245
-Unlike the other areas of the hedge system, this area seems to 
-have no metallic gleam; nevertheless it is still breathtaking.
-The trees and bushes are all variegated shades of green, the
-evergreens being a rich dark shade while the seasonal bushes
-are a lighter yellowish green, making a startling contrast.
-#246
-You are near the edge of the maze. You sample the blueberries
-on the bushes. They are delicious.
-#247
-You are at the western end of the living maze. Beside the
-shrubs forming the walls are tastefully planted beds of
-violets and brilliant purple pansies.
-To the west is the inner garden.
-#248
-You are in the inner garden of the elves. In the center is
-a living tree, with shimmering silvery bark, glistening metallic
-green leaves, and flowers ripe with nectar. As the nectar falls
-to the ground it forms droplets of silver. Around the tree is
-a hedge of briars which cannot be crossed. Unfortunately for
-adventurers such as you, most of the nectar falls inside the hedge.
-The exit is to the east.
Index: trunk/minix/commands/advent/advent2.txt
===================================================================
--- trunk/minix/commands/advent/advent2.txt	(revision 9)
+++ 	(revision )
@@ -1,514 +1,0 @@
-#1
-You're at end of road again.
-#2
-You're at hill in road.
-#3
-You're inside building.
-#4
-You're in valley.
-#5
-You're in forest.
-#6
-You're in forest.
-#7
-You're at slit in streambed.
-#8
-You're outside grate.
-#9
-You're below the grate.
-#10
-You're in cobble crawl.
-#11
-You're in Debris Room.
-#12
-You are in an awkward sloping east/west canyon.
-#13
-You're in Bird Chamber.
-#14
-You're at top of small pit.
-#15
-You're in Hall of Mists.
-#16
-The crack is far too small for you to follow.
-#17
-You're on east bank of fissure.
-#18
-You're in Nugget of Gold Room.
-#19
-You're in Hall of Mt King.
-#20
-You are at the bottom of the pit with a broken neck.
-#21
-You didn't make it.
-#22
-The dome is unclimbable.
-#23
-You're at west end of Twopit Room.
-#24
-You're in east pit.
-#25
-You're in west pit.
-#26
-You clamber up the plant and scurry through the hole at the top.
-#27
-You are on the west side of the fissure in the Hall of Mists.
-#28
-You are in a low N/S passage at a hole in the floor.  The hole goes
-down to an E/W passage.
-#29
-You are in the South Side Chamber.
-#30
-You are in the West Side Chamber of the Hall of the Mountain King.
-#31
-<$$<
-#32
-You can't get by the snake.
-#33
-You're at "Y2".
-#34
-You are in a jumble of rock, with cracks everywhere.
-#35
-You're at window on pit.
-#36
-You're in dirty passage.
-#37
-You are on the brink of a small clean climbable pit.
-#38
-You are in the bottom of a small pit with a little stream.
-#39
-You're in dusty rock room.
-#40
-You have crawled through a very low wide passage parallel.
-#41
-You're at west end of Hall of Mists.
-#42
-You are in a maze of twisty little passages, all alike.
-#43
-You are in a maze of twisty little passages, all alike.
-#44
-You are in a maze of twisty little passages, all alike.
-#45
-You are in a maze of twisty little passages, all alike.
-#46
-Dead end.
-#47
-Dead end.
-#48
-Dead end.
-#49
-You are in a maze of twisty little passages, all alike.
-#50
-You are in a maze of twisty little passages, all alike.
-#51
-You are in a maze of twisty little passages, all alike.
-#52
-You are in a maze of twisty little passages, all alike.
-#53
-You are in a maze of twisty little passages, all alike.
-#54
-Dead end.
-#55
-You are in a maze of twisty little passages, all alike.
-#56
-Dead end.
-#57
-You're at brink of pit.
-#58
-Dead end.
-#59
-You have crawled through a very low wide passage.
-#60
-You're at east end of Long Hall.
-#61
-You're at west end of Long Hall.
-#62
-You are at a crossover of a high N/S passage and a low E/W one.
-#63
-Dead end.
-#64
-You're at Complex Junction.
-#65
-You are in Bedquilt.
-#66
-You're in Swiss Cheese Room.
-#67
-You're at east end of Twopit Room.
-#68
-You're in Slab Room.
-#69
-You are in a secret N/S canyon above a large room.
-#70
-You are in a secret N/S canyon above a sizable passage.
-#71
-You're at junction of three secret canyons.
-#72
-You are in a large low room.  Crawls lead north, NE, and SW.
-#73
-Dead end crawl.
-#74
-You're in secret E/W canyon above tight canyon.
-#75
-You are at a wide place in a very tight N/S canyon.
-#76
-The canyon here becomes too tight to go further south.
-#77
-You are in a tall E/W canyon.
-#78
-The canyon runs into a mass of boulders -- dead end.
-#79
-The stream flows out through a pair of 1 foot diameter sewer pipes.
-#80
-You are in a maze of twisty little passages, all alike.
-#81
-Dead end.
-#82
-Dead end.
-#83
-You are in a maze of twisty little passages, all alike.
-#84
-You are in a maze of twisty little passages, all alike.
-#85
-Dead end.
-#86
-Dead end.
-#87
-You are in a maze of twisty little passages, all alike.
-#88
-You're in narrow corridor.
-#89
-There is nothing here to climb.  Use "up" or "out" to leave the pit.
-#90
-You have climbed up the plant and out of the pit.
-#91
-You're at steep incline above large room.
-#92
-You're in Giant Room.
-#93
-The passage here is blocked by a recent cave-in.
-#94
-You are at one end of an immense north/south passage.
-#95
-You're in cavern with waterfall.
-#96
-You're in Soft Room.
-#97
-You're in Oriental Room.
-#98
-You're in Misty Cavern.
-#99
-You're in Alcove.
-#100
-You're in Plover Room.
-#101
-You're in Dark-Room.
-#102
-You're in Arched Hall.
-#103
-You're in Shell Room.
-#104
-You are in a long sloping corridor with ragged sharp walls.
-#105
-You are in a cul-de-sac about eight feet across.
-#106
-You're in Anteroom.
-#107
-You are in a maze of twisty little passages, all different.
-#108
-You're at Witt's End.
-#109
-You're in Mirror Canyon.
-#110
-You're at window on pit.
-#111
-You're at top of stalactite.
-#112
-You are in a little maze of twisting passages, all different.
-#113
-You're at Reservoir.
-#114
-Dead end.
-#115
-You're at NE end.
-#116
-You're at SW end.
-#117
-You're on SW side of chasm.
-#118
-You're in sloping corridor.
-#119
-You are in a secret canyon which exits to the north and east.
-#120
-You are in a secret canyon which exits to the north and east.
-#121
-You are in a secret canyon which exits to the north and east.
-#122
-You're on NE side of chasm.
-#123
-You're in corridor.
-#124
-You're at fork in path.
-#125
-You're at junction with warm walls.
-#126
-You're at breath-taking view.
-#127
-You're in Chamber of Boulders.
-#128
-You're in Limestone Passage.
-#129
-You're in front of Barren Room.
-#130
-You're in Barren Room.
-#131
-You are in a maze of twisting little passages, all different.
-#132
-You are in a little maze of twisty passages, all different.
-#133
-You are in a twisting maze of little passages, all different.
-#134
-You are in a twisting little maze of passages, all different.
-#135
-You are in a twisty little maze of passages, all different.
-#136
-You are in a twisty maze of little passages, all different.
-#137
-You are in a little twisty maze of passages, all different.
-#138
-You are in a maze of little twisting passages, all different.
-#139
-You are in a maze of little twisty passages, all different.
-#140
-Dead end.
-#141
-You're at Sword Point.
-#142
-You're at top of slide.
-#143
-You're at entrance to Throne Room.
-#144
-You're on east side of Throne Room.
-#145
-<$$<
-#146
-You're in forest.
-#147
-You're on grassy knoll.
-#148
-You are at the edge of a trackless salt marsh.  Tall reeds obscure
-the view.
-#149
-You're in salt marsh.
-#150
-You're in salty marsh.
-#151
-You are in salt marsh.
-#152
-Dead end.
-#153
-You're on sandy beach.
-#154
-You're at broken rocks.
-#155
-You're at Ocean Vista.
-#156
-You're at the bottom of the cliff.
-#157
-You're at Thunder Hole.
-#158
-You're at top of steps in back of Thunder Hole.
-#159
-You're in cramped chamber.
-#160
-You're at ledge by wrought-iron door.
-#161
-You feel dizzy...Everything around you is spinning, expanding,
-growing larger....  Dear me!  Is the cave bigger or are you smaller?
-#162
-You are again overcome by a sickening vertigo, but this time
-everything around you is shrinking...Shrinking...
-#163
-You are again overcome by a sickening vertigo, but this time
-everything is shrinking... I mean, you are growing.  This is
-terribly confusing!
-#164
-You feel dizzy...Everything around you is spinning, expanding,
-growing larger....
-#165
-You're at the bottom of the cliff with a broken neck.
-#166
-You're at west wall of Blue Grotto.
-#167
-You're at underground sea.
-#168
-You're on east side of the Blue Grotto.
-#169
-You're in Bubble Chamber.
-#170
-You are in a windy tunnel between two large rooms.
-#171
-You're in Bat Cave.
-#172
-You are in a very tight N/S crack.
-#173
-You are in a very tight N/S crack.
-#174
-You're in the Cloakroom.
-#175
-You're in a room containing several small climbable pits.
-#176
-You are at the bottom of a small featureless pit.
-#177
-You are at a high hole in a rock wall.
-#178
-The NE passage is blocked by a recent cave-in.
-#179
-You are in a sloping muddy defile, next to a tumbling brook.
-#180
-You're at Tongue of Rock.
-#181
-The dog won't let you pass.
-#182
-You're in the Upper Passage, a long level E/W tunnel.
-#183
-You're in Star Chamber.
-#184
-You are at an elbow in a winding E/W passage.
-#185
-Dead end.
-#186
-You're at the intersection of two long tunnels.
-#187
-You're in a long narrow east-west passage.
-#188
-You're in Rotunda.
-#189
-You're in phone booth.
-#190
-You're at Devil's Chair.
-#191
-You're in a dead-end crack.
-#192
-You're on gravel beach.
-#193
-You're in Flower Room.
-#194
-You are at east end of short E/W corridor.
-#195
-You are at east end of short E/W corridor.
-#196
-You're in Arched Hall.
-#197
-You're in the Vestibule, a short east-west passage between two rooms.
-#198
-You're in the Fairy Grotto.
-#199
-You have approached the lower end of a steep passage.
-#200
-You're in the Crystal Palace.
-#201
-You are following a yellow sandstone path.
-#202
-You're in the Rainbow Room.
-#203
-You're in a steeply sloping passage.  It is very cold here.
-#204
-You're in the Hall of Ice.
-#205
-You are over the Rainbow (Room).
-#206
-You're in Green Lake Room.
-#207
-You're in red rock crawl.
-#208
-You're on south side of Lost River Canyon.
-#209
-You're at end of Lost River Canyon.
-#210
-You're at niche in ledge above Lost River.
-#211
-A very narrow and treacherous ledge.
-#212
-You're in phone booth.
-#213
-You're at the east end of a level passage at a hole in the floor.
-#214
-You're in dark cove.
-#215
-You're in dry basin.
-#216
-You're in old spillway.
-#217
-You're in the Winery.
-#218
-You're at limestone pinnacles.
-#219
-You're in Gothic Cathedral.
-#220
-You're at the east portal of the Gothic Cathedral.
-#221
-You're at the west portal of the Gothic Cathedral.
-#222
-You are at the foot of the Altar, an immense, broad stalagmite.
-#223
-You're on top of stalagmite.
-#224
-You're in the Crypt.
-#225
-You're in Gothic Chapel.
-#226
-You are on the floor of the Rainbow Room.
-#227
-You are at approach to River Styx.
-#228
-You're at the River Styx.
-#229
-You're on the east side of the river's sticks.
-#230
-You're on ledge above limestone pinnacles.
-#231
-You are very neatly skewered on the point of a sharp rock.
-#232
-You have poled your boat across the calm water.
-#233
-You have poled your boat across the dark water.
-#234
-You have poled your boat across the Blue Grotto.
-#235
-You're at Dante's Rest.
-#236
-You're at east end of Lost River Canyon.
-#237
-The staircase is now unclimbable.
-#238
-You're in the caretaker's pantry.
-#239
-You're on a small rise over the bay.
-#240
-You are on the highest pinnacle of the castle in the bay.
-Steps lead down into the garden.
-#241
-You are in the outer courtyard of the elves.
-#242
-You are in the living maze. There are red berries here.
-#243
-You are surrounded by a tall hedge with sharp iridescent leaves
-and metallic orange flowers.
-#244
-You are in the center of the living maze. The plants here are
-dormant this season, but still carry brilliant yellow leaves.
-#245
-Unlike the other areas of the hedge system, this area seems to 
-have no metallic gleam; nevertheless it is still breathtaking.
-The trees and bushes are all variegated shades of green, the
-evergreens being a rich dark shade while the seasonal bushes
-are a lighter yellowish green, making a startling contrast.
-#246
-You are near the edge of the maze. You sample the blueberries
-on the bushes. They are delicious.
-#247
-You are at the western end of the living maze. Beside the
-shrubs forming the walls are tastefully planted beds of
-violets and brilliant purple pansies.
-To the west is the inner garden.
-#248
-You're in the inner courtyard of the elves.
Index: trunk/minix/commands/advent/advent3.txt
===================================================================
--- trunk/minix/commands/advent/advent3.txt	(revision 9)
+++ 	(revision )
@@ -1,539 +1,0 @@
-#1
-#2
-/Brass lantern
-/There is a shiny brass lamp nearby.
-/There is a lamp shining nearby.
-/
-#3
-/*Grate
-/The grate is locked.
-/The grate is open.
-/
-#4
-/Wicker cage
-/There is a small wicker cage discarded nearby.
-/
-#5
-/Black rod
-/A three foot black rod with a rusty star on an end lies nearby.
-/
-#6
-/Black rod
-/A three foot black rod with a rusty mark on an end lies nearby.
-/
-#7
-/*Steps
-/Rough stone steps lead down the pit.
-/Rough stone steps lead up the dome.
-/
-#8
-#9
-/Wooden pole
-/A wooden pole is lying nearby.
-/A wooden pole has been stuck in the mud here.
-/
-#10
-/Velvet pillow
-/A small velvet pillow lies on the floor.
-/
-#11
-/*Snake
-/A huge green fierce snake bars the way!
-/<$$<  (Chased away)
-/
-#12
-/*Fissure
-/<$$<
-/A crystal bridge now spans the fissure.
-/The crystal bridge has vanished!
-/
-#13
-/*Stone tablet
-/A massive stone tablet imbedded in the wall reads:
-"Congratulations on bringing light into the Dark-Room!"
-/
-#14
-/Giant clam  >grunt!<
-/There is an enormous clam here with its shell tightly closed.
-/
-#15
-/Giant oyster  >groan!<
-/There is an enormous oyster here with its shell tightly closed.
-/Interesting.  There seems to be something written on the underside of
-the oyster.
-/
-#16
-/"Spelunker Today"
-/There are a few recent issues of "Spelunker Today" magazine here.
-/
-#17
-#18
-#19
-/Tasty food
-/There is food here.
-/
-#20
-/Small bottle
-/There is a small bottle here.
-/There is an empty bottle here.
-/There is a small bottle here.
-/There is a broken bottle here.
-/There is a small bottle here.
-/
-#21
-/*Chasm - troll bridge
-/A rickety wooden bridge extends across the chasm, vanishing into the
-mist.  A sign posted on the bridge reads, "Stop! Pay troll!"
-/The wreckage of a bridge (and a dead bear) can be seen at the bottom
-of the chasm.
-/
-#22
-/*Chasm2 & decrepit natural bridge
-/A decrepit natural bridge spans the chasm.  A message scrawled into
-the rock wall reads: "Bridge out of repair.  Maximum load: 35 Foonts."
-/The remnants of a natural bridge partially overhang the chasm.
-/
-#23
-/*Mirror
-/<$$<
-/
-#24
-/*plant
-/There is a tiny little plant in the pit, murmuring "Water, water, ..."
-/The plant spurts into furious growth for a few seconds.
-/There is a 12-foot-tall beanstalk stretching up out of the pit,
-bellowing "Water!! Water!!"
-/The plant grows explosively, almost filling the bottom of the pit.
-/There is a gigantic beanstalk stretching all the way up to the hole.
-/You've over-watered the plant!  It's shriveling up!  It's, it's...
-/
-#25
-/*Phony plant (seen in twopit room only when tall enough)
-/<$$<
-/The top of a 12-foot-tall beanstalk is poking out of the west pit.
-/There is a huge beanstalk growing out of the west pit up to the hole.
-/
-#26
-/*Stalactite
-/<$$<
-/
-#27
-/*shadowy figure
-/The shadowy figure seems to be trying to attract your attention.
-/
-#28
-/Dwarf's axe
-/There is a little axe here.
-/There is a little axe lying beside the bear.
-/There is a little axe lying beside the Wumpus.
-/There is a little axe lying beside the dog.
-/
-#29
-/*Cave drawings
-/<$$<
-/
-#30
-/*pirate
-/<$$<
-/
-#31
-/*dragon
-/A huge green fierce dragon bars the way!
-/Congratulations!  You have just vanquished a dragon with your bare
-hands!  (Unbelievable, isn't it?)
-/The body of a huge green dead dragon is lying off to one side.
-/
-#32
-#33
-/*Troll
-/A burly troll stands by the bridge and insists you throw him a
-treasure before you may cross.
-/The troll steps out from beneath the bridge and blocks your way.
-/<$$<  (Chased away)
-/
-#34
-/*phony troll
-/The troll is nowhere to be seen.
-/
-#35
-/<$$<  (Bear uses rtext 141)
-/There is a ferocious cave bear eying you from the far end of the room!
-/There is a gentle cave bear sitting placidly in one corner.
-/There is a contented-looking bear wandering about nearby.
-/<$$<  (Dead)
-/
-#36
-/*Message in second maze
-/There is a message scrawled in the dust in a flowery script, reading:
-"This is not the maze where the pirate leaves his treasure chest."
-/
-#37
-/*Volcano and/or geyser
-/<$$<
-/
-#38
-/*Vending machine
-/There is a massive vending machine here.  The instructions on it
-read:  "Insert coins to receive fresh batteries."
-/There is a massive vending machine here.
-/
-#39
-/Batteries
-/There are fresh batteries here.
-/Some worn-out batteries have been discarded nearby.
-/Some worn-out batteries have been discarded nearby.
-/
-#40
-/*Carpet and/or moss
-/<$$<
-/
-#41
-/*Rusty door
-/The way north is barred by a massive, rusty, iron door.
-/The way north leads through a massive, rusty, iron door.
-/
-#42
-/*Tiny door
-/The only way past the wall is through a tiny locked door.
-/The only way past the wall is through a tiny open door.
-/
-#43
-/*Tiny door-2
-/The door is locked.
-/The door is open.
-/
-#44
-/*Phone booth door
-/<$$<
-/
-#45
-#46
-/Beautiful flowers
-/There are some beautiful flowers here!
-/On the other side of the room a swarm of bees eagerly buzzes over
-a bunch of fresh flowers.
-/
-#47
-/Silken cloak
-/There is a silken cloak here!
-/<$$<  (wearing cloak)
-/A lovely silken cloak lies partially buried under a pile of
-loose rocks.
-/
-#48
-/Wooden boat
-/There is a small wooden boat here.
-/You are in a wooden boat.
-/
-#49
-/*Sticks at Styx
-/<$$<
-/
-#50
-/Large gold nugget
-/There is a large sparkling nugget of gold here!
-/
-#51
-/Several diamonds
-/There are diamonds here!
-/
-#52
-/Silver horn
-/There is a silver horn here!
-/
-#53
-/Precious jewelry
-/There is precious jewelry here!
-/<$$<  (wearing jewelry)
-/
-#54
-/Rare coins
-/There are many coins here!
-/
-#55
-/Treasure chest
-/The pirate's treasure chest is here!
-/
-#56
-/Golden eggs
-/There is a large nest here, full of golden eggs!
-/The nest of golden eggs has vanished!
-/Done!
-/
-#57
-/Jeweled trident
-/There is a jewel-encrusted trident here!
-/
-#58
-/Ming vase
-/There is a delicate, precious, ming vase here!
-/The vase is now resting, delicately, on a velvet pillow.
-/The floor is littered with worthless shards of pottery.
-/The ming vase drops with a delicate crash.
-/
-#59
-/Egg-sized emerald
-/There is an emerald here the size of a plover's egg!
-/
-#60
-/Platinum pyramid
-/There is a platinum pyramid here, 8 inches on a side!
-/
-#61
-/Glistening pearl
-/Off to one side lies a glistening pearl!
-/
-#62
-/Persian rug
-/There is a persian rug spread out on the floor!
-/The dragon is sprawled out on a persian rug!!
-/
-#63
-/Rare spices
-/There are rare spices here!
-/
-#64
-/Golden chain
-/There is a golden chain lying in a heap on the floor!
-/The bear is locked to the wall with a golden chain!
-/There is a golden chain locked to the wall!
-/
-#65
-/Gleaming sword
-/There is a gleaming sword here!
-/A gleaming sword is stuck into the anvil!
-/You grasp the sword's handle and give a mighty heave, but with a
-loud clang the sword blade shatters into several fragments.
-/Rusty shards of a elven sword lie scattered about.
-/A very clean sword is stuck into the anvil!
-/An oily sword is stuck into the anvil.
-/
-#66
-/Elfin crown
-/An ancient crown of elfin kings lies here!
-/<$$<  (wearing crown)
-/
-#67
-/Ruby slippers
-/There is a pair of ruby slippers here.
-/<$$<  (wearing slippers)
-/There is a pair of ruby slippers here.
-/
-#68
-/Delicate lyre
-/There is a delicate lyre here!
-/
-#69
-/Star sapphire
-/There is a star sapphire here!
-/
-#70
-/Holy Grail
-/There is an ornate silver chalice here!
-/
-#71
-/Oaken cask
-/There is an oaken cask here.
-/There is an empty oaken cask here.
-/There is an oaken cask here.
-/<$$<  (Unused)
-/There is an oaken cask here.
-/
-#72
-/Golden ring
-/There is a small gold ring here.
-/<$$<  (wearing ring)
-/On the Wumpus' finger is a small gold ring.
-/
-#73
-/Four-leafed clover
-/There is a four-leafed clover here!
-/<$$<  (wearing clover)
-/
-#74
-/Gold tree
-/There is a gold statue of a tree here.
-/
-#75
-/Silver droplet
-/There is a single droplet of silver on the ground here.
-/
-#76
-#77
-#78
-#79
-#80
-#81
-/Clear water
-/
-#82
-/Cool water
-/
-#83
-/Thick, black oil
-/
-#84
-/Thick, black oil
-/
-#85
-/Vintage wine
-/
-#86
-/Vintage wine
-/
-#87
-/*Bumblebees
-/<$$<
-/Some bumblebees are swarming around a bunch of fresh flowers.
-/
-#88
-/*Hollow wall
-/Your footsteps echo hollowly throughout the chamber.
-/<$$<
-/
-#89
-/*Wall with safe
-/A steel safe is embedded in the wall.
-/
-#90
-/Tiny brass key
-/There is a tiny brass key here.
-/There is a tiny brass key on the shelf.
-/
-#91
-/*Anvil
-/<$$<
-/
-#92
-/*rocks on cloak
-/<$$<  (ON CLOAK)
-/<$$<  (AFTER ROCK SLIDE)
-/
-#93
-/*telephone booth
-/The telephone booth is empty.
-
-The phone is ringing.
-/The phone booth is occupied by a gnome.  He is talking excitedly
-to someone at the other end.
-/The telephone booth is empty.
-/<$$<
-/
-#94
-/*Telephone
-/The phone is ringing.
-/The telephone is out of order.
-/The telephone is out of order.  It is badly dented.
-/<$$<
-/
-#95
-/Lead slugs
-/There are some lead slugs here!
-/
-#96
-/Sweet honeycomb
-/There is a sweet honeycomb here!
-/
-#97
-/*Beehive
-/There is an active beehive nearby.  The bees hum protectively
-around the hive.
-/There is an empty beehive nearby.
-/
-#98
-/*Black dog
-/A hideous black dog bares his teeth and growls at your approach.
-/Nearby, a large black dog is in a deep slumber.
-/
-#99
-/*Dreaded Wumpus
-/In the corner, a Wumpus is sleeping peacefully.
-/A sleepy Wumpus is ambling towards you.  He wants to invite you to
-dinner.  He wants you to *be* the dinner!
-/The Wumpus is still on your trail!  And he's getting closer!!
-/The Wumpus is only a few steps behind you!  All this exercise is
-making him veerrrrry hungry!
-/The Wumpus almost has you in his grasp!  You can feel his hot breath
-on your neck!
-/"Chomp, chomp."  Crunch!  Chew!  Slurp!  Smack!  Yum!!!
-/Nearby is the smashed body of a defunct Wumpus.
-/
-#100
-#101
-/Little bird in cage
-/A cheerful little bird is sitting here singing.
-/There is a little bird in the cage.
-/
-#102
-/Set of keys
-/There are some keys on the ground here.
-/
-#103
-/*Fountain
-/There is a fountain of sparkling vintage wine here!
-/
-#104
-/*Bats & guano in bat-cave
-/<$$<
-/
-#105
-/*gnome in phone booth
-/<$$<
-/
-#106
-/Colored mushrooms
-/There are some oddly-colored mushrooms here.
-/
-#107
-/Tiny cakes
-/There are some tiny cakes on the shelf.
-/
-#108
-/Leather Sack
-/There is a leather sack here.
-/
-#109
-#110
-/Rare book
-/There is a dusty, leather-bound volume here.
-/
-#111
-/Rare book
-/There is a dusty, leather-bound volume here.
-/
-#112
-/Steel wall-safe
-/The safe door is locked.
-/The safe door is open.
-/
-#113
-/Faded poster
-/Taped to the wall is a faded poster.
-/There is a faded poster here.
-/
-#114
-/Whiskbroom
-/There is a small whiskbroom here.
-/
-#115
-/*Carving on dusty rocks
-/<$$<
-/<$$<
-/
-#116
-/*Billboard
-/
-/
-#117
-#118
-/Small metal canister
-/There is a heavy, grey, metal canister here.
-/
-#119
-/Glowing stone
-/Nearby, a strange, greenish stone is glowing brightly.
-/
-#120
-/Quartz sphere
-/There is a polished sphere of pure quartz here!
-/
Index: trunk/minix/commands/advent/advent4.txt
===================================================================
--- trunk/minix/commands/advent/advent4.txt	(revision 9)
+++ 	(revision )
@@ -1,1068 +1,0 @@
-#1
-Somewhere nearby is Colossal Cave, where others have found fortunes in
-treasure and gold, though it is rumored that some who enter are never
-seen again.  Magic is said to work in the cave.  I will be your eyes
-and hands.  Direct me with natural English commands.  I should warn
-you that I look at all the letters of each word. Also you
-should enter "Northeast" as "NE" to distinguish it from "North".
-(Should you get stuck, type "HELP" or "?" for some general hints.)
-Good Luck!
-- - - -
-#2
-A little dwarf with a big knife blocks your way.
-#3
-A little dwarf just walked around a corner, saw you, threw a little
-axe at you which missed, cursed, and ran away.
-#4
-There is a threatening little dwarf in the room with you!
-#5
-One sharp nasty knife is thrown at you!
-#6
-None of them hit you!
-#7
-One of them gets you!
-#8
-A hollow voice says "Plugh".
-#9
-There is no way to go that direction.
-#10
-I am unsure how you are facing.  Use compass points or nearby objects.
-#11
-I don't know in from out here.  Use compass points or name something
-in the general direction you want to go.
-#12
-I don't know how to apply that word here.
-#13
-I don't understand that!
-#14
-I'm game.  Would you care to explain how?
-#15
-Sorry, but I am not allowed to give more detail.  I will repeat the
-long description of your location.
-#16
-It is now pitch dark.  If you proceed you will likely fall into a pit.
-#17
-If you prefer, simply type "W" rather than "West".
-#18
-Are you trying to catch the bird?
-#19
-The bird is frightened right now and you cannot catch it no matter
-what you try.  Perhaps you might try later.
-#20
-Are you trying to somehow deal with the snake?
-#21
-You can't kill the snake, or drive it away, or avoid it, or anything
-like that.  There is a way to get by, but you don't have the necessary
-resources right now.
-#22
-Do you really want to quit now?
-#23
-You fell into a pit and broke every bone in your body!
-#24
-You are already carrying it!
-#25
-You can't be serious!
-#26
-The bird was unafraid when you entered, but as you approach it becomes
-disturbed and you cannot catch it.
-#27
-You can catch the bird, but you cannot carry it.
-#28
-There is nothing here with a lock!
-#29
-You aren't carrying it!
-#30
-The little bird attacks the green snake, and in an astounding flurry
-drives the snake away.
-#31
-You have no keys!
-#32
-It has no lock.
-#33
-I don't know how to lock or unlock such a thing.
-#34
-It was already locked.
-#35
-The grate is now locked.
-#36
-The grate is now unlocked.
-#37
-It was already unlocked.
-#38
-You have no source of light.
-#39
-Your lamp is now on.
-#40
-Your lamp is now off.
-#41
-There is no way to get past the bear to unlock the chain, which is
-probably just as well.
-#42
-Nothing happens.
-#43
-Where?
-#44
-There is nothing here to attack.
-#45
-The little bird is now dead.  Its body disappears.
-#46
-Attacking the snake both doesn't work and is very dangerous.
-#47
-You killed a little dwarf.
-#48
-You attack a little dwarf, but he dodges out of the way.
-#49
-With what?  Your bare hands?
-#50
-Good try, but that is an old worn-out magic word.
-#51
-To move, try words like FOREST, BUILDING, DOWNSTREAM, IN, EAST, NORTH,
-UP, OR DOWN. Saying a place name may take you there, as may some
-magic words. You can say TAKE LAMP or DROP LAMP or PUT LAMP IN SACK.
-Some objects have side effects; for instance, the rod scares the bird.
-You can take or drop multiple objects by saying TAKE BOOK AND LAMP,
-etc. To list what you are currently holding, say INVENTORY, or just I.
-To reprint the detailed description of where you are, say LOOK
-or L. You can also LOOK IN or LOOK AT appropriate objects. Other
-useful commands are HEALTH, QUIT, SCORE, BRIEF, TERSE, UNBRIEF,
-UNTERSE, SAVE, and RESTORE. The latter two save or restore your
-current position. To get full credit for a treasure, you must have
-left it **safely** in the building. Some non-treasure items are best
-left near where you find them. There are clues for various problems
-lying about the cave: look and listen. If you seem to have found
-all the treasures, keep looking around a while, something else
-may happen to you (for a bonus!)
-(The word "give" doesn't exist, but you can say FEED BONE TO DOG or
-THROW BONE AT DOG. Also, you can use conveyances or animals(!)
-by TAKEing and DROPing them.)
-#52
-It misses!
-#53
-It gets you!
-#54
-Ok
-#55
-You can't unlock the keys.
-#56
-You have crawled around in some little holes and wound up back in the
-main passage.
-#57
-I don't know where the cave is, but hereabouts no stream can run on
-the surface for long.  I would try the stream.
-#58
-I need more detailed instructions to do that.
-#59
-I can only tell you what you see as you move about and manipulate
-things.  I cannot tell you where remote things are.
-#60
-I can't make any sense out of that.
-#61
-What?
-#62
-Are you trying to get into the cave?
-#63
-The grate is very solid and has a hardened steel lock.  You cannot
-enter without a key, and there are no keys nearby.  I would recommend
-looking elsewhere for the keys.
-#64
-The trees of the forest are large hardwood oak and maple, with an
-occasional grove of pine or spruce.  There is quite a bit of under-
-growth, largely birch and ash saplings plus nondescript bushes of
-various sorts.  This time of year visibility is quite restricted by
-all the leaves, but travel is quite easy if you detour around the
-spruce and berry bushes.
-#65
-
-
-		Welcome to ADVENTURE!
-
-
-	Original development by Willie Crowther.
-
-	Conversion to BDS  C by J. R. Jaeger
-
-	Unix standardization by Jerry D. Pohl.
-
-	Upgraded to version 6.6 by Robert R. Hall.
-
-
-		Would you like instructions?
-
-#66
-Digging without a shovel is quite impractical.  Even with a shovel
-progress is unlikely.
-#67
-Blasting requires dynamite.
-#68
-I'm as confused as you are.
-#69
-Mist is a white vapor, usually water, seen from time to time in
-caverns.  It can be found anywhere but is frequently a sign of a deep
-pit leading down to water.
-#70
-Your feet are now wet.
-#71
-I think I just lost my appetite.
-#72
-Thank you, it was delicious!
-#73
-You have taken a drink from the stream.  The water tastes strongly of
-minerals, but is not unpleasant.  It is extremely cold.
-#74
-The bottle is now empty.
-#75
-Rubbing the electric lamp is not particularly rewarding.  Anyway,
-nothing exciting happens.
-#76
-Peculiar.  Nothing unexpected happens.
-#77
-Your bottle is empty and the ground is wet.
-#78
-You can't pour that.
-#79
-Watch it!
-#80
-Which way?
-#81
-Oh dear, you seem to have gotten yourself killed.  I might be able to
-help you out, but I've never really done this before.  Do you want me
-to try to reincarnate you?
-#82
-All right.  But don't blame me if something goes wr......
-*                    --- POOF!! ---                    *
-You are engulfed in a cloud of orange smoke.  Coughing and gasping,
-you emerge from the smoke and find....
-
-#83
-You clumsy oaf, you've done it again!  I don't know how long I can
-keep this up.  Do you want me to try reincarnating you again?
-#84
-Okay, now where did I put my orange smoke?....  >POOF!<
-Everything disappears in a dense cloud of orange smoke.
-
-#85
-Now you've really done it!  I'm out of orange smoke!  You don't expect
-me to do a decent reincarnation without any orange smoke, do you?
-#86
-Okay, if you're so smart, do it yourself!  I'm leaving!
-#87
-#88
-#89
-#90
->>> Messages 81 thru 90 are reserved for "Obituaries". <<<
-#91
-Sorry, but I no longer seem to remember how it was you got here.
-#92
-It's too heavy.  You'll have to drop something first.
-#93
-You can't go through a locked steel grate!
-#94
-I believe what you want is right here with you.
-#95
-You don't fit through a two-inch slit!
-#96
-I respectfully suggest you go across the bridge instead of jumping.
-#97
-There is no way across the fissure.
-#98
-You're not carrying anything.
-#99
-You are currently holding the following:
-#100
-It's not hungry (it's merely pining' for the fjords).  Besides, you
-have no bird seed.
-#101
-The snake has now devoured your bird.
-#102
-There's nothing here it wants to eat (except perhaps you).
-#103
-You fool, dwarves eat only coal!  Now you've made him *REALLY* mad!!
-#104
-Your cask is empty and the ground is soaked.
-#105
-You aren't carrying them!
-#106
-I don't need to, thank you.
-#107
-The ground is wet and the air is smelly.
-#108
-Your lamp is now on, but the glare from the walls is absolutely
-blinding.  If you proceed you are likely to fall into a pit.
-#109
-You haven't any matches.
-#110
-Don't be ridiculous!
-#111
-The door is extremely rusty and refuses to open.
-#112
-The plant indignantly shakes dry its leaves and asks, "Water?"
-#113
-The hinges are quite thoroughly rusted now and won't budge.
-#114
-The oil has freed up the hinges so that the door will now move,
-although it requires some effort.
-#115
-The plant has exceptionally deep roots and cannot be pulled free.
-#116
-The dwarves' knives vanish as they strike the walls of the cave.
-#117
-Something you're carrying won't fit through the tunnel with you.
-You'd best take inventory and drop something.
-#118
-You can't fit this five-foot clam through that little passage!
-#119
-You can't fit this five-foot oyster through that little passage!
-#120
-I advise you to put down the clam before opening it.  >Strain!<
-#121
-I advise you to put down the oyster before opening it.  >Wrench!<
-#122
-You don't have anything strong enough to open the clam.
-#123
-You don't have anything strong enough to open the oyster.
-#124
-A glistening pearl falls out of the clam and rolls away.  Goodness,
-this must really be an oyster.  (I never was very good at identifying
-bivalves.)  Whatever it is, it has now snapped shut again.
-#125
-The oyster creaks open, revealing nothing but oyster inside.  It
-promptly snaps shut again.
-#126
-You have crawled around in some little holes and found your way
-blocked by a recent cave-in.  You are now back in the main passage.
-#127
-There are faint rustling noises from the darkness behind you.
-#128
-Out from the shadows behind you pounces a bearded pirate!  "Har, har,"
-he chortles, "I'll just take all this booty and hide it away with me
-chest deep in the maze!"  He snatches your treasure and vanishes into
-the gloom.
-#129
-A sepulchral voice reverberating through the cave, says, "Cave closing
-soon.  All adventurers exit immediately through Main Office."
-#130
-A mysterious recorded voice groans into life and announces:
-   "This exit is closed.  Please leave via Main Office."
-
-#131
-It looks as though you're dead.  Well, seeing as how it's so close to
-closing time anyway, I think we'll just call it a day.
-
-#132
-The sepulchral voice intones, "The cave is now closed."  As the echoes
-fade, there is a blinding flash of light (and a small puff of orange
-smoke). . . .    As your eyes refocus, you look around and find...
-
-#133
-There is a loud explosion, and a twenty-foot hole appears in the far
-wall, burying the dwarves in the rubble.  You march through the hole
-and find yourself in the Main Office, where a cheering band of
-friendly elves carry the conquering adventurer off into the sunset.
-
-#134
-There is a loud explosion, and a twenty-foot hole appears in the far
-wall, burying the snakes in the rubble.  A river of molten lava pours
-in through the hole, destroying everything in its path, including you!
-
-#135
-There is a loud explosion, and you are suddenly splashed across the
-walls of the room.
-
-#136
-The resulting ruckus has awakened the dwarves.  There are now several
-threatening little dwarves in the room with you!  Most of them throw
-knives at you!  All of them get you!
-
-#137
-Oh, leave the poor unhappy bird alone.
-#138
-I dare say whatever you want is around here somewhere.
-#139
-I'm not sure what you mean by "Stop".  Use "Quit" if you want to give
-up.
-#140
-You can't get there from here.
-#141
-You are being followed by a very large, tame bear.
-#142
--          *** THE HISTORY OF ADVENTURE (ABRIDGED) ***          -
--                    ** By Ima Wimp **                          -
-ADVENTURE was originally developed by William Crowther, and later
-substantially rewritten and expanded by Don Woods at Stanford Univ.
-According to legend, Crowther's original version was modelled on an
-a real cavern, called Colossal Cave, which is a part of Kentucky's
-Mammoth Caverns.  That version of the game included the main maze
-and a portion of the third-level (Complex Junction - Bedquilt -
-Swiss Cheese rooms, etc.), but not much more.
-Don Woods and some others at Stanford later rewrote portions of
-the original program, and greatly expanded the cave.  That version
-of the game is recognizable by the maximum score of 350 points.
-Some major additions were done by David Long while at the University
-of Chicago, Graduate School of Business. Long's additions include the
-seaside entrance and all of the cave on the "far side" of Lost River
-(Rainbow Room - Crystal Palace - Blue Grotto, etc.).
-The castle problem was added in late 1984 by an anonymous writer.
-Thanks are owed to Roger Matus and David Feldman, both of U. of C.,
-for several suggestions, including the Rainbow Room, the telephone
-booth and the fearsome Wumpus. Most thanks (and apologies)
-go to Thomas Malory, Charles Dodgson, the Grimm Brothers, Dante,
-Homer, Frank Baum and especially Anon., the real authors of ADVENTURE.
-#143
-Do you indeed wish to quit now?
-#144
-There is nothing here with which to fill the vase.
-#145
-The sudden change in temperature has delicately shattered the vase.
-#146
-It is beyond your power to do that.
-#147
-I don't know how.
-#148
-It is too far up for you to reach.
-#149
-You killed a little dwarf.  The body vanishes in a cloud of greasy
-black smoke.
-#150
-The shell is very strong and is impervious to attack.
-#151
-What's the matter, can't you read?  Now you'd best start over.
-#152
-The axe bounces harmlessly off the dragon's thick scales.
-#153
-The dragon looks rather nasty.  You'd best not try to get by.
-#154
-The little bird attacks the green dragon, and in an astounding flurry
-gets burnt to a cinder.  The ashes blow away.
-#155
-On what?
-#156
-Okay, from now on I'll only describe a place in full the first time
-you come to it.  To get the full description, say "LOOK".
-#157
-Trolls are close relatives with the rocks and have skin as tough as
-that of a rhinoceros.  The troll fends off your blows effortlessly.
-#158
-The troll deftly catches the axe, examines it carefully, and tosses it
-back, declaring, "Good workmanship, but it's not valuable enough."
-#159
-The troll catches your treasure and scurries away out of sight.
-#160
-The troll refuses to let you cross.
-#161
-There is no longer any way across the chasm.
-#162
-Just as you reach the other side, the bridge buckles beneath the
-weight of the bear, which was still following you around.  You
-scrabble desperately for support, but as the bridge collapses you
-stumble back and fall into the chasm.
-#163
-The bear lumbers toward the troll, who lets out a startled shriek and
-scurries away.  The bear soon gives up the pursuit and wanders back.
-#164
-The axe misses and lands near the bear where you can't get at it.
-#165
-With what?  Your bare hands?  Against *HIS* bear hands??
-#166
-The bear is confused; he only wants to be your friend.
-#167
-For crying out loud, the poor thing is already dead!
-#168
-The bear eagerly licks up the honeycomb, after which he seems to calm
-down considerably and even becomes rather friendly.
-#169
-The bear is still chained to the wall.
-#170
-The chain is still locked.
-#171
-The chain is now unlocked.
-#172
-The chain is now locked.
-#173
-There is nothing here to which the chain can be locked.
-#174
-There is nothing here to eat.
-#175
-Do you want the hint?
-#176
-Do you need help getting out of the maze?
-#177
-You can make the passages look less alike by dropping things.
-#178
-Are you trying to explore beyond the Plover Room?
-#179
-There is a way to explore that region without having to worry about
-falling into a pit.  None of the objects available is immediately
-useful in discovering the secret.
-#180
-Do you need help getting out of here?
-#181
-Don't go west.
-#182
-Gluttony is not one of the troll's vices.  Avarice, however, is.
-#183
-Your lamp is getting dim.  You'd best start wrapping this up, unless
-you can find some fresh batteries.  I seem to recall there's a vending
-machine in the maze.  Bring some coins with you.
-#184
-Your lamp has run out of power.
-#185
-There's not much point in wandering around out here, and you can't
-explore the cave without a lamp.  So let's just call it a day.
-#186
-There are faint rustling noises from the darkness behind you.  As you
-turn toward them, the beam of your lamp falls across a bearded pirate.
-He is carrying a large chest.  "Shiver me timbers!", he cries, "I've
-been spotted!  I'd best hie meself off to the maze to hide me chest!"
-With that, he vanishes into the gloom.
-#187
-Your lamp is getting dim.  You'd best replace those batteries.
-#188
-Your lamp is now shining with renewed strength.
-#189
-Your lamp is getting dim, and you haven't any more coins.  You'd
-best start wrapping this up.
-#190
-I'm afraid the magazine is written in dwarvish.
-#191
-"This is not the maze where the pirate leaves his treasure chest."
-#192
-Hmmm, this looks like a clue, which means it'll cost you 10 points to
-read it.  Should I go ahead and read it anyway?
-#193
-It says, "Not all black rods are magic wands. Some are useful for
-other cave construction purposes. There might be some around here."
-#194
-It says the same thing it did before.
-#195
-I'm afraid I don't understand.
-#196
-"Congratulations on bringing light into the dark-room!"
-#197
-You strike the mirror a resounding blow, whereupon it shatters into a
-myriad tiny fragments.
-#198
-You have taken the vase and hurled it delicately to the ground.
-#199
-You prod the nearest dwarf, who wakes up grumpily, takes one look at
-you, curses, and grabs for his axe.
-#200
-Is this acceptable?
-#201
-There's no point in suspending a demonstration game.
-#202
-You managed to climb about halfway up before losing your hold and
-sliding back.
-#203
-You were only a few yards from the top when you slipped and tumbled
-all the way back down.
-#204
-Ok, ok.  No need to be grabby.
-#205
-Pulling an angry bear around is a good way to get your arm ripped off.
-#206
-The sword is now very clean.
-#207
-The sword is now covered with oil.
-#208
-The handle is now too slippery to grasp.
-#209
-You have no scabbard!
-#210
-You are already wearing it!
-#211
-Do you want to extract the sword from the anvil?
-#212
-If you could convince me of your royal blood, you might get somewhere.
-#213
-Are you trying to go up the slide?
-#214
-Maybe you'd better look for another way into the cave.
-#215
-You grasp the sword's handle and pull, but the sword won't budge.
-Do you want to try yanking it out?
-#216
-A tiny elf runs straight at you, shouts "Phuce!", and
-disappears into the forest.
-#217
-You can't swim.  You'd best go by boat.
-#218
-The boat's oars were stolen by the dwarves to play bing-bong.
-(That's dwarvish ping-pong -- with rocks!).  You have no way
-to propel the boat.
-#219
-You are still in the boat.  It is too heavy to carry.
-#220
-You had better leave the boat first.
-#221
-You are now sitting in a small boat.
-#222
-You couldn't possibly cross this sea without a large ship.
-#223
-The cliff is unscalable.
-#224
-Your keys are all too large for the lock.
-#225
-The wall is too smooth to climb.
-#226
-The shelf is beyond your reach.
-#227
-You are already wearing them!
-#228
-You thought maybe these were peyote??  You feel a little dizzy,
-but nothing happens.
-#229
-You are growing taller, expanding like a telescope!  Just before
-your head strikes the top of the chamber, the mysterious process
-stops as suddenly as it began.
-#230
-You are closing up like an accordion....shrinking..shrinking.  You
-are now your normal size.
-#231
-You have smashed your bottle all over the ground.
-#232
-You are now too big to leave the way you came in.
-#233
-This is obviously an elfin entrance.  Unless you can squeeze
-yourself through a six-inch door, you'll have to find another
-way into the cave.
-#234
-The wrought-iron door is now locked.
-#235
-The tiny door is now locked.
-#236
-The wrought-iron door is now unlocked.
-#237
-The tiny door is now unlocked.
-#238
-You are blocked by the wrought-iron door.
-#239
-<$$<
-#240
-The Wumpus looks at the food with distaste.  He looks at *YOU* with
-relish!
-#241
-You have jerked the cloak free of the rocks.  However, in doing
-so you have caused a small rock slide, blocking the entrance
-and making an unholy din.
-#242
-The cloak is stuck tight under the rocks.  You'll probably have to
-yank it out.
-#243
-The Wumpus grabs the axe, stops and picks his teeth with it for a few
-moments while looking thoughtfully at you.  When he finishes picking
-his teeth, he eats the axe, belches, farts... and starts after
-you again!
-#244
-As the bridge disappears, the Wumpus scrambles frantically to reach
-your side of the fissure.  He misses by inches, and with a horrible
-shriek plunges to his death in the depths of the fissure!
-#245
-You can't even hit a sleeping Wumpus!  The axe is now lying too near
-the Wumpus for you to retrieve it.
-#246
-The Wumpus is between you and the axe.  You can't reach it.
-#247
-You can't fit through a six-inch door!
-#248
-The dog easily dodges the axe, which lands beyond him where you can't
-get at it.
-#249
-The dog woofs (natch) down the food and looks around hungrily for
-more.  However, he does not appear to be any better disposed towards
-your presence.
-#250
-You've got to be kidding!
-#251
-It's attached to the wall!
-#252
-You can't put a thing into itself!
-#253
-The gnome firmly blocks the door of the booth.  You can't enter.
-#254
-The constant ringing has awakened the dwarves!
-There are now several threatening little dwarves in the room with
-you!  Most of them throw knives at you!  All of them get you!
-#255
-The telephone is out of order.
-#256
-The telephone is out of order and your hand is sore.
-#257
-A couple of lead slugs drop from the coin box.  (Gnomes are
-notoriously cheap....)  But you've broken the phone beyond
-all hope.
-#258
-He wants treasure, not gab.
-#259
-He didn't say anything!
-#260
-It isn't a parrot.  He didn't say anything.
-#261
-No one replies.  The line goes dead with a faint "Click".
-#262
-I think you are a little confused!
-#263
-As you move towards the phone booth, a gnome suddenly streaks
-around the corner, jumps into the booth and rudely slams the door
-in your face.  You can't get in.
-#264
-He isn't hungry.
-#265
-As the blast of the horn reverberates through the chamber, the
-seemingly solid rock wall crumbles away, revealing another room just
-beyond.  The wall was most likely worn thin by an ancient watercourse
-which dried up just before completely wearing away the rock.
-#266
-The chamber reverberates to the blast of the horn.
-(Satchmo you ain't!)
-#267
-The bees swarm over the fresh flowers, leaving the hive unguarded
-and revealing a sweet honeycomb.
-#268
-You are now out of breath.
-#269
-It isn't ringing!
-#270
-A hairy paw reaches out of the darkness and....
-#271
-You don't have the correct change.
-#272
-You go a short way down the bright passage, but the light
-grows to blinding intensity.  You can't continue.
-#273
-You know, if you type "BRIEF", I won't have to keep repeating these
-long descriptions of each room.
-#274
-Are you trying to reach the natural bridge?
-#275
-You can't get to it by climbing the walls or jumping or anything
-like that.  You could always put in a telephone call to the local
-spelunking club for advice, if you could find a phone.
-#276
-You turkey!!!  Now you've done it!  It took some effort, but you
-woke up the Wumpus.  He slowly opens one red eye, and then another,
-and then one more (!!), and looks at you sleepily.  He had been
-dreaming of a late snack.  If you don't act quickly, you'll
-be a *late* adventurer!
-#277
-The blast of your horn echoes throughout hill and dale.
-#278
-All you have are watercress sandwiches.  The bear is less than
-interested.
-#279
-You have smashed your sword to smithereens against a rock.
-#280
-Setting yourself adrift in the boat with no way to propel it would
-not be very smart.  Best to keep the pole.
-#281
-You're already in it!
-#282
-You've hit the jackpot!!  Hundreds of coins and slugs cascade from
-the telephone's coin return slot and spill all over the floor of
-the booth.
-#283
-Whoops!  The floor has opened out from under you!  It seems you
-have fallen into a bottomless pit.  As a matter of fact, you're
-still falling!  Well, I have better things to do than wait around
-for you to strike bottom, so let's just assume you're dead.
-Sorry about that, Chief.
-#284
-The telephone in the booth has begun to ring.
-#285
-I don't understand what you are trying to do!
-#286
-How do you propose to cross the river?
-#287
-The air is filled with beautiful music.
-#288
-The air fills with beautiful music.  The dog gradually becomes
-less fierce, and after a short while he lies down by the side of
-the cavern and falls into a deep sleep.
-#289
-Are you trying to get past the dog?
-#290
-The only person I can remember who managed to get past the dog
-was that singer, ummm, what's his name... Eurydice's friend....
-#291
-That wouldn't be wise.  It is best to let sleeping dogs lie.
-#292
-The stream flows out of one very small crack and into another.
-You can't go that way.
-#293
-The river is too wide and deep to cross.
-#294
-The glare is absolutely blinding.  If you proceed you are likely
-to fall into a pit.
-#295
-The hum of the bees rises to an angry buzz as you move towards
-the hive.
-#296
-The sticks and branches are all in a tangle and are stuck in the
-mud.  You'd need a shovel to dig them out.
-#297
-You're already carrying them!
-#298
-The chalice is slightly cracked.  It won't hold any liquids.
-#299
-The cask is now empty.
-#300
-The wine goes right to your head.  You reel around in a drunken
-stupor and finally pass out.  You awaken with a splitting headache,
-and try to focus your eyes....
-#301
-Yeeeecchhh!!
-#302
-Your bottle is already full.
-#303
-The cask is already full.
-#304
-There is nothing here with which to fill the bottle.
-#305
-There is nothing here which you would want to put into the cask.
-#306
-Your bottle is now full of water.
-#307
-The cask is now full of water.
-#308
-Your bottle is now full of oil.
-#309
-The cask is now full of oil.
-#310
-The bottle is now full of wine.
-#311
-The cask is now full of wine.
-#312
-You have nothing in which to carry it.
-#313
-You can't fill that.
-#314
-Do you want it in the bottle or the cask?
-#315
-Your containers are both full.
-#316
-It's empty.
-#317
-Hmmm, I see you have already gone through an extra set of batteries.
-I'll get rid of the trash for you.
-#318
-The bridge shakes as you cross.  Large hunks of clay and rock near
-the edge break off and hurtle far down into the chasm.  Several of
-the cracks on the bridge surface widen perceptibly.
-#319
-The load is too much for the bridge!  With a roar, the entire
-structure gives way, plunging you headlong into the raging river at
-the bottom of the chasm and scattering all your holdings.  As the
-icy waters close over your head, you flail and thrash with all your
-might, and with your last ounce of strength pull yourself onto the
-south bank of the river.
-#320
-You can't get at him.  He is inside the phone booth.
-#321
-Your lamp is already on.
-#322
-Your lamp is already off.
-#323
-Your lamp is again growing dim.  You'd better get some more batteries.
-#324
-You know, you are wasting your batteries by wandering around out
-here with your light on.
-#325
-<Generic Adventure -- Version:7.0, July 1994>
-#326
-Dead wumpi, as a rule, are light eaters.  Nothing happens.
-#327
-How do expect to feed a sleeping Wumpus?
-#328
-You aren't holding it!
-#329
-It won't fit!
-#330
-The coin drops into the slot with a dull "clunk".  There is no
-dial tone.
-#331
-It's already there.
-#332
-Please read the supplied documentation files to find out where to
-send complaints, suggestions, and bug reports.
-#333
-The chest is now unlocked.
-#334
-The chest is now locked.
-#335
-You can't get at it.
-#336
-It's already open.
-#337
-It's locked.
-#338
-It's already closed.
-#339
-You can't fill that.  It would leak all over the place.
-#340
-It's not inside anything.
-#341
-It isn't there!
-#342
-How?
-#343
-Taken.
-#344
-Dropped.
-#345
-I don't think I can.
-#346
-Interesting.  How?
-#347
-Huh?
-#348
-You are in perfect health.
-#349
-You are fit as a fiddle.
-#350
-Only wizards can do that!
-#351
-Are you kidding?  Do you want to suffocate the poor thing?
-#352
-Thrown.
-#353
-Left.
-#354
-You can't get close enough for a clean thrust.
-#355
-As you move in for the kill, the dwarf neatly slips a knife
-between your ribs.
-#356
-As you approach, the dwarf slashes out with his knife!
-#357
-It's too dark to see anything!
-#358
-It's not open.
-#359
-There's nothing inside.
-#360
-It contains:
-#361
-The billboard reads:
-"Visit Beautiful Colossal Cave.  Open Year Around.  Fun for
-the entire family, or at least for those who survive."
-Below the headline is an impossibly complicated map showing how
-to find Colossal Cave.  Not that it matters, because all the
-directions are written in Elvish.
-#362
-Hidden behind the poster is a steel safe, embedded in the wall.
-#363
-Brushing the dust from one of the larger rocks reveals some carved
-characters.
-#364
-Enough dusting, already!  You're making me sneeze.
-#365
-The safe door smoothly swings open.
-#366
-Maybe if you rubbed your fingertips with sandpaper....
-#367
-The safe's door clicks shut.
-#368
-This is a combination safe.  The keys won't help.
-#369
-I certainly can't read in this light.
-#370
-The poster has a picture of a thin man with a long white beard.
-He is wearing a high pointed cap embroidered with strange symbols,
-and he is pointing a finger at you.  Below the picture are the words:
-"I want you!--To report all good ideas for extensions to this game
-to me without delay.  Remember: ask not what ADVENTURE can do to
-you; ask what you can do for ADVENTURE."
--                       *  *  *                              -
-"A public service of the John Dillinger Died for You Society."
-#371
-"Click."
-#372
-In the rock is carved the message "7-22-34".
-#373
-You can't get at them.
-#374
-Ok, I'll give you the full description whenever you enter a room
-for the first time.
-#375
-You don't have the right key.
-#376
-That's not strong enough to open the clam.
-#377
-That's not strong enough to open the oyster.
-#378
-Game suspension is no longer permitted!
-#379
-** Unused **
-#380
->>> Messages 381 thru 389 are reserved for "Diagnoses". <<<
-#381
-You are a bit off top form, but nothing to worry about.
-#382
-You are weaker than usual.  Better avoid fights.
-#383
-You really ought to take a break.  You're in tough shape.
-#384
-You are on the edge of collapse.  Lots of sun and fresh air will
-speed your recovery.
-#385
-Your strength is nearly gone.  Only a miracle can save you now.
-#386
-** Unused **
-#387
-** Unused **
-#388
-** Unused **
-#389
-** Unused **
-#390
->>> Messages 391 thru 399 are reserved for Radium Poisoning. <<<
-#391
-Is it hot in here?  You are flushed and sweating.
-#392
-You are feeling definitely peculiar, weak....
-#393
-You're dizzy, nauseous.  You can barely stand.
-#394
-You are really ill.  If you don't find an antidote soon, it's
-curtains.
-#395
-You are a walking wound.  You are very weak.  You'd better find out
-what's wrong before it's too late.
-#396
-Sheeesh!  What a mess!  Your hair has fallen out and your skin is
-covered with blisters.  And not an aspirin in sight!
-#397
-Well, you tried, but your strength is gone.  The agony is finally
-over.
-#398
-** Unused **
-#399
-** Unused **
-#400
-You feel rather disembodied, as if you were suddenly somewhere
-else entirely.
-#401
-You sense that you are in a dark place. The only thing in sight
-appears to be a companion to the crystal ball which holds your
-gaze. It seems to be searching the gloom for something to
-show you, but all it can see is itself: a brilliant blue
-six-pointed star suspended in space.
-#402
-Your gaze withdraws from the crystal ball, and you are now back
-in your normal senses.
-#403
-A large, stately elf walks up the rise, says the word
-"Saint-Michel", and is instantly transported to the castle.
-#404
-Are you trying to get to the castle?
-#405
-It's easy to get there if you know how. The elves cross over
-from here so perhaps you might watch an elf to see how.
-Of course they are a bit shy, so keep a good way off while you
-watch.
-#406
-You get a tingling feeling as you walk through the gate, and ...
-#407
-Fiddling with the bird in its cage is not useful.
-If you had it in your hand it would make a mess.
-#408
-Would you like a map?
Index: trunk/minix/commands/advent/build
===================================================================
--- trunk/minix/commands/advent/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/advent/database.c
===================================================================
--- trunk/minix/commands/advent/database.c	(revision 9)
+++ 	(revision )
@@ -1,141 +1,0 @@
-/*	program DATABASE.C					*/
-
-#include	<string.h>
-#include	<stdio.h>
-#include	"advent.h"
-#include	"advdec.h"
-#include	"advtext.h"
-
-static char oline[256];
-
-_PROTOTYPE(void rdupto, (FILE *, int, int, char *));
-_PROTOTYPE(void rdskip, (FILE *, int, int));
-
-/*
-  Function to scan a file up to a specified
-  point and either print or return a string.
-*/
-void rdupto(fdi, uptoc, print, string)
-FILE *fdi;
-int uptoc, print;
-char *string;
-{
-    int c, i;
-    static _CONST unsigned char key[4] = {'c' | 0x80, 'L' | 0x80,
-					  'y' | 0x80, 'D' | 0x80};
-
-    i = 1;
-    while ((c = getc(fdi)) != uptoc && c != EOF) {
-	if (c == '\n')
-	    i = 1;
-	if (c >= 0x80)
-	    c ^= key[i++ & 3];
-	if (c == '\r')
-	    continue;
-	if (print)
-	    putchar(c);
-	else
-	    *string++ = (char) c;
-    }
-    if (!print)
-	*string = '\0';
-    return;
-}
-
-/*
-  Function to read a file skipping
-  a given character a specified number
-  of times, with or without repositioning
-  the file.
-*/
-void rdskip(fdi, skipc, n)
-FILE *fdi;
-int skipc, n;
-{
-    int c;
-
-    while (n--)
-	while ((c = getc(fdi)) != skipc)
-	    if (c == EOF)
-		bug(32);
-    return;
-}
-
-/*
-  Routine to request a yes or no answer to a question.
-*/
-boolean yes(msg1, msg2, msg3)
-int msg1, msg2, msg3;
-{
-    char answer[INPUTBUFLEN];
-
-    if (msg1)
-	rspeak(msg1);
-    do {
-	switch (*ask("\n> ", answer, sizeof(answer))) {
-	case 'n':
-	case 'N':
-	    if (msg3)
-		rspeak(msg3);
-	    return (FALSE);
-	case 'y':
-	case 'Y':
-	    if (msg2)
-		rspeak(msg2);
-	    return (TRUE);
-	default:
-	    fputs("Please answer Y (yes) or N (no).", stdout);
-	}
-    } while (TRUE);
-}
-
-/*
-  Print a location description from "advent4.txt"
-*/
-void rspeak(msg)
-int msg;
-{
-    if (msg == 54)
-	printf("ok.\n");
-    else {
-	fseek(fd4, idx4[msg - 1], 0);
-	rdupto(fd4, '#', 1, 0);
-    }
-    return;
-}
-
-/*
-  Print an item message for a given state from "advent3.txt"
-*/
-void pspeak(item, state)
-int item, state;
-{
-    fseek(fd3, idx3[item - 1], 0);
-    rdskip(fd3, '/', state + 2);
-    rdupto(fd3, '/', FALSE, oline);
-    if (strncmp(oline, "<$$<", 4) != 0)
-	printf("%s", oline);
-    return;
-}
-
-/*
-  Print a long location description from "advent1.txt"
-*/
-void desclg(loc)
-int loc;
-{
-    fseek(fd1, idx1[loc - 1], 0);
-    rdupto(fd1, '#', 1, 0);
-    return;
-}
-
-/*
-  Print a short location description from "advent2.txt"
-*/
-void descsh(loc)
-int loc;
-{
-    fseek(fd2, idx2[loc - 1], 0);
-    rdupto(fd2, '#', 1, 0);
-    return;
-}
Index: trunk/minix/commands/advent/english.c
===================================================================
--- trunk/minix/commands/advent/english.c	(revision 9)
+++ 	(revision )
@@ -1,676 +1,0 @@
-/*	program ENGLISH.C					*/
-
-
-#include	<stdio.h>
-#include	<string.h>
-#include	<ctype.h>
-#include	<stdlib.h>
-#include	"advent.h"
-#include	"advdec.h"
-
-#define ALL	109
-
-#define ENTER	 3
-#define CRAWL	17
-#define JUMP	39
-#define CLIMB	56
-#define XYZZY	62
-#define PLUGH	65
-#define PLOVER	71
-#define PHUCE	82
-
-_PROTOTYPE(static void getwords, (void));
-_PROTOTYPE(static void clrlin, (void));
-_PROTOTYPE(static void doobj, (int *));
-_PROTOTYPE(static boolean doiobj, (void));
-_PROTOTYPE(static boolean do_scoop_up, (void));
-_PROTOTYPE(static boolean check_next, (void));
-
-static char buffer[INPUTBUFLEN] = {'\0', '\0', '\0', '\0'};
-static char *txt[MAXWORDS] = {buffer, buffer, buffer, buffer};
-static char *cindex = buffer;
-static boolean pflag;
-static int vrbkey, words[MAXWORDS] = {0, 0, 0, 0}, word, wdx = 0;
-static int takdir[20] = {2,  6,  9, 10, 11, 13, 14, 17, 23, 25,
-			33, 34, 36, 37, 39, 78, 79, 80, 89, -1};
-
-static int vkey[60] = {
-     0,   199,     9,     0,   130,     0,   197,     0,     0,   243,
-     0,     0,    89,   140,     0,     5,     0,   227,     0,     0,
-     0,    31,    42,     0,     0,     0,     0,   172,     1,     0,
-     0,     0,   254,     0,    69,     0,     0,    92,     0,     0,
-   138,   137,   149,   239,    45,    74,   183,     0,     0,   112,
-   241,     0,   114,     0,    30,     0,     0,     0,     0,     0
-};
-
-static int ptab[260] = {
-     0,  3028,  3065,  3009, -3005,  5071,  5070,  5058, -5020, 19055,
- 19108, 19038, 19020, 19071, 19070, 19058, 19004, 19048, 19091, 19094,
- 19112, 19002, 19118,  2062,  2066,  2047,  2067,  2053,  2065, -2010,
- -3114,  4034,  4011,  4101,  4035,  4099,  4098,  4017,  4104,  4014,
-  4015, -4087,  3083,  3085, -3081,  5055,  5108,  5020,  5071,  5070,
-  5058,  5004,  5048,  5091,  5112,  5099,  5118, 19055, 19108, 19020,
- 19071, 19070, 19058, 19004, 19048, 19091, 19112, 19099,-19118,  3028,
-  3065,  3009,  3005, -3018, 19055, 19108, 19038, 19020, 19071, 19070,
- 19058, 19004, 19004, 19048, 19091, 19094, 19112, 19002,-19118,  3028,
-  3065, -3018, 19055, 19108, 19038, 19020, 19071, 19070, 19058, 19004,
- 19048, 19091, 19094, 19112, 19118,  2062,  2066,  2047,  2067,  2053,
-  2065, -2010,  3102, -3090, 19055, 19108, 19020, 19071, 19070, 19058,
- 19004, 19048, 19091, 19014, 19015, 19112, 19118, 19120, 19120, -9999,
-  3090,  3102,  3028,  3057,  3065,  3009, -3005,-29999,  2052, -2068,
-  2024,  2065,  2091,  2042,  2073,  5071,  5070,  5058, -5020, 30999,
-  2062,  2066,  2047,  2067,  2053,  2065,  2010,  2073, 19055, 19108,
- 19038, 19020, 19071, 19070, 19058, 19004, 19048, 19091, 19094, 19112,
- 19002,-19118,  2014,  2015,  2013,  2999,  5014,  5015,  5013,  5999,
-  5110,  5113, -5999,  5055,  5108,  5020,  5071,  5070,  5058,  5004,
-  5048,  5091,  5014,  5015,  5112,  5099, -5118,  3102, -3090,  6066,
-  6047,  6067,  6053,  6072,  6073,  5055,  5108,  5020,  5071,  5070,
-  5004,  5004,  5048,  5091,  5112,  5099,  5118, 19055, 19108, 19020,
- 19071, 19070, 19058, 19004, 19048, 19091,-19118,  4034,  4011,  4101,
-  4035,  4099,  4098,  4017,  4104,  4027,  4087,  9999,-30999,  2002,
- -6002,  3102, -3090,  9999,  4034,  4011,  4101,  4035,  4099,  4087,
-  4098,  4017,  4104, -4027, -5999,     0,     0,     0,     0,     0,
-};
-
-static int adjkey[40] = {
-     0,    15,    38,    64,     4,    63,     1,    61,    62,    67,
-     9,    27,    53,    46,    47,    60,    31,    39,    40,     6,
-    43,    26,    32,    28,    34,    50,    49,    45,    44,    10,
-    20,    25,    21,    36,    37,    30,    33,     0,     0,     0
-};
-
-static int adjtab[70] = {
-     0,     5,    98,   -83,     2,   -90,    66,    41,   -90,   -39,
-    41,    14,    15,    50,   -11,    50,    64,    56,    72,   -74,
-   -19,   119,    59,    73,  -118,  -119,   -70,   -41,    95,  -118,
-  -118,   -58,   -71,  -120,   110,  -108,  -120,   -73,   -62,   -60,
-   110,    54,   -63,   -67,   -41,   -27,   -47,    52,   -75,   -69,
-    65,   112,    -3,    41,    72,    90,    20,   101,   107,  -118,
-   -55,   -10,   -38,    -4,    48,     9,   -71,   -39,     0,     0
-};
-
-/*
-  Analyze a two word sentence
-*/
-int english()
-{
-
-    char *ch_ptr, *word1, *word2;
-    int type, val, type2, val2, adj, k, kk;
-    static int iwest = 0;
-
-    if (!(words[++wdx])) {
-	getwords();
-	wdx = 0;
-    }
-    pflag = FALSE;
-    word = words[wdx];
-    if (word < 0) {			/* check first word	 */
-	printf("I didn't understand the word \"%s\"\n", txt[wdx]);
-	words[wdx+1] = 0;
-	return (FALSE);			/* didn't know it	 */
-    }
-    type2 = val2 = -1;
-    type = CLASS(word);
-    clrlin();
-    val = VAL(word);
-    if (words[wdx + 1] && CLASS(words[wdx + 1]) != CONJUNCTION) {
-
-	/* 'SAY' or 'CALL'.  If no next word, pass on to higher powers. */
-	if (type == ACTION && (val == SAY || val == YELL)) {
-	    word = words[++wdx];
-	    if (!(word == XYZZY || word == PLUGH
-		  || word == PLOVER || word == PHUCE)) {
-		if (val == SAY)
-		    printf("Okay, \"%s\".\n", txt[wdx]);
-		else {
-		    for (ch_ptr = txt[wdx]; *ch_ptr; ch_ptr++)
-			if (islower(*ch_ptr))
-			    *ch_ptr = toupper(*ch_ptr);
-		    printf("Okay, \"%s\"!!!!!\n", txt[wdx]);
-		}
-		return (FALSE);
-	    }
-	} else {
-	    word1 = txt[wdx];
-	    word2 = txt[wdx + 1];
-
-	    /* Special stuff for 'ENTER'.  Can't go into water. 'ENTER
-	       BOAT' means 'TAKE BOAT' */
-	    if (word == ENTER) {
-		if (CLASS(words[wdx + 1]) == NOUN && VAL(words[wdx + 1]) == BOAT)
-		    word = TAKE + 2000;
-		else if ((strcmp(word2, "stream") == 0)
-			 || (strcmp(word2, "water") == 0)
-			 || (strcmp(word2, "reservoir") == 0)
-			 || (strcmp(word2, "ocean") == 0)
-			 || (strcmp(word2, "sea") == 0)
-			 || (strcmp(word2, "pool") == 0)) {
-		    rspeak(liqloc(g.loc) == WATER ? 70 : 43);
-		    wdx++;
-		    return (FALSE);
-		}
-	    } else {
-		type2 = CLASS(words[wdx + 1]);
-		val2 = VAL(words[wdx + 1]);
-
-		/* 'LEAVE' is motion verb, unsless leaving an object.
-		   E.G., 'LEAVE BOAT' or 'LEAVE BOTTLE'.  BUt make sure
-		   to leave ('DROP') only totable objects. */
-		if (strcmp(word1, "leave") == 0 && type2 == NOUN) {
-		    if (!hinged(val2) || g.fixed[val2])
-			word = LEAVE + 2000;
-
-		    /* IF 'LIGHT LAMP', Light must be taken as an
-		       action verb, not a noun. */
-		} else if (strcmp(word1, "light") == 0
-			   && VAL(words[wdx + 1]) == LAMP) {
-		    word = ON + 2000;
-
-		    /* 'WATER PLANT' becomes 'POUR WATER', If we are at
-		       plant. 'OIL DOOR' becomes 'POUR OIL', etc., etc. */
-		} else if ((strcmp(word1, "water") == 0 || strcmp(word1, "oil") == 0)
-			   && (strcmp(word2, "plant") == 0 || strcmp(word2, "door") == 0
-			       || strcmp(word2, "sword") == 0 || strcmp(word2, "anvil") == 0)
-			   && at(val2)) {
-		    words[wdx + 1] = word;
-		    txt[wdx + 1] = txt[wdx];
-		    word = POUR + 2000;
-		}
-	    }
-	}
-
-    }
-    /* This is the 'inner' loop.  Dispatching of all word in a clause
-       after the first comes through here. */
-    do {
-	switch (CLASS(word)) {
-	case MOTION:
-	    {
-		boolean do_part2;
-		int i;
-
-		do_part2 = FALSE;
-		type = CLASS(verbs[vrbx]);
-		val = VAL(verbs[vrbx]);
-		if (!vrbx)
-		    do_part2 = TRUE;
-		else {
-		    if (type > ACTION) {
-			rspeak(confuz());
-			return (FALSE);
-		    }
-		}
-		if (type == ACTION) {
-		    if (val == GO)
-			do_part2 = TRUE;
-		    else {
-			if (val == TAKE) {
-			    for (i = 0; i < 20; i++)
-				if (takdir[i] == val)
-				    do_part2 = TRUE;
-			}
-			if (!do_part2) {
-			    word = vocab(txt[wdx], 1);
-			    if (word)
-				words[wdx--] = word;
-			}
-		    }
-		} else if (type != CRAWL && type != JUMP
-			   && type != CLIMB)
-		    do_part2 = TRUE;
-		if (do_part2) {
-		    verbs[1] = word;
-		    vrbx = 1;
-		    if (strcmp(txt[wdx], "west") == 0) {
-			iwest++;
-			if (iwest == 10)
-			    rspeak(17);
-		    }
-		}
-		break;
-	    }
-	case NOUN:
-	    if (pflag) {
-		if (!doiobj())
-		    return (FALSE);
-	    } else {
-		word = VAL(word);
-		if (word == ALL) {
-		    if (!do_scoop_up())
-			return (FALSE);
-		} else {
-		    doobj(&word);
-		    if (word > 0) {
-			objs[++objx] = word;
-			otxt[objx] = txt[wdx];
-		    } else {
-			clrlin();
-			pflag = FALSE;
-			wdx++;
-			while (words[wdx]) {
-			    if (CLASS(words[wdx]) == CONJUNCTION)
-				break;
-			    wdx++;
-			}
-			if (words[wdx] == 0)
-			    return (FALSE);
-		    }
-		}
-	    }
-	    break;
-	case ACTION:
-	    if (vrbx == 0)
-		vrbx++;
-	    else {
-		if (VAL(verbs[vrbx]) == TAKE) {
-		    val = VAL(word);
-		    if (val == DRINK || val == INVENTORY
-			|| val == SCORE || val == NOTHING
-			|| val == LOOK);
-		    else if (val == GO && (
-					 strcmp(txt[wdx], "walk") == 0
-				       || strcmp(txt[wdx], "run") == 0
-				   || strcmp(txt[wdx], "hike") == 0));
-		    else {
-			rspeak(confuz());
-			return (FALSE);
-		    }
-		} else if (objx || CLASS(words[wdx - 1]) == CONJUNCTION) {
-		    rspeak(confuz());
-		    return (FALSE);
-		}
-	    }
-	    verbs[vrbx] = word;
-	    vtxt[vrbx] = txt[wdx];
-	    break;
-	case MISC:
-	    if (vrbx) {
-		rspeak(confuz());
-		return (FALSE);
-	    }
-	    verbs[1] = word;
-	    vrbx = 1;
-	    break;
-	case PREPOSITION:
-	    if (CLASS(verbs[vrbx]) != ACTION || iobx) {
-		rspeak(confuz());
-		return (FALSE);
-	    }
-	    vrbkey = vkey[VAL(verbs[vrbx])];
-	    if (!vrbkey) {
-		rspeak(confuz());
-		return (FALSE);
-	    }
-	    prep = VAL(word);
-	    pflag = TRUE;
-	    break;
-	case ADJACTIVE:
-	    /* Adjective handler. Scarf the next word, make sure it is
-	       a valid object for this object.  Then call getobj to see
-	       if it is really there, Then link into object code. */
-	    adj = VAL(word);
-	    if (!check_next())
-		return (FALSE);
-	    else if (CLASS(word) == CONJUNCTION) {
-		printf("%s what?\n", txt[wdx - 1]);
-		return (FALSE);
-	    } else {
-		if (CLASS(word) != NOUN)
-		    word = vocab(txt[wdx], NOUN);
-		if (word == -1 || CLASS(word) != NOUN || VAL(word) == ALL) {
-		    rspeak(confuz());
-		    return (FALSE);
-		}
-		words[wdx] = word;
-		kk = VAL(word);
-		for (k = adjkey[adj]; adjtab[k] >= 0; k++) {
-		    if (kk == abs(adjtab[k]))
-			break;
-		}
-		if (adjtab[k] < 0) {
-		    rspeak(confuz());
-		    return (FALSE);
-		}
-	    }
-	    break;
-	case CONJUNCTION:
-	    if (!check_next())
-		return (FALSE);
-	    switch (CLASS(word)) {
-	    case MOTION:
-	    case ACTION:
-	    case MISC:
-		words[wdx--] = 0;
-		break;
-	    case NOUN:
-	    case ADJACTIVE:
-		break;
-	    case PREPOSITION:
-	    case CONJUNCTION:
-		rspeak(confuz());
-		return (FALSE);
-	    default:
-		bug(33);
-	    }
-	    break;
-	default:
-	    bug(33);
-	}
-	word = words[++wdx];
-	if (word < 0) {
-	    if (pct(50))
-		printf("I don't understand the word %s?\n", txt[wdx]);
-	    else
-		printf("Mumble ?  %s\n", txt[wdx]);
-
-	    words[wdx+1] = 0;
-	    return (FALSE);
-	}
-	type = CLASS(word);
-	if (type == NOUN) {
-	    /* It's not the first:  Make sure he included a comma or
-	       'and'. Differenctiate between direct & indirect objects.
-	       Check for special case of multiple ofjects: 'feed bear
-	       honey' or 'throw troll nugget'. */
-	    if ((pflag ? iobx : objx)
-		&& CLASS(words[wdx - 1]) != CONJUNCTION) {
-		val = VAL(verbs[vrbx]);
-		if (!living(objs[objx]) || (val != THROW && val != FEED)) {
-		    rspeak(confuz());
-		    return (FALSE);
-		}
-		iobx++;
-		iobjs[iobx] = objs[objx];
-		objs[objx] = 0;
-		objx++;
-	    }
-	}
-    } while (word);
-
-    if (verbs[1] == 0) {
-	if (objs[1] == 0) {
-	    rspeak(confuz());
-	    clrlin();
-	} else if (objs[2])
-	    printf("What do you want to do with them?\n");
-	else
-	    printf("What do you want to do with %s?\n", otxt[1]);
-	return (FALSE);
-    } else if (objx > 1 && iobx > 1) {
-	rspeak(confuz());
-	return (FALSE);
-    }
-    return (TRUE);
-
-}
-
-/*
-  retrieve input line (max INPUTBUFLEN chars), convert to lower case
-   & rescan for first two words (max. WORDSIZE-1 chars).
-*/
-static void getwords()
-{
-    static int wdx = 0;
-    int i, term_loc;
-    char terminator;
-
-    if (*cindex == '\0') {
-	while (!*ask("\n> ", buffer, sizeof(buffer))) ;
-	for (cindex = buffer; *cindex; cindex++)
-	    if (isupper(*cindex))
-		*cindex = tolower(*cindex);
-	cindex = buffer;
-    }
-    wdx = 0;
-    buffer[sizeof(buffer)-1] = '\0';
-    for (i = 0; i < MAXWORDS; i++) {
-	txt[i] = &buffer[sizeof(buffer)-1];
-	words[i] = 0;
-    }
-    do {
-	while (*cindex == ' ')
-	    cindex++;
-	txt[wdx] = cindex;
-	term_loc = strcspn(cindex, " ,.;\n");
-	cindex += term_loc;
-	terminator = *cindex;
-	*cindex++ = '\0';
-	if ((strcmp(txt[wdx], "a") != 0)
-	    && (strcmp(txt[wdx], "the") != 0)
-	    && (strcmp(txt[wdx], "an") != 0)) {
-	    words[wdx] = vocab(txt[wdx], 0);
-	    wdx++;
-	}
-	if (terminator == ',') {
-	    txt[wdx] = "and";
-	    words[wdx] = vocab(txt[wdx], 0);
-	    wdx++;
-	}
-    }
-    while ((terminator != ';') && (terminator != '.')
-	   && (terminator != '\0') && (terminator != '\n'));
-    if (terminator == '\0')
-	cindex--;
-    return;
-}
-
-/* CLRIN, clears out all surrent syntax args in preparation for
- * new input line
- */
-
-static void clrlin()
-{
-    int i;
-
-    for (i = 0; i < MAXWORDS; i++) {
-	verbs[i] = 0;
-	vtxt[i] = &buffer[sizeof(buffer)-1];
-    }
-
-    for (i = 0; i < MAXITEMS; i++) {
-	objs[i] = 0;
-	otxt[i] = &buffer[sizeof(buffer)-1];
-	iobjs[i] = 0;
-	iotxt[i] = &buffer[sizeof(buffer)-1];
-    }
-    vrbx = 0;
-    objx = 0;
-    iobx = 0;
-    prep = 0;
-}
-
-/*
-  Routine to process an object.
-*/
-static void doobj(object)
-int *object;
-{
-    int msg;
-
-    if (holding(*object))
-	return;
-    if (blind()) {
-	printf("I see no %s here.\n", txt[wdx]);
-	*object = 0;
-	return;
-    }
-    /* Is object here?  if so, transitive */
-    if (g.fixed[*object] == g.loc || athand(*object))
-	return;
-    else if (here(*object)) {
-	msg = plural(*object) ? 373 : 335;
-	*object = 0;
-	rspeak(msg);
-    }
-    /* Did he give grate as destination? */
-    else if (*object == GRATE) {
-	if (g.loc == 1 || g.loc == 4 || g.loc == 7) {
-	    verbs[1] = DEPRESSION;
-	    vrbx = 1;
-	    return;
-	} else if (g.loc > 9 && g.loc < 15) {
-	    verbs[1] = ENTRANCE;
-	    vrbx = 1;
-	    return;
-	}
-    }
-    /* Is it a dwarf he is after? */
-    else if (dcheck() && g.dflag >= 2) {
-	*object = DWARF;
-    }
-    /* Is he trying to get/use a liquid? */
-    else if (liqloc(g.loc) == *object
-	     || (liq(BOTTLE) == *object && athand(BOTTLE))
-	     || (liq(CASK) == *object && athand(CASK)));
-    else if (*object == PLANT && at(PLANT2) &&
-	     g.prop[PLANT2] == 0) {
-	*object = PLANT2;
-    } else if (*object == ROCKS && at(CARVNG)) {
-	*object = CARVNG;
-    }
-    /* Is he trying to grab a knife? */
-    else if (*object == KNIFE && g.knfloc == g.loc) {
-	rspeak(116);
-	g.knfloc = -1;
-    }
-    /* Is he trying to get at dynamite? */
-    else if (*object == ROD && athand(ROD2)) {
-	*object = ROD2;
-    } else if (*object == DOOR && (at(SAFE) || at(TDOOR)
-				   || at(TDOOR2) || at(PDOOR))) {
-	if (at(TDOOR2))
-	    *object = TDOOR2;
-	else if (at(PDOOR))
-	    *object = PDOOR;
-	else if (at(SAFE))
-	    *object = SAFE;
-	else
-	    *object = TDOOR;
-    } else if (*object == BOOK && athand(BOOK2)) {
-	*object = BOOK2;
-    } else if (!(verbs[vrbx] == FIND || verbs[vrbx] == INVENTORY)) {
-	*object = 0;
-	printf("I see no %s here.\n", txt[wdx]);
-    }
-    return;
-}
-
-static boolean doiobj()
-{
-    char dk[INPUTBUFLEN], dkk[INPUTBUFLEN];
-    int kk;
-    boolean ok;
-
-    /* checks object is valid for this preposition */
-    ok = TRUE;
-    word = VAL(word);
-    if (word != ALL) {
-	doobj(&word);
-	if (word > 0) {
-	    iobjs[++iobx] = word;
-	    iotxt[iobx] = txt[wdx];
-	} else
-	    ok = FALSE;
-    }
-    kk = abs(ptab[vrbkey]) / 1000;
-    if (kk == prep) {
-	/* preprosition is valid with this verb now check object of
-	   preprosition */
-
-	if (word == 0 || CLASS(word) == CONJUNCTION) {
-	    /* no object following prepresition: check special cases */
-
-	    pflag = FALSE;
-	    strcpy(dk, txt[--wdx]);
-	    strcpy(dkk, vtxt[vrbx]);
-	    ok = FALSE;
-	    if ((strcmp(dk, "on") == 0
-		 || strcmp(dk, "off") == 0)
-		&& (strcmp(dkk, "turn") == 0
-		    || objs[objx] == LAMP))
-		ok = TRUE;
-	    if (strcmp(dkk, "take") == 0
-		|| strcmp(dkk, "put") == 0)
-		ok = TRUE;
-	    if (strcmp(dk, "up") == 0
-		&& strcmp(dkk, "pick") == 0)
-		ok = TRUE;
-	    if (strcmp(dk, "down") == 0
-		 && (strcmp(dkk, "put") == 0 || verbs[vrbx] == THROW) )
-		ok = TRUE;
-	} else {
-	    /* object follows preposition See if it's plausible. */
-
-	    kk = abs(ptab[vrbkey]) % 1000;
-	    if (kk == word && kk == ALL) {
-		if (!do_scoop_up())
-		    return (FALSE);
-	    } else if (!(kk == word || kk == 999)) {
-		vrbkey++;
-		ok = ptab[vrbkey - 1] < 0 ? FALSE : TRUE;
-	    }
-	}
-    }
-    return (ok);
-}
-
-static boolean do_scoop_up()
-{
-    int i, val;
-
-    val = VAL(verbs[vrbx]);
-    if (val == DROP || val == PUT || val == LEAVE) {
-	for (i = 1; i < MAXOBJ; i++) {
-	    if (!athand(i) || g.fixed[i])
-		continue;
-	    if (i > WATER && i <= WINE + 1)
-		continue;
-	    if (toting(i)) {
-		objs[++objx] = i;
-		otxt[objx] = "BUG???";
-		if (objx >= 44)
-		    break;
-	    }
-	}
-    }
-    if (val == TAKE || val == PICK || val == GET) {
-	if (blind()) {
-	    rspeak(357);
-	    return (FALSE);
-	} else {
-	    for (i = 1; i < MAXOBJ; i++) {
-		if (!athand(i) || g.fixed[i])
-		    continue;
-		if (i > WATER && i <= WINE + 1)
-		    continue;
-		if (!toting(i)) {
-		    objs[++objx] = i;
-		    otxt[objx] = "BUG???";
-		    if (objx >= 44)
-			break;
-		}
-	    }
-	}
-    }
-    return (TRUE);
-}
-
-static boolean check_next()
-{
-
-    word = words[wdx + 1];
-    if (word > 0)
-	return (TRUE);
-    else if (word == 0)
-	rspeak(confuz());
-    else {
-	if (pct(50))
-	    printf("I don't understand the word %s?\n", txt[wdx]);
-	else
-	    printf("Mumble ?  %s\n", txt[wdx]);
-	words[wdx+1] = 0;
-    }
-
-    return (FALSE);
-}
Index: trunk/minix/commands/advent/initial.c
===================================================================
--- trunk/minix/commands/advent/initial.c	(revision 9)
+++ 	(revision )
@@ -1,264 +1,0 @@
-/*
-  Initialization of adventure play variables
-*/
-#include	<string.h>
-#include	<stdio.h>
-#include	"advent.h"		/* #define preprocessor equates	 */
-#define EXTERN				/* define, not declare, in advdec.h */
-#include	"advdec.h"
-
-int plac[MAXOBJ] = {
-      0,   0,   3,   8,  10,  11,   0,  14,   0, 148,	/*   0 -   9 */
-     96,  19,  17, 101, 103,   0, 106,   0,   0, 238,	/*  10 -  19 */
-    238, 117, 190, 109,  25,  23, 111,  35,   0,  97,	/*  20 -  29 */
-      0, 119,   0, 117,   0, 130,   0, 126, 140,   0,	/*  30 -  39 */
-     96,  94, 158, 160, 188,   0, 155, 174, 166, 228,	/*  40 -  49 */
-     18, 204,  27,  29,  30,   0,  92, 168,  97, 100,	/*  50 -  59 */
-    101,   0, 119, 127, 130, 141, 144, 205,  28, 182,	/*  60 -  69 */
-    225, 230,   0, 147, 241, 248,   0,   0,   0,   0,	/*  70 -  79 */
-      0,   0,   0,   0,   0,   0,   0, 193, 102,   0,	/*  80 -  89 */
-    159, 141, 172, 188, 189,   0,   0, 193, 227, 174,	/*  90 -  99 */
-      0,  13, 238, 217, 171,   0, 146, 159,   3,   0,	/* 100 - 109 */
-      0,   0,   0,   3, 180,  39,   5,   0, 110, 169,	/* 110 - 119 */
-    200
-};
-
-int fixd[MAXOBJ] = {
-      0,   0,   0,   9,   0,   0,   0,  15,   0,   0,	/*   0 -   9 */
-      0,  -1,  27,  -1,   0,   0,   0,  -1,   0,   0,	/*  10 -  19 */
-      0, 122, 235,  -1,  -1,  67,  -1, 110,   0,  -1,	/*  20 -  29 */
-     -1, 121,   0, 122,   0,  -1,  -1,  -1,  -1,   0,	/*  30 -  39 */
-     -1,  -1, 166, 167, 189,   0,   0,  -1,   0, 229,	/*  40 -  49 */
-      0,   0,   0,   0,   0,   0,   0,   0,   0,   0,	/*  50 -  59 */
-      0,   0, 121,   0,  -1,   0,   0,   0,   0,   0,	/*  60 -  69 */
-      0,   0,   0,   0,   0,   0,   0,   0,   0,   0,	/*  70 -  79 */
-      0,   0,   0,   0,   0,   0,   0,  -1, 194,  -1,	/*  80 -  89 */
-      0,  -1, 174,  -1,  -1,   0,   0,  -1,  -1,  -1,	/*  90 -  99 */
-      0,   0,   0,  -1,  -1,  -1,   0,   0,   0,   0,	/* 100 - 109 */
-      0,   0,  -1,   0,   0,  -1,  -1,   0,   0,   0,	/* 110 - 119 */
-      0
-};
-
-struct playinfo g = {
-    0,							/* turns */
-    1,							/* loc */
-    1,							/* oldloc */
-    1,							/* oldloc2 */
-    1,							/* newloc */
-    {							/* loc_attrib[MAXLOC] */
-	  0,   73,   65,   73,   73,			/*   0 -   4 */
-	 65,   65,   73, 1601,   33,			/*   5 -   9 */
-	 32,   32,   32, 1824,   32,			/*  10 -  14 */
-	  0,    2,    0,    0, 2816,			/*  15 -  19 */
-	  2,    2,    2,    0,   10,			/*  20 -  24 */
-	  0,    2,    0,    0,    0,			/*  25 -  29 */
-	  0,    2,    2,    8,    0,			/*  30 -  34 */
-	  0,    0,    0,    8,    0,			/*  35 -  39 */
-	  2,    0,  256,  256,  256,			/*  40 -  44 */
-	256,  272,  272,  272,  256,			/*  45 -  49 */
-	256,    0,  256,  256,  272,			/*  50 -  54 */
-	256,  272,    0,   16,    2,			/*  55 -  59 */
-	  0,    0,    0,    0,    0,			/*  60 -  64 */
-	  0,    0,    0,    0,    0,			/*  65 -  69 */
-	  0,    0,    0,    0,    0,			/*  70 -  74 */
-	  0,    0,    0,    0,    2,			/*  75 -  79 */
-	256,  256,  272,    0,    0,			/*  80 -  84 */
-	 16,  272,    0,    0,    2,			/*  85 -  89 */
-	  2,    0,    0,    0,    0,			/*  90 -  94 */
-	  8,    0,    0, 1280,  513,			/*  95 -  99 */
-	513,  512,    0,    0,    0,			/*  00 -  04 */
-	  0,    0,    0,  768,    0,			/* 105 - 109 */
-	  0,    0,    0,    8,    0,			/* 110 - 114 */
-	  1,    1,    0,    0,    0,			/* 115 - 119 */
-	  0,    0,   16,   16,   16,			/* 120 - 124 */
-	 16,   17,   16,   16,   16,			/* 125 - 129 */
-	 16,    0,    0,    0,    0,			/* 130 - 134 */
-	  0,    0,    0,    0,    0,			/* 135 - 139 */
-	  0, 1040,   16,    0,    0,			/* 140 - 144 */
-	  2,   65,   65,   65,   65,			/* 145 - 149 */
-	 65,   65,   65,   65,   65,			/* 150 - 154 */
-	 65,    3, 2625, 2113,   65,			/* 155 - 159 */
-	 65,    3,    3,    3,    3,			/* 160 - 164 */
-	  3,   41,   41,    9,    9,			/* 165 - 169 */
-	  0,    0,    0,    0,    0,			/* 170 - 174 */
-	  0,    0,    0,    2,    0,			/* 175 - 179 */
-	  0,    2,    0,    0,    0,			/* 180 - 184 */
-	  0,    0,    0,    0,   16,			/* 185 - 189 */
-	  0,    0,    9,    0,    0,			/* 190 - 194 */
-	  0,    0,    0,    9,    2,			/* 195 - 199 */
-	  1,    1, 2304,    0,    0,			/* 200 - 204 */
-	  0,    8,    8,    8,    0,			/* 205 - 209 */
-	  0,    0,    1,    0,    9,			/* 210 - 214 */
-	  0,    0,   12,    0,    0,			/* 215 - 219 */
-	  0,    0,    0,    0,    0,			/* 220 - 224 */
-	  0,    2, 2625,   73,   73,			/* 225 - 229 */
-	  0,    2,    2,    2,    2,			/* 230 - 234 */
-	  0,    0,    2,   65, 3137,			/* 235 - 239 */
-	 65,   65,   65,   65,   65,			/* 240 - 244 */
-	 65,   65,   65,   65	  			/* 245 - 249 */
-    },							/* loc_attrib[MAXLOC] */
-    {0 },						/* place[MAXOBJ] */
-    {0 },						/* fixed[MAXOBJ] */
-    {							/* weight[MAXOBJ] */
-	0, 0, 1, 0, 1, 2, 2, 0, 0, 2,			/*   0 -   9 */
-	1, 0, 0, 0, 7, 7, 1, 0, 0, 2,			/*  10 -  19 */
-	1, 0, 0, 0, 0, 0, 0, 0, 3, 0,			/*  20 -  29 */
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 3,			/*  30 -  39 */
-	0, 0, 0, 0, 0, 0, 1, 1, 0, 0,			/*  40 -  49 */
-	6, 1, 2, 2, 3, 5, 4, 3, 2, 3,			/*  50 -  59 */
-	4, 1, 3, 1, 3, 2, 1, 1, 2, 2,			/*  60 -  69 */
-	2, 3, 1, 1, 3, 1, 0, 0, 0, 0,			/*  70 -  79 */
-	0, 2, 2, 2, 2, 2, 2, 0, 0, 0,			/*  70 -  79 */
-	1, 0, 0, 0, 0, 3, 2, 0, 0, 0,			/*  80 -  89 */
-	0, 2, 1, 0, 0, 0, 1, 1, 2, 0,			/* 100 - 109 */
-	3, 3, 0, 1, 1, 0, 0, 0, 3, 1,			/* 110 - 119 */
-	2, 0, 0						/* 120 - 129 */
-    },							/* weight[MAXOBJ] */
-    {0 },						/* atloc[MAXLOC] */
-    {0 },						/* link[MAXOBJ * 2] */
-    {0 },						/* holder[MAXOBJ] */
-    {0 },						/* hlink[MAXOBJ] */
-    {0 },						/* visited[MAXLOC] */
-    {0 },						/* prop[MAXOBJ] */
-    {							/* obj_state[MAXOBJ] */
-	    0,     0, 32800,    26, 32770,		/*   0 -   4 */
-	   32,    32,  8192,     0,     0,		/*   5 -   9 */
-	   32,   512,     0,   256,   770,		/*  10 -  14 */
-	  770,   288,   512,     0,   160,		/*  15 -  19 */
-	32802,     0,     0,     0,   128,		/*  20 -  24 */
-	    0,     0,     0,    32,  8192,		/*  25 -  29 */
-	  512,   512,     0,   512,     0,		/*  30 -  34 */
-	  512,   256,     0, 32768,  8224,		/*  35 -  39 */
-	    0,    18,    26,    26,     2,		/*  40 -  44 */
-	    0,  8320, 18464, 32768,     0,		/*  45 -  49 */
-	16384, 16416, 16416, 26656, 24608,		/*  50 -  54 */
-	49240, 24608, 16384, 49184, 16416,		/*  55 -  59 */
-	16416, 16416, 16384, 16544, 16442,		/*  60 -  64 */
-	16416, 18464, 26656, 16416, 16416,		/*  65 -  69 */
-	49184, 49154, 18464, 18464, 16416,		/*  70 -  74 */
-	16416,     0,     0,     0,     0,		/*  75 -  79 */
-	    0,     0,     0,     0,     0,		/*  80 -  84 */
-	    0,     0,  8704,     0,     0,		/*  85 -  89 */
-	    0,     0,     0,     0, 32768,		/*  90 -  94 */
-	    0,   128,     0,     0,     0,		/*  95 -  99 */
-	    0,   160,  8224,     0,     0,		/* 100 - 104 */
-	    0,  8352,  8352, 32870,     0,		/* 105 - 109 */
-	16674,   258, 32858,   288,    32,		/* 110 - 114 */
-	  256,     0,     0, 32866, 16416,		/* 115 - 119 */
-	16416,     0,     0				/* 120 - 123 */
-    },							/* obj_state[MAXOBJ] */
-    {							/* points[MAXOBJ] */
-	   0,        0,        0,        0,        0,	/*   0 -   4 */
-	   0,        0,        0,        0,        0,	/*   5 -   9 */
-	   0,        0,        0,        0,        0,	/*  10 -  14 */
-	   0,  1000108,        0,        0,        0,	/*  15 -  19 */
-	   0,        0,        0,        0,        0,	/*  20 -  24 */
-	   0,        0,        0,        0,        0,	/*  25 -  29 */
-	   0,        0,        0,        0,        0,	/*  30 -  34 */
-	   0,        0,        0,        0,        0,	/*  35 -  39 */
-	   0,        0,        0,        0,        0,	/*  40 -  44 */
-	   0,        0, -3000112,        0,        0,	/*  45 -  49 */
-    -2000055, -2000112, -2000112, -1000112, -5000112,	/*  50 -  54 */
-     5000003, -3000112, -2000055,  2000003, -3000112,	/*  55 -  59 */
-    -4000112, -4000112,  3000003, -1000112, -4000112,	/*  60 -  64 */
-    -4000112, -2000112, -3000112, -1000112, -1000112,	/*  65 -  69 */
-    -2000112, -3012055, -4000112, -1000112, -5000112,	/*  70 -  74 */
-    -5000112,        0,        0,        0,        0,	/*  75 -  79 */
-	   0,        0,        0,        0,        0,	/*  80 -  84 */
-	   0,        0,        0,        0,        0,	/*  85 -  89 */
-	   0,        0,        0,        0,        0,	/*  90 -  94 */
-	   0,        0,        0,        0,        0,	/*  95 -  99 */
-	   0,        0,        0,        0,        0,	/* 100 - 104 */
-	   0,        0,        0,        0,        0,	/* 105 - 109 */
-    -2000112,        0,        0,        0,        0,	/* 110 - 114 */
-	   0,        0,        0,        0, -4000118,	/* 115 - 119 */
-    -2000112,        0					/* 120 - 122 */
-    },							/* points[MAXOBJ] */
-    {0 },						/* hinted[HNTMAX+1] */
-    {							/* hints[HNTMAX+1][5] */
-	{    0,    0,   0,   0,   0 },			/*  0 */
-	{    0, 9999,   4,   0,   0 },			/*  1 */
-        {    0, 9999,  10,   0,   0 },			/*  2 */
-        {    0, 9999,   5,   0,   0 },			/*  3 */
-	{    0,    0,   0,   0,   0 },			/*  4 */
-	{    0,    0,   0,   0,   0 },			/*  5 */
-	{    0,    0,   0,   0,   0 },			/*  6 */
-        {    0,   15,   4, 176, 177 },			/*  7 */
-        {    0,    8,   5, 178, 179 },			/*  8 */
-        {    0,   13,   3, 180, 181 },			/*  9 */
-        {    0,    6,  10, 211, 212 },			/* 10 */
-        {    0,    6,   5, 213, 214 },			/* 11 */
-	{    0,    4,   2,  62,  63 },			/* 12 */
-	{    0,    5,   2,  18,  19 },			/* 13 */
-	{    0,    4,   2,  62, 233 },			/* 14 */
-	{    0,    6,   5, 274, 275 },			/* 15 */
-	{    0,   10,   5, 289, 290 },			/* 16 */
-	{    0,    8,   2,  20,  21 },			/* 17 */
-	{    0,    5,   2, 404, 405 }			/* 18 */
-    },							/* hints[HNTMAX+1][5] */
-    {0 },						/* hintlc[HNTMAX+1] */
-    0,							/* tally */
-    0,							/* tally2 */
-    0,							/* limit */
-    0,							/* lmwarn */
-    0,							/* wzdark */
-    0,							/* closing */
-    0,							/* closed */
-    0,							/* holding */
-    0,							/* detail */
-    0,							/* knfloc */
-    30,							/* clock */
-    50,							/* clock2 */
-    0,							/* panic */
-    { 0, 19, 27, 33, 44, 64, 114 },			/* dloc[DWARFMAX+1] */
-    0,							/* dflag */
-    { 0, 0, 0, 0, 0, 0, 0 },				/* dseen[DWARFMAX+1] */
-    { 0, 0, 0, 0, 0, 0, 0 },				/* odloc[DWARFMAX+1] */
-    18,							/* daltloc */
-    0,							/* dkill */
-    114,						/* chloc */
-    140,						/* chloc2 */
-    0,							/* bonus */
-    0,							/* numdie */
-    0,							/* foobar */
-    0,							/* combo */
-    0,							/* terse */
-    5,							/* abbnum */
-    100,						/* health */
-    0,							/* chase */
-    FALSE,						/* flg239 */
-    0							/* lastglob */
-};
-
-/*
-  Initialization of adventure play variables
-*/
-void initialize()
-{
-    int i;
-
-    for (i = MAXOBJ; i > 0; i--) {
-	g.fixed[i] = fixd[i];
-	if (fixd[i] > 0) {
-	    drop(i + MAXOBJ, fixd[i]);
-	    drop(i, plac[i]);
-	}
-	if ((plac[i] != 0) && (fixd[i] <= 0))
-	    drop(i, plac[i]);
-    }
-
-    for (i = 1; i <= MAXOBJ; i++) {
-	if (treasr(i)) {
-	    g.prop[i] = -1;
-	    g.tally++;
-	}
-    }
-
-    newtravel = TRUE;
-    g.place[BOOK] = -1;
-    insert(BOOK, SAFE);
-    g.place[WATER] = -1;
-    insert(WATER, BOTTLE);
-    g.prop[BOTTLE] = 8;
-    return;
-}
Index: trunk/minix/commands/advent/itverb.c
===================================================================
--- trunk/minix/commands/advent/itverb.c	(revision 9)
+++ 	(revision )
@@ -1,597 +1,0 @@
-/*	program ITVERB.C					*/
-
-
-#include	<stdio.h>
-#include	"advent.h"
-#include	"advdec.h"
-
-_PROTOTYPE(void needobj, (void));
-_PROTOTYPE(void ivtake, (void));
-_PROTOTYPE(void ivopen, (void));
-_PROTOTYPE(void ivkill, (void));
-_PROTOTYPE(void ivdrink, (void));
-_PROTOTYPE(void ivquit, (void));
-_PROTOTYPE(void ivfoo, (void));
-_PROTOTYPE(void inventory, (void));
-_PROTOTYPE(void addobj, (int obj));
-_PROTOTYPE(void ivpour, (void));
-_PROTOTYPE(void ivfill, (void));
-_PROTOTYPE(void ivbrief, (void));
-_PROTOTYPE(void ivread, (void));
-_PROTOTYPE(void ivcombo, (void));
-_PROTOTYPE(void iveat, (void));
-/*
-  Routines to process intransitive verbs
-*/
-void itverb()
-{
-    int i;
-
-    newtravel = FALSE;
-    switch (verb) {
-    case DROP:
-    case SAY:
-    case WAVE:
-    case CALM:
-    case RUB:
-    case THROW:
-    case FIND:
-    case FEED:
-    case BREAK:
-    case WAKE:
-    case WEAR:
-    case HIT:
-    case DIAL:
-    case PLAY:
-    case PICK:
-    case PUT:
-    case TURN:		needobj();	break;
-    case TAKE:
-    case YANK:
-    case GET:
-    case INSRT:
-    case REMOVE:
-    case BURN:		ivtake();	break;
-    case OPEN:
-    case CLOSE:
-    case LOCK:
-    case UNLOCK:	ivopen();	break;
-    case NOTHING:	rspeak(54);	break;
-    case ON:
-    case OFF:		trverb();	break;
-    case WALK:		actspk(verb);	break;
-    case KILL:		ivkill();	break;
-    case POUR:		ivpour();	break;
-    case EAT:		iveat();	break;
-    case DRINK:		ivdrink();	break;
-    case QUIT:		ivquit();	break;
-    case INVENTORY:	inventory();	break;
-    case FILL:		ivfill();	break;
-    case BLAST:		ivblast();	break;
-    case SCORE:		score(TRUE);	break;
-    case FOO:		ivfoo();	break;
-    case BRIEF:		ivbrief();	break;
-    case READ:		ivread();	break;
-    case SUSPEND:
-	if (g.closing)
-	    rspeak(378);
-	else
-	    saveadv("advent.sav");
-	break;
-    case RESTORE:	restore("advent.sav");	break;
-    case ANSWER:
-	if ((g.loc != 189) || (g.prop[PHONE] != 0))
-	    needobj();
-	else {
-	    object = PHONE;
-	    itverb();
-	}
-	break;
-    case BLOW:		rspeak(268);	break;
-	/* Action verb 'LEAVE' has no object */
-    case LEAVE:		bug(29);	break;
-	/* Call if no phone is handy, yell. */
-    case YELL:
-	if (!here(PHONE))
-	    needobj();
-	else if (!g.closed)
-	    rspeak(271);
-	else {
-	    rspeak(283);
-	    normend();
-	}
-	break;
-	/* Health. give him a diagnosis. */
-    case HEALTH:
-	if (g.numdie)
-	    fprintf(stdout, "You have been killed %d times otherwise\n",
-		    g.numdie);
-	if (g.health >= 95) {
-	    if (pct(50))
-		rspeak(348);
-	    else
-		rspeak(349);
-	} else {
-	    fprintf(stdout,
-	       "Your health rating is %2d out of a possible 100.\n",
-		    g.health);
-	    rspeak(381 + (100 - g.health) / 20);
-	}
-	break;
-    case LOOK:		ivlook();	break;
-    case COMBO:
-	if (at(SAFE))
-	    ivcombo();
-	break;
-    case SWEEP:
-	/* Dust/sweep */
-	if (!at(CARVNG) || !athand(BRUSH) || (g.prop[CARVNG] == 1))
-	    rspeak(342);
-	else {
-	    g.prop[CARVNG] = 1;
-	    rspeak(363);
-	    rspeak(372);
-	}
-	break;
-    case TERSE:
-	/* Terse/unterse. supress all long_form descriptions. */
-	g.terse = !g.terse;
-	g.detail = 3;
-	rspeak(54);
-	break;
-    case WIZ:
-	is_wiz = !is_wiz;
-    case MAP:
-	rspeak(54);
-	break;
-    case GATE:
-	if (is_wiz) {
-	    static char buf[INPUTBUFLEN];
-	    sscanf(ask("Location ? ", buf, sizeof(buf)), "%d", &g.loc);
-	}
-	rspeak(54);
-	break;
-    case PIRLOC:
-	if (is_wiz) {
-	    fprintf(stdout, "The dwarfs are at locations:\n");
-	    for (i = 1; i < DWARFMAX; i++)
-		fprintf(stdout, "  %4d", g.dloc[i]);
-	    fprintf(stdout, "\nThe pirate is at location %4d\n",
-		    g.dloc[DWARFMAX]);
-	}
-	rspeak(54);
-	break;
-    default:
-	printf("This intransitive not implemented yet\n");
-    }
-    return;
-}
-
-/*
-  Routine to indicate no reasonable
-  object for verb found.  Used mostly by
-  intransitive verbs.
-*/
-void needobj()
-{
-    printf("%s what?\n", vtxt[vrbx]);
-    return;
-}
-
-/*
-  CARRY, TAKE etc.
-*/
-void ivtake()
-{
-    int anobj, item;
-
-    anobj = 0;
-    for (item = 1; item < MAXOBJ; ++item)
-	if (g.place[item] == g.loc)
-	    if (anobj == 0)
-		anobj = item;
-	    else {
-		needobj();
-		return;
-	    }
-
-    if (anobj == 0 || (dcheck() && g.dflag >= 2) || blind())
-	needobj();
-    else {
-	object = anobj;
-	if (verb == YANK)
-	    vyank();
-	else if (verb == WEAR)
-	    vwear();
-	else
-	    vtake();
-    }
-    return;
-}
-
-/*
-  OPEN, LOCK, UNLOCK
-*/
-void ivopen()
-{
-    int obj_cnt, item;
-
-    for (item = 1, obj_cnt = 0; item < MAXOBJ; item++) {
-	if ((g.place[item] == g.loc) && (hinged(item))) {
-	    object = item;
-	    obj_cnt++;
-	}
-    }
-    if (obj_cnt != 1)
-	needobj();
-    else if (verb == LOCK)
-	vlock();
-    else if (verb == UNLOCK)
-	vunlock();
-    else if (verb == SHUT)
-	vclose();
-    else
-	vopen();
-}
-
-/*
-  ATTACK, KILL etc
-*/
-boolean previous_obj;
-
-void ivkill()
-{
-    previous_obj = FALSE;
-    if (dcheck() && g.dflag >= 2)
-	object = DWARF;
-    if (here(SNAKE))
-	addobj(SNAKE);
-    if (at(DRAGON) && g.prop[DRAGON] == 0)
-	addobj(DRAGON);
-    if (at(TROLL))
-	addobj(TROLL);
-    if (here(GNOME))
-	addobj(GNOME);
-    if (here(BEAR) && g.prop[BEAR] == 0)
-	addobj(BEAR);
-    if (here(WUMPUS) && g.prop[WUMPUS] == 0)
-	addobj(WUMPUS);
-    /* Can't attack bird by throwing axe */
-    if (here(BIRD) && verb != THROW)
-	addobj(BIRD);
-    /* Clam and oyster both treated as clam for intransitive case; no
-       harm done. */
-    if (here(CLAM) || here(OYSTER))
-	addobj(CLAM);
-
-    if ((previous_obj) || (object == 0))
-	rspeak(44);
-    else
-	vkill();
-    return;
-}
-
-/*
-  POUR if no object, assume liq in container, if holding one.
-*/
-void ivpour()
-{
-    if ((holding(BOTTLE)) && (liq(BOTTLE) != 0) && !holding(CASK))
-	object = BOTTLE;
-    if ((holding(CASK)) && (liq(CASK) != 0) && !holding(BOTTLE))
-	object = CASK;
-
-    if (object == 0)
-	needobj();
-    else
-	trverb();
-}
-
-/*
-  EAT. intransitive: assume edible if present, else ask what.
-  If he as more than one edible, or none, 'EAT' is ambiguous
-  without an explicit object.
-*/
-void iveat()
-{
-    int i;
-
-    previous_obj = FALSE;
-    for (i = 1; i < MAXOBJ; i++) {
-	if ((here(i)) && (edible(i)))
-	    addobj(i);
-    }
-    if ((previous_obj) || (object == 0))
-	needobj();
-    else
-	trverb();
-}
-
-/*
-  DRINK.  If no object, assume water or wine and look for them here.
-  If potable is in bottle or cask, drink that.  If not, see if there
-  is something drinkable nearby (stream, lake, wine fountain, etc.),
-  and drink that.  If he has stuff in both containers, ask which.
-*/
-void ivdrink()
-{
-    int ll;
-
-    previous_obj = FALSE;
-    ll = liqloc(g.loc);
-    if ((ll == WATER) || (ll == WINE)) {
-	object = ll;
-	iobj = -1;
-    }
-    ll = liq(BOTTLE);
-    if ((athand(BOTTLE)) && ((ll == WATER) || (ll == WINE))) {
-	object = ll;
-	iobj = BOTTLE;
-    }
-    ll = liq(CASK);
-    if ((athand(CASK)) && ((ll == WATER) || (ll == WINE))
-	&& iobj != BOTTLE) {
-	object = ll;
-	iobj = CASK;
-    } else
-	object = 0;
-
-    if (object == 0)
-	needobj();
-    else
-	trverb();
-}
-
-/*
-  QUIT intransitive only. Verify intent and exit if that's what he wants
-*/
-void ivquit()
-{
-    gaveup = yes(22, 54, 54);
-    if (gaveup)
-	normend();
-    return;
-}
-
-/*
-  INVENTORY
-*/
-void inventory()
-{
-    int i, msg;
-    boolean init_msg;
-
-    init_msg = TRUE;
-    msg = 98;
-    for (i = 1; i < MAXOBJ; i++) {
-	if (!holding(i) || wearng(i) || i == BEAR || i == BOAT)
-	    continue;
-	if (init_msg)
-	    rspeak(99);
-	pspeak(i, -1);
-	init_msg = FALSE;
-	msg = 0;
-	lookin(i);
-    }
-
-    /* Tell him what he is wearing */
-    init_msg = TRUE;
-    for (i = 1; i < MAXOBJ; i++) {
-	if (wearng(i)) {
-	    if (init_msg)
-		fprintf(stdout, "\nYou are wearing:\n");
-	    fprintf(stdout, "     ");
-	    pspeak(i, -1);
-	    msg = 0;
-	    init_msg = FALSE;
-	}
-    }
-
-    if (holding(BOAT)) {
-	rspeak(221);
-	lookin(BOAT);
-    }
-    if (holding(BEAR))
-	msg = 141;
-
-    if (msg)
-	rspeak(msg);
-    return;
-}
-
-/*
-  FILL bottle or cask must be empty, and some liquid avaible
-*/
-void ivfill()
-{
-    if ((g.prop[CASK] == 1) && !here(CASK))
-	object = CASK;
-    if ((g.prop[BOTTLE] == 1) && !here(BOTTLE))
-	object = BOTTLE;
-
-    if ((here(BOTTLE) && here(CASK)) || (object == 0))
-	needobj();
-    else
-	trverb();
-}
-
-/*
-  BLAST etc.
-*/
-void ivblast()
-{
-    if (!g.closed)
-	actspk(verb);
-    else {
-	g.bonus = 135;
-	if (g.place[ROD2] == 212 && g.loc == 116)
-	    g.bonus = 133;
-	if (g.place[ROD2] == 116 && g.loc != 116)
-	    g.bonus = 134;
-	rspeak(g.bonus);
-	normend();
-    }
-    return;
-}
-
-/*
-  Handle fee fie foe foo...
-*/
-void ivfoo()
-{
-    int k;
-    int msg;
-
-    k = VAL(vocab(vtxt[vrbx], MISC));
-    if (g.foobar != 1 - k) {
-	if (g.foobar == 0)
-	    msg = 42;
-	else
-	    msg = 151;
-	rspeak(msg);
-	return;
-    }
-    g.foobar = k;
-    if (k != 4)
-	return;
-    g.foobar = 0;
-    if (g.place[EGGS] == plac[EGGS] ||
-	(toting(EGGS) && g.loc == plac[EGGS])) {
-	rspeak(42);
-	return;
-    }
-    /* Bring back troll if we steal the eggs back from him before
-       crossing */
-    if (g.place[EGGS] == 0 && g.place[TROLL] == 0 && g.prop[TROLL] == 0)
-	g.prop[TROLL] = 1;
-
-    if (here(EGGS))
-	k = 1;
-    else if (g.loc == plac[EGGS])
-	k = 0;
-    else
-	k = 2;
-    move(EGGS, plac[EGGS]);
-    pspeak(EGGS, k);
-    return;
-}
-
-/*
-  brief/unbrief. intransitive only.
-  suppress long descriptions after first time.
-*/
-void ivbrief()
-{
-    int msg;
-
-    g.detail = 3;
-    g.terse = FALSE;
-    if (g.abbnum != 10000) {
-	msg = 156;
-	g.abbnum = 10000;
-    } else {
-	msg = 374;
-	g.abbnum = 5;
-    }
-    rspeak(msg);
-}
-
-/*
-  read etc...
-*/
-void ivread()
-{
-    previous_obj = FALSE;
-    if (here(BOOK))
-	object = BOOK;
-    if (here(BOOK2))
-	addobj(BOOK2);
-    if (here(BILLBD))
-	addobj(BILLBD);
-    if (here(CARVNG))
-	addobj(CARVNG);
-    if (here(MAGAZINE))
-	addobj(MAGAZINE);
-    if (here(MESSAGE))
-	addobj(MESSAGE);
-    if (here(OYSTER))
-	addobj(OYSTER);
-    if (here(POSTER))
-	addobj(POSTER);
-    if (here(TABLET))
-	addobj(TABLET);
-
-    if (previous_obj || object == 0 || dark())
-	needobj();
-    else
-	vread();
-    return;
-}
-
-/*
-   LOOK. can't give more detail. Pretend it wasn't dark (though it may "now"
-   be dark) so he won't fall into a pit staring into the gloom.
-*/
-void ivlook()
-{
-    if (g.detail++ < 3)
-	rspeak(15);
-    g.wzdark = FALSE;
-    g.visited[g.loc] = 0;
-    g.newloc = g.loc;
-    newtravel = TRUE;
-    return;
-}
-
-/*
-  COMBO: trying to open safe. (see comments for fee fie foe foo)
-*/
-void ivcombo()
-{
-    int k, msg;
-
-    k = VAL(vocab(vtxt[vrbx], MISC)) - 10;
-    msg = 42;
-    if (g.combo != 1 - k) {
-	if (g.combo != 0)
-	    msg = 366;
-	rspeak(msg);
-	return;
-    }
-    g.combo = k;
-    if (k != 3)
-	rspeak(371);
-    else {
-	g.combo = 0;
-	bitoff(SAFE, LOCKBT);
-	biton(SAFE, OPENBT);
-	g.prop[SAFE] = 1;
-	if (g.prop[BOOK] < 0) {
-	    g.tally--;
-	    g.prop[BOOK] = 0;
-	    /* If remaining treasures too elusive, zap his lamp. this
-	       duplicates some code, must be done here since book is
-	       contained ins safe & tally stuff only works for thing
-	       deposited at a location. */
-	    if ((g.tally == g.tally2) && (g.tally != 0))
-		g.limit = (g.limit < 35) ? g.limit : 35;
-	}
-	rspeak(365);
-    }
-}
-
-/*
-  ensure uniqueness as objects are searched
-  out for an intransitive verb
-*/
-void addobj(obj)
-int obj;
-{
-    if (!previous_obj) {
-	if (object != 0)
-	    previous_obj = TRUE;
-	else
-	    object = obj;
-    }
-    return;
-}
Index: trunk/minix/commands/advent/score.c
===================================================================
--- trunk/minix/commands/advent/score.c	(revision 9)
+++ 	(revision )
@@ -1,199 +1,0 @@
-/**
-    SCORE
-
-   Calculate what the player's score would be if he quit now.
-   This may be the end of the game, or he may just be wondering
-   how he is doing.
-
-   The present scoring algorithm is as follows:
-   (treasure points are explained in a following comment)
-      objective:          points:        present total possible:
-   getting well into cave   25                    25
-   total possible for treasures (+mag)           426
-   reaching "closing"       20                    20
-   "closed": quit/killed    10
-             klutzed        20
-             wrong way      25
-             success        30                    30
-				total:   501
-   (points can also be deducted for using hints or deaths.)
-
-*/
-
-#include 	<stdio.h>
-#include	"advent.h"
-#include	"advdec.h"
-
-void score(scorng)
-boolean scorng;
-{
-    int cur_score, max_score, qk[3];
-    int obj, num_treas, k, i;
-    long t;
-    char *kk2c;
-
-    cur_score = 0;
-    max_score = 0;
-    num_treas = 0;
-
-/** First tally up the treasures.  Must be in building and not broken.
-   give the poor guy partial score just for finding each treasure.
-   Gets full score, qk[3], for obj if:
-        obj is at loc qk[1], and
-        obj has prop value of qk[2]
-
-                weight          total possible
-   magazine     1 (absolute)            1
-
-   all the following are multiplied by 5 (range 5-25):
-   book         2
-   cask         3 (with wine only)
-   chain        4 (must enter via styx)
-   chest        5
-   cloak        3
-   clover       1
-   coins        5
-   crown        2
-   crystal-ball 2
-   diamonds     2
-   eggs         3
-   emerald      3
-   grail        2
-   horn         2
-   jewels       1
-   lyre         1
-   nugget       2
-   pearl        4
-   pyramid      4
-   radium	4
-   ring         4
-   rug          3
-   sapphire     1
-   shoes        3
-   spices       1
-   sword        4
-   trident      2
-   vase         2
-   droplet	5
-   tree		5
-        total: 85 * 5 = 425 + 1 ==> 426
-*/
-
-    for (obj = 1; obj < MAXOBJ; obj++) {
-	if (g.points[obj] == 0)
-	    continue;
-	t = g.points[obj];
- 	qk[0] = (int) (t < 0L ? -((t = -t) % 1000) : (t % 1000));
- 	t /= 1000;
-	qk[1] = (int) (t % 1000);
-	qk[2] = (int) (t / 1000);
-	k = 0;
-	if (treasr(obj)) {
-	    num_treas++;
-	    k = qk[2] * 2;
-	    if (g.prop[obj] >= 0)
-		cur_score += k;
-	    qk[2] *= 5;
-	}
-	if ((g.place[obj] == qk[0]) && (g.prop[obj] == qk[1])
-	    && ((g.place[obj] != -CHEST) || (g.place[CHEST] == 3))
-	  && ((g.place[obj] != -SHIELD) || (g.place[SHIELD] == -SAFE))
-	    )
-	    cur_score += qk[2] - k;
-	max_score += qk[2];
-    }
-
-
-/**
-   Now look at how he finished and how far he got.  Maxdie and numdie tell us
-   how well he survived.  Gaveup says whether he exited via quit.  Dflag will
-   tell us if he ever got suitably deep into the cave.  Closing still indicates
-   whether he reached the endgame.  And if he got as far as "cave closed"
-   (indicated by "closed"), then bonus is zero for mundane exits or 133, 134,
-   135 if he blew it (so to speak).
-*/
-
-    if (g.dflag)
-	cur_score += 25;
-    max_score += 25;
-    if (g.closing)
-	cur_score += 20;
-    max_score += 20;
-    if (g.closed) {
-	if (g.bonus == 0)
-	    cur_score += 10;
-	else if (g.bonus == 135)
-	    cur_score += 20;
-	else if (g.bonus == 134)
-	    cur_score += 25;
-	else if (g.bonus == 133)
-	    cur_score += 30;
-    }
-    max_score += 30;
-
-/*  Deduct points for hints, deaths and quiting.
-    hints < hntmin are special; see database description
-*/
-    for (i = 1; i <= HNTMAX; i++)
-	if (g.hinted[i])
-	    cur_score -= g.hints[i][2];
-    cur_score -= g.numdie * 10;
-    if (gaveup)
-	cur_score -= 4;
-
-    fprintf(stdout, "You have found   %3d out of %3d Treasures,",
-	    num_treas - g.tally, num_treas);
-    fprintf(stdout, " using %4d turns\n", g.turns);
-    fprintf(stdout, "For a score of: %4d", cur_score);
-    fprintf(stdout, " out of a possible %4d\n", max_score);
-
-    if (cur_score < 110) {
-	fprintf(stdout, "You are obviously a rank amateur.");
-	if (!scorng)
-	    fprintf(stdout, "  Better luck next time.");
-	fputc('\n', stdout);
-	k = 110 - cur_score;
-    } else if (cur_score < 152) {
-	fprintf(stdout,
-	  "Your score qualifies you as a Novice Class Adventurer.\n");
-	k = 152 - cur_score;
-    } else if (cur_score < 200) {
-	fprintf(stdout,
-	"You have achieved the rating: \"Experienced Adventurer\".\n");
-	k = 200 - cur_score;
-    } else if (cur_score < 277) {
-	fprintf(stdout,
-	"You may now consider yourself a \"Seasoned Adventurer\".\n");
-	k = 277 - cur_score;
-    } else if (cur_score < 345) {
-	fprintf(stdout,
-		"You have reached \"Junior Master\" status.\n");
-	k = 345 - cur_score;
-    } else if (cur_score < 451) {
-	fprintf(stdout,
-		"Your score puts you in Master Adventurer Class C.\n");
-	k = 451 - cur_score;
-    } else if (cur_score < 471) {
-	fprintf(stdout,
-		"Your score puts you in Master Adventurer Class B.\n");
-	k = 471 - cur_score;
-    } else if (cur_score < 501) {
-	fprintf(stdout,
-		"Your score puts you in Master Adventurer Class A.\n");
-	k = 501 - cur_score;
-    } else {
-	fprintf(stdout,
-		"All of Adventuredom gives tribute to you, Adventurer Grandmaster!\n");
-	k = 0;
-    }
-
-    if (!scorng) {
-	kk2c = (k == 1) ? "." : "s.";
-	printf("\nTo acheive the next higher rating,");
-	if (cur_score == 501)
-	    printf(" would be a neat trick!\n\n  CONGRATULATIONS!!\n");
-	else
-	    printf(" you need %3d more point%s\n", k, kk2c);
-    }
-    return;
-}
Index: trunk/minix/commands/advent/setup.c
===================================================================
--- trunk/minix/commands/advent/setup.c	(revision 9)
+++ 	(revision )
@@ -1,99 +1,0 @@
-/**	program SETUP.C  					*
- *	execution will read the four adventure text files	*
- *	files; "advent1.txt", "advent2.txt", "advent3.txt" &	*
- *	"advent4.txt".  it will create the file "advtext.h"	*
- *	which is an Index Sequential Access Method (ISAM)	*
- *	header to be #included into "advent.c" before the	*
- *	header "advdec.h" is #included.				*/
-
-
-#include	<stdio.h>
-#include	<stdlib.h>
-#include	"advent.h"
-
-_PROTOTYPE(int main, (void));
-_PROTOTYPE(void file_error, (char *));
-_PROTOTYPE(void encode, (unsigned char *));
-
-int main()
-{
-
-    FILE *isam, *src, *dest;
-    char itxt[255];
-    int cnt, i;
-    long llen;
-    char filename[12];
-    static char *headername[] = {
-       "idx1[MAXLOC]", "idx2[MAXLOC]", "idx3[MAXOBJ]", "idx4[MAXMSG]",
-    };
-
-    long x29 = (1L << 29), x30 = (1L << 30);
-    if (!(x30 / 2 == x29 && 0L < x30 && x29 < x30)) {
-	fprintf(stderr, "Sorry, advent needs 32-bit `long int's.\n");
-	exit(EXIT_FAILURE);
-    }
-    isam = fopen("advtext.h", "w");
-    if (!isam) {
-	fprintf(stderr, "Sorry, I can't open advtext.h...\n");
-	exit(EXIT_FAILURE);
-    }
-    fprintf(isam, "\n/*\theader: ADVTEXT.H\t\t\t\t\t*/\n\n\n");
-
-    for (i = 1; i <= 4; i++) {
-	cnt = -1;
-	llen = 0L;
-	sprintf(filename, "advent%d.txt", i);
-	src = fopen(filename, "r");
-	if (!src)
-	    file_error(filename);
-	sprintf(filename, "advent%d.dat", i);
-	dest = fopen(filename, "w");
-	if (!dest)
-	    file_error(filename);
-	fprintf(isam, "long\t%s = {\n\t", headername[i - 1]);
-	while (fgets(itxt, 255, src)) {
-	    encode((unsigned char *) itxt);
-	    if (fprintf(dest, "%s\n", itxt) == EOF)
-		file_error(filename);
-	    if (itxt[0] == '#') {
-		if (llen)
-		    fprintf(isam, "%ld,%s\t", llen,
-			    &"\0\0\0\0\0\0\0\n"[++cnt & 7]);
-		llen = ftell(dest);
-		if (llen <= 0) {
-		    fprintf(stderr, "ftell err in %s\n", filename);
-		    exit(EXIT_FAILURE);
-		}			/* if (!llen)	 */
-	    }				/* if (itxt[0])	 */
-	}				/* while fgets	 */
-	if (fprintf(isam, "%ld\n\t};\n\n", llen) == EOF)
-	    file_error("advtext.h");
-	fclose(src);
-	if (fclose(dest) == EOF)
-	    file_error(filename);
-    }
-
-    if (fclose(isam) == EOF)
-	file_error("advtext.h");
-    return EXIT_SUCCESS;
-}					/* main		 */
-
-void file_error(filename)
-char *filename;
-{
-    perror(filename);
-    exit(EXIT_FAILURE);
-}
-
-_CONST unsigned char key[4] = {'c' | 0x80, 'L' | 0x80, 'y' | 0x80, 'D' | 0x80};
-
-void encode(msg)
-unsigned char *msg;
-{
-    register int i;
-
-    for (i = 1; msg[i]; i++)
-	msg[i] ^= key[i & 3];
-    msg[--i] = '\0';
-    return;
-}
Index: trunk/minix/commands/advent/travel.c
===================================================================
--- trunk/minix/commands/advent/travel.c	(revision 9)
+++ 	(revision )
@@ -1,336 +1,0 @@
-/*	module TRAVEL.C						*
- *      Routine to handle motion requests			*/
-
-
-#include	<stdio.h>
-#include	<stdlib.h>
-#include	"advent.h"
-#include	"advdec.h"
-#include	"advcave.h"
-
-struct trav travel[MAXTRAV];
-static int kalflg;
-static int bcrossing = 0;
-static int phuce[2][4] = {158, 160, 167, 166,
-			  160, 158, 166, 167};
-
-_PROTOTYPE(static void goback, (void));
-_PROTOTYPE(static void ck_kal, (void));
-_PROTOTYPE(static void dotrav, (void));
-_PROTOTYPE(static void badmove, (void));
-_PROTOTYPE(static void spcmove, (int rdest));
-
-void domove()
-{
-    gettrav(g.loc, travel);
-    switch (motion) {
-    case NULLX:
-	break;
-    case BACK:
-	goback();
-	break;
-    case CAVE:
-	if (outside(g.loc))
-	    rspeak(57);
-	else
-	    rspeak(58);
-	break;
-    default:
-	g.oldloc2 = g.oldloc;
-	g.oldloc = g.loc;
-	dotrav();
-    }
-    newtravel = TRUE;
-    return;
-}
-
-/*
-  Routine to handle request to return
-  from whence we came!
-*/
-static void goback()
-{
-    int kk, k2, want, temp;
-    struct trav strav[MAXTRAV];
-
-    want = forced(g.oldloc) ? g.oldloc2 : g.oldloc;
-    g.oldloc2 = g.oldloc;
-    g.oldloc = g.loc;
-    k2 = 0;
-    if (want == g.loc) {
-	rspeak(91);
-	ck_kal();
-	return;
-    }
-    for (kk = 0; travel[kk].tdest != -1; ++kk) {
-	if (!travel[kk].tcond && travel[kk].tdest == want) {
-	    motion = travel[kk].tverb;
-	    dotrav();
-	    return;
-	}
-	if (!travel[kk].tcond) {
-	    temp = travel[kk].tdest;
-	    gettrav(temp, strav);
-	    if (forced(temp) && strav[0].tdest == want)
-		k2 = temp;
-	}
-    }
-    if (k2) {
-	motion = travel[k2].tverb;
-	dotrav();
-    } else
-	rspeak(140);
-    ck_kal();
-    return;
-}
-
-static void ck_kal()
-{
-    if (g.newloc >= 242 && g.newloc <= 247) {
-	if (g.newloc == 242)
-	    kalflg = 0;
-	else if (g.newloc == (g.oldloc + 1))
-	    kalflg++;
-	else
-	    kalflg = -10;
-    }
-}
-
-/*
-  Routine to figure out a new location
-  given current location and a motion.
-*/
-static void dotrav()
-{
-    unsigned char mvflag, hitflag, kk;
-    int rdest, rverb, rcond, robject;
-    int pctt;
-
-    g.newloc = g.loc;
-    mvflag = hitflag = 0;
-    pctt = ranz(100);
-
-    for (kk = 0; travel[kk].tdest >= 0 && !mvflag; ++kk) {
-	rdest = travel[kk].tdest;
-	rverb = travel[kk].tverb;
-	rcond = travel[kk].tcond;
-	robject = rcond % 100;
-
-	if ((rverb != 1) && (rverb != motion) && !hitflag)
-	    continue;
-	++hitflag;
-	switch (rcond / 100) {
-	case 0:
-	    if ((rcond == 0) || (pctt < rcond))
-		++mvflag;
-	    break;
-	case 1:
-	    if (robject == 0)
-		++mvflag;
-	    else if (toting(robject))
-		++mvflag;
-	    break;
-	case 2:
-	    if (toting(robject) || at(robject))
-		++mvflag;
-	    break;
-	case 3:
-	case 4:
-	case 5:
-	case 7:
-	    if (g.prop[robject] != (rcond / 100) - 3)
-		++mvflag;
-	    break;
-	default:
-	    bug(37);
-	}
-    }
-    if (!mvflag)
-	badmove();
-    else if (rdest > 500)
-	rspeak(rdest - 500);
-    else if (rdest > 300)
-	spcmove(rdest);
-    else {
-	g.newloc = rdest;
-	ck_kal();
-    }
-    newtravel = TRUE;
-    return;
-}
-
-/*
-  The player tried a poor move option.
-*/
-static void badmove()
-{
-    int msg;
-
-    msg = 12;
-    if (motion >= 43 && motion <= 50)
-	msg = 9;
-    if (motion == 29 || motion == 30)
-	msg = 9;
-    if (motion == 7 || motion == 36 || motion == 37)
-	msg = 10;
-    if (motion == 11 || motion == 19)
-	msg = 11;
-    if (motion == 62 || motion == 65 || motion == 82)
-	msg = 42;
-    if (motion == 17)
-	msg = 80;
-    rspeak(msg);
-    return;
-}
-
-/*
-  Routine to handle very special movement.
-*/
-static void spcmove(rdest)
-int rdest;
-{
-    int load, obj, k;
-
-    switch (rdest - 300) {
-    case 1:				/* plover movement via alcove */
-	load = burden(0);
-	if (!load || (load == burden(EMERALD) && holding(EMERALD)))
-	    g.newloc = (99 + 100) - g.loc;
-	else
-	    rspeak(117);
-	break;
-    case 2:				/* trying to remove plover, bad
-					   route */
-	if (enclosed(EMERALD))
-	    extract(EMERALD);
-	drop(EMERALD, g.loc);
-	g.newloc = 33;
-	break;
-    case 3:				/* troll bridge */
-	if (g.prop[TROLL] == 1) {
-	    pspeak(TROLL, 1);
-	    g.prop[TROLL] = 0;
-	    move(TROLL2, 0);
-	    move((TROLL2 + MAXOBJ), 0);
-	    move(TROLL, plac[TROLL]);
-	    move((TROLL + MAXOBJ), fixd[TROLL]);
-	    juggle(CHASM);
-	    g.newloc = g.loc;
-	} else {
-	    g.newloc = plac[TROLL] + fixd[TROLL] - g.loc;
-	    if (g.prop[TROLL] == 0)
-		g.prop[TROLL] = 1;
-	    if (toting(BEAR)) {
-		rspeak(162);
-		g.prop[CHASM] = 1;
-		g.prop[TROLL] = 2;
-		drop(BEAR, g.newloc);
-		g.fixed[BEAR] = -1;
-		g.prop[BEAR] = 3;
-		if (g.prop[SPICES] < 0)
-		    ++g.tally2;
-		g.oldloc2 = g.newloc;
-		death();
-	    }
-	}
-	break;
-    case 4:
-	/* Growing or shrinking in area of tiny door.  Each time he
-	   does this, everything must be moved to the new loc.
-	   Presumably, all his possesions are shrunk or streched along
-	   with him. Phuce[2][4] is an array containg four pairs of
-	   "here" (K) and "there" (KK) locations. */
-	k = phuce[0][g.loc - 161];
-	g.newloc = phuce[1][g.loc - 161];
-	for (obj = 1; obj < MAXOBJ; obj++) {
-	    if (obj == BOAT)
-		continue;
-	    if (g.place[obj] == k && (g.fixed[obj] == 0 || g.fixed[obj] == -1))
-		move(obj, g.newloc);
-	}
-	break;
-    case 5:
-	/* Phone booth in rotunda. Trying to shove past gnome, to get
-	   into phone booth. */
-	if ((g.prop[BOOTH] == 0 && pct(35)) || g.visited[g.loc] == 1) {
-	    rspeak(263);
-	    g.prop[BOOTH] = 1;
-	    move(GNOME, 188);
-	} else {
-	    if (g.prop[BOOTH] == 1)
-		rspeak(253);
-	    else
-		g.newloc = 189;
-	}
-	break;
-    case 6:
-	/* Collapsing clay bridge.  He can cross with three (or fewer)
-	   thing.  If more, of if carrying obviously heavy things, he
-	   may end up in the drink. */
-	g.newloc = g.loc == 235 ? 190 : 235;
-	bcrossing++;
-	load = burden(0);
-	if (load > 4) {
-	    k = (load + bcrossing) * 6 - 10;
-	    if (!pct(k))
-		rspeak(318);
-	    else {
-		rspeak(319);
-		g.newloc = 236;
-		if (holding(LAMP))
-		    move(LAMP, 236);
-		if (toting(AXE) && enclosed(AXE))
-		    extract(AXE);
-		if (holding(AXE))
-		    move(AXE, 208);
-		for (obj = 1; obj < MAXOBJ; obj++)
-		    if (toting(obj))
-			destroy(obj);
-		g.prop[CHASM2] = 1;
-	    }
-	}
-	break;
-    case 7:
-	/* Kaleidoscope code is here. */
-	if (kalflg == 5) {
-	    g.newloc = 248;
-	    g.oldloc = 247;
-	} else {
-	    g.newloc = 242 + ranz(5);
-	    g.oldloc = g.newloc - 1;
-	    kalflg = g.newloc == 242 ? 0 : -10;
-	}
-	break;
-    default:
-	bug(38);
-    }
-    return;
-}
-
-/*
-  Routine to fill travel array for a given location
-*/
-void gettrav(loc, travel)
-int loc;
-struct trav *travel;
-{
-    int i;
-    long t, *lptr;
-
-    lptr = cave[loc - 1];
-    for (i = 0; i < MAXTRAV; i++) {
-	t = *lptr++;
-	if (!(t)) {
-	    travel->tdest = -1;		/* end of array	 */
-	    return;			/* terminate for loop	 */
-	}
-	travel->tverb = (int) (t % 1000);
-	t /= 1000;
-	travel->tdest = (int) (t % 1000);
-	t /= 1000;
-	travel->tcond = (int) (t % 1000);
-	travel++;
-    }
-    bug(25);
-    return;
-}
Index: trunk/minix/commands/advent/turn.c
===================================================================
--- trunk/minix/commands/advent/turn.c	(revision 9)
+++ 	(revision )
@@ -1,729 +1,0 @@
-/*	program TURN.C						*/
-
-
-#include	<stdio.h>
-#include	<stdlib.h>
-#include	"advent.h"
-#include	"advdec.h"
-
-_PROTOTYPE(void descitem, (void));
-_PROTOTYPE(void domove, (void));
-_PROTOTYPE(void goback, (void));
-_PROTOTYPE(void copytrv, (struct trav *, struct trav *));
-_PROTOTYPE(void dotrav, (void));
-_PROTOTYPE(void badmove, (void));
-_PROTOTYPE(void spcmove, (int));
-_PROTOTYPE(void death, (void));
-_PROTOTYPE(void dwarves, (void));
-_PROTOTYPE(void dopirate, (void));
-_PROTOTYPE(int stimer, (void));
-_PROTOTYPE(void do_hint, (int));
-
-
-/*
-  Routine to take 1 turn
-*/
-void turn()
-{
-    int i, hint;
-    static int waste = 0;
-
-    if (newtravel) {
-	/* If closing, then he can't leave except via the main office. */
-	if (outside(g.newloc) && g.newloc != 0 && g.closing) {
-	    rspeak(130);
-	    g.newloc = g.loc;
-	    if (!g.panic)
-		g.clock2 = 15;
-	    g.panic = TRUE;
-	}
-	/* See if a dwarf has seen him and has come from where he wants
-	   to go. */
-	if (g.newloc != g.loc && !forced(g.loc) && g.loc_attrib[g.loc] & NOPIRAT == 0)
-	    for (i = 1; i < (DWARFMAX - 1); ++i)
-		if (g.odloc[i] == g.newloc && g.dseen[i]) {
-		    g.newloc = g.loc;
-		    rspeak(2);
-		    break;
-		}
-
-	g.loc = g.newloc;
-	dwarves();			/* & special dwarf(pirate who
-					   steals)	 */
-
-	/* Check for death */
-	if (g.loc == 0) {
-	    death();
-	    return;
-	}
-	/* Check for forced move */
-	if (forced(g.loc)) {
-	    desclg(g.loc);
-	    ++g.visited[g.loc];
-	    domove();
-	    return;
-	}
-	/* Check for wandering in dark */
-	if (g.wzdark && dark() && pct(35)) {
-	    rspeak(23);
-	    g.oldloc2 = g.loc;
-	    death();
-	    return;
-	}
-	/* see if he is wasting his batteies out in the open */
-	if (outside(g.loc) && g.prop[LAMP]) {
-	    waste++;
-	    if (waste > 11) {
-		rspeak(324);
-		waste = 0;
-	    }
-	} else
-	    waste = 0;
-
-	/* If wumpus is chasing stooge, see if wumpus gets him */
-	if (g.chase) {
-	    g.chase++;
-	    g.prop[WUMPUS] = g.chase / 2;
-	    move(WUMPUS, g.loc);
-	    if (g.chase >= 10) {
-		if (dark())
-		    rspeak(270);
-		pspeak(WUMPUS, 5);
-		death();
-		return;
-	    }
-	}
-	/* check for radiation poisoning. */
-	g.health += (outside(g.loc)) ? 3 : 1;
-	if (g.health > 100)
-	    g.health = 100;
-	if (here(RADIUM) && (g.place[RADIUM] != -SHIELD || ajar(SHIELD)))
-	    g.health -= 7;
-	if (g.health < 60) {
-	    rspeak(391 + (60 - g.health) / 10);
-	    if (g.health < 0) {
-		death();
-		return;
-	    }
-	}
-	if ((g.oldloc == 188) && (g.loc != 188 && g.loc != 189)
-	    && (g.prop[BOOTH] == 1)) {
-	    move(GNOME, 0);
-	    g.prop[BOOTH] = 0;
-	}
-	/* Describe his situation */
-	describe();
-	if (!blind()) {
-	    ++g.visited[g.loc];
-	    descitem();
-	}
-    }					/* end of newtravel start for
-					   second entry point */
-    /* Check if this location is eligible for any hints.  If been here
-       long enough, branch to help section. Ignore "hints" < HNTMIN
-       (special stuff, see database notes. */
-    for (hint = HNTMIN; hint <= HNTMAX; hint++) {
-	if (g.hinted[hint])
-	    continue;
-	if (g.loc_attrib[g.loc] / 256 != hint - 6)
-	    g.hintlc[hint] = -1;
-	g.hintlc[hint]++;
-	if (g.hintlc[hint] >= g.hints[hint][1])
-	    do_hint(hint);
-    }
-
-    if (g.closed) {
-	if (g.prop[OYSTER] < 0 && toting(OYSTER))
-	    pspeak(OYSTER, 1);
-	for (i = 1; i < MAXOBJ; ++i)
-	    if (toting(i) && g.prop[i] < 0)
-		g.prop[i] = -1 - g.prop[i];
-    }
-    g.wzdark = dark();
-    if (g.knfloc > 0 && g.knfloc != g.loc)
-	g.knfloc = 0;
-    ++g.turns;
-    i = rand();
-
-    if (stimer())			/* as the grains of sand slip
-					   by */
-	return;
-
-    while (!english())			/* retrieve player instructions	 */
-	;
-
-    vrbx = 1;
-    objx = objs[1] ? 1 : 0;
-    iobx = iobjs[1] ? 1 : 0;
-    verb = VAL(verbs[vrbx]);
-    do {
-	object = objx ? objs[objx] : 0;
-	iobj = iobx ? iobjs[iobx] : 0;
-	if (object && (objs[2] || iobjs[2])) {
-	    pspeak(object, -1);
-	    printf("      ");
-	}
-	switch (CLASS(verbs[vrbx])) {
-	case MOTION:
-	    motion = verb;
-	    domove();
-	    break;
-	case NOUN:
-	    bug(22);
-	case ACTION:
-	    if (object || iobj)
-		trverb();
-	    else
-		itverb();
-	    break;
-	case MISC:
-	    rspeak(verb);
-	    if (verb == 51)
-		g.hinted[1] = TRUE;
-	    break;
-	default:
-	    bug(22);
-	}
-	if (objx) {
-	    objx++;
-	    if (objs[objx] == 0)
-		objx = 0;
-	}
-	if ((!objx || !objs[objx]) && iobx) {
-	    iobx++;
-	    if (iobjs[iobx] == 0)
-		iobx = 0;
-	    if (iobx && iobjs[1])
-		objx = 1;
-	}
-    } while (objx || iobx);
-    return;
-}
-
-/*
-  Routine to describe current location
-*/
-void describe()
-{
-    if (toting(BEAR))
-	rspeak(141);
-    if (dark())
-	rspeak(16);
-    else if ((g.terse && verb != LOOK) || g.visited[g.loc] % g.abbnum)
-	descsh(g.loc);
-    else
-	desclg(g.loc);
-    if (g.loc == 33 && pct(25) && !g.closing)
-	rspeak(8);
-    if (g.loc == 147 && !g.visited[g.loc])
-	rspeak(216);
-    return;
-}
-
-/*
-  Routine to describe visible items
-*/
-void descitem()
-{
-    int i, state;
-
-    for (i = 1; i < MAXOBJ; ++i) {
-	if (at(i)) {
-	    if (i == STEPS && toting(NUGGET))
-		continue;
-	    if (g.prop[i] < 0) {
-		if (g.closed)
-		    continue;
-		else {
-		    g.prop[i] = 0;
-		    if (i == RUG || i == CHAIN
-			|| i == SWORD || i == CASK)
-			g.prop[i] = 1;
-		    if (i == CLOAK || i == RING)
-			g.prop[i] = 2;
-		    --g.tally;
-		}
-	    }
-	    if (i == STEPS && g.loc == g.fixed[STEPS])
-		state = 1;
-	    else
-		state = g.prop[i] % 8;
-	    pspeak(i, state);
-	    lookin(i);
-	}
-    }
-    /* If remaining treasures too elusive, zap his lamp */
-    if (g.tally == g.tally2 && g.tally != 0 && g.limit > 35)
-	g.limit = 35;
-    return;
-}
-
-/*
-  Routine to handle player's demise via
-  waking up the dwarves...
-*/
-void dwarfend()
-{
-    rspeak(136);
-    normend();
-    return;
-}
-
-/*
-  normal end of game
-*/
-void normend()
-{
-    score(FALSE);
-    gaveup = TRUE;
-    return;
-}
-
-/*
-  Routine to handle the passing on of one
-  of the player's incarnations...
-*/
-void death()
-{
-    int yea, j;
-
-    if (!g.closing) {
-	if (g.limit < 0) {
-	    rspeak(185);
-	    normend();
-	    return;
-	}
-	yea = yes(81 + g.numdie * 2, 82 + g.numdie * 2, 54);
-	if (++g.numdie >= MAXDIE || !yea)
-	    normend();
-	if (g.chase) {
-	    g.chase = FALSE;
-	    g.prop[WUMPUS] = 0;
-	    move(WUMPUS, 174);
-	}
-	if (toting(LAMP))
-	    g.prop[LAMP] = 0;
-	for (j = 1; j < MAXOBJ; ++j) {
-	    if (toting(j))
-		drop(j, j == LAMP ? 1 : g.oldloc2);
-	    if (wearng(j)) {
-		g.prop[j] = 0;
-		bitoff(j, WEARBT);
-	    }
-	}
-	g.newloc = 3;
-	g.oldloc = g.loc;
-	g.health = 100;
-	return;
-    }
-    /* Closing -- no resurrection... */
-    rspeak(131);
-    ++g.numdie;
-    normend();
-    return;
-}
-
-/*
-  dwarf stuff.
-*/
-void dwarves()
-{
-    int i, j, k, attack, stick, dtotal;
-
-    /* See if dwarves allowed here */
-    if (g.newloc == 0 || forced(g.newloc) || g.loc_attrib[g.newloc] & NOPIRAT)
-	return;
-
-    /* See if dwarves are active. */
-    if (!g.dflag) {
-	if (inside(g.newloc))
-	    ++g.dflag;
-	return;
-    }
-    /* If first close encounter (of 3rd kind) */
-    if (g.dflag == 1) {
-	if (!inside(g.newloc) || pct(85))
-	    return;
-	++g.dflag;
-
-	/* kill 0, 1 or 2 of the dwarfs */
-	for (i = 1; i < 3; ++i)
-	    if (pct(50))
-		g.dloc[(ranz(DWARFMAX - 1)) + 1] = 0;
-
-	/* If any of the survivors is at location, use alternate choise */
-	for (i = 1; i <= DWARFMAX; ++i) {
-	    if (g.dloc[i] == g.newloc)
-		g.dloc[i] = g.daltloc;
-	    g.odloc[i] = g.dloc[i];
-	}
-	rspeak(3);
-	drop(AXE, g.newloc);
-	return;
-    }
-    /* Things are in full swing.  Move each dwarf at random, except if
-       he's seen us then he sticks with us.  Dwarfs never go to
-       locations outside or meet the bear or following him into dead
-       end in maze.  And of couse, dead dwarves don't do much of
-       anything.  */
-
-    dtotal = attack = stick = 0;
-    for (i = 1; i <= DWARFMAX; ++i) {
-	if (g.dloc[i] == 0)
-	    continue;
-	/* Move a dwarf at random.  we don't have a matrix around to do
-	   it as in the original version... */
-	do
-	    j = ranz(106) + 15;
-	/* allowed area */
-	while (j == g.odloc[i] || j == g.dloc[i]
-	       || g.loc_attrib[j] & NOPIRAT);
-
-	if (j == 0)
-	    bug(36);
-	g.odloc[i] = g.dloc[i];
-	g.dloc[i] = j;
-
-	g.dseen[i] = ((g.dseen[i] && inside(g.newloc))
-		      || g.dloc[i] == g.newloc
-		      || g.odloc[i] == g.newloc);
-
-	if (g.dseen[i]) {
-	    g.dloc[i] = g.newloc;
-	    if (i == DWARFMAX)
-		dopirate();
-	    else {
-		++dtotal;
-		if (g.odloc[i] == g.dloc[i]) {
-		    ++attack;
-		    if (g.knfloc >= 0)
-			g.knfloc = g.newloc;
-		    if (ranz(1000) < (45 * (g.dflag - 2)))
-			++stick;
-		}
-	    }
-	}
-    }
-
-    /* Now we know shat's happing, let's tell the poor sucker about it */
-    if (dtotal == 0)
-	return;
-    if (dtotal > 1)
-	printf("There are %d threatening little dwarves in the room with you!\n", dtotal);
-    else
-	rspeak(4);
-    if (attack == 0)
-	return;
-    if (g.dflag == 2)
-	++g.dflag;
-    if (attack > 1) {
-	printf("%d of them throw knives at you!!\n", attack);
-	k = 6;
-    } else {
-	rspeak(5);
-	k = 52;
-    }
-    if (stick <= 1) {
-	rspeak(stick + k);
-	if (stick == 0)
-	    return;
-    } else
-	printf("%d of them get you !!!\n", stick);
-    g.oldloc2 = g.newloc;
-    death();
-    return;
-}
-
-/*
-  pirate stuff
-*/
-void dopirate()
-{
-    int j;
-    boolean k;
-
-    if (g.newloc == g.chloc || g.prop[CHEST] >= 0)
-	return;
-    k = FALSE;
-    /* Pirate won't take pyramid from plover room or dark room  (too
-       easy! ) */
-    for (j = 1; j < MAXOBJ; ++j)
-	if (treasr(j) && !(j == CASK && liq(CASK) == WINE)
-	    && !(j == PYRAMID && (g.newloc == g.place[PYRAMID]
-				  || g.newloc == g.place[EMERALD]))) {
-	    if (toting(j) && athand(j))
-		goto stealit;
-	    if (here(j))
-		k = TRUE;
-	}
-    if (g.tally == g.tally2 + 1 && k == FALSE && g.place[CHEST] == 0 &&
-	athand(LAMP) && g.prop[LAMP] == 1) {
-	rspeak(186);
-	move(CHEST, g.chloc);
-	move(MESSAGE, g.chloc2);
-	g.dloc[DWARFMAX] = g.chloc;
-	g.odloc[DWARFMAX] = g.chloc;
-	g.dseen[DWARFMAX] = 0;
-	return;
-    }
-    if (g.odloc[DWARFMAX] != g.dloc[DWARFMAX] && pct(30))
-	rspeak(127);
-    return;
-
-stealit:
-
-    rspeak(128);
-    /* don't steal chest back from troll! */
-    if (g.place[MESSAGE] == 0)
-	move(CHEST, g.chloc);
-    move(MESSAGE, g.chloc2);
-    for (j = 1; j < MAXOBJ; ++j) {
-	if (!treasr(j) || !athand(j)
-	    || (j == PYRAMID &&
-	     (g.newloc == plac[PYRAMID] || g.newloc == plac[EMERALD]))
-	    || (j == CASK && (liq(CASK) != WINE)))
-	    continue;
-	if (enclosed(j))
-	    extract(j);
-	if (wearng(j)) {
-	    g.prop[j] = 0;
-	    bitoff(j, WEARBT);
-	}
-	insert(j, CHEST);
-    }
-    g.dloc[DWARFMAX] = g.chloc;
-    g.odloc[DWARFMAX] = g.chloc;
-    g.dseen[DWARFMAX] = FALSE;
-    return;
-}
-
-/*
-  special time limit stuff...
-*/
-int stimer()
-{
-    int i, spk;
-    static int clock3;
-
-    g.foobar = g.foobar > 0 ? -g.foobar : 0;
-    g.combo = g.combo > 0 ? -g.combo : 0;
-    if (g.turns > 310 && g.abbnum != 10000 && !g.terse)
-	rspeak(273);
-
-    /* Bump all the right clocks for reconning battery life and closing */
-    if (g.closed) {
-	clock3--;
-	if (clock3 == 0) {
-	    g.prop[PHONE] = 0;
-	    g.prop[BOOTH] = 0;
-	    rspeak(284);
-	} else if (clock3 < -7) {
-	    rspeak(254);
-	    normend();
-	    return (TRUE);
-	}
-    }
-    if (g.tally == 0 && inside(g.loc) && g.loc != Y2)
-	--g.clock;
-    if (g.clock == 0) {
-	/* Start closing the cave */
-	g.prop[GRATE] = 0;
-	biton(GRATE, LOCKBT);
-	bitoff(GRATE, OPENBT);
-	g.prop[FISSURE] = 0;
-	g.prop[TDOOR] = 0;
-	biton(TDOOR, LOCKBT);
-	bitoff(TDOOR, OPENBT);
-	g.prop[TDOOR2] = 0;
-	biton(TDOOR2, LOCKBT);
-	bitoff(TDOOR2, OPENBT);
-	for (i = 1; i <= DWARFMAX; ++i) {
-	    g.dseen[i] = FALSE;
-	    g.dloc[i] = 0;
-	}
-	move(TROLL, 0);
-	move((TROLL + MAXOBJ), 0);
-	move(TROLL2, plac[TROLL]);
-	move((TROLL2 + MAXOBJ), fixd[TROLL]);
-	juggle(CHASM);
-	if (g.prop[BEAR] != 3)
-	    destroy(BEAR);
-	g.prop[CHAIN] = 0;
-	g.fixed[CHAIN] = 0;
-	g.prop[AXE] = 0;
-	g.fixed[AXE] = 0;
-	rspeak(129);
-	g.clock = -1;
-	g.closing = TRUE;
-	return (FALSE);
-    }
-    if (g.clock < 0)
-	--g.clock2;
-    if (g.clock2 == 0) {
-	/* Set up storage room... and close the cave... */
-	g.prop[BOTTLE] = put(BOTTLE, 115, 8);
-	g.holder[BOTTLE] = WATER;
-	g.place[WATER] = -BOTTLE;
-	g.hlink[WATER] = 0;
-	bitoff(BOTTLE, OPENBT);
-	g.prop[PLANT] = put(PLANT, 115, 0);
-	g.prop[OYSTER] = put(OYSTER, 115, 0);
-	g.prop[LAMP] = put(LAMP, 115, 0);
-	g.prop[ROD] = put(ROD, 115, 0);
-	g.prop[DWARF] = put(DWARF, 115, 0);
-	g.loc = 115;
-	g.oldloc = 115;
-	g.newloc = 115;
-	/* Leave the grate with normal (non-negative property). */
-	put(GRATE, 116, 0);
-	biton(GRATE, LOCKBT);
-	bitoff(GRATE, OPENBT);
-	g.prop[SNAKE] = put(SNAKE, 116, 1);
-	g.prop[BIRD] = put(BIRD, 116, 1);
-	g.prop[CAGE] = put(CAGE, 116, 0);
-	g.prop[ROD2] = put(ROD2, 116, 0);
-	g.prop[PILLOW] = put(PILLOW, 116, 0);
-
-	g.prop[BOOTH] = put(BOOTH, 116, -3);
-	g.fixed[BOOTH] = 115;
-	g.prop[PHONE] = put(PHONE, 212, -4);
-
-	g.prop[MIRROR] = put(MIRROR, 115, 0);
-	g.fixed[MIRROR] = 116;
-	g.prop[BOOK2] = put(BOOK2, 115, 0);
-
-	for (i = 1; i < MAXOBJ; ++i) {
-	    if (toting(i) && enclosed(i))
-		extract(i);
-	    if (toting(i))
-		destroy(i);
-	}
-	rspeak(132);
-	g.closed = TRUE;
-	clock3 = 20 + ranz(20);
-	newtravel = TRUE;
-	return (TRUE);
-    }
-    if (g.prop[LAMP] == 1)
-	--g.limit;
-    if (g.limit == 0) {
-	--g.limit;
-	g.prop[LAMP] = 0;
-	if (here(LAMP))
-	    rspeak(184);
-	return (FALSE);
-    }
-    if (g.limit < 0 && outside(g.loc)) {
-	rspeak(185);
-	normend();
-	return (TRUE);
-    }
-    if (g.limit <= 40) {
-	if (g.lmwarn || !here(LAMP))
-	    return (FALSE);
-	g.lmwarn = TRUE;
-	spk = 187;
-	if (g.prop[BATTERIES] == 1)
-	    spk = 323;
-	if (g.place[BATTERIES] == 0)
-	    spk = 183;
-	if (g.prop[VEND] == 1)
-	    spk = 189;
-	rspeak(spk);
-	return (FALSE);
-    }
-    return (FALSE);
-}
-
-/* HINTS
-   come here if he's been long enough at required location(s)
-   for some unused hint,  hint number is in variable "hint".
-   Branch to quick test for additional conditions, then
-   do neet stuff. If conditions are met and we want to offer
-   hint.  Clear hintlc if no action is taken.
- */
-
-#define MASE 1
-#define DARK 2
-#define WITT 3
-#define H_SWORD 4
-#define SLIDE 5
-#define H_GRATE 6
-#define H_BIRD 7
-#define H_ELFIN 8
-#define RNBOW 9
-#define STYX  10
-#define H_SNAKE 11
-#define CASTLE 12
-
-void do_hint(hint)
-int hint;
-{
-    g.hintlc[hint] = 0;
-    switch (hint + 1 - HNTMIN) {
-    case MASE:
-	if (!at(g.loc) && !at(g.oldloc)
-	    && !at(g.loc) && burden(0) > 1)
-	    break;
-	else
-	    return;
-    case DARK:
-	if (g.prop[EMERALD] != -1 && g.prop[PYRAMID] == -1)
-	    break;
-	else
-	    return;
-    case WITT:
-	break;
-    case H_SWORD:
-	if ((g.prop[SWORD] == 1 || g.prop[SWORD] == 5)
-	    && !toting(CROWN))
-	    break;
-	else
-	    return;
-    case SLIDE:
-	break;
-    case H_GRATE:
-	if (g.prop[GRATE] == 0 && !athand(KEYS))
-	    break;
-	else
-	    return;
-    case H_BIRD:
-	if (here(BIRD) && athand(ROD) && object == BIRD)
-	    break;
-	else
-	    return;
-    case H_ELFIN:
-	if (!g.visited[159])
-	    break;
-	else
-	    return;
-    case RNBOW:
-	if (!toting(SHOES) || g.visited[205])
-	    break;
-	else
-	    return;
-    case STYX:
-	if (!athand(LYRE) && g.prop[DOG] != 1)
-	    break;
-	else
-	    return;
-    case H_SNAKE:
-	if (here(SNAKE) && !here(BIRD))
-	    break;
-	else
-	    return;
-    case CASTLE:
-	break;
-    default:
-	printf("  TRYING TO PRINT HINT # %d\n", hint);
-	bug(27);
-    }
-    if (!yes(g.hints[hint][3], 0, 54))
-	return;
-    printf("\nI am prepared to give you a hint,");
-    printf(" but it will cost you %2d points\n", g.hints[hint][2]);
-    g.hinted[hint] = yes(175, g.hints[hint][4], 54);
-    if (g.hinted[hint] && g.limit > 30)
-	g.limit += 30 * g.hints[hint][2];
-    return;
-}
Index: trunk/minix/commands/advent/utility.c
===================================================================
--- trunk/minix/commands/advent/utility.c	(revision 9)
+++ 	(revision )
@@ -1,749 +1,0 @@
-/*
-  Utility Routines
-  the next logical funtions describe attributes of objects.
-  (ajar, hinged, opaque, printd, treasr, vessel, wearng)
-*/
-
-#include	<stdio.h>
-#include	<stdlib.h>
-#include	<ctype.h>
-#include	<string.h>
-#include	"advent.h"
-#include	"advdec.h"
-
-/*
-  ajar .TRUE. if item is container and is open or unhinged
-*/
-boolean ajar(item)
-int item;
-{
-    return ((bitset(g.obj_state[item], OPENBT))
-	    || (vessel(item) && !hinged(item)));
-}
-
-/*
-  at .TRUE. To tell if player is on either side of a two sided object.
-*/
-boolean at(item)
-int item;
-{
-    if (item < 1 || item > MAXOBJ)
-	return (FALSE);
-    else
-	return (g.place[item] == g.loc || g.fixed[item] == g.loc);
-}
-
-/*
-  athand .TRUE. if item readily reachable
-  it can be lying here, in hand or in open container.
-*/
-boolean athand(item)
-int item;
-{
-    int contnr;
-    boolean aaa;
-
-    contnr = -g.place[item];
-    aaa = enclosed(item) && ajar(contnr);
-
-    return ((g.place[item] == g.loc) || holding(item)
-	    || (aaa && ((g.place[contnr] == g.loc)
-			|| (toting(item) && holding(contnr)))));
-}
-
-/*
-  bitoff turns off (sets to 0) a bit in obj_state word
-*/
-void bitoff(obj, bit)
-int obj, bit;
-{
-    long val;
-
-    val = 1L << bit;
-    g.obj_state[obj] &= ~val;
-}
-
-/*
-  biton turns on (sets to 1) a bit in obj_state word
-*/
-void biton(obj, bit)
-int obj, bit;
-{
-    long val;
-
-    val = 1L << bit;
-    g.obj_state[obj] |= val;
-}
-
-/*
-   bitset .TRUE. if object_state has bit N set
-*/
-boolean bitset(state, bit)
-long state;
-int bit;
-{
-    return (((state >> bit) & 1) == 1);
-}
-
-/*
-  blind .TRUE. if you can't see at this loc, (darkness of glare)
-*/
-boolean blind()
-{
-    return (dark() || (g.loc == 200
-		       && athand(LAMP) && (g.prop[LAMP] == 1)));
-}
-
-/*
-   burden .. returns weight of items being carried
-
-   if obj=0, burden calculates the total weight of the adventurer's burden
-   including everything in all containers (except the boat) that he is
-   carring.
-
-   if object is a container, calculate the weight of everything inside
-   the container (including the container itself). Since donkey FORTRAN
-   isn't recursive, we will only calculate weight of contained containers
-   one level down.  The only serious contained container would be the sack
-   The only thing we'll miss will be filled VS empty bottle or cage.
-
-   If object isn't a container, return its weight.
-*/
-int burden(obj)
-int obj;
-{
-    int i, sum, temp;
-
-    sum = 0;
-    if (obj == 0) {
-	for (i = 1; i < MAXOBJ; i++) {
-	    if (toting(i) && (g.place[i] != -BOAT))
-		sum += g.weight[i];
-	}
-    } else {
-	if (obj != BOAT) {
-	    sum = g.weight[obj];
-	    temp = g.holder[obj];
-	    while (temp != 0) {
-		sum += g.weight[temp];
-		temp = g.hlink[temp];
-	    }
-	}
-    }
-    return (sum);
-}
-
-/*
-  Routine to carry an object
-  start toting an object, removing it from the list of things
-  at its former location.  If object > MAXOBJ ( moving "FIXED"
-  or second loc), then don't change place.
-*/
-void carry(obj, where)
-int obj, where;
-{
-    int temp;
-
-    if (obj < MAXOBJ) {
-	if (g.place[obj] == -1)
-	    return;
-	g.place[obj] = -1;
-    }
-    if (g.atloc[where] == obj)
-	g.atloc[where] = g.link[obj];
-    else {
-	temp = g.atloc[where];
-	while (g.link[temp] != obj) {
-	    temp = g.link[temp];
-	    if (temp == 0)
-		bug(35);
-	}
-	g.link[temp] = g.link[obj];
-    }
-    return;
-}
-
-/*
-  confuz generates some variant of "Don't understand that" message.
-*/
-int confuz()
-{
-    int msg;
-
-    msg = 60;
-    if (pct(50))
-	msg = 61;
-    if (pct(33))
-	msg = 13;
-    if (pct(25))
-	msg = 347;
-    if (pct(20))
-	msg = 195;
-    return (msg);
-}
-
-/*
-  dark .TRUE. if there is no light here
-*/
-boolean dark()
-{
-    return (!(g.loc_attrib[g.loc] & LIGHT) &&
-	    (!g.prop[LAMP] || !athand(LAMP)));
-}
-
-/*
-  Routine to check for presence
-  of dwarves..
-*/
-int dcheck()
-{
-    int i;
-
-    for (i = 1; i < (DWARFMAX); ++i)
-	if (g.dloc[i] == g.loc)
-	    return (i);
-    return (0);
-}
-
-/*
-   dead .TRUE. if object is now dead
-*/
-boolean dead(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 10));
-}
-
-/*
-  drop Place an object at a given loc, prefixing it onto the atloc list.
-*/
-void drop(obj, where)
-int obj, where;
-{
-    if (obj > MAXOBJ)
-	g.fixed[obj - MAXOBJ] = where;
-    else
-	g.place[obj] = where;
-    if (where > 0) {
-	g.link[obj] = g.atloc[where];
-	g.atloc[where] = obj;
-    }
-    return;
-}
-
-/*
-  destroy Permanently eliminate "object" by moving it to
-  a non-existent location.
-*/
-void destroy(obj)
-int obj;
-{
-    move(obj, 0);
-    return;
-}
-
-/*
-   edible .TRUE. if obj can be eaten.
-*/
-boolean edible(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 7));
-}
-
-/*
-  enclosed .TRUE. If object is inside a container.
-*/
-boolean enclosed(item)
-int item;
-{
-    if (item < 1 || item > MAXOBJ)
-	return (FALSE);
-    else
-	return (g.place[item] < -1);
-}
-
-/*
-   extract remove "object" from a container.
-   origionally name "remove" but rename to avoid conflict with stdio.h
-*/
-void extract(obj)
-int obj;
-{
-    int contnr, temp;
-
-    contnr = -g.place[obj];
-    g.place[obj] = -1;
-    if (g.holder[contnr] == obj)
-	g.holder[contnr] = g.hlink[obj];
-    else {
-	temp = g.holder[contnr];
-	while (g.hlink[temp] != obj) {
-	    temp = g.hlink[temp];
-	    if (temp == 0)
-		bug(35);
-	}
-	g.hlink[temp] = g.hlink[obj];
-    }
-    return;
-}
-
-/*
-  forced To tell if a location will causes a forced move.
-  A forced location is one from which he is immediately bounced
-  to another.  Normal use is for death (forced to location zero)
-  and for description of journey from on place to another.
-*/
-int forced(at_loc)
-int at_loc;
-{
-    return ((g.loc_attrib[at_loc] & 10) == 2);
-}
-
-/*
-  here .TRUE. If an item is at location or is being carried.
-*/
-boolean here(item)
-int item;
-{
-    return (g.place[item] == g.loc || toting(item));
-}
-
-/*
-  hinged .TRUE. If object can be opened or shut.
-*/
-boolean hinged(object)
-int object;
-{
-    return (bitset(g.obj_state[object], 1));
-}
-
-/*
-  holding .TRUE. If the object is being carried in hand.
-*/
-boolean holding(item)
-int item;
-{
-    if (item < 1 || item > MAXOBJ)
-	return (FALSE);
-    else
-	return (g.place[item] == -1);
-}
-
-/*
-  insert
-*/
-void insert(obj, contnr)
-int obj, contnr;
-{
-    int temp;
-
-    if (contnr == obj)
-	bug(32);
-    carry(obj, g.loc);
-
-    temp = g.holder[contnr];
-    g.holder[contnr] = obj;
-    g.hlink[obj] = temp;
-    g.place[obj] = -contnr;
-}
-
-/*
-  inside = .TRUE. If location is well within cave
-*/
-boolean inside(loc)
-int loc;
-{
-    return (!outside(loc) && !portal(loc));
-}
-
-/*
-  Juggle an object by picking it up and putting it down again,
-  The purpose being to get the object to the front of the chain
-  at its loc.
-*/
-void juggle(obj)
-int obj;
-{
-    int i, j;
-
-    i = g.place[obj];
-    j = g.fixed[obj];
-    move(obj, i);
-    move(obj + MAXOBJ, j);
-    return;
-}
-
-/*
-  Determine liquid in the vessel
-*/
-int liq(item)
-int item;
-{
-    int liquid;
-
-    if ((item == BOTTLE) || (item == CASK))
-	liquid = liq2(((int) g.prop[item] >> 1) & 7);
-    else
-	liquid = 0;
-
-    return (liquid);
-}
-
-/*
-  Determine type of liquid in vessel
-*/
-int liq2(liquid)
-int liquid;
-{
-    switch (liquid) {
-    case 4:
-	return (WATER);
-    case 5:
-	return (OIL);
-    case 6:
-	return (WINE);
-    default:
-	return (0);			/* empty */
-    }
-}
-
-/*
-  Determine liquid at a location
-*/
-int liqloc(loc)
-int loc;
-{
-    return (liq2((int) ((g.loc_attrib[loc] >> 1) & 7)));
-}
-
-/*
-   living .TRUE. If object is living, bear for example
-*/
-boolean living(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 9));
-}
-
-/*
-   locked .TRUE. if lockable object is locked
-*/
-boolean locked(item)
-int item;
-{
-    return (bitset(g.obj_state[item], 4));
-}
-
-/*
-   locks .TRUE. if you can lock this object
-*/
-boolean locks(item)
-int item;
-{
-    return (bitset(g.obj_state[item], 3));
-}
-
-/*
-  LOOKIN list contents if obj is a container and is open or transparent.
-*/
-void lookin(contnr)
-int contnr;
-{
-    int temp;
-    boolean first_time;
-
-    if (vessel(contnr) && (ajar(contnr) || !opaque(contnr))) {
-	temp = g.holder[contnr];
-	first_time = TRUE;
-	while (temp != 0) {
-	    if (first_time)
-		rspeak(360);
-	    printf("     ");
-	    pspeak(temp, -1);
-	    temp = g.hlink[temp];
-	    first_time = FALSE;
-	}
-    }
-    return;
-}
-
-/*
-  Routine to move an object
-*/
-void move(obj, where)
-int obj, where;
-{
-    int from;
-
-    if (obj > MAXOBJ)
-	from = g.fixed[obj - MAXOBJ];
-    else {
-	if (enclosed(obj))
-	    extract(obj);
-	from = g.place[obj];
-    }
-    if ((from > 0) && (from < MAXOBJ * 2))
-	carry(obj, from);
-    drop(obj, where);
-    return;
-}
-
-/*
-  noway, generate's some variant of "can't do that" message.
-*/
-int noway()
-{
-    int msg;
-
-    msg = 14;
-    if (pct(50))
-	msg = 110;
-    if (pct(33))
-	msg = 147;
-    if (pct(25))
-	msg = 250;
-    if (pct(20))
-	msg = 262;
-    if (pct(17))
-	msg = 25;
-    if (pct(14))
-	msg = 345;
-    if (pct(12))
-	msg = 346;
-    return (msg);
-}
-
-/*
-  opaque .TRUE. If obj is non-transparent container
-*/
-boolean opaque(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 6));
-}
-
-/*
-   outsid .TRUE. If location is outside the cave
-*/
-boolean outside(loc)
-int loc;
-{
-    return (bitset(g.loc_attrib[loc], 6));
-}
-
-/*
-  Routine true x% of the time. (x an integer from 0 to 100)
-*/
-int pct(x)
-int x;
-{
-    return (ranz(100) < x);
-}
-
-/*
-   plural .TRUE. if object is multiple objects
-*/
-boolean plural(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 13));
-}
-
-/*
-   portal .TRUE. If location is a cave entrance
-*/
-boolean portal(loc)
-int loc;
-{
-    return (bitset(g.loc_attrib[loc], 5));
-}
-
-/*
-   printed .TRUE. If object can be read.
-*/
-boolean printed(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 8));
-}
-
-/*
-  put is the same as move, except it returns a
-  value used to set the negated prop values
-  for the repository objects.
-*/
-int put(obj, where, pval)
-int obj, where, pval;
-{
-    move(obj, where);
-    return ((-1) - pval);
-}
-
-/*
-  RANZ
-*/
-int ranz(range)
-int range;
-{
-    return (rand() % range);
-}
-
-/*
-   small .TRUE. If object fits in sack or small container
-*/
-boolean small(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 5));
-}
-
-/*
-  toting .TRUE. If an item is being caried.
-*/
-int toting(item)
-int item;
-{
-    boolean aaa, bbb, ccc;
-    int contnr, outer, outer2;
-
-    contnr = -g.place[item];
-    outer = -g.place[contnr];
-    outer2 = -g.place[outer];
-
-    aaa = holding(contnr);
-    bbb = enclosed(contnr) && holding(outer);
-    ccc = enclosed(outer) && holding(outer2);
-
-    return (holding(item) || (enclosed(item) && (aaa || bbb || ccc)));
-}
-
-/*
-  treasr .TRUE. If object is valuable for points
-*/
-boolean treasr(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 14));
-}
-
-/*
-  vessel .TRUE. if object can hold a liquid
-*/
-boolean vessel(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 15));
-}
-
-/*
-  wearng .TRUE. If wearing obj
-*/
-boolean wearng(item)
-int item;
-{
-    return (bitset(g.obj_state[item], WEARBT));
-}
-
-/*
-   worn .TRUE. if object is being worn
-*/
-boolean worn(obj)
-int obj;
-{
-    return (bitset(g.obj_state[obj], 11));
-}
-
-static char *e_msg[] = {
-			"message line > 70 characters",	/* 00 */
-			"null line in message",	/* 01 */
-			"too many words of messages",	/* 02 */
-			"too many travel options",	/* 03 */
-			"too many vocabulary words",	/* 04 */
-			"required vocabulary word not found",	/* 05 */
-			"too many rtext or mtext messages",	/* 06 */
-			"too many hints",	/* 07 */
-			"location has loc_attrib bit being set twice",	/* 08 */
-			"invalid section number in database",	/* 09 */
-			"out of order locs or rspeak entries.",	/* 10 */
-			"illegal motion word in travel table",	/* 11 */
-			"** unused **.",/* 12 */
-			"unknown or illegal word in adjective table.",	/* 13 */
-			"illegal word in prep/obj table",	/* 14 */
-			"too many entries in prep/obj table",	/* 15 */
-			"object has condition bit set twice",	/* 16 */
-			"object number too large",	/* 17 */
-			"too many entries in adjective/noun table.",	/* 18 */
-			"** unused **.",/* 19 */
-			"special travel (500>l>300) exceeds goto list",	/* 20 */
-			"ran off end of vocabulary table",	/* 21 */
-			"verb class (n/1000) not between 1 and 3",	/* 22 */
-			"intransitive action verb exceeds goto list",	/* 23 */
-			"transitive action verb exceeds goto list",	/* 24 */
-			"conditional travel entry with no alternative",	/* 25 */
-			"location has no travel entries",	/* 26 */
-			"hint number exceeds goto list",	/* 27 */
-			"invalid month returned by date function",	/* 28 */
-			"action verb 'leave' has no object.",	/* 29 */
-			"preposition found in unexpected table",	/* 30 */
-		 "received an unexpected word terminator from a1toa5",	/* 31 */
-		    "trying to put a container into itself (tricky!)",	/* 32 */
-			"unknown word class in getwds",	/* 33 */
-			"** unused **.",/* 34 */
-			"trying to carry a non-existent object"};	/* 35 */
-
-/*
-  Fatal error routine
-*/
-void bug(n)
-unsigned int n;
-{
-    if (n < 36 && *e_msg[n] != '*')
-	fprintf(stderr, "Fatal error, probable cause: %s\n", e_msg[n]);
-    else
-	fprintf(stderr, "Fatal error number %d - Unused error number!\n", n);
-    panic((char *) 0, TRUE);
-}
-
-/*
-  Prompt for input, strip leading and trailing spaces,
-  return &buf[first non-whitespace].
-  Does not return if end of input.
-*/
-char *
- ask(prompt, buf, buflen)
-char *prompt, *buf;
-int buflen;
-{
-    fputs(prompt, stdout);
-    fflush(stdout);
-    if (!fgets(buf, buflen, stdin))
-	panic("end of input", FALSE);
-    if (*buf) {
-	int c;
-	char *end = buf + strlen(buf);
-	if (end[-1] != '\n')
-	    /* Skip to end of line */
-	    while ((c = getchar()) != '\n' && c != EOF);
-	while (*buf && isspace(*buf))
-	    buf++;
-	while (buf <= --end && isspace(*end))
-	    *end = '\0';
-    }
-    return buf;
-}
-
-/*
-  save and abort
-*/
-
-void panic(msg, save)
-char *msg;
-boolean save;
-{
-    fprintf(stderr, "\nPANIC: %s%s\n",
-	 msg ? msg : "", save ? ". Save..." : msg ? "" : "aborting.");
-    if (save)
-	saveadv("advpanic.sav");
-    exit(EXIT_FAILURE);
-}
Index: trunk/minix/commands/advent/verb.c
===================================================================
--- trunk/minix/commands/advent/verb.c	(revision 9)
+++ 	(revision )
@@ -1,2142 +1,0 @@
-/*	program VERB.C						*/
-
-#include	"stdio.h"
-#include	"advent.h"
-#include	"advdec.h"
-
- /* Initialize default verb messages */
-static _CONST int actmsg[56] = {
-     0,  24,  29,  0,  33,   0,  33,  38,  38,  42,
-    14,  43, 110, 29, 110,  73,  75,  29,  13,  59,
-    59, 174, 313, 67,  13, 147, 155, 369, 146, 110,
-    13,  13,  24, 25, 110, 262,  14,  29, 271,  14,
-    14,  24,  29, 38,  24, 331,  24, 109, 332,   0,
-     0, 348, 358,  0, 364,   0};
-
-_PROTOTYPE(static int ck_obj, (void));
-_PROTOTYPE(void von, (void));
-_PROTOTYPE(void voff, (void));
-_PROTOTYPE(void vwave, (void));
-_PROTOTYPE(void veat, (void));
-_PROTOTYPE(void vthrow, (void));
-_PROTOTYPE(void vfind, (void));
-_PROTOTYPE(void vfill, (void));
-_PROTOTYPE(void vfeed, (void));
-_PROTOTYPE(void vbreak, (void));
-_PROTOTYPE(void vwake, (void));
-_PROTOTYPE(void vdrop, (void));
-_PROTOTYPE(void vpour, (void));
-_PROTOTYPE(void vput, (void));
-_PROTOTYPE(void vread, (void));
-_PROTOTYPE(void vinsert, (void));
-_PROTOTYPE(void vextract, (void));
-_PROTOTYPE(static boolean do_battle, (int *));
-_PROTOTYPE(void vhit, (void));
-_PROTOTYPE(void vanswer, (void));
-_PROTOTYPE(void vblow, (void));
-_PROTOTYPE(void vdial, (void));
-_PROTOTYPE(void vplay, (void));
-_PROTOTYPE(void vpick, (void));
-_PROTOTYPE(void vput, (void));
-_PROTOTYPE(void vturn, (void));
-_PROTOTYPE(void vget, (void));
-_PROTOTYPE(void vlook, (void));
-
-
-/*
-  Routine to process a transitive verb
-*/
-void trverb()
-{
-    newtravel = FALSE;
-    switch (verb) {
-    case NOTHING:
-    case CALM:
-    case WALK:
-    case QUIT:
-    case SCORE:
-    case FOO:
-    case SUSPEND:			break;
-    case TAKE:		vtake();	break;
-    case DROP:		vdrop();	break;
-    case SAY:		bug(34);	break;
-    case OPEN:		vopen();	break;
-    case CLOSE:		vclose();	break;
-    case LOCK:		vlock();	break;
-    case UNLOCK:	vunlock();	break;
-    case ON:		von();		break;
-    case OFF:		voff();		break;
-    case WAVE:		vwave();	break;
-    case KILL:		vkill();	break;
-    case POUR:		vpour();	break;
-    case EAT:		veat();		break;
-    case DRINK:		vdrink();	break;
-    case RUB:
-	if (object != LAMP)
-	    rspeak(76);
-	else
-	    actspk(RUB);
-	break;
-    case THROW:
-	if (prep == PREPDN)
-	    vput();
-	else
-	    vthrow();
-	break;
-    case FEED:		vfeed();	break;
-    case FIND:
-    case INVENTORY:	vfind();	break;
-    case FILL:		vfill();	break;
-    case BLAST:		ivblast();	break;
-    case READ:		vread();	break;
-    case BREAK:		vbreak();	break;
-    case WAKE:		vwake();	break;
-    case REMOVE:	vextract();	break;
-    case YANK:		vyank();	break;
-    case WEAR:		vwear();	break;
-    case HIT:		vhit();		break;
-    case ANSWER:	vanswer();	break;
-    case BLOW:		vblow();	break;
-    case DIAL:		vdial();	break;
-    case PLAY:		vplay();	break;
-    case PICK:		vpick();	break;
-    case PUT:		vput();		break;
-    case TURN:		vturn();	break;
-    case GET:		vget();		break;
-    case INSRT:		vinsert();	break;
-    case LOOK:		vlook();	break;
-    default:
-	printf("This verb is not implemented yet.\n");
-    }
-    return;
-}
-
-/*
-  Routine to speak default verb message
-*/
-void actspk(verb)
-int verb;
-{
-    int i;
-
-    if (verb < 1 || verb > 55)
-	bug(39);
-    i = actmsg[verb];
-    if (i)
-	rspeak(i);
-    return;
-}
-
-/*
-  CARRY TAKE etc.
-*/
-void vtake()
-{
-    int msg;
-
-    msg = 0;
-    if (object == BIRD && !g.closed && athand(BIRD)
-	&& g.place[BIRD] != g.loc) {
-	rspeak(407);
-	return;
-    }
-    if (prep == PREPOF) {
-	if (object && iobj) {
-	    rspeak(confuz());
-	    return;
-	} else if (!object) {
-	    object = iobj;
-	    iobj = 0;
-	    vdrop();
-	    return;
-	}
-    }
-    msg = 24;
-    if (object == BOAT)
-	msg = 281;
-    if (plural(object))
-	msg = 297;
-    if (holding(object)) {
-	rspeak(msg);
-	return;
-    }
-    /* Special case objects and fixed objects */
-    msg = ck_obj();
-    if (g.fixed[object]) {
-	rspeak(msg);
-	return;
-    }
-    if (prep == PREPIN) {
-	vinsert();
-	return;
-    }
-    /* Special case for liquids */
-    if (object == WATER || object == OIL || object == WINE) {
-	if (here(BOTTLE) && here(CASK)) {
-	    rspeak(315);
-	    return;
-	}
-	iobj = object;
-	if (here(BOTTLE)) {
-	    object = BOTTLE;
-	    if (holding(BOTTLE))
-		vfill();
-	    else
-		rspeak(312);
-	    return;
-	} else if (here(CASK)) {
-	    object = CASK;
-	    if (holding(CASK))
-		vfill();
-	    else
-		rspeak(312);
-	    return;
-	} else {
-	    rspeak(312);
-	    return;
-	}
-    }
-    if (object != BEAR && ((burden(0) + burden(object)) > 15)) {
-	if (wearng(object)) {
-	    g.prop[object] = 0;
-	    bitoff(object, WEARBT);
-	}
-	rspeak(92);
-	return;
-    }
-    if (prep == PREPFR || enclosed(object)) {
-	vextract();
-	return;
-    }
-    msg = 343;
-    /* Poster: hides wall safe */
-    if (object == POSTER && g.place[SAFE] == 0) {
-	g.prop[POSTER] = 1;
-	msg = 362;
-	/* Move safe and wall containing safe into view */
-	drop(SAFE, g.loc);
-	drop(WALL2, g.loc);
-    }
-    /* Boat: need the pole to push it */
-    if (object == BOAT) {
-	if (!toting(POLE) && g.place[POLE] != -BOAT) {
-	    rspeak(218);
-	    return;
-	} else {
-	    g.prop[BOAT] = 1;
-	    msg = 221;
-	}
-    }
-    /* Special case for bird. */
-    if (object == BIRD && g.prop[BIRD] <= 0) {
-	if (athand(ROD)) {
-	    rspeak(26);
-	    return;
-	}
-	if (!holding(CAGE)) {
-	    rspeak(27);
-	    return;
-	}
-	if (!ajar(CAGE)) {
-	    rspeak(358);
-	    return;
-	}
-	insert(BIRD, CAGE);
-	bitoff(CAGE, OPENBT);
-	pspeak(object, -1);
-	rspeak(54);
-	return;
-    }
-    /* SWORD If in anvil, need crown & must yank */
-    if (object == SWORD && g.prop[SWORD] != 0) {
-	if (iobj && iobj != ANVIL) {
-	    rspeak(noway());
-	    return;
-	}
-	if (verb != YANK)
-	    if (!yes(215, 0, 54))
-		return;
-
-	if (!wearng(CROWN)) {
-	    g.fixed[SWORD] = -1;
-	    g.prop[SWORD] = 3;
-	    pspeak(SWORD, 2);
-	    return;
-	}
-    }
-    carry(object, g.loc);
-    if (object == POLE || object == SKEY || object == SWORD
-	 || ((object == CLOAK || object == RING) && !wearng(object)) )
-	g.prop[object] = 0;
-
-    if (verb == YANK || object == SWORD)
-	msg = 204;
-    rspeak(msg);
-    return;
-}
-
-static int ck_obj()
-{
-    int msg;
-
-    msg = noway();
-    if (object == PLANT && g.prop[PLANT] <= 0)
-	msg = 115;
-    if (object == BEAR && g.prop[BEAR] == 1)
-	msg = 169;
-    if (object == CHAIN && g.prop[BEAR] != 0)
-	msg = 170;
-    if (object == SWORD && g.prop[SWORD] == 5)
-	msg = 208;
-    if (object == CLOAK && g.prop[CLOAK] == 2)
-	msg = 242;
-    if (object == AXE && g.prop[AXE] == 2)
-	msg = 246;
-    if (object == PHONE)
-	msg = 251;
-    if (object == BEES || object == HIVE)
-	msg = 295;
-    if (object == STICKS)
-	msg = 296;
-    return (msg);
-}
-
-/*
-  DROP etc.
-*/
-void vdrop()
-{
-    int msg;
-
-    /* Check for dynamite */
-    if (holding(ROD2) && object == ROD && !holding(ROD))
-	object = ROD2;
-    if (plural(object))
-	msg = 105;
-    else
-	msg = 29;
-
-    if (object == liq(BOTTLE))
-	object = BOTTLE;
-    else if (object == liq(CASK))
-	object = CASK;
-
-    if (!toting(object)) {
-	rspeak(msg);
-	return;
-    }
-    if (prep == PREPIN) {
-	vinsert();
-	return;
-    }
-    /* Snake and bird */
-    if (object == BIRD && here(SNAKE)) {
-	rspeak(30);
-	if (g.closed) {
-	    dwarfend();
-	    return;
-	}
-	extract(BIRD);
-	destroy(SNAKE);
-	/* Set snake prop for use by travel options */
-	g.prop[SNAKE] = 1;
-	drop(BIRD, g.loc);
-	return;
-    }
-    msg = 344;
-    if (verb == LEAVE)
-	msg = 353;
-    if (verb == THROW)
-	msg = 352;
-    if (verb == TAKE)
-	msg = 54;
-    if (object == POLE && holding(BOAT)) {
-	rspeak(280);
-	return;
-    }
-    /* Coins and vending machine */
-    if (object == COINS && here(VEND)) {
-	destroy(COINS);
-	drop(BATTERIES, g.loc);
-	pspeak(BATTERIES, 0);
-	return;
-    }
-    /* Bird and dragon (ouch!!) */
-    if (object == BIRD && at(DRAGON) && g.prop[DRAGON] == 0) {
-	rspeak(154);
-	extract(BIRD);
-	destroy(BIRD);
-	if (g.place[SNAKE] == plac[SNAKE])
-	    g.tally2++;
-	return;
-    }
-    /* Bear and troll */
-    if (object == BEAR && at(TROLL)) {
-	msg = 163;
-	destroy(TROLL);
-	destroy(TROLL + MAXOBJ);
-	move(TROLL2, plac[TROLL]);
-	move((TROLL2 + MAXOBJ), fixd[TROLL]);
-	juggle(CHASM);
-	g.prop[TROLL] = 2;
-    }
-    /* Vase */
-    else if (object == VASE) {
-	if (g.loc == plac[PILLOW])
-	    msg = 54;
-	else {
-	    g.prop[VASE] = at(PILLOW) ? 0 : 2;
-	    pspeak(VASE, g.prop[VASE] + 1);
-	    if (g.prop[VASE] != 0)
-		g.fixed[VASE] = -1;
-	}
-    } else {
-	if (worn(object) || object == POLE || object == BOAT)
-	    g.prop[object] = 0;
-	if (worn(object))
-	    bitoff(object, WEARBT);
-	if (object == POLE)
-	    g.prop[BOAT] = 0;
-    }
-
-    if (enclosed(object))
-	extract(object);
-    drop(object, g.loc);
-    rspeak(msg);
-    return;
-}
-
-/*
-  OPEN. special stuff for opening clam/oyster.
-  The following can be opened without a key:
-  clam/oyster, door, pdoor, bottle, cask, cage
-*/
-void vopen()
-{
-    int msg, oyclam;
-
-    if (!hinged(object))
-	msg = noway();
-    else if (object == PDOOR && g.prop[PDOOR] == 1)
-	msg = 253;
-    else if (ajar(object))
-	msg = 336;
-    else if (locks(object) || iobj == KEYS || iobj == SKEY) {
-	vunlock();
-	return;
-    } else if (locked(object))
-	if (object == DOOR)
-	    msg = 111;
-	else
-	    msg = 337;
-    else if (object == CLAM || object == OYSTER) {
-	oyclam = (object == OYSTER ? 1 : 0);
-	msg = oyclam + holding(object) ? 120 : 124;
-	if (!athand(TRIDENT))
-	    msg = 122 + oyclam;
-	if (iobj != 0 && iobj != TRIDENT)
-	    msg = 376 + oyclam;
-
-	if (msg == 124) {
-	    destroy(CLAM);
-	    drop(OYSTER, g.loc);
-	    drop(PEARL, 105);
-	}
-    } else {
-	msg = 54;
-	biton(object, OPENBT);
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-   close, shut
-   the following can be closed without keys:
-   door, pdoor, bottle, cask, cage
-*/
-void vclose()
-{
-    if (!hinged(object))
-	rspeak(noway());
-    else if (!ajar(object))
-	rspeak(338);
-    else if (locks(object))
-	vlock();
-    else {
-	rspeak(54);
-	bitoff(object, OPENBT);
-    }
-}
-
-/*
-  Lamp ON.
-*/
-void von()
-{
-    if (!athand(LAMP))
-	actspk(verb);
-    else if (g.limit < 0)
-	rspeak(184);
-    else if (g.prop[LAMP] == 1)
-	rspeak(321);
-    else {
-	g.prop[LAMP] = 1;
-	if (g.loc == 200)
-	    rspeak(108);
-	else
-	    rspeak(39);
-	if (g.wzdark) {
-	    g.wzdark = 0;
-	    describe();
-	    descitem();
-	}
-    }
-    return;
-}
-
-/*
-  Lamp OFF.
-*/
-void voff()
-{
-    if (!athand(LAMP))
-	actspk(verb);
-    else if (g.prop[LAMP] == 0)
-	rspeak(322);
-    else {
-	g.prop[LAMP] = 0;
-	rspeak(40);
-	if (dark())
-	    rspeak(16);
-    }
-    return;
-}
-
-/*
-  WAVE. no effect unless waving rod at fissure.
-*/
-void vwave()
-{
-    if (!holding(object) &&
-	(object != ROD || !holding(ROD2)))
-	rspeak(29);
-    else if (object != ROD || !at(FISSURE) ||
-	     !holding(object) || g.closing)
-	actspk(verb);
-    else if (iobj != 0 && iobj != FISSURE)
-	actspk(verb);
-    else {
-	g.prop[FISSURE] = 1 - g.prop[FISSURE];
-	pspeak(FISSURE, 2 - g.prop[FISSURE]);
-	if (g.chase == 0 || g.prop[FISSURE] != 0)
-	    return;
-	if ((g.loc == 17 && g.oldloc != 27)
-	    || (g.loc == 27 && g.oldloc != 17))
-	    return;
-	/* Demise of the Wumpus.  Champ must have just crossed bridge */
-	rspeak(244);
-	g.chase = 0;
-	drop(RING, 209);
-	g.prop[WUMPUS] = 6;
-	move(WUMPUS, 209);
-	biton(WUMPUS, DEADBT);
-	if (g.place[AXE] != plac[WUMPUS])
-	    return;
-	g.fixed[AXE] = 0;
-	g.prop[AXE] = 0;
-
-    }
-    return;
-}
-
-/*
-  ATTACK, KILL etc.
-*/
-void vkill()
-{
-    int msg, i, k;
-    boolean survival;
-
-    survival = TRUE;
-    switch (object) {
-    case BIRD:
-	if (g.closed)
-	    msg = 137;
-	else {
-	    destroy(BIRD);
-	    g.prop[BIRD] = 0;
-	    if (g.place[SNAKE] == plac[SNAKE])
-		g.tally2++;
-	    msg = 45;
-	}
-	break;
-    case DWARF:
-	if (g.closed) {
-	    dwarfend();
-	    return;
-	}
-	survival = do_battle(&msg);
-	break;
-    case 0:
-	msg = 44;
-	break;
-    case CLAM:
-    case OYSTER:
-	msg = 150;
-	break;
-    case DOG:
-	if (g.prop[DOG] == 1)
-	    msg = 291;
-	else if (iobj == AXE) {
-	    object = AXE;
-	    iobj = DOG;
-	    vthrow();
-	    return;
-	} else
-	    msg = 110;
-	break;
-    case SNAKE:
-	msg = 46;
-	break;
-    case TROLL:
-	if (iobj == AXE)
-	    msg = 158;
-	else
-	    msg = 110;
-	break;
-    case BEAR:
-	msg = 165 + (g.prop[BEAR] + 1) / 2;
-	break;
-    case WUMPUS:
-	if (g.prop[WUMPUS] == 6)
-	    msg = 167;
-	else if (iobj == AXE) {
-	    object = AXE;
-	    iobj = WUMPUS;
-	    vthrow();
-	    return;
-	} else
-	    msg = 110;
-	break;
-    case GNOME:
-	msg = 320;
-	break;
-    case DRAGON:
-	if (g.prop[DRAGON] != 0) {
-	    msg = 167;
-	    break;
-	}
-	if (!yes(49, 0, 0))
-	    break;
-	pspeak(DRAGON, 1);
-	biton(DRAGON, DEADBT);
-	g.prop[DRAGON] = 2;
-	g.prop[RUG] = 0;
-	k = (plac[DRAGON] + fixd[DRAGON]) / 2;
-	move((DRAGON + MAXOBJ), -1);
-	move((RUG + MAXOBJ), 0);
-	move(DRAGON, k);
-	move(RUG, k);
-	for (i = 1; i < MAXOBJ; i++)
-	    if (g.place[i] == plac[DRAGON]
-		|| g.place[i] == fixd[DRAGON]
-		|| holding(i))
-		move(i, k);
-	g.loc = k;
-	g.newloc = k;
-	return;
-    default:
-	actspk(verb);
-	return;
-    }
-    rspeak(msg);
-    if (!survival) {
-	g.oldloc2 = g.loc;
-	death();
-    }
-    return;
-}
-
-static boolean do_battle(msg_ptr)
-int *msg_ptr;
-{
-    boolean survival;
-    int temp;
-
-    survival = TRUE;
-    if (iobj == 0)
-	*msg_ptr = 49;
-    else if (iobj != AXE && iobj != SWORD) {
-	*msg_ptr = 355;
-	survival = FALSE;
-    } else if (pct(25)) {
-	temp = iobj;
-	iobj = object;
-	object = temp;
-	vthrow();
-	return (TRUE);
-    } else if (pct(25)) {
-	*msg_ptr = 355;
-	survival = FALSE;
-    } else if (pct(36))
-	*msg_ptr = 354;
-    else {
-	rspeak(356);
-	if (pct(61))
-	    *msg_ptr = 52;
-	else {
-	    *msg_ptr = 53;
-	    survival = FALSE;
-	}
-    }
-    return (survival);
-}
-
-/*
-  POUR
-*/
-void vpour()
-{
-    int msg;
-
-    if (object == BOTTLE || object == CASK) {
-	iobj = object;
-	object = liq(iobj);
-	if (object == 0) {
-	    rspeak(316);
-	    return;
-	}
-    } else {
-	if (object < WATER || object > (WINE + 1)) {
-	    rspeak(78);
-	    return;
-	}
-    }
-    if (!holding(BOTTLE) && !holding(CASK)) {
-	rspeak(29);
-	return;
-    }
-    if (holding(BOTTLE) && liq(BOTTLE) == object)
-	iobj = BOTTLE;
-    if (holding(CASK) && liq(CASK) == object)
-	iobj = CASK;
-    if (iobj == 0) {
-	rspeak(29);
-	return;
-    }
-    if (!ajar(iobj)) {
-	rspeak(335);
-	return;
-    }
-    if (iobj == CASK)
-	object++;
-    g.prop[iobj] = 1;
-    extract(object);
-    g.place[object] = 0;
-    msg = 77;
-    if (iobj == CASK) {
-	object--;
-	msg = 104;
-    }
-    if (at(PLANT) || at(DOOR) || (at(SWORD) && g.prop[SWORD] != 0)) {
-	if (at(DOOR)) {
-	    g.prop[DOOR] = 0;
-	    if (object == OIL) {
-		g.prop[DOOR] = 1;
-		bitoff(DOOR, LOCKBT);
-		biton(DOOR, OPENBT);
-	    }
-	    msg = 113 + g.prop[DOOR];
-	} else if (at(SWORD)) {
-	    /* If sword is alread oily, don't let him clean it. No
-	       soap. */
-	    if (g.prop[SWORD] != 5) {
-		g.prop[SWORD] = 4;
-		if (object == OIL) {
-		    g.prop[SWORD] = 5;
-		    g.fixed[SWORD] = -1;
-		}
-		msg = 206 + g.prop[SWORD] - 4;
-	    }
-	} else {
-	    msg = 112;
-	    if (object == WATER) {
-		if (g.prop[PLANT] < 0)
-		    g.prop[PLANT] = -g.prop[PLANT] - 1;
-		pspeak(PLANT, g.prop[PLANT] + 1);
-		g.prop[PLANT] = (g.prop[PLANT] + 2) % 6;
-		g.prop[PLANT2] = g.prop[PLANT] / 2;
-		newtravel = TRUE;
-		return;
-	    }
-	}
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-  EAT
-  If he ate the right thing and is in the right place, move him to
-  the other place with all his junk.  Otherwise, narky message.
-*/
-void veat()
-{
-    int msg, i, k, ll, kk;
-
-    switch (object) {
-    case HONEY:
-	g.tally2++;
-    case FOOD:
-	destroy(object);
-	msg = 72;
-	break;
-    case BIRD:
-    case SNAKE:
-    case CLAM:
-    case OYSTER:
-    case FLOWER:
-	msg = 301;
-	break;
-    case DWARF:
-    case DRAGON:
-    case TROLL:
-    case DOG:
-    case WUMPUS:
-    case BEAR:
-    case GNOME:
-	msg = 250;
-	break;
-    case MUSHRM:
-    case CAKES:
-	k = object - MUSHRM;
-	ll = 229 + k;
-	k = 159 - k;
-	kk = SKEY;
-	if (object == MUSHRM) {
-	    kk = TDOOR;
-	    if (g.loc != 158)
-		g.tally2++;
-	}
-	destroy(object);
-	msg = 228;
-	if (!(here(kk) || g.fixed[kk] == g.loc))
-	    break;
-	msg = ll;
-	/* If he hasn't taken tiny key off shelf, don't let him get it
-	   for free! */
-	for (i = 1; i < MAXOBJ; i++) {
-	    if (i == SKEY && g.prop[SKEY] == 1)
-		continue;
-	    if (g.place[i] == plac[kk] && g.fixed[i] == 0)
-		move(i, k);
-	}
-	if (g.loc == plac[SKEY] && g.place[SKEY] == plac[SKEY])
-	    g.tally2++;
-	g.loc = k;
-	g.newloc = k;
-	newtravel = TRUE;
-	break;
-    default:
-	actspk(verb);
-	return;
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-  DRINK
-*/
-void vdrink()
-{
-    int msg, k, j;
-
-    if (object == 0 && (iobj == BOTTLE || iobj == CASK))
-	object = liq(iobj);
-    msg = 110;
-    if (object == OIL)
-	msg = 301;
-    if (object != WATER && object != WINE) {
-	rspeak(msg);
-	return;
-    }
-    if (iobj == 0) {
-	if (object == liqloc(g.loc))
-	    iobj = -1;
-	if (athand(CASK) && object == liq(CASK))
-	    iobj = CASK;
-	if (athand(BOTTLE) && object == liq(BOTTLE))
-	    iobj = BOTTLE;
-    }
-    msg = 73;
-    if (iobj != -1) {
-	if (iobj == CASK)
-	    object++;
-	extract(object);
-	g.place[object] = 0;
-	g.prop[iobj] = 1;
-	msg = (iobj == CASK) ? 299 : 74;
-    }
-    if (object == WATER || object == (WATER + 1)) {
-	rspeak(msg);
-	return;
-    }
-    /* UH-OH. He's a wino. Let him reap the rewards of incontinence.
-       He'll wander around for awhile, then wake up somewhere or other,
-       having dropped most of his stuff. */
-    rspeak(300);
-    if (g.prop[LAMP] == 1)
-	g.limit -= ranz(g.limit) / 2;
-    if (g.limit < 10)
-	g.limit = 25;
-    k = 0;
-    if (pct(15))
-	k = 49;
-    if (k == 0 && pct(15))
-	k = 53;
-    if (k == 0 && pct(25))
-	k = 132;
-    if (k == 0)
-	k = 175;
-    if (outside(g.loc))
-	k = 5;
-    if (k == g.loc) {
-	rspeak(msg);
-	return;
-    }
-    if (holding(AXE))
-	move(AXE, k);
-    if (holding(LAMP))
-	move(LAMP, k);
-    for (j = 1; j < MAXOBJ; j++) {
-	if (wearng(j))
-	    bitoff(j, WEARBT);
-	if (holding(j))
-	    drop(j, g.loc);
-    }
-    g.loc = k;
-    g.newloc = k;
-}
-
-/*
-  THROW etc.
-*/
-void vthrow()
-{
-    int msg, i, k, dwarfn;
-
-    if (holding(ROD2) && object == ROD && !holding(ROD))
-	object = ROD2;
-    if (!holding(object)) {
-	actspk(verb);
-	return;
-    }
-    if (object == BOAT || object == BEAR) {
-	rspeak(noway());
-	return;
-    }
-    dwarfn = dcheck();
-    if (iobj == 0) {
-	/* No indirect object was specified.  If a dwarf is present,
-	   assume it is the object. If not, look for other living
-	   thing. If no living things present, treat 'THROW' as 'DROP'. */
-
-	if (dwarfn)
-	    iobj = DWARF;
-	else {
-	    /* No dwarves present; figure out pausible object. */
-	    k = 0;
-	    for (i = 1; i < MAXOBJ; i++) {
-		if (at(i) && living(i)) {
-		    iobj = i;
-		    k++;
-		}
-	    }
-	    if (k == 0) {
-		vdrop();
-		return;
-	    }
-	    /* It is a beastie of some sort.  Is there more than one?
-	       Don't kill the bird by default. */
-	    if (k > 1) {
-		rspeak(43);
-		return;
-	    } else {
-		if (iobj == BIRD) {
-		    vdrop();
-		    return;
-		}
-		if (treasr(object) && at(TROLL))
-		    iobj = TROLL;
-	    }
-	}
-    }
-    if (object == SWORD || object == BOTTLE) {
-	vbreak();
-	return;
-    }
-    if (object == FLOWER && iobj == HIVE)
-	iobj = BEES;
-    if (edible(object) && living(iobj)) {
-	vfeed();
-	return;
-    }
-    /* If not axe, same as drop... */
-    if (object != AXE && iobj != TROLL) {
-	vdrop();
-	return;
-    }
-    /* AXE is THROWN */
-    msg = 48;
-    switch (iobj) {
-    case DRAGON:
-	if (g.prop[DRAGON] == 0)
-	    msg = 152;
-	break;
-    case DWARF:
-	/* At a dwarf... */
-	if (pct(75)) {
-	    g.dseen[dwarfn] = g.dloc[dwarfn] = 0;
-	    msg = 47;
-	    ++g.dkill;
-	    if (g.dkill == 1)
-		msg = 149;
-	}
-	break;
-    case BEAR:
-	/* This'll teach him to throw axe at the bear */
-	if (g.prop[BEAR] == 0) {
-	    msg = 164;
-	    drop(AXE, g.loc);
-	    g.fixed[AXE] = -1;
-	    g.prop[AXE] = 1;
-	    juggle(BEAR);
-	}
-	rspeak(msg);
-	return;
-    case WUMPUS:
-	/* Or the WUMPUS! */
-	if (g.prop[WUMPUS] == 6) {
-	    vdrop();
-	    return;
-	} else {
-	    msg = 245;
-	    g.prop[AXE] = 2;
-	    if (g.prop[WUMPUS] == 0) {
-		drop(AXE, g.loc);
-		g.fixed[AXE] = -1;
-		juggle(iobj);
-	    } else {
-		msg = 243;
-		destroy(AXE);
-	    }
-	}
-	rspeak(msg);
-	return;
-    case DOG:
-	/* Or the nice doggie! */
-	if (g.prop[DOG] != 1) {
-	    msg = 248;
-	    g.prop[AXE] = 3;
-	    drop(AXE, g.loc);
-	    g.fixed[AXE] = -1;
-	    juggle(iobj);
-	}
-	rspeak(msg);
-	return;
-    case TROLL:
-	/* Snarf a treasure for the troll */
-	if (object == AXE) {
-	    msg = 158;
-	} else if (!treasr(object) ||
-		   (object == CASK && (liq(CASK) != WINE))) {
-	    vdrop();
-	    return;
-	} else {
-	    msg = 159;
-	    drop(object, 0);
-	    if (object == CASK)
-		g.place[WINE + 1] = 0;
-	    move(TROLL, 0);
-	    move((TROLL + MAXOBJ), 0);
-	    drop(TROLL2, plac[TROLL]);
-	    drop((TROLL2 + MAXOBJ), fixd[TROLL]);
-	    juggle(CHASM);
-	    rspeak(msg);
-	    return;
-	}
-	break;
-
-    default:
-	/* Otherwise it is an attack */
-	verb = KILL;
-	object = iobj;
-	iobj = objs[objx];
-	vkill();
-	return;
-    }
-
-    rspeak(msg);
-    drop(AXE, g.loc);
-    g.newloc = g.loc;
-    describe();
-}
-
-/*
-  FIND might be carrying it, or it might be here. else give caveat.
-*/
-void vfind()
-{
-    int msg;
-
-    if (at(object) ||
-	(liq(BOTTLE) == object && at(BOTTLE)) ||
-	object == liqloc(g.loc))
-	msg = 94;
-    else if (dcheck() && g.dflag >= 2 && object == DWARF)
-	msg = 94;
-    else if (g.closed)
-	msg = 138;
-    else if (at(object))
-	msg = 24;
-    else {
-	actspk(verb);
-	return;
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-  FEED
-*/
-void vfeed()
-{
-    int msg;
-
-    if (iobj == 0 || !living(iobj)) {
-	int i, k, kk;
-
-	if (object == BIRD) {
-	    rspeak(100);
-	    return;
-	}
-	if (!living(object)) {
-	    rspeak(noway());
-	    return;
-	}
-	/* See if there is anything edible around here. */
-
-	kk = 0;
-	k = 0;
-	for (i = 1; i < MAXOBJ; i++)
-	    if (here(i) && edible(i)) {
-		k++;
-		kk = i;
-	    }
-	iobj = object;
-	object = kk;
-	if (k != 1 && !dead(iobj)) {
-	    printf("What do you want to feed the %s\n", otxt[objx]);
-	    objs[1] = 0;
-	    objx = 0;
-	    return;
-	}
-    }
-    /* Feed object ot indirect object */
-    msg = 102;
-    switch (iobj) {
-    case DRAGON:
-	if (g.prop[DRAGON] != 0)
-	    msg = noway();
-	break;
-    case TROLL:
-	msg = 182;
-	break;
-    case SNAKE:
-	if (object == BIRD && !g.closed) {
-	    msg = 101;
-	    destroy(BIRD);
-	    g.prop[BIRD] = 0;
-	    g.tally2++;
-	}
-	break;
-    case DWARF:
-	msg = 103;
-	g.dflag++;
-	break;
-    case BEAR:
-	if (g.prop[BEAR] == 3)
-	    msg = noway();
-	if (g.prop[BEAR] == 1 || g.prop[BEAR] == 2)
-	    msg = 264;
-	if (object == FOOD)
-	    msg = 278;
-	if (object == HONEY) {
-	    g.prop[BEAR] = 1;
-	    g.fixed[AXE] = 0;
-	    destroy(HONEY);
-	    msg = 168;
-	}
-	break;
-    case DOG:
-	msg = 291;
-	if (object == FOOD && g.prop[DOG] != 1) {
-	    msg = 249;
-	    destroy(FOOD);
-	}
-	break;
-    case WUMPUS:
-	if (g.prop[WUMPUS] == 6)
-	    msg = 326;
-	if (g.prop[WUMPUS] == 0)
-	    msg = 327;
-	if (object == FOOD)
-	    msg = 240;
-	break;
-    case BEES:
-	if (object == FLOWER) {
-	    if (enclosed(FLOWER))
-		extract(FLOWER);
-	    drop(FLOWER, g.loc);
-	    g.fixed[FLOWER] = -1;
-	    g.prop[FLOWER] = 1;
-	    drop(HONEY, g.loc);
-	    juggle(HONEY);
-	    msg = 267;
-	    g.prop[HIVE] = 1;
-	}
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-  FILL. object with iobj
-*/
-void vfill()
-{
-    int msg, k;
-
-    if (!vessel(object))
-	msg = 313;
-    else {
-	if (iobj == 0)
-	    iobj = liqloc(g.loc);
-	if (object == BOTTLE || object == CASK) {
-	    k = (object == CASK) ? 1 : 0;
-	    msg = 0;
-	    if (iobj == 0)
-		msg = 304 + k;
-	    if (liq(object) != 0)
-		msg = 302 + k;
-	    if (msg != 0) {
-		rspeak(msg);
-		return;
-	    }
-	    msg = 306 + k;
-	    if (iobj == OIL)
-		msg = 308 + k;
-	    if (iobj == WINE)
-		msg = 310 + k;
-	    g.prop[object] = (int) g.loc_attrib[g.loc] & 14;
-	    g.place[iobj + k] = -1;
-	    insert(iobj + k, object);
-	} else if (object == VASE) {
-	    if (iobj == 0 || !holding(VASE)) {
-		rspeak(144);
-		return;
-	    }
-	    msg = 145;
-	    g.prop[VASE] = 2;
-	    g.fixed[VASE] = -1;
-	    if (enclosed(object))
-		extract(object);
-	    drop(object, g.loc);
-	} else if (object == GRAIL)
-	    msg = 298;
-	else
-	    msg = 339;
-    }
-    rspeak(msg);
-}
-
-/*
-  READ. Magazine in dwarvish, message we've seen, and ... oyster?
-*/
-void vread()
-{
-    int msg;
-
-    if (blind()) {
-	actspk(verb);
-	return;
-    }
-    if (object && iobj) {
-	rspeak(confuz());
-	return;
-    }
-    msg = confuz();
-    if (!object)
-	object = iobj;
-    switch (object) {
-    case BOOK:
-    case BOOK2:
-	msg = 142;
-	break;
-    case BILLBD:
-	msg = 361;
-	break;
-    case CARVNG:
-	msg = 372;
-	break;
-    case MAGAZINE:
-	msg = 190;
-	break;
-    case MESSAGE:
-	msg = 191;
-	break;
-    case POSTER:
-	msg = 370;
-	break;
-    case TABLET:
-	msg = 196;
-	break;
-    case OYSTER:
-	if (g.hinted[2] && holding(OYSTER))
-	    msg = 194;
-	if (!g.hinted[2] && holding(OYSTER) && g.closed) {
-	    g.hinted[2] = yes(192, 193, 54);
-	    return;
-	}
-	break;
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-  BREAK. works for mirror in repository and, of course the
-  vase and bottle.  Also the sword is more brittle than it appears.
-*/
-void vbreak()
-{
-    int msg, k;
-    boolean it_broke;
-
-    it_broke = FALSE;
-    msg = 146;
-    switch (object) {
-    case MIRROR:
-	msg = 148;
-	if (g.closed) {
-	    rspeak(197);
-	    dwarfend();
-	    return;
-	}
-	break;
-    case VASE:
-	if (g.prop[VASE] == 0) {
-	    it_broke = TRUE;
-	    msg = 198;
-	    g.prop[VASE] = 2;
-	}
-	break;
-    case BOTTLE:
-	if (g.prop[BOTTLE] != 3) {
-	    it_broke = TRUE;
-	    k = liq(BOTTLE);
-	    msg = 231;
-	    g.prop[BOTTLE] = 3;
-	    if (k) {
-		extract(k);
-		g.place[k] = 0;
-	    }
-	}
-	break;
-    case SWORD:
-	msg = 29;
-	if (holding(SWORD)) {
-	    msg = 279;
-	    g.prop[SWORD] = 4;
-	    it_broke = TRUE;
-	}
-	break;
-    }
-    if (it_broke) {
-	if (enclosed(object))
-	    extract(object);
-	if (holding(object))
-	    drop(object, g.loc);
-	g.fixed[object] = -1;
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-  WAKE. only use is to disturb the dwarves or the Wumpus.
-  Other wumpus-wakers link here.
-*/
-void vwake()
-{
-    int msg;
-
-    msg = actmsg[verb];
-    if (at(WUMPUS)) {
-	g.chase = TRUE;
-	g.prop[WUMPUS] = 1;
-	msg = 276;
-    }
-    if (at(DOG) && g.prop[DOG] == 1)
-	msg = 291;
-    if (object == DWARF && g.closed) {
-	rspeak(199);
-	dwarfend();
-	return;
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-   YANK. A variant of 'CARRY'.  In general, not a good idea.
-   At most, it gets the cloak or a couple of snide comments.
- */
-void vyank()
-{
-    if (toting(object))
-	vdrop();
-    else if (object == BEAR && g.prop[CHAIN])
-	rspeak(205);
-    else if (object == CLOAK && g.prop[CLOAK] == 2) {
-	/* Cloak. big trouble ahead. */
-	g.prop[ROCKS] = 1;
-	g.prop[CLOAK] = 0;
-	g.fixed[CLOAK] = 0;
-	carry(CLOAK, g.loc);
-	rspeak(241);
-	if (at(WUMPUS) && g.prop[WUMPUS] == 0) {
-	    g.chase = 1;
-	    g.prop[WUMPUS] = 1;
-	    rspeak(276);
-	}
-    } else
-	vtake();
-    return;
-}
-
-/*
-   WEAR.  Only good for jewels, ruby slippers, cloak & crown.
-   But he might try the sword.  Anything else is ridiculous.
-   Another variant of 'CARRY'.
- */
-void vwear()
-{
-    int msg;
-
-    if (object == SWORD && g.prop[SWORD] != 3)
-	msg = 209;
-    else if (worn(object)) {
-	if (object == CLOAK && g.prop[CLOAK] == 2)
-	    msg = 242;
-	else if (wearng(object))
-	    msg = (object == SHOES) ? 227 : 210;
-	else {
-	    g.prop[object] = 1;
-	    biton(object, WEARBT);
-	    if (enclosed(object))
-		extract(object);
-	    if (holding(object))
-		msg = 54;
-	    else {
-		vtake();
-		return;
-	    }
-	}
-    } else {
-	printf("Just exactly how does one wear a %s\n", otxt[objx]);
-	return;
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-   HIT. If not punching out telephone, assume attack.
- */
-void vhit()
-{
-    if (at(WUMPUS) && g.prop[WUMPUS] == 0) {
-	vwake();
-	return;
-    }
-    if (object != PHONE) {
-	vkill();
-	return;
-    } else {
-	if (g.closed) {
-	    rspeak(282);
-	    dwarfend();
-	    return;
-	}
-	if (g.prop[PHONE] == 2)
-	    rspeak(256);
-	else {
-	    drop(SLUGS, g.loc);
-	    g.prop[PHONE] = 2;
-	    g.prop[BOOTH] = 2;
-	    rspeak(257);
-	}
-    }
-    return;
-}
-
-/*
-   ANSWER (telephone). Smartass for anything else.
- */
-void vanswer()
-{
-    int msg;
-
-    switch (object) {
-    case DWARF:
-    case WUMPUS:
-    case SNAKE:
-    case BEAR:
-    case DRAGON:
-	msg = 259;
-	break;
-    case TROLL:
-	msg = 258;
-	break;
-    case BIRD:
-	msg = 260;
-	break;
-    case PHONE:
-	if (g.prop[PHONE] != 0)
-	    msg = 269;
-	else if (g.closed) {
-	    rspeak(283);
-	    normend();
-	    return;
-	} else {
-	    msg = 261;
-	    g.prop[PHONE] = 1;
-	    g.prop[BOOTH] = 2;
-	}
-	break;
-    default:
-	msg = actmsg[verb];
-	break;
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-   BLOW. Joshua fit de battle of Jericho, and de walls ...
- */
-void vblow()
-{
-    int msg, i, k;
-
-    msg = actmsg[verb];
-    if (object != 0 && iobj != 0) {
-	rspeak(msg);
-	return;
-    }
-    if (object == 0)
-	object = iobj;
-    iobj = 0;
-    if (object == 0)
-	msg = 268;
-    if (object == HORN) {
-	msg = outside(g.loc) ? 277 : 266;
-	if (at(WUMPUS)) {
-	    rspeak(msg);
-	    if (g.prop[WUMPUS] == 0)
-		vwake();
-	    return;
-	} else if (g.prop[WALL] != 1 && (g.loc == 102 || g.loc == 194)) {
-	    k = g.loc == 194 ? 195 : 196;
-	    msg = 265;
-	    g.prop[WALL] = 1;
-	    for (i = 1; i < MAXOBJ; i++)
-		if (g.place[i] == g.loc || g.fixed[i] == g.loc)
-		    move(i, k);
-	    g.newloc = k;
-	}
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-   DIAL. No effect unless at phone.
- */
-void vdial()
-{
-    if (object != PHONE)
-	actspk(verb);
-    else if (g.closed) {
-	rspeak(283);
-	normend();
-    } else
-	rspeak(271);
-    return;
-}
-
-/*
-   PLAY.  Only for horn or lyre.
- */
-void vplay()
-{
-    int msg;
-
-    msg = actmsg[verb];
-    if (object != 0 && iobj != 0) {
-	rspeak(confuz());
-	return;
-    }
-    if (object == 0)
-	object = iobj;
-    if (object == HORN) {
-	vblow();
-	return;
-    }
-    if (object == LYRE) {
-	msg = 287;
-	if (here(DOG) && !dead(DOG)) {
-	    g.prop[DOG] = 1;
-	    biton(DOG, DEADBT);
-	    g.fixed[AXE] = 0;
-	    g.prop[AXE] = 0;
-	    msg = 288;
-	}
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-   PICK/ PICK UP.  Can pick flower & mushrooms,
-   But must 'PICK UP' everything else.
- */
-void vpick()
-{
-    if (object == 0)
-	object = iobj;
-    iobj = 0;
-    if (object == FLOWER || object == MUSHRM || prep != 0)
-	vtake();
-    else
-	rspeak(confuz());
-    return;
-}
-
-/*
-   PUT DOWN: equivalent to drop
-   PUT IN: if liquid, means fill
-   PUT ON: wear of drop
- */
-void vput()
-{
-    if (prep == 0) {
-	printf("Where do you want to put the %s\n", otxt[objx]);
-	return;
-    }
-    if (prep == PREPIN)
-	vinsert();
-    else {
-	/* PUT ON: wear or put object on iobj */
-	if (prep == PREPON) {
-	    if (object == 0) {
-		object = iobj;
-		otxt[objx] = iotxt[iobx];
-		iobj = 0;
-	    }
-	    if (worn(object) || object == 0)
-		vwear();
-	    else
-		vdrop();
-	} else {
-	    /* PUT DOWN: "drop" */
-	    if (object == 0 && iobj == 0) {
-		if (object == 0)
-		    object = iobj;
-		iobj = 0;
-		vdrop();
-	    } else
-		rspeak(noway());
-	}
-    }
-    return;
-}
-
-/* turn on/off */
-void vturn()
-{
-    if (!prep)
-	rspeak(confuz());
-    else {
-	if (!object && iobj == LAMP)
-	    object = LAMP;
-	if (object != LAMP)
-	    rspeak(noway());
-	else if (prep == PREPON)
-	    von();
-	else
-	    voff();
-    }
-    return;
-}
-
-/*
-   GET (no prep): "take"
-   GET IN: "enter"
-   GET OUT: "leave"
- */
-void vget()
-{
-    if (prep == 0 || prep == PREPFR)
-	vtake();
-    else if (object == 0) {
-	object = iobj;
-	iobj = 0;
-	prep = 0;
-	vtake();
-    }
-    return;
-}
-
-/*
-   INSERT/PUT IN
- */
-void vinsert()
-{
-    int msg;
-
-    if (iobj == 0) {
-	printf("Where do you want to %s it?\n", vtxt[vrbx]);
-	return;
-    }
-    msg = noway();
-    if (object == SWORD && iobj == ANVIL && g.prop[SWORD] == 0)
-	msg = 350;
-    if (!vessel(iobj)) {
-	rspeak(msg);
-	return;
-    }
-    msg = ck_obj();
-    if (g.fixed[object]) {
-	rspeak(msg);
-	return;
-    }
-    if (object == iobj) {
-	rspeak(252);
-	return;
-    }
-    if (iobj == BOTTLE || iobj == CASK || iobj == VASE
-	|| iobj == GRAIL || (object >= WATER && object <= WINE + 1)) {
-	object = iobj;
-	iobj = objs[objx];
-	vfill();
-	return;
-    }
-    if (!ajar(iobj)) {
-	rspeak(358);
-	return;
-    }
-    if (iobj == CHEST) {
-	if (object == BOAT)
-	    msg = noway();
-	else {
-	    if (wearng(object))
-		bitoff(object, WEARBT);
-	    if (worn(object))
-		g.prop[object] = 0;
-	    if (enclosed(object))
-		extract(object);
-	    insert(object, iobj);
-	    msg = 54;
-	}
-	rspeak(msg);
-	return;
-    }
-    /* Bird goes into cage and only cage */
-    if (object == BIRD && iobj != CAGE) {
-	rspeak(351);
-	return;
-    }
-    if (object != BIRD && iobj == CAGE) {
-	rspeak(329);
-	return;
-    }
-    if (object == BIRD) {
-	prep = 0;
-	vtake();
-	return;
-    }
-    /* Bar vase & pillow from safe, to force putting down on florr */
-    if ((object == VASE || object == PILLOW) && iobj == SAFE) {
-	rspeak(329);
-	return;
-    }
-    if (object != RADIUM && iobj == SHIELD) {
-	rspeak(329);
-	return;
-    }
-    if (iobj == PHONE) {
-	if (object == COINS || object == SLUGS) {
-	    destroy(object);
-	    msg = 330;
-	} else
-	    msg = 329;
-	rspeak(msg);
-	return;
-    }
-    if (iobj == VEND) {
-	if (object == COINS || object == SLUGS) {
-	    destroy(object);
-	    move(BATTERIES, g.loc);
-	    if (g.prop[BATTERIES] == 1) {
-		rspeak(317);
-		g.prop[VEND] = 1;
-	    }
-	    g.prop[BATTERIES] = 0;
-	    pspeak(BATTERIES, 0);
-	} else
-	    rspeak(noway());
-	return;
-    }
-    /* Put batteries in lamp. There is a glitch here, in that if he
-       tries to get a third set of batteries before the second set has
-       been inserted, the second set disappears!
-       ***fix this some time ***
-     */
-    if (iobj == LAMP) {
-	if (object != BATTERIES || g.prop[BATTERIES] != 0)
-	    msg = noway();
-	else {
-	    g.prop[BATTERIES] = 1;
-	    if (enclosed(BATTERIES))
-		extract(BATTERIES);
-	    if (holding(BATTERIES))
-		drop(BATTERIES, g.loc);
-	    g.limit = 400;
-	    g.prop[LAMP] = 1;
-	    g.lmwarn = FALSE;
-	    msg = 188;
-	}
-	rspeak(msg);
-	return;
-    }
-    if (!small(object))
-	msg = 329;
-    else {
-	if (wearng(object))
-	    bitoff(object, WEARBT);
-	if (worn(object))
-	    g.prop[object] = 0;
-	if (enclosed(object))
-	    extract(object);
-	insert(object, iobj);
-	msg = 54;
-    }
-    rspeak(msg);
-    return;
-
-}
-
-/* Remove or take from */
-void vextract()
-{
-    int msg;
-
-    if (object == RING && g.prop[RING] == 2) {
-	prep = 0;
-	iobj = 0;
-	vtake();
-	return;
-    }
-    msg = 343;
-    if (iobj == 0) {
-	if (!enclosed(object))
-	    msg = 340;
-	iobj = -g.place[object];
-    }
-    if (g.place[object] != -iobj)
-	msg = 341;
-    if (!ajar(iobj))
-	msg = 335;
-    if (object == WATER || object == OIL || object == WINE)
-	msg = 342;
-    if (!toting(object) && ((burden(0) + burden(object)) > 15))
-	msg = 92;
-    if (msg == 343) {
-	if (object == BIRD) {
-	    vdrop();
-	    return;
-	}
-	extract(object);
-    }
-    rspeak(msg);
-    return;
-}
-
-/*
-   lock. chain, grate, chest, elfin door
-   Here are the current lock/unlock messages & numbers:
-   31	you have no keys.
-   32	it has no lock.
-   34	it's already locked.
-   35	the grate is now locked.
-   36	the grate is now unlocked.
-   37	it was allready unlocked.
-   55	you can't unlock the keys.
-   171	The chain is now unlocked.
-   172	The chain is now locked.
-   173	There is nothing here to which the chain can be locked.
-   224	Your keys are all too large.
-   234	The wrought-iron door is now locked.
-   235	The tiny door is now locked.
-   236	The wrought-iron door is now unlocked.
-   237	The tiny door is now unlocked.
-   375	You don't have the right key.
-   333	the chest is now locked.
-   334	the chest is now unlocked.
-   367	The safe's door swings shut.
-*/
-void vlock()
-{
-    int msg, k;
-
-    if (!hinged(object))
-    {
-	printf("I don't know how to lock or unlock the %s\n",
-	       otxt[objx]);
-	return;
-    }
-    else if (!locks(object))
-	msg = 32;
-    else if (locked(object))
-	msg = 34;
-    else if (!athand(KEYS) && !athand(SKEY) && object != SAFE)
-	msg = 31;
-    else {
-	msg = 375;
-	switch (object) {
-	case CHAIN:
-	    if (!athand(KEYS))
-		break;
-	    msg = 173;
-	    if (g.loc != plac[CHAIN])
-		break;
-	    msg = 172;
-	    g.prop[CHAIN] = 2;
-	    if (enclosed(CHAIN))
-		extract(CHAIN);
-	    if (holding(CHAIN))
-		drop(CHAIN, g.loc);
-	    g.fixed[CHAIN] = -1;
-	    biton(CHAIN, LOCKBT);
-	    bitoff(CHAIN, OPENBT);
-	    break;
-
-	case CHEST:
-	    if (!athand(KEYS))
-		break;
-	    msg = 334;
-	    biton(CHEST, LOCKBT);
-	    bitoff(CHEST, OPENBT);
-	    break;
-
-	case TDOOR:
-	case TDOOR2:
-	    msg = 224;
-	    if (!toting(SKEY))
-		break;
-	    g.prop[TDOOR] = 0;
-	    g.prop[TDOOR2] = 0;
-	    msg = 234 + (TDOOR2 - object);
-	    k = TDOOR + TDOOR2 - object;
-	    biton(k, LOCKBT);
-	    bitoff(k, OPENBT);
-	    biton(object, LOCKBT);
-	    bitoff(object, OPENBT);
-	    break;
-
-	case GRATE:
-	    if (!athand(KEYS))
-		break;
-	    g.prop[GRATE] = 0;
-	    msg = 35;
-	    biton(GRATE, LOCKBT);
-	    bitoff(GRATE, OPENBT);
-	    break;
-
-	case SAFE:
-	    g.prop[SAFE] = 0;
-	    msg = 367;
-	    biton(SAFE, LOCKBT);
-	    bitoff(SAFE, OPENBT);
-	    break;
-
-	}
-    }
-    rspeak(msg);
-}
-
-/*
-   UNLOCK. chain, grate, chest, elfin door.
-*/
-void vunlock()
-{
-    int msg, k;
-
-    if (object == KEYS || object == SKEY)
-	msg = 55;
-    else if (!hinged(object))
-    {
-	printf("I don't know how to lock or unlock the %s\n",
-	       otxt[objx]);
-	return;
-    }
-    else if (!locked(object))
-	msg = 37;
-    else if (!locks(object))
-	msg = 32;
-    else if (object == SAFE) {
-	if (iobj == KEYS || iobj == SKEY)
-	    msg = 368;
-	else
-	    msg = 342;
-    } else if (!athand(KEYS) && !athand(SKEY))
-	msg = 31;
-    else {
-	msg = 375;
-	switch (object) {
-	case CHAIN:
-	    if (!athand(KEYS))
-		break;
-	    if (g.prop[BEAR] == 0)
-		msg = 41;
-	    else {
-		msg = 171;
-		g.prop[CHAIN] = 0;
-		g.fixed[CHAIN] = 0;
-		if (g.prop[BEAR] != 3)
-		    g.prop[BEAR] = 2;
-		g.fixed[BEAR] = 2 - g.prop[BEAR];
-		bitoff(CHAIN, LOCKBT);
-		biton(CHAIN, OPENBT);
-	    }
-	    break;
-	case CHEST:
-	    if (athand(KEYS)) {
-		msg = 333;
-		bitoff(CHEST, LOCKBT);
-		biton(CHEST, OPENBT);
-	    }
-	    break;
-	case TDOOR:
-	case TDOOR2:
-	    /* Elvin door stuff to lock/unlock tiny door w/special key.
-	       the damn thing is really at four places, and we want the
-	       right messages if he only has 'BIG'keys (or no keys).
-	       Also, he can unlock it either while he is big or small. */
-	    msg = 224;
-	    if (!athand(SKEY))
-		break;
-	    if (g.closing) {
-		msg = 130;
-		if (!g.panic)
-		    g.clock2 = 15;
-		g.panic = TRUE;
-	    } else {
-		g.prop[TDOOR] = 1;
-		g.prop[TDOOR2] = 1;
-		msg = 234 + 2 + (TDOOR2 - object);
-		k = TDOOR + (TDOOR2 - object);
-		bitoff(k, LOCKBT);
-		biton(k, OPENBT);
-		bitoff(object, LOCKBT);
-		biton(object, OPENBT);
-	    }
-	    break;
-	case GRATE:
-	    if (!athand(KEYS))
-		break;
-	    if (g.closing) {
-		msg = 130;
-		if (!g.panic)
-		    g.clock2 = 15;
-		g.panic = TRUE;
-	    } else {
-		g.prop[GRATE] = 1;
-		msg = 36;
-		bitoff(GRATE, LOCKBT);
-		biton(GRATE, OPENBT);
-	    }
-	    break;
-	default:
-	    msg = 33;
-	}
-    }
-    rspeak(msg);
-}
-
-/*
-   LOOK.
-*/
-void vlook()
-{
-    int sloc;
-
-    if (object != 0) {
-	rspeak(confuz());
-	return;
-    }
-    /* Look into something (a container). */
-    if (vessel(iobj)) {
-	if (!ajar(iobj) && opaque(iobj))
-	    rspeak(actmsg[verb]);
-	else if (g.holder[iobj] == 0)
-	    rspeak(359);
-	else {
-	    putchar(' ');
-	    lookin(iobj);
-	}
-
-	/* Look at something. If written, read it. */
-    } else if (printed(iobj)) {
-	object = iobj;
-	iobj = 0;
-	vread();
-    } else if (iobj == SPHERE) {
-	if (!inside(g.loc) || athand(SAPPHIRE))
-	    rspeak(42);
-	else {
-	    rspeak(400);
-	    printf("  ");
-	    sloc = g.place[SAPPHIRE];
-	    if ((g.loc_attrib[sloc] % 2 == 0 || enclosed(SAPPHIRE))
-		&& sloc != 200
-		&& !g.place[LAMP] == sloc && g.prop[LAMP] != 0)
-		rspeak(401);
-	    else
-		desclg(sloc);
-	    if (sloc == 239 && !g.flg239) {
-		rspeak(403);
-		g.flg239 = TRUE;
-	    }
-	    printf("  ");
-	    rspeak(402);
-	}
-    } else
-	printf("I see nothing special about the %s?\n", iotxt[iobx]);
-    return;
-}
Index: trunk/minix/commands/advent/vocab.c
===================================================================
--- trunk/minix/commands/advent/vocab.c	(revision 9)
+++ 	(revision )
@@ -1,594 +1,0 @@
-
-/*
-  look-up vocabulary word in lex-ordered table.  words may have
-  two entries with different codes. if minimum acceptable type
-  = 0, then return minimum of different codes.  last word CANNOT
-  have two entries(due to binary sort).
-  word is the word to look up.
-  type  is the minimum acceptable value,
-  if != 0 return %1000
-*/
-
-#include	<string.h>
-#include	<stdio.h>
-#include	"advent.h"
-#include	"advdec.h"
-
-static _CONST struct wac wc[] = {
-				      "\"spelunker\"", 1016,
-				      "22", 2053,
-				      "22", 3012,
-				      "34", 2053,
-				      "34", 3013,
-				      "4-leafed", 5034,
-				      "7", 2053,
-				      "7", 3011,
-				      "?", 3051,
-				      "above", 29,
-				      "abra", 3050,
-				      "abracd", 3050,
-				      "across", 42,
-				      "alacaz", 3050,
-				      "all", 1109,
-				      "altar", 90,
-				      "and", 6001,
-				      "answer", 2035,
-				      "anvil", 1091,
-				      "ascend", 29,
-				      "at", 4009,
-				      "attack", 2012,
-				      "awaken", 2029,
-				      "awkward", 26,
-				      "axe", 1028,
-				      "back", 8,
-				      "ball", 1120,
-				      "barren", 40,
-				      "bat", 1104,
-				      "bats", 1104,
-				      "batshit", 1104,
-				      "batteries", 1039,
-				      "beans", 1024,
-				      "bear", 1035,
-				      "bed", 16,
-				      "bedquilt", 70,
-				      "bee", 1087,
-				      "beehive", 1097,
-				      "bees", 1087,
-				      "billboard", 1116,
-				      "bird", 1101,
-				      "bitch", 2048,
-				      "black", 5006,
-				      "blast", 2023,
-				      "blow", 2036,
-				      "blowup", 2023,
-				      "boat", 1048,
-				      "book", 1110,
-				      "booth", 1093,
-				      "bottle", 1020,
-				      "box", 1055,
-				      "brass", 5004,
-				      "break", 2028,
-				      "bridge", 89,
-				      "brief", 2026,
-				      "broken", 54,
-				      "broom", 1114,
-				      "brush", 1114,
-				      "brush", 2054,
-				      "building", 12,
-				      "bumble", 1087,
-				      "burn", 2047,
-				      "cage", 1004,
-				      "cake", 1107,	/* value must be
-							   mushrooms + 1 */
-				      "cakes", 1107,
-				      "call", 2038,
-				      "calm", 2010,
-				      "canister", 1118,
-				      "canyon", 25,
-				      "cape", 1047,
-				      "capture", 2001,
-				      "carpet", 1040,
-				      "carry", 2001,
-				      "carving", 1115,
-				      "cask", 1071,
-				      "catch", 2001,
-				      "cave", 67,
-				      "cavern", 73,
-				      "chain", 1064,
-				      "chalice", 1070,
-				      "chant", 2003,
-				      "chasm", 1021,	/* troll bridge */
-				      "chest", 1055,
-				      "chimney", 78,
-				      "clam", 1014,
-				      "click", 85,
-				      "climb", 56,
-				      "cloak", 1047,
-				      "close", 2006,
-				      "clover", 1073,
-				      "cobble", 18,
-				      "coins", 1054,
-				      "comb", 1096,
-				      "complain", 2048,
-				      "continue", 7,
-				      "continue", 2011,
-				      "crack", 33,
-				      "crap", 3106,
-				      "crap!", 3106,
-				      "crawl", 17,
-				      "cross", 69,
-				      "crown", 1066,
-				      "crystal", 5033,
-				      "cup", 1070,
-				      "cupcakes", 1107,
-				      "d", 30,
-				      "dark", 22,
-				      "debris", 51,
-				      "defile", 23,
-				      "depression", 63,
-				      "descend", 30,
-				      "describe", 2052,
-				      "detonate", 2023,
-				      "devour", 2014,
-				      "diagnose", 2051,
-				      "dial", 2039,
-				      "diamond", 1051,
-				      "diamonds", 1051,
-				      "dig", 3066,
-				      "discard", 2002,
-				      "disturb", 2029,
-				      "doff", 2002,
-				      "dog", 1098,
-				      "dome", 35,
-				      "don", 2033,
-				      "door", 1041,	/* giant door */
-				      "down", 30,
-				      "down", 4008,
-				      "downstream", 5,
-				      "downward", 30,
-				      "dragon", 1031,
-				      "drawing", 1029,
-				      "drink", 2015,
-				      "drop", 2002,
-				      "droplet", 1075,
-				      "dump", 2002,
-				      "dust", 2054,
-				      "dwarf", 1017,
-				      "dwarves", 1017,
-				      "e", 43,
-				      "east", 43,
-				      "eat", 2014,
-				      "egg", 1056,
-				      "eggs", 1056,
-				      "elfin", 5019,
-				      "emerald", 1059,
-				      "empty", 2013,
-				      "enter", 3,
-				      "entrance", 64,
-				      "everything", 1109,
-				      "examine", 2052,
-				      "excavate", 3066,
-				      "exit", 11,
-				      "explore", 2011,
-				      "extinguish", 2008,
-				      "fee", 2025,
-				      "fee", 3001,
-				      "feed", 2021,
-				      "fie", 2025,
-				      "fie", 3002,
-				      "fight", 2012,
-				      "figure", 1027,
-				      "fill", 2022,
-				      "find", 2019,
-				      "fissure", 1012,
-				      "fling", 2017,
-				      "floor", 58,
-				      "flower", 1046,
-				      "flowers", 1046,
-				      "foe", 2025,
-				      "foe", 3003,
-				      "follow", 2011,
-				      "foo", 2025,
-				      "foo", 3004,
-				      "food", 1019,
-				      "forcd", 1,
-				      "forest", 6,
-				      "fork", 77,
-				      "forward", 7,
-				      "fountain", 1103,
-				      "four-leafed", 5034,
-				      "free", 2002,
-				      "fresh", 5010,
-				      "from", 4005,
-				      "fuck", 3079,
-				      "fuck!", 3079,
-				      "fum", 2025,
-				      "fum", 3005,
-				      "gate", 2058,
-				      "get", 2044,
-				      "geyser", 1037,	/* same as volcano */
-				      "giant", 27,
-				      "giant", 5029,
-				      "glowing", 5031,
-				      "gnome", 1105,
-				      "go", 2011,
-				      "gold", 1050,
-				      "golden", 5001,
-				      "goto", 2011,
-				      "grab", 2032,
-				      "grail", 1070,
-				      "grate", 1003,
-				      "green", 5032,
-				      "grey", 5032,
-				      "gripe", 2048,
-				      "grotto", 91,
-				      "guano", 1104,
-				      "gully", 13,
-				      "h20", 1081,
-				      "hall", 38,
-				      "headlamp", 1002,
-				      "health", 2051,
-				      "heave", 2017,
-				      "heels", 1067,
-				      "help", 3051,
-				      "hike", 2011,
-				      "hill", 2,
-				      "hit", 2034,
-				      "hive", 1097,
-				      "hocus", 3050,
-				      "hole", 52,
-				      "holy", 5021,
-				      "honey", 1096,
-				      "honeycomb", 1096,
-				      "horn", 1052,
-				      "hound", 1098,
-				      "house", 12,
-				      "hurl", 2017,
-				      "i", 2020,
-				      "ice", 88,
-				      "ignite", 2023,
-				      "in", 19,
-				      "in", 4001,
-				      "insert", 2045,
-				      "inside", 19,
-				      "inside", 4001,
-				      "into", 4001,
-				      "inventory", 2020,
-				      "inward", 19,
-				      "iron", 5011,
-				      "issue", 1016,
-				      "jar", 1020,
-				      "jerk", 2032,
-				      "jewelry", 1053,
-				      "jewels", 1053,
-				      "jump", 39,
-				      "keep", 2001,
-				      "keg", 1071,
-				      "key", 1090,
-				      "keys", 1102,
-				      "kick", 2034,
-				      "kill", 2012,
-				      "knapsack", 1108,
-				      "knife", 1018,
-				      "knives", 1018,
-				      "knoll", 81,
-				      "l", 2052,
-				      "lamp", 1002,
-				      "lantern", 1002,
-				      "lead", 5023,
-				      "leaden", 5023,
-				      "leap", 39,
-				      "leather", 5024,
-				      "leave", 11,
-				      "leave", 2037,
-				      "ledge", 83,
-				      "left", 36,
-				      "light", 1002,
-				      "little", 5012,
-				      "lock", 2049,
-				      "look", 2052,
-				      "lost", 3068,
-				      "low", 24,
-				      "lyre", 1068,
-				      "machine", 1038,
-				      "magazine", 1016,
-				      "main", 76,
-				      "map", 2057,
-				      "message", 1036,
-				      "metal", 5035,
-				      "ming", 5016,
-				      "mirror", 1023,
-				      "mist", 3069,
-				      "moss", 1040,
-				      "mumble", 2003,
-				      "mushroom", 1106,
-				      "mushrooms", 1106,
-				      "n", 45,
-				      "ne", 47,
-				      "nest", 1056,
-				      "north", 45,
-				      "northeast", 47,
-				      "northwest", 50,
-				      "nothing", 2005,
-				      "nowhere", 21,
-				      "nugget", 1050,
-				      "null", 21,
-				      "nw", 50,
-				      "oak", 5022,
-				      "oaken", 5022,
-				      "off", 4006,
-				      "office", 76,
-				      "oil", 1083,	/* in bottle */
-				      "on", 4002,
-				      "onto", 4002,
-				      "onward", 7,
-				      "open", 2004,
-				      "opensesame", 3050,
-				      "oriental", 72,
-				      "out", 11,
-				      "outdoors", 32,
-				      "outside", 11,
-				      "over", 41,
-				      "oyster", 1015,
-				      "pantry", 57,
-				      "passage", 23,
-				      "pause", 2030,
-				      "pearl", 1061,
-				      "persian", 5002,
-				      "peruse", 2027,
-				      "peyote", 1106,
-				      "phone", 1094,
-				      "phonebooth", 1094,
-				      "phuce", 82,
-				      "pick", 2041,
-				      "pillow", 1010,
-				      "pirate", 1030,
-				      "pirloc", 2059,
-				      "piss", 3107,
-				      "piss!", 3107,
-				      "pit", 31,
-				      "placate", 2010,
-				      "plant", 1024,
-				      "platinum", 5017,
-				      "play", 2040,
-				      "plover", 71,
-				      "plugh", 65,
-				      "pocus", 3050,
-				      "pole", 1009,
-				      "pool", 80,
-				      "poster", 1113,
-				      "pottery", 1058,
-				      "pound", 2034,
-				      "pour", 2013,
-				      "pray", 92,
-				      "prayer", 92,
-				      "proceed", 2011,
-				      "pull", 2032,
-				      "punch", 2034,
-				      "put", 2042,
-				      "pyramid", 1060,
-				      "q", 2018,
-				      "quartz", 5036,
-				      "quit", 2018,
-				      "radium", 1119,
-				      "rare", 5018,
-				      "ration", 1019,
-				      "read", 2027,
-				      "refill", 2022,
-				      "release", 2002,
-				      "remove", 2046,
-				      "reply", 2035,
-				      "report", 2048,
-				      "reservoir", 75,
-				      "restore", 2031,
-				      "retreat", 8,
-				      "return", 8,
-				      "right", 37,
-				      "ring", 1072,
-				      "road", 2,
-				      "rock", 1119,
-				      "rock", 15,
-				      "rocks", 1092,
-				      "rocks", 1115,
-				      "rod", 1005,
-				      "room", 59,
-				      "rowboat", 1048,
-				      "rub", 2016,
-				      "ruby", 5020,
-				      "rug", 1062,
-				      "run", 2011,
-				      "rusty", 5028,
-				      "s", 46,
-				      "sack", 1108,
-				      "safe", 1112,
-				      "saint-michel", 93,
-				      "sandwich", 1019,
-				      "sapphire", 1069,
-				      "save", 2030,
-				      "say", 2003,
-				      "score", 2024,
-				      "se", 48,
-				      "secret", 66,
-				      "sesame", 3050,
-				      "shadowy", 5027,
-				      "shake", 2009,
-				      "shards", 1058,
-				      "shatter", 2028,
-				      "shazam", 3050,
-				      "shelf", 83,
-				      "shell", 74,
-				      "shield", 1118,
-				      "ship", 1048,
-				      "shit", 3106,
-				      "shit!", 3106,
-				      "shoes", 1067,
-				      "shut", 2006,
-				      "silk", 5013,
-				      "silken", 5013,
-				      "silver", 5014,
-				      "sing", 2003,
-				      "slab", 61,
-				      "slabroom", 61,
-				      "slay", 2012,
-				      "slide", 79,
-				      "slippers", 1067,
-				      "slit", 60,
-				      "slugs", 1095,
-				      "small", 5012,
-				      "smash", 2028,
-				      "snake", 1011,
-				      "south", 46,
-				      "southeast", 48,
-				      "southwest", 49,
-				      "spelunker", 1016,
-				      "sphere", 1120,
-				      "spices", 1063,
-				      "stair", 10,
-				      "stairs", 10,
-				      "stalagmite", 1026,
-				      "star", 5026,
-				      "statue", 1074,
-				      "steal", 2001,
-				      "steel", 5025,
-				      "steps", 1007,
-				      "steps", 34,
-				      "stick", 1049,
-				      "sticks", 1049,
-				      "stone", 1119,
-				      "stop", 3139,
-				      "stream", 14,
-				      "strike", 2034,
-				      "strum", 2040,
-				      "suggest", 2048,
-				      "surface", 20,
-				      "suspend", 2030,
-				      "sw", 49,
-				      "sweep", 2054,
-				      "swim", 3147,
-				      "swing", 2009,
-				      "sword", 1065,
-				      "tablet", 1013,
-				      "take", 2001,
-				      "tame", 2010,
-				      "tasty", 5030,
-				      "telephone", 1094,
-				      "terse", 2055,
-				      "then", 6002,
-				      "throw", 2017,
-				      "thunder", 84,
-				      "tiny", 5012,
-				      "to", 4004,
-				      "tome", 1110,
-				      "toss", 2017,
-				      "tote", 2001,
-				      "travel", 2011,
-				      "treasure", 5015,
-				      "tree", 1074,
-				      "tree", 3064,
-				      "trees", 3064,
-				      "trident", 1057,
-				      "troll", 1033,
-				      "tube", 1118,
-				      "tunnel", 23,
-				      "turn", 2043,
-				      "u", 29,
-				      "unbrief", 2026,
-				      "unlock", 2050,
-				      "unterse", 2055,
-				      "up", 29,
-				      "up", 4007,
-				      "upon", 4002,
-				      "upstream", 4,
-				      "upward", 29,
-				      "used", 5009,
-				      "utter", 2003,
-				      "valley", 9,
-				      "vase", 1058,
-				      "velvet", 5007,
-				      "vending", 5008,
-				      "view", 28,
-				      "volcano", 1037,
-				      "volume", 1110,
-				      "w", 44,
-				      "wake", 2029,
-				      "waken", 2029,
-				      "walk", 2011,
-				      "wall", 53,
-				      "wall", 1088,	/* in blue grotto */
-				      "wand", 1005,
-				      "water", 1081,	/* in bottle */
-				      "wave", 2009,
-				      "wear", 2033,
-				      "west", 44,
-				      "whack", 2034,
-				      "where", 2019,
-				      "whirl", 80,
-				      "whirlpool", 80,
-				      "whisk", 1114,
-				      "whiskbroom", 1114,
-				      "wicker", 5005,
-				      "wine", 1085,	/* in bottle */
-				      "with", 4003,
-				      "wiz", 2056,
-				      "wolf", 1098,
-				      "wooden", 5003,
-				      "worn", 5009,
-				      "worn-out", 5009,
-				      "wornout", 5009,
-				      "wumpus", 1099,
-				      "xyzzy", 62,
-				      "y2", 55,
-				      "yank", 2032
-};
-
-#define MAXWC	(sizeof(wc) / sizeof(struct wac))
-
-_PROTOTYPE(int binary, (char *));
-
-int vocab(word, type)
-char *word;
-int type;
-{
-    int v1, v2, temp;
-
-    if ((v1 = binary(word)) >= 0) {
-	if (v1 > 0 && strcmp(word, wc[v1 - 1].aword) == 0)
-	    v2 = v1 - 1;
-	else if (v1 < (MAXWC - 1) && strcmp(word, wc[v1 + 1].aword) == 0)
-	    v2 = v1 + 1;
-	else
-	    v2 = v1;
-	if (wc[v1].acode > wc[v2].acode) {
-	    temp = v1;
-	    v1 = v2;
-	    v2 = temp;
-	}
-	if (type <= CLASS(wc[v1].acode))
-	    return (wc[v1].acode);
-	else if (type <= CLASS(wc[v2].acode))
-	    return (wc[v2].acode);
-	else
-	    return (-1);
-    } else
-	return (-1);
-}
-
-int binary(w)
-char *w;
-{
-    int lo, mid, hi, check;
-
-    lo = 0;
-    hi = MAXWC - 1;
-    do {
-	mid = (lo + hi) / 2;
-	check = strcmp(w, wc[mid].aword);
-	if (check == 0)
-	    return (mid);
-	else if (check < 0)
-	    hi = mid - 1;
-	else
-	    lo = mid + 1;
-    } while (lo <= hi);
-    return (-1);
-}
Index: trunk/minix/commands/ash/Makefile
===================================================================
--- trunk/minix/commands/ash/Makefile	(revision 9)
+++ 	(revision )
@@ -1,105 +1,0 @@
-# Makefile for ash.
-
-SRCS=	builtins.c cd.c dirent.c error.c eval.c exec.c expand.c input.c \
-	jobs.c mail.c main.c memalloc.c miscbltin.c mystring.c nodes.c \
-	options.c parser.c redir.c show.c signames.c syntax.c trap.c \
-	output.c var.c
-
-OBJS=	builtins.o cd.o dirent.o error.o eval.o exec.o expand.o input.o \
-	jobs.o mail.o main.o memalloc.o miscbltin.o mystring.o nodes.o \
-	options.o parser.o redir.o show.o signames.o syntax.o trap.o \
-	output.o var.o init.o \
-	bltin/echo.o bltin/expr.o bltin/operators.o bltin/regexp.o
-
-#
-# Set READLINE in shell.h and add -ledit to LIBS if you want to use the
-# editline package by Simmule Turner and Rich Salz.  (The big, bloated
-# and GPL contaminated FSF readline should work too.)
-#
-CPPFLAGS= -DSHELL -I. -D_MINIX -D_POSIX_SOURCE
-CFLAGS=	-wo -i $(CPPFLAGS)
-LIBS=	-ledit
-CC = exec cc
-
-CLEANFILES= $(OBJS) \
-	builtins.c builtins.h init.c mkinit mknodes mksignames mksyntax \
-	nodes.c nodes.h signames.c signames.h syntax.c syntax.h token.def \
-	bltin/operators.h bltin/operators.c
-
-all:	sh
-
-sh:	$(OBJS)
-	$(CC) $(CFLAGS) -o sh $(OBJS) $(LIBS)
-	install -S 100k sh
-
-install:	/usr/bin/ash /usr/bin/sh /bin/sh /bin/bigsh
-
-/usr/bin/ash:	sh
-	install -cs -o bin $? $@
-
-/usr/bin/sh:	/usr/bin/ash
-	install -l $? $@
-
-/bin/sh:	/usr/bin/ash
-	install -lcs $? $@
-
-/bin/bigsh:	/usr/bin/ash
-	install -S 1500000 -lcs $? $@
-
-clean:
-	rm -f $(CLEANFILES) sh core
-
-parser.o: token.def
-
-token.def: mktokens
-	sh mktokens
-
-builtins.c builtins.h: builtins.table shell.h
-	sh mkbuiltins shell.h builtins.table
-
-init.o: mkinit $(SRCS)
-	./mkinit '$(CC) -c $(CFLAGS) init.c' $(SRCS)
-
-mkinit: mkinit.c
-	$(CC) $(CFLAGS) mkinit.c -o $@
-
-nodes.c nodes.h: mknodes nodetypes nodes.c.pat
-	./mknodes nodetypes nodes.c.pat
-
-mknodes: mknodes.c
-	$(CC) $(CFLAGS) mknodes.c -o $@
-
-signames.c signames.h: mksignames
-	./mksignames
-
-mksignames: mksignames.c
-	$(CC) $(CFLAGS) mksignames.c -o $@
-
-syntax.c syntax.h: mksyntax
-	./mksyntax
-
-mksyntax: mksyntax.c parser.h
-	$(CC) $(CFLAGS) mksyntax.c -o $@
-
-bltin/operators.h:	bltin/mkexpr bltin/binary_op bltin/unary_op
-	cd bltin && sh mkexpr
-
-bltin/echo.o:	bltin/echo.c
-	cd bltin && $(CC) -I.. $(CFLAGS) -c echo.c
-
-bltin/expr.o:	bltin/expr.c
-	cd bltin && $(CC) -I.. $(CFLAGS) -c expr.c
-
-bltin/operators.o:	bltin/operators.c
-	cd bltin && $(CC) -I.. $(CFLAGS) -c operators.c
-
-bltin/regexp.o:	bltin/regexp.c
-	cd bltin && $(CC) -I.. $(CFLAGS) -c regexp.c
-
-# Dependencies you say?  This will have to do.
-$(OBJS): error.h eval.h exec.h expand.h init.h input.h \
-	jobs.h machdep.h mail.h main.h memalloc.h mystring.h options.h \
-	output.h parser.h redir.h shell.h trap.h var.h \
-	builtins.h nodes.h signames.h syntax.h
-
-bltin/expr.o bltin/operators.o:	bltin/operators.h
Index: trunk/minix/commands/ash/TOUR
===================================================================
--- trunk/minix/commands/ash/TOUR	(revision 9)
+++ 	(revision )
@@ -1,348 +1,0 @@
-#	@(#)TOUR	5.1 (Berkeley) 3/7/91
-
-                       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.def
-        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.
Index: trunk/minix/commands/ash/bltin/LICENSE
===================================================================
--- trunk/minix/commands/ash/bltin/LICENSE	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-		    ASH GENERAL PUBLIC LICENSE
-
-  1. You may copy and distribute ash code or code derived from it in
-source or object form, provided that you conspicuously and appropriately
-publish on each copy a valid copyright notice "Copyright 1989 by Kenneth
-Almquist." (or with whatever year is appropriate); keep intact the
-notices on all files that refer to this License Agreement and to the
-absence of any warranty; and give any other recipients of the ash program
-a copy of this License Agreement along with the program.
-
-  2. You may not copy, sublicense, distribute or transfer ash except as
-expressly provided under this License Agreement.  Any attempt otherwise
-to copy, sublicense, distribute or transfer ash is void and your rights
-to use ash under this License agreement shall be automatically terminated.
-However, parties who have received computer software programs from you
-with this License Agreement will not have their licenses terminated so
-long as such parties remain in full compliance.
-
-
-			   NO WARRANTY
-
-  Because ash is licensed free of charge, I provide absolutely no
-warranty, to the extent permitted by applicable state law.  Except
-when otherwise stated in writing, Kenneth Almquist and/or other
-parties provide ash "as is" without warranty of any kind, either
-expressed or implied, including, but not limited to, the implied
-warranties of merchantability and fitness for a particular purpose.
-The entire risk as to the quality and performance of the program is
-with you.  Should the ash program prove defective, you assume the cost
-of all necessary servicing, repair or correction.
-
- In no event unless required by applicable law will Kenneth Almquist
-and/or any other party who may modify and redistribute ash as permitted
-above, be liable to you for damages, including any lost profits, lost
-monies, or other special, incidental or consequential damages arising
-out of the use or inability to use (including but not limited to loss
-of data or data being rendered inaccurate or losses sustained by third
-parties or a failure of the program to operate with programs provided
-by other parties) the program, even if you have been advised of the
-possibility of such damages, or for any claim by any other party.
Index: trunk/minix/commands/ash/bltin/binary_op
===================================================================
--- trunk/minix/commands/ash/bltin/binary_op	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-# List of binary operators used by test/expr.
-#
-# Copyright 1989 by Kenneth Almquist.  All rights reserved.
-# This file is part of ash, which is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-OR1	 -o	1
-OR2	 |	1
-AND1	 -a	2
-AND2	 &	2
-STREQ	 =	4    OP_STRING
-STRNE	 !=	4    OP_STRING
-NEWER	 -newer	4    OP_STRING
-EQ	 -eq	4    OP_INT
-NE	 -ne	4    OP_INT
-GT	 -gt	4    OP_INT
-LT	 -lt	4    OP_INT
-LE	 -le	4    OP_INT
-GE	 -ge	4    OP_INT
-PLUS	 +	5    OP_INT
-MINUS	 -	5    OP_INT
-TIMES	 *	6    OP_INT
-DIVIDE	 /	6    OP_INT
-REM	 %	6    OP_INT
-MATCHPAT :	7    OP_STRING
Index: trunk/minix/commands/ash/bltin/bltin.h
===================================================================
--- trunk/minix/commands/ash/bltin/bltin.h	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-/*
- * 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.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include "../shell.h"
-#include "../mystring.h"
-#ifdef SHELL
-#include "../output.h"
-#define stdout out1
-#define stderr out2
-#define printf out1fmt
-#define putc(c, file)	outc(c, file)
-#define putchar(c)	out1c(c)
-#define fprintf outfmt
-#define fputs outstr
-#define fflush flushout
-#define INITARGS(argv)
-#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
-
-#ifdef __STDC__
-pointer stalloc(int);
-void error(char *, ...);
-#else
-pointer stalloc();
-void error();
-#endif
-
-
-extern char *commandname;
Index: trunk/minix/commands/ash/bltin/catf.c
===================================================================
--- trunk/minix/commands/ash/bltin/catf.c	(revision 9)
+++ 	(revision )
@@ -1,88 +1,0 @@
-/*
- * Copy the files given as arguments to the standard output.  The file
- * name "-" refers to the standard input.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#define main catfcmd
-
-#include "bltin.h"
-#include "../error.h"
-#include <sys/param.h>
-#include <fcntl.h>
-
-
-#ifdef SBUFSIZE
-#define BUFSIZE() SBUFSIZE
-#else
-#ifdef MAXBSIZE
-#define BUFSIZE() MAXBSIZE
-#else
-#define BUFSIZE() BSIZE
-#endif
-#endif
-
-
-main(argc, argv)  char **argv; {
-      char *filename;
-      char *buf = stalloc(BUFSIZE());
-      int fd;
-      int i;
-#ifdef SHELL
-      volatile int input;
-      struct jmploc jmploc;
-      struct jmploc *volatile savehandler;
-#endif
-
-      INITARGS(argv);
-#ifdef SHELL
-      input = -1;
-      if (setjmp(jmploc.loc)) {
-	    close(input);
-	    handler = savehandler;
-	    longjmp(handler, 1);
-      }
-      savehandler = handler;
-      handler = &jmploc;
-#endif
-      while ((filename = *++argv) != NULL) {
-	    if (filename[0] == '-' && filename[1] == '\0') {
-		  fd = 0;
-	    } else {
-#ifdef SHELL
-		  INTOFF;
-		  if ((fd = open(filename, O_RDONLY)) < 0)
-			error("Can't open %s", filename);
-		  input = fd;
-		  INTON;
-#else
-		  if ((fd = open(filename, O_RDONLY)) < 0) {
-			fprintf(stderr, "catf: Can't open %s\n", filename);
-			exit(2);
-		  }
-#endif
-	    }
-	    while ((i = read(fd, buf, BUFSIZE())) > 0) {
-#ifdef SHELL
-		  if (out1 == &memout) {
-			register char *p;
-			for (p = buf ; --i >= 0 ; p++) {
-			      outc(*p, &memout);
-			}
-		  } else {
-			write(1, buf, i);
-		  }
-#else
-		  write(1, buf, i);
-#endif
-	    }
-	    if (fd != 0)
-		  close(fd);
-      }
-#ifdef SHELL
-      handler = savehandler;
-#endif
-}
Index: trunk/minix/commands/ash/bltin/echo.c
===================================================================
--- trunk/minix/commands/ash/bltin/echo.c	(revision 9)
+++ 	(revision )
@@ -1,74 +1,0 @@
-/*
- * Echo command.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#define main echocmd
-
-#include "bltin.h"
-
-#undef eflag
-
-
-main(argc, argv)  char **argv; {
-      register char **ap;
-      register char *p;
-      register char c;
-      int count;
-      int nflag = 0;
-#ifndef eflag
-      int eflag = 0;
-#endif
-
-      ap = argv;
-      if (argc)
-	    ap++;
-      if ((p = *ap) != NULL) {
-	    if (equal(p, "--")) {
-		  ap++;
-	    }
-	    if (equal(p, "-n")) {
-		  nflag++;
-		  ap++;
-	    } else if (equal(p, "-e")) {
-#ifndef eflag
-		  eflag++;
-#endif
-		  ap++;
-	    }
-      }
-      while ((p = *ap++) != NULL) {
-	    while ((c = *p++) != '\0') {
-		  if (c == '\\' && eflag) {
-			switch (*p++) {
-			case 'b':  c = '\b';  break;
-			case 'c':  return 0;		/* exit */
-			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:
-			      p--;
-			      break;
-			}
-		  }
-		  putchar(c);
-	    }
-	    if (*ap)
-		  putchar(' ');
-      }
-      if (! nflag)
-	    putchar('\n');
-      return 0;
-}
Index: trunk/minix/commands/ash/bltin/error.c
===================================================================
--- trunk/minix/commands/ash/bltin/error.c	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-/*
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include <stdio.h>
-
-char *commandname;
-
-
-void
-#ifdef __STDC__
-error(char *msg, ...) {
-#else
-error(msg)
-      char *msg;
-      {
-#endif
-
-      fprintf(stderr, "%s: %s\n", commandname, msg);
-      exit(2);
-}
Index: trunk/minix/commands/ash/bltin/expr.c
===================================================================
--- trunk/minix/commands/ash/bltin/expr.c	(revision 9)
+++ 	(revision )
@@ -1,481 +1,0 @@
-/*
- * The expr and test commands.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-
-#define main exprcmd
-
-#include "bltin.h"
-#include "operators.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#ifndef S_ISLNK
-#define lstat		stat
-#define S_ISLNK(mode)	(0)
-#endif
-
-#define STACKSIZE 12
-#define NESTINCR 16
-
-/* data types */
-#define STRING 0
-#define INTEGER 1
-#define BOOLEAN 2
-
-
-/*
- * This structure hold a value.  The type keyword specifies the type of
- * the value, and the union u holds the value.  The value of a boolean
- * is stored in u.num (1 = TRUE, 0 = FALSE).
- */
-
-struct value {
-      int type;
-      union {
-	    char *string;
-	    long num;
-      } u;
-};
-
-
-struct operator {
-      short op;			/* which operator */
-      short pri;		/* priority of operator */
-};
-
-
-struct filestat {
-      int op;			/* OP_FILE or OP_LFILE */
-      char *name;		/* name of file */
-      int rcode;		/* return code from stat */
-      struct stat stat;		/* status info on file */
-};
-
-
-extern char *match_begin[10];	/* matched string */
-extern short match_length[10];	/* defined in regexp.c */
-extern short number_parens;	/* number of \( \) pairs */
-
-
-#ifdef __STDC__
-int expr_is_false(struct value *);
-void expr_operator(int, struct value *, struct filestat *);
-int lookup_op(char *, char *const*);
-char *re_compile(char *);	/* defined in regexp.c */
-int re_match(char *, char *);	/* defined in regexp.c */
-long atol(const char *);
-#else
-int expr_is_false();
-void expr_operator();
-int lookup_op();
-char *re_compile();	/* defined in regexp.c */
-int re_match();	/* defined in regexp.c */
-long atol();
-#endif
-
-
-
-main(argc, argv)  char **argv; {
-      char **ap;
-      char *opname;
-      char c;
-      char *p;
-      int print;
-      int nest;		/* parenthises nesting */
-      int op;
-      int pri;
-      int skipping;
-      int binary;
-      struct operator opstack[STACKSIZE];
-      struct operator *opsp;
-      struct value valstack[STACKSIZE + 1];
-      struct value *valsp;
-      struct filestat fs;
-
-      INITARGS(argv);
-      c = **argv;
-      print = 1;
-      if (c == 't')
-	    print = 0;
-      else if (c == '[') {
-	    if (! equal(argv[argc - 1], "]"))
-		  error("missing ]");
-	    argv[argc - 1] = NULL;
-	    print = 0;
-      }
-      ap = argv + 1;
-      fs.name = NULL;
-
-      /*
-       * We use operator precedence parsing, evaluating the expression
-       * as we parse it.  Parentheses are handled by bumping up the
-       * priority of operators using the variable "nest."  We use the
-       * variable "skipping" to turn off evaluation temporarily for the
-       * short circuit boolean operators.  (It is important do the short
-       * circuit evaluation because under NFS a stat operation can take
-       * infinitely long.)
-       */
-
-      nest = 0;
-      skipping = 0;
-      opsp = opstack + STACKSIZE;
-      valsp = valstack;
-      if (*ap == NULL) {
-	    valstack[0].type = BOOLEAN;
-	    valstack[0].u.num = 0;
-	    goto done;
-      }
-      for (;;) {
-	    opname = *ap++;
-	    if (opname == NULL)
-syntax:		  error("syntax error");
-	    if (opname[0] == '(' && opname[1] == '\0') {
-		  nest += NESTINCR;
-		  continue;
-	    } else if (*ap && (op = lookup_op(opname, unary_op)) >= 0) {
-		  if (opsp == &opstack[0])
-overflow:		error("Expression too complex");
-		  --opsp;
-		  opsp->op = op;
-		  opsp->pri = op_priority[op] + nest;
-		  continue;
-
-	    } else {
-		  valsp->type = STRING;
-		  valsp->u.string = opname;
-		  valsp++;
-	    }
-	    for (;;) {
-		  opname = *ap++;
-		  if (opname == NULL) {
-			if (nest != 0)
-			      goto syntax;
-			pri = 0;
-			break;
-		  }
-		  if (opname[0] != ')' || opname[1] != '\0') {
-			if ((op = lookup_op(opname, binary_op)) < 0)
-			      goto syntax;
-			op += FIRST_BINARY_OP;
-			pri = op_priority[op] + nest;
-			break;
-		  }
-		  if ((nest -= NESTINCR) < 0)
-			goto syntax;
-	    }
-	    while (opsp < &opstack[STACKSIZE] && opsp->pri >= pri) {
-		  binary = opsp->op;
-		  for (;;) {
-			valsp--;
-			c = op_argflag[opsp->op];
-			if (c == OP_INT) {
-			      if (valsp->type == STRING)
-				    valsp->u.num = atol(valsp->u.string);
-			      valsp->type = INTEGER;
-			} else if (c >= OP_STRING) { /* OP_STRING or OP_FILE */
-			      if (valsp->type == INTEGER) {
-				    p = stalloc(32);
-#ifdef SHELL
-				    fmtstr(p, 32, "%d", valsp->u.num);
-#else
-				    sprintf(p, "%d", valsp->u.num);
-#endif
-				    valsp->u.string = p;
-			      } else if (valsp->type == BOOLEAN) {
-				    if (valsp->u.num)
-					  valsp->u.string = "true";
-				    else
-					  valsp->u.string = "";
-			      }
-			      valsp->type = STRING;
-			      if (c >= OP_FILE
-			       && (fs.op != c
-			           || fs.name == NULL
-			           || ! equal(fs.name, valsp->u.string))) {
-				    fs.op = c;
-				    fs.name = valsp->u.string;
-				    if (c == OP_FILE) {
-					fs.rcode = stat(valsp->u.string,
-								&fs.stat);
-				    } else {
-					fs.rcode = lstat(valsp->u.string,
-								&fs.stat);
-				    }
-			      }
-			}
-			if (binary < FIRST_BINARY_OP)
-			      break;
-			binary = 0;
-		  }
-		  if (! skipping)
-			expr_operator(opsp->op, valsp, &fs);
-		  else if (opsp->op == AND1 || opsp->op == OR1)
-			skipping--;
-		  valsp++;		/* push value */
-		  opsp++;		/* pop operator */
-	    }
-	    if (opname == NULL)
-		  break;
-	    if (opsp == &opstack[0])
-		  goto overflow;
-	    if (op == AND1 || op == AND2) {
-		  op = AND1;
-		  if (skipping || expr_is_false(valsp - 1))
-			skipping++;
-	    }
-	    if (op == OR1 || op == OR2) {
-		  op = OR1;
-		  if (skipping || ! expr_is_false(valsp - 1))
-			skipping++;
-	    }
-	    opsp--;
-	    opsp->op = op;
-	    opsp->pri = pri;
-      }
-done:
-      if (print) {
-	    if (valstack[0].type == STRING)
-		  printf("%s\n", valstack[0].u.string);
-	    else if (valstack[0].type == INTEGER)
-		  printf("%ld\n", valstack[0].u.num);
-	    else if (valstack[0].u.num != 0)
-		  printf("true\n");
-      }
-      return expr_is_false(&valstack[0]);
-}
-
-
-int
-expr_is_false(val)
-      struct value *val;
-      {
-      if (val->type == STRING) {
-	    if (val->u.string[0] == '\0')
-		  return 1;
-      } else {	/* INTEGER or BOOLEAN */
-	    if (val->u.num == 0)
-		  return 1;
-      }
-      return 0;
-}
-
-
-/*
- * Execute an operator.  Op is the operator.  Sp is the stack pointer;
- * sp[0] refers to the first operand, sp[1] refers to the second operand
- * (if any), and the result is placed in sp[0].  The operands are converted
- * to the type expected by the operator before expr_operator is called.
- * Fs is a pointer to a structure which holds the value of the last call
- * to stat, to avoid repeated stat calls on the same file.
- */
-
-void
-expr_operator(op, sp, fs)
-      int op;
-      struct value *sp;
-      struct filestat *fs;
-      {
-      int i;
-      struct stat st1, st2;
-
-      switch (op) {
-      case NOT:
-	    sp->u.num = expr_is_false(sp);
-	    sp->type = BOOLEAN;
-	    break;
-      case ISREAD:
-	    i = 04;
-	    goto permission;
-      case ISWRITE:
-	    i = 02;
-	    goto permission;
-      case ISEXEC:
-	    i = 01;
-permission:
-	    if (fs->stat.st_uid == geteuid())
-		  i <<= 6;
-	    else if (fs->stat.st_gid == getegid())
-		  i <<= 3;
-	    goto filebit;	/* true if (stat.st_mode & i) != 0 */
-      case ISFILE:
-	    i = S_IFREG;
-	    goto filetype;
-      case ISDIR:
-	    i = S_IFDIR;
-	    goto filetype;
-      case ISCHAR:
-	    i = S_IFCHR;
-	    goto filetype;
-      case ISBLOCK:
-	    i = S_IFBLK;
-	    goto filetype;
-      case ISFIFO:
-#ifdef S_IFIFO
-	    i = S_IFIFO;
-	    goto filetype;
-#else
-	    goto false;
-#endif
-filetype:
-	    if ((fs->stat.st_mode & S_IFMT) == i && fs->rcode >= 0) {
-true:
-		  sp->u.num = 1;
-	    } else {
-false:
-		  sp->u.num = 0;
-	    }
-	    sp->type = BOOLEAN;
-	    break;
-      case ISSETUID:
-	    i = S_ISUID;
-	    goto filebit;
-      case ISSETGID:
-	    i = S_ISGID;
-	    goto filebit;
-      case ISSTICKY:
-	    i = S_ISVTX;
-filebit:
-	    if (fs->stat.st_mode & i && fs->rcode >= 0)
-		  goto true;
-	    goto false;
-      case ISSIZE:
-	    sp->u.num = fs->rcode >= 0? fs->stat.st_size : 0L;
-	    sp->type = INTEGER;
-	    break;
-      case ISLINK1:
-      case ISLINK2:
-	    if (S_ISLNK(fs->stat.st_mode) && fs->rcode >= 0)
-		  goto true;
-	    fs->op = OP_FILE;	/* not a symlink, so expect a -d or so next */
-	    goto false;
-      case NEWER:
-	    if (stat(sp->u.string, &st1) != 0) {
-		  sp->u.num = 0;
-	    } else if (stat((sp + 1)->u.string, &st2) != 0) {
-		  sp->u.num = 1;
-	    } else {
-		  sp->u.num = st1.st_mtime >= st2.st_mtime;
-	    }
-	    sp->type = INTEGER;
-	    break;
-      case ISTTY:
-	    sp->u.num = isatty(sp->u.num);
-	    sp->type = BOOLEAN;
-	    break;
-      case NULSTR:
-	    if (sp->u.string[0] == '\0')
-		  goto true;
-	    goto false;
-      case STRLEN:
-	    sp->u.num = strlen(sp->u.string);
-	    sp->type = INTEGER;
-	    break;
-      case OR1:
-      case AND1:
-	    /*
-	     * These operators are mostly handled by the parser.  If we
-	     * get here it means that both operands were evaluated, so
-	     * the value is the value of the second operand.
-	     */
-	    *sp = *(sp + 1);
-	    break;
-      case STREQ:
-      case STRNE:
-	    i = 0;
-	    if (equal(sp->u.string, (sp + 1)->u.string))
-		  i++;
-	    if (op == STRNE)
-		  i = 1 - i;
-	    sp->u.num = i;
-	    sp->type = BOOLEAN;
-	    break;
-      case EQ:
-	    if (sp->u.num == (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case NE:
-	    if (sp->u.num != (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case GT:
-	    if (sp->u.num > (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case LT:
-	    if (sp->u.num < (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case LE:
-	    if (sp->u.num <= (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case GE:
-	    if (sp->u.num >= (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case PLUS:
-	    sp->u.num += (sp + 1)->u.num;
-	    break;
-      case MINUS:
-	    sp->u.num -= (sp + 1)->u.num;
-	    break;
-      case TIMES:
-	    sp->u.num *= (sp + 1)->u.num;
-	    break;
-      case DIVIDE:
-	    if ((sp + 1)->u.num == 0)
-		  error("Division by zero");
-	    sp->u.num /= (sp + 1)->u.num;
-	    break;
-      case REM:
-	    if ((sp + 1)->u.num == 0)
-		  error("Division by zero");
-	    sp->u.num %= (sp + 1)->u.num;
-	    break;
-      case MATCHPAT:
-	    {
-		  char *pat;
-
-		  pat = re_compile((sp + 1)->u.string);
-		  if (re_match(pat, sp->u.string)) {
-			if (number_parens > 0) {
-			      sp->u.string = match_begin[1];
-			      sp->u.string[match_length[1]] = '\0';
-			} else {
-			      sp->u.num = match_length[0];
-			      sp->type = INTEGER;
-			}
-		  } else {
-			if (number_parens > 0) {
-			      sp->u.string[0] = '\0';
-			} else {
-			      sp->u.num = 0;
-			      sp->type = INTEGER;
-			}
-		  }
-	    }
-	    break;
-      }
-}
-
-
-int
-lookup_op(name, table)
-      char *name;
-      char *const*table;
-      {
-      register char *const*tp;
-      register char const *p;
-      char c = name[1];
-
-      for (tp = table ; (p = *tp) != NULL ; tp++) {
-	    if (p[1] == c && equal(p, name))
-		  return tp - table;
-      }
-      return -1;
-}
Index: trunk/minix/commands/ash/bltin/line.c
===================================================================
--- trunk/minix/commands/ash/bltin/line.c	(revision 9)
+++ 	(revision )
@@ -1,27 +1,0 @@
-/*
- * The line command.  Reads one line from the standard input and writes it
- * to the standard output.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#define main linecmd
-
-#include "bltin.h"
-
-
-main(argc, argv)  char **argv; {
-      char c;
-
-      for (;;) {
-	    if (read(0, &c, 1) != 1) {
-		  putchar('\n');
-		  return 1;
-	    }
-	    putchar(c);
-	    if (c == '\n')
-		  return 0;
-      }
-}
Index: trunk/minix/commands/ash/bltin/makefile.not
===================================================================
--- trunk/minix/commands/ash/bltin/makefile.not	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-# Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
-# This file is part of ash, which is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-LIBFILES=catfcmd.o echocmd.o exprcmd.o linecmd.o nlechocmd.o\
-	operators.o regexp.o
-DEBUG=-g
-CFLAGS=$(DEBUG)
-#CC=gcc
-
-all:$P bltinlib.a catf echo expr line nlecho true umask
-
-bltinlib.a:$P $(LIBFILES)
-	ar rc $@ $(LIBFILES)
-
-catf: catf.c bltin.h ../shell.h ../error.h error.o stalloc.o
-	$(CC) $(CFLAGS) -o $@ catf.c error.o stalloc.o
-
-catfcmd.o: catf.c bltin.h ../shell.h ../error.h
-	$(CC) -DSHELL $(CFLAGS) -c catf.c
-	mv catf.o $@
-
-expr: expr.c bltin.h ../shell.h operators.h operators.o regexp.o error.o stalloc.o
-	$(CC) $(CFLAGS) -o $@ expr.c operators.o regexp.o error.o stalloc.o
-	-rm -f test '['
-	ln expr test
-	ln expr '['
-
-exprcmd.o: expr.c bltin.h ../shell.h operators.h
-	$(CC) -DSHELL $(CFLAGS) -c expr.c
-	mv expr.o $@
-
-operators.c operators.h: unary_op binary_op mkexpr
-	./mkexpr
-
-operators.o: ../shell.h operators.h
-
-regexp.o: bltin.h ../shell.h
-
-echo: echo.c bltin.h ../shell.h
-	$(CC) $(CFLAGS) -o $@ echo.c
-
-echocmd.o: echo.c bltin.h ../shell.h
-	$(CC) -DSHELL $(CFLAGS) -c echo.c
-	mv echo.o $@
-
-line: line.c bltin.h ../shell.h
-	$(CC) $(CFLAGS) -o $@ line.c
-
-linecmd.o: line.c bltin.h ../shell.h
-	$(CC) -DSHELL $(CFLAGS) -c line.c
-	mv line.o $@
-
-nlecho: nlecho.c bltin.h ../shell.h
-	$(CC) $(CFLAGS) -o $@ nlecho.c
-
-nlechocmd.o: nlecho.c bltin.h ../shell.h
-	$(CC) -DSHELL $(CFLAGS) -c nlecho.c
-	mv nlecho.o $@
-
-umask: umask.c bltin.h
-	$(CC) $(CFLAGS) -o $@ umask.c
-
-true:
-	> :
-	chmod 755 :
-	rm -f true
-	ln : true
-
-stalloc.o: ../shell.h
-
Index: trunk/minix/commands/ash/bltin/mkexpr
===================================================================
--- trunk/minix/commands/ash/bltin/mkexpr	(revision 9)
+++ 	(revision )
@@ -1,66 +1,0 @@
-# Copyright 1989 by Kenneth Almquist.  All rights reserved.
-#
-# This file is part of ash.  Ash is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-# All calls to awk removed, because Minix bawk is deficient.  (kjb)
-
-exec > operators.h
-i=0
-sed -e '/^[^#]/!d' unary_op binary_op | while read line
-do
-	set -$- $line
-	echo "#define $1 $i"
-	i=`expr $i + 1`
-done
-echo
-echo "#define FIRST_BINARY_OP" `sed -e '/^[^#]/!d' unary_op | wc -l`
-echo '
-#define OP_INT 1		/* arguments to operator are integer */
-#define OP_STRING 2		/* arguments to operator are string */
-#define OP_FILE 3		/* argument is a file name */
-#define OP_LFILE 4		/* argument is a file name of a symlink? */
-
-extern char *const unary_op[];
-extern char *const binary_op[];
-extern const char op_priority[];
-extern const char op_argflag[];'
-
-exec > operators.c
-echo '/*
- * Operators used in the expr/test command.
- */
-
-#include "../shell.h"
-#include "operators.h"
-
-char *const unary_op[] = {'
-sed -e '/^[^#]/!d
-	s/[ 	][ 	]*/ /g
-	s/^[^ ][^ ]* \([^ ][^ ]*\).*/      "\1",/
-	' unary_op
-echo '      NULL
-};
-
-char *const binary_op[] = {'
-sed -e '/^[^#]/!d
-	s/[ 	][ 	]*/ /g
-	s/^[^ ][^ ]* \([^ ][^ ]*\).*/      "\1",/
-	' binary_op
-echo '      NULL
-};
-
-const char op_priority[] = {'
-sed -e '/^[^#]/!d
-	s/[ 	][ 	]*/ /g
-	s/^[^ ][^ ]* [^ ][^ ]* \([^ ][^ ]*\).*/      \1,/
-	' unary_op binary_op
-echo '};
-
-const char op_argflag[] = {'
-sed -e '/^[^#]/!d
-	s/[ 	][ 	]*/ /g
-	s/^[^ ][^ ]* [^ ][^ ]* [^ ][^ ]*$/& 0/
-	s/^[^ ][^ ]* [^ ][^ ]* [^ ][^ ]* \([^ ][^ ]*\)/      \1,/
-	' unary_op binary_op
-echo '};'
Index: trunk/minix/commands/ash/bltin/nlecho.c
===================================================================
--- trunk/minix/commands/ash/bltin/nlecho.c	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-/*
- * Echo the command argument to the standard output, one line at a time.
- * This command is useful for debugging th shell and whenever you what
- * to output strings literally.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-
-#define main nlechocmd
-
-#include "bltin.h"
-
-
-main(argc, argv)  char **argv; {
-      register char **ap;
-
-      for (ap = argv + 1 ; *ap ; ap++) {
-	    fputs(*ap, stdout);
-	    putchar('\n');
-      }
-      return 0;
-}
Index: trunk/minix/commands/ash/bltin/regexp.c
===================================================================
--- trunk/minix/commands/ash/bltin/regexp.c	(revision 9)
+++ 	(revision )
@@ -1,299 +1,0 @@
-/*
- * Regular expression matching for expr(1).  Bugs:  The upper bound of
- * a range specified by the \{ feature cannot be zero.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include "bltin.h"
-
-
-#define RE_END 0		/* end of regular expression */
-#define RE_LITERAL 1		/* normal character follows */
-#define RE_DOT 2		/* "." */
-#define RE_CCL 3		/* "[...]" */
-#define RE_NCCL 4		/* "[^...]" */
-#define RE_LP 5			/* "\(" */
-#define RE_RP 6			/* "\)" */
-#define RE_MATCHED 7		/* "\digit" */
-#define RE_EOS 8		/* "$" matches end of string */
-#define RE_STAR 9		/* "*" */
-#define RE_RANGE 10		/* "\{num,num\}" */
-
-
-
-char *match_begin[10];
-short match_length[10];
-short number_parens;
-static int match();
-
-
-
-char *
-re_compile(pattern)
-	char *pattern;
-	{
-	register char *p;
-	register char c;
-	char *comp;
-	register char *q;
-	char *begin;
-	char *endp;
-	register int len;
-	int first;
-	int type;
-	char *stackp;
-	char stack[10];
-	int paren_num;
-	int i;
-	char *malloc();
-
-	p = pattern;
-	if (*p == '^')
-		p++;
-	comp = q = malloc(2 * strlen(p) + 1);
-	begin = q;
-	stackp = stack;
-	paren_num = 0;
-	for (;;) {
-		switch (c = *p++) {
-		case '\0':
-			*q = '\0';
-			goto out;
-		case '.':
-			*q++ = RE_DOT;
-			len = 1;
-			break;
-		case '[':
-			begin = q;
-			*q = RE_CCL;
-			if (*p == '^') {
-				*q = RE_NCCL;
-				p++;
-			}
-			q++;
-			first = 1;
-			while (*p != ']' || first == 1) {
-				if (p[1] == '-' && p[2] != ']') {
-					*q++ = '-';
-					*q++ = p[0];
-					*q++ = p[2];
-					p += 3;
-				} else if (*p == '-') {
-					*q++ = '-';
-					*q++ = '-';
-					*q++ = '-';
-					p++;
-				} else {
-					*q++ = *p++;
-				}
-				first = 0;
-			}
-			p++;
-			*q++ = '\0';
-			len = q - begin;
-			break;
-		case '$':
-			if (*p != '\0')
-				goto dft;
-			*q++ = RE_EOS;
-			break;
-		case '*':
-			if (len == 0)
-				goto dft;
-			type = RE_STAR;
-range:
-			i = (type == RE_RANGE)? 3 : 1;
-			endp = q + i;
-			begin = q - len;
-			do {
-				--q;
-				*(q + i) = *q;
-			} while (--len > 0);
-			q = begin;
-			*q++ = type;
-			if (type == RE_RANGE) {
-				i = 0;
-				while ((unsigned)(*p - '0') <= 9)
-					i = 10 * i + (*p++ - '0');
-				*q++ = i;
-				if (*p != ',') {
-					*q++ = i;
-				} else {
-					p++;
-					i = 0;
-					while ((unsigned)(*p - '0') <= 9)
-						i = 10 * i + (*p++ - '0');
-					*q++ = i;
-				}
-				if (*p != '\\' || *++p != '}')
-					error("RE error");
-				p++;
-			}
-			q = endp;
-			break;
-		case '\\':
-			if ((c = *p++) == '(') {
-				if (++paren_num > 9)
-					error("RE error");
-				*q++ = RE_LP;
-				*q++ = paren_num;
-				*stackp++ = paren_num;
-				len = 0;
-			} else if (c == ')') {
-				if (stackp == stack)
-					error("RE error");
-				*q++ = RE_RP;
-				*q++ = *--stackp;
-				len = 0;
-			} else if (c == '{') {
-				type = RE_RANGE;
-				goto range;
-			} else if ((unsigned)(c - '1') < 9) {
-				/* should check validity here */
-				*q++ = RE_MATCHED;
-				*q++ = c - '0';
-				len = 2;
-			} else {
-				goto dft;
-			}
-			break;
-		default:
-dft:			*q++ = RE_LITERAL;
-			*q++ = c;
-			len = 2;
-			break;
-		}
-	}
-out:
-	if (stackp != stack)
-		error("RE error");
-	number_parens = paren_num;
-	return comp;
-}
-
-
-
-re_match(pattern, string)
-	char *pattern;
-	char *string;
-	{
-	char **pp;
-
-	match_begin[0] = string;
-	for (pp = &match_begin[1] ; pp <= &match_begin[9] ; pp++)
-		*pp = 0;
-	return match(pattern, string);
-}
-
-
-
-static
-match(pattern, string)
-	char *pattern;
-	char *string;
-	{
-	register char *p, *q;
-	int counting;
-	int low, high, count;
-	char *curpat;
-	char *start_count;
-	int negate;
-	int found;
-	char *r;
-	int len;
-	char c;
-
-	p = pattern;
-	q = string;
-	counting = 0;
-	for (;;) {
-		if (counting) {
-			if (++count > high)
-				goto bad;
-			p = curpat;
-		}
-		switch (*p++) {
-		case RE_END:
-			match_length[0] = q - match_begin[0];
-			return 1;
-		case RE_LITERAL:
-			if (*q++ != *p++)
-				goto bad;
-			break;
-		case RE_DOT:
-			if (*q++ == '\0')
-				goto bad;
-			break;
-		case RE_CCL:
-			negate = 0;
-			goto ccl;
-		case RE_NCCL:
-			negate = 1;
-ccl:
-			found = 0;
-			c = *q++;
-			while (*p) {
-				if (*p == '-') {
-					if (c >= *++p && c <= *++p)
-						found = 1;
-				} else {
-					if (c == *p)
-						found = 1;
-				}
-				p++;
-			}
-			p++;
-			if (found == negate || c == 0)
-				goto bad;
-			break;
-		case RE_LP:
-			match_begin[*p++] = q;
-			break;
-		case RE_RP:
-			match_length[*p] = q - match_begin[*p];
-			p++;
-			break;
-		case RE_MATCHED:
-			r = match_begin[*p];
-			len = match_length[*p++];
-			while (--len >= 0) {
-				if (*q++ != *r++)
-					goto bad;
-			}
-			break;
-		case RE_EOS:
-			if (*q != '\0')
-				goto bad;
-			break;
-		case RE_STAR:
-			low = 0;
-			high = 32767;
-			goto range;
-		case RE_RANGE:
-			low = *p++;
-			high = *p++;
-			if (high == 0)
-				high = 32767;
-range:
-			curpat = p;
-			start_count = q;
-			count = 0;
-			counting++;
-			break;
-		}
-	}
-bad:
-	if (! counting)
-		return 0;
-	len = 1;
-	if (*curpat == RE_MATCHED)
-		len = match_length[curpat[1]];
-	while (--count >= low) {
-		if (match(p, start_count + count * len))
-			return 1;
-	}
-	return 0;
-}
Index: trunk/minix/commands/ash/bltin/stalloc.c
===================================================================
--- trunk/minix/commands/ash/bltin/stalloc.c	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-/*
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include "../shell.h"
-
-
-void error();
-pointer malloc();
-
-
-pointer
-stalloc(nbytes) {
-      register pointer p;
-
-      if ((p = malloc(nbytes)) == NULL)
-	    error("Out of space");
-      return p;
-}
Index: trunk/minix/commands/ash/bltin/umask.c
===================================================================
--- trunk/minix/commands/ash/bltin/umask.c	(revision 9)
+++ 	(revision )
@@ -1,19 +1,0 @@
-/*
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include <stdio.h>
-
-
-main(argc, argv)  char **argv; {
-      int mask;
-
-      if (argc > 1) {
-	    fprintf(stderr, "umask: only builtin version of umask can set value\n");
-	    exit(2);
-      }
-      printf("%.4o\n", umask(0));
-      return 0;
-}
Index: trunk/minix/commands/ash/bltin/unary_op
===================================================================
--- trunk/minix/commands/ash/bltin/unary_op	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-# List of unary operators used by test/expr.
-#
-# Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
-# This file is part of ash, which is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-NOT	 !	3
-ISREAD	 -r	12   OP_FILE
-ISWRITE  -w	12   OP_FILE
-ISEXEC	 -x	12   OP_FILE
-ISFILE	 -f	12   OP_FILE
-ISDIR	 -d	12   OP_FILE
-ISCHAR	 -c	12   OP_FILE
-ISBLOCK	 -b	12   OP_FILE
-ISFIFO	 -p	12   OP_FILE
-ISSETUID -u	12   OP_FILE
-ISSETGID -g	12   OP_FILE
-ISSTICKY -k	12   OP_FILE
-ISSIZE	 -s	12   OP_FILE
-ISLINK1  -h	12   OP_LFILE
-ISLINK2  -L	12   OP_LFILE
-ISTTY	 -t	12   OP_INT
-NULSTR	 -z	12   OP_STRING
-STRLEN	 -n	12   OP_STRING
Index: trunk/minix/commands/ash/build
===================================================================
--- trunk/minix/commands/ash/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/ash/builtins.table
===================================================================
--- trunk/minix/commands/ash/builtins.table	(revision 9)
+++ 	(revision )
@@ -1,83 +1,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991 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.
-#
-#	@(#)builtins	5.1 (Berkeley) 3/7/91
-
-#
-# This file lists all the builtin commands.  The first column is the name
-# of a C routine.  The -j flag, if present, specifies that this command
-# is to be excluded from systems without job control.  The rest of the line
-# specifies the command name or names used to run the command.  The entry
-# for nullcmd, which is run when the user does not specify a command, must
-# come first.
-#
-# Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
-# This file is part of ash, which is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-bltincmd	command
-#alloccmd	alloc
-bgcmd -j	bg
-breakcmd	break continue
-#catfcmd	catf
-cdcmd		cd chdir
-dotcmd		.
-echocmd		echo
-evalcmd		eval
-execcmd		exec
-exitcmd		exit
-exportcmd	export readonly
-exprcmd		expr test [
-fgcmd -j	fg
-getoptscmd	getopts
-hashcmd		hash
-jobidcmd	jobid
-jobscmd		jobs
-#lccmd		lc
-#linecmd		line
-localcmd	local
-#nlechocmd	nlecho
-pwdcmd		pwd
-readcmd		read
-returncmd	return
-setcmd		set
-setvarcmd	setvar
-shiftcmd	shift
-trapcmd		trap
-truecmd		: true false
-umaskcmd	umask
-unsetcmd	unset
-waitcmd		wait
Index: trunk/minix/commands/ash/cd.c
===================================================================
--- trunk/minix/commands/ash/cd.c	(revision 9)
+++ 	(revision )
@@ -1,372 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)cd.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-/*
- * 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 "mystring.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-
-
-#ifdef __STDC__
-STATIC int docd(char *, int, int);
-STATIC void updatepwd(char *);
-STATIC void getpwd(void);
-STATIC char *getcomponent(void);
-#else
-STATIC int docd();
-STATIC void updatepwd();
-STATIC void getpwd();
-STATIC char *getcomponent();
-#endif
-
-
-char *curdir;			/* current working directory */
-STATIC char *cdcomppath;
-
-#if UDIR || TILDE
-extern int didudir;		/* set if /u/logname or ~logname expanded */
-#endif
-
-
-int
-cdcmd(argc, argv)  char **argv; {
-	char *dest;
-	char *path;
-	char *p;
-	struct stat statb;
-	char *padvance();
-	int tohome= 0;
-
-	nextopt(nullstr);
-	if ((dest = *argptr) == NULL) {
-		if ((dest = bltinlookup("HOME", 1)) == NULL)
-			error("HOME not set");
-		tohome = 1;
-	}
-	if (*dest == '/' || (path = bltinlookup("CDPATH", 1)) == NULL)
-		path = nullstr;
-	while ((p = padvance(&path, dest)) != NULL) {
-		if (stat(p, &statb) >= 0
-		 && (statb.st_mode & S_IFMT) == S_IFDIR
-		 && docd(p, strcmp(p, dest), tohome) >= 0)
-			return 0;
-	}
-	error("can't cd to %s", dest);
-}
-
-
-/*
- * Actually do the chdir.  If the name refers to symbolic links, we
- * compute the actual directory name before doing the cd.  In an
- * interactive shell, print the directory name if "print" is nonzero
- * or if the name refers to a symbolic link.  We also print the name
- * if "/u/logname" was expanded in it, since this is similar to a
- * symbolic link.  (The check for this breaks if the user gives the
- * cd command some additional, unused arguments.)
- */
-
-#if SYMLINKS == 0
-STATIC int
-docd(dest, print, tohome)
-	char *dest;
-	{
-#if UDIR || TILDE
-	if (didudir)
-		print = 1;
-#endif
-	INTOFF;
-	if (chdir(dest) < 0) {
-		INTON;
-		return -1;
-	}
-	updatepwd(dest);
-	INTON;
-	if (print && iflag)
-		out1fmt("%s\n", stackblock());
-	return 0;
-}
-
-#else
-
-
-
-STATIC int
-docd(dest, print, tohome)
-	char *dest;
-	{
-	register char *p;
-	register char *q;
-	char *symlink;
-	char *component;
-	struct stat statb;
-	int first;
-	int i;
-
-	TRACE(("docd(\"%s\", %d, %d) called\n", dest, print, tohome));
-#if UDIR || TILDE
-	if (didudir)
-		print = 1;
-#endif
-
-top:
-	cdcomppath = dest;
-	STARTSTACKSTR(p);
-	if (*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)
-			error("lstat %s failed", stackblock());
-		if ((statb.st_mode & S_IFMT) != S_IFLNK)
-			continue;
-
-		/* Hit a symbolic link.  We have to start all over again. */
-		print = 1;
-		STPUTC('\0', p);
-		symlink = grabstackstr(p);
-		i = (int)statb.st_size + 2;		/* 2 for '/' and '\0' */
-		if (cdcomppath != NULL)
-			i += strlen(cdcomppath);
-		p = stalloc(i);
-		if (readlink(symlink, p, (int)statb.st_size) < 0) {
-			error("readlink %s failed", stackblock());
-		}
-		if (cdcomppath != NULL) {
-			p[(int)statb.st_size] = '/';
-			scopy(cdcomppath, p + (int)statb.st_size + 1);
-		} else {
-			p[(int)statb.st_size] = '\0';
-		}
-		if (p[0] != '/') {	/* relative path name */
-			char *r;
-			q = r = symlink;
-			while (*q) {
-				if (*q++ == '/')
-					r = q;
-			}
-			*r = '\0';
-			dest = stalloc(strlen(symlink) + strlen(p) + 1);
-			scopy(symlink, dest);
-			strcat(dest, p);
-		} else {
-			dest = p;
-		}
-		goto top;
-	}
-	STPUTC('\0', p);
-	p = grabstackstr(p);
-	INTOFF;
-	/* The empty string is not a legal argument to chdir on a POSIX 1003.1 
-	 * system. */
-	if (p[0] != '\0' && chdir(p) < 0) {
-		INTON;
-		return -1;
-	}
-	updatepwd(p);
-	INTON;
-	if (print && !tohome && iflag)
-		out1fmt("%s\n", p);
-	return 0;
-}
-#endif /* SYMLINKS */
-
-
-
-/*
- * Get the next component of the path name pointed to by cdcomppath.
- * This routine overwrites the string pointed to by cdcomppath.
- */
-
-STATIC char *
-getcomponent() {
-	register 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.
- */
-
-void hashcd();
-
-STATIC void
-updatepwd(dir)
-	char *dir;
-	{
-	char *new;
-	char *p;
-
-	hashcd();				/* update command hash table */
-	cdcomppath = stalloc(strlen(dir) + 1);
-	scopy(dir, cdcomppath);
-	STARTSTACKSTR(new);
-	if (*dir != '/') {
-		if (curdir == NULL)
-			return;
-		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);
-	if (curdir)
-		ckfree(curdir);
-	curdir = savestr(stackblock());
-}
-
-
-
-int
-pwdcmd(argc, argv)  char **argv; {
-	getpwd();
-	out1str(curdir);
-	out1c('\n');
-	return 0;
-}
-
-
-
-/*
- * Run /bin/pwd to find out what the current directory is.  We suppress
- * interrupts throughout most of this, but the user can still break out
- * of it by killing the pwd program.  If we already know the current
- * directory, this routine returns immediately.
- */
-
-#define MAXPWD 256
-
-STATIC void
-getpwd() {
-	char buf[MAXPWD];
-	char *p;
-	int i;
-	int status;
-	struct job *jp;
-	int pip[2];
-
-	if (curdir)
-		return;
-	INTOFF;
-	if (pipe(pip) < 0)
-		error("Pipe call failed");
-	jp = makejob((union node *)NULL, 1);
-	if (forkshell(jp, (union node *)NULL, FORK_NOJOB) == 0) {
-		close(pip[0]);
-		if (pip[1] != 1) {
-			close(1);
-			copyfd(pip[1], 1);
-			close(pip[1]);
-		}
-		execl("/bin/pwd", "pwd", (char *)0);
-		error("Cannot exec /bin/pwd");
-	}
-	close(pip[1]);
-	pip[1] = -1;
-	p = buf;
-	while ((i = read(pip[0], p, buf + MAXPWD - p)) > 0
-	     || i == -1 && errno == EINTR) {
-		if (i > 0)
-			p += i;
-	}
-	close(pip[0]);
-	pip[0] = -1;
-	status = waitforjob(jp);
-	if (status != 0)
-		error((char *)0);
-	if (i < 0 || p == buf || p[-1] != '\n')
-		error("pwd command failed");
-	p[-1] = '\0';
-	curdir = savestr(buf);
-	INTON;
-}
Index: trunk/minix/commands/ash/dirent.c
===================================================================
--- trunk/minix/commands/ash/dirent.c	(revision 9)
+++ 	(revision )
@@ -1,194 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)dirent.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-#include "shell.h"	/* definitions for pointer, NULL, DIRENT, and BSD */
-
-#if ! DIRENT
-
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-
-#ifndef S_ISDIR				/* macro to test for directory file */
-#define	S_ISDIR(mode)		(((mode) & S_IFMT) == S_IFDIR)
-#endif
-
-#ifdef BSD
-
-#ifdef __STDC__
-int stat(char *, struct stat *);
-#else
-int stat();
-#endif
-
-
-/*
- * The BSD opendir routine doesn't check that what is being opened is a
- * directory, so we have to include the check in a wrapper routine.
- */
-
-#undef opendir
-
-DIR *
-myopendir(dirname)
-	char *dirname;			/* name of directory */
-	{
-	struct stat statb;
-
-	if (stat(dirname, &statb) != 0 || ! S_ISDIR(statb.st_mode)) {
-		errno = ENOTDIR;
-		return NULL;		/* not a directory */
-	}
-	return opendir(dirname);
-}
-
-#else /* not BSD */
-
-/*
- * Dirent routines for old style file systems.
- */
-
-#ifdef __STDC__
-pointer malloc(unsigned);
-void free(pointer);
-int open(char *, int, ...);
-int close(int);
-int fstat(int, struct stat *);
-#else
-pointer malloc();
-void free();
-int open();
-int close();
-int fstat();
-#endif
-
-
-DIR *
-opendir(dirname)
-	char		*dirname;	/* name of directory */
-	{
-	register DIR	*dirp;		/* -> malloc'ed storage */
-	register int	fd;		/* file descriptor for read */
-	struct stat	statb;		/* result of fstat() */
-
-#ifdef O_NDELAY
-	fd = open(dirname, O_RDONLY|O_NDELAY);
-#else
-	fd = open(dirname, O_RDONLY);
-#endif
-	if (fd < 0)
-		return NULL;		/* errno set by open() */
-
-	if (fstat(fd, &statb) != 0 || !S_ISDIR(statb.st_mode)) {
-		(void)close(fd);
-		errno = ENOTDIR;
-		return NULL;		/* not a directory */
-	}
-
-	if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
-		(void)close(fd);
-		errno = ENOMEM;
-		return NULL;		/* not enough memory */
-	}
-
-	dirp->dd_fd = fd;
-	dirp->dd_nleft = 0;		/* refill needed */
-
-	return dirp;
-}
-
-
-
-int
-closedir(dirp)
-	register DIR *dirp;		/* stream from opendir() */
-	{
-	register int fd;
-
-	if (dirp == NULL) {
-		errno = EFAULT;
-		return -1;			/* invalid pointer */
-	}
-
-	fd = dirp->dd_fd;
-	free((pointer)dirp);
-	return close(fd);
-}
-
-
-
-struct dirent *
-readdir(dirp)
-	register DIR *dirp;		/* stream from opendir() */
-	{
-	register struct direct *dp;
-	register char *p, *q;
-	register int i;
-
-	do {
-		if ((dirp->dd_nleft -= sizeof (struct direct)) < 0) {
-			if ((i = read(dirp->dd_fd,
-					   (char *)dirp->dd_buf,
-					   DIRBUFENT*sizeof(struct direct))) <= 0) {
-				if (i == 0)
-					errno = 0;	/* unnecessary */
-				return NULL;		/* EOF or error */
-			}
-			dirp->dd_loc = dirp->dd_buf;
-			dirp->dd_nleft = i - sizeof (struct direct);
-		}
-		dp = dirp->dd_loc++;
-	} while (dp->d_ino == 0);
-	dirp->dd_entry.d_ino = dp->d_ino;
-
-	/* now copy the name, nul terminating it */
-	p = dp->d_name;
-	q = dirp->dd_entry.d_name;
-	i = DIRSIZ;
-	while (--i >= 0 && *p != '\0')
-		*q++ = *p++;
-	*q = '\0';
-	return &dirp->dd_entry;
-}
-
-#endif /* BSD */
-#endif /* DIRENT */
Index: trunk/minix/commands/ash/error.c
===================================================================
--- trunk/minix/commands/ash/error.c	(revision 9)
+++ 	(revision )
@@ -1,252 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)error.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * Errors and exceptions.
- */
-
-#include "shell.h"
-#include "main.h"
-#include "options.h"
-#include "output.h"
-#include "error.h"
-#include <sys/types.h>
-#include <signal.h>
-#ifdef __STDC__
-#include "stdarg.h"
-#else
-#include <varargs.h>	
-#endif
-#include <errno.h>
-
-
-/*
- * Code to handle exceptions in C.
- */
-
-struct jmploc *handler;
-int exception;
-volatile int suppressint;
-volatile int intpending;
-char *commandname;
-
-
-/*
- * 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(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() {
-	if (suppressint) {
-		intpending++;
-		return;
-	}
-	intpending = 0;
-#ifdef BSD
-	sigsetmask(0);
-#endif
-	if (rootshell && iflag)
-		exraise(EXINT);
-	else
-		_exit(128 + SIGINT);
-}
-
-
-
-void
-error2(a, b)
-	char *a, *b;
-	{
-	error("%s: %s", a, b);
-}
-
-
-/*
- * Error is called to raise the error exception.  If the first argument
- * is not NULL then error prints an error message using printf style
- * formatting.  It then raises the error exception.
- */
-
-#ifdef __STDC__
-void
-error(char *msg, ...) {
-#else
-void
-error(va_alist)
-	va_dcl
-	{
-	char *msg;
-#endif
-	va_list ap;
-
-	CLEAR_PENDING_INT;
-	INTOFF;
-#ifdef __STDC__
-	va_start(ap, msg);
-#else
-	va_start(ap);
-	msg = va_arg(ap, char *);
-#endif
-#if DEBUG
-	if (msg)
-		TRACE(("error(\"%s\") pid=%d\n", msg, getpid()));
-	else
-		TRACE(("error(NULL) pid=%d\n", getpid()));
-#endif
-	if (msg) {
-		if (commandname)
-			outfmt(&errout, "%s: ", commandname);
-		doformat(&errout, msg, ap);
-		out2c('\n');
-	}
-	va_end(ap);
-	flushall();
-	exraise(EXERROR);
-}
-
-
-#ifdef notdef	/* These strange error messages only confuse. -- kjb */
-/*
- * Table of error messages.
- */
-
-struct errname {
-	short errcode;		/* error number */
-	short action;		/* operation which encountered the error */
-	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",
-	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",
-	ENOEXEC, ALL,	"not an executable",
-	EISDIR, ALL,	"is a directory",
-/*    EMFILE, ALL,	"too many open files", */
-	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",
-	ETXTBSY, ALL,	"text busy",
-#ifdef SYSV
-	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.
- */
-
-char *
-errmsg(e, action) {
-	const struct errname *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;
-}
-#endif
Index: trunk/minix/commands/ash/error.h
===================================================================
--- trunk/minix/commands/ash/error.h	(revision 9)
+++ 	(revision )
@@ -1,116 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)error.h	5.1 (Berkeley) 3/7/91
- */
-
-/*
- * 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;
-
-/* exceptions */
-#define EXINT 0		/* SIGINT received */
-#define EXERROR 1	/* a generic error */
-#define EXSHELLPROC 2	/* execute a shell procedure */
-
-
-/*
- * 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;
-extern char *commandname;	/* name of command--printed on error */
-
-#define INTOFF suppressint++
-#define INTON if (--suppressint == 0 && intpending) onint(); else
-#define FORCEINTON {suppressint = 0; if (intpending) onint();}
-#define CLEAR_PENDING_INT intpending = 0
-#define int_pending() intpending
-
-#ifdef __STDC__
-void exraise(int);
-void onint(void);
-void error2(char *, char *);
-void error(char *, ...);
-char *errmsg(int, int);
-#else
-void exraise();
-void onint();
-void error2();
-void error();
-char *errmsg();
-#endif
-
-/* Errmsg uses confusingly different messages.  Prefer strerror().  -- kjb */
-#define errmsg(errno, action)	strerror(errno)
-
-
-/*
- * BSD setjmp saves the signal mask, which violates ANSI C and takes time,
- * so we use _setjmp instead.
- */
-
-#ifdef BSD
-#define setjmp(jmploc)	_setjmp(jmploc)
-#define longjmp(jmploc, val)	_longjmp(jmploc, val)
-#endif
Index: trunk/minix/commands/ash/eval.c
===================================================================
--- trunk/minix/commands/ash/eval.c	(revision 9)
+++ 	(revision )
@@ -1,939 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)eval.c	5.3 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-/*
- * 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 "mystring.h"
-#include <sys/types.h>
-#include <signal.h>
-
-
-/* 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 */
-
-
-/* reasons for skipping commands (see comment on breakcmd routine) */
-#define SKIPBREAK 1
-#define SKIPCONT 2
-#define SKIPFUNC 3
-
-MKINIT 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 oexitstatus;		/* saved exit status */
-
-
-#ifdef __STDC__
-STATIC void evalloop(union node *);
-STATIC void evalfor(union node *);
-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 *);
-#else
-STATIC void evalloop();
-STATIC void evalfor();
-STATIC void evalcase();
-STATIC void evalsubshell();
-STATIC void expredir();
-STATIC void evalpipe();
-STATIC void evalcommand();
-STATIC void prehash();
-#endif
-
-
-
-/*
- * Called to reset things after an exception.
- */
-
-#ifdef mkinit
-INCLUDE "eval.h"
-
-RESET {
-	evalskip = 0;
-	loopnest = 0;
-	funcnest = 0;
-}
-
-SHELLPROC {
-	exitstatus = 0;
-}
-#endif
-
-
-
-/*
- * The eval commmand.
- */
-
-evalcmd(argc, argv)  
-	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);
-        }
-        return exitstatus;
-}
-
-
-/*
- * Execute a command or commands contained in a string.
- */
-
-void
-evalstring(s)
-	char *s;
-	{
-	union node *n;
-	struct stackmark smark;
-
-	setstackmark(&smark);
-	setinputstring(s, 1);
-	while ((n = parsecmd(0)) != NEOF) {
-		evaltree(n, 0);
-		popstackmark(&smark);
-	}
-	popfile();
-	popstackmark(&smark);
-}
-
-
-
-/*
- * Evaluate a parse tree.  The value is left in the global variable
- * exitstatus.
- */
-
-void
-evaltree(n, flags)
-	union node *n;
-	{
-	if (n == NULL) {
-		TRACE(("evaltree(NULL) called\n"));
-		return;
-	}
-	TRACE(("evaltree(0x%x: %d) called\n", (int)n, n->type));
-	switch (n->type) {
-	case NSEMI:
-		evaltree(n->nbinary.ch1, 0);
-		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: {
-		int status = 0; 
-
-		evaltree(n->nif.test, EV_TESTED);
-		if (evalskip)
-			goto out;
-		if (exitstatus == 0) {
-			evaltree(n->nif.ifpart, flags);
-			status = exitstatus;
-		} else if (n->nif.elsepart) {
-			evaltree(n->nif.elsepart, flags);
-			status = exitstatus;
-		}
-		exitstatus = status;
-		break;
-	}
-	case NWHILE:
-	case NUNTIL:
-		evalloop(n);
-		break;
-	case NFOR:
-		evalfor(n);
-		break;
-	case NCASE:
-		evalcase(n, flags);
-		break;
-	case NDEFUN:
-		defun(n->narg.text, n->narg.next);
-		exitstatus = 0;
-		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) || (eflag && exitstatus
-	  && !(flags & EV_TESTED) && (n->type == NCMD ||
-	  n->type == NSUBSHELL))) {
-		exitshell(exitstatus);
-	}
-}
-
-
-STATIC void
-evalloop(n)
-	union node *n;
-	{
-	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, 0);
-		status = exitstatus;
-		if (evalskip)
-			goto skipping;
-	}
-	loopnest--;
-	exitstatus = status;
-}
-
-
-
-STATIC void
-evalfor(n)
-	union node *n;
-	{
-	struct arglist arglist;
-	union node *argp;
-	struct strlist *sp;
-	struct stackmark smark;
-
-	setstackmark(&smark);
-	arglist.lastp = &arglist.list;
-	for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
-		oexitstatus = exitstatus;
-		expandarg(argp, &arglist, 1);
-		if (evalskip)
-			goto out;
-	}
-	*arglist.lastp = NULL;
-
-	exitstatus = 0;
-	loopnest++;
-	for (sp = arglist.list ; sp ; sp = sp->next) {
-		setvar(n->nfor.var, sp->text, 0);
-		evaltree(n->nfor.body, 0);
-		if (evalskip) {
-			if (evalskip == SKIPCONT && --skipcount <= 0) {
-				evalskip = 0;
-				continue;
-			}
-			if (evalskip == SKIPBREAK && --skipcount <= 0)
-				evalskip = 0;
-			break;
-		}
-	}
-	loopnest--;
-out:
-	popstackmark(&smark);
-}
-
-
-
-STATIC void
-evalcase(n, flags)
-	union node *n;
-	{
-	union node *cp;
-	union node *patp;
-	struct arglist arglist;
-	struct stackmark smark;
-
-	setstackmark(&smark);
-	arglist.lastp = &arglist.list;
-        oexitstatus = exitstatus;
-	expandarg(n->ncase.expr, &arglist, 0);
-	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);
-				}
-				goto out;
-			}
-		}
-	}
-out:
-	popstackmark(&smark);
-}
-
-
-
-/*
- * Kick off a subshell to evaluate a tree.
- */
-
-STATIC void
-evalsubshell(n, flags)
-	union node *n;
-	{
-	struct job *jp;
-	int backgnd = (n->type == NBACKGND);
-
-	expredir(n->nredir.redirect);
-	jp = makejob(n, 1);
-	if (forkshell(jp, n, backgnd) == 0) {
-		if (backgnd)
-			flags &=~ EV_TESTED;
-		redirect(n->nredir.redirect, 0);
-		evaltree(n->nredir.n, flags | EV_EXIT);	/* never returns */
-	}
-	if (! backgnd) {
-		INTOFF;
-		exitstatus = waitforjob(jp);
-		INTON;
-	}
-}
-
-
-
-/*
- * Compute the names of the files in a redirection list.
- */
-
-STATIC void
-expredir(n)
-	union node *n;
-	{
-	register union node *redir;
-
-	for (redir = n ; redir ; redir = redir->nfile.next) {
-		oexitstatus = exitstatus;
-		if (redir->type == NFROM
-		 || redir->type == NTO
-		 || redir->type == NAPPEND) {
-			struct arglist fn;
-			fn.lastp = &fn.list;
-			expandarg(redir->nfile.fname, &fn, 0);
-			redir->nfile.expfname = fn.list->text;
-		}
-	}
-}
-
-
-
-/*
- * 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(n)
-	union node *n;
-	{
-	struct job *jp;
-	struct nodelist *lp;
-	int pipelen;
-	int prevfd;
-	int pip[2];
-
-	TRACE(("evalpipe(0x%x) called\n", (int)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 (pipe(pip) < 0) {
-				close(prevfd);
-				error("Pipe call failed");
-			}
-		}
-		if (forkshell(jp, lp->n, n->npipe.backgnd) == 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]);
-	}
-	INTON;
-	if (n->npipe.backgnd == 0) {
-		INTOFF;
-		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(n, result)
-	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) {
-		/* `` */
-	} else
-	if (n->type == NCMD) {
-                exitstatus = oexitstatus;
-		evalcommand(n, EV_BACKCMD, result);
-	} else {
-		if (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]);
-			}
-			evaltree(n, EV_EXIT);
-		}
-		close(pip[1]);
-		result->fd = pip[0];
-		result->jp = jp;
-	}
-	popstackmark(&smark);
-	TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
-		result->fd, result->buf, result->nleft, result->jp));
-}
-
-
-
-/*
- * Execute a simple command.
- */
-
-STATIC void
-evalcommand(cmd, flags, backcmd)
-	union node *cmd;
-	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;
-	register char *p;
-	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;
-
-	/* First expand the arguments. */
-	TRACE(("evalcommand(0x%x, %d) called\n", (int)cmd, flags));
-	setstackmark(&smark);
-	arglist.lastp = &arglist.list;
-	varlist.lastp = &varlist.list;
-	varflag = 1;
-        oexitstatus = exitstatus;
-	exitstatus = 0;
-	for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
-		p = argp->narg.text;
-		if (varflag && is_name(*p)) {
-			do {
-				p++;
-			} while (is_in_name(*p));
-			if (*p == '=') {
-				expandarg(argp, &varlist, 0);
-				continue;
-			}
-		}
-		expandarg(argp, &arglist, 1);
-		varflag = 0;
-	}
-	*arglist.lastp = NULL;
-	*varlist.lastp = NULL;
-	expredir(cmd->ncmd.redirect);
-	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)
-		*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 == 1) {
-		outc('+', &errout);
-		for (sp = varlist.list ; sp ; sp = sp->next) {
-			outc(' ', &errout);
-			out2str(sp->text);
-		}
-		for (sp = arglist.list ; sp ; sp = sp->next) {
-			outc(' ', &errout);
-			out2str(sp->text);
-		}
-		outc('\n', &errout);
-		flushout(&errout);
-	}
-
-	/* Now locate the command. */
-	if (argc == 0) {
-		cmdentry.cmdtype = CMDBUILTIN;
-		cmdentry.u.index = BLTINCMD;
-	} else {
-		find_command(argv[0], &cmdentry, 1);
-		if (cmdentry.cmdtype == CMDUNKNOWN) {	/* command not found */
-			exitstatus = 2;
-			flushout(&errout);
-			popstackmark(&smark);
-			return;
-		}
-		/* implement the bltin builtin here */
-		if (cmdentry.cmdtype == CMDBUILTIN && cmdentry.u.index == BLTINCMD) {
-			for (;;) {
-				argv++;
-				if (--argc == 0)
-					break;
-				if ((cmdentry.u.index = find_builtin(*argv)) < 0) {
-					outfmt(&errout, "%s: not found\n", *argv);
-					exitstatus = 2;
-					flushout(&errout);
-					popstackmark(&smark);
-					return;
-				}
-				if (cmdentry.u.index != BLTINCMD)
-					break;
-			}
-		}
-	}
-
-	/* 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.u.index == DOTCMD
-		 || cmdentry.u.index == EVALCMD)) {
-		jp = makejob(cmd, 1);
-		mode = cmd->ncmd.backgnd;
-		if (flags & EV_BACKCMD) {
-			mode = FORK_NOJOB;
-			if (pipe(pip) < 0)
-				error("Pipe call failed");
-		}
-		if (forkshell(jp, cmd, mode) != 0)
-			goto parent;	/* at end of routine */
-		if (flags & EV_BACKCMD) {
-			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. */
-	if (cmdentry.cmdtype == CMDFUNCTION) {
-		trputs("Shell function:  ");  trargs(argv);
-		redirect(cmd->ncmd.redirect, REDIR_PUSH);
-		saveparam = shellparam;
-		shellparam.malloc = 0;
-		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((struct shparam *)&saveparam);
-			else {
-				freeparam(&shellparam);
-				shellparam = saveparam;
-			}
-			poplocalvars();
-			localvars = savelocalvars;
-			handler = savehandler;
-			longjmp(handler->loc, 1);
-		}
-		savehandler = handler;
-		handler = &jmploc;
-		for (sp = varlist.list ; sp ; sp = sp->next)
-			mklocal(sp->text);
-		funcnest++;
-		if (flags & EV_TESTED)
-			evaltree(cmdentry.u.func, EV_TESTED);
-		else
-			evaltree(cmdentry.u.func, 0);
-		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);
-	} else if (cmdentry.cmdtype == CMDBUILTIN) {
-		trputs("builtin command:  ");  trargs(argv);
-		mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
-		if (flags == EV_BACKCMD) {
-			memout.nleft = 0;
-			memout.nextc = memout.buf;
-			memout.bufsize = 64;
-			mode |= REDIR_BACKQ;
-		}
-		redirect(cmd->ncmd.redirect, mode);
-		savecmdname = commandname;
-		cmdenviron = varlist.list;
-		e = -1;
-		if (setjmp(jmploc.loc)) {
-			e = exception;
-			exitstatus = (e == EXINT)? SIGINT+128 : 2;
-			goto cmddone;
-		}
-		savehandler = handler;
-		handler = &jmploc;
-		commandname = argv[0];
-		argptr = argv + 1;
-		optptr = NULL;			/* initialize nextopt */
-		exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
-		flushall();
-cmddone:
-		out1 = &output;
-		out2 = &errout;
-		freestdout();
-		if (e != EXSHELLPROC) {
-			commandname = savecmdname;
-			if (flags & EV_EXIT) {
-				exitshell(exitstatus);
-			}
-		}
-		handler = savehandler;
-		if (e != -1) {
-			if (e != EXERROR || cmdentry.u.index == BLTINCMD
-					       || cmdentry.u.index == DOTCMD
-					       || cmdentry.u.index == EVALCMD
-					       || cmdentry.u.index == EXECCMD)
-				exraise(e);
-			FORCEINTON;
-		}
-		if (cmdentry.u.index != EXECCMD)
-			popredir();
-		if (flags == EV_BACKCMD) {
-			backcmd->buf = memout.buf;
-			backcmd->nleft = memout.nextc - memout.buf;
-			memout.buf = NULL;
-		}
-	} else {
-		trputs("normal command:  ");  trargs(argv);
-		clearredir();
-		redirect(cmd->ncmd.redirect, 0);
-		if (varlist.list) {
-			p = stalloc(strlen(pathval()) + 1);
-			scopy(pathval(), p);
-		} else {
-			p = pathval();
-		}
-		for (sp = varlist.list ; sp ; sp = sp->next)
-			setvareq(sp->text, VEXPORT|VSTACK);
-		envp = environment();
-		shellexec(argv, envp, p, cmdentry.u.index);
-		/*NOTREACHED*/
-	}
-	goto out;
-
-parent:	/* parent process gets here (if we forked) */
-	if (mode == 0) {	/* argument to fork */
-		INTOFF;
-		exitstatus = waitforjob(jp);
-		INTON;
-	} else if (mode == 2) {
-		backcmd->fd = pip[0];
-		close(pip[1]);
-		backcmd->jp = jp;
-	}
-
-out:
-	if (lastarg)
-		setvar("_", lastarg, 0);
-	popstackmark(&smark);
-}
-
-
-
-/*
- * 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(n)
-	union node *n;
-	{
-	struct cmdentry entry;
-
-	if (n->type == NCMD && goodname(n->ncmd.args->narg.text))
-		find_command(n->ncmd.args->narg.text, &entry, 0);
-}
-
-
-
-/*
- * Builtin commands.  Builtin commands whose functions are closely
- * tied to evaluation are implemented here.
- */
-
-/*
- * No command given, or a bltin command with no arguments.  Set the
- * specified variables.
- */
-
-bltincmd(argc, argv)  char **argv; {
-	listsetvar(cmdenviron);
-	return 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.
- */
-
-breakcmd(argc, argv)  char **argv; {
-	int n;
-
-	n = 1;
-	if (argc > 1)
-		n = number(argv[1]);
-	if (n > loopnest)
-		n = loopnest;
-	if (n > 0) {
-		evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
-		skipcount = n;
-	}
-	return 0;
-}
-
-
-/*
- * The return command.
- */
-
-returncmd(argc, argv)  char **argv; {
-	int ret;
-
-	ret = oexitstatus;
-	if (argc > 1)
-		ret = number(argv[1]);
-	if (funcnest) {
-		evalskip = SKIPFUNC;
-		skipcount = 1;
-	}
-	return ret;
-}
-
-
-truecmd(argc, argv)  char **argv; {
-	return strcmp(argv[0], "false") == 0 ? 1 : 0;
-}
-
-
-execcmd(argc, argv)  char **argv; {
-	if (argc > 1) {
-		iflag = 0;		/* exit on error */
-		setinteractive(0);
-#if JOBS
-		jflag = 0;
-		setjobctl(0);
-#endif
-		shellexec(argv + 1, environment(), pathval(), 0);
-
-	}
-	return 0;
-}
Index: trunk/minix/commands/ash/eval.h
===================================================================
--- trunk/minix/commands/ash/eval.h	(revision 9)
+++ 	(revision )
@@ -1,65 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)eval.h	5.2 (Berkeley) 4/12/91
- */
-
-extern char *commandname;	/* currently executing command */
-extern int exitstatus;		/* exit status of last 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 */
-};
-
-
-#ifdef __STDC__
-void evalstring(char *);
-union node;	/* BLETCH for ansi C */
-void evaltree(union node *, int);
-void evalbackcmd(union node *, struct backcmd *);
-#else
-void evalstring();
-void evaltree();
-void evalbackcmd();
-#endif
-
-/* in_function returns nonzero if we are currently evaluating a function */
-#define in_function()	funcnest
-extern int funcnest;
Index: trunk/minix/commands/ash/exec.c
===================================================================
--- trunk/minix/commands/ash/exec.c	(revision 9)
+++ 	(revision )
@@ -1,824 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)exec.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-/*
- * 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 <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <limits.h>
-
-
-#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 */
-
-
-#ifdef __STDC__
-STATIC void tryexec(char *, char **, char **);
-STATIC void execinterp(char **, char **);
-STATIC void printentry(struct tblentry *);
-STATIC void clearcmdentry(int);
-STATIC struct tblentry *cmdlookup(char *, int);
-STATIC void delete_cmd_entry(void);
-#else
-STATIC void tryexec();
-STATIC void execinterp();
-STATIC void printentry();
-STATIC void clearcmdentry();
-STATIC struct tblentry *cmdlookup();
-STATIC void delete_cmd_entry();
-#endif
-
-
-
-/*
- * Exec a program.  Never returns.  If you change this routine, you may
- * have to change the find_command routine as well.
- */
-
-void
-shellexec(argv, envp, path, index)
-	char **argv, **envp;
-	char *path;
-	{
-	char *cmdname;
-	int e;
-
-	if (strchr(argv[0], '/') != NULL) {
-		tryexec(argv[0], argv, envp);
-		e = errno;
-	} else {
-		e = ENOENT;
-		while ((cmdname = padvance(&path, argv[0])) != NULL) {
-			if (--index < 0 && pathopt == NULL) {
-				tryexec(cmdname, argv, envp);
-				if (errno != ENOENT && errno != ENOTDIR)
-					e = errno;
-			}
-			stunalloc(cmdname);
-		}
-	}
-	error2(argv[0], errmsg(e, E_EXEC));
-}
-
-
-STATIC void
-tryexec(cmd, argv, envp)
-	char *cmd;
-	char **argv;
-	char **envp;
-	{
-	int e;
-	char *p;
-
-#ifdef SYSV
-	do {
-		execve(cmd, argv, envp);
-	} while (errno == EINTR);
-#else
-	execve(cmd, argv, envp);
-#endif
-#if HASHBANG
-	e = errno;
-	if (e == ENOEXEC) {
-		initshellproc();
-		setinputfile(cmd, 0);
-		commandname = arg0 = savestr(argv[0]);
-#ifndef BSD
-		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);
-		/*NOTREACHED*/
-	}
-	errno = e;
-#endif
-}
-
-
-#if !defined(BSD) && HASHBANG
-/*
- * 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(argv, envp)
-	char **argv, **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 !__minix
-	if (ap == newargs + 1) {	/* if no args, maybe no exec is needed */
-		p = newargs[0];
-		for (;;) {
-			if (equal(p, "sh") || equal(p, "ash")) {
-				return;
-			}
-			while (*p != '/') {
-				if (*p == '\0')
-					goto break2;
-				p++;
-			}
-			p++;
-		}
-break2:;
-	}
-#endif
-	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++);
-	shellexec(new, envp, pathval(), 0);
-}
-#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.
- */
-
-char *pathopt;
-
-char *
-padvance(path, name)
-	char **path;
-	char *name;
-	{
-	register char *p, *q;
-	char *start;
-	int len;
-
-	if (*path == NULL)
-		return NULL;
-	start = *path;
-	for (p = start ; *p && *p != ':' && *p != '%' ; p++);
-	len = p - start + strlen(name) + 2;	/* "2" is for '/' and '\0' */
-	while (stackblocksize() < len)
-		growstackblock();
-	q = stackblock();
-	if (p != start) {
-		bcopy(start, q, p - start);
-		q += p - start;
-		*q++ = '/';
-	}
-	strcpy(q, name);
-	pathopt = NULL;
-	if (*p == '%') {
-		pathopt = ++p;
-		while (*p && *p != ':')  p++;
-	}
-	if (*p == ':')
-		*path = p + 1;
-	else
-		*path = NULL;
-	return stalloc(len);
-}
-
-
-
-/*** Command hashing code ***/
-
-
-hashcmd(argc, argv)  char **argv; {
-	struct tblentry **pp;
-	struct tblentry *cmdp;
-	int c;
-	int verbose;
-	struct cmdentry entry;
-	char *name;
-
-	if (argc <= 1) {
-		for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
-			for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-				printentry(cmdp);
-			}
-		}
-		return 0;
-	}
-	verbose = 0;
-	while ((c = nextopt("rv")) != '\0') {
-		if (c == 'r') {
-			clearcmdentry(0);
-		} else if (c == 'v') {
-			verbose++;
-		}
-	}
-	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, 1);
-		if (verbose) {
-			if (entry.cmdtype != CMDUNKNOWN) {	/* if no error msg */
-				cmdp = cmdlookup(name, 0);
-				printentry(cmdp);
-			}
-			flushall();
-		}
-		argptr++;
-	}
-	return 0;
-}
-
-
-STATIC void
-printentry(cmdp)
-	struct tblentry *cmdp;
-	{
-	int index;
-	char *path;
-	char *name;
-
-	if (cmdp->cmdtype == CMDNORMAL) {
-		index = cmdp->param.index;
-		path = pathval();
-		do {
-			name = padvance(&path, cmdp->cmdname);
-			stunalloc(name);
-		} while (--index >= 0);
-		out1str(name);
-	} else if (cmdp->cmdtype == CMDBUILTIN) {
-		out1fmt("builtin %s", cmdp->cmdname);
-	} else if (cmdp->cmdtype == CMDFUNCTION) {
-		out1fmt("function %s", cmdp->cmdname);
-#if DEBUG
-	} else {
-		error("internal error: cmdtype %d", cmdp->cmdtype);
-#endif
-	}
-	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(name, entry, printerr)
-	char *name;
-	struct cmdentry *entry;
-	{
-	struct tblentry *cmdp;
-	int index;
-	int prev;
-	char *path;
-	char *fullname;
-	struct stat statb;
-	int e;
-	int i;
-
-	/* If name contains a slash, don't use the hash table */
-	if (strchr(name, '/') != NULL) {
-		entry->cmdtype = CMDNORMAL;
-		entry->u.index = 0;
-		return;
-	}
-
-	/* If name is in the table, and not invalidated by cd, we're done */
-	if ((cmdp = cmdlookup(name, 0)) != NULL && cmdp->rehash == 0)
-		goto success;
-
-	/* If %builtin not in path, check for builtin next */
-	if (builtinloc < 0 && (i = find_builtin(name)) >= 0) {
-		INTOFF;
-		cmdp = cmdlookup(name, 1);
-		cmdp->cmdtype = CMDBUILTIN;
-		cmdp->param.index = i;
-		INTON;
-		goto 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;
-	}
-
-	path = pathval();
-	e = ENOENT;
-	index = -1;
-loop:
-	while ((fullname = padvance(&path, name)) != NULL) {
-		stunalloc(fullname);
-		index++;
-		if (pathopt) {
-			if (prefix("builtin", pathopt)) {
-				if ((i = find_builtin(name)) < 0)
-					goto loop;
-				INTOFF;
-				cmdp = cmdlookup(name, 1);
-				cmdp->cmdtype = CMDBUILTIN;
-				cmdp->param.index = i;
-				INTON;
-				goto success;
-			} else if (prefix("func", pathopt)) {
-				/* handled below */
-			} else {
-				goto loop;	/* ignore unimplemented options */
-			}
-		}
-		/* if rehash, don't redo absolute path names */
-		if (fullname[0] == '/' && index <= prev) {
-			if (index < prev)
-				goto loop;
-			TRACE(("searchexec \"%s\": no change\n", name));
-			goto success;
-		}
-		while (stat(fullname, &statb) < 0) {
-#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 ((statb.st_mode & S_IFMT) != S_IFREG)
-			goto loop;
-		if (pathopt) {		/* this is a %func directory */
-			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;
-		}
-		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 __minix_vmd || defined(BSD)
-			gid_t group_list[NGROUPS_MAX];
-			int ngroups, i;
-
-			ngroups = getgroups(NGROUPS_MAX, group_list);
-
-			for (i = 0; i < ngroups; i++) {
-				if (statb.st_gid == group_list[i]) break;
-			}
-			if (i < ngroups) {
-				if ((statb.st_mode & 010) == 0)
-					goto loop;
-			} else
-#endif
-			if ((statb.st_mode & 01) == 0)
-				goto loop;
-		}
-		TRACE(("searchexec \"%s\" returns \"%s\"\n", name, fullname));
-		INTOFF;
-		cmdp = cmdlookup(name, 1);
-		cmdp->cmdtype = CMDNORMAL;
-		cmdp->param.index = index;
-		INTON;
-		goto success;
-	}
-
-	/* We failed.  If there was an entry for this command, delete it */
-	if (cmdp)
-		delete_cmd_entry();
-	if (printerr)
-		outfmt(out2, "%s: %s\n", name, errmsg(e, E_EXEC));
-	entry->cmdtype = CMDUNKNOWN;
-	return;
-
-success:
-	cmdp->rehash = 0;
-	entry->cmdtype = cmdp->cmdtype;
-	entry->u = cmdp->param;
-}
-
-
-
-/*
- * Search the table of builtin commands.
- */
-
-int
-find_builtin(name)
-	char *name;
-	{
-	const register struct builtincmd *bp;
-
-	for (bp = builtincmd ; bp->name ; bp++) {
-		if (*bp->name == *name && equal(bp->name, name))
-			return bp->code;
-	}
-	return -1;
-}
-
-
-
-/*
- * Called when a cd is done.  Marks all commands so the next time they
- * are executed they will be rehashed.
- */
-
-void
-hashcd() {
-	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;
-		}
-	}
-}
-
-
-
-/*
- * 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(newval)
-	char *newval;
-	{
-	char *old, *new;
-	int index;
-	int firstchange;
-	int bltin;
-
-	old = pathval();
-	new = newval;
-	firstchange = 9999;	/* assume no change */
-	index = 0;
-	bltin = -1;
-	for (;;) {
-		if (*old != *new) {
-			firstchange = index;
-			if (*old == '\0' && *new == ':'
-			 || *old == ':' && *new == '\0')
-				firstchange++;
-			old = new;	/* ignore subsequent differences */
-		}
-		if (*new == '\0')
-			break;
-		if (*new == '%' && bltin < 0 && prefix("builtin", new + 1))
-			bltin = index;
-		if (*new == ':') {
-			index++;
-		}
-		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(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();
-
-SHELLPROC {
-	deletefuncs();
-}
-#endif
-
-void
-deletefuncs() {
-	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(name, add)
-	char *name;
-	{
-	int hashval;
-	register 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() {
-	struct tblentry *cmdp;
-
-	INTOFF;
-	cmdp = *lastcmdentry;
-	*lastcmdentry = cmdp->next;
-	ckfree(cmdp);
-	INTON;
-}
-
-
-
-#ifdef notdef
-void
-getcmdentry(name, entry)
-	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.
- */
-
-void
-addcmdentry(name, entry)
-	char *name;
-	struct cmdentry *entry;
-	{
-	struct tblentry *cmdp;
-
-	INTOFF;
-	cmdp = cmdlookup(name, 1);
-	if (cmdp->cmdtype == CMDFUNCTION) {
-		freefunc(cmdp->param.func);
-	}
-	cmdp->cmdtype = entry->cmdtype;
-	cmdp->param = entry->u;
-	INTON;
-}
-
-
-/*
- * Define a shell function.
- */
-
-void
-defun(name, func)
-	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.
- */
-
-void
-unsetfunc(name)
-	char *name;
-	{
-	struct tblentry *cmdp;
-
-	if ((cmdp = cmdlookup(name, 0)) != NULL && cmdp->cmdtype == CMDFUNCTION) {
-		freefunc(cmdp->param.func);
-		delete_cmd_entry();
-	}
-}
Index: trunk/minix/commands/ash/exec.h
===================================================================
--- trunk/minix/commands/ash/exec.h	(revision 9)
+++ 	(revision )
@@ -1,75 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)exec.h	5.1 (Berkeley) 3/7/91
- */
-
-/* values of cmdtype */
-#define CMDUNKNOWN -1		/* no entry in table for command */
-#define CMDNORMAL 0		/* command is an executable program */
-#define CMDBUILTIN 1		/* command is a shell builtin */
-#define CMDFUNCTION 2		/* command is a shell function */
-
-
-struct cmdentry {
-	int cmdtype;
-	union param {
-		int index;
-		union node *func;
-	} u;
-};
-
-
-extern char *pathopt;		/* set by padvance */
-
-#ifdef __STDC__
-void shellexec(char **, char **, char *, int);
-char *padvance(char **, char *);
-void find_command(char *, struct cmdentry *, int);
-int find_builtin(char *);
-void hashcd(void);
-void changepath(char *);
-void defun(char *, union node *);
-void unsetfunc(char *);
-#else
-void shellexec();
-char *padvance();
-void find_command();
-int find_builtin();
-void hashcd();
-void changepath();
-void defun();
-void unsetfunc();
-#endif
Index: trunk/minix/commands/ash/expand.c
===================================================================
--- trunk/minix/commands/ash/expand.c	(revision 9)
+++ 	(revision )
@@ -1,1159 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)expand.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * 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 <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <dirent.h>
-#if USEGETPW
-#include <pwd.h>
-#endif
-
-/*
- * 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 nulonly;		/* 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 */
-#if UDIR || TILDE
-/*
- * Set if the last argument processed had /u/logname or ~logname expanded.
- * This variable is read by the cd command.
- */
-int didudir;
-#endif
-
-#ifdef __STDC__
-STATIC void argstr(char *, int);
-STATIC void expbackq(union node *, int, int);
-STATIC char *evalvar(char *, int);
-STATIC int varisset(int);
-STATIC void varvalue(int, int, int);
-STATIC void recordregion(int, int, int);
-STATIC void ifsbreakup(char *, struct arglist *);
-STATIC void expandmeta(struct strlist *);
-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 *);
-#else
-STATIC void argstr();
-STATIC void expbackq();
-STATIC char *evalvar();
-STATIC int varisset();
-STATIC void varvalue();
-STATIC void recordregion();
-STATIC void ifsbreakup();
-STATIC void expandmeta();
-STATIC void expmeta();
-STATIC void addfname();
-STATIC struct strlist *expsort();
-STATIC struct strlist *msort();
-STATIC int pmatch();
-#endif
-#if UDIR || TILDE
-#ifdef __STDC__
-STATIC char *expudir(char *);
-#else
-STATIC char *expudir();
-#endif
-#endif /* UDIR || TILDE */
-
-
-
-/*
- * Expand shell variables and backquotes inside a here document.
- */
-
-void
-expandhere(arg, fd)
-	union node *arg;	/* the document */
-	int fd;			/* where to write the expanded version */
-	{
-	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 full is true,
- * perform splitting and file name expansion.  When arglist is NULL, perform
- * here document expansion.
- */
-
-void
-expandarg(arg, arglist, full)
-	union node *arg;
-	struct arglist *arglist;
-	{
-	struct strlist *sp;
-	char *p;
-
-#if UDIR || TILDE
-	didudir = 0;
-#endif
-	argbackq = arg->narg.backquote;
-	STARTSTACKSTR(expdest);
-	ifsfirst.next = NULL;
-	ifslastp = NULL;
-	argstr(arg->narg.text, full);
-	if (arglist == NULL)
-		return;			/* here document expanded */
-	STPUTC('\0', expdest);
-	p = grabstackstr(expdest);
-	exparg.lastp = &exparg.list;
-	if (full) {
-		ifsbreakup(p, &exparg);
-		*exparg.lastp = NULL;
-		exparg.lastp = &exparg.list;
-		expandmeta(exparg.list);
-	} else {
-		sp = (struct strlist *)stalloc(sizeof (struct strlist));
-		sp->text = p;
-		*exparg.lastp = sp;
-		exparg.lastp = &sp->next;
-	}
-	while (ifsfirst.next != NULL) {
-		struct ifsregion *ifsp;
-		INTOFF;
-		ifsp = ifsfirst.next->next;
-		ckfree(ifsfirst.next);
-		ifsfirst.next = ifsp;
-		INTON;
-	}
-	*exparg.lastp = NULL;
-	if (exparg.list) {
-		*arglist->lastp = exparg.list;
-		arglist->lastp = exparg.lastp;
-	}
-}
-
-
-
-/*
- * Perform variable and command substitution.  If full is set, output CTLESC
- * characters to allow for further processing.  If full is not set, treat
- * $@ like $* since no splitting will be performed.
- */
-
-STATIC void
-argstr(p, full)
-	register char *p;
-	{
-	char c;
-
-	for (;;) {
-		switch (c = *p++) {
-		case '\0':
-		case CTLENDVAR:
-			goto breakloop;
-		case CTLESC:
-			if (full)
-				STPUTC(c, expdest);
-			c = *p++;
-			STPUTC(c, expdest);
-			break;
-		case CTLVAR:
-			p = evalvar(p, full);
-			break;
-		case CTLBACKQ:
-		case CTLBACKQ|CTLQUOTE:
-			expbackq(argbackq->n, c & CTLQUOTE, full);
-			argbackq = argbackq->next;
-			break;
-		default:
-			STPUTC(c, expdest);
-		}
-	}
-breakloop:;
-}
-
-
-/*
- * Expand stuff in backwards quotes.
- */
-
-STATIC void
-expbackq(cmd, quoted, full)
-	union node *cmd;
-	{
-	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;
-
-	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 (full && syntax[lastc] == CCTL)
-				STPUTC(CTLESC, dest);
-			STPUTC(lastc, dest);
-		}
-	}
-	if (lastc == '\n') {
-		STUNPUTC(dest);
-	}
-	if (in.fd >= 0)
-		close(in.fd);
-	if (in.buf)
-		ckfree(in.buf);
-	if (in.jp)
-		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;
-}
-
-
-
-/*
- * Expand a variable, and return a pointer to the next character in the
- * input string.
- */
-
-STATIC char *
-evalvar(p, full)
-	char *p;
-	{
-	int subtype;
-	int flags;
-	char *var;
-	char *val;
-	int c;
-	int set;
-	int special;
-	int startloc;
-
-	flags = *p++;
-	subtype = flags & VSTYPE;
-	var = p;
-	special = 0;
-	if (! is_name(*p))
-		special = 1;
-	p = strchr(p, '=') + 1;
-again: /* jump here after setting a variable with ${var=text} */
-	if (special) {
-		set = varisset(*var);
-		val = NULL;
-	} else {
-		val = lookupvar(var);
-		if (val == NULL || (flags & VSNUL) && val[0] == '\0') {
-			val = NULL;
-			set = 0;
-		} else
-			set = 1;
-	}
-	startloc = expdest - stackblock();
-	if (set && subtype != VSPLUS) {
-		/* insert the value of the variable */
-		if (special) {
-			varvalue(*var, flags & VSQUOTE, full);
-		} else {
-			char const *syntax = (flags & VSQUOTE)? DQSYNTAX : BASESYNTAX;
-
-			while (*val) {
-				if (full && syntax[*val] == CCTL)
-					STPUTC(CTLESC, expdest);
-				STPUTC(*val++, expdest);
-			}
-		}
-	}
-	if (subtype == VSPLUS)
-		set = ! set;
-	if (((flags & VSQUOTE) == 0 || (*var == '@' && shellparam.nparam != 1))
-	 && (set || subtype == VSNORMAL))
-		recordregion(startloc, expdest - stackblock(), flags & VSQUOTE);
-	if (! set && subtype != VSNORMAL) {
-		if (subtype == VSPLUS || subtype == VSMINUS) {
-			argstr(p, full);
-		} else {
-			char *startp;
-			int saveherefd = herefd;
-			herefd = -1;
-			argstr(p, 0);
-			STACKSTRNUL(expdest);
-			herefd = saveherefd;
-			startp = stackblock() + startloc;
-			if (subtype == VSASSIGN) {
-				setvar(var, startp, 0);
-				STADJUST(startp - expdest, expdest);
-				flags &=~ VSNUL;
-				goto again;
-			}
-			/* subtype == VSQUESTION */
-			if (*p != CTLENDVAR) {
-				outfmt(&errout, "%s\n", startp);
-				error((char *)NULL);
-			}
-			error("%.*s: parameter %snot set", p - var - 1,
-				var, (flags & VSNUL)? "null or " : nullstr);
-		}
-	}
-	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) {
-					if (argbackq != NULL)
-						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(name)
-	char name;
-	{
-	char **ap;
-
-	if (name == '!') {
-		if (backgndpid == -1)
-			return 0;
-	} else if (name == '@' || name == '*') {
-		if (*shellparam.p == NULL)
-			return 0;
-	} else if ((unsigned)(name -= '1') <= '9' - '1') {
-		ap = shellparam.p;
-		do {
-			if (*ap++ == NULL)
-				return 0;
-		} while (--name >= 0);
-	}
-	return 1;
-}
-
-
-
-/*
- * Add the value of a specialized variable to the stack string.
- */
-
-STATIC void
-varvalue(name, quoted, allow_split)
-	char name;
-	{
-	int num;
-	char temp[32];
-	char *p;
-	int i;
-	extern int oexitstatus;
-	char sep;
-	char **ap;
-	char const *syntax;
-
-	switch (name) {
-	case '$':
-		num = rootpid;
-		goto numvar;
-	case '?':
-		num = oexitstatus;
-		goto numvar;
-	case '#':
-		num = shellparam.nparam;
-		goto numvar;
-	case '!':
-		num = backgndpid;
-numvar:
-		p = temp + 31;
-		temp[31] = '\0';
-		do {
-			*--p = num % 10 + '0';
-		} while ((num /= 10) != 0);
-		while (*p)
-			STPUTC(*p++, expdest);
-		break;
-	case '-':
-		for (i = 0 ; optchar[i] ; i++) {
-			if (optval[i])
-				STPUTC(optchar[i], expdest);
-		}
-		break;
-	case '@':
-		if (allow_split) {
-			sep = '\0';
-			goto allargs;
-		}
-		/* fall through */			
-	case '*':
-		sep = ' ';
-allargs:
-		/* Only emit CTLESC if we will do further processing,
-		   i.e. if allow_split is set.  */
-		syntax = quoted && allow_split ? DQSYNTAX : BASESYNTAX;
-		for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
-			/* should insert CTLESC characters */
-			while (*p) {
-				if (syntax[*p] == CCTL)
-					STPUTC(CTLESC, expdest);
-				STPUTC(*p++, expdest);
-			}
-			if (*ap)
-				STPUTC(sep, expdest);
-		}
-		break;
-	case '0':
-		p = arg0;
-string:
-		/* Only emit CTLESC if we will do further processing,
-		   i.e. if allow_split is set.  */
-		syntax = quoted && allow_split ? DQSYNTAX : BASESYNTAX;
-		while (*p) {
-			if (syntax[*p] == CCTL)
-				STPUTC(CTLESC, expdest);
-			STPUTC(*p++, expdest);
-		}
-		break;
-	default:
-		if ((unsigned)(name -= '1') <= '9' - '1') {
-			p = shellparam.p[name];
-			goto string;
-		}
-		break;
-	}
-}
-
-
-
-/*
- * Record the the fact that we have to scan this region of the
- * string for IFS characters.
- */
-
-STATIC void
-recordregion(start, end, nulonly) {
-	register struct ifsregion *ifsp;
-
-	if (ifslastp == NULL) {
-		ifsp = &ifsfirst;
-	} else {
-		ifsp = (struct ifsregion *)ckmalloc(sizeof (struct ifsregion));
-		ifslastp->next = ifsp;
-	}
-	ifslastp = ifsp;
-	ifslastp->next = NULL;
-	ifslastp->begoff = start;
-	ifslastp->endoff = end;
-	ifslastp->nulonly = nulonly;
-}
-
-
-
-/*
- * 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(string, arglist)
-	char *string;
-	struct arglist *arglist;
-	{
-	struct ifsregion *ifsp;
-	struct strlist *sp;
-	char *start;
-	register char *p;
-	char *q;
-	char *ifs;
-
-	start = string;
-	if (ifslastp != NULL) {
-		ifsp = &ifsfirst;
-		do {
-			p = string + ifsp->begoff;
-			ifs = ifsp->nulonly? nullstr : ifsval();
-			while (p < string + ifsp->endoff) {
-				q = p;
-				if (*p == CTLESC)
-					p++;
-				if (strchr(ifs, *p++)) {
-					if (q > start || *ifs != ' ') {
-						*q = '\0';
-						sp = (struct strlist *)stalloc(sizeof *sp);
-						sp->text = start;
-						*arglist->lastp = sp;
-						arglist->lastp = &sp->next;
-					}
-					if (*ifs == ' ') {
-						for (;;) {
-							if (p >= string + ifsp->endoff)
-								break;
-							q = p;
-							if (*p == CTLESC)
-								p++;
-							if (strchr(ifs, *p++) == NULL) {
-								p = q;
-								break;
-							}
-						}
-					}
-					start = p;
-				}
-			}
-		} while ((ifsp = ifsp->next) != NULL);
-		if (*start || (*ifs != ' ' && start > string)) {
-			sp = (struct strlist *)stalloc(sizeof *sp);
-			sp->text = start;
-			*arglist->lastp = sp;
-			arglist->lastp = &sp->next;
-		}
-	} else {
-		sp = (struct strlist *)stalloc(sizeof *sp);
-		sp->text = start;
-		*arglist->lastp = sp;
-		arglist->lastp = &sp->next;
-	}
-}
-
-
-
-/*
- * 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(str)
-	struct strlist *str;
-	{
-	char *p;
-	struct strlist **savelastp;
-	struct strlist *sp;
-	char c;
-
-	while (str) {
-		if (fflag)
-			goto nometa;
-		p = str->text;
-#if UDIR
-		if (p[0] == '/' && p[1] == 'u' && p[2] == '/')
-			str->text = p = expudir(p);
-#endif
-#if TILDE
-		if (p[0] == '~')
-			str->text = p = expudir(p);
-#endif
-		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) {
-			if (! zflag) {
-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;
-	}
-}
-
-
-#if UDIR || TILDE
-/*
- * UDIR: Expand /u/username into the home directory for the specified user.
- * TILDE: Expand ~username into the home directory for the specified user.
- * We hope not to use the getpw stuff here, because then we would have to load
- * in stdio and who knows what else.  With networked password files there is
- * no choice alas.
- */
-
-#define MAXLOGNAME 32
-#define MAXPWLINE 128
-
-char *pfgets();
-
-
-STATIC char *
-expudir(path)
-	char *path;
-	{
-	register char *p, *q, *r;
-	char name[MAXLOGNAME];
-	char line[MAXPWLINE];
-	int i;
-#if USEGETPW
-	struct passwd *pw;
-#endif
-
-	r = path;				/* result on failure */
-	p = r + (*r == '~' ? 1 : 3);	/* the 1 skips "~", 3 skips "/u/" */
-	q = name;
-	while (*p && *p != '/') {
-		if (q >= name + MAXLOGNAME - 1)
-			return r;		/* fail, name too long */
-		*q++ = *p++;
-	}
-	*q = '\0';
-
-#if TILDE
-	if (*name == 0 && *r == '~') {
-		/* null name, use $HOME */
-		if ((q = lookupvar("HOME")) == NULL)
-			return r;		/* fail, home not set */
-		i = strlen(q);
-		r = stalloc(i + strlen(p) + 1);
-		scopy(q, r);
-		scopy(p, r + i);
-		TRACE(("expudir converts %s to %s\n", path, r));
-		didudir = 1;
-		path = r;
-		return r;
-	}
-#endif
-#if !USEGETPW	/* can do without the bloat */
-	setinputfile("/etc/passwd", 1);
-	q = line + strlen(name);
-	while (pfgets(line, MAXPWLINE) != NULL) {
-		if (line[0] == name[0] && prefix(name, line) && *q == ':') {
-			/* skip to start of home directory */
-			i = 4;
-			do {
-				while (*++q && *q != ':');
-			} while (--i > 0);
-			if (*q == '\0')
-				break;		/* fail, corrupted /etc/passwd */
-			q++;
-			for (r = q ; *r && *r != '\n' && *r != ':' ; r++);
-			*r = '\0';		/* nul terminate home directory */
-			i = r - q;		/* i = strlen(q) */
-			r = stalloc(i + strlen(p) + 1);
-			scopy(q, r);
-			scopy(p, r + i);
-			TRACE(("expudir converts %s to %s\n", path, r));
-			didudir = 1;
-			path = r;		/* succeed */
-			break;
-		}
-	}
-	popfile();
-#else
-	if ((pw = getpwnam(name)) != NULL) {
-		/* user exists */
-		q = pw->pw_dir;
-		i = strlen(q);
-		r = stalloc(i + strlen(p) + 1);
-		scopy(q, r);
-		scopy(p, r + i);
-		TRACE(("expudir converts %s to %s\n", path, r));
-		didudir = 1;
-		path = r;
-	}
-	endpwent();
-#endif /* USEGETPW */
-
-	return r;
-}
-#endif
-
-
-/*
- * Do metacharacter (i.e. *, ?, [...]) expansion.
- */
-
-STATIC void
-expmeta(enddir, name)
-	char *enddir;
-	char *name;
-	{
-	register char *p;
-	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 (;;) {
-				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 == 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 == CTLESC)
-				p++;
-			*enddir++ = *p;
-			if (*p == '\0')
-				break;
-		}
-		if (metaflag == 0 || stat(expdir, &statb) >= 0)
-			addfname(expdir);
-		return;
-	}
-	endname = p;
-	if (start != name) {
-		p = name;
-		while (p < start) {
-			if (*p == CTLESC)
-				p++;
-			*enddir++ = *p++;
-		}
-	}
-	if (enddir == expdir) {
-		p = ".";
-	} else if (enddir == expdir + 1 && *expdir == '/') {
-		p = "/";
-	} else {
-		p = expdir;
-		enddir[-1] = '\0';
-	}
-	if ((dirp = opendir(p)) == NULL)
-		return;
-	if (enddir != expdir)
-		enddir[-1] = '/';
-	if (*endname == 0) {
-		atend = 1;
-	} else {
-		atend = 0;
-		*endname++ = '\0';
-	}
-	matchdot = 0;
-	if (start[0] == '.' || start[0] == CTLESC && start[1] == '.')
-		matchdot++;
-	while (! int_pending() && (dp = readdir(dirp)) != NULL) {
-		if (dp->d_name[0] == '.' && ! matchdot)
-			continue;
-		if (patmatch(start, dp->d_name)) {
-			if (atend) {
-				scopy(dp->d_name, enddir);
-				addfname(expdir);
-			} else {
-				char *q;
-				for (p = enddir, q = dp->d_name ; *p++ = *q++ ;);
-				p[-1] = '/';
-				expmeta(p, endname);
-			}
-		}
-	}
-	closedir(dirp);
-	if (! atend)
-		endname[-1] = '/';
-}
-
-
-/*
- * Add a file name to the list.
- */
-
-STATIC void
-addfname(name)
-	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(str)
-	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(list, len)
-	struct strlist *list;
-	{
-	struct strlist *p, *q;
-	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(pattern, string)
-	char *pattern;
-	char *string;
-	{
-	if (pattern[0] == '!' && pattern[1] == '!')
-		return 1 - pmatch(pattern + 2, string);
-	else
-		return pmatch(pattern, string);
-}
-
-
-STATIC int
-pmatch(pattern, string)
-	char *pattern;
-	char *string;
-	{
-	register char *p, *q;
-	register char c;
-
-	p = pattern;
-	q = string;
-	for (;;) {
-		switch (c = *p++) {
-		case '\0':
-			goto breakloop;
-		case CTLESC:
-			if (*q++ != *p++)
-				return 0;
-			break;
-		case '?':
-			if (*q++ == '\0')
-				return 0;
-			break;
-		case '*':
-			c = *p;
-			if (c != CTLESC && c != '?' && c != '*' && c != '[') {
-				while (*q != c) {
-					if (*q == '\0')
-						return 0;
-					q++;
-				}
-			}
-			do {
-				if (pmatch(p, q))
-					return 1;
-			} while (*q++ != '\0');
-			return 0;
-		case '[': {
-			char *endp;
-			int invert, found;
-			char chr;
-
-			endp = p;
-			if (*endp == '!')
-				endp++;
-			for (;;) {
-				if (*endp == '\0')
-					goto dft;		/* no matching ] */
-				if (*endp == CTLESC)
-					endp++;
-				if (*++endp == ']')
-					break;
-			}
-			invert = 0;
-			if (*p == '!') {
-				invert++;
-				p++;
-			}
-			found = 0;
-			chr = *q++;
-			c = *p++;
-			do {
-				if (c == CTLESC)
-					c = *p++;
-				if (*p == '-' && p[1] != ']') {
-					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 (*q++ != c)
-				return 0;
-			break;
-		}
-	}
-breakloop:
-	if (*q != '\0')
-		return 0;
-	return 1;
-}
-
-
-
-/*
- * Remove any CTLESC characters from a string.
- */
-
-void
-rmescapes(str)
-	char *str;
-	{
-	register char *p, *q;
-
-	p = str;
-	while (*p != CTLESC) {
-		if (*p++ == '\0')
-			return;
-	}
-	q = p;
-	while (*p) {
-		if (*p == CTLESC)
-			p++;
-		*q++ = *p++;
-	}
-	*q = '\0';
-}
-
-
-
-/*
- * See if a pattern matches in a case statement.
- */
-
-int
-casematch(pattern, val)
-	union node *pattern;
-	char *val;
-	{
-	struct stackmark smark;
-	int result;
-	char *p;
-
-	setstackmark(&smark);
-	argbackq = pattern->narg.backquote;
-	STARTSTACKSTR(expdest);
-	ifslastp = NULL;
-	/* Preserve any CTLESC characters inserted previously, so that
-	   we won't expand reg exps which are inside strings.  */
-	argstr(pattern->narg.text, 1);
-	STPUTC('\0', expdest);
-	p = grabstackstr(expdest);
-	result = patmatch(p, val);
-	popstackmark(&smark);
-	return result;
-}
Index: trunk/minix/commands/ash/expand.h
===================================================================
--- trunk/minix/commands/ash/expand.h	(revision 9)
+++ 	(revision )
@@ -1,63 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)expand.h	5.1 (Berkeley) 3/7/91
- */
-
-struct strlist {
-	struct strlist *next;
-	char *text;
-};
-
-
-struct arglist {
-	struct strlist *list;
-	struct strlist **lastp;
-};
-
-#ifdef __STDC__
-union node;
-void expandarg(union node *, struct arglist *, int);
-void expandhere(union node *, int);
-int patmatch(char *, char *);
-void rmescapes(char *);
-int casematch(union node *, char *);
-#else
-void expandarg();
-void expandhere();
-int patmatch();
-void rmescapes();
-int casematch();
-#endif
Index: trunk/minix/commands/ash/funcs/cmv
===================================================================
--- trunk/minix/commands/ash/funcs/cmv	(revision 9)
+++ 	(revision )
@@ -1,49 +1,0 @@
-# Copyright (c) 1991 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	5.1 (Berkeley) 3/7/91
-
-# 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"
-}
Index: trunk/minix/commands/ash/funcs/dirs
===================================================================
--- trunk/minix/commands/ash/funcs/dirs	(revision 9)
+++ 	(revision )
@@ -1,73 +1,0 @@
-# Copyright (c) 1991 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	5.1 (Berkeley) 3/7/91
-
-# 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
-}
Index: trunk/minix/commands/ash/funcs/kill
===================================================================
--- trunk/minix/commands/ash/funcs/kill	(revision 9)
+++ 	(revision )
@@ -1,49 +1,0 @@
-# Copyright (c) 1991 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	5.1 (Berkeley) 3/7/91
-
-# 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
-}
Index: trunk/minix/commands/ash/funcs/login
===================================================================
--- trunk/minix/commands/ash/funcs/login	(revision 9)
+++ 	(revision )
@@ -1,38 +1,0 @@
-# Copyright (c) 1991 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	5.1 (Berkeley) 3/7/91
-
-# replaces the login builtin in the BSD shell
-login () exec login "$@"
Index: trunk/minix/commands/ash/funcs/newgrp
===================================================================
--- trunk/minix/commands/ash/funcs/newgrp	(revision 9)
+++ 	(revision )
@@ -1,37 +1,0 @@
-# Copyright (c) 1991 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	5.1 (Berkeley) 3/7/91
-
-newgrp() exec newgrp "$@"
Index: trunk/minix/commands/ash/funcs/popd
===================================================================
--- trunk/minix/commands/ash/funcs/popd	(revision 9)
+++ 	(revision )
@@ -1,73 +1,0 @@
-# Copyright (c) 1991 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	5.1 (Berkeley) 3/7/91
-
-# 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
-}
Index: trunk/minix/commands/ash/funcs/pushd
===================================================================
--- trunk/minix/commands/ash/funcs/pushd	(revision 9)
+++ 	(revision )
@@ -1,73 +1,0 @@
-# Copyright (c) 1991 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	5.1 (Berkeley) 3/7/91
-
-# 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
-}
Index: trunk/minix/commands/ash/funcs/suspend
===================================================================
--- trunk/minix/commands/ash/funcs/suspend	(revision 9)
+++ 	(revision )
@@ -1,41 +1,0 @@
-# Copyright (c) 1991 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	5.1 (Berkeley) 3/7/91
-
-suspend() {
-	local -
-	set +j
-	kill -TSTP 0
-}
Index: trunk/minix/commands/ash/init.h
===================================================================
--- trunk/minix/commands/ash/init.h	(revision 9)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)init.h	5.1 (Berkeley) 3/7/91
- */
-
-#ifdef __STDC__
-void init(void);
-void reset(void);
-void initshellproc(void);
-#else
-void init();
-void reset();
-void initshellproc();
-#endif
Index: trunk/minix/commands/ash/input.c
===================================================================
--- trunk/minix/commands/ash/input.c	(revision 9)
+++ 	(revision )
@@ -1,414 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)input.c	5.4 (Berkeley) 7/1/91";
-#endif /* not lint */
-
-/*
- * This file implements the input routines used by the parser.
- */
-
-#include <sys/types.h>
-#include <stdio.h>	/* defines BUFSIZ */
-#include "shell.h"
-#include <fcntl.h>
-#include <errno.h>
-#include "syntax.h"
-#include "input.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-
-#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
-
-
-/*
- * The parsefile structure pointed to by the global variable parsefile
- * contains information about the current file being read.
- */
-
-MKINIT
-struct parsefile {
-	int linno;		/* current line */
-	int fd;			/* file descriptor (or -1 if string) */
-	int nleft;		/* number of chars left in buffer */
-	char *nextc;		/* next char in buffer */
-	struct parsefile *prev;	/* preceding file on stack */
-	char *buf;		/* input buffer */
-};
-
-
-int plinno = 1;			/* input line number */
-MKINIT int parsenleft;		/* copy of parsefile->nleft */
-char *parsenextc;		/* copy of parsefile->nextc */
-MKINIT struct parsefile basepf;	/* top level input file */
-char basebuf[BUFSIZ];		/* buffer for top level input file */
-struct parsefile *parsefile = &basepf;	/* current input file */
-char *pushedstring;		/* copy of parsenextc when text pushed back */
-int pushednleft;		/* copy of parsenleft when text pushed back */
-
-#if READLINE
-char *readline __P((const char *prompt));
-char *r_use_prompt = NULL;	/* the prompt to use with readline */
-#endif
-
-#ifdef __STDC__
-STATIC void pushfile(void);
-#else
-STATIC void pushfile();
-#endif
-
-
-
-#ifdef mkinit
-INCLUDE "input.h"
-INCLUDE "error.h"
-
-INIT {
-	extern char basebuf[];
-
-	basepf.nextc = basepf.buf = basebuf;
-}
-
-RESET {
-	if (exception != EXSHELLPROC)
-		parsenleft = 0;            /* clear input buffer */
-	popallfiles();
-}
-
-SHELLPROC {
-	popallfiles();
-}
-#endif
-
-
-/*
- * Read a line from the script.
- */
-
-char *
-pfgets(line, len)
-	char *line;
-	{
-	register 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() {
-	return pgetc_macro();
-}
-
-
-/*
- * Refill the input buffer and return the next input character:
- *
- * 1) If a string was pushed back on the input, switch back to the regular
- *    buffer.
- * 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) Call read to read in the characters.
- * 4) Delete all nul characters from the buffer.
- */
-
-int
-preadbuffer() {
-	register char *p, *q;
-	register int i;
-
-	if (pushedstring) {
-		parsenextc = pushedstring;
-		pushedstring = NULL;
-		parsenleft = pushednleft;
-		if (--parsenleft >= 0)
-			return *parsenextc++;
-	}
-	if (parsenleft == EOF_NLEFT || parsefile->buf == NULL)
-		return PEOF;
-	flushout(&output);
-	flushout(&errout);
-#if READLINE
-    /* Use the readline() call if a prompt is to be printed (interactive). */
-    if (r_use_prompt != NULL) {
-	char *prompt;
-	char *line;
-
-	p = parsenextc = parsefile->buf;
-
-	prompt = r_use_prompt;
-	r_use_prompt = NULL;
-
-	if ((line = readline(prompt)) == NULL) {
-                parsenleft = EOF_NLEFT;
-                return PEOF;
-	}
-	strcpy(p, line);
-	free(line);
-	i = strlen(p);
-	p[i++] = '\n';
-    } else {
-#endif
-retry:
-	p = parsenextc = parsefile->buf;
-	i = read(parsefile->fd, p, BUFSIZ);
-	if (i <= 0) {
-                if (i < 0) {
-                        if (errno == EINTR)
-                                goto retry;
-#ifdef EWOULDBLOCK
-                        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;
-                                        }
-                                }
-                        }
-#endif
-                }
-                parsenleft = EOF_NLEFT;
-                return PEOF;
-	}
-#if READLINE
-    }
-#endif
-	parsenleft = i - 1;
-
-	/* delete nul characters */
-	for (;;) {
-		if (*p++ == '\0')
-			break;
-		if (--i <= 0)
-			return *parsenextc++;		/* no nul characters */
-	}
-	q = p - 1;
-	while (--i > 0) {
-		if (*p != '\0')
-			*q++ = *p;
-		p++;
-	}
-	if (q == parsefile->buf)
-		goto retry;			/* buffer contained nothing but nuls */
-	parsenleft = q - parsefile->buf - 1;
-	return *parsenextc++;
-}
-
-
-/*
- * Undo the last call to pgetc.  Only one character may be pushed back.
- * PEOF may be pushed back.
- */
-
-void
-pungetc() {
-	parsenleft++;
-	parsenextc--;
-}
-
-
-/*
- * Push a string back onto the input.  This code doesn't work if the user
- * tries to push back more than one string at once.
- */
-
-void
-ppushback(string, length)
-	char *string;
-	{
-	pushedstring = parsenextc;
-	pushednleft = parsenleft;
-	parsenextc = string;
-	parsenleft = length;
-}
-
-
-
-/*
- * Set the input to take input from a file.  If push is set, push the
- * old input onto the stack first.
- */
-
-void
-setinputfile(fname, push)
-	char *fname;
-	{
-	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(fd, push) {
-	(void) fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | 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);
-	parsenleft = 0;
-	plinno = 1;
-}
-
-
-/*
- * Like setinputfile, but takes input from a string.
- */
-
-void
-setinputstring(string, push)
-	char *string;
-	{
-	INTOFF;
-	if (push)
-		pushfile();
-	parsenextc = string;
-	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() {
-	struct parsefile *pf;
-
-	parsefile->nleft = parsenleft;
-	parsefile->nextc = parsenextc;
-	parsefile->linno = plinno;
-	pf = (struct parsefile *)ckmalloc(sizeof (struct parsefile));
-	pf->prev = parsefile;
-	pf->fd = -1;
-	parsefile = pf;
-}
-
-
-void
-popfile() {
-	struct parsefile *pf = parsefile;
-
-	INTOFF;
-	if (pf->fd >= 0)
-		close(pf->fd);
-	if (pf->buf)
-		ckfree(pf->buf);
-	parsefile = pf->prev;
-	ckfree(pf);
-	parsenleft = parsefile->nleft;
-	parsenextc = parsefile->nextc;
-	plinno = parsefile->linno;
-	INTON;
-}
-
-
-/*
- * Return to top level.
- */
-
-void
-popallfiles() {
-	while (parsefile != &basepf)
-		popfile();
-}
-
-
-
-/*
- * Close the file(s) that the shell is reading commands from.  Called
- * after a fork is done.
- */
-
-void
-closescript() {
-	popallfiles();
-	if (parsefile->fd > 0) {
-		close(parsefile->fd);
-		parsefile->fd = 0;
-	}
-}
Index: trunk/minix/commands/ash/input.h
===================================================================
--- trunk/minix/commands/ash/input.h	(revision 9)
+++ 	(revision )
@@ -1,84 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)input.h	5.1 (Berkeley) 3/7/91
- */
-
-/* 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 */
-
-
-#ifdef __STDC__
-char *pfgets(char *, int);
-int pgetc(void);
-int preadbuffer(void);
-void pungetc(void);
-void ppushback(char *, int);
-void setinputfile(char *, int);
-void setinputfd(int, int);
-void setinputstring(char *, int);
-void popfile(void);
-void popallfiles(void);
-void closescript(void);
-#else
-char *pfgets();
-int pgetc();
-int preadbuffer();
-void pungetc();
-void ppushback();
-void setinputfile();
-void setinputfd();
-void setinputstring();
-void popfile();
-void popallfiles();
-void closescript();
-#endif
-
-#define pgetc_macro()	(--parsenleft >= 0? *parsenextc++ : preadbuffer())
-
-#if READLINE
-/* The variable "r_use_prompt" indicates the prompt to use with readline,
- * *and* that readline may only be used if non-NULL.
- */
-extern char *r_use_prompt;
-#endif
Index: trunk/minix/commands/ash/jobs.c
===================================================================
--- trunk/minix/commands/ash/jobs.c	(revision 9)
+++ 	(revision )
@@ -1,1035 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)jobs.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-#include "shell.h"
-#if JOBS
-#include "sgtty.h"
-#undef CEOF			/* syntax.h redefines this */
-#endif
-#include "main.h"
-#include "parser.h"
-#include "nodes.h"
-#include "jobs.h"
-#include "options.h"
-#include "trap.h"
-#include "signames.h"
-#include "syntax.h"
-#include "input.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-#include "redir.h"
-#include <sys/types.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <errno.h>
-#ifdef BSD
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#endif
-#if POSIX
-#include <sys/wait.h>
-#endif
-
-
-
-struct job *jobtab;		/* array of jobs */
-int njobs;			/* size of array */
-MKINIT pid_t backgndpid = -1;	/* pid of last background process */
-#if JOBS
-int initialpgrp;		/* pgrp of shell on invocation */
-pid_t curjob;			/* current job */
-#endif
-
-#ifdef __STDC__
-STATIC void restartjob(struct job *);
-STATIC struct job *getjob(char *);
-STATIC void freejob(struct job *);
-STATIC int procrunning(int);
-STATIC int dowait(int, struct job *);
-STATIC int waitproc(int, int *);
-STATIC char *commandtext(union node *);
-#else
-STATIC void restartjob();
-STATIC struct job *getjob();
-STATIC void freejob();
-STATIC int procrunning();
-STATIC int dowait();
-STATIC int waitproc();
-STATIC char *commandtext();
-#endif
-
-
- 
-#if JOBS
-/*
- * 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(on) {
-	int ldisc;
-
-	if (on == jobctl || rootshell == 0)
-		return;
-	if (on) {
-		do { /* while we are in the background */
-			if (ioctl(2, TIOCGPGRP, (char *)&initialpgrp) < 0) {
-				out2str("ash: can't access tty; job control turned off\n");
-				jflag = 0;
-				return;
-			}
-			if (initialpgrp == -1)
-				initialpgrp = getpgrp(0);
-			else if (initialpgrp != getpgrp(0)) {
-				killpg(initialpgrp, SIGTTIN);
-				continue;
-			}
-		} while (0);
-		if (ioctl(2, TIOCGETD, (char *)&ldisc) < 0 || ldisc != NTTYDISC) {
-			out2str("ash: need new tty driver to run job control; job control turned off\n");
-			jflag = 0;
-			return;
-		}
-		setsignal(SIGTSTP);
-		setsignal(SIGTTOU);
-		setpgrp(0, rootpid);
-		ioctl(2, TIOCSPGRP, (char *)&rootpid);
-	} else { /* turning job control off */
-		setpgrp(0, initialpgrp);
-		ioctl(2, TIOCSPGRP, (char *)&initialpgrp);
-		setsignal(SIGTSTP);
-		setsignal(SIGTTOU);
-	}
-	jobctl = on;
-}
-#endif
-
-
-#ifdef mkinit
-
-SHELLPROC {
-	backgndpid = -1;
-#if JOBS
-	jobctl = 0;
-#endif
-}
-
-#endif
-
-
-
-#if JOBS
-fgcmd(argc, argv)  char **argv; {
-	struct job *jp;
-	int pgrp;
-	int status;
-
-	jp = getjob(argv[1]);
-	if (jp->jobctl == 0)
-		error("job not created under job control");
-	pgrp = jp->ps[0].pid;
-	ioctl(2, TIOCSPGRP, (char *)&pgrp);
-	restartjob(jp);
-	INTOFF;
-	status = waitforjob(jp);
-	INTON;
-	return status;
-}
-
-
-bgcmd(argc, argv)  char **argv; {
-	struct job *jp;
-
-	do {
-		jp = getjob(*++argv);
-		if (jp->jobctl == 0)
-			error("job not created under job control");
-		restartjob(jp);
-	} while (--argc > 1);
-	return 0;
-}
-
-
-STATIC void
-restartjob(jp)
-	struct job *jp;
-	{
-	struct procstat *ps;
-	int i;
-
-	if (jp->state == JOBDONE)
-		return;
-	INTOFF;
-	killpg(jp->ps[0].pid, SIGCONT);
-	for (ps = jp->ps, i = jp->nprocs ; --i >= 0 ; ps++) {
-		if ((ps->status & 0377) == 0177) {
-			ps->status = -1;
-			jp->state = 0;
-		}
-	}
-	INTON;
-}
-#endif
-
-
-int
-jobscmd(argc, argv)  char **argv; {
-	showjobs(0);
-	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(change) {
-	int jobno;
-	int procno;
-	int i;
-	struct job *jp;
-	struct procstat *ps;
-	int col;
-	char s[64];
-
-	TRACE(("showjobs(%d) called\n", change));
-	while (dowait(0, (struct job *)NULL) > 0);
-	for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) {
-		if (! jp->used)
-			continue;
-		if (jp->nprocs == 0) {
-			freejob(jp);
-			continue;
-		}
-		if (change && ! jp->changed)
-			continue;
-		procno = jp->nprocs;
-		for (ps = jp->ps ; ; ps++) {	/* for each process */
-			if (ps == jp->ps)
-				fmtstr(s, 64, "[%d] %d ", jobno, ps->pid);
-			else
-				fmtstr(s, 64, "    %d ", ps->pid);
-			out1str(s);
-			col = strlen(s);
-			s[0] = '\0';
-			if (ps->status == -1) {
-				/* don't print anything */
-			} else if ((ps->status & 0xFF) == 0) {
-				fmtstr(s, 64, "Exit %d", ps->status >> 8);
-			} else {
-				i = ps->status;
-#if JOBS
-				if ((i & 0xFF) == 0177)
-					i >>= 8;
-#endif
-				if ((i & 0x7F) <= MAXSIG && sigmesg[i & 0x7F])
-					scopy(sigmesg[i & 0x7F], s);
-				else
-					fmtstr(s, 64, "Signal %d", i & 0x7F);
-				if (i & 0x80)
-					strcat(s, " (core dumped)");
-			}
-			out1str(s);
-			col += strlen(s);
-			do {
-				out1c(' ');
-				col++;
-			} while (col < 30);
-			out1str(ps->cmd);
-			out1c('\n');
-			if (--procno <= 0)
-				break;
-		}
-		jp->changed = 0;
-		if (jp->state == JOBDONE) {
-			freejob(jp);
-		}
-	}
-}
-
-
-/*
- * Mark a job structure as unused.
- */
-
-STATIC void
-freejob(jp)
-	struct job *jp;
-	{
-	struct procstat *ps;
-	int i;
-
-	INTOFF;
-	for (i = jp->nprocs, ps = jp->ps ; --i >= 0 ; ps++) {
-		if (ps->cmd != nullstr)
-			ckfree(ps->cmd);
-	}
-	if (jp->ps != &jp->ps0)
-		ckfree(jp->ps);
-	jp->used = 0;
-#if JOBS
-	if (curjob == jp - jobtab + 1)
-		curjob = 0;
-#endif
-	INTON;
-}
-
-
-
-int
-waitcmd(argc, argv)  char **argv; {
-	struct job *job;
-	int status;
-	struct job *jp;
-
-	if (argc > 1) {
-		job = getjob(argv[1]);
-	} else {
-		job = NULL;
-	}
-	for (;;) {	/* loop until process terminated or stopped */
-		if (job != NULL) {
-			if (job->state) {
-				status = job->ps[job->nprocs - 1].status;
-				if ((status & 0xFF) == 0)
-					status = status >> 8 & 0xFF;
-#if JOBS
-				else if ((status & 0xFF) == 0177)
-					status = (status >> 8 & 0x7F) + 128;
-#endif
-				else
-					status = (status & 0x7F) + 128;
-				if (! iflag)
-					freejob(job);
-				return status;
-			}
-		} else {
-			for (jp = jobtab ; ; jp++) {
-				if (jp >= jobtab + njobs) {	/* no running procs */
-					return 0;
-				}
-				if (jp->used && jp->state == 0)
-					break;
-			}
-		}
-		dowait(1, (struct job *)NULL);
-	}
-}
-
-
-
-jobidcmd(argc, argv)  char **argv; {
-	struct job *jp;
-	int i;
-
-	jp = getjob(argv[1]);
-	for (i = 0 ; i < jp->nprocs ; ) {
-		out1fmt("%d", jp->ps[i].pid);
-		out1c(++i < jp->nprocs? ' ' : '\n');
-	}
-	return 0;
-}
-
-
-
-/*
- * Convert a job name to a job structure.
- */
-
-STATIC struct job *
-getjob(name)
-	char *name;
-	{
-	int jobno;
-	register struct job *jp;
-	int pid;
-	int i;
-
-	if (name == NULL) {
-#if JOBS
-currentjob:
-		if ((jobno = curjob) == 0 || jobtab[jobno - 1].used == 0)
-			error("No current job");
-		return &jobtab[jobno - 1];
-#else
-		error("No current job");
-#endif
-	} else if (name[0] == '%') {
-		if (is_digit(name[1])) {
-			jobno = number(name + 1);
-			if (jobno > 0 && jobno <= njobs
-			 && jobtab[jobno - 1].used != 0)
-				return &jobtab[jobno - 1];
-#if JOBS
-		} else if (name[1] == '%' && name[2] == '\0') {
-			goto currentjob;
-#endif
-		} else {
-			register struct job *found = NULL;
-			for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) {
-				if (jp->used && jp->nprocs > 0
-				 && prefix(name + 1, jp->ps[0].cmd)) {
-					if (found)
-						error("%s: ambiguous", name);
-					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;
-		}
-	}
-	error("No such job: %s", name);
-}
-
-
-
-/*
- * Return a new job structure,
- */
-
-struct job *
-makejob(node, nprocs)
-	union node *node;
-	{
-	int i;
-	struct job *jp;
-
-	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]);
-				bcopy(jobtab, jp, njobs * sizeof jp[0]);
-				for (i= 0; i<njobs; i++)
-				{
-					if (jobtab[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 = 0;
-	jp->used = 1;
-	jp->changed = 0;
-	jp->nprocs = 0;
-#if JOBS
-	jp->jobctl = jobctl;
-#endif
-	if (nprocs > 1) {
-		jp->ps = ckmalloc(nprocs * sizeof (struct procstat));
-	} else {
-		jp->ps = &jp->ps0;
-	}
-	INTON;
-	TRACE(("makejob(0x%x, %d) returns %%%d\n", (int)node, nprocs, jp - jobtab + 1));
-	return jp;
-}	
-
-
-/*
- * Fork of 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(jp, n, mode)
-	union node *n;
-	struct job *jp;
-	{
-	int pid;
-	int pgrp;
-
-	TRACE(("forkshell(%%%d, 0x%x, %d) called\n", jp - jobtab, (int)n, mode));
-	INTOFF;
-	pid = fork();
-	if (pid == -1) {
-		TRACE(("Fork failed, errno=%d\n", errno));
-		INTON;
-		error("Cannot fork");
-	}
-	if (pid == 0) {
-		struct job *p;
-		int wasroot;
-		int i;
-
-		TRACE(("Child shell %d\n", getpid()));
-		wasroot = rootshell;
-		rootshell = 0;
-		for (i = njobs, p = jobtab ; --i >= 0 ; p++)
-			if (p->used)
-				freejob(p);
-		closescript();
-		INTON;
-		clear_traps();
-#if JOBS
-		jobctl = 0;		/* do job control only in root shell */
-		if (wasroot && mode != FORK_NOJOB && jflag) {
-			if (jp == NULL || jp->nprocs == 0)
-				pgrp = getpid();
-			else
-				pgrp = jp->ps[0].pid;
-			setpgrp(0, pgrp);
-			if (mode == FORK_FG) {
-				/*** this causes superfluous TIOCSPGRPS ***/
-				if (ioctl(2, TIOCSPGRP, (char *)&pgrp) < 0)
-					error("TIOCSPGRP failed, errno=%d\n", errno);
-			}
-			setsignal(SIGTSTP);
-			setsignal(SIGTTOU);
-		} else if (mode == FORK_BG) {
-			ignoresig(SIGINT);
-			ignoresig(SIGQUIT);
-			if ((jp == NULL || jp->nprocs == 0)
-			    && ! fd0_redirected_p ()) {
-				close(0);
-				if (open("/dev/null", O_RDONLY) != 0)
-					error("Can't open /dev/null");
-			}
-		}
-#else
-		if (mode == FORK_BG) {
-			ignoresig(SIGINT);
-			ignoresig(SIGQUIT);
-			if ((jp == NULL || jp->nprocs == 0)
-			    && ! fd0_redirected_p ()) {
-				close(0);
-				if (open("/dev/null", O_RDONLY) != 0)
-					error("Can't open /dev/null");
-			}
-		}
-#endif
-		if (wasroot && iflag) {
-			setsignal(SIGINT);
-			setsignal(SIGQUIT);
-			setsignal(SIGTERM);
-		}
-		return pid;
-	}
-	if (rootshell && mode != FORK_NOJOB && jflag) {
-		if (jp == NULL || jp->nprocs == 0)
-			pgrp = pid;
-		else
-			pgrp = jp->ps[0].pid;
-#if JOBS
-		setpgrp(pid, pgrp);
-#endif
-	}
-	if (mode == FORK_BG)
-		backgndpid = pid;		/* set $! */
-	if (jp) {
-		struct procstat *ps = &jp->ps[jp->nprocs++];
-		ps->pid = pid;
-		ps->status = -1;
-		ps->cmd = nullstr;
-		if (iflag && rootshell && n)
-			ps->cmd = commandtext(n);
-	}
-	INTON;
-	TRACE(("In parent shell:  child = %d\n", pid));
-	return pid;
-}
-
-
-
-/*
- * 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(jp)
-	register struct job *jp;
-	{
-#if JOBS
-	int mypgrp = getpgrp(0);
-#endif
-	int status;
-	int st;
-
-	INTOFF;
-	TRACE(("waitforjob(%%%d) called\n", jp - jobtab + 1));
-	while (jp->state == 0 && dowait(1, jp) != -1) ;
-#if JOBS
-	if (jp->jobctl) {
-		if (ioctl(2, TIOCSPGRP, (char *)&mypgrp) < 0)
-			error("TIOCSPGRP failed, errno=%d\n", errno);
-	}
-	if (jp->state == JOBSTOPPED)
-		curjob = jp - jobtab + 1;
-#endif
-	status = jp->ps[jp->nprocs - 1].status;
-	/* convert to 8 bits */
-	if ((status & 0xFF) == 0)
-		st = status >> 8 & 0xFF;
-#if JOBS
-	else if ((status & 0xFF) == 0177)
-		st = (status >> 8 & 0x7F) + 128;
-#endif
-	else
-		st = (status & 0x7F) + 128;
-	if (! JOBS || jp->state == JOBDONE)
-		freejob(jp);
-	CLEAR_PENDING_INT;
-	if ((status & 0x7F) == SIGINT)
-		kill(getpid(), SIGINT);
-	INTON;
-	return st;
-}
-
-
-
-/*
- * Wait for a process to terminate.
- */
-
-STATIC int
-dowait(block, job)
-	struct job *job;
-	{
-	int pid;
-	int status;
-	struct procstat *sp;
-	struct job *jp;
-	struct job *thisjob;
-	int done;
-	int stopped;
-	int core;
-
-	TRACE(("dowait(%d) called\n", block));
-	do {
-		pid = waitproc(block, &status);
-		TRACE(("wait returns %d, status=%d, errno=%d\n",
-				pid, status, errno));
-	} while (pid == -1 && errno == EINTR);
-	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(("Changin status of proc %d from 0x%x to 0x%x\n", pid, sp->status, status));
-					sp->status = status;
-					thisjob = jp;
-				}
-				if (sp->status == -1)
-					stopped = 0;
-				else if ((sp->status & 0377) == 0177)
-					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 && curjob == jp - jobtab + 1)
-						curjob = 0;		/* no current job */
-#endif
-				}
-			}
-		}
-	}
-	INTON;
-	if (! rootshell || ! iflag || (job && thisjob == job)) {
-#if JOBS
-		if ((status & 0xFF) == 0177)
-			status >>= 8;
-#endif
-		core = status & 0x80;
-		status &= 0x7F;
-		if (status != 0 && status != SIGINT && status != SIGPIPE) {
-			if (thisjob != job)
-				outfmt(out2, "%d: ", pid);
-#if JOBS
-			if (status == SIGTSTP && rootshell && iflag)
-				outfmt(out2, "%%%d ", job - jobtab + 1);
-#endif
-			if (status <= MAXSIG && sigmesg[status])
-				out2str(sigmesg[status]);
-			else
-				outfmt(out2, "Signal %d", status);
-			if (core)
-				out2str(" - core dumped");
-			out2c('\n');
-			flushout(&errout);
-		} else {
-			TRACE(("Not printing status: status=%d\n", status));
-		}
-	} else {
-		TRACE(("Not printing status, rootshell=%d, job=0x%x\n", rootshell, job));
-		if (thisjob)
-			thisjob->changed = 1;
-	}
-	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(block, status)
-	int *status;
-	{
-#ifdef BSD
-	int flags;
-
-#if JOBS
-	flags = WUNTRACED;
-#else
-	flags = 0;
-#endif
-	if (block == 0)
-		flags |= WNOHANG;
-	return wait3((union wait *)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 POSIX
-	return waitpid(-1, status, block == 0 ? WNOHANG : 0);
-#else
-	if (block == 0)
-		return 0;
-	return wait(status);
-#endif
-#endif
-#endif
-}
-
-
-
-/*
- * Return a string identifying a command (to be printed by the
- * jobs command.
- */
-
-STATIC char *cmdnextc;
-STATIC int cmdnleft;
-STATIC void cmdtxt(), cmdputs();
-
-STATIC char *
-commandtext(n)
-	union node *n;
-	{
-	char *name;
-
-	cmdnextc = name = ckmalloc(50);
-	cmdnleft = 50 - 4;
-	cmdtxt(n);
-	*cmdnextc = '\0';
-	return name;
-}
-
-
-STATIC void
-cmdtxt(n)
-	union node *n;
-	{
-	union node *np;
-	struct nodelist *lp;
-	char *p;
-	int i;
-	char s[2];
-
-	if (n == NULL) 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);
-		cmdputs("...");
-		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 ...");
-		break;
-	case NCASE:
-		cmdputs("case ");
-		cmdputs(n->ncase.expr->narg.text);
-		cmdputs(" in ...");
-		break;
-	case NDEFUN:
-		cmdputs(n->narg.text);
-		cmdputs("() ...");
-		break;
-	case NCMD:
-		for (np = n->ncmd.args ; np ; np = np->narg.next) {
-			cmdtxt(np);
-			if (np->narg.next)
-				cmdputs(" ");
-		}
-		for (np = n->ncmd.redirect ; np ; np = np->nfile.next) {
-			cmdputs(" ");
-			cmdtxt(np);
-		}
-		break;
-	case NARG:
-		cmdputs(n->narg.text);
-		break;
-	case NTO:
-		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;
-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
-cmdputs(s)
-	char *s;
-	{
-	register char *p, *q;
-	register char c;
-	int subtype = 0;
-
-	if (cmdnleft <= 0)
-		return;
-	p = s;
-	q = cmdnextc;
-	while ((c = *p++) != '\0') {
-		if (c == CTLESC)
-			*q++ = *p++;
-		else if (c == CTLVAR) {
-			*q++ = '$';
-			if (--cmdnleft > 0)
-				*q++ = '{';
-			subtype = *p++;
-		} else if (c == '=' && subtype != 0) {
-			*q++ = "}-+?="[(subtype & VSTYPE) - VSNORMAL];
-			subtype = 0;
-		} else if (c == CTLENDVAR) {
-			*q++ = '}';
-		} else if (c == CTLBACKQ | c == CTLBACKQ+CTLQUOTE)
-			cmdnleft++;		/* ignore it */
-		else
-			*q++ = c;
-		if (--cmdnleft <= 0) {
-			*q++ = '.';
-			*q++ = '.';
-			*q++ = '.';
-			break;
-		}
-	}
-	cmdnextc = q;
-}
Index: trunk/minix/commands/ash/jobs.h
===================================================================
--- trunk/minix/commands/ash/jobs.h	(revision 9)
+++ 	(revision )
@@ -1,96 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)jobs.h	5.1 (Berkeley) 3/7/91
- */
-
-/* Mode argument to forkshell.  Don't change FORK_FG or FORK_BG. */
-#define FORK_FG 0
-#define FORK_BG 1
-#define FORK_NOJOB 2
-
-
-/*
- * 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.
- */
-
-struct procstat {
-	pid_t pid;		/* process id */
-	short status;		/* status flags (defined above) */
-	char *cmd;		/* text of command being run */
-};
-
-
-/* states */
-#define JOBSTOPPED 1		/* all procs are stopped */
-#define JOBDONE 2		/* all procs are completed */
-
-
-struct job {
-	struct procstat ps0;	/* status of process */
-	struct procstat *ps;	/* status or processes when more than one */
-	pid_t nprocs;		/* number of processes */
-	pid_t pgrp;		/* process group of this job */
-	char state;		/* true if job is finished */
-	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 */
-#endif
-};
-
-extern pid_t backgndpid;	/* pid of last background process */
-
-
-#ifdef __STDC__
-void setjobctl(int);
-void showjobs(int);
-struct job *makejob(union node *, int);
-int forkshell(struct job *, union node *, int);
-int waitforjob(struct job *);
-#else
-void setjobctl();
-void showjobs();
-struct job *makejob();
-int forkshell();
-int waitforjob();
-#endif
-
-#if ! JOBS
-#define setjobctl(on)	/* do nothing */
-#endif
Index: trunk/minix/commands/ash/machdep.h
===================================================================
--- trunk/minix/commands/ash/machdep.h	(revision 9)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)machdep.h	5.1 (Berkeley) 3/7/91
- */
-
-/*
- * Most machines require the value returned from malloc to be aligned
- * in some way.  The following macro will get this right on many machines.
- */
-
-#ifndef ALIGN
-union align {
-	int i;
-	char *cp;
-};
-
-#define ALIGN(nbytes)	((nbytes) + sizeof(union align) - 1 &~ (sizeof(union align) - 1))
-#endif
Index: trunk/minix/commands/ash/mail.c
===================================================================
--- trunk/minix/commands/ash/mail.c	(revision 9)
+++ 	(revision )
@@ -1,108 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)mail.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * Routines to check for mail.  (Perhaps make part of main.c?)
- */
-
-#include "shell.h"
-#include "exec.h"	/* defines padvance() */
-#include "var.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include <sys/types.h>
-#include <sys/stat.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(silent) {
-	register int i;
-	char *mpath;
-	char *p;
-	register 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 '/' */
-		if (stat(p, &statb) < 0)
-			statb.st_mtime = 0;
-		if (!silent
-			&& statb.st_size > 0
-			&& statb.st_mtime > mailtime[i]
-			&& statb.st_mtime > statb.st_atime
-		) {
-			out2str(pathopt? pathopt : "You have mail");
-			out2c('\n');
-		}
-		mailtime[i] = statb.st_mtime;
-	}
-	nmboxes = i;
-	popstackmark(&smark);
-}
Index: trunk/minix/commands/ash/mail.h
===================================================================
--- trunk/minix/commands/ash/mail.h	(revision 9)
+++ 	(revision )
@@ -1,43 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)mail.h	5.1 (Berkeley) 3/7/91
- */
-
-#ifdef __STDC__
-void chkmail(int);
-#else
-void chkmail();
-#endif
Index: trunk/minix/commands/ash/main.c
===================================================================
--- trunk/minix/commands/ash/main.c	(revision 9)
+++ 	(revision )
@@ -1,359 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)main.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <signal.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 "eval.h"
-#include "jobs.h"
-#include "input.h"
-#include "trap.h"
-#if ATTY
-#include "var.h"
-#endif
-#include "memalloc.h"
-#include "error.h"
-#include "init.h"
-#include "mystring.h"
-
-#define PROFILE 0
-
-int rootpid;
-int rootshell;
-STATIC union node *curcmd;
-STATIC union node *prevcmd;
-extern int errno;
-#if PROFILE
-short profile_buf[16384];
-extern int etext();
-#endif
-
-#ifdef __STDC__
-STATIC void read_profile(char *);
-char *getenv(char *);
-#else
-STATIC void read_profile();
-char *getenv();
-#endif
-
-
-/*
- * 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.
- */
-
-main(argc, argv)  char **argv; {
-	struct jmploc jmploc;
-	struct stackmark smark;
-	volatile int state;
-	char *shinit, *home;
-	char *profile = NULL, *ashrc = NULL;
-
-#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.
-		 */
-		if (exception == EXSHELLPROC) {
-			rootpid = getpid();
-			rootshell = 1;
-			minusc = NULL;
-			state = 3;
-		} else if (state == 0 || iflag == 0 || ! rootshell)
-			exitshell(2);
-		reset();
-#if ATTY
-		if (exception == EXINT
-		 && (! attyset() || equal(termval(), "emacs"))) {
-#else
-		if (exception == EXINT) {
-#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;
-#if DEBUG
-	opentrace();
-	trputs("Shell args:  ");  trargs(argv);
-#endif
-	rootpid = getpid();
-	rootshell = 1;
-	init();
-	setstackmark(&smark);
-	procargs(argc, argv);
-	if (eflag) eflag = 2;	/* Truly enable [ex]flag after init. */
-	if (xflag) xflag = 2;
-	if (argv[0] && argv[0][0] == '-') {
-		state = 1;
-		read_profile("/etc/profile");
-state1:
-		state = 2;
-		if ((home = getenv("HOME")) != NULL
-		    && (profile = (char *) malloc(strlen(home) + 10)) != NULL)
-		{
-			strcpy(profile, home);
-			strcat(profile, "/.profile");
-			read_profile(profile);
-		} else {
-			read_profile(".profile");
-		}
-	} else if ((sflag || minusc) && (shinit = getenv("SHINIT")) != NULL) {
-		state = 2;
-		evalstring(shinit);
-	}
-state2:
-	if (profile != NULL) free(profile);
-
-	state = 3;
-	if (!argv[0] || argv[0][0] != '-') {
-		if ((home = getenv("HOME")) != NULL
-			&& (ashrc = (char *) malloc(strlen(home) + 8)) != NULL)
-		{
-			strcpy(ashrc, home);
-			strcat(ashrc, "/.ashrc");
-			read_profile(ashrc);
-		}
-	}
-state3:
-	if (ashrc != NULL) free(ashrc);
-	if (eflag) eflag = 1;	/* Init done, enable [ex]flag */
-	if (xflag) xflag = 1;
-	exitstatus = 0;		/* Init shouldn't influence initial $? */
-
-	state = 4;
-	if (minusc) {
-		evalstring(minusc);
-	}
-	if (sflag || minusc == NULL) {
-state4:
-		cmdloop(1);
-	}
-#if PROFILE
-	monitor(0);
-#endif
-	exitshell(exitstatus);
-}
-
-
-/*
- * Read and execute commands.  "Top" is nonzero for the top level command
- * loop; it turns on prompting if the shell is interactive.
- */
-
-void
-cmdloop(top) {
-	union node *n;
-	struct stackmark smark;
-	int inter;
-	int numeof;
-
-	TRACE(("cmdloop(%d) called\n", top));
-	setstackmark(&smark);
-	numeof = 0;
-	for (;;) {
-		if (pendingsigs)
-			dotrap();
-		inter = 0;
-		if (iflag && top) {
-			inter++;
-			showjobs(1);
-			chkmail(0);
-			flushout(&output);
-		}
-		n = parsecmd(inter);
-#if DEBUG
-		/* showtree(n); */
-#endif
-		if (n == NEOF) {
-			if (Iflag == 0 || numeof >= 50)
-				break;
-			out2str("\nUse \"exit\" to leave shell.\n");
-			numeof++;
-		} else if (n != NULL && nflag == 0) {
-			if (inter) {
-				INTOFF;
-				if (prevcmd)
-					freefunc(prevcmd);
-				prevcmd = curcmd;
-				curcmd = copyfunc(n);
-				INTON;
-			}
-			evaltree(n, 0);
-#ifdef notdef
-			if (exitstatus)				      /*DEBUG*/
-				outfmt(&errout, "Exit status 0x%X\n", exitstatus);
-#endif
-		}
-		popstackmark(&smark);
-	}
-	popstackmark(&smark);		/* unnecessary */
-}
-
-
-
-/*
- * Read /etc/profile or .profile.  Return on error.
- */
-
-STATIC void
-read_profile(name)
-	char *name;
-	{
-	int fd;
-
-	INTOFF;
-	if ((fd = open(name, O_RDONLY)) >= 0)
-		setinputfd(fd, 1);
-	INTON;
-	if (fd < 0)
-		return;
-	cmdloop(0);
-	popfile();
-}
-
-
-
-/*
- * Read a file containing shell functions.
- */
-
-void
-readcmdfile(name)
-	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 compatable we should do a path
- * search for the file, but a path search doesn't make any sense.
- */
-
-dotcmd(argc, argv)  char **argv; {
-	exitstatus = 0;
-	if (argc >= 2) {		/* That's what SVR2 does */
-		setinputfile(argv[1], 1);
-		commandname = argv[1];
-		cmdloop(0);
-		popfile();
-	}
-	return exitstatus;
-}
-
-
-exitcmd(argc, argv)  char **argv; {
-	extern int oexitstatus;
-	if (argc > 1)
-		exitstatus = number(argv[1]);
-	else
-		exitstatus = oexitstatus;
-	exitshell(exitstatus);
-}
-
-
-lccmd(argc, argv)  char **argv; {
-	if (argc > 1) {
-		defun(argv[1], prevcmd);
-		return 0;
-	} else {
-		INTOFF;
-		freefunc(curcmd);
-		curcmd = prevcmd;
-		prevcmd = NULL;
-		INTON;
-		evaltree(curcmd, 0);
-		return exitstatus;
-	}
-}
-
-
-
-#ifdef notdef
-/*
- * Should never be called.
- */
-
-void
-exit(exitstatus) {
-	_exit(exitstatus);
-}
-#endif
Index: trunk/minix/commands/ash/main.h
===================================================================
--- trunk/minix/commands/ash/main.h	(revision 9)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)main.h	5.1 (Berkeley) 3/7/91
- */
-
-extern int rootpid;	/* pid of main shell */
-extern int rootshell;	/* true if we aren't a child of the main shell */
-
-#ifdef __STDC__
-void readcmdfile(char *);
-void cmdloop(int);
-#else
-void readcmdfile();
-void cmdloop();
-#endif
Index: trunk/minix/commands/ash/memalloc.c
===================================================================
--- trunk/minix/commands/ash/memalloc.c	(revision 9)
+++ 	(revision )
@@ -1,292 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)memalloc.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-#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(nbytes) {
-	register pointer p;
-	pointer malloc();
-
-	if ((p = malloc(nbytes)) == NULL)
-		error("Out of space");
-	return p;
-}
-
-
-/*
- * Same for realloc.
- */
-
-pointer
-ckrealloc(p, nbytes)
-	register pointer p;
-	{
-	pointer realloc();
-
-	if ((p = realloc(p, nbytes)) == NULL)
-		error("Out of space");
-	return p;
-}
-
-
-/*
- * Make a copy of a string in safe storage.
- */
-
-char *
-savestr(s)
-	char *s;
-	{
-	register 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;
-char *stacknxt = stackbase.space;
-int stacknleft = MINSIZE;
-int sstrnleft;
-int herefd = -1;
-
-
-
-pointer
-stalloc(nbytes) {
-	register char *p;
-
-	nbytes = 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(p)
-	pointer p;
-	{
-	if (p == NULL) {		/*DEBUG */
-		write(2, "stunalloc\n", 10);
-		abort();
-	}
-	stacknleft += stacknxt - (char *)p;
-	stacknxt = p;
-}
-
-
-
-void
-setstackmark(mark)
-	struct stackmark *mark;
-	{
-	mark->stackp = stackp;
-	mark->stacknxt = stacknxt;
-	mark->stacknleft = stacknleft;
-}
-
-
-void
-popstackmark(mark)
-	struct stackmark *mark;
-	{
-	struct stack_block *sp;
-
-	INTOFF;
-	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() {
-	char *p;
-	int newlen = stacknleft * 2 + 100;
-	char *oldspace = stacknxt;
-	int oldlen = stacknleft;
-	struct stack_block *sp;
-
-	if (stacknxt == stackp->space && stackp != &stackbase) {
-		INTOFF;
-		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;
-		INTON;
-	} else {
-		p = stalloc(newlen);
-		bcopy(oldspace, p, oldlen);
-		stacknxt = p;			/* free the space */
-		stacknleft += newlen;		/* we just allocated */
-	}
-}
-
-
-
-void
-grabstackblock(len) {
-	len = ALIGN(len);
-	stacknxt += len;
-	stacknleft -= len;
-}
-
-
-
-/*
- * The following routines are somewhat easier to use that 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() {
-	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() {
-	int len = stackblocksize() - sstrnleft;
-	growstackblock();
-	sstrnleft = stackblocksize() - len;
-	return stackblock() + len;
-}
-
-
-
-void
-ungrabstackstr(s, p)
-	char *s;
-	char *p;
-	{
-	stacknleft += stacknxt - s;
-	stacknxt = s;
-	sstrnleft = stacknleft - (p - s);
-}
Index: trunk/minix/commands/ash/memalloc.h
===================================================================
--- trunk/minix/commands/ash/memalloc.h	(revision 9)
+++ 	(revision )
@@ -1,95 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)memalloc.h	5.1 (Berkeley) 3/7/91
- */
-
-struct stackmark {
-	struct stack_block *stackp;
-	char *stacknxt;
-	int stacknleft;
-};
-
-
-extern char *stacknxt;
-extern int stacknleft;
-extern int sstrnleft;
-extern int herefd;
-
-#ifdef __STDC__
-pointer ckmalloc(int);
-pointer ckrealloc(pointer, int);
-void free(pointer);		/* defined in C library */
-char *savestr(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 *);
-#else
-pointer ckmalloc();
-pointer ckrealloc();
-void free();		/* defined in C library */
-char *savestr();
-pointer stalloc();
-void stunalloc();
-void setstackmark();
-void popstackmark();
-void growstackblock();
-void grabstackblock();
-char *growstackstr();
-char *makestrspace();
-void ungrabstackstr();
-#endif
-
-
-
-#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(); else
-#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))
Index: trunk/minix/commands/ash/miscbltin.c
===================================================================
--- trunk/minix/commands/ash/miscbltin.c	(revision 9)
+++ 	(revision )
@@ -1,166 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)miscbltin.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-/*
- * Miscelaneous builtins.
- */
-
-#include "shell.h"
-#include "options.h"
-#include "var.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-
-#undef eflag
-
-extern char **argptr;		/* argument list for builtin command */
-
-
-/*
- * The read builtin.  The -e option causes backslashes to escape the
- * following character.
- *
- * This uses unbuffered input, which may be avoidable in some cases.
- */
-
-readcmd(argc, argv)  char **argv; {
-	char **ap;
-	int backslash;
-	char c;
-	int eflag;
-	char *prompt;
-	char *ifs;
-	char *p;
-	int startword;
-	int status;
-	int i;
-
-	eflag = 0;
-	prompt = NULL;
-	while ((i = nextopt("ep:")) != '\0') {
-		if (i == 'p')
-			prompt = optarg;
-		else
-			eflag = 1;
-	}
-	if (prompt && isatty(0)) {
-		out2str(prompt);
-		flushall();
-	}
-	if (*(ap = argptr) == NULL)
-		error("arg count");
-	if ((ifs = bltinlookup("IFS", 1)) == NULL)
-		ifs = nullstr;
-	status = 0;
-	startword = 1;
-	backslash = 0;
-	STARTSTACKSTR(p);
-	for (;;) {
-		if (read(0, &c, 1) != 1) {
-			status = 1;
-			break;
-		}
-		if (c == '\0')
-			continue;
-		if (backslash) {
-			backslash = 0;
-			if (c != '\n')
-				STPUTC(c, p);
-			continue;
-		}
-		if (eflag && c == '\\') {
-			backslash++;
-			continue;
-		}
-		if (c == '\n')
-			break;
-		if (startword && *ifs == ' ' && strchr(ifs, c)) {
-			continue;
-		}
-		startword = 0;
-		if (backslash && c == '\\') {
-			if (read(0, &c, 1) != 1) {
-				status = 1;
-				break;
-			}
-			STPUTC(c, p);
-		} else if (ap[1] != NULL && strchr(ifs, c) != NULL) {
-			STACKSTRNUL(p);
-			setvar(*ap, stackblock(), 0);
-			ap++;
-			startword = 1;
-			STARTSTACKSTR(p);
-		} else {
-			STPUTC(c, p);
-		}
-	}
-	STACKSTRNUL(p);
-	setvar(*ap, stackblock(), 0);
-	while (*++ap != NULL)
-		setvar(*ap, nullstr, 0);
-	return status;
-}
-
-
-
-umaskcmd(argc, argv)  char **argv; {
-	int mask;
-	char *p;
-	int i;
-
-	if ((p = argv[1]) == NULL) {
-		INTOFF;
-		mask = umask(0);
-		umask(mask);
-		INTON;
-		out1fmt("%.4o\n", mask);	/* %#o might be better */
-	} else {
-		mask = 0;
-		do {
-			if ((unsigned)(i = *p - '0') >= 8)
-				error("Illegal number: %s", argv[1]);
-			mask = (mask << 3) + i;
-		} while (*++p != '\0');
-		umask(mask);
-	}
-	return 0;
-}
Index: trunk/minix/commands/ash/mkbuiltins
===================================================================
--- trunk/minix/commands/ash/mkbuiltins	(revision 9)
+++ 	(revision )
@@ -1,123 +1,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991 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.
-#
-#	@(#)mkbuiltins	5.2 (Berkeley) 3/8/91
-
-# All calls to awk removed, because Minix bawk is deficient.  (kjb)
-
-if [ $# != 2 ]
-then
-	echo "USAGE: $0 shell.h builtins"
-	exit 1
-fi
-SHL=$1
-BLTINS=$2
-
-temp=/tmp/ka$$
-exec > builtins.c
-cat <<\!
-/*
- * This file was generated by the mkbuiltins program.
- */
-
-#include "shell.h"
-#include "builtins.h"
-
-!
-if grep '^#define JOBS[	 ]*1' $SHL > /dev/null
-then
-	# Job control.
-	sed -e '/^#/d
-		s/	/ /g
-		s/ #.*//
-		/^ *$/d
-		s/-j//' $BLTINS > $temp
-else
-	# No job control.
-	sed -e '/^#/d
-		s/	/ /g
-		s/ #.*//
-		/^ *$/d
-		/-j/d' $BLTINS > $temp
-fi
-sed -e 's/ .*//
-	s/\(.*\)/int \1();/' $temp
-echo '
-int (*const builtinfunc[])() = {'
-sed -e 's/ .*//
-	s/\(.*\)/	\1,/' $temp
-echo '};
-
-const struct builtincmd builtincmd[] = {'
-i=0
-while read line
-do
-	set -$- $line
-	shift
-	for fun
-	do
-		echo "	\"$fun\", $i,"
-	done
-	i=`expr $i + 1`
-done < $temp
-echo '	NULL, 0
-};'
-
-exec > builtins.h
-cat <<\!
-/*
- * This file was generated by the mkbuiltins program.
- */
-
-#include <sys/cdefs.h>
-!
-i=0
-tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
-	while read line
-	do
-		set -$- $line
-		echo "#define $1 $i"
-		i=`expr $i + 1`
-	done
-echo '
-struct builtincmd {
-      char *name;
-      int code;
-};
-
-extern int (*const builtinfunc[])();
-extern const struct builtincmd builtincmd[];'
-rm -f $temp
Index: trunk/minix/commands/ash/mkinit.c
===================================================================
--- trunk/minix/commands/ash/mkinit.c	(revision 9)
+++ 	(revision )
@@ -1,547 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)mkinit.c	5.3 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-/*
- * This program scans all the source files for code to handle various
- * special events and combines this code into one file.  This (allegedly)
- * improves the structure of the program since there is no need for
- * anyone outside of a module to know that that module performs special
- * operations on particular events.  The command is executed iff init.c
- * is actually changed.
- *
- * Usage:  mkinit command sourcefile...
- */
-
-
-#include <sys/cdefs.h>
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <fcntl.h>
-
-
-/*
- * OUTFILE is the name of the output file.  Output is initially written
- * to the file OUTTEMP, which is then moved to OUTFILE if OUTTEMP and
- * OUTFILE are different.
- */
-
-#define OUTFILE "init.c"
-#define OUTTEMP "init.c.new"
-#define OUTOBJ "init.o"
-
-
-/*
- * A text structure is basicly just a string that grows as more characters
- * are added onto the end of it.  It is implemented as a linked list of
- * blocks of characters.  The routines addstr and addchar append a string
- * or a single character, respectively, to a text structure.  Writetext
- * writes the contents of a text structure to a file.
- */
-
-#define BLOCKSIZE 512
-
-struct text {
-	char *nextc;
-	int nleft;
-	struct block *start;
-	struct block *last;
-};      
-
-struct block {
-	struct block *next;
-	char text[BLOCKSIZE];
-};
-
-
-/*
- * There is one event structure for each event that mkinit handles.
- */
-
-struct event {
-	char *name;		/* name of event (e.g. INIT) */
-	char *routine;		/* name of routine called on event */
-	char *comment;		/* comment describing routine */
-	struct text code;		/* code for handling event */
-};
-
-
-char writer[] = "\
-/*\n\
- * This file was generated by the mkinit program.\n\
- */\n\
-\n";
-
-char init[] = "\
-/*\n\
- * Initialization code.\n\
- */\n";
-
-char reset[] = "\
-/*\n\
- * This routine is called when an error or an interrupt occurs in an\n\
- * interactive shell and control is returned to the main command loop.\n\
- */\n";
-
-char shellproc[] = "\
-/*\n\
- * This routine is called to initialize the shell to run a shell procedure.\n\
- */\n";
-
-
-struct event event[] = {
-	{"INIT", "init", init},
-	{"RESET", "reset", reset},
-	{"SHELLPROC", "initshellproc", shellproc},
-	{NULL, NULL}
-};
-
-
-char *curfile;				/* current file */
-int linno;				/* current line */
-char *header_files[200];		/* list of header files */
-struct text defines;			/* #define statements */
-struct text decls;			/* declarations */
-int amiddecls;				/* for formatting */
-
-
-void readfile(), doevent(), doinclude(), dodecl(), output();
-void addstr(), addchar(), writetext();
-
-#define equal(s1, s2)	(strcmp(s1, s2) == 0)
-
-FILE *ckfopen();
-char *savestr();
-void *ckmalloc __P((int));
-void error();
-
-main(argc, argv)
-	char **argv;
-	{
-	char **ap;
-	int fd;
-	char c;
-
-	if (argc < 2)
-		error("Usage:  mkinit command file...");
-	header_files[0] = "\"shell.h\"";
-	header_files[1] = "\"mystring.h\"";
-	for (ap = argv + 2 ; *ap ; ap++)
-		readfile(*ap);
-	output();
-	if (file_changed()) {
-		unlink(OUTFILE);
-		link(OUTTEMP, OUTFILE);
-		unlink(OUTTEMP);
-	} else {
-		unlink(OUTTEMP);
-		if (touch(OUTOBJ))
-			exit(0);		/* no compilation necessary */
-	}
-	printf("%s\n", argv[1]);
-	execl("/bin/sh", "sh", "-c", argv[1], (char *)0);
-	error("Can't exec shell");
-}
-
-
-/*
- * Parse an input file.
- */
-
-void
-readfile(fname)
-	char *fname;
-	{
-	FILE *fp;
-	char line[1024];
-	struct event *ep;
-
-	fp = ckfopen(fname, "r");
-	curfile = fname;
-	linno = 0;
-	amiddecls = 0;
-	while (fgets(line, sizeof line, fp) != NULL) {
-		linno++;
-		for (ep = event ; ep->name ; ep++) {
-			if (line[0] == ep->name[0] && match(ep->name, line)) {
-				doevent(ep, fp, fname);
-				break;
-			}
-		}
-		if (line[0] == 'I' && match("INCLUDE", line))
-			doinclude(line);
-		if (line[0] == 'M' && match("MKINIT", line))
-			dodecl(line, fp);
-		if (line[0] == '#' && gooddefine(line))
-			addstr(line, &defines);
-	}
-	fclose(fp);
-}
-
-
-int
-match(name, line)
-	char *name;
-	char *line;
-	{
-	register char *p, *q;
-
-	p = name, q = line;
-	while (*p) {
-		if (*p++ != *q++)
-			return 0;
-	}
-	if (*q != '{' && *q != ' ' && *q != '\t' && *q != '\n')
-		return 0;
-	return 1;
-}
-
-
-int
-gooddefine(line)
-	char *line;
-	{
-	register char *p;
-
-	if (! match("#define", line))
-		return 0;			/* not a define */
-	p = line + 7;
-	while (*p == ' ' || *p == '\t')
-		p++;
-	while (*p != ' ' && *p != '\t') {
-		if (*p == '(')
-			return 0;		/* macro definition */
-		p++;
-	}
-	while (*p != '\n' && *p != '\0')
-		p++;
-	if (p[-1] == '\\')
-		return 0;			/* multi-line definition */
-	return 1;
-}
-
-
-void
-doevent(ep, fp, fname)
-	register struct event *ep;
-	FILE *fp;
-	char *fname;
-	{
-	char line[1024];
-	int indent;
-	char *p;
-
-	sprintf(line, "\n      /* from %s: */\n", fname);
-	addstr(line, &ep->code);
-	addstr("      {\n", &ep->code);
-	for (;;) {
-		linno++;
-		if (fgets(line, sizeof line, fp) == NULL)
-			error("Unexpected EOF");
-		if (equal(line, "}\n"))
-			break;
-		indent = 6;
-		for (p = line ; *p == '\t' ; p++)
-			indent += 8;
-		for ( ; *p == ' ' ; p++)
-			indent++;
-		if (*p == '\n' || *p == '#')
-			indent = 0;
-		while (indent >= 8) {
-			addchar('\t', &ep->code);
-			indent -= 8;
-		}
-		while (indent > 0) {
-			addchar(' ', &ep->code);
-			indent--;
-		}
-		addstr(p, &ep->code);
-	}
-	addstr("      }\n", &ep->code);
-}
-
-
-void
-doinclude(line)
-	char *line;
-	{
-	register char *p;
-	char *name;
-	register char **pp;
-
-	for (p = line ; *p != '"' && *p != '<' && *p != '\0' ; p++);
-	if (*p == '\0')
-		error("Expecting '\"' or '<'");
-	name = p;
-	while (*p != ' ' && *p != '\t' && *p != '\n')
-		p++;
-	if (p[-1] != '"' && p[-1] != '>')
-		error("Missing terminator");
-	*p = '\0';
-
-	/* name now contains the name of the include file */
-	for (pp = header_files ; *pp && ! equal(*pp, name) ; pp++);
-	if (*pp == NULL)
-		*pp = savestr(name);
-}
-
-
-void
-dodecl(line1, fp)
-	char *line1;
-	FILE *fp;
-	{
-	char line[1024];
-	register char *p, *q;
-
-	if (strcmp(line1, "MKINIT\n") == 0) { /* start of struct/union decl */
-		addchar('\n', &decls);
-		do {
-			linno++;
-			if (fgets(line, sizeof line, fp) == NULL)
-				error("Unterminated structure declaration");
-			addstr(line, &decls);
-		} while (line[0] != '}');
-		amiddecls = 0;
-	} else {
-		if (! amiddecls)
-			addchar('\n', &decls);
-		q = NULL;
-		for (p = line1 + 6 ; *p != '=' && *p != '/' ; p++);
-		if (*p == '=') {		/* eliminate initialization */
-			for (q = p ; *q && *q != ';' ; q++);
-			if (*q == '\0')
-				q = NULL;
-			else {
-				while (p[-1] == ' ')
-					p--;
-				*p = '\0';
-			}
-		}
-		addstr("extern", &decls);
-		addstr(line1 + 6, &decls);
-		if (q != NULL)
-			addstr(q, &decls);
-		amiddecls = 1;
-	}
-}
-
-
-
-/*
- * Write the output to the file OUTTEMP.
- */
-
-void
-output() {
-	FILE *fp;
-	char **pp;
-	struct event *ep;
-
-	fp = ckfopen(OUTTEMP, "w");
-	fputs(writer, fp);
-	for (pp = header_files ; *pp ; pp++)
-		fprintf(fp, "#include %s\n", *pp);
-	fputs("\n\n\n", fp);
-	writetext(&defines, fp);
-	fputs("\n\n", fp);
-	writetext(&decls, fp);
-	for (ep = event ; ep->name ; ep++) {
-		fputs("\n\n\n", fp);
-		fputs(ep->comment, fp);
-		fprintf(fp, "\nvoid\n%s() {\n", ep->routine);
-		writetext(&ep->code, fp);
-		fprintf(fp, "}\n");
-	}
-	fclose(fp);
-}
-
-
-/*
- * Return true if the new output file is different from the old one.
- */
-
-int
-file_changed() {
-	register FILE *f1, *f2;
-	register int c;
-
-	if ((f1 = fopen(OUTFILE, "r")) == NULL
-	 || (f2 = fopen(OUTTEMP, "r")) == NULL)
-		return 1;
-	while ((c = getc(f1)) == getc(f2)) {
-		if (c == EOF)
-			return 0;
-	}
-	return 1;
-}
-
-
-/*
- * Touch a file.  Returns 0 on failure, 1 on success.
- */
-
-int
-touch(file)
-	char *file;
-	{
-	int fd;
-	char c;
-
-	if ((fd = open(file, O_RDWR)) < 0)
-		return 0;
-	if (read(fd, &c, 1) != 1) {
-		close(fd);
-		return 0;
-	}
-	lseek(fd, 0L, 0);
-	write(fd, &c, 1);
-	close(fd);
-	return 1;
-}
-
-
-
-/*
- * A text structure is simply a block of text that is kept in memory.
- * Addstr appends a string to the text struct, and addchar appends a single
- * character.
- */
-
-void
-addstr(s, text)
-	register char *s;
-	register struct text *text;
-	{
-	while (*s) {
-		if (--text->nleft < 0)
-			addchar(*s++, text);
-		else
-			*text->nextc++ = *s++;
-	}
-}
-
-
-void
-addchar(c, text)
-	register struct text *text;
-	{
-	struct block *bp;
-
-	if (--text->nleft < 0) {
-		bp = ckmalloc(sizeof *bp);
-		if (text->start == NULL)
-			text->start = bp;
-		else
-			text->last->next = bp;
-		text->last = bp;
-		text->nextc = bp->text;
-		text->nleft = BLOCKSIZE - 1;
-	}
-	*text->nextc++ = c;
-}
-
-/*
- * Write the contents of a text structure to a file.
- */
-void
-writetext(text, fp)
-	struct text *text;
-	FILE *fp;
-	{
-	struct block *bp;
-
-	if (text->start != NULL) {
-		for (bp = text->start ; bp != text->last ; bp = bp->next)
-			fwrite(bp->text, sizeof (char), BLOCKSIZE, fp);
-		fwrite(bp->text, sizeof (char), BLOCKSIZE - text->nleft, fp);
-	}
-}
-
-FILE *
-ckfopen(file, mode)
-	char *file;
-	char *mode;
-	{
-	FILE *fp;
-
-	if ((fp = fopen(file, mode)) == NULL) {
-		fprintf(stderr, "Can't open %s\n", file);
-		exit(2);
-	}
-	return fp;
-}
-
-void *
-ckmalloc(nbytes) {
-	register char *p;
-	char *malloc();
-
-	if ((p = malloc(nbytes)) == NULL)
-		error("Out of space");
-	return p;
-}
-
-char *
-savestr(s)
-	char *s;
-	{
-	register char *p;
-
-	p = ckmalloc(strlen(s) + 1);
-	strcpy(p, s);
-	return p;
-}
-
-void
-error(msg)
-	char *msg;
-	{
-	if (curfile != NULL)
-		fprintf(stderr, "%s:%d: ", curfile, linno);
-	fprintf(stderr, "%s\n", msg);
-	exit(2);
-}
Index: trunk/minix/commands/ash/mknodes.c
===================================================================
--- trunk/minix/commands/ash/mknodes.c	(revision 9)
+++ 	(revision )
@@ -1,432 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)mknodes.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * This program reads the nodetypes file and nodes.c.pat file.  It generates
- * the files nodes.h and nodes.c.
- */
-
-#include <stdio.h>
-
-
-#define MAXTYPES 50		/* max number of node types */
-#define MAXFIELDS 20		/* max fields in a structure */
-#define BUFLEN 100		/* size of character buffers */
-
-/* field types */
-#define T_NODE 1		/* union node *field */
-#define T_NODELIST 2		/* struct nodelist *field */
-#define T_STRING 3
-#define T_INT 4			/* int field */
-#define T_OTHER 5		/* other */
-#define T_TEMP 6		/* don't copy this field */
-
-
-struct field {			/* a structure field */
-	char *name;		/* name of field */
-	int type;			/* type of field */
-	char *decl;		/* declaration of field */
-};
-
-
-struct str {			/* struct representing a node structure */
-	char *tag;		/* structure tag */
-	int nfields;		/* number of fields in the structure */
-	struct field field[MAXFIELDS];	/* the fields of the structure */
-	int done;			/* set if fully parsed */
-};
-
-
-int ntypes;			/* number of node types */
-char *nodename[MAXTYPES];	/* names of the nodes */
-struct str *nodestr[MAXTYPES];	/* type of structure used by the node */
-int nstr;			/* number of structures */
-struct str str[MAXTYPES];	/* the structures */
-struct str *curstr;		/* current structure */
-
-
-FILE *infp = stdin;
-char line[1024];
-int linno;
-char *linep;
-
-
-char *savestr();
-#define equal(s1, s2)	(strcmp(s1, s2) == 0)
-
-
-main(argc, argv)
-	char **argv;
-	{
-	if (argc != 3)
-		error("usage: mknodes file\n");
-	if ((infp = fopen(argv[1], "r")) == NULL)
-		error("Can't open %s", argv[1]);
-	while (readline()) {
-		if (line[0] == ' ' || line[0] == '\t')
-			parsefield();
-		else if (line[0] != '\0')
-			parsenode();
-	}
-	output(argv[2]);
-	return 0;
-}
-
-
-
-parsenode() {
-	char name[BUFLEN];
-	char tag[BUFLEN];
-	struct str *sp;
-
-	if (curstr && curstr->nfields > 0)
-		curstr->done = 1;
-	nextfield(name);
-	if (! nextfield(tag))
-		error("Tag expected");
-	if (*linep != '\0')
-		error("Garbage at end of line");
-	nodename[ntypes] = savestr(name);
-	for (sp = str ; sp < str + nstr ; sp++) {
-		if (equal(sp->tag, tag))
-			break;
-	}
-	if (sp >= str + nstr) {
-		sp->tag = savestr(tag);
-		sp->nfields = 0;
-		curstr = sp;
-		nstr++;
-	}
-	nodestr[ntypes] = sp;
-	ntypes++;
-}
-
-
-parsefield() {
-	char name[BUFLEN];
-	char type[BUFLEN];
-	char decl[2 * BUFLEN];
-	struct field *fp;
-
-	if (curstr == NULL || curstr->done)
-		error("No current structure to add field to");
-	if (! nextfield(name))
-		error("No field name");
-	if (! nextfield(type))
-		error("No field type");
-	fp = &curstr->field[curstr->nfields];
-	fp->name = savestr(name);
-	if (equal(type, "nodeptr")) {
-		fp->type = T_NODE;
-		sprintf(decl, "union node *%s", name);
-	} else if (equal(type, "nodelist")) {
-		fp->type = T_NODELIST;
-		sprintf(decl, "struct nodelist *%s", name);
-	} else if (equal(type, "string")) {
-		fp->type = T_STRING;
-		sprintf(decl, "char *%s", name);
-	} else if (equal(type, "int")) {
-		fp->type = T_INT;
-		sprintf(decl, "int %s", name);
-	} else if (equal(type, "other")) {
-		fp->type = T_OTHER;
-	} else if (equal(type, "temp")) {
-		fp->type = T_TEMP;
-	} else {
-		error("Unknown type %s", type);
-	}
-	if (fp->type == T_OTHER || fp->type == T_TEMP) {
-		skipbl();
-		fp->decl = savestr(linep);
-	} else {
-		if (*linep)
-			error("Garbage at end of line");
-		fp->decl = savestr(decl);
-	}
-	curstr->nfields++;
-}
-
-
-char writer[] = "\
-/*\n\
- * This file was generated by the mknodes program.\n\
- */\n\
-\n";
-
-output(file)
-	char *file;
-	{
-	FILE *hfile;
-	FILE *cfile;
-	FILE *patfile;
-	int i;
-	struct str *sp;
-	struct field *fp;
-	char *p;
-
-	if ((patfile = fopen(file, "r")) == NULL)
-		error("Can't open %s", file);
-	if ((hfile = fopen("nodes.h", "w")) == NULL)
-		error("Can't create nodes.h");
-	if ((cfile = fopen("nodes.c", "w")) == NULL)
-		error("Can't create nodes.c");
-	fputs(writer, hfile);
-	for (i = 0 ; i < ntypes ; i++)
-		fprintf(hfile, "#define %s %d\n", nodename[i], i);
-	fputs("\n\n\n", hfile);
-	for (sp = str ; sp < &str[nstr] ; sp++) {
-		fprintf(hfile, "struct %s {\n", sp->tag);
-		for (i = sp->nfields, fp = sp->field ; --i >= 0 ; fp++) {
-			fprintf(hfile, "      %s;\n", fp->decl);
-		}
-		fputs("};\n\n\n", hfile);
-	}
-	fputs("union node {\n", hfile);
-	fprintf(hfile, "      int type;\n");
-	for (sp = str ; sp < &str[nstr] ; sp++) {
-		fprintf(hfile, "      struct %s %s;\n", sp->tag, sp->tag);
-	}
-	fputs("};\n\n\n", hfile);
-	fputs("struct nodelist {\n", hfile);
-	fputs("\tstruct nodelist *next;\n", hfile);
-	fputs("\tunion node *n;\n", hfile);
-	fputs("};\n\n\n", hfile);
-	fputs("#ifdef __STDC__\n", hfile);
-	fputs("union node *copyfunc(union node *);\n", hfile);
-	fputs("void freefunc(union node *);\n", hfile);
-	fputs("#else\n", hfile);
-	fputs("union node *copyfunc();\n", hfile);
-	fputs("void freefunc();\n", hfile);
-	fputs("#endif\n", hfile);
-
-	fputs(writer, cfile);
-	while (fgets(line, sizeof line, patfile) != NULL) {
-		for (p = line ; *p == ' ' || *p == '\t' ; p++);
-		if (equal(p, "%SIZES\n"))
-			outsizes(cfile);
-		else if (equal(p, "%CALCSIZE\n"))
-			outfunc(cfile, 1);
-		else if (equal(p, "%COPY\n"))
-			outfunc(cfile, 0);
-		else
-			fputs(line, cfile);
-	}
-}
-
-
-
-outsizes(cfile)
-	FILE *cfile;
-	{
-	int i;
-
-	fprintf(cfile, "static const short nodesize[%d] = {\n", ntypes);
-	for (i = 0 ; i < ntypes ; i++) {
-		fprintf(cfile, "      ALIGN(sizeof (struct %s)),\n", nodestr[i]->tag);
-	}
-	fprintf(cfile, "};\n");
-}
-
-
-outfunc(cfile, calcsize)
-	FILE *cfile;
-	{
-	struct str *sp;
-	struct field *fp;
-	int i;
-
-	fputs("      if (n == NULL)\n", cfile);
-	if (calcsize)
-		fputs("	    return;\n", cfile);
-	else
-		fputs("	    return NULL;\n", cfile);
-	if (calcsize)
-		fputs("      funcblocksize += nodesize[n->type];\n", cfile);
-	else {
-		fputs("      new = funcblock;\n", cfile);
-		fputs("      *(char **)&funcblock += nodesize[n->type];\n", 
-									cfile);
-	}
-	fputs("      switch (n->type) {\n", cfile);
-	for (sp = str ; sp < &str[nstr] ; sp++) {
-		for (i = 0 ; i < ntypes ; i++) {
-			if (nodestr[i] == sp)
-				fprintf(cfile, "      case %s:\n", nodename[i]);
-		}
-		for (i = sp->nfields ; --i >= 1 ; ) {
-			fp = &sp->field[i];
-			switch (fp->type) {
-			case T_NODE:
-				if (calcsize) {
-					indent(12, cfile);
-					fprintf(cfile, "calcsize(n->%s.%s);\n",
-						sp->tag, fp->name);
-				} else {
-					indent(12, cfile);
-					fprintf(cfile, "new->%s.%s = copynode(n->%s.%s);\n",
-						sp->tag, fp->name, sp->tag, fp->name);
-				}
-				break;
-			case T_NODELIST:
-				if (calcsize) {
-					indent(12, cfile);
-					fprintf(cfile, "sizenodelist(n->%s.%s);\n",
-						sp->tag, fp->name);
-				} else {
-					indent(12, cfile);
-					fprintf(cfile, "new->%s.%s = copynodelist(n->%s.%s);\n",
-						sp->tag, fp->name, sp->tag, fp->name);
-				}
-				break;
-			case T_STRING:
-				if (calcsize) {
-					indent(12, cfile);
-					fprintf(cfile, "funcstringsize += strlen(n->%s.%s) + 1;\n",
-						sp->tag, fp->name);
-				} else {
-					indent(12, cfile);
-					fprintf(cfile, "new->%s.%s = nodesavestr(n->%s.%s);\n",
-						sp->tag, fp->name, sp->tag, fp->name);
-				}
-				break;
-			case T_INT:
-			case T_OTHER:
-				if (! calcsize) {
-					indent(12, cfile);
-					fprintf(cfile, "new->%s.%s = n->%s.%s;\n",
-						sp->tag, fp->name, sp->tag, fp->name);
-				}
-				break;
-			}
-		}
-		indent(12, cfile);
-		fputs("break;\n", cfile);
-	}
-	fputs("      };\n", cfile);
-	if (! calcsize)
-		fputs("      new->type = n->type;\n", cfile);
-}
-
-
-indent(amount, fp)
-	FILE *fp;
-	{
-	while (amount >= 8) {
-		putc('\t', fp);
-		amount -= 8;
-	}
-	while (--amount >= 0) {
-		putc(' ', fp);
-	}
-}
-
-
-int
-nextfield(buf)
-	char *buf;
-	{
-	register char *p, *q;
-
-	p = linep;
-	while (*p == ' ' || *p == '\t')
-		p++;
-	q = buf;
-	while (*p != ' ' && *p != '\t' && *p != '\0')
-		*q++ = *p++;
-	*q = '\0';
-	linep = p;
-	return (q > buf);
-}
-
-
-skipbl() {
-	while (*linep == ' ' || *linep == '\t')
-		linep++;
-}
-
-
-int
-readline() {
-	register char *p;
-
-	if (fgets(line, 1024, infp) == NULL)
-		return 0;
-	for (p = line ; *p != '#' && *p != '\n' && *p != '\0' ; p++);
-	while (p > line && (p[-1] == ' ' || p[-1] == '\t'))
-		p--;
-	*p = '\0';
-	linep = line;
-	linno++;
-	if (p - line > BUFLEN)
-		error("Line too long");
-	return 1;
-}
-
-
-
-error(msg, a1, a2, a3, a4, a5, a6)
-	char *msg;
-	{
-	fprintf(stderr, "line %d: ", linno);
-	fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
-	putc('\n', stderr);
-	exit(2);
-}
-
-
-
-char *
-savestr(s)
-	char *s;
-	{
-	register char *p;
-	char *malloc();
-
-	if ((p = malloc(strlen(s) + 1)) == NULL)
-		error("Out of space");
-	strcpy(p, s);
-	return p;
-}
Index: trunk/minix/commands/ash/mksignames.c
===================================================================
--- trunk/minix/commands/ash/mksignames.c	(revision 9)
+++ 	(revision )
@@ -1,200 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)mksignames.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * This program generates the signames.h and signames.c files.
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <signal.h>
-
-
-
-struct sig {
-	int signo;		/* signal number */
-	char *name;		/* signal name (without leading "SIG") */
-	char *mesg;		/* description */
-};
-
-
-struct sig sigtab[] = {
-	SIGHUP, "HUP", "Hangup",
-	SIGINT, "INT", "Interrupt",	/* normally don't print message */
-	SIGQUIT, "QUIT", "Quit",
-	SIGILL, "ILL", "Illegal instruction",
-	SIGTRAP, "TRAP", "Trace/BPT trap",
-#ifdef SIGABRT
-	SIGABRT, "ABRT", "abort",
-#endif
-#if defined(SIGIOT) && (! defined(SIGABRT) || SIGABRT != SIGIOT)
-	SIGIOT, "IOT", "abort",
-#endif
-#ifdef SIGEMT
-	SIGEMT, "EMT", "EMT trap",
-#endif
-	SIGFPE, "FPE", "Floating exception",
-	SIGKILL, "KILL", "Killed",
-	SIGBUS, "BUS", "Bus error",
-	SIGSEGV, "SEGV", "Memory fault",
-#ifdef SIGSYS
-	SIGSYS, "SYS", "Bad system call",
-#endif
-	SIGPIPE, "PIPE", "Broken pipe",	/* normally don't print message */
-	SIGALRM, "ALRM", "Alarm call",
-	SIGTERM, "TERM", "Terminated",
-#ifdef SIGUSR1
-	SIGUSR1, "USR1", "User signal 1",
-#endif
-#ifdef SIGUSR2
-	SIGUSR2, "USR2", "User signal 2",
-#endif
-#ifdef SIGCLD
-	SIGCLD, "CLD", NULL,
-#endif
-#if defined(SIGCHLD) && ! defined(SIGCLD)
-	SIGCHLD, "CLD", NULL,
-#endif
-#ifdef SIGPWR
-	SIGPWR, "PWR", "Power fail",
-#endif
-#ifdef SIGPOLL
-	SIGPOLL, "POLL", "Poll",
-#endif
-	/* Now for the BSD signals */
-#ifdef SIGURG
-	SIGURG, "URG", NULL,
-#endif
-#ifdef SIGSTOP
-	SIGSTOP, "STOP", "Stopped",
-#endif
-#ifdef SIGTSTP
-	SIGTSTP, "TSTP", "Stopped",
-#endif
-#ifdef SIGCONT
-	SIGCONT, "CONT", NULL,
-#endif
-#ifdef SIGTTIN
-	SIGTTIN, "TTIN", "Stopped (input)",
-#endif
-#ifdef SIGTTOU
-	SIGTTOU, "TTOU", "Stopped (output)",
-#endif
-#ifdef SIGIO
-	SIGIO, "IO", NULL,
-#endif
-#ifdef SIGXCPU
-	SIGXCPU, "XCPU", "Time limit exceeded",
-#endif
-#ifdef SIGXFSZ
-	SIGXFSZ, "XFSZ", NULL,
-#endif
-#ifdef SIGVTALARM
-	SIGVTALARM, "VTALARM", "Virtual alarm",
-#endif
-#ifdef SIGPROF
-	SIGPROF, "PROF", "Profiling alarm",
-#endif
-#ifdef SIGWINCH
-	SIGWINCH, "WINCH", NULL,
-#endif
-	0, NULL, NULL
-};
-
-
-#define MAXSIG 64
-
-
-char *sigmesg[MAXSIG + 1];
-
-
-char writer[] = "\
-/*\n\
- * This file was generated by the mksignames program.\n\
- */\n\
-\n";
-
-
-
-main(argc, argv)  char **argv; {
-	FILE *cfile, *hfile;	
-	struct sig *sigp;
-	int maxsig;
-	int i;
-
-	if ((cfile = fopen("signames.c", "w")) == NULL) {
-		fputs("Can't create signames.c\n", stderr);
-		exit(2);
-	}
-	if ((hfile = fopen("signames.h", "w")) == NULL) {
-		fputs("Can't create signames.h\n", stderr);
-		exit(2);
-	}
-	maxsig = 0;
-	for (sigp = sigtab ; sigp->signo != 0 ; sigp++) {
-		if (sigp->signo < 0 || sigp->signo > MAXSIG)
-			continue;
-		sigmesg[sigp->signo] = sigp->mesg;
-		if (maxsig < sigp->signo)
-			maxsig = sigp->signo;
-	}
-
-	fputs(writer, hfile);
-	fprintf(hfile, "#define MAXSIG %d\n\n", maxsig);
-	fprintf(hfile, "extern char *const sigmesg[MAXSIG+1];\n");
-
-	fputs(writer, cfile);
-	fprintf(cfile, "#include \"shell.h\"\n\n");
-	fprintf(cfile, "char *const sigmesg[%d] = {\n", maxsig + 1);
-	for (i = 0 ; i <= maxsig ; i++) {
-		if (sigmesg[i] == NULL) {
-			fprintf(cfile, "      0,\n");
-		} else {
-			fprintf(cfile, "      \"%s\",\n", sigmesg[i]);
-		}
-	}
-	fprintf(cfile, "};\n");
-	exit(0);
-}
Index: trunk/minix/commands/ash/mksyntax.c
===================================================================
--- trunk/minix/commands/ash/mksyntax.c	(revision 9)
+++ 	(revision )
@@ -1,356 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)mksyntax.c	5.2 (Berkeley) 3/8/91";
-#endif /* not lint */
-
-/*
- * This program creates syntax.h and syntax.c.
- */
-
-#include <stdio.h>
-#include "parser.h"
-
-
-struct synclass {
-	char *name;
-	char *comment;
-};
-
-/* Syntax classes */
-struct synclass synclass[] = {
-	"CWORD",		"character is nothing special",
-	"CNL",		"newline character",
-	"CBACK",		"a backslash character",
-	"CSQUOTE",	"single quote",
-	"CDQUOTE",	"double quote",
-	"CENDQUOTE",	"a terminating quote",
-	"CBQUOTE",	"backwards single quote",
-	"CVAR",		"a dollar sign",
-	"CENDVAR",	"a '}' character",
-	"CEOF",		"end of file",
-	"CCTL",		"like CWORD, except it must be escaped",
-	"CSPCL",		"these terminate a word",
-	NULL, NULL
-};
-
-
-/*
- * Syntax classes for is_ functions.  Warning:  if you add new classes
- * you may have to change the definition of the is_in_name macro.
- */
-struct synclass is_entry[] = {
-	"ISDIGIT",	"a digit",
-	"ISUPPER",	"an upper case letter",
-	"ISLOWER",	"a lower case letter",
-	"ISUNDER",	"an underscore",
-	"ISSPECL",	"the name of a special parameter",
-	NULL, NULL,
-};
-
-char writer[] = "\
-/*\n\
- * This file was generated by the mksyntax program.\n\
- */\n\
-\n";
-
-
-FILE *cfile;
-FILE *hfile;
-char *syntax[513];
-int base;
-int size;		/* number of values which a char variable can have */
-int nbits;		/* number of bits in a character */
-int digit_contig;	/* true if digits are contiguous */
-
-
-main() {
-	char c;
-	char d;
-	int sign;
-	int i;
-	char buf[80];
-	int pos;
-	static char digit[] = "0123456789";
-
-	/* Create output files */
-	if ((cfile = fopen("syntax.c", "w")) == NULL) {
-		perror("syntax.c");
-		exit(2);
-	}
-	if ((hfile = fopen("syntax.h", "w")) == NULL) {
-		perror("syntax.h");
-		exit(2);
-	}
-	fputs(writer, hfile);
-	fputs(writer, cfile);
-
-	/* Determine the characteristics of chars. */
-	c = -1;
-	if (c < 0)
-		sign = 1;
-	else
-		sign = 0;
-	for (nbits = 1 ; ; nbits++) {
-		d = (1 << nbits) - 1;
-		if (d == c)
-			break;
-	}
-	printf("%s %d bit chars\n", sign? "signed" : "unsigned", nbits);
-	if (nbits > 9) {
-		fputs("Characters can't have more than 9 bits\n", stderr);
-		exit(2);
-	}
-	size = (1 << nbits) + 1;
-	base = 1;
-	if (sign)
-		base += 1 << (nbits - 1);
-	digit_contig = 1;
-	for (i = 0 ; i < 10 ; i++) {
-		if (digit[i] != '0' + i)
-			digit_contig = 0;
-	}
-
-	fputs("#include <sys/cdefs.h>\n", hfile);
-
-	/* Generate the #define statements in the header file */
-	fputs("/* Syntax classes */\n", hfile);
-	for (i = 0 ; synclass[i].name ; i++) {
-		sprintf(buf, "#define %s %d", synclass[i].name, i);
-		fputs(buf, hfile);
-		for (pos = strlen(buf) ; pos < 32 ; pos = pos + 8 &~ 07)
-			putc('\t', hfile);
-		fprintf(hfile, "/* %s */\n", synclass[i].comment);
-	}
-	putc('\n', hfile);
-	fputs("/* Syntax classes for is_ functions */\n", hfile);
-	for (i = 0 ; is_entry[i].name ; i++) {
-		sprintf(buf, "#define %s %#o", is_entry[i].name, 1 << i);
-		fputs(buf, hfile);
-		for (pos = strlen(buf) ; pos < 32 ; pos = pos + 8 &~ 07)
-			putc('\t', hfile);
-		fprintf(hfile, "/* %s */\n", is_entry[i].comment);
-	}
-	putc('\n', hfile);
-	fprintf(hfile, "#define SYNBASE %d\n", base);
-	fprintf(hfile, "#define PEOF %d\n\n", -base);
-	putc('\n', hfile);
-	fputs("#define BASESYNTAX (basesyntax + SYNBASE)\n", hfile);
-	fputs("#define DQSYNTAX (dqsyntax + SYNBASE)\n", hfile);
-	fputs("#define SQSYNTAX (sqsyntax + SYNBASE)\n", hfile);
-	putc('\n', hfile);
-	output_type_macros();		/* is_digit, etc. */
-	putc('\n', hfile);
-
-	/* Generate the syntax tables. */
-	fputs("#include \"shell.h\"\n", cfile);
-	fputs("#include \"syntax.h\"\n\n", cfile);
-	init();
-	fputs("/* syntax table used when not in quotes */\n", cfile);
-	add("\n", "CNL");
-	add("\\", "CBACK");
-	add("'", "CSQUOTE");
-	add("\"", "CDQUOTE");
-	add("`", "CBQUOTE");
-	add("$", "CVAR");
-	add("}", "CENDVAR");
-	add("<>();&| \t", "CSPCL");
-	print("basesyntax");
-	init();
-	fputs("\n/* syntax table used when in double quotes */\n", cfile);
-	add("\n", "CNL");
-	add("\\", "CBACK");
-	add("\"", "CENDQUOTE");
-	add("`", "CBQUOTE");
-	add("$", "CVAR");
-	add("}", "CENDVAR");
-	add("!*?[=", "CCTL");
-	print("dqsyntax");
-	init();
-	fputs("\n/* syntax table used when in single quotes */\n", cfile);
-	add("\n", "CNL");
-	add("'", "CENDQUOTE");
-	add("!*?[=", "CCTL");
-	print("sqsyntax");
-	filltable("0");
-	fputs("\n/* character classification table */\n", cfile);
-	add("0123456789", "ISDIGIT");
-	add("abcdefghijklmnopqrstucvwxyz", "ISLOWER");
-	add("ABCDEFGHIJKLMNOPQRSTUCVWXYZ", "ISUPPER");
-	add("_", "ISUNDER");
-	add("#?$!-*@", "ISSPECL");
-	print("is_type");
-	if (! digit_contig)
-		digit_convert();
-	exit(0);
-}
-
-
-
-/*
- * Clear the syntax table.
- */
-
-filltable(dftval)
-	char *dftval;
-	{
-	int i;
-
-	for (i = 0 ; i < size ; i++)
-		syntax[i] = dftval;
-}
-
-
-/*
- * Initialize the syntax table with default values.
- */
-
-init() {
-	filltable("CWORD");
-	syntax[0] = "CEOF";
-	syntax[base + CTLESC] = "CCTL";
-	syntax[base + CTLVAR] = "CCTL";
-	syntax[base + CTLENDVAR] = "CCTL";
-	syntax[base + CTLBACKQ] = "CCTL";
-	syntax[base + CTLBACKQ + CTLQUOTE] = "CCTL";
-}
-
-
-/*
- * Add entries to the syntax table.
- */
-
-add(p, type)
-	char *p, *type;
-	{
-	while (*p)
-		syntax[*p++ + base] = type;
-}
-
-
-
-/*
- * Output the syntax table.
- */
-
-print(name)
-	char *name;
-	{
-	int i;
-	int col;
-
-	fprintf(hfile, "extern const char %s[];\n", name);
-	fprintf(cfile, "const char %s[%d] = {\n", name, size);
-	col = 0;
-	for (i = 0 ; i < size ; i++) {
-		if (i == 0) {
-			fputs("      ", cfile);
-		} else if ((i & 03) == 0) {
-			fputs(",\n      ", cfile);
-			col = 0;
-		} else {
-			putc(',', cfile);
-			while (++col < 9 * (i & 03))
-				putc(' ', cfile);
-		}
-		fputs(syntax[i], cfile);
-		col += strlen(syntax[i]);
-	}
-	fputs("\n};\n", cfile);
-}
-
-
-
-/*
- * Output character classification macros (e.g. is_digit).  If digits are
- * contiguous, we can test for them quickly.
- */
-
-char *macro[] = {
-	"#define is_digit(c)\t((is_type+SYNBASE)[c] & ISDIGIT)",
-	"#define is_alpha(c)\t((is_type+SYNBASE)[c] & (ISUPPER|ISLOWER))",
-	"#define is_name(c)\t((is_type+SYNBASE)[c] & (ISUPPER|ISLOWER|ISUNDER))",
-	"#define is_in_name(c)\t((is_type+SYNBASE)[c] & (ISUPPER|ISLOWER|ISUNDER|ISDIGIT))",
-	"#define is_special(c)\t((is_type+SYNBASE)[c] & (ISSPECL|ISDIGIT))",
-	NULL
-};
-
-output_type_macros() {
-	char **pp;
-
-	if (digit_contig)
-		macro[0] = "#define is_digit(c)\t((unsigned)((c) - '0') <= 9)";
-	for (pp = macro ; *pp ; pp++)
-		fprintf(hfile, "%s\n", *pp);
-	if (digit_contig)
-		fputs("#define digit_val(c)\t((c) - '0')\n", hfile);
-	else
-		fputs("#define digit_val(c)\t(digit_value[c])\n", hfile);
-}
-
-
-
-/*
- * Output digit conversion table (if digits are not contiguous).
- */
-
-digit_convert() {
-	int maxdigit;
-	static char digit[] = "0123456789";
-	char *p;
-	int i;
-
-	maxdigit = 0;
-	for (p = digit ; *p ; p++)
-		if (*p > maxdigit)
-			maxdigit = *p;
-	fputs("extern const char digit_value[];\n", hfile);
-	fputs("\n\nconst char digit_value[] = {\n", cfile);
-	for (i = 0 ; i <= maxdigit ; i++) {
-		for (p = digit ; *p && *p != i ; p++);
-		if (*p == '\0')
-			p = digit;
-		fprintf(cfile, "      %d,\n", p - digit);
-	}
-	fputs("};\n", cfile);
-}
Index: trunk/minix/commands/ash/mktokens
===================================================================
--- trunk/minix/commands/ash/mktokens	(revision 9)
+++ 	(revision )
@@ -1,121 +1,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991 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.
-#
-#	@(#)mktokens	5.1 (Berkeley) 3/7/91
-
-# All calls to awk removed, because Minix bawk is deficient.  (kjb)
-
-# 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.
-
-cat > /tmp/ka$$ <<\!
-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"
-!
-nl=`wc -l /tmp/ka$$`
-exec > token.def
-i=0
-while read line
-do
-	set -$- $line
-	echo "#define $1 $i"
-	i=`expr $i + 1`
-done </tmp/ka$$
-echo '
-/* Array indicating which tokens mark the end of a list */
-const char tokendlist[] = {'
-while read line
-do
-	set -$- $line
-	echo "	$2,"
-done </tmp/ka$$
-echo '};
-
-char *const tokname[] = {'
-sed -e 's/"/\\"/g' \
-    -e 's/[^	 ]*[	 ][	 ]*[^	 ]*[	 ][	 ]*\(.*\)/	"\1",/' \
-    /tmp/ka$$
-echo '};
-'
-i=0
-go=
-sed 's/"//g' /tmp/ka$$ |
-	while read line
-	do
-		set -$- $line
-		if [ "$1" = TIF ]
-		then
-			echo "#define KWDOFFSET $i"
-			echo
-			echo "char *const parsekwd[] = {"
-			go=true
-		fi
-		if [ "$go" ]
-		then
-			echo "	\"$3\","
-		fi
-		i=`expr $i + 1`
-	done
-echo '	0
-};'
-
-rm /tmp/ka$$
Index: trunk/minix/commands/ash/mystring.c
===================================================================
--- trunk/minix/commands/ash/mystring.c	(revision 9)
+++ 	(revision )
@@ -1,174 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)mystring.c	5.1 (Berkeley) 3/7/91";
-#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.
- *	strchr(s, c)		Find first occurance of c in s.
- *	bcopy(from, to, n)	Copy a block of memory.
- *	number(s)		Convert a string of digits to an integer.
- *	is_number(s)		Return true if s is a string of digits.
- */
-
-#include "shell.h"
-#include "syntax.h"
-#include "error.h"
-#include "mystring.h"
-
-
-char nullstr[1];		/* zero length string */
-
-
-/*
- * 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(from, to, size)
-	register char const *from;
-	register char *to;
-	register int size;
-	{
-
-	while (--size > 0) {
-		if ((*to++ = *from++) == '\0')
-			return;
-	}
-	*to = '\0';
-}
-
-
-/*
- * strchr - find first occurrence of a character in a string.
- */
-
-#ifndef SYS5
-char *
-mystrchr(s, charwanted)
-	char const *s;
-	register char charwanted;
-	{
-	register char const *scan;
-
-	/*
-	 * The odd placement of the two tests is so NUL is findable.
-	 */
-	for (scan = s ; *scan != charwanted ; )	/* ++ moved down for opt. */
-		if (*scan++ == '\0')
-			return NULL;
-	return (char *)scan;
-}
-#endif
-
-
-
-/*
- * bcopy - copy bytes
- *
- * This routine was derived from code by Henry Spencer.
- */
-
-void
-mybcopy(src, dst, length)
-	pointer dst;
-	const pointer src;
-	register int length;
-	{
-	register char *d = dst;
-	register char *s = src;
-
-	while (--length >= 0)
-		*d++ = *s++;
-}
-
-
-/*
- * prefix -- see if pfx is a prefix of string.
- */
-
-int
-prefix(pfx, string)
-	register char const *pfx;
-	register char const *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(s)
-	const char *s;
-	{
-
-	if (! is_number(s))
-		error2("Illegal number", (char *)s);
-	return atoi(s);
-}
-
-
-
-/*
- * Check for a valid number.  This should be elsewhere.
- */
-
-int
-is_number(p)
-	register const char *p;
-	{
-	do {
-		if (! is_digit(*p))
-			return 0;
-	} while (*++p != '\0');
-	return 1;
-}
Index: trunk/minix/commands/ash/mystring.h
===================================================================
--- trunk/minix/commands/ash/mystring.h	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)mystring.h	5.1 (Berkeley) 3/7/91
- */
-
-#ifndef SYSV
-#define strchr mystrchr
-#endif
-
-#ifdef __STDC__
-void scopyn(const char *, char *, int);
-char *strchr(const char *, int);
-void mybcopy(const pointer, pointer, int);
-int prefix(const char *, const char *);
-int number(const char *);
-int is_number(const char *);
-int strcmp(const char *, const char *);	/* from C library */
-char *strcpy(char *, const char *);	/* from C library */
-int strlen(const char *);		/* from C library */
-char *strcat(char *, const char *);	/* from C library */
-char *strerror(int);			/* from C library */
-#else
-void scopyn();
-char *strchr();
-void mybcopy();
-int prefix();
-int number();
-int is_number();
-int strcmp();
-char *strcpy();
-int strlen();
-char *strcat();
-char *strerror();
-#endif
-
-#define equal(s1, s2)	(strcmp(s1, s2) == 0)
-#define scopy(s1, s2)	((void)strcpy(s2, s1))
-#define bcopy(src, dst, n)	mybcopy((pointer)(src), (pointer)(dst), n)
Index: trunk/minix/commands/ash/nodes.c.pat
===================================================================
--- trunk/minix/commands/ash/nodes.c.pat	(revision 9)
+++ 	(revision )
@@ -1,177 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)nodes.c.pat	5.2 (Berkeley) 3/8/91
- */
-
-/*
- * 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 */
-#ifdef __STDC__
-pointer funcblock;		/* block to allocate function from */
-#else
-char *funcblock;		/* block to allocate function from */
-#endif
-char *funcstring;		/* block to allocate strings from */
-
-%SIZES
-
-
-#ifdef __STDC__
-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 *);
-#else
-STATIC void calcsize();
-STATIC void sizenodelist();
-STATIC union node *copynode();
-STATIC struct nodelist *copynodelist();
-STATIC char *nodesavestr();
-#endif
-
-
-
-/*
- * 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 += 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;
-	    *(char **)&funcblock += 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++);
-      funcstring = q;
-      return rtn;
-}
-
-
-
-/*
- * Free a parse tree.
- */
-
-void
-freefunc(n)
-      union node *n;
-      {
-      if (n)
-	    ckfree(n);
-}
Index: trunk/minix/commands/ash/nodetypes
===================================================================
--- trunk/minix/commands/ash/nodetypes	(revision 9)
+++ 	(revision )
@@ -1,140 +1,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991 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.
-#
-#	@(#)nodetypes	5.1 (Berkeley) 3/7/91
-
-# 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 compex 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
-NFROM 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
-
-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)
Index: trunk/minix/commands/ash/options.c
===================================================================
--- trunk/minix/commands/ash/options.c	(revision 9)
+++ 	(revision )
@@ -1,397 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)options.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-#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"
-
-char *arg0;			/* value of $0 */
-struct shparam shellparam;	/* current positional parameters */
-char **argptr;			/* argument list for builtin commands */
-char *optarg;			/* set by nextopt (like getopt) */
-char *optptr;			/* used by nextopt */
-int editable;			/* isatty(0) && isatty(1) */
-
-char *minusc;			/* argument to -c option */
-
-
-#ifdef __STDC__
-STATIC void options(int);
-STATIC void setoption(int, int);
-#else
-STATIC void options();
-STATIC void setoption();
-#endif
-
-
-
-/*
- * Process the shell command line arguments.
- */
-
-void
-procargs(argc, argv)
-	char **argv;
-	{
-	char *p;
-
-	argptr = argv;
-	if (argc > 0)
-		argptr++;
-	for (p = optval ; p < optval + sizeof optval - 1 ; p++)
-		*p = 2;
-	options(1);
-	if (*argptr == NULL && minusc == NULL)
-		sflag = 1;
-	editable = (isatty(0) && isatty(1));
-	if (iflag == 2 && sflag == 1 && editable)
-		iflag = 1;
-	if (jflag == 2)
-		jflag = iflag;
-	for (p = optval ; p < optval + sizeof optval - 1 ; p++)
-		if (*p == 2)
-			*p = 0;
-	arg0 = argv[0];
-	if (sflag == 0) {
-		arg0 = *argptr++;
-		if (minusc == NULL) {
-			commandname = arg0;
-			setinputfile(commandname, 0);
-		}
-	}
-	shellparam.p = argptr;
-	/* assert(shellparam.malloc == 0 && shellparam.nparam == 0); */
-	while (*argptr) {
-		shellparam.nparam++;
-		argptr++;
-	}
-	setinteractive(iflag);
-	setjobctl(jflag);
-}
-
-
-
-/*
- * Process shell options.  The global variable argptr contains a pointer
- * to the argument list; we advance it past the options.
- */
-
-STATIC void
-options(cmdline) {
-	register 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) {
-				char *q;
-#ifdef NOHACK	/* removing this code allows sh -ce 'foo' for compat */
-				if (*p == '\0')
-#endif
-					q = *argptr++;
-				if (q == NULL || minusc != NULL)
-					error("Bad -c option");
-				minusc = q;
-#ifdef NOHACK
-				break;
-#endif
-			} else {
-				setoption(c, val);
-			}
-		}
-		if (! cmdline)
-			break;
-	}
-}
-
-
-STATIC void
-setoption(flag, val)
-	char flag;
-	int val;
-	{
-	register char *p;
-
-	if ((p = strchr(optchar, flag)) == NULL)
-		error("Illegal option -%c", flag);
-	optval[p - optchar] = val;
-}
-
-
-
-#ifdef mkinit
-INCLUDE "options.h"
-
-SHELLPROC {
-	char *p;
-
-	for (p = optval ; p < optval + sizeof optval ; p++)
-		*p = 0;
-}
-#endif
-
-
-/*
- * Set the shell parameters.
- */
-
-void
-setparam(argv)
-	char **argv;
-	{
-	char **newparam;
-	char **ap;
-	int nparam;
-
-	for (nparam = 0 ; argv[nparam] ; nparam++);
-	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(param)
-	struct shparam *param;
-	{
-	char **ap;
-
-	if (param->malloc) {
-		for (ap = param->p ; *ap ; ap++)
-			ckfree(*ap);
-		ckfree(param->p);
-	}
-}
-
-
-
-/*
- * The shift builtin command.
- */
-
-shiftcmd(argc, argv)  char **argv; {
-	int n;
-	char **ap1, **ap2;
-
-	n = 1;
-	if (argc > 1)
-		n = number(argv[1]);
-	if (n > shellparam.nparam)
-		n = shellparam.nparam;
-	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.
- */
-
-setcmd(argc, argv)  char **argv; {
-	if (argc == 1)
-		return showvarscmd(argc, argv);
-	INTOFF;
-	options(0);
-	setinteractive(iflag);
-	setjobctl(jflag);
-	if (*argptr != NULL) {
-		setparam(argptr);
-	}
-	INTON;
-	return 0;
-}
-
-
-/*
- * 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.
- */
-
-getoptscmd(argc, argv)  char **argv; {
-	register char *p, *q;
-	char c;
-	char s[10];
-
-	if (argc != 3)
-		error("Usage: getopts optstring var");
-	if (shellparam.optnext == NULL) {
-		shellparam.optnext = shellparam.p;
-		shellparam.optptr = NULL;
-	}
-	if ((p = shellparam.optptr) == NULL || *p == '\0') {
-		p = *shellparam.optnext;
-		if (p == NULL || *p != '-' || *++p == '\0') {
-atend:
-			fmtstr(s, 10, "%d", shellparam.optnext - shellparam.p + 1);
-			setvar("OPTIND", s, 0);
-			shellparam.optnext = NULL;
-			return 1;
-		}
-		shellparam.optnext++;
-		if (p[0] == '-' && p[1] == '\0')	/* check for "--" */
-			goto atend;
-	}
-	c = *p++;
-	for (q = argv[1] ; *q != c ; ) {
-		if (*q == '\0') {
-			out1fmt("Illegal option -%c\n", c);
-			c = '?';
-			goto out;
-		}
-		if (*++q == ':')
-			q++;
-	}
-	if (*++q == ':') {
-		if (*p == '\0') {
-			if ((p = *shellparam.optnext) == NULL) {
-				out1fmt("No arg for -%c option\n", c);
-				c = '?';
-				goto out;
-			}
-			shellparam.optnext++;
-		}
-		setvar("OPTARG", p, 0);
-		p = "";
-	}
-out:
-	shellparam.optptr = p;
-	s[0] = c;
-	s[1] = '\0';
-	setvar(argv[2], s, 0);
-	fmtstr(s, 10, "%d", shellparam.optnext - shellparam.p + 1);
-	setvar("OPTIND", s, 0);
-	return 0;
-}
-
-/*
- * 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(optstring)
-	char *optstring;
-	{
-	register char *p, *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);
-		optarg = p;
-		p = NULL;
-	}
-	optptr = p;
-	return c;
-}
Index: trunk/minix/commands/ash/options.h
===================================================================
--- trunk/minix/commands/ash/options.h	(revision 9)
+++ 	(revision )
@@ -1,90 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)options.h	5.1 (Berkeley) 3/7/91
- */
-
-struct shparam {
-	int nparam;	/* number of positional parameters (without $0) */
-	char malloc;	/* true if parameter list dynamicly allocated */
-	char **p;		/* parameter list */
-	char **optnext;	/* next parameter to be processed by getopts */
-	char *optptr;	/* used by getopts */
-};
-
-
-
-#define eflag optval[0]
-#define fflag optval[1]
-#define Iflag optval[2]
-#define iflag optval[3]
-#define jflag optval[4]
-#define nflag optval[5]
-#define sflag optval[6]
-#define xflag optval[7]
-#define zflag optval[8]
-#define vflag optval[9]
-
-#define NOPTS	10
-
-#ifdef DEFINE_OPTIONS
-const char optchar[NOPTS+1] = "efIijnsxzv";       /* shell flags */
-char optval[NOPTS+1];           /* values of option flags */
-#else
-extern const char optchar[NOPTS+1];
-extern char optval[NOPTS+1];
-#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 *optarg;		/* set by nextopt */
-extern char *optptr;		/* used by nextopt */
-extern int editable;		/* isatty(0) && isatty(1) */
-
-
-#ifdef __STDC__
-void procargs(int, char **);
-void setparam(char **);
-void freeparam(struct shparam *);
-int nextopt(char *);
-#else
-void procargs();
-void setparam();
-void freeparam();
-int nextopt();
-#endif
Index: trunk/minix/commands/ash/output.c
===================================================================
--- trunk/minix/commands/ash/output.c	(revision 9)
+++ 	(revision )
@@ -1,531 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)output.c	5.1 (Berkeley) 3/7/91";
-#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 <stdio.h>	/* defines BUFSIZ */
-#include "shell.h"
-#include "syntax.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#ifdef __STDC__
-#include "stdarg.h"
-#else
-#include <varargs.h>
-#endif
-#include <errno.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(block, length, file)
-	char *block;
-	int length;
-	struct output *file;
-	{
-	file->nextc = block;
-	file->nleft = --length;
-	file->fd = BLOCK_OUT;
-	file->flags = 0;
-}
-#endif
-
-
-void
-out1str(p)
-	char *p;
-	{
-	outstr(p, out1);
-}
-
-
-void
-out2str(p)
-	char *p;
-	{
-	outstr(p, out2);
-}
-
-
-void
-outstr(p, file)
-	register char *p;
-	register struct output *file;
-	{
-	while (*p)
-		outc(*p++, file);
-}
-
-
-char out_junk[16];
-
-
-void
-emptyoutbuf(dest)
-	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
-flushall() {
-	flushout(&output);
-	flushout(&errout);
-}
-
-
-void
-flushout(dest)
-	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() {
-	INTOFF;
-	if (output.buf) {
-		ckfree(output.buf);
-		output.buf = NULL;
-		output.nleft = 0;
-	}
-	INTON;
-}
-
-
-#ifdef __STDC__
-void
-outfmt(struct output *file, char *fmt, ...) {
-	va_list ap;
-
-	va_start(ap, fmt);
-	doformat(file, fmt, ap);
-	va_end(ap);
-}
-
-
-void
-out1fmt(char *fmt, ...) {
-	va_list ap;
-
-	va_start(ap, fmt);
-	doformat(out1, fmt, ap);
-	va_end(ap);
-}
-
-
-void
-fmtstr(char *outbuf, int length, 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);
-}
-
-#else /* not __STDC__ */
-
-void
-outfmt(va_alist)
-	va_dcl
-	{
-	va_list ap;
-	struct output *file;
-	char *fmt;
-
-	va_start(ap);
-	file = va_arg(ap, struct output *);
-	fmt = va_arg(ap, char *);
-	doformat(file, fmt, ap);
-	va_end(ap);
-}
-
-
-void
-out1fmt(va_alist)
-	va_dcl
-	{
-	va_list ap;
-	char *fmt;
-
-	va_start(ap);
-	fmt = va_arg(ap, char *);
-	doformat(out1, fmt, ap);
-	va_end(ap);
-}
-
-
-void
-fmtstr(va_alist)
-	va_dcl
-	{
-	va_list ap;
-	struct output strout;
-	char *outbuf;
-	int length;
-	char *fmt;
-
-	va_start(ap);
-	outbuf = va_arg(ap, char *);
-	length = va_arg(ap, int);
-	fmt = va_arg(ap, char *);
-	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';
-}
-#endif /* __STDC__ */
-
-
-/*
- * Formatted output.  This routine handles a subset of the printf formats:
- * - Formats supported: d, u, o, X, s, and c.
- * - The x format is also accepted but is treated like X.
- * - The l modifier is 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 __STDC__
-static const char digit[16] = "0123456789ABCDEF";
-#else
-static const char digit[17] = "0123456789ABCDEF";
-#endif
-
-
-void
-doformat(dest, f, ap)
-	register struct output *dest;
-	register char *f;		/* format string */
-	va_list ap;
-	{
-	register char c;
-	char temp[TEMPSIZE];
-	int flushleft;
-	int sharp;
-	int width;
-	int prec;
-	int islong;
-	char *p;
-	int sign;
-	long l;
-	unsigned long num;
-	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;
-		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') {
-			islong++;
-			f++;
-		}
-		switch (*f) {
-		case 'd':
-			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 'x':
-			/* we don't implement 'x'; treat like 'X' */
-		case 'X':
-			base = 16;
-uns_number:	  /* an unsigned number */
-			sign = 0;
-			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++;
-	}
-}
-
-
-
-/*
- * Version of write which resumes after a signal is caught.
- */
-
-int
-xwrite(fd, buf, nbytes)
-	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.
- */
-
-int
-xioctl(fd, request, arg) {
-	int i;
-
-	while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR);
-	return i;
-}
Index: trunk/minix/commands/ash/output.h
===================================================================
--- trunk/minix/commands/ash/output.h	(revision 9)
+++ 	(revision )
@@ -1,94 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)output.h	5.1 (Berkeley) 3/7/91
- */
-
-#ifndef OUTPUT_INCL
-
-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;
-
-
-#ifdef __STDC__
-void outstr(char *, struct output *);
-void out1str(char *);
-void out2str(char *);
-void outfmt(struct output *, char *, ...);
-void out1fmt(char *, ...);
-void fmtstr(char *, int, char *, ...);
-/* void doformat(struct output *, char *, va_list); */
-void doformat();
-void emptyoutbuf(struct output *);
-void flushall(void);
-void flushout(struct output *);
-void freestdout(void);
-int xwrite(int, char *, int);
-int xioctl(int, int, int);
-#else
-void outstr();
-void out1str();
-void out2str();
-void outfmt();
-void out1fmt();
-void fmtstr();
-/* void doformat(); */
-void doformat();
-void emptyoutbuf();
-void flushall();
-void flushout();
-void freestdout();
-int xwrite();
-int xioctl();
-#endif
-
-#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
Index: trunk/minix/commands/ash/parser.c
===================================================================
--- trunk/minix/commands/ash/parser.c	(revision 9)
+++ 	(revision )
@@ -1,1329 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)parser.c	5.3 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-#include "shell.h"
-#include "parser.h"
-#include "nodes.h"
-#include "expand.h"	/* defines rmescapes() */
-#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"
-
-
-/*
- * Shell command parser.
- */
-
-#define EOFMARKLEN 79
-
-/* values returned by readtoken */
-#include "token.def"
-
-
-
-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 */
-};
-
-
-
-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 */
-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 */
-
-
-#define GDB_HACK 1 /* avoid local declarations which gdb can't handle */
-#ifdef GDB_HACK
-static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0'};
-static const char types[] = "}-+?=";
-#endif
-
-
-STATIC union node *list __P((int));
-STATIC union node *andor __P((void));
-STATIC union node *pipeline __P((void));
-STATIC union node *command __P((void));
-STATIC union node *simplecmd __P((union node **, union node *));
-STATIC void parsefname __P((void));
-STATIC void parseheredoc __P((void));
-STATIC int readtoken __P((void));
-STATIC int readtoken1 __P((int, char const *, char *, int));
-STATIC void attyline __P((void));
-STATIC int noexpand __P((char *));
-STATIC void synexpect __P((int));
-STATIC void synerror __P((char *));
-
-#if ATTY || READLINE
-STATIC void putprompt __P((char *));
-#else /* not ATTY */
-#define putprompt(s)	out2str(s)
-#endif
-
-
-
-
-/*
- * Read and parse a command.  Returns NEOF on end of file.  (NULL is a
- * valid parse tree indicating a blank line.)
- */
-
-union node *
-parsecmd(interact) {
-	int t;
-	extern int exitstatus;
-
-	doprompt = interact;
-	if (doprompt)
-		putprompt(exitstatus == 0 ? ps1val() : pseval());
-	needprompt = 0;
-	if ((t = readtoken()) == TEOF)
-		return NEOF;
-	if (t == TNL)
-		return NULL;
-	tokpushback++;
-	return list(1);
-}
-
-
-STATIC union node *
-list(nlflag) {
-	union node *n1, *n2, *n3, **pn;
-	int first;
-
-	checkkwd = 2;
-	if (nlflag == 0 && tokendlist[peektoken()])
-		return NULL;
-	n1 = andor();
-	for (first = 1; ; first = 0) {
-		switch (readtoken()) {
-		case TBACKGND:
-			pn = &n1;
-			if (!first && n1->type == NSEMI) pn = &n1->nbinary.ch2;
-			if ((*pn)->type == NCMD || (*pn)->type == NPIPE) {
-				(*pn)->ncmd.backgnd = 1;
-			} else if ((*pn)->type == NREDIR) {
-				(*pn)->type = NBACKGND;
-			} else {
-				n3 = (union node *)stalloc(sizeof (struct nredir));
-				n3->type = NBACKGND;
-				n3->nredir.n = *pn;
-				n3->nredir.redirect = NULL;
-				*pn = n3;
-			}
-			goto tsemi;
-		case TNL:
-			tokpushback++;
-			/* fall through */
-tsemi:		case TSEMI:
-			if (readtoken() == TNL) {
-				parseheredoc();
-				if (nlflag)
-					return n1;
-			} else {
-				tokpushback++;
-			}
-			checkkwd = 2;
-			if (tokendlist[peektoken()])
-				return n1;
-			n2 = andor();
-			n3 = (union node *)stalloc(sizeof (struct nbinary));
-			n3->type = NSEMI;
-			n3->nbinary.ch1 = n1;
-			n3->nbinary.ch2 = n2;
-			n1 = n3;
-			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() {
-	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() {
-	union node *n1, *pipenode;
-	struct nodelist *lp, *prev;
-
-	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++;
-	return n1;
-}
-
-
-
-STATIC union node *
-command() {
-	union node *n1, *n2;
-	union node *ap, **app;
-	union node *cp, **cpp;
-	union node *redir, **rpp;
-	int t;
-
-	checkkwd = 2;
-	redir = 0;
-	rpp = &redir;
-	/* Check for redirection which may precede command */
-	while (readtoken() == TREDIR) {
-		*rpp = n2 = redirnode;
-		rpp = &n2->nfile.next;
-		parsefname();
-	}
-	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 = &ap;
-			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;
-			/* A newline or semicolon is required here to end
-			   the list.  */
-			if (lasttoken != TNL && lasttoken != TSEMI)
-				synexpect(-1);
-		} else {
-#ifndef GDB_HACK
-			static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE,
-								   '@', '=', '\0'};
-#endif
-			n2 = (union node *)stalloc(sizeof (struct narg));
-			n2->type = NARG;
-			n2->narg.text = (char *)argvars;
-			n2->narg.backquote = NULL;
-			n2->narg.next = NULL;
-			n1->nfor.args = n2;
-			/* A newline or semicolon is optional here. Anything
-			   else gets pushed back so we can read it again.  */
-			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;
-		while (checkkwd = 2, readtoken() == TWORD) {
-			*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 (readtoken() != TPIPE)
-					break;
-				app = &ap->narg.next;
-				if (readtoken() != TWORD)
-					synexpect(TWORD);
-			}
-			ap->narg.next = NULL;
-			if (lasttoken != TRP)
-				synexpect(TRP);
-			cp->nclist.body = list(0);
-			if ((t = readtoken()) == TESAC)
-				tokpushback++;
-			else if (t != TENDCASE)
-				synexpect(TENDCASE);
-			cpp = &cp->nclist.next;
-		}
-		*cpp = NULL;
-		if (lasttoken != TESAC)
-			synexpect(TESAC);
-		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 TNL:
-	case TSEMI:
-	case TEND:
-	case TRP:
-	case TEOF:
-	case TWORD:
-		tokpushback++;
-		return simplecmd(rpp, redir);
-	default:
-		synexpect(-1);
-	}
-
-	/* 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;
-	}
-	return n1;
-}
-
-
-STATIC union node *
-simplecmd(rpp, redir)
-	union node **rpp, *redir;
-	{
-	union node *args, **app;
-	union node **orig_rpp = rpp;
-	union node *n;
-
-	/* 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;
-	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();
-			return n;
-		} 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;
-	return n;
-}
-
-
-STATIC void
-parsefname() {
-	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) {
-		if (is_digit(wordtext[0]))
-			n->ndup.dupfd = digit_val(wordtext[0]);
-		else if (wordtext[0] == '-')
-			n->ndup.dupfd = -1;
-		else
-			goto bad;
-		if (wordtext[1] != '\0') {
-bad:
-			synerror("Bad fd number");
-		}
-	} else {
-		n->nfile.fname = (union node *)stalloc(sizeof (struct narg));
-		n = n->nfile.fname;
-		n->type = NARG;
-		n->narg.next = NULL;
-		n->narg.text = wordtext;
-		n->narg.backquote = backquotelist;
-	}
-}
-
-
-/*
- * Input any here documents.
- */
-
-STATIC void
-parseheredoc() {
-	struct heredoc *here;
-	union node *n;
-
-	while (heredoclist) {
-		here = heredoclist;
-		heredoclist = here->next;
-		if (needprompt) {
-			putprompt(ps2val());
-			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() {
-	int t;
-
-	t = readtoken();
-	tokpushback++;
-	return (t);
-}
-
-STATIC int xxreadtoken();
-
-STATIC int
-readtoken() {
-	int t;
-#if DEBUG
-	int alreadyseen = tokpushback;
-#endif
-	
-	t = xxreadtoken();
-
-	if (checkkwd) {
-		/*
-		 * eat newlines
-		 */
-		if (checkkwd == 2) {
-			checkkwd = 0;
-			while (t == TNL) {
-				parseheredoc();
-				t = xxreadtoken();
-			}
-		} else
-			checkkwd = 0;
-		/*
-		 * check for keywords
-		 */
-		if (t == TWORD && !quoteflag) {
-			register 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]));
-					break;
-				}
-			}
-		}
-	}
-#if 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() {
-	register c;
-
-	if (tokpushback) {
-		tokpushback = 0;
-		return lasttoken;
-	}
-	if (needprompt) {
-		putprompt(ps2val());
-		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)
-					putprompt(ps2val());
-				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:;}
-
-STATIC int
-readtoken1(firstc, syntax, eofmark, striptabs)
-	int firstc;
-	char const *syntax;
-	char *eofmark;
-	int striptabs;
-	{
-	register c = firstc;
-	register char *out;
-	int len;
-	char line[EOFMARKLEN + 1];
-	struct nodelist *bqlist;
-	int quotef;
-	int dblquote;
-	int varnest;
-	int oldstyle;
-
-	startlinno = plinno;
-	dblquote = 0;
-	if (syntax == DQSYNTAX)
-		dblquote = 1;
-	quotef = 0;
-	bqlist = NULL;
-	varnest = 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(3, out);	/* permit 3 calls to USTPUTC */
-			switch(syntax[c]) {
-			case CNL:	/* '\n' */
-				if (syntax == BASESYNTAX)
-					goto endword;	/* exit outer loop */
-				USTPUTC(c, out);
-				plinno++;
-				if (doprompt) {
-					putprompt(ps2val());
-				}
-				c = pgetc();
-				goto loop;		/* continue outer loop */
-			case CWORD:
-				USTPUTC(c, out);
-				break;
-			case CCTL:
-				if (eofmark == NULL || dblquote)
-					USTPUTC(CTLESC, out);
-				USTPUTC(c, out);
-				break;
-			case CBACK:	/* backslash */
-				c = pgetc();
-				if (c == PEOF) {
-					USTPUTC('\\', out);
-					pungetc();
-				} else if (c == '\n') {
-					if (doprompt)
-						putprompt(ps2val());
-				} else {
-					if (dblquote && c != '\\' && c != '`' && c != '$'
-							 && (c != '"' || eofmark != NULL))
-						USTPUTC('\\', out);
-					if (SQSYNTAX[c] == CCTL)
-						USTPUTC(CTLESC, out);
-					USTPUTC(c, out);
-					quotef++;
-				}
-				break;
-			case CSQUOTE:
-				syntax = SQSYNTAX;
-				break;
-			case CDQUOTE:
-				syntax = DQSYNTAX;
-				dblquote = 1;
-				break;
-			case CENDQUOTE:
-				if (eofmark) {
-					USTPUTC(c, out);
-				} else {
-					syntax = BASESYNTAX;
-					quotef++;
-					dblquote = 0;
-				}
-				break;
-			case CVAR:	/* '$' */
-				PARSESUB();		/* parse substitution */
-				break;
-			case CENDVAR:	/* '}' */
-				if (varnest > 0) {
-					varnest--;
-					USTPUTC(CTLENDVAR, out);
-				} else {
-					USTPUTC(c, 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 != 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;
-	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) {
-				register 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 {
-					ppushback(line, strlen(line));
-				}
-			}
-		}
-	}
-	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 = NTOFD;
-		else {
-			np->type = NTO;
-			pungetc();
-		}
-	} else {	/* c == '<' */
-		np->nfile.fd = 0;
-		c = pgetc();
-		if (c == '<') {
-			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();
-			}
-		} else if (c == '&')
-			np->type = NFROMFD;
-		else {
-			np->type = NFROM;
-			pungetc();
-		}
-	}
-	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;
-#ifndef GDB_HACK
-	static const char types[] = "}-+?=";
-#endif
-
-	c = pgetc();
-	if (c != '(' && c != '{' && !is_name(c) && !is_special(c)) {
-		USTPUTC('$', out);
-		pungetc();
-	} else if (c == '(') {	/* $(command) */
-		PARSEBACKQNEW();
-	} else {
-		USTPUTC(CTLVAR, out);
-		typeloc = out - stackblock();
-		USTPUTC(VSNORMAL, out);
-		subtype = VSNORMAL;
-		if (c == '{') {
-			c = pgetc();
-			subtype = 0;
-		}
-		if (is_name(c)) {
-			do {
-				STPUTC(c, out);
-				c = pgetc();
-			} while (is_in_name(c));
-		} else {
-			if (! is_special(c))
-badsub:				synerror("Bad substitution");
-			USTPUTC(c, out);
-			c = pgetc();
-		}
-		STPUTC('=', out);
-		flags = 0;
-		if (subtype == 0) {
-			if (c == ':') {
-				flags = VSNUL;
-				c = pgetc();
-			}
-			p = strchr(types, c);
-			if (p == NULL)
-				goto badsub;
-			subtype = p - types + VSNORMAL;
-		} else {
-			pungetc();
-		}
-		if (dblquote)
-			flags |= VSQUOTE;
-		*(stackblock() + typeloc) = subtype | flags;
-		if (subtype != VSNORMAL)
-			varnest++;
-	}
-	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 savedoprompt;
-
-	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);
-		bcopy(stackblock(), str, 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.  */
-		register char *out;
-		register c;
-		int savelen;
-		char *str;
-
-		STARTSTACKSTR(out);
-		while ((c = pgetc ()) != '`') {
-			if (c == '\\') {
-				c = pgetc ();
-				if (c != '\\' && c != '`' && c != '$'
-				    && (!dblquote || c != '"'))
-					STPUTC('\\', out);
-			}
-			if (c == '\n') {
-				plinno++;
-				if (doprompt)
-					putprompt(ps2val());
-			}
-			STPUTC(c, out);
-		}
-		STPUTC('\0', out);
-		savelen = out - stackblock();
-		if (savelen > 0) {
-			str = ckmalloc(savelen);
-			bcopy(stackblock(), str, savelen);
-		}
-		setinputstring(str, 1);
-		savedoprompt = doprompt;
-		doprompt = 0;	/* no prompts while rereading string */
-	}
-	nlpp = &bqlist;
-	while (*nlpp)
-		nlpp = &(*nlpp)->next;
-	*nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
-	(*nlpp)->next = NULL;
-	parsebackquote = oldstyle;
-	n = list(0);
-	if (!oldstyle && (readtoken() != TRP))
-		synexpect(TRP);
-	(*nlpp)->n = n;
-	/* Start reading from old file again.  */
-	if (oldstyle) {
-		popfile();
-		doprompt = savedoprompt;
-	}
-	while (stackblocksize() <= savelen)
-		growstackblock();
-	STARTSTACKSTR(out);
-	if (str) {
-		bcopy(str, out, savelen);
-		STADJUST(savelen, out);
-		INTOFF;
-		ckfree(str);
-		str = NULL;
-		INTON;
-	}
-	parsebackquote = savepbq;
-	handler = savehandler;
-	USTPUTC(CTLBACKQ + dblquote, out);
-	if (oldstyle)
-		goto parsebackq_oldreturn;
-	else
-		goto parsebackq_newreturn;
-}
-
-} /* end of readtoken */
-
-
-
-#ifdef mkinit
-RESET {
-	tokpushback = 0;
-}
-#endif
-
-
-#if READLINE
-/*
- * Remember a prompt for use with readline if input and output is a terminal.
- */
-
-STATIC void
-putprompt(s)
-	char *s;
-	{
-	if (editable) {
-		r_use_prompt = s;
-	} else {
-		out2str(s);
-	}
-}
-#endif
-
-#if ATTY
-/*
- * Called to process a command generated by atty.  We execute the line,
- * and catch any errors that occur so they don't propagate outside of
- * this routine.
- */
-
-STATIC void
-attyline() {
-	char line[256];
-	struct stackmark smark;
-	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
-
-	if (pfgets(line, sizeof line) == NULL)
-		return;				/* "can't happen" */
-	if (setjmp(jmploc.loc)) {
-		if (exception == EXERROR)
-			out2str("\033]D\n");
-		handler = savehandler;
-		longjmp(handler->loc, 1);
-	}
-	savehandler = handler;
-	handler = &jmploc;
-	setstackmark(&smark);
-	evalstring(line);
-	popstackmark(&smark);
-	handler = savehandler;
-	doprompt = 1;
-}
-
-
-/*
- * Output a prompt for atty.  We output the prompt as part of the
- * appropriate escape sequence.  
- */
-
-STATIC void
-putprompt(s)
-	char *s;
-	{
-	register char *p;
-
-	if (attyset() && ! equal(termval(), "emacs")) {
-		if (strchr(s, '\7'))
-			out2c('\7');
-		out2str("\033]P1;");
-		for (p = s ; *p ; p++) {
-			if ((unsigned)(*p - ' ') <= '~' - ' ')
-				out2c(*p);
-		}
-		out2c('\n');
-	} else {
-		out2str(s);
-	}
-}
-#endif
-
-
-
-/*
- * Returns true if the text contains nothing to expand (no dollar signs
- * or backquotes).
- */
-
-STATIC int
-noexpand(text)
-	char *text;
-	{
-	register char *p;
-	register char c;
-
-	p = text;
-	while ((c = *p++) != '\0') {
-		if (c == CTLESC)
-			p++;
-		else if (BASESYNTAX[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(name)
-	char *name;
-	{
-	register 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(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);
-}
-
-
-STATIC void
-synerror(msg)
-	char *msg;
-	{
-	if (commandname)
-		outfmt(&errout, "%s: %d: ", commandname, startlinno);
-	outfmt(&errout, "Syntax error: %s\n", msg);
-	error((char *)NULL);
-}
Index: trunk/minix/commands/ash/parser.h
===================================================================
--- trunk/minix/commands/ash/parser.h	(revision 9)
+++ 	(revision )
@@ -1,74 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)parser.h	5.1 (Berkeley) 3/7/91
- */
-
-/* control characters in argument strings */
-#define CTLESC '\201'
-#define CTLVAR '\202'
-#define CTLENDVAR '\203'
-#define CTLBACKQ '\204'
-#define CTLQUOTE 01		/* ored with CTLBACKQ code if in quotes */
-
-/* variable substitution byte (follows CTLVAR) */
-#define VSTYPE 07		/* type of variable substitution */
-#define VSNUL 040		/* colon--treat the empty string as unset */
-#define VSQUOTE 0100		/* inside double quotes--suppress splitting */
-
-/* values of VSTYPE field */
-#define VSNORMAL 1		/* normal variable:  $var or ${var} */
-#define VSMINUS 2		/* ${var-text} */
-#define VSPLUS 3		/* ${var+text} */
-#define VSQUESTION 4		/* ${var?message} */
-#define VSASSIGN 5		/* ${var=text} */
-
-
-/*
- * 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)
-
-
-#ifdef __STDC__
-union node *parsecmd(int);
-int goodname(char *);
-#else
-union node *parsecmd();
-int goodname();
-#endif
Index: trunk/minix/commands/ash/redir.c
===================================================================
--- trunk/minix/commands/ash/redir.c	(revision 9)
+++ 	(revision )
@@ -1,370 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)redir.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * Code for dealing with input/output redirection.
- */
-
-#include "shell.h"
-#include "nodes.h"
-#include "jobs.h"
-#include "expand.h"
-#include "redir.h"
-#include "eval.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include <sys/types.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <limits.h>
-
-
-#define EMPTY -2		/* marks an unused slot in redirtab */
-#define PIPESIZE 4096		/* amount of buffering in a pipe */
-
-
-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;
-
-#ifdef __STDC__
-STATIC void openredirect(union node *, char *);
-STATIC int openhere(union node *);
-#else
-STATIC void openredirect();
-STATIC int openhere();
-#endif
-
-
-
-/*
- * 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(redir, flags)
-	union node *redir;
-	int flags;
-	{
-	union node *n;
-	struct redirtab *sv;
-	int i;
-	int fd;
-	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) {
-		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;
-		if ((flags & REDIR_PUSH) && sv->renamed[fd] == EMPTY) {
-			INTOFF;
-			if ((i = copyfd(fd, 10)) != EMPTY) {
-				sv->renamed[fd] = i;
-				close(fd);
-			}
-			INTON;
-			if (i == EMPTY)
-				error("Out of file descriptors");
-		} else {
-			close(fd);
-		}
-		if (fd == 0)
-			fd0_redirected++;
-		openredirect(n, memory);
-	}
-	if (memory[1])
-		out1 = &memout;
-	if (memory[2])
-		out2 = &memout;
-}
-
-
-STATIC void
-openredirect(redir, memory)
-	union node *redir;
-	char memory[10];
-	{
-	int fd = redir->nfile.fd;
-	char *fname;
-	int f;
-
-	/* Assume redirection succeeds. */
-	exitstatus = 0;
-
-	/*
-	 * 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 ((f = open(fname, O_RDONLY)) < 0)
-			error("cannot open %s: %s", fname, errmsg(errno, E_OPEN));
-movefd:
-		if (f != fd) {
-			copyfd(f, fd);
-			close(f);
-		}
-		break;
-	case NTO:
-		fname = redir->nfile.expfname;
-#ifdef O_CREAT
-		if ((f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
-			error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-#else
-		if ((f = creat(fname, 0666)) < 0)
-			error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-#endif
-		goto movefd;
-	case NAPPEND:
-		fname = redir->nfile.expfname;
-#ifdef O_APPEND
-		if ((f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0)
-			error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-#else
-		if ((f = open(fname, O_WRONLY)) < 0
-		 && (f = creat(fname, 0666)) < 0)
-			error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-		lseek(f, 0L, 2);
-#endif
-		goto movefd;
-	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);
-		}
-		break;
-	case NHERE:
-	case NXHERE:
-		f = openhere(redir);
-		goto movefd;
-	default:
-		abort();
-	}
-	INTON;
-}
-
-
-/*
- * 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(redir)
-	union node *redir;
-	{
-	int pip[2];
-	int len;
-
-	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() {
-	register 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();
-}
-
-#endif
-
-
-/*
- * Discard all saved file descriptors.
- */
-
-void
-clearredir() {
-	register 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]);
-			}
-			rp->renamed[i] = EMPTY;
-		}
-	}
-}
-
-
-
-/*
- * Copy a file descriptor, like the F_DUPFD option of fcntl.  Returns -1
- * if the source file descriptor is closed, EMPTY if there are no unused
- * file descriptors left.
- */
-
-int
-copyfd(from, to) {
-#ifdef F_DUPFD
-	int newfd;
-
-	newfd = fcntl(from, F_DUPFD, to);
-	if (newfd < 0 && errno == EMFILE)
-		return EMPTY;
-	return newfd;
-#else
-	char toclose[32];
-	int i;
-	int newfd;
-	int e;
-
-	for (i = 0 ; i < to ; i++)
-		toclose[i] = 0;
-	INTOFF;
-	while ((newfd = dup(from)) >= 0 && newfd < to)
-		toclose[newfd] = 1;
-	e = errno;
-	for (i = 0 ; i < to ; i++) {
-		if (toclose[i])
-			close(i);
-	}
-	INTON;
-	if (newfd < 0 && e == EMFILE)
-		return EMPTY;
-	return newfd;
-#endif
-}
-
-/* Return true if fd 0 has already been redirected at least once.  */
-int
-fd0_redirected_p () {
-	return fd0_redirected != 0;
-}
Index: trunk/minix/commands/ash/redir.h
===================================================================
--- trunk/minix/commands/ash/redir.h	(revision 9)
+++ 	(revision )
@@ -1,56 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)redir.h	5.1 (Berkeley) 3/7/91
- */
-
-/* flags passed to redirect */
-#define REDIR_PUSH 01		/* save previous values of file descriptors */
-#define REDIR_BACKQ 02		/* save the command output in memory */
-
-#ifdef __STDC__
-union node;
-void redirect(union node *, int);
-void popredir(void);
-void clearredir(void);
-int copyfd(int, int);
-int fd0_redirected_p(void);
-#else
-void redirect();
-void popredir();
-void clearredir();
-int copyfd();
-int fd0_redirected_p();
-#endif
Index: trunk/minix/commands/ash/shell.h
===================================================================
--- trunk/minix/commands/ash/shell.h	(revision 9)
+++ 	(revision )
@@ -1,107 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)shell.h	5.4 (Berkeley) 4/12/91
- */
-
-/*
- * The follow should be set to reflect the type of system you have:
- *	JOBS -> 1 if you have Berkeley job control, 0 otherwise.
- *	SYMLINKS -> 1 if your system includes symbolic links, 0 otherwise.
- *	DIRENT -> 1 if your system has the SVR3 directory(3X) routines.
- *	UDIR -> 1 if you want the shell to simulate the /u directory.
- *	TILDE -> 1 if you want the shell to expand ~logname.
- *	USEGETPW -> 1 if getpwnam() must be used to look up a name.
- *	ATTY -> 1 to include code for atty(1).
- *	SHORTNAMES -> 1 if your linker cannot handle long names.
- *	READLINE -> 1 if line editing by readline() should be enabled.
- *	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 global "debug" to turn on)
- *	define DEBUG=2 to compile in and turn on debugging.
- *
- * When debugging is on, debugging info will be written to $HOME/trace and
- * a quit signal will generate a core dump.
- */
-
-
-#define JOBS	  0
-
-/* Set SYMLINKS to 0 by request of Giovanni Falzoni, who wrote the
- * symlink patches for Minix; email to minix-devel-l of thu 3 nov.
- */
-
-#if 0
-#define SYMLINKS  defined(S_ISLNK)
-#else
-#define SYMLINKS  0
-#endif
-
-#define DIRENT	  1
-#define UDIR	  0
-#define TILDE	  1
-#define USEGETPW  0
-#define ATTY	  0
-#define READLINE  1
-#define HASHBANG  0
-/* #define BSD */
-#define POSIX	  1
-#define DEBUG	  0
-
-#ifdef __STDC__
-typedef void *pointer;
-#ifndef NULL
-#define NULL (void *)0
-#endif
-#else /* not __STDC__ */
-typedef char *pointer;
-#ifndef NULL
-#define NULL 0
-#endif
-#endif /*  not __STDC__ */
-#define STATIC	/* empty */
-#define MKINIT	/* empty */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-extern char nullstr[1];		/* null string */
-
-
-#if DEBUG
-#define TRACE(param)	trace param
-#else
-#define TRACE(param)
-#endif
Index: trunk/minix/commands/ash/show.c
===================================================================
--- trunk/minix/commands/ash/show.c	(revision 9)
+++ 	(revision )
@@ -1,377 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)show.c	5.2 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-#include <stdio.h>
-#include <errno.h>
-#include "shell.h"
-#include "parser.h"
-#include "nodes.h"
-#include "mystring.h"
-
-
-#if DEBUG
-static shtree(), shcmd(), sharg(), indent();
-
-
-showtree(n)
-	union node *n;
-	{
-	trputs("showtree called\n");
-	shtree(n, 1, NULL, stdout);
-}
-
-
-static
-shtree(n, ind, pfx, fp)
-	union node *n;
-	char *pfx;
-	FILE *fp;
-	{
-	struct nodelist *lp;
-	char *s;
-
-	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
-shcmd(cmd, fp)
-	union node *cmd;
-	FILE *fp;
-	{
-	union node *np;
-	int first;
-	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 NAPPEND:	s = ">>"; dftfd = 1; break;
-			case NTOFD:	s = ">&"; dftfd = 1; break;
-			case NFROM:	s = "<";  dftfd = 0; break;
-			case NFROMFD:	s = "<&"; 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
-sharg(arg, fp)
-	union node *arg;
-	FILE *fp;
-	{
-	char *p;
-	struct nodelist *bqlist;
-	int subtype;
-
-	if (arg->type != NARG) {
-		printf("<node type %d>\n", arg->type);
-		fflush(stdout);
-		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;
-			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;
-			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
-indent(amount, pfx, fp)
-	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;
-
-#if DEBUG == 2
-int debug = 1;
-#else
-int debug = 0;
-#endif
-
-
-trputc(c) {
-#if DEBUG
-	if (tracefile == NULL)
-		return;
-	putc(c, tracefile);
-	if (c == '\n')
-		fflush(tracefile);
-#endif
-}
-
-
-trace(fmt, a1, a2, a3, a4, a5, a6, a7, a8)
-	char *fmt;
-	{
-#if DEBUG
-	int e = errno;
-	if (tracefile == NULL)
-		return;
-	fprintf(tracefile, fmt, a1, a2, a3, a4, a5, a6, a7, a8);
-	if (strchr(fmt, '\n'))
-		fflush(tracefile);
-	errno = e;
-#endif
-}
-
-
-trputs(s)
-	char *s;
-	{
-#if DEBUG
-	if (tracefile == NULL)
-		return;
-	fputs(s, tracefile);
-	if (strchr(s, '\n'))
-		fflush(tracefile);
-#endif
-}
-
-
-trstring(s)
-	char *s;
-	{
-	register char *p;
-	char c;
-
-#if DEBUG
-	if (tracefile == NULL)
-		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
-}
-
-
-trargs(ap)
-	char **ap;
-	{
-#if DEBUG
-	if (tracefile == NULL)
-		return;
-	while (*ap) {
-		trstring(*ap++);
-		if (*ap)
-			putc(' ', tracefile);
-		else
-			putc('\n', tracefile);
-	}
-	fflush(tracefile);
-#endif
-}
-
-
-opentrace() {
-	char s[100];
-	char *p;
-	char *getenv();
-	int flags;
-
-#if DEBUG
-	if (!debug)
-		return;
-	if ((p = getenv("HOME")) == NULL) {
-		if (getuid() == 0)
-			p = "/";
-		else
-			p = "/tmp";
-	}
-	scopy(p, s);
-	strcat(s, "/trace");
-	if ((tracefile = fopen(s, "a")) == NULL) {
-		fprintf(stderr, "Can't open %s\n", s);
-		return;
-	}
-#ifdef O_APPEND
-	if ((flags = fcntl(fileno(tracefile), F_GETFL, 0)) >= 0)
-		fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND);
-#endif
-	fputs("\nTracing started.\n", tracefile);
-	fflush(tracefile);
-#endif
-}
Index: trunk/minix/commands/ash/sys/cdefs.h
===================================================================
--- trunk/minix/commands/ash/sys/cdefs.h	(revision 9)
+++ 	(revision )
@@ -1,15 +1,0 @@
-/*	Replacement for something BSD has in sys/cdefs.h. */
-
-#ifndef _ASH_SYS_CDEFS
-#define _ASH_SYS_CDEFS
-
-#if __STDC__
-#define	__P(params)			params
-#else
-#define	__P(params)			()
-#endif
-
-/*	Probably in sys/types.h. */
-typedef void (*sig_t) __P(( int ));
-
-#endif /* _ASH_SYS_CDEFS */
Index: trunk/minix/commands/ash/test/malloc.c
===================================================================
--- trunk/minix/commands/ash/test/malloc.c	(revision 9)
+++ 	(revision )
@@ -1,1298 +1,0 @@
-
-/**********************************************************/
-/*
-/*		 This was file READ_ME
-/*
-/**********************************************************/
-
-/*
-	PROGRAM
-		malloc(), free(), realloc()
-	AUTHOR
-		Dick Grune, Free University, Amsterdam
-		Modified by Ceriel Jacobs, Free University, Amsterdam,
-		to make it faster
-	VERSION
-		$Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $
-	DESCRIPTION
-	This is an independent rewrite of the malloc/free package; it is
-	fast and efficient.  Free blocks are kept in doubly linked lists,
-	list N holding blocks with sizes between 2**N and 2**(N+1)-1.
-	Consequently neither malloc nor free have to do any searching:
-	the cost of a call of malloc() (or free()) is constant, however
-	many blocks you have got.
-	
-	If you switch on the NON_STANDARD macro (see param.h) every block
-	costs 2 pointers overhead (otherwise it's 4).
-*/
-/*
-	There is an organisational problem here: during devellopment
-	I want the package divided into modules, which implies external
-	names for the communication.  The only external names I want in
-	the finished product are malloc, realloc and free.  This requires
-	some hanky-panky.
-*/
-
-
-/**********************************************************/
-/*
-/*		 This was file size_type.h
-/*
-/**********************************************************/
-
-#if	_EM_WSIZE == _EM_PSIZE
-typedef unsigned int size_type;
-#elif	_EM_LSIZE == _EM_PSIZE
-typedef unsigned long size_type;
-#else
-#error funny pointer size
-#endif
-#include	<stdlib.h>
-#include	<stdio.h>
-
-
-/**********************************************************/
-/*
-/*		 This was file param.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-
-#	undef	NON_STANDARD	/*	If defined, the contents of a block
-					will NOT be left undisturbed after it
-					is freed, as opposed to what it says
-					in the manual (malloc(2)).
-					Setting this option reduces the memory
-					overhead considerably.  I personally
-					consider the specified behaviour an
-					artefact of the original
-					implementation.
-				*/
-
-#	define	ASSERT		/*	If defined, some inexpensive tests
-					will be made to ensure the
-					correctness of some sensitive data.
-					It often turns an uncontrolled crash
-					into a controlled one.
-				*/
-
-#	define	CHECK		/*	If defined, extensive and expensive
-					tests will be done, inculding a
-					checksum on the mallinks (chunk
-					information blocks).  The resulting
-					information will be printed on a file
-					called mal.out .
-					Additionally a function
-						maldump(n) int n;
-					will be defined, which will dump
-					pertinent info in pseudo-readable
-					form; it aborts afterwards if n != 0.
-				*/
-
-#	undef	EXTERN		/*	If defined, all static names will
-					become extern, which is a help in
-					using adb(1) or prof(1)
-				*/
-
-#	define	STORE		/*	If defined, separate free lists will
-					be kept of chunks with small sizes,
-					to speed things up a little.
-				*/
-
-#	undef SYSTEM		/*	If defined, the system module is used.
-					Otherwise, "sbrk" is called directly.
-				*/
-
-#define	ALIGNMENT	8	
-				/* alignment common to all types */
-#define	LOG_MIN_SIZE	3
-#define	LOG_MAX_SIZE	24
-
-
-/**********************************************************/
-/*
-/*		 This was file impl.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/*	This file essentially describes how the mallink info block
-	is implemented.
-*/
-
-#define	MIN_SIZE	(1<<LOG_MIN_SIZE)
-#define	MAX_FLIST	(LOG_MAX_SIZE - LOG_MIN_SIZE)
-#if ALIGNMENT != 4 && ALIGNMENT != 8 && ALIGNMENT != 16
-#error ALIGNMENT must be 4, 8 or 16
-#elif ALIGNMENT % _EM_LSIZE
-/* since calloc() does it's initialization in longs */
-#error ALIGNMENT must be a multiple of the long size
-#endif
-#define align(n)	(((n) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1))
-
-union _inf {
-	union _inf *ptr;
-	size_type ui;
-};
-
-typedef union _inf mallink;
-#define	MAL_NULL	((mallink *)0)
-
-/*	Access macros; only these macros know where to find values.
-	They are also lvalues.
-*/
-#ifndef	NON_STANDARD
-#define	OFF_SET	0
-#else	/* def NON_STANDARD */
-#define	OFF_SET	2
-#endif	/* NON_STANDARD */
-
-#define	_log_prev_of(ml)	((ml)[-1+OFF_SET]).ptr
-#define	_log_next_of(ml)	((ml)[-2+OFF_SET]).ptr
-#define	_phys_prev_of(ml)	((ml)[-3+OFF_SET]).ptr
-#define	_this_size_of(ml)	((ml)[-4+OFF_SET]).ui
-#ifndef	CHECK
-#define	N_WORDS			4
-#else	/* ifdef	CHECK */
-#define	_checksum_of(ml)	((ml)[-5+OFF_SET]).ui
-#define	_print_of(ml)		((ml)[-6+OFF_SET]).ui
-#define	_mark_of(ml)		((ml)[-7+OFF_SET]).ui
-#define	N_WORDS			7
-#endif	/* CHECK */
-
-#define	mallink_size()		(size_t) \
-	align((N_WORDS - OFF_SET) * sizeof (mallink))
-
-#ifdef	CHECK
-#define	set_mark(ml,e)		(_mark_of(ml) = (e))
-#define	mark_of(ml)		(_mark_of(ml))
-
-#define	set_checksum(ml,e)	(_checksum_of(ml) = (e))
-#define	checksum_of(ml)		(_checksum_of(ml))
-#endif	/* CHECK */
-
-#define new_mallink(ml)		( _log_prev_of(ml) = 0, \
-				  _log_next_of(ml) = 0, \
-				  _phys_prev_of(ml) = 0, \
-				  _this_size_of(ml) = 0 )
-
-#define	block_of_mallink(ml)	((void *)ml)
-#define	mallink_of_block(addr)	((mallink *)addr)
-
-#define	public	extern
-#define	publicdata	extern
-#ifndef	EXTERN
-#define	private	static
-#define	privatedata	static
-#else	/* def	EXTERN */
-#define	private	extern
-#define	privatedata
-#endif	/* EXTERN */
-
-#ifdef	ASSERT
-private m_assert(const char *fn, int ln);
-#define	assert(b)		(!(b) ? m_assert(__FILE__, __LINE__) : 0)
-#else	/* ndef	ASSERT */
-#define	assert(b)		0
-#endif	/* ASSERT */
-
-
-/**********************************************************/
-/*
-/*		 This was file check.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#ifdef	CHECK
-
-private check_mallinks(const char *s), calc_checksum(mallink *ml);
-private check_work_empty(const char *s);
-private started_working_on(mallink *ml), stopped_working_on(mallink *ml);
-
-#else	/* ifndef	CHECK */
-
-#define	maldump(n)		abort()
-#define	check_mallinks(s)	0
-#define	calc_checksum(ml)	0
-#define	started_working_on(ml)	0
-#define	stopped_working_on(ml)	0
-#define	check_work_empty(s)	0
-
-#endif	/* CHECK */
-
-
-/**********************************************************/
-/*
-/*		 This was file log.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/*	Algorithms to manipulate the doubly-linked lists of free
-	chunks.
-*/
-
-private link_free_chunk(mallink *ml), unlink_free_chunk(mallink *ml);
-private mallink *first_present(int class);
-private mallink *search_free_list(int class, size_t n);
-
-#ifdef STORE
-#define in_store(ml)		((size_type)_phys_prev_of(ml) & STORE_BIT)
-#define set_store(ml, e) \
-	(_phys_prev_of(ml) = (mallink *) \
-		((e) ? (size_type) _phys_prev_of(ml) | STORE_BIT : \
-		       (size_type) _phys_prev_of(ml) & ~STORE_BIT))
-#endif
-#define	set_log_prev(ml,e)	(_log_prev_of(ml) = (e))
-#define	log_prev_of(ml)		(mallink *) (_log_prev_of(ml))
-
-#define	set_log_next(ml,e)	(_log_next_of(ml) = (e))
-#define	log_next_of(ml)		(mallink *) (_log_next_of(ml))
-
-
-
-/**********************************************************/
-/*
-/*		 This was file phys.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/*	Algorithms to manipulate the doubly-linked list of physical
-	chunks.
-*/
-privatedata mallink *ml_last;
-
-#define FREE_BIT		01
-#ifdef STORE
-#define STORE_BIT		02
-#define BITS			(FREE_BIT|STORE_BIT)
-#else
-#define BITS			(FREE_BIT)
-#endif
-
-#define __bits(ml)		((int)((size_type)_phys_prev_of(ml) & BITS))
-#define	__free_of(ml)		((int)((size_type)_phys_prev_of(ml) & FREE_BIT))
-#define __phys_prev_of(ml)	((mallink *)((size_type)_phys_prev_of(ml) & ~BITS))
-#define prev_size_of(ml)	((char *)(ml) - \
-				 (char *)__phys_prev_of(ml) - \
-				 mallink_size() \
-				)
-#define	set_phys_prev(ml,e) \
-	(_phys_prev_of(ml) = (mallink *) ((char *)e + __bits(ml)))
-
-#ifdef	CHECK
-private Error(const char *fmt, const char *s, mallink *ml);
-#define	phys_prev_of(ml)	(mallink *) \
-	(first_mallink(ml) ? \
-		(char *)Error("phys_prev_of first_mallink %p", "somewhere", ml) : \
-		(char *)__phys_prev_of(ml) \
-	)
-#else	/* ndef	CHECK */
-#define	phys_prev_of(ml)	__phys_prev_of(ml)
-#endif	/* CHECK */
-
-#define	first_mallink(ml)	(int) (__phys_prev_of(ml) == 0)
-#define	last_mallink(ml)	(int) ((ml) == ml_last)
-
-/*	There is an ambiguity in the semantics of phys_next_of: sometimes
-	one wants it to return MAL_NULL if there is no next chunk, at
-	other times one wants the address of the virtual chunk at the
-	end of memory.  The present version returns the address of the
-	(virtual) chunk and relies on the user to test last_mallink(ml)
-	first.
-*/
-#define size_of(ml)		(_this_size_of(ml) - mallink_size())
-#define	set_phys_next(ml,e) \
-	(_this_size_of(ml) = (size_type)((char *)(e) - (char *)(ml)))
-#define	phys_next_of(ml)	(mallink *) ((char *)(ml) + _this_size_of(ml))
-
-#define	set_free(ml,e) \
-	(_phys_prev_of(ml) = (mallink *) \
-		((e) ? (size_type) _phys_prev_of(ml) | FREE_BIT : \
-		       (size_type) _phys_prev_of(ml) & ~FREE_BIT))
-#define	free_of(ml)		(__free_of(ml))
-
-#define coalesce_forw(ml,nxt)	( unlink_free_chunk(nxt), \
-				  combine_chunks((ml), (nxt)))
-
-#define coalesce_backw(ml,prv)	( unlink_free_chunk(prv), \
-				  stopped_working_on(ml), \
-				  combine_chunks((prv), (ml)), \
-				  started_working_on(prv))
-
-#ifdef	CHECK
-#define	set_print(ml,e)		(_print_of(ml) = (e))
-#define	print_of(ml)		(_print_of(ml))
-#endif	/* CHECK */
-
-private truncate(mallink *ml, size_t size);
-private combine_chunks(register mallink *ml1, register mallink *ml2);
-private mallink *create_chunk(void *p, size_t n);
-
-
-/**********************************************************/
-/*
-/*		 This was file mal.c
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include	<limits.h>
-#include	<stdlib.h>
-
-/*	Malloc space is traversed by N doubly-linked lists of chunks, each
-	containing a couple of house-keeping data addressed as a
-	'mallink' and a piece of useful space, called the block.
-	The N lists are accessed through their starting pointers in
-	free_list[].  Free_list[n] points to a list of chunks between
-	2**(n+LOG_MIN_SIZE) and 2**(n+LOG_MIN_SIZE+1)-1, which means
-	that the smallest chunk is 2**LOG_MIN_SIZE (== MIN_SIZE).
-*/
-
-#ifdef SYSTEM
-#include	<system.h>
-#define SBRK	sys_break
-#else
-#define SBRK	_sbrk
-#define	ILL_BREAK		(void *)(-1)	/* funny failure value */
-#endif
-extern void *SBRK(int incr);
-#ifdef STORE
-#define	MAX_STORE	32
-private do_free(mallink *ml), sell_out(void);
-privatedata mallink *store[MAX_STORE];
-#endif /* STORE */
-
-void *privious_free= (void *)-1;
-void *
-malloc(register size_t n)
-{check_mallinks("malloc entry");{
-	register mallink *ml;
-	register int min_class;
-	void *tmp;
-
-{ static int reent= 0; if (!reent) { reent++; printf("malloc\n"); reent--; } }
-privious_free= (void *)-1;
-	if (n == 0) {
-		return NULL;
-	}
-	if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n);
-#ifdef STORE
-	if (n <= MAX_STORE*MIN_SIZE)	{
-		/* look in the store first */
-		register mallink **stp = &store[(n >> LOG_MIN_SIZE) - 1];
-		
-		if (ml = *stp)	{
-			*stp = log_next_of(ml);
-			set_store(ml, 0);
-			check_mallinks("malloc fast exit");
-			assert(! in_store(ml));
-			tmp= block_of_mallink(ml);
-{ static int reent= 0; if (!reent) { reent++; printf("= 0x%x\n", tmp);reent--; } }
-			return tmp;
-		}
-	}
-#endif /* STORE */
-
-	check_work_empty("malloc, entry");
-
-	/*	Acquire a chunk of at least size n if at all possible;
-		Try everything.
-	*/
-	{
-		/*	Inline substitution of "smallest".
-		*/
-		register size_t n1 = n;
-
-		assert(n1 < (1L << LOG_MAX_SIZE));
-		min_class = 0;
-
-		do {
-			n1 >>= 1;
-			min_class++;
-		} while (n1 >= MIN_SIZE);
-	}
-
-	if (min_class >= MAX_FLIST)
-		return NULL;		/* we don't deal in blocks that big */
-	ml = first_present(min_class);
-	if (ml == MAL_NULL)	{
-		/*	Try and extend */
-		register void *p;
-#define	GRABSIZE	4096		/* Power of 2 */
-		register size_t req =
-			((MIN_SIZE<<min_class)+ mallink_size() + GRABSIZE - 1) &
-				~(GRABSIZE-1);
-	
-		if (!ml_last)	{
-			/* first align SBRK() */
-		
-			p = SBRK(0);
-			SBRK((int) (align((size_type) p) - (size_type) p));
-		}
-
-		/* SBRK takes an int; sorry ... */
-		if ((int) req < 0) {
-			p = ILL_BREAK;
-		} else {
-			p = SBRK((int)req);
-		}
-		if (p == ILL_BREAK) {
-			req = n + mallink_size();
-			if ((int) req >= 0) p = SBRK((int)req);
-		}
-		if (p == ILL_BREAK)	{
-			/*	Now this is bad.  The system will not give us
-				more memory.  We can only liquidate our store
-				and hope it helps.
-			*/
-#ifdef STORE
-			sell_out();
-			ml = first_present(min_class);
-			if (ml == MAL_NULL)	{
-#endif /* STORE */
-				/* In this emergency we try to locate a suitable
-				   chunk in the free_list just below the safe
-				   one; some of these chunks may fit the job.
-				*/
-				ml = search_free_list(min_class - 1, n);
-				if (!ml)	/* really out of space */
-					return NULL;
-				started_working_on(ml);
-				unlink_free_chunk(ml);
-				check_mallinks("suitable_chunk, forced");
-#ifdef STORE
-			}
-			else started_working_on(ml);
-#endif /* STORE */
-		}
-		else {
-			assert((size_type)p == align((size_type)p));
-			ml = create_chunk(p, req);
-		}
-		check_mallinks("suitable_chunk, extended");
-	}
-	else started_working_on(ml);
-
-	/* we have a chunk */
-	set_free(ml, 0);
-	calc_checksum(ml);
-	check_mallinks("suitable_chunk, removed");
-	n += mallink_size();
-	if (n + MIN_SIZE <= size_of(ml)) {
-		truncate(ml, n);
-	}
-	stopped_working_on(ml);
-	check_mallinks("malloc exit");
-	check_work_empty("malloc exit");
-#ifdef STORE
-	assert(! in_store(ml));
-#endif
-	tmp= block_of_mallink(ml);
-{ static int reent= 0; if (!reent) { reent++; printf("= 0x%x\n", tmp);reent--; } }
-	return tmp;
-}}
-
-void
-free(void *addr)
-{check_mallinks("free entry");{
-	register mallink *ml;
-
-printf("free 0x%x\n", addr);
-if (privious_free == addr) { fflush(stdout); fflush(stderr); abort(); }
-privious_free= addr;
-	if (addr == NULL) {
-		check_mallinks("free(0) very fast exit");
-		return;
-	}
-
-	ml = mallink_of_block(addr);
-#ifdef STORE
-
-	if (free_of(ml) || in_store(ml))
-		return;				/* user frees free block */
-	if (size_of(ml) <= MAX_STORE*MIN_SIZE)	{
-		/* return to store */
-		mallink **stp = &store[(size_of(ml) >> LOG_MIN_SIZE) - 1];
-		
-		set_log_next(ml, *stp);
-		*stp = ml;
-		set_store(ml, 1);
-		calc_checksum(ml);
-		check_mallinks("free fast exit");
-	}
-	else	{
-		do_free(ml);
-		check_mallinks("free exit");
-	}
-}}
-
-private
-do_free(register mallink *ml)
-{{
-#endif
-
-#ifndef STORE
-	if (free_of(ml))	return;
-#endif /* STORE */
-	started_working_on(ml);
-	set_free(ml, 1);
-	calc_checksum(ml);
-	if (! last_mallink(ml)) {
-		register mallink *next = phys_next_of(ml);
-
-		if (free_of(next)) coalesce_forw(ml, next);
-	}
-
-	if (! first_mallink(ml)) {
-		register mallink *prev = phys_prev_of(ml);
-
-		if (free_of(prev)) {
-			coalesce_backw(ml, prev);
-			ml = prev;
-		}
-	}
-	link_free_chunk(ml);
-	stopped_working_on(ml);
-	check_work_empty("free");
-
-	/* Compile-time checks on param.h */
-	switch (0)	{
-	case MIN_SIZE < OFF_SET * sizeof(mallink):	break;
-	case 1:	break;
-	/*	If this statement does not compile due to duplicate case
-		entry, the minimum size block cannot hold the links for
-		the free blocks.  Either raise LOG_MIN_SIZE or switch
-		off NON_STANDARD.
-	*/
-	}
-	switch(0)	{
-	case sizeof(void *) != sizeof(size_type):	break;
-	case 1:	break;
-	/*	If this statement does not compile due to duplicate
-		case entry, size_type is not defined correctly.
-		Redefine and compile again.
-	*/
-	}
-}}
-
-void *
-realloc(void *addr, register size_t n)
-{check_mallinks("realloc entry");{
-	register mallink *ml, *ph_next;
-	register size_type size;
-
-printf("realloc 0x%x, %d\n", addr, n);
-	if (addr == NULL) {
-		/*	Behave like most Unix realloc's when handed a
-			null-pointer
-		*/
-		return malloc(n);
-	}
-	if (n == 0) {
-		free(addr);
-		return NULL;
-	}
-	ml = mallink_of_block(addr);
-	if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n);
-#ifdef STORE
-	if (in_store(ml)) {
-		register mallink *stp = store[(size_of(ml) >> LOG_MIN_SIZE) - 1];
-		mallink *stp1 = NULL;
-		while (ml != stp)	{
-			stp1 = stp;
-			stp = log_next_of(stp);
-		}
-		stp = log_next_of(stp);
-		if (! stp1) store[(size_of(ml) >> LOG_MIN_SIZE) - 1] = stp;
-		else set_log_next(stp1, stp);
-		set_store(ml, 0);
-		calc_checksum(ml);
-	}
-#endif
-	if (free_of(ml)) {
-		unlink_free_chunk(ml);
-		set_free(ml, 0);		/* user reallocs free block */
-	}
-	started_working_on(ml);
-	size = size_of(ml);
-	if (	/* we can simplify the problem by adding the next chunk: */
-		n > size &&
-		!last_mallink(ml) &&
-		(ph_next = phys_next_of(ml), free_of(ph_next)) &&
-		n <= size + mallink_size() + size_of(ph_next)
-	)	{
-		/* add in the physically next chunk */
-		unlink_free_chunk(ph_next);
-		combine_chunks(ml, ph_next);
-		size = size_of(ml);
-		check_mallinks("realloc, combining");
-	}
-	if (n > size)	{		/* this didn't help */
-		void *new;
-		register char *l1, *l2 = addr;
-
-		stopped_working_on(ml);
-		if (!(new = l1 = malloc(n))) return NULL;	/* no way */
-		while (size--) *l1++ = *l2++;
-		free(addr);
-		check_work_empty("mv_realloc");
-#ifdef STORE
-		assert(! in_store(mallink_of_block(new)));
-#endif
-		return new;
-	}
-	/* it helped, but maybe too well */
-	n += mallink_size();
-	if (n + MIN_SIZE <= size_of(ml)) {
-		truncate(ml, n);
-	}
-	stopped_working_on(ml);
-	check_mallinks("realloc exit");
-	check_work_empty("realloc");
-#ifdef STORE
-	assert(! in_store(ml));
-#endif
-	return addr;
-}}
-
-void *
-calloc(size_t nmemb, size_t size)
-{check_mallinks("calloc entry");{
-	long *l1, *l2;
-	size_t n;
-
-printf("calloc\n");
-	if (size == 0) return NULL;
-	if (nmemb == 0) return NULL;
-
-	/* Check for overflow on the multiplication. The peephole-optimizer
-	 * will eliminate all but one of the possibilities.
-	 */
-	if (sizeof(size_t) == sizeof(int)) {
-		if (UINT_MAX / size < nmemb) return NULL;
-	} else if (sizeof(size_t) == sizeof(long)) {
-		if (ULONG_MAX / size < nmemb) return NULL;
-	} else return NULL;		/* can't happen, can it ? */
-
-	n = size * nmemb;
-	if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n);
-	if (n >= (1L << LOG_MAX_SIZE)) return NULL;
-	l1 = (long *) malloc(n);
-	l2 = l1 + (n / sizeof(long));	/* n is at least long aligned */
-	while ( l2 != l1 ) *--l2 = 0;
-	check_mallinks("calloc exit");
-	check_work_empty("calloc exit");
-	return (void *)l1;
-}}
-/*	Auxiliary routines */
-
-#ifdef STORE
-private
-sell_out(void)	{
-	/*	Frees all block in store.
-	*/
-	register mallink **stp;
-	
-	for (stp = &store[0]; stp < &store[MAX_STORE]; stp++)	{
-		register mallink *ml = *stp;
-		
-		while (ml)	{
-			*stp = log_next_of(ml);
-			set_store(ml, 0);
-			do_free(ml);
-			ml = *stp;
-		}
-	}
-
-}
-#endif /* STORE */
-
-#ifdef	ASSERT
-private
-m_assert(const char *fn, int ln)
-{
-	char ch;
-	
-	while (*fn)
-		write(2, fn++, 1);
-	write(2, ": malloc assert failed in line ", 31);
-	ch = (ln / 100) + '0'; write(2, &ch, 1); ln %= 100;
-	ch = (ln / 10) + '0'; write(2, &ch, 1); ln %= 10;
-	ch = (ln / 1) + '0'; write(2, &ch, 1);
-	write(2, "\n", 1);
-	maldump(1);
-}
-#endif	/* ASSERT */
-
-
-/**********************************************************/
-/*
-/*		 This was file log.c
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-
-/*	Logical manipulations.
-	The chunks are properly chained in the physical chain.
-*/
-
-privatedata mallink *free_list[MAX_FLIST];
-
-private
-link_free_chunk(register mallink *ml)
-{
-	/*	The free chunk ml is inserted in its proper logical
-		chain.
-	*/
-	register mallink **mlp = &free_list[-1];
-	register size_type n = size_of(ml);
-	register mallink *ml1;
-
-	assert(n < (1L << LOG_MAX_SIZE));
-
-	do {
-		n >>= 1;
-		mlp++;
-	}
-	while (n >= MIN_SIZE);
-
-	ml1 = *mlp;
-	set_log_prev(ml, MAL_NULL);
-	set_log_next(ml, ml1);
-	calc_checksum(ml);
-	if (ml1) {
-		/* link backwards
-		*/
-		set_log_prev(ml1, ml);
-		calc_checksum(ml1);
-	}
-	*mlp = ml;
-}
-
-private
-unlink_free_chunk(register mallink *ml)
-{
-	/*	Unlinks a free chunk from (the middle of) the
-		logical chain.
-	*/
-	register mallink *next = log_next_of(ml);
-	register mallink *prev = log_prev_of(ml);
-
-	if (!prev)	{
-		/* it is the first in the chain */
-		register mallink **mlp = &free_list[-1];
-		register size_type n = size_of(ml);
-
-		assert(n < (1L << LOG_MAX_SIZE));
-		do {
-			n >>= 1;
-			mlp++;
-		}
-		while (n >= MIN_SIZE);
-		*mlp = next;
-	}
-	else	{
-		set_log_next(prev, next);
-		calc_checksum(prev);
-	}
-	if (next) {
-		set_log_prev(next, prev);
-		calc_checksum(next);
-	}
-}
-
-private mallink *
-search_free_list(int class, size_t n)
-{
-	/*	Searches the free_list[class] for a chunk of at least size n;
-		since it is searching a slightly undersized list,
-		such a block may not be there.
-	*/
-	register mallink *ml;
-	
-	for (ml = free_list[class]; ml; ml = log_next_of(ml))
-		if (size_of(ml) >= n)
-			return ml;
-	return MAL_NULL;		/* nothing found */
-}
-
-private mallink *
-first_present(int class)
-{
-	/*	Find the index i in free_list[] such that:
-			i >= class && free_list[i] != MAL_NULL.
-		Return MAL_NULL if no such i exists;
-		Otherwise, return the first block of this list, after
-		unlinking it.
-	*/
-	register mallink **mlp, *ml;
-
-	for (mlp = &free_list[class]; mlp < &free_list[MAX_FLIST]; mlp++) {
-		if ((ml = *mlp) != MAL_NULL)	{
-	
-			*mlp = log_next_of(ml);	/* may be MAL_NULL */
-			if (*mlp) {
-				/* unhook backward link
-				*/
-				set_log_prev(*mlp, MAL_NULL);
-				calc_checksum(*mlp);
-			}
-			return ml;
-		}
-	}
-	return MAL_NULL;
-}
-
-#ifdef	CHECK
-private mallink *
-free_list_entry(int i)	{
-	/*	To allow maldump.c access to log.c's private data.
-	*/
-	return free_list[i];
-}
-#endif	/* CHECK */
-
-
-/**********************************************************/
-/*
-/*		 This was file phys.c
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include	<stdlib.h>
-
-/*	Physical manipulations.
-	The blocks concerned are not in any logical chain.
-*/
-
-private mallink *
-create_chunk(void *p, size_t n)
-{
-	/*	The newly acquired piece of memory at p, of length n,
-		is turned into a free chunk, properly chained in the
-		physical chain.
-		The address of the chunk is returned.
-	*/
-	register mallink *ml;
-	/*	All of malloc memory is followed by a virtual chunk, the
-		mallink of which starts mallink_size() bytes past the last
-		byte in memory.
-		Its use is prevented by testing for ml == ml_last first.
-	*/
-	register mallink *last = ml_last;
-	
-	assert(!last || p == (char *)phys_next_of(last) - mallink_size());
-	ml = (mallink *)((char *)p + mallink_size());	/* bump ml */
-	new_mallink(ml);
-	started_working_on(ml);
-	set_free(ml, 1);
-	set_phys_prev(ml, last);
-	ml_last = ml;
-
-	set_phys_next(ml, (mallink *)((char *)ml + n));
-	calc_checksum(ml);
-	assert(size_of(ml) + mallink_size() == n);
-	if (last && free_of(last)) {
-		coalesce_backw(ml, last);
-		ml = last;
-	}
-	check_mallinks("create_chunk, phys. linked");
-	return ml;
-}
-
-private
-truncate(register mallink *ml, size_t size)
-{
-	/*	The chunk ml is truncated.
-		The chunk at ml is split in two.
-		The remaining part is then freed.
-	*/
-	register mallink *new = (mallink *)((char *)ml + size);
-	register mallink *ph_next = phys_next_of(ml);
-
-	new_mallink(new);
-	set_free(new, 1);
-	set_phys_prev(new, ml);
-	set_phys_next(new, ph_next);
-	calc_checksum(new);
-	if (! last_mallink(ml))	{
-		set_phys_prev(ph_next, new);
-		calc_checksum(ph_next);
-		if (free_of(ph_next)) coalesce_forw(new, ph_next);
-	}
-	else	ml_last = new;
-	set_phys_next(ml, new);
-	calc_checksum(ml);
-
-	started_working_on(new);
-	link_free_chunk(new);
-	stopped_working_on(new);
-	check_mallinks("truncate");
-}
-
-private
-combine_chunks(register mallink *ml1, register mallink *ml2)
-{
-	/*	The chunks ml1 and ml2 are combined.
-	*/
-	register mallink *ml3 = phys_next_of(ml2);
-
-	set_phys_next(ml1, ml3);
-	calc_checksum(ml1);
-	if (!last_mallink(ml2))	{
-		set_phys_prev(ml3, ml1);
-		calc_checksum(ml3);
-	}
-	if (ml_last == ml2)
-		ml_last = ml1;
-}
-
-
-/**********************************************************/
-/*
-/*		 This was file check.c
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include	<stdio.h>
-
-#ifdef	CHECK			/* otherwise this whole file is skipped */
-
-/* ??? check these later */
-private acquire_malout(void), check_ml_last(const char *s);
-private dump_all_mallinks(void), dump_free_list(int i);
-private dump_mallink(const char *s, mallink *ml), print_loop(mallink *ml);
-private working_on(mallink *ml);
-private size_type checksum(mallink *ml);
-static FILE *malout;
-
-private mallink *free_list_entry(int i);
-
-#define	for_free_list(i,p) \
-	for (p = free_list_entry(i); p; p = log_next_of(p))
-
-#define	for_all_mallinks(ml)	/* backwards! */ \
-	for (ml = ml_last; ml; \
-		ml = first_mallink(ml) ? MAL_NULL : phys_prev_of(ml))
-
-/* Maldump */
-
-static int pr_cnt = 0;
-
-maldump(int n)	{
-	/*	Dump pertinent info in pseudo-readable format;
-		abort afterwards if n != 0.
-	*/
-	static int dumping = 0;
-	int i;
-	
-	if (dumping)
-		return;
-	dumping++;
-	acquire_malout();
-	fprintf(malout,
-		">>>>>>>>>>>>>>>> DUMP OF ALL MALLINKS <<<<<<<<<<<<<<<<");
-	fprintf(malout, "    ml_last = %p\n", ml_last);
-	if (++pr_cnt == 100) pr_cnt = 0;
-	dump_all_mallinks();
-	fprintf(malout,
-		">>>>>>>>>>>>>>>> DUMP OF FREE_LISTS <<<<<<<<<<<<<<<<\n");
-	if (++pr_cnt == 100) pr_cnt = 0;
-	for (i = 0; i < MAX_FLIST; i++)
-		dump_free_list(i);
-	fprintf(malout,
-		">>>>>>>>>>>>>>>> END OF DUMP <<<<<<<<<<<<<<<<\n");
-	fclose(malout);
-	dumping--;
-	if (n)
-		abort();
-}
-
-private
-acquire_malout(void)	{
-	static char buf[BUFSIZ];
-	
-	if (!malout)	{
-		malout = freopen("mal.out", "w", stderr);	
-		setbuf(malout, buf);
-	}
-}
-
-private
-dump_all_mallinks(void)	{
-	mallink *ml;
-	
-	for_all_mallinks (ml)	{
-		if (print_loop(ml))
-			return;
-		dump_mallink((char *)0, ml);
-	}
-}
-
-private
-dump_free_list(int i)	{
-	mallink *ml = free_list_entry(i);
-	
-	if (!ml)
-		return;
-	fprintf(malout, "%2d: ", i);
-	for_free_list(i, ml)	{
-		if (print_loop(ml))
-			return;
-		fprintf(malout, "%p ", ml);
-	}
-	fprintf(malout, "<\n");
-}
-
-private int
-print_loop(mallink *ml)	{
-	if (print_of(ml) == pr_cnt)	{
-		fprintf(malout, "... PRINT LOOP\n");
-		return 1;
-	}
-	set_print(ml, pr_cnt);
-	return 0;
-}
-
-private
-dump_mallink(const char *s, mallink *ml)	{
-	acquire_malout();
-	if (s)
-		fprintf(malout, "%s: ", s);
-	fprintf(malout, "@: %p;", ml);
-	if (ml && checksum_of(ml) != checksum(ml))
-		fprintf(malout, ">>>> CORRUPTED <<<<");
-	if (!ml)	{
-		fprintf(malout, "\n");
-		return;
-	}	
-	if (free_of(ml))	{
-		fprintf(malout, " l_p: %p;", _log_prev_of(ml));
-		fprintf(malout, " l_n: %p;", _log_next_of(ml));
-	}
-	fprintf(malout, " p_s: %p;", prev_size_of(ml));
-	fprintf(malout, " t_s: %p;", _this_size_of(ml));
-	fprintf(malout, " sz: %lu;", (unsigned long) size_of(ml));
-	fprintf(malout, " fr: %d;", free_of(ml));
-	fprintf(malout, "\n");
-}
-
-/*	Check_mallinks() checks the total data structure as accessible
-	through free_list[] and ml_last.  All check_sums should be OK,
-	except those held in the small array off_colour.  This is a
-	trick to allow to continue checking even when a few mallinks
-	are temporarily out of order.
-	Check_mallinks() tests for a lot of internal consistency.
-*/
-
-/* Some arbitrary constants */
-#define	IN_ML_LAST	93
-#define	IN_FREE_LIST	57		/* and in ml_last */
-#define	CLEAR		21
-
-#define	VRIJ		1
-#define	BEZET		2
-
-private
-check_mallinks(const char *s)	{
-	mallink *ml;
-	size_type size;
-	int i;
-	char stat;
-	
-	check_ml_last(s);
-	stat = BEZET;
-	for_all_mallinks(ml)	{
-		if (checksum_of(ml) != checksum(ml))
-			Error("mallink info at %p corrupted", s, ml);
-		if (working_on(ml))	{
-			stat = BEZET;
-			continue;
-		}
-		if (	!last_mallink(ml) &&
-			phys_prev_of(phys_next_of(ml)) != ml
-		)
-			Error("upward chain bad at %p", s, ml);
-		if (	!first_mallink(ml) &&
-			phys_next_of(phys_prev_of(ml)) != ml
-		)
-			Error("downward chain bad at %p", s, ml);
-		if (free_of(ml))	{
-			if (stat == VRIJ)
-				Error("free mallink at %p follows free mallink",
-								s, ml);
-			stat = VRIJ;
-		}
-		else
-			stat = BEZET;
-		set_mark(ml, IN_ML_LAST);
-	}
-	
-	for (i = 0, size = MIN_SIZE; i < MAX_FLIST; i++, size *= 2)	{
-		for_free_list(i, ml)	{
-			if (working_on(ml))
-				continue;
-			if (!free_of(ml))
-				Error("occupied mallink %p occurs in free_list", s, ml);
-			switch (mark_of(ml))	{
-			case IN_ML_LAST:
-				set_mark(ml, IN_FREE_LIST);
-				break;
-			case IN_FREE_LIST:
-				Error("mallink %p occurs in 2 free_lists",
-								s, ml);
-			default:
-				Error("unknown mallink %p in free_list",
-								s, ml);
-			}
-			if (size_of(ml) < size)
-				Error("size of mallink %p too small", s, ml);
-			if (size_of(ml) >= 2*size)
-				Error("size of mallink %p too large", s, ml);
-		}
-	}
-	for_all_mallinks (ml)	{
-		if (working_on(ml))
-			continue;
-		if (free_of(ml) && mark_of(ml) != IN_FREE_LIST)
-			Error("free mallink %p is in no free_list", s, ml);
-		set_mark(ml, CLEAR);
-	}
-}
-
-private
-check_ml_last(const char *s)	{
-	if (ml_last && _this_size_of(ml_last) == 0)
-		Error("size of ml_last == 0, at %p", s, ml_last);
-}
-
-private size_type
-checksum(mallink *ml)	{
-	size_type sum = 0;
-	
-	if (free_of(ml))	{
-		sum += (size_type)_log_prev_of(ml);
-		sum += (size_type)_log_next_of(ml);
-	}
-	sum += (size_type)prev_size_of(ml);
-	sum += (size_type)_this_size_of(ml);
-	return sum;
-}
-
-private
-calc_checksum(mallink *ml)	{
-	set_checksum(ml, checksum(ml));
-}
-
-#define	N_COLOUR	10
-static mallink *off_colour[N_COLOUR];
-
-private
-started_working_on(mallink *ml)	{
-	int i;
-	
-	for (i = 0; i < N_COLOUR; i++)
-		if (off_colour[i] == MAL_NULL)	{
-			off_colour[i] = ml;
-			return;
-		}
-	Error("out of off_colour array at %p", "started_working_on", ml);
-}
-
-private
-stopped_working_on(mallink *ml)	{
-	int i;
-	
-	for (i = 0; i < N_COLOUR; i++)
-		if (off_colour[i] == ml)	{
-			off_colour[i] = MAL_NULL;
-			return;
-		}
-	Error("stopped working on mallink %p", "stopped_working_on", ml);
-}
-
-private int
-working_on(mallink *ml)	{
-	int i;
-	
-	for (i = 0; i < N_COLOUR; i++)
-		if (off_colour[i] == ml)
-			return 1;
-	return 0;
-}
-
-private
-check_work_empty(const char *s)	{
-	int i;
-	int cnt = 0;
-	
-	for (i = 0; i < N_COLOUR; i++)
-		if (off_colour[i] != MAL_NULL)
-			cnt++;
-	if (cnt != 0)
-		Error("off_colour not empty", s, MAL_NULL);
-}
-
-private int
-Error(const char *fmt, const char *s, mallink *ml)	{
-	static int already_called = 0;
-
-	if (already_called++) return 0;
-	setbuf(stdout, (char *) 0);
-	printf("%s: ", s);
-	printf(fmt, (long)ml);
-	printf("\n");
-	acquire_malout();
-	fprintf(malout, "%s: ", s);
-	fprintf(malout, fmt, (long)ml);
-	fprintf(malout, "\n");
-	fflush(stdout);
-	maldump(1);
-	return 0;			/* to satisfy lint */
-}
-
-#endif	/* CHECK */
-
Index: trunk/minix/commands/ash/trap.c
===================================================================
--- trunk/minix/commands/ash/trap.c	(revision 9)
+++ 	(revision )
@@ -1,328 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)trap.c	5.2 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-#include "shell.h"
-#include "main.h"
-#include "nodes.h"	/* for other headers */
-#include "eval.h"
-#include "jobs.h"
-#include "options.h"
-#include "syntax.h"
-#include "signames.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "trap.h"
-#include "mystring.h"
-#include <sys/types.h>
-#include <signal.h>
-
-
-/*
- * 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 */
-
-
-extern char nullstr[1];		/* null string */
-
-char *trap[MAXSIG+1];		/* trap handler commands */
-MKINIT char sigmode[MAXSIG];	/* current value of signal */
-char gotsig[MAXSIG];		/* indicates specified signal received */
-int pendingsigs;			/* indicates some signal received */
-
-/*
- * The trap builtin.
- */
-
-trapcmd(argc, argv)  char **argv; {
-	char *action;
-	char **ap;
-	int signo;
-
-	if (argc <= 1) {
-		for (signo = 0 ; signo <= MAXSIG ; signo++) {
-			if (trap[signo] != NULL)
-				out1fmt("%d: %s\n", signo, trap[signo]);
-		}
-		return 0;
-	}
-	ap = argv + 1;
-	if (is_number(*ap))
-		action = NULL;
-	else
-		action = *ap++;
-	while (*ap) {
-		if ((signo = number(*ap)) < 0 || signo > MAXSIG)
-			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);
-		INTON;
-		ap++;
-	}
-	return 0;
-}
-
-
-
-/*
- * Clear traps on a fork.
- */
-
-void
-clear_traps() {
-	char **tp;
-
-	for (tp = trap ; tp <= &trap[MAXSIG] ; tp++) {
-		if (*tp && **tp) {	/* trap not NULL or SIG_IGN */
-			INTOFF;
-			ckfree(*tp);
-			*tp = NULL;
-			if (tp != &trap[0])
-				setsignal(tp - trap);
-			INTON;
-		}
-	}
-}
-
-
-
-/*
- * Set the signal handler for the specified signal.  The routine figures
- * out what it should be set to.
- */
-
-int
-setsignal(signo) {
-	int action;
-	sig_t sigact;
-	char *t;
-	extern void onsig();
-
-	if ((t = trap[signo]) == NULL)
-		action = S_DFL;
-	else if (*t != '\0')
-		action = S_CATCH;
-	else
-		action = S_IGN;
-	if (rootshell && action == S_DFL) {
-		switch (signo) {
-		case SIGINT:
-			if (iflag)
-				action = S_CATCH;
-			break;
-		case SIGQUIT:
-#if DEBUG
-			{
-			extern int debug;
-
-			if (debug)
-				break;
-			}
-#endif
-			/* FALLTHROUGH */
-		case SIGTERM:
-			if (iflag)
-				action = S_IGN;
-			break;
-#if JOBS
-		case SIGTSTP:
-		case SIGTTOU:
-			if (jflag)
-				action = S_IGN;
-			break;
-#endif
-		}
-	}
-	t = &sigmode[signo - 1];
-	if (*t == 0) {	/* current setting unknown */
-		/*
-		 * There is a race condition here if action is not S_IGN.
-		 * A signal can be ignored that shouldn't be.
-		 */
-		if ((int)(sigact = signal(signo, SIG_IGN)) == -1)
-			error("Signal system call failed");
-		if (sigact == SIG_IGN) {
-			*t = S_HARD_IGN;
-		} else {
-			*t = S_IGN;
-		}
-	}
-	if (*t == S_HARD_IGN || *t == 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;
-	}
-	*t = action;
-	return (int)signal(signo, sigact);
-}
-
-
-/*
- * Ignore a signal.
- */
-
-void
-ignoresig(signo) {
-	if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) {
-		signal(signo, SIG_IGN);
-	}
-	sigmode[signo - 1] = S_HARD_IGN;
-}
-
-
-#ifdef mkinit
-INCLUDE "signames.h"
-INCLUDE "trap.h"
-
-SHELLPROC {
-	char *sm;
-
-	clear_traps();
-	for (sm = sigmode ; sm < sigmode + MAXSIG ; sm++) {
-		if (*sm == S_IGN)
-			*sm = S_HARD_IGN;
-	}
-}
-#endif
-
-
-
-/*
- * Signal handler.
- */
-
-void
-onsig(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() {
-	int i;
-	int savestatus;
-
-	for (;;) {
-		for (i = 1 ; ; i++) {
-			if (gotsig[i - 1])
-				break;
-			if (i >= MAXSIG)
-				goto done;
-		}
-		gotsig[i - 1] = 0;
-		savestatus=exitstatus;
-		evalstring(trap[i]);
-		exitstatus=savestatus;
-	}
-done:
-	pendingsigs = 0;
-}
-
-
-
-/*
- * Controls whether the shell is interactive or not.
- */
-
-int is_interactive;
-
-void
-setinteractive(on) {
-	if (on == is_interactive)
-		return;
-	setsignal(SIGINT);
-	setsignal(SIGQUIT);
-	setsignal(SIGTERM);
-	is_interactive = on;
-}
-
-
-
-/*
- * Called to exit the shell.
- */
-
-void
-exitshell(status) {
-	struct jmploc loc1, loc2;
-	char *p;
-
-	TRACE(("exitshell(%d) pid=%d\n", status, getpid()));
-	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);
-	}
-l1:   handler = &loc2;			/* probably unnecessary */
-	flushall();
-#if JOBS
-	setjobctl(0);
-#endif
-l2:   _exit(status);
-}
Index: trunk/minix/commands/ash/trap.h
===================================================================
--- trunk/minix/commands/ash/trap.h	(revision 9)
+++ 	(revision )
@@ -1,55 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)trap.h	5.1 (Berkeley) 3/7/91
- */
-
-extern int pendingsigs;
-
-#ifdef __STDC__
-void clear_traps(void);
-int setsignal(int);
-void ignoresig(int);
-void dotrap(void);
-void setinteractive(int);
-void exitshell(int);
-#else
-void clear_traps();
-int setsignal();
-void ignoresig();
-void dotrap();
-void setinteractive();
-void exitshell();
-#endif
Index: trunk/minix/commands/ash/var.c
===================================================================
--- trunk/minix/commands/ash/var.c	(revision 9)
+++ 	(revision )
@@ -1,651 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)var.c	5.3 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-/*
- * 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"
-
-
-#define VTABSIZE 39
-
-
-struct varinit {
-	struct var *var;
-	int flags;
-	char *text;
-};
-
-
-#if ATTY
-struct var vatty;
-#endif
-struct var vifs;
-struct var vmail;
-struct var vmpath;
-struct var vpath;
-struct var vps1;
-struct var vps2;
-struct var vpse;
-struct var vvers;
-#if ATTY
-struct var vterm;
-#endif
-
-const struct varinit varinit[] = {
-#if ATTY
-	{&vatty,	VSTRFIXED|VTEXTFIXED|VUNSET,	"ATTY="},
-#endif
-	{&vifs,	VSTRFIXED|VTEXTFIXED,		"IFS= \t\n"},
-	{&vmail,	VSTRFIXED|VTEXTFIXED|VUNSET,	"MAIL="},
-	{&vmpath,	VSTRFIXED|VTEXTFIXED|VUNSET,	"MAILPATH="},
-	{&vpath,	VSTRFIXED|VTEXTFIXED,		"PATH=:/bin:/usr/bin"},
-	/* 
-	 * vps1 depends on uid
-	 */
-	{&vps2,	VSTRFIXED|VTEXTFIXED,		"PS2=> "},
-	{&vpse,	VSTRFIXED|VTEXTFIXED,		"PSE=* "},
-#if ATTY
-	{&vterm,	VSTRFIXED|VTEXTFIXED|VUNSET,	"TERM="},
-#endif
-	{NULL,	0,				NULL}
-};
-
-struct var *vartab[VTABSIZE];
-
-STATIC void unsetvar __P((char *));
-STATIC struct var **hashvar __P((char *));
-STATIC int varequal __P((char *, char *));
-
-/*
- * Initialize the varable symbol tables and import the environment
- */
-
-#ifdef mkinit
-INCLUDE "var.h"
-INIT {
-	char **envp;
-	extern char **environ;
-
-	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() {
-	const struct varinit *ip;
-	struct var *vp;
-	struct var **vpp;
-
-	for (ip = varinit ; (vp = ip->var) != NULL ; ip++) {
-		if ((vp->flags & VEXPORT) == 0) {
-			vpp = hashvar(ip->text);
-			vp->next = *vpp;
-			*vpp = vp;
-			vp->text = ip->text;
-			vp->flags = ip->flags;
-		}
-	}
-	/*
-	 * PS1 depends on uid
-	 */
-	if ((vps1.flags & VEXPORT) == 0) {
-		vpp = hashvar("PS1=");
-		vps1.next = *vpp;
-		*vpp = &vps1;
-		vps1.text = getuid() ? "PS1=$ " : "PS1=# ";
-		vps1.flags = VSTRFIXED|VTEXTFIXED;
-	}
-}
-
-/*
- * 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(name, val, flags)
-	char *name, *val;
-	{
-	char *p, *q;
-	int len;
-	int namelen;
-	char *nameeq;
-	int isbad;
-
-	isbad = 0;
-	p = name;
-	if (! is_name(*p++))
-		isbad = 1;
-	for (;;) {
-		if (! is_in_name(*p)) {
-			if (*p == '\0' || *p == '=')
-				break;
-			isbad = 1;
-		}
-		p++;
-	}
-	namelen = p - name;
-	if (isbad)
-		error("%.*s: is read only", namelen, name);
-	len = namelen + 2;		/* 2 is space for '=' and '\0' */
-	if (val == NULL) {
-		flags |= VUNSET;
-	} else {
-		len += strlen(val);
-	}
-	p = nameeq = ckmalloc(len);
-	q = name;
-	while (--namelen >= 0)
-		*p++ = *q++;
-	*p++ = '=';
-	*p = '\0';
-	if (val)
-		scopy(val, p);
-	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(s, flags)
-	char *s;
-	{
-	struct var *vp, **vpp;
-
-	vpp = hashvar(s);
-	for (vp = *vpp ; vp ; vp = vp->next) {
-		if (varequal(s, vp->text)) {
-			if (vp->flags & VREADONLY) {
-				int len = strchr(s, '=') - s;
-				error("%.*s: is read only", len, s);
-			}
-			INTOFF;
-			if (vp == &vpath)
-				changepath(s + 5);	/* 5 = strlen("PATH=") */
-			if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
-				ckfree(vp->text);
-			vp->flags &=~ (VTEXTFIXED|VSTACK|VUNSET);
-			vp->flags |= flags;
-			vp->text = s;
-			if (vp == &vmpath || (vp == &vmail && ! mpathset()))
-				chkmail(1);
-			INTON;
-			return;
-		}
-	}
-	/* not found */
-	vp = ckmalloc(sizeof (*vp));
-	vp->flags = flags;
-	vp->text = s;
-	vp->next = *vpp;
-	*vpp = vp;
-}
-
-
-
-/*
- * Process a linked list of variable assignments.
- */
-
-void
-listsetvar(list)
-	struct strlist *list;
-	{
-	struct strlist *lp;
-
-	INTOFF;
-	for (lp = list ; lp ; lp = lp->next) {
-		setvareq(savestr(lp->text), 0);
-	}
-	INTON;
-}
-
-
-
-/*
- * Find the value of a variable.  Returns NULL if not set.
- */
-
-char *
-lookupvar(name)
-	char *name;
-	{
-	struct var *v;
-
-	for (v = *hashvar(name) ; v ; v = v->next) {
-		if (varequal(v->text, name)) {
-			if (v->flags & VUNSET)
-				return NULL;
-			return strchr(v->text, '=') + 1;
-		}
-	}
-	return NULL;
-}
-
-
-
-/*
- * 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(name, doall)
-	char *name;
-	{
-	struct strlist *sp;
-	struct var *v;
-
-	for (sp = cmdenviron ; sp ; sp = sp->next) {
-		if (varequal(sp->text, name))
-			return strchr(sp->text, '=') + 1;
-	}
-	for (v = *hashvar(name) ; v ; v = v->next) {
-		if (varequal(v->text, name)) {
-			if (v->flags & VUNSET
-			 || ! doall && (v->flags & VEXPORT) == 0)
-				return NULL;
-			return strchr(v->text, '=') + 1;
-		}
-	}
-	return NULL;
-}
-
-
-
-/*
- * Generate a list of exported variables.  This routine is used to construct
- * the third argument to execve when executing a program.
- */
-
-char **
-environment() {
-	int nenv;
-	struct var **vpp;
-	struct var *vp;
-	char **env, **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;
-	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
-MKINIT void shprocvar();
-
-SHELLPROC {
-	shprocvar();
-}
-#endif
-
-void
-shprocvar() {
-	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.
- */
-
-int
-showvarscmd(argc, argv)  char **argv; {
-	struct var **vpp;
-	struct var *vp;
-
-	for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-		for (vp = *vpp ; vp ; vp = vp->next) {
-			if ((vp->flags & VUNSET) == 0)
-				out1fmt("%s\n", vp->text);
-		}
-	}
-	return 0;
-}
-
-
-
-/*
- * The export and readonly commands.
- */
-
-int
-exportcmd(argc, argv)  char **argv; {
-	struct var **vpp;
-	struct var *vp;
-	char *name;
-	char *p;
-	int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
-
-	listsetvar(cmdenviron);
-	if (argc > 1) {
-		while ((name = *argptr++) != NULL) {
-			if ((p = strchr(name, '=')) != NULL) {
-				p++;
-			} else {
-				vpp = hashvar(name);
-				for (vp = *vpp ; vp ; vp = vp->next) {
-					if (varequal(vp->text, name)) {
-						vp->flags |= flag;
-						goto found;
-					}
-				}
-			}
-			setvar(name, p, flag);
-found:;
-		}
-	} else {
-		for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-			for (vp = *vpp ; vp ; vp = vp->next) {
-				if (vp->flags & flag) {
-					for (p = vp->text ; *p != '=' ; p++)
-						out1c(*p);
-					out1c('\n');
-				}
-			}
-		}
-	}
-	return 0;
-}
-
-
-/*
- * The "local" command.
- */
-
-localcmd(argc, argv)  char **argv; {
-	char *name;
-
-	if (! in_function())
-		error("Not in a function");
-	while ((name = *argptr++) != NULL) {
-		mklocal(name);
-	}
-	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(name)
-	char *name;
-	{
-	struct localvar *lvp;
-	struct var **vpp;
-	struct var *vp;
-
-	INTOFF;
-	lvp = ckmalloc(sizeof (struct localvar));
-	if (name[0] == '-' && name[1] == '\0') {
-		lvp->text = ckmalloc(sizeof optval);
-		bcopy(optval, lvp->text, sizeof optval);
-		vp = NULL;
-	} else {
-		vpp = hashvar(name);
-		for (vp = *vpp ; vp && ! varequal(vp->text, name) ; vp = vp->next);
-		if (vp == NULL) {
-			if (strchr(name, '='))
-				setvareq(savestr(name), VSTRFIXED);
-			else
-				setvar(name, NULL, VSTRFIXED);
-			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 (strchr(name, '='))
-				setvareq(savestr(name), 0);
-		}
-	}
-	lvp->vp = vp;
-	lvp->next = localvars;
-	localvars = lvp;
-	INTON;
-}
-
-
-/*
- * Called after a function returns.
- */
-
-void
-poplocalvars() {
-	struct localvar *lvp;
-	struct var *vp;
-
-	while ((lvp = localvars) != NULL) {
-		localvars = lvp->next;
-		vp = lvp->vp;
-		if (vp == NULL) {	/* $- saved */
-			bcopy(lvp->text, optval, sizeof optval);
-			ckfree(lvp->text);
-		} else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) {
-			unsetvar(vp->text);
-		} else {
-			if ((vp->flags & VTEXTFIXED) == 0)
-				ckfree(vp->text);
-			vp->flags = lvp->flags;
-			vp->text = lvp->text;
-		}
-		ckfree(lvp);
-	}
-}
-
-
-setvarcmd(argc, argv)  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.
- */
-
-unsetcmd(argc, argv)  char **argv; {
-	char **ap;
-
-	for (ap = argv + 1 ; *ap ; ap++) {
-		unsetfunc(*ap);
-		unsetvar(*ap);
-	}
-	return 0;
-}
-
-
-/*
- * Unset the specified variable.
- */
-
-STATIC void
-unsetvar(s)
-	char *s;
-	{
-	struct var **vpp;
-	struct var *vp;
-
-	vpp = hashvar(s);
-	for (vp = *vpp ; vp ; vpp = &vp->next, vp = *vpp) {
-		if (varequal(vp->text, s)) {
-			INTOFF;
-			if (*(strchr(vp->text, '=') + 1) != '\0'
-			 || vp->flags & VREADONLY) {
-				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;
-		}
-	}
-}
-
-
-
-/*
- * Find the appropriate entry in the hash table from the name.
- */
-
-STATIC struct var **
-hashvar(p)
-	register char *p;
-	{
-	unsigned int hashval;
-
-	hashval = *p << 4;
-	while (*p && *p != '=')
-		hashval += *p++;
-	return &vartab[hashval % VTABSIZE];
-}
-
-
-
-/*
- * 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
-varequal(p, q)
-	register char *p, *q;
-	{
-	while (*p == *q++) {
-		if (*p++ == '=')
-			return 1;
-	}
-	if (*p == '=' && *(q - 1) == '\0')
-		return 1;
-	return 0;
-}
Index: trunk/minix/commands/ash/var.h
===================================================================
--- trunk/minix/commands/ash/var.h	(revision 9)
+++ 	(revision )
@@ -1,129 +1,0 @@
-/*-
- * Copyright (c) 1991 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.
- *
- *	@(#)var.h	5.1 (Berkeley) 3/7/91
- */
-
-/*
- * Shell variables.
- */
-
-/* flags */
-#define VEXPORT		01	/* variable is exported */
-#define VREADONLY	02	/* variable cannot be modified */
-#define VSTRFIXED	04	/* variable struct is staticly allocated */
-#define VTEXTFIXED	010	/* text is staticly allocated */
-#define VSTACK		020	/* text is allocated on the stack */
-#define VUNSET		040	/* the variable is not set */
-
-
-struct var {
-	struct var *next;		/* next entry in hash list */
-	int flags;		/* flags are defined above */
-	char *text;		/* name=value */
-};
-
-
-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;
-extern struct var vps1;
-extern struct var vps2;
-extern struct var vpse;
-#if ATTY
-extern struct var vterm;
-#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 mailval()	(vmail.text + 5)
-#define mpathval()	(vmpath.text + 9)
-#define pathval()	(vpath.text + 5)
-#define ps1val()	(vps1.text + 4)
-#define ps2val()	(vps2.text + 4)
-#define pseval()	(vpse.text + 4)
-#if ATTY
-#define termval()	(vterm.text + 5)
-#endif
-
-#if ATTY
-#define attyset()	((vatty.flags & VUNSET) == 0)
-#endif
-#define mpathset()	((vmpath.flags & VUNSET) == 0)
-
-
-#ifdef __STDC__
-void initvar();
-void setvar(char *, char *, int);
-void setvareq(char *, int);
-struct strlist;
-void listsetvar(struct strlist *);
-char *lookupvar(char *);
-char *bltinlookup(char *, int);
-char **environment();
-int showvarscmd(int, char **);
-void mklocal(char *);
-void poplocalvars(void);
-#else
-void initvar();
-void setvar();
-void setvareq();
-void listsetvar();
-char *lookupvar();
-char *bltinlookup();
-char **environment();
-int showvarscmd();
-void mklocal();
-void poplocalvars();
-#endif
Index: trunk/minix/commands/autil/Makefile
===================================================================
--- trunk/minix/commands/autil/Makefile	(revision 9)
+++ 	(revision )
@@ -1,26 +1,0 @@
-# Makefile for commands/autil
-
-CC = exec cc
-CFLAGS	= -I. -D_MINIX -D_POSIX_SOURCE -wo
-CCLD	= $(CC) -i $(CFLAGS)
-
-all:	anm asize
-
-anm:	anm.c rd.c rd_arhdr.c rd_bytes.c rd_unsig2.c
-	$(CCLD) -o $@ $?
-	install -S 32kw $@
-
-asize:	asize.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-install:	/usr/bin/anm /usr/bin/asize
-
-/usr/bin/anm:	anm
-	install -cs -o bin $? $@
-
-/usr/bin/asize:	asize
-	install -cs -o bin $? $@
-
-clean:
-	rm -f anm asize core
Index: trunk/minix/commands/autil/anm.c
===================================================================
--- trunk/minix/commands/autil/anm.c	(revision 9)
+++ 	(revision )
@@ -1,339 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Id: anm.c,v 1.2 2005/06/23 09:50:54 philip Exp $ */
-/*
-**	print symbol tables for
-**	ACK object files
-**
-**	anm [-gopruns] [name ...]
-*/
-
-#include	"out.h"
-#include	"arch.h"
-#include	"ranlib.h"
-
-#include	<stdio.h>
-#include	<ctype.h>
-
-int	numsort_flg;
-int	sectsort_flg;
-int	undef_flg;
-int	revsort_flg = 1;
-int	globl_flg;
-int	nosort_flg;
-int	arch_flg;
-int	prep_flg;
-int	read_error;
-struct	outhead	hbuf;
-struct	outsect	sbuf;
-long	off;
-char	*malloc();
-char	*realloc();
-long	s_base[S_MAX];	/* for specially encoded bases */
-char	*filename;
-int	narg;
-
-main(argc, argv)
-char **argv;
-{
-
-	if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) {
-		argv++;
-		while (*++*argv) switch (**argv) {
-		case 'n':		/* sort numerically */
-			numsort_flg++;
-			continue;
-
-		case 's':		/* sort in section order */
-			sectsort_flg++;
-			continue;
-
-		case 'g':		/* globl symbols only */
-			globl_flg++;
-			continue;
-
-		case 'u':		/* undefined symbols only */
-			undef_flg++;
-			continue;
-
-		case 'r':		/* sort in reverse order */
-			revsort_flg = -1;
-			continue;
-
-		case 'p':		/* don't sort -- symbol table order */
-			nosort_flg++;
-			continue;
-
-		case 'o':		/* prepend a name to each line */
-			prep_flg++;
-			continue;
-
-		default:		/* oops */
-			fprintf(stderr, "anm: invalid argument -%c\n", *argv[0]);
-			exit(1);
-		}
-		argc--;
-	}
-	if (argc == 0) {
-		argc = 1;
-		argv[1] = "a.out";
-	}
-	narg = argc;
-
-	while(argc--) {
-		int fd;
-
-		filename = *++argv;
-		if ((fd = open(filename, 0)) < 0) {
-			fprintf(stderr, "anm: cannot open %s\n", filename);
-			continue;
-		}
-		process(fd);
-		close(fd);
-	}
-	exit(0);
-}
-
-extern int rd_unsigned2();
-extern long lseek();
-extern char *strncpy();
-
-process(fd)
-	int	fd;
-{
-	unsigned int	magic;
-	long		nextpos;
-	struct ar_hdr	archive_header;
-	static char	buf[sizeof(archive_header.ar_name)+1];
-
-	if (narg > 1) printf("\n%s:\n", filename);
-
-	magic = rd_unsigned2(fd);
-	switch(magic) {
-	case O_MAGIC:
-		lseek(fd, 0L, 0);
-		do_file(fd);
-		break;
-	case ARMAG:
-	case AALMAG:
-		while (rd_arhdr(fd, &archive_header)) {
-			nextpos = lseek(fd, 0L, 1) + archive_header.ar_size;
-			if (nextpos & 1) nextpos++;
-			strncpy(buf,archive_header.ar_name,sizeof(archive_header.ar_name));
-			filename = buf;
-			if ( strcmp(filename, SYMDEF)) {
-				printf("\n%s:\n", filename);
-				do_file(fd);
-			}
-			lseek(fd, nextpos, 0);
-		}
-		break;
-	default:
-		fprintf(stderr, "anm: %s -- bad format\n", filename);
-		break;
-	}
-}
-
-do_file(fd)
-	int	fd;
-{
-	struct	outname	*nbufp = NULL;
-	struct	outname	nbuf;
-	char		*cbufp;
-	long		fi_to_co;
-	long		n;
-	unsigned	readcount;
-	int		i,j;
-	int		compare();
-
-	read_error = 0;
-	rd_fdopen(fd);
-
-	rd_ohead(&hbuf);
-	if (read_error) {
-		return;
-	}
-	if (BADMAGIC(hbuf)) {
-		return;
-	}
-
-	n = hbuf.oh_nname;
-	if (n == 0) {
-		fprintf(stderr, "anm: %s -- no name list\n", filename);
-		return;
-	}
-
-	if (hbuf.oh_nchar == 0) {
-		fprintf(stderr, "anm: %s -- no names\n", filename);
-		return;
-	}
-	if ((readcount = hbuf.oh_nchar) != hbuf.oh_nchar) {
-		fprintf(stderr, "anm: string area too big in %s\n", filename);
-		exit(2);
-	}
-
-	/* store special section bases ??? */
-	if (hbuf.oh_flags & HF_8086) {
-		rd_sect(&sbuf, hbuf.oh_nsect);
-		if (read_error) {
-			return;
-		}
-		for (i=0; i<hbuf.oh_nsect; i++) {
-			s_base[i+S_MIN] =
-				(sbuf.os_base>>12) & 03777760;
-		}
-	}
-
-	if ((cbufp = (char *)malloc(readcount)) == NULL) {
-		fprintf(stderr, "anm: out of memory on %s\n", filename);
-		exit(2);
-	}
-	rd_string(cbufp, hbuf.oh_nchar);
-	if (read_error) {
-		free(cbufp);
-		return;
-	}
-
-	fi_to_co = (long) (cbufp - OFF_CHAR(hbuf));
-	i = 0;
-	while (--n >= 0) {
-		rd_name(&nbuf, 1);
-		if (read_error) {
-			break;
-		}
-
-		if (globl_flg && (nbuf.on_type&S_EXT)==0)
-			continue;
-
-		if (undef_flg
-		    &&
-		    ((nbuf.on_type&S_TYP)!=S_UND || (nbuf.on_type&S_ETC)!=0))
-			continue;
-
-		if (nbuf.on_foff == 0) nbuf.on_mptr = 0;
-		else nbuf.on_mptr = (char *) (nbuf.on_foff + fi_to_co);
-
-		/* adjust value for specially encoded bases */
-		if (hbuf.oh_flags & HF_8086) {
-		    if (((nbuf.on_type&S_ETC) == 0) ||
-			((nbuf.on_type&S_ETC) == S_SCT)) {
-			j = nbuf.on_type&S_TYP;
-			if ((j>=S_MIN) && (j<=S_MAX))
-			    nbuf.on_valu += s_base[j];
-		    }
-		}
-
-		if (nbufp == NULL)
-			nbufp = (struct outname *)malloc(sizeof(struct outname));
-		else
-			nbufp = (struct outname *)realloc(nbufp, (i+1)*sizeof(struct outname));
-		if (nbufp == NULL) {
-			fprintf(stderr, "anm: out of memory on %s\n", filename);
-			exit(2);
-		}
-		nbufp[i++] = nbuf;
-	}
-
-	if (nbufp && nosort_flg==0)
-		qsort(nbufp, i, sizeof(struct outname), compare);
-
-	for (n=0; n<i; n++) {
-		char	cs1[4];
-		char	cs2[4];
-
-		if (prep_flg)
-			printf("%s:", filename);
-
-		switch(nbufp[n].on_type&S_ETC) {
-		case S_SCT:
-			sprintf(cs1, "%2d", (nbufp[n].on_type&S_TYP) - S_MIN);
-			sprintf(cs2, " S");
-			break;
-		case S_FIL:
-			sprintf(cs1, " -");
-			sprintf(cs2, " F");
-			break;
-		case S_MOD:
-			sprintf(cs1, " -");
-			sprintf(cs2, " M");
-			break;
-		case S_COM:
-			sprintf(cs1, " C");
-			if (nbufp[n].on_type&S_EXT)
-				sprintf(cs2, " E");
-			else
-				sprintf(cs2, " -");
-			break;
-		case 0:
-			if (nbufp[n].on_type&S_EXT)
-				sprintf(cs2, " E");
-			else
-				sprintf(cs2, " -");
-
-			switch(nbufp[n].on_type&S_TYP) {
-			case S_UND:
-				sprintf(cs1, " U");
-				break;
-			case S_ABS:
-				sprintf(cs1, " A");
-				break;
-			default:
-				sprintf(cs1, "%2d", (nbufp[n].on_type&S_TYP) - S_MIN);
-			}
-			break;
-		default:
-			sprintf(cs1, "??");
-			sprintf(cs2, " ?");
-		}
-
-		printf("%8lx %s %s %s\n",nbufp[n].on_valu,cs1,cs2,nbufp[n].on_mptr ? nbufp[n].on_mptr : "(NULL)");
-	}
-
-	if (nbufp)
-		free((char *)nbufp);
-	if (cbufp)
-		free((char *)cbufp);
-}
-
-compare(p1, p2)
-struct outname	*p1, *p2;
-{
-	int	i;
-
-	if (sectsort_flg) {
-		if ((p1->on_type&S_TYP) > (p2->on_type&S_TYP))
-			return(revsort_flg);
-		if ((p1->on_type&S_TYP) < (p2->on_type&S_TYP))
-			return(-revsort_flg);
-	}
-
-	if (numsort_flg) {
-		if (p1->on_valu > p2->on_valu)
-			return(revsort_flg);
-		if (p1->on_valu < p2->on_valu)
-			return(-revsort_flg);
-	}
-
-	if (! p1->on_mptr) {
-		if (! p2->on_mptr) return 0;
-		return -revsort_flg;
-	}
-	if (! p2->on_mptr) return revsort_flg;
-
-	i = strcmp(p1->on_mptr, p2->on_mptr);
-
-	if (i > 0)
-		return(revsort_flg);
-	if (i < 0)
-		return(-revsort_flg);
-
-	return(0);
-}
-
-rd_fatal()
-{
-	fprintf(stderr,"read error on %s\n", filename);
-	read_error = 1;
-}
Index: trunk/minix/commands/autil/arch.h
===================================================================
--- trunk/minix/commands/autil/arch.h	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-/* $Id: arch.h,v 1.1 2005/06/23 09:50:54 philip Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-
-#ifndef __ARCH_H_INCLUDED
-#define __ARCH_H_INCLUDED
-
-#define	ARMAG	0177545
-#define AALMAG	0177454
-
-struct	ar_hdr {
-	char	ar_name[14];
-	long	ar_date;
-	char	ar_uid;
-	char	ar_gid;
-	short	ar_mode;
-	long	ar_size;
-};
-
-#define AR_TOTAL	26
-#define AR_SIZE		22
-
-#endif /* __ARCH_H_INCLUDED */
Index: trunk/minix/commands/autil/asize.c
===================================================================
--- trunk/minix/commands/autil/asize.c	(revision 9)
+++ 	(revision )
@@ -1,93 +1,0 @@
-/* @(#)asize.c	1.4 */
-#define	ushort	unsigned short
-
-#include	<stdio.h>
-#include 	"out.h"
-
-/*
-	asize -- determine object size
-
-*/
-
-main(argc, argv)
-char **argv;
-{
-	struct outhead	buf;
-	struct outsect	sbuf;
-	ushort		nrsect;
-	long		sum;
-	int		gorp;
-	FILE		*f;
-
-	if (--argc == 0) {
-		argc = 1;
-		argv[1] = "a.out";
-	}
-	gorp = argc;
-
-	while(argc--) {
-		if ((f = fopen(*++argv, "r"))==NULL) {
-			fprintf(stderr, "asize: cannot open %s\n", *argv);
-			continue;
-		}
-		getofmt ((char *)&buf, SF_HEAD , f);
-		if(BADMAGIC(buf)) {
-			fprintf(stderr, "asize: %s-- bad format\n", *argv);
-			fclose(f);
-			continue;
-		}
-		nrsect = buf.oh_nsect;
-		if (nrsect == 0) {
-			fprintf(stderr, "asize: %s-- no sections\n", *argv);
-			fclose(f);
-			continue;
-		}
-		if (gorp > 1)
-			printf("%s: ", *argv);
-
-		sum = 0;
-		while (nrsect-- > 0) {
-			getofmt ((char *)&sbuf, SF_SECT , f);
-			printf("%ld", sbuf.os_size);
-			sum += sbuf.os_size;
-			if (nrsect > 0)
-				putchar('+');
-		}
-		printf(" = %ld = 0x%lx\n", sum, sum);
-		fclose(f);
-	}
-}
-
-getofmt(p, s, f)
-register char	*p;
-register char	*s;
-register FILE	*f;
-{
-	register i;
-	register long l;
-
-	for (;;) {
-		switch (*s++) {
-/*		case '0': p++; continue; */
-		case '1':
-			*p++ = getc(f);
-			continue;
-		case '2':
-			i = getc(f);
-			i |= (getc(f) << 8);
-			*((short *)p) = i; p += sizeof(short);
-			continue;
-		case '4':
-			l = (long)getc(f);
-			l |= ((long)getc(f) << 8);
-			l |= ((long)getc(f) << 16);
-			l |= ((long)getc(f) << 24);
-			*((long *)p) = l; p += sizeof(long);
-			continue;
-		default:
-		case '\0':
-			break;
-		}
-		break;
-	}
-}
Index: trunk/minix/commands/autil/build
===================================================================
--- trunk/minix/commands/autil/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/autil/obj.h
===================================================================
--- trunk/minix/commands/autil/obj.h	(revision 9)
+++ 	(revision )
@@ -1,79 +1,0 @@
-/* $Id: obj.h,v 1.1 2005/06/23 09:50:54 philip Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include <local.h>
-#include <stdio.h>
-#include <out.h>
-#include <ranlib.h>
-#include <arch.h>
-#include "object.h"
-
-#if ! defined(CHAR_UNSIGNED)
-#define CHAR_UNSIGNED 0
-#endif
-
-#if CHAR_UNSIGNED
-#define Xchar(ch)	(ch)
-#else
-#define Xchar(ch)	((ch) & 0377)
-#endif
-
-#if ! defined(BYTE_ORDER)
-#define BYTE_ORDER 0x3210
-#endif
-
-#if (BYTE_ORDER == 0x3210 || BYTE_ORDER == 0x1032)
-#define uget2(c)	(Xchar((c)[0]) | ((unsigned) Xchar((c)[1]) << 8))
-#define Xput2(i, c)	(((c)[0] = (i)), ((c)[1] = (i) >> 8))
-#define put2(i, c)	{ register int j = (i); Xput2(j, c); }
-#else
-#define uget2(c)	(* ((unsigned short *) (c)))
-#define Xput2(i, c)	(* ((short *) (c)) = (i))
-#define put2(i, c)	Xput2(i, c)
-#endif
-
-#define get2(c)		((short) uget2(c))
-
-#if BYTE_ORDER != 0x0123
-#define get4(c)		(uget2(c) | ((long) uget2((c)+2) << 16))
-#define put4(l, c)	{ register long x=(l); \
-			  Xput2((int)x,c); \
-			  Xput2((int)(x>>16),(c)+2); \
-			}
-#else
-#define get4(c)		(* ((long *) (c)))
-#define put4(l, c)	(* ((long *) (c)) = (l))
-#endif
-
-#define SECTCNT	3	/* number of sections with own output buffer */
-#if BIGMACHINE
-#define WBUFSIZ	(8*BUFSIZ)
-#else
-#define WBUFSIZ	BUFSIZ
-#endif
-
-struct fil {
-	int	cnt;
-	char	*pnow;
-	char	*pbegin;
-	long	currpos;
-	int	fd;
-	char	pbuf[WBUFSIZ];
-};
-
-extern struct fil __parts[];
-
-#define	PARTEMIT	0
-#define	PARTRELO	(PARTEMIT+SECTCNT)
-#define	PARTNAME	(PARTRELO+1)
-#define	PARTCHAR	(PARTNAME+1)
-#ifdef SYMDBUG
-#define PARTDBUG	(PARTCHAR+1)
-#else
-#define PARTDBUG	(PARTCHAR+0)
-#endif
-#define	NPARTS		(PARTDBUG + 1)
-
-#define getsect(s)      (PARTEMIT+((s)>=(SECTCNT-1)?(SECTCNT-1):(s)))
Index: trunk/minix/commands/autil/object.h
===================================================================
--- trunk/minix/commands/autil/object.h	(revision 9)
+++ 	(revision )
@@ -1,45 +1,0 @@
-/* $Id: object.h,v 1.1 2005/06/23 09:50:54 philip Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-
-#include <ansi.h>
-
-#ifndef __OBJECT_INCLUDED__
-#define __OBJECT_INCLUDED__
-
-_PROTOTYPE(int wr_open, (char *f));
-_PROTOTYPE(void wr_close, (void));
-_PROTOTYPE(void wr_ohead, (struct outhead *h));
-_PROTOTYPE(void wr_sect, (struct outsect *s, unsigned int c));
-_PROTOTYPE(void wr_outsect, (int sectno));
-_PROTOTYPE(void wr_emit, (char *b, long c));
-_PROTOTYPE(void wr_putc, (int c));
-_PROTOTYPE(void wr_relo, (struct outrelo *r, unsigned int c));
-_PROTOTYPE(void wr_name, (struct outname *n, unsigned int c));
-_PROTOTYPE(void wr_string, (char *s, long c));
-_PROTOTYPE(void wr_arhdr, (int fd, struct ar_hdr *a));
-_PROTOTYPE(void wr_ranlib, (int fd, struct ranlib *r, long cnt));
-_PROTOTYPE(void wr_int2, (int fd, int i));
-_PROTOTYPE(void wr_long, (int fd, long l));
-_PROTOTYPE(void wr_bytes, (int fd, char *buf, long l));
-_PROTOTYPE(int rd_open, (char *f));
-_PROTOTYPE(int rd_fdopen, (int f));
-_PROTOTYPE(void rd_close, (void));
-_PROTOTYPE(void rd_ohead, (struct outhead *h));
-_PROTOTYPE(void rd_sect, (struct outsect *s, unsigned int c));
-_PROTOTYPE(void rd_outsect, (int sectno));
-_PROTOTYPE(void rd_emit, (char *b, long c));
-_PROTOTYPE(void rd_relo, (struct outrelo *r, unsigned int c));
-_PROTOTYPE(void rd_rew_relo, (struct outhead *head));
-_PROTOTYPE(void rd_name, (struct outname *n, unsigned int c));
-_PROTOTYPE(void rd_string, (char *s, long c));
-_PROTOTYPE(int rd_arhdr, (int fd, struct ar_hdr *a));
-_PROTOTYPE(void rd_ranlib, (int fd, struct ranlib *r, long cnt));
-_PROTOTYPE(int rd_int2, (int fd));
-_PROTOTYPE(long rd_long, (int fd));
-_PROTOTYPE(void rd_bytes, (int fd, char *buf, long l));
-_PROTOTYPE(int rd_fd, (void));
-
-#endif /* __OBJECT_INCLUDED__ */
Index: trunk/minix/commands/autil/out.h
===================================================================
--- trunk/minix/commands/autil/out.h	(revision 9)
+++ 	(revision )
@@ -1,126 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Header: /cvsup/minix/src/commands/autil/out.h,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-
-#ifndef __OUT_H_INCLUDED
-#define __OUT_H_INCLUDED
-/*
- * output format for ACK assemblers
- */
-#ifndef ushort
-#define ushort	unsigned short
-#endif /* ushort */
-
-struct outhead {
-	ushort 	oh_magic;	/* magic number */
-	ushort 	oh_stamp;	/* version stamp */
-	ushort	oh_flags;	/* several format flags */
-	ushort	oh_nsect;	/* number of outsect structures */
-	ushort	oh_nrelo;	/* number of outrelo structures */
-	ushort	oh_nname;	/* number of outname structures */
-	long	oh_nemit;	/* sum of all os_flen */
-	long	oh_nchar;	/* size of string area */
-};
-
-#define O_MAGIC	0x0201		/* magic number of output file */
-#define	O_STAMP	0		/* version stamp */
-#define MAXSECT	64		/* Maximum number of sections */
-
-#define	HF_LINK	0x0004		/* unresolved references left */
-#define	HF_8086	0x0008		/* os_base specially encoded */
-
-struct outsect {
-	long 	os_base;	/* startaddress in machine */
-	long	os_size;	/* section size in machine */
-	long	os_foff;	/* startaddress in file */
-	long	os_flen;	/* section size in file */
-	long	os_lign;	/* section alignment */
-};
-
-struct outrelo {
-	char	or_type;	/* type of reference */
-	char	or_sect;	/* referencing section */
-	ushort	or_nami;	/* referenced symbol index */
-	long	or_addr;	/* referencing address */
-};
-
-struct outname {
-	union {
-	  char	*on_ptr;	/* symbol name (in core) */
-	  long	on_off;		/* symbol name (in file) */
-	}	on_u;
-#define on_mptr	on_u.on_ptr
-#define on_foff	on_u.on_off
-	ushort	on_type;	/* symbol type */
-	ushort	on_desc;	/* debug info */
-	long	on_valu;	/* symbol value */
-};
-
-/*
- * relocation type bits
- */
-#define RELSZ	0x07		/* relocation length */
-#define RELO1	   1		/* 1 byte */
-#define RELO2	   2		/* 2 bytes */
-#define RELO4	   4		/* 4 bytes */
-#define RELPC	0x08		/* pc relative */
-#define RELBR	0x10		/* High order byte lowest address. */
-#define RELWR	0x20		/* High order word lowest address. */
-
-/*
- * section type bits and fields
- */
-#define S_TYP	0x007F		/* undefined, absolute or relative */
-#define S_EXT	0x0080		/* external flag */
-#define S_ETC	0x7F00		/* for symbolic debug, bypassing 'as' */
-
-/*
- * S_TYP field values
- */
-#define S_UND	0x0000		/* undefined item */
-#define S_ABS	0x0001		/* absolute item */
-#define S_MIN	0x0002		/* first user section */
-#define S_MAX	(S_TYP-1)	/* last user section */
-#define S_CRS	S_TYP		/* on_valu is symbol index which contains value */
-
-/*
- * S_ETC field values
- */
-#define S_SCT	0x0100		/* section names */
-#define S_LIN	0x0200		/* hll source line item */
-#define S_FIL	0x0300		/* hll source file item */
-#define S_MOD	0x0400		/* ass source file item */
-#define S_COM	0x1000		/* Common name. */
-#define S_STB	0xe000		/* entries with any of these bits set are
-				   reserved for debuggers
-				*/
-
-/*
- * structure format strings
- */
-#define SF_HEAD		"22222244"
-#define SF_SECT		"44444"
-#define SF_RELO		"1124"
-#define SF_NAME		"4224"
-
-/*
- * structure sizes (bytes in file; add digits in SF_*)
- */
-#define SZ_HEAD		20
-#define SZ_SECT		20
-#define SZ_RELO		8
-#define SZ_NAME		12
-
-/*
- * file access macros
- */
-#define BADMAGIC(x)	((x).oh_magic!=O_MAGIC)
-#define OFF_SECT(x)	SZ_HEAD
-#define OFF_EMIT(x)	(OFF_SECT(x) + ((long)(x).oh_nsect * SZ_SECT))
-#define OFF_RELO(x)	(OFF_EMIT(x) + (x).oh_nemit)
-#define OFF_NAME(x)	(OFF_RELO(x) + ((long)(x).oh_nrelo * SZ_RELO))
-#define OFF_CHAR(x)	(OFF_NAME(x) + ((long)(x).oh_nname * SZ_NAME))
-
-#endif /* __OUT_H_INCLUDED */
Index: trunk/minix/commands/autil/ranlib.h
===================================================================
--- trunk/minix/commands/autil/ranlib.h	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/* $Id: ranlib.h,v 1.1 2005/06/23 09:50:54 philip Exp $ */
-
-#ifndef __RANLIB_H_INCLUDED
-#define __RANLIB_H_INCLUDED
-
-#ifndef SYMDEF
-#	define SYMDEF	"__.SYMDEF"
-#endif /* SYMDEF */
-
-/*
- * Structure of the SYMDEF table of contents for an archive.
- * SYMDEF begins with a long giving the number of ranlib
- * structures that immediately follow, and then continues with a string
- * table consisting of a long giving the number of bytes of
- * strings that follow and then the strings themselves.
- */
-struct ranlib {
-	union {
-	  char	*ran__ptr;	/* symbol name (in core) */
-	  long	ran__off;	/* symbol name (in file) */
-	}	ran_u;
-#define ran_ptr ran_u.ran__ptr
-#define ran_off ran_u.ran__off
-	long	ran_pos;	/* library member is at this position */
-};
-
-#define SZ_RAN	8
-#define SF_RAN	"44"
-
-#endif /* __RANLIB_H_INCLUDED */
Index: trunk/minix/commands/autil/rd.c
===================================================================
--- trunk/minix/commands/autil/rd.c	(revision 9)
+++ 	(revision )
@@ -1,260 +1,0 @@
-/* $Id: rd.c,v 1.1 2005/06/23 09:50:54 philip Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include "obj.h"
-
-extern long		lseek();
-
-/*
- * Parts of the output file.
- */
-#undef PARTEMIT
-#undef PARTRELO
-#undef PARTNAME
-#undef PARTCHAR
-#undef PARTDBUG
-#undef NPARTS
-
-#define	PARTEMIT	0
-#define	PARTRELO	1
-#define	PARTNAME	2
-#define	PARTCHAR	3
-#ifdef SYMDBUG
-#define PARTDBUG	4
-#else
-#define PARTDBUG	3
-#endif
-#define	NPARTS		(PARTDBUG + 1)
-
-static long		offset[MAXSECT];
-
-static int		outfile;
-static long		outseek[NPARTS];
-static long		currpos;
-static long		rd_base;
-#define OUTSECT(i) \
-	(outseek[PARTEMIT] = offset[i])
-#define BEGINSEEK(p, o) \
-	(outseek[(p)] = (o))
-
-static int sectionnr;
-
-static void
-OUTREAD(p, b, n)
-	char *b;
-	long n;
-{
-	register long l = outseek[p];
-
-	if (currpos != l) {
-		lseek(outfile, l, 0);
-	}
-	rd_bytes(outfile, b, n);
-	l += n;
-	currpos = l;
-	outseek[p] = l;
-}
-
-/*
- * Open the output file according to the chosen strategy.
- */
-int
-rd_open(f)
-	char *f;
-{
-
-	if ((outfile = open(f, 0)) < 0)
-		return 0;
-	return rd_fdopen(outfile);
-}
-
-static int offcnt;
-
-int
-rd_fdopen(fd)
-{
-	register int i;
-
-	for (i = 0; i < NPARTS; i++) outseek[i] = 0;
-	offcnt = 0;
-	rd_base = lseek(fd, 0L, 1);
-	if (rd_base < 0) {
-		return 0;
-	}
-	currpos = rd_base;
-	outseek[PARTEMIT] = currpos;
-	outfile = fd;
-	sectionnr = 0;
-	return 1;
-}
-
-void
-rd_close()
-{
-
-	close(outfile);
-	outfile = -1;
-}
-
-int
-rd_fd()
-{
-	return outfile;
-}
-
-void
-rd_ohead(head)
-	register struct outhead	*head;
-{
-	register long off;
-
-	OUTREAD(PARTEMIT, (char *) head, (long) SZ_HEAD);
-#if BYTE_ORDER == 0x0123
-	if (sizeof(struct outhead) != SZ_HEAD)
-#endif
-	{
-		register char *c = (char *) head + (SZ_HEAD-4);
-		
-		head->oh_nchar = get4(c);
-		c -= 4; head->oh_nemit = get4(c);
-		c -= 2; head->oh_nname = uget2(c);
-		c -= 2; head->oh_nrelo = uget2(c);
-		c -= 2; head->oh_nsect = uget2(c);
-		c -= 2; head->oh_flags = uget2(c);
-		c -= 2; head->oh_stamp = uget2(c);
-		c -= 2; head->oh_magic = uget2(c);
-	}
-	off = OFF_RELO(*head) + rd_base;
-	BEGINSEEK(PARTRELO, off);
-	off += (long) head->oh_nrelo * SZ_RELO;
-	BEGINSEEK(PARTNAME, off);
-	off += (long) head->oh_nname * SZ_NAME;
-	BEGINSEEK(PARTCHAR, off);
-#ifdef SYMDBUG
-	off += head->oh_nchar;
-	BEGINSEEK(PARTDBUG, off);
-#endif
-}
-
-void
-rd_rew_relos(head)
-	register struct outhead *head;
-{
-	register long off = OFF_RELO(*head) + rd_base;
-
-	BEGINSEEK(PARTRELO, off);
-}
-
-void
-rd_sect(sect, cnt)
-	register struct outsect	*sect;
-	register unsigned int	cnt;
-{
-	register char *c = (char *) sect + cnt * SZ_SECT;
-
-	OUTREAD(PARTEMIT, (char *) sect, (long)cnt * SZ_SECT);
-	sect += cnt;
-	offcnt += cnt;
-	while (cnt--) {
-		sect--;
-#if BYTE_ORDER == 0x0123
-		if (sizeof(struct outsect) != SZ_SECT)
-#endif
-		{
-			c -= 4; sect->os_lign = get4(c);
-			c -= 4; sect->os_flen = get4(c);
-			c -= 4; sect->os_foff = get4(c);
-			c -= 4; sect->os_size = get4(c);
-			c -= 4; sect->os_base = get4(c);
-		}
-		offset[--offcnt] = sect->os_foff + rd_base;
-	}
-}
-
-void
-rd_outsect(s)
-{
-	OUTSECT(s);
-	sectionnr = s;
-}
-
-/*
- * We don't have to worry about byte order here.
- */
-void
-rd_emit(emit, cnt)
-	char		*emit;
-	long		cnt;
-{
-	OUTREAD(PARTEMIT, emit, cnt);
-	offset[sectionnr] += cnt;
-}
-
-void
-rd_relo(relo, cnt)
-	register struct outrelo	*relo;
-	register unsigned int cnt;
-{
-
-	OUTREAD(PARTRELO, (char *) relo, (long) cnt * SZ_RELO);
-#if BYTE_ORDER == 0x0123
-	if (sizeof(struct outrelo) != SZ_RELO)
-#endif
-	{
-		register char *c = (char *) relo + (long) cnt * SZ_RELO;
-
-		relo += cnt;
-		while (cnt--) {
-			relo--;
-			c -= 4; relo->or_addr = get4(c);
-			c -= 2; relo->or_nami = uget2(c);
-			relo->or_sect = *--c;
-			relo->or_type = *--c;
-		}
-	}
-}
-
-void
-rd_name(name, cnt)
-	register struct outname	*name;
-	register unsigned int cnt;
-{
-
-	OUTREAD(PARTNAME, (char *) name, (long) cnt * SZ_NAME);
-#if BYTE_ORDER == 0x0123
-	if (sizeof(struct outname) != SZ_NAME)
-#endif
-	{
-		register char *c = (char *) name + (long) cnt * SZ_NAME;
-
-		name += cnt;
-		while (cnt--) {
-			name--;
-			c -= 4; name->on_valu = get4(c);
-			c -= 2; name->on_desc = uget2(c);
-			c -= 2; name->on_type = uget2(c);
-			c -= 4; name->on_foff = get4(c);
-		}
-	}
-}
-
-void
-rd_string(addr, len)
-	char *addr;
-	long len;
-{
-	
-	OUTREAD(PARTCHAR, addr, len);
-}
-
-#ifdef SYMDBUG
-void
-rd_dbug(buf, size)
-	char		*buf;
-	long		size;
-{
-	OUTREAD(PARTDBUG, buf, size);
-}
-#endif
Index: trunk/minix/commands/autil/rd_arhdr.c
===================================================================
--- trunk/minix/commands/autil/rd_arhdr.c	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-/* $Id: rd_arhdr.c,v 1.1 2005/06/23 09:50:54 philip Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include "obj.h"
-
-int
-rd_arhdr(fd, arhdr)
-	register struct ar_hdr	*arhdr;
-{
-	char buf[AR_TOTAL];
-	register char *c = buf;
-	register char *p = arhdr->ar_name;
-	register int i;
-
-	i = read(fd, c, AR_TOTAL);
-	if (i == 0) return 0;
-	if (i != AR_TOTAL) {
-		rd_fatal();
-	}
-	i = 14;
-	while (i--) {
-		*p++ = *c++;
-	}
-	arhdr->ar_date = ((long) get2(c)) << 16; c += 2;
-	arhdr->ar_date |= ((long) get2(c)) & 0xffff; c += 2;
-	arhdr->ar_uid = *c++;
-	arhdr->ar_gid = *c++;
-	arhdr->ar_mode = get2(c); c += 2;
-	arhdr->ar_size = (long) get2(c) << 16; c += 2;
-	arhdr->ar_size |= (long) get2(c) & 0xffff;
-	return 1;
-}
Index: trunk/minix/commands/autil/rd_bytes.c
===================================================================
--- trunk/minix/commands/autil/rd_bytes.c	(revision 9)
+++ 	(revision )
@@ -1,35 +1,0 @@
-/* $Id: rd_bytes.c,v 1.1 2005/06/23 09:50:54 philip Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-
-#include "obj.h"
-
-#define MININT		(1 << (sizeof(int) * 8 - 1))
-#define MAXCHUNK	(~MININT)	/* Highest count we read(2).	*/
-/* Unfortunately, MAXCHUNK is too large with some  compilers. Put it in
-   an int!
-*/
-
-static int maxchunk = MAXCHUNK;
-
-/*
- * We don't have to worry about byte order here.
- * Just read "cnt" bytes from file-descriptor "fd".
- */
-void 
-rd_bytes(fd, string, cnt)
-	register char	*string;
-	register long	cnt;
-{
-
-	while (cnt) {
-		register int n = cnt >= maxchunk ? maxchunk : cnt;
-
-		if (read(fd, string, n) != n)
-			rd_fatal();
-		string += n;
-		cnt -= n;
-	}
-}
Index: trunk/minix/commands/autil/rd_unsig2.c
===================================================================
--- trunk/minix/commands/autil/rd_unsig2.c	(revision 9)
+++ 	(revision )
@@ -1,15 +1,0 @@
-/* $Id: rd_unsig2.c,v 1.1 2005/06/23 09:50:54 philip Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include "obj.h"
-
-unsigned int
-rd_unsigned2(fd)
-{
-	char buf[2];
-
-	rd_bytes(fd, buf, 2L);
-	return uget2(buf);
-}
Index: trunk/minix/commands/awk/Makefile
===================================================================
--- trunk/minix/commands/awk/Makefile	(revision 9)
+++ 	(revision )
@@ -1,30 +1,0 @@
-# Makefile for awk.
-
-CC = exec cc
-CFLAGS	= -D_MINIX -D_POSIX_SOURCE -wo -w
-LDFLAGS	= -i -f
-
-OBJS = m.o e.o n.o l.o r.o v.o y.o regexp.o k.o
-
-all:	awk
-
-awk:	$(OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(OBJS) #-lm
-	install -S 32kw $@
-
-install:	/usr/bin/awk
-
-/usr/bin/awk:	awk
-	install -cs -o bin $? $@
-
-clean:
-	rm -f awk *.o a.out *.bak core
-
-e.o:	awk.h regexp.h
-l.o:	awk.h
-m.o:	awk.h
-n.o:	awk.h
-r.o:	awk.h regexp.h
-regexp.o:	regexp.h
-v.o:	awk.h regexp.h
-y.o:	awk.h
Index: trunk/minix/commands/awk/NOTE
===================================================================
--- trunk/minix/commands/awk/NOTE	(revision 9)
+++ 	(revision )
@@ -1,38 +1,0 @@
-a small AWK clone
-
-	±ÌvOÍAMinix 1.2 pÉ¢œàÌÅ·B®¬_Zðg¢
-Ü·©çAMinix 1.5 ÈOÌ ACK-C ÅÍRpCÅ«Ü¹ñB»Ìœß makefile 
-ÅÍAPeter S. Housel³ñÌ®¬_pbP[Wðg€æ€ÉÈÁÄ¢Ü·B
-CFLAGS Ì -f ªA»ÌwŠÅ·B±Ì®¬_pbP[WÍAñíÉæ­Å«Ä
-¢Ü·ªAatan(x, y) Ìø«ÌªtÉÈÁÄ¢Ü·ÌÅAC³µÄš¢Ä­
-Ÿ³¢BŒÉàœ© Áœæ€ÈL¯ª èÜ·ªAYêÄµÜ¢ÜµœBàµAœ
-©âèª éæ€ÅµœçA²A¢œŸ¯êÎAª©ªÅgÁÄ¢éàÌðö\
-·éæ€ÉµÜ·B
-
-	±ÌvOÍAShift-JIS Ì¿R[hðµ€æ€ÉÈÁÄ¢Ü·B
-
-EUC ÉÎ³¹éêÍA³K\»Ìµ¢A¿R[hÉÖW·éªÌ·ªK
-vÅ·ªAåµœèÔÅÍ èÜ¹ñBÇÈœ©ÏX³êœêÍApb`ðpÓµ
-Ä¢œŸ¯éÆðµ¢Å·B
-
-	ÍAÌÌ awk ÌdlÉÈÁÄ¢ÜµœªAuAWK Programming Languagev
-ªoÅ³êAPOSIX 1003.2 Ì draft Åà nawk dlªÌp³êœÌð@ïÉAnawk 
-ÌdlÉ«·ŠÜµœBIWiÌ awk ÆáÁÄAparser à lexical analizer 
-à hand maid Å·©çA64K+64K ÌÉûÜÁÄ¢Ü·B
-
-	{ÍAMinix çµ¢A³ÞIÈvOÉ·×«Å·µA»€µœ©Á
-œÌÅ·ªAàÆàÆA©ªœ¿ªg€œßÉAàÆçžÉXN[ð©Èª
-ç¢ÄµÜÁœœßA«ê¢ÈR[fBOÉÈÁÄ¢Ü¹ñBµ©µA64K+64K 
-ÌÅgŠé awk ªŒÉ èÜ¹ñÌÅAÆè Šž»sÌóÔÅöJµÄš­
-±ÆÉµÜµœB
-
-	vO»ÌàÌÍA³K\»Ì]¿ÉË¶·éàÌð¢ÄAuAWK 
-Programming LanguagevÉfÚ³êÄ¢éeXgvOÉÊé±ÆðmFµÄ 
-èÜ·B
-
-
-	32-bit Minix ÌêÍAAT&T IWiÌ awk Æ© gawk, mawk Æ¢Áœ
-vOªgŠÜ·ªA®¬_ðT|[gµœAc386 Å±ÌvOðR
-pC·é±ÆàÅ«Ü·B
-
-œÑ _ê (kh@hiraide.mogami-wire.co.jp)  1995-01-29
Index: trunk/minix/commands/awk/README
===================================================================
--- trunk/minix/commands/awk/README	(revision 9)
+++ 	(revision )
@@ -1,13 +1,0 @@
-A small AWK clone for the 16-bit Minix
-
-	We have written this program for the Minix 1.2 to fit into 64K+64K
-memory.  When compiling this program, you need the Peter S. Housel's 
-Floating Math Package with corrected the atan() function.  Original atan()
-function has incorrect argument sequence.
-
-	This program supports Japanese Shift-JIS KANJI code and passes
-all the test program of the "AWK programming language" written by original
-AWK authors except some programs relied upon the way of regular expression 
-evaluation.
-
-Kouichi Hirabayashi (kh@mogami-wire.co.jp)
Index: trunk/minix/commands/awk/awk.h
===================================================================
--- trunk/minix/commands/awk/awk.h	(revision 9)
+++ 	(revision )
@@ -1,186 +1,0 @@
-/*
- * a small awk clone
- *
- * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
- *
- * Absolutely no warranty. Use this software with your own risk.
- *
- * Permission to use, copy, modify and distribute this software for any
- * purpose and without fee is hereby granted, provided that the above
- * copyright and disclaimer notice.
- *
- * This program was written to fit into 64K+64K memory of the Minix 1.2.
- */
-
-/* lexical/parser tokens and executable statements */
-
-#define FIRSTP	256
-#define ARG	256
-#define ARITH	257
-#define ARRAY	258
-#define ASSIGN	259
-#define CALL	260
-#define CAT	261
-#define COND	262
-#define DELETE	263
-#define DO	264
-#define ELEMENT	265
-#define FIELD	266
-#define FOR	267
-#define FORIN	268
-#define GETLINE	269
-#define IF	270
-#define IN	271
-#define JUMP	272
-#define MATHFUN	273
-#define NULPROC	274
-#define P1STAT	275
-#define P2STAT	276
-#define PRINT	277
-#define PRINT0	278
-#define STRFUN	279
-#define SUBST	280
-#define USRFUN	281
-#define WHILE	282
-#define LASTP	282
-	/* lexical token */
-
-#define ADD	300	/* + */
-#define ADDEQ	301	/* += */
-#define AND	302	/* && */
-#define BEGIN	303	/* BEGIN */
-#define BINAND	304	/* & */
-#define BINOR	305	/* | */
-#define BREAK	306	/* break */
-#define CLOSE	307	/* close */
-#define CONTIN	308	/* continue */
-#define DEC	309	/* -- */
-#define DIV	310	/* / */
-#define DIVEQ	311	/* /= */
-#define	ELSE	312	/* else */
-#define END	313	/* END */
-#define EOL	314	/* ; or '\n' */
-#define EQ	315	/* == */
-#define EXIT	316	/* exit */
-#define FUNC	317	/* function */
-#define GE	318	/* >= */
-#define GT	319	/* > */
-#define IDENT	320	/* identifier */
-#define INC	321	/* ++ */
-#define LE	322	/* <= */
-#define LT	323	/* < */
-#define MATCH	324	/* ~ */
-#define MOD	325	/* % */
-#define MODEQ	326	/* %= */
-#define MULT	327	/* * */
-#define MULTEQ	328	/* *= */
-#define NE	329	/* != */
-#define NEXT	330	/* next */
-#define NOMATCH	331	/* !~ */
-#define NOT	332	/* ! */
-#define NUMBER	333	/* integer or floating number */
-#define OR	334	/* || */
-#define POWEQ	335	/* ^= */
-#define POWER	336	/* ^ */
-#define PRINTF	337	/* printf */
-#define REGEXP	338	/* /REG/ */
-#define RETURN	339	/* return */
-#define SHIFTL	340	/* << */
-#define SHIFTR	341	/* >> */
-#define SPRINT	342	/* sprint */
-#define SPRINTF	343	/* sprintf */
-#define STRING	344	/* ".." */
-#define SUB	345	/* - */
-#define SUBEQ	346	/* -= */
-#define SYSTEM	347	/* system */
-#define UMINUS	348	/* - */
-
-/* tokens in parser */
-
-#define VALUE	400	/* value node */
-#define INCDEC	401	/* ++, -- */
-#define PRE	402	/* pre incre/decre */
-#define POST	403	/* post incre/decre */
-
-/* redirect in print(f) statement */
-
-#define R_OUT	410	/* > */
-#define R_APD	411	/* >> */
-#define R_PIPE	412	/* | */
-#define R_IN	413	/* < */
-#define R_PIN	414	/* | getline */
-#define R_POUT	415	/* print | */
-
-/* function */
-
-#define ATAN2	500	/* atan2 */
-#define COS	501	/* cos */
-#define EXP	502	/* exp */
-#define INDEX	503	/* index */
-#define INT	504	/* int */
-#define LENGTH	505	/* length */
-#define LOG	506	/* log */
-#define RAND	507	/* rand */
-#define RGSUB	508	/* gsub */
-#define RMATCH	509	/* match */
-#define RSUB	510	/* sub */
-#define SIN	511	/* sin */
-#define SPLIT	512	/* split */
-#define SQRT	513	/* sqrt */
-#define SRAND	514	/* srand */
-#define SUBSTR	515	/* substr */
-
-/* print(f) options */
-
-#define FORMAT	1024	/* PRINTF, SPRINTF */
-#define STROUT	2048	/* SPRINTF */
-#define PRMASK	0x3ff	/* ~(FORMAT|STROUT) */
-
-	/* node - used in parsed tree */
-
-struct node {
-  int n_type;			/* node type */
-  struct node *n_next;		/* pointer to next node */
-  struct node *n_arg[1];	/* argument (variable length) */
-};
-
-typedef struct node NODE;
-
-	/* object cell */
-
-struct cell {
-  int c_type;		/* cell type */
-  char *c_sval;		/* string value */
-  double c_fval;	/* floating value */
-};
-
-typedef struct cell CELL;
-
-	/* cell type */
-
-#define UDF	0	/* pass parameter */
-#define VAR	1	/* variable */
-#define NUM	2	/* number */
-#define ARR	4	/* array */
-#define STR	8	/* string */
-#define REC	16	/* record */
-#define FLD	32	/* filed */
-#define PAT	64	/* pattern (compiled REGEXPR) */
-#define BRK	128	/* break */
-#define CNT	256	/* continue */
-#define NXT	512	/* next */
-#define EXT	1024	/* exit */
-#define RTN	2048	/* return */
-#define TMP	4096	/* temp cell */
-#define POS	8192	/* argument position */
-#define FUN	16384	/* function */
-
-	/* symbol cell - linked to symbol table */
-
-struct symbol {
-  char *s_name;
-  CELL *s_val;
-  struct symbol *s_next;
-};
-
-typedef struct symbol SYMBOL;
Index: trunk/minix/commands/awk/build
===================================================================
--- trunk/minix/commands/awk/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/awk/e.c
===================================================================
--- trunk/minix/commands/awk/e.c	(revision 9)
+++ 	(revision )
@@ -1,952 +1,0 @@
-/*
- * a small awk clone
- *
- * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
- *
- * Absolutely no warranty. Use this software with your own risk.
- *
- * Permission to use, copy, modify and distribute this software for any
- * purpose and without fee is hereby granted, provided that the above
- * copyright and disclaimer notice.
- *
- * This program was written to fit into 64K+64K memory of the Minix 1.2.
- */
-
-
-#include <stdio.h>
-#include <ctype.h>
-#include "awk.h"
-#include "regexp.h"
-
-extern char **FS, **OFS, **ORS, **OFMT;
-extern double *RSTART, *RLENGTH;
-extern char record[];
-extern CELL *field[];
-
-extern int r_start, r_length;
-
-double getfval(), atof();
-char *strsave(), *getsval(), *strcat(), *strstr();
-CELL *mkcell(), *mktmp();
-CELL *Field(), *Split(), *Forin();
-CELL *Arith(), *Assign(), *Stat(), *Mathfun(), *Strfun(), *Cond();
-CELL *Print(), *Cat(), *Array(), *Element();
-CELL *If(), *While(), *For(), *Do(), *Jump();
-CELL *P1stat(), *P2stat(), *Print0();
-CELL *Arg(), *Call(), *Ret();
-CELL *Subst(), *In(), *Getline(), *Delete(), *Close();
-CELL *Nulproc(), *Usrfun();
-CELL *_Arg();
-
-FILE *getfp();	/* r.c */
-
-CELL truecell = { NUM, NULL, 1.0 };
-CELL falsecell = { NUM, NULL, 0.0 };
-static CELL breakcell = { BRK, NULL, 0.0 };
-static CELL contcell = { CNT, NULL, 0.0 };
-static CELL nextcell = { NXT, NULL, 0.0 };
-static CELL retcell = { RTN, NULL, 0.0 };
-
-static CELL *retval;	/* function return value */
-
-int pateval;	/* used in P1STAT & P2STAT */
-static char *r_str;	/* STR in 'str ~ STR */
-static regexp *r_pat;	/* compiled pattern for STR */
-
-CELL *(*proctab[])() = {
-  Arg, Arith, Array, Assign, Call, Cat, Cond, Delete, Do, Element,
-  Field, For, Forin, Getline, If, In, Jump, Mathfun, Nulproc, P1stat,
-  P2stat, Print, Print0, Strfun, Subst, Usrfun, While
-};
-
-CELL *
-execute(p) NODE *p;
-{
-  int type, i;
-  CELL *r, *(*proc)();
-
-  type = p->n_type;
-  if (type == VALUE) {
-	if ((r = (CELL *) p->n_arg[0])->c_type & PAT && pateval) {
-		i = match(r->c_sval, (char *)record) ? 1 : 0;
-		r = mktmp(NUM, NULL, (double) i);
-	}
-	return r;
-  }
-  for ( ; p != NULL; p = p->n_next) {
-#if 0
-	if (p->n_type == VALUE) continue;	/* neglect */
-#endif
-/*
-	switch ((int) p->n_type) {
-	case ARRAY:
-		r = Array(p);
-		break;
-	case ARITH:
-		r = Arith(p);
-		break;
-	case ASSIGN:
-		r = Assign(p);
-		break;
-	case PRINT:
-		r = Print(p);
-		break;
-	case PRINT0:
-		r = Print0(p);
-		break;
-	case CAT:
-		r = Cat(p);
-		break;
-	case MATHFUN:
-		r = Mathfun(p);
-		break;
-	case STRFUN:
-		r = Strfun(p);
-		break;
-	case COND:
-		r = Cond(p);
-		break;
-	case IF:
-		r = If(p);
-		break;
-	case P1STAT:
-		r = P1stat(p);
-		break;
-	case P2STAT:
-		r = P2stat(p);
-		break;
-	case WHILE:
-		r = While(p);
-		break;
-	case DO:
-		r = Do(p);
-		break;
-	case FOR:
-		r = For(p);
-		break;
-	case FORIN:
-		r = Forin(p);
-		break;
-	case FIELD:
-		r = Field(p);
-		break;
-	case JUMP:
-		r = Jump(p);
-		break;
-	case ARG:
-		r = Arg(p);
-		break;
-	case CALL:
-		r = Call(p);
-		break;
-	case SUBST:
-		r = Subst(p);
-		break;
-	case ELEMENT:
-		r = Element(p);
-		break;
-	case IN:
-		r = In(p);
-		break;
-	case GETLINE:
-		r = Getline(p);
-		break;
-	case DELETE:
-		r = Delete(p);
-		break;
-	case NULPROC:
-		r = &truecell;
-		break;
-	default:
-		printf("PROGRAM ERROR ? ILLEGAL NODE TYPE(%d)\n", type);
-		exit(1);
-		break;
-	}
-*/
-	i = (int) p->n_type;
-	if (i < FIRSTP || i > LASTP)
-		error("ILLEGAL PROC (%d)", i);
-	proc = proctab[i - FIRSTP];
-	r = (*proc)(p);
-	if (r->c_type & (BRK|CNT|NXT|RTN))
-		return r;
-	if (p->n_next != NULL)
-		c_free(r);
-#ifdef DOS
-	kbhit();	/* needs in MS-DOS */
-#endif
-  }
-  return r;
-}
-
-static CELL *
-Arith(p) NODE *p;
-{
-  int op;
-  CELL *r, *u, *v, *execute();
-  double x, y, fmod(), pow();
-
-  op = (int) p->n_arg[0];
-  if (op == UMINUS) {
-	u = execute(p->n_arg[1]);
-	x = - getfval(u);
-  }
-  else if (op == INCDEC) {
-	u = execute(p->n_arg[1]);
-	x = getfval(u);
-	setfval(u, x + (int) p->n_arg[2]);
-	if ((int) p->n_arg[3] == PRE)
-		return u;
-	/* return dummy */
-  }
-  else {
-	u = execute(p->n_arg[1]);
-	v = execute(p->n_arg[2]);
-	x = getfval(u);
-	y = getfval(v);
-	if (op == DIV || op == MOD) {
-		if (y == 0.0)
-			fprintf(stderr, "divid by 0\n");
-	}
-	switch (op) {
-	case SUB: x -= y;break;
-	case ADD: x += y; break;
-	case MULT: x *= y; break;
-	case DIV:
-		if (y == 0.0)
-			error("division by zero in \"/\"", (char *)0);
-		x /= y; break;
-	case MOD:
-		if (y == 0.0)
-			error("division by zero in \"%%\"", (char *)0);
-		x = fmod(x, y); break;
-	case POWER: x = pow(x, y); break;
-	default: printf("UNSUPPORTED ARITH OPERATOR !\n"); break;
-	}
-	c_free(v);
-  }
-  c_free(u);
-  r = mktmp(NUM, NULL, x);
-  return r;
-}
-
-static CELL *
-Assign(p) NODE *p;
-{
-  CELL *u, *v, *execute();
-  int op;
-  double x, y, fmod(), pow();
-
-  op = (int) p->n_arg[0];
-  u = execute(p->n_arg[1]);
-
-#if 0
-  if (u->c_type == UDF)	/* fix up local var */
-	u->c_type |= VAR|STR;
-#endif
-  if (!(u->c_type & (VAR|FLD|REC)) && (u->c_type != UDF))
-	fprintf(stderr, "ASSIGN TO NON VARIABLE (%d)\n", u->c_type);
-  v = execute(p->n_arg[2]);
-
-  if (u == v)
-	goto rtn;	/* same node */
-
-  if (op == ASSIGN) {
-	if (v->c_type & NUM/* || isnum(v->c_sval)*/)
-		setfval(u, getfval(v));
-	else
-		setsval(u, getsval(v));
-  }
-  else {
-	x = getfval(u);
-	y = getfval(v);
-	switch (op) {
-	case ADDEQ:	x += y; break;
-	case SUBEQ:	x -= y; break;
-	case MULTEQ:	x *= y; break;
-	case DIVEQ:
-		if (y == 0.0)
-			error("division by zero in \"/=\"", (char *)0);
-		x /= y; break;
-	case MODEQ:
-		if (y == 0.0)
-			error("division by zero in \"%=\"", (char *)0);
-		x = fmod(x, y); break;
-	case POWEQ:	x = pow(x, y); break;
-	default:
-		synerr("illegal assign op (%d)", op);
-		break;
-	}
-	setfval(u, x);
-  }
-rtn:
-  c_free(v);
-  return u;
-}
-
-static CELL *
-Cat(p) NODE *p;
-{
-  CELL *u;
-  char *s, *t, str[BUFSIZ];
-
-  u = execute(p->n_arg[0]);
-  s = getsval(u);
-  for (t = str; *s; )
-	*t++ = *s++;
-  c_free(u);
-  u = execute(p->n_arg[1]);
-  s = getsval(u);
-  while (*s)
-	*t++ = *s++;
-  c_free(u);
-  *t = '\0';
- return mktmp(STR, str, 0.0);
-}
-
-static CELL *
-Print(p) NODE *p;
-{
-  register int i, redir, typ;
-  CELL *u;
-  char *s, str[BUFSIZ];
-  char *file;
-  FILE *fp;
-
-  redir = (int) p->n_arg[0];
-  if (typ = redir & PRMASK) {	/* redirect */
-	u = execute(p->n_arg[1]);
-	file = getsval(u);
-	if (typ == R_PIPE)
-		typ = R_POUT;
-	fp = getfp(file, typ);
-	c_free(u);
-  }
-  else
-	fp = stdout;
-  if (redir & FORMAT)	/* format */
-	format(str, p);
-  else {
-	*str = '\0';
-	for (i = 2; p->n_arg[i] != NULL; i++) {
-		if (i > 2)
-			strcat(str, *OFS);
-		u = execute(p->n_arg[i]);
-		s = getsval(u);
-		strcat(str, s);
-		c_free(u);
-	}
-	strcat(str, *ORS);
-  }
-  if (redir & STROUT)	/* sprintf */
-	return mktmp(STR, str, 0.0);
-  fputs(str, fp);
-  fflush(fp);
-  return &truecell;
-}
-
-static CELL *
-Mathfun(p) NODE *p;
-{
-  CELL *u, *v;
-  double x, y;
-  double atan2(), cos(), exp(), log(), sin(), sqrt(), modf();
-
-  if ((int) p->n_arg[1] == 0) {
-	u = NULL;
-	x = 0.0;
-  }
-  else {
-	u = execute(p->n_arg[2]);
-	x = getfval(u);
-  }
-  switch ((int) p->n_arg[0]) {
-  case ATAN2:
-	if ((int) p->n_arg[1] == 2) {
-		v = execute(p->n_arg[3]);
-		y = getfval(v);
-		x = atan2(x, y);
-		c_free(v);
-	}
-	else
-		x = 0.0;
-	break;
-  case COS:	x = cos(x); break;
-  case EXP:	x = exp(x); break;
-  case INT:	y = modf(x, &x); break;
-  case LOG:	x = log(x); break;
-  case SIN:	x = sin(x); break;
-  case SQRT:	x = sqrt(x); break;
-  case RAND:	x = (double) rand() / 32768.0; break;
-  case SRAND:	if (x == 0.0)
-			x = (double) time(0);
-		x = (double) srand((int) x);
-		break;
-  default:
-	fprintf(stderr, "unknown math function (%d)\n", p->n_arg[2]);
-	break;
-  }
-  if (u != NULL)
-	c_free(u);
-  return mktmp(NUM, NULL, x);
-}
-
-static CELL *
-Strfun(p) NODE *p;
-{
-  CELL *u, *v, *r;
-  char *s, *t, str[BUFSIZ];
-  int i, m, n;
-  double x;
-  regexp *pat, *getpat();
-
-  n = (int) p->n_arg[1];
-  if (n > 0 && (int) p->n_arg[0] != SPLIT) {
-	u = execute(p->n_arg[2]);
-	s = getsval(u);
-  }
-  else {
-	s = "";
-	u = NULL;
-  }
-  switch ((int) p->n_arg[0]) {
-  case INDEX:
-	if (n > 1) {
-		v = execute(p->n_arg[3]);
-		t = getsval(v);
-		i = Index(s, t);
-		c_free(v);
-	}
-	else
-		i = 0;
-	r = mktmp(NUM, NULL, (double) i);
-	break;
-  case LENGTH:
-	i = (n > 0) ? jstrlen(s) : jstrlen(record);
-	r = mktmp(NUM, NULL, (double) i);
-	break;
-  case SPLIT:
-	r = Split(p);
-	break;
-  case SUBSTR:
-	if (n > 1) {
-		v = execute(p->n_arg[3]);
-		m = (int) getfval(v) - 1;
-		c_free(v);
-	}
-	else
-		m = 0;
-	if (n > 2) {
-		v = execute(p->n_arg[4]);
-		n = (int) getfval(v);
-		c_free(v);
-	}
-	else
-		n = jstrlen(s) - m;
-	for (t = str; *s && m-- > 0; s++)
-		if (isKanji(*s))
-			s++;
-	while (*s && n-- > 0) {
-		if (isKanji(*s))
-			*t++ = *s++;
-		*t++ = *s++;
-	}
-	*t = '\0';
-	r = mktmp(STR, str, 0.0);
-	break;
-  case RMATCH:
-	if (n > 1) {
-		v = execute(p->n_arg[3]);
-		pat = getpat(v);
-		match(pat, s);
-		c_free(v);
-		if (r_start) {	/* change only if match */
-			*RSTART = (double) r_start;
-			*RLENGTH = (double) r_length;
-		}
-		r = mktmp(NUM, NULL, (double) r_start);
-	}
-	else
-		error("missing regexpr in match(str, regexpr)");
-	break;
-  case CLOSE:
-	r = Close(s);
-	break;
-  case SYSTEM:
-	r = mktmp(NUM, NULL, system(s) == -1 ? 0.0 : 1.0);
-	break;
-  default:
-	fprintf(stderr, "unknown string function");
-	break;
-  }
-  c_free(u);
-  return r;
-}
-
-static regexp *
-getpat(r) CELL *r;
-{
-  regexp *pat, *mkpat();
-
-  if (r->c_type & PAT)
-	pat = (regexp *) r->c_sval;
-  else {
-	if (r_str && strcmp(r_str, r->c_sval) == 0)
-		pat = r_pat;
-	else {
-		sfree(r_str); sfree(r_pat);
-		r_str = strsave(getsval(r));
-		pat = r_pat = mkpat(r_str);
-	}
-  }
-  return pat;
-}
-
-static CELL *
-Subst(p) NODE *p;
-{
-  CELL *u, *v, *w;
-  char *s, *t, *r, str[BUFSIZ], *strcpy();
-  int i, n;
-
-  n = (int) p->n_arg[1];
-  if (n > 1) {
-	u = execute(p->n_arg[3]);	/* substitute string */
-	s = getsval(u);
-	v = execute(p->n_arg[2]);	/* expr */
-	if (n > 2) {
-		w = execute(p->n_arg[4]);
-		t = getsval(w);
-		r = str;
-	}
-	else {
-		t = r = record;
-		w = NULL;
-	}
-	i = (int) p->n_arg[0] == RGSUB ? 0 : 1;
-	if (v->c_type & (PAT|STR))
-		i = Sub(r, v->c_sval, (v->c_type & STR), s, t, i);
-	else
-		error("[g]sub(PAT, .. ) must be /../ or string (%d)",
-			w->c_type);
-	if (n > 2) {
-		if (w->c_type & REC) {
-			strcpy(record, str);
-			mkfld(record, *FS, field);
-		}
-		else
-			setsval(w, str);
-	}
-	else
-		mkfld(record, *FS, field);
-	c_free(u);
-	c_free(v);
-	c_free(w);
-  }
-  else
-	i = 0;
-  return mktmp(NUM, NULL, (double) i);
-}
-
-static CELL *
-Cond(p) NODE *p;
-{
-  CELL *u, *v;
-  double x, y;
-  int op, i, j;
-  char *s;
-  int save = pateval;
-
-  op = (int) p->n_arg[0];
-  u = execute(p->n_arg[1]);
-  x = getfval(u);
-/*
-printf("Cond(%d)(%s)\n", u->c_type, u->c_sval);
-*/
-  if (op == AND || op == OR || op == NOT) {
-	if (u->c_type & NUM)
-		i = (x != 0.0);
-	else {
-		s = getsval(u);
-		i = (s != (char *)NULL) && (*s != '\0');
-	}
-  }
-  if (op == AND && !i) {
-	c_free(u);
-	return &falsecell;
-  }
-  if (op == OR && i) {
-	c_free(u);
-	return &truecell;
-  }
-  if (op == NOT)
-	i = i == 0 ? 1 : 0;
-  else {
-	if (op == MATCH || op == NOMATCH)
-		pateval = 0;
-	v = execute(p->n_arg[2]);
-	y = getfval(v);
-	if (op == AND || op == OR || op == BINAND || op == BINOR) {
-		if (v->c_type & NUM)
-			j = (y != 0.0);
-		else {
-			s = getsval(v);
-			j = (s != (char *)NULL) && (*s != '\0');
-		}
-		switch (op) {
-		case AND:	i = i && j; break;
-		case OR:	i = i || j; break;
-		case BINAND:	i = i & j; break;
-		case BINOR:	i = i | j; break;
-		}
-	}
-	else if (op == MATCH || op == NOMATCH) {
-		char *s;
-		regexp *pat, *getpat();
-
-		s = getsval(u);
-		pat = getpat(v);
-		i = match(pat, s) == 0 ? 0 : 1;
-		if (op == NOMATCH)
-			i = i == 0 ? 1 : 0;
-	}
-	else {	/* relative operator */
-/*
-printf("Cond(%d)(%d)(%s)(%s)\n", u->c_type, v->c_type, u->c_sval, v->c_sval);
-*/
-		if ((u->c_type & NUM) && (v->c_type & NUM))
-			i = x < y ? -1 : (x > y ? 1 : 0);
-		else
-			i = strcmp(getsval(u), getsval(v));
-/*
-printf("Cond(%d)(%d)(%g)(%g)(%d)\n", u->c_type, v->c_type, x, y, i);
-*/
-
-		switch (op) {
-		case LT:	i = i < 0 ? 1 : 0; break;
-		case LE:	i = i <= 0 ? 1 : 0; break;
-		case EQ:	i = i == 0 ? 1 : 0; break;
-		case NE:	i = i != 0 ? 1 : 0; break;
-		case GT:	i = i > 0 ? 1 : 0; break;
-		case GE:	i = i >= 0 ? 1 : 0; break;
-		default:
-			fprintf(stderr, "unknown relative operator (%d)\n", op);
-			break;
-		}
-	}
-	c_free(v);
-  }
-  c_free(u);
-  pateval = save;
-  return mktmp(NUM, NULL, (double) i);
-}
-
-static CELL *
-If(p) NODE *p;
-{
-  CELL *u;
-  int i;
-  char *s;
-
-  u = execute(p->n_arg[0]);
-  if (u->c_type & NUM)
-	i = (getfval(u) != 0.0);
-  else {
-	s = getsval(u);
-	i = (s != (char *)NULL) && (*s != '\0');
-  }
-  c_free(u);
-  if (i)
-	u = execute(p->n_arg[1]);
-  else if (p->n_arg[2])
-	u = execute(p->n_arg[2]);
-  else
-	u = &truecell;
-  return u;
-}
-
-static CELL *
-While(p) NODE *p;
-{
-  CELL *u;
-  double x;
-
-  for (;;) {
-	u = execute(p->n_arg[0]);
-	x = getfval(u);
-	if (x == 0.0)
-		break;
-	c_free(u);
-	u = execute(p->n_arg[1]);
-	switch (u->c_type) {
-	case BRK:
-		goto rtn;
-	case NXT: case EXT: case RTN:
-		return u;
-	}
-	c_free(u);
-  }
-rtn:
-  c_free(u);
-  return &truecell;
-}
-
-static CELL *
-Do(p) NODE *p;
-{
-  CELL *u;
-  double x;
-
-  for (;;) {
-	u = execute(p->n_arg[0]);
-	switch (u->c_type) {
-	case BRK:
-		goto rtn;
-	case NXT: case EXT: case RTN:
-		return u;
-	}
-	c_free(u);
-	u = execute(p->n_arg[1]);
-	if(getfval(u) == 0.0)
-		break;
-	c_free(u);
-  }
-rtn:
-  c_free(u);
-  return &truecell;
-}
-
-static CELL *
-For(p) NODE *p;
-{
-  CELL *u;
-  double x;
-
-  if (p->n_arg[0] != NULL) {
-	u = execute(p->n_arg[0]);
-	c_free(u);
-  }
-  for (;;) {
-	if (p->n_arg[1] != NULL) {
-		u = execute(p->n_arg[1]);
-		x = getfval(u);
-		c_free(u);
-		if (x == 0.0)
-			break;
-	}
-	u = execute(p->n_arg[3]);
-	switch (u->c_type) {
-	case BRK:
-		c_free(u);
-		goto rtn;
-	case NXT: case EXT: case RTN:
-		return u;
-	}
-	if (p->n_arg[2] != NULL) {
-		u = execute(p->n_arg[2]);
-		c_free(u);
-	}
-  }
-rtn:
-  return &truecell;
-}
-
-static CELL *
-Jump(p) NODE *p;
-{
-  CELL *u;
-  int i;
-
-  switch ((int) p->n_arg[0]) {
-  case BREAK:	u = &breakcell; break;
-  case CONTIN:	u = &contcell;  break;
-  case EXIT:
-	if ((int) p->n_arg[1]) {
-		u = execute(p->n_arg[1]);
-		i = (int) getfval(u);
-	}
-	else
-		i = 0;
-	closeall();
-	exit(i);
-  case RETURN:
-	Return(p);
-	u = &retcell;
-	break;
-  case NEXT:	u = &nextcell; break;
-  }
-  return u;
-}
-
-static
-Return(p) NODE *p;
-{
-  CELL *u;
-  int i;
-  char *s, str[BUFSIZ];
-
-  c_free(retval);
-  if (p->n_arg[1] != NULL) {
-	if (p->n_arg[2] == NULL) {
-/*
-if (0) {
-*/
-		u = execute(p->n_arg[1]);
-		if (u->c_type == UDF)
-			retval = mktmp(STR, "", 0.0);
-		else
-			retval = mktmp(u->c_type, u->c_sval, u->c_fval);
-		c_free(u);
-	}
-	else {
-		for (i = 1; p->n_arg[i] != NULL; i++) {
-			if (i == 1)
-				*str = '\0';
-			else
-				strcat(str, *OFS);
-			u = execute(p->n_arg[i]);
-			s = getsval(u);
-			strcat(str, s);
-			c_free(u);
-		}
-/*
-printf("Ret(%s)(%d)\n", str, isnum(str));
-*/
-		if (isnum(str))
-			retval = mktmp(STR|NUM, str, atof(str));
-		else
-			retval = mktmp(STR, str, 0.0);
-	}
-  }
-  else
-	retval = &truecell;
-}
-
-#define MAXFRAME	100
-CELL **frame[MAXFRAME];
-static int framep;
-
-static CELL *
-Arg(p) NODE *p;
-{
-  CELL *u;
-  int i;
-
-  u = (CELL *)p->n_arg[0];
-  return _Arg((int)u->c_fval);
-}
-
-CELL *
-_Arg(i)
-{
-/*
-printf("Arg(%d)\n", i);
-*/
-  return frame[framep - 1][i];
-}
-
-static CELL *
-Call(p) NODE *p;
-{
-  CELL *u, *v, *r, **arg;
-  NODE *q;
-  int i, j, k, n;
-  char *emalloc();
-
-  if (framep >= MAXFRAME - 2)
-	error("stack frame overflow", (char *)0);
-  retval = &truecell;
-  r = (CELL *) p->n_arg[0];
-  if (r->c_type != FUN)
-	synerr("called function is not declared", (char *)0);
-  n = (int) r->c_fval;	/* # of params */
-  if (n > 0) {
-	arg = (CELL **) emalloc(sizeof(u) * n);
-	for (i = 2, j = 0, k = (int) p->n_arg[1]; j < k; i++) {
-		u = execute(p->n_arg[i]);
-/*
-printf("pass, j(%d)typ(%d)\n", j, u->c_type);
-*/
-		if (u->c_type & ARR)
-			v = u;	/* pass by reference */
-		else {	/* pass by value */
-			v = mkcell(UDF, u->c_sval, u->c_fval);
-			if (u->c_type != UDF) {
-#if 0
-				v->c_type = u->c_type;
-				if (v->c_type & (NUM|STR))
-					v->c_type |= VAR;
-				v->c_type &= ~TMP;	/* dont't free */
-#else
-				v->c_type |= (u->c_type & (NUM|STR))|VAR;
-				/*v->c_type &= ~TMP;*/
-#endif
-				/* Don't free original */
-			}
-/*
-printf("pass1, j(%d)typ(%d)\n", j, v->c_type);
-*/
-		}
-		arg[j++] = v;
-	}
-	for ( ; j < n; )	/* local var */
-		arg[j++] = mkcell(UDF, NULL, 0.0);
-  }
-  else
-	arg = NULL;
-
-  frame[framep] = arg;
-  framep++;
-
-  r = execute(r->c_sval);
-  c_free(r);
-  framep--;
-  if (n > 0) {
-	for (j = n - 1 ; j > k; j--) {	/* local var */
-		u = arg[j];
-		if (u->c_type & ARR)
-			a_free(u);
-		else
-			c_free(u);
-	}
-	for ( ; j >= 0; j--) {
-		u = arg[j];
-		if (!(u->c_type & ARR)) {
-/*			c_free(u);*/
-			sfree(u->c_sval);
-			sfree(u);
-		}
-		else {
-			v = execute(p->n_arg[j + 2]);
-			if (v->c_type == UDF) {	/* copy back */
-/*
-printf("copy_back_UDF(%d)(%d)\n", j, u->c_type);
-*/
-				v->c_type = u->c_type;
-				sfree(v->c_sval);
-				v->c_sval = u->c_sval;
-				v->c_fval = u->c_fval;
-				sfree(u);
-			}
-		}
-	}
-  }
-  sfree(arg);
-/*  return retval;*/
-  u = mktmp(retval->c_type, retval->c_sval, retval->c_fval);
-  return u;
-}
-
-CELL *Nulproc()
-{
-  return &truecell;
-}
-
-CELL *
-Usrfun(p) NODE *p;
-{
-  CELL *u;
-
-  u = execute(p);
-  return u;
-}
Index: trunk/minix/commands/awk/k.c
===================================================================
--- trunk/minix/commands/awk/k.c	(revision 9)
+++ 	(revision )
@@ -1,43 +1,0 @@
-/*
- * a small awk clone
- *
- * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
- *
- * Absolutely no warranty. Use this software with your own risk.
- *
- * Permission to use, copy, modify and distribute this software for any
- * purpose and without fee is hereby granted, provided that the above
- * copyright and disclaimer notice.
- *
- * This program was written to fit into 64K+64K memory of the Minix 1.2.
- */
-
-
-#include <stdio.h>
-
-isKanji(c)
-{
-  c &= 0xff;
-  return (c > 0x80 && c < 0xa0 || c > 0xdf && c < 0xfd);
-}
-
-jstrlen(s) char *s;
-{
-  int i;
-
-  for (i = 0; *s; i++, s++)
-	if (isKanji(*s))
-		s++;
-  return i;
-}
-
-char *
-jStrchr(s, c) char *s;
-{
-  for ( ; *s; s++)
-	if (isKanji(*s))
-		s++;
-	else if (*s == c)
-		return s;
-  return NULL;
-}
Index: trunk/minix/commands/awk/l.c
===================================================================
--- trunk/minix/commands/awk/l.c	(revision 9)
+++ 	(revision )
@@ -1,333 +1,0 @@
-/*
- * a small awk clone
- *
- * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
- *
- * Absolutely no warranty. Use this software with your own risk.
- *
- * Permission to use, copy, modify and distribute this software for any
- * purpose and without fee is hereby granted, provided that the above
- * copyright and disclaimer notice.
- *
- * This program was written to fit into 64K+64K memory of the Minix 1.2.
- */
-
-
-#include <stdio.h>
-#include <ctype.h>
-#include "awk.h"
-
-extern char *srcprg;	/* inline program */
-extern FILE *pfp;	/* program file */
-
-int sym;	/* lexical token */
-int sym1;	/* auxiliary lexical token */
-int regexflg;	/* set by parser (y.c) to indicate parsing REGEXPR */
-int funflg;	/* set by parser (y.c) to indicate parsing FUNCTION */
-int printflg;	/* set by parser (y.c) to indicate parsing PRINT */
-int getlineflg;	/* set by parser (y.c) to indicate parsing GETLINE */
-char text[BUFSIZ];	/* lexical word */
-char line[BUFSIZ];	/* program line for error message (ring buffer) */
-char *linep = line;	/* line pointer */
-char funnam[128];	/* function name for error message */
-int lineno = 1;
-
-lex()
-{
-  int c, d;
-  char *s;
-
-  if (regexflg)
-	return sym = scanreg();
-next:
-  while ((c = Getc()) == ' ' || c == '\t')
-	;
-  while (c == '#')
-	for (c = Getc(); c != '\n'; c = Getc())
-		;
-  switch (c) {
-  case '\\':
-	if ((c = Getc()) == '\n') {
-		lineno++;
-		goto next;
-	}
-	break;
-  case '\n':
-	lineno++;
-	break;
-  }
-  switch (c) {
-  case EOF:	return sym = 0;
-  case '+':	return sym = follow2('=', '+', ADDEQ, INC, ADD);
-  case '-':	return sym = follow2('=', '-', SUBEQ, DEC, SUB);
-  case '*':	return sym = follow('=', MULTEQ, MULT);
-  case '/':	return sym = follow('=', DIVEQ, DIV);
-  case '%':	return sym = follow('=', MODEQ, MOD);
-  case '^':	return sym = follow('=', POWEQ, POWER);
-  case '=':	return sym = follow('=', EQ, ASSIGN);
-  case '!':	return sym = follow2('=', '~', NE, NOMATCH, NOT);
-  case '&':	return sym = follow('&', AND, BINAND);
-  case '|':	sym = follow('|', OR, BINOR);
-		if (printflg && sym == BINOR)
-			sym = R_POUT;
-		return sym;
-  case '<':	sym = follow2('=', '<', LE, SHIFTL, LT);
-		if (getlineflg && sym == LT)
-			sym = R_IN;
-		return sym;
-  case '>':	sym = follow2('=', '>', GE, SHIFTR, GT);
-		if (printflg) {
-			switch (sym) {
-			case GT: sym = R_OUT; break;
-			case SHIFTR: sym = R_APD; break;
-			}
-		}
-		return sym;
-  case '~':	return sym = MATCH; break;
-  case ';': case '\n':	return sym = EOL;
-  }
-  if (isalpha(c) || c == '_') {
-	for (s = text; isalnum(c) || c == '_'; ) {
-		*s++ = c; c = Getc();
-	}
-	Ungetc(c);
-	*s = '\0';
-	if ((d = iskeywd(text)) == 0 &&
-		(d = isbuiltin(text, &sym1)) == 0) {
-			if (c == '(')
-				return sym = CALL;
-			else if (funflg) {
-				if ((sym1 = isarg(text)) != -1)
-					return sym = ARG;
-			}
-	}
-	return sym = d ? d : IDENT;
-  }
-  else if (c == '.' || (isdigit(c))) {
-	Ungetc(c);
-	return sym = scannum(text);	/* NUMBER */
-  }
-  else if (c == '"')
-	return sym = scanstr(text);	/* STRING */
-  return sym = c;
-}
-
-static
-follow(c1, r1, r2)
-{
-  register int c;
-
-  if ((c = Getc()) == c1)
-	return r1;
-  else {
-	Ungetc(c);
-	return r2;
-  }
-}
-
-static
-follow2(c1, c2, r1, r2, r3)
-{
-  register int c;
-
-  if ((c = Getc()) == c1)
-	return r1;
-  else if (c == c2)
-	return r2;
-  else {
-	Ungetc(c);
-	return r3;
-  }
-}
-
-static
-iskeywd(s) char *s;
-{
-  static struct { char *kw; int token; } tab[] = {
-	"BEGIN", BEGIN,
-	"END", END,
-	"break", BREAK,
-	"continue", CONTIN,
-	"delete", DELETE,
-	"do", DO,
-	"else", ELSE,
-	"exit", EXIT,
-	"for", FOR,
-	"func", FUNC,
-	"function", FUNC,
-	"getline", GETLINE,
-	"if", IF,
-	"in", IN,
-	"next", NEXT,
-	"print", PRINT,
-	"printf", PRINTF,
-	"return", RETURN,
-	"sprint", SPRINT,
-	"sprintf", SPRINTF,
-	"while", WHILE,
-	"", 0, 0
-  };
-  register int i;
-
-  for (i = 0; tab[i].token; i++)
-	if (strcmp(tab[i].kw, s) == 0)
-		break;
-  return tab[i].token;
-}
-
-static
-isbuiltin(s, p) char *s; int *p;
-{
-  static struct { char *kw; int type; int token; } tab[] = {
-	"atan2", MATHFUN, ATAN2,
-	"close", STRFUN, CLOSE,
-	"cos", MATHFUN, COS,
-	"exp", MATHFUN, EXP,
-	"gsub", SUBST, RGSUB,
-	"index", STRFUN, INDEX,
-	"int", MATHFUN, INT,
-	"length", STRFUN, LENGTH,
-	"log", MATHFUN, LOG,
-	"match", STRFUN, RMATCH,
-	"sin", MATHFUN, SIN,
-	"sqrt", MATHFUN, SQRT,
-	"rand", MATHFUN, RAND,
-	"srand", MATHFUN, SRAND,
-	"split", STRFUN, SPLIT,
-	"sub", SUBST, RSUB,
-	"substr", STRFUN, SUBSTR,
-	"system", STRFUN, SYSTEM,
-	"", 0, 0
-  };
-  register int i;
-
-  for (i = 0; tab[i].token; i++)
-	if (strcmp(tab[i].kw, s) == 0)
-		break;
-  *p = tab[i].token;
-  return tab[i].type;
-}
-
-static
-scannum(s) char *s;
-{
-  register int c;
-  char *strchr();
-
-  if ((c = Getc()) && strchr("+-", c) != NULL) {
-	*s++ = c; c = Getc();
-  }
-  while (isdigit(c)) {
-	*s++ = c; c = Getc();
-  }
-  if (c == '.') {
-	*s++ = c; c = Getc();
-	while (isdigit(c)) {
-		*s++ = c; c = Getc();
-	}
-  }
-  if (c && strchr("eE", c) != NULL) {
-	*s++ = c; c = Getc();
-	if (c && strchr("+-", c) != NULL) {
-		*s++ = c; c = Getc();
-	}
-	while (isdigit(c)) {
-		*s++ = c; c = Getc();
-	}
-  }
-  *s = '\0';
-  Ungetc(c);
-  return NUMBER;
-}
-
-static
-scanstr(s) char *s;
-{
-  register int c, i, j;
-
-  for (c = Getc(); c != EOF & c != '"'; ) {
-	if (c == '\\') {
-		switch (c = Getc()) {
-		case 'b': c = '\b'; break;
-		case 'f': c = '\f'; break;
-		case 'n': c = '\n'; break;
-		case 'r': c = '\r'; break;
-		case 't': c = '\t'; break;
-		default:
-		if (isdigit(c)) {
-			for (i = j = 0; i < 3 && isdigit(c); c = Getc(), i++)
-				j = j * 8 + c - '0';
-			Ungetc(c);
-			c = j;
-		}
-		break;
-		}
-	}
-	*s++ = c;
-	if (isKanji(c))
-		*s++ = Getc();
-	c = Getc();
-  }
-  *s = '\0';
-  return STRING;
-}
-
-static
-scanreg()
-{
-  register int c;
-  register char *s;
-
-  for (s = text; (c = Getc()) != '/'; )
-	if (c == '\n')
-		error("newline in regular expression");
-	else {
-		if (isKanji(c) || c == '\\') {
-			*s++ = c; c = Getc();
-		}
-		*s++ = c;
-	}
-  *s = '\0';
-  return REGEXP;
-}
-
-static int c0;
-
-Ungetc(c)
-{
-  c0 = c;
-
-  if (linep > line) {
-	if (--linep < line)
-		linep == line + BUFSIZ - 1;
-  }
-}
-
-Getc()
-{
-  register int c;
-  char *s, *t;
-
-  if (c0) {
-	c = c0; c0 = 0;
-  }	
-  else if (srcprg)
-	c = *srcprg ? *srcprg++ : EOF;
-  else
-	c = fgetc(pfp);
-
-#if 0
-  if (linep - line == BUFSIZ) {
-printf("!!!\n");
-	for (s = line; *s != '\n' && ((s - line) <BUFSIZ); s++)
-		;
-printf("***(%d)***\n", *s);
-	for (t = line; s < linep; )
-		*t++ = *++s;
-  }
-#endif
-  *linep++ = c;
-  if ((linep - line) == BUFSIZ)
-	linep = line;
-  return c;
-}
Index: trunk/minix/commands/awk/m.c
===================================================================
--- trunk/minix/commands/awk/m.c	(revision 9)
+++ 	(revision )
@@ -1,141 +1,0 @@
-/*
- * a small awk clone
- *
- * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
- *
- * Absolutely no warranty. Use this software with your own risk.
- *
- * Permission to use, copy, modify and distribute this software for any
- * purpose and without fee is hereby granted, provided that the above
- * copyright and disclaimer notice.
- *
- * This program was written to fit into 64K+64K memory of the Minix 1.2.
- */
-
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <signal.h>
-#include "awk.h"
-
-extern char **FS, **FILENAME;
-extern char record[];
-extern FILE *ifp;
-
-NODE *parse();
-CELL *execute();
-FILE *efopen(), *fopen();
-char *strsave();
-
-int xargc;
-char **xargv;
-char *srcprg;
-FILE *pfp;
-char *cmd;
-#if 0
-int iflg;	/* interactive mode */
-#endif
-
-main(argc, argv) char **argv;
-{
-  char *s, *strpbrk(), *strchr();
-  void onint();
-
-#ifdef DOS
-  _sharg(&argc, &argv);
-#endif
-  signal(SIGINT, onint);
-  signal(SIGFPE, onint);
-  cmd = argv[0];
-  init();
-  while (--argc > 0 && (*++argv)[0] == '-')
-	for (s = argv[0]+1; *s; s++)
-		if (strcmp(argv[0], "-") == 0)
-			break;
-		else
-		switch (*s) {
-#if 0
-		case 'i':
-			iflg++;
-			pfp = stdin;
-			interactive();
-			/* no return */
-#endif
-		case 'F':
-			*FS = ++s;
-			break;
-		case 'f':
-			if (*(s+1))
-				s++;
-			else {
-				argc--; s = *++argv;
-			}
-			pfp = efopen(s, "r");
-			s += strlen(s) - 1;
-			break;
-		}
-  xargc = argc; xargv = argv;
-  if (pfp == NULL && xargc > 0) {
-	srcprg = *xargv++; xargc--;
-  }
-/*
-  if (pfp == NULL && xargc > 0) {
-	if (strpbrk(xargv[0], " !$^()={}[];<>,/~") != NULL) {
-		sprintf(record, "%s\n", xargv[0]);
-		srcprg = strsave(record);
-	}
-	else {
-		sprintf(record, "%s.awk", xargv[0]);
-		if ((pfp = fopen(record, "r")) == NULL)
-			error("can't open %s", record);
-	}
-	xargc--; xargv++;
-  }
-*/
-
-  while (*xargv != NULL && strchr(*xargv, '=') != NULL) {
-	setvar(*xargv++);
-	xargc--;
-  }
-
-  initarg(cmd, xargc, xargv);
-  if (xargc == 0) {
-	ifp = stdin; *FILENAME = "-";
-  }
-  parse();
-  closeall();
-  exit(0);
-}
-
-FILE *
-efopen(file, mode) char *file, *mode;
-{
-  FILE *fp, *fopen();
-
-  if ((fp = fopen(file, mode)) == NULL)
-	error("cannot open %s", file);
-  return fp;
-}
-
-error(s, t) char *s, *t;
-{
-  extern double *NR;
-
-  fprintf(stderr, "awk: ");
-  fprintf(stderr, s, t);
-  fprintf(stderr, "\n");
-  if (NR != NULL) {
-	fprintf(stderr, "record number %g\n", *NR);
-  }
-#ifdef DOS
-  closeall();
-#endif
-  exit(1);
-}
-
-void
-onint(i)
-{
-  closeall();
-  exit(0x80 | i);
-}
Index: trunk/minix/commands/awk/n.c
===================================================================
--- trunk/minix/commands/awk/n.c	(revision 9)
+++ 	(revision )
@@ -1,149 +1,0 @@
-/*
- * a small awk clone
- *
- * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
- *
- * Absolutely no warranty. Use this software with your own risk.
- *
- * Permission to use, copy, modify and distribute this software for any
- * purpose and without fee is hereby granted, provided that the above
- * copyright and disclaimer notice.
- *
- * This program was written to fit into 64K+64K memory of the Minix 1.2.
- */
-
-
-#include <stdio.h>
-#include "awk.h"
-
-NODE *
-node0(type)
-{
-  NODE *p;
-  char *emalloc();
-
-  p = (NODE *) emalloc(sizeof(*p) - sizeof(p));
-  p->n_type = type;
-  p->n_next = NULL;
-  return p;
-}
-
-NODE *
-node1(type, arg0) NODE *arg0;
-{
-  NODE *p;
-  char *emalloc();
-
-  p = (NODE *) emalloc(sizeof(*p));
-  p->n_type = type;
-  p->n_next = NULL;
-  p->n_arg[0] = (NODE *) arg0;
-  return p;
-}
-
-NODE *
-node2(type, arg0, arg1) NODE *arg0, *arg1;
-{
-  NODE *p;
-  char *emalloc();
-
-  p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * 1);
-  p->n_type = type;
-  p->n_next = NULL;
-  p->n_arg[0] = (NODE *) arg0;
-  p->n_arg[1] = (NODE *) arg1;
-  return p;
-}
-
-NODE *
-node3(type, arg0, arg1, arg2) NODE *arg0, *arg1, *arg2;
-{
-  NODE *p;
-  char *emalloc();
-
-  p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * 2);
-  p->n_type = type;
-  p->n_next = NULL;
-  p->n_arg[0] = (NODE *) arg0;
-  p->n_arg[1] = (NODE *) arg1;
-  p->n_arg[2] = (NODE *) arg2;
-  return p;
-}
-
-NODE *
-node4(type, arg0, arg1, arg2, arg3) NODE *arg0, *arg1, *arg2, *arg3;
-{
-  NODE *p;
-  char *emalloc();
-
-  p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * 3);
-  p->n_type = type;
-  p->n_next = NULL;
-  p->n_arg[0] = (NODE *) arg0;
-  p->n_arg[1] = (NODE *) arg1;
-  p->n_arg[2] = (NODE *) arg2;
-  p->n_arg[3] = (NODE *) arg3;
-  return p;
-}
-
-CELL *
-mkcell(type, sval, fval) char *sval; double fval;
-{
-  CELL *p;
-  char *emalloc(), *strsave();
-
-  p = (CELL *) emalloc(sizeof(*p));
-  p->c_type = type;
-  if (sval == NULL)
-	p->c_sval = NULL;
-  else
-	p->c_sval = strsave(sval);
-  p->c_fval = fval;
-  return p;
-}
-
-#ifdef TMPCELL
-#define MAXTMP	25
-
-CELL tmpcell[MAXTMP];
-#endif
-
-CELL *
-mktmp(type, sval, fval) char *sval; double fval;
-{
-  register int i;
-  char *strsave();
-
-#ifdef TMPCELL
-  for (i = 0; i < MAXTMP; i++)
-	if (tmpcell[i].c_type == 0) {
-		tmpcell[i].c_type = type | TMP;
-		tmpcell[i].c_sval = strsave(sval);
-		tmpcell[i].c_fval = fval;
-		return &tmpcell[i];
-	}
-  error("formula too complex", (char *) 0);
-#else
-  return mkcell(type | TMP, sval, fval);
-#endif
-}
-
-c_free(p) CELL *p;
-{
-  if ((p != NULL) && (p->c_type & TMP)) {
-#ifdef TMPCELL
-	p->c_type = 0;
-	sfree(p->c_sval);
-	p->c_sval = (char *)NULL;
-	p->c_fval = 0.0;
-#else
-	if (p->c_sval != NULL) {
-		Free(p->c_sval);
-		p->c_sval = NULL;
-	}
-	p->c_type = 0;
-	Free(p);
-	p = NULL;
-#endif
-  }
-}
Index: trunk/minix/commands/awk/r.c
===================================================================
--- trunk/minix/commands/awk/r.c	(revision 9)
+++ 	(revision )
@@ -1,627 +1,0 @@
-/*
- * a small awk clone
- *
- * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
- *
- * Absolutely no warranty. Use this software with your own risk.
- *
- * Permission to use, copy, modify and distribute this software for any
- * purpose and without fee is hereby granted, provided that the above
- * copyright and disclaimer notice.
- *
- * This program was written to fit into 64K+64K memory of the Minix 1.2.
- */
-
-
-#include <stdio.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#ifdef DOS
-#include <process.h>
-#endif
-#include "awk.h"
-#include "regexp.h"
-
-#define MAXFLD	100
-
-extern char **FS, **RS, **OFS, **ORS, **FILENAME;
-extern double *NF, *NR;
-extern double *FNR;
-extern double *ARGC;
-extern SYMBOL *argtab[];
-extern CELL *getvar();
-
-char *strsave(), *strcpy(), *getsval(), *jStrchr(), *strchr();
-double getfval(), atof();
-CELL *mkcell(), *mktmp(), *execute(), *patexec();
-FILE *efopen();
-
-extern CELL truecell, falsecell;
-
-extern int pateval;
-
-int infileno = 1;
-FILE *ifp;
-char record[BUFSIZ];
-CELL *field[MAXFLD];
-
-char *fs_str;
-regexp *fs_pat;
-
-CELL *
-Getline(p) NODE *p;
-{
-  CELL *u;
-  char *fnam, *s, str[BUFSIZ];
-  int i;
-  FILE *fp, *getfp();
-
-  if ((int) p->n_arg[0])	/* read into var */
-	s = str;
-  else
-	s = NULL;
-  if ((int) p->n_arg[1]) {	/* file name */
-	u = execute(p->n_arg[1]);
-	fnam = getsval(u);
-	fp = getfp(fnam, (int) p->n_arg[2]);
-	c_free(u);
-	i = get1rec(s, fp);
-  }
-  else
-	i = Getrec(s);
-  if (s == str) {
-	u = execute(p->n_arg[0]);
-	setsval(u, str);
-  }
-  return mktmp(NUM, NULL, (double) i);
-}
-
-static
-get1rec(buf, fp) char *buf; FILE *fp;
-{
-  register int c;
-  register char rs, *s;
-  int mflg;
-
-  if (buf == NULL)
-	buf = record;
-  if ((rs = **RS) == '\0') {	/* multi line record */
-	mflg = 1;
-	rs = '\n';
-  }
-  else
-	mflg = 0;
-
-  if (feof(fp) || (c = getc(fp)) == EOF)
-	return 0;
-  for (s = buf; ; ) {
-	for ( ; c != rs && c != EOF; c = getc(fp)) {
-		if (isKanji(c)) {
-			*s++ = c; c = getc(fp);
-		}
-		*s++ = c;
-	}
-	if (mflg) {
-		if ((c = getc(fp)) == '\n' || c == EOF)
-			break;
-		*s++ = '\n';
-	}
-	else
-		break;
-  }
-  *s = '\0';
-#if 1
-  if (buf == record) {
-#else
-  if (buf == record && c != EOF) {
-#endif
-	mkfld(record, *FS, field);
-	(*NR)++;
-	(*FNR)++;
-  }
-  return s > buf || c != EOF ? 1 : 0;
-}
-
-Getrec(s) char *s;
-{
-  CELL *u;
-  char *file, str[8];
-
-  while (ifp == stdin || infileno < (int)*ARGC) {
-	if (ifp == NULL) {
-		*FNR = 0.0;
-		if (infileno == (int)*ARGC)
-			break;
-		sprintf(str, "%d", infileno);
-		u = getvar(str, argtab);
-		file = getsval(u);
-		if (strchr(file, '=') != NULL) {
-			setvar(file);
-			infileno++;
-			continue;
-		}
-		else if (strcmp(file, "") == 0) {
-/*
-if (infileno == (int)*ARGC - 1)
-			ifp = stdin;
-*/
-			infileno++;
-			continue;
-		}
-		else {
-			if (strcmp(file, "-") == 0)
-				ifp = stdin;
-			else
-				ifp = efopen(file, "r");
-			*FILENAME = file;
-		}
-	}
-	if (get1rec(s, ifp))
-		return 1;
-	else {
-		if (ifp != stdin)
-			fclose(ifp);
-		ifp = NULL;
-		infileno++;
-	}
-  }
-  ifp = stdin;	/* for further "getline" */
-  *FILENAME = "-";
-  return 0;	/* EOF */
-}
-
-mkfld(rec, sep, fld) char *rec, *sep; CELL *fld[];
-{
-  char *s, *t;
-  char str[BUFSIZ];
-  int i, j, n;
-  int skip = 0;
-
-  if (strlen(sep) > 1)
-	return r_mkfld(rec, sep, fld);
-
-  if (*sep == ' ' || *sep == '\0') {
-	sep = " \t\n"; skip++;
-  }
-  for (i = 1, n = (int) *NF; i <= n; i++) {
-	sfree(fld[i]->c_sval);
-	sfree(fld[i]);
-	fld[i] = NULL;
-  }
-  for (i = 0, s = rec; ; ) {
-	t = str;
-	if (skip) {
-		while (*s && strchr(" \t\n", *s))
-			s++;
-		if (*s == '\0')
-			break;
-	}
-	while (*s && !jStrchr(sep, *s)) {
-		if (isKanji(*s))
-			*t++ = *s++;
-		*t++ = *s++;
-	}
-	*t = '\0';
-	if (isnum(str))
-		fld[++i] =  mkcell(FLD|STR|NUM, str, atof(str));
-	else
-		fld[++i] =  mkcell(FLD|STR, str, 0.0);
-	if (*s)
-		s++;
-	else
-		break;
-  }
-  *NF = (double) i;
-  return i;
-}
-
-static
-r_mkfld(rec, sep, fld) char *rec, *sep; CELL *fld[];
-{
-  char *s, *t;
-  char str[BUFSIZ];
-  int i, n;
-  regexp *mkpat();
-  extern int r_start, r_length;
-
-  if (strcmp(*FS, fs_str) != 0) {
-	sfree(fs_str); sfree(fs_pat);
-	fs_str = strsave(*FS);
-	fs_pat = mkpat(fs_str);
-  }
-  for (i = 1, n = (int) *NF; i <= n; i++) {
-	sfree(fld[i]->c_sval);
-	sfree(fld[i]);
-	fld[i] = NULL;
-  }
-  for (i = 0, s = rec, t = str; *s; ) {
-	if (match(fs_pat, s)) {
-		for (n = r_start; --n > 0; )
-			*t++ = *s++;
-	}
-	else {
-		while (*s)
-			*t++ = *s++;
-	}
-	*t = '\0';
-	t = str;
-	fld[++i] = mkcell(FLD|STR, str, 0.0);
-	if (*s)
-		s += r_length;
-  }
-  *NF = (double) i;
-  return i;
-}
-
-mkrec(u) CELL *u;
-{
-  register char *s, *t;
-  register int i, j;
-
-  for (j = (int)*NF, i = 1; i <= j; i++)
-	if (field[i] == u)
-		break;
-  if (i > j) {
-	for ( ; i < MAXFLD; i++)
-		if (field[i] == u)
-			break;
-	if (i == MAXFLD)
-		error("too many field (%d)", i);
-	*NF = (double)i;
-  }
-  for (t = record, i = 1, j = (int) *NF; i <= j; i++) {
-	if (i > 1)
-		*t++ = **OFS;
-	for (s = getsval(field[i]); *s; )
-		*t++ = *s++;
-  }
-  *t++ = '\0';
-}
-
-CELL *
-Field(p) NODE *p;
-{
-  CELL *u;
-  int i, j;
-
-  u = execute(p->n_arg[0]);
-  i = (int) getfval(u);
-  c_free(u);
-  j = (int)*NF;
-  if (i > j)
-	for (++j; j <= i; j++) {
-		if (field[j] == NULL)
-			field[j] = mkcell(FLD|STR, "", 0.0);
-	}
-  return field[i];
-}
-
-CELL *
-P1stat(p) NODE *p;
-{
-  CELL *u;
-  double x;
-
-  pateval++;
-  u = execute(p->n_arg[0]);
-  pateval = 0;
-  x = getfval(u);
-  c_free(u);
-  if (x != 0.0)
-	u = execute(p->n_arg[1]);
-  else
-	u = &truecell;
-  return u;
-}
-
-CELL *
-P2stat(p) NODE *p;
-{
-  static stat = 0;
-  CELL *u, *v;
-  double x;
-
-  switch (stat) {
-  case 0:
-	pateval++;
-	u = execute(p->n_arg[0]);
-	pateval = 0;
-	x = getfval(u);
-	c_free(u);
-	if (x == 0.0) {
-		u = &truecell; break;
-	}
-	else
-		stat++;
-	/* fall through */
-  case 1:
-	u = execute(p->n_arg[2]);
-	c_free(u);
-	pateval++;
-	u = execute(p->n_arg[1]);
-	pateval = 0;
-	x = getfval(u);
-	if (x != 0.0)
-		stat = 0;
-	break;
-  default:
-	u = &truecell;
-	break;
-  }
-  return u;
-}
-
-CELL *
-Print0()
-{
-/*
-  int i, j;
-  char *s, str[BUFSIZ];
-
-  for (*str = '\0', i = 1, j = (int) *NF; i <= j; i++) {
-	if (i > 1)
-		strcat(str, *OFS);
-	s = getsval(field[i]);
-	strcat(str, s);
-  }
-  strcat(str, *ORS);
-  fputs(str, stdout);
-*/
-  fprintf(stdout, "%s%s", record, *ORS);
-  return &truecell;
-}
-
-char *
-format(t, p) char *t; NODE *p;
-{
-  CELL *u, *v;
-  char *r, *s, *s0, fmt[BUFSIZ];
-  double x;
-  int i;
-
-  u = execute(p->n_arg[2]);
-  s = s0 = getsval(u);
-/*
-printf("fmt(%s)\n", s);
-*/
-  for (i = 3; *s; s++) {
-	if (isKanji(*s)) {
-		*t++ = *s++; *t++ = *s; continue;
-	}
-	if (*s != '%') {
-		*t++ = *s; continue;
-	}
-	else if (*(s + 1) == '%') {
-		*t++ = *s++; continue;
-	}
-	for (r = fmt, *r++ = *s++; *r++ = *s; s++) {
-		if (strchr("%cdefgosux", *s))
-			break;
-	}
-	*r = '\0';
-	if (p->n_arg[i] == NULL)
-		error("not enough args in printf(%s)", s0);
-	v = execute(p->n_arg[i++]);
-	if (*s == 's')
-		r = getsval(v);
-	else
-		x = getfval(v);
-/*
-printf("val(%d)(%s)\n", v->c_type, v->c_sval);
-*/
-	switch (*s) {
-	case 'c':
-		sprintf(t, fmt, (int) x);
-		break;
-	case 'd':
-		if (*(s - 1) != 'l') {
-			*--r = 'l'; *++r = 'd'; *++r = '\0';
-		}
-		sprintf(t, fmt, (long) x);
-		break;
-	case 'e': case 'f': case 'g':
-		sprintf(t, fmt, x);
-		break;
-	case 'o': case 'u': case 'x':
-		if (*(s - 1) == 'l')
-			sprintf(t, fmt, (long) x);
-		else
-			sprintf(t, fmt, (int) x);
-		break;
-	case 's':
-		/*r = getsval(v);*/
-		sprintf(t, fmt, r);
-		break;
-	default:
-		strcpy(t, fmt);
-		break;
-	}
-	c_free(v);
-	t += strlen(t);
-  }
-  c_free(u);
-  *t = '\0';
-}
-
-#define MAXFILE	10
-struct {
-  char *f_name;	/* file name */
-  FILE *f_fp;
-  int f_type;
-} filetab[MAXFILE];
-
-FILE *
-getfp(file, type) char *file;
-{
-  register int i;
-  register char *name, *mode;
-  char *awktmp();
-  FILE *fp, *efopen(), *epopen();
-
-  for (i = 0; i < MAXFILE; i++)
-	if (filetab[i].f_name && strcmp(filetab[i].f_name, file) == 0)
-		return filetab[i].f_fp;
-  for (i = 0; i < MAXFILE; i++)
-	if (!filetab[i].f_fp)
-		break;
-  if (i == MAXFILE)
-	error("too many files to open");
-  name = file;
-  switch (type) {
-  case R_OUT:	mode = "w"; break;
-  case R_APD:	mode = "a"; break;
-  case R_POUT:
-#ifdef DOS
-	name = awktmp(i); mode = "w";	/* MS-DOS */
-#else
-	fp = epopen(file, "w");
-	goto g1;
-#endif
-	break;
-  case R_IN:	mode = "r"; break;
-  case R_PIN:
-#ifdef DOS
-	{
-		int savefd, fd, result;
-
-		name = awktmp(i);
-		if ((fd = open(name,
-		O_WRONLY|O_TEXT|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE)) == -1)
-			error("can't open %s", name);
-		savefd = dup(1); dup2(fd, 1); close(fd);
-		if ((result =
-			system(file)) == -1)
-			error("can't exec %s", file);
-		dup2(savefd, 1); close(savefd); close(fd);
-		mode = "r";
-	}
-#else
-	fp = epopen(file,"r");
-	goto g1;
-#endif
-	break;
-  }
-  fp = efopen(name, mode);
-g1:
-  filetab[i].f_name = strsave(file);
-  filetab[i].f_type = type;
-  filetab[i].f_fp = fp;
-  return fp;
-}
-
-closeall()
-{
-  register int i;
-
-  for (i = 0; i < MAXFILE; i++)
-	close1(i);
-}
-
-CELL *
-Close(s) char *s;
-{
-  register int i;
-
-  for (i = 0; i < MAXFILE; i++)
-	if (strcmp(s, filetab[i].f_name) == 0) {
-		close1(i);
-		break;
-	}
-  i = (i == MAXFILE) ? 0 : 1;
-  return mktmp(NUM, NULL, (double) i);
-}
-
-static
-close1(i)
-{
-  int fd, result, savefd;
-  char *awktmp();
-
-  if (filetab[i].f_fp == NULL)
-	return;
-  switch (filetab[i].f_type) {
-  case R_PIN:
-#ifdef DOS
-	fclose(filetab[i].f_fp);
-	unlink(awktmp(i));
-#else
-	pclose(filetab[i].f_fp);
-#endif
-	break;
-  case R_IN: case R_OUT: case R_APD:
-	fclose(filetab[i].f_fp);
-	break;
-  case R_POUT:
-#ifdef DOS
-	fclose(filetab[i].f_fp);
-	if ((fd = open(awktmp(i), O_RDONLY)) == NULL)
-		error("can't open %s", awktmp(i));
-	savefd = dup(0);
-	dup2(fd, 0);
-	close(fd);
-	if ((result =
-		system(filetab[i].f_name)) == -1)
-/*
-	spawnl(P_WAIT, "/usr/bin/sh", "sh", "-c", filetab[i].f_name, (char *) 0)) == -1)
-		fprintf(stderr, "can't spawn /bin/sh\n");
-*/
-		error("can't exec %s", filetab[i].f_name);
-	dup2(savefd, 0);
-	close(savefd);
-	unlink(awktmp(i));
-#else
-	pclose(filetab[i].f_fp);
-#endif
-	break;
-  }
-  sfree(filetab[i].f_name);
-  filetab[i].f_type = 0;
-  filetab[i].f_name = NULL;
-  filetab[i].f_fp = NULL;
-}
-
-#ifndef DOS
-FILE *
-epopen(file, mod) char *file, *mod;
-{
-  FILE *fp, *popen();
-
-  if ((fp = popen(file, mod)) == NULL)
-	error("can't poen %s", file);
-  return fp;
-}
-#endif
-
-static char *
-awktmp(i)
-{
-  static char str[16];
-
-  sprintf(str, "awk000%02d.tmp", i);
-  return str;
-}
-
-Index(s, t) char *s, *t;
-{
-  register char *u, *v;
-  register int i;
-
-  for (i = 1; *s; s++, i++) {
-	for (u = s, v = t; *v; u++, v++) {
-		if (isKanji(*v)) {
-			if (*u != *v)
-				break;
-			u++; v++;
-		}
-		if (*u != *v)
-			break;
-	}
-	if (*v == '\0')
-		return i;
-	if (isKanji(*s))
-		s++;
-  }
-  return 0;
-}
Index: trunk/minix/commands/awk/regexp.c
===================================================================
--- trunk/minix/commands/awk/regexp.c	(revision 9)
+++ 	(revision )
@@ -1,1440 +1,0 @@
-/*
- * regcomp and regexec -- regsub and regerror are elsewhere
- *
- *	Copyright (c) 1986 by University of Toronto.
- *	Written by Henry Spencer.  Not derived from licensed software.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to redistribute it freely,
- *	subject to the following restrictions:
- *
- *	1. The author is not responsible for the consequences of use of
- *		this software, no matter how awful, even if they arise
- *		from defects in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *		by explicit claim or by omission.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *		be misrepresented as being the original software.
- *
- * Beware that some of this code is subtly aware of the way operator
- * precedence is structured in regular expressions.  Serious changes in
- * regular-expression syntax might require a total rethink.
- *
- *	Modified by K.Hirabayashi to accept KANJI code, memory allocation
- *	and to add following functions.
- *		isthere(), mkpat(), match(), regsub(), sjtok(), ktosj(),
- *		Strchr(), Strncmp(), Strlen()
- */
-
-#include <stdio.h>
-#include <ctype.h>
-#include "regexp.h"
-
-#define regerror(a)	error("regular expression error: %s", a)
-
-int r_start, r_length;
-
-/*
- * The first byte of the regexp internal "program" is actually this magic
- * number; the start node begins in the second byte.
- */
-#define	MAGIC	0234
-
-/*
- * The "internal use only" fields in regexp.h are present to pass info from
- * compile to execute that permits the execute phase to run lots faster on
- * simple cases.  They are:
- *
- * regstart	char that must begin a match; '\0' if none obvious
- * reganch	is the match anchored (at beginning-of-line only)?
- * regmust	string (pointer into program) that match must include, or NULL
- * regmlen	length of regmust string
- *
- * Regstart and reganch permit very fast decisions on suitable starting points
- * for a match, cutting down the work a lot.  Regmust permits fast rejection
- * of lines that cannot possibly match.  The regmust tests are costly enough
- * that regcomp() supplies a regmust only if the r.e. contains something
- * potentially expensive (at present, the only such thing detected is * or +
- * at the start of the r.e., which can involve a lot of backup).  Regmlen is
- * supplied because the test in regexec() needs it and regcomp() is computing
- * it anyway.
- */
-
-/*
- * Structure for regexp "program".  This is essentially a linear encoding
- * of a nondeterministic finite-state machine (aka syntax charts or
- * "railroad normal form" in parsing technology).  Each node is an opcode
- * plus a "next" pointer, possibly plus an operand.  "Next" pointers of
- * all nodes except BRANCH implement concatenation; a "next" pointer with
- * a BRANCH on both ends of it is connecting two alternatives.  (Here we
- * have one of the subtle syntax dependencies:  an individual BRANCH (as
- * opposed to a collection of them) is never concatenated with anything
- * because of operator precedence.)  The operand of some types of node is
- * a literal string; for others, it is a node leading into a sub-FSM.  In
- * particular, the operand of a BRANCH node is the first node of the branch.
- * (NB this is *not* a tree structure:  the tail of the branch connects
- * to the thing following the set of BRANCHes.)  The opcodes are:
- */
-
-/* definition	number	opnd?	meaning */
-#define	END	0	/* no	End of program. */
-#define	BOL	1	/* no	Match "" at beginning of line. */
-#define	EOL	2	/* no	Match "" at end of line. */
-#define	ANY	3	/* no	Match any one character. */
-#define	ANYOF	4	/* str	Match any character in this string. */
-#define	ANYBUT	5	/* str	Match any character not in this string. */
-#define	BRANCH	6	/* node	Match this alternative, or the next... */
-#define	BACK	7	/* no	Match "", "next" ptr points backward. */
-#define	EXACTLY	8	/* str	Match this string. */
-#define	NOTHING	9	/* no	Match empty string. */
-#define	STAR	10	/* node	Match this (simple) thing 0 or more times. */
-#define	PLUS	11	/* node	Match this (simple) thing 1 or more times. */
-#define	OPEN	20	/* no	Mark this point in input as start of #n. */
-		/*	OPEN+1 is number 1, etc. */
-#define	CLOSE	30	/* no	Analogous to OPEN. */
-
-/*
- * Opcode notes:
- *
- * BRANCH	The set of branches constituting a single choice are hooked
- *		together with their "next" pointers, since precedence prevents
- *		anything being concatenated to any individual branch.  The
- *		"next" pointer of the last BRANCH in a choice points to the
- *		thing following the whole choice.  This is also where the
- *		final "next" pointer of each individual branch points; each
- *		branch starts with the operand node of a BRANCH node.
- *
- * BACK		Normal "next" pointers all implicitly point forward; BACK
- *		exists to make loop structures possible.
- *
- * STAR,PLUS	'?', and complex '*' and '+', are implemented as circular
- *		BRANCH structures using BACK.  Simple cases (one character
- *		per match) are implemented with STAR and PLUS for speed
- *		and to minimize recursive plunges.
- *
- * OPEN,CLOSE	...are numbered at compile time.
- */
-
-/*
- * A node is one char of opcode followed by two chars of "next" pointer.
- * "Next" pointers are stored as two 8-bit pieces, high order first.  The
- * value is a positive offset from the opcode of the node containing it.
- * An operand, if any, simply follows the node.  (Note that much of the
- * code generation knows about this implicit relationship.)
- *
- * Using two bytes for the "next" pointer is vast overkill for most things,
- * but allows patterns to get big without disasters.
- */
-#define	OP(p)	(*(p))
-#define	NEXT(p)	(((*((p)+1)&0377)<<8) + *((p)+2)&0377)
-#define	OPERAND(p)	((p) + 3)
-
-
-
-/*
- * Utility definitions.
- */
-#ifndef CHARBITS
-#define	UCHARAT(p)	((int)*(ushort *)(p))
-#else
-#define	UCHARAT(p)	((int)*(p)&CHARBITS)
-#endif
-
-#define	FAIL(m)	{ regerror(m); return(NULL); }
-#define	ISMULT(c)	((c) == '*' || (c) == '+' || (c) == '?')
-#define	META	"^$.[()|?+*\\"
-
-/*
- * Flags to be passed up and down.
- */
-#define	HASWIDTH	01	/* Known never to match null string. */
-#define	SIMPLE		02	/* Simple enough to be STAR/PLUS operand. */
-#define	SPSTART		04	/* Starts with * or +. */
-#define	WORST		0	/* Worst case. */
-
-/*
- * Global work variables for regcomp().
- */
-static ushort *regparse;		/* Input-scan pointer. */
-static int regnpar;		/* () count. */
-static ushort regdummy;
-static ushort *regcode;		/* Code-emit pointer; &regdummy = don't. */
-static long regsize;		/* Code size. */
-
-/*
- * Forward declarations for regcomp()'s friends.
- */
-#ifndef STATIC
-#define	STATIC	static
-#endif
-STATIC ushort *reg();
-STATIC ushort *regbranch();
-STATIC ushort *regpiece();
-STATIC ushort *regatom();
-STATIC ushort *regnode();
-STATIC ushort *regnext();
-STATIC void regc();
-STATIC void reginsert();
-STATIC void regtail();
-STATIC void regoptail();
-STATIC int Strcspn();
-
-/*
- - regcomp - compile a regular expression into internal code
- *
- * We can't allocate space until we know how big the compiled form will be,
- * but we can't compile it (and thus know how big it is) until we've got a
- * place to put the code.  So we cheat:  we compile it twice, once with code
- * generation turned off and size counting turned on, and once "for real".
- * This also means that we don't allocate space until we are sure that the
- * thing really will compile successfully, and we never have to move the
- * code and thus invalidate pointers into it.  (Note that it has to be in
- * one piece because free() must be able to free it all.)
- *
- * Beware that the optimization-preparation code in here knows about some
- * of the structure of the compiled regexp.
- */
-regexp *
-regcomp(exp)
-ushort *exp;
-{
-  register regexp *r;
-  register ushort *scan;
-  register ushort *longest;
-  register int len;
-  int flags;
-  extern char *emalloc();
-
-  if (exp == NULL)
-	FAIL("NULL argument");
-
-  /* First pass: determine size, legality. */
-  regparse = exp;
-  regnpar = 1;
-  regsize = 0L;
-  regcode = &regdummy;
-  regc((ushort) MAGIC);
-  if (reg(0, &flags) == NULL)
-	return(NULL);
-
-  /* Small enough for pointer-storage convention? */
-  if (regsize >= 32767L)		/* Probably could be 65535L. */
-	FAIL("regexp too big");
-
-  /* Allocate space. */
-  r = (regexp *)emalloc(sizeof(regexp) + (unsigned)regsize * sizeof(ushort));
-
-  /* Second pass: emit code. */
-  regparse = exp;
-  regnpar = 1;
-  regcode = r->program;
-  regc((ushort) MAGIC);
-  if (reg(0, &flags) == NULL)
-	return(NULL);
-
-  /* Dig out information for optimizations. */
-  r->regstart = '\0';	/* Worst-case defaults. */
-  r->reganch = 0;
-  r->regmust = NULL;
-  r->regmlen = 0;
-  scan = r->program+1;			/* First BRANCH. */
-  if (OP(regnext(scan)) == END) {		/* Only one top-level choice. */
-	scan = OPERAND(scan);
-
-	/* Starting-point info. */
-	if (OP(scan) == EXACTLY)
-		r->regstart = *OPERAND(scan);
-	else if (OP(scan) == BOL)
-		r->reganch++;
-
-	/*
-	 * If there's something expensive in the r.e., find the
-	 * longest literal string that must appear and make it the
-	 * regmust.  Resolve ties in favor of later strings, since
-	 * the regstart check works with the beginning of the r.e.
-	 * and avoiding duplication strengthens checking.  Not a
-	 * strong reason, but sufficient in the absence of others.
-	 */
-	if (flags&SPSTART) {
-		longest = NULL;
-		len = 0;
-		for (; scan != NULL; scan = regnext(scan))
-			if (OP(scan) == EXACTLY && Strlen(OPERAND(scan)) >= len) {
-				longest = OPERAND(scan);
-				len = Strlen(OPERAND(scan));
-			}
-		r->regmust = longest;
-		r->regmlen = len;
-	}
-  }
-
-  return(r);
-}
-
-/*
- - reg - regular expression, i.e. main body or parenthesized thing
- *
- * Caller must absorb opening parenthesis.
- *
- * Combining parenthesis handling with the base level of regular expression
- * is a trifle forced, but the need to tie the tails of the branches to what
- * follows makes it hard to avoid.
- */
-static ushort *
-reg(paren, flagp)
-int paren;			/* Parenthesized? */
-int *flagp;
-{
-  register ushort *ret;
-  register ushort *br;
-  register ushort *ender;
-  register int parno;
-  int flags;
-
-  *flagp = HASWIDTH;	/* Tentatively. */
-
-  /* Make an OPEN node, if parenthesized. */
-  if (paren) {
-	if (regnpar >= NSUBEXP)
-		FAIL("too many ()");
-	parno = regnpar;
-	regnpar++;
-	ret = regnode(OPEN+parno);
-  } else
-	ret = NULL;
-
-  /* Pick up the branches, linking them together. */
-  br = regbranch(&flags);
-  if (br == NULL)
-	return(NULL);
-  if (ret != NULL)
-	regtail(ret, br);	/* OPEN -> first. */
-  else
-	ret = br;
-  if (!(flags&HASWIDTH))
-	*flagp &= ~HASWIDTH;
-  *flagp |= flags&SPSTART;
-  while (*regparse == '|') {
-	regparse++;
-	br = regbranch(&flags);
-	if (br == NULL)
-		return(NULL);
-	regtail(ret, br);	/* BRANCH -> BRANCH. */
-	if (!(flags&HASWIDTH))
-		*flagp &= ~HASWIDTH;
-	*flagp |= flags&SPSTART;
-  }
-
-  /* Make a closing node, and hook it on the end. */
-  ender = regnode((paren) ? CLOSE+parno : END);	
-  regtail(ret, ender);
-
-  /* Hook the tails of the branches to the closing node. */
-  for (br = ret; br != NULL; br = regnext(br))
-	regoptail(br, ender);
-
-  /* Check for proper termination. */
-  if (paren && *regparse++ != ')') {
-	FAIL("unmatched ()");
-  } else if (!paren && *regparse != '\0') {
-	if (*regparse == ')') {
-		FAIL("unmatched ()");
-	} else
-		FAIL("junk on end");	/* "Can't happen". */
-	/* NOTREACHED */
-  }
-
-  return(ret);
-}
-
-/*
- - regbranch - one alternative of an | operator
- *
- * Implements the concatenation operator.
- */
-static ushort *
-regbranch(flagp)
-int *flagp;
-{
-  register ushort *ret;
-  register ushort *chain;
-  register ushort *latest;
-  int flags;
-
-  *flagp = WORST;		/* Tentatively. */
-
-  ret = regnode(BRANCH);
-  chain = NULL;
-  while (*regparse != '\0' && *regparse != '|' && *regparse != ')') {
-	latest = regpiece(&flags);
-	if (latest == NULL)
-		return(NULL);
-	*flagp |= flags&HASWIDTH;
-	if (chain == NULL)	/* First piece. */
-		*flagp |= flags&SPSTART;
-	else
-		regtail(chain, latest);
-	chain = latest;
-  }
-  if (chain == NULL)	/* Loop ran zero times. */
-	(void) regnode(NOTHING);
-
-  return(ret);
-}
-
-/*
- - regpiece - something followed by possible [*+?]
- *
- * Note that the branching code sequences used for ? and the general cases
- * of * and + are somewhat optimized:  they use the same NOTHING node as
- * both the endmarker for their branch list and the body of the last branch.
- * It might seem that this node could be dispensed with entirely, but the
- * endmarker role is not redundant.
- */
-static ushort *
-regpiece(flagp)
-int *flagp;
-{
-  register ushort *ret;
-  register ushort op;
-  register ushort *next;
-  int flags;
-
-  ret = regatom(&flags);
-  if (ret == NULL)
-	return(NULL);
-
-  op = *regparse;
-  if (!ISMULT(op)) {
-	*flagp = flags;
-	return(ret);
-  }
-
-  if (!(flags&HASWIDTH) && op != '?')
-	FAIL("*+ operand could be empty");
-  *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH);
-
-  if (op == '*' && (flags&SIMPLE))
-	reginsert(STAR, ret);
-  else if (op == '*') {
-	/* Emit x* as (x&|), where & means "self". */
-	reginsert(BRANCH, ret);			/* Either x */
-	regoptail(ret, regnode(BACK));		/* and loop */
-	regoptail(ret, ret);			/* back */
-	regtail(ret, regnode(BRANCH));		/* or */
-	regtail(ret, regnode(NOTHING));		/* null. */
-  } else if (op == '+' && (flags&SIMPLE))
-	reginsert(PLUS, ret);
-  else if (op == '+') {
-	/* Emit x+ as x(&|), where & means "self". */
-	next = regnode(BRANCH);			/* Either */
-	regtail(ret, next);
-	regtail(regnode(BACK), ret);		/* loop back */
-	regtail(next, regnode(BRANCH));		/* or */
-	regtail(ret, regnode(NOTHING));		/* null. */
-  } else if (op == '?') {
-	/* Emit x? as (x|) */
-	reginsert(BRANCH, ret);			/* Either x */
-	regtail(ret, regnode(BRANCH));		/* or */
-	next = regnode(NOTHING);		/* null. */
-	regtail(ret, next);
-	regoptail(ret, next);
-  }
-  regparse++;
-  if (ISMULT(*regparse))
-	FAIL("nested *?+");
-
-  return(ret);
-}
-
-/*
- - regatom - the lowest level
- *
- * Optimization:  gobbles an entire sequence of ordinary characters so that
- * it can turn them into a single node, which is smaller to store and
- * faster to run.  Backslashed characters are exceptions, each becoming a
- * separate node; the code is simpler that way and it's not worth fixing.
- */
-static ushort *
-regatom(flagp)
-int *flagp;
-{
-  register ushort *ret;
-  int flags;
-  ushort c, d;
-
-  *flagp = WORST;		/* Tentatively. */
-
-  switch ((int) *regparse++) {
-  case '^':
-	ret = regnode(BOL);
-	break;
-  case '$':
-	ret = regnode(EOL);
-	break;
-  case '.':
-	ret = regnode(ANY);
-	*flagp |= HASWIDTH|SIMPLE;
-	break;
-  case '[': {
-		register int class;
-		register int classend;
-		register int c;
-
-		if (*regparse == '^') {	/* Complement of range. */
-			ret = regnode(ANYBUT);
-			regparse++;
-		} else
-			ret = regnode(ANYOF);
-		if (*regparse == ']' || *regparse == '-')
-			regc(*regparse++);
-		while (*regparse != '\0' && *regparse != ']') {
-			if (*regparse == '-') {
-				regparse++;
-				if (*regparse == ']' || *regparse == '\0')
-					regc((ushort) '-');
-				else {
-					class = UCHARAT(regparse-2)+1;
-					classend = UCHARAT(regparse);
-					if (class > classend+1)
-						FAIL("invalid [] range");
-					regc((ushort) 0xffff);
-					regc((ushort) class);
-					regc((ushort) classend);
-					regparse++;
-				}
-			} else {
-				if ((c = *regparse++) == '\\') {
-					if ((c = *regparse++) == 'n')
-						c = '\n';
-					else if (c == 't')
-						c = '\t';
-				}
-				regc(c);
-			}
-		}
-		regc((ushort) 0);
-		if (*regparse != ']')
-			FAIL("unmatched []");
-		regparse++;
-		*flagp |= HASWIDTH|SIMPLE;
-	}
-	break;
-  case '(':
-	ret = reg(1, &flags);
-	if (ret == NULL)
-		return(NULL);
-	*flagp |= flags&(HASWIDTH|SPSTART);
-	break;
-  case '\0':
-  case '|':
-  case ')':
-	FAIL("internal urp");	/* Supposed to be caught earlier. */
-	break;
-  case '?':
-  case '+':
-  case '*':
-	FAIL("?+* follows nothing");
-	break;
-  case '\\':
-	if (*regparse == '\0')
-		FAIL("trailing \\");
-	ret = regnode(EXACTLY);
-/*
-	regc(*regparse++);
-*/
-	c = *regparse++;
-	if (c == 'n')
-		c = '\n';
-	else if (c == 't')
-		c = '\t';
-	else if (c == 'f')
-		c = '\f';
-	else if (c == '\r')
-		c = '\r';
-	else if (c == '\b')
-		c = '\b';
-	else if (IsDigid(c)) {
-		d = c - '0';
-		if (IsDigid(*regparse)) {
-			d = d * 8 + *regparse++ - '0';
-			if (IsDigid(*regparse))
-				d = d * 8 + *regparse++ - '0';
-		}
-		c = d;
-	}
-	regc(c);
-	regc((ushort) 0);
-	*flagp |= HASWIDTH|SIMPLE;
-	break;
-  default: {
-		register int len;
-		register char ender;
-
-		regparse--;
-		len = Strcspn(regparse, META);
-		if (len <= 0)
-			FAIL("internal disaster");
-		ender = *(regparse+len);
-		if (len > 1 && ISMULT(ender))
-			len--;		/* Back off clear of ?+* operand. */
-		*flagp |= HASWIDTH;
-		if (len == 1)
-			*flagp |= SIMPLE;
-		ret = regnode(EXACTLY);
-		while (len > 0) {
-			regc(*regparse++);
-			len--;
-		}
-		regc((ushort) 0);
-	}
-	break;
-  }
-
-  return(ret);
-}
-
-IsDigid(c) ushort c;
-{
-  return '0' <= c && c <= '9';
-}
-
-/*
- - regnode - emit a node
- */
-static ushort *			/* Location. */
-regnode(op)
-ushort op;
-{
-  register ushort *ret;
-  register ushort *ptr;
-
-  ret = regcode;
-  if (ret == &regdummy) {
-	regsize += 3;
-	return(ret);
-  }
-
-  ptr = ret;
-  *ptr++ = op;
-  *ptr++ = '\0';		/* Null "next" pointer. */
-  *ptr++ = '\0';
-  regcode = ptr;
-
-  return(ret);
-}
-
-/*
- - regc - emit (if appropriate) a byte of code
- */
-static void
-regc(b)
-ushort b;
-{
-  if (regcode != &regdummy)
-	*regcode++ = b;
-  else
-	regsize++;
-}
-
-/*
- - reginsert - insert an operator in front of already-emitted operand
- *
- * Means relocating the operand.
- */
-static void
-reginsert(op, opnd)
-ushort op;
-ushort *opnd;
-{
-  register ushort *src;
-  register ushort *dst;
-  register ushort *place;
-
-  if (regcode == &regdummy) {
-	regsize += 3;
-	return;
-  }
-
-  src = regcode;
-  regcode += 3;
-  dst = regcode;
-  while (src > opnd)
-	*--dst = *--src;
-
-  place = opnd;		/* Op node, where operand used to be. */
-  *place++ = op;
-  *place++ = '\0';
-  *place++ = '\0';
-}
-
-/*
- - regtail - set the next-pointer at the end of a node chain
- */
-static void
-regtail(p, val)
-ushort *p;
-ushort *val;
-{
-  register ushort *scan;
-  register ushort *temp;
-  register int offset;
-
-  if (p == &regdummy)
-	return;
-
-  /* Find last node. */
-  scan = p;
-  for (;;) {
-	temp = regnext(scan);
-	if (temp == NULL)
-		break;
-	scan = temp;
-  }
-
-  if (OP(scan) == BACK)
-	offset = scan - val;
-  else
-	offset = val - scan;
-  *(scan+1) = (offset>>8)&0377;
-  *(scan+2) = offset&0377;
-}
-
-/*
- - regoptail - regtail on operand of first argument; nop if operandless
- */
-static void
-regoptail(p, val)
-ushort *p;
-ushort *val;
-{
-  /* "Operandless" and "op != BRANCH" are synonymous in practice. */
-  if (p == NULL || p == &regdummy || OP(p) != BRANCH)
-	return;
-  regtail(OPERAND(p), val);
-}
-
-/*
- * regexec and friends
- */
-
-/*
- * Global work variables for regexec().
- */
-static ushort *reginput;		/* String-input pointer. */
-static ushort *regbol;		/* Beginning of input, for ^ check. */
-static ushort **regstartp;	/* Pointer to startp array. */
-static ushort **regendp;		/* Ditto for endp. */
-
-/*
- * Forwards.
- */
-STATIC int regtry();
-STATIC int regmatch();
-STATIC int regrepeat();
-
-#ifdef DEBUG
-int regnarrate = 0;
-void regdump();
-STATIC char *regprop();
-#endif
-
-/*
- - regexec - match a regexp against a string
- */
-int
-regexec(prog, string, bolflag)
-register regexp *prog;
-register ushort *string;
-int bolflag;
-{
-  register ushort *s;
-  extern ushort *Strchr();
-
-  /* Be paranoid... */
-  if (prog == NULL || string == NULL) {
-	regerror("NULL parameter");
-	return(0);
-  }
-
-  /* Check validity of program. */
-  if (prog->program[0] != MAGIC) {
-	regerror("corrupted program");
-	return(0);
-  }
-
-  /* If there is a "must appear" string, look for it. */
-  if (prog->regmust != NULL) {
-	s = string;
-	while ((s = Strchr(s, prog->regmust[0])) != NULL) {
-		if (Strncmp(s, prog->regmust, prog->regmlen) == 0)
-			break;	/* Found it. */
-		s++;
-	}
-	if (s == NULL)	/* Not present. */
-		return(0);
-  }
-
-  /* Mark beginning of line for ^ . */
-  if(bolflag)
-	regbol = string;
-  else
-	regbol = NULL;
-
-  /* Simplest case:  anchored match need be tried only once. */
-  if (prog->reganch)
-	return(regtry(prog, string));
-
-  /* Messy cases:  unanchored match. */
-  s = string;
-  if (prog->regstart != '\0') {
-	/* We know what char it must start with. */
-	while ((s = Strchr(s, prog->regstart)) != NULL) {
-		if (regtry(prog, s))
-			return(1);
-		s++;
-	}
-}
-  else
-	/* We don't -- general case. */
-	do {
-		if (regtry(prog, s))
-			return(1);
-	} while (*s++ != '\0');
-
-  /* Failure. */
-  return(0);
-}
-
-/*
- - regtry - try match at specific point
- */
-static int			/* 0 failure, 1 success */
-regtry(prog, string)
-regexp *prog;
-ushort *string;
-{
-  register int i;
-  register ushort **sp;
-  register ushort **ep;
-
-  reginput = string;
-  regstartp = prog->startp;
-  regendp = prog->endp;
-
-  sp = prog->startp;
-  ep = prog->endp;
-  for (i = NSUBEXP; i > 0; i--) {
-	*sp++ = NULL;
-	*ep++ = NULL;
-  }
-  if (regmatch(prog->program + 1)) {
-	prog->startp[0] = string;
-	prog->endp[0] = reginput;
-	return(1);
-  } else
-	return(0);
-}
-
-/*
- - regmatch - main matching routine
- *
- * Conceptually the strategy is simple:  check to see whether the current
- * node matches, call self recursively to see whether the rest matches,
- * and then act accordingly.  In practice we make some effort to avoid
- * recursion, in particular by going through "ordinary" nodes (that don't
- * need to know whether the rest of the match failed) by a loop instead of
- * by recursion.
- */
-static int			/* 0 failure, 1 success */
-regmatch(prog)
-ushort *prog;
-{
-  register ushort *scan;	/* Current node. */
-  ushort *next;		/* Next node. */
-  extern ushort *Strchr();
-
-  scan = prog;
-#ifdef DEBUG
-  if (scan != NULL && regnarrate)
-	fprintf(stderr, "%s(\n", regprop(scan));
-#endif
-  while (scan != NULL) {
-#ifdef DEBUG
-	if (regnarrate)
-		fprintf(stderr, "%s...\n", regprop(scan));
-#endif
-	next = regnext(scan);
-
-	switch ((int) OP(scan)) {
-	case BOL:
-		if (reginput != regbol)
-			return(0);
-		break;
-	case EOL:
-		if (*reginput != '\0')
-			return(0);
-		break;
-	case ANY:
-		if (*reginput == '\0')
-			return(0);
-		reginput++;
-		break;
-	case EXACTLY: {
-			register int len;
-			register ushort *opnd;
-
-			opnd = OPERAND(scan);
-			/* Inline the first character, for speed. */
-			if (*opnd != *reginput)
-				return(0);
-			len = Strlen(opnd);
-			if (len > 1 && Strncmp(opnd, reginput, len) != 0)
-				return(0);
-			reginput += len;
-		}
-		break;
-	case ANYOF:
-		if (*reginput == '\0' || isthere(OPERAND(scan), *reginput) == 0)
-			return(0);
-		reginput++;
-		break;
-	case ANYBUT:
-		if (*reginput == '\0' || isthere(OPERAND(scan), *reginput) != 0)
-			return(0);
-		reginput++;
-		break;
-	case NOTHING:
-		break;
-	case BACK:
-		break;
-	case OPEN+1:
-	case OPEN+2:
-	case OPEN+3:
-	case OPEN+4:
-	case OPEN+5:
-	case OPEN+6:
-	case OPEN+7:
-	case OPEN+8:
-	case OPEN+9: {
-			register int no;
-			register ushort *save;
-
-			no = OP(scan) - OPEN;
-			save = reginput;
-
-			if (regmatch(next)) {
-				/*
-				 * Don't set startp if some later
-				 * invocation of the same parentheses
-				 * already has.
-				 */
-				if (regstartp[no] == NULL)
-					regstartp[no] = save;
-				return(1);
-			} else
-				return(0);
-		}
-		break;
-	case CLOSE+1:
-	case CLOSE+2:
-	case CLOSE+3:
-	case CLOSE+4:
-	case CLOSE+5:
-	case CLOSE+6:
-	case CLOSE+7:
-	case CLOSE+8:
-	case CLOSE+9: {
-			register int no;
-			register ushort *save;
-
-			no = OP(scan) - CLOSE;
-			save = reginput;
-
-			if (regmatch(next)) {
-				/*
-				 * Don't set endp if some later
-				 * invocation of the same parentheses
-				 * already has.
-				 */
-				if (regendp[no] == NULL)
-					regendp[no] = save;
-				return(1);
-			} else
-				return(0);
-		}
-		break;
-	case BRANCH: {
-			register ushort *save;
-
-			if (OP(next) != BRANCH)		/* No choice. */
-				next = OPERAND(scan);	/* Avoid recursion. */
-			else {
-				do {
-					save = reginput;
-					if (regmatch(OPERAND(scan)))
-						return(1);
-					reginput = save;
-					scan = regnext(scan);
-				} while (scan != NULL && OP(scan) == BRANCH);
-				return(0);
-				/* NOTREACHED */
-			}
-		}
-		break;
-	case STAR:
-	case PLUS: {
-			register ushort nextch;
-			register int no;
-			register ushort *save;
-			register int min;
-
-			/*
-			 * Lookahead to avoid useless match attempts
-			 * when we know what character comes next.
-			 */
-			nextch = '\0';
-			if (OP(next) == EXACTLY)
-				nextch = *OPERAND(next);
-			min = (OP(scan) == STAR) ? 0 : 1;
-			save = reginput;
-			no = regrepeat(OPERAND(scan));
-			while (no >= min) {
-				/* If it could work, try it. */
-				if (nextch == '\0' || *reginput == nextch)
-					if (regmatch(next))
-						return(1);
-				/* Couldn't or didn't -- back up. */
-				no--;
-				reginput = save + no;
-			}
-			return(0);
-		}
-		break;
-	case END:
-		return(1);	/* Success! */
-		break;
-	default:
-		regerror("memory corruption");
-		return(0);
-		break;
-	}
-
-	scan = next;
-  }
-
-  /*
-   * We get here only if there's trouble -- normally "case END" is
-   * the terminating point.
-   */
-  regerror("corrupted pointers");
-  return(0);
-}
-
-/*
- - regrepeat - repeatedly match something simple, report how many
- */
-static int
-regrepeat(p)
-ushort *p;
-{
-  register int count = 0;
-  register ushort *scan;
-  register ushort *opnd;
-
-  scan = reginput;
-  opnd = OPERAND(p);
-  switch (OP(p)) {
-  case ANY:
-	count = Strlen(scan);
-	scan += count;
-	break;
-  case EXACTLY:
-	while (*opnd == *scan) {
-		count++;
-		scan++;
-	}
-	break;
-  case ANYOF:
-	while (*scan != '\0' && isthere(opnd, *scan) != 0) {
-		count++;
-		scan++;
-	}
-	break;
-  case ANYBUT:
-	while (*scan != '\0' && isthere(opnd, *scan) == 0) {
-		count++;
-		scan++;
-	}
-	break;
-  default:		/* Oh dear.  Called inappropriately. */
-	regerror("internal foulup");
-	count = 0;	/* Best compromise. */
-	break;
-  }
-  reginput = scan;
-
-  return(count);
-}
-
-/*
- - regnext - dig the "next" pointer out of a node
- */
-static ushort *
-regnext(p)
-register ushort *p;
-{
-  register int offset;
-
-  if (p == &regdummy)
-	return(NULL);
-
-  offset = NEXT(p);
-  if (offset == 0)
-	return(NULL);
-
-  if (OP(p) == BACK)
-	return(p-offset);
-  else
-	return(p+offset);
-}
-
-#ifdef DEBUG
-
-STATIC char *regprop();
-
-/*
- - regdump - dump a regexp onto stdout in vaguely comprehensible form
- */
-void
-regdump(r)
-regexp *r;
-{
-  register ushort *s;
-  register ushort op = EXACTLY;	/* Arbitrary non-END op. */
-  register ushort *next;
-
-
-  s = r->program + 1;
-  while (op != END) {	/* While that wasn't END last time... */
-	op = OP(s);
-	printf("%2d%s", s-r->program, regprop(s));	/* Where, what. */
-	next = regnext(s);
-	if (next == NULL)		/* Next ptr. */
-		printf("(0)");
-	else 
-		printf("(%d)", (s-r->program)+(next-s));
-	s += 3;
-	if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
-		/* Literal string, where present. */
-		while (*s != '\0') {
-			if (*s == 0xffff) {	/* range */
-				kputchar(*++s); putchar('-'); ++s;
-			}
-			kputchar(*s++);
-		}
-		s++;
-	}
-	putchar('\n');
-  }
-
-  /* Header fields of interest. */
-  if (r->regstart != '\0') {
-	fputs("start `", stdout); kputchar(r->regstart); fputs("' ", stdout);
-  }
-  if (r->reganch)
-	printf("anchored ");
-  if (r->regmust != NULL) {
-	fputs("must have \"", stdout); kputs(r->regmust); putchar('"');
-  }
-  printf("\n");
-}
-
-kputchar(c) ushort c;
-{
-  if (c & 0xff00)
-	putchar(c >> 8);
-  putchar(c & 0xff);
-}
-
-kputs(s) ushort *s;
-{
-  while (*s)
-	kputchar(*s++);
-}
-
-/*
- - regprop - printable representation of opcode
- */
-static char *
-regprop(op)
-ushort *op;
-{
-  register char *p;
-  static char buf[50];
-
-  (void) strcpy(buf, ":");
-
-  switch ((int) OP(op)) {
-  case BOL:
-	p = "BOL";
-	break;
-  case EOL:
-	p = "EOL";
-	break;
-  case ANY:
-	p = "ANY";
-	break;
-  case ANYOF:
-	p = "ANYOF";
-	break;
-  case ANYBUT:
-	p = "ANYBUT";
-	break;
-  case BRANCH:
-	p = "BRANCH";
-	break;
-  case EXACTLY:
-	p = "EXACTLY";
-	break;
-  case NOTHING:
-	p = "NOTHING";
-	break;
-  case BACK:
-	p = "BACK";
-	break;
-  case END:
-	p = "END";
-	break;
-  case OPEN+1:
-  case OPEN+2:
-  case OPEN+3:
-  case OPEN+4:
-  case OPEN+5:
-  case OPEN+6:
-  case OPEN+7:
-  case OPEN+8:
-  case OPEN+9:
-	sprintf(buf+strlen(buf), "OPEN%d", OP(op)-OPEN);
-	p = NULL;
-	break;
-  case CLOSE+1:
-  case CLOSE+2:
-  case CLOSE+3:
-  case CLOSE+4:
-  case CLOSE+5:
-  case CLOSE+6:
-  case CLOSE+7:
-  case CLOSE+8:
-  case CLOSE+9:
-	sprintf(buf+strlen(buf), "CLOSE%d", OP(op)-CLOSE);
-	p = NULL;
-	break;
-  case STAR:
-	p = "STAR";
-	break;
-  case PLUS:
-	p = "PLUS";
-	break;
-  default:
-	regerror("corrupted opcode");
-	break;
-  }
-  if (p != NULL)
-	(void) strcat(buf, p);
-  return(buf);
-}
-#endif
-
-/*
- * The following is provided for those people who do not have strcspn() in
- * their C libraries.  They should get off their butts and do something
- * about it; at least one public-domain implementation of those (highly
- * useful) string routines has been published on Usenet.
- */
-/*
- * strcspn - find length of initial segment of s1 consisting entirely
- * of characters not from s2
- */
-
-static int
-Strcspn(s1, s2)
-ushort *s1;
-unsigned char *s2;
-{
-  register ushort *scan1;
-  register unsigned char *scan2;
-  register int count;
-
-  count = 0;
-  for (scan1 = s1; *scan1 != '\0'; scan1++) {
-	for (scan2 = s2; *scan2 != '\0';)	/* ++ moved down. */
-		if (*scan1 == *scan2++)
-			return(count);
-	count++;
-  }
-  return(count);
-}
-
-isthere(s, c) ushort *s, c;
-{
-  register unsigned int c1, c2;
-
-  for ( ; *s; s++) {
-	if (*s == 0xffff) {	/* range */
-		c1 = *++s; c2 = *++s;
-		if (c1 <= c && c <= c2)
-			return 1;
-	}
-	else if (*s == c)
-		return 1;
-  }
-  return 0;
-}
-
-ushort *
-Strchr(s, c) ushort *s, c;
-{
-  for ( ; *s; s++)
-	if (*s == c)
-		return s;
-  return NULL;
-}
-
-Strncmp(s, t, n) ushort *s, *t;
-{
-  for ( ; --n > 0 && *s == *t; s++, t++)
-	;
-  return *s - *t;
-}
-
-Strlen(s) ushort *s;
-{
-  int i;
-
-  for (i = 0; *s; i++, s++)
-	;
-  return i;
-}
-
-ushort kbuf[BUFSIZ];
-
-char *
-mkpat(s) char *s;
-{
-  sjtok(kbuf, s);
-  return (char *) regcomp(kbuf);
-}
-
-match(p, s) regexp *p; char *s;
-{
-  register int i;
-
-  sjtok(kbuf, s);
-  if (i = regexec(p, kbuf, 1)) {
-	r_start = p->startp[0] - kbuf + 1;
-	r_length = p->endp[0] - p->startp[0];
-  }
-  else
-	r_start = r_length = 0;
-  return i;
-}
-
-sjtok(s, t) ushort *s; unsigned char *t;
-{
-  register c;
-
-  for ( ; *t; t++) {
-	if (isKanji(c = *t))
-		c = (c << 8) | (*++t & 0xff);
-	*s++ = c;
-  }
-  *s = 0;
-}
-
-ktosj(s, t) unsigned char *s; ushort *t;
-{
-  register c;
-
-  while (*t) {
-	if ((c = *t++) & 0xff00)
-		*s++ = c >> 8;
-	*s++ = c & 0xff;
-  }
-  *s = '\0';
-}
-
-regsub(dst, exp, src, pat, pos) ushort *dst, *src, *pat; regexp *exp;
-{	/* dst <-- s/src/pat/pos	global substitution for pos == 0 */
-  register int c, i;
-  register ushort *loc1, *loc2, *s, *t, *u;
-  register int n = 0;
-
-  if (exp->program[0] != MAGIC) {
-	regerror("damaged regexp fed to regsub");
-	return 0;
-  }
-  while (*src) {
-next:
-	if (regexec(exp, src, 1) == 0)
-		break;
-	loc1 = exp->startp[0]; loc2 = exp->endp[0];
-	if (pos-- > 1) {
-		while (src < loc2)
-			*dst++ = *src++;
-		goto next;
-	}
-	while (src < loc1)
-		*dst++ = *src++;
-	for (s = pat; c = *s++; ) {
-		if (c == '&')
-			i = 0;
-		else if (c == '\\' && '0' <= *s && *s <= '9')
-			i = *s++ - '0';
-		else {
-			if (c == '\\' && (*s == '\\' || *s == '&'))
-				c = *s++;
-			*dst++ = c;
-			continue;
-		}
-		if ((t = exp->startp[i]) != NULL
-			&& (u = exp->endp[i]) != NULL) {
-			while (t < u)
-				*dst++ = *t++;
-		}
-	}
-	src = loc2;
-	n++;
-	if (pos == 0)
-		break;
-  }
-  while (*src)
-	*dst++ = *src++;
-  *dst++ = 0;
-  return n;
-}
-
-static ushort kbuf1[BUFSIZ], kbuf2[BUFSIZ];
-
-Sub(u, exp, str, s, t, pos) char *exp; char *s, *t, *u;
-{
-  register int i;
-  regexp *r;
-
-  if (str) {
-	sjtok(kbuf, exp);
-	r = regcomp(kbuf);
-  }
-  else
-	r = (regexp *) exp;
-  sjtok(kbuf, s);
-  sjtok(kbuf1, t);
-  i = regsub(kbuf2, r, kbuf1, kbuf, pos);
-  ktosj(u, kbuf2);
-  if (str)
-	sfree(r);
-
-  return i;
-}
Index: trunk/minix/commands/awk/regexp.h
===================================================================
--- trunk/minix/commands/awk/regexp.h	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-/*
- * Definitions etc. for regexp(3) routines.
- *
- * Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
- * not the System V one.
- */
-#define ushort	unsigned short
-#define CHARBITS 0xffff
-#define NSUBEXP  10
-typedef struct regexp {
-	ushort *startp[NSUBEXP];
-	ushort *endp[NSUBEXP];
-	ushort regstart;		/* Internal use only. */
-	ushort reganch;		/* Internal use only. */
-	ushort *regmust;		/* Internal use only. */
-	int regmlen;		/* Internal use only. */
-	ushort program[1];	/* Unwarranted chumminess with compiler. */
-} regexp;
-
-extern regexp *regcomp();
-extern int regexec();
-extern int regsub();
-extern int regerror();
Index: trunk/minix/commands/awk/v.c
===================================================================
--- trunk/minix/commands/awk/v.c	(revision 9)
+++ 	(revision )
@@ -1,689 +1,0 @@
-/*
- * a small awk clone
- *
- * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
- *
- * Absolutely no warranty. Use this software with your own risk.
- *
- * Permission to use, copy, modify and distribute this software for any
- * purpose and without fee is hereby granted, provided that the above
- * copyright and disclaimer notice.
- *
- * This program was written to fit into 64K+64K memory of the Minix 1.2.
- */
-
-
-#include <stdio.h>
-#include <ctype.h>
-#include "awk.h"
-#include "regexp.h"
-
-#define PI	3.14159265358979323846
-
-#define HASHSIZE	50
-#define MAXFIELD	100
-
-double atof();
-char *getsval(), *jStrchar();
-extern CELL *execute(), *_Arg();
-
-extern char record[];
-extern CELL *field[];
-
-extern CELL truecell, falsecell;
-extern prmflg;
-
-SYMBOL *hashtab[HASHSIZE];
-SYMBOL *funtab[HASHSIZE];
-SYMBOL *argtab[HASHSIZE];
-
-char *strsave(), *emalloc(), *strchr();
-CELL *lookup(), *install(), *_install(), *mkcell(), *mktmp(), *getvar();
-
-char **FS, **RS, **OFS, **ORS, **OFMT, **FILENAME;
-char **SUBSEP;
-double *NR, *NF;
-double *FNR, *ARGC, *RSTART, *RLENGTH;
-
-init()
-{
-  FS = &install("FS", VAR|STR, " ", 0.0, hashtab)->c_sval;
-  RS = &install("RS", VAR|STR, "\n", 0.0, hashtab)->c_sval;
-  OFS = &install("OFS", VAR|STR , " ", 0.0, hashtab)->c_sval;
-  ORS = &install("ORS", VAR|STR, "\n", 0.0, hashtab)->c_sval;
-  OFMT = &install("OFMT", VAR|STR, "%.6g", 0.0, hashtab)->c_sval;
-  NR = &install("NR", VAR|NUM, (char *)NULL, 0.0, hashtab)->c_fval;
-  NF = &install("NF", VAR|NUM, (char *)NULL, 0.0, hashtab)->c_fval;
-  FILENAME = &install("FILENAME", VAR|STR, (char *)NULL, 0.0, hashtab)->c_sval;
-  install("PI", VAR|NUM, (char *)NULL, PI, hashtab);
-  field[0] = mkcell(REC|STR, (char *)NULL, 0.0);	/* $0 */
-  field[0]->c_sval = record;
-  SUBSEP = &install("SUBSEP", VAR|STR, "\034", 0.0, hashtab)->c_sval;
-  FNR = &install("FNR", VAR|NUM, (char *)NULL, 0.0, hashtab)->c_fval;
-  RSTART = &install("RSTART", VAR|NUM, (char *)NULL, 0.0, hashtab)->c_fval;
-  RLENGTH = &install("RLENGTH", VAR|NUM, (char *)NULL, 0.0, hashtab)->c_fval;
-}
-
-setvar(s) char *s;
-{
-  CELL *u;
-  char *t;
-
-  for (t = s; *t && *t != '='; t++)
-	;
-  *t++ = '\0';
-  if ((u = lookup(s, hashtab)) == (CELL *)NULL) {
-	if (isnum(t))
-		install(s, VAR|NUM|STR, t, atof(t), hashtab);
-	else
-		install(s, VAR|STR, t, 0.0, hashtab);
-  }
-  else {
-	if (isnum(t))
-		setfval(u, atof(t));
-	else
-		setsval(u, t);
-  }
-}
-
-initarg(arg0, argc, argv) char *arg0, **argv;
-{
-  CELL *u;
-  register int i;
-  register char str[4];
-
-  ARGC = &install("ARGC", VAR|NUM, (char *)NULL, (double)argc+1, hashtab)->c_fval;
-  u = install("ARGV", ARR, (char *)NULL, 0.0, hashtab);
-  u->c_sval = (char *) argtab;
-  install("0", VAR|STR, arg0, 0.0, argtab);
-  for (i = 0; i < argc; i++) {
-	sprintf(str, "%d", i+1);
-	if (isnum(argv[i]))
-		install(str, VAR|STR|NUM, argv[i], atof(argv[i]), argtab);
-	else
-		install(str, VAR|STR, argv[i], 0.0, argtab);
-  }
-}
-
-static
-hash(s) unsigned char *s;
-{
-  register unsigned int h;
-
-  for (h = 0; *s; )
-	h += *s++;
-  return h % HASHSIZE;
-}
-
-CELL *
-lookup(s, h) char *s; SYMBOL *h[];
-{
-  register SYMBOL *p;
-
-  for (p = h[hash(s)]; p; p = p->s_next)
-	if (strcmp(s, p->s_name) == 0)
-		return p->s_val;
-  return (CELL *)NULL;
-}
-
-static CELL *
-install(name, type, sval, fval, h) char *name, *sval; double fval; SYMBOL *h[];
-{
-  CELL *u;
-
-  if ((u = lookup(name, h)) == (CELL *)NULL)
-	u = _install(name, type, sval, fval, h);
-  else
-	error("%s is doubly defined", name);
-  return u;
-}
-
-static CELL *
-_install(name, type, sval, fval, h) char *name, *sval; double fval; SYMBOL *h[];{
-  register SYMBOL *p;
-  CELL *u;
-  int hval;
-
-  p = (SYMBOL *) emalloc(sizeof(*p));
-  u = (CELL *) emalloc(sizeof(*u));
-  p->s_name = strsave(name);
-  p->s_val = u;
-  hval = hash(name);
-  p->s_next = h[hval];
-  h[hval] = p;
-  u->c_type = type;
-  u->c_sval = strsave(sval);
-#if 0
-  if (!(type & NUM) && isnum(sval)) {
-	u->c_fval = atof(sval);
-	u->c_type |= NUM;
-  }
-  else
-#endif
-	u->c_fval = fval;
-  return u;
-}
-
-CELL *
-getvar(s, h, typ) char *s; SYMBOL *h[];
-{
-  CELL *u;
-  SYMBOL *p;
-  char *t;
-  int i, hval;
-
-  if ((u = lookup(s, h)) == (CELL *)NULL) {
-	if (prmflg) {
-		u = _install(s, UDF, "", 0.0, h);
-		goto rtn;
-	}
-	else if (typ & ARR) {
-		t = emalloc(sizeof(SYMBOL *) * HASHSIZE);
-		for (i = 0; i < HASHSIZE; i++)
-			((SYMBOL **) t)[i] = (SYMBOL *)NULL;
-		u = (CELL *) emalloc(sizeof(*u));
-		u->c_type = typ;
-		u->c_sval = t;
-		u->c_fval = 0.0;
-		p = (SYMBOL *) emalloc(sizeof(*p));
-		p->s_name = strsave(s);
-		p->s_val = u;
-		hval = hash(s);
-		p->s_next = h[hval];
-		h[hval] = p;
-	}
-	else
-		u = _install(s, typ, "", 0.0, h);
-  }
-  else if (!prmflg && (u->c_type == UDF) && (typ != UDF)) {
-	/* fix up local_var/forward_function */
-	if (typ == ARR) {
-/*
-printf("getvar_correct_to_array\n");
-*/
-		u->c_type = typ;
-		sfree(u->c_sval);
-		u->c_sval = emalloc(sizeof(SYMBOL *) * HASHSIZE);
-		for (i = 0; i < HASHSIZE; i++)
-			((SYMBOL **) u->c_sval)[i] = (SYMBOL *)NULL;
-		u->c_fval = 0.0;
-	}
-	else if (typ != UDF) {
-		u->c_type = typ;
-	}
- }
-rtn:
-  return u;
-}
-
-fixarray(u) CELL *u;
-{
-  int i;
-
-  if (u->c_type == UDF) {	/* fix up local var */
-/*
-printf("fixarray\n");
-*/
-	u->c_type = ARR;
-	sfree(u->c_sval);
-	u->c_sval = emalloc(sizeof(SYMBOL *) * HASHSIZE);
-	for (i = 0; i < HASHSIZE; i++)
-		((SYMBOL **) u->c_sval)[i] = (SYMBOL *)NULL;
-	u->c_fval = 0.0;
-  }
-}
-
-a_free(u) CELL *u;
-{	/* free local array */
-  SYMBOL **h, *q, *r;
-  CELL *v;
-  int i;
-
-  if (!(u->c_type & ARR))
-	error("try to free non array variable", (char *)0);
-  h = (SYMBOL **) u->c_sval;
-  for (i = 0; i < HASHSIZE; i++)
-	for (q = h[i]; q; q = r) {
-		r = q->s_next;
-		sfree(q->s_name);
-		v = q->s_val;	/* CELL */
-		c_free(v);
-		sfree(q);	/* SYMBOL */
-	}
-
-  sfree(u->c_sval);	/* symbol table */
-  c_free(u);
-}
-
-CELL *
-Array(p) NODE *p;
-{
-  CELL *u;
-  char str[BUFSIZ];
-  int i, n;
-
-  CELL *v;
-
-  u = (CELL *) p->n_arg[0];
-  if (u->c_type == POS) {
-	i = (int)u->c_fval;
-/*
-printf("**ARG_ARRAY(%d)*\n", i);
-*/
-	u = _Arg(i);
-	if (u->c_type == UDF) {	/* fix up local array */
-/*
-printf("local_var_to_array\n");
-*/
-		fixarray(u);
-	}
-  }
-  else if (!(u->c_type & ARR))
-	error("non array refference");
-  arrayelm(p, str);
-  u = getvar(str, u->c_sval, VAR|NUM|STR);	/* "rtsort in AWK book */
-  return u;
-}
-
-static
-arrayelm(p, s) NODE *p; char *s;
-{
-  CELL *u;
-  int i, n;
-  char *t;
-
-/*
-char *tt = s;
-*/
-  n = (int) p->n_arg[1] + 2;
-  for (i = 2; i < n; i++) {
-	if (i > 2)
-		*s++ = **SUBSEP;
-	u = execute(p->n_arg[i]);
-	for (t = getsval(u); *t; )
-		*s++ = *t++;
-	c_free(u);
-  }
-  *s = '\0';
-/*
-printf("array_elm(%s)\n", tt);
-*/
-}
-
-CELL *
-Element(p) NODE *p;
-{
-  char str[BUFSIZ];
-
-  arrayelm(p, str);
-  return mktmp(STR, str, 0.0);
-}
-
-CELL *
-Delete(p) NODE *p;
-{
-  CELL *u;
-  char str[BUFSIZ];
-  int i;
-  SYMBOL *q, *r, **h;
-
-  u = (CELL *) p->n_arg[0];
-  if (!(u->c_type & ARR))
-	error("can't delete non array variable");
-  arrayelm(p, str);
-  h = (SYMBOL **) u->c_sval;
-  for (r = (SYMBOL *)NULL, i = hash(str), q = h[i]; q; r = q, q = q->s_next)
-	if (strcmp(str, q->s_name) == 0)
-		break;
-  if (q) {
-	sfree(q->s_val->c_sval);
-	sfree(q->s_name);
-	if (r)
-		r->s_next = q->s_next;
-	if (q == h[i])
-		h[i] = (SYMBOL *)NULL;
-  }
-  return &truecell;
-}
-
-CELL *
-In(p) NODE *p;
-{
-  SYMBOL **h, *q;
-  CELL *u, *v;
-  char *s;
-  int i;
-
-  u = (CELL *) p->n_arg[1];	/* array */
-  if (!(u->c_type & ARR))
-	error("%s is not an array", u->c_sval);
-  h = (SYMBOL **) u->c_sval;
-  if (u->c_sval != (char *)NULL) {
-	v = execute(p->n_arg[0]);	/* var */
-	s = getsval(v);
-	for (i = 0; i < HASHSIZE; i++)
-		for (q = h[i]; q; q = q->s_next) {
-			if (strcmp(s, q->s_name) == 0) {
-				c_free(v);
-				return &truecell;
-			}
-		}
-	c_free(v);
-  }
-  return &falsecell;
-}
-
-CELL *
-Split(p) NODE *p;
-{
-  CELL *u, *v, *w;
-  char *s, *t, *h, *name, *sep;
-  int i, n, skip;
-  char elm[8], str[BUFSIZ];
-  static char *s_str;
-  static regexp *s_pat;
-  regexp *mkpat();
-  extern int r_start, r_length;
-
-  n = (int) p->n_arg[1];
-  if (n > 1) {
-	u = execute(p->n_arg[2]);
-	s = getsval(u);			/* str */
-	v = execute(p->n_arg[3]);	/* array */
-	if (!(v->c_type & ARR)) {
-/*
-printf("Split fix_to_array(%d)\n", v->c_type);
-*/
-		if (v->c_type == UDF)	/* fix up local array */
-			fixarray(v);
-		else
-			error("split to non array variable", (char *)0);
-	}
-	h = v->c_sval;
-	c_free(v);
-	if (n > 2) {
-		v = execute(p->n_arg[4]);
-		sep = getsval(v);
-	}
-	else {
-		v = (CELL *)NULL;
-		sep = *FS;
-	}
-	if (strlen(sep) > 1) {	/* reg_exp */
-		if (strcmp(sep, s_str) != 0) {
-			sfree(s_str); sfree(s_pat);
-			s_str = strsave(sep);
-			s_pat = mkpat(s_str);
-		}
-		for (i = 0, t = str; *s; ) {
-			if (match(s_pat, s)) {
-				for (n = r_start; --n > 0; )
-					*t++ = *s++;
-			}
-			else {
-				while(*s)
-					*t++ = *s++;
-			}
-			*t = '\0';
-			t = str;
-			sprintf(elm, "%d", ++i);
-			w = getvar(elm, h, VAR);
-			if (isnum(str))
-				setfval(w, atof(str));
-			else
-				setsval(w, str);
-			if (*s)
-				s += r_length;
-		}
-	}
-	else {
-		skip = *sep == ' ';
-		for (i = 0; t = str, *s; ) {
-			if (skip)
-				while (jStrchr(" \t\n", *s))
-					s++;
-			if (!(*s))
-				break;
-			while (*s && !jStrchr(sep, *s)) {
-				if (isKanji(*s))
-					*t++ = *s++;
-				*t++ = *s++;
-			}
-			*t = '\0';
-			sprintf(elm, "%d", ++i);
-			w = getvar(elm, h, VAR);
-			if (isnum(str))
-				setfval(w, atof(str));
-			else
-				setsval(w, str);
-			if (*s && !skip)
-				s++;
-		}
-	}
-	c_free(v);	/* sep */
-	c_free(u);	/* str may be CATed */
-  }
-  else
-	i = 0;
-  return mktmp(NUM, (char *)NULL, (double) i);
-}
-
-CELL *
-Forin(p) NODE *p;
-{
-  CELL *u, *v;
-  SYMBOL **h, *q;
-  char *name;
-  int i;
-
-  u = execute(p->n_arg[1]);
-  if (!(u->c_type & ARR))
-	synerr(
-	"non array variable is specified in 'for (. in var)'", (char *)0);
-  h = (SYMBOL **) u->c_sval;
-  c_free(u);
-  u = execute(p->n_arg[0]);
-  if (u->c_type == UDF) {
-/*
-printf("Forin_fix_to_VAR|NUM\n");
-*/
-	u->c_type = VAR|NUM;
-  }
-  if (!(u->c_type & VAR))
-	error("'for (VAR in .)' is not variable (%d)", name, u->c_type);
-  for (i = 0; i < HASHSIZE; i++) {
-	for (q = h[i]; q; q = q->s_next) {
-		setsval(u, q->s_name);
-		v = execute(p->n_arg[2]);
-		c_free(v);
-	}
-  }
-  c_free(u);
-  return &truecell;
-}
-
-char *
-strsave(s) char *s;
-{
-  register int n;
-  char *emalloc(), *strcpy();
-
-  if (s == (char *)NULL)
-	return (char *)NULL;
-  n = strlen(s) + 1;
-  return strcpy(emalloc(n), s);
-}
-
-sfree(p) char *p;
-{
-  if (p != (char *)NULL)
-	Free(p);
-}
-
-isnum(s) char *s;
-{
-  char *strchr();
-
-  if (s == NULL || *s == '\0' || !strcmp(s, "."))
-	return 0;
-  if (*s && strchr("+-", *s) != (char *)NULL)
-	s++;
-  if (*s == '\0')
-	return 0;
-  while (isdigit(*s))
-	s++;
-  if (*s == '.') {
-	s++;
-	while (isdigit(*s))
-		s++;
-  }
-  if (*s && strchr("eE", *s) != (char *)NULL) {
-	s++;
-	if (*s == '\0')
-		return 0;
-	if (*s && strchr("+-", *s) != (char *)NULL)
-		s++;
-	while (isdigit(*s))
-		s++;
-  }
-  return *s == '\0';
-}
-
-setfval(u, f) CELL *u; double f;
-{
-  if (u->c_type == UDF) {	/* fix up local var */
-/*
-printf("setfval_fix_to_VAR\n");
-*/
-	u->c_type |= VAR;
-  }
-  if (u->c_type & (VAR|FLD|REC|TMP)) {
-	u->c_type &= ~STR;
-	u->c_type |= NUM;
-	sfree(u->c_sval);
-	u->c_sval = (char *)NULL;
-	u->c_fval = f;
-	if (u->c_type & FLD)
-		mkrec(u);
-  }
-  else
-	fprintf(stderr, "assign to nonvariable (%d)\n", u->c_type);
-}
-
-setsval(u, s) CELL *u; char *s;
-{
-  double atof();
-
-  if (u->c_type == UDF) {	/* fix up local var */
-/*
-printf("setsval_fix_to_VAR\n");
-*/
-	u->c_type |= VAR;
-  }
-  if (u->c_type & (VAR|FLD|REC|TMP)) {
-	u->c_type &= ~NUM;
-	u->c_type |= STR;
-	sfree(u->c_sval);
-	u->c_sval = strsave(s);
-#if 0	/* "table2" in AWK book */
-	if (isnum(u->c_sval)) {
-		u->c_fval = atof(u->c_sval);
-		u->c_type |= NUM;
-	}
-	else
-#endif
-		u->c_fval = 0.0;
-	if (u->c_type & FLD)
-		mkrec(u);
-  }
-  else
-	fprintf(stderr, "assign to constant (%d)\n", u->c_type);
-}
-
-double
-getfval(u) CELL *u;
-{
-  double x, atof();
-
-  if (u->c_type == UDF) {	/* local var */
-	u->c_type |= VAR|STR|NUM;
-	u->c_sval = strsave("");
-	x = u->c_fval = 0.0;
-  }
-  else if (u->c_type & NUM)
-	x = u->c_fval;
-#if 1
-  else {
-	x = atof(u->c_sval);
-#else
-  else {
-	if (isnum(u->c_sval))
-		x = atof(u->c_sval);
-	else
-		x = 0.0;
-#endif
-  }
-  return x;
-}
-
-char *
-getsval(u) CELL *u;
-{
-  char *s, str[80];
-
-  if (u->c_type & STR)
-	s = u->c_sval;
-  else if (u->c_type & NUM) {
-/*	if (u->c_fval >= -2147483648.0 && u->c_fval <= 2147483647.0)*/
-	if ((long)u->c_fval == u->c_fval)
-		s = "%.16g";
-	else
-		s = *OFMT;
-	sprintf(str, s, u->c_fval);
-	sfree(u->c_sval);
-	s = u->c_sval = strsave(str);
-  }
-#if 1
-  else if (u->c_type == UDF) {	/* local var */
-/*
-printf("getsval_fix_to_VAR|STR\n");
-*/
-	u->c_type |= VAR|STR|NUM;
-	s = u->c_sval = strsave("");
-	u->c_fval = 0.0;
-  }
-#endif
-  else
-	fprintf(stderr, "abnormal value (STR|NUM == 0)(%d)\n", u->c_type);
-  return s;
-}
-
-char *
-emalloc(n) unsigned n;
-{
-  char *p;
-#if 0
-  char far *_fmalloc();
-#else
-  char *malloc();
-#endif
-
-#if 0
-  if ((p = _fmalloc(n)) == (char *)NULL)
-#else
-  if ((p = malloc(n)) == (char *)NULL)
-#endif
-	error("memory over");
-  return p;
-}
-
-Free(s) char *s;
-{
-#if DOS
-  void _ffree();
-
-  _ffree(s);
-#else
-  free(s);
-#endif
-}
Index: trunk/minix/commands/awk/y.c
===================================================================
--- trunk/minix/commands/awk/y.c	(revision 9)
+++ 	(revision )
@@ -1,1087 +1,0 @@
-/*
- * a small awk clone
- *
- * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
- *
- * Absolutely no warranty. Use this software with your own risk.
- *
- * Permission to use, copy, modify and distribute this software for any
- * purpose and without fee is hereby granted, provided that the above
- * copyright and disclaimer notice.
- *
- * This program was written to fit into 64K+64K memory of the Minix 1.2.
- */
-
-
-#include <stdio.h>
-#include "awk.h"
-
-extern char *mkpat();
-
-extern char *cmd;
-extern char text[];
-extern char funnam[];
-extern int sym;
-extern int sym1;
-extern int regexflg;
-extern int funflg;
-extern int printflg;
-extern int getlineflg;
-
-extern SYMBOL *hashtab[], *funtab[];
-
-extern CELL *field[];
-
-char *emalloc(), *strsave();
-NODE *node0(), *node1(), *node2(), *node3(), *node4();
-NODE *stat(), *pastat();
-NODE *expr(), *expr1(), *expr2(), *expr3(), *expr4();
-NODE *expr5(), *expr6(), *expr7(), *expr8(), *expr9(), *expr10();
-NODE *doprint(), *dofuncn(), *doif(), *dowhile(), *dofor(), *body();
-NODE *doassign(), *dodo(), *doarray(), *doreturn(), *doelement();
-CELL *mkcell(), *getvar();
-CELL *execute(), *lookup();
-
-int forflg;	/* parsing for(expr in array), inhibit 'expr in array' */
-int prmflg;	/* parsing pass parameters */
-NODE *begin, *loop, *End;
-
-parse()
-{
-  NODE *p, *q, *r, *stat();
-  CELL *u;
-
-  lex();
-  skipeol();
-  while (sym) {
-	switch (sym) {
-	case BEGIN:
-		lex();
-		begin = stat();
-		break;
-	case END:
-		lex();
-		if (End == NULL)
-			End = stat();
-		else {
-			for (p = End; p; p = q) {
-				if ((q = p->n_next) == NULL)
-					p->n_next = stat();
-			}
-		}
-		break;
-	case FUNC:
-		lex();
-		dousrfun();
-		break;
-	default:
-		q = loop = pastat();
-		skipeol();
-		while (sym &&  sym != BEGIN && sym != END && sym != FUNC) {
-			r = pastat();
-			q->n_next = r;
-			q = r;
-			skipeol();
-		}
-		break;
-	}
-	skipeol();
-  }
-  if (begin) {
-	u = execute(begin);
-	c_free(u);
-  }
-  if (End || loop)
-	while (Getrec(NULL)) {
-		if (loop) {
-			u = execute(loop);
-			c_free(u);
-		}
-	}
-  if (End) {
-	u = execute(End);
-	c_free(u);
-  }
-}
-
-#define MAXARG		100
-static char *argnam[MAXARG];
-static int narg;
-
-static
-dousrfun()
-{
-  CELL *u;
-
-  strcpy(funnam, text);
-  u = getvar(text, funtab, FUN);
-  lex();
-  if (sym != '(')
-	synerr("'(' expected");
-  for (lex(); sym != ')'; narg++) {
-	if (sym != IDENT)
-		synerr("argument expected");
-	argnam[narg] = strsave(text);
-	lex();
-	if (sym == ',')
-		lex();
-  }
-  u->c_fval = (double) narg;
-  lex();
-  skipeol();
-  funflg++;
-  u->c_sval = (char *) stat();
-  funflg--;
-  if (narg > 0) {
-	do {
-		sfree(argnam[--narg]);
-	} while (narg > 0);
-  }
-  skipeol();
-}
-
-isarg(s) char *s;
-{
-  int i;
-
-  if (narg > 0) {
-	for (i = narg - 1; i >= 0; i--)
-		if (strcmp(s, argnam[i]) == 0)
-			break;
-  }
-  else
-	i = -1;
-  return i;
-}
-
-/*
-interactive()
-{
-  NODE *p, *q;
-  CELL *u;
-
-  for (lex(); sym; lex()) {
-	p = stat();
-	if (p->n_type != PRINT && !iscntl(p->n_type)) {
-		q = (NODE *) emalloc(sizeof(NODE) + sizeof(NODE *) * 4);
-		q->n_type = PRINT;
-		q->n_arg[0] = q->n_arg[1] = q->n_arg[3] = NULL;
-		q->n_arg[2] = p;
-		q->n_next = NULL;
-		p = q;
-	}
-	u = execute(p);
-	printf("[%g(%s)]\n", u->c_fval, u->c_sval);
-	c_free(u);
-  }
-  closeall();
-  exit(0);
-}
-*/
-
-static
-iscntl(t)
-{
-  static int tab[] = {
-	IF, DO, WHILE, FOR, JUMP, GETLINE, 0
-  };
-  int i;
-
-  for (i = 0; tab[i]; i++)
-	if (t == tab[i])
-		break;
-  return tab[i];
-}
-
-static NODE *
-pastat()
-{
-  NODE *p, *q, *r;
-
-  if (sym == '{')	/* action only */
-	p = stat();
-  else {	/* exp [, expr] [{ .. }] */
-	p = expr();
-	if (sym == ',') {
-		lex();
-		q = expr();
-	}
-	else
-		q = NULL;
-	if (sym && sym != EOL)
-		r = stat();
-	else
-		r = node0(PRINT0);
-	if (q)
-		p = node3(P2STAT, p, q, r);
-	else
-		p = node2(P1STAT, p, r);
-  }
-  return p;
-}
-
-static NODE *
-stat()
-{
-  NODE *p, *q, *r;
-  CELL *u, *v;
-  int op;
-
-/*printf("@stat(%d)(%s)\n", sym, text);*/
-  while (sym == EOL)
-	lex();
-  switch(sym) {
-  case PRINT:
-	p = doprint(0);
-	break;
-  case PRINTF:
-	p = doprint(FORMAT);
-	break;
-  case IF:
-	p = doif();
-	break;
-  case WHILE:
-	p = dowhile();
-	break;
-  case DO:
-	p = dodo();
-	break;
-  case FOR:
-	p = dofor();
-	break;
-  case RETURN:
-	p = doreturn();
-	break;
-  case EXIT:
-	p = node2(JUMP, (NODE *)sym, (NODE *)NULL);
-	lex();
-	if (sym == IDENT || sym == NUMBER || sym == ARG)
-		p->n_arg[1] = expr();
-	break;
-  case BREAK: case CONTIN: case NEXT:
-	p = node1(JUMP, (NODE *)sym);
-	lex();
-	break;
-  case DELETE:
-	lex();
-	u = getvar(text, hashtab, ARR);
-	if (Getc() != '[')
-		synerr("'[' expected");
-	p = doarray(u);
-	p->n_type = DELETE;
-	lex();	/* ']' */
-	break;
-  case '{':
-	lex();
-	skipeol();
-	if (sym == '}')
-		p = node0(NULPROC);
-	else
-		p = q = stat();
-	skipeol();
-	while (sym != '}') {
-		r = stat();
-		q->n_next = r;
-		q = r;
-		skipeol();
-	}
-	lex();
-	break;
-  default:
-	p = expr();
-#if 0
-	if (sym == BINOR) {	/* expr | GETLINE */
-		lex();
-		if (sym != GETLINE)
-			synerr("'GETLINE' expected");
-		lex();
-		if (sym == IDENT || sym == STRING || sym == ARG) {
-			q = expr();
-		}
-		else
-			q = NULL;
-		p = node3(GETLINE, q, p, (NODE *)R_PIN);
-	}
-#endif
-	break;
-  }
-  if (p->n_type == VALUE)
-	synerr("statement expected");
-  return p;
-}
-
-static
-skipeol()
-{
-  while (sym == EOL)
-	lex();
-}
-
-static NODE *
-doprint(fmt)
-{
-  NODE *p, *q, *r;
-  CELL *u;
-  int i, op;
-  int n = 0;
-
-  printflg++;
-  lex();
-  if (sym == '(')
-	lex();
-  if (sym != '}' && sym != ')' && sym != EOL && sym != R_OUT && sym != R_APD
-	&& sym != R_POUT) {
-	p = q = expr(); n++;
-	while (sym == ',') {
-  		lex();
-		skipeol();
-	  	r = expr(); n++;
-		q->n_next = r;
-	  	q = r;
-	}
-  }
-  if (sym == ')')
-	lex();
-  if (sym == R_OUT || sym == R_APD || sym == R_POUT) {
-	op = sym;
-	lex();
-/*	q = expr10();*/
-	q = expr();	/* 94-04-02 */
-  }
-  else
-	q = (NODE *) (op = 0);	/* stdout */
-  printflg = 0;
-  r = (NODE *) emalloc(sizeof(*r) + sizeof(r) * (n + 3));
-  r->n_type = PRINT;	/* convert list to arg */
-  r->n_next = NULL;
-  r->n_arg[0] = (NODE *) (op | fmt);
-  r->n_arg[1] = q;
-  if (n == 0) {
-	p = node1(VALUE, (NODE *)field[0]);
-  }
-  for (i = 2; p != NULL; i++) {
-	r->n_arg[i] = p;
-	q = p->n_next;
-	p->n_next = NULL;
-	p = q;
-  }
-  r->n_arg[i] = NULL;
-  return r;
-}
-
-static NODE *
-doif()
-{
-  NODE *p, *q, *r;
-
-  lex();
-  if (sym != '(')
-	synerr("'(' expected");
-  lex();
-  p = expr();
-  if (sym != ')')
-	synerr("')' expected");
-  lex();
-  skipeol();
-  q = stat();
-  skipeol();
-  if (sym == ELSE) {
-	lex();
-	skipeol();
-	r = stat();
-  }
-  else
-	r = NULL;
-  return node3(IF, p, q, r);
-}
-
-static NODE *
-dowhile()
-{
-  NODE *p, *q;
-
-  lex();
-  if (sym != '(')
-	synerr("'(' expected");
-  lex();
-  p = stat();
-  if (sym != ')')
-	synerr("')' expected");
-  q = body();
-  return node2(WHILE, p, q);
-}
-
-static NODE *
-dofor()
-{
-  NODE *p, *q, *r, *s;
-  CELL *u;
-  int i;
-
-  lex();
-  if (sym != '(')
-	synerr("'(' expected");
-  lex();
-  if (sym != EOL) {
-	forflg++;	/* inhibit parsing 'expr IN array' */
-	p = expr();
-	forflg = 0;
-  }
-  else
-	p = NULL;
-  if (sym == IN) {
-	lex();
-	if (sym == ARG) {
-/*
-printf("***FOR_IN_ARG(%d)***\n", sym);
-*/
-		u = mkcell(POS, NULL, (double)sym1);
-		q = node1(ARG, u);
-	}
-	else {
-		u = getvar(text, hashtab, ARR);
-		q = node1(VALUE, u);
-	}
-	lex();
-	if (sym != ')')
-		synerr("')' expected");
-	lex();
-	skipeol();
-	s = stat();
-	r = node3(FORIN, p, q, s);
-  }
-  else {
-	if (sym != EOL)
-		synerr("'in' or ';' expected");
-	lex();
-	if (sym != EOL)
-		q = expr();
-	else
-		q = NULL;
-	if (sym != EOL)
-		synerr("';' expected");
-	lex();
-	if (sym != ')')
-		r = expr();
-	else
-		r = NULL;
-	if (sym != ')')
-		synerr("')' expected");
-	s = body();
-	r = node4(FOR, p, q, r, s);
-  }
-  return r;
-}
-
-static NODE *
-body()
-{
-  NODE *r;
-
-  while ((sym = Getc()) == '\n' || sym == ' ' || sym == '\t')
-	;
-  if (sym == ';') {
-	r = node0(NULPROC);
-	lex();
-  }
-  else {
-	Ungetc(sym);
-	lex();
-	r = stat();
-  }
-  return r;
-}
-
-static NODE *
-dodo()
-{
-  NODE *p, *q;
-
-  lex();
-  skipeol();
-  p = stat();
-  skipeol();
-  if (sym != WHILE)
-	synerr("'while' expected");
-  lex();
-  if (sym != '(')
-	synerr("'(' expected");
-  lex();
-  q = stat();
-  if (sym != ')')
-	synerr("')' expected");
-  lex();
-  return node2(DO, p, q);
-}
-
-static NODE *
-doreturn()
-{
-  NODE *p, *q, *r;
-  int i, n = 0;
-
-  if (lex() != EOL) {
-	p = q = expr(); n++;
-	while (sym == ',') {
-		lex(); skipeol();
-		r = expr(); n++;
-		q ->n_next = r;
-		q = r;
-	}
-  }
-  else
-	p = (NODE *)NULL;
-
-  r = (NODE *) emalloc(sizeof(*r) + sizeof (r) * (n + 1));
-  r->n_type = JUMP;
-  r->n_next = NULL;
-  r->n_arg[0] = (NODE *) RETURN;
-  for (i = 1; p != NULL; i++) {
-	r->n_arg[i] = p;
-	q = p->n_next;
-	p->n_next = NULL;
-	p = q;
-  }
-  r->n_arg[i] = NULL;
-  return r;
-}
-
-static NODE *
-expr()
-{
-  NODE *p;
-
-  p = expr1();
-  if (isassign(sym))
-	p = doassign(sym, p);
-  return p;
-}
-
-static isassign(sym)
-{
-  return (sym == ASSIGN || sym == ADDEQ || sym == SUBEQ || sym == MULTEQ
-  	|| sym == DIVEQ || sym == MODEQ || sym == POWEQ);
-}
-
-static NODE *
-doassign(op, p) NODE *p;
-{	/* evaluate right to left */
-  NODE *q;
-
-  lex();
-  q = expr();
-  if (isassign(sym))
-	q = doassign(sym, q);
-  return node3(ASSIGN, (NODE *)op, p, q);
-}
-
-static NODE *
-expr1()
-{
-  NODE *p, *q;
-
-/*
-printf("expr1(%d)(%s)\n", sym, text);
-*/
-  p = expr2();
-  if (sym == '?') {
-	lex();
-#if 0
-	q = stat();
-	if (sym != ':')
-		synerr("':' expected");
-	lex();
-	return node3(IF, p, q, stat());
-#else
-	q = expr();
-	if (sym != ':')
-		synerr("':' expected");
-	lex();
-	return node3(IF, p, q, expr());
-#endif
-  }
-  return p;	/* 930213 */
-}
-
-static NODE *
-expr2()
-{
-  NODE *p;
-
-/*
-printf("expr2(%d)(%s)\n", sym, text);
-*/
-  p = expr3();
-  while (sym == OR) {
-	lex();
-	skipeol();
-	p = node3(COND, (NODE *)OR, p, expr3());
-  }
-  return p;
-}
-
-static NODE *
-expr3()
-{
-  NODE *p;
-
-/*
-printf("expr3(%d)(%s)\n", sym, text);
-*/
-  p = expr4();
-  while (sym == AND) {
-	lex();
-	skipeol();
-	p = node3(COND, (NODE *)AND, p, expr4());
-  }
-  return p;
-}
-
-static NODE *
-expr4()
-{
-  NODE *p;
-  CELL *q;
-  int op;
-
-/*
-printf("expr4(%d)(%s)\n", sym, text);
-*/
-  p = expr5();
-  if (!forflg && sym == IN) {
-	lex();
-	q = getvar(text, hashtab, ARR);
-	lex();
-	return node2(IN, p, q);
-  }
-  while (sym == EQ || sym == NE || sym == LT || sym == LE  || sym == GT
-	|| sym == GE || sym == MATCH || sym == NOMATCH) {
-	op = sym;
-	lex();
-	p = node3(COND, (NODE *)op, p, expr5());
-  }
-  return p;
-}
-
-static NODE *
-expr5()
-{
-  NODE *p, *q;
-
-/*
-printf("expr5(%d)(%s)\n", sym, text);
-*/
-  p = expr6();
-  while (iscat(sym)) {
-	q = expr6();
-	p = node2(CAT, p, q);
-  }
-  return p;
-}
-
-static iscat(sym)
-{
-  static int ctab[] = {
-	ADD, SUB, MULT, DIV, MOD, INC, DEC, STRING, NUMBER, IDENT, '(',
-	MATHFUN, STRFUN, SPRINTF, '$', SUBST, ARG, CALL, 0
-	};
-  register int i, j;
-
-  for (i = 0; j = ctab[i]; i++)
-	if (sym == j)
-		break;
-  return j;
-}
-
-static NODE *
-expr6()
-{
-  register int sign = sym;
-  NODE *p, *q;
-
-/*
-printf("expr6(%d)(%s)\n", sym, text);
-*/
-  if (sym == SUB || sym == ADD)
-	lex();
-  p = expr7();
-  if (sign == SUB)
-	p = node2(ARITH, (NODE *)UMINUS, p);
-  while (sym == ADD || sym == SUB) {
-	sign = sym;
-	lex();
-	q = expr7();
-	if (sign == ADD) {
-		p = node3(ARITH, (NODE *)ADD, p, q);
-	}
-	else if (sign == SUB) {
-		p = node3(ARITH, (NODE *)SUB, p, q);
-	}
-	else
-		synerr("'+' or '-' expected");
-  }
-  return p;
-}
-
-static NODE *
-expr7()
-{
-  register int op;
-  NODE *p, *q;
-
-/*
-printf("expr7(%d)(%s)\n", sym, text);
-*/
-  p = expr8();
-  while (sym == MULT || sym == DIV || sym == MOD) {
-	op = sym;
-	lex();
-	q = expr8();
-	switch (op) {
-	case MULT:	p = node3(ARITH, (NODE *)MULT, p, q); break;
-	case DIV:	p = node3(ARITH, (NODE *)DIV, p, q); break;
-	case MOD:	p = node3(ARITH, (NODE *)MOD, p, q); break;
-	default:	synerr("'*', '/' or '%' expected"); break;
-	}
-  }
-  return p;
-}
-
-static NODE *
-expr8()
-{
-  NODE *p;
-  int op;
-
-/*
-printf("expr8(%d)(%s)\n", sym, text);
-*/
-  if (sym == NOT) {
-	lex();
-	p = node2(COND, (NODE *)NOT, expr9());
-  }
-  else {
-	p = expr9();
-	if (sym == POWER) {
-		lex();
-		p = node3(ARITH, (NODE *)POWER, p, expr9());
-	}
-  }
-  return p;
-}
-
-static NODE *
-expr9()
-{
-  NODE *p, *q;
-  int op, sym0;
-
-/*
-printf("expr9(%d)(%s)\n", sym, text);
-*/
-  if (op = isincdec(sym)) {
-	lex();
-	if (sym != IDENT && sym != ARG)
-		synerr("illegal '++/--' operator");
-	p = expr10();
-	p = node4(ARITH, (NODE *)INCDEC, p, (NODE *)op, (NODE *)PRE);
-  }
-  else {
-	sym0 = sym;
-	p = expr10();
-	if (op = isincdec(sym)) {
-/*printf("POST(%d)(%d)(%s)\n", sym, sym0, text);*/
-		if (sym0 == IDENT || sym0 == ARG) {
-			p = node4(ARITH, (NODE *)INCDEC, p, (NODE *)op,
-				(NODE *)POST);
-			lex();
-		}
-	}
-	if (sym == BINOR) {	/* | getline */
-		lex();
-		if (sym != GETLINE)
-			synerr("'GETLINE' expected");
-		lex();
-		if (sym == IDENT || sym == STRING || sym == ARG) {
-			q = expr();
-		}
-		else
-			q = NULL;
-		p = node3(GETLINE, q, p, (NODE *)R_PIN);
-	}
-  }
-  return p;
-}
-
-static isincdec(sym)
-{
-  return sym == INC ? 1 : (sym == DEC ? -1 : 0);
-}
-
-static NODE *
-expr10()
-{
-  NODE *p, *q;
-  CELL *u, *v;
-  int op;
-  int c;
-int gsave, psave;
-  double atof();
-
-/*
-printf("expr10(%d)(%s)\n", sym, text);
-*/
-  switch (sym) {
-  case STRING:
-	u = mkcell(STR, text, 0.0);
-	goto g1;
-  case NUMBER:
-	u = mkcell(NUM, NULL, atof(text));
-g1:
-	p = node1(VALUE, u);
-	lex();
-	break;
-  case IDENT: case ARG:
-	if ((c = Getc()) == '[') {	/* array */
-		/* 940403 */
-		if (sym == ARG) {
-			u = (CELL *)emalloc(sizeof(CELL));
-			u = mkcell(POS, NULL, (double)sym1);
-			p = doarray(u);
-		}
-		else {
-			u = getvar(text, hashtab, ARR);
-			p = doarray(u);
-		}
-	}
-	else {
-		Ungetc(c);
-		if (sym == ARG) {
-			u = mkcell(POS, NULL, (double)sym1);
-			p = node1(ARG, u);
-		}
-		else {	/* symple variable */
-			u = getvar(text, hashtab, VAR|STR|NUM);
-			p = node1(VALUE, u);
-		}
-	}
-	lex();
-	break;
-  case '(':
-	/* print >(x ? y : z) needs this */
-gsave = getlineflg; psave = printflg;
-getlineflg = printflg = 0;
-	lex();
-	p = expr();
-	if (sym == ',')	/* (expr, expr, .. ) */
-		p = doelement(p);
-	if (sym != ')')
-		synerr("')' expected");
-getlineflg = gsave; printflg = psave;
-	lex();
-	break;
-  case CALL:
-	p = dofuncn(sym, getvar(text, funtab, UDF));
-	break;
-  case MATHFUN: case STRFUN: case SUBST:
-	p = dofuncn(sym, (CELL *)sym1);
-	break;
-  case SPRINTF:
-	p = doprint(FORMAT|STROUT);
-	break;
-  case '$':
-	lex();
-	switch (sym) {
-	case NUMBER:
-		u = mkcell(NUM, NULL, atof(text));
-		p = node1(VALUE, u);
-		p = node1(FIELD, p);
-		lex();
-		break;
-	case IDENT: case ARG: case '(':
-		p = node1(FIELD, expr10());
-		break;
-	default:
-		synerr("number or identifier expected after '$'", (char *)0);
-	}
-	break;
-  case DIV:
-	regexflg++;
-	lex();
-	regexflg = 0;
-	u = mkcell(PAT, NULL, 0.0);
-	u->c_sval = (char *) mkpat(text);
-	p = node1(VALUE, u);
-	lex();
-	break;
-  case GETLINE:
-	getlineflg++;
-	lex();
-	if (sym == IDENT || sym == STRING || sym == ARG)
-		q = expr10();	/* read into var */
-	else
-		q = NULL;
-	getlineflg = 0;
-	if (sym == R_IN) {
-		op = R_IN;
-		lex();
-		p = expr10();
-	}
-	else
-		op = (int) (p = NULL);
-	p = node3(GETLINE, q, p, (NODE *)op);
-	break;
-  default:
-	synerr(
-	"identifier, number, string, argument, regexpr, call or '(' expected");
-	break;
-  }
-  return p;
-}
-
-static NODE *
-dofuncn(fun, op) CELL *op;
-{
-  NODE *p;
-  int i, j;
-  int n = 0;
-  NODE *a[100];
-
-  if (lex() == '(') {
-	prmflg++;
-	for (lex(); sym && (sym != ')'); n++) {
-		if ((int)op == SPLIT && n == 1) {
-/*
-printf("sym(%d)sym1(%d)(%d)\n", sym, sym1, isarg(text));
-*/
-			if (sym != ARG) {	/*isarg(text) == -1*/
-				/* make an array if not exist */
-				prmflg = 0;
-				getvar(text, hashtab, ARR);
-				prmflg++;
-			}
-		}
-		a[n] = expr();
-		if (sym == ',')
-			lex();
-		else if (sym != ')')
-			synerr("',' or ')' expected");
-	}
-	prmflg = 0;
-
-	if (sym == ')')
-		lex();
-	else
-		synerr("')' expected");
-  }
-  p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * (n + 2));
-  p->n_type = fun;
-  p->n_next = NULL;
-  p->n_arg[0] = (NODE *) op;
-  p->n_arg[1] = (NODE *) n;
-  for (i = 0, j = 2; i < n; )
-	p->n_arg[j++] = a[i++];
-  p->n_arg[j] = NULL;
-  return p;
-}
-
-static NODE *
-doarray(u) CELL *u;
-{
-  NODE *p;
-  int i, j;
-  int n;
-  NODE *a[20];
-
-  for (lex(), n = 0; sym &&  sym != ']'; n++) {
-	a[n] = expr();
-	if (sym == ',')
-		lex();
-  }
-  if (sym != ']')
-	synerr("']' expected");
-  /* left ']' for expr10() */
-  p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * (n + 1));
-  p->n_type = ARRAY;
-  p->n_next = NULL;
-  p->n_arg[0] = (NODE *)u;
-  p->n_arg[1] = (NODE *) n;
-  for (i = 0, j = 2; i < n; )
-	p->n_arg[j++] = a[i++];
-  return p;
-}
-
-static NODE *
-doelement(q) NODE *q;
-{
-  NODE *p;
-  int i, j;
-  int n;
-  NODE *a[20];
-
-  a[0] = q;
-  for (lex(), n = 1; sym &&  sym != ')'; n++) {
-	a[n] = expr();
-	if (sym == ',')
-		lex();
-	else if (sym != ')')
-		synerr("',' or ')' expected");
-  }
-  /* left ')' for expr10() */
-  p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * (n + 1));
-  p->n_type = ELEMENT;
-  p->n_next = NULL;
-  p->n_arg[0] = NULL;
-  p->n_arg[1] = (NODE *) n;
-  for (i = 0, j = 2; i < n; )
-	p->n_arg[j++] = a[i++];
-  return p;
-}
-
-synerr(s, t) char *s, *t;
-{
-  extern int lineno;
-  extern char line[], *linep;
-  int c, i;
-  char *u, *v;
-
-  fprintf(stderr, "%s: Syntax error at line %d", cmd, lineno);
-  if (funflg)
-	fprintf(stderr, " in function %s", funnam);
-  fprintf(stderr, ":\n");
-  if ((v = linep - 1) < line)
-	v = line + BUFSIZ - 1;
-  for (i = 0, u = v - 1; ; --u) {
-	if (u < line) {
-		if (line[BUFSIZ - 1] == '\0')
-			break;
-		u = line + BUFSIZ - 1;
-	}
-	if (*u == '\n' && ++i == 2)
-		break;
-  }
-  if (u != v) {
-	while (u != v) {
-		fputc(*u, stderr);
-		if ((++u - line) == BUFSIZ)
-			u = line;
-	}
-	if (*u != '\n')
-		fputc(*u, stderr);
-	fprintf(stderr, " <--\n\n");
-/*
-	fprintf(stderr, " <-- ");
-	while ((c = Getc()) != EOF && c != '\n')
-		fputc(c, stderr);
-	fprintf(stderr, "\n");
-	if (c == EOF);
-		fprintf(stderr, "\n");
-*/
-  }
-  fprintf(stderr, s, t);
-  fprintf(stderr, "\n");
-#ifdef DOS
-  closeall();
-#endif
-  exit(1);
-}
Index: trunk/minix/commands/bc/COPYING
===================================================================
--- trunk/minix/commands/bc/COPYING	(revision 9)
+++ 	(revision )
@@ -1,346 +1,0 @@
-
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-                          675 Mass Ave, Cambridge, MA 02139, USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-
-	Appendix: How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) 19yy  <name of author>
-
-    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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) 19yy name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
-
Index: trunk/minix/commands/bc/Makefile
===================================================================
--- trunk/minix/commands/bc/Makefile	(revision 9)
+++ 	(revision )
@@ -1,89 +1,0 @@
-# Makefile for bc
-
-# A makefile for bc.  This is part of the bc/sbc distribution.
-#
-#
-#  Make sure these have the correct directories for your machine.
-#
-#  LIBDIR and BINDIR are where bc and libmath.b will be put.
-#
-PREFIX = /usr
-LIBDIR = $(PREFIX)/lib
-BINDIR = $(PREFIX)/bin
-#
-# Programs definitions for use by make.
-#
-SHELL = /bin/sh
-YACC = yacc
-#YACC = bison -y
-LEX = flex -I8
-#LEX = lex
-CC = exec cc
-CFLAGS = -D_POSIX_SOURCE
-LDFLAGS = -i
-#
-#
-OFILES = scan.o util.o main.o number.o storage.o load.o execute.o 
-#
-SUBDIRS = Examples Test
-#
-
-
-all: bc
-bc: $& config.h bc.o $(OFILES) global.o
-	$(CC) -o bc $(LDFLAGS) bc.o $(OFILES) global.o
-
-sbc: sbc.o $(OFILES) global.o
-	$(CC) -o sbc $(LDFLAGS) sbc.o $(OFILES) global.o
-
-math.h: libmath.b
-	$(MAKE) -$(MAKEFLAGS) fbc
-	./fbc -c libmath.b </dev/null >math.h
-	/bin/sh ./fix_math.h
-	rm -f ./fbc
-
-fbc: $(OFILES) bc.o
-	echo \"\" > math.h
-	$(CC) -c $(CFLAGS) global.c
-	$(CC) -o fbc $(LDFLAGS) bc.o $(OFILES) global.o
-
-install:	$(BINDIR)/bc $(LIBDIR)/libmath.b
-
-$(BINDIR)/bc:	bc
-	install -cs -o bin $? $@
-
-$(LIBDIR)/libmath.b:	libmath.b
-	install -c -o bin $? $@
-
-clean:
-	rm -f *.o *.bak core math.h bc sbc
-
-scan.c: scan.l
-	$(LEX) scan.l
-	mv lex.yy.c scan.c
-
-scan.o:	scan.c
-	$(CC) -c $(CFLAGS) -wa scan.c
-
-y.tab.h bc.c: bc.y
-	@echo "expect 1 shift/reduce conflict"
-	$(YACC) -d bc.y
-	mv y.tab.c bc.c
-
-sbc.c: sbc.y
-	$(YACC) -d sbc.y
-	mv y.tab.c sbc.c
-
-global.o: bcdefs.h global.h math.h
-bc.o:	bcdefs.h global.h 
-execute.o: bcdefs.h global.h
-load.o: bcdefs.h global.h 
-main.o: bcdefs.h global.h version.h
-number.o: bcdefs.h
-sbc.o: bcdefs.h global.h 
-scan.o: y.tab.h bcdefs.h global.h
-storage.o: bcdefs.h global.h
-util.o: bcdefs.h global.h version.h
-
-bcdefs.h: number.h const.h config.h
-	touch bcdefs.h
Index: trunk/minix/commands/bc/bc.c
===================================================================
--- trunk/minix/commands/bc/bc.c	(revision 9)
+++ 	(revision )
@@ -1,1373 +1,0 @@
-#ifndef lint
-static char yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93";
-#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"
-#line 2 "bc.y"
-/* bc.y: The grammar for a POSIX compatable bc processor with some
-         extensions to the language. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "global.h"
-#include "proto.h"
-#line 38 "bc.y"
-typedef union {
-	char	 *s_value;
-	char	  c_value;
-	int	  i_value;
-	arg_list *a_value;
-       } YYSTYPE;
-#line 52 "y.tab.c"
-#define NEWLINE 257
-#define AND 258
-#define OR 259
-#define NOT 260
-#define STRING 261
-#define NAME 262
-#define NUMBER 263
-#define MUL_OP 264
-#define ASSIGN_OP 265
-#define REL_OP 266
-#define INCR_DECR 267
-#define Define 268
-#define Break 269
-#define Quit 270
-#define Length 271
-#define Return 272
-#define For 273
-#define If 274
-#define While 275
-#define Sqrt 276
-#define Else 277
-#define Scale 278
-#define Ibase 279
-#define Obase 280
-#define Auto 281
-#define Read 282
-#define Warranty 283
-#define Halt 284
-#define Last 285
-#define Continue 286
-#define Print 287
-#define Limits 288
-#define UNARY_MINUS 289
-#define YYERRCODE 256
-short yylhs[] = {                                        -1,
-    0,    0,   10,   10,   10,   11,   11,   11,   11,   12,
-   12,   12,   12,   12,   12,   15,   15,   13,   13,   13,
-   13,   13,   13,   13,   13,   13,   13,   16,   17,   18,
-   19,   13,   20,   13,   22,   23,   13,   13,   25,   13,
-   24,   24,   26,   26,   21,   27,   21,   28,   14,    5,
-    5,    6,    6,    6,    7,    7,    7,    7,    8,    8,
-    9,    9,    9,    9,    4,    4,    2,    2,   29,    1,
-   30,    1,   31,    1,    1,    1,    1,    1,    1,    1,
-    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-    1,    3,    3,    3,    3,    3,    3,
-};
-short yylen[] = {                                         2,
-    0,    2,    2,    1,    2,    0,    1,    3,    2,    0,
-    1,    2,    3,    2,    3,    1,    2,    1,    1,    1,
-    1,    1,    1,    1,    1,    1,    4,    0,    0,    0,
-    0,   13,    0,    7,    0,    0,    7,    3,    0,    3,
-    1,    3,    1,    1,    0,    0,    3,    0,   12,    0,
-    1,    0,    3,    3,    1,    3,    3,    5,    0,    1,
-    1,    3,    3,    5,    0,    1,    0,    1,    0,    4,
-    0,    4,    0,    4,    2,    3,    3,    3,    3,    3,
-    2,    1,    1,    3,    4,    2,    2,    4,    4,    4,
-    3,    1,    4,    1,    1,    1,    1,
-};
-short yydefred[] = {                                      1,
-    0,    0,    0,   21,    0,   83,    0,    0,   22,   24,
-    0,    0,   28,    0,   35,    0,    0,   94,   95,    0,
-   18,   25,   97,   23,   39,   19,    0,    0,    0,    0,
-    0,    2,    0,   16,    4,    7,    5,   17,    0,    0,
-    0,    0,   96,   86,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,   81,    0,    0,    0,   11,   71,
-   73,    0,    0,    0,    0,    0,   69,   87,    3,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,   91,   43,    0,   40,    0,   84,
-    0,    0,   38,    0,    0,    0,    0,    0,    0,    0,
-    0,    8,    0,   85,    0,   93,    0,    0,    0,   88,
-   27,    0,    0,   33,    0,   89,   90,    0,   13,   15,
-    0,    0,    0,   62,    0,    0,    0,    0,    0,   29,
-    0,    0,   42,    0,   56,    0,    0,    0,    0,    0,
-   64,    0,    0,    0,   46,   34,   37,    0,   48,   58,
-   30,    0,    0,    0,    0,   47,   53,   54,    0,    0,
-    0,   31,   49,    0,   32,
-};
-short yydgoto[] = {                                       1,
-   30,   79,   31,  113,  108,  149,  109,   73,   74,   32,
-   33,   58,   34,   35,   59,   48,  138,  155,  164,  131,
-  146,   50,  132,   88,   54,   89,  152,  154,  101,   94,
-   95,
-};
-short yysindex[] = {                                      0,
-   -7,   58,  212,    0,  -22,    0, -233, -241,    0,    0,
-   -8,   -5,    0,   -4,    0,    2,    4,    0,    0,    9,
-    0,    0,    0,    0,    0,    0,  212,  212,   91,  725,
- -240,    0,  -29,    0,    0,    0,    0,    0,   84,  245,
-  212,  -57,    0,    0,   10,  212,  212,   14,  212,   16,
-  212,  212,   23,  156,    0,  549,  127,  -52,    0,    0,
-    0,  212,  212,  212,  212,  212,    0,    0,    0,   91,
-  -17,  725,   24,   -3,  578, -205,  562,  725,   27,  212,
-  606,  212,  669,  716,    0,    0,  725,    0,   19,    0,
-   91,  127,    0,  212,  212,  -36,  -39,  -91,  -91,  -36,
-  212,    0,  166,    0,  277,    0,  -21,   36,   40,    0,
-    0,  725,   28,    0,  725,    0,    0,  156,    0,    0,
-   84,  540,  -39,    0,   -9,  725,   -2,  -37, -174,    0,
-  127,   48,    0,  346,    0, -167,    3,  212, -185,  127,
-    0, -188,    6,   37,    0,    0,    0, -205,    0,    0,
-    0,  127,  -42,   91,  212,    0,    0,    0,  -20,   54,
-   26,    0,    0,  127,    0,
-};
-short yyrindex[] = {                                      0,
-  -16,    0,    0,    0,  409,    0,    0,    0,    0,    0,
-    0,  -58,    0,    0,    0,    0,  426,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,  -50,   46,
-  470,    0,    0,    0,    0,    0,    0,    0,  661,   56,
-    0,  525,    0,    0,    0,    0,   59,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,   -6,
-  705,    7,    0,   60,    0,   61,    0,   63,    0,   49,
-    0,    0,    0,    0,    0,    0,   17,    0,   78,    0,
-  -47,  -45,    0,    0,    0,  537,  440,  620,  637,  594,
-    0,    0,    0,    0,    0,    0,  -33,    0,   66,    0,
-    0,  -19,    0,    0,   68,    0,    0,    0,    0,    0,
-  667,  680,  508,    0,  705,   18,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,  -31,   49,  -44,    0,
-    0,  -40,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    1,   69,    0,    0,    0,    0,    0,
-   13,    0,    0,    0,    0,
-};
-short yygindex[] = {                                      0,
-  958,    0,  104, -118,    0,    0,  -35,    0,    0,    0,
-    0,  -34,   22,    0,   15,    0,    0,    0,    0,    0,
-    0,    0,    0,   -1,    0,    0,    0,    0,    0,    0,
-    0,
-};
-#define YYTABLESIZE 1113
-short yytable[] = {                                      52,
-   26,  129,   66,   64,   52,   65,   92,   55,   10,   57,
-   55,   12,   57,   14,   45,   36,  158,   40,   52,  144,
-   45,   66,   40,   38,   67,   55,   68,   57,   42,   70,
-   40,   46,   28,   41,   47,   49,  160,   27,   92,   66,
-  105,   51,    6,   52,   43,   18,   19,   61,   53,   76,
-   61,   23,    9,   80,   66,   82,  107,   66,   63,   10,
-   44,   63,  118,   85,  104,   28,   26,  111,   41,  127,
-   27,   12,   93,  103,   10,   44,  128,   12,   38,   14,
-   45,  134,   52,  129,  102,  136,  130,  137,  140,  142,
-  135,  145,  148,  143,  162,  151,   59,   28,  150,   67,
-   60,   50,   27,   68,   20,  119,   51,   65,   36,   65,
-   44,    0,  153,  120,    0,   29,  133,    0,    0,  159,
-    0,    0,    0,    0,    0,    0,   64,    0,   65,    0,
-   28,    0,    0,    0,    0,   27,   41,    0,    0,    0,
-    0,   44,    0,    0,    0,    0,    0,    0,   29,    0,
-  163,    0,  139,    0,    0,    0,    0,    0,    0,    0,
-    0,  147,    0,    0,    0,    0,   28,    0,    0,    0,
-   20,   27,   62,  156,    0,  119,    0,   66,    0,    0,
-   29,    0,    0,    0,    0,  165,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,   28,    0,    0,   26,    0,
-   27,    0,   41,    0,   91,   28,   10,    0,    0,   12,
-   27,   14,   45,   29,  157,   52,   52,    0,   26,   52,
-   52,   52,   52,   55,   62,   57,   52,   69,   52,   52,
-   52,   52,   52,   52,   52,   52,  161,   52,   52,   52,
-    6,   52,   52,   52,   52,   52,   52,   52,    2,   29,
-    9,   28,    3,    4,    5,    6,   27,   10,  124,    7,
-    8,    9,   10,   11,   12,   13,   14,   15,   16,   12,
-   17,   18,   19,   44,   20,   21,   22,   23,   24,   25,
-   26,   57,    0,    0,   28,    3,    4,    5,    6,   27,
-    0,    0,    7,   44,    9,   10,   11,   12,   13,   14,
-   15,   16,   20,   17,   18,   19,    0,   20,   21,   22,
-   23,   24,   25,   26,   37,    0,   28,    3,    4,    5,
-    6,   27,   20,    0,    7,    0,    9,   10,   11,   12,
-   13,   14,   15,   16,   41,   17,   18,   19,    0,   20,
-   21,   22,   23,   24,   25,   26,   57,   62,    0,   63,
-    3,    4,    5,    6,   41,    0,    0,    7,    0,    9,
-   10,   11,   12,   13,   14,   15,   16,    0,   17,   18,
-   19,    0,   20,   21,   22,   23,   24,   25,   26,    0,
-    0,    0,    0,    0,    0,   28,    3,    4,    5,    6,
-   27,    0,    0,    7,    0,    9,   10,   11,   12,   13,
-   14,   15,   16,    0,   17,   18,   19,    0,   20,   21,
-   22,   23,   24,   25,   26,    3,   86,    5,    6,    0,
-    0,    0,    7,    0,    0,    3,   11,    5,    6,    0,
-    0,   16,    7,   17,   18,   19,   11,   20,  141,    0,
-   23,   16,    0,   17,   18,   19,    0,   20,    0,   92,
-   23,   92,   92,   92,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,   96,   92,   96,   96,
-   96,    3,    0,    5,    6,    0,    0,    0,    7,    0,
-   76,    0,   11,   76,   96,    0,    0,   16,    0,   17,
-   18,   19,    0,   20,    0,    0,   23,    0,   76,    0,
-    0,   92,   92,    0,    3,    0,   71,    6,    0,    0,
-   82,    7,   82,   82,   82,   11,    0,    0,   96,   96,
-   16,    0,   17,   18,   19,    0,   20,    0,   82,   23,
-    0,    0,   76,   92,    0,    0,    3,    0,  125,    6,
-    0,    0,    0,    7,    0,    0,    0,   11,   70,    0,
-   96,   70,   16,    0,   17,   18,   19,    0,   20,    0,
-    0,   23,   82,   82,   76,   92,   70,   92,   92,   92,
-    0,    0,    0,    0,    0,    0,    0,   79,    0,   79,
-   79,   79,   64,   92,   65,    0,    0,    0,    0,   90,
-    0,   64,    0,   65,   82,   79,    0,    0,    0,    0,
-   70,    0,  110,    0,   64,    3,   65,    5,    6,    0,
-    0,    0,    7,    0,    0,    0,   11,   92,   92,    0,
-   64,   16,   65,   17,   18,   19,    0,   20,    0,   79,
-   23,    0,   70,   66,   80,    0,   80,   80,   80,    0,
-    0,    0,   66,    0,    0,    0,  114,    0,   64,   92,
-   65,    0,   80,    0,    0,   66,    0,    0,    0,    0,
-   77,   79,   77,   77,   77,   92,   92,   92,    0,    0,
-  106,   66,   92,   92,   92,   92,    0,   78,   77,   78,
-   78,   78,   96,   96,   96,   92,   80,    0,    0,   96,
-   96,   96,   96,    0,    0,   78,   76,   76,   76,   66,
-    0,   75,   96,    0,   75,   76,    0,   72,    0,  116,
-   72,   64,   77,   65,    0,    0,   76,    0,   80,   75,
-   74,    0,    0,   74,    0,   72,   82,   82,   82,   78,
-    0,    0,    0,   82,    0,   82,    0,    0,   74,    0,
-    0,    0,    0,    0,   77,   92,   82,   92,   92,   92,
-    0,    0,    0,   75,    0,    0,  117,    0,   64,   72,
-   65,   78,   66,    0,   70,   70,   70,   64,    0,   65,
-    0,    0,   74,   70,    0,    0,    0,    0,    0,    0,
-    0,   92,   92,   92,   70,   75,    0,    0,   92,    0,
-   92,   72,    0,   79,   79,   79,    0,   60,   92,    0,
-   79,   92,   79,   62,   74,   63,   60,   61,    0,   66,
-    0,    0,   62,   79,   63,    0,    0,    0,   66,   60,
-   61,    0,    0,    0,    0,   62,    0,   63,    0,    0,
-    0,    0,    0,    0,    0,   60,   61,    0,    0,    0,
-    0,   62,    0,   63,    0,    0,    0,    0,    0,    0,
-   80,   80,   80,    0,    0,    0,    0,   80,    0,   80,
-    0,    0,    0,   60,   61,    0,    0,    0,    0,   62,
-   80,   63,    0,    0,    0,    0,   77,   77,   77,    0,
-    0,    0,    0,    0,    0,   77,    0,    0,    0,    0,
-    0,    0,    0,   78,   78,   78,   77,    0,    0,    0,
-    0,    0,   78,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,   78,    0,    0,    0,   75,   75,   75,
-    0,    0,    0,   72,   72,   72,   60,   61,    0,    0,
-    0,    0,   62,    0,   63,    0,   74,   75,   74,    0,
-    0,    0,    0,   72,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,   74,    0,    0,    0,
-   39,    0,   92,   92,    0,    0,    0,    0,   92,   92,
-   92,   92,    0,   60,   61,    0,    0,    0,    0,   62,
-    0,   63,   60,   61,   55,   56,    0,    0,   62,    0,
-   63,    0,    0,    0,    0,    0,    0,   72,   75,    0,
-    0,    0,    0,   77,   78,    0,   81,    0,   83,   84,
-    0,   87,    0,    0,    0,    0,    0,    0,    0,   96,
-   97,   98,   99,  100,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,  112,    0,  115,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,  121,  122,    0,    0,    0,    0,    0,  123,    0,
-   75,    0,  126,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,   87,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,   75,    0,    0,    0,  112,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,  112,
-};
-short yycheck[] = {                                      40,
-   59,   44,   94,   43,   45,   45,   59,   41,   59,   41,
-   44,   59,   44,   59,   59,    1,   59,   40,   59,  138,
-  262,   41,   40,    2,  265,   59,  267,   59,  262,   59,
-   40,   40,   40,   91,   40,   40,  155,   45,   59,   59,
-   44,   40,   59,   40,  278,  279,  280,   41,   40,   40,
-   44,  285,   59,   40,   94,   40,  262,   94,   41,   59,
-   44,   44,   44,   41,   41,   40,  125,   41,   91,   91,
-   45,   59,  125,   91,  125,   59,   41,  125,   57,  125,
-  125,   91,  123,   44,   70,  123,   59,  262,   41,  257,
-   93,  277,  281,   91,   41,   59,   41,   40,   93,   41,
-   41,   41,   45,   41,   59,   91,   41,   59,   41,   41,
-    7,   -1,  148,   92,   -1,  123,  118,   -1,   -1,  154,
-   -1,   -1,   -1,   -1,   -1,   -1,   43,   -1,   45,   -1,
-   40,   -1,   -1,   -1,   -1,   45,   59,   -1,   -1,   -1,
-   -1,  125,   -1,   -1,   -1,   -1,   -1,   -1,  123,   -1,
-  125,   -1,  131,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,  140,   -1,   -1,   -1,   -1,   40,   -1,   -1,   -1,
-  125,   45,  264,  152,   -1,  161,   -1,   94,   -1,   -1,
-  123,   -1,   -1,   -1,   -1,  164,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,   40,   -1,   -1,  257,   -1,
-   45,   -1,  125,   -1,  257,   40,  257,   -1,   -1,  257,
-   45,  257,  257,  123,  257,  256,  257,   -1,  277,  260,
-  261,  262,  263,  257,  264,  257,  267,  257,  269,  270,
-  271,  272,  273,  274,  275,  276,  257,  278,  279,  280,
-  257,  282,  283,  284,  285,  286,  287,  288,  256,  123,
-  257,   40,  260,  261,  262,  263,   45,  257,   93,  267,
-  268,  269,  270,  271,  272,  273,  274,  275,  276,  257,
-  278,  279,  280,  257,  282,  283,  284,  285,  286,  287,
-  288,  256,   -1,   -1,   40,  260,  261,  262,  263,   45,
-   -1,   -1,  267,  277,  269,  270,  271,  272,  273,  274,
-  275,  276,  257,  278,  279,  280,   -1,  282,  283,  284,
-  285,  286,  287,  288,  257,   -1,   40,  260,  261,  262,
-  263,   45,  277,   -1,  267,   -1,  269,  270,  271,  272,
-  273,  274,  275,  276,  257,  278,  279,  280,   -1,  282,
-  283,  284,  285,  286,  287,  288,  256,  264,   -1,  266,
-  260,  261,  262,  263,  277,   -1,   -1,  267,   -1,  269,
-  270,  271,  272,  273,  274,  275,  276,   -1,  278,  279,
-  280,   -1,  282,  283,  284,  285,  286,  287,  288,   -1,
-   -1,   -1,   -1,   -1,   -1,   40,  260,  261,  262,  263,
-   45,   -1,   -1,  267,   -1,  269,  270,  271,  272,  273,
-  274,  275,  276,   -1,  278,  279,  280,   -1,  282,  283,
-  284,  285,  286,  287,  288,  260,  261,  262,  263,   -1,
-   -1,   -1,  267,   -1,   -1,  260,  271,  262,  263,   -1,
-   -1,  276,  267,  278,  279,  280,  271,  282,   93,   -1,
-  285,  276,   -1,  278,  279,  280,   -1,  282,   -1,   41,
-  285,   43,   44,   45,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,   -1,   41,   59,   43,   44,
-   45,  260,   -1,  262,  263,   -1,   -1,   -1,  267,   -1,
-   41,   -1,  271,   44,   59,   -1,   -1,  276,   -1,  278,
-  279,  280,   -1,  282,   -1,   -1,  285,   -1,   59,   -1,
-   -1,   93,   94,   -1,  260,   -1,  262,  263,   -1,   -1,
-   41,  267,   43,   44,   45,  271,   -1,   -1,   93,   94,
-  276,   -1,  278,  279,  280,   -1,  282,   -1,   59,  285,
-   -1,   -1,   93,  125,   -1,   -1,  260,   -1,  262,  263,
-   -1,   -1,   -1,  267,   -1,   -1,   -1,  271,   41,   -1,
-  125,   44,  276,   -1,  278,  279,  280,   -1,  282,   -1,
-   -1,  285,   93,   94,  125,   41,   59,   43,   44,   45,
-   -1,   -1,   -1,   -1,   -1,   -1,   -1,   41,   -1,   43,
-   44,   45,   43,   59,   45,   -1,   -1,   -1,   -1,   41,
-   -1,   43,   -1,   45,  125,   59,   -1,   -1,   -1,   -1,
-   93,   -1,   41,   -1,   43,  260,   45,  262,  263,   -1,
-   -1,   -1,  267,   -1,   -1,   -1,  271,   93,   94,   -1,
-   43,  276,   45,  278,  279,  280,   -1,  282,   -1,   93,
-  285,   -1,  125,   94,   41,   -1,   43,   44,   45,   -1,
-   -1,   -1,   94,   -1,   -1,   -1,   41,   -1,   43,  125,
-   45,   -1,   59,   -1,   -1,   94,   -1,   -1,   -1,   -1,
-   41,  125,   43,   44,   45,  257,  258,  259,   -1,   -1,
-   93,   94,  264,  265,  266,  267,   -1,   41,   59,   43,
-   44,   45,  257,  258,  259,  277,   93,   -1,   -1,  264,
-  265,  266,  267,   -1,   -1,   59,  257,  258,  259,   94,
-   -1,   41,  277,   -1,   44,  266,   -1,   41,   -1,   41,
-   44,   43,   93,   45,   -1,   -1,  277,   -1,  125,   59,
-   41,   -1,   -1,   44,   -1,   59,  257,  258,  259,   93,
-   -1,   -1,   -1,  264,   -1,  266,   -1,   -1,   59,   -1,
-   -1,   -1,   -1,   -1,  125,   41,  277,   43,   44,   45,
-   -1,   -1,   -1,   93,   -1,   -1,   41,   -1,   43,   93,
-   45,  125,   94,   -1,  257,  258,  259,   43,   -1,   45,
-   -1,   -1,   93,  266,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,  257,  258,  259,  277,  125,   -1,   -1,  264,   -1,
-  266,  125,   -1,  257,  258,  259,   -1,  258,   94,   -1,
-  264,  277,  266,  264,  125,  266,  258,  259,   -1,   94,
-   -1,   -1,  264,  277,  266,   -1,   -1,   -1,   94,  258,
-  259,   -1,   -1,   -1,   -1,  264,   -1,  266,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,  258,  259,   -1,   -1,   -1,
-   -1,  264,   -1,  266,   -1,   -1,   -1,   -1,   -1,   -1,
-  257,  258,  259,   -1,   -1,   -1,   -1,  264,   -1,  266,
-   -1,   -1,   -1,  258,  259,   -1,   -1,   -1,   -1,  264,
-  277,  266,   -1,   -1,   -1,   -1,  257,  258,  259,   -1,
-   -1,   -1,   -1,   -1,   -1,  266,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,  257,  258,  259,  277,   -1,   -1,   -1,
-   -1,   -1,  266,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,  277,   -1,   -1,   -1,  257,  258,  259,
-   -1,   -1,   -1,  257,  258,  259,  258,  259,   -1,   -1,
-   -1,   -1,  264,   -1,  266,   -1,  257,  277,  259,   -1,
-   -1,   -1,   -1,  277,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,   -1,  277,   -1,   -1,   -1,
-    3,   -1,  258,  259,   -1,   -1,   -1,   -1,  264,  265,
-  266,  267,   -1,  258,  259,   -1,   -1,   -1,   -1,  264,
-   -1,  266,  258,  259,   27,   28,   -1,   -1,  264,   -1,
-  266,   -1,   -1,   -1,   -1,   -1,   -1,   40,   41,   -1,
-   -1,   -1,   -1,   46,   47,   -1,   49,   -1,   51,   52,
-   -1,   54,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   62,
-   63,   64,   65,   66,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,   -1,   -1,   80,   -1,   82,
-   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,   94,   95,   -1,   -1,   -1,   -1,   -1,  101,   -1,
-  103,   -1,  105,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,  118,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,  134,   -1,   -1,   -1,  138,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,   -1,  155,
-};
-#define YYFINAL 1
-#ifndef YYDEBUG
-#define YYDEBUG 0
-#endif
-#define YYMAXTOKEN 289
-#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,"NEWLINE","AND","OR","NOT","STRING","NAME","NUMBER","MUL_OP",
-"ASSIGN_OP","REL_OP","INCR_DECR","Define","Break","Quit","Length","Return",
-"For","If","While","Sqrt","Else","Scale","Ibase","Obase","Auto","Read",
-"Warranty","Halt","Last","Continue","Print","Limits","UNARY_MINUS",
-};
-char *yyrule[] = {
-"$accept : program",
-"program :",
-"program : program input_item",
-"input_item : semicolon_list NEWLINE",
-"input_item : function",
-"input_item : error NEWLINE",
-"semicolon_list :",
-"semicolon_list : statement_or_error",
-"semicolon_list : semicolon_list ';' statement_or_error",
-"semicolon_list : semicolon_list ';'",
-"statement_list :",
-"statement_list : statement_or_error",
-"statement_list : statement_list NEWLINE",
-"statement_list : statement_list NEWLINE statement_or_error",
-"statement_list : statement_list ';'",
-"statement_list : statement_list ';' statement",
-"statement_or_error : statement",
-"statement_or_error : error statement",
-"statement : Warranty",
-"statement : Limits",
-"statement : expression",
-"statement : STRING",
-"statement : Break",
-"statement : Continue",
-"statement : Quit",
-"statement : Halt",
-"statement : Return",
-"statement : Return '(' return_expression ')'",
-"$$1 :",
-"$$2 :",
-"$$3 :",
-"$$4 :",
-"statement : For $$1 '(' opt_expression ';' $$2 opt_expression ';' $$3 opt_expression ')' $$4 statement",
-"$$5 :",
-"statement : If '(' expression ')' $$5 statement opt_else",
-"$$6 :",
-"$$7 :",
-"statement : While $$6 '(' expression $$7 ')' statement",
-"statement : '{' statement_list '}'",
-"$$8 :",
-"statement : Print $$8 print_list",
-"print_list : print_element",
-"print_list : print_element ',' print_list",
-"print_element : STRING",
-"print_element : expression",
-"opt_else :",
-"$$9 :",
-"opt_else : Else $$9 statement",
-"$$10 :",
-"function : Define NAME '(' opt_parameter_list ')' '{' NEWLINE opt_auto_define_list $$10 statement_list NEWLINE '}'",
-"opt_parameter_list :",
-"opt_parameter_list : define_list",
-"opt_auto_define_list :",
-"opt_auto_define_list : Auto define_list NEWLINE",
-"opt_auto_define_list : Auto define_list ';'",
-"define_list : NAME",
-"define_list : NAME '[' ']'",
-"define_list : define_list ',' NAME",
-"define_list : define_list ',' NAME '[' ']'",
-"opt_argument_list :",
-"opt_argument_list : argument_list",
-"argument_list : expression",
-"argument_list : NAME '[' ']'",
-"argument_list : argument_list ',' expression",
-"argument_list : argument_list ',' NAME '[' ']'",
-"opt_expression :",
-"opt_expression : expression",
-"return_expression :",
-"return_expression : expression",
-"$$11 :",
-"expression : named_expression ASSIGN_OP $$11 expression",
-"$$12 :",
-"expression : expression AND $$12 expression",
-"$$13 :",
-"expression : expression OR $$13 expression",
-"expression : NOT expression",
-"expression : expression REL_OP expression",
-"expression : expression '+' expression",
-"expression : expression '-' expression",
-"expression : expression MUL_OP expression",
-"expression : expression '^' expression",
-"expression : '-' expression",
-"expression : named_expression",
-"expression : NUMBER",
-"expression : '(' expression ')'",
-"expression : NAME '(' opt_argument_list ')'",
-"expression : INCR_DECR named_expression",
-"expression : named_expression INCR_DECR",
-"expression : Length '(' expression ')'",
-"expression : Sqrt '(' expression ')'",
-"expression : Scale '(' expression ')'",
-"expression : Read '(' ')'",
-"named_expression : NAME",
-"named_expression : NAME '[' expression ']'",
-"named_expression : Ibase",
-"named_expression : Obase",
-"named_expression : Scale",
-"named_expression : Last",
-};
-#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
-#define YYABORT goto yyabort
-#define YYREJECT goto yyabort
-#define YYACCEPT goto yyaccept
-#define YYERROR goto yyerrlab
-int
-yyparse()
-{
-    register int yym, yyn, yystate;
-#if YYDEBUG
-    register char *yys;
-    extern char *getenv();
-
-    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]) 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;
-#ifdef lint
-    goto yynewerror;
-#endif
-yynewerror:
-    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:
-#line 106 "bc.y"
-{
-			      yyval.i_value = 0;
-			      if (interactive)
-				{
-				  printf ("%s\n", BC_VERSION);
-				  welcome ();
-				}
-			    }
-break;
-case 3:
-#line 117 "bc.y"
-{ run_code (); }
-break;
-case 4:
-#line 119 "bc.y"
-{ run_code (); }
-break;
-case 5:
-#line 121 "bc.y"
-{
-			      yyerrok;
-			      init_gen ();
-			    }
-break;
-case 6:
-#line 127 "bc.y"
-{ yyval.i_value = 0; }
-break;
-case 10:
-#line 133 "bc.y"
-{ yyval.i_value = 0; }
-break;
-case 17:
-#line 142 "bc.y"
-{ yyval.i_value = yyvsp[0].i_value; }
-break;
-case 18:
-#line 145 "bc.y"
-{ warranty (""); }
-break;
-case 19:
-#line 147 "bc.y"
-{ limits (); }
-break;
-case 20:
-#line 149 "bc.y"
-{
-			      if (yyvsp[0].i_value & 2)
-				warn ("comparison in expression");
-			      if (yyvsp[0].i_value & 1)
-				generate ("W");
-			      else 
-				generate ("p");
-			    }
-break;
-case 21:
-#line 158 "bc.y"
-{
-			      yyval.i_value = 0;
-			      generate ("w");
-			      generate (yyvsp[0].s_value);
-			      free (yyvsp[0].s_value);
-			    }
-break;
-case 22:
-#line 165 "bc.y"
-{
-			      if (break_label == 0)
-				yyerror ("Break outside a for/while");
-			      else
-				{
-				  sprintf (genstr, "J%1d:", break_label);
-				  generate (genstr);
-				}
-			    }
-break;
-case 23:
-#line 175 "bc.y"
-{
-			      warn ("Continue statement");
-			      if (continue_label == 0)
-				yyerror ("Continue outside a for");
-			      else
-				{
-				  sprintf (genstr, "J%1d:", continue_label);
-				  generate (genstr);
-				}
-			    }
-break;
-case 24:
-#line 186 "bc.y"
-{ exit (0); }
-break;
-case 25:
-#line 188 "bc.y"
-{ generate ("h"); }
-break;
-case 26:
-#line 190 "bc.y"
-{ generate ("0R"); }
-break;
-case 27:
-#line 192 "bc.y"
-{ generate ("R"); }
-break;
-case 28:
-#line 194 "bc.y"
-{
-			      yyvsp[0].i_value = break_label; 
-			      break_label = next_label++;
-			    }
-break;
-case 29:
-#line 199 "bc.y"
-{
-			      if (yyvsp[-1].i_value > 1)
-				warn ("Comparison in first for expression");
-			      yyvsp[-1].i_value = next_label++;
-			      if (yyvsp[-1].i_value < 0)
-				sprintf (genstr, "N%1d:", yyvsp[-1].i_value);
-			      else
-				sprintf (genstr, "pN%1d:", yyvsp[-1].i_value);
-			      generate (genstr);
-			    }
-break;
-case 30:
-#line 210 "bc.y"
-{
-			      if (yyvsp[-1].i_value < 0) generate ("1");
-			      yyvsp[-1].i_value = next_label++;
-			      sprintf (genstr, "B%1d:J%1d:", yyvsp[-1].i_value, break_label);
-			      generate (genstr);
-			      yyval.i_value = continue_label;
-			      continue_label = next_label++;
-			      sprintf (genstr, "N%1d:", continue_label);
-			      generate (genstr);
-			    }
-break;
-case 31:
-#line 221 "bc.y"
-{
-			      if (yyvsp[-1].i_value > 1)
-				warn ("Comparison in third for expression");
-			      if (yyvsp[-1].i_value < 0)
-				sprintf (genstr, "J%1d:N%1d:", yyvsp[-7].i_value, yyvsp[-4].i_value);
-			      else
-				sprintf (genstr, "pJ%1d:N%1d:", yyvsp[-7].i_value, yyvsp[-4].i_value);
-			      generate (genstr);
-			    }
-break;
-case 32:
-#line 231 "bc.y"
-{
-			      sprintf (genstr, "J%1d:N%1d:",
-				       continue_label, break_label);
-			      generate (genstr);
-			      break_label = yyvsp[-12].i_value;
-			      continue_label = yyvsp[-4].i_value;
-			    }
-break;
-case 33:
-#line 239 "bc.y"
-{
-			      yyvsp[-1].i_value = if_label;
-			      if_label = next_label++;
-			      sprintf (genstr, "Z%1d:", if_label);
-			      generate (genstr);
-			    }
-break;
-case 34:
-#line 246 "bc.y"
-{
-			      sprintf (genstr, "N%1d:", if_label); 
-			      generate (genstr);
-			      if_label = yyvsp[-4].i_value;
-			    }
-break;
-case 35:
-#line 252 "bc.y"
-{
-			      yyvsp[0].i_value = next_label++;
-			      sprintf (genstr, "N%1d:", yyvsp[0].i_value);
-			      generate (genstr);
-			    }
-break;
-case 36:
-#line 258 "bc.y"
-{
-			      yyvsp[0].i_value = break_label; 
-			      break_label = next_label++;
-			      sprintf (genstr, "Z%1d:", break_label);
-			      generate (genstr);
-			    }
-break;
-case 37:
-#line 265 "bc.y"
-{
-			      sprintf (genstr, "J%1d:N%1d:", yyvsp[-6].i_value, break_label);
-			      generate (genstr);
-			      break_label = yyvsp[-3].i_value;
-			    }
-break;
-case 38:
-#line 271 "bc.y"
-{ yyval.i_value = 0; }
-break;
-case 39:
-#line 273 "bc.y"
-{  warn ("print statement"); }
-break;
-case 43:
-#line 280 "bc.y"
-{
-			      generate ("O");
-			      generate (yyvsp[0].s_value);
-			      free (yyvsp[0].s_value);
-			    }
-break;
-case 44:
-#line 286 "bc.y"
-{ generate ("P"); }
-break;
-case 46:
-#line 290 "bc.y"
-{
-			      warn ("else clause in if statement");
-			      yyvsp[0].i_value = next_label++;
-			      sprintf (genstr, "J%d:N%1d:", yyvsp[0].i_value, if_label); 
-			      generate (genstr);
-			      if_label = yyvsp[0].i_value;
-			    }
-break;
-case 48:
-#line 300 "bc.y"
-{
-			      /* Check auto list against parameter list? */
-			      check_params (yyvsp[-4].a_value,yyvsp[0].a_value);
-			      sprintf (genstr, "F%d,%s.%s[", lookup(yyvsp[-6].s_value,FUNCT), 
-				       arg_str (yyvsp[-4].a_value,TRUE), arg_str (yyvsp[0].a_value,TRUE));
-			      generate (genstr);
-			      free_args (yyvsp[-4].a_value);
-			      free_args (yyvsp[0].a_value);
-			      yyvsp[-7].i_value = next_label;
-			      next_label = 0;
-			    }
-break;
-case 49:
-#line 312 "bc.y"
-{
-			      generate ("0R]");
-			      next_label = yyvsp[-11].i_value;
-			    }
-break;
-case 50:
-#line 318 "bc.y"
-{ yyval.a_value = NULL; }
-break;
-case 52:
-#line 322 "bc.y"
-{ yyval.a_value = NULL; }
-break;
-case 53:
-#line 324 "bc.y"
-{ yyval.a_value = yyvsp[-1].a_value; }
-break;
-case 54:
-#line 326 "bc.y"
-{ yyval.a_value = yyvsp[-1].a_value; }
-break;
-case 55:
-#line 329 "bc.y"
-{ yyval.a_value = nextarg (NULL, lookup (yyvsp[0].s_value,SIMPLE)); }
-break;
-case 56:
-#line 331 "bc.y"
-{ yyval.a_value = nextarg (NULL, lookup (yyvsp[-2].s_value,ARRAY)); }
-break;
-case 57:
-#line 333 "bc.y"
-{ yyval.a_value = nextarg (yyvsp[-2].a_value, lookup (yyvsp[0].s_value,SIMPLE)); }
-break;
-case 58:
-#line 335 "bc.y"
-{ yyval.a_value = nextarg (yyvsp[-4].a_value, lookup (yyvsp[-2].s_value,ARRAY)); }
-break;
-case 59:
-#line 338 "bc.y"
-{ yyval.a_value = NULL; }
-break;
-case 61:
-#line 342 "bc.y"
-{
-			      if (yyvsp[0].i_value > 1) warn ("comparison in argument");
-			      yyval.a_value = nextarg (NULL,0);
-			    }
-break;
-case 62:
-#line 347 "bc.y"
-{
-			      sprintf (genstr, "K%d:", -lookup (yyvsp[-2].s_value,ARRAY));
-			      generate (genstr);
-			      yyval.a_value = nextarg (NULL,1);
-			    }
-break;
-case 63:
-#line 353 "bc.y"
-{
-			      if (yyvsp[0].i_value > 1) warn ("comparison in argument");
-			      yyval.a_value = nextarg (yyvsp[-2].a_value,0);
-			    }
-break;
-case 64:
-#line 358 "bc.y"
-{
-			      sprintf (genstr, "K%d:", -lookup (yyvsp[-2].s_value,ARRAY));
-			      generate (genstr);
-			      yyval.a_value = nextarg (yyvsp[-4].a_value,1);
-			    }
-break;
-case 65:
-#line 365 "bc.y"
-{
-			      yyval.i_value = -1;
-			      warn ("Missing expression in for statement");
-			    }
-break;
-case 67:
-#line 372 "bc.y"
-{
-			      yyval.i_value = 0;
-			      generate ("0");
-			    }
-break;
-case 68:
-#line 377 "bc.y"
-{
-			      if (yyvsp[0].i_value > 1)
-				warn ("comparison in return expresion");
-			    }
-break;
-case 69:
-#line 383 "bc.y"
-{
-			      if (yyvsp[0].c_value != '=')
-				{
-				  if (yyvsp[-1].i_value < 0)
-				    sprintf (genstr, "DL%d:", -yyvsp[-1].i_value);
-				  else
-				    sprintf (genstr, "l%d:", yyvsp[-1].i_value);
-				  generate (genstr);
-				}
-			    }
-break;
-case 70:
-#line 394 "bc.y"
-{
-			      if (yyvsp[0].i_value > 1) warn("comparison in assignment");
-			      if (yyvsp[-2].c_value != '=')
-				{
-				  sprintf (genstr, "%c", yyvsp[-2].c_value);
-				  generate (genstr);
-				}
-			      if (yyvsp[-3].i_value < 0)
-				sprintf (genstr, "S%d:", -yyvsp[-3].i_value);
-			      else
-				sprintf (genstr, "s%d:", yyvsp[-3].i_value);
-			      generate (genstr);
-			      yyval.i_value = 0;
-			    }
-break;
-case 71:
-#line 410 "bc.y"
-{
-			      warn("&& operator");
-			      yyvsp[0].i_value = next_label++;
-			      sprintf (genstr, "DZ%d:p", yyvsp[0].i_value);
-			      generate (genstr);
-			    }
-break;
-case 72:
-#line 417 "bc.y"
-{
-			      sprintf (genstr, "DZ%d:p1N%d:", yyvsp[-2].i_value, yyvsp[-2].i_value);
-			      generate (genstr);
-			      yyval.i_value = yyvsp[-3].i_value | yyvsp[0].i_value;
-			    }
-break;
-case 73:
-#line 423 "bc.y"
-{
-			      warn("|| operator");
-			      yyvsp[0].i_value = next_label++;
-			      sprintf (genstr, "B%d:", yyvsp[0].i_value);
-			      generate (genstr);
-			    }
-break;
-case 74:
-#line 430 "bc.y"
-{
-			      int tmplab;
-			      tmplab = next_label++;
-			      sprintf (genstr, "B%d:0J%d:N%d:1N%d:",
-				       yyvsp[-2].i_value, tmplab, yyvsp[-2].i_value, tmplab);
-			      generate (genstr);
-			      yyval.i_value = yyvsp[-3].i_value | yyvsp[0].i_value;
-			    }
-break;
-case 75:
-#line 439 "bc.y"
-{
-			      yyval.i_value = yyvsp[0].i_value;
-			      warn("! operator");
-			      generate ("!");
-			    }
-break;
-case 76:
-#line 445 "bc.y"
-{
-			      yyval.i_value = 3;
-			      switch (*(yyvsp[-1].s_value))
-				{
-				case '=':
-				  generate ("=");
-				  break;
-
-				case '!':
-				  generate ("#");
-				  break;
-
-				case '<':
-				  if (yyvsp[-1].s_value[1] == '=')
-				    generate ("{");
-				  else
-				    generate ("<");
-				  break;
-
-				case '>':
-				  if (yyvsp[-1].s_value[1] == '=')
-				    generate ("}");
-				  else
-				    generate (">");
-				  break;
-				}
-			    }
-break;
-case 77:
-#line 473 "bc.y"
-{
-			      generate ("+");
-			      yyval.i_value = yyvsp[-2].i_value | yyvsp[0].i_value;
-			    }
-break;
-case 78:
-#line 478 "bc.y"
-{
-			      generate ("-");
-			      yyval.i_value = yyvsp[-2].i_value | yyvsp[0].i_value;
-			    }
-break;
-case 79:
-#line 483 "bc.y"
-{
-			      genstr[0] = yyvsp[-1].c_value;
-			      genstr[1] = 0;
-			      generate (genstr);
-			      yyval.i_value = yyvsp[-2].i_value | yyvsp[0].i_value;
-			    }
-break;
-case 80:
-#line 490 "bc.y"
-{
-			      generate ("^");
-			      yyval.i_value = yyvsp[-2].i_value | yyvsp[0].i_value;
-			    }
-break;
-case 81:
-#line 495 "bc.y"
-{
-			      generate ("n");
-			      yyval.i_value = yyvsp[0].i_value;
-			    }
-break;
-case 82:
-#line 500 "bc.y"
-{
-			      yyval.i_value = 1;
-			      if (yyvsp[0].i_value < 0)
-				sprintf (genstr, "L%d:", -yyvsp[0].i_value);
-			      else
-				sprintf (genstr, "l%d:", yyvsp[0].i_value);
-			      generate (genstr);
-			    }
-break;
-case 83:
-#line 509 "bc.y"
-{
-			      int len = strlen(yyvsp[0].s_value);
-			      yyval.i_value = 1;
-			      if (len == 1 && *yyvsp[0].s_value == '0')
-				generate ("0");
-			      else if (len == 1 && *yyvsp[0].s_value == '1')
-				generate ("1");
-			      else
-				{
-				  generate ("K");
-				  generate (yyvsp[0].s_value);
-				  generate (":");
-				}
-			      free (yyvsp[0].s_value);
-			    }
-break;
-case 84:
-#line 525 "bc.y"
-{ yyval.i_value = yyvsp[-1].i_value | 1; }
-break;
-case 85:
-#line 527 "bc.y"
-{
-			      yyval.i_value = 1;
-			      if (yyvsp[-1].a_value != NULL)
-				{ 
-				  sprintf (genstr, "C%d,%s:",
-					   lookup (yyvsp[-3].s_value,FUNCT),
-					   arg_str (yyvsp[-1].a_value,FALSE));
-				  free_args (yyvsp[-1].a_value);
-				}
-			      else
-				{
-				  sprintf (genstr, "C%d:", lookup (yyvsp[-3].s_value,FUNCT));
-				}
-			      generate (genstr);
-			    }
-break;
-case 86:
-#line 543 "bc.y"
-{
-			      yyval.i_value = 1;
-			      if (yyvsp[0].i_value < 0)
-				{
-				  if (yyvsp[-1].c_value == '+')
-				    sprintf (genstr, "DA%d:L%d:", -yyvsp[0].i_value, -yyvsp[0].i_value);
-				  else
-				    sprintf (genstr, "DM%d:L%d:", -yyvsp[0].i_value, -yyvsp[0].i_value);
-				}
-			      else
-				{
-				  if (yyvsp[-1].c_value == '+')
-				    sprintf (genstr, "i%d:l%d:", yyvsp[0].i_value, yyvsp[0].i_value);
-				  else
-				    sprintf (genstr, "d%d:l%d:", yyvsp[0].i_value, yyvsp[0].i_value);
-				}
-			      generate (genstr);
-			    }
-break;
-case 87:
-#line 562 "bc.y"
-{
-			      yyval.i_value = 1;
-			      if (yyvsp[-1].i_value < 0)
-				{
-				  sprintf (genstr, "DL%d:x", -yyvsp[-1].i_value);
-				  generate (genstr); 
-				  if (yyvsp[0].c_value == '+')
-				    sprintf (genstr, "A%d:", -yyvsp[-1].i_value);
-				  else
-				      sprintf (genstr, "M%d:", -yyvsp[-1].i_value);
-				}
-			      else
-				{
-				  sprintf (genstr, "l%d:", yyvsp[-1].i_value);
-				  generate (genstr);
-				  if (yyvsp[0].c_value == '+')
-				    sprintf (genstr, "i%d:", yyvsp[-1].i_value);
-				  else
-				    sprintf (genstr, "d%d:", yyvsp[-1].i_value);
-				}
-			      generate (genstr);
-			    }
-break;
-case 88:
-#line 585 "bc.y"
-{ generate ("cL"); yyval.i_value = 1;}
-break;
-case 89:
-#line 587 "bc.y"
-{ generate ("cR"); yyval.i_value = 1;}
-break;
-case 90:
-#line 589 "bc.y"
-{ generate ("cS"); yyval.i_value = 1;}
-break;
-case 91:
-#line 591 "bc.y"
-{
-			      warn ("read function");
-			      generate ("cI"); yyval.i_value = 1;
-			    }
-break;
-case 92:
-#line 597 "bc.y"
-{ yyval.i_value = lookup(yyvsp[0].s_value,SIMPLE); }
-break;
-case 93:
-#line 599 "bc.y"
-{
-			      if (yyvsp[-1].i_value > 1) warn("comparison in subscript");
-			      yyval.i_value = lookup(yyvsp[-3].s_value,ARRAY);
-			    }
-break;
-case 94:
-#line 604 "bc.y"
-{ yyval.i_value = 0; }
-break;
-case 95:
-#line 606 "bc.y"
-{ yyval.i_value = 1; }
-break;
-case 96:
-#line 608 "bc.y"
-{ yyval.i_value = 2; }
-break;
-case 97:
-#line 610 "bc.y"
-{ yyval.i_value = 3; }
-break;
-#line 1318 "y.tab.c"
-    }
-    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);
-}
Index: trunk/minix/commands/bc/bc.y
===================================================================
--- trunk/minix/commands/bc/bc.y	(revision 9)
+++ 	(revision )
@@ -1,612 +1,0 @@
-%{
-/* bc.y: The grammar for a POSIX compatable bc processor with some
-         extensions to the language. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "global.h"
-#include "proto.h"
-%}
-
-%start program
-
-%union {
-	char	 *s_value;
-	char	  c_value;
-	int	  i_value;
-	arg_list *a_value;
-       }
-
-/* Extensions over POSIX bc.
-   a) NAME was LETTER.  This grammer allows longer names.
-      Single letter names will still work.
-   b) Relational_expression allowed only one comparison.
-      This grammar has added boolean expressions with
-      && (and) || (or) and ! (not) and allowed all of them in
-      full expressions.
-   c) Added an else to the if.
-   d) Call by variable array parameters
-   e) read() procedure that reads a number under program control from stdin.
-   f) halt statement that halts the the program under program control.  It
-      is an executed statement.
-   g) continue statement for for loops.
-   h) optional expressions in the for loop.
-   i) print statement to print multiple numbers per line.
-   j) warranty statement to print an extended warranty notice.
-   j) limits statement to print the processor's limits.
-*/
-
-%token <i_value> NEWLINE AND OR NOT
-%token <s_value> STRING NAME NUMBER
-/*     '-', '+' are tokens themselves		*/
-%token <c_value> MUL_OP
-/*     '*', '/', '%' 				*/
-%token <c_value> ASSIGN_OP
-/*     '=', '+=',  '-=', '*=', '/=', '%=', '^=' */
-%token <s_value> REL_OP
-/*     '==', '<=', '>=', '!=', '<', '>' 	*/
-%token <c_value> INCR_DECR
-/*     '++', '--' 				*/
-%token <i_value> Define    Break    Quit    Length
-/*     'define', 'break', 'quit', 'length' 	*/
-%token <i_value> Return    For    If    While    Sqrt   Else
-/*     'return', 'for', 'if', 'while', 'sqrt', 'else' 	*/
-%token <i_value> Scale    Ibase    Obase    Auto  Read
-/*     'scale', 'ibase', 'obase', 'auto', 'read' 	*/
-%token <i_value> Warranty, Halt, Last, Continue, Print, Limits
-/*     'warranty', 'halt', 'last', 'continue', 'print', 'limits'   */
-
-/* Types of all other things. */
-%type <i_value> expression return_expression named_expression opt_expression
-%type <c_value> '+' '-' 
-%type <a_value> opt_parameter_list opt_auto_define_list define_list
-%type <a_value> opt_argument_list argument_list
-%type <i_value> program input_item semicolon_list statement_list
-%type <i_value> statement function   statement_or_error
-
-/* precedence */
-%left OR
-%left AND
-%nonassoc NOT
-%left REL_OP
-%right ASSIGN_OP
-%left '+' '-'
-%left MUL_OP
-%right '^'
-%nonassoc UNARY_MINUS
-%nonassoc INCR_DECR
-
-%%
-program			: /* empty */
-			    {
-			      $$ = 0;
-			      if (interactive)
-				{
-				  printf ("%s\n", BC_VERSION);
-				  welcome ();
-				}
-			    }
-			| program input_item
-			;
-input_item		: semicolon_list NEWLINE
-			    { run_code (); }
-			| function
-			    { run_code (); }
-			| error NEWLINE
-			    {
-			      yyerrok;
-			      init_gen ();
-			    }
-			;
-semicolon_list		: /* empty */
-			    { $$ = 0; }
-			| statement_or_error
-			| semicolon_list ';' statement_or_error
-			| semicolon_list ';'
-			;
-statement_list		: /* empty */
-			    { $$ = 0; }
-			| statement_or_error
-			| statement_list NEWLINE
-			| statement_list NEWLINE statement_or_error
-			| statement_list ';'
-			| statement_list ';' statement
-			;
-statement_or_error	: statement
-  			| error statement
-			    { $$ = $2; }
-			;
-statement 		: Warranty
-			    { warranty (""); }
-			| Limits
-			    { limits (); }
-			| expression
-			    {
-			      if ($1 & 2)
-				warn ("comparison in expression");
-			      if ($1 & 1)
-				generate ("W");
-			      else 
-				generate ("p");
-			    }
-			| STRING
-			    {
-			      $$ = 0;
-			      generate ("w");
-			      generate ($1);
-			      free ($1);
-			    }
-			| Break
-			    {
-			      if (break_label == 0)
-				yyerror ("Break outside a for/while");
-			      else
-				{
-				  sprintf (genstr, "J%1d:", break_label);
-				  generate (genstr);
-				}
-			    }
-			| Continue
-			    {
-			      warn ("Continue statement");
-			      if (continue_label == 0)
-				yyerror ("Continue outside a for");
-			      else
-				{
-				  sprintf (genstr, "J%1d:", continue_label);
-				  generate (genstr);
-				}
-			    }
-			| Quit
-			    { exit (0); }
-			| Halt
-			    { generate ("h"); }
-			| Return
-			    { generate ("0R"); }
-			| Return '(' return_expression ')'
-			    { generate ("R"); }
-			| For 
-			    {
-			      $1 = break_label; 
-			      break_label = next_label++;
-			    }
-			  '(' opt_expression ';'
-			    {
-			      if ($4 > 1)
-				warn ("Comparison in first for expression");
-			      $4 = next_label++;
-			      if ($4 < 0)
-				sprintf (genstr, "N%1d:", $4);
-			      else
-				sprintf (genstr, "pN%1d:", $4);
-			      generate (genstr);
-			    }
-			  opt_expression ';'
-			    {
-			      if ($7 < 0) generate ("1");
-			      $7 = next_label++;
-			      sprintf (genstr, "B%1d:J%1d:", $7, break_label);
-			      generate (genstr);
-			      $<i_value>$ = continue_label;
-			      continue_label = next_label++;
-			      sprintf (genstr, "N%1d:", continue_label);
-			      generate (genstr);
-			    }
-			  opt_expression ')'
-			    {
-			      if ($10 > 1)
-				warn ("Comparison in third for expression");
-			      if ($10 < 0)
-				sprintf (genstr, "J%1d:N%1d:", $4, $7);
-			      else
-				sprintf (genstr, "pJ%1d:N%1d:", $4, $7);
-			      generate (genstr);
-			    }
-			  statement
-			    {
-			      sprintf (genstr, "J%1d:N%1d:",
-				       continue_label, break_label);
-			      generate (genstr);
-			      break_label = $1;
-			      continue_label = $<i_value>9;
-			    }
-			| If '(' expression ')' 
-			    {
-			      $3 = if_label;
-			      if_label = next_label++;
-			      sprintf (genstr, "Z%1d:", if_label);
-			      generate (genstr);
-			    }
-			  statement  opt_else
-			    {
-			      sprintf (genstr, "N%1d:", if_label); 
-			      generate (genstr);
-			      if_label = $3;
-			    }
-			| While 
-			    {
-			      $1 = next_label++;
-			      sprintf (genstr, "N%1d:", $1);
-			      generate (genstr);
-			    }
-			'(' expression 
-			    {
-			      $4 = break_label; 
-			      break_label = next_label++;
-			      sprintf (genstr, "Z%1d:", break_label);
-			      generate (genstr);
-			    }
-			')' statement
-			    {
-			      sprintf (genstr, "J%1d:N%1d:", $1, break_label);
-			      generate (genstr);
-			      break_label = $4;
-			    }
-			| '{' statement_list '}'
-			    { $$ = 0; }
-			| Print
-			    {  warn ("print statement"); }
-			  print_list
-			;
-print_list		: print_element
- 			| print_element ',' print_list
-			;
-print_element		: STRING
-			    {
-			      generate ("O");
-			      generate ($1);
-			      free ($1);
-			    }
-			| expression
-			    { generate ("P"); }
- 			;
-opt_else		: /* nothing */
-			| Else 
-			    {
-			      warn ("else clause in if statement");
-			      $1 = next_label++;
-			      sprintf (genstr, "J%d:N%1d:", $1, if_label); 
-			      generate (genstr);
-			      if_label = $1;
-			    }
-			  statement
-function 		: Define NAME '(' opt_parameter_list ')' '{'
-			  NEWLINE opt_auto_define_list 
-			    {
-			      /* Check auto list against parameter list? */
-			      check_params ($4,$8);
-			      sprintf (genstr, "F%d,%s.%s[", lookup($2,FUNCT), 
-				       arg_str ($4,TRUE), arg_str ($8,TRUE));
-			      generate (genstr);
-			      free_args ($4);
-			      free_args ($8);
-			      $1 = next_label;
-			      next_label = 0;
-			    }
-			  statement_list NEWLINE '}'
-			    {
-			      generate ("0R]");
-			      next_label = $1;
-			    }
-			;
-opt_parameter_list	: /* empty */ 
-			    { $$ = NULL; }
-			| define_list
-			;
-opt_auto_define_list 	: /* empty */ 
-			    { $$ = NULL; }
-			| Auto define_list NEWLINE
-			    { $$ = $2; } 
-			| Auto define_list ';'
-			    { $$ = $2; } 
-			;
-define_list 		: NAME
-			    { $$ = nextarg (NULL, lookup ($1,SIMPLE)); }
-			| NAME '[' ']'
-			    { $$ = nextarg (NULL, lookup ($1,ARRAY)); }
-			| define_list ',' NAME
-			    { $$ = nextarg ($1, lookup ($3,SIMPLE)); }
-			| define_list ',' NAME '[' ']'
-			    { $$ = nextarg ($1, lookup ($3,ARRAY)); }
-			;
-opt_argument_list	: /* empty */
-			    { $$ = NULL; }
-			| argument_list
-			;
-argument_list 		: expression
-			    {
-			      if ($1 > 1) warn ("comparison in argument");
-			      $$ = nextarg (NULL,0);
-			    }
-			| NAME '[' ']'
-			    {
-			      sprintf (genstr, "K%d:", -lookup ($1,ARRAY));
-			      generate (genstr);
-			      $$ = nextarg (NULL,1);
-			    }
-			| argument_list ',' expression
-			    {
-			      if ($3 > 1) warn ("comparison in argument");
-			      $$ = nextarg ($1,0);
-			    }
-			| argument_list ',' NAME '[' ']'
-			    {
-			      sprintf (genstr, "K%d:", -lookup ($3,ARRAY));
-			      generate (genstr);
-			      $$ = nextarg ($1,1);
-			    }
-			;
-opt_expression 		: /* empty */
-			    {
-			      $$ = -1;
-			      warn ("Missing expression in for statement");
-			    }
-			| expression
-			;
-return_expression	: /* empty */
-			    {
-			      $$ = 0;
-			      generate ("0");
-			    }
-			| expression
-			    {
-			      if ($1 > 1)
-				warn ("comparison in return expresion");
-			    }
-			;
-expression		:  named_expression ASSIGN_OP 
-			    {
-			      if ($2 != '=')
-				{
-				  if ($1 < 0)
-				    sprintf (genstr, "DL%d:", -$1);
-				  else
-				    sprintf (genstr, "l%d:", $1);
-				  generate (genstr);
-				}
-			    }
-			  expression
-			    {
-			      if ($4 > 1) warn("comparison in assignment");
-			      if ($2 != '=')
-				{
-				  sprintf (genstr, "%c", $2);
-				  generate (genstr);
-				}
-			      if ($1 < 0)
-				sprintf (genstr, "S%d:", -$1);
-			      else
-				sprintf (genstr, "s%d:", $1);
-			      generate (genstr);
-			      $$ = 0;
-			    }
-			;
-			| expression AND 
-			    {
-			      warn("&& operator");
-			      $2 = next_label++;
-			      sprintf (genstr, "DZ%d:p", $2);
-			      generate (genstr);
-			    }
-			  expression
-			    {
-			      sprintf (genstr, "DZ%d:p1N%d:", $2, $2);
-			      generate (genstr);
-			      $$ = $1 | $4;
-			    }
-			| expression OR
-			    {
-			      warn("|| operator");
-			      $2 = next_label++;
-			      sprintf (genstr, "B%d:", $2);
-			      generate (genstr);
-			    }
-			  expression
- 			    {
-			      int tmplab;
-			      tmplab = next_label++;
-			      sprintf (genstr, "B%d:0J%d:N%d:1N%d:",
-				       $2, tmplab, $2, tmplab);
-			      generate (genstr);
-			      $$ = $1 | $4;
-			    }
-			| NOT expression
-			    {
-			      $$ = $2;
-			      warn("! operator");
-			      generate ("!");
-			    }
-			| expression REL_OP expression
-			    {
-			      $$ = 3;
-			      switch (*($2))
-				{
-				case '=':
-				  generate ("=");
-				  break;
-
-				case '!':
-				  generate ("#");
-				  break;
-
-				case '<':
-				  if ($2[1] == '=')
-				    generate ("{");
-				  else
-				    generate ("<");
-				  break;
-
-				case '>':
-				  if ($2[1] == '=')
-				    generate ("}");
-				  else
-				    generate (">");
-				  break;
-				}
-			    }
-			| expression '+' expression
-			    {
-			      generate ("+");
-			      $$ = $1 | $3;
-			    }
-			| expression '-' expression
-			    {
-			      generate ("-");
-			      $$ = $1 | $3;
-			    }
-			| expression MUL_OP expression
-			    {
-			      genstr[0] = $2;
-			      genstr[1] = 0;
-			      generate (genstr);
-			      $$ = $1 | $3;
-			    }
-			| expression '^' expression
-			    {
-			      generate ("^");
-			      $$ = $1 | $3;
-			    }
-			| '-' expression  %prec UNARY_MINUS
-			    {
-			      generate ("n");
-			      $$ = $2;
-			    }
-			| named_expression
-			    {
-			      $$ = 1;
-			      if ($1 < 0)
-				sprintf (genstr, "L%d:", -$1);
-			      else
-				sprintf (genstr, "l%d:", $1);
-			      generate (genstr);
-			    }
-			| NUMBER
-			    {
-			      int len = strlen($1);
-			      $$ = 1;
-			      if (len == 1 && *$1 == '0')
-				generate ("0");
-			      else if (len == 1 && *$1 == '1')
-				generate ("1");
-			      else
-				{
-				  generate ("K");
-				  generate ($1);
-				  generate (":");
-				}
-			      free ($1);
-			    }
-			| '(' expression ')'
-			    { $$ = $2 | 1; }
-			| NAME '(' opt_argument_list ')'
-			    {
-			      $$ = 1;
-			      if ($3 != NULL)
-				{ 
-				  sprintf (genstr, "C%d,%s:",
-					   lookup ($1,FUNCT),
-					   arg_str ($3,FALSE));
-				  free_args ($3);
-				}
-			      else
-				{
-				  sprintf (genstr, "C%d:", lookup ($1,FUNCT));
-				}
-			      generate (genstr);
-			    }
-			| INCR_DECR named_expression
-			    {
-			      $$ = 1;
-			      if ($2 < 0)
-				{
-				  if ($1 == '+')
-				    sprintf (genstr, "DA%d:L%d:", -$2, -$2);
-				  else
-				    sprintf (genstr, "DM%d:L%d:", -$2, -$2);
-				}
-			      else
-				{
-				  if ($1 == '+')
-				    sprintf (genstr, "i%d:l%d:", $2, $2);
-				  else
-				    sprintf (genstr, "d%d:l%d:", $2, $2);
-				}
-			      generate (genstr);
-			    }
-			| named_expression INCR_DECR
-			    {
-			      $$ = 1;
-			      if ($1 < 0)
-				{
-				  sprintf (genstr, "DL%d:x", -$1);
-				  generate (genstr); 
-				  if ($2 == '+')
-				    sprintf (genstr, "A%d:", -$1);
-				  else
-				      sprintf (genstr, "M%d:", -$1);
-				}
-			      else
-				{
-				  sprintf (genstr, "l%d:", $1);
-				  generate (genstr);
-				  if ($2 == '+')
-				    sprintf (genstr, "i%d:", $1);
-				  else
-				    sprintf (genstr, "d%d:", $1);
-				}
-			      generate (genstr);
-			    }
-			| Length '(' expression ')'
-			    { generate ("cL"); $$ = 1;}
-			| Sqrt '(' expression ')'
-			    { generate ("cR"); $$ = 1;}
-			| Scale '(' expression ')'
-			    { generate ("cS"); $$ = 1;}
-			| Read '(' ')'
-			    {
-			      warn ("read function");
-			      generate ("cI"); $$ = 1;
-			    }
-			;
-named_expression	: NAME
-			    { $$ = lookup($1,SIMPLE); }
-			| NAME '[' expression ']'
-			    {
-			      if ($3 > 1) warn("comparison in subscript");
-			      $$ = lookup($1,ARRAY);
-			    }
-			| Ibase
-			    { $$ = 0; }
-			| Obase
-			    { $$ = 1; }
-			| Scale
-			    { $$ = 2; }
-			| Last
-			    { $$ = 3; }
-			;
-%%
Index: trunk/minix/commands/bc/bcdefs.h
===================================================================
--- trunk/minix/commands/bc/bcdefs.h	(revision 9)
+++ 	(revision )
@@ -1,154 +1,0 @@
-/* bcdefs.h:  The single file to include all constants and type definitions. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-/* Include the configuration file. */
-#include "config.h"
-
-/* Standard includes for all files. */
-#include <stdio.h>
-#include <sys/types.h>
-#include <ctype.h>
-#ifdef STRINGS_H
-#include <strings.h>
-#else
-#include <string.h>
-#endif
-#ifndef NO_LIMITS
-#include <limits.h>
-#endif
-
-/* Include the other definitions. */
-#include "const.h"
-#include "number.h"
-
-
-/* These definitions define all the structures used in
-   code and data storage.  This includes the representation of
-   labels.   The "guiding" principle is to make structures that
-   take a minimum of space when unused but can be built to contain
-   the full structures.  */
-
-/* Labels are first.  Labels are generated sequentially in functions
-   and full code.  They just "point" to a single bye in the code.  The
-   "address" is the byte number.  The byte number is used to get an
-   actual character pointer. */
-
-typedef struct bc_label_group
-    {
-      long l_adrs [ BC_LABEL_GROUP ];
-      struct bc_label_group *l_next;
-    } bc_label_group;
-
-
-/* Each function has its own code segments and labels.  There can be
-   no jumps between functions so labels are unique to a function. */
-
-typedef struct arg_list
-    {
-      int av_name;
-      struct arg_list *next;
-    } arg_list;
-
-typedef struct 
-    {
-      char f_defined;   /* Is this function defined yet. */
-      char *f_body[BC_MAX_SEGS];
-      int   f_code_size;
-      bc_label_group *f_label;
-      arg_list *f_params;
-      arg_list *f_autos;
-    } bc_function;
-
-/* Code addresses. */
-typedef struct {
-      int pc_func;
-      int pc_addr;
-    } program_counter;
-
-
-/* Variables are "pushable" (auto) and thus we need a stack mechanism.
-   This is built into the variable record. */
-
-typedef struct bc_var
-    {
-      bc_num v_value;
-      struct bc_var *v_next;
-    }  bc_var;
-
-
-/* bc arrays can also be "auto" variables and thus need the same
-   kind of stacking mechanisms. */
-
-typedef struct bc_array_node
-    {
-      union
-	{
-	  bc_num n_num [NODE_SIZE];
-	  struct bc_array_node *n_down [NODE_SIZE];
-	} n_items;
-    } bc_array_node;
-
-typedef struct bc_array
-    {
-      bc_array_node *a_tree;
-      short a_depth;
-    } bc_array;
-
-typedef struct bc_var_array
-    {
-      bc_array *a_value;
-      char      a_param;
-      struct bc_var_array *a_next;
-    } bc_var_array;
-
-
-/* For the stacks, execution and function, we need records to allow
-   for arbitrary size. */
-
-typedef struct estack_rec {
-	bc_num s_num;
-	struct estack_rec *s_next;
-} estack_rec;
-
-typedef struct fstack_rec {
-	int  s_val;
-	struct fstack_rec *s_next;
-} fstack_rec;
-
-
-/* The following are for the name tree. */
-
-typedef struct id_rec {
-	char  *id;      /* The program name. */
-			/* A name == 0 => nothing assigned yet. */
-	int   a_name;   /* The array variable name (number). */
-	int   f_name;   /* The function name (number).  */
-	int   v_name;   /* The variable name (number).  */
-        short balance;  /* For the balanced tree. */
-	struct id_rec *left, *right; /* Tree pointers. */
-} id_rec;
Index: trunk/minix/commands/bc/build
===================================================================
--- trunk/minix/commands/bc/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/bc/config.h
===================================================================
--- trunk/minix/commands/bc/config.h	(revision 9)
+++ 	(revision )
@@ -1,4 +1,0 @@
-/* config.h */
-#define SMALL_BUF
-#define BC_MATH_FILE "/usr/lib/libmath.b"
-#define SHORTNAMES
Index: trunk/minix/commands/bc/const.h
===================================================================
--- trunk/minix/commands/bc/const.h	(revision 9)
+++ 	(revision )
@@ -1,87 +1,0 @@
-/* const.h: Constants for bc. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-
-/* Define INT_MAX and LONG_MAX if not defined.  Assuming 32 bits... */
-
-#ifdef NO_LIMITS
-#define INT_MAX 0x7FFFFFFF
-#define LONG_MAX 0x7FFFFFFF
-#endif
-
-
-/* Define constants in some reasonable size.  The next 4 constants are
-   POSIX constants. */
-
-#define BC_BASE_MAX   INT_MAX
-#define BC_SCALE_MAX  INT_MAX
-#define BC_STRING_MAX INT_MAX
-
-
-/* Definitions for arrays. */
-
-#define BC_DIM_MAX    65535       /* this should be NODE_SIZE^NODE_DEPTH-1 */
-
-#define   NODE_SIZE        16     /* Must be a power of 2. */
-#define   NODE_MASK       0xf     /* Must be NODE_SIZE-1. */
-#define   NODE_SHIFT        4     /* Number of 1 bits in NODE_MASK. */
-#define   NODE_DEPTH        4
-
-
-/* Other BC limits defined but not part of POSIX. */
-
-#define BC_LABEL_GROUP 64
-#define BC_LABEL_LOG    6
-#define BC_MAX_SEGS    16    /* Code segments. */
-#define BC_SEG_SIZE  1024
-#define BC_SEG_LOG     10
-
-/* Maximum number of variables, arrays and functions and the
-   allocation increment for the dynamic arrays. */
-
-#define MAX_STORE   32767
-#define STORE_INCR     32
-
-/* Other interesting constants. */
-
-#define FALSE 0
-#define TRUE  1
-#define SIMPLE 0
-#define ARRAY  1
-#define FUNCT  2
-#define EXTERN extern
-#ifdef __STDC__
-#define CONST const
-#define VOID  void
-#else
-#define CONST
-#define VOID
-#endif
-
-/* Include the version definition. */
-#include "version.h"
Index: trunk/minix/commands/bc/execute.c
===================================================================
--- trunk/minix/commands/bc/execute.c	(revision 9)
+++ 	(revision )
@@ -1,783 +1,0 @@
-/* execute.c - run a bc program. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include <signal.h>
-#include "global.h"
-#include "proto.h"
-
-
-/* The SIGINT interrupt handling routine. */
-
-int had_sigint;
-
-void
-stop_execution (sig)
-     int sig;
-{
-  had_sigint = TRUE;
-  printf ("\n");
-  rt_error ("interrupted execution");
-}
-
-
-/* Get the current byte and advance the PC counter. */
-
-unsigned char
-byte (pc)
-     program_counter *pc;
-{
-  int seg, offset;
-    
-  seg = pc->pc_addr >> BC_SEG_LOG;
-  offset = pc->pc_addr++ % BC_SEG_SIZE;
-  return (functions[pc->pc_func].f_body[seg][offset]);
-}
-
-
-/* The routine that actually runs the machine. */
-
-void
-execute ()
-{
-  int label_num, l_gp, l_off;
-  bc_label_group *gp;
-  
-  char inst, ch;
-  int  new_func;
-  int  var_name;
-
-  int const_base;
-
-  bc_num temp_num;
-  arg_list *auto_list;
-
-  /* Initialize this run... */
-  pc.pc_func = 0;
-  pc.pc_addr = 0;
-  runtime_error = FALSE;
-  init_num (&temp_num);
-
-  /* Set up the interrupt mechanism for an interactive session. */
-  if (interactive)
-    {
-      signal (SIGINT, stop_execution);
-      had_sigint = FALSE;
-    }
-   
-  while (pc.pc_addr < functions[pc.pc_func].f_code_size && !runtime_error)
-    {
-      inst = byte(&pc);
-
-#if DEBUG > 3
-      { /* Print out address and the stack before each instruction.*/
-	int depth; estack_rec *temp = ex_stack;
-	
-	printf ("func=%d addr=%d inst=%c\n",pc.pc_func, pc.pc_addr, inst);
-	if (temp == NULL) printf ("empty stack.\n", inst);
-	else
-	  {
-	    depth = 1;
-	    while (temp != NULL)
-	      {
-		printf ("   %d = ", depth);
-		out_num (temp->s_num, 10, out_char);
-		depth++;
-		temp = temp->s_next;
-	      }
-	  }
-      }
-#endif
-
-    switch ( inst )
-      {
-
-      case 'A' : /* increment array variable (Add one). */
-	var_name = byte(&pc);
-	if ((var_name & 0x80) != 0)
-	  var_name = ((var_name << 8) & 0x7f) + byte(&pc);
-	incr_array (var_name);
-	break;
-
-      case 'B' : /* Branch to a label if TOS != 0. Remove value on TOS. */
-      case 'Z' : /* Branch to a label if TOS == 0. Remove value on TOS. */
-	c_code = !is_zero (ex_stack->s_num);
-	pop ();
-      case 'J' : /* Jump to a label. */
-	label_num = byte(&pc);  /* Low order bits first. */
-	label_num += byte(&pc) << 8;
-	if (inst == 'J' || (inst == 'B' && c_code)
-	    || (inst == 'Z' && !c_code)) {
-	  gp = functions[pc.pc_func].f_label;
-	  l_gp  = label_num >> BC_LABEL_LOG;
-	  l_off = label_num % BC_LABEL_GROUP;
-	  while (l_gp-- > 0) gp = gp->l_next;
-	  pc.pc_addr = gp->l_adrs[l_off];
-	}
-	break;
-
-      case 'C' : /* Call a function. */
-	/* Get the function number. */
-	new_func = byte(&pc);
-	if ((new_func & 0x80) != 0) 
-	  new_func = ((new_func << 8) & 0x7f) + byte(&pc);
-
-	/* Check to make sure it is defined. */
-	if (!functions[new_func].f_defined)
-	  {
-	    rt_error ("Function %s not defined.", f_names[new_func]);
-	    break;
-	  }
-
-	/* Check and push parameters. */
-	process_params (&pc, new_func);
-
-	/* Push auto variables. */
-	for (auto_list = functions[new_func].f_autos;
-	     auto_list != NULL;
-	     auto_list = auto_list->next)
-	  auto_var (auto_list->av_name);
-
-	/* Push pc and ibase. */
-	fpush (pc.pc_func);
-	fpush (pc.pc_addr);
-	fpush (i_base);
-
-	/* Reset pc to start of function. */
-	pc.pc_func = new_func;
-	pc.pc_addr = 0;
-	break;
-
-      case 'D' : /* Duplicate top of stack */
-	push_copy (ex_stack->s_num);
-	break;
-
-      case 'K' : /* Push a constant */
-	/* Get the input base and convert it to a bc number. */
-	if (pc.pc_func == 0) 
-	  const_base = i_base;
-	else
-	  const_base = fn_stack->s_val;
-	if (const_base == 10)
-	  push_b10_const (&pc);
-	else
-	  push_constant (prog_char, const_base);
-	break;
-
-      case 'L' : /* load array variable */
-	var_name = byte(&pc);
-	if ((var_name & 0x80) != 0)
-	  var_name = ((var_name << 8) & 0x7f) + byte(&pc);
-	load_array (var_name);
-	break;
-
-      case 'M' : /* decrement array variable (Minus!) */
-	var_name = byte(&pc);
-	if ((var_name & 0x80) != 0)
-	  var_name = ((var_name << 8) & 0x7f) + byte(&pc);
-	decr_array (var_name);
-	break;
-
-      case 'O' : /* Write a string to the output with processing. */
-	while ((ch = byte(&pc)) != '"')
-	  if (ch != '\\')
-	    out_char (ch);
-	  else
-	    {
-	      ch = byte(&pc);
-	      if (ch == '"') break;
-	      switch (ch)
-		{
-		case 'n':  out_char ('\n'); break;
-		case 't':  out_char ('\t'); break;
-		case 'r':  out_char ('\r'); break;
-		case 'b':  out_char (007); break;
-		case 'f':  out_char ('\f'); break;
-		case '\\': out_char ('\\'); break;
-		default:  break;
-		}
-	    }
-	if (interactive) fflush (stdout);
-	break;
-
-      case 'R' : /* Return from function */
-	if (pc.pc_func != 0)
-	  {
-	    /* "Pop" autos and parameters. */
-	    pop_vars(functions[pc.pc_func].f_autos);
-	    pop_vars(functions[pc.pc_func].f_params);
-	    /* reset the pc. */
-	    fpop ();
-	    pc.pc_addr = fpop ();
-	    pc.pc_func = fpop ();
-	  }
-	else
-	  rt_error ("Return from main program.");
-	break;
-
-      case 'S' : /* store array variable */
-	var_name = byte(&pc);
-	if ((var_name & 0x80) != 0)
-	  var_name = ((var_name << 8) & 0x7f) + byte(&pc);
-	store_array (var_name);
-	break;
-
-      case 'T' : /* Test tos for zero */
-	c_code = is_zero (ex_stack->s_num);
-	assign (c_code);
-	break;
-
-      case 'W' : /* Write the value on the top of the stack. */
-      case 'P' : /* Write the value on the top of the stack.  No newline. */
-	out_num (ex_stack->s_num, o_base, out_char);
-	if (inst == 'W') out_char ('\n');
-	store_var (3);  /* Special variable "last". */
-	if (interactive) fflush (stdout);
-	break;
-
-      case 'c' : /* Call special function. */
-	new_func = byte(&pc);
-
-      switch (new_func)
-	{
-	case 'L':  /* Length function. */
-	  /* For the number 0.xxxx,  0 is not significant. */
-	  if (ex_stack->s_num->n_len == 1 &&
-	      ex_stack->s_num->n_scale != 0 &&
-	      ex_stack->s_num->n_value[0] == 0 )
-	    int2num (&ex_stack->s_num, ex_stack->s_num->n_scale);
-	  else
-	    int2num (&ex_stack->s_num, ex_stack->s_num->n_len
-		     + ex_stack->s_num->n_scale);
-	  break;
-		
-	case 'S':  /* Scale function. */ 
-	  int2num (&ex_stack->s_num, ex_stack->s_num->n_scale);
-	  break;
-
-	case 'R':  /* Square Root function. */
-	  if (!bc_sqrt (&ex_stack->s_num, scale))
-	    rt_error ("Square root of a negative number");
-	  break;
-
-	case 'I': /* Read function. */
-	  push_constant (input_char, i_base);
-	  break;
-	}
-	break;
-
-      case 'd' : /* Decrement number */
-	var_name = byte(&pc);
-	if ((var_name & 0x80) != 0)
-	  var_name = ((var_name << 8) & 0x7f) + byte(&pc);
-	decr_var (var_name);
-	break;
-      
-      case 'h' : /* Halt the machine. */
-	exit (0);
-
-      case 'i' : /* increment number */
-	var_name = byte(&pc);
-	if ((var_name & 0x80) != 0)
-	  var_name = ((var_name << 8) & 0x7f) + byte(&pc);
-	incr_var (var_name);
-	break;
-
-      case 'l' : /* load variable */
-	var_name = byte(&pc);
-	if ((var_name & 0x80) != 0)
-	  var_name = ((var_name << 8) & 0x7f) + byte(&pc);
-	load_var (var_name);
-	break;
-
-      case 'n' : /* Negate top of stack. */
-	bc_sub (_zero_, ex_stack->s_num, &ex_stack->s_num);
-	break;
-
-      case 'p' : /* Pop the execution stack. */
-	pop ();
-	break;
-
-      case 's' : /* store variable */
-	var_name = byte(&pc);
-	if ((var_name & 0x80) != 0)
-	  var_name = ((var_name << 8) & 0x7f) + byte(&pc);
-	store_var (var_name);
-	break;
-
-      case 'w' : /* Write a string to the output. */
-	while ((ch = byte(&pc)) != '"') out_char (ch);
-	if (interactive) fflush (stdout);
-	break;
-		   
-      case 'x' : /* Exchange Top of Stack with the one under the tos. */
-	if (check_stack(2)) {
-	  bc_num temp = ex_stack->s_num;
-	  ex_stack->s_num = ex_stack->s_next->s_num;
-	  ex_stack->s_next->s_num = temp;
-	}
-	break;
-
-      case '0' : /* Load Constant 0. */
-	push_copy (_zero_);
-	break;
-
-      case '1' : /* Load Constant 0. */
-	push_copy (_one_);
-	break;
-
-      case '!' : /* Negate the boolean value on top of the stack. */
-	c_code = is_zero (ex_stack->s_num);
-	assign (c_code);
-	break;
-
-      case '&' : /* compare greater than */
-	if (check_stack(2))
-	  {
-	    c_code = !is_zero (ex_stack->s_next->s_num)
-	      && !is_zero (ex_stack->s_num);
-	    pop ();
-	    assign (c_code);
-	  }
-	break;
-
-      case '|' : /* compare greater than */
-	if (check_stack(2))
-	  {
-	    c_code = !is_zero (ex_stack->s_next->s_num)
-	      || !is_zero (ex_stack->s_num);
-	    pop ();
-	    assign (c_code);
-	  }
-	break;
-
-      case '+' : /* add */
-	if (check_stack(2))
-	  {
-	    bc_add (ex_stack->s_next->s_num, ex_stack->s_num, &temp_num);
-	    pop();
-	    pop();
-	    push_num (temp_num);
-	    init_num (&temp_num);
-	  }
-	break;
-
-      case '-' : /* subtract */
-	if (check_stack(2))
-	  {
-	    bc_sub (ex_stack->s_next->s_num, ex_stack->s_num, &temp_num);
-	    pop();
-	    pop();
-	    push_num (temp_num);
-	    init_num (&temp_num);
-	  }
-	break;
-
-      case '*' : /* multiply */
-	if (check_stack(2))
-	  {
-	    bc_multiply (ex_stack->s_next->s_num, ex_stack->s_num,
-			 &temp_num, scale);
-	    pop();
-	    pop();
-	    push_num (temp_num);
-	    init_num (&temp_num);
-	  }
-	break;
-
-      case '/' : /* divide */
-	if (check_stack(2))
-	  {
-	    if (bc_divide (ex_stack->s_next->s_num,
-			   ex_stack->s_num, &temp_num, scale) == 0)
-	      {
-		pop();
-		pop();
-		push_num (temp_num);
-		init_num (&temp_num);
-	      }
-	    else
-	      rt_error ("Divide by zero");
-	  }
-	break;
-
-      case '%' : /* remainder */
-	if (check_stack(2))
-	  {
-	    if (is_zero (ex_stack->s_num))
-	      rt_error ("Modulo by zero");
-	    else
-	      {
-		bc_modulo (ex_stack->s_next->s_num,
-			   ex_stack->s_num, &temp_num, scale);
-		pop();
-		pop();
-		push_num (temp_num);
-		init_num (&temp_num);
-	      }
-	  }
-	break;
-
-      case '^' : /* raise */
-	if (check_stack(2))
-	  {
-	    bc_raise (ex_stack->s_next->s_num,
-		      ex_stack->s_num, &temp_num, scale);
-	    if (is_zero (ex_stack->s_next->s_num) && is_neg (ex_stack->s_num))
-	      rt_error ("divide by zero");
-	    pop();
-	    pop();
-	    push_num (temp_num);
-	    init_num (&temp_num);
-	  }
-	break;
-
-      case '=' : /* compare equal */
-	if (check_stack(2))
-	  {
-	    c_code = bc_compare (ex_stack->s_next->s_num,
-				 ex_stack->s_num) == 0;
-	    pop ();
-	    assign (c_code);
-	  }
-	break;
-
-      case '#' : /* compare not equal */
-	if (check_stack(2))
-	  {
-	    c_code = bc_compare (ex_stack->s_next->s_num,
-				 ex_stack->s_num) != 0;
-	    pop ();
-	    assign (c_code);
-	  }
-	break;
-
-      case '<' : /* compare less than */
-	if (check_stack(2))
-	  {
-	    c_code = bc_compare (ex_stack->s_next->s_num,
-				 ex_stack->s_num) == -1;
-	    pop ();
-	    assign (c_code);
-	  }
-	break;
-
-      case '{' : /* compare less than or equal */
-	if (check_stack(2))
-	  {
-	    c_code = bc_compare (ex_stack->s_next->s_num,
-				 ex_stack->s_num) <= 0;
-	    pop ();
-	    assign (c_code);
-	  }
-	break;
-
-      case '>' : /* compare greater than */
-	if (check_stack(2))
-	  {
-	    c_code = bc_compare (ex_stack->s_next->s_num,
-				 ex_stack->s_num) == 1;
-	    pop ();
-	    assign (c_code);
-	  }
-	break;
-
-      case '}' : /* compare greater than or equal */
-	if (check_stack(2))
-	  {
-	    c_code = bc_compare (ex_stack->s_next->s_num,
-				 ex_stack->s_num) >= 0;
-	    pop ();
-	    assign (c_code);
-	  }
-	break;
-
-	default  : /* error! */
-	  rt_error ("bad instruction: inst=%c", inst);
-      }
-    }
-
-  /* Clean up the function stack and pop all autos/parameters. */
-  while (pc.pc_func != 0)
-    {
-      pop_vars(functions[pc.pc_func].f_autos);
-      pop_vars(functions[pc.pc_func].f_params);
-      fpop ();
-      pc.pc_addr = fpop ();
-      pc.pc_func = fpop ();
-    }
-
-  /* Clean up the execution stack. */ 
-  while (ex_stack != NULL) pop();
-
-  /* Clean up the interrupt stuff. */
-  if (interactive)
-    {
-      signal (SIGINT, use_quit);
-      if (had_sigint)
-	printf ("Interruption completed.\n");
-    }
-}
-
-
-/* Prog_char gets another byte from the program.  It is used for
-   conversion of text constants in the code to numbers. */
-
-char
-prog_char ()
-{
-  return byte(&pc);
-}
-
-
-/* Read a character from the standard input.  This function is used
-   by the "read" function. */
-
-char
-input_char ()
-{
-  char in_ch;
-  
-  /* Get a character from the standard input for the read function. */
-  in_ch = getchar();
-
-  /* Check for a \ quoted newline. */
-  if (in_ch == '\\')
-    {
-      in_ch = getchar();
-      if (in_ch == '\n')
-	in_ch = getchar();
-    }
-
-  /* Classify and preprocess the input character. */
-  if (isdigit(in_ch))
-    return (in_ch - '0');
-  if (in_ch >= 'A' && in_ch <= 'F')
-    return (in_ch + 10 - 'A');
-  if (in_ch >= 'a' && in_ch <= 'f')
-    return (in_ch + 10 - 'a');
-  if (in_ch == '.' || in_ch == '+' || in_ch == '-')
-    return (in_ch);
-  if (in_ch <= ' ')
-    return (' ');
-  
-  return (':');
-}
-
-
-/* Push_constant converts a sequence of input characters as returned
-   by IN_CHAR into a number.  The number is pushed onto the execution
-   stack.  The number is converted as a number in base CONV_BASE. */
-
-void
-push_constant (in_char, conv_base)
-   char (*in_char)(VOID);
-   int conv_base;
-{
-  int digits;
-  bc_num build, temp, result, mult, divisor;
-  char  in_ch, first_ch;
-  char  negative;
-
-  /* Initialize all bc numbers */
-  init_num (&temp);
-  init_num (&result);
-  init_num (&mult);
-  build = copy_num (_zero_);
-  negative = FALSE;
-
-  /* The conversion base. */
-  int2num (&mult, conv_base);
-  
-  /* Get things ready. */
-  in_ch = in_char();
-  while (in_ch == ' ')
-    in_ch = in_char();
-
-  if (in_ch == '+')
-    in_ch = in_char();
-  else
-    if (in_ch == '-')
-      {
-	negative = TRUE;
-	in_ch = in_char();
-      }
-
-  /* Check for the special case of a single digit. */
-  if (in_ch < 16)
-    {
-      first_ch = in_ch;
-      in_ch = in_char();
-      if (in_ch < 16 && first_ch >= conv_base)
-	first_ch = conv_base - 1;
-      int2num (&build, (int) first_ch);
-    }
-
-  /* Convert the integer part. */
-  while (in_ch < 16)
-    {
-      if (in_ch < 16 && in_ch >= conv_base) in_ch = conv_base-1;
-      bc_multiply (build, mult, &result, 0);
-      int2num (&temp, (int) in_ch);
-      bc_add (result, temp, &build);
-      in_ch = in_char();
-    }
-  if (in_ch == '.')
-    {
-      in_ch = in_char();
-      if (in_ch >= conv_base) in_ch = conv_base-1;
-      free_num (&result);
-      free_num (&temp);
-      divisor = copy_num (_one_);
-      result = copy_num (_zero_);
-      digits = 0;
-      while (in_ch < 16)
-	{
-	  bc_multiply (result, mult, &result, 0);
-	  int2num (&temp, (int) in_ch);
-	  bc_add (result, temp, &result);
-	  bc_multiply (divisor, mult, &divisor, 0);
-	  digits++;
-	  in_ch = in_char();
-	  if (in_ch < 16 && in_ch >= conv_base) in_ch = conv_base-1;
-	}
-      bc_divide (result, divisor, &result, digits);
-      bc_add (build, result, &build);
-    }
-  
-  /* Final work.  */
-  if (negative)
-    bc_sub (_zero_, build, &build);
-
-  push_num (build);
-  free_num (&temp);
-  free_num (&result);
-  free_num (&mult);
-}
-
-
-/* When converting base 10 constants from the program, we use this
-   more efficient way to convert them to numbers.  PC tells where
-   the constant starts and is expected to be advanced to after
-   the constant. */
-
-void
-push_b10_const (pc)
-     program_counter *pc;
-{
-  bc_num build;
-  program_counter look_pc;
-  int kdigits, kscale;
-  char inchar;
-  char *ptr;
-  
-  /* Count the digits and get things ready. */
-  look_pc = *pc;
-  kdigits = 0;
-  kscale  = 0;
-  inchar = byte (&look_pc);
-  while (inchar != '.' && inchar != ':')
-    {
-      kdigits++;
-      inchar = byte(&look_pc);
-    }
-  if (inchar == '.' )
-    {
-      inchar = byte(&look_pc);
-      while (inchar != ':')
-	{
-	  kscale++;
-	  inchar = byte(&look_pc);
-	}
-    }
-
-  /* Get the first character again and move the pc. */
-  inchar = byte(pc);
-  
-  /* Secial cases of 0, 1, and A-F single inputs. */
-  if (kdigits == 1 && kscale == 0)
-    {
-      if (inchar == 0)
-	{
-	  push_copy (_zero_);
-	  inchar = byte(pc);
-	  return;
-	}
-      if (inchar == 1) {
-      push_copy (_one_);
-      inchar = byte(pc);
-      return;
-    }
-    if (inchar > 9)
-      {
-	init_num (&build);
-	int2num (&build, inchar);
-	push_num (build);
-	inchar = byte(pc);
-	return;
-      }
-    }
-
-  /* Build the new number. */
-  if (kdigits == 0)
-    {
-      build = new_num (1,kscale);
-      ptr = build->n_value;
-      *ptr++ = 0;
-    }
-  else
-    {
-      build = new_num (kdigits,kscale);
-      ptr = build->n_value;
-    }
-
-  while (inchar != ':')
-    {
-      if (inchar != '.')
-	if (inchar > 9)
-	  *ptr++ = 9;
-	else
-	  *ptr++ = inchar;
-      inchar = byte(pc);
-    }
-  push_num (build);
-}
-
-
-/* Put the correct value on the stack for C_CODE.  Frees TOS num. */
-
-void
-assign (c_code)
-     char c_code;
-{
-  free_num (&ex_stack->s_num);
-  if (c_code)
-    ex_stack->s_num = copy_num (_one_);
-  else
-    ex_stack->s_num = copy_num (_zero_);
-}
Index: trunk/minix/commands/bc/fix_math.h
===================================================================
--- trunk/minix/commands/bc/fix_math.h	(revision 9)
+++ 	(revision )
@@ -1,9 +1,0 @@
-#!/bin/sh
-ed - math.h <<EOS-EOS
-1,1s/^/"/
-1,\$s/\$/\\\\/
-\$,\$d
-\$,\$s/\\\\\$/"/
-w
-q
-EOS-EOS
Index: trunk/minix/commands/bc/global.c
===================================================================
--- trunk/minix/commands/bc/global.c	(revision 9)
+++ 	(revision )
@@ -1,42 +1,0 @@
-/* global.c:  This defines the global variables. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-
-/* Since we want to define them here, we use the following define. */
-#undef EXTERN
-#define EXTERN
-
-/* Define all the global variables for bc. */
-#include "global.h"
-
-#ifndef BC_MATH_FILE
-CONST char libmath[] = 
-#include "math.h"
-;
-#endif 
Index: trunk/minix/commands/bc/global.h
===================================================================
--- trunk/minix/commands/bc/global.h	(revision 9)
+++ 	(revision )
@@ -1,108 +1,0 @@
-/* global.h:  The global variables for bc.  */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-
-/* For the current "break level" and if statements. */
-EXTERN int break_label;
-EXTERN int if_label;
-EXTERN int continue_label;
-
-/* Label numbers. */
-EXTERN int next_label;
-
-/* Used for "code" generation. */
-EXTERN char genstr[80];
-EXTERN int out_count;
-EXTERN char did_gen;
-
-/* Interactive and other flags. */
-EXTERN char interactive;
-EXTERN char compile_only;
-EXTERN char use_math;
-EXTERN char warn_not_std;
-EXTERN char std_only;
-
-/* global variables for the bc machine. All will be dynamic in size.*/
-/* Function storage. main is (0) and functions (1-f_count) */
-
-EXTERN bc_function *functions;
-EXTERN char **f_names;
-EXTERN int  f_count;
-
-/* Variable stoarge and reverse names. */
-
-EXTERN bc_var **variables;
-EXTERN char **v_names;
-EXTERN int  v_count;
-
-/* Array Variable storage and reverse names. */
-
-EXTERN bc_var_array **arrays;
-EXTERN char **a_names;
-EXTERN int  a_count;
-
-/* Execution stack. */
-EXTERN estack_rec *ex_stack;
-
-/* Function return stack. */
-EXTERN fstack_rec *fn_stack;
-
-/* Other "storage". */
-EXTERN int i_base;
-EXTERN int o_base;
-EXTERN int scale;
-EXTERN char c_code;
-EXTERN int out_col;
-EXTERN char runtime_error;
-EXTERN program_counter pc;
-
-/* Input Line numbers and other error information. */
-EXTERN int line_no;
-EXTERN int had_error;
-
-/* For larger identifiers, a tree, and how many "storage" locations
-   have been allocated. */
-
-EXTERN int next_array;
-EXTERN int next_func;
-EXTERN int next_var;
-
-EXTERN id_rec *name_tree;
-
-/* For error message production */
-EXTERN char **g_argv;
-EXTERN int    g_argc;
-EXTERN char   is_std_in;
-
-/* defined in number.c */
-extern bc_num _zero_;
-extern bc_num _one_;
-
-/* For use with getopt.  Do not declare them here.*/
-extern int optind;
-
Index: trunk/minix/commands/bc/libmath.b
===================================================================
--- trunk/minix/commands/bc/libmath.b	(revision 9)
+++ 	(revision )
@@ -1,255 +1,0 @@
-/* libmath.b for bc for minix.  */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-
-scale = 20
-
-/* Uses the fact that e^x = (e^(x/2))^2
-   When x is small enough, we use the series:
-     e^x = 1 + x + x^2/2! + x^3/3! + ...
-*/
-
-define e(x) {
-  auto  a, d, e, f, i, m, v, z
-
-  /* Check the sign of x. */
-  if (x<0) {
-    m = 1
-    x = -x
-  } 
-
-  /* Precondition x. */
-  z = scale;
-  scale = 4 + z + .44*x;
-  while (x > 1) {
-    f += 1;
-    x /= 2;
-  }
-
-  /* Initialize the variables. */
-  v = 1+x
-  a = x
-  d = 1
-
-  for (i=2; 1; i++) {
-    e = (a *= x) / (d *= i)
-    if (e == 0) {
-      if (f>0) while (f--)  v = v*v;
-      scale = z
-      if (m) return (1/v);
-      return (v/1);
-    }
-    v += e
-  }
-}
-
-/* Natural log. Uses the fact that ln(x^2) = 2*ln(x)
-    The series used is:
-       ln(x) = 2(a+a^3/3+a^5/5+...) where a=(x-1)/(x+1)
-*/
-
-define l(x) {
-  auto e, f, i, m, n, v, z
-
-  /* return something for the special case. */
-  if (x <= 0) return (1 - 10^scale)
-
-  /* Precondition x to make .5 < x < 2.0. */
-  z = scale;
-  scale += 4;
-  f = 2;
-  i=0
-  while (x >= 2) {  /* for large numbers */
-    f *= 2;
-    x = sqrt(x);
-  }
-  while (x <= .5) {  /* for small numbers */
-    f *= 2;
-    x = sqrt(x);
-  }
-
-  /* Set up the loop. */
-  v = n = (x-1)/(x+1)
-  m = n*n
-
-  /* Sum the series. */
-  for (i=3; 1; i+=2) {
-    e = (n *= m) / i
-    if (e == 0) {
-      v = f*v
-      scale = z
-      return (v/1)
-    }
-    v += e
-  }
-}
-
-/* Sin(x)  uses the standard series:
-   sin(x) = x - x^3/3! + x^5/5! - x^7/7! ... */
-
-define s(x) {
-  auto  e, i, m, n, s, v, z
-
-  /* precondition x. */
-  z = scale 
-  scale = 1.1*z + 1;
-  v = a(1)
-  if (x < 0) {
-    m = 1;
-    x = -x;
-  }
-  scale = 0
-  n = (x / v + 2 )/4
-  x = x - 4*n*v
-  if (n%2) x = -x
-
-  /* Do the loop. */
-  scale = z + 2;
-  v = e = x
-  s = -x*x
-  for (i=3; 1; i+=2) {
-    e *= s/(i*(i-1))
-    if (e == 0) {
-      scale = z
-      if (m) return (-v/1);
-      return (v/1);
-    }
-    v += e
-  }
-}
-
-/* Cosine : cos(x) = sin(x+pi/2) */
-define c(x) {
-  auto v;
-  scale += 1;
-  v = s(x+a(1)*2);
-  scale -= 1;
-  return (v/1);
-}
-
-/* Arctan: Using the formula:
-     atan(x) = atan(c) + atan((x-c)/(1+xc)) for a small c (.2 here)
-   For under .2, use the series:
-     atan(x) = x - x^3/3 + x^5/5 - x^7/7 + ...   */
-
-define a(x) {
-  auto a, e, f, i, m, n, s, v, z
-
-  /* Special case and for fast answers */
-  if (x==1) {
-    if (scale <= 25) return (.7853981633974483096156608/1)
-    if (scale <= 40) return (.7853981633974483096156608458198757210492/1)
-    if (scale <= 60) \
-      return (.785398163397448309615660845819875721049292349843776455243736/1)
-  }
-  if (x==.2) {
-    if (scale <= 25) return (.1973955598498807583700497/1)
-    if (scale <= 40) return (.1973955598498807583700497651947902934475/1)
-    if (scale <= 60) \
-      return (.197395559849880758370049765194790293447585103787852101517688/1)
-  }
-
-  /* Negative x? */
-  if (x<0) {
-    m = 1;
-    x = -x;
-  }
-
-  /* Save the scale. */
-  z = scale;
-
-  /* Note: a and f are known to be zero due to being auto vars. */
-  /* Calculate atan of a known number. */ 
-  if (x > .2)  {
-    scale = z+4;
-    a = a(.2);
-  }
-   
-  /* Precondition x. */
-  scale = z+2;
-  while (x > .2) {
-    f += 1;
-    x = (x-.2) / (1+x*.2);
-  }
-
-  /* Initialize the series. */
-  v = n = x;
-  s = -x*x;
-
-  /* Calculate the series. */
-  for (i=3; 1; i+=2) {
-    e = (n *= s) / i;
-    if (e == 0) {
-      scale = z;
-      if (m) return ((f*a+v)/-1);
-      return ((f*a+v)/1);
-    }
-    v += e
-  }
-}
-
-
-/* Bessel function of integer order.  Uses the following:
-   j(-n,x) = (-1)^n*j(n,x) 
-   j(n,x) = x^n/(2^n*n!) * (1 - x^2/(2^2*1!*(n+1)) + x^4/(2^4*2!*(n+1)*(n+2))
-            - x^6/(2^6*3!*(n+1)*(n+2)*(n+3)) .... )
-*/
-define j(n,x) {
-  auto a, d, e, f, i, m, s, v, z
-
-  /* Make n an integer and check for negative n. */
-  z = scale;
-  scale = 0;
-  n = n/1;
-  if (n<0) {
-    n = -n;
-    if (n%2 == 1) m = 1;
-  }
-
-  /* Compute the factor of x^n/(2^n*n!) */
-  f = 1;
-  for (i=2; i<=n; i++) f = f*i;
-  scale = 1.5*z;
-  f = x^n / 2^n / f;
-
-  /* Initialize the loop .*/
-  v = e = 1;
-  s = -x*x/4
-  scale = 1.5*z
-
-  /* The Loop.... */
-  for (i=1; 1; i++) {
-    e =  e * s / i / (n+i);
-    if (e == 0) {
-       scale = z
-       if (m) return (-f*v/1);
-       return (f*v/1);
-    }
-    v += e;
-  }
-}
Index: trunk/minix/commands/bc/load.c
===================================================================
--- trunk/minix/commands/bc/load.c	(revision 9)
+++ 	(revision )
@@ -1,333 +1,0 @@
-/* load.c:  This code "loads" code into the code segments. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "global.h"
-#include "proto.h"
-
-/* Load variables. */
-
-program_counter load_adr;
-char load_str;
-char load_const;
-
-/* Initialize the load sequence. */
-void
-init_load ()
-{
-  clear_func(0);
-  load_adr.pc_func = 0;
-  load_adr.pc_addr = 0;
-  load_str = FALSE;
-  load_const = FALSE;
-}
-
-/* addbyte adds one BYTE to the current code segment. */
-void
-addbyte (byte)
-     char byte;
-{
-  int seg, offset, func;
-
-  /* If there was an error, don't continue. */
-  if (had_error) return;
-
-  /* Calculate the segment and offset. */
-  seg = load_adr.pc_addr >> BC_SEG_LOG;
-  offset = load_adr.pc_addr++ % BC_SEG_SIZE;
-  func = load_adr.pc_func;
-
-  if (seg >= BC_MAX_SEGS)
-    {
-      yyerror ("Function too big.");
-      return;
-    }
-
-  if (functions[func].f_body[seg] == NULL)
-    functions[func].f_body[seg] = (char *) bc_malloc (BC_SEG_SIZE);
-
-  /* Store the byte. */
-  functions[func].f_body[seg][offset] = byte;
-  functions[func].f_code_size++;
-}
-
-
-/* Define a label LAB to be the current program counter. */
-
-void
-def_label (lab)
-     long lab;
-{
-  bc_label_group *temp;
-  int group, offset, func;
-    
-  /* Get things ready. */
-  group = lab >> BC_LABEL_LOG;
-  offset = lab % BC_LABEL_GROUP;
-  func = load_adr.pc_func;
-  
-  /* Make sure there is at least one label group. */
-  if (functions[func].f_label == NULL)
-    {
-      functions[func].f_label = 
-	(bc_label_group *) bc_malloc (sizeof(bc_label_group));
-      functions[func].f_label->l_next = NULL;
-    }
-
-  /* Add the label group. */
-  temp = functions[func].f_label;
-  while (group > 0)
-    {
-      if (temp->l_next == NULL)
-	{
-	  temp->l_next = (bc_label_group *) bc_malloc (sizeof(bc_label_group));
-	  temp->l_next->l_next = NULL;
-	}
-      temp = temp->l_next;
-      group --;
-    }
-
-  /* Define it! */
-  temp->l_adrs [offset] = load_adr.pc_addr;
-}
-
-/* Several instructions have integers in the code.  They
-   are all known to be legal longs.  So, no error code
-   is added.  STR is the pointer to the load string and
-   must be moved to the last non-digit character. */
-
-long
-long_val (str)
-     char **str;
-{ int  val = 0;
-  char neg = FALSE;
-
-  if (**str == '-')
-    {
-      neg = TRUE;
-      (*str)++;
-    }
-  while (isdigit(**str)) 
-    val = val*10 + *(*str)++ - '0';
-
-  if (neg)
-    return -val;
-  else
-    return val;
-}
-
-
-/* load_code loads the CODE into the machine. */
-
-void
-load_code (code)
-     char *code;
-{
-  char *str;
-  long  ap_name;	/* auto or parameter name. */
-  long  label_no;
-  long  vaf_name;	/* variable, array or function number. */
-  long  func;
-  program_counter save_adr;
-
-  /* Initialize. */
-  str = code;
-   
-  /* Scan the code. */
-  while (*str != 0)
-    {
-      /* If there was an error, don't continue. */
-      if (had_error) return;
-
-      if (load_str)
-	{
-	  if (*str == '"') load_str = FALSE;
-	  addbyte (*str++);
-	}
-      else
-	if (load_const)
-	  {
-	    if (*str == '\n') 
-	      str++;
-	    else
-	      {
-		if (*str == ':')
-		  {
-		    load_const = FALSE;
-		    addbyte (*str++);
-		  }
-		else
-		  if (*str == '.')
-		    addbyte (*str++);
-		  else
-		    if (*str >= 'A')
-		      addbyte (*str++ + 10 - 'A');
-		    else
-		      addbyte (*str++ - '0');
-	      }
-	  }
-	else
-	  {
-	    switch (*str)
-	      {
-
-	      case '"':	/* Starts a string. */
-		load_str = TRUE;
-		break;
-
-	      case 'N': /* A label */
-		str++;
-		label_no = long_val (&str);
-		def_label (label_no);
-		break;
-
-	      case 'B':  /* Branch to label. */
-	      case 'J':  /* Jump to label. */
-	      case 'Z':  /* Branch Zero to label. */
-		addbyte(*str++);
-		label_no = long_val (&str);
-		if (label_no > 65535L)
-		  {  /* Better message? */
-		    fprintf (stderr,"Program too big.\n");
-		    exit(1);
-		  }
-		addbyte ( (char) label_no & 0xFF);
-		addbyte ( (char) label_no >> 8);
-		break;
-
-	      case 'F':  /* A function, get the name and initialize it. */
-		str++;
-		func = long_val (&str);
-		clear_func (func);
-#if DEBUG > 2
-		printf ("Loading function number %d\n", func);
-#endif
-		/* get the parameters */
-		while (*str++ != '.')
-		  {
-		    if (*str == '.')
-		      {
-			str++;
-			break;
-		      }
-		    ap_name = long_val (&str);
-#if DEBUG > 2
-		    printf ("parameter number %d\n", ap_name);
-#endif
-		    functions[(int)func].f_params = 
-		      nextarg (functions[(int)func].f_params, ap_name);
-		  }
-
-		/* get the auto vars */
-		while (*str != '[')
-		  {
-		    if (*str == ',') str++;
-		    ap_name = long_val (&str);
-#if DEBUG > 2
-		    printf ("auto number %d\n", ap_name);
-#endif
-		    functions[(int)func].f_autos = 
-		      nextarg (functions[(int)func].f_autos, ap_name);
-		  }
-		save_adr = load_adr;
-		load_adr.pc_func = func;
-		load_adr.pc_addr = 0;
-		break;
-		
-	      case ']':  /* A function end */
-		functions[load_adr.pc_func].f_defined = TRUE;
-		load_adr = save_adr;
-		break;
-
-	      case 'C':  /* Call a function. */
-		addbyte (*str++);
-		func = long_val (&str);
-		if (func < 128)
-		  addbyte ( (char) func);
-		else
-		  {
-		    addbyte ((func >> 8) & 0xff | 0x80);
-		    addbyte (func & 0xff);
-		  }
-		if (*str == ',') str++;
-		while (*str != ':')
-		  addbyte (*str++);
-		addbyte (':');
-		break;
-		
-	      case 'c':  /* Call a special function. */
-		addbyte (*str++);
-		addbyte (*str);
-		break;
-
-	      case 'K':  /* A constant.... may have an "F" in it. */
-		addbyte (*str);
-		load_const = TRUE;
-		break;
-
-	      case 'd':  /* Decrement. */
-	      case 'i':  /* Increment. */
-	      case 'l':  /* Load. */
-	      case 's':  /* Store. */
-	      case 'A':  /* Array Increment */
-	      case 'M':  /* Array Decrement */
-	      case 'L':  /* Array Load */
-	      case 'S':  /* Array Store */
-		addbyte (*str++);
-		vaf_name = long_val (&str);
-		if (vaf_name < 128)
-		  addbyte (vaf_name);
-		else
-		  {
-		    addbyte ((vaf_name >> 8) & 0xff | 0x80);
-		    addbyte (vaf_name & 0xff);
-		  }
-		break;
-
-	      case '@':  /* A command! */
-		switch (*(++str))
-		  {
-		  case 'i':
-		    init_load ();
-		    break;
-		  case 'r':
-		    execute ();
-		    break;
-		  } 
-		break;
-
-	      case '\n':  /* Ignore the newlines */
-		break;
-		
-	      default:   /* Anything else */
-		addbyte (*str);	   
-	      }
-	    str++;
-	  }
-    }
-}
Index: trunk/minix/commands/bc/main.c
===================================================================
--- trunk/minix/commands/bc/main.c	(revision 9)
+++ 	(revision )
@@ -1,204 +1,0 @@
-/* main.c: The main program for bc.  */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include <signal.h>
-#include "global.h"
-#include "proto.h"
-
-/* Variables for processing multiple files. */
-char   first_file;
-extern FILE *yyin;
-
-
-/* The main program for bc. */
-int
-main (argc, argv)
-     int argc;
-     char *argv[];
-{
-  int  ch; 
-  
-  /* Initialize many variables. */
-  compile_only = FALSE;
-  use_math = FALSE;
-  warn_not_std = FALSE;
-  std_only = FALSE;
-  if (isatty(0) && isatty(1)) 
-    interactive = TRUE;
-  else
-    interactive = FALSE;
-
-  /* Parse the command line */
-  ch = getopt (argc, argv, "lcisvw");
-  while (ch != EOF)
-    {
-      switch (ch)
-	{
-	case 'c':  /* compile only */
-	  compile_only = TRUE;
-	  break;
-	case 'l':  /* math lib */
-	  use_math = TRUE;
-	  break;
-	case 'i':  /* force interactive */
-	  interactive = TRUE;
-	  break;
-	case 'w':  /* Non standard features give warnings. */
-	  warn_not_std = TRUE;
-	  break;
-	case 's':  /* Non standard features give errors. */
-	  std_only = TRUE;
-	  break;
-	case 'v':  /* Print the version. */
-	  printf ("%s\n", BC_VERSION);
-	  break;
-	}
-      ch = getopt (argc, argv, "lcisvw");
-    }
-
-  /* Initialize the machine.  */
-  init_storage();
-  init_load();
-
-  /* Set up interrupts to print a message. */
-  if (interactive)
-    signal (SIGINT, use_quit);
-
-  /* Initialize the front end. */
-  init_tree();
-  init_gen ();
-  g_argv = argv;
-  g_argc = argc;
-  is_std_in = FALSE;
-  first_file = TRUE;
-  if (!open_new_file ())
-    exit (1);
-
-  /* Do the parse. */
-  yyparse ();
-
-  /* End the compile only output with a newline. */
-  if (compile_only)
-    printf ("\n");
-
-  exit (0);
-}
-
-
-/* This is the function that opens all the files. 
-   It returns TRUE if the file was opened, otherwise
-   it returns FALSE. */
-
-int
-open_new_file ()
-{
-  FILE *new_file;
-
-  /* Set the line number. */
-  line_no = 1;
-
-  /* Check to see if we are done. */
-  if (is_std_in) return (FALSE);
-
-  /* Open the other files. */
-  if (use_math && first_file)
-    {
-#ifdef BC_MATH_FILE
-      /* Make the first file be the math library. */
-      new_file = fopen (BC_MATH_FILE, "r");
-      use_math = FALSE;
-      if (new_file != NULL)
-	{
-	  new_yy_file (new_file);
-	  return TRUE;
-	}	
-      else
-	{
-	  fprintf (stderr, "Math Library unavailable.\n");
-	  exit (1);
-	}
-#else
-      /* Load the code from a precompiled version of the math libarary. */
-      extern char libmath[];
-      char tmp;
-      /* These MUST be in the order of first mention of each function.
-	 That is why "a" comes before "c" even though "a" is defined after
-	 after "c".  "a" is used in "s"! */
-      tmp = lookup ("e", FUNCT);
-      tmp = lookup ("l", FUNCT);
-      tmp = lookup ("s", FUNCT);
-      tmp = lookup ("a", FUNCT);
-      tmp = lookup ("c", FUNCT);
-      tmp = lookup ("j", FUNCT);
-      load_code (libmath);
-#endif
-    }
-  
-  /* One of the argv values. */
-  while (optind < g_argc)
-    {
-      new_file = fopen (g_argv[optind], "r");
-      if (new_file != NULL)
-	{
-	  new_yy_file (new_file);
-	  optind++;
-	  return TRUE;
-	}
-      fprintf (stderr, "File %s is unavailable.\n", g_argv[optind++]);
-      exit (1);
-    }
-  
-  /* If we fall through to here, we should return stdin. */
-  new_yy_file (stdin);
-  is_std_in = TRUE;
-  return TRUE;
-}
-
-
-/* Set yyin to the new file. */
-
-void
-new_yy_file (file)
-     FILE *file;
-{
-  if (!first_file) fclose (yyin);
-  yyin = file;
-  first_file = FALSE;
-}
-
-
-/* Message to use quit.  */
-
-void
-use_quit (sig)
-     int sig;
-{
-  printf ("\n(interrupt) use quit to exit.\n");
-  signal (SIGINT, use_quit);
-}
Index: trunk/minix/commands/bc/number.c
===================================================================
--- trunk/minix/commands/bc/number.c	(revision 9)
+++ 	(revision )
@@ -1,1405 +1,0 @@
-/* number.c: Implements arbitrary precision numbers. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "proto.h"
-
-/* Storage used for special numbers. */
-bc_num _zero_;
-bc_num _one_;
-bc_num _two_;
-
-
-/* "Frees" a bc_num NUM.  Actually decreases reference count and only
-   frees the storage if reference count is zero. */
-
-void
-free_num (num)
-    bc_num *num;
-{
-  if (*num == NULL) return;
-  (*num)->n_refs--; 
-  if ((*num)->n_refs == 0) free(*num);
-  *num = NULL;
-}
-
-
-/* new_num allocates a number and sets fields to known values. */
-
-bc_num
-new_num (length, scale)
-     int length, scale;
-{
-  bc_num temp;
-
-  temp = (bc_num) malloc (sizeof(bc_struct)+length+scale);
-  if (temp == NULL) out_of_memory ();
-  temp->n_sign = PLUS;
-  temp->n_len = length;
-  temp->n_scale = scale;
-  temp->n_refs = 1;
-  temp->n_value[0] = 0;
-  return temp;
-}
-
-
-/* Intitialize the number package! */
-
-void
-init_numbers ()
-{
-  _zero_ = new_num (1,0);
-  _one_  = new_num (1,0);
-  _one_->n_value[0] = 1;
-  _two_  = new_num (1,0);
-  _two_->n_value[0] = 2;
-}
-
-
-/* Make a copy of a number!  Just increments the reference count! */
-
-bc_num
-copy_num (num)
-     bc_num num;
-{
-  num->n_refs++;
-  return num;
-}
-
-
-/* Initialize a number NUM by making it a copy of zero. */
-
-void
-init_num (num)
-     bc_num *num;
-{
-  *num = copy_num (_zero_);
-}
-
-
-/* Convert an integer VAL to a bc number NUM. */
-
-void
-int2num (num, val)
-     bc_num *num;
-     int val;
-{
-  char buffer[30];
-  char *bptr, *vptr;
-  int  ix = 1;
-  char neg = 0;
-  
-  /* Sign. */
-  if (val < 0)
-    {
-      neg = 1;
-      val = -val;
-    }
-  
-  /* Get things going. */
-  bptr = buffer;
-  *bptr++ = val % 10;
-  val = val / 10;
-  
-  /* Extract remaining digits. */
-  while (val != 0)
-    {
-      *bptr++ = val % 10;
-      val = val / 10;
-      ix++; 		/* Count the digits. */
-    }
-  
-  /* Make the number. */
-  free_num (num);
-  *num = new_num (ix, 0);
-  if (neg) (*num)->n_sign = MINUS;
-  
-  /* Assign the digits. */
-  vptr = (*num)->n_value;
-  while (ix-- > 0)
-    *vptr++ = *--bptr;
-}
-
-
-/* Convert a number NUM to a long.  The function returns only the integer 
-   part of the number.  For numbers that are too large to represent as
-   a long, this function returns a zero.  This can be detected by checking
-   the NUM for zero after having a zero returned. */
-
-long
-num2long (num)
-     bc_num num;
-{
-  long val;
-  char *nptr;
-  int  index;
-
-  /* Extract the int value, ignore the fraction. */
-  val = 0;
-  nptr = num->n_value;
-  for (index=num->n_len; (index>0) && (val<=(LONG_MAX/10)); index--)
-    val = val*10 + *nptr++;
-  
-  /* Check for overflow.  If overflow, return zero. */
-  if (index>0) val = 0;
-  if (val < 0) val = 0;
- 
-  /* Return the value. */
-  if (num->n_sign == PLUS)
-    return (val);
-  else
-    return (-val);
-}
-
-
-/* The following are some math routines for numbers. */
-_PROTOTYPE(static int _do_compare, (bc_num n1, bc_num n2, int use_sign,
-				    int ignore_last));
-_PROTOTYPE(static void _rm_leading_zeros, (bc_num num));
-_PROTOTYPE(static bc_num _do_add, (bc_num n1, bc_num n2));
-_PROTOTYPE(static bc_num _do_sub, (bc_num n1, bc_num n2));
-_PROTOTYPE(static void _one_mult, (unsigned char *num, int size, int digit,
-				   unsigned char *result));
-
-
-
-/* Compare two bc numbers.  Return value is 0 if equal, -1 if N1 is less
-   than N2 and +1 if N1 is greater than N2.  If USE_SIGN is false, just
-   compare the magnitudes. */
-
-static int
-_do_compare (n1, n2, use_sign, ignore_last)
-     bc_num n1, n2;
-     int use_sign;
-     int ignore_last;
-{
-  char *n1ptr, *n2ptr;
-  int  count;
-  
-  /* First, compare signs. */
-  if (use_sign && n1->n_sign != n2->n_sign)
-    {
-      if (n1->n_sign == PLUS)
-	return (1);	/* Positive N1 > Negative N2 */
-      else
-	return (-1);	/* Negative N1 < Positive N1 */
-    }
-  
-  /* Now compare the magnitude. */
-  if (n1->n_len != n2->n_len)
-    {
-      if (n1->n_len > n2->n_len)
-	{
-	  /* Magnitude of n1 > n2. */
-	  if (!use_sign || n1->n_sign == PLUS)
-	    return (1);
-	  else
-	    return (-1);
-	}
-      else
-	{
-	  /* Magnitude of n1 < n2. */
-	  if (!use_sign || n1->n_sign == PLUS)
-	    return (-1);
-	  else
-	    return (1);
-	}
-    }
-
-  /* If we get here, they have the same number of integer digits.
-     check the integer part and the equal length part of the fraction. */
-  count = n1->n_len + MIN (n1->n_scale, n2->n_scale);
-  n1ptr = n1->n_value;
-  n2ptr = n2->n_value;
-
-  while ((count > 0) && (*n1ptr == *n2ptr))
-    {
-      n1ptr++;
-      n2ptr++;
-      count--;
-    }
-  if (ignore_last && count == 1 && n1->n_scale == n2->n_scale)
-    return (0);
-  if (count != 0)
-    {
-      if (*n1ptr > *n2ptr)
-	{
-	  /* Magnitude of n1 > n2. */
-	  if (!use_sign || n1->n_sign == PLUS)
-	    return (1);
-	  else
-	    return (-1);
-	}
-      else
-	{
-	  /* Magnitude of n1 < n2. */
-	  if (!use_sign || n1->n_sign == PLUS)
-	    return (-1);
-	  else
-	    return (1);
-	}
-    }
-
-  /* They are equal up to the last part of the equal part of the fraction. */
-  if (n1->n_scale != n2->n_scale) 
-    if (n1->n_scale > n2->n_scale)
-      {
-	for (count = n1->n_scale-n2->n_scale; count>0; count--)
-	  if (*n1ptr++ != 0)
-	    {
-	      /* Magnitude of n1 > n2. */
-	      if (!use_sign || n1->n_sign == PLUS)
-		return (1);
-	      else
-		return (-1);
-	    }
-      }
-    else
-      {
-	for (count = n2->n_scale-n1->n_scale; count>0; count--)
-	  if (*n2ptr++ != 0)
-	    {
-	      /* Magnitude of n1 < n2. */
-	      if (!use_sign || n1->n_sign == PLUS)
-		return (-1);
-	      else
-		return (1);
-	    }
-      }
-  
-  /* They must be equal! */
-  return (0);
-}
-
-
-/* This is the "user callable" routine to compare numbers N1 and N2. */
-
-int
-bc_compare (n1, n2)
-     bc_num n1, n2;
-{
-  return _do_compare (n1, n2, TRUE, FALSE);
-}
-
-
-/* In some places we need to check if the number NUM is zero. */
-
-char
-is_zero (num)
-     bc_num num;
-{
-  int  count;
-  char *nptr;
-
-  /* Quick check. */
-  if (num == _zero_) return TRUE;
-
-  /* Initialize */
-  count = num->n_len + num->n_scale;
-  nptr = num->n_value;
-
-  /* The check */
-  while ((count > 0) && (*nptr++ == 0)) count--;
-
-  if (count != 0)
-    return FALSE;
-  else 
-    return TRUE;
-}
-
-
-/* In some places we need to check if the number is negative. */
-
-char
-is_neg (num)
-     bc_num num;
-{
-  return num->n_sign == MINUS;
-}
-
-
-/* For many things, we may have leading zeros in a number NUM.
-   _rm_leading_zeros just moves the data to the correct
-   place and adjusts the length. */
-
-static void
-_rm_leading_zeros (num)
-     bc_num num;
-{
-  int bytes;
-  char *dst, *src;
-
-  /* Do a quick check to see if we need to do it. */
-  if (*num->n_value != 0) return;
-
-  /* The first digit is 0, find the first non-zero digit in the 10's or
-     greater place. */
-  bytes = num->n_len;
-  src = num->n_value;
-  while (bytes > 1 && *src == 0) src++, bytes--;
-  num->n_len = bytes;
-  bytes += num->n_scale;
-  dst = num->n_value;
-  while (bytes-- > 0) *dst++ = *src++;
-  
-}
-
-
-/* Perform addition: N1 is added to N2 and the value is
-   returned.  The signs of N1 and N2 are ignored. */
-
-static bc_num
-_do_add (n1, n2)
-     bc_num n1, n2;
-{
-  bc_num sum;
-  int sum_scale, sum_digits;
-  char *n1ptr, *n2ptr, *sumptr;
-  int carry, n1bytes, n2bytes;
-
-  /* Prepare sum. */
-  sum_scale = MAX (n1->n_scale, n2->n_scale);
-  sum_digits = MAX (n1->n_len, n2->n_len) + 1;
-  sum = new_num (sum_digits,sum_scale);
-
-  /* Start with the fraction part.  Initialize the pointers. */
-  n1bytes = n1->n_scale;
-  n2bytes = n2->n_scale;
-  n1ptr = (char *) (n1->n_value + n1->n_len + n1bytes - 1);
-  n2ptr = (char *) (n2->n_value + n2->n_len + n2bytes - 1);
-  sumptr = (char *) (sum->n_value + sum_scale + sum_digits - 1);
-
-  /* Add the fraction part.  First copy the longer fraction.*/
-  if (n1bytes != n2bytes)
-    {
-      if (n1bytes > n2bytes)
-	while (n1bytes>n2bytes)
-	  { *sumptr-- = *n1ptr--; n1bytes--;}
-      else
-	while (n2bytes>n1bytes)
-	  { *sumptr-- = *n2ptr--; n2bytes--;}
-    }
-
-  /* Now add the remaining fraction part and equal size integer parts. */
-  n1bytes += n1->n_len;
-  n2bytes += n2->n_len;
-  carry = 0;
-  while ((n1bytes > 0) && (n2bytes > 0))
-    {
-      *sumptr = *n1ptr-- + *n2ptr-- + carry;
-      if (*sumptr > 9)
-	{
-	   carry = 1;
-	   *sumptr -= 10;
-	}
-      else
-	carry = 0;
-      sumptr--;
-      n1bytes--;
-      n2bytes--;
-    }
-
-  /* Now add carry the longer integer part. */
-  if (n1bytes == 0)
-    { n1bytes = n2bytes; n1ptr = n2ptr; }
-  while (n1bytes-- > 0)
-    {
-      *sumptr = *n1ptr-- + carry;
-      if (*sumptr > 9)
-	{
-	   carry = 1;
-	   *sumptr -= 10;
-	 }
-      else
-	carry = 0;
-      sumptr--;
-    }
-
-  /* Set final carry. */
-  if (carry == 1)
-    *sumptr += 1;
-  
-  /* Adjust sum and return. */
-  _rm_leading_zeros (sum);
-  return sum;  
-}
-
-
-/* Perform subtraction: N2 is subtracted from N1 and the value is
-   returned.  The signs of N1 and N2 are ignored.  Also, N1 is
-   assumed to be larger than N2.  */
-
-static bc_num
-_do_sub (n1, n2)
-     bc_num n1, n2;
-{
-  bc_num diff;
-  int diff_scale, diff_len;
-  int min_scale, min_len;
-  char *n1ptr, *n2ptr, *diffptr;
-  int borrow, count, val;
-
-  /* Allocate temporary storage. */
-  diff_len = MAX (n1->n_len, n2->n_len);
-  diff_scale = MAX (n1->n_scale, n2->n_scale);
-  min_len = MIN  (n1->n_len, n2->n_len);
-  min_scale = MIN (n1->n_scale, n2->n_scale);
-  diff = new_num (diff_len, diff_scale);
-
-  /* Initialize the subtract. */
-  n1ptr = (char *) (n1->n_value + n1->n_len + n1->n_scale -1);
-  n2ptr = (char *) (n2->n_value + n2->n_len + n2->n_scale -1);
-  diffptr = (char *) (diff->n_value + diff_len + diff_scale -1);
-
-  /* Subtract the numbers. */
-  borrow = 0;
-  
-  /* Take care of the longer scaled number. */
-  if (n1->n_scale != min_scale)
-    {
-      /* n1 has the longer scale */
-      for (count = n1->n_scale - min_scale; count > 0; count--)
-	*diffptr-- = *n1ptr--;
-    }
-  else
-    {
-      /* n2 has the longer scale */
-      for (count = n2->n_scale - min_scale; count > 0; count--)
-	{
-	  val = - *n2ptr-- - borrow;
-	  if (val < 0)
-	    {
-	      val += 10;
-	      borrow = 1;
-	    }
-	  else
-	    borrow = 0;
-	  *diffptr-- = val;
-	}
-    }
-  
-  /* Now do the equal length scale and integer parts. */
-  
-  for (count = 0; count < min_len + min_scale; count++)
-    {
-      val = *n1ptr-- - *n2ptr-- - borrow;
-      if (val < 0)
-	{
-	  val += 10;
-	  borrow = 1;
-	}
-      else
-	borrow = 0;
-      *diffptr-- = val;
-    }
-
-  /* If n1 has more digits then n2, we now do that subtract. */
-  if (diff_len != min_len)
-    {
-      for (count = diff_len - min_len; count > 0; count--)
-	{
-	  val = *n1ptr-- - borrow;
-	  if (val < 0)
-	    {
-	      val += 10;
-	      borrow = 1;
-	    }
-	  else
-	    borrow = 0;
-	  *diffptr-- = val;
-	}
-    }
-
-  /* Clean up and return. */
-  _rm_leading_zeros (diff);
-  return diff;
-}
-
-
-/* Here is the full add routine that takes care of negative numbers.
-   N1 is added to N2 and the result placed into RESULT. */
-
-void
-bc_add ( n1, n2, result)
-     bc_num n1, n2, *result;
-{
-  bc_num sum;
-  int cmp_res;
-
-  if (n1->n_sign == n2->n_sign)
-    {
-      sum = _do_add (n1, n2);
-      sum->n_sign = n1->n_sign;
-    }
-  else
-    {
-      /* subtraction must be done. */
-      cmp_res = _do_compare (n1, n2, FALSE, FALSE);  /* Compare magnitudes. */
-      switch (cmp_res)
-	{
-	case -1:
-	  /* n1 is less than n2, subtract n1 from n2. */
-	  sum = _do_sub (n2, n1);
-	  sum->n_sign = n2->n_sign;
-	  break;
-	case  0:
-	  /* They are equal! return zero! */
-	  sum = copy_num (_zero_);   
-	  break;
-	case  1:
-	  /* n2 is less than n1, subtract n2 from n1. */
-	  sum = _do_sub (n1, n2);
-	  sum->n_sign = n1->n_sign;
-	}
-    }
-
-  /* Clean up and return. */
-  free_num (result);
-  *result = sum;
-}
-
-
-/* Here is the full subtract routine that takes care of negative numbers.
-   N2 is subtracted from N1 and the result placed in RESULT. */
-
-void
-bc_sub ( n1, n2, result)
-     bc_num n1, n2, *result;
-{
-  bc_num diff;
-  int cmp_res;
-
-  if (n1->n_sign != n2->n_sign)
-    {
-      diff = _do_add (n1, n2);
-      diff->n_sign = n1->n_sign;
-    }
-  else
-    {
-      /* subtraction must be done. */
-      cmp_res = _do_compare (n1, n2, FALSE, FALSE);  /* Compare magnitudes. */
-      switch (cmp_res)
-	{
-	case -1:
-	  /* n1 is less than n2, subtract n1 from n2. */
-	  diff = _do_sub (n2, n1);
-	  diff->n_sign = (n2->n_sign == PLUS ? MINUS : PLUS);
-	  break;
-	case  0:
-	  /* They are equal! return zero! */
-	  diff = copy_num (_zero_);   
-	  break;
-	case  1:
-	  /* n2 is less than n1, subtract n2 from n1. */
-	  diff = _do_sub (n1, n2);
-	  diff->n_sign = n1->n_sign;
-	  break;
-	}
-    }
-  
-  /* Clean up and return. */
-  free_num (result);
-  *result = diff;
-}
-
-
-/* The multiply routine.  N2 time N1 is put int PROD with the scale of
-   the result being MIN(N2 scale+N1 scale, MAX (SCALE, N2 scale, N1 scale)).
-   */
-
-void
-bc_multiply (n1, n2, prod, scale)
-     bc_num n1, n2, *prod;
-     int scale;
-{
-  bc_num pval;			/* For the working storage. */
-  char *n1ptr, *n2ptr, *pvptr;	/* Work pointers. */
-  char *n1end, *n2end;		/* To the end of n1 and n2. */
-
-  int indx;
-  int len1, len2, total_digits;
-  long sum;
-  int full_scale, prod_scale;
-  int toss;
-
-  /* Initialize things. */
-  len1 = n1->n_len + n1->n_scale;
-  len2 = n2->n_len + n2->n_scale;
-  total_digits = len1 + len2;
-  full_scale = n1->n_scale + n2->n_scale;
-  prod_scale = MIN(full_scale,MAX(scale,MAX(n1->n_scale,n2->n_scale)));
-  toss = full_scale - prod_scale;
-  pval =  new_num (total_digits-full_scale, prod_scale);
-  pval->n_sign = ( n1->n_sign == n2->n_sign ? PLUS : MINUS );
-  n1end = (char *) (n1->n_value + len1 - 1);
-  n2end = (char *) (n2->n_value + len2 - 1);
-  pvptr = (char *) (pval->n_value + total_digits - toss - 1);
-  sum = 0;
-
-  /* Here are the loops... */
-  for (indx = 0; indx < toss; indx++)
-    {
-      n1ptr = (char *) (n1end - MAX(0, indx-len2+1));
-      n2ptr = (char *) (n2end - MIN(indx, len2-1));
-      while ((n1ptr >= n1->n_value) && (n2ptr <= n2end))
-	sum += *n1ptr-- * *n2ptr++;
-      sum = sum / 10;
-    }
-  for ( ; indx < total_digits-1; indx++)
-    {
-      n1ptr = (char *) (n1end - MAX(0, indx-len2+1));
-      n2ptr = (char *) (n2end - MIN(indx, len2-1));
-      while ((n1ptr >= n1->n_value) && (n2ptr <= n2end))
-	sum += *n1ptr-- * *n2ptr++;
-      *pvptr-- = sum % 10;
-      sum = sum / 10;
-    }
-  *pvptr-- = sum;
-
-  /* Assign to prod and clean up the number. */
-  free_num (prod);
-  *prod = pval;
-  _rm_leading_zeros (*prod);
-  if (is_zero (*prod)) 
-    (*prod)->n_sign = PLUS;
-}
-
-
-/* Some utility routines for the divide:  First a one digit multiply.
-   NUM (with SIZE digits) is multiplied by DIGIT and the result is
-   placed into RESULT.  It is written so that NUM and RESULT can be
-   the same pointers.  */
-
-static void
-_one_mult (num, size, digit, result)
-     unsigned char *num;
-     int size, digit;
-     unsigned char *result;
-{
-  int carry, value;
-  unsigned char *nptr, *rptr;
-
-  if (digit == 0)
-    memset (result, 0, size);
-  else
-    {
-      if (digit == 1)
-	memcpy (result, num, size);
-      else
-	{
-	  /* Initialize */
-	  nptr = (unsigned char *) (num+size-1);
-	  rptr = (unsigned char *) (result+size-1);
-	  carry = 0;
-
-	  while (size-- > 0)
-	    {
-	      value = *nptr-- * digit + carry;
-	      *rptr-- = value % 10;
-	      carry = value / 10;
-	    }
-  
-	  if (carry != 0) *rptr = carry;
-	}
-    }
-}
-
-
-/* The full division routine. This computes N1 / N2.  It returns
-   0 if the division is ok and the result is in QUOT.  The number of
-   digits after the decimal point is SCALE. It returns -1 if division
-   by zero is tried.  The algorithm is found in Knuth Vol 2. p237. */
-
-int
-bc_divide (n1, n2, quot, scale)
-     bc_num n1, n2, *quot;
-     int scale;
-{ 
-  bc_num qval;
-  unsigned char *num1, *num2;
-  unsigned char *ptr1, *ptr2, *n2ptr, *qptr;
-  int  scale1, val;
-  unsigned int  len1, len2, scale2, qdigits, extra, count;
-  unsigned int  qdig, qguess, borrow, carry;
-  unsigned char *mval;
-  char zero;
-  unsigned int  norm;
-
-  /* Test for divide by zero. */
-  if (is_zero (n2)) return -1;
-
-  /* Test for divide by 1.  If it is we must truncate. */
-  if (n2->n_scale == 0)
-    {
-      if (n2->n_len == 1 && *n2->n_value == 1)
-	{
-	  qval = new_num (n1->n_len, scale);
-	  qval->n_sign = (n1->n_sign == n2->n_sign ? PLUS : MINUS);
-	  memset (&qval->n_value[n1->n_len],0,scale);
-	  memcpy (qval->n_value, n1->n_value,
-		  n1->n_len + MIN(n1->n_scale,scale));
-	  free_num (quot);
-	  *quot = qval;
-	}
-    }
-  
-  /* Set up the divide.  Move the decimal point on n1 by n2's scale.
-     Remember, zeros on the end of num2 are wasted effort for dividing. */
-  scale2 = n2->n_scale;
-  n2ptr = (unsigned char *) n2->n_value+n2->n_len+scale2-1;
-  while ((scale2 > 0) && (*n2ptr-- == 0)) scale2--;
-
-  len1 = n1->n_len + scale2;
-  scale1 = n1->n_scale - scale2;
-  if (scale1 < scale)
-    extra = scale - scale1;
-  else
-    extra = 0;
-  num1 = (unsigned char *) malloc (n1->n_len+n1->n_scale+extra+2);
-  if (num1 == NULL) out_of_memory();
-  memset (num1, 0, n1->n_len+n1->n_scale+extra+2);
-  memcpy (num1+1, n1->n_value, n1->n_len+n1->n_scale);
-
-  len2 = n2->n_len + scale2;
-  num2 = (unsigned char *) malloc (len2+1);
-  if (num2 == NULL) out_of_memory();
-  memcpy (num2, n2->n_value, len2);
-  *(num2+len2) = 0;
-  n2ptr = num2;
-  while (*n2ptr == 0)
-    {
-      n2ptr++;
-      len2--;
-    }
-
-  /* Calculate the number of quotient digits. */
-  if (len2 > len1+scale)
-    {
-      qdigits = scale+1;
-      zero = TRUE;
-    }
-  else
-    {
-      zero = FALSE;
-      if (len2>len1)
-	qdigits = scale+1;  	/* One for the zero integer part. */
-      else
-	qdigits = len1-len2+scale+1;
-    }
-
-  /* Allocate and zero the storage for the quotient. */
-  qval = new_num (qdigits-scale,scale);
-  memset (qval->n_value, 0, qdigits);
-
-  /* Allocate storage for the temporary storage mval. */
-  mval = (unsigned char *) malloc (len2+1);
-  if (mval == NULL) out_of_memory ();
-
-  /* Now for the full divide algorithm. */
-  if (!zero)
-    {
-      /* Normalize */
-      norm =  10 / ((int)*n2ptr + 1);
-      if (norm != 1)
-	{
-	  _one_mult (num1, len1+scale1+extra+1, norm, num1);
-	  _one_mult (n2ptr, len2, norm, n2ptr);
-	}
-
-      /* Initialize divide loop. */
-      qdig = 0;
-      if (len2 > len1)
-	qptr = (unsigned char *) qval->n_value+len2-len1;
-      else
-	qptr = (unsigned char *) qval->n_value;
-
-      /* Loop */
-      while (qdig <= len1+scale-len2)
-	{
-	  /* Calculate the quotient digit guess. */
-	  if (*n2ptr == num1[qdig])
-	    qguess = 9;
-	  else
-	    qguess = (num1[qdig]*10 + num1[qdig+1]) / *n2ptr;
-
-	  /* Test qguess. */
-	  if (n2ptr[1]*qguess >
-	      (num1[qdig]*10 + num1[qdig+1] - *n2ptr*qguess)*10
-	       + num1[qdig+2])
-	    {
-	      qguess--;
-	      /* And again. */
-	      if (n2ptr[1]*qguess >
-		  (num1[qdig]*10 + num1[qdig+1] - *n2ptr*qguess)*10
-		  + num1[qdig+2])
-		qguess--;
-	    }
- 
-	  /* Multiply and subtract. */
-	  borrow = 0;
-	  if (qguess != 0)
-	    {
-	      *mval = 0;
-	      _one_mult (n2ptr, len2, qguess, mval+1);
-	      ptr1 = (unsigned char *) num1+qdig+len2;
-	      ptr2 = (unsigned char *) mval+len2;
-	      for (count = 0; count < len2+1; count++)
-		{
-		  val = (int) *ptr1 - (int) *ptr2-- - borrow;
-		  if (val < 0)
-		    {
-		      val += 10;
-		      borrow = 1;
-		    }
-		  else
-		    borrow = 0;
-		  *ptr1-- = val;
-		}
-	    }
-
-	  /* Test for negative result. */
-	  if (borrow == 1)
-	    {
-	      qguess--;
-	      ptr1 = (unsigned char *) num1+qdig+len2;
-	      ptr2 = (unsigned char *) n2ptr+len2-1;
-	      carry = 0;
-	      for (count = 0; count < len2; count++)
-		{
-		  val = (int) *ptr1 + (int) *ptr2-- + carry;
-		  if (val > 9)
-		    {
-		      val -= 10;
-		      carry = 1;
-		    }
-		  else
-		    carry = 0;
-		  *ptr1-- = val;
-		}
-	      if (carry == 1) *ptr1 = (*ptr1 + 1) % 10;
-	    }
-       
-	  /* We now know the quotient digit. */
-	  *qptr++ =  qguess;
-	  qdig++;
-	}
-    }
-
-  /* Clean up and return the number. */
-  qval->n_sign = ( n1->n_sign == n2->n_sign ? PLUS : MINUS );
-  if (is_zero (qval)) qval->n_sign = PLUS;
-  _rm_leading_zeros (qval);
-  free_num (quot);
-  *quot = qval;
-
-  /* Clean up temporary storage. */
-  free (mval);
-  free (num1);
-  free (num2);
-
-  return 0;	/* Everything is OK. */
-}
-
-
-/* Modulo for numbers.  This computes NUM1 % NUM2  and puts the
-   result in RESULT.   */
-
-int
-bc_modulo (num1, num2, result, scale)
-     bc_num num1, num2, *result;
-     int scale;
-{
-  bc_num temp;
-  int rscale;
-
-  /* Check for correct numbers. */
-  if (is_zero (num2)) return -1;
-
-  /* Calculate final scale. */
-  rscale = MAX (num1->n_scale, num2->n_scale+scale);
-  init_num (&temp);
-  
-  /* Calculate it. */
-  bc_divide (num1, num2, &temp, scale);
-  bc_multiply (temp, num2, &temp, rscale);
-  bc_sub (num1, temp, result);
-  free_num (&temp);
-
-  return 0;	/* Everything is OK. */
-}
-
-
-/* Raise NUM1 to the NUM2 power.  The result is placed in RESULT.
-   Maximum exponent is LONG_MAX.  If a NUM2 is not an integer,
-   only the integer part is used.  */
-
-void
-bc_raise (num1, num2, result, scale)
-     bc_num num1, num2, *result;
-     int scale;
-{
-   bc_num temp, power;
-   long exponent;
-   int rscale;
-   char neg;
-
-   /* Check the exponent for scale digits and convert to a long. */
-   if (num2->n_scale != 0)
-     rt_warn ("non-zero scale in exponent");
-   exponent = num2long (num2);
-   if (exponent == 0 && (num2->n_len > 1 || num2->n_value[0] != 0))
-       rt_error ("exponent too large in raise");
-
-   /* Special case if exponent is a zero. */
-   if (exponent == 0)
-     {
-       free_num (result);
-       *result = copy_num (_one_);
-       return;
-     }
-
-   /* Other initializations. */
-   if (exponent < 0)
-     {
-       neg = TRUE;
-       exponent = -exponent;
-       rscale = scale;
-     }
-   else
-     {
-       neg = FALSE;
-       rscale = MIN (num1->n_scale*exponent, MAX(scale, num1->n_scale));
-     }
-   temp = copy_num (_one_);
-   power = copy_num (num1);
-
-   /* Do the calculation. */
-   while (exponent != 0)
-     {
-       if (exponent & 1 != 0) 
-	 bc_multiply (temp, power, &temp, rscale);
-       bc_multiply (power, power, &power, rscale);
-       exponent = exponent >> 1;
-     }
-   
-   /* Assign the value. */
-   if (neg)
-     {
-       bc_divide (_one_, temp, result, rscale);
-       free_num (&temp);
-     }
-   else
-     {
-       free_num (result);
-       *result = temp;
-     }
-   free_num (&power);
-}
-
-
-/* Take the square root NUM and return it in NUM with SCALE digits
-   after the decimal place. */
-
-int 
-bc_sqrt (num, scale)
-     bc_num *num;
-     int scale;
-{
-  int rscale, cmp_res, done;
-  int cscale;
-  bc_num guess, guess1, point5;
-
-  /* Initial checks. */
-  cmp_res = bc_compare (*num, _zero_);
-  if (cmp_res < 0)
-    return 0;		/* error */
-  else
-    {
-      if (cmp_res == 0)
-	{
-	  free_num (num);
-	  *num = copy_num (_zero_);
-	  return 1;
-	}
-    }
-  cmp_res = bc_compare (*num, _one_);
-  if (cmp_res == 0)
-    {
-      free_num (num);
-      *num = copy_num (_one_);
-      return 1;
-    }
-
-  /* Initialize the variables. */
-  rscale = MAX (scale, (*num)->n_scale);
-  cscale = rscale + 2;
-  init_num (&guess);
-  init_num (&guess1);
-  point5 = new_num (1,1);
-  point5->n_value[1] = 5;
-  
-  
-  /* Calculate the initial guess. */
-  if (cmp_res < 0)
-    /* The number is between 0 and 1.  Guess should start at 1. */
-    guess = copy_num (_one_);
-  else
-    {
-      /* The number is greater than 1.  Guess should start at 10^(exp/2). */
-      int2num (&guess,10);
-      int2num (&guess1,(*num)->n_len);
-      bc_multiply (guess1, point5, &guess1, rscale);
-      guess1->n_scale = 0;
-      bc_raise (guess, guess1, &guess, rscale);
-      free_num (&guess1);
-    }
-  
-  /* Find the square root using Newton's algorithm. */
-  done = FALSE;
-  while (!done)
-    {
-      free_num (&guess1);
-      guess1 = copy_num (guess);
-      bc_divide (*num,guess,&guess,cscale);
-      bc_add (guess,guess1,&guess);
-      bc_multiply (guess,point5,&guess,cscale);
-      cmp_res = _do_compare (guess,guess1,FALSE,TRUE);
-      if (cmp_res == 0) done = TRUE;
-    }
-  
-  /* Assign the number and clean up. */
-  free_num (num);
-  bc_divide (guess,_one_,num,rscale);
-  free_num (&guess);
-  free_num (&guess1);
-  free_num (&point5);
-  return 1;
-}
-
-
-/* The following routines provide output for bcd numbers package
-   using the rules of POSIX bc for output. */
-
-/* This structure is used for saving digits in the conversion process. */
-typedef struct stk_rec {
-	long  digit;
-	struct stk_rec *next;
-} stk_rec;
-
-/* The reference string for digits. */
-char ref_str[] = "0123456789ABCDEF";
-
-
-/* A special output routine for "multi-character digits."  Exactly
-   SIZE characters must be output for the value VAL.  If SPACE is
-   non-zero, we must output one space before the number.  OUT_CHAR
-   is the actual routine for writing the characters. */
-
-void
-out_long (val, size, space, out_char)
-     long val;
-     int size, space;
-#ifdef __STDC__
-     void (*out_char)(int);
-#else
-     void (*out_char)();
-#endif
-{
-  char digits[40];
-  int len, ix;
-
-  if (space) (*out_char) (' ');
-  sprintf (digits, "%ld", val);
-  len = strlen (digits);
-  while (size > len)
-    {
-      (*out_char) ('0');
-      size--;
-    }
-  for (ix=0; ix < len; ix++)
-    (*out_char) (digits[ix]);
-}
-
-/* Output of a bcd number.  NUM is written in base O_BASE using OUT_CHAR
-   as the routine to do the actual output of the characters. */
-
-void
-out_num (num, o_base, out_char)
-     bc_num num;
-     int o_base;
-#ifdef __STDC__
-     void (*out_char)(int);
-#else
-     void (*out_char)();
-#endif
-{
-  char *nptr;
-  int  index, fdigit, pre_space;
-  stk_rec *digits, *temp;
-  bc_num int_part, frac_part, base, cur_dig, t_num, max_o_digit;
-
-  /* The negative sign if needed. */
-  if (num->n_sign == MINUS) (*out_char) ('-');
-
-  /* Output the number. */
-  if (is_zero (num))
-    (*out_char) ('0');
-  else
-    if (o_base == 10)
-      {
-	/* The number is in base 10, do it the fast way. */
-	nptr = num->n_value;
-	if (num->n_len > 1 || *nptr != 0)
-	  for (index=num->n_len; index>0; index--)
-	    (*out_char) (BCD_CHAR(*nptr++));
-	else
-	  nptr++;
-	
-	/* Now the fraction. */
-	if (num->n_scale > 0)
-	  {
-	    (*out_char) ('.');
-	    for (index=0; index<num->n_scale; index++)
-	      (*out_char) (BCD_CHAR(*nptr++));
-	  }
-      }
-    else
-      {
-	/* The number is some other base. */
-	digits = NULL;
-	init_num (&int_part);
-	bc_divide (num, _one_, &int_part, 0);
-	init_num (&frac_part);
-	init_num (&cur_dig);
-	init_num (&base);
-	bc_sub (num, int_part, &frac_part);
-	int2num (&base, o_base);
-	init_num (&max_o_digit);
-	int2num (&max_o_digit, o_base-1);
-
-
-	/* Get the digits of the integer part and push them on a stack. */
-	while (!is_zero (int_part))
-	  {
-	    bc_modulo (int_part, base, &cur_dig, 0);
-	    temp = (stk_rec *) malloc (sizeof(stk_rec));
-	    if (temp == NULL) out_of_memory();
-	    temp->digit = num2long (cur_dig);
-	    temp->next = digits;
-	    digits = temp;
-	    bc_divide (int_part, base, &int_part, 0);
-	  }
-
-	/* Print the digits on the stack. */
-	if (digits != NULL)
-	  {
-	    /* Output the digits. */
-	    while (digits != NULL)
-	      {
-		temp = digits;
-		digits = digits->next;
-		if (o_base <= 16) 
-		  (*out_char) (ref_str[ (int) temp->digit]);
-		else
-		  out_long (temp->digit, max_o_digit->n_len, 1, out_char);
-		free (temp);
-	      }
-	  }
-
-	/* Get and print the digits of the fraction part. */
-	if (num->n_scale > 0)
-	  {
-	    (*out_char) ('.');
-	    pre_space = 0;
-	    t_num = copy_num (_one_);
-	    while (t_num->n_len <= num->n_scale) {
-	      bc_multiply (frac_part, base, &frac_part, num->n_scale);
-	      fdigit = num2long (frac_part);
-	      int2num (&int_part, fdigit);
-	      bc_sub (frac_part, int_part, &frac_part);
-	      if (o_base <= 16)
-		(*out_char) (ref_str[fdigit]);
-	      else {
-		out_long (fdigit, max_o_digit->n_len, pre_space, out_char);
-		pre_space = 1;
-	      }
-	      bc_multiply (t_num, base, &t_num, 0);
-	    }
-	  }
-    
-	/* Clean up. */
-	free_num (&int_part);
-	free_num (&frac_part);
-	free_num (&base);
-	free_num (&cur_dig);
-      }
-}
-
-
-#if DEBUG > 0
-
-/* Debugging procedures.  Some are just so one can call them from the
-   debugger.  */
-
-/* p_n prints the number NUM in base 10. */
-
-void
-p_n (num)
-     bc_num num;
-{
-  out_num (num, 10, out_char);
-  return 0;
-}
-
-
-/* p_b prints a character array as if it was a string of bcd digits. */
-void
-p_v (name, num, len)
-     char *name;
-     unsigned char *num;
-     int len;
-{
-  int i;
-  printf ("%s=", name);
-  for (i=0; i<len; i++) printf ("%c",BCD_CHAR(num[i]));
-  printf ("\n");
-}
-
-
-/* Convert strings to bc numbers.  Base 10 only.*/
-
-void
-str2num (num, str, scale)
-     bc_num *num;
-     char *str;
-     int scale;
-{
-  int digits, strscale;
-  char *ptr, *nptr;
-  char zero_int;
-
-  /* Prepare num. */
-  free_num (num);
-
-  /* Check for valid number and count digits. */
-  ptr = str;
-  digits = 0;
-  strscale = 0;
-  zero_int = FALSE;
-  if ( (*ptr == '+') || (*ptr == '-'))  ptr++;  /* Sign */
-  while (*ptr == '0') ptr++;			/* Skip leading zeros. */
-  while (isdigit(*ptr)) ptr++, digits++;	/* digits */
-  if (*ptr == '.') ptr++;			/* decimal point */
-  while (isdigit(*ptr)) ptr++, strscale++;	/* digits */
-  if ((*ptr != '\0') || (digits+strscale == 0))
-    {
-      *num = copy_num (_zero_);
-      return;
-    }
-
-  /* Adjust numbers and allocate storage and initialize fields. */
-  strscale = MIN(strscale, scale);
-  if (digits == 0)
-    {
-      zero_int = TRUE;
-      digits = 1;
-    }
-  *num = new_num (digits, strscale);
-
-  /* Build the whole number. */
-  ptr = str;
-  if (*ptr == '-')
-    {
-      (*num)->n_sign = MINUS;
-      ptr++;
-    }
-  else
-    {
-      (*num)->n_sign = PLUS;
-      if (*ptr == '+') ptr++;
-    }
-  while (*ptr == '0') ptr++;			/* Skip leading zeros. */
-  nptr = (*num)->n_value;
-  if (zero_int)
-    {
-      *nptr++ = 0;
-      digits = 0;
-    }
-  for (;digits > 0; digits--)
-    *nptr++ = CH_VAL(*ptr++);
-
-  
-  /* Build the fractional part. */
-  if (strscale > 0)
-    {
-      ptr++;  /* skip the decimal point! */
-      for (;strscale > 0; strscale--)
-	*nptr++ = CH_VAL(*ptr++);
-    }
-}
-
-/* Convert a numbers to a string.  Base 10 only.*/
-
-char
-*num2str (num)
-      bc_num num;
-{
-  char *str, *sptr;
-  char *nptr;
-  int  index, signch;
-
-  /* Allocate the string memory. */
-  signch = ( num->n_sign == PLUS ? 0 : 1 );  /* Number of sign chars. */
-  if (num->n_scale > 0)
-    str = (char *) malloc (num->n_len + num->n_scale + 2 + signch);
-  else
-    str = (char *) malloc (num->n_len + 1 + signch);
-  if (str == NULL) out_of_memory();
-
-  /* The negative sign if needed. */
-  sptr = str;
-  if (signch) *sptr++ = '-';
-
-  /* Load the whole number. */
-  nptr = num->n_value;
-  for (index=num->n_len; index>0; index--)
-    *sptr++ = BCD_CHAR(*nptr++);
-
-  /* Now the fraction. */
-  if (num->n_scale > 0)
-    {
-      *sptr++ = '.';
-      for (index=0; index<num->n_scale; index++)
-	*sptr++ = BCD_CHAR(*nptr++);
-    }
-
-  /* Terminate the string and return it! */
-  *sptr = '\0';
-  return (str);
-}
-#endif
Index: trunk/minix/commands/bc/number.h
===================================================================
--- trunk/minix/commands/bc/number.h	(revision 9)
+++ 	(revision )
@@ -1,60 +1,0 @@
-/* number.h: Arbitrary precision numbers header file. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-
-typedef enum {PLUS, MINUS} sign;
-
-typedef struct
-    {
-      sign n_sign;
-      int  n_len;	/* The number of digits before the decimal point. */
-      int  n_scale;	/* The number of digits after the decimal point. */
-      int  n_refs;      /* The number of pointers to this number. */
-      char n_value[1];  /* The storage. Not zero char terminated. It is 
-      			   allocated with all other fields.  */
-    } bc_struct;
-
-typedef bc_struct *bc_num;
-
-/*  Some useful macros and constants. */
-
-#define CH_VAL(c)     (c - '0')
-#define BCD_CHAR(d)   (d + '0')
-
-#ifdef MIN
-#undef MIN
-#undef MAX
-#endif
-#define MAX(a,b)      (a>b?a:b)
-#define MIN(a,b)      (a>b?b:a)
-#define ODD(a)        (a&1)
-
-#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
-#endif
Index: trunk/minix/commands/bc/proto.h
===================================================================
--- trunk/minix/commands/bc/proto.h	(revision 9)
+++ 	(revision )
@@ -1,162 +1,0 @@
-/* proto.h: Prototype function definitions for "external" functions. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-/* For the pc version using k&r ACK. (minix1.5 and earlier.) */
-#ifdef SHORTNAMES
-#define init_numbers i_numbers
-#define push_constant push__constant
-#define load_const in_load_const
-#define yy_get_next_buffer yyget_next_buffer
-#define yy_init_buffer yyinit_buffer
-#define yy_last_accepting_state yylast_accepting_state
-#define arglist1 arg1list
-#endif
-
-/* Include the standard library header files. */
-#ifndef NO_UNISTD
-#include <unistd.h>
-#endif
-#ifndef NO_STDLIB
-#ifdef __STDC__
-#include <stdlib.h>
-#endif
-#endif
-
-/* Define the _PROTOTYPE macro if it is needed. */
-
-#ifndef _PROTOTYPE
-#ifdef __STDC__
-#define _PROTOTYPE(func, args) func args
-#else
-#define _PROTOTYPE(func, args) func()
-#endif
-#endif
-
-/* From execute.c */
-_PROTOTYPE(void stop_execution, (int));
-_PROTOTYPE(unsigned char byte, (program_counter *pc));
-_PROTOTYPE(void execute, (void));
-_PROTOTYPE(char prog_char, (void));
-_PROTOTYPE(char input_char, (void));
-_PROTOTYPE(void push_constant, (char (*in_char)(void), int conv_base));
-_PROTOTYPE(void push_b10_const, (program_counter *pc));
-_PROTOTYPE(void assign, (int c_code));
-
-/* From util.c */
-_PROTOTYPE(char *strcopyof, (char *str));
-_PROTOTYPE(arg_list *nextarg, (arg_list *args, int val));
-_PROTOTYPE(char *arg_str, (arg_list *args, int));
-_PROTOTYPE(void free_args, (arg_list *args));
-_PROTOTYPE(void check_params, (arg_list *params, arg_list *autos));
-_PROTOTYPE(void init_gen, (void));
-_PROTOTYPE(void generate, (char *str));
-_PROTOTYPE(void run_code, (void));
-_PROTOTYPE(void out_char, (int ch));
-_PROTOTYPE(id_rec *find_id, (id_rec *tree, char *id));
-_PROTOTYPE(int insert_id_rec, (id_rec **root, id_rec *new_id));
-_PROTOTYPE(void init_tree, (void));
-_PROTOTYPE(int lookup, (char *name, int namekind));
-_PROTOTYPE(char *bc_malloc, (int));
-_PROTOTYPE(void out_of_memory, (void));
-_PROTOTYPE(void welcome, (void));
-_PROTOTYPE(void warranty, (char *));
-_PROTOTYPE(void limits, (void));
-_PROTOTYPE(void yyerror, (char *str ,...));
-_PROTOTYPE(void warn, (char *mesg ,...));
-_PROTOTYPE(void rt_error, (char *mesg ,...));
-_PROTOTYPE(void rt_warn, (char *mesg ,...));
-
-/* From load.c */
-_PROTOTYPE(void init_load, (void));
-_PROTOTYPE(void addbyte, (int byte));
-_PROTOTYPE(void def_label, (long lab));
-_PROTOTYPE(long long_val, (char **str));
-_PROTOTYPE(void load_code, (char *code));
-
-/* From main.c */
-_PROTOTYPE(int main, (int argc , char *argv []));
-_PROTOTYPE(int open_new_file, (void));
-_PROTOTYPE(void new_yy_file, (FILE *file));
-_PROTOTYPE(void use_quit, (int));
-
-/* From number.c */
-_PROTOTYPE(void free_num, (bc_num *num));
-_PROTOTYPE(bc_num new_num, (int length, int scale));
-_PROTOTYPE(void init_numbers, (void));
-_PROTOTYPE(bc_num copy_num, (bc_num num));
-_PROTOTYPE(void init_num, (bc_num *num));
-_PROTOTYPE(void str2num, (bc_num *num, char *str, int scale));
-_PROTOTYPE(char *num2str, (bc_num num));
-_PROTOTYPE(void int2num, (bc_num *num, int val));
-_PROTOTYPE(long num2long, (bc_num num));
-_PROTOTYPE(int bc_compare, (bc_num n1, bc_num n2));
-_PROTOTYPE(char is_zero, (bc_num num));
-_PROTOTYPE(char is_neg, (bc_num num));
-_PROTOTYPE(void bc_add, (bc_num n1, bc_num n2, bc_num *result));
-_PROTOTYPE(void bc_sub, (bc_num n1, bc_num n2, bc_num *result));
-_PROTOTYPE(void bc_multiply, (bc_num n1, bc_num n2, bc_num *prod, int scale));
-_PROTOTYPE(int bc_divide, (bc_num n1, bc_num n2, bc_num *quot, int scale));
-_PROTOTYPE(int bc_modulo, (bc_num num1, bc_num num2, bc_num *result, int scale));
-_PROTOTYPE(void bc_raise, (bc_num num1, bc_num num2, bc_num *result, int scale));
-_PROTOTYPE(int bc_sqrt, (bc_num *num, int scale));
-_PROTOTYPE(void out_long, (long val, int size, int space,
-			   void (*out_char)(int)));
-_PROTOTYPE(void out_num, (bc_num num, int o_base, void (* out_char)(int)));
-
-
-/* From storage.c */
-_PROTOTYPE(void init_storage, (void));
-_PROTOTYPE(void more_functions, (void));
-_PROTOTYPE(void more_variables, (void));
-_PROTOTYPE(void more_arrays, (void));
-_PROTOTYPE(void clear_func, (int func ));
-_PROTOTYPE(int fpop, (void));
-_PROTOTYPE(void fpush, (int val ));
-_PROTOTYPE(void pop, (void));
-_PROTOTYPE(void push_copy, (bc_num num ));
-_PROTOTYPE(void push_num, (bc_num num ));
-_PROTOTYPE(char check_stack, (int depth ));
-_PROTOTYPE(bc_var *get_var, (int var_name ));
-_PROTOTYPE(bc_num *get_array_num, (int var_index, long index ));
-_PROTOTYPE(void store_var, (int var_name ));
-_PROTOTYPE(void store_array, (int var_name ));
-_PROTOTYPE(void load_var, (int var_name ));
-_PROTOTYPE(void load_array, (int var_name ));
-_PROTOTYPE(void decr_var, (int var_name ));
-_PROTOTYPE(void decr_array, (int var_name ));
-_PROTOTYPE(void incr_var, (int var_name ));
-_PROTOTYPE(void incr_array, (int var_name ));
-_PROTOTYPE(void auto_var, (int name ));
-_PROTOTYPE(void free_a_tree, (bc_array_node *root, int depth ));
-_PROTOTYPE(void pop_vars, (arg_list *list ));
-_PROTOTYPE(void process_params, (program_counter *pc, int func ));
-
-/* For the scanner and parser.... */
-_PROTOTYPE(int yyparse, (void));
-_PROTOTYPE(int yylex, (void)); 
-
Index: trunk/minix/commands/bc/sbc.y
===================================================================
--- trunk/minix/commands/bc/sbc.y	(revision 9)
+++ 	(revision )
@@ -1,448 +1,0 @@
-, %{
-/* sbc.y: A POSIX bc processor written for minix with no extensions.  */
- 
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "global.h"     /* To get the global variables. */
-#include "proto.h"
-%}
-
-%start program
-
-%union {
-	char *s_value;
-	char  c_value;
-	int   i_value;
-	arg_list *a_value;
-       }
-
-%token <i_value> NEWLINE AND OR NOT
-%token <s_value> STRING NAME NUMBER
-/*     '-', '+' are tokens themselves		*/
-%token <c_value> MUL_OP
-/*     '*', '/', '%' 				*/
-%token <c_value> ASSIGN_OP
-/*     '=', '+=',  '-=', '*=', '/=', '%=', '^=' */
-%token <s_value> REL_OP
-/*     '==', '<=', '>=', '!=', '<', '>' 	*/
-%token <c_value> INCR_DECR
-/*     '++', '--' 				*/
-%token <i_value> Define    Break    Quit    Length
-/*     'define', 'break', 'quit', 'length' 	*/
-%token <i_value> Return    For    If    While    Sqrt  Else
-/*     'return', 'for', 'if', 'while', 'sqrt',  'else' 	*/
-%token <i_value> Scale    Ibase    Obase    Auto  Read
-/*     'scale', 'ibase', 'obase', 'auto', 'read' 	*/
-%token <i_value> Warranty, Halt, Last, Continue, Print, Limits
-/*     'warranty', 'halt', 'last', 'continue', 'print', 'limits'  */
-
-/* The types of all other non-terminals. */
-%type <i_value> expression named_expression return_expression
-%type <a_value> opt_parameter_list parameter_list opt_auto_define_list
-%type <a_value> define_list opt_argument_list argument_list
-%type <i_value> program input_item semicolon_list statement_list
-%type <i_value> statement_or_error statement function relational_expression 
-
-/* precedence */
-%nonassoc REL_OP
-%right ASSIGN_OP
-%left '+' '-'
-%left MUL_OP
-%right '^'
-%nonassoc UNARY_MINUS
-%nonassoc INCR_DECR
-
-%%
-program			: /* empty */
-			    {
-			      $$ = 0;
-			      std_only = TRUE;
-			      if (interactive)
-				{
-				  printf ("s%s\n", BC_VERSION);
-				  welcome();
-				}
-			    }
-			| program input_item
-			;
-input_item		: semicolon_list NEWLINE
-			    { run_code(); }
-			| function
-			    { run_code(); }
-			| error NEWLINE
-			    {
-			      yyerrok; 
-			      init_gen() ;
-			    }
-			;
-semicolon_list		: /* empty */
-			    { $$ = 0; }
-			| statement_or_error
-			| semicolon_list ';' statement_or_error
-			| semicolon_list ';'
-			;
-statement_list		: /* empty */
-			    { $$ = 0; }
-			| statement
-			| statement_list NEWLINE
-			| statement_list NEWLINE statement
-			| statement_list ';'
-			| statement_list ';' statement
-			;
-statement_or_error	: statement
-			| error statement
-			    { $$ = $2; }
-			;
-statement 		: Warranty
-			    { warranty("s"); }
-			| expression
-			    {
-			      if ($1 & 1)
-				generate ("W");
-			      else
-				generate ("p");
-			    }
-			| STRING
-			    {
-			      $$ = 0;
-			      generate ("w");
-			      generate ($1);
-			      free ($1);
-			    }
-			| Break
-			    {
-			      if (break_label == 0)
-				yyerror ("Break outside a for/while");
-			      else
-				{
-				  sprintf (genstr, "J%1d:", break_label);
-				  generate (genstr);
-				}
-			    }
-			| Quit
-			    { exit(0); }
-			| Return
-			    { generate ("0R"); }
-			| Return '(' return_expression ')'
-			    { generate ("R"); }
-			| For 
-			    {
-			      $1 = break_label; 
-			      break_label = next_label++;
-			    }
-			  '(' expression ';'
-			    {
-			      $4 = next_label++;
-			      sprintf (genstr, "pN%1d:", $4);
-			      generate (genstr);
-			    }
-			  relational_expression ';'
-			    {
-			      $7 = next_label++;
-			      sprintf (genstr, "B%1d:J%1d:", $7, break_label);
-			      generate (genstr);
-			      $<i_value>$ = next_label++;
-			      sprintf (genstr, "N%1d:", $<i_value>$);
-			      generate (genstr);
-			    }
-			  expression ')'
-			    {
-			      sprintf (genstr, "pJ%1d:N%1d:", $4, $7);
-			      generate (genstr);
-			    }
-			  statement
-			    {
-			      sprintf (genstr, "J%1d:N%1d:", $<i_value>9,
-				       break_label);
-			      generate (genstr);
-			      break_label = $1;
-			    }
-			| If '(' relational_expression ')' 
-			    {
-			      $3 = next_label++;
-			      sprintf (genstr, "Z%1d:", $3);
-			      generate (genstr);
-			    }
-			  statement
-			    {
-			      sprintf (genstr, "N%1d:", $3); 
-			      generate (genstr);
-			    }
-			| While 
-			    {
-			      $1 = next_label++;
-			      sprintf (genstr, "N%1d:", $1);
-			      generate (genstr);
-			    }
-			'(' relational_expression 
-			    {
-			      $4 = break_label; 
-			      break_label = next_label++;
-			      sprintf (genstr, "Z%1d:", break_label);
-			      generate (genstr);
-			    }
-			')' statement
-			    {
-			      sprintf (genstr, "J%1d:N%1d:", $1, break_label);
-			      generate (genstr);
-			      break_label = $4;
-			    }
-			| '{' statement_list '}'
-			    { $$ = 0; }
-			;
-function 		: Define NAME '(' opt_parameter_list ')' '{'
-       			  NEWLINE opt_auto_define_list 
-			    {
-			      check_params ($4,$8);
-			      sprintf (genstr, "F%d,%s.%s[", lookup($2,FUNCT),
-				       arg_str ($4,TRUE), arg_str ($8,TRUE));
-			      generate (genstr);
-			      free_args ($4);
-			      free_args ($8);
-			      $1 = next_label;
-			      next_label = 0;
-			    }
-			  statement_list NEWLINE '}'
-			    {
-			      generate ("0R]");
-			      next_label = $1;
-			    }
-			;
-opt_parameter_list	: /* empty */ 
-			    { $$ = NULL; }
-			| parameter_list
-			;
-parameter_list 		: NAME
-			    { $$ = nextarg (NULL, lookup($1,SIMPLE)); }
-			| define_list ',' NAME
-			    { $$ = nextarg ($1, lookup($3,SIMPLE)); }
-			;
-opt_auto_define_list 	: /* empty */ 
-			    { $$ = NULL; }
-			| Auto define_list NEWLINE
-			    { $$ = $2; } 
-			| Auto define_list ';'
-			    { $$ = $2; } 
-			;
-define_list 		: NAME
-			    { $$ = nextarg (NULL, lookup($1,SIMPLE)); }
-			| NAME '[' ']'
-			    { $$ = nextarg (NULL, lookup($1,ARRAY)); }
-			| define_list ',' NAME
-			    { $$ = nextarg ($1, lookup($3,SIMPLE)); }
-			| define_list ',' NAME '[' ']'
-			    { $$ = nextarg ($1, lookup($3,ARRAY)); }
-			;
-opt_argument_list	: /* empty */
-			    { $$ = NULL; }
-			| argument_list
-			;
-argument_list 		: expression
-			    { $$ = nextarg (NULL,0); }
-			| argument_list ',' expression
-			    { $$ = nextarg ($1,0); }
-			;
-relational_expression	: expression
-			    { $$ = 0; }
-			| expression REL_OP expression
-			    {
-			      $$ = 0;
-			      switch (*($2))
-				{
-				case '=':
-				  generate ("=");
-				  break;
-				case '!':
-				  generate ("#");
-				  break;
-				case '<':
-				  if ($2[1] == '=')
-				    generate ("{");
-				  else
-				    generate ("<");
-				  break;
-				case '>':
-				  if ($2[1] == '=')
-				    generate ("}");
-				  else
-				    generate (">");
-				  break;
-				}
-			    }
-			;
-return_expression	: /* empty */
-			    {
-			      $$ = 0;
-			      generate ("0");
-			    }
-			| expression
-			;
-expression		: named_expression ASSIGN_OP 
-			    {
-			      if ($2 != '=')
-				{
-				  if ($1 < 0)
-				    sprintf (genstr, "DL%d:", -$1);
-				  else
-				    sprintf (genstr, "l%d:", $1);
-				  generate (genstr);
-				}
-			    }
-			  expression
-			    {
-			      $$ = 0;
-			      if ($2 != '=')
-				{
-				  sprintf (genstr, "%c", $2);
-				  generate (genstr);
-				}
-			      if ($1 < 0)
-				sprintf (genstr, "S%d:", -$1);
-			      else
-				sprintf (genstr, "s%d:", $1);
-			      generate (genstr);
-			    }
-			| expression '+' expression
-			    { generate ("+"); }
-			| expression '-' expression
-			    { generate ("-"); }
-			| expression MUL_OP expression
-			    {
-			      genstr[0] = $2;
-			      genstr[1] = 0;
-			      generate (genstr);
-			    }
-			| expression '^' expression
-			    { generate ("^"); }
-			| '-' expression           %prec UNARY_MINUS
-			    { generate ("n"); $$ = 1;}
-			| named_expression
-			    {
-			      $$ = 1;
-			      if ($1 < 0)
-				sprintf (genstr, "L%d:", -$1);
-			      else
-				sprintf (genstr, "l%d:", $1);
-			      generate (genstr);
-			    }
-			| NUMBER
-			    {
-			      int len = strlen($1);
-			      $$ = 1;
-			      if (len == 1 && *$1 == '0')
-				generate ("0");
-			      else
-				{
-				  if (len == 1 && *$1 == '1')
-				    generate ("1");
-				  else
-				    {
-				      generate ("K");
-				      generate ($1);
-				      generate (":");
-				    }
-				  free ($1);
-				}
-			    }
-			| '(' expression ')'
-			    { $$ = 1; }
-			| NAME '(' opt_argument_list ')'
-			    {
-			      $$ = 1;
-			      if ($3 != NULL)
-				{ 
-				  sprintf (genstr, "C%d,%s:", lookup($1,FUNCT),
-					   arg_str ($3,FALSE));
-				  free_args ($3);
-				}
-			      else
-				  sprintf (genstr, "C%d:", lookup($1,FUNCT));
-			      generate (genstr);
-			    }
-			| INCR_DECR named_expression
-			    {
-			      $$ = 1;
-			      if ($2 < 0)
-				{
-				  if ($1 == '+')
-				    sprintf (genstr, "DA%d:L%d:", -$2, -$2);
-				  else
-				    sprintf (genstr, "DM%d:L%d:", -$2, -$2);
-				}
-			      else
-				{
-				  if ($1 == '+')
-				    sprintf (genstr, "i%d:l%d:", $2, $2);
-				  else
-				    sprintf (genstr, "d%d:l%d:", $2, $2);
-				}
-			      generate (genstr);
-			    }
-			| named_expression INCR_DECR
-			    {
-			      $$ = 1;
-			      if ($1 < 0)
-				{
-				  sprintf (genstr, "DL%d:x", -$1);
-				  generate (genstr); 
-				  if ($2 == '+')
-				    sprintf (genstr, "A%d:", -$1);
-				  else
-				    sprintf (genstr, "M%d:", -$1);
-				}
-			      else
-				{
-				  sprintf (genstr, "l%d:", $1);
-				  generate (genstr);
-				  if ($2 == '+')
-				    sprintf (genstr, "i%d:", $1);
-				  else
-				    sprintf (genstr, "d%d:", $1);
-				}
-			      generate (genstr);
-			    }
-			| Length '(' expression ')'
-			    { generate ("cL"); $$ = 1;}
-			| Sqrt '(' expression ')'
-			    { generate ("cR"); $$ = 1;}
-			| Scale '(' expression ')'
-			    { generate ("cS"); $$ = 1;}
-			;
-named_expression	: NAME
-			    { $$ = lookup($1,SIMPLE); }
-			| NAME '[' expression ']'
-			    { $$ = lookup($1,ARRAY); }
-			| Ibase
-			    { $$ = 0; }
-			| Obase
-			    { $$ = 1; }
-			| Scale
-			    { $$ = 2; }
-			;
-
-%%
Index: trunk/minix/commands/bc/scan.c
===================================================================
--- trunk/minix/commands/bc/scan.c	(revision 9)
+++ 	(revision )
@@ -1,1369 +1,0 @@
-/* A lexical scanner generated by flex */
-
-/* scanner skeleton version:
- * $Header: /cvsup/minix/src/commands/bc/scan.c,v 1.1.1.1 2005/04/21 14:54:15 beng Exp $
- */
-
-#define FLEX_SCANNER
-
-#include <stdio.h>
-
-
-/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
-#ifdef c_plusplus
-#ifndef __cplusplus
-#define __cplusplus
-#endif
-#endif
-
-
-#ifdef __cplusplus
-
-#include <stdlib.h>
-#include <osfcn.h>
-
-/* use prototypes in function declarations */
-#define YY_USE_PROTOS
-
-/* the "const" storage-class-modifier is valid */
-#define YY_USE_CONST
-
-#else	/* ! __cplusplus */
-
-#ifdef __STDC__
-
-#ifdef __GNUC__
-#include <stddef.h>
-void *malloc( size_t );
-void free( void* );
-#else
-#include <stdlib.h>
-#endif	/* __GNUC__ */
-
-#define YY_USE_PROTOS
-#define YY_USE_CONST
-
-#endif	/* __STDC__ */
-#endif	/* ! __cplusplus */
-
-
-#ifdef __TURBOC__
-#define YY_USE_CONST
-#endif
-
-
-#ifndef YY_USE_CONST
-#define const
-#endif
-
-
-#ifdef YY_USE_PROTOS
-#define YY_PROTO(proto) proto
-#else
-#define YY_PROTO(proto) ()
-/* we can't get here if it's an ANSI C compiler, or a C++ compiler,
- * so it's got to be a K&R compiler, and therefore there's no standard
- * place from which to include these definitions
- */
-char *malloc();
-int free();
-int read();
-#endif
-
-
-/* amount of stuff to slurp up with each read */
-#ifndef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 8192
-#endif
-
-/* returned upon end-of-file */
-#define YY_END_TOK 0
-
-/* copy whatever the last rule matched to the standard output */
-
-/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */
-/* this used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite()
- */
-#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout )
-
-/* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#define YY_INPUT(buf,result,max_size) \
-	if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
-	    YY_FATAL_ERROR( "read() in flex scanner failed" );
-#define YY_NULL 0
-
-/* 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.
- */
-#define yyterminate() return ( YY_NULL )
-
-/* report a fatal error */
-
-/* The funky do-while is used to turn this macro definition into
- * a single C statement (which needs a semi-colon terminator).
- * This avoids problems with code like:
- *
- * 	if ( something_happens )
- *		YY_FATAL_ERROR( "oops, the something happened" );
- *	else
- *		everything_okay();
- *
- * 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 YY_FATAL_ERROR() call.
- */
-
-#define YY_FATAL_ERROR(msg) \
-	do \
-		{ \
-		(void) fputs( msg, stderr ); \
-		(void) putc( '\n', stderr ); \
-		exit( 1 ); \
-		} \
-	while ( 0 )
-
-/* default yywrap function - always treat EOF as an EOF */
-#define yywrap() 1
-
-/* 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 *
-
-/* 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 \
-	do \
-		{ \
-		yy_init_buffer( yy_current_buffer, yyin ); \
-		yy_load_buffer_state(); \
-		} \
-	while ( 0 )
-
-/* default declaration of generated scanner - a define so the user can
- * easily add parameters
- */
-#define YY_DECL int yylex YY_PROTO(( void )) 
-
-/* code executed at the end of each rule */
-#define YY_BREAK break;
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-#ifndef YY_BUF_SIZE
-#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */
-#endif
-
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-
-#define YY_CHAR unsigned char
-# line 1 "scan.l"
-#define INITIAL 0
-# line 2 "scan.l"
-/* scan.l: the (f)lex description file for the scanner. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "y.tab.h"
-#include "global.h"
-#include "proto.h"
-
-/* Using flex, we can ask for a smaller input buffer.  With lex, this
-   does nothing! */
-
-#ifdef SMALL_BUF
-#undef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 512
-#endif
-
-/* We want to define our own yywrap. */
-#undef yywrap
-_PROTOTYPE(int yywrap, (void));
-
-/* MINIX returns from read with < 0 if SIGINT is  encountered.
-   In flex, we can redefine YY_INPUT to the following.  In lex, this
-   does nothing! */
-#include <errno.h>
-#undef  YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
-	while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
-	    if (errno != EINTR) \
-		YY_FATAL_ERROR( "read() in flex scanner failed" );
-
-# line 60 "scan.l"
-
-/* done after the current pattern has been matched and before the
- * corresponding action - sets up yytext
- */
-#define YY_DO_BEFORE_ACTION \
-	yytext = yy_bp; \
-	yyleng = yy_cp - yy_bp; \
-	yy_hold_char = *yy_cp; \
-	*yy_cp = '\0'; \
-	yy_c_buf_p = yy_cp;
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
-/* 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_c_buf_p = yy_cp = yy_bp + n; \
-		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
-		} \
-	while ( 0 )
-
-#define unput(c) yyunput( c, yytext )
-
-
-struct yy_buffer_state
-    {
-    FILE *yy_input_file;
-
-    YY_CHAR *yy_ch_buf;		/* input buffer */
-    YY_CHAR *yy_buf_pos;	/* current position in input buffer */
-
-    /* size of input buffer in bytes, not including room for EOB characters*/
-    int yy_buf_size;	
-
-    /* number of characters read into yy_ch_buf, not including EOB characters */
-    int yy_n_chars;
-
-    int yy_eof_status;		/* whether we've seen an EOF on this buffer */
-#define EOF_NOT_SEEN 0
-    /* "pending" happens when the EOF has been seen but there's still
-     * some text process
-     */
-#define EOF_PENDING 1
-#define EOF_DONE 2
-    };
-
-static YY_BUFFER_STATE yy_current_buffer;
-
-/* 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 YY_CHAR yy_hold_char;
-
-static int yy_n_chars;		/* number of characters read into yy_ch_buf */
-
-
-
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-#ifndef YY_USER_INIT
-#define YY_USER_INIT
-#endif
-
-extern YY_CHAR *yytext;
-extern int yyleng;
-extern FILE *yyin, *yyout;
-
-YY_CHAR *yytext;
-int yyleng;
-
-FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
-
-#define YY_END_OF_BUFFER 40
-typedef int yy_state_type;
-static const short int yy_accept[144] =
-    {   0,
-        0,    0,   40,   38,   33,   31,   25,   38,   26,   38,
-       22,   26,   22,   22,   38,   26,   37,   29,   27,   29,
-       38,   22,   35,   35,   35,   35,   35,   35,   35,   35,
-       35,   35,   35,   35,   35,   35,   35,   35,   38,   33,
-       29,    0,   36,   27,   23,   30,   37,    0,   34,   37,
-       37,    0,   28,   32,   35,   35,   35,   35,   35,   35,
-       35,   35,   35,    7,   35,   35,   35,   35,   35,   35,
-       35,   35,   35,   35,   35,   24,   37,    0,    0,   37,
-        0,   35,   35,   35,   35,   35,    6,   35,   35,   35,
-       35,   35,   35,   35,   35,   35,   35,   35,   35,   35,
-
-       35,   13,   35,   35,   35,   14,   16,   35,   17,   35,
-       35,   35,   35,    3,   15,   35,   35,    9,   35,   35,
-        2,   35,   35,   11,   35,   35,   12,   20,   35,   10,
-       35,    8,   35,    1,    4,   21,    5,   35,   35,   35,
-       19,   18,    0
-    } ;
-
-static const YY_CHAR 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,    5,    1,    1,    6,    7,    1,    8,
-        9,   10,   11,   12,   13,   14,   15,   16,   16,   16,
-       16,   16,   16,   16,   16,   16,   16,    1,   17,   18,
-       19,   20,    1,    1,   21,   21,   21,   21,   21,   21,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-       22,   23,   24,   25,   26,    1,   27,   28,   29,   30,
-
-       31,   32,   33,   34,   35,   36,   37,   38,   39,   40,
-       41,   42,   43,   44,   45,   46,   47,   36,   48,   36,
-       49,   36,   50,   51,   52,    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,    1
-    } ;
-
-static const YY_CHAR yy_meta[53] =
-    {   0,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    2,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    2,    2,    2,    2,    2,
-        2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
-        2,    2,    2,    2,    2,    2,    2,    2,    2,    1,
-        1,    1
-    } ;
-
-static const short int yy_base[146] =
-    {   0,
-        0,    0,  193,  194,  190,  194,  172,  185,  170,  181,
-      194,  168,   42,   41,   41,   46,   52,  167,   61,  166,
-      181,  164,  135,  137,  139,  148,  140,  136,    0,  149,
-       27,   50,  147,  130,  126,  141,   40,   36,  120,  168,
-      194,  164,  194,  194,  194,  194,   66,  165,  194,   72,
-       76,  164,  194,  194,    0,  120,  134,  124,  131,  117,
-      117,  122,  132,    0,  113,  117,  117,  128,  119,  118,
-       52,  125,  107,  106,  114,  194,   80,  145,   84,   88,
-      144,  105,  118,   98,  108,  111,    0,   95,   95,   93,
-      105,  102,   91,   95,   88,  103,   85,   93,   84,   85,
-
-       90,    0,   90,   91,   85,    0,    0,   93,    0,   77,
-       76,   90,   74,    0,    0,   75,   87,    0,   90,   85,
-        0,   75,   83,    0,   76,   63,    0,    0,   66,    0,
-       62,    0,   47,    0,    0,    0,    0,   45,   53,   29,
-        0,    0,  194,  111,   56
-    } ;
-
-static const short int yy_def[146] =
-    {   0,
-      143,    1,  143,  143,  143,  143,  143,  144,  143,  143,
-      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  145,  145,  145,  145,  145,  145,  145,  145,
-      145,  145,  145,  145,  145,  145,  145,  145,  143,  143,
-      143,  144,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  143,  143,  145,  145,  145,  145,  145,  145,
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
-      145,  145,  145,  145,  145,  143,  143,  143,  143,  143,
-      143,  145,  145,  145,  145,  145,  145,  145,  145,  145,
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
-
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
-      145,  145,    0,  143,  143
-    } ;
-
-static const short int yy_nxt[247] =
-    {   0,
-        4,    5,    6,    7,    8,    9,   10,   11,   11,   12,
-       13,   11,   14,   15,   16,   17,   11,   18,   19,   20,
-       17,   11,   21,   11,   22,    4,   23,   24,   25,   26,
-       27,   28,   29,   30,   31,   29,   29,   32,   29,   29,
-       33,   34,   35,   36,   37,   29,   29,   38,   29,   11,
-       39,   11,   46,   46,   63,   49,   47,   55,   64,   44,
-       44,   47,   74,   48,   44,   50,   53,   51,   72,   75,
-       53,   53,   51,   53,   52,   53,   65,  142,   96,   41,
-       66,   77,   73,  141,   67,   53,   77,   80,   78,   50,
-      140,   51,   80,  139,   81,   77,   51,   97,   52,   47,
-
-       77,  138,   78,   80,   47,  137,   48,  136,   80,  135,
-       81,   42,   42,  134,  133,  132,  131,  130,  129,  128,
-      127,  126,  125,  124,  123,  122,  121,  120,  119,  118,
-      117,  116,  115,  114,  113,  112,  111,  110,  109,  108,
-      107,  106,  105,  104,  103,  102,   80,   77,  101,  100,
-       99,   98,   95,   94,   93,   92,   91,   90,   89,   88,
-       87,   86,   85,   84,   83,   82,   51,   79,   43,   40,
-       76,   71,   70,   69,   68,   62,   61,   60,   59,   58,
-       57,   56,   44,   54,   41,   41,   44,   45,   44,   43,
-       41,   40,  143,    3,  143,  143,  143,  143,  143,  143,
-
-      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  143,  143,  143,  143
-    } ;
-
-static const short int yy_chk[247] =
-    {   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,    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,   13,   14,   31,   16,   15,  145,   31,   14,
-       13,   15,   38,   15,   16,   17,   19,   17,   37,   38,
-       19,   19,   17,   19,   17,   19,   32,  140,   71,   19,
-       32,   47,   37,  139,   32,   19,   47,   50,   47,   51,
-      138,   51,   50,  133,   50,   77,   51,   71,   51,   79,
-
-       77,  131,   77,   80,   79,  129,   79,  126,   80,  125,
-       80,  144,  144,  123,  122,  120,  119,  117,  116,  113,
-      112,  111,  110,  108,  105,  104,  103,  101,  100,   99,
-       98,   97,   96,   95,   94,   93,   92,   91,   90,   89,
-       88,   86,   85,   84,   83,   82,   81,   78,   75,   74,
-       73,   72,   70,   69,   68,   67,   66,   65,   63,   62,
-       61,   60,   59,   58,   57,   56,   52,   48,   42,   40,
-       39,   36,   35,   34,   33,   30,   28,   27,   26,   25,
-       24,   23,   22,   21,   20,   18,   12,   10,    9,    8,
-        7,    5,    3,  143,  143,  143,  143,  143,  143,  143,
-
-      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
-      143,  143,  143,  143,  143,  143
-    } ;
-
-static yy_state_type yy_last_accepting_state;
-static YY_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
-
-/* these variables are all declared out here so that section 3 code can
- * manipulate them
- */
-/* points to current character in buffer */
-static YY_CHAR *yy_c_buf_p = (YY_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;
-
-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 yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr ));
-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 ));
-
-#define yy_new_buffer yy_create_buffer
-
-#ifdef __cplusplus
-static int yyinput YY_PROTO(( void ));
-#else
-static int input YY_PROTO(( void ));
-#endif
-
-YY_DECL
-    {
-    register yy_state_type yy_current_state;
-    register YY_CHAR *yy_cp, *yy_bp;
-    register int yy_act;
-
-
-
-    if ( yy_init )
-	{
-	YY_USER_INIT;
-
-	if ( ! yy_start )
-	    yy_start = 1;	/* first start state */
-
-	if ( ! yyin )
-	    yyin = stdin;
-
-	if ( ! yyout )
-	    yyout = stdout;
-
-	if ( yy_current_buffer )
-	    yy_init_buffer( yy_current_buffer, yyin );
-	else
-	    yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
-
-	yy_load_buffer_state();
-
-	yy_init = 0;
-	}
-
-    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_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 = yy_def[yy_current_state];
-		if ( yy_current_state >= 144 )
-		    yy_c = yy_meta[yy_c];
-		}
-	    yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
-	    ++yy_cp;
-	    }
-	while ( yy_base[yy_current_state] != 194 );
-
-yy_find_action:
-	yy_act = yy_accept[yy_current_state];
-
-	YY_DO_BEFORE_ACTION;
-	YY_USER_ACTION;
-
-do_action:	/* this label is used only to access EOF actions */
-
-
-	switch ( yy_act )
-	    {
-	    case 0: /* must backtrack */
-	    /* 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:
-# line 61 "scan.l"
-return(Define);
-	YY_BREAK
-case 2:
-# line 62 "scan.l"
-return(Break);
-	YY_BREAK
-case 3:
-# line 63 "scan.l"
-return(Quit);
-	YY_BREAK
-case 4:
-# line 64 "scan.l"
-return(Length);
-	YY_BREAK
-case 5:
-# line 65 "scan.l"
-return(Return);
-	YY_BREAK
-case 6:
-# line 66 "scan.l"
-return(For);
-	YY_BREAK
-case 7:
-# line 67 "scan.l"
-return(If);
-	YY_BREAK
-case 8:
-# line 68 "scan.l"
-return(While);
-	YY_BREAK
-case 9:
-# line 69 "scan.l"
-return(Sqrt);
-	YY_BREAK
-case 10:
-# line 70 "scan.l"
-return(Scale);
-	YY_BREAK
-case 11:
-# line 71 "scan.l"
-return(Ibase);
-	YY_BREAK
-case 12:
-# line 72 "scan.l"
-return(Obase);
-	YY_BREAK
-case 13:
-# line 73 "scan.l"
-return(Auto);
-	YY_BREAK
-case 14:
-# line 74 "scan.l"
-return(Else);
-	YY_BREAK
-case 15:
-# line 75 "scan.l"
-return(Read);
-	YY_BREAK
-case 16:
-# line 76 "scan.l"
-return(Halt);
-	YY_BREAK
-case 17:
-# line 77 "scan.l"
-return(Last);
-	YY_BREAK
-case 18:
-# line 78 "scan.l"
-return(Warranty);
-	YY_BREAK
-case 19:
-# line 79 "scan.l"
-return(Continue);
-	YY_BREAK
-case 20:
-# line 80 "scan.l"
-return(Print);
-	YY_BREAK
-case 21:
-# line 81 "scan.l"
-return(Limits);
-	YY_BREAK
-case 22:
-# line 82 "scan.l"
-{ yylval.c_value = yytext[0]; 
-					      return((int)yytext[0]); }
-	YY_BREAK
-case 23:
-# line 84 "scan.l"
-{ return(AND); }
-	YY_BREAK
-case 24:
-# line 85 "scan.l"
-{ return(OR); }
-	YY_BREAK
-case 25:
-# line 86 "scan.l"
-{ return(NOT); }
-	YY_BREAK
-case 26:
-# line 87 "scan.l"
-{ yylval.c_value = yytext[0]; return(MUL_OP); }
-	YY_BREAK
-case 27:
-# line 88 "scan.l"
-{ yylval.c_value = yytext[0]; return(ASSIGN_OP); }
-	YY_BREAK
-case 28:
-# line 89 "scan.l"
-{ 
-#ifdef OLD_EQ_OP
-			 char warn_save;
-			 warn_save = warn_not_std;
-			 warn_not_std = TRUE;
-			 warn ("Old fashioned =<op>");
-			 warn_not_std = warn_save;
-			 yylval.c_value = yytext[1];
-#else
-			 yylval.c_value = '=';
-			 yyless (1);
-#endif
-			 return(ASSIGN_OP);
-		       }
-	YY_BREAK
-case 29:
-# line 103 "scan.l"
-{ yylval.s_value = strcopyof((char *) yytext);
-			 return(REL_OP); }
-	YY_BREAK
-case 30:
-# line 105 "scan.l"
-{ yylval.c_value = yytext[0]; return(INCR_DECR); }
-	YY_BREAK
-case 31:
-# line 106 "scan.l"
-{ line_no++; return(NEWLINE); }
-	YY_BREAK
-case 32:
-# line 107 "scan.l"
-{  line_no++;  /* ignore a "quoted" newline */ }
-	YY_BREAK
-case 33:
-# line 108 "scan.l"
-{ /* ignore spaces and tabs */ }
-	YY_BREAK
-case 34:
-# line 109 "scan.l"
-{
-	int c;
-
-	for (;;)
-	  {
-	    while ( ((c=input()) != '*') && (c != EOF)) 
-	      /* eat it */
-	      if (c == '\n') line_no++;
-	    if (c == '*')
- 	      {
-		while ( (c=input()) == '*') /* eat it*/;
-		if (c == '/') break; /* at end of comment */
-		if (c == '\n') line_no++;
-	      }
-	    if (c == EOF)
-	      {
-		fprintf (stderr,"EOF encountered in a comment.\n");
-		break;
-	      }
-	  }
-      }
-	YY_BREAK
-case 35:
-# line 130 "scan.l"
-{ yylval.s_value = strcopyof((char *) yytext); return(NAME); }
-	YY_BREAK
-case 36:
-# line 131 "scan.l"
-{
- 	      unsigned char *look;
-	      int count = 0;
-	      yylval.s_value = strcopyof((char *) yytext);
-	      for (look = yytext; *look != 0; look++)
-		{
-		  if (*look == '\n') line_no++;
-		  if (*look == '"')  count++;
-		}
-	      if (count != 2) yyerror ("NUL character in string.");
-	      return(STRING);
-	    }
-	YY_BREAK
-case 37:
-# line 143 "scan.l"
-{
-	      unsigned char *src, *dst;
-	      int len;
-	      /* remove a trailing decimal point. */
-	      len = strlen((char *) yytext);
-	      if (yytext[len-1] == '.')
-	        yytext[len-1] = 0;
-	      /* remove leading zeros. */
-	      src = yytext;
-	      dst = yytext;
-	      while (*src == '0') src++;
-	      if (*src == 0) src--;
-	      /* Copy strings removing the newlines. */
-	      while (*src != 0)
-		{
-	          if (*src == '\\')
-		    {
-		      src++; src++;
-		      line_no++;
-		    }
-		  else
-		    *dst++ = *src++;
-	        }
-	      *dst = 0;
-	      yylval.s_value = strcopyof((char *) yytext); 
-	      return(NUMBER);
-	    }
-	YY_BREAK
-case 38:
-# line 170 "scan.l"
-{
-	  if (yytext[0] < ' ')
-	    yyerror ("illegal character: ^%c",yytext[0] + '@');
-	  else
-	    if (yytext[0] > '~')
-	      yyerror ("illegal character: \\%3d", (int) yytext[0]);
-	    else
-	      yyerror ("illegal character: %s",yytext);
-	}
-	YY_BREAK
-case 39:
-# line 179 "scan.l"
-ECHO;
-	YY_BREAK
-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 = yy_cp - yytext - 1;
-
-		/* undo the effects of YY_DO_BEFORE_ACTION */
-		*yy_cp = yy_hold_char;
-
-		/* 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 yyinput().
-		 */
-		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 + 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 + 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
-			{
-			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 + YY_MORE_ADJ;
-
-			    yy_act = YY_STATE_EOF((yy_start - 1) / 2);
-			    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 + yy_amount_of_matched_text;
-
-			yy_current_state = yy_get_previous_state();
-
-			yy_cp = yy_c_buf_p;
-			yy_bp = yytext + 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 + YY_MORE_ADJ;
-			goto yy_find_action;
-		    }
-		break;
-		}
-
-	    default:
-#ifdef FLEX_DEBUG
-		printf( "action # %d\n", yy_act );
-#endif
-		YY_FATAL_ERROR(
-			"fatal flex scanner internal error--no action found" );
-	    }
-	}
-    }
-
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * synopsis
- *     int yy_get_next_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 YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
-    register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
-    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" );
-
-    /* try to read more data */
-
-    /* first move last chars to start of buffer */
-    number_to_move = yy_c_buf_p - yytext;
-
-    for ( i = 0; i < number_to_move; ++i )
-	*(dest++) = *(source++);
-
-    if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
-	/* don't do the read, it's not guaranteed to return an EOF,
-	 * just force an EOF
-	 */
-	yy_n_chars = 0;
-
-    else
-	{
-	int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
-
-	if ( num_to_read > YY_READ_BUF_SIZE )
-	    num_to_read = YY_READ_BUF_SIZE;
-
-	else if ( num_to_read <= 0 )
-	    YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
-
-	/* read in more data */
-	YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
-		  yy_n_chars, num_to_read );
-	}
-
-    if ( yy_n_chars == 0 )
-	{
-	if ( number_to_move == 1 )
-	    {
-	    ret_val = EOB_ACT_END_OF_FILE;
-	    yy_current_buffer->yy_eof_status = EOF_DONE;
-	    }
-
-	else
-	    {
-	    ret_val = EOB_ACT_LAST_MATCH;
-	    yy_current_buffer->yy_eof_status = 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 begins at the second character in yy_ch_buf; the first
-     * character is the one which preceded it before reading in the latest
-     * buffer; it needs to be kept around in case it's a newline, so
-     * yy_get_previous_state() will have with '^' rules active
-     */
-
-    yytext = &yy_current_buffer->yy_ch_buf[1];
-
-    return ( ret_val );
-    }
-
-
-/* yy_get_previous_state - get the state just before the EOB char was reached
- *
- * synopsis
- *     yy_state_type yy_get_previous_state();
- */
-
-static yy_state_type yy_get_previous_state()
-
-    {
-    register yy_state_type yy_current_state;
-    register YY_CHAR *yy_cp;
-
-    yy_current_state = yy_start;
-
-    for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
-	{
-	register YY_CHAR yy_c = (*yy_cp ? yy_ec[*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 = yy_def[yy_current_state];
-	    if ( yy_current_state >= 144 )
-		yy_c = yy_meta[yy_c];
-	    }
-	yy_current_state = yy_nxt[yy_base[yy_current_state] + 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( register yy_state_type yy_current_state )
-#else
-static yy_state_type yy_try_NUL_trans( yy_current_state )
-register yy_state_type yy_current_state;
-#endif
-
-    {
-    register int yy_is_jam;
-    register YY_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 = yy_def[yy_current_state];
-	if ( yy_current_state >= 144 )
-	    yy_c = yy_meta[yy_c];
-	}
-    yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
-    yy_is_jam = (yy_base[yy_current_state] == 194);
-
-    return ( yy_is_jam ? 0 : yy_current_state );
-    }
-
-
-#ifdef YY_USE_PROTOS
-static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )
-#else
-static void yyunput( c, yy_bp )
-YY_CHAR c;
-register YY_CHAR *yy_bp;
-#endif
-
-    {
-    register YY_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 */
-	register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
-	register YY_CHAR *dest =
-	    &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
-	register YY_CHAR *source =
-	    &yy_current_buffer->yy_ch_buf[number_to_move];
-
-	while ( source > yy_current_buffer->yy_ch_buf )
-	    *--dest = *--source;
-
-	yy_cp += dest - source;
-	yy_bp += dest - source;
-	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" );
-	}
-
-    if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
-	yy_cp[-2] = '\n';
-
-    *--yy_cp = c;
-
-    /* note: the formal parameter *must* be called "yy_bp" for this
-     *       macro to now work correctly
-     */
-    YY_DO_BEFORE_ACTION; /* set up yytext again */
-    }
-
-
-#ifdef __cplusplus
-static int yyinput()
-#else
-static int input()
-#endif
-
-    {
-    int c;
-    YY_CHAR *yy_cp = yy_c_buf_p;
-
-    *yy_cp = 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 */
-	    yytext = yy_c_buf_p;
-	    ++yy_c_buf_p;
-
-	    switch ( yy_get_next_buffer() )
-		{
-		case EOB_ACT_END_OF_FILE:
-		    {
-		    if ( yywrap() )
-			{
-			yy_c_buf_p = yytext + YY_MORE_ADJ;
-			return ( EOF );
-			}
-
-		    YY_NEW_FILE;
-
-#ifdef __cplusplus
-		    return ( yyinput() );
-#else
-		    return ( input() );
-#endif
-		    }
-		    break;
-
-		case EOB_ACT_CONTINUE_SCAN:
-		    yy_c_buf_p = yytext + YY_MORE_ADJ;
-		    break;
-
-		case EOB_ACT_LAST_MATCH:
-#ifdef __cplusplus
-		    YY_FATAL_ERROR( "unexpected last match in yyinput()" );
-#else
-		    YY_FATAL_ERROR( "unexpected last match in input()" );
-#endif
-		}
-	    }
-	}
-
-    c = *yy_c_buf_p;
-    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
-
-    {
-    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 = 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) malloc( 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 = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
-
-    if ( ! b->yy_ch_buf )
-	YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
-    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 == yy_current_buffer )
-	yy_current_buffer = (YY_BUFFER_STATE) 0;
-
-    free( (char *) b->yy_ch_buf );
-    free( (char *) 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
-
-    {
-    b->yy_input_file = file;
-
-    /* we put in the '\n' and start reading from [1] so that an
-     * initial match-at-newline will be true.
-     */
-
-    b->yy_ch_buf[0] = '\n';
-    b->yy_n_chars = 1;
-
-    /* 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[1] = YY_END_OF_BUFFER_CHAR;
-    b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
-
-    b->yy_buf_pos = &b->yy_ch_buf[1];
-
-    b->yy_eof_status = EOF_NOT_SEEN;
-    }
-# line 179 "scan.l"
-
-
-
-
-/* This is the way to get multiple files input into lex. */
-
-int
-yywrap()
-{
-  if (!open_new_file ()) return (1);	/* EOF on standard in. */
-  return (0);				/* We have more input. */
-}
Index: trunk/minix/commands/bc/scan.l
===================================================================
--- trunk/minix/commands/bc/scan.l	(revision 9)
+++ 	(revision )
@@ -1,190 +1,0 @@
-%{
-/* scan.l: the (f)lex description file for the scanner. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "y.tab.h"
-#include "global.h"
-#include "proto.h"
-
-/* Using flex, we can ask for a smaller input buffer.  With lex, this
-   does nothing! */
-
-#ifdef SMALL_BUF
-#undef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 512
-#endif
-
-/* We want to define our own yywrap. */
-#undef yywrap
-_PROTOTYPE(int yywrap, (void));
-
-/* MINIX returns from read with < 0 if SIGINT is  encountered.
-   In flex, we can redefine YY_INPUT to the following.  In lex, this
-   does nothing! */
-#include <errno.h>
-#undef  YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
-	while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
-	    if (errno != EINTR) \
-		YY_FATAL_ERROR( "read() in flex scanner failed" );
-
-%}
-DIGIT [0-9A-F]
-LETTER [a-z]
-%%
-define return(Define);
-break  return(Break);
-quit   return(Quit);
-length return(Length);
-return return(Return);
-for    return(For);
-if     return(If);
-while  return(While);
-sqrt   return(Sqrt);
-scale  return(Scale);
-ibase  return(Ibase);
-obase  return(Obase);
-auto   return(Auto);
-else   return(Else);
-read   return(Read);
-halt   return(Halt);
-last   return(Last);
-warranty return(Warranty);
-continue return(Continue);
-print  return(Print);
-limits return(Limits);
-"+"|"-"|";"|"("|")"|"{"|"}"|"["|"]"|","|"^" { yylval.c_value = yytext[0]; 
-					      return((int)yytext[0]); }
-&& { return(AND); }
-\|\| { return(OR); }
-"!" { return(NOT); }
-"*"|"/"|"%" { yylval.c_value = yytext[0]; return(MUL_OP); }
-"="|\+=|-=|\*=|\/=|%=|\^=  { yylval.c_value = yytext[0]; return(ASSIGN_OP); }
-=\+|=-|=\*|=\/|=%|=\^  { 
-#ifdef OLD_EQ_OP
-			 char warn_save;
-			 warn_save = warn_not_std;
-			 warn_not_std = TRUE;
-			 warn ("Old fashioned =<op>");
-			 warn_not_std = warn_save;
-			 yylval.c_value = yytext[1];
-#else
-			 yylval.c_value = '=';
-			 yyless (1);
-#endif
-			 return(ASSIGN_OP);
-		       }
-==|\<=|\>=|\!=|"<"|">" { yylval.s_value = strcopyof((char *) yytext);
-			 return(REL_OP); }
-\+\+|-- { yylval.c_value = yytext[0]; return(INCR_DECR); }
-"\n" { line_no++; return(NEWLINE); }
-\\\n {  line_no++;  /* ignore a "quoted" newline */ }
-[ \t]+  { /* ignore spaces and tabs */ }
-"/*"  {
-	int c;
-
-	for (;;)
-	  {
-	    while ( ((c=input()) != '*') && (c != EOF)) 
-	      /* eat it */
-	      if (c == '\n') line_no++;
-	    if (c == '*')
- 	      {
-		while ( (c=input()) == '*') /* eat it*/;
-		if (c == '/') break; /* at end of comment */
-		if (c == '\n') line_no++;
-	      }
-	    if (c == EOF)
-	      {
-		fprintf (stderr,"EOF encountered in a comment.\n");
-		break;
-	      }
-	  }
-      }
-[a-z][a-z0-9_]* { yylval.s_value = strcopyof((char *) yytext); return(NAME); }
-\"[^\"]*\"  {
- 	      unsigned char *look;
-	      int count = 0;
-	      yylval.s_value = strcopyof((char *) yytext);
-	      for (look = yytext; *look != 0; look++)
-		{
-		  if (*look == '\n') line_no++;
-		  if (*look == '"')  count++;
-		}
-	      if (count != 2) yyerror ("NUL character in string.");
-	      return(STRING);
-	    }
-{DIGIT}({DIGIT}|\\\n)*("."({DIGIT}|\\\n)*)?|"."(\\\n)*{DIGIT}({DIGIT}|\\\n)* {
-	      unsigned char *src, *dst;
-	      int len;
-	      /* remove a trailing decimal point. */
-	      len = strlen((char *) yytext);
-	      if (yytext[len-1] == '.')
-	        yytext[len-1] = 0;
-	      /* remove leading zeros. */
-	      src = yytext;
-	      dst = yytext;
-	      while (*src == '0') src++;
-	      if (*src == 0) src--;
-	      /* Copy strings removing the newlines. */
-	      while (*src != 0)
-		{
-	          if (*src == '\\')
-		    {
-		      src++; src++;
-		      line_no++;
-		    }
-		  else
-		    *dst++ = *src++;
-	        }
-	      *dst = 0;
-	      yylval.s_value = strcopyof((char *) yytext); 
-	      return(NUMBER);
-	    }
-.       {
-	  if (yytext[0] < ' ')
-	    yyerror ("illegal character: ^%c",yytext[0] + '@');
-	  else
-	    if (yytext[0] > '~')
-	      yyerror ("illegal character: \\%3d", (int) yytext[0]);
-	    else
-	      yyerror ("illegal character: %s",yytext);
-	}
-%%
-
-
-
-/* This is the way to get multiple files input into lex. */
-
-int
-yywrap()
-{
-  if (!open_new_file ()) return (1);	/* EOF on standard in. */
-  return (0);				/* We have more input. */
-}
Index: trunk/minix/commands/bc/storage.c
===================================================================
--- trunk/minix/commands/bc/storage.c	(revision 9)
+++ 	(revision )
@@ -1,967 +1,0 @@
-/* storage.c:  Code and data storage manipulations.  This includes labels. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "global.h"
-#include "proto.h"
-
-
-/* Initialize the storage at the beginning of the run. */
-
-void
-init_storage ()
-{
-
-  /* Functions: we start with none and ask for more. */
-  f_count = 0;
-  more_functions ();
-  f_names[0] = "(main)";
-
-  /* Variables. */
-  v_count = 0;
-  more_variables ();
-  
-  /* Arrays. */
-  a_count = 0;
-  more_arrays ();
-
-  /* Other things... */
-  ex_stack = NULL;
-  fn_stack = NULL;
-  i_base = 10;
-  o_base = 10;
-  scale  = 0;
-  c_code = FALSE;
-  init_numbers();
-}
-
-/* Three functions for increasing the number of functions, variables, or
-   arrays that are needed.  This adds another 32 of the requested object. */
-
-void
-more_functions (VOID)
-{
-  int old_count;
-  int indx1, indx2;
-  bc_function *old_f;
-  bc_function *f;
-  char **old_names;
-
-  /* Save old information. */
-  old_count = f_count;
-  old_f = functions;
-  old_names = f_names;
-
-  /* Add a fixed amount and allocate new space. */
-  f_count += STORE_INCR;
-  functions = (bc_function *) bc_malloc (f_count*sizeof (bc_function));
-  f_names = (char **) bc_malloc (f_count*sizeof (char *));
-
-  /* Copy old ones. */
-  for (indx1 = 0; indx1 < old_count; indx1++)
-    {
-      functions[indx1] = old_f[indx1];
-      f_names[indx1] = old_names[indx1];
-    }
-
-  /* Initialize the new ones. */
-  for (; indx1 < f_count; indx1++)
-    {
-      f = &functions[indx1];
-      f->f_defined = FALSE;
-      for (indx2 = 0; indx2 < BC_MAX_SEGS; indx2++)
-	f->f_body [indx2] = NULL;
-      f->f_code_size = 0;
-      f->f_label = NULL;
-      f->f_autos = NULL;
-      f->f_params = NULL;
-    }
-
-  /* Free the old elements. */
-  if (old_count != 0)
-    {
-      free (old_f);
-      free (old_names);
-    }
-}
-
-void
-more_variables ()
-{
-  int indx;
-  int old_count;
-  bc_var **old_var;
-  char **old_names;
-
-  /* Save the old values. */
-  old_count = v_count;
-  old_var = variables;
-  old_names = v_names;
-
-  /* Increment by a fixed amount and allocate. */
-  v_count += STORE_INCR;
-  variables = (bc_var **) bc_malloc (v_count*sizeof(bc_var *));
-  v_names = (char **) bc_malloc (v_count*sizeof(char *));
-
-  /* Copy the old variables. */
-  for (indx = 3; indx < old_count; indx++)
-    variables[indx] = old_var[indx];
-
-  /* Initialize the new elements. */
-  for (; indx < v_count; indx++)
-    variables[indx] = NULL;
-
-  /* Free the old elements. */
-  if (old_count != 0)
-    {
-      free (old_var);
-      free (old_names);
-    }
-}
-
-void
-more_arrays ()
-{
-  int indx;
-  int old_count;
-  bc_var_array **old_ary;
-  char **old_names;
-
-  /* Save the old values. */
-  old_count = a_count;
-  old_ary = arrays;
-  old_names = a_names;
-
-  /* Increment by a fixed amount and allocate. */
-  a_count += STORE_INCR;
-  arrays = (bc_var_array **) bc_malloc (a_count*sizeof(bc_var_array *));
-  a_names = (char **) bc_malloc (a_count*sizeof(char *));
-
-  /* Copy the old arrays. */
-  for (indx = 1; indx < old_count; indx++)
-    arrays[indx] = old_ary[indx];
-
-
-  /* Initialize the new elements. */
-  for (; indx < v_count; indx++)
-    arrays[indx] = NULL;
-
-  /* Free the old elements. */
-  if (old_count != 0)
-    {
-      free (old_ary);
-      free (old_names);
-    }
-}
-
-
-/* clear_func clears out function FUNC and makes it ready to redefine. */
-
-void
-clear_func (func)
-     char func;
-{
-  bc_function *f;
-  int indx;
-  bc_label_group *lg;
-
-  /* Set the pointer to the function. */
-  f = &functions[func];
-  f->f_defined = FALSE;
-
-  /* Clear the code segments. */
-  for (indx = 0; indx < BC_MAX_SEGS; indx++)
-    {
-      if (f->f_body[indx] != NULL)
-	{
-	  free (f->f_body[indx]);
-	  f->f_body[indx] = NULL;
-	}
-    }
-
-  f->f_code_size = 0;
-  if (f->f_autos != NULL)
-    {
-      free_args (f->f_autos);
-      f->f_autos = NULL;
-    }
-  if (f->f_params != NULL)
-    {
-      free_args (f->f_params);
-      f->f_params = NULL;
-    }
-  while (f->f_label != NULL)
-    {
-      lg = f->f_label->l_next;
-      free (f->f_label);
-      f->f_label = lg;
-    }
-}
-
-
-/*  Pop the function execution stack and return the top. */
-
-int
-fpop()
-{
-  fstack_rec *temp;
-  int retval;
-  
-  if (fn_stack != NULL)
-    {
-      temp = fn_stack;
-      fn_stack = temp->s_next;
-      retval = temp->s_val;
-      free (temp);
-    }
-  return (retval);
-}
-
-
-/* Push VAL on to the function stack. */
-
-void
-fpush (val)
-     int val;
-{
-  fstack_rec *temp;
-  
-  temp = (fstack_rec *) bc_malloc (sizeof (fstack_rec));
-  temp->s_next = fn_stack;
-  temp->s_val = val;
-  fn_stack = temp;
-}
-
-
-/* Pop and discard the top element of the regular execution stack. */
-
-void
-pop ()
-{
-  estack_rec *temp;
-  
-  if (ex_stack != NULL)
-    {
-      temp = ex_stack;
-      ex_stack = temp->s_next;
-      free_num (&temp->s_num);
-      free (temp);
-    }
-}
-
-
-/* Push a copy of NUM on to the regular execution stack. */
-
-void
-push_copy (num)
-     bc_num num;
-{
-  estack_rec *temp;
-
-  temp = (estack_rec *) bc_malloc (sizeof (estack_rec));
-  temp->s_num = copy_num (num);
-  temp->s_next = ex_stack;
-  ex_stack = temp;
-}
-
-
-/* Push NUM on to the regular execution stack.  Do NOT push a copy. */
-
-void
-push_num (num)
-     bc_num num;
-{
-  estack_rec *temp;
-
-  temp = (estack_rec *) bc_malloc (sizeof (estack_rec));
-  temp->s_num = num;
-  temp->s_next = ex_stack;
-  ex_stack = temp;
-}
-
-
-/* Make sure the ex_stack has at least DEPTH elements on it.
-   Return TRUE if it has at least DEPTH elements, otherwise
-   return FALSE. */
-
-char
-check_stack (depth)
-     int depth;
-{
-  estack_rec *temp;
-
-  temp = ex_stack;
-  while ((temp != NULL) && (depth > 0))
-    {
-      temp = temp->s_next;
-      depth--;
-    }
-  if (depth > 0)
-    {
-      rt_error ("Stack error.");
-      return FALSE;
-    }
-  return TRUE;
-}
-
-
-/* The following routines manipulate simple variables and
-   array variables. */
-
-/* get_var returns a pointer to the variable VAR_NAME.  If one does not
-   exist, one is created. */
-
-bc_var *
-get_var (var_name)
-     int var_name;
-{
-  bc_var *var_ptr;
-
-  var_ptr = variables[var_name];
-  if (var_ptr == NULL)
-    {
-      var_ptr = variables[var_name] = (bc_var *) bc_malloc (sizeof (bc_var));
-      init_num (&var_ptr->v_value);
-    }
-  return var_ptr;
-}
-
-
-/* get_array_num returns the address of the bc_num in the array
-   structure.  If more structure is requried to get to the index,
-   this routine does the work to create that structure. VAR_INDEX
-   is a zero based index into the arrays storage array. INDEX is
-   the index into the bc array. */
-
-bc_num *
-get_array_num (var_index, index)
-     int var_index;
-     long  index;
-{
-  bc_var_array *ary_ptr;
-  bc_array *a_var;
-  bc_array_node *temp;
-  int log, ix, ix1;
-  int sub [NODE_DEPTH];
-
-  /* Get the array entry. */
-  ary_ptr = arrays[var_index];
-  if (ary_ptr == NULL)
-    {
-      ary_ptr = arrays[var_index] =
-	(bc_var_array *) bc_malloc (sizeof (bc_var_array));
-      ary_ptr->a_value = NULL;
-      ary_ptr->a_next = NULL;
-      ary_ptr->a_param = FALSE;
-    }
-
-  a_var = ary_ptr->a_value;
-  if (a_var == NULL) {
-    a_var = ary_ptr->a_value = (bc_array *) bc_malloc (sizeof (bc_array));
-    a_var->a_tree = NULL;
-    a_var->a_depth = 0;
-  }
-
-  /* Get the index variable. */
-  sub[0] = index & NODE_MASK;
-  ix = index >> NODE_SHIFT;
-  log = 1;
-  while (ix > 0 || log < a_var->a_depth)
-    {
-      sub[log] = ix & NODE_MASK;
-      ix >>= NODE_SHIFT;
-      log++;
-    }
-  
-  /* Build any tree that is necessary. */
-  while (log > a_var->a_depth)
-    {
-      temp = (bc_array_node *) bc_malloc (sizeof(bc_array_node));
-      if (a_var->a_depth != 0)
-	{
-	  temp->n_items.n_down[0] = a_var->a_tree;
-	  for (ix=1; ix < NODE_SIZE; ix++)
-	    temp->n_items.n_down[ix] = NULL;
-	}
-      else
-	{
-	  for (ix=0; ix < NODE_SIZE; ix++)
-	    temp->n_items.n_num[ix] = copy_num(_zero_);
-	}
-      a_var->a_tree = temp;
-      a_var->a_depth++;
-    }
-  
-  /* Find the indexed variable. */
-  temp = a_var->a_tree;
-  while ( log-- > 1)
-    {
-      ix1 = sub[log];
-      if (temp->n_items.n_down[ix1] == NULL)
-	{
-	  temp->n_items.n_down[ix1] =
-	    (bc_array_node *) bc_malloc (sizeof(bc_array_node));
-	  temp = temp->n_items.n_down[ix1];
-	  if (log > 1)
-	    for (ix=0; ix < NODE_SIZE; ix++)
-	      temp->n_items.n_down[ix] = NULL;
-	  else
-	    for (ix=0; ix < NODE_SIZE; ix++)
-	      temp->n_items.n_num[ix] = copy_num(_zero_);
-	}
-      else
-	temp = temp->n_items.n_down[ix1];
-    }
-  
-  /* Return the address of the indexed variable. */
-  return &(temp->n_items.n_num[sub[0]]);
-}
-
-
-/* Store the top of the execution stack into VAR_NAME.  
-   This includes the special variables ibase, obase, and scale. */
-
-void
-store_var (var_name)
-     int var_name;
-{
-  bc_var *var_ptr;
-  long temp;
-  char toobig;
-
-  if (var_name > 2)
-    {
-      /* It is a simple variable. */
-      var_ptr = get_var (var_name);
-      if (var_ptr != NULL)
-	{
-	  free_num(&var_ptr->v_value);
-	  var_ptr->v_value = copy_num (ex_stack->s_num);
-	}
-    }
-  else
-    {
-      /* It is a special variable... */
-      toobig = FALSE;
-      if (is_neg (ex_stack->s_num))
-	{
-	  switch (var_name)
-	    {
-	    case 0:
-	      rt_warn ("negative ibase, set to 2");
-	      temp = 2;
-	      break;
-	    case 1:
-	      rt_warn ("negative obase, set to 2");
-	      temp = 2;
-	      break;
-	    case 2:
-	      rt_warn ("negative scale, set to 0");
-	      temp = 0;
-	      break;
-	    }
-	}
-      else
-	{
-	  temp = num2long (ex_stack->s_num);
-	  if (!is_zero (ex_stack->s_num) && temp == 0)
-	    toobig = TRUE;
-	}
-      switch (var_name)
-	{
-	case 0:
-	  if (temp < 2 && !toobig)
-	    {
-	      i_base = 2;
-	      rt_warn ("ibase too small, set to 2");
-	    }
-	  else
-	    if (temp > 16 || toobig)
-	      {
-		i_base = 16;
-		rt_warn ("ibase too large, set to 16");
-	      }
-	    else
-	      i_base = (int) temp;
-	  break;
-
-	case 1:
-	  if (temp < 2 && !toobig)
-	    {
-	      o_base = 2;
-	      rt_warn ("obase too small, set to 2");
-	    }
-	  else
-	    if (temp > BC_BASE_MAX || toobig)
-	      {
-		o_base = BC_BASE_MAX;
-		rt_warn ("obase too large, set to %d", BC_BASE_MAX);
-	      }
-	    else
-	      o_base = (int) temp;
-	  break;
-
-	case 2:
-	  /*  WARNING:  The following if statement may generate a compiler
-	      warning if INT_MAX == LONG_MAX.  This is NOT a problem. */
-	  if (temp > BC_SCALE_MAX || toobig )
-	    {
-	      scale = BC_SCALE_MAX;
-	      rt_warn ("scale too large, set to %d", BC_SCALE_MAX);
-	    }
-	  else
-	    scale = (int) temp;
-	}
-    }
-}
-
-
-/* Store the top of the execution stack into array VAR_NAME. 
-   VAR_NAME is the name of an array, and the next to the top
-   of stack for the index into the array. */
-
-void
-store_array (var_name)
-     int var_name;
-{
-  bc_num *num_ptr;
-  long index;
-
-  if (!check_stack(2)) return;
-  index = num2long (ex_stack->s_next->s_num);
-  if (index < 0 || index > BC_DIM_MAX ||
-      (index == 0 && !is_zero(ex_stack->s_next->s_num))) 
-    rt_error ("Array %s subscript out of bounds.", a_names[var_name]);
-  else
-    {
-      num_ptr = get_array_num (var_name, index);
-      if (num_ptr != NULL)
-	{
-	  free_num (num_ptr);
-	  *num_ptr = copy_num (ex_stack->s_num);
-	  free_num (&ex_stack->s_next->s_num);
-	  ex_stack->s_next->s_num = ex_stack->s_num;
-	  init_num (&ex_stack->s_num);
-	  pop();
-	}
-    }
-}
-
-
-/*  Load a copy of VAR_NAME on to the execution stack.  This includes
-    the special variables ibase, obase and scale.  */
-
-void
-load_var (var_name)
-     int var_name;
-{
-  bc_var *var_ptr;
-
-  switch (var_name)
-    {
-
-    case 0:
-      /* Special variable ibase. */
-      push_copy (_zero_);
-      int2num (&ex_stack->s_num, i_base);
-      break;
-
-    case 1:
-      /* Special variable obase. */
-      push_copy (_zero_);
-      int2num (&ex_stack->s_num, o_base);
-      break;
-
-    case 2:
-      /* Special variable scale. */
-      push_copy (_zero_);
-      int2num (&ex_stack->s_num, scale);
-      break;
-
-    default:
-      /* It is a simple variable. */
-      var_ptr = variables[var_name];
-      if (var_ptr != NULL)
-	push_copy (var_ptr->v_value);
-      else
-	push_copy (_zero_);
-    }
-}
-
-
-/*  Load a copy of VAR_NAME on to the execution stack.  This includes
-    the special variables ibase, obase and scale.  */
-
-void
-load_array (var_name)
-     int var_name;
-{
-  bc_num *num_ptr;
-  long   index;
-
-  if (!check_stack(1)) return;
-  index = num2long (ex_stack->s_num);
-  if (index < 0 || index > BC_DIM_MAX ||
-     (index == 0 && !is_zero(ex_stack->s_num))) 
-    rt_error ("Array %s subscript out of bounds.", a_names[var_name]);
-  else
-    {
-      num_ptr = get_array_num (var_name, index);
-      if (num_ptr != NULL)
-	{
-	  pop();
-	  push_copy (*num_ptr);
-	}
-    }
-}
-
-
-/* Decrement VAR_NAME by one.  This includes the special variables
-   ibase, obase, and scale. */
-
-void
-decr_var (var_name)
-     int var_name;
-{
-  bc_var *var_ptr;
-
-  switch (var_name)
-    {
-
-    case 0: /* ibase */
-      if (i_base > 2)
-	i_base--;
-      else
-	rt_warn ("ibase too small in --");
-      break;
-      
-    case 1: /* obase */
-      if (o_base > 2)
-	o_base--;
-      else
-	rt_warn ("obase too small in --");
-      break;
-
-    case 2: /* scale */
-      if (scale > 0)
-	scale--;
-      else
-	rt_warn ("scale can not be negative in -- ");
-      break;
-
-    default: /* It is a simple variable. */
-      var_ptr = get_var (var_name);
-      if (var_ptr != NULL)
-	bc_sub (var_ptr->v_value,_one_,&var_ptr->v_value);
-    }
-}
-
-
-/* Decrement VAR_NAME by one.  VAR_NAME is an array, and the top of
-   the execution stack is the index and it is popped off the stack. */
-
-void
-decr_array (var_name)
-     char var_name;
-{
-  bc_num *num_ptr;
-  long   index;
-
-  /* It is an array variable. */
-  if (!check_stack (1)) return;
-  index = num2long (ex_stack->s_num);
-  if (index < 0 || index > BC_DIM_MAX ||
-     (index == 0 && !is_zero (ex_stack->s_num))) 
-    rt_error ("Array %s subscript out of bounds.", a_names[var_name]);
-  else
-    {
-      num_ptr = get_array_num (var_name, index);
-      if (num_ptr != NULL)
-	{
-	  pop ();
-	  bc_sub (*num_ptr, _one_, num_ptr);
-	}
-    }
-}
-
-
-/* Increment VAR_NAME by one.  This includes the special variables
-   ibase, obase, and scale. */
-
-void
-incr_var (var_name)
-     int var_name;
-{
-  bc_var *var_ptr;
-
-  switch (var_name)
-    {
-
-    case 0: /* ibase */
-      if (i_base < 16)
-	i_base++;
-      else
-	rt_warn ("ibase too big in ++");
-      break;
-
-    case 1: /* obase */
-      if (o_base < BC_BASE_MAX)
-	o_base++;
-      else
-	rt_warn ("obase too big in ++");
-      break;
-
-    case 2:
-      if (scale < BC_SCALE_MAX)
-	scale++;
-      else
-	rt_warn ("Scale too big in ++");
-      break;
-
-    default:  /* It is a simple variable. */
-      var_ptr = get_var (var_name);
-      if (var_ptr != NULL)
-	bc_add (var_ptr->v_value, _one_, &var_ptr->v_value);
-
-    }
-}
-
-
-/* Increment VAR_NAME by one.  VAR_NAME is an array and top of
-   execution stack is the index and is popped off the stack. */
-
-void
-incr_array (var_name)
-     int var_name;
-{
-  bc_num *num_ptr;
-  long   index;
-
-  if (!check_stack (1)) return;
-  index = num2long (ex_stack->s_num);
-  if (index < 0 || index > BC_DIM_MAX ||
-      (index == 0 && !is_zero (ex_stack->s_num))) 
-    rt_error ("Array %s subscript out of bounds.", a_names[var_name]);
-  else
-    {
-      num_ptr = get_array_num (var_name, index);
-      if (num_ptr != NULL)
-	{
-	  pop ();
-	  bc_add (*num_ptr, _one_, num_ptr);
-	}
-    }
-}
-
-
-/* Routines for processing autos variables and parameters. */
-
-/* NAME is an auto variable that needs to be pushed on its stack. */
-
-void
-auto_var (name)
-     int name;
-{
-  bc_var *v_temp;
-  bc_var_array *a_temp;
-  int ix;
-
-  if (name > 0)
-    {
-      /* A simple variable. */
-      ix = name;
-      v_temp = (bc_var *) bc_malloc (sizeof (bc_var));
-      v_temp->v_next = variables[ix];
-      init_num (&v_temp->v_value);
-      variables[ix] = v_temp;
-    }
-  else
-    {
-      /* An array variable. */
-      ix = -name;
-      a_temp = (bc_var_array *) bc_malloc (sizeof (bc_var_array));
-      a_temp->a_next = arrays[ix];
-      a_temp->a_value = NULL;
-      a_temp->a_param = FALSE;
-      arrays[ix] = a_temp;
-    } 
-}
-
-
-/* Free_a_tree frees everything associated with an array variable tree.
-   This is used when popping an array variable off its auto stack.  */
-
-void
-free_a_tree ( root, depth )
-     bc_array_node *root;
-     int depth;
-{
-  int ix;
-
-  if (root != NULL)
-    {
-      if (depth > 1)
-	for (ix = 0; ix < NODE_SIZE; ix++)
-	  free_a_tree (root->n_items.n_down[ix], depth-1);
-      else
-	for (ix = 0; ix < NODE_SIZE; ix++)
-	  free_num ( &(root->n_items.n_num[ix]));
-      free (root);
-    }
-}
-
-
-/* LIST is an NULL terminated list of varible names that need to be
-   popped off their auto stacks. */
-
-void
-pop_vars (list)
-     arg_list *list;
-{
-  bc_var *v_temp;
-  bc_var_array *a_temp;
-  int    ix;
-
-  while (list != NULL)
-    {
-      ix = list->av_name;
-      if (ix > 0)
-	{
-	  /* A simple variable. */
-	  v_temp = variables[ix];
-	  if (v_temp != NULL)
-	    {
-	      variables[ix] = v_temp->v_next;
-	      free_num (&v_temp->v_value);
-	      free (v_temp);
-	    }
-	}
-      else
-	{
-	  /* An array variable. */
-	  ix = -ix;
-	  a_temp = arrays[ix];
-	  if (a_temp != NULL)
-	    {
-	      arrays[ix] = a_temp->a_next;
-	      if (!a_temp->a_param && a_temp->a_value != NULL)
-		{
-		  free_a_tree (a_temp->a_value->a_tree,
-			       a_temp->a_value->a_depth);
-		  free (a_temp->a_value);
-		}
-	      free (a_temp);
-	    }
-	} 
-      list = list->next;
-    }
-}
-
-
-/* A call is being made to FUNC.  The call types are at PC.  Process
-   the parameters by doing an auto on the parameter variable and then
-   store the value at the new variable or put a pointer the the array
-   variable. */
-
-void
-process_params (pc, func)
-     program_counter *pc;
-     int func;
-{
-  char ch;
-  arg_list *params;
-  char warned = FALSE;
-  int ix, ix1;
-  bc_var *v_temp;
-  bc_var_array *a_src, *a_dest;
-  bc_num *n_temp;
-  
-  /* Get the parameter names from the function. */
-  params = functions[func].f_params;
-
-  while ((ch = byte(pc)) != ':')
-    {
-      if (params != NULL)
-	{
-	  if ((ch == '0') && params->av_name > 0)
-	    {
-	      /* A simple variable. */
-	      ix = params->av_name;
-	      v_temp = (bc_var *) bc_malloc (sizeof(bc_var));
-	      v_temp->v_next = variables[ix];
-	      v_temp->v_value = ex_stack->s_num;
-	      init_num (&ex_stack->s_num);
-	      variables[ix] = v_temp;
-	    }
-	  else
-	    if ((ch == '1') && (params->av_name < 0))
-	      {
-		/* The variables is an array variable. */
-	
-		/* Compute source index and make sure some structure exists. */
-		ix = (int) num2long (ex_stack->s_num);
-		n_temp = get_array_num (ix, 0);    
-	
-		/* Push a new array and Compute Destination index */
-		auto_var (params->av_name);  
-		ix1 = -params->av_name;
-
-		/* Set up the correct pointers in the structure. */
-		if (ix == ix1) 
-		  a_src = arrays[ix]->a_next;
-		else
-		  a_src = arrays[ix];
-		a_dest = arrays[ix1];
-		a_dest->a_param = TRUE;
-		a_dest->a_value = a_src->a_value;
-	      }
-	    else
-	      {
-		if (params->av_name < 0)
-		  rt_error ("Parameter type mismatch parameter %s.",
-			    a_names[-params->av_name]);
-		else
-		  rt_error ("Parameter type mismatch, parameter %s.",
-			    v_names[params->av_name]);
-		params++;
-	      }
-	  pop ();
-	}
-      else
-	{
-	  if (!warned)
-	    {
-	      rt_error ("Parameter number mismatch");
-	      warned = TRUE;
-	    }
-	}
-      params = params->next;
-    }
-  if (params != NULL) 
-    rt_error ("Parameter number mismatch");
-}
Index: trunk/minix/commands/bc/util.c
===================================================================
--- trunk/minix/commands/bc/util.c	(revision 9)
+++ 	(revision )
@@ -1,796 +1,0 @@
-/* util.c: Utility routines for bc. */
-
-/*  This file is part of bc written for MINIX.
-    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    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; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    You may contact the author by:
-       e-mail:  phil@cs.wwu.edu
-      us-mail:  Philip A. Nelson
-                Computer Science Department, 9062
-                Western Washington University
-                Bellingham, WA 98226-9062
-       
-*************************************************************************/
-
-
-#include "bcdefs.h"
-#ifndef VARARGS
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-#include "global.h"
-#include "proto.h"
-
-
-/* strcopyof mallocs new memory and copies a string to to the new
-   memory. */
-
-char *
-strcopyof (str)
-     char *str;
-{
-  char *temp;
-
-  temp = (char *) bc_malloc (strlen (str)+1);
-  return (strcpy (temp,str));
-}
-
-
-/* nextarg adds another value to the list of arguments. */
-
-arg_list *
-nextarg (args, val)
-     arg_list *args;
-     char val;
-{ arg_list *temp;
-
-  temp = (arg_list *) bc_malloc (sizeof (arg_list));
-  temp->av_name = val;
-  temp->next = args;
- 
-  return (temp);
-}
-
-
-/* For generate, we must produce a string in the form
-    "val,val,...,val".  We also need a couple of static variables
-   for retaining old generated strings.  It also uses a recursive
-   function that builds the string. */
-
-static char *arglist1 = NULL, *arglist2 = NULL;
-
-
-/* make_arg_str does the actual construction of the argument string.
-   ARGS is the pointer to the list and LEN is the maximum number of
-   characters needed.  1 char is the minimum needed. COMMAS tells
-   if each number should be seperated by commas.*/
-
-_PROTOTYPE (static char *make_arg_str, (arg_list *args, int len, int commas));
-
-static char *
-make_arg_str (args, len, commas)
-      arg_list *args;
-      int len;
-      int commas;
-{
-  char *temp;
-  char sval[20];
-
-  /* Recursive call. */
-  if (args != NULL)
-    temp = make_arg_str (args->next, len+11, commas);
-  else
-    {
-      temp = (char *) bc_malloc (len);
-      *temp = 0;
-      return temp;
-    }
-
-  /* Add the current number to the end of the string. */
-  if (len != 1 && commas) 
-    sprintf (sval, "%d,", args->av_name);
-  else
-    sprintf (sval, "%d", args->av_name);
-  temp = strcat (temp, sval);
-  return (temp);
-}
-
-char *
-arg_str (args, commas)
-     arg_list *args;
-     int commas;
-{
-  if (arglist2 != NULL) 
-    free (arglist2);
-  arglist2 = arglist1;
-  arglist1 = make_arg_str (args, 1, commas);
-  return (arglist1);
-}
-
-
-/* free_args frees an argument list ARGS. */
-
-void
-free_args (args)
-      arg_list *args;
-{ 
-  arg_list *temp;
- 
-  temp = args;
-  while (temp != NULL)
-    {
-      args = args->next;
-      free (temp);
-      temp = args;
-    }
-}
-
-
-/* Check for valid parameter (PARAMS) and auto (AUTOS) lists.
-   There must be no duplicates any where.  Also, this is where
-   warnings are generated for array parameters. */
-
-void
-check_params ( params, autos )
-     arg_list *params, *autos;
-{
-  arg_list *tmp1, *tmp2;
-
-  /* Check for duplicate parameters. */
-  if (params != NULL)
-    {
-      tmp1 = params;
-      while (tmp1 != NULL)
-	{
-	  tmp2 = tmp1->next;
-	  while (tmp2 != NULL)
-	    {
-	      if (tmp2->av_name == tmp1->av_name) 
-		yyerror ("duplicate parameter names");
-	      tmp2 = tmp2->next;
-	    }
-	  if (tmp1->av_name < 0)
-	    warn ("Array parameter");
-	  tmp1 = tmp1->next;
-	}
-    }
-
-  /* Check for duplicate autos. */
-  if (autos != NULL)
-    {
-      tmp1 = autos;
-      while (tmp1 != NULL)
-	{
-	  tmp2 = tmp1->next;
-	  while (tmp2 != NULL)
-	    {
-	      if (tmp2->av_name == tmp1->av_name) 
-		yyerror ("duplicate auto variable names");
-	      tmp2 = tmp2->next;
-	    }
-	  tmp1 = tmp1->next;
-	}
-    }
-
-  /* Check for duplicate between parameters and autos. */
-  if ((params != NULL) && (autos != NULL))
-    {
-      tmp1 = params;
-      while (tmp1 != NULL)
-	{
-	  tmp2 = autos;
-	  while (tmp2 != NULL)
-	    {
-	      if (tmp2->av_name == tmp1->av_name) 
-		yyerror ("variable in both parameter and auto lists");
-	      tmp2 = tmp2->next;
-	    }
-	  tmp1 = tmp1->next;
-	}
-    }
-}
-
-
-/* Initialize the code generator the parser. */
-
-void
-init_gen ()
-{
-  /* Get things ready. */
-  break_label = 0;
-  continue_label = 0;
-  next_label  = 1;
-  out_count = 2;
-  if (compile_only) 
-    printf ("@i");
-  else
-    init_load ();
-  had_error = FALSE;
-  did_gen = FALSE;
-}
-
-
-/* generate code STR for the machine. */
-
-void
-generate (str)
-      char *str;
-{
-  did_gen = TRUE;
-  if (compile_only)
-    {
-      printf ("%s",str);
-      out_count += strlen(str);
-      if (out_count > 60)
-	{
-	  printf ("\n");
-	  out_count = 0;
-	}
-    }
-  else
-    load_code (str);
-}
-
-
-/* Execute the current code as loaded. */
-
-void
-run_code()
-{
-  /* If no compile errors run the current code. */
-  if (!had_error && did_gen)
-    {
-      if (compile_only)
-	{
-	  printf ("@r\n"); 
-	  out_count = 0;
-	}
-      else
-	execute ();
-    }
-
-  /* Reinitialize the code generation and machine. */
-  if (did_gen)
-    init_gen();
-  else
-    had_error = FALSE;
-}
-
-
-/* Output routines: Write a character CH to the standard output.
-   It keeps track of the number of characters output and may
-   break the output with a "\<cr>". */
-
-void
-out_char (ch)
-     char ch;
-{
-  if (ch == '\n')
-    {
-      out_col = 0;
-      putchar ('\n');
-    }
-  else
-    {
-      out_col++;
-      if (out_col == 70)
-	{
-	  putchar ('\\');
-	  putchar ('\n');
-	  out_col = 1;
-	}
-      putchar (ch);
-    }
-}
-
-
-/* The following are "Symbol Table" routines for the parser. */
-
-/*  find_id returns a pointer to node in TREE that has the correct
-    ID.  If there is no node in TREE with ID, NULL is returned. */
-
-id_rec *
-find_id (tree, id)
-     id_rec *tree;
-     char   *id;
-{
-  int cmp_result;
-  
-  /* Check for an empty tree. */
-  if (tree == NULL)
-    return NULL;
-
-  /* Recursively search the tree. */
-  cmp_result = strcmp (id, tree->id);
-  if (cmp_result == 0)
-    return tree;  /* This is the item. */
-  else if (cmp_result < 0)
-    return find_id (tree->left, id);
-  else
-    return find_id (tree->right, id);  
-}
-
-
-/* insert_id_rec inserts a NEW_ID rec into the tree whose ROOT is
-   provided.  insert_id_rec returns TRUE if the tree height from
-   ROOT down is increased otherwise it returns FALSE.  This is a
-   recursive balanced binary tree insertion algorithm. */
-
-int insert_id_rec (root, new_id)
-     id_rec **root;
-     id_rec *new_id;
-{
-  id_rec *A, *B;
-
-  /* If root is NULL, this where it is to be inserted. */
-  if (*root == NULL)
-    {
-      *root = new_id;
-      new_id->left = NULL;
-      new_id->right = NULL;
-      new_id->balance = 0;
-      return (TRUE);
-    }
-
-  /* We need to search for a leaf. */
-  if (strcmp (new_id->id, (*root)->id) < 0)
-    {
-      /* Insert it on the left. */
-      if (insert_id_rec (&((*root)->left), new_id))
-	{
-	  /* The height increased. */
-	  (*root)->balance --;
-	  
-      switch ((*root)->balance)
-	{
-	case  0:  /* no height increase. */
-	  return (FALSE);
-	case -1:  /* height increase. */
-	  return (FALSE);
-	case -2:  /* we need to do a rebalancing act. */
-	  A = *root;
-	  B = (*root)->left;
-	  if (B->balance <= 0)
-	    {
-	      /* Single Rotate. */
-	      A->left = B->right;
-	      B->right = A;
-	      *root = B;
-	      A->balance = 0;
-	      B->balance = 0;
-	    }
-	  else
-	    {
-	      /* Double Rotate. */
-	      *root = B->right;
-	      B->right = (*root)->left;
-	      A->left = (*root)->right;
-	      (*root)->left = B;
-	      (*root)->right = A;
-	      switch ((*root)->balance)
-		{
-		case -1:
-		  A->balance = 1;
-		  B->balance = 0;
-		  break;
-		case  0:
-		  A->balance = 0;
-		  B->balance = 0;
-		  break;
-		case  1:
-		  A->balance = 0;
-		  B->balance = -1;
-		  break;
-		}
-	      (*root)->balance = 0;
-	    }
-	}     
-	} 
-    }
-  else
-    {
-      /* Insert it on the right. */
-      if (insert_id_rec (&((*root)->right), new_id))
-	{
-	  /* The height increased. */
-	  (*root)->balance ++;
-	  switch ((*root)->balance)
-	    {
-	    case 0:  /* no height increase. */
-	      return (FALSE);
-	    case 1:  /* height increase. */
-	      return (FALSE);
-	    case 2:  /* we need to do a rebalancing act. */
-	      A = *root;
-	      B = (*root)->right;
-	      if (B->balance >= 0)
-		{
-		  /* Single Rotate. */
-		  A->right = B->left;
-		  B->left = A;
-		  *root = B;
-		  A->balance = 0;
-		  B->balance = 0;
-		}
-	      else
-		{
-		  /* Double Rotate. */
-		  *root = B->left;
-		  B->left = (*root)->right;
-		  A->right = (*root)->left;
-		  (*root)->left = A;
-		  (*root)->right = B;
-		  switch ((*root)->balance)
-		    {
-		    case -1:
-		      A->balance = 0;
-		      B->balance = 1;
-		      break;
-		    case  0:
-		      A->balance = 0;
-		      B->balance = 0;
-		      break;
-		    case  1:
-		      A->balance = -1;
-		      B->balance = 0;
-		      break;
-		    }
-		  (*root)->balance = 0;
-		}
-	    }     
-	} 
-    }
-  
-  /* If we fall through to here, the tree did not grow in height. */
-  return (FALSE);
-}
-
-
-/* Initialize variables for the symbol table tree. */
-
-void
-init_tree()
-{
-  name_tree  = NULL;
-  next_array = 1;
-  next_func  = 1;
-  next_var   = 4;  /* 0 => ibase, 1 => obase, 2 => scale, 3 => last. */
-}
-
-
-/* Lookup routines for symbol table names. */
-
-int
-lookup (name, namekind)
-     char *name;
-     int  namekind;
-{
-  id_rec *id;
-
-  /* Warn about non-standard name. */
-  if (strlen(name) != 1)
-    warn ("multiple letter name - %s", name);
-
-  /* Look for the id. */
-  id = find_id (name_tree, name);
-  if (id == NULL)
-    {
-      /* We need to make a new item. */
-      id = (id_rec *) bc_malloc (sizeof (id_rec));
-      id->id = strcopyof (name);
-      id->a_name = 0;
-      id->f_name = 0;
-      id->v_name = 0;
-      insert_id_rec (&name_tree, id);
-    }
-
-  /* Return the correct value. */
-  switch (namekind)
-    {
-      
-    case ARRAY:
-      /* ARRAY variable numbers are returned as negative numbers. */
-      if (id->a_name != 0)
-	{
-	  free (name);
-	  return (-id->a_name);
-	}
-      id->a_name = next_array++;
-      a_names[id->a_name] = name;
-      if (id->a_name < MAX_STORE)
-	{
-	  if (id->a_name >= a_count)
-	    more_arrays ();
-	  return (-id->a_name);
-	}
-      yyerror ("Too many array variables");
-      exit (1);
-
-    case FUNCT:
-      if (id->f_name != 0)
-	{
-	  free(name);
-	  return (id->f_name);
-	}
-      id->f_name = next_func++;
-      f_names[id->f_name] = name;
-      if (id->f_name < MAX_STORE)
-	{
-	  if (id->f_name >= f_count)
-	    more_functions ();
-	  return (id->f_name);
-	}
-      yyerror ("Too many functions");
-      exit (1);
-
-    case SIMPLE:
-      if (id->v_name != 0)
-	{
-	  free(name);
-	  return (id->v_name);
-	}
-      id->v_name = next_var++;
-      v_names[id->v_name - 1] = name;
-      if (id->v_name <= MAX_STORE)
-	{
-	  if (id->v_name >= v_count)
-	    more_variables ();
-	  return (id->v_name);
-	}
-      yyerror ("Too many variables");
-      exit (1);
-    }
-}
-
-
-/* Print the welcome banner. */
-
-void 
-welcome()
-{
-#if !__minix
-  printf ("This is free software with ABSOLUTELY NO WARRANTY.\n");
-  printf ("For details type `warranty'. \n");
-#endif
-}
-
-
-/* Print out the warranty information. */
-
-void 
-warranty(prefix)
-     char *prefix;
-{
-  printf ("\n%s%s\n\n", prefix, BC_VERSION);
-  printf ("%s%s%s%s%s%s%s%s%s%s%s",
-"    This program is free software; you can redistribute it and/or modify\n",
-"    it under the terms of the GNU General Public License as published by\n",
-"    the Free Software Foundation; either version 2 of the License , or\n",
-"    (at your option) any later version.\n\n",
-"    This program is distributed in the hope that it will be useful,\n",
-"    but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
-"    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n",
-"    GNU General Public License for more details.\n\n",
-"    You should have received a copy of the GNU General Public License\n",
-"    along with this program. If not, write to the Free Software\n",
-"    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.\n\n");
-}
-
-/* Print out the limits of this program. */
-
-void
-limits()
-{
-  printf ("BC_BASE_MAX     = %d\n",  BC_BASE_MAX);
-  printf ("BC_DIM_MAX      = %ld\n", (long) BC_DIM_MAX);
-  printf ("BC_SCALE_MAX    = %d\n",  BC_SCALE_MAX);
-  printf ("BC_STRING_MAX   = %d\n",  BC_STRING_MAX);
-  printf ("MAX Exponent    = %ld\n", (long) LONG_MAX);
-  printf ("MAX code        = %ld\n", (long) BC_MAX_SEGS * (long) BC_SEG_SIZE);
-  printf ("multiply digits = %ld\n", (long) LONG_MAX / (long) 90);
-  printf ("Number of vars  = %ld\n", (long) MAX_STORE);
-#ifdef OLD_EQ_OP
-  printf ("Old assignment operatiors are valid. (=-, =+, ...)\n");
-#endif 
-}
-
-/* bc_malloc will check the return value so all other places do not
-   have to do it!  SIZE is the number of types to allocate. */
-
-char *
-bc_malloc (size)
-     int size;
-{
-  char *ptr;
-
-  ptr = (char *) malloc (size);
-  if (ptr == NULL)
-    out_of_memory ();
-
-  return ptr;
-}
-
-
-/* The following routines are error routines for various problems. */
-
-/* Malloc could not get enought memory. */
-
-void
-out_of_memory()
-{
-  fprintf (stderr, "Fatal error: Out of memory for malloc.\n");
-  exit (1);
-}
-
-
-
-/* The standard yyerror routine.  Built with variable number of argumnets. */
-
-#ifndef VARARGS
-#ifdef __STDC__
-void
-yyerror (char *str, ...)
-#else
-void
-yyerror (str)
-     char *str;
-#endif
-#else
-void
-yyerror (str, va_alist)
-     char *str;
-#endif
-{
-  char *name;
-  va_list args;
-
-#ifndef VARARGS   
-   va_start (args, str);
-#else
-   va_start (args);
-#endif
-  if (is_std_in)
-    name = "(standard_in)";
-  else
-    name = g_argv[optind-1];
-  fprintf (stderr,"%s %d: ",name,line_no);
-  vfprintf (stderr, str, args);
-  fprintf (stderr, "\n");
-  had_error = TRUE;
-  va_end (args);
-}
-
-
-/* The routine to produce warnings about non-standard features
-   found during parsing. */
-
-#ifndef VARARGS
-#ifdef __STDC__
-void 
-warn (char *mesg, ...)
-#else
-void
-warn (mesg)
-     char *mesg;
-#endif
-#else
-void
-warn (mesg, va_alist)
-     char *mesg;
-#endif
-{
-  char *name;
-  va_list args;
-
-#ifndef VARARGS   
-  va_start (args, mesg);
-#else
-  va_start (args);
-#endif
-  if (std_only)
-    {
-      if (is_std_in)
-	name = "(standard_in)";
-      else
-	name = g_argv[optind-1];
-      fprintf (stderr,"%s %d: ",name,line_no);
-      vfprintf (stderr, mesg, args);
-      fprintf (stderr, "\n");
-      had_error = TRUE;
-    }
-  else
-    if (warn_not_std)
-      {
-	if (is_std_in)
-	  name = "(standard_in)";
-	else
-	  name = g_argv[optind-1];
-	fprintf (stderr,"%s %d: (Warning) ",name,line_no);
-	vfprintf (stderr, mesg, args);
-	fprintf (stderr, "\n");
-      }
-  va_end (args);
-}
-
-/* Runtime error will  print a message and stop the machine. */
-
-#ifndef VARARGS
-#ifdef __STDC__
-void
-rt_error (char *mesg, ...)
-#else
-void
-rt_error (mesg)
-     char *mesg;
-#endif
-#else
-void
-rt_error (mesg, va_alist)
-     char *mesg;
-#endif
-{
-  va_list args;
-  char error_mesg [255];
-
-#ifndef VARARGS   
-  va_start (args, mesg);
-#else
-  va_start (args);
-#endif
-  vsprintf (error_mesg, mesg, args);
-  va_end (args);
-  
-  fprintf (stderr, "Runtime error (func=%s, adr=%d): %s\n",
-	   f_names[pc.pc_func], pc.pc_addr, error_mesg);
-  runtime_error = TRUE;
-}
-
-
-/* A runtime warning tells of some action taken by the processor that
-   may change the program execution but was not enough of a problem
-   to stop the execution. */
-
-#ifndef VARARGS
-#ifdef __STDC__
-void
-rt_warn (char *mesg, ...)
-#else
-void
-rt_warn (mesg)
-     char *mesg;
-#endif
-#else
-void
-rt_warn (mesg, va_alist)
-     char *mesg;
-#endif
-{
-  va_list args;
-  char error_mesg [255];
-
-#ifndef VARARGS   
-  va_start (args, mesg);
-#else
-  va_start (args);
-#endif
-  vsprintf (error_mesg, mesg, args);
-  va_end (args);
-
-  fprintf (stderr, "Runtime warning (func=%s, adr=%d): %s\n",
-	   f_names[pc.pc_func], pc.pc_addr, error_mesg);
-}
Index: trunk/minix/commands/bc/version.h
===================================================================
--- trunk/minix/commands/bc/version.h	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#define BC_VERSION  \
- "bc 1.02 (Mar 3, 92) Copyright (C) 1991, 1992 Free Software Foundation, Inc."
-
Index: trunk/minix/commands/bc/y.tab.h
===================================================================
--- trunk/minix/commands/bc/y.tab.h	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#define NEWLINE 257
-#define AND 258
-#define OR 259
-#define NOT 260
-#define STRING 261
-#define NAME 262
-#define NUMBER 263
-#define MUL_OP 264
-#define ASSIGN_OP 265
-#define REL_OP 266
-#define INCR_DECR 267
-#define Define 268
-#define Break 269
-#define Quit 270
-#define Length 271
-#define Return 272
-#define For 273
-#define If 274
-#define While 275
-#define Sqrt 276
-#define Else 277
-#define Scale 278
-#define Ibase 279
-#define Obase 280
-#define Auto 281
-#define Read 282
-#define Warranty 283
-#define Halt 284
-#define Last 285
-#define Continue 286
-#define Print 287
-#define Limits 288
-#define UNARY_MINUS 289
-typedef union {
-	char	 *s_value;
-	char	  c_value;
-	int	  i_value;
-	arg_list *a_value;
-       } YYSTYPE;
-extern YYSTYPE yylval;
Index: trunk/minix/commands/byacc/ACKNOWLEDGEMEN
===================================================================
--- trunk/minix/commands/byacc/ACKNOWLEDGEMEN	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-     Berkeley Yacc owes much to the unflagging efforts of Keith Bostic.
-His badgering kept me working on it long after I was ready to quit.
-
-     Berkeley Yacc is based on the excellent algorithm for computing LALR(1)
-lookaheads developed by Tom Pennello and Frank DeRemer.  The algorithm is
-described in their almost impenetrable article in TOPLAS 4,4.
-
-     Finally, much of the credit for the latest version must go to those
-who pointed out deficiencies of my earlier releases.  Among the most
-prolific contributors were
-
-	  Benson I. Margulies
-	  Dave Gentzel
-	  Antoine Verheijen
-	  Peter S. Housel
-	  Dale Smith
-	  Ozan Yigit
-	  John Campbell
-	  Bill Sommerfeld
-	  Paul Hilfinger
-	  Gary Bridgewater
-	  Dave Bakken
-	  Dan Lanciani
-	  Richard Sargent
-	  Parag Patel
Index: trunk/minix/commands/byacc/MANIFEST
===================================================================
--- trunk/minix/commands/byacc/MANIFEST	(revision 9)
+++ 	(revision )
@@ -1,33 +1,0 @@
-   File Name		Archive #	Description
------------------------------------------------------------
- ACKNOWLEDGEMENTS           1	
- CSU.diffs                  1	
- MANIFEST                   1	This shipping list
- Makefile                   1	
- NEW_FEATURES               1	
- NOTES                      1	
- NO_WARRANTY                1	
- README                     1	
- closure.c                  1	
- defs.h                     1	
- error.c                    1	
- lalr.c                     1	
- lr0.c                      1	
- main.c                     1	
- mkpar.c                    1	
- output.c                   2	
- reader.c                   3	
- skeleton.c                 1	
- symtab.c                   1	
- test                       1	
- test/error.output          1	
- test/error.tab.c           1	
- test/error.tab.h           1	
- test/error.y               1	
- test/ftp.output            2	
- test/ftp.tab.c             3	
- test/ftp.tab.h             1	
- test/ftp.y                 2	
- verbose.c                  1	
- warshall.c                 1	
- yacc.1                     1	
Index: trunk/minix/commands/byacc/Makefile
===================================================================
--- trunk/minix/commands/byacc/Makefile	(revision 9)
+++ 	(revision )
@@ -1,86 +1,0 @@
-# Makefile for Berkeley yacc.
-
-BINDIR	      = /usr/bin
-
-HDRS	      = defs.h
-
-CFLAGS	      = -DNDEBUG -D_MINIX -D_POSIX_SOURCE -wo $(OPT)
-
-LDFLAGS	      = -i
-
-LIBS	      =
-
-CC = exec cc
-
-LINKER	      = $(CC)
-
-MAKEFILE      = Makefile
-
-OBJS	      = closure.o \
-		error.o \
-		lalr.o \
-		lr0.o \
-		main.o \
-		mkpar.o \
-		output.o \
-		reader.o \
-		skeleton.o \
-		symtab.o \
-		verbose.o \
-		warshall.o
-
-PRINT	      = pr -f -l88
-
-PROGRAM	      = yacc
-
-SRCS	      = closure.c \
-		error.c \
-		lalr.c \
-		lr0.c \
-		main.c \
-		mkpar.c \
-		output.c \
-		reader.c \
-		skeleton.c \
-		symtab.c \
-		verbose.c \
-		warshall.c
-
-all:		$(PROGRAM)
-
-$(PROGRAM):     $(OBJS) $(LIBS)
-		$(LINKER) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
-		install -S 484k $(PROGRAM)
-
-install:	$(BINDIR)/yacc
-
-$(BINDIR)/yacc:	$(PROGRAM)
-		install -cs -o bin $(PROGRAM) $@
-
-clean:;		rm -f $(OBJS) $(PROGRAM) core
-
-#depend:;	@mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST)
-#
-#index:;	@ctags -wx $(HDRS) $(SRCS)
-#
-#listing:;	@$(PRINT) Makefile $(HDRS) $(SRCS) | lpr
-#
-#lint:;		@lint $(SRCS)
-#
-#program:        $(PROGRAM)
-#
-#tags:           $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS)
-
-###
-closure.o: defs.h
-error.o: defs.h
-lalr.o: defs.h
-lr0.o: defs.h
-main.o: defs.h
-mkpar.o: defs.h
-output.o: defs.h
-reader.o: defs.h
-skeleton.o: defs.h
-symtab.o: defs.h
-verbose.o: defs.h
-warshall.o: defs.h
Index: trunk/minix/commands/byacc/NEW_FEATURES
===================================================================
--- trunk/minix/commands/byacc/NEW_FEATURES	(revision 9)
+++ 	(revision )
@@ -1,46 +1,0 @@
-     The -r option has been implemented.  The -r option tells Yacc to
-put the read-only tables in y.tab.c and the code and variables in
-y.code.c.  Keith Bostic asked for this option so that :yyfix could be
-eliminated.
-
-     The -l and -t options have been implemented.  The -l option tells
-Yacc not to include #line directives in the code it produces.  The -t
-option causes debugging code to be included in the compiled parser.
-
-     The code for error recovery has been changed to implement the same
-algorithm as AT&T Yacc.  There will still be differences in the way
-error recovery works because AT&T Yacc uses more default reductions
-than Berkeley Yacc.
-
-     The environment variable TMPDIR determines the directory where
-temporary files will be created.  If TMPDIR is defined, temporary files
-will be created in the directory whose pathname is the value of TMPDIR.
-By default, temporary files are created in /tmp.
-
-     The keywords are now case-insensitive.  For example, %nonassoc,
-%NONASSOC, %NonAssoc, and %nOnAsSoC are all equivalent.
-
-     Commas and semicolons that are not part of C code are treated as
-commentary.
-
-     Line-end comments, as in BCPL, are permitted.  Line-end comments
-begin with // and end at the next end-of-line.  Line-end comments are
-permitted in C code; they are converted to C comments on output.
-
-     The form of y.output files has been changed to look more like
-those produced by AT&T Yacc.
-
-     A new kind of declaration has been added.  The form of the declaration
-is
-
-	  %ident string
-
-where string is a sequence of characters begining with a double quote
-and ending with either a double quote or the next end-of-line, whichever
-comes first.  The declaration will cause a #ident directive to be written
-near the start of the output file.
-
-     If a parser has been compiled with debugging code, that code can be
-enabled by setting an environment variable.  If the environment variable
-YYDEBUG is set to 0, debugging output is suppressed.  If it is set to 1,
-debugging output is written to standard output.
Index: trunk/minix/commands/byacc/NOTES
===================================================================
--- trunk/minix/commands/byacc/NOTES	(revision 9)
+++ 	(revision )
@@ -1,9 +1,0 @@
-Berkeley Yacc reflects its origins.  The reason so many routines
-use exactly six register variables is that Berkeley Yacc was
-developed on a VAX using PCC.  PCC placed at most six variables
-in registers.  I went to considerable effort to find which six
-variables most belonged in registers.  Changes in machines and
-compilers make that effort worthless, perhaps even harmful.
-
-The code contains many instances where address calculations are
-performed in particular ways to optimize the code for the VAX.
Index: trunk/minix/commands/byacc/NO_WARRANTY
===================================================================
--- trunk/minix/commands/byacc/NO_WARRANTY	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-     Berkeley Yacc is distributed with no warranty whatever.  The author
-and any other contributors take no responsibility for the consequences of
-its use.
Index: trunk/minix/commands/byacc/README
===================================================================
--- trunk/minix/commands/byacc/README	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-    Berkeley Yacc is an LALR(1) parser generator.  Berkeley Yacc has been made
-as compatible as possible with AT&T Yacc.  Berkeley Yacc can accept any input
-specification that conforms to the AT&T Yacc documentation.  Specifications
-that take advantage of undocumented features of AT&T Yacc will probably be
-rejected.
-
-    Berkeley Yacc is distributed with no warranty whatever.  The code is certain
-to contain errors.  Neither the author nor any contributor takes responsibility
-for any consequences of its use.
-
-    Berkeley Yacc is in the public domain.  The data structures and algorithms
-used in Berkeley Yacc are all either taken from documents available to the
-general public or are inventions of the author.  Anyone may freely distribute
-source or binary forms of Berkeley Yacc whether unchanged or modified.
-Distributers may charge whatever fees they can obtain for Berkeley Yacc.
-Programs generated by Berkeley Yacc may be distributed freely.
-
-    Please report bugs to
-
-			robert.corbett@eng.Sun.COM
-
-Include a small example if possible.  Please include the banner string from
-skeleton.c with the bug report.  Do not expect rapid responses.
Index: trunk/minix/commands/byacc/build
===================================================================
--- trunk/minix/commands/byacc/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/byacc/closure.c
===================================================================
--- trunk/minix/commands/byacc/closure.c	(revision 9)
+++ 	(revision )
@@ -1,255 +1,0 @@
-#include "defs.h"
-
-short *itemset;
-short *itemsetend;
-unsigned *ruleset;
-
-static unsigned *first_derives;
-static unsigned *EFF;
-
-
-set_EFF()
-{
-    register unsigned *row;
-    register int symbol;
-    register short *sp;
-    register int rowsize;
-    register int i;
-    register int rule;
-
-    rowsize = WORDSIZE(nvars);
-    EFF = NEW2(nvars * rowsize, unsigned);
-
-    row = EFF;
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	sp = derives[i];
-	for (rule = *sp; rule > 0; rule = *++sp)
-	{
-	    symbol = ritem[rrhs[rule]];
-	    if (ISVAR(symbol))
-	    {
-		symbol -= start_symbol;
-		SETBIT(row, symbol);
-	    }
-	}
-	row += rowsize;
-    }
-
-    reflexive_transitive_closure(EFF, nvars);
-
-#ifdef	DEBUG
-    print_EFF();
-#endif
-}
-
-
-set_first_derives()
-{
-    register unsigned *rrow;
-    register unsigned *vrow;
-    register int j;
-    register unsigned k;
-    register unsigned cword;
-    register short *rp;
-
-    int rule;
-    int i;
-    int rulesetsize;
-    int varsetsize;
-
-    rulesetsize = WORDSIZE(nrules);
-    varsetsize = WORDSIZE(nvars);
-    first_derives = NEW2(nvars * rulesetsize, unsigned) - ntokens * rulesetsize;
-
-    set_EFF();
-
-    rrow = first_derives + ntokens * rulesetsize;
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	vrow = EFF + ((i - ntokens) * varsetsize);
-	k = BITS_PER_WORD;
-	for (j = start_symbol; j < nsyms; k++, j++)
-	{
-	    if (k >= BITS_PER_WORD)
-	    {
-		cword = *vrow++;
-		k = 0;
-	    }
-
-	    if (cword & (1 << k))
-	    {
-		rp = derives[j];
-		while ((rule = *rp++) >= 0)
-		{
-		    SETBIT(rrow, rule);
-		}
-	    }
-	}
-
-	vrow += varsetsize;
-	rrow += rulesetsize;
-    }
-
-#ifdef	DEBUG
-    print_first_derives();
-#endif
-
-    FREE(EFF);
-}
-
-
-closure(nucleus, n)
-short *nucleus;
-int n;
-{
-    register int ruleno;
-    register unsigned word;
-    register unsigned i;
-    register short *csp;
-    register unsigned *dsp;
-    register unsigned *rsp;
-    register int rulesetsize;
-
-    short *csend;
-    unsigned *rsend;
-    int symbol;
-    int itemno;
-
-    rulesetsize = WORDSIZE(nrules);
-    rsp = ruleset;
-    rsend = ruleset + rulesetsize;
-    for (rsp = ruleset; rsp < rsend; rsp++)
-	*rsp = 0;
-
-    csend = nucleus + n;
-    for (csp = nucleus; csp < csend; ++csp)
-    {
-	symbol = ritem[*csp];
-	if (ISVAR(symbol))
-	{
-	    dsp = first_derives + symbol * rulesetsize;
-	    rsp = ruleset;
-	    while (rsp < rsend)
-		*rsp++ |= *dsp++;
-	}
-    }
-
-    ruleno = 0;
-    itemsetend = itemset;
-    csp = nucleus;
-    for (rsp = ruleset; rsp < rsend; ++rsp)
-    {
-	word = *rsp;
-	if (word)
-	{
-	    for (i = 0; i < BITS_PER_WORD; ++i)
-	    {
-		if (word & (1 << i))
-		{
-		    itemno = rrhs[ruleno+i];
-		    while (csp < csend && *csp < itemno)
-			*itemsetend++ = *csp++;
-		    *itemsetend++ = itemno;
-		    while (csp < csend && *csp == itemno)
-			++csp;
-		}
-	    }
-	}
-	ruleno += BITS_PER_WORD;
-    }
-
-    while (csp < csend)
-	*itemsetend++ = *csp++;
-
-#ifdef	DEBUG
-  print_closure(n);
-#endif
-}
-
-
-
-finalize_closure()
-{
-  FREE(itemset);
-  FREE(ruleset);
-  FREE(first_derives + ntokens * WORDSIZE(nrules));
-}
-
-
-#ifdef	DEBUG
-
-print_closure(n)
-int n;
-{
-  register short *isp;
-
-  printf("\n\nn = %d\n\n", n);
-  for (isp = itemset; isp < itemsetend; isp++)
-    printf("   %d\n", *isp);
-}
-
-
-print_EFF()
-{
-    register int i, j;
-    register unsigned *rowp;
-    register unsigned word;
-    register unsigned k;
-
-    printf("\n\nEpsilon Free Firsts\n");
-
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	printf("\n%s", symbol_name[i]);
-	rowp = EFF + ((i - start_symbol) * WORDSIZE(nvars));
-	word = *rowp++;
-
-	k = BITS_PER_WORD;
-	for (j = 0; j < nvars; k++, j++)
-	{
-	    if (k >= BITS_PER_WORD)
-	    {
-		word = *rowp++;
-		k = 0;
-	    }
-
-	    if (word & (1 << k))
-		printf("  %s", symbol_name[start_symbol + j]);
-	}
-    }
-}
-
-
-print_first_derives()
-{
-    register int i;
-    register int j;
-    register unsigned *rp;
-    register unsigned cword;
-    register unsigned k;
-
-    printf("\n\n\nFirst Derives\n");
-
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	printf("\n%s derives\n", symbol_name[i]);
-	rp = first_derives + i * WORDSIZE(nrules);
-	k = BITS_PER_WORD;
-	for (j = 0; j <= nrules; k++, j++)
-        {
-	  if (k >= BITS_PER_WORD)
-	  {
-	      cword = *rp++;
-	      k = 0;
-	  }
-
-	  if (cword & (1 << k))
-	    printf("   %d\n", j);
-	}
-    }
-
-  fflush(stdout);
-}
-
-#endif
Index: trunk/minix/commands/byacc/defs.h
===================================================================
--- trunk/minix/commands/byacc/defs.h	(revision 9)
+++ 	(revision )
@@ -1,298 +1,0 @@
-#include <assert.h>
-#include <ctype.h>
-#include <stdio.h>
-
-
-/*  machine-dependent definitions			*/
-/*  the following definitions are for the Tahoe		*/
-/*  they might have to be changed for other machines	*/
-
-/*  MAXCHAR is the largest unsigned character value	*/
-/*  MAXSHORT is the largest value of a C short		*/
-/*  MINSHORT is the most negative value of a C short	*/
-/*  MAXTABLE is the maximum table size			*/
-/*  BITS_PER_WORD is the number of bits in a C unsigned	*/
-/*  WORDSIZE computes the number of words needed to	*/
-/*	store n bits					*/
-/*  BIT returns the value of the n-th bit starting	*/
-/*	from r (0-indexed)				*/
-/*  SETBIT sets the n-th bit starting from r		*/
-
-#if !__STDC__
-#define	MAXCHAR		255
-#define	MAXSHORT	32767
-#define MINSHORT	-32768
-#define BITS_PER_WORD	32
-#else
-#include <limits.h>
-#define	MAXCHAR		UCHAR_MAX
-#define	MAXSHORT	SHRT_MAX
-#define MINSHORT	SHRT_MIN
-#define BITS_PER_WORD	(INT_MAX == 32767 ? 16 : 32)
-#define BITS_PER_BPW	(INT_MAX == 32767 ? 4 : 5)
-#endif
-#define MAXTABLE	32500
-#define	WORDSIZE(n)	(((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
-#define	BIT(r, n)	((((r)[(n)>>BITS_PER_BPW])>>((n)&(BITS_PER_WORD-1)))&1)
-#define	SETBIT(r, n)	((r)[(n)>>BITS_PER_BPW]|=((unsigned)1<<((n)&(BITS_PER_WORD-1))))
-
-
-/*  character names  */
-
-#define	NUL		'\0'    /*  the null character  */
-#define	NEWLINE		'\n'    /*  line feed  */
-#define	SP		' '     /*  space  */
-#define	BS		'\b'    /*  backspace  */
-#define	HT		'\t'    /*  horizontal tab  */
-#define	VT		'\013'  /*  vertical tab  */
-#define	CR		'\r'    /*  carriage return  */
-#define	FF		'\f'    /*  form feed  */
-#define	QUOTE		'\''    /*  single quote  */
-#define	DOUBLE_QUOTE	'\"'    /*  double quote  */
-#define	BACKSLASH	'\\'    /*  backslash  */
-
-
-/* defines for constructing filenames */
-
-#define CODE_SUFFIX	".code.c"
-#define	DEFINES_SUFFIX	".tab.h"
-#define	OUTPUT_SUFFIX	".tab.c"
-#define	VERBOSE_SUFFIX	".output"
-
-
-/* keyword codes */
-
-#define TOKEN 0
-#define LEFT 1
-#define RIGHT 2
-#define NONASSOC 3
-#define MARK 4
-#define TEXT 5
-#define TYPE 6
-#define START 7
-#define UNION 8
-#define IDENT 9
-
-
-/*  symbol classes  */
-
-#define UNKNOWN 0
-#define TERM 1
-#define NONTERM 2
-
-
-/*  the undefined value  */
-
-#define UNDEFINED (-1)
-
-
-/*  action codes  */
-
-#define SHIFT 1
-#define REDUCE 2
-
-
-/*  character macros  */
-
-#define IS_IDENT(c)	(isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
-#define	IS_OCTAL(c)	((c) >= '0' && (c) <= '7')
-#define	NUMERIC_VALUE(c)	((c) - '0')
-
-
-/*  symbol macros  */
-
-#define ISTOKEN(s)	((s) < start_symbol)
-#define ISVAR(s)	((s) >= start_symbol)
-
-
-/*  storage allocation macros  */
-
-#define CALLOC(k,n)	(calloc((unsigned)(k),(unsigned)(n)))
-#define	FREE(x)		(free((char*)(x)))
-#define MALLOC(n)	(malloc((unsigned)(n)))
-#define	NEW(t)		((t*)allocate(sizeof(t)))
-#define	NEW2(n,t)	((t*)allocate((unsigned)((n)*sizeof(t))))
-#define REALLOC(p,n)	(realloc((char*)(p),(unsigned)(n)))
-
-
-/*  the structure of a symbol table entry  */
-
-typedef struct bucket bucket;
-struct bucket
-{
-    struct bucket *link;
-    struct bucket *next;
-    char *name;
-    char *tag;
-    short value;
-    short index;
-    short prec;
-    char class;
-    char assoc;
-};
-
-
-/*  the structure of the LR(0) state machine  */
-
-typedef struct core core;
-struct core
-{
-    struct core *next;
-    struct core *link;
-    short number;
-    short accessing_symbol;
-    short nitems;
-    short items[1];
-};
-
-
-/*  the structure used to record shifts  */
-
-typedef struct shifts shifts;
-struct shifts
-{
-    struct shifts *next;
-    short number;
-    short nshifts;
-    short shift[1];
-};
-
-
-/*  the structure used to store reductions  */
-
-typedef struct reductions reductions;
-struct reductions
-{
-    struct reductions *next;
-    short number;
-    short nreds;
-    short rules[1];
-};
-
-
-/*  the structure used to represent parser actions  */
-
-typedef struct action action;
-struct action
-{
-    struct action *next;
-    short symbol;
-    short number;
-    short prec;
-    char action_code;
-    char assoc;
-    char suppressed;
-};
-
-
-/* global variables */
-
-extern char dflag;
-extern char lflag;
-extern char rflag;
-extern char tflag;
-extern char vflag;
-extern char *symbol_prefix;
-
-extern char *myname;
-extern char *cptr;
-extern char *line;
-extern int lineno;
-extern int outline;
-
-extern char *banner[];
-extern char *tables[];
-extern char *header[];
-extern char *body[];
-extern char *trailer[];
-
-extern char *action_file_name;
-extern char *code_file_name;
-extern char *defines_file_name;
-extern char *input_file_name;
-extern char *output_file_name;
-extern char *text_file_name;
-extern char *union_file_name;
-extern char *verbose_file_name;
-
-extern FILE *action_file;
-extern FILE *code_file;
-extern FILE *defines_file;
-extern FILE *input_file;
-extern FILE *output_file;
-extern FILE *text_file;
-extern FILE *union_file;
-extern FILE *verbose_file;
-
-extern int nitems;
-extern int nrules;
-extern int nsyms;
-extern int ntokens;
-extern int nvars;
-extern int ntags;
-
-extern char unionized;
-extern char line_format[];
-
-extern int   start_symbol;
-extern char  **symbol_name;
-extern short *symbol_value;
-extern short *symbol_prec;
-extern char  *symbol_assoc;
-
-extern short *ritem;
-extern short *rlhs;
-extern short *rrhs;
-extern short *rprec;
-extern char  *rassoc;
-
-extern short **derives;
-extern char *nullable;
-
-extern bucket *first_symbol;
-extern bucket *last_symbol;
-
-extern int nstates;
-extern core *first_state;
-extern shifts *first_shift;
-extern reductions *first_reduction;
-extern short *accessing_symbol;
-extern core **state_table;
-extern shifts **shift_table;
-extern reductions **reduction_table;
-extern unsigned *LA;
-extern short *LAruleno;
-extern short *lookaheads;
-extern short *goto_map;
-extern short *from_state;
-extern short *to_state;
-
-extern action **parser;
-extern int SRtotal;
-extern int RRtotal;
-extern short *SRconflicts;
-extern short *RRconflicts;
-extern short *defred;
-extern short *rules_used;
-extern short nunused;
-extern short final_state;
-
-/* global functions */
-
-extern char *allocate();
-extern bucket *lookup();
-extern bucket *make_bucket();
-
-
-/* system variables */
-
-extern int errno;
-
-
-/* system functions */
-
-extern void free();
-extern char *calloc();
-extern char *malloc();
-extern char *realloc();
-extern char *strcpy();
Index: trunk/minix/commands/byacc/error.c
===================================================================
--- trunk/minix/commands/byacc/error.c	(revision 9)
+++ 	(revision )
@@ -1,317 +1,0 @@
-/* routines for printing error messages  */
-
-#include "defs.h"
-
-
-fatal(msg)
-char *msg;
-{
-    fprintf(stderr, "%s: f - %s\n", myname, msg);
-    done(2);
-}
-
-
-no_space()
-{
-    fprintf(stderr, "%s: f - out of space\n", myname);
-    done(2);
-}
-
-
-open_error(filename)
-char *filename;
-{
-    fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
-    done(2);
-}
-
-
-unexpected_EOF()
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
-	    myname, lineno, input_file_name);
-    done(1);
-}
-
-
-print_pos(st_line, st_cptr)
-char *st_line;
-char *st_cptr;
-{
-    register char *s;
-
-    if (st_line == 0) return;
-    for (s = st_line; *s != '\n'; ++s)
-    {
-	if (isprint(*s) || *s == '\t')
-	    putc(*s, stderr);
-	else
-	    putc('?', stderr);
-    }
-    putc('\n', stderr);
-    for (s = st_line; s < st_cptr; ++s)
-    {
-	if (*s == '\t')
-	    putc('\t', stderr);
-	else
-	    putc(' ', stderr);
-    }
-    putc('^', stderr);
-    putc('\n', stderr);
-}
-
-
-syntax_error(st_lineno, st_line, st_cptr)
-int st_lineno;
-char *st_line;
-char *st_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
-	    myname, st_lineno, input_file_name);
-    print_pos(st_line, st_cptr);
-    done(1);
-}
-
-
-unterminated_comment(c_lineno, c_line, c_cptr)
-int c_lineno;
-char *c_line;
-char *c_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
-	    myname, c_lineno, input_file_name);
-    print_pos(c_line, c_cptr);
-    done(1);
-}
-
-
-unterminated_string(s_lineno, s_line, s_cptr)
-int s_lineno;
-char *s_line;
-char *s_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
-	    myname, s_lineno, input_file_name);
-    print_pos(s_line, s_cptr);
-    done(1);
-}
-
-
-unterminated_text(t_lineno, t_line, t_cptr)
-int t_lineno;
-char *t_line;
-char *t_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
-	    myname, t_lineno, input_file_name);
-    print_pos(t_line, t_cptr);
-    done(1);
-}
-
-
-unterminated_union(u_lineno, u_line, u_cptr)
-int u_lineno;
-char *u_line;
-char *u_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
-declaration\n", myname, u_lineno, input_file_name);
-    print_pos(u_line, u_cptr);
-    done(1);
-}
-
-
-over_unionized(u_cptr)
-char *u_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
-declarations\n", myname, lineno, input_file_name);
-    print_pos(line, u_cptr);
-    done(1);
-}
-
-
-illegal_tag(t_lineno, t_line, t_cptr)
-int t_lineno;
-char *t_line;
-char *t_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
-	    myname, t_lineno, input_file_name);
-    print_pos(t_line, t_cptr);
-    done(1);
-}
-
-
-illegal_character(c_cptr)
-char *c_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
-	    myname, lineno, input_file_name);
-    print_pos(line, c_cptr);
-    done(1);
-}
-
-
-used_reserved(s)
-char *s;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", illegal use of reserved symbol \
-%s\n", myname, lineno, input_file_name, s);
-    done(1);
-}
-
-
-tokenized_start(s)
-char *s;
-{
-     fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s cannot be \
-declared to be a token\n", myname, lineno, input_file_name, s);
-     done(1);
-}
-
-
-retyped_warning(s)
-char *s;
-{
-    fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
-redeclared\n", myname, lineno, input_file_name, s);
-}
-
-
-reprec_warning(s)
-char *s;
-{
-    fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \
-redeclared\n", myname, lineno, input_file_name, s);
-}
-
-
-revalued_warning(s)
-char *s;
-{
-    fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
-redeclared\n", myname, lineno, input_file_name, s);
-}
-
-
-terminal_start(s)
-char *s;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
-token\n", myname, lineno, input_file_name, s);
-    done(1);
-}
-
-
-restarted_warning()
-{
-    fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
-redeclared\n", myname, lineno, input_file_name);
-}
-
-
-no_grammar()
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
-specified\n", myname, lineno, input_file_name);
-    done(1);
-}
-
-
-terminal_lhs(s_lineno)
-int s_lineno;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
-of a production\n", myname, s_lineno, input_file_name);
-    done(1);
-}
-
-
-prec_redeclared()
-{
-    fprintf(stderr, "%s: w - line %d of  \"%s\", conflicting %%prec \
-specifiers\n", myname, lineno, input_file_name);
-}
-
-
-unterminated_action(a_lineno, a_line, a_cptr)
-int a_lineno;
-char *a_line;
-char *a_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
-	    myname, a_lineno, input_file_name);
-    print_pos(a_line, a_cptr);
-    done(1);
-}
-
-
-dollar_warning(a_lineno, i)
-int a_lineno;
-int i;
-{
-    fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
-end of the current rule\n", myname, a_lineno, input_file_name, i);
-}
-
-
-dollar_error(a_lineno, a_line, a_cptr)
-int a_lineno;
-char *a_line;
-char *a_cptr;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
-	    myname, a_lineno, input_file_name);
-    print_pos(a_line, a_cptr);
-    done(1);
-}
-
-
-untyped_lhs()
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
-	    myname, lineno, input_file_name);
-    done(1);
-}
-
-
-untyped_rhs(i, s)
-int i;
-char *s;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
-	    myname, lineno, input_file_name, i, s);
-    done(1);
-}
-
-
-unknown_rhs(i)
-int i;
-{
-    fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
-	    myname, lineno, input_file_name, i);
-    done(1);
-}
-
-
-default_action_warning()
-{
-    fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
-undefined value to $$\n", myname, lineno, input_file_name);
-}
-
-
-undefined_goal(s)
-char *s;
-{
-    fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
-    done(1);
-}
-
-
-undefined_symbol_warning(s)
-char *s;
-{
-    fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
-}
Index: trunk/minix/commands/byacc/lalr.c
===================================================================
--- trunk/minix/commands/byacc/lalr.c	(revision 9)
+++ 	(revision )
@@ -1,638 +1,0 @@
-#include "defs.h"
-
-typedef
-  struct shorts
-    {
-      struct shorts *next;
-      short value;
-    }
-  shorts;
-
-int tokensetsize;
-short *lookaheads;
-short *LAruleno;
-unsigned *LA;
-short *accessing_symbol;
-core **state_table;
-shifts **shift_table;
-reductions **reduction_table;
-short *goto_map;
-short *from_state;
-short *to_state;
-
-short **transpose();
-
-static int infinity;
-static int maxrhs;
-static int ngotos;
-static unsigned *F;
-static short **includes;
-static shorts **lookback;
-static short **R;
-static short *INDEX;
-static short *VERTICES;
-static int top;
-
-
-lalr()
-{
-    tokensetsize = WORDSIZE(ntokens);
-
-    set_state_table();
-    set_accessing_symbol();
-    set_shift_table();
-    set_reduction_table();
-    set_maxrhs();
-    initialize_LA();
-    set_goto_map();
-    initialize_F();
-    build_relations();
-    compute_FOLLOWS();
-    compute_lookaheads();
-}
-
-
-
-set_state_table()
-{
-    register core *sp;
-
-    state_table = NEW2(nstates, core *);
-    for (sp = first_state; sp; sp = sp->next)
-	state_table[sp->number] = sp;
-}
-
-
-
-set_accessing_symbol()
-{
-    register core *sp;
-
-    accessing_symbol = NEW2(nstates, short);
-    for (sp = first_state; sp; sp = sp->next)
-	accessing_symbol[sp->number] = sp->accessing_symbol;
-}
-
-
-
-set_shift_table()
-{
-    register shifts *sp;
-
-    shift_table = NEW2(nstates, shifts *);
-    for (sp = first_shift; sp; sp = sp->next)
-	shift_table[sp->number] = sp;
-}
-
-
-
-set_reduction_table()
-{
-    register reductions *rp;
-
-    reduction_table = NEW2(nstates, reductions *);
-    for (rp = first_reduction; rp; rp = rp->next)
-	reduction_table[rp->number] = rp;
-}
-
-
-
-set_maxrhs()
-{
-  register short *itemp;
-  register short *item_end;
-  register int length;
-  register int max;
-
-  length = 0;
-  max = 0;
-  item_end = ritem + nitems;
-  for (itemp = ritem; itemp < item_end; itemp++)
-    {
-      if (*itemp >= 0)
-	{
-	  length++;
-	}
-      else
-	{
-	  if (length > max) max = length;
-	  length = 0;
-	}
-    }
-
-  maxrhs = max;
-}
-
-
-
-initialize_LA()
-{
-  register int i, j, k;
-  register reductions *rp;
-
-  lookaheads = NEW2(nstates + 1, short);
-
-  k = 0;
-  for (i = 0; i < nstates; i++)
-    {
-      lookaheads[i] = k;
-      rp = reduction_table[i];
-      if (rp)
-	k += rp->nreds;
-    }
-  lookaheads[nstates] = k;
-
-  LA = NEW2(k * tokensetsize, unsigned);
-  LAruleno = NEW2(k, short);
-  lookback = NEW2(k, shorts *);
-
-  k = 0;
-  for (i = 0; i < nstates; i++)
-    {
-      rp = reduction_table[i];
-      if (rp)
-	{
-	  for (j = 0; j < rp->nreds; j++)
-	    {
-	      LAruleno[k] = rp->rules[j];
-	      k++;
-	    }
-	}
-    }
-}
-
-
-set_goto_map()
-{
-  register shifts *sp;
-  register int i;
-  register int symbol;
-  register int k;
-  register short *temp_map;
-  register int state2;
-  register int state1;
-
-  goto_map = NEW2(nvars + 1, short) - ntokens;
-  temp_map = NEW2(nvars + 1, short) - ntokens;
-
-  ngotos = 0;
-  for (sp = first_shift; sp; sp = sp->next)
-    {
-      for (i = sp->nshifts - 1; i >= 0; i--)
-	{
-	  symbol = accessing_symbol[sp->shift[i]];
-
-	  if (ISTOKEN(symbol)) break;
-
-	  if (ngotos == MAXSHORT)
-	    fatal("too many gotos");
-
-	  ngotos++;
-	  goto_map[symbol]++;
-        }
-    }
-
-  k = 0;
-  for (i = ntokens; i < nsyms; i++)
-    {
-      temp_map[i] = k;
-      k += goto_map[i];
-    }
-
-  for (i = ntokens; i < nsyms; i++)
-    goto_map[i] = temp_map[i];
-
-  goto_map[nsyms] = ngotos;
-  temp_map[nsyms] = ngotos;
-
-  from_state = NEW2(ngotos, short);
-  to_state = NEW2(ngotos, short);
-
-  for (sp = first_shift; sp; sp = sp->next)
-    {
-      state1 = sp->number;
-      for (i = sp->nshifts - 1; i >= 0; i--)
-	{
-	  state2 = sp->shift[i];
-	  symbol = accessing_symbol[state2];
-
-	  if (ISTOKEN(symbol)) break;
-
-	  k = temp_map[symbol]++;
-	  from_state[k] = state1;
-	  to_state[k] = state2;
-	}
-    }
-
-  FREE(temp_map + ntokens);
-}
-
-
-
-/*  Map_goto maps a state/symbol pair into its numeric representation.	*/
-
-int
-map_goto(state, symbol)
-int state;
-int symbol;
-{
-    register int high;
-    register int low;
-    register int middle;
-    register int s;
-
-    low = goto_map[symbol];
-    high = goto_map[symbol + 1];
-
-    for (;;)
-    {
-	assert(low <= high);
-	middle = (low + high) >> 1;
-	s = from_state[middle];
-	if (s == state)
-	    return (middle);
-	else if (s < state)
-	    low = middle + 1;
-	else
-	    high = middle - 1;
-    }
-}
-
-
-
-initialize_F()
-{
-  register int i;
-  register int j;
-  register int k;
-  register shifts *sp;
-  register short *edge;
-  register unsigned *rowp;
-  register short *rp;
-  register short **reads;
-  register int nedges;
-  register int stateno;
-  register int symbol;
-  register int nwords;
-
-  nwords = ngotos * tokensetsize;
-  F = NEW2(nwords, unsigned);
-
-  reads = NEW2(ngotos, short *);
-  edge = NEW2(ngotos + 1, short);
-  nedges = 0;
-
-  rowp = F;
-  for (i = 0; i < ngotos; i++)
-    {
-      stateno = to_state[i];
-      sp = shift_table[stateno];
-
-      if (sp)
-	{
-	  k = sp->nshifts;
-
-	  for (j = 0; j < k; j++)
-	    {
-	      symbol = accessing_symbol[sp->shift[j]];
-	      if (ISVAR(symbol))
-		break;
-	      SETBIT(rowp, symbol);
-	    }
-
-	  for (; j < k; j++)
-	    {
-	      symbol = accessing_symbol[sp->shift[j]];
-	      if (nullable[symbol])
-		edge[nedges++] = map_goto(stateno, symbol);
-	    }
-	
-	  if (nedges)
-	    {
-	      reads[i] = rp = NEW2(nedges + 1, short);
-
-	      for (j = 0; j < nedges; j++)
-		rp[j] = edge[j];
-
-	      rp[nedges] = -1;
-	      nedges = 0;
-	    }
-	}
-
-      rowp += tokensetsize;
-    }
-
-  SETBIT(F, 0);
-  digraph(reads);
-
-  for (i = 0; i < ngotos; i++)
-    {
-      if (reads[i])
-	FREE(reads[i]);
-    }
-
-  FREE(reads);
-  FREE(edge);
-}
-
-
-
-build_relations()
-{
-  register int i;
-  register int j;
-  register int k;
-  register short *rulep;
-  register short *rp;
-  register shifts *sp;
-  register int length;
-  register int nedges;
-  register int done;
-  register int state1;
-  register int stateno;
-  register int symbol1;
-  register int symbol2;
-  register short *shortp;
-  register short *edge;
-  register short *states;
-  register short **new_includes;
-
-  includes = NEW2(ngotos, short *);
-  edge = NEW2(ngotos + 1, short);
-  states = NEW2(maxrhs + 1, short);
-
-  for (i = 0; i < ngotos; i++)
-    {
-      nedges = 0;
-      state1 = from_state[i];
-      symbol1 = accessing_symbol[to_state[i]];
-
-      for (rulep = derives[symbol1]; *rulep >= 0; rulep++)
-	{
-	  length = 1;
-	  states[0] = state1;
-	  stateno = state1;
-
-	  for (rp = ritem + rrhs[*rulep]; *rp >= 0; rp++)
-	    {
-	      symbol2 = *rp;
-	      sp = shift_table[stateno];
-	      k = sp->nshifts;
-
-	      for (j = 0; j < k; j++)
-		{
-		  stateno = sp->shift[j];
-		  if (accessing_symbol[stateno] == symbol2) break;
-		}
-
-	      states[length++] = stateno;
-	    }
-
-	  add_lookback_edge(stateno, *rulep, i);
-
-	  length--;
-	  done = 0;
-	  while (!done)
-	    {
-	      done = 1;
-	      rp--;
-	      if (ISVAR(*rp))
-		{
-		  stateno = states[--length];
-		  edge[nedges++] = map_goto(stateno, *rp);
-		  if (nullable[*rp] && length > 0) done = 0;
-		}
-	    }
-	}
-
-      if (nedges)
-	{
-	  includes[i] = shortp = NEW2(nedges + 1, short);
-	  for (j = 0; j < nedges; j++)
-	    shortp[j] = edge[j];
-	  shortp[nedges] = -1;
-	}
-    }
-
-  new_includes = transpose(includes, ngotos);
-
-  for (i = 0; i < ngotos; i++)
-    if (includes[i])
-      FREE(includes[i]);
-
-  FREE(includes);
-
-  includes = new_includes;
-
-  FREE(edge);
-  FREE(states);
-}
-
-
-add_lookback_edge(stateno, ruleno, gotono)
-int stateno, ruleno, gotono;
-{
-    register int i, k;
-    register int found;
-    register shorts *sp;
-
-    i = lookaheads[stateno];
-    k = lookaheads[stateno + 1];
-    found = 0;
-    while (!found && i < k)
-    {
-	if (LAruleno[i] == ruleno)
-	    found = 1;
-	else
-	    ++i;
-    }
-    assert(found);
-
-    sp = NEW(shorts);
-    sp->next = lookback[i];
-    sp->value = gotono;
-    lookback[i] = sp;
-}
-
-
-
-short **
-transpose(R, n)
-short **R;
-int n;
-{
-  register short **new_R;
-  register short **temp_R;
-  register short *nedges;
-  register short *sp;
-  register int i;
-  register int k;
-
-  nedges = NEW2(n, short);
-
-  for (i = 0; i < n; i++)
-    {
-      sp = R[i];
-      if (sp)
-	{
-	  while (*sp >= 0)
-	    nedges[*sp++]++;
-	}
-    }
-
-  new_R = NEW2(n, short *);
-  temp_R = NEW2(n, short *);
-
-  for (i = 0; i < n; i++)
-    {
-      k = nedges[i];
-      if (k > 0)
-	{
-	  sp = NEW2(k + 1, short);
-	  new_R[i] = sp;
-	  temp_R[i] = sp;
-	  sp[k] = -1;
-	}
-    }
-
-  FREE(nedges);
-
-  for (i = 0; i < n; i++)
-    {
-      sp = R[i];
-      if (sp)
-	{
-	  while (*sp >= 0)
-	    *temp_R[*sp++]++ = i;
-	}
-    }
-
-  FREE(temp_R);
-
-  return (new_R);
-}
-
-
-
-compute_FOLLOWS()
-{
-  digraph(includes);
-}
-
-
-compute_lookaheads()
-{
-  register int i, n;
-  register unsigned *fp1, *fp2, *fp3;
-  register shorts *sp, *next;
-  register unsigned *rowp;
-
-  rowp = LA;
-  n = lookaheads[nstates];
-  for (i = 0; i < n; i++)
-    {
-      fp3 = rowp + tokensetsize;
-      for (sp = lookback[i]; sp; sp = sp->next)
-	{
-	  fp1 = rowp;
-	  fp2 = F + tokensetsize * sp->value;
-	  while (fp1 < fp3)
-	    *fp1++ |= *fp2++;
-	}
-      rowp = fp3;
-    }
-
-  for (i = 0; i < n; i++)
-    for (sp = lookback[i]; sp; sp = next)
-      {
-        next = sp->next;
-        FREE(sp);
-      }
-
-  FREE(lookback);
-  FREE(F);
-}
-
-
-digraph(relation)
-short **relation;
-{
-  register int i;
-
-  infinity = ngotos + 2;
-  INDEX = NEW2(ngotos + 1, short);
-  VERTICES = NEW2(ngotos + 1, short);
-  top = 0;
-
-  R = relation;
-
-  for (i = 0; i < ngotos; i++)
-    INDEX[i] = 0;
-
-  for (i = 0; i < ngotos; i++)
-    {
-      if (INDEX[i] == 0 && R[i])
-	traverse(i);
-    }
-
-  FREE(INDEX);
-  FREE(VERTICES);
-}
-
-
-
-traverse(i)
-register int i;
-{
-  register unsigned *fp1;
-  register unsigned *fp2;
-  register unsigned *fp3;
-  register int j;
-  register short *rp;
-
-  int height;
-  unsigned *base;
-
-  VERTICES[++top] = i;
-  INDEX[i] = height = top;
-
-  base = F + i * tokensetsize;
-  fp3 = base + tokensetsize;
-
-  rp = R[i];
-  if (rp)
-    {
-      while ((j = *rp++) >= 0)
-	{
-	  if (INDEX[j] == 0)
-	    traverse(j);
-
-	  if (INDEX[i] > INDEX[j])
-	    INDEX[i] = INDEX[j];
-
-	  fp1 = base;
-	  fp2 = F + j * tokensetsize;
-
-	  while (fp1 < fp3)
-	    *fp1++ |= *fp2++;
-	}
-    }
-
-  if (INDEX[i] == height)
-    {
-      for (;;)
-	{
-	  j = VERTICES[top--];
-	  INDEX[j] = infinity;
-
-	  if (i == j)
-	    break;
-
-	  fp1 = base;
-	  fp2 = F + j * tokensetsize;
-
-	  while (fp1 < fp3)
-	    *fp2++ = *fp1++;
-	}
-    }
-}
Index: trunk/minix/commands/byacc/lr0.c
===================================================================
--- trunk/minix/commands/byacc/lr0.c	(revision 9)
+++ 	(revision )
@@ -1,598 +1,0 @@
-
-#include "defs.h"
-
-extern short *itemset;
-extern short *itemsetend;
-extern unsigned *ruleset;
-
-int nstates;
-core *first_state;
-shifts *first_shift;
-reductions *first_reduction;
-
-int get_state();
-core *new_state();
-
-static core **state_set;
-static core *this_state;
-static core *last_state;
-static shifts *last_shift;
-static reductions *last_reduction;
-
-static int nshifts;
-static short *shift_symbol;
-
-static short *redset;
-static short *shiftset;
-
-static short **kernel_base;
-static short **kernel_end;
-static short *kernel_items;
-
-
-allocate_itemsets()
-{
-    register short *itemp;
-    register short *item_end;
-    register int symbol;
-    register int i;
-    register int count;
-    register int max;
-    register short *symbol_count;
-
-    count = 0;
-    symbol_count = NEW2(nsyms, short);
-
-    item_end = ritem + nitems;
-    for (itemp = ritem; itemp < item_end; itemp++)
-    {
-	symbol = *itemp;
-	if (symbol >= 0)
-	{
-	    count++;
-	    symbol_count[symbol]++;
-	}
-    }
-
-    kernel_base = NEW2(nsyms, short *);
-    kernel_items = NEW2(count, short);
-
-    count = 0;
-    max = 0;
-    for (i = 0; i < nsyms; i++)
-    {
-	kernel_base[i] = kernel_items + count;
-	count += symbol_count[i];
-	if (max < symbol_count[i])
-	    max = symbol_count[i];
-    }
-
-    shift_symbol = symbol_count;
-    kernel_end = NEW2(nsyms, short *);
-}
-
-
-allocate_storage()
-{
-    allocate_itemsets();
-    shiftset = NEW2(nsyms, short);
-    redset = NEW2(nrules + 1, short);
-    state_set = NEW2(nitems, core *);
-}
-
-
-append_states()
-{
-    register int i;
-    register int j;
-    register int symbol;
-
-#ifdef	TRACE
-    fprintf(stderr, "Entering append_states()\n");
-#endif
-    for (i = 1; i < nshifts; i++)
-    {
-	symbol = shift_symbol[i];
-	j = i;
-	while (j > 0 && shift_symbol[j - 1] > symbol)
-	{
-	    shift_symbol[j] = shift_symbol[j - 1];
-	    j--;
-	}
-	shift_symbol[j] = symbol;
-    }
-
-    for (i = 0; i < nshifts; i++)
-    {
-	symbol = shift_symbol[i];
-	shiftset[i] = get_state(symbol);
-    }
-}
-
-
-free_storage()
-{
-    FREE(shift_symbol);
-    FREE(redset);
-    FREE(shiftset);
-    FREE(kernel_base);
-    FREE(kernel_end);
-    FREE(kernel_items);
-    FREE(state_set);
-}
-
-
-
-generate_states()
-{
-    allocate_storage();
-    itemset = NEW2(nitems, short);
-    ruleset = NEW2(WORDSIZE(nrules), unsigned);
-    set_first_derives();
-    initialize_states();
-
-    while (this_state)
-    {
-	closure(this_state->items, this_state->nitems);
-	save_reductions();
-	new_itemsets();
-	append_states();
-
-	if (nshifts > 0)
-	    save_shifts();
-
-	this_state = this_state->next;
-    }
-
-    finalize_closure();
-    free_storage();
-}
-
-
-
-int
-get_state(symbol)
-int symbol;
-{
-    register int key;
-    register short *isp1;
-    register short *isp2;
-    register short *iend;
-    register core *sp;
-    register int found;
-    register int n;
-
-#ifdef	TRACE
-    fprintf(stderr, "Entering get_state(%d)\n", symbol);
-#endif
-
-    isp1 = kernel_base[symbol];
-    iend = kernel_end[symbol];
-    n = iend - isp1;
-
-    key = *isp1;
-    assert(0 <= key && key < nitems);
-    sp = state_set[key];
-    if (sp)
-    {
-	found = 0;
-	while (!found)
-	{
-	    if (sp->nitems == n)
-	    {
-		found = 1;
-		isp1 = kernel_base[symbol];
-		isp2 = sp->items;
-
-		while (found && isp1 < iend)
-		{
-		    if (*isp1++ != *isp2++)
-			found = 0;
-		}
-	    }
-
-	    if (!found)
-	    {
-		if (sp->link)
-		{
-		    sp = sp->link;
-		}
-		else
-		{
-		    sp = sp->link = new_state(symbol);
-		    found = 1;
-		}
-	    }
-	}
-    }
-    else
-    {
-	state_set[key] = sp = new_state(symbol);
-    }
-
-    return (sp->number);
-}
-
-
-
-initialize_states()
-{
-    register int i;
-    register short *start_derives;
-    register core *p;
-
-    start_derives = derives[start_symbol];
-    for (i = 0; start_derives[i] >= 0; ++i)
-	continue;
-
-    p = (core *) MALLOC(sizeof(core) + i*sizeof(short));
-    if (p == 0) no_space();
-
-    p->next = 0;
-    p->link = 0;
-    p->number = 0;
-    p->accessing_symbol = 0;
-    p->nitems = i;
-
-    for (i = 0;  start_derives[i] >= 0; ++i)
-	p->items[i] = rrhs[start_derives[i]];
-
-    first_state = last_state = this_state = p;
-    nstates = 1;
-}
-
-
-new_itemsets()
-{
-    register int i;
-    register int shiftcount;
-    register short *isp;
-    register short *ksp;
-    register int symbol;
-
-    for (i = 0; i < nsyms; i++)
-	kernel_end[i] = 0;
-
-    shiftcount = 0;
-    isp = itemset;
-    while (isp < itemsetend)
-    {
-	i = *isp++;
-	symbol = ritem[i];
-	if (symbol > 0)
-	{
-	    ksp = kernel_end[symbol];
-	    if (!ksp)
-	    {
-		shift_symbol[shiftcount++] = symbol;
-		ksp = kernel_base[symbol];
-	    }
-
-	    *ksp++ = i + 1;
-	    kernel_end[symbol] = ksp;
-	}
-    }
-
-    nshifts = shiftcount;
-}
-
-
-
-core *
-new_state(symbol)
-int symbol;
-{
-    register int n;
-    register core *p;
-    register short *isp1;
-    register short *isp2;
-    register short *iend;
-
-#ifdef	TRACE
-    fprintf(stderr, "Entering new_state(%d)\n", symbol);
-#endif
-
-    if (nstates >= MAXSHORT)
-	fatal("too many states");
-
-    isp1 = kernel_base[symbol];
-    iend = kernel_end[symbol];
-    n = iend - isp1;
-
-    p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short)));
-    p->accessing_symbol = symbol;
-    p->number = nstates;
-    p->nitems = n;
-
-    isp2 = p->items;
-    while (isp1 < iend)
-	*isp2++ = *isp1++;
-
-    last_state->next = p;
-    last_state = p;
-
-    nstates++;
-
-    return (p);
-}
-
-
-/* show_cores is used for debugging */
-
-show_cores()
-{
-    core *p;
-    int i, j, k, n;
-    int itemno;
-
-    k = 0;
-    for (p = first_state; p; ++k, p = p->next)
-    {
-	if (k) printf("\n");
-	printf("state %d, number = %d, accessing symbol = %s\n",
-		k, p->number, symbol_name[p->accessing_symbol]);
-	n = p->nitems;
-	for (i = 0; i < n; ++i)
-	{
-	    itemno = p->items[i];
-	    printf("%4d  ", itemno);
-	    j = itemno;
-	    while (ritem[j] >= 0) ++j;
-	    printf("%s :", symbol_name[rlhs[-ritem[j]]]);
-	    j = rrhs[-ritem[j]];
-	    while (j < itemno)
-		printf(" %s", symbol_name[ritem[j++]]);
-	    printf(" .");
-	    while (ritem[j] >= 0)
-		printf(" %s", symbol_name[ritem[j++]]);
-	    printf("\n");
-	    fflush(stdout);
-	}
-    }
-}
-
-
-/* show_ritems is used for debugging */
-
-show_ritems()
-{
-    int i;
-
-    for (i = 0; i < nitems; ++i)
-	printf("ritem[%d] = %d\n", i, ritem[i]);
-}
-
-
-/* show_rrhs is used for debugging */
-show_rrhs()
-{
-    int i;
-
-    for (i = 0; i < nrules; ++i)
-	printf("rrhs[%d] = %d\n", i, rrhs[i]);
-}
-
-
-/* show_shifts is used for debugging */
-
-show_shifts()
-{
-    shifts *p;
-    int i, j, k;
-
-    k = 0;
-    for (p = first_shift; p; ++k, p = p->next)
-    {
-	if (k) printf("\n");
-	printf("shift %d, number = %d, nshifts = %d\n", k, p->number,
-		p->nshifts);
-	j = p->nshifts;
-	for (i = 0; i < j; ++i)
-	    printf("\t%d\n", p->shift[i]);
-    }
-}
-
-
-save_shifts()
-{
-    register shifts *p;
-    register short *sp1;
-    register short *sp2;
-    register short *send;
-
-    p = (shifts *) allocate((unsigned) (sizeof(shifts) +
-			(nshifts - 1) * sizeof(short)));
-
-    p->number = this_state->number;
-    p->nshifts = nshifts;
-
-    sp1 = shiftset;
-    sp2 = p->shift;
-    send = shiftset + nshifts;
-
-    while (sp1 < send)
-	*sp2++ = *sp1++;
-
-    if (last_shift)
-    {
-	last_shift->next = p;
-	last_shift = p;
-    }
-    else
-    {
-	first_shift = p;
-	last_shift = p;
-    }
-}
-
-
-
-save_reductions()
-{
-    register short *isp;
-    register short *rp1;
-    register short *rp2;
-    register int item;
-    register int count;
-    register reductions *p;
-    register short *rend;
-
-    count = 0;
-    for (isp = itemset; isp < itemsetend; isp++)
-    {
-	item = ritem[*isp];
-	if (item < 0)
-	{
-	    redset[count++] = -item;
-	}
-    }
-
-    if (count)
-    {
-	p = (reductions *) allocate((unsigned) (sizeof(reductions) +
-					(count - 1) * sizeof(short)));
-
-	p->number = this_state->number;
-	p->nreds = count;
-
-	rp1 = redset;
-	rp2 = p->rules;
-	rend = rp1 + count;
-
-	while (rp1 < rend)
-	    *rp2++ = *rp1++;
-
-	if (last_reduction)
-	{
-	    last_reduction->next = p;
-	    last_reduction = p;
-	}
-	else
-	{
-	    first_reduction = p;
-	    last_reduction = p;
-	}
-    }
-}
-
-
-set_derives()
-{
-    register int i, k;
-    register int lhs;
-    register short *rules;
-
-    derives = NEW2(nsyms, short *);
-    rules = NEW2(nvars + nrules, short);
-
-    k = 0;
-    for (lhs = start_symbol; lhs < nsyms; lhs++)
-    {
-	derives[lhs] = rules + k;
-	for (i = 0; i < nrules; i++)
-	{
-	    if (rlhs[i] == lhs)
-	    {
-		rules[k] = i;
-		k++;
-	    }
-	}
-	rules[k] = -1;
-	k++;
-    }
-
-#ifdef	DEBUG
-    print_derives();
-#endif
-}
-
-free_derives()
-{
-    FREE(derives[start_symbol]);
-    FREE(derives);
-}
-
-#ifdef	DEBUG
-print_derives()
-{
-    register int i;
-    register short *sp;
-
-    printf("\nDERIVES\n\n");
-
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	printf("%s derives ", symbol_name[i]);
-	for (sp = derives[i]; *sp >= 0; sp++)
-	{
-	    printf("  %d", *sp);
-	}
-	putchar('\n');
-    }
-
-    putchar('\n');
-}
-#endif
-
-
-set_nullable()
-{
-    register int i, j;
-    register int empty;
-    int done;
-
-    nullable = MALLOC(nsyms);
-    if (nullable == 0) no_space();
-
-    for (i = 0; i < nsyms; ++i)
-	nullable[i] = 0;
-
-    done = 0;
-    while (!done)
-    {
-	done = 1;
-	for (i = 1; i < nitems; i++)
-	{
-	    empty = 1;
-	    while ((j = ritem[i]) >= 0)
-	    {
-		if (!nullable[j])
-		    empty = 0;
-		++i;
-	    }
-	    if (empty)
-	    {
-		j = rlhs[-j];
-		if (!nullable[j])
-		{
-		    nullable[j] = 1;
-		    done = 0;
-		}
-	    }
-	}
-    }
-
-#ifdef DEBUG
-    for (i = 0; i < nsyms; i++)
-    {
-	if (nullable[i])
-	    printf("%s is nullable\n", symbol_name[i]);
-	else
-	    printf("%s is not nullable\n", symbol_name[i]);
-    }
-#endif
-}
-
-
-free_nullable()
-{
-    FREE(nullable);
-}
-
-
-lr0()
-{
-    set_derives();
-    set_nullable();
-    generate_states();
-}
Index: trunk/minix/commands/byacc/main.c
===================================================================
--- trunk/minix/commands/byacc/main.c	(revision 9)
+++ 	(revision )
@@ -1,378 +1,0 @@
-#include <sys/types.h>
-#include <signal.h>
-#include "defs.h"
-
-char dflag;
-char lflag;
-char rflag;
-char tflag;
-char vflag;
-
-char *symbol_prefix;
-char *file_prefix = "y";
-char *myname = "yacc";
-char *temp_form = "yacc.XXXXXXX";
-
-int lineno;
-int outline;
-
-char *action_file_name;
-char *code_file_name;
-char *defines_file_name;
-char *input_file_name = "";
-char *output_file_name;
-char *text_file_name;
-char *union_file_name;
-char *verbose_file_name;
-
-FILE *action_file;	/*  a temp file, used to save actions associated    */
-			/*  with rules until the parser is written	    */
-FILE *code_file;	/*  y.code.c (used when the -r option is specified) */
-FILE *defines_file;	/*  y.tab.h					    */
-FILE *input_file;	/*  the input file				    */
-FILE *output_file;	/*  y.tab.c					    */
-FILE *text_file;	/*  a temp file, used to save text until all	    */
-			/*  symbols have been defined			    */
-FILE *union_file;	/*  a temp file, used to save the union		    */
-			/*  definition until all symbol have been	    */
-			/*  defined					    */
-FILE *verbose_file;	/*  y.output					    */
-
-int nitems;
-int nrules;
-int nsyms;
-int ntokens;
-int nvars;
-
-int   start_symbol;
-char  **symbol_name;
-short *symbol_value;
-short *symbol_prec;
-char  *symbol_assoc;
-
-short *ritem;
-short *rlhs;
-short *rrhs;
-short *rprec;
-char  *rassoc;
-short **derives;
-char *nullable;
-
-extern char *mktemp();
-extern char *getenv();
-
-
-done(k)
-int k;
-{
-    if (action_file) { fclose(action_file); unlink(action_file_name); }
-    if (text_file) { fclose(text_file); unlink(text_file_name); }
-    if (union_file) { fclose(union_file); unlink(union_file_name); }
-    exit(k);
-}
-
-
-void
-onintr(signo)
-    int signo;
-{
-    done(1);
-}
-
-
-set_signals()
-{
-#ifdef SIGINT
-    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
-	signal(SIGINT, onintr);
-#endif
-#ifdef SIGTERM
-    if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
-	signal(SIGTERM, onintr);
-#endif
-#ifdef SIGHUP
-    if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
-	signal(SIGHUP, onintr);
-#endif
-}
-
-
-usage()
-{
-    fprintf(stderr, "usage: %s [-dlrtv] [-b file_prefix] [-p symbol_prefix] filename\n", myname);
-    exit(1);
-}
-
-
-getargs(argc, argv)
-int argc;
-char *argv[];
-{
-    register int i;
-    register char *s;
-
-    if (argc > 0) myname = argv[0];
-    for (i = 1; i < argc; ++i)
-    {
-	s = argv[i];
-	if (*s != '-') break;
-	switch (*++s)
-	{
-	case '\0':
-	    input_file = stdin;
-	    if (i + 1 < argc) usage();
-	    return;
-
-	case '-':
-	    ++i;
-	    goto no_more_options;
-
-	case 'b':
-	    if (*++s)
-		 file_prefix = s;
-	    else if (++i < argc)
-		file_prefix = argv[i];
-	    else
-		usage();
-	    continue;
-
-	case 'd':
-	    dflag = 1;
-	    break;
-
-	case 'l':
-	    lflag = 1;
-	    break;
-
-	case 'p':
-	    if (*++s)
-		symbol_prefix = s;
-	    else if (++i < argc)
-		symbol_prefix = argv[i];
-	    else
-		usage();
-	    continue;
-
-	case 'r':
-	    rflag = 1;
-	    break;
-
-	case 't':
-	    tflag = 1;
-	    break;
-
-	case 'v':
-	    vflag = 1;
-	    break;
-
-	default:
-	    usage();
-	}
-
-	for (;;)
-	{
-	    switch (*++s)
-	    {
-	    case '\0':
-		goto end_of_option;
-
-	    case 'd':
-		dflag = 1;
-		break;
-
-	    case 'l':
-		lflag = 1;
-		break;
-
-	    case 'r':
-		rflag = 1;
-		break;
-
-	    case 't':
-		tflag = 1;
-		break;
-
-	    case 'v':
-		vflag = 1;
-		break;
-
-	    default:
-		usage();
-	    }
-	}
-end_of_option:;
-    }
-
-no_more_options:;
-    if (i + 1 != argc) usage();
-    input_file_name = argv[i];
-}
-
-
-char *
-allocate(n)
-unsigned n;
-{
-    register char *p;
-
-    p = NULL;
-    if (n)
-    {
-	p = CALLOC(1, n);
-	if (!p) no_space();
-    }
-    return (p);
-}
-
-
-create_file_names()
-{
-    int i, len;
-    char *tmpdir;
-
-    tmpdir = getenv("TMPDIR");
-    if (tmpdir == 0) tmpdir = "/tmp";
-
-    len = strlen(tmpdir);
-    i = len + 13;
-    if (len && tmpdir[len-1] != '/')
-	++i;
-
-    action_file_name = MALLOC(i);
-    if (action_file_name == 0) no_space();
-    text_file_name = MALLOC(i);
-    if (text_file_name == 0) no_space();
-    union_file_name = MALLOC(i);
-    if (union_file_name == 0) no_space();
-
-    strcpy(action_file_name, tmpdir);
-    strcpy(text_file_name, tmpdir);
-    strcpy(union_file_name, tmpdir);
-
-    if (len && tmpdir[len - 1] != '/')
-    {
-	action_file_name[len] = '/';
-	text_file_name[len] = '/';
-	union_file_name[len] = '/';
-	++len;
-    }
-
-    strcpy(action_file_name + len, temp_form);
-    strcpy(text_file_name + len, temp_form);
-    strcpy(union_file_name + len, temp_form);
-
-    action_file_name[len + 5] = 'a';
-    text_file_name[len + 5] = 't';
-    union_file_name[len + 5] = 'u';
-
-    mktemp(action_file_name);
-    mktemp(text_file_name);
-    mktemp(union_file_name);
-
-    len = strlen(file_prefix);
-
-    output_file_name = MALLOC(len + 7);
-    if (output_file_name == 0)
-	no_space();
-    strcpy(output_file_name, file_prefix);
-    strcpy(output_file_name + len, OUTPUT_SUFFIX);
-
-    if (rflag)
-    {
-	code_file_name = MALLOC(len + 8);
-	if (code_file_name == 0)
-	    no_space();
-	strcpy(code_file_name, file_prefix);
-	strcpy(code_file_name + len, CODE_SUFFIX);
-    }
-    else
-	code_file_name = output_file_name;
-
-    if (dflag)
-    {
-	defines_file_name = MALLOC(len + 7);
-	if (defines_file_name == 0)
-	    no_space();
-	strcpy(defines_file_name, file_prefix);
-	strcpy(defines_file_name + len, DEFINES_SUFFIX);
-    }
-
-    if (vflag)
-    {
-	verbose_file_name = MALLOC(len + 8);
-	if (verbose_file_name == 0)
-	    no_space();
-	strcpy(verbose_file_name, file_prefix);
-	strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
-    }
-}
-
-
-open_files()
-{
-    create_file_names();
-
-    if (input_file == 0)
-    {
-	input_file = fopen(input_file_name, "r");
-	if (input_file == 0)
-	    open_error(input_file_name);
-    }
-
-    action_file = fopen(action_file_name, "w");
-    if (action_file == 0)
-	open_error(action_file_name);
-
-    text_file = fopen(text_file_name, "w");
-    if (text_file == 0)
-	open_error(text_file_name);
-
-    if (vflag)
-    {
-	verbose_file = fopen(verbose_file_name, "w");
-	if (verbose_file == 0)
-	    open_error(verbose_file_name);
-    }
-
-    if (dflag)
-    {
-	defines_file = fopen(defines_file_name, "w");
-	if (defines_file == 0)
-	    open_error(defines_file_name);
-	union_file = fopen(union_file_name, "w");
-	if (union_file ==  0)
-	    open_error(union_file_name);
-    }
-
-    output_file = fopen(output_file_name, "w");
-    if (output_file == 0)
-	open_error(output_file_name);
-
-    if (rflag)
-    {
-	code_file = fopen(code_file_name, "w");
-	if (code_file == 0)
-	    open_error(code_file_name);
-    }
-    else
-	code_file = output_file;
-}
-
-
-int
-main(argc, argv)
-int argc;
-char *argv[];
-{
-    set_signals();
-    getargs(argc, argv);
-    open_files();
-    reader();
-    lr0();
-    lalr();
-    make_parser();
-    verbose();
-    output();
-    done(0);
-    /*NOTREACHED*/
-}
Index: trunk/minix/commands/byacc/mkpar.c
===================================================================
--- trunk/minix/commands/byacc/mkpar.c	(revision 9)
+++ 	(revision )
@@ -1,357 +1,0 @@
-
-#include "defs.h"
-
-action **parser;
-int SRtotal;
-int RRtotal;
-short *SRconflicts;
-short *RRconflicts;
-short *defred;
-short *rules_used;
-short nunused;
-short final_state;
-
-static int SRcount;
-static int RRcount;
-
-extern action *parse_actions();
-extern action *get_shifts();
-extern action *add_reductions();
-extern action *add_reduce();
-
-
-make_parser()
-{
-    register int i;
-
-    parser = NEW2(nstates, action *);
-    for (i = 0; i < nstates; i++)
-	parser[i] = parse_actions(i);
-
-    find_final_state();
-    remove_conflicts();
-    unused_rules();
-    if (SRtotal + RRtotal > 0) total_conflicts();
-    defreds();
-}
-
-
-action *
-parse_actions(stateno)
-register int stateno;
-{
-    register action *actions;
-
-    actions = get_shifts(stateno);
-    actions = add_reductions(stateno, actions);
-    return (actions);
-}
-
-
-action *
-get_shifts(stateno)
-int stateno;
-{
-    register action *actions, *temp;
-    register shifts *sp;
-    register short *to_state;
-    register int i, k;
-    register int symbol;
-
-    actions = 0;
-    sp = shift_table[stateno];
-    if (sp)
-    {
-	to_state = sp->shift;
-	for (i = sp->nshifts - 1; i >= 0; i--)
-	{
-	    k = to_state[i];
-	    symbol = accessing_symbol[k];
-	    if (ISTOKEN(symbol))
-	    {
-		temp = NEW(action);
-		temp->next = actions;
-		temp->symbol = symbol;
-		temp->number = k;
-		temp->prec = symbol_prec[symbol];
-		temp->action_code = SHIFT;
-		temp->assoc = symbol_assoc[symbol];
-		actions = temp;
-	    }
-	}
-    }
-    return (actions);
-}
-
-action *
-add_reductions(stateno, actions)
-int stateno;
-register action *actions;
-{
-    register int i, j, m, n;
-    register int ruleno, tokensetsize;
-    register unsigned *rowp;
-
-    tokensetsize = WORDSIZE(ntokens);
-    m = lookaheads[stateno];
-    n = lookaheads[stateno + 1];
-    for (i = m; i < n; i++)
-    {
-	ruleno = LAruleno[i];
-	rowp = LA + i * tokensetsize;
-	for (j = ntokens - 1; j >= 0; j--)
-	{
-	    if (BIT(rowp, j))
-		actions = add_reduce(actions, ruleno, j);
-	}
-    }
-    return (actions);
-}
-
-
-action *
-add_reduce(actions, ruleno, symbol)
-register action *actions;
-register int ruleno, symbol;
-{
-    register action *temp, *prev, *next;
-
-    prev = 0;
-    for (next = actions; next && next->symbol < symbol; next = next->next)
-	prev = next;
-
-    while (next && next->symbol == symbol && next->action_code == SHIFT)
-    {
-	prev = next;
-	next = next->next;
-    }
-
-    while (next && next->symbol == symbol &&
-	    next->action_code == REDUCE && next->number < ruleno)
-    {
-	prev = next;
-	next = next->next;
-    }
-
-    temp = NEW(action);
-    temp->next = next;
-    temp->symbol = symbol;
-    temp->number = ruleno;
-    temp->prec = rprec[ruleno];
-    temp->action_code = REDUCE;
-    temp->assoc = rassoc[ruleno];
-
-    if (prev)
-	prev->next = temp;
-    else
-	actions = temp;
-
-    return (actions);
-}
-
-
-find_final_state()
-{
-    register int goal, i;
-    register short *to_state;
-    register shifts *p;
-
-    p = shift_table[0];
-    to_state = p->shift;
-    goal = ritem[1];
-    for (i = p->nshifts - 1; i >= 0; --i)
-    {
-	final_state = to_state[i];
-	if (accessing_symbol[final_state] == goal) break;
-    }
-}
-
-
-unused_rules()
-{
-    register int i;
-    register action *p;
-
-    rules_used = (short *) MALLOC(nrules*sizeof(short));
-    if (rules_used == 0) no_space();
-
-    for (i = 0; i < nrules; ++i)
-	rules_used[i] = 0;
-
-    for (i = 0; i < nstates; ++i)
-    {
-	for (p = parser[i]; p; p = p->next)
-	{
-	    if (p->action_code == REDUCE && p->suppressed == 0)
-		rules_used[p->number] = 1;
-	}
-    }
-
-    nunused = 0;
-    for (i = 3; i < nrules; ++i)
-	if (!rules_used[i]) ++nunused;
-
-    if (nunused)
-	if (nunused == 1)
-	    fprintf(stderr, "%s: 1 rule never reduced\n", myname);
-	else
-	    fprintf(stderr, "%s: %d rules never reduced\n", myname, nunused);
-}
-
-
-remove_conflicts()
-{
-    register int i;
-    register int symbol;
-    register action *p, *pref;
-
-    SRtotal = 0;
-    RRtotal = 0;
-    SRconflicts = NEW2(nstates, short);
-    RRconflicts = NEW2(nstates, short);
-    for (i = 0; i < nstates; i++)
-    {
-	SRcount = 0;
-	RRcount = 0;
-	symbol = -1;
-	for (p = parser[i]; p; p = p->next)
-	{
-	    if (p->symbol != symbol)
-	    {
-		pref = p;
-		symbol = p->symbol;
-	    }
-	    else if (i == final_state && symbol == 0)
-	    {
-		SRcount++;
-		p->suppressed = 1;
-	    }
-	    else if (pref->action_code == SHIFT)
-	    {
-		if (pref->prec > 0 && p->prec > 0)
-		{
-		    if (pref->prec < p->prec)
-		    {
-			pref->suppressed = 2;
-			pref = p;
-		    }
-		    else if (pref->prec > p->prec)
-		    {
-			p->suppressed = 2;
-		    }
-		    else if (pref->assoc == LEFT)
-		    {
-			pref->suppressed = 2;
-			pref = p;
-		    }
-		    else if (pref->assoc == RIGHT)
-		    {
-			p->suppressed = 2;
-		    }
-		    else
-		    {
-			pref->suppressed = 2;
-			p->suppressed = 2;
-		    }
-		}
-		else
-		{
-		    SRcount++;
-		    p->suppressed = 1;
-		}
-	    }
-	    else
-	    {
-		RRcount++;
-		p->suppressed = 1;
-	    }
-	}
-	SRtotal += SRcount;
-	RRtotal += RRcount;
-	SRconflicts[i] = SRcount;
-	RRconflicts[i] = RRcount;
-    }
-}
-
-
-total_conflicts()
-{
-    fprintf(stderr, "%s: ", myname);
-    if (SRtotal == 1)
-	fprintf(stderr, "1 shift/reduce conflict");
-    else if (SRtotal > 1)
-	fprintf(stderr, "%d shift/reduce conflicts", SRtotal);
-
-    if (SRtotal && RRtotal)
-	fprintf(stderr, ", ");
-
-    if (RRtotal == 1)
-	fprintf(stderr, "1 reduce/reduce conflict");
-    else if (RRtotal > 1)
-	fprintf(stderr, "%d reduce/reduce conflicts", RRtotal);
-
-    fprintf(stderr, ".\n");
-}
-
-
-int
-sole_reduction(stateno)
-int stateno;
-{
-    register int count, ruleno;
-    register action *p;
-
-    count = 0;
-    ruleno = 0; 
-    for (p = parser[stateno]; p; p = p->next)
-    {
-	if (p->action_code == SHIFT && p->suppressed == 0)
-	    return (0);
-	else if (p->action_code == REDUCE && p->suppressed == 0)
-	{
-	    if (ruleno > 0 && p->number != ruleno)
-		return (0);
-	    if (p->symbol != 1)
-		++count;
-	    ruleno = p->number;
-	}
-    }
-
-    if (count == 0)
-	return (0);
-    return (ruleno);
-}
-
-
-defreds()
-{
-    register int i;
-
-    defred = NEW2(nstates, short);
-    for (i = 0; i < nstates; i++)
-	defred[i] = sole_reduction(i);
-}
- 
-free_action_row(p)
-register action *p;
-{
-  register action *q;
-
-  while (p)
-    {
-      q = p->next;
-      FREE(p);
-      p = q;
-    }
-}
-
-free_parser()
-{
-  register int i;
-
-  for (i = 0; i < nstates; i++)
-    free_action_row(parser[i]);
-
-  FREE(parser);
-}
-
Index: trunk/minix/commands/byacc/output.c
===================================================================
--- trunk/minix/commands/byacc/output.c	(revision 9)
+++ 	(revision )
@@ -1,1210 +1,0 @@
-#include "defs.h"
-
-static int nvectors;
-static int nentries;
-static short **froms;
-static short **tos;
-static short *tally;
-static short *width;
-static short *state_count;
-static short *order;
-static short *base;
-static short *pos;
-static int maxtable;
-static short *table;
-static short *check;
-static int lowzero;
-static int high;
-
-
-output()
-{
-    free_itemsets();
-    free_shifts();
-    free_reductions();
-    output_prefix();
-    output_stored_text();
-    output_defines();
-    output_rule_data();
-    output_yydefred();
-    output_actions();
-    free_parser();
-    output_debug();
-    output_stype();
-    if (rflag) write_section(tables);
-    write_section(header);
-    output_trailing_text();
-    write_section(body);
-    output_semantic_actions();
-    write_section(trailer);
-}
-
-
-output_prefix()
-{
-    if (symbol_prefix == NULL)
-	symbol_prefix = "yy";
-    else
-    {
-	++outline;
-	fprintf(code_file, "#define yyparse %sparse\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yylex %slex\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyerror %serror\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yychar %schar\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyval %sval\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yylval %slval\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yydebug %sdebug\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yynerrs %snerrs\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyerrflag %serrflag\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyss %sss\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyssp %sssp\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyvs %svs\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyvsp %svsp\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yylhs %slhs\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yylen %slen\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yydefred %sdefred\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yydgoto %sdgoto\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yysindex %ssindex\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyrindex %srindex\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yygindex %sgindex\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yytable %stable\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yycheck %scheck\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyname %sname\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyrule %srule\n", symbol_prefix);
-    }
-    ++outline;
-    fprintf(code_file, "#define YYPREFIX \"%s\"\n", symbol_prefix);
-}
-
-
-output_rule_data()
-{
-    register int i;
-    register int j;
-
-  
-    fprintf(output_file, "short %slhs[] = {%42d,", symbol_prefix,
-	    symbol_value[start_symbol]);
-
-    j = 10;
-    for (i = 3; i < nrules; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-        else
-	    ++j;
-
-        fprintf(output_file, "%5d,", symbol_value[rlhs[i]]);
-    }
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-
-    fprintf(output_file, "short %slen[] = {%42d,", symbol_prefix, 2);
-
-    j = 10;
-    for (i = 3; i < nrules; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	  j++;
-
-        fprintf(output_file, "%5d,", rrhs[i + 1] - rrhs[i] - 1);
-    }
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-}
-
-
-output_yydefred()
-{
-    register int i, j;
-
-    fprintf(output_file, "short %sdefred[] = {%39d,", symbol_prefix,
-	    (defred[0] ? defred[0] - 2 : 0));
-
-    j = 10;
-    for (i = 1; i < nstates; i++)
-    {
-	if (j < 10)
-	    ++j;
-	else
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-
-	fprintf(output_file, "%5d,", (defred[i] ? defred[i] - 2 : 0));
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-}
-
-
-output_actions()
-{
-    nvectors = 2*nstates + nvars;
-
-    froms = NEW2(nvectors, short *);
-    tos = NEW2(nvectors, short *);
-    tally = NEW2(nvectors, short);
-    width = NEW2(nvectors, short);
-
-    token_actions();
-    FREE(lookaheads);
-    FREE(LA);
-    FREE(LAruleno);
-    FREE(accessing_symbol);
-
-    goto_actions();
-    FREE(goto_map + ntokens);
-    FREE(from_state);
-    FREE(to_state);
-
-    sort_actions();
-    pack_table();
-    output_base();
-    output_table();
-    output_check();
-}
-
-
-token_actions()
-{
-    register int i, j;
-    register int shiftcount, reducecount;
-    register int max, min;
-    register short *actionrow, *r, *s;
-    register action *p;
-
-    actionrow = NEW2(2*ntokens, short);
-    for (i = 0; i < nstates; ++i)
-    {
-	if (parser[i])
-	{
-	    for (j = 0; j < 2*ntokens; ++j)
-	    actionrow[j] = 0;
-
-	    shiftcount = 0;
-	    reducecount = 0;
-	    for (p = parser[i]; p; p = p->next)
-	    {
-		if (p->suppressed == 0)
-		{
-		    if (p->action_code == SHIFT)
-		    {
-			++shiftcount;
-			actionrow[p->symbol] = p->number;
-		    }
-		    else if (p->action_code == REDUCE && p->number != defred[i])
-		    {
-			++reducecount;
-			actionrow[p->symbol + ntokens] = p->number;
-		    }
-		}
-	    }
-
-	    tally[i] = shiftcount;
-	    tally[nstates+i] = reducecount;
-	    width[i] = 0;
-	    width[nstates+i] = 0;
-	    if (shiftcount > 0)
-	    {
-		froms[i] = r = NEW2(shiftcount, short);
-		tos[i] = s = NEW2(shiftcount, short);
-		min = MAXSHORT;
-		max = 0;
-		for (j = 0; j < ntokens; ++j)
-		{
-		    if (actionrow[j])
-		    {
-			if (min > symbol_value[j])
-			    min = symbol_value[j];
-			if (max < symbol_value[j])
-			    max = symbol_value[j];
-			*r++ = symbol_value[j];
-			*s++ = actionrow[j];
-		    }
-		}
-		width[i] = max - min + 1;
-	    }
-	    if (reducecount > 0)
-	    {
-		froms[nstates+i] = r = NEW2(reducecount, short);
-		tos[nstates+i] = s = NEW2(reducecount, short);
-		min = MAXSHORT;
-		max = 0;
-		for (j = 0; j < ntokens; ++j)
-		{
-		    if (actionrow[ntokens+j])
-		    {
-			if (min > symbol_value[j])
-			    min = symbol_value[j];
-			if (max < symbol_value[j])
-			    max = symbol_value[j];
-			*r++ = symbol_value[j];
-			*s++ = actionrow[ntokens+j] - 2;
-		    }
-		}
-		width[nstates+i] = max - min + 1;
-	    }
-	}
-    }
-    FREE(actionrow);
-}
-
-goto_actions()
-{
-    register int i, j, k;
-
-    state_count = NEW2(nstates, short);
-
-    k = default_goto(start_symbol + 1);
-    fprintf(output_file, "short %sdgoto[] = {%40d,", symbol_prefix, k);
-    save_column(start_symbol + 1, k);
-
-    j = 10;
-    for (i = start_symbol + 2; i < nsyms; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	k = default_goto(i);
-	fprintf(output_file, "%5d,", k);
-	save_column(i, k);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    FREE(state_count);
-}
-
-int
-default_goto(symbol)
-int symbol;
-{
-    register int i;
-    register int m;
-    register int n;
-    register int default_state;
-    register int max;
-
-    m = goto_map[symbol];
-    n = goto_map[symbol + 1];
-
-    if (m == n) return (0);
-
-    for (i = 0; i < nstates; i++)
-	state_count[i] = 0;
-
-    for (i = m; i < n; i++)
-	state_count[to_state[i]]++;
-
-    max = 0;
-    default_state = 0;
-    for (i = 0; i < nstates; i++)
-    {
-	if (state_count[i] > max)
-	{
-	    max = state_count[i];
-	    default_state = i;
-	}
-    }
-
-    return (default_state);
-}
-
-
-
-save_column(symbol, default_state)
-int symbol;
-int default_state;
-{
-    register int i;
-    register int m;
-    register int n;
-    register short *sp;
-    register short *sp1;
-    register short *sp2;
-    register int count;
-    register int symno;
-
-    m = goto_map[symbol];
-    n = goto_map[symbol + 1];
-
-    count = 0;
-    for (i = m; i < n; i++)
-    {
-	if (to_state[i] != default_state)
-	    ++count;
-    }
-    if (count == 0) return;
-
-    symno = symbol_value[symbol] + 2*nstates;
-
-    froms[symno] = sp1 = sp = NEW2(count, short);
-    tos[symno] = sp2 = NEW2(count, short);
-
-    for (i = m; i < n; i++)
-    {
-	if (to_state[i] != default_state)
-	{
-	    *sp1++ = from_state[i];
-	    *sp2++ = to_state[i];
-	}
-    }
-
-    tally[symno] = count;
-    width[symno] = sp1[-1] - sp[0] + 1;
-}
-
-sort_actions()
-{
-  register int i;
-  register int j;
-  register int k;
-  register int t;
-  register int w;
-
-  order = NEW2(nvectors, short);
-  nentries = 0;
-
-  for (i = 0; i < nvectors; i++)
-    {
-      if (tally[i] > 0)
-	{
-	  t = tally[i];
-	  w = width[i];
-	  j = nentries - 1;
-
-	  while (j >= 0 && (width[order[j]] < w))
-	    j--;
-
-	  while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
-	    j--;
-
-	  for (k = nentries - 1; k > j; k--)
-	    order[k + 1] = order[k];
-
-	  order[j + 1] = i;
-	  nentries++;
-	}
-    }
-}
-
-
-pack_table()
-{
-    register int i;
-    register int place;
-    register int state;
-
-    base = NEW2(nvectors, short);
-    pos = NEW2(nentries, short);
-
-    maxtable = BITS_PER_WORD == 16 ? 400 : 1000;
-    table = NEW2(maxtable, short);
-    check = NEW2(maxtable, short);
-
-    lowzero = 0;
-    high = 0;
-
-    for (i = 0; i < maxtable; i++)
-	check[i] = -1;
-
-    for (i = 0; i < nentries; i++)
-    {
-	state = matching_vector(i);
-
-	if (state < 0)
-	    place = pack_vector(i);
-	else
-	    place = base[state];
-
-	pos[i] = place;
-	base[order[i]] = place;
-    }
-
-    for (i = 0; i < nvectors; i++)
-    {
-	if (froms[i])
-	    FREE(froms[i]);
-	if (tos[i])
-	    FREE(tos[i]);
-    }
-
-    FREE(froms);
-    FREE(tos);
-    FREE(pos);
-}
-
-
-/*  The function matching_vector determines if the vector specified by	*/
-/*  the input parameter matches a previously considered	vector.  The	*/
-/*  test at the start of the function checks if the vector represents	*/
-/*  a row of shifts over terminal symbols or a row of reductions, or a	*/
-/*  column of shifts over a nonterminal symbol.  Berkeley Yacc does not	*/
-/*  check if a column of shifts over a nonterminal symbols matches a	*/
-/*  previously considered vector.  Because of the nature of LR parsing	*/
-/*  tables, no two columns can match.  Therefore, the only possible	*/
-/*  match would be between a row and a column.  Such matches are	*/
-/*  unlikely.  Therefore, to save time, no attempt is made to see if a	*/
-/*  column matches a previously considered vector.			*/
-/*									*/
-/*  Matching_vector is poorly designed.  The test could easily be made	*/
-/*  faster.  Also, it depends on the vectors being in a specific	*/
-/*  order.								*/
-
-int
-matching_vector(vector)
-int vector;
-{
-    register int i;
-    register int j;
-    register int k;
-    register int t;
-    register int w;
-    register int match;
-    register int prev;
-
-    i = order[vector];
-    if (i >= 2*nstates)
-	return (-1);
-
-    t = tally[i];
-    w = width[i];
-
-    for (prev = vector - 1; prev >= 0; prev--)
-    {
-	j = order[prev];
-	if (width[j] != w || tally[j] != t)
-	    return (-1);
-
-	match = 1;
-	for (k = 0; match && k < t; k++)
-	{
-	    if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
-		match = 0;
-	}
-
-	if (match)
-	    return (j);
-    }
-
-    return (-1);
-}
-
-
-
-int
-pack_vector(vector)
-int vector;
-{
-    register int i, j, k, l;
-    register int t;
-    register int loc;
-    register int ok;
-    register short *from;
-    register short *to;
-    int newmax;
-
-    i = order[vector];
-    t = tally[i];
-    assert(t);
-
-    from = froms[i];
-    to = tos[i];
-
-    j = lowzero - from[0];
-    for (k = 1; k < t; ++k)
-	if (lowzero - from[k] > j)
-	    j = lowzero - from[k];
-    for (;; ++j)
-    {
-	if (j == 0)
-	    continue;
-	ok = 1;
-	for (k = 0; ok && k < t; k++)
-	{
-	    loc = j + from[k];
-	    if (loc >= maxtable)
-	    {
-		if (loc >= MAXTABLE)
-		    fatal("maximum table size exceeded");
-
-		newmax = maxtable;
-		do { newmax += 200; } while (newmax <= loc);
-		table = (short *) REALLOC(table, newmax*sizeof(short));
-		if (table == 0) no_space();
-		check = (short *) REALLOC(check, newmax*sizeof(short));
-		if (check == 0) no_space();
-		for (l  = maxtable; l < newmax; ++l)
-		{
-		    table[l] = 0;
-		    check[l] = -1;
-		}
-		maxtable = newmax;
-	    }
-
-	    if (check[loc] != -1)
-		ok = 0;
-	}
-	for (k = 0; ok && k < vector; k++)
-	{
-	    if (pos[k] == j)
-		ok = 0;
-	}
-	if (ok)
-	{
-	    for (k = 0; k < t; k++)
-	    {
-		loc = j + from[k];
-		table[loc] = to[k];
-		check[loc] = from[k];
-		if (loc > high) high = loc;
-	    }
-
-	    while (check[lowzero] != -1)
-		++lowzero;
-
-	    return (j);
-	}
-    }
-}
-
-
-
-output_base()
-{
-    register int i, j;
-
-    fprintf(output_file, "short %ssindex[] = {%39d,", symbol_prefix, base[0]);
-
-    j = 10;
-    for (i = 1; i < nstates; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", base[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\nshort %srindex[] = {%39d,", symbol_prefix,
-	    base[nstates]);
-
-    j = 10;
-    for (i = nstates + 1; i < 2*nstates; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", base[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\nshort %sgindex[] = {%39d,", symbol_prefix,
-	    base[2*nstates]);
-
-    j = 10;
-    for (i = 2*nstates + 1; i < nvectors - 1; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", base[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    FREE(base);
-}
-
-
-
-output_table()
-{
-    register int i;
-    register int j;
-
-    ++outline;
-    fprintf(code_file, "#define YYTABLESIZE %d\n", high);
-    fprintf(output_file, "short %stable[] = {%40d,", symbol_prefix,
-	    table[0]);
-
-    j = 10;
-    for (i = 1; i <= high; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", table[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    FREE(table);
-}
-
-
-
-output_check()
-{
-    register int i;
-    register int j;
-
-    fprintf(output_file, "short %scheck[] = {%40d,", symbol_prefix,
-	    check[0]);
-
-    j = 10;
-    for (i = 1; i <= high; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", check[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    FREE(check);
-}
-
-
-int
-is_C_identifier(name)
-char *name;
-{
-    register char *s;
-    register int c;
-
-    s = name;
-    c = *s;
-    if (c == '"')
-    {
-	c = *++s;
-	if (!isalpha(c) && c != '_' && c != '$')
-	    return (0);
-	while ((c = *++s) != '"')
-	{
-	    if (!isalnum(c) && c != '_' && c != '$')
-		return (0);
-	}
-	return (1);
-    }
-
-    if (!isalpha(c) && c != '_' && c != '$')
-	return (0);
-    while (c = *++s)
-    {
-	if (!isalnum(c) && c != '_' && c != '$')
-	    return (0);
-    }
-    return (1);
-}
-
-
-output_defines()
-{
-    register int c, i;
-    register char *s;
-
-    for (i = 2; i < ntokens; ++i)
-    {
-	s = symbol_name[i];
-	if (is_C_identifier(s))
-	{
-	    fprintf(code_file, "#define ");
-	    if (dflag) fprintf(defines_file, "#define ");
-	    c = *s;
-	    if (c == '"')
-	    {
-		while ((c = *++s) != '"')
-		{
-		    putc(c, code_file);
-		    if (dflag) putc(c, defines_file);
-		}
-	    }
-	    else
-	    {
-		do
-		{
-		    putc(c, code_file);
-		    if (dflag) putc(c, defines_file);
-		}
-		while (c = *++s);
-	    }
-	    ++outline;
-	    fprintf(code_file, " %d\n", symbol_value[i]);
-	    if (dflag) fprintf(defines_file, " %d\n", symbol_value[i]);
-	}
-    }
-
-    ++outline;
-    fprintf(code_file, "#define YYERRCODE %d\n", symbol_value[1]);
-
-    if (dflag && unionized)
-    {
-	fclose(union_file);
-	union_file = fopen(union_file_name, "r");
-	if (union_file == NULL) open_error(union_file_name);
-	while ((c = getc(union_file)) != EOF)
-	    putc(c, defines_file);
-	fprintf(defines_file, " YYSTYPE;\nextern YYSTYPE %slval;\n",
-		symbol_prefix);
-    }
-}
-
-
-output_stored_text()
-{
-    register int c;
-    register FILE *in, *out;
-
-    fclose(text_file);
-    text_file = fopen(text_file_name, "r");
-    if (text_file == NULL)
-	open_error(text_file_name);
-    in = text_file;
-    if ((c = getc(in)) == EOF)
-	return;
-    out = code_file;
-    if (c ==  '\n')
-	++outline;
-    putc(c, out);
-    while ((c = getc(in)) != EOF)
-    {
-	if (c == '\n')
-	    ++outline;
-	putc(c, out);
-    }
-    if (!lflag)
-	fprintf(out, line_format, ++outline + 1, code_file_name);
-}
-
-
-output_debug()
-{
-    register int i, j, k, max;
-    char **symnam, *s;
-
-    ++outline;
-    fprintf(code_file, "#define YYFINAL %d\n", final_state);
-    outline += 3;
-    fprintf(code_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
-	    tflag);
-    if (rflag)
-	fprintf(output_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
-		tflag);
-
-    max = 0;
-    for (i = 2; i < ntokens; ++i)
-	if (symbol_value[i] > max)
-	    max = symbol_value[i];
-    ++outline;
-    fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
-
-    symnam = (char **) MALLOC((max+1)*sizeof(char *));
-    if (symnam == 0) no_space();
-
-    /* Note that it is  not necessary to initialize the element		*/
-    /* symnam[max].							*/
-    for (i = 0; i < max; ++i)
-	symnam[i] = 0;
-    for (i = ntokens - 1; i >= 2; --i)
-	symnam[symbol_value[i]] = symbol_name[i];
-    symnam[0] = "end-of-file";
-
-    if (!rflag) ++outline;
-    fprintf(output_file, "#if YYDEBUG\nchar *%sname[] = {", symbol_prefix);
-    j = 80;
-    for (i = 0; i <= max; ++i)
-    {
-	if (s = symnam[i])
-	{
-	    if (s[0] == '"')
-	    {
-		k = 7;
-		while (*++s != '"')
-		{
-		    ++k;
-		    if (*s == '\\')
-		    {
-			k += 2;
-			if (*++s == '\\')
-			    ++k;
-		    }
-		}
-		j += k;
-		if (j > 80)
-		{
-		    if (!rflag) ++outline;
-		    putc('\n', output_file);
-		    j = k;
-		}
-		fprintf(output_file, "\"\\\"");
-		s = symnam[i];
-		while (*++s != '"')
-		{
-		    if (*s == '\\')
-		    {
-			fprintf(output_file, "\\\\");
-			if (*++s == '\\')
-			    fprintf(output_file, "\\\\");
-			else
-			    putc(*s, output_file);
-		    }
-		    else
-			putc(*s, output_file);
-		}
-		fprintf(output_file, "\\\"\",");
-	    }
-	    else if (s[0] == '\'')
-	    {
-		if (s[1] == '"')
-		{
-		    j += 7;
-		    if (j > 80)
-		    {
-			if (!rflag) ++outline;
-			putc('\n', output_file);
-			j = 7;
-		    }
-		    fprintf(output_file, "\"'\\\"'\",");
-		}
-		else
-		{
-		    k = 5;
-		    while (*++s != '\'')
-		    {
-			++k;
-			if (*s == '\\')
-			{
-			    k += 2;
-			    if (*++s == '\\')
-				++k;
-			}
-		    }
-		    j += k;
-		    if (j > 80)
-		    {
-			if (!rflag) ++outline;
-			putc('\n', output_file);
-			j = k;
-		    }
-		    fprintf(output_file, "\"'");
-		    s = symnam[i];
-		    while (*++s != '\'')
-		    {
-			if (*s == '\\')
-			{
-			    fprintf(output_file, "\\\\");
-			    if (*++s == '\\')
-				fprintf(output_file, "\\\\");
-			    else
-				putc(*s, output_file);
-			}
-			else
-			    putc(*s, output_file);
-		    }
-		    fprintf(output_file, "'\",");
-		}
-	    }
-	    else
-	    {
-		k = strlen(s) + 3;
-		j += k;
-		if (j > 80)
-		{
-		    if (!rflag) ++outline;
-		    putc('\n', output_file);
-		    j = k;
-		}
-		putc('"', output_file);
-		do { putc(*s, output_file); } while (*++s);
-		fprintf(output_file, "\",");
-	    }
-	}
-	else
-	{
-	    j += 2;
-	    if (j > 80)
-	    {
-		if (!rflag) ++outline;
-		putc('\n', output_file);
-		j = 2;
-	    }
-	    fprintf(output_file, "0,");
-	}
-    }
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    FREE(symnam);
-
-    if (!rflag) ++outline;
-    fprintf(output_file, "char *%srule[] = {\n", symbol_prefix);
-    for (i = 2; i < nrules; ++i)
-    {
-	fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
-	for (j = rrhs[i]; ritem[j] > 0; ++j)
-	{
-	    s = symbol_name[ritem[j]];
-	    if (s[0] == '"')
-	    {
-		fprintf(output_file, " \\\"");
-		while (*++s != '"')
-		{
-		    if (*s == '\\')
-		    {
-			if (s[1] == '\\')
-			    fprintf(output_file, "\\\\\\\\");
-			else
-			    fprintf(output_file, "\\\\%c", s[1]);
-			++s;
-		    }
-		    else
-			putc(*s, output_file);
-		}
-		fprintf(output_file, "\\\"");
-	    }
-	    else if (s[0] == '\'')
-	    {
-		if (s[1] == '"')
-		    fprintf(output_file, " '\\\"'");
-		else if (s[1] == '\\')
-		{
-		    if (s[2] == '\\')
-			fprintf(output_file, " '\\\\\\\\");
-		    else
-			fprintf(output_file, " '\\\\%c", s[2]);
-		    s += 2;
-		    while (*++s != '\'')
-			putc(*s, output_file);
-		    putc('\'', output_file);
-		}
-		else
-		    fprintf(output_file, " '%c'", s[1]);
-	    }
-	    else
-		fprintf(output_file, " %s", s);
-	}
-	if (!rflag) ++outline;
-	fprintf(output_file, "\",\n");
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "};\n#endif\n");
-}
-
-
-output_stype()
-{
-    if (!unionized && ntags == 0)
-    {
-	outline += 3;
-	fprintf(code_file, "#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n");
-    }
-}
-
-
-output_trailing_text()
-{
-    register int c, last;
-    register FILE *in, *out;
-
-    if (line == 0)
-	return;
-
-    in = input_file;
-    out = code_file;
-    c = *cptr;
-    if (c == '\n')
-    {
-	++lineno;
-	if ((c = getc(in)) == EOF)
-	    return;
-	if (!lflag)
-	{
-	    ++outline;
-	    fprintf(out, line_format, lineno, input_file_name);
-	}
-	if (c == '\n')
-	    ++outline;
-	putc(c, out);
-	last = c;
-    }
-    else
-    {
-	if (!lflag)
-	{
-	    ++outline;
-	    fprintf(out, line_format, lineno, input_file_name);
-	}
-	do { putc(c, out); } while ((c = *++cptr) != '\n');
-	++outline;
-	putc('\n', out);
-	last = '\n';
-    }
-
-    while ((c = getc(in)) != EOF)
-    {
-	if (c == '\n')
-	    ++outline;
-	putc(c, out);
-	last = c;
-    }
-
-    if (last != '\n')
-    {
-	++outline;
-	putc('\n', out);
-    }
-    if (!lflag)
-	fprintf(out, line_format, ++outline + 1, code_file_name);
-}
-
-
-output_semantic_actions()
-{
-    register int c, last;
-    register FILE *out;
-
-    fclose(action_file);
-    action_file = fopen(action_file_name, "r");
-    if (action_file == NULL)
-	open_error(action_file_name);
-
-    if ((c = getc(action_file)) == EOF)
-	return;
-
-    out = code_file;
-    last = c;
-    if (c == '\n')
-	++outline;
-    putc(c, out);
-    while ((c = getc(action_file)) != EOF)
-    {
-	if (c == '\n')
-	    ++outline;
-	putc(c, out);
-	last = c;
-    }
-
-    if (last != '\n')
-    {
-	++outline;
-	putc('\n', out);
-    }
-
-    if (!lflag)
-	fprintf(out, line_format, ++outline + 1, code_file_name);
-}
-
-
-free_itemsets()
-{
-    register core *cp, *next;
-
-    FREE(state_table);
-    for (cp = first_state; cp; cp = next)
-    {
-	next = cp->next;
-	FREE(cp);
-    }
-}
-
-
-free_shifts()
-{
-    register shifts *sp, *next;
-
-    FREE(shift_table);
-    for (sp = first_shift; sp; sp = next)
-    {
-	next = sp->next;
-	FREE(sp);
-    }
-}
-
-
-
-free_reductions()
-{
-    register reductions *rp, *next;
-
-    FREE(reduction_table);
-    for (rp = first_reduction; rp; rp = next)
-    {
-	next = rp->next;
-	FREE(rp);
-    }
-}
Index: trunk/minix/commands/byacc/reader.c
===================================================================
--- trunk/minix/commands/byacc/reader.c	(revision 9)
+++ 	(revision )
@@ -1,1770 +1,0 @@
-#include "defs.h"
-
-/*  The line size must be a positive integer.  One hundred was chosen	*/
-/*  because few lines in Yacc input grammars exceed 100 characters.	*/
-/*  Note that if a line exceeds LINESIZE characters, the line buffer	*/
-/*  will be expanded to accomodate it.					*/
-
-#define LINESIZE 100
-
-char *cache;
-int cinc, cache_size;
-
-int ntags, tagmax;
-char **tag_table;
-
-char saw_eof, unionized;
-char *cptr, *line;
-int linesize;
-
-bucket *goal;
-int prec;
-int gensym;
-char last_was_action;
-
-int maxitems;
-bucket **pitem;
-
-int maxrules;
-bucket **plhs;
-
-int name_pool_size;
-char *name_pool;
-
-char line_format[] = "#line %d \"%s\"\n";
-
-
-cachec(c)
-int c;
-{
-    assert(cinc >= 0);
-    if (cinc >= cache_size)
-    {
-	cache_size += 256;
-	cache = REALLOC(cache, cache_size);
-	if (cache == 0) no_space();
-    }
-    cache[cinc] = c;
-    ++cinc;
-}
-
-
-get_line()
-{
-    register FILE *f = input_file;
-    register int c;
-    register int i;
-
-    if (saw_eof || (c = getc(f)) == EOF)
-    {
-	if (line) { FREE(line); line = 0; }
-	cptr = 0;
-	saw_eof = 1;
-	return;
-    }
-
-    if (line == 0 || linesize != (LINESIZE + 1))
-    {
-	if (line) FREE(line);
-	linesize = LINESIZE + 1;
-	line = MALLOC(linesize);
-	if (line == 0) no_space();
-    }
-
-    i = 0;
-    ++lineno;
-    for (;;)
-    {
-	line[i]  =  c;
-	if (c == '\n') { cptr = line; return; }
-	if (++i >= linesize)
-	{
-	    linesize += LINESIZE;
-	    line = REALLOC(line, linesize);
-	    if (line ==  0) no_space();
-	}
-	c = getc(f);
-	if (c ==  EOF)
-	{
-	    line[i] = '\n';
-	    saw_eof = 1;
-	    cptr = line;
-	    return;
-	}
-    }
-}
-
-
-char *
-dup_line()
-{
-    register char *p, *s, *t;
-
-    if (line == 0) return (0);
-    s = line;
-    while (*s != '\n') ++s;
-    p = MALLOC(s - line + 1);
-    if (p == 0) no_space();
-
-    s = line;
-    t = p;
-    while ((*t++ = *s++) != '\n') continue;
-    return (p);
-}
-
-
-skip_comment()
-{
-    register char *s;
-
-    int st_lineno = lineno;
-    char *st_line = dup_line();
-    char *st_cptr = st_line + (cptr - line);
-
-    s = cptr + 2;
-    for (;;)
-    {
-	if (*s == '*' && s[1] == '/')
-	{
-	    cptr = s + 2;
-	    FREE(st_line);
-	    return;
-	}
-	if (*s == '\n')
-	{
-	    get_line();
-	    if (line == 0)
-		unterminated_comment(st_lineno, st_line, st_cptr);
-	    s = cptr;
-	}
-	else
-	    ++s;
-    }
-}
-
-
-int
-nextc()
-{
-    register char *s;
-
-    if (line == 0)
-    {
-	get_line();
-	if (line == 0)
-	    return (EOF);
-    }
-
-    s = cptr;
-    for (;;)
-    {
-	switch (*s)
-	{
-	case '\n':
-	    get_line();
-	    if (line == 0) return (EOF);
-	    s = cptr;
-	    break;
-
-	case ' ':
-	case '\t':
-	case '\f':
-	case '\r':
-	case '\v':
-	case ',':
-	case ';':
-	    ++s;
-	    break;
-
-	case '\\':
-	    cptr = s;
-	    return ('%');
-
-	case '/':
-	    if (s[1] == '*')
-	    {
-		cptr = s;
-		skip_comment();
-		s = cptr;
-		break;
-	    }
-	    else if (s[1] == '/')
-	    {
-		get_line();
-		if (line == 0) return (EOF);
-		s = cptr;
-		break;
-	    }
-	    /* fall through */
-
-	default:
-	    cptr = s;
-	    return (*s);
-	}
-    }
-}
-
-
-int
-keyword()
-{
-    register int c;
-    char *t_cptr = cptr;
-
-    c = *++cptr;
-    if (isalpha(c))
-    {
-	cinc = 0;
-	for (;;)
-	{
-	    if (isalpha(c))
-	    {
-		if (isupper(c)) c = tolower(c);
-		cachec(c);
-	    }
-	    else if (isdigit(c) || c == '_' || c == '.' || c == '$')
-		cachec(c);
-	    else
-		break;
-	    c = *++cptr;
-	}
-	cachec(NUL);
-
-	if (strcmp(cache, "token") == 0 || strcmp(cache, "term") == 0)
-	    return (TOKEN);
-	if (strcmp(cache, "type") == 0)
-	    return (TYPE);
-	if (strcmp(cache, "left") == 0)
-	    return (LEFT);
-	if (strcmp(cache, "right") == 0)
-	    return (RIGHT);
-	if (strcmp(cache, "nonassoc") == 0 || strcmp(cache, "binary") == 0)
-	    return (NONASSOC);
-	if (strcmp(cache, "start") == 0)
-	    return (START);
-	if (strcmp(cache, "union") == 0)
-	    return (UNION);
-	if (strcmp(cache, "ident") == 0)
-	    return (IDENT);
-    }
-    else
-    {
-	++cptr;
-	if (c == '{')
-	    return (TEXT);
-	if (c == '%' || c == '\\')
-	    return (MARK);
-	if (c == '<')
-	    return (LEFT);
-	if (c == '>')
-	    return (RIGHT);
-	if (c == '0')
-	    return (TOKEN);
-	if (c == '2')
-	    return (NONASSOC);
-    }
-    syntax_error(lineno, line, t_cptr);
-    /*NOTREACHED*/
-}
-
-
-copy_ident()
-{
-    register int c;
-    register FILE *f = output_file;
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c != '"') syntax_error(lineno, line, cptr);
-    ++outline;
-    fprintf(f, "#ident \"");
-    for (;;)
-    {
-	c = *++cptr;
-	if (c == '\n')
-	{
-	    fprintf(f, "\"\n");
-	    return;
-	}
-	putc(c, f);
-	if (c == '"')
-	{
-	    putc('\n', f);
-	    ++cptr;
-	    return;
-	}
-    }
-}
-
-
-copy_text()
-{
-    register int c;
-    int quote;
-    register FILE *f = text_file;
-    int need_newline = 0;
-    int t_lineno = lineno;
-    char *t_line = dup_line();
-    char *t_cptr = t_line + (cptr - line - 2);
-
-    if (*cptr == '\n')
-    {
-	get_line();
-	if (line == 0)
-	    unterminated_text(t_lineno, t_line, t_cptr);
-    }
-    if (!lflag) fprintf(f, line_format, lineno, input_file_name);
-
-loop:
-    c = *cptr++;
-    switch (c)
-    {
-    case '\n':
-    next_line:
-	putc('\n', f);
-	need_newline = 0;
-	get_line();
-	if (line) goto loop;
-	unterminated_text(t_lineno, t_line, t_cptr);
-
-    case '\'':
-    case '"':
-	{
-	    int s_lineno = lineno;
-	    char *s_line = dup_line();
-	    char *s_cptr = s_line + (cptr - line - 1);
-
-	    quote = c;
-	    putc(c, f);
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, f);
-		if (c == quote)
-		{
-		    need_newline = 1;
-		    FREE(s_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		    unterminated_string(s_lineno, s_line, s_cptr);
-		if (c == '\\')
-		{
-		    c = *cptr++;
-		    putc(c, f);
-		    if (c == '\n')
-		    {
-			get_line();
-			if (line == 0)
-			    unterminated_string(s_lineno, s_line, s_cptr);
-		    }
-		}
-	    }
-	}
-
-    case '/':
-	putc(c, f);
-	need_newline = 1;
-	c = *cptr;
-	if (c == '/')
-	{
-	    putc('*', f);
-	    while ((c = *++cptr) != '\n')
-	    {
-		if (c == '*' && cptr[1] == '/')
-		    fprintf(f, "* ");
-		else
-		    putc(c, f);
-	    }
-	    fprintf(f, "*/");
-	    goto next_line;
-	}
-	if (c == '*')
-	{
-	    int c_lineno = lineno;
-	    char *c_line = dup_line();
-	    char *c_cptr = c_line + (cptr - line - 1);
-
-	    putc('*', f);
-	    ++cptr;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, f);
-		if (c == '*' && *cptr == '/')
-		{
-		    putc('/', f);
-		    ++cptr;
-		    FREE(c_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		{
-		    get_line();
-		    if (line == 0)
-			unterminated_comment(c_lineno, c_line, c_cptr);
-		}
-	    }
-	}
-	need_newline = 1;
-	goto loop;
-
-    case '%':
-    case '\\':
-	if (*cptr == '}')
-	{
-	    if (need_newline) putc('\n', f);
-	    ++cptr;
-	    FREE(t_line);
-	    return;
-	}
-	/* fall through */
-
-    default:
-	putc(c, f);
-	need_newline = 1;
-	goto loop;
-    }
-}
-
-
-copy_union()
-{
-    register int c;
-    int quote;
-    int depth;
-    int u_lineno = lineno;
-    char *u_line = dup_line();
-    char *u_cptr = u_line + (cptr - line - 6);
-
-    if (unionized) over_unionized(cptr - 6);
-    unionized = 1;
-
-    if (!lflag)
-	fprintf(text_file, line_format, lineno, input_file_name);
-
-    fprintf(text_file, "typedef union");
-    if (dflag) fprintf(union_file, "typedef union");
-
-    depth = 0;
-loop:
-    c = *cptr++;
-    putc(c, text_file);
-    if (dflag) putc(c, union_file);
-    switch (c)
-    {
-    case '\n':
-    next_line:
-	get_line();
-	if (line == 0) unterminated_union(u_lineno, u_line, u_cptr);
-	goto loop;
-
-    case '{':
-	++depth;
-	goto loop;
-
-    case '}':
-	if (--depth == 0)
-	{
-	    fprintf(text_file, " YYSTYPE;\n");
-	    FREE(u_line);
-	    return;
-	}
-	goto loop;
-
-    case '\'':
-    case '"':
-	{
-	    int s_lineno = lineno;
-	    char *s_line = dup_line();
-	    char *s_cptr = s_line + (cptr - line - 1);
-
-	    quote = c;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, text_file);
-		if (dflag) putc(c, union_file);
-		if (c == quote)
-		{
-		    FREE(s_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		    unterminated_string(s_lineno, s_line, s_cptr);
-		if (c == '\\')
-		{
-		    c = *cptr++;
-		    putc(c, text_file);
-		    if (dflag) putc(c, union_file);
-		    if (c == '\n')
-		    {
-			get_line();
-			if (line == 0)
-			    unterminated_string(s_lineno, s_line, s_cptr);
-		    }
-		}
-	    }
-	}
-
-    case '/':
-	c = *cptr;
-	if (c == '/')
-	{
-	    putc('*', text_file);
-	    if (dflag) putc('*', union_file);
-	    while ((c = *++cptr) != '\n')
-	    {
-		if (c == '*' && cptr[1] == '/')
-		{
-		    fprintf(text_file, "* ");
-		    if (dflag) fprintf(union_file, "* ");
-		}
-		else
-		{
-		    putc(c, text_file);
-		    if (dflag) putc(c, union_file);
-		}
-	    }
-	    fprintf(text_file, "*/\n");
-	    if (dflag) fprintf(union_file, "*/\n");
-	    goto next_line;
-	}
-	if (c == '*')
-	{
-	    int c_lineno = lineno;
-	    char *c_line = dup_line();
-	    char *c_cptr = c_line + (cptr - line - 1);
-
-	    putc('*', text_file);
-	    if (dflag) putc('*', union_file);
-	    ++cptr;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, text_file);
-		if (dflag) putc(c, union_file);
-		if (c == '*' && *cptr == '/')
-		{
-		    putc('/', text_file);
-		    if (dflag) putc('/', union_file);
-		    ++cptr;
-		    FREE(c_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		{
-		    get_line();
-		    if (line == 0)
-			unterminated_comment(c_lineno, c_line, c_cptr);
-		}
-	    }
-	}
-	goto loop;
-
-    default:
-	goto loop;
-    }
-}
-
-
-int
-hexval(c)
-int c;
-{
-    if (c >= '0' && c <= '9')
-	return (c - '0');
-    if (c >= 'A' && c <= 'F')
-	return (c - 'A' + 10);
-    if (c >= 'a' && c <= 'f')
-	return (c - 'a' + 10);
-    return (-1);
-}
-
-
-bucket *
-get_literal()
-{
-    register int c, quote;
-    register int i;
-    register int n;
-    register char *s;
-    register bucket *bp;
-    int s_lineno = lineno;
-    char *s_line = dup_line();
-    char *s_cptr = s_line + (cptr - line);
-
-    quote = *cptr++;
-    cinc = 0;
-    for (;;)
-    {
-	c = *cptr++;
-	if (c == quote) break;
-	if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr);
-	if (c == '\\')
-	{
-	    char *c_cptr = cptr - 1;
-
-	    c = *cptr++;
-	    switch (c)
-	    {
-	    case '\n':
-		get_line();
-		if (line == 0) unterminated_string(s_lineno, s_line, s_cptr);
-		continue;
-
-	    case '0': case '1': case '2': case '3':
-	    case '4': case '5': case '6': case '7':
-		n = c - '0';
-		c = *cptr;
-		if (IS_OCTAL(c))
-		{
-		    n = (n << 3) + (c - '0');
-		    c = *++cptr;
-		    if (IS_OCTAL(c))
-		    {
-			n = (n << 3) + (c - '0');
-			++cptr;
-		    }
-		}
-		if (n > MAXCHAR) illegal_character(c_cptr);
-		c = n;
-	    	break;
-
-	    case 'x':
-		c = *cptr++;
-		n = hexval(c);
-		if (n < 0 || n >= 16)
-		    illegal_character(c_cptr);
-		for (;;)
-		{
-		    c = *cptr;
-		    i = hexval(c);
-		    if (i < 0 || i >= 16) break;
-		    ++cptr;
-		    n = (n << 4) + i;
-		    if (n > MAXCHAR) illegal_character(c_cptr);
-		}
-		c = n;
-		break;
-
-	    case 'a': c = 7; break;
-	    case 'b': c = '\b'; break;
-	    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;
-	    }
-	}
-	cachec(c);
-    }
-    FREE(s_line);
-
-    n = cinc;
-    s = MALLOC(n);
-    if (s == 0) no_space();
-    
-    for (i = 0; i < n; ++i)
-	s[i] = cache[i];
-
-    cinc = 0;
-    if (n == 1)
-	cachec('\'');
-    else
-	cachec('"');
-
-    for (i = 0; i < n; ++i)
-    {
-	c = ((unsigned char *)s)[i];
-	if (c == '\\' || c == cache[0])
-	{
-	    cachec('\\');
-	    cachec(c);
-	}
-	else if (isprint(c))
-	    cachec(c);
-	else
-	{
-	    cachec('\\');
-	    switch (c)
-	    {
-	    case 7: cachec('a'); break;
-	    case '\b': cachec('b'); break;
-	    case '\f': cachec('f'); break;
-	    case '\n': cachec('n'); break;
-	    case '\r': cachec('r'); break;
-	    case '\t': cachec('t'); break;
-	    case '\v': cachec('v'); break;
-	    default:
-		cachec(((c >> 6) & 7) + '0');
-		cachec(((c >> 3) & 7) + '0');
-		cachec((c & 7) + '0');
-		break;
-	    }
-	}
-    }
-
-    if (n == 1)
-	cachec('\'');
-    else
-	cachec('"');
-
-    cachec(NUL);
-    bp = lookup(cache);
-    bp->class = TERM;
-    if (n == 1 && bp->value == UNDEFINED)
-	bp->value = *(unsigned char *)s;
-    FREE(s);
-
-    return (bp);
-}
-
-
-int
-is_reserved(name)
-char *name;
-{
-    char *s;
-
-    if (strcmp(name, ".") == 0 ||
-	    strcmp(name, "$accept") == 0 ||
-	    strcmp(name, "$end") == 0)
-	return (1);
-
-    if (name[0] == '$' && name[1] == '$' && isdigit(name[2]))
-    {
-	s = name + 3;
-	while (isdigit(*s)) ++s;
-	if (*s == NUL) return (1);
-    }
-
-    return (0);
-}
-
-
-bucket *
-get_name()
-{
-    register int c;
-
-    cinc = 0;
-    for (c = *cptr; IS_IDENT(c); c = *++cptr)
-	cachec(c);
-    cachec(NUL);
-
-    if (is_reserved(cache)) used_reserved(cache);
-
-    return (lookup(cache));
-}
-
-
-int
-get_number()
-{
-    register int c;
-    register int n;
-
-    n = 0;
-    for (c = *cptr; isdigit(c); c = *++cptr)
-	n = 10*n + (c - '0');
-
-    return (n);
-}
-
-
-char *
-get_tag()
-{
-    register int c;
-    register int i;
-    register char *s;
-    int t_lineno = lineno;
-    char *t_line = dup_line();
-    char *t_cptr = t_line + (cptr - line);
-
-    ++cptr;
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (!isalpha(c) && c != '_' && c != '$')
-	illegal_tag(t_lineno, t_line, t_cptr);
-
-    cinc = 0;
-    do { cachec(c); c = *++cptr; } while (IS_IDENT(c));
-    cachec(NUL);
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c != '>')
-	illegal_tag(t_lineno, t_line, t_cptr);
-    ++cptr;
-
-    for (i = 0; i < ntags; ++i)
-    {
-	if (strcmp(cache, tag_table[i]) == 0)
-	    return (tag_table[i]);
-    }
-
-    if (ntags >= tagmax)
-    {
-	tagmax += 16;
-	tag_table = (char **)
-			(tag_table ? REALLOC(tag_table, tagmax*sizeof(char *))
-				   : MALLOC(tagmax*sizeof(char *)));
-	if (tag_table == 0) no_space();
-    }
-
-    s = MALLOC(cinc);
-    if  (s == 0) no_space();
-    strcpy(s, cache);
-    tag_table[ntags] = s;
-    ++ntags;
-    FREE(t_line);
-    return (s);
-}
-
-
-declare_tokens(assoc)
-int assoc;
-{
-    register int c;
-    register bucket *bp;
-    int value;
-    char *tag = 0;
-
-    if (assoc != TOKEN) ++prec;
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c == '<')
-    {
-	tag = get_tag();
-	c = nextc();
-	if (c == EOF) unexpected_EOF();
-    }
-
-    for (;;)
-    {
-	if (isalpha(c) || c == '_' || c == '.' || c == '$')
-	    bp = get_name();
-	else if (c == '\'' || c == '"')
-	    bp = get_literal();
-	else
-	    return;
-
-	if (bp == goal) tokenized_start(bp->name);
-	bp->class = TERM;
-
-	if (tag)
-	{
-	    if (bp->tag && tag != bp->tag)
-		retyped_warning(bp->name);
-	    bp->tag = tag;
-	}
-
-	if (assoc != TOKEN)
-	{
-	    if (bp->prec && prec != bp->prec)
-		reprec_warning(bp->name);
-	    bp->assoc = assoc;
-	    bp->prec = prec;
-	}
-
-	c = nextc();
-	if (c == EOF) unexpected_EOF();
-	value = UNDEFINED;
-	if (isdigit(c))
-	{
-	    value = get_number();
-	    if (bp->value != UNDEFINED && value != bp->value)
-		revalued_warning(bp->name);
-	    bp->value = value;
-	    c = nextc();
-	    if (c == EOF) unexpected_EOF();
-	}
-    }
-}
-
-
-declare_types()
-{
-    register int c;
-    register bucket *bp;
-    char *tag;
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c != '<') syntax_error(lineno, line, cptr);
-    tag = get_tag();
-
-    for (;;)
-    {
-	c = nextc();
-	if (isalpha(c) || c == '_' || c == '.' || c == '$')
-	    bp = get_name();
-	else if (c == '\'' || c == '"')
-	    bp = get_literal();
-	else
-	    return;
-
-	if (bp->tag && tag != bp->tag)
-	    retyped_warning(bp->name);
-	bp->tag = tag;
-    }
-}
-
-
-declare_start()
-{
-    register int c;
-    register bucket *bp;
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (!isalpha(c) && c != '_' && c != '.' && c != '$')
-	syntax_error(lineno, line, cptr);
-    bp = get_name();
-    if (bp->class == TERM)
-	terminal_start(bp->name);
-    if (goal && goal != bp)
-	restarted_warning();
-    goal = bp;
-}
-
-
-read_declarations()
-{
-    register int c, k;
-
-    cache_size = 256;
-    cache = MALLOC(cache_size);
-    if (cache == 0) no_space();
-
-    for (;;)
-    {
-	c = nextc();
-	if (c == EOF) unexpected_EOF();
-	if (c != '%') syntax_error(lineno, line, cptr);
-	switch (k = keyword())
-	{
-	case MARK:
-	    return;
-
-	case IDENT:
-	    copy_ident();
-	    break;
-
-	case TEXT:
-	    copy_text();
-	    break;
-
-	case UNION:
-	    copy_union();
-	    break;
-
-	case TOKEN:
-	case LEFT:
-	case RIGHT:
-	case NONASSOC:
-	    declare_tokens(k);
-	    break;
-
-	case TYPE:
-	    declare_types();
-	    break;
-
-	case START:
-	    declare_start();
-	    break;
-	}
-    }
-}
-
-
-initialize_grammar()
-{
-    nitems = 4;
-    maxitems = 300;
-    pitem = (bucket **) MALLOC(maxitems*sizeof(bucket *));
-    if (pitem == 0) no_space();
-    pitem[0] = 0;
-    pitem[1] = 0;
-    pitem[2] = 0;
-    pitem[3] = 0;
-
-    nrules = 3;
-    maxrules = 100;
-    plhs = (bucket **) MALLOC(maxrules*sizeof(bucket *));
-    if (plhs == 0) no_space();
-    plhs[0] = 0;
-    plhs[1] = 0;
-    plhs[2] = 0;
-    rprec = (short *) MALLOC(maxrules*sizeof(short));
-    if (rprec == 0) no_space();
-    rprec[0] = 0;
-    rprec[1] = 0;
-    rprec[2] = 0;
-    rassoc = (char *) MALLOC(maxrules*sizeof(char));
-    if (rassoc == 0) no_space();
-    rassoc[0] = TOKEN;
-    rassoc[1] = TOKEN;
-    rassoc[2] = TOKEN;
-}
-
-
-expand_items()
-{
-    maxitems += 300;
-    pitem = (bucket **) REALLOC(pitem, maxitems*sizeof(bucket *));
-    if (pitem == 0) no_space();
-}
-
-
-expand_rules()
-{
-    maxrules += 100;
-    plhs = (bucket **) REALLOC(plhs, maxrules*sizeof(bucket *));
-    if (plhs == 0) no_space();
-    rprec = (short *) REALLOC(rprec, maxrules*sizeof(short));
-    if (rprec == 0) no_space();
-    rassoc = (char *) REALLOC(rassoc, maxrules*sizeof(char));
-    if (rassoc == 0) no_space();
-}
-
-
-advance_to_start()
-{
-    register int c;
-    register bucket *bp;
-    char *s_cptr;
-    int s_lineno;
-
-    for (;;)
-    {
-	c = nextc();
-	if (c != '%') break;
-	s_cptr = cptr;
-	switch (keyword())
-	{
-	case MARK:
-	    no_grammar();
-
-	case TEXT:
-	    copy_text();
-	    break;
-
-	case START:
-	    declare_start();
-	    break;
-
-	default:
-	    syntax_error(lineno, line, s_cptr);
-	}
-    }
-
-    c = nextc();
-    if (!isalpha(c) && c != '_' && c != '.' && c != '_')
-	syntax_error(lineno, line, cptr);
-    bp = get_name();
-    if (goal == 0)
-    {
-	if (bp->class == TERM)
-	    terminal_start(bp->name);
-	goal = bp;
-    }
-
-    s_lineno = lineno;
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c != ':') syntax_error(lineno, line, cptr);
-    start_rule(bp, s_lineno);
-    ++cptr;
-}
-
-
-start_rule(bp, s_lineno)
-register bucket *bp;
-int s_lineno;
-{
-    if (bp->class == TERM)
-	terminal_lhs(s_lineno);
-    bp->class = NONTERM;
-    if (nrules >= maxrules)
-	expand_rules();
-    plhs[nrules] = bp;
-    rprec[nrules] = UNDEFINED;
-    rassoc[nrules] = TOKEN;
-}
-
-
-end_rule()
-{
-    register int i;
-
-    if (!last_was_action && plhs[nrules]->tag)
-    {
-	for (i = nitems - 1; pitem[i]; --i) continue;
-	if (pitem[i+1] == 0 || pitem[i+1]->tag != plhs[nrules]->tag)
-	    default_action_warning();
-    }
-
-    last_was_action = 0;
-    if (nitems >= maxitems) expand_items();
-    pitem[nitems] = 0;
-    ++nitems;
-    ++nrules;
-}
-
-
-insert_empty_rule()
-{
-    register bucket *bp, **bpp;
-
-    assert(cache);
-    sprintf(cache, "$$%d", ++gensym);
-    bp = make_bucket(cache);
-    last_symbol->next = bp;
-    last_symbol = bp;
-    bp->tag = plhs[nrules]->tag;
-    bp->class = NONTERM;
-
-    if ((nitems += 2) > maxitems)
-	expand_items();
-    bpp = pitem + nitems - 1;
-    *bpp-- = bp;
-    while (bpp[0] = bpp[-1]) --bpp;
-
-    if (++nrules >= maxrules)
-	expand_rules();
-    plhs[nrules] = plhs[nrules-1];
-    plhs[nrules-1] = bp;
-    rprec[nrules] = rprec[nrules-1];
-    rprec[nrules-1] = 0;
-    rassoc[nrules] = rassoc[nrules-1];
-    rassoc[nrules-1] = TOKEN;
-}
-
-
-add_symbol()
-{
-    register int c;
-    register bucket *bp;
-    int s_lineno = lineno;
-
-    c = *cptr;
-    if (c == '\'' || c == '"')
-	bp = get_literal();
-    else
-	bp = get_name();
-
-    c = nextc();
-    if (c == ':')
-    {
-	end_rule();
-	start_rule(bp, s_lineno);
-	++cptr;
-	return;
-    }
-
-    if (last_was_action)
-	insert_empty_rule();
-    last_was_action = 0;
-
-    if (++nitems > maxitems)
-	expand_items();
-    pitem[nitems-1] = bp;
-}
-
-
-copy_action()
-{
-    register int c;
-    register int i, n;
-    int depth;
-    int quote;
-    char *tag;
-    register FILE *f = action_file;
-    int a_lineno = lineno;
-    char *a_line = dup_line();
-    char *a_cptr = a_line + (cptr - line);
-
-    if (last_was_action)
-	insert_empty_rule();
-    last_was_action = 1;
-
-    fprintf(f, "case %d:\n", nrules - 2);
-    if (!lflag)
-	fprintf(f, line_format, lineno, input_file_name);
-    if (*cptr == '=') ++cptr;
-
-    n = 0;
-    for (i = nitems - 1; pitem[i]; --i) ++n;
-
-    depth = 0;
-loop:
-    c = *cptr;
-    if (c == '$')
-    {
-	if (cptr[1] == '<')
-	{
-	    int d_lineno = lineno;
-	    char *d_line = dup_line();
-	    char *d_cptr = d_line + (cptr - line);
-
-	    ++cptr;
-	    tag = get_tag();
-	    c = *cptr;
-	    if (c == '$')
-	    {
-		fprintf(f, "yyval.%s", tag);
-		++cptr;
-		FREE(d_line);
-		goto loop;
-	    }
-	    else if (isdigit(c))
-	    {
-		i = get_number();
-		if (i > n) dollar_warning(d_lineno, i);
-		fprintf(f, "yyvsp[%d].%s", i - n, tag);
-		FREE(d_line);
-		goto loop;
-	    }
-	    else if (c == '-' && isdigit(cptr[1]))
-	    {
-		++cptr;
-		i = -get_number() - n;
-		fprintf(f, "yyvsp[%d].%s", i, tag);
-		FREE(d_line);
-		goto loop;
-	    }
-	    else
-		dollar_error(d_lineno, d_line, d_cptr);
-	}
-	else if (cptr[1] == '$')
-	{
-	    if (ntags)
-	    {
-		tag = plhs[nrules]->tag;
-		if (tag == 0) untyped_lhs();
-		fprintf(f, "yyval.%s", tag);
-	    }
-	    else
-		fprintf(f, "yyval");
-	    cptr += 2;
-	    goto loop;
-	}
-	else if (isdigit(cptr[1]))
-	{
-	    ++cptr;
-	    i = get_number();
-	    if (ntags)
-	    {
-		if (i <= 0 || i > n)
-		    unknown_rhs(i);
-		tag = pitem[nitems + i - n - 1]->tag;
-		if (tag == 0) untyped_rhs(i, pitem[nitems + i - n - 1]->name);
-		fprintf(f, "yyvsp[%d].%s", i - n, tag);
-	    }
-	    else
-	    {
-		if (i > n)
-		    dollar_warning(lineno, i);
-		fprintf(f, "yyvsp[%d]", i - n);
-	    }
-	    goto loop;
-	}
-	else if (cptr[1] == '-')
-	{
-	    cptr += 2;
-	    i = get_number();
-	    if (ntags)
-		unknown_rhs(-i);
-	    fprintf(f, "yyvsp[%d]", -i - n);
-	    goto loop;
-	}
-    }
-    if (isalpha(c) || c == '_' || c == '$')
-    {
-	do
-	{
-	    putc(c, f);
-	    c = *++cptr;
-	} while (isalnum(c) || c == '_' || c == '$');
-	goto loop;
-    }
-    putc(c, f);
-    ++cptr;
-    switch (c)
-    {
-    case '\n':
-    next_line:
-	get_line();
-	if (line) goto loop;
-	unterminated_action(a_lineno, a_line, a_cptr);
-
-    case ';':
-	if (depth > 0) goto loop;
-	fprintf(f, "\nbreak;\n");
-	return;
-
-    case '{':
-	++depth;
-	goto loop;
-
-    case '}':
-	if (--depth > 0) goto loop;
-	fprintf(f, "\nbreak;\n");
-	return;
-
-    case '\'':
-    case '"':
-	{
-	    int s_lineno = lineno;
-	    char *s_line = dup_line();
-	    char *s_cptr = s_line + (cptr - line - 1);
-
-	    quote = c;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, f);
-		if (c == quote)
-		{
-		    FREE(s_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		    unterminated_string(s_lineno, s_line, s_cptr);
-		if (c == '\\')
-		{
-		    c = *cptr++;
-		    putc(c, f);
-		    if (c == '\n')
-		    {
-			get_line();
-			if (line == 0)
-			    unterminated_string(s_lineno, s_line, s_cptr);
-		    }
-		}
-	    }
-	}
-
-    case '/':
-	c = *cptr;
-	if (c == '/')
-	{
-	    putc('*', f);
-	    while ((c = *++cptr) != '\n')
-	    {
-		if (c == '*' && cptr[1] == '/')
-		    fprintf(f, "* ");
-		else
-		    putc(c, f);
-	    }
-	    fprintf(f, "*/\n");
-	    goto next_line;
-	}
-	if (c == '*')
-	{
-	    int c_lineno = lineno;
-	    char *c_line = dup_line();
-	    char *c_cptr = c_line + (cptr - line - 1);
-
-	    putc('*', f);
-	    ++cptr;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, f);
-		if (c == '*' && *cptr == '/')
-		{
-		    putc('/', f);
-		    ++cptr;
-		    FREE(c_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		{
-		    get_line();
-		    if (line == 0)
-			unterminated_comment(c_lineno, c_line, c_cptr);
-		}
-	    }
-	}
-	goto loop;
-
-    default:
-	goto loop;
-    }
-}
-
-
-int
-mark_symbol()
-{
-    register int c;
-    register bucket *bp;
-
-    c = cptr[1];
-    if (c == '%' || c == '\\')
-    {
-	cptr += 2;
-	return (1);
-    }
-
-    if (c == '=')
-	cptr += 2;
-    else if ((c == 'p' || c == 'P') &&
-	     ((c = cptr[2]) == 'r' || c == 'R') &&
-	     ((c = cptr[3]) == 'e' || c == 'E') &&
-	     ((c = cptr[4]) == 'c' || c == 'C') &&
-	     ((c = cptr[5], !IS_IDENT(c))))
-	cptr += 5;
-    else
-	syntax_error(lineno, line, cptr);
-
-    c = nextc();
-    if (isalpha(c) || c == '_' || c == '.' || c == '$')
-	bp = get_name();
-    else if (c == '\'' || c == '"')
-	bp = get_literal();
-    else
-    {
-	syntax_error(lineno, line, cptr);
-	/*NOTREACHED*/
-    }
-
-    if (rprec[nrules] != UNDEFINED && bp->prec != rprec[nrules])
-	prec_redeclared();
-
-    rprec[nrules] = bp->prec;
-    rassoc[nrules] = bp->assoc;
-    return (0);
-}
-
-
-read_grammar()
-{
-    register int c;
-
-    initialize_grammar();
-    advance_to_start();
-
-    for (;;)
-    {
-	c = nextc();
-	if (c == EOF) break;
-	if (isalpha(c) || c == '_' || c == '.' || c == '$' || c == '\'' ||
-		c == '"')
-	    add_symbol();
-	else if (c == '{' || c == '=')
-	    copy_action();
-	else if (c == '|')
-	{
-	    end_rule();
-	    start_rule(plhs[nrules-1], 0);
-	    ++cptr;
-	}
-	else if (c == '%')
-	{
-	    if (mark_symbol()) break;
-	}
-	else
-	    syntax_error(lineno, line, cptr);
-    }
-    end_rule();
-}
-
-
-free_tags()
-{
-    register int i;
-
-    if (tag_table == 0) return;
-
-    for (i = 0; i < ntags; ++i)
-    {
-	assert(tag_table[i]);
-	FREE(tag_table[i]);
-    }
-    FREE(tag_table);
-}
-
-
-pack_names()
-{
-    register bucket *bp;
-    register char *p, *s, *t;
-
-    name_pool_size = 13;  /* 13 == sizeof("$end") + sizeof("$accept") */
-    for (bp = first_symbol; bp; bp = bp->next)
-	name_pool_size += strlen(bp->name) + 1;
-    name_pool = MALLOC(name_pool_size);
-    if (name_pool == 0) no_space();
-
-    strcpy(name_pool, "$accept");
-    strcpy(name_pool+8, "$end");
-    t = name_pool + 13;
-    for (bp = first_symbol; bp; bp = bp->next)
-    {
-	p = t;
-	s = bp->name;
-	while (*t++ = *s++) continue;
-	FREE(bp->name);
-	bp->name = p;
-    }
-}
-
-
-check_symbols()
-{
-    register bucket *bp;
-
-    if (goal->class == UNKNOWN)
-	undefined_goal(goal->name);
-
-    for (bp = first_symbol; bp; bp = bp->next)
-    {
-	if (bp->class == UNKNOWN)
-	{
-	    undefined_symbol_warning(bp->name);
-	    bp->class = TERM;
-	}
-    }
-}
-
-
-pack_symbols()
-{
-    register bucket *bp;
-    register bucket **v;
-    register int i, j, k, n;
-
-    nsyms = 2;
-    ntokens = 1;
-    for (bp = first_symbol; bp; bp = bp->next)
-    {
-	++nsyms;
-	if (bp->class == TERM) ++ntokens;
-    }
-    start_symbol = ntokens;
-    nvars = nsyms - ntokens;
-
-    symbol_name = (char **) MALLOC(nsyms*sizeof(char *));
-    if (symbol_name == 0) no_space();
-    symbol_value = (short *) MALLOC(nsyms*sizeof(short));
-    if (symbol_value == 0) no_space();
-    symbol_prec = (short *) MALLOC(nsyms*sizeof(short));
-    if (symbol_prec == 0) no_space();
-    symbol_assoc = MALLOC(nsyms);
-    if (symbol_assoc == 0) no_space();
-
-    v = (bucket **) MALLOC(nsyms*sizeof(bucket *));
-    if (v == 0) no_space();
-
-    v[0] = 0;
-    v[start_symbol] = 0;
-
-    i = 1;
-    j = start_symbol + 1;
-    for (bp = first_symbol; bp; bp = bp->next)
-    {
-	if (bp->class == TERM)
-	    v[i++] = bp;
-	else
-	    v[j++] = bp;
-    }
-    assert(i == ntokens && j == nsyms);
-
-    for (i = 1; i < ntokens; ++i)
-	v[i]->index = i;
-
-    goal->index = start_symbol + 1;
-    k = start_symbol + 2;
-    while (++i < nsyms)
-	if (v[i] != goal)
-	{
-	    v[i]->index = k;
-	    ++k;
-	}
-
-    goal->value = 0;
-    k = 1;
-    for (i = start_symbol + 1; i < nsyms; ++i)
-    {
-	if (v[i] != goal)
-	{
-	    v[i]->value = k;
-	    ++k;
-	}
-    }
-
-    k = 0;
-    for (i = 1; i < ntokens; ++i)
-    {
-	n = v[i]->value;
-	if (n > 256)
-	{
-	    for (j = k++; j > 0 && symbol_value[j-1] > n; --j)
-		symbol_value[j] = symbol_value[j-1];
-	    symbol_value[j] = n;
-	}
-    }
-
-    if (v[1]->value == UNDEFINED)
-	v[1]->value = 256;
-
-    j = 0;
-    n = 257;
-    for (i = 2; i < ntokens; ++i)
-    {
-	if (v[i]->value == UNDEFINED)
-	{
-	    while (j < k && n == symbol_value[j])
-	    {
-		while (++j < k && n == symbol_value[j]) continue;
-		++n;
-	    }
-	    v[i]->value = n;
-	    ++n;
-	}
-    }
-
-    symbol_name[0] = name_pool + 8;
-    symbol_value[0] = 0;
-    symbol_prec[0] = 0;
-    symbol_assoc[0] = TOKEN;
-    for (i = 1; i < ntokens; ++i)
-    {
-	symbol_name[i] = v[i]->name;
-	symbol_value[i] = v[i]->value;
-	symbol_prec[i] = v[i]->prec;
-	symbol_assoc[i] = v[i]->assoc;
-    }
-    symbol_name[start_symbol] = name_pool;
-    symbol_value[start_symbol] = -1;
-    symbol_prec[start_symbol] = 0;
-    symbol_assoc[start_symbol] = TOKEN;
-    for (++i; i < nsyms; ++i)
-    {
-	k = v[i]->index;
-	symbol_name[k] = v[i]->name;
-	symbol_value[k] = v[i]->value;
-	symbol_prec[k] = v[i]->prec;
-	symbol_assoc[k] = v[i]->assoc;
-    }
-
-    FREE(v);
-}
-
-
-pack_grammar()
-{
-    register int i, j;
-    int assoc, prec;
-
-    ritem = (short *) MALLOC(nitems*sizeof(short));
-    if (ritem == 0) no_space();
-    rlhs = (short *) MALLOC(nrules*sizeof(short));
-    if (rlhs == 0) no_space();
-    rrhs = (short *) MALLOC((nrules+1)*sizeof(short));
-    if (rrhs == 0) no_space();
-    rprec = (short *) REALLOC(rprec, nrules*sizeof(short));
-    if (rprec == 0) no_space();
-    rassoc = REALLOC(rassoc, nrules);
-    if (rassoc == 0) no_space();
-
-    ritem[0] = -1;
-    ritem[1] = goal->index;
-    ritem[2] = 0;
-    ritem[3] = -2;
-    rlhs[0] = 0;
-    rlhs[1] = 0;
-    rlhs[2] = start_symbol;
-    rrhs[0] = 0;
-    rrhs[1] = 0;
-    rrhs[2] = 1;
-
-    j = 4;
-    for (i = 3; i < nrules; ++i)
-    {
-	rlhs[i] = plhs[i]->index;
-	rrhs[i] = j;
-	assoc = TOKEN;
-	prec = 0;
-	while (pitem[j])
-	{
-	    ritem[j] = pitem[j]->index;
-	    if (pitem[j]->class == TERM)
-	    {
-		prec = pitem[j]->prec;
-		assoc = pitem[j]->assoc;
-	    }
-	    ++j;
-	}
-	ritem[j] = -i;
-	++j;
-	if (rprec[i] == UNDEFINED)
-	{
-	    rprec[i] = prec;
-	    rassoc[i] = assoc;
-	}
-    }
-    rrhs[i] = j;
-
-    FREE(plhs);
-    FREE(pitem);
-}
-
-
-print_grammar()
-{
-    register int i, j, k;
-    int spacing;
-    register FILE *f = verbose_file;
-
-    if (!vflag) return;
-
-    k = 1;
-    for (i = 2; i < nrules; ++i)
-    {
-	if (rlhs[i] != rlhs[i-1])
-	{
-	    if (i != 2) fprintf(f, "\n");
-	    fprintf(f, "%4d  %s :", i - 2, symbol_name[rlhs[i]]);
-	    spacing = strlen(symbol_name[rlhs[i]]) + 1;
-	}
-	else
-	{
-	    fprintf(f, "%4d  ", i - 2);
-	    j = spacing;
-	    while (--j >= 0) putc(' ', f);
-	    putc('|', f);
-	}
-
-	while (ritem[k] >= 0)
-	{
-	    fprintf(f, " %s", symbol_name[ritem[k]]);
-	    ++k;
-	}
-	++k;
-	putc('\n', f);
-    }
-}
-
-
-reader()
-{
-    write_section(banner);
-    create_symbol_table();
-    read_declarations();
-    read_grammar();
-    free_symbol_table();
-    free_tags();
-    pack_names();
-    check_symbols();
-    pack_symbols();
-    pack_grammar();
-    free_symbols();
-    print_grammar();
-}
Index: trunk/minix/commands/byacc/skeleton.c
===================================================================
--- trunk/minix/commands/byacc/skeleton.c	(revision 9)
+++ 	(revision )
@@ -1,306 +1,0 @@
-#include "defs.h"
-
-/*  The definition of yysccsid in the banner should be replaced with	*/
-/*  a #pragma ident directive if the target C compiler supports		*/
-/*  #pragma ident directives.						*/
-/*									*/
-/*  If the skeleton is changed, the banner should be changed so that	*/
-/*  the altered version can be easily distinguished from the original.	*/
-/*									*/
-/*  The #defines included with the banner are there because they are	*/
-/*  useful in subsequent code.  The macros #defined in the header or	*/
-/*  the body either are not useful outside of semantic actions or	*/
-/*  are conditional.							*/
-
-char *banner[] =
-{
-    "#ifndef lint",
-    "static char yysccsid[] = \"@(#)yaccpar	1.9 (Berkeley) 02/21/93\";",
-    "#endif",
-    "#define YYBYACC 1",
-    "#define YYMAJOR 1",
-    "#define YYMINOR 9",
-    "#define yyclearin (yychar=(-1))",
-    "#define yyerrok (yyerrflag=0)",
-    "#define YYRECOVERING (yyerrflag!=0)",
-    0
-};
-
-
-char *tables[] =
-{
-    "extern short yylhs[];",
-    "extern short yylen[];",
-    "extern short yydefred[];",
-    "extern short yydgoto[];",
-    "extern short yysindex[];",
-    "extern short yyrindex[];",
-    "extern short yygindex[];",
-    "extern short yytable[];",
-    "extern short yycheck[];",
-    "#if YYDEBUG",
-    "extern char *yyname[];",
-    "extern char *yyrule[];",
-    "#endif",
-    0
-};
-
-
-char *header[] =
-{
-    "#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",
-    0
-};
-
-
-char *body[] =
-{
-    "#define YYABORT goto yyabort",
-    "#define YYREJECT goto yyabort",
-    "#define YYACCEPT goto yyaccept",
-    "#define YYERROR goto yyerrlab",
-    "int",
-    "yyparse()",
-    "{",
-    "    register int yym, yyn, yystate;",
-    "#if YYDEBUG",
-    "    register char *yys;",
-    "    extern char *getenv();",
-    "",
-    "    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]) 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;",
-    "#ifdef lint",
-    "    goto yynewerror;",
-    "#endif",
-    "yynewerror:",
-    "    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)",
-    "    {",
-    0
-};
-
-
-char *trailer[] =
-{
-    "    }",
-    "    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);",
-    "}",
-    0
-};
-
-
-write_section(section)
-char *section[];
-{
-    register int c;
-    register int i;
-    register char *s;
-    register FILE *f;
-
-    f = code_file;
-    for (i = 0; s = section[i]; ++i)
-    {
-	++outline;
-	while (c = *s)
-	{
-	    putc(c, f);
-	    ++s;
-	}
-	putc('\n', f);
-    }
-}
Index: trunk/minix/commands/byacc/symtab.c
===================================================================
--- trunk/minix/commands/byacc/symtab.c	(revision 9)
+++ 	(revision )
@@ -1,119 +1,0 @@
-#include "defs.h"
-
-
-/* TABLE_SIZE is the number of entries in the symbol table. */
-/* TABLE_SIZE must be a power of two.			    */
-
-#define	TABLE_SIZE 1024
-
-
-bucket **symbol_table;
-bucket *first_symbol;
-bucket *last_symbol;
-
-
-int
-hash(name)
-char *name;
-{
-    register char *s;
-    register int c, k;
-
-    assert(name && *name);
-    s = name;
-    k = *s;
-    while (c = *++s)
-	k = (31*k + c) & (TABLE_SIZE - 1);
-
-    return (k);
-}
-
-
-bucket *
-make_bucket(name)
-char *name;
-{
-    register bucket *bp;
-
-    assert(name);
-    bp = (bucket *) MALLOC(sizeof(bucket));
-    if (bp == 0) no_space();
-    bp->link = 0;
-    bp->next = 0;
-    bp->name = MALLOC(strlen(name) + 1);
-    if (bp->name == 0) no_space();
-    bp->tag = 0;
-    bp->value = UNDEFINED;
-    bp->index = 0;
-    bp->prec = 0;
-    bp-> class = UNKNOWN;
-    bp->assoc = TOKEN;
-
-    if (bp->name == 0) no_space();
-    strcpy(bp->name, name);
-
-    return (bp);
-}
-
-
-bucket *
-lookup(name)
-char *name;
-{
-    register bucket *bp, **bpp;
-
-    bpp = symbol_table + hash(name);
-    bp = *bpp;
-
-    while (bp)
-    {
-	if (strcmp(name, bp->name) == 0) return (bp);
-	bpp = &bp->link;
-	bp = *bpp;
-    }
-
-    *bpp = bp = make_bucket(name);
-    last_symbol->next = bp;
-    last_symbol = bp;
-
-    return (bp);
-}
-
-
-create_symbol_table()
-{
-    register int i;
-    register bucket *bp;
-
-    symbol_table = (bucket **) MALLOC(TABLE_SIZE*sizeof(bucket *));
-    if (symbol_table == 0) no_space();
-    for (i = 0; i < TABLE_SIZE; i++)
-	symbol_table[i] = 0;
-
-    bp = make_bucket("error");
-    bp->index = 1;
-    bp->class = TERM;
-
-    first_symbol = bp;
-    last_symbol = bp;
-    symbol_table[hash("error")] = bp;
-}
-
-
-free_symbol_table()
-{
-    FREE(symbol_table);
-    symbol_table = 0;
-}
-
-
-free_symbols()
-{
-    register bucket *p, *q;
-
-    for (p = first_symbol; p; p = q)
-    {
-	q = p->next;
-	FREE(p);
-    }
-}
Index: trunk/minix/commands/byacc/verbose.c
===================================================================
--- trunk/minix/commands/byacc/verbose.c	(revision 9)
+++ 	(revision )
@@ -1,329 +1,0 @@
-
-#include "defs.h"
-
-
-static short *null_rules;
-
-verbose()
-{
-    register int i;
-
-    if (!vflag) return;
-
-    null_rules = (short *) MALLOC(nrules*sizeof(short));
-    if (null_rules == 0) no_space();
-    fprintf(verbose_file, "\f\n");
-    for (i = 0; i < nstates; i++)
-	print_state(i);
-    FREE(null_rules);
-
-    if (nunused)
-	log_unused();
-    if (SRtotal || RRtotal)
-	log_conflicts();
-
-    fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
-	    nvars);
-    fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates);
-}
-
-
-log_unused()
-{
-    register int i;
-    register short *p;
-
-    fprintf(verbose_file, "\n\nRules never reduced:\n");
-    for (i = 3; i < nrules; ++i)
-    {
-	if (!rules_used[i])
-	{
-	    fprintf(verbose_file, "\t%s :", symbol_name[rlhs[i]]);
-	    for (p = ritem + rrhs[i]; *p >= 0; ++p)
-		fprintf(verbose_file, " %s", symbol_name[*p]);
-	    fprintf(verbose_file, "  (%d)\n", i - 2);
-	}
-    }
-}
-
-
-log_conflicts()
-{
-    register int i;
-
-    fprintf(verbose_file, "\n\n");
-    for (i = 0; i < nstates; i++)
-    {
-	if (SRconflicts[i] || RRconflicts[i])
-	{
-	    fprintf(verbose_file, "State %d contains ", i);
-	    if (SRconflicts[i] == 1)
-		fprintf(verbose_file, "1 shift/reduce conflict");
-	    else if (SRconflicts[i] > 1)
-		fprintf(verbose_file, "%d shift/reduce conflicts",
-			SRconflicts[i]);
-	    if (SRconflicts[i] && RRconflicts[i])
-		fprintf(verbose_file, ", ");
-	    if (RRconflicts[i] == 1)
-		fprintf(verbose_file, "1 reduce/reduce conflict");
-	    else if (RRconflicts[i] > 1)
-		fprintf(verbose_file, "%d reduce/reduce conflicts",
-			RRconflicts[i]);
-	    fprintf(verbose_file, ".\n");
-	}
-    }
-}
-
-
-print_state(state)
-int state;
-{
-    if (state)
-	fprintf(verbose_file, "\n\n");
-    if (SRconflicts[state] || RRconflicts[state])
-	print_conflicts(state);
-    fprintf(verbose_file, "state %d\n", state);
-    print_core(state);
-    print_nulls(state);
-    print_actions(state);
-}
-
-
-print_conflicts(state)
-int state;
-{
-    register int symbol, act, number;
-    register action *p;
-
-    symbol = -1;
-    for (p = parser[state]; p; p = p->next)
-    {
-	if (p->suppressed == 2)
-	    continue;
-
-	if (p->symbol != symbol)
-	{
-	    symbol = p->symbol;
-	    number = p->number;
-	    if (p->action_code == SHIFT)
-		act = SHIFT;
-	    else
-		act = REDUCE;
-	}
-	else if (p->suppressed == 1)
-	{
-	    if (state == final_state && symbol == 0)
-	    {
-		fprintf(verbose_file, "%d: shift/reduce conflict \
-(accept, reduce %d) on $end\n", state, p->number - 2);
-	    }
-	    else
-	    {
-		if (act == SHIFT)
-		{
-		    fprintf(verbose_file, "%d: shift/reduce conflict \
-(shift %d, reduce %d) on %s\n", state, number, p->number - 2,
-			    symbol_name[symbol]);
-		}
-		else
-		{
-		    fprintf(verbose_file, "%d: reduce/reduce conflict \
-(reduce %d, reduce %d) on %s\n", state, number - 2, p->number - 2,
-			    symbol_name[symbol]);
-		}
-	    }
-	}
-    }
-}
-
-
-print_core(state)
-int state;
-{
-    register int i;
-    register int k;
-    register int rule;
-    register core *statep;
-    register short *sp;
-    register short *sp1;
-
-    statep = state_table[state];
-    k = statep->nitems;
-
-    for (i = 0; i < k; i++)
-    {
-	sp1 = sp = ritem + statep->items[i];
-
-	while (*sp >= 0) ++sp;
-	rule = -(*sp);
-	fprintf(verbose_file, "\t%s : ", symbol_name[rlhs[rule]]);
-
-        for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
-	    fprintf(verbose_file, "%s ", symbol_name[*sp]);
-
-	putc('.', verbose_file);
-
-	while (*sp >= 0)
-	{
-	    fprintf(verbose_file, " %s", symbol_name[*sp]);
-	    sp++;
-	}
-	fprintf(verbose_file, "  (%d)\n", -2 - *sp);
-    }
-}
-
-
-print_nulls(state)
-int state;
-{
-    register action *p;
-    register int i, j, k, nnulls;
-
-    nnulls = 0;
-    for (p = parser[state]; p; p = p->next)
-    {
-	if (p->action_code == REDUCE &&
-		(p->suppressed == 0 || p->suppressed == 1))
-	{
-	    i = p->number;
-	    if (rrhs[i] + 1 == rrhs[i+1])
-	    {
-		for (j = 0; j < nnulls && i > null_rules[j]; ++j)
-		    continue;
-
-		if (j == nnulls)
-		{
-		    ++nnulls;
-		    null_rules[j] = i;
-		}
-		else if (i != null_rules[j])
-		{
-		    ++nnulls;
-		    for (k = nnulls - 1; k > j; --k)
-			null_rules[k] = null_rules[k-1];
-		    null_rules[j] = i;
-		}
-	    }
-	}
-    }
-
-    for (i = 0; i < nnulls; ++i)
-    {
-	j = null_rules[i];
-	fprintf(verbose_file, "\t%s : .  (%d)\n", symbol_name[rlhs[j]],
-		j - 2);
-    }
-    fprintf(verbose_file, "\n");
-}
-
-
-print_actions(stateno)
-int stateno;
-{
-    register action *p;
-    register shifts *sp;
-    register int as;
-
-    if (stateno == final_state)
-	fprintf(verbose_file, "\t$end  accept\n");
-
-    p = parser[stateno];
-    if (p)
-    {
-	print_shifts(p);
-	print_reductions(p, defred[stateno]);
-    }
-
-    sp = shift_table[stateno];
-    if (sp && sp->nshifts > 0)
-    {
-	as = accessing_symbol[sp->shift[sp->nshifts - 1]];
-	if (ISVAR(as))
-	    print_gotos(stateno);
-    }
-}
-
-
-print_shifts(p)
-register action *p;
-{
-    register int count;
-    register action *q;
-
-    count = 0;
-    for (q = p; q; q = q->next)
-    {
-	if (q->suppressed < 2 && q->action_code == SHIFT)
-	    ++count;
-    }
-
-    if (count > 0)
-    {
-	for (; p; p = p->next)
-	{
-	    if (p->action_code == SHIFT && p->suppressed == 0)
-		fprintf(verbose_file, "\t%s  shift %d\n",
-			    symbol_name[p->symbol], p->number);
-	}
-    }
-}
-
-
-print_reductions(p, defred)
-register action *p;
-register int defred;
-{
-    register int k, anyreds;
-    register action *q;
-
-    anyreds = 0;
-    for (q = p; q ; q = q->next)
-    {
-	if (q->action_code == REDUCE && q->suppressed < 2)
-	{
-	    anyreds = 1;
-	    break;
-	}
-    }
-
-    if (anyreds == 0)
-	fprintf(verbose_file, "\t.  error\n");
-    else
-    {
-	for (; p; p = p->next)
-	{
-	    if (p->action_code == REDUCE && p->number != defred)
-	    {
-		k = p->number - 2;
-		if (p->suppressed == 0)
-		    fprintf(verbose_file, "\t%s  reduce %d\n",
-			    symbol_name[p->symbol], k);
-	    }
-	}
-
-        if (defred > 0)
-	    fprintf(verbose_file, "\t.  reduce %d\n", defred - 2);
-    }
-}
-
-
-print_gotos(stateno)
-int stateno;
-{
-    register int i, k;
-    register int as;
-    register short *to_state;
-    register shifts *sp;
-
-    putc('\n', verbose_file);
-    sp = shift_table[stateno];
-    to_state = sp->shift;
-    for (i = 0; i < sp->nshifts; ++i)
-    {
-	k = to_state[i];
-	as = accessing_symbol[k];
-	if (ISVAR(as))
-	    fprintf(verbose_file, "\t%s  goto %d\n", symbol_name[as], k);
-    }
-}
-
Index: trunk/minix/commands/byacc/warshall.c
===================================================================
--- trunk/minix/commands/byacc/warshall.c	(revision 9)
+++ 	(revision )
@@ -1,82 +1,0 @@
-#include "defs.h"
-
-transitive_closure(R, n)
-unsigned *R;
-int n;
-{
-    register int rowsize;
-    register unsigned i;
-    register unsigned *rowj;
-    register unsigned *rp;
-    register unsigned *rend;
-    register unsigned *ccol;
-    register unsigned *relend;
-    register unsigned *cword;
-    register unsigned *rowi;
-
-    rowsize = WORDSIZE(n);
-    relend = R + n*rowsize;
-
-    cword = R;
-    i = 0;
-    rowi = R;
-    while (rowi < relend)
-    {
-	ccol = cword;
-	rowj = R;
-
-	while (rowj < relend)
-	{
-	    if (*ccol & (1 << i))
-	    {
-		rp = rowi;
-		rend = rowj + rowsize;
-		while (rowj < rend)
-		    *rowj++ |= *rp++;
-	    }
-	    else
-	    {
-		rowj += rowsize;
-	    }
-
-	    ccol += rowsize;
-	}
-
-	if (++i >= BITS_PER_WORD)
-	{
-	    i = 0;
-	    cword++;
-	}
-
-	rowi += rowsize;
-    }
-}
-
-reflexive_transitive_closure(R, n)
-unsigned *R;
-int n;
-{
-    register int rowsize;
-    register unsigned i;
-    register unsigned *rp;
-    register unsigned *relend;
-
-    transitive_closure(R, n);
-
-    rowsize = WORDSIZE(n);
-    relend = R + n*rowsize;
-
-    i = 0;
-    rp = R;
-    while (rp < relend)
-    {
-	*rp |= (1 << i);
-	if (++i >= BITS_PER_WORD)
-	{
-	    i = 0;
-	    rp++;
-	}
-
-	rp += rowsize;
-    }
-}
Index: trunk/minix/commands/bzip2-1.0.3/CHANGES
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/CHANGES	(revision 9)
+++ 	(revision )
@@ -1,275 +1,0 @@
-
-
-0.9.0
-~~~~~
-First version.
-
-
-0.9.0a
-~~~~~~
-Removed 'ranlib' from Makefile, since most modern Unix-es 
-don't need it, or even know about it.
-
-
-0.9.0b
-~~~~~~
-Fixed a problem with error reporting in bzip2.c.  This does not effect
-the library in any way.  Problem is: versions 0.9.0 and 0.9.0a (of the
-program proper) compress and decompress correctly, but give misleading
-error messages (internal panics) when an I/O error occurs, instead of
-reporting the problem correctly.  This shouldn't give any data loss
-(as far as I can see), but is confusing.
-
-Made the inline declarations disappear for non-GCC compilers.
-
-
-0.9.0c
-~~~~~~
-Fixed some problems in the library pertaining to some boundary cases.
-This makes the library behave more correctly in those situations.  The
-fixes apply only to features (calls and parameters) not used by
-bzip2.c, so the non-fixedness of them in previous versions has no
-effect on reliability of bzip2.c.
-
-In bzlib.c:
-   * made zero-length BZ_FLUSH work correctly in bzCompress().
-   * fixed bzWrite/bzRead to ignore zero-length requests.
-   * fixed bzread to correctly handle read requests after EOF.
-   * wrong parameter order in call to bzDecompressInit in
-     bzBuffToBuffDecompress.  Fixed.
-
-In compress.c:
-   * changed setting of nGroups in sendMTFValues() so as to 
-     do a bit better on small files.  This _does_ effect
-     bzip2.c.
-
-
-0.9.5a
-~~~~~~
-Major change: add a fallback sorting algorithm (blocksort.c)
-to give reasonable behaviour even for very repetitive inputs.
-Nuked --repetitive-best and --repetitive-fast since they are
-no longer useful.
-
-Minor changes: mostly a whole bunch of small changes/
-bugfixes in the driver (bzip2.c).  Changes pertaining to the
-user interface are:
-
-   allow decompression of symlink'd files to stdout
-   decompress/test files even without .bz2 extension
-   give more accurate error messages for I/O errors
-   when compressing/decompressing to stdout, don't catch control-C
-   read flags from BZIP2 and BZIP environment variables
-   decline to break hard links to a file unless forced with -f
-   allow -c flag even with no filenames
-   preserve file ownerships as far as possible
-   make -s -1 give the expected block size (100k)
-   add a flag -q --quiet to suppress nonessential warnings
-   stop decoding flags after --, so files beginning in - can be handled
-   resolved inconsistent naming: bzcat or bz2cat ?
-   bzip2 --help now returns 0
-
-Programming-level changes are:
-
-   fixed syntax error in GET_LL4 for Borland C++ 5.02
-   let bzBuffToBuffDecompress return BZ_DATA_ERROR{_MAGIC}
-   fix overshoot of mode-string end in bzopen_or_bzdopen
-   wrapped bzlib.h in #ifdef __cplusplus ... extern "C" { ... }
-   close file handles under all error conditions
-   added minor mods so it compiles with DJGPP out of the box
-   fixed Makefile so it doesn't give problems with BSD make
-   fix uninitialised memory reads in dlltest.c
-
-0.9.5b
-~~~~~~
-Open stdin/stdout in binary mode for DJGPP.
-
-0.9.5c
-~~~~~~
-Changed BZ_N_OVERSHOOT to be ... + 2 instead of ... + 1.  The + 1
-version could cause the sorted order to be wrong in some extremely
-obscure cases.  Also changed setting of quadrant in blocksort.c.
-
-0.9.5d
-~~~~~~
-The only functional change is to make bzlibVersion() in the library
-return the correct string.  This has no effect whatsoever on the
-functioning of the bzip2 program or library.  Added a couple of casts
-so the library compiles without warnings at level 3 in MS Visual
-Studio 6.0.  Included a Y2K statement in the file Y2K_INFO.  All other
-changes are minor documentation changes.
-
-1.0
-~~~
-Several minor bugfixes and enhancements:
-
-* Large file support.  The library uses 64-bit counters to
-  count the volume of data passing through it.  bzip2.c 
-  is now compiled with -D_FILE_OFFSET_BITS=64 to get large
-  file support from the C library.  -v correctly prints out
-  file sizes greater than 4 gigabytes.  All these changes have
-  been made without assuming a 64-bit platform or a C compiler
-  which supports 64-bit ints, so, except for the C library
-  aspect, they are fully portable.
-
-* Decompression robustness.  The library/program should be
-  robust to any corruption of compressed data, detecting and
-  handling _all_ corruption, instead of merely relying on
-  the CRCs.  What this means is that the program should 
-  never crash, given corrupted data, and the library should
-  always return BZ_DATA_ERROR.
-
-* Fixed an obscure race-condition bug only ever observed on
-  Solaris, in which, if you were very unlucky and issued
-  control-C at exactly the wrong time, both input and output
-  files would be deleted.
-
-* Don't run out of file handles on test/decompression when
-  large numbers of files have invalid magic numbers.
-
-* Avoid library namespace pollution.  Prefix all exported 
-  symbols with BZ2_.
-
-* Minor sorting enhancements from my DCC2000 paper.
-
-* Advance the version number to 1.0, so as to counteract the
-  (false-in-this-case) impression some people have that programs 
-  with version numbers less than 1.0 are in some way, experimental,
-  pre-release versions.
-
-* Create an initial Makefile-libbz2_so to build a shared library.
-  Yes, I know I should really use libtool et al ...
-
-* Make the program exit with 2 instead of 0 when decompression
-  fails due to a bad magic number (ie, an invalid bzip2 header).
-  Also exit with 1 (as the manual claims :-) whenever a diagnostic
-  message would have been printed AND the corresponding operation 
-  is aborted, for example
-     bzip2: Output file xx already exists.
-  When a diagnostic message is printed but the operation is not 
-  aborted, for example
-     bzip2: Can't guess original name for wurble -- using wurble.out
-  then the exit value 0 is returned, unless some other problem is
-  also detected.
-
-  I think it corresponds more closely to what the manual claims now.
-
-
-1.0.1
-~~~~~
-* Modified dlltest.c so it uses the new BZ2_ naming scheme.
-* Modified makefile-msc to fix minor build probs on Win2k.
-* Updated README.COMPILATION.PROBLEMS.
-
-There are no functionality changes or bug fixes relative to version
-1.0.0.  This is just a documentation update + a fix for minor Win32
-build problems.  For almost everyone, upgrading from 1.0.0 to 1.0.1 is
-utterly pointless.  Don't bother.
-
-
-1.0.2
-~~~~~
-A bug fix release, addressing various minor issues which have appeared
-in the 18 or so months since 1.0.1 was released.  Most of the fixes
-are to do with file-handling or documentation bugs.  To the best of my
-knowledge, there have been no data-loss-causing bugs reported in the
-compression/decompression engine of 1.0.0 or 1.0.1.
-
-Note that this release does not improve the rather crude build system
-for Unix platforms.  The general plan here is to autoconfiscate/
-libtoolise 1.0.2 soon after release, and release the result as 1.1.0
-or perhaps 1.2.0.  That, however, is still just a plan at this point.
-
-Here are the changes in 1.0.2.  Bug-reporters and/or patch-senders in
-parentheses.
-
-* Fix an infinite segfault loop in 1.0.1 when a directory is
-  encountered in -f (force) mode.
-     (Trond Eivind Glomsrod, Nicholas Nethercote, Volker Schmidt)
-
-* Avoid double fclose() of output file on certain I/O error paths.
-     (Solar Designer)
-
-* Don't fail with internal error 1007 when fed a long stream (> 48MB)
-  of byte 251.  Also print useful message suggesting that 1007s may be
-  caused by bad memory.
-     (noticed by Juan Pedro Vallejo, fixed by me)
-
-* Fix uninitialised variable silly bug in demo prog dlltest.c.
-     (Jorj Bauer)
-
-* Remove 512-MB limitation on recovered file size for bzip2recover
-  on selected platforms which support 64-bit ints.  At the moment
-  all GCC supported platforms, and Win32.
-     (me, Alson van der Meulen)
-
-* Hard-code header byte values, to give correct operation on platforms
-  using EBCDIC as their native character set (IBM's OS/390).
-     (Leland Lucius)
-
-* Copy file access times correctly.
-     (Marty Leisner)
-
-* Add distclean and check targets to Makefile.
-     (Michael Carmack)
-
-* Parameterise use of ar and ranlib in Makefile.  Also add $(LDFLAGS).
-     (Rich Ireland, Bo Thorsen)
-
-* Pass -p (create parent dirs as needed) to mkdir during make install.
-     (Jeremy Fusco)
-
-* Dereference symlinks when copying file permissions in -f mode.
-     (Volker Schmidt)
-
-* Majorly simplify implementation of uInt64_qrm10.
-     (Bo Lindbergh)
-
-* Check the input file still exists before deleting the output one,
-  when aborting in cleanUpAndFail().
-     (Joerg Prante, Robert Linden, Matthias Krings)
-
-Also a bunch of patches courtesy of Philippe Troin, the Debian maintainer
-of bzip2:
-
-* Wrapper scripts (with manpages): bzdiff, bzgrep, bzmore.
-
-* Spelling changes and minor enhancements in bzip2.1.
-
-* Avoid race condition between creating the output file and setting its
-  interim permissions safely, by using fopen_output_safely().
-  No changes to bzip2recover since there is no issue with file
-  permissions there.
-
-* do not print senseless report with -v when compressing an empty
-  file.
-
-* bzcat -f works on non-bzip2 files.
-
-* do not try to escape shell meta-characters on unix (the shell takes
-  care of these).
-
-* added --fast and --best aliases for -1 -9 for gzip compatibility.
-
-
-1.0.3 (15 Feb 05)
-~~~~~~~~~~~~~~~~~
-Fixes some minor bugs since the last version, 1.0.2.
-
-* Further robustification against corrupted compressed data.
-  There are currently no known bitstreams which can cause the
-  decompressor to crash, loop or access memory which does not
-  belong to it.  If you are using bzip2 or the library to 
-  decompress bitstreams from untrusted sources, an upgrade
-  to 1.0.3 is recommended.
-
-* The documentation has been converted to XML, from which html
-  and pdf can be derived.
-
-* Various minor bugs in the documentation have been fixed.
-
-* Fixes for various compilation warnings with newer versions of
-  gcc, and on 64-bit platforms.
-
-* The BZ_NO_STDIO cpp symbol was not properly observed in 1.0.2.
-  This has been fixed.
Index: trunk/minix/commands/bzip2-1.0.3/LICENSE
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/LICENSE	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-
-This program, "bzip2", the associated library "libbzip2", and all
-documentation, are copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-   not claim that you wrote the original software.  If you use this 
-   software in a product, an acknowledgment in the product 
-   documentation would be appreciated but is not required.
-
-3. Altered source versions must be plainly marked as such, and must
-   not be misrepresented as being the original software.
-
-4. 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.
-
-Julian Seward, Cambridge, UK.
-jseward@acm.org
-bzip2/libbzip2 version 1.0.3 of 15 February 2005
-
Index: trunk/minix/commands/bzip2-1.0.3/Makefile
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/Makefile	(revision 9)
+++ 	(revision )
@@ -1,216 +1,0 @@
-
-SHELL=/bin/sh
-
-# To assist in cross-compiling
-CC=exec cc
-AR=ar
-ARFLAGS=cr
-RANLIB=ranlib
-LDFLAGS=
-
-BIGFILES=#-D_FILE_OFFSET_BITS=64
-CFLAGS=-Wall -Winline -O -g $(BIGFILES) -Dlstat=stat -D_POSIX_SOURCE=1
-
-# Where you want it installed when you do 'make install'
-PREFIX=/usr/local
-PREFIX_BIN=$(PREFIX)/bin
-PREFIX_LIB=$(PREFIX)/lib
-PREFIX_MAN=$(PREFIX)/man
-PREFIX_INC=$(PREFIX)/include
-
-
-OBJS= blocksort.o  \
-      huffman.o    \
-      crctable.o   \
-      randtable.o  \
-      compress.o   \
-      decompress.o \
-      bzlib.o
-
-all: all_notest
-
-all_notest: libbz2.a bzip2 bzip2recover 
-	chmem =8000000 bzip2
-
-bzip2: libbz2.a bzip2.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
-
-bzip2recover: bzip2recover.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover bzip2recover.o
-
-libbz2.a: $(OBJS)
-	rm -f libbz2.a
-	$(AR) $(ARFLAGS) libbz2.a $(OBJS)
-	@if ( test -f $(RANLIB) -o -f /usr/bin/ranlib -o \
-		-f /bin/ranlib -o -f /usr/ccs/bin/ranlib ) ; then \
-		echo $(RANLIB) libbz2.a ; \
-		$(RANLIB) libbz2.a ; \
-	fi
-
-check: test
-test: bzip2 test_nodep
-
-test_nodep:
-	@cat words1
-	./bzip2 -1  < sample1.ref > sample1.rb2
-	./bzip2 -2  < sample2.ref > sample2.rb2
-	./bzip2 -3  < sample3.ref > sample3.rb2
-	./bzip2 -d  < sample1.bz2 > sample1.tst
-	./bzip2 -d  < sample2.bz2 > sample2.tst
-	./bzip2 -ds < sample3.bz2 > sample3.tst
-	cmp sample1.bz2 sample1.rb2 
-	cmp sample2.bz2 sample2.rb2
-	cmp sample3.bz2 sample3.rb2
-	cmp sample1.tst sample1.ref
-	cmp sample2.tst sample2.ref
-	cmp sample3.tst sample3.ref
-	@cat words3
-
-install: bzip2 bzip2recover
-	if ( test ! -d $(PREFIX_BIN) ) ; then mkdir -p $(PREFIX_BIN) ; fi
-	if ( test ! -d $(PREFIX_LIB) ) ; then mkdir -p $(PREFIX_LIB) ; fi
-	if ( test ! -d $(PREFIX_MAN) ) ; then mkdir -p $(PREFIX_MAN) ; fi
-	if ( test ! -d $(PREFIX_MAN)/man1 ) ; then mkdir -p $(PREFIX_MAN)/man1 ; fi
-	if ( test ! -d $(PREFIX_INC) ) ; then mkdir -p $(PREFIX_INC) ; fi
-	install -S 8M -o bin bzip2 $(PREFIX_BIN)/bzip2
-	install -S 4M -o bin bzip2 $(PREFIX_BIN)/bunzip2
-	install -S 2450k -o bin bzip2 $(PREFIX_BIN)/smallbunzip2
-	install -o bin bzip2 $(PREFIX_BIN)/bzcat
-	install -o bin bzip2recover $(PREFIX_BIN)/bzip2recover
-	chmod a+x $(PREFIX_BIN)/bzip2
-	chmod a+x $(PREFIX_BIN)/bunzip2
-	chmod a+x $(PREFIX_BIN)/bzcat
-	chmod a+x $(PREFIX_BIN)/bzip2recover
-	install -o bin bzip2.1 $(PREFIX_MAN)/man1
-	chmod a+r $(PREFIX_MAN)/man1/bzip2.1
-	install -o bin bzlib.h $(PREFIX_INC)
-	chmod a+r $(PREFIX_INC)/bzlib.h
-	install -o bin libbz2.a $(PREFIX_LIB)
-	chmod a+r $(PREFIX_LIB)/libbz2.a
-	install -o bin bzgrep $(PREFIX_BIN)/bzgrep
-	ln -f $(PREFIX_BIN)/bzgrep $(PREFIX_BIN)/bzegrep
-	ln -f $(PREFIX_BIN)/bzgrep $(PREFIX_BIN)/bzfgrep
-	chmod a+x $(PREFIX_BIN)/bzgrep
-	install -o bin bzmore $(PREFIX_BIN)/bzmore
-	ln -f $(PREFIX_BIN)/bzmore $(PREFIX_BIN)/bzless
-	chmod a+x $(PREFIX_BIN)/bzmore
-	install -o bin bzdiff $(PREFIX_BIN)/bzdiff
-	ln -f $(PREFIX_BIN)/bzdiff $(PREFIX_BIN)/bzcmp
-	chmod a+x $(PREFIX_BIN)/bzdiff
-	install -o bin bzgrep.1 bzmore.1 bzdiff.1 $(PREFIX_MAN)/man1
-	chmod a+r $(PREFIX_MAN)/man1/bzgrep.1
-	chmod a+r $(PREFIX_MAN)/man1/bzmore.1
-	chmod a+r $(PREFIX_MAN)/man1/bzdiff.1
-	echo ".so man1/bzgrep.1" > $(PREFIX_MAN)/man1/bzegrep.1
-	echo ".so man1/bzgrep.1" > $(PREFIX_MAN)/man1/bzfgrep.1
-	echo ".so man1/bzmore.1" > $(PREFIX_MAN)/man1/bzless.1
-	echo ".so man1/bzdiff.1" > $(PREFIX_MAN)/man1/bzcmp.1
-
-clean: 
-	rm -f *.o libbz2.a bzip2 bzip2recover \
-	sample1.rb2 sample2.rb2 sample3.rb2 \
-	sample1.tst sample2.tst sample3.tst
-
-blocksort.o: blocksort.c
-	@cat words0
-	$(CC) $(CFLAGS) -c blocksort.c
-huffman.o: huffman.c
-	$(CC) $(CFLAGS) -c huffman.c
-crctable.o: crctable.c
-	$(CC) $(CFLAGS) -c crctable.c
-randtable.o: randtable.c
-	$(CC) $(CFLAGS) -c randtable.c
-compress.o: compress.c
-	$(CC) $(CFLAGS) -c compress.c
-decompress.o: decompress.c
-	$(CC) $(CFLAGS) -c decompress.c
-bzlib.o: bzlib.c
-	$(CC) $(CFLAGS) -c bzlib.c
-bzip2.o: bzip2.c
-	$(CC) $(CFLAGS) -c bzip2.c
-bzip2recover.o: bzip2recover.c
-	$(CC) $(CFLAGS) -c bzip2recover.c
-
-
-distclean: clean
-	rm -f manual.ps manual.html manual.pdf
-
-DISTNAME=bzip2-1.0.3
-dist: check manual
-	rm -f $(DISTNAME)
-	ln -sf . $(DISTNAME)
-	tar cvf $(DISTNAME).tar \
-	   $(DISTNAME)/blocksort.c \
-	   $(DISTNAME)/huffman.c \
-	   $(DISTNAME)/crctable.c \
-	   $(DISTNAME)/randtable.c \
-	   $(DISTNAME)/compress.c \
-	   $(DISTNAME)/decompress.c \
-	   $(DISTNAME)/bzlib.c \
-	   $(DISTNAME)/bzip2.c \
-	   $(DISTNAME)/bzip2recover.c \
-	   $(DISTNAME)/bzlib.h \
-	   $(DISTNAME)/bzlib_private.h \
-	   $(DISTNAME)/Makefile \
-	   $(DISTNAME)/LICENSE \
-	   $(DISTNAME)/bzip2.1 \
-	   $(DISTNAME)/bzip2.1.preformatted \
-	   $(DISTNAME)/bzip2.txt \
-	   $(DISTNAME)/words0 \
-	   $(DISTNAME)/words1 \
-	   $(DISTNAME)/words2 \
-	   $(DISTNAME)/words3 \
-	   $(DISTNAME)/sample1.ref \
-	   $(DISTNAME)/sample2.ref \
-	   $(DISTNAME)/sample3.ref \
-	   $(DISTNAME)/sample1.bz2 \
-	   $(DISTNAME)/sample2.bz2 \
-	   $(DISTNAME)/sample3.bz2 \
-	   $(DISTNAME)/dlltest.c \
-	   $(DISTNAME)/manual.html \
-	   $(DISTNAME)/manual.pdf \
-	   $(DISTNAME)/manual.ps \
-	   $(DISTNAME)/README \
-	   $(DISTNAME)/README.COMPILATION.PROBLEMS \
-	   $(DISTNAME)/README.XML.STUFF \
-	   $(DISTNAME)/CHANGES \
-	   $(DISTNAME)/libbz2.def \
-	   $(DISTNAME)/libbz2.dsp \
-	   $(DISTNAME)/dlltest.dsp \
-	   $(DISTNAME)/makefile.msc \
-	   $(DISTNAME)/Y2K_INFO \
-	   $(DISTNAME)/unzcrash.c \
-	   $(DISTNAME)/spewG.c \
-	   $(DISTNAME)/mk251.c \
-	   $(DISTNAME)/bzdiff \
-	   $(DISTNAME)/bzdiff.1 \
-	   $(DISTNAME)/bzmore \
-	   $(DISTNAME)/bzmore.1 \
-	   $(DISTNAME)/bzgrep \
-	   $(DISTNAME)/bzgrep.1 \
-	   $(DISTNAME)/Makefile-libbz2_so \
-	   $(DISTNAME)/bz-common.xsl \
-	   $(DISTNAME)/bz-fo.xsl \
-	   $(DISTNAME)/bz-html.xsl \
-	   $(DISTNAME)/bzip.css \
-	   $(DISTNAME)/entities.xml \
-	   $(DISTNAME)/manual.xml \
-	   $(DISTNAME)/format.pl \
-	   $(DISTNAME)/xmlproc.sh
-	gzip -v $(DISTNAME).tar
-
-# For rebuilding the manual from sources on my SuSE 9.1 box
-
-MANUAL_SRCS= 	bz-common.xsl bz-fo.xsl bz-html.xsl bzip.css \
-		entities.xml manual.xml 
-
-manual: manual.html manual.ps manual.pdf
-
-manual.ps: $(MANUAL_SRCS)
-	./xmlproc.sh -ps manual.xml
-
-manual.pdf: $(MANUAL_SRCS)
-	./xmlproc.sh -pdf manual.xml
-
-manual.html: $(MANUAL_SRCS)
-	./xmlproc.sh -html manual.xml
Index: trunk/minix/commands/bzip2-1.0.3/Makefile-libbz2_so
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/Makefile-libbz2_so	(revision 9)
+++ 	(revision )
@@ -1,44 +1,0 @@
-
-# This Makefile builds a shared version of the library, 
-# libbz2.so.1.0.3, with soname libbz2.so.1.0,
-# at least on x86-Linux (RedHat 7.2), 
-# with gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98).  
-# Please see the README file for some 
-# important info about building the library like this.
-
-SHELL=/bin/sh
-CC=gcc
-BIGFILES=-D_FILE_OFFSET_BITS=64
-CFLAGS=-fpic -fPIC -Wall -Winline -O -g
-
-OBJS= blocksort.o  \
-      huffman.o    \
-      crctable.o   \
-      randtable.o  \
-      compress.o   \
-      decompress.o \
-      bzlib.o
-
-all: $(OBJS)
-	$(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.3 $(OBJS)
-	$(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.3
-	rm -f libbz2.so.1.0
-	ln -s libbz2.so.1.0.3 libbz2.so.1.0
-
-clean: 
-	rm -f $(OBJS) bzip2.o libbz2.so.1.0.3 libbz2.so.1.0 bzip2-shared
-
-blocksort.o: blocksort.c
-	$(CC) $(CFLAGS) -c blocksort.c
-huffman.o: huffman.c
-	$(CC) $(CFLAGS) -c huffman.c
-crctable.o: crctable.c
-	$(CC) $(CFLAGS) -c crctable.c
-randtable.o: randtable.c
-	$(CC) $(CFLAGS) -c randtable.c
-compress.o: compress.c
-	$(CC) $(CFLAGS) -c compress.c
-decompress.o: decompress.c
-	$(CC) $(CFLAGS) -c decompress.c
-bzlib.o: bzlib.c
-	$(CC) $(CFLAGS) -c bzlib.c
Index: trunk/minix/commands/bzip2-1.0.3/README.COMPILATION.PROBLEMS
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/README.COMPILATION.PROBLEMS	(revision 9)
+++ 	(revision )
@@ -1,39 +1,0 @@
-
-bzip2-1.0.3 should compile without problems on the vast majority of
-platforms.  Using the supplied Makefile, I've built and tested it
-myself for x86-linux and x86_64-linux.  With makefile.msc, Visual C++
-6.0 and nmake, you can build a native Win32 version too.  Large file
-support seems to work correctly on at least alpha-tru64unix and
-x86-cygwin32 (on Windows 2000).
-
-When I say "large file" I mean a file of size 2,147,483,648 (2^31)
-bytes or above.  Many older OSs can't handle files above this size,
-but many newer ones can.  Large files are pretty huge -- most files
-you'll encounter are not Large Files.
-
-Earlier versions of bzip2 (0.1, 0.9.0, 0.9.5) compiled on a wide
-variety of platforms without difficulty, and I hope this version will
-continue in that tradition.  However, in order to support large files,
-I've had to include the define -D_FILE_OFFSET_BITS=64 in the Makefile.
-This can cause problems.
-
-The technique of adding -D_FILE_OFFSET_BITS=64 to get large file
-support is, as far as I know, the Recommended Way to get correct large
-file support.  For more details, see the Large File Support
-Specification, published by the Large File Summit, at
-   http://ftp.sas.com/standards/large.file
-
-As a general comment, if you get compilation errors which you think
-are related to large file support, try removing the above define from
-the Makefile, ie, delete the line
-   BIGFILES=-D_FILE_OFFSET_BITS=64 
-from the Makefile, and do 'make clean ; make'.  This will give you a
-version of bzip2 without large file support, which, for most
-applications, is probably not a problem.  
-
-Alternatively, try some of the platform-specific hints listed below.
-
-You can use the spewG.c program to generate huge files to test bzip2's
-large file support, if you are feeling paranoid.  Be aware though that
-any compilation problems which affect bzip2 will also affect spewG.c,
-alas.
Index: trunk/minix/commands/bzip2-1.0.3/README.MINIX
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/README.MINIX	(revision 9)
+++ 	(revision )
@@ -1,172 +1,0 @@
-###############################################################################
-# Quick installation
-###############################################################################
-
-To build and install bzip into /usr/local, execute the following commands 
-as user bin:
-
-make
-make install
-
-To install into another directory use:
-make install PREFIX=<path>
-
-###############################################################################
-# bzip 1.0.3 for Minix
-###############################################################################
-The text below is taken from the original README file. The original file is
-available as README.ORIGINAL.
-
-This is the README for bzip2, a block-sorting file compressor, version
-1.0.3.  This version is fully compatible with the previous public
-releases, versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1 and 1.0.2.
-
-bzip2-1.0.3 is distributed under a BSD-style license.  For details,
-see the file LICENSE.
-
-Complete documentation is available in Postscript form (manual.ps),
-PDF (manual.pdf) or html (manual.html).  A plain-text version of the
-manual page is available as bzip2.txt.  A statement about Y2K issues
-is now included in the file Y2K_INFO.
-
-
-HOW TO BUILD -- MINIX
-
-Type `make'.  This builds the library libbz2.a and then the
-programs bzip2 and bzip2recover.  Six self-tests are run.
-If the self-tests complete ok, carry on to installation:
-
-To install in /usr/local/bin, /usr/local/lib, /usr/local/man and 
-   /usr/local/include, type
-   make install
-To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type 
-   make install PREFIX=/xxx/yyy
-If you are (justifiably) paranoid and want to see what 'make install'
-is going to do, you can first do
-   make -n install                      or
-   make -n install PREFIX=/xxx/yyy      respectively.
-The -n instructs make to show the commands it would execute, but
-not actually execute them.
-
-VALIDATION
-
-Correct operation, in the sense that a compressed file can always be
-decompressed to reproduce the original, is obviously of paramount
-importance.  To validate bzip2, I used a modified version of Mark
-Nelson's churn program.  Churn is an automated test driver which
-recursively traverses a directory structure, using bzip2 to compress
-and then decompress each file it encounters, and checking that the
-decompressed data is the same as the original.
-
-
-
-Please read and be aware of the following:
-
-WARNING:
-
-   This program (attempts to) compress data by performing several
-   non-trivial transformations on it.  Unless you are 100% familiar
-   with *all* the algorithms contained herein, and with the
-   consequences of modifying them, you should NOT meddle with the
-   compression or decompression machinery.  Incorrect changes can and
-   very likely *will* lead to disastrous loss of data.
-
-
-DISCLAIMER:
-
-   I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
-   USE OF THIS PROGRAM, HOWSOEVER CAUSED.
-
-   Every compression of a file implies an assumption that the
-   compressed file can be decompressed to reproduce the original.
-   Great efforts in design, coding and testing have been made to
-   ensure that this program works correctly.  However, the complexity
-   of the algorithms, and, in particular, the presence of various
-   special cases in the code which occur with very low but non-zero
-   probability make it impossible to rule out the possibility of bugs
-   remaining in the program.  DO NOT COMPRESS ANY DATA WITH THIS
-   PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
-   SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
-
-   That is not to say this program is inherently unreliable.  Indeed,
-   I very much hope the opposite is true.  bzip2 has been carefully
-   constructed and extensively tested.
-
-
-PATENTS:
-
-   To the best of my knowledge, bzip2 does not use any patented
-   algorithms.  However, I do not have the resources to carry out
-   a patent search.  Therefore I cannot give any guarantee of the
-   above statement.
-
-End of legalities.
-
-
-WHAT'S NEW IN 0.9.0 (as compared to 0.1pl2) ?
-
-   * Approx 10% faster compression, 30% faster decompression
-   * -t (test mode) is a lot quicker
-   * Can decompress concatenated compressed files
-   * Programming interface, so programs can directly read/write .bz2 files
-   * Less restrictive (BSD-style) licensing
-   * Flag handling more compatible with GNU gzip
-   * Much more documentation, i.e., a proper user manual
-   * Hopefully, improved portability (at least of the library)
-
-WHAT'S NEW IN 0.9.5 ?
-
-   * Compression speed is much less sensitive to the input
-     data than in previous versions.  Specifically, the very
-     slow performance caused by repetitive data is fixed.
-   * Many small improvements in file and flag handling.
-   * A Y2K statement.
-
-WHAT'S NEW IN 1.0.0 ?
-
-   See the CHANGES file.
-
-WHAT'S NEW IN 1.0.2 ?
-
-   See the CHANGES file.
-
-WHAT'S NEW IN 1.0.3 ?
-
-   See the CHANGES file.
-
-
-I hope you find bzip2 useful.  Feel free to contact me at
-   jseward@bzip.org
-if you have any suggestions or queries.  Many people mailed me with
-comments, suggestions and patches after the releases of bzip-0.15,
-bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1 and
-1.0.2, and the changes in bzip2 are largely a result of this feedback.
-I thank you for your comments.
-
-At least for the time being, bzip2's "home" is (or can be reached via)
-http://www.bzip.org
-
-Julian Seward
-jseward@bzip.org
-
-Cambridge, UK.
-
-18     July 1996 (version 0.15)
-25   August 1996 (version 0.21)
- 7   August 1997 (bzip2, version 0.1)
-29   August 1997 (bzip2, version 0.1pl2)
-23   August 1998 (bzip2, version 0.9.0)
- 8     June 1999 (bzip2, version 0.9.5)
- 4     Sept 1999 (bzip2, version 0.9.5d)
- 5      May 2000 (bzip2, version 1.0pre8)
-30 December 2001 (bzip2, version 1.0.2pre1)
-15 February 2005 (bzip2, version 1.0.3)
-
-###############################################################################
-# Changes to the source of version 1.0.3
-###############################################################################
-- Changed default installation to /usr/local
-- Adjusted Makefile to separate testing from building, to allow chmem in
-  between
-- Adjusted invocation of ar, as Minix ar does not support -q, even though the
-  documentation says it does
Index: trunk/minix/commands/bzip2-1.0.3/README.ORIGINAL
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/README.ORIGINAL	(revision 9)
+++ 	(revision )
@@ -1,185 +1,0 @@
-
-This is the README for bzip2, a block-sorting file compressor, version
-1.0.3.  This version is fully compatible with the previous public
-releases, versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1 and 1.0.2.
-
-bzip2-1.0.3 is distributed under a BSD-style license.  For details,
-see the file LICENSE.
-
-Complete documentation is available in Postscript form (manual.ps),
-PDF (manual.pdf) or html (manual.html).  A plain-text version of the
-manual page is available as bzip2.txt.  A statement about Y2K issues
-is now included in the file Y2K_INFO.
-
-
-HOW TO BUILD -- UNIX
-
-Type `make'.  This builds the library libbz2.a and then the
-programs bzip2 and bzip2recover.  Six self-tests are run.
-If the self-tests complete ok, carry on to installation:
-
-To install in /usr/bin, /usr/lib, /usr/man and /usr/include, type
-   make install
-To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type 
-   make install PREFIX=/xxx/yyy
-If you are (justifiably) paranoid and want to see what 'make install'
-is going to do, you can first do
-   make -n install                      or
-   make -n install PREFIX=/xxx/yyy      respectively.
-The -n instructs make to show the commands it would execute, but
-not actually execute them.
-
-
-HOW TO BUILD -- UNIX, shared library libbz2.so.
-
-Do 'make -f Makefile-libbz2_so'.  This Makefile seems to work for
-Linux-ELF (RedHat 7.2 on an x86 box), with gcc.  I make no claims
-that it works for any other platform, though I suspect it probably
-will work for most platforms employing both ELF and gcc.
-
-bzip2-shared, a client of the shared library, is also built, but not
-self-tested.  So I suggest you also build using the normal Makefile,
-since that conducts a self-test.  A second reason to prefer the
-version statically linked to the library is that, on x86 platforms,
-building shared objects makes a valuable register (%ebx) unavailable
-to gcc, resulting in a slowdown of 10%-20%, at least for bzip2.
-
-Important note for people upgrading .so's from 0.9.0/0.9.5 to version
-1.0.X.  All the functions in the library have been renamed, from (eg)
-bzCompress to BZ2_bzCompress, to avoid namespace pollution.
-Unfortunately this means that the libbz2.so created by
-Makefile-libbz2_so will not work with any program which used an older
-version of the library.  Sorry.  I do encourage library clients to
-make the effort to upgrade to use version 1.0, since it is both faster
-and more robust than previous versions.
-
-
-HOW TO BUILD -- Windows 95, NT, DOS, Mac, etc.
-
-It's difficult for me to support compilation on all these platforms.
-My approach is to collect binaries for these platforms, and put them
-on the master web page (http://sources.redhat.com/bzip2).  Look there.
-However (FWIW), bzip2-1.0.X is very standard ANSI C and should compile
-unmodified with MS Visual C.  If you have difficulties building, you
-might want to read README.COMPILATION.PROBLEMS.
-
-At least using MS Visual C++ 6, you can build from the unmodified
-sources by issuing, in a command shell: 
-   nmake -f makefile.msc
-(you may need to first run the MSVC-provided script VCVARS32.BAT
- so as to set up paths to the MSVC tools correctly).
-
-
-VALIDATION
-
-Correct operation, in the sense that a compressed file can always be
-decompressed to reproduce the original, is obviously of paramount
-importance.  To validate bzip2, I used a modified version of Mark
-Nelson's churn program.  Churn is an automated test driver which
-recursively traverses a directory structure, using bzip2 to compress
-and then decompress each file it encounters, and checking that the
-decompressed data is the same as the original.
-
-
-
-Please read and be aware of the following:
-
-WARNING:
-
-   This program (attempts to) compress data by performing several
-   non-trivial transformations on it.  Unless you are 100% familiar
-   with *all* the algorithms contained herein, and with the
-   consequences of modifying them, you should NOT meddle with the
-   compression or decompression machinery.  Incorrect changes can and
-   very likely *will* lead to disastrous loss of data.
-
-
-DISCLAIMER:
-
-   I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
-   USE OF THIS PROGRAM, HOWSOEVER CAUSED.
-
-   Every compression of a file implies an assumption that the
-   compressed file can be decompressed to reproduce the original.
-   Great efforts in design, coding and testing have been made to
-   ensure that this program works correctly.  However, the complexity
-   of the algorithms, and, in particular, the presence of various
-   special cases in the code which occur with very low but non-zero
-   probability make it impossible to rule out the possibility of bugs
-   remaining in the program.  DO NOT COMPRESS ANY DATA WITH THIS
-   PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
-   SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
-
-   That is not to say this program is inherently unreliable.  Indeed,
-   I very much hope the opposite is true.  bzip2 has been carefully
-   constructed and extensively tested.
-
-
-PATENTS:
-
-   To the best of my knowledge, bzip2 does not use any patented
-   algorithms.  However, I do not have the resources to carry out
-   a patent search.  Therefore I cannot give any guarantee of the
-   above statement.
-
-End of legalities.
-
-
-WHAT'S NEW IN 0.9.0 (as compared to 0.1pl2) ?
-
-   * Approx 10% faster compression, 30% faster decompression
-   * -t (test mode) is a lot quicker
-   * Can decompress concatenated compressed files
-   * Programming interface, so programs can directly read/write .bz2 files
-   * Less restrictive (BSD-style) licensing
-   * Flag handling more compatible with GNU gzip
-   * Much more documentation, i.e., a proper user manual
-   * Hopefully, improved portability (at least of the library)
-
-WHAT'S NEW IN 0.9.5 ?
-
-   * Compression speed is much less sensitive to the input
-     data than in previous versions.  Specifically, the very
-     slow performance caused by repetitive data is fixed.
-   * Many small improvements in file and flag handling.
-   * A Y2K statement.
-
-WHAT'S NEW IN 1.0.0 ?
-
-   See the CHANGES file.
-
-WHAT'S NEW IN 1.0.2 ?
-
-   See the CHANGES file.
-
-WHAT'S NEW IN 1.0.3 ?
-
-   See the CHANGES file.
-
-
-I hope you find bzip2 useful.  Feel free to contact me at
-   jseward@bzip.org
-if you have any suggestions or queries.  Many people mailed me with
-comments, suggestions and patches after the releases of bzip-0.15,
-bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1 and
-1.0.2, and the changes in bzip2 are largely a result of this feedback.
-I thank you for your comments.
-
-At least for the time being, bzip2's "home" is (or can be reached via)
-http://www.bzip.org
-
-Julian Seward
-jseward@bzip.org
-
-Cambridge, UK.
-
-18     July 1996 (version 0.15)
-25   August 1996 (version 0.21)
- 7   August 1997 (bzip2, version 0.1)
-29   August 1997 (bzip2, version 0.1pl2)
-23   August 1998 (bzip2, version 0.9.0)
- 8     June 1999 (bzip2, version 0.9.5)
- 4     Sept 1999 (bzip2, version 0.9.5d)
- 5      May 2000 (bzip2, version 1.0pre8)
-30 December 2001 (bzip2, version 1.0.2pre1)
-15 February 2005 (bzip2, version 1.0.3)
Index: trunk/minix/commands/bzip2-1.0.3/README.XML.STUFF
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/README.XML.STUFF	(revision 9)
+++ 	(revision )
@@ -1,31 +1,0 @@
-The script xmlproc.sh takes an xml file as input,
-and processes it to create .pdf, .html or .ps output.
-It uses format.pl, a perl script to format <pre> blocks nicely,
- and add CDATA tags so writers do not have to use eg. &lt; 
-
-The file "entities.xml" must be edited to reflect current
-version, year, etc.
-
-
-Usage:
-
-  xmlproc.sh -v manual.xml
-  Validates an xml file to ensure no dtd-compliance errors
-
-  xmlproc.sh -html manual.xml
-  Output: manual.html
-
-  xmlproc.sh -pdf manual.xml
-  Output: manual.pdf
-
-  xmlproc.sh -ps manual.xml
-  Output: manual.ps
-
-
-Notum bene: 
-- pdfxmltex barfs if given a filename with an underscore in it
-
-- xmltex won't work yet - there's a bug in passivetex
-    which we are all waiting for Sebastian to fix.
-  So we are going the xml -> pdf -> ps route for the time being,
-    using pdfxmltex.
Index: trunk/minix/commands/bzip2-1.0.3/Y2K_INFO
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/Y2K_INFO	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-
-Y2K status of bzip2 and libbzip2, versions 0.1, 0.9.0 and 0.9.5
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Informally speaking:
-   bzip2 is a compression program built on top of libbzip2, 
-   a library which does the real work of compression and 
-   decompression.  As far as I am aware, libbzip2 does not have 
-   any date-related code at all.
-
-   bzip2 itself copies dates from source to destination files 
-   when compressing or decompressing, using the 'stat' and 'utime' 
-   UNIX system calls.  It doesn't examine, manipulate or store the 
-   dates in any way.  So as far as I can see, there shouldn't be any 
-   problem with bzip2 providing 'stat' and 'utime' work correctly 
-   on your system.
-
-   On non-unix platforms (those for which BZ_UNIX in bzip2.c is
-   not set to 1), bzip2 doesn't even do the date copying.
-
-   Overall, informally speaking, I don't think bzip2 or libbzip2 
-   have a Y2K problem.
-
-Formally speaking:
-   I am not prepared to offer you any assurance whatsoever 
-   regarding Y2K issues in my software.  You alone assume the 
-   entire risk of using the software.  The disclaimer of liability 
-   in the LICENSE file in the bzip2 source distribution continues 
-   to apply on this issue as with every other issue pertaining 
-   to the software.
-
-Julian Seward
-Cambridge, UK
-25 August 1999
Index: trunk/minix/commands/bzip2-1.0.3/blocksort.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/blocksort.c	(revision 9)
+++ 	(revision )
@@ -1,1141 +1,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Block sorting machinery                               ---*/
-/*---                                           blocksort.c ---*/
-/*-------------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
-
-  To get some idea how the block sorting algorithms in this file 
-  work, read my paper 
-     On the Performance of BWT Sorting Algorithms
-  in Proceedings of the IEEE Data Compression Conference 2000,
-  Snowbird, Utah, USA, 27-30 March 2000.  The main sort in this
-  file implements the algorithm called  cache  in the paper.
---*/
-
-
-#include "bzlib_private.h"
-
-/*---------------------------------------------*/
-/*--- Fallback O(N log(N)^2) sorting        ---*/
-/*--- algorithm, for repetitive blocks      ---*/
-/*---------------------------------------------*/
-
-/*---------------------------------------------*/
-static 
-__inline__
-void fallbackSimpleSort ( UInt32* fmap, 
-                          UInt32* eclass, 
-                          Int32   lo, 
-                          Int32   hi )
-{
-   Int32 i, j, tmp;
-   UInt32 ec_tmp;
-
-   if (lo == hi) return;
-
-   if (hi - lo > 3) {
-      for ( i = hi-4; i >= lo; i-- ) {
-         tmp = fmap[i];
-         ec_tmp = eclass[tmp];
-         for ( j = i+4; j <= hi && ec_tmp > eclass[fmap[j]]; j += 4 )
-            fmap[j-4] = fmap[j];
-         fmap[j-4] = tmp;
-      }
-   }
-
-   for ( i = hi-1; i >= lo; i-- ) {
-      tmp = fmap[i];
-      ec_tmp = eclass[tmp];
-      for ( j = i+1; j <= hi && ec_tmp > eclass[fmap[j]]; j++ )
-         fmap[j-1] = fmap[j];
-      fmap[j-1] = tmp;
-   }
-}
-
-
-/*---------------------------------------------*/
-#define fswap(zz1, zz2) \
-   { Int32 zztmp = zz1; zz1 = zz2; zz2 = zztmp; }
-
-#define fvswap(zzp1, zzp2, zzn)       \
-{                                     \
-   Int32 yyp1 = (zzp1);               \
-   Int32 yyp2 = (zzp2);               \
-   Int32 yyn  = (zzn);                \
-   while (yyn > 0) {                  \
-      fswap(fmap[yyp1], fmap[yyp2]);  \
-      yyp1++; yyp2++; yyn--;          \
-   }                                  \
-}
-
-
-#define fmin(a,b) ((a) < (b)) ? (a) : (b)
-
-#define fpush(lz,hz) { stackLo[sp] = lz; \
-                       stackHi[sp] = hz; \
-                       sp++; }
-
-#define fpop(lz,hz) { sp--;              \
-                      lz = stackLo[sp];  \
-                      hz = stackHi[sp]; }
-
-#define FALLBACK_QSORT_SMALL_THRESH 10
-#define FALLBACK_QSORT_STACK_SIZE   100
-
-
-static
-void fallbackQSort3 ( UInt32* fmap, 
-                      UInt32* eclass,
-                      Int32   loSt, 
-                      Int32   hiSt )
-{
-   Int32 unLo, unHi, ltLo, gtHi, n, m;
-   Int32 sp, lo, hi;
-   UInt32 med, r, r3;
-   Int32 stackLo[FALLBACK_QSORT_STACK_SIZE];
-   Int32 stackHi[FALLBACK_QSORT_STACK_SIZE];
-
-   r = 0;
-
-   sp = 0;
-   fpush ( loSt, hiSt );
-
-   while (sp > 0) {
-
-      AssertH ( sp < FALLBACK_QSORT_STACK_SIZE, 1004 );
-
-      fpop ( lo, hi );
-      if (hi - lo < FALLBACK_QSORT_SMALL_THRESH) {
-         fallbackSimpleSort ( fmap, eclass, lo, hi );
-         continue;
-      }
-
-      /* Random partitioning.  Median of 3 sometimes fails to
-         avoid bad cases.  Median of 9 seems to help but 
-         looks rather expensive.  This too seems to work but
-         is cheaper.  Guidance for the magic constants 
-         7621 and 32768 is taken from Sedgewick's algorithms
-         book, chapter 35.
-      */
-      r = ((r * 7621) + 1) % 32768;
-      r3 = r % 3;
-      if (r3 == 0) med = eclass[fmap[lo]]; else
-      if (r3 == 1) med = eclass[fmap[(lo+hi)>>1]]; else
-                   med = eclass[fmap[hi]];
-
-      unLo = ltLo = lo;
-      unHi = gtHi = hi;
-
-      while (1) {
-         while (1) {
-            if (unLo > unHi) break;
-            n = (Int32)eclass[fmap[unLo]] - (Int32)med;
-            if (n == 0) { 
-               fswap(fmap[unLo], fmap[ltLo]); 
-               ltLo++; unLo++; 
-               continue; 
-            };
-            if (n > 0) break;
-            unLo++;
-         }
-         while (1) {
-            if (unLo > unHi) break;
-            n = (Int32)eclass[fmap[unHi]] - (Int32)med;
-            if (n == 0) { 
-               fswap(fmap[unHi], fmap[gtHi]); 
-               gtHi--; unHi--; 
-               continue; 
-            };
-            if (n < 0) break;
-            unHi--;
-         }
-         if (unLo > unHi) break;
-         fswap(fmap[unLo], fmap[unHi]); unLo++; unHi--;
-      }
-
-      AssertD ( unHi == unLo-1, "fallbackQSort3(2)" );
-
-      if (gtHi < ltLo) continue;
-
-      n = fmin(ltLo-lo, unLo-ltLo); fvswap(lo, unLo-n, n);
-      m = fmin(hi-gtHi, gtHi-unHi); fvswap(unLo, hi-m+1, m);
-
-      n = lo + unLo - ltLo - 1;
-      m = hi - (gtHi - unHi) + 1;
-
-      if (n - lo > hi - m) {
-         fpush ( lo, n );
-         fpush ( m, hi );
-      } else {
-         fpush ( m, hi );
-         fpush ( lo, n );
-      }
-   }
-}
-
-#undef fmin
-#undef fpush
-#undef fpop
-#undef fswap
-#undef fvswap
-#undef FALLBACK_QSORT_SMALL_THRESH
-#undef FALLBACK_QSORT_STACK_SIZE
-
-
-/*---------------------------------------------*/
-/* Pre:
-      nblock > 0
-      eclass exists for [0 .. nblock-1]
-      ((UChar*)eclass) [0 .. nblock-1] holds block
-      ptr exists for [0 .. nblock-1]
-
-   Post:
-      ((UChar*)eclass) [0 .. nblock-1] holds block
-      All other areas of eclass destroyed
-      fmap [0 .. nblock-1] holds sorted order
-      bhtab [ 0 .. 2+(nblock/32) ] destroyed
-*/
-
-#define       SET_BH(zz)  bhtab[(zz) >> 5] |= (1 << ((zz) & 31))
-#define     CLEAR_BH(zz)  bhtab[(zz) >> 5] &= ~(1 << ((zz) & 31))
-#define     ISSET_BH(zz)  (bhtab[(zz) >> 5] & (1 << ((zz) & 31)))
-#define      WORD_BH(zz)  bhtab[(zz) >> 5]
-#define UNALIGNED_BH(zz)  ((zz) & 0x01f)
-
-static
-void fallbackSort ( UInt32* fmap, 
-                    UInt32* eclass, 
-                    UInt32* bhtab,
-                    Int32   nblock,
-                    Int32   verb )
-{
-   Int32 ftab[257];
-   Int32 ftabCopy[256];
-   Int32 H, i, j, k, l, r, cc, cc1;
-   Int32 nNotDone;
-   Int32 nBhtab;
-   UChar* eclass8 = (UChar*)eclass;
-
-   /*--
-      Initial 1-char radix sort to generate
-      initial fmap and initial BH bits.
-   --*/
-   if (verb >= 4)
-      VPrintf0 ( "        bucket sorting ...\n" );
-   for (i = 0; i < 257;    i++) ftab[i] = 0;
-   for (i = 0; i < nblock; i++) ftab[eclass8[i]]++;
-   for (i = 0; i < 256;    i++) ftabCopy[i] = ftab[i];
-   for (i = 1; i < 257;    i++) ftab[i] += ftab[i-1];
-
-   for (i = 0; i < nblock; i++) {
-      j = eclass8[i];
-      k = ftab[j] - 1;
-      ftab[j] = k;
-      fmap[k] = i;
-   }
-
-   nBhtab = 2 + (nblock / 32);
-   for (i = 0; i < nBhtab; i++) bhtab[i] = 0;
-   for (i = 0; i < 256; i++) SET_BH(ftab[i]);
-
-   /*--
-      Inductively refine the buckets.  Kind-of an
-      "exponential radix sort" (!), inspired by the
-      Manber-Myers suffix array construction algorithm.
-   --*/
-
-   /*-- set sentinel bits for block-end detection --*/
-   for (i = 0; i < 32; i++) { 
-      SET_BH(nblock + 2*i);
-      CLEAR_BH(nblock + 2*i + 1);
-   }
-
-   /*-- the log(N) loop --*/
-   H = 1;
-   while (1) {
-
-      if (verb >= 4) 
-         VPrintf1 ( "        depth %6d has ", H );
-
-      j = 0;
-      for (i = 0; i < nblock; i++) {
-         if (ISSET_BH(i)) j = i;
-         k = fmap[i] - H; if (k < 0) k += nblock;
-         eclass[k] = j;
-      }
-
-      nNotDone = 0;
-      r = -1;
-      while (1) {
-
-	 /*-- find the next non-singleton bucket --*/
-         k = r + 1;
-         while (ISSET_BH(k) && UNALIGNED_BH(k)) k++;
-         if (ISSET_BH(k)) {
-            while (WORD_BH(k) == 0xffffffff) k += 32;
-            while (ISSET_BH(k)) k++;
-         }
-         l = k - 1;
-         if (l >= nblock) break;
-         while (!ISSET_BH(k) && UNALIGNED_BH(k)) k++;
-         if (!ISSET_BH(k)) {
-            while (WORD_BH(k) == 0x00000000) k += 32;
-            while (!ISSET_BH(k)) k++;
-         }
-         r = k - 1;
-         if (r >= nblock) break;
-
-         /*-- now [l, r] bracket current bucket --*/
-         if (r > l) {
-            nNotDone += (r - l + 1);
-            fallbackQSort3 ( fmap, eclass, l, r );
-
-            /*-- scan bucket and generate header bits-- */
-            cc = -1;
-            for (i = l; i <= r; i++) {
-               cc1 = eclass[fmap[i]];
-               if (cc != cc1) { SET_BH(i); cc = cc1; };
-            }
-         }
-      }
-
-      if (verb >= 4) 
-         VPrintf1 ( "%6d unresolved strings\n", nNotDone );
-
-      H *= 2;
-      if (H > nblock || nNotDone == 0) break;
-   }
-
-   /*-- 
-      Reconstruct the original block in
-      eclass8 [0 .. nblock-1], since the
-      previous phase destroyed it.
-   --*/
-   if (verb >= 4)
-      VPrintf0 ( "        reconstructing block ...\n" );
-   j = 0;
-   for (i = 0; i < nblock; i++) {
-      while (ftabCopy[j] == 0) j++;
-      ftabCopy[j]--;
-      eclass8[fmap[i]] = (UChar)j;
-   }
-   AssertH ( j < 256, 1005 );
-}
-
-#undef       SET_BH
-#undef     CLEAR_BH
-#undef     ISSET_BH
-#undef      WORD_BH
-#undef UNALIGNED_BH
-
-
-/*---------------------------------------------*/
-/*--- The main, O(N^2 log(N)) sorting       ---*/
-/*--- algorithm.  Faster for "normal"       ---*/
-/*--- non-repetitive blocks.                ---*/
-/*---------------------------------------------*/
-
-/*---------------------------------------------*/
-static
-__inline__
-Bool mainGtU ( UInt32  i1, 
-               UInt32  i2,
-               UChar*  block, 
-               UInt16* quadrant,
-               UInt32  nblock,
-               Int32*  budget )
-{
-   Int32  k;
-   UChar  c1, c2;
-   UInt16 s1, s2;
-
-   AssertD ( i1 != i2, "mainGtU" );
-   /* 1 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 2 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 3 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 4 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 5 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 6 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 7 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 8 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 9 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 10 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 11 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-   /* 12 */
-   c1 = block[i1]; c2 = block[i2];
-   if (c1 != c2) return (c1 > c2);
-   i1++; i2++;
-
-   k = nblock + 8;
-
-   do {
-      /* 1 */
-      c1 = block[i1]; c2 = block[i2];
-      if (c1 != c2) return (c1 > c2);
-      s1 = quadrant[i1]; s2 = quadrant[i2];
-      if (s1 != s2) return (s1 > s2);
-      i1++; i2++;
-      /* 2 */
-      c1 = block[i1]; c2 = block[i2];
-      if (c1 != c2) return (c1 > c2);
-      s1 = quadrant[i1]; s2 = quadrant[i2];
-      if (s1 != s2) return (s1 > s2);
-      i1++; i2++;
-      /* 3 */
-      c1 = block[i1]; c2 = block[i2];
-      if (c1 != c2) return (c1 > c2);
-      s1 = quadrant[i1]; s2 = quadrant[i2];
-      if (s1 != s2) return (s1 > s2);
-      i1++; i2++;
-      /* 4 */
-      c1 = block[i1]; c2 = block[i2];
-      if (c1 != c2) return (c1 > c2);
-      s1 = quadrant[i1]; s2 = quadrant[i2];
-      if (s1 != s2) return (s1 > s2);
-      i1++; i2++;
-      /* 5 */
-      c1 = block[i1]; c2 = block[i2];
-      if (c1 != c2) return (c1 > c2);
-      s1 = quadrant[i1]; s2 = quadrant[i2];
-      if (s1 != s2) return (s1 > s2);
-      i1++; i2++;
-      /* 6 */
-      c1 = block[i1]; c2 = block[i2];
-      if (c1 != c2) return (c1 > c2);
-      s1 = quadrant[i1]; s2 = quadrant[i2];
-      if (s1 != s2) return (s1 > s2);
-      i1++; i2++;
-      /* 7 */
-      c1 = block[i1]; c2 = block[i2];
-      if (c1 != c2) return (c1 > c2);
-      s1 = quadrant[i1]; s2 = quadrant[i2];
-      if (s1 != s2) return (s1 > s2);
-      i1++; i2++;
-      /* 8 */
-      c1 = block[i1]; c2 = block[i2];
-      if (c1 != c2) return (c1 > c2);
-      s1 = quadrant[i1]; s2 = quadrant[i2];
-      if (s1 != s2) return (s1 > s2);
-      i1++; i2++;
-
-      if (i1 >= nblock) i1 -= nblock;
-      if (i2 >= nblock) i2 -= nblock;
-
-      k -= 8;
-      (*budget)--;
-   }
-      while (k >= 0);
-
-   return False;
-}
-
-
-/*---------------------------------------------*/
-/*--
-   Knuth's increments seem to work better
-   than Incerpi-Sedgewick here.  Possibly
-   because the number of elems to sort is
-   usually small, typically <= 20.
---*/
-static
-Int32 incs[14] = { 1, 4, 13, 40, 121, 364, 1093, 3280,
-                   9841, 29524, 88573, 265720,
-                   797161, 2391484 };
-
-static
-void mainSimpleSort ( UInt32* ptr,
-                      UChar*  block,
-                      UInt16* quadrant,
-                      Int32   nblock,
-                      Int32   lo, 
-                      Int32   hi, 
-                      Int32   d,
-                      Int32*  budget )
-{
-   Int32 i, j, h, bigN, hp;
-   UInt32 v;
-
-   bigN = hi - lo + 1;
-   if (bigN < 2) return;
-
-   hp = 0;
-   while (incs[hp] < bigN) hp++;
-   hp--;
-
-   for (; hp >= 0; hp--) {
-      h = incs[hp];
-
-      i = lo + h;
-      while (True) {
-
-         /*-- copy 1 --*/
-         if (i > hi) break;
-         v = ptr[i];
-         j = i;
-         while ( mainGtU ( 
-                    ptr[j-h]+d, v+d, block, quadrant, nblock, budget 
-                 ) ) {
-            ptr[j] = ptr[j-h];
-            j = j - h;
-            if (j <= (lo + h - 1)) break;
-         }
-         ptr[j] = v;
-         i++;
-
-         /*-- copy 2 --*/
-         if (i > hi) break;
-         v = ptr[i];
-         j = i;
-         while ( mainGtU ( 
-                    ptr[j-h]+d, v+d, block, quadrant, nblock, budget 
-                 ) ) {
-            ptr[j] = ptr[j-h];
-            j = j - h;
-            if (j <= (lo + h - 1)) break;
-         }
-         ptr[j] = v;
-         i++;
-
-         /*-- copy 3 --*/
-         if (i > hi) break;
-         v = ptr[i];
-         j = i;
-         while ( mainGtU ( 
-                    ptr[j-h]+d, v+d, block, quadrant, nblock, budget 
-                 ) ) {
-            ptr[j] = ptr[j-h];
-            j = j - h;
-            if (j <= (lo + h - 1)) break;
-         }
-         ptr[j] = v;
-         i++;
-
-         if (*budget < 0) return;
-      }
-   }
-}
-
-
-/*---------------------------------------------*/
-/*--
-   The following is an implementation of
-   an elegant 3-way quicksort for strings,
-   described in a paper "Fast Algorithms for
-   Sorting and Searching Strings", by Robert
-   Sedgewick and Jon L. Bentley.
---*/
-
-#define mswap(zz1, zz2) \
-   { Int32 zztmp = zz1; zz1 = zz2; zz2 = zztmp; }
-
-#define mvswap(zzp1, zzp2, zzn)       \
-{                                     \
-   Int32 yyp1 = (zzp1);               \
-   Int32 yyp2 = (zzp2);               \
-   Int32 yyn  = (zzn);                \
-   while (yyn > 0) {                  \
-      mswap(ptr[yyp1], ptr[yyp2]);    \
-      yyp1++; yyp2++; yyn--;          \
-   }                                  \
-}
-
-static 
-__inline__
-UChar mmed3 ( UChar a, UChar b, UChar c )
-{
-   UChar t;
-   if (a > b) { t = a; a = b; b = t; };
-   if (b > c) { 
-      b = c;
-      if (a > b) b = a;
-   }
-   return b;
-}
-
-#define mmin(a,b) ((a) < (b)) ? (a) : (b)
-
-#define mpush(lz,hz,dz) { stackLo[sp] = lz; \
-                          stackHi[sp] = hz; \
-                          stackD [sp] = dz; \
-                          sp++; }
-
-#define mpop(lz,hz,dz) { sp--;             \
-                         lz = stackLo[sp]; \
-                         hz = stackHi[sp]; \
-                         dz = stackD [sp]; }
-
-
-#define mnextsize(az) (nextHi[az]-nextLo[az])
-
-#define mnextswap(az,bz)                                        \
-   { Int32 tz;                                                  \
-     tz = nextLo[az]; nextLo[az] = nextLo[bz]; nextLo[bz] = tz; \
-     tz = nextHi[az]; nextHi[az] = nextHi[bz]; nextHi[bz] = tz; \
-     tz = nextD [az]; nextD [az] = nextD [bz]; nextD [bz] = tz; }
-
-
-#define MAIN_QSORT_SMALL_THRESH 20
-#define MAIN_QSORT_DEPTH_THRESH (BZ_N_RADIX + BZ_N_QSORT)
-#define MAIN_QSORT_STACK_SIZE 100
-
-static
-void mainQSort3 ( UInt32* ptr,
-                  UChar*  block,
-                  UInt16* quadrant,
-                  Int32   nblock,
-                  Int32   loSt, 
-                  Int32   hiSt, 
-                  Int32   dSt,
-                  Int32*  budget )
-{
-   Int32 unLo, unHi, ltLo, gtHi, n, m, med;
-   Int32 sp, lo, hi, d;
-
-   Int32 stackLo[MAIN_QSORT_STACK_SIZE];
-   Int32 stackHi[MAIN_QSORT_STACK_SIZE];
-   Int32 stackD [MAIN_QSORT_STACK_SIZE];
-
-   Int32 nextLo[3];
-   Int32 nextHi[3];
-   Int32 nextD [3];
-
-   sp = 0;
-   mpush ( loSt, hiSt, dSt );
-
-   while (sp > 0) {
-
-      AssertH ( sp < MAIN_QSORT_STACK_SIZE, 1001 );
-
-      mpop ( lo, hi, d );
-      if (hi - lo < MAIN_QSORT_SMALL_THRESH || 
-          d > MAIN_QSORT_DEPTH_THRESH) {
-         mainSimpleSort ( ptr, block, quadrant, nblock, lo, hi, d, budget );
-         if (*budget < 0) return;
-         continue;
-      }
-
-      med = (Int32) 
-            mmed3 ( block[ptr[ lo         ]+d],
-                    block[ptr[ hi         ]+d],
-                    block[ptr[ (lo+hi)>>1 ]+d] );
-
-      unLo = ltLo = lo;
-      unHi = gtHi = hi;
-
-      while (True) {
-         while (True) {
-            if (unLo > unHi) break;
-            n = ((Int32)block[ptr[unLo]+d]) - med;
-            if (n == 0) { 
-               mswap(ptr[unLo], ptr[ltLo]); 
-               ltLo++; unLo++; continue; 
-            };
-            if (n >  0) break;
-            unLo++;
-         }
-         while (True) {
-            if (unLo > unHi) break;
-            n = ((Int32)block[ptr[unHi]+d]) - med;
-            if (n == 0) { 
-               mswap(ptr[unHi], ptr[gtHi]); 
-               gtHi--; unHi--; continue; 
-            };
-            if (n <  0) break;
-            unHi--;
-         }
-         if (unLo > unHi) break;
-         mswap(ptr[unLo], ptr[unHi]); unLo++; unHi--;
-      }
-
-      AssertD ( unHi == unLo-1, "mainQSort3(2)" );
-
-      if (gtHi < ltLo) {
-         mpush(lo, hi, d+1 );
-         continue;
-      }
-
-      n = mmin(ltLo-lo, unLo-ltLo); mvswap(lo, unLo-n, n);
-      m = mmin(hi-gtHi, gtHi-unHi); mvswap(unLo, hi-m+1, m);
-
-      n = lo + unLo - ltLo - 1;
-      m = hi - (gtHi - unHi) + 1;
-
-      nextLo[0] = lo;  nextHi[0] = n;   nextD[0] = d;
-      nextLo[1] = m;   nextHi[1] = hi;  nextD[1] = d;
-      nextLo[2] = n+1; nextHi[2] = m-1; nextD[2] = d+1;
-
-      if (mnextsize(0) < mnextsize(1)) mnextswap(0,1);
-      if (mnextsize(1) < mnextsize(2)) mnextswap(1,2);
-      if (mnextsize(0) < mnextsize(1)) mnextswap(0,1);
-
-      AssertD (mnextsize(0) >= mnextsize(1), "mainQSort3(8)" );
-      AssertD (mnextsize(1) >= mnextsize(2), "mainQSort3(9)" );
-
-      mpush (nextLo[0], nextHi[0], nextD[0]);
-      mpush (nextLo[1], nextHi[1], nextD[1]);
-      mpush (nextLo[2], nextHi[2], nextD[2]);
-   }
-}
-
-#undef mswap
-#undef mvswap
-#undef mpush
-#undef mpop
-#undef mmin
-#undef mnextsize
-#undef mnextswap
-#undef MAIN_QSORT_SMALL_THRESH
-#undef MAIN_QSORT_DEPTH_THRESH
-#undef MAIN_QSORT_STACK_SIZE
-
-
-/*---------------------------------------------*/
-/* Pre:
-      nblock > N_OVERSHOOT
-      block32 exists for [0 .. nblock-1 +N_OVERSHOOT]
-      ((UChar*)block32) [0 .. nblock-1] holds block
-      ptr exists for [0 .. nblock-1]
-
-   Post:
-      ((UChar*)block32) [0 .. nblock-1] holds block
-      All other areas of block32 destroyed
-      ftab [0 .. 65536 ] destroyed
-      ptr [0 .. nblock-1] holds sorted order
-      if (*budget < 0), sorting was abandoned
-*/
-
-#define BIGFREQ(b) (ftab[((b)+1) << 8] - ftab[(b) << 8])
-#define SETMASK (1 << 21)
-#define CLEARMASK (~(SETMASK))
-
-static
-void mainSort ( UInt32* ptr, 
-                UChar*  block,
-                UInt16* quadrant, 
-                UInt32* ftab,
-                Int32   nblock,
-                Int32   verb,
-                Int32*  budget )
-{
-   Int32  i, j, k, ss, sb;
-   Int32  runningOrder[256];
-   Bool   bigDone[256];
-   Int32  copyStart[256];
-   Int32  copyEnd  [256];
-   UChar  c1;
-   Int32  numQSorted;
-   UInt16 s;
-   if (verb >= 4) VPrintf0 ( "        main sort initialise ...\n" );
-
-   /*-- set up the 2-byte frequency table --*/
-   for (i = 65536; i >= 0; i--) ftab[i] = 0;
-
-   j = block[0] << 8;
-   i = nblock-1;
-   for (; i >= 3; i -= 4) {
-      quadrant[i] = 0;
-      j = (j >> 8) | ( ((UInt16)block[i]) << 8);
-      ftab[j]++;
-      quadrant[i-1] = 0;
-      j = (j >> 8) | ( ((UInt16)block[i-1]) << 8);
-      ftab[j]++;
-      quadrant[i-2] = 0;
-      j = (j >> 8) | ( ((UInt16)block[i-2]) << 8);
-      ftab[j]++;
-      quadrant[i-3] = 0;
-      j = (j >> 8) | ( ((UInt16)block[i-3]) << 8);
-      ftab[j]++;
-   }
-   for (; i >= 0; i--) {
-      quadrant[i] = 0;
-      j = (j >> 8) | ( ((UInt16)block[i]) << 8);
-      ftab[j]++;
-   }
-
-   /*-- (emphasises close relationship of block & quadrant) --*/
-   for (i = 0; i < BZ_N_OVERSHOOT; i++) {
-      block   [nblock+i] = block[i];
-      quadrant[nblock+i] = 0;
-   }
-
-   if (verb >= 4) VPrintf0 ( "        bucket sorting ...\n" );
-
-   /*-- Complete the initial radix sort --*/
-   for (i = 1; i <= 65536; i++) ftab[i] += ftab[i-1];
-
-   s = block[0] << 8;
-   i = nblock-1;
-   for (; i >= 3; i -= 4) {
-      s = (s >> 8) | (block[i] << 8);
-      j = ftab[s] -1;
-      ftab[s] = j;
-      ptr[j] = i;
-      s = (s >> 8) | (block[i-1] << 8);
-      j = ftab[s] -1;
-      ftab[s] = j;
-      ptr[j] = i-1;
-      s = (s >> 8) | (block[i-2] << 8);
-      j = ftab[s] -1;
-      ftab[s] = j;
-      ptr[j] = i-2;
-      s = (s >> 8) | (block[i-3] << 8);
-      j = ftab[s] -1;
-      ftab[s] = j;
-      ptr[j] = i-3;
-   }
-   for (; i >= 0; i--) {
-      s = (s >> 8) | (block[i] << 8);
-      j = ftab[s] -1;
-      ftab[s] = j;
-      ptr[j] = i;
-   }
-
-   /*--
-      Now ftab contains the first loc of every small bucket.
-      Calculate the running order, from smallest to largest
-      big bucket.
-   --*/
-   for (i = 0; i <= 255; i++) {
-      bigDone     [i] = False;
-      runningOrder[i] = i;
-   }
-
-   {
-      Int32 vv;
-      Int32 h = 1;
-      do h = 3 * h + 1; while (h <= 256);
-      do {
-         h = h / 3;
-         for (i = h; i <= 255; i++) {
-            vv = runningOrder[i];
-            j = i;
-            while ( BIGFREQ(runningOrder[j-h]) > BIGFREQ(vv) ) {
-               runningOrder[j] = runningOrder[j-h];
-               j = j - h;
-               if (j <= (h - 1)) goto zero;
-            }
-            zero:
-            runningOrder[j] = vv;
-         }
-      } while (h != 1);
-   }
-
-   /*--
-      The main sorting loop.
-   --*/
-
-   numQSorted = 0;
-
-   for (i = 0; i <= 255; i++) {
-
-      /*--
-         Process big buckets, starting with the least full.
-         Basically this is a 3-step process in which we call
-         mainQSort3 to sort the small buckets [ss, j], but
-         also make a big effort to avoid the calls if we can.
-      --*/
-      ss = runningOrder[i];
-
-      /*--
-         Step 1:
-         Complete the big bucket [ss] by quicksorting
-         any unsorted small buckets [ss, j], for j != ss.  
-         Hopefully previous pointer-scanning phases have already
-         completed many of the small buckets [ss, j], so
-         we don't have to sort them at all.
-      --*/
-      for (j = 0; j <= 255; j++) {
-         if (j != ss) {
-            sb = (ss << 8) + j;
-            if ( ! (ftab[sb] & SETMASK) ) {
-               Int32 lo = ftab[sb]   & CLEARMASK;
-               Int32 hi = (ftab[sb+1] & CLEARMASK) - 1;
-               if (hi > lo) {
-                  if (verb >= 4)
-                     VPrintf4 ( "        qsort [0x%x, 0x%x]   "
-                                "done %d   this %d\n",
-                                ss, j, numQSorted, hi - lo + 1 );
-                  mainQSort3 ( 
-                     ptr, block, quadrant, nblock, 
-                     lo, hi, BZ_N_RADIX, budget 
-                  );   
-                  numQSorted += (hi - lo + 1);
-                  if (*budget < 0) return;
-               }
-            }
-            ftab[sb] |= SETMASK;
-         }
-      }
-
-      AssertH ( !bigDone[ss], 1006 );
-
-      /*--
-         Step 2:
-         Now scan this big bucket [ss] so as to synthesise the
-         sorted order for small buckets [t, ss] for all t,
-         including, magically, the bucket [ss,ss] too.
-         This will avoid doing Real Work in subsequent Step 1's.
-      --*/
-      {
-         for (j = 0; j <= 255; j++) {
-            copyStart[j] =  ftab[(j << 8) + ss]     & CLEARMASK;
-            copyEnd  [j] = (ftab[(j << 8) + ss + 1] & CLEARMASK) - 1;
-         }
-         for (j = ftab[ss << 8] & CLEARMASK; j < copyStart[ss]; j++) {
-            k = ptr[j]-1; if (k < 0) k += nblock;
-            c1 = block[k];
-            if (!bigDone[c1])
-               ptr[ copyStart[c1]++ ] = k;
-         }
-         for (j = (ftab[(ss+1) << 8] & CLEARMASK) - 1; j > copyEnd[ss]; j--) {
-            k = ptr[j]-1; if (k < 0) k += nblock;
-            c1 = block[k];
-            if (!bigDone[c1]) 
-               ptr[ copyEnd[c1]-- ] = k;
-         }
-      }
-
-      AssertH ( (copyStart[ss]-1 == copyEnd[ss])
-                || 
-                /* Extremely rare case missing in bzip2-1.0.0 and 1.0.1.
-                   Necessity for this case is demonstrated by compressing 
-                   a sequence of approximately 48.5 million of character 
-                   251; 1.0.0/1.0.1 will then die here. */
-                (copyStart[ss] == 0 && copyEnd[ss] == nblock-1),
-                1007 )
-
-      for (j = 0; j <= 255; j++) ftab[(j << 8) + ss] |= SETMASK;
-
-      /*--
-         Step 3:
-         The [ss] big bucket is now done.  Record this fact,
-         and update the quadrant descriptors.  Remember to
-         update quadrants in the overshoot area too, if
-         necessary.  The "if (i < 255)" test merely skips
-         this updating for the last bucket processed, since
-         updating for the last bucket is pointless.
-
-         The quadrant array provides a way to incrementally
-         cache sort orderings, as they appear, so as to 
-         make subsequent comparisons in fullGtU() complete
-         faster.  For repetitive blocks this makes a big
-         difference (but not big enough to be able to avoid
-         the fallback sorting mechanism, exponential radix sort).
-
-         The precise meaning is: at all times:
-
-            for 0 <= i < nblock and 0 <= j <= nblock
-
-            if block[i] != block[j], 
-
-               then the relative values of quadrant[i] and 
-                    quadrant[j] are meaningless.
-
-               else {
-                  if quadrant[i] < quadrant[j]
-                     then the string starting at i lexicographically
-                     precedes the string starting at j
-
-                  else if quadrant[i] > quadrant[j]
-                     then the string starting at j lexicographically
-                     precedes the string starting at i
-
-                  else
-                     the relative ordering of the strings starting
-                     at i and j has not yet been determined.
-               }
-      --*/
-      bigDone[ss] = True;
-
-      if (i < 255) {
-         Int32 bbStart  = ftab[ss << 8] & CLEARMASK;
-         Int32 bbSize   = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
-         Int32 shifts   = 0;
-
-         while ((bbSize >> shifts) > 65534) shifts++;
-
-         for (j = bbSize-1; j >= 0; j--) {
-            Int32 a2update     = ptr[bbStart + j];
-            UInt16 qVal        = (UInt16)(j >> shifts);
-            quadrant[a2update] = qVal;
-            if (a2update < BZ_N_OVERSHOOT)
-               quadrant[a2update + nblock] = qVal;
-         }
-         AssertH ( ((bbSize-1) >> shifts) <= 65535, 1002 );
-      }
-
-   }
-
-   if (verb >= 4)
-      VPrintf3 ( "        %d pointers, %d sorted, %d scanned\n",
-                 nblock, numQSorted, nblock - numQSorted );
-}
-
-#undef BIGFREQ
-#undef SETMASK
-#undef CLEARMASK
-
-
-/*---------------------------------------------*/
-/* Pre:
-      nblock > 0
-      arr2 exists for [0 .. nblock-1 +N_OVERSHOOT]
-      ((UChar*)arr2)  [0 .. nblock-1] holds block
-      arr1 exists for [0 .. nblock-1]
-
-   Post:
-      ((UChar*)arr2) [0 .. nblock-1] holds block
-      All other areas of block destroyed
-      ftab [ 0 .. 65536 ] destroyed
-      arr1 [0 .. nblock-1] holds sorted order
-*/
-void BZ2_blockSort ( EState* s )
-{
-   UInt32* ptr    = s->ptr; 
-   UChar*  block  = s->block;
-   UInt32* ftab   = s->ftab;
-   Int32   nblock = s->nblock;
-   Int32   verb   = s->verbosity;
-   Int32   wfact  = s->workFactor;
-   UInt16* quadrant;
-   Int32   budget;
-   Int32   budgetInit;
-   Int32   i;
-
-   if (nblock < 10000) {
-      fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
-   } else {
-      /* Calculate the location for quadrant, remembering to get
-         the alignment right.  Assumes that &(block[0]) is at least
-         2-byte aligned -- this should be ok since block is really
-         the first section of arr2.
-      */
-      i = nblock+BZ_N_OVERSHOOT;
-      if (i & 1) i++;
-      quadrant = (UInt16*)(&(block[i]));
-
-      /* (wfact-1) / 3 puts the default-factor-30
-         transition point at very roughly the same place as 
-         with v0.1 and v0.9.0.  
-         Not that it particularly matters any more, since the
-         resulting compressed stream is now the same regardless
-         of whether or not we use the main sort or fallback sort.
-      */
-      if (wfact < 1  ) wfact = 1;
-      if (wfact > 100) wfact = 100;
-      budgetInit = nblock * ((wfact-1) / 3);
-      budget = budgetInit;
-
-      mainSort ( ptr, block, quadrant, ftab, nblock, verb, &budget );
-      if (verb >= 3) 
-         VPrintf3 ( "      %d work, %d block, ratio %5.2f\n",
-                    budgetInit - budget,
-                    nblock, 
-                    (float)(budgetInit - budget) /
-                    (float)(nblock==0 ? 1 : nblock) ); 
-      if (budget < 0) {
-         if (verb >= 2) 
-            VPrintf0 ( "    too repetitive; using fallback"
-                       " sorting algorithm\n" );
-         fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
-      }
-   }
-
-   s->origPtr = -1;
-   for (i = 0; i < s->nblock; i++)
-      if (ptr[i] == 0)
-         { s->origPtr = i; break; };
-
-   AssertH( s->origPtr != -1, 1003 );
-}
-
-
-/*-------------------------------------------------------------*/
-/*--- end                                       blocksort.c ---*/
-/*-------------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/build
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/build	(revision 9)
+++ 	(revision )
@@ -1,6 +1,0 @@
-#!/bin/sh
-make clean
-make all
-if [ "$1" != build ]
-then make install
-fi
Index: trunk/minix/commands/bzip2-1.0.3/bz-common.xsl
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bz-common.xsl	(revision 9)
+++ 	(revision )
@@ -1,39 +1,0 @@
-<?xml version="1.0"?> <!-- -*- sgml -*- -->
-<xsl:stylesheet 
-     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-
-<!-- we like '1.2 Title' -->
-<xsl:param name="section.autolabel" select="'1'"/> 
-<xsl:param name="section.label.includes.component.label" select="'1'"/>
-
-<!-- Do not put 'Chapter' at the start of eg 'Chapter 1. Doing This' -->
-<xsl:param name="local.l10n.xml" select="document('')"/> 
-<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"> 
-  <l:l10n language="en"> 
-    <l:context name="title-numbered">
-      <l:template name="chapter" text="%n.&#160;%t"/>
-    </l:context> 
-  </l:l10n>
-</l:i18n>
-
-<!-- don't generate sub-tocs for qanda sets -->
-<xsl:param name="generate.toc">
-set       toc,title
-book      toc,title,figure,table,example,equation
-chapter   toc,title
-section   toc
-sect1     toc
-sect2     toc
-sect3     toc
-sect4     nop
-sect5     nop
-qandaset  toc
-qandadiv  nop
-appendix  toc,title
-article/appendix  nop
-article   toc,title
-preface   toc,title
-reference toc,title
-</xsl:param>
-
-</xsl:stylesheet>
Index: trunk/minix/commands/bzip2-1.0.3/bz-fo.xsl
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bz-fo.xsl	(revision 9)
+++ 	(revision )
@@ -1,257 +1,0 @@
-<?xml version="1.0" encoding="UTF-8"?> <!-- -*- sgml -*- -->
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
-     xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
-
-<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
-<xsl:import href="bz-common.xsl"/>
-
-<!-- set indent = yes while debugging, then change to NO -->
-<xsl:output method="xml" indent="yes"/>
-
-<!-- ensure only passivetex extensions are on -->
-<xsl:param name="stylesheet.result.type" select="'fo'"/>
-<!-- fo extensions: PDF bookmarks and index terms -->
-<xsl:param name="use.extensions" select="'1'"/>
-<xsl:param name="xep.extensions" select="0"/>      
-<xsl:param name="fop.extensions" select="0"/>     
-<xsl:param name="saxon.extensions" select="0"/>   
-<xsl:param name="passivetex.extensions" select="1"/>
-<xsl:param name="tablecolumns.extension" select="'1'"/>
-
-<!-- ensure we are using single sided -->
-<xsl:param name="double.sided" select="'0'"/> 
-
-<!-- insert cross references to page numbers -->
-<xsl:param name="insert.xref.page.number" select="1"/>
-
-<!-- <?custom-pagebreak?> inserts a page break at this point -->
-<xsl:template match="processing-instruction('custom-pagebreak')">
-  <fo:block break-before='page'/>
-</xsl:template>
-
-<!-- show links in color -->
-<xsl:attribute-set name="xref.properties">
-  <xsl:attribute name="color">blue</xsl:attribute>
-</xsl:attribute-set>
-
-<!-- make pre listings indented a bit + a bg colour -->
-<xsl:template match="programlisting | screen">
-  <fo:block start-indent="0.25in" wrap-option="no-wrap" 
-            white-space-collapse="false" text-align="start" 
-            font-family="monospace" background-color="#f2f2f9"
-            linefeed-treatment="preserve" 
-            xsl:use-attribute-sets="normal.para.spacing">
-    <xsl:apply-templates/>
-  </fo:block>
-</xsl:template>
-<!-- make verbatim output prettier -->
-<xsl:template match="literallayout">
-  <fo:block start-indent="0.25in" wrap-option="no-wrap" 
-            white-space-collapse="false" text-align="start" 
-            font-family="monospace" background-color="#edf7f4"
-            linefeed-treatment="preserve" 
-            space-before="0em" space-after="0em">
-    <xsl:apply-templates/>
-  </fo:block>
-</xsl:template>
-
-<!-- workaround bug in passivetex fo output for itemizedlist -->
-<xsl:template match="itemizedlist/listitem">
-  <xsl:variable name="id">
-  <xsl:call-template name="object.id"/></xsl:variable>
-  <xsl:variable name="itemsymbol">
-    <xsl:call-template name="list.itemsymbol">
-      <xsl:with-param name="node" select="parent::itemizedlist"/>
-    </xsl:call-template>
-  </xsl:variable>
-  <xsl:variable name="item.contents">
-    <fo:list-item-label end-indent="label-end()">
-      <fo:block>
-        <xsl:choose>
-          <xsl:when test="$itemsymbol='disc'">&#x2022;</xsl:when>
-          <xsl:when test="$itemsymbol='bullet'">&#x2022;</xsl:when>
-          <xsl:otherwise>&#x2022;</xsl:otherwise>
-        </xsl:choose>
-      </fo:block>
-    </fo:list-item-label>
-    <fo:list-item-body start-indent="body-start()">
-      <xsl:apply-templates/>    <!-- removed extra block wrapper -->
-    </fo:list-item-body>
-  </xsl:variable>
-  <xsl:choose>
-    <xsl:when test="parent::*/@spacing = 'compact'">
-      <fo:list-item id="{$id}" 
-          xsl:use-attribute-sets="compact.list.item.spacing">
-        <xsl:copy-of select="$item.contents"/>
-      </fo:list-item>
-    </xsl:when>
-    <xsl:otherwise>
-      <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
-        <xsl:copy-of select="$item.contents"/>
-      </fo:list-item>
-    </xsl:otherwise>
-  </xsl:choose>
-</xsl:template>
-
-<!-- workaround bug in passivetex fo output for orderedlist -->
-<xsl:template match="orderedlist/listitem">
-  <xsl:variable name="id">
-  <xsl:call-template name="object.id"/></xsl:variable>
-  <xsl:variable name="item.contents">
-    <fo:list-item-label end-indent="label-end()">
-      <fo:block>
-        <xsl:apply-templates select="." mode="item-number"/>
-      </fo:block>
-    </fo:list-item-label>
-    <fo:list-item-body start-indent="body-start()">
-      <xsl:apply-templates/>    <!-- removed extra block wrapper -->
-    </fo:list-item-body>
-  </xsl:variable>
-  <xsl:choose>
-    <xsl:when test="parent::*/@spacing = 'compact'">
-      <fo:list-item id="{$id}" 
-          xsl:use-attribute-sets="compact.list.item.spacing">
-        <xsl:copy-of select="$item.contents"/>
-      </fo:list-item>
-    </xsl:when>
-    <xsl:otherwise>
-      <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
-        <xsl:copy-of select="$item.contents"/>
-      </fo:list-item>
-    </xsl:otherwise>
-  </xsl:choose>
-</xsl:template>
-
-<!-- workaround bug in passivetex fo output for variablelist -->
-<xsl:param name="variablelist.as.blocks" select="1"/>
-<xsl:template match="varlistentry" mode="vl.as.blocks">
-  <xsl:variable name="id">
-    <xsl:call-template name="object.id"/></xsl:variable>
-  <fo:block id="{$id}" xsl:use-attribute-sets="list.item.spacing"  
-      keep-together.within-column="always" 
-      keep-with-next.within-column="always">
-    <xsl:apply-templates select="term"/>
-  </fo:block>
-  <fo:block start-indent="0.5in" end-indent="0in" 
-            space-after.minimum="0.2em" 
-            space-after.optimum="0.4em" 
-            space-after.maximum="0.6em">
-    <fo:block>
-      <xsl:apply-templates select="listitem"/>
-    </fo:block>
-  </fo:block>
-</xsl:template>
-
-
-<!-- workaround bug in footers: force right-align w/two 80|30 cols -->
-<xsl:template name="footer.table">
-  <xsl:param name="pageclass" select="''"/>
-  <xsl:param name="sequence" select="''"/>
-  <xsl:param name="gentext-key" select="''"/>
-  <xsl:choose>
-    <xsl:when test="$pageclass = 'index'">
-      <xsl:attribute name="margin-left">0pt</xsl:attribute>
-    </xsl:when>
-  </xsl:choose>
-  <xsl:variable name="candidate">
-    <fo:table table-layout="fixed" width="100%">
-      <fo:table-column column-number="1" column-width="80%"/>
-      <fo:table-column column-number="2" column-width="20%"/>
-      <fo:table-body>
-        <fo:table-row height="14pt">
-          <fo:table-cell text-align="left" display-align="after">
-            <xsl:attribute name="relative-align">baseline</xsl:attribute>
-            <fo:block> 
-              <fo:block> </fo:block><!-- empty cell -->
-            </fo:block>
-          </fo:table-cell>
-          <fo:table-cell text-align="center" display-align="after">
-            <xsl:attribute name="relative-align">baseline</xsl:attribute>
-            <fo:block>
-              <xsl:call-template name="footer.content">
-                <xsl:with-param name="pageclass" select="$pageclass"/>
-                <xsl:with-param name="sequence" select="$sequence"/>
-                <xsl:with-param name="position" select="'center'"/>
-                <xsl:with-param name="gentext-key" select="$gentext-key"/>
-              </xsl:call-template>
-            </fo:block>
-          </fo:table-cell>
-        </fo:table-row>
-      </fo:table-body>
-    </fo:table>
-  </xsl:variable>
-  <!-- Really output a footer? -->
-  <xsl:choose>
-    <xsl:when test="$pageclass='titlepage' and $gentext-key='book'
-                    and $sequence='first'">
-      <!-- no, book titlepages have no footers at all -->
-    </xsl:when>
-    <xsl:when test="$sequence = 'blank' and $footers.on.blank.pages = 0">
-      <!-- no output -->
-    </xsl:when>
-    <xsl:otherwise>
-      <xsl:copy-of select="$candidate"/>
-    </xsl:otherwise>
-  </xsl:choose>
-</xsl:template>
-
-
-<!-- fix bug in headers: force right-align w/two 40|60 cols -->
-<xsl:template name="header.table">
-  <xsl:param name="pageclass" select="''"/>
-  <xsl:param name="sequence" select="''"/>
-  <xsl:param name="gentext-key" select="''"/>
-  <xsl:choose>
-    <xsl:when test="$pageclass = 'index'">
-      <xsl:attribute name="margin-left">0pt</xsl:attribute>
-    </xsl:when>
-  </xsl:choose>
-  <xsl:variable name="candidate">
-    <fo:table table-layout="fixed" width="100%">
-      <xsl:call-template name="head.sep.rule">
-        <xsl:with-param name="pageclass" select="$pageclass"/>
-        <xsl:with-param name="sequence" select="$sequence"/>
-        <xsl:with-param name="gentext-key" select="$gentext-key"/>
-      </xsl:call-template>
-      <fo:table-column column-number="1" column-width="40%"/>
-      <fo:table-column column-number="2" column-width="60%"/>
-      <fo:table-body>
-        <fo:table-row height="14pt">
-          <fo:table-cell text-align="left" display-align="before">
-            <xsl:attribute name="relative-align">baseline</xsl:attribute>
-            <fo:block>
-              <fo:block> </fo:block><!-- empty cell -->
-            </fo:block>
-          </fo:table-cell>
-          <fo:table-cell text-align="center" display-align="before">
-            <xsl:attribute name="relative-align">baseline</xsl:attribute>
-            <fo:block>
-              <xsl:call-template name="header.content">
-                <xsl:with-param name="pageclass" select="$pageclass"/>
-                <xsl:with-param name="sequence" select="$sequence"/>
-                <xsl:with-param name="position" select="'center'"/>
-                <xsl:with-param name="gentext-key" select="$gentext-key"/>
-              </xsl:call-template>
-            </fo:block>
-          </fo:table-cell>
-        </fo:table-row>
-      </fo:table-body>
-    </fo:table>
-  </xsl:variable>
-  <!-- Really output a header? -->
-  <xsl:choose>
-    <xsl:when test="$pageclass = 'titlepage' and $gentext-key = 'book'
-                    and $sequence='first'">
-      <!-- no, book titlepages have no headers at all -->
-    </xsl:when>
-    <xsl:when test="$sequence = 'blank' and $headers.on.blank.pages = 0">
-      <!-- no output -->
-    </xsl:when>
-    <xsl:otherwise>
-      <xsl:copy-of select="$candidate"/>
-    </xsl:otherwise>
-  </xsl:choose>
-</xsl:template>
-
-
-</xsl:stylesheet>
Index: trunk/minix/commands/bzip2-1.0.3/bz-html.xsl
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bz-html.xsl	(revision 9)
+++ 	(revision )
@@ -1,20 +1,0 @@
-<?xml version="1.0"?> <!-- -*- sgml -*- -->
-<!DOCTYPE xsl:stylesheet [ <!ENTITY bz-css SYSTEM "./bzip.css"> ]>
-
-<xsl:stylesheet 
-   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-
-<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"/>
-<xsl:import href="bz-common.xsl"/>
-
-<!-- use 8859-1 encoding -->
-<xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
-
-<!-- we include the css directly when generating one large file -->
-<xsl:template name="user.head.content">  
-  <style type="text/css" media="screen">
-    <xsl:text>&bz-css;</xsl:text>
-  </style>
-</xsl:template>
-
-</xsl:stylesheet>
Index: trunk/minix/commands/bzip2-1.0.3/bzdiff
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzdiff	(revision 9)
+++ 	(revision )
@@ -1,76 +1,0 @@
-#!/bin/sh
-# sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
-
-# Bzcmp/diff wrapped for bzip2, 
-# adapted from zdiff by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
-
-# Bzcmp and bzdiff are used to invoke the cmp or the  diff  pro-
-# gram  on compressed files.  All options specified are passed
-# directly to cmp or diff.  If only 1 file is specified,  then
-# the  files  compared  are file1 and an uncompressed file1.gz.
-# If two files are specified, then they are  uncompressed  (if
-# necessary) and fed to cmp or diff.  The exit status from cmp
-# or diff is preserved.
-
-PATH="/usr/bin:$PATH"; export PATH
-prog=`echo $0 | sed 's|.*/||'`
-case "$prog" in
-  *cmp) comp=${CMP-cmp}   ;;
-  *)    comp=${DIFF-diff} ;;
-esac
-
-OPTIONS=
-FILES=
-for ARG
-do
-    case "$ARG" in
-    -*)	OPTIONS="$OPTIONS $ARG";;
-     *)	if test -f "$ARG"; then
-            FILES="$FILES $ARG"
-        else
-            echo "${prog}: $ARG not found or not a regular file"
-	    exit 1
-        fi ;;
-    esac
-done
-if test -z "$FILES"; then
-	echo "Usage: $prog [${comp}_options] file [file]"
-	exit 1
-fi
-tmp=`tempfile -d /tmp -p bz` || {
-      echo 'cannot create a temporary file' >&2
-      exit 1
-}
-set $FILES
-if test $# -eq 1; then
-	FILE=`echo "$1" | sed 's/.bz2$//'`
-	bzip2 -cd "$FILE.bz2" | $comp $OPTIONS - "$FILE"
-	STAT="$?"
-
-elif test $# -eq 2; then
-	case "$1" in
-        *.bz2)
-                case "$2" in
-	        *.bz2)
-			F=`echo "$2" | sed 's|.*/||;s|.bz2$||'`
-                        bzip2 -cdfq "$2" > $tmp
-                        bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp
-                        STAT="$?"
-			/bin/rm -f $tmp;;
-
-                *)      bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
-                        STAT="$?";;
-                esac;;
-        *)      case "$2" in
-	        *.bz2)
-                        bzip2 -cdfq "$2" | $comp $OPTIONS "$1" -
-                        STAT="$?";;
-                *)      $comp $OPTIONS "$1" "$2"
-                        STAT="$?";;
-                esac;;
-	esac
-        exit "$STAT"
-else
-	echo "Usage: $prog [${comp}_options] file [file]"
-	exit 1
-fi
Index: trunk/minix/commands/bzip2-1.0.3/bzdiff.1
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzdiff.1	(revision 9)
+++ 	(revision )
@@ -1,47 +1,0 @@
-\"Shamelessly copied from zmore.1 by Philippe Troin <phil@fifi.org>
-\"for Debian GNU/Linux
-.TH BZDIFF 1
-.SH NAME
-bzcmp, bzdiff \- compare bzip2 compressed files
-.SH SYNOPSIS
-.B bzcmp
-[ cmp_options ] file1
-[ file2 ]
-.br
-.B bzdiff
-[ diff_options ] file1
-[ file2 ]
-.SH DESCRIPTION
-.I  Bzcmp
-and 
-.I bzdiff
-are used to invoke the
-.I cmp
-or the
-.I diff
-program on bzip2 compressed files.  All options specified are passed
-directly to
-.I cmp
-or
-.IR diff "."
-If only 1 file is specified, then the files compared are
-.I file1
-and an uncompressed
-.IR file1 ".bz2."
-If two files are specified, then they are uncompressed if necessary and fed to
-.I cmp
-or
-.IR diff "."
-The exit status from 
-.I cmp
-or
-.I diff
-is preserved.
-.SH "SEE ALSO"
-cmp(1), diff(1), bzmore(1), bzless(1), bzgrep(1), bzip2(1)
-.SH BUGS
-Messages from the
-.I cmp
-or
-.I diff
-programs refer to temporary filenames instead of those specified.
Index: trunk/minix/commands/bzip2-1.0.3/bzgrep
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzgrep	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-#!/bin/sh
-
-# Bzgrep wrapped for bzip2, 
-# adapted from zgrep by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
-## zgrep notice:
-## zgrep -- a wrapper around a grep program that decompresses files as needed
-## Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
-
-PATH="/usr/bin:$PATH"; export PATH
-
-prog=`echo $0 | sed 's|.*/||'`
-case "$prog" in
-	*egrep)	grep=${EGREP-egrep}	;;
-	*fgrep)	grep=${FGREP-fgrep}	;;
-	*)	grep=${GREP-grep}	;;
-esac
-pat=""
-while test $# -ne 0; do
-  case "$1" in
-  -e | -f) opt="$opt $1"; shift; pat="$1"
-           if test "$grep" = grep; then  # grep is buggy with -e on SVR4
-             grep=egrep
-           fi;;
-  -A | -B) opt="$opt $1 $2"; shift;;
-  -*)	   opt="$opt $1";;
-   *)      if test -z "$pat"; then
-	     pat="$1"
-	   else
-	     break;
-           fi;;
-  esac
-  shift
-done
-
-if test -z "$pat"; then
-  echo "grep through bzip2 files"
-  echo "usage: $prog [grep_options] pattern [files]"
-  exit 1
-fi
-
-list=0
-silent=0
-op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
-case "$op" in
-  *l*) list=1
-esac
-case "$op" in
-  *h*) silent=1
-esac
-
-if test $# -eq 0; then
-  bzip2 -cdfq | $grep $opt "$pat"
-  exit $?
-fi
-
-res=0
-for i do
-  if test -f "$i"; then :; else if test -f "$i.bz2"; then i="$i.bz2"; fi; fi
-  if test $list -eq 1; then
-    bzip2 -cdfq "$i" | $grep $opt "$pat" 2>&1 > /dev/null && echo $i
-    r=$?
-  elif test $# -eq 1 -o $silent -eq 1; then
-    bzip2 -cdfq "$i" | $grep $opt "$pat"
-    r=$?
-  else
-    bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${i}:|"
-    r=$?
-  fi
-  test "$r" -ne 0 && res="$r"
-done
-exit $res
Index: trunk/minix/commands/bzip2-1.0.3/bzgrep.1
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzgrep.1	(revision 9)
+++ 	(revision )
@@ -1,56 +1,0 @@
-\"Shamelessly copied from zmore.1 by Philippe Troin <phil@fifi.org>
-\"for Debian GNU/Linux
-.TH BZGREP 1
-.SH NAME
-bzgrep, bzfgrep, bzegrep \- search possibly bzip2 compressed files for a regular expression
-.SH SYNOPSIS
-.B bzgrep
-[ grep_options ]
-.BI  [\ -e\ ] " pattern"
-.IR filename ".\|.\|."
-.br
-.B bzegrep
-[ egrep_options ]
-.BI  [\ -e\ ] " pattern"
-.IR filename ".\|.\|."
-.br
-.B bzfgrep
-[ fgrep_options ]
-.BI  [\ -e\ ] " pattern"
-.IR filename ".\|.\|."
-.SH DESCRIPTION
-.IR  Bzgrep
-is used to invoke the
-.I grep
-on bzip2-compressed files. All options specified are passed directly to
-.I grep.
-If no file is specified, then the standard input is decompressed
-if necessary and fed to grep.
-Otherwise the given files are uncompressed if necessary and fed to
-.I grep.
-.PP
-If
-.I bzgrep
-is invoked as
-.I bzegrep
-or
-.I bzfgrep
-then
-.I egrep
-or
-.I fgrep
-is used instead of
-.I grep.
-If the GREP environment variable is set,
-.I bzgrep
-uses it as the
-.I grep
-program to be invoked. For example:
-
-    for sh:  GREP=fgrep  bzgrep string files
-    for csh: (setenv GREP fgrep; bzgrep string files)
-.SH AUTHOR
-Charles Levert (charles@comm.polymtl.ca). Adapted to bzip2 by Philippe
-Troin <phil@fifi.org> for Debian GNU/Linux.
-.SH "SEE ALSO"
-grep(1), egrep(1), fgrep(1), bzdiff(1), bzmore(1), bzless(1), bzip2(1)
Index: trunk/minix/commands/bzip2-1.0.3/bzip.css
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzip.css	(revision 9)
+++ 	(revision )
@@ -1,74 +1,0 @@
-/* Colours:
-#74240f  dark brown      h1, h2, h3, h4
-#336699  medium blue     links
-#339999  turquoise       link hover colour
-#202020  almost black    general text
-#761596  purple          md5sum text
-#626262  dark gray       pre border
-#eeeeee  very light gray pre background
-#f2f2f9  very light blue nav table background
-#3366cc  medium blue     nav table border
-*/
-
-a, a:link, a:visited, a:active { color: #336699; }
-a:hover { color: #339999; }
-
-body { font: 80%/126% sans-serif; }
-h1, h2, h3, h4 { color: #74240f; }
-
-dt { color: #336699; font-weight: bold }
-dd { 
- margin-left: 1.5em; 
- padding-bottom: 0.8em;
-}
-
-/* -- ruler -- */
-div.hr_blue { 
-  height:  3px; 
-  background:#ffffff url("/images/hr_blue.png") repeat-x; }
-div.hr_blue hr { display:none; }
-
-/* release styles */
-#release p { margin-top: 0.4em; }
-#release .md5sum { color: #761596; }
-
-
-/* ------ styles for docs|manuals|howto ------ */
-/* -- lists -- */
-ul  { 
- margin:     0px 4px 16px 16px;
- padding:    0px;
- list-style: url("/images/li-blue.png"); 
-}
-ul li { 
- margin-bottom: 10px;
-}
-ul ul	{ 
- list-style-type:  none; 
- list-style-image: none; 
- margin-left:      0px; 
-}
-
-/* header / footer nav tables */
-table.nav {
- border:     solid 1px #3366cc;
- background: #f2f2f9;
- background-color: #f2f2f9;
- margin-bottom: 0.5em;
-}
-/* don't have underlined links in chunked nav menus */
-table.nav a { text-decoration: none; }
-table.nav a:hover { text-decoration: underline; }
-table.nav td { font-size: 85%; }
-
-code, tt, pre { font-size: 120%; }
-code, tt { color: #761596; }
-
-div.literallayout, pre.programlisting, pre.screen {
- color:      #000000;
- padding:    0.5em;
- background: #eeeeee;
- border:     1px solid #626262;
- background-color: #eeeeee;
- margin: 4px 0px 4px 0px; 
-}
Index: trunk/minix/commands/bzip2-1.0.3/bzip2.1
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzip2.1	(revision 9)
+++ 	(revision )
@@ -1,454 +1,0 @@
-.PU
-.TH bzip2 1
-.SH NAME
-bzip2, bunzip2 \- a block-sorting file compressor, v1.0.3
-.br
-bzcat \- decompresses files to stdout
-.br
-bzip2recover \- recovers data from damaged bzip2 files
-
-.SH SYNOPSIS
-.ll +8
-.B bzip2
-.RB [ " \-cdfkqstvzVL123456789 " ]
-[
-.I "filenames \&..."
-]
-.ll -8
-.br
-.B bunzip2
-.RB [ " \-fkvsVL " ]
-[ 
-.I "filenames \&..."
-]
-.br
-.B bzcat
-.RB [ " \-s " ]
-[ 
-.I "filenames \&..."
-]
-.br
-.B bzip2recover
-.I "filename"
-
-.SH DESCRIPTION
-.I bzip2
-compresses files using the Burrows-Wheeler block sorting
-text compression algorithm, and Huffman coding.  Compression is
-generally considerably better than that achieved by more conventional
-LZ77/LZ78-based compressors, and approaches the performance of the PPM
-family of statistical compressors.
-
-The command-line options are deliberately very similar to 
-those of 
-.I GNU gzip, 
-but they are not identical.
-
-.I bzip2
-expects a list of file names to accompany the
-command-line flags.  Each file is replaced by a compressed version of
-itself, with the name "original_name.bz2".  
-Each compressed file
-has the same modification date, permissions, and, when possible,
-ownership as the corresponding original, so that these properties can
-be correctly restored at decompression time.  File name handling is
-naive in the sense that there is no mechanism for preserving original
-file names, permissions, ownerships or dates in filesystems which lack
-these concepts, or have serious file name length restrictions, such as
-MS-DOS.
-
-.I bzip2
-and
-.I bunzip2
-will by default not overwrite existing
-files.  If you want this to happen, specify the \-f flag.
-
-If no file names are specified,
-.I bzip2
-compresses from standard
-input to standard output.  In this case,
-.I bzip2
-will decline to
-write compressed output to a terminal, as this would be entirely
-incomprehensible and therefore pointless.
-
-.I bunzip2
-(or
-.I bzip2 \-d) 
-decompresses all
-specified files.  Files which were not created by 
-.I bzip2
-will be detected and ignored, and a warning issued.  
-.I bzip2
-attempts to guess the filename for the decompressed file 
-from that of the compressed file as follows:
-
-       filename.bz2    becomes   filename
-       filename.bz     becomes   filename
-       filename.tbz2   becomes   filename.tar
-       filename.tbz    becomes   filename.tar
-       anyothername    becomes   anyothername.out
-
-If the file does not end in one of the recognised endings, 
-.I .bz2, 
-.I .bz, 
-.I .tbz2
-or
-.I .tbz, 
-.I bzip2 
-complains that it cannot
-guess the name of the original file, and uses the original name
-with
-.I .out
-appended.
-
-As with compression, supplying no
-filenames causes decompression from 
-standard input to standard output.
-
-.I bunzip2 
-will correctly decompress a file which is the
-concatenation of two or more compressed files.  The result is the
-concatenation of the corresponding uncompressed files.  Integrity
-testing (\-t) 
-of concatenated 
-compressed files is also supported.
-
-You can also compress or decompress files to the standard output by
-giving the \-c flag.  Multiple files may be compressed and
-decompressed like this.  The resulting outputs are fed sequentially to
-stdout.  Compression of multiple files 
-in this manner generates a stream
-containing multiple compressed file representations.  Such a stream
-can be decompressed correctly only by
-.I bzip2 
-version 0.9.0 or
-later.  Earlier versions of
-.I bzip2
-will stop after decompressing
-the first file in the stream.
-
-.I bzcat
-(or
-.I bzip2 -dc) 
-decompresses all specified files to
-the standard output.
-
-.I bzip2
-will read arguments from the environment variables
-.I BZIP2
-and
-.I BZIP,
-in that order, and will process them
-before any arguments read from the command line.  This gives a 
-convenient way to supply default arguments.
-
-Compression is always performed, even if the compressed 
-file is slightly
-larger than the original.  Files of less than about one hundred bytes
-tend to get larger, since the compression mechanism has a constant
-overhead in the region of 50 bytes.  Random data (including the output
-of most file compressors) is coded at about 8.05 bits per byte, giving
-an expansion of around 0.5%.
-
-As a self-check for your protection, 
-.I 
-bzip2
-uses 32-bit CRCs to
-make sure that the decompressed version of a file is identical to the
-original.  This guards against corruption of the compressed data, and
-against undetected bugs in
-.I bzip2
-(hopefully very unlikely).  The
-chances of data corruption going undetected is microscopic, about one
-chance in four billion for each file processed.  Be aware, though, that
-the check occurs upon decompression, so it can only tell you that
-something is wrong.  It can't help you 
-recover the original uncompressed
-data.  You can use 
-.I bzip2recover
-to try to recover data from
-damaged files.
-
-Return values: 0 for a normal exit, 1 for environmental problems (file
-not found, invalid flags, I/O errors, &c), 2 to indicate a corrupt
-compressed file, 3 for an internal consistency error (eg, bug) which
-caused
-.I bzip2
-to panic.
-
-.SH OPTIONS
-.TP
-.B \-c --stdout
-Compress or decompress to standard output.
-.TP
-.B \-d --decompress
-Force decompression.  
-.I bzip2, 
-.I bunzip2 
-and
-.I bzcat 
-are
-really the same program, and the decision about what actions to take is
-done on the basis of which name is used.  This flag overrides that
-mechanism, and forces 
-.I bzip2
-to decompress.
-.TP
-.B \-z --compress
-The complement to \-d: forces compression, regardless of the
-invocation name.
-.TP
-.B \-t --test
-Check integrity of the specified file(s), but don't decompress them.
-This really performs a trial decompression and throws away the result.
-.TP
-.B \-f --force
-Force overwrite of output files.  Normally,
-.I bzip2 
-will not overwrite
-existing output files.  Also forces 
-.I bzip2 
-to break hard links
-to files, which it otherwise wouldn't do.
-
-bzip2 normally declines to decompress files which don't have the
-correct magic header bytes.  If forced (-f), however, it will pass
-such files through unmodified.  This is how GNU gzip behaves.
-.TP
-.B \-k --keep
-Keep (don't delete) input files during compression
-or decompression.
-.TP
-.B \-s --small
-Reduce memory usage, for compression, decompression and testing.  Files
-are decompressed and tested using a modified algorithm which only
-requires 2.5 bytes per block byte.  This means any file can be
-decompressed in 2300k of memory, albeit at about half the normal speed.
-
-During compression, \-s selects a block size of 200k, which limits
-memory use to around the same figure, at the expense of your compression
-ratio.  In short, if your machine is low on memory (8 megabytes or
-less), use \-s for everything.  See MEMORY MANAGEMENT below.
-.TP
-.B \-q --quiet
-Suppress non-essential warning messages.  Messages pertaining to
-I/O errors and other critical events will not be suppressed.
-.TP
-.B \-v --verbose
-Verbose mode -- show the compression ratio for each file processed.
-Further \-v's increase the verbosity level, spewing out lots of
-information which is primarily of interest for diagnostic purposes.
-.TP
-.B \-L --license -V --version
-Display the software version, license terms and conditions.
-.TP
-.B \-1 (or \-\-fast) to \-9 (or \-\-best)
-Set the block size to 100 k, 200 k ..  900 k when compressing.  Has no
-effect when decompressing.  See MEMORY MANAGEMENT below.
-The \-\-fast and \-\-best aliases are primarily for GNU gzip 
-compatibility.  In particular, \-\-fast doesn't make things
-significantly faster.  
-And \-\-best merely selects the default behaviour.
-.TP
-.B \--
-Treats all subsequent arguments as file names, even if they start
-with a dash.  This is so you can handle files with names beginning
-with a dash, for example: bzip2 \-- \-myfilename.
-.TP
-.B \--repetitive-fast --repetitive-best
-These flags are redundant in versions 0.9.5 and above.  They provided
-some coarse control over the behaviour of the sorting algorithm in
-earlier versions, which was sometimes useful.  0.9.5 and above have an
-improved algorithm which renders these flags irrelevant.
-
-.SH MEMORY MANAGEMENT
-.I bzip2 
-compresses large files in blocks.  The block size affects
-both the compression ratio achieved, and the amount of memory needed for
-compression and decompression.  The flags \-1 through \-9
-specify the block size to be 100,000 bytes through 900,000 bytes (the
-default) respectively.  At decompression time, the block size used for
-compression is read from the header of the compressed file, and
-.I bunzip2
-then allocates itself just enough memory to decompress
-the file.  Since block sizes are stored in compressed files, it follows
-that the flags \-1 to \-9 are irrelevant to and so ignored
-during decompression.
-
-Compression and decompression requirements, 
-in bytes, can be estimated as:
-
-       Compression:   400k + ( 8 x block size )
-
-       Decompression: 100k + ( 4 x block size ), or
-                      100k + ( 2.5 x block size )
-
-Larger block sizes give rapidly diminishing marginal returns.  Most of
-the compression comes from the first two or three hundred k of block
-size, a fact worth bearing in mind when using
-.I bzip2
-on small machines.
-It is also important to appreciate that the decompression memory
-requirement is set at compression time by the choice of block size.
-
-For files compressed with the default 900k block size,
-.I bunzip2
-will require about 3700 kbytes to decompress.  To support decompression
-of any file on a 4 megabyte machine, 
-.I bunzip2
-has an option to
-decompress using approximately half this amount of memory, about 2300
-kbytes.  Decompression speed is also halved, so you should use this
-option only where necessary.  The relevant flag is -s.
-
-In general, try and use the largest block size memory constraints allow,
-since that maximises the compression achieved.  Compression and
-decompression speed are virtually unaffected by block size.
-
-Another significant point applies to files which fit in a single block
--- that means most files you'd encounter using a large block size.  The
-amount of real memory touched is proportional to the size of the file,
-since the file is smaller than a block.  For example, compressing a file
-20,000 bytes long with the flag -9 will cause the compressor to
-allocate around 7600k of memory, but only touch 400k + 20000 * 8 = 560
-kbytes of it.  Similarly, the decompressor will allocate 3700k but only
-touch 100k + 20000 * 4 = 180 kbytes.
-
-Here is a table which summarises the maximum memory usage for different
-block sizes.  Also recorded is the total compressed size for 14 files of
-the Calgary Text Compression Corpus totalling 3,141,622 bytes.  This
-column gives some feel for how compression varies with block size.
-These figures tend to understate the advantage of larger block sizes for
-larger files, since the Corpus is dominated by smaller files.
-
-           Compress   Decompress   Decompress   Corpus
-    Flag     usage      usage       -s usage     Size
-
-     -1      1200k       500k         350k      914704
-     -2      2000k       900k         600k      877703
-     -3      2800k      1300k         850k      860338
-     -4      3600k      1700k        1100k      846899
-     -5      4400k      2100k        1350k      845160
-     -6      5200k      2500k        1600k      838626
-     -7      6100k      2900k        1850k      834096
-     -8      6800k      3300k        2100k      828642
-     -9      7600k      3700k        2350k      828642
-
-.SH RECOVERING DATA FROM DAMAGED FILES
-.I bzip2
-compresses files in blocks, usually 900kbytes long.  Each
-block is handled independently.  If a media or transmission error causes
-a multi-block .bz2
-file to become damaged, it may be possible to
-recover data from the undamaged blocks in the file.
-
-The compressed representation of each block is delimited by a 48-bit
-pattern, which makes it possible to find the block boundaries with
-reasonable certainty.  Each block also carries its own 32-bit CRC, so
-damaged blocks can be distinguished from undamaged ones.
-
-.I bzip2recover
-is a simple program whose purpose is to search for
-blocks in .bz2 files, and write each block out into its own .bz2 
-file.  You can then use
-.I bzip2 
-\-t
-to test the
-integrity of the resulting files, and decompress those which are
-undamaged.
-
-.I bzip2recover
-takes a single argument, the name of the damaged file, 
-and writes a number of files "rec00001file.bz2",
-"rec00002file.bz2", etc, containing the  extracted  blocks.
-The  output  filenames  are  designed  so  that the use of
-wildcards in subsequent processing -- for example,  
-"bzip2 -dc  rec*file.bz2 > recovered_data" -- processes the files in
-the correct order.
-
-.I bzip2recover
-should be of most use dealing with large .bz2
-files,  as  these will contain many blocks.  It is clearly
-futile to use it on damaged single-block  files,  since  a
-damaged  block  cannot  be recovered.  If you wish to minimise 
-any potential data loss through media  or  transmission errors, 
-you might consider compressing with a smaller
-block size.
-
-.SH PERFORMANCE NOTES
-The sorting phase of compression gathers together similar strings in the
-file.  Because of this, files containing very long runs of repeated
-symbols, like "aabaabaabaab ..."  (repeated several hundred times) may
-compress more slowly than normal.  Versions 0.9.5 and above fare much
-better than previous versions in this respect.  The ratio between
-worst-case and average-case compression time is in the region of 10:1.
-For previous versions, this figure was more like 100:1.  You can use the
-\-vvvv option to monitor progress in great detail, if you want.
-
-Decompression speed is unaffected by these phenomena.
-
-.I bzip2
-usually allocates several megabytes of memory to operate
-in, and then charges all over it in a fairly random fashion.  This means
-that performance, both for compressing and decompressing, is largely
-determined by the speed at which your machine can service cache misses.
-Because of this, small changes to the code to reduce the miss rate have
-been observed to give disproportionately large performance improvements.
-I imagine 
-.I bzip2
-will perform best on machines with very large caches.
-
-.SH CAVEATS
-I/O error messages are not as helpful as they could be.
-.I bzip2
-tries hard to detect I/O errors and exit cleanly, but the details of
-what the problem is sometimes seem rather misleading.
-
-This manual page pertains to version 1.0.3 of
-.I bzip2.  
-Compressed data created by this version is entirely forwards and
-backwards compatible with the previous public releases, versions
-0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1 and 1.0.2, but with the following
-exception: 0.9.0 and above can correctly decompress multiple
-concatenated compressed files.  0.1pl2 cannot do this; it will stop
-after decompressing just the first file in the stream.
-
-.I bzip2recover
-versions prior to 1.0.2 used 32-bit integers to represent
-bit positions in compressed files, so they could not handle compressed
-files more than 512 megabytes long.  Versions 1.0.2 and above use
-64-bit ints on some platforms which support them (GNU supported
-targets, and Windows).  To establish whether or not bzip2recover was
-built with such a limitation, run it without arguments.  In any event
-you can build yourself an unlimited version if you can recompile it
-with MaybeUInt64 set to be an unsigned 64-bit integer.
-
-
-
-.SH AUTHOR
-Julian Seward, jsewardbzip.org.
-
-http://www.bzip.org
-
-The ideas embodied in
-.I bzip2
-are due to (at least) the following
-people: Michael Burrows and David Wheeler (for the block sorting
-transformation), David Wheeler (again, for the Huffman coder), Peter
-Fenwick (for the structured coding model in the original
-.I bzip,
-and many refinements), and Alistair Moffat, Radford Neal and Ian Witten
-(for the arithmetic coder in the original
-.I bzip).  
-I am much
-indebted for their help, support and advice.  See the manual in the
-source distribution for pointers to sources of documentation.  Christian
-von Roques encouraged me to look for faster sorting algorithms, so as to
-speed up compression.  Bela Lubkin encouraged me to improve the
-worst-case compression performance.  
-Donna Robinson XMLised the documentation.
-The bz* scripts are derived from those of GNU gzip.
-Many people sent patches, helped
-with portability problems, lent machines, gave advice and were generally
-helpful.
Index: trunk/minix/commands/bzip2-1.0.3/bzip2.1.preformatted
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzip2.1.preformatted	(revision 9)
+++ 	(revision )
@@ -1,399 +1,0 @@
-bzip2(1)                                                 bzip2(1)
-
-
-
-NNAAMMEE
-       bzip2, bunzip2 â a blockâsorting file compressor, v1.0.3
-       bzcat â decompresses files to stdout
-       bzip2recover â recovers data from damaged bzip2 files
-
-
-SSYYNNOOPPSSIISS
-       bbzziipp22 [ ââccddffkkqqssttvvzzVVLL112233445566778899 ] [ _f_i_l_e_n_a_m_e_s _._._.  ]
-       bbuunnzziipp22 [ ââffkkvvssVVLL ] [ _f_i_l_e_n_a_m_e_s _._._.  ]
-       bbzzccaatt [ ââss ] [ _f_i_l_e_n_a_m_e_s _._._.  ]
-       bbzziipp22rreeccoovveerr _f_i_l_e_n_a_m_e
-
-
-DDEESSCCRRIIPPTTIIOONN
-       _b_z_i_p_2  compresses  files  using  the BurrowsâWheeler block
-       sorting text compression algorithm,  and  Huffman  coding.
-       Compression  is  generally  considerably  better than that
-       achieved by more conventional LZ77/LZ78âbased compressors,
-       and  approaches  the performance of the PPM family of staÂ­
-       tistical compressors.
-
-       The commandâline options are deliberately very similar  to
-       those of _G_N_U _g_z_i_p_, but they are not identical.
-
-       _b_z_i_p_2  expects  a list of file names to accompany the comÂ­
-       mandâline flags.  Each file is replaced  by  a  compressed
-       version  of  itself,  with  the  name "original_name.bz2".
-       Each compressed file has the same modification date,  perÂ­
-       missions, and, when possible, ownership as the correspondÂ­
-       ing original, so that these properties  can  be  correctly
-       restored  at  decompression  time.   File name handling is
-       naive in the sense that there is no mechanism for preservÂ­
-       ing  original file names, permissions, ownerships or dates
-       in filesystems which lack these concepts, or have  serious
-       file name length restrictions, such as MSâDOS.
-
-       _b_z_i_p_2  and  _b_u_n_z_i_p_2 will by default not overwrite existing
-       files.  If you want this to happen, specify the âf flag.
-
-       If no file names  are  specified,  _b_z_i_p_2  compresses  from
-       standard  input  to  standard output.  In this case, _b_z_i_p_2
-       will decline to write compressed output to a terminal,  as
-       this  would  be  entirely  incomprehensible  and therefore
-       pointless.
-
-       _b_u_n_z_i_p_2 (or _b_z_i_p_2 _â_d_) decompresses  all  specified  files.
-       Files which were not created by _b_z_i_p_2 will be detected and
-       ignored, and a warning issued.  _b_z_i_p_2  attempts  to  guess
-       the  filename  for  the decompressed file from that of the
-       compressed file as follows:
-
-              filename.bz2    becomes   filename
-              filename.bz     becomes   filename
-              filename.tbz2   becomes   filename.tar
-              filename.tbz    becomes   filename.tar
-              anyothername    becomes   anyothername.out
-
-       If the file does not end in one of the recognised endings,
-       _._b_z_2_,  _._b_z_,  _._t_b_z_2 or _._t_b_z_, _b_z_i_p_2 complains that it cannot
-       guess the name of the original file, and uses the original
-       name with _._o_u_t appended.
-
-       As  with compression, supplying no filenames causes decomÂ­
-       pression from standard input to standard output.
-
-       _b_u_n_z_i_p_2 will correctly decompress a file which is the conÂ­
-       catenation of two or more compressed files.  The result is
-       the concatenation of the corresponding uncompressed files.
-       Integrity testing (ât) of concatenated compressed files is
-       also supported.
-
-       You can also compress or decompress files to the  standard
-       output  by giving the âc flag.  Multiple files may be comÂ­
-       pressed and decompressed like this.  The resulting outputs
-       are  fed  sequentially to stdout.  Compression of multiple
-       files in this manner generates a stream containing  multiÂ­
-       ple compressed file representations.  Such a stream can be
-       decompressed correctly only  by  _b_z_i_p_2  version  0.9.0  or
-       later.   Earlier  versions of _b_z_i_p_2 will stop after decomÂ­
-       pressing the first file in the stream.
-
-       _b_z_c_a_t (or _b_z_i_p_2 _â_d_c_) decompresses all specified  files  to
-       the standard output.
-
-       _b_z_i_p_2  will  read arguments from the environment variables
-       _B_Z_I_P_2 and _B_Z_I_P_, in  that  order,  and  will  process  them
-       before  any  arguments  read  from the command line.  This
-       gives a convenient way to supply default arguments.
-
-       Compression is always performed, even  if  the  compressed
-       file  is slightly larger than the original.  Files of less
-       than about one hundred bytes tend to get larger, since the
-       compression  mechanism  has  a  constant  overhead  in the
-       region of 50 bytes.  Random data (including the output  of
-       most  file  compressors)  is  coded at about 8.05 bits per
-       byte, giving an expansion of around 0.5%.
-
-       As a selfâcheck for your  protection,  _b_z_i_p_2  uses  32âbit
-       CRCs  to make sure that the decompressed version of a file
-       is identical to the original.  This guards against corrupÂ­
-       tion  of  the compressed data, and against undetected bugs
-       in _b_z_i_p_2 (hopefully very unlikely).  The chances  of  data
-       corruption  going  undetected  is  microscopic,  about one
-       chance in four billion for each file processed.  Be aware,
-       though,  that  the  check occurs upon decompression, so it
-       can only tell you that something is wrong.  It canât  help
-       you  recover  the original uncompressed data.  You can use
-       _b_z_i_p_2_r_e_c_o_v_e_r to try to recover data from damaged files.
-
-       Return values: 0 for a normal exit,  1  for  environmental
-       problems  (file not found, invalid flags, I/O errors, &c),
-       2 to indicate a corrupt compressed file, 3 for an internal
-       consistency error (eg, bug) which caused _b_z_i_p_2 to panic.
-
-
-OOPPTTIIOONNSS
-       ââcc ââââssttddoouutt
-              Compress or decompress to standard output.
-
-       ââdd ââââddeeccoommpprreessss
-              Force  decompression.  _b_z_i_p_2_, _b_u_n_z_i_p_2 and _b_z_c_a_t are
-              really the same program,  and  the  decision  about
-              what  actions to take is done on the basis of which
-              name is used.  This flag overrides that  mechanism,
-              and forces _b_z_i_p_2 to decompress.
-
-       ââzz ââââccoommpprreessss
-              The   complement   to   âd:   forces   compression,
-              regardless of the invocation name.
-
-       ââtt ââââtteesstt
-              Check integrity of the specified file(s), but donât
-              decompress  them.   This  really  performs  a trial
-              decompression and throws away the result.
-
-       ââff ââââffoorrccee
-              Force overwrite of output files.   Normally,  _b_z_i_p_2
-              will  not  overwrite  existing  output files.  Also
-              forces _b_z_i_p_2 to break hard links to files, which it
-              otherwise wouldnât do.
-
-              bzip2  normally  declines to decompress files which
-              donât have the  correct  magic  header  bytes.   If
-              forced  (âf),  however,  it  will  pass  such files
-              through unmodified.  This is how GNU gzip  behaves.
-
-       ââkk ââââkkeeeepp
-              Keep  (donât delete) input files during compression
-              or decompression.
-
-       ââss ââââssmmaallll
-              Reduce memory usage, for compression, decompression
-              and  testing.   Files  are  decompressed and tested
-              using a modified algorithm which only requires  2.5
-              bytes  per  block byte.  This means any file can be
-              decompressed in 2300k of memory,  albeit  at  about
-              half the normal speed.
-
-              During  compression,  âs  selects  a  block size of
-              200k, which limits memory use to  around  the  same
-              figure,  at  the expense of your compression ratio.
-              In short, if your  machine  is  low  on  memory  (8
-              megabytes  or  less),  use  âs for everything.  See
-              MEMORY MANAGEMENT below.
-
-       ââqq ââââqquuiieett
-              Suppress nonâessential warning messages.   Messages
-              pertaining  to I/O errors and other critical events
-              will not be suppressed.
-
-       ââvv ââââvveerrbboossee
-              Verbose mode ââ show the compression ratio for each
-              file  processed.   Further  âvâs  increase the verÂ­
-              bosity level, spewing out lots of information which
-              is primarily of interest for diagnostic purposes.
-
-       ââLL ââââlliicceennssee ââVV ââââvveerrssiioonn
-              Display  the  software  version,  license terms and
-              conditions.
-
-       ââ11 ((oorr ââââffaasstt)) ttoo ââ99 ((oorr ââââbbeesstt))
-              Set the block size to 100 k, 200 k ..  900  k  when
-              compressing.   Has  no  effect  when decompressing.
-              See MEMORY MANAGEMENT below.  The ââfast and ââbest
-              aliases  are  primarily for GNU gzip compatibility.
-              In particular, ââfast doesnât make things  signifiÂ­
-              cantly  faster.   And  ââbest  merely  selects  the
-              default behaviour.
-
-       ââââ     Treats all subsequent arguments as file names, even
-              if they start with a dash.  This is so you can hanÂ­
-              dle files with names beginning  with  a  dash,  for
-              example: bzip2 ââ âmyfilename.
-
-       âââârreeppeettiittiivveeââffaasstt âââârreeppeettiittiivveeââbbeesstt
-              These  flags  are  redundant  in versions 0.9.5 and
-              above.  They provided some coarse control over  the
-              behaviour  of the sorting algorithm in earlier verÂ­
-              sions, which was sometimes useful.  0.9.5 and above
-              have  an  improved  algorithm  which  renders these
-              flags irrelevant.
-
-
-MMEEMMOORRYY MMAANNAAGGEEMMEENNTT
-       _b_z_i_p_2 compresses large files in blocks.   The  block  size
-       affects  both  the  compression  ratio  achieved,  and the
-       amount of memory needed for compression and decompression.
-       The  flags  â1  through  â9  specify  the block size to be
-       100,000 bytes through 900,000 bytes (the default)  respecÂ­
-       tively.   At  decompression  time, the block size used for
-       compression is read from  the  header  of  the  compressed
-       file, and _b_u_n_z_i_p_2 then allocates itself just enough memory
-       to decompress the file.  Since block sizes are  stored  in
-       compressed  files,  it follows that the flags â1 to â9 are
-       irrelevant to and so ignored during decompression.
-
-       Compression and decompression requirements, in bytes,  can
-       be estimated as:
-
-              Compression:   400k + ( 8 x block size )
-
-              Decompression: 100k + ( 4 x block size ), or
-                             100k + ( 2.5 x block size )
-
-       Larger  block  sizes  give  rapidly  diminishing  marginal
-       returns.  Most of the compression comes from the first two
-       or  three hundred k of block size, a fact worth bearing in
-       mind when using _b_z_i_p_2  on  small  machines.   It  is  also
-       important  to  appreciate  that  the  decompression memory
-       requirement is set at compression time by  the  choice  of
-       block size.
-
-       For  files  compressed  with  the default 900k block size,
-       _b_u_n_z_i_p_2 will require about 3700 kbytes to decompress.   To
-       support decompression of any file on a 4 megabyte machine,
-       _b_u_n_z_i_p_2 has an option to  decompress  using  approximately
-       half this amount of memory, about 2300 kbytes.  DecompresÂ­
-       sion speed is also halved, so you should use  this  option
-       only where necessary.  The relevant flag is âs.
-
-       In general, try and use the largest block size memory conÂ­
-       straints  allow,  since  that  maximises  the  compression
-       achieved.   Compression and decompression speed are virtuÂ­
-       ally unaffected by block size.
-
-       Another significant point applies to files which fit in  a
-       single  block  ââ  that  means  most files youâd encounter
-       using a large block  size.   The  amount  of  real  memory
-       touched is proportional to the size of the file, since the
-       file is smaller than a block.  For example, compressing  a
-       file  20,000  bytes  long  with the flag â9 will cause the
-       compressor to allocate around 7600k of  memory,  but  only
-       touch 400k + 20000 * 8 = 560 kbytes of it.  Similarly, the
-       decompressor will allocate 3700k but  only  touch  100k  +
-       20000 * 4 = 180 kbytes.
-
-       Here  is a table which summarises the maximum memory usage
-       for different block sizes.  Also  recorded  is  the  total
-       compressed  size for 14 files of the Calgary Text CompresÂ­
-       sion Corpus totalling 3,141,622 bytes.  This column  gives
-       some  feel  for  how  compression  varies with block size.
-       These figures tend to understate the advantage  of  larger
-       block  sizes  for  larger files, since the Corpus is domiÂ­
-       nated by smaller files.
-
-                  Compress   Decompress   Decompress   Corpus
-           Flag     usage      usage       âs usage     Size
-
-            â1      1200k       500k         350k      914704
-            â2      2000k       900k         600k      877703
-            â3      2800k      1300k         850k      860338
-            â4      3600k      1700k        1100k      846899
-            â5      4400k      2100k        1350k      845160
-            â6      5200k      2500k        1600k      838626
-            â7      6100k      2900k        1850k      834096
-            â8      6800k      3300k        2100k      828642
-            â9      7600k      3700k        2350k      828642
-
-
-RREECCOOVVEERRIINNGG DDAATTAA FFRROOMM DDAAMMAAGGEEDD FFIILLEESS
-       _b_z_i_p_2 compresses files in blocks, usually 900kbytes  long.
-       Each block is handled independently.  If a media or transÂ­
-       mission error causes a multiâblock  .bz2  file  to  become
-       damaged,  it  may  be  possible  to  recover data from the
-       undamaged blocks in the file.
-
-       The compressed representation of each block  is  delimited
-       by  a  48âbit pattern, which makes it possible to find the
-       block boundaries with reasonable  certainty.   Each  block
-       also  carries its own 32âbit CRC, so damaged blocks can be
-       distinguished from undamaged ones.
-
-       _b_z_i_p_2_r_e_c_o_v_e_r is a  simple  program  whose  purpose  is  to
-       search  for blocks in .bz2 files, and write each block out
-       into its own .bz2 file.  You can then use _b_z_i_p_2 ât to test
-       the integrity of the resulting files, and decompress those
-       which are undamaged.
-
-       _b_z_i_p_2_r_e_c_o_v_e_r takes a single argument, the name of the damÂ­
-       aged    file,    and    writes    a    number   of   files
-       "rec00001file.bz2",  "rec00002file.bz2",  etc,  containing
-       the   extracted   blocks.   The   output   filenames   are
-       designed  so  that the use of wildcards in subsequent proÂ­
-       cessing  ââ for example, "bzip2 âdc  rec*file.bz2 > recovÂ­
-       ered_data" ââ processes the files in the correct order.
-
-       _b_z_i_p_2_r_e_c_o_v_e_r should be of most use dealing with large .bz2
-       files,  as  these will contain many blocks.  It is clearly
-       futile to use it on damaged singleâblock  files,  since  a
-       damaged  block  cannot  be recovered.  If you wish to minÂ­
-       imise any potential data loss through media  or  transmisÂ­
-       sion errors, you might consider compressing with a smaller
-       block size.
-
-
-PPEERRFFOORRMMAANNCCEE NNOOTTEESS
-       The sorting phase of compression gathers together  similar
-       strings  in  the  file.  Because of this, files containing
-       very long runs of  repeated  symbols,  like  "aabaabaabaab
-       ..."   (repeated  several hundred times) may compress more
-       slowly than normal.  Versions 0.9.5 and  above  fare  much
-       better  than previous versions in this respect.  The ratio
-       between worstâcase and averageâcase compression time is in
-       the  region  of  10:1.  For previous versions, this figure
-       was more like 100:1.  You can use the âvvvv option to monÂ­
-       itor progress in great detail, if you want.
-
-       Decompression speed is unaffected by these phenomena.
-
-       _b_z_i_p_2  usually  allocates  several  megabytes of memory to
-       operate in, and then charges all over it in a fairly  ranÂ­
-       dom  fashion.   This means that performance, both for comÂ­
-       pressing and decompressing, is largely determined  by  the
-       speed  at  which  your  machine  can service cache misses.
-       Because of this, small changes to the code to  reduce  the
-       miss  rate  have  been observed to give disproportionately
-       large performance improvements.  I imagine _b_z_i_p_2 will perÂ­
-       form best on machines with very large caches.
-
-
-CCAAVVEEAATTSS
-       I/O  error  messages  are not as helpful as they could be.
-       _b_z_i_p_2 tries hard to detect I/O errors  and  exit  cleanly,
-       but  the  details  of  what  the problem is sometimes seem
-       rather misleading.
-
-       This manual page pertains to version 1.0.3 of _b_z_i_p_2_.  ComÂ­
-       pressed  data created by this version is entirely forwards
-       and  backwards  compatible  with   the   previous   public
-       releases,  versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1 and
-       1.0.2, but with the following exception: 0.9.0  and  above
-       can  correctly decompress multiple concatenated compressed
-       files.  0.1pl2 cannot do this; it will stop  after  decomÂ­
-       pressing just the first file in the stream.
-
-       _b_z_i_p_2_r_e_c_o_v_e_r  versions prior to 1.0.2 used 32âbit integers
-       to represent bit positions in compressed  files,  so  they
-       could  not handle compressed files more than 512 megabytes
-       long.  Versions 1.0.2 and above use 64âbit  ints  on  some
-       platforms  which  support them (GNU supported targets, and
-       Windows).  To establish whether or  not  bzip2recover  was
-       built  with  such  a limitation, run it without arguments.
-       In any event you can build yourself an  unlimited  version
-       if  you  can  recompile  it  with MaybeUInt64 set to be an
-       unsigned 64âbit integer.
-
-
-
-
-AAUUTTHHOORR
-       Julian Seward, jsewardbzip.org.
-
-       http://www.bzip.org
-
-       The ideas embodied in _b_z_i_p_2 are due to (at least) the folÂ­
-       lowing  people: Michael Burrows and David Wheeler (for the
-       block sorting transformation), David Wheeler  (again,  for
-       the Huffman coder), Peter Fenwick (for the structured codÂ­
-       ing model in the original _b_z_i_p_, and many refinements), and
-       Alistair  Moffat,  Radford  Neal  and  Ian Witten (for the
-       arithmetic  coder  in  the  original  _b_z_i_p_)_.   I  am  much
-       indebted for their help, support and advice.  See the manÂ­
-       ual in the source distribution for pointers to sources  of
-       documentation.  Christian von Roques encouraged me to look
-       for faster sorting algorithms, so as to speed up  compresÂ­
-       sion.  Bela Lubkin encouraged me to improve the worstâcase
-       compression performance.  Donna Robinson XMLised the docuÂ­
-       mentation.   The bz* scripts are derived from those of GNU
-       gzip.  Many people sent patches, helped  with  portability
-       problems,  lent  machines,  gave advice and were generally
-       helpful.
-
-
-
-                                                         bzip2(1)
Index: trunk/minix/commands/bzip2-1.0.3/bzip2.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzip2.c	(revision 9)
+++ 	(revision )
@@ -1,2111 +1,0 @@
-
-/*-----------------------------------------------------------*/
-/*--- A block-sorting, lossless compressor        bzip2.c ---*/
-/*-----------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-
-/*----------------------------------------------------*/
-/*--- IMPORTANT                                    ---*/
-/*----------------------------------------------------*/
-
-/*--
-   WARNING:
-      This program and library (attempts to) compress data by 
-      performing several non-trivial transformations on it.  
-      Unless you are 100% familiar with *all* the algorithms 
-      contained herein, and with the consequences of modifying them, 
-      you should NOT meddle with the compression or decompression 
-      machinery.  Incorrect changes can and very likely *will* 
-      lead to disasterous loss of data.
-
-   DISCLAIMER:
-      I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
-      USE OF THIS PROGRAM, HOWSOEVER CAUSED.
-
-      Every compression of a file implies an assumption that the
-      compressed file can be decompressed to reproduce the original.
-      Great efforts in design, coding and testing have been made to
-      ensure that this program works correctly.  However, the
-      complexity of the algorithms, and, in particular, the presence
-      of various special cases in the code which occur with very low
-      but non-zero probability make it impossible to rule out the
-      possibility of bugs remaining in the program.  DO NOT COMPRESS
-      ANY DATA WITH THIS PROGRAM AND/OR LIBRARY UNLESS YOU ARE PREPARED 
-      TO ACCEPT THE POSSIBILITY, HOWEVER SMALL, THAT THE DATA WILL 
-      NOT BE RECOVERABLE.
-
-      That is not to say this program is inherently unreliable.
-      Indeed, I very much hope the opposite is true.  bzip2/libbzip2
-      has been carefully constructed and extensively tested.
-
-   PATENTS:
-      To the best of my knowledge, bzip2/libbzip2 does not use any 
-      patented algorithms.  However, I do not have the resources 
-      available to carry out a full patent search.  Therefore I cannot 
-      give any guarantee of the above statement.
---*/
-
-
-
-/*----------------------------------------------------*/
-/*--- and now for something much more pleasant :-) ---*/
-/*----------------------------------------------------*/
-
-/*---------------------------------------------*/
-/*--
-  Place a 1 beside your platform, and 0 elsewhere.
---*/
-
-/*--
-  Generic 32-bit Unix.
-  Also works on 64-bit Unix boxes.
-  This is the default.
---*/
-#define BZ_UNIX      1
-
-/*--
-  Win32, as seen by Jacob Navia's excellent
-  port of (Chris Fraser & David Hanson)'s excellent
-  lcc compiler.  Or with MS Visual C.
-  This is selected automatically if compiled by a compiler which
-  defines _WIN32, not including the Cygwin GCC.
---*/
-#define BZ_LCCWIN32  0
-
-#if defined(_WIN32) && !defined(__CYGWIN__)
-#undef  BZ_LCCWIN32
-#define BZ_LCCWIN32 1
-#undef  BZ_UNIX
-#define BZ_UNIX 0
-#endif
-
-
-/*---------------------------------------------*/
-/*--
-  Some stuff for all platforms.
---*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <math.h>
-#include <errno.h>
-#include <ctype.h>
-#include "bzlib.h"
-
-#define ERROR_IF_EOF(i)       { if ((i) == EOF)  ioError(); }
-#define ERROR_IF_NOT_ZERO(i)  { if ((i) != 0)    ioError(); }
-#define ERROR_IF_MINUS_ONE(i) { if ((i) == (-1)) ioError(); }
-
-
-/*---------------------------------------------*/
-/*--
-   Platform-specific stuff.
---*/
-
-#if BZ_UNIX
-#   include <fcntl.h>
-#   include <sys/types.h>
-#   include <utime.h>
-#   include <unistd.h>
-#   include <sys/stat.h>
-#   include <sys/times.h>
-
-#   define PATH_SEP    '/'
-#   define MY_LSTAT    lstat
-#   define MY_STAT     stat
-#   define MY_S_ISREG  S_ISREG
-#   define MY_S_ISDIR  S_ISDIR
-
-#   define APPEND_FILESPEC(root, name) \
-      root=snocString((root), (name))
-
-#   define APPEND_FLAG(root, name) \
-      root=snocString((root), (name))
-
-#   define SET_BINARY_MODE(fd) /**/
-
-#   ifdef __GNUC__
-#      define NORETURN __attribute__ ((noreturn))
-#   else
-#      define NORETURN /**/
-#   endif
-
-#   ifdef __DJGPP__
-#     include <io.h>
-#     include <fcntl.h>
-#     undef MY_LSTAT
-#     undef MY_STAT
-#     define MY_LSTAT stat
-#     define MY_STAT stat
-#     undef SET_BINARY_MODE
-#     define SET_BINARY_MODE(fd)                        \
-        do {                                            \
-           int retVal = setmode ( fileno ( fd ),        \
-                                  O_BINARY );           \
-           ERROR_IF_MINUS_ONE ( retVal );               \
-        } while ( 0 )
-#   endif
-
-#   ifdef __CYGWIN__
-#     include <io.h>
-#     include <fcntl.h>
-#     undef SET_BINARY_MODE
-#     define SET_BINARY_MODE(fd)                        \
-        do {                                            \
-           int retVal = setmode ( fileno ( fd ),        \
-                                  O_BINARY );           \
-           ERROR_IF_MINUS_ONE ( retVal );               \
-        } while ( 0 )
-#   endif
-#endif /* BZ_UNIX */
-
-
-
-#if BZ_LCCWIN32
-#   include <io.h>
-#   include <fcntl.h>
-#   include <sys\stat.h>
-
-#   define NORETURN       /**/
-#   define PATH_SEP       '\\'
-#   define MY_LSTAT       _stat
-#   define MY_STAT        _stat
-#   define MY_S_ISREG(x)  ((x) & _S_IFREG)
-#   define MY_S_ISDIR(x)  ((x) & _S_IFDIR)
-
-#   define APPEND_FLAG(root, name) \
-      root=snocString((root), (name))
-
-#   define APPEND_FILESPEC(root, name)                \
-      root = snocString ((root), (name))
-
-#   define SET_BINARY_MODE(fd)                        \
-      do {                                            \
-         int retVal = setmode ( fileno ( fd ),        \
-                                O_BINARY );           \
-         ERROR_IF_MINUS_ONE ( retVal );               \
-      } while ( 0 )
-
-#endif /* BZ_LCCWIN32 */
-
-
-/*---------------------------------------------*/
-/*--
-  Some more stuff for all platforms :-)
---*/
-
-typedef char            Char;
-typedef unsigned char   Bool;
-typedef unsigned char   UChar;
-typedef int             Int32;
-typedef unsigned int    UInt32;
-typedef short           Int16;
-typedef unsigned short  UInt16;
-                                       
-#define True  ((Bool)1)
-#define False ((Bool)0)
-
-/*--
-  IntNative is your platform's `native' int size.
-  Only here to avoid probs with 64-bit platforms.
---*/
-typedef int IntNative;
-
-
-/*---------------------------------------------------*/
-/*--- Misc (file handling) data decls             ---*/
-/*---------------------------------------------------*/
-
-Int32   verbosity;
-Bool    keepInputFiles, smallMode, deleteOutputOnInterrupt;
-Bool    forceOverwrite, testFailsExist, unzFailsExist, noisy;
-Int32   numFileNames, numFilesProcessed, blockSize100k;
-Int32   exitValue;
-
-/*-- source modes; F==file, I==stdin, O==stdout --*/
-#define SM_I2O           1
-#define SM_F2O           2
-#define SM_F2F           3
-
-/*-- operation modes --*/
-#define OM_Z             1
-#define OM_UNZ           2
-#define OM_TEST          3
-
-Int32   opMode;
-Int32   srcMode;
-
-#define FILE_NAME_LEN 1034
-
-Int32   longestFileName;
-Char    inName [FILE_NAME_LEN];
-Char    outName[FILE_NAME_LEN];
-Char    tmpName[FILE_NAME_LEN];
-Char    *progName;
-Char    progNameReally[FILE_NAME_LEN];
-FILE    *outputHandleJustInCase;
-Int32   workFactor;
-
-static void    panic                 ( Char* )   NORETURN;
-static void    ioError               ( void )    NORETURN;
-static void    outOfMemory           ( void )    NORETURN;
-static void    configError           ( void )    NORETURN;
-static void    crcError              ( void )    NORETURN;
-static void    cleanUpAndFail        ( Int32 )   NORETURN;
-static void    compressedStreamEOF   ( void )    NORETURN;
-
-static void    copyFileName ( Char*, Char* );
-static void*   myMalloc     ( Int32 );
-
-
-
-/*---------------------------------------------------*/
-/*--- An implementation of 64-bit ints.  Sigh.    ---*/
-/*--- Roll on widespread deployment of ANSI C9X ! ---*/
-/*---------------------------------------------------*/
-
-typedef
-   struct { UChar b[8]; } 
-   UInt64;
-
-
-static
-void uInt64_from_UInt32s ( UInt64* n, UInt32 lo32, UInt32 hi32 )
-{
-   n->b[7] = (UChar)((hi32 >> 24) & 0xFF);
-   n->b[6] = (UChar)((hi32 >> 16) & 0xFF);
-   n->b[5] = (UChar)((hi32 >> 8)  & 0xFF);
-   n->b[4] = (UChar) (hi32        & 0xFF);
-   n->b[3] = (UChar)((lo32 >> 24) & 0xFF);
-   n->b[2] = (UChar)((lo32 >> 16) & 0xFF);
-   n->b[1] = (UChar)((lo32 >> 8)  & 0xFF);
-   n->b[0] = (UChar) (lo32        & 0xFF);
-}
-
-
-static
-double uInt64_to_double ( UInt64* n )
-{
-   Int32  i;
-   double base = 1.0;
-   double sum  = 0.0;
-   for (i = 0; i < 8; i++) {
-      sum  += base * (double)(n->b[i]);
-      base *= 256.0;
-   }
-   return sum;
-}
-
-
-static
-Bool uInt64_isZero ( UInt64* n )
-{
-   Int32 i;
-   for (i = 0; i < 8; i++)
-      if (n->b[i] != 0) return 0;
-   return 1;
-}
-
-
-/* Divide *n by 10, and return the remainder.  */
-static 
-Int32 uInt64_qrm10 ( UInt64* n )
-{
-   UInt32 rem, tmp;
-   Int32  i;
-   rem = 0;
-   for (i = 7; i >= 0; i--) {
-      tmp = rem * 256 + n->b[i];
-      n->b[i] = tmp / 10;
-      rem = tmp % 10;
-   }
-   return rem;
-}
-
-
-/* ... and the Whole Entire Point of all this UInt64 stuff is
-   so that we can supply the following function.
-*/
-static
-void uInt64_toAscii ( char* outbuf, UInt64* n )
-{
-   Int32  i, q;
-   UChar  buf[32];
-   Int32  nBuf   = 0;
-   UInt64 n_copy = *n;
-   do {
-      q = uInt64_qrm10 ( &n_copy );
-      buf[nBuf] = q + '0';
-      nBuf++;
-   } while (!uInt64_isZero(&n_copy));
-   outbuf[nBuf] = 0;
-   for (i = 0; i < nBuf; i++) 
-      outbuf[i] = buf[nBuf-i-1];
-}
-
-
-/*---------------------------------------------------*/
-/*--- Processing of complete files and streams    ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-static 
-Bool myfeof ( FILE* f )
-{
-   Int32 c = fgetc ( f );
-   if (c == EOF) return True;
-   ungetc ( c, f );
-   return False;
-}
-
-
-/*---------------------------------------------*/
-static 
-void compressStream ( FILE *stream, FILE *zStream )
-{
-   BZFILE* bzf = NULL;
-   UChar   ibuf[5000];
-   Int32   nIbuf;
-   UInt32  nbytes_in_lo32, nbytes_in_hi32;
-   UInt32  nbytes_out_lo32, nbytes_out_hi32;
-   Int32   bzerr, bzerr_dummy, ret;
-
-   SET_BINARY_MODE(stream);
-   SET_BINARY_MODE(zStream);
-
-   if (ferror(stream)) goto errhandler_io;
-   if (ferror(zStream)) goto errhandler_io;
-
-   bzf = BZ2_bzWriteOpen ( &bzerr, zStream, 
-                           blockSize100k, verbosity, workFactor );   
-   if (bzerr != BZ_OK) goto errhandler;
-
-   if (verbosity >= 2) fprintf ( stderr, "\n" );
-
-   while (True) {
-
-      if (myfeof(stream)) break;
-      nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream );
-      if (ferror(stream)) goto errhandler_io;
-      if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
-      if (bzerr != BZ_OK) goto errhandler;
-
-   }
-
-   BZ2_bzWriteClose64 ( &bzerr, bzf, 0, 
-                        &nbytes_in_lo32, &nbytes_in_hi32,
-                        &nbytes_out_lo32, &nbytes_out_hi32 );
-   if (bzerr != BZ_OK) goto errhandler;
-
-   if (ferror(zStream)) goto errhandler_io;
-   ret = fflush ( zStream );
-   if (ret == EOF) goto errhandler_io;
-   if (zStream != stdout) {
-      ret = fclose ( zStream );
-      outputHandleJustInCase = NULL;
-      if (ret == EOF) goto errhandler_io;
-   }
-   outputHandleJustInCase = NULL;
-   if (ferror(stream)) goto errhandler_io;
-   ret = fclose ( stream );
-   if (ret == EOF) goto errhandler_io;
-
-   if (verbosity >= 1) {
-      if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
-	 fprintf ( stderr, " no data compressed.\n");
-      } else {
-	 Char   buf_nin[32], buf_nout[32];
-	 UInt64 nbytes_in,   nbytes_out;
-	 double nbytes_in_d, nbytes_out_d;
-	 uInt64_from_UInt32s ( &nbytes_in, 
-			       nbytes_in_lo32, nbytes_in_hi32 );
-	 uInt64_from_UInt32s ( &nbytes_out, 
-			       nbytes_out_lo32, nbytes_out_hi32 );
-	 nbytes_in_d  = uInt64_to_double ( &nbytes_in );
-	 nbytes_out_d = uInt64_to_double ( &nbytes_out );
-	 uInt64_toAscii ( buf_nin, &nbytes_in );
-	 uInt64_toAscii ( buf_nout, &nbytes_out );
-	 fprintf ( stderr, "%6.3f:1, %6.3f bits/byte, "
-		   "%5.2f%% saved, %s in, %s out.\n",
-		   nbytes_in_d / nbytes_out_d,
-		   (8.0 * nbytes_out_d) / nbytes_in_d,
-		   100.0 * (1.0 - nbytes_out_d / nbytes_in_d),
-		   buf_nin,
-		   buf_nout
-		 );
-      }
-   }
-
-   return;
-
-   errhandler:
-   BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1, 
-                        &nbytes_in_lo32, &nbytes_in_hi32,
-                        &nbytes_out_lo32, &nbytes_out_hi32 );
-   switch (bzerr) {
-      case BZ_CONFIG_ERROR:
-         configError(); break;
-      case BZ_MEM_ERROR:
-         outOfMemory (); break;
-      case BZ_IO_ERROR:
-         errhandler_io:
-         ioError(); break;
-      default:
-         panic ( "compress:unexpected error" );
-   }
-
-   panic ( "compress:end" );
-   /*notreached*/
-}
-
-
-
-/*---------------------------------------------*/
-static 
-Bool uncompressStream ( FILE *zStream, FILE *stream )
-{
-   BZFILE* bzf = NULL;
-   Int32   bzerr, bzerr_dummy, ret, nread, streamNo, i;
-   UChar   obuf[5000];
-   UChar   unused[BZ_MAX_UNUSED];
-   Int32   nUnused;
-   void*   unusedTmpV;
-   UChar*  unusedTmp;
-
-   nUnused = 0;
-   streamNo = 0;
-
-   SET_BINARY_MODE(stream);
-   SET_BINARY_MODE(zStream);
-
-   if (ferror(stream)) goto errhandler_io;
-   if (ferror(zStream)) goto errhandler_io;
-
-   while (True) {
-
-      bzf = BZ2_bzReadOpen ( 
-               &bzerr, zStream, verbosity, 
-               (int)smallMode, unused, nUnused
-            );
-      if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
-      streamNo++;
-
-      while (bzerr == BZ_OK) {
-         nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
-         if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat;
-         if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
-            fwrite ( obuf, sizeof(UChar), nread, stream );
-         if (ferror(stream)) goto errhandler_io;
-      }
-      if (bzerr != BZ_STREAM_END) goto errhandler;
-
-      BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
-      if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
-
-      unusedTmp = (UChar*)unusedTmpV;
-      for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
-
-      BZ2_bzReadClose ( &bzerr, bzf );
-      if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
-
-      if (nUnused == 0 && myfeof(zStream)) break;
-   }
-
-   closeok:
-   if (ferror(zStream)) goto errhandler_io;
-   ret = fclose ( zStream );
-   if (ret == EOF) goto errhandler_io;
-
-   if (ferror(stream)) goto errhandler_io;
-   ret = fflush ( stream );
-   if (ret != 0) goto errhandler_io;
-   if (stream != stdout) {
-      ret = fclose ( stream );
-      outputHandleJustInCase = NULL;
-      if (ret == EOF) goto errhandler_io;
-   }
-   outputHandleJustInCase = NULL;
-   if (verbosity >= 2) fprintf ( stderr, "\n    " );
-   return True;
-
-   trycat: 
-   if (forceOverwrite) {
-      rewind(zStream);
-      while (True) {
-      	 if (myfeof(zStream)) break;
-      	 nread = fread ( obuf, sizeof(UChar), 5000, zStream );
-      	 if (ferror(zStream)) goto errhandler_io;
-      	 if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
-      	 if (ferror(stream)) goto errhandler_io;
-      }
-      goto closeok;
-   }
-  
-   errhandler:
-   BZ2_bzReadClose ( &bzerr_dummy, bzf );
-   switch (bzerr) {
-      case BZ_CONFIG_ERROR:
-         configError(); break;
-      case BZ_IO_ERROR:
-         errhandler_io:
-         ioError(); break;
-      case BZ_DATA_ERROR:
-         crcError();
-      case BZ_MEM_ERROR:
-         outOfMemory();
-      case BZ_UNEXPECTED_EOF:
-         compressedStreamEOF();
-      case BZ_DATA_ERROR_MAGIC:
-         if (zStream != stdin) fclose(zStream);
-         if (stream != stdout) fclose(stream);
-         if (streamNo == 1) {
-            return False;
-         } else {
-            if (noisy)
-            fprintf ( stderr, 
-                      "\n%s: %s: trailing garbage after EOF ignored\n",
-                      progName, inName );
-            return True;       
-         }
-      default:
-         panic ( "decompress:unexpected error" );
-   }
-
-   panic ( "decompress:end" );
-   return True; /*notreached*/
-}
-
-
-/*---------------------------------------------*/
-static 
-Bool testStream ( FILE *zStream )
-{
-   BZFILE* bzf = NULL;
-   Int32   bzerr, bzerr_dummy, ret, nread, streamNo, i;
-   UChar   obuf[5000];
-   UChar   unused[BZ_MAX_UNUSED];
-   Int32   nUnused;
-   void*   unusedTmpV;
-   UChar*  unusedTmp;
-
-   nUnused = 0;
-   streamNo = 0;
-
-   SET_BINARY_MODE(zStream);
-   if (ferror(zStream)) goto errhandler_io;
-
-   while (True) {
-
-      bzf = BZ2_bzReadOpen ( 
-               &bzerr, zStream, verbosity, 
-               (int)smallMode, unused, nUnused
-            );
-      if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
-      streamNo++;
-
-      while (bzerr == BZ_OK) {
-         nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
-         if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler;
-      }
-      if (bzerr != BZ_STREAM_END) goto errhandler;
-
-      BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
-      if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
-
-      unusedTmp = (UChar*)unusedTmpV;
-      for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
-
-      BZ2_bzReadClose ( &bzerr, bzf );
-      if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
-      if (nUnused == 0 && myfeof(zStream)) break;
-
-   }
-
-   if (ferror(zStream)) goto errhandler_io;
-   ret = fclose ( zStream );
-   if (ret == EOF) goto errhandler_io;
-
-   if (verbosity >= 2) fprintf ( stderr, "\n    " );
-   return True;
-
-   errhandler:
-   BZ2_bzReadClose ( &bzerr_dummy, bzf );
-   if (verbosity == 0) 
-      fprintf ( stderr, "%s: %s: ", progName, inName );
-   switch (bzerr) {
-      case BZ_CONFIG_ERROR:
-         configError(); break;
-      case BZ_IO_ERROR:
-         errhandler_io:
-         ioError(); break;
-      case BZ_DATA_ERROR:
-         fprintf ( stderr,
-                   "data integrity (CRC) error in data\n" );
-         return False;
-      case BZ_MEM_ERROR:
-         outOfMemory();
-      case BZ_UNEXPECTED_EOF:
-         fprintf ( stderr,
-                   "file ends unexpectedly\n" );
-         return False;
-      case BZ_DATA_ERROR_MAGIC:
-         if (zStream != stdin) fclose(zStream);
-         if (streamNo == 1) {
-          fprintf ( stderr, 
-                    "bad magic number (file not created by bzip2)\n" );
-            return False;
-         } else {
-            if (noisy)
-            fprintf ( stderr, 
-                      "trailing garbage after EOF ignored\n" );
-            return True;       
-         }
-      default:
-         panic ( "test:unexpected error" );
-   }
-
-   panic ( "test:end" );
-   return True; /*notreached*/
-}
-
-
-/*---------------------------------------------------*/
-/*--- Error [non-] handling grunge                ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-static
-void setExit ( Int32 v )
-{
-   if (v > exitValue) exitValue = v;
-}
-
-
-/*---------------------------------------------*/
-static 
-void cadvise ( void )
-{
-   if (noisy)
-   fprintf (
-      stderr,
-      "\nIt is possible that the compressed file(s) have become corrupted.\n"
-        "You can use the -tvv option to test integrity of such files.\n\n"
-        "You can use the `bzip2recover' program to attempt to recover\n"
-        "data from undamaged sections of corrupted files.\n\n"
-    );
-}
-
-
-/*---------------------------------------------*/
-static 
-void showFileNames ( void )
-{
-   if (noisy)
-   fprintf (
-      stderr,
-      "\tInput file = %s, output file = %s\n",
-      inName, outName 
-   );
-}
-
-
-/*---------------------------------------------*/
-static 
-void cleanUpAndFail ( Int32 ec )
-{
-   IntNative      retVal;
-   struct MY_STAT statBuf;
-
-   if ( srcMode == SM_F2F 
-        && opMode != OM_TEST
-        && deleteOutputOnInterrupt ) {
-
-      /* Check whether input file still exists.  Delete output file
-         only if input exists to avoid loss of data.  Joerg Prante, 5
-         January 2002.  (JRS 06-Jan-2002: other changes in 1.0.2 mean
-         this is less likely to happen.  But to be ultra-paranoid, we
-         do the check anyway.)  */
-      retVal = MY_STAT ( inName, &statBuf );
-      if (retVal == 0) {
-         if (noisy)
-            fprintf ( stderr, 
-                      "%s: Deleting output file %s, if it exists.\n",
-                      progName, outName );
-         if (outputHandleJustInCase != NULL)
-            fclose ( outputHandleJustInCase );
-         retVal = remove ( outName );
-         if (retVal != 0)
-            fprintf ( stderr,
-                      "%s: WARNING: deletion of output file "
-                      "(apparently) failed.\n",
-                      progName );
-      } else {
-         fprintf ( stderr,
-                   "%s: WARNING: deletion of output file suppressed\n",
-                    progName );
-         fprintf ( stderr,
-                   "%s:    since input file no longer exists.  Output file\n",
-                   progName );
-         fprintf ( stderr,
-                   "%s:    `%s' may be incomplete.\n",
-                   progName, outName );
-         fprintf ( stderr, 
-                   "%s:    I suggest doing an integrity test (bzip2 -tv)"
-                   " of it.\n",
-                   progName );
-      }
-   }
-
-   if (noisy && numFileNames > 0 && numFilesProcessed < numFileNames) {
-      fprintf ( stderr, 
-                "%s: WARNING: some files have not been processed:\n"
-                "%s:    %d specified on command line, %d not processed yet.\n\n",
-                progName, progName,
-                numFileNames, numFileNames - numFilesProcessed );
-   }
-   setExit(ec);
-   exit(exitValue);
-}
-
-
-/*---------------------------------------------*/
-static 
-void panic ( Char* s )
-{
-   fprintf ( stderr,
-             "\n%s: PANIC -- internal consistency error:\n"
-             "\t%s\n"
-             "\tThis is a BUG.  Please report it to me at:\n"
-             "\tjseward@bzip.org\n",
-             progName, s );
-   showFileNames();
-   cleanUpAndFail( 3 );
-}
-
-
-/*---------------------------------------------*/
-static 
-void crcError ( void )
-{
-   fprintf ( stderr,
-             "\n%s: Data integrity error when decompressing.\n",
-             progName );
-   showFileNames();
-   cadvise();
-   cleanUpAndFail( 2 );
-}
-
-
-/*---------------------------------------------*/
-static 
-void compressedStreamEOF ( void )
-{
-  if (noisy) {
-    fprintf ( stderr,
-	      "\n%s: Compressed file ends unexpectedly;\n\t"
-	      "perhaps it is corrupted?  *Possible* reason follows.\n",
-	      progName );
-    perror ( progName );
-    showFileNames();
-    cadvise();
-  }
-  cleanUpAndFail( 2 );
-}
-
-
-/*---------------------------------------------*/
-static 
-void ioError ( void )
-{
-   fprintf ( stderr,
-             "\n%s: I/O or other error, bailing out.  "
-             "Possible reason follows.\n",
-             progName );
-   perror ( progName );
-   showFileNames();
-   cleanUpAndFail( 1 );
-}
-
-
-/*---------------------------------------------*/
-static 
-void mySignalCatcher ( IntNative n )
-{
-   fprintf ( stderr,
-             "\n%s: Control-C or similar caught, quitting.\n",
-             progName );
-   cleanUpAndFail(1);
-}
-
-
-/*---------------------------------------------*/
-static 
-void mySIGSEGVorSIGBUScatcher ( IntNative n )
-{
-   if (opMode == OM_Z)
-      fprintf ( 
-      stderr,
-      "\n%s: Caught a SIGSEGV or SIGBUS whilst compressing.\n"
-      "\n"
-      "   Possible causes are (most likely first):\n"
-      "   (1) This computer has unreliable memory or cache hardware\n"
-      "       (a surprisingly common problem; try a different machine.)\n"
-      "   (2) A bug in the compiler used to create this executable\n"
-      "       (unlikely, if you didn't compile bzip2 yourself.)\n"
-      "   (3) A real bug in bzip2 -- I hope this should never be the case.\n"
-      "   The user's manual, Section 4.3, has more info on (1) and (2).\n"
-      "   \n"
-      "   If you suspect this is a bug in bzip2, or are unsure about (1)\n"
-      "   or (2), feel free to report it to me at: jseward@bzip.org.\n"
-      "   Section 4.3 of the user's manual describes the info a useful\n"
-      "   bug report should have.  If the manual is available on your\n"
-      "   system, please try and read it before mailing me.  If you don't\n"
-      "   have the manual or can't be bothered to read it, mail me anyway.\n"
-      "\n",
-      progName );
-      else
-      fprintf ( 
-      stderr,
-      "\n%s: Caught a SIGSEGV or SIGBUS whilst decompressing.\n"
-      "\n"
-      "   Possible causes are (most likely first):\n"
-      "   (1) The compressed data is corrupted, and bzip2's usual checks\n"
-      "       failed to detect this.  Try bzip2 -tvv my_file.bz2.\n"
-      "   (2) This computer has unreliable memory or cache hardware\n"
-      "       (a surprisingly common problem; try a different machine.)\n"
-      "   (3) A bug in the compiler used to create this executable\n"
-      "       (unlikely, if you didn't compile bzip2 yourself.)\n"
-      "   (4) A real bug in bzip2 -- I hope this should never be the case.\n"
-      "   The user's manual, Section 4.3, has more info on (2) and (3).\n"
-      "   \n"
-      "   If you suspect this is a bug in bzip2, or are unsure about (2)\n"
-      "   or (3), feel free to report it to me at: jseward@bzip.org.\n"
-      "   Section 4.3 of the user's manual describes the info a useful\n"
-      "   bug report should have.  If the manual is available on your\n"
-      "   system, please try and read it before mailing me.  If you don't\n"
-      "   have the manual or can't be bothered to read it, mail me anyway.\n"
-      "\n",
-      progName );
-
-   showFileNames();
-   if (opMode == OM_Z)
-      cleanUpAndFail( 3 ); else
-      { cadvise(); cleanUpAndFail( 2 ); }
-}
-
-
-/*---------------------------------------------*/
-static 
-void outOfMemory ( void )
-{
-   fprintf ( stderr,
-             "\n%s: couldn't allocate enough memory\n",
-             progName );
-   showFileNames();
-   cleanUpAndFail(1);
-}
-
-
-/*---------------------------------------------*/
-static 
-void configError ( void )
-{
-   fprintf ( stderr,
-             "bzip2: I'm not configured correctly for this platform!\n"
-             "\tI require Int32, Int16 and Char to have sizes\n"
-             "\tof 4, 2 and 1 bytes to run properly, and they don't.\n"
-             "\tProbably you can fix this by defining them correctly,\n"
-             "\tand recompiling.  Bye!\n" );
-   setExit(3);
-   exit(exitValue);
-}
-
-
-/*---------------------------------------------------*/
-/*--- The main driver machinery                   ---*/
-/*---------------------------------------------------*/
-
-/* All rather crufty.  The main problem is that input files
-   are stat()d multiple times before use.  This should be
-   cleaned up. 
-*/
-
-/*---------------------------------------------*/
-static 
-void pad ( Char *s )
-{
-   Int32 i;
-   if ( (Int32)strlen(s) >= longestFileName ) return;
-   for (i = 1; i <= longestFileName - (Int32)strlen(s); i++)
-      fprintf ( stderr, " " );
-}
-
-
-/*---------------------------------------------*/
-static 
-void copyFileName ( Char* to, Char* from ) 
-{
-   if ( strlen(from) > FILE_NAME_LEN-10 )  {
-      fprintf (
-         stderr,
-         "bzip2: file name\n`%s'\n"
-         "is suspiciously (more than %d chars) long.\n"
-         "Try using a reasonable file name instead.  Sorry! :-)\n",
-         from, FILE_NAME_LEN-10
-      );
-      setExit(1);
-      exit(exitValue);
-   }
-
-  strncpy(to,from,FILE_NAME_LEN-10);
-  to[FILE_NAME_LEN-10]='\0';
-}
-
-
-/*---------------------------------------------*/
-static 
-Bool fileExists ( Char* name )
-{
-   FILE *tmp   = fopen ( name, "rb" );
-   Bool exists = (tmp != NULL);
-   if (tmp != NULL) fclose ( tmp );
-   return exists;
-}
-
-
-/*---------------------------------------------*/
-/* Open an output file safely with O_EXCL and good permissions.
-   This avoids a race condition in versions < 1.0.2, in which
-   the file was first opened and then had its interim permissions
-   set safely.  We instead use open() to create the file with
-   the interim permissions required. (--- --- rw-).
-
-   For non-Unix platforms, if we are not worrying about
-   security issues, simple this simply behaves like fopen.
-*/
-FILE* fopen_output_safely ( Char* name, const char* mode )
-{
-#  if BZ_UNIX
-   FILE*     fp;
-   IntNative fh;
-   fh = open(name, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR);
-   if (fh == -1) return NULL;
-   fp = fdopen(fh, mode);
-   if (fp == NULL) close(fh);
-   return fp;
-#  else
-   return fopen(name, mode);
-#  endif
-}
-
-
-/*---------------------------------------------*/
-/*--
-  if in doubt, return True
---*/
-static 
-Bool notAStandardFile ( Char* name )
-{
-   IntNative      i;
-   struct MY_STAT statBuf;
-
-   i = MY_LSTAT ( name, &statBuf );
-   if (i != 0) return True;
-   if (MY_S_ISREG(statBuf.st_mode)) return False;
-   return True;
-}
-
-
-/*---------------------------------------------*/
-/*--
-  rac 11/21/98 see if file has hard links to it
---*/
-static 
-Int32 countHardLinks ( Char* name )
-{  
-   IntNative      i;
-   struct MY_STAT statBuf;
-
-   i = MY_LSTAT ( name, &statBuf );
-   if (i != 0) return 0;
-   return (statBuf.st_nlink - 1);
-}
-
-
-/*---------------------------------------------*/
-/* Copy modification date, access date, permissions and owner from the
-   source to destination file.  We have to copy this meta-info off
-   into fileMetaInfo before starting to compress / decompress it,
-   because doing it afterwards means we get the wrong access time.
-
-   To complicate matters, in compress() and decompress() below, the
-   sequence of tests preceding the call to saveInputFileMetaInfo()
-   involves calling fileExists(), which in turn establishes its result
-   by attempting to fopen() the file, and if successful, immediately
-   fclose()ing it again.  So we have to assume that the fopen() call
-   does not cause the access time field to be updated.
-
-   Reading of the man page for stat() (man 2 stat) on RedHat 7.2 seems
-   to imply that merely doing open() will not affect the access time.
-   Therefore we merely need to hope that the C library only does
-   open() as a result of fopen(), and not any kind of read()-ahead
-   cleverness.
-
-   It sounds pretty fragile to me.  Whether this carries across
-   robustly to arbitrary Unix-like platforms (or even works robustly
-   on this one, RedHat 7.2) is unknown to me.  Nevertheless ...  
-*/
-#if BZ_UNIX
-static 
-struct MY_STAT fileMetaInfo;
-#endif
-
-static 
-void saveInputFileMetaInfo ( Char *srcName )
-{
-#  if BZ_UNIX
-   IntNative retVal;
-   /* Note use of stat here, not lstat. */
-   retVal = MY_STAT( srcName, &fileMetaInfo );
-   ERROR_IF_NOT_ZERO ( retVal );
-#  endif
-}
-
-
-static 
-void applySavedMetaInfoToOutputFile ( Char *dstName )
-{
-#  if BZ_UNIX
-   IntNative      retVal;
-   struct utimbuf uTimBuf;
-
-   uTimBuf.actime = fileMetaInfo.st_atime;
-   uTimBuf.modtime = fileMetaInfo.st_mtime;
-
-   retVal = chmod ( dstName, fileMetaInfo.st_mode );
-   ERROR_IF_NOT_ZERO ( retVal );
-
-   retVal = utime ( dstName, &uTimBuf );
-   ERROR_IF_NOT_ZERO ( retVal );
-
-   retVal = chown ( dstName, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
-   /* chown() will in many cases return with EPERM, which can
-      be safely ignored.
-   */
-#  endif
-}
-
-
-/*---------------------------------------------*/
-static 
-Bool containsDubiousChars ( Char* name )
-{
-#  if BZ_UNIX
-   /* On unix, files can contain any characters and the file expansion
-    * is performed by the shell.
-    */
-   return False;
-#  else /* ! BZ_UNIX */
-   /* On non-unix (Win* platforms), wildcard characters are not allowed in 
-    * filenames.
-    */
-   for (; *name != '\0'; name++)
-      if (*name == '?' || *name == '*') return True;
-   return False;
-#  endif /* BZ_UNIX */
-}
-
-
-/*---------------------------------------------*/
-#define BZ_N_SUFFIX_PAIRS 4
-
-Char* zSuffix[BZ_N_SUFFIX_PAIRS] 
-   = { ".bz2", ".bz", ".tbz2", ".tbz" };
-Char* unzSuffix[BZ_N_SUFFIX_PAIRS] 
-   = { "", "", ".tar", ".tar" };
-
-static 
-Bool hasSuffix ( Char* s, Char* suffix )
-{
-   Int32 ns = strlen(s);
-   Int32 nx = strlen(suffix);
-   if (ns < nx) return False;
-   if (strcmp(s + ns - nx, suffix) == 0) return True;
-   return False;
-}
-
-static 
-Bool mapSuffix ( Char* name, 
-                 Char* oldSuffix, Char* newSuffix )
-{
-   if (!hasSuffix(name,oldSuffix)) return False;
-   name[strlen(name)-strlen(oldSuffix)] = 0;
-   strcat ( name, newSuffix );
-   return True;
-}
-
-
-/*---------------------------------------------*/
-static 
-void compress ( Char *name )
-{
-   FILE  *inStr;
-   FILE  *outStr;
-   Int32 n, i;
-   struct MY_STAT statBuf;
-
-   deleteOutputOnInterrupt = False;
-
-   if (name == NULL && srcMode != SM_I2O)
-      panic ( "compress: bad modes\n" );
-
-   switch (srcMode) {
-      case SM_I2O: 
-         copyFileName ( inName, "(stdin)" );
-         copyFileName ( outName, "(stdout)" ); 
-         break;
-      case SM_F2F: 
-         copyFileName ( inName, name );
-         copyFileName ( outName, name );
-         strcat ( outName, ".bz2" ); 
-         break;
-      case SM_F2O: 
-         copyFileName ( inName, name );
-         copyFileName ( outName, "(stdout)" ); 
-         break;
-   }
-
-   if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
-      if (noisy)
-      fprintf ( stderr, "%s: There are no files matching `%s'.\n",
-                progName, inName );
-      setExit(1);
-      return;
-   }
-   if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
-      fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
-                progName, inName, strerror(errno) );
-      setExit(1);
-      return;
-   }
-   for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++) {
-      if (hasSuffix(inName, zSuffix[i])) {
-         if (noisy)
-         fprintf ( stderr, 
-                   "%s: Input file %s already has %s suffix.\n",
-                   progName, inName, zSuffix[i] );
-         setExit(1);
-         return;
-      }
-   }
-   if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
-      MY_STAT(inName, &statBuf);
-      if ( MY_S_ISDIR(statBuf.st_mode) ) {
-         fprintf( stderr,
-                  "%s: Input file %s is a directory.\n",
-                  progName,inName);
-         setExit(1);
-         return;
-      }
-   }
-   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
-      if (noisy)
-      fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
-                progName, inName );
-      setExit(1);
-      return;
-   }
-   if ( srcMode == SM_F2F && fileExists ( outName ) ) {
-      if (forceOverwrite) {
-	 remove(outName);
-      } else {
-	 fprintf ( stderr, "%s: Output file %s already exists.\n",
-		   progName, outName );
-	 setExit(1);
-	 return;
-      }
-   }
-   if ( srcMode == SM_F2F && !forceOverwrite &&
-        (n=countHardLinks ( inName )) > 0) {
-      fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
-                progName, inName, n, n > 1 ? "s" : "" );
-      setExit(1);
-      return;
-   }
-
-   if ( srcMode == SM_F2F ) {
-      /* Save the file's meta-info before we open it.  Doing it later
-         means we mess up the access times. */
-      saveInputFileMetaInfo ( inName );
-   }
-
-   switch ( srcMode ) {
-
-      case SM_I2O:
-         inStr = stdin;
-         outStr = stdout;
-         if ( isatty ( fileno ( stdout ) ) ) {
-            fprintf ( stderr,
-                      "%s: I won't write compressed data to a terminal.\n",
-                      progName );
-            fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
-                              progName, progName );
-            setExit(1);
-            return;
-         };
-         break;
-
-      case SM_F2O:
-         inStr = fopen ( inName, "rb" );
-         outStr = stdout;
-         if ( isatty ( fileno ( stdout ) ) ) {
-            fprintf ( stderr,
-                      "%s: I won't write compressed data to a terminal.\n",
-                      progName );
-            fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
-                              progName, progName );
-            if ( inStr != NULL ) fclose ( inStr );
-            setExit(1);
-            return;
-         };
-         if ( inStr == NULL ) {
-            fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
-                      progName, inName, strerror(errno) );
-            setExit(1);
-            return;
-         };
-         break;
-
-      case SM_F2F:
-         inStr = fopen ( inName, "rb" );
-         outStr = fopen_output_safely ( outName, "wb" );
-         if ( outStr == NULL) {
-            fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
-                      progName, outName, strerror(errno) );
-            if ( inStr != NULL ) fclose ( inStr );
-            setExit(1);
-            return;
-         }
-         if ( inStr == NULL ) {
-            fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
-                      progName, inName, strerror(errno) );
-            if ( outStr != NULL ) fclose ( outStr );
-            setExit(1);
-            return;
-         };
-         break;
-
-      default:
-         panic ( "compress: bad srcMode" );
-         break;
-   }
-
-   if (verbosity >= 1) {
-      fprintf ( stderr,  "  %s: ", inName );
-      pad ( inName );
-      fflush ( stderr );
-   }
-
-   /*--- Now the input and output handles are sane.  Do the Biz. ---*/
-   outputHandleJustInCase = outStr;
-   deleteOutputOnInterrupt = True;
-   compressStream ( inStr, outStr );
-   outputHandleJustInCase = NULL;
-
-   /*--- If there was an I/O error, we won't get here. ---*/
-   if ( srcMode == SM_F2F ) {
-      applySavedMetaInfoToOutputFile ( outName );
-      deleteOutputOnInterrupt = False;
-      if ( !keepInputFiles ) {
-         IntNative retVal = remove ( inName );
-         ERROR_IF_NOT_ZERO ( retVal );
-      }
-   }
-
-   deleteOutputOnInterrupt = False;
-}
-
-
-/*---------------------------------------------*/
-static 
-void uncompress ( Char *name )
-{
-   FILE  *inStr;
-   FILE  *outStr;
-   Int32 n, i;
-   Bool  magicNumberOK;
-   Bool  cantGuess;
-   struct MY_STAT statBuf;
-
-   deleteOutputOnInterrupt = False;
-
-   if (name == NULL && srcMode != SM_I2O)
-      panic ( "uncompress: bad modes\n" );
-
-   cantGuess = False;
-   switch (srcMode) {
-      case SM_I2O: 
-         copyFileName ( inName, "(stdin)" );
-         copyFileName ( outName, "(stdout)" ); 
-         break;
-      case SM_F2F: 
-         copyFileName ( inName, name );
-         copyFileName ( outName, name );
-         for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
-            if (mapSuffix(outName,zSuffix[i],unzSuffix[i]))
-               goto zzz; 
-         cantGuess = True;
-         strcat ( outName, ".out" );
-         break;
-      case SM_F2O: 
-         copyFileName ( inName, name );
-         copyFileName ( outName, "(stdout)" ); 
-         break;
-   }
-
-   zzz:
-   if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
-      if (noisy)
-      fprintf ( stderr, "%s: There are no files matching `%s'.\n",
-                progName, inName );
-      setExit(1);
-      return;
-   }
-   if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
-      fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
-                progName, inName, strerror(errno) );
-      setExit(1);
-      return;
-   }
-   if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
-      MY_STAT(inName, &statBuf);
-      if ( MY_S_ISDIR(statBuf.st_mode) ) {
-         fprintf( stderr,
-                  "%s: Input file %s is a directory.\n",
-                  progName,inName);
-         setExit(1);
-         return;
-      }
-   }
-   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
-      if (noisy)
-      fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
-                progName, inName );
-      setExit(1);
-      return;
-   }
-   if ( /* srcMode == SM_F2F implied && */ cantGuess ) {
-      if (noisy)
-      fprintf ( stderr, 
-                "%s: Can't guess original name for %s -- using %s\n",
-                progName, inName, outName );
-      /* just a warning, no return */
-   }   
-   if ( srcMode == SM_F2F && fileExists ( outName ) ) {
-      if (forceOverwrite) {
-	remove(outName);
-      } else {
-        fprintf ( stderr, "%s: Output file %s already exists.\n",
-                  progName, outName );
-        setExit(1);
-        return;
-      }
-   }
-   if ( srcMode == SM_F2F && !forceOverwrite &&
-        (n=countHardLinks ( inName ) ) > 0) {
-      fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
-                progName, inName, n, n > 1 ? "s" : "" );
-      setExit(1);
-      return;
-   }
-
-   if ( srcMode == SM_F2F ) {
-      /* Save the file's meta-info before we open it.  Doing it later
-         means we mess up the access times. */
-      saveInputFileMetaInfo ( inName );
-   }
-
-   switch ( srcMode ) {
-
-      case SM_I2O:
-         inStr = stdin;
-         outStr = stdout;
-         if ( isatty ( fileno ( stdin ) ) ) {
-            fprintf ( stderr,
-                      "%s: I won't read compressed data from a terminal.\n",
-                      progName );
-            fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
-                              progName, progName );
-            setExit(1);
-            return;
-         };
-         break;
-
-      case SM_F2O:
-         inStr = fopen ( inName, "rb" );
-         outStr = stdout;
-         if ( inStr == NULL ) {
-            fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
-                      progName, inName, strerror(errno) );
-            if ( inStr != NULL ) fclose ( inStr );
-            setExit(1);
-            return;
-         };
-         break;
-
-      case SM_F2F:
-         inStr = fopen ( inName, "rb" );
-         outStr = fopen_output_safely ( outName, "wb" );
-         if ( outStr == NULL) {
-            fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
-                      progName, outName, strerror(errno) );
-            if ( inStr != NULL ) fclose ( inStr );
-            setExit(1);
-            return;
-         }
-         if ( inStr == NULL ) {
-            fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
-                      progName, inName, strerror(errno) );
-            if ( outStr != NULL ) fclose ( outStr );
-            setExit(1);
-            return;
-         };
-         break;
-
-      default:
-         panic ( "uncompress: bad srcMode" );
-         break;
-   }
-
-   if (verbosity >= 1) {
-      fprintf ( stderr, "  %s: ", inName );
-      pad ( inName );
-      fflush ( stderr );
-   }
-
-   /*--- Now the input and output handles are sane.  Do the Biz. ---*/
-   outputHandleJustInCase = outStr;
-   deleteOutputOnInterrupt = True;
-   magicNumberOK = uncompressStream ( inStr, outStr );
-   outputHandleJustInCase = NULL;
-
-   /*--- If there was an I/O error, we won't get here. ---*/
-   if ( magicNumberOK ) {
-      if ( srcMode == SM_F2F ) {
-         applySavedMetaInfoToOutputFile ( outName );
-         deleteOutputOnInterrupt = False;
-         if ( !keepInputFiles ) {
-            IntNative retVal = remove ( inName );
-            ERROR_IF_NOT_ZERO ( retVal );
-         }
-      }
-   } else {
-      unzFailsExist = True;
-      deleteOutputOnInterrupt = False;
-      if ( srcMode == SM_F2F ) {
-         IntNative retVal = remove ( outName );
-         ERROR_IF_NOT_ZERO ( retVal );
-      }
-   }
-   deleteOutputOnInterrupt = False;
-
-   if ( magicNumberOK ) {
-      if (verbosity >= 1)
-         fprintf ( stderr, "done\n" );
-   } else {
-      setExit(2);
-      if (verbosity >= 1)
-         fprintf ( stderr, "not a bzip2 file.\n" ); else
-         fprintf ( stderr,
-                   "%s: %s is not a bzip2 file.\n",
-                   progName, inName );
-   }
-
-}
-
-
-/*---------------------------------------------*/
-static 
-void testf ( Char *name )
-{
-   FILE *inStr;
-   Bool allOK;
-   struct MY_STAT statBuf;
-
-   deleteOutputOnInterrupt = False;
-
-   if (name == NULL && srcMode != SM_I2O)
-      panic ( "testf: bad modes\n" );
-
-   copyFileName ( outName, "(none)" );
-   switch (srcMode) {
-      case SM_I2O: copyFileName ( inName, "(stdin)" ); break;
-      case SM_F2F: copyFileName ( inName, name ); break;
-      case SM_F2O: copyFileName ( inName, name ); break;
-   }
-
-   if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
-      if (noisy)
-      fprintf ( stderr, "%s: There are no files matching `%s'.\n",
-                progName, inName );
-      setExit(1);
-      return;
-   }
-   if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
-      fprintf ( stderr, "%s: Can't open input %s: %s.\n",
-                progName, inName, strerror(errno) );
-      setExit(1);
-      return;
-   }
-   if ( srcMode != SM_I2O ) {
-      MY_STAT(inName, &statBuf);
-      if ( MY_S_ISDIR(statBuf.st_mode) ) {
-         fprintf( stderr,
-                  "%s: Input file %s is a directory.\n",
-                  progName,inName);
-         setExit(1);
-         return;
-      }
-   }
-
-   switch ( srcMode ) {
-
-      case SM_I2O:
-         if ( isatty ( fileno ( stdin ) ) ) {
-            fprintf ( stderr,
-                      "%s: I won't read compressed data from a terminal.\n",
-                      progName );
-            fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
-                              progName, progName );
-            setExit(1);
-            return;
-         };
-         inStr = stdin;
-         break;
-
-      case SM_F2O: case SM_F2F:
-         inStr = fopen ( inName, "rb" );
-         if ( inStr == NULL ) {
-            fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
-                      progName, inName, strerror(errno) );
-            setExit(1);
-            return;
-         };
-         break;
-
-      default:
-         panic ( "testf: bad srcMode" );
-         break;
-   }
-
-   if (verbosity >= 1) {
-      fprintf ( stderr, "  %s: ", inName );
-      pad ( inName );
-      fflush ( stderr );
-   }
-
-   /*--- Now the input handle is sane.  Do the Biz. ---*/
-   outputHandleJustInCase = NULL;
-   allOK = testStream ( inStr );
-
-   if (allOK && verbosity >= 1) fprintf ( stderr, "ok\n" );
-   if (!allOK) testFailsExist = True;
-}
-
-
-/*---------------------------------------------*/
-static 
-void license ( void )
-{
-   fprintf ( stderr,
-
-    "bzip2, a block-sorting file compressor.  "
-    "Version %s.\n"
-    "   \n"
-    "   Copyright (C) 1996-2005 by Julian Seward.\n"
-    "   \n"
-    "   This program is free software; you can redistribute it and/or modify\n"
-    "   it under the terms set out in the LICENSE file, which is included\n"
-    "   in the bzip2-1.0 source distribution.\n"
-    "   \n"
-    "   This program is distributed in the hope that it will be useful,\n"
-    "   but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-    "   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-    "   LICENSE file for more details.\n"
-    "   \n",
-    BZ2_bzlibVersion()
-   );
-}
-
-
-/*---------------------------------------------*/
-static 
-void usage ( Char *fullProgName )
-{
-   fprintf (
-      stderr,
-      "bzip2, a block-sorting file compressor.  "
-      "Version %s.\n"
-      "\n   usage: %s [flags and input files in any order]\n"
-      "\n"
-      "   -h --help           print this message\n"
-      "   -d --decompress     force decompression\n"
-      "   -z --compress       force compression\n"
-      "   -k --keep           keep (don't delete) input files\n"
-      "   -f --force          overwrite existing output files\n"
-      "   -t --test           test compressed file integrity\n"
-      "   -c --stdout         output to standard out\n"
-      "   -q --quiet          suppress noncritical error messages\n"
-      "   -v --verbose        be verbose (a 2nd -v gives more)\n"
-      "   -L --license        display software version & license\n"
-      "   -V --version        display software version & license\n"
-      "   -s --small          use less memory (at most 2500k)\n"
-      "   -1 .. -9            set block size to 100k .. 900k\n"
-      "   --fast              alias for -1\n"
-      "   --best              alias for -9\n"
-      "\n"
-      "   If invoked as `bzip2', default action is to compress.\n"
-      "              as `bunzip2',  default action is to decompress.\n"
-      "              as `bzcat', default action is to decompress to stdout.\n"
-      "\n"
-      "   If no file names are given, bzip2 compresses or decompresses\n"
-      "   from standard input to standard output.  You can combine\n"
-      "   short flags, so `-v -4' means the same as -v4 or -4v, &c.\n"
-#     if BZ_UNIX
-      "\n"
-#     endif
-      ,
-
-      BZ2_bzlibVersion(),
-      fullProgName
-   );
-}
-
-
-/*---------------------------------------------*/
-static 
-void redundant ( Char* flag )
-{
-   fprintf ( 
-      stderr, 
-      "%s: %s is redundant in versions 0.9.5 and above\n",
-      progName, flag );
-}
-
-
-/*---------------------------------------------*/
-/*--
-  All the garbage from here to main() is purely to
-  implement a linked list of command-line arguments,
-  into which main() copies argv[1 .. argc-1].
-
-  The purpose of this exercise is to facilitate 
-  the expansion of wildcard characters * and ? in 
-  filenames for OSs which don't know how to do it
-  themselves, like MSDOS, Windows 95 and NT.
-
-  The actual Dirty Work is done by the platform-
-  specific macro APPEND_FILESPEC.
---*/
-
-typedef
-   struct zzzz {
-      Char        *name;
-      struct zzzz *link;
-   }
-   Cell;
-
-
-/*---------------------------------------------*/
-static 
-void *myMalloc ( Int32 n )
-{
-   void* p;
-
-   p = malloc ( (size_t)n );
-   if (p == NULL) outOfMemory ();
-   return p;
-}
-
-
-/*---------------------------------------------*/
-static 
-Cell *mkCell ( void )
-{
-   Cell *c;
-
-   c = (Cell*) myMalloc ( sizeof ( Cell ) );
-   c->name = NULL;
-   c->link = NULL;
-   return c;
-}
-
-
-/*---------------------------------------------*/
-static 
-Cell *snocString ( Cell *root, Char *name )
-{
-   if (root == NULL) {
-      Cell *tmp = mkCell();
-      tmp->name = (Char*) myMalloc ( 5 + strlen(name) );
-      strcpy ( tmp->name, name );
-      return tmp;
-   } else {
-      Cell *tmp = root;
-      while (tmp->link != NULL) tmp = tmp->link;
-      tmp->link = snocString ( tmp->link, name );
-      return root;
-   }
-}
-
-
-/*---------------------------------------------*/
-static 
-void addFlagsFromEnvVar ( Cell** argList, Char* varName ) 
-{
-   Int32 i, j, k;
-   Char *envbase, *p;
-
-   envbase = getenv(varName);
-   if (envbase != NULL) {
-      p = envbase;
-      i = 0;
-      while (True) {
-         if (p[i] == 0) break;
-         p += i;
-         i = 0;
-         while (isspace((Int32)(p[0]))) p++;
-         while (p[i] != 0 && !isspace((Int32)(p[i]))) i++;
-         if (i > 0) {
-            k = i; if (k > FILE_NAME_LEN-10) k = FILE_NAME_LEN-10;
-            for (j = 0; j < k; j++) tmpName[j] = p[j];
-            tmpName[k] = 0;
-            APPEND_FLAG(*argList, tmpName);
-         }
-      }
-   }
-}
-
-
-/*---------------------------------------------*/
-#define ISFLAG(s) (strcmp(aa->name, (s))==0)
-
-IntNative main ( IntNative argc, Char *argv[] )
-{
-   Int32  i, j;
-   Char   *tmp;
-   Cell   *argList;
-   Cell   *aa;
-   Bool   decode;
-
-   /*-- Be really really really paranoid :-) --*/
-   if (sizeof(Int32) != 4 || sizeof(UInt32) != 4  ||
-       sizeof(Int16) != 2 || sizeof(UInt16) != 2  ||
-       sizeof(Char)  != 1 || sizeof(UChar)  != 1)
-      configError();
-
-   /*-- Initialise --*/
-   outputHandleJustInCase  = NULL;
-   smallMode               = False;
-   keepInputFiles          = False;
-   forceOverwrite          = False;
-   noisy                   = True;
-   verbosity               = 0;
-   blockSize100k           = 9;
-   testFailsExist          = False;
-   unzFailsExist           = False;
-   numFileNames            = 0;
-   numFilesProcessed       = 0;
-   workFactor              = 30;
-   deleteOutputOnInterrupt = False;
-   exitValue               = 0;
-   i = j = 0; /* avoid bogus warning from egcs-1.1.X */
-
-   /*-- Set up signal handlers for mem access errors --*/
-   signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
-#  if BZ_UNIX
-#  ifndef __DJGPP__
-   signal (SIGBUS,  mySIGSEGVorSIGBUScatcher);
-#  endif
-#  endif
-
-   copyFileName ( inName,  "(none)" );
-   copyFileName ( outName, "(none)" );
-
-   copyFileName ( progNameReally, argv[0] );
-   progName = &progNameReally[0];
-   for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
-      if (*tmp == PATH_SEP) progName = tmp + 1;
-
-
-   /*-- Copy flags from env var BZIP2, and 
-        expand filename wildcards in arg list.
-   --*/
-   argList = NULL;
-   addFlagsFromEnvVar ( &argList,  "BZIP2" );
-   addFlagsFromEnvVar ( &argList,  "BZIP" );
-   for (i = 1; i <= argc-1; i++)
-      APPEND_FILESPEC(argList, argv[i]);
-
-
-   /*-- Find the length of the longest filename --*/
-   longestFileName = 7;
-   numFileNames    = 0;
-   decode          = True;
-   for (aa = argList; aa != NULL; aa = aa->link) {
-      if (ISFLAG("--")) { decode = False; continue; }
-      if (aa->name[0] == '-' && decode) continue;
-      numFileNames++;
-      if (longestFileName < (Int32)strlen(aa->name) )
-         longestFileName = (Int32)strlen(aa->name);
-   }
-
-
-   /*-- Determine source modes; flag handling may change this too. --*/
-   if (numFileNames == 0)
-      srcMode = SM_I2O; else srcMode = SM_F2F;
-
-
-   /*-- Determine what to do (compress/uncompress/test/cat). --*/
-   /*-- Note that subsequent flag handling may change this. --*/
-   opMode = OM_Z;
-
-   if ( (strstr ( progName, "unzip" ) != 0) ||
-        (strstr ( progName, "UNZIP" ) != 0) )
-      opMode = OM_UNZ;
-
-   if ( (strstr ( progName, "z2cat" ) != 0) ||
-        (strstr ( progName, "Z2CAT" ) != 0) ||
-        (strstr ( progName, "zcat" ) != 0)  ||
-        (strstr ( progName, "ZCAT" ) != 0) )  {
-      opMode = OM_UNZ;
-      srcMode = (numFileNames == 0) ? SM_I2O : SM_F2O;
-   }
-
-   if(strstr ( progName, "small" ) != 0) {
-   	smallMode = True;
-   }
-
-
-   /*-- Look at the flags. --*/
-   for (aa = argList; aa != NULL; aa = aa->link) {
-      if (ISFLAG("--")) break;
-      if (aa->name[0] == '-' && aa->name[1] != '-') {
-         for (j = 1; aa->name[j] != '\0'; j++) {
-            switch (aa->name[j]) {
-               case 'c': srcMode          = SM_F2O; break;
-               case 'd': opMode           = OM_UNZ; break;
-               case 'z': opMode           = OM_Z; break;
-               case 'f': forceOverwrite   = True; break;
-               case 't': opMode           = OM_TEST; break;
-               case 'k': keepInputFiles   = True; break;
-               case 's': smallMode        = True; break;
-               case 'q': noisy            = False; break;
-               case '1': blockSize100k    = 1; break;
-               case '2': blockSize100k    = 2; break;
-               case '3': blockSize100k    = 3; break;
-               case '4': blockSize100k    = 4; break;
-               case '5': blockSize100k    = 5; break;
-               case '6': blockSize100k    = 6; break;
-               case '7': blockSize100k    = 7; break;
-               case '8': blockSize100k    = 8; break;
-               case '9': blockSize100k    = 9; break;
-               case 'V':
-               case 'L': license();            break;
-               case 'v': verbosity++; break;
-               case 'h': usage ( progName );
-                         exit ( 0 );
-                         break;
-               default:  fprintf ( stderr, "%s: Bad flag `%s'\n",
-                                   progName, aa->name );
-                         usage ( progName );
-                         exit ( 1 );
-                         break;
-            }
-         }
-      }
-   }
-   
-   /*-- And again ... --*/
-   for (aa = argList; aa != NULL; aa = aa->link) {
-      if (ISFLAG("--")) break;
-      if (ISFLAG("--stdout"))            srcMode          = SM_F2O;  else
-      if (ISFLAG("--decompress"))        opMode           = OM_UNZ;  else
-      if (ISFLAG("--compress"))          opMode           = OM_Z;    else
-      if (ISFLAG("--force"))             forceOverwrite   = True;    else
-      if (ISFLAG("--test"))              opMode           = OM_TEST; else
-      if (ISFLAG("--keep"))              keepInputFiles   = True;    else
-      if (ISFLAG("--small"))             smallMode        = True;    else
-      if (ISFLAG("--quiet"))             noisy            = False;   else
-      if (ISFLAG("--version"))           license();                  else
-      if (ISFLAG("--license"))           license();                  else
-      if (ISFLAG("--exponential"))       workFactor = 1;             else 
-      if (ISFLAG("--repetitive-best"))   redundant(aa->name);        else
-      if (ISFLAG("--repetitive-fast"))   redundant(aa->name);        else
-      if (ISFLAG("--fast"))              blockSize100k = 1;          else
-      if (ISFLAG("--best"))              blockSize100k = 9;          else
-      if (ISFLAG("--verbose"))           verbosity++;                else
-      if (ISFLAG("--help"))              { usage ( progName ); exit ( 0 ); }
-         else
-         if (strncmp ( aa->name, "--", 2) == 0) {
-            fprintf ( stderr, "%s: Bad flag `%s'\n", progName, aa->name );
-            usage ( progName );
-            exit ( 1 );
-         }
-   }
-
-   if (verbosity > 4) verbosity = 4;
-   if (opMode == OM_Z && smallMode && blockSize100k > 2) 
-      blockSize100k = 2;
-
-   if (opMode == OM_TEST && srcMode == SM_F2O) {
-      fprintf ( stderr, "%s: -c and -t cannot be used together.\n",
-                progName );
-      exit ( 1 );
-   }
-
-   if (srcMode == SM_F2O && numFileNames == 0)
-      srcMode = SM_I2O;
-
-   if (opMode != OM_Z) blockSize100k = 0;
-
-   if (srcMode == SM_F2F) {
-      signal (SIGINT,  mySignalCatcher);
-      signal (SIGTERM, mySignalCatcher);
-#     if BZ_UNIX
-      signal (SIGHUP,  mySignalCatcher);
-#     endif
-   }
-
-   if (opMode == OM_Z) {
-     if (srcMode == SM_I2O) {
-        compress ( NULL );
-     } else {
-        decode = True;
-        for (aa = argList; aa != NULL; aa = aa->link) {
-           if (ISFLAG("--")) { decode = False; continue; }
-           if (aa->name[0] == '-' && decode) continue;
-           numFilesProcessed++;
-           compress ( aa->name );
-        }
-     }
-   } 
-   else
-
-   if (opMode == OM_UNZ) {
-      unzFailsExist = False;
-      if (srcMode == SM_I2O) {
-         uncompress ( NULL );
-      } else {
-         decode = True;
-         for (aa = argList; aa != NULL; aa = aa->link) {
-            if (ISFLAG("--")) { decode = False; continue; }
-            if (aa->name[0] == '-' && decode) continue;
-            numFilesProcessed++;
-            uncompress ( aa->name );
-         }      
-      }
-      if (unzFailsExist) { 
-         setExit(2); 
-         exit(exitValue);
-      }
-   } 
-
-   else {
-      testFailsExist = False;
-      if (srcMode == SM_I2O) {
-         testf ( NULL );
-      } else {
-         decode = True;
-         for (aa = argList; aa != NULL; aa = aa->link) {
-	    if (ISFLAG("--")) { decode = False; continue; }
-            if (aa->name[0] == '-' && decode) continue;
-            numFilesProcessed++;
-            testf ( aa->name );
-	 }
-      }
-      if (testFailsExist && noisy) {
-         fprintf ( stderr,
-           "\n"
-           "You can use the `bzip2recover' program to attempt to recover\n"
-           "data from undamaged sections of corrupted files.\n\n"
-         );
-         setExit(2);
-         exit(exitValue);
-      }
-   }
-
-   /* Free the argument list memory to mollify leak detectors 
-      (eg) Purify, Checker.  Serves no other useful purpose.
-   */
-   aa = argList;
-   while (aa != NULL) {
-      Cell* aa2 = aa->link;
-      if (aa->name != NULL) free(aa->name);
-      free(aa);
-      aa = aa2;
-   }
-
-   return exitValue;
-}
-
-
-/*-----------------------------------------------------------*/
-/*--- end                                         bzip2.c ---*/
-/*-----------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/bzip2.txt
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzip2.txt	(revision 9)
+++ 	(revision )
@@ -1,391 +1,0 @@
-
-NAME
-       bzip2, bunzip2 - a block-sorting file compressor, v1.0.3
-       bzcat - decompresses files to stdout
-       bzip2recover - recovers data from damaged bzip2 files
-
-
-SYNOPSIS
-       bzip2 [ -cdfkqstvzVL123456789 ] [ filenames ...  ]
-       bunzip2 [ -fkvsVL ] [ filenames ...  ]
-       bzcat [ -s ] [ filenames ...  ]
-       bzip2recover filename
-
-
-DESCRIPTION
-       bzip2  compresses  files  using  the Burrows-Wheeler block
-       sorting text compression algorithm,  and  Huffman  coding.
-       Compression  is  generally  considerably  better than that
-       achieved by more conventional LZ77/LZ78-based compressors,
-       and  approaches  the performance of the PPM family of sta-
-       tistical compressors.
-
-       The command-line options are deliberately very similar  to
-       those of GNU gzip, but they are not identical.
-
-       bzip2  expects  a list of file names to accompany the com-
-       mand-line flags.  Each file is replaced  by  a  compressed
-       version  of  itself,  with  the  name "original_name.bz2".
-       Each compressed file has the same modification date,  per-
-       missions, and, when possible, ownership as the correspond-
-       ing original, so that these properties  can  be  correctly
-       restored  at  decompression  time.   File name handling is
-       naive in the sense that there is no mechanism for preserv-
-       ing  original file names, permissions, ownerships or dates
-       in filesystems which lack these concepts, or have  serious
-       file name length restrictions, such as MS-DOS.
-
-       bzip2  and  bunzip2 will by default not overwrite existing
-       files.  If you want this to happen, specify the -f flag.
-
-       If no file names  are  specified,  bzip2  compresses  from
-       standard  input  to  standard output.  In this case, bzip2
-       will decline to write compressed output to a terminal,  as
-       this  would  be  entirely  incomprehensible  and therefore
-       pointless.
-
-       bunzip2 (or bzip2 -d) decompresses  all  specified  files.
-       Files which were not created by bzip2 will be detected and
-       ignored, and a warning issued.  bzip2  attempts  to  guess
-       the  filename  for  the decompressed file from that of the
-       compressed file as follows:
-
-              filename.bz2    becomes   filename
-              filename.bz     becomes   filename
-              filename.tbz2   becomes   filename.tar
-              filename.tbz    becomes   filename.tar
-              anyothername    becomes   anyothername.out
-
-       If the file does not end in one of the recognised endings,
-       .bz2,  .bz,  .tbz2 or .tbz, bzip2 complains that it cannot
-       guess the name of the original file, and uses the original
-       name with .out appended.
-
-       As  with compression, supplying no filenames causes decom-
-       pression from standard input to standard output.
-
-       bunzip2 will correctly decompress a file which is the con-
-       catenation of two or more compressed files.  The result is
-       the concatenation of the corresponding uncompressed files.
-       Integrity testing (-t) of concatenated compressed files is
-       also supported.
-
-       You can also compress or decompress files to the  standard
-       output  by giving the -c flag.  Multiple files may be com-
-       pressed and decompressed like this.  The resulting outputs
-       are  fed  sequentially to stdout.  Compression of multiple
-       files in this manner generates a stream containing  multi-
-       ple compressed file representations.  Such a stream can be
-       decompressed correctly only  by  bzip2  version  0.9.0  or
-       later.   Earlier  versions of bzip2 will stop after decom-
-       pressing the first file in the stream.
-
-       bzcat (or bzip2 -dc) decompresses all specified  files  to
-       the standard output.
-
-       bzip2  will  read arguments from the environment variables
-       BZIP2 and BZIP, in  that  order,  and  will  process  them
-       before  any  arguments  read  from the command line.  This
-       gives a convenient way to supply default arguments.
-
-       Compression is always performed, even  if  the  compressed
-       file  is slightly larger than the original.  Files of less
-       than about one hundred bytes tend to get larger, since the
-       compression  mechanism  has  a  constant  overhead  in the
-       region of 50 bytes.  Random data (including the output  of
-       most  file  compressors)  is  coded at about 8.05 bits per
-       byte, giving an expansion of around 0.5%.
-
-       As a self-check for your  protection,  bzip2  uses  32-bit
-       CRCs  to make sure that the decompressed version of a file
-       is identical to the original.  This guards against corrup-
-       tion  of  the compressed data, and against undetected bugs
-       in bzip2 (hopefully very unlikely).  The chances  of  data
-       corruption  going  undetected  is  microscopic,  about one
-       chance in four billion for each file processed.  Be aware,
-       though,  that  the  check occurs upon decompression, so it
-       can only tell you that something is wrong.  It can't  help
-       you  recover  the original uncompressed data.  You can use
-       bzip2recover to try to recover data from damaged files.
-
-       Return values: 0 for a normal exit,  1  for  environmental
-       problems  (file not found, invalid flags, I/O errors, &c),
-       2 to indicate a corrupt compressed file, 3 for an internal
-       consistency error (eg, bug) which caused bzip2 to panic.
-
-
-OPTIONS
-       -c --stdout
-              Compress or decompress to standard output.
-
-       -d --decompress
-              Force  decompression.  bzip2, bunzip2 and bzcat are
-              really the same program,  and  the  decision  about
-              what  actions to take is done on the basis of which
-              name is used.  This flag overrides that  mechanism,
-              and forces bzip2 to decompress.
-
-       -z --compress
-              The   complement   to   -d:   forces   compression,
-              regardless of the invocation name.
-
-       -t --test
-              Check integrity of the specified file(s), but don't
-              decompress  them.   This  really  performs  a trial
-              decompression and throws away the result.
-
-       -f --force
-              Force overwrite of output files.   Normally,  bzip2
-              will  not  overwrite  existing  output files.  Also
-              forces bzip2 to break hard links to files, which it
-              otherwise wouldn't do.
-
-              bzip2  normally  declines to decompress files which
-              don't have the  correct  magic  header  bytes.   If
-              forced  (-f),  however,  it  will  pass  such files
-              through unmodified.  This is how GNU gzip  behaves.
-
-       -k --keep
-              Keep  (don't delete) input files during compression
-              or decompression.
-
-       -s --small
-              Reduce memory usage, for compression, decompression
-              and  testing.   Files  are  decompressed and tested
-              using a modified algorithm which only requires  2.5
-              bytes  per  block byte.  This means any file can be
-              decompressed in 2300k of memory,  albeit  at  about
-              half the normal speed.
-
-              During  compression,  -s  selects  a  block size of
-              200k, which limits memory use to  around  the  same
-              figure,  at  the expense of your compression ratio.
-              In short, if your  machine  is  low  on  memory  (8
-              megabytes  or  less),  use  -s for everything.  See
-              MEMORY MANAGEMENT below.
-
-       -q --quiet
-              Suppress non-essential warning messages.   Messages
-              pertaining  to I/O errors and other critical events
-              will not be suppressed.
-
-       -v --verbose
-              Verbose mode -- show the compression ratio for each
-              file  processed.   Further  -v's  increase the ver-
-              bosity level, spewing out lots of information which
-              is primarily of interest for diagnostic purposes.
-
-       -L --license -V --version
-              Display  the  software  version,  license terms and
-              conditions.
-
-       -1 (or --fast) to -9 (or --best)
-              Set the block size to 100 k, 200 k ..  900  k  when
-              compressing.   Has  no  effect  when decompressing.
-              See MEMORY MANAGEMENT below.  The --fast and --best
-              aliases  are  primarily for GNU gzip compatibility.
-              In particular, --fast doesn't make things  signifi-
-              cantly  faster.   And  --best  merely  selects  the
-              default behaviour.
-
-       --     Treats all subsequent arguments as file names, even
-              if they start with a dash.  This is so you can han-
-              dle files with names beginning  with  a  dash,  for
-              example: bzip2 -- -myfilename.
-
-       --repetitive-fast --repetitive-best
-              These  flags  are  redundant  in versions 0.9.5 and
-              above.  They provided some coarse control over  the
-              behaviour  of the sorting algorithm in earlier ver-
-              sions, which was sometimes useful.  0.9.5 and above
-              have  an  improved  algorithm  which  renders these
-              flags irrelevant.
-
-
-MEMORY MANAGEMENT
-       bzip2 compresses large files in blocks.   The  block  size
-       affects  both  the  compression  ratio  achieved,  and the
-       amount of memory needed for compression and decompression.
-       The  flags  -1  through  -9  specify  the block size to be
-       100,000 bytes through 900,000 bytes (the default)  respec-
-       tively.   At  decompression  time, the block size used for
-       compression is read from  the  header  of  the  compressed
-       file, and bunzip2 then allocates itself just enough memory
-       to decompress the file.  Since block sizes are  stored  in
-       compressed  files,  it follows that the flags -1 to -9 are
-       irrelevant to and so ignored during decompression.
-
-       Compression and decompression requirements, in bytes,  can
-       be estimated as:
-
-              Compression:   400k + ( 8 x block size )
-
-              Decompression: 100k + ( 4 x block size ), or
-                             100k + ( 2.5 x block size )
-
-       Larger  block  sizes  give  rapidly  diminishing  marginal
-       returns.  Most of the compression comes from the first two
-       or  three hundred k of block size, a fact worth bearing in
-       mind when using bzip2  on  small  machines.   It  is  also
-       important  to  appreciate  that  the  decompression memory
-       requirement is set at compression time by  the  choice  of
-       block size.
-
-       For  files  compressed  with  the default 900k block size,
-       bunzip2 will require about 3700 kbytes to decompress.   To
-       support decompression of any file on a 4 megabyte machine,
-       bunzip2 has an option to  decompress  using  approximately
-       half this amount of memory, about 2300 kbytes.  Decompres-
-       sion speed is also halved, so you should use  this  option
-       only where necessary.  The relevant flag is -s.
-
-       In general, try and use the largest block size memory con-
-       straints  allow,  since  that  maximises  the  compression
-       achieved.   Compression and decompression speed are virtu-
-       ally unaffected by block size.
-
-       Another significant point applies to files which fit in  a
-       single  block  --  that  means  most files you'd encounter
-       using a large block  size.   The  amount  of  real  memory
-       touched is proportional to the size of the file, since the
-       file is smaller than a block.  For example, compressing  a
-       file  20,000  bytes  long  with the flag -9 will cause the
-       compressor to allocate around 7600k of  memory,  but  only
-       touch 400k + 20000 * 8 = 560 kbytes of it.  Similarly, the
-       decompressor will allocate 3700k but  only  touch  100k  +
-       20000 * 4 = 180 kbytes.
-
-       Here  is a table which summarises the maximum memory usage
-       for different block sizes.  Also  recorded  is  the  total
-       compressed  size for 14 files of the Calgary Text Compres-
-       sion Corpus totalling 3,141,622 bytes.  This column  gives
-       some  feel  for  how  compression  varies with block size.
-       These figures tend to understate the advantage  of  larger
-       block  sizes  for  larger files, since the Corpus is domi-
-       nated by smaller files.
-
-                  Compress   Decompress   Decompress   Corpus
-           Flag     usage      usage       -s usage     Size
-
-            -1      1200k       500k         350k      914704
-            -2      2000k       900k         600k      877703
-            -3      2800k      1300k         850k      860338
-            -4      3600k      1700k        1100k      846899
-            -5      4400k      2100k        1350k      845160
-            -6      5200k      2500k        1600k      838626
-            -7      6100k      2900k        1850k      834096
-            -8      6800k      3300k        2100k      828642
-            -9      7600k      3700k        2350k      828642
-
-
-RECOVERING DATA FROM DAMAGED FILES
-       bzip2 compresses files in blocks, usually 900kbytes  long.
-       Each block is handled independently.  If a media or trans-
-       mission error causes a multi-block  .bz2  file  to  become
-       damaged,  it  may  be  possible  to  recover data from the
-       undamaged blocks in the file.
-
-       The compressed representation of each block  is  delimited
-       by  a  48-bit pattern, which makes it possible to find the
-       block boundaries with reasonable  certainty.   Each  block
-       also  carries its own 32-bit CRC, so damaged blocks can be
-       distinguished from undamaged ones.
-
-       bzip2recover is a  simple  program  whose  purpose  is  to
-       search  for blocks in .bz2 files, and write each block out
-       into its own .bz2 file.  You can then use bzip2 -t to test
-       the integrity of the resulting files, and decompress those
-       which are undamaged.
-
-       bzip2recover takes a single argument, the name of the dam-
-       aged    file,    and    writes    a    number   of   files
-       "rec00001file.bz2",  "rec00002file.bz2",  etc,  containing
-       the   extracted   blocks.   The   output   filenames   are
-       designed  so  that the use of wildcards in subsequent pro-
-       cessing  -- for example, "bzip2 -dc  rec*file.bz2 > recov-
-       ered_data" -- processes the files in the correct order.
-
-       bzip2recover should be of most use dealing with large .bz2
-       files,  as  these will contain many blocks.  It is clearly
-       futile to use it on damaged single-block  files,  since  a
-       damaged  block  cannot  be recovered.  If you wish to min-
-       imise any potential data loss through media  or  transmis-
-       sion errors, you might consider compressing with a smaller
-       block size.
-
-
-PERFORMANCE NOTES
-       The sorting phase of compression gathers together  similar
-       strings  in  the  file.  Because of this, files containing
-       very long runs of  repeated  symbols,  like  "aabaabaabaab
-       ..."   (repeated  several hundred times) may compress more
-       slowly than normal.  Versions 0.9.5 and  above  fare  much
-       better  than previous versions in this respect.  The ratio
-       between worst-case and average-case compression time is in
-       the  region  of  10:1.  For previous versions, this figure
-       was more like 100:1.  You can use the -vvvv option to mon-
-       itor progress in great detail, if you want.
-
-       Decompression speed is unaffected by these phenomena.
-
-       bzip2  usually  allocates  several  megabytes of memory to
-       operate in, and then charges all over it in a fairly  ran-
-       dom  fashion.   This means that performance, both for com-
-       pressing and decompressing, is largely determined  by  the
-       speed  at  which  your  machine  can service cache misses.
-       Because of this, small changes to the code to  reduce  the
-       miss  rate  have  been observed to give disproportionately
-       large performance improvements.  I imagine bzip2 will per-
-       form best on machines with very large caches.
-
-
-CAVEATS
-       I/O  error  messages  are not as helpful as they could be.
-       bzip2 tries hard to detect I/O errors  and  exit  cleanly,
-       but  the  details  of  what  the problem is sometimes seem
-       rather misleading.
-
-       This manual page pertains to version 1.0.3 of bzip2.  Com-
-       pressed  data created by this version is entirely forwards
-       and  backwards  compatible  with   the   previous   public
-       releases,  versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1 and
-       1.0.2, but with the following exception: 0.9.0  and  above
-       can  correctly decompress multiple concatenated compressed
-       files.  0.1pl2 cannot do this; it will stop  after  decom-
-       pressing just the first file in the stream.
-
-       bzip2recover  versions prior to 1.0.2 used 32-bit integers
-       to represent bit positions in compressed  files,  so  they
-       could  not handle compressed files more than 512 megabytes
-       long.  Versions 1.0.2 and above use 64-bit  ints  on  some
-       platforms  which  support them (GNU supported targets, and
-       Windows).  To establish whether or  not  bzip2recover  was
-       built  with  such  a limitation, run it without arguments.
-       In any event you can build yourself an  unlimited  version
-       if  you  can  recompile  it  with MaybeUInt64 set to be an
-       unsigned 64-bit integer.
-
-
-AUTHOR
-       Julian Seward, jsewardbzip.org.
-
-       http://www.bzip.org
-
-       The ideas embodied in bzip2 are due to (at least) the fol-
-       lowing  people: Michael Burrows and David Wheeler (for the
-       block sorting transformation), David Wheeler  (again,  for
-       the Huffman coder), Peter Fenwick (for the structured cod-
-       ing model in the original bzip, and many refinements), and
-       Alistair  Moffat,  Radford  Neal  and  Ian Witten (for the
-       arithmetic  coder  in  the  original  bzip).   I  am  much
-       indebted for their help, support and advice.  See the man-
-       ual in the source distribution for pointers to sources  of
-       documentation.  Christian von Roques encouraged me to look
-       for faster sorting algorithms, so as to speed up  compres-
-       sion.  Bela Lubkin encouraged me to improve the worst-case
-       compression performance.  Donna Robinson XMLised the docu-
-       mentation.   The bz* scripts are derived from those of GNU
-       gzip.  Many people sent patches, helped  with  portability
-       problems,  lent  machines,  gave advice and were generally
-       helpful.
-
Index: trunk/minix/commands/bzip2-1.0.3/bzip2recover.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzip2recover.c	(revision 9)
+++ 	(revision )
@@ -1,546 +1,0 @@
-
-/*-----------------------------------------------------------*/
-/*--- Block recoverer program for bzip2                   ---*/
-/*---                                      bzip2recover.c ---*/
-/*-----------------------------------------------------------*/
-
-/*--
-  This program is bzip2recover, a program to attempt data 
-  salvage from damaged files created by the accompanying
-  bzip2-1.0.3 program.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0.3 of 15 February 2005
---*/
-
-/*--
-  This program is a complete hack and should be rewritten
-  properly.  It isn't very complicated.
---*/
-
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-/* This program records bit locations in the file to be recovered.
-   That means that if 64-bit ints are not supported, we will not
-   be able to recover .bz2 files over 512MB (2^32 bits) long.
-   On GNU supported platforms, we take advantage of the 64-bit
-   int support to circumvent this problem.  Ditto MSVC.
-
-   This change occurred in version 1.0.2; all prior versions have
-   the 512MB limitation.
-*/
-#ifdef __GNUC__
-   typedef  unsigned long long int  MaybeUInt64;
-#  define MaybeUInt64_FMT "%Lu"
-#else
-#ifdef _MSC_VER
-   typedef  unsigned __int64  MaybeUInt64;
-#  define MaybeUInt64_FMT "%I64u"
-#else
-   typedef  unsigned int   MaybeUInt64;
-#  define MaybeUInt64_FMT "%u"
-#endif
-#endif
-
-typedef  unsigned int   UInt32;
-typedef  int            Int32;
-typedef  unsigned char  UChar;
-typedef  char           Char;
-typedef  unsigned char  Bool;
-#define True    ((Bool)1)
-#define False   ((Bool)0)
-
-
-#define BZ_MAX_FILENAME 2000
-
-Char inFileName[BZ_MAX_FILENAME];
-Char outFileName[BZ_MAX_FILENAME];
-Char progName[BZ_MAX_FILENAME];
-
-MaybeUInt64 bytesOut = 0;
-MaybeUInt64 bytesIn  = 0;
-
-
-/*---------------------------------------------------*/
-/*--- Header bytes                                ---*/
-/*---------------------------------------------------*/
-
-#define BZ_HDR_B 0x42                         /* 'B' */
-#define BZ_HDR_Z 0x5a                         /* 'Z' */
-#define BZ_HDR_h 0x68                         /* 'h' */
-#define BZ_HDR_0 0x30                         /* '0' */
- 
-
-/*---------------------------------------------------*/
-/*--- I/O errors                                  ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-void readError ( void )
-{
-   fprintf ( stderr,
-             "%s: I/O error reading `%s', possible reason follows.\n",
-            progName, inFileName );
-   perror ( progName );
-   fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
-             progName );
-   exit ( 1 );
-}
-
-
-/*---------------------------------------------*/
-void writeError ( void )
-{
-   fprintf ( stderr,
-             "%s: I/O error reading `%s', possible reason follows.\n",
-            progName, inFileName );
-   perror ( progName );
-   fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
-             progName );
-   exit ( 1 );
-}
-
-
-/*---------------------------------------------*/
-void mallocFail ( Int32 n )
-{
-   fprintf ( stderr,
-             "%s: malloc failed on request for %d bytes.\n",
-            progName, n );
-   fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
-             progName );
-   exit ( 1 );
-}
-
-
-/*---------------------------------------------*/
-void tooManyBlocks ( Int32 max_handled_blocks )
-{
-   fprintf ( stderr,
-             "%s: `%s' appears to contain more than %d blocks\n",
-            progName, inFileName, max_handled_blocks );
-   fprintf ( stderr,
-             "%s: and cannot be handled.  To fix, increase\n",
-             progName );
-   fprintf ( stderr, 
-             "%s: BZ_MAX_HANDLED_BLOCKS in bzip2recover.c, and recompile.\n",
-             progName );
-   exit ( 1 );
-}
-
-
-
-/*---------------------------------------------------*/
-/*--- Bit stream I/O                              ---*/
-/*---------------------------------------------------*/
-
-typedef
-   struct {
-      FILE*  handle;
-      Int32  buffer;
-      Int32  buffLive;
-      Char   mode;
-   }
-   BitStream;
-
-
-/*---------------------------------------------*/
-BitStream* bsOpenReadStream ( FILE* stream )
-{
-   BitStream *bs = malloc ( sizeof(BitStream) );
-   if (bs == NULL) mallocFail ( sizeof(BitStream) );
-   bs->handle = stream;
-   bs->buffer = 0;
-   bs->buffLive = 0;
-   bs->mode = 'r';
-   return bs;
-}
-
-
-/*---------------------------------------------*/
-BitStream* bsOpenWriteStream ( FILE* stream )
-{
-   BitStream *bs = malloc ( sizeof(BitStream) );
-   if (bs == NULL) mallocFail ( sizeof(BitStream) );
-   bs->handle = stream;
-   bs->buffer = 0;
-   bs->buffLive = 0;
-   bs->mode = 'w';
-   return bs;
-}
-
-
-/*---------------------------------------------*/
-void bsPutBit ( BitStream* bs, Int32 bit )
-{
-   if (bs->buffLive == 8) {
-      Int32 retVal = putc ( (UChar) bs->buffer, bs->handle );
-      if (retVal == EOF) writeError();
-      bytesOut++;
-      bs->buffLive = 1;
-      bs->buffer = bit & 0x1;
-   } else {
-      bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) );
-      bs->buffLive++;
-   };
-}
-
-
-/*---------------------------------------------*/
-/*--
-   Returns 0 or 1, or 2 to indicate EOF.
---*/
-Int32 bsGetBit ( BitStream* bs )
-{
-   if (bs->buffLive > 0) {
-      bs->buffLive --;
-      return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
-   } else {
-      Int32 retVal = getc ( bs->handle );
-      if ( retVal == EOF ) {
-         if (errno != 0) readError();
-         return 2;
-      }
-      bs->buffLive = 7;
-      bs->buffer = retVal;
-      return ( ((bs->buffer) >> 7) & 0x1 );
-   }
-}
-
-
-/*---------------------------------------------*/
-void bsClose ( BitStream* bs )
-{
-   Int32 retVal;
-
-   if ( bs->mode == 'w' ) {
-      while ( bs->buffLive < 8 ) {
-         bs->buffLive++;
-         bs->buffer <<= 1;
-      };
-      retVal = putc ( (UChar) (bs->buffer), bs->handle );
-      if (retVal == EOF) writeError();
-      bytesOut++;
-      retVal = fflush ( bs->handle );
-      if (retVal == EOF) writeError();
-   }
-   retVal = fclose ( bs->handle );
-   if (retVal == EOF) {
-      if (bs->mode == 'w') writeError(); else readError();
-   }
-   free ( bs );
-}
-
-
-/*---------------------------------------------*/
-void bsPutUChar ( BitStream* bs, UChar c )
-{
-   Int32 i;
-   for (i = 7; i >= 0; i--)
-      bsPutBit ( bs, (((UInt32) c) >> i) & 0x1 );
-}
-
-
-/*---------------------------------------------*/
-void bsPutUInt32 ( BitStream* bs, UInt32 c )
-{
-   Int32 i;
-
-   for (i = 31; i >= 0; i--)
-      bsPutBit ( bs, (c >> i) & 0x1 );
-}
-
-
-/*---------------------------------------------*/
-Bool endsInBz2 ( Char* name )
-{
-   Int32 n = strlen ( name );
-   if (n <= 4) return False;
-   return
-      (name[n-4] == '.' &&
-       name[n-3] == 'b' &&
-       name[n-2] == 'z' &&
-       name[n-1] == '2');
-}
-
-
-/*---------------------------------------------------*/
-/*---                                             ---*/
-/*---------------------------------------------------*/
-
-/* This logic isn't really right when it comes to Cygwin. */
-#ifdef _WIN32
-#  define  BZ_SPLIT_SYM  '\\'  /* path splitter on Windows platform */
-#else
-#  define  BZ_SPLIT_SYM  '/'   /* path splitter on Unix platform */
-#endif
-
-#define BLOCK_HEADER_HI  0x00003141UL
-#define BLOCK_HEADER_LO  0x59265359UL
-
-#define BLOCK_ENDMARK_HI 0x00001772UL
-#define BLOCK_ENDMARK_LO 0x45385090UL
-
-/* Increase if necessary.  However, a .bz2 file with > 50000 blocks
-   would have an uncompressed size of at least 40GB, so the chances
-   are low you'll need to up this.
-*/
-#define BZ_MAX_HANDLED_BLOCKS 50000
-
-MaybeUInt64 bStart [BZ_MAX_HANDLED_BLOCKS];
-MaybeUInt64 bEnd   [BZ_MAX_HANDLED_BLOCKS];
-MaybeUInt64 rbStart[BZ_MAX_HANDLED_BLOCKS];
-MaybeUInt64 rbEnd  [BZ_MAX_HANDLED_BLOCKS];
-
-Int32 main ( Int32 argc, Char** argv )
-{
-   FILE*       inFile;
-   FILE*       outFile;
-   BitStream*  bsIn, *bsWr;
-   Int32       b, wrBlock, currBlock, rbCtr;
-   MaybeUInt64 bitsRead;
-
-   UInt32      buffHi, buffLo, blockCRC;
-   Char*       p;
-
-   strcpy ( progName, argv[0] );
-   inFileName[0] = outFileName[0] = 0;
-
-   fprintf ( stderr, 
-             "bzip2recover 1.0.3: extracts blocks from damaged .bz2 files.\n" );
-
-   if (argc != 2) {
-      fprintf ( stderr, "%s: usage is `%s damaged_file_name'.\n",
-                        progName, progName );
-      switch (sizeof(MaybeUInt64)) {
-         case 8:
-            fprintf(stderr, 
-                    "\trestrictions on size of recovered file: None\n");
-            break;
-         case 4:
-            fprintf(stderr, 
-                    "\trestrictions on size of recovered file: 512 MB\n");
-            fprintf(stderr, 
-                    "\tto circumvent, recompile with MaybeUInt64 as an\n"
-                    "\tunsigned 64-bit int.\n");
-            break;
-         default:
-            fprintf(stderr, 
-                    "\tsizeof(MaybeUInt64) is not 4 or 8 -- "
-                    "configuration error.\n");
-            break;
-      }
-      exit(1);
-   }
-
-   if (strlen(argv[1]) >= BZ_MAX_FILENAME-20) {
-      fprintf ( stderr, 
-                "%s: supplied filename is suspiciously (>= %d chars) long.  Bye!\n",
-                progName, (int)strlen(argv[1]) );
-      exit(1);
-   }
-
-   strcpy ( inFileName, argv[1] );
-
-   inFile = fopen ( inFileName, "rb" );
-   if (inFile == NULL) {
-      fprintf ( stderr, "%s: can't read `%s'\n", progName, inFileName );
-      exit(1);
-   }
-
-   bsIn = bsOpenReadStream ( inFile );
-   fprintf ( stderr, "%s: searching for block boundaries ...\n", progName );
-
-   bitsRead = 0;
-   buffHi = buffLo = 0;
-   currBlock = 0;
-   bStart[currBlock] = 0;
-
-   rbCtr = 0;
-
-   while (True) {
-      b = bsGetBit ( bsIn );
-      bitsRead++;
-      if (b == 2) {
-         if (bitsRead >= bStart[currBlock] &&
-            (bitsRead - bStart[currBlock]) >= 40) {
-            bEnd[currBlock] = bitsRead-1;
-            if (currBlock > 0)
-               fprintf ( stderr, "   block %d runs from " MaybeUInt64_FMT 
-                                 " to " MaybeUInt64_FMT " (incomplete)\n",
-                         currBlock,  bStart[currBlock], bEnd[currBlock] );
-         } else
-            currBlock--;
-         break;
-      }
-      buffHi = (buffHi << 1) | (buffLo >> 31);
-      buffLo = (buffLo << 1) | (b & 1);
-      if ( ( (buffHi & 0x0000ffff) == BLOCK_HEADER_HI 
-             && buffLo == BLOCK_HEADER_LO)
-           || 
-           ( (buffHi & 0x0000ffff) == BLOCK_ENDMARK_HI 
-             && buffLo == BLOCK_ENDMARK_LO)
-         ) {
-         if (bitsRead > 49) {
-            bEnd[currBlock] = bitsRead-49;
-         } else {
-            bEnd[currBlock] = 0;
-         }
-         if (currBlock > 0 &&
-	     (bEnd[currBlock] - bStart[currBlock]) >= 130) {
-            fprintf ( stderr, "   block %d runs from " MaybeUInt64_FMT 
-                              " to " MaybeUInt64_FMT "\n",
-                      rbCtr+1,  bStart[currBlock], bEnd[currBlock] );
-            rbStart[rbCtr] = bStart[currBlock];
-            rbEnd[rbCtr] = bEnd[currBlock];
-            rbCtr++;
-         }
-         if (currBlock >= BZ_MAX_HANDLED_BLOCKS)
-            tooManyBlocks(BZ_MAX_HANDLED_BLOCKS);
-         currBlock++;
-
-         bStart[currBlock] = bitsRead;
-      }
-   }
-
-   bsClose ( bsIn );
-
-   /*-- identified blocks run from 1 to rbCtr inclusive. --*/
-
-   if (rbCtr < 1) {
-      fprintf ( stderr,
-                "%s: sorry, I couldn't find any block boundaries.\n",
-                progName );
-      exit(1);
-   };
-
-   fprintf ( stderr, "%s: splitting into blocks\n", progName );
-
-   inFile = fopen ( inFileName, "rb" );
-   if (inFile == NULL) {
-      fprintf ( stderr, "%s: can't open `%s'\n", progName, inFileName );
-      exit(1);
-   }
-   bsIn = bsOpenReadStream ( inFile );
-
-   /*-- placate gcc's dataflow analyser --*/
-   blockCRC = 0; bsWr = 0;
-
-   bitsRead = 0;
-   outFile = NULL;
-   wrBlock = 0;
-   while (True) {
-      b = bsGetBit(bsIn);
-      if (b == 2) break;
-      buffHi = (buffHi << 1) | (buffLo >> 31);
-      buffLo = (buffLo << 1) | (b & 1);
-      if (bitsRead == 47+rbStart[wrBlock]) 
-         blockCRC = (buffHi << 16) | (buffLo >> 16);
-
-      if (outFile != NULL && bitsRead >= rbStart[wrBlock]
-                          && bitsRead <= rbEnd[wrBlock]) {
-         bsPutBit ( bsWr, b );
-      }
-
-      bitsRead++;
-
-      if (bitsRead == rbEnd[wrBlock]+1) {
-         if (outFile != NULL) {
-            bsPutUChar ( bsWr, 0x17 ); bsPutUChar ( bsWr, 0x72 );
-            bsPutUChar ( bsWr, 0x45 ); bsPutUChar ( bsWr, 0x38 );
-            bsPutUChar ( bsWr, 0x50 ); bsPutUChar ( bsWr, 0x90 );
-            bsPutUInt32 ( bsWr, blockCRC );
-            bsClose ( bsWr );
-         }
-         if (wrBlock >= rbCtr) break;
-         wrBlock++;
-      } else
-      if (bitsRead == rbStart[wrBlock]) {
-         /* Create the output file name, correctly handling leading paths. 
-            (31.10.2001 by Sergey E. Kusikov) */
-         Char* split;
-         Int32 ofs, k;
-         for (k = 0; k < BZ_MAX_FILENAME; k++) 
-            outFileName[k] = 0;
-         strcpy (outFileName, inFileName);
-         split = strrchr (outFileName, BZ_SPLIT_SYM);
-         if (split == NULL) {
-            split = outFileName;
-         } else {
-            ++split;
-	 }
-	 /* Now split points to the start of the basename. */
-         ofs  = split - outFileName;
-         sprintf (split, "rec%5d", wrBlock+1);
-         for (p = split; *p != 0; p++) if (*p == ' ') *p = '0';
-         strcat (outFileName, inFileName + ofs);
-
-         if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
-
-         fprintf ( stderr, "   writing block %d to `%s' ...\n",
-                           wrBlock+1, outFileName );
-
-         outFile = fopen ( outFileName, "wb" );
-         if (outFile == NULL) {
-            fprintf ( stderr, "%s: can't write `%s'\n",
-                      progName, outFileName );
-            exit(1);
-         }
-         bsWr = bsOpenWriteStream ( outFile );
-         bsPutUChar ( bsWr, BZ_HDR_B );    
-         bsPutUChar ( bsWr, BZ_HDR_Z );    
-         bsPutUChar ( bsWr, BZ_HDR_h );    
-         bsPutUChar ( bsWr, BZ_HDR_0 + 9 );
-         bsPutUChar ( bsWr, 0x31 ); bsPutUChar ( bsWr, 0x41 );
-         bsPutUChar ( bsWr, 0x59 ); bsPutUChar ( bsWr, 0x26 );
-         bsPutUChar ( bsWr, 0x53 ); bsPutUChar ( bsWr, 0x59 );
-      }
-   }
-
-   fprintf ( stderr, "%s: finished\n", progName );
-   return 0;
-}
-
-
-
-/*-----------------------------------------------------------*/
-/*--- end                                  bzip2recover.c ---*/
-/*-----------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/bzlib.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzlib.c	(revision 9)
+++ 	(revision )
@@ -1,1616 +1,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Library top-level functions.                          ---*/
-/*---                                               bzlib.c ---*/
-/*-------------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-/*--
-   CHANGES
-   ~~~~~~~
-   0.9.0 -- original version.
-
-   0.9.0a/b -- no changes in this file.
-
-   0.9.0c
-      * made zero-length BZ_FLUSH work correctly in bzCompress().
-      * fixed bzWrite/bzRead to ignore zero-length requests.
-      * fixed bzread to correctly handle read requests after EOF.
-      * wrong parameter order in call to bzDecompressInit in
-        bzBuffToBuffDecompress.  Fixed.
---*/
-
-#include "bzlib_private.h"
-
-
-/*---------------------------------------------------*/
-/*--- Compression stuff                           ---*/
-/*---------------------------------------------------*/
-
-
-/*---------------------------------------------------*/
-#ifndef BZ_NO_STDIO
-void BZ2_bz__AssertH__fail ( int errcode )
-{
-   fprintf(stderr, 
-      "\n\nbzip2/libbzip2: internal error number %d.\n"
-      "This is a bug in bzip2/libbzip2, %s.\n"
-      "Please report it to me at: jseward@bzip.org.  If this happened\n"
-      "when you were using some program which uses libbzip2 as a\n"
-      "component, you should also report this bug to the author(s)\n"
-      "of that program.  Please make an effort to report this bug;\n"
-      "timely and accurate bug reports eventually lead to higher\n"
-      "quality software.  Thanks.  Julian Seward, 15 February 2005.\n\n",
-      errcode,
-      BZ2_bzlibVersion()
-   );
-
-   if (errcode == 1007) {
-   fprintf(stderr,
-      "\n*** A special note about internal error number 1007 ***\n"
-      "\n"
-      "Experience suggests that a common cause of i.e. 1007\n"
-      "is unreliable memory or other hardware.  The 1007 assertion\n"
-      "just happens to cross-check the results of huge numbers of\n"
-      "memory reads/writes, and so acts (unintendedly) as a stress\n"
-      "test of your memory system.\n"
-      "\n"
-      "I suggest the following: try compressing the file again,\n"
-      "possibly monitoring progress in detail with the -vv flag.\n"
-      "\n"
-      "* If the error cannot be reproduced, and/or happens at different\n"
-      "  points in compression, you may have a flaky memory system.\n"
-      "  Try a memory-test program.  I have used Memtest86\n"
-      "  (www.memtest86.com).  At the time of writing it is free (GPLd).\n"
-      "  Memtest86 tests memory much more thorougly than your BIOSs\n"
-      "  power-on test, and may find failures that the BIOS doesn't.\n"
-      "\n"
-      "* If the error can be repeatably reproduced, this is a bug in\n"
-      "  bzip2, and I would very much like to hear about it.  Please\n"
-      "  let me know, and, ideally, save a copy of the file causing the\n"
-      "  problem -- without which I will be unable to investigate it.\n"
-      "\n"
-   );
-   }
-
-   exit(3);
-}
-#endif
-
-
-/*---------------------------------------------------*/
-static
-int bz_config_ok ( void )
-{
-   if (sizeof(int)   != 4) return 0;
-   if (sizeof(short) != 2) return 0;
-   if (sizeof(char)  != 1) return 0;
-   return 1;
-}
-
-
-/*---------------------------------------------------*/
-static
-void* default_bzalloc ( void* opaque, Int32 items, Int32 size )
-{
-   void* v = malloc ( items * size );
-   return v;
-}
-
-static
-void default_bzfree ( void* opaque, void* addr )
-{
-   if (addr != NULL) free ( addr );
-}
-
-
-/*---------------------------------------------------*/
-static
-void prepare_new_block ( EState* s )
-{
-   Int32 i;
-   s->nblock = 0;
-   s->numZ = 0;
-   s->state_out_pos = 0;
-   BZ_INITIALISE_CRC ( s->blockCRC );
-   for (i = 0; i < 256; i++) s->inUse[i] = False;
-   s->blockNo++;
-}
-
-
-/*---------------------------------------------------*/
-static
-void init_RL ( EState* s )
-{
-   s->state_in_ch  = 256;
-   s->state_in_len = 0;
-}
-
-
-static
-Bool isempty_RL ( EState* s )
-{
-   if (s->state_in_ch < 256 && s->state_in_len > 0)
-      return False; else
-      return True;
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzCompressInit) 
-                    ( bz_stream* strm, 
-                     int        blockSize100k,
-                     int        verbosity,
-                     int        workFactor )
-{
-   Int32   n;
-   EState* s;
-
-   if (!bz_config_ok()) return BZ_CONFIG_ERROR;
-
-   if (strm == NULL || 
-       blockSize100k < 1 || blockSize100k > 9 ||
-       workFactor < 0 || workFactor > 250)
-     return BZ_PARAM_ERROR;
-
-   if (workFactor == 0) workFactor = 30;
-   if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
-   if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
-
-   s = BZALLOC( sizeof(EState) );
-   if (s == NULL) return BZ_MEM_ERROR;
-   s->strm = strm;
-
-   s->arr1 = NULL;
-   s->arr2 = NULL;
-   s->ftab = NULL;
-
-   n       = 100000 * blockSize100k;
-   s->arr1 = BZALLOC( n                  * sizeof(UInt32) );
-   s->arr2 = BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) );
-   s->ftab = BZALLOC( 65537              * sizeof(UInt32) );
-
-   if (s->arr1 == NULL || s->arr2 == NULL || s->ftab == NULL) {
-      if (s->arr1 != NULL) BZFREE(s->arr1);
-      if (s->arr2 != NULL) BZFREE(s->arr2);
-      if (s->ftab != NULL) BZFREE(s->ftab);
-      if (s       != NULL) BZFREE(s);
-      return BZ_MEM_ERROR;
-   }
-
-   s->blockNo           = 0;
-   s->state             = BZ_S_INPUT;
-   s->mode              = BZ_M_RUNNING;
-   s->combinedCRC       = 0;
-   s->blockSize100k     = blockSize100k;
-   s->nblockMAX         = 100000 * blockSize100k - 19;
-   s->verbosity         = verbosity;
-   s->workFactor        = workFactor;
-
-   s->block             = (UChar*)s->arr2;
-   s->mtfv              = (UInt16*)s->arr1;
-   s->zbits             = NULL;
-   s->ptr               = (UInt32*)s->arr1;
-
-   strm->state          = s;
-   strm->total_in_lo32  = 0;
-   strm->total_in_hi32  = 0;
-   strm->total_out_lo32 = 0;
-   strm->total_out_hi32 = 0;
-   init_RL ( s );
-   prepare_new_block ( s );
-   return BZ_OK;
-}
-
-
-/*---------------------------------------------------*/
-static
-void add_pair_to_block ( EState* s )
-{
-   Int32 i;
-   UChar ch = (UChar)(s->state_in_ch);
-   for (i = 0; i < s->state_in_len; i++) {
-      BZ_UPDATE_CRC( s->blockCRC, ch );
-   }
-   s->inUse[s->state_in_ch] = True;
-   switch (s->state_in_len) {
-      case 1:
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         break;
-      case 2:
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         break;
-      case 3:
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         break;
-      default:
-         s->inUse[s->state_in_len-4] = True;
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         s->block[s->nblock] = (UChar)ch; s->nblock++;
-         s->block[s->nblock] = ((UChar)(s->state_in_len-4));
-         s->nblock++;
-         break;
-   }
-}
-
-
-/*---------------------------------------------------*/
-static
-void flush_RL ( EState* s )
-{
-   if (s->state_in_ch < 256) add_pair_to_block ( s );
-   init_RL ( s );
-}
-
-
-/*---------------------------------------------------*/
-#define ADD_CHAR_TO_BLOCK(zs,zchh0)               \
-{                                                 \
-   UInt32 zchh = (UInt32)(zchh0);                 \
-   /*-- fast track the common case --*/           \
-   if (zchh != zs->state_in_ch &&                 \
-       zs->state_in_len == 1) {                   \
-      UChar ch = (UChar)(zs->state_in_ch);        \
-      BZ_UPDATE_CRC( zs->blockCRC, ch );          \
-      zs->inUse[zs->state_in_ch] = True;          \
-      zs->block[zs->nblock] = (UChar)ch;          \
-      zs->nblock++;                               \
-      zs->state_in_ch = zchh;                     \
-   }                                              \
-   else                                           \
-   /*-- general, uncommon cases --*/              \
-   if (zchh != zs->state_in_ch ||                 \
-      zs->state_in_len == 255) {                  \
-      if (zs->state_in_ch < 256)                  \
-         add_pair_to_block ( zs );                \
-      zs->state_in_ch = zchh;                     \
-      zs->state_in_len = 1;                       \
-   } else {                                       \
-      zs->state_in_len++;                         \
-   }                                              \
-}
-
-
-/*---------------------------------------------------*/
-static
-Bool copy_input_until_stop ( EState* s )
-{
-   Bool progress_in = False;
-
-   if (s->mode == BZ_M_RUNNING) {
-
-      /*-- fast track the common case --*/
-      while (True) {
-         /*-- block full? --*/
-         if (s->nblock >= s->nblockMAX) break;
-         /*-- no input? --*/
-         if (s->strm->avail_in == 0) break;
-         progress_in = True;
-         ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) ); 
-         s->strm->next_in++;
-         s->strm->avail_in--;
-         s->strm->total_in_lo32++;
-         if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++;
-      }
-
-   } else {
-
-      /*-- general, uncommon case --*/
-      while (True) {
-         /*-- block full? --*/
-         if (s->nblock >= s->nblockMAX) break;
-         /*-- no input? --*/
-         if (s->strm->avail_in == 0) break;
-         /*-- flush/finish end? --*/
-         if (s->avail_in_expect == 0) break;
-         progress_in = True;
-         ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) ); 
-         s->strm->next_in++;
-         s->strm->avail_in--;
-         s->strm->total_in_lo32++;
-         if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++;
-         s->avail_in_expect--;
-      }
-   }
-   return progress_in;
-}
-
-
-/*---------------------------------------------------*/
-static
-Bool copy_output_until_stop ( EState* s )
-{
-   Bool progress_out = False;
-
-   while (True) {
-
-      /*-- no output space? --*/
-      if (s->strm->avail_out == 0) break;
-
-      /*-- block done? --*/
-      if (s->state_out_pos >= s->numZ) break;
-
-      progress_out = True;
-      *(s->strm->next_out) = s->zbits[s->state_out_pos];
-      s->state_out_pos++;
-      s->strm->avail_out--;
-      s->strm->next_out++;
-      s->strm->total_out_lo32++;
-      if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
-   }
-
-   return progress_out;
-}
-
-
-/*---------------------------------------------------*/
-static
-Bool handle_compress ( bz_stream* strm )
-{
-   Bool progress_in  = False;
-   Bool progress_out = False;
-   EState* s = strm->state;
-   
-   while (True) {
-
-      if (s->state == BZ_S_OUTPUT) {
-         progress_out |= copy_output_until_stop ( s );
-         if (s->state_out_pos < s->numZ) break;
-         if (s->mode == BZ_M_FINISHING && 
-             s->avail_in_expect == 0 &&
-             isempty_RL(s)) break;
-         prepare_new_block ( s );
-         s->state = BZ_S_INPUT;
-         if (s->mode == BZ_M_FLUSHING && 
-             s->avail_in_expect == 0 &&
-             isempty_RL(s)) break;
-      }
-
-      if (s->state == BZ_S_INPUT) {
-         progress_in |= copy_input_until_stop ( s );
-         if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) {
-            flush_RL ( s );
-            BZ2_compressBlock ( s, (Bool)(s->mode == BZ_M_FINISHING) );
-            s->state = BZ_S_OUTPUT;
-         }
-         else
-         if (s->nblock >= s->nblockMAX) {
-            BZ2_compressBlock ( s, False );
-            s->state = BZ_S_OUTPUT;
-         }
-         else
-         if (s->strm->avail_in == 0) {
-            break;
-         }
-      }
-
-   }
-
-   return progress_in || progress_out;
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
-{
-   Bool progress;
-   EState* s;
-   if (strm == NULL) return BZ_PARAM_ERROR;
-   s = strm->state;
-   if (s == NULL) return BZ_PARAM_ERROR;
-   if (s->strm != strm) return BZ_PARAM_ERROR;
-
-   preswitch:
-   switch (s->mode) {
-
-      case BZ_M_IDLE:
-         return BZ_SEQUENCE_ERROR;
-
-      case BZ_M_RUNNING:
-         if (action == BZ_RUN) {
-            progress = handle_compress ( strm );
-            return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;
-         } 
-         else
-	 if (action == BZ_FLUSH) {
-            s->avail_in_expect = strm->avail_in;
-            s->mode = BZ_M_FLUSHING;
-            goto preswitch;
-         }
-         else
-         if (action == BZ_FINISH) {
-            s->avail_in_expect = strm->avail_in;
-            s->mode = BZ_M_FINISHING;
-            goto preswitch;
-         }
-         else 
-            return BZ_PARAM_ERROR;
-
-      case BZ_M_FLUSHING:
-         if (action != BZ_FLUSH) return BZ_SEQUENCE_ERROR;
-         if (s->avail_in_expect != s->strm->avail_in) 
-            return BZ_SEQUENCE_ERROR;
-         progress = handle_compress ( strm );
-         if (s->avail_in_expect > 0 || !isempty_RL(s) ||
-             s->state_out_pos < s->numZ) return BZ_FLUSH_OK;
-         s->mode = BZ_M_RUNNING;
-         return BZ_RUN_OK;
-
-      case BZ_M_FINISHING:
-         if (action != BZ_FINISH) return BZ_SEQUENCE_ERROR;
-         if (s->avail_in_expect != s->strm->avail_in) 
-            return BZ_SEQUENCE_ERROR;
-         progress = handle_compress ( strm );
-         if (!progress) return BZ_SEQUENCE_ERROR;
-         if (s->avail_in_expect > 0 || !isempty_RL(s) ||
-             s->state_out_pos < s->numZ) return BZ_FINISH_OK;
-         s->mode = BZ_M_IDLE;
-         return BZ_STREAM_END;
-   }
-   return BZ_OK; /*--not reached--*/
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzCompressEnd)  ( bz_stream *strm )
-{
-   EState* s;
-   if (strm == NULL) return BZ_PARAM_ERROR;
-   s = strm->state;
-   if (s == NULL) return BZ_PARAM_ERROR;
-   if (s->strm != strm) return BZ_PARAM_ERROR;
-
-   if (s->arr1 != NULL) BZFREE(s->arr1);
-   if (s->arr2 != NULL) BZFREE(s->arr2);
-   if (s->ftab != NULL) BZFREE(s->ftab);
-   BZFREE(strm->state);
-
-   strm->state = NULL;   
-
-   return BZ_OK;
-}
-
-
-/*---------------------------------------------------*/
-/*--- Decompression stuff                         ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzDecompressInit) 
-                     ( bz_stream* strm, 
-                       int        verbosity,
-                       int        small )
-{
-   DState* s;
-
-   if (!bz_config_ok()) return BZ_CONFIG_ERROR;
-
-   if (strm == NULL) return BZ_PARAM_ERROR;
-   if (small != 0 && small != 1) return BZ_PARAM_ERROR;
-   if (verbosity < 0 || verbosity > 4) return BZ_PARAM_ERROR;
-
-   if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
-   if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
-
-   s = BZALLOC( sizeof(DState) );
-   if (s == NULL) return BZ_MEM_ERROR;
-   s->strm                  = strm;
-   strm->state              = s;
-   s->state                 = BZ_X_MAGIC_1;
-   s->bsLive                = 0;
-   s->bsBuff                = 0;
-   s->calculatedCombinedCRC = 0;
-   strm->total_in_lo32      = 0;
-   strm->total_in_hi32      = 0;
-   strm->total_out_lo32     = 0;
-   strm->total_out_hi32     = 0;
-   s->smallDecompress       = (Bool)small;
-   s->ll4                   = NULL;
-   s->ll16                  = NULL;
-   s->tt                    = NULL;
-   s->currBlockNo           = 0;
-   s->verbosity             = verbosity;
-
-   return BZ_OK;
-}
-
-
-/*---------------------------------------------------*/
-/* Return  True iff data corruption is discovered.
-   Returns False if there is no problem.
-*/
-static
-Bool unRLE_obuf_to_output_FAST ( DState* s )
-{
-   UChar k1;
-
-   if (s->blockRandomised) {
-
-      while (True) {
-         /* try to finish existing run */
-         while (True) {
-            if (s->strm->avail_out == 0) return False;
-            if (s->state_out_len == 0) break;
-            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
-            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
-            s->state_out_len--;
-            s->strm->next_out++;
-            s->strm->avail_out--;
-            s->strm->total_out_lo32++;
-            if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
-         }
-
-         /* can a new run be started? */
-         if (s->nblock_used == s->save_nblock+1) return False;
-               
-         /* Only caused by corrupt data stream? */
-         if (s->nblock_used > s->save_nblock+1)
-            return True;
-   
-         s->state_out_len = 1;
-         s->state_out_ch = s->k0;
-         BZ_GET_FAST(k1); BZ_RAND_UPD_MASK; 
-         k1 ^= BZ_RAND_MASK; s->nblock_used++;
-         if (s->nblock_used == s->save_nblock+1) continue;
-         if (k1 != s->k0) { s->k0 = k1; continue; };
-   
-         s->state_out_len = 2;
-         BZ_GET_FAST(k1); BZ_RAND_UPD_MASK; 
-         k1 ^= BZ_RAND_MASK; s->nblock_used++;
-         if (s->nblock_used == s->save_nblock+1) continue;
-         if (k1 != s->k0) { s->k0 = k1; continue; };
-   
-         s->state_out_len = 3;
-         BZ_GET_FAST(k1); BZ_RAND_UPD_MASK; 
-         k1 ^= BZ_RAND_MASK; s->nblock_used++;
-         if (s->nblock_used == s->save_nblock+1) continue;
-         if (k1 != s->k0) { s->k0 = k1; continue; };
-   
-         BZ_GET_FAST(k1); BZ_RAND_UPD_MASK; 
-         k1 ^= BZ_RAND_MASK; s->nblock_used++;
-         s->state_out_len = ((Int32)k1) + 4;
-         BZ_GET_FAST(s->k0); BZ_RAND_UPD_MASK; 
-         s->k0 ^= BZ_RAND_MASK; s->nblock_used++;
-      }
-
-   } else {
-
-      /* restore */
-      UInt32        c_calculatedBlockCRC = s->calculatedBlockCRC;
-      UChar         c_state_out_ch       = s->state_out_ch;
-      Int32         c_state_out_len      = s->state_out_len;
-      Int32         c_nblock_used        = s->nblock_used;
-      Int32         c_k0                 = s->k0;
-      UInt32*       c_tt                 = s->tt;
-      UInt32        c_tPos               = s->tPos;
-      char*         cs_next_out          = s->strm->next_out;
-      unsigned int  cs_avail_out         = s->strm->avail_out;
-      /* end restore */
-
-      UInt32       avail_out_INIT = cs_avail_out;
-      Int32        s_save_nblockPP = s->save_nblock+1;
-      unsigned int total_out_lo32_old;
-
-      while (True) {
-
-         /* try to finish existing run */
-         if (c_state_out_len > 0) {
-            while (True) {
-               if (cs_avail_out == 0) goto return_notr;
-               if (c_state_out_len == 1) break;
-               *( (UChar*)(cs_next_out) ) = c_state_out_ch;
-               BZ_UPDATE_CRC ( c_calculatedBlockCRC, c_state_out_ch );
-               c_state_out_len--;
-               cs_next_out++;
-               cs_avail_out--;
-            }
-            s_state_out_len_eq_one:
-            {
-               if (cs_avail_out == 0) { 
-                  c_state_out_len = 1; goto return_notr;
-               };
-               *( (UChar*)(cs_next_out) ) = c_state_out_ch;
-               BZ_UPDATE_CRC ( c_calculatedBlockCRC, c_state_out_ch );
-               cs_next_out++;
-               cs_avail_out--;
-            }
-         }   
-         /* Only caused by corrupt data stream? */
-         if (c_nblock_used > s_save_nblockPP)
-            return True;
-
-         /* can a new run be started? */
-         if (c_nblock_used == s_save_nblockPP) {
-            c_state_out_len = 0; goto return_notr;
-         };   
-         c_state_out_ch = c_k0;
-         BZ_GET_FAST_C(k1); c_nblock_used++;
-         if (k1 != c_k0) { 
-            c_k0 = k1; goto s_state_out_len_eq_one; 
-         };
-         if (c_nblock_used == s_save_nblockPP) 
-            goto s_state_out_len_eq_one;
-   
-         c_state_out_len = 2;
-         BZ_GET_FAST_C(k1); c_nblock_used++;
-         if (c_nblock_used == s_save_nblockPP) continue;
-         if (k1 != c_k0) { c_k0 = k1; continue; };
-   
-         c_state_out_len = 3;
-         BZ_GET_FAST_C(k1); c_nblock_used++;
-         if (c_nblock_used == s_save_nblockPP) continue;
-         if (k1 != c_k0) { c_k0 = k1; continue; };
-   
-         BZ_GET_FAST_C(k1); c_nblock_used++;
-         c_state_out_len = ((Int32)k1) + 4;
-         BZ_GET_FAST_C(c_k0); c_nblock_used++;
-      }
-
-      return_notr:
-      total_out_lo32_old = s->strm->total_out_lo32;
-      s->strm->total_out_lo32 += (avail_out_INIT - cs_avail_out);
-      if (s->strm->total_out_lo32 < total_out_lo32_old)
-         s->strm->total_out_hi32++;
-
-      /* save */
-      s->calculatedBlockCRC = c_calculatedBlockCRC;
-      s->state_out_ch       = c_state_out_ch;
-      s->state_out_len      = c_state_out_len;
-      s->nblock_used        = c_nblock_used;
-      s->k0                 = c_k0;
-      s->tt                 = c_tt;
-      s->tPos               = c_tPos;
-      s->strm->next_out     = cs_next_out;
-      s->strm->avail_out    = cs_avail_out;
-      /* end save */
-   }
-   return False;
-}
-
-
-
-/*---------------------------------------------------*/
-__inline__ Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
-{
-   Int32 nb, na, mid;
-   nb = 0;
-   na = 256;
-   do {
-      mid = (nb + na) >> 1;
-      if (indx >= cftab[mid]) nb = mid; else na = mid;
-   }
-   while (na - nb != 1);
-   return nb;
-}
-
-
-/*---------------------------------------------------*/
-/* Return  True iff data corruption is discovered.
-   Returns False if there is no problem.
-*/
-static
-Bool unRLE_obuf_to_output_SMALL ( DState* s )
-{
-   UChar k1;
-
-   if (s->blockRandomised) {
-
-      while (True) {
-         /* try to finish existing run */
-         while (True) {
-            if (s->strm->avail_out == 0) return False;
-            if (s->state_out_len == 0) break;
-            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
-            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
-            s->state_out_len--;
-            s->strm->next_out++;
-            s->strm->avail_out--;
-            s->strm->total_out_lo32++;
-            if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
-         }
-   
-         /* can a new run be started? */
-         if (s->nblock_used == s->save_nblock+1) return False;
-
-         /* Only caused by corrupt data stream? */
-         if (s->nblock_used > s->save_nblock+1)
-            return True;
-   
-         s->state_out_len = 1;
-         s->state_out_ch = s->k0;
-         BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK; 
-         k1 ^= BZ_RAND_MASK; s->nblock_used++;
-         if (s->nblock_used == s->save_nblock+1) continue;
-         if (k1 != s->k0) { s->k0 = k1; continue; };
-   
-         s->state_out_len = 2;
-         BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK; 
-         k1 ^= BZ_RAND_MASK; s->nblock_used++;
-         if (s->nblock_used == s->save_nblock+1) continue;
-         if (k1 != s->k0) { s->k0 = k1; continue; };
-   
-         s->state_out_len = 3;
-         BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK; 
-         k1 ^= BZ_RAND_MASK; s->nblock_used++;
-         if (s->nblock_used == s->save_nblock+1) continue;
-         if (k1 != s->k0) { s->k0 = k1; continue; };
-   
-         BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK; 
-         k1 ^= BZ_RAND_MASK; s->nblock_used++;
-         s->state_out_len = ((Int32)k1) + 4;
-         BZ_GET_SMALL(s->k0); BZ_RAND_UPD_MASK; 
-         s->k0 ^= BZ_RAND_MASK; s->nblock_used++;
-      }
-
-   } else {
-
-      while (True) {
-         /* try to finish existing run */
-         while (True) {
-            if (s->strm->avail_out == 0) return False;
-            if (s->state_out_len == 0) break;
-            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
-            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
-            s->state_out_len--;
-            s->strm->next_out++;
-            s->strm->avail_out--;
-            s->strm->total_out_lo32++;
-            if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
-         }
-   
-         /* can a new run be started? */
-         if (s->nblock_used == s->save_nblock+1) return False;
-
-         /* Only caused by corrupt data stream? */
-         if (s->nblock_used > s->save_nblock+1)
-            return True;
-   
-         s->state_out_len = 1;
-         s->state_out_ch = s->k0;
-         BZ_GET_SMALL(k1); s->nblock_used++;
-         if (s->nblock_used == s->save_nblock+1) continue;
-         if (k1 != s->k0) { s->k0 = k1; continue; };
-   
-         s->state_out_len = 2;
-         BZ_GET_SMALL(k1); s->nblock_used++;
-         if (s->nblock_used == s->save_nblock+1) continue;
-         if (k1 != s->k0) { s->k0 = k1; continue; };
-   
-         s->state_out_len = 3;
-         BZ_GET_SMALL(k1); s->nblock_used++;
-         if (s->nblock_used == s->save_nblock+1) continue;
-         if (k1 != s->k0) { s->k0 = k1; continue; };
-   
-         BZ_GET_SMALL(k1); s->nblock_used++;
-         s->state_out_len = ((Int32)k1) + 4;
-         BZ_GET_SMALL(s->k0); s->nblock_used++;
-      }
-
-   }
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzDecompress) ( bz_stream *strm )
-{
-   Bool    corrupt;
-   DState* s;
-   if (strm == NULL) return BZ_PARAM_ERROR;
-   s = strm->state;
-   if (s == NULL) return BZ_PARAM_ERROR;
-   if (s->strm != strm) return BZ_PARAM_ERROR;
-
-   while (True) {
-      if (s->state == BZ_X_IDLE) return BZ_SEQUENCE_ERROR;
-      if (s->state == BZ_X_OUTPUT) {
-         if (s->smallDecompress)
-            corrupt = unRLE_obuf_to_output_SMALL ( s ); else
-            corrupt = unRLE_obuf_to_output_FAST  ( s );
-         if (corrupt) return BZ_DATA_ERROR;
-         if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
-            BZ_FINALISE_CRC ( s->calculatedBlockCRC );
-            if (s->verbosity >= 3) 
-               VPrintf2 ( " {0x%08x, 0x%08x}", s->storedBlockCRC, 
-                          s->calculatedBlockCRC );
-            if (s->verbosity >= 2) VPrintf0 ( "]" );
-            if (s->calculatedBlockCRC != s->storedBlockCRC)
-               return BZ_DATA_ERROR;
-            s->calculatedCombinedCRC 
-               = (s->calculatedCombinedCRC << 1) | 
-                    (s->calculatedCombinedCRC >> 31);
-            s->calculatedCombinedCRC ^= s->calculatedBlockCRC;
-            s->state = BZ_X_BLKHDR_1;
-         } else {
-            return BZ_OK;
-         }
-      }
-      if (s->state >= BZ_X_MAGIC_1) {
-         Int32 r = BZ2_decompress ( s );
-         if (r == BZ_STREAM_END) {
-            if (s->verbosity >= 3)
-               VPrintf2 ( "\n    combined CRCs: stored = 0x%08x, computed = 0x%08x", 
-                          s->storedCombinedCRC, s->calculatedCombinedCRC );
-            if (s->calculatedCombinedCRC != s->storedCombinedCRC)
-               return BZ_DATA_ERROR;
-            return r;
-         }
-         if (s->state != BZ_X_OUTPUT) return r;
-      }
-   }
-
-   AssertH ( 0, 6001 );
-
-   return 0;  /*NOTREACHED*/
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzDecompressEnd)  ( bz_stream *strm )
-{
-   DState* s;
-   if (strm == NULL) return BZ_PARAM_ERROR;
-   s = strm->state;
-   if (s == NULL) return BZ_PARAM_ERROR;
-   if (s->strm != strm) return BZ_PARAM_ERROR;
-
-   if (s->tt   != NULL) BZFREE(s->tt);
-   if (s->ll16 != NULL) BZFREE(s->ll16);
-   if (s->ll4  != NULL) BZFREE(s->ll4);
-
-   BZFREE(strm->state);
-   strm->state = NULL;
-
-   return BZ_OK;
-}
-
-
-#ifndef BZ_NO_STDIO
-/*---------------------------------------------------*/
-/*--- File I/O stuff                              ---*/
-/*---------------------------------------------------*/
-
-#define BZ_SETERR(eee)                    \
-{                                         \
-   if (bzerror != NULL) *bzerror = eee;   \
-   if (bzf != NULL) bzf->lastErr = eee;   \
-}
-
-typedef 
-   struct {
-      FILE*     handle;
-      Char      buf[BZ_MAX_UNUSED];
-      Int32     bufN;
-      Bool      writing;
-      bz_stream strm;
-      Int32     lastErr;
-      Bool      initialisedOk;
-   }
-   bzFile;
-
-
-/*---------------------------------------------*/
-static Bool myfeof ( FILE* f )
-{
-   Int32 c = fgetc ( f );
-   if (c == EOF) return True;
-   ungetc ( c, f );
-   return False;
-}
-
-
-/*---------------------------------------------------*/
-BZFILE* BZ_API(BZ2_bzWriteOpen) 
-                    ( int*  bzerror,      
-                      FILE* f, 
-                      int   blockSize100k, 
-                      int   verbosity,
-                      int   workFactor )
-{
-   Int32   ret;
-   bzFile* bzf = NULL;
-
-   BZ_SETERR(BZ_OK);
-
-   if (f == NULL ||
-       (blockSize100k < 1 || blockSize100k > 9) ||
-       (workFactor < 0 || workFactor > 250) ||
-       (verbosity < 0 || verbosity > 4))
-      { BZ_SETERR(BZ_PARAM_ERROR); return NULL; };
-
-   if (ferror(f))
-      { BZ_SETERR(BZ_IO_ERROR); return NULL; };
-
-   bzf = malloc ( sizeof(bzFile) );
-   if (bzf == NULL)
-      { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
-
-   BZ_SETERR(BZ_OK);
-   bzf->initialisedOk = False;
-   bzf->bufN          = 0;
-   bzf->handle        = f;
-   bzf->writing       = True;
-   bzf->strm.bzalloc  = NULL;
-   bzf->strm.bzfree   = NULL;
-   bzf->strm.opaque   = NULL;
-
-   if (workFactor == 0) workFactor = 30;
-   ret = BZ2_bzCompressInit ( &(bzf->strm), blockSize100k, 
-                              verbosity, workFactor );
-   if (ret != BZ_OK)
-      { BZ_SETERR(ret); free(bzf); return NULL; };
-
-   bzf->strm.avail_in = 0;
-   bzf->initialisedOk = True;
-   return bzf;   
-}
-
-
-
-/*---------------------------------------------------*/
-void BZ_API(BZ2_bzWrite)
-             ( int*    bzerror, 
-               BZFILE* b, 
-               void*   buf, 
-               int     len )
-{
-   Int32 n, n2, ret;
-   bzFile* bzf = (bzFile*)b;
-
-   BZ_SETERR(BZ_OK);
-   if (bzf == NULL || buf == NULL || len < 0)
-      { BZ_SETERR(BZ_PARAM_ERROR); return; };
-   if (!(bzf->writing))
-      { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
-   if (ferror(bzf->handle))
-      { BZ_SETERR(BZ_IO_ERROR); return; };
-
-   if (len == 0)
-      { BZ_SETERR(BZ_OK); return; };
-
-   bzf->strm.avail_in = len;
-   bzf->strm.next_in  = buf;
-
-   while (True) {
-      bzf->strm.avail_out = BZ_MAX_UNUSED;
-      bzf->strm.next_out = bzf->buf;
-      ret = BZ2_bzCompress ( &(bzf->strm), BZ_RUN );
-      if (ret != BZ_RUN_OK)
-         { BZ_SETERR(ret); return; };
-
-      if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
-         n = BZ_MAX_UNUSED - bzf->strm.avail_out;
-         n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar), 
-                       n, bzf->handle );
-         if (n != n2 || ferror(bzf->handle))
-            { BZ_SETERR(BZ_IO_ERROR); return; };
-      }
-
-      if (bzf->strm.avail_in == 0)
-         { BZ_SETERR(BZ_OK); return; };
-   }
-}
-
-
-/*---------------------------------------------------*/
-void BZ_API(BZ2_bzWriteClose)
-                  ( int*          bzerror, 
-                    BZFILE*       b, 
-                    int           abandon,
-                    unsigned int* nbytes_in,
-                    unsigned int* nbytes_out )
-{
-   BZ2_bzWriteClose64 ( bzerror, b, abandon, 
-                        nbytes_in, NULL, nbytes_out, NULL );
-}
-
-
-void BZ_API(BZ2_bzWriteClose64)
-                  ( int*          bzerror, 
-                    BZFILE*       b, 
-                    int           abandon,
-                    unsigned int* nbytes_in_lo32,
-                    unsigned int* nbytes_in_hi32,
-                    unsigned int* nbytes_out_lo32,
-                    unsigned int* nbytes_out_hi32 )
-{
-   Int32   n, n2, ret;
-   bzFile* bzf = (bzFile*)b;
-
-   if (bzf == NULL)
-      { BZ_SETERR(BZ_OK); return; };
-   if (!(bzf->writing))
-      { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
-   if (ferror(bzf->handle))
-      { BZ_SETERR(BZ_IO_ERROR); return; };
-
-   if (nbytes_in_lo32 != NULL) *nbytes_in_lo32 = 0;
-   if (nbytes_in_hi32 != NULL) *nbytes_in_hi32 = 0;
-   if (nbytes_out_lo32 != NULL) *nbytes_out_lo32 = 0;
-   if (nbytes_out_hi32 != NULL) *nbytes_out_hi32 = 0;
-
-   if ((!abandon) && bzf->lastErr == BZ_OK) {
-      while (True) {
-         bzf->strm.avail_out = BZ_MAX_UNUSED;
-         bzf->strm.next_out = bzf->buf;
-         ret = BZ2_bzCompress ( &(bzf->strm), BZ_FINISH );
-         if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
-            { BZ_SETERR(ret); return; };
-
-         if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
-            n = BZ_MAX_UNUSED - bzf->strm.avail_out;
-            n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar), 
-                          n, bzf->handle );
-            if (n != n2 || ferror(bzf->handle))
-               { BZ_SETERR(BZ_IO_ERROR); return; };
-         }
-
-         if (ret == BZ_STREAM_END) break;
-      }
-   }
-
-   if ( !abandon && !ferror ( bzf->handle ) ) {
-      fflush ( bzf->handle );
-      if (ferror(bzf->handle))
-         { BZ_SETERR(BZ_IO_ERROR); return; };
-   }
-
-   if (nbytes_in_lo32 != NULL)
-      *nbytes_in_lo32 = bzf->strm.total_in_lo32;
-   if (nbytes_in_hi32 != NULL)
-      *nbytes_in_hi32 = bzf->strm.total_in_hi32;
-   if (nbytes_out_lo32 != NULL)
-      *nbytes_out_lo32 = bzf->strm.total_out_lo32;
-   if (nbytes_out_hi32 != NULL)
-      *nbytes_out_hi32 = bzf->strm.total_out_hi32;
-
-   BZ_SETERR(BZ_OK);
-   BZ2_bzCompressEnd ( &(bzf->strm) );
-   free ( bzf );
-}
-
-
-/*---------------------------------------------------*/
-BZFILE* BZ_API(BZ2_bzReadOpen) 
-                   ( int*  bzerror, 
-                     FILE* f, 
-                     int   verbosity,
-                     int   small,
-                     void* unused,
-                     int   nUnused )
-{
-   bzFile* bzf = NULL;
-   int     ret;
-
-   BZ_SETERR(BZ_OK);
-
-   if (f == NULL || 
-       (small != 0 && small != 1) ||
-       (verbosity < 0 || verbosity > 4) ||
-       (unused == NULL && nUnused != 0) ||
-       (unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED)))
-      { BZ_SETERR(BZ_PARAM_ERROR); return NULL; };
-
-   if (ferror(f))
-      { BZ_SETERR(BZ_IO_ERROR); return NULL; };
-
-   bzf = malloc ( sizeof(bzFile) );
-   if (bzf == NULL) 
-      { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
-
-   BZ_SETERR(BZ_OK);
-
-   bzf->initialisedOk = False;
-   bzf->handle        = f;
-   bzf->bufN          = 0;
-   bzf->writing       = False;
-   bzf->strm.bzalloc  = NULL;
-   bzf->strm.bzfree   = NULL;
-   bzf->strm.opaque   = NULL;
-   
-   while (nUnused > 0) {
-      bzf->buf[bzf->bufN] = *((UChar*)(unused)); bzf->bufN++;
-      unused = ((void*)( 1 + ((UChar*)(unused))  ));
-      nUnused--;
-   }
-
-   ret = BZ2_bzDecompressInit ( &(bzf->strm), verbosity, small );
-   if (ret != BZ_OK)
-      { BZ_SETERR(ret); free(bzf); return NULL; };
-
-   bzf->strm.avail_in = bzf->bufN;
-   bzf->strm.next_in  = bzf->buf;
-
-   bzf->initialisedOk = True;
-   return bzf;   
-}
-
-
-/*---------------------------------------------------*/
-void BZ_API(BZ2_bzReadClose) ( int *bzerror, BZFILE *b )
-{
-   bzFile* bzf = (bzFile*)b;
-
-   BZ_SETERR(BZ_OK);
-   if (bzf == NULL)
-      { BZ_SETERR(BZ_OK); return; };
-
-   if (bzf->writing)
-      { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
-
-   if (bzf->initialisedOk)
-      (void)BZ2_bzDecompressEnd ( &(bzf->strm) );
-   free ( bzf );
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzRead) 
-           ( int*    bzerror, 
-             BZFILE* b, 
-             void*   buf, 
-             int     len )
-{
-   Int32   n, ret;
-   bzFile* bzf = (bzFile*)b;
-
-   BZ_SETERR(BZ_OK);
-
-   if (bzf == NULL || buf == NULL || len < 0)
-      { BZ_SETERR(BZ_PARAM_ERROR); return 0; };
-
-   if (bzf->writing)
-      { BZ_SETERR(BZ_SEQUENCE_ERROR); return 0; };
-
-   if (len == 0)
-      { BZ_SETERR(BZ_OK); return 0; };
-
-   bzf->strm.avail_out = len;
-   bzf->strm.next_out = buf;
-
-   while (True) {
-
-      if (ferror(bzf->handle)) 
-         { BZ_SETERR(BZ_IO_ERROR); return 0; };
-
-      if (bzf->strm.avail_in == 0 && !myfeof(bzf->handle)) {
-         n = fread ( bzf->buf, sizeof(UChar), 
-                     BZ_MAX_UNUSED, bzf->handle );
-         if (ferror(bzf->handle))
-            { BZ_SETERR(BZ_IO_ERROR); return 0; };
-         bzf->bufN = n;
-         bzf->strm.avail_in = bzf->bufN;
-         bzf->strm.next_in = bzf->buf;
-      }
-
-      ret = BZ2_bzDecompress ( &(bzf->strm) );
-
-      if (ret != BZ_OK && ret != BZ_STREAM_END)
-         { BZ_SETERR(ret); return 0; };
-
-      if (ret == BZ_OK && myfeof(bzf->handle) && 
-          bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0)
-         { BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; };
-
-      if (ret == BZ_STREAM_END)
-         { BZ_SETERR(BZ_STREAM_END);
-           return len - bzf->strm.avail_out; };
-      if (bzf->strm.avail_out == 0)
-         { BZ_SETERR(BZ_OK); return len; };
-      
-   }
-
-   return 0; /*not reached*/
-}
-
-
-/*---------------------------------------------------*/
-void BZ_API(BZ2_bzReadGetUnused) 
-                     ( int*    bzerror, 
-                       BZFILE* b, 
-                       void**  unused, 
-                       int*    nUnused )
-{
-   bzFile* bzf = (bzFile*)b;
-   if (bzf == NULL)
-      { BZ_SETERR(BZ_PARAM_ERROR); return; };
-   if (bzf->lastErr != BZ_STREAM_END)
-      { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
-   if (unused == NULL || nUnused == NULL)
-      { BZ_SETERR(BZ_PARAM_ERROR); return; };
-
-   BZ_SETERR(BZ_OK);
-   *nUnused = bzf->strm.avail_in;
-   *unused = bzf->strm.next_in;
-}
-#endif
-
-
-/*---------------------------------------------------*/
-/*--- Misc convenience stuff                      ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzBuffToBuffCompress) 
-                         ( char*         dest, 
-                           unsigned int* destLen,
-                           char*         source, 
-                           unsigned int  sourceLen,
-                           int           blockSize100k, 
-                           int           verbosity, 
-                           int           workFactor )
-{
-   bz_stream strm;
-   int ret;
-
-   if (dest == NULL || destLen == NULL || 
-       source == NULL ||
-       blockSize100k < 1 || blockSize100k > 9 ||
-       verbosity < 0 || verbosity > 4 ||
-       workFactor < 0 || workFactor > 250) 
-      return BZ_PARAM_ERROR;
-
-   if (workFactor == 0) workFactor = 30;
-   strm.bzalloc = NULL;
-   strm.bzfree = NULL;
-   strm.opaque = NULL;
-   ret = BZ2_bzCompressInit ( &strm, blockSize100k, 
-                              verbosity, workFactor );
-   if (ret != BZ_OK) return ret;
-
-   strm.next_in = source;
-   strm.next_out = dest;
-   strm.avail_in = sourceLen;
-   strm.avail_out = *destLen;
-
-   ret = BZ2_bzCompress ( &strm, BZ_FINISH );
-   if (ret == BZ_FINISH_OK) goto output_overflow;
-   if (ret != BZ_STREAM_END) goto errhandler;
-
-   /* normal termination */
-   *destLen -= strm.avail_out;   
-   BZ2_bzCompressEnd ( &strm );
-   return BZ_OK;
-
-   output_overflow:
-   BZ2_bzCompressEnd ( &strm );
-   return BZ_OUTBUFF_FULL;
-
-   errhandler:
-   BZ2_bzCompressEnd ( &strm );
-   return ret;
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzBuffToBuffDecompress) 
-                           ( char*         dest, 
-                             unsigned int* destLen,
-                             char*         source, 
-                             unsigned int  sourceLen,
-                             int           small,
-                             int           verbosity )
-{
-   bz_stream strm;
-   int ret;
-
-   if (dest == NULL || destLen == NULL || 
-       source == NULL ||
-       (small != 0 && small != 1) ||
-       verbosity < 0 || verbosity > 4) 
-          return BZ_PARAM_ERROR;
-
-   strm.bzalloc = NULL;
-   strm.bzfree = NULL;
-   strm.opaque = NULL;
-   ret = BZ2_bzDecompressInit ( &strm, verbosity, small );
-   if (ret != BZ_OK) return ret;
-
-   strm.next_in = source;
-   strm.next_out = dest;
-   strm.avail_in = sourceLen;
-   strm.avail_out = *destLen;
-
-   ret = BZ2_bzDecompress ( &strm );
-   if (ret == BZ_OK) goto output_overflow_or_eof;
-   if (ret != BZ_STREAM_END) goto errhandler;
-
-   /* normal termination */
-   *destLen -= strm.avail_out;
-   BZ2_bzDecompressEnd ( &strm );
-   return BZ_OK;
-
-   output_overflow_or_eof:
-   if (strm.avail_out > 0) {
-      BZ2_bzDecompressEnd ( &strm );
-      return BZ_UNEXPECTED_EOF;
-   } else {
-      BZ2_bzDecompressEnd ( &strm );
-      return BZ_OUTBUFF_FULL;
-   };      
-
-   errhandler:
-   BZ2_bzDecompressEnd ( &strm );
-   return ret; 
-}
-
-
-/*---------------------------------------------------*/
-/*--
-   Code contributed by Yoshioka Tsuneo
-   (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
-   to support better zlib compatibility.
-   This code is not _officially_ part of libbzip2 (yet);
-   I haven't tested it, documented it, or considered the
-   threading-safeness of it.
-   If this code breaks, please contact both Yoshioka and me.
---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------------*/
-/*--
-   return version like "0.9.0c".
---*/
-const char * BZ_API(BZ2_bzlibVersion)(void)
-{
-   return BZ_VERSION;
-}
-
-
-#ifndef BZ_NO_STDIO
-/*---------------------------------------------------*/
-
-#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
-#   include <fcntl.h>
-#   include <io.h>
-#   define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)
-#else
-#   define SET_BINARY_MODE(file)
-#endif
-static
-BZFILE * bzopen_or_bzdopen
-               ( const char *path,   /* no use when bzdopen */
-                 int fd,             /* no use when bzdopen */
-                 const char *mode,
-                 int open_mode)      /* bzopen: 0, bzdopen:1 */
-{
-   int    bzerr;
-   char   unused[BZ_MAX_UNUSED];
-   int    blockSize100k = 9;
-   int    writing       = 0;
-   char   mode2[10]     = "";
-   FILE   *fp           = NULL;
-   BZFILE *bzfp         = NULL;
-   int    verbosity     = 0;
-   int    workFactor    = 30;
-   int    smallMode     = 0;
-   int    nUnused       = 0; 
-
-   if (mode == NULL) return NULL;
-   while (*mode) {
-      switch (*mode) {
-      case 'r':
-         writing = 0; break;
-      case 'w':
-         writing = 1; break;
-      case 's':
-         smallMode = 1; break;
-      default:
-         if (isdigit((int)(*mode))) {
-            blockSize100k = *mode-BZ_HDR_0;
-         }
-      }
-      mode++;
-   }
-   strcat(mode2, writing ? "w" : "r" );
-   strcat(mode2,"b");   /* binary mode */
-
-   if (open_mode==0) {
-      if (path==NULL || strcmp(path,"")==0) {
-        fp = (writing ? stdout : stdin);
-        SET_BINARY_MODE(fp);
-      } else {
-        fp = fopen(path,mode2);
-      }
-   } else {
-#ifdef BZ_STRICT_ANSI
-      fp = NULL;
-#else
-      fp = fdopen(fd,mode2);
-#endif
-   }
-   if (fp == NULL) return NULL;
-
-   if (writing) {
-      /* Guard against total chaos and anarchy -- JRS */
-      if (blockSize100k < 1) blockSize100k = 1;
-      if (blockSize100k > 9) blockSize100k = 9; 
-      bzfp = BZ2_bzWriteOpen(&bzerr,fp,blockSize100k,
-                             verbosity,workFactor);
-   } else {
-      bzfp = BZ2_bzReadOpen(&bzerr,fp,verbosity,smallMode,
-                            unused,nUnused);
-   }
-   if (bzfp == NULL) {
-      if (fp != stdin && fp != stdout) fclose(fp);
-      return NULL;
-   }
-   return bzfp;
-}
-
-
-/*---------------------------------------------------*/
-/*--
-   open file for read or write.
-      ex) bzopen("file","w9")
-      case path="" or NULL => use stdin or stdout.
---*/
-BZFILE * BZ_API(BZ2_bzopen)
-               ( const char *path,
-                 const char *mode )
-{
-   return bzopen_or_bzdopen(path,-1,mode,/*bzopen*/0);
-}
-
-
-/*---------------------------------------------------*/
-BZFILE * BZ_API(BZ2_bzdopen)
-               ( int fd,
-                 const char *mode )
-{
-   return bzopen_or_bzdopen(NULL,fd,mode,/*bzdopen*/1);
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzread) (BZFILE* b, void* buf, int len )
-{
-   int bzerr, nread;
-   if (((bzFile*)b)->lastErr == BZ_STREAM_END) return 0;
-   nread = BZ2_bzRead(&bzerr,b,buf,len);
-   if (bzerr == BZ_OK || bzerr == BZ_STREAM_END) {
-      return nread;
-   } else {
-      return -1;
-   }
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzwrite) (BZFILE* b, void* buf, int len )
-{
-   int bzerr;
-
-   BZ2_bzWrite(&bzerr,b,buf,len);
-   if(bzerr == BZ_OK){
-      return len;
-   }else{
-      return -1;
-   }
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzflush) (BZFILE *b)
-{
-   /* do nothing now... */
-   return 0;
-}
-
-
-/*---------------------------------------------------*/
-void BZ_API(BZ2_bzclose) (BZFILE* b)
-{
-   int bzerr;
-   FILE *fp = ((bzFile *)b)->handle;
-   
-   if (b==NULL) {return;}
-   if(((bzFile*)b)->writing){
-      BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL);
-      if(bzerr != BZ_OK){
-         BZ2_bzWriteClose(NULL,b,1,NULL,NULL);
-      }
-   }else{
-      BZ2_bzReadClose(&bzerr,b);
-   }
-   if(fp!=stdin && fp!=stdout){
-      fclose(fp);
-   }
-}
-
-
-/*---------------------------------------------------*/
-/*--
-   return last error code 
---*/
-static char *bzerrorstrings[] = {
-       "OK"
-      ,"SEQUENCE_ERROR"
-      ,"PARAM_ERROR"
-      ,"MEM_ERROR"
-      ,"DATA_ERROR"
-      ,"DATA_ERROR_MAGIC"
-      ,"IO_ERROR"
-      ,"UNEXPECTED_EOF"
-      ,"OUTBUFF_FULL"
-      ,"CONFIG_ERROR"
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-};
-
-
-const char * BZ_API(BZ2_bzerror) (BZFILE *b, int *errnum)
-{
-   int err = ((bzFile *)b)->lastErr;
-
-   if(err>0) err = 0;
-   *errnum = err;
-   return bzerrorstrings[err*-1];
-}
-#endif
-
-
-/*-------------------------------------------------------------*/
-/*--- end                                           bzlib.c ---*/
-/*-------------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/bzlib.h
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzlib.h	(revision 9)
+++ 	(revision )
@@ -1,323 +1,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Public header file for the library.                   ---*/
-/*---                                               bzlib.h ---*/
-/*-------------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-
-#ifndef _BZLIB_H
-#define _BZLIB_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BZ_RUN               0
-#define BZ_FLUSH             1
-#define BZ_FINISH            2
-
-#define BZ_OK                0
-#define BZ_RUN_OK            1
-#define BZ_FLUSH_OK          2
-#define BZ_FINISH_OK         3
-#define BZ_STREAM_END        4
-#define BZ_SEQUENCE_ERROR    (-1)
-#define BZ_PARAM_ERROR       (-2)
-#define BZ_MEM_ERROR         (-3)
-#define BZ_DATA_ERROR        (-4)
-#define BZ_DATA_ERROR_MAGIC  (-5)
-#define BZ_IO_ERROR          (-6)
-#define BZ_UNEXPECTED_EOF    (-7)
-#define BZ_OUTBUFF_FULL      (-8)
-#define BZ_CONFIG_ERROR      (-9)
-
-typedef 
-   struct {
-      char *next_in;
-      unsigned int avail_in;
-      unsigned int total_in_lo32;
-      unsigned int total_in_hi32;
-
-      char *next_out;
-      unsigned int avail_out;
-      unsigned int total_out_lo32;
-      unsigned int total_out_hi32;
-
-      void *state;
-
-      void *(*bzalloc)(void *,int,int);
-      void (*bzfree)(void *,void *);
-      void *opaque;
-   } 
-   bz_stream;
-
-
-#ifndef BZ_IMPORT
-#define BZ_EXPORT
-#endif
-
-#ifndef BZ_NO_STDIO
-/* Need a definitition for FILE */
-#include <stdio.h>
-#endif
-
-#ifdef _WIN32
-#   include <windows.h>
-#   ifdef small
-      /* windows.h define small to char */
-#      undef small
-#   endif
-#   ifdef BZ_EXPORT
-#   define BZ_API(func) WINAPI func
-#   define BZ_EXTERN extern
-#   else
-   /* import windows dll dynamically */
-#   define BZ_API(func) (WINAPI * func)
-#   define BZ_EXTERN
-#   endif
-#else
-#   define BZ_API(func) func
-#   define BZ_EXTERN extern
-#endif
-
-
-/*-- Core (low-level) library functions --*/
-
-BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( 
-      bz_stream* strm, 
-      int        blockSize100k, 
-      int        verbosity, 
-      int        workFactor 
-   );
-
-BZ_EXTERN int BZ_API(BZ2_bzCompress) ( 
-      bz_stream* strm, 
-      int action 
-   );
-
-BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( 
-      bz_stream* strm 
-   );
-
-BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( 
-      bz_stream *strm, 
-      int       verbosity, 
-      int       small
-   );
-
-BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( 
-      bz_stream* strm 
-   );
-
-BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( 
-      bz_stream *strm 
-   );
-
-
-
-/*-- High(er) level library functions --*/
-
-#ifndef BZ_NO_STDIO
-#define BZ_MAX_UNUSED 5000
-
-typedef void BZFILE;
-
-BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( 
-      int*  bzerror,   
-      FILE* f, 
-      int   verbosity, 
-      int   small,
-      void* unused,    
-      int   nUnused 
-   );
-
-BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( 
-      int*    bzerror, 
-      BZFILE* b 
-   );
-
-BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( 
-      int*    bzerror, 
-      BZFILE* b, 
-      void**  unused,  
-      int*    nUnused 
-   );
-
-BZ_EXTERN int BZ_API(BZ2_bzRead) ( 
-      int*    bzerror, 
-      BZFILE* b, 
-      void*   buf, 
-      int     len 
-   );
-
-BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( 
-      int*  bzerror,      
-      FILE* f, 
-      int   blockSize100k, 
-      int   verbosity, 
-      int   workFactor 
-   );
-
-BZ_EXTERN void BZ_API(BZ2_bzWrite) ( 
-      int*    bzerror, 
-      BZFILE* b, 
-      void*   buf, 
-      int     len 
-   );
-
-BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( 
-      int*          bzerror, 
-      BZFILE*       b, 
-      int           abandon, 
-      unsigned int* nbytes_in, 
-      unsigned int* nbytes_out 
-   );
-
-BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( 
-      int*          bzerror, 
-      BZFILE*       b, 
-      int           abandon, 
-      unsigned int* nbytes_in_lo32, 
-      unsigned int* nbytes_in_hi32, 
-      unsigned int* nbytes_out_lo32, 
-      unsigned int* nbytes_out_hi32
-   );
-#endif
-
-
-/*-- Utility functions --*/
-
-BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( 
-      char*         dest, 
-      unsigned int* destLen,
-      char*         source, 
-      unsigned int  sourceLen,
-      int           blockSize100k, 
-      int           verbosity, 
-      int           workFactor 
-   );
-
-BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( 
-      char*         dest, 
-      unsigned int* destLen,
-      char*         source, 
-      unsigned int  sourceLen,
-      int           small, 
-      int           verbosity 
-   );
-
-
-/*--
-   Code contributed by Yoshioka Tsuneo
-   (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
-   to support better zlib compatibility.
-   This code is not _officially_ part of libbzip2 (yet);
-   I haven't tested it, documented it, or considered the
-   threading-safeness of it.
-   If this code breaks, please contact both Yoshioka and me.
---*/
-
-BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
-      void
-   );
-
-#ifndef BZ_NO_STDIO
-BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
-      const char *path,
-      const char *mode
-   );
-
-BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
-      int        fd,
-      const char *mode
-   );
-         
-BZ_EXTERN int BZ_API(BZ2_bzread) (
-      BZFILE* b, 
-      void* buf, 
-      int len 
-   );
-
-BZ_EXTERN int BZ_API(BZ2_bzwrite) (
-      BZFILE* b, 
-      void*   buf, 
-      int     len 
-   );
-
-BZ_EXTERN int BZ_API(BZ2_bzflush) (
-      BZFILE* b
-   );
-
-BZ_EXTERN void BZ_API(BZ2_bzclose) (
-      BZFILE* b
-   );
-
-BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
-      BZFILE *b, 
-      int    *errnum
-   );
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-/*-------------------------------------------------------------*/
-/*--- end                                           bzlib.h ---*/
-/*-------------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/bzlib_private.h
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzlib_private.h	(revision 9)
+++ 	(revision )
@@ -1,537 +1,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Private header file for the library.                  ---*/
-/*---                                       bzlib_private.h ---*/
-/*-------------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-
-#ifndef _BZLIB_PRIVATE_H
-#define _BZLIB_PRIVATE_H
-
-#include <stdlib.h>
-
-#ifndef BZ_NO_STDIO
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#endif
-
-#include "bzlib.h"
-
-
-
-/*-- General stuff. --*/
-
-#define BZ_VERSION  "1.0.3, 15-Feb-2005"
-
-typedef char            Char;
-typedef unsigned char   Bool;
-typedef unsigned char   UChar;
-typedef int             Int32;
-typedef unsigned int    UInt32;
-typedef short           Int16;
-typedef unsigned short  UInt16;
-
-#define True  ((Bool)1)
-#define False ((Bool)0)
-
-#ifndef __GNUC__
-#define __inline__  /* */
-#endif 
-
-#ifndef BZ_NO_STDIO
-extern void BZ2_bz__AssertH__fail ( int errcode );
-#define AssertH(cond,errcode) \
-   { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); }
-#if BZ_DEBUG
-#define AssertD(cond,msg) \
-   { if (!(cond)) {       \
-      fprintf ( stderr,   \
-        "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\
-      exit(1); \
-   }}
-#else
-#define AssertD(cond,msg) /* */
-#endif
-#define VPrintf0(zf) \
-   fprintf(stderr,zf)
-#define VPrintf1(zf,za1) \
-   fprintf(stderr,zf,za1)
-#define VPrintf2(zf,za1,za2) \
-   fprintf(stderr,zf,za1,za2)
-#define VPrintf3(zf,za1,za2,za3) \
-   fprintf(stderr,zf,za1,za2,za3)
-#define VPrintf4(zf,za1,za2,za3,za4) \
-   fprintf(stderr,zf,za1,za2,za3,za4)
-#define VPrintf5(zf,za1,za2,za3,za4,za5) \
-   fprintf(stderr,zf,za1,za2,za3,za4,za5)
-#else
-extern void bz_internal_error ( int errcode );
-#define AssertH(cond,errcode) \
-   { if (!(cond)) bz_internal_error ( errcode ); }
-#define AssertD(cond,msg) /* */
-#define VPrintf0(zf) /* */
-#define VPrintf1(zf,za1) /* */
-#define VPrintf2(zf,za1,za2) /* */
-#define VPrintf3(zf,za1,za2,za3) /* */
-#define VPrintf4(zf,za1,za2,za3,za4) /* */
-#define VPrintf5(zf,za1,za2,za3,za4,za5) /* */
-#endif
-
-
-#define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1)
-#define BZFREE(ppp)  (strm->bzfree)(strm->opaque,(ppp))
-
-
-/*-- Header bytes. --*/
-
-#define BZ_HDR_B 0x42   /* 'B' */
-#define BZ_HDR_Z 0x5a   /* 'Z' */
-#define BZ_HDR_h 0x68   /* 'h' */
-#define BZ_HDR_0 0x30   /* '0' */
-  
-/*-- Constants for the back end. --*/
-
-#define BZ_MAX_ALPHA_SIZE 258
-#define BZ_MAX_CODE_LEN    23
-
-#define BZ_RUNA 0
-#define BZ_RUNB 1
-
-#define BZ_N_GROUPS 6
-#define BZ_G_SIZE   50
-#define BZ_N_ITERS  4
-
-#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
-
-
-
-/*-- Stuff for randomising repetitive blocks. --*/
-
-extern Int32 BZ2_rNums[512];
-
-#define BZ_RAND_DECLS                          \
-   Int32 rNToGo;                               \
-   Int32 rTPos                                 \
-
-#define BZ_RAND_INIT_MASK                      \
-   s->rNToGo = 0;                              \
-   s->rTPos  = 0                               \
-
-#define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0)
-
-#define BZ_RAND_UPD_MASK                       \
-   if (s->rNToGo == 0) {                       \
-      s->rNToGo = BZ2_rNums[s->rTPos];         \
-      s->rTPos++;                              \
-      if (s->rTPos == 512) s->rTPos = 0;       \
-   }                                           \
-   s->rNToGo--;
-
-
-
-/*-- Stuff for doing CRCs. --*/
-
-extern UInt32 BZ2_crc32Table[256];
-
-#define BZ_INITIALISE_CRC(crcVar)              \
-{                                              \
-   crcVar = 0xffffffffL;                       \
-}
-
-#define BZ_FINALISE_CRC(crcVar)                \
-{                                              \
-   crcVar = ~(crcVar);                         \
-}
-
-#define BZ_UPDATE_CRC(crcVar,cha)              \
-{                                              \
-   crcVar = (crcVar << 8) ^                    \
-            BZ2_crc32Table[(crcVar >> 24) ^    \
-                           ((UChar)cha)];      \
-}
-
-
-
-/*-- States and modes for compression. --*/
-
-#define BZ_M_IDLE      1
-#define BZ_M_RUNNING   2
-#define BZ_M_FLUSHING  3
-#define BZ_M_FINISHING 4
-
-#define BZ_S_OUTPUT    1
-#define BZ_S_INPUT     2
-
-#define BZ_N_RADIX 2
-#define BZ_N_QSORT 12
-#define BZ_N_SHELL 18
-#define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
-
-
-
-
-/*-- Structure holding all the compression-side stuff. --*/
-
-typedef
-   struct {
-      /* pointer back to the struct bz_stream */
-      bz_stream* strm;
-
-      /* mode this stream is in, and whether inputting */
-      /* or outputting data */
-      Int32    mode;
-      Int32    state;
-
-      /* remembers avail_in when flush/finish requested */
-      UInt32   avail_in_expect;
-
-      /* for doing the block sorting */
-      UInt32*  arr1;
-      UInt32*  arr2;
-      UInt32*  ftab;
-      Int32    origPtr;
-
-      /* aliases for arr1 and arr2 */
-      UInt32*  ptr;
-      UChar*   block;
-      UInt16*  mtfv;
-      UChar*   zbits;
-
-      /* for deciding when to use the fallback sorting algorithm */
-      Int32    workFactor;
-
-      /* run-length-encoding of the input */
-      UInt32   state_in_ch;
-      Int32    state_in_len;
-      BZ_RAND_DECLS;
-
-      /* input and output limits and current posns */
-      Int32    nblock;
-      Int32    nblockMAX;
-      Int32    numZ;
-      Int32    state_out_pos;
-
-      /* map of bytes used in block */
-      Int32    nInUse;
-      Bool     inUse[256];
-      UChar    unseqToSeq[256];
-
-      /* the buffer for bit stream creation */
-      UInt32   bsBuff;
-      Int32    bsLive;
-
-      /* block and combined CRCs */
-      UInt32   blockCRC;
-      UInt32   combinedCRC;
-
-      /* misc administratium */
-      Int32    verbosity;
-      Int32    blockNo;
-      Int32    blockSize100k;
-
-      /* stuff for coding the MTF values */
-      Int32    nMTF;
-      Int32    mtfFreq    [BZ_MAX_ALPHA_SIZE];
-      UChar    selector   [BZ_MAX_SELECTORS];
-      UChar    selectorMtf[BZ_MAX_SELECTORS];
-
-      UChar    len     [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-      Int32    code    [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-      Int32    rfreq   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-      /* second dimension: only 3 needed; 4 makes index calculations faster */
-      UInt32   len_pack[BZ_MAX_ALPHA_SIZE][4];
-
-   }
-   EState;
-
-
-
-/*-- externs for compression. --*/
-
-extern void 
-BZ2_blockSort ( EState* );
-
-extern void 
-BZ2_compressBlock ( EState*, Bool );
-
-extern void 
-BZ2_bsInitWrite ( EState* );
-
-extern void 
-BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
-
-extern void 
-BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
-
-
-
-/*-- states for decompression. --*/
-
-#define BZ_X_IDLE        1
-#define BZ_X_OUTPUT      2
-
-#define BZ_X_MAGIC_1     10
-#define BZ_X_MAGIC_2     11
-#define BZ_X_MAGIC_3     12
-#define BZ_X_MAGIC_4     13
-#define BZ_X_BLKHDR_1    14
-#define BZ_X_BLKHDR_2    15
-#define BZ_X_BLKHDR_3    16
-#define BZ_X_BLKHDR_4    17
-#define BZ_X_BLKHDR_5    18
-#define BZ_X_BLKHDR_6    19
-#define BZ_X_BCRC_1      20
-#define BZ_X_BCRC_2      21
-#define BZ_X_BCRC_3      22
-#define BZ_X_BCRC_4      23
-#define BZ_X_RANDBIT     24
-#define BZ_X_ORIGPTR_1   25
-#define BZ_X_ORIGPTR_2   26
-#define BZ_X_ORIGPTR_3   27
-#define BZ_X_MAPPING_1   28
-#define BZ_X_MAPPING_2   29
-#define BZ_X_SELECTOR_1  30
-#define BZ_X_SELECTOR_2  31
-#define BZ_X_SELECTOR_3  32
-#define BZ_X_CODING_1    33
-#define BZ_X_CODING_2    34
-#define BZ_X_CODING_3    35
-#define BZ_X_MTF_1       36
-#define BZ_X_MTF_2       37
-#define BZ_X_MTF_3       38
-#define BZ_X_MTF_4       39
-#define BZ_X_MTF_5       40
-#define BZ_X_MTF_6       41
-#define BZ_X_ENDHDR_2    42
-#define BZ_X_ENDHDR_3    43
-#define BZ_X_ENDHDR_4    44
-#define BZ_X_ENDHDR_5    45
-#define BZ_X_ENDHDR_6    46
-#define BZ_X_CCRC_1      47
-#define BZ_X_CCRC_2      48
-#define BZ_X_CCRC_3      49
-#define BZ_X_CCRC_4      50
-
-
-
-/*-- Constants for the fast MTF decoder. --*/
-
-#define MTFA_SIZE 4096
-#define MTFL_SIZE 16
-
-
-
-/*-- Structure holding all the decompression-side stuff. --*/
-
-typedef
-   struct {
-      /* pointer back to the struct bz_stream */
-      bz_stream* strm;
-
-      /* state indicator for this stream */
-      Int32    state;
-
-      /* for doing the final run-length decoding */
-      UChar    state_out_ch;
-      Int32    state_out_len;
-      Bool     blockRandomised;
-      BZ_RAND_DECLS;
-
-      /* the buffer for bit stream reading */
-      UInt32   bsBuff;
-      Int32    bsLive;
-
-      /* misc administratium */
-      Int32    blockSize100k;
-      Bool     smallDecompress;
-      Int32    currBlockNo;
-      Int32    verbosity;
-
-      /* for undoing the Burrows-Wheeler transform */
-      Int32    origPtr;
-      UInt32   tPos;
-      Int32    k0;
-      Int32    unzftab[256];
-      Int32    nblock_used;
-      Int32    cftab[257];
-      Int32    cftabCopy[257];
-
-      /* for undoing the Burrows-Wheeler transform (FAST) */
-      UInt32   *tt;
-
-      /* for undoing the Burrows-Wheeler transform (SMALL) */
-      UInt16   *ll16;
-      UChar    *ll4;
-
-      /* stored and calculated CRCs */
-      UInt32   storedBlockCRC;
-      UInt32   storedCombinedCRC;
-      UInt32   calculatedBlockCRC;
-      UInt32   calculatedCombinedCRC;
-
-      /* map of bytes used in block */
-      Int32    nInUse;
-      Bool     inUse[256];
-      Bool     inUse16[16];
-      UChar    seqToUnseq[256];
-
-      /* for decoding the MTF values */
-      UChar    mtfa   [MTFA_SIZE];
-      Int32    mtfbase[256 / MTFL_SIZE];
-      UChar    selector   [BZ_MAX_SELECTORS];
-      UChar    selectorMtf[BZ_MAX_SELECTORS];
-      UChar    len  [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-
-      Int32    limit  [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-      Int32    base   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-      Int32    perm   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-      Int32    minLens[BZ_N_GROUPS];
-
-      /* save area for scalars in the main decompress code */
-      Int32    save_i;
-      Int32    save_j;
-      Int32    save_t;
-      Int32    save_alphaSize;
-      Int32    save_nGroups;
-      Int32    save_nSelectors;
-      Int32    save_EOB;
-      Int32    save_groupNo;
-      Int32    save_groupPos;
-      Int32    save_nextSym;
-      Int32    save_nblockMAX;
-      Int32    save_nblock;
-      Int32    save_es;
-      Int32    save_N;
-      Int32    save_curr;
-      Int32    save_zt;
-      Int32    save_zn; 
-      Int32    save_zvec;
-      Int32    save_zj;
-      Int32    save_gSel;
-      Int32    save_gMinlen;
-      Int32*   save_gLimit;
-      Int32*   save_gBase;
-      Int32*   save_gPerm;
-
-   }
-   DState;
-
-
-
-/*-- Macros for decompression. --*/
-
-#define BZ_GET_FAST(cccc)                     \
-    s->tPos = s->tt[s->tPos];                 \
-    cccc = (UChar)(s->tPos & 0xff);           \
-    s->tPos >>= 8;
-
-#define BZ_GET_FAST_C(cccc)                   \
-    c_tPos = c_tt[c_tPos];                    \
-    cccc = (UChar)(c_tPos & 0xff);            \
-    c_tPos >>= 8;
-
-#define SET_LL4(i,n)                                          \
-   { if (((i) & 0x1) == 0)                                    \
-        s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else    \
-        s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4);  \
-   }
-
-#define GET_LL4(i)                             \
-   ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF)
-
-#define SET_LL(i,n)                          \
-   { s->ll16[i] = (UInt16)(n & 0x0000ffff);  \
-     SET_LL4(i, n >> 16);                    \
-   }
-
-#define GET_LL(i) \
-   (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
-
-#define BZ_GET_SMALL(cccc)                            \
-      cccc = BZ2_indexIntoF ( s->tPos, s->cftab );    \
-      s->tPos = GET_LL(s->tPos);
-
-
-/*-- externs for decompression. --*/
-
-extern Int32 
-BZ2_indexIntoF ( Int32, Int32* );
-
-extern Int32 
-BZ2_decompress ( DState* );
-
-extern void 
-BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
-                           Int32,  Int32, Int32 );
-
-
-#endif
-
-
-/*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/
-
-#ifdef BZ_NO_STDIO
-#ifndef NULL
-#define NULL 0
-#endif
-#endif
-
-
-/*-------------------------------------------------------------*/
-/*--- end                                   bzlib_private.h ---*/
-/*-------------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/bzmore
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzmore	(revision 9)
+++ 	(revision )
@@ -1,61 +1,0 @@
-#!/bin/sh
-
-# Bzmore wrapped for bzip2, 
-# adapted from zmore by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
-
-PATH="/usr/bin:$PATH"; export PATH
-
-prog=`echo $0 | sed 's|.*/||'`
-case "$prog" in
-	*less)	more=less	;;
-	*)	more=more       ;;
-esac
-
-if test "`echo -n a`" = "-n a"; then
-  # looks like a SysV system:
-  n1=''; n2='\c'
-else
-  n1='-n'; n2=''
-fi
-oldtty=`stty -g 2>/dev/null`
-if stty -cbreak 2>/dev/null; then
-  cb='cbreak'; ncb='-cbreak'
-else
-  # 'stty min 1' resets eof to ^a on both SunOS and SysV!
-  cb='min 1 -icanon'; ncb='icanon eof ^d'
-fi
-if test $? -eq 0 -a -n "$oldtty"; then
-   trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
-else
-   trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
-fi
-
-if test $# = 0; then
-    if test -t 0; then
-	echo usage: $prog files...
-    else
-	bzip2 -cdfq | eval $more
-    fi
-else
-    FIRST=1
-    for FILE
-    do
-	if test $FIRST -eq 0; then
-		echo $n1 "--More--(Next file: $FILE)$n2"
-		stty $cb -echo 2>/dev/null
-		ANS=`dd bs=1 count=1 2>/dev/null` 
-		stty $ncb echo 2>/dev/null
-		echo " "
-		if test "$ANS" = 'e' -o "$ANS" = 'q'; then
-			exit
-		fi
-	fi
-	if test "$ANS" != 's'; then
-		echo "------> $FILE <------"
-		bzip2 -cdfq "$FILE" | eval $more
-	fi
-	if test -t; then
-		FIRST=0
-	fi
-    done
-fi
Index: trunk/minix/commands/bzip2-1.0.3/bzmore.1
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/bzmore.1	(revision 9)
+++ 	(revision )
@@ -1,152 +1,0 @@
-.\"Shamelessly copied from zmore.1 by Philippe Troin <phil@fifi.org>
-.\"for Debian GNU/Linux
-.TH BZMORE 1
-.SH NAME
-bzmore, bzless \- file perusal filter for crt viewing of bzip2 compressed text
-.SH SYNOPSIS
-.B bzmore
-[ name ...  ]
-.br
-.B bzless
-[ name ...  ]
-.SH NOTE
-In the following description,
-.I bzless
-and
-.I less
-can be used interchangeably with
-.I bzmore
-and
-.I more.
-.SH DESCRIPTION
-.I  Bzmore
-is a filter which allows examination of compressed or plain text files
-one screenful at a time on a soft-copy terminal.
-.I bzmore
-works on files compressed with
-.I bzip2
-and also on uncompressed files.
-If a file does not exist,
-.I bzmore
-looks for a file of the same name with the addition of a .bz2 suffix.
-.PP
-.I Bzmore
-normally pauses after each screenful, printing --More--
-at the bottom of the screen.
-If the user then types a carriage return, one more line is displayed.
-If the user hits a space,
-another screenful is displayed.  Other possibilities are enumerated later.
-.PP
-.I Bzmore
-looks in the file
-.I /etc/termcap
-to determine terminal characteristics,
-and to determine the default window size.
-On a terminal capable of displaying 24 lines,
-the default window size is 22 lines.
-Other sequences which may be typed when
-.I bzmore
-pauses, and their effects, are as follows (\fIi\fP is an optional integer
-argument, defaulting to 1) :
-.PP
-.IP \fIi\|\fP<space>
-display
-.I i
-more lines, (or another screenful if no argument is given)
-.PP
-.IP ^D
-display 11 more lines (a ``scroll'').
-If
-.I i
-is given, then the scroll size is set to \fIi\|\fP.
-.PP
-.IP d
-same as ^D (control-D)
-.PP
-.IP \fIi\|\fPz
-same as typing a space except that \fIi\|\fP, if present, becomes the new
-window size.  Note that the window size reverts back to the default at the
-end of the current file.
-.PP
-.IP \fIi\|\fPs
-skip \fIi\|\fP lines and print a screenful of lines
-.PP
-.IP \fIi\|\fPf
-skip \fIi\fP screenfuls and print a screenful of lines
-.PP
-.IP "q or Q"
-quit reading the current file; go on to the next (if any)
-.PP
-.IP "e or q"
-When the prompt --More--(Next file: 
-.IR file )
-is printed, this command causes bzmore to exit.
-.PP
-.IP s
-When the prompt --More--(Next file: 
-.IR file )
-is printed, this command causes bzmore to skip the next file and continue.
-.PP 
-.IP =
-Display the current line number.
-.PP
-.IP \fIi\|\fP/expr
-search for the \fIi\|\fP-th occurrence of the regular expression \fIexpr.\fP
-If the pattern is not found,
-.I bzmore
-goes on to the next file (if any).
-Otherwise, a screenful is displayed, starting two lines before the place
-where the expression was found.
-The user's erase and kill characters may be used to edit the regular
-expression.
-Erasing back past the first column cancels the search command.
-.PP
-.IP \fIi\|\fPn
-search for the \fIi\|\fP-th occurrence of the last regular expression entered.
-.PP
-.IP !command
-invoke a shell with \fIcommand\|\fP. 
-The character `!' in "command" are replaced with the
-previous shell command.  The sequence "\\!" is replaced by "!".
-.PP
-.IP ":q or :Q"
-quit reading the current file; go on to the next (if any)
-(same as q or Q).
-.PP
-.IP .
-(dot) repeat the previous command.
-.PP
-The commands take effect immediately, i.e., it is not necessary to
-type a carriage return.
-Up to the time when the command character itself is given,
-the user may hit the line kill character to cancel the numerical
-argument being formed.
-In addition, the user may hit the erase character to redisplay the
---More-- message.
-.PP
-At any time when output is being sent to the terminal, the user can
-hit the quit key (normally control\-\\).
-.I Bzmore
-will stop sending output, and will display the usual --More--
-prompt.
-The user may then enter one of the above commands in the normal manner.
-Unfortunately, some output is lost when this is done, due to the
-fact that any characters waiting in the terminal's output queue
-are flushed when the quit signal occurs.
-.PP
-The terminal is set to
-.I noecho
-mode by this program so that the output can be continuous.
-What you type will thus not show on your terminal, except for the / and !
-commands.
-.PP
-If the standard output is not a teletype, then
-.I bzmore
-acts just like
-.I bzcat,
-except that a header is printed before each file.
-.SH FILES
-.DT
-/etc/termcap		Terminal data base
-.SH "SEE ALSO"
-more(1), less(1), bzip2(1), bzdiff(1), bzgrep(1)
Index: trunk/minix/commands/bzip2-1.0.3/compress.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/compress.c	(revision 9)
+++ 	(revision )
@@ -1,716 +1,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Compression machinery (not incl block sorting)        ---*/
-/*---                                            compress.c ---*/
-/*-------------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-/*--
-   CHANGES
-   ~~~~~~~
-   0.9.0 -- original version.
-
-   0.9.0a/b -- no changes in this file.
-
-   0.9.0c
-      * changed setting of nGroups in sendMTFValues() so as to 
-        do a bit better on small files
---*/
-
-#include "bzlib_private.h"
-
-
-/*---------------------------------------------------*/
-/*--- Bit stream I/O                              ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------------*/
-void BZ2_bsInitWrite ( EState* s )
-{
-   s->bsLive = 0;
-   s->bsBuff = 0;
-}
-
-
-/*---------------------------------------------------*/
-static
-void bsFinishWrite ( EState* s )
-{
-   while (s->bsLive > 0) {
-      s->zbits[s->numZ] = (UChar)(s->bsBuff >> 24);
-      s->numZ++;
-      s->bsBuff <<= 8;
-      s->bsLive -= 8;
-   }
-}
-
-
-/*---------------------------------------------------*/
-#define bsNEEDW(nz)                           \
-{                                             \
-   while (s->bsLive >= 8) {                   \
-      s->zbits[s->numZ]                       \
-         = (UChar)(s->bsBuff >> 24);          \
-      s->numZ++;                              \
-      s->bsBuff <<= 8;                        \
-      s->bsLive -= 8;                         \
-   }                                          \
-}
-
-
-/*---------------------------------------------------*/
-static
-__inline__
-void bsW ( EState* s, Int32 n, UInt32 v )
-{
-   bsNEEDW ( n );
-   s->bsBuff |= (v << (32 - s->bsLive - n));
-   s->bsLive += n;
-}
-
-
-/*---------------------------------------------------*/
-static
-void bsPutUInt32 ( EState* s, UInt32 u )
-{
-   bsW ( s, 8, (u >> 24) & 0xffL );
-   bsW ( s, 8, (u >> 16) & 0xffL );
-   bsW ( s, 8, (u >>  8) & 0xffL );
-   bsW ( s, 8,  u        & 0xffL );
-}
-
-
-/*---------------------------------------------------*/
-static
-void bsPutUChar ( EState* s, UChar c )
-{
-   bsW( s, 8, (UInt32)c );
-}
-
-
-/*---------------------------------------------------*/
-/*--- The back end proper                         ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------------*/
-static
-void makeMaps_e ( EState* s )
-{
-   Int32 i;
-   s->nInUse = 0;
-   for (i = 0; i < 256; i++)
-      if (s->inUse[i]) {
-         s->unseqToSeq[i] = s->nInUse;
-         s->nInUse++;
-      }
-}
-
-
-/*---------------------------------------------------*/
-static
-void generateMTFValues ( EState* s )
-{
-   UChar   yy[256];
-   Int32   i, j;
-   Int32   zPend;
-   Int32   wr;
-   Int32   EOB;
-
-   /* 
-      After sorting (eg, here),
-         s->arr1 [ 0 .. s->nblock-1 ] holds sorted order,
-         and
-         ((UChar*)s->arr2) [ 0 .. s->nblock-1 ] 
-         holds the original block data.
-
-      The first thing to do is generate the MTF values,
-      and put them in
-         ((UInt16*)s->arr1) [ 0 .. s->nblock-1 ].
-      Because there are strictly fewer or equal MTF values
-      than block values, ptr values in this area are overwritten
-      with MTF values only when they are no longer needed.
-
-      The final compressed bitstream is generated into the
-      area starting at
-         (UChar*) (&((UChar*)s->arr2)[s->nblock])
-
-      These storage aliases are set up in bzCompressInit(),
-      except for the last one, which is arranged in 
-      compressBlock().
-   */
-   UInt32* ptr   = s->ptr;
-   UChar* block  = s->block;
-   UInt16* mtfv  = s->mtfv;
-
-   makeMaps_e ( s );
-   EOB = s->nInUse+1;
-
-   for (i = 0; i <= EOB; i++) s->mtfFreq[i] = 0;
-
-   wr = 0;
-   zPend = 0;
-   for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i;
-
-   for (i = 0; i < s->nblock; i++) {
-      UChar ll_i;
-      AssertD ( wr <= i, "generateMTFValues(1)" );
-      j = ptr[i]-1; if (j < 0) j += s->nblock;
-      ll_i = s->unseqToSeq[block[j]];
-      AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" );
-
-      if (yy[0] == ll_i) { 
-         zPend++;
-      } else {
-
-         if (zPend > 0) {
-            zPend--;
-            while (True) {
-               if (zPend & 1) {
-                  mtfv[wr] = BZ_RUNB; wr++; 
-                  s->mtfFreq[BZ_RUNB]++; 
-               } else {
-                  mtfv[wr] = BZ_RUNA; wr++; 
-                  s->mtfFreq[BZ_RUNA]++; 
-               }
-               if (zPend < 2) break;
-               zPend = (zPend - 2) / 2;
-            };
-            zPend = 0;
-         }
-         {
-            register UChar  rtmp;
-            register UChar* ryy_j;
-            register UChar  rll_i;
-            rtmp  = yy[1];
-            yy[1] = yy[0];
-            ryy_j = &(yy[1]);
-            rll_i = ll_i;
-            while ( rll_i != rtmp ) {
-               register UChar rtmp2;
-               ryy_j++;
-               rtmp2  = rtmp;
-               rtmp   = *ryy_j;
-               *ryy_j = rtmp2;
-            };
-            yy[0] = rtmp;
-            j = ryy_j - &(yy[0]);
-            mtfv[wr] = j+1; wr++; s->mtfFreq[j+1]++;
-         }
-
-      }
-   }
-
-   if (zPend > 0) {
-      zPend--;
-      while (True) {
-         if (zPend & 1) {
-            mtfv[wr] = BZ_RUNB; wr++; 
-            s->mtfFreq[BZ_RUNB]++; 
-         } else {
-            mtfv[wr] = BZ_RUNA; wr++; 
-            s->mtfFreq[BZ_RUNA]++; 
-         }
-         if (zPend < 2) break;
-         zPend = (zPend - 2) / 2;
-      };
-      zPend = 0;
-   }
-
-   mtfv[wr] = EOB; wr++; s->mtfFreq[EOB]++;
-
-   s->nMTF = wr;
-}
-
-
-/*---------------------------------------------------*/
-#define BZ_LESSER_ICOST  0
-#define BZ_GREATER_ICOST 15
-
-static
-void sendMTFValues ( EState* s )
-{
-   Int32 v, t, i, j, gs, ge, totc, bt, bc, iter;
-   Int32 nSelectors, alphaSize, minLen, maxLen, selCtr;
-   Int32 nGroups, nBytes;
-
-   /*--
-   UChar  len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-   is a global since the decoder also needs it.
-
-   Int32  code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-   Int32  rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
-   are also globals only used in this proc.
-   Made global to keep stack frame size small.
-   --*/
-
-
-   UInt16 cost[BZ_N_GROUPS];
-   Int32  fave[BZ_N_GROUPS];
-
-   UInt16* mtfv = s->mtfv;
-
-   if (s->verbosity >= 3)
-      VPrintf3( "      %d in block, %d after MTF & 1-2 coding, "
-                "%d+2 syms in use\n", 
-                s->nblock, s->nMTF, s->nInUse );
-
-   alphaSize = s->nInUse+2;
-   for (t = 0; t < BZ_N_GROUPS; t++)
-      for (v = 0; v < alphaSize; v++)
-         s->len[t][v] = BZ_GREATER_ICOST;
-
-   /*--- Decide how many coding tables to use ---*/
-   AssertH ( s->nMTF > 0, 3001 );
-   if (s->nMTF < 200)  nGroups = 2; else
-   if (s->nMTF < 600)  nGroups = 3; else
-   if (s->nMTF < 1200) nGroups = 4; else
-   if (s->nMTF < 2400) nGroups = 5; else
-                       nGroups = 6;
-
-   /*--- Generate an initial set of coding tables ---*/
-   { 
-      Int32 nPart, remF, tFreq, aFreq;
-
-      nPart = nGroups;
-      remF  = s->nMTF;
-      gs = 0;
-      while (nPart > 0) {
-         tFreq = remF / nPart;
-         ge = gs-1;
-         aFreq = 0;
-         while (aFreq < tFreq && ge < alphaSize-1) {
-            ge++;
-            aFreq += s->mtfFreq[ge];
-         }
-
-         if (ge > gs 
-             && nPart != nGroups && nPart != 1 
-             && ((nGroups-nPart) % 2 == 1)) {
-            aFreq -= s->mtfFreq[ge];
-            ge--;
-         }
-
-         if (s->verbosity >= 3)
-            VPrintf5( "      initial group %d, [%d .. %d], "
-                      "has %d syms (%4.1f%%)\n",
-                      nPart, gs, ge, aFreq, 
-                      (100.0 * (float)aFreq) / (float)(s->nMTF) );
- 
-         for (v = 0; v < alphaSize; v++)
-            if (v >= gs && v <= ge) 
-               s->len[nPart-1][v] = BZ_LESSER_ICOST; else
-               s->len[nPart-1][v] = BZ_GREATER_ICOST;
- 
-         nPart--;
-         gs = ge+1;
-         remF -= aFreq;
-      }
-   }
-
-   /*--- 
-      Iterate up to BZ_N_ITERS times to improve the tables.
-   ---*/
-   for (iter = 0; iter < BZ_N_ITERS; iter++) {
-
-      for (t = 0; t < nGroups; t++) fave[t] = 0;
-
-      for (t = 0; t < nGroups; t++)
-         for (v = 0; v < alphaSize; v++)
-            s->rfreq[t][v] = 0;
-
-      /*---
-        Set up an auxiliary length table which is used to fast-track
-	the common case (nGroups == 6). 
-      ---*/
-      if (nGroups == 6) {
-         for (v = 0; v < alphaSize; v++) {
-            s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
-            s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
-            s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v];
-	 }
-      }
-
-      nSelectors = 0;
-      totc = 0;
-      gs = 0;
-      while (True) {
-
-         /*--- Set group start & end marks. --*/
-         if (gs >= s->nMTF) break;
-         ge = gs + BZ_G_SIZE - 1; 
-         if (ge >= s->nMTF) ge = s->nMTF-1;
-
-         /*-- 
-            Calculate the cost of this group as coded
-            by each of the coding tables.
-         --*/
-         for (t = 0; t < nGroups; t++) cost[t] = 0;
-
-         if (nGroups == 6 && 50 == ge-gs+1) {
-            /*--- fast track the common case ---*/
-            register UInt32 cost01, cost23, cost45;
-            register UInt16 icv;
-            cost01 = cost23 = cost45 = 0;
-
-#           define BZ_ITER(nn)                \
-               icv = mtfv[gs+(nn)];           \
-               cost01 += s->len_pack[icv][0]; \
-               cost23 += s->len_pack[icv][1]; \
-               cost45 += s->len_pack[icv][2]; \
-
-            BZ_ITER(0);  BZ_ITER(1);  BZ_ITER(2);  BZ_ITER(3);  BZ_ITER(4);
-            BZ_ITER(5);  BZ_ITER(6);  BZ_ITER(7);  BZ_ITER(8);  BZ_ITER(9);
-            BZ_ITER(10); BZ_ITER(11); BZ_ITER(12); BZ_ITER(13); BZ_ITER(14);
-            BZ_ITER(15); BZ_ITER(16); BZ_ITER(17); BZ_ITER(18); BZ_ITER(19);
-            BZ_ITER(20); BZ_ITER(21); BZ_ITER(22); BZ_ITER(23); BZ_ITER(24);
-            BZ_ITER(25); BZ_ITER(26); BZ_ITER(27); BZ_ITER(28); BZ_ITER(29);
-            BZ_ITER(30); BZ_ITER(31); BZ_ITER(32); BZ_ITER(33); BZ_ITER(34);
-            BZ_ITER(35); BZ_ITER(36); BZ_ITER(37); BZ_ITER(38); BZ_ITER(39);
-            BZ_ITER(40); BZ_ITER(41); BZ_ITER(42); BZ_ITER(43); BZ_ITER(44);
-            BZ_ITER(45); BZ_ITER(46); BZ_ITER(47); BZ_ITER(48); BZ_ITER(49);
-
-#           undef BZ_ITER
-
-            cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
-            cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
-            cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
-
-         } else {
-	    /*--- slow version which correctly handles all situations ---*/
-            for (i = gs; i <= ge; i++) { 
-               UInt16 icv = mtfv[i];
-               for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv];
-            }
-         }
- 
-         /*-- 
-            Find the coding table which is best for this group,
-            and record its identity in the selector table.
-         --*/
-         bc = 999999999; bt = -1;
-         for (t = 0; t < nGroups; t++)
-            if (cost[t] < bc) { bc = cost[t]; bt = t; };
-         totc += bc;
-         fave[bt]++;
-         s->selector[nSelectors] = bt;
-         nSelectors++;
-
-         /*-- 
-            Increment the symbol frequencies for the selected table.
-          --*/
-         if (nGroups == 6 && 50 == ge-gs+1) {
-            /*--- fast track the common case ---*/
-
-#           define BZ_ITUR(nn) s->rfreq[bt][ mtfv[gs+(nn)] ]++
-
-            BZ_ITUR(0);  BZ_ITUR(1);  BZ_ITUR(2);  BZ_ITUR(3);  BZ_ITUR(4);
-            BZ_ITUR(5);  BZ_ITUR(6);  BZ_ITUR(7);  BZ_ITUR(8);  BZ_ITUR(9);
-            BZ_ITUR(10); BZ_ITUR(11); BZ_ITUR(12); BZ_ITUR(13); BZ_ITUR(14);
-            BZ_ITUR(15); BZ_ITUR(16); BZ_ITUR(17); BZ_ITUR(18); BZ_ITUR(19);
-            BZ_ITUR(20); BZ_ITUR(21); BZ_ITUR(22); BZ_ITUR(23); BZ_ITUR(24);
-            BZ_ITUR(25); BZ_ITUR(26); BZ_ITUR(27); BZ_ITUR(28); BZ_ITUR(29);
-            BZ_ITUR(30); BZ_ITUR(31); BZ_ITUR(32); BZ_ITUR(33); BZ_ITUR(34);
-            BZ_ITUR(35); BZ_ITUR(36); BZ_ITUR(37); BZ_ITUR(38); BZ_ITUR(39);
-            BZ_ITUR(40); BZ_ITUR(41); BZ_ITUR(42); BZ_ITUR(43); BZ_ITUR(44);
-            BZ_ITUR(45); BZ_ITUR(46); BZ_ITUR(47); BZ_ITUR(48); BZ_ITUR(49);
-
-#           undef BZ_ITUR
-
-         } else {
-	    /*--- slow version which correctly handles all situations ---*/
-            for (i = gs; i <= ge; i++)
-               s->rfreq[bt][ mtfv[i] ]++;
-         }
-
-         gs = ge+1;
-      }
-      if (s->verbosity >= 3) {
-         VPrintf2 ( "      pass %d: size is %d, grp uses are ", 
-                   iter+1, totc/8 );
-         for (t = 0; t < nGroups; t++)
-            VPrintf1 ( "%d ", fave[t] );
-         VPrintf0 ( "\n" );
-      }
-
-      /*--
-        Recompute the tables based on the accumulated frequencies.
-      --*/
-      /* maxLen was changed from 20 to 17 in bzip2-1.0.3.  See 
-         comment in huffman.c for details. */
-      for (t = 0; t < nGroups; t++)
-         BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]), 
-                                 alphaSize, 17 /*20*/ );
-   }
-
-
-   AssertH( nGroups < 8, 3002 );
-   AssertH( nSelectors < 32768 &&
-            nSelectors <= (2 + (900000 / BZ_G_SIZE)),
-            3003 );
-
-
-   /*--- Compute MTF values for the selectors. ---*/
-   {
-      UChar pos[BZ_N_GROUPS], ll_i, tmp2, tmp;
-      for (i = 0; i < nGroups; i++) pos[i] = i;
-      for (i = 0; i < nSelectors; i++) {
-         ll_i = s->selector[i];
-         j = 0;
-         tmp = pos[j];
-         while ( ll_i != tmp ) {
-            j++;
-            tmp2 = tmp;
-            tmp = pos[j];
-            pos[j] = tmp2;
-         };
-         pos[0] = tmp;
-         s->selectorMtf[i] = j;
-      }
-   };
-
-   /*--- Assign actual codes for the tables. --*/
-   for (t = 0; t < nGroups; t++) {
-      minLen = 32;
-      maxLen = 0;
-      for (i = 0; i < alphaSize; i++) {
-         if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
-         if (s->len[t][i] < minLen) minLen = s->len[t][i];
-      }
-      AssertH ( !(maxLen > 17 /*20*/ ), 3004 );
-      AssertH ( !(minLen < 1),  3005 );
-      BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]), 
-                          minLen, maxLen, alphaSize );
-   }
-
-   /*--- Transmit the mapping table. ---*/
-   { 
-      Bool inUse16[16];
-      for (i = 0; i < 16; i++) {
-          inUse16[i] = False;
-          for (j = 0; j < 16; j++)
-             if (s->inUse[i * 16 + j]) inUse16[i] = True;
-      }
-     
-      nBytes = s->numZ;
-      for (i = 0; i < 16; i++)
-         if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0);
-
-      for (i = 0; i < 16; i++)
-         if (inUse16[i])
-            for (j = 0; j < 16; j++) {
-               if (s->inUse[i * 16 + j]) bsW(s,1,1); else bsW(s,1,0);
-            }
-
-      if (s->verbosity >= 3) 
-         VPrintf1( "      bytes: mapping %d, ", s->numZ-nBytes );
-   }
-
-   /*--- Now the selectors. ---*/
-   nBytes = s->numZ;
-   bsW ( s, 3, nGroups );
-   bsW ( s, 15, nSelectors );
-   for (i = 0; i < nSelectors; i++) { 
-      for (j = 0; j < s->selectorMtf[i]; j++) bsW(s,1,1);
-      bsW(s,1,0);
-   }
-   if (s->verbosity >= 3)
-      VPrintf1( "selectors %d, ", s->numZ-nBytes );
-
-   /*--- Now the coding tables. ---*/
-   nBytes = s->numZ;
-
-   for (t = 0; t < nGroups; t++) {
-      Int32 curr = s->len[t][0];
-      bsW ( s, 5, curr );
-      for (i = 0; i < alphaSize; i++) {
-         while (curr < s->len[t][i]) { bsW(s,2,2); curr++; /* 10 */ };
-         while (curr > s->len[t][i]) { bsW(s,2,3); curr--; /* 11 */ };
-         bsW ( s, 1, 0 );
-      }
-   }
-
-   if (s->verbosity >= 3)
-      VPrintf1 ( "code lengths %d, ", s->numZ-nBytes );
-
-   /*--- And finally, the block data proper ---*/
-   nBytes = s->numZ;
-   selCtr = 0;
-   gs = 0;
-   while (True) {
-      if (gs >= s->nMTF) break;
-      ge = gs + BZ_G_SIZE - 1; 
-      if (ge >= s->nMTF) ge = s->nMTF-1;
-      AssertH ( s->selector[selCtr] < nGroups, 3006 );
-
-      if (nGroups == 6 && 50 == ge-gs+1) {
-            /*--- fast track the common case ---*/
-            UInt16 mtfv_i;
-            UChar* s_len_sel_selCtr 
-               = &(s->len[s->selector[selCtr]][0]);
-            Int32* s_code_sel_selCtr
-               = &(s->code[s->selector[selCtr]][0]);
-
-#           define BZ_ITAH(nn)                      \
-               mtfv_i = mtfv[gs+(nn)];              \
-               bsW ( s,                             \
-                     s_len_sel_selCtr[mtfv_i],      \
-                     s_code_sel_selCtr[mtfv_i] )
-
-            BZ_ITAH(0);  BZ_ITAH(1);  BZ_ITAH(2);  BZ_ITAH(3);  BZ_ITAH(4);
-            BZ_ITAH(5);  BZ_ITAH(6);  BZ_ITAH(7);  BZ_ITAH(8);  BZ_ITAH(9);
-            BZ_ITAH(10); BZ_ITAH(11); BZ_ITAH(12); BZ_ITAH(13); BZ_ITAH(14);
-            BZ_ITAH(15); BZ_ITAH(16); BZ_ITAH(17); BZ_ITAH(18); BZ_ITAH(19);
-            BZ_ITAH(20); BZ_ITAH(21); BZ_ITAH(22); BZ_ITAH(23); BZ_ITAH(24);
-            BZ_ITAH(25); BZ_ITAH(26); BZ_ITAH(27); BZ_ITAH(28); BZ_ITAH(29);
-            BZ_ITAH(30); BZ_ITAH(31); BZ_ITAH(32); BZ_ITAH(33); BZ_ITAH(34);
-            BZ_ITAH(35); BZ_ITAH(36); BZ_ITAH(37); BZ_ITAH(38); BZ_ITAH(39);
-            BZ_ITAH(40); BZ_ITAH(41); BZ_ITAH(42); BZ_ITAH(43); BZ_ITAH(44);
-            BZ_ITAH(45); BZ_ITAH(46); BZ_ITAH(47); BZ_ITAH(48); BZ_ITAH(49);
-
-#           undef BZ_ITAH
-
-      } else {
-	 /*--- slow version which correctly handles all situations ---*/
-         for (i = gs; i <= ge; i++) {
-            bsW ( s, 
-                  s->len  [s->selector[selCtr]] [mtfv[i]],
-                  s->code [s->selector[selCtr]] [mtfv[i]] );
-         }
-      }
-
-
-      gs = ge+1;
-      selCtr++;
-   }
-   AssertH( selCtr == nSelectors, 3007 );
-
-   if (s->verbosity >= 3)
-      VPrintf1( "codes %d\n", s->numZ-nBytes );
-}
-
-
-/*---------------------------------------------------*/
-void BZ2_compressBlock ( EState* s, Bool is_last_block )
-{
-   if (s->nblock > 0) {
-
-      BZ_FINALISE_CRC ( s->blockCRC );
-      s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
-      s->combinedCRC ^= s->blockCRC;
-      if (s->blockNo > 1) s->numZ = 0;
-
-      if (s->verbosity >= 2)
-         VPrintf4( "    block %d: crc = 0x%08x, "
-                   "combined CRC = 0x%08x, size = %d\n",
-                   s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
-
-      BZ2_blockSort ( s );
-   }
-
-   s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]);
-
-   /*-- If this is the first block, create the stream header. --*/
-   if (s->blockNo == 1) {
-      BZ2_bsInitWrite ( s );
-      bsPutUChar ( s, BZ_HDR_B );
-      bsPutUChar ( s, BZ_HDR_Z );
-      bsPutUChar ( s, BZ_HDR_h );
-      bsPutUChar ( s, (UChar)(BZ_HDR_0 + s->blockSize100k) );
-   }
-
-   if (s->nblock > 0) {
-
-      bsPutUChar ( s, 0x31 ); bsPutUChar ( s, 0x41 );
-      bsPutUChar ( s, 0x59 ); bsPutUChar ( s, 0x26 );
-      bsPutUChar ( s, 0x53 ); bsPutUChar ( s, 0x59 );
-
-      /*-- Now the block's CRC, so it is in a known place. --*/
-      bsPutUInt32 ( s, s->blockCRC );
-
-      /*-- 
-         Now a single bit indicating (non-)randomisation. 
-         As of version 0.9.5, we use a better sorting algorithm
-         which makes randomisation unnecessary.  So always set
-         the randomised bit to 'no'.  Of course, the decoder
-         still needs to be able to handle randomised blocks
-         so as to maintain backwards compatibility with
-         older versions of bzip2.
-      --*/
-      bsW(s,1,0);
-
-      bsW ( s, 24, s->origPtr );
-      generateMTFValues ( s );
-      sendMTFValues ( s );
-   }
-
-
-   /*-- If this is the last block, add the stream trailer. --*/
-   if (is_last_block) {
-
-      bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 );
-      bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 );
-      bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
-      bsPutUInt32 ( s, s->combinedCRC );
-      if (s->verbosity >= 2)
-         VPrintf1( "    final combined CRC = 0x%08x\n   ", s->combinedCRC );
-      bsFinishWrite ( s );
-   }
-}
-
-
-/*-------------------------------------------------------------*/
-/*--- end                                        compress.c ---*/
-/*-------------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/crctable.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/crctable.c	(revision 9)
+++ 	(revision )
@@ -1,144 +1,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Table for doing CRCs                                  ---*/
-/*---                                            crctable.c ---*/
-/*-------------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-
-#include "bzlib_private.h"
-
-/*--
-  I think this is an implementation of the AUTODIN-II,
-  Ethernet & FDDI 32-bit CRC standard.  Vaguely derived
-  from code by Rob Warnock, in Section 51 of the
-  comp.compression FAQ.
---*/
-
-UInt32 BZ2_crc32Table[256] = {
-
-   /*-- Ugly, innit? --*/
-
-   0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
-   0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
-   0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
-   0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
-   0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
-   0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
-   0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
-   0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
-   0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
-   0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
-   0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
-   0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
-   0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
-   0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
-   0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
-   0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
-   0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
-   0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
-   0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
-   0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
-   0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
-   0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
-   0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
-   0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
-   0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
-   0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
-   0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
-   0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
-   0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
-   0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
-   0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
-   0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
-   0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
-   0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
-   0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
-   0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
-   0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
-   0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
-   0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
-   0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
-   0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
-   0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
-   0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
-   0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
-   0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
-   0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
-   0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
-   0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
-   0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
-   0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
-   0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
-   0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
-   0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
-   0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
-   0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
-   0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
-   0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
-   0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
-   0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
-   0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
-   0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
-   0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
-   0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
-   0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
-};
-
-
-/*-------------------------------------------------------------*/
-/*--- end                                        crctable.c ---*/
-/*-------------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/decompress.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/decompress.c	(revision 9)
+++ 	(revision )
@@ -1,666 +1,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Decompression machinery                               ---*/
-/*---                                          decompress.c ---*/
-/*-------------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-
-#include "bzlib_private.h"
-
-
-/*---------------------------------------------------*/
-static
-void makeMaps_d ( DState* s )
-{
-   Int32 i;
-   s->nInUse = 0;
-   for (i = 0; i < 256; i++)
-      if (s->inUse[i]) {
-         s->seqToUnseq[s->nInUse] = i;
-         s->nInUse++;
-      }
-}
-
-
-/*---------------------------------------------------*/
-#define RETURN(rrr)                               \
-   { retVal = rrr; goto save_state_and_return; };
-
-#define GET_BITS(lll,vvv,nnn)                     \
-   case lll: s->state = lll;                      \
-   while (True) {                                 \
-      if (s->bsLive >= nnn) {                     \
-         UInt32 v;                                \
-         v = (s->bsBuff >>                        \
-             (s->bsLive-nnn)) & ((1 << nnn)-1);   \
-         s->bsLive -= nnn;                        \
-         vvv = v;                                 \
-         break;                                   \
-      }                                           \
-      if (s->strm->avail_in == 0) RETURN(BZ_OK);  \
-      s->bsBuff                                   \
-         = (s->bsBuff << 8) |                     \
-           ((UInt32)                              \
-              (*((UChar*)(s->strm->next_in))));   \
-      s->bsLive += 8;                             \
-      s->strm->next_in++;                         \
-      s->strm->avail_in--;                        \
-      s->strm->total_in_lo32++;                   \
-      if (s->strm->total_in_lo32 == 0)            \
-         s->strm->total_in_hi32++;                \
-   }
-
-#define GET_UCHAR(lll,uuu)                        \
-   GET_BITS(lll,uuu,8)
-
-#define GET_BIT(lll,uuu)                          \
-   GET_BITS(lll,uuu,1)
-
-/*---------------------------------------------------*/
-#define GET_MTF_VAL(label1,label2,lval)           \
-{                                                 \
-   if (groupPos == 0) {                           \
-      groupNo++;                                  \
-      if (groupNo >= nSelectors)                  \
-         RETURN(BZ_DATA_ERROR);                   \
-      groupPos = BZ_G_SIZE;                       \
-      gSel = s->selector[groupNo];                \
-      gMinlen = s->minLens[gSel];                 \
-      gLimit = &(s->limit[gSel][0]);              \
-      gPerm = &(s->perm[gSel][0]);                \
-      gBase = &(s->base[gSel][0]);                \
-   }                                              \
-   groupPos--;                                    \
-   zn = gMinlen;                                  \
-   GET_BITS(label1, zvec, zn);                    \
-   while (1) {                                    \
-      if (zn > 20 /* the longest code */)         \
-         RETURN(BZ_DATA_ERROR);                   \
-      if (zvec <= gLimit[zn]) break;              \
-      zn++;                                       \
-      GET_BIT(label2, zj);                        \
-      zvec = (zvec << 1) | zj;                    \
-   };                                             \
-   if (zvec - gBase[zn] < 0                       \
-       || zvec - gBase[zn] >= BZ_MAX_ALPHA_SIZE)  \
-      RETURN(BZ_DATA_ERROR);                      \
-   lval = gPerm[zvec - gBase[zn]];                \
-}
-
-
-/*---------------------------------------------------*/
-Int32 BZ2_decompress ( DState* s )
-{
-   UChar      uc;
-   Int32      retVal;
-   Int32      minLen, maxLen;
-   bz_stream* strm = s->strm;
-
-   /* stuff that needs to be saved/restored */
-   Int32  i;
-   Int32  j;
-   Int32  t;
-   Int32  alphaSize;
-   Int32  nGroups;
-   Int32  nSelectors;
-   Int32  EOB;
-   Int32  groupNo;
-   Int32  groupPos;
-   Int32  nextSym;
-   Int32  nblockMAX;
-   Int32  nblock;
-   Int32  es;
-   Int32  N;
-   Int32  curr;
-   Int32  zt;
-   Int32  zn; 
-   Int32  zvec;
-   Int32  zj;
-   Int32  gSel;
-   Int32  gMinlen;
-   Int32* gLimit;
-   Int32* gBase;
-   Int32* gPerm;
-
-   if (s->state == BZ_X_MAGIC_1) {
-      /*initialise the save area*/
-      s->save_i           = 0;
-      s->save_j           = 0;
-      s->save_t           = 0;
-      s->save_alphaSize   = 0;
-      s->save_nGroups     = 0;
-      s->save_nSelectors  = 0;
-      s->save_EOB         = 0;
-      s->save_groupNo     = 0;
-      s->save_groupPos    = 0;
-      s->save_nextSym     = 0;
-      s->save_nblockMAX   = 0;
-      s->save_nblock      = 0;
-      s->save_es          = 0;
-      s->save_N           = 0;
-      s->save_curr        = 0;
-      s->save_zt          = 0;
-      s->save_zn          = 0;
-      s->save_zvec        = 0;
-      s->save_zj          = 0;
-      s->save_gSel        = 0;
-      s->save_gMinlen     = 0;
-      s->save_gLimit      = NULL;
-      s->save_gBase       = NULL;
-      s->save_gPerm       = NULL;
-   }
-
-   /*restore from the save area*/
-   i           = s->save_i;
-   j           = s->save_j;
-   t           = s->save_t;
-   alphaSize   = s->save_alphaSize;
-   nGroups     = s->save_nGroups;
-   nSelectors  = s->save_nSelectors;
-   EOB         = s->save_EOB;
-   groupNo     = s->save_groupNo;
-   groupPos    = s->save_groupPos;
-   nextSym     = s->save_nextSym;
-   nblockMAX   = s->save_nblockMAX;
-   nblock      = s->save_nblock;
-   es          = s->save_es;
-   N           = s->save_N;
-   curr        = s->save_curr;
-   zt          = s->save_zt;
-   zn          = s->save_zn; 
-   zvec        = s->save_zvec;
-   zj          = s->save_zj;
-   gSel        = s->save_gSel;
-   gMinlen     = s->save_gMinlen;
-   gLimit      = s->save_gLimit;
-   gBase       = s->save_gBase;
-   gPerm       = s->save_gPerm;
-
-   retVal = BZ_OK;
-
-   switch (s->state) {
-
-      GET_UCHAR(BZ_X_MAGIC_1, uc);
-      if (uc != BZ_HDR_B) RETURN(BZ_DATA_ERROR_MAGIC);
-
-      GET_UCHAR(BZ_X_MAGIC_2, uc);
-      if (uc != BZ_HDR_Z) RETURN(BZ_DATA_ERROR_MAGIC);
-
-      GET_UCHAR(BZ_X_MAGIC_3, uc)
-      if (uc != BZ_HDR_h) RETURN(BZ_DATA_ERROR_MAGIC);
-
-      GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
-      if (s->blockSize100k < (BZ_HDR_0 + 1) || 
-          s->blockSize100k > (BZ_HDR_0 + 9)) RETURN(BZ_DATA_ERROR_MAGIC);
-      s->blockSize100k -= BZ_HDR_0;
-
-      if (s->smallDecompress) {
-         s->ll16 = BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
-         s->ll4  = BZALLOC( 
-                      ((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar) 
-                   );
-         if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR);
-      } else {
-         s->tt  = BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) );
-         if (s->tt == NULL) RETURN(BZ_MEM_ERROR);
-      }
-
-      GET_UCHAR(BZ_X_BLKHDR_1, uc);
-
-      if (uc == 0x17) goto endhdr_2;
-      if (uc != 0x31) RETURN(BZ_DATA_ERROR);
-      GET_UCHAR(BZ_X_BLKHDR_2, uc);
-      if (uc != 0x41) RETURN(BZ_DATA_ERROR);
-      GET_UCHAR(BZ_X_BLKHDR_3, uc);
-      if (uc != 0x59) RETURN(BZ_DATA_ERROR);
-      GET_UCHAR(BZ_X_BLKHDR_4, uc);
-      if (uc != 0x26) RETURN(BZ_DATA_ERROR);
-      GET_UCHAR(BZ_X_BLKHDR_5, uc);
-      if (uc != 0x53) RETURN(BZ_DATA_ERROR);
-      GET_UCHAR(BZ_X_BLKHDR_6, uc);
-      if (uc != 0x59) RETURN(BZ_DATA_ERROR);
-
-      s->currBlockNo++;
-      if (s->verbosity >= 2)
-         VPrintf1 ( "\n    [%d: huff+mtf ", s->currBlockNo );
- 
-      s->storedBlockCRC = 0;
-      GET_UCHAR(BZ_X_BCRC_1, uc);
-      s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
-      GET_UCHAR(BZ_X_BCRC_2, uc);
-      s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
-      GET_UCHAR(BZ_X_BCRC_3, uc);
-      s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
-      GET_UCHAR(BZ_X_BCRC_4, uc);
-      s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
-
-      GET_BITS(BZ_X_RANDBIT, s->blockRandomised, 1);
-
-      s->origPtr = 0;
-      GET_UCHAR(BZ_X_ORIGPTR_1, uc);
-      s->origPtr = (s->origPtr << 8) | ((Int32)uc);
-      GET_UCHAR(BZ_X_ORIGPTR_2, uc);
-      s->origPtr = (s->origPtr << 8) | ((Int32)uc);
-      GET_UCHAR(BZ_X_ORIGPTR_3, uc);
-      s->origPtr = (s->origPtr << 8) | ((Int32)uc);
-
-      if (s->origPtr < 0)
-         RETURN(BZ_DATA_ERROR);
-      if (s->origPtr > 10 + 100000*s->blockSize100k) 
-         RETURN(BZ_DATA_ERROR);
-
-      /*--- Receive the mapping table ---*/
-      for (i = 0; i < 16; i++) {
-         GET_BIT(BZ_X_MAPPING_1, uc);
-         if (uc == 1) 
-            s->inUse16[i] = True; else 
-            s->inUse16[i] = False;
-      }
-
-      for (i = 0; i < 256; i++) s->inUse[i] = False;
-
-      for (i = 0; i < 16; i++)
-         if (s->inUse16[i])
-            for (j = 0; j < 16; j++) {
-               GET_BIT(BZ_X_MAPPING_2, uc);
-               if (uc == 1) s->inUse[i * 16 + j] = True;
-            }
-      makeMaps_d ( s );
-      if (s->nInUse == 0) RETURN(BZ_DATA_ERROR);
-      alphaSize = s->nInUse+2;
-
-      /*--- Now the selectors ---*/
-      GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
-      if (nGroups < 2 || nGroups > 6) RETURN(BZ_DATA_ERROR);
-      GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
-      if (nSelectors < 1) RETURN(BZ_DATA_ERROR);
-      for (i = 0; i < nSelectors; i++) {
-         j = 0;
-         while (True) {
-            GET_BIT(BZ_X_SELECTOR_3, uc);
-            if (uc == 0) break;
-            j++;
-            if (j >= nGroups) RETURN(BZ_DATA_ERROR);
-         }
-         s->selectorMtf[i] = j;
-      }
-
-      /*--- Undo the MTF values for the selectors. ---*/
-      {
-         UChar pos[BZ_N_GROUPS], tmp, v;
-         for (v = 0; v < nGroups; v++) pos[v] = v;
-   
-         for (i = 0; i < nSelectors; i++) {
-            v = s->selectorMtf[i];
-            tmp = pos[v];
-            while (v > 0) { pos[v] = pos[v-1]; v--; }
-            pos[0] = tmp;
-            s->selector[i] = tmp;
-         }
-      }
-
-      /*--- Now the coding tables ---*/
-      for (t = 0; t < nGroups; t++) {
-         GET_BITS(BZ_X_CODING_1, curr, 5);
-         for (i = 0; i < alphaSize; i++) {
-            while (True) {
-               if (curr < 1 || curr > 20) RETURN(BZ_DATA_ERROR);
-               GET_BIT(BZ_X_CODING_2, uc);
-               if (uc == 0) break;
-               GET_BIT(BZ_X_CODING_3, uc);
-               if (uc == 0) curr++; else curr--;
-            }
-            s->len[t][i] = curr;
-         }
-      }
-
-      /*--- Create the Huffman decoding tables ---*/
-      for (t = 0; t < nGroups; t++) {
-         minLen = 32;
-         maxLen = 0;
-         for (i = 0; i < alphaSize; i++) {
-            if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
-            if (s->len[t][i] < minLen) minLen = s->len[t][i];
-         }
-         BZ2_hbCreateDecodeTables ( 
-            &(s->limit[t][0]), 
-            &(s->base[t][0]), 
-            &(s->perm[t][0]), 
-            &(s->len[t][0]),
-            minLen, maxLen, alphaSize
-         );
-         s->minLens[t] = minLen;
-      }
-
-      /*--- Now the MTF values ---*/
-
-      EOB      = s->nInUse+1;
-      nblockMAX = 100000 * s->blockSize100k;
-      groupNo  = -1;
-      groupPos = 0;
-
-      for (i = 0; i <= 255; i++) s->unzftab[i] = 0;
-
-      /*-- MTF init --*/
-      {
-         Int32 ii, jj, kk;
-         kk = MTFA_SIZE-1;
-         for (ii = 256 / MTFL_SIZE - 1; ii >= 0; ii--) {
-            for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
-               s->mtfa[kk] = (UChar)(ii * MTFL_SIZE + jj);
-               kk--;
-            }
-            s->mtfbase[ii] = kk + 1;
-         }
-      }
-      /*-- end MTF init --*/
-
-      nblock = 0;
-      GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
-
-      while (True) {
-
-         if (nextSym == EOB) break;
-
-         if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
-
-            es = -1;
-            N = 1;
-            do {
-               if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
-               if (nextSym == BZ_RUNB) es = es + (1+1) * N;
-               N = N * 2;
-               GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
-            }
-               while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
-
-            es++;
-            uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ];
-            s->unzftab[uc] += es;
-
-            if (s->smallDecompress)
-               while (es > 0) {
-                  if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
-                  s->ll16[nblock] = (UInt16)uc;
-                  nblock++;
-                  es--;
-               }
-            else
-               while (es > 0) {
-                  if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
-                  s->tt[nblock] = (UInt32)uc;
-                  nblock++;
-                  es--;
-               };
-
-            continue;
-
-         } else {
-
-            if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
-
-            /*-- uc = MTF ( nextSym-1 ) --*/
-            {
-               Int32 ii, jj, kk, pp, lno, off;
-               UInt32 nn;
-               nn = (UInt32)(nextSym - 1);
-
-               if (nn < MTFL_SIZE) {
-                  /* avoid general-case expense */
-                  pp = s->mtfbase[0];
-                  uc = s->mtfa[pp+nn];
-                  while (nn > 3) {
-                     Int32 z = pp+nn;
-                     s->mtfa[(z)  ] = s->mtfa[(z)-1];
-                     s->mtfa[(z)-1] = s->mtfa[(z)-2];
-                     s->mtfa[(z)-2] = s->mtfa[(z)-3];
-                     s->mtfa[(z)-3] = s->mtfa[(z)-4];
-                     nn -= 4;
-                  }
-                  while (nn > 0) { 
-                     s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--; 
-                  };
-                  s->mtfa[pp] = uc;
-               } else { 
-                  /* general case */
-                  lno = nn / MTFL_SIZE;
-                  off = nn % MTFL_SIZE;
-                  pp = s->mtfbase[lno] + off;
-                  uc = s->mtfa[pp];
-                  while (pp > s->mtfbase[lno]) { 
-                     s->mtfa[pp] = s->mtfa[pp-1]; pp--; 
-                  };
-                  s->mtfbase[lno]++;
-                  while (lno > 0) {
-                     s->mtfbase[lno]--;
-                     s->mtfa[s->mtfbase[lno]] 
-                        = s->mtfa[s->mtfbase[lno-1] + MTFL_SIZE - 1];
-                     lno--;
-                  }
-                  s->mtfbase[0]--;
-                  s->mtfa[s->mtfbase[0]] = uc;
-                  if (s->mtfbase[0] == 0) {
-                     kk = MTFA_SIZE-1;
-                     for (ii = 256 / MTFL_SIZE-1; ii >= 0; ii--) {
-                        for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
-                           s->mtfa[kk] = s->mtfa[s->mtfbase[ii] + jj];
-                           kk--;
-                        }
-                        s->mtfbase[ii] = kk + 1;
-                     }
-                  }
-               }
-            }
-            /*-- end uc = MTF ( nextSym-1 ) --*/
-
-            s->unzftab[s->seqToUnseq[uc]]++;
-            if (s->smallDecompress)
-               s->ll16[nblock] = (UInt16)(s->seqToUnseq[uc]); else
-               s->tt[nblock]   = (UInt32)(s->seqToUnseq[uc]);
-            nblock++;
-
-            GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
-            continue;
-         }
-      }
-
-      /* Now we know what nblock is, we can do a better sanity
-         check on s->origPtr.
-      */
-      if (s->origPtr < 0 || s->origPtr >= nblock)
-         RETURN(BZ_DATA_ERROR);
-
-      /*-- Set up cftab to facilitate generation of T^(-1) --*/
-      s->cftab[0] = 0;
-      for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
-      for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
-      for (i = 0; i <= 256; i++) {
-         if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
-            /* s->cftab[i] can legitimately be == nblock */
-            RETURN(BZ_DATA_ERROR);
-         }
-      }
-
-      s->state_out_len = 0;
-      s->state_out_ch  = 0;
-      BZ_INITIALISE_CRC ( s->calculatedBlockCRC );
-      s->state = BZ_X_OUTPUT;
-      if (s->verbosity >= 2) VPrintf0 ( "rt+rld" );
-
-      if (s->smallDecompress) {
-
-         /*-- Make a copy of cftab, used in generation of T --*/
-         for (i = 0; i <= 256; i++) s->cftabCopy[i] = s->cftab[i];
-
-         /*-- compute the T vector --*/
-         for (i = 0; i < nblock; i++) {
-            uc = (UChar)(s->ll16[i]);
-            SET_LL(i, s->cftabCopy[uc]);
-            s->cftabCopy[uc]++;
-         }
-
-         /*-- Compute T^(-1) by pointer reversal on T --*/
-         i = s->origPtr;
-         j = GET_LL(i);
-         do {
-            Int32 tmp = GET_LL(j);
-            SET_LL(j, i);
-            i = j;
-            j = tmp;
-         }
-            while (i != s->origPtr);
-
-         s->tPos = s->origPtr;
-         s->nblock_used = 0;
-         if (s->blockRandomised) {
-            BZ_RAND_INIT_MASK;
-            BZ_GET_SMALL(s->k0); s->nblock_used++;
-            BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK; 
-         } else {
-            BZ_GET_SMALL(s->k0); s->nblock_used++;
-         }
-
-      } else {
-
-         /*-- compute the T^(-1) vector --*/
-         for (i = 0; i < nblock; i++) {
-            uc = (UChar)(s->tt[i] & 0xff);
-            s->tt[s->cftab[uc]] |= (i << 8);
-            s->cftab[uc]++;
-         }
-
-         s->tPos = s->tt[s->origPtr] >> 8;
-         s->nblock_used = 0;
-         if (s->blockRandomised) {
-            BZ_RAND_INIT_MASK;
-            BZ_GET_FAST(s->k0); s->nblock_used++;
-            BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK; 
-         } else {
-            BZ_GET_FAST(s->k0); s->nblock_used++;
-         }
-
-      }
-
-      RETURN(BZ_OK);
-
-
-
-    endhdr_2:
-
-      GET_UCHAR(BZ_X_ENDHDR_2, uc);
-      if (uc != 0x72) RETURN(BZ_DATA_ERROR);
-      GET_UCHAR(BZ_X_ENDHDR_3, uc);
-      if (uc != 0x45) RETURN(BZ_DATA_ERROR);
-      GET_UCHAR(BZ_X_ENDHDR_4, uc);
-      if (uc != 0x38) RETURN(BZ_DATA_ERROR);
-      GET_UCHAR(BZ_X_ENDHDR_5, uc);
-      if (uc != 0x50) RETURN(BZ_DATA_ERROR);
-      GET_UCHAR(BZ_X_ENDHDR_6, uc);
-      if (uc != 0x90) RETURN(BZ_DATA_ERROR);
-
-      s->storedCombinedCRC = 0;
-      GET_UCHAR(BZ_X_CCRC_1, uc);
-      s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
-      GET_UCHAR(BZ_X_CCRC_2, uc);
-      s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
-      GET_UCHAR(BZ_X_CCRC_3, uc);
-      s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
-      GET_UCHAR(BZ_X_CCRC_4, uc);
-      s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
-
-      s->state = BZ_X_IDLE;
-      RETURN(BZ_STREAM_END);
-
-      default: AssertH ( False, 4001 );
-   }
-
-   AssertH ( False, 4002 );
-
-   save_state_and_return:
-
-   s->save_i           = i;
-   s->save_j           = j;
-   s->save_t           = t;
-   s->save_alphaSize   = alphaSize;
-   s->save_nGroups     = nGroups;
-   s->save_nSelectors  = nSelectors;
-   s->save_EOB         = EOB;
-   s->save_groupNo     = groupNo;
-   s->save_groupPos    = groupPos;
-   s->save_nextSym     = nextSym;
-   s->save_nblockMAX   = nblockMAX;
-   s->save_nblock      = nblock;
-   s->save_es          = es;
-   s->save_N           = N;
-   s->save_curr        = curr;
-   s->save_zt          = zt;
-   s->save_zn          = zn;
-   s->save_zvec        = zvec;
-   s->save_zj          = zj;
-   s->save_gSel        = gSel;
-   s->save_gMinlen     = gMinlen;
-   s->save_gLimit      = gLimit;
-   s->save_gBase       = gBase;
-   s->save_gPerm       = gPerm;
-
-   return retVal;   
-}
-
-
-/*-------------------------------------------------------------*/
-/*--- end                                      decompress.c ---*/
-/*-------------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/dlltest.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/dlltest.c	(revision 9)
+++ 	(revision )
@@ -1,176 +1,0 @@
-/*
-   minibz2
-      libbz2.dll test program.
-      by Yoshioka Tsuneo(QWF00133@nifty.ne.jp/tsuneo-y@is.aist-nara.ac.jp)
-      This file is Public Domain.
-      welcome any email to me.
-
-   usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]
-*/
-
-#define BZ_IMPORT
-#include <stdio.h>
-#include <stdlib.h>
-#include "bzlib.h"
-#ifdef _WIN32
-#include <io.h>
-#endif
-
-
-#ifdef _WIN32
-
-#define BZ2_LIBNAME "libbz2-1.0.2.DLL" 
-
-#include <windows.h>
-static int BZ2DLLLoaded = 0;
-static HINSTANCE BZ2DLLhLib;
-int BZ2DLLLoadLibrary(void)
-{
-   HINSTANCE hLib;
-
-   if(BZ2DLLLoaded==1){return 0;}
-   hLib=LoadLibrary(BZ2_LIBNAME);
-   if(hLib == NULL){
-      fprintf(stderr,"Can't load %s\n",BZ2_LIBNAME);
-      return -1;
-   }
-   BZ2_bzlibVersion=GetProcAddress(hLib,"BZ2_bzlibVersion");
-   BZ2_bzopen=GetProcAddress(hLib,"BZ2_bzopen");
-   BZ2_bzdopen=GetProcAddress(hLib,"BZ2_bzdopen");
-   BZ2_bzread=GetProcAddress(hLib,"BZ2_bzread");
-   BZ2_bzwrite=GetProcAddress(hLib,"BZ2_bzwrite");
-   BZ2_bzflush=GetProcAddress(hLib,"BZ2_bzflush");
-   BZ2_bzclose=GetProcAddress(hLib,"BZ2_bzclose");
-   BZ2_bzerror=GetProcAddress(hLib,"BZ2_bzerror");
-
-   if (!BZ2_bzlibVersion || !BZ2_bzopen || !BZ2_bzdopen
-       || !BZ2_bzread || !BZ2_bzwrite || !BZ2_bzflush
-       || !BZ2_bzclose || !BZ2_bzerror) {
-      fprintf(stderr,"GetProcAddress failed.\n");
-      return -1;
-   }
-   BZ2DLLLoaded=1;
-   BZ2DLLhLib=hLib;
-   return 0;
-
-}
-int BZ2DLLFreeLibrary(void)
-{
-   if(BZ2DLLLoaded==0){return 0;}
-   FreeLibrary(BZ2DLLhLib);
-   BZ2DLLLoaded=0;
-}
-#endif /* WIN32 */
-
-void usage(void)
-{
-   puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]");
-}
-
-int main(int argc,char *argv[])
-{
-   int decompress = 0;
-   int level = 9;
-   char *fn_r = NULL;
-   char *fn_w = NULL;
-
-#ifdef _WIN32
-   if(BZ2DLLLoadLibrary()<0){
-      fprintf(stderr,"Loading of %s failed.  Giving up.\n", BZ2_LIBNAME);
-      exit(1);
-   }
-   printf("Loading of %s succeeded.  Library version is %s.\n",
-          BZ2_LIBNAME, BZ2_bzlibVersion() );
-#endif
-   while(++argv,--argc){
-      if(**argv =='-' || **argv=='/'){
-         char *p;
-
-         for(p=*argv+1;*p;p++){
-            if(*p=='d'){
-               decompress = 1;
-            }else if('1'<=*p && *p<='9'){
-               level = *p - '0';
-            }else{
-               usage();
-               exit(1);
-            }
-         }
-      }else{
-         break;
-      }
-   }
-   if(argc>=1){
-      fn_r = *argv;
-      argc--;argv++;
-   }else{
-      fn_r = NULL;
-   }
-   if(argc>=1){
-      fn_w = *argv;
-      argc--;argv++;
-   }else{
-      fn_w = NULL;
-   }
-   {
-      int len;
-      char buff[0x1000];
-      char mode[10];
-
-      if(decompress){
-         BZFILE *BZ2fp_r = NULL;
-         FILE *fp_w = NULL;
-
-         if(fn_w){
-            if((fp_w = fopen(fn_w,"wb"))==NULL){
-               printf("can't open [%s]\n",fn_w);
-               perror("reason:");
-               exit(1);
-            }
-         }else{
-            fp_w = stdout;
-         }
-         if((fn_r == NULL && (BZ2fp_r = BZ2_bzdopen(fileno(stdin),"rb"))==NULL)
-            || (fn_r != NULL && (BZ2fp_r = BZ2_bzopen(fn_r,"rb"))==NULL)){
-            printf("can't bz2openstream\n");
-            exit(1);
-         }
-         while((len=BZ2_bzread(BZ2fp_r,buff,0x1000))>0){
-            fwrite(buff,1,len,fp_w);
-         }
-         BZ2_bzclose(BZ2fp_r);
-         if(fp_w != stdout) fclose(fp_w);
-      }else{
-         BZFILE *BZ2fp_w = NULL;
-         FILE *fp_r = NULL;
-
-         if(fn_r){
-            if((fp_r = fopen(fn_r,"rb"))==NULL){
-               printf("can't open [%s]\n",fn_r);
-               perror("reason:");
-               exit(1);
-            }
-         }else{
-            fp_r = stdin;
-         }
-         mode[0]='w';
-         mode[1] = '0' + level;
-         mode[2] = '\0';
-
-         if((fn_w == NULL && (BZ2fp_w = BZ2_bzdopen(fileno(stdout),mode))==NULL)
-            || (fn_w !=NULL && (BZ2fp_w = BZ2_bzopen(fn_w,mode))==NULL)){
-            printf("can't bz2openstream\n");
-            exit(1);
-         }
-         while((len=fread(buff,1,0x1000,fp_r))>0){
-            BZ2_bzwrite(BZ2fp_w,buff,len);
-         }
-         BZ2_bzclose(BZ2fp_w);
-         if(fp_r!=stdin)fclose(fp_r);
-      }
-   }
-#ifdef _WIN32
-   BZ2DLLFreeLibrary();
-#endif
-   return 0;
-}
Index: trunk/minix/commands/bzip2-1.0.3/dlltest.dsp
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/dlltest.dsp	(revision 9)
+++ 	(revision )
@@ -1,93 +1,0 @@
-# Microsoft Developer Studio Project File - Name="dlltest" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 5.00
-# ** ÒWµÈ¢Å­Ÿ³¢ **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=dlltest - Win32 Debug
-!MESSAGE ±êÍLøÈÒ²žÌ§²ÙÅÍ èÜ¹ñB ±ÌÌßÛŒÞªžÄðËÞÙÄÞ·éœßÉÍ NMAKE ðgpµÄ­Ÿ³¢B
-!MESSAGE [Ò²žÌ§²ÙÌŽžœÎß°Ä] ºÏÝÄÞðgpµÄÀsµÄ­Ÿ³¢
-!MESSAGE 
-!MESSAGE NMAKE /f "dlltest.mak".
-!MESSAGE 
-!MESSAGE NMAKE ÌÀsÉ\¬ðwèÅ«Ü·
-!MESSAGE ºÏÝÄÞ ×²ÝãÅÏžÛÌÝèðè`µÜ·Bá:
-!MESSAGE 
-!MESSAGE NMAKE /f "dlltest.mak" CFG="dlltest - Win32 Debug"
-!MESSAGE 
-!MESSAGE IðÂ\ÈËÞÙÄÞ Ó°ÄÞ:
-!MESSAGE 
-!MESSAGE "dlltest - Win32 Release" ("Win32 (x86) Console Application" p)
-!MESSAGE "dlltest - Win32 Debug" ("Win32 (x86) Console Application" p)
-!MESSAGE 
-
-# Begin Project
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "dlltest - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x411 /d "NDEBUG"
-# ADD RSC /l 0x411 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"minibz2.exe"
-
-!ELSEIF  "$(CFG)" == "dlltest - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "dlltest_"
-# PROP BASE Intermediate_Dir "dlltest_"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "dlltest_"
-# PROP Intermediate_Dir "dlltest_"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x411 /d "_DEBUG"
-# ADD RSC /l 0x411 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"minibz2.exe" /pdbtype:sept
-
-!ENDIF 
-
-# Begin Target
-
-# Name "dlltest - Win32 Release"
-# Name "dlltest - Win32 Debug"
-# Begin Source File
-
-SOURCE=.\bzlib.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\dlltest.c
-# End Source File
-# End Target
-# End Project
Index: trunk/minix/commands/bzip2-1.0.3/entities.xml
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/entities.xml	(revision 9)
+++ 	(revision )
@@ -1,9 +1,0 @@
-<!-- misc. strings -->
-<!ENTITY bz-url "http://www.bzip.org">
-<!ENTITY bz-email "jseward@bzip.org">
-<!ENTITY bz-lifespan "1996-2005">
-
-<!ENTITY bz-version "1.0.3">
-<!ENTITY bz-date "15 February 2005">
-
-<!ENTITY manual-title "bzip2 Manual">
Index: trunk/minix/commands/bzip2-1.0.3/format.pl
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/format.pl	(revision 9)
+++ 	(revision )
@@ -1,53 +1,0 @@
-#!/usr/bin/perl -w
-use strict;
-
-# get command line values:
-if ( $#ARGV !=1 ) {
-    die "Usage:  $0 xml_infile xml_outfile\n";
-}
-
-my $infile = shift;
-# check infile exists
-die "Can't find file \"$infile\""
-  unless -f $infile;
-# check we can read infile
-if (! -r $infile) {
-    die "Can't read input $infile\n";
-}
-# check we can open infile
-open( INFILE,"<$infile" ) or 
-    die "Can't input $infile $!";
-
-#my $outfile = 'fmt-manual.xml';
-my $outfile = shift;
-#print "Infile: $infile, Outfile: $outfile\n";
-# check we can write to outfile
-open( OUTFILE,">$outfile" ) or 
-    die "Can't output $outfile $! for writing";
-
-my ($prev, $curr, $str);
-$prev = ''; $curr = '';
-while ( <INFILE> ) {
-
-		print OUTFILE $prev;
-    $prev = $curr;
-    $curr = $_;
-    $str = '';
-
-    if ( $prev =~ /<programlisting>$|<screen>$/ ) {
-        chomp $prev;
-        $curr = join( '', $prev, "<![CDATA[", $curr );
-				$prev = '';
-        next;
-    }
-    elsif ( $curr =~ /<\/programlisting>|<\/screen>/ ) {
-        chomp $prev;
-        $curr = join( '', $prev, "]]>", $curr );
-				$prev = '';
-        next;
-    }
-}
-print OUTFILE $curr;
-close INFILE;
-close OUTFILE;
-exit;
Index: trunk/minix/commands/bzip2-1.0.3/huffman.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/huffman.c	(revision 9)
+++ 	(revision )
@@ -1,245 +1,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Huffman coding low-level stuff                        ---*/
-/*---                                             huffman.c ---*/
-/*-------------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-
-#include "bzlib_private.h"
-
-/*---------------------------------------------------*/
-#define WEIGHTOF(zz0)  ((zz0) & 0xffffff00)
-#define DEPTHOF(zz1)   ((zz1) & 0x000000ff)
-#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
-
-#define ADDWEIGHTS(zw1,zw2)                           \
-   (WEIGHTOF(zw1)+WEIGHTOF(zw2)) |                    \
-   (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
-
-#define UPHEAP(z)                                     \
-{                                                     \
-   Int32 zz, tmp;                                     \
-   zz = z; tmp = heap[zz];                            \
-   while (weight[tmp] < weight[heap[zz >> 1]]) {      \
-      heap[zz] = heap[zz >> 1];                       \
-      zz >>= 1;                                       \
-   }                                                  \
-   heap[zz] = tmp;                                    \
-}
-
-#define DOWNHEAP(z)                                   \
-{                                                     \
-   Int32 zz, yy, tmp;                                 \
-   zz = z; tmp = heap[zz];                            \
-   while (True) {                                     \
-      yy = zz << 1;                                   \
-      if (yy > nHeap) break;                          \
-      if (yy < nHeap &&                               \
-          weight[heap[yy+1]] < weight[heap[yy]])      \
-         yy++;                                        \
-      if (weight[tmp] < weight[heap[yy]]) break;      \
-      heap[zz] = heap[yy];                            \
-      zz = yy;                                        \
-   }                                                  \
-   heap[zz] = tmp;                                    \
-}
-
-
-/*---------------------------------------------------*/
-void BZ2_hbMakeCodeLengths ( UChar *len, 
-                             Int32 *freq,
-                             Int32 alphaSize,
-                             Int32 maxLen )
-{
-   /*--
-      Nodes and heap entries run from 1.  Entry 0
-      for both the heap and nodes is a sentinel.
-   --*/
-   Int32 nNodes, nHeap, n1, n2, i, j, k;
-   Bool  tooLong;
-
-   Int32 heap   [ BZ_MAX_ALPHA_SIZE + 2 ];
-   Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
-   Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ]; 
-
-   for (i = 0; i < alphaSize; i++)
-      weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
-
-   while (True) {
-
-      nNodes = alphaSize;
-      nHeap = 0;
-
-      heap[0] = 0;
-      weight[0] = 0;
-      parent[0] = -2;
-
-      for (i = 1; i <= alphaSize; i++) {
-         parent[i] = -1;
-         nHeap++;
-         heap[nHeap] = i;
-         UPHEAP(nHeap);
-      }
-
-      AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
-   
-      while (nHeap > 1) {
-         n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
-         n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
-         nNodes++;
-         parent[n1] = parent[n2] = nNodes;
-         weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
-         parent[nNodes] = -1;
-         nHeap++;
-         heap[nHeap] = nNodes;
-         UPHEAP(nHeap);
-      }
-
-      AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
-
-      tooLong = False;
-      for (i = 1; i <= alphaSize; i++) {
-         j = 0;
-         k = i;
-         while (parent[k] >= 0) { k = parent[k]; j++; }
-         len[i-1] = j;
-         if (j > maxLen) tooLong = True;
-      }
-      
-      if (! tooLong) break;
-
-      /* 17 Oct 04: keep-going condition for the following loop used
-         to be 'i < alphaSize', which missed the last element,
-         theoretically leading to the possibility of the compressor
-         looping.  However, this count-scaling step is only needed if
-         one of the generated Huffman code words is longer than
-         maxLen, which up to and including version 1.0.2 was 20 bits,
-         which is extremely unlikely.  In version 1.0.3 maxLen was
-         changed to 17 bits, which has minimal effect on compression
-         ratio, but does mean this scaling step is used from time to
-         time, enough to verify that it works.
-
-         This means that bzip2-1.0.3 and later will only produce
-         Huffman codes with a maximum length of 17 bits.  However, in
-         order to preserve backwards compatibility with bitstreams
-         produced by versions pre-1.0.3, the decompressor must still
-         handle lengths of up to 20. */
-
-      for (i = 1; i <= alphaSize; i++) {
-         j = weight[i] >> 8;
-         j = 1 + (j / 2);
-         weight[i] = j << 8;
-      }
-   }
-}
-
-
-/*---------------------------------------------------*/
-void BZ2_hbAssignCodes ( Int32 *code,
-                         UChar *length,
-                         Int32 minLen,
-                         Int32 maxLen,
-                         Int32 alphaSize )
-{
-   Int32 n, vec, i;
-
-   vec = 0;
-   for (n = minLen; n <= maxLen; n++) {
-      for (i = 0; i < alphaSize; i++)
-         if (length[i] == n) { code[i] = vec; vec++; };
-      vec <<= 1;
-   }
-}
-
-
-/*---------------------------------------------------*/
-void BZ2_hbCreateDecodeTables ( Int32 *limit,
-                                Int32 *base,
-                                Int32 *perm,
-                                UChar *length,
-                                Int32 minLen,
-                                Int32 maxLen,
-                                Int32 alphaSize )
-{
-   Int32 pp, i, j, vec;
-
-   pp = 0;
-   for (i = minLen; i <= maxLen; i++)
-      for (j = 0; j < alphaSize; j++)
-         if (length[j] == i) { perm[pp] = j; pp++; };
-
-   for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
-   for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
-
-   for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
-
-   for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
-   vec = 0;
-
-   for (i = minLen; i <= maxLen; i++) {
-      vec += (base[i+1] - base[i]);
-      limit[i] = vec-1;
-      vec <<= 1;
-   }
-   for (i = minLen + 1; i <= maxLen; i++)
-      base[i] = ((limit[i-1] + 1) << 1) - base[i];
-}
-
-
-/*-------------------------------------------------------------*/
-/*--- end                                         huffman.c ---*/
-/*-------------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/libbz2.def
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/libbz2.def	(revision 9)
+++ 	(revision )
@@ -1,27 +1,0 @@
-LIBRARY			LIBBZ2
-DESCRIPTION		"libbzip2: library for data compression"
-EXPORTS
-	BZ2_bzCompressInit
-	BZ2_bzCompress
-	BZ2_bzCompressEnd
-	BZ2_bzDecompressInit
-	BZ2_bzDecompress
-	BZ2_bzDecompressEnd
-	BZ2_bzReadOpen
-	BZ2_bzReadClose
-	BZ2_bzReadGetUnused
-	BZ2_bzRead
-	BZ2_bzWriteOpen
-	BZ2_bzWrite
-	BZ2_bzWriteClose
-	BZ2_bzWriteClose64
-	BZ2_bzBuffToBuffCompress
-	BZ2_bzBuffToBuffDecompress
-	BZ2_bzlibVersion
-	BZ2_bzopen
-	BZ2_bzdopen
-	BZ2_bzread
-	BZ2_bzwrite
-	BZ2_bzflush
-	BZ2_bzclose
-	BZ2_bzerror
Index: trunk/minix/commands/bzip2-1.0.3/libbz2.dsp
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/libbz2.dsp	(revision 9)
+++ 	(revision )
@@ -1,130 +1,0 @@
-# Microsoft Developer Studio Project File - Name="libbz2" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 5.00
-# ** ÒWµÈ¢Å­Ÿ³¢ **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=libbz2 - Win32 Debug
-!MESSAGE ±êÍLøÈÒ²žÌ§²ÙÅÍ èÜ¹ñB ±ÌÌßÛŒÞªžÄðËÞÙÄÞ·éœßÉÍ NMAKE ðgpµÄ­Ÿ³¢B
-!MESSAGE [Ò²žÌ§²ÙÌŽžœÎß°Ä] ºÏÝÄÞðgpµÄÀsµÄ­Ÿ³¢
-!MESSAGE 
-!MESSAGE NMAKE /f "libbz2.mak".
-!MESSAGE 
-!MESSAGE NMAKE ÌÀsÉ\¬ðwèÅ«Ü·
-!MESSAGE ºÏÝÄÞ ×²ÝãÅÏžÛÌÝèðè`µÜ·Bá:
-!MESSAGE 
-!MESSAGE NMAKE /f "libbz2.mak" CFG="libbz2 - Win32 Debug"
-!MESSAGE 
-!MESSAGE IðÂ\ÈËÞÙÄÞ Ó°ÄÞ:
-!MESSAGE 
-!MESSAGE "libbz2 - Win32 Release" ("Win32 (x86) Dynamic-Link Library" p)
-!MESSAGE "libbz2 - Win32 Debug" ("Win32 (x86) Dynamic-Link Library" p)
-!MESSAGE 
-
-# Begin Project
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "libbz2 - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
-# ADD BASE RSC /l 0x411 /d "NDEBUG"
-# ADD RSC /l 0x411 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /out:"libbz2.dll"
-
-!ELSEIF  "$(CFG)" == "libbz2 - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
-# ADD BASE RSC /l 0x411 /d "_DEBUG"
-# ADD RSC /l 0x411 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"libbz2.dll" /pdbtype:sept
-
-!ENDIF 
-
-# Begin Target
-
-# Name "libbz2 - Win32 Release"
-# Name "libbz2 - Win32 Debug"
-# Begin Source File
-
-SOURCE=.\blocksort.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\bzlib.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\bzlib.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\bzlib_private.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\compress.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\crctable.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\decompress.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\huffman.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\libbz2.def
-# End Source File
-# Begin Source File
-
-SOURCE=.\randtable.c
-# End Source File
-# End Target
-# End Project
Index: trunk/minix/commands/bzip2-1.0.3/makefile.msc
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/makefile.msc	(revision 9)
+++ 	(revision )
@@ -1,63 +1,0 @@
-# Makefile for Microsoft Visual C++ 6.0
-# usage: nmake -f makefile.msc
-# K.M. Syring (syring@gsf.de)
-# Fixed up by JRS for bzip2-0.9.5d release.
-
-CC=cl
-CFLAGS= -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo
-
-OBJS= blocksort.obj  \
-      huffman.obj    \
-      crctable.obj   \
-      randtable.obj  \
-      compress.obj   \
-      decompress.obj \
-      bzlib.obj
-
-all: lib bzip2 test
-
-bzip2: lib
-	$(CC) $(CFLAGS) -o bzip2 bzip2.c libbz2.lib setargv.obj
-	$(CC) $(CFLAGS) -o bzip2recover bzip2recover.c
-
-lib: $(OBJS)
-	lib /out:libbz2.lib $(OBJS)
-
-test: bzip2
-	type words1
-	.\\bzip2 -1  < sample1.ref > sample1.rb2
-	.\\bzip2 -2  < sample2.ref > sample2.rb2
-	.\\bzip2 -3  < sample3.ref > sample3.rb2
-	.\\bzip2 -d  < sample1.bz2 > sample1.tst
-	.\\bzip2 -d  < sample2.bz2 > sample2.tst
-	.\\bzip2 -ds < sample3.bz2 > sample3.tst
-	@echo All six of the fc's should find no differences.
-	@echo If fc finds an error on sample3.bz2, this could be
-	@echo because WinZip's 'TAR file smart CR/LF conversion'
-	@echo is too clever for its own good.  Disable this option.
-	@echo The correct size for sample3.ref is 120,244.  If it
-	@echo is 150,251, WinZip has messed it up.
-	fc sample1.bz2 sample1.rb2 
-	fc sample2.bz2 sample2.rb2
-	fc sample3.bz2 sample3.rb2
-	fc sample1.tst sample1.ref
-	fc sample2.tst sample2.ref
-	fc sample3.tst sample3.ref
-
-
-
-clean: 
-	del *.obj
-	del libbz2.lib 
-	del bzip2.exe
-	del bzip2recover.exe
-	del sample1.rb2 
-	del sample2.rb2 
-	del sample3.rb2
-	del sample1.tst 
-	del sample2.tst
-	del sample3.tst
-
-.c.obj: 
-	$(CC) $(CFLAGS) -c $*.c -o $*.obj
-
Index: trunk/minix/commands/bzip2-1.0.3/manual.html
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/manual.html	(revision 9)
+++ 	(revision )
@@ -1,2687 +1,0 @@
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<title>bzip2 and libbzip2, version 1.0.3</title>
-<meta name="generator" content="DocBook XSL Stylesheets V1.64.1">
-<style type="text/css" media="screen">/* Colours:
-#74240f  dark brown      h1, h2, h3, h4
-#336699  medium blue     links
-#339999  turquoise       link hover colour
-#202020  almost black    general text
-#761596  purple          md5sum text
-#626262  dark gray       pre border
-#eeeeee  very light gray pre background
-#f2f2f9  very light blue nav table background
-#3366cc  medium blue     nav table border
-*/
-
-a, a:link, a:visited, a:active { color: #336699; }
-a:hover { color: #339999; }
-
-body { font: 80%/126% sans-serif; }
-h1, h2, h3, h4 { color: #74240f; }
-
-dt { color: #336699; font-weight: bold }
-dd { 
- margin-left: 1.5em; 
- padding-bottom: 0.8em;
-}
-
-/* -- ruler -- */
-div.hr_blue { 
-  height:  3px; 
-  background:#ffffff url("/images/hr_blue.png") repeat-x; }
-div.hr_blue hr { display:none; }
-
-/* release styles */
-#release p { margin-top: 0.4em; }
-#release .md5sum { color: #761596; }
-
-
-/* ------ styles for docs|manuals|howto ------ */
-/* -- lists -- */
-ul  { 
- margin:     0px 4px 16px 16px;
- padding:    0px;
- list-style: url("/images/li-blue.png"); 
-}
-ul li { 
- margin-bottom: 10px;
-}
-ul ul	{ 
- list-style-type:  none; 
- list-style-image: none; 
- margin-left:      0px; 
-}
-
-/* header / footer nav tables */
-table.nav {
- border:     solid 1px #3366cc;
- background: #f2f2f9;
- background-color: #f2f2f9;
- margin-bottom: 0.5em;
-}
-/* don't have underlined links in chunked nav menus */
-table.nav a { text-decoration: none; }
-table.nav a:hover { text-decoration: underline; }
-table.nav td { font-size: 85%; }
-
-code, tt, pre { font-size: 120%; }
-code, tt { color: #761596; }
-
-div.literallayout, pre.programlisting, pre.screen {
- color:      #000000;
- padding:    0.5em;
- background: #eeeeee;
- border:     1px solid #626262;
- background-color: #eeeeee;
- margin: 4px 0px 4px 0px; 
-}
-</style>
-</head>
-<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" lang="en">
-<div class="titlepage">
-<div>
-<div><h1 class="title">
-<a name="userman"></a>bzip2 and libbzip2, version 1.0.3</h1></div>
-<div><h2 class="subtitle">A program and library for data compression</h2></div>
-<div><div class="authorgroup"><div class="author">
-<h3 class="author">
-<span class="firstname">Julian</span> <span class="surname">Seward</span>
-</h3>
-<div class="affiliation"><span class="orgname">http://www.bzip.org<br></span></div>
-</div></div></div>
-<div><p class="releaseinfo">Version 1.0.3 of 15 February 2005</p></div>
-<div><p class="copyright">Copyright © 1996-2005 Julian Seward</p></div>
-<div><div class="legalnotice">
-<p>This program, <tt class="computeroutput">bzip2</tt>, the
-  associated library <tt class="computeroutput">libbzip2</tt>, and
-  all documentation, are copyright © 1996-2005 Julian Seward.
-  All rights reserved.</p>
-<p>Redistribution and use in source and binary forms, with
-  or without modification, are permitted provided that the
-  following conditions are met:</p>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc"><p>Redistributions of source code must retain the
-   above copyright notice, this list of conditions and the
-   following disclaimer.</p></li>
-<li style="list-style-type: disc"><p>The origin of this software must not be
-   misrepresented; you must not claim that you wrote the original
-   software.  If you use this software in a product, an
-   acknowledgment in the product documentation would be
-   appreciated but is not required.</p></li>
-<li style="list-style-type: disc"><p>Altered source versions must be plainly marked
-   as such, and must not be misrepresented as being the original
-   software.</p></li>
-<li style="list-style-type: disc"><p>The name of the author may not be used to
-   endorse or promote products derived from this software without
-   specific prior written permission.</p></li>
-</ul></div>
-<p>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.</p>
-<p>PATENTS: To the best of my knowledge,
- <tt class="computeroutput">bzip2</tt> and
- <tt class="computeroutput">libbzip2</tt> do not use any patented
- algorithms.  However, I do not have the resources to carry
- out a patent search.  Therefore I cannot give any guarantee of
- the above statement.
- </p>
-</div></div>
-</div>
-<div></div>
-<hr>
-</div>
-<div class="toc">
-<p><b>Table of Contents</b></p>
-<dl>
-<dt><span class="chapter"><a href="#intro">1. Introduction</a></span></dt>
-<dt><span class="chapter"><a href="#using">2. How to use bzip2</a></span></dt>
-<dd><dl>
-<dt><span class="sect1"><a href="#name">2.1. NAME</a></span></dt>
-<dt><span class="sect1"><a href="#synopsis">2.2. SYNOPSIS</a></span></dt>
-<dt><span class="sect1"><a href="#description">2.3. DESCRIPTION</a></span></dt>
-<dt><span class="sect1"><a href="#options">2.4. OPTIONS</a></span></dt>
-<dt><span class="sect1"><a href="#memory-management">2.5. MEMORY MANAGEMENT</a></span></dt>
-<dt><span class="sect1"><a href="#recovering">2.6. RECOVERING DATA FROM DAMAGED FILES</a></span></dt>
-<dt><span class="sect1"><a href="#performance">2.7. PERFORMANCE NOTES</a></span></dt>
-<dt><span class="sect1"><a href="#caveats">2.8. CAVEATS</a></span></dt>
-<dt><span class="sect1"><a href="#author">2.9. AUTHOR</a></span></dt>
-</dl></dd>
-<dt><span class="chapter"><a href="#libprog">3. 
-Programming with libbzip2
-</a></span></dt>
-<dd><dl>
-<dt><span class="sect1"><a href="#top-level">3.1. Top-level structure</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#ll-summary">3.1.1. Low-level summary</a></span></dt>
-<dt><span class="sect2"><a href="#hl-summary">3.1.2. High-level summary</a></span></dt>
-<dt><span class="sect2"><a href="#util-fns-summary">3.1.3. Utility functions summary</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#err-handling">3.2. Error handling</a></span></dt>
-<dt><span class="sect1"><a href="#low-level">3.3. Low-level interface</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#bzcompress-init">3.3.1. BZ2_bzCompressInit</a></span></dt>
-<dt><span class="sect2"><a href="#bzCompress">3.3.2. BZ2_bzCompress</a></span></dt>
-<dt><span class="sect2"><a href="#bzCompress-end">3.3.3. BZ2_bzCompressEnd</a></span></dt>
-<dt><span class="sect2"><a href="#bzDecompress-init">3.3.4. BZ2_bzDecompressInit</a></span></dt>
-<dt><span class="sect2"><a href="#bzDecompress">3.3.5. BZ2_bzDecompress</a></span></dt>
-<dt><span class="sect2"><a href="#bzDecompress-end">3.3.6. BZ2_bzDecompressEnd</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#hl-interface">3.4. High-level interface</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#bzreadopen">3.4.1. BZ2_bzReadOpen</a></span></dt>
-<dt><span class="sect2"><a href="#bzread">3.4.2. BZ2_bzRead</a></span></dt>
-<dt><span class="sect2"><a href="#bzreadgetunused">3.4.3. BZ2_bzReadGetUnused</a></span></dt>
-<dt><span class="sect2"><a href="#bzreadclose">3.4.4. BZ2_bzReadClose</a></span></dt>
-<dt><span class="sect2"><a href="#bzwriteopen">3.4.5. BZ2_bzWriteOpen</a></span></dt>
-<dt><span class="sect2"><a href="#bzwrite">3.4.6. BZ2_bzWrite</a></span></dt>
-<dt><span class="sect2"><a href="#bzwriteclose">3.4.7. BZ2_bzWriteClose</a></span></dt>
-<dt><span class="sect2"><a href="#embed">3.4.8. Handling embedded compressed data streams</a></span></dt>
-<dt><span class="sect2"><a href="#std-rdwr">3.4.9. Standard file-reading/writing code</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#util-fns">3.5. Utility functions</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#bzbufftobuffcompress">3.5.1. BZ2_bzBuffToBuffCompress</a></span></dt>
-<dt><span class="sect2"><a href="#bzbufftobuffdecompress">3.5.2. BZ2_bzBuffToBuffDecompress</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#zlib-compat">3.6. zlib compatibility functions</a></span></dt>
-<dt><span class="sect1"><a href="#stdio-free">3.7. Using the library in a stdio-free environment</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#stdio-bye">3.7.1. Getting rid of stdio</a></span></dt>
-<dt><span class="sect2"><a href="#critical-error">3.7.2. Critical error handling</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#win-dll">3.8. Making a Windows DLL</a></span></dt>
-</dl></dd>
-<dt><span class="chapter"><a href="#misc">4. Miscellanea</a></span></dt>
-<dd><dl>
-<dt><span class="sect1"><a href="#limits">4.1. Limitations of the compressed file format</a></span></dt>
-<dt><span class="sect1"><a href="#port-issues">4.2. Portability issues</a></span></dt>
-<dt><span class="sect1"><a href="#bugs">4.3. Reporting bugs</a></span></dt>
-<dt><span class="sect1"><a href="#package">4.4. Did you get the right package?</a></span></dt>
-<dt><span class="sect1"><a href="#reading">4.5. Further Reading</a></span></dt>
-</dl></dd>
-</dl>
-</div>
-<div class="chapter" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title">
-<a name="intro"></a>1. Introduction</h2></div></div>
-<div></div>
-</div>
-<p><tt class="computeroutput">bzip2</tt> compresses files
-using the Burrows-Wheeler block-sorting text compression
-algorithm, and Huffman coding.  Compression is generally
-considerably better than that achieved by more conventional
-LZ77/LZ78-based compressors, and approaches the performance of
-the PPM family of statistical compressors.</p>
-<p><tt class="computeroutput">bzip2</tt> is built on top of
-<tt class="computeroutput">libbzip2</tt>, a flexible library for
-handling compressed data in the
-<tt class="computeroutput">bzip2</tt> format.  This manual
-describes both how to use the program and how to work with the
-library interface.  Most of the manual is devoted to this
-library, not the program, which is good news if your interest is
-only in the program.</p>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc"><p><a href="#using">How to use bzip2</a> describes how to use
- <tt class="computeroutput">bzip2</tt>; this is the only part
- you need to read if you just want to know how to operate the
- program.</p></li>
-<li style="list-style-type: disc"><p><a href="#libprog">Programming with libbzip2</a> describes the
- programming interfaces in detail, and</p></li>
-<li style="list-style-type: disc"><p><a href="#misc">Miscellanea</a> records some
- miscellaneous notes which I thought ought to be recorded
- somewhere.</p></li>
-</ul></div>
-</div>
-<div class="chapter" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title">
-<a name="using"></a>2. How to use bzip2</h2></div></div>
-<div></div>
-</div>
-<div class="toc">
-<p><b>Table of Contents</b></p>
-<dl>
-<dt><span class="sect1"><a href="#name">2.1. NAME</a></span></dt>
-<dt><span class="sect1"><a href="#synopsis">2.2. SYNOPSIS</a></span></dt>
-<dt><span class="sect1"><a href="#description">2.3. DESCRIPTION</a></span></dt>
-<dt><span class="sect1"><a href="#options">2.4. OPTIONS</a></span></dt>
-<dt><span class="sect1"><a href="#memory-management">2.5. MEMORY MANAGEMENT</a></span></dt>
-<dt><span class="sect1"><a href="#recovering">2.6. RECOVERING DATA FROM DAMAGED FILES</a></span></dt>
-<dt><span class="sect1"><a href="#performance">2.7. PERFORMANCE NOTES</a></span></dt>
-<dt><span class="sect1"><a href="#caveats">2.8. CAVEATS</a></span></dt>
-<dt><span class="sect1"><a href="#author">2.9. AUTHOR</a></span></dt>
-</dl>
-</div>
-<p>This chapter contains a copy of the
-<tt class="computeroutput">bzip2</tt> man page, and nothing
-else.</p>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="name"></a>2.1. NAME</h2></div></div>
-<div></div>
-</div>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc"><p><tt class="computeroutput">bzip2</tt>,
-  <tt class="computeroutput">bunzip2</tt> - a block-sorting file
-  compressor, v1.0.3</p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">bzcat</tt> -
-   decompresses files to stdout</p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">bzip2recover</tt> -
-   recovers data from damaged bzip2 files</p></li>
-</ul></div>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="synopsis"></a>2.2. SYNOPSIS</h2></div></div>
-<div></div>
-</div>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc"><p><tt class="computeroutput">bzip2</tt> [
-  -cdfkqstvzVL123456789 ] [ filenames ...  ]</p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">bunzip2</tt> [
-  -fkvsVL ] [ filenames ...  ]</p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">bzcat</tt> [ -s ] [
-  filenames ...  ]</p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">bzip2recover</tt>
-  filename</p></li>
-</ul></div>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="description"></a>2.3. DESCRIPTION</h2></div></div>
-<div></div>
-</div>
-<p><tt class="computeroutput">bzip2</tt> compresses files
-using the Burrows-Wheeler block sorting text compression
-algorithm, and Huffman coding.  Compression is generally
-considerably better than that achieved by more conventional
-LZ77/LZ78-based compressors, and approaches the performance of
-the PPM family of statistical compressors.</p>
-<p>The command-line options are deliberately very similar to
-those of GNU <tt class="computeroutput">gzip</tt>, but they are
-not identical.</p>
-<p><tt class="computeroutput">bzip2</tt> expects a list of
-file names to accompany the command-line flags.  Each file is
-replaced by a compressed version of itself, with the name
-<tt class="computeroutput">original_name.bz2</tt>.  Each
-compressed file has the same modification date, permissions, and,
-when possible, ownership as the corresponding original, so that
-these properties can be correctly restored at decompression time.
-File name handling is naive in the sense that there is no
-mechanism for preserving original file names, permissions,
-ownerships or dates in filesystems which lack these concepts, or
-have serious file name length restrictions, such as
-MS-DOS.</p>
-<p><tt class="computeroutput">bzip2</tt> and
-<tt class="computeroutput">bunzip2</tt> will by default not
-overwrite existing files.  If you want this to happen, specify
-the <tt class="computeroutput">-f</tt> flag.</p>
-<p>If no file names are specified,
-<tt class="computeroutput">bzip2</tt> compresses from standard
-input to standard output.  In this case,
-<tt class="computeroutput">bzip2</tt> will decline to write
-compressed output to a terminal, as this would be entirely
-incomprehensible and therefore pointless.</p>
-<p><tt class="computeroutput">bunzip2</tt> (or
-<tt class="computeroutput">bzip2 -d</tt>) decompresses all
-specified files.  Files which were not created by
-<tt class="computeroutput">bzip2</tt> will be detected and
-ignored, and a warning issued.
-<tt class="computeroutput">bzip2</tt> attempts to guess the
-filename for the decompressed file from that of the compressed
-file as follows:</p>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc"><p><tt class="computeroutput">filename.bz2 </tt>
-  becomes
-  <tt class="computeroutput">filename</tt></p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">filename.bz </tt>
-  becomes
-  <tt class="computeroutput">filename</tt></p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">filename.tbz2</tt>
-  becomes
-  <tt class="computeroutput">filename.tar</tt></p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">filename.tbz </tt>
-  becomes
-  <tt class="computeroutput">filename.tar</tt></p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">anyothername </tt>
-  becomes
-  <tt class="computeroutput">anyothername.out</tt></p></li>
-</ul></div>
-<p>If the file does not end in one of the recognised endings,
-<tt class="computeroutput">.bz2</tt>,
-<tt class="computeroutput">.bz</tt>,
-<tt class="computeroutput">.tbz2</tt> or
-<tt class="computeroutput">.tbz</tt>,
-<tt class="computeroutput">bzip2</tt> complains that it cannot
-guess the name of the original file, and uses the original name
-with <tt class="computeroutput">.out</tt> appended.</p>
-<p>As with compression, supplying no filenames causes
-decompression from standard input to standard output.</p>
-<p><tt class="computeroutput">bunzip2</tt> will correctly
-decompress a file which is the concatenation of two or more
-compressed files.  The result is the concatenation of the
-corresponding uncompressed files.  Integrity testing
-(<tt class="computeroutput">-t</tt>) of concatenated compressed
-files is also supported.</p>
-<p>You can also compress or decompress files to the standard
-output by giving the <tt class="computeroutput">-c</tt> flag.
-Multiple files may be compressed and decompressed like this.  The
-resulting outputs are fed sequentially to stdout.  Compression of
-multiple files in this manner generates a stream containing
-multiple compressed file representations.  Such a stream can be
-decompressed correctly only by
-<tt class="computeroutput">bzip2</tt> version 0.9.0 or later.
-Earlier versions of <tt class="computeroutput">bzip2</tt> will
-stop after decompressing the first file in the stream.</p>
-<p><tt class="computeroutput">bzcat</tt> (or
-<tt class="computeroutput">bzip2 -dc</tt>) decompresses all
-specified files to the standard output.</p>
-<p><tt class="computeroutput">bzip2</tt> will read arguments
-from the environment variables
-<tt class="computeroutput">BZIP2</tt> and
-<tt class="computeroutput">BZIP</tt>, in that order, and will
-process them before any arguments read from the command line.
-This gives a convenient way to supply default arguments.</p>
-<p>Compression is always performed, even if the compressed
-file is slightly larger than the original.  Files of less than
-about one hundred bytes tend to get larger, since the compression
-mechanism has a constant overhead in the region of 50 bytes.
-Random data (including the output of most file compressors) is
-coded at about 8.05 bits per byte, giving an expansion of around
-0.5%.</p>
-<p>As a self-check for your protection,
-<tt class="computeroutput">bzip2</tt> uses 32-bit CRCs to make
-sure that the decompressed version of a file is identical to the
-original.  This guards against corruption of the compressed data,
-and against undetected bugs in
-<tt class="computeroutput">bzip2</tt> (hopefully very unlikely).
-The chances of data corruption going undetected is microscopic,
-about one chance in four billion for each file processed.  Be
-aware, though, that the check occurs upon decompression, so it
-can only tell you that something is wrong.  It can't help you
-recover the original uncompressed data.  You can use
-<tt class="computeroutput">bzip2recover</tt> to try to recover
-data from damaged files.</p>
-<p>Return values: 0 for a normal exit, 1 for environmental
-problems (file not found, invalid flags, I/O errors, etc.), 2
-to indicate a corrupt compressed file, 3 for an internal
-consistency error (eg, bug) which caused
-<tt class="computeroutput">bzip2</tt> to panic.</p>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="options"></a>2.4. OPTIONS</h2></div></div>
-<div></div>
-</div>
-<div class="variablelist"><dl>
-<dt><span class="term"><tt class="computeroutput">-c --stdout</tt></span></dt>
-<dd><p>Compress or decompress to standard
-  output.</p></dd>
-<dt><span class="term"><tt class="computeroutput">-d --decompress</tt></span></dt>
-<dd><p>Force decompression.
-  <tt class="computeroutput">bzip2</tt>,
-  <tt class="computeroutput">bunzip2</tt> and
-  <tt class="computeroutput">bzcat</tt> are really the same
-  program, and the decision about what actions to take is done on
-  the basis of which name is used.  This flag overrides that
-  mechanism, and forces bzip2 to decompress.</p></dd>
-<dt><span class="term"><tt class="computeroutput">-z --compress</tt></span></dt>
-<dd><p>The complement to
-  <tt class="computeroutput">-d</tt>: forces compression,
-  regardless of the invokation name.</p></dd>
-<dt><span class="term"><tt class="computeroutput">-t --test</tt></span></dt>
-<dd><p>Check integrity of the specified file(s), but
-  don't decompress them.  This really performs a trial
-  decompression and throws away the result.</p></dd>
-<dt><span class="term"><tt class="computeroutput">-f --force</tt></span></dt>
-<dd>
-<p>Force overwrite of output files.  Normally,
-  <tt class="computeroutput">bzip2</tt> will not overwrite
-  existing output files.  Also forces
-  <tt class="computeroutput">bzip2</tt> to break hard links to
-  files, which it otherwise wouldn't do.</p>
-<p><tt class="computeroutput">bzip2</tt> normally declines
-  to decompress files which don't have the correct magic header
-  bytes. If forced (<tt class="computeroutput">-f</tt>),
-  however, it will pass such files through unmodified. This is
-  how GNU <tt class="computeroutput">gzip</tt> behaves.</p>
-</dd>
-<dt><span class="term"><tt class="computeroutput">-k --keep</tt></span></dt>
-<dd><p>Keep (don't delete) input files during
-  compression or decompression.</p></dd>
-<dt><span class="term"><tt class="computeroutput">-s --small</tt></span></dt>
-<dd>
-<p>Reduce memory usage, for compression,
-  decompression and testing.  Files are decompressed and tested
-  using a modified algorithm which only requires 2.5 bytes per
-  block byte.  This means any file can be decompressed in 2300k
-  of memory, albeit at about half the normal speed.</p>
-<p>During compression, <tt class="computeroutput">-s</tt>
-  selects a block size of 200k, which limits memory use to around
-  the same figure, at the expense of your compression ratio.  In
-  short, if your machine is low on memory (8 megabytes or less),
-  use <tt class="computeroutput">-s</tt> for everything.  See
-  <a href="#memory-management">MEMORY MANAGEMENT</a> below.</p>
-</dd>
-<dt><span class="term"><tt class="computeroutput">-q --quiet</tt></span></dt>
-<dd><p>Suppress non-essential warning messages.
-  Messages pertaining to I/O errors and other critical events
-  will not be suppressed.</p></dd>
-<dt><span class="term"><tt class="computeroutput">-v --verbose</tt></span></dt>
-<dd><p>Verbose mode -- show the compression ratio for
-  each file processed.  Further
-  <tt class="computeroutput">-v</tt>'s increase the verbosity
-  level, spewing out lots of information which is primarily of
-  interest for diagnostic purposes.</p></dd>
-<dt><span class="term"><tt class="computeroutput">-L --license -V --version</tt></span></dt>
-<dd><p>Display the software version, license terms and
-  conditions.</p></dd>
-<dt><span class="term"><tt class="computeroutput">-1</tt> (or
- <tt class="computeroutput">--fast</tt>) to
- <tt class="computeroutput">-9</tt> (or
- <tt class="computeroutput">-best</tt>)</span></dt>
-<dd><p>Set the block size to 100 k, 200 k ...  900 k
-  when compressing.  Has no effect when decompressing.  See <a href="#memory-management">MEMORY MANAGEMENT</a> below.  The
-  <tt class="computeroutput">--fast</tt> and
-  <tt class="computeroutput">--best</tt> aliases are primarily
-  for GNU <tt class="computeroutput">gzip</tt> compatibility.
-  In particular, <tt class="computeroutput">--fast</tt> doesn't
-  make things significantly faster.  And
-  <tt class="computeroutput">--best</tt> merely selects the
-  default behaviour.</p></dd>
-<dt><span class="term"><tt class="computeroutput">--</tt></span></dt>
-<dd><p>Treats all subsequent arguments as file names,
-  even if they start with a dash.  This is so you can handle
-  files with names beginning with a dash, for example:
-  <tt class="computeroutput">bzip2 --
-  -myfilename</tt>.</p></dd>
-<dt>
-<span class="term"><tt class="computeroutput">--repetitive-fast</tt>, </span><span class="term"><tt class="computeroutput">--repetitive-best</tt>, </span>
-</dt>
-<dd><p>These flags are redundant in versions 0.9.5 and
-  above.  They provided some coarse control over the behaviour of
-  the sorting algorithm in earlier versions, which was sometimes
-  useful.  0.9.5 and above have an improved algorithm which
-  renders these flags irrelevant.</p></dd>
-</dl></div>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="memory-management"></a>2.5. MEMORY MANAGEMENT</h2></div></div>
-<div></div>
-</div>
-<p><tt class="computeroutput">bzip2</tt> compresses large
-files in blocks.  The block size affects both the compression
-ratio achieved, and the amount of memory needed for compression
-and decompression.  The flags <tt class="computeroutput">-1</tt>
-through <tt class="computeroutput">-9</tt> specify the block
-size to be 100,000 bytes through 900,000 bytes (the default)
-respectively.  At decompression time, the block size used for
-compression is read from the header of the compressed file, and
-<tt class="computeroutput">bunzip2</tt> then allocates itself
-just enough memory to decompress the file.  Since block sizes are
-stored in compressed files, it follows that the flags
-<tt class="computeroutput">-1</tt> to
-<tt class="computeroutput">-9</tt> are irrelevant to and so
-ignored during decompression.</p>
-<p>Compression and decompression requirements, in bytes, can be
-estimated as:</p>
-<pre class="programlisting">Compression:   400k + ( 8 x block size )
-
-Decompression: 100k + ( 4 x block size ), or
-               100k + ( 2.5 x block size )</pre>
-<p>Larger block sizes give rapidly diminishing marginal
-returns.  Most of the compression comes from the first two or
-three hundred k of block size, a fact worth bearing in mind when
-using <tt class="computeroutput">bzip2</tt> on small machines.
-It is also important to appreciate that the decompression memory
-requirement is set at compression time by the choice of block
-size.</p>
-<p>For files compressed with the default 900k block size,
-<tt class="computeroutput">bunzip2</tt> will require about 3700
-kbytes to decompress.  To support decompression of any file on a
-4 megabyte machine, <tt class="computeroutput">bunzip2</tt> has
-an option to decompress using approximately half this amount of
-memory, about 2300 kbytes.  Decompression speed is also halved,
-so you should use this option only where necessary.  The relevant
-flag is <tt class="computeroutput">-s</tt>.</p>
-<p>In general, try and use the largest block size memory
-constraints allow, since that maximises the compression achieved.
-Compression and decompression speed are virtually unaffected by
-block size.</p>
-<p>Another significant point applies to files which fit in a
-single block -- that means most files you'd encounter using a
-large block size.  The amount of real memory touched is
-proportional to the size of the file, since the file is smaller
-than a block.  For example, compressing a file 20,000 bytes long
-with the flag <tt class="computeroutput">-9</tt> will cause the
-compressor to allocate around 7600k of memory, but only touch
-400k + 20000 * 8 = 560 kbytes of it.  Similarly, the decompressor
-will allocate 3700k but only touch 100k + 20000 * 4 = 180
-kbytes.</p>
-<p>Here is a table which summarises the maximum memory usage
-for different block sizes.  Also recorded is the total compressed
-size for 14 files of the Calgary Text Compression Corpus
-totalling 3,141,622 bytes.  This column gives some feel for how
-compression varies with block size.  These figures tend to
-understate the advantage of larger block sizes for larger files,
-since the Corpus is dominated by smaller files.</p>
-<pre class="programlisting">        Compress   Decompress   Decompress   Corpus
-Flag     usage      usage       -s usage     Size
-
- -1      1200k       500k         350k      914704
- -2      2000k       900k         600k      877703
- -3      2800k      1300k         850k      860338
- -4      3600k      1700k        1100k      846899
- -5      4400k      2100k        1350k      845160
- -6      5200k      2500k        1600k      838626
- -7      6100k      2900k        1850k      834096
- -8      6800k      3300k        2100k      828642
- -9      7600k      3700k        2350k      828642</pre>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="recovering"></a>2.6. RECOVERING DATA FROM DAMAGED FILES</h2></div></div>
-<div></div>
-</div>
-<p><tt class="computeroutput">bzip2</tt> compresses files in
-blocks, usually 900kbytes long.  Each block is handled
-independently.  If a media or transmission error causes a
-multi-block <tt class="computeroutput">.bz2</tt> file to become
-damaged, it may be possible to recover data from the undamaged
-blocks in the file.</p>
-<p>The compressed representation of each block is delimited by
-a 48-bit pattern, which makes it possible to find the block
-boundaries with reasonable certainty.  Each block also carries
-its own 32-bit CRC, so damaged blocks can be distinguished from
-undamaged ones.</p>
-<p><tt class="computeroutput">bzip2recover</tt> is a simple
-program whose purpose is to search for blocks in
-<tt class="computeroutput">.bz2</tt> files, and write each block
-out into its own <tt class="computeroutput">.bz2</tt> file.  You
-can then use <tt class="computeroutput">bzip2 -t</tt> to test
-the integrity of the resulting files, and decompress those which
-are undamaged.</p>
-<p><tt class="computeroutput">bzip2recover</tt> takes a
-single argument, the name of the damaged file, and writes a
-number of files <tt class="computeroutput">rec0001file.bz2</tt>,
-<tt class="computeroutput">rec0002file.bz2</tt>, etc, containing
-the extracted blocks.  The output filenames are designed so that
-the use of wildcards in subsequent processing -- for example,
-<tt class="computeroutput">bzip2 -dc rec*file.bz2 &gt;
-recovered_data</tt> -- lists the files in the correct
-order.</p>
-<p><tt class="computeroutput">bzip2recover</tt> should be of
-most use dealing with large <tt class="computeroutput">.bz2</tt>
-files, as these will contain many blocks.  It is clearly futile
-to use it on damaged single-block files, since a damaged block
-cannot be recovered.  If you wish to minimise any potential data
-loss through media or transmission errors, you might consider
-compressing with a smaller block size.</p>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="performance"></a>2.7. PERFORMANCE NOTES</h2></div></div>
-<div></div>
-</div>
-<p>The sorting phase of compression gathers together similar
-strings in the file.  Because of this, files containing very long
-runs of repeated symbols, like "aabaabaabaab ..."  (repeated
-several hundred times) may compress more slowly than normal.
-Versions 0.9.5 and above fare much better than previous versions
-in this respect.  The ratio between worst-case and average-case
-compression time is in the region of 10:1.  For previous
-versions, this figure was more like 100:1.  You can use the
-<tt class="computeroutput">-vvvv</tt> option to monitor progress
-in great detail, if you want.</p>
-<p>Decompression speed is unaffected by these
-phenomena.</p>
-<p><tt class="computeroutput">bzip2</tt> usually allocates
-several megabytes of memory to operate in, and then charges all
-over it in a fairly random fashion.  This means that performance,
-both for compressing and decompressing, is largely determined by
-the speed at which your machine can service cache misses.
-Because of this, small changes to the code to reduce the miss
-rate have been observed to give disproportionately large
-performance improvements.  I imagine
-<tt class="computeroutput">bzip2</tt> will perform best on
-machines with very large caches.</p>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="caveats"></a>2.8. CAVEATS</h2></div></div>
-<div></div>
-</div>
-<p>I/O error messages are not as helpful as they could be.
-<tt class="computeroutput">bzip2</tt> tries hard to detect I/O
-errors and exit cleanly, but the details of what the problem is
-sometimes seem rather misleading.</p>
-<p>This manual page pertains to version 1.0.3 of
-<tt class="computeroutput">bzip2</tt>.  Compressed data created
-by this version is entirely forwards and backwards compatible
-with the previous public releases, versions 0.1pl2, 0.9.0 and
-0.9.5, 1.0.0, 1.0.1 and 1.0.2, but with the following exception: 0.9.0
-and above can correctly decompress multiple concatenated
-compressed files.  0.1pl2 cannot do this; it will stop after
-decompressing just the first file in the stream.</p>
-<p><tt class="computeroutput">bzip2recover</tt> versions
-prior to 1.0.2 used 32-bit integers to represent bit positions in
-compressed files, so it could not handle compressed files more
-than 512 megabytes long.  Versions 1.0.2 and above use 64-bit ints
-on some platforms which support them (GNU supported targets, and
-Windows). To establish whether or not
-<tt class="computeroutput">bzip2recover</tt> was built with such
-a limitation, run it without arguments. In any event you can
-build yourself an unlimited version if you can recompile it with
-<tt class="computeroutput">MaybeUInt64</tt> set to be an
-unsigned 64-bit integer.</p>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="author"></a>2.9. AUTHOR</h2></div></div>
-<div></div>
-</div>
-<p>Julian Seward,
-<tt class="computeroutput">jseward@bzip.org</tt></p>
-<p>The ideas embodied in
-<tt class="computeroutput">bzip2</tt> are due to (at least) the
-following people: Michael Burrows and David Wheeler (for the
-block sorting transformation), David Wheeler (again, for the
-Huffman coder), Peter Fenwick (for the structured coding model in
-the original <tt class="computeroutput">bzip</tt>, and many
-refinements), and Alistair Moffat, Radford Neal and Ian Witten
-(for the arithmetic coder in the original
-<tt class="computeroutput">bzip</tt>).  I am much indebted for
-their help, support and advice.  See the manual in the source
-distribution for pointers to sources of documentation.  Christian
-von Roques encouraged me to look for faster sorting algorithms,
-so as to speed up compression.  Bela Lubkin encouraged me to
-improve the worst-case compression performance.  
-Donna Robinson XMLised the documentation.
-Many people sent
-patches, helped with portability problems, lent machines, gave
-advice and were generally helpful.</p>
-</div>
-</div>
-<div class="chapter" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title">
-<a name="libprog"></a>3. 
-Programming with <tt class="computeroutput">libbzip2</tt>
-</h2></div></div>
-<div></div>
-</div>
-<div class="toc">
-<p><b>Table of Contents</b></p>
-<dl>
-<dt><span class="sect1"><a href="#top-level">3.1. Top-level structure</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#ll-summary">3.1.1. Low-level summary</a></span></dt>
-<dt><span class="sect2"><a href="#hl-summary">3.1.2. High-level summary</a></span></dt>
-<dt><span class="sect2"><a href="#util-fns-summary">3.1.3. Utility functions summary</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#err-handling">3.2. Error handling</a></span></dt>
-<dt><span class="sect1"><a href="#low-level">3.3. Low-level interface</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#bzcompress-init">3.3.1. BZ2_bzCompressInit</a></span></dt>
-<dt><span class="sect2"><a href="#bzCompress">3.3.2. BZ2_bzCompress</a></span></dt>
-<dt><span class="sect2"><a href="#bzCompress-end">3.3.3. BZ2_bzCompressEnd</a></span></dt>
-<dt><span class="sect2"><a href="#bzDecompress-init">3.3.4. BZ2_bzDecompressInit</a></span></dt>
-<dt><span class="sect2"><a href="#bzDecompress">3.3.5. BZ2_bzDecompress</a></span></dt>
-<dt><span class="sect2"><a href="#bzDecompress-end">3.3.6. BZ2_bzDecompressEnd</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#hl-interface">3.4. High-level interface</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#bzreadopen">3.4.1. BZ2_bzReadOpen</a></span></dt>
-<dt><span class="sect2"><a href="#bzread">3.4.2. BZ2_bzRead</a></span></dt>
-<dt><span class="sect2"><a href="#bzreadgetunused">3.4.3. BZ2_bzReadGetUnused</a></span></dt>
-<dt><span class="sect2"><a href="#bzreadclose">3.4.4. BZ2_bzReadClose</a></span></dt>
-<dt><span class="sect2"><a href="#bzwriteopen">3.4.5. BZ2_bzWriteOpen</a></span></dt>
-<dt><span class="sect2"><a href="#bzwrite">3.4.6. BZ2_bzWrite</a></span></dt>
-<dt><span class="sect2"><a href="#bzwriteclose">3.4.7. BZ2_bzWriteClose</a></span></dt>
-<dt><span class="sect2"><a href="#embed">3.4.8. Handling embedded compressed data streams</a></span></dt>
-<dt><span class="sect2"><a href="#std-rdwr">3.4.9. Standard file-reading/writing code</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#util-fns">3.5. Utility functions</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#bzbufftobuffcompress">3.5.1. BZ2_bzBuffToBuffCompress</a></span></dt>
-<dt><span class="sect2"><a href="#bzbufftobuffdecompress">3.5.2. BZ2_bzBuffToBuffDecompress</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#zlib-compat">3.6. zlib compatibility functions</a></span></dt>
-<dt><span class="sect1"><a href="#stdio-free">3.7. Using the library in a stdio-free environment</a></span></dt>
-<dd><dl>
-<dt><span class="sect2"><a href="#stdio-bye">3.7.1. Getting rid of stdio</a></span></dt>
-<dt><span class="sect2"><a href="#critical-error">3.7.2. Critical error handling</a></span></dt>
-</dl></dd>
-<dt><span class="sect1"><a href="#win-dll">3.8. Making a Windows DLL</a></span></dt>
-</dl>
-</div>
-<p>This chapter describes the programming interface to
-<tt class="computeroutput">libbzip2</tt>.</p>
-<p>For general background information, particularly about
-memory use and performance aspects, you'd be well advised to read
-<a href="#using">How to use bzip2</a> as well.</p>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="top-level"></a>3.1. Top-level structure</h2></div></div>
-<div></div>
-</div>
-<p><tt class="computeroutput">libbzip2</tt> is a flexible
-library for compressing and decompressing data in the
-<tt class="computeroutput">bzip2</tt> data format.  Although
-packaged as a single entity, it helps to regard the library as
-three separate parts: the low level interface, and the high level
-interface, and some utility functions.</p>
-<p>The structure of
-<tt class="computeroutput">libbzip2</tt>'s interfaces is similar
-to that of Jean-loup Gailly's and Mark Adler's excellent
-<tt class="computeroutput">zlib</tt> library.</p>
-<p>All externally visible symbols have names beginning
-<tt class="computeroutput">BZ2_</tt>.  This is new in version
-1.0.  The intention is to minimise pollution of the namespaces of
-library clients.</p>
-<p>To use any part of the library, you need to
-<tt class="computeroutput">#include &lt;bzlib.h&gt;</tt>
-into your sources.</p>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="ll-summary"></a>3.1.1. Low-level summary</h3></div></div>
-<div></div>
-</div>
-<p>This interface provides services for compressing and
-decompressing data in memory.  There's no provision for dealing
-with files, streams or any other I/O mechanisms, just straight
-memory-to-memory work.  In fact, this part of the library can be
-compiled without inclusion of
-<tt class="computeroutput">stdio.h</tt>, which may be helpful
-for embedded applications.</p>
-<p>The low-level part of the library has no global variables
-and is therefore thread-safe.</p>
-<p>Six routines make up the low level interface:
-<tt class="computeroutput">BZ2_bzCompressInit</tt>,
-<tt class="computeroutput">BZ2_bzCompress</tt>, and
-<tt class="computeroutput">BZ2_bzCompressEnd</tt> for
-compression, and a corresponding trio
-<tt class="computeroutput">BZ2_bzDecompressInit</tt>,
-<tt class="computeroutput">BZ2_bzDecompress</tt> and
-<tt class="computeroutput">BZ2_bzDecompressEnd</tt> for
-decompression.  The <tt class="computeroutput">*Init</tt>
-functions allocate memory for compression/decompression and do
-other initialisations, whilst the
-<tt class="computeroutput">*End</tt> functions close down
-operations and release memory.</p>
-<p>The real work is done by
-<tt class="computeroutput">BZ2_bzCompress</tt> and
-<tt class="computeroutput">BZ2_bzDecompress</tt>.  These
-compress and decompress data from a user-supplied input buffer to
-a user-supplied output buffer.  These buffers can be any size;
-arbitrary quantities of data are handled by making repeated calls
-to these functions.  This is a flexible mechanism allowing a
-consumer-pull style of activity, or producer-push, or a mixture
-of both.</p>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="hl-summary"></a>3.1.2. High-level summary</h3></div></div>
-<div></div>
-</div>
-<p>This interface provides some handy wrappers around the
-low-level interface to facilitate reading and writing
-<tt class="computeroutput">bzip2</tt> format files
-(<tt class="computeroutput">.bz2</tt> files).  The routines
-provide hooks to facilitate reading files in which the
-<tt class="computeroutput">bzip2</tt> data stream is embedded
-within some larger-scale file structure, or where there are
-multiple <tt class="computeroutput">bzip2</tt> data streams
-concatenated end-to-end.</p>
-<p>For reading files,
-<tt class="computeroutput">BZ2_bzReadOpen</tt>,
-<tt class="computeroutput">BZ2_bzRead</tt>,
-<tt class="computeroutput">BZ2_bzReadClose</tt> and 
-<tt class="computeroutput">BZ2_bzReadGetUnused</tt> are
-supplied.  For writing files,
-<tt class="computeroutput">BZ2_bzWriteOpen</tt>,
-<tt class="computeroutput">BZ2_bzWrite</tt> and
-<tt class="computeroutput">BZ2_bzWriteFinish</tt> are
-available.</p>
-<p>As with the low-level library, no global variables are used
-so the library is per se thread-safe.  However, if I/O errors
-occur whilst reading or writing the underlying compressed files,
-you may have to consult <tt class="computeroutput">errno</tt> to
-determine the cause of the error.  In that case, you'd need a C
-library which correctly supports
-<tt class="computeroutput">errno</tt> in a multithreaded
-environment.</p>
-<p>To make the library a little simpler and more portable,
-<tt class="computeroutput">BZ2_bzReadOpen</tt> and
-<tt class="computeroutput">BZ2_bzWriteOpen</tt> require you to
-pass them file handles (<tt class="computeroutput">FILE*</tt>s)
-which have previously been opened for reading or writing
-respectively.  That avoids portability problems associated with
-file operations and file attributes, whilst not being much of an
-imposition on the programmer.</p>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="util-fns-summary"></a>3.1.3. Utility functions summary</h3></div></div>
-<div></div>
-</div>
-<p>For very simple needs,
-<tt class="computeroutput">BZ2_bzBuffToBuffCompress</tt> and
-<tt class="computeroutput">BZ2_bzBuffToBuffDecompress</tt> are
-provided.  These compress data in memory from one buffer to
-another buffer in a single function call.  You should assess
-whether these functions fulfill your memory-to-memory
-compression/decompression requirements before investing effort in
-understanding the more general but more complex low-level
-interface.</p>
-<p>Yoshioka Tsuneo
-(<tt class="computeroutput">QWF00133@niftyserve.or.jp</tt> /
-<tt class="computeroutput">tsuneo-y@is.aist-nara.ac.jp</tt>) has
-contributed some functions to give better
-<tt class="computeroutput">zlib</tt> compatibility.  These
-functions are <tt class="computeroutput">BZ2_bzopen</tt>,
-<tt class="computeroutput">BZ2_bzread</tt>,
-<tt class="computeroutput">BZ2_bzwrite</tt>,
-<tt class="computeroutput">BZ2_bzflush</tt>,
-<tt class="computeroutput">BZ2_bzclose</tt>,
-<tt class="computeroutput">BZ2_bzerror</tt> and
-<tt class="computeroutput">BZ2_bzlibVersion</tt>.  You may find
-these functions more convenient for simple file reading and
-writing, than those in the high-level interface.  These functions
-are not (yet) officially part of the library, and are minimally
-documented here.  If they break, you get to keep all the pieces.
-I hope to document them properly when time permits.</p>
-<p>Yoshioka also contributed modifications to allow the
-library to be built as a Windows DLL.</p>
-</div>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="err-handling"></a>3.2. Error handling</h2></div></div>
-<div></div>
-</div>
-<p>The library is designed to recover cleanly in all
-situations, including the worst-case situation of decompressing
-random data.  I'm not 100% sure that it can always do this, so
-you might want to add a signal handler to catch segmentation
-violations during decompression if you are feeling especially
-paranoid.  I would be interested in hearing more about the
-robustness of the library to corrupted compressed data.</p>
-<p>Version 1.0.3 more robust in this respect than any
-previous version.  Investigations with Valgrind (a tool for detecting
-problems with memory management) indicate
-that, at least for the few files I tested, all single-bit errors
-in the decompressed data are caught properly, with no
-segmentation faults, no uses of uninitialised data, no out of
-range reads or writes, and no infinite looping in the decompressor.
-So it's certainly pretty robust, although
-I wouldn't claim it to be totally bombproof.</p>
-<p>The file <tt class="computeroutput">bzlib.h</tt> contains
-all definitions needed to use the library.  In particular, you
-should definitely not include
-<tt class="computeroutput">bzlib_private.h</tt>.</p>
-<p>In <tt class="computeroutput">bzlib.h</tt>, the various
-return values are defined.  The following list is not intended as
-an exhaustive description of the circumstances in which a given
-value may be returned -- those descriptions are given later.
-Rather, it is intended to convey the rough meaning of each return
-value.  The first five actions are normal and not intended to
-denote an error situation.</p>
-<div class="variablelist"><dl>
-<dt><span class="term"><tt class="computeroutput">BZ_OK</tt></span></dt>
-<dd><p>The requested action was completed
-   successfully.</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_RUN_OK, BZ_FLUSH_OK,
-    BZ_FINISH_OK</tt></span></dt>
-<dd><p>In 
-   <tt class="computeroutput">BZ2_bzCompress</tt>, the requested
-   flush/finish/nothing-special action was completed
-   successfully.</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_STREAM_END</tt></span></dt>
-<dd><p>Compression of data was completed, or the
-   logical stream end was detected during
-   decompression.</p></dd>
-</dl></div>
-<p>The following return values indicate an error of some
-kind.</p>
-<div class="variablelist"><dl>
-<dt><span class="term"><tt class="computeroutput">BZ_CONFIG_ERROR</tt></span></dt>
-<dd><p>Indicates that the library has been improperly
-   compiled on your platform -- a major configuration error.
-   Specifically, it means that
-   <tt class="computeroutput">sizeof(char)</tt>,
-   <tt class="computeroutput">sizeof(short)</tt> and
-   <tt class="computeroutput">sizeof(int)</tt> are not 1, 2 and
-   4 respectively, as they should be.  Note that the library
-   should still work properly on 64-bit platforms which follow
-   the LP64 programming model -- that is, where
-   <tt class="computeroutput">sizeof(long)</tt> and
-   <tt class="computeroutput">sizeof(void*)</tt> are 8.  Under
-   LP64, <tt class="computeroutput">sizeof(int)</tt> is still 4,
-   so <tt class="computeroutput">libbzip2</tt>, which doesn't
-   use the <tt class="computeroutput">long</tt> type, is
-   OK.</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_SEQUENCE_ERROR</tt></span></dt>
-<dd><p>When using the library, it is important to call
-   the functions in the correct sequence and with data structures
-   (buffers etc) in the correct states.
-   <tt class="computeroutput">libbzip2</tt> checks as much as it
-   can to ensure this is happening, and returns
-   <tt class="computeroutput">BZ_SEQUENCE_ERROR</tt> if not.
-   Code which complies precisely with the function semantics, as
-   detailed below, should never receive this value; such an event
-   denotes buggy code which you should
-   investigate.</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_PARAM_ERROR</tt></span></dt>
-<dd><p>Returned when a parameter to a function call is
-   out of range or otherwise manifestly incorrect.  As with
-   <tt class="computeroutput">BZ_SEQUENCE_ERROR</tt>, this
-   denotes a bug in the client code.  The distinction between
-   <tt class="computeroutput">BZ_PARAM_ERROR</tt> and
-   <tt class="computeroutput">BZ_SEQUENCE_ERROR</tt> is a bit
-   hazy, but still worth making.</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_MEM_ERROR</tt></span></dt>
-<dd><p>Returned when a request to allocate memory
-   failed.  Note that the quantity of memory needed to decompress
-   a stream cannot be determined until the stream's header has
-   been read.  So
-   <tt class="computeroutput">BZ2_bzDecompress</tt> and
-   <tt class="computeroutput">BZ2_bzRead</tt> may return
-   <tt class="computeroutput">BZ_MEM_ERROR</tt> even though some
-   of the compressed data has been read.  The same is not true
-   for compression; once
-   <tt class="computeroutput">BZ2_bzCompressInit</tt> or
-   <tt class="computeroutput">BZ2_bzWriteOpen</tt> have
-   successfully completed,
-   <tt class="computeroutput">BZ_MEM_ERROR</tt> cannot
-   occur.</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_DATA_ERROR</tt></span></dt>
-<dd><p>Returned when a data integrity error is
-   detected during decompression.  Most importantly, this means
-   when stored and computed CRCs for the data do not match.  This
-   value is also returned upon detection of any other anomaly in
-   the compressed data.</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_DATA_ERROR_MAGIC</tt></span></dt>
-<dd><p>As a special case of
-   <tt class="computeroutput">BZ_DATA_ERROR</tt>, it is
-   sometimes useful to know when the compressed stream does not
-   start with the correct magic bytes (<tt class="computeroutput">'B' 'Z'
-   'h'</tt>).</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_IO_ERROR</tt></span></dt>
-<dd><p>Returned by
-   <tt class="computeroutput">BZ2_bzRead</tt> and
-   <tt class="computeroutput">BZ2_bzWrite</tt> when there is an
-   error reading or writing in the compressed file, and by
-   <tt class="computeroutput">BZ2_bzReadOpen</tt> and
-   <tt class="computeroutput">BZ2_bzWriteOpen</tt> for attempts
-   to use a file for which the error indicator (viz,
-   <tt class="computeroutput">ferror(f)</tt>) is set.  On
-   receipt of <tt class="computeroutput">BZ_IO_ERROR</tt>, the
-   caller should consult <tt class="computeroutput">errno</tt>
-   and/or <tt class="computeroutput">perror</tt> to acquire
-   operating-system specific information about the
-   problem.</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_UNEXPECTED_EOF</tt></span></dt>
-<dd><p>Returned by
-   <tt class="computeroutput">BZ2_bzRead</tt> when the
-   compressed file finishes before the logical end of stream is
-   detected.</p></dd>
-<dt><span class="term"><tt class="computeroutput">BZ_OUTBUFF_FULL</tt></span></dt>
-<dd><p>Returned by
-   <tt class="computeroutput">BZ2_bzBuffToBuffCompress</tt> and
-   <tt class="computeroutput">BZ2_bzBuffToBuffDecompress</tt> to
-   indicate that the output data will not fit into the output
-   buffer provided.</p></dd>
-</dl></div>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="low-level"></a>3.3. Low-level interface</h2></div></div>
-<div></div>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzcompress-init"></a>3.3.1. <tt class="computeroutput">BZ2_bzCompressInit</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">typedef struct {
-  char *next_in;
-  unsigned int avail_in;
-  unsigned int total_in_lo32;
-  unsigned int total_in_hi32;
-
-  char *next_out;
-  unsigned int avail_out;
-  unsigned int total_out_lo32;
-  unsigned int total_out_hi32;
-
-  void *state;
-
-  void *(*bzalloc)(void *,int,int);
-  void (*bzfree)(void *,void *);
-  void *opaque;
-} bz_stream;
-
-int BZ2_bzCompressInit ( bz_stream *strm, 
-                         int blockSize100k, 
-                         int verbosity,
-                         int workFactor );</pre>
-<p>Prepares for compression.  The
-<tt class="computeroutput">bz_stream</tt> structure holds all
-data pertaining to the compression activity.  A
-<tt class="computeroutput">bz_stream</tt> structure should be
-allocated and initialised prior to the call.  The fields of
-<tt class="computeroutput">bz_stream</tt> comprise the entirety
-of the user-visible data.  <tt class="computeroutput">state</tt>
-is a pointer to the private data structures required for
-compression.</p>
-<p>Custom memory allocators are supported, via fields
-<tt class="computeroutput">bzalloc</tt>,
-<tt class="computeroutput">bzfree</tt>, and
-<tt class="computeroutput">opaque</tt>.  The value
-<tt class="computeroutput">opaque</tt> is passed to as the first
-argument to all calls to <tt class="computeroutput">bzalloc</tt>
-and <tt class="computeroutput">bzfree</tt>, but is otherwise
-ignored by the library.  The call <tt class="computeroutput">bzalloc (
-opaque, n, m )</tt> is expected to return a pointer
-<tt class="computeroutput">p</tt> to <tt class="computeroutput">n *
-m</tt> bytes of memory, and <tt class="computeroutput">bzfree (
-opaque, p )</tt> should free that memory.</p>
-<p>If you don't want to use a custom memory allocator, set
-<tt class="computeroutput">bzalloc</tt>,
-<tt class="computeroutput">bzfree</tt> and
-<tt class="computeroutput">opaque</tt> to
-<tt class="computeroutput">NULL</tt>, and the library will then
-use the standard <tt class="computeroutput">malloc</tt> /
-<tt class="computeroutput">free</tt> routines.</p>
-<p>Before calling
-<tt class="computeroutput">BZ2_bzCompressInit</tt>, fields
-<tt class="computeroutput">bzalloc</tt>,
-<tt class="computeroutput">bzfree</tt> and
-<tt class="computeroutput">opaque</tt> should be filled
-appropriately, as just described.  Upon return, the internal
-state will have been allocated and initialised, and
-<tt class="computeroutput">total_in_lo32</tt>,
-<tt class="computeroutput">total_in_hi32</tt>,
-<tt class="computeroutput">total_out_lo32</tt> and
-<tt class="computeroutput">total_out_hi32</tt> will have been
-set to zero.  These four fields are used by the library to inform
-the caller of the total amount of data passed into and out of the
-library, respectively.  You should not try to change them.  As of
-version 1.0, 64-bit counts are maintained, even on 32-bit
-platforms, using the <tt class="computeroutput">_hi32</tt>
-fields to store the upper 32 bits of the count.  So, for example,
-the total amount of data in is <tt class="computeroutput">(total_in_hi32
-&lt;&lt; 32) + total_in_lo32</tt>.</p>
-<p>Parameter <tt class="computeroutput">blockSize100k</tt>
-specifies the block size to be used for compression.  It should
-be a value between 1 and 9 inclusive, and the actual block size
-used is 100000 x this figure.  9 gives the best compression but
-takes most memory.</p>
-<p>Parameter <tt class="computeroutput">verbosity</tt> should
-be set to a number between 0 and 4 inclusive.  0 is silent, and
-greater numbers give increasingly verbose monitoring/debugging
-output.  If the library has been compiled with
-<tt class="computeroutput">-DBZ_NO_STDIO</tt>, no such output
-will appear for any verbosity setting.</p>
-<p>Parameter <tt class="computeroutput">workFactor</tt>
-controls how the compression phase behaves when presented with
-worst case, highly repetitive, input data.  If compression runs
-into difficulties caused by repetitive data, the library switches
-from the standard sorting algorithm to a fallback algorithm.  The
-fallback is slower than the standard algorithm by perhaps a
-factor of three, but always behaves reasonably, no matter how bad
-the input.</p>
-<p>Lower values of <tt class="computeroutput">workFactor</tt>
-reduce the amount of effort the standard algorithm will expend
-before resorting to the fallback.  You should set this parameter
-carefully; too low, and many inputs will be handled by the
-fallback algorithm and so compress rather slowly, too high, and
-your average-to-worst case compression times can become very
-large.  The default value of 30 gives reasonable behaviour over a
-wide range of circumstances.</p>
-<p>Allowable values range from 0 to 250 inclusive.  0 is a
-special case, equivalent to using the default value of 30.</p>
-<p>Note that the compressed output generated is the same
-regardless of whether or not the fallback algorithm is
-used.</p>
-<p>Be aware also that this parameter may disappear entirely in
-future versions of the library.  In principle it should be
-possible to devise a good way to automatically choose which
-algorithm to use.  Such a mechanism would render the parameter
-obsolete.</p>
-<p>Possible return values:</p>
-<pre class="programlisting">BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if strm is NULL 
-  or blockSize &lt; 1 or blockSize &gt; 9
-  or verbosity &lt; 0 or verbosity &gt; 4
-  or workFactor &lt; 0 or workFactor &gt; 250
-BZ_MEM_ERROR 
-  if not enough memory is available
-BZ_OK 
-  otherwise</pre>
-<p>Allowable next actions:</p>
-<pre class="programlisting">BZ2_bzCompress
-  if BZ_OK is returned
-  no specific action needed in case of error</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzCompress"></a>3.3.2. <tt class="computeroutput">BZ2_bzCompress</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">int BZ2_bzCompress ( bz_stream *strm, int action );</pre>
-<p>Provides more input and/or output buffer space for the
-library.  The caller maintains input and output buffers, and
-calls <tt class="computeroutput">BZ2_bzCompress</tt> to transfer
-data between them.</p>
-<p>Before each call to
-<tt class="computeroutput">BZ2_bzCompress</tt>,
-<tt class="computeroutput">next_in</tt> should point at the data
-to be compressed, and <tt class="computeroutput">avail_in</tt>
-should indicate how many bytes the library may read.
-<tt class="computeroutput">BZ2_bzCompress</tt> updates
-<tt class="computeroutput">next_in</tt>,
-<tt class="computeroutput">avail_in</tt> and
-<tt class="computeroutput">total_in</tt> to reflect the number
-of bytes it has read.</p>
-<p>Similarly, <tt class="computeroutput">next_out</tt> should
-point to a buffer in which the compressed data is to be placed,
-with <tt class="computeroutput">avail_out</tt> indicating how
-much output space is available.
-<tt class="computeroutput">BZ2_bzCompress</tt> updates
-<tt class="computeroutput">next_out</tt>,
-<tt class="computeroutput">avail_out</tt> and
-<tt class="computeroutput">total_out</tt> to reflect the number
-of bytes output.</p>
-<p>You may provide and remove as little or as much data as you
-like on each call of
-<tt class="computeroutput">BZ2_bzCompress</tt>.  In the limit,
-it is acceptable to supply and remove data one byte at a time,
-although this would be terribly inefficient.  You should always
-ensure that at least one byte of output space is available at
-each call.</p>
-<p>A second purpose of
-<tt class="computeroutput">BZ2_bzCompress</tt> is to request a
-change of mode of the compressed stream.</p>
-<p>Conceptually, a compressed stream can be in one of four
-states: IDLE, RUNNING, FLUSHING and FINISHING.  Before
-initialisation
-(<tt class="computeroutput">BZ2_bzCompressInit</tt>) and after
-termination (<tt class="computeroutput">BZ2_bzCompressEnd</tt>),
-a stream is regarded as IDLE.</p>
-<p>Upon initialisation
-(<tt class="computeroutput">BZ2_bzCompressInit</tt>), the stream
-is placed in the RUNNING state.  Subsequent calls to
-<tt class="computeroutput">BZ2_bzCompress</tt> should pass
-<tt class="computeroutput">BZ_RUN</tt> as the requested action;
-other actions are illegal and will result in
-<tt class="computeroutput">BZ_SEQUENCE_ERROR</tt>.</p>
-<p>At some point, the calling program will have provided all
-the input data it wants to.  It will then want to finish up -- in
-effect, asking the library to process any data it might have
-buffered internally.  In this state,
-<tt class="computeroutput">BZ2_bzCompress</tt> will no longer
-attempt to read data from
-<tt class="computeroutput">next_in</tt>, but it will want to
-write data to <tt class="computeroutput">next_out</tt>.  Because
-the output buffer supplied by the user can be arbitrarily small,
-the finishing-up operation cannot necessarily be done with a
-single call of
-<tt class="computeroutput">BZ2_bzCompress</tt>.</p>
-<p>Instead, the calling program passes
-<tt class="computeroutput">BZ_FINISH</tt> as an action to
-<tt class="computeroutput">BZ2_bzCompress</tt>.  This changes
-the stream's state to FINISHING.  Any remaining input (ie,
-<tt class="computeroutput">next_in[0 .. avail_in-1]</tt>) is
-compressed and transferred to the output buffer.  To do this,
-<tt class="computeroutput">BZ2_bzCompress</tt> must be called
-repeatedly until all the output has been consumed.  At that
-point, <tt class="computeroutput">BZ2_bzCompress</tt> returns
-<tt class="computeroutput">BZ_STREAM_END</tt>, and the stream's
-state is set back to IDLE.
-<tt class="computeroutput">BZ2_bzCompressEnd</tt> should then be
-called.</p>
-<p>Just to make sure the calling program does not cheat, the
-library makes a note of <tt class="computeroutput">avail_in</tt>
-at the time of the first call to
-<tt class="computeroutput">BZ2_bzCompress</tt> which has
-<tt class="computeroutput">BZ_FINISH</tt> as an action (ie, at
-the time the program has announced its intention to not supply
-any more input).  By comparing this value with that of
-<tt class="computeroutput">avail_in</tt> over subsequent calls
-to <tt class="computeroutput">BZ2_bzCompress</tt>, the library
-can detect any attempts to slip in more data to compress.  Any
-calls for which this is detected will return
-<tt class="computeroutput">BZ_SEQUENCE_ERROR</tt>.  This
-indicates a programming mistake which should be corrected.</p>
-<p>Instead of asking to finish, the calling program may ask
-<tt class="computeroutput">BZ2_bzCompress</tt> to take all the
-remaining input, compress it and terminate the current
-(Burrows-Wheeler) compression block.  This could be useful for
-error control purposes.  The mechanism is analogous to that for
-finishing: call <tt class="computeroutput">BZ2_bzCompress</tt>
-with an action of <tt class="computeroutput">BZ_FLUSH</tt>,
-remove output data, and persist with the
-<tt class="computeroutput">BZ_FLUSH</tt> action until the value
-<tt class="computeroutput">BZ_RUN</tt> is returned.  As with
-finishing, <tt class="computeroutput">BZ2_bzCompress</tt>
-detects any attempt to provide more input data once the flush has
-begun.</p>
-<p>Once the flush is complete, the stream returns to the
-normal RUNNING state.</p>
-<p>This all sounds pretty complex, but isn't really.  Here's a
-table which shows which actions are allowable in each state, what
-action will be taken, what the next state is, and what the
-non-error return values are.  Note that you can't explicitly ask
-what state the stream is in, but nor do you need to -- it can be
-inferred from the values returned by
-<tt class="computeroutput">BZ2_bzCompress</tt>.</p>
-<pre class="programlisting">IDLE/any
-  Illegal.  IDLE state only exists after BZ2_bzCompressEnd or
-  before BZ2_bzCompressInit.
-  Return value = BZ_SEQUENCE_ERROR
-
-RUNNING/BZ_RUN
-  Compress from next_in to next_out as much as possible.
-  Next state = RUNNING
-  Return value = BZ_RUN_OK
-
-RUNNING/BZ_FLUSH
-  Remember current value of next_in. Compress from next_in
-  to next_out as much as possible, but do not accept any more input.
-  Next state = FLUSHING
-  Return value = BZ_FLUSH_OK
-
-RUNNING/BZ_FINISH
-  Remember current value of next_in. Compress from next_in
-  to next_out as much as possible, but do not accept any more input.
-  Next state = FINISHING
-  Return value = BZ_FINISH_OK
-
-FLUSHING/BZ_FLUSH
-  Compress from next_in to next_out as much as possible, 
-  but do not accept any more input.
-  If all the existing input has been used up and all compressed
-  output has been removed
-    Next state = RUNNING; Return value = BZ_RUN_OK
-  else
-    Next state = FLUSHING; Return value = BZ_FLUSH_OK
-
-FLUSHING/other     
-  Illegal.
-  Return value = BZ_SEQUENCE_ERROR
-
-FINISHING/BZ_FINISH
-  Compress from next_in to next_out as much as possible,
-  but to not accept any more input.  
-  If all the existing input has been used up and all compressed
-  output has been removed
-    Next state = IDLE; Return value = BZ_STREAM_END
-  else
-    Next state = FINISHING; Return value = BZ_FINISHING
-
-FINISHING/other
-  Illegal.
-  Return value = BZ_SEQUENCE_ERROR</pre>
-<p>That still looks complicated?  Well, fair enough.  The
-usual sequence of calls for compressing a load of data is:</p>
-<div class="orderedlist"><ol type="1">
-<li><p>Get started with
-  <tt class="computeroutput">BZ2_bzCompressInit</tt>.</p></li>
-<li><p>Shovel data in and shlurp out its compressed form
-  using zero or more calls of
-  <tt class="computeroutput">BZ2_bzCompress</tt> with action =
-  <tt class="computeroutput">BZ_RUN</tt>.</p></li>
-<li><p>Finish up. Repeatedly call
-  <tt class="computeroutput">BZ2_bzCompress</tt> with action =
-  <tt class="computeroutput">BZ_FINISH</tt>, copying out the
-  compressed output, until
-  <tt class="computeroutput">BZ_STREAM_END</tt> is
-  returned.</p></li>
-<li><p>Close up and go home.  Call
-  <tt class="computeroutput">BZ2_bzCompressEnd</tt>.</p></li>
-</ol></div>
-<p>If the data you want to compress fits into your input
-buffer all at once, you can skip the calls of
-<tt class="computeroutput">BZ2_bzCompress ( ..., BZ_RUN )</tt>
-and just do the <tt class="computeroutput">BZ2_bzCompress ( ..., BZ_FINISH
-)</tt> calls.</p>
-<p>All required memory is allocated by
-<tt class="computeroutput">BZ2_bzCompressInit</tt>.  The
-compression library can accept any data at all (obviously).  So
-you shouldn't get any error return values from the
-<tt class="computeroutput">BZ2_bzCompress</tt> calls.  If you
-do, they will be
-<tt class="computeroutput">BZ_SEQUENCE_ERROR</tt>, and indicate
-a bug in your programming.</p>
-<p>Trivial other possible return values:</p>
-<pre class="programlisting">BZ_PARAM_ERROR
-  if strm is NULL, or strm-&gt;s is NULL</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzCompress-end"></a>3.3.3. <tt class="computeroutput">BZ2_bzCompressEnd</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">int BZ2_bzCompressEnd ( bz_stream *strm );</pre>
-<p>Releases all memory associated with a compression
-stream.</p>
-<p>Possible return values:</p>
-<pre class="programlisting">BZ_PARAM_ERROR  if strm is NULL or strm-&gt;s is NULL
-BZ_OK           otherwise</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzDecompress-init"></a>3.3.4. <tt class="computeroutput">BZ2_bzDecompressInit</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">int BZ2_bzDecompressInit ( bz_stream *strm, int verbosity, int small );</pre>
-<p>Prepares for decompression.  As with
-<tt class="computeroutput">BZ2_bzCompressInit</tt>, a
-<tt class="computeroutput">bz_stream</tt> record should be
-allocated and initialised before the call.  Fields
-<tt class="computeroutput">bzalloc</tt>,
-<tt class="computeroutput">bzfree</tt> and
-<tt class="computeroutput">opaque</tt> should be set if a custom
-memory allocator is required, or made
-<tt class="computeroutput">NULL</tt> for the normal
-<tt class="computeroutput">malloc</tt> /
-<tt class="computeroutput">free</tt> routines.  Upon return, the
-internal state will have been initialised, and
-<tt class="computeroutput">total_in</tt> and
-<tt class="computeroutput">total_out</tt> will be zero.</p>
-<p>For the meaning of parameter
-<tt class="computeroutput">verbosity</tt>, see
-<tt class="computeroutput">BZ2_bzCompressInit</tt>.</p>
-<p>If <tt class="computeroutput">small</tt> is nonzero, the
-library will use an alternative decompression algorithm which
-uses less memory but at the cost of decompressing more slowly
-(roughly speaking, half the speed, but the maximum memory
-requirement drops to around 2300k).  See <a href="#using">How to use bzip2</a>
-for more information on memory management.</p>
-<p>Note that the amount of memory needed to decompress a
-stream cannot be determined until the stream's header has been
-read, so even if
-<tt class="computeroutput">BZ2_bzDecompressInit</tt> succeeds, a
-subsequent <tt class="computeroutput">BZ2_bzDecompress</tt>
-could fail with
-<tt class="computeroutput">BZ_MEM_ERROR</tt>.</p>
-<p>Possible return values:</p>
-<pre class="programlisting">BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if ( small != 0 &amp;&amp; small != 1 )
-  or (verbosity &lt;; 0 || verbosity &gt; 4)
-BZ_MEM_ERROR
-  if insufficient memory is available</pre>
-<p>Allowable next actions:</p>
-<pre class="programlisting">BZ2_bzDecompress
-  if BZ_OK was returned
-  no specific action required in case of error</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzDecompress"></a>3.3.5. <tt class="computeroutput">BZ2_bzDecompress</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">int BZ2_bzDecompress ( bz_stream *strm );</pre>
-<p>Provides more input and/out output buffer space for the
-library.  The caller maintains input and output buffers, and uses
-<tt class="computeroutput">BZ2_bzDecompress</tt> to transfer
-data between them.</p>
-<p>Before each call to
-<tt class="computeroutput">BZ2_bzDecompress</tt>,
-<tt class="computeroutput">next_in</tt> should point at the
-compressed data, and <tt class="computeroutput">avail_in</tt>
-should indicate how many bytes the library may read.
-<tt class="computeroutput">BZ2_bzDecompress</tt> updates
-<tt class="computeroutput">next_in</tt>,
-<tt class="computeroutput">avail_in</tt> and
-<tt class="computeroutput">total_in</tt> to reflect the number
-of bytes it has read.</p>
-<p>Similarly, <tt class="computeroutput">next_out</tt> should
-point to a buffer in which the uncompressed output is to be
-placed, with <tt class="computeroutput">avail_out</tt>
-indicating how much output space is available.
-<tt class="computeroutput">BZ2_bzCompress</tt> updates
-<tt class="computeroutput">next_out</tt>,
-<tt class="computeroutput">avail_out</tt> and
-<tt class="computeroutput">total_out</tt> to reflect the number
-of bytes output.</p>
-<p>You may provide and remove as little or as much data as you
-like on each call of
-<tt class="computeroutput">BZ2_bzDecompress</tt>.  In the limit,
-it is acceptable to supply and remove data one byte at a time,
-although this would be terribly inefficient.  You should always
-ensure that at least one byte of output space is available at
-each call.</p>
-<p>Use of <tt class="computeroutput">BZ2_bzDecompress</tt> is
-simpler than
-<tt class="computeroutput">BZ2_bzCompress</tt>.</p>
-<p>You should provide input and remove output as described
-above, and repeatedly call
-<tt class="computeroutput">BZ2_bzDecompress</tt> until
-<tt class="computeroutput">BZ_STREAM_END</tt> is returned.
-Appearance of <tt class="computeroutput">BZ_STREAM_END</tt>
-denotes that <tt class="computeroutput">BZ2_bzDecompress</tt>
-has detected the logical end of the compressed stream.
-<tt class="computeroutput">BZ2_bzDecompress</tt> will not
-produce <tt class="computeroutput">BZ_STREAM_END</tt> until all
-output data has been placed into the output buffer, so once
-<tt class="computeroutput">BZ_STREAM_END</tt> appears, you are
-guaranteed to have available all the decompressed output, and
-<tt class="computeroutput">BZ2_bzDecompressEnd</tt> can safely
-be called.</p>
-<p>If case of an error return value, you should call
-<tt class="computeroutput">BZ2_bzDecompressEnd</tt> to clean up
-and release memory.</p>
-<p>Possible return values:</p>
-<pre class="programlisting">BZ_PARAM_ERROR
-  if strm is NULL or strm-&gt;s is NULL
-  or strm-&gt;avail_out &lt; 1
-BZ_DATA_ERROR
-  if a data integrity error is detected in the compressed stream
-BZ_DATA_ERROR_MAGIC
-  if the compressed stream doesn't begin with the right magic bytes
-BZ_MEM_ERROR
-  if there wasn't enough memory available
-BZ_STREAM_END
-  if the logical end of the data stream was detected and all
-  output in has been consumed, eg s--&gt;avail_out &gt; 0
-BZ_OK
-  otherwise</pre>
-<p>Allowable next actions:</p>
-<pre class="programlisting">BZ2_bzDecompress
-  if BZ_OK was returned
-BZ2_bzDecompressEnd
-  otherwise</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzDecompress-end"></a>3.3.6. <tt class="computeroutput">BZ2_bzDecompressEnd</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">int BZ2_bzDecompressEnd ( bz_stream *strm );</pre>
-<p>Releases all memory associated with a decompression
-stream.</p>
-<p>Possible return values:</p>
-<pre class="programlisting">BZ_PARAM_ERROR
-  if strm is NULL or strm-&gt;s is NULL
-BZ_OK
-  otherwise</pre>
-<p>Allowable next actions:</p>
-<pre class="programlisting">  None.</pre>
-</div>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="hl-interface"></a>3.4. High-level interface</h2></div></div>
-<div></div>
-</div>
-<p>This interface provides functions for reading and writing
-<tt class="computeroutput">bzip2</tt> format files.  First, some
-general points.</p>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc"><p>All of the functions take an
-  <tt class="computeroutput">int*</tt> first argument,
-  <tt class="computeroutput">bzerror</tt>.  After each call,
-  <tt class="computeroutput">bzerror</tt> should be consulted
-  first to determine the outcome of the call.  If
-  <tt class="computeroutput">bzerror</tt> is
-  <tt class="computeroutput">BZ_OK</tt>, the call completed
-  successfully, and only then should the return value of the
-  function (if any) be consulted.  If
-  <tt class="computeroutput">bzerror</tt> is
-  <tt class="computeroutput">BZ_IO_ERROR</tt>, there was an
-  error reading/writing the underlying compressed file, and you
-  should then consult <tt class="computeroutput">errno</tt> /
-  <tt class="computeroutput">perror</tt> to determine the cause
-  of the difficulty.  <tt class="computeroutput">bzerror</tt>
-  may also be set to various other values; precise details are
-  given on a per-function basis below.</p></li>
-<li style="list-style-type: disc"><p>If <tt class="computeroutput">bzerror</tt> indicates
-  an error (ie, anything except
-  <tt class="computeroutput">BZ_OK</tt> and
-  <tt class="computeroutput">BZ_STREAM_END</tt>), you should
-  immediately call
-  <tt class="computeroutput">BZ2_bzReadClose</tt> (or
-  <tt class="computeroutput">BZ2_bzWriteClose</tt>, depending on
-  whether you are attempting to read or to write) to free up all
-  resources associated with the stream.  Once an error has been
-  indicated, behaviour of all calls except
-  <tt class="computeroutput">BZ2_bzReadClose</tt>
-  (<tt class="computeroutput">BZ2_bzWriteClose</tt>) is
-  undefined.  The implication is that (1)
-  <tt class="computeroutput">bzerror</tt> should be checked
-  after each call, and (2) if
-  <tt class="computeroutput">bzerror</tt> indicates an error,
-  <tt class="computeroutput">BZ2_bzReadClose</tt>
-  (<tt class="computeroutput">BZ2_bzWriteClose</tt>) should then
-  be called to clean up.</p></li>
-<li style="list-style-type: disc"><p>The <tt class="computeroutput">FILE*</tt> arguments
-  passed to <tt class="computeroutput">BZ2_bzReadOpen</tt> /
-  <tt class="computeroutput">BZ2_bzWriteOpen</tt> should be set
-  to binary mode.  Most Unix systems will do this by default, but
-  other platforms, including Windows and Mac, will not.  If you
-  omit this, you may encounter problems when moving code to new
-  platforms.</p></li>
-<li style="list-style-type: disc"><p>Memory allocation requests are handled by
-  <tt class="computeroutput">malloc</tt> /
-  <tt class="computeroutput">free</tt>.  At present there is no
-  facility for user-defined memory allocators in the file I/O
-  functions (could easily be added, though).</p></li>
-</ul></div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzreadopen"></a>3.4.1. <tt class="computeroutput">BZ2_bzReadOpen</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">typedef void BZFILE;
-
-BZFILE *BZ2_bzReadOpen( int *bzerror, FILE *f, 
-                        int verbosity, int small,
-                        void *unused, int nUnused );</pre>
-<p>Prepare to read compressed data from file handle
-<tt class="computeroutput">f</tt>.
-<tt class="computeroutput">f</tt> should refer to a file which
-has been opened for reading, and for which the error indicator
-(<tt class="computeroutput">ferror(f)</tt>)is not set.  If
-<tt class="computeroutput">small</tt> is 1, the library will try
-to decompress using less memory, at the expense of speed.</p>
-<p>For reasons explained below,
-<tt class="computeroutput">BZ2_bzRead</tt> will decompress the
-<tt class="computeroutput">nUnused</tt> bytes starting at
-<tt class="computeroutput">unused</tt>, before starting to read
-from the file <tt class="computeroutput">f</tt>.  At most
-<tt class="computeroutput">BZ_MAX_UNUSED</tt> bytes may be
-supplied like this.  If this facility is not required, you should
-pass <tt class="computeroutput">NULL</tt> and
-<tt class="computeroutput">0</tt> for
-<tt class="computeroutput">unused</tt> and
-n<tt class="computeroutput">Unused</tt> respectively.</p>
-<p>For the meaning of parameters
-<tt class="computeroutput">small</tt> and
-<tt class="computeroutput">verbosity</tt>, see
-<tt class="computeroutput">BZ2_bzDecompressInit</tt>.</p>
-<p>The amount of memory needed to decompress a file cannot be
-determined until the file's header has been read.  So it is
-possible that <tt class="computeroutput">BZ2_bzReadOpen</tt>
-returns <tt class="computeroutput">BZ_OK</tt> but a subsequent
-call of <tt class="computeroutput">BZ2_bzRead</tt> will return
-<tt class="computeroutput">BZ_MEM_ERROR</tt>.</p>
-<p>Possible assignments to
-<tt class="computeroutput">bzerror</tt>:</p>
-<pre class="programlisting">BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if f is NULL
-  or small is neither 0 nor 1
-  or ( unused == NULL &amp;&amp; nUnused != 0 )
-  or ( unused != NULL &amp;&amp; !(0 &lt;= nUnused &lt;= BZ_MAX_UNUSED) )
-BZ_IO_ERROR
-  if ferror(f) is nonzero
-BZ_MEM_ERROR
-  if insufficient memory is available
-BZ_OK
-  otherwise.</pre>
-<p>Possible return values:</p>
-<pre class="programlisting">Pointer to an abstract BZFILE
-  if bzerror is BZ_OK
-NULL
-  otherwise</pre>
-<p>Allowable next actions:</p>
-<pre class="programlisting">BZ2_bzRead
-  if bzerror is BZ_OK
-BZ2_bzClose
-  otherwise</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzread"></a>3.4.2. <tt class="computeroutput">BZ2_bzRead</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">int BZ2_bzRead ( int *bzerror, BZFILE *b, void *buf, int len );</pre>
-<p>Reads up to <tt class="computeroutput">len</tt>
-(uncompressed) bytes from the compressed file
-<tt class="computeroutput">b</tt> into the buffer
-<tt class="computeroutput">buf</tt>.  If the read was
-successful, <tt class="computeroutput">bzerror</tt> is set to
-<tt class="computeroutput">BZ_OK</tt> and the number of bytes
-read is returned.  If the logical end-of-stream was detected,
-<tt class="computeroutput">bzerror</tt> will be set to
-<tt class="computeroutput">BZ_STREAM_END</tt>, and the number of
-bytes read is returned.  All other
-<tt class="computeroutput">bzerror</tt> values denote an
-error.</p>
-<p><tt class="computeroutput">BZ2_bzRead</tt> will supply
-<tt class="computeroutput">len</tt> bytes, unless the logical
-stream end is detected or an error occurs.  Because of this, it
-is possible to detect the stream end by observing when the number
-of bytes returned is less than the number requested.
-Nevertheless, this is regarded as inadvisable; you should instead
-check <tt class="computeroutput">bzerror</tt> after every call
-and watch out for
-<tt class="computeroutput">BZ_STREAM_END</tt>.</p>
-<p>Internally, <tt class="computeroutput">BZ2_bzRead</tt>
-copies data from the compressed file in chunks of size
-<tt class="computeroutput">BZ_MAX_UNUSED</tt> bytes before
-decompressing it.  If the file contains more bytes than strictly
-needed to reach the logical end-of-stream,
-<tt class="computeroutput">BZ2_bzRead</tt> will almost certainly
-read some of the trailing data before signalling
-<tt class="computeroutput">BZ_SEQUENCE_END</tt>.  To collect the
-read but unused data once
-<tt class="computeroutput">BZ_SEQUENCE_END</tt> has appeared,
-call <tt class="computeroutput">BZ2_bzReadGetUnused</tt>
-immediately before
-<tt class="computeroutput">BZ2_bzReadClose</tt>.</p>
-<p>Possible assignments to
-<tt class="computeroutput">bzerror</tt>:</p>
-<pre class="programlisting">BZ_PARAM_ERROR
-  if b is NULL or buf is NULL or len &lt; 0
-BZ_SEQUENCE_ERROR
-  if b was opened with BZ2_bzWriteOpen
-BZ_IO_ERROR
-  if there is an error reading from the compressed file
-BZ_UNEXPECTED_EOF
-  if the compressed file ended before 
-  the logical end-of-stream was detected
-BZ_DATA_ERROR
-  if a data integrity error was detected in the compressed stream
-BZ_DATA_ERROR_MAGIC
-  if the stream does not begin with the requisite header bytes 
-  (ie, is not a bzip2 data file).  This is really 
-  a special case of BZ_DATA_ERROR.
-BZ_MEM_ERROR
-  if insufficient memory was available
-BZ_STREAM_END
-  if the logical end of stream was detected.
-BZ_OK
-  otherwise.</pre>
-<p>Possible return values:</p>
-<pre class="programlisting">number of bytes read
-  if bzerror is BZ_OK or BZ_STREAM_END
-undefined
-  otherwise</pre>
-<p>Allowable next actions:</p>
-<pre class="programlisting">collect data from buf, then BZ2_bzRead or BZ2_bzReadClose
-  if bzerror is BZ_OK
-collect data from buf, then BZ2_bzReadClose or BZ2_bzReadGetUnused
-  if bzerror is BZ_SEQUENCE_END
-BZ2_bzReadClose
-  otherwise</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzreadgetunused"></a>3.4.3. <tt class="computeroutput">BZ2_bzReadGetUnused</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">void BZ2_bzReadGetUnused( int* bzerror, BZFILE *b, 
-                          void** unused, int* nUnused );</pre>
-<p>Returns data which was read from the compressed file but
-was not needed to get to the logical end-of-stream.
-<tt class="computeroutput">*unused</tt> is set to the address of
-the data, and <tt class="computeroutput">*nUnused</tt> to the
-number of bytes.  <tt class="computeroutput">*nUnused</tt> will
-be set to a value between <tt class="computeroutput">0</tt> and
-<tt class="computeroutput">BZ_MAX_UNUSED</tt> inclusive.</p>
-<p>This function may only be called once
-<tt class="computeroutput">BZ2_bzRead</tt> has signalled
-<tt class="computeroutput">BZ_STREAM_END</tt> but before
-<tt class="computeroutput">BZ2_bzReadClose</tt>.</p>
-<p>Possible assignments to
-<tt class="computeroutput">bzerror</tt>:</p>
-<pre class="programlisting">BZ_PARAM_ERROR
-  if b is NULL
-  or unused is NULL or nUnused is NULL
-BZ_SEQUENCE_ERROR
-  if BZ_STREAM_END has not been signalled
-  or if b was opened with BZ2_bzWriteOpen
-BZ_OK
-  otherwise</pre>
-<p>Allowable next actions:</p>
-<pre class="programlisting">BZ2_bzReadClose</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzreadclose"></a>3.4.4. <tt class="computeroutput">BZ2_bzReadClose</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">void BZ2_bzReadClose ( int *bzerror, BZFILE *b );</pre>
-<p>Releases all memory pertaining to the compressed file
-<tt class="computeroutput">b</tt>.
-<tt class="computeroutput">BZ2_bzReadClose</tt> does not call
-<tt class="computeroutput">fclose</tt> on the underlying file
-handle, so you should do that yourself if appropriate.
-<tt class="computeroutput">BZ2_bzReadClose</tt> should be called
-to clean up after all error situations.</p>
-<p>Possible assignments to
-<tt class="computeroutput">bzerror</tt>:</p>
-<pre class="programlisting">BZ_SEQUENCE_ERROR
-  if b was opened with BZ2_bzOpenWrite
-BZ_OK
-  otherwise</pre>
-<p>Allowable next actions:</p>
-<pre class="programlisting">none</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzwriteopen"></a>3.4.5. <tt class="computeroutput">BZ2_bzWriteOpen</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">BZFILE *BZ2_bzWriteOpen( int *bzerror, FILE *f, 
-                         int blockSize100k, int verbosity,
-                         int workFactor );</pre>
-<p>Prepare to write compressed data to file handle
-<tt class="computeroutput">f</tt>.
-<tt class="computeroutput">f</tt> should refer to a file which
-has been opened for writing, and for which the error indicator
-(<tt class="computeroutput">ferror(f)</tt>)is not set.</p>
-<p>For the meaning of parameters
-<tt class="computeroutput">blockSize100k</tt>,
-<tt class="computeroutput">verbosity</tt> and
-<tt class="computeroutput">workFactor</tt>, see
-<tt class="computeroutput">BZ2_bzCompressInit</tt>.</p>
-<p>All required memory is allocated at this stage, so if the
-call completes successfully,
-<tt class="computeroutput">BZ_MEM_ERROR</tt> cannot be signalled
-by a subsequent call to
-<tt class="computeroutput">BZ2_bzWrite</tt>.</p>
-<p>Possible assignments to
-<tt class="computeroutput">bzerror</tt>:</p>
-<pre class="programlisting">BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if f is NULL
-  or blockSize100k &lt; 1 or blockSize100k &gt; 9
-BZ_IO_ERROR
-  if ferror(f) is nonzero
-BZ_MEM_ERROR
-  if insufficient memory is available
-BZ_OK
-  otherwise</pre>
-<p>Possible return values:</p>
-<pre class="programlisting">Pointer to an abstract BZFILE
-  if bzerror is BZ_OK
-NULL
-  otherwise</pre>
-<p>Allowable next actions:</p>
-<pre class="programlisting">BZ2_bzWrite
-  if bzerror is BZ_OK
-  (you could go directly to BZ2_bzWriteClose, but this would be pretty pointless)
-BZ2_bzWriteClose
-  otherwise</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzwrite"></a>3.4.6. <tt class="computeroutput">BZ2_bzWrite</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">void BZ2_bzWrite ( int *bzerror, BZFILE *b, void *buf, int len );</pre>
-<p>Absorbs <tt class="computeroutput">len</tt> bytes from the
-buffer <tt class="computeroutput">buf</tt>, eventually to be
-compressed and written to the file.</p>
-<p>Possible assignments to
-<tt class="computeroutput">bzerror</tt>:</p>
-<pre class="programlisting">BZ_PARAM_ERROR
-  if b is NULL or buf is NULL or len &lt; 0
-BZ_SEQUENCE_ERROR
-  if b was opened with BZ2_bzReadOpen
-BZ_IO_ERROR
-  if there is an error writing the compressed file.
-BZ_OK
-  otherwise</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzwriteclose"></a>3.4.7. <tt class="computeroutput">BZ2_bzWriteClose</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">void BZ2_bzWriteClose( int *bzerror, BZFILE* f,
-                       int abandon,
-                       unsigned int* nbytes_in,
-                       unsigned int* nbytes_out );
-
-void BZ2_bzWriteClose64( int *bzerror, BZFILE* f,
-                         int abandon,
-                         unsigned int* nbytes_in_lo32,
-                         unsigned int* nbytes_in_hi32,
-                         unsigned int* nbytes_out_lo32,
-                         unsigned int* nbytes_out_hi32 );</pre>
-<p>Compresses and flushes to the compressed file all data so
-far supplied by <tt class="computeroutput">BZ2_bzWrite</tt>.
-The logical end-of-stream markers are also written, so subsequent
-calls to <tt class="computeroutput">BZ2_bzWrite</tt> are
-illegal.  All memory associated with the compressed file
-<tt class="computeroutput">b</tt> is released.
-<tt class="computeroutput">fflush</tt> is called on the
-compressed file, but it is not
-<tt class="computeroutput">fclose</tt>'d.</p>
-<p>If <tt class="computeroutput">BZ2_bzWriteClose</tt> is
-called to clean up after an error, the only action is to release
-the memory.  The library records the error codes issued by
-previous calls, so this situation will be detected automatically.
-There is no attempt to complete the compression operation, nor to
-<tt class="computeroutput">fflush</tt> the compressed file.  You
-can force this behaviour to happen even in the case of no error,
-by passing a nonzero value to
-<tt class="computeroutput">abandon</tt>.</p>
-<p>If <tt class="computeroutput">nbytes_in</tt> is non-null,
-<tt class="computeroutput">*nbytes_in</tt> will be set to be the
-total volume of uncompressed data handled.  Similarly,
-<tt class="computeroutput">nbytes_out</tt> will be set to the
-total volume of compressed data written.  For compatibility with
-older versions of the library,
-<tt class="computeroutput">BZ2_bzWriteClose</tt> only yields the
-lower 32 bits of these counts.  Use
-<tt class="computeroutput">BZ2_bzWriteClose64</tt> if you want
-the full 64 bit counts.  These two functions are otherwise
-absolutely identical.</p>
-<p>Possible assignments to
-<tt class="computeroutput">bzerror</tt>:</p>
-<pre class="programlisting">BZ_SEQUENCE_ERROR
-  if b was opened with BZ2_bzReadOpen
-BZ_IO_ERROR
-  if there is an error writing the compressed file
-BZ_OK
-  otherwise</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="embed"></a>3.4.8. Handling embedded compressed data streams</h3></div></div>
-<div></div>
-</div>
-<p>The high-level library facilitates use of
-<tt class="computeroutput">bzip2</tt> data streams which form
-some part of a surrounding, larger data stream.</p>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc"><p>For writing, the library takes an open file handle,
-  writes compressed data to it,
-  <tt class="computeroutput">fflush</tt>es it but does not
-  <tt class="computeroutput">fclose</tt> it.  The calling
-  application can write its own data before and after the
-  compressed data stream, using that same file handle.</p></li>
-<li style="list-style-type: disc"><p>Reading is more complex, and the facilities are not as
-  general as they could be since generality is hard to reconcile
-  with efficiency.  <tt class="computeroutput">BZ2_bzRead</tt>
-  reads from the compressed file in blocks of size
-  <tt class="computeroutput">BZ_MAX_UNUSED</tt> bytes, and in
-  doing so probably will overshoot the logical end of compressed
-  stream.  To recover this data once decompression has ended,
-  call <tt class="computeroutput">BZ2_bzReadGetUnused</tt> after
-  the last call of <tt class="computeroutput">BZ2_bzRead</tt>
-  (the one returning
-  <tt class="computeroutput">BZ_STREAM_END</tt>) but before
-  calling
-  <tt class="computeroutput">BZ2_bzReadClose</tt>.</p></li>
-</ul></div>
-<p>This mechanism makes it easy to decompress multiple
-<tt class="computeroutput">bzip2</tt> streams placed end-to-end.
-As the end of one stream, when
-<tt class="computeroutput">BZ2_bzRead</tt> returns
-<tt class="computeroutput">BZ_STREAM_END</tt>, call
-<tt class="computeroutput">BZ2_bzReadGetUnused</tt> to collect
-the unused data (copy it into your own buffer somewhere).  That
-data forms the start of the next compressed stream.  To start
-uncompressing that next stream, call
-<tt class="computeroutput">BZ2_bzReadOpen</tt> again, feeding in
-the unused data via the <tt class="computeroutput">unused</tt> /
-<tt class="computeroutput">nUnused</tt> parameters.  Keep doing
-this until <tt class="computeroutput">BZ_STREAM_END</tt> return
-coincides with the physical end of file
-(<tt class="computeroutput">feof(f)</tt>).  In this situation
-<tt class="computeroutput">BZ2_bzReadGetUnused</tt> will of
-course return no data.</p>
-<p>This should give some feel for how the high-level interface
-can be used.  If you require extra flexibility, you'll have to
-bite the bullet and get to grips with the low-level
-interface.</p>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="std-rdwr"></a>3.4.9. Standard file-reading/writing code</h3></div></div>
-<div></div>
-</div>
-<p>Here's how you'd write data to a compressed file:</p>
-<pre class="programlisting">FILE*   f;
-BZFILE* b;
-int     nBuf;
-char    buf[ /* whatever size you like */ ];
-int     bzerror;
-int     nWritten;
-
-f = fopen ( "myfile.bz2", "w" );
-if ( !f ) {
- /* handle error */
-}
-b = BZ2_bzWriteOpen( &amp;bzerror, f, 9 );
-if (bzerror != BZ_OK) {
- BZ2_bzWriteClose ( b );
- /* handle error */
-}
-
-while ( /* condition */ ) {
- /* get data to write into buf, and set nBuf appropriately */
- nWritten = BZ2_bzWrite ( &amp;bzerror, b, buf, nBuf );
- if (bzerror == BZ_IO_ERROR) { 
-   BZ2_bzWriteClose ( &amp;bzerror, b );
-   /* handle error */
- }
-}
-
-BZ2_bzWriteClose( &amp;bzerror, b );
-if (bzerror == BZ_IO_ERROR) {
- /* handle error */
-}</pre>
-<p>And to read from a compressed file:</p>
-<pre class="programlisting">FILE*   f;
-BZFILE* b;
-int     nBuf;
-char    buf[ /* whatever size you like */ ];
-int     bzerror;
-int     nWritten;
-
-f = fopen ( "myfile.bz2", "r" );
-if ( !f ) {
-  /* handle error */
-}
-b = BZ2_bzReadOpen ( &amp;bzerror, f, 0, NULL, 0 );
-if ( bzerror != BZ_OK ) {
-  BZ2_bzReadClose ( &amp;bzerror, b );
-  /* handle error */
-}
-
-bzerror = BZ_OK;
-while ( bzerror == BZ_OK &amp;&amp; /* arbitrary other conditions */) {
-  nBuf = BZ2_bzRead ( &amp;bzerror, b, buf, /* size of buf */ );
-  if ( bzerror == BZ_OK ) {
-    /* do something with buf[0 .. nBuf-1] */
-  }
-}
-if ( bzerror != BZ_STREAM_END ) {
-   BZ2_bzReadClose ( &amp;bzerror, b );
-   /* handle error */
-} else {
-   BZ2_bzReadClose ( &amp;bzerror );
-}</pre>
-</div>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="util-fns"></a>3.5. Utility functions</h2></div></div>
-<div></div>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzbufftobuffcompress"></a>3.5.1. <tt class="computeroutput">BZ2_bzBuffToBuffCompress</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">int BZ2_bzBuffToBuffCompress( char*         dest,
-                              unsigned int* destLen,
-                              char*         source,
-                              unsigned int  sourceLen,
-                              int           blockSize100k,
-                              int           verbosity,
-                              int           workFactor );</pre>
-<p>Attempts to compress the data in <tt class="computeroutput">source[0
-.. sourceLen-1]</tt> into the destination buffer,
-<tt class="computeroutput">dest[0 .. *destLen-1]</tt>.  If the
-destination buffer is big enough,
-<tt class="computeroutput">*destLen</tt> is set to the size of
-the compressed data, and <tt class="computeroutput">BZ_OK</tt>
-is returned.  If the compressed data won't fit,
-<tt class="computeroutput">*destLen</tt> is unchanged, and
-<tt class="computeroutput">BZ_OUTBUFF_FULL</tt> is
-returned.</p>
-<p>Compression in this manner is a one-shot event, done with a
-single call to this function.  The resulting compressed data is a
-complete <tt class="computeroutput">bzip2</tt> format data
-stream.  There is no mechanism for making additional calls to
-provide extra input data.  If you want that kind of mechanism,
-use the low-level interface.</p>
-<p>For the meaning of parameters
-<tt class="computeroutput">blockSize100k</tt>,
-<tt class="computeroutput">verbosity</tt> and
-<tt class="computeroutput">workFactor</tt>, see
-<tt class="computeroutput">BZ2_bzCompressInit</tt>.</p>
-<p>To guarantee that the compressed data will fit in its
-buffer, allocate an output buffer of size 1% larger than the
-uncompressed data, plus six hundred extra bytes.</p>
-<p><tt class="computeroutput">BZ2_bzBuffToBuffDecompress</tt>
-will not write data at or beyond
-<tt class="computeroutput">dest[*destLen]</tt>, even in case of
-buffer overflow.</p>
-<p>Possible return values:</p>
-<pre class="programlisting">BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if dest is NULL or destLen is NULL
-  or blockSize100k &lt; 1 or blockSize100k &gt; 9
-  or verbosity &lt; 0 or verbosity &gt; 4
-  or workFactor &lt; 0 or workFactor &gt; 250
-BZ_MEM_ERROR
-  if insufficient memory is available 
-BZ_OUTBUFF_FULL
-  if the size of the compressed data exceeds *destLen
-BZ_OK
-  otherwise</pre>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="bzbufftobuffdecompress"></a>3.5.2. <tt class="computeroutput">BZ2_bzBuffToBuffDecompress</tt></h3></div></div>
-<div></div>
-</div>
-<pre class="programlisting">int BZ2_bzBuffToBuffDecompress( char*         dest,
-                                unsigned int* destLen,
-                                char*         source,
-                                unsigned int  sourceLen,
-                                int           small,
-                                int           verbosity );</pre>
-<p>Attempts to decompress the data in <tt class="computeroutput">source[0
-.. sourceLen-1]</tt> into the destination buffer,
-<tt class="computeroutput">dest[0 .. *destLen-1]</tt>.  If the
-destination buffer is big enough,
-<tt class="computeroutput">*destLen</tt> is set to the size of
-the uncompressed data, and <tt class="computeroutput">BZ_OK</tt>
-is returned.  If the compressed data won't fit,
-<tt class="computeroutput">*destLen</tt> is unchanged, and
-<tt class="computeroutput">BZ_OUTBUFF_FULL</tt> is
-returned.</p>
-<p><tt class="computeroutput">source</tt> is assumed to hold
-a complete <tt class="computeroutput">bzip2</tt> format data
-stream.
-<tt class="computeroutput">BZ2_bzBuffToBuffDecompress</tt> tries
-to decompress the entirety of the stream into the output
-buffer.</p>
-<p>For the meaning of parameters
-<tt class="computeroutput">small</tt> and
-<tt class="computeroutput">verbosity</tt>, see
-<tt class="computeroutput">BZ2_bzDecompressInit</tt>.</p>
-<p>Because the compression ratio of the compressed data cannot
-be known in advance, there is no easy way to guarantee that the
-output buffer will be big enough.  You may of course make
-arrangements in your code to record the size of the uncompressed
-data, but such a mechanism is beyond the scope of this
-library.</p>
-<p><tt class="computeroutput">BZ2_bzBuffToBuffDecompress</tt>
-will not write data at or beyond
-<tt class="computeroutput">dest[*destLen]</tt>, even in case of
-buffer overflow.</p>
-<p>Possible return values:</p>
-<pre class="programlisting">BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if dest is NULL or destLen is NULL
-  or small != 0 &amp;&amp; small != 1
-  or verbosity &lt; 0 or verbosity &gt; 4
-BZ_MEM_ERROR
-  if insufficient memory is available 
-BZ_OUTBUFF_FULL
-  if the size of the compressed data exceeds *destLen
-BZ_DATA_ERROR
-  if a data integrity error was detected in the compressed data
-BZ_DATA_ERROR_MAGIC
-  if the compressed data doesn't begin with the right magic bytes
-BZ_UNEXPECTED_EOF
-  if the compressed data ends unexpectedly
-BZ_OK
-  otherwise</pre>
-</div>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="zlib-compat"></a>3.6. <tt class="computeroutput">zlib</tt> compatibility functions</h2></div></div>
-<div></div>
-</div>
-<p>Yoshioka Tsuneo has contributed some functions to give
-better <tt class="computeroutput">zlib</tt> compatibility.
-These functions are <tt class="computeroutput">BZ2_bzopen</tt>,
-<tt class="computeroutput">BZ2_bzread</tt>,
-<tt class="computeroutput">BZ2_bzwrite</tt>,
-<tt class="computeroutput">BZ2_bzflush</tt>,
-<tt class="computeroutput">BZ2_bzclose</tt>,
-<tt class="computeroutput">BZ2_bzerror</tt> and
-<tt class="computeroutput">BZ2_bzlibVersion</tt>.  These
-functions are not (yet) officially part of the library.  If they
-break, you get to keep all the pieces.  Nevertheless, I think
-they work ok.</p>
-<pre class="programlisting">typedef void BZFILE;
-
-const char * BZ2_bzlibVersion ( void );</pre>
-<p>Returns a string indicating the library version.</p>
-<pre class="programlisting">BZFILE * BZ2_bzopen  ( const char *path, const char *mode );
-BZFILE * BZ2_bzdopen ( int        fd,    const char *mode );</pre>
-<p>Opens a <tt class="computeroutput">.bz2</tt> file for
-reading or writing, using either its name or a pre-existing file
-descriptor.  Analogous to <tt class="computeroutput">fopen</tt>
-and <tt class="computeroutput">fdopen</tt>.</p>
-<pre class="programlisting">int BZ2_bzread  ( BZFILE* b, void* buf, int len );
-int BZ2_bzwrite ( BZFILE* b, void* buf, int len );</pre>
-<p>Reads/writes data from/to a previously opened
-<tt class="computeroutput">BZFILE</tt>.  Analogous to
-<tt class="computeroutput">fread</tt> and
-<tt class="computeroutput">fwrite</tt>.</p>
-<pre class="programlisting">int  BZ2_bzflush ( BZFILE* b );
-void BZ2_bzclose ( BZFILE* b );</pre>
-<p>Flushes/closes a <tt class="computeroutput">BZFILE</tt>.
-<tt class="computeroutput">BZ2_bzflush</tt> doesn't actually do
-anything.  Analogous to <tt class="computeroutput">fflush</tt>
-and <tt class="computeroutput">fclose</tt>.</p>
-<pre class="programlisting">const char * BZ2_bzerror ( BZFILE *b, int *errnum )</pre>
-<p>Returns a string describing the more recent error status of
-<tt class="computeroutput">b</tt>, and also sets
-<tt class="computeroutput">*errnum</tt> to its numerical
-value.</p>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="stdio-free"></a>3.7. Using the library in a <tt class="computeroutput">stdio</tt>-free environment</h2></div></div>
-<div></div>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="stdio-bye"></a>3.7.1. Getting rid of <tt class="computeroutput">stdio</tt></h3></div></div>
-<div></div>
-</div>
-<p>In a deeply embedded application, you might want to use
-just the memory-to-memory functions.  You can do this
-conveniently by compiling the library with preprocessor symbol
-<tt class="computeroutput">BZ_NO_STDIO</tt> defined.  Doing this
-gives you a library containing only the following eight
-functions:</p>
-<p><tt class="computeroutput">BZ2_bzCompressInit</tt>,
-<tt class="computeroutput">BZ2_bzCompress</tt>,
-<tt class="computeroutput">BZ2_bzCompressEnd</tt>
-<tt class="computeroutput">BZ2_bzDecompressInit</tt>,
-<tt class="computeroutput">BZ2_bzDecompress</tt>,
-<tt class="computeroutput">BZ2_bzDecompressEnd</tt>
-<tt class="computeroutput">BZ2_bzBuffToBuffCompress</tt>,
-<tt class="computeroutput">BZ2_bzBuffToBuffDecompress</tt></p>
-<p>When compiled like this, all functions will ignore
-<tt class="computeroutput">verbosity</tt> settings.</p>
-</div>
-<div class="sect2" lang="en">
-<div class="titlepage">
-<div><div><h3 class="title">
-<a name="critical-error"></a>3.7.2. Critical error handling</h3></div></div>
-<div></div>
-</div>
-<p><tt class="computeroutput">libbzip2</tt> contains a number
-of internal assertion checks which should, needless to say, never
-be activated.  Nevertheless, if an assertion should fail,
-behaviour depends on whether or not the library was compiled with
-<tt class="computeroutput">BZ_NO_STDIO</tt> set.</p>
-<p>For a normal compile, an assertion failure yields the
-message:</p>
-<div class="blockquote"><blockquote class="blockquote">
-<p>bzip2/libbzip2: internal error number N.</p>
-<p>This is a bug in bzip2/libbzip2, 1.0.3 of 15 February 2005.
-Please report it to me at: jseward@bzip.org.  If this happened
-when you were using some program which uses libbzip2 as a
-component, you should also report this bug to the author(s)
-of that program.  Please make an effort to report this bug;
-timely and accurate bug reports eventually lead to higher
-quality software.  Thanks.  Julian Seward, 15 February 2005.
-</p>
-</blockquote></div>
-<p>where <tt class="computeroutput">N</tt> is some error code
-number.  If <tt class="computeroutput">N == 1007</tt>, it also
-prints some extra text advising the reader that unreliable memory
-is often associated with internal error 1007. (This is a
-frequently-observed-phenomenon with versions 1.0.0/1.0.1).</p>
-<p><tt class="computeroutput">exit(3)</tt> is then
-called.</p>
-<p>For a <tt class="computeroutput">stdio</tt>-free library,
-assertion failures result in a call to a function declared
-as:</p>
-<pre class="programlisting">extern void bz_internal_error ( int errcode );</pre>
-<p>The relevant code is passed as a parameter.  You should
-supply such a function.</p>
-<p>In either case, once an assertion failure has occurred, any
-<tt class="computeroutput">bz_stream</tt> records involved can
-be regarded as invalid.  You should not attempt to resume normal
-operation with them.</p>
-<p>You may, of course, change critical error handling to suit
-your needs.  As I said above, critical errors indicate bugs in
-the library and should not occur.  All "normal" error situations
-are indicated via error return codes from functions, and can be
-recovered from.</p>
-</div>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="win-dll"></a>3.8. Making a Windows DLL</h2></div></div>
-<div></div>
-</div>
-<p>Everything related to Windows has been contributed by
-Yoshioka Tsuneo
-(<tt class="computeroutput">QWF00133@niftyserve.or.jp</tt> /
-<tt class="computeroutput">tsuneo-y@is.aist-nara.ac.jp</tt>), so
-you should send your queries to him (but perhaps Cc: me,
-<tt class="computeroutput">jseward@bzip.org</tt>).</p>
-<p>My vague understanding of what to do is: using Visual C++
-5.0, open the project file
-<tt class="computeroutput">libbz2.dsp</tt>, and build.  That's
-all.</p>
-<p>If you can't open the project file for some reason, make a
-new one, naming these files:
-<tt class="computeroutput">blocksort.c</tt>,
-<tt class="computeroutput">bzlib.c</tt>,
-<tt class="computeroutput">compress.c</tt>,
-<tt class="computeroutput">crctable.c</tt>,
-<tt class="computeroutput">decompress.c</tt>,
-<tt class="computeroutput">huffman.c</tt>,
-<tt class="computeroutput">randtable.c</tt> and
-<tt class="computeroutput">libbz2.def</tt>.  You will also need
-to name the header files <tt class="computeroutput">bzlib.h</tt>
-and <tt class="computeroutput">bzlib_private.h</tt>.</p>
-<p>If you don't use VC++, you may need to define the
-proprocessor symbol
-<tt class="computeroutput">_WIN32</tt>.</p>
-<p>Finally, <tt class="computeroutput">dlltest.c</tt> is a
-sample program using the DLL.  It has a project file,
-<tt class="computeroutput">dlltest.dsp</tt>.</p>
-<p>If you just want a makefile for Visual C, have a look at
-<tt class="computeroutput">makefile.msc</tt>.</p>
-<p>Be aware that if you compile
-<tt class="computeroutput">bzip2</tt> itself on Win32, you must
-set <tt class="computeroutput">BZ_UNIX</tt> to 0 and
-<tt class="computeroutput">BZ_LCCWIN32</tt> to 1, in the file
-<tt class="computeroutput">bzip2.c</tt>, before compiling.
-Otherwise the resulting binary won't work correctly.</p>
-<p>I haven't tried any of this stuff myself, but it all looks
-plausible.</p>
-</div>
-</div>
-<div class="chapter" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title">
-<a name="misc"></a>4. Miscellanea</h2></div></div>
-<div></div>
-</div>
-<div class="toc">
-<p><b>Table of Contents</b></p>
-<dl>
-<dt><span class="sect1"><a href="#limits">4.1. Limitations of the compressed file format</a></span></dt>
-<dt><span class="sect1"><a href="#port-issues">4.2. Portability issues</a></span></dt>
-<dt><span class="sect1"><a href="#bugs">4.3. Reporting bugs</a></span></dt>
-<dt><span class="sect1"><a href="#package">4.4. Did you get the right package?</a></span></dt>
-<dt><span class="sect1"><a href="#reading">4.5. Further Reading</a></span></dt>
-</dl>
-</div>
-<p>These are just some random thoughts of mine.  Your mileage
-may vary.</p>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="limits"></a>4.1. Limitations of the compressed file format</h2></div></div>
-<div></div>
-</div>
-<p><tt class="computeroutput">bzip2-1.0.X</tt>,
-<tt class="computeroutput">0.9.5</tt> and
-<tt class="computeroutput">0.9.0</tt> use exactly the same file
-format as the original version,
-<tt class="computeroutput">bzip2-0.1</tt>.  This decision was
-made in the interests of stability.  Creating yet another
-incompatible compressed file format would create further
-confusion and disruption for users.</p>
-<p>Nevertheless, this is not a painless decision.  Development
-work since the release of
-<tt class="computeroutput">bzip2-0.1</tt> in August 1997 has
-shown complexities in the file format which slow down
-decompression and, in retrospect, are unnecessary.  These
-are:</p>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc"><p>The run-length encoder, which is the first of the
-   compression transformations, is entirely irrelevant.  The
-   original purpose was to protect the sorting algorithm from the
-   very worst case input: a string of repeated symbols.  But
-   algorithm steps Q6a and Q6b in the original Burrows-Wheeler
-   technical report (SRC-124) show how repeats can be handled
-   without difficulty in block sorting.</p></li>
-<li style="list-style-type: disc">
-<p>The randomisation mechanism doesn't really need to be
-   there.  Udi Manber and Gene Myers published a suffix array
-   construction algorithm a few years back, which can be employed
-   to sort any block, no matter how repetitive, in O(N log N)
-   time.  Subsequent work by Kunihiko Sadakane has produced a
-   derivative O(N (log N)^2) algorithm which usually outperforms
-   the Manber-Myers algorithm.</p>
-<p>I could have changed to Sadakane's algorithm, but I find
-   it to be slower than <tt class="computeroutput">bzip2</tt>'s
-   existing algorithm for most inputs, and the randomisation
-   mechanism protects adequately against bad cases.  I didn't
-   think it was a good tradeoff to make.  Partly this is due to
-   the fact that I was not flooded with email complaints about
-   <tt class="computeroutput">bzip2-0.1</tt>'s performance on
-   repetitive data, so perhaps it isn't a problem for real
-   inputs.</p>
-<p>Probably the best long-term solution, and the one I have
-   incorporated into 0.9.5 and above, is to use the existing
-   sorting algorithm initially, and fall back to a O(N (log N)^2)
-   algorithm if the standard algorithm gets into
-   difficulties.</p>
-</li>
-<li style="list-style-type: disc"><p>The compressed file format was never designed to be
-   handled by a library, and I have had to jump though some hoops
-   to produce an efficient implementation of decompression.  It's
-   a bit hairy.  Try passing
-   <tt class="computeroutput">decompress.c</tt> through the C
-   preprocessor and you'll see what I mean.  Much of this
-   complexity could have been avoided if the compressed size of
-   each block of data was recorded in the data stream.</p></li>
-<li style="list-style-type: disc"><p>An Adler-32 checksum, rather than a CRC32 checksum,
-   would be faster to compute.</p></li>
-</ul></div>
-<p>It would be fair to say that the
-<tt class="computeroutput">bzip2</tt> format was frozen before I
-properly and fully understood the performance consequences of
-doing so.</p>
-<p>Improvements which I was able to incorporate into 0.9.0,
-despite using the same file format, are:</p>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc"><p>Single array implementation of the inverse BWT.  This
-  significantly speeds up decompression, presumably because it
-  reduces the number of cache misses.</p></li>
-<li style="list-style-type: disc"><p>Faster inverse MTF transform for large MTF values.
-  The new implementation is based on the notion of sliding blocks
-  of values.</p></li>
-<li style="list-style-type: disc"><p><tt class="computeroutput">bzip2-0.9.0</tt> now reads
-  and writes files with <tt class="computeroutput">fread</tt>
-  and <tt class="computeroutput">fwrite</tt>; version 0.1 used
-  <tt class="computeroutput">putc</tt> and
-  <tt class="computeroutput">getc</tt>.  Duh!  Well, you live
-  and learn.</p></li>
-</ul></div>
-<p>Further ahead, it would be nice to be able to do random
-access into files.  This will require some careful design of
-compressed file formats.</p>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="port-issues"></a>4.2. Portability issues</h2></div></div>
-<div></div>
-</div>
-<p>After some consideration, I have decided not to use GNU
-<tt class="computeroutput">autoconf</tt> to configure 0.9.5 or
-1.0.</p>
-<p><tt class="computeroutput">autoconf</tt>, admirable and
-wonderful though it is, mainly assists with portability problems
-between Unix-like platforms.  But
-<tt class="computeroutput">bzip2</tt> doesn't have much in the
-way of portability problems on Unix; most of the difficulties
-appear when porting to the Mac, or to Microsoft's operating
-systems.  <tt class="computeroutput">autoconf</tt> doesn't help
-in those cases, and brings in a whole load of new
-complexity.</p>
-<p>Most people should be able to compile the library and
-program under Unix straight out-of-the-box, so to speak,
-especially if you have a version of GNU C available.</p>
-<p>There are a couple of
-<tt class="computeroutput">__inline__</tt> directives in the
-code.  GNU C (<tt class="computeroutput">gcc</tt>) should be
-able to handle them.  If you're not using GNU C, your C compiler
-shouldn't see them at all.  If your compiler does, for some
-reason, see them and doesn't like them, just
-<tt class="computeroutput">#define</tt>
-<tt class="computeroutput">__inline__</tt> to be
-<tt class="computeroutput">/* */</tt>.  One easy way to do this
-is to compile with the flag
-<tt class="computeroutput">-D__inline__=</tt>, which should be
-understood by most Unix compilers.</p>
-<p>If you still have difficulties, try compiling with the
-macro <tt class="computeroutput">BZ_STRICT_ANSI</tt> defined.
-This should enable you to build the library in a strictly ANSI
-compliant environment.  Building the program itself like this is
-dangerous and not supported, since you remove
-<tt class="computeroutput">bzip2</tt>'s checks against
-compressing directories, symbolic links, devices, and other
-not-really-a-file entities.  This could cause filesystem
-corruption!</p>
-<p>One other thing: if you create a
-<tt class="computeroutput">bzip2</tt> binary for public distribution,
-please consider linking it statically (<tt class="computeroutput">gcc
--static</tt>).  This avoids all sorts of library-version
-issues that others may encounter later on.</p>
-<p>If you build <tt class="computeroutput">bzip2</tt> on
-Win32, you must set <tt class="computeroutput">BZ_UNIX</tt> to 0
-and <tt class="computeroutput">BZ_LCCWIN32</tt> to 1, in the
-file <tt class="computeroutput">bzip2.c</tt>, before compiling.
-Otherwise the resulting binary won't work correctly.</p>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="bugs"></a>4.3. Reporting bugs</h2></div></div>
-<div></div>
-</div>
-<p>I tried pretty hard to make sure
-<tt class="computeroutput">bzip2</tt> is bug free, both by
-design and by testing.  Hopefully you'll never need to read this
-section for real.</p>
-<p>Nevertheless, if <tt class="computeroutput">bzip2</tt> dies
-with a segmentation fault, a bus error or an internal assertion
-failure, it will ask you to email me a bug report.  Experience from
-years of feedback of bzip2 users indicates that almost all these
-problems can be traced to either compiler bugs or hardware
-problems.</p>
-<div class="itemizedlist"><ul type="bullet">
-<li style="list-style-type: disc">
-<p>Recompile the program with no optimisation, and
-  see if it works.  And/or try a different compiler.  I heard all
-  sorts of stories about various flavours of GNU C (and other
-  compilers) generating bad code for
-  <tt class="computeroutput">bzip2</tt>, and I've run across two
-  such examples myself.</p>
-<p>2.7.X versions of GNU C are known to generate bad code
-  from time to time, at high optimisation levels.  If you get
-  problems, try using the flags
-  <tt class="computeroutput">-O2</tt>
-  <tt class="computeroutput">-fomit-frame-pointer</tt>
-  <tt class="computeroutput">-fno-strength-reduce</tt>.  You
-  should specifically <span class="emphasis"><em>not</em></span> use
-  <tt class="computeroutput">-funroll-loops</tt>.</p>
-<p>You may notice that the Makefile runs six tests as part
-  of the build process.  If the program passes all of these, it's
-  a pretty good (but not 100%) indication that the compiler has
-  done its job correctly.</p>
-</li>
-<li style="list-style-type: disc">
-<p>If <tt class="computeroutput">bzip2</tt>
-  crashes randomly, and the crashes are not repeatable, you may
-  have a flaky memory subsystem.
-  <tt class="computeroutput">bzip2</tt> really hammers your
-  memory hierarchy, and if it's a bit marginal, you may get these
-  problems.  Ditto if your disk or I/O subsystem is slowly
-  failing.  Yup, this really does happen.</p>
-<p>Try using a different machine of the same type, and see
-  if you can repeat the problem.</p>
-</li>
-<li style="list-style-type: disc"><p>This isn't really a bug, but ... If
-  <tt class="computeroutput">bzip2</tt> tells you your file is
-  corrupted on decompression, and you obtained the file via FTP,
-  there is a possibility that you forgot to tell FTP to do a
-  binary mode transfer.  That absolutely will cause the file to
-  be non-decompressible.  You'll have to transfer it
-  again.</p></li>
-</ul></div>
-<p>If you've incorporated
-<tt class="computeroutput">libbzip2</tt> into your own program
-and are getting problems, please, please, please, check that the
-parameters you are passing in calls to the library, are correct,
-and in accordance with what the documentation says is allowable.
-I have tried to make the library robust against such problems,
-but I'm sure I haven't succeeded.</p>
-<p>Finally, if the above comments don't help, you'll have to
-send me a bug report.  Now, it's just amazing how many people
-will send me a bug report saying something like:</p>
-<pre class="programlisting">bzip2 crashed with segmentation fault on my machine</pre>
-<p>and absolutely nothing else.  Needless to say, a such a
-report is <span class="emphasis"><em>totally, utterly, completely and
-comprehensively 100% useless; a waste of your time, my time, and
-net bandwidth</em></span>.  With no details at all, there's no way
-I can possibly begin to figure out what the problem is.</p>
-<p>The rules of the game are: facts, facts, facts.  Don't omit
-them because "oh, they won't be relevant".  At the bare
-minimum:</p>
-<pre class="programlisting">Machine type.  Operating system version.  
-Exact version of bzip2 (do bzip2 -V).  
-Exact version of the compiler used.  
-Flags passed to the compiler.</pre>
-<p>However, the most important single thing that will help me
-is the file that you were trying to compress or decompress at the
-time the problem happened.  Without that, my ability to do
-anything more than speculate about the cause, is limited.</p>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="package"></a>4.4. Did you get the right package?</h2></div></div>
-<div></div>
-</div>
-<p><tt class="computeroutput">bzip2</tt> is a resource hog.
-It soaks up large amounts of CPU cycles and memory.  Also, it
-gives very large latencies.  In the worst case, you can feed many
-megabytes of uncompressed data into the library before getting
-any compressed output, so this probably rules out applications
-requiring interactive behaviour.</p>
-<p>These aren't faults of my implementation, I hope, but more
-an intrinsic property of the Burrows-Wheeler transform
-(unfortunately).  Maybe this isn't what you want.</p>
-<p>If you want a compressor and/or library which is faster,
-uses less memory but gets pretty good compression, and has
-minimal latency, consider Jean-loup Gailly's and Mark Adler's
-work, <tt class="computeroutput">zlib-1.2.1</tt> and
-<tt class="computeroutput">gzip-1.2.4</tt>.  Look for them at 
-<a href="http://www.zlib.org" target="_top">http://www.zlib.org</a> and 
-<a href="http://www.gzip.org" target="_top">http://www.gzip.org</a>
-respectively.</p>
-<p>For something faster and lighter still, you might try Markus F
-X J Oberhumer's <tt class="computeroutput">LZO</tt> real-time
-compression/decompression library, at 
-<a href="http://www.oberhumer.com/opensource" target="_top">http://www.oberhumer.com/opensource</a>.</p>
-</div>
-<div class="sect1" lang="en">
-<div class="titlepage">
-<div><div><h2 class="title" style="clear: both">
-<a name="reading"></a>4.5. Further Reading</h2></div></div>
-<div></div>
-</div>
-<p><tt class="computeroutput">bzip2</tt> is not research
-work, in the sense that it doesn't present any new ideas.
-Rather, it's an engineering exercise based on existing
-ideas.</p>
-<p>Four documents describe essentially all the ideas behind
-<tt class="computeroutput">bzip2</tt>:</p>
-<div class="literallayout"><p>Michael Burrows and D. J. Wheeler:<br>
-  "A block-sorting lossless data compression algorithm"<br>
-   10th May 1994. <br>
-   Digital SRC Research Report 124.<br>
-   ftp://ftp.digital.com/pub/DEC/SRC/research-reports/SRC-124.ps.gz<br>
-   If you have trouble finding it, try searching at the<br>
-   New Zealand Digital Library, http://www.nzdl.org.<br>
-<br>
-Daniel S. Hirschberg and Debra A. LeLewer<br>
-  "Efficient Decoding of Prefix Codes"<br>
-   Communications of the ACM, April 1990, Vol 33, Number 4.<br>
-   You might be able to get an electronic copy of this<br>
-   from the ACM Digital Library.<br>
-<br>
-David J. Wheeler<br>
-   Program bred3.c and accompanying document bred3.ps.<br>
-   This contains the idea behind the multi-table Huffman coding scheme.<br>
-   ftp://ftp.cl.cam.ac.uk/users/djw3/<br>
-<br>
-Jon L. Bentley and Robert Sedgewick<br>
-  "Fast Algorithms for Sorting and Searching Strings"<br>
-   Available from Sedgewick's web page,<br>
-   www.cs.princeton.edu/~rs<br>
-</p></div>
-<p>The following paper gives valuable additional insights into
-the algorithm, but is not immediately the basis of any code used
-in bzip2.</p>
-<div class="literallayout"><p>Peter Fenwick:<br>
-   Block Sorting Text Compression<br>
-   Proceedings of the 19th Australasian Computer Science Conference,<br>
-     Melbourne, Australia.  Jan 31 - Feb 2, 1996.<br>
-   ftp://ftp.cs.auckland.ac.nz/pub/peter-f/ACSC96paper.ps</p></div>
-<p>Kunihiko Sadakane's sorting algorithm, mentioned above, is
-available from:</p>
-<div class="literallayout"><p>http://naomi.is.s.u-tokyo.ac.jp/~sada/papers/Sada98b.ps.gz<br>
-</p></div>
-<p>The Manber-Myers suffix array construction algorithm is
-described in a paper available from:</p>
-<div class="literallayout"><p>http://www.cs.arizona.edu/people/gene/PAPERS/suffix.ps<br>
-</p></div>
-<p>Finally, the following papers document some
-investigations I made into the performance of sorting
-and decompression algorithms:</p>
-<div class="literallayout"><p>Julian Seward<br>
-   On the Performance of BWT Sorting Algorithms<br>
-   Proceedings of the IEEE Data Compression Conference 2000<br>
-     Snowbird, Utah.  28-30 March 2000.<br>
-<br>
-Julian Seward<br>
-   Space-time Tradeoffs in the Inverse B-W Transform<br>
-   Proceedings of the IEEE Data Compression Conference 2001<br>
-     Snowbird, Utah.  27-29 March 2001.<br>
-</p></div>
-</div>
-</div>
-</div></body>
-</html>
Index: trunk/minix/commands/bzip2-1.0.3/manual.xml
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/manual.xml	(revision 9)
+++ 	(revision )
@@ -1,2966 +1,0 @@
-<?xml version="1.0"?> <!-- -*- sgml -*- -->
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
-  "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"[
-
-<!-- various strings, dates etc. common to all docs -->
-<!ENTITY % common-ents SYSTEM "entities.xml"> %common-ents;
-]>
-
-<book lang="en" id="userman" xreflabel="bzip2 Manual">
-
- <bookinfo>
-  <title>bzip2 and libbzip2, version 1.0.3</title>
-  <subtitle>A program and library for data compression</subtitle>
-  <copyright>
-   <year>&bz-lifespan;</year>
-   <holder>Julian Seward</holder>
-  </copyright>
-  <releaseinfo>Version &bz-version; of &bz-date;</releaseinfo>
-
-  <authorgroup>
-   <author>
-    <firstname>Julian</firstname>
-    <surname>Seward</surname>
-    <affiliation>
-     <orgname>&bz-url;</orgname>
-    </affiliation>
-   </author>
-  </authorgroup>
-
-  <legalnotice>
-
-  <para>This program, <computeroutput>bzip2</computeroutput>, the
-  associated library <computeroutput>libbzip2</computeroutput>, and
-  all documentation, are copyright &copy; &bz-lifespan; Julian Seward.
-  All rights reserved.</para>
-
-  <para>Redistribution and use in source and binary forms, with
-  or without modification, are permitted provided that the
-  following conditions are met:</para>
-
-  <itemizedlist mark='bullet'>
-
-   <listitem><para>Redistributions of source code must retain the
-   above copyright notice, this list of conditions and the
-   following disclaimer.</para></listitem>
-
-   <listitem><para>The origin of this software must not be
-   misrepresented; you must not claim that you wrote the original
-   software.  If you use this software in a product, an
-   acknowledgment in the product documentation would be
-   appreciated but is not required.</para></listitem>
-
-   <listitem><para>Altered source versions must be plainly marked
-   as such, and must not be misrepresented as being the original
-   software.</para></listitem>
-
-   <listitem><para>The name of the author may not be used to
-   endorse or promote products derived from this software without
-   specific prior written permission.</para></listitem>
-
-  </itemizedlist>
-
-  <para>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.</para>
-
- <para>PATENTS: To the best of my knowledge,
- <computeroutput>bzip2</computeroutput> and
- <computeroutput>libbzip2</computeroutput> do not use any patented
- algorithms.  However, I do not have the resources to carry
- out a patent search.  Therefore I cannot give any guarantee of
- the above statement.
- </para>
-
-</legalnotice>
-
-</bookinfo>
-
-
-
-<chapter id="intro" xreflabel="Introduction">
-<title>Introduction</title>
-
-<para><computeroutput>bzip2</computeroutput> compresses files
-using the Burrows-Wheeler block-sorting text compression
-algorithm, and Huffman coding.  Compression is generally
-considerably better than that achieved by more conventional
-LZ77/LZ78-based compressors, and approaches the performance of
-the PPM family of statistical compressors.</para>
-
-<para><computeroutput>bzip2</computeroutput> is built on top of
-<computeroutput>libbzip2</computeroutput>, a flexible library for
-handling compressed data in the
-<computeroutput>bzip2</computeroutput> format.  This manual
-describes both how to use the program and how to work with the
-library interface.  Most of the manual is devoted to this
-library, not the program, which is good news if your interest is
-only in the program.</para>
-
-<itemizedlist mark='bullet'>
-
- <listitem><para><xref linkend="using"/> describes how to use
- <computeroutput>bzip2</computeroutput>; this is the only part
- you need to read if you just want to know how to operate the
- program.</para></listitem>
-
- <listitem><para><xref linkend="libprog"/> describes the
- programming interfaces in detail, and</para></listitem>
-
- <listitem><para><xref linkend="misc"/> records some
- miscellaneous notes which I thought ought to be recorded
- somewhere.</para></listitem>
-
-</itemizedlist>
-
-</chapter>
-
-
-<chapter id="using" xreflabel="How to use bzip2">
-<title>How to use bzip2</title>
-
-<para>This chapter contains a copy of the
-<computeroutput>bzip2</computeroutput> man page, and nothing
-else.</para>
-
-<sect1 id="name" xreflabel="NAME">
-<title>NAME</title>
-
-<itemizedlist mark='bullet'>
-
- <listitem><para><computeroutput>bzip2</computeroutput>,
-  <computeroutput>bunzip2</computeroutput> - a block-sorting file
-  compressor, v1.0.3</para></listitem>
-
- <listitem><para><computeroutput>bzcat</computeroutput> -
-   decompresses files to stdout</para></listitem>
-
- <listitem><para><computeroutput>bzip2recover</computeroutput> -
-   recovers data from damaged bzip2 files</para></listitem>
-
-</itemizedlist>
-
-</sect1>
-
-
-<sect1 id="synopsis" xreflabel="SYNOPSIS">
-<title>SYNOPSIS</title>
-
-<itemizedlist mark='bullet'>
-
- <listitem><para><computeroutput>bzip2</computeroutput> [
-  -cdfkqstvzVL123456789 ] [ filenames ...  ]</para></listitem>
-
- <listitem><para><computeroutput>bunzip2</computeroutput> [
-  -fkvsVL ] [ filenames ...  ]</para></listitem>
-
- <listitem><para><computeroutput>bzcat</computeroutput> [ -s ] [
-  filenames ...  ]</para></listitem>
-
- <listitem><para><computeroutput>bzip2recover</computeroutput>
-  filename</para></listitem>
-
-</itemizedlist>
-
-</sect1>
-
-
-<sect1 id="description" xreflabel="DESCRIPTION">
-<title>DESCRIPTION</title>
-
-<para><computeroutput>bzip2</computeroutput> compresses files
-using the Burrows-Wheeler block sorting text compression
-algorithm, and Huffman coding.  Compression is generally
-considerably better than that achieved by more conventional
-LZ77/LZ78-based compressors, and approaches the performance of
-the PPM family of statistical compressors.</para>
-
-<para>The command-line options are deliberately very similar to
-those of GNU <computeroutput>gzip</computeroutput>, but they are
-not identical.</para>
-
-<para><computeroutput>bzip2</computeroutput> expects a list of
-file names to accompany the command-line flags.  Each file is
-replaced by a compressed version of itself, with the name
-<computeroutput>original_name.bz2</computeroutput>.  Each
-compressed file has the same modification date, permissions, and,
-when possible, ownership as the corresponding original, so that
-these properties can be correctly restored at decompression time.
-File name handling is naive in the sense that there is no
-mechanism for preserving original file names, permissions,
-ownerships or dates in filesystems which lack these concepts, or
-have serious file name length restrictions, such as
-MS-DOS.</para>
-
-<para><computeroutput>bzip2</computeroutput> and
-<computeroutput>bunzip2</computeroutput> will by default not
-overwrite existing files.  If you want this to happen, specify
-the <computeroutput>-f</computeroutput> flag.</para>
-
-<para>If no file names are specified,
-<computeroutput>bzip2</computeroutput> compresses from standard
-input to standard output.  In this case,
-<computeroutput>bzip2</computeroutput> will decline to write
-compressed output to a terminal, as this would be entirely
-incomprehensible and therefore pointless.</para>
-
-<para><computeroutput>bunzip2</computeroutput> (or
-<computeroutput>bzip2 -d</computeroutput>) decompresses all
-specified files.  Files which were not created by
-<computeroutput>bzip2</computeroutput> will be detected and
-ignored, and a warning issued.
-<computeroutput>bzip2</computeroutput> attempts to guess the
-filename for the decompressed file from that of the compressed
-file as follows:</para>
-
-<itemizedlist mark='bullet'>
-
- <listitem><para><computeroutput>filename.bz2 </computeroutput>
-  becomes
-  <computeroutput>filename</computeroutput></para></listitem>
-
- <listitem><para><computeroutput>filename.bz </computeroutput>
-  becomes
-  <computeroutput>filename</computeroutput></para></listitem>
-
- <listitem><para><computeroutput>filename.tbz2</computeroutput>
-  becomes
-  <computeroutput>filename.tar</computeroutput></para></listitem>
-
- <listitem><para><computeroutput>filename.tbz </computeroutput>
-  becomes
-  <computeroutput>filename.tar</computeroutput></para></listitem>
-
- <listitem><para><computeroutput>anyothername </computeroutput>
-  becomes
-  <computeroutput>anyothername.out</computeroutput></para></listitem>
-
-</itemizedlist>
-
-<para>If the file does not end in one of the recognised endings,
-<computeroutput>.bz2</computeroutput>,
-<computeroutput>.bz</computeroutput>,
-<computeroutput>.tbz2</computeroutput> or
-<computeroutput>.tbz</computeroutput>,
-<computeroutput>bzip2</computeroutput> complains that it cannot
-guess the name of the original file, and uses the original name
-with <computeroutput>.out</computeroutput> appended.</para>
-
-<para>As with compression, supplying no filenames causes
-decompression from standard input to standard output.</para>
-
-<para><computeroutput>bunzip2</computeroutput> will correctly
-decompress a file which is the concatenation of two or more
-compressed files.  The result is the concatenation of the
-corresponding uncompressed files.  Integrity testing
-(<computeroutput>-t</computeroutput>) of concatenated compressed
-files is also supported.</para>
-
-<para>You can also compress or decompress files to the standard
-output by giving the <computeroutput>-c</computeroutput> flag.
-Multiple files may be compressed and decompressed like this.  The
-resulting outputs are fed sequentially to stdout.  Compression of
-multiple files in this manner generates a stream containing
-multiple compressed file representations.  Such a stream can be
-decompressed correctly only by
-<computeroutput>bzip2</computeroutput> version 0.9.0 or later.
-Earlier versions of <computeroutput>bzip2</computeroutput> will
-stop after decompressing the first file in the stream.</para>
-
-<para><computeroutput>bzcat</computeroutput> (or
-<computeroutput>bzip2 -dc</computeroutput>) decompresses all
-specified files to the standard output.</para>
-
-<para><computeroutput>bzip2</computeroutput> will read arguments
-from the environment variables
-<computeroutput>BZIP2</computeroutput> and
-<computeroutput>BZIP</computeroutput>, in that order, and will
-process them before any arguments read from the command line.
-This gives a convenient way to supply default arguments.</para>
-
-<para>Compression is always performed, even if the compressed
-file is slightly larger than the original.  Files of less than
-about one hundred bytes tend to get larger, since the compression
-mechanism has a constant overhead in the region of 50 bytes.
-Random data (including the output of most file compressors) is
-coded at about 8.05 bits per byte, giving an expansion of around
-0.5%.</para>
-
-<para>As a self-check for your protection,
-<computeroutput>bzip2</computeroutput> uses 32-bit CRCs to make
-sure that the decompressed version of a file is identical to the
-original.  This guards against corruption of the compressed data,
-and against undetected bugs in
-<computeroutput>bzip2</computeroutput> (hopefully very unlikely).
-The chances of data corruption going undetected is microscopic,
-about one chance in four billion for each file processed.  Be
-aware, though, that the check occurs upon decompression, so it
-can only tell you that something is wrong.  It can't help you
-recover the original uncompressed data.  You can use
-<computeroutput>bzip2recover</computeroutput> to try to recover
-data from damaged files.</para>
-
-<para>Return values: 0 for a normal exit, 1 for environmental
-problems (file not found, invalid flags, I/O errors, etc.), 2
-to indicate a corrupt compressed file, 3 for an internal
-consistency error (eg, bug) which caused
-<computeroutput>bzip2</computeroutput> to panic.</para>
-
-</sect1>
-
-
-<sect1 id="options" xreflabel="OPTIONS">
-<title>OPTIONS</title>
-
-<variablelist>
-
- <varlistentry>
- <term><computeroutput>-c --stdout</computeroutput></term>
- <listitem><para>Compress or decompress to standard
-  output.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-d --decompress</computeroutput></term>
- <listitem><para>Force decompression.
-  <computeroutput>bzip2</computeroutput>,
-  <computeroutput>bunzip2</computeroutput> and
-  <computeroutput>bzcat</computeroutput> are really the same
-  program, and the decision about what actions to take is done on
-  the basis of which name is used.  This flag overrides that
-  mechanism, and forces bzip2 to decompress.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-z --compress</computeroutput></term>
- <listitem><para>The complement to
-  <computeroutput>-d</computeroutput>: forces compression,
-  regardless of the invokation name.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-t --test</computeroutput></term>
- <listitem><para>Check integrity of the specified file(s), but
-  don't decompress them.  This really performs a trial
-  decompression and throws away the result.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-f --force</computeroutput></term>
- <listitem><para>Force overwrite of output files.  Normally,
-  <computeroutput>bzip2</computeroutput> will not overwrite
-  existing output files.  Also forces
-  <computeroutput>bzip2</computeroutput> to break hard links to
-  files, which it otherwise wouldn't do.</para>
-  <para><computeroutput>bzip2</computeroutput> normally declines
-  to decompress files which don't have the correct magic header
-  bytes. If forced (<computeroutput>-f</computeroutput>),
-  however, it will pass such files through unmodified. This is
-  how GNU <computeroutput>gzip</computeroutput> behaves.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-k --keep</computeroutput></term>
- <listitem><para>Keep (don't delete) input files during
-  compression or decompression.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-s --small</computeroutput></term>
- <listitem><para>Reduce memory usage, for compression,
-  decompression and testing.  Files are decompressed and tested
-  using a modified algorithm which only requires 2.5 bytes per
-  block byte.  This means any file can be decompressed in 2300k
-  of memory, albeit at about half the normal speed.</para>
-  <para>During compression, <computeroutput>-s</computeroutput>
-  selects a block size of 200k, which limits memory use to around
-  the same figure, at the expense of your compression ratio.  In
-  short, if your machine is low on memory (8 megabytes or less),
-  use <computeroutput>-s</computeroutput> for everything.  See
-  <xref linkend="memory-management"/> below.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-q --quiet</computeroutput></term>
- <listitem><para>Suppress non-essential warning messages.
-  Messages pertaining to I/O errors and other critical events
-  will not be suppressed.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-v --verbose</computeroutput></term>
- <listitem><para>Verbose mode -- show the compression ratio for
-  each file processed.  Further
-  <computeroutput>-v</computeroutput>'s increase the verbosity
-  level, spewing out lots of information which is primarily of
-  interest for diagnostic purposes.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-L --license -V --version</computeroutput></term>
- <listitem><para>Display the software version, license terms and
-  conditions.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>-1</computeroutput> (or
- <computeroutput>--fast</computeroutput>) to
- <computeroutput>-9</computeroutput> (or
- <computeroutput>-best</computeroutput>)</term>
- <listitem><para>Set the block size to 100 k, 200 k ...  900 k
-  when compressing.  Has no effect when decompressing.  See <xref
-  linkend="memory-management" /> below.  The
-  <computeroutput>--fast</computeroutput> and
-  <computeroutput>--best</computeroutput> aliases are primarily
-  for GNU <computeroutput>gzip</computeroutput> compatibility.
-  In particular, <computeroutput>--fast</computeroutput> doesn't
-  make things significantly faster.  And
-  <computeroutput>--best</computeroutput> merely selects the
-  default behaviour.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>--</computeroutput></term>
- <listitem><para>Treats all subsequent arguments as file names,
-  even if they start with a dash.  This is so you can handle
-  files with names beginning with a dash, for example:
-  <computeroutput>bzip2 --
-  -myfilename</computeroutput>.</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><computeroutput>--repetitive-fast</computeroutput></term>
- <term><computeroutput>--repetitive-best</computeroutput></term>
- <listitem><para>These flags are redundant in versions 0.9.5 and
-  above.  They provided some coarse control over the behaviour of
-  the sorting algorithm in earlier versions, which was sometimes
-  useful.  0.9.5 and above have an improved algorithm which
-  renders these flags irrelevant.</para></listitem>
- </varlistentry>
-
-</variablelist>
-
-</sect1>
-
-
-<sect1 id="memory-management" xreflabel="MEMORY MANAGEMENT">
-<title>MEMORY MANAGEMENT</title>
-
-<para><computeroutput>bzip2</computeroutput> compresses large
-files in blocks.  The block size affects both the compression
-ratio achieved, and the amount of memory needed for compression
-and decompression.  The flags <computeroutput>-1</computeroutput>
-through <computeroutput>-9</computeroutput> specify the block
-size to be 100,000 bytes through 900,000 bytes (the default)
-respectively.  At decompression time, the block size used for
-compression is read from the header of the compressed file, and
-<computeroutput>bunzip2</computeroutput> then allocates itself
-just enough memory to decompress the file.  Since block sizes are
-stored in compressed files, it follows that the flags
-<computeroutput>-1</computeroutput> to
-<computeroutput>-9</computeroutput> are irrelevant to and so
-ignored during decompression.</para>
-
-<para>Compression and decompression requirements, in bytes, can be
-estimated as:</para>
-<programlisting>
-Compression:   400k + ( 8 x block size )
-
-Decompression: 100k + ( 4 x block size ), or
-               100k + ( 2.5 x block size )
-</programlisting>
-
-<para>Larger block sizes give rapidly diminishing marginal
-returns.  Most of the compression comes from the first two or
-three hundred k of block size, a fact worth bearing in mind when
-using <computeroutput>bzip2</computeroutput> on small machines.
-It is also important to appreciate that the decompression memory
-requirement is set at compression time by the choice of block
-size.</para>
-
-<para>For files compressed with the default 900k block size,
-<computeroutput>bunzip2</computeroutput> will require about 3700
-kbytes to decompress.  To support decompression of any file on a
-4 megabyte machine, <computeroutput>bunzip2</computeroutput> has
-an option to decompress using approximately half this amount of
-memory, about 2300 kbytes.  Decompression speed is also halved,
-so you should use this option only where necessary.  The relevant
-flag is <computeroutput>-s</computeroutput>.</para>
-
-<para>In general, try and use the largest block size memory
-constraints allow, since that maximises the compression achieved.
-Compression and decompression speed are virtually unaffected by
-block size.</para>
-
-<para>Another significant point applies to files which fit in a
-single block -- that means most files you'd encounter using a
-large block size.  The amount of real memory touched is
-proportional to the size of the file, since the file is smaller
-than a block.  For example, compressing a file 20,000 bytes long
-with the flag <computeroutput>-9</computeroutput> will cause the
-compressor to allocate around 7600k of memory, but only touch
-400k + 20000 * 8 = 560 kbytes of it.  Similarly, the decompressor
-will allocate 3700k but only touch 100k + 20000 * 4 = 180
-kbytes.</para>
-
-<para>Here is a table which summarises the maximum memory usage
-for different block sizes.  Also recorded is the total compressed
-size for 14 files of the Calgary Text Compression Corpus
-totalling 3,141,622 bytes.  This column gives some feel for how
-compression varies with block size.  These figures tend to
-understate the advantage of larger block sizes for larger files,
-since the Corpus is dominated by smaller files.</para>
-
-<programlisting>
-        Compress   Decompress   Decompress   Corpus
-Flag     usage      usage       -s usage     Size
-
- -1      1200k       500k         350k      914704
- -2      2000k       900k         600k      877703
- -3      2800k      1300k         850k      860338
- -4      3600k      1700k        1100k      846899
- -5      4400k      2100k        1350k      845160
- -6      5200k      2500k        1600k      838626
- -7      6100k      2900k        1850k      834096
- -8      6800k      3300k        2100k      828642
- -9      7600k      3700k        2350k      828642
-</programlisting>
-
-</sect1>
-
-
-<sect1 id="recovering" xreflabel="RECOVERING DATA FROM DAMAGED FILES">
-<title>RECOVERING DATA FROM DAMAGED FILES</title>
-
-<para><computeroutput>bzip2</computeroutput> compresses files in
-blocks, usually 900kbytes long.  Each block is handled
-independently.  If a media or transmission error causes a
-multi-block <computeroutput>.bz2</computeroutput> file to become
-damaged, it may be possible to recover data from the undamaged
-blocks in the file.</para>
-
-<para>The compressed representation of each block is delimited by
-a 48-bit pattern, which makes it possible to find the block
-boundaries with reasonable certainty.  Each block also carries
-its own 32-bit CRC, so damaged blocks can be distinguished from
-undamaged ones.</para>
-
-<para><computeroutput>bzip2recover</computeroutput> is a simple
-program whose purpose is to search for blocks in
-<computeroutput>.bz2</computeroutput> files, and write each block
-out into its own <computeroutput>.bz2</computeroutput> file.  You
-can then use <computeroutput>bzip2 -t</computeroutput> to test
-the integrity of the resulting files, and decompress those which
-are undamaged.</para>
-
-<para><computeroutput>bzip2recover</computeroutput> takes a
-single argument, the name of the damaged file, and writes a
-number of files <computeroutput>rec0001file.bz2</computeroutput>,
-<computeroutput>rec0002file.bz2</computeroutput>, etc, containing
-the extracted blocks.  The output filenames are designed so that
-the use of wildcards in subsequent processing -- for example,
-<computeroutput>bzip2 -dc rec*file.bz2 &#62;
-recovered_data</computeroutput> -- lists the files in the correct
-order.</para>
-
-<para><computeroutput>bzip2recover</computeroutput> should be of
-most use dealing with large <computeroutput>.bz2</computeroutput>
-files, as these will contain many blocks.  It is clearly futile
-to use it on damaged single-block files, since a damaged block
-cannot be recovered.  If you wish to minimise any potential data
-loss through media or transmission errors, you might consider
-compressing with a smaller block size.</para>
-
-</sect1>
-
-
-<sect1 id="performance" xreflabel="PERFORMANCE NOTES">
-<title>PERFORMANCE NOTES</title>
-
-<para>The sorting phase of compression gathers together similar
-strings in the file.  Because of this, files containing very long
-runs of repeated symbols, like "aabaabaabaab ..."  (repeated
-several hundred times) may compress more slowly than normal.
-Versions 0.9.5 and above fare much better than previous versions
-in this respect.  The ratio between worst-case and average-case
-compression time is in the region of 10:1.  For previous
-versions, this figure was more like 100:1.  You can use the
-<computeroutput>-vvvv</computeroutput> option to monitor progress
-in great detail, if you want.</para>
-
-<para>Decompression speed is unaffected by these
-phenomena.</para>
-
-<para><computeroutput>bzip2</computeroutput> usually allocates
-several megabytes of memory to operate in, and then charges all
-over it in a fairly random fashion.  This means that performance,
-both for compressing and decompressing, is largely determined by
-the speed at which your machine can service cache misses.
-Because of this, small changes to the code to reduce the miss
-rate have been observed to give disproportionately large
-performance improvements.  I imagine
-<computeroutput>bzip2</computeroutput> will perform best on
-machines with very large caches.</para>
-
-</sect1>
-
-
-
-<sect1 id="caveats" xreflabel="CAVEATS">
-<title>CAVEATS</title>
-
-<para>I/O error messages are not as helpful as they could be.
-<computeroutput>bzip2</computeroutput> tries hard to detect I/O
-errors and exit cleanly, but the details of what the problem is
-sometimes seem rather misleading.</para>
-
-<para>This manual page pertains to version &bz-version; of
-<computeroutput>bzip2</computeroutput>.  Compressed data created
-by this version is entirely forwards and backwards compatible
-with the previous public releases, versions 0.1pl2, 0.9.0 and
-0.9.5, 1.0.0, 1.0.1 and 1.0.2, but with the following exception: 0.9.0
-and above can correctly decompress multiple concatenated
-compressed files.  0.1pl2 cannot do this; it will stop after
-decompressing just the first file in the stream.</para>
-
-<para><computeroutput>bzip2recover</computeroutput> versions
-prior to 1.0.2 used 32-bit integers to represent bit positions in
-compressed files, so it could not handle compressed files more
-than 512 megabytes long.  Versions 1.0.2 and above use 64-bit ints
-on some platforms which support them (GNU supported targets, and
-Windows). To establish whether or not
-<computeroutput>bzip2recover</computeroutput> was built with such
-a limitation, run it without arguments. In any event you can
-build yourself an unlimited version if you can recompile it with
-<computeroutput>MaybeUInt64</computeroutput> set to be an
-unsigned 64-bit integer.</para>
-
-</sect1>
-
-
-
-<sect1 id="author" xreflabel="AUTHOR">
-<title>AUTHOR</title>
-
-<para>Julian Seward,
-<computeroutput>&bz-email;</computeroutput></para>
-
-<para>The ideas embodied in
-<computeroutput>bzip2</computeroutput> are due to (at least) the
-following people: Michael Burrows and David Wheeler (for the
-block sorting transformation), David Wheeler (again, for the
-Huffman coder), Peter Fenwick (for the structured coding model in
-the original <computeroutput>bzip</computeroutput>, and many
-refinements), and Alistair Moffat, Radford Neal and Ian Witten
-(for the arithmetic coder in the original
-<computeroutput>bzip</computeroutput>).  I am much indebted for
-their help, support and advice.  See the manual in the source
-distribution for pointers to sources of documentation.  Christian
-von Roques encouraged me to look for faster sorting algorithms,
-so as to speed up compression.  Bela Lubkin encouraged me to
-improve the worst-case compression performance.  
-Donna Robinson XMLised the documentation.
-Many people sent
-patches, helped with portability problems, lent machines, gave
-advice and were generally helpful.</para>
-
-</sect1>
-
-</chapter>
-
-
-
-<chapter id="libprog" xreflabel="Programming with libbzip2">
-<title>
-Programming with <computeroutput>libbzip2</computeroutput>
-</title>
-
-<para>This chapter describes the programming interface to
-<computeroutput>libbzip2</computeroutput>.</para>
-
-<para>For general background information, particularly about
-memory use and performance aspects, you'd be well advised to read
-<xref linkend="using"/> as well.</para>
-
-
-<sect1 id="top-level" xreflabel="Top-level structure">
-<title>Top-level structure</title>
-
-<para><computeroutput>libbzip2</computeroutput> is a flexible
-library for compressing and decompressing data in the
-<computeroutput>bzip2</computeroutput> data format.  Although
-packaged as a single entity, it helps to regard the library as
-three separate parts: the low level interface, and the high level
-interface, and some utility functions.</para>
-
-<para>The structure of
-<computeroutput>libbzip2</computeroutput>'s interfaces is similar
-to that of Jean-loup Gailly's and Mark Adler's excellent
-<computeroutput>zlib</computeroutput> library.</para>
-
-<para>All externally visible symbols have names beginning
-<computeroutput>BZ2_</computeroutput>.  This is new in version
-1.0.  The intention is to minimise pollution of the namespaces of
-library clients.</para>
-
-<para>To use any part of the library, you need to
-<computeroutput>#include &lt;bzlib.h&gt;</computeroutput>
-into your sources.</para>
-
-
-
-<sect2 id="ll-summary" xreflabel="Low-level summary">
-<title>Low-level summary</title>
-
-<para>This interface provides services for compressing and
-decompressing data in memory.  There's no provision for dealing
-with files, streams or any other I/O mechanisms, just straight
-memory-to-memory work.  In fact, this part of the library can be
-compiled without inclusion of
-<computeroutput>stdio.h</computeroutput>, which may be helpful
-for embedded applications.</para>
-
-<para>The low-level part of the library has no global variables
-and is therefore thread-safe.</para>
-
-<para>Six routines make up the low level interface:
-<computeroutput>BZ2_bzCompressInit</computeroutput>,
-<computeroutput>BZ2_bzCompress</computeroutput>, and
-<computeroutput>BZ2_bzCompressEnd</computeroutput> for
-compression, and a corresponding trio
-<computeroutput>BZ2_bzDecompressInit</computeroutput>,
-<computeroutput>BZ2_bzDecompress</computeroutput> and
-<computeroutput>BZ2_bzDecompressEnd</computeroutput> for
-decompression.  The <computeroutput>*Init</computeroutput>
-functions allocate memory for compression/decompression and do
-other initialisations, whilst the
-<computeroutput>*End</computeroutput> functions close down
-operations and release memory.</para>
-
-<para>The real work is done by
-<computeroutput>BZ2_bzCompress</computeroutput> and
-<computeroutput>BZ2_bzDecompress</computeroutput>.  These
-compress and decompress data from a user-supplied input buffer to
-a user-supplied output buffer.  These buffers can be any size;
-arbitrary quantities of data are handled by making repeated calls
-to these functions.  This is a flexible mechanism allowing a
-consumer-pull style of activity, or producer-push, or a mixture
-of both.</para>
-
-</sect2>
-
-
-<sect2 id="hl-summary" xreflabel="High-level summary">
-<title>High-level summary</title>
-
-<para>This interface provides some handy wrappers around the
-low-level interface to facilitate reading and writing
-<computeroutput>bzip2</computeroutput> format files
-(<computeroutput>.bz2</computeroutput> files).  The routines
-provide hooks to facilitate reading files in which the
-<computeroutput>bzip2</computeroutput> data stream is embedded
-within some larger-scale file structure, or where there are
-multiple <computeroutput>bzip2</computeroutput> data streams
-concatenated end-to-end.</para>
-
-<para>For reading files,
-<computeroutput>BZ2_bzReadOpen</computeroutput>,
-<computeroutput>BZ2_bzRead</computeroutput>,
-<computeroutput>BZ2_bzReadClose</computeroutput> and 
-<computeroutput>BZ2_bzReadGetUnused</computeroutput> are
-supplied.  For writing files,
-<computeroutput>BZ2_bzWriteOpen</computeroutput>,
-<computeroutput>BZ2_bzWrite</computeroutput> and
-<computeroutput>BZ2_bzWriteFinish</computeroutput> are
-available.</para>
-
-<para>As with the low-level library, no global variables are used
-so the library is per se thread-safe.  However, if I/O errors
-occur whilst reading or writing the underlying compressed files,
-you may have to consult <computeroutput>errno</computeroutput> to
-determine the cause of the error.  In that case, you'd need a C
-library which correctly supports
-<computeroutput>errno</computeroutput> in a multithreaded
-environment.</para>
-
-<para>To make the library a little simpler and more portable,
-<computeroutput>BZ2_bzReadOpen</computeroutput> and
-<computeroutput>BZ2_bzWriteOpen</computeroutput> require you to
-pass them file handles (<computeroutput>FILE*</computeroutput>s)
-which have previously been opened for reading or writing
-respectively.  That avoids portability problems associated with
-file operations and file attributes, whilst not being much of an
-imposition on the programmer.</para>
-
-</sect2>
-
-
-<sect2 id="util-fns-summary" xreflabel="Utility functions summary">
-<title>Utility functions summary</title>
-
-<para>For very simple needs,
-<computeroutput>BZ2_bzBuffToBuffCompress</computeroutput> and
-<computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput> are
-provided.  These compress data in memory from one buffer to
-another buffer in a single function call.  You should assess
-whether these functions fulfill your memory-to-memory
-compression/decompression requirements before investing effort in
-understanding the more general but more complex low-level
-interface.</para>
-
-<para>Yoshioka Tsuneo
-(<computeroutput>QWF00133@niftyserve.or.jp</computeroutput> /
-<computeroutput>tsuneo-y@is.aist-nara.ac.jp</computeroutput>) has
-contributed some functions to give better
-<computeroutput>zlib</computeroutput> compatibility.  These
-functions are <computeroutput>BZ2_bzopen</computeroutput>,
-<computeroutput>BZ2_bzread</computeroutput>,
-<computeroutput>BZ2_bzwrite</computeroutput>,
-<computeroutput>BZ2_bzflush</computeroutput>,
-<computeroutput>BZ2_bzclose</computeroutput>,
-<computeroutput>BZ2_bzerror</computeroutput> and
-<computeroutput>BZ2_bzlibVersion</computeroutput>.  You may find
-these functions more convenient for simple file reading and
-writing, than those in the high-level interface.  These functions
-are not (yet) officially part of the library, and are minimally
-documented here.  If they break, you get to keep all the pieces.
-I hope to document them properly when time permits.</para>
-
-<para>Yoshioka also contributed modifications to allow the
-library to be built as a Windows DLL.</para>
-
-</sect2>
-
-</sect1>
-
-
-<sect1 id="err-handling" xreflabel="Error handling">
-<title>Error handling</title>
-
-<para>The library is designed to recover cleanly in all
-situations, including the worst-case situation of decompressing
-random data.  I'm not 100% sure that it can always do this, so
-you might want to add a signal handler to catch segmentation
-violations during decompression if you are feeling especially
-paranoid.  I would be interested in hearing more about the
-robustness of the library to corrupted compressed data.</para>
-
-<para>Version 1.0.3 more robust in this respect than any
-previous version.  Investigations with Valgrind (a tool for detecting
-problems with memory management) indicate
-that, at least for the few files I tested, all single-bit errors
-in the decompressed data are caught properly, with no
-segmentation faults, no uses of uninitialised data, no out of
-range reads or writes, and no infinite looping in the decompressor.
-So it's certainly pretty robust, although
-I wouldn't claim it to be totally bombproof.</para>
-
-<para>The file <computeroutput>bzlib.h</computeroutput> contains
-all definitions needed to use the library.  In particular, you
-should definitely not include
-<computeroutput>bzlib_private.h</computeroutput>.</para>
-
-<para>In <computeroutput>bzlib.h</computeroutput>, the various
-return values are defined.  The following list is not intended as
-an exhaustive description of the circumstances in which a given
-value may be returned -- those descriptions are given later.
-Rather, it is intended to convey the rough meaning of each return
-value.  The first five actions are normal and not intended to
-denote an error situation.</para>
-
-<variablelist>
-
- <varlistentry>
-  <term><computeroutput>BZ_OK</computeroutput></term>
-  <listitem><para>The requested action was completed
-   successfully.</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_RUN_OK, BZ_FLUSH_OK,
-    BZ_FINISH_OK</computeroutput></term>
-  <listitem><para>In 
-   <computeroutput>BZ2_bzCompress</computeroutput>, the requested
-   flush/finish/nothing-special action was completed
-   successfully.</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_STREAM_END</computeroutput></term>
-  <listitem><para>Compression of data was completed, or the
-   logical stream end was detected during
-   decompression.</para></listitem>
- </varlistentry>
-
-</variablelist>
-
-<para>The following return values indicate an error of some
-kind.</para>
-
-<variablelist>
-
- <varlistentry>
-  <term><computeroutput>BZ_CONFIG_ERROR</computeroutput></term>
-  <listitem><para>Indicates that the library has been improperly
-   compiled on your platform -- a major configuration error.
-   Specifically, it means that
-   <computeroutput>sizeof(char)</computeroutput>,
-   <computeroutput>sizeof(short)</computeroutput> and
-   <computeroutput>sizeof(int)</computeroutput> are not 1, 2 and
-   4 respectively, as they should be.  Note that the library
-   should still work properly on 64-bit platforms which follow
-   the LP64 programming model -- that is, where
-   <computeroutput>sizeof(long)</computeroutput> and
-   <computeroutput>sizeof(void*)</computeroutput> are 8.  Under
-   LP64, <computeroutput>sizeof(int)</computeroutput> is still 4,
-   so <computeroutput>libbzip2</computeroutput>, which doesn't
-   use the <computeroutput>long</computeroutput> type, is
-   OK.</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_SEQUENCE_ERROR</computeroutput></term>
-  <listitem><para>When using the library, it is important to call
-   the functions in the correct sequence and with data structures
-   (buffers etc) in the correct states.
-   <computeroutput>libbzip2</computeroutput> checks as much as it
-   can to ensure this is happening, and returns
-   <computeroutput>BZ_SEQUENCE_ERROR</computeroutput> if not.
-   Code which complies precisely with the function semantics, as
-   detailed below, should never receive this value; such an event
-   denotes buggy code which you should
-   investigate.</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_PARAM_ERROR</computeroutput></term>
-  <listitem><para>Returned when a parameter to a function call is
-   out of range or otherwise manifestly incorrect.  As with
-   <computeroutput>BZ_SEQUENCE_ERROR</computeroutput>, this
-   denotes a bug in the client code.  The distinction between
-   <computeroutput>BZ_PARAM_ERROR</computeroutput> and
-   <computeroutput>BZ_SEQUENCE_ERROR</computeroutput> is a bit
-   hazy, but still worth making.</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_MEM_ERROR</computeroutput></term>
-  <listitem><para>Returned when a request to allocate memory
-   failed.  Note that the quantity of memory needed to decompress
-   a stream cannot be determined until the stream's header has
-   been read.  So
-   <computeroutput>BZ2_bzDecompress</computeroutput> and
-   <computeroutput>BZ2_bzRead</computeroutput> may return
-   <computeroutput>BZ_MEM_ERROR</computeroutput> even though some
-   of the compressed data has been read.  The same is not true
-   for compression; once
-   <computeroutput>BZ2_bzCompressInit</computeroutput> or
-   <computeroutput>BZ2_bzWriteOpen</computeroutput> have
-   successfully completed,
-   <computeroutput>BZ_MEM_ERROR</computeroutput> cannot
-   occur.</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_DATA_ERROR</computeroutput></term>
-  <listitem><para>Returned when a data integrity error is
-   detected during decompression.  Most importantly, this means
-   when stored and computed CRCs for the data do not match.  This
-   value is also returned upon detection of any other anomaly in
-   the compressed data.</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_DATA_ERROR_MAGIC</computeroutput></term>
-  <listitem><para>As a special case of
-   <computeroutput>BZ_DATA_ERROR</computeroutput>, it is
-   sometimes useful to know when the compressed stream does not
-   start with the correct magic bytes (<computeroutput>'B' 'Z'
-   'h'</computeroutput>).</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_IO_ERROR</computeroutput></term>
-  <listitem><para>Returned by
-   <computeroutput>BZ2_bzRead</computeroutput> and
-   <computeroutput>BZ2_bzWrite</computeroutput> when there is an
-   error reading or writing in the compressed file, and by
-   <computeroutput>BZ2_bzReadOpen</computeroutput> and
-   <computeroutput>BZ2_bzWriteOpen</computeroutput> for attempts
-   to use a file for which the error indicator (viz,
-   <computeroutput>ferror(f)</computeroutput>) is set.  On
-   receipt of <computeroutput>BZ_IO_ERROR</computeroutput>, the
-   caller should consult <computeroutput>errno</computeroutput>
-   and/or <computeroutput>perror</computeroutput> to acquire
-   operating-system specific information about the
-   problem.</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_UNEXPECTED_EOF</computeroutput></term>
-  <listitem><para>Returned by
-   <computeroutput>BZ2_bzRead</computeroutput> when the
-   compressed file finishes before the logical end of stream is
-   detected.</para></listitem>
- </varlistentry>
-
- <varlistentry>
-  <term><computeroutput>BZ_OUTBUFF_FULL</computeroutput></term>
-  <listitem><para>Returned by
-   <computeroutput>BZ2_bzBuffToBuffCompress</computeroutput> and
-   <computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput> to
-   indicate that the output data will not fit into the output
-   buffer provided.</para></listitem>
- </varlistentry>
-
-</variablelist>
-
-</sect1>
-
-
-
-<sect1 id="low-level" xreflabel=">Low-level interface">
-<title>Low-level interface</title>
-
-
-<sect2 id="bzcompress-init" xreflabel="BZ2_bzCompressInit">
-<title><computeroutput>BZ2_bzCompressInit</computeroutput></title>
-
-<programlisting>
-typedef struct {
-  char *next_in;
-  unsigned int avail_in;
-  unsigned int total_in_lo32;
-  unsigned int total_in_hi32;
-
-  char *next_out;
-  unsigned int avail_out;
-  unsigned int total_out_lo32;
-  unsigned int total_out_hi32;
-
-  void *state;
-
-  void *(*bzalloc)(void *,int,int);
-  void (*bzfree)(void *,void *);
-  void *opaque;
-} bz_stream;
-
-int BZ2_bzCompressInit ( bz_stream *strm, 
-                         int blockSize100k, 
-                         int verbosity,
-                         int workFactor );
-</programlisting>
-
-<para>Prepares for compression.  The
-<computeroutput>bz_stream</computeroutput> structure holds all
-data pertaining to the compression activity.  A
-<computeroutput>bz_stream</computeroutput> structure should be
-allocated and initialised prior to the call.  The fields of
-<computeroutput>bz_stream</computeroutput> comprise the entirety
-of the user-visible data.  <computeroutput>state</computeroutput>
-is a pointer to the private data structures required for
-compression.</para>
-
-<para>Custom memory allocators are supported, via fields
-<computeroutput>bzalloc</computeroutput>,
-<computeroutput>bzfree</computeroutput>, and
-<computeroutput>opaque</computeroutput>.  The value
-<computeroutput>opaque</computeroutput> is passed to as the first
-argument to all calls to <computeroutput>bzalloc</computeroutput>
-and <computeroutput>bzfree</computeroutput>, but is otherwise
-ignored by the library.  The call <computeroutput>bzalloc (
-opaque, n, m )</computeroutput> is expected to return a pointer
-<computeroutput>p</computeroutput> to <computeroutput>n *
-m</computeroutput> bytes of memory, and <computeroutput>bzfree (
-opaque, p )</computeroutput> should free that memory.</para>
-
-<para>If you don't want to use a custom memory allocator, set
-<computeroutput>bzalloc</computeroutput>,
-<computeroutput>bzfree</computeroutput> and
-<computeroutput>opaque</computeroutput> to
-<computeroutput>NULL</computeroutput>, and the library will then
-use the standard <computeroutput>malloc</computeroutput> /
-<computeroutput>free</computeroutput> routines.</para>
-
-<para>Before calling
-<computeroutput>BZ2_bzCompressInit</computeroutput>, fields
-<computeroutput>bzalloc</computeroutput>,
-<computeroutput>bzfree</computeroutput> and
-<computeroutput>opaque</computeroutput> should be filled
-appropriately, as just described.  Upon return, the internal
-state will have been allocated and initialised, and
-<computeroutput>total_in_lo32</computeroutput>,
-<computeroutput>total_in_hi32</computeroutput>,
-<computeroutput>total_out_lo32</computeroutput> and
-<computeroutput>total_out_hi32</computeroutput> will have been
-set to zero.  These four fields are used by the library to inform
-the caller of the total amount of data passed into and out of the
-library, respectively.  You should not try to change them.  As of
-version 1.0, 64-bit counts are maintained, even on 32-bit
-platforms, using the <computeroutput>_hi32</computeroutput>
-fields to store the upper 32 bits of the count.  So, for example,
-the total amount of data in is <computeroutput>(total_in_hi32
-&#60;&#60; 32) + total_in_lo32</computeroutput>.</para>
-
-<para>Parameter <computeroutput>blockSize100k</computeroutput>
-specifies the block size to be used for compression.  It should
-be a value between 1 and 9 inclusive, and the actual block size
-used is 100000 x this figure.  9 gives the best compression but
-takes most memory.</para>
-
-<para>Parameter <computeroutput>verbosity</computeroutput> should
-be set to a number between 0 and 4 inclusive.  0 is silent, and
-greater numbers give increasingly verbose monitoring/debugging
-output.  If the library has been compiled with
-<computeroutput>-DBZ_NO_STDIO</computeroutput>, no such output
-will appear for any verbosity setting.</para>
-
-<para>Parameter <computeroutput>workFactor</computeroutput>
-controls how the compression phase behaves when presented with
-worst case, highly repetitive, input data.  If compression runs
-into difficulties caused by repetitive data, the library switches
-from the standard sorting algorithm to a fallback algorithm.  The
-fallback is slower than the standard algorithm by perhaps a
-factor of three, but always behaves reasonably, no matter how bad
-the input.</para>
-
-<para>Lower values of <computeroutput>workFactor</computeroutput>
-reduce the amount of effort the standard algorithm will expend
-before resorting to the fallback.  You should set this parameter
-carefully; too low, and many inputs will be handled by the
-fallback algorithm and so compress rather slowly, too high, and
-your average-to-worst case compression times can become very
-large.  The default value of 30 gives reasonable behaviour over a
-wide range of circumstances.</para>
-
-<para>Allowable values range from 0 to 250 inclusive.  0 is a
-special case, equivalent to using the default value of 30.</para>
-
-<para>Note that the compressed output generated is the same
-regardless of whether or not the fallback algorithm is
-used.</para>
-
-<para>Be aware also that this parameter may disappear entirely in
-future versions of the library.  In principle it should be
-possible to devise a good way to automatically choose which
-algorithm to use.  Such a mechanism would render the parameter
-obsolete.</para>
-
-<para>Possible return values:</para>
-
-<programlisting>
-BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if strm is NULL 
-  or blockSize < 1 or blockSize > 9
-  or verbosity < 0 or verbosity > 4
-  or workFactor < 0 or workFactor > 250
-BZ_MEM_ERROR 
-  if not enough memory is available
-BZ_OK 
-  otherwise
-</programlisting>
-
-<para>Allowable next actions:</para>
-
-<programlisting>
-BZ2_bzCompress
-  if BZ_OK is returned
-  no specific action needed in case of error
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzCompress" xreflabel="BZ2_bzCompress">
-<title><computeroutput>BZ2_bzCompress</computeroutput></title>
-
-<programlisting>
-int BZ2_bzCompress ( bz_stream *strm, int action );
-</programlisting>
-
-<para>Provides more input and/or output buffer space for the
-library.  The caller maintains input and output buffers, and
-calls <computeroutput>BZ2_bzCompress</computeroutput> to transfer
-data between them.</para>
-
-<para>Before each call to
-<computeroutput>BZ2_bzCompress</computeroutput>,
-<computeroutput>next_in</computeroutput> should point at the data
-to be compressed, and <computeroutput>avail_in</computeroutput>
-should indicate how many bytes the library may read.
-<computeroutput>BZ2_bzCompress</computeroutput> updates
-<computeroutput>next_in</computeroutput>,
-<computeroutput>avail_in</computeroutput> and
-<computeroutput>total_in</computeroutput> to reflect the number
-of bytes it has read.</para>
-
-<para>Similarly, <computeroutput>next_out</computeroutput> should
-point to a buffer in which the compressed data is to be placed,
-with <computeroutput>avail_out</computeroutput> indicating how
-much output space is available.
-<computeroutput>BZ2_bzCompress</computeroutput> updates
-<computeroutput>next_out</computeroutput>,
-<computeroutput>avail_out</computeroutput> and
-<computeroutput>total_out</computeroutput> to reflect the number
-of bytes output.</para>
-
-<para>You may provide and remove as little or as much data as you
-like on each call of
-<computeroutput>BZ2_bzCompress</computeroutput>.  In the limit,
-it is acceptable to supply and remove data one byte at a time,
-although this would be terribly inefficient.  You should always
-ensure that at least one byte of output space is available at
-each call.</para>
-
-<para>A second purpose of
-<computeroutput>BZ2_bzCompress</computeroutput> is to request a
-change of mode of the compressed stream.</para>
-
-<para>Conceptually, a compressed stream can be in one of four
-states: IDLE, RUNNING, FLUSHING and FINISHING.  Before
-initialisation
-(<computeroutput>BZ2_bzCompressInit</computeroutput>) and after
-termination (<computeroutput>BZ2_bzCompressEnd</computeroutput>),
-a stream is regarded as IDLE.</para>
-
-<para>Upon initialisation
-(<computeroutput>BZ2_bzCompressInit</computeroutput>), the stream
-is placed in the RUNNING state.  Subsequent calls to
-<computeroutput>BZ2_bzCompress</computeroutput> should pass
-<computeroutput>BZ_RUN</computeroutput> as the requested action;
-other actions are illegal and will result in
-<computeroutput>BZ_SEQUENCE_ERROR</computeroutput>.</para>
-
-<para>At some point, the calling program will have provided all
-the input data it wants to.  It will then want to finish up -- in
-effect, asking the library to process any data it might have
-buffered internally.  In this state,
-<computeroutput>BZ2_bzCompress</computeroutput> will no longer
-attempt to read data from
-<computeroutput>next_in</computeroutput>, but it will want to
-write data to <computeroutput>next_out</computeroutput>.  Because
-the output buffer supplied by the user can be arbitrarily small,
-the finishing-up operation cannot necessarily be done with a
-single call of
-<computeroutput>BZ2_bzCompress</computeroutput>.</para>
-
-<para>Instead, the calling program passes
-<computeroutput>BZ_FINISH</computeroutput> as an action to
-<computeroutput>BZ2_bzCompress</computeroutput>.  This changes
-the stream's state to FINISHING.  Any remaining input (ie,
-<computeroutput>next_in[0 .. avail_in-1]</computeroutput>) is
-compressed and transferred to the output buffer.  To do this,
-<computeroutput>BZ2_bzCompress</computeroutput> must be called
-repeatedly until all the output has been consumed.  At that
-point, <computeroutput>BZ2_bzCompress</computeroutput> returns
-<computeroutput>BZ_STREAM_END</computeroutput>, and the stream's
-state is set back to IDLE.
-<computeroutput>BZ2_bzCompressEnd</computeroutput> should then be
-called.</para>
-
-<para>Just to make sure the calling program does not cheat, the
-library makes a note of <computeroutput>avail_in</computeroutput>
-at the time of the first call to
-<computeroutput>BZ2_bzCompress</computeroutput> which has
-<computeroutput>BZ_FINISH</computeroutput> as an action (ie, at
-the time the program has announced its intention to not supply
-any more input).  By comparing this value with that of
-<computeroutput>avail_in</computeroutput> over subsequent calls
-to <computeroutput>BZ2_bzCompress</computeroutput>, the library
-can detect any attempts to slip in more data to compress.  Any
-calls for which this is detected will return
-<computeroutput>BZ_SEQUENCE_ERROR</computeroutput>.  This
-indicates a programming mistake which should be corrected.</para>
-
-<para>Instead of asking to finish, the calling program may ask
-<computeroutput>BZ2_bzCompress</computeroutput> to take all the
-remaining input, compress it and terminate the current
-(Burrows-Wheeler) compression block.  This could be useful for
-error control purposes.  The mechanism is analogous to that for
-finishing: call <computeroutput>BZ2_bzCompress</computeroutput>
-with an action of <computeroutput>BZ_FLUSH</computeroutput>,
-remove output data, and persist with the
-<computeroutput>BZ_FLUSH</computeroutput> action until the value
-<computeroutput>BZ_RUN</computeroutput> is returned.  As with
-finishing, <computeroutput>BZ2_bzCompress</computeroutput>
-detects any attempt to provide more input data once the flush has
-begun.</para>
-
-<para>Once the flush is complete, the stream returns to the
-normal RUNNING state.</para>
-
-<para>This all sounds pretty complex, but isn't really.  Here's a
-table which shows which actions are allowable in each state, what
-action will be taken, what the next state is, and what the
-non-error return values are.  Note that you can't explicitly ask
-what state the stream is in, but nor do you need to -- it can be
-inferred from the values returned by
-<computeroutput>BZ2_bzCompress</computeroutput>.</para>
-
-<programlisting>
-IDLE/any
-  Illegal.  IDLE state only exists after BZ2_bzCompressEnd or
-  before BZ2_bzCompressInit.
-  Return value = BZ_SEQUENCE_ERROR
-
-RUNNING/BZ_RUN
-  Compress from next_in to next_out as much as possible.
-  Next state = RUNNING
-  Return value = BZ_RUN_OK
-
-RUNNING/BZ_FLUSH
-  Remember current value of next_in. Compress from next_in
-  to next_out as much as possible, but do not accept any more input.
-  Next state = FLUSHING
-  Return value = BZ_FLUSH_OK
-
-RUNNING/BZ_FINISH
-  Remember current value of next_in. Compress from next_in
-  to next_out as much as possible, but do not accept any more input.
-  Next state = FINISHING
-  Return value = BZ_FINISH_OK
-
-FLUSHING/BZ_FLUSH
-  Compress from next_in to next_out as much as possible, 
-  but do not accept any more input.
-  If all the existing input has been used up and all compressed
-  output has been removed
-    Next state = RUNNING; Return value = BZ_RUN_OK
-  else
-    Next state = FLUSHING; Return value = BZ_FLUSH_OK
-
-FLUSHING/other     
-  Illegal.
-  Return value = BZ_SEQUENCE_ERROR
-
-FINISHING/BZ_FINISH
-  Compress from next_in to next_out as much as possible,
-  but to not accept any more input.  
-  If all the existing input has been used up and all compressed
-  output has been removed
-    Next state = IDLE; Return value = BZ_STREAM_END
-  else
-    Next state = FINISHING; Return value = BZ_FINISHING
-
-FINISHING/other
-  Illegal.
-  Return value = BZ_SEQUENCE_ERROR
-</programlisting>
-
-
-<para>That still looks complicated?  Well, fair enough.  The
-usual sequence of calls for compressing a load of data is:</para>
-
-<orderedlist>
-
- <listitem><para>Get started with
-  <computeroutput>BZ2_bzCompressInit</computeroutput>.</para></listitem>
-
- <listitem><para>Shovel data in and shlurp out its compressed form
-  using zero or more calls of
-  <computeroutput>BZ2_bzCompress</computeroutput> with action =
-  <computeroutput>BZ_RUN</computeroutput>.</para></listitem>
-
- <listitem><para>Finish up. Repeatedly call
-  <computeroutput>BZ2_bzCompress</computeroutput> with action =
-  <computeroutput>BZ_FINISH</computeroutput>, copying out the
-  compressed output, until
-  <computeroutput>BZ_STREAM_END</computeroutput> is
-  returned.</para></listitem> <listitem><para>Close up and go home.  Call
-  <computeroutput>BZ2_bzCompressEnd</computeroutput>.</para></listitem>
-
-</orderedlist>
-
-<para>If the data you want to compress fits into your input
-buffer all at once, you can skip the calls of
-<computeroutput>BZ2_bzCompress ( ..., BZ_RUN )</computeroutput>
-and just do the <computeroutput>BZ2_bzCompress ( ..., BZ_FINISH
-)</computeroutput> calls.</para>
-
-<para>All required memory is allocated by
-<computeroutput>BZ2_bzCompressInit</computeroutput>.  The
-compression library can accept any data at all (obviously).  So
-you shouldn't get any error return values from the
-<computeroutput>BZ2_bzCompress</computeroutput> calls.  If you
-do, they will be
-<computeroutput>BZ_SEQUENCE_ERROR</computeroutput>, and indicate
-a bug in your programming.</para>
-
-<para>Trivial other possible return values:</para>
-
-<programlisting>
-BZ_PARAM_ERROR
-  if strm is NULL, or strm->s is NULL
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzCompress-end" xreflabel="BZ2_bzCompressEnd">
-<title><computeroutput>BZ2_bzCompressEnd</computeroutput></title>
-
-<programlisting>
-int BZ2_bzCompressEnd ( bz_stream *strm );
-</programlisting>
-
-<para>Releases all memory associated with a compression
-stream.</para>
-
-<para>Possible return values:</para>
-
-<programlisting>
-BZ_PARAM_ERROR  if strm is NULL or strm->s is NULL
-BZ_OK           otherwise
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzDecompress-init" xreflabel="BZ2_bzDecompressInit">
-<title><computeroutput>BZ2_bzDecompressInit</computeroutput></title>
-
-<programlisting>
-int BZ2_bzDecompressInit ( bz_stream *strm, int verbosity, int small );
-</programlisting>
-
-<para>Prepares for decompression.  As with
-<computeroutput>BZ2_bzCompressInit</computeroutput>, a
-<computeroutput>bz_stream</computeroutput> record should be
-allocated and initialised before the call.  Fields
-<computeroutput>bzalloc</computeroutput>,
-<computeroutput>bzfree</computeroutput> and
-<computeroutput>opaque</computeroutput> should be set if a custom
-memory allocator is required, or made
-<computeroutput>NULL</computeroutput> for the normal
-<computeroutput>malloc</computeroutput> /
-<computeroutput>free</computeroutput> routines.  Upon return, the
-internal state will have been initialised, and
-<computeroutput>total_in</computeroutput> and
-<computeroutput>total_out</computeroutput> will be zero.</para>
-
-<para>For the meaning of parameter
-<computeroutput>verbosity</computeroutput>, see
-<computeroutput>BZ2_bzCompressInit</computeroutput>.</para>
-
-<para>If <computeroutput>small</computeroutput> is nonzero, the
-library will use an alternative decompression algorithm which
-uses less memory but at the cost of decompressing more slowly
-(roughly speaking, half the speed, but the maximum memory
-requirement drops to around 2300k).  See <xref linkend="using"/>
-for more information on memory management.</para>
-
-<para>Note that the amount of memory needed to decompress a
-stream cannot be determined until the stream's header has been
-read, so even if
-<computeroutput>BZ2_bzDecompressInit</computeroutput> succeeds, a
-subsequent <computeroutput>BZ2_bzDecompress</computeroutput>
-could fail with
-<computeroutput>BZ_MEM_ERROR</computeroutput>.</para>
-
-<para>Possible return values:</para>
-
-<programlisting>
-BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if ( small != 0 && small != 1 )
-  or (verbosity <; 0 || verbosity > 4)
-BZ_MEM_ERROR
-  if insufficient memory is available
-</programlisting>
-
-<para>Allowable next actions:</para>
-
-<programlisting>
-BZ2_bzDecompress
-  if BZ_OK was returned
-  no specific action required in case of error
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzDecompress" xreflabel="BZ2_bzDecompress">
-<title><computeroutput>BZ2_bzDecompress</computeroutput></title>
-
-<programlisting>
-int BZ2_bzDecompress ( bz_stream *strm );
-</programlisting>
-
-<para>Provides more input and/out output buffer space for the
-library.  The caller maintains input and output buffers, and uses
-<computeroutput>BZ2_bzDecompress</computeroutput> to transfer
-data between them.</para>
-
-<para>Before each call to
-<computeroutput>BZ2_bzDecompress</computeroutput>,
-<computeroutput>next_in</computeroutput> should point at the
-compressed data, and <computeroutput>avail_in</computeroutput>
-should indicate how many bytes the library may read.
-<computeroutput>BZ2_bzDecompress</computeroutput> updates
-<computeroutput>next_in</computeroutput>,
-<computeroutput>avail_in</computeroutput> and
-<computeroutput>total_in</computeroutput> to reflect the number
-of bytes it has read.</para>
-
-<para>Similarly, <computeroutput>next_out</computeroutput> should
-point to a buffer in which the uncompressed output is to be
-placed, with <computeroutput>avail_out</computeroutput>
-indicating how much output space is available.
-<computeroutput>BZ2_bzCompress</computeroutput> updates
-<computeroutput>next_out</computeroutput>,
-<computeroutput>avail_out</computeroutput> and
-<computeroutput>total_out</computeroutput> to reflect the number
-of bytes output.</para>
-
-<para>You may provide and remove as little or as much data as you
-like on each call of
-<computeroutput>BZ2_bzDecompress</computeroutput>.  In the limit,
-it is acceptable to supply and remove data one byte at a time,
-although this would be terribly inefficient.  You should always
-ensure that at least one byte of output space is available at
-each call.</para>
-
-<para>Use of <computeroutput>BZ2_bzDecompress</computeroutput> is
-simpler than
-<computeroutput>BZ2_bzCompress</computeroutput>.</para>
-
-<para>You should provide input and remove output as described
-above, and repeatedly call
-<computeroutput>BZ2_bzDecompress</computeroutput> until
-<computeroutput>BZ_STREAM_END</computeroutput> is returned.
-Appearance of <computeroutput>BZ_STREAM_END</computeroutput>
-denotes that <computeroutput>BZ2_bzDecompress</computeroutput>
-has detected the logical end of the compressed stream.
-<computeroutput>BZ2_bzDecompress</computeroutput> will not
-produce <computeroutput>BZ_STREAM_END</computeroutput> until all
-output data has been placed into the output buffer, so once
-<computeroutput>BZ_STREAM_END</computeroutput> appears, you are
-guaranteed to have available all the decompressed output, and
-<computeroutput>BZ2_bzDecompressEnd</computeroutput> can safely
-be called.</para>
-
-<para>If case of an error return value, you should call
-<computeroutput>BZ2_bzDecompressEnd</computeroutput> to clean up
-and release memory.</para>
-
-<para>Possible return values:</para>
-
-<programlisting>
-BZ_PARAM_ERROR
-  if strm is NULL or strm->s is NULL
-  or strm->avail_out < 1
-BZ_DATA_ERROR
-  if a data integrity error is detected in the compressed stream
-BZ_DATA_ERROR_MAGIC
-  if the compressed stream doesn't begin with the right magic bytes
-BZ_MEM_ERROR
-  if there wasn't enough memory available
-BZ_STREAM_END
-  if the logical end of the data stream was detected and all
-  output in has been consumed, eg s-->avail_out > 0
-BZ_OK
-  otherwise
-</programlisting>
-
-<para>Allowable next actions:</para>
-
-<programlisting>
-BZ2_bzDecompress
-  if BZ_OK was returned
-BZ2_bzDecompressEnd
-  otherwise
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzDecompress-end" xreflabel="BZ2_bzDecompressEnd">
-<title><computeroutput>BZ2_bzDecompressEnd</computeroutput></title>
-
-<programlisting>
-int BZ2_bzDecompressEnd ( bz_stream *strm );
-</programlisting>
-
-<para>Releases all memory associated with a decompression
-stream.</para>
-
-<para>Possible return values:</para>
-
-<programlisting>
-BZ_PARAM_ERROR
-  if strm is NULL or strm->s is NULL
-BZ_OK
-  otherwise
-</programlisting>
-
-<para>Allowable next actions:</para>
-
-<programlisting>
-  None.
-</programlisting>
-
-</sect2>
-
-</sect1>
-
-
-<sect1 id="hl-interface" xreflabel="High-level interface">
-<title>High-level interface</title>
-
-<para>This interface provides functions for reading and writing
-<computeroutput>bzip2</computeroutput> format files.  First, some
-general points.</para>
-
-<itemizedlist mark='bullet'>
-
- <listitem><para>All of the functions take an
-  <computeroutput>int*</computeroutput> first argument,
-  <computeroutput>bzerror</computeroutput>.  After each call,
-  <computeroutput>bzerror</computeroutput> should be consulted
-  first to determine the outcome of the call.  If
-  <computeroutput>bzerror</computeroutput> is
-  <computeroutput>BZ_OK</computeroutput>, the call completed
-  successfully, and only then should the return value of the
-  function (if any) be consulted.  If
-  <computeroutput>bzerror</computeroutput> is
-  <computeroutput>BZ_IO_ERROR</computeroutput>, there was an
-  error reading/writing the underlying compressed file, and you
-  should then consult <computeroutput>errno</computeroutput> /
-  <computeroutput>perror</computeroutput> to determine the cause
-  of the difficulty.  <computeroutput>bzerror</computeroutput>
-  may also be set to various other values; precise details are
-  given on a per-function basis below.</para></listitem>
-
- <listitem><para>If <computeroutput>bzerror</computeroutput> indicates
-  an error (ie, anything except
-  <computeroutput>BZ_OK</computeroutput> and
-  <computeroutput>BZ_STREAM_END</computeroutput>), you should
-  immediately call
-  <computeroutput>BZ2_bzReadClose</computeroutput> (or
-  <computeroutput>BZ2_bzWriteClose</computeroutput>, depending on
-  whether you are attempting to read or to write) to free up all
-  resources associated with the stream.  Once an error has been
-  indicated, behaviour of all calls except
-  <computeroutput>BZ2_bzReadClose</computeroutput>
-  (<computeroutput>BZ2_bzWriteClose</computeroutput>) is
-  undefined.  The implication is that (1)
-  <computeroutput>bzerror</computeroutput> should be checked
-  after each call, and (2) if
-  <computeroutput>bzerror</computeroutput> indicates an error,
-  <computeroutput>BZ2_bzReadClose</computeroutput>
-  (<computeroutput>BZ2_bzWriteClose</computeroutput>) should then
-  be called to clean up.</para></listitem>
-
- <listitem><para>The <computeroutput>FILE*</computeroutput> arguments
-  passed to <computeroutput>BZ2_bzReadOpen</computeroutput> /
-  <computeroutput>BZ2_bzWriteOpen</computeroutput> should be set
-  to binary mode.  Most Unix systems will do this by default, but
-  other platforms, including Windows and Mac, will not.  If you
-  omit this, you may encounter problems when moving code to new
-  platforms.</para></listitem>
-
- <listitem><para>Memory allocation requests are handled by
-  <computeroutput>malloc</computeroutput> /
-  <computeroutput>free</computeroutput>.  At present there is no
-  facility for user-defined memory allocators in the file I/O
-  functions (could easily be added, though).</para></listitem>
-
-</itemizedlist>
-
-
-
-<sect2 id="bzreadopen" xreflabel="BZ2_bzReadOpen">
-<title><computeroutput>BZ2_bzReadOpen</computeroutput></title>
-
-<programlisting>
-typedef void BZFILE;
-
-BZFILE *BZ2_bzReadOpen( int *bzerror, FILE *f, 
-                        int verbosity, int small,
-                        void *unused, int nUnused );
-</programlisting>
-
-<para>Prepare to read compressed data from file handle
-<computeroutput>f</computeroutput>.
-<computeroutput>f</computeroutput> should refer to a file which
-has been opened for reading, and for which the error indicator
-(<computeroutput>ferror(f)</computeroutput>)is not set.  If
-<computeroutput>small</computeroutput> is 1, the library will try
-to decompress using less memory, at the expense of speed.</para>
-
-<para>For reasons explained below,
-<computeroutput>BZ2_bzRead</computeroutput> will decompress the
-<computeroutput>nUnused</computeroutput> bytes starting at
-<computeroutput>unused</computeroutput>, before starting to read
-from the file <computeroutput>f</computeroutput>.  At most
-<computeroutput>BZ_MAX_UNUSED</computeroutput> bytes may be
-supplied like this.  If this facility is not required, you should
-pass <computeroutput>NULL</computeroutput> and
-<computeroutput>0</computeroutput> for
-<computeroutput>unused</computeroutput> and
-n<computeroutput>Unused</computeroutput> respectively.</para>
-
-<para>For the meaning of parameters
-<computeroutput>small</computeroutput> and
-<computeroutput>verbosity</computeroutput>, see
-<computeroutput>BZ2_bzDecompressInit</computeroutput>.</para>
-
-<para>The amount of memory needed to decompress a file cannot be
-determined until the file's header has been read.  So it is
-possible that <computeroutput>BZ2_bzReadOpen</computeroutput>
-returns <computeroutput>BZ_OK</computeroutput> but a subsequent
-call of <computeroutput>BZ2_bzRead</computeroutput> will return
-<computeroutput>BZ_MEM_ERROR</computeroutput>.</para>
-
-<para>Possible assignments to
-<computeroutput>bzerror</computeroutput>:</para>
-
-<programlisting>
-BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if f is NULL
-  or small is neither 0 nor 1
-  or ( unused == NULL && nUnused != 0 )
-  or ( unused != NULL && !(0 <= nUnused <= BZ_MAX_UNUSED) )
-BZ_IO_ERROR
-  if ferror(f) is nonzero
-BZ_MEM_ERROR
-  if insufficient memory is available
-BZ_OK
-  otherwise.
-</programlisting>
-
-<para>Possible return values:</para>
-
-<programlisting>
-Pointer to an abstract BZFILE
-  if bzerror is BZ_OK
-NULL
-  otherwise
-</programlisting>
-
-<para>Allowable next actions:</para>
-
-<programlisting>
-BZ2_bzRead
-  if bzerror is BZ_OK
-BZ2_bzClose
-  otherwise
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzread" xreflabel="BZ2_bzRead">
-<title><computeroutput>BZ2_bzRead</computeroutput></title>
-
-<programlisting>
-int BZ2_bzRead ( int *bzerror, BZFILE *b, void *buf, int len );
-</programlisting>
-
-<para>Reads up to <computeroutput>len</computeroutput>
-(uncompressed) bytes from the compressed file
-<computeroutput>b</computeroutput> into the buffer
-<computeroutput>buf</computeroutput>.  If the read was
-successful, <computeroutput>bzerror</computeroutput> is set to
-<computeroutput>BZ_OK</computeroutput> and the number of bytes
-read is returned.  If the logical end-of-stream was detected,
-<computeroutput>bzerror</computeroutput> will be set to
-<computeroutput>BZ_STREAM_END</computeroutput>, and the number of
-bytes read is returned.  All other
-<computeroutput>bzerror</computeroutput> values denote an
-error.</para>
-
-<para><computeroutput>BZ2_bzRead</computeroutput> will supply
-<computeroutput>len</computeroutput> bytes, unless the logical
-stream end is detected or an error occurs.  Because of this, it
-is possible to detect the stream end by observing when the number
-of bytes returned is less than the number requested.
-Nevertheless, this is regarded as inadvisable; you should instead
-check <computeroutput>bzerror</computeroutput> after every call
-and watch out for
-<computeroutput>BZ_STREAM_END</computeroutput>.</para>
-
-<para>Internally, <computeroutput>BZ2_bzRead</computeroutput>
-copies data from the compressed file in chunks of size
-<computeroutput>BZ_MAX_UNUSED</computeroutput> bytes before
-decompressing it.  If the file contains more bytes than strictly
-needed to reach the logical end-of-stream,
-<computeroutput>BZ2_bzRead</computeroutput> will almost certainly
-read some of the trailing data before signalling
-<computeroutput>BZ_SEQUENCE_END</computeroutput>.  To collect the
-read but unused data once
-<computeroutput>BZ_SEQUENCE_END</computeroutput> has appeared,
-call <computeroutput>BZ2_bzReadGetUnused</computeroutput>
-immediately before
-<computeroutput>BZ2_bzReadClose</computeroutput>.</para>
-
-<para>Possible assignments to
-<computeroutput>bzerror</computeroutput>:</para>
-
-<programlisting>
-BZ_PARAM_ERROR
-  if b is NULL or buf is NULL or len < 0
-BZ_SEQUENCE_ERROR
-  if b was opened with BZ2_bzWriteOpen
-BZ_IO_ERROR
-  if there is an error reading from the compressed file
-BZ_UNEXPECTED_EOF
-  if the compressed file ended before 
-  the logical end-of-stream was detected
-BZ_DATA_ERROR
-  if a data integrity error was detected in the compressed stream
-BZ_DATA_ERROR_MAGIC
-  if the stream does not begin with the requisite header bytes 
-  (ie, is not a bzip2 data file).  This is really 
-  a special case of BZ_DATA_ERROR.
-BZ_MEM_ERROR
-  if insufficient memory was available
-BZ_STREAM_END
-  if the logical end of stream was detected.
-BZ_OK
-  otherwise.
-</programlisting>
-
-<para>Possible return values:</para>
-
-<programlisting>
-number of bytes read
-  if bzerror is BZ_OK or BZ_STREAM_END
-undefined
-  otherwise
-</programlisting>
-
-<para>Allowable next actions:</para>
-
-<programlisting>
-collect data from buf, then BZ2_bzRead or BZ2_bzReadClose
-  if bzerror is BZ_OK
-collect data from buf, then BZ2_bzReadClose or BZ2_bzReadGetUnused
-  if bzerror is BZ_SEQUENCE_END
-BZ2_bzReadClose
-  otherwise
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzreadgetunused" xreflabel="BZ2_bzReadGetUnused">
-<title><computeroutput>BZ2_bzReadGetUnused</computeroutput></title>
-
-<programlisting>
-void BZ2_bzReadGetUnused( int* bzerror, BZFILE *b, 
-                          void** unused, int* nUnused );
-</programlisting>
-
-<para>Returns data which was read from the compressed file but
-was not needed to get to the logical end-of-stream.
-<computeroutput>*unused</computeroutput> is set to the address of
-the data, and <computeroutput>*nUnused</computeroutput> to the
-number of bytes.  <computeroutput>*nUnused</computeroutput> will
-be set to a value between <computeroutput>0</computeroutput> and
-<computeroutput>BZ_MAX_UNUSED</computeroutput> inclusive.</para>
-
-<para>This function may only be called once
-<computeroutput>BZ2_bzRead</computeroutput> has signalled
-<computeroutput>BZ_STREAM_END</computeroutput> but before
-<computeroutput>BZ2_bzReadClose</computeroutput>.</para>
-
-<para>Possible assignments to
-<computeroutput>bzerror</computeroutput>:</para>
-
-<programlisting>
-BZ_PARAM_ERROR
-  if b is NULL
-  or unused is NULL or nUnused is NULL
-BZ_SEQUENCE_ERROR
-  if BZ_STREAM_END has not been signalled
-  or if b was opened with BZ2_bzWriteOpen
-BZ_OK
-  otherwise
-</programlisting>
-
-<para>Allowable next actions:</para>
-
-<programlisting>
-BZ2_bzReadClose
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzreadclose" xreflabel="BZ2_bzReadClose">
-<title><computeroutput>BZ2_bzReadClose</computeroutput></title>
-
-<programlisting>
-void BZ2_bzReadClose ( int *bzerror, BZFILE *b );
-</programlisting>
-
-<para>Releases all memory pertaining to the compressed file
-<computeroutput>b</computeroutput>.
-<computeroutput>BZ2_bzReadClose</computeroutput> does not call
-<computeroutput>fclose</computeroutput> on the underlying file
-handle, so you should do that yourself if appropriate.
-<computeroutput>BZ2_bzReadClose</computeroutput> should be called
-to clean up after all error situations.</para>
-
-<para>Possible assignments to
-<computeroutput>bzerror</computeroutput>:</para>
-
-<programlisting>
-BZ_SEQUENCE_ERROR
-  if b was opened with BZ2_bzOpenWrite
-BZ_OK
-  otherwise
-</programlisting>
-
-<para>Allowable next actions:</para>
-
-<programlisting>
-none
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzwriteopen" xreflabel="BZ2_bzWriteOpen">
-<title><computeroutput>BZ2_bzWriteOpen</computeroutput></title>
-
-<programlisting>
-BZFILE *BZ2_bzWriteOpen( int *bzerror, FILE *f, 
-                         int blockSize100k, int verbosity,
-                         int workFactor );
-</programlisting>
-
-<para>Prepare to write compressed data to file handle
-<computeroutput>f</computeroutput>.
-<computeroutput>f</computeroutput> should refer to a file which
-has been opened for writing, and for which the error indicator
-(<computeroutput>ferror(f)</computeroutput>)is not set.</para>
-
-<para>For the meaning of parameters
-<computeroutput>blockSize100k</computeroutput>,
-<computeroutput>verbosity</computeroutput> and
-<computeroutput>workFactor</computeroutput>, see
-<computeroutput>BZ2_bzCompressInit</computeroutput>.</para>
-
-<para>All required memory is allocated at this stage, so if the
-call completes successfully,
-<computeroutput>BZ_MEM_ERROR</computeroutput> cannot be signalled
-by a subsequent call to
-<computeroutput>BZ2_bzWrite</computeroutput>.</para>
-
-<para>Possible assignments to
-<computeroutput>bzerror</computeroutput>:</para>
-
-<programlisting>
-BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if f is NULL
-  or blockSize100k < 1 or blockSize100k > 9
-BZ_IO_ERROR
-  if ferror(f) is nonzero
-BZ_MEM_ERROR
-  if insufficient memory is available
-BZ_OK
-  otherwise
-</programlisting>
-
-<para>Possible return values:</para>
-
-<programlisting>
-Pointer to an abstract BZFILE
-  if bzerror is BZ_OK
-NULL
-  otherwise
-</programlisting>
-
-<para>Allowable next actions:</para>
-
-<programlisting>
-BZ2_bzWrite
-  if bzerror is BZ_OK
-  (you could go directly to BZ2_bzWriteClose, but this would be pretty pointless)
-BZ2_bzWriteClose
-  otherwise
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzwrite" xreflabel="BZ2_bzWrite">
-<title><computeroutput>BZ2_bzWrite</computeroutput></title>
-
-<programlisting>
-void BZ2_bzWrite ( int *bzerror, BZFILE *b, void *buf, int len );
-</programlisting>
-
-<para>Absorbs <computeroutput>len</computeroutput> bytes from the
-buffer <computeroutput>buf</computeroutput>, eventually to be
-compressed and written to the file.</para>
-
-<para>Possible assignments to
-<computeroutput>bzerror</computeroutput>:</para>
-
-<programlisting>
-BZ_PARAM_ERROR
-  if b is NULL or buf is NULL or len < 0
-BZ_SEQUENCE_ERROR
-  if b was opened with BZ2_bzReadOpen
-BZ_IO_ERROR
-  if there is an error writing the compressed file.
-BZ_OK
-  otherwise
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzwriteclose" xreflabel="BZ2_bzWriteClose">
-<title><computeroutput>BZ2_bzWriteClose</computeroutput></title>
-
-<programlisting>
-void BZ2_bzWriteClose( int *bzerror, BZFILE* f,
-                       int abandon,
-                       unsigned int* nbytes_in,
-                       unsigned int* nbytes_out );
-
-void BZ2_bzWriteClose64( int *bzerror, BZFILE* f,
-                         int abandon,
-                         unsigned int* nbytes_in_lo32,
-                         unsigned int* nbytes_in_hi32,
-                         unsigned int* nbytes_out_lo32,
-                         unsigned int* nbytes_out_hi32 );
-</programlisting>
-
-<para>Compresses and flushes to the compressed file all data so
-far supplied by <computeroutput>BZ2_bzWrite</computeroutput>.
-The logical end-of-stream markers are also written, so subsequent
-calls to <computeroutput>BZ2_bzWrite</computeroutput> are
-illegal.  All memory associated with the compressed file
-<computeroutput>b</computeroutput> is released.
-<computeroutput>fflush</computeroutput> is called on the
-compressed file, but it is not
-<computeroutput>fclose</computeroutput>'d.</para>
-
-<para>If <computeroutput>BZ2_bzWriteClose</computeroutput> is
-called to clean up after an error, the only action is to release
-the memory.  The library records the error codes issued by
-previous calls, so this situation will be detected automatically.
-There is no attempt to complete the compression operation, nor to
-<computeroutput>fflush</computeroutput> the compressed file.  You
-can force this behaviour to happen even in the case of no error,
-by passing a nonzero value to
-<computeroutput>abandon</computeroutput>.</para>
-
-<para>If <computeroutput>nbytes_in</computeroutput> is non-null,
-<computeroutput>*nbytes_in</computeroutput> will be set to be the
-total volume of uncompressed data handled.  Similarly,
-<computeroutput>nbytes_out</computeroutput> will be set to the
-total volume of compressed data written.  For compatibility with
-older versions of the library,
-<computeroutput>BZ2_bzWriteClose</computeroutput> only yields the
-lower 32 bits of these counts.  Use
-<computeroutput>BZ2_bzWriteClose64</computeroutput> if you want
-the full 64 bit counts.  These two functions are otherwise
-absolutely identical.</para>
-
-<para>Possible assignments to
-<computeroutput>bzerror</computeroutput>:</para>
-
-<programlisting>
-BZ_SEQUENCE_ERROR
-  if b was opened with BZ2_bzReadOpen
-BZ_IO_ERROR
-  if there is an error writing the compressed file
-BZ_OK
-  otherwise
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="embed" xreflabel="Handling embedded compressed data streams">
-<title>Handling embedded compressed data streams</title>
-
-<para>The high-level library facilitates use of
-<computeroutput>bzip2</computeroutput> data streams which form
-some part of a surrounding, larger data stream.</para>
-
-<itemizedlist mark='bullet'>
-
- <listitem><para>For writing, the library takes an open file handle,
-  writes compressed data to it,
-  <computeroutput>fflush</computeroutput>es it but does not
-  <computeroutput>fclose</computeroutput> it.  The calling
-  application can write its own data before and after the
-  compressed data stream, using that same file handle.</para></listitem>
-
- <listitem><para>Reading is more complex, and the facilities are not as
-  general as they could be since generality is hard to reconcile
-  with efficiency.  <computeroutput>BZ2_bzRead</computeroutput>
-  reads from the compressed file in blocks of size
-  <computeroutput>BZ_MAX_UNUSED</computeroutput> bytes, and in
-  doing so probably will overshoot the logical end of compressed
-  stream.  To recover this data once decompression has ended,
-  call <computeroutput>BZ2_bzReadGetUnused</computeroutput> after
-  the last call of <computeroutput>BZ2_bzRead</computeroutput>
-  (the one returning
-  <computeroutput>BZ_STREAM_END</computeroutput>) but before
-  calling
-  <computeroutput>BZ2_bzReadClose</computeroutput>.</para></listitem>
-
-</itemizedlist>
-
-<para>This mechanism makes it easy to decompress multiple
-<computeroutput>bzip2</computeroutput> streams placed end-to-end.
-As the end of one stream, when
-<computeroutput>BZ2_bzRead</computeroutput> returns
-<computeroutput>BZ_STREAM_END</computeroutput>, call
-<computeroutput>BZ2_bzReadGetUnused</computeroutput> to collect
-the unused data (copy it into your own buffer somewhere).  That
-data forms the start of the next compressed stream.  To start
-uncompressing that next stream, call
-<computeroutput>BZ2_bzReadOpen</computeroutput> again, feeding in
-the unused data via the <computeroutput>unused</computeroutput> /
-<computeroutput>nUnused</computeroutput> parameters.  Keep doing
-this until <computeroutput>BZ_STREAM_END</computeroutput> return
-coincides with the physical end of file
-(<computeroutput>feof(f)</computeroutput>).  In this situation
-<computeroutput>BZ2_bzReadGetUnused</computeroutput> will of
-course return no data.</para>
-
-<para>This should give some feel for how the high-level interface
-can be used.  If you require extra flexibility, you'll have to
-bite the bullet and get to grips with the low-level
-interface.</para>
-
-</sect2>
-
-
-<sect2 id="std-rdwr" xreflabel="Standard file-reading/writing code">
-<title>Standard file-reading/writing code</title>
-
-<para>Here's how you'd write data to a compressed file:</para>
-
-<programlisting>
-FILE*   f;
-BZFILE* b;
-int     nBuf;
-char    buf[ /* whatever size you like */ ];
-int     bzerror;
-int     nWritten;
-
-f = fopen ( "myfile.bz2", "w" );
-if ( !f ) {
- /* handle error */
-}
-b = BZ2_bzWriteOpen( &bzerror, f, 9 );
-if (bzerror != BZ_OK) {
- BZ2_bzWriteClose ( b );
- /* handle error */
-}
-
-while ( /* condition */ ) {
- /* get data to write into buf, and set nBuf appropriately */
- nWritten = BZ2_bzWrite ( &bzerror, b, buf, nBuf );
- if (bzerror == BZ_IO_ERROR) { 
-   BZ2_bzWriteClose ( &bzerror, b );
-   /* handle error */
- }
-}
-
-BZ2_bzWriteClose( &bzerror, b );
-if (bzerror == BZ_IO_ERROR) {
- /* handle error */
-}
-</programlisting>
-
-<para>And to read from a compressed file:</para>
-
-<programlisting>
-FILE*   f;
-BZFILE* b;
-int     nBuf;
-char    buf[ /* whatever size you like */ ];
-int     bzerror;
-int     nWritten;
-
-f = fopen ( "myfile.bz2", "r" );
-if ( !f ) {
-  /* handle error */
-}
-b = BZ2_bzReadOpen ( &bzerror, f, 0, NULL, 0 );
-if ( bzerror != BZ_OK ) {
-  BZ2_bzReadClose ( &bzerror, b );
-  /* handle error */
-}
-
-bzerror = BZ_OK;
-while ( bzerror == BZ_OK && /* arbitrary other conditions */) {
-  nBuf = BZ2_bzRead ( &bzerror, b, buf, /* size of buf */ );
-  if ( bzerror == BZ_OK ) {
-    /* do something with buf[0 .. nBuf-1] */
-  }
-}
-if ( bzerror != BZ_STREAM_END ) {
-   BZ2_bzReadClose ( &bzerror, b );
-   /* handle error */
-} else {
-   BZ2_bzReadClose ( &bzerror );
-}
-</programlisting>
-
-</sect2>
-
-</sect1>
-
-
-<sect1 id="util-fns" xreflabel="Utility functions">
-<title>Utility functions</title>
-
-
-<sect2 id="bzbufftobuffcompress" xreflabel="BZ2_bzBuffToBuffCompress">
-<title><computeroutput>BZ2_bzBuffToBuffCompress</computeroutput></title>
-
-<programlisting>
-int BZ2_bzBuffToBuffCompress( char*         dest,
-                              unsigned int* destLen,
-                              char*         source,
-                              unsigned int  sourceLen,
-                              int           blockSize100k,
-                              int           verbosity,
-                              int           workFactor );
-</programlisting>
-
-<para>Attempts to compress the data in <computeroutput>source[0
-.. sourceLen-1]</computeroutput> into the destination buffer,
-<computeroutput>dest[0 .. *destLen-1]</computeroutput>.  If the
-destination buffer is big enough,
-<computeroutput>*destLen</computeroutput> is set to the size of
-the compressed data, and <computeroutput>BZ_OK</computeroutput>
-is returned.  If the compressed data won't fit,
-<computeroutput>*destLen</computeroutput> is unchanged, and
-<computeroutput>BZ_OUTBUFF_FULL</computeroutput> is
-returned.</para>
-
-<para>Compression in this manner is a one-shot event, done with a
-single call to this function.  The resulting compressed data is a
-complete <computeroutput>bzip2</computeroutput> format data
-stream.  There is no mechanism for making additional calls to
-provide extra input data.  If you want that kind of mechanism,
-use the low-level interface.</para>
-
-<para>For the meaning of parameters
-<computeroutput>blockSize100k</computeroutput>,
-<computeroutput>verbosity</computeroutput> and
-<computeroutput>workFactor</computeroutput>, see
-<computeroutput>BZ2_bzCompressInit</computeroutput>.</para>
-
-<para>To guarantee that the compressed data will fit in its
-buffer, allocate an output buffer of size 1% larger than the
-uncompressed data, plus six hundred extra bytes.</para>
-
-<para><computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput>
-will not write data at or beyond
-<computeroutput>dest[*destLen]</computeroutput>, even in case of
-buffer overflow.</para>
-
-<para>Possible return values:</para>
-
-<programlisting>
-BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if dest is NULL or destLen is NULL
-  or blockSize100k < 1 or blockSize100k > 9
-  or verbosity < 0 or verbosity > 4
-  or workFactor < 0 or workFactor > 250
-BZ_MEM_ERROR
-  if insufficient memory is available 
-BZ_OUTBUFF_FULL
-  if the size of the compressed data exceeds *destLen
-BZ_OK
-  otherwise
-</programlisting>
-
-</sect2>
-
-
-<sect2 id="bzbufftobuffdecompress" xreflabel="BZ2_bzBuffToBuffDecompress">
-<title><computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput></title>
-
-<programlisting>
-int BZ2_bzBuffToBuffDecompress( char*         dest,
-                                unsigned int* destLen,
-                                char*         source,
-                                unsigned int  sourceLen,
-                                int           small,
-                                int           verbosity );
-</programlisting>
-
-<para>Attempts to decompress the data in <computeroutput>source[0
-.. sourceLen-1]</computeroutput> into the destination buffer,
-<computeroutput>dest[0 .. *destLen-1]</computeroutput>.  If the
-destination buffer is big enough,
-<computeroutput>*destLen</computeroutput> is set to the size of
-the uncompressed data, and <computeroutput>BZ_OK</computeroutput>
-is returned.  If the compressed data won't fit,
-<computeroutput>*destLen</computeroutput> is unchanged, and
-<computeroutput>BZ_OUTBUFF_FULL</computeroutput> is
-returned.</para>
-
-<para><computeroutput>source</computeroutput> is assumed to hold
-a complete <computeroutput>bzip2</computeroutput> format data
-stream.
-<computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput> tries
-to decompress the entirety of the stream into the output
-buffer.</para>
-
-<para>For the meaning of parameters
-<computeroutput>small</computeroutput> and
-<computeroutput>verbosity</computeroutput>, see
-<computeroutput>BZ2_bzDecompressInit</computeroutput>.</para>
-
-<para>Because the compression ratio of the compressed data cannot
-be known in advance, there is no easy way to guarantee that the
-output buffer will be big enough.  You may of course make
-arrangements in your code to record the size of the uncompressed
-data, but such a mechanism is beyond the scope of this
-library.</para>
-
-<para><computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput>
-will not write data at or beyond
-<computeroutput>dest[*destLen]</computeroutput>, even in case of
-buffer overflow.</para>
-
-<para>Possible return values:</para>
-
-<programlisting>
-BZ_CONFIG_ERROR
-  if the library has been mis-compiled
-BZ_PARAM_ERROR
-  if dest is NULL or destLen is NULL
-  or small != 0 && small != 1
-  or verbosity < 0 or verbosity > 4
-BZ_MEM_ERROR
-  if insufficient memory is available 
-BZ_OUTBUFF_FULL
-  if the size of the compressed data exceeds *destLen
-BZ_DATA_ERROR
-  if a data integrity error was detected in the compressed data
-BZ_DATA_ERROR_MAGIC
-  if the compressed data doesn't begin with the right magic bytes
-BZ_UNEXPECTED_EOF
-  if the compressed data ends unexpectedly
-BZ_OK
-  otherwise
-</programlisting>
-
-</sect2>
-
-</sect1>
-
-
-<sect1 id="zlib-compat" xreflabel="zlib compatibility functions">
-<title><computeroutput>zlib</computeroutput> compatibility functions</title>
-
-<para>Yoshioka Tsuneo has contributed some functions to give
-better <computeroutput>zlib</computeroutput> compatibility.
-These functions are <computeroutput>BZ2_bzopen</computeroutput>,
-<computeroutput>BZ2_bzread</computeroutput>,
-<computeroutput>BZ2_bzwrite</computeroutput>,
-<computeroutput>BZ2_bzflush</computeroutput>,
-<computeroutput>BZ2_bzclose</computeroutput>,
-<computeroutput>BZ2_bzerror</computeroutput> and
-<computeroutput>BZ2_bzlibVersion</computeroutput>.  These
-functions are not (yet) officially part of the library.  If they
-break, you get to keep all the pieces.  Nevertheless, I think
-they work ok.</para>
-
-<programlisting>
-typedef void BZFILE;
-
-const char * BZ2_bzlibVersion ( void );
-</programlisting>
-
-<para>Returns a string indicating the library version.</para>
-
-<programlisting>
-BZFILE * BZ2_bzopen  ( const char *path, const char *mode );
-BZFILE * BZ2_bzdopen ( int        fd,    const char *mode );
-</programlisting>
-
-<para>Opens a <computeroutput>.bz2</computeroutput> file for
-reading or writing, using either its name or a pre-existing file
-descriptor.  Analogous to <computeroutput>fopen</computeroutput>
-and <computeroutput>fdopen</computeroutput>.</para>
-
-<programlisting>
-int BZ2_bzread  ( BZFILE* b, void* buf, int len );
-int BZ2_bzwrite ( BZFILE* b, void* buf, int len );
-</programlisting>
-
-<para>Reads/writes data from/to a previously opened
-<computeroutput>BZFILE</computeroutput>.  Analogous to
-<computeroutput>fread</computeroutput> and
-<computeroutput>fwrite</computeroutput>.</para>
-
-<programlisting>
-int  BZ2_bzflush ( BZFILE* b );
-void BZ2_bzclose ( BZFILE* b );
-</programlisting>
-
-<para>Flushes/closes a <computeroutput>BZFILE</computeroutput>.
-<computeroutput>BZ2_bzflush</computeroutput> doesn't actually do
-anything.  Analogous to <computeroutput>fflush</computeroutput>
-and <computeroutput>fclose</computeroutput>.</para>
-
-<programlisting>
-const char * BZ2_bzerror ( BZFILE *b, int *errnum )
-</programlisting>
-
-<para>Returns a string describing the more recent error status of
-<computeroutput>b</computeroutput>, and also sets
-<computeroutput>*errnum</computeroutput> to its numerical
-value.</para>
-
-</sect1>
-
-
-<sect1 id="stdio-free" 
-       xreflabel="Using the library in a stdio-free environment">
-<title>Using the library in a <computeroutput>stdio</computeroutput>-free environment</title>
-
-
-<sect2 id="stdio-bye" xreflabel="Getting rid of stdio">
-<title>Getting rid of <computeroutput>stdio</computeroutput></title>
-
-<para>In a deeply embedded application, you might want to use
-just the memory-to-memory functions.  You can do this
-conveniently by compiling the library with preprocessor symbol
-<computeroutput>BZ_NO_STDIO</computeroutput> defined.  Doing this
-gives you a library containing only the following eight
-functions:</para>
-
-<para><computeroutput>BZ2_bzCompressInit</computeroutput>,
-<computeroutput>BZ2_bzCompress</computeroutput>,
-<computeroutput>BZ2_bzCompressEnd</computeroutput>
-<computeroutput>BZ2_bzDecompressInit</computeroutput>,
-<computeroutput>BZ2_bzDecompress</computeroutput>,
-<computeroutput>BZ2_bzDecompressEnd</computeroutput>
-<computeroutput>BZ2_bzBuffToBuffCompress</computeroutput>,
-<computeroutput>BZ2_bzBuffToBuffDecompress</computeroutput></para>
-
-<para>When compiled like this, all functions will ignore
-<computeroutput>verbosity</computeroutput> settings.</para>
-
-</sect2>
-
-
-<sect2 id="critical-error" xreflabel="Critical error handling">
-<title>Critical error handling</title>
-
-<para><computeroutput>libbzip2</computeroutput> contains a number
-of internal assertion checks which should, needless to say, never
-be activated.  Nevertheless, if an assertion should fail,
-behaviour depends on whether or not the library was compiled with
-<computeroutput>BZ_NO_STDIO</computeroutput> set.</para>
-
-<para>For a normal compile, an assertion failure yields the
-message:</para>
-
-<blockquote>
-<para>bzip2/libbzip2: internal error number N.</para>
-<para>This is a bug in bzip2/libbzip2, &bz-version; of &bz-date;.
-Please report it to me at: &bz-email;.  If this happened
-when you were using some program which uses libbzip2 as a
-component, you should also report this bug to the author(s)
-of that program.  Please make an effort to report this bug;
-timely and accurate bug reports eventually lead to higher
-quality software.  Thanks.  Julian Seward, &bz-date;.
-</para></blockquote>
-
-<para>where <computeroutput>N</computeroutput> is some error code
-number.  If <computeroutput>N == 1007</computeroutput>, it also
-prints some extra text advising the reader that unreliable memory
-is often associated with internal error 1007. (This is a
-frequently-observed-phenomenon with versions 1.0.0/1.0.1).</para>
-
-<para><computeroutput>exit(3)</computeroutput> is then
-called.</para>
-
-<para>For a <computeroutput>stdio</computeroutput>-free library,
-assertion failures result in a call to a function declared
-as:</para>
-
-<programlisting>
-extern void bz_internal_error ( int errcode );
-</programlisting>
-
-<para>The relevant code is passed as a parameter.  You should
-supply such a function.</para>
-
-<para>In either case, once an assertion failure has occurred, any
-<computeroutput>bz_stream</computeroutput> records involved can
-be regarded as invalid.  You should not attempt to resume normal
-operation with them.</para>
-
-<para>You may, of course, change critical error handling to suit
-your needs.  As I said above, critical errors indicate bugs in
-the library and should not occur.  All "normal" error situations
-are indicated via error return codes from functions, and can be
-recovered from.</para>
-
-</sect2>
-
-</sect1>
-
-
-<sect1 id="win-dll" xreflabel="Making a Windows DLL">
-<title>Making a Windows DLL</title>
-
-<para>Everything related to Windows has been contributed by
-Yoshioka Tsuneo
-(<computeroutput>QWF00133@niftyserve.or.jp</computeroutput> /
-<computeroutput>tsuneo-y@is.aist-nara.ac.jp</computeroutput>), so
-you should send your queries to him (but perhaps Cc: me,
-<computeroutput>&bz-email;</computeroutput>).</para>
-
-<para>My vague understanding of what to do is: using Visual C++
-5.0, open the project file
-<computeroutput>libbz2.dsp</computeroutput>, and build.  That's
-all.</para>
-
-<para>If you can't open the project file for some reason, make a
-new one, naming these files:
-<computeroutput>blocksort.c</computeroutput>,
-<computeroutput>bzlib.c</computeroutput>,
-<computeroutput>compress.c</computeroutput>,
-<computeroutput>crctable.c</computeroutput>,
-<computeroutput>decompress.c</computeroutput>,
-<computeroutput>huffman.c</computeroutput>,
-<computeroutput>randtable.c</computeroutput> and
-<computeroutput>libbz2.def</computeroutput>.  You will also need
-to name the header files <computeroutput>bzlib.h</computeroutput>
-and <computeroutput>bzlib_private.h</computeroutput>.</para>
-
-<para>If you don't use VC++, you may need to define the
-proprocessor symbol
-<computeroutput>_WIN32</computeroutput>.</para>
-
-<para>Finally, <computeroutput>dlltest.c</computeroutput> is a
-sample program using the DLL.  It has a project file,
-<computeroutput>dlltest.dsp</computeroutput>.</para>
-
-<para>If you just want a makefile for Visual C, have a look at
-<computeroutput>makefile.msc</computeroutput>.</para>
-
-<para>Be aware that if you compile
-<computeroutput>bzip2</computeroutput> itself on Win32, you must
-set <computeroutput>BZ_UNIX</computeroutput> to 0 and
-<computeroutput>BZ_LCCWIN32</computeroutput> to 1, in the file
-<computeroutput>bzip2.c</computeroutput>, before compiling.
-Otherwise the resulting binary won't work correctly.</para>
-
-<para>I haven't tried any of this stuff myself, but it all looks
-plausible.</para>
-
-</sect1>
-
-</chapter>
-
-
-
-<chapter id="misc" xreflabel="Miscellanea">
-<title>Miscellanea</title>
-
-<para>These are just some random thoughts of mine.  Your mileage
-may vary.</para>
-
-
-<sect1 id="limits" xreflabel="Limitations of the compressed file format">
-<title>Limitations of the compressed file format</title>
-
-<para><computeroutput>bzip2-1.0.X</computeroutput>,
-<computeroutput>0.9.5</computeroutput> and
-<computeroutput>0.9.0</computeroutput> use exactly the same file
-format as the original version,
-<computeroutput>bzip2-0.1</computeroutput>.  This decision was
-made in the interests of stability.  Creating yet another
-incompatible compressed file format would create further
-confusion and disruption for users.</para>
-
-<para>Nevertheless, this is not a painless decision.  Development
-work since the release of
-<computeroutput>bzip2-0.1</computeroutput> in August 1997 has
-shown complexities in the file format which slow down
-decompression and, in retrospect, are unnecessary.  These
-are:</para>
-
-<itemizedlist mark='bullet'>
-
- <listitem><para>The run-length encoder, which is the first of the
-   compression transformations, is entirely irrelevant.  The
-   original purpose was to protect the sorting algorithm from the
-   very worst case input: a string of repeated symbols.  But
-   algorithm steps Q6a and Q6b in the original Burrows-Wheeler
-   technical report (SRC-124) show how repeats can be handled
-   without difficulty in block sorting.</para></listitem>
-
- <listitem><para>The randomisation mechanism doesn't really need to be
-   there.  Udi Manber and Gene Myers published a suffix array
-   construction algorithm a few years back, which can be employed
-   to sort any block, no matter how repetitive, in O(N log N)
-   time.  Subsequent work by Kunihiko Sadakane has produced a
-   derivative O(N (log N)^2) algorithm which usually outperforms
-   the Manber-Myers algorithm.</para>
-
-   <para>I could have changed to Sadakane's algorithm, but I find
-   it to be slower than <computeroutput>bzip2</computeroutput>'s
-   existing algorithm for most inputs, and the randomisation
-   mechanism protects adequately against bad cases.  I didn't
-   think it was a good tradeoff to make.  Partly this is due to
-   the fact that I was not flooded with email complaints about
-   <computeroutput>bzip2-0.1</computeroutput>'s performance on
-   repetitive data, so perhaps it isn't a problem for real
-   inputs.</para>
-
-   <para>Probably the best long-term solution, and the one I have
-   incorporated into 0.9.5 and above, is to use the existing
-   sorting algorithm initially, and fall back to a O(N (log N)^2)
-   algorithm if the standard algorithm gets into
-   difficulties.</para></listitem>
-
-  <listitem><para>The compressed file format was never designed to be
-   handled by a library, and I have had to jump though some hoops
-   to produce an efficient implementation of decompression.  It's
-   a bit hairy.  Try passing
-   <computeroutput>decompress.c</computeroutput> through the C
-   preprocessor and you'll see what I mean.  Much of this
-   complexity could have been avoided if the compressed size of
-   each block of data was recorded in the data stream.</para></listitem>
-
- <listitem><para>An Adler-32 checksum, rather than a CRC32 checksum,
-   would be faster to compute.</para></listitem>
-
-</itemizedlist>
-
-<para>It would be fair to say that the
-<computeroutput>bzip2</computeroutput> format was frozen before I
-properly and fully understood the performance consequences of
-doing so.</para>
-
-<para>Improvements which I was able to incorporate into 0.9.0,
-despite using the same file format, are:</para>
-
-<itemizedlist mark='bullet'>
-
- <listitem><para>Single array implementation of the inverse BWT.  This
-  significantly speeds up decompression, presumably because it
-  reduces the number of cache misses.</para></listitem>
-
- <listitem><para>Faster inverse MTF transform for large MTF values.
-  The new implementation is based on the notion of sliding blocks
-  of values.</para></listitem>
-
- <listitem><para><computeroutput>bzip2-0.9.0</computeroutput> now reads
-  and writes files with <computeroutput>fread</computeroutput>
-  and <computeroutput>fwrite</computeroutput>; version 0.1 used
-  <computeroutput>putc</computeroutput> and
-  <computeroutput>getc</computeroutput>.  Duh!  Well, you live
-  and learn.</para></listitem>
-
-</itemizedlist>
-
-<para>Further ahead, it would be nice to be able to do random
-access into files.  This will require some careful design of
-compressed file formats.</para>
-
-</sect1>
-
-
-<sect1 id="port-issues" xreflabel="Portability issues">
-<title>Portability issues</title>
-
-<para>After some consideration, I have decided not to use GNU
-<computeroutput>autoconf</computeroutput> to configure 0.9.5 or
-1.0.</para>
-
-<para><computeroutput>autoconf</computeroutput>, admirable and
-wonderful though it is, mainly assists with portability problems
-between Unix-like platforms.  But
-<computeroutput>bzip2</computeroutput> doesn't have much in the
-way of portability problems on Unix; most of the difficulties
-appear when porting to the Mac, or to Microsoft's operating
-systems.  <computeroutput>autoconf</computeroutput> doesn't help
-in those cases, and brings in a whole load of new
-complexity.</para>
-
-<para>Most people should be able to compile the library and
-program under Unix straight out-of-the-box, so to speak,
-especially if you have a version of GNU C available.</para>
-
-<para>There are a couple of
-<computeroutput>__inline__</computeroutput> directives in the
-code.  GNU C (<computeroutput>gcc</computeroutput>) should be
-able to handle them.  If you're not using GNU C, your C compiler
-shouldn't see them at all.  If your compiler does, for some
-reason, see them and doesn't like them, just
-<computeroutput>#define</computeroutput>
-<computeroutput>__inline__</computeroutput> to be
-<computeroutput>/* */</computeroutput>.  One easy way to do this
-is to compile with the flag
-<computeroutput>-D__inline__=</computeroutput>, which should be
-understood by most Unix compilers.</para>
-
-<para>If you still have difficulties, try compiling with the
-macro <computeroutput>BZ_STRICT_ANSI</computeroutput> defined.
-This should enable you to build the library in a strictly ANSI
-compliant environment.  Building the program itself like this is
-dangerous and not supported, since you remove
-<computeroutput>bzip2</computeroutput>'s checks against
-compressing directories, symbolic links, devices, and other
-not-really-a-file entities.  This could cause filesystem
-corruption!</para>
-
-<para>One other thing: if you create a
-<computeroutput>bzip2</computeroutput> binary for public distribution,
-please consider linking it statically (<computeroutput>gcc
--static</computeroutput>).  This avoids all sorts of library-version
-issues that others may encounter later on.</para>
-
-<para>If you build <computeroutput>bzip2</computeroutput> on
-Win32, you must set <computeroutput>BZ_UNIX</computeroutput> to 0
-and <computeroutput>BZ_LCCWIN32</computeroutput> to 1, in the
-file <computeroutput>bzip2.c</computeroutput>, before compiling.
-Otherwise the resulting binary won't work correctly.</para>
-
-</sect1>
-
-
-<sect1 id="bugs" xreflabel="Reporting bugs">
-<title>Reporting bugs</title>
-
-<para>I tried pretty hard to make sure
-<computeroutput>bzip2</computeroutput> is bug free, both by
-design and by testing.  Hopefully you'll never need to read this
-section for real.</para>
-
-<para>Nevertheless, if <computeroutput>bzip2</computeroutput> dies
-with a segmentation fault, a bus error or an internal assertion
-failure, it will ask you to email me a bug report.  Experience from
-years of feedback of bzip2 users indicates that almost all these
-problems can be traced to either compiler bugs or hardware
-problems.</para>
-
-<itemizedlist mark='bullet'>
-
- <listitem><para>Recompile the program with no optimisation, and
-  see if it works.  And/or try a different compiler.  I heard all
-  sorts of stories about various flavours of GNU C (and other
-  compilers) generating bad code for
-  <computeroutput>bzip2</computeroutput>, and I've run across two
-  such examples myself.</para>
-
-  <para>2.7.X versions of GNU C are known to generate bad code
-  from time to time, at high optimisation levels.  If you get
-  problems, try using the flags
-  <computeroutput>-O2</computeroutput>
-  <computeroutput>-fomit-frame-pointer</computeroutput>
-  <computeroutput>-fno-strength-reduce</computeroutput>.  You
-  should specifically <emphasis>not</emphasis> use
-  <computeroutput>-funroll-loops</computeroutput>.</para>
-
-  <para>You may notice that the Makefile runs six tests as part
-  of the build process.  If the program passes all of these, it's
-  a pretty good (but not 100%) indication that the compiler has
-  done its job correctly.</para></listitem>
-
- <listitem><para>If <computeroutput>bzip2</computeroutput>
-  crashes randomly, and the crashes are not repeatable, you may
-  have a flaky memory subsystem.
-  <computeroutput>bzip2</computeroutput> really hammers your
-  memory hierarchy, and if it's a bit marginal, you may get these
-  problems.  Ditto if your disk or I/O subsystem is slowly
-  failing.  Yup, this really does happen.</para>
-
-  <para>Try using a different machine of the same type, and see
-  if you can repeat the problem.</para></listitem>
-
-  <listitem><para>This isn't really a bug, but ... If
-  <computeroutput>bzip2</computeroutput> tells you your file is
-  corrupted on decompression, and you obtained the file via FTP,
-  there is a possibility that you forgot to tell FTP to do a
-  binary mode transfer.  That absolutely will cause the file to
-  be non-decompressible.  You'll have to transfer it
-  again.</para></listitem>
-
-</itemizedlist>
-
-<para>If you've incorporated
-<computeroutput>libbzip2</computeroutput> into your own program
-and are getting problems, please, please, please, check that the
-parameters you are passing in calls to the library, are correct,
-and in accordance with what the documentation says is allowable.
-I have tried to make the library robust against such problems,
-but I'm sure I haven't succeeded.</para>
-
-<para>Finally, if the above comments don't help, you'll have to
-send me a bug report.  Now, it's just amazing how many people
-will send me a bug report saying something like:</para>
-
-<programlisting>
-bzip2 crashed with segmentation fault on my machine
-</programlisting>
-
-<para>and absolutely nothing else.  Needless to say, a such a
-report is <emphasis>totally, utterly, completely and
-comprehensively 100% useless; a waste of your time, my time, and
-net bandwidth</emphasis>.  With no details at all, there's no way
-I can possibly begin to figure out what the problem is.</para>
-
-<para>The rules of the game are: facts, facts, facts.  Don't omit
-them because "oh, they won't be relevant".  At the bare
-minimum:</para>
-
-<programlisting>
-Machine type.  Operating system version.  
-Exact version of bzip2 (do bzip2 -V).  
-Exact version of the compiler used.  
-Flags passed to the compiler.
-</programlisting>
-
-<para>However, the most important single thing that will help me
-is the file that you were trying to compress or decompress at the
-time the problem happened.  Without that, my ability to do
-anything more than speculate about the cause, is limited.</para>
-
-</sect1>
-
-
-<sect1 id="package" xreflabel="Did you get the right package?">
-<title>Did you get the right package?</title>
-
-<para><computeroutput>bzip2</computeroutput> is a resource hog.
-It soaks up large amounts of CPU cycles and memory.  Also, it
-gives very large latencies.  In the worst case, you can feed many
-megabytes of uncompressed data into the library before getting
-any compressed output, so this probably rules out applications
-requiring interactive behaviour.</para>
-
-<para>These aren't faults of my implementation, I hope, but more
-an intrinsic property of the Burrows-Wheeler transform
-(unfortunately).  Maybe this isn't what you want.</para>
-
-<para>If you want a compressor and/or library which is faster,
-uses less memory but gets pretty good compression, and has
-minimal latency, consider Jean-loup Gailly's and Mark Adler's
-work, <computeroutput>zlib-1.2.1</computeroutput> and
-<computeroutput>gzip-1.2.4</computeroutput>.  Look for them at 
-<ulink url="http://www.zlib.org">http://www.zlib.org</ulink> and 
-<ulink url="http://www.gzip.org">http://www.gzip.org</ulink>
-respectively.</para>
-
-<para>For something faster and lighter still, you might try Markus F
-X J Oberhumer's <computeroutput>LZO</computeroutput> real-time
-compression/decompression library, at 
-<ulink url="http://www.oberhumer.com/opensource">http://www.oberhumer.com/opensource</ulink>.</para>
-
-</sect1>
-
-
-
-<sect1 id="reading" xreflabel="Further Reading">
-<title>Further Reading</title>
-
-<para><computeroutput>bzip2</computeroutput> is not research
-work, in the sense that it doesn't present any new ideas.
-Rather, it's an engineering exercise based on existing
-ideas.</para>
-
-<para>Four documents describe essentially all the ideas behind
-<computeroutput>bzip2</computeroutput>:</para>
-
-<literallayout>Michael Burrows and D. J. Wheeler:
-  "A block-sorting lossless data compression algorithm"
-   10th May 1994. 
-   Digital SRC Research Report 124.
-   ftp://ftp.digital.com/pub/DEC/SRC/research-reports/SRC-124.ps.gz
-   If you have trouble finding it, try searching at the
-   New Zealand Digital Library, http://www.nzdl.org.
-
-Daniel S. Hirschberg and Debra A. LeLewer
-  "Efficient Decoding of Prefix Codes"
-   Communications of the ACM, April 1990, Vol 33, Number 4.
-   You might be able to get an electronic copy of this
-   from the ACM Digital Library.
-
-David J. Wheeler
-   Program bred3.c and accompanying document bred3.ps.
-   This contains the idea behind the multi-table Huffman coding scheme.
-   ftp://ftp.cl.cam.ac.uk/users/djw3/
-
-Jon L. Bentley and Robert Sedgewick
-  "Fast Algorithms for Sorting and Searching Strings"
-   Available from Sedgewick's web page,
-   www.cs.princeton.edu/~rs
-</literallayout>
-
-<para>The following paper gives valuable additional insights into
-the algorithm, but is not immediately the basis of any code used
-in bzip2.</para>
-
-<literallayout>Peter Fenwick:
-   Block Sorting Text Compression
-   Proceedings of the 19th Australasian Computer Science Conference,
-     Melbourne, Australia.  Jan 31 - Feb 2, 1996.
-   ftp://ftp.cs.auckland.ac.nz/pub/peter-f/ACSC96paper.ps</literallayout>
-
-<para>Kunihiko Sadakane's sorting algorithm, mentioned above, is
-available from:</para>
-
-<literallayout>http://naomi.is.s.u-tokyo.ac.jp/~sada/papers/Sada98b.ps.gz
-</literallayout>
-
-<para>The Manber-Myers suffix array construction algorithm is
-described in a paper available from:</para>
-
-<literallayout>http://www.cs.arizona.edu/people/gene/PAPERS/suffix.ps
-</literallayout>
-
-<para>Finally, the following papers document some
-investigations I made into the performance of sorting
-and decompression algorithms:</para>
-
-<literallayout>Julian Seward
-   On the Performance of BWT Sorting Algorithms
-   Proceedings of the IEEE Data Compression Conference 2000
-     Snowbird, Utah.  28-30 March 2000.
-
-Julian Seward
-   Space-time Tradeoffs in the Inverse B-W Transform
-   Proceedings of the IEEE Data Compression Conference 2001
-     Snowbird, Utah.  27-29 March 2001.
-</literallayout>
-
-</sect1>
-
-</chapter>
-
-</book>
Index: trunk/minix/commands/bzip2-1.0.3/mk251.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/mk251.c	(revision 9)
+++ 	(revision )
@@ -1,16 +1,0 @@
-
-/* Spew out a long sequence of the byte 251.  When fed to bzip2
-   versions 1.0.0 or 1.0.1, causes it to die with internal error
-   1007 in blocksort.c.  This assertion misses an extremely rare
-   case, which is fixed in this version (1.0.2) and above.
-*/
-
-#include <stdio.h>
-
-int main ()
-{
-   int i;
-   for (i = 0; i < 48500000 ; i++)
-     putchar(251);
-   return 0;
-}
Index: trunk/minix/commands/bzip2-1.0.3/randtable.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/randtable.c	(revision 9)
+++ 	(revision )
@@ -1,124 +1,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Table for randomising repetitive blocks               ---*/
-/*---                                           randtable.c ---*/
-/*-------------------------------------------------------------*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2005 Julian R Seward.  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. The origin of this software must not be misrepresented; you must 
-     not claim that you wrote the original software.  If you use this 
-     software in a product, an acknowledgment in the product 
-     documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
-     not be misrepresented as being the original software.
-
-  4. 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.
-
-  Julian Seward, Cambridge, UK.
-  jseward@bzip.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
-     Mike Burrows
-     David Wheeler
-     Peter Fenwick
-     Alistair Moffat
-     Radford Neal
-     Ian H. Witten
-     Robert Sedgewick
-     Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-
-#include "bzlib_private.h"
-
-
-/*---------------------------------------------*/
-Int32 BZ2_rNums[512] = { 
-   619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 
-   985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 
-   733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 
-   419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 
-   878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 
-   862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 
-   150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 
-   170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 
-   73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 
-   909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 
-   641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 
-   161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 
-   382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 
-   98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 
-   227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 
-   469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 
-   184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 
-   715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 
-   951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 
-   652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 
-   645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 
-   609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 
-   653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 
-   411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 
-   170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 
-   857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 
-   669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 
-   944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 
-   344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 
-   897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 
-   433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 
-   686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 
-   946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 
-   978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 
-   680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 
-   707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 
-   297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 
-   134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 
-   343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 
-   140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 
-   170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 
-   369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 
-   804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 
-   896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 
-   661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 
-   768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 
-   61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 
-   372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 
-   780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 
-   920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 
-   645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 
-   936, 638
-};
-
-
-/*-------------------------------------------------------------*/
-/*--- end                                       randtable.c ---*/
-/*-------------------------------------------------------------*/
Index: trunk/minix/commands/bzip2-1.0.3/sample3.ref
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/sample3.ref	(revision 9)
+++ 	(revision )
@@ -1,30007 +1,0 @@
-This file is exceedingly boring.  If you find yourself
-reading it, please (1) take it from me that you can safely
-guess what the rest of the file says, and (2) seek professional
-help.
-
-ps.  there are no further sarcastic remarks in this file.
-
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
-ugh
Index: trunk/minix/commands/bzip2-1.0.3/spewG.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/spewG.c	(revision 9)
+++ 	(revision )
@@ -1,39 +1,0 @@
-
-/* spew out a thoroughly gigantic file designed so that bzip2
-   can compress it reasonably rapidly.  This is to help test
-   support for large files (> 2GB) in a reasonable amount of time.
-   I suggest you use the undocumented --exponential option to
-   bzip2 when compressing the resulting file; this saves a bit of
-   time.  Note: *don't* bother with --exponential when compressing 
-   Real Files; it'll just waste a lot of CPU time :-)
-   (but is otherwise harmless).
-*/
-
-#define _FILE_OFFSET_BITS 64
-
-#include <stdio.h>
-#include <stdlib.h>
-
-/* The number of megabytes of junk to spew out (roughly) */
-#define MEGABYTES 5000
-
-#define N_BUF 1000000
-char buf[N_BUF];
-
-int main ( int argc, char** argv )
-{
-   int ii, kk, p;
-   srandom(1);
-   setbuffer ( stdout, buf, N_BUF );
-   for (kk = 0; kk < MEGABYTES * 515; kk+=3) {
-      p = 25+random()%50;
-      for (ii = 0; ii < p; ii++)
-         printf ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" );
-      for (ii = 0; ii < p-1; ii++)
-         printf ( "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" );
-      for (ii = 0; ii < p+1; ii++)
-         printf ( "ccccccccccccccccccccccccccccccccccccc" );
-   }
-   fflush(stdout);
-   return 0;
-}
Index: trunk/minix/commands/bzip2-1.0.3/unzcrash.c
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/unzcrash.c	(revision 9)
+++ 	(revision )
@@ -1,126 +1,0 @@
-
-/* A test program written to test robustness to decompression of
-   corrupted data.  Usage is 
-       unzcrash filename
-   and the program will read the specified file, compress it (in memory),
-   and then repeatedly decompress it, each time with a different bit of
-   the compressed data inverted, so as to test all possible one-bit errors.
-   This should not cause any invalid memory accesses.  If it does, 
-   I want to know about it!
-
-   p.s.  As you can see from the above description, the process is
-   incredibly slow.  A file of size eg 5KB will cause it to run for
-   many hours.
-*/
-
-#include <stdio.h>
-#include <assert.h>
-#include "bzlib.h"
-
-#define M_BLOCK 1000000
-
-typedef unsigned char uchar;
-
-#define M_BLOCK_OUT (M_BLOCK + 1000000)
-uchar inbuf[M_BLOCK];
-uchar outbuf[M_BLOCK_OUT];
-uchar zbuf[M_BLOCK + 600 + (M_BLOCK / 100)];
-
-int nIn, nOut, nZ;
-
-static char *bzerrorstrings[] = {
-       "OK"
-      ,"SEQUENCE_ERROR"
-      ,"PARAM_ERROR"
-      ,"MEM_ERROR"
-      ,"DATA_ERROR"
-      ,"DATA_ERROR_MAGIC"
-      ,"IO_ERROR"
-      ,"UNEXPECTED_EOF"
-      ,"OUTBUFF_FULL"
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-      ,"???"   /* for future */
-};
-
-void flip_bit ( int bit )
-{
-   int byteno = bit / 8;
-   int bitno  = bit % 8;
-   uchar mask = 1 << bitno;
-   //fprintf ( stderr, "(byte %d  bit %d  mask %d)",
-   //          byteno, bitno, (int)mask );
-   zbuf[byteno] ^= mask;
-}
-
-int main ( int argc, char** argv )
-{
-   FILE* f;
-   int   r;
-   int   bit;
-   int   i;
-
-   if (argc != 2) {
-      fprintf ( stderr, "usage: unzcrash filename\n" );
-      return 1;
-   }
-
-   f = fopen ( argv[1], "r" );
-   if (!f) {
-      fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
-      return 1;
-   }
-
-   nIn = fread ( inbuf, 1, M_BLOCK, f );
-   fprintf ( stderr, "%d bytes read\n", nIn );
-
-   nZ = M_BLOCK;
-   r = BZ2_bzBuffToBuffCompress (
-         zbuf, &nZ, inbuf, nIn, 9, 0, 30 );
-
-   assert (r == BZ_OK);
-   fprintf ( stderr, "%d after compression\n", nZ );
-
-   for (bit = 0; bit < nZ*8; bit++) {
-      fprintf ( stderr, "bit %d  ", bit );
-      flip_bit ( bit );
-      nOut = M_BLOCK_OUT;
-      r = BZ2_bzBuffToBuffDecompress (
-            outbuf, &nOut, zbuf, nZ, 0, 0 );
-      fprintf ( stderr, " %d  %s ", r, bzerrorstrings[-r] );
-
-      if (r != BZ_OK) {
-         fprintf ( stderr, "\n" );
-      } else {
-         if (nOut != nIn) {
-           fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
-           return 1;
-         } else {
-           for (i = 0; i < nOut; i++)
-             if (inbuf[i] != outbuf[i]) { 
-                fprintf(stderr, "mismatch at %d\n", i ); 
-                return 1; 
-           }
-           if (i == nOut) fprintf(stderr, "really ok!\n" );
-         }
-      }
-
-      flip_bit ( bit );
-   }
-
-#if 0
-   assert (nOut == nIn);
-   for (i = 0; i < nOut; i++) {
-     if (inbuf[i] != outbuf[i]) {
-        fprintf ( stderr, "difference at %d !\n", i );
-        return 1;
-     }
-   }
-#endif
-
-   fprintf ( stderr, "all ok\n" );
-   return 0;
-}
Index: trunk/minix/commands/bzip2-1.0.3/words0
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/words0	(revision 9)
+++ 	(revision )
@@ -1,5 +1,0 @@
-
-If compilation produces errors, or a large number of warnings, 
-please read README.COMPILATION.PROBLEMS -- you might be able to
-adjust the flags in this Makefile to improve matters.
-
Index: trunk/minix/commands/bzip2-1.0.3/words1
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/words1	(revision 9)
+++ 	(revision )
@@ -1,4 +1,0 @@
-
-Doing 6 tests (3 compress, 3 uncompress) ...
-If there's a problem, things might stop at this point.
- 
Index: trunk/minix/commands/bzip2-1.0.3/words2
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/words2	(revision 9)
+++ 	(revision )
@@ -1,5 +1,0 @@
-
-Checking test results.  If any of the four "cmp"s which follow
-report any differences, something is wrong.  If you can't easily
-figure out what, please let me know (jseward@acm.org).
-
Index: trunk/minix/commands/bzip2-1.0.3/words3
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/words3	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-
-If you got this far and the "cmp"s didn't complain, it looks
-like you're in business.  
-
-To install in /usr/bin, /usr/lib, /usr/man and /usr/include, type
-   make install
-To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type 
-   make install PREFIX=/xxx/yyy
-If you are (justifiably) paranoid and want to see what 'make install'
-is going to do, you can first do
-   make -n install                      or
-   make -n install PREFIX=/xxx/yyy      respectively.
-The -n instructs make to show the commands it would execute, but
-not actually execute them.
-
-Instructions for use are in the preformatted manual page, in the file
-bzip2.txt.  For more detailed documentation, read the full manual.  
-It is available in Postscript form (manual.ps), PDF form (manual.pdf),
-and HTML form (manual_toc.html).
-
-You can also do "bzip2 --help" to see some helpful information. 
-"bzip2 -L" displays the software license.
-
Index: trunk/minix/commands/bzip2-1.0.3/xmlproc.sh
===================================================================
--- trunk/minix/commands/bzip2-1.0.3/xmlproc.sh	(revision 9)
+++ 	(revision )
@@ -1,99 +1,0 @@
-#!/bin/bash
-# see the README in this directory for usage etc.
-
-usage() {
-  echo '';
-  echo 'Usage: xmlproc.sh -[option] <filename.xml>';
-  echo 'Specify a target from:';
-  echo '-v      verify xml file conforms to dtd';
-  echo '-html   output in html format (single file)';
-  echo '-ps     output in postscript format';
-  echo '-pdf    output in pdf format';
-  exit;
-}
-
-if test $# -ne 2; then
-  usage
-fi
-# assign the variable for the output type
-action=$1; shift
-# assign the output filename
-xmlfile=$1; shift
-# and check user input it correct
-if !(test -f $xmlfile); then
-  echo "No such file: $xmlfile";
-  exit;
-fi
-# some other stuff we will use
-OUT=output
-xsl_fo=bz-fo.xsl
-xsl_html=bz-html.xsl
-
-basename=$xmlfile
-basename=${basename//'.xml'/''}
-
-fofile="${basename}.fo"
-htmlfile="${basename}.html"
-pdffile="${basename}.pdf"
-psfile="${basename}.ps"
-xmlfmtfile="${basename}.fmt"
-
-# first process the xmlfile with CDATA tags
-./format.pl $xmlfile $xmlfmtfile
-# so the shell knows where the catalogs live
-export XML_CATALOG_FILES=/etc/xml/catalog
-
-# post-processing tidy up
-cleanup() {
-  echo "Cleaning up: # $@" 
-  while [ $# != 0 ]
-  do
-    arg=$1; shift;
-    echo "  deleting $arg";
-    rm $arg
-  done
-}
-
-case $action in
-  -v)
-   flags='--noout --xinclude --noblanks --postvalid'
-   dtd='--dtdvalid http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd'
-   xmllint $flags $dtd $xmlfmtfile 2> $OUT 
-   egrep 'error' $OUT 
-   rm $OUT
-  ;;
-
-  -html)
-   echo "Creating $htmlfile ..."
-   xsltproc --nonet --xinclude  -o $htmlfile $xsl_html $xmlfmtfile
-   cleanup $xmlfmtfile
-  ;;
-
-  -pdf)
-   echo "Creating $pdffile ..."
-   xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
-   pdfxmltex $fofile >$OUT </dev/null
-   pdfxmltex $fofile >$OUT </dev/null
-   pdfxmltex $fofile >$OUT </dev/null
-   cleanup $OUT $xmlfmtfile *.aux *.fo *.log *.out
-  ;;
-
-  -ps)
-   echo "Creating $psfile ..."
-   xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
-   pdfxmltex $fofile >$OUT </dev/null
-   pdfxmltex $fofile >$OUT </dev/null
-   pdfxmltex $fofile >$OUT </dev/null
-   pdftops $pdffile $psfile
-   cleanup $OUT $xmlfmtfile $pdffile *.aux *.fo *.log *.out
-#  passivetex is broken, so we can't go this route yet.
-#   xmltex $fofile >$OUT </dev/null
-#   xmltex $fofile >$OUT </dev/null
-#   xmltex $fofile >$OUT </dev/null
-#   dvips -R -q -o bzip-manual.ps *.dvi
-  ;;
-
-  *)
-  usage
-  ;;
-esac
Index: trunk/minix/commands/cawf/Makefile
===================================================================
--- trunk/minix/commands/cawf/Makefile	(revision 9)
+++ 	(revision )
@@ -1,107 +1,0 @@
-# 	Makefile for cawf
-
-#	Define UNIX for vanilla Unix systems -- e.g., older DYNIX.
-#
-#	Define UNIX and USG for System V, BSD 4.3 and for SunOS.
-#
-#	USG may also be needed if the required string function prototypes --
-#	e.g., for strrchr() -- are in <string.h> rather than <strings.h>.
-#
-#DEFS = -DUNIX -DUSG
-#
-#	Define STDLIB for systems that have <stdlib.h> -- e.g., AIX and
-#	SunOS.
-#
-#	Redefine CAWFLIB by adding -DCAWFLIB=\"...\" to DEFS.
-#
-#DEFS = -DUNIX -DUSG -DCAWFLIB=\"/usr/local/lib/cawf\"
-#
-#	Customize the install rule.
-#
-#	-ansi and -pedantic are ANSI compliance options for the gcc compiler.
-#	Remove them if your compiler objects.
-#
-#	If you're using xlc 2.1 on AIX 3.2 for the RISC/SYSTEM 6000, you
-#	must delete the definition of __STR__ (two leading and two trailing
-#	underscore characters), because the xlc 2.1 compiler incorrectly
-#	inlines string functions when compiling pass3.c.
-#
-#DEFS = -DUNIX -DSTDLIB -U__STR__
-#
-#	Unix systems that have a <malloc.h> need MALLOCH defined, unless
-#	they also have a <stdlib.h> that provides a function prototype for
-#	malloc() and its relatives (most do).
-#
-#DEFS = -DUNIX -DMALLOCH
-
-CC = exec cc
-
-DEFS = -DUNIX -DUSG -DSTDLIB
-
-CFLAGS = -i -f -wo -O ${DEFS}
-
-HDR = ansi.h cawf.h cawflib.h proto.h regexp.h regmagic.h
-
-SRC = cawf.c device.c error.c expand.c expr.c getopt.c macsup.c nreq.c \
-      output.c pass2.c pass3.c  regerror.c regexp.c store.c string.c
-
-OBJ = cawf.o device.o error.o expand.o expr.o getopt.o macsup.o nreq.o \
-      output.o pass2.o pass3.o  regerror.o regexp.o store.o string.o
-
-all:	bsfilt cawf
-
-bsfilt: bsfilt.c
-	${CC} ${CFLAGS} bsfilt.c -o $@
-	install -S 4kw $@
-
-cawf:	${OBJ}
-	${CC} ${CFLAGS} ${OBJ} -o $@
-	install -S 56k $@
-
-clean:
-	rm -f *.o a.out core *errs bsfilt cawf
-
-${OBJ}:	${HDR}
-
-install:	\
-	/usr/bin/bsfilt /usr/bin/colcrt /usr/bin/cawf \
-	/usr/bin/nroff /usr/lib/cawf /usr/lib/cawf/common \
-	/usr/lib/cawf/device.cf /usr/lib/cawf/dumb.dev \
-	/usr/lib/cawf/man.mac /usr/lib/cawf/me.mac \
-	/usr/lib/cawf/ms.mac /usr/lib/cawf/mnx.mac
-
-/usr/bin/bsfilt:	bsfilt
-	install -cs -o bin bsfilt $@
-
-/usr/bin/colcrt:	/usr/bin/bsfilt
-	install -l /usr/bin/bsfilt $@
-
-/usr/bin/cawf:	cawf
-	install -cs -o bin cawf $@
-
-/usr/bin/nroff:	/usr/bin/cawf
-	install -l /usr/bin/cawf $@
-
-/usr/lib/cawf:	
-	install -d -o bin /usr/lib/cawf
-
-/usr/lib/cawf/common:	common
-	install -c -o bin common $@
-
-/usr/lib/cawf/device.cf:	device.cf
-	install -c -o bin device.cf $@
-
-/usr/lib/cawf/dumb.dev:	dumb.dev
-	install -c -o bin dumb.dev $@
-
-/usr/lib/cawf/man.mac:	man.mac
-	install -c -o bin man.mac $@
-
-/usr/lib/cawf/me.mac:	me.mac
-	install -c -o bin me.mac $@
-
-/usr/lib/cawf/ms.mac:	ms.mac
-	install -c -o bin ms.mac $@
-
-/usr/lib/cawf/mnx.mac:	mnx.mac
-	install -c -o bin mnx.mac $@
Index: trunk/minix/commands/cawf/README
===================================================================
--- trunk/minix/commands/cawf/README	(revision 9)
+++ 	(revision )
@@ -1,264 +1,0 @@
-Cawf - nroff-like text formatter
-
-Cawf is a C version of awf, Henry Spencer's Amazingly Workable (text)
-Formatter.  (Awf is written in awk and appears in comp.sources.unix,
-Volume 23, Issue 27.)  Cawf and awf provide a usable subset of raw nroff
-capabilities and the styles of the man(7), me(7) and ms(7) macro sets.
-One of cawf's virtues is that it will run on PC clones under MS-DOS.  It
-is also, like awf, totally independent of any licensed Unix source code.
-
-This distribution contains complete source, make files for Unix and
-MS-DOS, documentation (raw and formatted) and MS-DOS executables for cawf
-and a companion output filters, bsfilt.
-
-This is the fourth distribution of cawf.  Changes include:
-
-	*  Some rudimentary output device support has been added, via a device
-	   configuration file.
-
-	*  The code has been converted to use unsigned characters.
-
-	*  An attempt has been made to make the code ANSI C compliant.
-
-	*  The following bugs have been fixed:
-
-		A bug in the locating of the device file has been corrected,
-		so that the code performs as documented.
-
-		Null macro arguments are ignored.
-
-		Some unused arguments to local functions have been more
-		carefully type cast to avoid portability problems.
-
-	*  The .fl and .rn requests are now supported.
-
-	*  Limited support has been added for the non-break request control
-	   character, the acute accent (').
-
-	*  Argument count conditionals -- operating on \n(.$ -- may now use
-	   the >= and <= operators in addition to [<=>].
-
-	*  Macros may be terminated with "..", ".", "''" or "'".
-
-	*  String interpolation is performed if it is specified at the start
-	   of the .ds request argument.
-
-	*  The .tr request has been enhanced to handle named characters and
-	   string interpolation.
-
-	*  The SS macro is now included in man.mac.
-
-	*  The cawf version number is now displayed in the help output.
-
-	*  A limited -me macro set is included in me.mac.
-
-Changes to cawf to run under Minix:
-
-	*  The DOS binaries and make files have been removed.
- 
-	*  Tabs stops changed from per 5 to per 8.
-
-	*  Bold and underline as it should be in device.cf.
-
-	*  Added .SB and .TA to man.mac.
-
-	*  Numerous prototypes added.
-
-
-CONTENTS
---------
-
-This Minix distribution of cawf includes:
-
-	README		    this file
-	*.c and *.h	    source files to build cawf and bsfilt (bsfilt
-			    removes Backspaces from cawf output)
-	bsfilt.1	    nroff source for the bsfilt manual page
-	cawf.1		    nroff source for the cawf manual page
-	common		    initialization file for CAWFLIB library
-	device.cf	    output device configuration file for CAWFLIB
-			    library
-	dumb.dev	    device description file for CAWFLIB library
-	Makefile	    Unix-style make file
-	man.mac		    man(7) macros for CAWFLIB library
-	me.mac		    me(7) macros for CAWFLIB library
-	ms.mac		    ms(7) macros for CAWFLIB library
-	diffs		    Minix patches
-#ifdef PUTTING_IT_ON_THE_NET
-	cawf
-	bsfilt		    binaries compiled under Minix-PC 1.5 using the ACK
-			    ANSI C compiler using software floating point
-#endif
-
-
-LIBRARY
--------
-
-To use cawf, you must select a location for the CAWFLIB library files.  The
-distributed cawf binary expects to find them in /usr/local/lib/cawf but you
-can alter that with the CAWFLIB environment variable, or you can change the
-CAWFLIB #define in cawf.h and rebuild cawf from the sources.
-
-CAWFLIB contains a minimum of six files:
-
-	common		common raw nroff commands to get cawf started
-	dumb.dev	a set of character definitions for a plain, "dumb"
-			ASCII device - e. g., the console display, a CRT or
-			a basic line printer
-	device.cf	the output device configuration file
-	man.mac		the man(7) macros
-	me.mac		the me(7) macros
-	ms.mac		the ms(7) macros
-
-You may want to add your own macro files to the library.  Just name them
-"m[your-name].mac", following the usual nroff naming convention for macro
-files.
-
-If you have fancy output devices with special character specifications, you
-may want to generate new *.dev files for them.  Follow the format of dumb.dev
-in making new character specifications.  To define characters for a new
-device, select a name prefix for it and create a file in CAWFLIB with the
-name "<prefix>.dev".  To use the new file, set the TERM environment variable
-to <prefix> - e. g., when I test cawf on Unix, I need a vt100.dev, because
-my TERM environment variable value is usually vt100.  All I do is make
-vt100.dev a symbolic link to dumb.dev.  Even that isn't even necessary,
-because cawf will use dumb.dev if it can't find TERM.dev.
-
-In addition to the character specifications possible through the *.dev files,
-cawf provides one-time font selection and bold or italic face support for
-output devices via its -d and -f options.  Cawf can be directed to issue
-specific device codes for bold and italic characters, and one font can be
-specified for the entire document.  Cawf has some built-in output device
-support, and addition support is contained in the device configuration file,
-device.cf.  Additional devices may be defined in device.cf.
-
-It is not necessary to generate a new *.dev file for each output device
-definition.  Only when you need special character definitions do you need to
-create a *.dev file.  The dumb.dev file is adequate for most devices you 
-define in device.cf.
-
-
-SOURCES
--------
-
-The Unix make file has some definitions that help tune it to the local
-Unix environment:
-
-	CAWFLIB		is a string that can be used in lieu of changes
-			to cawf.h's CWFLIB #define.
-
-	MALLOCH		is a string that should be defined when a UNIX
-			environment has a <malloc.h>, unless it also has a
-			<stdlib.h> with protoypes for malloc() and its
-			relatives.  In the latter case, you should define
-			STDLIB, but you don't need to define MALLOCH.
-
-	STDLIB		indicates that standard library function prototype
-			definitions may be found in <stdlib.h>.
-
-			STDLIB must be defined for MS-DOS Quick C.
-
-			If STDLIB is not defined, the cawf sources try to
-			define their own library function return values.
-
-	__STR__		The definition of this string must be deleted when
-			using the xlc 1.2 compiler on the RISC/System 6000
-			under AIX 3.2.  Put
-
-				-U__STR__
-
-			in the Makefile DEFS string.  This must be done
-			because the xlc 1.2 compiler does not correctly inline
-			string functions when compiling pass3.c.
-
-	UNIX		switches the build environment to Unix.  You may also
-			have to decide about MALLOCH, STDLIB, __STR__ and USG
-			when you define UNIX.
-
-			Do not define UNIX for MS-DOS Quick-C; do define
-			STDLIB.
-
-	USG		adjusts for System V.  (UNIX must also be defined.)
-
-			You may also need to define USG to select the proper
-			header file for string function prototypes.  If UNIX
-			and USG are defined, "proto.h" selects <string.h>;
-			if only UNIX, <strings.h>.  Cawf needs the more
-			complete set of definitions, including strchr() and
-			strrchr().  If <string.h> #includes <strings.h>, as
-			is sometimes the case, define only UNIX.
-
-I have built and tested cawf in the UNIX context under AIX 3.2 (see the
-note above on __STR__), BSD4.3-Tahoe, Sequent DYNIX, ETAV (SYSV 3.0),
-NeXTStep 3.0, SunOS 4.1.1 and Ultrix 2.2.  If you build under another Unix
-variant, you may have to adjust the source code, header files and Makefile
-to fit.  Check the Makefile first for hints.
-
-
-ANSI C COMPLIANCE
------------------
-
-Some effort has been devoted to making the cawf sources ANSI C compliant.
-The header file proto.h contains function prototypes that enable ANSI C
-argument checking.  The state of definition of the __STDC__ symbol is used
-to select options that depend on strict adherence to the ANSI C standard --
-e.g., the need for the isascii() test before islower() or isupper().  If
-your ANSI compiler doesn't define this variable when it's acting in strict
-ANSI C mode, you may have to define it in the Makefile.
-
-
-MS-DOS CONSIDERATIONS
----------------------
-
-The MS-DOS version of cawf was created to run under the KornShell of the
-Mortis Kern Systems Toolkit.  One ramification of using MKS' ksh is that it
-supports the separate standard error and standard output streams.  Hence,
-cawf blithely distributes its error messages to the standard error file, and
-assumes the user's shell is capable of separating them from standard output.
-
-If you don't use the MKS KornShell, but do want to separate the output
-streams, you'll have to modify the cawf source code.  As a rudimentary aid,
-cawf uses a separate stream pointer, Efs, for writing error output, but sets
-it to stderr.  You can change that process to open a separate error file and
-set Efs to point to it.
-
-
-COPYRIGHTS AND CREDITS
-----------------------
-
-The sources are copyrighted, but freely distributable under usual terms -
-retention of credit, etc.
-
-Please acknowledge:
-
-	AT&T for their public-domain release of getopt(3) at the 1985
-	UNIFORUM conference;
-
-	Chet Creider, Bob Hardy and Ted Campbell for their contributions
-	to font filtering;
-
-	Henry Spencer for awf and his regular expression package;
-
-	Andy Tanenbaum for his help in ANSI C compliance, including his
-	ansi.h header file from Minix.
-
-Henry says about awf, "I can't believe I really wrote this."  Those are
-my sentiments exactly about cawf, but I also understand that necessity
-sometimes forces us to do what we would prefer to avoid.
-
-
-BUGS AND ENHANCEMENTS
----------------------
-
-I'll be glad to hear about bugs and needs for enhancements, but make no
-promises about delivering fixes or upgrades in response.
-
-Vic Abell <abe@cc.purdue.edu>
-24 November 1992
-
-
-MINIX SPECIFIC TINKERING
-------------------------
-
-Kees J. Bot <kjb@cs.vu.nl>
-26 November 1992
Index: trunk/minix/commands/cawf/ansi.h
===================================================================
--- trunk/minix/commands/cawf/ansi.h	(revision 9)
+++ 	(revision )
@@ -1,56 +1,0 @@
-/* The <ansi.h> header attempts to decide whether the compiler has enough
- * conformance to Standard C for Minix to take advantage of.  If so, the
- * symbol _ANSI is defined (as 31415).  Otherwise _ANSI is not defined
- * here, but it may be defined by applications that want to bend the rules.
- * The magic number in the definition is to inhibit unnecessary bending
- * of the rules.  (For consistency with the new '#ifdef _ANSI" tests in
- * the headers, _ANSI should really be defined as nothing, but that would
- * break many library routines that use "#if _ANSI".)
-
- * If _ANSI ends up being defined, a macro
- *
- *	_PROTOTYPE(function, params)
- *
- * is defined.  This macro expands in different ways, generating either
- * ANSI Standard C prototypes or old-style K&R (Kernighan & Ritchie)
- * prototypes, as needed.  Finally, some programs use _CONST, _VOIDSTAR etc
- * in such a way that they are portable over both ANSI and K&R compilers.
- * The appropriate macros are defined here.
- */
-
-#ifndef _ANSI_H
-#define _ANSI_H
-
-#if __STDC__ == 1
-#define _ANSI		31459	/* compiler claims full ANSI conformance */
-#endif
-
-#ifdef __GNUC__
-#define _ANSI		31459	/* gcc conforms enough even in non-ANSI mode */
-#endif
-
-#ifdef _ANSI
-
-/* Keep everything for ANSI prototypes. */
-#define	_PROTOTYPE(function, params)	function params
-
-#define	_VOIDSTAR	void *
-#define	_VOID		void
-#define	_CONST		const
-#define	_VOLATILE	volatile
-#define _SIZET		size_t
-
-#else
-
-/* Throw away the parameters for K&R prototypes. */
-#define	_PROTOTYPE(function, params)	function()
-
-#define	_VOIDSTAR	void *
-#define	_VOID		void
-#define	_CONST
-#define	_VOLATILE
-#define _SIZET		int
-
-#endif /* _ANSI */
-
-#endif /* ANSI_H */
Index: trunk/minix/commands/cawf/bsfilt.c
===================================================================
--- trunk/minix/commands/cawf/bsfilt.c	(revision 9)
+++ 	(revision )
@@ -1,211 +1,0 @@
-/*
- *	bsfilt.c - a colcrt-like processor for cawf(1)
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include <stdio.h>
-
-#ifdef UNIX
-# ifdef USG
-#include <string.h>
-# else	/* not USG */
-#include <strings.h>
-# endif	/* USG */
-#else	/* not UNIX */
-#include <string.h>
-#endif	/* UNIX */
-
-#include <sys/types.h>
-
-#include "ansi.h"
-
-#define MAXLL	2048			/* ridiculous maximum line length */
-
-int Dash = 1;				/* underline with dashes */
-int Dp = 0;				/* dash pending */
-int Lc = 0;				/* line count */
-char *Pname;				/* program name */
-unsigned char Ulb[MAXLL];		/* underline buffer */
-int Ulx = 0;				/* underline buffer index */
-
-_PROTOTYPE(void Putchar,(int ch));
-
-main(argc, argv)
-	int argc;
-	char *argv[];
-{
-	int ax = 1;			/* argument index */
-	unsigned char c;		/* character buffer */
-	FILE *fs;			/* file stream */
-	int nf = 0;			/* number of files processed */
-	unsigned char pc;		/* previous character */
-	int under = 0;                  /* underline */
-/*
- * Save program name.
- */
-	if ((Pname = strrchr(argv[0], '/')) != NULL)
-		Pname++;
-	else if ((Pname = strrchr(argv[0], '\\')) != NULL)
-		Pname++;
-	else
-		Pname = argv[0];
-/*
- * Process options.
- */
-	if (argc > 1 && argv[1][0] == '-') {
-		switch (argv[1][1]) {
-	/*
-	 * "-U" - underline with dashes.
-	 */
-		case 'U':
-			Dash = 0;
-			under = 1;
-			break;
-	/*
-	 * "-" - do no  underlining at all.
-	 */
-		case '\0':
-			Dash = under = 0;
-			break;
-		default:
-			(void) fprintf(stderr,
-				"%s usage: [-] [-U] [file]\n", Pname);
-			exit(1);
-		}
-		ax++;
-	}
-/*
- * Process files.  Read standard input if no files names.
- */
-
-	while (ax < argc || nf == 0) {
-		if (ax >= argc)
-			fs = stdin;
-		else {
-#ifdef	UNIX
-			if ((fs = fopen(argv[ax], "r")) == NULL)
-#else
-			if ((fs = fopen(argv[ax], "rt")) == NULL)
-#endif
-			{
-				(void) fprintf(stderr, "%s: can't open %s\n",
-					Pname, argv[ax]);
-				exit(1);
-			}
-			ax++;
-		}
-		nf++;
-	/*
-	 * Read input a character at a time.
-	 */
-		for (pc = '\0';;) {
-			c = (unsigned char)fgetc(fs);
-			if (feof(fs))
-				break;
-			switch(c) {
-
-			case '\n':
-				if (pc)
-					Putchar((int)pc);
-				Putchar('\n');
-				pc = '\0';
-				break;
-
-			case '\b':
-				if (pc == '_') {
-					if (under) {
-						putchar(pc);
-						putchar('\b');
-					} else if (Dash)
-						Dp = 1;
-				}
-				pc = '\0';
-				break;
-
-			default:
-				if (pc)
-					Putchar((int)pc);
-				pc = c;
-			}
-		}
-		if (pc) {
-			Putchar((int)pc);
-			Putchar((int)'\n');
-		}
-	}
-	exit(0);
-}
-
-
-/*
- * Putchar(ch) - put a character with possible underlining
- */
-
-void
-Putchar(ch)
-	int ch;
-{
-	int i;					/* temporary index */
-
-	if ((unsigned char)ch == '\n') {
-/*
- * Handle end of line.
- */
-		putchar('\n');
-		if (Ulx) {
-			while (Ulx && Ulb[Ulx-1] == ' ')
-				Ulx--;
-			if (Ulx) {
-				for (i = 0; i < Ulx; i++)
-					putchar(Ulb[i]);
-				putchar('\n');
-			}
-		}
-		Dp = Ulx = 0;
-		Lc++;
-		return;
-	}
-/*
- * Put "normal" character.
- */
-	putchar((unsigned char)ch);
-	if (Dash) {
-
-	/*
-	 * Handle dash-type underlining.
-	 */
-		if (Ulx >= MAXLL) {
-			(void) fprintf(stderr,
-				"%s: underline for line %d > %d characters\n",
-				Pname, Lc, MAXLL);
-			exit(1);
-		}
-		Ulb[Ulx++] = Dp ? '-' : ' ';
-		Dp = 0;
-	}
-}
Index: trunk/minix/commands/cawf/build
===================================================================
--- trunk/minix/commands/cawf/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/cawf/cawf.c
===================================================================
--- trunk/minix/commands/cawf/cawf.c	(revision 9)
+++ 	(revision )
@@ -1,488 +1,0 @@
-/*
- *	cawf - a C version of Henry Spencer's awf(1), the Amazingly
- *	       Workable (text) Formatter
- *
- *	V. Abell, Purdue University Computing Center
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-static char Version[] = "4.0";
-
-#include "cawf.h"
-
-#include <sys/stat.h>
-#ifndef	UNIX
-#include <io.h>
-#include <process.h>
-#include <string.h>
-#include <sys\types.h>
-#include <sys\stat.h>
-#endif
-
-
-main(argc, argv)
-	int     argc;
-	char    *argv[];
-{
-	char *ep;               	/* environment pointer */
-	int fff = 0;			/* final form feed status */
-	char **files;			/* file names */
-	int help = 0;			/* help status */
-	int i;	               		/* temporary index */
-	size_t l;                       /* length */
-	char *lib = CAWFLIB;		/* library path */
-	int libl;			/* library path length */
-	int mac = 0;			/* macro specification status */
-	int nf = 0;             	/* number of files */
-	char *np;               	/* name pointer */
-	int pc;                 	/* prolog count */
-	struct stat sbuf;               /* stat buffer */
-/*
- * Save program name.
- */
-	if ((Pname = strrchr(argv[0], '\\')) != NULL)
-		Pname++;
-	else if ((Pname = strrchr(argv[0], '/')) != NULL)
-		Pname++;
-	else
-		Pname = argv[0];
-/*
- * Set error file stream pointer.
- */
-	Efs = stderr;
-/*
- * Get library name.
- */
-	if ((np = getenv("CAWFLIB")) != NULL)
-		lib = np;
-	libl = strlen(lib);
-/*
- * Get device file name.
- */
-	for (ep = getenv("TERM");; ep = NULL) {
-		if (ep == NULL || *ep == '\0')
-			ep = "dumb";
-		l = libl + 1 + strlen(ep) + strlen(".dev") + 1;
-		if ((np = malloc(l)) == NULL)
-			Error(FATAL, NOLINE,
-				" no string space for device file: ", ep);
-		(void) sprintf(np, "%s/%s.dev", lib, ep);
-		if (stat(np, &sbuf) == 0)
-			break;
-		if (strcmp(ep, "dumb") == 0)
-			Error(FATAL, NOLINE, " no dumb.dev file in ", lib);
-		(void) free(np);
-	}
-	if ((files = malloc((argc + 2) * sizeof(files[0]))) == NULL)
-		Error(FATAL, NOLINE, " no space for file list",
-			NULL);
-	files[nf++] = np;
-/*
- * Get common text file name.
- */
-	l = libl + 1 + strlen("common") + 1;
-	if ((np = malloc(l)) == NULL)
-		Error(FATAL, NOLINE, " no string space for common file name",
-			NULL);
-	(void) sprintf(np, "%s/common", lib);
-	files[nf++] = np;
-/*
- * Process options.
- */
-	while ((i = getopt(argc, argv, "c:d:ef:hm:")) != EOF) {
-		switch (i) {
-	/*
-	 * -c<device_configuration_file_path>>
-	 */
-		case 'c':
-			Devconf = optarg;
-			break;
-	/*
-	 * -d<output_device_name> -- define output device name
-	 *
-	 * The default output device name is NORMAL -- i.e., a device that
-	 * does bold face with backspace and overprinting and italic face with
-	 * underscore.  NORMAL is usually a terminal device.
-	 *
-	 * There is a built-in device, named ANSI, that does bold face with
-	 * the ANSI shadow mode and italic face with the ANSI underscore mode.
-	 * ANSI is normally a terminal device that supports the ANSI shadow
-	 * and underscore modes.
-	 *
-	 * There is a built-in output device, named NONE, that does nothing
-	 * at all for the bold or italic faces.  This is usually a terminal
-	 * device.
-	 *
-	 * All other device names must match a stanza in the device
-	 * configuration file.
-	 */
-		case 'd':
-			Device = optarg;
-			break;
-	/*
-	 * -e -- eject: issue final form feed
-	 */
-		case 'e':
-			fff = 1;
-			break;
-	/*
-	 * -f<output_device_font_name> -- define font name for the output
-	 *				  device (from device configuration
-	 *				  file)
-	 */
-		case 'f':
-			Devfont = optarg;
-			break;
-	/*
-	 * -h -- display help (usage)
-	 */
-		case 'h':
-			help = 1;
-			break;
-	/*
-	 * -m<macro_file_name>
-	 *
-	 *  Special support is provided for -man, -me and -ms.
-	 */
-		case 'm':
-			if (mac) {
-				Error(WARN, NOLINE,
-					"multiple macro file declaration",
-					NULL);
-				break;
-			}
-			l = libl + 2 + strlen(optarg) + strlen(".mac") + 1;
-			if ((np = malloc(l)) == NULL)
-				Error(FATAL, NOLINE, " no string space for ",
-					argv[1]);
-			(void) sprintf(np, "%s/m%s.mac", lib, optarg);
-			files[nf++] = np;
-			if (strcmp(optarg, "an") == 0)
-				Marg = MANMACROS;
-			else if (strcmp(optarg, "s") == 0
-			     ||  strcmp(optarg, "e") == 0)
-				Marg = MSMACROS;
-			mac++;
-			break;
-	/*
-	 * Option not recognized by getopt().
-	 */
-		case '?':
-			Err = 1;
-		}
-	}
-	if (Defdev())
-		Err++;
-	if (help || Err) {
-	  (void) fprintf(stderr,
-	    "%s %s usage: [-c<c>] [-d<d>] [-e] [-f<f>] [-h] [-m<m>] file...\n",
-		Pname, Version);
-	  (void) fprintf(stderr,
-	    "\t-c<c>     <c> is the device configuration file path\n");
-	  (void) fprintf(stderr,
-	    "\t-d<d>     <d> is the output device name\n");
-	  (void) fprintf(stderr,
-	    "\t          (default = NORMAL, using \\b for bold and italic)\n");
-	  (void) fprintf(stderr,
-	    "\t          (built-ins = ANSI, NONE and NORMAL)\n");
-	  (void) fprintf(stderr,
-	    "\t-e        issue eject after last page\n");
-	  (void) fprintf(stderr,
-	    "\t-f<f>     <f> is the output device font name\n");
-	  (void) fprintf(stderr,
-	    "\t-h        display help (this output)\n");
-	  (void) fprintf(stderr,
-	    "\t-m<m>     m<m> is the macro file name\n");
-	  (void) fprintf(stderr,
-	    "\tfile ...  source file names\n");
-	  exit(Err);
-	}
-	if (mac == 0) {
-
-	    /*
-	     * No macroes - enable Bold, Italic, Roman and Courier fonts.
-	     */
-		for (i = 0; Fcode[i].nm; i++) {
-			switch (Fcode[i].nm) {
-			case 'B':
-			case 'I':
-			case 'R':
-			case 'C':
-				Fcode[i].status = '1';
-			}
-		}
-	}
-/*
- * Add user-supplied file names.
- */
-	pc = nf;
-	if (optind >= argc) {
-		files[nf++] = NULL;       /* STDIN */
-	} else {
-		while (optind < argc)
-			files[nf++] = argv[optind++];
-	}
-/*
- * Make sure all input files are accessible.
- */
-	for (i = 0; i < nf; i++) {
-		if (files[i] != NULL) {
-			if (stat(files[i], &sbuf) != 0)
-				Error(WARN, NOLINE, " can't find ", files[i]);
-		}
-	}
-	if (Err)
-		exit(1);
-/*
- * Miscellaneous initialization.
- */
-
-	for (i = 0; ; i++) {
-		if (Pat[i].re == NULL)
-			break;
-		if ((Pat[i].pat = regcomp(Pat[i].re)) == NULL)
-			Error(WARN, NOLINE, Pat[i].re, " regcomp failure");
-	}
-	if ((i = Findscale((int)'n', 0.0, 0)) < 0)
-		Error(WARN, NOLINE, " can't find Scale['n']", NULL);
-	Scalen = Scale[i].val;
-	if ((i = Findscale((int)'u', 0.0, 0)) < 0)
-		Error(WARN, NOLINE, " can't find Scale['u']", NULL);
-	Scaleu = Scale[i].val;
-	if ((i = Findscale((int)'v', 0.0, 0)) < 0)
-		Error(WARN, NOLINE, " can't find Scale['v']", NULL);
-	Scalev = Scale[i].val;
-	(void) Findstr((unsigned char *)"CH", (unsigned char *)"= % -", 1);
-	Cont = Newstr((unsigned char *)" ");
-	Contlen = 1;
-	if ((Trtbl = (unsigned char *)malloc(256)) == NULL)
-		Error(WARN, NOLINE, " can't allocate translate table space",
-			NULL);
-	else {
-		*Trtbl = ' ';
-		for (i = 1; i < 256; i++)
-			Trtbl[i] = (unsigned char) i;
-	}
-	if (Err)
-		exit(1);
-/*
- * Here begins pass1 of awf - reading input lines and expanding macros.
- */
-
-/*
- * Output prolog.
- */
-	if (Fstr.i) {
-		for (i = 0; i < Fstr.il; i++) {
-			Charput((int)Fstr.i[i]);
-		}
-	}
-	Macro((unsigned char *)".^x");
-	Macro((unsigned char *)".^b");
-	Macro((unsigned char *)".^# 1 <prolog>");
-/*
- * Read input files.
- */
-	for (i = 0; i < nf; i++) {
-		Dowarn = (i >= pc);
-		if (files[i] == NULL) {
-			np = "stdin";
-			Ifs = stdin;
-		} else {
-#ifdef	UNIX
-			if ((Ifs = fopen(files[i], "r")) == NULL)
-#else
-			if ((Ifs = fopen(files[i], "rt")) == NULL)
-#endif
-				Error(FATAL, NOLINE, " can't open ", files[i]);
-			np = files[i];
-		}
-		if (i >= pc) {
-			(void) sprintf((char *)Line, ".^# 1 %s", np);
-			Macro(Line);
-			NR = 0;
-		}
-		Fsp = 0;
-		do {
-			while (fgets((char *)Line, MAXLINE, Ifs) != NULL) {
-				NR++;
-				if ((np = strrchr((char *)Line, '\n')) != NULL)
-					*np = '\0';
-				else
-					Line[MAXLINE-1] = '\0';
-				Macro(Line);
-			}
-			if (i >= pc)
-				Macro((unsigned char *)".^e");
-			if (Ifs != stdin)
-				(void) fclose(Ifs);
-			if (Fsp > 0) {
-				Free(&Inname);
-				Inname = Inn_stk[Fsp-1];
-				NR = NR_stk[Fsp-1];
-				Ifs = Ifs_stk[Fsp-1];
-			}
-		} while (Fsp-- > 0);
-	}
-	Macro(NULL);
-	if (fff)
-		Charput((int)'\f');
-	exit(Err);
-}
-
-
-/*
- * Macro(inp) - process a possible macro statement
- *		pass non-macros and macros alike to pass 2
- */
-
-void
-Macro(inp)
-	unsigned char *inp;		/* possible macro statement pointer */
-{
-	unsigned char c[2];		/* characters */
-	int endm;			/* end of macro status */
-	FILE *fs;			/* temporary file stream */
-	int i, j, k;                    /* temporary indexes */
-	int mx;                         /* Macrotab[] index */
-	int req;			/* request character status */
-	unsigned char *s1, *s2;		/* temporary string pointers */
-
-	if (inp == NULL) {
-		Pass2(NULL);
-		return;
-	}
-	req = (*inp == '.' || *inp == '\'') ? 1 : 0;
-/*
- * Check for file name designator.
- */
-	if (req && inp[1] == '^' && inp[2] == '#') {
-		Free(&Inname);
-		Inname = Field(3, inp, 1);
-		F = NULL;
-		Pass2(inp);
-		return;
-	}
-/*
- * Check for source command - "^[.']so".
- */
-	if (req && inp[1] == 's' && inp[2] == 'o') {
-		if ((s1 = Field(2, inp, 1)) == NULL) {
-			Error(WARN, LINE, " no file specified", NULL);
-			return;
-		}
-		if ((fs = fopen((char *)s1, "r")) == NULL) {
-			Error(WARN, LINE, " can't open", NULL);
-			return;
-		}
-		if (Fsp >= MAXFSTK) {
-			(void) fclose(fs);
-			Error(WARN, LINE, " nesting too deep", NULL);
-			return;
-		}
-		Ifs_stk[Fsp] = Ifs;
-		Ifs = fs;
-		Inn_stk[Fsp] = Inname;
-		Inname = F;
-		F = NULL;
-		NR_stk[Fsp++] = NR;
-		NR = 0;
-		return;
-	}
- /*
-  * Check for ignore.
-  */
-	if (req && inp[1] == 'i' && inp[2] == 'g') {
-		while (fgets((char *)inp, MAXLINE, Ifs) != NULL) {
-			NR++;
-			if (inp[0] == '.' && inp[1] == '.') break;
-		}
-		return;
-	}
- /*
-  * Check for start of macro definition.
-  */
-	if (req && inp[1] == 'd' && inp[2] == 'e') {
-		if (inp[3] != ' ' || inp[4] == '\0') {
-			Error(WARN, LINE, " illegal macro definition", NULL);
-			return;
-		}
-		c[0] = inp[4];
-		c[1] = inp[5];
-		Curmx = Findmacro(c, 1);
-		return;
-	}
-/*
- * Check for macro text.  Remove double backslashes.
- */
-	if (req && (inp[1] == '\0' || (inp[2] == '\0' && inp[0] == inp[1])))
-		endm = 1;
-	else
-		endm = 0;
-	if (Curmx >= 0 && !endm) {
-		if (Mtx >= MAXMTXT)
-			Error(FATAL, LINE, " out of macro text space", NULL);
-		if ((s1 = (unsigned char *)strchr((char *)inp, '\\')) == NULL)
-			Macrotxt[Mtx] = Newstr(inp);
-		else {
-			for (s1 = Pass1ln, s2 = inp;; s1++) {
-				if ((*s1 = *s2++) == '\0')
-					break;
-				if (*s1 == '\\' && *s2 == '\\')
-					s2++;
-			}
-			Macrotxt[Mtx] = Newstr(Pass1ln);
-		}
-		if (Macrotab[Curmx].bx == -1)
-			Macrotab[Curmx].bx = Mtx;
-		Mtx++;
-		Macrotab[Curmx].ct++;
-		return;
-	}
-/*
- * Check for end of macro.
- */
-	if (Curmx >= 0 && endm) {
-		Curmx = -1;
-		(void) sprintf((char *)Pass1ln, ".^# %d %s", NR, Inname);
-		Pass2(Pass1ln);
-		return;
-	}
- /*
-  * Check for conditionals and macro expansions.
-  */
-	if (req
-	&&  (((mx = Findmacro(inp+1, 0)) != -1) || regexec(Pat[0].pat, inp))) {
-		Expand(inp);
-		return;
-	}
-/*
- * None of the above: forward the line.
- */
-	Pass2(inp);
-}
Index: trunk/minix/commands/cawf/cawf.h
===================================================================
--- trunk/minix/commands/cawf/cawf.h	(revision 9)
+++ 	(revision )
@@ -1,265 +1,0 @@
-/*
- *	cawf.h - definitions for cawf(1)
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include <stdio.h>
-#ifdef	UNIX
-#include <sys/types.h>
-#else
-#include <sys\types.h>
-#endif
-#include "regexp.h"
-#include "cawflib.h"
-#include "proto.h"
-
-#define	DEVCONFIG	"device.cf"		/* device configuration file */
-#define ESC		'\033'			/* ESCape character */
-#define MAXEXP          30                      /* maximum expressions
-						 * (and TABs) */
-#define MAXFSTK		5			/* maximum file stack
-						 * (for .so) */
-#define MAXHYCH		10			/* maximum hyphen characters */
-#define MAXLINE         512			/* maximum line length */
-#define MAXMACRO        100			/* maximum number of macros */
-#define MAXMTXT         1024			/* maximum macro text lines */
-#define MAXNHNR		10			/* maximum ".NH" numbers
-						 * (but 0 not used) */
-#define MAXNR		50			/* maximum number reg */
-#define MAXOLL		512			/* maximum output line length */
-#define	MAXSCH		256			/* maximum special characters */
-#define MAXSP		25			/* maximum stack pointer (for
-						 * nesting of macro calls) */
-#define MAXSTR		100			/* maximum ".ds" strings */
-
-/*
- * Output line adjustment modes
- */
-
-#define LEFTADJ		0
-#define RIGHTADJ	1
-#define BOTHADJ		2
-
-/*
- * Error handling codes
- */
-
-#define	FATAL		0			/* fatal error */
-#define	LINE		0			/* display line */
-#define	NOLINE		1			/* don't display line */
-#define WARN		1			/* warning error */
-
-/*
- * Padding directions
- */
-
-#define	PADLEFT		0			/* pad from left */
-#define PADRIGHT	1			/* pad from right */
-
-/*
- * Pass 3 signal codes
- */
-
-#define NOBREAK		-1
-#define DOBREAK		-2
-#define MESSAGE		-3
-
-/*
- * Macro argument types
- */
-
-#define	MANMACROS	1			/* -man */
-#define MSMACROS	2			/* -ms */
-
-
-struct fcode {
-	unsigned char nm;		/* font name character */
-	unsigned char status;		/* status */
-};
-
-struct fontstr {			/* font control strings */
-
-	unsigned char *i;		/* font initialization string */
-	int il;				/* length of *i */ 
-	unsigned char *b;		/* bold */
-	int bl;				/* length of *bb */
-	unsigned char *it;		/* italic */
-	int itl;			/* length of *itb */
-	unsigned char *r;		/* roman string */
-	int rl;				/* length of *r */
-}; 
-
-struct hytab {
-	unsigned char font;		/* font name character */
-	int len;			/* effective length */
-	unsigned char *str;		/* value string */
-};
-
-struct macro {
-        unsigned char name[2];		/* macro name */
-        int bx;				/* beginning Macrotxt[] index */
-	int ct;				/* index count */
-};
-
-struct nbr {
-	unsigned char nm[2];		/* register name */
-	int val;			/* value */
-};
-
-struct parms {
-	char nm[2];			/* parameter name */
-	char *cmd;			/* pass 3 command */
-	int val;                        /* current value */
-	int prev;                       /* previous value */
-};
-
-struct rx {
-	char *re;			/* regular expression */
-	struct regexp *pat;		/* compiled pattern */
-};
-
-struct scale {
-	unsigned char nm;		/* scale factor name */
-	double val;			/* value */
-};
-
-struct schtab {
-	unsigned char nm[2];		/* character name */
-	int len;			/* effective length */
-	unsigned char *str;		/* value string */
-};
-
-struct str {
-	unsigned char nm[2];		/* string name */
-	unsigned char *str;		/* string value */
-};
-
-extern int Adj;				/* output line adjustment mode */
-extern unsigned char *Aftnxt;		/* action after next line */
-extern unsigned char *Args[];		/* macro arguments */
-extern unsigned char *Argstack[];	/* stack for Expand()'s "args[]" */
-extern int Backc;                       /* last word ended with '\\c' */
-extern int Botmarg;			/* bottom margin */
-extern int Centering;                   /* centering count */
-extern int Condstack[];                 /* stack for Expand()'s "cond" */
-extern unsigned char *Cont;		/* continue line append */
-extern int Contlen;			/* continue line append length */
-extern int Curmx;                 	/* current macro name */
-extern char *Device;			/* output device name */
-extern char *Devconf;			/* device configuration file path */
-extern char *Devfont;			/* output device font */
-extern int Divert;			/* diversion status */
-extern FILE *Efs;			/* error file stream pointer */
-extern unsigned char *Eol;		/* end of line information */
-extern int Eollen;			/* end of line length */
-extern int Err;                         /* error flag */
-extern unsigned char *F;		/* field value */
-extern struct fcode Fcode[];		/* font codes */
-extern int Fill;			/* fill status */
-extern unsigned char Font[];		/* current font */
-extern int Fontctl;			/* output font control */
-extern char Fontstat;			/* output font status */
-extern int Fph;				/* first page header status */
-extern int Fsp;                         /* files stack pointer (for .so) */
-extern struct fontstr Fstr;		/* font control strings */
-extern unsigned char *Ftc;		/* center footer */
-extern unsigned char *Ftl;		/* left footer */
-extern unsigned char *Ftr;		/* right footer */
-extern unsigned char *Hdc;		/* center header */
-extern int Hdft;			/* header/footer status */
-extern unsigned char *Hdl;		/* left header */
-extern unsigned char *Hdr;		/* right header */
-extern FILE *Ifs;			/* input file stream */
-extern FILE *Ifs_stk[];			/* Ifs stack */
-extern int Ind;                         /* indentation amount */
-extern unsigned char *Inname;		/* input file name */
-extern unsigned char *Inn_stk[];	/* Inname stack */
-extern struct hytab Hychar[];           /* hyphen characters */
-extern int LL;				/* line length */
-extern unsigned char Line[];		/* input line */
-extern int Lockil;			/* pass 2 line number is locked
-					 * (processing is inside macro) */
-extern int Marg;                        /* macro argument - man, ms, etc. */
-extern struct macro Macrotab[];         /* macro table */
-extern int Macrostack[];                /* stack for Expand()'s "macro" */
-extern unsigned char *Macrotxt[];	/* macro text */
-extern int Mtx;                         /* macro text index */
-extern int Mxstack[];                   /* stack for Expand()'s "mx" */
-extern int Nhnr[];			/* ".NH" numbers */
-extern int Nhy;                         /* number of Hychar[] entries */
-extern int Nleftstack[];                /* stack for Expand()'s "nleft" */
-extern int Nmac;                        /* number of macros */
-extern int Nnr;                         /* number of Numb[] entries */
-extern int Nospmode;			/* no space mode */
-extern int Nparms;                      /* number of Parms[] entries */
-extern int NR;                          /* number of record, ala awk */
-extern int NR_stk[];			/* NR stack */
-extern int Nsch;                        /* number of Schar[] entries */
-extern int Nstr;                        /* number of entries in Str[] */
-extern int Ntabs;			/* number of TAB positions */
-extern struct nbr Numb[];		/* number registers */
-extern int Nxtln;			/* next line number */
-extern char *optarg;			/* getopt(3) argument pointer */
-extern int optind;			/* getopt(3) index */
-extern int Outll;			/* output line length */
-extern unsigned char Outln[];		/* output line */
-extern int Outlx;			/* output line index */
-extern int P2il;                        /* pass 2 input line number */
-extern unsigned char *P2name;		/* pass 2 input file name */
-extern int P3fill;			/* pass 3 fill status */
-extern int Padchar[];			/* padding character locations */
-extern int Padfrom;			/* which end to pad from */
-extern int Padx;			/* Padchar[] index */
-extern struct parms Parms[];            /* parameter registers */
-extern unsigned char Pass1ln[];		/* pass 1 output line */
-extern unsigned char Pass2ln[];		/* pass 2 output line */
-extern struct rx Pat[];			/* compiled regexp patterns */
-extern int Pglen;			/* page length */
-extern int Pgoff;			/* page offset */
-extern char *Pname;			/* program name */
-extern unsigned char Prevfont;		/* previous font */
-extern int Ptrstack[];                  /* stack for Expand()'s "ptr" */
-extern struct scale Scale[];		/* scaling factors */
-extern double Scalen;                   /* 'n' scaling factor */
-extern double Scaleu;                   /* 'u' scaling factor */
-extern double Scalev;                   /* 'v' scaling factor */
-extern struct schtab Schar[];           /* special characters */
-extern int Sp;				/* stack pointer */
-extern struct str Str[];		/* ".ds" strings */
-extern int Sx;				/* string index */
-extern int Tabs[];			/* TAB positions */
-extern int Thispg;			/* this page number */
-extern int Tind;			/* temporary indentation amount */
-extern int Topmarg;			/* top margin */
-extern unsigned char *Trtbl;		/* .tr table */
-extern int Uhyph;			/* hyphen usage state */
-extern int Vspace;                      /* vertical (inter-text-line) spacing */
-extern unsigned char Word[];		/* pass 2 word buffer */
-extern int Wordl;                       /* effective length of Word[] */
-extern int Wordx;                       /* Word[] index */
-extern int Dowarn;			/* Enables warnings when true */
Index: trunk/minix/commands/cawf/cawflib.h
===================================================================
--- trunk/minix/commands/cawf/cawflib.h	(revision 9)
+++ 	(revision )
@@ -1,39 +1,0 @@
-/*
- *	cawflib.h - definition of cawf's library path
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#ifndef	CAWFLIB
-#ifdef  UNIX
-#define CAWFLIB         "/usr/lib/cawf"		/* UNIX library location */
-#else
-#define CAWFLIB         "c:/sys/lib/cawf"       /* PC-DOS library location */
-#endif
-#endif
-						/* (CAWFLIB environment
-						 * variable over-rides it) */
Index: trunk/minix/commands/cawf/common
===================================================================
--- trunk/minix/commands/cawf/common	(revision 9)
+++ 	(revision )
@@ -1,7 +1,0 @@
-.\" Common startup code, fully device-independent.
-.\" --------------------------------
-.fi
-.ce 0
-.ta +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8
-.in 0
-.ti 0
Index: trunk/minix/commands/cawf/device.c
===================================================================
--- trunk/minix/commands/cawf/device.c	(revision 9)
+++ 	(revision )
@@ -1,415 +1,0 @@
-/*
- *	device.c -- cawf(1) output device support functions
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-#include <ctype.h>
-
-_PROTOTYPE(static unsigned char *Convstr,(char *s, int *len));
-_PROTOTYPE(static int Convfont,(char *nm, char *s, char **fn,
-	unsigned char **fi));
-
-#ifndef	UNIX
-#define	strcasecmp	strcmpi
-#endif
-
-
-
-/*
- * Convstr(s, len) - convert a string
- */
-
-static unsigned char *
-Convstr(s, len)
-	char *s;			/* input string */
-	int *len;			/* length of result */
-{
-	int c;				/* character assembly */
-	unsigned char *cp;		/* temporary character pointer */
-	char *em;			/* error message */
-	int i;				/* temporary index */
-	int l;				/* length */
-	unsigned char *r;		/* result string */
-/*
- * Make space for the result.
- */
-	if ((r = (unsigned char *)malloc(strlen((char *)s) + 1)) == NULL) {
-		(void) fprintf(stderr, "%s: out of string space at %s\n",
-			Pname, s);
-		return(NULL);
-	}
-/*
- * Copy the input string to the result, processing '\\' escapes.
- */
-	for (cp = r, l = 0; *s;) {
-		switch (*s) {
-
-		case '\\':
-			s++;
-			if (*s >= '0' && *s <= '7') {
-		/*
-		 * '\xxx' -- octal form
-		 */
-				for (c = i = 0; i < 3; i++, s++) {
-					if (*s < '0' || *s > '7') {
-						em = "non-octal char";
-bad_string:
-						(void) fprintf(stderr,
-							"%s: %s : %s\n",
-							Pname, em, (char *)r);
-						return(NULL);
-					}
-					c = (c << 3) + *s - '0';
-				}
-				if (c > 0377) {
-					em = "octal char > 0377";
-					goto bad_string;
-				}
-				*cp++ = c;
-				l++;
-			} else if (*s == 'x') {
-		/*
-		 * '\xyy' -- hexadecimal form
-		 */
-				s++;
-				for (c = i = 0; i < 2; i++, s++) {
-#if	defined(__STDC__)
-					if ( ! isalpha(*s) && ! isdigit(*s))
-#else
-					if ( ! isascii(*s) && ! isalpha(*s)
-					&&   ! isdigit(*s))
-#endif
-					{
-non_hex_char:
-						em = "non-hex char";
-						goto bad_string;
-					}
-					c = c << 4;
-					if (*s >= '0' && *s <= '9')
-						c += *s - '0';
-					else if ((*s >= 'a' && *s <= 'f')
-					     ||  (*s >= 'A' && *s <= 'F'))
-						c += *s + 10 -
-						     (isupper(*s) ? 'A' : 'a');
-					else
-						goto non_hex_char;
-				}
-				*cp++ = (unsigned char)c;
-				l++;
-			} else if (*s == 'E' || *s == 'e') {
-		/*
-		 * '\E' or '\e' -- ESCape
-		 */
-				*cp++ = ESC;
-				l++;
-				s++;
-			} else if (*s == '\0') {
-				em = "no char after \\";
-				goto bad_string;
-			} else {
-		/*
-		 * escaped character (for some reason)
-		 */
-				*cp++ = *s++;
-				l++;
-			}
-			break;
-	/*
-	 * Copy a "normal" character.
-	 */
-		default:
-			*cp++ = *s++;
-			l++;
-		}
-	}
-	*cp = '\0';
-	*len = l;
-	return(r);
-}
-
-
-/*
- * Convfont(nm, s, fn, fi) - convert a font for a device
- */
-
-static int
-Convfont(nm, s, fn, fi)
-	char *nm;			/* output device name */
-	char *s;			/* font definition string */
-	char **fn;			/* font name address */
-	unsigned char **fi;		/* initialization string address */
-{
-	char *cp;			/* temporary character pointer */
-	int len;			/* length */
-/*
- * Get the font name, allocate space for it and allocate space for
- * a font structure.
- */
-	if ((cp = strchr(s, '=')) == NULL) {
-		(void) fprintf(stderr, "%s: bad %s font line format: %s\n",
-			Pname, nm, s);
-		return(0);
-	}
-	if ((*fn = (char *)malloc(cp - s + 1)) == NULL) {
-		(void) fprintf(stderr, "%s: no space for %s font name %s\n",
-			Pname, nm, s);
-		return(0);
-	}
-	(void) strncpy(*fn, s, cp - s);
-	(*fn)[cp - s] = '\0';
-/*
- * Assmble the font initialization string.
- */
-	if ((*fi = Convstr(cp + 1, &len)) == NULL)
-		return(0);
-	return(len);
-}
-
-
-/*
- * Defdev() - define the output device
- */
-
-int
-Defdev()
-{
-	unsigned char *fi = NULL;	/* last font initialization string */
-	char *fn = NULL;		/* font name */
-	int fd = 0;			/* found-device flag */
-	FILE *fs;			/* file stream */
-	int err = 0;			/* errror count */
-	int i;				/* temporary index */
-	int len;			/* length */
-	char line[MAXLINE];		/* line buffer */
-	char *p;			/* output device configuration file */
-	char *s;			/* temporary string pointer */
-/*
- * Check for the built-in devices, ANSI, NONE or NORMAL (default).
- */
-	Fstr.b = Fstr.i = Fstr.it = Fstr.r = NULL;
-	Fstr.bl = Fstr.il = Fstr.itl = Fstr.rl = 0;
-	if (Device == NULL || strcasecmp(Device, "normal") == 0) {
-		Fontctl = 0;
-check_font:
-		if (Devfont) {
-			(void) fprintf(stderr,
-				"%s: font %s for device %s illegal\n",
-				Pname, Devfont, Device ? Device : "NORMAL");
-			return(1);
-		}
-		return(0);
-	}
-	Fontctl = 1;
-	if (strcasecmp(Device, "ansi") == 0) {
-		Fstr.b = Newstr((unsigned char *)"x[1m");
-		Fstr.it = Newstr((unsigned char *)"x[4m");
-		Fstr.r = Newstr((unsigned char *)"x[0m");
-		Fstr.b[0] = Fstr.it[0] = Fstr.r[0] = ESC;
-		Fstr.bl = Fstr.itl = Fstr.rl = 4;
-		goto check_font;
-	}
-	if (strcasecmp(Device, "none") == 0)
-		goto check_font;
-/*
- * If a device configuration file path is supplied, use it.
- */
-	if (Devconf)
-		p = Devconf;
-	else {
-
-	/*
-	 * Use the CAWFLIB environment if it is defined.
-	 */
-		if ((p = getenv("CAWFLIB")) == NULL)	
-			p = CAWFLIB;
-		len = strlen(p) + 1 + strlen(DEVCONFIG) + 1;
-		if ((s = (char *)malloc(len)) == NULL) {
-			(void) fprintf(stderr, "%s: no space for %s name\n",
-				Pname, DEVCONFIG);
-			return(1);
-		}
-		(void) sprintf(s, "%s/%s", p, DEVCONFIG);
-		p = s;
-	}
-/*
- * Open the configuration file.
- */
-#ifdef	UNIX
-	if ((fs = fopen(p, "r")) == NULL)
-#else
-	if ((fs = fopen(p, "rt")) == NULL)
-#endif
-	{
-		(void) fprintf(stderr, "%s: can't open config file: %s\n",
-			Pname, p);
-		return(1);
-	}
-	*line = ' ';
-/*
- * Look for a device definition line -- a line that begins with a name.
- */
-	while ( ! feof(fs)) {
-		if (*line == '\t' || *line == '#' || *line == ' ') {
-			(void) fgets(line, MAXLINE, fs);
-			continue;
-		}
-		if ((s = strrchr(line, '\n')) != NULL)
-			*s = '\0';
-		else
-			line[MAXLINE-1] = '\0';
-	/*
-	 * Match device name.
-	 */
-		if (strcmp(Device, line) != 0) {
-			(void) fgets(line, MAXLINE, fs);
-			continue;
-		}
-		fd = 1;
-	/*
-	 * Read the parameter lines for the device.
-	 */
-		while (fgets(line, MAXLINE, fs) != NULL) {
-			if (*line == ' ') {
-				for (i = 1; line[i] == ' '; i++)
-					;
-			} else if (*line == '\t')
-				i = 1;
-			else
-				break;
-#if	defined(__STDC__)
-			if ( ! isalpha(line[i])
-#else
-			if ( ! isascii(line[i]) || ! isalpha(line[i])
-#endif
-			||   line[i+1] != '=')
-				break;
-			if ((s = strrchr(line, '\n')) != NULL)
-				*s = '\0';
-			else
-				line[MAXLINE-1] = '\0';
-			switch (line[i]) {
-		/*
-		 * \tb=<bolding_string>
-		 */
-			case 'b':
-				if (Fstr.b != NULL) {
-				    (void) fprintf(stderr,
-					"%s: dup bold for %s in %s: %s\n",
-					Pname, Device, p, line);
-					(void) free(Fstr.b);
-					Fstr.b = NULL;
-				}
-				if ((Fstr.b = Convstr(&line[i+2], &Fstr.bl))
-				== NULL)
-					err++;
-				break;
-		/*
-		 * \ti=<italicization_string>
-		 */
-			case 'i':
-				if (Fstr.it != NULL) {
-				    (void) fprintf(stderr,
-					"%s: dup italic for %s in %s: %s\n",
-					Pname, Device, p, line);
-					(void) free(Fstr.it);
-					Fstr.it = NULL;
-				}
-				if ((Fstr.it = Convstr(&line[i+2], &Fstr.itl))
-				== NULL)
-					err++;
-				break;
-		/*
-		 * \tr=<return_to_Roman_string>
-		 */
-			case 'r':
-				if (Fstr.r != NULL) {
-				    (void) fprintf(stderr,
-					"%s: dup roman for %s in %s: %s\n",
-					Pname, Device, p, line);
-					(void) free(Fstr.r);
-					Fstr.r = NULL;
-				}
-				if ((Fstr.r = Convstr(&line[i+2], &Fstr.rl))
-				== NULL)
-					err++;
-				break;
-		/*
-		 * \tf=<font_name>=<font_initialization_string>
-		 */
-			case 'f':
-				if ( ! Devfont || Fstr.i)
-					break;
-				if ((i = Convfont(Device, &line[i+2], &fn, &fi))
-				< 0)
-					err++;
-				else if (fn && strcmp(Devfont, fn) == 0) {
-					Fstr.i = fi;
-					Fstr.il = i;
-					fi = NULL;
-				}
-				if (fn) {
-					(void) free(fn);
-					fn = NULL;
-				}
-				if (fi) {
-					(void) free((char *)fi);
-					fi = NULL;
-				}
-				break;
-		/*
-		 * ????
-		 */
-			default:
-				(void) fprintf(stderr,
-					"%s: unknown device %s line: %s\n",
-					Pname, Device, line);
-				err++;
-			}
-		}
-		break;
-	}
-	(void) fclose(fs);
-	if (err)
-		return(1);
-/*
- * See if the device stanza was located and the font exists.
- */
-	if ( ! fd) {
-		(void) fprintf(stderr, "%s: can't find device %s in %s\n",
-			Pname, Device, p);
-		return(1);
-	}
-	if (Devfont && ! Fstr.i) {
-		(void) fprintf(stderr,
-			"%s: font %s for device %s not found in %s\n",
-			Pname, Devfont, Device, p);
-		return(1);
-	}
-	return(0);
-}
Index: trunk/minix/commands/cawf/device.cf
===================================================================
--- trunk/minix/commands/cawf/device.cf	(revision 9)
+++ 	(revision )
@@ -1,89 +1,0 @@
-# cawf(1) device configuration file
-#
-# device
-# \tb=bold_control_sequence
-# \ti=italic_control_sequence
-# \tr=roman_control_sequence
-# \tf=font_name=font_initialization
-#
-# The first font name is the default for the device.
-#
-# sorted in reverse alphabetical order by device name
-
-# VGA monochrome monitors
-#	italic = underline
-
-vgamono
-	b=\033[1m
-	i=\033[4m
-	r=\033[0m
-
-
-# HP LaserJet III
-
-lj3
-	b=\x1b(s7B
-	i=\x1b(s1S
-	r=\x1b(s0B\x1b(s0S
-	f=c10=\x1b&l0O\x1b(8U\x1b(s0p12h10v0s0b3T
-	f=c12ibm=\x1b&l0O\x1b(10U\x1b(s0p10.00h12.0v0s0b3T
-	f=lg12=\x1b&l0O\x1b(8U\x1b(s12h12v0s0b6T
-
-# Panasonic KX-P1180
-#	bold = Emphasized
-#
-#	all fonts are Near Letter Quality (NLQ)
-
-kxp1180
-	b=\033E
-	i=\0334
-	r=\0335\033F
-	f=c10=\033x1\033k0\033P
-	f=bps10=\033x1\033k6\033P
-	f=bps12=\033x1\033k6\033M
-	f=c12=\033x1\033k0\033M
-	f=p10=\033x1\033k3\033P
-	f=p12=\033x1\033k3\033M
-	f=ss10=\033x1\033k1\033P
-	f=ss12=\033x1\033k1\033M
-
-# Panasonic KX-P1124 (from Bob Hardy <hardy@lucid.com>)
-#       bold = Emphasized
-#
-#       all fonts are Near Letter Quality (NLQ)
-#
-#       The s10 and s12 fonts are Script, which is only available on the more
-#       deluxe models of the Panasonic KX-P1100 series -- e.g., Script is not
-#       supported on the KX-P1180, but is supported on the KX-P1124.
-
-kxp1124
-	b=\033E
-	i=\0334
-	r=\0335\033F
-	f=c10=\033x1\033k0\033P
-	f=bps10=\033x1\033k6\033P
-	f=bps12=\033x1\033k6\033M
-	f=c12=\033x1\033k0\033M
-	f=p10=\033x1\033k3\033P
-	f=p12=\033x1\033k3\033M
-	f=s10=\033x1\033k4\033P
-	f=s12=\033x1\033k4\033M
-	f=ss10=\033x1\033k1\033P
-	f=ss12=\033x1\033k1\033M
-
-# IBM Personal Printer Data Stream (PPDS) protocol
-#	bold = Double-strike
-#	italic = Underline
-
-ibmppds
-	b=\033G
-	i=\033-\001
-	r=\033-\000\033H
-
-# Epson FX-86e/FX-800
-#	bold = double strike
-
-epson
-	b=\033G
-	i=\0334
-	r=\0335\033H
Index: trunk/minix/commands/cawf/diffs
===================================================================
--- trunk/minix/commands/cawf/diffs	(revision 9)
+++ 	(revision )
@@ -1,211 +1,0 @@
-diff -c1 ../4.0.2.dist/Makefile ./Makefile
-*** ../4.0.2.dist/Makefile	Thu Nov 26 09:06:28 1992
---- ./Makefile	Thu Nov 26 09:17:08 1992
-***************
-*** 36,40 ****
-  
-! DEFS = -DUNIX -DSTDLIB -ansi -pedantic
-  
-! CFLAGS = -O ${DEFS}
-  
---- 36,40 ----
-  
-! DEFS = -DUNIX -DUSG -DSTDLIB
-  
-! CFLAGS = -i -s -f -O ${DEFS}
-  
-diff -c1 ../4.0.2.dist/README ./README
-*** ../4.0.2.dist/README	Thu Nov 26 09:06:28 1992
---- ./README	Thu Nov 26 09:19:26 1992
-***************
-*** 54,56 ****
---- 54,68 ----
-  
-+ Changes to cawf to run under Minix:
-  
-+ 	*  The DOS binaries and make files have been removed.
-+  
-+ 	*  Tabs stops changed from per 5 to per 8.
-+ 
-+ 	*  Bold and underline as it should be in device.cf.
-+ 
-+ 	*  Added .SB and .TA to man.mac.
-+ 
-+ 	*  Numerous prototypes added.
-+ 
-+ 
-  CONTENTS
-***************
-*** 58,62 ****
-  
-! This Unix distribution of cawf includes:
-  
-! 	00readme	    this file
-  	*.c and *.h	    source files to build cawf and bsfilt (bsfilt
---- 70,74 ----
-  
-! This Minix distribution of cawf includes:
-  
-! 	README		    this file
-  	*.c and *.h	    source files to build cawf and bsfilt (bsfilt
-***************
-*** 64,70 ****
-  	bsfilt.1	    nroff source for the bsfilt manual page
-- 	bsfilt.exe.uue	    uuencoded MS-DOS bsfilt executable
-- 	bsfilt.mak	    MS-DOS Quick-C make file for bsfilt
-  	cawf.1		    nroff source for the cawf manual page
-- 	cawf.exe.uue	    uuencoded MS-DOS cawf executable
-- 	cawf.mak	    MS-DOS Quick-C make file for cawf
-  	common		    initialization file for CAWFLIB library
---- 76,78 ----
-***************
-*** 77,86 ****
-  	ms.mac		    ms(7) macros for CAWFLIB library
-  
-- Hint: to generate an MS-DOS executable, uudecode the *.exe.uue file -- e.g.
-  
-- 	$ uudecode cawf.exe.uue
-- 
-- yields a cawf.exe file.
-- 
-- 
-  LIBRARY
---- 85,94 ----
-  	ms.mac		    ms(7) macros for CAWFLIB library
-+ 	diffs		    Minix patches
-+ #ifdef PUTTING_IT_ON_THE_NET
-+ 	cawf
-+ 	bsfilt		    binaries compiled under Minix-PC 1.5 using the ACK
-+ 			    ANSI C compiler using software floating point
-+ #endif
-  
-  
-  LIBRARY
-***************
-*** 89,92 ****
-  To use cawf, you must select a location for the CAWFLIB library files.  The
-! distributed cawf.exe expects to find them in c:\sys\lib\cawf, but you can
-! alter that with the CAWFLIB environment variable, or you can change the
-  CAWFLIB #define in cawf.h and rebuild cawf from the sources.
---- 97,100 ----
-  To use cawf, you must select a location for the CAWFLIB library files.  The
-! distributed cawf binary expects to find them in /usr/local/lib/cawf but you
-! can alter that with the CAWFLIB environment variable, or you can change the
-  CAWFLIB #define in cawf.h and rebuild cawf from the sources.
-***************
-*** 135,139 ****
-  
-! A Unix make file and a cawf.mak file for version 2.5 of Microsoft MS-DOS
-! Quick-C are included.  The Unix make file has some definitions that help
-! tune it to the local Unix environment:
-  
---- 143,146 ----
-  
-! The Unix make file has some definitions that help tune it to the local
-! Unix environment:
-  
-***************
-*** 251 ****
---- 258,264 ----
-  
-+ 
-+ MINIX SPECIFIC TINKERING
-+ ------------------------
-+ 
-+ Kees J. Bot <kjb@cs.vu.nl>
-+ 26 November 1992
-diff -c1 ../4.0.2.dist/cawflib.h ./cawflib.h
-*** ../4.0.2.dist/cawflib.h	Thu Nov 26 09:06:35 1992
---- ./cawflib.h	Thu Nov 26 09:17:10 1992
-***************
-*** 32,34 ****
-  #ifdef  UNIX
-! #define CAWFLIB         "/Homes/abe/lib/cawf"	/* UNIX library location */
-  #else
---- 32,34 ----
-  #ifdef  UNIX
-! #define CAWFLIB         "/usr/local/lib/cawf"	/* UNIX library location */
-  #else
-diff -c1 ../4.0.2.dist/common ./common
-*** ../4.0.2.dist/common	Thu Nov 26 09:06:36 1992
---- ./common	Thu Nov 26 09:17:10 1992
-***************
-*** 4,6 ****
-  .ce 0
-! .ta +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5
-  .in 0
---- 4,6 ----
-  .ce 0
-! .ta +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8
-  .in 0
-diff -c1 ../4.0.2.dist/device.c ./device.c
-*** ../4.0.2.dist/device.c	Thu Nov 26 09:06:36 1992
---- ./device.c	Thu Nov 26 09:34:09 1992
-***************
-*** 229,231 ****
-  	if (strcasecmp(Device, "ansi") == 0) {
-! 		Fstr.b = Newstr((unsigned char *)"x[7m");
-  		Fstr.it = Newstr((unsigned char *)"x[4m");
---- 229,231 ----
-  	if (strcasecmp(Device, "ansi") == 0) {
-! 		Fstr.b = Newstr((unsigned char *)"x[1m");
-  		Fstr.it = Newstr((unsigned char *)"x[4m");
-diff -c1 ../4.0.2.dist/device.cf ./device.cf
-*** ../4.0.2.dist/device.cf	Thu Nov 26 09:06:37 1992
---- ./device.cf	Thu Nov 26 09:21:17 1992
-***************
-*** 13,15 ****
-  # VGA monochrome monitors
-! #	italic = reverse video
-  
---- 13,15 ----
-  # VGA monochrome monitors
-! #	italic = underline
-  
-***************
-*** 17,19 ****
-  	b=\033[1m
-! 	i=\033[7m
-  	r=\033[0m
---- 17,19 ----
-  	b=\033[1m
-! 	i=\033[4m
-  	r=\033[0m
-Only in .: diffs
-diff -c1 ../4.0.2.dist/man.mac ./man.mac
-*** ../4.0.2.dist/man.mac	Thu Nov 26 09:06:42 1992
---- ./man.mac	Thu Nov 26 09:17:12 1992
-***************
-*** 5,7 ****
-  .ds LH "\\$1(\\$2)
-! .ds CH "Unix Programmer's Manual
-  .ds RH "\\$1(\\$2)
---- 5,7 ----
-  .ds LH "\\$1(\\$2)
-! .ds CH "Minix Programmer's Manual
-  .ds RH "\\$1(\\$2)
-***************
-*** 120,121 ****
---- 120,128 ----
-  .\"-----------------
-+ .de SB
-+ .\" Can't reduce size, just do bold
-+ .ft B
-+ .it 1 fP
-+ .if \\n(.$>0 \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-+ ..
-+ .\"-----------------
-  .de IR
-***************
-*** 150,152 ****
-  .de DT
-! .ta +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5
-  ..
---- 157,163 ----
-  .de DT
-! .ta +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8
-! ..
-! .\"-----------------
-! .de TA
-! .ta \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-  ..
Index: trunk/minix/commands/cawf/dumb.dev
===================================================================
--- trunk/minix/commands/cawf/dumb.dev	(revision 9)
+++ 	(revision )
@@ -1,158 +1,0 @@
-.\" Device-dependent but not macro-set-dependent definitions.
-.\" --------------------------------
-.\" overall formatting initialization
-.\" 12 cpi horizontal exploits 80-column terminal well (6.5i@12 = 78)
-.^r cpi 12 6
-.\" call margin adjustment device-dependent for sake of some unusual cases
-.ad
-.\" page parameters
-.pl 10i
-.ll 6.5i
-.po 0
-.\" --------------------------------
-.\" fonts, and their hyphens, last font change doubled to set up \fP
-.^f R
-.ft R
-.^c hy 1 -
-.^f I
-.ft I
-.^c hy 1 -
-.^f B
-.ft B
-.^c hy 1 -\b-\b-
-.^f C
-.ft C
-.^c hy 1 -\b-\b-
-.ft R
-.ft R
-.\" --------------------------------
-.\" definitions of nroff special characters
-.\" The character definitions here operate on the "better ugly than invisible"
-.\" principle, and try to approximate the character *somehow*.  They were
-.\" tuned for a Teletype 40 line printer, but should give vaguely plausible
-.\" results on any overprinting ASCII device.
-.\"
-.\" first, things that nroff considered builtins
-.^c \ 1 \\
-.^c e 1 \\
-.^c ' 1 '
-.^c ` 1 `
-.^c - 1 -
-.\" some things seem to assume that \+ is like \-
-.^c + 1 +
-.\" we do not do backslash-space here, it can't be done with .^c, but the
-.\" other forms of space we can do
-.^c 0 1 " 
-.^c | 0
-.^c ^ 0
-.^c & 0
-.\"
-.\" and more normal characters
-.\" note, the hyphenation logic knows about em
-.^c em 2 --
-.^c en 1 -
-.\" hy is a special case, see above
-.^c bu 1 +\bo
-.^c sq 2 []
-.^c ru 1 _
-.^c 12 3 1/2
-.^c 14 3 1/4
-.^c 34 3 3/4
-.^c de 1 '\b`
-.^c dg 1 -\b!
-.^c fm 1 '
-.^c ct 1 /\bc
-.^c rg 3 (R)
-.^c co 3 (c)
-.^c pl 1 +
-.^c mi 1 -
-.^c eq 1 =
-.^c ** 1 *
-.^c sc 1 j\bf
-.^c aa 1 '
-.^c ga 1 `
-.^c ul 1 _
-.^c sl 1 /
-.^c *a 1 <\ba
-.^c *b 1 ,\bB
-.^c *g 1 ,\by
-.^c *d 1 S\bo
-.^c *e 1 -\bc
-.^c *z 1 ,\bL
-.^c *y 1 ,\bn
-.^c *h 1 -\b0
-.^c *i 1 ,\bi
-.^c *k 1 <\bK
-.^c *l 1 \\\b>
-.^c *m 1 ,\bu
-.^c *n 1 ,\bv
-.^c *c 1 ,\b3
-.^c *o 1 o
-.^c *p 1 -\bn
-.^c *r 1 p
-.^c *s 1 -\bo
-.^c ts 1 s
-.^c *t 1 ~\bt
-.^c *u 1 u
-.^c *f 1 /\bo
-.^c *x 1 /\b\\
-.^c *q 1 |\bu
-.^c *w 1 u\bw
-.^c *G 2 ~\b|~
-.^c *D 2 _\b/_\b\\
-.^c *H 1 -\bO
-.^c *L 2 /\\
-.^c *C 1 _\b-\b~
-.^c *P 2 ~\b|~\b|
-.^c *S 1 ~\b_\b>
-.^c *U 1 Y
-.^c *F 1 |\bO
-.^c *Q 1 |\bU
-.^c *W 2 _\b(_\b)
-.^c sr 2 \\/
-.^c rn 1 ~
-.^c >= 1 _\b>
-.^c <= 1 _\b<
-.^c == 1 _\b=
-.^c ~= 1 ~\b=
-.^c ap 1 ~
-.^c != 1 /\b=
-.^c -> 2 ->
-.^c <- 2 <-
-.^c ua 1 |\b^
-.^c da 1 |\bv
-.^c mu 1 x
-.^c di 1 -\b:
-.^c +- 1 _\b+
-.^c cu 1 U
-.^c ca 3 (^)
-.^c sb 2 (_\b~
-.^c sp 2 _\b~)
-.^c ib 2 (~\b_\b=
-.^c ip 2 ~\b_\b=)
-.^c if 2 oo
-.^c pd 1 3\bo
-.^c gr 1 ~\bV
-.^c no 1 -
-.^c is 1 '\b,\bI
-.^c pt 2 oc
-.^c es 1 /\bO
-.^c mo 1 -\bC
-.^c br 1 |
-.^c dd 1 I\b|
-.^c rh 1 =\b>
-.^c lh 1 =\b<
-.^c bs 4 (:-)
-.^c or 1 |
-.^c ci 1 O
-.^c lt 1 ~\b(
-.^c lb 1 _\b(
-.^c rt 1 ~\b)
-.^c rb 1 _\b)
-.^c lk 1 -\b(
-.^c rk 1 -\b)
-.^c bv 1 |
-.^c lf 1 _\b[
-.^c rf 1 _\b]
-.^c lc 1 ~\b[
-.^c rc 1 ~\b]
Index: trunk/minix/commands/cawf/error.c
===================================================================
--- trunk/minix/commands/cawf/error.c	(revision 9)
+++ 	(revision )
@@ -1,97 +1,0 @@
-/*
- *	error.c - error handling functions for cawf(1)
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-
-
-/*
- * Error(t, l, s1, s2) - issue error message
- */
-
-void
-Error(t, l, s1, s2)
-	int t;				/* type: WARN or FATAL */
-	int l;				/* LINE: display Line[] */
-	char *s1, *s2;			/* optional text */
-{
-	char msg[MAXLINE];		/* message */
-
-	if (t == WARN && !Dowarn) return;
-
-	if (l == LINE)
-		(void) fprintf(Efs, "%s: (%s, %d):%s%s - %s\n",
-			Pname,
-			Inname,
-			NR,
-			(s1 == NULL) ? "" : s1,
-			(s2 == NULL) ? "" : s2,
-			Line);
-	else
-		(void) fprintf(Efs, "%s:%s%s\n",
-			Pname,
-			(s1 == NULL) ? "" : s1,
-			(s2 == NULL) ? "" : s2);
-	if (t == FATAL)
-		exit(1);
-	Err = 1;
-	return;
-}
-
-
-/*
- * Error3(len, word, sarg, narg) - process error in pass3
- */
-
-void
-Error3(len, word, sarg, narg, msg)
-	int len;			/* length (negative is special */
-        char *word;			/* word */
-        char *sarg;			/* string argument */
-        int narg;                       /* numeric argument */
-	char *msg;			/* message */
-{
-	if (len == MESSAGE) {
-		(void) fprintf(Efs, "%s: (%s, %d) %s\n",
-			Pname,
-			(word == NULL) ? "<none>" : word,
-			narg,
-			(sarg == NULL) ? "<none>" : sarg);
-		return;
-	}
-	(void) fprintf(Efs,
-		"%s: pass3, len=%d, word=\"%s\", sarg=\"%s\", narg=%d%s%s\n",
-		Pname, len,
-		(word == NULL) ? "" : word,
-		(sarg == NULL) ? "" : sarg,
-		narg,
-		(msg == NULL) ? "" : " - ",
-		(msg == NULL) ? "" : msg);
-	Err = 1;
-}
Index: trunk/minix/commands/cawf/expand.c
===================================================================
--- trunk/minix/commands/cawf/expand.c	(revision 9)
+++ 	(revision )
@@ -1,308 +1,0 @@
-/*
- *	expand.c - macro expansion functions for cawf(1)
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-
-/*
- * Expand(line) - expand macro or if/ie/el line
- */
-
-void
-Expand(line)
-	unsigned char *line;
-{
-	unsigned char buf[2*MAXLINE];	/* line buffer */
-	unsigned char cmd[4];		/* nroff command */
-	int cmdl;			/* command length */
-	int cmdx;			/* cmd index in Macrotab[] */
-	int cond = 0;			/* conditional statuses */
-	int i, j;			/* temporary indexes */
-	int iflen;			/* if statement length */
-	int invert;			/* inversion status */
-	unsigned char *lp;		/* line pointer */
-	int mx = -1;			/* Macrotab[] index */
-	int n1, n2;			/* temporary numbers */
-	int nargs = 0;			/* number of arguments */
-	int nleft = 0;			/* number of macro lines left */
-	char op;			/* comparison operator */
-	int prevcond;			/* previous condition (for else's) */
-	int ptr = -1;			/* Macrotxt[] index */
-	int quote;			/* quoted string status */
-	unsigned char *s1, *s2;		/* temporary string pointers */
-
-
-	(void) sprintf((char *)buf, ".^= %d %s", NR, (char *)Inname);
-	Pass2(buf);
-
-	for (lp = line; *lp; ) {
-		invert = regexec(Pat[1].pat, lp);
-		prevcond = cond;
-		cond = 0;
-		if (regexec(Pat[0].pat, lp) == 0) {
-	    /*
-	     * Not conditional: - ! "^[.'](i[ef]|el)"
-	     */
-			cond = 1;
-			iflen = 0;
-		}
-
-		else if (regexec(Pat[2].pat, lp)) {
-	    /*
-	     * Argument count comparison: -
-	     *		"^[.']i[ef] !?\\n\(\.\$(>|>=|=|<|<=)[0-9] "
-	     */
-			iflen = strlen(".if \\n(.$=n ") + invert;
-			s1 = lp + iflen - 3;
-			op = *s1++;
-			if (*s1 == '=' && (op == '>' || op == '<')) {
-				s1++;
-				op = (op == '>') ? 'G' : 'L';
-			}
-			n1 = (int)(*s1 - '0');
-			switch (op) {
-				case '=':
-					if ((nargs - 1) == n1)
-						cond = 1;
-					break;
-				case '<':
-					if ((nargs - 1) < n1)
-						cond = 1;
-					break;
-				case '>':
-					if ((nargs - 1) > n1)
-						cond = 1;
-					break;
-				case 'G':	/* >= */
-					if ((nargs - 1) >= n1)
-						cond = 1;
-					break;
-				case 'L':	/* <= */
-					if ((nargs - 1) <= n1)
-						cond = 1;
-			}
-		}
-		
-		else if (regexec(Pat[3].pat, lp)) {
-	    /*
-	     * Argument string comparison: - "^[.']i[ef] !?'\\\$[0-9]'[^']*' "
-	     */
-			iflen = strlen(".if '\\$n'") + invert;
-			n1 = (int)(*(lp + iflen - 2) - '0');
-			if (n1 >= 0 && n1 < nargs)
-				s1 = Args[n1];
-			else
-				s1 = (unsigned char *)"";
-			if ((s2 = (unsigned char *)strchr((char *)lp
-				  + iflen, '\''))
-			!= NULL) {
-				n2 = s2 - lp - iflen;
-				if (strncmp((char *)s1, (char *)lp + iflen, n2)
-				== 0)
-					cond = 1;
-				iflen += n2 + 2;
-			}
-		}
-		
-		else if (regexec(Pat[4].pat, lp)) {
-	    /*
-	     * Nroff or troff: - "^[.']i[ef] !?[nt] "
-	     */
-			iflen = strlen(".if n ") + invert;
-			if (*(lp + iflen - 2) == 'n')
-				cond = 1;
-		}
-		
-		else if ((*lp == '.' || *lp == '\'')
-		     &&  strncmp((char *)lp+1, "el ", 3) == 0) {
-	    /*
-	     * Else clause: - "^[.']el "
-	     */
-			cond = 1 - prevcond;
-			iflen = 4;
-		}
-		
-		else {
-	    /*
-	     * Unknown conditional:
-	     */
-			cond = 1;
-			iflen = 0;
-			(void) sprintf((char *)buf,
-				".tm unknown .if/.ie form: %s", (char *)lp);
-			lp = buf;
-		}
-	   /*
-	    * Handle conditional.  If case is true, locate predicate.
-	    * If predicate is an .i[ef], process it.
-	    */
-		if (invert)
-			cond = 1 - cond;
-		if (cond && iflen > 0) {
-			lp += iflen;
-			if (regexec(Pat[15].pat, lp))
-				continue;
-		}
-	    /*
-	     * Do argument substitution, as necessary.
-	     */
-		if (cond && regexec(Pat[5].pat, lp)) {      /* "\$[0-9]" ??? */
-			for (s1 = buf;;) {
-				if ((n1 = Pat[5].pat->startp[0] - lp) > 0) {
-					(void) strncpy((char *)s1, (char *)lp,
-						n1);
-					s1 += n1;
-				}
-				*s1 = '\0';
-				lp = Pat[5].pat->endp[0];
-				n1 = (int)(*(lp-1) - '0');
-				if (n1 >= 0 && n1 < nargs) {
-					(void) strcpy((char *)s1,
-						(char *)Args[n1]);
-					s1 += strlen((char *)Args[n1]);
-				}
-				if (*lp == '\0')
-					break;
-				if (regexec(Pat[5].pat, lp) == 0) {
-					(void) strcpy((char *)s1, (char *)lp);
-					break;
-				}
-			}
-			lp = buf;
-		}
-	    /*
-	     * Check for nroff command.
-	     */
-		if (cond) {
-			cmdl = 0;
-			if (cond && (*lp == '.' || *lp == '\'')) {
-				if ((*cmd = *(lp+1)) != '\0') {
-					cmdl++;
-					if ((*(cmd+1) = *(lp+2)) == ' ')
-						*(cmd+1) = '\0';
-					else
-						cmdl++;
-				}
-			}
-			cmd[cmdl] = '\0';
-		}
-		if (cond == 0)
-			i = i;		/* do nothing if condition is false */
-		else if (cmdl == 0 || ((cmdx = Findmacro(cmd, 0)) < 0))
-			Pass2(lp);
-		else if (Sp >= MAXSP) {
-			(void) sprintf((char *)buf, " macro nesting > %d",
-				MAXSP);
-			Error(WARN, LINE, (char *)buf, NULL);
-		} else {
-	    /*
-	     * Stack macros.
-	     */
-		  /*
-		   * Push stack.
-		   */
-			Sp++;
-			Nleftstack[Sp] = nleft;
-			Ptrstack[Sp] = ptr;
-			Mxstack[Sp] = mx;
-			Condstack[Sp] = cond;
-			for (i = 10*Sp, j = 0; j < 10; i++, j++) {
-				Argstack[i] = Args[j];
-				Args[j] = NULL;
-			}
-		   /*
-		    * Start new stack entry.
-		    */
-			mx = cmdx;
-			ptr = Macrotab[mx].bx;
-			cond = 0;
-			nleft = Macrotab[mx].ct;
-			Args[0] = Newstr(cmd);
-		   /*
-		    * Parse arguments.
-		    */
-			for (s1 = lp + cmdl + 1, nargs = 1; nargs < 10;) {
-				while (*s1 && (*s1 == ' ' || *s1 == '\t'))
-					s1++;
-				if (*s1 == '\0')
-					break;
-				if (*s1 == '"') {
-					s1++;
-					quote = 1;
-				} else
-					quote = 0;
-				for (s2 = buf;;) {
-				    if (!quote && (*s1 == ' ' || *s1 == '\t')) {
-					*s2 = '\0';
-					break;
-				    }
-				    if ((*s2 = *s1) == '\0')
-					break;
-				    s1++;
-				    if (quote && *s2 == '"') {
-					*s2 = '\0';
-					break;
-				    }
-				    s2++;
-			    	}
-				if (buf[0])
-					Args[nargs++] = Newstr(buf);
-			}
-			for (i = nargs; i < 10; i++) {
-				Args[i] = NULL;
-			}
-		}
-	    /*
-	     * Unstack completed macros.
-	     */
-		while (nleft <= 0 && Sp >= 0) {
-			nleft = Nleftstack[Sp];
-			mx = Mxstack[Sp];
-			ptr = Ptrstack[Sp];
-			cond = Condstack[Sp];
-			for (i = 10*Sp, j = 0, nargs = -1; j < 10; i++, j++) {
-				Free(&Args[j]);
-				if ((Args[j] = Argstack[i]) != NULL)
-					nargs = j;
-			}
-			Sp--;
-			nargs++;
-		}
-	    /*
-	     * Get next line.
-	     */
-		if (nleft > 0) {
-			lp = Macrotxt[ptr++];
-			nleft--;
-		} else
-			lp = (unsigned char *)"";
-	}
-	(void) sprintf((char *)buf, ".^# %d %s", NR, (char *)Inname);
-	Pass2(buf);
-}
Index: trunk/minix/commands/cawf/expr.c
===================================================================
--- trunk/minix/commands/cawf/expr.c	(revision 9)
+++ 	(revision )
@@ -1,175 +1,0 @@
-/*
- *	expr.c - expression support functions for cawf(1)
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-
-
-/*
- * Asmcode(s, c) - assemble number/name code following backslash-character
- *		   definition  - e. .g, "\\nPO"
- */
-
-unsigned char *
-Asmcode(s, c)
-	unsigned char **s;		/* pointer to character after '\\' */
-	unsigned char *c;		/* code destination (c[3]) */
-{
-	unsigned char *s1;
-
-	s1 = *s + 1;
-	c[0] = c[1] = c[2] = '\0';
-	if ((c[0] = *s1) == '(') {
-		s1++;
-		if ((c[0] = *s1) != '\0') {
-			s1++;
-			c[1] = *s1;
-		}
-	}
-	return(s1);
-}
-
-
-/*
- * Delnum(nx) - delete number
- */
-
-void
-Delnum(nx)
-	int nx;				/* number index */
-{
-	unsigned char buf[MAXLINE];	/* message buffer */
-
-	if (nx >= Nnr) {
-		(void) sprintf((char *)buf, " bad Delnum(%d) index", nx);
-		Error(FATAL, LINE, (char *)buf, NULL);
-	}
-	while (nx < (Nnr - 1)) {
-		Numb[nx] = Numb[nx + 1];
-		nx++;
-	}
-	Nnr--;
-}
-
-
-/*
- * Findnum(n, v, e) - find or optionally enter number value
- */
-
-Findnum(n, v, e)
-	unsigned char *n;		/* register name */
-	int v;				/* value */
-	int e;				/* 0 = find, don't enter
-					 * 1 = enter, don't find */
-{
-	int cmp, low, hi, mid;		/* binary search controls */
-	unsigned char c[3];		/* name buffer */
-
-	c[0] = n[0];
-	c[1] = (n[1] == ' ' || n[1] == '\t') ? '\0' : n[1];
-	c[2] = '\0';
-	low = mid = 0;
-	hi = Nnr - 1;
-	while (low <= hi) {
-		mid = (low + hi) / 2;
-		if ((cmp = strncmp((char *)c, (char *)Numb[mid].nm, 2)) < 0)
-			hi = mid - 1;
-		else if (cmp > 0)
-			low = mid + 1;
-		else {
-			if (e)
-				Numb[mid].val = v;
-			return(mid);
-		}
-	}
-	if ( ! e)
-		return(-1);
-	if (Nnr >= MAXNR)
-		Error(FATAL, LINE, " out of number registers at ", (char *)c);
-	if (Nnr) {
-		if (cmp > 0)
-			mid++;
-		for (hi = Nnr - 1; hi >= mid; hi--)
-			Numb[hi+1] = Numb[hi];
-	}
-	Nnr++;
-	Numb[mid].nm[0] = c[0];
-	Numb[mid].nm[1] = c[1];
-	Numb[mid].val = v;
-	return(mid);
-}
-
-
-/*
- * Findparms(n) - find parameter registers
- */
-
-Findparms(n)
-	unsigned char *n;		/* parameter name */
-{
-	unsigned char c[3];		/* character buffer */
-	int i;				/* temporary index */
-
-	c[0] = n[0];
-	c[1] = (n[1] == ' ' || n[1] == '\t') ? '\0' : n[1];
-	c[2] = '\0';
-	for (i = 0; Parms[i].nm[0]; i++) {
-		if (c[0] == Parms[i].nm[0] && c[1] == Parms[i].nm[1])
-			return(i);
-	}
-	return(-1);
-}
-
-
-/*
- * Findscale(n, v, e) - find and optionally enter scaling factor value
- */
-
-Findscale(n, v, e)
-	int n;				/* scaling factor name */
-	double v;			/* value */
-	int e;				/* 0 = find, don't enter
-					 * 1 = enter, don't find */
-{
-	int i;
-	double *pval;
-
-	for (i = 0; Scale[i].nm; i++) {
-		if ((unsigned char )n == Scale[i].nm)
-			break;
-	}
-	if (Scale[i].nm) {
-		if (e) {
-			pval = &Scale[i].val;
-			*pval = v;
-		}
-		return(i);
-	}
-	return(-1);
-}
Index: trunk/minix/commands/cawf/getopt.c
===================================================================
--- trunk/minix/commands/cawf/getopt.c	(revision 9)
+++ 	(revision )
@@ -1,77 +1,0 @@
-/*
-Newsgroups: mod.std.unix
-Subject: public domain AT&T getopt source
-Date: 3 Nov 85 19:34:15 GMT
-
-Here's something you've all been waiting for:  the AT&T public domain
-source for getopt(3).  It is the code which was given out at the 1985
-UNIFORUM conference in Dallas.  I obtained it by electronic mail
-directly from AT&T.  The people there assure me that it is indeed
-in the public domain.
-*/
-
-
-/*LINTLIBRARY*/
-#define NULL	0
-#define EOF	(-1)
-#define ERR(s, c)	if(opterr){\
-	extern int strlen(), write();\
-	char errbuf[2];\
-	errbuf[0] = c; errbuf[1] = '\n';\
-	(void) write(2, argv[0], (unsigned)strlen(argv[0]));\
-	(void) write(2, s, (unsigned)strlen(s));\
-	(void) write(2, errbuf, 2);}
-
-extern int strcmp();
-extern char *strchr();
-
-int	opterr = 1;
-int	optind = 1;
-int	optopt;
-char	*optarg;
-
-int
-getopt(argc, argv, opts)
-int	argc;
-char	**argv, *opts;
-{
-	static int sp = 1;
-	register int c;
-	register char *cp;
-
-	if(sp == 1)
-		if(optind >= argc ||
-		   argv[optind][0] != '-' || argv[optind][1] == '\0')
-			return(EOF);
-		else if(strcmp(argv[optind], "--") == NULL) {
-			optind++;
-			return(EOF);
-		}
-	optopt = c = argv[optind][sp];
-	if(c == ':' || (cp=strchr(opts, c)) == NULL) {
-		ERR(": illegal option -- ", c);
-		if(argv[optind][++sp] == '\0') {
-			optind++;
-			sp = 1;
-		}
-		return('?');
-	}
-	if(*++cp == ':') {
-		if(argv[optind][sp+1] != '\0')
-			optarg = &argv[optind++][sp+1];
-		else if(++optind >= argc) {
-			ERR(": option requires an argument -- ", c);
-			sp = 1;
-			return('?');
-		} else
-			optarg = argv[optind++];
-		sp = 1;
-	} else {
-		if(argv[optind][++sp] == '\0') {
-			sp = 1;
-			optind++;
-		}
-		optarg = NULL;
-	}
-	return(c);
-}
Index: trunk/minix/commands/cawf/macsup.c
===================================================================
--- trunk/minix/commands/cawf/macsup.c	(revision 9)
+++ 	(revision )
@@ -1,181 +1,0 @@
-/*
- *	macsup.c - macro processing support functions for cawf(1)
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-
-
-/*
- * Delmacro(mx) - delete macro
- */
-
-Delmacro(mx)
-	int mx;				/* macro index */
-{
-	unsigned char buf[MAXLINE];	/* error message buffer */
-	int i, j;			/* temporary indexes */
-
-	if (mx >= Nmac) {
-		(void) sprintf((char *)buf, " bad Delmacro(%d) index", mx);
-		Error(FATAL, LINE, (char *)buf, NULL);
-	}
-	for (i = Macrotab[mx].bx, j = i + Macrotab[mx].ct; i < j; i++) {
-		Free(&Macrotxt[i]);
-	}
-	for (i = mx; i < (Nmac - 1); i++) {
-		Macrotab[i] = Macrotab[i+1];
-	}
-	Nmac--;
-}
-
-
-/*
- * Field(n, p, c) - skip to field n in p and optionally return a copy
- */
-
-unsigned char *
-Field(n, p, c)
-	int n;				/* field number */
-	unsigned char *p;		/* pointer to line containing fields */
-	int c;				/* 1: make a copy of the field */
-{
-	unsigned char *fs, *fe, *s;
-
-	if (c)
-		Free(&F);
-	fe = p;
-	while (n) {
-		while (*fe == ' ' || *fe == '\t')
-			fe++;
-		fs = fe;
-		while (*fe && *fe != ' ' && *fe != '\t')
-			fe++;
-		if (fs == fe)
-			return(NULL);
-		if (n == 1) {
-			if ( ! c)
-				return(fs);
-			if ((F = (unsigned char *)malloc((size_t)(fe - fs + 1)))
-			== NULL)
-				Error(FATAL, LINE, " Field out of string space",
-					NULL);
-			(void) strncpy((char *)F, (char *)fs, (fe - fs));
-			F[fe -fs] = '\0';
-			return(F);
-		}
-		n--;
-	}
-	return(NULL);
-}
-
-/*
- * Findmacro(p, e) - find macro and optionally enter it
- *
- * return = Macrotab[] index or -1 if not found
- */
-
-
-Findmacro(p, e)
-	unsigned char *p;	/* pointer to 2 character macro name  */
-	int e;			/* 0 = find, don't enter
-				 * 1 = enter, don't find */
-{
-	unsigned char c[3];
-	int cmp, hi, low, mid;
-
-	c[0] = p[0];
-	c[1] = (p[1] == ' ' || p[1] == '\t') ? '\0' : p[1];
-	c[2] = '\0';
-	low = mid = 0;
-	hi = Nmac - 1;
-	while (low <= hi) {
-		mid = (low + hi) / 2;
-		if ((cmp = strncmp((char *)c, (char *)Macrotab[mid].name, 2))
-		< 0)
-			hi = mid - 1;
-		else if (cmp > 0)
-			low = mid + 1;
-		else {
-			if ( ! e)
-				return(mid);
-			 Error(WARN, LINE, " duplicate macro ", (char *)c);
-			 hi = Macrotab[mid].bx + Macrotab[mid].ct;
-			 for (low = Macrotab[mid].bx; low < hi; low++) {
-				Free(&Macrotxt[low]);
-			 }
-			 goto new_macro;
-		}
-	}
-	if ( ! e)
-		return(-1);
-	if (Nmac >= MAXMACRO)
-		Error(FATAL, LINE, " macro table full at ", (char *)c);
-	if (Nmac) {
-		if (cmp > 0)
-			mid++;
-		for (hi = Nmac - 1; hi >= mid; hi--)
-			Macrotab[hi+1] = Macrotab[hi];
-	}
-	Nmac++;
-	Macrotab[mid].name[0] = c[0];
-	Macrotab[mid].name[1] = c[1];
-
-new_macro:
-
-	Macrotab[mid].bx = -1;
-	Macrotab[mid].ct = 0;
-	return(mid);
-}
-
-void
-Free(p)
-	unsigned char **p;
-{
-	if (*p != NULL) {
-		(void) free(*p);
-		*p = NULL;
-	}
-}
-
-/*
- * Newstr(s) - allocate space for string
- */
-
-unsigned char *
-Newstr(s)
-	unsigned char *s;
-{
-	unsigned char *ns;
-
-	if ((ns = (unsigned char *)malloc((size_t)(strlen((char *)s) + 1)))
-	== NULL)
-	    Error(FATAL, LINE, " Newstr out of malloc space at ", (char *)s);
-	(void) strcpy((char *)ns, (char *)s);
-	return(ns);
-}
Index: trunk/minix/commands/cawf/man.mac
===================================================================
--- trunk/minix/commands/cawf/man.mac	(revision 9)
+++ 	(revision )
@@ -1,180 +1,0 @@
-.^b HF 1
-.^b fh 1
-.\"-----------------
-.de TH
-.ds LH "\\$1(\\$2)
-.ds CH "Minix Programmer's Manual
-.ds RH "\\$1(\\$2)
-.ds LF "
-.ds CF "\\$3
-.ds RF "%
-..
-.\"-----------------
-.de AT
-..
-.\"-----------------
-.de IX
-..
-.\"-----------------
-.de NB
-.ds nb "\\$1
-.lF
-..
-.\"-----------------
-.de BY
-.ds by "\\$1
-.lF
-..
-.\"-----------------
-.de UC
-.BY "\\$1BSD"
-..
-.\"-----------------
-.\" common initialization for headers and paragraphs:  .In need
-.de In
-.ne \\$1
-.sp \\n(PDu
-.fi
-.in 0
-.ti 0
-.in \\n(inu
-.it
-.ft R
-.ns
-..
-.\"-----------------
-.de SH
-.In 6
-.in 0
-.ft B
-\&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-.ft R
-.nr in 5n
-.in \\n(inu
-..
-.\"-----------------
-.de SS
-.In 6
-.in 2n
-.ft B
-\&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-.ft R
-.in \\n(inu
-..
-.\"-----------------
-.de LP
-.In 4
-..
-.\"-----------------
-.de PP
-.LP
-..
-.\"-----------------
-.de P
-.LP
-..
-.\"-----------------
-.de HP
-.In 4
-.if \\n(.$>0 .ti 0-\\$1
-.if \\n(.$=0 .ti 0-\\n(tpu
-..
-.\"-----------------
-.de TP
-.In 4
-.if \\n(.$>0 .nr tp \\$1n
-.in \\n(inu+\\n(tpu
-.ti 0-\\n(tpu
-.it 1 tP
-..
-.\"-----------------
-.de IP
-.ie \\n(.$>1 .TP "\\$2"
-.el .TP
-\&\\$1
-..
-.\"-----------------
-.de I
-.ft I
-.it 1 fR
-.if \\n(.$>0 \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-..
-.\"-----------------
-.de B
-.ft B
-.it 1 fR
-.if \\n(.$>0 \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-..
-.\"-----------------
-.de SB
-.\" Can't reduce size, just do bold
-.ft B
-.it 1 fR
-.if \\n(.$>0 \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-..
-.\"-----------------
-.de IR
-\&\\fI\\$1\\fR\\$2\\fI\\$3\\fR\\$4\\fI\\$5\\fR\\$6\\fI\\$7\\fR\\$8\\fI\\$9\\fR
-..
-.\"-----------------
-.de RI
-\&\\$1\\fI\\$2\\fR\\$3\\fI\\$4\\fR\\$5\\fI\\$6\\fR\\$7\\fI\\$8\\fR\\$9
-..
-.\"-----------------
-.de BR
-\&\\fB\\$1\\fR\\$2\\fB\\$3\\fR\\$4\\fB\\$5\\fR\\$6\\fB\\$7\\fR\\$8\\fB\\$9\\fR
-..
-.\"-----------------
-.de RB
-\&\\$1\\fB\\$2\\fR\\$3\\fB\\$4\\fR\\$5\\fB\\$6\\fR\\$7\\fB\\$8\\fR\\$9
-..
-.\"-----------------
-.de BI
-\&\\fB\\$1\\fI\\$2\\fB\\$3\\fI\\$4\\fB\\$5\\fI\\$6\\fB\\$7\\fI\\$8\\fB\\$9\\fR
-..
-.\"-----------------
-.de IB
-\&\\fI\\$1\\fB\\$2\\fI\\$3\\fB\\$4\\fI\\$5\\fB\\$6\\fI\\$7\\fB\\$8\\fI\\$9\\fR
-..
-.\"-----------------
-.de SM
-.\" no-op
-.if \\n(.$>0 \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-..
-.\"-----------------
-.de DT
-.ta +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8
-..
-.\"-----------------
-.de TA
-.ta \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-..
-.\"-----------------
-.de RS
-.in +5n
-..
-.\"-----------------
-.de RE
-.in -5n
-..
-.de DS
-.br
-..
-.de DE
-.br
-..
-.\"-----------------
-.de PD
-.ie \\n(.$=0 .nr PD 0.3v
-.el .nr PD \\$1n
-..
-.\"-----------------
-.\" misc. initialization
-.nr tp 5n
-.PD
-.ds lq \&"
-.ds rq \&"
-.ds R \(rg
-.ds S "
-.ds Tm (TM)
-.nr )P 1v
Index: trunk/minix/commands/cawf/me.mac
===================================================================
--- trunk/minix/commands/cawf/me.mac	(revision 9)
+++ 	(revision )
@@ -1,199 +1,0 @@
-.^b HF 1
-.^b fh 0
-.^b NH
-.\"-----------------
-.de r
-.ie \\n(.$=0 .ft R
-.el \\fR\\$1\\fP\\$2
-..
-.\"-----------------
-.de i
-.ie \\n(.$=0 .ft I
-.el \\fI\\$1\\fP\\$2
-..
-.\"-----------------
-.de b
-.ie \\n(.$=0 .ft B
-.el \\fB\\$1\\fP\\$2
-..
-.\"-----------------
-.de UX
-\\$2UNIX\\$1
-..
-.\"-----------------
-.de DA
-.ds DY "\\$1 \\$2 \\$3
-.\" keep trailing spaces out of CF
-.if \\n(.$=1 .ds CF "\\$1
-.if \\n(.$=2 .ds CF "\\$1 \\$2
-.if \\n(.$>2 .ds CF "\\$1 \\$2 \\$3
-..
-.\"-----------------
-.de ND
-.\" it's our default, ignore it
-..
-.\"-----------------
-.de TL
-.rs
-.sp 5
-.ft B
-.ce 9999
-..
-.\"-----------------
-.de AU
-.sp 2
-.ft R
-..
-.\"-----------------
-.de AI
-.sp
-.ft R
-..
-.\"-----------------
-.de AB
-.sp 2
-.ce 0
-.ll -7n
-.in +7n
-..
-.\"-----------------
-.de AE
-.sp
-.ll
-.in
-..
-.\" common initialization for headers and paragraphs:  .In need extraspace
-.de In
-.ne \\$1
-.sp \\n(Tsu
-.nr Ts 0
-.ie \\n(.$>1 .nr iN \\$2v
-.el .nr iN 0
-.sp \\n(psu+\\n(iNu
-.ce 0
-.ft R
-.in 0
-.ti 0
-.in \\n(inu
-.ll \\n(LLu
-.ns
-.fi
-..
-.\"-----------------
-.de uh
-.\" unnumbered section head
-.nr in 0
-.In 6 1
-.ie \\n(.$=0 .ft B
-.el \\fB\\$1\\fP\\$2
-..
-.\"-----------------
-.de sh
-.\" numbered section head
-.nr in 0
-.In 6 1
-.ft B
-.\" punt to awk code to get the header numbering right
-.nH \\$1
-.\" and pick up the result
-\&\\*(Nh \\$2
-.ft R
-..
-.\"-----------------
-.de lp
-.\" left-blocked paragraph
-.In 4
-..
-.\"-----------------
-.de pp
-.\" paragraph, first line indented
-.In 4
-.ti \\n(piu
-..
-.\"-----------------
-.de tp
-.In 4
-.if \\n(.$>0 .nr tp \\$1n
-.in \\n(inu+\\n(tpu
-.ti 0-\\n(tpu
-.\" .it 1 tP
-..
-.\"-----------------
-.de ip
-.\" indented paragraph
-.ie \\n(.$>1 .tp "\\$2"
-.el .tp 4n
-\&\\$1
-..
-.\"-----------------
-.de np
-.\" numbered paragraph
-.nr $p +1			\" increment paragraph number
-.ip (\n($p)
-..
-.\"-----------------
-.de bu
-.\" bulleted paragraph
-.ip \(bu
-..
-.\"-----------------
-.de (q
-.\" begin major quote
-.nr in +5n
-.nr LL -5n
-.In 4
-..
-.\"-----------------
-.de )q
-.\" end major quote
-.sp
-.nr in -5n
-.nr LL +5n
-.In 4
-..
-.\"-----------------
-.de (l
-.\" begin list
-.In 5
-.if '\\$1'C' .ce 9999
-.if '\\$1'' .in +5n
-.if '\\$1'L' .in 0
-.nf
-..
-.\"-----------------
-.de )l
-.\" end list
-.In 3
-.sp
-.rs
-..
-.\"-----------------
-.de u
-\&\\fI$1\\fP
-..
-.\"-----------------
-.de sm
-..
-.\"-----------------
-.\" exdented paragraph macro borrowed from Berkeley -ms
-.de XP	
-.lp
-.in \\n(piu
-.ti
-..
-.\"-----------------
-.\" the -ms accent strings
-.ds ' "'\b
-.ds ` "`\b
-.ds : ":\b
-.ds ^ "^\b
-.ds ~ "~\b
-.ds C "v\b
-.ds , ",\b
-.\" post-title spacing (set to 4v if using .TL macro)
-.nr Ts 0v
-.\" and parameter setup
-.nr LL 6i
-.ll \n(LLu
-.nr ps 0.3v
-.nr pi 5n
Index: trunk/minix/commands/cawf/mnx.mac
===================================================================
--- trunk/minix/commands/cawf/mnx.mac	(revision 9)
+++ 	(revision )
@@ -1,137 +1,0 @@
-.\" -mnx macros for the Minix "Book manual pages".	Author: Kees J. Bot
-.\"								19 Nov 1994
-.\" Uses -ms:
-.so /usr/lib/cawf/ms.mac
-.tr ~
-.ds OQ \&'
-.ds CQ \&'
-.ds SQ \&'
-.ds M0 MINIX
-.ds M1 \\s-1MINIX\\s+1
-.ds M2 \\s-2MINIX\\s+2
-.ds M9 \\s-1MINIX\\s+1
-.ds m0 minix
-.de MX
-\s-2MINIX\s+2\\$1
-..
-.de Ux
-\s-2UNIX\s+2\\$1
-..
-.ds Mx \\s-1MINIX\\s0
-.ds Mp \\s-1MINIX-PC\\s0
-.ds Ms \\s-1MINIX-ST\\s0
-.ds M0 MINIX
-.ds M1 MINIX
-.ds M2 MINIX
-.ds M9 MINIX
-.ds Mx MINIX
-.ds Mp MINIX-PC
-.ds Ms MINIX-ST
-.de CD
-.LP
-.ne 2
-.ta 11m 15m 36m
-.ds SX Syntax:
-.ds FL Flags:
-.ds EX Examples:
-.ds EY Example:
-.in +16m
-.ti -16m
-\\fBCommand:\&	\\$1\\fR
-.in -16m
-.br
-..
-.de SX
-.in +16m
-.ti -16m
-\\fB\*(SX\&	\\$1
-.in -16m
-.ds SX
-.br
-..
-.de FL
-.in +15m
-.ti -15m
-\\fB\*(FL\&	\\fB\\$1	\\fR\\$2
-.in -15m
-.ds FL
-.br
-..
-.de EX
-.br
-.in +38m
-.ti -38m
-\\fB\*(EX\&	\\fR\\$1		\\fR# \\$2
-.in -38m
-.ds EX
-.ds EY
-.br
-..
-.de EY
-.br
-.in +38m
-.ti -38m
-\\fB\*(EY\&	\\fR\\$1		\\fR# \\$2
-.in -38m
-.ds EX
-.ds EY
-.br
-..
-.de Cx
-.in +8
-.ft B
-\&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-.ft R
-.in -8
-..
-.de DI
-.ft B
-\&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-.ft R
-..
-.de SY
-\\$3\\$1\\$2
-..
-.de HS
-.sp 0.5
-..
-.de SP
-.sp
-..
-.\"	Major section (normally numbered)
-.de SE
-.sp 1
-\fB\\$1\fP
-.sp 1
-..
-.\"	Subsection (normally numbered)
-.de SS
-.sp 1
-\fB\\$1\fP
-..
-.de UU
-.SH
-\\$1
-.sp 1
-..
-.\"	Start list
-.de LI
-.in +0.25i
-.ll -0.25i
-.HS
-..
-.\"	End list
-.de LX
-.sp 1
-.in -0.25i
-.ll +0.25i
-.LP
-..
-.\"	List item
-.de IT
-.HS
-..
-.\"Short unnumbered lines
-.de UN
-.HS
-..
Index: trunk/minix/commands/cawf/ms.mac
===================================================================
--- trunk/minix/commands/cawf/ms.mac	(revision 9)
+++ 	(revision )
@@ -1,210 +1,0 @@
-.^b HF 1
-.^b fh 0
-.^b NH
-.\"-----------------
-.de R
-.ie \\n(.$=0 .ft R
-.el \\fR\\$1\\fP\\$2
-..
-.\"-----------------
-.de I
-.ie \\n(.$=0 .ft I
-.el \\fI\\$1\\fP\\$2
-..
-.\"-----------------
-.de B
-.ie \\n(.$=0 .ft B
-.el \\fB\\$1\\fP\\$2
-..
-.\"-----------------
-.de UX
-\\$2UNIX\\$1
-..
-.\"-----------------
-.de DA
-.ds DY "\\$1 \\$2 \\$3
-.\" keep trailing spaces out of CF
-.if \\n(.$=1 .ds CF "\\$1
-.if \\n(.$=2 .ds CF "\\$1 \\$2
-.if \\n(.$>2 .ds CF "\\$1 \\$2 \\$3
-..
-.\"-----------------
-.de ND
-.\" it's our default, ignore it
-..
-.\"-----------------
-.de TL
-.rs
-.sp 5
-.ft B
-.ce 9999
-..
-.\"-----------------
-.de AU
-.sp 2
-.ft R
-..
-.\"-----------------
-.de AI
-.sp
-.ft R
-..
-.\"-----------------
-.de AB
-.sp 2
-.ce 0
-.ll -7n
-.in +7n
-..
-.\"-----------------
-.de AE
-.sp
-.ll
-.in
-..
-.\"-----------------
-.\" common initialization for headers and paragraphs:  .In need extraspace
-.de In
-.ne \\$1
-.sp \\n(Tsu
-.nr Ts 0
-.ie \\n(.$>1 .nr iN \\$2v
-.el .nr iN 0
-.sp \\n(PDu+\\n(iNu
-.ce 0
-.ft R
-.in 0
-.ti 0
-.in \\n(inu
-.ll \\n(LLu
-.ns
-.fi
-..
-.\"-----------------
-.de SH
-.nr in 0
-.In 6 1
-.ft B
-..
-.\"-----------------
-.de NH
-.nr in 0
-.In 6 1
-.ft B
-.\" punt to awk code to get the header numbering right
-.nH \\$1
-.\" and pick up the result
-\&\\*(Nh
-..
-.\"-----------------
-.de LP
-.In 4
-..
-.\"-----------------
-.de PP
-.In 4
-.ti \\n(PIu
-..
-.\"-----------------
-.de TP
-.In 4
-.if \\n(.$>0 .nr tp \\$1n
-.in \\n(inu+\\n(tpu
-.ti 0-\\n(tpu
-.it 1 tP
-..
-.\"-----------------
-.de IP
-.ie \\n(.$>1 .TP "\\$2"
-.el .TP 4n
-\&\\$1
-..
-.\"-----------------
-.de QP
-.In 4
-.in +5n
-.ll -5n
-..
-.\"-----------------
-.de QS
-.nr in +5n
-.nr LL -5n
-.In 4
-..
-.\"-----------------
-.de QE
-.nr in -5n
-.nr LL +5n
-.In 4
-..
-.\"-----------------
-.de DS
-.In 5
-.if '\\$1'C' .ce 9999
-.if '\\$1'' .in +5n
-.nf
-..
-.\"-----------------
-.de CD
-.In 5
-.ce 9999
-.nf
-..
-.\"-----------------
-.de LD
-.In 5
-.nf
-..
-.\"-----------------
-.de ID
-.In 5
-.in +5n
-.nf
-..
-.\"-----------------
-.de DE
-.In 3
-.rs
-..
-.\"-----------------
-.de RS
-.nr in +5n
-.in \\n(inu
-..
-.\"-----------------
-.de RE
-.nr in -5n
-.in \\n(inu
-..
-.\"-----------------
-.de UL
-\&\\fI$1\\fP
-..
-.\"-----------------
-.de RP
-..
-.\"-----------------
-.de LG
-..
-.\"-----------------
-.de SM
-..
-.\"-----------------
-.de NL
-..
-.\"-----------------
-.\" the -ms accent strings
-.ds ' "'\b
-.ds ` "`\b
-.ds : ":\b
-.ds ^ "^\b
-.ds ~ "~\b
-.ds C "v\b
-.ds , ",\b
-.\" post-title spacing
-.nr Ts 4v
-.\" and parameter setup
-.nr LL 6i
-.ll \n(LLu
-.nr PD 0.3v
-.nr PI 5n
Index: trunk/minix/commands/cawf/nreq.c
===================================================================
--- trunk/minix/commands/cawf/nreq.c	(revision 9)
+++ 	(revision )
@@ -1,880 +1,0 @@
-/*
- *	nreq.c - cawf(1) processing of nroff requests
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-#include <ctype.h>
-
-
-/*
- * Prototypes for request processing functions.
- */
-
-_PROTOTYPE(static void nr_UL,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_Ub,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_Uc,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_Uf,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_Ur,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_ad,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_bp,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_br,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_ce,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_di,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_ds,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_fi,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_fl,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_ft,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_it,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_na,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_nf,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_ns,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_rm,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_rn,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_rr,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_rs,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_tm,(unsigned char *line, int brk));
-_PROTOTYPE(static void nr_tr,(unsigned char *line, int brk));
-
-_PROTOTYPE(static void nr_nil,(unsigned char *line, int brk));
-
-
-/*
- * NrReqt[] - nroff request processing table
- *
- * CAUTION: place new entries in their proper alphabetical order, since
- *	    this table is processed with a binary search.
- */
-
-static struct nr_req {
-	char *nm;			/* nroff request */
-	void (*fun)();			/* processing function */
-} NrReqt[] = {
-	{ "\\\"",	nr_nil },	/* backslash-quote */
-	{ "^#",		nr_UL  },
-	{ "^=",		nr_UL  },
-	{ "^b",		nr_Ub  },
-	{ "^c",		nr_Uc  },
-	{ "^d",		nr_nil },
-	{ "^e",		nr_nil },
-	{ "^f",		nr_Uf  },
-	{ "^r",		nr_Ur  },
-	{ "^x",		nr_nil },
-	{ "ad",		nr_ad  },
-	{ "bp",		nr_bp  },
-	{ "br",		nr_br  },
-	{ "ce",		nr_ce  },
-	{ "di",		nr_di  },
-	{ "ds",		nr_ds  },
-	{ "fi",		nr_fi  },
-	{ "fl",		nr_fl  },
-	{ "ft",		nr_ft  },
-	{ "hy",		nr_nil },
-	{ "i0",		nr_nil },
-	{ "it",		nr_it  },
-	{ "lg",		nr_nil },
-	{ "li",		nr_nil },
-	{ "na",		nr_na  },
-	{ "nf",		nr_nf  },
-	{ "ns",		nr_ns  },
-	{ "ps",		nr_nil },
-	{ "rm",		nr_rm  },
-	{ "rn",		nr_rn  },
-	{ "rr",		nr_rr  },
-	{ "rs",		nr_rs  },
-	{ "tm",		nr_tm  },
-	{ "tr",		nr_tr  },
-	{ "vs",		nr_nil },
-};
-/*
- * Nreq(line, brk) - process miscellaneous nroff requests from line
- *		     buffer with request status of (brk)
- */
-
-void
-Nreq(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	unsigned char c[3];		/* command buffer */
-	int cmp, hi, low, mid;		/* binary search indixes */
-
-	c[0] = c[1] = c[2] = '\0';
-	if ((c[0] = line[1]) != '\0')
-		c[1] = line[2];
-
-	low = mid = 0;
-	hi = sizeof(NrReqt) / sizeof(struct nr_req);
-	while (low <= hi) {
-		mid = (low + hi) / 2;
-		if ((cmp = strcmp((char *)c, NrReqt[mid].nm)) < 0)
-			hi = mid - 1;
-		else if (cmp > 0)
-			low = mid + 1;
-		else {
-			(void) (*NrReqt[mid].fun)(line, brk);
-			return;
-		}
-	}
-    /*
-     * Unknown request starting with a '.' or '\''..
-     */
-	Error(WARN, LINE, " unknown request", NULL);
-}
-
-
-/*
- * Adjust - "^[.']ad"
- */
-
-static void
-nr_ad(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Pass3(NOBREAK, (unsigned char *)"both", NULL, 0);
-}
-
-
-/*
-* Begin new page - "^[.']bp"
-*/
-
-static void
-nr_bp(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Pass3(brk, (unsigned char *)"need", NULL, 999);
-}
-
-
-/*
-* Break - "^[.']br"
-*/
-
-static void
-nr_br(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Pass3(brk, (unsigned char *)"flush", NULL, 0);
-}
-
-
-/*
- * Center - "^[.']ce"
- */
-
-static void
-nr_ce(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	unsigned char *s;			/* string poiner */
-
-	if ((s = Field(2, line, 0)) != NULL)
-		Centering = atoi((char *)s);
-	else
-		Centering = 1;
-}
-
-
-/*
- * Diversion on and off - "^[.']di"
- */
-
-static void
-nr_di(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Pass3(DOBREAK, (unsigned char *)"flush", NULL, 0);
-	Divert ^= 1;
-}
-
-
-/*
- * Define string - "^[.']ds"
- */
-
-static void
-nr_ds(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	unsigned char buf[MAXLINE];	/* temporary buffer */
-	unsigned char nm[4], nm1[4];	/* name buffers */
-	unsigned char *s1, *s2, *s3,	/* temporary string pointers */
-		       *s4;
-
-	if (Asmname(&line[3], nm) == 0) {
-		Error(WARN, LINE, " no name", NULL);
-		return;
-	}
-	s1 = Field(3, line, 0);
-	s2 = Findstr(nm, s1, 1);
-	while (*s2 == '\\' && *(s2 + 1) == '*') {
-		s2++;
-		s3 = Asmcode(&s2, nm1);
-		s2 = Findstr(nm1, NULL, 0);
-	}
-	if (Hdft) {
-
-	/*
-	 * Look for names LH, LF, CH, CF, RH, RF.
-	 */
-		if ((nm[0]=='L' || nm[0]=='C' || nm[0]=='R')
-		&&  (nm[1]=='F' || nm[1]=='H')) {
-			(void) sprintf((char *)buf, "%s", (char *)nm);
-			Pass3(NOBREAK, buf, s2, 0);
-		}
-	}
-}
-
-
-
-/*
- * Fill - "^[.']fi"
- */
-
-static void
-nr_fi(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Fill = 1;
-	Pass3(brk, (unsigned char *)"flush", NULL, 0);
-}
-
-
-/*
- * Flush - "^[.']fl"
- */
-
-static void
-nr_fl(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Pass3(brk, (unsigned char *)"flush", NULL, 0);
-}
-
-
-/*
- * Font - "^[.']ft <font_name>"
- */
-
-static void
-nr_ft(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	int i;				/* temporary index */
-
-	if (line[3] == '\0' || line[4] == '\0')
-		line[4] = 'P';
-	if (line[4] == 'P') {
-		Font[0] = Prevfont;
-		return;
-	}
-	for (i = 0; Fcode[i].nm; i++) {
-		if (Fcode[i].nm == line[4])
-		break;
-	}
-	if (Fcode[i].status == '\0') {
-		Error(WARN, LINE, " bad font code", NULL);
-		return;
-	}
-	Prevfont = Font[0];
-	Font[0] = line[4];
-}
-
-
-/*
- * Input trap - "^[.']it [1 <request>]"
- */
-
-static void
-nr_it(line, brk)
-	unsigned char *line;
-	int brk;
-
-{
-	unsigned char buf[MAXLINE];	/* temporary buffer */
-	int i;				/* temporary index */
-	unsigned char *s1, *s2;		/* temporary string pointers */
-
-	if ((s1 = Field(2, line, 0)) == NULL) {
-		Free(&Aftnxt);
-		return;
-	}
-	if ((i = atoi((char *)s1)) != 1) {
-		Error(WARN, LINE, " first .it arg must be 1", NULL);
-		return;
-	}
-	if ((s2 = Field(3, line, 0)) == NULL)
-		Free(&Aftnxt);
-	else {
-		(void) sprintf((char *)buf, "%s,%s",
-			(Aftnxt == NULL) ? "" : (char *)Aftnxt,
-			(char *)s2);
-		Free(&Aftnxt);
-		Aftnxt = Newstr(buf);
-	}
-}
-
-
-/*
- * Comment - "^[.']\\" - do nothing
- *
- * Debug - "^[.']\^d" - do nothing
- *
- * Finalization - "[.']\^e" - do nothing
- *
- * Error file - "^[.']\^x <name>" - do nothing
- *
- * "^[.']i0", "^[.']lg" and "^[.']li" - do nothing
- *
- * Point size - "^[.']ps" - do nothing
- *
- * Vertical spacing - "^[.']vs" - do nothing
- *
- */
-
-static void
-nr_nil(line, brk)
-	unsigned char *line;
-	int brk;
-{
-}
-
-
-/*
- * No adjust "^[.']na"
- */
-
-static void
-nr_na(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Pass3(NOBREAK, (unsigned char *)"left", NULL, 0);
-}
-
-
-/*
- * No fill - "^[.']nf"
- */
-
-static void
-nr_nf(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Fill = 0;
-	Pass3(brk, (unsigned char *)"flush", NULL, 0);
-}
-
-
-/*
- * No space - "^[.']ns"
- */
-
-static void
-nr_ns(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Pass3(NOBREAK, (unsigned char *)"nospace", NULL, 0);
-}
-
-
-/*
- * Remove macro or string - "^[.']rm"
- */
-
-static void
-nr_rm(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	int i;				/* temporary index */
-	unsigned char nm[4];		/* name buffer */
-
-	if (Asmname(&line[3], nm) == 0) {
-		Error(WARN, LINE, " no name", NULL);
-		return;
-	}
-	if ((i = Findmacro(nm, 0)) >= 0) {
-		Delmacro(i);
-		return;
-			}
-	(void) Findstr(nm, NULL, 0);
-		if (Sx >= 0) {
-			Delstr(Sx);
-			return;
-	}
-	Error(WARN, LINE, " no macro/string", NULL);
-}
-
-
-/*
- * Rename macro or string - "^[.']rn"
- */
-
-static void
-nr_rn(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	int i, j;			/* temporary indexes */
-	unsigned char nm[4], nm1[4];	/* name buffers */
-	unsigned char *s1;		/* temporary string pointer */
-
-	if ((s1 = Field(2, line, 0)) == NULL ||  Asmname(s1, nm) == 0) {
-		Error(WARN, LINE, " no name", NULL);
-		return;
-	}
-	if ((s1 = Field(3, line, 0)) == NULL ||  Asmname(s1, nm1) == 0) {
-		Error(WARN, LINE, " no new name", NULL);
-		return;
-	}
-	if ((i = Findmacro(nm, 0)) >= 0) {
-		if ((j = Findmacro(nm1, 0)) >= 0)
-			Delmacro(j);
-		j = Findmacro(nm1, 1);
-		Macrotab[j].bx = Macrotab[i].bx;
-		Macrotab[i].bx = -1;
-		Macrotab[j].ct = Macrotab[i].ct;
-		Macrotab[i].ct = 0;
-		Delmacro(i);
-		return;
-	}
-	(void) Findstr(nm, NULL, 0);
-	if ((i = Sx) >= 0) {
-		(void) Findstr(nm1, Str[i].str, 1);
-		Delstr(i);
-		return;
-	}
-	if (Findmacro(nm1, 0) < 0)
-		(void) Findmacro(nm1, 1);
-}
-
-
-/*
- * Remove register - "^[.']rr"
- */
-
-static void
-nr_rr(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	int i;				/* temporary index */
-	unsigned char nm[4];		/* name buffer */
-
-	if (Asmname(&line[3], nm) == 0) {
-		Error(WARN, LINE, " no name", NULL);
-		return;
-	}
-	if ((i = Findnum(nm, 0, 0)) < 0) {
-		Error(WARN, LINE, " no register", NULL);
-		return;
-	}
-	Delnum(i);
-}
-
-
-/*
- * Resume space - "^[.']rs"
- */
-
-static void
-nr_rs(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Pass3(NOBREAK, (unsigned char *)"yesspace", NULL, 0);
-}
-
-
-/*
- * Message - "^[.']tm"
- */
-
-static void
-nr_tm(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	Pass3(MESSAGE, Inname, (line[3] == ' ') ? &line[4] : &line[3], NR);
-}
-
-
-/*
- * Translate - "^[.']tr abcd..."
- */
-
-static void
-nr_tr(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	unsigned char buf[MAXLINE];	/* temporary buffer */
-	int i, j;			/* temporary indexes */
-	unsigned char nm[4], nm1[4];	/* name buffers */
-	unsigned char *s1, *s2;		/* temporary string pointers */
-	int trin, trout;		/* types: 0 = char; 1 = named char */
-	unsigned char xbuf[MAXLINE];	/* temporary buffer */
-
-	if (line[3] != ' ') {
-		Error(WARN, LINE, " unknown translation", NULL);
-		return;
-	}
-	for (s1 = &line[4]; *s1;) {
-	    nm[1] = nm[2] = '\0';
-	    s2 = s1 + 1;
-	/*
-	 * Assemble the input value.
-	 */
-	    if (*s1 == '\\' && (*s2 == '*' || *s2 == '(')) {
-		if (*s2 == '(') {
-	    /*
-	     * Input is named character -- "\(xx".
-	     */
-		    trin = 1;
-		    s1 = s2 + 1;
-		    if ((nm[0] = *s1) != '\0') {
-			s1++;
-			if ((nm[1] = *s1) != '\0')
-			    s1++;
-		    }
-		} else {
-	    /*
-	     * Input is interpolated string -- "\*x" or "\*(xx".
-	     */
-		    s1 = Asmcode(&s2, nm);
-		    if (*s1)
-			s1++;
-		    s2 = Findstr(nm, NULL, 0);
-		    if (*s2 != '\0') {
-			if ((strlen((char *)s2) + strlen((char *)s1) + 1)
-			>= MAXLINE)
-			    Error(WARN, LINE, " string too long: ", (char *)nm);
-			else {
-			    (void) sprintf((char *)buf, "%s%s",
-				(char *)s2, (char *)s1);
-			    (void) strcpy((char *)xbuf, (char *)buf);
-			    s1 = xbuf;
-			}
-		    }
-		    continue;
-		}
-	    } else {
-
-	    /*
-	     * Input is a simple character.
-	     */
-		trin = 0;
-		if ((nm[0] = *s1) != '\0')
-		    s1++;
-	    }
-	/*
-	 * Assemble the output value.
-	 */
-
-assemble_output:
-	    nm1[1] = nm1[2] = '\0';
-	    if (*s1 == '\0') {
-
-	    /*
-	     * Supply a space if there is no output character.
-	     */
-		trout = 0;
-		nm1[0] = ' ';
-	    } else {
-		s2 = s1 + 1;
-		if (*s1 == '\\' && (*s2 == '(' || *s2 == '*')) {
-		    if (*s2 == '(') {
-		/*
-		 * The output is a named character -- "\(xx".
-		 */
-			trout = 1;
-			s1 = s2 + 1;
-			if ((nm1[0] = *s1) != '\0') {
-			    s1++;
-			    if ((nm1[1] = *s1) != '\0')
-				s1++;
-			}
-		    } else {
-		/*
-		 * The output is an interpolated string -- * "\*x" or "\*(xx".
-		 */
-			s1 = Asmcode(&s2, nm1);
-			if (*s1)
-			    s1++;
-			s2 = Findstr(nm1, NULL, 0);
-			if (*s2 != '\0') {
-		    /*
-		     * Interpolate a string value.
-		     */
-			    if ((strlen((char *)s2) + strlen((char *)s1) + 1)
-			    >= MAXLINE)
-				Error(WARN, LINE, " string too long: ",
-				    (char *)nm);
-			    else {
-				(void) sprintf((char *)buf, "%s%s", (char *)s2,
-				    (char *)s1);
-				(void) strcpy((char *)xbuf, (char *)buf);
-			        s1 = xbuf;
-			    }
-			}
-			goto assemble_output;
-		    }
-		} else {
-		    trout = 0;
-		    if ((nm1[0] = *s1) != '0')
-			s1++;
-		    else
-			nm1[0] = ' ';
-		}
-	    }
-	/*
-	 * Do the translation.
-	 */
-	    switch (trin) {
-
-	    case 0:			/* simple char */
-		switch (trout) {
-
-		case 0:			/* to simple char */
-		    Trtbl[(int)nm[0]] = nm1[0];
-		    break;
-		case 1:			/* to named char */
-		    if ((i = Findchar(nm1, 0, NULL, 0)) < 0
-		    ||  strlen((char *)Schar[i].str) != 1)
-			Error(WARN, LINE, " bad named character: ",
-			    (char *)nm1);
-		    else
-			Trtbl[(int)nm[0]] = *(Schar[i].str);
-		    break;
-		}
-		break;
-	    case 1:			/* named char */
-		if ((i = Findchar(nm, 0, NULL, 0)) < 0)
-		    Error(WARN, LINE, " unknown named character: ", (char *)nm);
-		else {
-		    switch (trout) {
-
-		    case 0:		/* to simple char */
-			Free(&Schar[i].str);
-			Schar[i].str = Newstr(nm1);
-			Schar[i].len = 1;
-			break;
-		    case 1:		/* to named char */
-			if ((j = Findchar(nm1, 0, NULL, 0)) < 0)
-			    Error(WARN, LINE, " unknown named character: ",
-				(char *)nm1);
-			else
-			    (void) Findchar(nm, Schar[j].len, Schar[j].str, 1);
-			break;
-		    }
-		}
-		break;
-	    }
-	}
-}
-
-
-/*
- * Initialization - "^[.']\^b (fh|HF|NH) [01]"
- *
- * fh = first page header status
- * HF = header/footer status
- * NH = initialize number headers
- */
-
-static void
-nr_Ub(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	int i;				/* temporary index */
-	unsigned char *s1, *s2;		/* temporary string pointers */
-
-	if ((s1 = Field(2, line, 0)) == NULL)
-		return;
-	if ((s2 = Field(3, line, 0)) == NULL)
-		i = 0;
-	else
-		i = atoi((char *)s2);
-	if (s1[0] == 'f' && s1[1] == 'h')
-		Pass3(NOBREAK, (unsigned char *)"fph", NULL, i);
-	else if (s1[0] == 'H' && s1[1] == 'F')
-		Hdft = i;
-	else if (s1[0] == 'N' && s1[1] == 'H') {
-		for (i = 0; i < MAXNHNR; i++)
-			Nhnr[i] = 0;
-	} else
-		Error(WARN, LINE, " unknown initialization", NULL);
-}
-
-
-/*
- * Character definitions - "^[.']\^c"
- */
-
-static void
-nr_Uc(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	unsigned char buf[MAXLINE];	/* temporary buffer */
-	int i;				/* temporary index */
-	unsigned char *s1, *s2, *s3,	/* temporary string pointers */
-		      *s4, *s5;
-
-	s2 = Field(2, line, 0);
-	i = atoi((char *)Field(3, line, 0));
-	s4 = Field(4, line, 0);
-	if (i < 0 || i > MAXLINE/2 || *s2 == '\0') {
-		Error(WARN, LINE, " bad character definition", NULL);
-		return;
-	}
-	if (s4 == NULL)
-		s4 = (unsigned char *)"";
-	else if (*s4 == '"')
-		s4++;
-	s1 = buf;
-	while ((s5 = (unsigned char *)strchr((char *)s4, '\\')) != NULL) {
-		while (s5 > s4)
-			*s1++ = *s4++;
-		s4 = ++s5;
-		if (*s5 == '\\')
-			*s1++ = '\\';
-		else if (*s5 == 'b')
-			*s1++ = '\b';
-		if (*s4)
-			s4++;
-	}
-	while (*s1++ = *s4++)
-		;
-	if (*s2 == 'h' && *(s2+1) == 'y')
-		(void) Findhy(buf, i, 1);
-	else
-		(void) Findchar(s2, i, buf, 1);
-}
-
-
-/*
- * Font is OK - "[.']\^f <font_name_character>"
- */
-
-static void
-nr_Uf(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	int i;				/* temporary index */
-
-	if (line[3] != '\0' && line[4] != '\0') {
-		for (i = 0; Fcode[i].nm; i++) {
-			if (line[4] == Fcode[i].nm) {
-				Fcode[i].status = '1';
-				return;
-			}
-		}
-	}
-	Error(WARN, LINE, " unknown font", NULL);
-}
-
-
-/*
- * Resolutions - "[.']\^r cpi horizontal vertical"
- */
-
-static void
-nr_Ur(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	unsigned char buf[MAXLINE];	/* temporary buffer */
-	int i, j;			/* temporary indexes */
-	double tval;			/* temporary value */
-
-	if ((i = atoi((char *)Field(3, line, 0))) <= 0
-	||  (j = atoi((char *)Field(4, line, 0))) <= 0) {
-		Error(WARN, LINE, " bad cpi resolutions", NULL);
-		return;
-	}
-	tval = (double) (240.0 / (double) i);
-	if (Findscale((int)'m', tval, 1) < 0)
-		Error(FATAL, LINE, " missing Scal['m']", NULL);
-	Scalen = tval;
-	if (Scalen <= 0.0) {
-		(void) sprintf((char *)buf, " bad Scale['n'] (%f)", Scalen);
-		Error(FATAL, LINE, (char *)buf, NULL);
-	}
-	if (Findscale((int)'n', tval, 1) < 0)
-		Error(FATAL, LINE, " missing Scale['n']", NULL);
-	Scalev = (double) (240.0 / (double) j);
-	if (Scalev <= 0.0) {
-		(void) sprintf((char *)buf, " bad Scale['v'] (%f)", Scalen);
-		Error(FATAL, LINE, (char *)buf, NULL);
-	}
-	if (Findscale((int)'v', Scalev, 1) < 0)
-		Error(FATAL, LINE, " missing Scale['v']", NULL);
-}
-
-
-/*
- * Set line number and file name - "^[.']\^# <number> <file>"
- *
- * Lock line number and file name - "^[.']\^= <number> <file>"
- */
-
-static void
-nr_UL(line, brk)
-	unsigned char *line;
-	int brk;
-{
-	unsigned char *s1;		/* temporary string pointer */
-
-	if ((s1 = Field(2, line, 0)) != NULL)
-		P2il = atoi((char *)s1) - 1;
-	else
-		P2il = 0;
-	Lockil = (line[2] == '#') ? 0 : 1;
-	Free(&P2name);
-	if (Field(3, line, 1) != NULL) {
-		P2name = F;
-		F = NULL;
-	} else
-		P2name = NULL;
-}
Index: trunk/minix/commands/cawf/output.c
===================================================================
--- trunk/minix/commands/cawf/output.c	(revision 9)
+++ 	(revision )
@@ -1,96 +1,0 @@
-/*
- *	output-c - output support functions for cawf(1)
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-
-
-/*
- * LenprtHF(s, p, t) - get length of print header or footer with page number
- *		       interpolation
- */
-
-LenprtHF(s, p, t)
-	unsigned char *s;		/* header/footer string */
-	int p;				/* page number */
-	int t;				/* type: 0 = get interpolated length
-					 *	 1 = print */
-{
-	unsigned char buf[10];		/* buffer for page number */
-	int len;			/* line length */
-	unsigned char *s1;		/* temporary string pointer */
-	
-	if (s == NULL)
-		return(0);
-	for (len = 0; *s && *s != '%'; s++) {
-		len++;
-		if (t)
-			Charput((int)*s);
-	}
-	if (*s) {
-		(void) sprintf((char *)buf, "%d", p);
-		for (s1 = buf; *s1; s1++) {
-			len++;
-			if (t)
-				Charput((int)*s1);
-		}
-		for (s++; *s; s++) {
-			len++;
-			if (t)
-				Charput((int)*s);
-		}
-	}
-	return(len);
-}
-
-
-/*
- * Charput(s) - put a character to output, subject to diversion
- */
-
-void
-Charput(c)
-	int c;			/* character to put */
-{
-	if (Divert == 0)
-		putchar((unsigned char)c);
-}
-
-
-/*
- * Stringput(s) - put a string to output, subject to diversion
- */
-
-void
-Stringput(s)
-	unsigned char *s;	/* string to put */
-{
-	if (Divert == 0)
-		fputs((char *)s, stdout);
-}
Index: trunk/minix/commands/cawf/pass2.c
===================================================================
--- trunk/minix/commands/cawf/pass2.c	(revision 9)
+++ 	(revision )
@@ -1,842 +1,0 @@
-/*
- *	pass2.c - cawf(1) pass 2 function
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-#include <ctype.h>
-
-/*
- * Pass2(line) - process the nroff requests in a line and break
- *		 text into words for pass 3
- */
-
-void
-Pass2(line)
-	unsigned char *line;
-{
-	int brk;			/* request break status */
-	unsigned char buf[MAXLINE];	/* working buffer */
-	unsigned char c;		/* character buffer */
-	double d;			/* temporary double */
-	double exscale;			/* expression scaling factor */
-	double expr[MAXEXP];            /* expressions */
-	unsigned char exsign[MAXEXP];	/* expression signs */
-	int i, j;			/* temporary indexes */
-	int inword;			/* word processing status */
-	int nexpr;			/* number of expressions */
-	unsigned char nm[4], nm1[4];	/* names */
-	int nsp;			/* number of spaces */
-	unsigned char op;		/* expression term operator */
-	unsigned char opstack[MAXSP];	/* expression operation stack */
-	unsigned char period;		/* end of word status */
-	unsigned char *s1, *s2, *s3;	/* temporary string pointers */
-	double sexpr[MAXEXP];           /* signed expressions */
-	int sp;				/* expression stack pointer */
-	unsigned char ssign;		/* expression's starting sign */
-	int tabpos;			/* tab position */
-	double tscale;			/* term scaling factor */
-	double tval;			/* term value */
-	double val;			/* term value */
-	double valstack[MAXSP];		/* expression value stack */
-	unsigned char xbuf[MAXLINE];	/* expansion buffer */
-
-	if (line == NULL) {
-    /*
-     * End of macro expansion.
-     */
-		Pass3(DOBREAK, (unsigned char *)"need", NULL, 999);
-		return;
-	}
-    /*
-     * Adjust line number.
-     */
-	if (Lockil == 0)
-		P2il++;
-    /*
-     * Empty line - "^[ \t]*$" or "^\\\"".
-     */
-	if (regexec(Pat[6].pat, line)
-	||  strncmp((char *)line, "\\\"", 2) == 0) {
-		Pass3(DOBREAK, (unsigned char *)"space", NULL, 0);
-		return;
-	}
-    /*
-     * Line begins with white space.
-     */
-	if (*line == ' ' || *line == '\t') {
-		Pass3(DOBREAK, (unsigned char *)"flush", NULL, 0);
-		Pass3(0, (unsigned char *)"", NULL, 0);
-	}
-	if (*line != '.' && *line != '\'') {
-    /*
-     * Line contains text (not an nroff request).
-     */
-		if (Font[0] == 'R' && Backc == 0 && Aftnxt == NULL
-		&&  regexec(Pat[7].pat, line) == 0) {
-		    /*
-		     * The font is Roman, there is no "\\c" or "after next"
-		     * trap pending and and the line has no '\\', '\t', '-',
-		     * or "  "  (regular expression "\\|\t|-|  ").
-		     *
-		     * Output each word of the line as "<length> <word>".
-		     */
-			for (s1 = line;;) {
-				while (*s1 && *s1 == ' ')
-					s1++;
-				if (*s1 == '\0')
-					break;
-				for (s2 = s1, s3 = buf; *s2 && *s2 != ' ';)
-				    *s3++ = Trtbl[(int)*s2++];
-				*s3 = '\0';
-				Pass3((s2 - s1), buf, NULL, 0);
-				s1 = *s2 ? ++s2 : s2;
-			}
-		    /*
-		     * Line terminates with punctuation and optional
-		     * bracketing (regular expression "[.!?:][\])'\"*]*$").
-		     */
-			if (regexec(Pat[8].pat, line))
-				Pass3(NOBREAK, (unsigned char *)"gap", NULL, 2);
-			if (Centering > 0) {
-				Pass3(DOBREAK,(unsigned char *)"center", NULL,
-					0);
-				Centering--;
-			} else if (Fill == 0)
-				Pass3(DOBREAK, (unsigned char *)"flush", NULL,
-					0);
-			return;
-		}
-	    /*
-	     * Line must be scanned a character at a time.
-	     */
-		inword = nsp = tabpos = 0;
-		period = '\0';
-		for (s1 = line;; s1++) {
-		    /*
-		     * Space or TAB causes state transition.
-		     */
-			if (*s1 == '\0' || *s1 == ' ' || *s1 == '\t') {
-				if (inword) {
-					if (!Backc) {
-						Endword();
-						Pass3(Wordl, Word, NULL, 0);
-						if (Uhyph) {
-						  Pass3(NOBREAK,
-						    (unsigned char *)"nohyphen",
-						    NULL, 0);
-						}
-					}
-					inword = 0;
-					nsp = 0;
-				}
-				if (*s1 == '\0')
-					break;
-			} else {
-				if (inword == 0) {
-					if (Backc == 0) {
-						Wordl = Wordx = 0;
-						Uhyph = 0;
-					}
-					Backc = 0;
-					inword = 1;
-					if (nsp > 1) {
-						Pass3(NOBREAK,
-						    (unsigned char *)"gap",
-						    NULL, nsp);
-					}
-				}
-			}
-		    /*
-		     * Process a character.
-		     */
-			switch (*s1) {
-		    /*
-		     * Space
-		     */
-	     		case ' ':
-				nsp++;
-				period = '\0';
-				break;
-		    /*
-		     * TAB
-		     */
-	     		case '\t':
-				tabpos++;
-				if (tabpos <= Ntabs) {
-					Pass3(NOBREAK,
-					    (unsigned char *)"tabto", NULL,
-					    Tabs[tabpos-1]);
-				}
-				nsp = 0;
-				period = '\0';
-				break;
-		    /*
-		     * Hyphen if word is being assembled
-		     */
-			case '-':
-				if (Wordl <= 0)
-				    goto ordinary_char;
-				if ((i = Findhy(NULL, 0, 0)) < 0) {
-				    Error(WARN, LINE, " no hyphen for font ",
-					(char *)Font);
-				    return;
-				}
-				Endword();
-				Pass3(Wordl, Word, NULL, Hychar[i].len);
-				Pass3(NOBREAK, (unsigned char *)"userhyphen",
-				    Hychar[i].str, Hychar[i].len);
-				Wordl = Wordx = 0;
-				period = '\0';
-				Uhyph = 1;
-				break;
-		    /*
-		     * Backslash
-		     */
-			case '\\':
-				s1++;
-				switch(*s1) {
-			    /*
-			     * Comment - "\\\""
-			     */
-				case '"':
-					while (*(s1+1))
-						s1++;
-					break;
-			    /*
-			     * Change font - "\\fN"
-			     */
-				case 'f':
-					s1 = Asmcode(&s1, nm);
-					if (nm[0] == 'P') {
-					    Font[0] = Prevfont;
-					    break;
-					}
-					for (i = 0; Fcode[i].nm; i++) {
-					    if (Fcode[i].nm == nm[0])
-						break;
-					}
-					if (Fcode[i].nm == '\0'
-					||  nm[1] != '\0') {
-					    Error(WARN, LINE, " unknown font ",
-					    	(char *)nm);
-					    break;
-					}
-					if (Fcode[i].status != '1') {
-					    Error(WARN, LINE,
-						" font undefined ", (char *)nm);
-					    break;
-					} else {
-					    Prevfont = Font[0];
-					    Font[0] = nm[0];
-					}
-					break;
-			    /*
-			     * Positive horizontal motion - "\\h\\n(NN" or
-			     * "\\h\\nN"
-			     */
-				case 'h':
-					if (s1[1] != '\\' || s1[2] != 'n') {
-					    Error(WARN, LINE,
-						" no \\n after \\h", NULL);
-					    break;
-					}
-					s1 +=2;
-					s1 = Asmcode(&s1, nm);
-					if ((i = Findnum(nm, 0, 0)) < 0)
-						goto unknown_num;
-					if ((j = Numb[i].val) < 0) {
-					    Error(WARN, LINE, " \\h < 0 ",
-					    NULL);
-					    break;
-					}
-					if (j == 0)
-						break;
-					if ((strlen((char *)s1+1) + j + 1)
-					>=  MAXLINE)
-						goto line_too_long;
-					for (s2 = &xbuf[1]; j; j--)
-						*s2++ = ' ';
-					(void) strcpy((char *)s2, (char *)s1+1);
-					s1 = xbuf;
-					break;
-			    /*
-			     * Save current position in register if "\\k<reg>"
-			     */
-			        case 'k':
-					s1 = Asmcode(&s1, nm);
-					if ((i = Findnum(nm, 0, 0)) < 0)
-					    i = Findnum(nm, 0, 1);
-					Numb[i].val =
-						(int)((double)Outll * Scalen);
-					break;
-			    /*
-			     * Interpolate number - "\\n(NN" or "\\nN"
-			     */
-				case 'n':
-					s1 = Asmcode(&s1, nm);
-					if ((i = Findnum(nm, 0, 0)) < 0) {
-unknown_num:
-					    Error(WARN, LINE,
-					        " unknown number register ",
-						(char *)nm);
-					    break;
-					}
-					(void) sprintf((char *)buf, "%d",
-					    Numb[i].val);
-					if ((strlen((char *)buf)
-					   + strlen((char *)s1+1) + 1)
-					>=  MAXLINE) {
-line_too_long:
-					    Error(WARN, LINE, " line too long",
-					        NULL);
-					    break;
-					}
-					(void) sprintf((char *)buf, "%d%s",
-					    Numb[i].val, (char *)s1+1);
-					(void) strcpy((char *)&xbuf[1],
-						(char *)buf);
-				        s1 = xbuf;
-					break;
-			    /*
-			     * Change size - "\\s[+-][0-9]" - NOP
-			     */
-				case 's':
-					s1++;
-					if (*s1 == '+' || *s1 == '-')
-						s1++;
-					while (*s1 && isdigit(*s1))
-						s1++;
-					s1--;
-					break;
-			    /*
-			     * Continue - "\\c"
-			     */
-				case 'c':
-					Backc = 1;
-					break;
-			    /*
-			     * Interpolate string - "\\*(NN" or "\\*N"
-			     */
-				case '*':
-					s1 = Asmcode(&s1, nm);
-					s2 = Findstr(nm, NULL, 0);
-					if (*s2 != '\0') {
-					    if ((strlen((char *)s2)
-					       + strlen((char *)s1+1) + 1)
-					    >=  MAXLINE)
-						goto line_too_long;
-					    (void) sprintf((char *)buf, "%s%s",
-						(char *)s2, (char *)s1+1);
-					    (void) strcpy((char *)&xbuf[1],
-						(char *)buf);
-					    s1 = xbuf;
-					}
-					break;
-			    /*
-			     * Discretionary hyphen - "\\%"
-			     */
-				case '%':
-					if (Wordl <= 0)
-					    break;
-					if ((i = Findhy(NULL, 0, 0)) < 0) {
-					    Error(WARN, LINE,
-					        " no hyphen for font ",
-						(char *)Font);
-					    break;
-					}
-					Endword();
-					Pass3(Wordl, Word, NULL, Hychar[i].len);
-					Pass3(NOBREAK,
-					    (unsigned char *) "hyphen",
-					    Hychar[i].str, Hychar[i].len);
-					Wordl = Wordx = 0;
-					Uhyph = 1;
-					break;
-			    /*
-			     * None of the above - may be special character
-			     * name.
-			     */
-				default:
-					s2 = s1--;
-					s1 = Asmcode(&s1, nm);
-					if ((i = Findchar(nm, 0, NULL, 0)) < 0){
-					    s1 = s2;
-					    goto ordinary_char;
-					}
-					if (strcmp((char *)nm, "em") == 0
-					&& Wordx > 0) {
-				    /*
-				     * "\\(em" is a special case when a word
-				     * has been assembled, because of
-				     * hyphenation.
-				     */
-					    Endword();
-					    Pass3(Wordl, Word, NULL,
-					        Schar[i].len);
-					    Pass3(NOBREAK,
-						(unsigned char *)"userhyphen",
-					        Schar[i].str, Schar[i].len);
-				            Wordl = Wordx = 0;
-					    period = '\0';
-					    Uhyph = 1;
-			 		}
-				    /*
-				     * Interpolate a special character
-				     */
-					if (Str2word(Schar[i].str,
-					    strlen((char *)Schar[i].str)) != 0)
-						return;
-				        Wordl += Schar[i].len;
-					period = '\0';
-				}
-				break;
-		    /*
-		     * Ordinary character
-		     */
-			default:
-ordinary_char:
-				if (Str2word(s1, 1) != 0)
-					return;
-				Wordl++;
-				if (*s1 == '.' || *s1 == '!'
-				||  *s1 == '?' || *s1 == ':')
-				    period = '.';
-				else if (period == '.') {
-				    nm[0] = *s1;
-				    nm[1] = '\0';
-				    if (regexec(Pat[13].pat, nm) == 0)
-					 period = '\0';
-				}
-			}
-		}
-	    /*
-	     * End of line processing
-	     */
-     		if (!Backc) {
-			if (period == '.')
-				Pass3(NOBREAK, (unsigned char *)"gap", NULL, 2);
-			if (Centering > 0) {
-				Pass3(DOBREAK, (unsigned char *)"center", NULL,
-				0);
-				Centering--;
-			} else if (!Fill)
-				Pass3(DOBREAK, (unsigned char *)"flush", NULL,
-				0);
-		}
-		if (Aftnxt == NULL)
-			return;
-		/* else fall through to process an "after next trap */
-	}
-    /*
-     * Special -man macro handling.
-     */
-	if (Marg == MANMACROS) {
-	    /*
-	     * A text line - "^[^.]" - is only processed when there is an
-	     * "after next" directive.
-	     */
-		if (*line != '.' && *line != '\'') {
-			if (Aftnxt != NULL) {
-				if (regexec(Pat[9].pat, Aftnxt))  /* ",fP" */
-					Font[0] = Prevfont;
-				if (regexec(Pat[16].pat, Aftnxt))  /* ",fR" */
-					Font[0] = 'R';
-				if (regexec(Pat[10].pat, Aftnxt))  /* ",tP" */
-					Pass3(DOBREAK,
-						(unsigned char *)"toindent",
-						NULL, 0);
-				Free(&Aftnxt);
-			}
-			return;
-		}
-	    /*
-	     * Special footer handling - "^.lF"
-	     */
-		if (line[1] == 'l' && line[2] == 'F') {
-			s1 = Findstr((unsigned char *)"by", NULL, 0);
-			s2 = Findstr((unsigned char *)"nb", NULL, 0);
-			if (*s1 == '\0' || *s2 == '\0')
-				(void) sprintf((char *)buf, "%s%s",
-					(char *)s1, (char *)s2);
-			else
-				(void) sprintf((char *)buf, "%s; %s",
-					(char *)s1, (char *)s2);
-			Pass3(NOBREAK, (unsigned char *)"LF", buf, 0);
-			return;
-		}
-	}
-    /*
-     * Special -ms macro handling.
-     */
-	if (Marg == MSMACROS) {
-	    /*
-	     * A text line - "^[^.]" - is only processed when there is an
-	     * "after next" directive.
-	     */
-		if (*line != '.' && *line != '\'') {
-			if (Aftnxt != NULL) {
-				if (regexec(Pat[10].pat, Aftnxt))  /* ",tP" */
-					Pass3(DOBREAK,
-						(unsigned char *)"toindent",
-						NULL, 0);
-				Free(&Aftnxt);
-			}
-			return;
-		}
-	    /*
-	     * Numbered headings - "^[.']nH"
-	     */
-		if (line[1] == 'n' && line[2] == 'H') {
-			s1 = Field(2, line, 0);
-			if (s1 != NULL) {
-				i = atoi((char *)s1) - 1;	
-				if (i < 0) {
-					for (j = 0; j < MAXNHNR; j++) {
-						Nhnr[j] = 0;
-					}
-					i = 0;
-				} else if (i >= MAXNHNR) {
-				    (void) sprintf((char *)buf,
-					" over NH limit (%d)", MAXNHNR);
-				    Error(WARN, LINE, (char *)buf, NULL);
-				}
-			} else
-				i = 0;
-			Nhnr[i]++;
-			for (j = i + 1; j < MAXNHNR; j++) {
-				Nhnr[j] = 0;
-			}
-			s1 = buf;
-			for (j = 0; j <= i; j++) {
-				(void) sprintf((char *)s1, "%d.", Nhnr[j]);
-				s1 = buf + strlen((char *)buf);
-			}
-			(void) Findstr((unsigned char *)"Nh", buf, 1);
-			return;
-		}
-	}
-    /*
-     * Remaining lines should begin with a '.' or '\'' unless an "after next"
-     * trap has failed.
-     */
-	if (*line != '.' && *line != '\'') {
-		if (Aftnxt != NULL)
-			Error(WARN, LINE, " failed .it: ", (char *)Aftnxt);
-		else
-			Error(WARN, LINE, " unrecognized line ", NULL);
-		return;
-	}
-	brk = (*line == '.') ? DOBREAK : NOBREAK;
-    /*
-     * Evaluate expressions for "^[.'](ta|ll|ls|in|ti|po|ne|sp|pl|nr)"
-     * Then process the requests.
-     */
-	if (regexec(Pat[11].pat, &line[1])) {
-	    /*
-	     * Establish default scale factor.
-	     */
-		if ((line[1] == 'n' && line[2] == 'e')
-		||  (line[1] == 's' && line[2] == 'p')
-		||  (line[1] == 'p' && line[2] == 'l'))
-			exscale = Scalev;
-		else if (line[1] == 'n' && line[2] == 'r')
-			exscale = Scaleu;
-		else
-			exscale = Scalen;
-	    /*
-	     * Determine starting argument.
-	     */
-		if (line[1] == 'n' && line[2] == 'r')
-			s1 = Field(2, &line[3], 0);
-		else
-			s1 = Field(1, &line[3], 0);
-	    /*
-	     * Evaluate expressions.
-	     */
-		for (nexpr = 0; s1 != NULL &&*s1 != '\0'; ) {
-			while (*s1 == ' ' || *s1 == '\t')
-				s1++;
-			if (*s1 == '+' || *s1 == '-')
-				ssign = *s1++;
-			else
-				ssign = '\0';
-		    /*
-		     * Process terms.
-		     */
-			val = 0.0;
-			sp = -1;
-			c = '+';
-			s1--;
-			while (c == '+' || c == '*' || c == '%'
-			||  c == ')' || c == '-' || c == '/') {
-			    op = c;
-			    s1++;
-			    tscale = exscale;
-			    tval = 0.0;
-			/*
-			 * Pop stack on right parenthesis.
-			 */
-			    if (op == ')') {
-				tval = val;
-				if (sp >= 0) {
-				    val = valstack[sp];
-				    op = opstack[sp];
-				    sp--;
-				} else {
-				    Error(WARN, LINE,
-					" expression stack underflow", NULL);
-				    return;
-				}
-				tscale = Scaleu;
-			/*
-			 * Push stack on left parenthesis.
-			 */
-			    } else if (*s1 == '(') {
-				sp++;
-				if (sp >= MAXSP) {
-				    Error(WARN, LINE,
-				       " expression stack overflow", NULL);
-				    return;
-				}
-				valstack[sp] = val;
-				opstack[sp] = op;
-				val = 0.0;
-				c = '+';
-				continue;
-			    } else if (*s1 == '\\') {
-			      s1++;
-			      switch(*s1) {
-			/*
-			 * "\\"" begins a comment.
-			 */
-			      case '"':
-				while (*s1)
-					s1++;
-				break;
-			/*
-			 * Crude width calculation for "\\w"
-			 */
-			      case 'w':
-				s2 = ++s1;
-				if (*s1) {
-				    s1++;
-				    while (*s1 && *s1 != *s2)
-					s1++;
-				    tval = (double) (s1 - s2 - 1) * Scalen;
-				    if (*s1)
-					s1++;
-				}
-				break;
-			/*
-			 * Interpolate number register if "\\n".
-			 */
-			      case 'n':
-				s1 = Asmcode(&s1, nm);
-				if ((i = Findnum(nm, 0, 0)) >= 0)
-				    tval = Numb[i].val;
-			        s1++;
-			     }
-			/*
-			 * Assemble numeric value.
-			 */
-			    } else if (*s1 == '.' || isdigit(*s1)) {
-				for (i = 0; isdigit(*s1) || *s1 == '.'; s1++) {
-				    if (*s1 == '.') {
-					i = 10;
-					continue;
-				    }
-				    d = (double) (*s1 - '0');
-				    if (i) {
-					tval = tval + (d / (double) i);
-					i = i * 10;
-				    } else
-					tval = (tval * 10.0) + d;
-				}
-			    } else {
-			/*
-			 * It's not an expression.  Ignore extra scale.
-			 */
-				if ((i = Findscale((int)*s1, 0.0, 0)) < 0) {
-				    (void) sprintf((char *)buf,
-					" \"%s\" isn't an expression",
-					(char *)s1);
-				    Error(WARN, LINE, (char *)buf, NULL);
-				}
-				s1++;
-			    }
-			/*
-			 * Add term to expression value.
-			 */
-			    if ((i = Findscale((int)*s1, 0.0, 0)) >= 0) {
-				tval *= Scale[i].val;
-				s1++;
-			    } else
-				tval *= tscale;
-			    switch (op) {
-			    case '+':
-				val += tval;
-				break;
-			    case '-':
-				val -= tval;
-				break;
-			    case '*':
-				val *= tval;
-				break;
-			    case '/':
-			    case '%':
-				i = (int) val;
-				j = (int) tval;
-				if (j == 0) {
-				    Error(WARN, LINE,
-					(*s1 == '/') ? "div" : "mod",
-				        " by 0");
-				    return;
-				}
-				if (op == '/')
-					val = (double) (i / j);
-				else
-					val = (double) (i % j);
-				break;
-			    }
-			    c = *s1;
-			}
-		    /*
-		     * Save expression value and sign.
-		     */
-			if (nexpr >= MAXEXP) {
-				(void) sprintf((char *)buf,
-				    " at expression limit of %d", MAXEXP);
-				Error(WARN, LINE, (char *)buf, NULL);
-				return;
-			}
-			exsign[nexpr] = ssign;
-			expr[nexpr] = val;
-			if (ssign == '-')
-				sexpr[nexpr] = -1.0 * val;
-			else
-				sexpr[nexpr] = val;
-			nexpr++;
-			while (*s1 == ' ' || *s1 == '\t')
-				s1++;
-		}
-	    /*
-	     * Set parameters "(ll|ls|in|ti|po|pl)"
-	     */
-		if (regexec(Pat[12].pat, &line[1])) {
-			nm[0] = line[1];
-			nm[1] = line[2];
-			if ((i = Findparms(nm)) < 0) {
-				Error(WARN, LINE,
-				    " can't find parameter register ",
-				    (char *)nm);
-				return;
-			}
-			if (nexpr == 0 || exscale == 0.0)
-				j = Parms[i].prev;
-			else if (exsign[0] == '\0'
-			     ||  (nm[0] == 't' && nm[1] == 'i'))
-				 j = (int)(sexpr[0] / exscale);
-			else
-				j = Parms[i].val + (int)(sexpr[0] / exscale);
-			Parms[i].prev = Parms[i].val;
-			Parms[i].val = j;
-			nm[0] = (nexpr) ? exsign[0] : '\0';     /* for .ti */
-			nm[1] = '\0';
-			Pass3(brk, (unsigned char *)Parms[i].cmd, nm, j);
-			return;
-		}
-		if (line[1] == 'n') {
-			switch(line[2]) {
-	    /*
-	     * Need - "^[.']ne <expression>"
-	     */
-			case 'e':
-				if (nexpr && Scalev > 0.0)
-					i = (int) ((expr[0]/Scalev) + 0.99);
-				else
-					i = 0;
-				Pass3(DOBREAK, (unsigned char *)"need", NULL,
-					i);
-				return;
-	    /*
-	     * Number - "^[.']nr <name> <expression>"
-	     */
-			case 'r':
-				if ((s1 = Field(2, line, 0)) == NULL) {
-				    Error(WARN, LINE, " bad number register",
-				        NULL);
-				    return;
-				}
-				if ((i = Findnum(s1, 0, 0)) < 0)
-				    i = Findnum(s1, 0, 1);
-				if (nexpr < 1) {
-				    Numb[i].val = 0;
-				    return;
-				}
-				if (exsign[0] == '\0')
-				    Numb[i].val = (int) expr[0];
-				else
-				    Numb[i].val += (int) sexpr[0];
-				return;
-			}
-		}
-	    /*
-	     * Space - "^[.']sp <expression>"
-	     */
-		if (line[1] == 's' && line[2] == 'p') {
-			if (nexpr == 0)
-				i = 1;
-			else
-				i = (int)((expr[0] / Scalev) + 0.99);
-			while (i--)
-				Pass3(brk, (unsigned char *)"space", NULL, 0);
-			return;
-		}
-	    /*
-	     * Tab positions - "^[.']ta <pos1> <pos2> . . ."
-	     */
-     		if (line[1] == 't' && line[2] == 'a') {
-			tval = 0.0;
-			for (j = 0; j < nexpr; j++) {
-				if (exsign[j] == '\0')
-					tval = expr[j];
-				else
-					tval += sexpr[j];
-				Tabs[j] = (int) (tval / Scalen);
-			}
-			Ntabs = nexpr;
-			return;
-		}
-	}
-    /*
-     * Process all other nroff requests via Nreq().
-     */
-	(void) Nreq(line, brk);
-	return;
-}
Index: trunk/minix/commands/cawf/pass3.c
===================================================================
--- trunk/minix/commands/cawf/pass3.c	(revision 9)
+++ 	(revision )
@@ -1,614 +1,0 @@
-/*
- *	pass3.c - cawf(1) pass 3 function
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-
-void
-Pass3(len, word, sarg, narg)
-	int len;			/* length (negative is special) */
-	unsigned char *word;		/* word */
-	unsigned char *sarg;		/* string argument */
-	int narg;			/* numeric argument */
-{
-	int addto;			/* spaces to add to all words */
-	int i, j, k;			/* temporary index */
-	unsigned char msg[MAXLINE];	/* message buffer */
-	int n;				/* temporary number */
-	unsigned char *s1;		/* temporary string pointer */
-	int sp = 0;			/* no-break spacing switch */
-	int sp_Outll;			/* sp-saved Outll */
-	char sp_Outln;			/* sp-saved Outln[0] */
-	int sp_Outlx;			/* sp-saved Outlx */
-	int sp_Padx;			/* sp-saved Padx */
-	int sp_Tind;			/* sp-saved Tind */
-	int wl;				/* real word length */
-	int xsp;			/* extra spaces to add */
-	int vsp;			/* vertical spacing status */
-
-	vsp = 0;
-	if (word != NULL)
-		wl = strlen((char *)word);
-    /*
-     * If not a special command, process a word.
-     */
-	if (len >= 0 && Outll < 0) {
-	/*
-	 * Enter first word.
-	 */
-		(void) strcpy((char *)Outln, (char *)word);
-		Outll = len;
-		Outlx = wl;
-		Padx = 0;
-	} else if (len >= 0
-	       && (Outll+Contlen+len+narg) <= (LL-Pgoff-Ind-Tind)) {
-	/*
-	 * The word fits, so enter it.
-	 */
-		if ((Contlen + len) > 0) {
-line_too_big:
-			if ((Outlx + Contlen + wl) >= MAXOLL) {
-				Error3(len, (char *)word, (char *)sarg, narg,
-					"output line too big");
-				return;
-			} else {
-				if (Contlen > 0 && Cont != NULL) {
-					if (Contlen == 1 && *Cont == ' ') {
-						Padchar[Padx++] = Outlx;
-						Outln[Outlx++] = ' ';
-					} else {
-					    (void) strcpy((char *)&Outln[Outlx],
-						(char *)Cont);
-					    Outlx += Contlen;
-					}
-				}
-				if (len > 0) {
-					(void) strcpy((char *)&Outln[Outlx],
-						(char *)word);
-					Outlx += wl;
-				}
-			}
-		}
-		Outll += Contlen + len;
-	} else if (len == NOBREAK || len == MESSAGE) {
-		/*
-		 * Do nothing (equivalent to break)
-		 */
-	} else if (len == DOBREAK && strcmp((char *)word, "need") == 0
-	       &&  (Nxtln + narg) < (Pglen + 1 - Botmarg)) {
-		/*
-		 * Do nothing, because there is room on the page.
-		 */
-	} else if (len == DOBREAK && strcmp((char *)word, "toindent") == 0
-	       &&  (Ind + Tind + Outll) < Ind) {
-	/*
-	 * Move to indent position with line - there is room.
-	 */
-		n = Ind - (Ind + Tind +Outll);
-		Outll += n;
-		if ((Outlx + n) >= MAXOLL)
-			goto line_too_big;
-		for (i = n; i; i--)
-			Outln[Outlx++] = ' ';
-		Padx = 0;
-		Free(&Cont);
-		Contlen = 0;
-	} else if (Outll >= 0
-	       || (len == DOBREAK && strcmp((char *)word, "need") == 0)) {
-	/*
-	 * A non-empty line or a "need" forces output.
-	 */
-		vsp = 0;
-
-print_line:
-		if (Nxtln == 1) {
-	    /*
-	     * We're at the top of the page, so issue the header.
-	     */
-			if (Thispg > 1)
-				Charput((int)'\f');
-			for (i = (Topmarg - 1)/2; i > 0; i--) {
-				Charput((int)'\n');
-				Nxtln++;
-			}
-		    /*
-		     * Print the page header, as required.
-		     */
-			if (Fph || Thispg > 1) {
-				i = LenprtHF(Hdc, Thispg, 0)
-				  + LenprtHF(Hdl, Thispg, 0)
-				  + LenprtHF(Hdr, Thispg, 0) + 2;
-				j = (LL - i - Pgoff) / 2 + 1;
-				n = LL - Pgoff - i - j + 2;
-				for (k = 0; k < Pgoff; k++)
-					Charput((int)' ');
-				if (Hdl)
-					LenprtHF(Hdl, Thispg, 1);
-				while (j-- > 0)
-					Charput((int)' ');
-				if (Hdc)
-					LenprtHF(Hdc, Thispg, 1);
-				while (n-- > 0)
-					Charput((int)' ');
-				if (Hdr)
-					LenprtHF(Hdr, Thispg, 1);
-				Charput((int)'\n');
-			} else
-				Charput((int)'\n');
-			Nxtln++;
-			while(Nxtln <= Topmarg) {
-				Charput((int)'\n');
-				Nxtln++;
-			}
-		}
-	    /*
-	     *  Add a trailing hyphen, if mecessary.
-	     */
-     		if (vsp == 0 && Eollen > 0 && Eol != NULL) {
-			i = strlen((char *)Eol);
-			if ((Outlx + i) >= MAXOLL)
-				goto line_too_big;
-			(void) strcpy((char *)&Outln[Outlx], (char *)Eol);
-			Outlx += i;
-			Outll += Eollen;
-		}
-	    /*
-	     * Trim trailing spaces from the output line.
-	     */
-     		while (Outlx > 0) {
-			if (Outln[Outlx - 1] != ' ')
-				break;
-			if (Padx > 0 && (Outlx - 1) == Padchar[Padx - 1])
-				Padx--;
-			Outlx--;
-			Outln[Outlx] = '\0';
-			Outll--;
-		}
-		if (Outlx == 0)
-			Charput((int)'\n');
-		else if (len == DOBREAK && strcmp((char *)word, "center") == 0)
-		    {
-		    /*
-		     * Center the output line.
-		     */
-			i = (LL - Pgoff - Outll) / 2;
-			if (i < 0)
-				i = 0;
-			for (j = (Pgoff + Ind + Tind + i); j; j--)
-				Charput((int)' ');
-			Stringput(Outln);
-			Charput((int)'\n');
-		} else if (Adj == LEFTADJ
-		       || (Adj == BOTHADJ && (len < 0 || Padx == 0))) {
-		    /*
-		     * No right margin adjustment - disabled, inappropriate
-		     * (line ended by break) or impossible.
-		     */
-			for (i = 0; i < (Pgoff + Ind + Tind); i++)
-				Charput((int)' ');
-			Stringput(Outln);
-			Charput((int)'\n');
-		} else if (Adj == BOTHADJ) {
-		    /*
-		     * Adjust right margin.
-		     */
-			for (i = 0; i < (Pgoff + Ind + Tind); i++)
-				Charput((int)' ');
-			i = LL - (Pgoff + Ind + Tind);
-			j = i - Outll;
-			addto = Padx ? (j / Padx) : 0;
-			xsp = j - (Padx * addto);
-			for (i = 0, s1 = Outln; i < Padx; i++) {
-				while (*s1 && (s1 - Outln) <= Padchar[i])
-					Charput((int)*s1++);
-				if (*s1 == '\0')
-					break;
-				j = addto;
-				if (Padfrom == PADLEFT) {
-					if (i < xsp)
-						j++;
-				} else if (i >= (Padx - xsp))
-					j++;
-				while (j-- > 0)
-					Charput((int)' ');
-			}
-			while (*s1)
-				Charput((int)*s1++);
-			Charput((int)'\n');
-			Padfrom = (Padfrom == PADLEFT) ? PADRIGHT : PADLEFT;
-		}
-	    /*
-	     * End of line housekeeping
-	     */
-		Nxtln++;
-		Outll = -1;
-		Outlx = 0;
-		Padx = 0;
-		Tind = 0;
-		Nospmode = 0;
-		if (vsp == 0 && len == DOBREAK
-		&&  strcmp((char *)word, "need") == 0) {
-		    /*
-		     * Break caused by "need" - satisfy it.
-		     */
-			while (Nxtln < (Pglen + 1 - Botmarg)) {
-				Charput((int)'\n');
-				Nxtln++;
-			}
-		}
-		if (Nxtln >= (Pglen + 1 - Botmarg)) {
-	    /*
-	     * Footer required
-	     */
-			for (i = (Botmarg - 1)/2; i > 0; i--) {
-				Charput((int)'\n');
-				Nxtln++;
-			}
-			i = LenprtHF(Ftl, Thispg, 0) + LenprtHF(Ftc, Thispg, 0)
-			  + LenprtHF(Ftr, Thispg, 0) + 2;
-			j = (LL - i - Pgoff) / 2 + 1;
-			n = LL - Pgoff - i - j + 2;
-			for (k = 0; k < Pgoff; k++)
-				Charput((int)' ');
-			if (Ftl)
-				LenprtHF(Ftl, Thispg, 1);
-			while (j-- > 0)
-				Charput((int)' ');
-			if (Ftc)
-				LenprtHF(Ftc, Thispg, 1);
-			while (n-- > 0)
-				Charput((int)' ');
-			if (Ftr)
-				LenprtHF(Ftr, Thispg, 1);
-			Charput((int)'\n');
-			Nxtln++;
-		/*
-		 * The last blank line on the page is suppressed to assist
-		 * printers that can't look ahead to the following FF.
-		 */
-			while (Nxtln < Pglen) {
-				Charput((int)'\n');
-				Nxtln++;
-			}
-			Nxtln = 1;
-			Thispg++;
-			Nospmode = 1;
-			Padfrom = PADRIGHT;
-		}
-	    /*
-	     * Initiate any extra vertical spacing.
-	     */
-		if (++vsp < Vspace)
-			goto print_line;
-	    /*
-	     * Save any input word that might have forced output.
-	     */
-		if (len >= 0) {
-			(void) strcpy((char *)Outln, (char *)word);
-			Outll = len;
-			Outlx = wl;
-			Padx = 0;
-		}
-	}
-    /*
-     * A break causes padding reversal.
-     */
-	if (len == DOBREAK)
-		Padfrom = PADRIGHT;
-	if (len >= 0 || strcmp((char *)word, "nohyphen") == 0) {
-    /*
-     * Reset continuation and hyphenation.
-     */
-		if (Contlen != 1 || Cont[0] != ' ') {
-			Free(&Cont);
-			Cont = Newstr((unsigned char *)" ");
-			Contlen = 1;
-		}
-		if (Eollen > 0) {
-			Free(&Eol);
-			Eollen = 0;
-		}
-		return;
-	}
-    /*
-     * Now post-process any special commands.
-     */
-	if (len == MESSAGE) {
-		Error3(len, (char *)word, (char *)sarg, narg, NULL);
-		return;
-	}
-
-	switch (*word) {
-
-	case 'b':				/* both */
-	    /*
-	     * Adjust on both margins.
-	     */
-		Adj = BOTHADJ;
-		return;
-
-	case 'c':				/* center */
-		return;
-
-	case 'e':				/* errsto */
-	    /*
-	     * "errsto" comes from awf.
-	     */
-		return;
-
-	case 'f':				/* flush and fph */
-		if (word[1] == 'l')
-			return;
-		else if (word[1] == 'p') {
-	    /*
-	     * First page header status
-	     */
-			Fph = narg;
-			return;
-		}
-		break;
-
-	case 'g':				/* gap */
-	    /*
-	     * Increase word gap.  (Space is not paddable.)
-	     */
-		if (Outll >= 0) {
-			if ((Outlx + narg - 1) >= MAXOLL)
-				goto line_too_big;
-			for (i = 0; i < (narg - 1); i++) {
-				Outln[Outlx++] = ' ';
-				Outll++;
-			}
-		}
-		return;
-
-	case 'h':				/* hyphen */
-	    /*
-	     * Set discretionary hyphen.
-	     */
-		Free(&Cont);
-		Contlen = 0;
-		Free(&Eol);
-		Eol = (sarg != NULL) ? Newstr(sarg) : NULL;
-		Eollen = narg;
-		return;
-
-	case 'i':				/* indent */
-	    /*
-	     * Set indentation.
-	     */
-		Ind = narg;
-		return;
-
-	case 'l':				/* left or linelen */
-		if (word[1] == 'e') {
-	    /*
-	     * Adjust on left margin.
-	     */
-			Adj = LEFTADJ;
-			return;
-		} else if (word[1] == 'i') {
-	    /*
-	     * Set line length.
-	     */
-			LL = narg;
-			return;
-		}
-		break;
-
-	case 'n':				/* need or nospace */
-		if (word[1] == 'e')
-			return;			/* need */
-		else if (word[1] == 'o') {
-	    /*
-	     * Set no space mode.
-	     */
-			Nospmode = 1;
-			return;
-		}
-		break;
-
-	case 'p':				/* pagelen or pageoffset */
-		if (strncmp((char *)&word[1], "age", 3) != 0)
-			break;
-		if (word[4] == 'l') {
-	    /*
-	     * Set page length.
-	     */
-			Pglen = narg;
-			return;
-		} else if (word[4] == 'o') {
-	    /*
-	     * Set page offset.
-	     */
-			Pgoff = narg;
-			return;
-		}
-		break;
-
-	case 's':				/* space */
-		if (sp) {
-
-		/*
-		 * Restore values after NOBREAK spacing ("^'sp").
-		 */
-			Outlx = sp_Outlx;
-			Outln[0] = sp_Outln;
-			Padx = sp_Padx;
-			Outll = sp_Outll;
-			Tind = sp_Tind;
-			return;
-		}
-		if (Nospmode == 0) {
-			if (len == NOBREAK) {
-		
-			/*
-			 * Set up for NOBREAK spacing.
-			 */
-				sp_Outlx = Outlx;
-				sp_Outln = Outln[0];
-				sp_Padx = Padx;
-				sp_Outll = Outll;
-				sp_Tind = Tind;
-				vsp = Vspace + 1;
-				sp = 1;
-			}
-		/*
-		 * Generate a blank line.
-		 */
-			Outlx = 0;
-			Outln[0] = '\0';
-			Padx = 0;
-			Outll = LL - 1;
-			if (sp)
-				goto print_line;
-		}
-		return;
-
-	case 't':				/* tabto, tempindent, or
-						 * toindent */
-		if (word[1] == 'a') {
-	    /*
-	     * Move to TAB stop.
-	     */
-			if (Outll < 0)
-				Outll = 0;
-			if ((n = narg - Outll) > 0) {
-				if ((Outlx + n) >= MAXOLL)
-					goto line_too_big;
-				Outll += n;
-				for (i = n; i > 0; i--)
-					Outln[Outlx++] = ' ';
-				Free(&Cont);
-				Contlen = 0;
-				Padx = 0;
-			}
-			return;
-		} else if (word[1] == 'e') {
-	    /*
-	     * Set temporary indentation.
-	     */
-			if (*sarg == '\0' && narg >= 0)
-				Tind = narg - Ind;
-			else
-				Tind = ((Ind + narg) >= 0) ? narg : -Ind;
-			return;
-		} else if (word[1] == 'o')
-			return;				/* toindent */
-		break;
-
-	case 'u':					/* userhyphen */
-	    /*
-	     * Set line length.
-	     */
-		Free(&Cont);
-		Free(&Eol);
-		Contlen = Eollen = narg;
-		Cont = (sarg == NULL) ? NULL : Newstr(sarg);
-		Eol = (sarg == NULL) ? NULL : Newstr(sarg);
-		return;
-
-	case 'v':					/* vspace */
-	    /*
-	     * Set vertical spacing.
-	     */
-		Vspace = (narg == 0) ? 1 : narg;
-		return;
-
-	case 'y':					/* yesspace */
-	    /*
-	     * Set space mode.
-	     */
-		Nospmode = 0;
-		return;
-	}				/* end of switch(*word) */
-    /*
-     * Locate header and footer defintions.
-     */
-	if (regexec(Pat[14].pat, word)) {
-		if (strcmp((char *)word, "LH") == 0) {
-		    /*
-		     * Left header
-		     */
-			Free(&Hdl);
-			if (sarg != NULL)
-				Hdl = Newstr(sarg);
-			return;
-		}
-		if (strcmp((char *)word, "CH") == 0) {
-		    /*
-		     * Center header
-		     */
-			Free(&Hdc);
-			if (sarg != NULL)
-				Hdc = Newstr(sarg);
-			return;
-		}
-		if (strcmp((char *)word, "RH") == 0) {
-		    /*
-		     * Right header
-		     */
-			Free(&Hdr);
-			if (sarg != NULL)
-				Hdr = Newstr(sarg);
-			return;
-		}
-		if (strcmp((char *)word, "LF") == 0) {
-		    /*
-		     * Left footer
-		     */
-			Free(&Ftl);
-			if (sarg != NULL)
-				Ftl = Newstr(sarg);
-			return;
-		}
-		if (strcmp((char *)word, "CF") == 0) {
-		    /*
-		     * Center footer
-		     */
-			Free(&Ftc);
-			if (sarg != NULL)
-				Ftc = Newstr(sarg);
-			return;
-		}
-		if (strcmp((char *)word, "RF") == 0) {
-		    /*
-		     * Right footer
-		     */
-			Free(&Ftr);
-			if (sarg != NULL)
-				Ftr = Newstr(sarg);
-			return;
-		}
-	}
-    /*
-     * Error on unknown arguments
-     */
-	Error3(len, (char *)word, (char *)sarg, narg, "unknown request");
-}
Index: trunk/minix/commands/cawf/proto.h
===================================================================
--- trunk/minix/commands/cawf/proto.h	(revision 9)
+++ 	(revision )
@@ -1,117 +1,0 @@
-/*
- *	proto.h - function prototype definitions for cawf(1)
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "ansi.h"
-
-#ifdef	UNIX
-# ifdef	USG
-#include <string.h>
-# else	/* not USG */
-#include <strings.h>
-# endif	/* USG */
-#else	/* not UNIX */
-#include <string.h>
-#endif	/* UNIX */
-
-/*
- * The following conditional rat's nest intends to:
- *
- * for MS-DOS	#include <stdlib.h> and <malloc.h>.  <stdlib.h> exists in
- *		MS-DOS so the STDLIB symbol should be defined and UNIX
- *		shouldn't be.
- *
- * for Unix	#include <stdlib.h> if the STDLIB symbol is defined.  If
- *		STDLIB isn't defined, define a prototype for getenv().
- *		If the UNIX symbol is defined (and it should be) and if
- *		the MALLOCH symbol is defined, #include <malloc.h>; else
- *		define a prototype for malloc() if UNIX is defined and
- *		MALLOCH isn't.  (The Unix <stdlib.h> usually defines the
- *		malloc() prototype.)
- *
- * for ???	Define a prototype for getenv() and #include <malloc.h>
- *		if neither STDLIB nor UNIX are defined.  (What system is
- *		this?)
- */
-
-#ifdef	STDLIB
-#include <stdlib.h>
-# ifndef	UNIX
-#include <malloc.h>
-# endif		/* UNIX */
-#else	/* not STDLIB */
-_PROTOTYPE(char *getenv,(char *name));
-# ifdef	UNIX
-#  ifdef	MALLOCH
-#include <malloc.h>
-#  else		/* not MALLOCH */
-_PROTOTYPE(char *malloc,(unsigned size));
-#  endif	/* MALLOCH */
-# else	/* not UNIX */
-#include <malloc.h>
-# endif	/* UNIX */
-#endif	/* STDLIB */
-
-_PROTOTYPE(unsigned char *Asmcode,(unsigned char **s, unsigned char *c));
-_PROTOTYPE(int Asmname,(unsigned char *s, unsigned char *c));
-_PROTOTYPE(void Charput,(int c));
-_PROTOTYPE(int Delmacro,(int mx));
-_PROTOTYPE(int Defdev,());
-_PROTOTYPE(void Delstr,(int sx));
-_PROTOTYPE(void Error,(int t, int l, char *s1, char *s2));
-_PROTOTYPE(void Error3,(int len, char *word, char *sarg, int narg, char *msg));
-_PROTOTYPE(void Expand,(unsigned char *line));
-_PROTOTYPE(void Delnum,(int nx));
-_PROTOTYPE(unsigned char *Field,(int n, unsigned char *p, int c));
-_PROTOTYPE(void Endword,());
-_PROTOTYPE(int Findchar,(unsigned char *nm, int l, unsigned char *s, int e));
-_PROTOTYPE(int Findhy,(unsigned char *s, int l, int e));
-_PROTOTYPE(int Findmacro,(unsigned char *p, int e));
-_PROTOTYPE(int Findnum,(unsigned char *n, int v, int e));
-_PROTOTYPE(int Findparms,(unsigned char *n));
-_PROTOTYPE(int Findscale,(int n, double v, int e));
-_PROTOTYPE(unsigned char *Findstr,(unsigned char *nm, unsigned char *s, int e));
-_PROTOTYPE(int getopt,(int argc, char **argv, char *opts));
-_PROTOTYPE(int LenprtHF,(unsigned char *s, int p, int t));
-_PROTOTYPE(int main,(int argc, char *argv[]));
-_PROTOTYPE(void Macro,(unsigned char *inp));
-_PROTOTYPE(void Nreq,(unsigned char *line, int brk));
-_PROTOTYPE(void Free,(unsigned char **p));
-_PROTOTYPE(unsigned char *Newstr,(unsigned char *s));
-_PROTOTYPE(void Pass2,(unsigned char *line));
-_PROTOTYPE(void Pass3,(int len, unsigned char *word, unsigned char *sarg, int narg));
-_PROTOTYPE(void regerror,(char *s));
-_PROTOTYPE(unsigned char *reg,(int paren, int *flagp));
-_PROTOTYPE(unsigned char *regatom,(int *flagp));
-_PROTOTYPE(unsigned char *regbranch,(int *flagp));
-_PROTOTYPE(regexp *regcomp,(char *exp));
-_PROTOTYPE(void regdump,(regexp *r));
-_PROTOTYPE(int regexec,(regexp *prog, unsigned char *string));
-_PROTOTYPE(void Stringput,(unsigned char *s));
-_PROTOTYPE(int Str2word,(unsigned char *s, int len));
Index: trunk/minix/commands/cawf/regerror.c
===================================================================
--- trunk/minix/commands/cawf/regerror.c	(revision 9)
+++ 	(revision )
@@ -1,18 +1,0 @@
-#include <stdio.h>
-#include "regexp.h"
-#include "proto.h"
-
-void
-regerror(s)
-char *s;
-{
-#ifndef DOSPORT
-#ifdef ERRAVAIL
-	error("regexp: %s", s);
-#else
-	fprintf(stderr, "regexp(3): %s", s);
-	exit(1);
-#endif
-	/* NOTREACHED */
-#endif /* ifdef'd out for less's sake when reporting error inside less */
-}
Index: trunk/minix/commands/cawf/regexp.c
===================================================================
--- trunk/minix/commands/cawf/regexp.c	(revision 9)
+++ 	(revision )
@@ -1,1242 +1,0 @@
-/*
- * regcomp and regexec -- regsub and regerror are elsewhere
- *
- *	Copyright (c) 1986 by University of Toronto.
- *	Written by Henry Spencer.  Not derived from licensed software.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to redistribute it freely,
- *	subject to the following restrictions:
- *
- *	1. The author is not responsible for the consequences of use of
- *		this software, no matter how awful, even if they arise
- *		from defects in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *		by explicit claim or by omission.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *		be misrepresented as being the original software.
- *
- * Beware that some of this code is subtly aware of the way operator
- * precedence is structured in regular expressions.  Serious changes in
- * regular-expression syntax might require a total rethink.
- */
-#include <stdio.h>
-#ifdef	UNIX
-#ifdef	USG
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#else
-#include <string.h>
-#endif
-#include "regexp.h"
-#include "regmagic.h"
-#include "proto.h"
-
-/*
- * The "internal use only" fields in regexp.h are present to pass info from
- * compile to execute that permits the execute phase to run lots faster on
- * simple cases.  They are:
- *
- * regstart	char that must begin a match; '\0' if none obvious
- * reganch	is the match anchored (at beginning-of-line only)?
- * regmust	string (pointer into program) that match must include, or NULL
- * regmlen	length of regmust string
- *
- * Regstart and reganch permit very fast decisions on suitable starting points
- * for a match, cutting down the work a lot.  Regmust permits fast rejection
- * of lines that cannot possibly match.  The regmust tests are costly enough
- * that regcomp() supplies a regmust only if the r.e. contains something
- * potentially expensive (at present, the only such thing detected is * or +
- * at the start of the r.e., which can involve a lot of backup).  Regmlen is
- * supplied because the test in regexec() needs it and regcomp() is computing
- * it anyway.
- */
-
-/*
- * Structure for regexp "program".  This is essentially a linear encoding
- * of a nondeterministic finite-state machine (aka syntax charts or
- * "railroad normal form" in parsing technology).  Each node is an opcode
- * plus a "next" pointer, possibly plus an operand.  "Next" pointers of
- * all nodes except BRANCH implement concatenation; a "next" pointer with
- * a BRANCH on both ends of it is connecting two alternatives.  (Here we
- * have one of the subtle syntax dependencies:  an individual BRANCH (as
- * opposed to a collection of them) is never concatenated with anything
- * because of operator precedence.)  The operand of some types of node is
- * a literal string; for others, it is a node leading into a sub-FSM.  In
- * particular, the operand of a BRANCH node is the first node of the branch.
- * (NB this is *not* a tree structure:  the tail of the branch connects
- * to the thing following the set of BRANCHes.)  The opcodes are:
- */
-
-/* definition	number	opnd?	meaning */
-#define	END	0	/* no	End of program. */
-#define	BOL	1	/* no	Match "" at beginning of line. */
-#define	EOL	2	/* no	Match "" at end of line. */
-#define	ANY	3	/* no	Match any one character. */
-#define	ANYOF	4	/* str	Match any character in this string. */
-#define	ANYBUT	5	/* str	Match any character not in this string. */
-#define	BRANCH	6	/* node	Match this alternative, or the next... */
-#define	BACK	7	/* no	Match "", "next" ptr points backward. */
-#define	EXACTLY	8	/* str	Match this string. */
-#define	NOTHING	9	/* no	Match empty string. */
-#define	STAR	10	/* node	Match this (simple) thing 0 or more times. */
-#define	PLUS	11	/* node	Match this (simple) thing 1 or more times. */
-#define	OPEN	20	/* no	Mark this point in input as start of #n. */
-			/*	OPEN+1 is number 1, etc. */
-#define	CLOSE	30	/* no	Analogous to OPEN. */
-
-/*
- * Opcode notes:
- *
- * BRANCH	The set of branches constituting a single choice are hooked
- *		together with their "next" pointers, since precedence prevents
- *		anything being concatenated to any individual branch.  The
- *		"next" pointer of the last BRANCH in a choice points to the
- *		thing following the whole choice.  This is also where the
- *		final "next" pointer of each individual branch points; each
- *		branch starts with the operand node of a BRANCH node.
- *
- * BACK		Normal "next" pointers all implicitly point forward; BACK
- *		exists to make loop structures possible.
- *
- * STAR,PLUS	'?', and complex '*' and '+', are implemented as circular
- *		BRANCH structures using BACK.  Simple cases (one character
- *		per match) are implemented with STAR and PLUS for speed
- *		and to minimize recursive plunges.
- *
- * OPEN,CLOSE	...are numbered at compile time.
- */
-
-/*
- * A node is one char of opcode followed by two chars of "next" pointer.
- * "Next" pointers are stored as two 8-bit pieces, high order first.  The
- * value is a positive offset from the opcode of the node containing it.
- * An operand, if any, simply follows the node.  (Note that much of the
- * code generation knows about this implicit relationship.)
- *
- * Using two bytes for the "next" pointer is vast overkill for most things,
- * but allows patterns to get big without disasters.
- */
-#define	OP(p)	(*(p))
-#define	NEXT(p)	(((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
-#define	OPERAND(p)	((p) + 3)
-
-/*
- * See regmagic.h for one further detail of program structure.
- */
-
-
-/*
- * Utility definitions.
- */
-#ifndef CHARBITS
-#define	UCHARAT(p)	((int)*(unsigned char *)(p))
-#else
-#define	UCHARAT(p)	((int)*(p)&CHARBITS)
-#endif
-
-#define	FAIL(m)	{ regerror(m); return(NULL); }
-#define	ISMULT(c)	((c) == '*' || (c) == '+' || (c) == '?')
-#define	META	"^$.[()|?+*\\"
-
-/*
- * Flags to be passed up and down.
- */
-#define	HASWIDTH	01	/* Known never to match null string. */
-#define	SIMPLE		02	/* Simple enough to be STAR/PLUS operand. */
-#define	SPSTART		04	/* Starts with * or +. */
-#define	WORST		0	/* Worst case. */
-#define STATIC 
-/*
- * Global work variables for regcomp().
- */
-
-STATIC char *regparse;		/* Input-scan pointer. */
-STATIC int regnpar;		/* () count. */
-STATIC unsigned char regdummy;
-STATIC unsigned char *regcode;	/* Code-emit pointer; &regdummy = don't. */
-STATIC long regsize;		/* Code size. */
-
-/*
- * Forward declarations for regcomp()'s friends.
- */
-_PROTOTYPE(STATIC unsigned char *reg, (int paren, int *flagp ));
-_PROTOTYPE(STATIC unsigned char *regbranch, (int *flagp ));
-_PROTOTYPE(STATIC unsigned char *regpiece, (int *flagp ));
-_PROTOTYPE(STATIC unsigned char *regatom, (int *flagp ));
-_PROTOTYPE(STATIC unsigned char *regnode, (int op ));
-_PROTOTYPE(STATIC void regc, (int b ));
-_PROTOTYPE(STATIC void reginsert, (int op, unsigned char *opnd ));
-_PROTOTYPE(STATIC void regtail, (unsigned char *p, unsigned char *val ));
-_PROTOTYPE(STATIC void regoptail, (unsigned char *p, unsigned char *val ));
-_PROTOTYPE(STATIC int regtry, (regexp *prog, unsigned char *string ));
-_PROTOTYPE(STATIC int regmatch, (unsigned char *prog ));
-_PROTOTYPE(STATIC int regrepeat, (unsigned char *p ));
-_PROTOTYPE(STATIC unsigned char *regnext, (unsigned char *p ));
-_PROTOTYPE(STATIC unsigned char *regprop, (unsigned char *op ));
-
-#ifdef STRCSPN
-_PROTOTYPE(STATIC int strcspn, (unsigned char *s1, unsigned char *s2 ));
-#endif
-
-/*
- - regcomp - compile a regular expression into internal code
- *
- * We can't allocate space until we know how big the compiled form will be,
- * but we can't compile it (and thus know how big it is) until we've got a
- * place to put the code.  So we cheat:  we compile it twice, once with code
- * generation turned off and size counting turned on, and once "for real".
- * This also means that we don't allocate space until we are sure that the
- * thing really will compile successfully, and we never have to move the
- * code and thus invalidate pointers into it.  (Note that it has to be in
- * one piece because free() must be able to free it all.)
- *
- * Beware that the optimization-preparation code in here knows about some
- * of the structure of the compiled regexp.
- */
-regexp *
-regcomp(exp)
-char *exp;
-{
-	register regexp *r;
-	register unsigned char *scan;
-	register unsigned char *longest;
-	register int len;
-	int flags;
-
-	if (exp == NULL)
-		FAIL("NULL argument");
-
-	/* First pass: determine size, legality. */
-	regparse = exp;
-	regnpar = 1;
-	regsize = 0L;
-	regcode = &regdummy;
-	regc(MAGIC);
-	if (reg(0, &flags) == NULL)
-		return(NULL);
-
-	/* Small enough for pointer-storage convention? */
-	if (regsize >= 32767L)		/* Probably could be 65535L. */
-		FAIL("regexp too big");
-
-	/* Allocate space. */
-	r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize);
-	if (r == NULL)
-		FAIL("out of space");
-
-	/* Second pass: emit code. */
-	regparse = exp;
-	regnpar = 1;
-	regcode = r->program;
-	regc(MAGIC);
-	if (reg(0, &flags) == NULL)
-		return(NULL);
-
-	/* Dig out information for optimizations. */
-	r->regstart = '\0';	/* Worst-case defaults. */
-	r->reganch = 0;
-	r->regmust = NULL;
-	r->regmlen = 0;
-	scan = r->program+1;			/* First BRANCH. */
-	if (OP(regnext(scan)) == END) {		/* Only one top-level choice. */
-		scan = OPERAND(scan);
-
-		/* Starting-point info. */
-		if (OP(scan) == EXACTLY)
-			r->regstart = *OPERAND(scan);
-		else if (OP(scan) == BOL)
-			r->reganch++;
-
-		/*
-		 * If there's something expensive in the r.e., find the
-		 * longest literal string that must appear and make it the
-		 * regmust.  Resolve ties in favor of later strings, since
-		 * the regstart check works with the beginning of the r.e.
-		 * and avoiding duplication strengthens checking.  Not a
-		 * strong reason, but sufficient in the absence of others.
-		 */
-		if (flags&SPSTART) {
-			longest = NULL;
-			len = 0;
-			for (; scan != NULL; scan = regnext(scan))
-				if (OP(scan) == EXACTLY
-				&& strlen((char *)OPERAND(scan)) >= len) {
-					longest = OPERAND(scan);
-					len = strlen((char *)OPERAND(scan));
-				}
-			r->regmust = longest;
-			r->regmlen = len;
-		}
-	}
-
-	return(r);
-}
-
-/*
- - reg - regular expression, i.e. main body or parenthesized thing
- *
- * Caller must absorb opening parenthesis.
- *
- * Combining parenthesis handling with the base level of regular expression
- * is a trifle forced, but the need to tie the tails of the branches to what
- * follows makes it hard to avoid.
- */
-STATIC unsigned char *
-reg(paren, flagp)
-int paren;			/* Parenthesized? */
-int *flagp;
-{
-	register unsigned char *ret;
-	register unsigned char *br;
-	register unsigned char *ender;
-	register int parno;
-	int flags;
-
-	*flagp = HASWIDTH;	/* Tentatively. */
-
-	/* Make an OPEN node, if parenthesized. */
-	if (paren) {
-		if (regnpar >= NSUBEXP)
-			FAIL("too many ()");
-		parno = regnpar;
-		regnpar++;
-		ret = regnode(OPEN+parno);
-	} else
-		ret = NULL;
-
-	/* Pick up the branches, linking them together. */
-	br = regbranch(&flags);
-	if (br == NULL)
-		return(NULL);
-	if (ret != NULL)
-		regtail(ret, br);	/* OPEN -> first. */
-	else
-		ret = br;
-	if (!(flags&HASWIDTH))
-		*flagp &= ~HASWIDTH;
-	*flagp |= flags&SPSTART;
-	while (*regparse == '|') {
-		regparse++;
-		br = regbranch(&flags);
-		if (br == NULL)
-			return(NULL);
-		regtail(ret, br);	/* BRANCH -> BRANCH. */
-		if (!(flags&HASWIDTH))
-			*flagp &= ~HASWIDTH;
-		*flagp |= flags&SPSTART;
-	}
-
-	/* Make a closing node, and hook it on the end. */
-	ender = regnode((paren) ? CLOSE+parno : END);	
-	regtail(ret, ender);
-
-	/* Hook the tails of the branches to the closing node. */
-	for (br = ret; br != NULL; br = regnext(br))
-		regoptail(br, ender);
-
-	/* Check for proper termination. */
-	if (paren && *regparse++ != ')') {
-		FAIL("unmatched ()");
-	} else if (!paren && *regparse != '\0') {
-		if (*regparse == ')') {
-			FAIL("unmatched ()");
-		} else
-			FAIL("junk on end");	/* "Can't happen". */
-		/* NOTREACHED */
-	}
-
-	return(ret);
-}
-
-/*
- - regbranch - one alternative of an | operator
- *
- * Implements the concatenation operator.
- */
-STATIC unsigned char *
-regbranch(flagp)
-int *flagp;
-{
-	register unsigned char *ret;
-	register unsigned char *chain;
-	register unsigned char *latest;
-	int flags;
-
-	*flagp = WORST;		/* Tentatively. */
-
-	ret = regnode(BRANCH);
-	chain = NULL;
-	while (*regparse != '\0' && *regparse != '|' && *regparse != ')') {
-		latest = regpiece(&flags);
-		if (latest == NULL)
-			return(NULL);
-		*flagp |= flags&HASWIDTH;
-		if (chain == NULL)	/* First piece. */
-			*flagp |= flags&SPSTART;
-		else
-			regtail(chain, latest);
-		chain = latest;
-	}
-	if (chain == NULL)	/* Loop ran zero times. */
-		(void) regnode(NOTHING);
-
-	return(ret);
-}
-
-/*
- - regpiece - something followed by possible [*+?]
- *
- * Note that the branching code sequences used for ? and the general cases
- * of * and + are somewhat optimized:  they use the same NOTHING node as
- * both the endmarker for their branch list and the body of the last branch.
- * It might seem that this node could be dispensed with entirely, but the
- * endmarker role is not redundant.
- */
-STATIC unsigned char *
-regpiece(flagp)
-int *flagp;
-{
-	register unsigned char *ret;
-	register unsigned char op;
-	register unsigned char *next;
-	int flags;
-
-	ret = regatom(&flags);
-	if (ret == NULL)
-		return(NULL);
-
-	op = *regparse;
-	if (!ISMULT(op)) {
-		*flagp = flags;
-		return(ret);
-	}
-
-	if (!(flags&HASWIDTH) && op != '?')
-		FAIL("*+ operand could be empty");
-	*flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH);
-
-	if (op == '*' && (flags&SIMPLE))
-		reginsert(STAR, ret);
-	else if (op == '*') {
-		/* Emit x* as (x&|), where & means "self". */
-		reginsert(BRANCH, ret);			/* Either x */
-		regoptail(ret, regnode(BACK));		/* and loop */
-		regoptail(ret, ret);			/* back */
-		regtail(ret, regnode(BRANCH));		/* or */
-		regtail(ret, regnode(NOTHING));		/* null. */
-	} else if (op == '+' && (flags&SIMPLE))
-		reginsert(PLUS, ret);
-	else if (op == '+') {
-		/* Emit x+ as x(&|), where & means "self". */
-		next = regnode(BRANCH);			/* Either */
-		regtail(ret, next);
-		regtail(regnode(BACK), ret);		/* loop back */
-		regtail(next, regnode(BRANCH));		/* or */
-		regtail(ret, regnode(NOTHING));		/* null. */
-	} else if (op == '?') {
-		/* Emit x? as (x|) */
-		reginsert(BRANCH, ret);			/* Either x */
-		regtail(ret, regnode(BRANCH));		/* or */
-		next = regnode(NOTHING);		/* null. */
-		regtail(ret, next);
-		regoptail(ret, next);
-	}
-	regparse++;
-	if (ISMULT(*regparse))
-		FAIL("nested *?+");
-
-	return(ret);
-}
-
-/*
- - regatom - the lowest level
- *
- * Optimization:  gobbles an entire sequence of ordinary characters so that
- * it can turn them into a single node, which is smaller to store and
- * faster to run.  Backslashed characters are exceptions, each becoming a
- * separate node; the code is simpler that way and it's not worth fixing.
- */
-STATIC unsigned char *
-regatom(flagp)
-int *flagp;
-{
-	register unsigned char *ret;
-	int flags;
-
-	*flagp = WORST;		/* Tentatively. */
-
-	switch (*regparse++) {
-	case '^':
-		ret = regnode(BOL);
-		break;
-	case '$':
-		ret = regnode(EOL);
-		break;
-	case '.':
-		ret = regnode(ANY);
-		*flagp |= HASWIDTH|SIMPLE;
-		break;
-	case '[': {
-			register int class;
-			register int classend;
-
-			if (*regparse == '^') {	/* Complement of range. */
-				ret = regnode(ANYBUT);
-				regparse++;
-			} else
-				ret = regnode(ANYOF);
-			if (*regparse == ']' || *regparse == '-')
-				regc(*regparse++);
-			while (*regparse != '\0' && *regparse != ']') {
-				if (*regparse == '-') {
-					regparse++;
-					if (*regparse == ']' || *regparse == '\0')
-						regc('-');
-					else {
-						class = UCHARAT(regparse-2)+1;
-						classend = UCHARAT(regparse);
-						if (class > classend+1)
-							FAIL("invalid [] range");
-						for (; class <= classend; class++)
-							regc(class);
-						regparse++;
-					}
-				} else
-					regc(*regparse++);
-			}
-			regc('\0');
-			if (*regparse != ']')
-				FAIL("unmatched []");
-			regparse++;
-			*flagp |= HASWIDTH|SIMPLE;
-		}
-		break;
-	case '(':
-		ret = reg(1, &flags);
-		if (ret == NULL)
-			return(NULL);
-		*flagp |= flags&(HASWIDTH|SPSTART);
-		break;
-	case '\0':
-	case '|':
-	case ')':
-		FAIL("internal urp");	/* Supposed to be caught earlier. */
-		break;
-	case '?':
-	case '+':
-	case '*':
-		FAIL("?+* follows nothing");
-		break;
-	case '\\':
-		if (*regparse == '\0')
-			FAIL("trailing \\");
-		ret = regnode(EXACTLY);
-		regc(*regparse++);
-		regc('\0');
-		*flagp |= HASWIDTH|SIMPLE;
-		break;
-	default: {
-			register int len;
-			register unsigned char ender;
-
-			regparse--;
-#ifdef	STRCSPN
-			len = strcspn(regparse, (unsigned char *)META);
-#else
-			len = strcspn((char *)regparse, META);
-#endif
-			if (len <= 0)
-				FAIL("internal disaster");
-			ender = *(regparse+len);
-			if (len > 1 && ISMULT(ender))
-				len--;		/* Back off clear of ?+* operand. */
-			*flagp |= HASWIDTH;
-			if (len == 1)
-				*flagp |= SIMPLE;
-			ret = regnode(EXACTLY);
-			while (len > 0) {
-				regc(*regparse++);
-				len--;
-			}
-			regc('\0');
-		}
-		break;
-	}
-
-	return(ret);
-}
-
-/*
- - regnode - emit a node
- */
-STATIC unsigned char *			/* Location. */
-regnode(iop)
-int iop;
-{
-	register unsigned char *ret;
-	register unsigned char *ptr;
-	unsigned char op;
-
-	op = (unsigned char) iop;
-	ret = regcode;
-	if (ret == &regdummy) {
-		regsize += 3;
-		return(ret);
-	}
-
-	ptr = ret;
-	*ptr++ = op;
-	*ptr++ = '\0';		/* Null "next" pointer. */
-	*ptr++ = '\0';
-	regcode = ptr;
-
-	return(ret);
-}
-
-/*
- - regc - emit (if appropriate) a byte of code
- */
-STATIC void
-regc(ib)
-int ib;
-{
-	unsigned char b;
-
-	b = (unsigned char) ib;
-	if (regcode != &regdummy)
-		*regcode++ = b;
-	else
-		regsize++;
-}
-
-/*
- - reginsert - insert an operator in front of already-emitted operand
- *
- * Means relocating the operand.
- */
-STATIC void
-reginsert(iop, opnd)
-int iop;
-unsigned char *opnd;
-{
-	register unsigned char *src;
-	register unsigned char *dst;
-	register unsigned char *place;
-	unsigned char op;
-
-	op = (unsigned char) iop;
-	if (regcode == &regdummy) {
-		regsize += 3;
-		return;
-	}
-
-	src = regcode;
-	regcode += 3;
-	dst = regcode;
-	while (src > opnd)
-		*--dst = *--src;
-
-	place = opnd;		/* Op node, where operand used to be. */
-	*place++ = op;
-	*place++ = '\0';
-	*place++ = '\0';
-}
-
-/*
- - regtail - set the next-pointer at the end of a node chain
- */
-STATIC void
-regtail(p, val)
-unsigned char *p;
-unsigned char *val;
-{
-	register unsigned char *scan;
-	register unsigned char *temp;
-	register int offset;
-
-	if (p == &regdummy)
-		return;
-
-	/* Find last node. */
-	scan = p;
-	for (;;) {
-		temp = regnext(scan);
-		if (temp == NULL)
-			break;
-		scan = temp;
-	}
-
-	if (OP(scan) == BACK)
-		offset = scan - val;
-	else
-		offset = val - scan;
-	*(scan+1) = (offset>>8)&0377;
-	*(scan+2) = offset&0377;
-}
-
-/*
- - regoptail - regtail on operand of first argument; nop if operandless
- */
-STATIC void
-regoptail(p, val)
-unsigned char *p;
-unsigned char *val;
-{
-	/* "Operandless" and "op != BRANCH" are synonymous in practice. */
-	if (p == NULL || p == &regdummy || OP(p) != BRANCH)
-		return;
-	regtail(OPERAND(p), val);
-}
-
-/*
- * regexec and friends
- */
-
-/*
- * Global work variables for regexec().
- */
-STATIC unsigned char *reginput;		/* String-input pointer. */
-STATIC unsigned char *regbol;		/* Beginning of input, for ^ check. */
-STATIC unsigned char **regstartp;	/* Pointer to startp array. */
-STATIC unsigned char **regendp;		/* Ditto for endp. */
-
-#ifdef DEBUG
-int regnarrate = 0;
-void regdump();
-STATIC unsigned char *regprop();
-#endif
-
-/*
- - regexec - match a regexp against a string
- */
-int
-regexec(prog, string)
-register regexp *prog;
-register unsigned char *string;
-{
-	register unsigned char *s;
-#ifndef	STDLIB
-	extern char *strchr();
-#endif
-
-	/* Be paranoid... */
-	if (prog == NULL || string == NULL) {
-		regerror("NULL parameter");
-		return(0);
-	}
-
-	/* Check validity of program. */
-	if (UCHARAT(prog->program) != MAGIC) {
-		regerror("corrupted program");
-		return(0);
-	}
-
-	/* If there is a "must appear" string, look for it. */
-	if (prog->regmust != NULL) {
-		s = string;
-		while ((s = (unsigned char *)strchr((char *)s,prog->regmust[0]))
-		!= NULL) {
-			if (strncmp((char *)s, (char *)prog->regmust,
-			    prog->regmlen)
-			== 0)
-				break;	/* Found it. */
-			s++;
-		}
-		if (s == NULL)	/* Not present. */
-			return(0);
-	}
-
-	/* Mark beginning of line for ^ . */
-	regbol = string;
-
-	/* Simplest case:  anchored match need be tried only once. */
-	if (prog->reganch)
-		return(regtry(prog, string));
-
-	/* Messy cases:  unanchored match. */
-	s = string;
-	if (prog->regstart != '\0')
-		/* We know what char it must start with. */
-		while ((s = (unsigned char *)strchr((char *)s, prog->regstart))
-		!= NULL) {
-			if (regtry(prog, s))
-				return(1);
-			s++;
-		}
-	else
-		/* We don't -- general case. */
-		do {
-			if (regtry(prog, s))
-				return(1);
-		} while (*s++ != '\0');
-
-	/* Failure. */
-	return(0);
-}
-
-/*
- - regtry - try match at specific point
- */
-STATIC int			/* 0 failure, 1 success */
-regtry(prog, string)
-regexp *prog;
-unsigned char *string;
-{
-	register int i;
-	register unsigned char **sp;
-	register unsigned char **ep;
-
-	reginput = string;
-	regstartp = prog->startp;
-	regendp = prog->endp;
-
-	sp = prog->startp;
-	ep = prog->endp;
-	for (i = NSUBEXP; i > 0; i--) {
-		*sp++ = NULL;
-		*ep++ = NULL;
-	}
-	if (regmatch(prog->program + 1)) {
-		prog->startp[0] = string;
-		prog->endp[0] = reginput;
-		return(1);
-	} else
-		return(0);
-}
-
-/*
- - regmatch - main matching routine
- *
- * Conceptually the strategy is simple:  check to see whether the current
- * node matches, call self recursively to see whether the rest matches,
- * and then act accordingly.  In practice we make some effort to avoid
- * recursion, in particular by going through "ordinary" nodes (that don't
- * need to know whether the rest of the match failed) by a loop instead of
- * by recursion.
- */
-STATIC int			/* 0 failure, 1 success */
-regmatch(prog)
-unsigned char *prog;
-{
-	register unsigned char *scan;	/* Current node. */
-	unsigned char *next;		/* Next node. */
-#ifndef	STDLIB
-	extern char *strchr();
-#endif
-
-	scan = prog;
-#ifdef DEBUG
-	if (scan != NULL && regnarrate)
-		fprintf(stderr, "%s(\n", regprop(scan));
-#endif
-	while (scan != NULL) {
-#ifdef DEBUG
-		if (regnarrate)
-			fprintf(stderr, "%s...\n", regprop(scan));
-#endif
-		next = regnext(scan);
-
-		switch (OP(scan)) {
-		case BOL:
-			if (reginput != regbol)
-				return(0);
-			break;
-		case EOL:
-			if (*reginput != '\0')
-				return(0);
-			break;
-		case ANY:
-			if (*reginput == '\0')
-				return(0);
-			reginput++;
-			break;
-		case EXACTLY: {
-				register int len;
-				register unsigned char *opnd;
-
-				opnd = OPERAND(scan);
-				/* Inline the first character, for speed. */
-				if (*opnd != *reginput)
-					return(0);
-				len = strlen((char *)opnd);
-				if (len > 1 && strncmp((char *)opnd,
-				   (char *)reginput, len)
-				!= 0)
-					return(0);
-				reginput += len;
-			}
-			break;
-		case ANYOF:
-			if (*reginput == '\0'
-			|| strchr((char *)OPERAND(scan), *reginput) == NULL)
-				return(0);
-			reginput++;
-			break;
-		case ANYBUT:
-			if (*reginput == '\0'
-			|| strchr((char *)OPERAND(scan), *reginput) != NULL)
-				return(0);
-			reginput++;
-			break;
-		case NOTHING:
-			break;
-		case BACK:
-			break;
-		case OPEN+1:
-		case OPEN+2:
-		case OPEN+3:
-		case OPEN+4:
-		case OPEN+5:
-		case OPEN+6:
-		case OPEN+7:
-		case OPEN+8:
-		case OPEN+9: {
-				register int no;
-				register unsigned char *save;
-
-				no = OP(scan) - OPEN;
-				save = reginput;
-
-				if (regmatch(next)) {
-					/*
-					 * Don't set startp if some later
-					 * invocation of the same parentheses
-					 * already has.
-					 */
-					if (regstartp[no] == NULL)
-						regstartp[no] = save;
-					return(1);
-				} else
-					return(0);
-			}
-			break;
-		case CLOSE+1:
-		case CLOSE+2:
-		case CLOSE+3:
-		case CLOSE+4:
-		case CLOSE+5:
-		case CLOSE+6:
-		case CLOSE+7:
-		case CLOSE+8:
-		case CLOSE+9: {
-				register int no;
-				register unsigned char *save;
-
-				no = OP(scan) - CLOSE;
-				save = reginput;
-
-				if (regmatch(next)) {
-					/*
-					 * Don't set endp if some later
-					 * invocation of the same parentheses
-					 * already has.
-					 */
-					if (regendp[no] == NULL)
-						regendp[no] = save;
-					return(1);
-				} else
-					return(0);
-			}
-			break;
-		case BRANCH: {
-				register unsigned char *save;
-
-				if (OP(next) != BRANCH)		/* No choice. */
-					next = OPERAND(scan);	/* Avoid recursion. */
-				else {
-					do {
-						save = reginput;
-						if (regmatch(OPERAND(scan)))
-							return(1);
-						reginput = save;
-						scan = regnext(scan);
-					} while (scan != NULL && OP(scan) == BRANCH);
-					return(0);
-					/* NOTREACHED */
-				}
-			}
-			break;
-		case STAR:
-		case PLUS: {
-				register unsigned char nextch;
-				register int no;
-				register unsigned char *save;
-				register int min;
-
-				/*
-				 * Lookahead to avoid useless match attempts
-				 * when we know what character comes next.
-				 */
-				nextch = '\0';
-				if (OP(next) == EXACTLY)
-					nextch = *OPERAND(next);
-				min = (OP(scan) == STAR) ? 0 : 1;
-				save = reginput;
-				no = regrepeat(OPERAND(scan));
-				while (no >= min) {
-					/* If it could work, try it. */
-					if (nextch == '\0' || *reginput == nextch)
-						if (regmatch(next))
-							return(1);
-					/* Couldn't or didn't -- back up. */
-					no--;
-					reginput = save + no;
-				}
-				return(0);
-			}
-			break;
-		case END:
-			return(1);	/* Success! */
-			break;
-		default:
-			regerror("memory corruption");
-			return(0);
-			break;
-		}
-
-		scan = next;
-	}
-
-	/*
-	 * We get here only if there's trouble -- normally "case END" is
-	 * the terminating point.
-	 */
-	regerror("corrupted pointers");
-	return(0);
-}
-
-/*
- - regrepeat - repeatedly match something simple, report how many
- */
-STATIC int
-regrepeat(p)
-unsigned char *p;
-{
-	register int count = 0;
-	register unsigned char *scan;
-	register unsigned char *opnd;
-
-	scan = reginput;
-	opnd = OPERAND(p);
-	switch (OP(p)) {
-	case ANY:
-		count = strlen((char *)scan);
-		scan += count;
-		break;
-	case EXACTLY:
-		while (*opnd == *scan) {
-			count++;
-			scan++;
-		}
-		break;
-	case ANYOF:
-		while (*scan != '\0' && strchr((char *)opnd, *scan) != NULL) {
-			count++;
-			scan++;
-		}
-		break;
-	case ANYBUT:
-		while (*scan != '\0' && strchr((char *)opnd, *scan) == NULL) {
-			count++;
-			scan++;
-		}
-		break;
-	default:		/* Oh dear.  Called inappropriately. */
-		regerror("internal foulup");
-		count = 0;	/* Best compromise. */
-		break;
-	}
-	reginput = scan;
-
-	return(count);
-}
-
-/*
- - regnext - dig the "next" pointer out of a node
- */
-STATIC unsigned char *
-regnext(p)
-register unsigned char *p;
-{
-	register int offset;
-
-	if (p == &regdummy)
-		return(NULL);
-
-	offset = NEXT(p);
-	if (offset == 0)
-		return(NULL);
-
-	if (OP(p) == BACK)
-		return(p-offset);
-	else
-		return(p+offset);
-}
-
-#ifdef DEBUG
-
-STATIC unsigned char *regprop();
-
-/*
- - regdump - dump a regexp onto stdout in vaguely comprehensible form
- */
-void
-regdump(r)
-regexp *r;
-{
-	register unsigned char *s;
-	register unsigned char op = EXACTLY;	/* Arbitrary non-END op. */
-	register unsigned char *next;
-	extern char *strchr();
-
-
-	s = r->program + 1;
-	while (op != END) {	/* While that wasn't END last time... */
-		op = OP(s);
-		printf("%2d%s", s-r->program, regprop(s));	/* Where, what. */
-		next = regnext(s);
-		if (next == NULL)		/* Next ptr. */
-			printf("(0)");
-		else 
-			printf("(%d)", (s-r->program)+(next-s));
-		s += 3;
-		if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
-			/* Literal string, where present. */
-			while (*s != '\0') {
-				putchar(*s);
-				s++;
-			}
-			s++;
-		}
-		putchar('\n');
-	}
-
-	/* Header fields of interest. */
-	if (r->regstart != '\0')
-		printf("start `%c' ", r->regstart);
-	if (r->reganch)
-		printf("anchored ");
-	if (r->regmust != NULL)
-		printf("must have \"%s\"", r->regmust);
-	printf("\n");
-}
-
-/*
- - regprop - printable representation of opcode
- */
-STATIC unsigned char *
-regprop(op)
-unsigned char *op;
-{
-	register unsigned char *p;
-	STATIC unsigned char buf[50];
-
-	(void) strcpy(buf, ":");
-
-	switch (OP(op)) {
-	case BOL:
-		p = "BOL";
-		break;
-	case EOL:
-		p = "EOL";
-		break;
-	case ANY:
-		p = "ANY";
-		break;
-	case ANYOF:
-		p = "ANYOF";
-		break;
-	case ANYBUT:
-		p = "ANYBUT";
-		break;
-	case BRANCH:
-		p = "BRANCH";
-		break;
-	case EXACTLY:
-		p = "EXACTLY";
-		break;
-	case NOTHING:
-		p = "NOTHING";
-		break;
-	case BACK:
-		p = "BACK";
-		break;
-	case END:
-		p = "END";
-		break;
-	case OPEN+1:
-	case OPEN+2:
-	case OPEN+3:
-	case OPEN+4:
-	case OPEN+5:
-	case OPEN+6:
-	case OPEN+7:
-	case OPEN+8:
-	case OPEN+9:
-		sprintf(buf+strlen(buf), "OPEN%d", OP(op)-OPEN);
-		p = NULL;
-		break;
-	case CLOSE+1:
-	case CLOSE+2:
-	case CLOSE+3:
-	case CLOSE+4:
-	case CLOSE+5:
-	case CLOSE+6:
-	case CLOSE+7:
-	case CLOSE+8:
-	case CLOSE+9:
-		sprintf(buf+strlen(buf), "CLOSE%d", OP(op)-CLOSE);
-		p = NULL;
-		break;
-	case STAR:
-		p = "STAR";
-		break;
-	case PLUS:
-		p = "PLUS";
-		break;
-	default:
-		regerror("corrupted opcode");
-		break;
-	}
-	if (p != NULL)
-		(void) strcat(buf, p);
-	return(buf);
-}
-#endif
-
-/*
- * The following is provided for those people who do not have strcspn() in
- * their C libraries.  They should get off their butts and do something
- * about it; at least one public-domain implementation of those (highly
- * useful) string routines has been published on Usenet.
- */
-#ifdef STRCSPN
-/*
- * strcspn - find length of initial segment of s1 consisting entirely
- * of characters not from s2
- */
-
-STATIC int
-strcspn(s1, s2)
-unsigned char *s1;
-unsigned char *s2;
-{
-	register unsigned char *scan1;
-	register unsigned char *scan2;
-	register int count;
-
-	count = 0;
-	for (scan1 = s1; *scan1 != '\0'; scan1++) {
-		for (scan2 = s2; *scan2 != '\0';)	/* ++ moved down. */
-			if (*scan1 == *scan2++)
-				return(count);
-		count++;
-	}
-	return(count);
-}
-#endif
Index: trunk/minix/commands/cawf/regexp.h
===================================================================
--- trunk/minix/commands/cawf/regexp.h	(revision 9)
+++ 	(revision )
@@ -1,17 +1,0 @@
-/*
- * Definitions etc. for regexp(3) routines.
- *
- * Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
- * not the System V one.
- */
-#define NSUBEXP  10
-typedef struct regexp {
-	unsigned char *startp[NSUBEXP];
-	unsigned char *endp[NSUBEXP];
-	unsigned char regstart;		/* Internal use only. */
-	unsigned char reganch;		/* Internal use only. */
-	unsigned char *regmust;		/* Internal use only. */
-	unsigned char regmlen;		/* Internal use only. */
-	unsigned char program[1];	/* Unwarranted chumminess with
-					 * compiler. */
-} regexp;
Index: trunk/minix/commands/cawf/regmagic.h
===================================================================
--- trunk/minix/commands/cawf/regmagic.h	(revision 9)
+++ 	(revision )
@@ -1,5 +1,0 @@
-/*
- * The first byte of the regexp internal "program" is actually this magic
- * number; the start node begins in the second byte.
- */
-#define	MAGIC	0234
Index: trunk/minix/commands/cawf/store.c
===================================================================
--- trunk/minix/commands/cawf/store.c	(revision 9)
+++ 	(revision )
@@ -1,184 +1,0 @@
-/*
- *	store.c - cawf(1) storage areas
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-
-struct rx Pat[] = {
-	{ "^[.'](i[ef]|el)",			 	NULL},	/* 0 */
-	{ "^[.']i[ef] !",				NULL},  /* 1 */
-	{ "^[.']i[ef] !?\\\\n\\(\\.\\$(>|>=|=|<|<=)[0-9] ",
-							NULL},	/* 2 */
-	{ "^[.']i[ef] !?'\\\\\\$[0-9]'[^']*' ",		NULL},	/* 3 */
-	{ "^[.']i[ef] !?[nt] ",				NULL},  /* 4 */
-	{ "\\\\\\$[0-9]",                               NULL},  /* 5 */
-	{ "^[ \t]*$",					NULL},  /* 6 */
-	{ "\\\\|\t|-|  ",				NULL},	/* 7 */
-	{ "[.!?:][]\\)'\\\"\\*]*$",                     NULL},  /* 8 */
-	{ ",fP",					NULL},	/* 9 */
-	{ ",tP",					NULL},	/* 10 */
-	{ "^(ta|ll|ls|in|ti|po|ne|sp|pl|nr)",           NULL},  /* 11 */
-	{ "^(ll|ls|in|ti|po|pl)",                       NULL},  /* 12 */
-	{ "[]\\)'\\\"\\*]",                             NULL},  /* 13 */
-	{ "^(LH|CH|RH|LF|CF|RF)",			NULL},	/* 14 */
-	{ "^[.']i[ef]",			 		NULL},	/* 15 */
-	{ ",fR",					NULL},	/* 16 */
-	{ NULL,                                         NULL}   /* END */
-};
-
-int Adj = BOTHADJ;			/* output line adjustment mode */
-unsigned char *Aftnxt = NULL;		/* action after next line */
-unsigned char *Args[] = { NULL, NULL,	/* 10 macro arguments */
-			  NULL, NULL,
-			  NULL, NULL,
-			  NULL, NULL,
-			  NULL, NULL
-};
-unsigned char *Argstack[10*MAXSP];	/* stack for Expand()'s "args[]" */
-int Backc = 0;				/* last word ended with '\\c' */
-int Botmarg = 5;			/* bottom margin */
-int Centering = 0;			/* centering count */
-int Condstack[MAXSP];                   /* stack for Expand()'s "cond" */
-unsigned char *Cont = NULL;		/* continue line append */
-int Contlen = 0;			/* continue line append length */
-int Curmx = -1;				/* current macro index */
-char *Device = NULL;			/* output device name */
-char *Devconf = NULL;			/* device configuration file path */
-char *Devfont = NULL;			/* output device font */
-int Divert = 0;                         /* diversion status */
-FILE *Efs = NULL;			/* error file stream */
-unsigned char *Eol = NULL;		/* end of line information */
-int Eollen = 0;				/* end of line length */
-int Err = 0;                            /* error flag */
-unsigned char *F = NULL;		/* field value */
-struct fcode Fcode[] = {		/* font codes */
-	{ 'B',  '\0'},			/* Bold */
-	{ 'I',  '\0'},			/* Italic */
-	{ 'R',  '\0'},			/* Roman */
-	{ 'C',  '\0'},			/* Courier */
-	{ '\0', '\0'}
-};
-int Fill = 0;				/* fill status */
-unsigned char Font[] = { '\0', '\0' };	/* current font */
-int Fontctl;				/* output font control */
-char Fontstat = 'R';			/* output font status */
-int Fph = 0;				/* first page header status */
-int Fsp = 0;				/* files stack pointer (for .so) */
-struct fontstr Fstr;			/* font control strings */
-unsigned char *Ftc = NULL;		/* center footer */
-unsigned char *Ftl = NULL;		/* left footer */
-unsigned char *Ftr = NULL;		/* right footer */
-unsigned char *Hdc = NULL;		/* center header */
-int Hdft = 0;				/* header/footer status */
-unsigned char *Hdl = NULL;		/* left header */
-unsigned char *Hdr = NULL;		/* right header */
-struct hytab Hychar[MAXHYCH];		/* hyphen characters */
-FILE *Ifs = NULL;			/* input file stream */
-FILE *Ifs_stk[MAXFSTK];                 /* Ifs stack */
-int Ind = 0;				/* indentation amount */
-unsigned char *Inname = NULL;		/* input file name */
-unsigned char *Inn_stk[MAXFSTK];	/* Inname stack */
-int LL = 78;				/* line length (default) */
-unsigned char Line[MAXLINE];		/* input line */
-int Lockil = 0;                      	/* pass 2 line number is locked
-                                         * (processing is inside macro) */
-int Marg = 0;				/* macro argument - man, ms, etc. */
-struct macro Macrotab[MAXMACRO];        /* macro table */
-unsigned char *Macrotxt[MAXMTXT];	/* macro text */
-int Mtx = 0;                            /* macro text index */
-int Mxstack[MAXSP];                     /* stack for Expand()'s "mx" */
-int Nfc;				/* number of font codes */
-int Nhnr[MAXNHNR];                      /* ".NH" numbers */
-int Nhy = 0;				/* number of Hychar[] entries */
-int Nleftstack[MAXSP];                  /* stack for Expand()'s "nleft" */
-int Nmac = 0;                           /* number of macros */
-int Nnr = 0;				/* number of Numb[] entries */
-int Nospmode = 1;                    	/* no space mode */
-int Nparms = 0;				/* number of Parms[] entries */
-int NR = 0;                             /* number of record ala awk */
-int NR_stk[MAXFSTK];                   	/* NR stack */
-int Nsch = 0;				/* number of Schar[] entries */
-int Nstr = 0;				/* number of entries in Str[] */
-int Ntabs = 0;				/* number of TAB positions */
-struct nbr Numb[MAXNR];			/* number registers */
-int Nxtln = 1;				/* next line number */
-int Outll = -1;				/* output line length */
-unsigned char Outln[MAXOLL*2];		/* output line */
-int Outlx = 0;				/* output line index */
-int P2il = 0; 	                        /* pass 2 input line number */
-unsigned char *P2name = NULL;		/* pass 2 input file name */
-int P3fill = 1;				/* pass 3 fill status */
-int Padchar[MAXOLL];			/* padding character locations */
-int Padfrom = PADLEFT;			/* which end to pad from */
-int Padx = 0;				/* Padchar[] index */
-struct parms Parms[] = {                /* parameter registers */
-	{ {'i', 'n'}, "indent", 0, 0      },
-	{ {'l', 'l'}, "linelen", 0, 0     },
-	{ {'l', 's'}, "vspace", 0, 0	  },
-	{ {'t', 'i'}, "tempindent", 0, 0  },
-	{ {'p', 'o'}, "pageoffset", 0, 0  },
-	{ {'p', 'l'}, "pagelen", 0, 0     },
-	{ {'\0', '\0'}, NULL, 0, 0        }
-};
-unsigned char Pass1ln[MAXLINE];		/* pass 1 output line */
-unsigned char Pass2ln[MAXLINE];		/* pass 2 output line */
-int Pglen = 66;				/* page length */
-int Pgoff = 0;				/* page offset */
-char *Pname = NULL;			/* program name */
-unsigned char Prevfont = '\0';		/* previous font */
-int Ptrstack[MAXSP];                    /* stack for Expand()'s "ptr" */
-struct scale Scale[] = {		/* scaling factors */
-	{ 'i',	(240.0)		 	},
-	{ 'c',	((240.0 * 50.0)/127.0)	},
-	{ 'P',	(240.0/6.0)		},
-	{ 'p',	(240.0/72.0)		},
-	{ 'u',  (1.0)                   },
-	{ 'm',  (1.0)                   },
-	{ 'n',  (1.0)                   },
-	{ 'v',  (1.0)                   },
-	{ '\0',	(0.0)			}
-};
-double Scalen = 0.0;			/* 'n' scaling factor */
-double Scaleu = 0.0;			/* 'u' scaling factor */
-double Scalev = 0.0;			/* 'v' scaling factor */
-struct schtab Schar[MAXSCH];		/* special characters */
-int Sp = -1;				/* stack pointer */
-struct str Str[MAXSTR];                 /* ".ds" strings */
-int Sx = -1;				/* string index */
-int Tabs[MAXEXP+1];			/* TAB positions */
-int Thispg = 1;				/* this page number */
-int Tind = 0; 				/* temporary indentation amount */
-int Topmarg = 5;			/* top margin */
-unsigned char *Trtbl = NULL;		/* .tr table */
-int Uhyph = 0;				/* hyphen usage state */
-int Vspace = 1;				/* vertical (inter-text-line) spacing */
-unsigned char Word[MAXLINE];		/* pass 2 word buffer */
-int Wordl = 0;                          /* effective length of Word[] */
-int Wordx = 0;                          /* Word[] index */
-int Dowarn = 1;				/* Enable warnings if true */
Index: trunk/minix/commands/cawf/string.c
===================================================================
--- trunk/minix/commands/cawf/string.c	(revision 9)
+++ 	(revision )
@@ -1,351 +1,0 @@
-/*
- *	string.c - string support functions for cawf(1)
- */
-
-/*
- *	Copyright (c) 1991 Purdue University Research Foundation,
- *	West Lafayette, Indiana 47907.  All rights reserved.
- *
- *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
- *	University Computing Center.  Not derived from licensed software;
- *	derived from awf(1) by Henry Spencer of the University of Toronto.
- *
- *	Permission is granted to anyone to use this software for any
- *	purpose on any computer system, and to alter it and redistribute
- *	it freely, subject to the following restrictions:
- *
- *	1. The author is not responsible for any consequences of use of
- *	   this software, even if they arise from flaws in it.
- *
- *	2. The origin of this software must not be misrepresented, either
- *	   by explicit claim or by omission.  Credits must appear in the
- *	   documentation.
- *
- *	3. Altered versions must be plainly marked as such, and must not
- *	   be misrepresented as being the original software.  Credits must
- *	   appear in the documentation.
- *
- *	4. This notice may not be removed or altered.
- */
-
-#include "cawf.h"
-#include <ctype.h>
-
-_PROTOTYPE(static void Setroman,());
-
-
-/*
- * Asmname(s, c) - assemble name
- */
-
-Asmname(s, c)
-	unsigned char *s;		/* pointer to name */
-	unsigned char *c;		/* code destination (c[3]) */
-{
-
-	c[1] = c[2] = '\0';
-	while (*s && *s == ' ')
-		s++;
-	if ((c[0] = *s) == '\0')
-		return(0);
-	return(((c[1] = s[1]) == '\0') ? 1 : 2);
-}
-
-
-/*
- * Delstr(sx) - delete string
- */
-
-void
-Delstr(sx)
-	int sx;				/* string index */
-{
-	char buf[MAXLINE];		/* message buffer */
-
-	if (sx >= Nstr) {
-		(void) sprintf(buf, " bad Delstr(%d) index", sx);
-		Error(FATAL, LINE, buf, NULL);
-	}
-	Free(&Str[sx].str);
-	while (sx < (Nstr - 1)) {
-		Str[sx] = Str[sx + 1];
-		sx++;
-	}
-	Nstr--;
-}
-
-
-/*
- * Endword() - end a word
- */
-
-void
-Endword()
-{
-	if (Fontstat != 'R')
-		Setroman();
-	Word[Wordx] = '\0';
-}
-
-
-/*
- * Findchar(nm, l, s, e) - find special character definition and
- *			   optionally enter it
- */
-
-Findchar(nm, l, s, e)
-	unsigned char *nm;		/* character name */
-	int l;				/* effective length */
-	unsigned char *s;		/* value string */
-	int e;				/* 0 = find, don't enter
-					 * 1 = don't find, enter */
-{
-	int cmp, hi, low, mid;
-	unsigned char c[3];
-
-	c[0] = nm[0];
-	c[1] = (nm[1] == ' ' || nm[1] == '\t') ? '\0' : nm[1];
-	c[2] = '\0';
-	low = mid = 0;
-	hi = Nsch - 1;
-	while (low <= hi) {
-		mid = (low + hi) / 2;
-		if ((cmp = strncmp((char *)c, (char *)Schar[mid].nm, 2)) < 0)
-			hi = mid - 1;
-		else if (cmp > 0)
-			low = mid + 1;
-		else {
-			if ( ! e)
-				return(mid);
-			Free(&Schar[mid].str);
-			goto new_char;
-		}
-	}
-	if ( ! e)
-		return(-1);
-	if (Nsch >= MAXSCH)
-		Error(FATAL, LINE, " at character table limit", NULL);
-	if (Nsch) {
-		if (cmp > 0)
-			mid++;
-		for (hi = Nsch - 1; hi >= mid; hi--)
-			Schar[hi+1] = Schar[hi];
-	}
-	Nsch++;
-	Schar[mid].nm[0] = c[0];
-	Schar[mid].nm[1] = c[1];
-
-new_char:
-
-	Schar[mid].str = Newstr(s);
-	Schar[mid].len = l;
-	return(mid);
-}
-
-
-/*
- * Findhy(s, l, e) - find and optionally enter hyphen
- */
-
-Findhy(s, l, e)
-	unsigned char *s;		/* value string */
-	int l;				/* equivalent length */
-	int e;				/* 0 = find, don't enter
-					 * 1 = enter, don't find */
-{
-	int i;
-
-	for (i = 0; i < Nhy; i++) {
-		if (Font[0] == Hychar[i].font)
-			break;
-	}
-	if (i >= Nhy) {
-		if ( ! e)
-			return(-1);
-		if (Nhy >= MAXHYCH)
-			Error(FATAL, LINE, " at hyphen limit for font ",
-				(char *)Font);
-		Hychar[i].font = Font[0];
-		Nhy++;
-	} else {
-		if ( ! e)
-			return(i);
-		Error(WARN, LINE, " duplicate hyphen for font ", (char *)Font);
-		Free(&Hychar[i].str);
-	}
-	Hychar[i].str = Newstr(s);
-	Hychar[i].len = l;
-	return(i);
-}
-
-
-/*
- * Findstr(nm, s, e) - find and  optionally enter string in Str[]
- */
-
-unsigned char *
-Findstr(nm, s, e)
-	unsigned char *nm;		/* 2 character string name */
-	unsigned char *s;		/* string value */
-	int e;				/* 0 = find, don't enter
-					 * 1 = enter, don't find */
-{
-	unsigned char c[3];		/* character buffer */
-	int cmp, hi, low, mid;		/* binary search controls */
-	int i;				/* temporary indexes */
-	unsigned char *s1, *s2;		/* temporary string pointers */
-
-	c[0] = nm[0];
-	c[1] = (nm[1] == ' ' || nm[1] == '\t') ? '\0' : nm[1];
-	c[2] = '\0';
-	low = mid = 0;
-	hi = Nstr - 1;
-	Sx = -1;
-	while (low <= hi) {
-		mid = (low + hi) / 2;
-		if ((cmp = strncmp((char *)c, (char *)Str[mid].nm, 2)) < 0)
-			hi = mid - 1;
-		else if (cmp > 0)
-			low = mid + 1;
-		else {
-			Sx = mid;
-			if ( ! e)
-				return(Str[mid].str);
-			Free(&Str[mid].str);
-			goto new_string;
-		}
-	}
-	if ( ! e)
-		return((unsigned char *)"");
-	if (Nstr >= MAXSTR)
-		Error(FATAL, LINE, " out of space for string ", (char *)c);
-	if (Nstr) {
-		if (cmp > 0)
-			mid++;
-		for (hi = Nstr - 1; hi >= mid; hi--)
-			Str[hi+1] = Str[hi];
-	}
-	Nstr++;
-	Sx = mid;
-	Str[mid].nm[0] = c[0];
-	Str[mid].nm[1] = c[1];
-
-new_string:
-
-	if (s == NULL)
-		return (Str[mid].str = Newstr((unsigned char *)""));
-	i = (*s == '"') ? 1 : 0;
-	s1 = Str[mid].str = Newstr(s + i);
-	if (i) {
-		s2 = s1 + strlen((char *)s1);
-		if (s2 > s1 && *(s2-1) == '"')
-			*(s2-1) = '\0';
-	}
-	return(s1);
-}
-
-
-/*
- * Setroman() - set Roman font
- */
-
-static void
-Setroman()
-{
-	int i;
-
-	if ((Wordx + Fstr.rl) >= MAXLINE)
-		Error(WARN, LINE, " word too long", NULL);
-	else {
-		if (Fstr.r) {
-			for (i = 0; i < Fstr.rl; i++) {
-				Word[Wordx++] = Fstr.r[i];
-			}
-	    	}
-		Fontstat = 'R';
-	}
-}
-
-
-/*
- * Str2word(s, len) - copy len characters from string to Word[]
- */
-
-Str2word(s, len)
-	unsigned char *s;
-	int len;
-{
-	int i;
-
-	for (; len > 0; len--, s++) {
-		switch (Font[0]) {
-		case 'B':
-		case 'C':
-			if (Fontctl == 0) {
-				if ((Wordx + 5) >= MAXLINE) {
-word_too_long:
-					Error(WARN, LINE, " word too long",
-						NULL);
-					return(1);
-				}
-				Word[Wordx++] = Trtbl[(int)*s];
-				Word[Wordx++] = '\b';
-				Word[Wordx++] = Trtbl[(int)*s];
-				Word[Wordx++] = '\b';
-				Word[Wordx++] = Trtbl[(int)*s];
-				break;
-			}
-			if (Fontstat != Font[0]) {
-				if (Fontstat != 'R')
-					Setroman();
-				if ((Wordx + Fstr.bl) >= MAXLINE)
-					goto word_too_long;
-				if (Fstr.b) {
-					for (i = 0; i < Fstr.bl; i++) {
-						Word[Wordx++] = Fstr.b[i];
-					}
-				}
-				Fontstat = Font[0];
-			}
-			if ((Wordx + 1) >= MAXLINE)
-				goto word_too_long;
-			Word[Wordx++] = Trtbl[(int)*s];
-			break;
-		case 'I':
-			if (isalnum(*s)) {
-				if (Fontctl == 0) {
-					if ((Wordx + 3) >= MAXLINE)
-						goto word_too_long;
-					Word[Wordx++] = '_';
-					Word[Wordx++] = '\b';
-					Word[Wordx++] = Trtbl[(int)*s];
-					break;
-				}
-				if (Fontstat != 'I') {
-					if (Fontstat != 'R')
-						Setroman();
-					if ((Wordx + Fstr.itl) >= MAXLINE)
-						goto word_too_long;
-					if (Fstr.it) {
-					    for (i = 0; i < Fstr.itl; i++) {
-						Word[Wordx++] = Fstr.it[i];
-					    }
-					}
-					Fontstat = 'I';
-				}
-				if ((Wordx + 1) >= MAXLINE)
-					goto word_too_long;
-				Word[Wordx++] = Trtbl[(int)*s];
-				break;
-			}
-			/* else fall through */
-		default:
-			if (Fontstat != 'R')
-				Setroman();
-			if ((Wordx + 1) >= MAXLINE)
-				goto word_too_long;
-			Word[Wordx++] = Trtbl[(int)*s];
-		}
-	}
-	return(0);
-}
Index: trunk/minix/commands/cron/Makefile
===================================================================
--- trunk/minix/commands/cron/Makefile	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-# Makefile for cron.
-
-CFLAGS=		-D_MINIX -D_POSIX_SOURCE
-CC = exec cc
-LDFLAGS=
-
-all:	cron crontab
-
-CRON_OBJ=	cron.o tab.o misc.o
-CRONTAB_OBJ=	crontab.o tab.o misc.o
-
-cron:	$(CRON_OBJ)
-	$(CC) $(LDFLAGS) -o $@ $(CRON_OBJ)
-	install -S 8kw $@
-
-crontab:	$(CRONTAB_OBJ)
-	$(CC) $(LDFLAGS) -o $@ $(CRONTAB_OBJ)
-	install -S 4kw $@
-
-install:	/usr/bin/cron /usr/bin/crontab
-
-/usr/bin/cron:	cron
-	install -cs $? $@
-
-/usr/bin/crontab:	crontab
-	install -cs -o root -m 4755 $? $@
-
-clean:
-	rm -f *.o cron crontab core a.out
-
-# Dependencies.
-cron.o crontab.o:	misc.h tab.h
-tab.o:			misc.h tab.h
-misc.o:			misc.h
Index: trunk/minix/commands/cron/build
===================================================================
--- trunk/minix/commands/cron/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/cron/cron.c
===================================================================
--- trunk/minix/commands/cron/cron.c	(revision 9)
+++ 	(revision )
@@ -1,465 +1,0 @@
-/*	cron 1.4 - clock daemon				Author: Kees J. Bot
- *								7 Dec 1996
- */
-
-#define _MINIX_SOURCE
-#define _MINIX 1
-
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <limits.h>
-#include <dirent.h>
-#include <time.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <grp.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include "misc.h"
-#include "tab.h"
-
-#if __minix && !__minix_vmd
-#define initgroups(name, gid)	(0)
-#endif
-
-static volatile int busy;	/* Set when something is afoot, don't sleep! */
-static volatile int need_reload;/* Set if table reload required. */
-static volatile int need_quit;	/* Set if cron must exit. */
-static volatile int debug;	/* Debug level. */
-
-static void run_job(cronjob_t *job)
-/* Execute a cron job.  Register its pid in the job structure.  If a job's
- * crontab has an owner then its output is mailed to that owner, otherwise
- * no special provisions are made, so the output will go where cron's output
- * goes.  This keeps root's mailbox from filling up.
- */
-{
-	pid_t pid;
-	int need_mailer;
-	int mailfd[2], errfd[2];
-	struct passwd *pw;
-	crontab_t *tab= job->tab;
-
-	need_mailer= (tab->user != nil);
-
-	if (job->atjob) {
-		struct stat st;
-
-		need_mailer= 1;
-		if (rename(tab->file, tab->data) < 0) {
-			if (errno == ENOENT) {
-				/* Normal error, job deleted. */
-				need_reload= 1;
-			} else {
-				/* Bad error, halt processing AT jobs. */
-				log(LOG_CRIT, "Can't rename %s: %s\n",
-					tab->file, strerror(errno));
-				tab_reschedule(job);
-			}
-			return;
-		}
-		/* Will need to determine the next AT job. */
-		need_reload= 1;
-
-		if (stat(tab->data, &st) < 0) {
-			log(LOG_ERR, "Can't stat %s: %s\n",
-						tab->data, strerror(errno));
-			tab_reschedule(job);
-			return;
-		}
-		if ((pw= getpwuid(st.st_uid)) == nil) {
-			log(LOG_ERR, "Unknown owner for uid %lu of AT job %s\n",
-				(unsigned long) st.st_uid, job->cmd);
-			tab_reschedule(job);
-			return;
-		}
-	} else {
-		pw= nil;
-		if (job->user != nil && (pw= getpwnam(job->user)) == nil) {
-			log(LOG_ERR, "%s: Unknown user\n", job->user);
-			tab_reschedule(job);
-			return;
-		}
-	}
-
-	if (need_mailer) {
-		errfd[0]= -1;
-		if (pipe(errfd) < 0 || pipe(mailfd) < 0) {
-			log(LOG_ERR, "pipe() call failed: %s\n",
-							strerror(errno));
-			if (errfd[0] != -1) {
-				close(errfd[0]);
-				close(errfd[1]);
-			}
-			tab_reschedule(job);
-			return;
-		}
-		(void) fcntl(errfd[1], F_SETFD,
-				fcntl(errfd[1], F_GETFD) | FD_CLOEXEC);
-
-		if ((pid= fork()) == -1) {
-			log(LOG_ERR, "fork() call failed: %s\n",
-							strerror(errno));
-			close(errfd[0]);
-			close(errfd[1]);
-			close(mailfd[0]);
-			close(mailfd[1]);
-			tab_reschedule(job);
-			return;
-		}
-
-		if (pid == 0) {
-			/* Child that is to be the mailer. */
-			char subject[70+20], *ps;
-
-			close(errfd[0]);
-			close(mailfd[1]);
-			if (mailfd[0] != 0) {
-				dup2(mailfd[0], 0);
-				close(mailfd[0]);
-			}
-
-			memset(subject, 0, sizeof(subject));
-			sprintf(subject,
-				"Output from your %s job: %.50s",
-				job->atjob ? "AT" : "cron",
-				job->cmd);
-			if (subject[70] != 0) {
-				strcpy(subject+70-3, "...");
-			}
-			for (ps= subject; *ps != 0; ps++) {
-				if (*ps == '\n') *ps= '%';
-			}
-
-			execl("/usr/bin/mail", "mail", "-s", subject,
-						pw->pw_name, (char *) nil);
-			write(errfd[1], &errno, sizeof(errno));
-			_exit(1);
-		}
-
-		close(mailfd[0]);
-		close(errfd[1]);
-		if (read(errfd[0], &errno, sizeof(errno)) > 0) {
-			log(LOG_ERR, "can't execute /usr/bin/mail: %s\n",
-							strerror(errno));
-			close(errfd[0]);
-			close(mailfd[1]);
-			tab_reschedule(job);
-			return;
-		}
-		close(errfd[0]);
-	}
-
-	if (pipe(errfd) < 0) {
-		log(LOG_ERR, "pipe() call failed: %s\n", strerror(errno));
-		if (need_mailer) close(mailfd[1]);
-		tab_reschedule(job);
-		return;
-	}
-	(void) fcntl(errfd[1], F_SETFD, fcntl(errfd[1], F_GETFD) | FD_CLOEXEC);
-
-	if ((pid= fork()) == -1) {
-		log(LOG_ERR, "fork() call failed: %s\n", strerror(errno));
-		close(errfd[0]);
-		close(errfd[1]);
-		if (need_mailer) close(mailfd[1]);
-		tab_reschedule(job);
-		return;
-	}
-
-	if (pid == 0) {
-		/* Child that is to be the cron job. */
-		close(errfd[0]);
-		if (need_mailer) {
-			if (mailfd[1] != 1) {
-				dup2(mailfd[1], 1);
-				close(mailfd[1]);
-			}
-			dup2(1, 2);
-		}
-
-		if (pw != nil) {
-			/* Change id to the owner of the job. */
-			initgroups(pw->pw_name, pw->pw_gid);
-			setgid(pw->pw_gid);
-			setuid(pw->pw_uid);
-			chdir(pw->pw_dir);
-			if (setenv("USER", pw->pw_name, 1) < 0) goto bad;
-			if (setenv("LOGNAME", pw->pw_name, 1) < 0) goto bad;
-			if (setenv("HOME", pw->pw_dir, 1) < 0) goto bad;
-			if (setenv("SHELL", pw->pw_shell[0] == 0 ? "/bin/sh"
-						: pw->pw_shell, 1) < 0) goto bad;
-		}
-
-		if (job->atjob) {
-			execl("/bin/sh", "sh", tab->data, (char *) nil);
-		} else {
-			execl("/bin/sh", "sh", "-c", job->cmd, (char *) nil);
-		}
-	    bad:
-		write(errfd[1], &errno, sizeof(errno));
-		_exit(1);
-	}
-
-	if (need_mailer) close(mailfd[1]);
-	close(errfd[1]);
-	if (read(errfd[0], &errno, sizeof(errno)) > 0) {
-		log(LOG_ERR, "can't execute /bin/sh: %s\n", strerror(errno));
-		close(errfd[0]);
-		tab_reschedule(job);
-		return;
-	}
-	close(errfd[0]);
-	job->pid= pid;
-	if (debug >= 1) fprintf(stderr, "executing >%s<, pid = %ld\n",
-						job->cmd, (long) job->pid);
-}
-
-static void load_crontabs(void)
-/* Load all the crontabs we like to run.  We didn't bother to make a list in
- * an array or something, this is too system specific to make nice.
- */
-{
-	DIR *spool;
-#if __minix_vmd
-	FILE *pkgs;
-#endif
-
-	tab_parse("/usr/lib/crontab", nil);
-	tab_parse("/usr/local/lib/crontab", nil);
-	tab_parse("/var/lib/crontab", nil);
-
-#if __minix_vmd
-	if ((pkgs= fopen("/usr/lib/packages", "r")) != nil) {
-		char name[NAME_MAX+1];
-		char *np;
-		int c;
-		char tab[sizeof("/var/opt//lib/crontab") + NAME_MAX];
-
-		while ((c= fgetc(pkgs)) != EOF) {
-			np= name;
-			while (c != EOF && c != '/' && c != '\n') {
-				if (np < name+NAME_MAX) *np++ = c;
-				c= fgetc(pkgs);
-			}
-			*np= 0;
-			while (c != EOF && c != '\n') c= fgetc(pkgs);
-
-			if (name[0] == 0) continue;	/* ? */
-
-			strcpy(tab, "/var/opt/");
-			strcat(tab, name);
-			strcat(tab, "/lib/crontab");
-			tab_parse(tab, nil);
-		}
-		if (ferror(pkgs)) {
-			log(LOG_CRIT, "/usr/lib/packages: %s\n",
-							strerror(errno));
-		}
-		fclose(pkgs);
-	} else {
-		if (errno != ENOENT) {
-			log(LOG_ERR, "/usr/lib/packages: %s\n",
-							strerror(errno));
-		}
-	}
-#endif /* Minix-vmd */
-
-	if ((spool= opendir("/usr/spool/crontabs")) != nil) {
-		struct dirent *entry;
-		char tab[sizeof("/usr/spool/crontabs/") + NAME_MAX];
-
-		while ((entry= readdir(spool)) != nil) {
-			if (entry->d_name[0] == '.') continue;
-
-			strcpy(tab, "/usr/spool/crontabs/");
-			strcat(tab, entry->d_name);
-			tab_parse(tab, entry->d_name);
-		}
-		closedir(spool);
-	}
-
-	/* Find the first to be executed AT job. */
-	tab_find_atjob("/usr/spool/at");
-
-	tab_purge();
-	if (debug >= 2) {
-		tab_print(stderr);
-		fprintf(stderr, "%lu memory chunks in use\n",
-			(unsigned long) alloc_count);
-	}
-}
-
-static void handler(int sig)
-{
-	switch (sig) {
-	case SIGHUP:
-		need_reload= 1;
-		break;
-	case SIGINT:
-	case SIGTERM:
-		need_quit= 1;
-		break;
-	case SIGUSR1:
-		debug++;
-		break;
-	case SIGUSR2:
-		debug= 0;
-		break;
-	}
-	alarm(1);	/* A signal may come just before a blocking call. */
-	busy= 1;
-}
-
-static void usage(void)
-{
-	fprintf(stderr, "Usage: %s [-d[#]]\n", prog_name);
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	int i;
-	struct sigaction sa, osa;
-	FILE *pf;
-	int r;
-
-	prog_name= strrchr(argv[0], '/');
-	if (prog_name == nil) prog_name= argv[0]; else prog_name++;
-
-	i= 1;
-	while (i < argc && argv[i][0] == '-') {
-		char *opt= argv[i++] + 1;
-
-		if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-		while (*opt != 0) switch (*opt++) {
-		case 'd':
-			if (*opt == 0) {
-				debug= 1;
-			} else {
-				debug= strtoul(opt, &opt, 10);
-				if (*opt != 0) usage();
-			}
-			break;
-		default:
-			usage();
-		}
-	}
-	if (i != argc) usage();
-
-	selectlog(SYSLOG);
-	openlog(prog_name, LOG_PID, LOG_DAEMON);
-	setlogmask(LOG_UPTO(LOG_INFO));
-
-	/* Save process id. */
-	if ((pf= fopen(PIDFILE, "w")) == NULL) {
-		fprintf(stderr, "%s: %s\n", PIDFILE, strerror(errno));
-		exit(1);
-	}
-	fprintf(pf, "%d\n", getpid());
-	if (ferror(pf) || fclose(pf) == EOF) {
-		fprintf(stderr, "%s: %s\n", PIDFILE, strerror(errno));
-		exit(1);
-	}
-
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags= 0;
-	sa.sa_handler= handler;
-
-	/* Hangup: Reload crontab files. */
-	sigaction(SIGHUP, &sa, nil);
-
-	/* User signal 1 & 2: Raise or reset debug level. */
-	sigaction(SIGUSR1, &sa, nil);
-	sigaction(SIGUSR2, &sa, nil);
-
-	/* Interrupt and Terminate: Cleanup and exit. */
-	if (sigaction(SIGINT, nil, &osa) == 0 && osa.sa_handler != SIG_IGN) {
-		sigaction(SIGINT, &sa, nil);
-	}
-	if (sigaction(SIGTERM, nil, &osa) == 0 && osa.sa_handler != SIG_IGN) {
-		sigaction(SIGTERM, &sa, nil);
-	}
-
-	/* Alarm: Wake up and run a job. */
-	sigaction(SIGALRM, &sa, nil);
-
-	/* Initialize current time and time next to do something. */
-	time(&now);
-	next= NEVER;
-
-	/* Table load required first time. */
-	need_reload= 1;
-
-	do {
-		if (need_reload) {
-			need_reload= 0;
-			load_crontabs();
-			busy= 1;
-		}
-
-		/* Run jobs whose time has come. */
-		if (next <= now) {
-			cronjob_t *job;
-
-			if ((job= tab_nextjob()) != nil) run_job(job);
-			busy= 1;
-		}
-
-		if (busy) {
-			/* Did a job finish? */
-			r= waitpid(-1, nil, WNOHANG);
-			busy= 0;
-		} else {
-			/* Sleep until the next job must be started. */
-			if (next == NEVER) {
-				alarm(0);
-			} else {
-#if __minix_vmd
-				struct timeval tvnext;
-
-				tvnext.tv_sec= next;
-				tvnext.tv_usec= 0;
-				sysutime(UTIME_SETALARM, &tvnext);
-#else
-				alarm((next - now) > INT_MAX
-						? INT_MAX : (next - now));
-#endif
-			}
-			if (debug >= 1) fprintf(stderr, "%s: sleep until %s",
-						prog_name, ctime(&next));
-
-			closelog();	/* Don't keep resources open. */
-
-			/* Wait for a job to exit or a timeout. */
-			r= waitpid(-1, nil, 0);
-			if (r == -1 && errno == ECHILD) pause();
-			alarm(0);
-			time(&now);
-		}
-
-		if (r > 0) {
-			/* A job has finished, reschedule it. */
-			if (debug >= 1) fprintf(stderr, "pid %d has exited\n",
-									r);
-			tab_reap_job((pid_t) r);
-			busy= 1;
-		}
-	} while (!need_quit);
-
-	/* Remove the pid file to signal that cron is gone. */
-	unlink(PIDFILE);
-
-	return 0;
-}
-
-/*
- * $PchId: cron.c,v 1.4 2000/07/17 19:00:35 philip Exp $
- */
Index: trunk/minix/commands/cron/crontab.c
===================================================================
--- trunk/minix/commands/cron/crontab.c	(revision 9)
+++ 	(revision )
@@ -1,258 +1,0 @@
-/*	crontab 1.2 - user crontab manipulation		Author: Kees J. Bot
- *								12 Jan 1997
- */
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <sys/stat.h>
-#include "misc.h"
-#include "tab.h"
-
-#if __minix && !__minix_vmd
-#define seteuid(uid)	((uid),0)	/* Minix can't fiddle with uids. */
-#endif
-
-static int opentab(int uid, char *file, int how)
-/* Open a crontab file under the given uid.  How is 'r' or 'w'.  Return
- * the result of open(2).
- */
-{
-	uid_t safe_uid;
-	int flags, r, err;
-
-	switch (how) {
-	case 'r':	flags= O_RDONLY;			break;
-	case 'w':	flags= O_WRONLY | O_CREAT | O_TRUNC;	break;
-	default:	errno= EINVAL;				return -1;
-	}
-
-#if __minix && !__minix_vmd
-	/* Standard Minix has no saved uid, so use the lousy old access(). */
-	if (uid != 0) {
-		if (access(file, how == 'r' ? R_OK : W_OK) < 0) return -1;
-	}
-#endif
-
-	safe_uid= geteuid();
-	seteuid(uid);
-	r= open(file, flags, 0666);
-	err= errno;
-	seteuid(safe_uid);
-	errno= err;
-	return r;
-}
-
-static void copytab(int fd_in, char *file_in, int fd_out, char *file_out)
-/* Copy one open file to another.  Complain and exit on errors. */
-{
-	ssize_t r, w;
-	char buf[1024];
-
-	while ((r= read(fd_in, buf, sizeof(buf))) > 0) {
-		w= 0;
-		while (w < r) {
-			if ((r= write(fd_out, buf+w, r-w)) <= 0) {
-				fprintf(stderr,
-				"%s: Write error on %s: %s\n",
-					prog_name,
-					file_out,
-					r == 0 ? "End of file"
-							: strerror(errno));
-				exit(1);
-			}
-			w+= r;
-		}
-	}
-	if (r < 0) {
-		fprintf(stderr, "%s: Read error on %s: %s\n",
-			prog_name, file_in, strerror(errno));
-		exit(1);
-	}
-}
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Usage: %s -c [user] file  # Change crontab\n"
-		"       %s -l [user]       # List crontab\n"
-		"       %s -r [user]       # Remove crontab\n"
-		"       %s -p              # Tell cron to reload\n",
-		prog_name, prog_name, prog_name, prog_name);
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	int i;
-	int cflag, lflag, rflag, pflag;
-	uid_t uid;
-	char *user, *file;
-	struct passwd *pw;
-	static char SPOOLDIR[]= "/usr/spool/crontabs";
-	char tabfile[sizeof(SPOOLDIR) + NAME_MAX];
-
-	prog_name= strrchr(argv[0], '/');
-	if (prog_name == nil) prog_name= argv[0]; else prog_name++;
-
-	cflag= lflag= rflag= pflag= 0;
-	i= 1;
-	while (i < argc && argv[i][0] == '-') {
-		char *opt= argv[i++] + 1;
-
-		if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-		while (*opt != 0) switch (*opt++) {
-		case 'c':	cflag= 1;	break;
-		case 'l':	lflag= 1;	break;
-		case 'r':	rflag= 1;	break;
-		case 'p':	pflag= 1;	break;
-		default:	usage();
-		}
-	}
-	if (cflag + lflag + rflag + pflag != 1) usage();
-
-	user= file= nil;
-	if (!pflag && i < argc) user= argv[i++];
-	if (cflag) {
-		if (user == nil) usage();
-		if (i < argc) {
-			file= argv[i++];
-		} else {
-			file= user;
-			user= nil;
-		}
-	}
-	if (i != argc) usage();
-
-	if (geteuid() != 0) {
-		fprintf(stderr, "%s: No root privileges?\n", prog_name);
-	}
-	uid= getuid();
-	if (user == nil) {
-		if ((pw= getpwuid(uid)) == nil) {
-			fprintf(stderr,
-				"%s: Don't know who you (uid %lu) are!\n",
-				prog_name, (unsigned long) uid);
-			exit(1);
-		}
-	} else {
-		if ((pw= getpwnam(user)) == nil) {
-			fprintf(stderr,
-				"%s: Don't know who you (%s) are!\n",
-				prog_name, user);
-			exit(1);
-		}
-	}
-	if (uid != 0 && pw->pw_uid != uid) {
-		fprintf(stderr,
-		"%s: Only root can change the crontabs of others!\n",
-			prog_name);
-		exit(1);
-	}
-	user= pw->pw_name;
-	uid= pw->pw_uid;
-	seteuid(uid);
-	umask(0077);
-
-	selectlog(STDERR);
-	sprintf(tabfile, "%s/%s", SPOOLDIR, user);
-
-	if (lflag) {
-		int fd;
-
-		if ((fd= opentab(0, tabfile, 'r')) < 0) {
-			fprintf(stderr, "%s: Can't open %s: %s\n",
-				prog_name, tabfile, strerror(errno));
-			exit(1);
-		}
-		copytab(fd, tabfile, 1, "stdout");
-		close(fd);
-	}
-
-	if (rflag) {
-		seteuid(0);
-		if (unlink(tabfile) < 0) {
-			fprintf(stderr, "%s: Can't remove %s: %s\n",
-				prog_name, tabfile, strerror(errno));
-			exit(1);
-		}
-		seteuid(uid);
-		printf("Crontab of %s removed\n", user);
-		pflag= 1;
-	}
-
-	/* Initialize current Time */
-	time(&now);
-
-	if (cflag) {
-		int fd1, fd2;
-
-		if ((fd1= opentab(uid, file, 'r')) < 0) {
-			fprintf(stderr, "%s: Can't open %s: %s\n",
-				prog_name, file, strerror(errno));
-			exit(1);
-		}
-
-		/* Try to parse the new crontab file.  If the parsing
-		 * succeeds then 'crontabs' will be non-null.
-		 */
-		tab_parse(file, user);
-		tab_purge();
-		if (crontabs == nil) exit(1);
-
-		if ((fd2= opentab(0, tabfile, 'w')) < 0) {
-			fprintf(stderr, "%s: Can't open %s: %s\n",
-				prog_name, tabfile, strerror(errno));
-			exit(1);
-		}
-		copytab(fd1, file, fd2, tabfile);
-		close(fd1);
-		close(fd2);
-		printf("New crontab for %s installed\n", user);
-		pflag= 1;
-	}
-
-	if (pflag) {
-		/* Alert cron to the new situation. */
-		FILE *fp;
-
-		seteuid(0);
-		if ((fp= fopen(PIDFILE, "r")) != NULL) {
-			unsigned long pid;
-			int c;
-
-			pid= 0;
-			while ((c= fgetc(fp)) != EOF && c != '\n') {
-				if ((unsigned) (c - '0') >= 10) {
-					pid= 0; break;
-				}
-				pid= 10*pid + (c - '0');
-				if (pid >= 30000) { pid= 0; break; }
-			}
-			if (pid > 1 && kill((pid_t) pid, SIGHUP) == 0) {
-				pflag= 0;
-			}
-		}
-		seteuid(uid);
-		if (pflag) {
-			fprintf(stderr,
-			"%s: Alerting cron has failed; cron still running?\n",
-				prog_name);
-			exit(1);
-		}
-		printf("Cron signalled to reload tables\n");
-	}
-	return 0;
-}
-
-/*
- * $PchId: crontab.c,v 1.4 2000/07/17 18:54:50 philip Exp $
- */
Index: trunk/minix/commands/cron/misc.c
===================================================================
--- trunk/minix/commands/cron/misc.c	(revision 9)
+++ 	(revision )
@@ -1,68 +1,0 @@
-/*	misc.c - Miscellaneous stuff for cron		Author: Kees J. Bot
- *								12 Jan 1997
- */
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <time.h>
-#include "misc.h"
-
-char *prog_name;		/* Name of this program. */
-time_t now;			/* Cron's idea of the current time. */
-time_t next;			/* Time to run the next job. */
-
-size_t alloc_count;		/* # Of chunks of memory allocated. */
-
-void *allocate(size_t len)
-/* Checked malloc().  Better not feed it length 0. */
-{
-	void *mem;
-
-	if ((mem= malloc(len)) == nil) {
-		log(LOG_ALERT, "Out of memory, exiting\n");
-		exit(1);
-	}
-	alloc_count++;
-	return mem;
-}
-
-void deallocate(void *mem)
-{
-	if (mem != nil) {
-		free(mem);
-		alloc_count--;
-	}
-}
-
-static enum logto logto= SYSLOG;
-
-void selectlog(enum logto where)
-/* Select where logging output should go, syslog or stdout. */
-{
-	logto= where;
-}
-
-void log(int level, const char *fmt, ...)
-/* Like syslog(), but may go to stderr. */
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-
-#if __minix_vmd || !__minix
-	if (logto == SYSLOG) {
-		vsyslog(level, fmt, ap);
-	} else
-#endif
-	{
-		fprintf(stderr, "%s: ", prog_name);
-		vfprintf(stderr, fmt, ap);
-	}
-	va_end(ap);
-}
-
-/*
- * $PchId: misc.c,v 1.3 2000/07/17 19:01:57 philip Exp $
- */
Index: trunk/minix/commands/cron/misc.h
===================================================================
--- trunk/minix/commands/cron/misc.h	(revision 9)
+++ 	(revision )
@@ -1,42 +1,0 @@
-/*	misc.h - miscellaneous stuff			Author: Kees J. Bot
- *								7 Dec 1996
- */
-#ifndef MISC__H
-#define MISC__H
-
-#include <time.h>
-
-/* The name of the program. */
-extern char *prog_name;
-
-/* Where cron stores it pid. */
-#define PIDFILE	"/usr/run/cron.pid"
-
-/* Cron's idea of the current time, and the time next to run something. */
-extern time_t now;
-extern time_t next;
-
-/* Memory allocation. */
-void *allocate(size_t len);
-void deallocate(void *mem);
-extern size_t alloc_count;
-
-/* Logging, by syslog or to stderr. */
-#if __minix_vmd || !__minix
-#include <sys/syslog.h>
-#else
-enum log_dummy { LOG_ERR, LOG_CRIT, LOG_ALERT };
-#define openlog(ident, opt, facility)	((void) 0)
-#define closelog()			((void) 0)
-#define setlogmask(mask)		(0)
-#endif
-
-enum logto { SYSLOG, STDERR };
-void selectlog(enum logto where);
-void log(int level, const char *fmt, ...);
-
-#endif /* MISC__H */
-
-/*
- * $PchId: misc.h,v 1.3 2000/07/17 18:56:02 philip Exp $
- */
Index: trunk/minix/commands/cron/tab.c
===================================================================
--- trunk/minix/commands/cron/tab.c	(revision 9)
+++ 	(revision )
@@ -1,816 +1,0 @@
-/*	tab.c - process crontabs and create in-core crontab data
- *							Author: Kees J. Bot
- *								7 Dec 1996
- * Changes:
- * 17 Jul 2000 by Philip Homburg
- *	- Tab_reschedule() rewritten (and fixed).
- */
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-#include <time.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include "misc.h"
-#include "tab.h"
-
-static int nextbit(bitmap_t map, int bit)
-/* Return the next bit set in 'map' from 'bit' onwards, cyclic. */
-{
-	for (;;) {
-		bit= (bit+1) & 63;
-		if (bit_isset(map, bit)) break;
-	}
-	return bit;
-}
-
-void tab_reschedule(cronjob_t *job)
-/* Reschedule one job.  Compute the next time to run the job in job->rtime.
- */
-{
-	struct tm prevtm, nexttm, tmptm;
-	time_t nodst_rtime, dst_rtime;
-
-	/* AT jobs are only run once. */
-	if (job->atjob) { job->rtime= NEVER; return; }
-
-	/* Was the job scheduled late last time? */
-	if (job->late) job->rtime= now;
-
-	prevtm= *localtime(&job->rtime);
-	prevtm.tm_sec= 0;
-
-	nexttm= prevtm;
-	nexttm.tm_min++;	/* Minimal increment */
-
-	for (;;)
-	{
-		if (nexttm.tm_min > 59)
-		{
-			nexttm.tm_min= 0;
-			nexttm.tm_hour++;
-		}
-		if (nexttm.tm_hour > 23)
-		{
-			nexttm.tm_min= 0;
-			nexttm.tm_hour= 0;
-			nexttm.tm_mday++;
-		}
-		if (nexttm.tm_mday > 31)
-		{
-			nexttm.tm_hour= nexttm.tm_min= 0;
-			nexttm.tm_mday= 1;
-			nexttm.tm_mon++;
-		}
-		if (nexttm.tm_mon >= 12)
-		{
-			nexttm.tm_hour= nexttm.tm_min= 0;
-			nexttm.tm_mday= 1;
-			nexttm.tm_mon= 0;
-			nexttm.tm_year++;
-		}
-
-		/* Verify tm_year. A crontab entry cannot restrict tm_year
-		 * directly. However, certain dates (such as Feb, 29th) do
-		 * not occur every year. We limit the difference between
-		 * nexttm.tm_year and prevtm.tm_year to detect impossible dates
-		 * (e.g, Feb, 31st). In theory every date occurs within a
-		 * period of 4 years. However, some years at the end of a 
-		 * century are not leap years (e.g, the year 2100). An extra
-		 * factor of 2 should be enough.
-		 */
-		if (nexttm.tm_year-prevtm.tm_year > 2*4)
-		{
-			job->rtime= NEVER;
-			return;			/* Impossible combination */
-		}
-
-		if (!job->do_wday)
-		{
-			/* Verify the mon and mday fields. If do_wday and
-			 * do_mday are both true we have to merge both
-			 * schedules. This is done after the call to mktime.
-			 */
-			if (!bit_isset(job->mon, nexttm.tm_mon))
-			{
-				/* Clear other fields */
-				nexttm.tm_mday= 1;
-				nexttm.tm_hour= nexttm.tm_min= 0;
-
-				nexttm.tm_mon++;
-				continue;
-			}
-
-			/* Verify mday */
-			if (!bit_isset(job->mday, nexttm.tm_mday))
-			{
-				/* Clear other fields */
-				nexttm.tm_hour= nexttm.tm_min= 0;
-
-				nexttm.tm_mday++;
-				continue;
-			}
-		}
-
-		/* Verify hour */
-		if (!bit_isset(job->hour, nexttm.tm_hour))
-		{
-			/* Clear tm_min field */
-			nexttm.tm_min= 0;
-
-			nexttm.tm_hour++;
-			continue;
-		}
-
-		/* Verify min */
-		if (!bit_isset(job->min, nexttm.tm_min))
-		{
-			nexttm.tm_min++;
-			continue;
-		}
-
-		/* Verify that we don't have any problem with DST. Try
-		 * tm_isdst=0 first. */
-		tmptm= nexttm;
-		tmptm.tm_isdst= 0;
-#if 0
-		fprintf(stderr, 
-	"tab_reschedule: trying %04d-%02d-%02d %02d:%02d:%02d isdst=0\n",
-				1900+nexttm.tm_year, nexttm.tm_mon+1,
-				nexttm.tm_mday, nexttm.tm_hour,
-				nexttm.tm_min, nexttm.tm_sec);
-#endif
-		nodst_rtime= job->rtime= mktime(&tmptm);
-		if (job->rtime == -1) {
-			/* This should not happen. */
-			log(LOG_ERR,
-			"mktime failed for %04d-%02d-%02d %02d:%02d:%02d",
-				1900+nexttm.tm_year, nexttm.tm_mon+1,
-				nexttm.tm_mday, nexttm.tm_hour,
-				nexttm.tm_min, nexttm.tm_sec);
-			job->rtime= NEVER;
-			return;	
-		}
-		tmptm= *localtime(&job->rtime);
-		if (tmptm.tm_hour != nexttm.tm_hour ||
-			tmptm.tm_min != nexttm.tm_min)
-		{
-			assert(tmptm.tm_isdst);
-			tmptm= nexttm;
-			tmptm.tm_isdst= 1;
-#if 0
-			fprintf(stderr, 
-	"tab_reschedule: trying %04d-%02d-%02d %02d:%02d:%02d isdst=1\n",
-				1900+nexttm.tm_year, nexttm.tm_mon+1,
-				nexttm.tm_mday, nexttm.tm_hour,
-				nexttm.tm_min, nexttm.tm_sec);
-#endif
-			dst_rtime= job->rtime= mktime(&tmptm);
-			if (job->rtime == -1) {
-				/* This should not happen. */
-				log(LOG_ERR,
-			"mktime failed for %04d-%02d-%02d %02d:%02d:%02d\n",
-					1900+nexttm.tm_year, nexttm.tm_mon+1,
-					nexttm.tm_mday, nexttm.tm_hour,
-					nexttm.tm_min, nexttm.tm_sec);
-				job->rtime= NEVER;
-				return;	
-			}
-			tmptm= *localtime(&job->rtime);
-			if (tmptm.tm_hour != nexttm.tm_hour ||
-				tmptm.tm_min != nexttm.tm_min)
-			{
-				assert(!tmptm.tm_isdst);
-				/* We have a problem. This time neither
-				 * exists with DST nor without DST.
-				 * Use the latest time, which should be
-				 * nodst_rtime.
-				 */
-				assert(nodst_rtime > dst_rtime);
-				job->rtime= nodst_rtime;
-#if 0
-				fprintf(stderr,
-			"During DST trans. %04d-%02d-%02d %02d:%02d:%02d\n",
-					1900+nexttm.tm_year, nexttm.tm_mon+1,
-					nexttm.tm_mday, nexttm.tm_hour,
-					nexttm.tm_min, nexttm.tm_sec);
-#endif
-			}
-		}
-
-		/* Verify this the combination (tm_year, tm_mon, tm_mday). */
-		if (tmptm.tm_mday != nexttm.tm_mday ||
-			tmptm.tm_mon != nexttm.tm_mon ||
-			tmptm.tm_year != nexttm.tm_year)
-		{
-			/* Wrong day */
-#if 0
-			fprintf(stderr, "Wrong day\n");
-#endif
-			nexttm.tm_hour= nexttm.tm_min= 0;
-			nexttm.tm_mday++;
-			continue;
-		}
-
-		/* Check tm_wday */
-		if (job->do_wday && bit_isset(job->wday, tmptm.tm_wday))
-		{
-			/* OK, wday matched */
-			break;
-		}
-
-		/* Check tm_mday */
-		if (job->do_mday && bit_isset(job->mon, tmptm.tm_mon) &&
-			bit_isset(job->mday, tmptm.tm_mday))
-		{
-			/* OK, mon and mday matched */
-			break;
-		}
-
-		if (!job->do_wday && !job->do_mday)
-		{
-			/* No need to match wday and mday */
-			break;
-		}
-
-		/* Wrong day */
-#if 0
-		fprintf(stderr, "Wrong mon+mday or wday\n");
-#endif
-		nexttm.tm_hour= nexttm.tm_min= 0;
-		nexttm.tm_mday++;
-	}
-#if 0
-	fprintf(stderr, "Using %04d-%02d-%02d %02d:%02d:%02d \n",
-		1900+nexttm.tm_year, nexttm.tm_mon+1, nexttm.tm_mday,
-		nexttm.tm_hour, nexttm.tm_min, nexttm.tm_sec);
-	tmptm= *localtime(&job->rtime);
-	fprintf(stderr, "Act. %04d-%02d-%02d %02d:%02d:%02d isdst=%d\n",
-		1900+tmptm.tm_year, tmptm.tm_mon+1, tmptm.tm_mday,
-		tmptm.tm_hour, tmptm.tm_min, tmptm.tm_sec,
-		tmptm.tm_isdst);
-#endif
-
-
-	/* Is job issuing lagging behind with the progress of time? */
-	job->late= (job->rtime < now);
-
-  	/* The result is in job->rtime. */
-  	if (job->rtime < next) next= job->rtime;
-}
-
-#define isdigit(c)	((unsigned) ((c) - '0') < 10)
-
-static char *get_token(char **ptr)
-/* Return a pointer to the next token in a string.  Move *ptr to the end of
- * the token, and return a pointer to the start.  If *ptr == start of token
- * then we're stuck against a newline or end of string.
- */
-{
-	char *start, *p;
-
-	p= *ptr;
-	while (*p == ' ' || *p == '\t') p++;
-
-	start= p;
-	while (*p != ' ' && *p != '\t' && *p != '\n' && *p != 0) p++;
-	*ptr= p;
-	return start;
-}
-
-static int range_parse(char *file, char *data, bitmap_t map,
-	int min, int max, int *wildcard)
-/* Parse a comma separated series of 'n', 'n-m' or 'n:m' numbers.  'n'
- * includes number 'n' in the bit map, 'n-m' includes all numbers between
- * 'n' and 'm' inclusive, and 'n:m' includes 'n+k*m' for any k if in range.
- * Numbers must fall between 'min' and 'max'.  A '*' means all numbers.  A
- * '?' is allowed as a synonym for the current minute, which only makes sense
- * in the minute field, i.e. max must be 59.  Return true iff parsed ok.
- */
-{
-	char *p;
-	int end;
-	int n, m;
-
-	/* Clear all bits. */
-	for (n= 0; n < 8; n++) map[n]= 0;
-
-	p= data;
-	while (*p != ' ' && *p != '\t' && *p != '\n' && *p != 0) p++;
-	end= *p;
-	*p= 0;
-	p= data;
-
-	if (*p == 0) {
-		log(LOG_ERR, "%s: not enough time fields\n", file);
-		return 0;
-	}
-
-	/* Is it a '*'? */
-	if (p[0] == '*' && p[1] == 0) {
-		for (n= min; n <= max; n++) bit_set(map, n);
-		p[1]= end;
-		*wildcard= 1;
-		return 1;
-	}
-	*wildcard= 0;
-
-	/* Parse a comma separated series of numbers or ranges. */
-	for (;;) {
-		if (*p == '?' && max == 59 && p[1] != '-') {
-			n= localtime(&now)->tm_min;
-			p++;
-		} else {
-			if (!isdigit(*p)) goto syntax;
-			n= 0;
-			do {
-				n= 10 * n + (*p++ - '0');
-				if (n > max) goto range;
-			} while (isdigit(*p));
-		}
-		if (n < min) goto range;
-
-		if (*p == '-') {	/* A range of the form 'n-m'? */
-			p++;
-			if (!isdigit(*p)) goto syntax;
-			m= 0;
-			do {
-				m= 10 * m + (*p++ - '0');
-				if (m > max) goto range;
-			} while (isdigit(*p));
-			if (m < n) goto range;
-			do {
-				bit_set(map, n);
-			} while (++n <= m);
-		} else
-		if (*p == ':') {	/* A repeat of the form 'n:m'? */
-			p++;
-			if (!isdigit(*p)) goto syntax;
-			m= 0;
-			do {
-				m= 10 * m + (*p++ - '0');
-				if (m > (max-min+1)) goto range;
-			} while (isdigit(*p));
-			if (m == 0) goto range;
-			while (n >= min) n-= m;
-			while ((n+= m) <= max) bit_set(map, n);
-		} else {
-					/* Simply a number */
-			bit_set(map, n);
-		}
-		if (*p == 0) break;
-		if (*p++ != ',') goto syntax;
-	}
-	*p= end;
-	return 1;
-  syntax:
-	log(LOG_ERR, "%s: field '%s': bad syntax for a %d-%d time field\n",
-		file, data, min, max);
-	return 0;
-  range:
-	log(LOG_ERR, "%s: field '%s': values out of the %d-%d allowed range\n",
-		file, data, min, max);
-	return 0;
-}
-
-void tab_parse(char *file, char *user)
-/* Parse a crontab file and add its data to the tables.  Handle errors by
- * yourself.  Table is owned by 'user' if non-null.
- */
-{
-	crontab_t **atab, *tab;
-	cronjob_t **ajob, *job;
-	int fd;
-	struct stat st;
-	char *p, *q;
-	size_t n;
-	ssize_t r;
-	int ok, wc;
-
-	for (atab= &crontabs; (tab= *atab) != nil; atab= &tab->next) {
-		if (strcmp(file, tab->file) == 0) break;
-	}
-
-	/* Try to open the file. */
-	if ((fd= open(file, O_RDONLY)) < 0 || fstat(fd, &st) < 0) {
-		if (errno != ENOENT) {
-			log(LOG_ERR, "%s: %s\n", file, strerror(errno));
-		}
-		if (fd != -1) close(fd);
-		return;
-	}
-
-	/* Forget it if the file is awfully big. */
-	if (st.st_size > TAB_MAX) {
-		log(LOG_ERR, "%s: %lu bytes is bigger than my %lu limit\n",
-			file,
-			(unsigned long) st.st_size,
-			(unsigned long) TAB_MAX);
-		return;
-	}
-
-	/* If the file is the same as before then don't bother. */
-	if (tab != nil && st.st_mtime == tab->mtime) {
-		close(fd);
-		tab->current= 1;
-		return;
-	}
-
-	/* Create a new table structure. */
-	tab= allocate(sizeof(*tab));
-	tab->file= allocate((strlen(file) + 1) * sizeof(tab->file[0]));
-	strcpy(tab->file, file);
-	tab->user= nil;
-	if (user != nil) {
-		tab->user= allocate((strlen(user) + 1) * sizeof(tab->user[0]));
-		strcpy(tab->user, user);
-	}
-	tab->data= allocate((st.st_size + 1) * sizeof(tab->data[0]));
-	tab->jobs= nil;
-	tab->mtime= st.st_mtime;
-	tab->current= 0;
-	tab->next= *atab;
-	*atab= tab;
-
-	/* Pull a new table in core. */
-	n= 0;
-	while (n < st.st_size) {
-		if ((r = read(fd, tab->data + n, st.st_size - n)) < 0) {
-			log(LOG_CRIT, "%s: %s", file, strerror(errno));
-			close(fd);
-			return;
-		}
-		if (r == 0) break;
-		n+= r;
-	}
-	close(fd);
-	tab->data[n]= 0;
-	if (strlen(tab->data) < n) {
-		log(LOG_ERR, "%s contains a null character\n", file);
-		return;
-	}
-
-	/* Parse the file. */
-	ajob= &tab->jobs;
-	p= tab->data;
-	ok= 1;
-	while (ok && *p != 0) {
-		q= get_token(&p);
-		if (*q == '#' || q == p) {
-			/* Comment or empty. */
-			while (*p != 0 && *p++ != '\n') {}
-			continue;
-		}
-
-		/* One new job coming up. */
-		*ajob= job= allocate(sizeof(*job));
-		*(ajob= &job->next)= nil;
-		job->tab= tab;
-
-		if (!range_parse(file, q, job->min, 0, 59, &wc)) {
-			ok= 0;
-			break;
-		}
-
-		q= get_token(&p);
-		if (!range_parse(file, q, job->hour, 0, 23, &wc)) {
-			ok= 0;
-			break;
-		}
-
-		q= get_token(&p);
-		if (!range_parse(file, q, job->mday, 1, 31, &wc)) {
-			ok= 0;
-			break;
-		}
-		job->do_mday= !wc;
-
-		q= get_token(&p);
-		if (!range_parse(file, q, job->mon, 1, 12, &wc)) {
-			ok= 0;
-			break;
-		}
-		job->do_mday |= !wc;
-
-		q= get_token(&p);
-		if (!range_parse(file, q, job->wday, 0, 7, &wc)) {
-			ok= 0;
-			break;
-		}
-		job->do_wday= !wc;
-
-		/* 7 is Sunday, but 0 is a common mistake because it is in the
-		 * tm_wday range.  We allow and even prefer it internally.
-		 */
-		if (bit_isset(job->wday, 7)) {
-			bit_clr(job->wday, 7);
-			bit_set(job->wday, 0);
-		}
-
-		/* The month range is 1-12, but tm_mon likes 0-11. */
-		job->mon[0] >>= 1;
-		if (bit_isset(job->mon, 8)) bit_set(job->mon, 7);
-		job->mon[1] >>= 1;
-
-		/* Scan for options. */
-		job->user= nil;
-		while (q= get_token(&p), *q == '-') {
-			q++;
-			if (q[0] == '-' && q+1 == p) {
-				/* -- */
-				q= get_token(&p);
-				break;
-			}
-			while (q < p) switch (*q++) {
-			case 'u':
-				if (q == p) q= get_token(&p);
-				if (q == p) goto usage;
-				memmove(q-1, q, p-q);	/* gross... */
-				p[-1]= 0;
-				job->user= q-1;
-				q= p;
-				break;
-			default:
-			usage:
-				log(LOG_ERR,
-			"%s: bad option -%c, good options are: -u username\n",
-					file, q[-1]);
-				ok= 0;
-				goto endtab;
-			}
-		}
-
-		/* A crontab owned by a user can only do things as that user. */
-		if (tab->user != nil) job->user= tab->user;
-
-		/* Inspect the first character of the command. */
-		job->cmd= q;
-		if (q == p || *q == '#') {
-			/* Rest of the line is empty, i.e. the commands are on
-			 * the following lines indented by one tab.
-			 */
-			while (*p != 0 && *p++ != '\n') {}
-			if (*p++ != '\t') {
-				log(LOG_ERR, "%s: contains an empty command\n",
-					file);
-				ok= 0;
-				goto endtab;
-			}
-			while (*p != 0) {
-				if ((*q = *p++) == '\n') {
-					if (*p != '\t') break;
-					p++;
-				}
-				q++;
-			}
-		} else {
-			/* The command is on this line.  Alas we must now be
-			 * backwards compatible and change %'s to newlines.
-			 */
-			p= q;
-			while (*p != 0) {
-				if ((*q = *p++) == '\n') break;
-				if (*q == '%') *q= '\n';
-				q++;
-			}
-		}
-		*q= 0;
-		job->rtime= now;
-		job->late= 0;		/* It is on time. */
-		job->atjob= 0;		/* True cron job. */
-		job->pid= IDLE_PID;	/* Not running yet. */
-		tab_reschedule(job);	/* Compute next time to run. */
-	}
-  endtab:
-
-	if (ok) tab->current= 1;
-}
-
-void tab_find_atjob(char *atdir)
-/* Find the first to be executed AT job and kludge up an crontab job for it.
- * We set tab->file to "atdir/jobname", tab->data to "atdir/past/jobname",
- * and job->cmd to "jobname".
- */
-{
-	DIR *spool;
-	struct dirent *entry;
-	time_t t0, t1;
-	struct tm tmnow, tmt1;
-	static char template[] = "96.365.1546.00";
-	char firstjob[sizeof(template)];
-	int i;
-	crontab_t *tab;
-	cronjob_t *job;
-
-	if ((spool= opendir(atdir)) == nil) return;
-
-	tmnow= *localtime(&now);
-	t0= NEVER;
-
-	while ((entry= readdir(spool)) != nil) {
-		/* Check if the name fits the template. */
-		for (i= 0; template[i] != 0; i++) {
-			if (template[i] == '.') {
-				if (entry->d_name[i] != '.') break;
-			} else {
-				if (!isdigit(entry->d_name[i])) break;
-			}
-		}
-		if (template[i] != 0 || entry->d_name[i] != 0) continue;
-
-		/* Convert the name to a time.  Careful with the century. */
-		memset(&tmt1, 0, sizeof(tmt1));
-		tmt1.tm_year= atoi(entry->d_name+0);
-		while (tmt1.tm_year < tmnow.tm_year-10) tmt1.tm_year+= 100;
-		tmt1.tm_mday= 1+atoi(entry->d_name+3);
-		tmt1.tm_min= atoi(entry->d_name+7);
-		tmt1.tm_hour= tmt1.tm_min / 100;
-		tmt1.tm_min%= 100;
-		tmt1.tm_isdst= -1;
-		if ((t1= mktime(&tmt1)) == -1) {
-			/* Illegal time?  Try in winter time. */
-			tmt1.tm_isdst= 0;
-			if ((t1= mktime(&tmt1)) == -1) continue;
-		}
-		if (t1 < t0) {
-			t0= t1;
-			strcpy(firstjob, entry->d_name);
-		}
-	}
-	closedir(spool);
-
-	if (t0 == NEVER) return;	/* AT job spool is empty. */
-
-	/* Create new table and job structures. */
-	tab= allocate(sizeof(*tab));
-	tab->file= allocate((strlen(atdir) + 1 + sizeof(template))
-						* sizeof(tab->file[0]));
-	strcpy(tab->file, atdir);
-	strcat(tab->file, "/");
-	strcat(tab->file, firstjob);
-	tab->data= allocate((strlen(atdir) + 6 + sizeof(template))
-						* sizeof(tab->data[0]));
-	strcpy(tab->data, atdir);
-	strcat(tab->data, "/past/");
-	strcat(tab->data, firstjob);
-	tab->user= nil;
-	tab->mtime= 0;
-	tab->current= 1;
-	tab->next= crontabs;
-	crontabs= tab;
-
-	tab->jobs= job= allocate(sizeof(*job));
-	job->next= nil;
-	job->tab= tab;
-	job->user= nil;
-	job->cmd= tab->data + strlen(atdir) + 6;
-	job->rtime= t0;
-	job->late= 0;
-	job->atjob= 1;		/* One AT job disguised as a cron job. */
-	job->pid= IDLE_PID;
-
-	if (job->rtime < next) next= job->rtime;
-}
-
-void tab_purge(void)
-/* Remove table data that is no longer current.  E.g. a crontab got removed.
- */
-{
-	crontab_t **atab, *tab;
-	cronjob_t *job;
-
-	atab= &crontabs;
-	while ((tab= *atab) != nil) {
-		if (tab->current) {
-			/* Table is fine. */
-			tab->current= 0;
-			atab= &tab->next;
-		} else {
-			/* Table is not, or no longer valid; delete. */
-			*atab= tab->next;
-			while ((job= tab->jobs) != nil) {
-				tab->jobs= job->next;
-				deallocate(job);
-			}
-			deallocate(tab->data);
-			deallocate(tab->file);
-			deallocate(tab->user);
-			deallocate(tab);
-		}
-	}
-}
-
-static cronjob_t *reap_or_find(pid_t pid)
-/* Find a finished job or search for the next one to run. */
-{
-	crontab_t *tab;
-	cronjob_t *job;
-	cronjob_t *nextjob;
-
-	nextjob= nil;
-	next= NEVER;
-	for (tab= crontabs; tab != nil; tab= tab->next) {
-		for (job= tab->jobs; job != nil; job= job->next) {
-			if (job->pid == pid) {
-				job->pid= IDLE_PID;
-				tab_reschedule(job);
-			}
-			if (job->pid != IDLE_PID) continue;
-			if (job->rtime < next) next= job->rtime;
-			if (job->rtime <= now) nextjob= job;
-		}
-	}
-	return nextjob;
-}
-
-void tab_reap_job(pid_t pid)
-/* A job has finished.  Try to find it among the crontab data and reschedule
- * it.  Recompute time next to run a job.
- */
-{
-	(void) reap_or_find(pid);
-}
-
-cronjob_t *tab_nextjob(void)
-/* Find a job that should be run now.  If none are found return null.
- * Update 'next'.
- */
-{
-	return reap_or_find(NO_PID);
-}
-
-static void pr_map(FILE *fp, bitmap_t map)
-{
-	int last_bit= -1, bit;
-	char *sep;
-
-	sep= "";
-	for (bit= 0; bit < 64; bit++) {
-		if (bit_isset(map, bit)) {
-			if (last_bit == -1) last_bit= bit;
-		} else {
-			if (last_bit != -1) {
-				fprintf(fp, "%s%d", sep, last_bit);
-				if (last_bit != bit-1) {
-					fprintf(fp, "-%d", bit-1);
-				}
-				last_bit= -1;
-				sep= ",";
-			}
-		}
-	}
-}
-
-void tab_print(FILE *fp)
-/* Print out a stored crontab file for debugging purposes. */
-{
-	crontab_t *tab;
-	cronjob_t *job;
-	char *p;
-	struct tm tm;
-
-	for (tab= crontabs; tab != nil; tab= tab->next) {
-		fprintf(fp, "tab->file = \"%s\"\n", tab->file);
-		fprintf(fp, "tab->user = \"%s\"\n",
-				tab->user == nil ? "(root)" : tab->user);
-		fprintf(fp, "tab->mtime = %s", ctime(&tab->mtime));
-
-		for (job= tab->jobs; job != nil; job= job->next) {
-			if (job->atjob) {
-				fprintf(fp, "AT job");
-			} else {
-				pr_map(fp, job->min); fputc(' ', fp);
-				pr_map(fp, job->hour); fputc(' ', fp);
-				pr_map(fp, job->mday); fputc(' ', fp);
-				pr_map(fp, job->mon); fputc(' ', fp);
-				pr_map(fp, job->wday);
-			}
-			if (job->user != nil && job->user != tab->user) {
-				fprintf(fp, " -u %s", job->user);
-			}
-			fprintf(fp, "\n\t");
-			for (p= job->cmd; *p != 0; p++) {
-				fputc(*p, fp);
-				if (*p == '\n') fputc('\t', fp);
-			}
-			fputc('\n', fp);
-			tm= *localtime(&job->rtime);
-			fprintf(fp, "    rtime = %.24s%s\n", asctime(&tm),
-				tm.tm_isdst ? " (DST)" : "");
-			if (job->pid != IDLE_PID) {
-				fprintf(fp, "    pid = %ld\n", (long) job->pid);
-			}
-		}
-	}
-}
-
-/*
- * $PchId: tab.c,v 1.5 2000/07/25 22:07:51 philip Exp $
- */
Index: trunk/minix/commands/cron/tab.h
===================================================================
--- trunk/minix/commands/cron/tab.h	(revision 9)
+++ 	(revision )
@@ -1,72 +1,0 @@
-/*	tab.h - in-core crontab data			Author: Kees J. Bot
- *								7 Dec 1996
- */
-#ifndef TAB__H
-#define TAB__H
-
-#include <sys/types.h>
-#include <limits.h>
-
-struct crontab;
-
-typedef unsigned char bitmap_t[8];
-
-typedef struct cronjob {	/* One entry in a crontab file */
-	struct cronjob	*next;
-	struct crontab	*tab;		/* Associated table file. */
-	bitmap_t	min;		/* Minute (0-59) */
-	bitmap_t	hour;		/* Hour (0-23) */
-	bitmap_t	mday;		/* Day of the month (1-31) */
-	bitmap_t	mon;		/* Month (1-12) */
-	bitmap_t	wday;		/* Weekday (0-7 with 0 = 7 = Sunday) */
-	char		*user;		/* User to run it as (nil = root) */
-	char		*cmd;		/* Command to run */
-	time_t		rtime;		/* When next to run */
-	char		do_mday;	/* True iff mon or mday is not '*' */
-	char		do_wday;	/* True iff wday is not '*' */
-	char		late;		/* True iff the job is late */
-	char		atjob;		/* True iff it is an AT job */
-	pid_t		pid;		/* Process-id of job if nonzero */
-} cronjob_t;
-
-typedef struct crontab {
-	struct crontab	*next;
-	char		*file;		/* Crontab name */
-	char		*user;		/* Owner if non-null */
-	time_t		mtime;		/* Last modified time */
-	cronjob_t	*jobs;		/* List of jobs in the file */
-	char		*data;		/* File data */
-	int		current;	/* True if current, i.e. file exists */
-} crontab_t;
-
-crontab_t *crontabs;		/* All crontabs. */
-
-/* A time as far in the future as possible. */
-#define NEVER		((time_t) ((time_t) -1 < 0 ? LONG_MAX : ULONG_MAX))
-
-/* Don't trust crontabs bigger than this: */
-#define TAB_MAX		((sizeof(int) == 2 ? 8 : 128) * 1024)
-
-/* Pid if no process running, or a pid value you'll never see. */
-#define IDLE_PID	((pid_t) 0)
-#define NO_PID		((pid_t) -1)
-
-/* Bitmap operations. */
-#define bit_set(map, n)		((void) ((map)[(n) >> 3] |= (1 << ((n) & 7))))
-#define bit_clr(map, n)		((void) ((map)[(n) >> 3] &= ~(1 << ((n) & 7))))
-#define bit_isset(map, n)	(!!((map)[(n) >> 3] & (1 << ((n) & 7))))
-
-/* Functions. */
-void tab_parse(char *file, char *user);
-void tab_find_atjob(char *atdir);
-void tab_purge(void);
-void tab_reap_job(pid_t pid);
-void tab_reschedule(cronjob_t *job);
-cronjob_t *tab_nextjob(void);
-void tab_print(FILE *fp);
-
-#endif /* TAB__H */
-
-/*
- * $PchId: tab.h,v 1.3 2000/07/17 07:57:27 philip Exp $
- */
Index: trunk/minix/commands/de/Makefile
===================================================================
--- trunk/minix/commands/de/Makefile	(revision 9)
+++ 	(revision )
@@ -1,22 +1,0 @@
-# Makefile for de
-
-CC	= exec cc
-CFLAGS	= -O -D_MINIX -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2
-
-all:	de
-
-OBJS	= de.o de_stdin.o de_stdout.o de_diskio.o de_recover.o
-
-de:	$(OBJS)
-	$(CC) -i $(OBJS) -o de
-	install -S 4kw de
-
-install:	/usr/bin/de
-
-/usr/bin/de:	de
-	install -cs -o bin de $@
-
-$(OBJS): de.h
-
-clean:
-	rm -f *.bak *.o de
Index: trunk/minix/commands/de/README
===================================================================
--- trunk/minix/commands/de/README	(revision 9)
+++ 	(revision )
@@ -1,156 +1,0 @@
-		de - A Minix Disk Editor
-
-	      Terrence W. Holm, Jan. 1989
-
-
-INTRODUCTION
-
-    The de(1) disk editor allows a system administrator to
-    look at and modify a Minix file system device. Commands
-    allow movement throughout a file system device, displaying
-    information in a couple of formats, writing blocks from
-    the device onto another file, and rewriting words on the
-    disk.
-
-    A few changes to the Minix file system aid recovering files.
-    I-node numbers are retained in directory entries now (they
-    get moved to the end). And all the i-node information is not
-    zeroed-out when a file is unlinked. So, after a file is
-    accidently rm(1)'ed, you can find the old i-node, and then
-    manually (or automatically) go to each of the freed blocks
-    and write them to a new file.
-
-
-USES FOR THE DISK EDITOR
-
-    1)	EDUCATION. Students can look at a file system in
-        a painless manner. For example you don't have to
-	use od(1) to look at the zone numbers in i-nodes.
-
-	A simple assignment is to change the size of an un-mounted
-	floppy disk file system from 360 to 300 blocks. (A more
-	difficult assignment is to explain why this works, even
-	though fsck(1) and df(1) do not report the correct number
-	of free blocks. :-)
-
-    2)  ADMINISTRATION. You can visually check inconsistencies
-	reported by fsck(1) before letting fsck(1) fix them.
-	You can change any word on the disk, this greatly simplifies
-	editing file system information. For example, changing the
-	size of a block special device is actually fun, no more
-	"blind" writing to your partitions.
-
-	Bit maps can be displayed with 2048 "bits" per screen,
-	(on the IBM/PC console), see how your zones are allocated!
-
-    3)  RECOVERING LOST FILES. You can search a disk for an ASCII
-	string, once found, the block can be written out to a file.
-
-	A one line change to fs/path.c allows users to get the i-node
-	number for a file after it has been removed from a directory.
-
-	Another couple lines changed in the file system keep the
-	i-node information available until the i-node is reused
-	(normally this information is zeroed out when an i-node is
-	released.) This allows a de(1) user to go to a released
-	i-node, get all the block numbers, go to these blocks and
-	write them back to a new file.
-
-	The whole recovery process is automated by running "de -r file".
-	So, IF a file is unlink(2)'ed (eg. "rm file"), AND IF no one
-	allocates a new i-node or block in the mean-time, THEN you
-	can recover the file.
-
-
-RECOVERY SECURITY
-
-    Normally Minix hard disk partitions are r/w only by the super-user,
-    and floppy disks are r/w by anyone. This means that only "root"
-    can look at hard disk partitions, but others can use de(1) to play
-    with their floppy disks.
-
-    When recovering files ("de -r file"), a user requires access to
-    the major file system partitions. This can be done by:
-
-	(a) Give everyone access to the hard disks. DON'T DO THIS, it
-	    defeats all the file system protection we already have.
-
-	(b) Make de(1) set-uid "root". This is the way to go, IF you
-	    are running a Minix system that has NO ACCESS from the
-	    outside. This allows anyone to execute "de -r file", but only
-	    root to use "de /dev/hd3". De(1) does some checking when
-	    retrieving lost blocks, eg. making sure they really are
-	    free blocks and making sure the user owned the i-node.
-	    BUT, file system information has been lost when the file
-	    was unlink(2)'ed, so de(1) can not be 100% sure that a
-	    recovered block really belonged to the user. THIS IS A
-	    SECURITY HOLE. [Since the only access to my machine is from
-	    observable terminals and their associated humans, I run
-	    de(1) as set-uid root.]
-
-	(c) Keep the disks rw-------, and don't set-uid de(1). This
-	    means that only the super-user can recover lost files.
-	    So, if you accidently "rm", you must tell the system
-	    administrator to "su" and recover your file, (be sure to
-	    inform the other users to stop whatever they are doing
-	    until the file is restored).
-
-
-INSTALLATION
-
-	- Install de.1 in /usr/man/cat1.
-
-	- Install the files: Makefile, README, de.h, de.c, de_stdin.c,
-	  de_stdout.c, de_diskio.c and de_recover.c in commands/de.
-	  Add -F and -T. to the Makefile, if necessary.
-
-	- "make" de(1). If a header file is not found, don't worry:
-	  You probably have it somewhere, just link it to what de(1)
-	  is looking for. This program also requires the subroutine
-	  tolower(3), see EFTH MINIX report #50, if you don't have it.
-
-	- Do you really want set-uid root on de?
-
-	- Patch the files fs/path.c, fs/link.c and fs/open.c. If
-	  you don't patch the file system then the recover option
-	  "-r" and associated commands ('x' and 'X') will not work,
-	  but de(1) is still functional and useful.
-
-	- "make" a new fs, using -DRECOVER. Rebuild a boot diskette.
-
-
-USING DE(1) FOR THE FIRST TIME
-
-    De(1) starts up in "word" mode at block 0 of the specified
-    device. Hit the PGDN (or space bar) a few times, observing
-    all the information on the screen. Each PGUP/PGDN moves to
-    the next 1024 byte block, (de(1) only knows about 1 block per
-    zone file systems). Note that "word" mode only displays 32
-    bytes at a time, so you are only observing the first 32 bytes
-    in the first few blocks when you skip using PGDN.
-
-    Now go back to block 3, (zone bit map), using "g 3 ENTER".
-    Change to "map" mode "v m", and then use the down arrow key
-    to check each 2 Megs in the zone bit map.
-
-    Now change to "block" mode using "v b". And go to some data
-    block, eg. "g 1000 ENTER". Use PGUP/PGDN to see what data
-    is in each nearby block.
-
-    Remember 'h' gives you a help page.
-
-    Try some more commands, for example: 'END', 'I', '/'.
-    (Note: searching through a whole disk under Minix takes a
-    long time: 30-60 seconds per megabyte, depending on your
-    machine, drive and controller, [Minix is embarrassingly slow].)
-
-    Don't worry about looking at a mounted device, you must specify
-    the "-w" option before the 's' command is operational, and
-    this command is the only one which will try to modify the
-    contents of the device.
-
-
-MINIX-ST
-
-    Please contact me if you are interesting in attempting a port
-    to MINIX-ST.
Index: trunk/minix/commands/de/build
===================================================================
--- trunk/minix/commands/de/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/de/de.c
===================================================================
--- trunk/minix/commands/de/de.c	(revision 9)
+++ 	(revision )
@@ -1,1335 +1,0 @@
-/****************************************************************/
-/*								*/
-/*	de.c							*/
-/*								*/
-/*		Main loop of the "Disk editor".			*/
-/*								*/
-/****************************************************************/
-/*  origination         1989-Jan-15        Terrence W. Holm	*/
-/****************************************************************/
-
-
-#include <minix/config.h>
-#include <sys/types.h>
-#include <sys/dir.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <ctype.h>
-#include <errno.h>
-#undef ERROR			/* arrgghh, errno.h has this pollution */
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <minix/const.h>
-#include <minix/type.h>
-#include "../../servers/fs/const.h"
-#include "../../servers/fs/type.h"
-#include "../../servers/fs/inode.h"
-
-#include "de.h"
-
-static char copyright[] = "de  (c) Terrence W. Holm 1989";
-
-
-_PROTOTYPE(void Push , (de_state *s ));
-_PROTOTYPE(int Get_Base , (int *base ));
-_PROTOTYPE(int Get_Filename , (de_state *s ));
-_PROTOTYPE(int Get_Count , (char *units , unsigned long *result ));
-_PROTOTYPE(void Exec_Shell , (void));
-_PROTOTYPE(void Sigint , (int));
-
-
-
-/****************************************************************/
-/*								*/
-/*	main()							*/
-/*								*/
-/*		Initialize. Handle the "-r" recovery option if	*/
-/*		specified, else enter the main processing loop.	*/
-/*								*/
-/****************************************************************/
-
-
-void main( argc, argv )
-  int   argc;
-  char *argv[];
-
-  {
-  static de_state s;		/* it is safer not to put it on the stack
-				 * and some things probably now rely on zero
-				 * initialization
-				 */  
-  char *command_name = argv[0];
-  int   recover = 0;
-
-
-  s.device_mode = O_RDONLY;
-
-
-  /*  Parse arguments  */
-
-  if ( argc == 3  &&  strcmp( argv[1], "-r" ) == 0 )
-    {
-    recover = 1;
-    --argc;
-    ++argv;
-    }
-  else if ( argc == 3  &&  strcmp( argv[1], "-w" ) == 0 )
-    {
-    s.device_mode = O_RDWR;
-    --argc;
-    ++argv;
-    }
-
-  if ( argc != 2  ||  *argv[1] == '-' )
-    {
-    fprintf( stderr, "Usage: %s [-w] /dev/device\n", command_name );
-    fprintf( stderr, "       %s -r lost_file_name\n", command_name );
-    exit( 1 );
-    }
-
-
-  /*  Set the effective id to the real id. This eliminates	*/
-  /*  any increase in privilege done by a set-uid bit on the	*/
-  /*  executable file. We want to be "root" for recovering 	*/
-  /*  files, because we must be able to read the device.	*/
-  /*  However, in normal usage, de(1) should not let just 	*/
-  /*  anyone look at a file system, thus we drop the privilege.	*/
-  /*								*/
-  /*  NOTE: There is a security hole when using "-r" with a	*/
-  /*  set-uid de(1). Do not use set-uid root if there is any	*/
-  /*  way to externally access your Minix system.		*/
-
-  if ( ! recover )
-    {
-    setuid( getuid() );
-    setgid( getgid() );
-    }
-
-
-  /*  Set terminal characteristics, and ^C interrupt handler  */
-
-  Save_Term();
-
-  if ( signal( SIGINT, SIG_IGN ) != SIG_IGN )
-    {
-    signal( SIGINT,  Sigint );
-    signal( SIGQUIT, Sigint );
-    }
-
-  Set_Term();
-
-  if ( ! Init_Termcap() )
-    Error( "Requires a termcap entry" );
-
-
-
-  /*  Get the device file name. If recovering, also open an output file.  */
-
-  if ( recover )
-    {
-    char *dir_name;
-    char *file_name;
-    struct stat device_stat;
-    struct stat tmp_stat;
-
-    /*  Split the path name into a directory and a file name.  */
-
-    if ( strlen(argv[1]) > MAX_STRING )
-      Error( "Path name too long" );
-
-    if ( ! Path_Dir_File( argv[1], &dir_name, &file_name ) )
-      Error( "Recover aborted" );
-
-    /*  Find the device holding the directory.  */
-
-    if ( (s.device_name = File_Device( dir_name )) == NULL )
-      Error( "Recover aborted" );
-
-
-    /*  The output file will be in /tmp with the same file name.  */
-
-    strcpy( s.file_name, TMP );
-    strcat( s.file_name, "/" );
-    strcat( s.file_name, file_name );
-
-
-    /*  Make sure /tmp is not on the same device as the file we	   */
-    /*  are trying to recover (we don't want to use up the free	   */
-    /*  i-node and blocks before we get a chance to recover them). */
-
-    if ( stat( s.device_name, &device_stat ) == -1 )
-      Error( "Can not stat(2) device %s", s.device_name );
-
-    if ( stat( TMP, &tmp_stat ) == -1 )
-      Error( "Can not stat(2) directory %s", TMP );
-
-    if ( device_stat.st_rdev == tmp_stat.st_dev )
-      Error( "Will not recover files on the same device as %s", TMP );
-
-    if ( access( s.file_name, F_OK ) == 0 )
-      Error( "Will not overwrite file %s", s.file_name );
-
-
-    /*  Open the output file.  */
-
-    if ( (s.file_f = fopen( s.file_name, "w" )) == NULL )
-      Error( "Can not open file %s", s.file_name );
-
-    /*  Don't let anyone else look at the recovered file  */
-
-    chmod( s.file_name, 0700 );
-
-    /*  If running as root then change the owner of the  */
-    /*  restored file. If not running as root then the   */
-    /*  chown(2) will fail.				 */
-
-    chown( s.file_name, getuid(), getgid() );
-    }
-  else
-    {
-    s.device_name = argv[1];
-    s.file_name[ 0 ] = '\0';
-    }
-
-
-  /*  Open the device file.  */
-
-  {
-  struct stat device_stat;
-  off_t size;
-
-  if ( stat( s.device_name, &device_stat ) == -1 )
-    Error( "Can not find file %s", s.device_name );
-
-  if ( (device_stat.st_mode & S_IFMT) != S_IFBLK  &&
-       (device_stat.st_mode & S_IFMT) != S_IFREG )
-    Error( "Can only edit block special or regular files" );
-
-
-  if ( (s.device_d = open( s.device_name, s.device_mode )) == -1 )
-    Error( "Can not open %s", s.device_name );
-
-  if ( (size = lseek( s.device_d, 0L, SEEK_END )) == -1 )
-    Error( "Error seeking %s", s.device_name );
-
-  if ( size % K != 0 )
-    {
-    Warning( "Device size is not a multiple of 1024" );
-    Warning( "The (partial) last block will not be accessible" );
-    }
-  }
-
-
-  /*  Initialize the rest of the state record  */
-
-  s.mode = WORD;
-  s.output_base = 10;
-  s.search_string[ 0 ] = '\0';
-
-  {
-  int i;
-
-  for ( i = 0;  i < MAX_PREV;  ++i )
-    {
-    s.prev_addr[ i ] = 0L;
-    s.prev_mode[ i ] = WORD;
-    }
-  }
-
-
-  sync();
-
-  Read_Super_Block( &s );
-
-  Read_Bit_Maps( &s );
-
-  s.address = 0L;
-
-
-
-  /*  Recover mode basically performs an 'x' and an 'X'  */
-
-  if ( recover )
-    {
-    ino_t inode = Find_Deleted_Entry( &s, argv[1] );
-    off_t size;
-
-    if ( inode == 0 )
-      {
-      unlink( s.file_name );
-      Error( "Recover aborted" );
-      }
-
-    s.address = ( (long) s.first_data - s.inode_blocks ) * K
-		      + (long) (inode - 1) * s.inode_size;
-
-    Read_Block( &s, s.buffer );
-
-
-    /*  Have found the lost i-node, now extract the blocks.  */
-
-    if ( (size = Recover_Blocks( &s )) == -1L )
-      {
-      unlink( s.file_name );
-      Error( "Recover aborted" );
-      }
-
-    Reset_Term();
-
-    printf( "Recovered %ld bytes, written to file %s\n", size, s.file_name );
-
-    exit( 0 );
-    }
-
-
-  /*  Enter the main loop, first time redraw the screen  */
-  {
-  int rc = REDRAW;
-
-
-  do
-    {
-    if ( rc == REDRAW )
-      {
-      Read_Block( &s, s.buffer );
-      Draw_Screen( &s );
-      s.last_addr = s.address;
-      Draw_Pointers( &s );
-      }
-
-    else if ( rc == REDRAW_POINTERS )
-      {
-      s.offset = (unsigned) (s.address & ~ K_MASK);
-      Draw_Pointers( &s );
-      }
-
-    else if ( rc == ERROR )
-      {
-      Erase_Prompt();
-      putchar( BELL );
-      }
-    } while ( (rc = Process( &s, Arrow_Esc(Get_Char()) )) != EOF );
-  }
-
-
-  /*  If there is an open output file that was never written to  */
-  /*  then remove its directory entry. This occurs when no 'w' 	 */
-  /*  or 'W' command occurred between a 'c' command and exiting	 */
-  /*  the program.						 */
-
-  if ( s.file_name[0] != '\0'  &&  ! s.file_written )
-    unlink( s.file_name );
-
-
-  Reset_Term();	   /*  Restore terminal characteristics  */
-
-  exit( 0 );
-  }
-
-
-
-/****************************************************************/
-/*								*/
-/*	Get_Base( base )					*/
-/*								*/
-/*		Get a new base value.				*/
-/*		Returns REDRAW or ERROR.			*/
-/*								*/
-/****************************************************************/
-
-
-
-int Get_Base( base )
-  int *base;
-  {
-	switch ( Get_Char() )
-	  {
-	  case 'h' :	*base = 16;
-			break;
-
-	  case 'd' :	*base = 10;
-			break;
-
-	  case 'o' :	*base = 8;
-			break;
-
-	  case 'b' :	*base = 2;
-			break;
-
-	  default  :	return( ERROR );
-	  }
-
-		return( REDRAW );
-  }
-
-
-
-/****************************************************************/
-/*								*/
-/*	Process( state, input_char )				*/
-/*								*/
-/*		Determine the function requested by the 	*/
-/*		input character. Returns OK, REDRAW,		*/
-/*		REDRAW_POINTERS,  ERROR or EOF.			*/
-/*								*/
-/****************************************************************/
-
-
-int Process( s, c )
-  de_state  *s;
-  int  c;
-
-  {
-  switch ( c )
-    {
-    case 'b' :				/*  Back up one block	*/
-    case ESC_PGUP :
-
-		if ( s->address == 0 )
-		  return( ERROR );
-
-		s->address = (s->address - K) & K_MASK;
-
-		return( REDRAW );
-
-
-    case 'B' :				/*  Back up to home	*/
-    case ESC_HOME :
-
-		if ( s->address == 0 )
-		  return( OK );
-
-		Push( s );
-
-		s->address = 0L;
-
-		return( REDRAW );
-
-
-    case 'c' :				/*  Change file name	*/
-
-		{
-		int rc = Get_Filename( s );
-
-		return( rc == OK ? REDRAW : rc );
-		}
-
-
-    case 'd' :				/*  Down		*/
-    case ESC_DOWN :
-
-		{
-		s->last_addr = s->address;
-
-		switch ( s->mode )
-		  {
-		  case WORD :	s->address += 2;
-
-				if ( (s->address & PAGE_MASK) == 0 )
-				  return( REDRAW );
-
-				return( REDRAW_POINTERS );
-
-		  case BLOCK :	s->address += 64;
-
-				if ( (s->last_addr & K_MASK) !=
-				     (s->address   & K_MASK) )
-				  return( REDRAW );
-
-				return( REDRAW_POINTERS );
-
-		  case MAP :	s->address += 256;
-
-				return( REDRAW );
-
-		  default :	Error( "Internal fault (mode)" );
-		  }
-		}
-
-
-    case 'f' :				/*  Forward one block	*/
-    case ' ' :
-    case ESC_PGDN :
-
-		if ( s->block == s->device_size - 1 )
-		  return( ERROR );
-
-		s->address = (s->address + K) & K_MASK;
-
-		return( REDRAW );
-
-
-    case 'F' :				/*  Forward to end	*/
-    case ESC_END :
-
-		{
-		off_t  last_block = ( (long) s->device_size - 1 ) * K;
-
-		if ( s->address == last_block )
-		  return( OK );
-
-		Push( s );
-
-		s->address = last_block;
-
-		return( REDRAW );
-		}
-
-
-    case 'g' :				/*  Goto block		*/
-
-		{
-		unsigned long block;
-
-		if ( Get_Count( "Block?", &block ) )
-		  {
-		  if ( block >= s->zones )
-		    {
-		    Warning( "Block number too large" );
-		    return( REDRAW );
-		    }
-
-		  Push( s );
-
-		  s->address = (off_t) block * K;
-
-		  return( REDRAW );
-		  }
-		else
-		  return( ERROR );
-		}
-
-
-    case 'G' :				/*  Goto block indirect	*/
-
-		{
-		unsigned block = *( (word_t *) &s->buffer[ s->offset ] );
-
-		if ( s->mode != WORD )
-		  {
-		  Warning( "Must be in visual mode \"word\"" );
-		  return( REDRAW );
-		  }
-
-		if ( block >= s->zones )
-		  {
-		  Warning( "Block number too large" );
-		  return( REDRAW );
-		  }
-
-		Push( s );
-
-		s->mode = BLOCK;
-		s->address = (long) block * K;
-
-		return( REDRAW );
-		}
-
-
-    case 'h' :				/*  Help		*/
-    case '?' :
-
-		Draw_Help_Screen( s );
-
-		Wait_For_Key();
-
-		return( REDRAW );
-
-
-    case 'i' :				/*  Goto i-node		*/
-
-		{
-		unsigned long inode;
-
-		if ( Get_Count( "I-node?", &inode ) )
-		  {
-		  if ( inode < 1  || inode > s->inodes )
-		    {
-		    Warning( "Illegal i-node number" );
-		    return( REDRAW );
-		    }
-
-		  Push( s );
-
-		  s->mode = WORD;
-		  s->address = (off_t) (s->first_data - s->inode_blocks) * K
-				  + (off_t) (inode - 1) * s->inode_size;
-
-		  return( REDRAW );
-		  }
-		else
-		  return( ERROR );
-		}
-
-
-    case 'I' :				/*  Filename to i-node	*/
-
-		{
-		ino_t inode;
-		char *filename;
-
-		Draw_Prompt( "File name?" );
-
-		filename = Get_Line();
-
-		if ( filename == NULL  ||  filename[0] == '\0' )
-		  return( ERROR );
-
-		inode = Find_Inode( s, filename );
-
-		if ( inode )
-		  {
-		  Push( s );
-
-		  s->mode = WORD;
-		  s->address = ( (long) s->first_data - s->inode_blocks ) * K
-				  + (long) (inode - 1) * s->inode_size;
-		  }
-
-		return( REDRAW );
-		}
-
-
-    case 'l' :				/*  Left		*/
-    case ESC_LEFT :
-
-		{
-		s->last_addr = s->address;
-
-		switch ( s->mode )
-		  {
-		  case WORD :	s->address = s->address - 32;
-
-				return( REDRAW );
-
-		  case BLOCK :	s->address -= 1;
-
-				if ( (s->last_addr & K_MASK) !=
-				     (s->address   & K_MASK) )
-				  return( REDRAW );
-
-				return( REDRAW_POINTERS );
-
-		  case MAP :	s->address -= 4;
-
-				if ( (s->last_addr & ~ MAP_MASK) !=
-				     (s->address   & ~ MAP_MASK) )
-				  return( REDRAW );
-
-				return( REDRAW_POINTERS );
-
-		  default :	Error( "Internal fault (mode)" );
-		  }
-		}
-
-
-    case 'm' :				/*  Invoke a Minix shell */
-
-		Reset_Term();
-
-		Exec_Shell();
-
-		Set_Term();
-
-		return( REDRAW );
-
-
-    case 'n' :				/*  Search for next	*/
-
-		{
-		off_t addr;
-
-		if ( s->search_string[0] == '\0' )
-		  {
-		  Warning( "No search string defined" );
-		  return( REDRAW );
-		  }
-
-		Draw_Prompt( "Searching..." );
-
-		if ( (addr = Search( s, s->search_string )) == -1L )
-		  {
-		  Warning( "Search string not found" );
-
-		  Wait_For_Key();
-
-		  return( REDRAW );
-		  }
-
-		Push( s );
-		s->address = addr;
-
-		return( REDRAW );
-		}
-
-
-    case 'o' :				/*  Set output base	*/
-
-		Draw_Prompt( "Output base?" );
-
-		return( Get_Base( &s->output_base ) );
-
-
-    case 'p' :				/*  Previous address	*/
-
-		{
-		int  i;
-
-		s->address = s->prev_addr[ 0 ];
-		s->mode    = s->prev_mode[ 0 ];
-
-  		for ( i = 0;  i < MAX_PREV - 1;  ++i )
-		  {
-    		  s->prev_addr[ i ] = s->prev_addr[ i + 1 ];
-		  s->prev_mode[ i ] = s->prev_mode[ i + 1 ];
-		  }
-
-		return( REDRAW );
-		}
-
-
-    case 'q' :				/*  Quit		 */
-    case EOF :
-    case CTRL_D :
-
-		return( EOF );
-
-
-    case 'r' :				/*  Right		*/
-    case ESC_RIGHT :
-
-		{
-		s->last_addr = s->address;
-
-		switch ( s->mode )
-		  {
-		  case WORD :	s->address += 32;
-
-				return( REDRAW );
-
-		  case BLOCK :	s->address += 1;
-
-				if ( (s->last_addr & K_MASK) !=
-				     (s->address   & K_MASK) )
-				  return( REDRAW );
-
-				return( REDRAW_POINTERS );
-
-		  case MAP :	s->address += 4;
-
-				if ( (s->last_addr & ~ MAP_MASK) !=
-				     (s->address   & ~ MAP_MASK) )
-				  return( REDRAW );
-
-				return( REDRAW_POINTERS );
-
-		  default :	Error( "Internal fault (mode)" );
-		  }
-		}
-
-    case 's' :				/*  Store word		*/
-
-		{
-		unsigned long word;
-
-		if ( s->mode != WORD )
-		  {
-		  Warning( "Must be in visual mode \"word\"" );
-		  return( REDRAW );
-		  }
-
-		if ( s->device_mode == O_RDONLY )
-		  {
-		  Warning( "Use -w option to open device for writing" );
-		  return( REDRAW );
-		  }
-
-		if ( Get_Count( "Store word?", &word ) )
-		  {
-		  if ( word != (word_t) word )
-		    {
-		      Warning( "Word is more than 16 bits" );
-		      return( REDRAW );
-		    }
-		  Write_Word( s, (word_t) word );
-
-		  return( REDRAW );
-		  }
-		else
-		  return( ERROR );
-		}
-
-
-    case 'u' :				/*  Up			*/
-    case ESC_UP :
-
-		{
-		s->last_addr = s->address;
-
-		switch ( s->mode )
-		  {
-		  case WORD :	s->address -= 2;
-
-				if ( (s->last_addr & PAGE_MASK) == 0 )
-				  return( REDRAW );
-
-				return( REDRAW_POINTERS );
-
-		  case BLOCK :	s->address -= 64;
-
-				if ( (s->last_addr & K_MASK) !=
-				     (s->address   & K_MASK) )
-				  return( REDRAW );
-
-				return( REDRAW_POINTERS );
-
-		  case MAP :	s->address -= 256;
-
-				return( REDRAW );
-
-		  default :	Error( "Internal fault (mode)" );
-		  }
-		}
-
-
-    case 'v' :				/*  Visual mode		*/
-
-		Draw_Prompt( "Visual mode?" );
-
-		switch ( Get_Char() )
-		  {
-		  case 'w' :	s->mode = WORD;
-				break;
-
-		  case 'b' :	s->mode = BLOCK;
-				break;
-
-		  case 'm' :	{
-				/* Assume user knows if map mode is possible
-				char *tty = ttyname( 0 );
-
-				if ( tty == NULL  ||
-				    strcmp( tty, "/dev/tty0" ) != 0 )
-				  Warning( "Must be at console" );
-				else
-				*/
-				  s->mode = MAP;
-
-				break;
-				}
-
-		  default  :	return( ERROR );
-		  }
-
-		return( REDRAW );
-
-
-    case 'w' :				/*  Write ASCII block	*/
-
-		if ( s->file_name[0] == '\0' )
-		  {
-		  int  rc = Get_Filename( s );
-
-		  if ( rc != OK )
-		    return( rc );
-		  }
-
-		/*  We have a successfully opened file  */
-
-		/*  Eliminate non-ASCII characters	*/
-		{
-		int i;
-		char buf[ K ];
-		char *from = s->buffer;
-		char *to = buf;
-
-		for ( i = 0;  i < K;  ++i, ++from )
-		  {
-		  *to = *from & 0x7f;
-
-		  if ( *to != '\0'  &&  *to != '\177' )
-		    ++to;
-		  }
-
-		if ( fwrite( buf, 1, (int)(to - buf), s->file_f ) != to - buf )
-		  Warning( "Problem writing out buffer" );
-
-		s->file_written = 1;
-
-		return( REDRAW );
-		}
-
-
-    case 'W' :				/*  Write block exactly	*/
-
-		if ( s->file_name[0] == '\0' )
-		  {
-		  int  rc = Get_Filename( s );
-
-		  if ( rc != OK )
-		    return( rc );
-		  }
-
-		/*  We have a successfully opened file  */
-
-		if ( fwrite( s->buffer, 1, K, s->file_f ) != K )
-		  Warning( "Problem writing out buffer" );
-
-		s->file_written = 1;
-
-		return( REDRAW );
-
-
-    case 'x' :				/*  eXtract lost entry	*/
-
-		{
-		ino_t inode;
-		char *filename;
-
-		Draw_Prompt( "Lost file name?" );
-
-		filename = Get_Line();
-
-		if ( filename == NULL  ||  filename[0] == '\0' )
-		  return( ERROR );
-
-		inode = Find_Deleted_Entry( s, filename );
-
-		if ( inode )
-		  {
-		  Push( s );
-
-		  s->mode = WORD;
-		  s->address = ( (long) s->first_data - s->inode_blocks ) * K
-				  + (long) (inode - 1) * s->inode_size;
-		  }
-
-		return( REDRAW );
-		}
-
-
-    case 'X' :				/*  eXtract lost blocks	*/
-
-		{
-		int  rc;
-
-		if ( s->mode != WORD )
-		  {
-		  Warning( "Must be in visual mode \"word\"" );
-		  return( REDRAW );
-		  }
-
-
-		/*  Force a new output file name.  */
-
-		if ( (rc = Get_Filename( s )) != OK )
-		  return( rc );
-
-
-		Draw_Strings( s );
-
-		Erase_Prompt();
-		Draw_Prompt( "Recovering..." );
-
-		if ( Recover_Blocks( s ) == -1L )
-		  unlink( s->file_name );
-
-		/*  Force closure of output file.  */
-
-		fclose( s->file_f );
-		s->file_name[ 0 ] = '\0';
-
-		return( REDRAW );
-		}
-
-
-    case '/' :				/*  Search		*/
-    case ESC_PLUS :
-
-		{
-		off_t addr;
-		char *string;
-
-		Draw_Prompt( "Search string?" );
-
-		string = Get_Line();
-
-		if ( string == NULL )
-		  return( ERROR );
-
-		if ( string[0] != '\0' )
-		  {
-		  strcpy( s->search_string, string );
-		  Draw_Strings( s );
-		  }
-
-		else if ( s->search_string[0] == '\0' )
-		  {
-		  Warning( "No search string defined" );
-		  return( REDRAW );
-		  }
-
-		Erase_Prompt();
-		Draw_Prompt( "Searching..." );
-
-		if ( (addr = Search( s, s->search_string )) == -1L )
-		  {
-		  Warning( "Search string not found" );
-
-		  Wait_For_Key();
-
-		  return( REDRAW );
-		  }
-
-		Push( s );
-
-		s->mode = BLOCK;
-		s->address = addr;
-
-		return( REDRAW );
-		}
-
-
-    default:
-		return( ERROR );
-    }
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Push( state )						*/
-/*								*/
-/*		Push current address and mode, used by the	*/
-/*		commands B, F, g, G, i, I, n, x and /.  This	*/
-/*		information is popped by the 'p' command.	*/
-/*								*/
-/****************************************************************/
-
-
-void Push( s )
-  de_state *s;
-
-  {
-  int  i;
-
-  for ( i = MAX_PREV - 1;  i > 0;  --i )
-    {
-    s->prev_addr[ i ] = s->prev_addr[ i - 1 ];
-    s->prev_mode[ i ] = s->prev_mode[ i - 1 ];
-    }
-
-  s->prev_addr[ 0 ] = s->address;
-  s->prev_mode[ 0 ] = s->mode;
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Get_Filename( state )					*/
-/*								*/
-/*		Read and check a filename.			*/
-/*								*/
-/****************************************************************/
-
-
-int Get_Filename( s )
-  de_state *s;
-
-  {
-  char *filename;
-  char *name;
-  FILE *f;
-
-  Draw_Prompt( "File name?" );
-
-  filename = Get_Line();
-
-  if ( filename == NULL  ||  filename[0] == '\0' )
-    return( ERROR );
-
-
-  for ( name = filename;  *name != '\0';  ++name )
-    if ( ! isgraph( *name ) )
-      {
-      Warning( "File name contains non-graphic characters" );
-      return( REDRAW );
-      }
-
-
-  if ( access( filename, F_OK ) == 0 )
-    {
-    Warning( "Will not overwrite file %s", filename );
-    return( REDRAW );
-    }
-
-  if ( (f = fopen( filename, "w" )) == NULL )
-    {
-    Warning( "Can not open file %s", filename );
-    return( REDRAW );
-    }
-
-  /*  If there is already an open output file then  */
-  /*  close it. If it was never written to then	    */
-  /*  remove its directory entry.		    */
-
-  if ( s->file_name[0] != '\0' )
-    {
-    if ( ! s->file_written )
-      unlink( s->file_name );
-
-    fclose( s->file_f );
-    }
-
-  strcpy( s->file_name, filename );
-  s->file_f = f;
-  s->file_written = 0;
-
-  return( OK );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Get_Count()						*/
-/*								*/
-/*		Read and check a number. Returns non-zero	*/
-/*		if successful.					*/
-/*								*/
-/****************************************************************/
-
-
-int Get_Count( units, result )
-  char *units;
-  unsigned long *result;
-
-  {
-  char *number;
-
-  Draw_Prompt( units );
-
-  number = Get_Line();
-
-  if ( number == NULL  ||  number[0] == '\0' )
-    return( 0 );
-
-  errno = 0;
-  *result = strtoul( number, (char **) NULL, 0 );
-  return( errno == 0 );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	In_Use( bit, map )					*/
-/*								*/
-/*		Is the bit set in the map?			*/
-/*								*/
-/****************************************************************/
-
-
-int In_Use( bit, map )
-  bit_t bit;
-  bitchunk_t *map;
-
-  {
-  return( map[ (int) (bit / (CHAR_BIT * sizeof (bitchunk_t))) ] &
-	  (1 << ((unsigned) bit % (CHAR_BIT * sizeof (bitchunk_t)))) );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Find_Inode( state, filename )				*/
-/*								*/
-/*		Find the i-node for the given file name.	*/
-/*								*/
-/****************************************************************/
-
-
-ino_t Find_Inode( s, filename )
-  de_state *s;
-  char *filename;
-
-  {
-  struct stat device_stat;
-  struct stat file_stat;
-  ino_t inode;
-
-
-  if ( fstat( s->device_d, &device_stat ) == -1 )
-    Error( "Can not fstat(2) file system device" );
-
-#ifdef S_IFLNK
-  if ( lstat( filename, &file_stat ) == -1 )
-#else
-  if ( stat( filename, &file_stat ) == -1 )
-#endif
-    {
-    Warning( "Can not find file %s", filename );
-    return( 0 );
-    }
-
-  if ( device_stat.st_rdev != file_stat.st_dev )
-    {
-    Warning( "File is not on device %s", s->device_name );
-    return( 0 );
-    }
-
-
-  inode = file_stat.st_ino;
-
-  if ( inode < 1  || inode > s->inodes )
-    {
-    Warning( "Illegal i-node number" );
-    return( 0 );
-    }
-
-  return( inode );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Exec_Shell()						*/
-/*								*/
-/*		Fork off a sub-process to exec() the shell.	*/
-/*								*/
-/****************************************************************/
-
-
-void Exec_Shell()
-
-  {
-  int pid = fork();
-
-  if ( pid == -1 )
-    return;
-
-
-  if ( pid == 0 )
-    {
-    /*  The child process  */
-
-    extern char **environ;
-    char *shell  =  getenv( "SHELL" );
-
-    if ( shell == NULL )
-      shell = "/bin/sh";
-
-    execle( shell, shell, (char *) 0, environ );
-
-    perror( shell );
-    exit( 127 );
-    }
-
-
-  /*  The parent process: ignore signals, wait for sub-process	*/
-
-  signal( SIGINT,  SIG_IGN );
-  signal( SIGQUIT, SIG_IGN );
-
-  {
-  int  status;
-  int  w;
-
-  while ( (w=wait(&status)) != pid  &&  w != -1 );
-  }
-
-  signal( SIGINT,  Sigint );
-  signal( SIGQUIT, Sigint );
-
-  return;
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Sigint()						*/
-/*								*/
-/*		Terminate the program on an interrupt (^C)	*/
-/*		or quit (^\) signal.				*/
-/*								*/
-/****************************************************************/
-
-
-void Sigint(n)
-int n;
-  {
-  Reset_Term();		/*  Restore terminal characteristics	*/
-
-  putchar( '\n' );
-
-  exit( 1 );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Error( text, ... )					*/
-/*								*/
-/*		Print an error message on stderr.		*/
-/*								*/
-/****************************************************************/
-
-
-#if __STDC__
-void Error( const char *text, ... )
-#else
-void Error( text )
-  char *text;
-#endif  
-
-  {
-  va_list argp;
-
-  Reset_Term();
-
-  fprintf( stderr, "\nde: " );
-  va_start( argp, text );
-  vfprintf( stderr, text, argp );
-  va_end( argp );
-  if ( errno != 0 )
-    fprintf( stderr, ": %s", strerror( errno ) );
-  fprintf( stderr, "\n" );
-
-  exit( 1 );
-  }
Index: trunk/minix/commands/de/de.h
===================================================================
--- trunk/minix/commands/de/de.h	(revision 9)
+++ 	(revision )
@@ -1,363 +1,0 @@
-/****************************************************************/
-/*								*/
-/*	de.h							*/
-/*								*/
-/*		Definitions for the "Disk editor".		*/
-/*								*/
-/****************************************************************/
-/*  origination         1989-Jan-15        Terrence W. Holm	*/
-/****************************************************************/
-
-
-/****************************************************************/
-/*								*/
-/*	de(1)							*/
-/*								*/
-/*  This is the MINIX disk editor. It allows the user to	*/
-/*  observe and modify a file system. It can also be used	*/
-/*  to recover unlink(2)'ed files				*/
-/*								*/
-/*  See the de(1) man page.					*/
-/*								*/
-/****************************************************************/
-
-
-/****************************************************************/
-/*								*/
-/*	de		   Copyright  Terrence W. Holm  1989	*/
-/*								*/
-/* This program was written for users of the Minix operating	*/
-/* system, and in the spirit of other public domain software	*/
-/* written for said system, this source code is made available	*/
-/* at no cost to everyone. I assume no responsibility for	*/
-/* damage to file systems caused by this program.		*/
-/*								*/
-/* This program (one .h, five .c's and a "man" page) may be	*/
-/* copied and/or modified subject to (1) no charge must be	*/
-/* made for distribution, other than for the medium, (2) all	*/
-/* modified sources must be clearly marked as such, (3) all	*/
-/* sources must carry this copyright.				*/
-/*								*/
-/****************************************************************/
-
-
-/****************************************************************/
-/*								*/
-/*	files							*/
-/*								*/
-/*	    de.h		Definitions			*/
-/*	    de.c		The main loop			*/
-/*	    de_stdin.c		Character input routines	*/
-/*	    de_stdout.c		Output routines			*/
-/*	    de_diskio.c		File system read/write		*/
-/*	    de_recover.c	File restoration routines	*/
-/*								*/
-/*	    de.1		"Man" page			*/
-/*	    Makefile		For "make"			*/
-/*	    README		Installation help		*/
-/*								*/
-/*								*/
-/*	fs/path.c was modified to support the 'x' command.	*/
-/*	fs/link.c and fs/open.c were changed for 'X'.		*/
-/*								*/
-/****************************************************************/
-#undef printf
-#include <stdio.h>
-#include <dirent.h>
-
-/*  General constants  */
-
-#define   MAX_STRING	60		/*  For all input lines	*/
-#define   MAX_PREV	8		/*  For 'p' command	*/
-#define   SEARCH_BUFFER (4*K)		/*  For '/' and 'n'	*/
-
-
-/*  Files  */
-
-#define   TMP      "/tmp"		/*  For "-r" output	*/
-#define   DEV	   "/dev"		/*  Where devices are	*/
-
-
-/*  a.out header constants  (see a.out.h, if you have it)  */
-
-#if (CHIP == INTEL)
-#define   A_OUT    0x0301
-#define   SPLIT    0x0420
-#endif
-
-#if (CHIP == M68000)
-#define   A_OUT    0x0301
-#define   SPLIT	   0x0B20
-#endif
-
-#if (CHIP == SPARC)
-#define   A_OUT    0x0301
-#define   SPLIT    0x0B20
-#endif
-
-/*  Each buffer is 1k.  In WORD mode 16 words (32 bytes) can be	*/
-/*  displayed at once. In BLOCK mode 1K bytes can be displayed.	*/
-/*  In MAP mode 2048 bits (256 bytes) are displayed.		*/
-
-#define   K		1024		/*  STD_BLK		*/
-#define   K_MASK	(~(K-1))	/*  Round to K boundary	*/
-#define   K_SHIFT	10		/*  Ie. 1<<10 = K	*/
-#define   PAGE_MASK	0x1f		/*  Word mode: 32 bytes	*/
-#define   PAGE_SHIFT    5		/*  Ie. 1<<5 = 32	*/
-#define   MAP_BITS_PER_BLOCK (8 * K)    /*  1k block, 8192 bits */
-#define   MAP_MASK	0xff		/*  256 bytes/screen	*/
-
-
-
-/*  Terminal i/o codes  */
-
-#define   CTRL_D	'\004'		/*  ASCII ^D		*/
-#define   BELL		'\007'		/*  ASCII bell code     */
-#define   BS		'\010'		/*  ASCII back space	*/
-#define   CTRL_U	'\025'		/*  ASCII ^U		*/
-#define	  ESCAPE  	'\033'		/*  ASCII escape code	*/
-#define   DEL           '\177'		/*  ASCII delete code   */
-
-
-/*  Input escape codes generated by the	Minix console.	*/
-/*  Format: ESC [ X. 					*/
-
-#define   ESC_HOME	('H' + 0x80)
-#define   ESC_UP	('A' + 0x80)
-#define   ESC_PGUP	('V' + 0x80)
-#define   ESC_LEFT	('D' + 0x80)
-#define   ESC_5		('G' + 0x80)
-#define   ESC_RIGHT	('C' + 0x80)
-#define   ESC_END	('Y' + 0x80)
-#define   ESC_DOWN	('B' + 0x80)
-#define   ESC_PGDN	('U' + 0x80)
-#define   ESC_PLUS	('T' + 0x80)
-#define   ESC_MINUS	('S' + 0x80)
-
-
-/*  Graphic box codes - only applicable for console display  */
-/*  in visual mode "map".				     */
-
-#if (CHIP == INTEL)
-#define   BOX_CLR	' '		/*  Empty box		*/
-#define   BOX_ALL	'\333'		/*  Filled box		*/
-#define   BOX_TOP	'\337'		/*  Filled upper half	*/
-#define   BOX_BOT	'\334'		/*  Filled lower half   */
-#endif
-
-#if (CHIP == M68000)
-/*  Please change these.  */
-#define   BOX_CLR	' '		/*  Empty box		*/
-#define   BOX_ALL	'='		/*  Filled box		*/
-#define   BOX_TOP	'-'		/*  Filled upper half	*/
-#define   BOX_BOT	'_'		/*  Filled lower half   */
-#endif
-
-#if (CHIP == SPARC)
-/*  Please change these.  */
-#define   BOX_CLR	' '		/*  Empty box		*/
-#define   BOX_ALL	'='		/*  Filled box		*/
-#define   BOX_TOP	'-'		/*  Filled upper half	*/
-#define   BOX_BOT	'_'		/*  Filled lower half   */
-#endif
-
-/*  Move positions for the output display.  */
-
-#define   STATUS_COLUMN	 2
-#define   STATUS_LINE    0
-#define   BLOCK_COLUMN	 4
-#define   BLOCK_LINE	 4
-#define   INFO_COLUMN	 30
-#define   INFO_LINE	 BLOCK_LINE
-#define   PROMPT_COLUMN	 0
-#define   PROMPT_LINE	 23
-#define   WARNING_COLUMN 5
-#define   WARNING_LINE   10
-
-
-
-/*  Values returned by Process() and Get_Filename()  */
-
-#define   OK		  0		/*  No update required	*/
-#define   REDRAW	  1		/*  Redraw whole screen	*/
-#define   REDRAW_POINTERS 2		/*  Redraw just ptrs	*/
-#define   ERROR		  3		/*  Beep		*/
-
-
-/*  Visual modes  */
-
-#define   WORD	   1
-#define   BLOCK    2
-#define   MAP	   3
-
-typedef  unsigned short word_t;		/*  For most user i/o	*/
-#if _WORD_SIZE == 2
-typedef  unsigned int Word_t;		/*  What it should always be */
-#else
-typedef  int Word_t;			/*  Unsigned promotion under ANSI C */
-#endif
-
-#ifndef I_MAP_SLOTS
-/* Max number of inode and zone map blocks we can handle. */
-#define I_MAP_SLOTS	8
-#define Z_MAP_SLOTS	(sizeof(char *) == 2 ? 16 : 128)
-#endif
-
-typedef  struct  de_state		/*  State of disk ed.	*/
-  {
-  /*  Information from super block  */
-  /*  The types here are mostly promoted types for simplicity	*/
-  /*  and efficiency.						*/
-
-  unsigned inodes;			/*  Number of i-nodes	*/
-  zone_t zones;				/*  Total # of blocks	*/
-  unsigned inode_maps;			/*  I-node map blocks	*/
-  unsigned zone_maps;			/*  Zone map blocks	*/
-  unsigned inode_blocks;		/*  I-node blocks	*/
-  unsigned first_data;			/*  Total non-data blks	*/
-  int magic;				/*  Magic number	*/
-
-  /* Numbers derived from the magic number */  
-  
-  unsigned char is_fs;			/*  Nonzero for good fs	*/
-  unsigned char v1;			/*  Nonzero for V1 fs	*/
-  unsigned inode_size;			/*  Size of disk inode	*/
-  unsigned nr_indirects;		/*  # indirect blocks	*/
-  unsigned zone_num_size;		/*  Size of disk z num	*/
-  int block_size;			/*  FS block size       */
-
-  /* Other derived numbers */  
-  
-  bit_t inodes_in_map;			/*  Bits in i-node map	*/
-  bit_t zones_in_map;			/*  Bits in zone map	*/
-  int ndzones;				/*  # direct zones in an inode */
-
-  /*  Information from map blocks  */
-
-  bitchunk_t inode_map[ I_MAP_SLOTS * K / sizeof (bitchunk_t) ];
-  bitchunk_t zone_map[ Z_MAP_SLOTS * K / sizeof (bitchunk_t) ];
-
-  /*  Information for current block  */
-
-  off_t address;			/*  Current address	*/
-  off_t last_addr;			/*  For erasing ptrs	*/
-  zone_t block;				/*  Current block (1K)	*/
-  unsigned offset;			/*  Offset within block	*/
-
-  char buffer[ _MAX_BLOCK_SIZE ];
-
-  /*  Display state  */
-
-  int  mode;				/*  WORD, BLOCK or MAP	*/
-  int  output_base;			/*  2, 8, 10, or 16	*/
-
-  /*  Search information  */
-
-  char search_string[ MAX_STRING + 1 ];	/*  For '/' and 'n'	*/
-  off_t prev_addr[ MAX_PREV ];		/*  For 'p' command	*/
-  int   prev_mode[ MAX_PREV ];
-
-  /*  File information  */
-
-  char *device_name;			/*  From command line	*/
-  int   device_d;
-  int   device_mode;			/*  O_RDONLY or O_RDWR	*/
-  zone_t device_size;			/*  Number of blocks	*/
-
-  char  file_name[ MAX_STRING + 1 ];	/*  For 'w' and 'W'	*/
-  FILE *file_f;
-  int   file_written;			/*  Flag if written to	*/
-
-  }  de_state;
-
-
-
-/*  Forward references for external routines  */
-
-/*  de.c  */
-
-_PROTOTYPE(void main , (int argc , char *argv []));
-_PROTOTYPE(int Process , (de_state *s , int c ));
-
-#if __STDC__
-void  Error( const char *text, ... );
-#else
-void  Error();
-#endif
-
-_PROTOTYPE(int In_Use , (bit_t bit , bitchunk_t *map ));
-_PROTOTYPE(ino_t Find_Inode , (de_state *s , char *filename ));
-
-
-/*  de_stdin.c  */
-
-_PROTOTYPE(void Save_Term , (void));
-_PROTOTYPE(void Set_Term , (void));
-_PROTOTYPE(void Reset_Term , (void));
-_PROTOTYPE(int Get_Char , (void));
-_PROTOTYPE(char *Get_Line , (void));
-_PROTOTYPE(int Arrow_Esc , (int c ));
-
-/*  de_stdout.c  */
-
-_PROTOTYPE(int Init_Termcap , (void));
-_PROTOTYPE(void Draw_Help_Screen , (de_state *s ));
-_PROTOTYPE(void Wait_For_Key , (void));
-_PROTOTYPE(void Draw_Prompt , (char *string ));
-_PROTOTYPE(void Erase_Prompt , (void));
-
-_PROTOTYPE(void Draw_Screen , (de_state *s ));
-_PROTOTYPE(void Draw_Strings , (de_state *s ));
-_PROTOTYPE(void Draw_Pointers , (de_state *s ));
-_PROTOTYPE(void Print_Ascii , (int c ));
-
-_PROTOTYPE(void Goto , (int column , int line ));
-_PROTOTYPE(void Block_Type , (de_state *s ));
-_PROTOTYPE(void Draw_Words , (de_state *s ));
-_PROTOTYPE(void Draw_Info , (de_state *s ));
-_PROTOTYPE(void Draw_Block , (char *block ));
-_PROTOTYPE(void Draw_Map , (char *block , int max_bits ));
-_PROTOTYPE(void Draw_Offset , (de_state *s ));
-_PROTOTYPE(void Word_Pointers , (off_t old_addr , off_t new_addr ));
-_PROTOTYPE(void Block_Pointers , (off_t old_addr , off_t new_addr ));
-_PROTOTYPE(void Map_Pointers , (off_t old_addr , off_t new_addr ));
-_PROTOTYPE(void Print_Number , (Word_t number , int output_base ));
-_PROTOTYPE(void Draw_Zone_Numbers , (de_state *s , struct inode *inode ,
-						int zindex , int zrow ));
-
-#if __STDC__
-void  Warning( const char *text, ... );
-#else
-void  Warning();
-#endif
-
-
-/*  de_diskio.c  */
-
-_PROTOTYPE(void Read_Disk , (de_state *s , off_t block_addr , char *buffer ));
-_PROTOTYPE(void Read_Block , (de_state *s , char *buffer ));
-_PROTOTYPE(void Read_Super_Block , (de_state *s ));
-_PROTOTYPE(void Read_Bit_Maps , (de_state *s ));
-_PROTOTYPE(off_t Search , (de_state *s , char *string ));
-_PROTOTYPE(void Write_Word , (de_state *s , Word_t word ));
-
-
-/*  de_recover.c  */
-
-_PROTOTYPE(int Path_Dir_File , (char *path_name , char **dir_name ,
-							char **file_name ));
-_PROTOTYPE(char *File_Device , (char *file_name ));
-_PROTOTYPE(ino_t Find_Deleted_Entry , (de_state *s , char *path_name ));
-_PROTOTYPE(off_t Recover_Blocks , (de_state *s ));
-
-
-#undef    printf			/*  Because fs/const.h	*/
-					/*  defines it.		*/
-
-
-/*  Static functions are all pre-declared FORWARD but none are	*/
-/*  declared static yet - this can wait until all functions are	*/
-/*  declared with prototypes.					*/
-
-#undef FORWARD
-#define FORWARD /* static */
Index: trunk/minix/commands/de/de_diskio.c
===================================================================
--- trunk/minix/commands/de/de_diskio.c	(revision 9)
+++ 	(revision )
@@ -1,352 +1,0 @@
-/****************************************************************/
-/*								*/
-/*	de_diskio.c						*/
-/*								*/
-/*		Reading and writing to a file system device.	*/
-/*								*/
-/****************************************************************/
-/*  origination         1989-Jan-15        Terrence W. Holm	*/
-/****************************************************************/
-
-
-#include <minix/config.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <limits.h>
-#include <string.h>
-#include <dirent.h>
-
-#include <minix/const.h>
-#include <minix/type.h>
-#include "../../servers/fs/const.h"
-#include "../../servers/fs/type.h"
-#include "../../servers/fs/super.h"
-#include "../../servers/fs/inode.h"
-#include <minix/fslib.h>
-
-#include "de.h"
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Read_Disk( state, block_addr, buffer )			*/
-/*								*/
-/*		Reads a 1k block at "block_addr" into "buffer".	*/
-/*								*/
-/****************************************************************/
-
-
-void Read_Disk( s, block_addr, buffer )
-  de_state *s;
-  off_t  block_addr;
-  char  *buffer;
-
-  {
-  if ( lseek( s->device_d, block_addr, SEEK_SET ) == -1 )
-    Error( "Error seeking %s", s->device_name );
-
-  if ( read( s->device_d, buffer, s->block_size ) != s->block_size )
-    Error( "Error reading %s", s->device_name );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Read_Block( state, buffer )				*/
-/*								*/
-/*		Reads a 1k block from "state->address" into	*/
-/*		"buffer". Checks "address", and updates		*/
-/*		"block" and "offset".				*/
-/*								*/
-/****************************************************************/
-
-
-void Read_Block( s, buffer )
-  de_state *s;
-  char *buffer;
-
-  {
-  off_t end_addr;
-  off_t block_addr;
-  end_addr = (long) s->device_size * s->block_size - 1;
-
-  if ( s->address < 0 )
-    s->address = 0L;
-
-  if ( s->address > end_addr )
-    s->address = end_addr;
-
-  /*  The address must be rounded off for  */
-  /*  certain visual display modes.        */
-
-  if ( s->mode == WORD )
-    s->address &= ~1L;
-  else if ( s->mode == MAP )
-    s->address &= ~3L;
-
-
-  block_addr = s->address & K_MASK;
-
-  s->block  = (zone_t) (block_addr >> K_SHIFT);
-  s->offset = (unsigned) (s->address - block_addr);
-
-  Read_Disk( s, block_addr, buffer );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Read_Super_Block( state )				*/
-/*								*/
-/*		Read and check the super block.			*/
-/*								*/
-/****************************************************************/
-
-
-void Read_Super_Block( s )
-  de_state *s;
-
-  {
-  struct super_block *super = (struct super_block *) s->buffer;
-  unsigned inodes_per_block;
-  off_t size;
-
-  s->block_size = K;
-  Read_Disk( s, (long) SUPER_BLOCK_BYTES, s->buffer );
-
-  s->magic = super->s_magic;
-  if ( s->magic == SUPER_MAGIC )
-    {
-    s->is_fs = TRUE;
-    s->v1 = TRUE;
-    s->inode_size = V1_INODE_SIZE;
-    inodes_per_block = V1_INODES_PER_BLOCK;
-    s->nr_indirects = V1_INDIRECTS;
-    s->zone_num_size = V1_ZONE_NUM_SIZE;
-    s->zones = super->s_nzones;
-    s->ndzones = V1_NR_DZONES;
-    s->block_size = _STATIC_BLOCK_SIZE;
-    }
-  else if ( s->magic == SUPER_V2 || s->magic == SUPER_V3)
-    {
-    if(s->magic == SUPER_V3)
-    	s->block_size = super->s_block_size;
-    else
-    	s->block_size = _STATIC_BLOCK_SIZE;
-    s->is_fs = TRUE;
-    s->v1 = FALSE;
-    s->inode_size = V2_INODE_SIZE;
-    inodes_per_block = V2_INODES_PER_BLOCK(s->block_size);
-    s->nr_indirects = V2_INDIRECTS(s->block_size);
-    s->zone_num_size = V2_ZONE_NUM_SIZE;
-    s->zones = super->s_zones;
-    s->ndzones = V2_NR_DZONES;
-    }
-  else  
-    {
-    if ( super->s_magic == SUPER_REV )
-      Warning( "V1-bytes-swapped file system (?)" );
-    else if ( super->s_magic == SUPER_V2_REV )
-      Warning( "V2-bytes-swapped file system (?)" );
-    else  
-      Warning( "Not a Minix file system" );
-    Warning( "The file system features will not be available" );  
-    s->zones = 100000L;
-    return;
-    }
-
-  s->inodes = super->s_ninodes;
-  s->inode_maps = bitmapsize( (bit_t) s->inodes + 1 , s->block_size);
-  if ( s->inode_maps != super->s_imap_blocks )
-    {
-    if ( s->inode_maps > super->s_imap_blocks )
-      Error( "Corrupted inode map count or inode count in super block" );
-    else  
-      Warning( "Count of inode map blocks in super block suspiciously high" );
-    s->inode_maps = super->s_imap_blocks;
-    }
-
-  s->zone_maps = bitmapsize( (bit_t) s->zones , s->block_size);
-  if ( s->zone_maps != super->s_zmap_blocks )
-    {
-    if ( s->zone_maps > super->s_zmap_blocks )
-      Error( "Corrupted zone map count or zone count in super block" );
-    else
-      Warning( "Count of zone map blocks in super block suspiciously high" );
-    s->zone_maps = super->s_zmap_blocks;
-    }
-
-  s->inode_blocks = (s->inodes + inodes_per_block - 1) / inodes_per_block;
-  s->first_data   = 2 + s->inode_maps + s->zone_maps + s->inode_blocks;
-  if ( s->first_data != super->s_firstdatazone )
-  {
-    if ( s->first_data > super->s_firstdatazone )
-      Error( "Corrupted first data zone offset or inode count in super block" );
-    else
-      Warning( "First data zone in super block suspiciously high" );
-    s->first_data = super->s_firstdatazone;
-  }  
-
-  s->inodes_in_map = s->inodes + 1;
-  s->zones_in_map  = s->zones + 1 - s->first_data;
-
-  /*
-  if ( s->zones != s->device_size )
-    Warning( "Zone count does not equal device size" );
-  */
-
-  s->device_size = s->zones;
-
-  if ( super->s_log_zone_size != 0 )
-    Error( "Can not handle multiple blocks per zone" );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Read_Bit_Maps( state )					*/
-/*								*/
-/*		Read in the i-node and zone bit maps from the	*/
-/*		specified file system device.			*/
-/*								*/
-/****************************************************************/
-
-
-void Read_Bit_Maps( s )
-  de_state *s;
-
-  {
-  int i;
-
-  if ( s->inode_maps > I_MAP_SLOTS  ||  s->zone_maps > Z_MAP_SLOTS )
-    {
-    Warning( "Super block specifies too many bit map blocks" );
-    return;
-    }
-
-  for ( i = 0;  i < s->inode_maps;  ++i )
-    {
-    Read_Disk( s, (long) (2 + i) * K,
-	       (char *) &s->inode_map[ i * K / sizeof (bitchunk_t ) ] );
-    }
-
-  for ( i = 0;  i < s->zone_maps;  ++i )
-    {
-    Read_Disk( s, (long) (2 + s->inode_maps + i) * K,
-	       (char *) &s->zone_map[ i * K / sizeof (bitchunk_t ) ] );
-    }
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Search( state, string )					*/
-/*								*/
-/*		Search from the current address for the ASCII	*/
-/*		"string" on the device.				*/
-/*								*/
-/****************************************************************/
-
-
-off_t Search( s, string )
-  de_state *s;
-  char *string;
-
-  {
-  off_t address   = s->address + 1;
-  off_t last_addr = address;
-  char  buffer[ SEARCH_BUFFER ];
-  int   offset;
-  int   tail_length = strlen( string ) - 1;
-  int   count = SEARCH_BUFFER;
-  int   last_offset;
-
-
-  for (  ;  count == SEARCH_BUFFER;  address += SEARCH_BUFFER - tail_length )
-    {
-    if ( lseek( s->device_d, address, SEEK_SET ) == -1 )
-      Error( "Error seeking %s", s->device_name );
-
-    if ( (count = read( s->device_d, buffer, SEARCH_BUFFER)) == -1 )
-      Error( "Error reading %s", s->device_name );
-
-
-    if ( address - last_addr >= 500L * K )
-      {
-      putchar( '.' );
-      fflush( stdout );
-
-      last_addr += 500L * K;
-      }
-
-
-    last_offset = count - tail_length;
-
-    for ( offset = 0;  offset < last_offset;  ++offset )
-      {
-      register char c = buffer[ offset ];
-
-      if ( c == *string )
-	{
-	char *tail_buffer = &buffer[ offset + 1 ];
-	char *tail_string = string + 1;
-
-	do
-	  {
-	  if ( *tail_string == '\0' )
-	    return( address + offset );
-	  }
-          while ( *tail_buffer++ == *tail_string++ );
-        }
-      }  /*  end for ( offset )  */
-    }  /*  end for ( address )  */
-
-  return( -1L );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Write_Word( state, word )				*/
-/*								*/
-/*		Write a word at address.			*/
-/*								*/
-/****************************************************************/
-
-
-void Write_Word( s, word )
-  de_state *s;
-  word_t word;
-
-  {
-  if ( s->address & 01 )
-    Error( "Internal fault (unaligned address)" );
-
-  if ( lseek( s->device_d, s->address, SEEK_SET ) == -1 )
-    Error( "Error seeking %s", s->device_name );
-
-  if ( write( s->device_d, (char *) &word, sizeof word ) != sizeof word )
-    Error( "Error writing %s", s->device_name );
-  }
Index: trunk/minix/commands/de/de_recover.c
===================================================================
--- trunk/minix/commands/de/de_recover.c	(revision 9)
+++ 	(revision )
@@ -1,612 +1,0 @@
-/****************************************************************/
-/*								*/
-/*	de_recover.c						*/
-/*								*/
-/*		File restoration routines.			*/
-/*								*/
-/****************************************************************/
-/*  origination         1989-Jan-21        Terrence W. Holm	*/
-/*  handle "holes"	1989-Jan-28	   Terrence W. Holm	*/
-/****************************************************************/
-
-
-#include <minix/config.h>
-#include <sys/types.h>
-#include <sys/dir.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <pwd.h>
-#include <string.h>
-#include <unistd.h>
-#include <dirent.h>
-
-#include <minix/const.h>
-#include <minix/type.h>
-#include "../../servers/fs/const.h"
-#include "../../servers/fs/type.h"
-#include "../../servers/fs/inode.h"
-#include <minix/fslib.h>
-
-#include "de.h"
-
-_PROTOTYPE(int Indirect, (de_state *s, zone_t block, off_t *size, int dblind));
-_PROTOTYPE(int Data_Block, (de_state *s, zone_t block, off_t *file_size ));
-_PROTOTYPE(int Free_Block, (de_state *s, zone_t block ));
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Path_Dir_File( path_name, dir_name, file_name )		*/
-/*								*/
-/*		Split "path_name" into a directory name and	*/
-/*		a file name.					*/
-/*								*/
-/*		Zero is returned on error conditions.		*/
-/*								*/
-/****************************************************************/
-
-
-int Path_Dir_File( path_name, dir_name, file_name )
-  char  *path_name;
-  char **dir_name;
-  char **file_name;
-
-  {
-  char *p;
-  static char directory[ MAX_STRING + 1 ];
-  static char filename[ MAX_STRING + 1 ];
-
-
-  if ( (p = strrchr( path_name, '/' )) == NULL )
-    {
-    strcpy( directory, "." );
-    strcpy( filename, path_name );
-    }
-  else
-    {
-    *directory = '\0';
-    strncat( directory, path_name, p - path_name );
-    strcpy( filename, p + 1 );
-    }
-
-  if ( *directory == '\0' )
-    strcpy( directory, "/" );
-
-  if ( *filename == '\0' )
-    {
-    Warning( "A file name must follow the directory name" );
-    return( 0 );
-    }
-
-  *dir_name  = directory;
-  *file_name = filename;
-
-  return( 1 );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	File_Device( file_name )				*/
-/*								*/
-/*		Return the name of the file system device	*/
-/*		containing the file "file_name".		*/
-/*								*/
-/*		This is used if the "-r" option was specified.	*/
-/*		In this case we have only been given a file	*/
-/*		name, and must determine which file system	*/
-/*		device to open.					*/
-/*								*/
-/*		NULL is returned on error conditions.		*/
-/*								*/
-/****************************************************************/
-
-
-
-char *File_Device( file_name )
-  char *file_name;
-
-  {
-  struct stat file_stat;
-  struct stat device_stat;
-  int dev_d;
-  struct direct entry;
-  static char device_name[ NAME_MAX + 1 ];
-
-
-  if ( access( file_name, R_OK ) != 0 )
-    {
-    Warning( "Can not find %s", file_name );
-    return( NULL );
-    }
-
-
-  if ( stat( file_name, &file_stat ) == -1 )
-    {
-    Warning( "Can not stat(2) %s", file_name );
-    return( NULL );
-    }
-
-
-  /*  Open /dev for reading  */
-
-  if ( (dev_d = open( DEV, O_RDONLY )) == -1 )
-    {
-    Warning( "Can not read %s", DEV );
-    return( NULL );
-    }
-
-
-  while ( read( dev_d, (char *) &entry, sizeof(struct direct) )
-				     == sizeof(struct direct) )
-    {
-    if ( entry.d_ino == 0 )
-      continue;
-
-    strcpy( device_name, DEV );
-    strcat( device_name, "/" );
-    strncat( device_name, entry.d_name, NAME_MAX );
-
-    if ( stat( device_name, &device_stat ) == -1 )
-      continue;
-
-    if ( (device_stat.st_mode & S_IFMT) != S_IFBLK )
-      continue;
-
-    if ( file_stat.st_dev == device_stat.st_rdev )
-      {
-      close( dev_d );
-      return( device_name );
-      }
-    }
-
-  close( dev_d );
-
-  Warning( "The device containing file %s is not in %s", file_name, DEV );
-
-  return( NULL );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Find_Deleted_Entry( state, path_name )			*/
-/*								*/
-/*		Split "path_name" into a directory name and	*/
-/*		a file name. Then search the directory for	*/
-/*		an entry that would match the deleted file	*/
-/*		name. (Deleted entries have a zero i-node	*/
-/*		number, but the original i-node number is 	*/
-/*		placed at the end of the file name.)		*/
-/*								*/
-/*		If successful an i-node number is returned,	*/
-/*		else zero is returned.				*/
-/*								*/
-/****************************************************************/
-
-
-ino_t Find_Deleted_Entry( s, path_name )
-  de_state *s;
-  char *path_name;
-
-  {
-  char *dir_name;
-  char *file_name;
-
-
-  /*  Check if the file exists  */
-
-  if ( access( path_name, F_OK ) == 0 )
-    {
-    Warning( "File has not been deleted" );
-    return( 0 );
-    }
-
-
-  /*  Split the path name into a directory and a file name  */
-
-  if ( ! Path_Dir_File( path_name, &dir_name, &file_name ) )
-    return( 0 );
-
-
-  /*  Check to make sure the user has read permission on  */
-  /*  the directory.					  */
-
-  if ( access( dir_name, R_OK ) != 0 )
-    {
-    Warning( "Can not find %s", dir_name );
-    return( 0 );
-    }
-
-
-  /*  Make sure "dir_name" is really a directory. */
-  {
-  struct stat dir_stat;
-
-  if ( stat( dir_name, &dir_stat ) == -1   ||
-		 (dir_stat.st_mode & S_IFMT) != S_IFDIR )
-    {
-    Warning( "Can not find directory %s", dir_name );
-    return( 0 );
-    }
-  }
-
-
-  /*  Make sure the directory is on the current  */
-  /*  file system device.                        */
-
-  if ( Find_Inode( s, dir_name ) == 0 )
-    return( 0 );
-
-
-  /*  Open the directory and search for the lost file name.  */
-  {
-  int   dir_d;
-  int   count;
-  struct direct entry;
-
-  if ( (dir_d = open( dir_name, O_RDONLY )) == -1 )
-    {
-    Warning( "Can not read directory %s", dir_name );
-    return( 0 );
-    }
-
-  while ( (count = read( dir_d, (char *) &entry, sizeof(struct direct) ))
-					      == sizeof(struct direct) )
-    {
-    if ( entry.d_ino == 0  &&
-	strncmp( file_name, entry.d_name, NAME_MAX - sizeof(ino_t) ) == 0 )
-      {
-      ino_t inode = *( (ino_t *) &entry.d_name[ NAME_MAX - sizeof(ino_t) ] );
-
-      close( dir_d );
-
-      if ( inode < 1  || inode > s->inodes )
-    	{
-    	Warning( "Illegal i-node number" );
-    	return( 0 );
-    	}
-
-      return( inode );
-      }
-    }
-
-  close( dir_d );
-
-  if ( count == 0 )
-    Warning( "Can not find a deleted entry for %s", file_name );
-  else
-    Warning( "Problem reading directory %s", dir_name );
-
-  return( 0 );
-  }
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Recover_Blocks( state )					*/
-/*								*/
-/*		Try to recover all the blocks for the i-node	*/
-/*		currently pointed to by "s->address". The	*/
-/*		i-node and all of the blocks must be marked	*/
-/*		as FREE in the bit maps. The owner of the	*/
-/*		i-node must match the current real user name.	*/
-/*								*/
-/*		"Holes" in the original file are maintained.	*/
-/*		This allows moving sparse files from one device	*/
-/*		to another.					*/
-/*								*/
-/*		On any error -1L is returned, otherwise the	*/
-/*		size of the recovered file is returned.		*/
-/*								*/
-/*								*/
-/*		NOTE: Once a user has read access to a device,	*/
-/*		there is a security hole, as we lose the	*/
-/*		normal file system protection. For convenience,	*/
-/*		de(1) is sometimes set-uid root, this allows	*/
-/*		anyone to use the "-r" option. When recovering,	*/
-/*		Recover_Blocks() can only superficially check	*/
-/*		the validity of a request.			*/
-/*								*/
-/****************************************************************/
-
-
-off_t Recover_Blocks( s )
-  de_state *s;
-
-  {
-  struct inode core_inode;
-  d1_inode *dip1;
-  d2_inode *dip2;
-  struct inode *inode = &core_inode;
-  bit_t node = (s->address - (s->first_data - s->inode_blocks) * K) /
-		s->inode_size + 1;
-
-  dip1 = (d1_inode *) &s->buffer[ s->offset & ~ PAGE_MASK ];
-  dip2 = (d2_inode *) &s->buffer[ s->offset & ~ PAGE_MASK
-					    & ~ (V2_INODE_SIZE-1) ];
-  conv_inode( inode, dip1, dip2, READING, s->magic );
-
-  if ( s->block < s->first_data - s->inode_blocks  ||
-	    s->block >= s->first_data )
-    {
-    Warning( "Not in an inode block" );
-    return( -1L );
-    }
-
-
-  /*  Is this a valid, but free i-node?  */
-
-  if ( node > s->inodes )
-    {
-    Warning( "Not an inode" );
-    return( -1L );
-    }
-
-  if ( In_Use(node, s->inode_map) )
-    {
-    Warning( "I-node is in use" );
-    return( -1L );
-    }
-
-
-  /*  Only recover files that belonged to the real user.  */
-
-  {
-  uid_t real_uid = getuid();
-  struct passwd *user = getpwuid( real_uid );
-
-  if ( real_uid != SU_UID  &&  real_uid != inode->i_uid )
-    {
-    Warning( "I-node did not belong to user %s", user ? user->pw_name : "" );
-    return( -1L );
-    }
-  }
-
-
-  /*  Recover all the blocks of the file.  */
-
-  {
-  off_t file_size = inode->i_size;
-  int i;
-
-
-  /*  Up to s->ndzones pointers are stored in the i-node.  */
-
-  for ( i = 0;  i < s->ndzones;  ++i )
-    {
-    if ( file_size == 0 )
-	return( inode->i_size );
-
-    if ( ! Data_Block( s, inode->i_zone[ i ], &file_size ) )
-      return( -1L );
-    }
-
-  if ( file_size == 0 )
-    return( inode->i_size );
-
-
-  /*  An indirect block can contain up to inode->i_indirects more blk ptrs.  */
-
-  if ( ! Indirect( s, inode->i_zone[ s->ndzones ], &file_size, 0 ) )
-    return( -1L );
-
-  if ( file_size == 0 )
-    return( inode->i_size );
-
-
-  /*  A double indirect block can contain up to inode->i_indirects blk ptrs. */
-
-  if ( ! Indirect( s, inode->i_zone[ s->ndzones+1 ], &file_size, 1 ) )
-    return( -1L );
-
-  if ( file_size == 0 )
-    return( inode->i_size );
-
-  Error( "Internal fault (file_size != 0)" );
-  }
-
-  /* NOTREACHED */
-  return( -1L );
-  }
-
-
-
-
-
-
-/*  Indirect( state, block, &file_size, double )
- *
- *  Recover all the blocks pointed to by the indirect block
- *  "block",  up to "file_size" bytes. If "double" is true,
- *  then "block" is a double-indirect block pointing to
- *  V*_INDIRECTS indirect blocks.
- *
- *  If a "hole" is encountered, then just seek ahead in the
- *  output file.
- */
-
-
-int Indirect( s, block, file_size, dblind )
-  de_state *s;
-  zone_t   block;
-  off_t    *file_size;
-  int       dblind;
-
-  {
-  union
-    {
-    zone1_t ind1[ V1_INDIRECTS ];
-    zone_t  ind2[ V2_INDIRECTS(_MAX_BLOCK_SIZE) ];
-    } indirect;
-  int  i;
-  zone_t zone;
-
-  /*  Check for a "hole".  */
-
-  if ( block == NO_ZONE )
-    {
-    off_t skip = (off_t) s->nr_indirects * K;
-
-    if ( *file_size < skip  ||  dblind )
-      {
-      Warning( "File has a hole at the end" );
-      return( 0 );
-      }
-
-    if ( fseek( s->file_f, skip, SEEK_CUR ) == -1 )
-      {
-      Warning( "Problem seeking %s", s->file_name );
-      return( 0 );
-      }
-
-    *file_size -= skip;
-    return( 1 );
-    }
-
-
-  /*  Not a "hole". Recover indirect block, if not in use.  */
-
-  if ( ! Free_Block( s, block ) )
-    return( 0 );
-
-
-  Read_Disk( s, (long) block << K_SHIFT, (char *) &indirect );
-
-  for ( i = 0;  i < s->nr_indirects;  ++i )
-    {
-    if ( *file_size == 0 )
-	return( 1 );
-
-    zone = (s->v1 ? indirect.ind1[ i ] : indirect.ind2[ i ]);
-    if ( dblind )
-      {
-      if ( ! Indirect( s, zone, file_size, 0 ) )
-	return( 0 );
-      }
-    else
-      {
-      if ( ! Data_Block( s, zone, file_size ) )
-        return( 0 );
-      }
-    }
-
-  return( 1 );
-  }
-
-
-
-
-
-
-/*  Data_Block( state, block, &file_size )
- *
- *  If "block" is free then write  Min(file_size, k)
- *  bytes from it onto the current output file.
- *
- *  If "block" is zero, this means that a 1k "hole"
- *  is in the file. The recovered file maintains
- *  the reduced size by not allocating the block.
- *
- *  The file size is decremented accordingly.
- */
-
-
-int Data_Block( s, block, file_size )
-  de_state *s;
-  zone_t   block;
-  off_t    *file_size;
-
-  {
-  char buffer[ K ];
-  off_t block_size = *file_size > K ? K : *file_size;
-
-
-  /*  Check for a "hole".  */
-
-  if ( block == NO_ZONE )
-    {
-    if ( block_size < K )
-      {
-      Warning( "File has a hole at the end" );
-      return( 0 );
-      }
-
-    if ( fseek( s->file_f, block_size, SEEK_CUR ) == -1 )
-      {
-      Warning( "Problem seeking %s", s->file_name );
-      return( 0 );
-      }
-
-    *file_size -= block_size;
-    return( 1 );
-    }
-
-
-  /*  Block is not a "hole". Copy it to output file, if not in use.  */
-
-  if ( ! Free_Block( s, block ) )
-    return( 0 );
-
-  Read_Disk( s, (long) block << K_SHIFT, buffer );
-
-
-  if ( fwrite( buffer, 1, (size_t) block_size, s->file_f )
-       != (size_t) block_size )
-    {
-    Warning( "Problem writing %s", s->file_name );
-    return( 0 );
-    }
-
-  *file_size -= block_size;
-  return( 1 );
-  }
-
-
-
-
-
-
-/*  Free_Block( state, block )
- *
- *  Make sure "block" is a valid data block number, and it
- *  has not been allocated to another file.
- */
-
-
-int Free_Block( s, block )
-  de_state *s;
-  zone_t  block;
-
-  {
-  if ( block < s->first_data  ||  block >= s->zones )
-    {
-    Warning( "Illegal block number" );
-    return( 0 );
-    }
-
-  if ( In_Use( (bit_t) (block - (s->first_data - 1)), s->zone_map ) )
-    {
-    Warning( "Encountered an \"in use\" data block" );
-    return( 0 );
-    }
-
-  return( 1 );
-  }
-
Index: trunk/minix/commands/de/de_stdin.c
===================================================================
--- trunk/minix/commands/de/de_stdin.c	(revision 9)
+++ 	(revision )
@@ -1,298 +1,0 @@
-/****************************************************************/
-/*								*/
-/*	de_stdin.c						*/
-/*								*/
-/*		Processing input from the "de" user.		*/
-/*								*/
-/****************************************************************/
-/*  origination         1989-Jan-15        Terrence W. Holm	*/
-/****************************************************************/
-
-
-#include <sys/types.h>
-#include <termios.h>
-#include <signal.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#include <minix/config.h>
-#include <minix/const.h>
-#include "../../servers/fs/const.h"
-#include "../../servers/fs/inode.h"
-
-#include "de.h"
-
-FORWARD _PROTOTYPE(int Timed_Get_Char , (int time ));
-FORWARD _PROTOTYPE(void Timed_Out , (int sig));
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Save_Term()						*/
-/*								*/
-/*		Save the current terminal characteristics.	*/
-/*								*/
-/*								*/
-/*	Set_Term()						*/
-/*								*/
-/*		Set up the terminal characteristics.		*/
-/*								*/
-/*								*/
-/*	Reset_Term()						*/
-/*								*/
-/*		Restore the terminal characteristics.		*/
-/*								*/
-/****************************************************************/
-
-
-static struct termios saved_term;
-
-
-void Save_Term()
-
-  {
-  tcgetattr( 0, &saved_term );
-  }
-
-
-
-
-void Set_Term()
-
-  {
-  struct termios term;
-
-  term = saved_term;
-
-
-  /*  No tab expansion, no echo, don't map ^M to ^J, cbreak mode  */
-
-  term.c_iflag &= ~ICRNL;
-  term.c_oflag &= ~OPOST;
-  term.c_lflag &= ~ICANON & ~ECHO;
-
-
-  /*  Change the interrupt character to ^C  */
-
-  term.c_cc[VINTR] = '\003';
-
-  tcsetattr( 0, TCSANOW, &term );
-  }
-
-
-
-
-void Reset_Term()
-
-  {
-  tcsetattr( 0, TCSANOW, &saved_term );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Get_Char()						*/
-/*								*/
-/*		Return the next input character. Escape		*/
-/*		sequences are mapped to special codes.		*/
-/*								*/
-/****************************************************************/
-
-
-int Get_Char()
-  {
-  int c;
-  static int unget_char = EOF;
-
-
-  /*  Flush the output to the screen before waiting  */
-  /*  for input from the user.			     */
-
-  fflush( stdout );
-
-  if ( unget_char == EOF )
-    {
-    while ( (c = Timed_Get_Char( 60 * 60 )) < EOF )
-      printf( "%c", BELL );
-    }
-  else
-    {
-    c = unget_char;
-    unget_char = EOF;
-    }
-
-  if ( c == EOF )
-    return( EOF );
-
-  if ( c != ESCAPE )
-    return( c );
-
-  if ( (c = Timed_Get_Char( 1 )) <= EOF )
-    return( ESCAPE );
-
-  if ( c != '[' )
-    {
-    unget_char = c;
-    return( ESCAPE );
-    }
-
-  if ( (c = Timed_Get_Char( 1 )) <= EOF )
-    {
-    unget_char = '[';
-    return( ESCAPE );
-    }
-
-  return( c | 0x80 );   /* Flag ESC [ x  */
-  }
-
-
-
-
-
-
-int Timed_Get_Char( time )
-  int time;
-
-  {
-  char c;
-  int  count;
-
-  signal( SIGALRM, Timed_Out );
-
-  alarm( time );
-  count = read( 0, &c, 1 );
-  alarm( 0 );
-
-  if ( count <= 0 )
-    return( EOF + count );
-
-  return( c & 0x7f );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Get_Line()						*/
-/*								*/
-/*		Read a line from the user. Returns a pointer	*/
-/*		to a local buffer, or NULL if DEL or a non-	*/
-/*		ASCII character was typed. Processes ^H and	*/
-/*		^U. ^M terminates the input.			*/
-/*								*/
-/****************************************************************/
-
-
-char *Get_Line()
-
-  {
-  int c;
-  int i;
-  static char line[ MAX_STRING + 1 ];
-
-  for ( i = 0;  i <= MAX_STRING;  ++i )
-    {
-    c = Get_Char();
-
-    if ( c == EOF  ||  c == DEL  ||  (c & 0x80) )
-	return( NULL );
-
-    if ( c == BS )
-	{
-	if ( --i >= 0 )
-	  {
-	  printf( "\b \b" );
-	  --i;
-	  }
-	}
-
-    else if ( c == CTRL_U )
-	{
-	for ( --i;  i >= 0;  --i )
-	  printf( "\b \b" );
-	}
-
-    else if ( c == '\r' )
-	{
-	line[ i ] = '\0';
-	return( line );
-	}
-
-    else if ( i < MAX_STRING )
-	{
-	line[ i ] = c;
-	Print_Ascii( c );
-	}
-
-    else  /*  Line buffer is full, don't add any more to it.  */
-	{
-	putchar( BELL );
-	--i;
-	}
-    }
-
-  Error( "Internal fault (line buffer overflow)" );
-
-  /* NOTREACHED */
-  return( NULL );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Arrow_Esc( char )					*/
-/*								*/
-/*		If the keyboard does not generate Ansi escape	*/
-/*		codes for the arrow keys, but does generate	*/
-/*		single byte control codes, then map these	*/
-/*		codes to the special characters we are using	*/
-/*		to denote the Ansi escape codes.		*/
-/*								*/
-/****************************************************************/
-
-
-extern  char   Kup;		/* (ku) - Up arrow key		*/
-extern  char   Kdown;		/* (kd) - Down arrow key	*/
-extern  char   Kleft;		/* (kl) - Left arrow key	*/
-extern  char   Kright;		/* (kr) - Right arrow key	*/
-
-
-int Arrow_Esc( c )
-  int c;
-
-  {
-  if ( c == Kup )
-    return( ESC_UP );
-
-  if ( c == Kdown )
-    return( ESC_DOWN );
-
-  if ( c == Kleft )
-    return( ESC_LEFT );
-
-  if ( c == Kright )
-    return( ESC_RIGHT );
-
-  return( c );
-  }
-
-void Timed_Out(sig)
-int sig;
-  {}
-
-/*
- * $PchHeader: /mount/hd2/minix/sys/cmd/de/RCS/de_stdin.c,v 1.3 1995/02/10 08:01:30 philip Exp $
- */
Index: trunk/minix/commands/de/de_stdout.c
===================================================================
--- trunk/minix/commands/de/de_stdout.c	(revision 9)
+++ 	(revision )
@@ -1,1173 +1,0 @@
-/****************************************************************/
-/*								*/
-/*	de_stdout.c						*/
-/*								*/
-/*		Displaying information from the "Disk editor".	*/
-/*								*/
-/****************************************************************/
-/*  origination         1989-Jan-15        Terrence W. Holm	*/
-/****************************************************************/
-
-
-#include <minix/config.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <grp.h>
-#include <pwd.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termcap.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <minix/const.h>
-#include <minix/type.h>
-#include "../../servers/fs/const.h"
-#include "../../servers/fs/type.h"
-#include "../../servers/fs/inode.h"
-#include <minix/fslib.h>
-
-#include "de.h"
-
-#ifndef major
-#define major(x) ( (x>>8) & 0377)
-#define minor(x) (x & 0377)
-#endif
-
-/****************************************************************/
-/*   		Code for handling termcap			*/
-/****************************************************************/
-
-
-#define  TC_BUFFER  1024	/* Size of termcap(3) buffer	*/
-#define  TC_STRINGS  200	/* Enough room for cm,cl,so,se	*/
-
-
-static  char  *Tmove;		/* (cm) - Format for tgoto	*/
-static  char  *Tclr_all;	/* (cl) - Clear screen  	*/
-static  char  *Treverse;	/* (so) - Start reverse mode 	*/
-static  char  *Tnormal;		/* (se) - End reverse mode	*/
-
-char   Kup    = 0;		/* (ku) - Up arrow key		*/
-char   Kdown  = 0;		/* (kd) - Down arrow key	*/
-char   Kleft  = 0;		/* (kl) - Left arrow key	*/
-char   Kright = 0;		/* (kr) - Right arrow key	*/
-
-_PROTOTYPE(void Goto , (int column , int line ));
-_PROTOTYPE(void Block_Type , (de_state *s ));
-_PROTOTYPE(void Draw_Words , (de_state *s ));
-_PROTOTYPE(void Draw_Info , (de_state *s ));
-_PROTOTYPE(void Draw_Block , (char *block ));
-_PROTOTYPE(void Draw_Map , (char *block , int max_bits ));
-_PROTOTYPE(void Draw_Offset , (de_state *s ));
-_PROTOTYPE(void Word_Pointers , (off_t old_addr , off_t new_addr ));
-_PROTOTYPE(void Block_Pointers , (off_t old_addr , off_t new_addr ));
-_PROTOTYPE(void Map_Pointers , (off_t old_addr , off_t new_addr ));
-_PROTOTYPE(void Print_Number , (Word_t number , int output_base ));
-_PROTOTYPE(void Draw_Zone_Numbers , (de_state *s , struct inode *inode ,
-						int zindex , int zrow ));
-
-
-
-/****************************************************************/
-/*								*/
-/*	Init_Termcap()						*/
-/*								*/
-/*		Initializes the external variables for the	*/
-/*		current terminal.				*/
-/*								*/
-/****************************************************************/
-
-
-int Init_Termcap()
-
-  {
-  char  *term;
-  char   buffer[ TC_BUFFER ];
-  static char strings[ TC_STRINGS ];
-  char  *s = &strings[0];
-  char  *Kcode;
-
-
-  term = getenv( "TERM" );
-
-  if ( term == NULL )
-    return( 0 );
-
-  if ( tgetent( buffer, term ) != 1 )
-    return( 0 );
-
-
-  if ( (Tmove = tgetstr( "cm", &s )) == NULL )
-    return( 0 );
-
-  if ( (Tclr_all = tgetstr( "cl", &s )) == NULL )
-    return( 0 );
-
-  if ( (Treverse = tgetstr( "so", &s )) == NULL )
-    {
-    Treverse = Tnormal = s;
-    *s = '\0';
-    ++s;
-    }
-  else if ( (Tnormal = tgetstr( "se", &s )) == NULL )
-    return( 0 );
-
-
-  /*  See if there are single character arrow key codes  */
-
-  if ( (Kcode = tgetstr( "ku", &s )) != NULL  &&  strlen( Kcode ) == 1 )
-    Kup = Kcode[0];
-
-  if ( (Kcode = tgetstr( "kd", &s )) != NULL  &&  strlen( Kcode ) == 1 )
-    Kdown = Kcode[0];
-
-  if ( (Kcode = tgetstr( "kl", &s )) != NULL  &&  strlen( Kcode ) == 1 )
-    Kleft = Kcode[0];
-
-  if ( (Kcode = tgetstr( "kr", &s )) != NULL  &&  strlen( Kcode ) == 1 )
-    Kright = Kcode[0];
-
-
-  return( 1 );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Goto( column, line )					*/
-/*								*/
-/*		Use the termcap string to move the cursor.	*/
-/*								*/
-/****************************************************************/
-
-
-void Goto( column, line )
-  int  column;
-  int  line;
-
-  {
-  fputs( tgoto( Tmove, column, line ), stdout );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*   		       Output routines				*/
-/****************************************************************/
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Help_Screen()					*/
-/*								*/
-/****************************************************************/
-
-
-void Draw_Help_Screen( s )
-  de_state *s;
-
-  {
-  int down;
-  int right;
-
-  switch ( s->mode )
-    {
-    case WORD  :   down = 2;    right = 32;  break;
-    case BLOCK :   down = 64;   right = 1;   break;
-    case MAP   :   down = 256;  right = 4;   break;
-    }
-
-  printf( "%s                             ", Tclr_all );
-  printf( "%sDE  COMMANDS%s\r\n\n\n", Treverse, Tnormal );
-
-
-  printf( "   PGUP   b   Back one block              h   Help\r\n" );
-  printf( "   PGDN   f   Forward one block           q   Quit\r\n" );
-  printf( "   HOME   B   Goto first block            m   Minix shell\r\n" );
-  printf( "   END    F   Goto last block\r\n" );
-  printf( "                                          v   Visual mode (w b m)\r\n" );
-  printf( "          g   Goto specified block        o   Output base (h d o b)\r\n" );
-  printf( "          G   Goto block indirectly\r\n" );
-  printf( "          i   Goto i-node                 c   Change file name\r\n" );
-  printf( "          I   Filename to i-node          w   Write ASCII block\r\n" );
-  printf( "                                          W   Write block exactly\r\n" );
-  printf( "          /   Search\r\n" );
-  printf( "          n   Next occurrence             x   Extract lost entry\r\n" );
-  printf( "          p   Previous address            X   Extract lost blocks\r\n" );
-  printf( "                                          s   Store word\r\n" );
-  printf( "   UP     u   Move back %d bytes\r\n", down );
-  printf( "   DOWN   d   Move forward %d bytes\r\n", down );
-  printf( "   LEFT   l   Move back %d byte%s\r\n", right,
-					right == 1 ? "" : "s" );
-  printf( "   RIGHT  r   Move forward %d byte%s\r\n\n\n", right,
-					right == 1 ? "" : "s" );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Wait_For_Key()						*/
-/*								*/
-/*		The user must press a key to continue.		*/
-/*								*/
-/****************************************************************/
-
-
-void Wait_For_Key()
-
-  {
-  Draw_Prompt( "Press a key to continue..." );
-
-  Get_Char();
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Prompt( string )					*/
-/*								*/
-/*		Write a message in the "prompt" area.		*/
-/*								*/
-/****************************************************************/
-
-
-void Draw_Prompt( string )
-  char  *string;
-
-  {
-  Goto( PROMPT_COLUMN, PROMPT_LINE );
-
-  printf( "%s%s%s ", Treverse, string, Tnormal );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Erase_Prompt()						*/
-/*								*/
-/*		Erase the message in the "prompt" area.		*/
-/*								*/
-/****************************************************************/
-
-
-void Erase_Prompt()
-
-  {
-  Goto( PROMPT_COLUMN, PROMPT_LINE );
-
-  printf( "%77c", ' ' );
-
-  Goto( PROMPT_COLUMN, PROMPT_LINE );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Screen( state )					*/
-/*								*/
-/*		Redraw everything, except pointers.		*/
-/*								*/
-/****************************************************************/
-
-
-void Draw_Screen( s )
-  de_state *s;
-
-  {
-  fputs( Tclr_all, stdout );
-
-  Draw_Strings( s );
-  Block_Type( s );
-
-  switch ( s->mode )
-    {
-    case WORD :   Draw_Words( s );
-		  Draw_Info( s );
-		  break;
-
-    case BLOCK :  Draw_Block( s->buffer );
-		  break;
-
-    case MAP :	  {
-		  int max_bits = 2 * K;
-
-		  /*  Don't display the bits after the end  */
-		  /*  of the i-node or zone bit maps.	    */
-
-		  if ( s->block == 2 + s->inode_maps - 1 )
-		    max_bits = (int)
-			       (s->inodes_in_map
-				- CHAR_BIT * K * (ino_t) (s->inode_maps - 1)
-				- CHAR_BIT * (ino_t) (s->offset & ~ MAP_MASK));
-
-		  else if ( s->block == 2 + s->inode_maps + s->zone_maps - 1 )
-		    max_bits = (int)
-			       (s->zones_in_map
-			        - CHAR_BIT * K * (zone_t) (s->zone_maps - 1)
-				- CHAR_BIT * (zone_t) (s->offset & ~ MAP_MASK));
-
-		  if ( max_bits < 0 )
-		      max_bits = 0;
-
-		  Draw_Map( &s->buffer[ s->offset & ~ MAP_MASK ], max_bits );
-		  break;
-		  }
-    }
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Strings( state )					*/
-/*								*/
-/*		The first status line contains the device name,	*/
-/*		the current write file name (if one is open)	*/
-/*		and the current search string (if one has	*/
-/*		been defined).					*/
-/*								*/
-/*		Long strings are truncated.			*/
-/*								*/
-/****************************************************************/
-
-
-void Draw_Strings( s )
-  de_state *s;
-
-  {
-  int len;
-  int i;
-
-  Goto( STATUS_COLUMN, STATUS_LINE );
-
-  printf( "Device %s= %-14.14s  ",
-	     s->device_mode == O_RDONLY ? "" : "(w) ", s->device_name );
-
-  switch ( s->magic )
-    {
-    case SUPER_MAGIC :	printf( "V1 file system  ");
-			break;
-    case SUPER_REV :	printf( "V1-bytes-swapped file system (?)  ");
-			break;
-    case SUPER_V2 :	printf( "V2 file system  ");
-			break;
-    case SUPER_V2_REV :	printf( "V2-bytes-swapped file system (?)  ");
-			break;
-    case SUPER_V3 :	printf( "V3 file system  ");
-			break;
-    default :		printf( "not a Minix file system  ");
-			break;
-    }
-
-  len = strlen( s->file_name );
-
-  if ( len == 0 )
-    printf( "%29s", " " );
-  else if ( len <= 20 )
-    printf( "File = %-20s  ", s->file_name );
-  else
-    printf( "File = ...%17.17s  ", s->file_name + len - 17 );
-
-
-  len = strlen( s->search_string );
-
-  if ( len == 0 )
-    printf( "%20s", " " );
-  else
-    {
-    printf( "Search = " );
-
-    if ( len <= 11 )
-      {
-      for ( i = 0;  i < len;  ++i )
-        Print_Ascii( s->search_string[ i ] );
-
-      for ( ;  i < 11;  ++i )
-	putchar( ' ' );
-      }
-    else
-      {
-      for ( i = 0;  i < 8;  ++i )
-        Print_Ascii( s->search_string[ i ] );
-
-      printf( "..." );
-      }
-    }
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Block_Type( state )					*/
-/*								*/
-/*		Display the current block type.			*/
-/*								*/
-/****************************************************************/
-
-
-void Block_Type( s )
-  de_state *s;
-
-  {
-  Goto( STATUS_COLUMN, STATUS_LINE + 1 );
-
-  printf( "Block  = %5u of %-5u  ", s->block, s->zones );
-
-  if ( !s->is_fs )
-    return;
-
-  if ( s->block == BOOT_BLOCK )
-    printf( "Boot block" );
-
-  else if ( s->block == 1 )
-    printf( "Super block" );
-
-  else if ( s->block < 2 + s->inode_maps )
-    printf( "I-node bit map" );
-
-  else if ( s->block < 2 + s->inode_maps + s->zone_maps )
-    printf( "Zone bit map" );
-
-  else if ( s->block < s->first_data )
-    printf( "I-nodes" );
-
-  else
-    printf( "Data block  (%sin use)",
-	In_Use( (bit_t) (s->block - (s->first_data - 1)), s->zone_map )
-	? "" : "not " );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Words( state )					*/
-/*								*/
-/*		Draw a page in word format.			*/
-/*								*/
-/****************************************************************/
-
-
-void Draw_Words( s )
-  de_state *s;
-
-  {
-  int line;
-  int addr = s->offset & ~ PAGE_MASK;
-
-
-  for ( line = 0;  line < 16;  ++line, addr += 2 )
-    {
-    Goto( BLOCK_COLUMN, BLOCK_LINE + line );
-
-    printf( "%5d  ", addr );
-
-    Print_Number( *( (word_t *) &s->buffer[ addr ] ), s->output_base );
-    }
-
-  Goto( BLOCK_COLUMN + 64, BLOCK_LINE  );
-  printf( "(base %d)", s->output_base );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Info( state )					*/
-/*								*/
-/*		Add information to a page drawn in word format.	*/
-/*		The routine recognizes the super block, inodes,	*/
-/*		executables and "ar" archives. If the current	*/
-/*		page is not one of these, then ASCII characters	*/
-/*		are printed from the data words.		*/
-/*								*/
-/****************************************************************/
-
-
-char *super_block_info[] =  {	"number of inodes",
-				"V1 number of zones",
-				"inode bit map blocks",
-				"zone bit map blocks",
-				"first data zone",
-				"blocks per zone shift & flags",
-				"maximum file size",
-				"",
-				"magic number",
-				"fsck magic number",
-				"V2 number of zones"  };
-
-
-void Draw_Info( s )
-  de_state *s;
-
-  {
-  int i;
-  int page = s->offset >> PAGE_SHIFT;
-  dev_t dev;
-
-
-  if ( s->is_fs  &&  s->block == 1  &&  page == 0 )
-      for ( i = 0;  i < 11;  ++i )
- 	{
-	Goto( INFO_COLUMN, INFO_LINE + i );
-	printf( "%s", super_block_info[ i ] );
-	}
-
-  else if ( s->is_fs  &&  s->block >= s->first_data - s->inode_blocks  &&
-	    s->block < s->first_data )
-      {
-      struct inode core_inode;
-      d1_inode *dip1;
-      d2_inode *dip2;
-      struct inode *inode = &core_inode;
-      int special = 0;
-      int m;
-      struct passwd *user;
-      struct group *grp;
-
-      dip1 = (d1_inode *) &s->buffer[ s->offset & ~ PAGE_MASK ];
-      dip2 = (d2_inode *) &s->buffer[ s->offset & ~ PAGE_MASK
-						& ~ (V2_INODE_SIZE-1) ];
-      conv_inode( inode, dip1, dip2, READING, s->magic );
-
-      user = getpwuid( inode->i_uid );
-      grp  = getgrgid( inode->i_gid );
-
-      if ( s->magic != SUPER_MAGIC  &&  page & 1 )
-	{
-	Draw_Zone_Numbers( s, inode, 2, 0 );
-	return;
-	}
-
-      Goto( INFO_COLUMN, INFO_LINE  );
-
-      switch( inode->i_mode & S_IFMT )
-    	{
-    	case S_IFDIR :  printf( "directory  " );
-		    	break;
-
-    	case S_IFCHR :  printf( "character  " );
-		    	special = 1;
-		    	break;
-
-    	case S_IFBLK :  printf( "block  " );
-		   	special = 1;
-		    	break;
-
-    	case S_IFREG :  printf( "regular  " );
-		    	break;
-#ifdef S_IFIFO
-    	case S_IFIFO :  printf( "fifo  " );
-		    	break;
-#endif
-#ifdef S_IFLNK
-    	case S_IFLNK :  printf( "symlink  " );
-		    	break;
-#endif
-#ifdef S_IFSOCK
-    	case S_IFSOCK:  printf( "socket  " );
-		    	break;
-#endif
-    	default      :  printf( "unknown  " );
-    	}
-
-	for ( m = 11;  m >= 0;  --m )
-	  putchar( (inode->i_mode & (1<<m)) ? "xwrxwrxwrtgu"[m] : '-' );
-
-	if ( s->magic == SUPER_MAGIC )
-	  {
-	  /* V1 file system */
-	  Goto( INFO_COLUMN, INFO_LINE + 1 );
-	  printf( "user %s", user ? user->pw_name : "" );
-
-	  Goto( INFO_COLUMN, INFO_LINE + 2 );
-	  printf( "file size %lu", inode->i_size );
-
-	  Goto( INFO_COLUMN, INFO_LINE + 4 );
-	  printf( "m_time %s", ctime( &inode->i_mtime ) );
-
-	  Goto( INFO_COLUMN, INFO_LINE + 6 );
-	  printf( "links %d, group %s",
-		  inode->i_nlinks, grp ? grp->gr_name : "" );
-
-	  Draw_Zone_Numbers( s, inode, 0, 7 );
-	  }
-	else
-	  {
-	  /* V2 file system, even page. */
-	  Goto( INFO_COLUMN, INFO_LINE + 1 );
-	  printf( "links %d ", inode->i_nlinks);
-
-	  Goto( INFO_COLUMN, INFO_LINE + 2 );
-	  printf( "user %s", user ? user->pw_name : "" );
-
-	  Goto( INFO_COLUMN, INFO_LINE + 3 );
-	  printf( "group %s", grp ? grp->gr_name : "" );
-
-	  Goto( INFO_COLUMN, INFO_LINE + 4 );
-	  printf( "file size %lu", inode->i_size );
-
-	  Goto( INFO_COLUMN, INFO_LINE + 6 );
-	  printf( "a_time %s", ctime( &inode->i_atime ) );
-
-	  Goto( INFO_COLUMN, INFO_LINE + 8 );
-	  printf( "m_time %s", ctime( &inode->i_mtime ) );
-
-	  Goto( INFO_COLUMN, INFO_LINE + 10 );
-	  printf( "c_time %s", ctime( &inode->i_ctime ) );
-
-	  Draw_Zone_Numbers( s, inode, 0, 12 );
-	}
-
-      if ( special )
-	{
-	Goto( INFO_COLUMN, INFO_LINE + 7 );
-	dev = (dev_t) inode->i_zone[0];
-	printf( "major %d, minor %d", major(dev), minor(dev) );
-	}
-      }
-
-  else  /*  Print ASCII characters for each byte in page  */
-      {
-      char *p = &s->buffer[ s->offset & ~ PAGE_MASK ];
-
-      for ( i = 0;  i < 16;  ++i )
-        {
-        Goto( INFO_COLUMN, INFO_LINE + i );
-        Print_Ascii( *p++ );
-        Print_Ascii( *p++ );
-        }
-
-      if ( s->block >= s->first_data  &&  page == 0 )
-	{
-	unsigned magic  = ((s->buffer[1] & 0xff) << 8) | (s->buffer[0] & 0xff);
-	unsigned second = ((s->buffer[3] & 0xff) << 8) | (s->buffer[2] & 0xff);
-
-	/*  Is this block the start of an executable file?  */
-
-	if ( magic == (unsigned) A_OUT )
-	  {
-          Goto( INFO_COLUMN, INFO_LINE );
-	  printf( "executable" );
-
-          Goto( INFO_COLUMN, INFO_LINE + 1 );
-
-	  if ( second == (unsigned) SPLIT )
-	    printf( "separate I & D" );
-	  else
-	    printf( "combined I & D" );
-	  }
-	}
-      }
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Block( block )					*/
-/*								*/
-/*		Redraw a 1k block in character format.		*/
-/*								*/
-/****************************************************************/
-
-
-void Draw_Block( block )
-  char *block;
-
-  {
-  int line;
-  int column;
-  int reverse = 0;
-  int msb_flag = 0;
-
-
-  for ( line = 0;  line < 16;  ++line )
-    {
-    Goto( BLOCK_COLUMN, BLOCK_LINE + line );
-
-    for ( column = 0;  column < 64;  ++column )
-      {
-      char c = *block++;
-
-      if ( c & 0x80 )
-	{
-	msb_flag = 1;
-	c &= 0x7f;
-	}
-
-      if ( c >= ' '  &&  c < DEL )
-	{
-	if ( reverse )
-	  { fputs( Tnormal, stdout ); reverse = 0; }
-
-        putchar( c );
-	}
-      else
-	{
-	if ( ! reverse )
-	  { fputs( Treverse, stdout ); reverse = 1; }
-
-	putchar( c == DEL ? '?' : '@' + c );
-	}
-      }  /*  end for ( column )  */
-    }  /*  end for ( line )  */
-
-  if ( reverse )
-    { fputs( Tnormal, stdout ); reverse = 0; }
-
-  if ( msb_flag )
-    {
-    Goto( BLOCK_COLUMN + 68, BLOCK_LINE + 6 );
-    fputs( "(MSB)", stdout );
-    }
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Map( block, max_bits )				*/
-/*								*/
-/*		Redraw a block in a bit map format.		*/
-/*		Display min( max_bits, 2048 ) bits.		*/
-/*								*/
-/*		The 256 bytes in "block" are displayed from	*/
-/*		top to bottom and left to right. Bit 0 of	*/
-/*		a byte is towards the top of the screen.	*/
-/*								*/
-/*		Special graphic codes are used to generate	*/
-/*		two "bits" per character position. So a 16	*/
-/*		line by 64 column display is 32 "bits" by	*/
-/*		64 "bits". Or 4 bytes by 64 bytes.		*/
-/*								*/
-/****************************************************************/
-
-
-void Draw_Map( block, max_bits )
-  char *block;
-  int   max_bits;
-
-  {
-  int line;
-  int column;
-  int bit_count = 0;
-
-  for ( line = 0;  line < 16;  ++line )
-    {
-    char *p = &block[ (line & 0xC) >> 2 ];
-    int shift = (line & 0x3) << 1;
-
-    Goto( BLOCK_COLUMN, BLOCK_LINE + line );
-
-    for ( column = 0;  column < 64;  ++column, p += 4 )
-      {
-      char c = (*p >> shift) & 0x3;
-      int current_bit = ((p - block) << 3) + shift;
-
-      /*  Don't display bits past "max_bits"  */
-
-      if ( current_bit >= max_bits )
-	break;
-
-      /*  If "max_bits" occurs in between the two bits  */
-      /*  I am trying to display as one character, then	*/
-      /*  zero off the high-order bit.			*/
-
-      if ( current_bit + 1 == max_bits )
-	c &= 1;
-
-      switch ( c )
-	{
-	case 0 :  putchar( BOX_CLR );
-		  break;
-
-	case 1 :  putchar( BOX_TOP );
-		  ++bit_count;
-		  break;
-
-	case 2 :  putchar( BOX_BOT );
-		  ++bit_count;
-		  break;
-
-	case 3 :  putchar( BOX_ALL );
-		  bit_count += 2;
-		  break;
-	}
-      }  /*  end for ( column )  */
-    }  /*  end for ( line )  */
-
-
-  Goto( BLOCK_COLUMN + 68, BLOCK_LINE + 6 );
-  printf( "(%d)", bit_count );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Pointers( state )					*/
-/*								*/
-/*		Redraw the pointers and the offset field.	*/
-/*		The rest of the screen stays intact.		*/
-/*								*/
-/****************************************************************/
-
-
-void Draw_Pointers( s )
-  de_state *s;
-
-  {
-  Draw_Offset( s );
-
-  switch ( s->mode )
-    {
-    case WORD :   Word_Pointers( s->last_addr, s->address );
-		  break;
-
-    case BLOCK :  Block_Pointers( s->last_addr, s->address );
-		  break;
-
-    case MAP :	  Map_Pointers( s->last_addr, s->address );
-		  break;
-    }
-
-  Goto( PROMPT_COLUMN, PROMPT_LINE );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Draw_Offset( state )					*/
-/*								*/
-/*		Display the offset in the current buffer	*/
-/*		and the relative position if within a map	*/
-/*		or i-node block.				*/
-/*								*/
-/****************************************************************/
-
-
-void Draw_Offset( s )
-  de_state *s;
-
-  {
-  Goto( STATUS_COLUMN, STATUS_LINE + 2 );
-
-  printf( "Offset = %5d           ", s->offset );
-
-
-  if ( s->block < 2 )
-    return;
-
-  if ( s->block < 2 + s->inode_maps )
-    {
-    long bit = (s->address - 2 * K) * 8;
-
-    if ( bit < s->inodes_in_map )
-	printf( "I-node %ld of %d     ", bit, s->inodes );
-    else
-	printf( "(padding)                " );
-    }
-
-  else if ( s->block < 2 + s->inode_maps + s->zone_maps )
-    {
-    long bit = (s->address - (2 + s->inode_maps) * K) * 8;
-
-    if ( bit < s->zones_in_map )
-	printf( "Block %ld of %u     ", bit + s->first_data - 1, s->zones );
-    else
-	printf( "(padding)                " );
-    }
-
-  else if ( s->block < s->first_data )
-    {
-    bit_t node = (s->address - (2 + s->inode_maps + s->zone_maps) * K) /
-		s->inode_size + 1;
-
-    if ( node <= s->inodes )
-	printf( "I-node %lu of %lu  (%sin use)       ",
-		(unsigned long) node, (unsigned long) s->inodes,
-		In_Use( node, s->inode_map ) ? "" : "not " );
-    else
-	printf( "(padding)                             " );
-    }
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Word_Pointers( old_addr, new_addr )			*/
-/*								*/
-/*	Block_Pointers( old_addr, new_addr )			*/
-/*								*/
-/*	Map_Pointers( old_addr, new_addr )			*/
-/*								*/
-/*		Redraw the index pointers for a each type	*/
-/*		of display. The pointer at "old_addr" is	*/
-/*		erased and a new pointer is positioned		*/
-/*		for "new_addr". This makes the screen		*/
-/*		update faster and more pleasant for the user.	*/
-/*								*/
-/****************************************************************/
-
-
-void Word_Pointers( old_addr, new_addr )
-  off_t old_addr;
-  off_t new_addr;
-
-  {
-  int from = ( (int) old_addr & PAGE_MASK ) >> 1;
-  int to   = ( (int) new_addr & PAGE_MASK ) >> 1;
-
-  Goto( BLOCK_COLUMN - 2, BLOCK_LINE + from );
-  putchar( ' ' );
-
-  Goto( BLOCK_COLUMN - 2, BLOCK_LINE + to );
-  putchar( '>' );
-  }
-
-
-
-
-void Block_Pointers( old_addr, new_addr )
-  off_t old_addr;
-  off_t new_addr;
-
-  {
-  int from = (int) old_addr & ~K_MASK;
-  int to   = (int) new_addr & ~K_MASK;
-
-  Goto( BLOCK_COLUMN - 2, BLOCK_LINE + from / 64 );
-  putchar( ' ' );
-
-  Goto( BLOCK_COLUMN - 2, BLOCK_LINE + to / 64 );
-  putchar( '>' );
-
-  Goto( BLOCK_COLUMN + from % 64, BLOCK_LINE + 17 );
-  putchar( ' ' );
-
-  Goto( BLOCK_COLUMN + to % 64, BLOCK_LINE + 17 );
-  putchar( '^' );
-  }
-
-
-
-
-void Map_Pointers( old_addr, new_addr )
-  off_t old_addr;
-  off_t new_addr;
-
-  {
-  int from = ( (int) old_addr & MAP_MASK ) >> 2;
-  int to   = ( (int) new_addr & MAP_MASK ) >> 2;
-
-  Goto( BLOCK_COLUMN + from, BLOCK_LINE + 17 );
-  putchar( ' ' );
-
-  Goto( BLOCK_COLUMN + to, BLOCK_LINE + 17 );
-  putchar( '^' );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Print_Number( number, output_base )			*/
-/*								*/
-/*		Output "number" in the output base.		*/
-/*								*/
-/****************************************************************/
-
-
-void Print_Number( number, output_base )
-  word_t number;
-  int output_base;
-
-  {
-  switch ( output_base )
-    {
-    case 16 :	printf( "%5x", number );
-		break;
-
-    case 10 :	printf( "%7u", number );
-		break;
-
-    case 8 :	printf( "%7o", number );
-		break;
-
-    case 2 :	{
-      		unsigned int mask;
-      		char pad = ' ';
-
-      		for ( mask = 0x8000;  mask > 1;  mask >>= 1 )
-		  putchar( (mask & number) ? (pad = '0', '1') : pad );
-
-      		putchar( (0x01 & number) ? '1' : '0' );
-
-		break;
-      		}
-
-    default :	Error( "Internal fault (output_base)" );
-    }
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Print_Ascii( char )					*/
-/*								*/
-/*		Display a character in reverse mode if it	*/
-/*		is not a normal printable ASCII character.	*/
-/*								*/
-/****************************************************************/
-
-
-void Print_Ascii( c )
-  char c;
-
-  {
-  c &= 0x7f;
-
-  if ( c < ' ' )
-    printf( "%s%c%s", Treverse, '@' + c, Tnormal );
-  else if ( c == DEL )
-    printf( "%s?%s", Treverse, Tnormal );
-  else
-    putchar( c );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*	Warning( text, arg1, arg2 )				*/
-/*								*/
-/*		Display a message for 2 seconds.		*/
-/*								*/
-/****************************************************************/
-
-
-#if __STDC__
-void Warning( const char *text, ... )
-#else
-void Warning( text )
-  char *text;
-#endif  
-
-  {
-  va_list argp;
-  
-  printf( "%c%s", BELL, Tclr_all );
-
-  Goto( WARNING_COLUMN, WARNING_LINE );
-
-  printf( "%s Warning: ", Treverse );
-  va_start( argp, text );
-  vprintf( text, argp );
-  va_end( argp );
-  printf( " %s", Tnormal );
-
-  fflush(stdout);		/* why does everyone forget this? */
-
-  sleep( 2 );
-  }
-
-
-void Draw_Zone_Numbers( s, inode, zindex, zrow )
-  de_state *s;
-  struct inode *inode;
-  int zindex;
-  int zrow;
-
-  {
-  static char *plurals[] = { "", "double ", "triple " };
-  zone_t zone;
-
-  for ( ; zrow < 16;
-	++zindex, zrow += s->zone_num_size / sizeof (word_t) )
-    {
-    Goto( INFO_COLUMN, INFO_LINE + zrow );
-    if ( zindex < s->ndzones )
-      printf( "zone %d", zindex );
-    else
-      printf( "%sindirect", plurals[ zindex - s->ndzones ] );
-    if ( s->magic != SUPER_MAGIC )
-      {
-      zone = inode->i_zone[ zindex ];
-      if ( zone != (word_t) zone )
-	{
-	Goto( INFO_COLUMN + 16, INFO_LINE + zrow );
-	printf("%ld", (long) zone );
-	}
-      }
-    }
-  }
Index: trunk/minix/commands/dhcpd/Makefile
===================================================================
--- trunk/minix/commands/dhcpd/Makefile	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-# Makefile for dhcpd.
-
-CFLAGS	= $(OPT) -D_MINIX
-LDFLAGS	=
-CC = exec cc
-
-all:	dhcpd
-
-OBJ=	dhcpd.o tags.o devices.o ether.o
-
-dhcpd:	$(OBJ)
-	$(CC) $(LDFLAGS) -o $@ $(OBJ)
-	install -S 12kw $@
-
-install:	/usr/bin/dhcpd
-
-/usr/bin/dhcpd:	dhcpd
-	install -c $? $@
-
-clean:
-	rm -f *.o dhcpd core a.out
-
-# Dependencies.
-$(OBJ):			dhcpd.h
-dhcpd.o ether.o:	arp.h
Index: trunk/minix/commands/dhcpd/arp.h
===================================================================
--- trunk/minix/commands/dhcpd/arp.h	(revision 9)
+++ 	(revision )
@@ -1,26 +1,0 @@
-/*	arp.h - Address Resolution Protocol packet format.
- *							Author: Kees J. Bot
- *								16 Dec 2000
- */
-#ifndef ARP_H
-#define ARP_H
-
-typedef struct arp46 {
-	ether_addr_t	dstaddr;
-	ether_addr_t	srcaddr;
-	ether_type_t	ethtype;	/* ARP_PROTO. */
-	u16_t		hdr, pro;	/* ARP_ETHERNET & ETH_IP_PROTO. */
-	u8_t		hln, pln;	/* 6 & 4. */
-	u16_t		op;		/* ARP_REQUEST or ARP_REPLY. */
-	ether_addr_t	sha;		/* Source hardware address. */
-	u8_t		spa[4];		/* Source protocol address. */
-	ether_addr_t	tha;		/* Likewise for the target. */
-	u8_t		tpa[4];
-	char		padding[60 - (4*6 + 2*4 + 4*2 + 2*1)];
-} arp46_t;
-
-#define ARP_ETHERNET	1	/* ARP on Ethernet. */
-#define ARP_REQUEST	1	/* A request for an IP address. */
-#define ARP_REPLY	2	/* A reply to a request. */
-
-#endif /* ARP_H */
Index: trunk/minix/commands/dhcpd/build
===================================================================
--- trunk/minix/commands/dhcpd/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/dhcpd/devices.c
===================================================================
--- trunk/minix/commands/dhcpd/devices.c	(revision 9)
+++ 	(revision )
@@ -1,280 +1,0 @@
-/*	devices.c - Handle network devices.
- *							Author: Kees J. Bot
- *								11 Jun 1999
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-#include <sys/ioctl.h>
-#include <sys/asynchio.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/ether.h>
-#include <net/gen/eth_hdr.h>
-#include <net/gen/eth_io.h>
-#include <net/gen/ip_hdr.h>
-#include <net/gen/ip_io.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_hdr.h>
-#include <net/gen/udp_io.h>
-#include <net/gen/dhcp.h>
-#include "dhcpd.h"
-
-void get_buf(buf_t **bp)
-{
-    /* Allocate and return a buffer pointer iff *bp == nil. */
-    if (*bp != nil) {
-	/* Already has one. */
-    } else {
-	/* Get one from the heap. */
-	buf_t *new= allocate(sizeof(*new));
-	new->dhcp= (dhcp_t *) (new->buf + sizeof(eth_hdr_t)
-				+ sizeof(ip_hdr_t) + sizeof(udp_hdr_t));
-	new->udpio= ((udp_io_hdr_t *) new->dhcp) - 1;
-	new->udp= ((udp_hdr_t *) new->dhcp) - 1;
-	new->ip= ((ip_hdr_t *) new->udp) - 1;
-	new->eth= ((eth_hdr_t *) new->ip) - 1;
-	*bp= new;
-    }
-}
-
-void put_buf(buf_t **bp)
-{
-    /* Return a buffer to the heap. */
-    if (*bp != nil) {
-	free(*bp);
-	*bp= nil;
-    }
-}
-
-void give_buf(buf_t **dbp, buf_t **sbp)
-{
-    /* Hand over a buffer to another variable. */
-    put_buf(dbp);
-    *dbp= *sbp;
-    *sbp= nil;
-}
-
-#if __minix_vmd
-#define N_FDS		16	/* Minix-vmd can go async on many fds. */
-#else
-#define N_FDS		 1	/* Minix doesn't have async I/O. */
-#endif
-
-static fd_t fds[N_FDS];			/* List of open descriptors. */
-static struct network *fdwaitq;		/* Queue of nets waiting for fds. */
-
-network_t *newnetwork(void)
-{
-    /* Create and initialize a network structure. */
-    network_t *new;
-
-    new= allocate(sizeof(*new));
-    memset(new, 0, sizeof(*new));
-    new->hostname= nil;
-    new->solicit= NEVER;
-    new->sol_ct= -1;
-    return new;
-}
-
-void closefd(fd_t *fdp)
-{
-    /* Close a descriptor. */
-    if (fdp->fdtype != FT_CLOSED) {
-	asyn_close(&asyn, fdp->fd);
-	close(fdp->fd);
-	fdp->fdtype= FT_CLOSED;
-	fdp->since= 0;
-	put_buf(&fdp->bp);
-	if (debug >= 3) printf("%s: Closed\n", fdp->device);
-    }
-}
-
-int opendev(network_t *np, fdtype_t fdtype, int compete)
-{
-    /* Make sure that a network has the proper device open and configured.
-     * Return true if this is made so, or false if the device doesn't exist.
-     * If compete is true then the caller competes for old descriptors.
-     * The errno value is EAGAIN if we're out of descriptors.
-     */
-    fd_t *fdp, *fdold;
-    time_t oldest;
-    nwio_ethstat_t ethstat;
-    nwio_ethopt_t ethopt;
-    nwio_ipopt_t ipopt;
-    nwio_udpopt_t udpopt;
-    network_t **pqp;
-    static char devbytype[][4] = { "", "eth", "ip", "udp", "udp" };
-
-    /* Don't attempt to open higher level devices if not bound. */
-    if (!(np->flags & NF_BOUND) && fdtype > FT_ETHERNET) {
-	errno= EAGAIN;
-	return 0;
-    }
-
-    /* Check if already open / Find the oldest descriptor. */
-    fdold= nil;
-    oldest= NEVER;
-    for (fdp= fds; fdp < arraylimit(fds); fdp++) {
-	if (fdp->n == np->n && fdp->fdtype == fdtype) {
-	    /* Already open. */
-	    np->fdp= fdp;
-	    return 1;
-	}
-	if (fdp->since <= oldest) { fdold= fdp; oldest= fdp->since; }
-    }
-
-    /* None free?  Then wait for one to get old if so desired. */
-    if (fdold->fdtype != FT_CLOSED && !compete) {
-	errno= EAGAIN;
-	return 0;
-    }
-
-    if (!(np->flags & NF_WAIT)) {
-	for (pqp= &fdwaitq; *pqp != nil; pqp= &(*pqp)->wait) {}
-	*pqp= np;
-	np->wait= nil;
-	np->flags |= NF_WAIT;
-    }
-
-    /* We allow a net to keep a descriptor for half of the fast period. */
-    oldest += DELTA_FAST/2;
-
-    if (fdwaitq != np || (fdold->fdtype != FT_CLOSED && oldest > now)) {
-	/* This net is not the first in the queue, or the oldest isn't
-	 * old enough.  Forget it for now.
-	 */
-	if (oldest < event) event= oldest;
-	errno= EAGAIN;
-	return 0;
-    }
-
-    /* The oldest is mine. */
-    np->flags &= ~NF_WAIT;
-    fdwaitq= np->wait;
-    closefd(fdold);
-
-    /* Open the proper device in the proper mode. */
-    fdp= fdold;
-    fdp->n= np->n;
-    sprintf(fdp->device, "/dev/%s%d", devbytype[fdtype], np->n);
-    np->fdp= fdp;
-
-    if ((fdp->fd= open(fdp->device, O_RDWR)) < 0) {
-	if (errno == ENOENT || errno == ENODEV || errno == ENXIO) return 0;
-	fatal(fdp->device);
-    }
-
-    switch (fdtype) {
-    case FT_ETHERNET:
-	fcntl(np->fdp->fd, F_SETFL, fcntl(np->fdp->fd, F_GETFL) | O_NONBLOCK);
-	if (ioctl(np->fdp->fd, NWIOGETHSTAT, &ethstat) < 0) {
-	    /* Not an Ethernet. */
-	    close(fdp->fd);
-	    return 0;
-	}
-	np->eth= ethstat.nwes_addr;
-	ethopt.nweo_flags= NWEO_COPY | NWEO_EN_LOC | NWEO_EN_BROAD
-			| NWEO_REMANY | NWEO_TYPEANY | NWEO_RWDATALL;
-
-	if (ioctl(fdp->fd, NWIOSETHOPT, &ethopt) < 0) {
-	    fprintf(stderr, "%s: %s: Unable to set eth options: %s\n",
-		program, fdp->device, strerror(errno));
-	    exit(1);
-	}
-	break;
-
-    case FT_ICMP:
-	ipopt.nwio_flags= NWIO_COPY | NWIO_EN_LOC | NWIO_EN_BROAD
-			| NWIO_REMANY | NWIO_PROTOSPEC
-			| NWIO_HDR_O_SPEC | NWIO_RWDATALL;
-	ipopt.nwio_tos= 0;
-	ipopt.nwio_ttl= 1;
-	ipopt.nwio_df= 0;
-	ipopt.nwio_hdropt.iho_opt_siz= 0;
-	ipopt.nwio_proto= IPPROTO_ICMP;
-
-	if (ioctl(fdp->fd, NWIOSIPOPT, &ipopt) < 0) {
-	    fprintf(stderr, "%s: %s: Unable to set IP options: %s\n",
-		program, fdp->device, strerror(errno));
-	    exit(1);
-	}
-	break;
-
-    case FT_BOOTPC:
-	udpopt.nwuo_flags= NWUO_COPY | NWUO_EN_LOC | NWUO_EN_BROAD
-			| NWUO_RP_ANY | NWUO_RA_ANY | NWUO_RWDATALL
-			| NWUO_DI_IPOPT | NWUO_LP_SET;
-	udpopt.nwuo_locport= port_client;
-	goto udp;
-
-    case FT_BOOTPS:
-	udpopt.nwuo_flags= NWUO_EXCL | NWUO_EN_LOC | NWUO_EN_BROAD
-			| NWUO_RP_ANY | NWUO_RA_ANY | NWUO_RWDATALL
-			| NWUO_DI_IPOPT | NWUO_LP_SET;
-	udpopt.nwuo_locport= port_server;
-    udp:
-	if (ioctl(fdp->fd, NWIOSUDPOPT, &udpopt) == -1) {
-	    fprintf(stderr, "%s: %s: Unable to set UDP options: %s\n",
-		program, fdp->device, strerror(errno));
-	    exit(1);
-	}
-	break;
-
-    default:;
-    }
-
-    fdp->fdtype= fdtype;
-    fdp->since= now;
-    if (debug >= 3) printf("%s: Opened\n", fdp->device);
-    return 1;
-}
-
-void closedev(network_t *np, fdtype_t fdtype)
-{
-    /* We no longer need a given type of device to be open. */
-    fd_t *fdp;
-
-    for (fdp= fds; fdp < arraylimit(fds); fdp++) {
-	if (fdp->n == np->n && (fdp->fdtype == fdtype || fdtype == FT_ALL)) {
-	    closefd(fdp);
-	}
-    }
-}
-
-char *ipdev(int n)
-{
-    /* IP device for network #n. */
-    static char device[sizeof("/dev/ipNNN")];
-
-    sprintf(device, "/dev/ip%d", n);
-    return device;
-}
-
-void set_ipconf(char *device, ipaddr_t ip, ipaddr_t mask, unsigned mtu)
-{
-    /* Set IP address and netmask of an IP device. */
-    int fd;
-    nwio_ipconf_t ipconf;
-
-    if (test > 0) return;
-
-    if ((fd= open(device, O_RDWR)) < 0) fatal(device);
-    ipconf.nwic_flags= NWIC_IPADDR_SET | NWIC_NETMASK_SET;
-    ipconf.nwic_ipaddr= ip;
-    ipconf.nwic_netmask= mask;
-#ifdef NWIC_MTU_SET
-    if (mtu != 0) {
-	ipconf.nwic_flags |= NWIC_MTU_SET;
-	ipconf.nwic_mtu= mtu;
-    }
-#endif
-    if (ioctl(fd, NWIOSIPCONF, &ipconf) < 0) fatal(device);
-    close(fd);
-}
Index: trunk/minix/commands/dhcpd/dhcpd.c
===================================================================
--- trunk/minix/commands/dhcpd/dhcpd.c	(revision 9)
+++ 	(revision )
@@ -1,1406 +1,0 @@
-/*	dhcpd 1.15 - Dynamic Host Configuration Protocol daemon.
- *							Author: Kees J. Bot
- *								11 Jun 1999
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <signal.h>
-#include <string.h>
-#include <time.h>
-#include <limits.h>
-#include <configfile.h>
-#include <sys/ioctl.h>
-#include <sys/asynchio.h>
-#include <net/hton.h>
-#include <net/gen/socket.h>
-#include <net/gen/netdb.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/ether.h>
-#include <net/gen/if_ether.h>
-#include <net/gen/eth_hdr.h>
-#include <net/gen/ip_hdr.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_hdr.h>
-#include <net/gen/udp_io.h>
-#include <net/gen/dhcp.h>
-#include "arp.h"
-#define EXTERN
-#include "dhcpd.h"
-
-char *configfile= PATH_DHCPCONF;
-char *poolfile= PATH_DHCPPOOL;
-static char *cachefile= PATH_DHCPCACHE;
-static int qflag;		/* True if printing cached DHCP data. */
-static int aflag, rflag;	/* True if adding or deleting pool addresses. */
-
-#define BCAST_IP	HTONL(0xFFFFFFFFUL)
-
-/* We try to play with up to this many networks. */
-#define N_NETS		32
-static unsigned n_nets;		/* Actual number of networks. */
-
-void report(const char *label)
-{
-    static FILE *logfp;
-    if(!logfp)
-	logfp = fopen("/usr/log/dhcp.log", "w");
-    if(logfp)
-    	fprintf(logfp, "%s: %s: %s\n", program, label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-    report(label);
-    exit(1);
-}
-
-void *allocate(size_t size)
-{
-    void *mem;
-
-    if ((mem= malloc(size)) == nil) fatal("Can't allocate memory");
-    return mem;
-}
-
-/* Choose a DHCP xid based on the start time and network number.  Not really
- * random, but we don't have anything more random than the clock anyway.
- */
-#define XID(np)		htonl(((u32_t) (np)->start << 8) | (np)->n)
-
-static network_t *network[N_NETS];
-
-int ifname2if(const char *name)
-{
-    /* Translate an interface name to a number, -1 if bad. */
-    char *end;
-    unsigned long n;
-
-    if (*name++ != 'i' || *name++ != 'p') return -1;
-    n= strtoul(name, &end, 10);
-    if (end == name || *end != 0) return -1;
-    if (n >= N_NETS) return -1;
-    return n;
-}
-
-network_t *if2net(int n)
-{
-    /* Translate an interface number to a network struct. */
-    int i;
-
-    for (i= 0; i < n_nets; i++) {
-	if (network[i]->n == n) return network[i];
-    }
-    return nil;
-}
-
-static ipaddr_t defaultmask(ipaddr_t ip)
-{
-    /* Compute netmask by the oldfashioned Class rules. */
-    if (B(&ip)[0] < 0x80) return HTONL(0xFF000000UL);	/* Class A. */
-    if (B(&ip)[0] < 0xC0) return HTONL(0xFFFF0000UL);	/* Class B. */
-    if (B(&ip)[0] < 0xE0) return HTONL(0xFFFFFF00UL);	/* Class C. */
-    return HTONL(0xFFFFFFFFUL);  /* Multicast?  Shouldn't happen... */
-}
-
-#define POOL_MAGIC	HTONL(0x81F85D00UL)
-
-typedef struct pool {		/* Dynamic pool entry. */
-	u32_t		magic;		/* Pool file magic number. */
-	ipaddr_t	ip;		/* IP address. */
-	u32_t		expire;		/* When does/did the lease expire? */
-	u8_t		len;		/* Client ID length. */
-	u8_t		unused[19];	/* Space for extensions. */
-	u8_t		clid[CLID_MAX];	/* Client ID of current/last user. */
-} pool_t;
-
-static int openpool(int mode)
-{
-    /* Open the dynamic pool and lock it, return fd on success or -1. */
-    int fd;
-    struct flock lck;
-
-    if ((fd= open(poolfile, mode, 0644)) < 0) {
-	if (errno != ENOENT) fatal(poolfile);
-	return -1;
-    }
-    if (mode != O_RDONLY) {
-	lck.l_type= F_WRLCK;
-	lck.l_whence= SEEK_SET;
-	lck.l_start= 0;
-	lck.l_len= 0;
-	if (fcntl(fd, F_SETLKW, &lck) < 0) fatal(poolfile);
-    }
-    return fd;
-}
-
-static int readpool(int fd, pool_t *entry)
-{
-    /* Read one pool table entry, return true unless EOF. */
-    ssize_t r;
-
-    if ((r= read(fd, entry, sizeof(*entry))) < 0) fatal(poolfile);
-    if (r == 0) return 0;
-
-    if (r != sizeof(*entry) || entry->magic != POOL_MAGIC) {
-	fprintf(stderr, "%s: %s: Pool table is corrupt\n",
-	    program, poolfile);
-	close(fd);
-	return 0;
-    }
-    return 1;
-}
-
-#if !__minix_vmd	/* No fsync() for Minix. */
-#define fsync(fd)	sync()
-#endif
-
-static void writepool(int fd, pool_t *entry)
-{
-    /* (Over)write a pool table entry. */
-    if (write(fd, entry, sizeof(*entry)) < 0
-	|| (entry->expire > now && fsync(fd) < 0)
-    ) {
-	fatal(poolfile);
-    }
-}
-
-static ipaddr_t findpool(u8_t *client, size_t len, ipaddr_t ifip)
-{
-    /* Look for a client ID in the dynamic address pool within the same network
-     * as 'ifip'.  Select an unused one for a new client if necessary.  Return
-     * 0 if nothing is available, otherwise the IP address we can offer.
-     */
-    int fd, found;
-    pool_t entry, oldest;
-    dhcp_t dhcp;
-    u8_t *pmask;
-    ipaddr_t mask;
-
-    /* Any information available on the network the client is at? */
-    if (!makedhcp(&dhcp, nil, 0, nil, 0, ifip, ifip, nil)) return 0;
-
-    if ((fd= openpool(O_RDWR)) < 0) return 0;
-
-    (void) gettag(&dhcp, DHCP_TAG_NETMASK, &pmask, nil);
-    memcpy(&mask, pmask, sizeof(mask));
-
-    oldest.expire= NEVER;
-    while ((found= readpool(fd, &entry))) {
-	/* Deleted entry? */
-	if (entry.ip == 0) continue;
-
-	/* Correct network? */
-	if (((entry.ip ^ ifip) & mask) != 0) continue;
-
-	/* Client present? */
-	if (entry.len == len && memcmp(entry.clid, client, len) == 0) break;
-
-	/* Oldest candidate for a new lease? */
-	entry.expire= ntohl(entry.expire);
-	if (entry.expire < oldest.expire) oldest= entry;
-    }
-    close(fd);
-
-    if (found) return entry.ip;
-    if (oldest.expire <= now) return oldest.ip;
-    return 0;
-}
-
-static int commitpool(ipaddr_t ip, u8_t *client, size_t len, time_t expire)
-{
-    /* Commit a new binding to stable storage, return true on success. */
-    int fd;
-    pool_t entry;
-
-    if ((fd= openpool(O_RDWR)) < 0) return 0;
-
-    do {
-	if (!readpool(fd, &entry)) {
-	    close(fd);
-	    return 0;
-	}
-    } while (entry.ip != ip);
-
-    entry.expire= htonl(expire);
-    entry.len= len;
-    memcpy(entry.clid, client, len);
-    if (lseek(fd, -(off_t)sizeof(entry), SEEK_CUR) == -1) fatal(poolfile);
-    writepool(fd, &entry);
-    close(fd);
-    return 1;
-}
-
-static void updatepool(int add, const char *name)
-{
-    /* Add a new IP address to the dynamic pool. */
-    ipaddr_t ip;
-    int fd, i;
-    pool_t entry;
-    struct hostent *he;
-    off_t off, off0;
-
-    if ((he= gethostbyname(name)) == nil || he->h_addrtype != AF_INET) {
-	fprintf(stderr, "%s: %s: Unknown host\n", program, name);
-	exit(1);
-    }
-    for (i= 0; he->h_addr_list[i] != nil; i++) {}
-    if (i != 1) {
-	fprintf(stderr, "%s: %s has %d addresses\n", program, name, i);
-	exit(1);
-    }
-    memcpy(&ip, he->h_addr_list[0], sizeof(ip));
-
-    if ((fd= openpool(O_RDWR|O_CREAT)) < 0) fatal(poolfile);
-
-    off= 0;
-    off0= -1;
-    while (readpool(fd, &entry)) {
-	if (add) {
-	    if (entry.ip == ip) {
-		fprintf(stderr, "%s: %s: %s is already present\n",
-		    program, poolfile, name);
-		exit(1);
-	    }
-	    if (entry.ip == 0 && off0 == -1) off0= off;
-	} else {
-	    if (entry.ip == ip) {
-		memset(&entry, 0, sizeof(entry));
-		entry.magic= POOL_MAGIC;
-		entry.ip= 0;
-		if (lseek(fd, off, SEEK_SET) == -1) fatal(poolfile);
-		writepool(fd, &entry);
-	    }
-	}
-	off+= sizeof(entry);
-    }
-
-    if (add) {
-	if (off0 != -1 && lseek(fd, off0, SEEK_SET) == -1) fatal(poolfile);
-	memset(&entry, 0, sizeof(entry));
-	entry.magic= POOL_MAGIC;
-	entry.ip= ip;
-	writepool(fd, &entry);
-    }
-    close(fd);
-}
-
-static void cachedhcp(int n, dhcp_t *dp)
-{
-    /* Store a DHCP packet in a cache where those who care can find it. */
-    static int inited;
-    FILE *fp;
-    int fd;
-    int mode;
-
-    if (test > 0) return;
-
-    if (!inited) {
-	/* First time, clear store and also save my pid. */
-	if ((fp= fopen(PATH_DHCPPID, "w")) != nil) {
-	    if (fprintf(fp, "%d\n", getpid()) == EOF || fclose(fp) == EOF) {
-		fatal(PATH_DHCPPID);
-	    }
-	}
-	inited= 1;
-	mode= O_WRONLY | O_CREAT | O_TRUNC;
-    } else {
-	mode= O_WRONLY;
-    }
-
-    dp->xid= htonl(now);	/* To tell how old this data is. */
-
-    if ((fd= open(cachefile, mode, 0666)) < 0
-	|| lseek(fd, (off_t) n * sizeof(*dp), SEEK_SET) == -1
-	|| write(fd, dp, sizeof(*dp)) < 0
-	|| close(fd) < 0
-    ) {
-	if (errno != ENOENT) fatal(cachefile);
-    }
-}
-
-static void printdata(void)
-{
-    /* Show the contents of the cache and the dynamic pool. */
-    int fd;
-    dhcp_t d;
-    ssize_t r;
-    int i;
-    pool_t entry;
-    unsigned long expire;
-    char delta[3*sizeof(u32_t)];
-
-    initdhcpconf();
-
-    if ((fd= open(cachefile, O_RDONLY)) < 0) fatal(cachefile);
-    i= 0;
-    while ((r= read(fd, &d, sizeof(d))) == sizeof(d)) {
-	if (d.yiaddr != 0) {
-	    printf("DHCP data for network %d:\n", i);
-	    printdhcp(&d);
-	}
-	i++;
-    }
-    if (r < 0) fatal(cachefile);
-    close(fd);
-
-    if ((fd= openpool(O_RDONLY)) >= 0) {
-	printf("Dynamic address pool since %ld:\n", (long) now);
-	while (readpool(fd, &entry)) {
-	    if (entry.ip == 0) continue;
-	    expire= ntohl(entry.expire);
-	    if (expire == 0) {
-		strcpy(delta, "unused");
-	    } else
-	    if (expire == 0xFFFFFFFFUL) {
-		strcpy(delta, "infinite");
-	    } else
-	    if (expire < now) {
-		sprintf(delta, "-%lu", now - expire);
-	    } else {
-		sprintf(delta, "+%lu", expire - now);
-	    }
-	    printf("\t%-15s %8s  ", inet_ntoa(entry.ip), delta);
-	    for (i= 0; i < entry.len; i++) {
-		printf("%02X", entry.clid[i]);
-	    }
-	    fputc('\n', stdout);
-	}
-	close(fd);
-    }
-}
-
-static udpport_t portbyname(const char *name)
-{
-    struct servent *se;
-
-    if ((se= getservbyname(name, "udp")) == nil) {
-	fprintf(stderr, "%s: Unknown port \"%s\"\n", program, name);
-	exit(1);
-    }
-    return se->s_port;
-}
-
-static int send(network_t *np, void *data, size_t len)
-{
-    /* Send out a packet using a filedescriptor that is probably in async mode,
-     * so first dup() a sync version, then write.  Return true on success.
-     */
-    int fd;
-    ssize_t r;
-
-    if ((fd= dup(np->fdp->fd)) < 0) fatal("Can't dup()");
-    if ((r= write(fd, data, len)) < 0) {
-	report(np->fdp->device);
-	sleep(10);
-    }
-    close(fd);
-    return r >= 0;
-}
-
-static size_t servdhcp(network_t *np, buf_t *bp, size_t dlen)
-{
-    buf_t *abp= nil;
-    ipaddr_t cip, ifip;
-    u8_t defclid[1+sizeof(bp->dhcp->chaddr)];
-    u8_t *pdata, *client, *class, *server, *reqip, *lease;
-    u32_t expire;
-    size_t len, cilen, calen;
-    int type, dyn;
-    u8_t atype;
-    static char NAKMESS[] = "IP address requested isn't yours";
-
-    if (test > 0) return 0;
-
-    /* The IP address of the interface close to the client. */
-    ifip= bp->dhcp->giaddr != 0 ? bp->dhcp->giaddr : np->ip;
-
-    /* All kinds of DHCP tags. */
-    if (gettag(bp->dhcp, DHCP_TAG_TYPE, &pdata, nil)) {
-	type= *pdata;
-    } else {
-	type= -1;		/* BOOTP? */
-    }
-
-    if (!gettag(bp->dhcp, DHCP_TAG_CLIENTID, &client, &cilen)) {
-	defclid[0]= bp->dhcp->htype;
-	memcpy(defclid+1, bp->dhcp->chaddr, bp->dhcp->hlen);
-	client= defclid;
-	cilen= 1+bp->dhcp->hlen;
-    }
-
-    if (!gettag(bp->dhcp, DHCP_TAG_CLASSID, &class, &calen)) {
-	calen= 0;
-    }
-
-    if (!gettag(bp->dhcp, DHCP_TAG_SERVERID, &server, nil)) {
-	server= B(&np->ip);
-    }
-
-    if (!gettag(bp->dhcp, DHCP_TAG_REQIP, &reqip, nil)) {
-	reqip= nil;
-    }
-
-    /* I'm a server?  Then see if I know this client. */
-    if ((np->flags & NF_SERVING)
-	&& bp->dhcp->op == DHCP_BOOTREQUEST
-	&& between(1, bp->dhcp->hlen, sizeof(bp->dhcp->chaddr))
-	&& (server == nil || memcmp(server, &np->ip, sizeof(np->ip)) == 0)
-    ) {
-	get_buf(&abp);
-
-	/* Is the client in my tables? */
-	(void) makedhcp(abp->dhcp, class, calen, client, cilen, 0, ifip, nil);
-	cip= abp->dhcp->yiaddr;
-
-	dyn= 0;
-	/* If not, do we have a dynamic address? */
-	if (cip == 0 && (cip= findpool(client, cilen, ifip)) != 0) dyn= 1;
-
-	if (type == DHCP_INFORM) {
-	    /* The client already has an address, it just wants information.
-	     * We only answer if we could answer a normal request (cip != 0),
-	     * unless configured to answer anyone.
-	     */
-	    if (cip != 0 || (np->flags & NF_INFORM)) cip= bp->dhcp->ciaddr;
-	}
-
-	if (cip == 0 || !makedhcp(abp->dhcp, class, calen,
-					client, cilen, cip, ifip, nil)) {
-	    put_buf(&abp);
-	}
-
-	if (abp != nil) {
-	    if (gettag(abp->dhcp, DHCP_TAG_LEASE, &lease, nil)) {
-		memcpy(&expire, lease, sizeof(expire));
-		expire= now + ntohl(expire);
-		if (expire < now) expire= 0xFFFFFFFFUL;
-	    } else {
-		if (dyn) {
-		    /* A dynamic address must have a lease. */
-		    fprintf(stderr, "%s: No lease set for address %s\n",
-			program, inet_ntoa(cip));
-		    exit(1);
-		}
-		lease= nil;
-		expire= 0xFFFFFFFFUL;
-	    }
-
-	    /* What does our client want, and what do we say? */
-	    switch (type) {
-	    case DHCP_DISCOVER:
-		atype= DHCP_OFFER;
-
-		/* Assign this address for a short moment. */
-		if (dyn && !commitpool(cip, client, cilen, now + DELTA_FAST)) {
-		    put_buf(&abp);
-		}
-		break;
-
-	    case -1:/* BOOTP */
-	    case DHCP_REQUEST:
-	    case DHCP_INFORM:
-		atype= DHCP_ACK;
-		/* The address wanted must be the address we offer. */
-		if ((reqip != nil && memcmp(reqip, &cip, sizeof(cip)) != 0)
-		    || (bp->dhcp->ciaddr != 0 && bp->dhcp->ciaddr != cip)
-		) {
-		    atype= DHCP_NAK;
-		} else
-		if (dyn && type == DHCP_REQUEST) {
-		    /* Assign this address for the duration of the lease. */
-		    if (!commitpool(cip, client, cilen, expire)) put_buf(&abp);
-		}
-		break;
-
-	    case DHCP_DECLINE:
-		/* Our client doesn't want the offered address! */
-		if (dyn
-		    && reqip != nil
-		    && memcmp(reqip, &cip, sizeof(cip)) == 0
-		) {
-		    int i;
-
-		    fprintf(stderr, "%s: ", program);
-		    for (i= 0; i < cilen; i++) {
-			fprintf(stderr, "%02X", client[i]);
-		    }
-		    fprintf(stderr, " declines %s", inet_ntoa(cip));
-		    if (gettag(bp->dhcp, DHCP_TAG_MESSAGE, &pdata, &len)) {
-			fprintf(stderr, " saying: \"%.*s\"", (int)len, pdata);
-		    }
-		    fputc('\n', stderr);
-
-		    /* Disable address for the duration of the lease. */
-		    (void) commitpool(cip, nil, 0, expire);
-		}
-		put_buf(&abp);
-		break;
-
-	    case DHCP_RELEASE:
-		/* Our client is nice enough to return its address. */
-		if (dyn) (void) commitpool(cip, client, cilen, now);
-		put_buf(&abp);
-		break;
-
-	    default:	/* Anything else is ignored. */
-		put_buf(&abp);
-	    }
-	}
-
-	if (abp != nil) {
-	    /* Finish the return packet. */
-	    abp->dhcp->htype= bp->dhcp->htype;
-	    abp->dhcp->hlen= bp->dhcp->hlen;
-	    abp->dhcp->hops= 0;
-	    abp->dhcp->xid= bp->dhcp->xid;
-	    abp->dhcp->secs= 0;
-	    abp->dhcp->flags= bp->dhcp->flags;
-	    abp->dhcp->ciaddr= 0;
-	    abp->dhcp->yiaddr= atype == DHCP_NAK ? 0 : cip;
-	    if (atype == DHCP_NAK) abp->dhcp->siaddr= 0;
-	    abp->dhcp->giaddr= bp->dhcp->giaddr;
-	    memcpy(abp->dhcp->chaddr,bp->dhcp->chaddr,sizeof(bp->dhcp->chaddr));
-
-	    settag(abp->dhcp, DHCP_TAG_SERVERID, &np->ip, sizeof(np->ip));
-
-	    if (lease == nil) {
-		/* No lease specified?  Then give an infinite lease. */
-		settag(abp->dhcp, DHCP_TAG_LEASE, &expire, sizeof(expire));
-	    }
-
-	    if (type == DHCP_INFORM) {
-		/* Oops, this one has a fixed address, so no lease business. */
-		abp->dhcp->yiaddr= 0;
-		settag(abp->dhcp, DHCP_TAG_LEASE, nil, 0);
-		settag(abp->dhcp, DHCP_TAG_RENEWAL, nil, 0);
-		settag(abp->dhcp, DHCP_TAG_REBINDING, nil, 0);
-	    }
-
-	    if (atype == DHCP_NAK) {
-		/* A NAK doesn't need much. */
-		memset(abp->dhcp->sname, 0, sizeof(abp->dhcp->sname));
-		memset(abp->dhcp->file, 0, sizeof(abp->dhcp->file));
-		memset(abp->dhcp->options, 255, sizeof(abp->dhcp->options));
-		settag(abp->dhcp, DHCP_TAG_MESSAGE, NAKMESS, sizeof(NAKMESS));
-	    }
-
-	    settag(abp->dhcp, DHCP_TAG_TYPE, &atype, sizeof(atype));
-
-	    /* Figure out where to send this to. */
-	    abp->udpio->uih_src_addr= np->ip;
-	    abp->udpio->uih_src_port= port_server;
-	    if (bp->dhcp->giaddr != 0) {
-		abp->udpio->uih_dst_addr= bp->dhcp->giaddr;
-		abp->udpio->uih_dst_port= port_server;
-	    } else
-	    if (bp->dhcp->flags & DHCP_FLAGS_BCAST) {
-		abp->udpio->uih_dst_addr= BCAST_IP;
-		abp->udpio->uih_dst_port= port_client;
-	    } else
-	    if (bp->udpio->uih_src_addr != 0
-		&& bp->udpio->uih_dst_addr == np->ip
-	    ) {
-		abp->udpio->uih_dst_addr= bp->udpio->uih_src_addr;
-		abp->udpio->uih_dst_port= port_client;
-	    } else {
-		abp->udpio->uih_dst_addr= BCAST_IP;
-		abp->udpio->uih_dst_port= port_client;
-	    }
-	    abp->udpio->uih_ip_opt_len= 0;
-	    abp->udpio->uih_data_len= sizeof(dhcp_t);
-
-	    /* Copy the packet to the input buffer, and return the new size. */
-	    memcpy(bp->buf, abp->buf, sizeof(bp->buf));
-	    put_buf(&abp);
-	    return sizeof(udp_io_hdr_t) + sizeof(dhcp_t);
-	}
-    }
-
-    /* I'm a relay?  If it is a not already a relayed request then relay. */
-    if ((np->flags & NF_RELAYING)
-	&& bp->dhcp->op == DHCP_BOOTREQUEST
-	&& bp->dhcp->giaddr == 0
-    ) {
-	bp->dhcp->giaddr= np->ip;
-	bp->udpio->uih_src_addr= np->ip;
-	bp->udpio->uih_src_port= port_server;
-	bp->udpio->uih_dst_addr= np->server;
-	bp->udpio->uih_dst_port= port_server;
-	return dlen;
-    }
-
-    /* I'm a relay?  If the server sends a reply to me then relay back. */
-    if ((np->flags & NF_RELAYING)
-	&& bp->dhcp->op == DHCP_BOOTREPLY
-	&& bp->dhcp->giaddr == np->ip
-    ) {
-	bp->dhcp->giaddr= 0;
-	bp->udpio->uih_src_addr= np->ip;
-	bp->udpio->uih_src_port= port_server;
-	bp->udpio->uih_dst_addr= BCAST_IP;
-	bp->udpio->uih_dst_port= port_client;
-	return dlen;
-    }
-
-    /* Don't know what to do otherwise, so doing nothing seems wise. */
-    return 0;
-}
-
-static void onsig(int sig)
-{
-    switch (sig) {
-    case SIGUSR1:	debug++;	break;
-    case SIGUSR2:	debug= 0;	break;
-    }
-}
-
-static void usage(void)
-{
-    fprintf(stderr,
-"Usage: %s [-qar] [-t[L]] [-d[L]] [-f config] [-c cache] [-p pool] [host ...]\n",
-	program);
-    exit(1);
-}
-
-int main(int argc, char **argv)
-{
-    int i;
-    network_t *np;
-    struct sigaction sa;
-    ssize_t r= -1;
-    buf_t *bp= nil;
-    static struct timeval eventtv;
-
-    program= argv[0];
-    start= now= time(nil);
-
-    debug= 0;
-    i= 1;
-    while (i < argc && argv[i][0] == '-') {
-	char *opt= argv[i++]+1;
-
-	if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-	while (*opt != 0) switch (*opt++) {
-	case 'f':
-	    if (*opt == 0) {
-		if (i == argc) usage();
-		opt= argv[i++];
-	    }
-	    configfile= opt;
-	    opt= "";
-	    break;
-	case 'c':
-	    if (*opt == 0) {
-		if (i == argc) usage();
-		opt= argv[i++];
-	    }
-	    cachefile= opt;
-	    opt= "";
-	    break;
-	case 'p':
-	    if (*opt == 0) {
-		if (i == argc) usage();
-		opt= argv[i++];
-	    }
-	    poolfile= opt;
-	    opt= "";
-	    break;
-	case 't':
-	    test= 1;
-	    if (between('0', *opt, '9')) test= strtoul(opt, &opt, 10);
-	    break;
-	case 'd':
-	    debug= 1;
-	    if (between('0', *opt, '9')) debug= strtoul(opt, &opt, 10);
-	    break;
-	case 'q':
-	    qflag= 1;
-	    break;
-	case 'a':
-	    aflag= 1;
-	    break;
-	case 'r':
-	    rflag= 1;
-	    break;
-	default:
-	    usage();
-	}
-    }
-    if (aflag + rflag + qflag > 1) usage();
-
-    if (aflag || rflag) {
-	/* Add or remove addresses from the dynamic pool. */
-	while (i < argc) updatepool(aflag, argv[i++]);
-	exit(0);
-    }
-
-    if (i != argc) usage();
-
-    if (qflag) {
-	/* Only show the contents of the cache and dynamic pool to the user. */
-	printdata();
-	exit(0);
-    }
-
-    /* BOOTP ports. */
-    port_server= portbyname("bootps");
-    port_client= portbyname("bootpc");
-
-    sa.sa_handler= onsig;
-    sigemptyset(&sa.sa_mask);
-    sa.sa_flags= 0;
-    sigaction(SIGUSR1, &sa, nil);
-    sigaction(SIGUSR2, &sa, nil);
-
-    /* Initial configuration. */
-    for (i= 0; i < N_NETS; i++) {
-	int fd;
-	ipaddr_t ip, mask;
-
-	/* Is there something there? */
-	if ((fd= open(ipdev(i), O_RDWR|O_NONBLOCK)) < 0) {
-	    if (errno != ENOENT && errno != ENODEV && errno != ENXIO) {
-		fatal(ipdev(i));
-	    }
-	    continue;
-	}
-	close(fd);
-
-	network[n_nets++]= np= newnetwork();
-	np->n= i;
-
-	/* Ethernet? */
-	if (opendev(np, FT_ETHERNET, 1)) {
-	    np->type= B(&np->eth)[0] != 'Z' ? NT_ETHERNET : NT_SINK;
-	    if (debug >= 1) {
-		printf("%s: Ethernet address is %s%s\n",
-		    np->fdp->device, ether_ntoa(&np->eth),
-		    np->type == NT_SINK ? " (sink)" : "");
-	    }
-	    closedev(np, FT_ETHERNET);
-	}
-
-	/* Only true Ethernets worry about DHCP. */
-	if (np->type != NT_ETHERNET) np->renew= np->rebind= np->lease= NEVER;
-    }
-
-    /* Try to find my interfaces in the DHCP table. */
-    for (i= 0; i < n_nets; i++) {
-	ipaddr_t cip;
-	u8_t clid[1+DHCP_HLEN_ETH];
-	size_t cilen;
-
-	np= network[i];
-	if (np->flags & NF_BOUND) continue;
-
-	if (np->type == NT_IP) {
-	    cilen= 0;
-	} else {
-	    ether2clid(clid, &np->eth);
-	    cilen= 1+DHCP_HLEN_ETH;
-	}
-
-	/* Try to find an Ethernet address, or the IP address of an already
-	 * configured network.  If we have data we get an IP address back.
-	 */
-	get_buf(&bp);
-	(void) makedhcp(bp->dhcp, (u8_t *) "Minix", 5,
-					clid, cilen, np->ip, 0, np);
-	cip= bp->dhcp->yiaddr;
-
-	/* Gather information on the interface. */
-	if (cip != 0
-	    && makedhcp(bp->dhcp, (u8_t *) "Minix", 5,
-					clid, cilen, cip, cip, np)
-	    && test < 2
-	) {
-	    u8_t *pdata;
-	    u16_t mtu;
-
-	    cachedhcp(np->n, bp->dhcp);
-	    np->ip= cip;
-	    (void) gettag(bp->dhcp, DHCP_TAG_NETMASK, &pdata, nil);
-	    memcpy(&np->mask, pdata, sizeof(np->mask));
-	    if (gettag(bp->dhcp, DHCP_TAG_GATEWAY, &pdata, nil)) {
-		memcpy(&np->gateway, pdata, sizeof(np->gateway));
-	    } else {
-		np->gateway= 0;
-	    }
-	    if (gettag(bp->dhcp, DHCP_TAG_IPMTU, &pdata, nil)) {
-		memcpy(&mtu, pdata, sizeof(mtu));
-		mtu= ntohs(mtu);
-	    } else {
-		mtu= 0;
-	    }
-	    set_ipconf(ipdev(np->n), np->ip, np->mask, mtu);
-	    if (debug >= 1) {
-		printf("%s: IP address is %s\n",
-		    ipdev(np->n), cidr_ntoa(np->ip, np->mask));
-	    }
-	    np->flags |= NF_BOUND;
-	    np->renew= np->rebind= np->lease= NEVER;
-	    np->sol_ct= N_SOLICITS;
-	    np->solicit= 0;
-
-	    /* Other (previous) interfaces may have been defined. */
-	    i= 0;
-	}
-	put_buf(&bp);
-    }
-
-    for (;;) {
-	now= time(nil);
-	event= NEVER;
-
-	/* Is it time to request/renew a lease? */
-	for (i= 0; i < n_nets; i++) {
-	    np= network[i];
-
-	    if (np->renew <= now) {
-		u8_t type;
-		static u8_t taglist[] = {
-		    DHCP_TAG_NETMASK, DHCP_TAG_GATEWAY, DHCP_TAG_DNS,
-		    	DHCP_TAG_HOSTNAME
-		};
-		u8_t ethclid[1+DHCP_HLEN_ETH];
-
-		/* We may have lost our binding or even our lease. */
-		if (np->rebind <= now) np->server= BCAST_IP;
-
-		if (np->lease <= now) {
-		    if (np->flags & NF_BOUND) closedev(np, FT_ALL);
-
-		    if ((np->flags & (NF_BOUND | NF_POSSESSIVE)) == NF_BOUND) {
-			set_ipconf(ipdev(np->n), np->ip= 0, np->mask= 0, 0);
-			if (debug >= 1) {
-			    printf("%s: Interface disabled (lease expired)\n",
-				ipdev(np->n));
-			}
-		    }
-		    np->flags &= ~NF_BOUND;
-		}
-
-		/* See if we can open the network we need to send on. */
-		if (!(np->flags & NF_BOUND)) {
-		    if (!opendev(np, FT_ETHERNET, 1)) continue;
-		} else {
-		    if (!opendev(np, FT_BOOTPC, 1)) continue;
-		}
-
-		if (!(np->flags & NF_NEGOTIATING)) {
-		    /* We need to start querying a DHCP server. */
-		    np->start= now;
-		    np->delta= DELTA_FIRST;
-		    np->flags |= NF_NEGOTIATING;
-		}
-
-		/* Fill in a DHCP query packet. */
-		get_buf(&bp);
-		dhcp_init(bp->dhcp);
-		bp->dhcp->op= DHCP_BOOTREQUEST;
-		bp->dhcp->htype= DHCP_HTYPE_ETH;
-		bp->dhcp->hlen= DHCP_HLEN_ETH;
-		bp->dhcp->xid= XID(np);
-		bp->dhcp->secs= htons(now - np->start > 0xFFFF
-					? 0xFFFF : now - np->start);
-		memcpy(bp->dhcp->chaddr, &np->eth, sizeof(np->eth));
-
-		if (np->lease <= now) {
-		    /* First time, or my old server is unresponsive. */
-		    type= DHCP_DISCOVER;
-		} else {
-		    /* Request an offered address or renew an address. */
-		    type= DHCP_REQUEST;
-		    if (np->flags & NF_BOUND) {
-			/* A renewal, I claim my current address. */
-			bp->dhcp->ciaddr= np->ip;
-		    } else {
-			/* Nicely ask for the address just offered. */
-			settag(bp->dhcp, DHCP_TAG_REQIP, &np->ip,
-							sizeof(np->ip));
-			settag(bp->dhcp, DHCP_TAG_SERVERID, &np->server,
-							sizeof(np->server));
-		    }
-		}
-		settag(bp->dhcp, DHCP_TAG_TYPE, &type, 1);
-
-		/* My client ID.  Simply use the default. */
-		ether2clid(ethclid, &np->eth);
-		settag(bp->dhcp, DHCP_TAG_CLIENTID, ethclid, sizeof(ethclid));
-
-		/* The Class ID may serve to recognize Minix hosts. */
-		settag(bp->dhcp, DHCP_TAG_CLASSID, "Minix", 5);
-
-		/* The few tags that Minix can make good use of. */
-		settag(bp->dhcp, DHCP_TAG_REQPAR, taglist, sizeof(taglist));
-
-		/* Some weird sites use a hostname, not a client ID. */
-		if (np->hostname != nil) {
-		    settag(bp->dhcp, DHCP_TAG_HOSTNAME,
-					np->hostname, strlen(np->hostname));
-		}
-
-		bp->udpio->uih_src_addr= np->ip;
-		bp->udpio->uih_dst_addr= np->server;
-		bp->udpio->uih_src_port= port_client;
-		bp->udpio->uih_dst_port= port_server;
-		bp->udpio->uih_ip_opt_len= 0;
-		bp->udpio->uih_data_len= sizeof(dhcp_t);
-
-		if (!(np->flags & NF_BOUND)) {
-		    /* Rebind over Ethernet. */
-		    udp2ether(bp, np);
-		    if (send(np, bp->eth, sizeof(eth_hdr_t) + sizeof(ip_hdr_t)
-					+ sizeof(udp_hdr_t) + sizeof(dhcp_t))) {
-			if (debug >= 1) {
-			    printf("%s: Broadcast DHCP %s\n",
-				np->fdp->device, dhcptypename(type));
-			    if (debug >= 2) printdhcp(bp->dhcp);
-			}
-		    }
-		} else {
-		    /* Renew over UDP. */
-		    if (send(np, bp->udpio, sizeof(udp_io_hdr_t)
-							+ sizeof(dhcp_t))) {
-			if (debug >= 1) {
-			    printf("%s: Sent DHCP %s to %s\n",
-				np->fdp->device,
-				dhcptypename(type),
-				inet_ntoa(np->server));
-			    if (debug >= 2) printdhcp(bp->dhcp);
-			}
-		    }
-		}
-		put_buf(&bp);
-
-		/* When to continue querying a DHCP server? */
-		if (np->flags & NF_BOUND) {
-		    /* Still bound, keep halving time till next event. */
-		    time_t e, d;
-
-		    e= now < np->rebind ? np->rebind : np->lease;
-		    d= (e - now) / 2;
-		    if (d < DELTA_SLOW) d= DELTA_SLOW;
-		    np->renew= now + d;
-		    if (np->renew > e) np->renew= e;
-		} else {
-		    /* Not bound, be desparate. */
-		    np->renew= now + np->delta;
-		    if ((np->delta *= 2) > DELTA_FAST) np->delta= DELTA_FAST;
-		}
-	    }
-	    if (np->renew < event) event= np->renew;
-	}
-
-	/* Read DHCP responses. */
-	for (i= 0; i < n_nets; i++) {
-	    np= network[i];
-	    if (!(np->flags & NF_NEGOTIATING)) continue;
-
-	    if (!(np->flags & NF_BOUND)) {
-		if (!opendev(np, FT_ETHERNET, 0)) continue;
-		get_buf(&np->fdp->bp);
-		r= asyn_read(&asyn, np->fdp->fd, np->fdp->bp->eth,
-							BUF_ETH_SIZE);
-	    } else {
-		if (!opendev(np, FT_BOOTPC, 0)) continue;
-		get_buf(&np->fdp->bp);
-		r= asyn_read(&asyn, np->fdp->fd, np->fdp->bp->udpio,
-							BUF_UDP_SIZE);
-	    }
-	    if (r != -1) break;
-	    if (errno != ASYN_INPROGRESS && errno != EPACKSIZE) {
-		report(np->fdp->device);
-		sleep(10);
-	    }
-	}
-
-	/* Is there a response? */
-	if (i < n_nets) {
-	    give_buf(&bp, &np->fdp->bp);
-	    if (((!(np->flags & NF_BOUND)
-		    && r >= (sizeof(eth_hdr_t) + sizeof(ip_hdr_t)
-				+ sizeof(udp_hdr_t) + offsetof(dhcp_t, options))
-		    && ether2udp(bp)
-		    && bp->udpio->uih_dst_port == port_client)
-		  ||
-		  ((np->flags & NF_BOUND)
-		    && r >= sizeof(udp_io_hdr_t) + offsetof(dhcp_t, options)))
-		&& bp->dhcp->op == DHCP_BOOTREPLY
-		&& bp->dhcp->htype == DHCP_HTYPE_ETH
-		&& bp->dhcp->hlen == DHCP_HLEN_ETH
-		&& bp->dhcp->xid == XID(np)
-		&& memcmp(bp->dhcp->chaddr, &np->eth, sizeof(np->eth)) == 0
-	    ) {
-		/* Pfew!  We got a DHCP reply! */
-		u8_t *pdata;
-		size_t len;
-		int type;
-		ipaddr_t mask, gateway, relay, server;
-		u16_t mtu;
-		u32_t lease, renew, rebind, t;
-
-		relay= bp->udpio->uih_src_addr;
-		if (gettag(bp->dhcp, DHCP_TAG_SERVERID, &pdata, nil)) {
-		    memcpy(&server, pdata, sizeof(server));
-		} else {
-		    server= relay;
-		}
-
-		if (gettag(bp->dhcp, DHCP_TAG_TYPE, &pdata, nil)) {
-		    type= pdata[0];
-		} else {
-		    type= DHCP_ACK;	/* BOOTP? */
-		}
-
-		if (debug >= 1) {
-		    printf("%s: Got a DHCP %s from %s",
-			np->fdp->device, dhcptypename(type), inet_ntoa(server));
-		    printf(relay != server ? " through %s\n" : "\n",
-			inet_ntoa(relay));
-		    if (debug >= 2) printdhcp(bp->dhcp);
-		}
-
-		if (gettag(bp->dhcp, DHCP_TAG_NETMASK, &pdata, nil)) {
-		    memcpy(&mask, pdata, sizeof(mask));
-		} else {
-		    mask= defaultmask(bp->dhcp->ciaddr);
-		}
-
-		if (gettag(bp->dhcp, DHCP_TAG_IPMTU, &pdata, nil)) {
-		    memcpy(&mtu, pdata, sizeof(mtu));
-		    mtu= ntohs(mtu);
-		} else {
-		    mtu= 0;
-		}
-
-		if (gettag(bp->dhcp, DHCP_TAG_GATEWAY, &pdata, nil)) {
-		    memcpy(&gateway, pdata, sizeof(gateway));
-		} else {
-		    gateway= 0;
-		}
-
-		lease= NEVER;
-		if (gettag(bp->dhcp, DHCP_TAG_LEASE, &pdata, nil)) {
-		    memcpy(&lease, pdata, sizeof(lease));
-		    lease= ntohl(lease);
-		}
-
-		rebind= lease - lease / 8;
-		if (gettag(bp->dhcp, DHCP_TAG_REBINDING, &pdata, nil)) {
-		    memcpy(&t, pdata, sizeof(t));
-		    t= ntohl(t);
-		    if (t < rebind) rebind= t;
-		}
-
-		renew= lease / 2;
-		if (gettag(bp->dhcp, DHCP_TAG_RENEWAL, &pdata, nil)) {
-		    memcpy(&t, pdata, sizeof(t));
-		    t= ntohl(t);
-		    if (t < renew) renew= t;
-		}
-
-		if (type == DHCP_OFFER && np->rebind <= np->renew) {
-		    /* It's an offer for an address and we haven't taken one
-		     * yet.  It's all the same to us, so take this one.
-		     */
-		    np->ip= bp->dhcp->yiaddr;
-		    np->mask= mask;
-		    np->server= server;
-		    np->gateway= gateway;
-		    np->delta= DELTA_FIRST;
-		    np->renew= now;
-		    np->rebind= np->lease= now + DELTA_FAST;
-
-		    /* Send out an ARP request to see if the offered address
-		     * is in use already.
-		     */
-		    make_arp(bp, np);
-		    if (send(np, bp->eth, sizeof(arp46_t))) {
-			if (debug >= 2) {
-			    printf("Sent ARP for %s\n", inet_ntoa(np->ip));
-			}
-		    }
-		    np->flags &= ~NF_CONFLICT;
-		}
-
-		if (type == DHCP_ACK && !(np->flags & NF_CONFLICT)) {
-		    /* An acknowledgment.  The address is all mine. */
-		    cachedhcp(np->n, bp->dhcp);
-		    np->ip= bp->dhcp->yiaddr;
-		    np->mask= mask;
-		    np->server= server;
-		    set_ipconf(ipdev(np->n), np->ip, np->mask, mtu);
-		    if (debug >= 1) {
-			printf("%s: Address set to %s\n",
-			    ipdev(np->n), cidr_ntoa(np->ip, np->mask));
-		    }
-		    if (lease >= NEVER - now) {
-			/* The lease is infinite! */
-			np->renew= np->rebind= np->lease= NEVER;
-		    } else {
-			np->lease= now + lease;
-			np->renew= now + renew;
-			np->rebind= now + rebind;
-		    }
-		    if (test >= 3) {
-			np->renew= now + 60;
-			np->rebind= test >= 4 ? np->renew : np->renew + 60;
-			np->lease= test >= 5 ? np->rebind : np->rebind + 60;
-		    }
-		    if (!(np->flags & NF_IRDP)) {
-			np->sol_ct= (np->flags & NF_BOUND) ? 1 : N_SOLICITS;
-			np->solicit= 0;
-		    }
-		    np->flags &= ~NF_NEGOTIATING;
-		    np->flags |= NF_BOUND;
-		    closedev(np, FT_ETHERNET);
-		    closedev(np, FT_BOOTPC);
-		}
-
-		if (type == DHCP_ACK && (np->flags & NF_CONFLICT)) {
-		    /* Alas there is a conflict.  Decline to use the address. */
-		    u8_t ethclid[1+DHCP_HLEN_ETH];
-		    static char USED[]= "Address in use by 00:00:00:00:00:00";
-
-		    type= DHCP_DECLINE;
-		    dhcp_init(bp->dhcp);
-		    bp->dhcp->op= DHCP_BOOTREQUEST;
-		    bp->dhcp->htype= DHCP_HTYPE_ETH;
-		    bp->dhcp->hlen= DHCP_HLEN_ETH;
-		    bp->dhcp->xid= XID(np);
-		    bp->dhcp->secs= 0;
-		    memcpy(bp->dhcp->chaddr, &np->eth, sizeof(np->eth));
-		    settag(bp->dhcp, DHCP_TAG_REQIP, &np->ip, sizeof(np->ip));
-		    settag(bp->dhcp, DHCP_TAG_TYPE, &type, 1);
-		    ether2clid(ethclid, &np->eth);
-		    settag(bp->dhcp, DHCP_TAG_CLIENTID,ethclid,sizeof(ethclid));
-		    strcpy(USED+18, ether_ntoa(&np->conflict));
-		    settag(bp->dhcp, DHCP_TAG_MESSAGE, USED, strlen(USED));
-
-		    bp->udpio->uih_src_port= port_client;
-		    bp->udpio->uih_dst_port= port_server;
-		    bp->udpio->uih_ip_opt_len= 0;
-		    bp->udpio->uih_data_len= sizeof(dhcp_t);
-		    udp2ether(bp, np);
-
-		    if (send(np, bp->eth, sizeof(eth_hdr_t) + sizeof(ip_hdr_t)
-					+ sizeof(udp_hdr_t) + sizeof(dhcp_t))) {
-			if (debug >= 1) {
-			    printf("%s: Broadcast DHCP %s\n",
-				np->fdp->device, dhcptypename(type));
-			    if (debug >= 2) printdhcp(bp->dhcp);
-			}
-		    }
-		    
-		    np->renew= np->rebind= np->lease= now + DELTA_FAST;
-		    np->delta= DELTA_FIRST;
-		}
-
-		if (type == DHCP_NAK) {
-		    /* Oops, a DHCP server doesn't like me, start over! */
-		    np->renew= np->rebind= np->lease= now + DELTA_FAST;
-		    np->delta= DELTA_FIRST;
-
-		    fprintf(stderr, "%s: Got a NAK from %s",
-			program, inet_ntoa(server));
-		    if (relay != server) {
-			fprintf(stderr, " through %s", inet_ntoa(relay));
-		    }
-		    if (gettag(bp->dhcp, DHCP_TAG_MESSAGE, &pdata, &len)) {
-			fprintf(stderr, " saying: \"%.*s\"", (int)len, pdata);
-		    }
-		    fputc('\n', stderr);
-		}
-	    } else
-	    if (!(np->flags & NF_BOUND)
-		&& np->rebind > now
-		&& r >= sizeof(arp46_t)
-		&& is_arp_me(bp, np)
-	    ) {
-		/* Oh no, someone else is using the address offered to me! */
-		np->flags |= NF_CONFLICT;
-
-		fprintf(stderr, "%s: %s: %s offered by ",
-			program,
-			np->fdp->device,
-			inet_ntoa(np->ip));
-		fprintf(stderr, "%s is already in use by %s\n",
-			inet_ntoa(np->server),
-			ether_ntoa(&np->conflict));
-	    }
-	    put_buf(&bp);
-	    if (np->renew < event) event= np->renew;
-	}
-
-	/* Perform router solicitations. */
-	for (i= 0; i < n_nets; i++) {
-	    np= network[i];
-	    if (!(np->flags & NF_BOUND)) continue;
-
-	    if (np->solicit <= now) {
-		if (!opendev(np, FT_ICMP, 1)) continue;
-		np->solicit= NEVER;
-
-		get_buf(&bp);
-		if (np->gateway != 0) {
-		    /* No IRDP response seen yet, advertise the router given
-		     * by DHCP to my own interface.
-		     */
-		    icmp_advert(bp, np);
-		    if (send(np, bp->ip, sizeof(ip_hdr_t) + 16)) {
-			if (debug >= 2) {
-			    printf("%s: Sent advert for %s to self\n",
-				np->fdp->device, inet_ntoa(np->gateway));
-			}
-		    }
-		    np->solicit= now + DELTA_ADV/2;
-		}
-
-		if (np->sol_ct >= 0 && --np->sol_ct >= 0) {
-		    /* Send a router solicitation. */
-		    icmp_solicit(bp);
-		    if (send(np, bp->ip, sizeof(*bp->ip) + 8)) {
-			if (debug >= 2) {
-			    printf("%s: Broadcast router solicitation\n",
-				np->fdp->device);
-			}
-		    }
-		    np->solicit= now + DELTA_SOL;
-		} else {
-		    /* No response, or not soliciting right now. */
-		    closedev(np, FT_ICMP);
-		}
-
-		put_buf(&bp);
-	    }
-	    if (np->solicit < event) event= np->solicit;
-	}
-
-	/* Read router adverts. */
-	for (i= 0; i < n_nets; i++) {
-	    np= network[i];
-	    if (!(np->flags & NF_BOUND)) continue;
-	    if (np->sol_ct < 0) continue;
-
-	    if (!opendev(np, FT_ICMP, 0)) continue;
-	    get_buf(&np->fdp->bp);
-	    r= asyn_read(&asyn, np->fdp->fd, np->fdp->bp->ip, BUF_IP_SIZE);
-	    if (r != -1) break;
-	    if (errno != ASYN_INPROGRESS && errno != EPACKSIZE) {
-		report(np->fdp->device);
-		sleep(10);
-	    }
-	}
-
-	/* Is there an advert? */
-	if (i < n_nets && r >= sizeof(ip_hdr_t) + 8) {
-	    ipaddr_t router;
-
-	    give_buf(&bp, &np->fdp->bp);
-	    if ((router= icmp_is_advert(bp)) != 0) {
-		if (debug >= 2) {
-		    printf("%s: Router advert received from %s\n",
-			np->fdp->device, inet_ntoa(router));
-		}
-		np->solicit= NEVER;
-		np->sol_ct= -1;
-		np->flags |= NF_IRDP;
-		closedev(np, FT_ICMP);
-	    }
-	    put_buf(&bp);
-	}
-
-	/* We start serving if all the interfaces so marked are configured. */
-	for (i= 0; i < n_nets; i++) {
-	    np= network[i];
-	    if ((np->flags & NF_RELAYING) && (np->flags & NF_BOUND)) {
-		if (((np->ip ^ np->server) & np->mask) == 0) {
-		    /* Don't relay to a server that is on this same net. */
-		    np->flags &= ~NF_RELAYING;
-		}
-	    }
-	    if (!(np->flags & (NF_SERVING|NF_RELAYING))) continue;
-	    if (!(np->flags & NF_BOUND)) { serving= 0; break; }
-	    serving= 1;
-	}
-
-	/* Read DHCP requests. */
-	for (i= 0; i < n_nets; i++) {
-	    np= network[i];
-	    if (!(np->flags & NF_BOUND)) continue;
-	    if (!(np->flags & (NF_SERVING|NF_RELAYING)) || !serving) continue;
-
-	    if (!opendev(np, FT_BOOTPS, 0)) continue;
-	    get_buf(&np->fdp->bp);
-	    r= asyn_read(&asyn, np->fdp->fd, np->fdp->bp->udpio, BUF_UDP_SIZE);
-
-	    if (r != -1) break;
-	    if (errno != ASYN_INPROGRESS && errno != EPACKSIZE) {
-		report(np->fdp->device);
-		sleep(10);
-	    }
-	}
-
-	/* Is there a request? */
-	if (i < n_nets
-	    && r >= sizeof(udp_io_hdr_t) + offsetof(dhcp_t, options)
-	) {
-	    give_buf(&bp, &np->fdp->bp);
-
-	    if (debug >= 1) {
-		printf("%s: Got DHCP packet from %s to ",
-		    np->fdp->device, inet_ntoa(bp->udpio->uih_src_addr));
-		printf("%s\n", inet_ntoa(bp->udpio->uih_dst_addr));
-		if (debug >= 2) printdhcp(bp->dhcp);
-	    }
-
-	    /* Can we do something with this DHCP packet? */
-	    if ((r= servdhcp(np, bp, r)) > 0) {
-		/* Yes, we have something to send somewhere. */
-		if (send(np, bp->udpio, r)) {
-		    if (debug >= 1) {
-			printf("%s: Sent DHCP packet to %s\n",
-			    np->fdp->device,
-			    inet_ntoa(bp->udpio->uih_dst_addr));
-			if (debug >= 2) printdhcp(bp->dhcp);
-		    }
-		}
-	    }
-	    put_buf(&bp);
-	}
-
-	if (debug >= 1) {
-	    static char *lastbrk;
-	    extern char _end;
-
-	    if (sbrk(0) != lastbrk) {
-		lastbrk= sbrk(0);
-		printf("Memory use = %lu\n",
-		    (unsigned long) (lastbrk - &_end));
-	    }
-	    fflush(stdout);
-	}
-
-	/* Bail out if not a server, and there is nothing else to do ever. */
-	if (!serving && event == NEVER) break;
-
-	/* Wait for something to do. */
-	eventtv.tv_sec= event;
-	if (asyn_wait(&asyn, 0, event == NEVER ? nil : &eventtv) < 0) {
-	    if (errno != EINTR) {
-		report("asyn_wait()");
-		sleep(10);
-	    }
-	}
-    }
-    if (debug >= 1) printf("Nothing more to do! Bailing out...\n");
-    return 0;
-}
Index: trunk/minix/commands/dhcpd/dhcpd.h
===================================================================
--- trunk/minix/commands/dhcpd/dhcpd.h	(revision 9)
+++ 	(revision )
@@ -1,159 +1,0 @@
-/*	dhcpd.h - Dynamic Host Configuration Protocol daemon.
- *							Author: Kees J. Bot
- *								16 Dec 2000
- */
-
-#define nil ((void*)0)
-
-#include <minix/paths.h>
-
-/* Paths to files. */
-#define PATH_DHCPCONF	_PATH_DHCPCONF
-#define PATH_DHCPPID	_PATH_DHCPPID
-#define PATH_DHCPCACHE	_PATH_DHCPCACHE
-#define PATH_DHCPPOOL	_PATH_DHCPPOOL
-
-#define CLID_MAX	32	/* Maximum client ID length. */
-
-#ifndef EXTERN
-#define EXTERN	extern
-#endif
-
-EXTERN char *program;		/* This program's name. */
-extern char *configfile;	/* Configuration file. */
-extern char *poolfile;		/* Dynamic address pool. */
-EXTERN int serving;		/* True if being a DHCP server. */
-EXTERN unsigned test;		/* Test level. */
-EXTERN unsigned debug;		/* Debug level. */
-EXTERN asynchio_t asyn;		/* Bookkeeping for all async I/O. */
-
-/* BOOTP UDP ports:  (That they are different is quite stupid.) */
-EXTERN u16_t port_server;	/* Port server listens on. */
-EXTERN u16_t port_client;	/* Port client listens on. */
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-#define between(a,c,z)	(sizeof(c) <= sizeof(unsigned) ? \
-	(unsigned) (c) - (a) <= (unsigned) (z) - (a) : \
-	(unsigned long) (c) - (a) <= (unsigned long) (z) - (a))
-
-/* To treat objects as octet arrays: */
-#define B(a)		((u8_t *) (a))
-
-/* Times. */
-EXTERN time_t start, now;		/* Start and current time. */
-EXTERN time_t event;			/* Time of the next timed event. */
-
-/* Special times and periods: */
-#define NEVER	(sizeof(time_t) <= sizeof(int) ? INT_MAX : LONG_MAX)
-#define DELTA_FIRST		   4	/* Between first and second query. */
-#define DELTA_FAST		  64	/* Unbound queries this often. */
-#define DELTA_SLOW		 512	/* Bound queries are more relaxed. */
-#define N_SOLICITS		   3	/* Number of solicitations. */
-#define DELTA_SOL		   3	/* Time between solicitations. */
-#define DELTA_ADV		2048	/* Router adverts to self lifetime. */
-
-/* Buffers for packets. */
-typedef struct buf {
-	eth_hdr_t	*eth;		/* Ethernet header in payload. */
-	ip_hdr_t	*ip;		/* IP header in payload. */
-	udp_hdr_t	*udp;		/* UDP header in payload. */
-	udp_io_hdr_t	*udpio;		/* UDP I/O header in payload. */
-	dhcp_t		*dhcp;		/* DHCP data in payload. */
-	u8_t		pad[2];		/* buf[] must start at 2 mod 4. */
-					/* Payload: */
-	u8_t		buf[ETH_MAX_PACK_SIZE];
-} buf_t;
-
-#define BUF_ETH_SIZE	(ETH_MAX_PACK_SIZE)
-#define BUF_IP_SIZE	(BUF_ETH_SIZE - sizeof(eth_hdr_t))
-#define BUF_UDP_SIZE	(BUF_IP_SIZE - sizeof(ip_hdr_t) - sizeof(udp_hdr_t) \
-				+ sizeof(udp_io_hdr_t))
-
-/* Type of network device open: Ethernet, ICMP, BOOTP client, BOOTP server. */
-typedef enum { FT_CLOSED, FT_ETHERNET, FT_ICMP, FT_BOOTPC, FT_BOOTPS } fdtype_t;
-
-#define FT_ALL	FT_CLOSED	/* To close all open descriptors at once. */
-
-typedef struct fd {		/* An open descriptor. */
-	i8_t		fd;		/* Open descriptor. */
-	u8_t		fdtype;		/* Type of network open. */
-	char		device[sizeof("/dev/eth###")];	/* Device name. */
-	u8_t		n;		/* Network that owns it. */
-	buf_t		*bp;		/* Associated packet buffer. */
-	time_t		since;		/* Open since when? */
-} fd_t;
-
-/* Network state: Any IP device, Ethernet in sink mode, True Ethernet. */
-typedef enum { NT_IP, NT_SINK, NT_ETHERNET } nettype_t;
-
-typedef struct network {	/* Information on a network. */
-	u8_t		n;		/* Network number. */
-	ether_addr_t	eth;		/* Ethernet address of this net. */
-	u8_t		type;		/* What kind of net is this? */
-	i8_t		sol_ct;		/* Router solicitation count. */
-	ether_addr_t	conflict;	/* Address conflict with this one. */
-	unsigned	flags;		/* Various flags. */
-	fd_t		*fdp;		/* Current open device. */
-	struct network	*wait;		/* Wait for a resource list. */
-	ipaddr_t	ip;		/* IP address of this net. */
-	ipaddr_t	mask;		/* Associated netmask. */
-	ipaddr_t	gateway;	/* My router. */
-	ipaddr_t	server;		/* My DHCP server. */
-	const char	*hostname;	/* Optional hostname to query for. */
-	time_t		start;		/* Query or lease start time. */
-	time_t		delta;		/* Query again after delta seconds. */
-	time_t		renew;		/* Next query or go into renewal. */
-	time_t		rebind;		/* When to go into rebind. */
-	time_t		lease;		/* When our lease expires. */
-	time_t		solicit;	/* Time to do a router solicitation. */
-} network_t;
-
-/* Flags. */
-#define NF_NEGOTIATING	0x001		/* Negotiating with a DHCP server. */
-#define NF_BOUND	0x002		/* Address configured through DHCP. */
-#define NF_SERVING	0x004		/* I'm a server on this network. */
-#define NF_RELAYING	0x008		/* I'm relaying for this network. */
-#define NF_WAIT		0x010		/* Wait for a resource to free up. */
-#define NF_IRDP		0x020		/* IRDP is used on this net. */
-#define NF_CONFLICT	0x040		/* There is an address conflict. */
-#define NF_POSSESSIVE	0x080		/* Keep address if lease expires. */
-#define NF_INFORM	0x100		/* It's ok to answer DHCPINFORM. */
-
-/* Functions defined in dhcpd.c. */
-void report(const char *label);
-void fatal(const char *label);
-void *allocate(size_t size);
-int ifname2if(const char *name);
-network_t *if2net(int n);
-
-/* Devices.c */
-void get_buf(buf_t **bp);
-void put_buf(buf_t **bp);
-void give_buf(buf_t **dbp, buf_t **sbp);
-network_t *newnetwork(void);
-void closefd(fd_t *fdp);
-int opendev(network_t *np, fdtype_t fdtype, int compete);
-void closedev(network_t *np, fdtype_t fdtype);
-char *ipdev(int n);
-void set_ipconf(char *device, ipaddr_t ip, ipaddr_t mask, unsigned mtu);
-
-/* Ether.c */
-void udp2ether(buf_t *bp, network_t *np);
-int ether2udp(buf_t *bp);
-void make_arp(buf_t *bp, network_t *np);
-int is_arp_me(buf_t *bp, network_t *np);
-void icmp_solicit(buf_t *bp);
-void icmp_advert(buf_t *bp, network_t *np);
-ipaddr_t icmp_is_advert(buf_t *bp);
-
-/* Tags.c */
-#define gettag(dp, st, pd, pl)	dhcp_gettag((dp), (st), (pd), (pl))
-void settag(dhcp_t *dp, int tag, void *data, size_t len);
-char *cidr_ntoa(ipaddr_t addr, ipaddr_t mask);
-void ether2clid(u8_t *clid, ether_addr_t *eth);
-void initdhcpconf(void);
-int makedhcp(dhcp_t *dp, u8_t *class, size_t calen, u8_t *client, size_t cilen,
-				ipaddr_t ip, ipaddr_t ifip, network_t *np);
-char *dhcptypename(int type);
-void printdhcp(dhcp_t *dp);
Index: trunk/minix/commands/dhcpd/ether.c
===================================================================
--- trunk/minix/commands/dhcpd/ether.c	(revision 9)
+++ 	(revision )
@@ -1,203 +1,0 @@
-/*	ether.c - Raw Ethernet stuff
- *							Author: Kees J. Bot
- *								16 Dec 2000
- */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/asynchio.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/ether.h>
-#include <net/gen/eth_hdr.h>
-#include <net/gen/ip_hdr.h>
-#include <net/gen/icmp.h>
-#include <net/gen/icmp_hdr.h>
-#include <net/gen/oneCsum.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_hdr.h>
-#include <net/gen/dhcp.h>
-#include "arp.h"
-#include "dhcpd.h"
-
-static ether_addr_t BCAST_ETH =	{{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }};
-#define BCAST_IP	HTONL(0xFFFFFFFFUL)
-#define LOCALHOST	HTONL(0x7F000001UL)
-
-static u16_t udp_cksum(ipaddr_t src, ipaddr_t dst, udp_hdr_t *udp)
-{
-    /* Compute the checksum of an UDP packet plus data. */
-    struct udp_pseudo {
-	ipaddr_t	src, dst;
-	u8_t		zero, proto;
-	u16_t		length;
-    } pseudo;
-    size_t len;
-
-    /* Fill in the UDP pseudo header that must be prefixed to the UDP
-     * packet to compute the checksum of the whole thing.
-     */
-    pseudo.src= src;
-    pseudo.dst= dst;
-    pseudo.zero= 0;
-    pseudo.proto= IPPROTO_UDP;
-    pseudo.length= udp->uh_length;
-
-    len= ntohs(udp->uh_length);
-    if (len & 1) {
-	/* Length is odd?  Pad with a zero. */
-	B(udp)[len++]= 0;
-    }
-    return oneC_sum(oneC_sum(0, &pseudo, sizeof(pseudo)), udp, len);
-}
-
-void udp2ether(buf_t *bp, network_t *np)
-{
-    /* Transform a packet in UDP format to raw Ethernet.  Ignore the UDP
-     * addresses, always broadcast from 0.0.0.0.
-     */
-    udp_io_hdr_t udpio;
-
-    /* Save the UDP I/O header. */
-    udpio= *bp->udpio;
-
-    /* Fill in the Ethernet, IP and UDP headers. */
-    bp->eth->eh_dst= BCAST_ETH;
-    bp->eth->eh_src= np->eth;
-    bp->eth->eh_proto= HTONS(ETH_IP_PROTO);
-    bp->ip->ih_vers_ihl= 0x45;
-    bp->ip->ih_tos= 0;
-    bp->ip->ih_length= htons(sizeof(ip_hdr_t)
-			+ sizeof(udp_hdr_t) + udpio.uih_data_len);
-    bp->ip->ih_id= 0;
-    bp->ip->ih_flags_fragoff= NTOHS(0x4000);
-    bp->ip->ih_ttl= IP_MAX_TTL;
-    bp->ip->ih_proto= IPPROTO_UDP;
-    bp->ip->ih_hdr_chk= 0;
-    bp->ip->ih_src= 0;
-    bp->ip->ih_dst= BCAST_IP;
-    bp->ip->ih_hdr_chk= ~oneC_sum(0, bp->ip, sizeof(*bp->ip));
-    bp->udp->uh_src_port= udpio.uih_src_port;
-    bp->udp->uh_dst_port= udpio.uih_dst_port;
-    bp->udp->uh_length= htons(sizeof(udp_hdr_t) + udpio.uih_data_len);
-    bp->udp->uh_chksum= 0;
-    bp->udp->uh_chksum= ~udp_cksum(bp->ip->ih_src, bp->ip->ih_dst, bp->udp);
-}
-
-int ether2udp(buf_t *bp)
-{
-    /* Transform an UDP packet read from raw Ethernet to normal UDP.
-     * Return true iff the packet is indeed UDP and has no errors.
-     */
-    udp_io_hdr_t udpio;
-
-    if (bp->eth->eh_proto != HTONS(ETH_IP_PROTO)
-	|| bp->ip->ih_vers_ihl != 0x45
-	|| bp->ip->ih_proto != IPPROTO_UDP
-	|| oneC_sum(0, bp->ip, 20) != (u16_t) ~0
-	|| udp_cksum(bp->ip->ih_src, bp->ip->ih_dst, bp->udp) != (u16_t) ~0
-    ) {
-	/* Not UDP/IP or checksums bad. */
-	return 0;
-    }
-    udpio.uih_src_addr= bp->ip->ih_src;
-    udpio.uih_dst_addr= bp->ip->ih_dst;
-    udpio.uih_src_port= bp->udp->uh_src_port;
-    udpio.uih_dst_port= bp->udp->uh_dst_port;
-    udpio.uih_ip_opt_len= 0;
-    udpio.uih_data_len= ntohs(bp->udp->uh_length) - sizeof(udp_hdr_t);
-    *bp->udpio= udpio;
-    return 1;
-}
-
-void make_arp(buf_t *bp, network_t *np)
-{
-    /* Create an ARP packet to query for my IP address. */
-    arp46_t *arp= (arp46_t *) bp->eth;
-
-    memset(arp, 0, sizeof(*arp));
-    arp->dstaddr= BCAST_ETH;
-    arp->srcaddr= np->eth;
-    arp->ethtype= HTONS(ETH_ARP_PROTO);
-    arp->hdr= HTONS(ARP_ETHERNET);
-    arp->pro= HTONS(ETH_IP_PROTO);
-    arp->hln= 6;
-    arp->pln= 4;
-    arp->op= HTONS(ARP_REQUEST);
-    arp->sha= np->eth;
-    memcpy(arp->spa, &np->ip, sizeof(np->ip));
-    memcpy(arp->tpa, &np->ip, sizeof(np->ip));
-}
-
-int is_arp_me(buf_t *bp, network_t *np)
-{
-    /* True iff an ARP packet is a reply from someone else with an address I
-     * thought was mine.  (That's like, bad.)
-     */
-    arp46_t *arp= (arp46_t *) bp->eth;
-
-    if (arp->ethtype == HTONS(ETH_ARP_PROTO)
-	&& arp->hdr == HTONS(ARP_ETHERNET)
-	&& arp->pro == HTONS(ETH_IP_PROTO)
-	&& arp->op == HTONS(ARP_REPLY)
-	&& memcmp(&arp->spa, &np->ip, sizeof(np->ip)) == 0
-	&& memcmp(&arp->sha, &np->eth, sizeof(np->eth)) != 0
-    ) {
-	np->conflict= arp->sha;
-	return 1;
-    }
-    return 0;
-}
-
-void icmp_solicit(buf_t *bp)
-{
-    /* Fill in a router solicitation ICMP packet. */
-    icmp_hdr_t *icmp= (icmp_hdr_t *) (bp->ip + 1);
-
-    bp->ip->ih_vers_ihl= 0x45;
-    bp->ip->ih_dst= BCAST_IP;
-
-    icmp->ih_type= ICMP_TYPE_ROUTE_SOL;
-    icmp->ih_code= 0;
-    icmp->ih_hun.ihh_unused= 0;
-    icmp->ih_chksum= 0;
-    icmp->ih_chksum= ~oneC_sum(0, icmp, 8);
-}
-
-void icmp_advert(buf_t *bp, network_t *np)
-{
-    /* Fill in a router advert to be sent to my own interface. */
-    icmp_hdr_t *icmp= (icmp_hdr_t *) (bp->ip + 1);
-
-    bp->ip->ih_vers_ihl= 0x45;
-    bp->ip->ih_dst= LOCALHOST;
-
-    icmp->ih_type= ICMP_TYPE_ROUTER_ADVER;
-    icmp->ih_code= 0;
-    icmp->ih_hun.ihh_ram.iram_na= 1;
-    icmp->ih_hun.ihh_ram.iram_aes= 2;
-    icmp->ih_hun.ihh_ram.iram_lt= htons(DELTA_ADV);
-    ((u32_t *) icmp->ih_dun.uhd_data)[0] = np->gateway;
-    ((u32_t *) icmp->ih_dun.uhd_data)[1] = HTONL((u32_t) -9999);
-    icmp->ih_chksum= 0;
-    icmp->ih_chksum= ~oneC_sum(0, icmp, 16);
-}
-
-ipaddr_t icmp_is_advert(buf_t *bp)
-{
-    /* Check if an IP packet is a router advertisement, and if it's genuine,
-     * i.e. the sender is mentioned in the packet.
-     */
-    icmp_hdr_t *icmp= (icmp_hdr_t *) (bp->ip + 1);
-    int i;
-
-    if (icmp->ih_type == ICMP_TYPE_ROUTER_ADVER) {
-	for (i= 0; i < icmp->ih_hun.ihh_ram.iram_na; i++) {
-	    if (((u32_t *) icmp->ih_dun.uhd_data)[2*i] == bp->ip->ih_src) {
-		/* It's a router! */
-		return bp->ip->ih_src;
-	    }
-	}
-    }
-    return 0;
-}
Index: trunk/minix/commands/dhcpd/tags.c
===================================================================
--- trunk/minix/commands/dhcpd/tags.c	(revision 9)
+++ 	(revision )
@@ -1,924 +1,0 @@
-/*	tags.c - Obtain DHCP tags from the config file
- *							Author: Kees J. Bot
- *								16 Dec 2000
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <signal.h>
-#include <string.h>
-#include <time.h>
-#include <limits.h>
-#include <configfile.h>
-#include <sys/ioctl.h>
-#include <sys/asynchio.h>
-#include <net/hton.h>
-#include <net/gen/socket.h>
-#include <net/gen/netdb.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/ether.h>
-#include <net/gen/if_ether.h>
-#include <net/gen/eth_hdr.h>
-#include <net/gen/ip_hdr.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_hdr.h>
-#include <net/gen/dhcp.h>
-#include "dhcpd.h"
-
-#define doff(field)		offsetof(dhcp_t, field)
-
-void settag(dhcp_t *dp, int tag, void *data, size_t len)
-{
-    if (!dhcp_settag(dp, tag, data, len)) {
-	/* Oops, it didn't fit?  Is this really Minix??? */
-	fprintf(stderr,
-	    "%s: DHCP packet too big, please trim the configuration\n",
-	    program);
-	exit(1);
-    }
-}
-
-static int name2ip(ipaddr_t *pip, const char *name, ipaddr_t ifip)
-{
-    /* Translate a name to an IP address, preferably from the hosts file,
-     * but also from the DNS if being a server.  Prefer the address closest
-     * to the interface with IP address 'ifip' if there are choices..
-     */
-    extern struct hostent *_gethostent(void);	/* File reading versions. */
-    extern void _endhostent(void);
-    struct hostent *he;
-    size_t len= strlen(name);
-    u32_t d, distance= -1;
-    ipaddr_t ip;
-    int i;
-    char *hn;
-
-    /* Already an IP address? */
-    if (inet_aton(name, pip)) return 1;
-
-    /* In the hosts file? */
-    while ((he= _gethostent()) != nil) {
-	hn= he->h_name;
-	i= -1;
-	do {
-	    if (strncasecmp(name, hn, len) == 0
-		&& (hn[len] == 0 || hn[len] == '.')
-	    ) {
-		memcpy(&ip, he->h_addr, sizeof(ip));
-		d= ntohl(ip) ^ ntohl(ifip);
-		if (d < distance) {
-		    *pip= ip;
-		    distance= d;
-		}
-		break;
-	    }
-	} while ((hn= he->h_aliases[++i]) != nil);
-    }
-    _endhostent();
-    if (distance < -1) return 1;
-
-    /* Nothing?  Try the real DNS if being a server. */
-    if (serving) {
-	if ((he= gethostbyname(name)) != nil && he->h_addrtype == AF_INET) {
-	    /* Select the address closest to 'ifip'. */
-	    for (i= 0; he->h_addr_list[i] != nil; i++) {
-		memcpy(&ip, he->h_addr_list[i], sizeof(ip));
-		d= ntohl(ip) ^ ntohl(ifip);
-		if (d < distance) {
-		    *pip= ip;
-		    distance= d;
-		}
-	    }
-	    return 1;
-	}
-    }
-    return 0;
-}
-
-static char *ip2name(ipaddr_t ip)
-{
-    /* Translate an IP address to a name, etc, etc. */
-    extern struct hostent *_gethostent(void);	/* File reading versions. */
-    extern void _endhostent(void);
-    struct hostent *he;
-
-    /* In the hosts file? */
-    while ((he= _gethostent()) != nil) {
-	if (memcmp(he->h_addr, &ip, sizeof(ip)) == 0) break;
-    }
-    _endhostent();
-
-    /* Nothing?  Try the real DNS if being a server. */
-    if (he == nil && serving) {
-	he= gethostbyaddr((char *) &ip, sizeof(ip), AF_INET);
-    }
-    return he != nil ? he->h_name : nil;
-}
-
-static int cidr_aton(const char *cidr, ipaddr_t *addr, ipaddr_t *mask)
-{
-    char *slash, *check;
-    ipaddr_t a;
-    int ok;
-    unsigned long len;
-
-    if ((slash= strchr(cidr, '/')) == nil) return 0;
-
-    *slash++= 0;
-    ok= inet_aton(cidr, &a);
-
-    len= strtoul(slash, &check, 10);
-    if (check == slash || *check != 0 || len > 32) ok= 0;
-
-    *--slash= '/';
-    if (!ok) return 0;
-    *addr= a;
-    *mask= htonl(len == 0 ? 0 : (0xFFFFFFFFUL << (32-len)) & 0xFFFFFFFFUL);
-    return 1;
-}
-
-char *cidr_ntoa(ipaddr_t addr, ipaddr_t mask)
-{
-    ipaddr_t testmask= 0xFFFFFFFFUL;
-    int n;
-    static char result[sizeof("255.255.255.255/255.255.255.255")];
-
-    for (n= 32; n >= 0; n--) {
-	if (mask == htonl(testmask)) break;
-	testmask= (testmask << 1) & 0xFFFFFFFFUL;
-    }
-
-    sprintf(result, "%s/%-2d", inet_ntoa(addr), n);
-    if (n == -1) strcpy(strchr(result, '/')+1, inet_ntoa(mask));
-    return result;
-}
-
-static size_t ascii2octet(u8_t *b, size_t size, const char *a)
-{
-    /* Convert a series of hex digit pairs to an octet (binary) array at
-     * 'b' with length 'size'.  Return the number of octets in 'a' or
-     * -1 on error.
-     */
-    size_t len;
-    int n, c;
-
-    len= 0;
-    n= 0;
-    while ((c= *a++) != 0) {
-	if (between('0', c, '9')) c= (c - '0') + 0x0;
-	else
-	if (between('a', c, 'f')) c= (c - 'a') + 0xa;
-	else
-	if (between('A', c, 'F')) c= (c - 'A') + 0xA;
-	else {
-	    return -1;
-	}
-
-	if (n == 0) {
-	    if (len < size) b[len] = c << 4;
-	} else {
-	    if (len < size) b[len] |= c;
-	    len++;
-	}
-	n ^= 1;
-    }
-    return n == 0 ? len : -1;
-}
-
-void ether2clid(u8_t *clid, ether_addr_t *eth)
-{
-    /* Convert an Ethernet address to the default client ID form. */
-    clid[0]= DHCP_HTYPE_ETH;
-    memcpy(clid+1, eth, DHCP_HLEN_ETH);
-}
-
-static size_t ascii2clid(u8_t *clid, const char *a)
-{
-    /* Convert an ethernet address, or a series of hex digits to a client ID.
-     * Return its length if ok, otherwise -1.
-     */
-    size_t len;
-    ether_addr_t *eth;
-
-    if ((eth= ether_aton(a)) != nil) {
-	ether2clid(clid, eth);
-	len= 1+DHCP_HLEN_ETH;
-    } else {
-	len= ascii2octet(clid, CLID_MAX, a);
-    }
-    return len;
-}
-
-static config_t *dhcpconf;		/* In-core DHCP configuration. */
-
-/* DHCP tag types. */
-typedef enum { TT_ASCII, TT_BOOLEAN, TT_IP, TT_NUMBER, TT_OCTET } tagtype_t;
-
-/* DHCP/BOOTP tag definitions. */
-typedef struct tagdef {
-	u8_t		tag;		/* Tag number. */
-	u8_t		type;		/* Type and flags. */
-	u8_t		gran;		/* Granularity. */
-	u8_t		max;		/* Maximum number of arguments. */
-	const char	*name;		/* Defined name. */
-} tagdef_t;
-
-#define TF_TYPE		0x07		/* To mask out the type. */
-#define TF_STATIC	0x08		/* "Static", i.e. a struct field. */
-#define TF_RO		0x10		/* Read-only, user can't set. */
-
-/* List of static DHCP fields.  The tag field is misused here as an offset
- * into the DHCP structure.
- */
-static tagdef_t statictag[] = {
-    { doff(op),     TT_NUMBER|TF_STATIC|TF_RO,	1,   1,	"op"		},
-    { doff(htype),  TT_NUMBER|TF_STATIC|TF_RO,	1,   1,	"htype"		},
-    { doff(hlen),   TT_NUMBER|TF_STATIC|TF_RO,	1,   1,	"hlen"		},
-    { doff(hops),   TT_NUMBER|TF_STATIC|TF_RO,	1,   1,	"hops"		},
-    { doff(xid),    TT_NUMBER|TF_STATIC|TF_RO,	4,   1,	"xid"		},
-    { doff(secs),   TT_NUMBER|TF_STATIC|TF_RO,	2,   1,	"secs"		},
-    { doff(flags),  TT_NUMBER|TF_STATIC|TF_RO,	2,   1,	"flags"		},
-    { doff(ciaddr), TT_IP|TF_STATIC|TF_RO,	1,   1,	"ciaddr"	},
-    { doff(yiaddr), TT_IP|TF_STATIC|TF_RO,	1,   1,	"yiaddr"	},
-    { doff(siaddr), TT_IP|TF_STATIC,		1,   1,	"siaddr"	},
-    { doff(giaddr), TT_IP|TF_STATIC|TF_RO,	1,   1,	"giaddr"	},
-    { doff(chaddr), TT_OCTET|TF_STATIC|TF_RO,	1,  16,	"chaddr"	},
-    { doff(sname),  TT_ASCII|TF_STATIC,		1,  64,	"sname"		},
-    { doff(file),   TT_ASCII|TF_STATIC,		1, 128,	"file"		},
-};
-#define N_STATIC	arraysize(statictag)
-
-static tagdef_t alltagdef[N_STATIC + 254];	/* List of tag definitions. */
-#define tagdef	(alltagdef+N_STATIC-1)		/* Just the optional ones. */
-
-#define tagdefined(tp)		((tp)->name != nil)
-
-static void inittagdef(void)
-{
-    /* Initialize the tag definitions from the "tag" commands in the config
-     * file.
-     */
-    int t;
-    tagdef_t *tp;
-    static tagdef_t predef[] = {
-	{ DHCP_TAG_NETMASK,	TT_IP,	   1,	  1,	"netmask"	},
-	{ DHCP_TAG_GATEWAY,	TT_IP,	   1,	255,	"gateway"	},
-	{ DHCP_TAG_DNS,		TT_IP,	   1,	255,	"DNSserver"	},
-    };
-    static char *typenames[] = { "ascii", "boolean", "ip", "number", "octet" };
-    config_t *cfg;
-    static u8_t rotags[] = {
-	DHCP_TAG_REQIP, DHCP_TAG_OVERLOAD, DHCP_TAG_TYPE, DHCP_TAG_SERVERID,
-	DHCP_TAG_REQPAR, DHCP_TAG_MESSAGE, DHCP_TAG_MAXDHCP
-    };
-
-    for (t= 1; t <= 254; t++) {
-	tp= &tagdef[t];
-	tp->tag= t;
-	tp->type= TT_OCTET;
-	tp->name= nil;
-    }
-
-    /* Set the static and "all Minix needs" tags. */
-    memcpy(alltagdef, statictag, sizeof(statictag));
-    for (tp= predef; tp < arraylimit(predef); tp++) tagdef[tp->tag] = *tp;
-
-    /* Search for tag definitions in the config file. */
-    for (cfg= dhcpconf; cfg != nil; cfg= cfg->next) {
-	config_t *cmd= cfg->list;
-
-	if (strcasecmp(cmd->word, "tag") == 0) {
-	    if (config_length(cmd) == 6
-		&& (cmd->next->flags & CFG_DULONG)
-		&& config_isatom(cmd->next->next)
-		&& config_isatom(cmd->next->next->next)
-		&& (cmd->next->next->next->next->flags & CFG_DULONG)
-		&& (cmd->next->next->next->next->next->flags & CFG_DULONG)
-	    ) {
-		unsigned long tag, gran, max;
-		const char *name, *typename;
-		unsigned type;
-
-		tag= strtoul(cmd->next->word, nil, 10);
-		name= cmd->next->next->word;
-		typename= cmd->next->next->next->word;
-		gran= strtoul(cmd->next->next->next->next->word, nil, 10);
-		max= strtoul(cmd->next->next->next->next->next->word, nil, 10);
-
-		for (type= 0; type < arraysize(typenames); type++) {
-		    if (strcasecmp(typename, typenames[type]) == 0) break;
-		}
-
-		if (!(1 <= tag && tag <= 254)
-		    || !(type < arraysize(typenames))
-		    || !((type == TT_NUMBER
-			    && (gran == 1 || gran == 2 || gran == 4))
-			|| (type != TT_NUMBER && 1 <= gran && gran <= 16))
-		    || !(max <= 255)
-		) {
-		    fprintf(stderr,
-			"\"%s\", line %u: Tag definition is incorrect\n",
-			cmd->file, cmd->line);
-		    exit(1);
-		}
-
-		tp= &tagdef[(int)tag];
-		tp->type= type;
-		tp->name= name;
-		tp->gran= gran;
-		tp->max= max;
-	    } else {
-		fprintf(stderr,
-	    "\"%s\", line %u: Usage: tag number name type granularity max\n",
-		    cmd->file, cmd->line);
-		exit(1);
-	    }
-	}
-    }
-
-    /* Many DHCP tags are not for the user to play with. */
-    for (t= 0; t < arraysize(rotags); t++) tagdef[rotags[t]].type |= TF_RO;
-}
-
-static tagdef_t *tagdefbyname(const char *name)
-{
-    /* Find a tag definition by the name of the tag.  Return null if not
-     * defined.
-     */
-    tagdef_t *tp;
-
-    for (tp= alltagdef; tp < arraylimit(alltagdef); tp++) {
-	if (tagdefined(tp) && strcasecmp(tp->name, name) == 0) return tp;
-    }
-    return nil;
-}
-
-void initdhcpconf(void)
-{
-    /* Read/refresh configuration from the DHCP configuration file. */
-    dhcpconf= config_read(configfile, 0, dhcpconf);
-    if (config_renewed(dhcpconf)) inittagdef();
-}
-
-static void configtag(dhcp_t *dp, config_t *cmd, ipaddr_t ifip)
-{
-    /* Add a tag to a DHCP packet from the config file. */
-    tagdef_t *tp;
-    u8_t data[260], *d;
-    size_t i;
-    int delete= 0;
-
-    if (strcasecmp(cmd->word, "no") == 0) {
-	if (config_length(cmd) != 2 || !config_isatom(cmd->next)) {
-	    fprintf(stderr, "\"%s\", line %u: Usage: no tag-name\n",
-		cmd->file, cmd->line);
-	    exit(1);
-	}
-	cmd= cmd->next;
-	delete= 1;
-    }
-
-    if ((tp= tagdefbyname(cmd->word)) == nil) {
-	fprintf(stderr, "\"%s\", line %u: Unknown tag '%s'\n",
-	    cmd->file, cmd->line, cmd->word);
-	exit(1);
-    }
-
-    if (tp->type & TF_RO) {
-	fprintf(stderr, "\"%s\", line %u: Tag '%s' can't be configured\n",
-	    cmd->file, cmd->line, cmd->word);
-	exit(1);
-    }
-
-    i= 0;
-    d= data;
-    if (!delete) {
-	config_t *arg= cmd->next;
-	do {
-	    switch (tp->type & TF_TYPE) {
-	    case TT_ASCII: {
-		if (arg == nil || !config_isatom(arg) || arg->next != nil) {
-		    fprintf(stderr, "\"%s\", line %u: Usage: %s string\n",
-			cmd->file, cmd->line, cmd->word);
-		    exit(1);
-		}
-		strncpy((char *) data, arg->word, sizeof(data));
-		d += i = strnlen((char *) data, sizeof(data));
-		break;}
-	    case TT_BOOLEAN: {
-		if (arg == nil || !config_isatom(arg)
-		    || !(strcasecmp(arg->word, "false") == 0
-			    || strcasecmp(arg->word, "true") == 0)
-		) {
-		    fprintf(stderr,
-			"\"%s\", line %u: Usage: %s false|true ...\n",
-			cmd->file, cmd->line, cmd->word);
-		    exit(1);
-		}
-		if (d < arraylimit(data)) {
-		    *d++ = (arg->word[0] != 'f' && arg->word[0] != 'F');
-		}
-		i++;
-		break;}
-	    case TT_IP: {
-		ipaddr_t ip;
-		unsigned long len;
-		char *end;
-
-		if (arg == nil || !config_isatom(arg)) {
-		    fprintf(stderr, "\"%s\", line %u: Usage: %s host ...\n",
-			cmd->file, cmd->line, cmd->word);
-		    exit(1);
-		}
-		if (arg->word[0] == '/'
-			&& between(1, len= strtoul(arg->word+1, &end, 10), 31)
-			&& *end == 0
-		) {
-		    ip= htonl((0xFFFFFFFFUL << (32-len)) & 0xFFFFFFFFUL);
-		} else
-		if (!name2ip(&ip, arg->word, ifip)) {
-		    fprintf(stderr,
-		    "\"%s\", line %u: Can't translate %s to an IP address\n",
-			arg->file, arg->line, arg->word);
-		    exit(1);
-		}
-		if (d <= arraylimit(data) - sizeof(ip)) {
-		    memcpy(d, &ip, sizeof(ip));
-		    d += sizeof(ip);
-		}
-		i++;
-		break;}
-	    case TT_NUMBER: {
-		unsigned long n;
-		int g;
-
-		if (arg == nil || !(arg->flags & CFG_CLONG)) {
-		    fprintf(stderr, "\"%s\", line %u: Usage: %s number ...\n",
-			cmd->file, cmd->line, cmd->word);
-		    exit(1);
-		}
-		n= strtoul(arg->word, nil, 0);
-		g= tp->gran;
-		do {
-		    if (d <= arraylimit(data)) *d++ = (n >> (--g * 8)) & 0xFF;
-		} while (g != 0);
-		i++;
-		break;}
-	    case TT_OCTET: {
-		if (arg == nil || !config_isatom(arg) || arg->next != nil) {
-		    fprintf(stderr, "\"%s\", line %u: Usage: %s hexdigits\n",
-			cmd->file, cmd->line, cmd->word);
-		    exit(1);
-		}
-		i= ascii2octet(data, sizeof(data), arg->word);
-		if (i == -1) {
-		    fprintf(stderr,
-			"\"%s\", line %u: %s: Bad hexdigit string\n",
-			arg->file, arg->line, arg->word);
-		    exit(1);
-		}
-		d= data + i;
-		break;}
-	    }
-	} while ((arg= arg->next) != nil);
-
-	if (d > data + 255) {
-	    fprintf(stderr, "\"%s\", line %u: Tag value is way too big\n",
-		cmd->file, cmd->line);
-	    exit(1);
-	}
-	if ((tp->type & TF_TYPE) != TT_NUMBER && (i % tp->gran) != 0) {
-	    fprintf(stderr,
-		"\"%s\", line %u: Expected a multiple of %d initializers\n",
-		cmd->file, cmd->line, tp->gran);
-	    exit(1);
-	}
-	if (tp->max != 0 && i > tp->max) {
-	    fprintf(stderr,
-		"\"%s\", line %u: Got %d initializers, can have only %d\n",
-		cmd->file, cmd->line, (int) i, tp->max);
-	    exit(1);
-	}
-    }
-    if (tp->type & TF_STATIC) {
-	size_t len= tp->gran * tp->max;
-	if ((tp->type & TF_TYPE) == TT_IP) len *= sizeof(ipaddr_t);
-	memset(B(dp) + tp->tag, 0, len);
-	memcpy(B(dp) + tp->tag, data, (d - data));
-    } else {
-	settag(dp, tp->tag, data, (d - data));
-    }
-}
-
-int makedhcp(dhcp_t *dp, u8_t *class, size_t calen, u8_t *client, size_t cilen,
-				ipaddr_t ip, ipaddr_t ifip, network_t *np)
-{
-    /* Fill in a DHCP packet at 'dp' for the host identified by the
-     * (class, client, ip) combination.  Makedhcp is normally called twice,
-     * once to find the IP address (so ip == 0) and once again to find all
-     * data that goes with that IP address (ip != 0).  On the first call the
-     * return value of this function should be ignored and only 'yiaddr'
-     * checked and used as 'ip' on the next pass.  True is returned iff there
-     * is information for the client on the network at interface address
-     * 'ifip', by checking if the 'ip' and 'ifip' are on the same network.
-     * If np is nonnull then we are working for one of our own interfaces, so
-     * options can be set and adjourning interfaces can be programmed.
-     */
-    config_t *todo[16];
-    size_t ntodo= 0;
-    ipaddr_t hip, mask;
-    u8_t *pmask;
-    char *hostname;
-    u32_t distance= -1;
-
-    initdhcpconf();
-
-    /* Start creating a packet. */
-    dhcp_init(dp);
-    dp->op= DHCP_BOOTREPLY;
-
-    /* The initial TODO list is the whole DHCP config. */
-    todo[ntodo++]= dhcpconf;
-
-    while (ntodo > 0) {
-	config_t *cmd, *follow;
-
-	if (todo[ntodo-1] == nil) { ntodo--; continue; }
-	cmd= todo[ntodo-1]->list;
-	todo[ntodo-1]= todo[ntodo-1]->next;
-
-	follow= nil;	/* Macro or list to follow next? */
-
-	if (strcasecmp(cmd->word, "client") == 0) {
-	    u8_t cfgid[CLID_MAX];
-	    size_t cfglen;
-	    char *name;
-	    int ifno;
-	    u32_t d;
-
-	    if (between(3, config_length(cmd), 5)
-		&& config_isatom(cmd->next)
-		&& (cfglen= ascii2clid(cfgid, cmd->next->word)) != -1
-		&& config_isatom(cmd->next->next)
-		&& (((ifno= ifname2if(cmd->next->next->word)) == -1
-			&& config_length(cmd) <= 4)
-		    || ((ifno= ifname2if(cmd->next->next->word)) != -1
-			&& config_length(cmd) >= 4
-			&& config_isatom(cmd->next->next->next)))
-	    ) {
-		if (cilen == cfglen && memcmp(client, cfgid, cilen) == 0
-		    && (ifno == -1 || np == nil || ifno == np->n)
-		) {
-		    config_t *atname= cmd->next->next;
-		    if (ifno != -1) atname= atname->next;
-		    name= atname->word;
-
-		    if (name2ip(&hip, name, ifip) && (ip == 0 || ip == hip)) {
-			d= ntohl(hip) ^ ntohl(ifip);
-			if (d < distance) {
-			    dp->yiaddr= hip;
-			    follow= atname->next;
-			    distance= d;
-			}
-		    }
-		}
-	    } else {
-		fprintf(stderr,
-	    "\"%s\", line %u: Usage: client ID [ip#] host [macro|{params}]\n",
-		    cmd->file, cmd->line);
-		exit(1);
-	    }
-	} else
-	if (strcasecmp(cmd->word, "class") == 0) {
-	    config_t *clist;
-	    int match;
-
-	    match= 0;
-	    for (clist= cmd->next; clist != nil
-				&& clist->next != nil
-				&& config_isatom(clist); clist= clist->next) {
-		if (calen > 0
-		    && strncmp(clist->word, (char *) class, calen) == 0
-		) {
-		    match= 1;
-		}
-	    }
-	    if (clist == cmd->next || clist->next != nil) {
-		fprintf(stderr,
-		"\"%s\", line %u: Usage: class class-name ... macro|{params}\n",
-		    cmd->file, cmd->line);
-	    }
-	    if (match) follow= clist;
-	} else
-	if (strcasecmp(cmd->word, "host") == 0) {
-	    if (config_length(cmd) == 3
-		&& config_isatom(cmd->next)
-	    ) {
-		if (ip != 0) {
-		    if (cidr_aton(cmd->next->word, &hip, &mask)) {
-			if (((hip ^ ip) & mask) == 0) {
-			    if (!gettag(dp, DHCP_TAG_NETMASK, nil, nil)) {
-				settag(dp, DHCP_TAG_NETMASK,
-						&mask, sizeof(mask));
-			    }
-			    dp->yiaddr= ip;
-			    follow= cmd->next->next;
-			}
-		    } else
-		    if (name2ip(&hip, cmd->next->word, ifip)) {
-			if (hip == ip) {
-			    dp->yiaddr= ip;
-			    follow= cmd->next->next;
-			}
-		    }
-		}
-	    } else {
-		fprintf(stderr,
-		"\"%s\", line %u: Usage: host host-spec macro|{params}\n",
-		    cmd->file, cmd->line);
-		exit(1);
-	    }
-	} else
-	if (strcasecmp(cmd->word, "interface") == 0) {
-	    if (between(3, config_length(cmd), 4)
-		&& config_isatom(cmd->next)
-		&& config_isatom(cmd->next->next)
-	    ) {
-		network_t *ifnp;
-
-		if (np != nil) {
-		    if ((ifnp= if2net(ifname2if(cmd->next->word))) == nil) {
-			fprintf(stderr,
-			    "\"%s\", line %u: Can't find interface %s\n",
-			    cmd->next->file, cmd->next->line, cmd->next->word);
-			exit(1);
-		    }
-		    if (!name2ip(&hip, cmd->next->next->word, 0)) {
-			fprintf(stderr,
-			    "\"%s\", line %u: Can't find IP address of %s\n",
-			    cmd->next->next->file, cmd->next->next->line,
-			    cmd->next->next->word);
-			exit(1);
-		    }
-		    ifnp->ip= hip;
-		    if (ifnp == np) {
-			dp->yiaddr= hip;
-			follow= cmd->next->next->next;
-		    }
-		}
-	    } else {
-		fprintf(stderr,
-		"\"%s\", line %u: Usage: interface ip# host%s\n",
-		    cmd->file, cmd->line, ntodo==1 ? " [macro|{params}]" : "");
-		exit(1);
-	    }
-	} else
-	if (strcasecmp(cmd->word, "macro") == 0) {
-	    if (config_length(cmd) == 2 && config_isatom(cmd->next)) {
-		follow= cmd->next;
-	    } else
-	    if (ntodo > 1) {
-		fprintf(stderr, "\"%s\", line %u: Usage: macro macro-name\n",
-		    cmd->file, cmd->line);
-		exit(1);
-	    }
-	} else
-	if (strcasecmp(cmd->word, "tag") == 0) {
-	    if (ntodo > 1) {
-		fprintf(stderr,
-		    "\"%s\", line %u: A %s can't be defined here\n",
-		    cmd->file, cmd->line, cmd->word);
-		exit(1);
-	    }
-	} else
-	if (strcasecmp(cmd->word, "option") == 0) {
-	    int ifno;
-	    network_t *ifnp;
-	    config_t *opt;
-
-	    if ((opt= cmd->next) != nil
-		&& config_isatom(opt)
-		&& (ifno= ifname2if(opt->word)) != -1
-	    ) {
-		if ((ifnp= if2net(ifno)) == nil) {
-		    fprintf(stderr,
-			"\"%s\", line %u: Interface %s is not enabled\n",
-			opt->file, opt->line, opt->word);
-		    exit(1);
-		}
-		opt= opt->next;
-	    } else {
-		ifnp= np;
-	    }
-
-	    if (between(1, config_length(opt), 2)
-		&& config_isatom(opt)
-		&& strcasecmp(opt->word, "server") == 0
-		&& (opt->next == nil
-		    || strcasecmp(opt->next->word, "inform") == 0)
-	    ) {
-		if (np != nil) {
-		    ifnp->flags |= NF_SERVING;
-		    if (opt->next != nil) ifnp->flags |= NF_INFORM;
-		}
-	    } else
-	    if (config_length(opt) == 2
-		&& config_isatom(opt)
-		&& strcasecmp(opt->word, "relay") == 0
-		&& config_isatom(opt->next)
-	    ) {
-		if (np != nil) {
-		    if (!name2ip(&hip, opt->next->word, ifip)) {
-			fprintf(stderr,
-			    "\"%s\", line %u: Can't find IP address of %s\n",
-			    opt->next->file, opt->next->line,
-			    opt->next->word);
-			exit(1);
-		    }
-		    ifnp->flags |= NF_RELAYING;
-		    ifnp->server= hip;
-		}
-	    } else
-	    if (config_length(opt) == 1
-		&& config_isatom(opt)
-		&& strcasecmp(opt->word, "possessive") == 0
-	    ) {
-		if (np != nil) ifnp->flags |= NF_POSSESSIVE;
-	    } else
-	    if (config_length(opt) == 2
-		&& config_isatom(opt)
-		&& strcasecmp(opt->word, "hostname") == 0
-		&& config_isatom(opt->next)
-	    ) {
-		if (np != nil) np->hostname= opt->next->word;
-	    } else {
-		fprintf(stderr, "\"%s\", line %u: Unknown option\n",
-		    cmd->file, cmd->line);
-		exit(1);
-	    }
-	} else {
-	    /* Must be an actual data carrying tag. */
-	    configtag(dp, cmd, ifip);
-	}
-
-	if (follow != nil) {
-	    /* A client/class/host entry selects a macro or list that must
-	     * be followed next.
-	     */
-	    config_t *macro;
-
-	    if (config_isatom(follow)) {	/* Macro name */
-		config_t *cfg;
-
-		for (cfg= dhcpconf; cfg != nil; cfg= cfg->next) {
-		    macro= cfg->list;
-
-		    if (strcasecmp(macro->word, "macro") == 0) {
-			if (config_length(macro) == 3
-			    && config_isatom(macro->next)
-			    && config_issub(macro->next->next)
-			) {
-			    if (strcasecmp(macro->next->word, follow->word) == 0
-			    ) {
-				break;
-			    }
-			} else {
-			    fprintf(stderr,
-			"\"%s\", line %u: Usage: macro macro-name {params}\n",
-				macro->file, macro->line);
-			}
-		    }
-		}
-		follow= cfg == nil ? nil : macro->next->next->list;
-	    } else {
-		/* Simply a list of more tags and stuff. */
-		follow= follow->list;
-	    }
-
-	    if (ntodo == arraysize(todo)) {
-		fprintf(stderr, "\"%s\", line %u: Nesting is too deep\n",
-		    follow->file, follow->line);
-		exit(1);
-	    }
-	    todo[ntodo++]= follow;
-	}
-    }
-
-    /* Check if the IP and netmask are OK for the interface. */
-    if (!gettag(dp, DHCP_TAG_NETMASK, &pmask, nil)) return 0;
-    memcpy(&mask, pmask, sizeof(mask));
-    if (((ip ^ ifip) & mask) != 0) return 0;
-
-    /* Fill in the hostname and/or domain. */
-    if ((hostname= ip2name(ip)) != nil) {
-	char *domain;
-
-	if ((domain= strchr(hostname, '.')) != nil) *domain++ = 0;
-
-	if (!gettag(dp, DHCP_TAG_HOSTNAME, nil, nil)) {
-	    settag(dp, DHCP_TAG_HOSTNAME, hostname, strlen(hostname));
-	}
-
-	if (domain != nil && !gettag(dp, DHCP_TAG_DOMAIN, nil, nil)) {
-	    settag(dp, DHCP_TAG_DOMAIN, domain, strlen(domain));
-	}
-    }
-
-    return 1;
-}
-
-static char *dhcpopname(int op)
-{
-    static char *onames[] = { "??\?", "REQUEST", "REPLY" };
-    return onames[op < arraysize(onames) ? op : 0];
-}
-
-char *dhcptypename(int type)
-{
-    static char *tnames[] = {
-	"??\?", "DISCOVER", "OFFER", "REQUEST", "DECLINE",
-	"ACK", "NAK", "RELEASE", "INFORM"
-    };
-    return tnames[type < arraysize(tnames) ? type : 0];
-}
-
-void printdhcp(dhcp_t *dp)
-{
-    /* Print the contents of a DHCP packet, usually for debug purposes. */
-    tagdef_t *tp;
-    u8_t *data, *ovld;
-    size_t i, len;
-
-    for (tp= alltagdef; tp < arraylimit(alltagdef); tp++) {
-	if (tp->type & TF_STATIC) {
-	    data= B(dp) + tp->tag;
-	    len= tp->gran * tp->max;
-	    if ((tp->type & TF_TYPE) == TT_IP) len *= sizeof(ipaddr_t);
-	    if (tp->tag == doff(chaddr)) len= dp->hlen;
-
-	    /* Don't show uninteresting stuff. */
-	    if (tp->tag == doff(htype) && dp->htype == DHCP_HTYPE_ETH) continue;
-
-	    if (tp->tag == doff(hlen) && dp->hlen == DHCP_HLEN_ETH) continue;
-
-	    if ((tp->tag == doff(file) || tp->tag == doff(sname))
-		&& gettag(dp, DHCP_TAG_OVERLOAD, &ovld, nil)
-		&& (ovld[0] & (tp->tag == doff(file) ? 1 : 2))
-	    ) {
-		continue;
-	    }
-	    for (i= 0; i < len && data[i] == 0; i++) {}
-	    if (i == len) continue;
-	} else {
-	    if (!gettag(dp, tp->tag, &data, &len)) continue;
-	}
-
-	if (tagdefined(tp)) {
-	    printf("\t%s =", tp->name);
-	} else {
-	    printf("\tT%d =", tp->tag);
-	}
-
-	i= 0;
-	while (i < len) {
-	    switch (tp->type & TF_TYPE) {
-	    case TT_ASCII: {
-		printf(" \"%.*s\"", (int) len, data);
-		i= len;
-		break;}
-	    case TT_BOOLEAN: {
-		printf(data[i++] == 0 ? " false" : " true");
-		break;}
-	    case TT_IP: {
-		ipaddr_t ip;
-		memcpy(&ip, data+i, sizeof(ip));
-		printf(" %s", inet_ntoa(ip));
-		i += sizeof(ip);
-		break;}
-	    case TT_NUMBER: {
-		u32_t n= 0;
-		int g= tp->gran;
-
-		do n= (n << 8) | data[i++]; while (--g != 0);
-		printf(" %lu", (unsigned long) n);
-		if ((tp->type & TF_STATIC) && tp->tag == doff(op)) {
-		    printf(" (%s)", dhcpopname(n));
-		}
-		if (!(tp->type & TF_STATIC) && tp->tag == DHCP_TAG_TYPE) {
-		    printf(" (%s)", dhcptypename(n));
-		}
-		break;}
-	    case TT_OCTET: {
-		if (i == 0) fputc(' ', stdout);
-		printf("%02X", data[i++]);
-		break;}
-	    }
-	}
-	fputc('\n', stdout);
-    }
-}
Index: trunk/minix/commands/dis88/Makefile
===================================================================
--- trunk/minix/commands/dis88/Makefile	(revision 9)
+++ 	(revision )
@@ -1,50 +1,0 @@
-# Makefile for dis
-
-# @(#) Makefile, Ver. 2.1 created 00:00:00 87/09/01
-# Makefile for 8088 symbolic disassembler
-
-# Copyright (C) 1987 G. M. Harding, all rights reserved.
-# Permission to copy and redistribute is hereby granted,
-# provided full source code, with all copyright notices,
-# accompanies any redistribution.
-
-# This Makefile  automates the process of compiling and linking
-# a symbolic  object-file  disassembler  program  for the Intel
-# 8088 CPU. Relatively machine-independent code is contained in
-# the file dismain.c; lookup tables and handler routines, which
-# are by their nature  machine-specific,  are  contained in two
-# files named distabs.c and dishand.c,  respectively.  (A third
-# machine-specific file, disfp.c, contains handler routines for
-# floating-point  coprocessor opcodes.)  A header file,  dis.h,
-# attempts to mediate between the machine-specific and machine-
-# independent portions of the code. An attempt has been made to
-# isolate machine  dependencies and to deal with them in fairly
-# straightforward ways. Thus, it should be possible to target a
-# different CPU by rewriting the handler  routines and changing
-# the initialization  data in the lookup tables.  It should not
-# be necessary to alter the formats of the tables.
-
-CFLAGS =-O -wo
-OBJ = disrel.o dismain.o distabs.o dishand.o disfp.o
-CC=exec cc
-
-all:	dis88
-
-dis88:	$(OBJ)
-	cc -i -o dis88 $(OBJ)
-	install -S 5kw dis88
-
-install:	/usr/bin/dis88
-
-/usr/bin/dis88:	dis88
-	install -cs -o bin dis88 $@
-
-disrel.o:	disrel.c
-dismain.o:	dismain.c dis.h
-distabs.o:	distabs.c dis.h
-dishand.o:	dishand.c dis.h
-disfp.o:	disfp.c dis.h
-
-
-clean:	
-	rm -f *.bak *.o core dis88
Index: trunk/minix/commands/dis88/README
===================================================================
--- trunk/minix/commands/dis88/README	(revision 9)
+++ 	(revision )
@@ -1,239 +1,0 @@
-                                     dis88
-                                  Beta Release
-                                    87/09/01
-                                      ---
-                                 G. M. HARDING
-                                    POB 4142
-                           Santa Clara CA  95054-0142
-
-
-             "Dis88" is a symbolic disassembler for the Intel 8088 CPU,
-        designed to run under the PC/IX  operating  system on an IBM XT
-        or fully-compatible clone.  Its output is in the format of, and
-        is completely compatible with, the PC/IX assembler,  "as".  The
-        program is copyrighted by its author, but may be copied and re-
-        distributed freely provided that complete source code, with all
-        copyright notices, accompanies any distribution. This provision
-        also applies to any  modifications you may make.  You are urged
-        to comment such changes,  giving,  as a miminum,  your name and
-        complete address.
-
-             This release of the program is a beta release, which means
-        that it has been  extensively,  but not  exhaustively,  tested.
-        User comments, recommendations, and bug fixes are welcome.  The
-        principal features of the current release are:
-
-             (a)  The ability to  disassemble  any file in PC/IX object
-        format, making full use of symbol and relocation information if
-        it is present,  regardless of whether the file is executable or
-        linkable,  and regardless of whether it has continuous or split
-        I/D space;
-
-             (b)  Automatic generation of synthetic labels when no sym-
-        bol table is available; and
-
-             (c)  Optional  output of address and object-code  informa-
-        tion as assembler comment text.
-
-             Limitations of the current release are:
-
-             (a)  Numeric co-processor  (i.e., 8087)  mnemonics are not
-        supported.  Instructions  for the co-processor are disassembled
-        as CPU escape  sequences,  or as  interrupts,  depending on how
-        they were assembled in the first place. This limitation will be
-        addressed in a future release.
-
-             (b)  Symbolic  references  within the object  file's  data
-        segment are not supported. Thus, for example, if a data segment
-        location is initialized to point to a text segment address,  no
-        reference to a text segment symbol will be detected. This limi-
-        tation is likely to remain in future  releases,  because object
-        code does not, in most cases, contain sufficient information to
-        allow meaningful interpretation of pure data.  (Note,  however,
-        that  symbolic  references  to the data segment from within the
-        text segment are always supported.)
-
-             As a final caveat,  be aware that the PC/IX assembler does
-        not recognize the  "esc"  mnemonic,  even though it refers to a
-        completely  valid CPU operation  which is documented in all the
-        Intel literature. Thus, the corresponding opcodes (0xd8 through
-        0xdf) are disassembled as .byte directives. For reference, how-
-        ever,  the syntactically-correct "esc" instruction is output as
-        a comment.
-
-             To build the disassembler program, transfer all the source
-        files,  together with the Makefile,  to a suitable  (preferably
-        empty) PC/IX directory. Then, simply type "make".
-
-             To use dis88,  place it in a  directory  which  appears in
-        your $PATH list.  It may then be invoked by name from  whatever
-        directory you happen to be in.  As a minimum,  the program must
-        be invoked with one command-line argument:  the name of the ob-
-        ject file to be disassembled.  (Dis88 will complain if the file
-        specified is not an object file.)  Optionally,  you may specify
-        an output file; stdout is the default.  One command-line switch
-        is available:  "-o",  which makes the program display addresses
-        and object code along with its mnemonic disassembly.
-
-             The "-o" option is useful primarily for verifying the cor-
-        rectness of the program's output. In particular, it may be used
-        to check the accuracy of local  relative  jump  opcodes.  These
-        jumps often  target  local  labels,  which are lost at assembly
-        time;  thus,  the disassembly may contain cryptic  instructions
-        like "jnz .+39".  As a user convenience,  all relative jump and
-        call  opcodes are output with a comment  which  identifies  the
-        physical target address.
-
-             By convention, the release level of the program as a whole
-        is the SID of the file disrel.c, and this SID string appears in
-        each disassembly.  Release 2.1 of the program is the first beta
-        release to be distributed on Usenet.
-
-
-.TH dis88 1 LOCAL
-.SH "NAME"
-dis88 \- 8088 symbolic disassembler
-.SH "SYNOPSIS"
-\fBdis88\fP [ -o ] ifile [ ofile ]
-.SH "DESCRIPTION"
-Dis88 reads ifile, which must be in PC/IX a.out format.
-It interprets the binary opcodes and data locations, and
-writes corresponding assembler source code to stdout, or
-to ofile if specified.  The program's output is in the
-format of, and fully compatible with, the PC/IX assembler,
-as(1).  If a symbol table is present in ifile, labels and
-references will be symbolic in the output.  If the input
-file lacks a symbol table, the fact will be noted, and the
-disassembly will proceed, with the disassembler generating
-synthetic labels as needed.  If the input file has split
-I/D space, or if it is executable, the disassembler will
-make all necessary adjustments in address-reference calculations.
-.PP
-If the "-o" option appears, object code will be included
-in comments during disassembly of the text segment.  This
-feature is used primarily for debugging the disassembler
-itself, but may provide information of passing interest
-to users.
-.PP
-The program always outputs the current machine address
-before disassembling an opcode.  If a symbol table is
-present, this address is output as an assembler comment;
-otherwise, it is incorporated into the synthetic label
-which is generated internally.  Since relative jumps,
-especially short ones, may target unlabelled locations,
-the program always outputs the physical target address
-as a comment, to assist the user in following the code.
-.PP
-The text segment of an object file is always padded to
-an even machine address.  In addition, if the file has
-split I/D space, the text segment will be padded to a
-paragraph boundary (i.e., an address divisible by 16).
-As a result of this padding, the disassembler may produce
-a few spurious, but harmless, instructions at the
-end of the text segment.
-.PP
-Disassembly of the data segment is a difficult matter.
-The information to which initialized data refers cannot
-be inferred from context, except in the special case
-of an external data or address reference, which will be
-reflected in the relocation table.  Internal data and
-address references will already be resolved in the object file,
-and cannot be recreated.  Therefore, the data
-segment is disassembled as a byte stream, with long
-stretches of null data represented by an appropriate
-".zerow" pseudo-op.  This limitation notwithstanding,
-labels (as opposed to symbolic references) are always
-output at appropriate points within the data segment.
-.PP
-If disassembly of the data segment is difficult, disassembly of the
-bss segment is quite easy, because uninitialized data is all
-zero by definition.  No data
-is output in the bss segment, but symbolic labels are
-output as appropriate.
-.PP
-For each opcode which takes an operand, a particular
-symbol type (text, data, or bss) is appropriate.  This
-tidy correspondence is complicated somewhat, however,
-by the existence of assembler symbolic constants and
-segment override opcodes.  Therefore, the disassembler's
-symbol lookup routine attempts to apply a certain amount
-of intelligence when it is asked to find a symbol.  If
-it cannot match on a symbol of the preferred type, it
-may return a symbol of some other type, depending on
-preassigned (and somewhat arbitrary) rankings within
-each type.  Finally, if all else fails, it returns a
-string containing the address sought as a hex constant;
-this behavior allows calling routines to use the output
-of the lookup function regardless of the success of its
-search.
-.PP
-It is worth noting, at this point, that the symbol lookup
-routine operates linearly, and has not been optimized in
-any way.  Execution time is thus likely to increase
-geometrically with input file size.  The disassembler is
-internally limited to 1500 symbol table entries and 1500
-relocation table entries; while these limits are generous
-(/unix, itself, has fewer than 800 symbols), they are not
-guaranteed to be adequate in all cases.  If the symbol
-table or the relocation table overflows, the disassembly
-aborts.
-.PP
-Finally, users should be aware of a bug in the assembler,
-which causes it not to parse the "esc" mnemonic, even
-though "esc" is a completely legitimate opcode which is
-documented in all the Intel literature.  To accommodate
-this deficiency, the disassembler translates opcodes of
-the "esc" family to .byte directives, but notes the
-correct mnemonic in a comment for reference.
-.PP
-In all cases, it should be possible to submit the output
-of the disassembler program to the assembler, and assemble
-it without error.  In most cases, the resulting object
-code will be identical to the original; in any event, it
-will be functionally equivalent.
-.SH "SEE ALSO"
-adb(1), as(1), cc(1), ld(1).
-.br
-"Assembler Reference Manual" in the PC/IX Programmer's
-Guide.
-.SH "DIAGNOSTICS"
-"can't access input file" if the input file cannot be
-found, opened, or read.
-.sp
-"can't open output file" if the output file cannot be
-created.
-.sp
-"warning: host/cpu clash" if the program is run on a
-machine with a different CPU.
-.sp
-"input file not in object format" if the magic number
-does not correspond to that of a PC/IX object file.
-.sp
-"not an 8086/8088 object file" if the CPU ID of the
-file header is incorrect.
-.sp
-"reloc table overflow" if there are more than 1500
-entries in the relocation table.
-.sp
-"symbol table overflow" if there are more than 1500
-entries in the symbol table.
-.sp
-"lseek error" if the input file is corrupted (should
-never happen).
-.sp
-"warning: no symbols" if the symbol table is missing.
-.sp
-"can't reopen input file" if the input file is removed
-or altered during program execution (should never happen).
-.SH "BUGS"
-Numeric co-processor (i.e., 8087) mnemonics are not currently supported.
-Instructions for the co-processor are
-disassembled as CPU escape sequences, or as interrupts,
-depending on how they were assembled in the first place.
-.sp
-Despite the program's best efforts, a symbol retrieved
-from the symbol table may sometimes be different from
-the symbol used in the original assembly.
-.sp
-The disassembler's internal tables are of fixed size,
-and the program aborts if they overflow.
Index: trunk/minix/commands/dis88/build
===================================================================
--- trunk/minix/commands/dis88/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/dis88/dis.h
===================================================================
--- trunk/minix/commands/dis88/dis.h	(revision 9)
+++ 	(revision )
@@ -1,167 +1,0 @@
- /*
- ** @(#) dis.h, Ver. 2.1 created 00:00:00 87/09/01
- */
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  *  Copyright (C) 1987 G. M. Harding, all rights reserved  *
-  *                                                         *
-  * Permission to copy and  redistribute is hereby granted, *
-  * provided full source code,  with all copyright notices, *
-  * accompanies any redistribution.                         *
-  *                                                         *
-  * This file contains declarations and definitions used by *
-  * the 8088 disassembler program. The program was designed *
-  * for execution on a machine of its own type (i.e., it is *
-  * not designed as a cross-disassembler);  consequently, A *
-  * SIXTEEN-BIT INTEGER SIZE HAS BEEN ASSUMED. This assump- *
-  * tion is not particularly important,  however, except in *
-  * the machine-specific  portions of the code  (i.e.,  the *
-  * handler  routines and the optab[] array).  It should be *
-  * possible to override this assumption,  for execution on *
-  * 32-bit machines,  by use of a  pre-processor  directive *
-  * (see below); however, this has not been tested.         *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-#include <sys/types.h>
-#include <a.out.h>      /* Object file format definitions   */
-#include <fcntl.h>      /* System file-control definitions  */
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>      /* System standard I/O definitions  */
-
-#define MAXSYM 1500     /* Maximum entries in symbol table  */
-
-extern struct nlist     /* Array to hold the symbol table   */
-   symtab[MAXSYM];
-
-extern struct reloc     /* Array to hold relocation table   */
-   relo[MAXSYM];
-
-extern int symptr;      /* Index into the symtab[] array    */
-extern int relptr;      /* Index into the relo[] array      */
-
-struct opcode           /* Format for opcode data records   */
-{
-   char *text;          /* Pointer to mnemonic text   */
-   void (*func)();      /* Pointer to handler routine */
-   unsigned min;        /* Minimum # of object bytes  */
-   unsigned max;        /* Maximum # of object bytes  */
-};
-
-extern struct opcode    /* Array to hold the opcode table   */
-  optab[256];
-
-extern char *REGS[];    /* Table of register names          */
-extern char *REGS0[];   /* Mode 0 register name table       */
-extern char *REGS1[];   /* Mode 1 register name table       */
-
-#define AL REGS[0]      /* CPU register manifests           */
-#define CL REGS[1]
-#define DL REGS[2]
-#define BL REGS[3]
-#define AH REGS[4]
-#define CH REGS[5]
-#define DH REGS[6]
-#define BH REGS[7]
-#define AX REGS[8]
-#define CX REGS[9]
-#define DX REGS[10]
-#define BX REGS[11]
-#define SP REGS[12]
-#define BP REGS[13]
-#define SI REGS[14]
-#define DI REGS[15]
-#define ES REGS[16]
-#define CS REGS[17]
-#define SS REGS[18]
-#define DS REGS[19]
-#define BX_SI REGS0[0]
-#define BX_DI REGS0[1]
-#define BP_SI REGS0[2]
-#define BP_DI REGS0[3]
-
-extern int symrank[6][6];     /* Symbol type/rank matrix    */
-extern unsigned long PC;      /* Current program counter    */
-extern int segflg;      /* Flag: segment override in effect */
-extern int objflg;      /* Flag: output object as a comment */
-
-#define OBJMAX 8        /* Size of the object code buffer   */
-
-extern unsigned char    /* Internal buffer for object code  */
-   objbuf[OBJMAX];
-
-extern int objptr;      /* Index into the objbuf[] array    */
-
-extern char ADD[],      /* Opcode family mnemonic strings   */
-            OR[],
-            ADC[],
-            SBB[],
-            AND[],
-            SUB[],
-            XOR[],
-            CMP[],
-            NOT[],
-            NEG[],
-            MUL[],
-            DIV[],
-            MOV[],
-            ESC[],
-            TEST[],
-            AMBIG[];
-
-extern char *OPFAM[];   /* Indexed mnemonic family table    */
-extern struct exec HDR; /* Holds the object file's header   */
-
-#define LOOK_ABS 0      /* Arguments to lookup() function   */
-#define LOOK_REL 1
-#define LOOK_LNG 2
-
-#define TR_STD 0        /* Arguments to mtrans() function   */
-#define TR_SEG 8
-
-                        /* Macro for byte input primitive   */
-#define FETCH(p)  ++PC; p = getchar() & 0xff; objbuf[objptr++] = p
-
-
-/* disfp.c */
-_PROTOTYPE(void eshand, (int j ));
-_PROTOTYPE(void fphand, (int j ));
-_PROTOTYPE(void inhand, (int j ));
-
-/* dishand.c */
-_PROTOTYPE(void objini, (int j ));
-_PROTOTYPE(void objout, (void));
-_PROTOTYPE(void badseq, (int j, int k ));
-_PROTOTYPE(void dfhand, (int j ));
-_PROTOTYPE(void sbhand, (int j ));
-_PROTOTYPE(void aohand, (int j ));
-_PROTOTYPE(void sjhand, (int j ));
-_PROTOTYPE(void imhand, (int j ));
-_PROTOTYPE(void mvhand, (int j ));
-_PROTOTYPE(void mshand, (int j ));
-_PROTOTYPE(void pohand, (int j ));
-_PROTOTYPE(void cihand, (int j ));
-_PROTOTYPE(void mihand, (int j ));
-_PROTOTYPE(void mqhand, (int j ));
-_PROTOTYPE(void tqhand, (int j ));
-_PROTOTYPE(void rehand, (int j ));
-_PROTOTYPE(void mmhand, (int j ));
-_PROTOTYPE(void srhand, (int j ));
-_PROTOTYPE(void aahand, (int j ));
-_PROTOTYPE(void iohand, (int j ));
-_PROTOTYPE(void ljhand, (int j ));
-_PROTOTYPE(void mahand, (int j ));
-_PROTOTYPE(void mjhand, (int j ));
-
-/* dismain.c */
-_PROTOTYPE(void main, (int argc, char **argv ));
-
-/* distabs.c */
-_PROTOTYPE(char *getnam, (int k ));
-_PROTOTYPE(int lookext, (long off, long loc, char *buf ));
-_PROTOTYPE(char *lookup, (long addr, int type, int kind, long ext ));
-_PROTOTYPE(char *mtrans, (int c, int m, int type ));
-_PROTOTYPE(void mtrunc, (char *a ));
Index: trunk/minix/commands/dis88/disfp.c
===================================================================
--- trunk/minix/commands/dis88/disfp.c	(revision 9)
+++ 	(revision )
@@ -1,161 +1,0 @@
-static char *sccsid =
-   "@(#) disfp.c, Ver. 2.1 created 00:00:00 87/09/01";
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  *  Copyright (C) 1987 G. M. Harding, all rights reserved  *
-  *                                                         *
-  * Permission to copy and  redistribute is hereby granted, *
-  * provided full source code,  with all copyright notices, *
-  * accompanies any redistribution.                         *
-  *                                                         *
-  * This file contains handler routines for the numeric op- *
-  * codes of the 8087 co-processor,  as well as a few other *
-  * opcodes which are related to 8087 emulation.            *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-#include "dis.h"              /* Disassembler declarations  */
-
-#define FPINT0 0xd8           /* Floating-point interrupts  */
-#define FPINT1 0xd9
-#define FPINT2 0xda
-#define FPINT3 0xdb
-#define FPINT4 0xdc
-#define FPINT5 0xdd
-#define FPINT6 0xde
-#define FPINT7 0xdf
-
-                              /* Test for floating opcodes  */
-#define ISFLOP(x) \
-   (((x) >= FPINT0) && ((x) <= FPINT7))
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the  handler for the escape  family of opcodes. *
-  * These opcodes place the contents of a specified  memory *
-  * location on the system bus,  for access by a peripheral *
-  * or by a co-processor such as the 8087. (The 8087 NDP is *
-  * accessed  only  via bus  escapes.)  Due to a bug in the *
-  * PC/IX assembler,  the "esc" mnemonic is not recognized; *
-  * consequently,  escape opcodes are disassembled as .byte *
-  * directives,  with the appropriate  mnemonic and operand *
-  * included as a comment.  FOR NOW, those escape sequences *
-  * corresponding  to 8087  opcodes  are  treated as simple *
-  * escapes.                                                *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-eshand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF eshand()  * * * * * * * * * */
-
-   register char *a;
-   register int k;
-
-   objini(j);
-
-   FETCH(k);
-
-   a = mtrans((j & 0xfd),(k & 0xc7),TR_STD);
-
-   mtrunc(a);
-
-   printf("\t.byte\t0x%02.2x\t\t| esc\t%s\n",j,a);
-
-   for (k = 1; k < objptr; ++k)
-      printf("\t.byte\t0x%02.2x\n",objbuf[k]);
-
-}/* * * * * * * * * * * END OF eshand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler routine for floating-point opcodes. *
-  * Since PC/IX must  accommodate  systems with and without *
-  * 8087 co-processors, it allows floating-point operations *
-  * to be  initiated  in either of two ways:  by a software *
-  * interrput whose type is in the range 0xd8 through 0xdf, *
-  * or by a CPU escape sequence, which is invoked by an op- *
-  * code in the same range.  In either case, the subsequent *
-  * byte determines the actual numeric operation to be per- *
-  * formed.  However,  depending  on the  method of access, *
-  * either  one or two code bytes will  precede  that byte, *
-  * and the fphand()  routine has no way of knowing whether *
-  * it was invoked by  interrupt or by an escape  sequence. *
-  * Therefore, unlike all of the other handler routines ex- *
-  * cept dfhand(),  fphand() does not initialize the object *
-  * buffer, leaving that chore to the caller.               *
-  *                                                         *
-  * FOR NOW,  fphand()  does not disassemble floating-point *
-  * opcodes to floating  mnemonics,  but simply outputs the *
-  * object code as .byte directives.                        *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-fphand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF fphand()  * * * * * * * * * */
-
-   register int k;
-
-   segflg = 0;
-
-   FETCH(k);
-
-   printf("\t.byte\t0x%02.2x\t\t| 8087 code sequence\n",
-    objbuf[0]);
-
-   for (k = 1; k < objptr; ++k)
-      printf("\t.byte\t0x%02.2x\n",objbuf[k]);
-
-/* objout();                                       FOR NOW  */
-
-}/* * * * * * * * * * * END OF fphand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the  handler for  variable  software  interrupt *
-  * opcodes.  It is included in this file because PC/IX im- *
-  * plements its software floating-point emulation by means *
-  * of interrupts.  Any interrupt in the range 0xd8 through *
-  * 0xdf is an  NDP-emulation  interrupt,  and is specially *
-  * handled by the assembler.                               *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-inhand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF inhand()  * * * * * * * * * */
-
-   register int k;
-
-   objini(j);
-
-   FETCH(k);
-
-   if (ISFLOP(k))
-      {
-      fphand(k);
-      return;
-      }
-
-   printf("%s\t%d\n",optab[j].text,k);
-
-   objout();
-
-}/* * * * * * * * * * * END OF inhand() * * * * * * * * * * */
-
-
-
Index: trunk/minix/commands/dis88/dishand.c
===================================================================
--- trunk/minix/commands/dis88/dishand.c	(revision 9)
+++ 	(revision )
@@ -1,1071 +1,0 @@
-static char *sccsid =
-   "@(#) dishand.c, Ver. 2.1 created 00:00:00 87/09/01";
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  *  Copyright (C) 1987 G. M. Harding, all rights reserved  *
-  *                                                         *
-  * Permission to copy and  redistribute is hereby granted, *
-  * provided full source code,  with all copyright notices, *
-  * accompanies any redistribution.                         *
-  *                                                         *
-  * This file contains the source code for most of the spe- *
-  * cialized handler routines of the disassembler  program. *
-  * (The file disfp.c contains handler routines specific to *
-  * the 8087 numeric  co-processor.)  Each handler  routine *
-  * interprets the opcode byte  (and subsequent data bytes, *
-  * if any)  of a particular family of opcodes,  and is re- *
-  * sponsible for generating appropriate output. All of the *
-  * code in this file is highly MACHINE-SPECIFIC, and would *
-  * have to be rewritten for a different  CPU.  The handler *
-  * routines are accessed  only via pointers in the optab[] *
-  * array, however, so machine dependencies are confined to *
-  * this file, its sister file "disfp.c", and the data file *
-  * "distabs.c".                                            *
-  *                                                         *
-  * All of the code in this file is based on the assumption *
-  * of sixteen-bit integers.                                *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-#include "dis.h"              /* Disassembler declarations  */
-
-int segflg;                   /* Segment-override flag      */
-
-unsigned char objbuf[OBJMAX]; /* Buffer for object code     */
-
-int objptr;                   /* Index into objbuf[]        */
-
-unsigned long PC;             /* Current program counter    */
-
-
- /* * * * * *  MISCELLANEOUS SUPPORTING ROUTINES  * * * * * */
-
-
-void
-objini(j)                     /* Object code init routine   */
-
-   register int j;
-
-{
-   if ((segflg == 1) || (segflg == 2))
-      segflg *= 3;
-   else
-      segflg = 0;
-   objptr = 0;
-   objbuf[objptr++] = (unsigned char)(j);
-}
-
-
-void
-objout()                      /* Object-code output routine */
-
-{
-    register int k;
-
-   if ( ! objflg )
-      return;
-   else
-      {
-      printf("\t|");
-      if (symptr >= 0)
-         printf(" %05.5lx:",(PC + 1L - (long)(objptr)));
-      for (k = 0; k < objptr; ++k)
-         printf(" %02.2x",objbuf[k]);
-      putchar('\n');
-      }
-}
-
-
-void
-badseq(j,k)                   /* Invalid-sequence routine   */
-
-   register int j, k;
-
-{
-   printf("\t.byte\t0x%02.2x\t\t| invalid code sequence\n",j);
-   printf("\t.byte\t0x%02.2x\n",k);
-}
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This  routine  is the first of several  opcode-specific *
-  * handlers,  each of which is  dedicated  to a particular *
-  * opcode family.  A pointer to a handler  routine is con- *
-  * tained in the second field of each optab[]  entry.  The *
-  * dfhand()  routine is the default handler,  invoked when *
-  * no other handler is appropriate (generally, when an in- *
-  * valid opcode is encountered).                           *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-dfhand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF dfhand()  * * * * * * * * * */
-
-   segflg = 0;
-
-   printf("\t.byte\t0x%02.2x",j);
-
-   if (optab[j].min || optab[j].max)
-      putchar('\n');
-   else
-      printf("\t\t| unimplemented opcode\n");
-
-}/* * * * * * * * * * * END OF dfhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the  single-byte  handler,  invoked  whenever a *
-  * one-byte opcode is encountered.                         *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-sbhand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF sbhand()  * * * * * * * * * */
-
-   objini(j);
-
-   if (j == 0x2e)                               /* seg cs   */
-      segflg = 1;
-
-   if ((j == 0x26)                              /* seg es   */
-    || (j == 0x36)                              /* seg ss   */
-    || (j == 0x3e))                             /* seg ds   */
-      segflg = 2;
-
-   printf("%s\n",optab[j].text);
-
-   objout();
-
-}/* * * * * * * * * * * END OF sbhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for most of the processor's regular *
-  * arithmetic operations.                                  *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-aohand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF aohand()  * * * * * * * * * */
-
-   register int k;
-   int m, n;
-   char b[64];
-
-   objini(j);
-
-   switch (j & 7)
-      {
-      case 0 :
-      case 1 :
-      case 2 :
-      case 3 :
-         printf("%s\t",optab[j].text);
-         FETCH(k);
-         printf("%s\n",mtrans(j,k,TR_STD));
-         break;
-      case 4 :
-         FETCH(k);
-         printf("%s\tal,*0x%02.2x\n",optab[j].text,k);
-         break;
-      case 5 :
-         FETCH(m);
-         FETCH(n);
-         k = (n << 8) | m;
-         if (lookext((long)(k),(PC - 1),b))
-            printf("%s\tax,#%s\n",optab[j].text,b);
-         else
-            printf("%s\tax,#0x%04.4x\n",optab[j].text,k);
-         break;
-      default :
-         dfhand(j);
-         break;
-      }
-
-   objout();
-
-}/* * * * * * * * * * * END OF aohand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the  handler for opcodes  which  perform  short *
-  * (eight-bit) relative jumps.                             *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-sjhand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF sjhand()  * * * * * * * * * */
-
-   register int k;
-   int m;
-
-   objini(j);
-
-   FETCH(m);
-
-   if (m & 0x80)
-      k = 0xff00;
-   else
-      k = 0;
-
-   k |= m;
-
-   printf("%s\t%s\t\t| loc %05.5lx\n",optab[j].text,
-    lookup((PC + k + 1L),N_TEXT,LOOK_REL,-1L),
-    (PC + k + 1L));
-
-   objout();
-
-}/* * * * * * * * * * * END OF sjhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the  handler for a  loosely-knit  family of op- *
-  * codes which perform  arithmetic and logical operations, *
-  * and which take immediate  data.  The routine's logic is *
-  * rather complex,  so,  in an effort to avoid  additional *
-  * complexity,  the search for external  references in the *
-  * relocation table has been dispensed with. Eager hackers *
-  * can try their hand at coding such a search.             *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-imhand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF imhand()  * * * * * * * * * */
-
-   unsigned long pc;
-   register int k;
-   int offset, oflag, immed, iflag, mod, opi, w, rm;
-   int m, n;
-   static char a[100], b[30];
-
-   objini(j);
-
-   FETCH(k);
-
-   pc = PC + 1;
-
-   offset = 0;
-   mod = (k & 0xc0) >> 6;
-   opi = (k & 0x38) >> 3;
-   w = j & 1;
-   rm = k & 7;
-
-   if ((j & 2)
-    && ((opi == 1)
-     || (opi == 4)
-     || (opi == 6)))
-      {
-      badseq(j,k);
-      return;
-      }
-
-   strcpy(a,OPFAM[opi]);
-
-   if ( ! w )
-      strcat(a,"b");
-
-   if ((oflag = mod) > 2)
-      oflag = 0;
-
-   if ((mod == 0) && (rm == 6))
-      {
-      FETCH(m);
-      FETCH(n);
-      offset = (n << 8) | m;
-      }
-   else if (oflag)
-      if (oflag == 2)
-         {
-         FETCH(m);
-         FETCH(n);
-         offset = (n << 8) | m;
-         }
-      else
-         {
-         FETCH(m);
-         if (m & 0x80)
-            n = 0xff00;
-         else
-            n = 0;
-         offset = n | m;
-         }
-
-   switch (j & 3)
-      {
-      case 0 :
-      case 2 :
-         FETCH(immed);
-         iflag = 0;
-         break;
-      case 1 :
-         FETCH(m);
-         FETCH(n);
-         immed = (n << 8) | m;
-         iflag = 1;
-         break;
-      case 3 :
-         FETCH(immed);
-         if (immed & 0x80)
-            immed &= 0xff00;
-         iflag = 0;
-         break;
-      }
-
-   strcat(a,"\t");
-
-   switch (mod)
-      {
-      case 0 :
-         if (rm == 6)
-            strcat(a,
-             lookup((long)(offset),N_DATA,LOOK_ABS,pc));
-         else
-            {
-            sprintf(b,"(%s)",REGS0[rm]);
-            strcat(a,b);
-            }
-         break;
-      case 1 :
-      case 2 :
-         if (mod == 1)
-            strcat(a,"*");
-         else
-            strcat(a,"#");
-         sprintf(b,"%d(",offset);
-         strcat(a,b);
-         strcat(a,REGS1[rm]);
-         strcat(a,")");
-         break;
-      case 3 :
-         strcat(a,REGS[(w << 3) | rm]);
-         break;
-      }
-
-   strcat(a,",");
-   if (iflag)
-      strcat(a,"#");
-   else
-      strcat(a,"*");
-   sprintf(b,"%d",immed);
-   strcat(a,b);
-
-   printf("%s\n",a);
-
-   objout();
-
-}/* * * * * * * * * * * END OF imhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the  handler  for  various  "mov"-type  opcodes *
-  * which use the mod,  reg,  and r/m  fields of the second *
-  * code byte in a standard, straightforward way.           *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-mvhand(j)
-
-   int j;                     /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF mvhand()  * * * * * * * * * */
-
-   register int k, m = j;
-
-   objini(j);
-
-   FETCH(k);
-
-   if ((m == 0x84) || (m == 0x85)      /* Kind of kludgey   */
-    || (m == 0xc4) || (m == 0xc5)
-    || (m == 0x8d))
-      if (m & 0x40)
-         m |= 0x03;
-      else
-         m |= 0x02;
-
-   printf("%s\t%s\n",optab[j].text,mtrans(m,k,TR_STD));
-
-   objout();
-
-}/* * * * * * * * * * * END OF mvhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for segment-register "mov" opcodes. *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-mshand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF mshand()  * * * * * * * * * */
-
-   register int k;
-
-   objini(j);
-
-   FETCH(k);
-
-   if (k & 0x20)
-      {
-      badseq(j,k);
-      return;
-      }
-
-   printf("%s\t%s\n",optab[j].text,mtrans(j,k,TR_SEG));
-
-   objout();
-
-}/* * * * * * * * * * * END OF mshand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the  handler for pops,  other than  single-byte *
-  * pops.  (The 8088 allows  popping into any register,  or *
-  * directly into memory,  accessed  either  immediately or *
-  * through a register and an index.)                       *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-pohand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF pohand()  * * * * * * * * * */
-
-   char *a;
-   register int k;
-
-   objini(j);
-
-   FETCH(k);
-
-   if (k & 0x38)
-      {
-      badseq(j,k);
-      return;
-      }
-
-   printf("%s\t",optab[j].text);
-
-   a = mtrans((j & 0xfd),k,TR_STD);
-
-   mtrunc(a);
-
-   printf("%s\n",a);
-
-   objout();
-
-}/* * * * * * * * * * * END OF pohand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler routine for intersegment  calls and *
-  * jumps.  Its output is never symbolic,  because the host *
-  * linker  does not allow  symbolic  intersegment  address *
-  * references except by means of symbolic  constants,  and *
-  * any such  constants in the symbol  table,  even if they *
-  * are of the  appropriate  value,  may be misleading.  In *
-  * compiled code,  intersegment  references  should not be *
-  * encountered,  and even in assembled  code,  they should *
-  * occur infrequently. If and when they do occur, however, *
-  * they will be disassembled in absolute form.             *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-cihand(j)
-
-   int j;                     /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF cihand()  * * * * * * * * * */
-
-   register int m, n;
-
-   objini(j);
-
-   printf("%s\t",optab[j].text);
-
-   FETCH(m);
-   FETCH(n);
-
-   printf("#0x%04.4x,",((n << 8) | m));
-
-   FETCH(m);
-   FETCH(n);
-
-   printf("#0x%04.4x\n",((n << 8) | m));
-
-   objout();
-
-}/* * * * * * * * * * * END OF cihand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for  "mov"  opcodes with  immediate *
-  * data.                                                   *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-mihand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF mihand()  * * * * * * * * * */
-
-   register int k;
-   int m, n;
-   char b[64];
-
-   objini(j);
-
-   printf("%s",optab[j].text);
-
-   if (j & 8)
-      {
-      FETCH(m);
-      FETCH(n);
-      k = ((n << 8) | m);
-      if (lookext((long)(k),(PC - 1),b))
-         printf("#%s\n",b);
-      else
-         printf("#%d\n",k);
-      }
-   else
-      {
-      FETCH(m);
-      printf("*%d\n",m);
-      }
-
-   objout();
-
-}/* * * * * * * * * * * END OF mihand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for a family of quick-move opcodes. *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-mqhand(j)
-
-   int j;                     /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF mqhand()  * * * * * * * * * */
-
-   unsigned long pc;
-   register int m, n;
-
-   objini(j);
-
-   pc = PC + 1;
-
-   FETCH(m);
-   FETCH(n);
-
-   m = (n << 8) | m;
-
-   printf("%s\t",optab[j].text);
-
-   if (j & 2)
-      printf("%s,%s\n",
-       lookup((long)(m),N_DATA,LOOK_ABS,pc),
-       REGS[(j & 1) << 3]);
-   else
-      printf("%s,%s\n",
-       REGS[(j & 1) << 3],
-       lookup((long)(m),N_DATA,LOOK_ABS,pc));
-
-   objout();
-
-}/* * * * * * * * * * * END OF mqhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for a family of quick-test opcodes. *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-tqhand(j)
-
-   int j;                     /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF tqhand()  * * * * * * * * * */
-
-   register int m, n;
-   int k;
-   char b[64];
-
-   objini(j);
-
-   printf("%s\t%s,",optab[j].text,REGS[(j & 1) << 3]);
-
-   FETCH(m);
-
-   if (j & 1)
-      {
-      FETCH(n);
-      k = ((n << 8) | m);
-      if (lookext((long)(k),(PC - 1),b))
-         printf("#%s\n",b);
-      else
-         printf("#%d\n",k);
-      }
-   else
-      {
-      if (m & 80)
-         m |= 0xff00;
-      printf("*%d\n",m);
-      }
-
-   objout();
-
-}/* * * * * * * * * * * END OF tqhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for multiple-byte "return" opcodes. *
-  * The 8088 allows returns to take an optional  16-bit ar- *
-  * gument,  which  reflects  the  amount to be added to SP *
-  * after  the pop of the  return  address.  The idea is to *
-  * facilitate  the use of local  parameters  on the stack. *
-  * After some  rumination,  it was decided to  disassemble *
-  * any such arguments as absolute quantities,  rather than *
-  * rummaging  through the symbol table for possible corre- *
-  * sponding constants.                                     *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-rehand(j)
-
-   int j;                     /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF rehand()  * * * * * * * * * */
-
-   register int m, n;
-
-   objini(j);
-
-   FETCH(m);
-   FETCH(n);
-
-   m = (n << 8) | m;
-
-   printf("%s\t#0x%04.4x\n",optab[j].text,m);
-
-   objout();
-
-}/* * * * * * * * * * * END OF rehand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for "mov"  opcodes involving memory *
-  * and immediate data.                                     *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-mmhand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF mmhand()  * * * * * * * * * */
-
-   char *a;
-   register int k;
-   char b[64];
-
-   objini(j);
-
-   FETCH(k);
-
-   if (k & 0x38)
-      {
-      badseq(j,k);
-      return;
-      }
-
-   printf("%s",optab[j].text);
-
-   if ( ! (j & 1) )
-      putchar('b');
-
-   a = mtrans((j & 0xfd),(k & 0xc7),TR_STD);
-
-   mtrunc(a);
-
-   printf("\t%s,",a);
-
-   if (j & 1)
-      {
-      FETCH(j);
-      FETCH(k);
-      k = (k << 8) | j;
-      if (lookext((long)(k),(PC - 1),b))
-         printf("#%s\n",b);
-      else
-         printf("#%d\n",k);
-      }
-   else
-      {
-      FETCH(k);
-      printf("*%d\n",k);
-      }
-
-   objout();
-
-}/* * * * * * * * * * * END OF mmhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the  handler  for the 8088  family of shift and *
-  * rotate instructions.                                    *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-srhand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF srhand()  * * * * * * * * * */
-
-   char *a;
-   register int k;
-
-   objini(j);
-
-   FETCH(k);
-
-   if ((k & 0x38) == 0x30)
-      {
-      badseq(j,k);
-      return;
-      }
-
-   printf("%s",OPFAM[((k & 0x38) >> 3) + 16]);
-
-   if ( ! (j & 1) )
-      putchar('b');
-
-   a = mtrans((j & 0xfd),(k & 0xc7),TR_STD);
-
-   mtrunc(a);
-
-   printf("\t%s",a);
-
-   if (j & 2)
-      printf(",cl\n");
-   else
-      printf(",*1\n");
-
-   objout();
-
-}/* * * * * * * * * * * END OF srhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for the ASCII-adjust opcodes.       *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-aahand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF aahand()  * * * * * * * * * */
-
-   register int k;
-
-   objini(j);
-
-   FETCH(k);
-
-   if (k != 0x0a)
-      {
-      badseq(j,k);
-      return;
-      }
-
-   printf("%s\n",optab[j].text);
-
-   objout();
-
-}/* * * * * * * * * * * END OF aahand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for port I/O opcodes  which specify *
-  * the port address as an immediate operand.               *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-iohand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF iohand()  * * * * * * * * * */
-
-   register int k;
-
-   objini(j);
-
-   FETCH(k);
-
-   printf("%s\t0x%02.2x\n",optab[j].text,k);
-
-   objout();
-
-}/* * * * * * * * * * * END OF iohand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the  handler  for opcodes  which  perform  long *
-  * (sixteen-bit) relative jumps and calls.                 *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-ljhand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF ljhand()  * * * * * * * * * */
-
-   register int k;
-   int m, n;
-
-   objini(j);
-
-   FETCH(m);
-   FETCH(n);
-
-   k = (n << 8) | m;
-
-   printf("%s\t%s\t\t| loc %05.5lx\n",optab[j].text,
-    lookup((PC + k + 1L),N_TEXT,LOOK_LNG,(PC - 1L)),
-    (PC + k + 1L));
-
-   objout();
-
-}/* * * * * * * * * * * END OF ljhand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for a pair of oddball opcodes (0xf6 *
-  * and 0xf7) which perform miscellaneous arithmetic opera- *
-  * tions not dealt with elsewhere.                         *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-mahand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF mahand()  * * * * * * * * * */
-
-   char *a;
-   register int k;
-   char b[64];
-
-   objini(j);
-
-   FETCH(k);
-
-   a = mtrans((j & 0xfd),(k & 0xc7),TR_STD);
-
-   mtrunc(a);
-
-   switch (((k = objbuf[1]) & 0x38) >> 3)
-      {
-      case 0 :
-         printf("\ttest");
-         break;
-      case 1 :
-         badseq(j,k);
-         return;
-      case 2 :
-         printf("\tnot");
-         break;
-      case 3 :
-         printf("\tneg");
-         break;
-      case 4 :
-         printf("\tmul");
-         break;
-      case 5 :
-         printf("\timul");
-         break;
-      case 6 :
-         printf("\tdiv");
-         break;
-      case 7 :
-         printf("\tidiv");
-         break;
-      }
-
-   if ( ! (j & 1) )
-      putchar('b');
-
-   printf("\t%s",a);
-
-   if (k & 0x38)
-      putchar('\n');
-   else
-      if (j & 1)
-         {
-         FETCH(j);
-         FETCH(k);
-         k = (k << 8) | j;
-         if (lookext((long)(k),(PC - 1),b))
-            printf(",#%s\n",b);
-         else
-            printf(",#%d\n",k);
-         }
-      else
-         {
-         FETCH(k);
-         printf(",*%d\n",k);
-         }
-
-   objout();
-
-}/* * * * * * * * * * * END OF mahand() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the handler for miscellaneous jump, call, push, *
-  * and increment/decrement opcodes  (0xfe and 0xff)  which *
-  * are not dealt with elsewhere.                           *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-mjhand(j)
-
-   register int j;            /* Pointer to optab[] entry   */
-
-{/* * * * * * * * * *  START OF mjhand()  * * * * * * * * * */
-
-   char *a;
-   register int k;
-
-   objini(j);
-
-   FETCH(k);
-
-   a = mtrans((j & 0xfd),(k & 0xc7),TR_STD);
-
-   mtrunc(a);
-
-   switch (((k = objbuf[1]) & 0x38) >> 3)
-      {
-      case 0 :
-         printf("\tinc");
-         if ( ! (j & 1) )
-            putchar('b');
-         putchar('\t');
-         break;
-      case 1 :
-         printf("\tdec");
-         if ( ! (j & 1) )
-            putchar('b');
-         putchar('\t');
-         break;
-      case 2 :
-         if (j & 1)
-            printf("\tcall\t@");
-         else
-            goto BAD;
-         break;
-      case 3 :
-         if (j & 1)
-            printf("\tcalli\t@");
-         else
-            goto BAD;
-         break;
-      case 4 :
-         if (j & 1)
-            printf("\tjmp\t@");
-         else
-            goto BAD;
-         break;
-      case 5 :
-         if (j & 1)
-            printf("\tjmpi\t@");
-         else
-            goto BAD;
-         break;
-      case 6 :
-         if (j & 1)
-            printf("\tpush\t");
-         else
-            goto BAD;
-         break;
-      case 7 :
- BAD :
-         badseq(j,k);
-         return;
-      }
-
-   printf("%s\n",a);
-
-   objout();
-
-}/* * * * * * * * * * * END OF mjhand() * * * * * * * * * * */
-
-
-
Index: trunk/minix/commands/dis88/dismain.c
===================================================================
--- trunk/minix/commands/dis88/dismain.c	(revision 9)
+++ 	(revision )
@@ -1,631 +1,0 @@
-static char *sccsid =  "@(#) dismain.c, Ver. 2.1 created 00:00:00 87/09/01";
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  *  Copyright (C) 1987 G. M. Harding, all rights reserved  *
-  *                                                         *
-  * Permission to copy and  redistribute is hereby granted, *
-  * provided full source code,  with all copyright notices, *
-  * accompanies any redistribution.                         *
-  *                                                         *
-  * This file  contains  the source  code for the  machine- *
-  * independent  portions of a disassembler  program to run *
-  * in a Unix (System III) environment.  It expects, as its *
-  * input, a file in standard a.out format, optionally con- *
-  * taining symbol table information.  If a symbol table is *
-  * present, it will be used in the disassembly; otherwise, *
-  * all address references will be literal (absolute).      *
-  *                                                         *
-  * The disassembler  program was originally written for an *
-  * Intel 8088 CPU.  However, all details of the actual CPU *
-  * architecture are hidden in three machine-specific files *
-  * named  distabs.c,  dishand.c,  and disfp.c  (the latter *
-  * file is specific to the 8087 numeric co-processor). The *
-  * code in this file is generic,  and should require mini- *
-  * mal revision if a different CPU is to be targeted. If a *
-  * different version of Unix is to be targeted, changes to *
-  * this file may be necessary, and if a completely differ- *
-  * ent OS is to be targeted, all bets are off.             *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-#include "dis.h"              /* Disassembler declarations  */
-
-extern char *release;         /* Contains release string    */
-static char *IFILE = NULL;    /* Points to input file name  */
-static char *OFILE = NULL;    /* Points to output file name */
-static char *PRG;             /* Name of invoking program   */
-static unsigned long zcount;  /* Consecutive "0" byte count */
-int objflg = 0;               /* Flag: output object bytes  */
-
-#define unix 1
-#define i8086 1
-#define ibmpc 1
-
-#if unix && i8086 && ibmpc    /* Set the CPU identifier     */
-static int cpuid = 1;
-#else
-static int cpuid = 0;
-#endif
-
-_PROTOTYPE(static void usage, (char *s ));
-_PROTOTYPE(static void fatal, (char *s, char *t ));
-_PROTOTYPE(static void zdump, (unsigned long beg ));
-_PROTOTYPE(static void prolog, (void));
-_PROTOTYPE(static void distext, (void));
-_PROTOTYPE(static void disdata, (void));
-_PROTOTYPE(static void disbss, (void));
-
-_PROTOTYPE(static char *invoker, (char *s));
-_PROTOTYPE(static int objdump, (char *c));
-_PROTOTYPE(static char *getlab, (int type));
-_PROTOTYPE(static void prolog, (void));
-
- /* * * * * * * MISCELLANEOUS UTILITY FUNCTIONS * * * * * * */
-
-static void
-usage(s)
-   register char *s;
-{
-   fprintf(stderr,"Usage: %s [-o] ifile [ofile]\n",s);
-   exit(-1);
-}
-
-static void
-fatal(s,t)
-   register char *s, *t;
-{
-   fprintf(stderr,"\07%s: %s\n",s,t);
-   exit(-1);
-}
-
-static void
-zdump(beg)
-   unsigned long beg;
-{
-   beg = PC - beg;
-   if (beg > 1L)
-      printf("\t.zerow\t%ld\n",(beg >> 1));
-   if (beg & 1L)
-      printf("\t.byte\t0\n");
-}
-
-static char *
-invoker(s)
-   register char *s;
-{
-   register int k;
-
-   k = strlen(s);
-
-   while (k--)
-      if (s[k] == '/')
-         {
-         s += k;
-         ++s;
-         break;
-         }
-
-   return (s);
-}
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This rather tricky routine supports the disdata() func- *
-  * tion.  Its job is to output the code for a sequence  of *
-  * data bytes whenever the object buffer is full,  or when *
-  * a symbolic label is to be output. However, it must also *
-  * keep track of  consecutive  zero words so that  lengthy *
-  * stretches of null data can be  compressed by the use of *
-  * an  appropriate  assembler  pseudo-op.  It does this by *
-  * setting and testing a file-wide  flag which counts suc- *
-  * cessive full buffers of null data. The function returns *
-  * a logical  TRUE value if it outputs  anything,  logical *
-  * FALSE otherwise.  (This enables disdata()  to determine *
-  * whether to output a new  synthetic  label when there is *
-  * no symbol table.)                                       *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-static int
-objdump(c)
-
-   register char *c;
-
-{/* * * * * * * * * * START OF  objdump() * * * * * * * * * */
-
-   register int k;
-   int retval = 0;
-
-   if (objptr == OBJMAX)
-      {
-      for (k = 0; k < OBJMAX; ++k)
-         if (objbuf[k])
-            break;
-      if (k == OBJMAX)
-         {
-         zcount += k;
-         objptr = 0;
-         if (c == NULL)
-            return (retval);
-         }
-      }
-
-   if (zcount)
-      {
-      printf("\t.zerow\t%ld\n",(zcount >> 1));
-      ++retval;
-      zcount = 0L;
-      }
-
-   if (objptr)
-      {
-      printf("\t.byte\t");
-      ++retval;
-      }
-   else
-      return (retval);
-
-   for (k = 0; k < objptr; ++k)
-      {
-      printf("0x%02.2x",objbuf[k]);
-      if (k < (objptr - 1))
-         putchar(',');
-      else
-         putchar('\n');
-      }
-
-   objptr = 0;
-
-   return (retval);
-
-}/* * * * * * * * * *  END OF  objdump()  * * * * * * * * * */
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This  routine,  called  at the  beginning  of the input *
-  * cycle for each object byte,  and before any interpreta- *
-  * tion is  attempted,  searches  the symbol table for any *
-  * symbolic  name with a value  corresponding  to the cur- *
-  * rent PC and a type  corresponding  to the segment  type *
-  * (i.e.,  text, data, or bss) specified by the function's *
-  * argument. If any such name is found, a pointer to it is *
-  * returned; otherwise, a NULL pointer is returned.        *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-static char *
-getlab(type)
-register int type;
-{/* * * * * * * * * *  START OF getlab()  * * * * * * * * * */
-
-   register int k;
-   static char b[32], c[10];
-
-   if (symptr < 0)
-      if ((type == N_TEXT)
-       || ((type == N_DATA) && ( ! objptr ) && ( ! zcount )))
-         {
-         if (type == N_TEXT)
-            sprintf(b,"T%05.5lx:",PC);
-         else
-            sprintf(b,"D%05.5lx:",PC);
-         return (b);
-         }
-      else
-         return (NULL);
-
-   for (k = 0; k <= symptr; ++k)
-      if ((symtab[k].n_value == PC)
-       && ((symtab[k].n_sclass & N_SECT) == type))
-         {
-         sprintf(b,"%s:\n",getnam(k));
-         if (objflg && (type != N_TEXT))
-            sprintf(c,"| %05.5lx\n",PC);
-         strcat(b,c);
-         return (b);
-         }
-
-   return (NULL);
-
-}/* * * * * * * * * * * END OF getlab() * * * * * * * * * * */
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This routine  performs a preliminary scan of the symbol *
-  * table,  before disassembly begins, and outputs declara- *
-  * tions of globals and constants.                         *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-static void
-prolog()
-
-{/* * * * * * * * * *  START OF prolog()  * * * * * * * * * */
-
-   register int j, flag;
-
-   if (symptr < 0)
-      return;
-
-   for (j = flag = 0; j <= symptr; ++j)
-      if ((symtab[j].n_sclass & N_CLASS) == C_EXT)
-         if (((symtab[j].n_sclass & N_SECT) > N_UNDF)
-          && ((symtab[j].n_sclass & N_SECT) < N_COMM))
-            {
-            char *c = getnam(j);
-            printf("\t.globl\t%s",c);
-            if (++flag == 1)
-               {
-               putchar('\t');
-               if (strlen(c) < 8)
-                  putchar('\t');
-               printf("| Internal global\n");
-               }
-            else
-               putchar('\n');
-            }
-         else
-            if (symtab[j].n_value)
-               {
-               char *c = getnam(j);
-               printf("\t.comm\t%s,0x%08.8lx",c,
-                symtab[j].n_value);
-               if (++flag == 1)
-                  printf("\t| Internal global\n");
-               else
-                  putchar('\n');
-               }
-
-   if (flag)
-      putchar('\n');
-
-   for (j = flag = 0; j <= relptr; ++j)
-      if (relo[j].r_symndx < S_BSS)
-         {
-         char *c = getnam(relo[j].r_symndx);
-         ++flag;
-         printf("\t.globl\t%s",c);
-         putchar('\t');
-         if (strlen(c) < 8)
-            putchar('\t');
-         printf("| Undef: %05.5lx\n",relo[j].r_vaddr);
-         }
-
-   if (flag)
-      putchar('\n');
-
-   for (j = flag = 0; j <= symptr; ++j)
-      if ((symtab[j].n_sclass & N_SECT) == N_ABS)
-         {
-         char *c = getnam(j);
-         printf("%s=0x%08.8lx",c,symtab[j].n_value);
-         if (++flag == 1)
-            {
-            printf("\t\t");
-            if (strlen(c) < 5)
-               putchar('\t');
-            printf("| Literal\n");
-            }
-         else
-            putchar('\n');
-         }
-
-   if (flag)
-      putchar('\n');
-
-}/* * * * * * * * * * * END OF prolog() * * * * * * * * * * */
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This function is  responsible  for  disassembly  of the *
-  * object file's text segment.                             *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-static void
-distext()
-
-{/* * * * * * * * * * START OF  distext() * * * * * * * * * */
-
-   char *c;
-   register int j;
-   register void (*f)();
-
-   for (j = 0; j < (int)(HDR.a_hdrlen); ++j)
-      getchar();
-
-   printf("| %s, %s\n\n",PRG,release);
-
-   printf("| @(");
-
-   printf("#)\tDisassembly of %s",IFILE);
-
-   if (symptr < 0)
-      printf(" (no symbols)\n\n");
-   else
-      printf("\n\n");
-
-   if (HDR.a_flags & A_EXEC)
-      printf("| File is executable\n\n");
-
-   if (HDR.a_flags & A_SEP)
-      {
-      printf("| File has split I/D space, and may have\n");
-      printf("| extraneous instructions in text segment\n\n");
-      }
-
-   prolog();
-
-   printf("\t.text\t\t\t| loc = %05.5lx, size = %05.5lx\n\n",
-    PC,HDR.a_text);
-
-   segflg = 0;
-
-   for (PC = 0L; PC < HDR.a_text; ++PC)
-      {
-      j = getchar() & 0xff;
-      if ((j == 0) && ((PC + 1L) == HDR.a_text))
-         {
-         ++PC;
-         break;
-         }
-      if ((c = getlab(N_TEXT)) != NULL)
-         printf("%s",c);
-      f = optab[j].func;
-      (*f)(j);
-      }
-
-}/* * * * * * * * * *  END OF  distext()  * * * * * * * * * */
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This  function  handles the object file's data segment. *
-  * There is no good way to disassemble a data segment, be- *
-  * cause it is  impossible  to tell,  from the object code *
-  * alone,  what each data byte refers to.  If it refers to *
-  * an external symbol,  the reference can be resolved from *
-  * the relocation table, if there is one.  However,  if it *
-  * refers to a static symbol,  it cannot be  distinguished *
-  * from numeric, character, or other pointer data. In some *
-  * cases,  one might make a semi-educated  guess as to the *
-  * nature of the data,  but such  guesses  are  inherently *
-  * haphazard,  and they are  bound to be wrong a good por- *
-  * tion of the time.  Consequently,  the data  segment  is *
-  * disassembled  as a byte  stream,  which will satisfy no *
-  * one but which, at least, will never mislead anyone.     *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-static void
-disdata()
-
-{/* * * * * * * * * * START OF  disdata() * * * * * * * * * */
-
-   register char *c;
-   register int j;
-   unsigned long end;
-
-   putchar('\n');
-
-   if (HDR.a_flags & A_SEP)
-      {
-      PC = 0L;
-      end = HDR.a_data;
-      }
-   else
-      end = HDR.a_text + HDR.a_data;
-
-   printf("\t.data\t\t\t| loc = %05.5lx, size = %05.5lx\n\n",
-    PC,HDR.a_data);
-
-   segflg = 0;
-
-   for (objptr = 0, zcount = 0L; PC < end; ++PC)
-      {
-      if ((c = getlab(N_DATA)) != NULL)
-         {
-         objdump(c);
-         printf("%s",c);
-         }
-      if (objptr >= OBJMAX)
-         if (objdump(NULL) && (symptr < 0))
-            printf("D%05.5lx:",PC);
-      j = getchar() & 0xff;
-      objbuf[objptr++] = j;
-      }
-
-   objdump("");
-
-}/* * * * * * * * * *  END OF  disdata()  * * * * * * * * * */
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This  function  handles the object  file's bss segment. *
-  * Disassembly of the bss segment is easy,  because every- *
-  * thing in it is zero by definition.                      *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-static void disbss()
-
-{/* * * * * * * * * *  START OF disbss()  * * * * * * * * * */
-
-   register int j;
-   register char *c;
-   unsigned long beg, end;
-
-   putchar('\n');
-
-   if (HDR.a_flags & A_SEP)
-      end = HDR.a_data + HDR.a_bss;
-   else
-      end = HDR.a_text + HDR.a_data + HDR.a_bss;
-
-   printf("\t.bss\t\t\t| loc = %05.5lx, size = %05.5lx\n\n",
-    PC,HDR.a_bss);
-
-   segflg = 0;
-
-   for (beg = PC; PC < end; ++PC)
-      if ((c = getlab(N_BSS)) != NULL)
-         {
-         if (PC > beg)
-            {
-            zdump(beg);
-            beg = PC;
-            }
-         printf("%s",c);
-         }
-
-   if (PC > beg)
-      zdump(beg);
-
-}/* * * * * * * * * * * END OF disbss() * * * * * * * * * * */
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This is the program  entry  point.  The command line is *
-  * searched for an input file name, which must be present. *
-  * An optional output file name is also permitted; if none *
-  * is found, standard output is the default.  One command- *
-  * line option is available:  "-o",  which causes the pro- *
-  * gram to include  object code in comments along with its *
-  * mnemonic output.                                        *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-main(argc,argv)
-
-   int argc;                  /* Command-line args from OS  */
-   register char **argv;
-
-{/* * * * * * * * * * * START OF main() * * * * * * * * * * */
-
-   char a[1024];
-   register int fd;
-   long taboff, tabnum;
-   long reloff, relnum;
-
-   PRG = invoker(*argv);
-
-   while (*++argv != NULL)    /* Process command-line args  */
-      if (**argv == '-')
-         switch (*++*argv)
-            {
-            case 'o' :
-               if (*++*argv)
-                  usage(PRG);
-               else
-                  ++objflg;
-               break;
-            default :
-               usage(PRG);
-            }
-      else
-         if (IFILE == NULL)
-            IFILE = *argv;
-         else if (OFILE == NULL)
-            OFILE = *argv;
-         else
-            usage(PRG);
-
-   if (IFILE == NULL)
-      usage(PRG);
-   else
-      if ((fd = open(IFILE,0)) < 0)
-         {
-         sprintf(a,"can't access input file %s",IFILE);
-         fatal(PRG,a);
-         }
-
-   if (OFILE != NULL)
-      if (freopen(OFILE,"w",stdout) == NULL)
-         {
-         sprintf(a,"can't open output file %s",OFILE);
-         fatal(PRG,a);
-         }
-
-   if ( ! cpuid )
-      fprintf(stderr,"\07%s: warning: host/cpu clash\n",PRG);
-
-   read(fd, (char *) &HDR,sizeof(struct exec));
-
-   if (BADMAG(HDR))
-      {
-      sprintf(a,"input file %s not in object format",IFILE);
-      fatal(PRG,a);
-      }
-
-   if (HDR.a_cpu != A_I8086)
-      {
-      sprintf(a,"%s is not an 8086/8088 object file",IFILE);
-      fatal(PRG,a);
-      }
-
-   if (HDR.a_hdrlen <= A_MINHDR)
-      HDR.a_trsize = HDR.a_drsize = 0L;
-      HDR.a_tbase = HDR.a_dbase = 0L;
-/*   AST emergency patch
-      HDR.a_lnums = HDR.a_toffs = 0L;
-*/
-
-   reloff = HDR.a_text        /* Compute reloc data offset  */
-          + HDR.a_data
-          + (long)(HDR.a_hdrlen);
-
-   relnum =
-      (HDR.a_trsize + HDR.a_drsize) / sizeof(struct reloc);
-
-   taboff = reloff            /* Compute name table offset  */
-          + HDR.a_trsize
-          + HDR.a_drsize;
-
-   tabnum = HDR.a_syms / sizeof(struct nlist);
-
-   if (relnum > MAXSYM)
-      fatal(PRG,"reloc table overflow");
-
-   if (tabnum > MAXSYM)
-      fatal(PRG,"symbol table overflow");
-
-   if (relnum)                            /* Get reloc data */
-      if (lseek(fd,reloff,0) != reloff)
-         fatal(PRG,"lseek error");
-      else
-         {
-         for (relptr = 0; relptr < relnum; ++relptr)
-            read(fd, (char *) &relo[relptr],sizeof(struct reloc));
-         relptr--;
-         }
-
-   if (tabnum)                            /* Read in symtab */
-      if (lseek(fd,taboff,0) != taboff)
-         fatal(PRG,"lseek error");
-      else
-         {
-         for (symptr = 0; symptr < tabnum; ++symptr)
-            read(fd, (char *) &symtab[symptr],sizeof(struct nlist));
-         symptr--;
-         }
-   else
-      fprintf(stderr,"\07%s: warning: no symbols\n",PRG);
-
-   close(fd);
-
-   if (freopen(IFILE,"r",stdin) == NULL)
-      {
-      sprintf(a,"can't reopen input file %s",IFILE);
-      fatal(PRG,a);
-      }
-
-   distext();
-
-   disdata();
-
-   disbss();
-
-   exit(0);
-
-}/* * * * * * * * * * *  END OF main()  * * * * * * * * * * */
Index: trunk/minix/commands/dis88/disrel.c
===================================================================
--- trunk/minix/commands/dis88/disrel.c	(revision 9)
+++ 	(revision )
@@ -1,30 +1,0 @@
-static char *copyright =
-   "@(#) Copyright (C) 1987 G. M. Harding, all rights reserved";
-
-static char *sccsid =
-   "@(#) disrel.c, Ver. 2.1 created 00:00:00 87/09/01";
-
-char *release =
-   "release 2.1 (MINIX)";
-
- /*
- **
- ** This file documents the major revisions to the 8088 sym-
- ** bolic disassembler. It also contains the release string
- ** which is output at the head of each disassembly, and the
- ** copyright string which must be incorporated in any code
- ** distribution.
- **
- ** Permission to copy and redistribute is hereby granted,
- ** provided full source code, with all copyright notices,
- ** accompanies any redistribution.
- **
- ** REVISION HISTORY:
- **
- ** SEP 87:
- **    After internal shakeout, released on Usenet.
- **
- ** JUN 88:
- **    Ported to MINIX
- */
-
Index: trunk/minix/commands/dis88/distabs.c
===================================================================
--- trunk/minix/commands/dis88/distabs.c	(revision 9)
+++ 	(revision )
@@ -1,715 +1,0 @@
-static char *sccsid =
-   "@(#) distabs.c, Ver. 2.1 created 00:00:00 87/09/01";
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  *  Copyright (C) 1987 G. M. Harding, all rights reserved  *
-  *                                                         *
-  * Permission to copy and  redistribute is hereby granted, *
-  * provided full source code,  with all copyright notices, *
-  * accompanies any redistribution.                         *
-  *                                                         *
-  * This file  contains  the  lookup  tables and other data *
-  * structures for the Intel 8088 symbolic disassembler. It *
-  * also contains a few global  routines  which  facilitate *
-  * access to the tables,  for use primarily by the handler *
-  * functions.                                              *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-#include "dis.h"              /* Disassembler declarations  */
-
-struct exec HDR;              /* Used to hold header info   */
-
-struct nlist symtab[MAXSYM];  /* Array of symbol table info */
-
-struct reloc relo[MAXSYM];    /* Array of relocation info   */
-
-int symptr = -1,              /* Index into symtab[]        */
-    relptr = -1;              /* Index into relo[]          */
-
-char *REGS[] =                /* Table of register names    */
-   {
-   "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
-   "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
-   "es", "cs", "ss", "ds"
-   };
-
-char *REGS0[] =               /* Mode 0 register name table */
-   {
-   "bx_si", "bx_di", "bp_si", "bp_di", "si", "di", "", "bx"
-   };
-
-char *REGS1[] =               /* Mode 1 register name table */
-   {
-   "bx_si", "bx_di", "bp_si", "bp_di", "si", "di", "bp", "bx"
-   };
-
-int symrank[6][6] =           /* Symbol type/rank matrix    */
-   {
-              /* UND  ABS  TXT  DAT  BSS  COM */
-   /* UND */      5,   4,   1,   2,   3,   0,
-   /* ABS */      1,   5,   4,   3,   2,   0,
-   /* TXT */      4,   1,   5,   3,   2,   0,
-   /* DAT */      3,   1,   2,   5,   4,   0,
-   /* BSS */      3,   1,   2,   4,   5,   0,
-   /* COM */      2,   0,   1,   3,   4,   5
-   };
-
-
- /* * * * * * * * * * * * OPCODE DATA * * * * * * * * * * * */
-
-char ADD[]   = "\tadd",             /* Mnemonics by family  */
-     OR[]    = "\tor",
-     ADC[]   = "\tadc",
-     SBB[]   = "\tsbb",
-     AND[]   = "\tand",
-     SUB[]   = "\tsub",
-     XOR[]   = "\txor",
-     CMP[]   = "\tcmp",
-     NOT[]   = "\tnot",
-     NEG[]   = "\tneg",
-     MUL[]   = "\tmul",
-     DIV[]   = "\tdiv",
-     MOV[]   = "\tmov",
-     ESC[]   = "\tesc",
-     TEST[]  = "\ttest",
-     AMBIG[] = "",
-     ROL[]   = "\trol",
-     ROR[]   = "\tror",
-     RCL[]   = "\trcl",
-     RCR[]   = "\trcr",
-     SAL[]   = "\tsal",
-     SHR[]   = "\tshr",
-     SHL[]   = "\tshl",
-     SAR[]   = "\tsar";
-
-char *OPFAM[] =                     /* Family lookup table  */
-   {
-   ADD, OR, ADC, SBB, AND, SUB, XOR, CMP,
-   NOT, NEG, MUL, DIV, MOV, ESC, TEST, AMBIG,
-   ROL, ROR, RCL, RCR, SAL, SHR, SHL, SAR
-   };
-
-struct opcode optab[] =             /* Table of opcode data */
-   {
-   ADD,              aohand,  2,    4,             /* 0x00  */
-   ADD,              aohand,  2,    4,             /* 0x01  */
-   ADD,              aohand,  2,    4,             /* 0x02  */
-   ADD,              aohand,  2,    4,             /* 0x03  */
-   ADD,              aohand,  2,    2,             /* 0x04  */
-   ADD,              aohand,  3,    3,             /* 0x05  */
-   "\tpush\tes",     sbhand,  1,    1,             /* 0x06  */
-   "\tpop\tes",      sbhand,  1,    1,             /* 0x07  */
-   OR,               aohand,  2,    4,             /* 0x08  */
-   OR,               aohand,  2,    4,             /* 0x09  */
-   OR,               aohand,  2,    4,             /* 0x0a  */
-   OR,               aohand,  2,    4,             /* 0x0b  */
-   OR,               aohand,  2,    2,             /* 0x0c  */
-   OR,               aohand,  3,    3,             /* 0x0d  */
-   "\tpush\tcs",     sbhand,  1,    1,             /* 0x0e  */
-   NULL,             dfhand,  0,    0,             /* 0x0f  */
-   ADC,              aohand,  2,    4,             /* 0x10  */
-   ADC,              aohand,  2,    4,             /* 0x11  */
-   ADC,              aohand,  2,    4,             /* 0x12  */
-   ADC,              aohand,  2,    4,             /* 0x13  */
-   ADC,              aohand,  2,    2,             /* 0x14  */
-   ADC,              aohand,  3,    3,             /* 0x15  */
-   "\tpush\tss",     sbhand,  1,    1,             /* 0x16  */
-   "\tpop\tss",      sbhand,  1,    1,             /* 0x17  */
-   SBB,              aohand,  2,    4,             /* 0x18  */
-   SBB,              aohand,  2,    4,             /* 0x19  */
-   SBB,              aohand,  2,    4,             /* 0x1a  */
-   SBB,              aohand,  2,    4,             /* 0x1b  */
-   SBB,              aohand,  2,    2,             /* 0x1c  */
-   SBB,              aohand,  3,    3,             /* 0x1d  */
-   "\tpush\tds",     sbhand,  1,    1,             /* 0x1e  */
-   "\tpop\tds",      sbhand,  1,    1,             /* 0x1f  */
-   AND,              aohand,  2,    4,             /* 0x20  */
-   AND,              aohand,  2,    4,             /* 0x21  */
-   AND,              aohand,  2,    4,             /* 0x22  */
-   AND,              aohand,  2,    4,             /* 0x23  */
-   AND,              aohand,  2,    2,             /* 0x24  */
-   AND,              aohand,  3,    3,             /* 0x25  */
-   "\tseg\tes",      sbhand,  1,    1,             /* 0x26  */
-   "\tdaa",          sbhand,  1,    1,             /* 0x27  */
-   SUB,              aohand,  2,    4,             /* 0x28  */
-   SUB,              aohand,  2,    4,             /* 0x29  */
-   SUB,              aohand,  2,    4,             /* 0x2a  */
-   SUB,              aohand,  2,    4,             /* 0x2b  */
-   SUB,              aohand,  2,    2,             /* 0x2c  */
-   SUB,              aohand,  3,    3,             /* 0x2d  */
-   "\tseg\tcs",      sbhand,  1,    1,             /* 0x2e  */
-   "\tdas",          sbhand,  1,    1,             /* 0x2f  */
-   XOR,              aohand,  2,    4,             /* 0x30  */
-   XOR,              aohand,  2,    4,             /* 0x31  */
-   XOR,              aohand,  2,    4,             /* 0x32  */
-   XOR,              aohand,  2,    4,             /* 0x33  */
-   XOR,              aohand,  2,    2,             /* 0x34  */
-   XOR,              aohand,  3,    3,             /* 0x35  */
-   "\tseg\tss",      sbhand,  1,    1,             /* 0x36  */
-   "\taaa",          sbhand,  1,    1,             /* 0x37  */
-   CMP,              aohand,  2,    4,             /* 0x38  */
-   CMP,              aohand,  2,    4,             /* 0x39  */
-   CMP,              aohand,  2,    4,             /* 0x3a  */
-   CMP,              aohand,  2,    4,             /* 0x3b  */
-   CMP,              aohand,  2,    2,             /* 0x3c  */
-   CMP,              aohand,  3,    3,             /* 0x3d  */
-   "\tseg\tds",      sbhand,  1,    1,             /* 0x3e  */
-   "\taas",          sbhand,  1,    1,             /* 0x3f  */
-   "\tinc\tax",      sbhand,  1,    1,             /* 0x40  */
-   "\tinc\tcx",      sbhand,  1,    1,             /* 0x41  */
-   "\tinc\tdx",      sbhand,  1,    1,             /* 0x42  */
-   "\tinc\tbx",      sbhand,  1,    1,             /* 0x43  */
-   "\tinc\tsp",      sbhand,  1,    1,             /* 0x44  */
-   "\tinc\tbp",      sbhand,  1,    1,             /* 0x45  */
-   "\tinc\tsi",      sbhand,  1,    1,             /* 0x46  */
-   "\tinc\tdi",      sbhand,  1,    1,             /* 0x47  */
-   "\tdec\tax",      sbhand,  1,    1,             /* 0x48  */
-   "\tdec\tcx",      sbhand,  1,    1,             /* 0x49  */
-   "\tdec\tdx",      sbhand,  1,    1,             /* 0x4a  */
-   "\tdec\tbx",      sbhand,  1,    1,             /* 0x4b  */
-   "\tdec\tsp",      sbhand,  1,    1,             /* 0x4c  */
-   "\tdec\tbp",      sbhand,  1,    1,             /* 0x4d  */
-   "\tdec\tsi",      sbhand,  1,    1,             /* 0x4e  */
-   "\tdec\tdi",      sbhand,  1,    1,             /* 0x4f  */
-   "\tpush\tax",     sbhand,  1,    1,             /* 0x50  */
-   "\tpush\tcx",     sbhand,  1,    1,             /* 0x51  */
-   "\tpush\tdx",     sbhand,  1,    1,             /* 0x52  */
-   "\tpush\tbx",     sbhand,  1,    1,             /* 0x53  */
-   "\tpush\tsp",     sbhand,  1,    1,             /* 0x54  */
-   "\tpush\tbp",     sbhand,  1,    1,             /* 0x55  */
-   "\tpush\tsi",     sbhand,  1,    1,             /* 0x56  */
-   "\tpush\tdi",     sbhand,  1,    1,             /* 0x57  */
-   "\tpop\tax",      sbhand,  1,    1,             /* 0x58  */
-   "\tpop\tcx",      sbhand,  1,    1,             /* 0x59  */
-   "\tpop\tdx",      sbhand,  1,    1,             /* 0x5a  */
-   "\tpop\tbx",      sbhand,  1,    1,             /* 0x5b  */
-   "\tpop\tsp",      sbhand,  1,    1,             /* 0x5c  */
-   "\tpop\tbp",      sbhand,  1,    1,             /* 0x5d  */
-   "\tpop\tsi",      sbhand,  1,    1,             /* 0x5e  */
-   "\tpop\tdi",      sbhand,  1,    1,             /* 0x5f  */
-   NULL,             dfhand,  0,    0,             /* 0x60  */
-   NULL,             dfhand,  0,    0,             /* 0x61  */
-   NULL,             dfhand,  0,    0,             /* 0x62  */
-   NULL,             dfhand,  0,    0,             /* 0x63  */
-   NULL,             dfhand,  0,    0,             /* 0x64  */
-   NULL,             dfhand,  0,    0,             /* 0x65  */
-   NULL,             dfhand,  0,    0,             /* 0x66  */
-   NULL,             dfhand,  0,    0,             /* 0x67  */
-   NULL,             dfhand,  0,    0,             /* 0x68  */
-   NULL,             dfhand,  0,    0,             /* 0x69  */
-   NULL,             dfhand,  0,    0,             /* 0x6a  */
-   NULL,             dfhand,  0,    0,             /* 0x6b  */
-   NULL,             dfhand,  0,    0,             /* 0x6c  */
-   NULL,             dfhand,  0,    0,             /* 0x6d  */
-   NULL,             dfhand,  0,    0,             /* 0x6e  */
-   NULL,             dfhand,  0,    0,             /* 0x6f  */
-   "\tjo",           sjhand,  2,    2,             /* 0x70  */
-   "\tjno",          sjhand,  2,    2,             /* 0x71  */
-   "\tjc",           sjhand,  2,    2,             /* 0x72  */
-   "\tjnc",          sjhand,  2,    2,             /* 0x73  */
-   "\tjz",           sjhand,  2,    2,             /* 0x74  */
-   "\tjnz",          sjhand,  2,    2,             /* 0x75  */
-   "\tjna",          sjhand,  2,    2,             /* 0x76  */
-   "\tja",           sjhand,  2,    2,             /* 0x77  */
-   "\tjs",           sjhand,  2,    2,             /* 0x78  */
-   "\tjns",          sjhand,  2,    2,             /* 0x79  */
-   "\tjp",           sjhand,  2,    2,             /* 0x7a  */
-   "\tjnp",          sjhand,  2,    2,             /* 0x7b  */
-   "\tjl",           sjhand,  2,    2,             /* 0x7c  */
-   "\tjnl",          sjhand,  2,    2,             /* 0x7d  */
-   "\tjng",          sjhand,  2,    2,             /* 0x7e  */
-   "\tjg",           sjhand,  2,    2,             /* 0x7f  */
-   AMBIG,            imhand,  3,    5,             /* 0x80  */
-   AMBIG,            imhand,  4,    6,             /* 0x81  */
-   AMBIG,            imhand,  3,    5,             /* 0x82  */
-   AMBIG,            imhand,  3,    5,             /* 0x83  */
-   TEST,             mvhand,  2,    4,             /* 0x84  */
-   TEST,             mvhand,  2,    4,             /* 0x85  */
-   "\txchg",         mvhand,  2,    4,             /* 0x86  */
-   "\txchg",         mvhand,  2,    4,             /* 0x87  */
-   MOV,              mvhand,  2,    4,             /* 0x88  */
-   MOV,              mvhand,  2,    4,             /* 0x89  */
-   MOV,              mvhand,  2,    4,             /* 0x8a  */
-   MOV,              mvhand,  2,    4,             /* 0x8b  */
-   MOV,              mshand,  2,    4,             /* 0x8c  */
-   "\tlea",          mvhand,  2,    4,             /* 0x8d  */
-   MOV,              mshand,  2,    4,             /* 0x8e  */
-   "\tpop",          pohand,  2,    4,             /* 0x8f  */
-   "\tnop",          sbhand,  1,    1,             /* 0x90  */
-   "\txchg\tax,cx",  sbhand,  1,    1,             /* 0x91  */
-   "\txchg\tax,dx",  sbhand,  1,    1,             /* 0x92  */
-   "\txchg\tax,bx",  sbhand,  1,    1,             /* 0x93  */
-   "\txchg\tax,sp",  sbhand,  1,    1,             /* 0x94  */
-   "\txchg\tax,bp",  sbhand,  1,    1,             /* 0x95  */
-   "\txchg\tax,si",  sbhand,  1,    1,             /* 0x96  */
-   "\txchg\tax,di",  sbhand,  1,    1,             /* 0x97  */
-   "\tcbw",          sbhand,  1,    1,             /* 0x98  */
-   "\tcwd",          sbhand,  1,    1,             /* 0x99  */
-   "\tcalli",        cihand,  5,    5,             /* 0x9a  */
-   "\twait",         sbhand,  1,    1,             /* 0x9b  */
-   "\tpushf",        sbhand,  1,    1,             /* 0x9c  */
-   "\tpopf",         sbhand,  1,    1,             /* 0x9d  */
-   "\tsahf",         sbhand,  1,    1,             /* 0x9e  */
-   "\tlahf",         sbhand,  1,    1,             /* 0x9f  */
-   MOV,              mqhand,  3,    3,             /* 0xa0  */
-   MOV,              mqhand,  3,    3,             /* 0xa1  */
-   MOV,              mqhand,  3,    3,             /* 0xa2  */
-   MOV,              mqhand,  3,    3,             /* 0xa3  */
-   "\tmovb",         sbhand,  1,    1,             /* 0xa4  */
-   "\tmovw",         sbhand,  1,    1,             /* 0xa5  */
-   "\tcmpb",         sbhand,  1,    1,             /* 0xa6  */
-   "\tcmpw",         sbhand,  1,    1,             /* 0xa7  */
-   TEST,             tqhand,  2,    2,             /* 0xa8  */
-   TEST,             tqhand,  3,    3,             /* 0xa9  */
-   "\tstob",         sbhand,  1,    1,             /* 0xaa  */
-   "\tstow",         sbhand,  1,    1,             /* 0xab  */
-   "\tlodb",         sbhand,  1,    1,             /* 0xac  */
-   "\tlodw",         sbhand,  1,    1,             /* 0xad  */
-   "\tscab",         sbhand,  1,    1,             /* 0xae  */
-   "\tscaw",         sbhand,  1,    1,             /* 0xaf  */
-   "\tmov\tal,",     mihand,  2,    2,             /* 0xb0  */
-   "\tmov\tcl,",     mihand,  2,    2,             /* 0xb1  */
-   "\tmov\tdl,",     mihand,  2,    2,             /* 0xb2  */
-   "\tmov\tbl,",     mihand,  2,    2,             /* 0xb3  */
-   "\tmov\tah,",     mihand,  2,    2,             /* 0xb4  */
-   "\tmov\tch,",     mihand,  2,    2,             /* 0xb5  */
-   "\tmov\tdh,",     mihand,  2,    2,             /* 0xb6  */
-   "\tmov\tbh,",     mihand,  2,    2,             /* 0xb7  */
-   "\tmov\tax,",     mihand,  3,    3,             /* 0xb8  */
-   "\tmov\tcx,",     mihand,  3,    3,             /* 0xb9  */
-   "\tmov\tdx,",     mihand,  3,    3,             /* 0xba  */
-   "\tmov\tbx,",     mihand,  3,    3,             /* 0xbb  */
-   "\tmov\tsp,",     mihand,  3,    3,             /* 0xbc  */
-   "\tmov\tbp,",     mihand,  3,    3,             /* 0xbd  */
-   "\tmov\tsi,",     mihand,  3,    3,             /* 0xbe  */
-   "\tmov\tdi,",     mihand,  3,    3,             /* 0xbf  */
-   NULL,             dfhand,  0,    0,             /* 0xc0  */
-   NULL,             dfhand,  0,    0,             /* 0xc1  */
-   "\tret",          rehand,  3,    3,             /* 0xc2  */
-   "\tret",          sbhand,  1,    1,             /* 0xc3  */
-   "\tles",          mvhand,  2,    4,             /* 0xc4  */
-   "\tlds",          mvhand,  2,    4,             /* 0xc5  */
-   MOV,              mmhand,  3,    5,             /* 0xc6  */
-   MOV,              mmhand,  4,    6,             /* 0xc7  */
-   NULL,             dfhand,  0,    0,             /* 0xc8  */
-   NULL,             dfhand,  0,    0,             /* 0xc9  */
-   "\treti",         rehand,  3,    3,             /* 0xca  */
-   "\treti",         sbhand,  1,    1,             /* 0xcb  */
-   "\tint",          sbhand,  1,    1,             /* 0xcc  */
-   "\tint",          inhand,  2,    2,             /* 0xcd  */
-   "\tinto",         sbhand,  1,    1,             /* 0xce  */
-   "\tiret",         sbhand,  1,    1,             /* 0xcf  */
-   AMBIG,            srhand,  2,    4,             /* 0xd0  */
-   AMBIG,            srhand,  2,    4,             /* 0xd1  */
-   AMBIG,            srhand,  2,    4,             /* 0xd2  */
-   AMBIG,            srhand,  2,    4,             /* 0xd3  */
-   "\taam",          aahand,  2,    2,             /* 0xd4  */
-   "\taad",          aahand,  2,    2,             /* 0xd5  */
-   NULL,             dfhand,  0,    0,             /* 0xd6  */
-   "\txlat",         sbhand,  1,    1,             /* 0xd7  */
-   ESC,              eshand,  2,    2,             /* 0xd8  */
-   ESC,              eshand,  2,    2,             /* 0xd9  */
-   ESC,              eshand,  2,    2,             /* 0xda  */
-   ESC,              eshand,  2,    2,             /* 0xdb  */
-   ESC,              eshand,  2,    2,             /* 0xdc  */
-   ESC,              eshand,  2,    2,             /* 0xdd  */
-   ESC,              eshand,  2,    2,             /* 0xde  */
-   ESC,              eshand,  2,    2,             /* 0xdf  */
-   "\tloopne",       sjhand,  2,    2,             /* 0xe0  */
-   "\tloope",        sjhand,  2,    2,             /* 0xe1  */
-   "\tloop",         sjhand,  2,    2,             /* 0xe2  */
-   "\tjcxz",         sjhand,  2,    2,             /* 0xe3  */
-   "\tin",           iohand,  2,    2,             /* 0xe4  */
-   "\tinw",          iohand,  2,    2,             /* 0xe5  */
-   "\tout",          iohand,  2,    2,             /* 0xe6  */
-   "\toutw",         iohand,  2,    2,             /* 0xe7  */
-   "\tcall",         ljhand,  3,    3,             /* 0xe8  */
-   "\tjmp",          ljhand,  3,    3,             /* 0xe9  */
-   "\tjmpi",         cihand,  5,    5,             /* 0xea  */
-   "\tj",            sjhand,  2,    2,             /* 0xeb  */
-   "\tin",           sbhand,  1,    1,             /* 0xec  */
-   "\tinw",          sbhand,  1,    1,             /* 0xed  */
-   "\tout",          sbhand,  1,    1,             /* 0xee  */
-   "\toutw",         sbhand,  1,    1,             /* 0xef  */
-   "\tlock",         sbhand,  1,    1,             /* 0xf0  */
-   NULL,             dfhand,  0,    0,             /* 0xf1  */
-   "\trepnz",        sbhand,  1,    1,             /* 0xf2  */
-   "\trepz",         sbhand,  1,    1,             /* 0xf3  */
-   "\thlt",          sbhand,  1,    1,             /* 0xf4  */
-   "\tcmc",          sbhand,  1,    1,             /* 0xf5  */
-   AMBIG,            mahand,  2,    5,             /* 0xf6  */
-   AMBIG,            mahand,  2,    6,             /* 0xf7  */
-   "\tclc",          sbhand,  1,    1,             /* 0xf8  */
-   "\tstc",          sbhand,  1,    1,             /* 0xf9  */
-   "\tcli",          sbhand,  1,    1,             /* 0xfa  */
-   "\tsti",          sbhand,  1,    1,             /* 0xfb  */
-   "\tcld",          sbhand,  1,    1,             /* 0xfc  */
-   "\tstd",          sbhand,  1,    1,             /* 0xfd  */
-   AMBIG,            mjhand,  2,    4,             /* 0xfe  */
-   AMBIG,            mjhand,  2,    4              /* 0xff  */
-   };
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This simple routine  returns the name field of a symbol *
-  * table entry as a printable string.                      *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-char *
-getnam(k)
-
-   register int k;
-
-{/* * * * * * * * * *  START OF getnam()  * * * * * * * * * */
-
-   register int j;
-   static char a[9];
-
-   for (j = 0; j < 8; ++j)
-      if ( ! symtab[k].n_name[j] )
-         break;
-      else
-         a[j] = symtab[k].n_name[j];
-
-   a[j] = '\0';
-
-   return (a);
-
-}/* * * * * * * * * * * END OF getnam() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This function is  responsible  for mucking  through the *
-  * relocation  table in  search of  externally  referenced *
-  * symbols to be output as  operands.  It accepts two long *
-  * arguments: the code-segment location at which an extern *
-  * reference  is  expected,  and the offset value which is *
-  * embedded  in the  object  code and used at link time to *
-  * bias the external value.  In the most typical case, the *
-  * function will be called by lookup(), which always makes *
-  * a check for external names before  searching the symbol *
-  * table proper.  However,  it may also be called directly *
-  * by any function  (such as the  move-immediate  handler) *
-  * which wants to make an independent check for externals. *
-  * The caller is expected to supply, as the third argument *
-  * to the function,  a pointer to a character buffer large *
-  * enough to hold any possible  output  string.  Lookext() *
-  * will fill this  buffer and return a logical  TRUE if it *
-  * finds an extern reference;  otherwise, it will return a *
-  * logical FALSE, leaving the buffer undisturbed.          *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-int
-lookext(off,loc,buf)
-
-   long off, loc;
-   char *buf;
-
-{/* * * * * * * * * * START OF  lookext() * * * * * * * * * */
-
-   register int k;
-   char c[16];
-
-   if ((loc != -1L) && (relptr >= 0))
-      for (k = 0; k <= relptr; ++k)
-         if ((relo[k].r_vaddr == loc)
-          && (relo[k].r_symndx < S_BSS))
-            {
-            strcpy(buf,getnam(relo[k].r_symndx));
-            if (off)
-               {
-               if (off < 0)
-                  sprintf(c,"%ld",off);
-               else
-                  sprintf(c,"+%ld",off);
-               strcat(buf,c);
-               }
-            return (1);
-            }
-
-   return (0);
-
-}/* * * * * * * * * *  END OF  lookext()  * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This  function  finds an entry in the  symbol  table by *
-  * value.  Its input is a (long) machine address,  and its *
-  * output is a pointer to a string  containing  the corre- *
-  * sponding symbolic name. The function first searches the *
-  * relocation table for a possible external reference;  if *
-  * none is found,  a linear  search of the symbol table is *
-  * undertaken. If no matching symbol has been found at the *
-  * end of these searches,  the function  returns a pointer *
-  * to a string  containing the ASCII equivalent of the ad- *
-  * dress which was to be located,  so that,  regardless of *
-  * the success of the search,  the function's return value *
-  * is suitable for use as a memory-reference operand.  The *
-  * caller specifies the type of symbol to be found  (text, *
-  * data, bss, undefined,  absolute, or common) by means of *
-  * the function's  second  parameter.  The third parameter *
-  * specifies  the  format to be used in the event of a nu- *
-  * meric output:  zero for absolute format,  one for short *
-  * relative  format,  two for long  relative  format.  The *
-  * fourth  parameter is the address  which would appear in *
-  * the relocation table for the reference in question,  or *
-  * -1 if the relocation  table is not to be searched.  The *
-  * function attempts to apply a certain amount of intelli- *
-  * gence in its  selection  of symbols,  so it is possible *
-  * that,  in the absence of a type match,  a symbol of the *
-  * correct value but different type will be returned.      *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-char *
-lookup(addr,type,kind,ext)
-
-   long addr;              /* Machine address to be located */
-
-   int type,               /* Type of symbol to be matched  */
-       kind;               /* Addressing output mode to use */
-
-   long ext;               /* Value for extern ref, if any  */
-
-{/* * * * * * * * * *  START OF lookup()  * * * * * * * * * */
-
-   register int j, k;
-   static char b[64];
-
-   struct
-      {
-      int   i;
-      int   t;
-      }
-   best;
-
-   if (lookext(addr,ext,b))
-      return (b);
-
-   if (segflg)
-      if (segflg & 1)
-         type = N_TEXT;
-      else
-         type = N_DATA;
-
-   for (k = 0, best.i = -1; k <= symptr; ++k)
-      if (symtab[k].n_value == addr)
-         if ((j = symtab[k].n_sclass & N_SECT) == type)
-            {
-            best.t = j;
-            best.i = k;
-            break;
-            }
-         else if (segflg || (HDR.a_flags & A_SEP))
-            continue;
-         else if (best.i < 0)
-            best.t = j, best.i = k;
-         else if (symrank[type][j] > symrank[type][best.t])
-            best.t = j, best.i = k;
-
-   if (best.i >= 0)
-      return (getnam(best.i));
-
-   if (kind == LOOK_ABS)
-      sprintf(b,"0x%05.5x",addr);
-   else
-      {
-      long x = addr - (PC - kind);
-      if (x < 0)
-         sprintf(b,".%ld",x);
-      else
-         sprintf(b,".+%ld",x);
-      }
-
-   return (b);
-
-}/* * * * * * * * * * * END OF lookup() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This function  translates an 8088  addressing mode byte *
-  * to an equivalent assembler string,  returning a pointer *
-  * thereto.  If necessary,  it performs  successive inputs *
-  * of bytes from the object file in order to obtain offset *
-  * data,  adjusting PC  accordingly.  (The addressing mode *
-  * byte  appears in several  8088  opcodes;  it is used to *
-  * specify source and destination operand locations.)  The *
-  * third  argument to the function is zero if the standard *
-  * registers are to be used,  or eight if the segment reg- *
-  * isters are to be used; these constants are defined sym- *
-  * bolically in dis.h.  NOTE:  The mtrans()  function must *
-  * NEVER be called except  immediately  after fetching the *
-  * mode byte.  If any additional  object bytes are fetched *
-  * after  the fetch of the mode  byte,  mtrans()  will not *
-  * produce correct output!                                 *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-char *
-mtrans(c,m,type)
-
-   register int c;            /* Primary instruction byte   */
-   register int m;            /* Addressing mode byte       */
-
-   int type;                  /* Type code: standard or seg */
-
-{/* * * * * * * * * *  START OF mtrans()  * * * * * * * * * */
-
-   unsigned long pc;
-   int offset, oflag, dir, w, mod, reg, rm;
-   static char a[100];
-   static char b[30];
-
-   offset = 0;
-   dir = c & 2;
-   w = c & 1;
-   mod = (m & 0xc0) >> 6;
-   reg = (m & 0x38) >> 3;
-   rm = m & 7;
-   pc = PC + 1;
-
-   if (type)
-      w = 1;
-
-   if ((oflag = mod) > 2)
-      oflag = 0;
-
-   if (oflag)
-      {
-      int j, k;
-      if (oflag == 2)
-         {
-         FETCH(j);
-         FETCH(k);
-         offset = (k << 8) | j;
-         }
-      else
-         {
-         FETCH(j);
-         if (j & 0x80)
-            k = 0xff00;
-         else
-            k = 0;
-         offset = k | j;
-         }
-      }
-
-   if (dir)
-      {
-      strcpy(a,REGS[type + ((w << 3) | reg)]);
-      strcat(a,",");
-      switch (mod)
-         {
-         case 0 :
-            if (rm == 6)
-               {
-               int j, k;
-               FETCH(j);
-               FETCH(k);
-               offset = (k << 8) | j;
-               strcat(a,
-                lookup((long)(offset),N_DATA,LOOK_ABS,pc));
-               }
-            else
-               {
-               sprintf(b,"(%s)",REGS0[rm]);
-               strcat(a,b);
-               }
-            break;
-         case 1 :
-         case 2 :
-            if (mod == 1)
-               strcat(a,"*");
-            else
-               strcat(a,"#");
-            sprintf(b,"%d(",offset);
-            strcat(a,b);
-            strcat(a,REGS1[rm]);
-            strcat(a,")");
-            break;
-         case 3 :
-            strcat(a,REGS[(w << 3) | rm]);
-            break;
-         }
-      }
-   else
-      {
-      switch (mod)
-         {
-         case 0 :
-            if (rm == 6)
-               {
-               int j, k;
-               FETCH(j);
-               FETCH(k);
-               offset = (k << 8) | j;
-               strcpy(a,
-                lookup((long)(offset),N_DATA,LOOK_ABS,pc));
-               }
-            else
-               {
-               sprintf(b,"(%s)",REGS0[rm]);
-               strcpy(a,b);
-               }
-            break;
-         case 1 :
-         case 2 :
-            if (mod == 1)
-               strcpy(a,"*");
-            else
-               strcpy(a,"#");
-            sprintf(b,"%d(",offset);
-            strcat(a,b);
-            strcat(a,REGS1[rm]);
-            strcat(a,")");
-            break;
-         case 3 :
-            strcpy(a,REGS[(w << 3) | rm]);
-            break;
-         }
-      strcat(a,",");
-      strcat(a,REGS[type + ((w << 3) | reg)]);
-      }
-
-   return (a);
-
-}/* * * * * * * * * * * END OF mtrans() * * * * * * * * * * */
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-  *                                                         *
-  * This simple routine  truncates a string returned by the *
-  * mtrans() function, removing its source operand. This is *
-  * useful in handlers which ignore the "reg"  field of the *
-  * mode byte.                                              *
-  *                                                         *
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-void
-mtrunc(a)
-
-   register char *a;          /* Ptr. to string to truncate */
-
-{/* * * * * * * * * *  START OF mtrunc()  * * * * * * * * * */
-
-   register int k;
-
-   for (k = strlen(a) - 1; k >= 0; --k)
-      if (a[k] == ',')
-         {
-         a[k] = '\0';
-         break;
-         }
-
-}/* * * * * * * * * * * END OF mtrunc() * * * * * * * * * * */
-
-
-
Index: trunk/minix/commands/elle/Makefile
===================================================================
--- trunk/minix/commands/elle/Makefile	(revision 9)
+++ 	(revision )
@@ -1,57 +1,0 @@
-# Makefile for elle
-
-CC = exec cc
-CFLAGS = -O -DIGN_JOB_CONTROL -D_POSIX_SOURCE -wa
-LDFLAGS= -i
-
-all:	elle ellec
-
-OBJ = eemain.o eecmds.o eesite.o eevini.o eedisp.o eeterm.o eeerr.o  \
-      eeques.o eebuff.o eefile.o eefed.o eeedit.o eebit.o eef1.o \
-      eef2.o eefd.o eehelp.o eekmac.o eef3.o eesrch.o eequer.o \
-      eefill.o eediag.o sbstr.o sbm.o sberr.o sbbcpy.o
-
-# It probably isn't necessary to make all this stuff all the time, but it
-# is fairly easy and makes the whole process simpler.  If this is not done,
-# the dependencies are very complicated because some of the .c and .h files
-# are made dynamically.
-elle:	ellec $(OBJ) $(FUN_OFILES) elle.h eesite.h
-#	$(CC) $(CFLAGS) -c defprf.c	# depends on the new *.h files
-	$(CC) $(LDFLAGS) -o $@ $(OBJ)
-	install -S 64k $@
-
-defprf.c:	deffun.e
-	cat deffun.e defprf.e | ellec -Pconf  > defprf.c
-
-eefdef.h:	deffun.e
-	cat deffun.e defprf.e | ellec -Fconf  > eefdef.h
-
-eefidx.h:	deffun.e
-	cat deffun.e defprf.e | ellec -FXconf > eefidx.h
-
-# Don't flush these files if interrupted, dammit!
-.PRECIOUS: ellec deffun.e defprf.e
-
-# The following files must be recompiled if eefidx.h is changed
-eecmds.o eebuff.o eeerr.o eehelp.o eejust.o eemain.o eeques.o eef1.o: eefidx.h
-
-# ELLE profile compiler.  
-#	Although eefdef.h and defprf.c are included by ELLEC, they
-#	are not listed as dependencies in order to avoid loops (see
-#	their target entries).  That is OK because their information is not
-#	used when generating the makecf files; it only furnishes default
-#	values needed when an ELLE user compiles a user profile.
-ellec: ellec.c
-	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ ellec.c
-	install -S 8kw $@
-
-install:	/usr/bin/elle /usr/bin/ellec
-
-/usr/bin/elle:	elle
-	install -cs -o bin elle $@
-
-/usr/bin/ellec:	ellec
-	install -cs -o bin ellec $@
-
-clean:	
-	rm -f *.o *.bak core elle ellec
Index: trunk/minix/commands/elle/build
===================================================================
--- trunk/minix/commands/elle/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/elle/deffun.e
===================================================================
--- trunk/minix/commands/elle/deffun.e	(revision 9)
+++ 	(revision )
@@ -1,201 +1,0 @@
-;;;
-;;; ELLE Master Function Definition file - "deffun.e"
-;;;
-;;;	This file serves as input to the ellec program.  It defines
-;;; all ELLE functions which may serve as keyboard-bound user commands.
-;;;
-;;; Format: (efun <Index> <Name> <Routine> <Module>)
-;;;		Index - an unique index # (used only within ELLE)
-;;;		Name - an unique string identifying this function to the user.
-;;;		Routine - the C routine implementing the function within ELLE.
-;;;		Module - the name of the C source file that the routine is in.
-;;;
-;;; The following definitions are roughly organized by object.
-;;; All functions that emulate EMACS functions are given names identical
-;;; to the EMACS function names.  For historical reasons these names
-;;; are not as consistent as they could be (sigh).
-;;; Those which have no exact counterpart in EMACS are identified by comments.
-
-(undefall)	; Ensure all predefined stuff is cleared out.
-
-; Simple Insertion
-(efun   1 "Insert Self"		f_insself	eef1)
-(efun   2 "Quoted Insert"	f_quotins	eef1)
-(efun   3 "CRLF"		f_crlf		eef1)
-
-; Characters
-(efun   4 "Forward Character"	f_fchar		eef1)
-(efun   5 "Backward Character"	f_bchar		eef1)
-(efun   6 "Delete Character"	f_dchar		eef1)
-(efun   7 "Backward Delete Character" f_bdchar	eef1)
-(efun   8 "Delete Horizontal Space" f_delspc	eef1)
-(efun   9 "Transpose Characters" f_tchars	eef1)
-
-; Words
-(efun  10 "Forward Word"	f_fword		eef1)
-(efun  11 "Backward Word"	f_bword		eef1)
-(efun  12 "Kill Word"		f_kword		eef1)
-(efun  13 "Backward Kill Word"	f_bkword	eef1)
-(efun  14 "Transpose Words"	f_twords	eef1)
-(efun  15 "Uppercase Word"	f_ucword	eef1)
-(efun  16 "Lowercase Word"	f_lcword	eef1)
-(efun  17 "Uppercase Initial"	f_uciword	eef1)
-     ; 18-19 reserved
-
-; Lines
-(efun  20 "Beginning of Line"	f_begline	eef2)
-(efun  21 "End of Line"		f_endline	eef2)
-(efun  22 "Next Line"		f_nxtline	eef2)
-(efun  23 "Previous Line"	f_prvline	eef2)
-(efun  24 "Down Real Line"	f_dnrline	eef2)
-(efun  25 "Up Real Line"	f_uprline	eef2)
-(efun  26 "Open Line"		f_oline		eef2)
-(efun  27 "Delete Blank Lines"	f_delblines	eef2)
-(efun  28 "Kill Line"		f_kline		eef2)
-(efun  29 "Backward Kill Line"	f_bkline	eef2)	; not EMACS
-(efun  30 "Goto Line"		f_goline	eef2)	; not EMACS
-     ; 31-34 reserved
-
-; Regions
-(efun  35 "Set/Pop Mark"	f_setmark	eef2)
-(efun  36 "Exchange Point and Mark" f_exchmark	eef2)
-(efun  37 "Kill Region"		f_kregion	eef2)
-(efun  38 "Copy Region"		f_copreg	eef2)
-(efun  39 "Uppercase Region"	f_ucreg		eef2)
-(efun  40 "Lowercase Region"	f_lcreg		eef2)
-(efun  41 "Fill Region"		f_fillreg	eef2)
-     ; 42-44 reserved
-
-; Paragraphs
-(efun  45 "Forward Paragraph"	f_fpara		eef2)
-(efun  46 "Backward Paragraph"	f_bpara		eef2)
-(efun  47 "Mark Paragraph"	f_mrkpara	eef2)
-(efun  48 "Fill Paragraph"	f_fillpara	eef2)
-     ; 49 reserved
-
-; Buffers
-(efun  50 "Select Buffer"	f_selbuffer	eebuff)
-(efun  51 "Select Existing Buffer" f_selxbuffer	eebuff)	; not EMACS
-(efun  52 "Kill Buffer"		f_kbuffer	eebuff)
-(efun  53 "List Buffers"	f_listbufs	eebuff)
-(efun  54 "Buffer Not Modified"	f_bufnotmod	eebuff)
-(efun  55 "EOL CRLF Mode"	f_eolmode	eebuff)	; ELLE
-(efun  56 "Goto Beginning"	f_gobeg		eebuff)
-(efun  57 "Goto End"		f_goend		eebuff)
-(efun  58 "What Page"		f_whatpage	eebuff)
-     ; 59 reserved
-
-; Files
-(efun  60 "Find File"		f_ffile		eefile)
-(efun  61 "Read File"		f_rfile		eefile)
-(efun  62 "Visit File"		f_vfile		eefile)
-(efun  63 "Insert File"		f_ifile		eefile)
-(efun  64 "Save File"		f_sfile		eefile)
-(efun  65 "Save All Files"	f_savefiles	eebuff)
-(efun  66 "Write File"		f_wfile		eefile)
-(efun  67 "Write Region"	f_wreg		eefile)
-(efun  68 "Write Last Kill"	f_wlastkill	eefile)	; not EMACS
-     ; 69 reserved
-
-; Windows
-(efun  70 "Two Windows"		f_2winds	eebuff)
-(efun  71 "One Window"		f_1wind		eebuff)
-(efun  72 "Other Window"	f_othwind	eebuff)
-(efun  73 "Grow Window"		f_growind	eebuff)
-(efun  74 "Shrink Window"	f_shrinkwind	eebuff)	; not EMACS	
-(efun  75 "Delete Window"	f_delwind	eebuff)	; not EMACS
-(efun  76 "Standout Window"	f_sowind	eebuff)	; ELLE
-(efun  77 "Two Mode Windows"	f_2modewinds	eebuff)	; ELLE
-
-; Window Positioning
-(efun  78 "New Window"		f_newwin	eefd)
-(efun  79 "Next Screen"		f_nscreen	eefd)
-(efun  80 "Previous Screen"	f_pscreen	eefd)
-(efun  81 "Other New Screen"	f_othnscreen	eefd)	; not EMACS
-(efun  82 "Line to Window Border" f_lwindbord	eefd)	; not EMACS
-(efun  83 "Scroll Window Up"	f_scupwind	eefd)	; not EMACS
-(efun  84 "Scroll Window Down"	f_scdnwind	eefd)	; not EMACS
-(efun  85 "Move to Window Top"	f_mvwtop	eefd)	; not EMACS
-(efun  86 "Move to Window Bottom" f_mvwbot	eefd)	; not EMACS
-     ; 87-89 reserved
-
-; Command Input
-(efun  90 "Set Profile"		f_setprof	eecmds)	; ELLE
-(efun  91 "Prefix Meta"		f_pfxmeta	eecmds)
-(efun  92 "Prefix Extend"	f_pfxext	eecmds)
-(efun  93 "Universal Arg"	f_uarg		eecmds)
-(efun  94 "Negative Argument"	f_negarg	eecmds)
-(efun  95 "Argument Digit"	f_argdig	eecmds)
-(efun  96 "VT100 Button Hack"	f_vtbuttons	eecmds)	; not EMACS
-
-; Help
-(efun  97 "Describe"		f_describe	eehelp)
-     ; 98-99 reserved
-
-; Keyboard Macros
-(efun 100 "Start Kbd Macro"	f_skmac		eekmac)
-(efun 101 "End Kbd Macro"	f_ekmac		eekmac)
-(efun 102 "Execute Kbd Macro"	f_xkmac		eekmac)
-(efun 103 "View Kbd Macro"	f_vkmac		eekmac)
-    ; 104 reserved
-
-; Killing
-(efun 105 "Un-kill"		f_unkill	eef3)
-(efun 106 "Un-kill Pop"		f_unkpop	eef3)
-(efun 107 "Append Next Kill"	f_appnkill	eef3)
-    ; 108-109 reserved
-
-; Searching
-(efun 110 "String Search"	f_srch		eesrch)
-(efun 111 "Reverse String Search" f_rsrch	eesrch)
-(efun 112 "Incremental Search"	f_isrch		eesrch)
-(efun 113 "Reverse Search"	f_risrch	eesrch)
-
-; Query Replace & friends
-(efun 114 "Replace String"	f_repstr	eequer)
-(efun 115 "Query Replace"	f_querep	eequer)
-(efun 116 "Replace in Line"	f_repline	eequer)	; not EMACS
-
-; Fill Mode
-(efun 117 "Set Fill Column"	f_sfcol		eefill)
-(efun 118 "Set Fill Prefix"	f_sfpref	eefill)
-(efun 119 "Auto Fill Mode"	f_fillmode	eefill)
-(efun 120 "Text Mode"		f_textmode	eefill)	; IMAGEN
-
-; Indentation
-(efun 121 "Indent According to Mode" f_indatm	eef3)
-(efun 122 "Indent New Line"	f_indnl		eef3)
-(efun 123 "Back to Indentation"	f_backind	eef3)
-(efun 124 "Indent for Comment"	f_indcomm	eef3)
-(efun 125 "Indent Relative"	f_indrel	eef3)
-	; 126-128 reserved
-
-; Miscellaneous
-(efun 129 "Match Bracket"	f_matchbrack	eef3)	; not EMACS 
-
-; Process Control
-(efun 130 "Push to Inferior"	f_pshinf	eemain)
-(efun 131 "Return to Superior"	f_retsup	eemain)
-(efun 132 "Write File Exit"	f_wfexit	eemain)	; not EMACS
-    ; 133-139 reserved
-
-; ELLE Debugging
-(efun 140 "Hit Breakpoint"	f_bkpt		eeerr)	; ELLE
-(efun 141 "Debug Mode"		f_debug		eediag)	; ELLE
-    ; 142-149 reserved
-;---------------------------------------------------------------
-
-; IMAGEN configuration only
-(efun 150 "Execute Unix Command" f_xucmd	eemake)	; IMAGEN
-(efun 151 "Execute Make"	f_make		eemake)	; IMAGEN
-(efun 152 "Find Next Error"	f_nxterr	eemake)	; IMAGEN
-
-; ICONOGRAPHICS-specific
-(efun 153 "ICO Extend Command"	f_icoxcmd	eefico)	; ICONOGRAPHICS
-(efun 154 "ICO Typeset Funs"	f_icotypfns	eefico)	; ICONOGRAPHICS
-(efun 155 "ICO Spec Input Funs" f_icospifns	eefico) ; ICONOGRAPHICS
-
-; SUN Mouse functions
-(efun 156 "Stuff Selection"	f_stuffsel	eesun)	; SUN
-(efun 157 "Select Region"	f_selregion	eesun)	; SUN
-
Index: trunk/minix/commands/elle/defprf.c
===================================================================
--- trunk/minix/commands/elle/defprf.c	(revision 9)
+++ 	(revision )
@@ -1,231 +1,0 @@
-/* This file defines the initial data for ELLE's default user profile.
-** It is automatically generated by ELLEC, and should not be edited.
-*/
-char charmap[] = {
-	35,	/* (  0)  ^@  Set/Pop Mark */
-	20,	/* (  1)  ^A  Beginning of Line */
-	 5,	/* (  2)  ^B  Backward Character */
-	 0,	/* (  3)  ^C  unknown function */
-	 6,	/* (  4)  ^D  Delete Character */
-	21,	/* (  5)  ^E  End of Line */
-	 4,	/* (  6)  ^F  Forward Character */
-	 0,	/* (  7)  ^G  unknown function */
-	 5,	/* ( 10)  ^H  Backward Character */
-	121,	/* ( 11)  ^I  Indent According to Mode */
-	122,	/* ( 12)  ^J  Indent New Line */
-	28,	/* ( 13)  ^K  Kill Line */
-	78,	/* ( 14)  ^L  New Window */
-	 3,	/* ( 15)  ^M  CRLF */
-	24,	/* ( 16)  ^N  Down Real Line */
-	26,	/* ( 17)  ^O  Open Line */
-	25,	/* ( 20)  ^P  Up Real Line */
-	 2,	/* ( 21)  ^Q  Quoted Insert */
-	113,	/* ( 22)  ^R  Reverse Search */
-	112,	/* ( 23)  ^S  Incremental Search */
-	 9,	/* ( 24)  ^T  Transpose Characters */
-	93,	/* ( 25)  ^U  Universal Arg */
-	79,	/* ( 26)  ^V  Next Screen */
-	37,	/* ( 27)  ^W  Kill Region */
-	92,	/* ( 30)  ^X  Prefix Extend */
-	105,	/* ( 31)  ^Y  Un-kill */
-	 0,	/* ( 32)  ^Z  unknown function */
-	91,	/* ( 33)  ^[  Prefix Meta */
-	141,	/* ( 34)  ^\  Debug Mode */
-	 0,	/* ( 35)  ^]  unknown function */
-	140,	/* ( 36)  ^^  Hit Breakpoint */
-	97,	/* ( 37)  ^_  Describe */
-	 1,	/* ( 40)      Insert Self */
-	 1,	/* ( 41)   !  Insert Self */
-	 1,	/* ( 42)   "  Insert Self */
-	 1,	/* ( 43)   #  Insert Self */
-	 1,	/* ( 44)   $  Insert Self */
-	 1,	/* ( 45)   %  Insert Self */
-	 1,	/* ( 46)   &  Insert Self */
-	 1,	/* ( 47)   '  Insert Self */
-	 1,	/* ( 50)   (  Insert Self */
-	 1,	/* ( 51)   )  Insert Self */
-	 1,	/* ( 52)   *  Insert Self */
-	 1,	/* ( 53)   +  Insert Self */
-	 1,	/* ( 54)   ,  Insert Self */
-	 1,	/* ( 55)   -  Insert Self */
-	 1,	/* ( 56)   .  Insert Self */
-	 1,	/* ( 57)   /  Insert Self */
-	 1,	/* ( 60)   0  Insert Self */
-	 1,	/* ( 61)   1  Insert Self */
-	 1,	/* ( 62)   2  Insert Self */
-	 1,	/* ( 63)   3  Insert Self */
-	 1,	/* ( 64)   4  Insert Self */
-	 1,	/* ( 65)   5  Insert Self */
-	 1,	/* ( 66)   6  Insert Self */
-	 1,	/* ( 67)   7  Insert Self */
-	 1,	/* ( 70)   8  Insert Self */
-	 1,	/* ( 71)   9  Insert Self */
-	 1,	/* ( 72)   :  Insert Self */
-	 1,	/* ( 73)   ;  Insert Self */
-	 1,	/* ( 74)   <  Insert Self */
-	 1,	/* ( 75)   =  Insert Self */
-	 1,	/* ( 76)   >  Insert Self */
-	 1,	/* ( 77)   ?  Insert Self */
-	 1,	/* (100)   @  Insert Self */
-	 1,	/* (101)   A  Insert Self */
-	 1,	/* (102)   B  Insert Self */
-	 1,	/* (103)   C  Insert Self */
-	 1,	/* (104)   D  Insert Self */
-	 1,	/* (105)   E  Insert Self */
-	 1,	/* (106)   F  Insert Self */
-	 1,	/* (107)   G  Insert Self */
-	 1,	/* (110)   H  Insert Self */
-	 1,	/* (111)   I  Insert Self */
-	 1,	/* (112)   J  Insert Self */
-	 1,	/* (113)   K  Insert Self */
-	 1,	/* (114)   L  Insert Self */
-	 1,	/* (115)   M  Insert Self */
-	 1,	/* (116)   N  Insert Self */
-	 1,	/* (117)   O  Insert Self */
-	 1,	/* (120)   P  Insert Self */
-	 1,	/* (121)   Q  Insert Self */
-	 1,	/* (122)   R  Insert Self */
-	 1,	/* (123)   S  Insert Self */
-	 1,	/* (124)   T  Insert Self */
-	 1,	/* (125)   U  Insert Self */
-	 1,	/* (126)   V  Insert Self */
-	 1,	/* (127)   W  Insert Self */
-	 1,	/* (130)   X  Insert Self */
-	 1,	/* (131)   Y  Insert Self */
-	 1,	/* (132)   Z  Insert Self */
-	 1,	/* (133)   [  Insert Self */
-	 1,	/* (134)   \  Insert Self */
-	 1,	/* (135)   ]  Insert Self */
-	 1,	/* (136)   ^  Insert Self */
-	 1,	/* (137)   _  Insert Self */
-	 1,	/* (140)   `  Insert Self */
-	 1,	/* (141)   a  Insert Self */
-	 1,	/* (142)   b  Insert Self */
-	 1,	/* (143)   c  Insert Self */
-	 1,	/* (144)   d  Insert Self */
-	 1,	/* (145)   e  Insert Self */
-	 1,	/* (146)   f  Insert Self */
-	 1,	/* (147)   g  Insert Self */
-	 1,	/* (150)   h  Insert Self */
-	 1,	/* (151)   i  Insert Self */
-	 1,	/* (152)   j  Insert Self */
-	 1,	/* (153)   k  Insert Self */
-	 1,	/* (154)   l  Insert Self */
-	 1,	/* (155)   m  Insert Self */
-	 1,	/* (156)   n  Insert Self */
-	 1,	/* (157)   o  Insert Self */
-	 1,	/* (160)   p  Insert Self */
-	 1,	/* (161)   q  Insert Self */
-	 1,	/* (162)   r  Insert Self */
-	 1,	/* (163)   s  Insert Self */
-	 1,	/* (164)   t  Insert Self */
-	 1,	/* (165)   u  Insert Self */
-	 1,	/* (166)   v  Insert Self */
-	 1,	/* (167)   w  Insert Self */
-	 1,	/* (170)   x  Insert Self */
-	 1,	/* (171)   y  Insert Self */
-	 1,	/* (172)   z  Insert Self */
-	 1,	/* (173)   {  Insert Self */
-	 1,	/* (174)   |  Insert Self */
-	 1,	/* (175)   }  Insert Self */
-	 1,	/* (176)   ~  Insert Self */
-	 7,	/* (177) DEL  Backward Delete Character */
-};
- char metamap[] = {
-	02  , 86,	/* M-^B  Move to Window Bottom */
-	014 , 30,	/* M-^L  Goto Line */
-	016 , 84,	/* M-^N  Scroll Window Down */
-	020 , 83,	/* M-^P  Scroll Window Up */
-	022 ,111,	/* M-^R  Reverse String Search */
-	023 ,110,	/* M-^S  String Search */
-	024 , 85,	/* M-^T  Move to Window Top */
-	027 ,107,	/* M-^W  Append Next Kill */
-	030 , 51,	/* M-^X  Select Existing Buffer */
-	036 , 74,	/* M-^^  Shrink Window */
-	045 ,115,	/*  M-%  Query Replace */
-	055 , 94,	/*  M--  Negative Argument */
-	060 , 95,	/*  M-0  Argument Digit */
-	061 , 95,	/*  M-1  Argument Digit */
-	062 , 95,	/*  M-2  Argument Digit */
-	063 , 95,	/*  M-3  Argument Digit */
-	064 , 95,	/*  M-4  Argument Digit */
-	065 , 95,	/*  M-5  Argument Digit */
-	066 , 95,	/*  M-6  Argument Digit */
-	067 , 95,	/*  M-7  Argument Digit */
-	070 , 95,	/*  M-8  Argument Digit */
-	071 , 95,	/*  M-9  Argument Digit */
-	073 ,124,	/*  M-;  Indent for Comment */
-	074 , 56,	/*  M-<  Goto Beginning */
-	076 , 57,	/*  M->  Goto End */
-	0133, 46,	/*  M-[  Backward Paragraph */
-	0134,  8,	/*  M-\  Delete Horizontal Space */
-	0135, 45,	/*  M-]  Forward Paragraph */
-	0102, 11,	/*  M-B  Backward Word */
-	0103, 17,	/*  M-C  Uppercase Initial */
-	0104, 12,	/*  M-D  Kill Word */
-	0106, 10,	/*  M-F  Forward Word */
-	0107, 41,	/*  M-G  Fill Region */
-	0110, 47,	/*  M-H  Mark Paragraph */
-	0111,125,	/*  M-I  Indent Relative */
-	0114, 16,	/*  M-L  Lowercase Word */
-	0115,123,	/*  M-M  Back to Indentation */
-	0116, 22,	/*  M-N  Next Line */
-	0117, 96,	/*  M-O  VT100 Button Hack */
-	0120, 23,	/*  M-P  Previous Line */
-	0121, 48,	/*  M-Q  Fill Paragraph */
-	0124, 14,	/*  M-T  Transpose Words */
-	0125, 15,	/*  M-U  Uppercase Word */
-	0126, 80,	/*  M-V  Previous Screen */
-	0127, 38,	/*  M-W  Copy Region */
-	0131,106,	/*  M-Y  Un-kill Pop */
-	0176, 54,	/*  M-~  Buffer Not Modified */
-	0177, 13,	/* M-DEL  Backward Kill Word */
-};
- char extmap[] = {
-	02  , 53,	/* X-^B  List Buffers */
-	03  ,132,	/* X-^C  Write File Exit */
-	05  , 67,	/* X-^E  Write Region */
-	06  , 60,	/* X-^F  Find File */
-	013 , 68,	/* X-^K  Write Last Kill */
-	014 , 40,	/* X-^L  Lowercase Region */
-	015 , 55,	/* X-^M  EOL CRLF Mode */
-	017 , 27,	/* X-^O  Delete Blank Lines */
-	020 , 90,	/* X-^P  Set Profile */
-	022 , 61,	/* X-^R  Read File */
-	023 , 64,	/* X-^S  Save File */
-	025 , 39,	/* X-^U  Uppercase Region */
-	026 , 62,	/* X-^V  Visit File */
-	027 , 66,	/* X-^W  Write File */
-	030 , 36,	/* X-^X  Exchange Point and Mark */
-	032 ,131,	/* X-^Z  Return to Superior */
-	041 ,130,	/*  X-!  Push to Inferior */
-	044 ,116,	/*  X-$  Replace in Line */
-	045 ,114,	/*  X-%  Replace String */
-	050 ,100,	/*  X-(  Start Kbd Macro */
-	051 ,101,	/*  X-)  End Kbd Macro */
-	052 ,103,	/*  X-*  View Kbd Macro */
-	056 ,118,	/*  X-.  Set Fill Prefix */
-	060 , 75,	/*  X-0  Delete Window */
-	061 , 71,	/*  X-1  One Window */
-	062 , 70,	/*  X-2  Two Windows */
-	070 , 76,	/*  X-8  Standout Window */
-	071 , 77,	/*  X-9  Two Mode Windows */
-	075 , 58,	/*  X-=  What Page */
-	0136, 73,	/*  X-^  Grow Window */
-	0102, 50,	/*  X-B  Select Buffer */
-	0105,102,	/*  X-E  Execute Kbd Macro */
-	0106,117,	/*  X-F  Set Fill Column */
-	0111, 63,	/*  X-I  Insert File */
-	0113, 52,	/*  X-K  Kill Buffer */
-	0117, 72,	/*  X-O  Other Window */
-	0123, 65,	/*  X-S  Save All Files */
-	0124,119,	/*  X-T  Auto Fill Mode */
-	0177, 29,	/* X-DEL  Backward Kill Line */
-};
-struct profile def_prof = {
-  1, /* Ver */
-  sizeof(charmap),   charmap,
-  sizeof(metamap)/2, metamap,
-  sizeof(extmap)/2,  extmap, 
-  0, 0
-};
Index: trunk/minix/commands/elle/defprf.e
===================================================================
--- trunk/minix/commands/elle/defprf.e	(revision 9)
+++ 	(revision )
@@ -1,259 +1,0 @@
-;;;
-;;; ELLE Default Command Profile - "defprf.e"
-;;;
-;;;	This file is input to the ellec program.  It defines the default
-;;; command key bindings that ELLE uses, in the absence of an individual
-;;; user profile.
-;;;	These defaults attempt to emulate the default EMACS command key
-;;; bindings.  Differences, where known, are commented.
-;;;
-;;;	"ELLE" means the function is unique to ELLE.
-;;;	E/G: (cmd altnam) "thisname";
-;;;		"E:" refers to TOPS-20 EMACS, "G:" refers to Gnu Emacs.
-;;;		(cmd) This function exists but is bound to "cmd" instead.
-;;;		    (*) function exists but is not bound to any specific key.
-;;;		    ()  function does not exist.
-;;;		    (=) function exists, with same binding (normally omitted)
-;;;		altnam  Name by which this function is known.
-;;;		"thisname" - name of function bound to this command.
-;;;		    -    means the command is unbound (undefined).
-
-(keyallunbind)		; Flush any predefined bindings
-
-(keybind ^@ "Set/Pop Mark")
-(keybind ^A "Beginning of Line")
-(keybind ^B "Backward Character")
-; ^C not bound.  			; E: ()- G: mode-specific-command-prefix
-(keybind ^D "Delete Character")
-(keybind ^E "End of Line")
-(keybind ^F "Forward Character")
-(keybind ^H "Backward Character")	; G: (^B) help-command
-(keybind ^I "Indent According to Mode")
-(keybind ^J "Indent New Line")
-(keybind ^K "Kill Line")
-(keybind ^L "New Window")
-(keybind ^M "CRLF")
-(keybind ^N "Down Real Line")
-(keybind ^O "Open Line")
-(keybind ^P "Up Real Line")
-(keybind ^Q "Quoted Insert")
-(keybind ^R "Reverse Search")
-(keybind ^S "Incremental Search")
-(keybind ^T "Transpose Characters")
-(keybind ^U "Universal Arg")
-(keybind ^V "Next Screen")
-(keybind ^W "Kill Region")
-(keybind ^X "Prefix Extend")
-(keybind ^Y "Un-kill")
-; ^Z not bound			; E: Prefix Control-Meta;  G: suspend-emacs
-(keybind ^[ "Prefix Meta")
-(keybind "^\" "Debug Mode")	; ELLE. E: () Prefix Meta;  G: () -
-; ^] not bound.			; E+G: Abort Recursive Edit
-(keybind ^^ "Hit Breakpoint")	; ELLE. E: () Prefix Control;  G: () -
-(keybind ^_ "Describe")		; E: (M-?) Help;  G: (^H-k) undo
-(keybind " " "Insert Self")
-(keybind ! "Insert Self")
-(keybind """" "Insert Self")
-(keybind # "Insert Self")
-(keybind $ "Insert Self")
-(keybind % "Insert Self")
-(keybind & "Insert Self")
-(keybind ' "Insert Self")
-(keybind "(" "Insert Self")
-(keybind ")" "Insert Self")
-(keybind * "Insert Self")
-(keybind + "Insert Self")
-(keybind , "Insert Self")
-(keybind - "Insert Self")
-(keybind . "Insert Self")
-(keybind / "Insert Self")
-(keybind 0 "Insert Self")
-(keybind 1 "Insert Self")
-(keybind 2 "Insert Self")
-(keybind 3 "Insert Self")
-(keybind 4 "Insert Self")
-(keybind 5 "Insert Self")
-(keybind 6 "Insert Self")
-(keybind 7 "Insert Self")
-(keybind 8 "Insert Self")
-(keybind 9 "Insert Self")
-(keybind : "Insert Self")
-(keybind ";" "Insert Self")
-(keybind < "Insert Self")
-(keybind = "Insert Self")
-(keybind > "Insert Self")
-(keybind ? "Insert Self")
-(keybind @ "Insert Self")
-(keybind A "Insert Self")
-(keybind B "Insert Self")
-(keybind C "Insert Self")
-(keybind D "Insert Self")
-(keybind E "Insert Self")
-(keybind F "Insert Self")
-(keybind G "Insert Self")
-(keybind H "Insert Self")
-(keybind I "Insert Self")
-(keybind J "Insert Self")
-(keybind K "Insert Self")
-(keybind L "Insert Self")
-(keybind M "Insert Self")
-(keybind N "Insert Self")
-(keybind O "Insert Self")
-(keybind P "Insert Self")
-(keybind Q "Insert Self")
-(keybind R "Insert Self")
-(keybind S "Insert Self")
-(keybind T "Insert Self")
-(keybind U "Insert Self")
-(keybind V "Insert Self")
-(keybind W "Insert Self")
-(keybind X "Insert Self")
-(keybind Y "Insert Self")
-(keybind Z "Insert Self")
-(keybind [ "Insert Self")
-(keybind "\" "Insert Self")
-(keybind ] "Insert Self")
-(keybind ^ "Insert Self")
-(keybind _ "Insert Self")
-(keybind ` "Insert Self")
-(keybind a "Insert Self")
-(keybind b "Insert Self")
-(keybind c "Insert Self")
-(keybind d "Insert Self")
-(keybind e "Insert Self")
-(keybind f "Insert Self")
-(keybind g "Insert Self")
-(keybind h "Insert Self")
-(keybind i "Insert Self")
-(keybind j "Insert Self")
-(keybind k "Insert Self")
-(keybind l "Insert Self")
-(keybind m "Insert Self")
-(keybind n "Insert Self")
-(keybind o "Insert Self")
-(keybind p "Insert Self")
-(keybind q "Insert Self")
-(keybind r "Insert Self")
-(keybind s "Insert Self")
-(keybind t "Insert Self")
-(keybind u "Insert Self")
-(keybind v "Insert Self")
-(keybind w "Insert Self")
-(keybind x "Insert Self")
-(keybind y "Insert Self")
-(keybind z "Insert Self")
-(keybind { "Insert Self")
-(keybind | "Insert Self")
-(keybind } "Insert Self")
-(keybind ~ "Insert Self")
-(keybind DEL "Backward Delete Character")
-
-; Meta chars
-
-(keybind M-^B "Move to Window Bottom")	; ELLE (ima). E+G:()-
-(keybind M-^L "Goto Line")		; E:();  G:(* goto-line) -
-(keybind M-^N "Scroll Window Down")	; ELLE (ima). E+G:()- forward-list
-(keybind M-^P "Scroll Window Up")	; ELLE (ima). E+G:()- backward-list
-(keybind M-^R "Reverse String Search")	; E:(*); G:(* search-backward) -
-(keybind M-^S "String Search")		; E:(*); G:(* search-forward) isearch-forward-regexp
-(keybind M-^T "Move to Window Top")	; ELLE (ima). E+G:()-
-(keybind M-^W "Append Next Kill")
-(keybind M-^X "Select Existing Buffer")	; ELLE (ima). E+G:()-
-(keybind M-^^ "Shrink Window")		; ELLE (ima). E+G:()-
-(keybind M-% "Query Replace")
-(keybind M-- "Negative Argument")
-(keybind M-0 "Argument Digit")
-(keybind M-1 "Argument Digit")
-(keybind M-2 "Argument Digit")
-(keybind M-3 "Argument Digit")
-(keybind M-4 "Argument Digit")
-(keybind M-5 "Argument Digit")
-(keybind M-6 "Argument Digit")
-(keybind M-7 "Argument Digit")
-(keybind M-8 "Argument Digit")
-(keybind M-9 "Argument Digit")
-(keybind "M-;" "Indent for Comment")
-(keybind M-< "Goto Beginning")
-(keybind M-> "Goto End")
-(keybind M-[ "Backward Paragraph")
-(keybind "M-\" "Delete Horizontal Space")
-(keybind M-] "Forward Paragraph")
-(keybind M-B "Backward Word")
-(keybind M-C "Uppercase Initial")
-(keybind M-D "Kill Word")
-(keybind M-F "Forward Word")
-(keybind M-G "Fill Region")
-(keybind M-H "Mark Paragraph")
-(keybind M-I "Indent Relative")		; E+G: (*) Tab to Tab Stop
-(keybind M-L "Lowercase Word")
-(keybind M-M "Back to Indentation")
-(keybind M-N  "Next Line")		; E:(*); G:(* forward-line) -
-(keybind M-O "VT100 button hack")	; ELLE. E+G: () -
-(keybind M-P  "Previous Line")		; E:(*); G:() -
-(keybind M-Q "Fill Paragraph")
-(keybind M-T "Transpose Words")
-(keybind M-U "Uppercase Word")
-(keybind M-V "Previous Screen")
-(keybind M-W "Copy Region")
-(keybind M-Y "Un-kill Pop")
-(keybind M-~ "Buffer Not Modified")
-(keybind M-DEL "Backward Kill Word")
-
-; Extended commands
-
-(keybind X-^B "List Buffers")
-(keybind X-^C "Write File Exit")	; ELLE (ima). E:()-; G: (= save-buffers-kill-emacs)
-(keybind X-^E "Write Region")		; E:(*)-;    G:(*) eval-last-sexp
-(keybind X-^F "Find File")
-(keybind X-^K "Write Last Kill")	; ELLE (mnx). E+G:()-
-(keybind X-^L "Lowercase Region")
-(keybind X-^M "EOL CRLF Mode")		; ELLE.  E+G: ()-
-(keybind X-^O "Delete Blank Lines")
-(keybind X-^P "Set Profile")		; ELLE.  E+G: () Mark Page
-(keybind X-^R "Read File")
-(keybind X-^S "Save File")
-(keybind X-^U "Uppercase Region")
-(keybind X-^V "Visit File")
-(keybind X-^W "Write File")
-(keybind X-^X "Exchange Point and Mark")
-(keybind X-^Z "Return to Superior")	; G:() suspend-emacs
-(keybind X-! "Push to Inferior")	; ELLE.  E:(*)-; G:()-
-(keybind X-$  "Replace in Line")	; ELLE (mnx). E+G:()-
-(keybind X-% "Replace String")		; E+G: (*) -
-(keybind "X-(" "Start Kbd Macro")
-(keybind "X-)" "End Kbd Macro")
-(keybind X-* "View Kbd Macro")		; E: (*)-; G: ()-
-(keybind X-. "Set Fill Prefix")
-(keybind X-0 "Delete Window")		; E: ()-
-(keybind X-1 "One Window")
-(keybind X-2 "Two Windows")
-(keybind X-8 "Standout Window")		; ELLE.  E+G:()-
-(keybind X-9 "Two Mode Windows")	; ELLE.  E+G:()-
-(keybind X-= "What Page")		; E+G: (*) What Cursor Position
-(keybind X-^ "Grow Window")
-(keybind X-B "Select Buffer")
-(keybind X-E "Execute Kbd Macro")
-(keybind X-F "Set Fill Column")
-(keybind X-I "Insert File")		; E: (*) Info
-(keybind X-K "Kill Buffer")
-(keybind X-O "Other Window")
-(keybind X-S "Save All Files")		; E:(*)-; G:(= save-some-buffers)
-(keybind X-T "Auto Fill Mode")		; E:(*) Transpose Regions;  G:(*)-
-(keybind X-DEL "Backward Kill Line")	; ELLE(ico)  E+G:() Backward Kill Sentence
-
-
-; IMAGEN-specific functions, not bound.
-;(keybind ""  "Text Mode")		; IMAGEN E:(*);	G:(*)
-;(keybind ""  "Execute Unix Command")	; IMAGEN E:();	G:(M-! shell-command)
-;(keybind ""  "Execute Make")		; IMAGEN E:(* Compile); G:(* compile)
-;(keybind ""  "Find Next Error")	; IMAGEN E:();	G:(X-` next-error)
-
-; SUN Mouse functions, for menuitem selection.
-;(menuitem "Stuff Selection")	; SUN
-;(menuitem "Select Region")	; SUN
-
-; Forget completely about these.
-;(keybind ""  "ICO Extend Command")	; ICONOGRAPHICS
-;(keybind ""  "ICO Typeset Funs")	; ICONOGRAPHICS
-;(keybind ""  "ICO Spec Input Funs")	; ICONOGRAPHICS
-
Index: trunk/minix/commands/elle/eebit.c
===================================================================
--- trunk/minix/commands/elle/eebit.c	(revision 9)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/* ELLE - Copyright 1985, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * EEBIT	Bit Array functions
- */
-#include "sb.h"
-
-/* Char-bit array functions.   All assume that there are at least 8 bits
- * in a byte, and that the number of bytes per word is a power of 2.
- */
-/* CHBBITS represents log 2 of the # of bits stored per chbit-array word.
- *	WDBITS already has log2 of the # of bytes per word, and we are
- *	assuming each byte has at least 8 bits, so log2(8) = 3.
- */
-#define CHBSIZE (WDSIZE*8)	/* # bits per word */
-#define CHBBITS (WDBITS+3)	/* log2(CHBSIZE) */
-#define CHBMASK (CHBSIZE-1)
-#define CHBARYSIZ (128/CHBSIZE)	/* # words per ASCII array */
-
-/* CHBALLOC(size) - Allocates a char-bit array */
-int *
-chballoc(size)
-int size;
-{	return((int *)calloc((size + CHBSIZE-1)/CHBSIZE, (sizeof(int))));
-}
-
-/* CHBIT(array, char) - Tests bit in char-bit array
- */
-chbit(array,c)
-register int *array, c;
-{	return(array[c >> CHBBITS] & (1 << (c & CHBMASK)));
-}
-/* CHBIS (array, char) - Sets bit in char-bit array
- */
-chbis(array,c)
-register int *array, c;
-{	array[c >> CHBBITS] |= (1 << (c & CHBMASK));
-}
-/* CHBIC (array, char) - Clears bit in char-bit array
- */
-chbic(array,c)
-register int *array, c;
-{	array[c >> CHBBITS] &= ~(1 << (c & CHBMASK));
-}
Index: trunk/minix/commands/elle/eebuff.c
===================================================================
--- trunk/minix/commands/elle/eebuff.c	(revision 9)
+++ 	(revision )
@@ -1,1081 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-
-/* EEBUFF	Buffer and Window functions.
- *	Each buffer is an independent SB-string described by a
- *	buffer structure.  All buffer structures are allocated dynamically
- *	and chained together starting from buf_head.
- */
-
-#include "elle.h"
-
-#if FX_FILLMODE
-extern int fill_mode;
-#endif
-#if FX_SKMAC
-extern int kdef_mode;
-#endif
-
-struct buffer *make_buf(), *find_buf(), *sel_mbuf(), *sel_nbuf();
-struct window *make_win();
-
-/* EFUN: "Select Buffer" */
-/*	Select old buffer or create a new one.  Defaults to previously
- *	used buffer.
- */
-f_selbuffer()
-{	register char *ans;
-	register struct buffer *b;
-
-	if((b = last_buf) == cur_buf)	/* If default same as current, */
-		if(!(b = sel_mbuf(b)))	/* try to pick a more useful one. */
-			b = sel_nbuf(cur_buf);
-
-	ans = ask("Select buffer (%s): ",b->b_name);
-	if (ans == 0)		       /* he aborted */
-		return;
-	if (*ans != '\0')		/* Null string => use last buff */
-	  {	b = find_buf (ans);	/* Else find/create one */
-		if (b == 0)
-			b = make_buf (ans);
-	  }
-	sel_buf(b);
-	chkfree(ans);
-}
-
-#if FX_SELXBUFFER
-/* EFUN: "Select Existing Buffer" (not EMACS) - from IMAGEN config */
-
-static int findstr();
-
-f_selxbuffer()
-{	register char *ans;
-	register struct buffer *b;
-
-	b = last_buf;			/* This is default */
-	ans = ask("Select existing buffer (%s): ", b->b_name);
-	if (ans == 0)			/* Aborted */
-		return;
-	if (*ans != 0)
-	  {	for (b = buf_head; b != 0; b = b->b_next)
-			if (findstr(ans, b->b_name))
-				break;
-		if (b == 0)
-			ding("That isn't a substring of any buffer name!");
-	  }
-	chkfree(ans);
-	if (b != 0)
-	  {	saytoo(" => ");
-		sayntoo(b->b_name);
-		sel_buf(b);
-	  }
-}
-
-static int
-findstr(str, instr)			/* Find "str" in string "instr" */
-register char *str, *instr;
-{	register char *sp, *isp;
-
-	while (*instr)
-	  {	sp = str;
-		isp = instr;
-		while (*sp)
-			if (*sp++ != *isp++)
-				goto next;
-		return(1);
-next:		++instr;
-	  }
-	return(0);
-}
-#endif /*FX_SELXBUFFER*/
-
-
-/* EFUN: "Kill Buffer"	*/
-/*	Kill specified buffer - defaults to current buffer.
- * This code assumes a killed buffer will never be on a window list unless it
- * is pointed to by cur_buf or oth_win->w_buf!!!!
- */
-f_kbuffer()
-{	register struct buffer *b, *ob;
-	register char *ans;
-
-	if((ans = ask("Kill buffer: ")) == 0)
-		return;
-	if(*ans == 0) b = cur_buf;
-	else if(*ans == SP) b = 0;
-	else b = find_buf(ans);
-
-	chkfree(ans);
-	if(!b)
-	  {	ding("No such buffer");
-		return;
-	  }
-#if IMAGEN
-	if (b->b_flags & B_PERMANENT)
-	  {	ding("Permanent buffer--cannot kill!");
-		return;
-	  }
-	if (b->b_flags & B_MODIFIED)
-	  {	if ((ans == ask("Buffer is modified; are you sure? ")) == 0)
-			return;
-		if(upcase(*ans) != 'Y')
-		  {	chkfree(ans);
-			return;
-		  }
-		chkfree(ans);
-	  }
-#endif /*IMAGEN*/
-	if(b == cur_buf || (oth_win && (oth_win->w_buf == b)))
-	  {	ob = last_buf;
-		do
-		  {
-			/* If default same as doomed buffer, try to pick
-			 * a more useful alternative. */
-			if((b == ob) && !(ob = sel_mbuf(b)))
-				ob = sel_nbuf(b);
-
-			ans = ask("Killing in-use buffer; select which other buffer (%s): ",
-					ob->b_name);
-			if(ans == 0) return;
-			if(*ans)
-			  {	if(*ans == SP) ob = 0;
-				else ob = find_buf(ans);
-			  }
-			chkfree(ans);
-			if(!ob)
-			  {	ding("No such buffer");
-				return;
-			  }
-		  } while (b == ob);
-
-		/* B is buffer to kill, OB is buffer to replace it with */
-		if(oth_win && (oth_win->w_buf == b))
-		  {	f_othwind();	/* Select other one */
-			chg_buf(ob);	/* Change to new buffer */
-			f_othwind();
-		  }
-		if(cur_buf == b)
-			chg_buf(ob);
-	  }
-
-	kill_buf(b);			/* Die!!!! */
-	if(last_buf == b)
-		last_buf = cur_buf;
-}
-
-/* EFUN: "List Buffers" */
-/*	Display a list of all user buffers.  Internal buffers, whose names
- *	start with a space, are not shown.
- */
-f_listbufs()
-{
-	register struct buffer *b;
-	register char *cp;
-	register int i;
-	struct buffer *tbuf, *savbuf;
-	char temp[20];
-
-	/* First must set up special buffer... */
-	savbuf = cur_buf;
-	chg_buf(tbuf = make_buf(" **SHOW**"));
-	e_sputz("Buffers in this ELLE:\n\n");
-	for(b = buf_head; b; b = b->b_next)
-	  {	cp = b->b_name;
-		if(*cp == SP) continue;	/* Ignore internal buffs */
-		e_sputz((b->b_flags&B_MODIFIED) ? "* " : "  ");
-		e_sputz(cp);			/* Insert buffer name */
-		dottoa(temp,ex_blen(b));	/* Get buff-length string */
-		if((i = ((FNAMELEN > 14) ? 30 : 20)
-			 - strlen(cp) - strlen(temp)) > 0)
-			e_insn(SP, i);
-		e_sputz(" (");
-		e_sputz(temp);
-		e_sputz(") ");
-		if(cp = b->b_fn)
-			e_sputz(cp);
-#if IMAGEN
-		if (b->b_flags & B_CMODE)
-			e_sputz(" (C)");
-		else if (b->b_flags & B_TEXTMODE)
-			e_sputz(" (Text)");
-		else
-			e_sputz(" (Fundamental)");
-#endif /*IMAGEN*/
-		e_putc(LF);
-	  }
-	mk_showin(tbuf);	/* Show this buffer in temp window */
-	chg_buf(savbuf);	/* Return to real current buffer */
-	kill_buf(tbuf);
-}
-
-
-/* EFUN: "Buffer Not Modified" */
-/*	Mark the current buffer as not modified.
- */
-f_bufnotmod()
-{
-	cur_buf -> b_flags &= ~B_MODIFIED;
-	redp(RD_MODE);
-}
-
-#if FX_EOLMODE
-/* EFUN: "EOL CRLF Mode" (not EMACS) */
-/*	Toggle the EOL mode of the current buffer.
-**		LF EOL Mode means LF alone is an EOL.
-**		CRLF EOL Mode means CRLF together is an EOL.
-*/
-f_eolmode()
-{
-	cur_buf->b_flags ^= B_EOLCRLF;		/* Flip this bit */
-	say((cur_buf->b_flags & B_EOLCRLF)
-		? "EOL Mode is CRLF"		/* If now on */
-		: "EOL Mode is LF");		/* If now off */
-
-	redp(RD_WINRES);			/* Redo window for this buf */
-}
-#endif /*FX_EOLMODE*/
-
-
-#if FX_GOBEG
-/* EFUN: "Goto Beginning" */
-f_gobeg()
-{	e_gobob();
-	ed_setcur();
-}
-#endif /*FX_GOBEG*/
-
-#if FX_GOEND
-/* EFUN: "Goto End" */
-f_goend()
-{	e_goeob();
-	ed_setcur();
-}
-#endif /*FX_GOEND*/
-
-#if FX_WHATPAGE
-/* EFUN: "What Page" */
-/*	Extra info added as per earlier ICONOGRAPHICS "What Buffer Position"
-** Reports on current position as follows:
-**	Dot=<n>, Page <n>  Line <n> (line <n> of <m>)
-*/
-f_whatpage()
-{
-	register chroff cnt;
-	register int c;
-	register int page, line;
-	int lineatp;
-	char tempstr[12], *dottoa ();
-
-        saynow("Dot=");
-        dottoa(tempstr, cur_dot);
-        sayntoo(tempstr);
-
-	e_gobob();
-	page = line = lineatp = 1;
-	for (cnt = cur_dot; --cnt >= 0;)
-		if ((c = e_getc()) == LF)
-			++line;
-		else if (c == FF)
-		  {	++page;
-			lineatp = line;
-		  }
-
-        saytoo(", Page ");
-        dottoa(tempstr, (chroff)page);
-        saytoo(tempstr);
-	saytoo("  Line ");
-        dottoa(tempstr, (chroff)(1 + line - lineatp));
-        saytoo(tempstr);
-	saytoo("  Col ");
-        dottoa(tempstr, (chroff)indtion(cur_dot));
-        saytoo(tempstr);
-	saytoo("  [line ");
-	dottoa(tempstr, (chroff)line);
-	saytoo(tempstr);
-	sayntoo(" of ");		/* Force out while scan rest */
-
-        for(e_gocur(); e_gonl() ; ++line) ;	/* Count lines until EOF */
-	c = e_rgetc();			/* Remember what last char is */
-        dottoa(tempstr, (chroff)line);
-        saytoo(tempstr);
-        if (c != LF)		/* Check last char */
-            saytoo(" (no EOL at EOF!)");
-        sayntoo("]");
-	e_gocur();			/* Back to original position */
-}
-#endif /*FX_WHATPAGE*/
-
-
-init_buf ()			       /* init buffer stuff */
-{
-	buf_head = 0;
-	lines_buf = cur_buf = make_buf(" **LINES**");	/* For sep_win */
-	e_insn('-',scr_wid-2);			/* Fill with dashes */
-	last_buf = cur_buf = make_buf ("Main");	/* Make Main buffer */
-	init_win();				/* Now can init windows */
-}
-
-struct buffer *
-make_buf(bname)	       /* create buffer "bname" if it doesn't exist */
-char *bname;
-{	register struct buffer *b;
-	register char *name;
-
-	b = find_buf(name = bname);
-	if (b)				/* if it exists already */
-		return(b);
-	b = (struct buffer *) memalloc(sizeof (struct buffer));
-	b -> b_next = buf_head;	       /* link it in */
-	buf_head = b;
-	b->b_name = strdup(name);	/* Allocate copy of name string */
-	b->b_dot = 0;		/* Set dot to beg */
-	sb_open(b,(SBSTR *)0);		/* Open buffer with null initial sbstring */
-	b->b_fn = 0;
-	b->b_flags = 0;
-	b->b_mode = cur_mode;	/* Inherit current mode */
-	return(b);
-}
-
-
-struct buffer *
-find_buf(name)	       /* returns pointer to buffer of that name or 0 */
-char *name;
-{	register struct buffer *b = buf_head;
-
-	while (b && strcmp(b->b_name, name))
-		b = b -> b_next;
-	return(b);
-}
-
-sel_buf(b)				/* select buffer, saving last */
-struct buffer *b;
-{
-	if(b != cur_buf) last_buf = cur_buf;
-	chg_buf(b);
-}
-
-chg_buf (newbuf)		       /* change current buffer to newbuf */
-struct buffer *newbuf;
-{	register struct buffer *obuf, *nbuf;
-
-	if ((nbuf = newbuf) == (obuf = cur_buf))
-		return;			/* Do nothing if same buffers */
-	obuf->b_dot = cur_dot;
-	cur_buf = nbuf;
-	cur_mode = nbuf->b_mode;
-	e_gosetcur(nbuf->b_dot);	/* Set cur_dot and go there */
-	cur_win->w_buf = nbuf;
-	cur_win->w_dot = cur_dot;
-#if IMAGEN
-	cur_win->w_redp = RD_WINRES|RD_REDO;
-#else
-	cur_win->w_redp = RD_WINRES;	/* Reset flags - do complete update */
-#endif /*-IMAGEN*/
-	unlk_buf(obuf);			/* Unlock previous buffer if can */
-	mark_p = 0;			/* this is lazy */
-	redp(RD_MODE|RD_WINRES);
-}
-
-/* See if specified buffer belongs to any active window, and
- * if not then get it into an idle, unlocked state; this helps the
- * edit package compact and swap stuff out while it's not being used.
- * Assumes proper state of dot has been stored into b_dot.
- */
-unlk_buf(bufp)
-struct buffer *bufp;
-{	register struct buffer *b;
-	register struct window *w;
-
-	b = bufp;
-	for(w = win_head; w; w = w->w_next)
-		if(b == w->w_buf)
-			return;		/* Buffer is actively being shown */
-	sb_rewind((SBBUF *)b);		/* Return to idle state */
-}
-
-/* SEL_NBUF(buf) - Select next user buffer.  Ignores internal buffers.
- *	Arg of 0 starts at beg of buffer list.  Always returns
- *	a buffer pointer - returns argument (which may be 0)
- *	if found no other user buffers.
- *
- * SEL_MBUF(buf) - Select next modified buffer.
- *	Returns buffer ptr to "next" modified buffer, if any.
- *	Arg of 0 starts at beg of buffer list and scans all of them.
- *	Returns 0 if no other modified buffers exist (unlike SEL_NBUF!)
- *	Ignores internal buffers, whose names start with a space.
- */
-/* struct buffer *buf_mptr; */
-#if 0
-struct buffer *
-sel_mbuf(buf)
-struct buffer *buf;
-{	register struct buffer *b;
-	register int sweep;
-
-	sweep = 0;			/* Make 2 sweeps only */
-	if(b = buf) b = b->b_next;
-	do {
-		if(b == 0)		/* Initialize if needed */
-			b = buf_head;
-		for(; b; b = b->b_next)
-			if((b->b_flags & B_MODIFIED) && (*b->b_name != SP))
-				return((b == buf) ? 0 : b);
-	  } while(sweep++ != 0);
-	return(0);
-}
-#endif /*COMMENT*/
-
-struct buffer *
-sel_mbuf(buf)
-register struct buffer *buf;
-{	register struct buffer *b, *b2;
-	b = b2 = sel_nbuf(buf);
-	do {	if(b == buf) break;
-		if(b->b_flags & B_MODIFIED)
-			return(b);
-	  } while((b = sel_nbuf(b)) != b2);
-
-	return(0);
-}
-
-struct buffer *
-sel_nbuf(buf)
-register struct buffer *buf;
-{	register struct buffer *b;
-
-	b = buf;
-	do {
-		if(!b || !(b = b->b_next))
-			b = buf_head;
-		if(*b->b_name != SP)
-			break;
-	  } while (b != buf);
-	return(b);
-}
-
-
-kill_buf(buf)
-struct buffer *buf;
-{	register struct buffer *b, *b1, *bt;
-
-	b = buf;
-	b1 = 0;
-	for(bt = buf_head; bt && bt != b; bt = bt -> b_next)
-		b1 = bt;
-	if(bt == 0)
-	  {	ring_bell();
-		errbarf("No such buffer");	/* Internal error */
-		return;
-	  }
-	if (b1 == 0)
-		buf_head = b->b_next;
-	else
-		b1->b_next = b->b_next;
-	sbs_del(sb_close((SBBUF *)b));	/* Close buffer & delete sbstring */
-	sb_fdcls(-1);			/* Make sweep for unused FD's */
-	if(b->b_fn)
-		chkfree(b->b_fn);	/* Flush filename if one */
-	chkfree(b->b_name);		/* Flush name */
-	chkfree((char *)b);		/* Flush buffer */
-}
-
-
-/* ZAP_BUFFER - Delete all of the buffer, but if it's been modified,
- *	ask first.  Returns 0 if user aborts.
- */
-zap_buffer()
-{
-#if IMAGEN
-	extern struct buffer *exec_buf;	/* in e_make.c */
-
-	if(cur_buf != exec_buf && cur_buf -> b_flags & B_MODIFIED)
-#else
-	if(cur_buf -> b_flags & B_MODIFIED)
-#endif /*-IMAGEN*/
-		if(ask_kbuf(cur_buf) <= 0)
-			return(0);		/* Aborted */
-	ed_reset();		/* This takes care of redisplay too */
-	mark_p = 0;
-#if IMAGEN
-	cur_buf->b_flags &= ~B_BACKEDUP; /* Clear backed-up flag */
-#endif
-	return(1);
-}
-
-
-
-
-/* ASK_KBUF - Ask user "are you sure?" before killing a buffer.
- *	Returns +1 if user says "yes" - OK to kill.
- *		 0 if user aborts (^G)
- *		-1 if user says "no".
- */
-ask_kbuf(buf)
-struct buffer *buf;
-{	register struct buffer *b;
-	register char *s;
-	register int ans;
-
-	b = buf;
-	s = ask("Buffer %s contains changes - forget them? ", b->b_name);
-	if(s == 0) return(0);
-	ans = (upcase(*s) == 'Y') ? 1 : -1;
-	chkfree(s);
-	return(ans);
-}
-
-
-/* Window stuff */
-
-/* Like EMACS, ELLE only provides at most two user windows.
- * The current user window is pointed to by user_win;
- * the "other" one is oth_win.  If oth_win == 0, there is only one user
- * window.
- */
-
-#if FX_2MODEWINDS
-int sepmode_p = 0;	/* Set true if separator window is a 2nd mode win */
-#endif
-
-/* EFUN: "Two Windows" */
-/*	Divide the current window in half, put the current buffer in the
- *	other window, and go to the new window.
- */
-f_2winds()
-{	register int h, t;
-	register struct window *w;
-
-	if (oth_win)
-	  {
-#if !(IMAGEN)
-		ding("Already 2 windows");
-#endif /*-IMAGEN*/
-		return;
-	  }
-	w = cur_win;
-	d_fixcur();			/* Stabilize current window */
-	h = (w->w_ht) / 2;
-	t = w->w_pos + h;		/* Pos of dividing window */
-	sep_win = make_win(t, 1, lines_buf);
-					/* assume using dashes to separate */
-	oth_win = make_win(t + 1, w->w_ht - (h + 1), cur_buf);
-					/* Other window has balance */
-#if FX_SOWIND
-	oth_win->w_flags |= cur_win->w_flags&W_STANDOUT;
-	sep_win->w_flags |= mode_win->w_flags&W_STANDOUT;
-#endif
-#if FX_2MODEWINDS
-	chk2modws();			/* Update 2-mode-wind status */
-#endif
-	w->w_ht = h;			/* Decrease current window to half */
-
-	/* Minimize redisplay by moving each window's dot into
-	 * a currently displayed area */
-	if(cur_dot < (oth_win->w_topldot = scr[t+1]->sl_boff))
-		oth_win->w_dot = oth_win->w_topldot;	/* Adj bottom win */
-	else					/* Adjust top window */
-	  {	oth_win->w_dot = cur_dot;	/* Bottom keeps dot */
-		cur_dot = scr[t-1]->sl_boff;	/* but top needs new one. */
-	  }
-	f_othwind();			/* switch to other window */
-	redp(RD_WINDS);			/* Update all windows */
-}
-
-
-/* EFUN: "One Window" */
-/*	Revert to using only one window; use the current buffer (unlike
- *	EMACS which always selects the top window's buffer)
- *	Ensures that current window's vars are correctly set for
- *	new dimensions (w_pos, w_ht, plus w_topldot to minimize redisplay),
- *	then kills unneeded windows.
- */
-f_1wind()
-{	register struct window *w;
-
-	if (oth_win == 0)
-	  {
-#if (!IMAGEN)
-		ding("Only 1 window");
-#endif /*-IMAGEN*/
-		return;
-	  }
-	w = cur_win;
-	if(w->w_pos)		/* If not top window */
-	  {	d_fixcur();		/* Ensure screen-line data correct */
-		e_go(w->w_topldot);	/* Beginning from top of window, */
-		d_fgoloff(-w->w_pos);	/* Move back enough lines */
-		w->w_topldot = e_dot();	/* To set new start of window */
-		e_gocur();		/* Then move back to orig place */
-		w->w_pos = 0;
-	  }
-	w->w_ht += oth_win -> w_ht + 1;
-	kill_win (oth_win);
-	kill_win (sep_win);
-	oth_win = sep_win = 0;
-#if FX_2MODEWINDS
-	chk2modws();	/* Update notion of whether have 2 mode winds */
-#endif
-	redp(RD_FIXWIN|RD_WINDS|RD_MODE); /* New topldot for this window,
-					 * and check all remaining windows */
-}
-
-/* EFUN: "Other Window" */
-/*	Move to the "other" user window.
- */
-f_othwind ()
-{	if (oth_win == 0)
-	  {
-#if !(IMAGEN)
-		ding("Only 1 window");
-#endif /*-IMAGEN*/
-		return;
-	  }
-	chg_win(oth_win);
-	oth_win = user_win;
-	user_win = cur_win;
-	redp(RD_MODE);
-}
-
-/* EFUN: "Grow Window" */
-/*	Grow the current window - while in two window mode,
- *	increase the size of the current window by the arg
- *	and decrease the other accordingly
- */
-f_growind()
-{	register struct window *cw, *ow;
-	register int e;
-
-	if ((ow = oth_win) == 0)
-	  {
-#if !(IMAGEN)
-		ding("Only 1 window");
-#endif /*-IMAGEN*/
-		return;
-	  }
-	e = exp;
-	if((cw = cur_win)->w_pos != 0)	/* If current window is on bottom */
-	  {	cw = ow;		/* Then fake code to think it's top */
-		ow = cur_win;
-		e = -e;
-	  }
-	if(  cw->w_ht + e < 1
-	  || ow->w_ht + e < 1)
-	  {	ding("Too much");
-		return;
-	  }
-	cw -> w_ht += e;
-	ow -> w_pos += e;
-	ow -> w_ht -= e;
-	sep_win -> w_pos += e;
-	redp(RD_WINDS | RD_MODE);		/* Update all windows */
-}
-
-#if FX_SHRINKWIND
-/* EFUN: "Shrink Window" (not EMACS) - from IMAGEN config */
-f_shrinkwind()
-{
-	if (! oth_win)
-		return;
-	f_othwind();
-	f_growind();
-	f_othwind();
-}
-#endif /*FX_SHRINKWIND*/
-
-#if FX_DELWIND
-/* EFUN: "Delete Window" (not EMACS) - from IMAGEN config */
-f_delwind()
-{
-	if(!oth_win)
-		return;
-	f_othwind();
-	f_1wind();
-}
-#endif /*FX_DELWIND*/
-
-#if FX_SOWIND
-/* EFUN: "Standout Window" (not EMACS) */
-/*	Toggles the display standout mode for the current window.
-**	With argument of 4, toggles the standout mode for the non-buffer
-**	parts of the screen, such as the ELLE mode line.
-** (This corresponds to FS INVMOD$ in EMACS)
-**	With argument of 0, turns standout mode off for all windows.
-*/
-/* It suffices to set the window flag bit and force a RD_WINRES for that
- * window; the redisplay code will do the rest.
-*/
-static void tgso_wind();
-
-f_sowind()
-{
-	register struct window *w;
-	switch(exp)
-	  {	default:		/* Toggle current window */
-			tgso_wind(cur_win);
-			break;
-		case 4:			/* Toggle mode & separator windows */
-			tgso_wind(mode_win);
-			tgso_wind(sep_win);	/* This may not exist */
-			break;
-		case 0:			/* Turn off standout for all winds */
-			for(w = win_head; w; w = w->w_next)
-				if(w->w_flags&W_STANDOUT)
-					tgso_wind(w);
-	  }
-#if FX_2MODEWINDS
-	chk2modws();	/* Update notion of whether have 2 mode winds */
-#endif
-}
-
-static void
-tgso_wind(w)		/* Toggle standout mode for given window */
-register struct window *w;
-{
-	if (w == 0) return;		/* For case of no sep_win */
-	if (w->w_flags & W_STANDOUT)
-		w->w_flags &= ~W_STANDOUT;
-	else w->w_flags |= W_STANDOUT;
-	w->w_redp |= RD_WINRES;		/* Re-do this particular window */
-	redp(RD_CHKALL);		/* Check all windows for changes */
-}
-#endif /*FX_SOWIND*/
-
-
-#if FX_2MODEWINDS
-/* EFUN: "Two Mode Windows" (not EMACS) */
-/*	With arg, sets ev_2modws to that value (0, 1, or 2).
-**	No arg, toggles current setting between 0 and 2.
-*/
-
-f_2modewinds()
-{
-	ev_2modws = exp_p ? exp : (ev_2modws ? 0 : 2);
-	chk2modws();
-}
-
-/* CHK2MODWS - Called after anything changes which might affect
-**	whether 2 mode windows are in effect or not.  Fixes up
-**	sep_win to either be or not be a mode window.
-*/
-chk2modws()
-{	register struct window *w;
-	static struct buffer *sep_buf = 0;
-
-	if(!(w = sep_win))
-	  {	sepmode_p = 0;		/* Don't have 2 windows at all */
-		return;
-	  }
-	sepmode_p = (ev_2modws == 1)
-			? (mode_win->w_flags&W_STANDOUT)
-			: ev_2modws;
-
-	if(sepmode_p)		/* Turn 2-mode-winds on? */
-	  {
-		if(!sep_buf)
-			sep_buf = make_buf(" **SEPMODE**");
-		w->w_buf = sep_buf;
-		w->w_flags |= W_MODE;
-	  }
-	else			/* Turn 2-mode-winds off */
-	  {	w->w_buf = lines_buf;
-		w->w_flags &= ~W_MODE;
-		redp(RD_CHKALL);	/* No longer a mode win, so must */
-					/* check all to ensure it's updated */
-	  }
-	w->w_redp |= RD_WINRES;
-	redp(RD_MODE);
-}
-#endif /*FX_2MODEWINDS*/
-
-
-init_win ()
-{
-	win_head = 0;
-	oth_win = 0;
-	user_win = make_win(0, scr_ht - (ECHOLINES+1), cur_buf); /* Main */
-	mode_win = make_win(scr_ht - (ECHOLINES+1), 1, make_buf(" **MODE**"));
-	ask_win  = make_win(scr_ht - ECHOLINES,     1, make_buf(" **ASK**"));
-#if FX_SOWIND
-	if(ev_modwso)
-		mode_win->w_flags |= W_STANDOUT;
-#endif
-
-	cur_win = user_win;
-}
-
-chg_win(newwin)		       /* change current window to newwin */
-struct window *newwin;
-{
-	cur_win->w_dot = cur_dot;	/* Save window's current dot */
-	cur_win->w_redp |= rd_type&RDS_WINFLGS;	/* and its redisplay flags */
-	cur_win = newwin;		/* OK, switch to new current window */
-	cur_buf = newwin->w_buf;	/* Set new buffer from win */
-	e_gosetcur(newwin->w_dot);	/* Set new cur_dot from win too */
-			/* Note done this way to canonicalize the location
-			** (may be past new EOB) and ensure SB buffer
-			** internals agree with cur_dot.
-			*/
-	rd_type &= ~RDS_WINFLGS;	/* Remove old per-window flags */
-	redp(RD_WINRES|RD_MODE);	/* Maybe caller shd handle? */
-			/* Note WINRES must be set in case we are pointing
-			 * to a buffer that was modified while we were in
-			 * the other window!
-			 */
-}
-
-
-struct window *
-make_win (pos, ht, buf)
-int pos, ht;
-struct buffer *buf;
-{	register struct window *w;
-	register struct buffer *b;
-
-	b = buf;
-	w = (struct window *) memalloc(sizeof (struct window));
-	w->w_flags = 0;
-	w->w_pos = pos;
-	w->w_ht = ht;
-	w->w_buf = b;
-	w->w_dot = b->b_dot;	/* Set dot from buffer value */
-	w->w_topldot = 0;	/* Set top of window to beg of buffer */
-	w->w_pct = 200;		/* Assume "ALL" */
-	w->w_bmod = 0;
-	w->w_emod = 0;
-	w->w_oldz = 0;
-	w->w_redp = RD_WINRES;	/* Window will need complete update */
-	w->w_next = win_head;	/* Done, now link it in */
-	win_head = w;
-	return (w);
-}
-
-kill_win (win)
-struct window *win;
-{	register struct window *w, *w1, *kw;
-
-	kw = win;
-	w1 = 0;
-	for (w = win_head; w && w != kw; w = w -> w_next)
-		w1 = w;
-	if (w == 0)
-	  {	ring_bell();
-		errbarf("No such window");	/* Internal error */
-		return;
-	  }
-	if (w1 == 0)
-		win_head = w -> w_next;
-	else
-		w1 -> w_next = w -> w_next;
-	kw->w_buf->b_dot = (kw == cur_win) ? cur_dot : kw->w_dot;
-	chkfree (kw);
-#if IMAGEN		/* Not needed? */
-	redp (RD_WINRES|RD_WINDS|RD_REDO);
-#endif /*IMAGEN*/
-}
-
-
-/*
- * "Show-window" routines, used to set up, step through, and close a
- * temporary "show" window.
- * MK_SHOWIN(bufp)
- * UP_SHOWIN()
- * KL_SHOWIN()
- */
-
-/* MK_SHOWIN(bufp) - Temporarily display a buffer
- */
-mk_showin(b)
-struct buffer *b;
-{	register struct window *w;
-	register int i;
-	int moreflg, intflg;		/* Interrupt flag */
-	struct window *savwin;
-
-	/* First must set up special window... */
-	savwin = cur_win;
-	chg_win(w = make_win(0, scr_ht-(ECHOLINES+3), b));
- redo:
-	d_fixcur();		/* Fix up screen image of current window */
-
-	/* Find how many lines actually used, and reduce size to that */
-	i = w->w_ht;
-	while(--i >= 0)
-	  {
-		if(scr[i]->sl_boff != w->w_oldz) break;
-	  }
-	if(++i <= 0)
-		goto skipit;	/* Punt the whole thing */
-	if(!(moreflg = (i >= w->w_ht)))
-		w->w_ht = i;	/* Reduce size of window */
-
-	intflg = upd_wind(w);	/* Update the window! */
-	if(!intflg)		/* Unless input waiting, add prompt. */
-	  {
-		yellat( moreflg ?
-	"--MORE-- (type Space for more, or type any command to flush)" :
-	"------------------------------------------------ (Hit space to continue)--",
-			w->w_ht);
-		
-	  }
-	tbufls();		/* Ensure all output forced out */
-	i = cmd_read();		/* then wait for user to input a char */
-	if(i == SP)
-	  {	if(moreflg)
-		  {	yellat("", w->w_ht);
-			d_screen(1);
-			w->w_redp |= RD_WINRES;
-			goto redo;
-		  }
-	  }
-#if !(IMAGEN)		/* IMAGEN - always ignore what was typed */
-	else unrchf = i;
-#endif /*-IMAGEN*/
-skipit:	chg_win(savwin);
-	kill_win(w);
-	redp(RD_WINDS);		/* Update all remaining windows */
-}
-
-
-/* Mode Line generation */
-
-struct window *
-make_mode(bw)
-register struct window *bw;	/* Base window we are reporting status of */
-{
-	register struct buffer *b;	/* Buffer of this window */
-	struct window *mw, *savew;	/* Save current window */
-	struct buffer *saveb;	/* and current buffer (in case different) */
-	char temp[20];
-
-	saveb = cur_buf;	/* Save values prior to context switch */
-	savew = cur_win;
-	b = bw->w_buf;		/* Get buffer for that window */
-
-#if FX_2MODEWINDS
-	if((mw = sep_win) && (mw->w_flags&W_MODE) &&
-	    (bw->w_pos == 0))		/* Base window is top window? */
-	  {				/* Use sep_win as mode wind */
-	  }
-	else
-#endif
-		mw = mode_win;		/* Default is normal mode window */
-	chg_win(mw);			/* Go to mode line window */
-	e_gobob();			/* go to beginning */
-	e_reset();			/* Flush buffer */
-#if IMAGEN
-	e_sputz(" ");
-	e_sputz(b->b_name);
-	if (b -> b_flags & B_MODIFIED)
-		e_sputz("*");
-	e_sputz(" (");
-	if (b->b_flags & B_QUERYREP)
-		e_sputz("[Query Replace] ");
-	if (b->b_flags & B_CMODE)
-		e_sputz("C");
-	else if (b->b_flags & B_TEXTMODE)
-		e_sputz("Text");
-	else
-		e_sputz("Fundamental");
-	e_sputz(")  ");
-	if (b->b_fn)
-		e_sputz(b->b_fn);
-	e_sputz("      ");
-#else
-	e_sputz(ev_verstr);		/* Editor name/version */
-	e_sputz(" (");
-	e_sputz(cur_mode->mjm_name);	/* insert major mode name */
-#if FX_FILLMODE
-	if(fill_mode) e_sputz(" Fill");
-#endif /*FX_FILLMODE*/
-#if FX_SKMAC
-	if(kdef_mode) e_sputz(" MacroDef");
-#endif /*FX_SKMAC*/
-	e_sputz(") ");
-	e_sputz(b->b_name);		/* buffer name */
-	e_sputz(": ");
-	if (b->b_fn)
-		e_sputz(b->b_fn);       /* file name */
-	if (b->b_flags & B_MODIFIED)
-		e_sputz(" *");
-	else	e_sputz("  ");
-#endif /*-IMAGEN*/
-	if(bw->w_pct < 200)		/* Not ALL? */
-	  {	e_sputz(" --");
-		switch(bw->w_pct)
-		  {	case -1:
-				e_sputz("TOP");
-				break;
-			case 150:
-				e_sputz("BOT");
-				break;
-			default:
-				dottoa(&temp[0],(chroff)bw->w_pct);
-				e_sputz(&temp[0]);
-				e_putc('%');
-		  }
-		e_sputz("--");
-	  }
-#if FX_SOWIND
-	if(mw->w_flags&W_STANDOUT)
-		e_insn(SP, (int)(scr_wd0 - e_blen()));	/* Stuff out with spaces */
-#endif
-
-	redp(RD_WINRES);
-	chg_win(savew);		/* Restore context */
-	chg_buf(saveb);
-	return(mw);		/* Return mode window */
-}
-
-
-buf_mod()
-{	register struct buffer *b;
-
-	b = cur_buf;
-	if((b->b_flags & B_MODIFIED) == 0)
-	  {	b->b_flags |= B_MODIFIED;
-		redp(RD_MODE);
-	  }
-}
-
-/* BUF_TMOD - called when text modified in buffer, to set all
- *	the appropriate indicators so that redisplay works right.
- *	Changed text is everything from CUR_DOT to the given offset
- *	from same.  If stuff was deleted, offset should be 0.
- * BUF_TMAT - similar but argument is location of other end of range,
- *	when caller knows that and wants life easy.
- */
-
-buf_tmat(dot)
-chroff dot;
-{	buf_tmod(dot - cur_dot);	/* Convert to offset */
-}
-buf_tmod(offset)
-chroff offset;
-{	register struct window *w;
-	chroff a, b, tmp;
-
-	w = cur_win;
-	a = cur_dot;
-	b = a + offset;
-	if(a > b)	/* Get into right order */
-	  {	tmp = a;
-		a = b;
-		b = tmp;
-	  }
-	b = e_blen() - b;	/* Make upper bound relative to EOB */
-	if(w->w_bmod < 0)	/* Have range vars been set yet? */
-	  {	w->w_bmod = a;	/* Nope, so can just set 'em now. */
-		w->w_emod = b;
-	  }
-	else
-	  {	if(a < w->w_bmod)
-			w->w_bmod = a;
-		if(b < w->w_emod)
-			w->w_emod = b;
-	  }
-	buf_mod();		/* Maybe later just insert here? */
-	redp(RD_TMOD);
-}
Index: trunk/minix/commands/elle/eecmds.c
===================================================================
--- trunk/minix/commands/elle/eecmds.c	(revision 9)
+++ 	(revision )
@@ -1,323 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-
-/* EECMDS	Command table lookup and profile code
- */
-
-#include "elle.h"
-
-/* Function table, see the included file for explanation. */
-
-	/* First must pre-declare function addrs */
-#define EFUN(rtn,rtnstr,name) int rtn();
-#define EFUNHOLE
-#include "eefdef.h"
-
-	/* Now re-insert to define function table */
-int (*funtab[])() =
-{
-#undef EFUN		/* Avoid redefinition error message */
-#undef EFUNHOLE
-#define EFUN(rtn,rtnstr,name) rtn,
-#define EFUNHOLE 0,
-#include "eefdef.h"
-};
-int funmax = sizeof(funtab)/sizeof(funtab[0]);	/* 1st illegal function # */
-
-/* Insert default command char map tables and profile structure */
-
-#include "defprf.c"
-
-
-/* EFUN: "Prefix Meta" */
-/*	Meta-prefix command.
- *	For now, very simple.  Perhaps later try to hair up with
- *	time-out "M-" prompt?
- */
-f_pfxmeta()
-{	return(cmd_xct(cmd_read()|CB_META));
-}
-
-/* EFUN: "Prefix Extend" */
-/*	Extended-prefix command.
- *	Likewise trivial; perhaps later hair up with timeout "^X-" prompt?
- */
-f_pfxext()
-{	return(cmd_xct(cmd_read()|CB_EXT));
-}
-
-/* EFUN: "Universal Arg" */
-/*	This routine is also called by "Argument Digit" with a special arg
- * of -1 in order to share code.  Since that invocation always sets unrchf,
- * it should always complete at least one digit read loop.
- * Note that exp and exp_p are set to 1 and 0 at the top-level command
- * loop.
- */
-f_uarg(ch)
-int ch;
-{	register int c, oc, i;
-
-	/* Set distinguishing exp_p value depending on whether invoked
-	 * by CTRL-U or another function (Argument Digit, Negative Argument)
-	 */
-	exp_p = (ch < 0) ? 1 : 4;
-	i = 0;			/* Read numerical arg if any follows */
-	for(;;)
-	  {	oc = cmd_read();	/* Get next input char */
-		c = oc & 0177;
-		if(c == '-' && !i)
-		  {	exp_p = -1;
-			exp = 1;	/* Set in case no digits follow */
-		  }
-		else if('0' <= c && c <= '9')	/* If it's a digit too, */
-		  {	i = (i * 10) + c - '0';	/* add digit in. */
-			if(exp_p >= 0) exp_p = 1;
-			exp = i;
-		  }
-		else break;
-	  }
-	exp *= exp_p;		/* Multiply arg appropriately */
-	unrchf = oc;		/* Not a digit, re-read it next. */
-
-	this_cmd = ARGCMD;
-}
-
-/* EFUN: "Negative Argument" */
-f_negarg(ch)
-int ch;
-{	f_uarg(-1);		/* Invoke code from Universal Arg */
-	exp = -exp;
-}
-
-/* EFUN: "Argument Digit" */
-f_argdig(ch)
-int ch;
-{	unrchf = ch;		/* Re-read the digit */
-	f_uarg(-1);		/* Invoke code from Universal Arg */
-}
-
-/* EFUN: "Set Profile" */
-/*	Asks for a profile file and sets profile from it.
- */
-f_setprof()
-{	int set_profile();
-	hack_file("Set Profile: ", set_profile);
-}
-
-#if FX_VTBUTTONS
-/* EFUN: "VT100 Button Hack" */
-/*	This must be bound to Meta-O if anything, because the VT100 sends
- *	an ESC O prefix when the function buttons are used.
- */
-f_vtbuttons ()			/* vt100 function buttons */
-{
-	switch(cmd_read())
-	  {	case ('A'): 
-			return (f_uprline ());
-		case ('B'): 
-			return (f_dnrline ());
-		case ('C'): 
-			return (f_fword ());
-		case ('D'): 
-			return (f_bword ());
-		case ('Q'): 		/* PF1 */
-			return (f_kregion());
-		default: 
-			ring_bell ();
-		break;
-	  }
-}
-#endif /*FX_VTBUTTONS*/
-
-
-/* CMD_WAIT() - Return TRUE if any command input waiting.
-*/
-cmd_wait()
-{	return(unrchf >= 0
-#if FX_SKMAC
-		|| km_inwait()		/* Check for kbdmac input waiting */
-#endif /*FX_SKMAC*/
-		|| tinwait());
-}
-
-/* CMD_READ() - Read a command (single char) from user, and return it.
-*/
-cmd_read()
-{	register int c;
-
-	if((c = unrchf) >= 0)	/* Re-reading last char? */
-	  {	unrchf = -1;
-		return(c);
-	  }
-#if FX_SKMAC			/* Hacking keyboard macros? */
-	return(km_getc());	/* Yes.  This calls tgetc if no kbd macro */
-#else
-	return(tgetc());
-#endif /*-FX_SKMAC*/
-}
-
-/* CMD_XCT(ch) - Command Execution dispatch routine.
-**	Takes char and executes the function (efun) bound to that command key.
-*/
-cmd_xct(ch)
-int ch;
-{	register int (*funct) ();
-	register int c;
-	int (*(cmd_fun())) ();
-
-	if(funct = cmd_fun(c = ch))		/* Get function to run */
-		return((*funct) (c&0177));	/* Invoke with char arg */
-	ring_bell();		/* Undefined command char, error. */
-}
-
-/* CMD_FUN(ch) - Return function for char, 0 if none
-*/
-int (*cmd_fun(c))()
-int c;
-{
-	return(funtab[cmd_idx(c)]);
-}
-
-/* CMD_IDX(ch) - Given command char, return function index for it
-*/
-cmd_idx(c)
-register int c;
-{	register char *cp;
-	register int i;
-
-	if(c&CB_EXT)
-	  {	cp = def_prof.extvec;
-		i = def_prof.extvcnt;
-		goto inlup;
-	  }
-	if(c&CB_META)
-	  {	cp = def_prof.metavec;
-		i = def_prof.metavcnt;
-	inlup:	c = upcase(c);
-		do {	if(*cp++ != c) cp++;
-			else
-			  {	i = *cp&0377;
-				break;
-			  }
-		  } while(--i);		/* If counts out, will return 0! */
-	  }
-	else i = def_prof.chrvec[c&0177]&0377;
-	if(i >= funmax)
-		return(0);
-	return(i);
-}
-
-
-/* Profile hacking */
-
-#if TOPS20
-#include <sys/file.h>		/* for O_BINARY */
-#endif
-
-set_profile(filename)
-char *filename;
-{	char pfile[200];
-	char psfile[200];
-	register int pfd, len;
-	chroff sbx_fdlen();
-	register char *profptr;
-	struct stored_profile st_prof;
-
-	if(filename) strcpy(pfile,filename);
-	else		/* Check for user's profile */
-	  {
-		strcat(strcat(strcpy(pfile,homedir),"/"),ev_profile);
-	  }
-	if((pfd = open(pfile,
-#if TOPS20
-				O_BINARY
-#else
-				0
-#endif
-					)) < 0)
-	  {	if(filename)
-		  {	ding("Cannot open file");
-		  }
-		return;
-	  }
-	if((len = (int)sbx_fdlen(pfd)) < sizeof(struct stored_profile))
-		goto badfil;
-	profptr = memalloc((SBMO)len);
-	if(read(pfd,profptr,len) != len)
-		goto badfmt;
-
-	/* Have read profile into memory, now set up ptrs etc */
-	bcopy((SBMA)profptr,(SBMA)&st_prof,sizeof(struct stored_profile));
-	def_prof.version = prof_upack(st_prof.version);
-	if(def_prof.version != 1)
-		goto badfmt;
-	def_prof.chrvcnt = prof_upack(st_prof.chrvcnt);
-	def_prof.chrvec  = profptr + prof_upack(st_prof.chrvec);
-	def_prof.metavcnt = prof_upack(st_prof.metavcnt);
-	def_prof.metavec = profptr + prof_upack(st_prof.metavec);
-	def_prof.extvcnt = prof_upack(st_prof.extvcnt);
-	def_prof.extvec  = profptr + prof_upack(st_prof.extvec);
-#if SUN
-	def_prof.menuvcnt = prof_upack(st_prof.menuvcnt);
-	def_prof.menuvec = profptr + prof_upack(st_prof.menuvec);
-#endif /*SUN*/
-	goto done;
-
-badfmt:	chkfree(profptr);
-badfil:	ding("Bad profile format");
-done:	close(pfd);
-}
-
-
-#if SUN
-/* SUN Menu profile hacking.
- *	This is here, instead of e_sun.c, because
- * the profile format is still evolving and for the time being I want to
- * keep all profile-hacking code in one place. --KLH
- */
-#include "suntool/tool_hs.h"
-#include "suntool/menu.h"
-
-#define MENUMAX	16
-
-/* Defined in eesun.c */
-extern struct menu *menuptr;
-extern struct menu menu;
-
-char *funamtab[] = {
-#undef EFUN
-#undef EFUNHOLE
-#define EFUN(rtn,rtnstr,name) name,
-#define EFUNHOLE 0,
-#include "eefdef.h"
-};
-
-init_menu() /* initialize the menu for elle from user profile */
-{
-	register struct menuitem *mi;
-	register int n, i, fni;
-
-	if((n = def_prof.menuvcnt) <= 0)
-		return;
-	if(n > MENUMAX) n = MENUMAX;
-	mi = menu.m_items = (struct menuitem *) calloc(n, sizeof *mi);
-
-	menu.m_itemcount = 0;
-	for(i = 0; i < n; i++)
-	  {	fni = def_prof.menuvec[i]&0377;
-		if(fni >= funmax) continue;
-		if(funtab[fni] && funamtab[fni])
-		  {	mi->mi_data = (caddr_t) funtab[fni];
-			mi->mi_imagedata = (caddr_t) strdup(funamtab[fni]);
-			mi->mi_imagetype = MENU_IMAGESTRING;
-			mi++;
-			menu.m_itemcount++;
-		  }
-	  }
-	if(menu.m_itemcount)
-		menuptr = &menu;
-}
-#endif /*SUN*/
Index: trunk/minix/commands/elle/eediag.c
===================================================================
--- trunk/minix/commands/elle/eediag.c	(revision 9)
+++ 	(revision )
@@ -1,356 +1,0 @@
-/* ELLE - Copyright 1982, 1985, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*	EEDIAG - Error diagnostics and testing routines
- */
-
-#include "elle.h"
-
-#if FX_DEBUG
-
-/* EFUN: "Debug Mode" */
-/*	With no arg, toggles self-checking on and off.
- *	With arg of 4 (^U), enters special debug/diagnostics mode.
- */
-
-f_debug(ch)
-int ch;
-{	extern int (*vfy_vec)();	/* In E_MAIN.C */
-	char *vfy_data();
-
-	if(ch < 0)		/* Internal call? */
-	  {	dbg_diag();
-		return;
-	  }
-	if(exp == 4)
-	  {	askerr();
-		return;
-	  }
-	if(vfy_vec) vfy_vec = 0;		/* Toggle current value */
-	else vfy_vec = (int (*)())vfy_data;
-	say(vfy_vec ? "Self-checking on" : "Self-checking off");
-}
-
-
-char *
-vfy_data(flag)		/* Flag = 0 for quiet check */
-int flag;
-{
-	register char *res, *mess;
-	char *sbe_mvfy(), *sbe_sbvfy(), *sbe_svfy();
-
-	if(res = sbe_mvfy(0)) mess = "Mem mgt";
-	else if(res = sbe_sbvfy(cur_buf,0)) mess = "SBBUF";
-	else if(res = sbe_svfy(0)) mess = "SD list";
-	else return(0);		/* Success */
-
-	if(flag)
-	  {	int ostate = clean_exit();
-		printf("\n%s error: %s !!!\n",mess,res);
-		askerr();
-		if(ostate > 0) set_tty();
-	  }
-	return(res);	/* Error seen */
-}
-
-
-extern char *asklin();
-extern int sbx_nfl,sbm_nfl;
-
-char diaghelp[] = "\
-Q - Quit diag mode\n\
-! - Goto subshell\n\
-V - Verify Mem & SD lists\n\
-MF - Mem Freelist\n\
-M  - Mem list\n\
-B  - Current buffer SB\n\
-DF - SD Freelist\n\
-D  - SDs in use\n\
-DL - SD Logical lists\n\
-DP - SD Physical lists\n\
-C n - Compact; 0-7=sbx_comp(n), 8=SM freelist, 9=SD freelist.\n\
-W  - Window printout\n\
-X n - Xercise randomly (GC every n)\n\
-Z n - like X but with notes\n";
-
-dbg_diag()
-{	register char *cp;
-	register int c;
-	char linbuf[100];
-	char *sbe_mfl();
-	char *sbe_sfl();
-	char *sbe_sbs();
-	char *sbe_sdlist();
-
-    for(;;)
-    {	printf("D>");
-	asklin(cp = linbuf);			/* Read a line of input */
-	switch(upcase(*cp++))
-	  {
-	case '?':
-		writez(1,diaghelp);	/* Too long for printf */
-		continue;
-	case '!':
-		f_pshinf();		/* Invoke inferior subshell */
-		clean_exit();		/* Restore normal modes */
-		continue;
-	case 'Q':		/* Quit */
-		return;
-
-	case 'B':		/* Print current SBBUF */
-		sbe_sbs(cur_buf,1);
-		continue;
-
-	case 'C':		/* C n - Compact */
-		c = atoi(&linbuf[1]);
-		if(c == 8)
-			sbm_ngc();	/* GC the SM nodes */
-#if 0 /* This doesn't work, dangerous to invoke. */
-		else if(c == 9)
-			sbm_xngc(&sbx_nfl,sizeof(struct sdblk),
-				SM_DNODS);
-#endif
-		else
-			sbx_comp(512,c);
-		continue;
-
-	case 'D':		/* Print all SD blocks in mem order */
-		switch(upcase(*cp))
-		  {
-		case 0:		/* D - all SDs in mem order */
-			sbe_sds();
-			continue;
-		case 'F':	/* DF - SD freelist */
-			sbe_sfl(1);
-			continue;
-		case 'L':	/* DL - SD logical list */
-			sbe_sdlist(1,0);
-			continue;
-		case 'P':	/* DP - SD physical list */
-			sbe_sdlist(1,1);
-			continue;
-		  }
-		break;		/* failure */
-
-	case 'M':	
-		switch(upcase(*cp))
-		  {
-		case 0:		/* M - all mem alloc info */
-			sbe_mem();
-			continue;
-		case 'F':	/* MF - mem freelist */
-			sbe_mfl(1);
-			continue;
-		  }
-		break;		/* failure */
-
-	case 'V':		/* Verify */
-		if(cp = vfy_data(0))
-			printf("  Failed: %s\n",cp);
-		else printf("  OK\n");
-		continue;
-	case 'W':		/* Print out current window */
-		db_prwind(cur_win);
-		continue;
-	case 'X':		/* Xercise */
-		c = atoi(&linbuf[1]);
-		vfy_exer(0, c ? c : 100);
-		continue;
-	case 'Z':		/* Zercise */
-		c = atoi(&linbuf[1]);
-		vfy_exer(1, c ? c : 100);
-		continue;
-
-	  }	/* End of switch */
-
-	printf("?? Type ? for help\n");
-    }	/* Loop forever */
-}
-
-
-
-/* VFY_EXER - a "random" editor exerciser.  It creates a buffer,
- *	fills it with some patterned stuff, and then edits it
- *	pseudo-randomly in ways which retain the basic pattern.
- *	Frequent GC's and self-checks are done, and execution
- *	halted either when an error is seen or when typein is detected.
- */
-char *xer_strs [] = {
-	"throne", "too", "sky", "fore", "fingers", "sex", "stone",
-	"010", "nazgul", "base"
-};
-
-
-vfy_exer(pf, gcfrq)
-int pf;			/* Nonzero to print notes as we go */
-int gcfrq;		/* Frequency of GC invocation (# passes per GC) */
-{	register int i, k, c;
-	long npass;
-	char *res, linbuf[100];
-	chroff lbeg, lend;
-	struct buffer *bfp, *make_buf();
-
-	/* Clean out kill buffer first */
-	for(i = 0; i < KILL_LEN; ++i)
-		kill_push((SBSTR *)0);
-
-	bfp = make_buf("**EXORCISE**");
-	chg_buf(bfp);
-	i = 2000;
-	e_gobol();
-	do {
-		ed_sins("Line ");
-		ed_sins(xer_strs[i%10]);
-		e_putc(LF);
-	  } while(--i);
-	if(pf) printf("Bufflen: %ld\n", e_blen());
-
-	/* Buffer now has stuff in it, start hacking. */
-	npass = 0;
-	srand(1);	/* Start random seed */
-	for(;;)
-	  {	if(tinwait() && (*asklin(linbuf)))
-		  {	printf("Typein stop.\n");
-			break;
-		  }
-		++npass;
-		printf(" Pass %ld",npass);
-		if(npass%gcfrq == 0)		/* Time to do a GC? */
-		  {
-			i = rand();		/* Level between 0-4 */
-			i = (i < 0 ? -i : i) % 5;
-			printf(" - GC lev %d\n", i);
-			sbx_comp(512,i);
-			goto xerchk;
-		  }
-
-		k = (i = rand())%1024;
-		if (i&020000) k = -k;
-		e_igoff(k);		/* Move randomly */
-		e_gobol();		/* Get stuff to flush */
-		lbeg = e_dot();
-		k = (i = rand())%64;
-		if(i&010000) k = -k;
-		e_igoff(k);
-		lend = e_nldot();
-		if(pf) printf(" Kill %ld/ %d;", lbeg, k);
-		ed_kill(lbeg, lend);
-		if(res = vfy_data(0))
-		  {	printf("XERR after kill: %s\n",res);
-			break;
-		  }
-		k = (i = rand())%2048;
-		if(i&04000) k = -k;
-		e_igoff(k);
-		e_gobol();
-		e_setcur();
-		if(pf) printf(" Yank %ld;", e_dot());
-		f_unkill();		/* Yank back */
-		if(res = vfy_data(0))
-		  {	printf("XERR after yank: %s\n",res);
-			break;
-		  }
-		last_cmd = YANKCMD;
-		for(i = rand()%4; i >= 0; --i)
-		  {	if(pf) printf(" Pop;");
-			f_unkpop();	/* Do meta-Y */
-			if(res = vfy_data(0))
-			  {	printf("XERR after pop: %s\n",res);
-				goto out;
-			  }
-		  }
-		if(rand()&07)	/* Slowly add stuff */
-		  {	if(pf) printf(" Add");
-			ed_sins("Line ");
-			ed_sins(xer_strs[rand()%10]);
-			e_putc(LF);
-			if(res = vfy_data(0))
-			  {	printf("XERR after ins: %s\n",res);
-				break;
-			  }
-		  }
-		printf("\n");
-
-		/* Okay, done with this pass edits, run through the
-		 * file to ensure pattern is still there
-		 */
-	xerchk:	e_gobob();
-		while((c = e_getc()) != EOF)
-			if(c == LF && (c = e_getc()) != EOF)
-			  {	if(         c != 'L'
-				  || e_getc() != 'i'
-				  || e_getc() != 'n'
-				  || e_getc() != 'e'
-				  || e_getc() != ' ')
-				  {	printf("XERR in pattern!\n");
-					goto out;
-				  }
-			  }
-	  }
-	/* User typein or error, stop. */
-out:	e_setcur();
-	redp(RD_SCREEN);
-	printf("Loop count = %ld\n",npass);
-}
-
-
-/* DB_PRWIND(win) - Print out stuff about given window
- */
-db_prwind(w)
-register struct window *w;
-{	register struct scr_line *s;
-	register int i;
-	char tstr[MAXLINE+MAXCHAR];
-	char *db_scflgs();
-
-	printf("cur_dot/ %ld  cur_buf/ %o cur_win/ %o\n",
-		cur_dot, cur_buf, cur_win);
-
-	printf("Window %o:\n", w);
-	printf("  next/ %o\n", w->w_next);
-	printf("  buf / %o\n", w->w_buf);
-	printf("  redp/ %o\n", w->w_redp);
-
-	printf("  topldot/ %ld\n", w->w_topldot);
-	printf("  dot / %ld\n", w->w_dot);
-	printf("  bmod/ %ld\n", w->w_bmod);
-	printf("  emod/ %ld\n", w->w_emod);
-	printf("  oldz/ %ld\n", w->w_oldz);
-
-	printf("  pos / %d\n", w->w_pos);
-	printf("  ht  / %d\n", w->w_ht);
-	printf("\
-#  Flags   Boff Len ! Cols Line\n");
-	for(i = w->w_pos; i < w->w_pos + w->w_ht; ++i)
-	  {	s = scr[i];
-		printf("%2d %-5.5s %6ld %3d %1d %4d ",
-			i, db_scflgs(s->sl_flg), s->sl_boff, s->sl_len,
-			s->sl_cont, s->sl_col);
-		strncpy(tstr, s->sl_line, MAXLINE);
-		tstr[s->sl_col] = 0;
-		printf("%-40.40s\n", tstr);
-		if(s->sl_flg&SL_MOD)
-		  {	printf("%26d ", s->sl_ncol);
-			strncpy(tstr, s->sl_nlin, MAXLINE);
-			tstr[s->sl_ncol] = 0;
-			printf("%-40.40s\n", tstr);
-		  }
-	  }
-}
-
-char *
-db_scflgs(flags)
-int flags;
-{	static char retstr[10];
-	register char *cp;
-	
-	cp = retstr;
-	if(flags&SL_MOD) *cp++ = 'M';
-	if(flags&SL_EOL) *cp++ = 'E';
-	*cp = 0;
-	return(retstr);
-}
-
-#endif /*FX_DEBUG*/
Index: trunk/minix/commands/elle/eedisp.c
===================================================================
--- trunk/minix/commands/elle/eedisp.c	(revision 9)
+++ 	(revision )
@@ -1,1727 +1,0 @@
-/* ELLE - Copyright 1982, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/* EEDISP	Redisplay and screen image routines
- */
-
-#if 0
-
-Note that there are several different types of "efficiency" criteria
-involved with respect to display updating:
-	(1) Terminal speed: minimize # characters output.
-	(2) Program speed: minimize CPU time used.
-	(3) Program size: minimize code and memory usage.
-	(4) Program modularity: minimize "hooks" between edit/display rtns.
-The current algorithms necessarily represent a compromise among all of
-these objectives.
-
-	The cursor is always located at CUR_DOT in the buffer CUR_BUF
-of the current window CUR_WIN.  This may not be true during function
-execution, but is always true at the top-level loop of command
-execution and redisplay.  In order to minimize update overhead, there
-are various flags or variables that the edit functions can use to
-communicate with "redisplay" and tell it how extensive the updates
-really need to be.
-
-	The entire known screen is always represented by a linked list
-of "windows"; updating the entire screen consists of separately
-updating every window on the list.  Windows can only be defined
-horizontally (as a range of lines), and must not overlap.  Each window
-has a buffer associated with it; the redisplay routines are responsible
-for displaying the contents of this buffer.
-
-	The lowest level data structure for the screen consists of an
-array of SCR_LINE structures, one for each possible physical screen
-line.  Each line structure has some flags, and pointers to three different
-representations of what should be on the line:
-	(1) SL_BOFF, SL_LEN - Defines the range of the buffer data which
-		this screen line should represent.
-		If the flag SL_EOL is set, this range ends with (and includes)
-		an EOL character.
-	(2) SL_LINE, SL_COL - Always keeps a copy of the current physical
-		screen line image.  Each byte is a character which occupies
-		only one column position on the screen.
-		If the flag SL_CSO is set, the line is in standout mode.
-	(3) SL_NLIN, SL_NCOL - The desired "new" screen line image.
-		This is only valid if the SL_MOD flag is set for the line,
-		indicating that these variables are set and point to the
-		new image of what the screen line should be.
-		If the flag SL_NSO is set, the new line should be in standout
-		mode.
-
-	Lastly there is a variable SL_CONT, which is needed for
-continuation of too-long logical lines over several physical lines.  If
-SL_CONT is:
-	0 = logical line fits entirely on the screen.
-		Either SL_EOL is set, or this line is ended by EOF
-		(end of the buffer).
-	1 = logical line is too long, but the last buffer char fits
-		entirely on this physical line.  SL_EOL is never set.
-	>1 = logical line is too long, and the last buffer char
-		"overruns" the end of the physical image; that is, part of
-		its representation is at the end of this line, but the
-		rest of it is at the start of the next line.  This can
-		only happen with "big" characters like TAB, ^A, ~^A, etc.
-		that need more than one column of representation.
-		There are SL_CONT-1 chars of overrun stored at the
-		end of SL_LINE (SL_NLIN if SL_MOD is set).
-		SL_EOL is never set.
-
-Note that if a line contains any overrun, and the next line is also
-part of the same window, the next line''s screen image will start with
-the SL_CONT-1 chars of overrun, rather than with the representation of
-that line''s first buffer char.
-
-	The "EOL" character on Unix systems is normally the new-line
-character '\n' (ASCII LF).  However, on other systems EOL may be
-indicated by a two-character CR-LF sequence, with either CR or LF alone
-considered to be "stray".  For this reason, the buffer flag B_EOLCRLF
-exists to control handling and display of EOLs.  If the flag is off,
-the EOL mode is LF, and there are no problems of splitting up characters.
-If the flag is on, however, the EOL mode is CRLF and the following rules
-hold:
-	EOL is the sequence CR-LF only.
-	LF without preceding CR is a "stray" LF, displayed as ^J.
-	CR without following LF is a "stray" CR, displayed as ^M.
-	Stray LFs and CRs do not terminate a logical line.
-	"End of Line" as a position is the dot just before the CR of a CR-LF.
-	"Beg of Line" as a position is the dot just after the LF of a CR-LF.
-	If the current dot is between a CR and LF, it is positioned at
-		the beginning of the physical screen line.
-
-
-SL_LINE and SL_COL are always accurate at every stage of processing.
-The other variables are accurate only after fix_wind has been called
-to "fix up" the line structures within a window.  If either
-RD_WINRES or RD_TMOD is set, none of these "other variables" should
-be depended on.  Any functions which are screen-relative (d_ type)
-must be sure that fix_wind is called if necessary, and must give
-preference to the "new" representation in SL_NLINE and SL_NCOL if
-SL_MOD is set.
-
-The flag RD_UPDWIN will be set by fix_wind if any lines have been
-modified.  Because fix_wind does not perform any actual display update,
-it is possible for functions to continue operating on the buffer and
-screen image without requiring that changes be displayed until there is
-nothing else left to do.  The routine upd_wind performs the actual
-terminal I/O necessary to update all the screen lines which have SL_MOD
-set.  Although the process of updating each line is currently
-non-interruptible, it is possible for upd_wind to interrupt itself
-between line updates if it detects that user input has happened, and it will
-return with the window only partially updated.  The screen image state
-will be completely consistent, however, and the RD_UPDWIN flag will
-remain set.
-
-Communication between the editing functions and the redisplay routines
-is limited as much as possible to the flags in the global RD_TYPE.
-Each window has its own copy of these flags in W_REDP, so that if
-windows are changed, the update hints for that window will be
-preserved.  The flags that can be set are listed below.  Those marked
-with "*" are global in nature; all others apply only within a single
-window (normally the current window).
-
-* RD_SCREEN - Total refresh.  Clears entire screen and redisplays all
-	windows.
-* RD_MODE - Mode line has changed, update it.
-* RD_CHKALL - Check ALL windows for any redisplay flags, and perform
-	any updates necessary.  Otherwise only the current (or specified)
-	window flags are checked.
-* RD_WINDS - Updates all windows.  Like RD_WINRES applied to all windows.
-  RD_WINRES - Update window (assume completely changed).
-  RD_TMOD - Text changed in this window.  The range of changes is
-	specified by W_BMOD and W_EMOD in combination with W_OLDZ.
-	Redisplay checking will limit itself to this range.
-	These vars are set by buf_tmod in the main command loop, and
-	reset by fix_wind when the window is fixed up.
-  RD_MOVE - Cursor has moved within current window; may have moved outside
-	the window.  W_DOT or CUR_DOT specifies where it should be.
-  RD_ILIN - Hint: Line insert done.  Currently no function sets this.
-  RD_DLIN - Hint: Line delete done.  Currently no function sets this.
-
-Internal flags:
-  RD_UPDWIN - Window needs updating. Used by fix_wind and upd_wind only.
-	Set when window has been "fixed up" and at least one screen
-	line was modified.
-  RD_FIXWIN - Supposed to mean window needs fixing (via call to fix_wind).
-	Not really used.
-
-Not implemented, may never be, but comments retained:
-  RD_WINCLR - Clear window (not entire screen)
-  RD_NEWWIN - Window has moved.  (not needed? Random stuff here)
-	a. to follow cursor; redisplay selects a new TOPLDOT.
-	b. randomly; new TOPLDOT furnished, use unless cursor out (then a).
-	c. find new TOPLDOT as directed (move up/down N screen lines)
-	For now, assume that (c) doesn''t apply (ie C-V uses (b) and sets
-	TOPLDOT itself).  So fix_wind selects new one only if cursor
-	won''t fit.  topldot takes precedence over sl_boff.
-
-#endif /*COMMENT*/
-
-
-/* Declarations and stuff */
-
-#include "elle.h"
-
-static int sctr();
-
-
-int trm_mode;	/* 0 = TTY in normal, non-edit mode.
-		 * 1 = TTY in edit mode.
-		 * -1 = TTY detached (hung up).
-		 * This flag is only used by the 3 routines below,
-		 * plus hup_exit.
-		 */
-
-/* REDP_INIT() - Called once-only at startup to initialize redisplay
- *	and terminal
- */
-redp_init ()
-{
-	trm_mode = 0;		/* Ensure flag says not in edit mode */
-	ts_init();		/* Get sys term info, set up stuff */
-	if (trm_ospeed == 0)	/* Default speed to 9600 if unknown */
-		trm_ospeed = 13;
-	t_init();		/* Identify term type, set term-dep stuff */
-	set_scr();		/* Set up software screen image */
-	set_tty();		/* Enter editing mode! */
-	redp(RD_SCREEN|RD_MODE); /* Force full re-display, new mode line */
-}
-
-/* SET_TTY() - Set up terminal modes for editing */
-
-set_tty()
-{	if(trm_mode) return;	/* Ignore if detached or in edit mode */
-	trm_mode++;
-	ts_enter();		/* Set up system's ideas about terminal */
-	t_enter();		/* Set terminal up for editing */
-}
-
-/* CLEAN_EXIT() - Restore original terminal modes.
- *	Returns previous state.
- */
-clean_exit ()
-{	register int prevstate = trm_mode;
-
-	if(prevstate > 0)	/* Ignore unless in editing mode */
-	  {	trm_mode = 0;
-		t_curpos(scr_ht-1, 0);	/* Go to screen bottom */
-		t_exit();		/* Clean up the terminal */
-		tbufls();		/* Force out all buffered output */
-		ts_exit();		/* Restore system's old term state */
-#if ! IMAGEN
-		writez(1,"\n");		/* Get fresh line using OS output */
-#endif /*-IMAGEN*/
-	  }
-	return prevstate;
-}
-
-/* SET_SCR() - Allocate screen image, set up screenline pointer table */
-
-set_scr()
-{	register struct scr_line **scrp, *stp;
-	register scrsiz;
-	char *sbuf;
-
-	scr_wd0 = scr_wid - 1;
-	scrsiz = scr_ht*(scr_wid+MAXCHAR);
-	if(  scr_ht  > MAXHT || scr_wid > MAXLINE)
-	  {	clean_exit();
-		printf("ELLE: %dx%d screen too big\n",scr_ht,scr_wid);
-		exit(1);
-	  }
-	if((stp = (struct scr_line *) calloc(scr_ht*sizeof(struct scr_line)
-							 + scrsiz*2,1)) == 0)
-	  {	clean_exit();
-		printf("ELLE: not enough memory\n");
-		exit(1);
-	  }
-	sbuf = (char *)stp + scr_ht*sizeof(struct scr_line);
-	for(scrp = &scr[0]; scrp < &scr[scr_ht]; sbuf += scr_wid+MAXCHAR)
-	  {	stp->sl_line = sbuf;
-		stp->sl_nlin = sbuf + scrsiz;
-		*scrp++ = stp++;
-	  }
-}
-
-
-/* REDISPLAY()
- *	Main function of redisplay routines.  Called every time ELLE
- * forces update of the terminal screen.  "rd_type" contains hints
- * as to what has changed or needs updating, to avoid wasting time
- * on things which don't need attention.
- */
-redisplay ()
-{	register struct window *w;
-	register i;
-	struct window *make_mode();
-
-	w = cur_win;
-	w->w_redp |= rd_type&RDS_WINFLGS;	/* Set cur_win's flags */
-	rd_type &= ~RDS_WINFLGS;		/* Leave only globals */
-
-	if (rd_type & RD_SCREEN)		/* Clear and refresh? */
-	  {
-		t_clear ();			/* Clear the screen */
-		for(i = scr_ht; --i >= 0;)	/* Clear screen image */
-			scr[i]->sl_col = 0;
-		if(w != ask_win)		/* If not in ask-window */
-		  {	chg_win(ask_win);
-			e_reset();		/* Then flush its contents */
-			chg_win(w);
-		  }
-		redp(RD_WINDS);		/* Update all windows */
-		rd_type &= ~RD_SCREEN;	/* If redisplay is interrupted, */
-					/* don't do it all over again */
-	  }
-	if (rd_type & RD_WINDS)		/* Update all windows? */
-	  {	redp(RD_CHKALL);
-		for (w = win_head; w; w = w -> w_next)	/* For each win */
-			w->w_redp |= RD_WINRES;
-		rd_type &= ~RD_WINDS;
-	  }
-	if (rd_type & RD_CHKALL)	/* Check all windows for changes? */
-	  {	for (w = win_head; w; w = w->w_next)	/* For each win */
-		    if(!(w->w_flags&W_MODE))		/* skip mode wins */
-			if(w->w_redp && upd_wind(w))
-				return;		/* May be interrupted */
-
-	  }
-
-	/* See if ask-window needs updating (to avoid RD_CHKALL in SAY) */
-	if((w = ask_win)->w_redp && upd_wind(w))
-		return;				/* May be interrupted */
-
-	/* Check current window for changes */
-	if((w = cur_win)->w_redp && upd_wind(w))
-		return;				/* May be interrupted */
-
-	/* Now update mode line(s) if necessary */
-	if(rd_type&RD_MODE)
-	  {
-		fupd_wind(w = make_mode(user_win));
-#if FX_2MODEWINDS
-		if (sep_win			/* If 2 windows */
-		  && (sep_win->w_flags&W_MODE)	/* and 2 mode windows */
-		  && (sep_win->w_redp || mode_win->w_redp))	/* Check */
-			fupd_wind(make_mode(oth_win));	/* Must update both */
-#endif
-	  }
-
-	/* Finally, leave cursor in right place. */
-	if(upd_curs(cur_dot)==0)		/* If something screwed up, */
-		errbarf("Cursor out of window");	/* Complain, */
-						/* and leave cursor at bot */
-	rd_type = 0;
-	tbufls();		/* Force out all terminal output */
-}
-
-fupd_wind(w)		/* Force window update */
-register struct window *w;
-{
-	w->w_redp |= RD_WINRES;
-	if(fix_wind(w))
-		upd_wind(w);
-}
-
-
-/*
- * UPD_CURS
- *	Move screen cursor to position of specified dot within current window.
- *	Returns 0 if dot was not within window (and cursor was not moved),
- *	otherwise returns 1 for success.
- */
-upd_curs(adot)
-chroff adot;
-{	register struct scr_line *s;
-	register int y, x;
-	chroff savdot;
-
-	if((y = d_line(adot)) < 0)
-		return(0);	/* Fail, not within window */
-	s = scr[y];		/* Now have line that dot is on */
-
-	/* Get proper offset for any continuation chars from prev line */
-	if(y > cur_win->w_pos)
-	  {	if((x = scr[y-1]->sl_cont) > 0)
-			x--;
-	  }
-	else x = 0;
-
-	savdot = e_dot();
-	e_go(s->sl_boff);
-	if((x = d_ncols((int)(adot - s->sl_boff),x)) < 0)
-	  {	/* If lost, assume it's because we are just after a char
-		** which has its representation continued onto next line.
-		** Move cursor to end of that continuation.
-		** d_line should have ensured that this is safe, but
-		** we double-check just to make sure.
-		*/
-		if((x = s->sl_cont) > 0)	/* Set X to end of cont */
-			--x;
-						/* and on next line down */
-		if(++y >= (cur_win->w_pos + cur_win->w_ht))
-		  {	e_go(savdot);		/* Failed, below window */
-			return(0);
-		  }
-	  }
-	e_go(savdot);
-	t_move(y, x);		/* Move cursor cleverly */
-	return(1);		/* Return success! */
-}
-
-/* Return line # for given dot, -1 if out of current window */
-d_line(cdot)
-chroff cdot;
-{	register struct scr_line *s;
-	register struct window *w;
-	register int i;
-	chroff savdot;
-	int bot;
-
-	w = cur_win;
-	i = w->w_pos;
-	bot = i + w->w_ht;
-	for(; i < bot; i++)
-	  {	s = scr[i];
-		if(cdot <= s->sl_boff)
-			goto gotl;
-	  }
-	/* End of window, repeat test specially for last line */
-	savdot = s->sl_boff + (chroff)s->sl_len;
-	if(cdot > savdot)	/* If past last char of last line */
-		return(-1);	/* then clearly outside */
-	--i;			/* Make i match s (bottom line) */
-	if(savdot != cdot)	/* If not exactly at end */
-		return(i);	/* Then we're inside for sure */
-	goto linbet;
-
-gotl:	if(s->sl_boff != cdot)	/* Are we on line boundary? */
-	  {	if(i <= w->w_pos)	/* No, off top of window? */
-			return(-1);	/* Above top, out for sure */
-		return(--i);
-	  }
-
-	/* Here, dot is exactly on line boundary, have to decide which
-	 * line it really belongs to.
-	 * Get S = pointer to line which cursor is at the end of.
-	 */
-	if(i <= w->w_pos)	/* Quick chk of trivial case, empty buffer */
-		return(i);
-	s = scr[--i];
-linbet:
-	if((s->sl_flg&SL_EOL)	/* If line has LF */
-	  || (s->sl_cont > 1))	/* or a continued char */
-		if(++i >= bot)		/* Then cursor is on next line */
-			return(-1);
-	return(i);
-}
-
-
-/* D_NCOLS - auxiliary for UPD_CURS.  (also called by indtion() in EEFD)
-**	 We are positioned at a place in the current buffer corresponding to
-** the beginning of the screen line, and given:
-**	lcnt - # of chars in buffer to move forward over
-**	ccol - current column position
-** Returns the new column position.  There are some special cases:
-**	Hits EOF: returns normally (new column position)
-**	Hits EOL: returns -1
-**	Position is past end of screen: returns -1
-** The buffer position has changed, but this is irrelevant as upd_curs
-** restores it just after the call.
-*/
-d_ncols(lcnt, ccol)
-int lcnt;
-int ccol;
-{	register int col, i;
-	register SBBUF *sb;
-	int c;
-	char tmp[MAXCHAR*2];	/* MAXCHAR is enough, but *2 just in case */
-
-	col = ccol;
-	sb = (SBBUF *) cur_buf;
-	if((i = lcnt) > 0)
-		do {	if((c = sb_getc(sb)) == EOF)
-				break;
-			/* Check to see if we've run into an EOL */
-#if FX_EOLMODE
-			if(c == CR)
-			  {	if(eolcrlf(sb))
-				  {	if((c = sb_getc(sb)) == LF) /* EOL? */
-					/* Real EOL.  Fail unless point
-					** is between CR and LF, in which case
-					** we return 0 (left margin).
-					*/
-					    return (i==1 ? 0 : -1);
-					/* Stray CR, back up & fall thru */
-					if(c != EOF)
-						sb_backc(sb);
-					c = CR;
-				  }
-			  } else if (c == LF)
-			  {	if(!eolcrlf(sb))	/* Real EOL? */
-					return -1;	/* Yes, fail */
-				/* If EOL mode is CRLF then hitting a LF
-				** can only happen for stray LFs (the
-				** previous check for CR takes care of
-				** CRLFs, and we never start scanning
-				** from the middle of a CRLF.
-				** Drop thru to show stray LF.
-				*/
-			  }
-#else
-			if(c == LF)
-				return(-1);
-#endif /*-FX_EOLMODE*/
-			col += sctr(c, tmp, col);
-		  } while(--i);
-	if(col > scr_wd0)
-		return(-1);
-	return(col);
-}
-
-/* D_LUPD - called from command level to completely redisplay a
- *	specific line on the screen.
- */
-d_lupd(w, idx)
-struct window *w;		/* Window this line belongs to, if known */
-int idx;
-{	t_curpos(idx, 0);
-	t_docleol();		/* Zap physical screen line */
-	scr[idx]->sl_col = 0;	/* Reflect it on phys screen image */
-	if(w)			/* Mark window for updating */
-		w->w_redp |= RD_WINRES;
-	else redp(RD_WINDS);	/* No window given, assume global */
-	redp(RD_MOVE);		/* Cursor has moved */
-}
-
-/* Clear a window completely the "quickest possible way" */
-clear_wind(w)
-register struct window *w;
-{
-	register int i = w->w_pos;	/* Top line of window */
-	register int bot = i + w->w_ht;	/* Bottom line (plus 1) of window */
-
-	for ( ; i < bot; ++i)
-		d_lupd(w, i);		/* Zap that line */
-}
-
-
-/* FIX_WIND - Sets up window screen image.  Does not generate any
- *	terminal output, but completely specifies what the new screen
- *	image should look like.
- *	Only the following 4 flags (lumped together in RDS_DOFIX)
- *	provoke fix_wind to do something:
- *		RD_MOVE - cursor has moved, must make sure still within
- *			window, and select new one if not.
- *		RD_TMOD - Text has been changed somewhere.
- *		RD_FIXWIN - Something requested that fix_wind fix things.
- *			Normally this is set when a new w_topldot is set.
- *		RD_WINRES - Window needs to be completely regenerated.
- * Results:
- *	Verifies that the current dot for the window (w_dot) exists.
- * If it is past the end of buffer, it is reset to EOB, and if this is
- * the current window, also updates cur_dot.  Otherwise, w_dot is never
- * adjusted; it is fix_wind's responsibility to make sure that the window
- * displays w_dot.
- *	Verifies that current w_topldot setting will result in cursor
- * (specified by w_dot) appearing within window.  If not, resets w_topldot
- * to an appropriate value (1/3 of way down from top, unless
- * moving up in which case 1/3 of way up from bottom).
- *	Makes sure that sl_boff, sl_len, sl_flg, and sl_cont
- * are set properly for all lines in window.  SL_MOD is set
- * for any lines requiring screen updates; these lines
- * also have sl_nlin and sl_ncol properly set.
- *	Note that sl_line and sl_col are NOT updated or changed, because
- * the physical screen has not been altered!
- *
- *	Returns 0 if no physical screen updates are needed (other than
- *		cursor moving and mode line updating).
- *	Returns 1 if screen updates are needed; RD_UPDWIN is set in w_redp,
- *		indicating that UPD_WIND should be called.
- */
-
-fix_wind (win)
-struct window *win;
-{
-	register struct window *w;
-	register int i;
-	register struct scr_line *s;
-	chroff cdot, bdelta, updot, sdot, newz;
-	chroff savdot;
-	struct buffer *savbuf;
-	int bot, nlmod, savi, contf, ocontf, randomflg;
-	int newpct;
-
-	if(!(w = win))
-		return(0);
-	if(!(w->w_redp&RDS_DOFIX))	/* Anything we need to do? */
-		return(0);		/* Nope, just ignore */
-
-	/* Find current dot for this window, and set up other stuff */
-	cdot = (w == cur_win) ? cur_dot : w->w_dot;
-	bot = w->w_pos + w->w_ht;
-	savbuf = cur_buf;
-	cur_buf = w->w_buf;
-	savdot = e_dot();
-	nlmod = 0;			/* No screen image changes so far */
-
-	/* Dot (ie cursor) is before current top?  If so, must move
-	 * backwards to find a new topldot.  Note also that buffer may have
-	 * changed so that either cdot or topldot points past EOF.
-	 */
-	if(w->w_topldot > cdot)
-	  {	/* Yes, must search backwards scrht/3 screen lines */
-		/* from cdot in order to find topldot. */
-		/* Don't bother updating scr stuff beforehand since we'll
-		 * have to revise everything anyway and can do it on the fly.
-		 */
-		i = (ev_mvpct * w->w_ht) / 100;
-		goto skipdn;
-
-	finddn:	i = ((100 - ev_mvpct) * w->w_ht) / 100;
-	skipdn:	if(i <= 0) i = 1;	/* Ensure # is reasonable */
-		else if(i >= w->w_ht) i = w->w_ht-1;
-		e_go(cdot);		/* Start here (may normalize to EOF)*/
-		d_backup(i ? i : 1);	/* Try to back up cleverly */
-		w->w_topldot = e_dot();
-		randomflg = 0;		/* We have some idea where we are */
-	fixall:		/* Entry point for later recheck, with randomflg==1 */
-		newz = e_blen();
-		if(newz < cdot)		/* Part of buf may have gone away */
-		  {			/* So normalize dot to EOF */
-			w->w_dot = cdot = newz;
-			if(w == cur_win)	/* Special check for fixing */
-				cur_dot = newz;	/* up cur_dot too! */
-			goto finddn;	/* and get a new top-of-window loc */
-		  }
-	retry:	i = w->w_pos;
-		contf = 0;
-		s = 0;
-		for(; i < bot; i++)
-		  {	nlmod++;
-			fix_line(scr[i], s);	/* s = 0 the first time */
-			s = scr[i];
-#if FX_SOWIND
-			if(w->w_flags & W_STANDOUT)
-				s->sl_flg |= SL_NSO;
-			else s->sl_flg &= ~SL_NSO;
-#endif
-		  }
-		if(inwinp(w,cdot))	/* Ensure in window */
-			goto mdone;
-		if(randomflg)		/* If jumped randomly, */
-		  {	i = (ev_nwpct * w->w_ht) / 100;
-			goto skipdn;	/* Try to select new window */
-		  }
-
-		/* We tried to back up and went too far. */
-		if(cdot < w->w_topldot)	/* Verify place is ahead */
-		  {	errbarf("fix_wind failed");	/* Didn't back up?? */
-			goto finddn;
-		  }
-		/* Move down one line and try again */
-		if(w->w_ht > 1)
-			w->w_topldot = scr[w->w_pos+1]->sl_boff;
-		else
-		  {	s = scr[w->w_pos];
-			w->w_topldot = s->sl_boff + s->sl_len;
-		  }
-		e_go(w->w_topldot);
-		goto retry;
-	  }
-
-	/* At some future point, could separate out processing for
-	 * RD_WINRES and RD_FIXWIN.  Latter flag implies only w_topldot
-	 * has changed (new window selected).  Former implies whole
-	 * buffer has been munged, and everything is completely redone.
-	 */
-	if(w->w_redp&(RD_WINRES|RD_FIXWIN))	/* If re-figuring whole window */
-	  {	e_go(w->w_topldot);	/* Start here, and */
-		randomflg = 1;		/* set up flag saying random jump */
-		goto fixall;		/* and go crunch all lines. */
-	  }
-	if((w->w_redp&RD_TMOD)==0)	/* If claims no text mods, */
-	  {	if(inwinp(w,cdot)==0)	/* Just verify cursor loc. */
-			goto finddn;	/* Sigh.... */
-		newz = w->w_oldz;	/* Win, set up for exit. */
-		goto done;
-	  }
-	/* Here only when RD_TMOD is set, indicating changes are
-	 * between range variables.
-	 */
-	/* Find upper bound of any mods.  This is a little gross in the
-	 * speed dept and some faster way should perhaps be devised.
-	 * In particular the main loop should incrementally keep track of
-	 * buffer size, and should set a flag RD_TEXT if anything has
-	 * actually been changed.  Edit routines should have lots of
-	 * flags available to tell main loop more precisely what they did,
-	 * so main loop can take care of updating b/emod and stuff.
-	 */
-	if((newz = e_blen()) == 0)
-		goto finddn;		/* Ensure blank window is cleared */
-	bdelta = newz - w->w_oldz;
-	if((updot = newz) > w->w_emod)
-		updot -= w->w_emod;
-	if(bdelta == 0 && (updot == w->w_bmod))
-		goto inwinq;
-
-	/* Could also check for updot < w_topldot (changes above win)
-	 * or sl_boff+sl_len < w_bmod  (changes below win) but those
-	 * cases are probably pretty rare.
-	 */
-	/* First find line where changes start */
-	for(i = w->w_pos; i < bot; i++)
-	  {	s = scr[i];
-		if(w->w_bmod <= s->sl_boff)	/* Changes prior to this? */
-			break;
-	  }
-	if(i >= bot)			/* Test last line specially */
-	  {	if(w->w_bmod > (s->sl_boff + (chroff)s->sl_len))
-			goto inwinq;	/* Outside window */
-					/* Last line changed, hack it */
-	  }
-	if(i > w->w_pos			/* If we have a prev line */
-	  && (s->sl_len == 0		/* and we're at EOF, */
-	    || w->w_bmod != s->sl_boff	/* or not at start of line */
-	    || scr[i-1]->sl_cont))	/* or prev line is continuation */
-		s = scr[--i];		/* then it's prev line we want */
-
-	/* I has index for screen line changes begin on; S has ptr.
-	 * This piece of code handles case where buffer has been modified
-	 * starting at BMOD, and BDELTA chars have been inserted/deleted;
-	 * range of changes ends at UPDOT.
-	 */
-	savi = i;
-	while(++i < bot)
-		scr[i]->sl_boff += bdelta;
-	i = savi;
-
-	/* Now start with 1st changed line and start figuring new line
-	 * lengths.  Stop when hit end, or past updot and boff is correct
-	 * for start of line.
-	 */
-	/* can improve this by jumping out when past emod, and testing for
-	 * an EOL - then know stuff has to match someplace, so look for that.
-	 * could then simply update lengths or something?
-	 */
-	if(i > w->w_pos)	/* Find # cols already there from prev line*/
-		contf = scr[i-1]->sl_cont;
-	else contf = 0;
-	ocontf = 1;			/* Fake it so always update 1st line*/
-	e_go(sdot = s->sl_boff);
-	for(; i < bot; i++)
-	  {	s = scr[i];
-		if(updot <= sdot	/* If past changed stuff */
-		  && sdot == s->sl_boff	/* and locs are lined up */
-		  && contf == 0		/* and previous line clean */
-		  && ocontf == 0)	/* (both old and new images) */
-			break;		/* Then done. */
-		nlmod++;
-		ocontf = s->sl_cont;	/* Save old-image contf value */
-		fix_line(s, (i > w->w_pos) ? scr[i-1] : 0);
-#if FX_SOWIND
-		if(w->w_flags & W_STANDOUT)
-			s->sl_flg |= SL_NSO;
-		else s->sl_flg &= ~SL_NSO;
-#endif
-		sdot = e_dot();
-		contf = s->sl_cont;	/* Get new-image contf value */
-	  }
-	if(inwinp(w,cdot))	/* OK, screen fixed, see if cursor inside */
-		goto mdone;
-	goto finddn;
-
-	/* Test if still in window and dispatch appropriately */
-inwinq:	if(inwinp(w,cdot))
-		goto done;
-	else goto finddn;
-
-	/* Come here when done, after mods made to window.
-	 * Calculate new %-of-buffer position for window's view, and
-	 * see if it's changed from current %.
-	 */
-mdone:	if(w != cur_win) goto done;	/* If not current window, ignore */
-	s = scr[bot-1];
-	if((s->sl_boff + (chroff)s->sl_len) >= newz)
-		if(w->w_topldot) newpct = 150;	/* BOT */
-		else newpct = 200;		/* ALL */
-	else if(w->w_topldot == 0)
-		newpct = -1;			/* TOP */
-	else		/* NOTE: This won't work if topldot is huge */
-		newpct = (w->w_topldot*100)/newz;	/* nn% */
-	if(newpct != w->w_pct)		/* OK, now compare with old % */
-	  {	w->w_pct = newpct;	/* Different, must set and */
-		redp(RD_MODE);		/* invoke redisplay of mode line! */
-	  }
-
-done:	w->w_bmod = -1;		/* To indicate vars not set */
-	w->w_oldz = newz;
-	w->w_redp &= ~RDS_DOFIX;	/* Clear flags that invoked us */
-	if(nlmod)
-		w->w_redp |= RD_UPDWIN;	/* Say stuff to be updated */
-	e_go(savdot);
-	cur_buf = savbuf;
-	return(nlmod);
-}
-
-/* INWINP - Returns true if given dot is inside given window.
- */
-inwinp(win,cdot)
-struct window *win;
-chroff cdot;
-{	register struct scr_line *s;
-	register struct window *w;
-	chroff sdot;
-
-	w = win;
-	if(cdot < w->w_topldot)
-		return(0);
-	s = scr[(w->w_pos + w->w_ht) - 1];
-	sdot = s->sl_boff + (chroff)s->sl_len;
-	if(cdot < sdot)
-		return(1);		/* Yup, inside window. */
-	if(cdot > sdot)
-		return(0);
-
-	/* Dot is exactly at end of window, must check further. */
-	if(s->sl_len		/* If line exists, */
-	 && ((s->sl_flg&SL_EOL)	/* and ends in LF, */
-	    || s->sl_cont > 1))	/* or sl_cont > 1, lose. */
-		return(0);
-	return(1);		/* Else inside, win. */
-}
-
-
-/*
- * UPD_WIND
- *	If argument 0, assumes cur_win and DOESN'T interrupt if input
- *	detected.
- */
-
-upd_wind(win)
-struct window *win;
-{	register int i, n;
-	register struct scr_line *s;
-	struct window *w;
-	int top, bot, dspf, num, isave, noicost, nodcost, iline, dline;
-#if FX_SOWIND
-	int oldso;
-#endif
-#if IMAGEN
-	int origdspf;
-	char redpmsg[128];
-#endif /*IMAGEN*/
-
-	if((w=win)==0)
-		w = cur_win;
-	dspf = w->w_redp;		/* Get update flags for window */
-#if IMAGEN
-	origdspf = dspf;
-#endif /*IMAGEN*/
-	if(w == cur_win)		/* If updating current window, */
-		dspf |= rd_type;	/* merge in global flags */
-	if((dspf &= RDS_WINFLGS) == 0)	/* Well, it might happen sometimes */
-		goto zdone;
-	w->w_redp = dspf;
-	if(dspf&(RD_WINRES|RD_TMOD|RD_MOVE|RD_FIXWIN))
-	  {	fix_wind(w);		/* May set some flags, so */
-		dspf = w->w_redp;	/* get them back... */
-	  }
-	if((dspf&RD_UPDWIN)==0)		/* Must ask for update! */
-		goto zdone;
-#if IMAGEN
-	if (dbg_redp)
-	  {	sprintf(redpmsg,
-			"buffer: %14s, rd_type: %06o, w_redp: %06o, dspf: %06o",
-			w->w_buf->b_name, rd_type, origdspf, dspf);
-		barf2(redpmsg);
-	  }
-#endif /*IMAGEN*/
-
-	/* Assume screen structure set up by FIX_WIND, just go
-	 * effect change for every line modified.
-	 */
-#if FX_SOWIND
-	oldso = t_dostandout((w->w_flags&W_STANDOUT)? 1:0);
-#endif
-	top = w->w_pos;
-	bot = top + w->w_ht;
-	for(i = top; i < bot; ++i)
-	  if((s = scr[i])->sl_flg&SL_MOD)
-	  {	if(win && tinwait())	/* If OK, stop if any chars typed */
-		  {	tbufls();
-			w->w_redp = dspf;
-#if FX_SOWIND
-			t_dostandout(oldso);
-#endif
-			return(1);	/* Return immediately, say int'd */
-		  }
-		if(slineq(s,s))		/* Compare old with new */
-			goto ldone;	/* Lines equal, no update needed */
-	
-#if IMAGEN
-		/* If hint says redo entirely */
-		if (dspf & RD_REDO)
-		  {	s->sl_flg |= SL_REDO;	 /* Do "fast update" */
-			goto nodel;		/* Just go update line */
-		  }
-#endif /*IMAGEN*/
-		if((trm_flags&TF_IDLIN)==0)
-			goto nodel;		/* Just go update line */
-
-
-		/* Check for I/D line.  If no hints exist, check for both
-		 * insert and delete.
-		 */
-		if((dspf&(RD_ILIN|RD_DLIN))==0)
-			dspf |= RD_ILIN|RD_DLIN;
-		noicost = 0;
-		nodcost = 0;
-
-		/* Check for insert line.  See if the current old screen
-		 * line is duplicated among any of the new lines which
-		 * follow it.  If a match is found, keep looking and add
-		 * up the number of characters in the matching lines.
-		 */
-		if(dspf&RD_ILIN)
-		  {
-			/* See if this old screen line is needed elsewhere */
-			if(s->sl_col == 0)	/* Ignore if blank */
-				goto noins;
-			
-			for(n = i+1; n < bot; n++)
-			  {	if((scr[n]->sl_flg&SL_MOD)==0)
-					break;
-				if(slineq(s, scr[n]))	/* Old, new */
-				  {	if(!noicost) iline = n;	/* 1st time */
-					noicost += s->sl_col;
-					s++;
-				  }
-				else if(noicost) break;
-			  }
-			if(!noicost)		/* If no match, forget it */
-				goto noins;	/* S will not have changed. */
-			s = scr[i];		/* Restore S */
-			n = iline;		/* Have matches, get index
-						 * of first matching line */
-
-			/* Heuristic to decide whether to perform
-			 * insert-line operation.  Kind of stupid, but
-			 * good enough for now.
-			 */
-			num = (n-i)*(tvc_ldn+tvc_lin) + (tvc_li + tvc_ld);
-			if((n-i) >= (scr_ht-(ECHOLINES+3))
-						/* Don't move lines all the
-						 * way down full screen! */
-			  || num >= noicost)	/* Compare cost with estimated
-						 * cost of not doing insert.*/
-				goto noins;
-
-			/* Insert lines! */
-			dspf &= ~RD_ILIN;
-			inslin(i, n - i, w);
-			for(; i < n; i++)	/* Update intervening lines */
-				upd_line (i);
-			goto ldone;
-		  }
-noins:
-
-		/* Check for delete line.  See if the new screen line
-		 * is duplicated among any of the old lines already on
-		 * the screen.  If a match is found, keep looking and add
-		 * up the number of characters in the matching lines.
-		 */
-		if(dspf&RD_DLIN)
-		  {
-			/* See if the new line already exists elsewhere */
-			if(s->sl_ncol == 0)	/* Ignore blank lines */
-				goto nodel;
-			for (n = i + 1; n < bot; n++)
-			  {	if((scr[n]->sl_flg&SL_MOD)==0)
-					break;
-				if(slineq(scr[n],s))	/* Old, new */
-				  {	if(!nodcost) dline = n;	/* 1st time */
- 					nodcost += s->sl_ncol;
-					s++;
-				  }
-				else if(nodcost) break;
-			  }
-			if(!nodcost)		/* If no match, forget it */
-				goto nodel;	/* S will not have changed. */
-			s = scr[i];		/* Restore S */
-			n = dline;		/* Index of 1st match */
-
-			/* Heuristic to decide whether to perform
-			 * delete-line operation.  Same hack as for
-			 * insert-line.
-			 */
-			num = (n-i)*(tvc_ldn+tvc_lin) + (tvc_li + tvc_ld);
-			if((n-i) >= (scr_ht-(ECHOLINES+3))
-			  || num >= nodcost)
-				goto nodel;
-
-			/* Delete lines! */
-			dspf &= ~RD_DLIN;
-			dellin(i, n - i, w);
-			goto ldone;
-		  }
-nodel:
-		/* All failed, so just update line */
-		upd_line(i);
-ldone:		s->sl_flg &= ~SL_MOD;	/* Clear mod flag */
-	  }
-done:
-#if FX_SOWIND
-	t_dostandout(oldso);	/* Back to previous mode */
-#endif
-zdone:	w->w_redp = 0;
-	return(0);		/* Say completed */
-}
-
-
-
-/*
- * SLINEQ - Compare old, new screen image lines.  If new line doesn't
- *	have the modified flag set, use its old image.
- *	If the standout mode differs, always fails.
- */
-
-slineq(olds, news)
-struct scr_line *olds;
-struct scr_line *news;
-{	register char *cpo, *cpn;
-	register int cnt;
-
-	cpo = (char *)news;
-	if(((struct scr_line *)cpo)->sl_flg&SL_MOD)
-	  {	cnt = ((struct scr_line *)cpo)->sl_ncol;
-		cpn = ((struct scr_line *)cpo)->sl_nlin;
-#if FX_SOWIND		/* Mode of old must match mode of new */
-		if(((olds->sl_flg & SL_CSO)==0) !=
-			((((struct scr_line *)cpo)->sl_flg & SL_NSO)==0))
-			return 0;
-#endif
-	  }
-	else
-	  {	cnt = ((struct scr_line *)cpo)->sl_col;
-		cpn = ((struct scr_line *)cpo)->sl_line;
-#if FX_SOWIND		/* Modes of current lines must match */
-		if((olds->sl_flg & SL_CSO) !=
-			(((struct scr_line *)cpo)->sl_flg & SL_CSO))
-			return 0;
-#endif
-	  }
-
-	/* Crufty match stuff */
-	if(cnt != olds->sl_col)
-		return(0);
-	if(cnt)
-	  {	cpo = olds->sl_line;
-		do { if(*cpo++ != *cpn++)
-			return(0);
-		  } while(--cnt);
-	  }
-	return(1);
-}
-
-
-/* UPD_LINE(lineno) - Effects the update of a physical screen line,
- *	assuming that the screen line structure for that line has been
- *	properly set up by fix_wind.  It cannot be interrupted by typein.
- *	Does a lot of work to check out optimization for char I/D.
- *	Someday it could also check out the possibility of doing a CLEOL at
- *	some point to reduce the number of spaces that need to be output.
- */
-
-upd_line(y)
-int y;
-{	register i;
-	register char *sci, *cp;
-	struct scr_line *s;
-
-	int xpos;			/* actual screen position */
-	int c, c2, p2, cmpcost, delcost;
-	int savc, ocol, ncol;
-	char *savcp, *savsci;
-#if FX_SOWIND
-	int oldso, newso;
-	int writall = 0;
-#endif
-
-	s = scr[y];
-	savsci = sci = s->sl_line;	/* What is currently on the screen */
-#if IMAGEN
-	if (s->sl_flg & SL_REDO)
-	  {	/* Check for line-redo flag */
-		s->sl_flg &= ~SL_REDO;	/* Clear it: we are handling it */
-		writall = 1;	/* Re-do this line completely */
-		t_move(y, 0);
-		t_docleol();
-		s->sl_col = 0;
-	  }
-#endif /*IMAGEN*/
-
-#if FX_SOWIND
-	/* See whether modes of the lines are the same or not. */
-	newso = (s->sl_flg & SL_NSO)!=0;	/* Get new mode (true if SO)*/
-	if(((s->sl_flg & SL_CSO)!=0) !=	newso)
-	  {	t_move(y, 0);		/* Not same, must zap existing line */
-		t_docleol();
-		s->sl_col = 0;
-		writall = newso;	/* Output all if SO is new mode */
-	  }
-	oldso = t_dostandout(newso);	/* Get in right mode */
-#endif
-
-	ocol = s->sl_col;
-	savcp = cp = s->sl_nlin;
-	ncol = s->sl_ncol;
-
-	/* Find leading equalness */
-	i = ocol;
-	if(i > ncol) i = ncol;		/* Use minimum count */
-	if(i)
-	  {	do { if(*cp++ != *sci++)
-			  {	--cp;
-				break;
-			  }
-		  } while(--i);
-		i = cp - savcp;
-		sci = savsci;		/* Restore ptr to beg of cur line */
-	  }
-
-	/* From here on, "i" is now the x-coordinate (column addr)
-	 * of the first position that doesn't match.  "cp" points to
-	 * the first nonmatching char in the new line image.
-	 */
-#if COHERENT		/* Has direct video interface capability */
-	if(trm_flags&TF_DIRVID)
-	  {	if(ncol < ocol)
-		  {	/* Flesh out new line to completely replace old */
-			fillsp(&s->sl_nlin[ncol], ocol-ncol);
-			ncol = ocol;
-		  }
-		/* Spit out changed stuff.  t_direct will handle the
-		 * case where i == ncol (ie no changes needed).
-		 */
-		t_direct(y,i,cp,ncol-i);
-		goto done;
-	  }
-#endif /*COHERENT*/
-
-	if(i == ncol)			/* Matched up to end of new line? */
-		goto idone;		/* Yes, can skip big loop! */
-
-#if FX_SOWIND
-	if(writall)			/* If simply writing everything...*/
-	  {	t_move(y, 0);
-		tputn(cp, ncol);	/* Output them all */
-		curs_col = ncol;	/* Update cursor position */
-		goto idone;		/* then wrap up! */
-	  }
-#endif
-
-	/* Now must fill out remainder of old line with blanks. */
-	if(ocol < scr_wid)
-	  {
-#if FX_SOWIND
-		if(newso) fillset(&sci[ocol], scr_wid-ocol, 0);
-		else
-#endif
-		fillsp(&sci[ocol],scr_wid-ocol);	/* Fill out */
-	  }
-
-	/******  Main update loop. ******/
-	for (; i < ncol; i++)
-	  {	c = *cp++;		/* Note *CP will point to next */
-		if(c == sci[i])
-			continue;
-		if(i >= ocol)		/* Past EOL of old line? */
-		  {
-putin:			sci[i] = c;
-			if(y != curs_lin || i != curs_col)
-				t_move(y, i);
-			tput(c);
-			curs_col++;
-			continue;
-		  }
-
-		if((trm_flags&TF_IDCHR)==0)	/* Replace */
-			goto putin;
-
-		/* Do checking to see whether char I/D operations should
-		 * be invoked.  This code is quite CPU intensive and
-		 * can cause noticeable pauses if run on a slow CPU with
-		 * a fast (9600) terminal line.  The optimization tradeoff
-		 * seems worthwhile most of the time, however.
-		 */
-		cmpcost = 0;		/* Default is don't compare */
-		if(ncol == ocol)	/* If line lengths same, must chk */
-		  {
-/*			if(ncol >= scr_wid) */	/* If line overrun, compare */
-				cmpcost++;
-		  }
-#if 0
-If ncol == ocol, have problem with tabs:
-	If don''t use I/D char, but tabs exist, lots of wasteful update.
-	If DO use I/D char, and no tabs exist, potential for mistakenly
-		using I/D when didn''t have to.  Not too bad, though?
-	If DO use I/D char, then mild screw when inserting/deleting
-		just before a tab, since could have just overwritten,
-		but I/D insists on jerking things around.
-	Insert test:
-		If old char was space, replace? Problem: will cause cursor
-		jump if really should have shifted a long run of spaces.
-		But that is probably okay.
-	Delete test:
-		If new char is space, replace? again, will cause cursor jump
-		with long run of spaces.
-#endif /*COMMENT*/
-
-		if(ncol < ocol || cmpcost)	/* Try delete-char */
-		  {
-			/* Search old for match of c and nextc */
-dodel:			savc = c;
-			if(i >= ncol-1)
-				goto putin;
-			c2 = *cp;
-			if(c == SP && ncol == ocol)
-				goto tryins;
-			p2 = i;
-			for(;;)
-			  {	if(c == sci[i] && c2 == sci[i+1])
-					break;
-				if(++i < ocol)
-					continue;
-				i = p2;
-				if(cmpcost) {cmpcost = 0; goto tryins;}
-				goto putin;
-			  }
-			/* Find # chars that match (i.e. will be saved) */
-			for(c=1; (i+c < ncol) && (sci[i+c] == cp[c-1]); c++);
-			delcost = tvc_cd + tvc_cdn*(i - p2);
-			if(delcost >= c)
-			  {	c = savc;
-				i = p2;
-				if(cmpcost) { cmpcost = 0; goto tryins;}
-				goto putin;	/* Punt */
-			  }
-			if(cmpcost)
-			  {	c = savc; i = p2;
-				goto tryins;
-			  }
-			t_move(y, p2);
-			c = i - p2;	/* Find # chars to flush */
-			strncpy(&sci[p2],&sci[i], ocol-i);
-			ocol -= c;
-			fillsp(&sci[ocol], c);
-			i = p2;			/* Restore i */
-			t_delchr(c);		/* Flush this many cols */
-			continue;
-		  }
-
-		/* Try ins-char */
-		/* Search new for match of i and i+1 */
-		/* Note this cannot be used while in standout mode, since
-		** the new spaces created will probably be in the wrong mode.
-		*/
-tryins:
-#if FX_SOWIND
-		if(newso) goto putin;
-#endif
-		if(i+1 >= ocol)
-			goto putin;
-
-		savc = c;
-		savcp = cp;
-		c2 = sci[i+1];
-		if(sci[i] == SP && ncol == ocol)
-			goto putin;
-		xpos = i;		/* save current col */
-		i++;
-		for(;;)
-		  {	if(i >= ncol) goto puntx;
-			c = *cp++;
-inlp2:			if(c != sci[xpos])
-			  {	if(i > scr_wid) goto puntx;
-				i++;
-				continue;
-			  }
-			if(i >= ncol) goto puntx;
-			c = *cp++;
-			if(c != c2)
-			  {	i++;		/* Allow for previous c */
-				goto inlp2;	/* which is always 1 */
-			  }
-			break;
-		  }
-		if(i >= scr_wid) goto puntx;
-
-		/* Find how many chars match (i.e. will be saved) */
-		for(c = 2; xpos+c < ncol && sci[xpos+c] == *cp++; c++);
-		if((p2 = tvc_ci + tvc_cin*(i - xpos)) >= c)
-			goto puntx;	/* Not worth it... */
-		if(cmpcost && p2 >= delcost)
-			goto puntx;	/* Do delchr instead */
-
-		/* We've decided to insert some chars! */
-		i -= xpos;		/* Get # char positions to insert */
-		cp = savcp;		/* Get ptr to newline string */
-		--cp;			/* Point at 1st char to insert */
-					/* Make room in scr array */
-		inspc(&sci[xpos],
-			&sci[(ocol+i >= scr_wid) ? scr_wid-i : ocol], i);
-		ocol += i;		/* Update size of old line */
-		strncpy(&sci[xpos], cp, i);	/* Copy all inserted chars */
-
-		t_move(y, xpos);	/* Now ensure in right place */
-		t_inschr(i, cp);	/* and insert string onto screen! */
-
-		cp += i;		/* Update source ptr */
-		cp++;			/* Point to next char */
-		i += xpos;
-		continue;		/* Now continue loop! */
-
-	puntx:	i = xpos;
-		c = savc;
-		cp = savcp;
-		if(cmpcost) { cmpcost = 0; goto dodel;}
-		goto putin;
-	  }
-
-	/* All done putting up new stuff.  Now see if any remaining old
-	** stuff needs to be cleared from end of line.
-	*/
-idone:	if(i < ocol)		/* if still have text to right, */
-	  {	t_move(y,i);	/* move there */
-		t_docleol();	/* and clear old stuff. */
-	  }
-
-done:	s->sl_line = s->sl_nlin;	/* Replace old image by new */
-	s->sl_col = s->sl_ncol;
-	s->sl_nlin = sci;
-	s->sl_flg &= ~SL_MOD;
-#if FX_SOWIND			/* Copy standout mode to current */
-	if(newso) s->sl_flg |= SL_CSO;
-	else s->sl_flg &= ~SL_CSO;
-#endif
-}
-
-#if FX_SOWIND
-fillset(str,cnt,c)
-char *str;
-int cnt;
-int c;
-{	register int n;
-	register char *cp;
-	if((n = cnt) <= 0) return;
-	cp = str;
-	do{ *cp++ = c;
-	  } while(--n);
-}
-#endif
-
-fillsp(str,cnt)
-char *str;
-int cnt;
-{	register int n;
-	register char *cp;
-	if((n = cnt) <= 0) return;
-	cp = str;
-	do{ *cp++ = SP;
-	  } while(--n);
-}
-inspc(cp0, cpl, cnt)
-char *cp0, *cpl;
-int cnt;
-{	register char *cp, *cp2;
-	register n;
-	if((n = cnt) <= 0) return;
-	cp = cpl;		/* ptr to last+1 char in string */
-	cp2 = cp+n;		/* ptr to loc+1 to move to */
-	n = cp - cp0;		/* # chars to move */
-	do *--cp2 = *--cp;
-	while(--n);
-	n = cnt;		/* Now fill gap with spaces */
-	do *cp++ = SP;
-	while(--n);
-}
-
-
-/* FIX_LINE - Fixes up new screen image for a single line.  Does not
- *	do any actual terminal I/O, and does not change the old screen
- *	image.  Assumes that previous line (if any is furnished) has
- *	already been properly set up.
- */
-
-int sctreol = 0;	/* Ugly crock for talking to sctrin() */
-			/* 0 = no EOL seen, 1 = EOL seen, -1 = EOF seen */
-fix_line(slp, olds)
-struct scr_line *slp;
-struct scr_line *olds;
-{	register struct scr_line *s;
-	register int col, scrw;
-	char *cp;
-	int ch;
-
-	col = 0;
-	scrw = scr_wid;
-	cp = slp->sl_nlin;
-	if((s = olds) && (col = s->sl_cont))
-	  {	if(--col)
-			strncpy(cp, (s->sl_flg&SL_MOD) ?
-					&s->sl_nlin[scrw]
-					 : &s->sl_line[scrw], col);
-		cp += col;
-	  }
-	scrw--;			/* Note now using scr_wd0 !! */
-	s = slp;
-	s->sl_boff = e_dot();
-	col = sctrin(cp, scrw, col);
-	if (col < scrw || sctreol)	/* Does line need continuation mark? */
-		s->sl_cont = 0;		/* No, say no cont chars */
-	else {
-		/* Yes, find # cols of overflow.  If not 0, must be > 0 */
-		/* and char is a biggie.  Make room for continuation chars */
-		if(col -= scrw)
-			inspc(&s->sl_nlin[scrw],&s->sl_nlin[scrw+col], 1);
-		s->sl_cont = col+1;		/* # cont chars, plus 1 */
-		s->sl_nlin[scrw] = CI_CLINE;	/* Display "contin" mark */
-		col = scrw+1;
-	  }
-
-	s->sl_ncol = col;
-	s->sl_len = e_dot() - s->sl_boff;
-	s->sl_flg |= (SL_MOD|SL_EOL);	/* Say new, and assume line has EOL */
-	if(sctreol <= 0)		/* unless it doesn't really */
-		s->sl_flg &= ~SL_EOL;	/* in which case turn off flag */
-	return;
-}
-
-/* SCTRIN - auxiliary for FIX_LINE.
- *	lim - # cols chars are allowed to use
- *	ccol - current column (0 = bol)
- * Returns when see EOL or EOF, or
- *	when all columns have been filled up.  Retval-ccol = # overflow.
- *	Note that any overflow is indivisible (i.e. a char with a
- *	multi-col representation is responsible for the overflow).
- *	So, overflow = 0 means next char would be in 1st non-ex column
- *	and overflow > 0 means last char read has extra columns, but
- *	it did start within bounds.
- */
-sctrin(to, lim, ccol)
-char *to;
-int lim;
-int ccol;
-{	register SBBUF *sb;
-	register col, cnt;
-
-	sb = (SBBUF *) cur_buf;
-	col = ccol;
-	sctreol = 0;		/* No EOL or EOF seen */
-	do
-	  {	cnt = sb_getc(sb);
-		if(cnt == EOF)
-		  {	--sctreol;	/* Say EOF seen! */
-			return(col);
-		  }
-#if FX_EOLMODE
-		if(cnt == CR)		/* Possible EOL? */
-		  {	if(eolcrlf(sb))
-			  {	if((cnt = sb_getc(sb)) == LF)	/* Real EOL? */
-				  {	sctreol++;
-					return col;	/* Yes, return */
-				  }
-				/* Stray CR, back up & fall thru */
-				if(cnt != EOF)
-					sb_backc(sb);
-				cnt = CR;	/* Show stray CR */
-			  }
-		  } else if (cnt == LF)
-		  {	if(!eolcrlf(sb))	/* Real EOL? */
-			  {	sctreol++;
-				return col;	/* Yes, return */
-			  }
-			/* If EOL mode is CRLF then hitting a LF
-			** can only happen for stray LFs (the
-			** previous check for CR takes care of
-			** CRLFs, and we never start scanning
-			** from the middle of a CRLF.
-			** Drop thru to show stray LF.
-			*/
-		  }
-#else
-		if(cnt == LF)
-		  {	sctreol++;	/* Say EOL seen */
-			return col;
-		  }
-#endif /*_FX_EOLMODE*/
-		cnt = sctr(cnt, to, col);
-		to += cnt;
-		col += cnt;
-	  } while(col < lim);
-
-	/* If we're stopping because last char put us precisely at the
-	** end of the line, make a further check to see whether an EOL
-	** is next.  If so, we can include that in the line since it
-	** doesn't need any more columns for representation!
-	*/
-	if (col == lim)		/* If stopping exactly at edge of screen */
-	    switch (sb_getc(sb))	/* Check out next char */
-	      {	case EOF:
-			--sctreol;		/* Yes, note EOF seen */
-			break;			/* and can return immed */
-#if FX_EOLMODE
-		case CR:		/* Possible EOL? */
-			if(eolcrlf(sb))
-			  {	if((cnt = sb_getc(sb)) == LF)	/* Real EOL? */
-				  {	sctreol++;	/* Yes, set flag */
-					break;		/* and return */
-				  }
-				/* Stray CR, back up & fall thru */
-				if(cnt != EOF)		/* Back up char that */
-					sb_backc(sb);	/* came after the CR */
-				sb_rgetc(sb);		/* Then back over CR */
-				break;
-			  }
-			sb_backc(sb);
-			break;
-		case LF:
-			if(!eolcrlf(sb))	/* Real EOL? */
-			  {	sctreol++;	/* Yes, set flag */
-				break;		/* and return */
-			  }
-			/* If EOL mode is CRLF then hitting a LF
-			** can only happen for stray LFs (the
-			** previous check for CR takes care of
-			** CRLFs, and we never start scanning
-			** from the middle of a CRLF.
-			** Drop thru into default to back up over LF.
-			*/
-#else
-		case LF:
-			sctreol++;	/* Say EOL seen */
-			break;		/* and return */
-#endif /*-FX_EOLMODE*/
-		default:
-			sb_backc(sb);		/* Back up over random char */
-			break;
-	    }
-	return(col);
-}
-
-
-/* SCTR - Screen Char TRanslation routine.
-**	This routine is completely responsible for the way a buffer char is
-** displayed on the screen.  Given a char and the current column position,
-** it stores the representation using the given pointer and returns
-** the number of chars (columns) used by the representation.
-**	Normal printing chars (plus space) are simply themselves.
-**	TAB is a variable number of spaces depending on the column pos.
-**		(we use standard tabstops of 8)
-**	All control chars are uparrow followed by a printing char.
-**		e.g. ctrl-A = ^A
-**		This includes ESC which is ^[.
-**		DEL is shown as ^?.
-**	Chars with the 8th bit set have the prefix CI_META (currently ~) and
-**		the rest of the representation is as above (except for TAB).
-**	Chars with the 9th bit set have the prefix CI_TOP (currently |) and
-**		the rest of the representation is as above (except for TAB).
-**		This only exists for systems with 9-bit chars such as TOPS-20.
-*/
-
-static int
-sctr(ch, to, ccol)
-int ch;			/* Buffer char to translate */
-char *to;		/* Place to deposit translation in */
-int ccol;		/* Current column position */
-{	register char *cp;
-	register c, n;
-
-	c = ch;
-	if(037 < c && c < 0177)	/* Most common case */
-	  {	*to = c;
-		return(1);
-	  }
-	cp = to;
-	if(c == TAB)			/* Next most common case */
-	  {	n = 010 - (ccol&07);	/* Tab stops are every 8 cols */
-		ccol = n;		/* Save value */
-		do *cp++ = SP;
-		while (--n);
-		return(ccol);
-	  }
-	ccol = 1;			/* Re-use var */
-#if TOPS20
-	if(c&0400)			/* 9th bit set? */
-	  {	*cp++ = CI_TOP;
-		ccol++;
-	  }
-#endif /*TOPS20*/
-	if(c&0200)
-	  {	*cp++ = CI_META;
-		ccol++;
-	  }
-	if((c &= 0177) <= 037 || c == 0177)
-	  {	*cp++ = CI_CNTRL;
-		c ^= 0100;		/* Transform cntrl char */
-		ccol++;
-	  }
-	*cp = c;
-	return(ccol);
-}
-
-
-/* INSLIN(line, N, wind) - Insert lines
- * DELLIN(line, N, wind) - Delete lines
- *	Both routines insert/delete N lines at "line" in window "wind"
- *	and update the screen image accordingly.
- */
-
-inslin (line, n, win)
-int   line;			       /* line number to insert BEFORE */
-int   n;			       /* number of lines to insert */
-struct window *win;		       /* window we are in */
-{	register int  i;
-	register int bot;
-	register char **savp;
-	char *savscr[MAXHT];
-
-	bot = win -> w_ht + win -> w_pos;
-	t_curpos (line, 0);
-	t_inslin (n, bot);		/* do the insertion on the screen */
-	savp = &savscr[0];
-	for (i = 1; i <= n; i++)	/* free lines that fall off-screen */
-		*savp++ = scr[bot - i]->sl_line;
-
-	for (i = bot - 1; i >= line + n; i--)		/* move down lines */
-	  {	scr[i]->sl_line = scr[i - n]->sl_line;	/* below the insertion */
-		scr[i]->sl_col = scr[i - n]->sl_col;
-	  }
-	savp = &savscr[0];
-	for (i = line + n - 1; i >= line; i--)
-				       /* blank lines where inserted */
-	  {	scr[i]->sl_line = *savp++;
-		scr[i]->sl_col = 0;
-	  }
-	for(i = line; i < bot; ++i)
-		scr[i]->sl_flg |= SL_MOD;
-}
-
-dellin (line, n, win)
-int   line;			       /* first line to be deleted */
-int   n;			       /* number of lines to be deleted */
-struct window *win;		       /* window we are in */
-{	register int  i;
-	register int bot;
-	register char **savp;
-	char *savscr[MAXHT];
-
-	bot = win -> w_ht + win -> w_pos;
-
-	t_curpos (line, 0);
-	t_dellin (n, bot);	       /* do the deletion on the screen */
-	savp = &savscr[0];
-	for (i = line; i < line + n; i++)    /* free the deleted lines */
-		*savp++ = scr[i]->sl_line;
-	for (i = line; i < bot - n; i++)	/* move lines up to fill */
-	  {	scr[i]->sl_line = scr[i + n]->sl_line;	/* deleted spaces */
-		scr[i]->sl_col = scr[i + n]->sl_col;
-	  }
-
-	savp = &savscr[0];
-	for (i = bot - n; i < bot; i++)      /* blank lines at bottom */
-	  {	scr[i]->sl_line = *savp++;
-		scr[i]->sl_col = 0;
-	  }
-	for(i = line; i < bot; ++i)
-		scr[i]->sl_flg |= SL_MOD;
-}
-
-
-/* T_ Terminal functions - these are similar to the terminal-dependent
- *	routines in EETERM (which they call) but rely on some knowledge of
- *	the screen image in order to do their job cleverly.
- */
-
-#if FX_SOWIND
-
-/* T_DOSTANDOUT(on) - Turn standout mode on or off, cleverly.
-**	Returns previous state.
-*/
-static int curso = 0;		/* Current state (initially off) */
-int
-t_dostandout(on)
-int on;
-{
-	int oldso;
-
-	if ((oldso = curso) != on)	/* If desired state doesn't match, */
-	  {	t_standout(on);		/* invoke new state. */
-		curso = on;
-	  }
-	return oldso;
-}
-#endif
-
-
-t_move(y,x)
-register int y,x;
-{	register int d;
-
-	if(y != curs_lin)		/* No vertical smarts yet */
-	  {	t_curpos(y, x);
-		return;
-	  }
-	if((d = (x - curs_col)) >= 0)	/* Find diff in column position */
-	  {	if(d == 0) return;	/* If none, nothing to do! */
-
-		/* Moving right.  If distance is less than abs-move cost,
-		 * do clever right-move by copying screen image */
-		if(d < tvc_pos)
-#if FX_SOWIND	/* Ensure not in standout mode */
-			if((scr[y]->sl_flg&(SL_CSO|SL_NSO))==0)
-#endif
-		  {
-			tputn(&scr[y]->sl_line[curs_col], d);
-			curs_col = x;
-			return;
-		  }
-	  }
-	/* Moving to left, try to do clever left-move by backspacing
-	 * instead of using abs move.
-	 */
-	else if((d = -d)*tvc_bs < tvc_pos)
-	  {	do { t_backspace();
-		  } while(--d);
-		return;
-	  }
-	/* No luck with cleverness, just move. */
-	t_curpos(y, x);
-}
-
-t_docleol()
-{	register struct scr_line *s;
-	register int cnt, ocol;
-
-	if(trm_flags&TF_CLEOL) t_cleol();	/* Winning */
-	else		/* Losing */
-	  {	s = scr[curs_lin];
-		if((cnt = s->sl_col - curs_col) > 0)
-		  {
-#if FX_SOWIND
-			int oldso = t_dostandout(0);
-#endif
-			ocol = curs_col;
-			do { tput(SP); curs_col++;
-			  } while(--cnt);
-#if FX_SOWIND
-			t_dostandout(oldso);
-#endif
-			t_move(curs_lin, ocol);
-		  }
-	  }
-}
-
Index: trunk/minix/commands/elle/eeedit.c
===================================================================
--- trunk/minix/commands/elle/eeedit.c	(revision 9)
+++ 	(revision )
@@ -1,723 +1,0 @@
-/* ELLE - Copyright 1982, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*	EEEDIT - E-type routines */
-
-#include "elle.h"
-
-/* E_	- Operate on cur_buf.  Do not change value of cur_dot unless
- *		unavoidable side effect (also e_setcur).
- * EX_	- Like E_ but take SB ptr value.  Never touch cur_dot.
- * ED_	- Like E_, operate on cur_buf, update cur_dot and display stuff.
- * D_	- Perform necessary display update for given operations.
- *
- * Note that "dot" refers to the current read/write pointer for a sbbuffer.
- * The name comes from EMACS/TECO where "." represents this value.
- */
-
-#define CURSBB (SBBUF *)cur_buf		/* Shorthand for current SB buffer */
-
-e_reset()	/* Reset current buffer */
-{	ex_reset(CURSBB);
-	cur_dot = 0;
-}
-
-/* Basic functions - apply SB routines to current buffer.
- * There is some optimization here which knows that certain SB functions
- * are macros.
- */
-e_rgetc()	/* Read/move 1 char backward */
-{	return(sb_rgetc((CURSBB)));
-}
-e_rdelc()	/* Delete 1 char backward */
-{	return(sb_rdelc((CURSBB)));
-}
-e_delc()	/* Delete 1 char forward */
-{	return(sb_deln(CURSBB,(chroff)1));
-}
-e_getc()	/* Read/move 1 char forward */
-{	register SBBUF *sb;
-	sb = CURSBB;		/* Macro: use reg */
-	return(sb_getc(sb));
-}
-e_backc()	/* Move 1 char backward */
-{	register SBBUF *sb;
-	sb = CURSBB;		/* Macro: use reg */
-	sb_backc(sb);			/* No value returned */
-}
-e_putc(c)	/* Insert/write 1 char forward */
-char c;
-{	register SBBUF *sb;
-	sb = CURSBB;		/* Macro: use reg */
-	return(sb_putc(sb, c));
-}
-e_peekc()	/* Read 1 char forward (no move) */
-{	register SBBUF *sb;
-	sb = CURSBB;		/* Macro: use reg */
-	return(sb_peekc(sb));
-}
-e_ovwc(ch)	/* Overwrite 1 char forward */
-char ch;
-{
-	sb_setovw(CURSBB);	/* Turn on overwrite mode */
-	e_putc(ch);
-	sb_clrovw(CURSBB);	/* Turn off overwrite mode */
-}
-
-SBSTR *
-e_copyn(off)	/* Copy N chars forward/backward, return SD to sbstring */
-chroff off;
-{	return(sb_cpyn(CURSBB,off));
-}
-e_deln(off)	/* Delete N chars forward/backward */
-chroff off;
-{	return(sb_deln(CURSBB, off));
-}
-
-/* E_SETCUR() - set cur_dot to current position (dot).  This is the only
- *	E_ routine that mungs cur_dot except for e_reset.
- */
-e_setcur()
-{	cur_dot = e_dot();
-}
-e_gosetcur(dot)		/* Go to specified dot and set cur_dot as well */
-chroff dot;
-{	sb_seek(CURSBB,dot,0);
-	e_setcur();	/* Not cur_dot = dot since want canonicalization */
-}
-
-/* E_GO(dot) - Move to specified location. */
-/* These "GO" routines all move to the location specified, returning
- *	0 if successful and -1 on error.  "cur_dot" is never changed,
- *	with the exception of e_gosetcur.
- * Note that other "GO" routines (eg E_GONL) will return 1 if successful
- *	and 0 if stopped by EOF.
- */
-
-e_gocur() { return(e_go(cur_dot)); }		/* Move to cur_dot */
-e_gobob() { return(e_go((chroff) 0)); }		/* Move to Beg Of Buffer */
-e_goeob() { return(sb_seek(CURSBB,(chroff)0,2)); } /* Move to End Of Buffer */
-e_go(dot)	/* Move to specified location. */
-chroff dot;
-{	return(sb_seek(CURSBB,dot,0));
-}
-e_igoff(ioff)	/* Move (int) N chars forward/backward */
-int ioff;
-{	return(sb_seek(CURSBB,(chroff)ioff,1));
-}
-
-e_goff(off)	/* Move (full) N chars forward/backward */
-chroff off;
-{	return(sb_seek(CURSBB,off,1));
-}
-
-int ex_gonl(), ex_gopl(), ex_gobol(), ex_goeol();
-
-e_gobol() { return(ex_gobol(CURSBB)); }	/* Move to beg of this line */
-e_goeol() { return(ex_goeol(CURSBB)); }	/* Move to end of this line */
-e_gonl()  { return(ex_gonl(CURSBB)); }	/* Move to beg of next line */
-e_gopl()  { return(ex_gopl(CURSBB)); }	/* Move to beg of prev line */
-
-
-/* E_DOT() - Return current value of dot. */
-chroff e_dot()   { return(sb_tell(CURSBB)); }		/* Current pos */
-chroff e_nldot() { return(e_alldot(CURSBB,ex_gonl)); }	/* Beg of next line */
-chroff e_pldot() { return(e_alldot(CURSBB,ex_gopl)); }	/* Beg of prev line */
-chroff e_boldot(){ return(e_alldot(CURSBB,ex_gobol));}	/* Beg of this line */
-chroff e_eoldot(){ return(e_alldot(CURSBB,ex_goeol));}	/* End of this line */
-
-chroff
-e_alldot(sbp,rtn)	/* Auxiliary for above stuff */
-SBBUF *sbp;
-int (*rtn)();
-{	return(ex_alldot(sbp,rtn,e_dot()));
-}
-
-/* E_BLEN - Return length of current buffer */
-chroff
-e_blen() { return(ex_blen(CURSBB)); }
-
-
-/* EX_ routines - similar to E_ but take a buffer/sbbuf argument
- *	instead of assuming current buffer.
- */
-
-/* EX_RESET - Reset a given buffer */
-ex_reset(b)
-struct buffer *b;
-{	sbs_del(sb_close((SBBUF *)b));
-	sb_open((SBBUF *)b,(SBSTR *)0);
-}
-
-ex_go(sbp,loc)		/* Move to given dot in specified sbbuf */
-chroff loc;
-SBBUF *sbp;
-{	return(sb_seek(sbp,loc,0));
-}
-
-chroff
-ex_dot(sbp)	/* Return current position in specified sbbuf */
-SBBUF *sbp;
-{
-	return(sb_tell(sbp));
-}
-
-
-chroff
-ex_boldot(sbp,dot)	/* Return dot for BOL of specified sbbuf */
-SBBUF *sbp;
-chroff dot;
-{	return(ex_alldot(sbp,ex_gobol,dot));
-}
-
-chroff
-ex_alldot(sbp,rtn,dot)	/* Auxiliary for some e_ stuff */
-SBBUF *sbp;
-int (*rtn)();
-chroff dot;
-{	register SBBUF *sb;
-	chroff savloc, retloc;
-
-	savloc = sb_tell(sb = sbp);
-	sb_seek(sb,dot,0);
-	(*rtn)(sb);
-	retloc = sb_tell(sb);
-	sb_seek(sb,savloc,0);
-	return(retloc);
-}
-
-/* GO (forward) to Next Line of specified sbbuf - returns 0 if stopped at EOF
- * before an EOL is seen. */
-ex_gonl(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register int c;
-	sb = sbp;
-#if FX_EOLMODE
-	if(eolcrlf(sb))
-		while((c = sb_getc(sb)) != EOF)
-		  {	if(c == LF)		/* Possible EOL? */
-			  {	sb_backc(sb);	/* See if prev char was CR */
-				if((c = sb_rgetc(sb)) != EOF)
-					sb_getc(sb);
-				sb_getc(sb);	/* Must restore position */
-				if(c == CR)	/* Now test for CR */
-					return(1);	/* Won, CR-LF! */
-			  }
-		  }
-	else
-#endif
-	while((c = sb_getc(sb)) != EOF)
-		if(c == LF)
-			return(1);
-	return(0);
-}
-
-/* GO (forward) to End Of Line of specified sbbuf - returns 0 if stopped at
- * EOF before an EOL is seen. */
-ex_goeol(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register int c;
-	sb = sbp;
-#if FX_EOLMODE
-	if(eolcrlf(sb))
-		while((c = sb_getc(sb)) != EOF)
-		  {	if(c == LF)		/* Possible EOL? */
-			  {	sb_backc(sb);	/* See if prev char was CR */
-				if((c = sb_rgetc(sb)) == CR)
-					return(1);	/* Won, CR-LF! */
-				if(c != EOF)	/* No, must restore position */
-					sb_getc(sb);	/* Skip over */
-				sb_getc(sb);		/* Skip over LF */
-			  }
-		  }
-	else
-#endif
-	while((c = sb_getc(sb)) != EOF)
-		if(c == LF)
-		  {	sb_backc(sb);
-			return(1);
-		  }
-	return(0);
-}
-
-/* GO (backward) to Beg Of Line of specified sbbuf - returns 0 if stopped
- * at EOF
- */
-ex_gobol(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register int c;
-	sb = sbp;
-#if FX_EOLMODE
-	if(eolcrlf(sb))
-		while((c = sb_rgetc(sb)) != EOF)
-		  {	if(c == LF)		/* Possible EOL? */
-			  {	if((c = sb_rgetc(sb)) == CR)
-				  {	sb_getc(sb);	/* Won, CR-LF! */
-					sb_getc(sb);	/* Move back */
-					return(1);
-				  }
-				if(c != EOF)	/* No, must restore position */
-					sb_getc(sb);	/* Undo the rgetc */
-			  }
-		  }
-	else
-#endif
-	while((c = sb_rgetc(sb)) != EOF)
-		if(c == LF)
-		  {	sb_getc(sb);
-			return(1);
-		  }
-	return(0);
-}
-
-/* GO (backward) to Previous Line of specified sbbuf - returns 0 if stopped
- * at EOF before an EOL is seen (i.e. if already on 1st line of buffer)
- */
-ex_gopl(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register int c;
-	sb = sbp;
-#if FX_EOLMODE
-	if(eolcrlf(sb))
-		while((c = sb_rgetc(sb)) != EOF)
-		  {	if(c == LF)		/* Possible EOL? */
-			  {	if((c = sb_rgetc(sb)) == CR)
-				  {	ex_gobol(sb);
-					return(1);		/* Won! */
-				  }
-				if(c != EOF)	/* No, must restore position */
-					sb_getc(sb);	/* Undo the rgetc */
-			  }
-		  }
-	else
-#endif
-	while((c = sb_rgetc(sb)) != EOF)
-		if(c == LF)
-		  {	ex_gobol(sb);
-			return(1);	/* Won! */
-		  }
-	return(0);
-}
-
-
-chroff
-ex_blen(sbp)		/* Return length of specified sbbuf */
-SBBUF *sbp;
-{
-	return(sb_tell(sbp)+sb_ztell(sbp));
-}
-
-
-/* Miscellaneous stuff */
-
-/* E_GOFWSP() - Forward over whitespace */
-e_gofwsp()
-{	register int c;
-	while((c = e_getc()) == SP || c == TAB);
-	if(c != EOF) e_backc();
-}
-
-/* E_GOBWSP() - Backward over whitespace */
-e_gobwsp()
-{	register int c;
-	while((c = e_rgetc()) == SP || c == TAB);
-	if(c != EOF) e_getc();
-}
-
-
-/* E_GOLINE(n) - Goes N lines forward (or backward).
-**	If N == 0, goes to beginning of current line.
-**	Returns 0 if hit EOF.
-*/
-e_goline(i)
-register int i;
-{
-	if(i > 0)
-	  {	do { if(!e_gonl()) return(0); }
-		while(--i);
-	  }
-	else if(i < 0)
-	  {	i = -i;
-		do { if(!e_gopl()) return(0); }
-		while(--i);
-	  }
-	else e_gobol();		/* arg of 0 */
-	return 1;
-}
-
-/* E_LBLANKP() - Returns true if all characters in rest of line are blank.
- *	Moves to beginning of next line as side effect, unless fails.
- */
-e_lblankp()
-{	register int c;
-	for(;;) switch(e_getc())
-	  {
-		case SP:
-		case TAB:
-			continue;
-		case LF:	/* Normally drop thru to return 1 as for EOF */
-#if FX_EOLMODE
-			if(eolcrlf(cur_buf))
-			  {	e_rgetc();
-				if((c = e_rgetc()) != EOF) /* Get prev char */
-					e_getc();
-				e_getc();
-				if(c != CR)		/* Now examine */
-					continue;	/* Not CR-LF, go on */
-			  }	/* Else drop thru to return win */
-#endif
-		case EOF:
-			return(1);
-		default:
-			return(0);
-	  }
-	/* Never drops out */
-}
-
-
-
-e_insn(ch, cnt)
-int ch;
-int cnt;
-{	register int i;
-	if((i = cnt) > 0)
-		do { e_putc(ch);
-		  } while(--i);
-}
-
-e_sputz(acp)
-char *acp;
-{	register SBBUF *sb;
-	register char *cp;
-	register int c;
-	if(cp = acp)
-	  {	sb = CURSBB;
-		while(c = *cp++)
-			sb_putc(sb,c);
-	  }
-}
-
-/* BOLEQ - Returns TRUE if 2 dots are on the same line
- *	(i.e. have the same Beg-Of-Line)
- */
-boleq(dot1,dot2)
-chroff dot1,dot2;
-{	return( (ex_boldot(CURSBB,dot1) == ex_boldot(CURSBB,dot2)));
-}
-
-
-char *
-dottoa(str,val)
-char *str;
-chroff val;
-{	register char *s;
-
-	s = str;
-	if(val < 0)
-	  {	*s++ = '-';
-		val = -val;
-	  }
-	if(val >= 10)
-		s = dottoa(s, val/10);
-	*s++ = '0' + (int)(val%10);
-	*s = 0;
-	return(s);
-}
-
-
-
-/* Paragraph utilities */
-
-#if FX_FPARA || FX_BPARA || FX_MRKPARA || FX_FILLPARA
-
-#if FX_SFPREF
-extern char *fill_prefix;	/* Defined in eefill.c for now */
-extern int fill_plen;		/* Ditto */
-#endif /*FX_SFPREF*/
-
-#if ICONOGRAPHICS
-int para_mode = PARABLOCK;	/* eexcmd.c only other file that refs this */
-#endif /*ICONOGRAPHICS*/
-
-
-/* Go to beginning of paragraph */
-e_gobpa()
-{	register int c;
-	chroff savdot;
-
-	savdot = e_dot();
-	e_bwsp();
-	while((c = e_rgetc()) != EOF)
-		if(c == LF)		/* Went past line? */
-		  {	e_getc();		/* Back up and check */
-#if FX_SFPREF
-			if(fill_plen)
-				if(tstfillp(fill_plen))
-				  {	e_igoff(-(fill_plen+1));
-					continue;
-				  }
-				else break;
-#endif /*FX_SFPREF*/
-#if ICONOGRAPHICS
-                        c = e_peekc ();
-
-                        if (para_mode == PARABLOCK)
-                            if (c == LF)
-                                break;
-
-                        if (para_mode == PARALINE)
-                            if (c_wsp (c))
-                                break;
-#else
-			if(c_pwsp(e_peekc()))	/* Check 1st chr for wsp */
-				break;		/* If wsp, done */
-#endif /*ICONOGRAPHICS*/
-			e_rgetc();		/* Nope, continue */
-		  }
-	if((c = e_peekc()) == '.' || c == '-')
-	  {	e_gonl();
-		if(e_dot() >= savdot)
-			e_gopl();
-	  }
-}
-
-/* Go to end of paragraph */
-e_goepa()
-{	register int c;
-
-	e_gobol();			/* First go to beg of cur line */
-	e_fwsp();
-	while((c = e_getc()) != EOF)
-        	if (c == LF)
-		  {
-#if FX_SFPREF
-		if(fill_plen)		/* If Fill Prefix is defined */
-			if(tstfillp(fill_plen))	/* then must start with it */
-				continue;
-			else break;		/* or else we're done */
-#endif /*FX_SFPREF*/
-#if ICONOGRAPHICS
-                if (para_mode == PARABLOCK)
-                    if (e_peekc () == LF)
-                        break;
-
-                if (para_mode == PARALINE)
-                    if (c_wsp (e_peekc ()))
-                        break;
-#else
-                if(c_pwsp(e_peekc()))
-                        break;
-#endif /*-ICONOGRAPHICS*/
-		  }
-}
-
-exp_do(rpos, rneg)
-int (*rpos)(), (*rneg)();
-{	register int e;
-	register int (*rtn)();
-
-	if((e = exp) == 0)
-		return;
-	rtn = rpos;
-	if(e < 0)
-	  {	rtn = rneg;
-		e = -e;
-	  }
-	do { (*rtn)();
-	  } while(--e);
-}
-
-
-e_fwsp()
-{	register int c;
-	while(c_wsp(c = e_getc()));
-	if(c != EOF) e_backc();
-}
-e_bwsp()
-{	register int c;
-	while(c_wsp(c = e_rgetc()));
-	if(c != EOF) e_getc();
-}
-
-
-c_wsp(ch)
-int ch;
-{	register int c;
-	c = ch;
-	if(c == SP || c == TAB || c == LF || c == FF)
-		return(1);
-	return(0);
-}
-c_pwsp(ch)
-int ch;
-{	register int c;
-	c = ch;
-	if(c == '.' || c == '-')
-		return(1);
-	return(c_wsp(c));
-}
-
-#endif /* FX_FPARA || FX_BPARA || FX_MRKPARA || FX_FILLPARA */
-
-
-/* Word function auxiliaries */
-
-/* Returns true if this character is a delimiter. */
-delimp(c)
-int  c;
-{	static int  delim_tab[] =
-	  {
-	    0177777, 0177777,		/* All controls */
-	    0177777, 0176000,		/* All punct but 0-9 */
-	    0000001, 0074000,		/* All punct but A-Z and _ */
-	    0000001, 0174000		/* All punct but a-z */
-	  };
-	return (delim_tab[c >> 4] & (1 << (c & 017)));
-}
-
-e_wding(adot,n)
-register chroff *adot;
-int n;
-{	chroff savdot;
-	savdot = e_dot();
-	e_gowd(n);
-	*adot = e_dot();
-	e_go(savdot);
-	if(*adot == savdot)
-	  {	ring_bell();
-		return(0);
-	  }
-	return(1);
-}
-chroff
-e_wdot(dot,n)
-chroff dot;
-int n;
-{	chroff savdot, retdot;
-	savdot = e_dot();
-	e_go(dot);
-	e_gowd(n);
-	retdot = e_dot();
-	e_go(savdot);
-	return(retdot);
-}
-e_gowd(n)
-int n;
-{	register int (*gch)(), c, cnt;
-	int e_getc(), e_rgetc();
-	chroff ret_dot;
-
-	if((cnt = n) == 0)
-		return;
-	if(cnt > 0)
-		gch = e_getc;		/* Forward routine */
-	else
-	  {	gch = e_rgetc;		/* Backward routine */
-		cnt = -cnt;
-	  }
-	do
-	  {	ret_dot = e_dot();	/* Remember dot for last word found */
-		while((c = (*gch)()) != EOF && delimp(c));
-		if(c == EOF)
-		  {	e_go(ret_dot);		/* Use last word found */
-			break;
-		  }
-		while((c = (*gch)()) != EOF && !delimp(c));
-		if(c == EOF)
-			break;
-		if(n < 0) e_getc(); else e_backc();
-	  } while(--cnt);
-}
-
-
-/* Searching */
-
-e_search(mstr,mlen,backwards)
-char *mstr;
-int mlen;
-int backwards;
-{	register SBBUF *sb;
-	register char *cp;
-	register int c;
-	char *savcp;
-	int cnt, scnt;
-#if IMAGEN
-	register int c1;
-	register int caseless = (cur_buf->b_flags & B_TEXTMODE);
-#endif /*IMAGEN*/
-
-	sb = (SBBUF *) cur_buf;
-	if (!backwards)
-	  {		/* Search forwards */
-	sfwd:	cp = mstr;
-		while((c = sb_getc(sb)) != EOF)
-		  {
-#if IMAGEN
-			if((!caseless && c != *cp) || 
-			    (caseless && upcase(c) != upcase(*cp))) continue;
-#else
-			if(c != *cp) continue;
-#endif /*-IMAGEN*/
-			cp++;
-			cnt = mlen;
-			while(--cnt > 0)
-			  {
-#if IMAGEN
-				c1 = *cp++;
-				c = e_getc();
-				if ((!caseless && c1 != c) ||
-				     (caseless && upcase(c1) != upcase(c)))
-#else
-				if(*cp++ != (c = e_getc()))
-#endif /*-IMAGEN*/
-				  {	if(c == EOF) return(0);
-					sb_seek(sb,(chroff)(cnt-mlen),1);
-					goto sfwd;
-				  }
-			  }
-			return(1);
-		  }
-	  }
-	else
-	  {		/* Search backwards */
-		scnt = mlen - 1;
-		savcp = mstr + scnt;		/* Point to end of string */
-
-	sbck:	cp = savcp;
-		while((c = sb_rgetc(sb)) != EOF)
-		  {
-#if IMAGEN
-			if((!caseless && c != *cp) || 
-			    (caseless && upcase(c) != upcase(*cp))) continue;
-#else
-			if(c != *cp) continue;
-#endif /*-IMAGEN*/
-			cp--;
-			if((cnt = scnt) == 0) return(1);
-			do
-			  {
-#if IMAGEN
-				c1 = *cp--;
-				c = e_rgetc();
-				if ((!caseless && c1 != c) ||
-				     (caseless && upcase(c1) != upcase(c)))
-#else
-				if(*cp-- != (c = e_rgetc()))
-#endif /*-IMAGEN*/
-				  {	if(c == EOF) return(0);
-					sb_seek(sb,(chroff)(mlen-cnt),1);
-					goto sbck;
-				  }
-			  }
-			while(--cnt);
-			return(1);
-		  }
-	  }
-	return(0);		/* Failed */
-}
Index: trunk/minix/commands/elle/eeerr.c
===================================================================
--- trunk/minix/commands/elle/eeerr.c	(revision 9)
+++ 	(revision )
@@ -1,186 +1,0 @@
-/* ELLE - Copyright 1982, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*	EEERR - Error handling & testing routines
- */
-
-#include "elle.h"
-
-#if V6
-#include "eesigs.h"
-#else
-#include <signal.h>
-#endif
-
-/* EFUN: "Hit Breakpoint" */
-f_bkpt()
-{	clean_exit();
-	bpt();
-        set_tty();
-}
-bpt() {}		/* Put a DDT/ADB breakpoint here */
-
-
-#if !(STRERROR)		/* If strerror() not supported, we provide it. */
-extern int sys_nerr;		/* Max index into sys_errlist */
-extern char *sys_errlist[];
-
-char *
-strerror(num)
-int num;
-{
-	static char badbuf[30];
-	if (num > 0 && num <= sys_nerr)
-		return (sys_errlist[num]);
-	sprintf(badbuf, "unknown error %d", num);
-	return badbuf;
-}
-#endif /* -STRERROR */
-
-
-
-errsbm(type,adr,str,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
-register int type;	/* Type, flags */
-int (*adr)();		/* Addr called from */
-char *str;		/* Printf string */
-{	register struct buffer *b;
-	int oldttystate;
-
-	oldttystate = clean_exit();	/* Ensure not in editing mode */
-	if(type == SBFERR)	/* File overwrite error?  A0 is FD */
-	  {	printf("WARNING - FILE CORRUPTED!\nBuffers affected:\n");
-		for(b = buf_head; b; b = b->b_next)
-		  {	if(sb_fdinp((SBBUF *)b, a0))
-				printf((b->b_fn ? "  %s: %s\n" : "  %s\n"),
-					b->b_name, b->b_fn);
-		  }
-		if (oldttystate > 0) set_tty();
-		return(1);	/* Try to continue normally */
-	  }
-	printf("%sERR: %o ", (type ? "SBX" : "SBM"), adr);
-	printf(str,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12);
-	askerr();
-}
-
-/*
- *  Bite_bag -- Try to save our rear ends after a catastrophe.
- *	This routine is mainly called from "interrupt"
- *	level when a memory fault or bus error occurs.
- *	We try to save the buffer to the file "ELLE.crash"
- *	in the current working directory.  If it loses, well
- *	then you have really lost.  Note: this routine does
- *	not reset the appropriate signal handler, so it is
- *	never re-entered.  If a fault repeats once in this
- *	code, then the world dies.
- */
-
-bite_bag(fault)				/* We come here on any memory error */
-int fault;
-{
-	int ostate;
-	/* Some systems, such as BSD4.x and SUN, do not reset caught signals
-	 * to SIG_DFL.
-	 * This is a win, but isn't what vanilla UNIX code expects.
-	 * Since it doesn't hurt to do it explicitly, we always turn it off
-	 * explicitly...
-	 */
-	signal(fault, SIG_DFL);		/* Reinstate default handling */
-
-	ostate = clean_exit();		/* Fix up the terminal modes first! */
-	printf("ELLE stopped by fatal interrupt (%d)!\n\
-Type S or W to try saving your work.\n",fault);
-	askerr();
-	if(ostate > 0) set_tty();
-	signal(fault, bite_bag);	/* If continued, re-enable signal */
-}
-
-/* HUP_EXIT - Called by a SIGHUP hangup signal.
- *	Tries to save all modified buffers before exiting.
- *	Note that the TTY is not touched at all, although the terminal mode
- *	flag is set just in case further error handling routines are invoked.
- */
-hup_exit()
-{	extern int trm_mode;		/* See e_disp.c */
-
-	trm_mode = -1;			/* Say TTY is now detached */
-	saveworld((struct buffer *)0, 0);	/* Save world, w/o feedback */
-	exit(1);
-}
-
-
-errint()		/* Routine provided for ADB jumps */
-{	askerr();
-}
-char askh1[] = "\
-A - Abort process\n\
-B - Breakpoint (must have \"bpt:b\" set in ADB)\n\
-C - Continue\n\
-D - Diagnostic command mode\n";
-char askh2[] = "\
-S - Try to save current buffer\n\
-W - Try to save world (all modified buffers)\n";
-
-int bsaving = 0;	/* Set while in middle of saving buffer(s) */
-
-askerr()
-{	register struct buffer *b;
-	char linbuf[100];
-	char *asklin();
-	extern int (*funtab[])();	/* In E_CMDS.C */
-	int ostate;
-
-	ostate = clean_exit();		/* Clean up TTY if not already done */
-reask:
-	printf("(A,B,C,D,S,W,?)");
-	switch(upcase(*asklin(linbuf)))
-	  {
-		case '?':
-			writez(1,askh1);	/* Too long for &$@! printf */
-			writez(1,askh2);	/* Too long for &$@! V6 C */
-			break;			/*    optimizer (/lib/c2) */
-		case 'A':
-			abort();
-			break;
-		case 'B':
-			bpt();
-			break;
-		case 'Q':
-		case 'C':
-			goto done;
-		case 'D':
-			if(funtab[FN_DEBUG])
-				(*funtab[FN_DEBUG])(-1);
-			else printf("Sorry, no diagnostics\n");
-			break;
-		case 'S':	/* Try to save current buffer only */
-			b = cur_buf;
-			goto savb;
-		case 'W':	/* Try to save all modified buffers */
-			b = 0;
-		savb:	if(bsaving++)
-			  {	printf("Already saving -- continued");
-				goto done;
-			  }
-			saveworld(b, 1);	/* Save, with feedback */
-			bsaving = 0;
-			break;
-	  }
-	goto reask;
-done:
-	if(ostate > 0)
-		set_tty();
-}
-
-char *
-asklin(acp)
-char *acp;
-{	register char *cp;
-	register int c;
-	cp = acp;
-	while((c = tgetc()) != LF)
-		*cp++ = c;
-	*cp++ = 0;
-	return(acp);
-}
Index: trunk/minix/commands/elle/eef1.c
===================================================================
--- trunk/minix/commands/elle/eef1.c	(revision 9)
+++ 	(revision )
@@ -1,284 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * EEF1	Various functions
- *		Char move/ins/del
- *		Case change
- *		Char/word transpose
- */
-
-#include "elle.h"
-
-/* EFUN: "Insert Self" */
-f_insself (c)
-int c;
-{
-#if IMAGEN
-	fim_insself(c);
-#else
-#if FX_FILLMODE
-	extern int fill_mode;
-
-	if(fill_mode) fx_insfill(c);
-	else
-#endif /*FX_FILLMODE*/
-	ed_insn(c, exp);	/* Normal stuff */
-#endif /*-IMAGEN*/
-}
-
-/* EFUN: "Quoted Insert"
-**	Inserts next char directly, <exp> number of times.
-** Does not check anything about the char and does not do anything
-** depending on the mode.  In particular, CR is not turned into EOL.
-*/
-f_quotins()
-{
-	ed_insn(cmd_read(), exp);	/* Insert next char directly */
-}
-
-#if FX_CRLF
-/* EFUN: "CRLF" */
-f_crlf()
-{
-#if IMAGEN
-	fim_crlf();
-#else
-	register int i;
-
-	if(e_goeol() == cur_dot		/* If at end of current line */
-	  && exp == 1			/* and inserting only 1 new line */
-	  && e_lblankp() && e_lblankp())	/* and next 2 lines blank */
-	  {	e_gocur();		/* Then just re-use next line. */
-		e_gonl();		/* Go to its start */
-		e_setcur();		/* and establish cur_dot there. */
-		ed_delete(e_dot(), e_eoldot());	/* Ensure any blanks flushed */
-	  }
-	else
-	  {	e_gocur();		/* Otherwise back to original place */
-		if((i = exp) > 0)	/* and simply insert newlines */
-			do ed_crins();
-			while(--i);
-	  }
-#endif /*-IMAGEN*/
-}
-#endif /*FX_CRLF*/
-
-
-/* EFUN: "Forward Character" */
-f_fchar()
-{	ed_igoff(exp);
-}
-
-/* EFUN: "Backward Character" */
-f_bchar()
-{	ed_igoff(-exp);
-}
-
-/* EFUN: "Delete Character" */
-f_dchar ()
-{
-#if IMAGEN
-	fim_dchar();
-#else
-	ef_deln(exp);
-#endif /*-IMAGEN*/
-}
-
-/* EFUN: "Backward Delete Character" */
-f_bdchar ()
-{
-#if IMAGEN
-	fim_bdchar();
-#else
-	ef_deln(-exp);
-#endif /*-IMAGEN*/
-}
-
-/* Delete forward or backward N characters.
- * If arg, kills instead of deleting.
- */
-ef_deln(x)
-int x;
-{
-	e_igoff(x);
-	if(exp_p) ed_kill(cur_dot, e_dot());
-	else ed_delete(cur_dot, e_dot());
-}
-
-
-#if FX_DELSPC
-/* EFUN: "Delete Horizontal Space" */
-/*	Delete spaces/tabs around point.
- */
-f_delspc()
-{	chroff dot1;
-
-	e_gobwsp();			/* Move backward over whitespace */
-	dot1 = e_dot();			/* Save point */
-	e_gofwsp();			/* Move forward over whitespace */
-	ed_delete(dot1,e_dot());	/* Delete twixt start and here */
-}
-#endif /*FX_DELSPC*/
-
-
-#if FX_TCHARS
-/* EFUN: "Transpose Characters"
- *	Transpose chars before and after cursor.  Doesn't hack args yet.
- * EMACS: With positive arg, exchs chars before & after cursor, moves right,
- *	and repeats the specified # of times, dragging the char to the
- *	left of the cursor right.
- *	With negative arg, transposes 2 chars to left of cursor, moves
- *	between them, and repeats the specified # of times, exactly undoing
- *	the positive arg form.  With zero arg, transposes chars at point
- *	and mark.
- *	HOWEVER: at the end of a line, with no arg, the preceding 2 chars
- *	are transposed.
- */
-f_tchars()
-{	register int c, c2;
-#if IMAGEN
-	c = e_rgetc();			/* Gosmacs style: twiddle prev 2 */
-	if (c == EOF)
-		return(e_gocur());	/* Do nothing at beginning of bfr */
-#else
-
-	if((c = e_getc()) == EOF	/* If at EOF */
-	  || e_rgetc() == LF)		/* or at end of line, */
-		c = e_rgetc();		/* use preceding 2 chars */
-#endif /*-IMAGEN*/
-
-	if((c2 = e_rgetc()) == EOF)	/* At beginning of buffer? */
-		return(e_gocur());	/* Yes, do nothing */
-	e_ovwc(c);
-	e_ovwc(c2);
-	e_setcur();
-	buf_tmod((chroff)-2);		/* Munged these 2 chars */
-}
-#endif /*FX_TCHARS*/
-
-
-#if FX_FWORD
-/* EFUN: "Forward Word" */
-f_fword()
-{	chroff retdot;
-	if(e_wding(&retdot, exp))
-		ed_go(retdot);
-}
-#endif
-
-#if FX_BWORD
-/* EFUN: "Backward Word" */
-f_bword()
-{	exp = -exp;
-	f_fword();
-}
-#endif
-
-#if FX_KWORD
-/* EFUN: "Kill Word" */
-f_kword()
-{	chroff retdot;
-
-	if(e_wding(&retdot,exp))
-	  {	ed_kill(cur_dot,retdot);
-		this_cmd = KILLCMD;
-	  }
-}
-#endif
-
-#if FX_BKWORD
-/* EFUN: "Backward Kill Word" */
-f_bkword()
-{	exp = -exp;
-	f_kword();
-}
-#endif
-
-
-#if FX_TWORDS
-/* EFUN: "Transpose Words" */
-/*	Transpose word.  Urk!
- */
-f_twords()
-{	register SBSTR *sd1, *sd2;
-	register SBBUF *sb;
-	chroff begwd1, endwd1, begwd2, endwd2;
-
-	endwd2 = e_wdot(cur_dot, 1);	/* Go to end of 2nd word */
-	begwd2 = e_wdot(endwd2, -1);	/* Go to beg of 2nd word */
-	if(begwd2 >= endwd2)		/* If no 2nd word, punt. */
-		return;
-	begwd1 = e_wdot(begwd2, -1);	/* Go to beg of 1st word */
-	endwd1 = e_wdot(begwd1, 1);	/* Go to end of 1st word */
-	if(begwd1 >= endwd1)		/* If no 1st word, punt. */
-		return;
-	if(endwd1 > begwd2)		/* Avoid possible overlap */
-		return;
-
-	e_go(begwd2);
-	sb = (SBBUF *)cur_buf;
-	sd2 = sb_killn(sb, endwd2 - begwd2);	/* Excise wd 2 first */
-	e_go(begwd1);
-	sd1 = sb_killn(sb, endwd1 - begwd1);	/* Excise wd 1 */
-	sb_sins(sb, sd2);			/* Replace with wd 2 */
-	e_goff(begwd2 - endwd1);		/* Move past between stuff */
-	sb_sins(sb, sd1);			/* Insert wd 1 */
-	e_setcur();
-	buf_tmat(begwd1);			/* Modified this range */
-}
-#endif /*FX_TWORDS*/
-
-
-/* Case hacking functions and support */
-
-#if FX_UCWORD
-/* EFUN: "Uppercase Word" */
-f_ucword()
-{	case_word(0);
-}
-#endif /*FX_UCWORD*/
-
-#if FX_LCWORD
-/* EFUN: "Lowercase Word" */
-f_lcword()
-{	case_word(1);
-}
-#endif /*FX_LCWORD*/
-
-#if FX_UCIWORD
-/* EFUN: "Uppercase Initial" */
-f_uciword()
-{	case_word(2);
-}
-#endif /*FX_UCIWORD*/
-
-#if FX_UCWORD||FX_LCWORD||FX_UCIWORD
-case_word (downp)
-{	chroff retdot;
-#if IMAGEN
-	chroff startdot;
-
-	/* Normalize our position to beginning of "current" word,
-	 * where "current" is defined to be the current word we are in,
-	 * or else the previous word if we are not in any word.
-	 * All this silly nonsense just to perpetuate Gosmacs's
-	 * wrong behaviour!
-	 */
-	startdot = cur_dot;	/* Save current position */
-	e_getc();	/* If at beg of word, ensure we get inside it */
-	e_gowd(-1);	/* Go to start of this or prev word */
-	e_setcur();	/* Set cur_dot */
-#endif /*IMAGEN*/
-
-	if(e_wding(&retdot, exp))
-	  {	ed_case(cur_dot,retdot,downp);
-		e_gosetcur(retdot);
-	  }
-#if IMAGEN
-	e_gosetcur(startdot);
-#endif /*IMAGEN*/
-}
-#endif /* any case_word caller */
Index: trunk/minix/commands/elle/eef2.c
===================================================================
--- trunk/minix/commands/elle/eef2.c	(revision 9)
+++ 	(revision )
@@ -1,314 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * EEF2		Various functions
- */
-
-#include "elle.h"
-
-/* Line Handling functions */
-
-/* EFUN: "Beginning of Line" */
-f_begline()
-{	e_gobol();
-	ed_setcur();
-}
-
-/* EFUN: "End of Line" */
-f_endline()
-{	e_goeol();
-	ed_setcur();
-}
-
-/* EFUN: "Next Line" */
-/*	Goes to beginning of next line */
-f_nxtline()
-{	return(down_bline(exp));
-}
-
-/* EFUN: "Previous Line" */
-/*	Goes to beginning of previous line */
-f_prvline()
-{	return(down_bline(-exp));
-}
-
-/* EFUN: "Down Real Line" */
-f_dnrline ()
-{	down_line(exp);
-}
-
-/* EFUN: "Up Real Line" */
-f_uprline ()
-{	down_line(-exp);
-}
-
-#if FX_OLINE
-/* EFUN: "Open Line" */
-f_oline()
-{	register int i;
-	chroff savdot;
-
-	savdot = cur_dot;
-	if((i = exp) > 0)
-		do { ed_crins(); }
-		while(--i);
-	e_gosetcur(savdot);
-}
-#endif /*FX_OLINE*/
-
-#if FX_DELBLINES
-/* EFUN: "Delete Blank Lines" */
-/*	Delete blank lines around point.
- */
-f_delblines()
-{	register int c;
-	chroff dot1, dot2, oldcur;
-
-	oldcur = cur_dot;
-	do { e_gobwsp(); }
-	while ((c = e_rgetc()) == LF);
-	if (c != EOF)
-		e_gonl();
-	dot1 = e_dot();
-	if(dot1 > oldcur) return;
-	do { e_gofwsp(); }
-	while ((c = e_getc()) == LF);
-	if(c != EOF)
-		e_gobol();
-	dot2 = e_dot();
-	if(dot2 < oldcur) return;
-	ed_delete(dot1,dot2);
-}
-#endif /*FX_DELBLINES*/
-
-#if FX_KLINE
-/* EFUN: "Kill Line" */
-f_kline()
-{
-	if(exp_p)
-		e_goline(exp);		/* Move that many lines */
-					/* (if 0, goes to BOL) */
-	else				/* No arg, handle specially */
-	  {	if(e_lblankp())		/* Is rest of line blank? */
-			;		/* Yes, now at next line! */
-		else e_goeol();		/* No, go to EOL rather than NL */
-	  }
-	ed_kill(cur_dot,e_dot());
-	e_setcur();
-	this_cmd = KILLCMD;
-}
-#endif /*FX_KLINE*/
-
-#if FX_BKLINE
-/* EFUN: "Backward Kill Line" (not EMACS) */
-/*	Originally an Iconographics function.
-*/
-f_bkline()
-{
-	if(exp_p) exp = -exp;		/* If arg, invert it */
-	else
-	  {	exp = 0;		/* No arg, furnish 0 */
-		exp_p = 1;
-	  }
-	f_kline();			/* Invoke "Kill Line" */
-}
-#endif /*FX_BKLINE*/
-
-#if FX_GOLINE
-/* EFUN: "Goto Line" (not EMACS) (GNU goto-line) */
-f_goline()
-{
-        e_gobob();
-        down_bline(exp-1);    /* already at line 1 */
-}
-#endif /*FX_GOLINE*/
-
-
-down_bline(arg)
-int arg;
-{	
-	if(arg)
-		e_goline(arg);
-	ed_setcur();
-}
-
-#if FX_DNRLINE || FX_UPRLINE
-down_line (x)
-int x;
-{	register int i, res;
-
-	res = x ? e_goline(x) : 1;	/* Move that many lines */
-	goal = 0;
-	if(res == 0)			/* Hit buffer limits (EOF)? */
-	  {	if(x > 0)		/* Moving downwards? */
-		  {
-#if !(IMAGEN)		/* If IMAGEN, do not extend!! */
-			if(x == 1) ed_crins();	/* Yeah, maybe extend */
-			else
-#endif
-				goal = indtion(cur_dot);
-			goto done;
-		  }
-	  }
-
-	if(last_cmd == LINECMD		/* If previous cmd also a line move */
-	  && pgoal != -1)		/* and we have a previous goal col */
-		goal = pgoal;		/* then make it the current goal */
-	else goal = indtion(cur_dot);	/* Else invent goal from current pos */
-
-	i = inindex(e_dot(), goal);	/* See # chars needed to reach goal */
-	if(i == -1)			/* If off edge of line, */
-		e_goeol();		/* just move to end of this line */
-	else e_igoff(i);		/* else move to goal. */
-
-done:	pgoal = goal;
-	this_cmd = LINECMD;
-	ed_setcur();
-}
-#endif /*FX_DNRLINE || FX_UPRLINE*/
-
-
-
-
-/* Region Handling functions */
-
-/* EFUN: "Set/Pop Mark" */
-f_setmark()
-{
-	mark_dot = e_dot();
-	mark_p = 1;
-	if(ev_markshow)			/* If have one, show indicator */
-		saytoo(ev_markshow);	/* that mark was set. */
-}
-
-/* EFUN: "Exchange Point and Mark" */
-f_exchmark()
-{	chroff tmpdot;
-
-	if(chkmark())
-	  {	tmpdot = mark_dot;
-		mark_dot = cur_dot;
-		ed_go(tmpdot);		/* Set cur_dot and go there */
-	  }
-}
-
-/* EFUN: "Kill Region" */
-f_kregion()
-{
-	if(chkmark())
-	  {	ed_kill(cur_dot,mark_dot); /* Will adj cur_dot, mark_dot */
-		e_gocur();
-		this_cmd = KILLCMD;
-	  }
-}
-
-/* EFUN: "Copy Region" */
-f_copreg()
-{
-	if(chkmark())
-	  {	e_gocur();
-		kill_push(e_copyn(mark_dot - cur_dot));
-		e_gocur();
-	  }
-}
-
-
-/* EFUN: "Uppercase Region" */
-f_ucreg()
-{	ef_creg(0);
-}
-
-/* EFUN: "Lowercase Region" */
-f_lcreg()
-{	ef_creg(1);
-}
-
-ef_creg(downp)
-int downp;
-{
-	if(chkmark())
-		ed_case(cur_dot,mark_dot,downp);
-}
-
-#if FX_FILLREG
-/* EFUN: "Fill Region" */
-f_fillreg()
-{	if(chkmark())
-		ed_fill(mark_dot,cur_dot,0);
-}
-#endif /*FX_FILLREG*/
-
-/* CHKMARK() - minor utility for region-hacking functions.
- *	Returns TRUE if mark exists.
- *	Otherwise complains to user and returns 0.
- */
-chkmark()
-{	if(mark_p == 0)
-		ding("No mark!");
-	return(mark_p);
-}
-
-
-/* Paragraph functions */
-
-#if FX_FPARA
-/* EFUN: "Forward Paragraph" */
-f_fpara()
-{	int e_gobpa(), e_goepa();
-
-	exp_do(e_goepa, e_gobpa);
-	ed_setcur();
-}
-#endif /*FX_FPARA*/
-
-#if FX_BPARA
-/* EFUN: "Backward Paragraph" */
-/*	Go to beginning of paragraph.
- *	Skip all whitespace until text seen, then stop at beginning of
- *	1st line starting with whitespace.
- */
-f_bpara()
-{	int e_gobpa(), e_goepa();
-
-	exp_do(e_gobpa, e_goepa);
-	ed_setcur();
-}
-#endif /*FX_BPARA*/
-
-#if FX_MRKPARA
-/* EFUN: "Mark Paragraph" */
-f_mrkpara()
-{
-	f_fpara();		/* Go to end of paragraph */
-	f_setmark();		/* Put mark there */
-	f_bpara();		/* Then back to start of paragraph */
-}
-#endif /*FX_MRKPARA*/
-
-#if FX_FILLPARA
-/* EFUN: "Fill Paragraph" */
-f_fillpara()
-{
-	chroff savloc, endloc;
-
-	savloc = cur_dot;
-#if ICONOGRAPHICS
-        e_getc();			/* DON'T go to next para if at end */
-        e_gobpa();			/* of this one!! */
-#endif /*ICONOGRAPHICS*/
-	e_goepa();			/* Go to end of parag */
-	if(e_rgetc() != LF)		/* If last char EOL, back over it. */
-		e_getc();
-	endloc = e_dot();		/* Remember where end is */
-	e_gobpa();			/* Go to beg of parag */
-#if ICONOGRAPHICS
-        kill_push(e_copyn(endloc - e_dot ()));
-                                        /* put old version on kill ring */
-#endif /*ICONOGRAPHICS*/
-	e_fwsp();			/* Move over initial whitespace */
-	ed_fill(e_dot(), endloc, 0);	/* Fill this region, return to dot */
-}
-#endif /*FX_FILLPARA*/
Index: trunk/minix/commands/elle/eef3.c
===================================================================
--- trunk/minix/commands/elle/eef3.c	(revision 9)
+++ 	(revision )
@@ -1,284 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * EEF3		Various Functions (Yanking, Indentation, miscellaneous)
- */
-
-#include "elle.h"
-
-#if FX_APPNKILL
-/* EFUN: "Append Next Kill" */
-f_appnkill()
-{	this_cmd = KILLCMD;	/* Fake out next call to ed_kill */
-}
-#endif /*FX_APPNKILL*/
-
-#if FX_UNKILL
-/* EFUN: "Un-kill" */
-f_unkill()
-{	register SBSTR *sd;
-
-	if((sd = kill_ring[kill_ptr]) == 0)
-	  {	ring_bell();
-		return;
-	  }
-	mark_dot = cur_dot;		/* Set mark at old location */
-	mark_p = 1;			/* Mark's been set */
-	sb_sins((SBBUF *)cur_buf,sbs_cpy(sd));	/* Insert copy of stuff */
-	cur_dot = e_dot();		/* We're now after the new stuff */
-	buf_tmat(mark_dot);		/* Say modified from here to cur_dot*/
-	this_cmd = YANKCMD;
-}
-#endif /*FX_UNKILL*/
-
-#if FX_UNKPOP
-/* EFUN: "Un-kill Pop" */
-f_unkpop()
-{	register SBSTR *sd;
-	register int i;
-
-	if (last_cmd != YANKCMD)
-	  {	ring_bell ();
-		return;
-	  }
-	ed_delete(cur_dot,mark_dot);
-	if(cur_dot > mark_dot)
-		cur_dot = mark_dot;
-	i = KILL_LEN;
-	do {
-		if(--kill_ptr < 0)
-			kill_ptr = KILL_LEN-1;
-		if(sd = kill_ring[kill_ptr])
-			break;
-	  } while(--i);
-
-	/* kill_ptr now pointing to right place; effect the yank. */
-	e_gocur();		/* Make sure point at right place too! */
-	return(f_unkill());
-}
-#endif /*FX_UNKPOP*/
-
-
-/* Indentation routines - still not polished */
-
-#if FX_INDATM
-/* EFUN: "Indent According to Mode" */
-/*	In Fundamental mode, just inserts a tab.
-*/
-f_indatm()
-{	f_insself(TAB);		/* This takes care of mode checking */
-}
-#endif /*FX_INDATM*/
-
-#if FX_INDNL
-/* EFUN: "Indent New Line" */
-f_indnl()			/* execute CR followed by tab */
-{
-#if IMAGEN
-	/* Not dispatch-based, but rather hard-wired to do Gosmacs thing */
-	ed_crins();
-	f_indund();
-#else
-	cmd_xct(CR);
-	cmd_xct(TAB);
-#endif /*-IMAGEN*/
-}
-#endif /*FX_INDNL*/
-
-
-#if FX_BACKIND
-/* EFUN: "Back to Indentation"
-**	Moves to end of current line's indentation.
-*/
-f_backind()
-{	e_gobol();	/* First move to beg of line */
-	e_gofwsp();	/* Then forward over whitespace */
-	ed_setcur();
-}
-#endif /*FX_BACKIND*/
-
-
-#if FX_INDCOMM
-
-static char *comm_beg = "/* ";
-static char *comm_end = " */";
-
-/* EFUN: "Indent for Comment" */
-f_indcomm()
-{
-	f_endline();
-	if(indtion(cur_dot) < ev_ccolumn)
-		ed_indto(ev_ccolumn);
-	else ed_sins("  ");
-	ed_sins (comm_beg);
-	ed_sins (comm_end);
-	e_igoff(-strlen (comm_end));       /* back over end string */
-	e_setcur();
-}
-#endif /*FX_INDCOMM*/
-
-#if FX_INDREL
-/* EFUN: "Indent Relative" */
-/* This used to mistakenly be called Indent Under.
-**	Still not fully implemented.
-**	If at beginning of line, looks back at previous indented line,
-** and indents this line that much.  If there is no preceding indented
-** line or not at beginning of line, insert a tab.
-*/
-f_indrel()
-{	register int c;
-	register  n;
-#if IMAGEN
-	chroff savdot;
-#endif /*IMAGEN*/
-#if ICONOGRAPHICS
-        chroff savdot;
-        int curind, newind, morebuf;
-#endif /*ICONOGRAPHICS*/
-
-	if((c = e_rgetc()) == EOF)
-#if IMAGEN
-		return(f_insself(TAB));	/* Do mode-based tabbing */
-#else
-		return(ed_insert(TAB));
-#endif /*-IMAGEN*/
-
-	if(c == LF)
-	  {	e_gobol();
-		e_gofwsp();
-		n = d_curind();
-		e_gonl();		/* Return to orig pos */
-		if(n)
-		  {	ed_indto(n);
-#if IMAGEN
-			savdot = e_dot();
-			e_gofwsp();
-			ed_delete(savdot, e_dot());
-#endif /*IMAGEN*/
-			return;
-		  }
-	  }
-#if ICONOGRAPHICS
-        else
-          {     e_igoff (1);
-                curind = indtion (savdot = e_dot ());
-                                /* get current dot and indentation */
-                while (1)       /* find a prev line that extends rightward */
-                   {    morebuf = e_gopl ();
-                        e_goeol ();
-                        if ((newind = d_curind()) > curind) break;
-                        if (morebuf == 0)  /* hit beginning of buffer */
-                        {       e_go (savdot);
-                                f_delspc();
-                                return (1);
-                        }
-                   }
-
-                e_gobol ();
-                e_igoff (inindex (e_dot (), curind));
-                if (d_curind() > curind)
-                        e_rgetc ();              /* pushed ahead by tab */
-
-                while (c_wsp (e_getc ()) == 0) ;
-                e_backc ();
-                e_fwsp ();
-                newind = d_curind();
-                e_go (savdot);
-                f_delspc();
-                ed_indto (newind);
-           }
-#else
-        else e_getc();
-#if IMAGEN
-	f_insself(TAB);			/* Do mode-based tabbing */
-#else
-	ed_insert(TAB);
-#endif /*-IMAGEN*/
-#endif /*-ICONOGRAPHICS*/
-}
-#endif /*FX_INDREL*/
-
-
-
-/* Paren matching stuff.  Note that this stuff will be very painful unless
-** tinwait() works properly.
-*/
-#if 0
-/* EFUN: "Self-Insert and Match" (intended to be bound to brackets) */
-/* (KLH: Evidently this was never finished)
-*/
-insertmatch(c)
-register int c;
-{
-	
-}
-#endif
-
-/* Should change this to Matching Paren */
-#if FX_MATCHBRACK
-/* EFUN: "Match Bracket" (not EMACS) - from IMAGEN config
- * Show the matching bracket for the character right before dot
- */
-f_matchbrack()
-{
-	chroff savdot;
-	register int i, mc, secs;
-
-	if (exp_p)
-		secs = exp;
-	else
-		secs = 1;
-	savdot = cur_dot;		/* Save our location */
-	mc = e_rgetc();			/* Pick up character before dot */
-	if (mc != ')' && mc != ']' && mc != '}')
-	  {	e_getc();		/* Nothing, try at dot instead */
-		e_getc();
-		mc = e_rgetc();
-		if (mc != ')' && mc != ']' && mc != '}')
-		  {	ding("What bracket?");
-			e_go(savdot);
-			return;
-		  }
-	  }
-	if (! matchonelevel(mc))
-		ring_bell();
-	else
-	  {	ed_setcur();
-	        if (d_line(cur_dot) < 0)
-			secs = 10;	/* Wait longer if off-screen */
-		redisplay();		/* Wish it were simple upd_wind() */
-	        for (i = 1; i <= secs; ++i)
-		  {	if (tinwait())
-				break;
-			sleep(1);
-	          }
-	  }
-	e_gosetcur(savdot);		/* Back to origin */
-	redp(RD_MOVE);			/* Cursor has moved */
-}
-
-
-/* Try to match 'mc', return true iff found it */
-matchonelevel(mc)
-register int mc;
-{
-	register int c;
-
-	while ((c = e_rgetc()) != EOF)
-	  {	if (c == /*[*/ ']' || c == /*(*/ ')' || c == /*{*/ '}')
-		  {	if (! matchonelevel(c))
-				break;
-		  }
-		else if (c == '(' /*)*/)
-			return(mc == /*(*/ ')');
-		else if (c == '[' /*]*/)
-			return(mc == /*[*/ ']');
-		else if (c == '{' /*}*/)
-			return(mc == /*{*/ '}');
-	  }
-	return(0);
-}
-#endif /*FX_MATCHBRACK*/
Index: trunk/minix/commands/elle/eefd.c
===================================================================
--- trunk/minix/commands/elle/eefd.c	(revision 9)
+++ 	(revision )
@@ -1,439 +1,0 @@
-/* ELLE - Copyright 1982, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-
-/* EEFD		Display control functions
- */
-
-#include "elle.h"
-
-
-#if FX_NEWWIN
-/* EFUN: "New Window" */
-/* 	Clear current window and set as requested.
- *		^L - clear current window and redisplay it (default top)
- *		<arg>^L - select new window so that current line is
- *			the <arg>'th from top of window (0 = top line)
- *		^U^L - clear current line and redisplay.
- */
-f_newwin()
-{	register int i, n;
-	register struct window *w;
-
-	d_fixcur();		/* Ensure screen vars correct */
-	w = cur_win;
-	if (exp_p)
-	  {	if((n = exp) == 4 && exp_p == 4		/* CTRL-U? */
-		  && (i = d_line(cur_dot)) >= 0)	/* On valid line? */
-		  {	d_lupd(w, i);			/* Update it */
-			return;
-		  }
-	  }
-	else			/* No argument given */
-	  {	redp(RD_SCREEN);	/* Clear whole screen (later just window? */
-#if IMAGEN
-		return;
-#else
-		n = (ev_nwpct*w->w_ht)/100;	/* Set new window using % */
-#endif /*-IMAGEN*/
-	  }
-	if (n < 0) n = 0;		/* Ensure # is reasonable */
-	else if (n >= w->w_ht)
-		n = w->w_ht - 1;
-	d_fgoloff(-n);			/* Go up given # of lines */
-	w->w_topldot = e_dot();		/* Set new top-line dot */
-	e_gocur();			/* Move back to cur_dot */
-	redp(RD_FIXWIN);		/* Say to re-hack window */
-}
-#endif /*FX_NEWWIN*/
-
-#if FX_NSCREEN
-/* EFUN: "Next Screen" */
-f_nscreen()
-{	d_screen( exp);
-}
-#endif /*FX_NSCREEN*/
-
-#if FX_PSCREEN
-/* EFUN: "Previous Screen" */
-f_pscreen()
-{	d_screen(-exp);
-}
-#endif /*FX_PSCREEN*/
-
-#if FX_OTHNSCREEN
-/* EFUN: "Other New Screen" (not EMACS) - from IMAGEN config */
-f_othnscreen()
-{
-	if (! oth_win)
-		return;
-	f_othwind();
-	if (exp_p)			/* With arg, back up */
-		d_screen(-1);
-	else
-		d_screen(1);
-	f_othwind();
-	redp(RD_WINDS);			/* Look at all windows */
-}
-#endif /*FX_OTHNSCREEN*/
-
-
-#if FX_LWINDBORD
-/* EFUN: "Line to Window Border" (not EMACS) - from IMAGEN config */
-f_lwindbord()
-{
-	if (exp_p)
-		/* With arg, means "to bottom" */
-		exp = cur_win->w_ht - 1;
-	else
-		/* Else, to top */
-		exp = 0;
-
-	/* Just a "front end" for ^L */
-	exp_p = 1;
-	f_newwin();
-}
-#endif /*FX_LWINDBORD*/
-
-#if FX_SCUPWIND
-/* EFUN: "Scroll Window Up" (not EMACS) - from IMAGEN config */
-f_scupwind()
-{
-	scroll_win(exp);
-}
-#endif /*FX_SCUPWIND*/
-
-#if FX_SCDNWIND
-/* EFUN: "Scroll Window Down" (not EMACS) - from IMAGEN config */
-f_scdnwind()
-{
-	scroll_win(-exp);
-}
-#endif /*FX_SCDNWIND*/
-
-
-#if FX_MVWTOP
-/* EFUN: "Move to Window Top" (not EMACS) - from IMAGEN config */
-f_mvwtop()
-{
-	extern moveborder();
-	moveborder(1);
-}
-#endif /*FX_MVWTOP*/
-
-#if FX_MVWBOT
-/* EFUN: "Move to Window Bottom" (not EMACS) - from IMAGEN config */
-f_mvwbot()
-{
-	extern moveborder();
-	moveborder(0);
-}
-#endif /*FX_MVWBOT*/
-
-
-
-
-#if FX_NSCREEN || FX_PSCREEN || FX_OTHNSCREEN
-/* Move to new loc by N screenfuls.
- * If moving downward, keep bottom 2 lines of current screen on top of next.
- * If moving up, keep top 2 lines of current screen on bottom of next.
- */
-d_screen(rep)
-int rep;
-{
-	register int i;
-	register struct window *w;
-	chroff newdot;
-
-	w = cur_win;
-	if((i = w->w_ht - 2) <= 0)	/* Just-in-case check */
-		i = 1;
-	if((i *= rep) == 0)
-		return;
-	d_fixcur();			/* Ensure window fixed up */
-	e_go(w->w_topldot);		/* Start at top of screen */
-	d_fgoloff(i);
-
-	/* Find where we are now, and make that the new top of window. */
-	if((newdot = e_dot()) != e_blen())	/* If not at EOF, */
-		w->w_topldot = newdot;	/* set new top of window! */
-	else w->w_topldot = 0;		/* Else let fix_wind select top. */
-
-	e_setcur();			/* Ensure cur_dot set to real loc */
-#if IMAGEN
-	redp(RD_WINRES|RD_REDO);	/* HINT: just repaint screen */
-#else
-	redp(RD_FIXWIN|RD_MOVE);
-#endif /*-IMAGEN*/
-}
-#endif /*FX_NSCREEN || FX_PSCREEN || FX_OTHNSCREEN*/
-
-
-#if FX_SCUPWIND || FX_SCDNWIND	/* If want scroll-window function */
-scroll_win(n)
-register int n;
-{	register struct window *w = cur_win;
-	chroff savdot;
-
-	if (n == 0) return;
-	d_fixcur();		/* Ensure screen vars for win all set up */
-	e_go(w->w_topldot);	/* Go to top of current window */
-	d_fgoloff(n);		/* Move given # of display lines */
-	w->w_topldot = e_dot();	/* Set new top of window */
-	redp(RD_FIXWIN);	/* Say new window needs fixing up */
-
-	/* Now adjust position of current dot so it is still within window */
-	if (n > 0)
-	  {	/* Moving screen text "up" (win down) */
-		if (cur_dot < w->w_topldot)	/* See if scrolled off top */
-			e_setcur();		/* yes, make dot be win top */
-	  }
-	else {	/* Moving screen text "down" (win up) */
-		savdot = cur_dot;	/* Save since must temporarily */
-		e_setcur();		/* set current dot within window, */
-		d_fixcur();		/* so screen can be fixed up. */
-		if (inwinp(w, savdot))	/* Now see if old dot in new win */
-			cur_dot = savdot;	/* Yes, just restore it! */
-		else			/* No, make it beg of bottom line. */
-			cur_dot = scr[w->w_pos + w->w_ht - 1]->sl_boff;
-	  }
-	e_gocur();		/* Make current pos be cur_dot */
-}
-#endif /* FX_SC%%WIND */
-
-#if FX_MVWTOP || FX_MVWBOT	/* Guts for above two functions */
-static
-moveborder(top)
-int top;
-{
-	d_fixcur();		/* Ensure current win screen image fixed up */
-	e_gosetcur(top ? cur_win->w_topldot
-			: scr[cur_win->w_pos + cur_win->w_ht - 1]->sl_boff);
-
-	redp(RD_MOVE);		/* Should only be cursor adjustment */
-}
-#endif /*FX_MVW%%%*/
-
-
-/* Given a line and a position in that line, return the xpos.
- * NOTE CAREFULLY that when line extends over several screen lines,
- * the value returned is the screen X position even though it
- * may be some lines down from the start of the logical line!
- * Also note this won't work very well if tabs exist on the extra
- * lines.  This rtn should not be used for cursor positioning.
- * Also note: d_ncols() will never return -1 meaning EOL because the
- * setup guarantees there is no EOL within the range checked.
- */
-d_curind()	/* Find current indentation */
-{	indtion(e_dot());
-}
-indtion(lin)
-chroff lin;
-{	register int i, col;
-	chroff savdot;
-	chroff nchars;
-
-	savdot = e_dot();		/* Save current position */
-	e_go(lin);			/* Go to line caller wants */
-	e_gobol();			/* Go to its beginning */
-	col = 0;			/* Start at left margin */
-	if((nchars = lin - e_dot()) > 0)
-	    do {
-		if(nchars < (i = scr_wd0))
-			i = nchars;
-		if((col = d_ncols(i, col)) < 0)	/* Hit edge of screen? */
-			col = 0;		/* Reset to left margin */
-	    } while((nchars -= i) > 0);
-	e_go(savdot);			/* Restore current position */
-	return(col);
-}
-
-/* ININDEX - How many positions in lin must we go to get to xpos?
- * Returns -1 if can't be done.  Assumes "lin" is at beginning of a line!
- */
-
-inindex (lin, xpos)
-chroff lin;
-int   xpos;
-{	register int col, x;
-	chroff savdot;
-	char tmp[MAXLINE+MAXCHAR];
-	extern int sctreol;		/* From EEDISP */
-
-	if((x = xpos) <= 0) return(0);
-	if(x >= MAXLINE) return(-1);	/* ?!? */
-	col = 0;
-	savdot = e_dot();
-	e_go(lin);			/* Assumes this is start of line */
-	col = sctrin(tmp, x, 0);	/* Translate from sb_getc input */
-	if((col - x) >= 0)		/* Exact count-out or past it? */
-	  {	x = e_dot() - lin;	/* Yup, win. */
-		if (sctreol > 0)	/* Did we hit (and include) EOL? */
-#if FX_EOLMODE			/* If so, back up over the EOL. */
-			x -= eolcrlf(cur_buf) ? 2 : 1;
-#else
-			--x;
-#endif
-	  }
-	else x = -1;			/* Nope, EOL or EOF hit too soon. */
-	e_go(savdot);
-	return(x);
-}
-
-
-/*
- * D_ ROUTINES - display-relative functions.  Similar to E_, but
- *	a "line" is defined as one line of the screen rather than
- *	as a logical text line.  Also, for efficiency reasons
- *	arguments are given saying how many lines to hack.
- */
-
-d_gopl() { return(d_goloff(-1)); }
-d_gonl() { return(d_goloff( 1)); }
-
-/* D_GOLOFF(i) - Go to beginning of a display line
- * D_FGOLOFF(i) - ditto, but assumes screen image of window already fixed up.
- *	i - # of lines offset.  Negative moves up, positive down.
- *		Zero arg goes to beginning of current display line.
- *	Side effects: screen image of window is fixed up at
- *	start of routine, but is NOT updated by the move to new location.
- */
-d_goloff(cnt)
-int cnt;
-{	d_fixcur();
-	d_fgoloff(cnt);		/* Now can invoke fixed-up fast version */
-}
-d_fgoloff(cnt)
-register int cnt;
-{	register int y;
-	struct scr_line l;
-	char line[MAXLINE+MAXCHAR];
-	int top, bot;
-
-	/* Find current position in window, since can save time
-	 * by using stuff already in fixed-up screen image.
-	 */
-	if((y = d_line(e_dot())) < 0)		/* Get current Y position */
-	  {
-		errbarf("Dot out of window");
-		y = 0;
-	  }
-	top = cur_win->w_pos;		/* 1st line of window */
-	bot = top + cur_win->w_ht;	/* 1st line not in window */
-	l.sl_boff = scr[y]->sl_boff;
-	l.sl_nlin = &line[0];
-	l.sl_cont = 0;
-
-	if(cnt > 0) goto down;
-	
-	/* Go upwards.  This is hairy because we want to be clever about
-	 * huge logical lines -- avoid going all the way back to BOL.
-	 */
-	if((y+cnt) >= top)	/* Fits? */
-		goto onscr;	/* Hurray, hack it! */
-	cnt += y - top;		/* Sigh, find # lines to skip */
-	y = top;
-	l.sl_boff = scr[y]->sl_boff;
-	e_go(l.sl_boff);
-
-	/* Okay, here's the hairy part.  Must go backwards from top
-	 * line; if no EOL within scr_wid*cnt chars, then simply assume one is
-	 * seen.
-	 */
-	cnt = -cnt;
-	d_backup(cnt);
-	return;		/* Really should re-adjust stuff, but... */
-
-	/* Go downwards.  Not too bad... */
-down:
-	if((y+cnt) <= bot)	/* Fits? */
-		goto onscr;	/* Hurray, hack it! */
-	cnt -= bot - y;		/* Sigh, find # lines can skip */
-	y = bot - 1;
-	l.sl_boff = scr[y]->sl_boff + scr[y]->sl_len;
-	if(y > top
-	  && (l.sl_cont = scr[y-1]->sl_cont))
-		l.sl_line = scr[y-1]->sl_line;
-	e_go(l.sl_boff);
-
-	do {
-		fix_line(&l,&l);
-	  } while(--cnt > 0 && l.sl_len);
-	return;
-
-onscr:	if((y += cnt) >= bot)
-	  {	--y;
-		e_go(scr[y]->sl_boff + scr[y]->sl_len);
-	  }
-	else e_go(scr[y]->sl_boff);
-}
-
-/* D_FIXCUR() - Ensure current window is fixed up, with
- *	current location (not necessarily cur_dot)!
- * Ensure cur_dot reflects real loc so that fix_wind will work,
- * and always call fix_wind to ensure that screen image vars
- * are set properly.  Note any active redisplay flags must be carried
- * on into window redisplay flags, so fix_wind will notice them.
- */
-d_fixcur()
-{	register struct window *w;
-	chroff savedot;
-
-	w = cur_win;
-	savedot = cur_dot;
-	e_setcur();
-	w->w_redp |= rd_type&RDS_WINFLGS;
-	fix_wind(w);		/* Always ensure window is set up! */
-	redp(w->w_redp);	/* Add back new flags */
-	rd_type &= ~RDS_DOFIX;	/* and flush fix-invoking ones */
-	cur_dot = savedot;	/* Restore cur_dot, no longer hacked. */
-}
-
-
-d_backup(nlin)		/* Try to back up by nlin screen lines */
-int nlin;
-{	register int cnt, n, c;
-	int eolstop;
-
-	if((cnt = nlin+1) <= 0) return;
-	c = 0;
-	do
-	  {	n = scr_wid;
-		eolstop = 0;		/* Not yet stopped at EOL */
-		do {	if((c = e_rgetc()) == EOF)
-				return;
-			if(c == LF)
-			  {
-#if FX_EOLMODE
-				if(eolcrlf(cur_buf))
-				  {	if((c = e_rgetc()) == CR)
-					  {	eolstop++;
-						break;
-					  }
-					if(c != EOF)
-						e_getc();
-				  }
-				else
-#endif
-				  {	eolstop++;
-					break;
-				  }
-			  }
-		  } while(--n);
-	  } while(--cnt);
-	if(eolstop)
-	  {
-#if FX_EOLMODE
-		if(eolcrlf(cur_buf)) e_getc();	/* Skip back over CR */
-#endif
-		e_getc();		/* Skip back over LF */
-	  }
-
-	/* At this point, dot is guaranteed to be less than goal,
-	 * which is the important thing for fix_wind, which can handle
-	 * things okay if dot is off bottom of window.
-	 */
-	return(1);		/* Say always test result */
-}
Index: trunk/minix/commands/elle/eefdef.h
===================================================================
--- trunk/minix/commands/elle/eefdef.h	(revision 9)
+++ 	(revision )
@@ -1,159 +1,0 @@
-/* .H Function Definition file, generated by ELLEC */
-/*   0 */ EFUNHOLE /* Always undefined */
-/*   1 */ EFUN( f_insself   , "f_insself"   , "Insert Self")
-/*   2 */ EFUN( f_quotins   , "f_quotins"   , "Quoted Insert")
-/*   3 */ EFUN( f_crlf      , "f_crlf"      , "CRLF")
-/*   4 */ EFUN( f_fchar     , "f_fchar"     , "Forward Character")
-/*   5 */ EFUN( f_bchar     , "f_bchar"     , "Backward Character")
-/*   6 */ EFUN( f_dchar     , "f_dchar"     , "Delete Character")
-/*   7 */ EFUN( f_bdchar    , "f_bdchar"    , "Backward Delete Character")
-/*   8 */ EFUN( f_delspc    , "f_delspc"    , "Delete Horizontal Space")
-/*   9 */ EFUN( f_tchars    , "f_tchars"    , "Transpose Characters")
-/*  10 */ EFUN( f_fword     , "f_fword"     , "Forward Word")
-/*  11 */ EFUN( f_bword     , "f_bword"     , "Backward Word")
-/*  12 */ EFUN( f_kword     , "f_kword"     , "Kill Word")
-/*  13 */ EFUN( f_bkword    , "f_bkword"    , "Backward Kill Word")
-/*  14 */ EFUN( f_twords    , "f_twords"    , "Transpose Words")
-/*  15 */ EFUN( f_ucword    , "f_ucword"    , "Uppercase Word")
-/*  16 */ EFUN( f_lcword    , "f_lcword"    , "Lowercase Word")
-/*  17 */ EFUN( f_uciword   , "f_uciword"   , "Uppercase Initial")
-/*  18 */ EFUNHOLE
-/*  19 */ EFUNHOLE
-/*  20 */ EFUN( f_begline   , "f_begline"   , "Beginning of Line")
-/*  21 */ EFUN( f_endline   , "f_endline"   , "End of Line")
-/*  22 */ EFUN( f_nxtline   , "f_nxtline"   , "Next Line")
-/*  23 */ EFUN( f_prvline   , "f_prvline"   , "Previous Line")
-/*  24 */ EFUN( f_dnrline   , "f_dnrline"   , "Down Real Line")
-/*  25 */ EFUN( f_uprline   , "f_uprline"   , "Up Real Line")
-/*  26 */ EFUN( f_oline     , "f_oline"     , "Open Line")
-/*  27 */ EFUN( f_delblines , "f_delblines" , "Delete Blank Lines")
-/*  28 */ EFUN( f_kline     , "f_kline"     , "Kill Line")
-/*  29 */ EFUN( f_bkline    , "f_bkline"    , "Backward Kill Line")
-/*  30 */ EFUN( f_goline    , "f_goline"    , "Goto Line")
-/*  31 */ EFUNHOLE
-/*  32 */ EFUNHOLE
-/*  33 */ EFUNHOLE
-/*  34 */ EFUNHOLE
-/*  35 */ EFUN( f_setmark   , "f_setmark"   , "Set/Pop Mark")
-/*  36 */ EFUN( f_exchmark  , "f_exchmark"  , "Exchange Point and Mark")
-/*  37 */ EFUN( f_kregion   , "f_kregion"   , "Kill Region")
-/*  38 */ EFUN( f_copreg    , "f_copreg"    , "Copy Region")
-/*  39 */ EFUN( f_ucreg     , "f_ucreg"     , "Uppercase Region")
-/*  40 */ EFUN( f_lcreg     , "f_lcreg"     , "Lowercase Region")
-/*  41 */ EFUN( f_fillreg   , "f_fillreg"   , "Fill Region")
-/*  42 */ EFUNHOLE
-/*  43 */ EFUNHOLE
-/*  44 */ EFUNHOLE
-/*  45 */ EFUN( f_fpara     , "f_fpara"     , "Forward Paragraph")
-/*  46 */ EFUN( f_bpara     , "f_bpara"     , "Backward Paragraph")
-/*  47 */ EFUN( f_mrkpara   , "f_mrkpara"   , "Mark Paragraph")
-/*  48 */ EFUN( f_fillpara  , "f_fillpara"  , "Fill Paragraph")
-/*  49 */ EFUNHOLE
-/*  50 */ EFUN( f_selbuffer , "f_selbuffer" , "Select Buffer")
-/*  51 */ EFUN( f_selxbuffer, "f_selxbuffer", "Select Existing Buffer")
-/*  52 */ EFUN( f_kbuffer   , "f_kbuffer"   , "Kill Buffer")
-/*  53 */ EFUN( f_listbufs  , "f_listbufs"  , "List Buffers")
-/*  54 */ EFUN( f_bufnotmod , "f_bufnotmod" , "Buffer Not Modified")
-/*  55 */ EFUN( f_eolmode   , "f_eolmode"   , "EOL CRLF Mode")
-/*  56 */ EFUN( f_gobeg     , "f_gobeg"     , "Goto Beginning")
-/*  57 */ EFUN( f_goend     , "f_goend"     , "Goto End")
-/*  58 */ EFUN( f_whatpage  , "f_whatpage"  , "What Page")
-/*  59 */ EFUNHOLE
-/*  60 */ EFUN( f_ffile     , "f_ffile"     , "Find File")
-/*  61 */ EFUN( f_rfile     , "f_rfile"     , "Read File")
-/*  62 */ EFUN( f_vfile     , "f_vfile"     , "Visit File")
-/*  63 */ EFUN( f_ifile     , "f_ifile"     , "Insert File")
-/*  64 */ EFUN( f_sfile     , "f_sfile"     , "Save File")
-/*  65 */ EFUN( f_savefiles , "f_savefiles" , "Save All Files")
-/*  66 */ EFUN( f_wfile     , "f_wfile"     , "Write File")
-/*  67 */ EFUN( f_wreg      , "f_wreg"      , "Write Region")
-/*  68 */ EFUN( f_wlastkill , "f_wlastkill" , "Write Last Kill")
-/*  69 */ EFUNHOLE
-/*  70 */ EFUN( f_2winds    , "f_2winds"    , "Two Windows")
-/*  71 */ EFUN( f_1wind     , "f_1wind"     , "One Window")
-/*  72 */ EFUN( f_othwind   , "f_othwind"   , "Other Window")
-/*  73 */ EFUN( f_growind   , "f_growind"   , "Grow Window")
-/*  74 */ EFUN( f_shrinkwind, "f_shrinkwind", "Shrink Window")
-/*  75 */ EFUN( f_delwind   , "f_delwind"   , "Delete Window")
-/*  76 */ EFUN( f_sowind    , "f_sowind"    , "Standout Window")
-/*  77 */ EFUN( f_2modewinds, "f_2modewinds", "Two Mode Windows")
-/*  78 */ EFUN( f_newwin    , "f_newwin"    , "New Window")
-/*  79 */ EFUN( f_nscreen   , "f_nscreen"   , "Next Screen")
-/*  80 */ EFUN( f_pscreen   , "f_pscreen"   , "Previous Screen")
-/*  81 */ EFUNHOLE
-/*  82 */ EFUNHOLE
-/*  83 */ EFUN( f_scupwind  , "f_scupwind"  , "Scroll Window Up")
-/*  84 */ EFUN( f_scdnwind  , "f_scdnwind"  , "Scroll Window Down")
-/*  85 */ EFUN( f_mvwtop    , "f_mvwtop"    , "Move to Window Top")
-/*  86 */ EFUN( f_mvwbot    , "f_mvwbot"    , "Move to Window Bottom")
-/*  87 */ EFUNHOLE
-/*  88 */ EFUNHOLE
-/*  89 */ EFUNHOLE
-/*  90 */ EFUN( f_setprof   , "f_setprof"   , "Set Profile")
-/*  91 */ EFUN( f_pfxmeta   , "f_pfxmeta"   , "Prefix Meta")
-/*  92 */ EFUN( f_pfxext    , "f_pfxext"    , "Prefix Extend")
-/*  93 */ EFUN( f_uarg      , "f_uarg"      , "Universal Arg")
-/*  94 */ EFUN( f_negarg    , "f_negarg"    , "Negative Argument")
-/*  95 */ EFUN( f_argdig    , "f_argdig"    , "Argument Digit")
-/*  96 */ EFUN( f_vtbuttons , "f_vtbuttons" , "VT100 Button Hack")
-/*  97 */ EFUN( f_describe  , "f_describe"  , "Describe")
-/*  98 */ EFUNHOLE
-/*  99 */ EFUNHOLE
-/* 100 */ EFUN( f_skmac     , "f_skmac"     , "Start Kbd Macro")
-/* 101 */ EFUN( f_ekmac     , "f_ekmac"     , "End Kbd Macro")
-/* 102 */ EFUN( f_xkmac     , "f_xkmac"     , "Execute Kbd Macro")
-/* 103 */ EFUN( f_vkmac     , "f_vkmac"     , "View Kbd Macro")
-/* 104 */ EFUNHOLE
-/* 105 */ EFUN( f_unkill    , "f_unkill"    , "Un-kill")
-/* 106 */ EFUN( f_unkpop    , "f_unkpop"    , "Un-kill Pop")
-/* 107 */ EFUN( f_appnkill  , "f_appnkill"  , "Append Next Kill")
-/* 108 */ EFUNHOLE
-/* 109 */ EFUNHOLE
-/* 110 */ EFUN( f_srch      , "f_srch"      , "String Search")
-/* 111 */ EFUN( f_rsrch     , "f_rsrch"     , "Reverse String Search")
-/* 112 */ EFUN( f_isrch     , "f_isrch"     , "Incremental Search")
-/* 113 */ EFUN( f_risrch    , "f_risrch"    , "Reverse Search")
-/* 114 */ EFUN( f_repstr    , "f_repstr"    , "Replace String")
-/* 115 */ EFUN( f_querep    , "f_querep"    , "Query Replace")
-/* 116 */ EFUN( f_repline   , "f_repline"   , "Replace in Line")
-/* 117 */ EFUN( f_sfcol     , "f_sfcol"     , "Set Fill Column")
-/* 118 */ EFUN( f_sfpref    , "f_sfpref"    , "Set Fill Prefix")
-/* 119 */ EFUN( f_fillmode  , "f_fillmode"  , "Auto Fill Mode")
-/* 120 */ EFUNHOLE
-/* 121 */ EFUN( f_indatm    , "f_indatm"    , "Indent According to Mode")
-/* 122 */ EFUN( f_indnl     , "f_indnl"     , "Indent New Line")
-/* 123 */ EFUN( f_backind   , "f_backind"   , "Back to Indentation")
-/* 124 */ EFUN( f_indcomm   , "f_indcomm"   , "Indent for Comment")
-/* 125 */ EFUN( f_indrel    , "f_indrel"    , "Indent Relative")
-/* 126 */ EFUNHOLE
-/* 127 */ EFUNHOLE
-/* 128 */ EFUNHOLE
-/* 129 */ EFUNHOLE
-/* 130 */ EFUN( f_pshinf    , "f_pshinf"    , "Push to Inferior")
-/* 131 */ EFUN( f_retsup    , "f_retsup"    , "Return to Superior")
-/* 132 */ EFUN( f_wfexit    , "f_wfexit"    , "Write File Exit")
-/* 133 */ EFUNHOLE
-/* 134 */ EFUNHOLE
-/* 135 */ EFUNHOLE
-/* 136 */ EFUNHOLE
-/* 137 */ EFUNHOLE
-/* 138 */ EFUNHOLE
-/* 139 */ EFUNHOLE
-/* 140 */ EFUN( f_bkpt      , "f_bkpt"      , "Hit Breakpoint")
-/* 141 */ EFUN( f_debug     , "f_debug"     , "Debug Mode")
-/* 142 */ EFUNHOLE
-/* 143 */ EFUNHOLE
-/* 144 */ EFUNHOLE
-/* 145 */ EFUNHOLE
-/* 146 */ EFUNHOLE
-/* 147 */ EFUNHOLE
-/* 148 */ EFUNHOLE
-/* 149 */ EFUNHOLE
-/* 150 */ EFUNHOLE
-/* 151 */ EFUNHOLE
-/* 152 */ EFUNHOLE
-/* 153 */ EFUNHOLE
-/* 154 */ EFUNHOLE
-/* 155 */ EFUNHOLE
-/* 156 */ EFUNHOLE
-/* 157 */ EFUNHOLE
Index: trunk/minix/commands/elle/eefed.c
===================================================================
--- trunk/minix/commands/elle/eefed.c	(revision 9)
+++ 	(revision )
@@ -1,285 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*	EEFED - ED-type functions
- */
-#include "elle.h"
-
-/*
- * ED_INSERT -- Insert character given as argument.
- */
-
-ed_insert(c)
-int c;
-{	register SBBUF *sb;
-
-	sb = (SBBUF *) cur_buf;		/* For a little speed */
-	sb_putc(sb,c);		/* Insert the char */
-	cur_dot++;		/* Advance dot */
-	buf_tmod((chroff)-1);	/* Mark buffer modified, for redisplay etc. */
-				/* Perhaps later use specialized routine? */
-}
-
-ed_insn(ch, cnt)
-int ch, cnt;
-{	register int i;
-	if((i = cnt) > 0)
-		do { ed_insert(ch);
-		  } while(--i);
-}
-
-ed_crins()
-{
-#if FX_EOLMODE
-	if (eolcrlf(cur_buf))	/* If EOL is made of CR-LF */
-		ed_insert(CR);	/* then first insert CR, then drop down to */
-#endif
-	ed_insert(LF);		/* Insert LF */
-}
-
-
-ed_sins (s)			       /* insert this string */
-register char *s;
-{	register c;
-	while (c = *s++)
-		ed_insert (c);
-}
-
-ed_nsins (s, i)		/* Insert string of N chars */
-register char *s;
-register int i;
-{	if(i > 0)
-		do { ed_insert(*s++); } while(--i);
-}
-
-/* ED_INDTO(col) - Indent to specified column.
-**	Finds current cursor position, and inserts tabs and spaces
-** so cursor ends up at column goal.  Does nothing if already at or past
-** specified column.
-*/
-
-ed_indto(goal)
-register int goal;
-{	register int ng;
-
-	ng = goal & ~07;		/* Get distance to tab stop */
-	ed_insn(TAB, ((ng - (d_curind() & ~07)) >> 3));
-	ed_insn(SP, goal-ng);
-}
-
-
-/* Oddball routine - Set cur_dot to actual I/O location and
- * tell display that cursor probably moved.  This is not really a
- * function of itself; it provides support for real functions.
- */
-ed_setcur()
-{	e_setcur();	/* Set cur_dot */
-	redp(RD_MOVE);	/* Alert redisplay to check cursor loc */
-}
-
-/* Go to given dot */
-ed_go (dot)
-chroff dot;
-{	e_go(dot);
-	ed_setcur();
-}
-
-/* Go to given offset from current location */
-ed_goff(off)
-chroff off;
-{	e_goff(off);
-	ed_setcur();
-}
-
-/* Go to given INTEGER offset from current location */
-ed_igoff(ioff)
-int ioff;
-{	e_igoff(ioff);
-	ed_setcur();
-}
-
-/* Reset (delete all of) Buffer
- * Should buffer be marked modified or not? Currently isn't.
- */
-ed_reset()
-{	if(e_blen() == 0)
-		return;		/* Already empty */
-	e_reset();
-	cur_dot = 0;
-	cur_win->w_topldot = 0;	/* Is this necessary? */
-#if IMAGEN
-	redp(RD_WINRES|RD_REDO);
-#else
-	redp(RD_WINRES);	/* This window needs complete update */
-#endif /*-IMAGEN*/
-
-/*	buf_mod(); */		/* Mark modified ?? */
-/*	mark_p = 0; */		/* Say no mark set ?? */
-}
-
-ed_deln(off)
-chroff off;
-{	chroff dot;
-	dot = e_dot();
-	e_goff(off);	
-	ed_delete(e_dot(), dot);
-}
-
-/* ED_DELETE(dot1,dot2) -  Delete all characters between the two
- *	positions indicated by dot1 and dot2.  Their order does not
- *	matter; cur_dot and mark_dot are updated as necessary.
- */
-ed_delete(dot1,dot2)
-chroff dot1,dot2;
-{	chroff tmpdot, savdot;
-
-	if(dot1 > dot2)
-	  {	tmpdot = dot1;
-		dot1 = dot2;
-		dot2 = tmpdot;
-	  }
-	e_go(dot1);
-	tmpdot = dot2-dot1;
-	sb_deln((SBBUF *)cur_buf,tmpdot);
-
-	savdot = cur_dot;		/* Save cur_dot value */
-	cur_dot = dot1;			/* so can set up for */
-	buf_tmod((chroff)0);		/* call to update disp-change vars */
-	cur_dot = savdot;
-
-	if(cur_dot >= dot2)
-		cur_dot -= tmpdot;
-	else if(cur_dot > dot1)
-		cur_dot = dot1;
-	if(mark_dot >= dot2)
-		mark_dot -= tmpdot;
-	else if(mark_dot > dot1)
-		mark_dot = dot1;
-	e_gocur();
-}
-
-/* ED_KILL(dot1,dot2) - Kill (save and delete) text between two places in
- *	the buffer.
- * We assume we are deleting from dot1 to dot2, thus if dot1 > dot2
- * then backwards deletion is implied, and the saved text is prefixed
- * (instead of appended) to any previously killed text.
- */
-ed_kill(dot1,dot2)
-chroff dot1,dot2;
-{	register SBSTR *sd, *sdo;
-	SBSTR *e_copyn();
-
-	e_go(dot1);
-	sd = e_copyn(dot2-dot1);
-	if(sd == 0) return;
-	if(last_cmd == KILLCMD && (sdo = kill_ring[kill_ptr]))
-	  {	if(dot1 > dot2)	/* Prefix new killed stuff onto old stuff */
-		  {	sbs_app(sd,sdo);
-			kill_ring[kill_ptr] = sd;
-		  }
-		else		/* Append new stuff to old stuff */
-			sbs_app(sdo,sd);
-	  }
-	else kill_push(sd);
-	ed_delete(dot1,dot2);
-}
-
-kill_push(sdp)
-SBSTR *sdp;
-{	register SBSTR *sd;
-
-	if(++kill_ptr >= KILL_LEN) kill_ptr = 0;
-	if(sd = kill_ring[kill_ptr])
-		sbs_del(sd);
-	kill_ring[kill_ptr] = sdp;
-}
-
-
-
-#define isupper(c) (('A' <= c) && (c <= 'Z'))
-#define islower(c) (('a' <= c) && (c <= 'z'))
-#define toupper(c) (c + ('A' - 'a'))
-#define tolower(c) (c + ('a' - 'A'))
-
-#if FX_UCWORD||FX_LCWORD||FX_UCIWORD||FX_UCREG||FX_LCREG
-
-/* ED_CASE(dot1,dot2,downp) - Change the case within a region.
- *	downp = 0 for uppercase, 1 for lowercase, 2 for capitalize.
- */
-ed_case(dot1, dot2, downp)
-chroff dot1, dot2;
-int downp;
-{	chroff dcnt;
-	register int c, a, z;
-	int modflg;
-
-	modflg = 0;
-	if((dcnt = dot2 - dot1) < 0)
-	  {	dcnt = dot1;
-		dot1 = dot2;
-		dot2 = dcnt;
-		dcnt -= dot1;
-	  }
-	e_go(dot1);
-
-	if(downp==2)
-	  {	a = 0;	/* 0 looking for wd, 1 in word */
-		while(--dcnt >= 0)
-		  {	if(delimp(c = e_getc()))	/* Char in wd? */
-			  {	a = 0;			/* No */
-				continue;
-			  }
-			 if(a)		/* If already inside word */
-			  {	if(isupper(c))
-					c = tolower(c);
-				else continue;
-			  }
-			else	/* If encountered start of word */
-			  {	a = 1;
-				if(islower(c))
-					c = toupper(c);
-				else continue;
-			  }
-			e_backc();
-			e_ovwc(c);
-			modflg++;
-		  }
-		goto casdon;
-	  }
-	if(downp==0)
-	  {	a = 'a';		/* Convert to lower case */
-		z = 'z';
-		downp = -040;
-	  }
-	else
-	  {	a = 'A';		/* Convert to upper case */
-		z = 'Z';
-		downp = 040;
-	  }
-	while(--dcnt >= 0)
-	  {	if(a <= (c = e_getc()) && c <= z)
-		  {	e_backc();
-			e_ovwc(c+downp);
-			modflg++;
-		  }
-	  }
-
-casdon:	dot2 = cur_dot;			/* Save dot */
-	e_setcur();			/* Set up for modification range chk*/
-	if(modflg)
-		buf_tmat(dot1);		/* Stuff munged from there to here */
-	ed_go(dot2);
-}
-#endif /* any ed_case caller */
-
-
-/* UPCASE(c) - Return upper-case version of character */
-upcase(ch)
-int ch;
-{	register int c;
-	c = ch&0177;
-	return(islower(c) ? toupper(c) : c);
-}
-
Index: trunk/minix/commands/elle/eefidx.h
===================================================================
--- trunk/minix/commands/elle/eefidx.h	(revision 9)
+++ 	(revision )
@@ -1,241 +1,0 @@
-/* .H Function Index Definition file, generated by ELLEC */
-/* FN_ defines Function Numbers (indices) for all known functions */
-/* FX_ defines Function eXistence in this ELLE configuration */
-#define FN_INSSELF          1 /* Insert Self */
-#define FX_INSSELF          1
-#define FN_QUOTINS          2 /* Quoted Insert */
-#define FX_QUOTINS          2
-#define FN_CRLF             3 /* CRLF */
-#define FX_CRLF             3
-#define FN_FCHAR            4 /* Forward Character */
-#define FX_FCHAR            4
-#define FN_BCHAR            5 /* Backward Character */
-#define FX_BCHAR            5
-#define FN_DCHAR            6 /* Delete Character */
-#define FX_DCHAR            6
-#define FN_BDCHAR           7 /* Backward Delete Character */
-#define FX_BDCHAR           7
-#define FN_DELSPC           8 /* Delete Horizontal Space */
-#define FX_DELSPC           8
-#define FN_TCHARS           9 /* Transpose Characters */
-#define FX_TCHARS           9
-#define FN_FWORD           10 /* Forward Word */
-#define FX_FWORD           10
-#define FN_BWORD           11 /* Backward Word */
-#define FX_BWORD           11
-#define FN_KWORD           12 /* Kill Word */
-#define FX_KWORD           12
-#define FN_BKWORD          13 /* Backward Kill Word */
-#define FX_BKWORD          13
-#define FN_TWORDS          14 /* Transpose Words */
-#define FX_TWORDS          14
-#define FN_UCWORD          15 /* Uppercase Word */
-#define FX_UCWORD          15
-#define FN_LCWORD          16 /* Lowercase Word */
-#define FX_LCWORD          16
-#define FN_UCIWORD         17 /* Uppercase Initial */
-#define FX_UCIWORD         17
-#define FN_BEGLINE         20 /* Beginning of Line */
-#define FX_BEGLINE         20
-#define FN_ENDLINE         21 /* End of Line */
-#define FX_ENDLINE         21
-#define FN_NXTLINE         22 /* Next Line */
-#define FX_NXTLINE         22
-#define FN_PRVLINE         23 /* Previous Line */
-#define FX_PRVLINE         23
-#define FN_DNRLINE         24 /* Down Real Line */
-#define FX_DNRLINE         24
-#define FN_UPRLINE         25 /* Up Real Line */
-#define FX_UPRLINE         25
-#define FN_OLINE           26 /* Open Line */
-#define FX_OLINE           26
-#define FN_DELBLINES       27 /* Delete Blank Lines */
-#define FX_DELBLINES       27
-#define FN_KLINE           28 /* Kill Line */
-#define FX_KLINE           28
-#define FN_BKLINE          29 /* Backward Kill Line */
-#define FX_BKLINE          29
-#define FN_GOLINE          30 /* Goto Line */
-#define FX_GOLINE          30
-#define FN_SETMARK         35 /* Set/Pop Mark */
-#define FX_SETMARK         35
-#define FN_EXCHMARK        36 /* Exchange Point and Mark */
-#define FX_EXCHMARK        36
-#define FN_KREGION         37 /* Kill Region */
-#define FX_KREGION         37
-#define FN_COPREG          38 /* Copy Region */
-#define FX_COPREG          38
-#define FN_UCREG           39 /* Uppercase Region */
-#define FX_UCREG           39
-#define FN_LCREG           40 /* Lowercase Region */
-#define FX_LCREG           40
-#define FN_FILLREG         41 /* Fill Region */
-#define FX_FILLREG         41
-#define FN_FPARA           45 /* Forward Paragraph */
-#define FX_FPARA           45
-#define FN_BPARA           46 /* Backward Paragraph */
-#define FX_BPARA           46
-#define FN_MRKPARA         47 /* Mark Paragraph */
-#define FX_MRKPARA         47
-#define FN_FILLPARA        48 /* Fill Paragraph */
-#define FX_FILLPARA        48
-#define FN_SELBUFFER       50 /* Select Buffer */
-#define FX_SELBUFFER       50
-#define FN_SELXBUFFER      51 /* Select Existing Buffer */
-#define FX_SELXBUFFER      51
-#define FN_KBUFFER         52 /* Kill Buffer */
-#define FX_KBUFFER         52
-#define FN_LISTBUFS        53 /* List Buffers */
-#define FX_LISTBUFS        53
-#define FN_BUFNOTMOD       54 /* Buffer Not Modified */
-#define FX_BUFNOTMOD       54
-#define FN_EOLMODE         55 /* EOL CRLF Mode */
-#define FX_EOLMODE         55
-#define FN_GOBEG           56 /* Goto Beginning */
-#define FX_GOBEG           56
-#define FN_GOEND           57 /* Goto End */
-#define FX_GOEND           57
-#define FN_WHATPAGE        58 /* What Page */
-#define FX_WHATPAGE        58
-#define FN_FFILE           60 /* Find File */
-#define FX_FFILE           60
-#define FN_RFILE           61 /* Read File */
-#define FX_RFILE           61
-#define FN_VFILE           62 /* Visit File */
-#define FX_VFILE           62
-#define FN_IFILE           63 /* Insert File */
-#define FX_IFILE           63
-#define FN_SFILE           64 /* Save File */
-#define FX_SFILE           64
-#define FN_SAVEFILES       65 /* Save All Files */
-#define FX_SAVEFILES       65
-#define FN_WFILE           66 /* Write File */
-#define FX_WFILE           66
-#define FN_WREG            67 /* Write Region */
-#define FX_WREG            67
-#define FN_WLASTKILL       68 /* Write Last Kill */
-#define FX_WLASTKILL       68
-#define FN_2WINDS          70 /* Two Windows */
-#define FX_2WINDS          70
-#define FN_1WIND           71 /* One Window */
-#define FX_1WIND           71
-#define FN_OTHWIND         72 /* Other Window */
-#define FX_OTHWIND         72
-#define FN_GROWIND         73 /* Grow Window */
-#define FX_GROWIND         73
-#define FN_SHRINKWIND      74 /* Shrink Window */
-#define FX_SHRINKWIND      74
-#define FN_DELWIND         75 /* Delete Window */
-#define FX_DELWIND         75
-#define FN_SOWIND          76 /* Standout Window */
-#define FX_SOWIND          76
-#define FN_2MODEWINDS      77 /* Two Mode Windows */
-#define FX_2MODEWINDS      77
-#define FN_NEWWIN          78 /* New Window */
-#define FX_NEWWIN          78
-#define FN_NSCREEN         79 /* Next Screen */
-#define FX_NSCREEN         79
-#define FN_PSCREEN         80 /* Previous Screen */
-#define FX_PSCREEN         80
-#define FN_OTHNSCREEN      81 /* Other New Screen */
-#define FX_OTHNSCREEN       0
-#define FN_LWINDBORD       82 /* Line to Window Border */
-#define FX_LWINDBORD        0
-#define FN_SCUPWIND        83 /* Scroll Window Up */
-#define FX_SCUPWIND        83
-#define FN_SCDNWIND        84 /* Scroll Window Down */
-#define FX_SCDNWIND        84
-#define FN_MVWTOP          85 /* Move to Window Top */
-#define FX_MVWTOP          85
-#define FN_MVWBOT          86 /* Move to Window Bottom */
-#define FX_MVWBOT          86
-#define FN_SETPROF         90 /* Set Profile */
-#define FX_SETPROF         90
-#define FN_PFXMETA         91 /* Prefix Meta */
-#define FX_PFXMETA         91
-#define FN_PFXEXT          92 /* Prefix Extend */
-#define FX_PFXEXT          92
-#define FN_UARG            93 /* Universal Arg */
-#define FX_UARG            93
-#define FN_NEGARG          94 /* Negative Argument */
-#define FX_NEGARG          94
-#define FN_ARGDIG          95 /* Argument Digit */
-#define FX_ARGDIG          95
-#define FN_VTBUTTONS       96 /* VT100 Button Hack */
-#define FX_VTBUTTONS       96
-#define FN_DESCRIBE        97 /* Describe */
-#define FX_DESCRIBE        97
-#define FN_SKMAC          100 /* Start Kbd Macro */
-#define FX_SKMAC          100
-#define FN_EKMAC          101 /* End Kbd Macro */
-#define FX_EKMAC          101
-#define FN_XKMAC          102 /* Execute Kbd Macro */
-#define FX_XKMAC          102
-#define FN_VKMAC          103 /* View Kbd Macro */
-#define FX_VKMAC          103
-#define FN_UNKILL         105 /* Un-kill */
-#define FX_UNKILL         105
-#define FN_UNKPOP         106 /* Un-kill Pop */
-#define FX_UNKPOP         106
-#define FN_APPNKILL       107 /* Append Next Kill */
-#define FX_APPNKILL       107
-#define FN_SRCH           110 /* String Search */
-#define FX_SRCH           110
-#define FN_RSRCH          111 /* Reverse String Search */
-#define FX_RSRCH          111
-#define FN_ISRCH          112 /* Incremental Search */
-#define FX_ISRCH          112
-#define FN_RISRCH         113 /* Reverse Search */
-#define FX_RISRCH         113
-#define FN_REPSTR         114 /* Replace String */
-#define FX_REPSTR         114
-#define FN_QUEREP         115 /* Query Replace */
-#define FX_QUEREP         115
-#define FN_REPLINE        116 /* Replace in Line */
-#define FX_REPLINE        116
-#define FN_SFCOL          117 /* Set Fill Column */
-#define FX_SFCOL          117
-#define FN_SFPREF         118 /* Set Fill Prefix */
-#define FX_SFPREF         118
-#define FN_FILLMODE       119 /* Auto Fill Mode */
-#define FX_FILLMODE       119
-#define FN_TEXTMODE       120 /* Text Mode */
-#define FX_TEXTMODE         0
-#define FN_INDATM         121 /* Indent According to Mode */
-#define FX_INDATM         121
-#define FN_INDNL          122 /* Indent New Line */
-#define FX_INDNL          122
-#define FN_BACKIND        123 /* Back to Indentation */
-#define FX_BACKIND        123
-#define FN_INDCOMM        124 /* Indent for Comment */
-#define FX_INDCOMM        124
-#define FN_INDREL         125 /* Indent Relative */
-#define FX_INDREL         125
-#define FN_MATCHBRACK     129 /* Match Bracket */
-#define FX_MATCHBRACK       0
-#define FN_PSHINF         130 /* Push to Inferior */
-#define FX_PSHINF         130
-#define FN_RETSUP         131 /* Return to Superior */
-#define FX_RETSUP         131
-#define FN_WFEXIT         132 /* Write File Exit */
-#define FX_WFEXIT         132
-#define FN_BKPT           140 /* Hit Breakpoint */
-#define FX_BKPT           140
-#define FN_DEBUG          141 /* Debug Mode */
-#define FX_DEBUG          141
-#define FN_XUCMD          150 /* Execute Unix Command */
-#define FX_XUCMD            0
-#define FN_MAKE           151 /* Execute Make */
-#define FX_MAKE             0
-#define FN_NXTERR         152 /* Find Next Error */
-#define FX_NXTERR           0
-#define FN_ICOXCMD        153 /* ICO Extend Command */
-#define FX_ICOXCMD          0
-#define FN_ICOTYPFNS      154 /* ICO Typeset Funs */
-#define FX_ICOTYPFNS        0
-#define FN_ICOSPIFNS      155 /* ICO Spec Input Funs */
-#define FX_ICOSPIFNS        0
-#define FN_STUFFSEL       156 /* Stuff Selection */
-#define FX_STUFFSEL         0
-#define FN_SELREGION      157 /* Select Region */
-#define FX_SELREGION        0
Index: trunk/minix/commands/elle/eefile.c
===================================================================
--- trunk/minix/commands/elle/eefile.c	(revision 9)
+++ 	(revision )
@@ -1,834 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
-	 *	products without permission of the author.
- */
-/*
- * EEFILE	File reading/writing functions
- */
-
-#include "elle.h"
-#include <stdio.h>	/* Use "standard" I/O package for writing */
-#ifndef BUFSIZ
-#define BUFSIZ BUFSIZE	/* Some places use wrong name in stdio.h */
-#endif /*-BUFSIZ*/
-#if V6
-	struct stat {
-		int st_dev;
-		int st_ino;
-		char *st_mode;
-		char st_nlink;
-		char st_uid;
-		char st_gid;
-		char st_size0;
-		char st_size;
-		int st_addr[8];
-		long st_atime;
-		long st_mtime;
-	};
-#define ENOENT (2)	/* Syscall error - no such file or dir */
-#else
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#endif /*-V6*/
-
-#if TOPS20
-#include <sys/file.h>		/* Get open mode bits */
-#endif
-
-extern char *strerror();		/* Return error string for errno */
-extern struct buffer *make_buf(), *find_buf();
-
-char *fncons(), *last_fname();
-
-int hoardfd = -1;	/* Retain a FD here to ensure we can always write */
-
-/* Flags for iwritfile() */
-#define WF_SMASK 07	/* Source Mask */
-#define WF_SBUFF  0	/*   source: Buffer */
-#define WF_SREG   1	/*   source: Region */
-#define WF_SKILL 2	/*   source: Last Kill */
-#define WF_ASK 010	/* Ask for filename to write to */
-static int iwritfile();
-
-
-/* EFUN: "Find File" */
-/*	Ask user for a filename and do a find_file for it.
- *	If buffer exists for that filename, select that buffer.
- *	Else create a buffer for it, and read in the file if it exists.
- */
-f_ffile()
-{	int find_file();
-#if IMAGEN
-	hack_file("Visit file: ", find_file);
-#else
-	hack_file("Find file: ", find_file);
-#endif /*-IMAGEN*/
-}
-
-/* EFUN: "Read File" */
-/*	User read_file function, asks user for a filename and reads it
- */
-f_rfile() { u_r_file("Read file: "); }
-
-/* EFUN: "Visit File" */
-/*	Same as Read File, with different prompt.
- */
-f_vfile() { u_r_file("Visit file: "); }
-
-
-u_r_file(prompt)
-char *prompt;
-{	register char *f_name;
-	register struct buffer *b;
-
-	if((f_name = ask (prompt))==0)	/* prompt user for filename */
-		return;				/* user punted... */
-	b = cur_buf;
-	if(*f_name == '\0')
-	  {	if (b -> b_fn == 0)
-			ding("No default file name.");
-		else read_file(b -> b_fn);
-	  }
-	else read_file(f_name);
-	chkfree(f_name);
-}
-
-/* EFUN: "Insert File" */
-/*	Asks for a filename and inserts the file at current location.
- *	Point is left at beginning, and the mark at the end.
- */
-f_ifile()
-{	int ins_file();
-	hack_file("Insert file: ", ins_file);
-}
-
-
-/* EFUN: "Save File" */
-/*	Save current buffer to its default file name
- */
-f_sfile()
-{	if(cur_buf->b_flags&B_MODIFIED)
-		return(iwritfile(WF_SBUFF));	/* Write buffer, don't ask */
-	else
-	  {	saynow("(No changes need to be written)");
-		return(1);
-	  }
-}
-
-#if FX_SAVEFILES || FX_WFEXIT
-/* EFUN: "Save All Files" */
-/*  F_SAVEFILES - Offer to save all modified files.
- *	With argument, doesn't ask.
- *	Returns 0 if user aborts or if an error happened.
- */
-f_savefiles()
-{	register struct buffer *b, *savb;
-	register int res = 1;
-	char *ans;
-
-	savb = cur_buf;
-	for (b = buf_head; res && b; b = b->b_next)
-		if ((b->b_flags & B_MODIFIED) && b->b_fn)
-		  {	if(exp_p)		/* If arg, */
-			  {	chg_buf(b);	/* just save, don't ask */
-				res = f_sfile();
-				continue;	/* Check next buffer */
-			  }
-			/* Ask user whether to save */
-			ans = ask("Buffer %s contains changes - write out? ",
-					b->b_name);
-			if(ans == 0)
-			  {	res = 0;	/* User aborted */
-				break;
-			  }
-			if (upcase(*ans) == 'Y')
-			  {	chg_buf(b);
-				res = f_sfile();	/* Save File */
-			  }
-			chkfree(ans);
-		  }
-	chg_buf(savb);
-	return(res);
-}
-#endif /*FX_SAVEFILES||FX_WFEXIT*/
-
-
-/* EFUN: "Write File" */
-/*	Write out the buffer to an output file.
- */
-f_wfile()
-{	return iwritfile(WF_ASK|WF_SBUFF);
-}
-
-/* EFUN: "Write Region" */
-/*	Write region out to a file
- */
-f_wreg()
-{	return iwritfile(WF_ASK|WF_SREG);	/* Ask, write region */
-}
-
-#if FX_WLASTKILL
-/* EFUN: "Write Last Kill" (not EMACS) */
-/*	Write current kill buffer out to a file.
-**	This is mainly for MINIX.
-*/
-extern int kill_ptr;		/* From EEF3 */
-extern SBSTR *kill_ring[];
-
-f_wlastkill()
-{	return iwritfile(WF_ASK|WF_SKILL);
-}
-#endif
-
-
-
-/* HACK_FILE - intermediate subroutine
- */
-hack_file(prompt, rtn)
-char *prompt;
-int (*rtn)();
-{	register char *f_name;
-
-	if((f_name = ask(prompt)) == 0)
-		return;
-	if (*f_name != '\0')			/* Check for null answer */
-		(*rtn)(f_name);
-	chkfree(f_name);
-}
-
-/* FIND_FILE(f_name)
- *	If there is a buffer whose fn == f_name, select that buffer.
- *	Else create one with name of the last section of f_name and
- *	read the file into that buffer.
- */
-find_file(f_name)
-register char *f_name;
-{	register struct buffer *b;
-	register char *ans;
-	char *lastn;
-	int fd;
-
-#if IMAGEN
-	char real_name[128];		/* File name w/ expanded ~ and $ */
-	expand_file(real_name, f_name);
-	f_name = real_name;
-#endif /*IMAGEN*/
-
-	for (b = buf_head; b; b = b -> b_next)
-		if(b->b_fn && (strcmp (b -> b_fn, f_name) == 0))
-			break;
-	if (b)				/* if we found one */
-	  {	sel_buf(b);		/* go there */
-		return;			/* and we are done */
-	  }
-	if((fd = open(f_name,0)) < 0)	/* See if file exists */
-	  {	if(errno != ENOENT)	/* No, check reason */
-		  {	ferr_ropn();	/* Strange error, complain */
-			return;		/* and do nothing else. */
-		  }
-	  }
-	else close(fd);			/* Found!  Close FD, since the */
-					/* read_file rtn will re-open. */
-
-	lastn = last_fname(f_name);	/* Find buffer name */
-	b = find_buf(lastn);		/* Is there a buffer of that name? */
-	if (b && (ex_blen(b) || b->b_fn))
-	  {	ans = ask("Buffer %s contains %s, which buffer shall I use? ",
-    			b -> b_name, b->b_fn ? b->b_fn : "something");
-		if(ans == 0) return;		/* Aborted */
-		if (*ans != '\0')		/* if null answer, use b */
-			b = make_buf(ans);	/* else use ans */
-		chkfree(ans);
-	  }
-	else
-		b = make_buf(lastn);
-	sel_buf(b);
-	if(fd < 0)		/* If file doesn't exist, */
-	  {	set_fn(f_name);	/* just say "new" and set filename */
-		return;		/* and return right away. */
-	  }
-	if (read_file(f_name)==0)	/* File exists, read it in! */
-	  {	if(b->b_fn)		/* Failed... if filename, */
-		  {	chkfree(b->b_fn);	/* flush the filename. */
-			b->b_fn = 0;
-		  }
-	  }
-}
-
-/* READ_FILE(f_name)
- *	Reads file into current buffer, flushing any
- *	previous contents (if buffer modified, will ask about saving)
- *	Returns 0 if failed.
- */
-read_file(f_name)
-char *f_name;
-{
-#if IMAGEN
-	struct stat s;
-	char real_name[128];		/* File name w/ expanded ~ and $ */
-#endif /*IMAGEN*/
-
-	if(!zap_buffer())	/* Flush the whole buffer */
-		return;		/* Unless user aborts */
-#if IMAGEN
-	expand_file(real_name, f_name);
-	f_name = real_name;		/* Hack, hack! */
-#endif /*IMAGEN*/
-	set_fn(f_name);
-	if (ins_file(f_name)==0)
-		return 0;
-	f_bufnotmod();		/* Say not modified now */
-#if IMAGEN
-	stat(f_name, &s);		/* Get file stat */
-	cur_buf->b_mtime = s.st_mtime;	/*  and pick out last-modified time */
-#endif /*IMAGEN*/
-	return 1;
-}
-
-/* INS_FILE(f_name)
- *	Inserts file named f_name into current buffer at current point
- *	Point is not moved; mark is set to end of inserted stuff.
- *	Returns 0 if failed, 1 if won.
- */
-ins_file (f_name)
-char *f_name;
-{	register int ifd;
-	register SBSTR *sd;
-	chroff insdot;			/* To check for range of mods */
-
-#if IMAGEN
-	char real_name[128];		/* File name w/ expanded ~ and $ */
-	expand_file(real_name, f_name);
-	f_name = real_name;
-#endif /*IMAGEN*/
-#if !(TOPS20)
-	if((ifd = open(f_name,0)) < 0)
-#else
-	if((ifd = open(f_name,O_RDONLY|O_UNCONVERTED)) < 0)
-#endif /*TOPS20*/
-	  {	ferr_ropn();		/* Can't open, complain */
-		return 0;		/* no redisplay */
-	  }
-	errno = 0;
-	if((sd = sb_fduse(ifd)) == 0)
-	  {	if (ifd >= SB_NFILES)
-			dingtoo(" Cannot read - too many internal files");
-		else if (errno)
-			ferr_ropn();
-		else errbarf("SB rtn cannot read file?");
-		close(ifd);
-		return 0;
-	  }
-	sb_sins(cur_buf,sd);
-	insdot = e_dot();
-	f_setmark();			/* Set mark at current ptr */
-	if(cur_dot != insdot)		/* If pointer was advanced, */
-		buf_tmat(insdot);	/* then stuff was inserted */
-	e_gocur();
-	return 1;
-}
-
-ferr_ropn() { ferr(" Cannot read"); }
-ferr_wopn() { ferr(" Cannot write"); }
-ferr(str)
-char *str;
-{	saytoo(str);
-	saytoo(" - ");
-	dingtoo(strerror(errno));
-}
-
-
-
-/* IWRITFILE - auxiliary for writing files.
-**	Returns 1 if write successful, 0 if not.
-*/
-static int
-iwritfile(flags)
-int flags;
-{	register struct buffer *b;
-	register char *o_name;		/* output file name */
-	int styp = flags & WF_SMASK;	/* Source type, one of WF_Sxxx */
-	char *prompt;
-#ifdef STDWRITE
-	register FILE *o_file;		/* output file pointer */
-	char obuf[BUFSIZ];
-	chroff dotcnt;
-#endif /*STDWRITE*/
-	int ofd;			/* output file FD */
-	SBSTR *sd;
-	char fname[FNAMSIZ];		/* To avoid chkfree hassle */
-	char newname[FNAMSIZ];		/* for robustness */
-	char oldname[FNAMSIZ];		/* ditto */
-	int res;
-	struct stat statb;
-	int statres;
-#if IMAGEN
-	struct stat s;
-	char real_name[128];		/* File name w/ expanded ~ and $ */
-#endif /*IMAGEN*/
-	res = 1;			/* Let's keep track of success */
-
-	/* Check for existence of source, and set prompt string */
-	switch(styp)
-	  {
-		case WF_SBUFF:
-			prompt = "Write File: ";
-			break;
-		case WF_SREG:
-			if(!mark_p)
-			  {	dingtoo(" No Mark!");
-				return(0);
-			  }
-			prompt = "Write Region: ";
-			break;
-#if FX_WLASTKILL
-		case WF_SKILL:
-			if(!kill_ring[kill_ptr])
-			  {	dingtoo("No killed stuff");
-				return(0);
-			  }
-			prompt = "Write Last Kill: ";
-			break;
-#endif
-		default:			/* Internal error */
-			errbarf("bad iwritfile arg");
-			return 0;
-	  }
-
-	if (flags&WF_ASK)
-	  {	if((o_name = ask(prompt))==0)
-			return(0);		/* User punted. */
-		strcpy(&fname[0], o_name);	/* Copy filename onto stack */
-		chkfree(o_name);
-	  }
-	o_name = &fname[0];
-	b = cur_buf;
-	if (!(flags&WF_ASK) || (*o_name == '\0'))
-	  {	if (b->b_fn == 0)
-		  {	ding("No default file name.");
-			return(0);
-		  }
-		strcpy(o_name, b->b_fn);
-	  }
-
-#if IMAGEN
-	expand_file(real_name, o_name);
-	o_name = real_name;		/* Hack, hack */
-#endif /*IMAGEN*/
-
-	statres = stat(o_name,&statb);	/* Get old file's info (if any) */
-
-#if IMAGEN
-	/* Now, make sure someone hasn't written the file behind our backs */
-	if ((styp==WF_SBUFF) && !(flags&WF_ASK)
-	  && b->b_fn && stat(b->b_fn, &s) >= 0)
-		if (s.st_mtime != b->b_mtime)
-		  {	char *ans;
-			ans = ask("Since you last read \"%s\", someone has changed it.\nDo you want to write it anyway (NOT RECOMMENDED!)? ",
-				   b->b_fn);
-			if (ans == 0 || upcase(*ans) != 'Y')
-			  {
-				ding("I suggest you either read it again, or\nwrite it to a temporary file, and merge the two versions manually.");
-				if (ans) chkfree(ans);
-				return(0);
-			  }
-			if (ans) chkfree(ans);
-		  }
-#endif /*IMAGEN*/
-
-  /* Try to get around major UNIX screw of smashing files.
-   * This still isn't perfect (screws up with long filenames) but...
-   * 1. Write out to <newname>
-   * 2. Rename <name> to <oldname> (may have to delete existing <oldname>)
-   * 3. Rename <newname> to <name>.
-   */
-	fncons(oldname,ev_fno1,o_name,ev_fno2);	/* Set up "old" filename */
-	fncons(newname,ev_fnn1,o_name,ev_fnn2);	/* Set up "new" filename */
-	unlink(newname);			/* Ensure we don't clobber */
-	unhoard();				/* Now give up saved FD */
-#if !(V6)	/* Standard V6 doesn't have access call */
-	if(statres >= 0)			/* If file exists, */
-	  {	if(access(o_name, 2) != 0)	/* check for write access */
-		  {	ferr_wopn();
-			res = 0;	/* Failure */
-			goto wdone;
-		  }
-	  }
-#endif /*-V6*/
-#ifdef STDWRITE
-	if(flags&WF_ASK)
-	  {	if((o_file = fopen(newname, "w")) ==0)	/* Create new output file */
-		  {	ferr_wopn();
-			res = 0;		/* Failure */
-			goto wdone;
-		  }
-		setbuf(o_file,obuf);	/* Ensure always have buffer */
-	  }
-	else	/* New stuff */
-#endif /*STDWRITE*/
-	  {
-#if !(TOPS20)
-		if((ofd = creat(newname,ev_filmod)) < 0)
-#else
-		if((ofd = open(newname,O_WRONLY|O_UNCONVERTED)) < 0)
-#endif /*TOPS20*/
-		  {	ferr_wopn();
-			res = 0;		/* Failure */
-			goto wdone;
-		  }
-	  }
-	if (styp==WF_SBUFF)
-		set_fn(o_name);		/* Won, so set default fn for buff */
-#if IMAGEN
-	saynow("Writing ");
-	switch(styp)
-	  {	case WF_SBUFF:	saytoo(b->b_fn); break;
-		case WF_SREG:	saytoo("region"); break;
-#if FX_WLASTKILL
-		case WF_SKILL:	saytoo("last kill"); break;
-#endif
-	  }
-	sayntoo("...");
-#else
-	saynow("Writing...");
-#endif /*-IMAGEN*/
-
-#if !(TOPS20)			/* T20 does all this already */
-	if(statres >= 0)		/* Get old file's modes */
-	  {				/* Try to duplicate them */
-		/* Do chmod first since after changing owner we may not
-		** have permission to change mode, at least on V6.
-		*/
-		chmod(newname,statb.st_mode & 07777);
-#if V6
-		chown(newname, (statb.st_gid<<8)|(statb.st_uid&0377));
-#else
-		chown(newname,statb.st_uid,statb.st_gid);
-#endif /*-V6*/
-	  }
-#if V6
-	/* If no old file existed, and we are a V6 system, try to set
-	 * the modes explicitly.  On V7 we're OK because the user can
-	 * diddle "umask" to get whatever is desired.
-	 * On TOPS-20 of course everything is all peachy.
-	 */
-	else chmod(newname, ev_filmod);
-#endif /*V6*/
-#endif /*TOPS20*/
-
-
-#ifdef STDWRITE
-	if(flags&WF_ASK)
-	  {	switch(styp)
-		  {
-			case WF_SBUFF:
-				dotcnt = e_blen();
-				e_gobob();
-				break;
-			case WF_SREG:
-				if((dotcnt = mark_dot - cur_dot) < 0)
-				  {	e_goff(dotcnt);
-					dotcnt = -dotcnt;
-				  }
-				else e_gocur();
-				break;
-			/* WF_SKILL not implemented here */
-		  }
-		while(--dotcnt >= 0)
-			putc(sb_getc(((SBBUF *)b)), o_file);
-		e_gocur();
-		fflush(o_file);			/* Force everything out */
-		res = ferror(o_file);		/* Save result of stuff */
-		fclose(o_file);			/* Now flush FD */
-	  }
-	else	/* New stuff */
-#endif /*STDWRITE*/
-	  {
-		switch(styp)
-		  {
-			case WF_SBUFF:
-				res = sb_fsave((SBBUF *)b, ofd);
-				break;
-			case WF_SREG:
-				e_gocur();
-				sd = e_copyn((chroff)(mark_dot - cur_dot));
-				res = sbx_aout(sd, 2, ofd);
-				sbs_del(sd);
-				break;
-#if FX_WLASTKILL
-			case WF_SKILL:
-				res = sbx_aout(kill_ring[kill_ptr], 2, ofd);
-				break;
-#endif
-		  }
-		close(ofd);
-	  }
-	if(errno = res)
-	  {	ferr(" Output error");
-		res = 0;		/* Failure */
-		goto wdone;
-	  }
-	else
-		res = 1;		/* Success so far */
-	if(styp == WF_SBUFF)
-		f_bufnotmod();		/* Reset "buffer modified" flag */
-
-	/* Here we effect the screw-prevention steps explained earlier. */
-	/* TOPS-20, with generation numbers, need not worry about this. */
-#if TOPS20
-	saynow("Written");
-
-#else /*-TOPS20*/
-#if IMAGEN	/* KLH -- This conditional bracketting is prone to lossage */
-	/* Only create the .BAK file once per editing session!! */
-	if ((styp==WF_SBUFF) || !(b->b_flags & B_BACKEDUP))
-	  {	if (styp==WF_SBUFF)
-			b->b_flags |= B_BACKEDUP;
-#endif /*IMAGEN*/
-	unlink(oldname);	/* remove any existing "old" file */
-	if(link(o_name,oldname) == 0)	/* Rename current to "old" */
-	 	unlink(o_name);
-		/* Here is the critical point... if we stop here, there is no
-		 * longer any file with the appropriate filename!!!
-		 */
-#if IMAGEN
-	  }
-	else
-		unlink(o_name);
-#endif /*IMAGEN*/
-	if(link(newname,o_name) == 0)	/* Rename "new" to current */
-	  {	unlink(newname);
-#if IMAGEN
-		sayntoo("OK");
-#else
-		saynow("Written");
-#endif /*-IMAGEN*/
-	  }
-	else
-	  {	dingtoo("rename error!");
-		res = 0;
-	  }
-#endif /*-TOPS20*/
-
-#if IMAGEN
-	/* Update the last-modified time for the file in this buffer */
-	if ((styp == WF_SBUFF) && b->b_fn)
-	  {	stat(b->b_fn, &s);
-		b->b_mtime = s.st_mtime;
-	  }
-#endif /*IMAGEN*/
-
-wdone:
-	hoard();			/* Get back a retained FD */
-	return(res);
-}
-
-
-/* FNCONS(dest,pre,f_name,post)
- *	Specialized routine to cons up a filename string into "dest",
- *	given prefix and postfix strings to be added onto last component of
- *	filename.
- */
-char *
-fncons(dest, pre, f_name, post)
-char *dest,*pre,*f_name,*post;
-{	register char *cp, *cp2;
-	char *last_fname();
-
-	cp = dest;
-	*cp = 0;			/* Make dest string null initially */
-	cp2 = last_fname(f_name);	/* Get pointer to beg of last name */
-	strncat(cp,f_name,cp2-f_name);	/* Copy first part of filename */
-	if(pre)	strcat(cp, pre);	/* If prefix exists, add it on */
-	cp = last_fname(cp);		/* Recheck in case levels added */
-	strcat(cp, cp2);		/* Now add last name */
-	if(cp2 = post)			/* If there's a postfix, must check */
-	  {	cp[FNAMELEN-strlen(cp2)] = 0;	/* and cut dest so postfix */
-		strcat(cp, cp2);		/* will fit on end. */
-	  }
-	return(dest);
-}
-
-/* LAST_FNAME(string)
- *	Get the last component of a file name.  Returns pointer to
- *	start of component; does NOT copy string!
- */
-char *
-last_fname(f_name)
-char *f_name;
-{	register char *cp, *p;
-	register int c;
-
-	p = f_name;		/* pointer to last slash */
-	cp = p;
-	while(c = *cp++)
-		if(c == '/')
-			p = cp;		/* point to after the slash */
-	return(p);
-}
-
-/* SET_FN(string)
- *	Set the default filename for current buffer to "string".
- */
-set_fn (string)
-char *string;
-{	register struct buffer *b;
-	register char *str;
-#if IMAGEN
-	register char *cp;
-	register int len;
-#endif /*IMAGEN*/
-	char *strdup();
-
-	b = cur_buf;
-	str = strdup(string);		/* Copy now in case copying self */
-	if(b->b_fn)
-		chkfree(b->b_fn);
-	b -> b_fn = str;
-#if IMAGEN
-	/* Do mode determination based on file name (HACK HACK) */
-	len = strlen(str);
-	b->b_flags &= ~(B_CMODE|B_TEXTMODE);
-	if (len > 4)
-	  {	if (strcmp(&str[len - 5], "draft") == 0)
-			b->b_flags |= B_TEXTMODE;
-		else
-		  {	cp = &str[len - 4];
-			if (strcmp(cp, ".txt") == 0 ||
-			    strcmp(cp, ".mss") == 0)
-				b->b_flags |= B_TEXTMODE;
-		  }
-	  }
-	if (len > 2)
-	  {	cp = &str[len - 2];
-		if (strcmp(cp, ".h") == 0 || strcmp(cp, ".c") == 0)
-			b->b_flags |= B_CMODE;
-	  }
-#endif /*IMAGEN*/
-	redp(RD_MODE);
-}
-
-
-/* SAVEWORLD - Attempt to save all changes user has made.
- *	Currently this amounts to writing out all modified buffers
- *	to the files $HOME/+buffername.  If a buffer is given as argument,
- *	only that buffer is saved.
- *	This is only called from the error handling routines with
- *	the TTY either gone or in normal (non-edit) mode.  The "grunt"
- *	flag says whether to output feedback during the saving process.
- */
-saveworld(bp, grunt)
-struct buffer *bp;
-int grunt;
-{	register struct buffer *b;
-	register int wfd;
-	char sfname[FNAMSIZ];
-	struct buffer *sel_mbuf();
-
-	unhoard();		/* Ensure a FD is free for writing */
-	if(b = bp) goto once;
-	while(!bp && (b = sel_mbuf(b)))
-	  {
-	once:	strcat(strcat(strcpy(sfname,homedir),"/+"),b->b_name);
-		if(grunt) printf("Saving %s...",sfname);
-#if !(TOPS20)
-		if((wfd = creat(sfname, ev_filmod)) < 0)
-#else
-		if((wfd = open(sfname,O_WRONLY|O_UNCONVERTED)) < 0)
-#endif /*TOPS20*/
-		  {	if(grunt)
-				printf(" error - %s\n", strerror(errno));
-		  }
-		else
-		  {	sb_fsave((SBBUF *)b, wfd);
-			close(wfd);
-			if(grunt) printf("\n");
-		  }
-		b->b_flags &= ~B_MODIFIED;
-	  }
-	hoard();
-}
-
-/* HOARD, UNHOARD - Routines to save a FD for writing, to make sure
- *	that we can always write out a buffer no matter how many
- *	file descriptors we are currently using.
- */
-hoard()			/* Stash away a FD */
-{	if(hoardfd <= 0)
-#if !(TOPS20)
-		hoardfd = open("nul:", 1);
-#else
-		hoardfd = open("/dev/null", 1);
-#endif
-}
-unhoard()		/* Give up our stashed FD so it can be re-used */
-{	close(hoardfd);
-	hoardfd = -1;
-}
-
-
-#if IMAGEN
-#include <pwd.h>
-#include <ctype.h>
-
-/*
- * expand_file: expand any ~user-name/ or $env-var/ prefixes in sfn,
- * producing the full name in dfn
- */
-expand_file(dfn, sfn)
-register char *dfn, *sfn;
-{
-	register char *sp, *tp;
-	register int c;
-	register struct passwd *pw;
-	char ts[128];
-
-	/* HORRIBLE, GROSS, DISGUSTING HACK: if the destination and
-	 * source strings are identical (same pointer), then do not
-	 * do any expansion--this happens to work with the current
-	 * structure very well, since multiple expansions may happen.
-	 */
-	if (dfn == sfn)
-		return;
-
-	ts[0] = 0;
-
-	/* If have a leading $, then expand environment variable */
-	if (*sfn == '$')
-	  {	++sfn;
-		tp = ts;
-		while (*tp++ = *sfn)
-			if (!isalnum(*sfn))
-				break;
-			else
-				++sfn;
-		*--tp = 0;		/* Just in case */
-		strcpy(ts, getenv(ts));	/* MARGINAL!! */
-	  }
-	/* If have leading ~, then expand login name (null means $HOME) */
-	else if (*sfn == '~')
-	  {	++sfn;
-		if (*sfn == '/' || *sfn == 0)
-			strcpy(ts, getenv("HOME"));
-		else
-		  {	tp = ts;
-			while (*sfn && *sfn != '/')
-				*tp++ = *sfn++;
-			*tp = 0;
-			pw = (struct passwd *)getpwnam(ts);
-			if (! pw)
-				strcpy(ts, "???");
-			else
-				strcpy(ts, pw->pw_dir);
-		  }
-	  }
-
-	/* Now, ts is either empty or contains the expansion;
-	 * sfn has been updated correctly.
-	 */
-	strcpy(dfn, ts);
-	strcat(dfn, sfn);
-}
-#endif /*IMAGEN*/
Index: trunk/minix/commands/elle/eefill.c
===================================================================
--- trunk/minix/commands/elle/eefill.c	(revision 9)
+++ 	(revision )
@@ -1,648 +1,0 @@
-/* ELLE - Copyright 1982, 1985, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * EEFILL	Fill Mode functions
- */
-
-#include "elle.h"
-
-extern int ev_fcolumn;	/* Fill Column variable (defined in EEVINI) */
-#if FX_SFPREF
-char *fill_prefix;	/* Fill Prefix variable */
-int fill_plen;		/* Length of Fill Prefix (0 = no prefix) */
-#endif /*FX_SFPREF*/
-
-#if FX_FILLMODE
-int fill_mode = 0;	/* TRUE when Auto Fill Mode is on */
-int *fill_trig;		/* Pointer to fill-trigger chbit array */
-static char *fill_initrig = " \t.,;:)!";
-#endif /*FX_FILLMODE*/
-
-/* Following stuff for testing routines on */
-/*
-
-          1         2         3         4         5	    6         7
-0123456789012345678901234567890123456789012345678901234567890123456789012345
-
-Okay...  more stuff to hack.  Okay.  a b c d e f g h i j k l m
-n o p q r s t u v w x y z dfsd stuff to hack 01234 Okay testing
-more stuff to hack.  Okay...  more stuff to hack more stuff to
-hack.  Okay...  more stuff to line long stuff to hack.  Okay...
-even more gap and.  period.  okay, end of stuff.
-	This is another fence.
-*/
-
-
-
-#if FX_SFCOL
-/* EFUN: "Set Fill Column" */
-f_sfcol()
-{	register int linel;
-	char temp[20];
-
-	linel = exp_p ? exp : d_curind();
-	if(linel < 0) linel = 0;
-	say("Fill column = ");
-	dottoa(temp,(chroff)linel);
-	saytoo(temp);
-	ev_fcolumn = linel;
-}
-#endif /*FX_SFCOL*/
-
-
-#if FX_SFPREF
-/* EFUN: "Set Fill Prefix" */
-f_sfpref()
-{	register int i;
-	register char *cp;
-
-	if((i = cur_dot - e_boldot()) > MAXLINE)
-	  {	ding("Absurd Fill Prefix");
-		return;
-	  }
-	if(fill_prefix)
-	  {	chkfree(fill_prefix);
-		fill_plen = 0;
-	  }
-	if(i <= 0)
-	  {	fill_prefix = 0;
-		cp = "";
-	  }
-	else
-	  {	fill_prefix = cp = memalloc((SBMO)(i+1));
-		fill_plen = i;
-		e_gobol();
-		do { *cp++ = e_getc(); }
-		while(--i);
-		*cp = 0;
-		cp = fill_prefix;
-	  }
-	say("Fill Prefix = \"");
-	saytoo(cp);
-	saytoo("\"");
-}
-
-
-/* TSTFILLP(lim) - Check for existence of Fill Prefix at current dot.  If
- *	not there, returns 0 without changing dot.  If there, returns
- *	1 and leaves dot immediately after the Fill Prefix.
- *	Lim = # of chars allowed to scan from buffer.
- */
-tstfillp(lim)
-int lim;
-{	register int i, c;
-	register char *cp;
-	chroff savdot;
-
-	if(!(i = fill_plen) || (i > lim))
-		return(0);
-	savdot = e_dot();
-	cp = fill_prefix;
-	do {	if(*cp++ != e_getc())
-		  {	e_go(savdot);
-			return(0);
-		  }
-	  } while(--i);
-	return(1);
-}
-#endif /*FX_SFPREF*/
-
-
-#if FX_FILLREG || FX_FILLPARA
-
-/* ED_FILL(start, end, flag) - Fill a region.
- *	Flag	0 for full filling; extra whitespace is flushed.  First
- *			word is always retained.
- *		1 for skimpy filling such as Auto-Fill likes.
- *			Extra whitespace is NOT flushed, except at
- *			beginning of a newly created line.
- *			This is not yet implemented however.
- * Note: updates cur_dot to compensate for changes in buffer, and returns
- *	there when done!
- * Note: Checks for Fill Prefix when it exists.
- */
-ed_fill(begloc, endloc, flag)
-chroff begloc, endloc;
-int flag;
-{	register int c;
-	register int len, lastc;
-	chroff savloc;
-	int lastbrk;
-	int parlen;
-
-	parlen = endloc - begloc;
-	if(parlen < 0)
-	  {	begloc = endloc;
-		parlen = -parlen;
-	  }
-	e_go(begloc);
-	len = d_curind();		/* Set up current col */
-
-#if FX_SFPREF
-	/* If at beg of line, check for fill prefix and skip over it */
-	if((len == 0) && tstfillp(parlen))
-	  {	parlen -= fill_plen;
-		len = d_curind();
-	  }
-#endif /*FX_SFPREF*/
-	lastbrk = 0;			/* Put next word on no matter what. */
-	c = 0;
-	for(;;)
-	  {
-#if ICONOGRAPHICS
-             if (c != ')' && c != '"')  /* allow for two sp after .) or ." */
-#endif /*ICONOGRAPHICS*/
-		lastc = c;
-		if(--parlen < 0) break;
-		c = e_getc();
-		if(c == EOF)
-			break;
-#if FX_SFPREF
-		/* If at beg of line, check for fill prefix and flush it */
-		if((c == LF) && tstfillp(parlen))
-		  {	e_igoff(-(fill_plen+1));
-			e_ovwc(c = SP);
-			e_deln((chroff)fill_plen);
-			parlen -= fill_plen;
-			if(cur_dot >= e_dot())
-				cur_dot -= fill_plen;
-		  }
-#endif /*FX_SFPREF*/
-		if(c == TAB || c == LF)		/* Replace tabs+eols by sps */
-		  {	e_backc();		/* Back up 1 */
-			e_ovwc(c = SP);
-		  }
-		if(c == SP)
-		  {	if(lastc == SP)
-			  {	e_rdelc();
-				if(cur_dot > e_dot()) --cur_dot;
-				continue;
-			  }
-			lastbrk = len;
-			if(lastc == '.' || lastc == '!' || lastc == '?'
-#if ICONOGRAPHICS
-                                                        || lastc == ':'
-#endif /*ICONOGRAPHICS*/
-									)
-			  {	if(--parlen < 0) goto done;
-				if((c = e_getc()) == EOF)
-					goto done;
-				len++;
-				if(c != SP)
-				  {	e_backc();
-					e_putc(c = SP);
-					if(cur_dot >= e_dot()) ++cur_dot;
-				  }
-			  }
-		  }
-#if ICONOGRAPHICS
-		if (c == BS)                    /* adjust for backspaces */
-			if ((len -= 2) < 0) len = 0;
-#endif /*ICONOGRAPHICS*/
-		/* Normal char */
-		if(++len > ev_fcolumn && lastbrk)	/* If went too far */
-		  {	c = lastbrk - len;	/* Must put EOL at last SP */
-			e_igoff(c);
-			parlen -= c;	/* C is negative, actually adding */
-			parlen--;
-			e_ovwc(LF);
-			lastbrk = 0;
-			len = 0;
-			c = SP;		/* Pretend this char was space */
-#if FX_SFPREF
-			if(fill_plen)
-			  {	if(cur_dot >= e_dot())
-					cur_dot += fill_plen;
-				/* Better hope no nulls in prefix! */
-				e_sputz(fill_prefix);
-				len = d_curind();
-			  }
-#endif /*FX_SFPREF*/
-		  }
-	  }
-done:	savloc = cur_dot;
-	e_setcur();	/* Reached paragraph end, set cur_dot temporarily */
-	buf_tmod(begloc-cur_dot);	/* So that proper range is marked */
-	e_gosetcur(savloc);		/* Then restore original cur_dot */
-}
-#endif /*FX_FILLREG || FX_FILLPARA*/
-
-
-#if FX_FILLMODE
-
-/* EFUN: "Auto Fill Mode" */
-/*	Toggles Auto Fill Mode (a minor mode). */
-f_fillmode()
-{	register char *cp;
-	int *chballoc();
-
-	fill_mode = fill_mode ? 0 : 1;
-	if(!fill_trig)
-	  {	fill_trig = chballoc(128);
-		for(cp = fill_initrig; *cp; ++cp)
-			chbis(fill_trig, *cp);
-	  }
-	redp(RD_MODE);
-}
-
-/* Called by F_INSSELF to handle char insertion in Auto Fill mode */
-fx_insfill(c)
-int c;
-{
-	ed_insn(c,exp);
-	if(chbit(fill_trig, c))
-	  {	fill_cur_line();
-
-	  }
-}
-
-
-fill_cur_line()
-{
-	register int foundit, i;
-	chroff lastbrkdot, boldot, eoldot;
-
-	boldot = e_boldot();
-
-	/* First back up to find place to make first break. */
-	e_bwsp();
-	lastbrkdot = e_dot();
-	foundit = 0;
-	for(foundit = 0; foundit >= 0;)
-	  {	if((i = d_curind()) <= ev_fcolumn)
-		  {	if(foundit)
-				foundit = -1;
-			else break;
-		  }
-		else ++foundit;
-		while (!c_wsp (e_rgetc ())) ;
-		e_bwsp();
-		lastbrkdot = e_dot();
-		if(lastbrkdot <= boldot)
-		  {	lastbrkdot = boldot;
-			break;
-		  }
-	  }
-
-	if(foundit)
-		ed_fill(lastbrkdot, e_eoldot(), 1);
-}
-#endif /*FX_FILLMODE*/
-
-
-#if IMAGEN
-
-#if FX_TEXTMODE
-/* EFUN: "Text Mode Toggle" (not EMACS) */
-f_textmode()
-{
-	cur_buf->b_flags ^= B_TEXTMODE;
-	redp(RD_MODE);
-}
-#endif /*FX_TEXTMODE*/
-
-int curr_indent = -1;		/* Current indent (for text mode autowrap) */
-				/*  (misnomered: actually current column) */
-chroff best_break;		/* Best break point so far */
-
-
-/* Fill-mode version of "Insert Self" */
-
-fim_insself(c)
-int c;
-{
-	register int ind, flags = cur_buf->b_flags;
-
-	/* In Text mode, auto-wrap happens at spaces after fill column */
-	if (c == SP && flags & B_TEXTMODE && exp == 1 && magic_wrap(c))
-		return;
-
-	/* In C-mode, tab stops are every 4 columns */
-	else if (c == TAB && flags & B_CMODE &&
-			(ind = magic_backto_bol()) >= 0)
-		ed_indto((ind + 4) & ~3);
-	else
-	  {	ed_insn(c, exp);
-
-		/* Keep track of indent, once we have a grip on it */
-		if (last_cmd == INSCMD && curr_indent != -1)
-		  {	this_cmd = INSCMD;  /* Keep the ball rolling */
-			if (c == TAB)
-				curr_indent = ((curr_indent + 8) & ~7)
-						 + 8 * (exp - 1);
-			else if (c == '\n')
-				curr_indent = 0;
-			else if (c < SP || c > 0176)
-				curr_indent += (2 * exp);
-			else
-				curr_indent += exp;
-		  }
-	  }
-}
-
-/* Fill-mode version of "Delete Character" */
-
-fim_dchar()
-{	/* In C mode, deleting at BOL should do fake TAB preservation */
-	if (cur_buf->b_flags & B_CMODE)
-	  {	chroff savdot;
-		register int c, indent;
-
-		if (e_rgetc() != LF)
-		  {	/* Only hack this at BOL */
-			e_getc();
-			goto normal;
-	    	  }
-		e_getc();
-		savdot = e_dot();
-		indent = 0;
-		while ((c = e_getc()) == SP || c == TAB)
-			if (c == SP)
-				++indent;
-		else
-			indent = (indent + 8) & ~7;
-		e_rgetc();
-		if (indent >= 4)
-		  {	ed_delete(savdot, e_dot());
-			ed_indto((indent - 4) & ~3);
-			f_begline();		/* HACK!!!! */
-		  }
-		else
-		  {	e_go(savdot);
-			ef_deln(exp);
-		  }
-	  }
-	else
- normal:	return (ef_deln(exp));
-}
-
-/* Fill-mode version of "Backward Delete Character" */
-
-fim_bdchar()
-{	register int ind;
-
-	/* If in C mode, and deleting into white space at BOL, hack tabs */
-	if (exp == 1 && cur_buf->b_flags & B_CMODE &&
-			(ind = magic_backto_bol()) > 0)
-		ed_indto(ind < 4 ? ind - 1 : ((ind - 4) & ~3));
-	else
-		return (ef_deln (-exp));
-}
-
-/* Fill-mode version of "CRLF" */
-fim_crlf()
-{	register int i;
-
-	if(e_getc() == LF
-	  && exp == 1
-	  && e_lblankp() && e_lblankp())
-	  {	e_gocur();
-		e_gonl();
-		e_setcur();
-		ed_delete(e_dot(), e_eoldot());
-	  }
-	else
-	  {	e_gocur();
-#if IMAGEN
-		if (cur_buf->b_flags & B_TEXTMODE && exp == 1 &&
-		    magic_wrap('\n'))
-			return;
-		else
-#endif /*IMAGEN*/
-		if((i = exp) > 0)
-			do ed_crins();
-			while(--i);
-	  }
-}
-
-
-/* Do all magic for auto-wrap in Text mode:
- * return as did wrap (i.e., everything is taken care of)
- */
-magic_wrap(tc)
-int tc;				/* "trigger char" */
-{
-	register int c, indent, i, nc;
-	chroff savdot, modstart, breakdot;
-    
-	savdot = e_dot();
-	nc = 0;
-	if (last_cmd == INSCMD && curr_indent != -1)
-	  {	indent = curr_indent;		/* Already know our indent */
-		breakdot = best_break;
-	  }
-	else
-	  {
-#ifdef INDENTDEBUG
-		barf2("Full indent calculation");
-#endif
-		for (nc = 0; (c = e_rgetc()) != EOF && c != '\n'; ++nc)
-		    ;				/* nc: # chars to look at */
-		if (c == '\n')			/* Go back over NL */
-			e_getc();
-		indent = 0;
-    
-		/* Search for last line break point, leaving it in breakdot */
-		breakdot = (chroff)0;
-		while (--nc >= 0)
-		  {	c = e_getc();
-			if (c == TAB)
-				indent = (indent + 8) & ~7;
-			else if (c < SP || c > 0176)
-				indent += 2;
-			else
-				++indent;
-			if ((c == SP || c == TAB) &&
-			  (breakdot == (chroff)0 || (indent <= ev_fcolumn)))
-				breakdot = e_dot();
-		  }
-	  }
-
-    /* If there is nothing to do, get out */
-	if (indent <= ev_fcolumn)
-	  {	e_go(savdot);
-		if (tc == SP)
-		  {	curr_indent = indent;
-			best_break = (chroff)(savdot + 1); /* Remember here, also */
-			this_cmd = INSCMD;		/* We do know current indent */
-		  }
-		else if (tc == '\n')
-		  {	curr_indent = 0;
-			best_break = (chroff)0;
-			this_cmd = INSCMD;
-		  }
-		else
-			errbarf("bad trigger");
-		return(0);
-	  }
-
-	if (breakdot == (chroff)0)
-	  {
-	/* No breakpoint found or none needed, just break line at end
-	 */
-		e_go(savdot);
-		modstart = savdot;
-		e_putc('\n');
-	  }
-	else
-	  {
-	/* Get to breakpoint and replace with newline
-	 */
-		e_go(breakdot);
-		e_rdelc();
-		modstart = e_dot();		/* Remember where changes start */
-		e_putc('\n');			/* Insert line break */
-		e_go(savdot);			/* Get back to trigger point */
-	  }
-	if (e_rgetc() != '\n')
-	  {		/* If not at line start, */
-		e_getc();
-		e_putc(tc);			/*  insert trigger character */
-
-	/* Once again, compute new indent by backing up to BOL */
-		for (nc = 0; (c = e_rgetc()) != EOF && c != '\n'; ++nc)
-			;
-		if (c == '\n')			/* Go back over NL */
-			e_getc();
-		indent = 0;
-		breakdot = (chroff)0;
-		while (--nc >= 0)
-		  {		/* Get back to current dot */
-			c = e_getc();
-			if (c == TAB)
-				indent = (indent + 8) & ~7;
-			else if (c < SP || c > 0176)
-				indent += 2;
-			else
-				++indent;
-			if ((c == SP || c == TAB) &&
-			  (breakdot == (chroff)0 || (indent <= ev_fcolumn)))
-				breakdot = e_dot();
-		  }
-		if (breakdot == (chroff)0)	/* If no good break found, use dot */
-			breakdot = e_dot();
-		curr_indent = indent;		/* Now we know where we are */
-		if (tc == '\n')			/* If trigger was NL */
-			best_break = (chroff)0;	/*  indent is 0, and no best break */
-		else
-			best_break = breakdot;	/* This is best break so far */
-	  }
-	else
-	  {	e_getc();
-		curr_indent = 0;		/* At line start, no indent */
-		best_break = (chroff)0;		/* Do not have a best break so far */
-	  }
-	ed_setcur();
-	buf_tmat(modstart);			/* Alert to potential changes */
-	this_cmd = INSCMD;			/* Say we know where we are */
-	return(1);
-}
-
-/* Do lots of magic things for C-mode indent:
- * erase back to BOL iff we are looking back at white space only,
- * returning the indent level of the original dot
- * (< 0 means no erasure done)
- */
-/*#define MYDEBUG /* */
-#ifdef MYDEBUG
-reveal(msg, v1, v2, v3)
-char *msg;
-{
-	char ahint[128];
-	sprintf(ahint, msg, v1, v2, v3);
-	barf2(ahint);
-}
-#endif
-
-magic_backto_bol()
-{
-	chroff savdot;
-	register int c, indent, nc, i;
-
-	savdot = e_dot();
-        nc = 0;
-	while ((c = e_rgetc()) != EOF && c != LF)
-	  {	++nc;			/* Count # chars */
-		if (c != SP && c != TAB)
-		  {	e_go(savdot);
-#ifdef MYDEBUG
-			reveal("fail: nc: %d", nc);
-#endif
-			return -1;
-        	  }
-    	  }
-	if (c == LF)			/* Go back over the LF */
-		e_getc();
-    	indent = 0;			/* (zero-based indent) */
-    	savdot = e_dot();		/* BOL is now origin for delete */
-    	for (i = 1; i <= nc; ++i)
-    		if ((c = e_getc()) == SP)
-			++indent;
-		else 			/* (tab) */
-			indent = (indent + 8) & ~7;
-    	if (nc > 0)			/* Don't bother deleting nothing */
-		ed_delete(savdot, e_dot());
-#ifdef MYDEBUG
-	reveal("indent: %d, nc: %d, foo: %d", indent, nc, 234);
-#endif
-	return(indent);
-}
-#endif /*IMAGEN*/
-
-
-#if ICONOGRAPHICS
-/* Iconographics hack for Auto-Fill mode.  Too big and clumsy, but
- * retained for posterity in case it has some obscure feature.
- */
-
-fill_current_line ()
-{
-        chroff startpos, endpos, savepos, limitpos;
-        int i, foundit;
-        SBSTR *savep;
-
-        foundit = 0;
-        while (d_curind() > ev_fcolumn)
-           {
-            foundit = 1;
-            startpos = e_dot ();
-            e_bwsp ();
-            while (d_curind() > ev_fcolumn) /* back up to ends of wds*/
-               {                                /* until <= fill column */
-                while (!c_wsp (e_rgetc ())) ;
-                e_bwsp ();
-               }
-            if (e_dot () == e_boldot ())
-               { /*	ding ("Word does not fit in fill column"); */
-	                return(0);
-               }
-            savep = e_copyn (startpos - e_dot ());
-            e_setcur ();                /* ed_delete does gocur */
-            ed_delete (savepos = e_dot (), startpos);
-
-		f_crlf();		/* Now insert newline */
-		e_sputz(fill_prefix);	/* With fill prefix */
-            startpos += e_dot () - savepos;
-            if (d_curind() > ev_fcolumn)
-               {	ed_delete (savepos, e_dot ());
-	                sb_sins (cur_buf, savep);
-	                e_setcur ();
-        	        ding ("Fill prefix > fill column???");
-                	return(0);
-               }
-            savepos = e_dot ();         /* gun inherited initial whitespace */
-            sb_sins (cur_buf, savep);
-            e_go (savepos);
-            e_fwsp ();
-            if ((limitpos = e_dot ()) > startpos) limitpos = startpos;
-                                        /* in case rest of line was white */
-            ed_delete (savepos, limitpos);
-            e_gosetcur (startpos + savepos - limitpos);
-           }
-
-        return foundit;
-  }
-#endif /*ICONOGRAPHICS*/
Index: trunk/minix/commands/elle/eehelp.c
===================================================================
--- trunk/minix/commands/elle/eehelp.c	(revision 9)
+++ 	(revision )
@@ -1,81 +1,0 @@
-/* ELLE - Copyright 1982, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*	EEHELP - Help function
- */
-
-#include "elle.h"		       /* include structure definitions */
-
-
-#if FX_DESCRIBE
-/* EFUN: "Describe" */
-/*	DESCRIBE - Help-command hack.
-**	Crude approximation of EMACS function.
-*/
-static struct buffer *help_buf;
-
-f_describe()
-{	register char *cp;
-	register int i, c;
-	char str[10];
-	struct buffer *savbuf, *b, *make_buf();
-	chroff bdot;
-
-	saynow("Help for command: ");
-	i = cmd_idx(c = cmd_read());		/* Get function idx for cmd */
-	if(c&CB_META) sayntoo("M-");
-	if(i == FN_PFXMETA)
-	  {	sayntoo("M-");
-		i = cmd_idx(c = (cmd_read() | CB_META));
-	  }
-	else if(i == FN_PFXEXT)
-	  {	sayntoo("^X-");
-		i = cmd_idx(c = (cmd_read() | CB_EXT));
-	  }
-	str[0] = c&0177;
-	str[1] = 0;
-	sayntoo(str);
-
-	/* Now read in the help file, if necessary */
-	savbuf = cur_buf;
-	if(help_buf)
-		chg_buf(help_buf);
-	else
-	  {
-		saynow("Loading ");
-		sayntoo(ev_helpfile);
-		sayntoo("...");
-		chg_buf(help_buf = make_buf(" **HELP**"));
-		if(read_file(ev_helpfile) == 0)
-		  {	chg_buf(savbuf);
-			kill_buf(help_buf);
-			help_buf = 0;
-			return;
-		  }
-	  }
-
-
-	/* Find function index in current buffer */
-	cp = str;
-	*cp++ = '<';
-	*cp++ = 'F';
-	cp = dottoa(cp, (chroff)i);
-	*cp++ = '>';
-	e_gobob();
-	if(e_search(str, cp-str, 0) == 0)
-		sayntoo(" No help found");
-	else
-	  {
-		bdot = e_dot();
-		while(!e_lblankp()) e_gonl();	/* Move past 1st blank line */
-		b = make_buf(" *SHOW*");
-		sb_sins((SBBUF *)b, e_copyn(bdot - e_dot()));
-		mk_showin(b);			/* Show the stuff */
-		kill_buf(b);
-		sayclr();
-	  }
-	chg_buf(savbuf);
-}
-#endif /*FX_DESCRIBE*/
Index: trunk/minix/commands/elle/eekmac.c
===================================================================
--- trunk/minix/commands/elle/eekmac.c	(revision 9)
+++ 	(revision )
@@ -1,181 +1,0 @@
-/* ELLE - Copyright 1982, 1985, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*	EEKMAC - Keyboard Macro routines
- *		Modelled after the "e_macro.c" for ICONOGRAPHICS
- *		by C. D. Tavares, 9/11/82
- */
-
-#include "elle.h"
-
-#if FX_SKMAC		/* Entire file is under this conditional! */
-
-int kdef_mode;		/* Set when collecting (a "minor mode") */
-static int km_flag = 0;	/* 1 = executing, -1 collecting, 0 neither */
-static int km_exp;	/* Arg to "Execute Kbd Macro" - # times more to xct */
-static struct buffer *km_buf;
-
-/* EFUN: "Start Kbd Macro" */
-
-f_skmac()
-{	register struct buffer *b;
-	struct buffer *make_buf();
-
-	if(km_flag)
-	  {	ding("Kbd macro active, ignoring \"Start Kbd Macro\"");
-		return;
-	  }
-	if((b = km_buf) == 0)
-		b = km_buf = make_buf(" *KBDMAC*");
-	ex_reset(b);
-	km_flag = -1;		/* Say starting macro collection */
-	kdef_mode = 1;
-	redp(RD_MODE);
-}
-
-/* EFUN: "End Kbd Macro" */
-
-f_ekmac()
-{
-	if(km_flag > 0 && (--km_exp >= 0))
-	  {	ex_go((SBBUF *)km_buf, (chroff)0);
-	  }
-	else if(km_flag)
-	  {	km_flag = 0;
-		kdef_mode = 0;	/* Flush minor mode */
-		redp(RD_MODE);
-	  }
-}
-
-/* EFUN: "Execute Kbd Macro" */
-
-f_xkmac()
-{
-	if(km_flag)
-		ding("Already in kbd macro!");
-	else if(km_buf == 0)
-		ding("No kbd macro defined");
-	else if((km_exp = exp-1) >= 0)
-	  {
-		ex_go((SBBUF *)km_buf, (chroff) 0);
-		km_flag = 1;		/* Start macro execution */
-	  }
-}
-
-/* EFUN: "View Kbd Macro" */
-
-f_vkmac()
-{	register struct buffer *b, *savbuf;
-	chroff prmplen;
-
-	if(!(b = km_buf))
-	  {	ding("No kbd macro defined");
-		return;
-	  }
-	savbuf = cur_buf;
-	chg_buf(b);
-	e_gobob();
-	e_sputz("Current Kbd macro:\n\n");
-	prmplen = e_dot();
-	mk_showin(b);		/* Show the macro buffer temporarily */
-	e_gobob();
-        chg_buf(savbuf);
-	sb_deln((SBBUF *)b, prmplen);	/* Flush the prompt */
-}
-
-
-/* KM_GETC - return next command char from kbd macro being executed.
-**	This is < 0 if not executing kbd macro.  Also responsible for
-**	gathering input for kbd macro.
-*/
-km_getc()
-{	register int c;
-
-	while (km_flag > 0)		/* Executing macro? */
-	  {	c = sb_getc(((SBBUF *)km_buf));	/* Yes, get char */
-		if(c != EOF)
-			return(c);		/* and return as cmd */
-
-		if(--km_exp >= 0)		/* Macro done.  Repeat? */
-			ex_go((SBBUF *)km_buf, (chroff)0);	/* Yes */
-		else km_flag = 0;		/* No, stop execution */
-	  }
-	c = tgetc();			/* Get char from user (TTY) */
-	if(km_flag < 0)			/* Save it if collecting macro */
-	  {	sb_putc(((SBBUF *)km_buf), c);
-	  }
-	return(c);
-}
-
-/* KM_INWAIT() - Return TRUE if any keyboard-macro input waiting.
- */
-km_inwait()
-{	register int c;
-	if(km_flag > 0)
-		if((c = sb_getc(((SBBUF *)km_buf))) != EOF || (km_exp > 0))
-		  {	sb_backc(((SBBUF *)km_buf));
-			return(1);
-		  }
-	return(0);
-}
-
-km_abort ()
-{
-	if(km_flag > 0)		/* Executing? */
-		km_flag = 0;	/* Stop */
-	else if(km_flag < 0)	/* Collecting? */
-		f_ekmac();	/* Close it out */
-}
-
-#endif /*FX_SKMAC*/
-
-
-#if 0	/* Old unused stuff */
-static char mode_buf [60];
-
-add_mode (mode)
-  char *mode;
-  {
-        register char *cur, *c, *m;
-
-        if (cur_mode != mode_buf)
-           {
-            strcpy (mode_buf, cur_mode);
-            cur_mode = mode_buf;
-           }
-
-        if (cur_mode [0]) strcat (cur_mode, ", ");
-        strcat (cur_mode, mode);
-        make_mode ();
-  }
-
-remove_mode (mode)
-  char *mode;
-  {
-        register char *cur, *c, *m;
-
-        if (*cur_mode == 0) return;
-
-        if (cur_mode != mode_buf)
-           {
-            strcpy (mode_buf, cur_mode);
-            cur_mode = mode_buf;
-           }
-
-        for (cur = cur_mode ; *cur ; cur++)
-            if (*cur == *mode)          /* 1st char matches */
-               {
-                for (c = cur, m = mode ; *m && (*m == *c) ; m++, c++) ;
-                if (!(*m))              /* ok, mode matched */
-                   {                    /* kill leading ", " */
-                    if (*(cur - 1) == ' ') --cur;
-                    if (*(cur - 1) == ',') --cur;
-                    for ( ; *cur = *c ; cur++, c++) ;   /* recopy to end */
-                    make_mode ();
-                    return;
-                   }
-               }
-  }
-#endif /*COMMENT*/
Index: trunk/minix/commands/elle/eemain.c
===================================================================
--- trunk/minix/commands/elle/eemain.c	(revision 9)
+++ 	(revision )
@@ -1,516 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * EEMAIN	ELLE Main Command Loop
- */
-
-#include "elle.h"
-
-#include <stdio.h>
-#if !(V6)
-#include <signal.h>
-#else
-#include "eesigs.h"		/* Use this on V6 system */
-#endif /*V6*/
-
-char *argfile[MAXARGFILES];	/* Filename args at startup */
-
-extern int (*sbm_debug)();
-extern int (*sbv_debug)();
-int (*vfy_vec)();	/* If non-zero, routine to verify data
-			 * after each main-loop command */
-
-main (argc, argv)
-int argc;
-char **argv;
-{
-	register int c;		/* Current command character */
-	register int i;
-	static int waitct;
-	extern int errsbm();
-#if SUN
-	extern int sun_rdevf;	/* from EESUN */
-#endif
-#ifdef STKMEM
-	char stackm[STKMEM];		/* Allocate some unused stack space */
-#endif /*STKMEM*/
-
-	sbv_debug = errsbm;		/* Load with addrs of routine to */
-	sbm_debug = errsbm;		/* process SB and SBM errors. */
-
-#ifdef STKMEM
-	sbm_init(&stackm[0],(SBMO)STKMEM);	/* Initialize mem alloc rtns */
-#endif /*STKMEM*/
-#if SUN
-	sun_main(&argc, argv);		/* On SUN, invoke window startup */
-#endif /*SUN*/
-
-	setbuf(stdout, (char *)NULL);	/* Remove all stdio buffering */
-	setbuf(stderr, (char *)NULL);	/* in case of error reports. */
-
-	waitct = 0;			/* debugging */
-	doargs(argc,argv);		/* Set up args */
-	initialize ();			/* Initialize the editor */
-
-	if (argfile[0])			/* shell line arg */
-		find_file(argfile[0]);
-#if MAXARGFILES > 1
-	if(argfile[1])
-	  {	f_2winds();		/* Make 2 windows, go to 2nd */
-		i = 1;
-#if MAXARGFILES > 2
-		for (; i < MAXARGFILES; ++i)
-#endif /* > 2 files */
-			find_file(argfile[i]);	/* Get further file(s) */
-		f_othwind();		/* Move back to 1st window */
-	  }
-#endif /* > 1 file */
-
-	redp(RD_SCREEN|RD_MODE);	/* Clear and show mode line */
-	setexit(0);			/* catch for ints, ^G throws */
-
-/* -----------------------------------------------------------
-**			ELLE MAIN LOOP
-**
-*/
-	for (;;)
-	  {
-		/* First set up default arg unless last cmd specified it */
-		if(this_cmd != ARGCMD)
-		  {	exp = 1;		/* Default arg is 1 */
-			exp_p = 0;		/* Say no explicit arg */
-			last_cmd = this_cmd;
-		  }
-		this_cmd = 0;
-
-		askclr();		/* If stuff asked, say to clear it */
-		if(cmd_wait())
-			waitct++;
-		else if(rd_type != 0)
-			redisplay();	/* Redisplay if needed and no input */
-#if SUN
-		sun_rdevf = 1;		/* Allow mouse events on this input */
-#endif
-		c = cmd_read();		/* Read an editor command */
-		sayclr();		/* Ask to clear echo area cleverly */
-
-#if SUN
-		if(c != -1)		/* SUN may not have real input */
-#endif					/*    if mouse event happened. */
-			cmd_xct(c);	/* Execute the command char! */
-
-		if(vfy_vec)		/* If debugging, */
-			(*vfy_vec)(1);	/* verify data structs right away */
-	  }
-}
-
-
-char *prof_file;	/* Can specify user profile filename */
-
-doargs(argc,argv)
-int argc;
-char **argv;
-{	register int cnt, c;
-	register char **av;
-	extern int tibfmsk;
-	int argfiles = 0;
-	int argsignored = 0;
-
-	av = argv;
-	cnt = argc;
-
-#if V6	/* V6 doesn't have environment thus no TERM var */
-	/* Hack to force terminal type; analyze pgm name to get
-	 * possible ".type" suffix.
-	 */
-	if(cnt && (c = strlen(*av)))
-	  while(--c >= 0)
-	  {	switch(av[0][c])
-		  {	case '.':
-				tv_stype = &av[0][c+1];
-			case '/':
-				break;
-			default: continue;
-		  }
-		break;
-	  }
-#endif /*V6*/
-
-	while(--cnt > 0)
-	  {	++av;
-		if(*av[0] != '-')	/* If not switch, */
-		  {			/* assume it's an input filename */
-			if (argfiles < MAXARGFILES)
-				argfile[argfiles++] = *av;
-			else
-				++argsignored;
-			continue;
-		  }
-		c = upcase(av[0][1]);
-		switch(c)		/* Switches without args */
-		  {	case 'I':	/* Allow debug ints */
-				dbg_isw = 1;
-				continue;
-			case '8':		/* Ask for 8-bit input */
-				tibfmsk = 0377;
-				continue;
-			case '7':		/* Ask for 7-bit input */
-				tibfmsk = 0177;
-				continue;
-#if IMAGEN
-			case 'R':	/* Debug redisplay stuff */
-				dbg_redp = 1;
-				continue;
-#endif /*IMAGEN*/
-		  }
-		if(--cnt <= 0)
-			goto stop;
-		++av;
-		switch(c)		/* Switches with args */
-		  {	case 'T':	/* Terminal type */
-				tv_stype = *av;
-				break;	
-			case 'P':
-				prof_file = *av;
-			default:
-				goto stop;
-		  }
-		continue;
-	stop:	printf("ELLE: bad switch: %s\n",*av);
-		exit(1);
-	  }
-	if (argsignored > 0)
-	  {	printf("ELLE: more than %d file args, %d ignored.\n",
-			MAXARGFILES, argsignored);
-		sleep(2);	/* Complain but continue after pause */
-	  }
-}
-
-
-int f_throw();		/* throw function */
-int bite_bag();		/* Error handling routine */
-int hup_exit();		/* Hangup handling routine */
-
-struct majmode ifunmode = { "Fundamental" };
-
-initialize ()				/* Initialization */
-{
-#if SUN
-	extern int sun_winfd;
-#endif
-	cur_mode = fun_mode = &ifunmode;	/* Set current major mode */
-	unrchf = pgoal = -1;
-	if(!homedir)
-	  {
-#if V6
-		extern char *logdir();
-		homedir = logdir();
-#else /* V7 */
-		homedir = getenv("HOME");
-#endif /*-V6*/
-	  }
-
-	sbx_tset((chroff)0,0);		/* Create swapout file */
-					/* (Temporary hack, fix up later) */
-	hoard();			/* Hoard a FD for write purposes */
-
-	redp_init();			/* Set up the display routines */
-	init_buf();			/* Set up initial buffers */
-	set_profile(prof_file);		/* Set up user profile */
-
-#if SUN
-	if(sun_winfd) sun_init();
-#endif /*SUN*/
-
-	/* Set up signal handlers */
-#if 0					/* not really used */
-	signal (SIGQUIT, f_throw);	/* Quit - on ^G */
-#endif
-#if !(MINIX)
-	signal (SIGSYS, bite_bag);	/* Bad arg to Sys call */
-#endif
-	signal (SIGSEGV, bite_bag);	/* Segmentation Violation */
-#if !(COHERENT)
-	signal (SIGILL, bite_bag);	/* Illegal Instruction interrupt */
-	signal (SIGBUS, bite_bag);	/* Bus Error interrupt */
-#endif /*-COHERENT*/
-#if !(TOPS20)				/* T20 just detaches job */
-	signal (SIGHUP, hup_exit);	/* Terminal Hangup interrupt */
-#endif /*-TOPS20*/
-}
-
-
-/* NOTE: This routine is not actually used, because ELLE does not
- * allow interrupts to do anything.
- */
-/* EFUN: "Error Throw" */
-f_throw ()			       /* abort whatever is going on */
-{
-	ring_bell ();
-	curs_lin = -1000;		/* make t_curpos do something */
-	redp(RD_MOVE);		/* crock: cursor seems to move, so fix it */
-	signal(SIGQUIT, f_throw);	/* rearm signal */
-/*	unwind_stack(main); */
-	reset(1);			/* throw to main loop */
-}
-
-/* RING_BELL - General-purpose feeper when something goes wrong with
- *	a function.
- */
-ring_bell()
-{	t_bell();		/* Tell user something's wrong */
-
-#if FX_SKMAC
-        f_ekmac();		/* Stop collecting keyboard macro if any */
-#endif /*FX_SKMAC*/
-}
-
-
-/* EFUN: "Return to Superior"
- *	Behavior here is somewhat system-dependent.  If it is possible to
- * suspend the process and continue later, we do not ask about modified
- * buffers.  Otherwise, we do.  Questioning can always be forced by using
- * the prefix ^U.
- *	Note that here we try to be very careful about not letting the user
- * exit while buffers are still modified, since UNIX flushes the process
- * if we exit.  Also, the code here conspires with sel_mbuf to rotate
- * through all modified buffers, complaining about a different one each time,
- * so that the user need not even know how to select a buffer!
- */
-f_retsup()
-{	register char *reply;
-	register int c;
-	register struct buffer *b, *b2;
-	extern struct buffer *sel_mbuf();
-	extern int tsf_pause;
-
-	/* If we have capability of pausing and later continuing, do that,
-	 * except if CTRL-U forces us into question/save/quit behavior.
-	 */
-	if(tsf_pause && (exp_p != 4))
-	  {	clean_exit();		/* Return TTY to normal mode */
-		ts_pause();		/* Pause this inferior */
-		set_tty();		/* Continued, return to edit mode */
-		redp(RD_SCREEN);
-		return;
-	  }
-
-	/* Sigh, do more typical "Are you sure" questioning prior to
-	 * killing the editor permanently.
-	 */
-	b = cur_buf;
-	if((b = sel_mbuf(b)) || (b = sel_mbuf((struct buffer *)0)) )
-	  {	if(b2 = sel_mbuf(b))
-			reply = ask(
-		"Quit: buffers %s, %s,... still have changes - forget them? ",
-				b->b_name, b2->b_name);
-		else
-			reply = ask(
-		"Quit: buffer %s still has changes - forget them? ",
-				b->b_name);
-		
-	  }
-	else
-	  {
-#if IMAGEN	/* Do not ask further if nothing modified */
-		barf("Bye");
-		clean_exit();
-		exit(0);
-#else
-		reply = ask("Quit? ");
-#endif /*-IMAGEN*/
-	  }
-
-	if (reply == 0)
-		return;			/* Aborted, just return */
-
-	c = upcase(*reply);		/* Get 1st char of reply */
-	chkfree(reply);
-
-	switch(c)
-	  {	case 'Y':
-#if IMAGEN
-			barf("Bye");
-#endif /*IMAGEN*/
-			clean_exit();
-			exit(0);
-#if 0
-		case 'S':		/* Suspend command for debugging */
-			bkpt();
-			return;
-#endif /*COMMENT*/
-		default:		/* Complain */
-			ring_bell();
-		case 'N':
-			if(b)	/* B set if we have any modified buffers */
-			  {	sel_buf(b);
-				if(b->b_fn)
-					saynow("Use ^X ^S to save buffer");
-				else	saynow("Use ^X ^W to write out buffer");
-			  }
-	  }
-}
-
-
-
-#if FX_WFEXIT
-/* EFUN: "Write File Exit" (not EMACS) - from IMAGEN config */
-f_wfexit()
-{
-	exp_p = 1;		/* Ensure f_savefiles asks no questions */
-	if (! f_savefiles())	/* Save all modified buffers, but */
-		return;		/*  stay here if any save fails */
-	saynow("Bye");
-	clean_exit();
-	exit(0);
-}
-#endif /*FX_WFEXIT*/
-
-
-/* Subprocess-handling stuff; put here for time being. */
-
-/* EFUN: "Push to Inferior" */
-#if TOPS20
-#include <frkxec.h>	/* Support for KCC forkexec() call */
-#endif
-f_pshinf()
-{
-	register int res;
-	register int (*sav2)(), (*sav3)();
-	int pid, status;
-	char *shellname;
-#if IMAGEN
-	char fullshell[64];
-#endif /*IMAGEN*/
-
-	sav2 = signal(SIGINT, SIG_IGN);		/* Ignore TTY interrupts */
-	sav3 = signal(SIGQUIT, SIG_IGN);	/* Ditto TTY "quit"s */
-	clean_exit();				/* Restore normal TTY modes */
-
-#if TOPS20
-    {
-	struct frkxec fx;
-	fx.fx_flags = FX_WAIT | FX_T20_PGMNAME;
-	fx.fx_name = "SYS:EXEC.EXE";
-	fx.fx_argv = fx.fx_envp = NULL;
-	if (forkexec(&fx) < 0)
-		writerr("Cannot run EXEC");
-    }
-#else /*-TOPS20*/
-	switch(pid = fork())
-	  {	case -1:
-			writerr("Cannot fork");
-			break;
-		case 0:		/* We're the child */
-			for(res = 3; res < 20;)	/* Don't let inf hack fd's */
-				close(res++);
-#if V6
-			execl("/bin/sh","-sh",0);
-#else
-			signal(SIGINT, SIG_DFL);	/* V7 shell wants this?? */
-			signal(SIGQUIT, SIG_DFL);	/*	*/
-#if IMAGEN
-			if((shellname = getenv("SHELL")) == 0)
-				shellname = "sh";
-			strcpy(fullshell, "/bin/");
-			strcat(fullshell, shellname);
-			shellname = fullshell;
-#else
-			if((shellname = getenv("SHELL")) == 0)
-				shellname = "/bin/sh";
-#endif /*-IMAGEN*/
-
-			if((shellname = getenv("SHELL")) == 0)
-				shellname = "/bin/sh";
-			execl(shellname, shellname, 0);
-#endif /*-V6*/
-			writerr("No shell!");
-			exit(1);
-			break;
-		default:
-			while((res = wait(&status)) != pid && res != -1);
-			break;
-	  }
-#endif /*-TOPS20*/
-
-	signal(SIGINT, sav2);		/* Restore signal settings */
-	signal(SIGQUIT, sav3);
-	set_tty();			/* Restore editor TTY modes */
-	redp(RD_SCREEN|RD_MODE);	/* Done, redisplay */
-}
-
-
-/* Miscellaneous utility routines - memory alloc/free and string hacking.
- * If this page becomes overly large, it can be split off into a separate
- * file called E_MISC.
- */
-char *
-strdup(s)
-char *s;	/* Note that STRCPY's return val must be its 1st arg */
-{	char *strcpy();
-	return(strcpy(memalloc((SBMO)(strlen(s)+1)), s));
-}
-
-char *
-memalloc(size)
-SBMO size;
-{	register SBMA ptr;
-	extern SBMA sbx_malloc();
-
-	if ((ptr = (SBMA)sbx_malloc(size)) != 0)
-		return((char *)ptr);
-	barf("ELLE: No memory left");
-	askerr();
-	return(0);		/* If we dare to continue... */
-}
-
-chkfree (ptr)
-SBMA ptr;
-{
-	if(!free(ptr))
-	  {	errbarf("Something overwrote an allocated block!");
-		askerr();
-	  }
-}
-
-
-/* USTRCMP - Uppercase String Compare.
- *	Returns 0 if mismatch,
- *		1 if full match,
- *		-1 if str1 runs out first (partial match)
- */
-ustrcmp(str1,str2)
-char *str1, *str2;
-{	register char *s1, *s2;
-	register int c;
-	s1 = str1; s2 = str2;
-	while(c = *s1++)
-	  {	if(c != *s2 && upcase(c) != upcase(*s2))
-			return(0);
-		s2++;
-	  }
-	return(c == *s2 ? 1 : -1);
-}
-
-
-/* WRITERR(str) - Output string to standard error output.
-**	This is a separate routine to save a little space on calls.
-*/
-writerr(str)
-char *str;
-{	return(writez(2, str));
-}
-
-/* WRITEZ(fd, str) - Miscellaneous general-purpose string output.
- */
-writez(fd,acp)
-int fd;
-char *acp;
-{	register char *cp;
-	cp = acp;
-	while(*cp++);
-	write(fd,acp,cp-acp-1);
-}
Index: trunk/minix/commands/elle/eemake.c
===================================================================
--- trunk/minix/commands/elle/eemake.c	(revision 9)
+++ 	(revision )
@@ -1,310 +1,0 @@
-/* ELLE - Copyright 1982, 1985, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/* EEMAKE - IMAGEN configuration functions for interfacing to "make".
- *	Written by (I think) Chris Ryland at IMAGEN, who also
- * wrote other functions scattered through ELLE.  These are either
- * conditionalized or are commented as being derived from the IMAGEN
- * configuration.
- *
- * KLH: An attempt has been made to keep these routines updated as ELLE
- * changed, but their workings cannot be guaranteed.
- */
-
-
-/*
- * eemake: "make" (and other program) support
- *
- * Next-error depends on programs writing error messages of the form:
- *  "file", line n: message
- * which is a de facto standard, at least in some worlds.
- */
-
-#include "elle.h"
-
-#if !(IMAGEN)		/* Only with IMAGEN config for now */
-f_xucmd() {}
-f_make() {}
-f_nxterr() {}
-#else
-
-#include <stdio.h>
-
-struct buffer *exec_buf;	/* Ptr to "Execution" buffer */
-				/* Only external ref is from e_buff.c */
-
-#define MSGLENGTH (scr_wid - 11)	/* Max length of message */
-int fresh_make = 1;			/* Fresh Execution buffer contents */
-chroff last_error_BOL;			/* Dot for last-error's BOL */
-
-/* EFUN: "Execute Unix Command" */
-f_xucmd()
-{
-	make_or_unix_cmd(0);
-}
-
-/* EFUN: "Execute Make" */
-f_make()
-{
-	make_or_unix_cmd(1);
-}
-
-/* EFUN: "Find Next Error" */
-f_nxterr()
-{
-	register struct sbstr *sb;
-	register char *cp;
-	register int c;
-	char file[64], line[32];
-#ifdef ONEWINDOW
-	char msg[512];
-#endif
-	chroff linedot;
-	int lineno;
-	register int len;
-
-	sel_execbuf();
-	if (! fresh_make)
-	  {	e_go(last_error_BOL);
-		e_gonl();
-	  }
-	else
-	  {	fresh_make = 0;
-		e_gobob();
-		last_error_BOL = e_dot();
-	  }
-
-	/* Looking for `"file", line n: msg' */
-	if (! e_search("\", line ", 8, 0))
-		goto failed;
-	linedot = e_dot();
-	e_gobol();			/* Found something, get to BOL */
-	if (e_getc() != '"')
-		goto failed;		/* Insist on beginning "file" */
-	cp = file;			/* Pick up filename */
-	while ((c = e_getc()) != '"')
-		*cp++ = c;
-	*cp = 0;
-	e_go(linedot);			/* Back to after "line " */
-	cp = line;
-	while ((c = e_getc()) >= '0' && c <= '9')
-		*cp++ = c;
-	*cp = 0;
-	lineno = atoi(line);		/* Pick up line number */
-#ifdef ONEWINDOW
-	cp = msg;			/* Now get rest of line to msg */
-	len = 0;			/* But keep length <= MSGLENGTH */
-	e_getc();			/* Go past purported space */
-	while ((c = e_getc()) != LF && c != EOF && len <= MSGLENGTH)
-	  {	if (c == '\t')
-			len = (len + 8) & ~07;
-		else if (c < ' ' || c > 0176)
-			len += 2;
-		else
-			++len;
-		*cp++ = c;
-	  }
-	*cp = 0;
-	if (len > MSGLENGTH)
-		strcat(msg, "...");
-#ifdef DEBUG
-	say("file ");
-	saytoo(file);
-	saytoo(", line ");
-	saytoo(line);
-	saytoo(", msg: ");
-	sayntoo(msg);
-#else
-	say(line);
-	saytoo(": ");
-	sayntoo(msg);
-#endif /*DEBUG*/
-#else /* -ONEWINDOW */
-	f_begline();			/* Get to start of line */
-	last_error_BOL = e_dot();	/* Remember this position */
-	exp_p = 1;			/* Make this the new top line */
-	exp = 0;
-	f_newwin();
-	upd_wind(0);
-#endif /*ONEWINDOW*/
-
-	/* Now, visit the given file and line */
-#ifdef ONEWINDOW	
-#else
-	f_othwind();			/* To other window */
-#endif
-	find_file(file);
-	f_gobeg();
-	down_line(lineno - 1);
-#ifdef READJUST				/* NAW */
-	exp_p = 1;
-	exp = cur_win->w_ht / 4;	/* Adjust how we look at "error" */
-	f_newwin();
-#endif /*READJUST*/
-	return;
-
-failed:	ding("No more errors!");
-	fresh_make = 1;			/* Fake-out: pretend starting over */
-	return;
-}
-
-
-
-/* Do the "cmd" and put its output in the Execution buffer */
-do_exec(cmd, nicely)
-char *cmd;
-int nicely;
-{
-	register int n;
-	int status, res, pid, fd[2];
-	char nicecmd[256];
-	char pipebuff[512];
-	struct buffer *b;
-
-	b = cur_buf;
-	sel_execbuf();			/* Get our execution buffer up */
-	ed_reset();			/* Clear it out */
-	fresh_make = 1;
-	upd_wind(0);
-	if (nicely)
-		sayntoo(" ...starting up...");
-	else
-		sayntoo(" ...starting up (nasty person)...");
-	pipe(fd);
-	switch (pid = fork())
-	  {
-	case -1:
-		/* Fork failed, in parent */
-		ding("Cannot fork!?!");
-		break;
-
-	case 0: /* In child */
-		for (n = 0; n < 20; ++n)
-			if (n != fd[0] && n != fd[1])
-				close(n);
-		open("/dev/null", 0);	/* Give ourselves empty stdin */
-		dup(fd[1]);
-		dup(fd[1]);		/* stdout, stderr out to pipe */
-		close(fd[1]);		/* Close the pipe itself */
-		close(fd[0]);
-		if (nicely)
-		  {	strcpy(nicecmd, "nice -4 ");
-			strcat(nicecmd, cmd);
-			execl("/bin/sh", "sh", "-c", nicecmd, 0);
-		  }
-		else
-			execl("/bin/sh", "sh", "-c", cmd, 0);
-		write(1, "Cannot execute!", 15);
-		_exit(-1);
-		break;
-
-	default:
-		/* Parent */
-		close(fd[1]);		/* Close the output direction */
-		while ((n = read(fd[0], pipebuff, sizeof(pipebuff))) > 0)
-		  {	ed_nsins(pipebuff, n);
-			upd_wind(0);
-			saynow("Chugging along...");
-		  }
-		close(fd[0]);
-		while ((res = wait(&status)) != pid && res != -1)
-			;		/* Wait for this fork to die */
-		f_bufnotmod();		/* Buffer is fresh */
-		saynow("Done!");
-		break;
-	  }
-	f_othwind();			/* Back to other window */
-	chg_buf(b);			/* Back to original buffer */
-}
-
-char last_make_cmd[256];		/* Last Unix/make command */
-int have_last_make_cmd = 0;
-
-make_or_unix_cmd(domake)
-int domake;
-{
-#if APOLLO
-	register int nicely = exp == 16;	/* modification for apollo */
-#else
-	register int nicely = exp != 16;
-#endif /*-APOLLO*/
-	register char *reply, *cmd = 0;
-
-	if (domake)			/* If "make"-style, */
-	  {	int savp = exp_p;
-		exp_p = 1;
-		f_savefiles();		/*  write modified files quietly */
-		exp_p = savp;
-	  }
-	if (exp_p || ! domake)
-	  {		/* Arg given make, or Unix command */
-		reply = ask((! domake) ? "Unix command: " : "Command: ");
-		if (! reply)
-			return;
-		if (*reply == 0)
-		  {	if (have_last_make_cmd)
-				cmd = &last_make_cmd[0];
-			else
-			  {	chkfree(reply);
-				ding("No previous command!");
-				return;
-			  }
-		  }
-		else
-			cmd = reply;
-		if (cmd != &last_make_cmd[0])	/* Update last command */
-			strcpy(last_make_cmd, cmd);
-		have_last_make_cmd = 1;
-		say("Command: ");
-		sayntoo(cmd);
-		do_exec(cmd, nicely);
-		chkfree(reply);
-	  }
-	else if (have_last_make_cmd)
-	  {	say("Command: ");
-		sayntoo(last_make_cmd);
-		do_exec(last_make_cmd, nicely);
-	  }
-	else
-	  {	saynow("Command: make");
-		do_exec("make", nicely);
-	  }
-}
-
-
-sel_execbuf()
-{	if(!exec_buf)
-	  {	/* Make execution buffer; don't let anyone kill it */
-		exec_buf = make_buf("Execution");
-		exec_buf->b_flags |= B_PERMANENT;
-	  }
-	popto_buf(exec_buf);
-}
-
-/* Utility: pop the given buffer to a window, getting into 2-window mode */
-popto_buf(b)
-register struct buffer *b;
-{
-	/* See if we already have this buffer in a visible window */
-	if (b == cur_win->w_buf)
-	  {	if (oth_win == 0)
-		  {	f_2winds();
-			f_othwind();		/* Get back to our window */
-		  }
-	  }
-	else if (oth_win != 0 && b == oth_win->w_buf)
-		f_othwind();
-	else if (oth_win == 0)
-	  {		/* One window mode */
-		f_2winds();			/* Get two, get into second */
-		sel_buf(b);			/* Select our new buffer */
-	  }
-	else
-	  {	f_othwind();			/* Get to other window */
-		sel_buf(b);			/*  and select our buffer */
-	  }
-}
-
-#endif /*IMAGEN*/
Index: trunk/minix/commands/elle/eeprof.h
===================================================================
--- trunk/minix/commands/elle/eeprof.h	(revision 9)
+++ 	(revision )
@@ -1,20 +1,0 @@
-#define PROF_VER (1)
-
-struct profile {
-int version;
-int chrvcnt;  char *chrvec; 
-int metavcnt; char *metavec;
-int extvcnt;  char *extvec; 
-int menuvcnt; char *menuvec;
-};
-
-struct stored_profile {
-unsigned char version[2];
-unsigned char chrvcnt[2], chrvec[2]; 
-unsigned char metavcnt[2], metavec[2];
-unsigned char extvcnt[2], extvec[2]; 
-unsigned char menuvcnt[2], menuvec[2];
-};
-
-#define prof_pack(p, n)		((p)[0] = (n) & 0xFF, (p)[1] = (n) >> 8)
-#define prof_upack(p)		((p)[0] | ((p)[1] << 8))
Index: trunk/minix/commands/elle/eeproto.h
===================================================================
--- trunk/minix/commands/elle/eeproto.h	(revision 9)
+++ 	(revision )
@@ -1,435 +1,0 @@
-#ifndef _ANSI
-#include <ansi.h>
-#endif
-
-/* eebit.c */
-_PROTOTYPE( int *chballoc, (int size) );
-_PROTOTYPE( int chbit, (int *array, int c) );
-_PROTOTYPE( int chbis, (int *array, int c) );
-_PROTOTYPE( int chbic, (int *array, int c) );
-
-/* eebuff.c */
-_PROTOTYPE( int f_selbuffer, (void) );
-_PROTOTYPE( int f_selxbuffer, (void) );
-_PROTOTYPE( int f_kbuffer, (void) );
-_PROTOTYPE( int f_listbufs, (void) );
-_PROTOTYPE( int f_bufnotmod, (void) );
-_PROTOTYPE( int f_eolmode, (void) );
-_PROTOTYPE( int f_gobeg, (void) );
-_PROTOTYPE( int f_goend, (void) );
-_PROTOTYPE( int f_whatpage, (void) );
-_PROTOTYPE( int init_buf, (void) );
-_PROTOTYPE( struct buffer *make_buf, (char *bname) );
-_PROTOTYPE( struct buffer *find_buf, (char *name) );
-_PROTOTYPE( int sel_buf, (struct buffer *b) );
-_PROTOTYPE( int chg_buf, (struct buffer *newbuf) );
-_PROTOTYPE( int unlk_buf, (struct buffer *bufp) );
-_PROTOTYPE( struct buffer *sel_mbuf, (struct buffer *buf) );
-_PROTOTYPE( struct buffer *sel_mbuf, (struct buffer *buf) );
-_PROTOTYPE( struct buffer *sel_nbuf, (struct buffer *buf) );
-_PROTOTYPE( int kill_buf, (struct buffer *buf) );
-_PROTOTYPE( int zap_buffer, (void) );
-_PROTOTYPE( int ask_kbuf, (struct buffer *buf) );
-_PROTOTYPE( int f_2winds, (void) );
-_PROTOTYPE( int f_1wind, (void) );
-_PROTOTYPE( int f_othwind, (void) );
-_PROTOTYPE( int f_growind, (void) );
-_PROTOTYPE( int f_shrinkwind, (void) );
-_PROTOTYPE( int f_delwind, (void) );
-_PROTOTYPE( int f_sowind, (void) );
-_PROTOTYPE( int f_2modewinds, (void) );
-_PROTOTYPE( int chk2modws, (void) );
-_PROTOTYPE( int init_win, (void) );
-_PROTOTYPE( int chg_win, (struct window *newwin) );
-_PROTOTYPE( struct window *make_win, (int pos, int ht, struct buffer *buf) );
-_PROTOTYPE( int kill_win, (struct window *win) );
-_PROTOTYPE( int mk_showin, (struct buffer *b) );
-_PROTOTYPE( struct window *make_mode, (struct window *bw) );
-_PROTOTYPE( int buf_mod, (void) );
-_PROTOTYPE( int buf_tmat, (chroff dot) );
-_PROTOTYPE( int buf_tmod, (chroff offset) );
-
-/* eecmds.c */
-_PROTOTYPE( int f_pfxmeta, (void) );
-_PROTOTYPE( int f_pfxext, (void) );
-_PROTOTYPE( int f_uarg, (int ch) );
-_PROTOTYPE( int f_negarg, (int ch) );
-_PROTOTYPE( int f_argdig, (int ch) );
-_PROTOTYPE( int f_setprof, (void) );
-_PROTOTYPE( int f_vtbuttons, (void) );
-_PROTOTYPE( int cmd_wait, (void) );
-_PROTOTYPE( int cmd_read, (void) );
-_PROTOTYPE( int cmd_xct, (int ch) );
-_PROTOTYPE( int cmd_idx, (int c) );
-_PROTOTYPE( int set_profile, (char *filename) );
-_PROTOTYPE( int init_menu, (void) );
-
-/* eediag.c */
-_PROTOTYPE( int f_debug, (int ch) );
-_PROTOTYPE( char *vfy_data, (int flag) );
-_PROTOTYPE( int dbg_diag, (void) );
-_PROTOTYPE( int vfy_exer, (int pf, int gcfrq) );
-_PROTOTYPE( int db_prwind, (struct window *w) );
-_PROTOTYPE( char *db_scflgs, (int flags) );
-
-/* eedisp.c */
-_PROTOTYPE( int set_tty, (void) );
-_PROTOTYPE( int clean_exit, (void) );
-_PROTOTYPE( int set_scr, (void) );
-_PROTOTYPE( int redisplay, (void) );
-_PROTOTYPE( int fupd_wind, (struct window *w) );
-_PROTOTYPE( int upd_curs, (chroff adot) );
-_PROTOTYPE( int d_line, (chroff cdot) );
-_PROTOTYPE( int d_ncols, (int lcnt, int ccol) );
-_PROTOTYPE( int d_lupd, (struct window *w, int idx) );
-_PROTOTYPE( int clear_wind, (struct window *w) );
-_PROTOTYPE( int fix_wind, (struct window *win) );
-_PROTOTYPE( int inwinp, (struct window *win, chroff cdot) );
-_PROTOTYPE( int upd_wind, (struct window *win) );
-_PROTOTYPE( int slineq, (struct scr_line *olds, struct scr_line *news) );
-_PROTOTYPE( int upd_line, (int y) );
-_PROTOTYPE( int fillset, (char *str, int cnt, int c) );
-_PROTOTYPE( int fillsp, (char *str, int cnt) );
-_PROTOTYPE( int inspc, (char *cp0, char *cpl, int cnt) );
-_PROTOTYPE( int fix_line, (struct scr_line *slp, struct scr_line *olds) );
-_PROTOTYPE( int sctrin, (char *to, int lim, int ccol) );
-_PROTOTYPE( int inslin, (int line, int n, struct window *win) );
-_PROTOTYPE( int dellin, (int line, int n, struct window *win) );
-_PROTOTYPE( int t_dostandout, (int on) );
-_PROTOTYPE( int t_move, (int y, int x) );
-_PROTOTYPE( int t_docleol, (void) );
-
-/* eeedit.c */
-_PROTOTYPE( int e_reset, (void) );
-_PROTOTYPE( int e_rgetc, (void) );
-_PROTOTYPE( int e_rdelc, (void) );
-_PROTOTYPE( int e_delc, (void) );
-_PROTOTYPE( int e_getc, (void) );
-_PROTOTYPE( int e_backc, (void) );
-_PROTOTYPE( int e_putc, (int c) );
-_PROTOTYPE( int e_peekc, (void) );
-_PROTOTYPE( int e_ovwc, (int ch) );
-_PROTOTYPE( SBSTR *e_copyn, (chroff off) );
-_PROTOTYPE( int e_deln, (chroff off) );
-_PROTOTYPE( int e_setcur, (void) );
-_PROTOTYPE( int e_gosetcur, (chroff dot) );
-_PROTOTYPE( int e_gocur, (void) );
-_PROTOTYPE( int e_gobob, (void) );
-_PROTOTYPE( int e_goeob, (void) );
-_PROTOTYPE( int e_go, (chroff dot) );
-_PROTOTYPE( int e_igoff, (int ioff) );
-_PROTOTYPE( int e_goff, (chroff off) );
-_PROTOTYPE( int e_gobol, (void) );
-_PROTOTYPE( int e_goeol, (void) );
-_PROTOTYPE( int e_gonl, (void) );
-_PROTOTYPE( int e_gopl, (void) );
-_PROTOTYPE( chroff e_dot, (void) );
-_PROTOTYPE( chroff e_nldot, (void) );
-_PROTOTYPE( chroff e_pldot, (void) );
-_PROTOTYPE( chroff e_boldot, (void) );
-_PROTOTYPE( chroff e_eoldot, (void) );
-_PROTOTYPE( chroff e_alldot, (SBBUF *sbp, int (*rtn )()) );
-_PROTOTYPE( chroff e_blen, (void) );
-_PROTOTYPE( int ex_reset, (struct buffer *b) );
-_PROTOTYPE( int ex_go, (SBBUF *sbp, chroff loc) );
-_PROTOTYPE( chroff ex_dot, (SBBUF *sbp) );
-_PROTOTYPE( chroff ex_boldot, (SBBUF *sbp, chroff dot) );
-_PROTOTYPE( chroff ex_alldot, (SBBUF *sbp, int (*rtn )(), chroff dot) );
-_PROTOTYPE( int ex_gonl, (SBBUF *sbp) );
-_PROTOTYPE( int ex_goeol, (SBBUF *sbp) );
-_PROTOTYPE( int ex_gobol, (SBBUF *sbp) );
-_PROTOTYPE( int ex_gopl, (SBBUF *sbp) );
-_PROTOTYPE( chroff ex_blen, (SBBUF *sbp) );
-_PROTOTYPE( int e_gofwsp, (void) );
-_PROTOTYPE( int e_gobwsp, (void) );
-_PROTOTYPE( int e_goline, (int i) );
-_PROTOTYPE( int e_lblankp, (void) );
-_PROTOTYPE( int e_insn, (int ch, int cnt) );
-_PROTOTYPE( int e_sputz, (char *acp) );
-_PROTOTYPE( int boleq, (chroff dot1, chroff dot2) );
-_PROTOTYPE( char *dottoa, (char *str, chroff val) );
-_PROTOTYPE( int e_gobpa, (void) );
-_PROTOTYPE( int e_goepa, (void) );
-_PROTOTYPE( int exp_do, (int (*rpos )(), int (*rneg )()) );
-_PROTOTYPE( int e_fwsp, (void) );
-_PROTOTYPE( int e_bwsp, (void) );
-_PROTOTYPE( int c_wsp, (int ch) );
-_PROTOTYPE( int c_pwsp, (int ch) );
-_PROTOTYPE( int delimp, (int c) );
-_PROTOTYPE( int e_wding, (chroff *adot, int n) );
-_PROTOTYPE( chroff e_wdot, (chroff dot, int n) );
-_PROTOTYPE( int e_gowd, (int n) );
-_PROTOTYPE( int e_search, (char *mstr, int mlen, int backwards) );
-
-/* eeerr.c */
-_PROTOTYPE( int f_bkpt, (void) );
-_PROTOTYPE( int bpt, (void) );
-_PROTOTYPE( char *strerror, (int num) );
-_PROTOTYPE( int errsbm, (int type, int (*adr )(), char *str, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12) );
-_PROTOTYPE( int bite_bag, (int fault) );
-_PROTOTYPE( int hup_exit, (void) );
-_PROTOTYPE( int errint, (void) );
-_PROTOTYPE( int askerr, (void) );
-_PROTOTYPE( char *asklin, (char *acp) );
-
-/* eef1.c */
-_PROTOTYPE( int f_insself, (int c) );
-_PROTOTYPE( int f_quotins, (void) );
-_PROTOTYPE( int f_crlf, (void) );
-_PROTOTYPE( int f_fchar, (void) );
-_PROTOTYPE( int f_bchar, (void) );
-_PROTOTYPE( int f_dchar, (void) );
-_PROTOTYPE( int f_bdchar, (void) );
-_PROTOTYPE( int ef_deln, (int x) );
-_PROTOTYPE( int f_delspc, (void) );
-_PROTOTYPE( int f_tchars, (void) );
-_PROTOTYPE( int f_fword, (void) );
-_PROTOTYPE( int f_bword, (void) );
-_PROTOTYPE( int f_kword, (void) );
-_PROTOTYPE( int f_bkword, (void) );
-_PROTOTYPE( int f_twords, (void) );
-_PROTOTYPE( int f_ucword, (void) );
-_PROTOTYPE( int f_lcword, (void) );
-_PROTOTYPE( int f_uciword, (void) );
-_PROTOTYPE( int case_word, (int downp) );
-
-/* eef2.c */
-_PROTOTYPE( int f_begline, (void) );
-_PROTOTYPE( int f_endline, (void) );
-_PROTOTYPE( int f_nxtline, (void) );
-_PROTOTYPE( int f_prvline, (void) );
-_PROTOTYPE( int f_dnrline, (void) );
-_PROTOTYPE( int f_uprline, (void) );
-_PROTOTYPE( int f_oline, (void) );
-_PROTOTYPE( int f_delblines, (void) );
-_PROTOTYPE( int f_kline, (void) );
-_PROTOTYPE( int f_bkline, (void) );
-_PROTOTYPE( int f_goline, (void) );
-_PROTOTYPE( int down_bline, (int arg) );
-_PROTOTYPE( int down_line, (int x) );
-_PROTOTYPE( int f_setmark, (void) );
-_PROTOTYPE( int f_exchmark, (void) );
-_PROTOTYPE( int f_kregion, (void) );
-_PROTOTYPE( int f_copreg, (void) );
-_PROTOTYPE( int f_ucreg, (void) );
-_PROTOTYPE( int f_lcreg, (void) );
-_PROTOTYPE( int ef_creg, (int downp) );
-_PROTOTYPE( int f_fillreg, (void) );
-_PROTOTYPE( int chkmark, (void) );
-_PROTOTYPE( int f_fpara, (void) );
-_PROTOTYPE( int f_bpara, (void) );
-_PROTOTYPE( int f_mrkpara, (void) );
-_PROTOTYPE( int f_fillpara, (void) );
-
-/* eef3.c */
-_PROTOTYPE( int f_appnkill, (void) );
-_PROTOTYPE( int f_unkill, (void) );
-_PROTOTYPE( int f_unkpop, (void) );
-_PROTOTYPE( int f_indatm, (void) );
-_PROTOTYPE( int f_indnl, (void) );
-_PROTOTYPE( int f_backind, (void) );
-_PROTOTYPE( int f_indcomm, (void) );
-_PROTOTYPE( int f_indrel, (void) );
-_PROTOTYPE( int insertmatch, (int c) );
-_PROTOTYPE( int f_matchbrack, (void) );
-_PROTOTYPE( int matchonelevel, (int mc) );
-
-/* eefd.c */
-_PROTOTYPE( int f_newwin, (void) );
-_PROTOTYPE( int f_nscreen, (void) );
-_PROTOTYPE( int f_pscreen, (void) );
-_PROTOTYPE( int f_othnscreen, (void) );
-_PROTOTYPE( int f_lwindbord, (void) );
-_PROTOTYPE( int f_scupwind, (void) );
-_PROTOTYPE( int f_scdnwind, (void) );
-_PROTOTYPE( int f_mvwtop, (void) );
-_PROTOTYPE( int f_mvwbot, (void) );
-_PROTOTYPE( int d_screen, (int rep) );
-_PROTOTYPE( int scroll_win, (int n) );
-_PROTOTYPE( int d_curind, (void) );
-_PROTOTYPE( int indtion, (chroff lin) );
-_PROTOTYPE( int inindex, (chroff lin, int xpos) );
-_PROTOTYPE( int d_gopl, (void) );
-_PROTOTYPE( int d_gonl, (void) );
-_PROTOTYPE( int d_goloff, (int cnt) );
-_PROTOTYPE( int d_fgoloff, (int cnt) );
-_PROTOTYPE( int d_fixcur, (void) );
-_PROTOTYPE( int d_backup, (int nlin) );
-
-/* eefed.c */
-_PROTOTYPE( int ed_insert, (int c) );
-_PROTOTYPE( int ed_insn, (int ch, int cnt) );
-_PROTOTYPE( int ed_crins, (void) );
-_PROTOTYPE( int ed_sins, (char *s) );
-_PROTOTYPE( int ed_nsins, (char *s, int i) );
-_PROTOTYPE( int ed_indto, (int goal) );
-_PROTOTYPE( int ed_setcur, (void) );
-_PROTOTYPE( int ed_go, (chroff dot) );
-_PROTOTYPE( int ed_goff, (chroff off) );
-_PROTOTYPE( int ed_igoff, (int ioff) );
-_PROTOTYPE( int ed_reset, (void) );
-_PROTOTYPE( int ed_deln, (chroff off) );
-_PROTOTYPE( int ed_delete, (chroff dot1, chroff dot2) );
-_PROTOTYPE( int ed_kill, (chroff dot1, chroff dot2) );
-_PROTOTYPE( int kill_push, (SBSTR *sdp) );
-_PROTOTYPE( int ed_case, (chroff dot1, chroff dot2, int downp) );
-_PROTOTYPE( int upcase, (int ch) );
-
-/* eefile.c */
-_PROTOTYPE( int f_ffile, (void) );
-_PROTOTYPE( int f_rfile, (void) );
-_PROTOTYPE( int f_vfile, (void) );
-_PROTOTYPE( int u_r_file, (char *prompt) );
-_PROTOTYPE( int f_ifile, (void) );
-_PROTOTYPE( int f_sfile, (void) );
-_PROTOTYPE( int f_savefiles, (void) );
-_PROTOTYPE( int f_wfile, (void) );
-_PROTOTYPE( int f_wreg, (void) );
-_PROTOTYPE( int f_wlastkill, (void) );
-_PROTOTYPE( int hack_file, (char *prompt, int (*rtn )()) );
-_PROTOTYPE( int find_file, (char *f_name) );
-_PROTOTYPE( int read_file, (char *f_name) );
-_PROTOTYPE( int ins_file, (char *f_name) );
-_PROTOTYPE( int ferr_ropn, (void) );
-_PROTOTYPE( int ferr_wopn, (void) );
-_PROTOTYPE( int ferr, (char *str) );
-_PROTOTYPE( char *fncons, (char *dest, char *pre, char *f_name, char *post) );
-_PROTOTYPE( char *last_fname, (char *f_name) );
-_PROTOTYPE( int set_fn, (char *string) );
-_PROTOTYPE( int saveworld, (struct buffer *bp, int grunt) );
-_PROTOTYPE( int hoard, (void) );
-_PROTOTYPE( int unhoard, (void) );
-_PROTOTYPE( int expand_file, (char *dfn, char *sfn) );
-
-/* eefill.c */
-_PROTOTYPE( int f_sfcol, (void) );
-_PROTOTYPE( int f_sfpref, (void) );
-_PROTOTYPE( int tstfillp, (int lim) );
-_PROTOTYPE( int ed_fill, (chroff begloc, chroff endloc, int flag) );
-_PROTOTYPE( int f_fillmode, (void) );
-_PROTOTYPE( int fx_insfill, (int c) );
-_PROTOTYPE( int fill_cur_line, (void) );
-_PROTOTYPE( int f_textmode, (void) );
-_PROTOTYPE( int fim_insself, (int c) );
-_PROTOTYPE( int fim_dchar, (void) );
-_PROTOTYPE( int fim_bdchar, (void) );
-_PROTOTYPE( int fim_crlf, (void) );
-_PROTOTYPE( int magic_wrap, (int tc) );
-_PROTOTYPE( int reveal, (char *msg, int v1, int v2, int v3) );
-_PROTOTYPE( int magic_backto_bol, (void) );
-_PROTOTYPE( int fill_current_line, (void) );
-
-/* eehelp.c */
-_PROTOTYPE( int f_describe, (void) );
-
-/* eekmac.c */
-_PROTOTYPE( int f_skmac, (void) );
-_PROTOTYPE( int f_ekmac, (void) );
-_PROTOTYPE( int f_xkmac, (void) );
-_PROTOTYPE( int f_vkmac, (void) );
-_PROTOTYPE( int km_getc, (void) );
-_PROTOTYPE( int km_inwait, (void) );
-_PROTOTYPE( int km_abort, (void) );
-_PROTOTYPE( int add_mode, (char *mode) );
-_PROTOTYPE( int remove_mode, (char *mode) );
-
-/* eemain.c */
-_PROTOTYPE( int doargs, (int argc, char **argv) );
-_PROTOTYPE( int initialize, (void) );
-_PROTOTYPE( int f_throw, (void) );
-_PROTOTYPE( int ring_bell, (void) );
-_PROTOTYPE( int f_retsup, (void) );
-_PROTOTYPE( int f_wfexit, (void) );
-_PROTOTYPE( int f_pshinf, (void) );
-_PROTOTYPE( char *strdup, (char *s) );
-_PROTOTYPE( char *memalloc, (SBMO size) );
-_PROTOTYPE( int chkfree, (SBMA ptr) );
-_PROTOTYPE( int ustrcmp, (char *str1, char *str2) );
-_PROTOTYPE( int writerr, (char *str) );
-_PROTOTYPE( int writez, (int fd, char *acp) );
-
-/* eemake.c */
-_PROTOTYPE( int f_xucmd, (void) );
-_PROTOTYPE( int f_make, (void) );
-_PROTOTYPE( int f_nxterr, (void) );
-_PROTOTYPE( int f_xucmd, (void) );
-_PROTOTYPE( int f_make, (void) );
-_PROTOTYPE( int f_nxterr, (void) );
-_PROTOTYPE( int do_exec, (char *cmd, int nicely) );
-_PROTOTYPE( int make_or_unix_cmd, (int domake) );
-_PROTOTYPE( int sel_execbuf, (void) );
-_PROTOTYPE( int popto_buf, (struct buffer *b) );
-
-/* eequer.c */
-_PROTOTYPE( int f_querep, (void) );
-_PROTOTYPE( int f_repstr, (void) );
-_PROTOTYPE( int f_repline, (void) );
-_PROTOTYPE( int ed_dorep, (int type, struct majmode *mode) );
-
-/* eeques.c */
-#if 0
-_PROTOTYPE( char *ask, (char *string, char *arg1, char *arg2, char *arg3) );
-#else
-char *ask();
-#endif
-_PROTOTYPE( int askclr, (void) );
-_PROTOTYPE( int say, (char *str) );
-_PROTOTYPE( int saynow, (char *str) );
-_PROTOTYPE( int saytoo, (char *str) );
-_PROTOTYPE( int sayntoo, (char *str) );
-_PROTOTYPE( int ding, (char *str) );
-_PROTOTYPE( int dingtoo, (char *str) );
-_PROTOTYPE( int saylntoo, (char *str, int n) );
-_PROTOTYPE( int sayclr, (void) );
-#if 0
-_PROTOTYPE( int sayall, (char *str, int flags, int len) );
-#else
-int sayall();
-#endif
-_PROTOTYPE( int yellat, (char *str, int line) );
-_PROTOTYPE( int yelltoo, (char *str) );
-_PROTOTYPE( int errbarf, (char *str) );
-_PROTOTYPE( int barf, (char *str) );
-_PROTOTYPE( int barf2, (char *str) );
-
-/* eesite.c */
-_PROTOTYPE( int ts_inp, (void) );
-_PROTOTYPE( int ts_init, (void) );
-_PROTOTYPE( int ts_enter, (void) );
-_PROTOTYPE( int ts_exit, (void) );
-_PROTOTYPE( int tpoke, (int cmd, int bn, int val) );
-_PROTOTYPE( int ts_pause, (void) );
-
-/* eesrch.c */
-_PROTOTYPE( int f_srch, (void) );
-_PROTOTYPE( int f_rsrch, (void) );
-_PROTOTYPE( int lin_search, (int backwards) );
-_PROTOTYPE( int srchint, (void) );
-_PROTOTYPE( char *srch_ask, (char *prompt) );
-_PROTOTYPE( int f_risrch, (void) );
-_PROTOTYPE( int i_search, (int back) );
-
-/* eeterm.c */
-_PROTOTYPE( int t_init, (void) );
-_PROTOTYPE( int t_fatal, (char *str) );
-_PROTOTYPE( int t_enter, (void) );
-_PROTOTYPE( int t_exit, (void) );
-_PROTOTYPE( int t_clear, (void) );
-_PROTOTYPE( int t_curpos, (int lin, int col) );
-_PROTOTYPE( int t_backspace, (void) );
-_PROTOTYPE( int t_bell, (void) );
-_PROTOTYPE( int t_cleol, (void) );
-_PROTOTYPE( int t_inslin, (int n, int bot) );
-_PROTOTYPE( int t_dellin, (int n, int bot) );
-_PROTOTYPE( int t_inschr, (int n, char *str) );
-_PROTOTYPE( int t_delchr, (int n) );
-_PROTOTYPE( int t_standout, (int on) );
-_PROTOTYPE( int t_direct, (int lin, int col, char *str, int len) );
-_PROTOTYPE( int tput, (int ch) );
-_PROTOTYPE( int tputz, (char *str) );
-_PROTOTYPE( int tputn, (char *str, int cnt) );
-_PROTOTYPE( int tbufls, (void) );
-_PROTOTYPE( int tgetc, (void) );
-_PROTOTYPE( int tinwait, (void) );
-
-/* eevini.c */
Index: trunk/minix/commands/elle/eequer.c
===================================================================
--- trunk/minix/commands/elle/eequer.c	(revision 9)
+++ 	(revision )
@@ -1,189 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * EEQUER	Query-Replace and Replace-String functions
- */
-
-#include "elle.h"		       /* include structure definitions */
-
-/* EFUN: "Query Replace" */
-/*	Crude approximation of EMACS function.
- */
-f_querep()
-{	static struct majmode iqrpmode = { "Query Replace" };
-	ed_dorep(0, &iqrpmode);
-}
-
-/* EFUN: "Replace String" */
-/*	Similar to Query Replace and uses same code.
- */
-f_repstr()
-{	static struct majmode irepmode = { "Replace String" };
-	ed_dorep(1, &irepmode);
-}
-
-#if FX_REPLINE
-/* EFUN: "Replace in Line" (not EMACS) */
-/*	Acts like Replace String but only operates on current line.
-**	Currently a big crock.
-**	Feature of crockishness is that Unkill Pop (M-Y) will restore old
-**	line.
-*/
-f_repline()
-{
-	extern struct buffer *make_buf();
-	struct buffer *b, *oldb = cur_buf;
-	static struct majmode rlmode = { "Replace in Line" };
-
-	if(!(b = make_buf(" **LINE**")))
-	  {	ring_bell();
-		return;
-	  }
-	f_kline();		/* Kill line(s) from original buffer */
-	chg_buf(b);		/* Switch to temp buffer */
-	f_unkill();		/* Get killed stuff into temp buffer */
-	e_gosetcur((chroff)0);	/* Starting at beginning, */
-	ed_dorep(1, &rlmode);		/* Execute Replace String on it. */
-	ed_kill((chroff)0, e_blen());	/* Now kill everything in it, */
-	chg_buf(oldb);		/* switch back to original buffer, */
-	f_unkill();		/* and restore new stuff! */
-	kill_buf(b);		/* Now flush temporary buffer. */
-}
-#endif
-
-
-/* Note that the major mode is set without changing the buffer's major
- * mode.  When the function is done, the current major mode is reset
- * from the buffer mode.
- */
-ed_dorep(type, mode)		/* 0 = Query Replace, 1 = Replace String */
-int type;
-struct majmode *mode;
-{	register int c;
-	register int olen, allflg;
-	char *srch_ask();
-	char *opromp, *npromp;
-	char *nstr, *ostr;	/* Note ostr is == to srch_str */
-	int nlen;
-	chroff last_loc;
-#if IMAGEN
-	int nrepled = 0;
-	char replmsg[64];
-#endif /*IMAGEN*/
-
-	/* Set mode, then get search string and replace string */
-#if IMAGEN
-	cur_win->w_buf->b_flags |= B_QUERYREP;
-#else
-	cur_mode = mode;	/* Set major mode pointer */
-#endif /*-IMAGEN*/
-
-	redp(RD_MODE);
-	nstr = 0;
-#if IMAGEN
-	opromp = "Old string: ";
-	npromp = "New string: ";
-#else
-	opromp = "Replace string: ";
-	npromp = "with string: ";
-#endif /*-IMAGEN*/
-	if((ostr = srch_ask(opromp)) == 0)
-		goto done;
-	olen = srch_len;	/* srch_ask sets this! */
-	if((nstr = ask("%s%s %s", opromp, ostr, npromp)) == 0)
-		goto done;
-	nlen = ask_len;
-
-	/* Now enter search and subcommand loop */
-	allflg = type;		/* Unless 0 for Query Rep, replace all */ 
-	for(;;)
-	  {	last_loc = cur_dot;
-		if(e_search(ostr,olen,0) == 0)
-			break;
-		ed_setcur();			/* Cursor moved */
-	redisp:
-		if(!allflg) redisplay();	/* Update screen */
-	getcmd:
-		if(!allflg) c = cmd_read();
-		else c = SP;
-		switch(c)
-		  {
-#if IMAGEN
-			case 'n':
-#endif /*IMAGEN*/
-			case DEL:	/* Don't replace, go on */
-				continue;
-#if IMAGEN
-			case ',':
-#endif /*IMAGEN*/
-			case '.':	/* Replace and exit */
-			case SP:	/* Replace, go on */
-				ed_delete(cur_dot,(chroff)(cur_dot-olen));
-				ed_nsins(nstr,nlen);
-#if IMAGEN
-				++nrepled;
-#endif /*IMAGEN*/
-				if(c == '.') goto done;
-				continue;
-#if IMAGEN
-			default:
-#endif /*IMAGEN*/
-			case '?':	/* Show options */
-#if IMAGEN
-				saynow("\
-' '=>change, 'n'=>don't, '.'=>change, quit, '!'=>change rest, '^'=>back up");
-#else
-				saynow("\
-SP=Replace, DEL=Don't, ESC=Stop, !=Replace all, ^=Back up, .=Replace & Stop");
-#endif /*-IMAGEN*/
-				goto getcmd;
-			case '^':	/* Return to last place found */
-				ed_go(last_loc);
-				goto redisp;
-
-			case CTRL('G'):
-			case ESC:	/* Exit where we are */
-				goto done;
-
-			case CTRL('L'):	/* Redisplay */
-				redp(RD_SCREEN);
-				goto redisp;
-
-			case '!':	/* Replace all the rest */
-				allflg++;
-				goto getcmd;
-
-#if !(IMAGEN)
-			case ',':	/* Replace and show */
-			case CTRL('R'):	/* Enter edit mode recursively */
-			case CTRL('W'):	/* Delete once and ^R */
-				saynow("not implemented");
-				goto getcmd;
-			default:	/* Exit and re-read char */
-				unrchf = c;
-				goto done;
-#endif /*-IMAGEN*/
-		  }
-	  }
-done:
-#if IMAGEN
-	cur_win->w_buf->b_flags &= ~B_QUERYREP;
-#else
-	cur_mode = cur_buf->b_mode;
-#endif /*-IMAGEN*/
-
-	redp(RD_MODE);
-	if(nstr) 	/* Free nstr (but not ostr, it's == srch_str!) */
-		chkfree(nstr);
-#if IMAGEN
-	if (nrepled <= 0)
-		saynow("No replacements done");
-	else
-	  {	sprintf(replmsg, "Replaced %d occurences", nrepled);
-		saynow(replmsg);
-	  }
-#endif /*IMAGEN*/
-}
Index: trunk/minix/commands/elle/eeques.c
===================================================================
--- trunk/minix/commands/elle/eeques.c	(revision 9)
+++ 	(revision )
@@ -1,328 +1,0 @@
-/* ELLE - Copyright 1982, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*	EEQUES - Handle queries and status displays
- */
-#include "elle.h"
-
-/*
- * Ask -- ask the user for some input on the lowest line of the screen
- * 
- * The arg is a string in printf form, followed by up to three args
- * for the printf string
- *
- *        The string is read into a sort of mini buffer, only the
- *        last line of which is visible on the screen. All editing
- *        features are available to the user to edit the input string.
- *        When the delim character is typed, input is terminated and
- *        The input string is passed back to the caller.
- *	  The delim is either an escape or a cr.
- *        IT IS UP TO THE CALLER TO FREE THIS MEMORY.
- *
- * Note that the actual length of the returned string can be found
- * in the global variable ask_len.  This is a crock but allows
- * callers to hack nulls in arg strings if they want to.
- */
-
-int chg_win();
-struct window *make_mode();
-
-static int ask_lin;	/* Saved cursor location when ask is done */
-static int ask_blen;	/* Non-zero if buffer contains something */
-static int ask_cnt;	/* Incremented by ask(), cleared by askclr() */
-
-/* Table of allowed functions during ASK */
-static char askftab[] = {
-	FN_PFXMETA, FN_INSSELF, FN_BEGLINE, FN_ENDLINE, FN_BCHAR, FN_FCHAR,
-	FN_DCHAR, FN_BDCHAR, FN_TCHARS, FN_QUOTINS, FN_UARG, FN_BKPT,
-	FN_DEBUG,
-	FN_GOBEG, FN_GOEND, FN_FWORD, FN_BWORD, FN_KWORD, FN_BKWORD,
-	FN_UCWORD, FN_LCWORD, FN_UCIWORD, FN_ARGDIG, FN_NEWWIN, FN_KLINE,
-	FN_UNKILL, FN_BKLINE,
-	0
-};
-
-char *
-ask (string, arg1, arg2, arg3)
-char *string, *arg1, *arg2, *arg3;
-
-{	register int i, c;
-	register char *s;
-	struct window *oldwin;
-	char *newline;		/* where output line goes */
-	char cbuf[200];			/* For prompt string creation */
-	int p_length;			/* length of prompt */
-	chroff anslen;			/* Length of answer */
-	int funnum;			/* Crock stuff */
-#if FX_FILLMODE
-	extern int fill_mode;
-	int ofillmode = fill_mode;	/* Gotta turn this one off */
-	fill_mode = 0;
-#endif /*FX_FILLMODE*/
-
-	oldwin = cur_win;
-	chg_win (ask_win);
-	ed_reset();			/* Flush contents & request redisp */
-	ask_lin = cur_win->w_pos;	/* Set here in case never redisp */
-	ask_cnt++;			/* Bump # of times called */
-
-  	/* copy 'string' into line */
-	cbuf[0] = 0;
-asklp:	sprintf (&cbuf[strlen(cbuf)], string, arg1, arg2, arg3);
-	p_length = strlen(cbuf);	/* Find how long it is */
-
-  	/* now let the user type in */
-	for(;;)
-	  {
-		if ((rd_type & (RDS_WINFLGS|RD_MODE)) && tinwait () == 0)
-		  {
-			e_gobob();	/* Gross crock: insert prompt */
-			e_sputz(cbuf);		/* Ugh, bletch */
-			cur_dot += p_length;	/* Temporarily update loc */
-			redp(RD_WINRES);	/* Do complete re-crunch */
-			upd_wind((struct window *)0);		/* Don't interrupt */
-			/* Ensure mode line is spiffy too.  This should
-			** only have to be invoked the first time ask_win
-			** redisplay is done, and never thereafter.
-			*/
-			if(rd_type&RD_MODE)	/* If mode also needs it, */
-				fupd_wind(make_mode(user_win));	/* do it */
-
-			upd_curs(cur_dot);
-			rd_type &= ~(RDS_WINFLGS|RD_MODE);
-			ask_lin = curs_lin;	/* Remember line cursor on */
-			tbufls();
-
-			e_gobob();	/* More crock: Remove prompt */
-			sb_deln((SBBUF *)cur_buf,(chroff)p_length);	/* Ugh etc. */
-			cur_dot -= p_length;		/* Restore loc */
-			e_gocur();
-		  }
-		exp = 1;
-		exp_p = 0;
-	cont:	this_cmd = 0;
-		c = cmd_read();
-
-		if (
-#if !(ICONOGRAPHICS)
-			c == ESC ||
-#endif /*-ICONOGRAPHICS*/
-				 c == LF || c == CR)
-			break;
-		if (c == BELL)       /* ^G means punt.. */
-		  {	chg_win(oldwin);
-			ask_blen = 1;	/* Assume buffer has something */
-			ding((char *)0);	/* Clear echo window */
-			ask_cnt = 0;	/* Nothing for askclr to do */
-#if FX_SKMAC
-			km_abort();
-#endif /*FX_SKMAC*/
-#if FX_FILLMODE
-			fill_mode = ofillmode;
-#endif /*FX_FILLMODE*/
-			return(0);	/* Return 0 to indicate we quit */
-		  }
-		/* This censoring section is a real crock! */
-		funnum = cmd_idx(c);		/* Map key to command */
-		while(funnum == FN_PFXMETA)	/* Allow META prefix */
-			funnum = cmd_idx(c = CB_META|cmd_read());
-		for(s = askftab; (i = *s&0377); ++s)
-			if(funnum == i) break;
-		switch(i)
-		  {	default:	/* Permissible function */
-				cmd_xct(c);
-				break;
-			case FN_NEWWIN:	/* Wants redisplay, do specially */
-				clear_wind(ask_win);
-				break;
-			case 0:		/* Illegal function */
-				ring_bell();
-#if FX_SKMAC
-				km_abort();
-#endif /*FX_SKMAC*/
-				continue;
-		  }
-		if(this_cmd == ARGCMD)
-			goto cont;
-	  }
-
-	if((anslen = e_blen()) > 255)		/* Ridiculously long? */
-	  {	strcpy(cbuf,"Huh? Try again - ");
-#if FX_SKMAC
-			km_abort();
-#endif /*FX_SKMAC*/
-		goto asklp;
-	  }
-	i = anslen;
-	e_gobob();		/* Go to start of buffer */
-	e_sputz(cbuf);		/* Re-insert prompt so buffer == screen */
-	ask_blen = i + 1;	/* Say buffer has something in it */
-
-	s = memalloc((SBMO)(i + 1));	/* Allocate fixed loc for answer */
-	newline = s;		/* Return ptr to allocated string */
-	ask_len = i;		/* And return (via global) length of string */
-	if(i) do { *s++ = e_getc(); }
-		while(--i);
-	*s = '\0';		       /* make sure string terminated */
-	chg_win(oldwin);
-#if FX_FILLMODE
-	fill_mode = ofillmode;
-#endif /*FX_FILLMODE*/
-	return (newline);	       /* return pointer to data */
-}
-
-/* ASKCLR - Clears the echo area (but not immediately) if the last thing
-**	done to it was an ask() call.  Note that invoking a SAY routine
-**	specifically causes this to be a no-op; SAYCLR must be done instead.
-*/
-askclr()
-{
-	if(ask_cnt) sayclr();	/* Zap if need be */
-}
-
-
-/* SAY - put up some text on bottom line.
- *	Does this intelligently; text stays up until next SAY or
- *	screen refresh.
- * SAYNOW - like SAY but forces display right away
- * SAYTOO - adds to existing stuff
- * SAYNTOO - ditto but forces output right away.
- * DING - Ring_bell then SAYNOW 
- * DINGTOO - is to DING as SAYNTOO is to SAYNOW.
- * SAYCLR - Clears echo area (but not immediately)
- */
-#define SAY_NOW 01	/* Force display immediately */
-#define SAY_TOO 02	/* Add to existing stuff */
-#define SAY_BEL 04	/* Ding bell prior to text */
-#define SAY_LEN 010	/* String length specified by 3rd arg */
-
-say(str)	char *str; {	sayall(str, 0); }
-saynow(str)	char *str; {	sayall(str, SAY_NOW); }
-saytoo(str)	char *str; {	sayall(str, SAY_TOO); }
-sayntoo(str)	char *str; {	sayall(str, SAY_NOW|SAY_TOO); }
-ding(str)	char *str; {	sayall(str, SAY_NOW|SAY_BEL); }
-dingtoo(str)	char *str; {	sayall(str, SAY_NOW|SAY_TOO|SAY_BEL); }
-saylntoo(str,n)	char *str; {	sayall(str, SAY_NOW|SAY_TOO|SAY_LEN, n); }
-sayclr()		   {	sayall((char *)0, 0); }
-
-sayall(str,flags,len)
-char *str;
-int flags, len;
-{	register struct window *w;
-	register f;
-
-	f = flags;
-	w = cur_win;
-
-	ask_cnt = 0;			/* Always reset this */
-	if(str == 0 && ask_blen == 0)	/* If clearing, and buff empty */
-		return;			/* nothing to do. */
-	chg_win(ask_win);
-	if(f&SAY_TOO)
-		e_goeob();	/* Add to end of existing stuff */
-	else e_reset();		/* Flush previous stuff if any */
-	if(str)
-	  {	if(f&SAY_LEN)		/* Insert string to post up */
-			ed_nsins(str,len);
-		else e_sputz(str);
-	  }
-	ask_blen = e_dot();	/* Remember whether buffer has something */
-
-	e_setcur();		/* and remember to set dot */
-	if(f&SAY_NOW)
-	  {	if(f&SAY_BEL)
-			ring_bell();
-		redp(RD_WINRES);
-		upd_wind((struct window *)0);
-		tbufls();
-	  }
-	else redp(RD_WINRES);	/* Set for this window */
-	chg_win(w);		/* Back to previous window */
-
-	/* redisplay() does a special check for ask_win->w_redp, so we
-	** don't need to set a global flag like RD_CHKALL.
-	*/
-}
-
-
-/* YELLAT -- post string on specified line of screen, immediately.
- *	Differs from SAYNOW and SAYNTOO in that NO buffer
- *	manipulation is done; screen image is hacked directly.
- */
-
-yellat(str, line)
-char *str;
-register int line;
-{	register struct scr_line *s;
-
-	s = scr[line];
-	strncpy(s->sl_nlin, str, scr_wd0);
-	s->sl_ncol = strlen(str);
-#if IMAGEN
-	s->sl_flg |= SL_REDO;
-#endif
-	upd_line(line);
-	tbufls();
-}
-
-/* YELLTOO -- Append string to previous echo line of screen, immediately.
-**	Uses the ask_lin variable which is set by ask().
-**	Currently this function is only needed for srchint() in EESRCH.
-*/
-yelltoo(str)
-char *str;
-{	register int i;
-	register struct scr_line *s;
-	char nstr[MAXLINE];
-
-	s = scr[ask_lin];
-	i = s->sl_col;
-	nstr[0] = 0;
-	strncat(strncat(nstr, s->sl_line, i),	/* Make new string */
-			str, MAXLINE - i);
-	yellat(nstr, ask_lin);			/* Post it */
-}
-
-
-/* BARF - output a message on the bottom line of the screen,
-**	bypassing everything (window, buffer, screen image).
-**	Does NOT know about SAY's stuff and does not update it!
-**	Use only in dire straits...
-** ERRBARF - same but uses a standard error-message prefix.
-*/
-
-errbarf(str)
-char *str;
-{
-	barf("\007ELLE Internal Error: ");
-	tputz(str);
-	tbufls();
-}
-
-barf(str)
-char *str;
-{
-	ask_cnt = 0;			/* Ensure askclr() disabled */
-	t_curpos(scr_ht - ECHOLINES, 0);       /* goto echo area */
-	t_cleol();
-	tputz(str);
-	tbufls();
-	curs_col = -1000;	/* Say we dunno where cursor is now */
-}
-
-#if IMAGEN
-/* Same, but do it far from harm's way */
-barf2(str)
-char *str;
-{
-	t_curpos (scr_ht - 1, scr_wid - strlen(str) - 8);
-	t_cleol ();
-	tputz(str);
-	tputz(" --M--");
-	tbufls();
-	tgetc();			/* Read any char & discard */
-	curs_col = -1000;	/* Say we dunno where cursor is now */
-}
-#endif /*IMAGEN*/
Index: trunk/minix/commands/elle/eesigs.h
===================================================================
--- trunk/minix/commands/elle/eesigs.h	(revision 9)
+++ 	(revision )
@@ -1,32 +1,0 @@
-/* ELLE - Copyright 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/* EESIGS.H
- *	This file is only provided for inclusion only by V6 systems, where
- * the standard /usr/include/signal.h file may not exist and thus we
- * need to do our own definitions.
- */
-
-/* Signals marked with "*" cause a core image dump
- * if not caught or ignored. */
-
-#define	SIGHUP	1	/*   Hangup (eg dialup carrier lost) */
-#define	SIGINT	2	/*   Interrupt (user TTY interrupt) */
-#define	SIGQUIT	3	/* * Quit (user TTY interrupt) */
-#define	SIGILL	4	/* * Illegal Instruction (not reset when caught) */
-#define	SIGTRAP	5	/* * Trace Trap (not reset when caught) */
-#define	SIGIOT	6	/* * IOT instruction */
-#define	SIGEMT	7	/* * EMT instruction */
-#define	SIGFPE	8	/* * Floating Point Exception */
-#define	SIGKILL	9	/*   Kill (cannot be caught or ignored) */
-#define	SIGBUS	10	/* * Bus Error */
-#define	SIGSEGV	11	/* * Segmentation Violation */
-#define	SIGSYS	12	/* * Bad argument to system call */
-#define	SIGPIPE	13	/*   Write on a pipe with no one to read it */
-#define	SIGALRM	14	/*   Alarm Clock */
-#define	SIGTERM	15	/*   Software termination signal (from "kill" pgm) */
-
-#define	SIG_DFL	(int (*)())0	/* Arg to "signal" to resume default action */
-#define	SIG_IGN	(int (*)())1	/* Arg to "signal" to ignore this sig */
Index: trunk/minix/commands/elle/eesite.c
===================================================================
--- trunk/minix/commands/elle/eesite.c	(revision 9)
+++ 	(revision )
@@ -1,364 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/* EESITE	Site dependent frobs
- *	Primarily TS_ routines for TTY control.  Most site-dependent
- *	routine is TS_INP for detection of TTY input.
- */
-
-#include "elle.h"
-
-#if !(V6)
-#include <signal.h>	/* For SIGTSTP in ts_pause */
-#else
-#include "eesigs.h"
-#endif
-
-int tsf_pause = 0;	/* Set if ts_pause works.  Ref'd by equit in e_main */
-
-#if !(SYSV || BBN)	/* SYSV and BBN have weird tty calls */
-
-#if MINIX
-#include <termios.h>
-struct termios origterm, newterm;
-#else
-#if V6
-	/* Normal V6 declarations, must provide explicitly */
-struct sgttyb {
-	char sg_ispeed;
-	char sg_ospeed;
-	char sg_erase;
-	char sg_kill;
-	int sg_flags;
-};
-#define ECHO (010)
-#define CRMOD (020)
-#define RAW (040)
-#else
-	/* Normal V7 UNIX declarations, can use include file */
-#include <sgtty.h>
-#endif
-
-struct sgttyb nstate;	/* Both V6 and V7 */
-struct sgttyb ostate;	/* Both V6 and V7 */
-#endif /*!(SYSV || BBN)*/
-#endif /*!MINIX*/
-
-
-#if BBN		/* BBN system frobs */
-#include "/sys/sys/h/modtty.h"
-struct modes  nstate;
-struct modes  ostate;
-#endif /*BBN*/
-
-#if DNTTY		/* DN TTY frobs */
-#include <tty.h>
-char partab[2];		/* to satisfy obscene ref in tty.h */
-#endif /*DNTTY*/
-
-
-#if (UCB || TOPS20)		/* UCB, TOPS20 additional frobs */
-#include <sys/ioctl.h>		/* For ts_inp() and tldisc */
-#if IMAGEN
-struct tchars otchars, ntchars;	/* Original and new tchars */
-#endif /*IMAGEN*/
-#endif /*(UCB || TOPS20)*/
-
-#if SYSV		/* System V (and PC/IX) crocks */
-#include <termio.h>
-#include <sys/ioctl.h>
-
-struct termio	/* terminal i/o status flags */
-	origterm,	/* status of terminal at start of ELLE */
-	newterm;	/* status of terminal when using ELLE */
-#endif /*SYSV*/
-
-/* TS_INP
- *	Ask system if terminal input is available (on file descriptor 0).
- *	Returns non-zero if so, else returns zero.
- *	Very important that this call NOT hang or block in any way,
- *	because it is used to detect type-ahead by the user;
- *	return should be immediate whether or not input is waiting.
- */
-ts_inp()
-{
-#if BBN				/* Idiosyncratic */
-	int   cap_buf[2];
-	capac (0, &cap_buf[0], 4);
-	return (cap_buf[0]);
-#endif /*BBN*/
-
-#if (DNTTY || ONYX)		/* Have "empty()" syscall */
-	return(empty(0) ? 0 : 1);
-#endif /*DNTTY || ONYX*/
-#if (UCB || TOPS20)		/* Have FIONREAD ioctl */
-	long retval;
-	if(ioctl(0,FIONREAD,&retval))	/* If this call fails, */
-		return(0);		/* assume no input waiting */
-	return((retval ? 1 : 0));
-#endif /*UCB || TOPS20*/
-#if COHERENT
-	int retval;
-	ioctl(0, TIOCQUERY, &retval);
-	return((retval ? 1 : 0));
-#endif /*COHERENT*/
-#if VENIX86
-	struct sgttyb iocbuf;
-	ioctl(0, TIOCQCNT, &iocbuf);
-	return(iocbuf.sg_ispeed != 0 );
-#endif /*VENIX86*/
-
-#if !(BBN||COHERENT||DNTTY||ONYX||TOPS20||UCB||VENIX86)
-	return(0);		/* Default - never any type-ahead, sigh */
-#endif
-}
-
-
-/* TS_INIT()
- *	Get terminal information from system, initialize things for
- *	ts_enter and ts_exit.  This is called before t_init.
- *	Must set "trm_ospeed".
- */
-ts_init()
-{
-#if DNTTY
-	signal(16,1);		/* DN peculiar - turn off ctl-A */
-#endif /*DNTTY*/
-
-#if !(MINIX || SYSV || BBN)		/* Normal UNIX stuff */
-	ioctl(1, TIOCGETP, &ostate);	/* Remember old state */
-	nstate = ostate;		/* Set up edit-mode state vars */
-	nstate.sg_flags |= RAW;			/* We'll want raw mode */
-	nstate.sg_flags &= ~(ECHO|CRMOD);	/* with no echoing */
-	trm_ospeed = ostate.sg_ospeed;
-
-#if (IMAGEN && UCB)
-	/* Get around 4.1+ remote/local flow control bug (from Gosmacs) */
-	ioctl(0, TIOCGETC, &otchars);  /* Save original tchars */
-	ntchars = otchars;
-	ntchars.t_startc = -1;		/* Kill start/stop */
-	ntchars.t_stopc  = -1;
-	ioctl(0, TIOCSETC, &ntchars);
-#endif /*IMAGEN && UCB*/
-#endif /*!(SYSV || BBN)*/
-
-#if BBN
-	modtty(1, M_GET | M_MODES, &ostate, sizeof(ostate));	/* Save old */
-	modtty(1, M_GET | M_MODES, &nstate, sizeof(nstate));	/* Setup new */
-	nstate.t_erase = nstate.t_kill = nstate.t_intr = nstate.t_esc =
-		nstate.t_eof = nstate.t_replay = 0377;
-	nstate.t_quit = BELL;			/* ^G */
-	nstate.t_breaks = TB_ALL;		/* break on all */
-	nstate.t_iflags &= ~TI_ECHO & ~TI_NOSPCL & ~TI_CRMOD;
-				/* no echos, specials on, no CR -> LF*/
-	nstate.t_iflags |= TI_CLR_MSB;			/* ignore parity */
-	nstate.t_oflags &= ~TO_CRMOD & ~TO_AUTONL;	/* no CR -> NL */
-	if (trm_flags & NOXONOFF)
-		nstate.t_oflags &= ~TO_XONXOFF;
-	else
-		nstate.t_oflags |= TO_XONXOFF;   
-
-	nstate.t_oflags |= TO_CLR_MSB;		/* no special high bits */
-	nstate.t_pagelen = 0;			/* no paging of output */
-	trm_ospeed = ostate.t_ospeed;
-#endif /*BBN*/
-
-#if MINIX
-	tcgetattr(0, &origterm);	/* How things are now */
-	newterm = origterm;		/* Save them for restore on exit */
-
-	/* input flags */
-	newterm.c_iflag |= IGNBRK;	/* Ignore break conditions.*/
-	newterm.c_iflag &= ~INLCR;	/* Don't map NL to CR on input */
-	newterm.c_iflag &= ~ICRNL;      /* Don't map CR to NL on input */
-	newterm.c_iflag &= ~BRKINT;	/* Do not signal on break.*/
-	newterm.c_iflag &= ~IXON;	/* Disable start/stop output control.*/
-	newterm.c_iflag &= ~IXOFF;	/* Disable start/stop input control.*/
-
-	/* output flags */
-	newterm.c_oflag &= ~OPOST;	/* Disable output processing */
-
-	/* line discipline */
-	newterm.c_lflag &= ~ISIG;	/* Disable signals.*/
-	newterm.c_lflag &= ~ICANON;	/* Want to disable canonical I/O */
-	newterm.c_lflag &= ~ECHO;	/* Disable echo.*/
-	newterm.c_lflag &= ~ECHONL;	/* Disable separate NL echo.*/
-	newterm.c_lflag &= ~IEXTEN;	/* Disable input extensions.*/
-
-	newterm.c_cc[VMIN] = 1;		/* Min. chars. on input (immed) */
-	newterm.c_cc[VTIME] = 0;        /* Min. time delay on input (immed) */
-
-	/* Make it stick */
-	tcsetattr(0, TCSANOW, &newterm);
-#endif /*MINIX*/
-
-#if SYSV
-	ioctl(0, TCGETA, &origterm);	/* How things are now */
-	newterm = origterm;		/* Save them for restore on exit */
-
-	/* input flags */
-	newterm.c_iflag |= IGNBRK;	/* Ignore break conditions.*/
-	newterm.c_iflag &= ~INLCR;	/* Don't map NL to CR on input */
-	newterm.c_iflag &= ~ICRNL;      /* Don't map CR to NL on input */
-	newterm.c_iflag &= ~BRKINT;	/* Do not signal on break.*/
-	newterm.c_iflag &= ~IXON;	/* Disable start/stop output control.*/
-	newterm.c_iflag &= ~IXOFF;	/* Disable start/stop input control.*/
-
-	/* line discipline */
-	newterm.c_lflag &= ~ISIG;	/* Disable signals.*/
-	newterm.c_lflag &= ~ICANON;	/* Want to disable canonical I/O */
-	newterm.c_lflag &= ~ECHO;	/* Disable echo.*/
-
-	newterm.c_cc[4] = 1;		/* Min. chars. on input (immed) */
-	newterm.c_cc[5] = 1;	        /* Min. time delay on input (immed) */
-
-	/* Make it stick */
-	ioctl(0, TCSETA, &newterm);
-#endif /*SYSV*/
-
-#if (UCB || TOPS20)
-	{	int tldisc;
-		ioctl(0, TIOCGETD, &tldisc);	/* Find line discipline */
-
-/* The flag IGN_JOB_CONTROL has been introduced to allow job control haters
- * to simply ignore the whole thing.  When ELLE is compiled with
- * -DIGN_JOB_CONTROL, it will exit properly when the Return to Superior
- * command is executed.
-*/
-#if SIGTSTP
-#ifndef IGN_JOB_CONTROL
-		if(tldisc == NTTYDISC) tsf_pause = 1;
-#endif
-#endif /*SIGTSTP*/
-
-	}
-#endif /*UCB || TOPS20*/
-}
-
-/* TS_ENTER()
- *	Tell system to enter right terminal mode for editing.
- *	This is called before t_enter.
- */
-ts_enter()
-{
-#if !(MINIX || SYSV || BBN)
-	ioctl(1, TIOCSETP, &nstate);
-#if IMAGEN && UCB
-	ioctl(0, TIOCSETC, &ntchars);	/* Restore new tchars */
-#endif /*IMAGEN && UCB*/
-#endif /*!(SYSV||BBN)*/
-
-#if BBN
-	modtty (1, M_SET | M_MODES, &nstate, sizeof (nstate));
-#endif /*BBN*/
-
-#if MINIX
-	/* Make it behave as previously defined in ts_init */
-	tcsetattr(0, TCSANOW, &newterm);
-#endif /*SYSV*/
-
-#if SYSV
-	/* Make it behave as previously defined in ts_init */
-	ioctl(0, TCSETA, &newterm);
-#endif /*SYSV*/
-
-#if DNTTY	/* DN hackery!  Enable 8-bit input so as to read meta bit. */
-	if(dbg_isw)
-	  {	tpoke(TH_CSET,T_2FLGS2,EEI);	/* Enable ints */
-		tpoke(TH_CSETB,T_QUIT, 0377);	/* Turn off QUIT intrpt */
-	  }
-	else if(trm_flags & TF_METAKEY)
-		tpoke(TH_CSET,T_2FLGS2,T2_LITIN); /* Turn on 8-bit input! */
-#endif /*DNTTY*/
-}
-
-/* TS_EXIT
- *	Tell system to restore old terminal mode (we are leaving edit mode).
- *	This is called after t_exit.
- */
-ts_exit()
-{
-#if DNTTY
-	if(dbg_isw)
-		tpoke(TH_CCLR,T_2FLGS2,EEI);	/* Turn off EEI bit */
-	else if(trm_flags & TF_METAKEY)
-		tpoke(TH_CCLR,T_2FLGS2,T2_LITIN); /* Turn off 8-bit input */
-#endif /*DNTTY*/
-
-#if !(MINIX || SYSV || BBN)
-	ioctl(1, TIOCSETP, &ostate);	/* SYSV and BBN don't use stty */
-#if IMAGEN && UCB
-	ioctl(0, TIOCSETC, &otchars);	/* Restore original tchars */
-#endif /*IMAGEN && UCB*/
-#endif /*!(SYSV || BBN)*/
-
-#if BBN
-	modtty (1, M_SET | M_MODES, &ostate, sizeof (ostate));
-#endif /*BBN*/
-
-#if MINIX
-	tcsetattr(0, TCSANOW, &origterm);
-#endif /*MINIX*/
-
-#if SYSV
-	ioctl(0, TCSETA, &origterm);
-#endif /*SYSV*/
-}
-
-#if DNTTY
-int thkcmd[] { 0, 0, -1 };
-tpoke(cmd,bn,val)
-int cmd, bn, val;
-{
-	thkcmd[0] = cmd|bn;
-	thkcmd[1] = val;
-	if(ttyhak(0,&thkcmd) < 0)
-		return(-1);
-	else return(thkcmd[1]);
-}
-#endif /*DNTTY*/
-
-
-/* TS_PAUSE - Stop process and return control of TTY to superior.
- *	There is also a flag variable, TSF_PAUSE, which indicates
- *	whether or not this routine will actually do anything.
- */
-#if TOPS20
-#include <jsys.h>
-#endif
-
-ts_pause()
-{
-#if TOPS20
-	int acs[5];
-	jsys(HALTF, acs);
-#endif
-
-#if UCB
-#if SIGTSTP
-	signal(SIGTSTP, SIG_DFL);
-#if BSD4_2
-#define	mask(s)	(1 << ((s)-1))
-	sigsetmask(sigblock(0) &~ mask(SIGTSTP));
-#endif /*BSD4_2*/
-	kill(0, SIGTSTP);
-#if BSD4_2
-	sigblock(mask(SIGTSTP));
-#endif /*BSD4_2*/
-#endif /*SIGTSTP*/
-#endif /*UCB*/
-}
-
-ts_winsize()
-{
-#ifdef TIOCGWINSZ
-	struct winsize winsize;
-
-	if (ioctl(1, TIOCGWINSZ, &winsize) == 0) {
-		if (winsize.ws_row != 0) scr_ht = winsize.ws_row;
-		if (winsize.ws_col != 0) scr_wid = winsize.ws_col;
-	}
-#endif
-}
Index: trunk/minix/commands/elle/eesite.h
===================================================================
--- trunk/minix/commands/elle/eesite.h	(revision 9)
+++ 	(revision )
@@ -1,186 +1,0 @@
-/* ELLE - Copyright 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * EESITE.H	Site-dependent switches & definitions
- */
-
-/* CONDITIONAL COMPILATION SWITCHES */
-
-#define V6	0	/* Running on V6 system (else V7 assumed) */
-
-#define APOLLO 0	/* Running on an Apollo system */
-#define BBN	0	/* Running on BBN system (tty stuff) */
-#define BSD4_2	0	/* Running on 4.2BSD system */
-#define COHERENT 0	/* Running on Coherent IBM-PC system */
-#define DNTTY	0	/* Running on SRI V6 Deafnet system (tty stuff) */
-#define HPUX	0	/* Running on Hewlett-Packard System V + */
-#define MINIX	1	/* Running on MINIX (IBM-PC) system */
-#define ONYX	0	/* Running on ONYX Z8000 system */
-#define PCIX	0	/* Running on PC/IX (IBM-PC) system */
-#define SUN	0	/* Running on SUN workstation system */
-#define SYSV	0	/* Running on Unix System V (or perhaps Sys III) */
-#define TOPS20	0	/* Running on TOPS-20 KCC C implementation */
-#define UCB	0	/* Running on 2.8, 2.9, or 4.x BSD sys (tty stuff) */
-#define VENIX86 0	/* Running on Venix86 (IBM-PC) system */
-
-#define ICONOGRAPHICS 0 /* Using Iconographics configuration version */
-#define IMAGEN 0	/* Using Imagen configuration version */
-
-/* Resolve system dependencies */
-#if SUN
-#undef BSD4_2
-#define BSD4_2 1	/* SUN uses 4.2BSD */
-#endif
-
-#if BSD4_2
-#undef UCB
-#define UCB	1	/* 4.2 is special case of general UCB stuff */
-#endif /*BSD4_2*/
-
-#if (PCIX || HPUX)
-#undef SYSV
-#define SYSV	1	/* PC/IX & HP-UX are based on System III & V (resp) */
-#endif
-
-
-/* Set system or site dependent stuff here */
-
-#if V6
-#define void int	/* May need this for other systems too */
-#endif
-
-/* Changes to parameters (elle.h) or variable defaults (e_vinit.c) */
-
-#if COHERENT
-#define EVFNO2  0	/* "Old" filename postfix - use no old file! */
-#define EVFNN2 "+"	/* "New" filename postfix */
-#define TX_COHIBM 1	/* Ensure Coherent IBM-PC console support included */
-#endif /*COHERENT*/
-
-#if DNTTY
-#define EVLLEN 60	/* Short line length for TDDs */
-#endif /*DNTTY*/
-
-#if HPUX
-#define EVFNO2 "~"	/* Same as CCA Emacs.  Sorts last in listing. */
-#endif /*HPUX*/
-
-#if MINIX
-#define EVFNO2 ".bak"	/* "Old" filename postfix */
-#define EVMARKSHOW "Mark set"
-#define EVCCOL (33)	/* Use this as Comment Column */
-#define EVMVPCT 1	/* 1% - Try to use minimal window repositioning */
-#define EVMODWSO 1	/* Use mode window standout if can */
-#define STRERROR 1	/* Say that implementation provides strerror() */
-
-#include <sys/types.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-#endif /*MINIX*/
-
-#if ONYX
-#define STKMEM (4*512)		/* ONYX Z8000 seems to have less room avail */
-#endif /*ONYX*/
-
-#if BSD4_2
-#define FNAMELEN 255	/* Max size of last filename component */
-#define FNAMSIZ 400	/* Max size of complete filename */
-#endif /*BSD4_2*/
-
-#if TOPS20
-#define EVHELPFILE "elle:help.dat"	/* T20 ELLE help file */
-#define EVPROFBINFILE "ellep.b1"	/* T20 binary profile file */
-#define EVPROFTEXTFILE "ellep.e"	/* T20 ASCII profile file */
-#define EVFNO2 0	/* No old filename postfix (T20 has generations) */
-#define EVFNN2 0	/* No new filename postfix (T20 has generations) */
-#define FNAMELEN (40*3)	/* Max size of non-directory filename component */
-#define FNAMSIZ (40*5)	/* Max size of complete filename */
-#define STRERROR 1	/* Say that implementation provides strerror() */
-#endif /*TOPS20*/
-
-#if VENIX86
-#define TIBFSIZ 1	/* Venix86 block reads in raw mode */
-#endif /*VENIX86*/
-
-/* Configuration settings */
-
-#if ICONOGRAPHICS
-#define EVFNO2 "@"	/* "Old" filename postfix */
-#define EVMARKSHOW "Set."
-#define PARABLOCK 1	/* Values meaningful only for ICONOGRAPHICS */
-#define PARALINE  2
-#define TXC_VISBEL 1	/* Use visible bell if possible */
-#endif /*ICONOGRAPHICS*/
-
-#if IMAGEN
-#define EVFNO2 ".BAK"	/* "Old" filename postfix */
-#define EVMARKSHOW "Mark set"
-#define TOBFSIZ (10*80)	/* Size of TTY output buffer */
-#define ECHOLINES 2	/* Use 2 echo-area lines, not 1 */
-#define MAXARGFILES 10	/* Several startup filename args */
-#endif /*IMAGEN*/
-
-
-/* Now set any defaults for things not already defined */
-
-/* TERMINAL SUPPORT SWITCHES */
-/* 	Only those terminals which have a switch defined here	*/
-/*	will be included in ELLE's "hardwired" support.		*/
-/*	Switch name:	Compiles support for:			*/
-#ifndef TX_TERMCAP
-#define TX_TERMCAP 1	/*    *	- most TERMCAP-defined terminals */
-#endif
-#ifndef TX_H19
-#define TX_H19	1	/* "H19"	- Heath/Zenith-19 */
-#endif
-#ifndef TX_DM2500
-#define TX_DM2500 1	/* "DM2500","DM3025" - Datamedia 2500 */
-#endif
-#ifndef TX_COHIBM
-#define TX_COHIBM 0	/* "COHIBM"	- Coherent IBM-PC console */
-#endif
-#ifndef TX_TVI925
-#define TX_TVI925 0	/* "TVI925"	- TeleVideo 925 */
-#endif
-#ifndef TX_OM8025
-#define TX_OM8025 0	/* "OM8025"	- Omron 8025AG */
-#endif
-
-#ifndef TXC_VISBEL	/* Non-zero if want to use visible bell */
-#define TXC_VISBEL 0
-#endif
-
-/* Default terminal type string, used if ELLE cannot get type either
-** from $TERM or from startup args.
-*/
-#ifndef TXS_DEFAULT
-#define TXS_DEFAULT "H19"	/* Default terminal type string */
-#endif
-
-/* Combination parameter/switch definitions */
-
-/* STKMEM - System-dependent stack allocation crock, defines amount of
- *	stack memory to grab for general-purpose use.  This is mainly
- *	useful for PDP-11s or machines with similarly brain-damaged
- *	address space hardware.  A PDP-11 memory segment is 8K bytes,
- *	or 16 512-byte blocks, and the stack segment quarantines all of
- *	this space even though the actual stack may only use a miniscule
- *	portion of it.
- */
-
-/* Use this if compiling for a PDP11 system, otherwise leave undefined.. */
-#if (V6 || 0)
-#define STKMEM (8*512)		/* Use half a PDP11 segment */
-#endif
-
-/* These defaults are in eesite.h so ELLEC can get at them too. */
-#ifndef EVPROFBINFILE	/* Location of binary user profile, relative to HOME */
-#define EVPROFBINFILE ".ellepro.b1"
-#endif
-#ifndef EVPROFTEXTFILE	/* Location of ASCII user profile (used by ELLEC) */
-#define EVPROFTEXTFILE ".ellepro.e"
-#endif
Index: trunk/minix/commands/elle/eesrch.c
===================================================================
--- trunk/minix/commands/elle/eesrch.c	(revision 9)
+++ 	(revision )
@@ -1,277 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * EESRCH	Searching functions
- */
-
-#include "elle.h"
-#if !(V6)
-#include <signal.h>
-#else
-#include "eesigs.h"		/* Use this on V6 system */
-#endif /*V6*/
-
-/*
- *   Buffer String Search routines
- *
- *      If no search string is provided, a string that was previously
- *      used in the last search is once again used.
- */
-
-/* EFUN: "String Search" */
-f_srch()
-{	return (lin_search (0));
-}
-
-/* EFUN: "Reverse String Search" */
-f_rsrch()
-{	return (lin_search (1));
-}
-
-/* LIN_SEARCH - Main routine for non-incremental String Search.  Asks for
- *	a search string and looks for it.
- */ 
-lin_search (backwards)
-int  backwards;
-{	register char *mem;	/* item to be searched for */
-	register int res;
-	int srchint(), (*sav_srchalarm)();
-	char *srch_ask();
-	chroff savdot;
-
-	savdot = cur_dot;		/* Save original loc */
-
-#if ICONOGRAPHICS
-        if((mem = srch_ask(backwards ? "Reverse Search%s%s%s"
-                                     : "Search%s%s%s"))==0)
-                return;
-#else
-        if((mem = srch_ask(backwards ? "Reverse Search: " : "Search: "))==0)
-                return;
-#endif /*-ICONOGRAPHICS*/
-	sav_srchalarm = signal(SIGALRM,/*&*/srchint);	/* Handle timeout */
-	alarm(1);					/* One sec from now */
-
-	res = e_search(mem,srch_len,backwards);	/* Search for str! */
-
-	alarm(0);				/* Turn off alarm */
-	signal(SIGALRM,sav_srchalarm);		/* Restore old handler */
-
-	if(res)				/* Search won? */
-	  {	ed_setcur();
-		return;
-	  }
-
-	/* Search failed */
-	e_gosetcur(savdot);
-	ding("Search Failed");
-}
-
-srchint()
-{	yelltoo(" ...");
-}
-
-char *
-srch_ask(prompt)
-char *prompt;
-{	register char *ans, *old;
-
-#if ICONOGRAPHICS
-        if (srch_str)
-           ans = ask(prompt, " (", srch_str, "): ");
-        else ans = ask (prompt, ": ", "", "");
-        if (ans == 0) return (0);
-#else
-        if((ans = ask(prompt)) == 0)
-                return(0);              /* user punted ... */
-#endif /*-ICONOGRAPHICS*/
-	old = srch_str;
-	if (*ans == '\0')
-	  {	chkfree(ans);
-		if ((ans = old) == 0)		/* no string specified */
-		  {	dingtoo("Nothing to search for");
-			return(0);
-		  }
-#if !(ICONOGRAPHICS)
-		saylntoo(old, srch_len);	/* Show what old string is */
-#endif /*-ICONOGRAPHICS*/
-	  }
-	else
-	  {	if (old)
-			chkfree(old);	/* free up old srch string */
-		srch_str = ans;
-		srch_len = ask_len;
-	  }
-	return(ans);
-}
-
-
-#if 0
-	Incremental Search stuff.
-Description of EMACS behavior:
-	^Q quotes next char.
-	DEL cancels last char.  If this cancelled a match, point is moved
-		to previous match.
-	If not all of input can be found, it is not discarded.  Can rub out,
-		discard unmatched stuff with ^G, exit, etc.
-	^S repeats search forward; ^R repeats backward.
-		If empty string, either
-			changes direction (if not same)
-			or brings back previous string
-	ESC exits.  If empty string, changes to non-incremental string search.
-	^G of a winning search aborts, exits, and moves point back to origin.
-	^G of a failing search discards the input that wasn''t found.
-	Other C- or M- chars exit and are executed.
-ELLE also interprets ^H (BS) as DEL, because some keyboards make it hard to
-	type DEL and there is no way the user can
-	re-bind the incremental-search commands.
-#endif /*COMMENT*/
-
-#if FX_ISRCH
-/* EFUN: "Incremental Search" */
-f_isrch() { i_search(0); }
-#endif /*FX_ISRCH*/
-
-#if FX_RISRCH
-/* EFUN: "Reverse Search" */
-f_risrch() { i_search(1); }
-#endif /*FX_RISRCH*/
-
-#if FX_ISRCH || FX_RISRCH
-
-i_search(back)
-int back;		/* Current mode: 0 if forward, 1 if backward */
-{	register int c;
-	register int inpcnt;	/* # chars in current input srch str */
-	int inpgood;		/* Length of last winning string */
-	char inpstr[ISRCHLIM];	/* Holds current input search string */
-	chroff inpdot[ISRCHLIM];	/* Holds winning addrs for each */
-	struct window *savwin;
-	int winning;	/* 1 = currently winning, 0 = currently failing */
-	int pref, shown;
-	int f_insself(), (*(cmd_fun()))();
-
-	winning = 1;
-	inpcnt = 0;
-	inpgood = 0;
-	inpdot[0] = cur_dot;
-	savwin = cur_win;
-
-	/* Set up prompt and read all TTY input thus far */
-	shown = 0;
- sloop:	c = cmd_wait();		/* See if any command input waiting */
-	if(shown || !c)
-	  {	e_setcur();	/* Assume we moved around, so set cur_dot */
-		chg_win(ask_win);
-		ed_reset();	/* Flush contents & invoke redisplay */
-		ed_sins(back ? "R-search: " : "I-search: ");
-		ed_nsins(inpstr, inpcnt);
-		if(!winning) ed_sins("\t(FAILING)");
-		upd_wind((struct window *)0);	/* Force ask_win update */
-		if(c)
-		  {	upd_curs(cur_dot);
-			tbufls();
-		  }
-		chg_win(savwin);
-		shown = 1;	/* Say search prompt has been shown */
-	  }
-	if(!c)			/* If no user input waiting, show buffer */
-	  {	redp(RD_MOVE);		/* Cursor moved in window */
-		redisplay();
-	  }
-	c = cmd_read();		/* Get input char */
-	switch(c)
-	  {	case DEL:		/* Cancel last char */
-		case BS:		/* Hard to type DEL on some kbds */
-			if(inpcnt <= 0) goto sloop;
-			if(--inpcnt > inpgood) goto sloop;
-			winning = 1;
-			if(inpcnt == inpgood) goto sloop;
-			inpgood--;
-			ed_go(inpdot[inpcnt]);
-			goto sloop;
-
-		case CTRL('Q'):
-			c = cmd_read();	/* Quote next char */
-			break;
-		case CTRL('S'):
-			pref = 0;
-			goto ctlsr;
-		case CTRL('R'):
-			pref = 1;
-			goto ctlsr;
-
-		case CTRL('G'):
-			if(winning)
-			  {	ed_go(inpdot[0]);
-				goto sdone;
-			  }
-			inpcnt = inpgood;
-			winning = 1;
-			goto sloop;
-		case ESC:
-		case CR:
-			if(inpcnt)
-				goto sdone;
-			lin_search(back);
-			return;
-		default:
-			if(f_insself != cmd_fun(c))
-			  {	unrchf = c;
-				goto sdone;
-			  }
-		case TAB:	/* Strange self-inserting char */
-			break;
-	  }
-	if(inpcnt >= ISRCHLIM-1)
-	  {	ding("I-search str too long");
-		sleep(1);
-		goto sdone;
-	  }
-	inpstr[inpcnt++] = c;
-	if(!winning) goto sloop;
-
-	/* Now search for string.  (Arm alarm interrupt?) */
-	/* cur_dot has current location cursor is at; we want to back off
-	 * from this so a repeated search will find the same location if
-	 * appropriate. */
-	e_igoff(back ? inpcnt : -(inpcnt-1));
-dosrch:
-	winning = e_search(inpstr,inpcnt,back);
-	if (winning)
-	  {	inpgood = inpcnt;	/* Remember last win length */
-		inpdot[inpcnt] = e_dot();	/* and location */
-	  }
-	else e_gocur();			/* Back to start position */
-	goto sloop;
-
- ctlsr:	if (pref != back)
-	  {	back = pref;
-		if(inpcnt <= 0) goto sloop;
-	  }
-	if(inpcnt <= 0)
-	  {	if(!srch_str || (inpcnt = srch_len) <= 0)
-			goto sloop;
-		bcopy((SBMA)srch_str, (SBMA)inpstr, srch_len);
-		inpcnt = srch_len;
-		unrchf = c;		/* Repeat cmd after display */
-		shown = 1;		/* Force search-string display */
-		goto sloop;
-	  }
-	goto dosrch;
-
-  sdone:
-	if(srch_str) chkfree(srch_str);
-	srch_str = memalloc((SBMO)(inpcnt+1));
-	bcopy((SBMA)inpstr,(SBMA)srch_str,inpcnt);	/* Copy into srch_str */
-	srch_len = inpcnt;
-	e_setcur();
-	chg_win(ask_win);
-	ed_reset();
-	chg_win(savwin);
-	redp(RD_CHKALL);
-}
-#endif /*FX_ISRCH || FX_RISRCH*/
Index: trunk/minix/commands/elle/eeterm.c
===================================================================
--- trunk/minix/commands/elle/eeterm.c	(revision 9)
+++ 	(revision )
@@ -1,1300 +1,0 @@
-/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- *  EETERM	ELLE Terminal Driver.
- *	Directly supports DM2500, H-19, Omron 8025AG, Coherent/IBM-PC, TVI925.
- *	Others also supported if using TX_TERMCAP.
- */
-
-#include "elle.h"
-
-/* Define terminal indices (there may be holes but C preprocessor is too
- * stupid to let us close them).  Should be one TN_ definition for every
- * hardwired terminal type, even though whether or not it is actually
- * compiled depends on which TX_ switches are defined.
- */
-#define TN_TERMCAP 0
-#define TN_DM2500 1
-#define TN_H19	  2
-#define TN_OM8025 3
-#define TN_COHIBM 4	/* Coherent IBM-PC console */
-#define TN_TVI925 5
-
-#if TX_COHIBM && !(TX_H19)	/* Ensure H19 defined if COHIBM is. */
-#define TX_H19 1
-#endif
-
-#ifndef TXS_DEFAULT		/* If no default is explicitly specified */
-#define TXS_DEFAULT "H19"	/* Then settle for H-19 */
-#endif /*TXS_DEFAULT*/
-
-
-
-
-extern char *tv_stype;	/* If set, specifies terminal type */
-extern int tibfmsk;	/* Crock to mask off parity (meta) bit */
-static int tv_padc;	/* Pad character to use */
-static int tv_cspeed;	/* # msec per char (set from trm_ospeed) */
-static int tv_type;	/* Index of selected terminal type */
-
-/* Internal functions */
-static void tpadn(), tpad();
-
-/* Character speed table, indexed by system output speed value (0-017).
- * Value in table is 100 * <# msec used per character>.
- */
-static int cspdtab[] =
-{	/* Val    Idx Baud CPS  Time/char in msec */
-	0,	/*  0 Hangup -	----		*/
-	13333,	/*  1   50 7.5 133.33  (Baudot)	*/
-	10000,	/*  2   75  10 100.0   (Baudot)	*/
-	10000,	/*  3  110  10 100.0		*/
-	 8200,	/*  4 134.5 12.2 82.0 (IBM2741)	*/
-	 6666,	/*  5  150  15 	66.6666 	*/
-	 5000,	/*  6  200  20	50.0		*/
-	 3333,	/*  7  300  30	33.3333 	*/
-	 1666,	/*  8  600  60  16.6666 	*/
-	  833,	/*  9 1200 120   8.3333 	*/
-	  555,	/* 10 1800 180   5.5555 	*/
-	  416,	/* 11 2400 240   4.1666 	*/
-	  208,	/* 12 4800 480   2.0833		*/
-	  104,	/* 13 9600 960   1.04166	*/
-	0,	/* 14 Ext A  ?	 ?		*/
-	0	/* 15 Ext B  ?	 ?		*/
-};
-
-#if TX_TERMCAP
-/* Declarations for TERMCAP stuff.  Only EETERM knows about them. */
-
-/* Termcap routines */
-extern int tgetent(), tgetnum(), tgetflag(), tputs();
-extern char *tgetstr(), *tgoto();
-static int getcap();		/* Internal routines */
-static void putpad(), putnpad(), putpar();
-
-/* Gross disgusting externals that must be defined for TERMCAP rtns */
-char	PC;		/* Pad char */
-char	*BC;		/* Backspace to use, if not ^H */
-char	*UP;		/* Cursor up */
-short	ospeed;		/* Terminal output speed */
-
-/* Termcap numerical values/flags */
-static int
-	tc_am,		/* TRUE if has auto-wrap */
-	tc_km;		/* TRUE if meta key exists */
-
-/* Termcap capability strings we want to know about */
-
-struct tcap { char tcicod1, tcicod2, *tccap; };
-static struct tcap tcap[] = {
-#define TC_al	tcap[0].tccap	/* Add (insert) line */
-	{'a','l', 0},
-#define TC_AL	tcap[1].tccap	/* Add N lines */
-	{'A','L', 0},
-#define TC_bc	tcap[2].tccap	/* Backspace Char (for BC) */
-	{'b','c', 0},
-#define TC_ce	tcap[3].tccap	/* Erase to end of line (CLEOL) */
-	{'c','e', 0},
-#define TC_cl	tcap[4].tccap	/* Clear screen */
-	{'c','l', 0},
-#define TC_cm	tcap[5].tccap	/* Cursor motion */
-	{'c','m', 0},
-#define TC_dc	tcap[6].tccap	/* Delete char */
-	{'d','c', 0},
-#define TC_DC	tcap[7].tccap	/* Delete N chars */
-	{'D','C', 0},
-#define TC_dl	tcap[8].tccap	/* Delete line */
-	{'d','l', 0},
-#define TC_DL	tcap[9].tccap	/* Delete N lines */
-	{'D','L', 0},
-#define TC_dm	tcap[10].tccap	/* Delete mode on */
-	{'d','m', 0},
-#define TC_ed	tcap[11].tccap	/* Delete mode off */
-	{'e','d', 0},
-#define TC_ei	tcap[12].tccap	/* Insert mode off */
-	{'e','i', 0},
-#define TC_ia	tcap[13].tccap	/* Add line while in insert mode (see note) */
-	{'i','a', 0},
-#define TC_ic	tcap[14].tccap	/* Insert blank char */
-	{'i','c', 0},
-#define TC_IC	tcap[15].tccap	/* Insert N blank chars */
-	{'I','C', 0},
-#define TC_id	tcap[16].tccap	/* Delete line while in del mode (see note) */
-	{'i','d', 0},
-#define TC_im	tcap[17].tccap	/* Insert mode on */
-	{'i','m', 0},
-#define TC_ip	tcap[18].tccap	/* Padding to send after char insertion */
-	{'i','p', 0},
-#define TC_mm	tcap[19].tccap	/* String to set (turn on) meta-key mode */
-	{'m','m', 0},
-#define TC_mo	tcap[20].tccap	/* String to reset (turn off) meta-key mode */
-	{'m','o', 0},
-#define TC_pc	tcap[21].tccap	/* Pad Char (for PC) */
-	{'p','c', 0},
-#define TC_se	tcap[22].tccap	/* End standout mode */
-	{'s','e', 0},
-#define TC_so	tcap[23].tccap	/* Enter standout mode */
-	{'s','o', 0},
-#define TC_te	tcap[24].tccap	/* String to end programs that use termcap */
-	{'t','e', 0},
-#define TC_ti	tcap[25].tccap	/* String to beg programs that use termcap */
-	{'t','i', 0},
-#define TC_up	tcap[26].tccap	/* Move cursor up (for UP) */
-	{'u','p', 0},
-#define TC_vb	tcap[27].tccap	/* Visible bell */
-	{'v','b', 0},
-};
-#define NTCAPS ((sizeof(tcap))/(sizeof(struct tcap)))	/* # entries */
-
-/*
- * There are many other things that must be taken into account.
- * The termcap code here will probably not work for many termcap entries,
- * but the only sure way to find out which ones they are is to try them.
- */
-/* Note that the "ia" and "id" strings are not defined by the TERMCAP doc;
- * their usage here is derived from examining other TERMCAP-using programs.
- * Sigh!!!!
- */
-#endif /*TX_TERMCAP*/
-
-
-/* T_INIT is called once only at program startup, to identify the
- *	terminal type and set up any one-time things.
- * T_FATAL is only called if some routine detects an error related to the
- *	terminal specification, before any initialization is done.
- *	It prints a short error message and exits the program.
- * T_ENTER is called after TS_ENTER to set the terminal parameters for
- *	editing (as opposed to normal typeout).  It may be called
- *	several times.
- * T_EXIT is called before TS_EXIT to restore normal typeout modes.
- *	It is called on exit from the program, and perhaps other times.
- */
-t_init()
-{
-	char *getenv();
-
-	/* Set some default parameters */
-	scr_ht = 24;
-	scr_wid = 79;
-	trm_flags = 0;
-	tvc_cin = 1;		/* Assume 1 char per char I/D pos */
-	tvc_cdn = 1;
-	tvc_pos = 4;		/* Default abs-move cost is 4 chars */
-	tvc_bs = 1;		/* Default backspace cost is 1 char */
-	tv_cspeed = cspdtab[trm_ospeed];	/* Find # msec per char */
-
-	/* First must determine terminal type, and check for terminals
-	 * that are hardwired into ELLE. */
-	if(!tv_stype		/* String set in command line args? */
-#if !(V6)
-	 && !(tv_stype = getenv("TERM"))	/* or given by TERM var? */
-#endif /*-V6*/
-		) tv_stype = TXS_DEFAULT;	/* No, try using default */
-	if(0) ;			/* Sigh, stupid construct */
-#if TX_H19
-	else if(ustrcmp(tv_stype,"H19")) tv_type = TN_H19;
-#endif /*TX_H19*/
-#if TX_OM8025
-	else if(ustrcmp(tv_stype,"OM8025")) tv_type = TN_OM8025;
-#endif /*TX_OM8025*/
-#if TX_DM2500
-	else if(ustrcmp(tv_stype,"DM2500")) tv_type = TN_DM2500;
-	else if(ustrcmp(tv_stype,"DM3025")) tv_type = TN_DM2500;
-#endif /*TX_DM2500*/
-#if TX_COHIBM
-	else if(ustrcmp(tv_stype,"COHIBM")) tv_type = TN_COHIBM;
-#endif /*TX_COHIBM*/
-#if TX_TVI925
-	else if(ustrcmp(tv_stype,"TVI925")) tv_type = TN_TVI925;
-#endif /*TX_TVI925*/
-#if TX_TERMCAP	/* This should be last thing */
-	else if(getcap(tv_stype)) tv_type = TN_TERMCAP;
-#endif /*TX_TERMCAP*/
-	else t_fatal("type unknown");	/* Ugh, barf and exit */
-
-	/* Terminal selected, now initialize parameters for it. */
-	switch(tv_type)
-	  {
-#if TX_DM2500
-		case TN_DM2500:
-			tv_padc = 0177;		/* Use rubout for pad */
-			tvc_pos = 3;		/* Only 3 chars for abs mov */
-			tvc_ci = 2;
-		/*	tvc_cin = 1; */		/* Default is OK */
-			tvc_cd = 2;
-		/*	tvc_cdn = 1; */		/* Default is OK */
-			tvc_ld = 2;
-			tvc_ldn = 1;
-			tvc_li = 2;
-			tvc_lin = 1;
-			if(trm_ospeed == 13)	/* If 9600, */
-			  {	tvc_cin = 5;		/* Sigh, high cost */
-				tvc_cdn = 2;
-				tvc_lin = 18;
-				tvc_ldn = 2;
-			  }
-			trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL|TF_METAKEY;
-			break;
-#endif /*TX_DM2500*/
-#if TX_H19
-		case TN_H19:			
-			trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL;
-			tvc_ci = 8;
-		/*	tvc_cin = 1; */	/* default is ok */
-			tvc_cd = 0;
-			tvc_cdn = 2;
-		/*	tvc_ld = 0; */	/* Default is OK */
-			tvc_ldn = 1 << (trm_ospeed - 7);
-		/*	tvc_li = 0; */	/* Default is OK */
-			tvc_lin = tvc_ldn;
-			break;
-#endif /*TX_H19*/
-#if TX_COHIBM
-		case TN_COHIBM:
-			trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL|TF_METAKEY|TF_DIRVID;
-			/* Always use lowest possible costs */
-		/*	tvc_ci = 0; */	/* Default */
-			tvc_cin = 2;
-		/*	tvc_cd = 0; */	/* Default */
-			tvc_cdn = 2;
-		/*	tvc_ld = 0; */	/* Default */
-			tvc_ldn = 2;
-		/*	tvc_li = 0; */	/* Default */
-			tvc_lin = 2;
-			break;
-#endif /*TX_COHIBM*/
-#if TX_OM8025
-		case TN_OM8025:
-			trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL;
-			tvc_pos = 6;
-		/*	tvc_ci = tvc_cd = 0; */	/* Default */
-			tvc_cin = 4;
-			tvc_cdn = 2;
-		/*	tvc_ld = tvc_li = 0; */	/* Default */
-			tvc_ldn = 10;		/* Crude approx */
-			tvc_lin = 10;
-			if(trm_ospeed > 7)	/* If faster than 300 baud */
-				trm_flags &= ~TF_IDLIN;	/* Turn off LID */
-			break;
-#endif /*TX_OM8025*/
-#if TX_TVI925
-		case TN_TVI925:
-			trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL;
-			tvc_ci = tvc_cd = tvc_cin = tvc_cdn
-				= tvc_ldn = tvc_lin = 2;
-			break;
-#endif /*TX_TVI925*/
-	  }
-	if(tibfmsk < 0)		/* If mask is still default -1, set it. */
-		tibfmsk = ((trm_flags&TF_METAKEY) ? 0377 : 0177);
-}
-
-/* T_FATAL(str) - prints error message and exits.
-*/
-t_fatal(str)
-char *str;
-{	writerr("ELLE: \"");
-	writerr(tv_stype);
-	writerr("\" terminal ");
-	writerr(str);
-	writerr("\n");
-	exit(1);		/* Terminate with prejudice */
-}
-
-
-/* T_ENTER is called after TS_ENTER to set the terminal parameters for
- *	editing (as opposed to normal typeout).
- *	Standout mode must initially be off.
- */
-
-t_enter()
-{	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-                        putpad(TC_ti);
-			if(tc_km) putpad(TC_mm);	/* Use meta if poss */
-#if FX_SOWIND
-			t_standout(0);		/* Ensure standout mode off */
-#endif
-			break;
-#endif /*TX_TERMCAP*/
-#if TX_DM2500
-		case TN_DM2500:
-			tput(030);	/* Just in case, flush stray modes */
-			break;
-#endif /*TX_DM2500*/
-#if TX_COHIBM
-		case TN_COHIBM:		/* Note TN_H19 will exist too */
-#endif /*TX_COHIBM*/
-#if TX_H19
-		case TN_H19:
-			/* Enter ZDS (Heath) mode, then
-			 * Exit graphics mode (G) Exit ins-char mode (O)
-			 * exit rev video mode (q) exit hold-screen mode (\)
-			 * set cursor on (y5)
-			 */
-			tputz("\033[?2h\033G\033O\033q\033\\\033y5");
-			/* Set Discard-at-EOL (w)
-			 * Set no auto-CR (y9)
-			 * Enable 25th line (x1)
-			 */
-			tputz("\033w\033y9\033x1");
-			break;
-#endif /*TX_H19*/
-	  }
-}
-
-
-/* T_EXIT - Leave editing modes.  This function should restore
-**	the terminal's modes to what they were before ELLE was started.
-**	Standout mode is turned off.
-*/
-
-t_exit()
-{
-	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-			if(tc_km) putpad(TC_mo);	/* Turn off meta */
-			putpad(TC_te);
-			break;
-#endif /*TX_TERMCAP*/
-#if TX_DM2500
-		case TN_DM2500:
-			tput(035);	/* Turn on roll mode */
-			break;
-#endif /*TX_DM2500*/
-#if TX_COHIBM
-		case TN_COHIBM:		/* If this exists, TN_H19 will too */
-#endif /*TX_COHIBM*/
-#if TX_H19
-		case TN_H19:
-			tputz("\033v");		/* Turn EOL-wrap back on */
-#if DNTTY
-			tputz("\033<");		/* Return to ANSI mode */
-#endif /*DNTTY*/
-			break;
-#endif /*TX_H19*/
-	  }
-}
-
-
-/* T_CLEAR() - Clears the screen and homes the cursor.
- *	Always valid - ELLE refuses to support terminals without this.
- */
-
-t_clear ()
-{	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-			putnpad(TC_cl,scr_ht);
-			break;
-#endif /*TX_TERMCAP*/
-#if TX_DM2500
-		case TN_DM2500:
-			tputz("\036\036");	/* Double Master Clear */
-			break;
-#endif /*TX_DM2500*/
-#if TX_COHIBM
-		case TN_COHIBM:		/* Note TN_H19 will exist too */
-#endif /*TX_COHIBM*/
-#if TX_H19
-		case TN_H19:
-			tputz("\033E");
-		/*	tputn(zpadstr,9);	*/
-			break;
-#endif /*TX_H19*/
-#if TX_OM8025
-		case TN_OM8025:
-			tputz("\033H\033J");	/* Home then CLEOS */
-			tpad(1000);		/* One second!!!! */
-			break;
-#endif /*TX_OM8025*/
-#if TX_TVI925
-		case TN_TVI925:
-			tput(032);	/* ^Z */
-			break;
-#endif /*TX_TVI925*/
-	  }
-	curs_lin = curs_col = 0;
-}
-
-
-/* T_CURPOS(y, x) - Absolute move.  Place cursor in given position
- *	regardless of where it currently is.
- *	Updates curs_lin, curs_col.
- *	Always valid -- ELLE refuses to support terminals without this.
- */
-
-t_curpos (lin, col)
-register int lin, col;
-{
-	if(col > scr_wid)		/* Easiest to catch here */
-		col = scr_wid;
-
-	/* Do absolute positioning */
-	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-			putpad(tgoto(TC_cm, col, lin));
-			break;
-#endif /*TX_TERMCAP*/
-#if TX_DM2500
-		case TN_DM2500:
-			tput(014);
-			tput(col^0140);
-			tput(lin^0140);
-			break;
-#endif /*TX_DM2500*/
-#if TX_COHIBM
-		case TN_COHIBM:		/* If this exists, TN_H19 will too */
-#endif /*TX_COHIBM*/
-#if TX_H19
-		case TN_H19:
-			tputz("\033Y");
-			tput(lin+040);
-			tput(col+040);
-			break;
-#endif /*TX_H19*/
-#if TX_OM8025
-		case TN_OM8025:
-			tputz("\033\175");
-			tput(0100+((lin+1)>>4));
-			tput(0100+((lin+1)&017));
-			tput(0100+((col+1)>>4));
-			tput(0100+((col+1)&017));
-			break;
-#endif /*TX_OM8025*/
-#if TX_TVI925
-		case TN_TVI925:
-			tputz("\033=");
-			tput(lin+040);
-			tput(col+040);
-			break;
-#endif /*TX_TVI925*/
-	  }
-	curs_lin = lin;
-	curs_col = col;
-}
-
-/* T_BACKSPACE() - Back up 1 character position.
- *	Updates curs_col.
- *	Only valid if tvc_bs has a "reasonable" value ( < 1000)
- */
-
-t_backspace()
-{
-#if TX_TERMCAP
-	if(BC) tputz(BC);	/* Use alternate BS */
-	else
-#endif
-	tput('\010');		/* Send BS */
-	--curs_col;
-}
-
-/* T_BELL() - Ring terminal's bell (or flash something, or whatever).
- *	Forces out all output thus far, to ensure immediate attention.
- *	This used to be an unbuffered feep, but was changed to use normal
- *	output path in order to avoid messing up terminal escape sequences.
- */
-t_bell()
-{
-#if TXC_VISBEL && TX_TERMCAP
-	if(TC_vb)
-	        tputz(TC_vb);		/* Do visible bell if possible */
-	else
-#endif
-        tput(BELL);
-        tbufls();       /* Force it out */
-}
-
-
-/* T_CLEOL() - Clear to End Of Line.
- *	Only valid if trm_flags has TF_CLEOL set.
- */
-
-t_cleol ()
-{
-	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-			putpad(TC_ce);
-			break;
-#endif /*TX_TERMCAP*/
-#if TX_DM2500
-		case TN_DM2500:
-			tput(027);
-			break;
-#endif /*TX_DM2500*/
-#if TX_COHIBM
-		case TN_COHIBM:		/* If this exists, TN_H19 will too */
-#endif /*TX_COHIBM*/
-#if TX_H19
-		case TN_H19:
-			tputz("\033K");
-			break;
-#endif /*TX_H19*/
-#if TX_OM8025
-		case TN_OM8025:
-			tputz("\033K");
-			tpad(41);	/* 1/25 sec padding */
-			break;
-#endif /*TX_OM8025*/
-#if TX_TVI925
-		case TN_TVI925:
-			tputz("\033T");
-			break;
-#endif /*TX_TVI925*/
-	  }
-}
-
-
-/* T_INSLIN(n, bot) - Insert lines in window.
- *	n   - # blank lines to insert.
- *	bot - # of last line of current window
- *
- *		The current line is moved down and N blank lines inserted.
- *	Lines which are moved past bot are lost.
- *	May leave cursor in random place.
- *	Only valid if trm_flags has TF_IDLIN set.
- */
-
-t_inslin (n, bot)
-int   n;			/* number of lines */
-int   bot;			/* line number of last line in window */
-{	register  i, j;
-	int savc,savl;
-
-	if((i = n) <= 0) return;
-	if(bot < (scr_ht-1))
-	  {	savc = curs_col;
-		savl = curs_lin;
-		t_curpos(bot-i, 0);
-		t_dellin(i, scr_ht);
-		t_curpos(savl, savc);
-	  }
-	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-			if(TC_AL)
-				putpar(TC_AL, i, i);
-			else if(TC_ia)
-			  {	putpad(TC_im);
-				do { putpad(TC_ia);
-				  } while(--i);
-				putpad(TC_ei);
-			  }
-			else
-				do { putnpad(TC_al, scr_ht - curs_lin);
-				  } while(--i);
-			break;
-#endif /*TX_TERMCAP*/
-#if TX_DM2500
-		case TN_DM2500:
-			tput(020);		/* Enter I/D mode */
-			do {	tput(012);		/* Insert line */
-			  	switch(trm_ospeed)
-				  {	case 13: j = 17; break;	/* 9600 */
-					case 12: j = 8; break;	/* 4800 */
-					case 11: j = 4; break;	/* 2400 */
-					case 9:  j = 2; break;	/* 1200 */
-					default: j = 0; break;
-				  }
-				tpadn(j);
-			  } while(--i);
-			tput(030);			/* Exit I/D mode */
-			break;
-#endif /*TX_DM2500*/
-#if TX_H19
-	/* NOTE: H19 supposedly requires 19 ms for each line during line I/D
-	 * operations.
-	 * In actual practice, at 9600 baud 25 pads are necessary (24 wont work!)
-	 * for both I and D.  Plus esc-E needs 9 pads.
-	 */
-		case TN_H19:
-			do {	tputz("\033L");
-				switch(trm_ospeed)
-				  {	case 13: j = 25; break;
-					case 9:	j = 4; break;
-					case 7: j = 1; break;
-					default: j = 0; break;
-				  }
-				tpadn(j);
-			  } while(--i);
-			break;
-#endif /*TX_H19*/
-#if TX_COHIBM
-		case TN_COHIBM:
-			do {	tputz("\033L");  /* no padding required */
-		  	  } while(--i);
-			break;
-#endif /*TX_COHIBM*/
-#if TX_OM8025
-		case TN_OM8025:
-			do {	tputz("\033L");
-				tpad(100*(scr_ht - curs_lin));	/* .1 per moved line*/
-			  } while(--i);
-			break;
-#endif /*TX_OM8025*/
-#if TX_TVI925
-		case TN_TVI925:
-			do tputz("\033E");
-			while(--i);
-			break;
-#endif /*TX_TVI925*/
-	  }
-}
-
-
-/* T_DELLIN(n, bot) - Delete lines from window.
- *	n   - # lines to delete.
- *	bot - # of last line of current window.
- *		The current line, and N-1 following lines, are deleted.
- *	Blank lines are inserted past bot.
- *	Cursor should be left at original position.
- *	Only valid if trm_flags has TF_IDLIN set.
- */
-t_dellin (n, bot)
-int   n;			/* number of lines */
-int   bot;			/* line number of last line in window */
-{	register  i, j;
-	int savl, savc;
-
-	if((i = n) <= 0) return;
-	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-			if(TC_DL)
-				putpar(TC_DL, i, i);
-			else if(TC_id)
-			  {	putpad(TC_dm);
-				do putpad(TC_id);
-				while(--i);
-				putpad(TC_ed);
-			  }
-			else
-				do { putnpad(TC_dl,scr_ht - curs_lin);
-				  } while(--i);
-
-			break;
-#endif /*TX_TERMCAP*/
-#if TX_DM2500
-		case TN_DM2500:
-			tput(020);
-			do {	tput(032);
-			  	if(trm_ospeed >= 13)	/* 9600 */
-					tput(0177);
-			  } while(--i);
-			tput(030);
-			break;
-#endif /*TX_DM2500*/
-#if TX_H19
-		case TN_H19:
-			do {	tputz("\033M");
-				switch(trm_ospeed){
-					case 13: j = 25; break;
-					case 9:	j = 4; break;
-					case 7: j = 1; break;
-					default: j = 0; break;
-					}
-				tpadn(j);
-			  } while(--i);
-			break;
-#endif /*TX_H19*/
-#if TX_COHIBM
-		case TN_COHIBM:
-			do {	tputz("\033M");	  /* no padding required */
-			  } while(--i);
-			break;
-#endif /*TX_COHIBM*/
-#if TX_OM8025
-		case TN_OM8025:
-			do {	tputz("\033M");
-				tpad(100*(scr_ht - curs_lin));
-			  } while(--i);
-			break;
-#endif /*TX_OM8025*/
-#if TX_TVI925
-		case TN_TVI925:
-			do {	tputz("\033R");
-			  } while(--i);
-			break;
-#endif /*TX_TVI925*/
-	  }
-	if(bot < (scr_ht-1))
-	  {	savl = curs_lin;
-		savc = curs_col;
-		t_curpos(bot-n,0);
-		t_inslin(n,scr_ht);
-		t_curpos(savl,savc);
-	  }
-}
-
-
-/* T_INSCHR(n, str) - Insert n chars in current line
- *	n   - # characters to insert
- *	str - Pointer to char string.  If 0, insert spaces.
- *
- *	Insert N characters from string str at current position.
- *	The cursor may move but curs_col must be updated.
- *	Only valid if trm_flags has TF_IDCHR set.
- */
-t_inschr(n, str)
-int n;
-char *str;
-{	register int i;
-	register char *cp;
-
-	if((i = n) <= 0) return;
-	cp = str;
-	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-			putpad(TC_im);		/* Go into insert mode */
-			if(TC_IC)
-			  {	putpar(TC_IC, i, 1);
-				if(cp) tputn(cp, i);
-				else do tput(SP); while(--i);
-			  }
-			else do {
-				if(TC_ic) putpad(TC_ic);
-				if(cp) tput(*cp++);
-				else tput(SP);
-				if(TC_ip) putpad(TC_ip);
-			  } while(--i);
-			putpad(TC_ei);		/* Exit insert mode */
-			curs_col += n;
-			break;
-#endif /*TX_TERMCAP*/
-#if TX_COHIBM
-		case TN_COHIBM:		/* If this exists, TN_H19 will too */
-#endif /*TX_COHIBM*/
-#if TX_H19
-		case TN_H19:
-			tputz("\033@");		/* Enter ins char mode */
-			do {	if(cp) tput(*cp++);
-				else tput(SP);
-			  } while(--i);
-			tputz("\033O");		/* Exit ins char mode */
-			curs_col += n;
-			break;
-#endif /*TX_H19*/
-#if TX_DM2500
-		case TN_DM2500:
-			tput(020);		/* Enter I/D mode */
-			if(trm_ospeed == 13)	/* 9600 baud lossage */
-			  {	do {
-					tputz(" \177");	/* SP and DEL */
-				  } while(--i);
-				tput(030);
-				i = n;
-				if(i < 3)	/* If close enough, */
-					tputn("\010\010", i);	/* use BSes */
-				else t_curpos(curs_lin, curs_col);
-			  }
-			else			/* Not 9600, can win */
-			  {	do { tput(034);
-				  } while(--i);
-				tput(030);
-				if(cp == 0) return;
-				i = n;
-			  }
-
-			do {	if(cp) tput(*cp++);
-				else tput(SP);
-			  } while(--i);
-			curs_col += n;
-			break;
-#endif /*TX_DM2500*/
-#if TX_OM8025
-		case TN_OM8025:
-			do {
-				tputz("\033@");
-				if(cp) tput(*cp++);
-				else tput(SP);
-			  } while(--i);
-			curs_col += n;
-			break;
-#endif /*TX_OM8025*/
-#if TX_TVI925
-		case TN_TVI925:
-			do {	tputz("\033Q");
-			  } while(--i);
-			if(cp)
-			  {	tputn(cp, n);
-				curs_col += n;
-			  }
-			break;
-#endif /*TX_TVI925*/
-	  }
-}
-
-
-/* T_DELCHR(n) - Delete N chars in current line.
- *	Deletes the N characters to the right of the cursor.  Remaining
- *	chars are shifted left.  The cursor should not move.
- *	Only valid if trm_flags has TF_IDCHR set.
- */
-t_delchr(n)		/* Delete N chars at current loc */
-int n;
-{	register int i;
-
-	if((i = n) <= 0) return;
-	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-			putpad(TC_dm);	/* Enter delete mode */
-			if(TC_DC)
-				putpar(TC_DC, i, 1);
-			else do {	/* Delete char while in del mode */
-				putpad(TC_dc);
-			} while(--i);
-			putpad(TC_ed);	/* Exit delete mode */
-			break;
-#endif /*TX_TERMCAP*/
-#if TX_COHIBM
-		case TN_COHIBM:		/* If this exists, TN_H19 will too */
-#endif /*TX_COHIBM*/
-#if TX_H19
-		case TN_H19:
-			do tputz("\033N");
-			while(--i);
-			break;
-#endif /*TX_H19*/
-#if TX_DM2500
-		case TN_DM2500:
-			tput(020);		/* Enter I/D mode */
-			do if(trm_ospeed == 13)	/* 9600? */
-				tputz("\010\177");	/* BS and DEL */
-			  else tput(010);
-			while(--i);
-			tput(030);		/* Exit I/D mode */
-			break;
-#endif /*TX_DM2500*/
-#if TX_OM8025
-		case TN_OM8025:
-			do tputz("\033P");
-			while (--i);
-			break;
-#endif /*TX_OM8025*/
-#if TX_TVI925
-		case TN_TVI925:
-			do {	tputz("\033W");
-			  } while(--i);
-#endif /*TX_TVI925*/
-	  }
-}
-
-
-#if FX_SOWIND
-
-/* T_STANDOUT(n) - Enter or leave standout mode.
- *	n   - 0 to return to normal display mode,
- *	      1 to enter standout display mode.
- *		This is usually reverse video but may be something else.
- *
- *	Only valid if trm_flags has TF_SO set.
- */
-
-t_standout(on)
-int on;
-{
-	switch(tv_type)
-	  {
-#if TX_TERMCAP
-		case TN_TERMCAP:
-			putpad(on ? TC_so : TC_se);
-			break;
-#endif /*TX_TERMCAP*/
-
-#if TX_COHIBM
-		case TN_COHIBM:		/* Note TN_H19 will exist too */
-#endif /*TX_COHIBM*/
-#if TX_H19
-		case TN_H19:
-			tputz(on ? "\033p" : "\033q");
-			break;
-#endif /*TX_H19*/
-	  }
-}
-#endif /*FX_SOWIND*/
-
-
-
-/* TPADN(n) - Output N pad chars.
- */
-static void
-tpadn(n)
-int n;
-{	register int i, pad;
-	if((i = n) > 0)
-	  {	pad = tv_padc;
-		do { tput(pad);
-		  } while(--i);
-	  }
-}
-
-/* TPAD(msec) - Output padding for given # of milliseconds.
- */
-static void
-tpad(n)
-int n;
-{	register int i, i2;
-
-	i = n;
-	while(i > 0)
-	  {	if((i2 = 320) < i)	/* So can use integers */
-			i2 = i;
-		i -= i2;
-		i2 *= 100;
-		while((i2 -= tv_cspeed) > 0)
-			tput(tv_padc);
-	  }
-}
-#if TX_TERMCAP
-/*
- * Print the string str, interpreting padding.
- */
-int tput();	/* Our output function */
-static void
-putpad(str)
-char *str;
-{	if(str) tputs(str, 1, tput);	/* Invoke TERMCAP function */
-}
-static void
-putnpad(str,n)
-char *str;
-int n;
-{	if(str) tputs(str, n, tput);
-}
-static void
-putpar(str, par, n)		/* Wish we had tparm() */
-char *str;
-int par,n;
-{	putnpad(tgoto(str, 0, par), n);
-}
-#endif /*TX_TERMCAP*/
-
-
-/*
- * Read in the stuff from termcap upon startup.
- */
-
-#if TX_TERMCAP
-static int tstrlen(), tstrlp();
-
-#ifndef TCAPSLEN
-#define TCAPSLEN 1024	/* Default size of buffer for TERMCAP strings */
-#endif /*-TCAPSLEN*/
-
-static int
-getcap(stype)
-char *stype;
-{	register char *t;
-	register int i;
-	int buflen;
-	char *tcbuf, *tcbptr;		/* Pointers into termcap buffer */
-	char tmpstr[4];
-	char tmpbuf[TCAPSLEN];		/* Allocate from stack */
-	char *malloc();
-	char *realloc();
-
-	/* First see if can find the terminal type. */
-	if((tgetent(tmpbuf, stype)) != 1)
-		return(0);
-
-	/* Found it!  Set up a string buffer to save the caps. */
-	if(!(tcbuf = malloc(TCAPSLEN)))	/* Get permanent buffer */
-		t_fatal(" - cannot allocate termcap buffer");
-	tcbptr = tcbuf;
-
-	/* Now gobble all the string caps that ELLE wants to know about. */
-	tmpstr[3] = '\0';
-	i = NTCAPS;
-	do {
-		tmpstr[0] = tcap[i].tcicod1;	/* Make str of the code */
-		tmpstr[1] = tcap[i].tcicod2;
-		tcap[i].tccap = tgetstr(tmpstr, &tcbptr);	/* Get cap */
-	} while(--i);
-	buflen = tcbptr - tcbuf;	/* String buffer done, finalize */
-	if(buflen >= TCAPSLEN)
-		t_fatal("description too big!");
-	realloc(tcbuf, buflen);		/* Free up unused part of buffer */
-					/* (this better not move it!!!) */
-
-	/* Now get the number/flag stuff that ELLE needs. */
-	tc_am = tgetflag("am");		/* auto wrap */
-	if (tgetflag("xn")) tc_am = 0;	/* auto wrap at 81st char, nice! */
-	tc_km = (tgetflag("km")		/* TTY has meta key */
-		|| tgetflag("MT"));	/* Alternate version of "km"?? */
-	scr_ht = tgetnum("li");		/* Set screen height (# lines) */
-	scr_wid = tgetnum("co");	/* Set screen width (# cols) */
-	ts_winsize();
-
-	/* Now initialize the stupid external vars that TERMCAP rtns want. */
-	if(TC_pc) PC = *TC_pc;	/* Pad char */
-	BC = TC_bc;		/* Backspace str (if no BS) */
-	UP = TC_up;		/* Cursor up */
-	ospeed = trm_ospeed;	/* Put output speed here */
-
-
-	/* Basic data extracted, now mull over it and set the remaining
-	 * ELLE variables
-	 */
-#if FX_SOWIND
-	if(tgetnum("sg") <= 0)		/* If no magic cookie problems */
-	  {	if (TC_so && TC_se)	/* And have standout caps, */
-			trm_flags |= TF_SO;	/* Say has standout cap */
-	  }
-#endif
-
-	if (!(TC_cm && TC_cl))
-		t_fatal("lacks cursor addressing or clear screen.");
-	tvc_pos = tstrlen(TC_cm);		/* Find cost of abs move */
-	if(BC)					/* Find cost of backspace */
-		tvc_bs = tstrlen(BC);
-
-	/* Find costs for doing I/D char operations */
-	if ((TC_im||TC_ic) && (TC_dm||TC_dc))
-	  {	trm_flags |= TF_IDCHR;
-		tvc_ci  = tstrlen(TC_im)+tstrlen(TC_ei);
-		tvc_cin = tstrlen(TC_ic)+1+tstrlen(TC_ip);
-		if(TC_IC)			/* If have multi-IC, use it */
-		  {	tvc_ci += tstrlp(TC_IC, 1);
-			tvc_cin = 1;
-		  }
-		tvc_cd  = tstrlen(TC_dm)+tstrlen(TC_ed);
-		tvc_cdn = tstrlen(TC_dc);
-		if(TC_DC)			/* If have multi-DC, use it */
-		  {	tvc_cd += tstrlp(TC_DC, 1);
-			tvc_cdn = 0;
-		  }
-	  }
-
-	/* Find costs for doing I/D line operations */
-	if ((TC_ia || TC_al) && (TC_id || TC_dl))
-	  {	trm_flags |= TF_IDLIN;
-		tvc_li = 0;			/* Usual case */
-		tvc_lin = tstrlen(TC_al);
-		if(TC_AL)			/* If have multi-IL, use it */
-		  {	tvc_li  = tstrlp(TC_AL, 1);
-			tvc_lin = tstrlp(TC_AL, 2) - tvc_lin;
-		  }
-		else if(TC_ia)
-		  {	tvc_li  = tstrlen(TC_im)+tstrlen(TC_ei);
-			tvc_lin = tstrlen(TC_ia);
-		  }
-
-		tvc_ld = 0;			/* Usual case */
-		tvc_ldn = tstrlen(TC_dl);
-		if(TC_DL)			/* If have multi-DL, use it */
-		  {	tvc_ld  = tstrlp(TC_DL, 1);
-			tvc_ldn = tstrlp(TC_DL, 2) - tvc_ld;
-		  }
-		else if(TC_id)
-		  {	tvc_ld = tstrlen(TC_dm)+tstrlen(TC_ed);
-			tvc_ldn = tstrlen(TC_id);
-		  }
-	  }
-
-	if (tc_am)
-	  {	scr_wid--;		/* For now, avoid invoking wrap. */
-#if 0
-		trm_flags |= AUTOWRAP;	/* */
-#endif
-	  }
-	if (TC_ce) trm_flags |= TF_CLEOL;		/* Term has CLEOL? */
-	if (tc_km) trm_flags |= TF_METAKEY;	/* Term has meta key? */
-
-	return(1);
-}
-
-/* Pair of routines which conspire in order to find # chars actually output
- * by a particular termcap string.
- */
-static int _tslen;		/* Stored count */
-static void _tslinc(ch) { _tslen++; }
-static int
-tstrlen(str)
-char *str;
-{	_tslen = 0;
-	if(str && str[0])
-		tputs(str, 1, _tslinc);	/* Mult padding by just 1 */
-	return(_tslen);
-}
-
-static int
-tstrlp(str, par)		/* Same but with parameter */
-char *str;
-int par;
-{
-#if 0
-	if(str)
-	  {	char *cp = tgoto(str, 0, par);
-		int i = strlen(cp);
-		while(--i >= 0)
-			printf(" %o", *cp++);
-		printf("\n");
-	  }
-#endif
-	return !str ? 0 : tstrlen(tgoto(str, 0, par));
-}
-#endif /*TX_TERMCAP*/
-
-
-/* Direct-Video terminal output routine
- *	Currently only COHERENT has this capability.
- */
-
-#if COHERENT
-#include <sgtty.h>
-
-struct vidctl {
-	int	v_position;		/* Position in video memory */
-	int	v_count;		/* Number of characters to transfer */
-	char	*v_buffer;		/* Character buffer to read/write */
-};
-/*
- * Attribute masks for TIOVPUTB - attributes occupy odd addresses
- * in video memory.
- */
-#define	VNORM	0x07			/* Ordinary Video */
-#define	VINTE	0x08			/* Intense video */
-#define	VBLIN	0x80			/* Blinking video */
-#define	VREVE	0x70			/* Reverse video */
-#define	VUNDE	0x01			/* Underline video (mono board) */
-
-/* T_DIRECT(line, col, string, len) - Do direct-video output of string.
- *	Puts the string ("len" chars in length) on the screen starting at
- *	the X,Y character position given by col, line.
- *	This routine is only called if terminal has the "TF_DIRVID" flag set.
- */
-t_direct(lin, col, str, len)
-int lin, col;
-register char *str;
-register int len;
-{	register char *cp;
-	char vbuf[MAXLINE*2];
-	struct vidctl v;
-
-	if(len <= 0) return;
-	tbufls();		/* Ensure normal output is forced out */
-	v.v_position = (lin*80 + col)*2;
-	v.v_count = len*2;
-	v.v_buffer = cp = vbuf;
-	do {
-		*cp++ = *str++;
-		*cp++ = VNORM;
-	  } while(--len);
-	ioctl(1, TIOVPUTB, &v);
-}
-#endif /*COHERENT*/
-
-
-/*
- * Terminal Output buffering routines
- */
-
-static char tbuf[TOBFSIZ];	/* Output buffer */
-static int tbufcnt = 0;		/* # chars of room left in buffer */
-static char *tbufp = 0;		/* Pointer to deposit in buffer */
-
-tput(ch)
-int ch;
-{	if(--tbufcnt < 0)
-		tbufls();
-	*tbufp++ = ch;
-}
-
-tputz(str)
-char *str;
-{	register int c;
-	register char *cp, *tp;
-	cp = str;
-	tp = tbufp;
-	while(c = *cp++)
-	  {	if(--tbufcnt < 0)
-		  {	tbufp = tp;
-			tbufls();
-			tp = tbufp;
-		  }
-		*tp++ = c;
-	  }
-	tbufp = tp;
-}
-
-tputn(str,cnt)
-char *str;
-int cnt;
-{	register int c;
-	register char *cp, *tp;
-	cp = str;
-	tp = tbufp;
-	if((c = cnt) > 0)
-	do {
-		if(--tbufcnt < 0)
-		  {
-			tbufp = tp;
-			tbufls();
-			tp = tbufp;
-		  }
-		*tp++ = *cp++;
-	  } while(--c);
-	tbufp = tp;
-}
-
-tbufls()
-{	register int cnt;
-
-	if(tbufp
-	  && (cnt = tbufp - tbuf) > 0)		/* # chars written */
-		write(1, tbuf, cnt);		/* Out they go */
-	tbufp = tbuf;
-	tbufcnt = TOBFSIZ-1;	/* Allow for usual expected decrement */
-}
-
-
-/*
- * Terminal Input buffering routines
- */
-
-int tibfmsk = -1;		/* Mask AND'ed with input chars (external) */
-static char tibuf[TIBFSIZ];	/* TTY input buffer */
-static char *tibfp;		/* Pointer to read from buffer */
-static int tibfcnt = 0;		/* # chars left to be read from buffer */
-
-tgetc()
-{
-#if SUN
-	register int c;
-	extern int sun_winfd, sun_rdevf;
-
-	if(sun_winfd)
-	  {	if(!sun_rdevf)
-			return(sun_input(1)&tibfmsk);
-		sun_rdevf = 0;		/* Check mouse too, but only once! */
-		c = sun_input(0);
-		if(c != -1) c &= tibfmsk;
-		return(c);
-	  }
-#endif /*SUN*/
-	while(--tibfcnt < 0)
-		tibfcnt = read(0,(tibfp = tibuf),TIBFSIZ);
-	return((*tibfp++)&tibfmsk);
-}
-
-tinwait()
-{	return(tibfcnt > 0 || ts_inp());
-}
Index: trunk/minix/commands/elle/eevini.c
===================================================================
--- trunk/minix/commands/elle/eevini.c	(revision 9)
+++ 	(revision )
@@ -1,100 +1,0 @@
-/* ELLE - Copyright 1982, 1987 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/* EEVINI - ELLE initialized variables and array storage.
- *	Initial values are defined here, but the vars must be
- * declared in ELLE.H as well so that references from all modules will
- * compile correctly.
- *	Arrays are also allocated here, so size re-definitions only require
- * re-compiling this single small module.
- */
-
-#define EXT		/* Allocate storage for non-initialized vars */
-#include "elle.h"
-
-#ifndef EVFILMOD
-#if V6
-#define EVFILMOD (0600)	/* (int) Default file creation mode on V6 */
-#else
-#define EVFILMOD (0666)	/* (int) Default file creation mode on V7, note */
-#endif /*-V6*/		/*       paranoids can use V7 "umask" in shell. */
-#endif
-#ifndef EVFNO1
-#define EVFNO1 0	/* (char *) "Old" filename prefix */
-#endif
-#ifndef EVFNN1
-#define EVFNN1 0	/* (char *) "New" filename prefix */
-#endif
-#ifndef EVFNO2
-#define EVFNO2 "O"	/* (char *) "Old" filename postfix */
-#endif
-#ifndef EVFNN2
-#define EVFNN2 "N"	/* (char *) "New" filename postfix */
-#endif
-#ifndef EVFCOL
-#define EVFCOL (71)	/* (int) Initial value for Fill Column */
-#endif
-#ifndef EVCCOL
-#define EVCCOL (40)	/* (int) Initial value for Comment Column */
-#endif
-#ifndef EVNWPCT
-#define EVNWPCT 50	/* (int) 50% For random New Window, center cursor. */
-#endif
-#ifndef EVMVPCT
-#define EVMVPCT 67	/* (int) 67% When move off edge, show 67% new stuff */
-#endif
-#ifndef EVMODWSO
-#define EVMODWSO 0	/* (bool) Initial mode window standout mode */
-#endif
-#ifndef EV2MODEWS
-#define EV2MODEWS 1	/* 2-mode-window flag. 0=Never, 1=if SO, 2=always */
-#endif
-#ifndef EVMARKSHOW
-#define EVMARKSHOW 0	/* (char *) String shown for Set Mark */
-#endif
-#ifndef EVHELPFILE	/* (char *) Location of ELLE help file. */
-#define EVHELPFILE "/usr/src/elle/help.dat"
-#endif
-
-char *ev_verstr = "ELLE 4.1b";	/* String: Editor name and version # */
-int ev_filmod = EVFILMOD;	/* Default file creation mode */
-char *ev_fno1 = EVFNO1;		/* "Old" filename prefix */
-char *ev_fnn1 = EVFNN1;		/* "New" filename prefix */
-char *ev_fno2 = EVFNO2;		/* "Old" filename postfix */
-char *ev_fnn2 = EVFNN2;		/* "New" filename postfix */
-
-int ev_fcolumn = EVFCOL;	/* Initial value for Fill Column */
-#if FX_INDCOMM
-int ev_ccolumn = EVCCOL;	/* Initial value for Comment Column */
-#endif
-
-/* New window selection parameters.
-**	Both are expressed as an integer % of window lines (where the whole
-**	window is 100), and apply when a new window is selected.
-** ev_nwpct - when "New Window" is called, % of lines between top and cursor.
-**	Also applies when screen has changed randomly.
-** ev_mvpct - when cursor moves out of window, this is the % of lines
-**	between top and cursor (if moved off top) or between bottom and
-**	cursor (if moved off bottom).
-*/
-int ev_nwpct = EVNWPCT;		/* New Window cursor loc preference (%) */
-int ev_mvpct = EVMVPCT;		/* Moved cursor loc preference (%) */
-
-#if FX_SOWIND
-int ev_modwso = EVMODWSO;	/* Initial mode window standout flag */
-#endif
-#if FX_2MODEWINDS
-int ev_2modws = EV2MODEWS;	/* Initial 2-mode-wind flag */
-#endif
-char *ev_markshow = EVMARKSHOW;	/* String to display when Set Mark done */
-
-char *ev_helpfile = EVHELPFILE;	/* Location of ELLE help file */
-char *ev_profile = EVPROFBINFILE; /* Location of ELLE binary user profile */
-				/* Note ELLE doesn't use EVPROFTEXTFILE. */
-
-/* Array allocations */
-
-struct scr_line *scr[MAXHT];		/* Array of screen line structures */
-SBSTR *kill_ring[KILL_LEN];		/* Kill ring table */
Index: trunk/minix/commands/elle/elle.h
===================================================================
--- trunk/minix/commands/elle/elle.h	(revision 9)
+++ 	(revision )
@@ -1,364 +1,0 @@
-/* ELLE - Copyright 1982, 1984 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/*
- * ELLE.H	Global ELLE definitions
- */
-
-#ifndef EXT
-#define EXT extern	/* Default assumes these are referencing decls */
-#endif
-
-/* Make identifiers unique in 1st 6 chars as per ANSI rule for externals */
-#define tvc_cin tvccin
-#define tvc_cdn tvccdn
-#define tvc_lin tvclin
-#define tvc_ldn tvcldn
-#define ev_fno1 evfno1
-#define ev_fno2 evfno2
-#define ev_fnn1 evfnn1
-#define ev_fnn2 evfnn2
-
-#define ask_sall	asksal	/* eebuff.c */
-#define ask_save	asksav
-#define buf_tmod	buftmo
-#define buf_tmat	buftma
-#define e_gobob		egobob	/* eeedit.c */
-#define e_gobol		egobol
-#define e_goeob		egoeob
-#define e_goeol		egoeol
-#define fill_prefix	filpfx	/* eefill.c */
-#define fill_plen	filpln
-#define fill_cur_line	filcln
-#define kill_ptr	kilptr		/* eef3.c */
-#define kill_push	kilpsh
-#define ed_insert	edinst	/* eefed.c */
-#define ed_insn		edinsn
-#define ed_deln		eddeln
-#define ed_delete	eddele
-#define f_fillreg	ffilrg	/* eejust.c */
-#define f_fillpara	ffilpa
-
-#include "eesite.h"	/* Insert site-dependent flags and parameters */
-#include "sb.h"		/* Insert SB package definitions */
-#include "eeprof.h"	/* Insert user profile definition.  This is a
-			 *	separate file so ELLEC can use it too. */
-#include "eefidx.h"	/* Insert desired function defs */
-
-/* ELLE Compile-time parameter defaults */
-
-#ifndef KILL_LEN
-#define KILL_LEN 8	/* Size of kill ring */
-#endif
-#ifndef MAXHT
-#define MAXHT 72	/* Height (# lines) of largest screen we'll suport */
-#endif
-#ifndef MAXLINE
-#define MAXLINE 132	/* Width  (# chars) of largest screen we'll support */
-#endif
-#ifndef FNAMELEN
-#define FNAMELEN 14	/* Sys-dep: Max size of last filename component */
-#endif			/*	Check FNAMSIZ if you change this. */
-#ifndef FNAMSIZ
-#define FNAMSIZ 100	/* Sys-dep: Max size of complete filename */
-#endif			/*	This must be at least as large as FNAMELEN! */
-#ifndef ISRCHLIM
-#define ISRCHLIM 50	/* Max # of chars to allow I-search on */
-#endif
-#ifndef TOBFSIZ
-#define TOBFSIZ 80	/* Size of TTY output buffer */
-#endif
-#ifndef TIBFSIZ
-#define TIBFSIZ 50	/* Size of TTY input buffer */
-#endif
-#ifndef ECHOLINES
-#define ECHOLINES 1	/* # of lines for echo area (below mode line) */
-#endif
-#ifndef MAXARGFILES
-#define MAXARGFILES 2	/* # of filename args OK at startup */
-#endif
-
-/* ELLE initialized variables.
- *	Initial values are defined in EEVINI.C, but the vars must be
- * declared here as well so that references from all modules will
- * compile correctly.
- */
-
-extern char *ev_verstr;		/* String: Editor name and version # */
-extern int ev_filmod;		/* Default file creation mode */
-extern char *ev_fno1,*ev_fno2;	/* Pre, postfix for "old" filenames */
-extern char *ev_fnn1,*ev_fnn2;	/* Pre, postfix for "new" filenames */
-extern int ev_fcolumn;		/* Fill Column variable */
-#if FX_INDCOMM
-extern int ev_ccolumn;		/* Comment Column variable */
-#endif
-extern int ev_nwpct, ev_mvpct;	/* New window selection percentages */
-#if FX_SOWIND
-extern int ev_modwso;		/* Initial mode window standout flag */
-#endif
-#if FX_2MODEWINDS
-extern int ev_2modws;		/* Initial setting of 2-mode-window flag */
-#endif
-extern char *ev_markshow;	/* String to show when Set Mark done */
-extern char *ev_helpfile;	/* Location of ELLE help file */
-extern char *ev_profile;	/* Filename of ELLE binary user profile */
-extern struct profile def_prof;	/* ELLE default user profile */
-
-/* Global variables */
-
-EXT chroff cur_dot;		/* Current dot */
-EXT chroff mark_dot;		/* Dot for mark */
-EXT int mark_p;			/* flag indicating whether mark exists */
-EXT int this_cmd, last_cmd;	/* Command type */
-EXT int unrchf;			/* Stuffed character back for readcommand */
-EXT int exp;			/* Numeric argument for commands */
-EXT int exp_p;			/* Flag meaning an arg was given */
-EXT int pgoal;			/* Permanent goal column */
-EXT int goal;
-EXT char *srch_str;		/* Last search string specified (0 = none) */
-EXT int srch_len;		/* Length of srch_str string */
-EXT int ask_len;		/* Length of last string returned by "ask" */
-EXT char *homedir;		/* User's home directory */
-EXT int kill_ptr;		/* Index into kill ring */
-extern SBSTR *kill_ring[];	/* Kill ring table (allocated in eevini) */
-
-/* Editor Command types */
-
-#define KILLCMD 1		/* Kill command, for kill merging */
-#define ARGCMD  2		/* Argument-setter, for main loop */
-#define YANKCMD 3		/* Yank command, for yankpop */
-#define LINECMD 4		/* Next or previous line goal hacking */
-#if IMAGEN
-#define INSCMD  5		/* Simple char-insert command, for autowrap */
-#endif /*IMAGEN*/
-
-/* Misc char definitions */
-#define CTRL(ch) (037&ch)
-#define BELL	('\007')	/* Will become \a in ANSI */
-#define BS	('\b')
-#define TAB	('\t')
-#define LF	('\n')
-#define FF	('\f')
-#define CR	('\r')
-#define ESC	('\033')
-#define SP	(' ')
-#define DEL	('\177')
-
-#define CB_META (0200)		/* Meta bit in command char */
-#define CB_EXT  (0400)		/* Extend bit in command char */
-#define METIZER ESC
-#define EXTIZER CTRL('X')
-
-/* Terminal parameters - set at runtime startup */
-
-EXT char *tv_stype;	/* Terminal type string specified by user/system */
-EXT int scr_ht;		/* # lines of main screen area */
-EXT int scr_wid;	/* # columns of screen */
-EXT int scr_wd0;	/* scr_wid - 1 (for 0-origin stuff) */
-EXT int trm_ospeed;	/* Output speed index */
-EXT int tvc_pos;	/* Cost for absolute move (# of output chars) */
-EXT int tvc_bs;		/* Cost for backspace */
-EXT int tvc_ci, tvc_cin;	/* Char ins cost per call, cost per column */
-EXT int tvc_cd, tvc_cdn;	/* Char del   "   "   "     "    "   "     */
-EXT int tvc_li, tvc_lin;	/* Line ins cost per call, cost per line */
-EXT int tvc_ld, tvc_ldn;	/* Line del   "   "   "     "    "   "   */
-
-EXT int trm_flags;	/* Terminal capabilities - bit flags */
-			/* Maybe change to word vars someday (faster) */
-#define TF_IDLIN	01	/* Has I/D line */
-#define TF_IDCHR	02	/* Has I/D char */
-#define TF_SO		04	/* Has usable standout mode */
-#define TF_CLEOL	010	/* Has clear-to-eol */
-#define TF_METAKEY	020	/* Has meta key */
-#define TF_DIRVID	040	/* Has direct-video type interface */
-
-
-/* Redisplay definitions */
-
-EXT int curs_lin;	/* Line # of current cursor (0 origin) */
-EXT int curs_col;	/* Column # of current cursor (0 origin) */
-
-EXT int rd_type;	/* Global var: holds redisplay "hints" */
-#define redp(n) rd_type |= (n)
-
-#define RD_SCREEN 01	/* Clear everything and redisplay */
-#define RD_WINDS 02	/* Check all windows for changes (b/emod) */
-#define RD_MODE 04	/* Mode line has changed, update it. */
-#define RD_WINRES 0400	/* Assume all of window was changed (clear b/emod) */
-#define RD_MOVE	010	/* Cursor has moved */
-#define RD_UPDWIN 020	/* Window fixed, must update modified screen lines */
-/*#define RD_ICHR 0	*//* Hint: Char insert done */
-/*#define RD_DCHR 0	*//* Hint: Char del done */
-#define RD_ILIN 0100	/* Hint: Line insert done */
-#define RD_DLIN 0200	/* Hint: Line del done */
-
-/* #define RD_MOVWIN 02000	*//* Window should be re-positioned */
-#define RD_FIXWIN 02000		/* Window needs fixing (call fix_wind) */
-#define RD_TMOD   04000		/* Text changed in this window, check it. */
-#define RD_WINCLR 010000	/* Clear window with CLEOLs (not yet) */
-#define RD_CHKALL 020000	/* Check all windows for redisplay flags */
-#if IMAGEN
-#define RD_REDO   040000	/* Just re-do the entire window, don't think */
-#endif /*IMAGEN*/
-
-	/* Flags with global effects, only seen in rd_type */
-#define RDS_GLOBALS (RD_SCREEN|RD_MODE|RD_WINDS|RD_CHKALL)
-	/* Flags which are allowed per-window (in w_redp) */
-#define RDS_WINFLGS (~RDS_GLOBALS)
-	/* Flags which force FIX_WIND() to do something */
-#define RDS_DOFIX (RD_WINRES|RD_TMOD|RD_FIXWIN|RD_MOVE)
-
-#define CI_CLINE '!'		/* Char indicator for continued line */
-#define CI_CNTRL '^'		/* Char indicator for control chars */
-#define CI_META  '~'		/* Char indicator for meta-bit (8th) set */
-#define CI_TOP   '|'		/* Char indicator for top-bit (9th) set */
-#define MAXCHAR (8+3)		/* Longest char representation (TAB) + slop */
-
-/* Definitions for screen structures */
-
-struct scr_line {
-	chroff sl_boff;		/* Ptr to start of line's text in buffer */
-	int sl_len;		/* # buffer chars in line (incl NL) */
-	char *sl_line;		/* Ptr to screen image of line */
-	int sl_col;		/* # chars in image == # columns used */
-	char sl_flg;		/* Flags - set if this line modified */
-	char sl_cont;		/* If line being continued on next, this */
-				/* contains 1 plus # extra chars (if any) */
-				/* stored at end of this line which shd be */
-				/* put at beg of next line. */
-	char *sl_nlin;	/* New screen image line if modified flag set */
-	int sl_ncol;
-};
-	/* sl_flg definitions */
-#define SL_MOD 01		/* New line exists, must update to it */
-#define SL_EOL 02		/* Buffer line ends with EOL */
-#define SL_CSO 04		/* Current screen line is in standout mode */
-#define SL_NSO 010		/* New screen line is in standout mode */
-#if IMAGEN
-#define SL_REDO 0100		/* Line should be redone completely */
-#endif /*IMAGEN*/
-
-extern struct scr_line *scr[];	/* Screen line ptrs (allocated in e_vinit) */
-
-
-/* Buffer stuff */
-
-struct buffer 
-{	SBBUF b_sb;			/* MUST be 1st thing! */
-	struct buffer *b_next;		/* ptr to next in chain */
-	char *b_name;			/* text name */
-	char *b_fn;			/* filename */
-	chroff b_dot;			/* point (dot) */
-	int b_flags;			/* misc. bits */
-	struct majmode *b_mode;		/* Mode of buffer */
-#if IMAGEN
-	long b_mtime;			/* Last file modification time */
-#endif /*IMAGEN*/
-};
-	/* b_flags definitions */
-#define B_MODIFIED	01		/* Buffer is modified */
-#define B_EOLCRLF	0200		/* On = CRLF mode, off = LF mode */
-#if IMAGEN
-#define B_PERMANENT 002			/* buffer cannot be killed */
-#define B_CMODE	    004			/* "C" mode (HACK HACK) */
-#define B_BACKEDUP  010			/* Buffer has been backed up once */
-#define B_TEXTMODE  020			/* Text mode (auto-wrap, basically) */
-#define B_QUERYREP  040			/* Query-replace mode (qualifier) */
-#endif /*IMAGEN*/
-
-/* Handy macro to check EOL mode */
-#define eolcrlf(buf) (((struct buffer *)buf)->b_flags&B_EOLCRLF)
-
-/* Buffer pointers */
-
-EXT struct buffer
-		 *buf_head,		/* head of list of all buffers */
-		 *cur_buf,		/* buffer we are editing now */
-		 *last_buf,		/* buffer we were editing before */
-		 *lines_buf;		/* buffer for sep_win */
-
-/* Window stuff */
-
-struct window
-{	struct window *w_next;		/* ptr to next in chain */
-	int w_flags;			/* Window flags */
-	int w_pos;			/* index of top line */
-	int w_ht;			/* number of lines */
-	struct buffer *w_buf;		/* buffer in this window */
-	int w_pct;			/* % of buffer window is at */
-	int w_redp;			/* Redisplay hints */
-	chroff w_topldot;		/* line currently at top of window */
-	chroff w_dot;			/* Saved dot while not cur_win */
-	chroff w_bmod;			/* Lower bound of modified text */
-	chroff w_emod;			/* Upper bound of modified text */
-					/* (offset from end of buffer!) */
-	chroff w_oldz;			/* Buffer len as of last update */
-};
-
-/* Window flags */
-#define W_STANDOUT	01	/* Use terminal's standout mode for window */
-#define W_MODE		02	/* This is a mode window */
-
-/* Window pointers */
-
-EXT struct window
-		*win_head,		/* head of list of all windows */
-		*cur_win,		/* window we are now in */
-		*user_win,		/* current user window */
-		*oth_win,		/* "other" user window */
-		*mode_win,		/* window for mode line */
-		*ask_win,		/* window for ask (echo) area */
-		*sep_win;		/* window for separation dashes */
-
-/* Major Mode stuff.  Each buffer has its own major mode.
- * Only one major mode may be in effect at any time.
- */
-struct majmode {
-	char *mjm_name;		/* Simple for now */
-};
-EXT struct majmode *fun_mode;	/* Fundamental mode - the default */
-EXT struct majmode *cur_mode;	/* Current major mode */
-
-/* Minor modes are currently implemented by means of flag variables
- * which have global effects (regardless of buffer or major mode).
- * Each variable has the name "x_mode" where x is the name of the minor
- * mode.  These are declared in the modules containing their support code.
- * In the future this may be generalized along the lines of major modes.
- */
-
-
-/* Miscellaneous debug stuff */
-
-EXT int dbgval;		/* Set nonzero to do verify stuff */
-EXT int dbg_isw;	/* Set to enable interrupts if possible */
-#if IMAGEN
-EXT int dbg_redp;	/* Set to debug redisplay algorithms */
-#endif /*IMAGEN*/
-extern int errno;
-
-/* V7 routines for setexit/reset emulation */
-
-#if !(V6)
-#include <setjmp.h>
-EXT jmp_buf env_main;
-#define setexit(a)	setjmp(env_main)
-#define reset(a)	longjmp(env_main,a)
-#endif /*-V6*/
-
-/* Declare functions returning CHROFF values (offsets into a buffer) */
-
-extern chroff e_dot(),e_nldot(),e_pldot(),e_boldot(),e_eoldot(),
-	e_alldot(),ex_boldot(),ex_alldot(),
-	ex_blen(),e_blen(),ex_dot(),e_wdot();
-
-extern SBSTR *e_copyn();
-
-/* Some other commonly needed declarations */
-
-extern char *memalloc(), *ask(), *dottoa(), *strdup();
-#if !(V6)
-extern char *getenv();
-#endif /*-V6*/
-#include "eeproto.h"	/* function prototypes */
Index: trunk/minix/commands/elle/ellec.c
===================================================================
--- trunk/minix/commands/elle/ellec.c	(revision 9)
+++ 	(revision )
@@ -1,1425 +1,0 @@
-/* ELLEC - Copyright 1983 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.
- */
-/* ELLEC - ELLE Compiler
- *    Invoked with no arguments, acts as general ELLE compiler filter;
- *	reads ASCII profile input, and outputs a binary profile.
- *    Otherwise:
- *	-Profile	Compiles user's profile.
- *		HOME/.ellepro.e -> HOME/.ellepro.bN (N = fmt version #)
- *		NOTE: on V6, "HOME/" is left out.
- *	-Pconf		Outputs defprf.c for ELLE (accepts std in) (old -E)
- *	-Fconf		Outputs eefdef.h for ELLE (accepts std in)
- *	-FXconf		Outputs eefidx.h for ELLE (accepts std in)
- *	-CMconf		Outputs config makefile for ELLE ( " )
- *	-CSconf	arg	Outputs config file using "arg" - for V6 config.v6 file.
- *	-Pdump		Outputs defprf.e user profile (old -P)
- *	-Fdump		Outputs deffun.e
- */
-
-#if 0
-The ASCII profile file associates command chars with functions.
-It is simply a series of lisp-like expressions of the form
-	(keybind <char spec> <fun spec>)
-		
-	e.g. (keybind "C-Y" "Yank Pop")
-
-Command char specification:
-	Allowed prefixes:
-		<ch>	The char itself
-		C-	Controlify (zap bits 140)
-		^<ch>	Ditto
-		M-	Meta (add bit 200) - case ignored
-		X-	Extended (add bit) - case ignored
-	To quote a char or char spec, use quoted-string syntax.
-
-Function name specification:
-	Function names are specified by quoted strings containing the entire
-	long-form ASCII function name.  Matching is done case-independently.
-
-#endif /*COMMENT*/
-
-
-
-#include "eesite.h"		/* Site specific stuff if any */
-#include <stdio.h>
-#include <ctype.h>
-#include <unistd.h>
-#include "eeprof.h"		/* Profile structure definition */
-
-
-#define EFUNMAX 400	/* Maximum # (+1) of functions that can be defined */
-#define KBTSIZ (128*2)	/* Initial size of key binding tables */
-
-
-/* EFUN Function definition table.
-**	Functions that were copied from the pre-defined table will
-** have a value of NULL in ef_mod.
-*/
-struct fun {
-	int ef_idx;	/* Function index (same as index of entry) */
-	char *ef_name;	/* Function name */
-	char *ef_adr;	/* C routine name in ELLE */
-	char *ef_mod;	/* Source module that C routine lives in */
-};
-struct fun efuntab[EFUNMAX];
-int efxmax = 0;		/* Largest function idx used */
-
-int format_ver = PROF_VER;	/* Current version # of binary profile fmt */
-
-/* Keybind mapping tables.  There are four separate tables:
-**	Simple character.  Always 128 single-byte items, indexed by the simple
-**		command char.  Each item is the corresponding function index.
-**	Meta char.  Variable number of 2-byte items; first is a command char
-**		and second is its function index.
-**	Extended char.  Same format as Meta char.
-**	Menu item (SUN only).  Variable number of single-byte items, each
-**		a function index.
-**
-*/
-char *chrptr;		/* Pointer to simple-char table */
-int chrsiz = 128;	/* Current size of table */
-int chrcnt = 0;		/* # bytes actually used */
-
-char *mtaptr;		/* Pointer to meta-char table */
-int mtasiz = KBTSIZ;	/* Current size (twice the # of items) */
-int mtacnt = 0;		/* # bytes actually used */
-
-char *extptr;		/* Pointer to ext-char table */
-int extsiz = KBTSIZ;	/* Current size (twice the # of items) */
-int extcnt = 0;		/* # bytes actually used */
-
-char *mnuptr;		/* Pointer to menu-item table (SUN only) */
-int mnusiz = KBTSIZ;	/* Current size */
-int mnucnt = 0;		/* # bytes actually used */
-
-
-#define CB_EXT 0400		/* "X-" prefix on command char */
-#define CB_META 0200		/* "M-" prefix on command char */
-
-
-/* Set up the pre-defined data areas.  This includes the
-** predefined function table plus the default profile (keyboard mappings).
-** Note this only contains entries for ef_name and ef_adr.
-*/
-
-struct fun pdfuntab[] = {	/* Pre-Defined Function table */
-#define EFUN(rtn,rtnstr,name) 0, name, rtnstr, 0,
-#define EFUNHOLE 0, 0, 0, 0,
-#include "eefdef.h"
-};
-int npdfuns = sizeof(pdfuntab)/sizeof(struct fun);	/* # of entries */
-
-#include "defprf.c"	/* Insert default profile mapping */
-			/* This defines charmap, metamap, and extmap. */
-
-
-/* Stuff for feeble-minded list processor */
-#define NIL ((struct lnode *)0)
-#define LTRUE (&ltruenode)
-
-#define LT_VAL 0
-#define LT_STR 1
-#define LT_LIST 2
-#define LT_ATOM 3	/* Should use this later instead of LT_STR */
-
-struct lnode {
-	struct lnode *lnxt;
-	int ltyp;
-	union {
-		int lvi;
-		char *lvs;
-		struct lnode *lvl;
-	} lval;
-};
-
-struct lnode ltruenode;		/* Constant TRUE */
-
-_PROTOTYPE(int main , (int argc , char **argv ));
-_PROTOTYPE(int doargs , (int argc , char **argv ));
-_PROTOTYPE(char **findkey , (char *cp , char ***aretp , char **tabp , int tabsiz , int elsize ));
-_PROTOTYPE(int nstrcmp , (char *s1 , char *s2 ));
-_PROTOTYPE(int ustrcmp , (char *s1 , char *s2 ));
-_PROTOTYPE(int strueq , (char *s1 , char *s2 ));
-_PROTOTYPE(int do_opcod , (void));
-_PROTOTYPE(int do_opasc , (void));
-_PROTOTYPE(int outkbind , (int c , int fx ));
-_PROTOTYPE(int do_obprof , (void));
-_PROTOTYPE(int mupcase , (int ch ));
-_PROTOTYPE(int upcase , (int ch ));
-_PROTOTYPE(char *qstr , (char *str ));
-_PROTOTYPE(char *charep , (int c ));
-_PROTOTYPE(int do_ocnf , (char *str ));
-_PROTOTYPE(int do_ofcod , (void));
-_PROTOTYPE(int do_ofasc , (void));
-_PROTOTYPE(int do_ofxcod , (void));
-_PROTOTYPE(int compile_stdin , (void));
-_PROTOTYPE(int lrch , (void));
-_PROTOTYPE(struct lnode *lread , (void));
-_PROTOTYPE(int wspfls , (void));
-_PROTOTYPE(struct lnode *lrstr , (int flg ));
-_PROTOTYPE(int islword , (int c ));
-_PROTOTYPE(struct lnode *eval , (struct lnode *lp ));
-_PROTOTYPE(struct lnode *undefall , (struct lnode *lp ));
-_PROTOTYPE(struct lnode *efun , (struct lnode *lp ));
-_PROTOTYPE(struct lnode *keybind , (struct lnode *lp ));
-_PROTOTYPE(struct lnode *keyallun , (void));
-_PROTOTYPE(struct lnode *menuitem , (struct lnode *lp ));
-_PROTOTYPE(int repchar , (char *str ));
-_PROTOTYPE(struct lnode *getln , (void));
-_PROTOTYPE(int numcvt , (char *str , int *anum ));
-_PROTOTYPE(int listcnt , (struct lnode *lp ));
-_PROTOTYPE(char *funname , (int i ));
-_PROTOTYPE(int findfun , (char *name ));
-_PROTOTYPE(int funcnt , (int *arr ));
-_PROTOTYPE(int scpy , (char *from , char *to , int cnt ));
-_PROTOTYPE(char *stripsp , (char *cp ));
-
-int warn();
-int lerr();
-int fatal();
-
-
-
-/* ELLEC argument stuff */
-char *argfile;
-char *outfile;
-int swfilter;	/* If no args */
-int swprof;	/* -P */
-int swelle;	/* -E */
-
-int uproflg;	/* Do compilation of user's profile */
-int swpcnf;	/* Output defprf.c (C initialization of profile) */
-int swfcnf;	/* Output eefdef.h */
-int swfxcnf;	/* Output eefidx.h */
-int swcmcnf;	/* Output config makefile (makecf.fun) */
-char *swcscnf;	/* Output config specially (for V6) */
-int swallc;	/* Do all of config stuff */
-int swfdmp;	/* Output deffun.e */
-int nfiles;	/* # file specs seen */
-
-main(argc,argv)
-int argc;
-char **argv;
-{	register int i;
-	register char *cp;
-	char temp[300];
-
-	/* Initialize LTRUE
-	** (cannot portably initialize a union at compile time)
-	*/
-	ltruenode.ltyp = LT_VAL;	/* Set type (other fields zero) */
-
-	/* Process switches */
-	if(argc <= 1) swfilter++;	/* If no args, assume filter */
-	else doargs(argc,argv);
-
-	/* Initialize function definitions and key bindings from predefs */
-	chrptr = malloc(chrsiz);
-	mtaptr = malloc(mtasiz);
-	extptr = malloc(extsiz);
-	mnuptr = malloc(mnusiz);
-	if (!chrptr || !mtaptr || !extptr || !mnuptr)
-		fatal("cannot init, no memory");
-
-	scpy(charmap, chrptr, (chrcnt = sizeof(charmap)));
-	scpy(metamap, mtaptr, (mtacnt = sizeof(metamap)));
-	scpy( extmap, extptr, (extcnt = sizeof(extmap)));
-	if(def_prof.menuvec)
-		scpy(def_prof.menuvec, mnuptr, (mnucnt = def_prof.menuvcnt));
-
-	for(i = 0; i < npdfuns; ++i)		/* Initialize function defs */
-		if(pdfuntab[i].ef_name)
-		  {	efuntab[i].ef_idx = i;
-			efuntab[i].ef_name = pdfuntab[i].ef_name;
-			efuntab[i].ef_adr = stripsp(pdfuntab[i].ef_adr);
-			if(efxmax < i) efxmax = i;
-		  }
-
-
-	/* Routines expect input from stdin and output their results
-	 * to stdout.
-	 */
-	if(argfile)
-		if(freopen(argfile,"r",stdin) == NULL)
-			fatal("cannot open input file \"%s\"",argfile);
-	if(outfile)
-		if(freopen(outfile,"w",stdout) == NULL)
-			fatal("cannot open output file \"%s\"",outfile);
-
-
-	/* Check for general compilation */
-	if(swfilter)
-	  {	/* Not really implemented yet */
-		fatal("bad usage, see doc");
-	  }
-
-	/* Do profile hacking of some kind */
-	if(swprof || swelle)
-	  {	if (compile_stdin())	/* Compile input profile */
-		  {	if(swprof)
-				do_opasc();	/* Output ASCII profile (.e) */
-			else if(swelle)
-				do_opcod();	/* Output bin profile (.b1) */
-		  }
-		exit(0);
-	  }
-
-	/* Check for variousness */
-	if(swpcnf)
-	  {	if(compile_stdin())		/* Compile input */
-			do_opcod();	/* Output the C initialization code */
-		exit(0);
-	  }
-	if(swfxcnf)
-	  {	if(compile_stdin())		/* Compile input */
-			do_ofxcod();	/* Output the eefidx.h code */
-		exit(0);
-	  }
-	if(swfcnf)
-	  {	if(compile_stdin())		/* Compile input */
-			do_ofcod();	/* Output the eefdef.h code */
-		exit(0);
-	  }
-	if(swcmcnf || swcscnf)
-	  {	if(compile_stdin())		/* Compile input */
-			do_ocnf(swcscnf);	/* Output the makecf.fun code */
-		exit(0);
-	  }
-	if(swfdmp)
-	  {	if(compile_stdin())		/* Compile input */
-			do_ofasc();	/* Output the deffun.e code */
-		exit(0);
-	  }
-
-
-	/* Hack user's profile */
-	if(!uproflg) exit(0);
-	if(!argfile)
-	  {
-		temp[0] = 0;
-#if !V6
-		if (cp = getenv("HOME"))
-			strcat(temp, cp);
-#if !TOPS20
-		strcat(temp,"/");
-#endif /*-TOPS20*/
-#endif /*-V6*/
-		strcat(temp, EVPROFTEXTFILE);
-		if(freopen(temp,"r",stdin) == NULL)
-			fatal("cannot open profile \"%s\"",temp);
-	  }
-	if(!outfile)
-	  {
-		temp[0] = 0;
-#if !V6
-		if (cp = getenv("HOME"))
-			strcat(temp, cp);
-#if !TOPS20
-		strcat(temp,"/");
-#endif /*-TOPS20*/
-#endif /*-V6*/
-		strcat(temp, EVPROFBINFILE);
-		if(freopen(temp,"wb",stdout) == NULL	/* Try binary 1st */
-		  && freopen(temp,"w",stdout) == NULL)
-			fatal("cannot open output profile \"%s\"",temp);
-
-	  }
-	/* Hack user's profile */
-	if(compile_stdin())		/* Compile input profile */
-		do_obprof();	/* Output the binary */
-
-}
-
-
-#define SW_FLG 0
-#define SW_VAR 1
-#define SW_STR 2
-struct swarg {
-	char *sw_name;
-	long sw_type;
-	int *sw_avar;
-	char **sw_astr;
-} swtab[] = {
-	"P",		SW_FLG, &swprof,	0,	/* Old stuff */
-	"E",		SW_FLG,	&swelle,	0,
-	"Profile",	SW_FLG, &uproflg,	0,
-	"Pconf",	SW_FLG, &swpcnf,	0,
-	"Fconf",	SW_FLG, &swfcnf,	0,
-	"FXconf",	SW_FLG, &swfxcnf,	0,
-	"CMconf",	SW_FLG, &swcmcnf,	0,
-	"CSconf",	SW_STR, 0,		&swcscnf,
-	"Allconf",	SW_FLG, &swallc,	0,
-	"Pdump",	SW_FLG,	&swprof,	0,
-	"Fdump",	SW_FLG, &swfdmp,	0
-};
-
-doargs(argc,argv)
-int argc;
-char **argv;
-{	register int cnt, c;
-	register char **av;
-	register int i;
-	register struct swarg *swp;
-	struct swarg *swp2;
-	int swerrs = 0;
-
-	av = argv;
-	cnt = argc;
-	nfiles = 0;
-
-	while(--cnt > 0)
-	  {	++av;
-		if(*av[0] != '-')	/* If not switch, */
-		  {			/* assume it's an input filename */
-			nfiles++;
-			continue;
-		  }
-		av[0]++;
-
-		/* Try to look up switch in table */
-		swp = (struct swarg *)findkey(av[0], &swp2, swtab,
-			(sizeof(swtab))/(sizeof(struct swarg)),
-			(sizeof(struct swarg))/(sizeof(char *)));
-		if(swp2)
-		  {	fprintf(stderr,"ellec: ambiguous switch: -%s = %s or %s\n",
-				av[0], swp->sw_name, swp2->sw_name);
-			goto swdone;
-		  }
-		if(swp)	switch(swp->sw_type)
-		  {	case SW_FLG:
-				*(swp->sw_avar) = 1;
-				goto swdone;
-			case SW_VAR:
-				*(swp->sw_avar) = 1;
-				if(cnt <= 1) goto swdone;
-				if(isdigit(*av[1]))
-				  {	*(swp->sw_avar) = atoi(av[1]);
-					--cnt;
-					goto swargdone;
-				  }
-				goto swdone;
-				
-			case SW_STR:
-				if(cnt <= 1) goto swdone;
-				*(swp->sw_astr) = av[1];
-				goto swargdone;
-
-			default:
-				fprintf(stderr,"ellec: bad switch type: %s\n",
-					av[0]);
-				swerrs++;
-		  }
-
-	stop:	fprintf(stderr,"ellec: bad switch: %s\n",*av);
-		swerrs++;
-		goto swdone;
-	swargdone:
-		av[0] = 0;
-		av++;
-	swdone:	av[0] = 0;
-	  }
-	if(swerrs) exit(1);		/* Stop if any problems */
-}
-
-char **
-findkey(cp, aretp, tabp, tabsiz, elsize)
-register char *cp;
-char ***aretp;
-register char **tabp;
-int tabsiz, elsize;
-{	register char **mp1, **mp2;
-	register int i, res;
-	
-	*aretp = mp1 = mp2 = 0;
-	for(i = 0; i < tabsiz; ++i, tabp += elsize)
-	  { if(res = ustrcmp(cp,*tabp))
-		  {	if(res > 0) return(tabp);
-			if(!mp1) mp1 = tabp;
-			else mp2 = tabp;
-		  }
-	  }
-	if(mp2)
-		*aretp = mp2;		/* Ambiguous */
-	return(mp1);
-}
-
-/* NSTRCMP - New string compare.
- *	Returns:
- *		2 if str2 > str1 (mismatch)
- *		1 if str2 counted out (str1 > str2)
- *		0 if full match
- *		-1 if str1 counted out (str1 < str2)
- *		-2 if str1 < str2 (mismatch)
- */
-
-nstrcmp(s1,s2)
-register char *s1, *s2;
-{	register int c, d;
-
-	while(c = *s1++)
-	  {	if(c != *s2)
-		  {	if((d = upcase(c) - upcase(*s2)) != 0)
-				return(*s2==0 ? 1 : (d > 0 ? 2 : -2));
-		  }
-		++s2;
-	  }
-	return(*s2 ? -1 : 0);
-}
-
-/* USTRCMP - uppercase string compare.
- *	Returns 0 if mismatch,
- *		1 if full match,
- *		-1 if str1 runs out first (partial match)
- */
-ustrcmp(s1,s2)
-register char *s1, *s2;
-{	register int c;
-
-	if ( ! s1 || ! s2 ) return ( 0 );	/* Check for null ptr */
-	while(c = *s1++)
-	  { if(c != *s2)
-		  {	if(((c ^ *s2) != 040)
-			 || (upcase(c) != upcase(*s2)))
-				return(0);
-		  }
-		s2++;
-	  }
-	return(c == *s2 ? 1 : -1);
-}
-
-strueq(s1,s2)
-char *s1;
-char *s2;
-{	return (ustrcmp(s1, s2) > 0 ? 1 : 0);
-}
-
-
-/* Output C initialization code for default profile (defprf.c) */
-
-do_opcod()
-{	register int i, c, f;
-
-	printf("\
-/* This file defines the initial data for ELLE's default user profile.\n\
-** It is automatically generated by ELLEC, and should not be edited.\n\
-*/\n\
-char charmap[] = {\n");
-	for(i=0; i < chrcnt; i++)
-	  {	printf("\t%2d,",(f = chrptr[i]&0377));
-		printf("\t/* (%3o) %3s",i,charep(i));
-		printf("  %s",funname(f));
-		printf(" */\n");
-	  }
-
-	printf("};\n char metamap[] = {\n");
-	for(i = 0; i < mtacnt; i += 2)
-	  {	printf("\t0%-3o,%3d,",(c = mtaptr[i]&0377),(f = mtaptr[i+1]&0377));
-		printf("\t/* %4s",charep(c|CB_META));
-		printf("  %s",funname(f));
-		printf(" */\n");
-	  }
-
-	printf("};\n char extmap[] = {\n");
-	for(i = 0; i < extcnt; i += 2)
-	  {	printf("\t0%-3o,%3d,",(c = extptr[i]&0377),(f = extptr[i+1]&0377));
-		printf("\t/* %4s",charep(c|CB_EXT));
-		printf("  %s",funname(f));
-		printf(" */\n");
-	  }
-	printf("};\n");
-	printf("struct profile def_prof = {\n");
-	printf("  %d, /* Ver */\n", format_ver);
-	printf("  sizeof(charmap),   charmap,\n");
-	printf("  sizeof(metamap)/2, metamap,\n");
-	printf("  sizeof(extmap)/2,  extmap, \n");
-	printf("  0, 0\n");
-	printf("};\n");
-
-}
-
-
-/* Output ASCII version of default profile */
-
-int oerrs;
-
-do_opasc()
-{	register int i, c, f;
-
-	oerrs = 0;
-	printf("; ELLE default ASCII profile\n\n");
-	printf("(keyallunbind)  ; To flush all existing bindings\n\n");
-	for(i=0; i < chrcnt; i++)
-		outkbind(i, chrptr[i]&0377);
-
-	printf("\n; Meta chars\n\n");
-	for(i = 0; i < mtacnt; i += 2)
-		outkbind(CB_META | (mtaptr[i]&0377), mtaptr[i+1]&0377);
-
-	printf("\n ; Extended commands\n\n");
-	for(i = 0; i < extcnt; i += 2)
-		outkbind(CB_EXT | (extptr[i]&0377), extptr[i+1]&0377);
-
-	printf("\n");
-	if(oerrs)
-		fatal("%d errors encountered, check output file.", oerrs);
-}
-
-outkbind(c, fx)
-{
-	if(fx == 0)		/* Allow key to be mapped to nothing. */
-		return;
-	if(fx <= 0 || fx > efxmax)
-		printf(";INTERNAL ERROR: Bad function index %d for key %s\n",
-			fx, charep(c));
-	else if(efuntab[fx].ef_name == NULL)
-		printf(";INTERNAL ERROR: No name for function %d while mapping key %s\n",
-			fx, charep(c));
-	else {
-	  	printf("(keybind %s \"%s\")\n",
-			qstr(charep(c)),efuntab[fx].ef_name);
-		return;
-	  }
-	oerrs++;
-}
-
-
-/* Output binary user profile */
-
-do_obprof()
-{	register unsigned int rp;	/* Relative "pointer" */
-	struct stored_profile st_prof;
-
-	rp = sizeof(st_prof);		/* Initialize */
-
-	/* Fixed by Kochin Chang, July 1995 */
-	/* format version should be the first field in compiled profile */
-	prof_pack(st_prof.version, format_ver);
-
-	prof_pack(st_prof.chrvec, rp);
-	prof_pack(st_prof.chrvcnt, chrcnt);
-	rp += chrcnt;
-
-	prof_pack(st_prof.metavec, rp);
-	prof_pack(st_prof.metavcnt, mtacnt/2);
-	rp += mtacnt;
-
-	prof_pack(st_prof.extvec, rp);
-	prof_pack(st_prof.extvcnt, extcnt/2);
-	rp += extcnt;
-
-	prof_pack(st_prof.menuvec, rp);
-	prof_pack(st_prof.menuvcnt, mnucnt);
-	rp += mnucnt;
-
-	fwrite((char *)&st_prof,sizeof(st_prof),1,stdout);
-	fwrite(chrptr,sizeof(char),chrcnt,stdout);
-	if(mtacnt)  fwrite(mtaptr, sizeof(*mtaptr), mtacnt, stdout);
-	if(extcnt)  fwrite(extptr, sizeof(*extptr), extcnt, stdout);
-	if(mnucnt) fwrite(mnuptr,sizeof(*mnuptr),mnucnt,stdout);
-}
-
-/* Return upper-case version of character */
-mupcase(ch)
-register int ch;
-{	return((ch&(~0177)) | upcase(ch));
-}
-upcase (ch)
-{	register int c;
-	c = ch&0177;
-	return((('a' <= c) && (c <= 'z')) ? (c - ('a'-'A')) : c);
-}
-
-char *
-qstr(str)
-register char *str;
-{	register int c;
-	static char qstrbuf[100];
-	register char *cp;
-	cp = str;
-	while((c = *cp++) && islword(c));
-	if(c == 0) return(str);	/* No quoting needed */
-
-	cp = qstrbuf;
-	*cp++ = '"';
-	while(*cp++ = c = *str++)
-		if(c == '"') *cp++ = c;	/* Double the quotes */
-	cp[-1] = '"';
-	*cp = 0;
-	return(qstrbuf);
-}
-
-char *
-charep(c)
-register int c;
-{	static char chrbuf[10];
-	register char *cp;
-	cp = chrbuf;
-	if(c&CB_EXT)
-	  {	*cp++ = 'X';
-		*cp++ = '-';
-		c &= ~CB_EXT;
-	  }
-	if(c&CB_META)
-	  {	*cp++ = 'M';
-		*cp++ = '-';
-		c &= ~CB_META;
-	  }
-	if(c <= 037)
-	  {	*cp++ = '^';
-		c += 0100;
-	  }
-	if(c == 0177)
-	  {	*cp++ = 'D';
-		*cp++ = 'E';
-		*cp++ = 'L';
-	  }
-	else *cp++ = c;
-	*cp = 0;
-	return(chrbuf);
-}
-
-
-/* Output config Makefile (makecf.fun)
- *	If argument is 0 (NULL), does Makefile type output.
- *	Otherwise uses string for special-purpose output.
- */
-do_ocnf(str)
-char *str;
-{	register struct fun *fnp;
-	register int i, mi;
-	register char *cp;
-	int fmtab[EFUNMAX];
-	int nfmods;
-	char *modtab[EFUNMAX];
-	char *unknown = "unknown-module";
-
-	if(str == NULL)			/* If not V6 version */
-	  {	printf("# Function module definition file, generated by ELLEC\n");
-		printf("FUN_OFILES = ");
-	  }
-
-	nfmods = 0;
-
-	funcnt(fmtab);		/* Count function occs */
-
-	for(i = 1; i <= efxmax; ++i)
-	  {	if(fmtab[i] == 0) continue;
-		fnp = &efuntab[i];
-
-		if(fnp->ef_name == 0)
-			fatal("internal error - no name for function %d", i);
-		
-		/* Got a function, store its module name if not a dup */
-		if ((cp = fnp->ef_mod) == NULL)	/* Substitute if undef */
-			cp = unknown;	
-		for(mi=0; mi < nfmods; ++mi)
-			if(ustrcmp(cp, modtab[mi]) > 0)
-				break;
-		if(mi < nfmods) continue;
-		modtab[nfmods++] = cp;
-	  }
-
-	/* Now have table of all modules used.  Crunch them into output. */
-	for(mi=0; mi < nfmods; ++mi)
-	    if (modtab[mi] != unknown)
-	      {	if(str != NULL)		/* V6 version? */
-			printf("%s %s\n", str, modtab[mi]);
-		else printf("\\\n\t%s.o", modtab[mi]);
-	      }
-	printf("\n");
-}
-
-
-/* Output eefdef.h */
-
-do_ofcod()
-{	register struct fun *fnp;
-	register int i;
-	char temp[40];
-	int fmtab[EFUNMAX];
-
-	printf("/* .H Function Definition file, generated by ELLEC */\n");
-	printf("/*   0 */ EFUNHOLE /* Always undefined */\n");
-
-	funcnt(fmtab);		/* Count function occs */
-
-	for(i = 1; i <= efxmax ; ++i)
-	  {
-		fnp = &efuntab[i];
-		printf("/* %3d */ ", i);
-		if(fmtab[i] == 0 || fnp->ef_name == 0)
-			printf("EFUNHOLE\n");
-		else
-		  {	sprintf(temp, "\"%s\"", fnp->ef_adr);
-			printf("EFUN( %-12s, %-14s, \"%s\")\n", fnp->ef_adr,
-				temp, fnp->ef_name);
-		  }
-	  }
-
-}
-
-
-/* Output ascii version of function def file
-*/
-do_ofasc()
-{	register struct fun *fnp;
-	register int i;
-	register char *fa, *fm;
-
-	printf("; Master Function Definition file\n");
-
-	for(i = 1; i <= efxmax ; ++i)
-	  {
-		fnp = &efuntab[i];
-		if(fnp->ef_idx == 0)	/* No definition for this index? */
-			continue;
-		if(fnp->ef_name == 0)
-		  {	warn("internal error - no name for function %d", i);
-			continue;
-		  }
-
-		if ((fa = fnp->ef_adr) == NULL)
-			fa = "unknown-addr";
-		if ((fm = fnp->ef_mod) == NULL)
-			fm = "unknown-module";
-		printf("(efun %d \"%s\" %s %s)\n",
-			fnp->ef_idx, fnp->ef_name, fa, fm);
-	  }
-}
-
-
-/* Output eefidx.h */
-
-do_ofxcod()
-{	register struct fun *fnp;
-	register int i;
-	register char *cp, *cp2;
-	int fmtab[EFUNMAX];
-	char tmpstr[100];
-
-	printf("\
-/* .H Function Index Definition file, generated by ELLEC */\n");
-	printf("\
-/* FN_ defines Function Numbers (indices) for all known functions */\n");
-	printf("\
-/* FX_ defines Function eXistence in this ELLE configuration */\n");
-
-	funcnt(fmtab);		/* Count function occs */
-
-	for(i = 1; i <= efxmax ; ++i)
-	  {
-		fnp = &efuntab[i];
-		if(fnp->ef_idx == 0)	/* No definition for this index? */
-			continue;
-		if(fnp->ef_adr == 0 || fnp->ef_name == 0)
-		  {	warn("internal error - no addr/name for function %d", i);
-			continue;
-		  }
-
-		cp2 = fnp->ef_adr;
-		cp = tmpstr;
-		while(*cp++ = upcase(*cp2++));
-		cp = tmpstr;
-		if((*cp++ != 'F') || (*cp++ != '_'))
-			cp = tmpstr;
-
-		/* Always define FN_ as index */
-		printf("#define FN_%-14s %3d /* %s */\n",
-				cp, i, fnp->ef_name);
-		/* Define FX_ as 0 if unused, else same as FN_ */
-		printf("#define FX_%-14s %3d\n", cp,
-			(fmtab[i] == 0) ? 0 : i);	/* 0 if unused */
-	  }
-
-}
-
-
-/* Compile input! */
-
-compile_stdin()
-{	register struct lnode *lp;
-
-	while((lp = lread()) != NIL)
-		eval(lp);
-
-	return(1);
-}
-
-
-#define MAXLINE 300
-int llstch = -1;
-int leofflg;
-#define unlrch(c) llstch = c
-
-int lineno = 0;
-char linebuf[MAXLINE];
-char *linecp = linebuf;
-
-lrch()
-{	register int c;
-	if((c = llstch) >= 0)
-	  {	if(c == 0 && leofflg)
-			return(EOF);
-		llstch = -1;
-		return(c);
-	  }
-	if((c = getc(stdin)) == EOF)
-	  {	leofflg = 1;
-		llstch = 0;
-		*linecp = 0;
-		linecp = linebuf;
-		return(c);
-	  }
-	if(c == '\n')
-	  {	lineno++;
-		linecp = linebuf;
-	  }
-	else *linecp++ = c;
-	return(c);
-}
-
-struct lnode *
-lread()
-{	register int c;
-	register struct lnode *lp, *lp2;
-	struct lnode *head;
-
-	wspfls();
-	if((c = lrch())== EOF)
-		return(NIL);
-	if(c == ')')	/* End of a list? */
-		return(NIL);
-	if(c == '(')	/* Start of a list? */
-	  {	head = lp = getln();
-		lp->ltyp = LT_LIST;
-		if((head->lval.lvl = lp = lread()) == NIL)
-			return(head);	/* Return empty list */
-		while(lp2 = lread())
-		  {	lp->lnxt = lp2;
-			lp = lp2;
-		  }
-		return(head);
-	  }
-
-	/* Atom of some kind */
-	if(c=='"')
-	  {	return(lrstr(1));
-	  }
-	unlrch(c);
-	return(lrstr(0));
-}
-
-wspfls()
-{	register int c;
-	for(;;)
-	  {	c = lrch();
-		if(isspace(c)) continue;
-		if(c == ';')
-			while((c = lrch()) != '\n')
-				if(c == EOF) return;		
-		break;
-	  }		
-	if(c != EOF) unlrch(c);
-}
-
-#define LSMAX 300	/* Max # chars in atom string */
-struct lnode *
-lrstr(flg)
-{	char cbuf[LSMAX];
-	register char *cp;
-	register int c, i;
-	struct lnode *lp;
-
-	cp = cbuf;
-	i = 0;
-
-	while((c = lrch()) != EOF)
-	  if (flg) switch(c)
-	  {	case '"':
-			if((c = lrch()) == EOF)
-				return(NIL);
-			if(c != '"')
-			  {	unlrch(c);
-				goto out;
-			  }
-		default:
-		ok:
-			if(++i > LSMAX)
-				break;
-			*cp++ = c;
-			continue;
-	  }
-	else
-	  {	if(islword(c)) goto ok;
-		unlrch(c);
-		break;
-	  }
-  out:
-	lp = getln();
-	lp->ltyp = LT_STR;
-	lp->lval.lvs = malloc(i+1);
-	*cp = 0;
-	strcpy(lp->lval.lvs, cbuf);
-	return(lp);
-}
-islword(c)
-{	return((040 < c && c < 0177
-		&& c != '(' && c !=')' && c != ';'
-		&& c != '"' && c != '\\') ? 1 : 0);
-}
-
-
-
-struct lnode *keybind(), *keyallun(), *menuitem(), *efun(),
-	*undefall();
-
-struct lfun {
-	char *lfname;			/* Name of list function */
-	struct lnode * (*lfrtn)();	/* Function address */
-} lfntab[] = {
-	"keybind",	keybind,
-	"efun",		efun,
-	"menuitem",	menuitem,
-	"keyallunbind",	keyallun,
-/*	"keyunbind",	keyunbind,	*/	/* Not yet */
-	"undefall",	undefall,
-/*	"undef",	undef,		*/	/* Not yet */
-	0, 0
-};
-
-struct lnode *
-eval(lp)
-register struct lnode *lp;
-{	register struct lnode *flp;
-	register struct lfun *lfent;
-
-	if(lp->ltyp != LT_LIST)
-		return(lp);
-	if((flp = lp->lval.lvl) == NIL)
-		return(NIL);
-	if(flp->ltyp != LT_STR)
-		return(NIL);
-
-	/* Look up list function and invoke it */
-	for(lfent = lfntab; lfent->lfname; lfent++)
-		if(strueq(flp->lval.lvs, lfent->lfname))
-			return((*(lfent->lfrtn))(flp->lnxt));
-
-	lerr("unknown op: (%s)", flp->lval.lvs);
-	return(NIL);
-}
-
-
-
-/* UNDEFALL - (undefall)
-**	Undefines all functions.  Typically used to clear out
-** predefined functions prior to compiling a set of new efuns.
-*/
-struct lnode *
-undefall(lp)
-register struct lnode *lp;
-{
-	register int i;
-	efxmax = 0;		/* Say nothing in function def table! */
-	for(i = 0; i < EFUNMAX; ++i)
-	  {	efuntab[i].ef_idx = 0;
-		efuntab[i].ef_name = 0;
-		efuntab[i].ef_adr = 0;
-		efuntab[i].ef_mod = 0;
-	  }
-	return(LTRUE);
-}
-
-
-/* EFUN - (efun <index> <functionname> <address> <module>)
-**	Checks out the args and if no problems, stores the function
-** definition in efuntab.
-*/
-struct lnode *
-efun(lp)
-register struct lnode *lp;
-{	struct lnode *nlp;
-	register int c, i;
-	register struct fun *fnp;
-	char *fname, *faddr, *fmod;
-	int fni, num;
-
-	if(listcnt(lp) < 4)
-	  {	lerr("efun - not enough args");
-		return(NIL);
-	  }
-
-	/* First thing should be function index */
-	switch(lp->ltyp)
-	  {	case LT_VAL:
-			fni = lp->lval.lvi;
-			break;
-		case LT_STR:
-			if(numcvt(lp->lval.lvs, &num))
-			  {	fni = num;
-				break;
-			  }
-		default:
-			lerr("efun - non-value function index");
-			return(NIL);
-	  }
-
-	/* Next thing should be function name */
-	lp = lp->lnxt;
-	if(lp->ltyp != LT_STR)	/* Function name not a string */
-	  {	lerr("efun - non-string function name");
-		return(NIL);
-	  }
-	fname = lp->lval.lvs;
-
-	/* Next thing should be function addr */
-	lp = lp->lnxt;
-	if(lp->ltyp != LT_STR)	/* Function addr not a string */
-	  {	lerr("efun - non-string function addr");
-		return(NIL);
-	  }
-	faddr = lp->lval.lvs;
-
-	/* Next thing should be function module */
-	lp = lp->lnxt;
-	if(lp->ltyp != LT_STR)	/* Function module not a string */
-	  {	lerr("efun - non-string function module");
-		return(NIL);
-	  }
-	fmod = lp->lval.lvs;
-
-	/* Now see if already exists or anything */
-	if(fni <= 0 || fni > EFUNMAX)
-	  {	lerr("efun - bad function index %d", fni);
-		return(NIL);
-	  }
-	fnp = &efuntab[fni];
-	if(fnp->ef_idx != 0)
-	  {
-		if (fnp->ef_idx == fni
-		 && strueq(fnp->ef_name, fname)
-		 && strueq(fnp->ef_adr, faddr)
-		 && (fnp->ef_mod == NULL || strueq(fnp->ef_mod, fmod)))
-			goto win;		/* Benign redefinition */
-
-lerr("efun - redefining function (%d \"%s\" %s %s)",
-		fnp->ef_idx, fnp->ef_name, fnp->ef_adr,
-		(fnp->ef_mod ? fnp->ef_mod : "unknown-module"));
-	  }
-	for(i = 0; i < EFUNMAX; ++i)
-	  {	if(efuntab[i].ef_idx == 0) continue;
-		if(ustrcmp(efuntab[i].ef_adr,faddr) > 0
-		  || ustrcmp(efuntab[i].ef_name, fname) > 0)
-		  {	if(i == fni) continue;
-			lerr("efun - name or address dup!  \"%s\"", fname);
-			return(NIL);
-		  }
-	  }
-
-	/* No problems, store the function def in efuntab! */
-win:	fnp->ef_idx = fni;
-	fnp->ef_mod = fmod;
-	fnp->ef_adr = faddr;
-	fnp->ef_name = fname;
-
-	if(efxmax < fni) efxmax = fni;
-	return(LTRUE);
-}
-
-
-
-/* KEYBIND - (keybind <charspec> <functionname>) */
-
-struct lnode *
-keybind(lp)
-register struct lnode *lp;
-{	struct lnode *nlp;
-	register int c, i;
-	int fni;
-
-	if(lp == NIL || (nlp = lp->lnxt)== NIL)
-		return(NIL);
-	switch(lp->ltyp)
-	  {	case LT_VAL:
-			c = lp->lval.lvi;
-			break;
-		case LT_LIST:
-			return(NIL);
-		case LT_STR:
-			c = repchar(lp->lval.lvs);
-			break;
-	  }
-	if(c == -1)
-		return(NIL);	/* No such command char name */
-
-	lp = nlp;
-	if(lp->ltyp != LT_STR)	/* Function name not a string */
-	  {	lerr("(keybind) non-string function name");
-		return(NIL);
-	  }
-	fni = findfun(lp->lval.lvs);
-	if(fni == 0)		/* No such function name */
-	  {	lerr("(keybind) no such function - \"%s\"", lp->lval.lvs);
-		return(NIL);
-	  }
-	if(c & CB_EXT)
-	  {	c &= ~CB_EXT;
-
-		/* Check for redefinition */
-		for(i = 0; i < extcnt; i += 2)
-			if(c == (extptr[i]&0377))	/* Already there? */
-			  {	if((extptr[i+1]&0377) != fni)	/* Yes, check fn */
-				    lerr("(keybind) redefining X-%s as %d=\"%s\"",
-					charep(c), fni, lp->lval.lvs);
-				break;
-			  }
-		if(i >= extcnt)		/* Didn't find? */
-		  {	if(extcnt >= extsiz)
-			  {	lerr("(keybind) too many X- commands");
-				return(NIL);	/* Too many EXT cmds */
-			  }
-			i = extcnt;	/* Increase size of table */
-			extcnt += 2;
-		  }
-		/* Now store new binding */
-		extptr[i] = c;
-		extptr[i+1] = fni;
-	  }
-	else if(c&CB_META)
-	  {	c &= ~CB_META;
-
-		/* Check for redefinition */
-		for(i = 0; i < mtacnt; i += 2)
-			if(c == (mtaptr[i]&0377))	/* Already there? */
-			  {	if((mtaptr[i+1]&0377) != fni)	/* Yes, check fn */
-				    lerr("(keybind) redefining M-%s as %d=\"%s\"",
-					charep(c), fni, lp->lval.lvs);
-				break;
-			  }
-		if(i >= mtacnt)		/* Didn't find? */
-		  {	if(mtacnt >= mtasiz)
-			  {	lerr("(keybind) too many M- commands");
-				return(NIL);	/* Too many META cmds */
-			  }
-			i = mtacnt;	/* Increase size of table */
-			mtacnt += 2;
-		  }
-		/* Now store new binding */
-		mtaptr[i] = c;
-		mtaptr[i+1] = fni;
-	  }
-	else {
-		i = c & 0177;
-		if (chrptr[i] && (chrptr[i]&0377) != fni)
-		    lerr("(keybind) redefining %s as %d=\"%s\"",
-			charep(c), fni, lp->lval.lvs);
-		chrptr[i] = fni;
-	  }
-	return(LTRUE);
-}
-
-/* KEYALLUNBIND - (keyallunbind) */
-struct lnode *
-keyallun()
-{	register int i;
-	register char *cp;
-
-/*	fprintf(stderr, "ellec: clearing all key definitions\n"); */
-	for(i = 0, cp = chrptr; i < chrcnt; i++)
-		*cp++ = 0;
-	mtacnt = extcnt = mnucnt = 0;
-	return(LTRUE);
-}
-
-
-/* MENUITEM - (menuitem <functionname>) */
-
-struct lnode *
-menuitem(lp)
-register struct lnode *lp;
-{	register int i, fni;
-
-	if(lp == NIL)
-		return(NIL);
-	switch(lp->ltyp)
-	  {	case LT_VAL:
-			fni = lp->lval.lvi;
-			break;
-		case LT_LIST:
-			return(NIL);
-		case LT_STR:
-			fni = findfun(lp->lval.lvs);
-			break;
-	  }
-	if(fni == 0) return(NIL);	/* Bad val or no such function name */
-	for(i = 0; i < mnusiz; i++)
-		if(fni == (mnuptr[i]&0377) || mnuptr[i] == 0)
-		  {	mnuptr[i] = fni;
-			mnucnt++;
-			return(LTRUE);
-		  }
-	return(NIL);		/* Too many menu items */
-}
-
-
-repchar(str)
-register char *str;
-{	register int c;
-	register int i, l;
-
-	if (str == 0) return (-1);
-	i = 0;
-	l = strlen(str);
-	c = (*str++)&0377;
-	if(l == 0) return(-1);
-	if(l == 1) return(c);	/* One-char representation */
-	if(c == '^')
-		if(l == 2) return((~0140) & mupcase(*str));
-		else return(-1);
-	c = mupcase(c);
-	if (*str == '-')
-	  {	if(*++str == 0) return(-1);
-		switch(c)
-		  {	case 'X': return(CB_EXT | mupcase(repchar(str)));
-			case 'M': return(CB_META | mupcase(repchar(str)));
-			case 'C': return((~0140) & repchar(str));
-		  }
-	  }
-	if(c == 'S' && upcase(*str) == 'P' && l == 2)
-		return(' ');
-	if(c == 'D' && upcase(*str++) == 'E' && upcase(*str++) == 'L'
-		&& *str == 0)
-		return(0177);
-	return(-1);		
-}
-
-struct lnode *
-getln()
-{	return((struct lnode *)calloc(1,sizeof(struct lnode)));
-}
-
-numcvt(str, anum)
-char *str;
-int *anum;
-{	register char *cp;
-	register int i, c, sign;
-	if((cp = str) == 0)
-		return 0;
-	i = sign = 0;
-	if(*cp == '-')
-		cp++, sign++;
-	while(c = *cp++)
-		if(!isdigit(c)) return(0);
-		else i = 10*i + (c - '0');
-	*anum = sign ? -i : i;
-	return(1);
-}
-
-
-
-listcnt(lp)
-register struct lnode *lp;
-{	register int i;
-	i = 0;
-	while(lp)
-		++i, lp = lp->lnxt;
-	return(i);
-}
-
-
-/* FUNNAME - Given function index, return function name.
-**	Always wins; returns "unknown" for bad indices.
-*/
-char *
-funname(i)
-register int i;
-{
-	register char *cp = NULL;
-	if(0 < i && i <= efxmax && (cp = efuntab[i].ef_name))
-		return cp;
-	return("unknown function");
-}
-
-findfun(name)
-register char *name;
-{	register int i;
-	if((i = efxmax) > 0)
-	  {	do { if(strueq(name, efuntab[i].ef_name))
-			return(i);
-		  } while(--i);
-		return(0);
-	  }
-	return(0);
-}
-
-
-/* FUNCNT - Scan all key bindings, counting each occurrence of every
-**	function index.
-**	This is used to determine which functions are actually used.
-*/
-funcnt(arr)
-register int *arr;		/* Pointer to array of EFUNMAX ints */
-{
-	register int i;
-
-	for(i = 0; i < EFUNMAX; ++i)	/* Clear the array */
-		arr[i] = 0;
-	
-	for(i = 0; i < chrcnt; ++i)	/* Scan bindings */
-		arr[chrptr[i]&0377]++;
-	for(i = 0; i < mtacnt; i += 2)
-		arr[mtaptr[i+1]&0377]++;
-	for(i = 0; i < extcnt; i += 2)
-		arr[extptr[i+1]&0377]++;
-}
-
-scpy(from,to,cnt)
-register char *from,*to;
-register int cnt;
-{	if(cnt > 0)
-		do { *to++ = *from++; }
-		while(--cnt);
-}
-
-/* STRIPSP - strip spaces from string.  Returns ptr to start. */
-char *
-stripsp(cp)
-register char *cp;
-{
-	register char *ep, *lastp;
-	while(*cp == ' ') ++cp;
-	if (*cp)
-	  {	ep = cp + strlen(cp);	/* Point to null ending the str */
-		while (*--ep == ' ');
-		*++ep = 0;		/* Tie it off */
-	  }
-	return cp;
-}
-
-
-warn(str,a,b,c,d,e,f,g,h,i)
-char *str;
-{
-	fprintf(stderr, "ellec: ");
-	fprintf(stderr, str, a,b,c,d,e,f,g,h,i);
-	fprintf(stderr, "\n");
-}
-
-lerr(str,a,b,c,d,e,f,g,h,i)
-char *str;
-{
-	warn(str, a,b,c,d,e,f,g,h,i);
-	*linecp = 0;			/* Tie off current line buffer */
-	fprintf(stderr, "    Line %d: %s\n", lineno, linebuf);
-}
-
-fatal(str,a,b,c,d,e,f,g,h,i)
-char *str;
-{
-	warn(str, a,b,c,d,e,f,g,h,i);
-	exit(1);
-}
-
Index: trunk/minix/commands/elle/sb.h
===================================================================
--- trunk/minix/commands/elle/sb.h	(revision 9)
+++ 	(revision )
@@ -1,284 +1,0 @@
-/* SB - Copyright 1982 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.  In all cases
- *	the source code and any modifications thereto must remain
- *	available to any user.
- *
- *	This is part of the SB library package.
- *	Any software using the SB library must likewise be made
- *	quasi-public, with freely available sources.
- */
-
-#ifdef COMMENT
-
-The initials "SB" stand for "String Block" or "String Buffer".
-
-SBBUFFER - A SB buffer containing a sbstring opened for editing.
-SBFILE   - A structure holding file-specific information for all
-		SDBLKs pointing to that file.
-SBSTRING - A SB string; conceptually a single string, but actually
-		a linked list of SDBLKs.  Unless opened by a SBBUFFER,
-		only a few operations are allowed on SBSTRINGs (creating,
-		copying, deleting).
-SDBLK    - One of the linked nodes constituting a sbstring.  Each SDBLK
-		node points to a continuous string either in memory or
-		on disk, or both.
-SBLK	 - Another name for SDBLK.
-SMBLK	 - An allocated chunk of memory.  Also refers to the node structure
-		maintained by the SBM memory management routines, which
-		points to the actual chunk of memory.
-SBM	 - Name of the memory management package.  SBM routines are used
-		to allocate memory in general, and are not just for
-		use by SB routines.
-
-************ MACHINE DEPENDENT DEFINITIONS **********
-
-	The following compile time definitions represent machine
-dependent parameters which are intended mainly for use only by SBM and
-SBSTR routines.  Other programs should use them with caution.  Note
-that a great deal of code assumes that type "int" corresponds to a basic
-machine word (as per C Reference Manual).
-
-	The current definitions will only work for machines which have
-1, 2, 4, or 8 "char" bytes in a machine word.  Any other size will
-require some changes to the definitions and possibly to some places
-using them.
-
-WORD   - integer-type definition corresponding to machine word.
-WDSIZE - # addressable char bytes in a machine word.		(1, 2, 4, 8)
-WDBITS - # low order bits in an address, ie log2(WDSIZE).	(0, 1, 2, 3)
-WDMASK - Mask for low order bits of address			(0, 1, 3, 7)
-CHAR_MASK - If defined, machine does sign-extension on chars, and
-	they must be masked with this value.
-
-	Note that the macro for WDBITS has no mathematical significance
-other than being an expression which happens to evaluate into the right
-constant for the 4 allowed values of WDSIZE, and in fact it is this
-crock which restricts WDSIZE!  If C had a base 2 logarithm expression
-then any power of 2 could be used.
-
-Values for machines
-				WORD	WDSIZE	WDBITS	WDMASK
-	PDP11, Z8000, I8086	int	2	1	01
-	VAX11, M68000, PDP10	int	4	2	03
-
-#endif /* COMMENT */
-
-
-/* First try to define a few things in a semi-portable way
-*/
-#include "eesite.h"
-#ifdef __STDC__		/* Implementation supports ANSI stuff? */
-#include <limits.h>		/* Get sizes for char stuff */
-#define _SBMUCHAR 1		/* Can use "unsigned char" */
-#define _SBMCHARSIGN (CHAR_MIN < 0)	/* True if "char" is sign-extended */
-#define CHAR_MASK (UCHAR_MAX)
-
-#else	/* not ANSI */
-#ifndef _SBMUCHAR		/* Default assumes no "unsigned char" */
-#define _SBMUCHAR 0
-#endif
-#ifndef _SBMCHARSIGN		/* Default assumes "char" is sign-extended */
-#define _SBMCHARSIGN 1
-#endif
-#ifndef CHAR_MASK		/* Default assumes "char" is 8 bits */
-#define CHAR_MASK 0377
-#endif
-#endif	/* not ANSI */
-
-/* Define "sb_uchartoint" as a macro which ensures that an unsigned
-** character value is converted properly to an int value.
-*/
-#if (_SBMUCHAR || (_SBMCHARSIGN==0))
-#define sb_uchartoint(a) (a)		/* No fear of sign extension */
-#else
-#define sb_uchartoint(a) ((a)&CHAR_MASK)	/* Bah, sign extension */
-#endif
-
-
-/* Defs for machines with a base-2 WDSIZE.  Yes, the (int) is indeed necessary
- * (to allow implicit conversion to long where needed - the PDP11 compiler
- * is known to lose without it, because sizeof is cast as "unsigned int"
- * which loses big in long masks!)
- */
-#define WORD int
-#define WDSIZE ((int)(sizeof(WORD)))
-#define WDMASK (WDSIZE-1)
-#define WDBITS ((WDSIZE>>2)+(1&WDMASK))
-
-#define rnddiv(a) ((a)>>WDBITS)		/* # words, rounded down */
-#define rndrem(a) ((a)&WDMASK)		/* # bytes remaining past wd bndary */
-#define rnddwn(a) ((a)&~WDMASK)		/* Round down to word boundary */
-#define rndup(a)  rnddwn((a)+WDSIZE-1)	/* Round up to word boundary */
-
-#ifdef COMMENT	/* The following are for machines without a base-2 WDSIZE */
-#define rnddiv(a) ((a)/WDSIZE)
-#define rndrem(a) ((a)%WDSIZE)
-#define rnddwn(a) ((a)-rndrem(a))
-#define rndup(a)  rnddwn((a)+WDSIZE-1)
-#undef WDMASK			/* These become meaningless and anything */
-#undef WDBITS			/* which uses them should be changed! */
-#endif /* COMMENT */
-
-/* The following 3 definitions are somewhat machine-dependent,
- * but are specifically intended for general use and work for all
- * currently known C implementations.
- *	SBMO must be an integer-type object large enough to hold
- *	the largest difference in SBMA pointers, and must not be
- *	used in signed comparisons.
- */
-
-typedef long chroff;		/* CHROFF - Char offset in disk/sbstr */
-typedef unsigned int SBMO;	/* SBMO - Char offset in memory */
-typedef
-#if _SBMUCHAR
-	unsigned
-#endif
-		char *SBMA;	/* SBMA - Pointer to char loc in memory */
-
-
-
-/* The following definitions tend to be system-dependent.  Only the
- * SBM and SBSTR routines use them.
- */
-#define SB_NFILES 32		/* # of open files we can hack.  Actually
-				 * this is max FD value plus 1. */
-#define SB_BUFSIZ 512		/* Optimal buffer size (system block size) */
-#define SB_SLOP (16*WDSIZE)	/* # slop chars to tolerate for allocations */
-
-#define SMNODES (20)		/* # SM or SD nodes to create when needed */
-#define SMCHUNKSIZ (16*512)	/* # bytes of mem to create (via sbrk) " " */
-#define MAXSBMO ((SBMO)-1)	/* Used in SBM only */
-		/* MAXSBMO should be the largest possible SBMO value. */
-
-
-#define EOF (-1)
-#define SBFILE struct sbfile
-#define SBBUF struct sbbuffer
-#define SBSTR struct sdblk	/* Start of a sbstring */
-
-struct sbfile {
-	int sfflags;		/* Various flags */
-	int sffd;		/* FD for file (-1 if none) */
-	struct sdblk *sfptr1;	/* Ptr to 1st node in phys list */
-	chroff sflen;		/* Original length of file FD is for */
-};
-
-	/* Definition of SBBUF string/buffer */
-struct sbbuffer {
-	SBMA sbiop;		/* I/O pointer into in-core text */
-	int sbrleft;		/* # chars left for reading */
-	int sbwleft;		/* # chars left for writing */
-	int sbflags;		/* Various flags */
-	chroff sbdot;		/* Logical pos for start of current sdblk */
-	chroff sboff;		/* Offset into current sdblk (if no smblk)*/
-	struct sdblk *sbcur;	/* Pointer to current SD block of string */
-};
-	/* Flags for "sbflags" */
-#define SB_OVW	01	/* Over-write mode */
-#define SB_WRIT 02	/* Written; smuse needs to be updated from sbiop */
-
-	/* NOTE: An unused sbbuf structure should be completely zeroed.
-	 *	This will cause routines to handle it properly
-	 *	if they are accidentally pointed at it.
-	 */
-
-	/* Definition of SDBLK */
-struct sdblk {
-	struct sdblk *slforw;	/* Logical sequence forward link */
-	struct sdblk *slback;	/* Logical sequence backward link */
-	int sdflags;
-	struct sdblk *sdforw;	/* Physical sequence (disk) */
-	struct sdblk *sdback;	/* ditto - backptr for easy flushing */
-	struct smblk *sdmem;	/* Mem pointer, 0 if no in-core version */
-	SBFILE *sdfile;		/* File pointer, 0 if no disk version */
-	chroff sdlen;		/* # chars in disk text */
-	chroff sdaddr;		/* Disk address of text */
-};
-	/* Flags for "sdflags" */
-#define SD_LOCK 0100000		/* Locked because opened by a SBBUF */
-#define SD_LCK2	0040000		/* Locked for other reasons */
-#define SD_MOD	0020000		/* Modified, mem blk is real stuff */
-#define SD_NID	   0323		/* Node ID marks active (not on freelist) */
-#define SD_LOCKS (SD_LOCK|SD_LCK2)
-
-/* Note sdback is ONLY needed for fixing up phys list when a sdblk is
- * deleted (so as to find previous blk in phys list).  Perhaps it shd
- * be flushed (ie only use SDFORW)?  How to do deletions - use circular
- * list?  Sigh.
- */
-
-	/* Definition of SMBLK (used by SBM routines) */
-struct smblk {
-	struct smblk *smforw;	/* Links to other mem blks, in phys order */
-	struct smblk *smback;
-	int smflags;		/* Type, in-use flags */
-	SBMA smaddr;		/* Mem address of text */
-	SBMO smlen;		/* # bytes in mem block */
-	SBMO smuse;		/* # bytes "used" in block */
-};
-	/* Flags for "smflags" */
-#define SM_USE	0100000		/* Block is in use (mem free if off) */
-#define SM_NXM	 040000		/* Block mem is non-existent */
-#define SM_EXT	 020000		/* Block mem owned by external (non-SBM) rtn*/
-#define SM_MNODS 010000		/* Block holds SMBLK nodes */
-#define SM_DNODS  04000		/* Block holds SDBLK nodes */
-#define SM_NID	   0315		/* Node in-use identifier (low byte) */
-
-/* Error handler type values */
-#define SBMERR 0	/* Error in SBM package */
-#define SBXERR 1	/* Error in SBSTR package */
-#define SBFERR 2	/* "Error" - SBSTR package found a file overwritten.
-			 *	Non-zero return will continue normally. */
-
-
-/* Redefine certain external symbols to be unique in the first 6 chars
-** to conform with ANSI requirements.
-*/
-#define sbm_nfre sbmnfre	/* SBM stuff */
-#define sbm_nfor sbmnfor
-#define sbm_nmov sbmnmov
-#define sbm_ngc  sbmngc
-#define sbx_ndget sbxndg	/* SBSTR stuff */
-#define sbx_ndel  sbxnde
-#define sbx_ndfre sbxndf
-#define sbx_sdcpy sbxsdc
-#define sbx_sdgc  sbxsdg
-#define sbe_sdlist sbesls	/* SBERR stuff */
-#define sbe_sdtab  sbestb
-#define sbe_sds    sbesds
-#define sbe_sbvfy  sbesbv
-#define sbe_sbs    sbesbs
-
-/* Forward declarations */
-extern SBMA sbm_lowaddr;	/* For roundoff purposes */
-
-extern SBFILE sbv_tf;		/* SBFILE for temp swapout file */
-extern int (*sbv_debug)();	/* Error handler address */
-extern off_t lseek();		/* For sbstr code mostly */
-extern char *mktemp();
-extern char *malloc();
-extern char *calloc();
-extern SBBUF *sb_open();
-extern SBSTR *sb_close(), *sb_fduse(), *sbs_cpy(), *sbs_app(), *sb_cpyn(),
-	*sb_killn();
-extern struct sdblk *sbx_ready();
-extern chroff sb_tell(), sb_ztell(), sbs_len();
-
-
-/* Definition of SB_GETC, SB_PUTC, SB_BACKC macros */
-
-#define sb_putc(s,c) (--((s)->sbwleft) >= 0 ? \
-				(*(s)->sbiop++ = c) : sb_sputc(s,c))
-#define sb_getc(s)   (--((s)->sbrleft) >= 0 ? \
-				sb_uchartoint(*(s)->sbiop++) : sb_sgetc(s))
-#define sb_peekc(s)  ((s)->sbrleft > 0 ? \
-				sb_uchartoint(*(s)->sbiop)   : sb_speekc(s))
-
-/* WARNING - sb_backc must ONLY be used if last operation was a
- * successful sb_getc!!  For slow but sure invocation use sb_rgetc.
- */
-#define sb_backc(s) (++(s->sbrleft), --(s->sbiop))
-
-#include "sbproto.h"	/* function prototypes */
Index: trunk/minix/commands/elle/sbbcpy.c
===================================================================
--- trunk/minix/commands/elle/sbbcpy.c	(revision 9)
+++ 	(revision )
@@ -1,54 +1,0 @@
-
-#include "sb.h"
-
-/* BCOPY(from,to,cnt) - Copy string of bytes.
- *	Normally this routine is an assembly-language library routine,
- *	but not all systems have it.  Hence this C-language version
- *	which tries to be fairly machine-independent.
- *	Attempts to be clever about using word moves instead of byte moves.
- *	Does not hack overlapping backward moves.
- */
-bcopy(from, to, cnt)	/* Copy count bytes from -> to */
-register SBMA from;
-register SBMA to;
-register unsigned cnt;
-{
-	if(!cnt)
-		return;
-	while(rndrem((int)from))	/* Get source aligned */
-	  {     *to++ = *from++;
-		if(--cnt == 0) return;
-	  }
-	if(rndrem((int)to) == 0)	/* Do word move if dest now aligned */
-	  {	register unsigned tmp;
-		tmp = cnt;
-		if((cnt = rnddiv(cnt)) > 4)
-		  {	sbm_wcpy((int *)from, (int *)to, cnt);
-			if((cnt = rndrem(tmp)) == 0)
-				return;	/* No leftover bytes, all done */
-			tmp -= cnt;	/* Ugh, must update pointers */
-			from += tmp;
-			to += tmp;
-		  }
-		else cnt = tmp;		/* Not worth call overhead */
-	  }                             
-	do { *to++ = *from++; }		/* Finish up with byte loop */
-	while(--cnt);
-}
-
-/* SBM_WCPY - word-move auxiliary routine.
- *	This is a separate routine so that machines with only a few
- *	registers have a chance to use them for the word copy loop.
- *	This cannot be made part of BCOPY without doing some
- *	unnecessary pointer conversions and using extra variables
- *	(since most compilers will not accept type casts on lvalues,
- *	which are needed to treat (char *) as (int *)).
- */
-sbm_wcpy(from, to, cnt)
-register int *from, *to;
-register unsigned cnt;
-{
-	if(cnt)
-		do { *to++ = *from++; }
-		while(--cnt);
-}
Index: trunk/minix/commands/elle/sberr.c
===================================================================
--- trunk/minix/commands/elle/sberr.c	(revision 9)
+++ 	(revision )
@@ -1,686 +1,0 @@
-/* SB - Copyright 1982 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.  In all cases
- *	the source code and any modifications thereto must remain
- *	available to any user.
- *
- *	This is part of the SB library package.
- *	Any software using the SB library must likewise be made
- *	quasi-public, with freely available sources.
- */
-
-#define PRINT		/* Include printout stuff */
-
-#include "sb.h"
-#include <stdio.h>
-
-extern struct smblk *sbm_nfl;
-extern struct smblk *sbm_list;
-extern struct sdblk *sbx_nfl;
-
-#ifdef PRINT
-#define PRF(stmt) {if(p) stmt;}
-#define PRFBUG(str,stmt) {if(p) stmt;else return(str);}
-#define PRFBAD(str,stmt) {if(p) stmt; return(str);}
-#else
-#define PRF(stmt) ;
-#define PRFBUG(str,stmt) return(str);
-#define PRFBAD(str,stmt) return(str);
-#endif
-
-#ifndef NPTRS
-#define NPTRS (1000)		/* Catch loops of period less than this. */
-#endif
-
-int sbe_dec = 0;		/* Set nonzero to use decimal printout */
-
-struct ptab {
-	int pt_pflag;		/* Printflag value */
-	char *pt_err;		/* Error string return */
-	int pt_xerr;		/* Error index return */
-	int pt_hidx;		/* Highest freelist entry */
-	int pt_nsto;		/* # entries stored in table */
-	int pt_cnt;		/* # of entry store attempts */
-	struct smblk *pt_tab[NPTRS];
-};
-
-_PROTOTYPE( char *sbe_sdtab, (struct ptab *pt, int p, int phys) );
-_PROTOTYPE( char *sbe_schk, (struct sdblk *sd, struct ptab *pt) );
-_PROTOTYPE( int sbe_tbent, (struct ptab *pt, struct smblk *sm) );
-
-#define PTF_PRF	01	/* Do printout stuff */
-#define PTF_OVFERR 02	/* Complain if table overflows */
-#define PTF_SDPHYS 04	/* Follow SD phys links (else logical links) */
-
-struct flgt {
-	int flg_bit;
-	int flg_chr;
-};
-
-_PROTOTYPE( char *sbe_fstr, (int flags, struct flgt *fp) );
-
-char *sbe_mvfy(), *sbe_mfl(), *sbe_mlst();		/* SBM */
-char *sbe_sbvfy(), *sbe_sbs();				/* SBBUF */
-char *sbe_svfy(), *sbe_sdlist(), *sbe_sdtab(), *sbe_schk();	/* SD */
-char *sbe_fstr();				/* Misc utility */
-
-
-
-/* SBE_MEM() - Print out memory usage list
-*/
-sbe_mem()
-{
-	printf("\nMemory Usage:\n");
-	printf("\tsbm_nfl : %6o\n",sbm_nfl);
-	printf("\tsbm_list: %6o\n",sbm_list);
-	printf("\tsmblk nodes are %o bytes long.\n",sizeof (struct smblk));
-
-	sbe_mlst(1);		/* Scan mem list, printing stuff. */
-}
-
-/* SBE_MVFY() - Verify memory allocation structures
- *	Returns error message (0 if no errors found).
- */
-char *
-sbe_mvfy()
-{	register char *res;
-
-	if((res = sbe_mfl(0))
-	  || (res = sbe_mlst(0)))
-		return(res);
-	return(0);
-}
-
-
-/* SBM Debugging Routines */
-
-struct flgt smflgtab[] = {
-	SM_USE,	'U',
-	SM_NXM, 'N',
-	SM_EXT, 'E',
-	SM_MNODS,'M',
-	SM_DNODS,'D',
-	0,0
-};
-
-static char smfhelp[] = "U-Used, N-NXM, E-External, M-SMnodes, D-SDnodes";
-static char smhdline[] = "\
-      SM: back   smaddr   smlen  smuse  smflags";
-
-/* SBE_MFL(printflag) - Verify/Print memory freelist
- *	Returns error message (0 if no errors found).
- */
-char *
-sbe_mfl(p)
-int p;
-{	register struct smblk *sm;
-	register int i;
-	struct ptab smtab;		/* For loop detection */
-
-	PRF(printf("Tracing SM node freelist --\n"))
-	PRF(printf("    Maximum loop detection size is %d.", NPTRS))
-	if((sm = sbm_nfl) == 0)
-	  {	PRF(printf("\n\tNo list.\n"))
-		return(0);			/* Null freelist is ok */
-	  }
-	smtab.pt_pflag = p ? PTF_PRF : 0;
-	smtab.pt_nsto = smtab.pt_cnt = 0;
-	i = 0;				/* Print 8 addrs/line */
-	for(; sm; sm = sm->smforw)
-	  {
-		PRF(printf("%s%7o->", (i==0 ? "\n    " : ""), sm))
-		if(++i >= 8) i = 0;
-		if(sbe_tbent(&smtab, sm) < 0)	/* If hit loop, stop */
-			PRFBAD("SM freelist loop",
-			  printf("\nLOOP - %o seen as node %d!!\n",
-				sm, smtab.pt_xerr))
-		if(sm->smflags)
-		  {	PRF((i = 0, printf("\nFreelist node has flags:\n")))
-			PRFBUG("Free SM flagged", sbe_smp(sm, 0))
-		  }
-	  }
-	PRF(printf("\nEnd - %d nodes on SM freelist.\n", smtab.pt_cnt))
-	return(0);
-}
-
-/* SBE_MLST(printflag) - Verify/Print allocated memory list.
- *	Returns error message (0 if no errors found).
- */
-char *
-sbe_mlst(p)
-int p;
-{	register struct smblk *sm, *smf, *smb;
-	char *nextaddr;
-	int i;
-	struct ptab smtab;		/* For loop detection */
-
-	PRF(printf("Tracing mem list -- \n"))
-	if((sm = sbm_list) == 0)
-	  {	PRF(printf("\tNo list?!\n"))
-		if(sbm_nfl)		/* Ensure rest are 0 too */
-			return("No mem list?!!");
-		return(0);
-	  }
-
-	smtab.pt_pflag = p;
-	smtab.pt_cnt = smtab.pt_nsto = 0;
-	smb = 0;
-	PRF(printf("   Flags: %s\n%s\n", smfhelp, smhdline))
-	for(; sm; sm = smf)
-	  {	PRF(printf("  %6o: ",sm))
-		if(sbe_tbent(&smtab, sm) < 0)
-			PRFBAD("Loop in mem list!!",
-			  printf("LOOP - seen as node %d!!\n", smtab.pt_xerr))
-
-		if(sm->smback == smb)
-			PRF(printf("^ "))	/* Back ptr OK */
-
-		else PRFBUG("Bad back ptr!",
-			printf("%6o BAD Backptr!!\n\t    ",sm->smback))
-
-		if((sm->smflags&0377)!= SM_NID)
-			PRFBUG("SM: bad node ID",
-				printf("BAD - no node ID!\n\t    "))
-		PRF(printf((sm->smflags&SM_USE) ? "     " : "FREE "))
-		if(sm->smlen == 0)
-			PRFBUG("SM: len 0",
-				printf("Zero-length area!"))
-		if((sm->smflags&SM_USE)==0
-		  && rndrem(sm->smaddr - sbm_lowaddr))
-			PRFBUG("Bad free-mem block",
-				printf("Bad free-mem block"))
-		PRF(sbe_smp(sm, 1))		/* Print out rest of info */
-
-		if(nextaddr != sm->smaddr
-		  && smtab.pt_cnt != 1)		/* 1st time needs init */
-		  {	PRFBUG("Alignment error!",
-				printf("\t  BAD!! %6o expected; ",nextaddr))
-#if !(MINIX)
-			PRF((i = sm->smaddr - nextaddr) > 0
-				? printf("%d skipped.\n",i)
-				: printf("%d overlapped.\n",-i))
-#endif
-		  }
-		nextaddr = sm->smaddr + sm->smlen;
-		smf = sm->smforw;
-		smb = sm;			/* Save ptr to back */
-	  }
-	PRF(printf("End = %6o\n",nextaddr))
-	return(0);
-}
-
-#ifdef PRINT
-sbe_smp(sm,type)
-register struct smblk *sm;
-int type;
-{
-	if(type==0)
-		printf("  %6o:  %s  ", sm,
-			((sm->smflags&SM_USE) ? "    " : "FREE"));
-	printf("%6o: ", sm->smaddr);
-	printf((sbe_dec ? "%5d. %5d." : "%6o %6o"), sm->smlen, sm->smuse);
-	printf("  %7o = %s\n", sm->smflags, sbe_fstr(sm->smflags, smflgtab));
-}
-#endif /*PRINT*/
-
-
-/* SD (SBSTR) debugging routines */
-
-struct flgt sdflgtab[] = {
-	SD_LOCK, 'L',
-	SD_LCK2, 'T',
-	SD_MOD,	 '*',
-	0,0
-};
-
-static char sdfhelp[] = "\
-<f> flags: *-MOD (disk outofdate), L-LOCK, T-LCK2 (temp)";
-static char sdhdline[] = "\
-<f>      SD: slforw slback sdflgs sdforw sdback  sdmem sdfile  sdaddr sdlen";
-
-
-/* SBE_SFL(printflag) - Verify/Print SD freelist
- *	Returns error message (0 if no errors found).
- */
-char *
-sbe_sfl(p)
-int p;
-{	register struct sdblk *sd;
-	register int i;
-	struct ptab sdtab;		/* For loop detection */
-
-	PRF(printf("Tracing SDBLK node freelist --\n"))
-	PRF(printf("    Maximum loop detection size is %d.", NPTRS))
-	if((sd = sbx_nfl) == 0)
-	  {	PRF(printf("\n\tNo list.\n"))
-		return(0);			/* Null freelist is ok */
-	  }
-	sdtab.pt_pflag = p ? PTF_PRF : 0;
-	sdtab.pt_nsto = sdtab.pt_cnt = 0;
-	i = 0;				/* Print 8 addrs/line */
-	for(; sd; sd = sd->slforw)
-	  {
-		PRF(printf("%s%7o->", (i==0 ? "\n    " : ""), sd))
-		if(++i >= 8) i = 0;
-		if(sbe_tbent(&sdtab, sd) < 0)	/* If hit loop, stop */
-			PRFBAD("SD freelist loop",
-			  printf("\nLOOP - %o seen as node %d!!",
-				sd, sdtab.pt_xerr))
-		if(sd->sdflags)
-		  {	PRF((i = 0, printf("\nFreelist node has flags:\n")))
-			PRFBUG("Free SD flagged", sbe_psd(sd))
-		  }
-	  }
-	PRF(printf("\nEnd - %d nodes on SD freelist.\n", sdtab.pt_cnt))
-	return(0);
-}
-
-
-
-/* SBE_SDS() - Print out all sdblk data stuff
- */
-sbe_sds()
-{	int sbe_psd();
-
-	printf("Printout of all in-use SDBLKs:\n");
-	printf("  %s\n", sdfhelp);
-	printf("%s\n", sdhdline);
-	sbm_nfor(SM_DNODS,sizeof(struct sdblk),sbe_psd,0);
-	printf("\n");
-}
-
-/* SBE_PSD - Auxiliary for invocation by SBE_SDS above. */
-sbe_psd(sd)
-register struct sdblk *sd;
-{	register int flags;
-
-	flags = sd->sdflags;
-	printf("%c%c%c",
-		((flags&SD_MOD)  ? '*' : ' '),
-		((flags&SD_LOCK) ? 'L' : ' '),
-		((flags&SD_LCK2) ? 'T' : ' '));
-
-	printf(" %7o: %6o %6o %6o %6o %6o %6o %6o %7lo %5ld.\n", sd,
-		sd->slforw, sd->slback, sd->sdflags,
-		sd->sdforw, sd->sdback, sd->sdmem,
-		sd->sdfile, sd->sdaddr, sd->sdlen);
-	return(0);
-}
-
-/* SBE_SVFY() - Verify all SD blocks
- *	Returns error message (0 if no errors found).
- */
-char *
-sbe_svfy()
-{	register char *res;
-	return((res = sbe_sdlist(0,0)) ? res : sbe_sdlist(0,1));
-}
-
-/* SBE_SDLIST(printflag, physflag) - Verify/Print all SD blocks.
- *	Show logical lists if physflag 0
- *	Show physical lists otherwise
- *	Returns error message (0 if no errors found).
- */
-char *
-sbe_sdlist(p,phys)
-int p, phys;
-{	register char *res;
-	struct ptab sdtab;	/* The SDLIST table to use */
-
-	/* First put freelist in table, then scan for all
-	 * SD nodes.  Each active node (not in table) gets
-	 * its entire list traced forward/backward and added to table.
-	 */
-	if(res = sbe_sdtab(&sdtab, p, phys))	/* Set up freelist table */
-		return(res);
-
-	/* Freelist entered in table, now scan all SD's */
-	res = (char *)sbm_nfor(SM_DNODS,sizeof(struct sdblk),
-			sbe_schk, &sdtab);
-
-	PRF(printf("\n"))
-	return(res);
-}
-
-/* SBE_SDTAB(tableptr, printflag, physflag) - Auxiliary for SBE_SDLIST.
- *	Stuffs all freelist SDBLK addresses in table for dup detection.
- *	Returns error message (0 if no errors found).
- */
-char *
-sbe_sdtab(pt, p, phys)
-register struct ptab *pt;
-int p, phys;
-{	register struct sdblk *sd;
-	register int res;
-
-	pt->pt_pflag = (p ? PTF_PRF : 0) | (phys ? PTF_SDPHYS : 0)
-			| PTF_OVFERR;
-	pt->pt_cnt = pt->pt_nsto = 0;	/* Initialize */
-
-	/* Stick freelist in table */
-	for(sd = sbx_nfl; sd; sd = sd->slforw)
-	  {	if(sbe_tbent(pt, sd) < 0)
-		  {	if(pt->pt_xerr < 0)
-				PRFBAD("SD freelist too long",
-					printf("SD freelist too long (%d)\n",
-						NPTRS))
-			PRFBAD("SD freelist loop",
-			  printf("SD freelist loop at %o\n", pt->pt_xerr))
-		  }
-
-		if(sd->sdflags)
-		  {
-			PRF(printf("Bad free SD, non-zero flag:\n"))
-			PRFBUG("Free SD flagged", sbe_psd(sd))
-		  }
-	  }
-	pt->pt_hidx = pt->pt_nsto;	/* Set idx of 1st non-FL entry */
-	return(0);
-}
-
-
-/* SBE_SCHK(SDptr, tableptr) - Auxiliary for SBE_SDLIST.
- *	If SD not already in table, verifies or prints
- *	the complete physical or logical list it's on, and enters all
- *	of its SDs into table (to prevent doing it again).
- *	Returns 0 if no errors, else error string.
-** There is a problem when the table overflows.  The tbent routine
-** wants to add it (wrapping around at bottom) in that case, because
-** that still helps detect loops.  But this routine wants to reset
-** the table back (after scanning to head of list) and once it starts
-** scanning forward again it will fail, because some of the SDs are
-** still in the table due to the wraparound!  Thus PTF_OVFERR is always
-** set, in order to at least give the right error message.
-*/
-char *
-sbe_schk(sd, pt)
-register struct sdblk *sd;
-struct ptab *pt;
-{	register struct sdblk *sdx;
-	register struct smblk *sm;
-	struct sbfile *savfile;
-	chroff lastaddr;
-	int p, res, savidx, phys;
-
-	phys = pt->pt_pflag&PTF_SDPHYS;	/* Set up physflag */
-	if(phys && (sd->sdfile == 0))	/* Ignore non-phys stuff if phys */
-		return(0);
-	p = pt->pt_pflag&PTF_PRF;	/* Set up printflag */
-	savidx = pt->pt_nsto;		/* Remember initial extent of table */
-
-	if(sbe_tbent(pt, sd) < 0)
-	  {	if(pt->pt_xerr >= 0)	/* OK if already in table */
-			return(0);
-		PRFBAD("Too many SDs",
-			printf("Too many SDs for table (%d)\n",	NPTRS))
-	  }
-
-	/* Now search backward for start of list */
-	while(sdx = (phys ? sd->sdback : sd->slback))
-		if(sbe_tbent(pt,sdx) >= 0)
-			sd = sdx;
-		else break;
-	if(sdx)
-	  {	if(pt->pt_xerr < 0)	/* Table error? */
-			PRFBAD("Too many SDs",
-				printf("Too many SDs for table (%d)\n",NPTRS))
-		PRF(printf("Backlist loop!! Dup'd node:%s\n",
-				(pt->pt_xerr < pt->pt_hidx) ?
-					"(on freelist!)" : "" ))
-		PRFBUG((phys ? "Phys SD loop" : "SD loop"), sbe_psd(sdx))
-	  }
-	/* Reset table to flush nodes backed over */
-	pt->pt_cnt = pt->pt_nsto = savidx;
-
-	/* SD now points to start of list.  Begin stepping thru list... */
-	PRF(printf("---- %sList started: ", (phys ? "Phys " : "")))
-	if(phys)
-	  {	savfile = sd->sdfile;
-		PRF(printf(" SF: %o, fd= %d, ln= %ld\n",
-			savfile,savfile->sffd,savfile->sflen))
-		if(savfile->sfptr1 != sd)
-			PRFBUG("SFPTR1 bad",
-			  printf("  BAD!! Sfptr1 %o doesn't match SD %o!!\n",
-				savfile->sfptr1, sd))
-		lastaddr = 0;
-	  }
-	else PRF(printf("\n"))
-
-	PRF(printf("%s\n", sdhdline))
-	for(sdx = 0; sd; (sdx = sd, sd = (phys ? sd->sdforw : sd->slforw)))
-	  {
-		PRF(sbe_psd(sd))	/* Print it out */
-		if(sdx != (phys ? sd->sdback : sd->slback))
-		  {	if(phys)
-			  PRFBUG("PSD bad sdback",printf("\tBad phys backptr\n"))
-			else
-			  PRFBUG("SD bad slback",printf("\tBad backptr\n"))
-		  }
-
-		if((sd->sdflags&0377) != SD_NID)
-			PRFBUG("Bad SD node ID", printf("\tBad node ID!\n"))
-
-
-		if(sd->sdfile && (sd->sdlen < 0 || sd->sdaddr < 0))
-			PRFBUG("SD: neg len/addr",
-				printf("\tNeg disk len/addr\n"))
-		if(phys) goto dophys;
-
-		/* Do special stuff for logical list */
-		if(sm = sd->sdmem)
-		  {	if((sm->smflags&0377) != SM_NID)
-				PRFBUG("SD: bad SM",
-					printf("\nBad SMBLK ptr\n"))
-			if((sd->sdflags&SD_MOD)==0
-			  && sd->sdlen != sm->smuse)
-				PRFBUG("SD != SM",
-					printf("\tBad SMBLK? Len conflict\n"))
-			if(sm->smlen < sm->smuse)
-				PRFBUG("SD: SM len < use",
-					printf("\tBad SMBLK, len < use\n"))
-		  }
-		goto doboth;	/* Skip phys stuff */
-
-		/* Do special stuff for phys list */
-	dophys:	if(sd->sdfile != savfile)
-			PRFBUG("SD: bad sdfile",
-				printf("\tBad sdfile ptr! Shd be %o\n",
-					savfile))
-		if(sd->sdaddr < lastaddr)
-			PRFBUG("SD addr out of order",
-				printf("\tBad disk addr, not in order!\n"))
-		lastaddr = sd->sdaddr;
-		/* Done with special phys stuff */
-
-	doboth:	if(sbe_tbent(pt, sd) < 0)
-		  {	if(pt->pt_xerr < 0)
-				PRFBAD("Too many SDs",
-					printf("Too many SDs for table (%d)\n",NPTRS))
-
-			PRFBUG("SD loop",
-				printf("\tLOOP!! This SD already seen%s.\n",
-					(pt->pt_xerr < pt->pt_hidx) ?
-					" (on freelist!)" : "" ))
-			break;
-		  }
-	  }
-	PRF(printf("-----------\n"))
-	return(0);
-}
-
-
-/* SBE_DSK(SFptr) - Print out disk usage list for specific file
- */
-
-sbe_dsk(sfp)
-SBFILE *sfp;
-{
-	printf("SBFILE printout not coded: %o\n",sfp);
-}
-
-
-/* SBBUF structure debugging routines */
-
-struct flgt sbflgtab[] = {
-	SB_OVW, 'O',
-	SB_WRIT,'W',
-	0,0
-};
-static char sbfhelp[] = "O-Overwrite, W-Write";
-
-/* SBE_SBVFY(SBptr) - Verify a SB-string.
- *	Returns error message (0 if no errors found).
- */
-char *
-sbe_sbvfy(sbp)
-SBBUF *sbp;
-{	return(sbe_sbs(sbp,0));
-}
-
-/* SBE_SBS(SBptr, printflag) - Verify/Print SBSTR data stuff
- *	Returns error message (0 if no errors found).
- */
-char *
-sbe_sbs(sbp,p)
-SBBUF *sbp;
-int p;
-{	register SBBUF *sb;
-	register struct smblk *sm;
-	register struct sdblk *sd;
-
-	sb = sbp;
-	PRF(printf("SBSTR %o: ",sb))
-	if(sb == 0)
-		PRFBUG(0,printf("Zero pointer???\n"))
-
-	/* First print out cryptic summary in case pointers bomb
-	 * out farther on. */
-	PRF(printf(" (io,cur,r,w,f,.,+ = %o,%o,%d,%d,%o,%lo,%lo)\n",
-		sb->sbiop, sb->sbcur, sb->sbrleft, sb->sbwleft,
-		sb->sbflags, sb->sbdot, sb->sboff))
-
-	PRF(printf("  sbflags %5o = %s (%s)\n",
-			sb->sbflags, sbe_fstr(sb->sbflags,sbflgtab),
-			sbfhelp))
-
-	if(sd = sb->sbcur)	/* Okay, now try getting pointers */
-		sm = sd->sdmem;
-	else sm = 0;
-
-	PRF(printf("  sbcur %6o",sd))
-	if(sd)
-	  {
-		PRF(printf("\n   %s\n   ", sdhdline))
-		PRF(sbe_psd(sd))
-
-		if((sd->sdflags&0377) != SD_NID)
-			PRFBUG("SBCUR not SD?",printf("   BAD SDBLK ID!! \n"))
-		if(sm)
-		  {
-			PRF(printf("   %s\n   ", smhdline))
-			PRF(sbe_smp(sm,0))
-			if((sm->smflags&0377) != SM_NID)
-				PRFBUG("SBCUR has bad SM",
-					printf("   BAD SMBLK ID!!\n"))
-		  }
-	  }
-
-
-	PRF(printf("  sbiop  %6o",sb->sbiop))
-	if(sb->sbiop)
-	  {	if(!sm || sb->sbiop < sm->smaddr
-		  || sb->sbiop > (sm->smaddr + sm->smlen))
-			PRFBUG("Bad SBIOP", printf("  BAD"))
-	  }
-	else if(sb->sbrleft > 0 || sb->sbwleft > 0)
-		PRFBUG("Bad SBIOP/cnts", printf("  BAD"))
-	PRF(printf("\n"))
-
-	PRF(printf("  sbrleft %5o = %5d.",sb->sbrleft, sb->sbrleft))
-	if(sb->sbrleft
-	  && (	!sm
-	    ||	sb->sbwleft
-	    ||	(sb->sbflags&SB_WRIT)
-	    ||	(sb->sbrleft != (sm->smuse - (sb->sbiop - sm->smaddr)))
-	    ))
-		PRFBUG("Bad sbrleft", printf("  BAD"))
-	PRF(printf("\n"))
-
-	PRF(printf("  sbwleft %5o = %5d.", sb->sbwleft, sb->sbwleft))
-	if(sb->sbwleft
-	  && (	!sm
-	    ||	(sb->sbflags&SB_WRIT) == 0
-	    ||	(sb->sbwleft > (sm->smlen - (sb->sbiop - sm->smaddr)))
-	    ))
-		PRFBUG("Bad sbwleft", printf("  BAD"))
-	PRF(printf("\n"))
-
-	PRF(printf("  sbdot %7lo = %7ld.", sb->sbdot, sb->sbdot))
-	if(sb->sbdot < 0)
-		PRFBUG("Bad sbdot", printf("  BAD"))
-
-	PRF(printf("\n  sboff %7lo = %7ld.\n", sb->sboff, sb->sboff))
-	PRF(printf("  I/O ptr loc: %ld.\n\n", sb_tell(sb)))
-
-	return(0);
-}
-
-
-/* SBE_TBENT() - Auxiliary to add and check entries to a pointer table.
- *	Note we assume here that smblk ptrs are used, although sdblks
- *	can also be hacked.  This wins as long as the two kinds of ptrs
- *	are basically identical (saves horrible casting problems).
- *	Returns index # if successful (between 0 and NPTRS-1 inclusive).
- *	Otherwise an error (-1), with relevant info in pt_xerr:
- *		-1 if out of room and flag set making it an error
- *		0-n if entry already existed.
- */
-sbe_tbent(pt, sm)
-register struct ptab *pt;
-struct smblk *sm;
-{	register struct smblk **smt;
-	register int i;
-	int p;
-
-	p = pt->pt_pflag&PTF_PRF;	/* Set up print flag */
-	smt = &(pt->pt_tab[0]);
-	if(i = pt->pt_nsto)
-	  {	do {
-			if(sm == *smt++)
-			  {	pt->pt_xerr = pt->pt_nsto - i;
-				return(-1);
-			  }
-		  } while(--i);
-		--smt;
-	  }
-
-	i = pt->pt_cnt++;
-	if(++(pt->pt_nsto) > NPTRS)
-	  {	if(pt->pt_pflag&PTF_OVFERR)
-		  {	pt->pt_err = "Ptrtab overflow";
-			pt->pt_xerr = -1;
-			return(-1);
-		  }
-		pt->pt_nsto = NPTRS;
-		i %= NPTRS;
-	  }
-	pt->pt_tab[i] = sm;
-	return(i);
-}
-
-/* SBE_FSTR(flags, flagtab) - Auxiliary to convert flag word to a string
- *	and return pointer to it.  Handy for printfs.
- */
-char *
-sbe_fstr(flags, fp)
-register int flags;
-register struct flgt *fp;
-{	static char retstr[17];	/* Max of 16 flags */
-	register char *cp;
-	cp = retstr;
-	for(; fp->flg_bit; ++fp)
-		*cp++ = (fp->flg_bit&flags) ? fp->flg_chr : ' ';
-	*cp = 0;
-	return(retstr);
-}
Index: trunk/minix/commands/elle/sbm.c
===================================================================
--- trunk/minix/commands/elle/sbm.c	(revision 9)
+++ 	(revision )
@@ -1,923 +1,0 @@
-/* SB - Copyright 1982 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.  In all cases
- *	the source code and any modifications thereto must remain
- *	available to any user.
- *
- *	This is part of the SB library package.
- *	Any software using the SB library must likewise be made
- *	quasi-public, with freely available sources.
- */
-
-#if 0
-	This file contains the low-level memory allocation
-subroutines which are used by the SBLK routines.  The code here
-is quite machine-dependent, and the definitions in "sb.h" should be
-carefully checked to verify that they are correct for the target
-machine.
-
-	The ultimate low-level routine is "sbrk()" which must be
-provided by the system''s C library.  SBM expects that successive calls
-to sbrk() will return contiguous areas of memory with progressively
-higher addresses.  Also, the very first call to sbrk() is assumed to
-return a word-aligned address.
-#endif /*COMMENT*/
-
-#include "sb.h"
-
-#define FUDGE (sizeof(struct smblk))	/* Allow this much fudge in
-				allocation, to prevent undue fragmentation */
-
-char *(*sbm_debug)();           /* Debug switch - user-furnished routine */
-
-struct smblk *sbm_nfl;          /* Pointer to node freelist */
-struct smblk *sbm_nxtra;	/* Reserved extra free node */
-struct smblk *sbm_list;         /* Pointer to smblk memory alloc list.
-				 * ALL smblks are strung onto this list
-				 * except for the freelist!
-				 */
-SBMA sbm_lowaddr;		/* Lowest word-aligned address we know about.*/
-
-/* If compiling with debug switch set, use special routine in place of
- * sbrk so we can pretend we have a very limited area of free memory.
- */
-#ifdef DBG_SIZE
-#define SBM_SBRK sbm_brk
-char *sbm_brk();
-#else
-#define SBM_SBRK sbrk
-#endif /*DBG_SIZE*/
-
-/* Forward routine declarations */
-char *sbrk();
-struct smblk *sbm_nmak(), *sbm_nget(), *sbm_mget(), *sbm_split();
-struct smblk *sbm_lmak(), *sbm_err();
-
-
-/* SBM_INIT - Initialize storage management.
- *	If args are zero, normal initialization is done.  Otherwise,
- *	args are understood to be pointers to an area of memory allocated
- *	on the stack (eg by an "int mem[2000]" declaration in MAIN) and
- *	initialization will include this area in addition to the
- *	unused space between "_end" and the start of the stack segment.
- *	This is mostly of use for PDP11s which would otherwise waste a lot
- *	of address space.
- *	Maybe should have a SBM_RESET() function?
- */
-
-struct smblk *
-sbm_init(xaddr,xlen)
-SBMA xaddr;		/* Address of allocated stack area if any */
-SBMO xlen;		/* Size of this area */
-{       register struct smblk *sm, *sml;
-	register char *cp;
-
-	/* Get initial chunk of memory from standard system rtn */
-	if((cp = SBM_SBRK(SMNODES*sizeof(struct smblk))) == 0
-	  || (int) cp == -1)
-		return(sbm_err(0,"Can't sbrk"));
-	sm = (struct smblk *)cp;		/* Better be word-aligned! */
-	sbm_lmak(sm,(SBMO)sizeof(struct smblk),SMNODES);      /* Make list */
-	sbm_nfl = sm;				/* Point freelist at it */
-	sbm_lowaddr = (SBMA)sm;			/* Remember lowest addr seen */
-
-	/* Set up 1st node pointing to all memory from here on up.
-	 * We don't know exactly how much will be available at this point,
-	 * so we just pretend we have the maximum possible.
-	 */
-	sbm_list = sml = sbm_nget();
-	sml->smforw = sml->smback = 0;
-	sml->smflags = SM_USE|SM_NID;		/* Initial flags */
-	sml->smaddr = (SBMA) sml;
-	sml->smlen = MAXSBMO;			/* Pretend we have lots */
-	sml->smuse = (SMNODES * sizeof(struct smblk));
-
-	/* Now split off everything above initial allocation as NXM. */
-	sm = sbm_split(sml, sm->smuse);
-	sml->smflags |= SM_MNODS;	/* Mark 1st node as having SM nodes */
-	sm->smflags  |= SM_NXM;		/* Mark 2nd node as NXM */
-
-	/* Now possibly set up extra nodes, if stack mem is being allocated
-	 * (From our viewpoint it looks as if a chunk in the middle of
-	 * the initial NXM section has been declared usable)
-	 */
-	if(xlen)
-	  {     /* Allow for "extra" static stack memory */
-		/* Will lose if xaddr <= 1st NXM! */
-		sml = sbm_split(sm, (SBMO)(xaddr - sm->smaddr));
-		sbm_split(sml, xlen);		/* Split off following NXM */
-		sml->smflags &= ~(SM_USE|SM_NXM); /* This node is free mem! */
-	  }
-
-	/* Now set up a small additional node which points to the NXM
-	 * that we cannot get from SBRK.  At this stage, this is just
-	 * a place-holder, to reserve the node so we don't have to
-	 * worry about running out of nodes at the same time sbrk stops
-	 * returning memory.
-	 * SM points to the NXM that we expect SBRK to dig into.
-	 */
-	sbm_split(sm, sm->smlen - WDSIZE); /* Chop off teensy bit */
-	sm->smflags &= ~SM_USE;		/* Now mark NXM "free"!! */
-
-	/* Finally, reserve an "extra" SM node for use by sbm_nget
-	 * when it is allocating more freelist node chunks.
-	 */
-	sbm_nxtra = sbm_nget();
-
-	return(sbm_list);
-}
-
-
-/* SBM_NGET() - Get a free SM node.
- *	Note the hair to provide a spare SM node when
- *	we are allocating memory for more SM nodes.  This is necessary
- *	because sbm_mget and sbm_nget call each other recursively and
- *	sbm_mget cannot create any new memory without a SM node to point
- *	at the allocated chunk.
- */
-struct smblk *
-sbm_nget()
-{       register struct smblk *sm, *sml;
-
-	if(!(sm = sbm_nfl))		/* Get a node from freelist */
-	  {	/* Freelist is empty, try to allocate more nodes. */
-
-		/* Put our "spare" smblk on freelist temporarily so that
-		 * sbm_mget has a chance of winning.
-		 * Infinite recursion is avoided by a test
-		 * in sbm_mget which checks sbm_nfl and sbm_nxtra.
-		 */
-		if(!(sm = sbm_nxtra))
-			return(sbm_err(0,"Zero sbm_nxtra!"));
-		sm->smforw = 0;
-		sbm_nfl = sm;
-		sbm_nxtra = 0;
-
-		/* Try to allocate another chunk of SM nodes. */
-		sml = sbm_nmak(sizeof(struct smblk),SM_MNODS);
-
-		/* Put the new free nodes (if any) on freelist.
-		 * Done this way because freelist may have had one or two
-		 * nodes added to it by sbm_mget, so can't just stick
-		 * a new pointer in sbm_nfl.
-		 */
-		while(sm = sml)
-		  {	sml = sm->smforw;
-			sbm_nfre(sm);
-		  }
-
-		/* Now reserve an extra node again.
-		 * It is an error if there is nothing on freelist here,
-		 * because even if sbm_mget failed the "extra node" should
-		 * still be on freelist.  The check for a zero sbm_nxtra
-		 * above will catch such an error.
-		 */
-		sbm_nxtra = sbm_nget();
-
-		/* Now see if anything to return */
-		if(!(sm = sbm_nfl))		/* If freelist empty again, */
-			return(0);		/* give up. */
-	  }
-	sbm_nfl = sm->smforw;   /* If win, take it off freelist */
-	return(sm);		/* Return ptr or 0 if none */
-}
-
-/* SBM_NFRE(sm) - Return a SM node to the SM freelist.
- */
-sbm_nfre(smp)
-struct smblk *smp;
-{       register struct smblk *sm;
-	(sm = smp)->smflags = 0;
-	sm->smforw = sbm_nfl;
-	sbm_nfl = sm;
-}
-
-/* SBM_NMAK(elsize, flag) - Make (allocate & build) a typeless node freelist.
- */
-struct smblk *
-sbm_nmak(elsize, flag)
-SBMO elsize;
-unsigned flag;
-{       register struct smblk *sm, *smp;
-	register int cnt;
-
-	if((sm = sbm_mget(SMNODES*elsize,SMNODES*elsize)) == 0)
-		return(0);
-
-	sm->smflags |= flag;            /* Indicate type of nodes */
-	cnt = sm->smlen/elsize;		/* Find # nodes that will fit */
-	sm->smuse = cnt * elsize;	/* Actual size used */
-	smp = (struct smblk *)(sm->smaddr);	/* Ptr to 1st loc of mem */
-	sbm_lmak(smp, (SBMO)elsize, cnt);	/* Build freelist */
-	return(smp);            /* Return 1st free node. Caller is */
-				/* responsible for setting freelist ptr. */
-}
-
-/* SBM_LMAK - Build freelist of typeless nodes.
- *	Note this does not allocate memory, it just converts an already
- *	allocated memory area.
- */
-struct smblk *
-sbm_lmak(addr, elsize, num)
-SBMA addr;
-SBMO elsize;
-int num;
-{	register struct smblk *sm, *smp;
-	register int cnt;
-
-	smp = (struct smblk *) addr;
-	if((cnt = num) <= 0)
-		return(0);
-	do {	sm = smp;       /* Save ptr */
-		sm->smforw = (smp = (struct smblk *) ((SBMA)smp + elsize));
-		sm->smflags = 0;
-	  } while(--cnt);
-	sm->smforw = 0;         /* Last node points to nothing */
-	return(sm);		/* Return ptr to last node */
-}
-
-/* SBM_NMOV(sm1, sm2, begp, elsize) - Move a typeless node.
- *	Copy sm1 to sm2, adjust ptrs, leave sm1 free.
- */
-sbm_nmov(smp1,smp2,begp,elsize)
-struct smblk *smp1, *smp2, **begp;
-int elsize;
-{       register struct smblk *sm;
-
-	bcopy((SBMA)smp1,(SBMA)(sm = smp2), elsize);     /* Copy the stuff */
-	if(sm->smforw) sm->smforw->smback = sm; /* Fix up links */
-	if(sm->smback) sm->smback->smforw = sm;
-	else *begp = sm;
-}
-
-
-/* SBM_MGET(min,max) - Get a SMBLK with specified amount of memory.
- *      Returns 0 if none available.
- *      Memory is guaranteed to start on word boundary, but may not
- *              end on one.  Note that sbm_mfree is responsible for
- *              ensuring that free mem starts word-aligned.
- *	A subtle but major concern of this code is the number of freelist
- * nodes gobbled by a single call.  If the freelist happens to not have
- * enough nodes, then a recursive call to sbm_mget is made (via sbm_nget)
- * in order to allocate a new batch of freelist nodes!  sbm_nget will
- * always provide a single "spare" node during such an allocation, but
- * there is only one and it is essential that sbm_mget gobble only ONE
- * (if any) during such a call, which is indicated by sbm_nxtra==0.
- *	The maximum # of freelist nodes that sbm_mget can gobble is
- * 2, when (1) NXM memory is obtained, and a SM is needed to point at
- * the new free mem, plus (2) the resulting SM is too big, and has to
- * be split up, which requires another SM for the remainder.
- *	The "used-NXM" smblk is set up at init time precisely in order to
- * avoid the necessity of creating it here when sbrk stops winning, since
- * that would require yet another freelist node and make it possible for
- * sbm_mget to gobble 3 during one call -- too many.
- *	Further note: the sbm_nfl checks are necessary in order
- * to ensure that a SM node is available for use by sbm_split.  Otherwise
- * the calls to sbm_split might create a new SM freelist by gobbling the
- * very memory which we are hoping to return!
- */
-SBMO sbm_chksiz = SMCHUNKSIZ;	/* Current chunk size to feed sbrk */
-
-struct smblk *
-sbm_mget(cmin,cmax)
-SBMO cmin,cmax;
-{       register struct smblk *sm, *sml;
-	register SBMO csiz;
-	register SBMA addr, xaddr;
-
-	if((sm = sbm_list) == 0         /* If never done, */
-	  && (sm = sbm_init((SBMA)0,(SBMO)0)) == 0)	/* initialize mem alloc stuff. */
-		return(0);		/* Can't init??? */
-
-	/* Round up sizes to word boundary */
-	if(rndrem(cmin)) cmin = rndup(cmin);
-	if(rndrem(cmax)) cmax = rndup(cmax);
-
-	/* Search for a free block having enough memory.
-	 * If run into a free-NXM block, always "win", since there may be
-	 * a combination of preceding free-mem and new mem which will satisfy
-	 * the request.  If it turns out this didn't work, we'll just fail
-	 * a little farther on.
-	 */
-retry:	csiz = cmin;			/* Set size that will satisfy us */
-	do {
-		if(  ((sm->smflags&SM_USE) == 0)
-		  && ((sm->smlen >= csiz) || (sm->smflags&SM_NXM)) )
-			break;
-	  } while(sm = sm->smforw);
-	if(sm == 0)
-		return(0);	/* Found none that minimum would fit */
-
-	if(sm->smflags&SM_NXM)
-	  {	/* Found free area, but it's marked NXM and the system
-		 * must be persuaded (via sbrk) to let us use that portion
-		 * of our address space.  Grab a good-sized chunk.
-		 */
-		if(sbm_nfl == 0)	/* Verify a spare SM node is avail */
-			goto getnod;	/* Nope, must get one. */
-
-		/* Decide amount of mem to ask system for, via sbrk.
-		 * The fine point here is the check of sbm_nxtra to make sure
-		 * that, when building more freelist nodes, we don't have
-		 * to use more than one SM node in the process.  If we
-		 * asked for too much mem, we'd have to use a SM node
-		 * to hold the excess after splitting.
-		 */
-		csiz = cmax;
-		if(sbm_nxtra		/* If normal then try for big chunk */
-		  && csiz < sbm_chksiz) csiz = sbm_chksiz;	/* Max */
-		if (csiz > sm->smlen)  csiz = sm->smlen;	/* Min */
-
-		/* Get the NXM mem */
-		if((addr = (SBMA)SBM_SBRK(csiz)) != sm->smaddr)
-		  {     /* Unexpected value returned from SBRK! */
-
-			if((int)addr != 0 && (int)addr != -1)
-			  {	return(sbm_err(0,"SBRK %o != %o", addr,
-						sm->smaddr));
-#if 0
-			/* If value indicates couldn't get the stuff, then
-			 * we have probably hit our limit and the rest of
-			 * NXM should be declared "used" to prevent further
-			 * hopeless sbrk calls.  We split off the portion
-			 * of NXM that is known for sure to be unavailable,
-			 * and mark it "used".  If a "used NXM" area already
-			 * exists following this one, the two are merged.
-			 * The chunk size is then reduced by half, so
-			 * only log2(SMCHUNKSIZ) attempts will be made, and
-			 * we try again.
-			 */
-				/* If returned some mem which starts outside
-				 * the NXM then something is screwed up. */
-				if(addr < sm->smaddr
-				  || (addr >= sm->smaddr+sm->smlen))
-					return(sbm_err(0,"SBRK %o != %o",
-						addr, sm->smaddr));
-				/* Got some mem, falls within NXM.
-				 * Presumably someone else has called sbrk
-				 * since last time, so we need to fence off
-				 * the intervening area. */
-				sm = sbm_split((sml=sm),(addr - sm->smaddr));
-				sml->smflags |= SM_USE|SM_EXT;
-				return(sbm_mget(cmin,cmax));
-#endif /*COMMENT*/
-			  }
-
-			/* Handle case of SBRK claiming no more memory.
-			 * Gobble as much as we can, and then turn this NXM
-			 * block into a free-mem block, and leave the
-			 * remainder in the used-NXM block (which should
-			 * immediately follow this free-NXM block!)
-			 */
-			if(!(sml = sm->smforw)	/* Ensure have used-NXM blk */
-			  || (sml->smflags&(SM_USE|SM_NXM))
-					!= (SM_USE|SM_NXM))
-				return(sbm_err(0,"No uNXM node!"));
-			xaddr = sm->smaddr;	/* Use this for checking */
-			sm->smuse = 0;		/* Use this for sum */
-			for(csiz = sm->smlen; csiz > 0;)
-			  {	addr = SBM_SBRK(csiz);
-				if((int)addr == 0 || (int)addr == -1)
-				  {	csiz >>= 1;
-					continue;
-				  }
-				if(addr != xaddr)
-					return(sbm_err(0,"SBRK %o != %o", addr,
-						xaddr));
-				sm->smuse += csiz;
-				xaddr += csiz;
-			  }
-
-			/* Have gobbled as much from SBRK as we could.
-			 * Turn the free-NXM block into a free-mem block,
-			 * unless we got nothing, in which case just merge
-			 * it into the used-NXM block and continue
-			 * searching from this point.
-			 */
-			if(!(csiz = sm->smuse))	/* Get total added */
-			  {	sm->smflags = sml->smflags;	/* Ugh. */
-				sbm_mmrg(sm);
-				goto retry;		/* Keep looking */
-			  }
-			else
-			  {	sml->smaddr = sm->smaddr + csiz;
-				sml->smlen += sm->smlen - csiz;
-				sm->smlen = csiz;
-				sm->smflags &= ~SM_NXM;	/* No longer NXM */
-			  }
-		  }
-
-		/* Here when we've acquired CSIZ more memory from sbrk.
-		 * If preceding mem area is not in use, merge new mem
-		 * into it.
-		 */
-		if((sml = sm->smback) && 
-		  (sml->smflags&(SM_USE|SM_NXM))==0)    /* Previous free? */
-		  {     sml->smlen += csiz;		/* Yes, simple! */
-			sm->smaddr += csiz;		/* Fix up */
-			if((sm->smlen -= csiz) == 0)	/* If no NXM left,*/
-				sbm_mmrg(sml);	/* Merge NXM node w/prev */
-			sm = sml;		/* Prev is now winning node */
-		  }
-		else
-		  {	/* Prev node isn't a free area.  Split up the NXM
-			 * node to account for acquired mem, unless we
-			 * gobbled all the mem available.
-			 */
-			if(sm->smlen > csiz	/* Split unless all used */
-			  && !sbm_split(sm,csiz)) /* Call shd always win */
-				return(sbm_err(0,"getsplit err: %o",sm));
-			sm->smflags &= ~SM_NXM;	/* Node is now real mem */
-		  }
-
-		/* Now make a final check that we have enough memory.
-		 * This can fail because SBRK may not have been able
-		 * to gobble enough memory, either because (1) not
-		 * as much NXM was available as we thought,
-		 * or (2) we noticed the free-NXM area and immediately
-		 * gambled on trying it without checking any lengths.
-		 * In any case, we try again starting from the current SM
-		 * because there may be more free mem higher up (eg on
-		 * stack).
-		 */
-		if(sm->smlen < cmin)
-			goto retry;
-	  }
-
-	/* Check to see if node has too much mem.  This is especially true
-	 * for memory just acquired via sbrk, which gobbles a huge chunk each
-	 * time.  If there's too much, we split up the area.
-	 */
-	if(sm->smlen > cmax+FUDGE)	/* Got too much?  (Allow some fudge)*/
-		/* Yes, split up so don't gobble too much. */
-		if(sbm_nfl)                     /* If success guaranteed, */
-			sbm_split(sm,cmax);     /* split it, all's well. */
-		else goto getnod;
-
-	sm->smuse = 0;
-	sm->smflags |= SM_USE;  /* Finally seize it by marking "in-use". */
-	return(sm);
-
-	/* Come here when we will need to get another SM node but the
-	 * SM freelist is empty.  We have to forget about using the area
-	 * we just found, because sbm_nget may gobble it for the
-	 * freelist.  So, we first force a refill of the freelist, and then
-	 * invoke ourselves again on what's left.
-	 */
-getnod:
-	if(sml = sbm_nget())		/* Try to build freelist */
-	  {	sbm_nfre(sml);		/* Won, give node back, */
-		sm = sbm_list;		/* and retry, starting over! */
-		goto retry;	
-	  }
-	/* Failed.  Not enough memory for both this request
-	 * and one more block of SM nodes.  Since such a SM_MNODS
-	 * block isn't very big, we are so close to the limits that it
-	 * isn't worth trying to do something fancy here to satisfy the
-	 * original request.  So we just fail.
-	 */
-	return(0);
-}
-
-#ifdef DBG_SIZE
-/* Code for debugging stuff by imposing an artificial limitation on size
- * of available memory.
- */
-SBMO sbm_dlim = MAXSBMO;	/* Amount of mem to allow (default is max) */
-
-char *
-sbm_brk(size)
-unsigned size;
-{	register char *addr;
-
-	if(size > sbm_dlim) return(0);
-	addr = sbrk(size);
-	if((int)addr == 0 || (int)addr == -1)
-		return(0);
-	sbm_dlim -= size;
-	return(addr);
-}
-#endif /*DBG_SIZE*/
-
-
-/* SBM_MFREE(sm) - Free up an allocated memory area.
- */
-sbm_mfree(sm)
-register struct smblk *sm;
-{       register struct smblk *smx;
-	register SBMO crem;
-
-	sm->smflags &= ~SM_USE;			/* Say mem is free */
-	if((smx = sm->smback)                   /* Check preceding mem */
-	  && (smx->smflags&(SM_USE|SM_NXM))==0) /*   If it's free, */
-		sbm_mmrg(sm = smx);		/*   then merge 'em. */
-	if((smx = sm->smforw)			/* Check following mem */
-	  && (smx->smflags&(SM_USE|SM_NXM))==0) /*   Again, if free,  */
-		sbm_mmrg(sm);                   /*   merge them.   */
-
-	if(sm->smlen == 0)              /* Just in case, chk for null blk */
-	  {     if(smx = sm->smback)            /* If pred exists, */
-			sbm_mmrg(smx);          /* merge quietly. */
-		else {
-			sbm_list = sm->smforw;  /* 1st node on list, so */
-			sbm_nfre(sm);           /* simply flush it. */
-		  }
-		return;
-	  }
-
-	/* This code is slightly over-general for some machines.
-	 * The pointer subtraction is done in order to get a valid integer
-	 * offset value regardless of the internal representation of a pointer.
-	 * We cannot reliably force alignment via casts; some C implementations
-	 * treat that as a no-op.
-	 */
-	if(crem = rndrem(sm->smaddr - sbm_lowaddr))	/* On word bndry? */
-	  {     /* No -- must adjust.  All free mem blks MUST, by fiat,
-		 * start on word boundary.  Here we fix things by
-		 * making the leftover bytes belong to the previous blk,
-		 * no matter what it is used for.  Prev blk is guaranteed to
-		 * (1) Exist (this cannot be 1st blk since 1st is known to
-		 * start on wd boundary) and to be (2) Non-free (else it would
-		 * have been merged).
-		 */
-		if((smx = sm->smback) == 0)     /* Get ptr to prev blk */
-		  {	sbm_err(0,"Align err");	/* Catch screws */
-			return;
-		  }
-		crem = WDSIZE - crem;	/* Find # bytes to flush */
-		if(crem >= sm->smlen)	/* Make sure node has that many */
-		  {	sbm_mmrg(smx);  /* Flush node to avoid zero length */
-			return;
-		  }
-		smx->smlen += crem;	/* Make stray bytes part of prev */
-		sm->smaddr += crem;	/* And flush from current. */
-		sm->smlen -= crem;
-	  }
-}
-
-
-/* SBM_EXP - Expand (or shrink) size of an allocated memory chunk.
- *	"nsize" is desired new size; may be larger or smaller than current
- *	size.
- */
-struct smblk *
-sbm_exp(sm,size)
-register struct smblk *sm;
-register SBMO size;
-{       register struct smblk *smf;
-	register SBMO mexp, pred, succ;
-
-	if(sm->smlen >= size)		/* Do we want truncation? */
-		goto realo2;		/* Yup, go split block */
-
-	/* Block is expanding. */
-	mexp = size - sm->smlen;		/* Get # bytes to expand by */
-	pred = succ = 0;
-	if((smf = sm->smforw)           	/* See if free mem follows */
-	 && (smf->smflags&(SM_USE|SM_NXM)) == 0)
-		if((succ = smf->smlen) >= mexp)
-			goto realo1;		/* Quick stuff if succ OK */
-
-	if((smf = sm->smback)			/* See if free mem precedes */
-	 && (smf->smflags&(SM_USE|SM_NXM)) == 0)
-		pred = smf->smlen;
-
-	/* If not enough free space combined on both sides of this chunk,
-	 * we have to look for a completely new block.
-	 */
-	if(pred+succ < mexp)
-	  {	if((smf = sbm_mget(size,size)) == 0)
-			return(0);              /* Couldn't find one */
-		else pred = 0;			/* Won, indicate new block */
-	  }
-
-	/* OK, must copy either into new block or down into predecessor
-	 * (overlap is OK as long as bcopy moves 1st byte first)
-	 */
-	bcopy(sm->smaddr, smf->smaddr, sm->smlen);
-	smf->smflags = sm->smflags;     /* Copy extra attribs */
-	smf->smuse = sm->smuse;
-	if(!pred)			/* If invoked sbm_mget */
-	  {	sbm_mfree(sm);		/* then must free up old area */
-		return(smf);		/* and can return immediately. */
-	  }
-	sbm_mmrg(smf);			/* Merge current into pred blk */
-	sm = smf;			/* Now pred is current blk. */
-
-	if(succ)
-realo1:		sbm_mmrg(sm);		/* Merge succ into current blk */
-realo2: if(sm->smlen > size		/* If now have too much, */
-	  && sbm_split(sm, size))       /* split up and possibly */
-		sbm_mfree(sm->smforw);  /* free up unused space. */
-	return(sm);
-
-	/* Note that sbm_split can fail if it can't get a free node,
-	 * which is only possible if we are reducing the size of an area.
-	 * If it fails, we just return anyway without truncating the area.
-	 */
-}
-
-
-/* SBM_MMRG(sm) - Merge a memory area with the area following it.
- *	The node (and memory area) following the SM pointed to are
- *	merged in and the successor node freed up.  The flags
- *	and smuse of the current SM (which is not moved or anything)
- *	remain the same.
- */
-sbm_mmrg(smp)
-struct smblk *smp;
-{       register struct smblk *sm, *sm2;
-
-	sm = smp;
-	sm->smlen += (sm2 = sm->smforw)->smlen;	/* Add succ's len */
-	if(sm->smforw = sm2->smforw)            /* and fix linkages */
-		sm->smforw->smback = sm;
-	sbm_nfre(sm2);                          /* now can flush succ node */
-}
-
-/* SBM_SPLIT - Split up an area (gets a new smblk to point to split-off
- *	portion.)
- * Note returned value is ptr to 2nd smblk, since this is a new one.
- * Ptr to 1st remains valid since original smblk stays where it is.
- * NOTE: Beware of splitting up free mem (SM_USE == 0) since sbm_nget may
- * steal it out from under unless precautions are taken!  See comments
- * at sbm_mget related to this.
- */
-struct smblk *
-sbm_split(smp,coff)
-struct smblk *smp;
-SBMO coff;
-{       register struct smblk *sm, *smx;
-	register SBMO csiz;
-
-	if((sm = smp)->smlen <= (csiz = coff))
-		return(0);
-	if((smx = sbm_nget()) == 0)
-		return(0);
-	smx->smlen = sm->smlen - csiz;          /* Set 2nd size */
-	smx->smaddr = sm->smaddr + csiz;        /* Set 2nd addr */
-	sm->smlen = csiz;			/* Take from 1st size */
-	smx->smflags = sm->smflags;             /* Copy flags */
-	if(smx->smforw = sm->smforw)            /* Splice 2nd after 1 */
-		smx->smforw->smback = smx;
-	smx->smback = sm;
-	sm->smforw = smx;                       /* Put 2nd into chain */
-	return(smx);                            /* Return ptr to 2nd smblk */
-}
-
-#if 0	/* Replaced by "bcopy" for system-dep efficiency */
-/* SBM_SCPY - Copy string of bytes.  Somewhat machine-dependent;
- *	Tries to be clever about using word moves instead of byte moves.
- */
-sbm_scpy(from, to, count)       /* Copy count bytes from -> to */
-char *from, *to;
-unsigned count;
-{       register char *s1, *s2;
-	register unsigned cnt;
-	int tmp;
-
-	if((cnt = count) == 0)
-		return;
-	s1 = from;
-	s2 = to;
-	while(rndrem((int)s1))		/* Get 1st ptr aligned */
-	  {     *s2++ = *s1++;
-		if(--cnt == 0) return;
-	  }
-	if(rndrem((int)s2) == 0)	/* Do wd move if ptr 2 now aligned */
-	  {
-#ifdef DUMBPCC /* Code for dumber (Portable C type) compiler */
-		register WORD *ap, *bp;
-		tmp = cnt;
-		ap = (WORD *) s1;
-		bp = (WORD *) s2;
-		if(cnt = rnddiv(cnt))
-			do { *bp++ = *ap++; }
-			while(--cnt);
-		if ((cnt = rndrem(tmp)) ==0)
-			return;
-		s1 = (char *) ap;
-		s2 = (char *) bp;
-#else
-	/* Tight loop for efficient copying on 11s */
-		tmp = cnt;
-		if(cnt = rnddiv(cnt))
-			do { *((WORD *)s2)++ = *((WORD *)s1)++; }
-			while(--cnt);
-		if((cnt = rndrem(tmp)) == 0)
-			return;
-#endif /*-DUMBPCC*/
-	  }                             
-	do { *s2++ = *s1++; }	/* Finish up with byte loop */
-	while(--cnt);
-}
-#endif /*COMMENT*/
-
-struct smblk *		/* If it returns at all, this is most common type */
-sbm_err(val,str,a0,a1,a2,a3)
-char *str;
-struct smblk *val;
-{	int *sptr;
-
-	sptr = (int *) &sptr;	/* Point to self on stack */
-	sptr += 5;		/* Point to return addr */
-	if((int)sbm_debug==1)
-		abort();
-	if(sbm_debug)
-		(*sbm_debug)(0,*sptr,str,a0,a1,a2,a3);
-	return(val);
-}
-
-
-/* These routines correspond to the V7 LIBC routines as described
- * in the V7 UPM (3).  They should provide satisfactory emulation
- * if the documentation is correct.  Replacement is necessary since
- * the SBM routines are jealous and cannot tolerate competition for
- * calls of SBRK; i.e. the memory being managed must be contiguous.
- */
-
-/* Guaranteed to return word-aligned pointer to area of AT LEAST
- * requested size.  Area size is rounded up to word boundary.
- */
-
-char *
-malloc(size)
-unsigned size;
-{       register struct smblk *sm, **sma;
-	register SBMO siz;
-
-	siz = rndup(size + sizeof (struct smblk *));   /* Make room for ptr */
-	if((sm = sbm_mget(siz,siz)) == 0)
-		return(0);
-	*(sma = (struct smblk **)sm->smaddr) = sm; /* Store ptr in addr-1 */
-	return((char *)++sma);
-}
-
-char *
-alloc(size)     /* For V6 programs - note different failure value! */
-unsigned size;
-{       register char *addr;
-	return((addr = malloc(size)) ? addr : (char *) -1);
-}
-
-free(ptr)
-char *ptr;
-{       register struct smblk *sm, **smp;
-
-	smp = &((struct smblk **)ptr)[-1];	/* Point to addr-1 */
-	sm = *smp;				/* Pluck SM ptr therefrom */
-	if(((sm->smflags&0377) != SM_NID) || sm->smaddr != (SBMA)smp)
-		return((int)sbm_err(0,"free: bad arg %o", ptr));
-	sbm_mfree(sm);
-	return(1);
-}
-
-char *
-realloc(ptr,size)
-char *ptr;
-unsigned size;
-{       register struct smblk *sm, **smp;
-
-	smp = &((struct smblk **)ptr)[-1];	/* Point to addr-1 */
-	sm = *smp;				/* Pluck SM ptr therefrom */
-	if(((sm->smflags&0377) != SM_NID) || (sm->smaddr != (SBMA)smp))
-		return((char *)sbm_err(0,"realloc: bad arg %o",ptr));
-	if((sm = sbm_exp(sm, rndup(size+(sizeof(struct smblk *))))) == 0)
-		return(0);
-	*(smp = (struct smblk **)sm->smaddr) = sm;      /* Save smblk ptr */
-	return((char *)++smp);
-}
-
-char *
-calloc(nelem,elsize)
-unsigned nelem, elsize;
-{       register SBMO cmin;
-	register WORD *ip;                     /* Clear in units of words */
-	register char *addr;
-
-	if((cmin = nelem*elsize) == 0           /* Find # bytes to get */
-	  || (addr = malloc(cmin)) == 0)        /* Get it */
-		return(0);
-	ip = (WORD *) addr;			/* Set up ptr to area */
-	cmin = rnddiv(cmin+WDSIZE-1);		/* Find # words to clear */
-	do { *ip++ = 0; } while (--cmin);       /* Zap the area */
-	return(addr);
-}
-
-
-/* SBM_NGC() - Specific routine for GC'ing SMBLK nodes.
- *
- * SBM_XNGC(begp, elsize, type) - Compact nodes of specified type.
- *      Scans allocated mem from low to high to find chunks with nodes of
- *	the specified type.
- *      Flushes current freelist and rebuilds it as scan progresses,
- *      such that 1st thing on list is lowest-addr node.  When a node is
- *      seen that can be moved, new node is acquired from freelist if
- *      it exists, otherwise no move is made.  If a chunk has been scanned
- *      and no active nodes remain, it is flushed and freelist updated.
- *      NOTE: This has not yet been verified to work with nodes of any
- *		type other than SMBLK.
- */
-
-sbm_ngc()
-{	register struct smblk *sm;
-	if(!(sm = sbm_nxtra))
-		return((int)sbm_err(0,"Zero sbm_nxtra"));
-	sm->smflags |= SM_USE;		/* Ensure this one isn't GC'd */
-	sbm_xngc(&sbm_nfl, sizeof(struct smblk), SM_MNODS);
-	sm->smflags = 0;		/* Flush temporary crock */
-}
-sbm_xngc(begp, elsize, flag)
-struct smblk **begp;
-unsigned elsize, flag;
-{       register struct smblk *sm, *chk, *smf;
-	struct smblk *ftail, *savtail;
-	int cnt, inuse;
-
-	*begp = ftail = 0;		/* Flush node freelist */
-	for(chk = sbm_list; chk; chk = chk->smforw)
-	  if(chk->smflags&flag)
-	    {   sm = (struct smblk *) chk->smaddr;
-		cnt = (chk->smuse)/elsize;
-		savtail = ftail;
-		inuse = 0;
-		smf = *begp;
-					 /* Set up ptr to 1st freelist node */
-		while(--cnt >= 0)
-		  {     /* Here decide if movable */
-			if(sm->smflags && smf   /* Live and have copy place */
-			  && (
-				(sm->smflags&SM_USE) == 0       /* Free mem? */
-			    ||  (sm->smflags&(SM_MNODS|SM_DNODS))
-			     )
-			  && sm->smback)        /* has backptr (see ncpy) */
-			  {                             /* Move the node */
-				*begp = smf->smforw;	/* Get free node */
-				if(smf == ftail)
-					ftail = 0;
-				if(smf == savtail)
-					savtail = 0;
-				/* Move node.  Already checked for back ptr
-				 * of 0 since no obvious way to tell where
-				 * the ptr to list is kept.  Sigh.
-				 */
-				sbm_nmov(sm,smf,(struct smblk **)0,elsize);
-				/* Get ptr to new freelist node.  Note
-				 * check to ensure that it is not in this
-				 * same chunk (if it is, no point in moving
-				 * any nodes!)
-				 */
-				if((smf = *begp) >= chk)
-					smf = 0;        /* Zero if same chk */
-				sm->smflags = 0;        /* Make node free */
-			  }
-			/* At this point, not movable */
-			if(sm->smflags == 0)            /* Free node? */
-			  {     if(ftail)               /* Add to freelist */
-					ftail->smforw = sm;
-				ftail = sm;
-				if(*begp == 0)
-					*begp = sm;
-				sm->smforw = 0;
-			  }
-			else inuse++;
-			sm = (struct smblk *)((SBMA)sm + elsize);
-		  }
-		if(inuse == 0                           /* All free? */
-		  && (sm = chk->smback))		/* & not 1st? */
-		  {     if(savtail)                     /* Edit freelist */
-				(ftail = savtail)->smforw = 0;
-			else *begp = ftail = 0;
-			sbm_mfree(chk);
-			chk = sm;
-		  }
-	    }
-}
-
-/*
- *      Note that proc must return a zero value, or loop aborts and
- *      returns that selfsame value.
- */
-sbm_nfor(flag,nodsiz,proc,arg)
-int flag;
-int (*proc)();
-int nodsiz;
-struct sbfile *arg;
-{       register struct smblk *sm, *np;
-	register int cnt;
-	int res;
-
-	for(sm = sbm_list; sm; sm = sm->smforw)
-	  if(sm->smflags&flag)
-	    {   np = (struct smblk *) sm->smaddr;
-		cnt = sm->smuse/nodsiz;
-		do {
-			if(np->smflags)
-				if(res = (*proc)(np,arg))
-					return(res);
-			np = (struct smblk *)((SBMA)np + nodsiz);
-		  } while(--cnt);
-	    }
-	return(0);
-}
Index: trunk/minix/commands/elle/sbproto.h
===================================================================
--- trunk/minix/commands/elle/sbproto.h	(revision 9)
+++ 	(revision )
@@ -1,120 +1,0 @@
-#ifndef _ANSI
-#include <ansi.h>
-#endif
-
-/* sbbcpy.c */
-_PROTOTYPE( int bcopy, (SBMA from, SBMA to, unsigned cnt) );
-_PROTOTYPE( int sbm_wcpy, (int *from, int *to, unsigned cnt) );
-
-/* sberr.c */
-_PROTOTYPE( int sbe_mem, (void) );
-_PROTOTYPE( char *sbe_mvfy, (void) );
-_PROTOTYPE( char *sbe_mfl, (int p) );
-_PROTOTYPE( char *sbe_mlst, (int p) );
-_PROTOTYPE( int sbe_smp, (struct smblk *sm, int type) );
-_PROTOTYPE( char *sbe_sfl, (int p) );
-_PROTOTYPE( int sbe_sds, (void) );
-_PROTOTYPE( int sbe_psd, (struct sdblk *sd) );
-_PROTOTYPE( char *sbe_svfy, (void) );
-_PROTOTYPE( char *sbe_sdlist, (int p, int phys) );
-_PROTOTYPE( int sbe_dsk, (SBFILE *sfp) );
-_PROTOTYPE( char *sbe_sbvfy, (SBBUF *sbp) );
-_PROTOTYPE( char *sbe_sbs, (SBBUF *sbp, int p) );
-
-/* sbm.c */
-_PROTOTYPE( struct smblk *sbm_init, (SBMA xaddr, SBMO xlen) );
-_PROTOTYPE( struct smblk *sbm_nget, (void) );
-_PROTOTYPE( int sbm_nfre, (struct smblk *smp) );
-_PROTOTYPE( struct smblk *sbm_nmak, (SBMO elsize, unsigned flag) );
-_PROTOTYPE( struct smblk *sbm_lmak, (SBMA addr, SBMO elsize, int num) );
-_PROTOTYPE( int sbm_nmov, (struct smblk *smp1, struct smblk *smp2, struct smblk **begp, int elsize) );
-_PROTOTYPE( struct smblk *sbm_mget, (SBMO cmin, SBMO cmax) );
-_PROTOTYPE( char *sbm_brk, (unsigned size) );
-_PROTOTYPE( int sbm_mfree, (struct smblk *sm) );
-_PROTOTYPE( struct smblk *sbm_exp, (struct smblk *sm, SBMO size) );
-_PROTOTYPE( int sbm_mmrg, (struct smblk *smp) );
-_PROTOTYPE( struct smblk *sbm_split, (struct smblk *smp, SBMO coff) );
-_PROTOTYPE( int sbm_scpy, (char *from, char *to, unsigned count) );
-#if 0
-_PROTOTYPE( struct smblk *sbm_err, (struct smblk *val, char *str, int a0, int a1, int a2, int a3) );
-#else
-struct smblk *sbm_err();
-#endif
-_PROTOTYPE( char *malloc, (unsigned size) );
-_PROTOTYPE( char *alloc, (unsigned size) );
-_PROTOTYPE( int free, (char *ptr) );
-_PROTOTYPE( char *realloc, (char *ptr, unsigned size) );
-_PROTOTYPE( char *calloc, (unsigned nelem, unsigned elsize) );
-_PROTOTYPE( int sbm_ngc, (void) );
-_PROTOTYPE( int sbm_xngc, (struct smblk **begp, unsigned elsize, unsigned flag) );
-_PROTOTYPE( int sbm_nfor, (int flag, int nodsiz, int (*proc )(), struct sbfile *arg) );
-
-/* sbstr.c */
-_PROTOTYPE( SBSTR *sb_close, (SBBUF *sbp) );
-_PROTOTYPE( int sb_setovw, (SBBUF *sbp) );
-_PROTOTYPE( int sb_clrovw, (SBBUF *sbp) );
-_PROTOTYPE( chroff sbx_fdlen, (int fd) );
-_PROTOTYPE( SBSTR *sb_fduse, (int ifd) );
-_PROTOTYPE( int sb_fdcls, (int ifd) );
-_PROTOTYPE( int sbx_fcls, (struct sbfile *sfp) );
-_PROTOTYPE( int sb_fdinp, (SBBUF *sb, int fd) );
-_PROTOTYPE( int sb_fsave, (SBBUF *sb, int fd) );
-_PROTOTYPE( int sb_sgetc, (SBBUF *sb) );
-_PROTOTYPE( int sb_sputc, (SBBUF *sb, int ch) );
-_PROTOTYPE( int sb_speekc, (SBBUF *sb) );
-_PROTOTYPE( int sb_rgetc, (SBBUF *sb) );
-_PROTOTYPE( int sb_rdelc, (SBBUF *sbp) );
-_PROTOTYPE( int sb_deln, (SBBUF *sbp, chroff num) );
-_PROTOTYPE( struct sdblk *sb_killn, (SBBUF *sbp, chroff num) );
-_PROTOTYPE( SBSTR *sb_cpyn, (SBBUF *sbp, chroff num) );
-_PROTOTYPE( int sb_sins, (SBBUF *sbp, struct sdblk *sdp) );
-_PROTOTYPE( SBSTR *sbs_cpy, (SBSTR *sdp) );
-_PROTOTYPE( int sbs_del, (SBSTR *sdp) );
-_PROTOTYPE( SBSTR *sbs_app, (struct sdblk *sdp, struct sdblk *sdp2) );
-_PROTOTYPE( chroff sbs_len, (SBSTR *sdp) );
-_PROTOTYPE( int sb_seek, (SBBUF *sbp, chroff coff, int flg) );
-_PROTOTYPE( int sb_rewind, (SBBUF *sbp) );
-_PROTOTYPE( chroff sb_tell, (SBBUF *sbp) );
-_PROTOTYPE( chroff sb_ztell, (SBBUF *sbp) );
-#if 0
-_PROTOTYPE( struct sdblk *sbx_ready, (SBBUF *sbp, int type, SBMO cmin, SBMO cmax) );
-#else
-struct sdblk *sbx_ready();
-#endif
-_PROTOTYPE( struct sdblk *sbx_next, (SBBUF *sbp) );
-_PROTOTYPE( struct sdblk *sbx_norm, (SBBUF *sbp, int mode) );
-_PROTOTYPE( struct sdblk *sbx_beg, (struct sdblk *sdp) );
-_PROTOTYPE( int sbx_smdisc, (SBBUF *sbp) );
-_PROTOTYPE( int sbx_sbrdy, (SBBUF *sbp) );
-_PROTOTYPE( struct sdblk *sbx_scpy, (struct sdblk *sdp, struct sdblk *sdlast) );
-_PROTOTYPE( struct sdblk *sbx_sdcpy, (struct sdblk *sdp) );
-_PROTOTYPE( struct sdblk *sbx_xcis, (SBBUF *sbp, chroff num, struct sdblk **asd2, chroff *adot) );
-_PROTOTYPE( struct sdblk *sbx_split, (struct sdblk *sdp, chroff coff) );
-_PROTOTYPE( struct smblk *sbx_msplit, (struct smblk *smp, SBMO size) );
-_PROTOTYPE( struct sdblk *sbx_ndel, (struct sdblk *sdp) );
-_PROTOTYPE( int sbx_npdel, (struct sdblk *sdp) );
-_PROTOTYPE( struct sdblk *sbx_ndget, (void) );
-_PROTOTYPE( int sbx_ndfre, (struct sdblk *sdp) );
-_PROTOTYPE( SBMA sbx_malloc, (unsigned size) );
-_PROTOTYPE( struct smblk *sbx_mget, (SBMO cmin, SBMO cmax) );
-_PROTOTYPE( int sbx_comp, (int cmin, int lev) );
-_PROTOTYPE( int sbx_sdgc, (struct sdblk *sdp, int lev) );
-#if 0
-_PROTOTYPE( int sbx_aout, (struct sdblk *sdp, int flag, int fd) );
-#else
-int sbx_aout();
-#endif
-_PROTOTYPE( chroff sbx_qlen, (struct sdblk *sdp) );
-_PROTOTYPE( int sbx_tset, (chroff loff, int align) );
-_PROTOTYPE( struct sdblk *sbx_ffnd, (SBFILE *sfp, chroff size, chroff *aloc) );
-_PROTOTYPE( int sbx_rdf, (int fd, char *addr, int cnt, int skflg, chroff loc) );
-_PROTOTYPE( int sbx_rugpull, (int fd) );
-_PROTOTYPE( int sbx_unpur, (struct sdblk *sd, struct sbfile *sf) );
-#if 0
-_PROTOTYPE( int sbx_err, (int val, char *str, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12) );
-#else
-int sbx_err();
-#endif
-
-/* sbvall.c */
-_PROTOTYPE( char *valloc, (unsigned size) );
Index: trunk/minix/commands/elle/sbstr.c
===================================================================
--- trunk/minix/commands/elle/sbstr.c	(revision 9)
+++ 	(revision )
@@ -1,2213 +1,0 @@
-/* SB - Copyright 1982 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.  In all cases
- *	the source code and any modifications thereto must remain
- *	available to any user.
- *
- *	This is part of the SB library package.
- *	Any software using the SB library must likewise be made
- *	quasi-public, with freely available sources.
- */
-
-#if 0
-Todo stuff:
-	New definitions:
-		sbbuffer - old sbstr.  Abbrev & struct "sbbuff".  Macro SBBUFF
-			(or SBBUF?)
-		sbstring - list of sds.  Abbrev sbstr.  Macro SBSTR.
-			Should *sbstr == *sdblk?  Yeah.
-		sbfile - as before.  Macro SBFILE. (or SBFIL?)
-
-	Try to get zero-length sdblks flushed on the fly,
-		rather than waiting for moby GC.  Also, need to set
-		up compaction of SD freelist, as well as SM freelist.
-		Make SM freelist compact self-invoked by SBM_MGET?
-	Any need for phys disk ptrs other than for tempfile?
-		Can do sbm_forn through SDblks to find active sdfiles
-		so list isn''t needed for that.
-	Can sdback be flushed?  (not needed for keeping list sorted,
-		or for searching it -- only used when linking
-		blocks in or out of list.)  Perhaps use circular list?
-		If list only used for tmpfile, then to link in/out could
-		always start from sfptr1 of tmpfile? Sure, but slow?
-		Last SD on phys list could belong to no logical list,
-		and denote free space on tmpfile?
-
-	--------------------------
-
-	An "open" SBBUFFER will allow one to read, write, insert into,
-and delete from a sbstring (a logical character string).  "Dot" refers
-to the current logical character position, which is where all
-operations must happen; sb_fseek must be used to change this location.
-There are several states that the I/O can be in:
-!SBCUR		----CLOSED----
-		All other elements, including SBIOP, should also be 0.
-		Dot is 0.
-SBCUR && !SBIOP	----OPEN/IDLE----
-		SBCUR points to a SD block (its SDMEM may or may not exist)
-		SBIOP==0 (otherwise it would be open/ready)
-		Dot is SBDOT + SBOFF.
-		R/Wleft must be 0.
-SBCUR && SBIOP	----OPEN/READY----
-		SBCUR points to a SDBLK (SDMEM must exist!)
-		SBIOP exists.
-		Dot is SBDOT + offset into SMBLK.  SBOFF is ignored!
-		SB_WRIT flag is set if "smuse" must be updated.
-		The R/Wleft counts are set up:
-		1. Rleft 0, Wleft 0 -- Since SBIOP is set, must assume
-			counts are too.
-			So this means at end of text, no room left.
-			Otherwise would imply that setup needs doing.
-		2. Rleft N, Wleft 0 -- At beg or middle of text
-		3. Rleft 0, Wleft N -- At end of text
-		4. Rleft N, Wleft N -- Shouldn''t ever happen
-
-		Note that Rleft is always correct.  Wleft is sometimes
-		set 0 in order to force a call to determine real state.
-
-Note that SBIOP alone is a sufficient test for being OPEN/READY.
-
-The important thing about updating the smblk is to ensure that the "smuse"
-field is correct.  This can only be changed by writing or deleting.  We assume
-that deletions always update immediately, thus to determine if an update
-is necessary, see if SB_WRIT is set.  If so, update smuse before doing
-anything but more writing!!!!
-
-The SDBLK must be marked "modified" whenever a write operation is
-done.  We try to do this only the first time, by keeping Wleft zero
-until after the first write.  This is also when SB_WRIT gets set.
-However, if in overwrite mode, Wleft must be kept zero in order to
-force the proper actions; SB_WRIT is also not turned on since smuse
-will not change.  Note that at EOF, overwrite becomes the same thing
-as insert and is treated identically...
-
-	If a SBLK has an in-core copy but no disk copy, it can be
-freely modified.  Otherwise, modifications should preferably split
-the block so as to retain "pure" blocks as long as possible.  "Pure" blocks
-can always have their in-core versions flushed immediately (unless for
-compaction purposes they''ll need to be written out in the same GC pass).
-Alternatively, mods can simply mark the disk copy "free" and go
-ahead as if no such copy existed.
-	No additions or changes to a pure block are allowed, but
-deletions from the end or beginning are always allowed.  All other
-changes must split or insert new blocks to accomplish the changes.
-
-Locking:
-	SDBLKs are subject to unpredictable relocation, compaction,
-and garbage collecting.  There are three ways in which a SDBLK can
-remain fixed:
-
-	1. The SDBLK has the SD_LOCK flag set.  This flag is used whenever
-		a SBBUF''s SBCUR is pointing to this SDBLK.
-	2. The SDBLK has the SD_LCK2 flag set.  This flag is used only
-		during execution of various internal routines and should
-		not be seen anywhere during execution of user code.
-	3. The SDBLK has no back-pointer (is first block in a sbstring).
-		Such SDBLKs cannot be relocated (since it is not known
-		what may be pointing to them) but unlike the other 2 cases
-		they are still subject to compaction with succeeding SDBLKs.
-
-The SDBLK must be locked with SD_LOCK for as long as it is being
-pointed to by SBCUR.  The sole exception is when a SBBUF in the
-OPEN/IDLE state is pointing to the first SDBLK of a sbstring; this
-sdblk is guaranteed not to be moved, since sdblks without a
-back-pointer are never moved.  SD_LOCK is asserted as soon as the state
-changes to OPEN/READY, of course.  The internal routines take pains to
-always move SD_LOCK as appropriate.  Note that only one SD in a
-sbstring can ever have SD_LOCK turned on.  SD_LCK2 is an auxiliary flag
-which may appear in more than one SDBLK, for use by low-level routines
-for various temporary reasons; either will prevent the SDBLK from being
-modified in any way by the storage compactor.
-
-SEEKs are a problem because it''s unclear at seek time what will happen
-next, so the excision of the smblk can''t be optimized.  If the seek
-happens to land in a sdblk with an existing smblk, there''s no problem;
-but if it''s a sdblk alone, how to decide which part of it to read in???
-If next action is:
-	write - split up sdblk and create new one.  Read nothing in.
-	read - read in 512 bytes starting at disk blk boundary if possible
-		else read in 128 bytes starting with selected char
-		(include beg of sdblk if less than 64 chars away)
-	overwrite - as for read.
-	backread - like read but position at end of sdblk.
-	delete - split up sdblk, read nothing in.
-
-We solve this through the OPEN/IDLE state, where SBIOP == 0 means SBOFF
-points to logical offset from start of current sdblk, so that the seek
-need not take any action.  Only when a specific operation is requested
-will the transition to OPEN/READY take place, at which time we''ll know
-what the optimal excision strategy is.  The routine SBX_READY performs
-this function.
-
-The physical links (SDFORW and SDBACK) are only valid when SDFILE is
-set (likewise for SDLEN and SDADDR).  In other words, mungs to a sdblk
-must check SDFILE to see whether or not the phys links should be
-altered.  Normally they aren''t except during sdblk creation, deletion,
-or swapout, no matter how much the sdblk gets shuffled around
-logically.  The disk physical list is kept sorted in order of starting
-addresses.  The text blocks indicated can overlap.  When a GC is
-necessary, the code must figure out how much space is actually free.
-
--------------- Old woolgathering, ignore rest of this page ---------------
-
-Question: should 512-byte buffers be maintained, one for each SBFILE?
-Or should the in-core text be hacked up to serve for buffering?
-Question is where to point the READ/WRITE system calls.  Currently,
-they are pointed directly at the in-core text, and there are no
-auxiliary buffers.
-
-If use auxiliary buffers:
-	How to handle flushing, when changing location etc?
-	Could be clever about reading from large disk block, only
-	get part of it into buffer instead of splitting up in order to
-	read a "whole" block.
-	Problem: sbstrings can include pieces of several different files.
-		Hard to maintain just one buffer per FD without hacking
-		done on one sbstring screwing that on another.
-If don''t use buffers:
-	Need to have a "chars-left" field in mem blocks, so know how
-	much more can be added.  Will need heuristics for how much
-	extra space to allocate.
-#endif /*COMMENT*/
-
-
-/* Includes, initial definitions */
-
-#include <stdio.h>
-#include "sb.h"
-
-#ifndef V6
-#define V6 0
-#endif
-
-#if V6
-#include <stat.h>
-#else
-#include <sys/types.h>
-#include <sys/stat.h>
-#if MINIX
-#include <fcntl.h>	/* For open() flags */
-#else
-#include <sys/file.h>	/* For open() flags */
-#endif /* MINIX */
-#endif /*-V6*/
-
-extern int errno;
-extern char *strerror();	/* From ANSI <string.h> */
-
-/* Allocation decls */
-SBFILE sbv_tf;		/* SBFILE for temp swapout file */
-int (*sbv_debug)();	/* Error handler address */
-
-
-/* SBX_READY argument flags (internal to SBSTR routines only)
- * The following values should all be unique; the exact value
- * doesn't matter as long as the right SKM flags are given.
- */
-#define SK_READF 0			/* 0-skip fwd,  align BOB */
-#define SK_READB (0|SKM_0BACK|SKM_EOB)	/* 0-skip bkwd, align EOB */
-#define SK_WRITEF (0|SKM_EOB)		/* 0-skip fwd,  align EOB */
-#define SK_DELF (4|SKM_0BACK)		/* 0-skip bkwd, align BOB */
-#define SK_DELB (4|SKM_EOB)		/* 0-skip fwd,  align EOB */
-#define SKM_0BACK 01	/* Zero-skip direction: 0 = fwd, set = backwd
-			 * Don't ever change this value! See SBX_NORM. */
-#define SKM_EOB	  02	/* Alignment: 0 = Beg-Of-Buf, set = End-Of-Buf */
-
-/* Note on routine names:
- *	"SB_" 	User callable, deals with sbbufs (usually).
- *	"SBS_"	User callable, deals with sbstrings only.
- *	"SBX_"	Internal routine, not meant for external use.
- *	"SBM_"	Routine handling mem alloc, usually user callable.
- */
-
-
-/* SBBUF Opening, Closing, Mode setting */
-
-/* SB_OPEN(sb,sd) - Sets up SBBUF given pointer to first SD of a sbstring.
- * 	If SD == 0 then creates null sbstring.
- *	Any previous contents of SBBUF are totally ignored!!!  If you
- *		want to save the stuff, use SB_UNSET.
- *	Sets I/O ptr to start of sbstring.
- *	Returns 0 if error, else the given SB.
- */
-SBBUF *
-sb_open(sbp,sdp)
-SBBUF *sbp;
-SBSTR *sdp;
-{	register struct sdblk *sd;
-	register int cnt;
-	register WORD *clrp;
-
-	if(!sbp) return((SBBUF *)0);
-	if((sd = sdp) == 0)
-	  {	sd = sbx_ndget();	/* Get a fresh node */
-		clrp = (WORD *) sd;	/* Clear it all */
-		cnt = rnddiv(sizeof(struct sdblk));
-		do { *clrp++ = 0; } while(--cnt);
-		sd->sdflags = SD_NID;	/* Except flags of course */
-	  }
-	else if(sd->slback)		/* Must be first thing in sbstring */
-		return((SBBUF *)0);		/* Perhaps could normalize tho */
-
-	clrp = (WORD *) sbp;		/* Clear sbbuffer stuff */
-	cnt = rnddiv(sizeof(SBBUF));
-	do { *clrp++ = 0; } while(--cnt);
-
-	sbp->sbcur = sd;
-	/* Note that SD_LOCK need not be set, because first SDBLK has no
-	 * backptr.  This is desirable to allow storage compactor maximum
-	 * freedom in merging sdblks.
-	 */
-	/*	sd->sdflags |= SD_LOCK; */	/* Lock this one */
-	return(sbp);
-}
-
-
-/* SB_CLOSE(sb)	- Close a SBBUF.
- *	Returns pointer to start of sbstring (first SD).
- *	Returns 0 if error.
- */
-SBSTR *
-sb_close(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register struct sdblk *sd;
-
-	if((sb = sbp) == 0)	/* Verify pointer */
-		return((SBSTR *)0);
-	sb_rewind(sb);		/* Do most of the work, including unlock */
-	sd = sb->sbcur;		/* Save ptr to sbstring */
-	sb->sbcur = 0;		/* Now reset the sbbuffer structure */
-	sb->sbflags = 0;
-	return(sd);
-}
-
-
-/* SB_SETOVW(sbp) - Set SBBUF Over-write mode for PUTC's.
- * SB_CLROVW(sbp) - Clear ditto.
- */
-sb_setovw(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	if(sb=sbp)
-	  {	sb->sbflags |= SB_OVW;
-		sb->sbwleft = 0;
-	  }
-}
-
-sb_clrovw(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	if(sb=sbp) sb->sbflags &= ~SB_OVW;
-}
-
-
-/* SBSTRING file system operations (see also sb_fsave) */
-
-/* SB_FDUSE(fd) - Make a sbstring for given file.
- * 	FD is an open file descriptor.
- *	Returns pointer to a SBSTR containing the given file, or 0 if error.
- *	The FD must not be closed until a SB_FDCLS is done to
- *	purge memory of any blocks pointing at the file.
- * ** Maybe allocate sbfile structs with sbx_ndget, i.e. overlay on
- * ** top of sdblk node??  Wd this screw verify, GC, etc? Maybe not if
- * ** SD_LCK2 set...
- */
-
-struct sbfile *sbv_ftab[SB_NFILES];
-
-chroff
-sbx_fdlen(fd)
-int fd;
-{
-#if !V6
-	struct stat statb;
-#else
-	struct statb statb;
-	chroff len;
-	struct {int hiwd ; int lowd;} foo;
-#endif /*V6*/
-
-	if(fstat(fd,&statb) < 0) return((chroff)-1);
-#if V6
-	len = statb.i_size1;
-	len.hiwd = statb.i_size0 & 0377;
-	return(len);
-#else
-	return((chroff)statb.st_size);
-#endif /*-V6*/
-}
-
-SBSTR *
-sb_fduse(ifd)
-int ifd;
-{	register struct sdblk *sd;
-	register struct sbfile *sf;
-	register int fd;
-	chroff len;
-
-	if((fd = ifd) < 0 || SB_NFILES <= fd	/* Check for absurd FD */
-	  || sbv_ftab[fd])			/* and slot already in use */
-		return((SBSTR *)0);
-	if((len = sbx_fdlen(fd)) < 0) return((SBSTR *)0);
-	sbv_ftab[fd]= sf = (struct sbfile *)sbx_malloc(sizeof(struct sbfile));
-	sf->sffd = fd;
-	sf->sfptr1 = sd = sbx_ndget();
-	sf->sflen = len;
-	sd->slforw = 0;
-	sd->slback = 0;
-	sd->sdforw = 0;
-	sd->sdback = 0;
-	sd->sdmem = 0;
-	sd->sdfile = sf;
-	sd->sdlen = len;
-	sd->sdaddr = 0;
-	return(sd);
-}
-
-/* SB_FDCLS(fd) - Close a file descriptor being used by sbstrings.
- *	If arg is -1, closes all FD's that are unused (a "sweep").
- *	For specific arg, returns 0 if couldn't close FD because still in use.
- *	Perhaps later version of routine could have option to copy
- *	still-used SD's to tempfile, and force the FD closed?
- */
-sb_fdcls(ifd)
-int ifd;
-{	register int fd;
-
-	if((fd = ifd) >= 0)
-	  {	if(fd >= SB_NFILES) return(0);	/* Error of sorts */
-		return(sbx_fcls(sbv_ftab[fd]));
-	  }
-	fd = SB_NFILES-1;
-	do {
-		sbx_fcls(sbv_ftab[fd]);
-	  } while(--fd);	/* Doesn't try FD 0 ! */
-	return(1);
-}
-
-sbx_fcls(sfp)
-struct sbfile *sfp;
-{	register struct sbfile *sf;
-	register int fd;
-
-	if((sf = sfp)==0		/* Ignore null args */
-	  || sf == &sbv_tf)		/* and never close our tempfile! */
-		return(0);
-	fd = sf->sffd;			/* Find sys file descriptor */
-	if(sbv_ftab[fd] != sf)		/* Ensure consistency */
-		return(sbx_err(0,"SF table inconsistency"));
-	if(sf->sfptr1)			/* Any phys list still exists? */
-		return(0);		/* Yes, still in use, can't close */
-	close(fd);			/* Maybe do this when list gone? */
-	sbv_ftab[fd] = 0;		/* Remove from table */
-	free(sf);			/* Remove sbfile struct from mem */
-}
-
-/* SB_FDINP(sb,fd) - Returns TRUE if specified fd is still in use
- *	by specified sbbuffer.
- */
-sb_fdinp(sb, fd)
-register SBBUF *sb;
-int fd;
-{	register struct sdblk *sd;
-	register struct sbfile *sf;
-
-	if((sf = sbv_ftab[fd]) == 0
-	  || (sd = sb->sbcur) == 0)
-		return(0);
-	sd = sbx_beg(sd);		/* Move to beginning of sbstring */
-	for(; sd; sd = sd->slforw)	/* Scan thru all blocks in string */
-		if(sd->sdfile == sf)	/* If any of them match, */
-			return(1);	/* Return tally-ho */
-	return(0); 
-}
-
-/* SB_FSAVE(sb,fd) - Write entire SBBUF out to specified FD.
- *	Returns 0 if successful, else system call error number.
- */
-sb_fsave(sb,fd)		/* Write all of given sbbuf to given fd */
-register SBBUF *sb;
-int fd;
-{
-	sbx_smdisc(sb);
-	return(sbx_aout(sbx_beg(sb->sbcur), 2, fd));
-}
-
-
-/* SBBUF Character Operations */
-
-/* SB_GETC(sb) - Get next char from sbstring.
- *	Returns char at current location and advances I/O ptr.
- *	Returns EOF on error or end-of-string.
- */
-int
-sb_sgetc(sb)
-register SBBUF *sb;
-{
-	if(--(sb->sbrleft) >= 0)
-		return sb_uchartoint(*sb->sbiop++);
-
-	/* Must do hard stuff -- check ptrs, get next blk */
-	sb->sbrleft = 0;			/* Reset cnt to zero */
-	if(sb->sbcur == 0			/* Make sure sbbuffer there */
-	  || (int)sbx_ready(sb,SK_READF,0,SB_BUFSIZ) <= 0)  /* Normalize & gobble */
-		return(EOF);
-	return(sb_sgetc(sb));			/* Try again */
-}	/* Loop wd be faster, but PDL OV will catch infinite-loop bugs */
-
-
-/* SB_PUTC(sb,ch) - Put char into sbstring.
- *	Inserts char at current location.
- *	Returns EOF on error, else the char value.
- */
-int
-sb_sputc(sb,ch)
-register SBBUF *sb;
-int ch;
-{
-	register struct sdblk *sd;
-
-	if(--(sb->sbwleft) >= 0) return(*sb->sbiop++ = ch);
-
-	sb->sbwleft = 0;		/* Reset cnt to avoid overflow */
-	if((sd = sb->sbcur) == 0)	/* Verify string is there */
-		return(EOF);		/* Could perhaps create it?? */
-	if(sb->sbflags&SB_OVW)		/* If overwriting, handle std case */
-	  {	if(sb->sbiop &&
-		  --sb->sbrleft >= 0)		/* Use this for real count */
-		  {	sd->sdflags |= SD_MOD;	/* Win, munging... */
-			return(*sb->sbiop++ = ch);
-		  }
-		/* Overwriting and hit end of this block. */
-		if((int)sbx_ready(sb,SK_READF,0,SB_BUFSIZ) > 0) /* Re-normalize */
-			return(sb_sputc(sb,ch));
-
-		/*  No blks left, fall through to insert stuff at end */
-	  }
-
-	/* Do canonical setup with heavy artillery */
-	if((int)sbx_ready(sb,SK_WRITEF,SB_SLOP,SB_BUFSIZ) <= 0)	/* Get room */
-		return(EOF);		/* Should never happen, but... */
-	sb->sbflags |= SB_WRIT;
-	sb->sbcur->sdflags |= SD_MOD;
-	return(sb_sputc(sb,ch));	/* Try again */
-}	/* Loop wd be faster, but PDL OV will catch infinite-loop bugs */
-
-
-/* SB_PEEKC(sb) - Peek at next char from sbstring.
- *	Returns char that sb_getc would next return, but without
- *	changing I/O ptr.
- *	Returns EOF on error or end-of-string.
- */
-int
-sb_speekc(sb)
-register SBBUF *sb;
-{
-	if (sb->sbrleft <= 0)			/* See if OK to read */
-	  {	if (sb_sgetc(sb) == EOF)	/* No, try hard to get next */
-			return EOF;		/* Failed, return EOF */
-		sb_backc(sb);			/* Won, back up */
-	  }
-	return sb_uchartoint(*sb->sbiop);
-}
-
-/* SB_RGETC(sb) - Get previous char from sbstring.
- *	Returns char prior to current location and backs up I/O ptr.
- *	Returns EOF on error or beginning-of-string.
- */
-int
-sb_rgetc(sb)
-register SBBUF *sb;
-{
-	register struct smblk *sm;
-	register struct sdblk *sd;
-
-	if((sd=sb->sbcur) && (sm = sd->sdmem)
-	  && sb->sbiop > sm->smaddr)
-	  {	if(sb->sbflags&SB_WRIT)
-		  {	sm->smuse = sb->sbiop - sm->smaddr;
-			sb->sbwleft = 0;
-			sb->sbflags &= ~SB_WRIT;
-		  }
-		sb->sbrleft++;
-		return sb_uchartoint(*--sb->sbiop);	/* Return char */ 
-	  }
-	if((int)sbx_ready(sb,SK_READB,SB_BUFSIZ,0) <= 0)
-		return(EOF);
-	return(sb_rgetc(sb));
-}
-
-/* SB_RDELC(sb) - Delete backwards one char.
- *	Returns nothing.
- */
-sb_rdelc(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register struct sdblk *sd;
-
-	if(((sb=sbp)->sbflags&SB_WRIT)	/* Handle simple case fast */
-	  && sb->sbiop > (sd = sb->sbcur)->sdmem->smaddr)
-		  {	sb->sbwleft++;
-			sb->sbiop--;
-			sd->sdflags |= SD_MOD;
-			return;
-		  }
-	else sb_deln(sb,(chroff) -1);	/* Else punt... */
-}
-
-/* SB_DELC(sb) - Delete one char forward? */
-/* SB_INSC(sb,ch) - Insert char?  (instead of or in addition to PUTC) */
-
-
-
-/* SBBUF string or N-char operations */
-
-/* SB_DELN(sb,chroff) - delete N chars.  Negative N means backwards.
- *	Differs from sb_killn in that it flushes the text forever,
- *	and doesn't return anything.
- */
-
-sb_deln(sbp, num)
-SBBUF *sbp;
-chroff num;
-{
-	register struct sdblk *sd;
-
-	if(sd = sb_killn(sbp,num))
-		sbs_del(sd);	/* Punt */
-}
-
-/* SB_KILLN(sb,chroff) - delete N chars, saving.  Negative N means backwards.
- *	Returns SD pointer to beginning of saved sbstring.
- */
-struct sdblk *
-sb_killn(sbp, num)
-SBBUF *sbp;
-chroff num;
-{	register SBBUF *sb;
-	register struct sdblk *sd, *sd2;
-	struct sdblk *sdr, *sdx;
-	chroff savdot;
-
-	if((sd = sbx_xcis((sb=sbp),num,&sdr,&savdot)) == 0)
-		return((struct sdblk *)0);
-
-	sb->sbcur->sdflags &= ~SD_LOCK;	/* Now can flush sbcur lock */
-
-	/* SD and SD2 now delimit bounds of stuff to excise.
-	 * First do direction dependent fixups
-	 */
-	if(num >= 0)			/* If deleting forward, */
-		sb->sbdot = savdot;	/* must reset dot to initial loc */
-
-	/* SD and SD2 now in first/last order.  Complete SBCUR fixup. */
-	sd2 = sdr;			/* sdr has ptr to end of stuff */
-	if(sd2 = sd2->slforw)		/* More stuff after killed list? */
-	  {	sb->sbcur = sd2;	/* Yes, point at it */
-		sb->sboff = 0;		/* Dot already set right */
-	  }
-	else if(sdx = sd->slback)	/* See if any prior to killed list */
-	  {	sb->sbcur = sdx;		/* Yes, point at it */
-		sb->sboff = (sdx->sdmem ?	/* Get len of prev blk */
-			sdx->sdmem->smuse : sdx->sdlen);
-		sb->sbdot -= sb->sboff;
-	  }
-	else sb_open(sb,(SBSTR *)0);	/* No stuff left!  Create null sbstring */
-
-	/* Fix up logical links.  Note SD2 points to succ of killed stuff */
-	if(sd->slback)			/* If previous exists */
-	  {	if(sd->slback->slforw = sd2)	/* Point it to succ, and */
-			sd2->slback = sd->slback; /* thence to self */
-		sd->slback = 0;			/* Now init killed list */
-	  }
-	else if(sd2) sd2->slback = 0;		/* No prev, clean rest */
-	(sd2 = sdr)->slforw = 0;		/* Finish killed list */
-
-	sb->sbcur->sdflags |= SD_LOCK;	/* Ensure current SD now locked */
-	sd->sdflags &= ~SD_LCK2;	/* And unlock killed list */
-	sd2->sdflags &= ~SD_LCK2;
-	return(sd);
-}
-
-/* SB_CPYN(sbp,num) - Copy num characters, returns SD to sbstring.
- *	Like SB_KILLN but doesn't take chars out of original sbstring.
- */
-SBSTR *
-sb_cpyn(sbp,num)
-SBBUF *sbp;
-chroff num;
-{	register SBBUF *sb;
-	register struct sdblk *sd, *sd2;
-	struct sdblk *sdr;
-	chroff savloc;
-
-	sb = sbp;
-	if((sd = sbx_xcis(sb,num,&sdr,&savloc)) == 0)
-		return((SBSTR *)0);
-	sd2 = sbx_scpy(sd,sdr);
-	sb_seek(sb,-num,1);		/* Return to original loc */
-	return(sd2);		/* Return val is ptr to head of copy.
-				 * It needn't be locked, because GC will
-				 * never move list heads!
-				 */
-}
-
-/* SB_SINS(sb,sd) - Insert sbstring at current location
- *
- */
-sb_sins(sbp,sdp)
-SBBUF *sbp;
-struct sdblk *sdp;
-{	register SBBUF *sb;
-	register struct sdblk *sd, *sdx;
-	chroff inslen;
-
-	if((sb = sbp)==0
-	  || (sd = sdp) == 0)
-		return(0);
-	if(sd->slback)		/* Perhaps normalize to beg? */
-		return(0);
-	if((sdx = (struct sdblk *)sbx_ready(sb,SK_DELB)) == 0)	/* Get cur pos ready */
-		return(0);
-	inslen = sbs_len(sd);		/* Save length of inserted stuff */
-
-	sd->slback = sdx;		/* Fix up links */
-	if(sdx->slforw)
-	  {	while(sd->slforw)	/* Hunt for end of inserted sbstring */
-			sd = sd->slforw;
-		sd->slforw = sdx->slforw;
-		sd->slforw->slback = sd;
-	  }
-	sdx->slforw = sdp;
-	sb->sboff += inslen;		/* Set IO ptr to end of new stuff */
-	return(1);
-}
-
-
-/* SBSTRING routines - operate on "bare" sbstrings. */
-
-/* SBS_CPY(sd) - Copies given sbstring, returns ptr to new sbstring.
- */
-SBSTR *
-sbs_cpy(sdp)
-SBSTR *sdp;
-{	return(sbx_scpy(sdp,(struct sdblk *)0));
-}
-
-/* SBS_DEL(sd) - Flush a sbstring.
- */
-sbs_del(sdp)
-SBSTR *sdp;
-{	register struct sdblk *sd;
-
-	if(sd = sdp)
-		while(sd = sbx_ndel(sd));
-}
-
-
-/* SBS_APP(sd1,sd2) - Appends sbstring sd2 at end of sbstring sd1.
- *	Returns sd1 (pointer to new sbstring).
- */
-
-SBSTR *
-sbs_app(sdp,sdp2)
-struct sdblk *sdp,*sdp2;
-{	register struct sdblk *sd, *sdx;
-
-	if(sd = sdp)
-	  {	while(sdx = sd->slforw)
-			sd = sdx;
-		if(sd->slforw = sdx = sdp2)
-			sdx->slback = sd;
-	  }
-	return(sdp);
-}
-
-/* SBS_LEN(sd) - Find length of sbstring.
- */
-chroff
-sbs_len(sdp)
-SBSTR *sdp;
-{	register struct sdblk *sd;
-	register struct smblk *sm;
-	chroff len;
-
-	if((sd = sdp)==0) return((chroff)0);
-	len = 0;
-	for(; sd ; sd = sd->slforw)
-	  {	if(sm = sd->sdmem)
-			len += (chroff)sm->smuse;
-		else len += sd->sdlen;
-	  }
-	return(len);
-}
-
-
-/* SBBUF I/O pointer ("dot") routines */
-
-/* SB_SEEK(sb,chroff,flag) - Like FSEEK.  Changes I/O ptr value as
- *	indicated by "flag":
- * 		0 - offset from beg
- *		1 - offset from current pos
- *		2 - offset from EOF
- *	Returns -1 on errors.
- *	Seeking beyond beginning or end of sbbuf will leave pointer
- *	at the beginning or end respectively.
- *	Returns 0 unless error (then returns -1).
- */
-sb_seek(sbp, coff, flg)
-SBBUF *sbp;
-chroff coff;
-int flg;
-{	register SBBUF *sb;
-	register struct smblk *sm;
-	register struct sdblk *sd;
-	SBMO moff;
-
-	sb = sbp;
-	if((sd = sb->sbcur) == 0) return(-1);
-	if(sb->sbiop == 0)
-	  {	switch(flg)
-		  {	case 0:	if(coff == 0)	/* Optimize common case */
-					return(sb_rewind(sb));
-				sb->sboff = coff - sb->sbdot;	/* Abs */
-				break;
-			case 1:	sb->sboff += coff;		/* Rel */
-				break;
-			case 2:	sb->sboff += sb_ztell(sb) + coff;
-				break;
-			default: return(-1);
-		  }
-		sbx_norm(sb,0);
-		return(0);
-	  }
-	if((sm = sd->sdmem) == 0)
-		return(sbx_err(-1,"SDMEM 0"));
-	moff = sb->sbiop - sm->smaddr;	/* Get cur smblk offset */
-	if(sb->sbflags&SB_WRIT)		/* Update since moving out */
-	  {	sm->smuse = moff;
-		sb->sbflags &= ~SB_WRIT;
-	  }
-	sb->sbwleft = 0;		/* Always gets zapped */
-	switch(flg)
-	  {	case 0:		/* Offset from beginning */
-			coff -= sb->sbdot + (chroff)moff; /* Make rel */
-
-		case 1:		/* Offset from current loc */
-			break;
-
-		case 2:		/* Offset from end */
-			coff += sb_ztell(sb);
-			break;
-		default: return(-1);
-	  }
-
-	/* COFF now has relative offset from current location */
-	if (-(chroff)moff <= coff && coff <= sb->sbrleft)
-	  {				/* Win! Handle repos-within-smblk */
-		sb->sbiop += coff;
-		sb->sbrleft -= coff;	/* Set r; wleft already 0 */
-		return(0);
-	  }
-
-	/* Come here when moving to a different sdblk. */
-	sb->sbrleft = 0;
-	sb->sbiop = 0;
-	sb->sboff = coff + (chroff)moff;
-	sbx_norm(sb,0);
-	return(0);
-}
-
-/* SB_REWIND(sb) - Go to beginning of sbbuffer.
- *	Much faster than using sb_seek.  Note that this leaves the sbbuffer
- *	in an open/idle state which is maximally easy to compact.
- */
-sb_rewind(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register struct sdblk *sd;
-
-	if((sb = sbp)==0) return;
-	sbx_smdisc(sb);			/* Ensure I/O disconnected */
-	(sd = sb->sbcur)->sdflags &= ~SD_LOCK;	/* Unlock current blk */
-	sd = sbx_beg(sd);		/* Move to beg of sbstring */
-	/* Need not lock - see sb_open comments, also sb_close */
-	/*	sd->sdflags |= SD_LOCK; */	/* Lock onto this one */
-	sb->sbcur = sd;
-	sb->sbdot = 0;
-	sb->sboff = 0;
-}
-
-/* SB_TELL(sb) - Get I/O ptr value for SBBUF.
- *	Returns -1 on errors.
- */
-
-chroff
-sb_tell(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register struct smblk *sm;
-	register struct sdblk *sd;
-
-	if((sd = (sb=sbp)->sbcur) == 0)
-		return((chroff)-1);
-	if(sb->sbiop == 0)
-		return(sb->sbdot + sb->sboff);
-	if((sm = sd->sdmem) == 0)
-		return(sbx_err(0,"SDMEM 0"));
-	return(sb->sbdot + (unsigned)(sb->sbiop - sm->smaddr));
-}
-
-/* SB_ZTELL(sb) - Get I/O ptr relative to "Z" (EOF).
- *	Returns # chars from current location to EOF; 0 if any errors.
- */
-chroff
-sb_ztell(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register struct smblk *sm;
-	register struct sdblk *sd;
-
-	if((sd = (sb=sbp)->sbcur) == 0)
-		return((chroff)0);
-	if(sb->sbiop && (sm = sd->sdmem))
-	  {	if(sb->sbflags&SB_WRIT)		/* If actively writing, */
-			return(sbs_len(sd->slforw));	/* ignore this blk. */
-			/* Note that previous code makes it unnecessary
-			 * to invoke sbx_smdisc.  (otherwise wrong
-			 * smuse would confuse sbs_len).
-			 */
-		return(sbs_len(sd) - (sb->sbiop - sm->smaddr));
-	  }
-	else
-		return(sbs_len(sd) - sb->sboff);
-}
-
-
-/* Code past this point should insofar as possible be INTERNAL. */
-
-/* SBX_READY(sb,type,cmin,cmax) - Set up SBBUF for reading or writing.
- *
- * If no current smblk:
- *	reading - set up for reading
- *	writing - set up for splitting?
- * If current smblk:
- *	reading - if can read, OK.  Else position at beg of next sdblk
- *	writing - if can write, OK.  Else position at end of prev sdblk,
- *		or set up for splitting?
- * Types:
- *	0 - Read forward (BOB)
- *	1 - Read backward (EOB)
- *	3 - Write (insert forward) (EOB)
- *	4 - Delete forward (return SD, force BOB-aligned)
- *	5 - Delete backward (return SD, force EOB-aligned)
- * Connected SD is always locked.
- * Returns 0 if error, -1 if EOF-type error, 1 for success.
- *
- * For types 0,1:
- *	CMIN,CMAX represent max # chars to read in to left and right of
- *		I/O ptr (prev and post).  Actual amount read in may be
- *		much less, but will never be zero.
- *	Successful return guarantees that SBIOP etc. are ready.
- * For type 3:
- *	If new block is allocated, CMIN and CMAX represent min, max sizes
- *		of the block.
- *	Successful return guarantees that SBIOP etc. are ready, but
- *	NOTE that SB_WRIT and SD_MOD are not set!  If not going to use
- *	for writing, be sure to clear sbwleft on return!
- * For types 4,5:
- *	CMIN, CMAX are ignored.
- *	SBIOP is always cleared.  SBOFF is guaranteed to be 0 for
- *	type 4, SMUSE for type 5.
- *	Return value is a SD ptr; 0 indicates error.  -1 isn't used.
- */
-
-struct sdblk *
-sbx_ready(sbp,type,cmin,cmax)
-SBBUF *sbp;
-int type;
-SBMO cmin,cmax;
-{	register SBBUF *sb;
-	register struct sdblk *sd;
-	register struct smblk *sm;
-	int cnt, slop, rem;
-	SBMO moff;
-
-	if((sd = (sb=sbp)->sbcur) == 0)
-		return(0);
-	if(sb->sbiop)		/* Canonicalize for given operation */
-	  {	if((sm = sd->sdmem)==0)
-			return(0);
-		moff = sb->sbiop - sm->smaddr;	/* Current block offset */
-	  switch(type)
-	  {
-	case SK_READF:		/* Read Forward */
-		if(sb->sbrleft > 0)	/* Already set up? */
-			return(1);	/* Yup, fast return */
-		sbx_smdisc(sb);		/* None left, disc to get next */
-		if((sd = sbx_next(sb)) == 0)	/* Try to get next blk */
-			return(-1);	/* At EOF */
-		break;
-
-	case SK_READB:		/* Read Backward */
-		if(moff)		/* Stuff there to read? */
-		  {	if(sb->sbflags&SB_WRIT)	/* Yup, turn writes off */
-			  {	sm->smuse = moff;
-				sb->sbflags &= ~SB_WRIT;
-			  }
-			sb->sbwleft = 0;
-			return(1);
-		  }
-		sbx_smdisc(sb);
-		break;
-
-	case SK_WRITEF:		/* Writing */
-		if(sb->sbrleft <= 0)
-			sb->sbwleft = sm->smlen - moff;
-		if(sb->sbwleft > 0)
-			return(1);	/* OK to write now */
-					/* NOTE: flags not set!!! */
-		sbx_smdisc(sb);
-		break;
-
-	case SK_DELF:		/* Delete forward - force BOB */
-		if(sb->sbrleft <= 0)		/* At end of blk? */
-		  {	sbx_smdisc(sb);		/* Win, unhook */
-			return(sbx_next(sb));   /* Return next or 0 if EOF */
-		  }
-		sbx_smdisc(sb);			/* Not at end, but see if */
-		if(moff == 0)			/* at beg of blk? */
-			return(sd);	/* Fast win! */
-		break;
-
-	case SK_DELB:		/* Delete backward - force EOB */
-		if(sb->sbrleft <= 0)		/* Win if already EOB */
-		  {	sbx_smdisc(sb);
-			return(sd);
-		  }
-		sbx_smdisc(sb);
-		break;
-
-	default:
-		return(0);
-	  }
-	  }
-
-	/* Schnarf in the text, or whatever.
-	 * SD points to current sdblk (must be SD_LOCKed)
-	 * SBDOT must have correct value for this SD
-	 * SBOFF has offset from there to put I/O ptr at.
-	 *
-	 * After normalization, SBOFF is guaranteed to point within
-	 * the SD.  Other guarantees apply to boundary cases, depending
-	 * on the mode (type) bits.
-	 */
-	sd = sbx_norm(sb,type);	/* Normalize I/O pos appropriately */
-	sm = sd->sdmem;
-	switch(type)
-	  {
-	case SK_READB:		/* Read Backward */
-		if(sb->sboff == 0)	/* Due to normalize, if 0 seen */
-			return(-1);	/* then we know it's BOF */
-		if(sm) goto sekr2;
-		else goto sekr1;
-
-	case SK_READF:		/* Read Forward */
-		if(sm) goto sekr2;
-		if(sb->sboff == sd->sdlen)	/* Normalize means if EOB */
-			return(-1);		/* then at EOF. */
-	sekr1:	slop = SB_SLOP;
-	sekr3:	if(sb->sboff > cmin+slop)	/* Too much leading text? */
-		  {				/* Split off leading txt */
-			sbx_split(sd,(chroff)(sb->sboff - cmin));
-			sd = sbx_next(sb);	/* Point to next sdblk */
-			sb->sboff = cmin;	/* Set correct offset */
-						/* (sbx_next assumes 0) */
-		  }
-		if(sd->sdlen > sb->sboff+cmax+slop) /* Too much trailing txt? */
-			sbx_split(sd,(chroff)(sb->sboff+cmax));
-
-		/* ----- Try to get mem blk to read stuff into ----- */
-		/* Note alignment hack for extra efficiency.  This ensures
-		 * that all reads from disk to memory are made with the same
-		 * source and destination word alignment, so the system kernel
-		 * only needs byte-moves for the first or last bytes; all
-		 * others can be word-moves.
-		 * This works because sbx_mget always returns word-aligned
-		 * storage, and we use sbx_msplit to trim off the right number
-		 * of bytes from the start.
-		 */
-		cnt = sd->sdlen;		/* Get # bytes we'd like */
-		if(rem = rndrem(sd->sdaddr))	/* If disk not word-aligned */
-			cnt += rem;		/* allow extra for aligning.*/
-		if(sm == 0)			/* Always true 1st time */
-		  {	sm = sbx_mget(SB_SLOP,cnt); /* Get room (may GC!)*/
-			if(sm->smlen < cnt)	/* Got what we wanted? */
-			  {	slop = 0;	/* NO!!	 Impose stricter */
-				cmin = 0;	/* limits.  Allow for new */
-				cmax = sm->smlen - (WDSIZE-1); /* rem. */
-				if(type == SK_READB)
-				  {	cmin = cmax; cmax = 0; }
-				goto sekr3;	/* Go try again, sigh. */
-			  }
-		  }
-		else if(sm->smlen < cnt)	/* 2nd time shd always win */
-		  {	sbx_err(0,"Readin blksiz err");	/* Internal error, */
-			if((cmax /= 2) > 0) goto sekr3;	/* w/crude recovery */
-			return(0);
-		  }
-		if(rem)		/* If disk not word-aligned, hack stuff */
-		  {	sm = sbx_msplit(sm, (SBMO)rem);	/* Trim off from beg*/
-			sbm_mfree(sm->smback);		/* Free the excess */
-		  }
-		sd->sdmem = sm;
-		sm->smuse = sd->sdlen;
-
-		if(sd->sdfile == 0)
-			return(sbx_err(0,"No file"));	/* Gasp? */
-		if(!sbx_rdf(sd->sdfile->sffd, sm->smaddr, sm->smuse,
-				1, sd->sdaddr))
-			return(sbx_err(0,"Readin SD: %o", sd));
-		/* ------- */
-
-	sekr2:	sbx_sbrdy(sb);		/* Make it current, pt to beg */
-		sb->sbwleft = 0;	/* Ensure not set (esp if READB) */
-		break;
-
-	case SK_WRITEF:		/* Write-type seek */
-		if(sm == 0)
-		  {	/* Block is on disk, so always split (avoid readin) */
-			if(sd->sdlen)			/* May be empty */
-			  {	sbx_split(sd, sb->sboff); /* Split at IO ptr */
-				sd = sbx_next(sb);	/* Move to 2nd part */
-				if(sd->sdlen)		/* If stuff there, */
-							/* split it again. */
-					sbx_split(sd, (chroff) 0);
-			  }
-			goto sekwget;
-		  }
-
-		/* Block in memory */
-		moff = sm->smuse;
-		if(sb->sboff == moff)		/* At end of the block? */
-		  {	if(sm->smlen > moff)	/* Yes, have room? */
-				goto sekw;	/* Win, go setup and ret */
-			if(sm->smforw			/* If next mem blk */
-			  && (sm->smforw->smflags	/* Can have bytes */
-				& (SM_USE|SM_NXM))==0	/* stolen from it */
-			  && (sd->sdflags&SD_MOD)	/* and we ain't pure*/
-			  && sm->smlen < cmax)		/* and not too big */
-			  {	/* Then steal some core!!  Note that without
-				 * the size test, a stream of putc's could
-				 * create a monster block gobbling all mem.
-				 */
-				cmin = cmax - sm->smlen;
-				if(cmin&01) cmin++;	/* Ensure wd-align */
-				if(sm->smforw->smlen <= cmin)
-				  {	sbm_mmrg(sm);
-					goto sekw;
-				  }
-				sm->smforw->smlen -= cmin;
-				sm->smforw->smaddr += cmin;
-				sm->smlen += cmin;
-				goto sekw;
-			  }
-			/* Last try... check next logical blk for room */
-			if(sd->slforw && (sm = sd->slforw->sdmem)
-			  && sm->smuse == 0
-			  && sm->smlen)
-			  {	sd = sbx_next(sb);	/* Yup, go there */
-				goto sekw;
-			  }
-		  }
-
-		/* Middle of block, split up to insert */
-		sbx_split(sd, sb->sboff);	/* Split at IO ptr */
-		if(sd->sdmem)			/* Unless blk now empty, */
-		  {	sd = sbx_next(sb);	/* move to next. */
-			if(sd->sdmem)		/* If not empty either */
-			  sbx_split(sd, (chroff) 0);	/* Split again */
-		  }
-
-		/* Have empty SD block, get some mem for it */
-  sekwget:	sd->sdmem = sm = sbx_mget(cmin,cmax);
-		sm->smuse = 0;
-   sekw:	sbx_sbrdy(sb);		/* Sets up sbwleft... */
-		return(1);
-
-	case SK_DELF:		/* Delete forward */
-		if(sb->sboff == 0)	/* At block beg already? */
-			return(sd);	/* Win, return it */
-		sbx_split(sd, sb->sboff);	/* No, split up and */
-		return(sbx_next(sb));	/* return ptr to 2nd part */
-
-	case SK_DELB:		/* Delete backward (force EOB align) */
-		if(sb->sboff !=		/* If not at EOB already, */
-		  (sm ? (chroff)(sm->smuse) : sd->sdlen))
-			sbx_split(sd, sb->sboff);	/* Then split */
-		return(sd);	/* And return ptr to 1st part */
-		break;
-
-	default:
-		return(0);
-	  }	/* End of switch */
-	return(1);
-}
-
-struct sdblk *
-sbx_next (sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register struct sdblk *sd, *sdf;
-	if((sdf = (sd = (sb=sbp)->sbcur)->slforw) == 0)
-		return((struct sdblk *)0);
-	sb->sbdot += (sd->sdmem ? (chroff)sd->sdmem->smuse : sd->sdlen);
-	sb->sboff = 0;
-	sd->sdflags &= ~SD_LOCK;	/* Unlock current */
-	sdf->sdflags |= SD_LOCK;	/* Lock next */
-	sb->sbcur = sdf;
-	return(sdf);
-}
-
-
-/* SBX_NORM(sb,mode) - Normalizes I/O position as desired.
- *	The SBBUF must have I/O disconnected (SBIOP==0).
- *	Adjusts SBCUR, SBDOT, and SBOFF so that SBOFF is guaranteed
- *	to point to a location in the current SD block.
- *	The mode flags determine action when there is more than
- *	one possible SD that could be pointed to, as is the case
- *	when the I/O pos falls on a block boundary (possibly with
- *	adjacent zero-length blocks as well).
- *	SKM_0BACK - Zero-skip direction.
- *		  0 = Skip forward over zero-length blocks.
- *		set = Skip backward over zero-length blocks.
- *	SKM_EOB	  - Block-end selection (applies after skipping done).
- *		  0 = Point to BOB (Beginning Of Block).
- *		set = Point to EOB (End Of Block).
- * Returns the new current SD as a convenience.
- * Notes:
- *	The SKM_0BACK flag value is a special hack to search in
- *		the right direction when SBOFF is initially 0.
- *	None of the mode flags have any effect if the I/O pos falls
- *		within a block.
- *	Perhaps this routine should flush the zero-length blks it
- *		finds, if they're not locked??
- */
-struct sdblk *
-sbx_norm(sbp,mode)
-SBBUF *sbp;
-int mode;
-{	register struct sdblk *sd;
-	register struct smblk *sm;
-	register SBBUF *sb;
-	chroff len;
-
-	if((sd = (sb=sbp)->sbcur) == 0)
-	  {	sb->sbdot = 0;
-		sb->sboff = 0;
-		return(sd);
-	  }
-	sd->sdflags &= ~SD_LOCK;	/* Unlock current blk */
-
-	if(sb->sboff >= (mode&01))	/* Hack hack to get right skip */
-	  for(;;)			/* Scan forwards */
-	  {	if(sm = sd->sdmem)		/* Get length of this blk */
-			len = sm->smuse;
-		else len = sd->sdlen;
-		if(sb->sboff <= len)
-		  if(sb->sboff < len	/* If == and fwd 0-skip, continue */
-		  || (mode&SKM_0BACK))
-		    {	if((mode&SKM_EOB)	/* Done, adjust to EOB? */
-			  && sb->sboff == 0	/* Yes, are we at BOB? */
-			  && sd->slback)	/* and can do it? */
-			  {	sd = sd->slback;	/* Move to EOB */
-				sb->sboff = (sm = sd->sdmem) 
-					? (chroff)(sm->smuse) : sd->sdlen;
-				sb->sbdot -= sb->sboff;
-			  }
-			break;
-		    }
-		if(sd->slforw == 0)	/* At EOF? */
-		  {	sb->sboff = len;
-			break;
-		  }
-		sd = sd->slforw;
-		sb->sboff -= len;
-		sb->sbdot += len;
-	  }
-	else				/* Scan backwards */
-	 for(;;)
-	  {	if(sd->slback == 0)	/* At BOF? */
-		  {	sb->sboff = 0;
-			sb->sbdot = 0;	/* Should already be 0, but... */
-			break;
-		  }
-		sd = sd->slback;
-		if(sm = sd->sdmem)		/* Get length of this blk */
-			len = sm->smuse;
-		else len = sd->sdlen;
-		sb->sbdot -= len;
-		if((sb->sboff += len) >= 0)
-		  if(sb->sboff > 0	/* If == 0 and bkwd 0-skip, continue */
-		    || !(mode&SKM_0BACK))
-		    {	if((mode&SKM_EOB) == 0	/* Done, adjust to BOB? */
-			  && sb->sboff == len	/* Yes, are we at EOB? */
-			  && sd->slforw)	/* and can do it? */
-			  {	sd = sd->slforw;	/* Move to BOB */
-				sb->sboff = 0;
-				sb->sbdot += len;
-			  }
-			break;
-		    }
-	  }
-	sb->sbcur = sd;
-	sd->sdflags |= SD_LOCK;
-	return(sd);
-}
-
-
-
-struct sdblk *
-sbx_beg(sdp)
-struct sdblk *sdp;
-{	register struct sdblk *sd, *sdx;
-	if(sd = sdp)
-		while(sdx = sd->slback)
-			sd = sdx;
-	return(sd);
-}
-
-
-sbx_smdisc(sbp)
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register struct smblk *sm;
-	register struct sdblk *sd;
-
-	sb = sbp;
-	if((sd = sb->sbcur) == 0
-	  || (sm = sd->sdmem) == 0)
-		return;
-	if(sb->sbflags&SB_WRIT)
-	  {	sm->smuse = sb->sbiop - sm->smaddr;
-		sb->sbflags &= ~SB_WRIT;
-	  }
-	sb->sboff = sb->sbiop - sm->smaddr;
-	sb->sbiop = 0;
-	sb->sbrleft = sb->sbwleft = 0;
-}
-
-sbx_sbrdy(sbp)		/* Sets up SBIOP, SBRLEFT, SBWLEFT */
-SBBUF *sbp;
-{	register SBBUF *sb;
-	register struct sdblk *sd;
-	register struct smblk *sm;
-
-	if((sd = (sb=sbp)->sbcur) == 0
-	  || (sm = sd->sdmem) == 0)
-		return;
-	sd->sdflags |= SD_LOCK;
-	sb->sbiop = sm->smaddr + sb->sboff;
-	if(sb->sbrleft = sm->smuse - sb->sboff)
-		sb->sbwleft = 0;
-	else sb->sbwleft = sm->smlen - sm->smuse;
-}
-
-
-
-/* SBX_SCPY(sd,sdl) - Copies given sbstring, returns ptr to new sbstring.
- *	Only goes as far as sdl (last copied blk); 0 for entire sbstring.
- */
-struct sdblk *
-sbx_scpy(sdp,sdlast)
-struct sdblk *sdp, *sdlast;
-{	register struct sdblk *sd, *sd2, *sdn;
-	struct sdblk *sdr;
-
-	if((sd = sdp) == 0) return((struct sdblk *)0);
-	sdn = 0;
-	do {
-		sd->sdflags |= SD_LCK2;
-		sd2 = sbx_sdcpy(sd);
-		if(sd2->slback = sdn)
-		  {	sdn->slforw = sd2;
-			sdn->sdflags &= ~SD_LOCKS;
-		  }
-		else sdr = sd2;		/* Save 1st */
-		sdn = sd2;
-		sd->sdflags &= ~SD_LCK2;
-	  } while(sd != sdlast && (sd = sd->slforw));
-	sd2->slforw = 0;
-	sd2->sdflags &= ~SD_LOCKS;
-	return(sdr);
-}
-
-
-/* SBX_SDCPY(sd) - Copies given sdblk, returns ptr to new blk.
- *	Does not set locks, assumes caller does this (which it MUST,
- *	to avoid compaction lossage!)
- */
-
-struct sdblk *
-sbx_sdcpy(sdp)
-struct sdblk *sdp;
-{	register struct sdblk *sd, *sd2;
-	register struct smblk *sm, *sm2;
-
-	if((sd = sdp) == 0) return((struct sdblk *)0);
-	sd2 = sbx_ndget();		/* Get a free sdblk */
-	bcopy((SBMA)sd, (SBMA)sd2, sizeof(struct sdblk));	/* Copy sdblk data */
-	sd2->slforw = 0;		/* Don't let it think it's on a list */
-	sd2->slback = 0;
-	if(sd2->sdfile)			/* If has disk copy, */
-	  {	sd->sdforw = sd2;	/* Fix phys list ptrs */
-		sd2->sdback = sd;
-		if(sd2->sdforw)
-			sd2->sdforw->sdback = sd2;
-	  }
-	if(sm = sd2->sdmem)		/* If has in-core copy, try to */
-	  {	if(sm2 = sbm_mget(sm->smuse,sm->smuse))	/* get mem for it */
-		  {	bcopy(sm->smaddr,sm2->smaddr,sm->smuse);
-			sm2->smuse = sm->smuse;
-			sd2->sdmem = sm2;	/* Point new sd to copy */
-		  }
-		else				/* Can't get mem... */
-		  {	if(sd2->sdflags&SD_MOD)
-				sbx_aout(sd2,1);	/* Swap out the blk */
-			sd2->sdmem = 0;		/* Don't have incore copy */
-		  }
-	  }
-	return(sd2);
-}
-
-
-/* SBX_XCIS(sbp,coff,&sdp2,adot) - Internal routine to excise a sbstring,
- *	defined as everything between current location and given offset.
- *	SD to first sdblk is returned (0 if error)
- *	SD2 (address passed as 3rd arg) is set to last sdblk.
- *	Both are locked with LCK2 to ensure that pointers are valid.
- *	The current location at time of call is also returned via adot.
- */
-struct sdblk *
-sbx_xcis(sbp,num,asd2,adot)
-SBBUF *sbp;
-chroff num, *adot;
-struct sdblk **asd2;
-{	register SBBUF *sb;
-	register struct sdblk *sd, *sd2;
-	int dirb;
-
-	if((sb = sbp) == 0) return((struct sdblk *)0);
-	dirb = 0;		/* Delete forward */
-	if(num == 0) return((struct sdblk *)0);	/* Delete nothing */
-	if(num < 0) dirb++;	/* Delete backward */
-
-	if((sd = (struct sdblk *)
-			sbx_ready(sb, (dirb ? SK_DELB : SK_DELF))) == 0)
-		return((struct sdblk *)0);		/* Maybe nothing there */
-	sd->sdflags |= SD_LCK2;		/* Lock up returned SD */
-	*adot = sb->sbdot;		/* Save current location */
-	sb->sboff += num;		/* Move to other end of range */
-
-	if((sd2 = (struct sdblk *)
-			sbx_ready(sb,(dirb ? SK_DELF : SK_DELB))) == 0)
-	  {	sd->sdflags &= ~SD_LCK2;	/* This shd never happen if */
-		return(				/* we got this far, but...  */
-		  (struct sdblk *)sbx_err(0,"KILLN SD2 failed"));
-	  }
-	sd2->sdflags |= SD_LCK2;	/* Lock up other end of stuff */
-
-	/* SD and SD2 now delimit bounds of stuff to excise.
-	 * Now do direction dependent fixups
-	 */
-	if(dirb)
-	  {	/* Backward, current sbdot is ok but must get SD/SD2
-		 * into first/last order.  Also, due to nature of block
-		 * splitups, a backward delete within single block will leave
-		 * SD actually pointing at predecessor block.
-		 */
-		if(sd->slforw == sd2)	/* If SD became pred, fix things. */
-		  {	sd->sdflags &= ~SD_LCK2;	/* Oops, unlock! */
-			sd = sd2;
-		  }
-		else	/* Just need to swap SD, SD2 ptrs. */
-		  {	/* Goddamit why doesn't C have an */
-			/* exchange operator??? */
-			*asd2 = sd;
-			return(sd2);
-		  }
-	  }
-	*asd2 = sd2;
-	return(sd);
-}
-
-
-/* SBX_SPLIT(sd,chroff) - Splits block SD at point CHROFF (offset from
- *	start of block).  SD remains valid; it is left locked.
- *	The smblk is split too, if one exists, and SMUSE adjusted.
- *	If offset 0, or equal to block length, the 1st or 2nd SD respectively
- *	will not have a smblk and its sdlen will be 0.
- *	(Note that if a smblk exists, a zero sdlen doesn't indicate much)
- */
-struct sdblk *
-sbx_split(sdp, coff)
-struct sdblk *sdp;
-chroff coff;
-{	register struct sdblk *sd, *sdf, *sdx;
-
-	if((sd=sdp) == 0)
-		return((struct sdblk *)0);
-	sd->sdflags |= SD_LOCK;
-	if(sd->sdflags&SD_MOD)		/* If block has been munged, */
-		sbx_npdel(sd);		/* Flush from phys list now. */
-	sdf = sbx_ndget();		/* Get a sdblk node */
-	bcopy((SBMA)sd, (SBMA)sdf, (sizeof (struct sdblk)));	/* Copy node */
-	/* Note that the flags are copied, so both sdblks are locked and
-	 * safe from possible GC compaction during call to sbx_msplit...
-	 */
-	if(coff == 0)			/* If offset was 0, */
-	  {				/* then 1st SD becomes null */
-		if(sdf->sdfile)		/* Fix up phys links here */
-		  {	if(sdx = sdf->sdback)
-				sdx->sdforw = sdf;
-			else sdf->sdfile->sfptr1 = sdf;
-			if(sdx = sdf->sdforw)
-				sdx->sdback = sdf;
-		  }
-		sdx = sd;
-		goto nulsdx;
-	  }
-	else if(sd->sdmem)
-		if(coff >= sd->sdmem->smuse)
-			goto nulsdf;
-		else sdf->sdmem = sbx_msplit(sd->sdmem, (SBMO)coff);
-	else if(coff >= sd->sdlen)
-nulsdf:	  {	sdx = sdf;
-nulsdx:		sdx->sdforw = 0;
-		sdx->sdback = 0;
-		sdx->sdmem = 0;
-		sdx->sdfile = 0;
-		sdx->sdlen = 0;
-		sdx->sdaddr = 0;
-		goto nulskp;
-	  }
-	if(sd->sdfile)
-	  {	sdf->sdlen -= coff;		/* Set size of remainder */
-		sdf->sdaddr += coff;		/* and address */
-		sd->sdlen = coff;		/* Set size of 1st part */
-
-	/* Link 2nd block into proper place in physical sequence.
-	 * 1st block is already in right place.	 Search forward until
-	 * find a block with same or higher disk address, and insert
-	 * in front of it.  If sdlen is zero, just flush the links,
-	 * which is OK since the 1st block is what's pointed to anyway.
-	 */
-		if(sdf->sdlen > 0)
-		  {	while((sdx = sd->sdforw) /* Find place to insert */
-			  && sdf->sdaddr > sdx->sdaddr)
-				sd = sdx;
-			sdf->sdback = sd;	/* Link following sd. */
-			if(sdf->sdforw = sd->sdforw)
-				sdf->sdforw->sdback = sdf;
-			sd->sdforw = sdf;
-			sd = sdp;		/* Restore pointer */
-		  }
-		else
-		  {	sdf->sdforw = 0;
-			sdf->sdback = 0;
-			sdf->sdfile = 0;	/* Say no disk */
-		  }
-	  }
-
-nulskp:	sdf->slback = sd;		/* Link in logical sequence */
-	if(sd->slforw)
-		sd->slforw->slback = sdf;
-	sd->slforw = sdf;
-
-	sdf->sdflags &= ~SD_LOCKS;	/* Unlock 2nd but not 1st */
-	return(sd);			/* Note sd, not sdf */
-}
-
-/* SBX_MSPLIT - Like sbm_split but never fails, and sets
- *	SMUSE values appropriately
- */
-struct smblk *
-sbx_msplit(smp, size)
-struct smblk *smp;
-SBMO size;
-{	register struct smblk *sm, *smx;
-	register int lev;
-
-	lev = 0;
-	while((smx = sbm_split((sm = smp), size)) == 0)
-		sbx_comp(SB_BUFSIZ,lev++); /* Need to get some smblk nodes */
-	if(sm->smlen >= sm->smuse)	/* Split across used portion? */
-		smx->smuse = 0;		/* Nope, new blk is all free */
-	else
-	  {	smx->smuse = sm->smuse - sm->smlen;
-		sm->smuse = sm->smlen;
-	  }
-	return(smx);
-}
-
-
-/* SBX_NDEL - flush a SD and associated SM.  Fixes up logical
- * and physical links properly.  Returns ptr to next logical SD.
- * NOTE: if sd->slback does not exist, the returned SD is your
- * only hold on the list, since the SD gets flushed anyway!
- */
-struct sdblk *
-sbx_ndel(sdp)
-struct sdblk *sdp;
-{	register struct sdblk *sd, *sdx;
-	register struct smblk *sm;
-
-	sd = sdp;
-	if(sm = sd->sdmem)		/* If smblk exists, */
-	  {	sbm_mfree(sm);		/* flush it. */
-		sd->sdmem = 0;
-	  }
-	if(sdx = sd->slback)
-		sdx->slforw = sd->slforw;
-	if(sd->slforw)
-		sd->slforw->slback = sdx;	/* May be zero */
-
-	/* Logical links done, now hack phys links */
-	if(sd->sdfile)			/* Have phys links? */
-		sbx_npdel(sd);		/* Yes, flush from phys list */
-
-	sdx = sd->slforw;
-	sbx_ndfre(sd);
-	return(sdx);
-}
-
-sbx_npdel(sdp)
-struct sdblk *sdp;
-{	register struct sdblk *sd, *sdx;
-	register struct sbfile *sf;
-
-	if((sf = (sd=sdp)->sdfile) == 0)
-		return;
-	if(sdx = sd->sdback)	/* Start of disk file? */
-		sdx->sdforw = sd->sdforw;
-	else
-		sf->sfptr1 = sd->sdforw;
-	if(sdx = sd->sdforw)
-		sdx->sdback = sd->sdback;
-	sd->sdfile = 0;
-	sd->sdlen = 0;
-}
-
-
-
-struct sdblk *sbx_nfl;	/* Pointer to sdblk node freelist */
-
-struct sdblk *
-sbx_ndget()		/* Like sbm_nget but never fails! */
-{	register struct sdblk *sd;
-	register int lev;
-
-	lev = 0;
-	while((sd = sbx_nfl) == 0		/* Get a node */
-						/* If fail, make more */
-		&& (sd = sbm_nmak((sizeof (struct sdblk)),SM_DNODS)) == 0)
-						/* If still fail, try GC */
-			sbx_comp(sizeof(struct sdblk)*SM_DNODS,lev++);
-
-	sbx_nfl = sd->slforw;		/* Take it off freelist */
-	sd->sdflags = SD_NID;
-	return(sd);			/* Return ptr to it */
-}
-
-sbx_ndfre(sdp)
-struct sdblk *sdp;
-{	register struct sdblk *sd;
-	(sd = sdp)->sdflags = 0;
-	sd->slforw = sbx_nfl;
-	sbx_nfl = sd;
-}
-
-SBMA
-sbx_malloc(size)
-unsigned size;
-{
-	register int lev;
-	register SBMA res;
-
-	lev = 0;
-	while((res = (SBMA)malloc(size)) == 0)
-		sbx_comp(size,lev++);
-	return(res);
-}
-
-struct smblk *
-sbx_mget(cmin,cmax)     /* like sbm_mget but never fails! */
-SBMO cmin, cmax;
-{	register struct smblk *sm;
-	register int lev, csiz;
-
-	lev = 0;
-	csiz = cmax;
-	for(;;)
-	  {	if(sm = sbm_mget(csiz,cmax))
-			return(sm);		/* Won right off... */
-		sbx_comp(csiz,lev++);		/* Barf, invoke GC */
-		if(sm = sbm_mget(csiz,cmax))	/* Then try again */
-			return(sm);
-		if((csiz >>= 1) < cmin)		/* If still short, reduce */
-			csiz = cmin;		/* request down to min */
-	  }
-}
-
-
-chroff sbv_taddr;	/* Disk addr of place to write into (set by TSET) */
-struct sdblk *sbv_tsd;	/* SD that disk addr comes after (set by TSET) */
-
-#define sbx_qlk(sd)  (sd->sdflags&SD_LOCKS)
-
-#if 0
-	This is the compaction routine, which is the key to the
-entire scheme.	Paging text to and from disk is trivial, but the
-ability to merge blocks is the important thing since it allows
-flushing the pointer information as well as the actual text!  This
-eliminates fragmentation as a fatal problem.
-	There are a variety of ways that storage can be reclaimed:
-
-- "pure" in-core blocks can be flushed instantly.
-- "impure" incore blocks can be written to tempfile storage and flushed.
-- The SM node freelist can be compacted so as to flush memory which is
-	used for nothing but holding free nodes.
-- The SD node freelist can be compacted, ditto.
-- SBBUFs can be compacted, by:
-	- Merging logically & physically adjacent on-disk pieces
-	- merging logically & physically adjacent in-core pieces
-	- merging logically adjacent in-core pieces
-	- merging logically adjacent disk pieces, by reading in
-		and then writing out to tempfile storage.
-		Worst case would reduce whole sbstr to single tempfile block.
-
-Problems:
-	What is "optimal" algorithm for typical usage?
-	Must go over all code to make sure right things get locked
-		and unlocked to avoid having rug pulled out from under.
-	Could have optional "registration table" for sbstruc; if exist
-		in table, can check during GC.	If find one, can first
-		do sbx_smdisc and then repoint sbcur to 1st block,
-		with sbdot of 0 and sboff of sb_tell().	 This allows
-		reducing whole thing to one block even tho "locked".
-		Never touch stuff locked with SD_LCK2, though.
-		Also may need way to protect the sbstr SD actually being
-		pointed to by current sbx routine processing.
-	Could have count of # nodes free for SM and SD; don''t GC 
-		unless # is some number greater than size of a node block!
-	Have different levels of compaction; pass level # down thru calls
-		so as to invoke progressively sterner compaction measures.
-		Can invoke sbx_comp with any particular level!
-	Must have list somewhere of SBBUFs?  or maybe OK to scan core
-		for SM_DNODS, then scan sdblks?
-	Screw: could happen that stuff gets flushed (cuz pure) or even
-		written out to tempfile, and then we have to read it back
-		in so as to compact more stuff into tempfile... how to avoid?
-		If pure stuff small and next to impure stuff, merge?
-	Some calls just want to get another free node and don''t need
-		new core.  How to indicate this?  How to decide between
-		freeing up used nodes, and creating new node freelist?
-#endif /*COMMENT*/
-/* Compact stuff.
- * General algorithm for getting storage is:
- *	1) allocate from freelist if enough there
- *	2) find unlocked pure smblk to free up
- *	3) find unlocked impure smblks, write out.
- *	4) Compact stuff by reducing # of sdblks.  This is key to scheme!
- *		Otherwise fragmentation will kill program.
- * Maybe put age cnt in each sbstr?  Bump global and set cntr each time
- * sbstr gets major hacking (not just getc/putc).
- */
-extern struct smblk *sbm_list;
-sbx_comp(cmin,lev)
-int cmin, lev;
-{	int sbx_sdgc();
-
-	if(lev > 100)		/* If program has no way to handle this, */
-		abort();	/* then simply blow up. */
-	if(lev > 10)		/* Too many iterations? Try to warn. */
-		return(sbx_err(0,"GC loop, cannot free block of size %d",
-				cmin));
-
-	/* Step thru core hunting for SD node blocks */
-	sbm_nfor(SM_DNODS,sizeof(struct sdblk),sbx_sdgc,lev);
-}
-
-/* Do GC stuff on a sdblk.  Guaranteed to exist, but may be locked */
-sbx_sdgc(sdp,lev)
-struct sdblk *sdp;
-int lev;
-{	register struct sdblk *sd, *sdf;
-	register struct smblk *sm;
-	struct smblk *smf, *sbm_exp ();
-	SBMO more;
-
-	sd = sdp;
-	if(sbx_qlk(sd)) return(0);
-	sm = sd->sdmem;
-	sdf = sd->slforw;
-	if (lev < 4) goto lev3;
-
-	/* Level 4 - write out everything possible */
-	/* Back up to start of sbstr */
-	while((sdf = sd->slback) && !sbx_qlk(sdf))
-		sd = sdf;
-	if((sdf = sd->slforw) == 0	/* If only 1 blk, ensure on disk */
-	  || sbx_qlk(sdf))
-	  {	if(sm = sd->sdmem)
-		  {	if(sd->sdflags&SD_MOD)		/* If impure, */
-				sbx_aout(sd, 1);	/* swap out the SD */
-			sbm_mfree(sm);
-			sd->sdmem = 0;
-		  }
-		return(0);
-	  }
-	/* At least two blocks in string.  Set up for flushout. */
-	sbx_aout(sd, 0);	/* Swapout as much of sbstring as possible */
-	return(0);
-
-lev3:			/* Level 3 - write out more */
-lev2:			/* Level 2 - write out all impure & small pure */
-lev1:	if(lev >= 1)	/* Level 1 - merge small impure & small pure */
-	  {	if(!sm || !sdf) return(0);
-		while(((smf = sdf->sdmem) && !(sdf->sdflags&SD_LOCKS)
-		  && (more = smf->smuse + sm->smuse) < SB_BUFSIZ) )
-		  {	if(sm->smforw != smf
-			  && more > sm->smlen)		/* If need more rm */
-			  {	sm = sbm_exp(sm,more);	/* Get it */
-				if(!sm) return(0);	/* If none, stop */
-				sd->sdmem = sm;
-			  }
-			bcopy(smf->smaddr,
-			     sm->smaddr + sm->smuse, smf->smuse);
-			sm->smuse = more;
-			if(sm->smforw == smf)
-			  {	sdf->sdmem = 0;
-				sbm_mmrg(sm);	/* Merge */
-				if(sm->smlen > more+SB_SLOP)
-					sbm_mfree(sbm_split(sm, more));
-					/* Guaranteed to win since mmrg
-					 * just freed a mem node */
-			  }
-			sd->sdflags |= SD_MOD;
-			if(sdf = sbx_ndel(sdf))
-				continue;
-			return(0);
-		  }
-	  }
-
-	if(lev <= 0)	/* Level 0 - free up large pure blocks */
-			/* Also merge blocks which are adjacent on disk */
-	  {	if(sm)
-		  {	if(sm->smuse == 0)
-				sd->sdlen = 0;
-			else if((sd->sdflags&SD_MOD) == 0
-			    && sm->smuse > 64)
-			  {	sbm_mfree(sm);
-				sd->sdmem = 0;
-				goto lev0adj;
-			  }
-			else goto lev0adj;
-		  }
-
-		if(sd->sdlen == 0	/* Free zero blocks */
-		  && sd->slback)	/* Make sure don't lose list */
-		  {	sbx_ndel(sd);
-			if((sd = sdf) == 0)
-				return(0);
-			sdf = sd->slforw;
-		  }
-	lev0adj:	/* Merge blocks if adjacent on disk */
-			/* This is common after reading thru large chunks
-			* of a file but not modifying it much.
-			*/
-		if((sd->sdflags&SD_MOD) == 0	/* Pure */
-		  && sdf && (sdf->sdflags&(SD_LOCKS|SD_MOD)) == 0
-		  && sd->sdfile && (sd->sdfile == sdf->sdfile)
-		  && (sd->sdaddr + sd->sdlen) == sdf->sdaddr )
-		  {	sd->sdlen += sdf->sdlen;
-			sbx_ndel(sdf);		/* Flush 2nd */
-			if(sm = sd->sdmem)
-			  {	sbm_mfree(sm);
-				sd->sdmem = 0;
-			  }
-		  }
-		return(0);
-	  }
-	return(0);
-}
-
-
-/* SBX_AOUT - output ALL of a hackable sbstring starting at given sdblk.
- *	Note that code is careful to do things so that an abort at any
- *	time (e.g. write error) will still leave sbstring in valid state.
- * Flag value:
- *	0 - Writes out as many unlocked sdblks as possible, and merges
- *		so that resulting sdblk (same one pointed to by arg)
- *		incorporates all stuff written out.
- *	1 - Writes out single sdblk indicated, whether unlocked or not.
- *		Doesn't free mem or merge anything; does update physlist
- *		and flags.
- *	2 - Writes out all sdblks to specified FD/offset, no mods at all,
- *		not even to physlist or flags.	Good for saving files
- *		when something seems wrong.  (How to pass fd/off args?)
- *		(offset arg not implemented, no need yet; 0 assumed)
- * Returns 0 if successful, else UNIX system call error number.
- */
-
-sbx_aout(sdp,flag,fd)
-struct sdblk *sdp;
-int flag, fd;
-{	register struct sdblk *sd;
-	register struct smblk *sm;
-	register int cnt;
-	int ifd, ofd, skflg, rem;
-	chroff inlen;
-	extern SBMA sbm_lowaddr;	/* Need this from SBM for rndrem */
-	char buf[SB_BUFSIZ+16];	/* Get buffer space from stack! */
-				/* Allow extra for word-align reads. */
-				/* This should be +WDSIZE, but some */
-				/* C compilers (eg XENIX) can't handle */
-				/* "sizeof" arith in allocation stmts! */
-
-	/* This flag and the two ptrs below are needed because UNIX
-	 * maintains only one I/O ptr per open file, and we can sometimes
-	 * be reading from/writing to the swapout file at same time.
-	 * Using DUP() to get a new FD (to avoid seeking back and forth)
-	 * won't help since both FD's will use the same I/O ptr!!!
-	 * Lastly, can't depend on returned value of LSEEK to push/pop
-	 * ptr, since V6 systems don't implement tell() or lseek() directly.
-	 * So we have to do it by hand...
-	 */
-	int botchflg;
-	chroff outptr, inptr;
-
-	if((sd = sdp)==0) return;
-	ofd = sbv_tf.sffd;		/* Default output FD */
-	if(flag==0)
-	  {	sbx_tset(sbx_qlen(sd),0);/* Find place for whole string */
-		outptr = sbv_taddr;	/* We'll have to update wrt ptr */
-	  }
-	else if (flag==1)	/* Single SD block, so it's reasonable to 
-				 * try aligning the output with the input. */
-	  {	if(sm = sd->sdmem)
-		  {	cnt = rndrem(sm->smaddr - sbm_lowaddr);
-			sbx_tset((chroff)(sm->smuse),cnt);
-		  }
-		else
-		  {	cnt = rndrem(sd->sdaddr);
-			sbx_tset(sd->sdlen, cnt);
-		  }
-		outptr = sbv_taddr;	/* We'll have to update wrt ptr */
-	  }
-	else		/* Outputting a whole sbstring to a file */
-	  {	ofd = fd;
-		outptr = 0;
-	  }
-
-	for(; sd;)
-	  {	if(flag==0 && sbx_qlk(sd))
-			break;		/* Stop when hit locked sdblk */
-		if(sm = sd->sdmem)
-		  {	if(cnt = sm->smuse)
-				if(write(ofd, sm->smaddr, cnt) != cnt)
-					return(sbx_err(errno,"Swapout wrt err"));
-			outptr += cnt;
-			if(flag==0)
-			  {	sd->sdmem = 0;	/* Flush the mem used */
-				sbm_mfree(sm);
-			  }
-			inlen = cnt;
-		  }
-		else if(inlen = sd->sdlen)
-		  {	if(sd->sdfile == 0)
-				return(sbx_err(errno,"Sdfile 0, SD %o",sd));
-			/* Foo on UNIX */
-			botchflg = ((ifd = sd->sdfile->sffd) == ofd) ? 1 : 0;
-			skflg = 1;		/* Always seek first time */
-			inptr = sd->sdaddr;
-			/* Efficiency hack - set up for first read so that
-			 * transfer is word-aligned and terminates at end
-			 * of a disk block.
-			 */
-			rem = rndrem(inptr);		/* Get alignment */
-			cnt = SB_BUFSIZ - (int)(inptr%SB_BUFSIZ);
-			while(inlen > 0)
-			  {
-				if(inlen < cnt) cnt = inlen;
-				if(!sbx_rdf(ifd, buf+rem, cnt, skflg, inptr))
-					return(sbx_err(errno,"Swapout err, SD %o",sd));
-				/* Further seeks depend on botch setting */
-				if(skflg = botchflg)
-				  {	if(lseek(ofd,outptr,0) < 0)
-						return(sbx_err(errno,
-							"Swapout sk err"));
-					inptr += cnt;
-				  }
-				if(write(ofd, buf+rem, cnt) != cnt)
-					return(sbx_err(errno,
-						"Swapout wrt err"));
-				outptr += cnt;
-				inlen -= cnt;
-				cnt = SB_BUFSIZ; /* Now can use full blocks */
-				rem = 0;	/* Aligned nicely, too! */
-			  }
-			inlen = sd->sdlen;
-		  }
-
-		/* Text written out, now merge block in */
-		if(flag == 2)			/* No merge if saving file */
-			goto donxt;
-		if(sd != sdp)			/* First block? */
-		  {	sdp->sdlen += inlen;	/* No, simple merge */
-			sd = sbx_ndel(sd);	/* Flush, get next */
-			continue;
-		  }
-
-		/* Handle 1st block specially */
-		if(sd->sdfile		/* Unlink from phys list */
-		  && sd != sbv_tsd)	/* Don't unlink if self */
-			sbx_npdel(sd);
-		sd->sdlen = inlen;
-		sd->sdfile = &sbv_tf;
-		sd->sdaddr = sbv_taddr;	/* Set from sbx_tset val */
-		sd->sdflags &= ~SD_MOD;	/* On disk, no longer modified */
-
-		/* Now insert into phys list at specified place */
-		if(sd == sbv_tsd)	/* If already same place */
-			goto next;	/* Skip linkin. */
-		if(sd->sdback = sbv_tsd)
-		  {	sd->sdforw = sbv_tsd->sdforw;
-			sd->sdback->sdforw = sd;
-		  }
-		else
-		  {	sd->sdforw = sbv_tf.sfptr1;
-			sbv_tf.sfptr1 = sd;
-		  }
-		if(sd->sdforw)
-			sd->sdforw->sdback = sd;
-
-	next:	if(flag==1)		/* If only doing 1 sdblk, */
-			break;		/* stop here. */
-	donxt:	sd = sd->slforw;	/* Done with 1st, get next */
-	  }
-	return(0);			/* Win return, no errors */
-}
-
-/* Returns hackable length of a sbstring (ends at EOF or locked block) */
-chroff
-sbx_qlen(sdp)
-struct sdblk *sdp;
-{	register struct sdblk *sd;
-	register struct smblk *sm;
-	chroff len;
-
-	len = 0;
-	for(sd = sdp; sd && !sbx_qlk(sd); sd = sd->slforw)
-		if(sm = sd->sdmem)
-			len += (chroff)sm->smuse;
-		else len += sd->sdlen;
-	return(len);
-}
-
-
-
-/* SBX_TSET - finds a place on temp swapout file big enough to hold
- *	given # of chars.  Sets SBV_TADDR to that location, as well
- *	as seeking to it so the next write call will output there.
- *	This location is guaranteed to have the requested
- *	byte alignment (0 = word-aligned).
- */
-sbx_tset(loff, align)
-chroff loff;
-int align;
-{	register int fd;
-
-	if(sbv_tf.sffd <= 0)
-	  {		/* Must open the temp file! */
-/* Temporary file mechanism is system-dependent.  Eventually this
-** will probably require inclusion of a true c-env header file; for the
-** time being, we can cheat a little by checking O_T20_WILD, which will
-** be defined by <sys/file.h> on TOPS-20.  Otherwise, we assume we are
-** on a real Unix.
-*/
-#ifdef O_T20_WILD
-		extern char *tmpnam();	/* Use ANSI function */
-		fd = open(tmpnam((char *)NULL),
-				O_RDWR | O_CREAT | O_TRUNC | O_BINARY);
-		if(fd < 0)
-			return(sbx_err(0,"Swapout creat err"));		
-#else /* Real Unix */
-		static char fcp[] = "/tmp/sbd.XXXXXX";
-		if((fd = creat(mktemp(fcp),0600)) < 0)
-			return(sbx_err(0,"Swapout creat err"));
-		/* Must re-open so that we can both read and write to it */
-		close(fd);
-		if((fd = open(fcp,2)) < 0)
-			return(sbx_err(0,"Swapout open err"));
-		unlink(fcp);	/* Set so it vanishes when we do */
-#endif
-
-		sbv_tf.sffd = fd;	/* Initialize the sbfile struct */
-		sbv_tf.sfptr1 = 0;
-		sbv_ftab[fd] = &sbv_tf;	/* Record in table of all sbfiles */
-		sbv_taddr = 0;		/* "Return" this value */
-		return;		/* Ignore alignment for now */
-	  }
-	sbv_tsd = sbx_ffnd(&sbv_tf, loff+align, &sbv_taddr);
-	sbv_taddr += align;
-	if(lseek(sbv_tf.sffd, sbv_taddr, 0) < 0)
-		return(sbx_err(0,"Swapout seek err: (%d,%ld,0) %d %s",
-			sbv_tf.sffd, sbv_taddr, errno, strerror(errno)));
-
-}
-
-/* SBX_FFND - searches disk list of given file for free space of
- *	at least size chars.  Note that list must be sorted by ascending
- *	disk addrs in order for this to work!  If sdaddrs are only
- *	changed in SBX_SPLIT this will be true.
- *	Sets "aloc" to disk address for writing (this is guaranteed to
- *	be word-aligned, for efficiency), and returns SD ptr to
- *	block which this addr should follow in the physical list.  If ptr
- *	is 0, it means addr should be 1st thing in list.
- */
-struct sdblk *
-sbx_ffnd(sfp, size, aloc)
-SBFILE *sfp;
-chroff size, *aloc;
-{	register struct sdblk *sd, *sds, *sdl;
-	chroff cur;
-
-	cur = 0;
-	sds = 0;
-	sd = sfp->sfptr1;
-redo:	for(; sd ; sd = (sds=sd)->sdforw)
-	  {	if(cur < sd->sdaddr)		/* Gap seen? */
-		  {	if(size <= (sd->sdaddr - cur))	/* Yes, big enuf? */
-				break;			/* Yup! */
-		  }					/* No, bump. */
-		else if(cur >=(sd->sdaddr + sd->sdlen))	/* No gap but chk */
-			continue;			/* No overlap, ok */
-		/* Bump to next possible gap. */
-		cur = sd->sdaddr + sd->sdlen;
-		cur = (long)rndup(cur);	/* Round up to word boundary! */
-	  }
-	*aloc = cur;		/* Return winning addr */
-
-	/* Perform verification check -- make sure this really is OK
-	 * and complain if not.	 If this never blows up, eventually can
-	 * take the check out.
-	 */
-	sdl = sd;
-	for(sd = sfp->sfptr1; sd; sd = sd->sdforw)
-	  {	if(cur < sd->sdaddr)
-		  {	if(size <= (sd->sdaddr - cur))
-				continue;
-		  }
-		else if(cur >= (sd->sdaddr + sd->sdlen))
-			continue;
-
-		sbx_err(0,"FFND blew it, but recovered. SD %o siz %ld",
-			sd, size);
-		sd = (sds = sdl)->sdforw;
-		goto redo;
-	  }
-
-
-	return(sds);		/* Return ptr to block this addr follows */
-}
-
-sbx_rdf(fd,addr,cnt,skflg,loc)
-register int fd;
-char *addr;
-int skflg;
-chroff loc;
-{	register int rres, eres;
-	long lres;
-	char *errtyp, *ftyp;
-	chroff curlen;
-
-	errno = 0;
-	if(skflg && (lres = lseek(fd, (long)loc, 0)) == -1)
-	  {	errtyp = "Sk err";
-		goto errhan;
-	  }
-	if((rres = read(fd, addr, cnt)) != cnt)
-	  {	lres = rres;
-		errtyp = "Rd err";
-		goto errhan;
-	  }
-	return(rres);
-errhan:				/* Handle read or seek error */
-	eres = errno;
-	if(fd == sbv_tf.sffd)	/* See if dealing with swapout file */
-	  {	ftyp = "(swap)";
-		curlen = 0;
-	  }
-	else {			/* No, normal buffer file. */
-		ftyp = "";
-		curlen = sbx_fdlen(fd);
-		if(sbv_ftab[fd] &&
-		  (curlen != sbv_ftab[fd]->sflen))	/* File changed? */
-			if(sbx_rugpull(fd))	/* Yes, handle special case */
-				return(cnt);	/* Allow "win" return */
-	  }
-	sbx_err(0,"%s %d:%s, %ld:(%d%s,%o,%d)=%ld (fl %ld)",
-			errtyp,	eres, strerror(eres),
-			loc, fd, ftyp, addr, cnt, lres,
-			curlen);
-	return(0);
-}
-
-/* SBX_RUGPULL(fd) - Special routine called when package detects that
- *	the file indicated by the fd has changed since its original
- *	opening.  This can happen when a file is over-written by some
- *	other program (ED, for example).
- *	This means that all sdblks which reference this fd
- *	are probably bad.  Pass special error back up to the calling
- *	program to give it a chance at doing something.
- *	Extra credit: scan all sdblks and unpurify all which point to this
- *	file, so as to protect everything we still remember about it.
- *	Otherwise a GC could flush pure in-core portions.
- */
-sbx_rugpull(fd)		/* FD already known to have entry in sbv_ftab */
-register int fd;
-{	int sbx_unpur();
-
-	/* First scan all sdblks to save what we still have. */
-	/* This does NOT remove the sdfile pointer, so we can still
-	 * find blocks that are affected. */
-	sbm_nfor(SM_DNODS, sizeof(struct sdblk), sbx_unpur, sbv_ftab[fd]);
-
-	if((int)sbv_debug == 1 || !sbv_debug)
-		return(0);			/* Nothing else we can do */
-	return((*sbv_debug)(2,(int *)0,"",fd));	/* Let caller handle it */
-}
-sbx_unpur(sd, sf)		/* Auxiliary routine for SBX_RUGPULL */
-register struct sdblk *sd;
-register struct sbfile *sf;
-{	if(sd->sdfile == sf	/* If sdblk belongs to affected file */
-	  && sd->sdmem)		/* and has in-core version of text, */
-		sd->sdflags |= SD_MOD;	/* then ensure core version is used */
-}
-
-sbx_err(val,str,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
-char *str;
-{	int *sptr;
-
-	sptr = (int *) &sptr;	/* Point to self on stack */
-	sptr += 5;		/* Point to return addr */
-	if((int)sbv_debug == 1)
-	  {	abort();
-	  }
-	if(sbv_debug)
-		(*sbv_debug)(1,*sptr,str,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12);
-	return(val);
-}
Index: trunk/minix/commands/elle/sbvall.c
===================================================================
--- trunk/minix/commands/elle/sbvall.c	(revision 9)
+++ 	(revision )
@@ -1,42 +1,0 @@
-/* VALLOC - Aligned memory allocator
- *	Emulation of the 4.2BSD library routine of the same name.
- *	Copyright 1985 by Ken Harrenstien, SRI International
- *	This software is quasi-public; it may be used freely with
- *	like software, but may NOT be sold or made part of licensed
- *	products without permission of the author.  In all cases
- *	the source code and any modifications thereto must remain
- *	available to any user.
- *
- *	This is part of the SB library package.
- *	Any software using the SB library must likewise be made
- *	quasi-public, with freely available sources.
- */
-
-#include "sb.h"
-
-char *
-valloc(size)
-unsigned size;
-{	register int pagmsk;
-	register SBMO i;
-	register struct smblk *sm, *smr;
-	struct smblk *sbm_mget(), *sbm_split();
-
-	pagmsk = getpagesize() - 1;	/* Get page size in bytes, less 1 */
-	if(!(sm = sbm_mget(size+pagmsk, size+pagmsk))) /* Get area big enuf */
-		return(0);
-	/* Now find # bytes prior to 1st page boundary.
-	 * This expression gives 0 if already at boundary, else #-1.
-	 */
-	i = pagmsk - ((int)(sm->smaddr) & pagmsk);
-	if(i)		/* If need to split off preceding stuff, */
-	  {	smr = sbm_split(sm, i+1);	/* do so (note i adjusted) */
-		sbm_mfree(sm);			/* Release preceding mem */
-		if(!(sm = smr)) return(0);	/* If couldn't split, fail */
-	  }
-	if(i = (sm->smlen - size))	/* See if any trailing stuff */
-	  {	smr = sbm_split(sm, size);	/* Yeah, split it off too */
-		if(smr) sbm_mfree(smr);	/* If couldn't split, excess OK. */
-	  }
-	return((char *)(sm->smaddr));
-}
Index: trunk/minix/commands/elvis/.descr
===================================================================
--- trunk/minix/commands/elvis/.descr	(revision 9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-Lightweight vi
Index: trunk/minix/commands/elvis/Doc.sh
===================================================================
--- trunk/minix/commands/elvis/Doc.sh	(revision 9)
+++ 	(revision )
@@ -1,3314 +1,0 @@
-echo x - cflags.ms
-sed '/^X/s///' > cflags.ms << '/'
-X.Go 9 "CFLAGS"
-X.PP
-X\*E uses many preprocessor symbols to control compilation.
-XSome of these control the sizes of buffers and such.
-XThe "-DNO_XXXX" options remove small sets of related features.
-X.PP
-XMost \*E users will probably want to keep all features available.
-XMinix-PC users, though, will have to sacrifice some sets because otherwise
-X\*E would be too bulky to compile.
-XThe "asld" phase of the compiler craps out.
-X.IP "-DM_SYSV, -Dbsd, -DTOS, -DCOHERENT, -Damiga"
-XThese flags tell the compiler that \*E is being compiled for
-XSystem-V UNIX, BSD UNIX, Atari TOS, Coherent, or AmigaDos, respectively.
-XFor other systems, the config.h file can generally figure it out automatically.
-X.IP -DRAINBOW
-XFor MS-DOS systems, this causes support for the DEC Rainbow to be compiled
-Xinto \*E.
-X.IP -DS5WINSIZE
-XSome versions of SysV UNIX don't support support the "winsize"
-Xstyle of screen-size testing,
-Xso elvis ignores window size changes by default.
-X.IP
-XHowever, many of the newer SysV systems defines "winsize" in the
-Xfile "/usr/include/sys/ptem.h".
-XIf your SysV system has "winsize" then you should add
-X-DS5SWINSIZE to the CFLAGS setting.
-X.IP -DTERMIOS
-XPOSIX is a SysV-derived specification which uses a terminal control
-Xpackage called "termios", instead of "termio".
-XSome other SysV systems may also use termios.
-XYou can make elvis uses termios instead of the more common termio
-Xby adding -DTERMIOS to CFLAGS.
-X(Note: This hasn't been tested very well.)
-X.IP -DNBUFS=\fInumber\fP
-X\*E keeps most of your text in a temporary file;
-Xonly a small amount is actually stored in RAM.
-XThis flag allows you to control how much of the file can be in RAM at any time.
-XThe default is 5 blocks, and the minimum is 3 blocks.
-X(See the -DBLKSIZE flag, below.)
-X.IP
-XMore RAM allows global changes to happen a little faster.
-X f you're just making many small changes in one section of a file, though,
-Xextra RAM won't help much.
-X.IP -DBLKSIZE=\fInumber\fP
-XThis controls the size of blocks that \*E uses internally.
-XThe value of BLKSIZE must be a power of two.
-XEvery time you double BLKSIZE, you quadruple the size of a text file that
-X\*E can handle, but you also cause the temporary file to grow faster.
-XFor MS-DOS, Coherent, and Minix-PC, the default value is 1024, which allows
-Xyou to edit files up to almost 512K bytes long.
-XFor all other systems, the default value is 2048, which allows you to edit
-Xfiles that are nearly 2 megabytes long.
-X.IP
-XThe BLKSIZE also determines the maximum line length, and a few other limits.
-XBLKSIZE should be either 256, 512, 1024, or 2048.
-XValues other than these can lead to strange behaviour.
-X.IP -DTMPDIR=\fIstring\fP
-XThis sets the default value of the "directory" option, which specifies where
-Xthe temporary files should reside.
-XThe value of TMPDIR must be a string, so be sure your value includes the
-Xquote characters on each end.
-X.IP "-DEXRC=\fIstr\fP, -DHMEXRC=\fIstr\fP, -DSYSEXRC=\fIstr\fP, -DEXINIT=\fIstr\fP"
-XThis lets you control the names of the initialization files.
-XTheir values must be strings, so be careful about quoting.
-X.IP
-XEXRC is the name of the initialization file in the current directory.
-XIts default value is ".exrc" on UNIX systems -- the same as the real vi.
-XSince that isn't a legal DOS filename, under DOS the default is "elvis.rc".
-XFor other systems, check the config.h file.
-X.IP
-XHMEXRC is the name of the initialization file in your home directory.
-XBy default, it is the same as EXRC.
-X\*E will automatically prepend the name of your home directory to HMEXRC
-Xat run time, so don't give a full path name.
-X.IP
-XSYSEXRC is the name of a system-wide initialization file.
-XIt has no default value;
-Xif you don't define a value for it, then
-Xthe code that supports SYSEXRC just isn't compiled.
-XThe value of SYSEXRC should be a full pathname, in quotes.
-X.IP
-XEXINIT is the name of an environment variable that can contain initialization
-Xcommands.
-XNormally, its value is "EXINIT".
-X.IP -DKEYWORDPRG=\fIstring\fP
-XThis flag determines the default value of the "keywordprg" option.
-XIts value must be a string, so be careful about quoting.
-XThe default value of this flag is "ref", which is a C reference program.
-X.IP "-DCC_COMMAND=\fIstring\fP -DMAKE_COMMAND=\fIstring\fP -DERRLIST=\fIstring\fP"
-XThese control the names of the C compiler, the "make" utility, and the
-Xerror output file, respectively.
-XThey are only used if -DNO_ERRLIST is not given.
-X.IP
-XThe default value of CC_COMMAND depends on the Operating System and compiler
-Xthat you use to compile elvis;
-Xfor UNIX, the default is "cc".
-XThe default values of MAKE_COMMAND and ERRLIST are "make" and "errlist",
-Xrespectively.
-X.IP -DMAXRCLEN=\fInumber\fP
-XThis determines how large a :@ macro command can be (measured in bytes).
-XThe default is 1000 bytes.
-XIf you increase this value significantly,
-Xthen you may need to allocate extra memory for the stack.
-XSee the "CHMEM" setting in the Makefile.
-X.IP -DSHELL=\fIstring\fP
-XThis is the default value of the "shell" option, and hence
-Xthe default shell used from within \*E.
-XThis only controls the default;
-Xthe value you give here may be overridden at run-time by setting
-Xan environment variable named SHELL (or COMSPEC for MS-DOS).
-XIts value must be a string constant, so be careful about quoting.
-X.IP -DTAGS=\fIstring\fP
-XThis sets the name of the "tags" file,
-Xwhich is used by the :tag command.
-XIts value must be a string constant, so be careful about quoting.
-X.IP "-DCS_IBMPC -DCS_LATIN1 -DCS_SPECIAL"
-XThe digraph table and flipcase option will normally start out empty.
-XHowever, if you add -DCS_IBMPC or -DCS_LATIN1 to your CFLAGS,
-Xthen they will start out filled with values that are appropriate for the
-XIBM PC character set or the ISO Latin-1 character set, respectively.
-X.IP
-XYou can also use -DCS_IBMPC and -DCS_SPECIAL together to get digraphs
-Xthat produce the PC's graphic characters.
-X.IP "-DDEBUG -DEBUG2"
-X-DDEBUG adds the ":debug" and ":validate" commands,
-Xand also adds many internal consistency checks.
-XIt increases the size of the ".text" segment by about 6K.
-X.IP
-X-DDEBUG2 causes a line to be appended to a file called "debug.out"
-Xeverytime any change is made to the edit buffer.
-X.IP -DCRUNCH
-XThis flag removes some non-critical code, so that \*E is smaller.
-XFor example, it removes a short-cut from the regexp package, so that
-Xtext searches are slower.
-XAlso, screen updates are not as efficient.
-XA couple of obscure features are disabled by this, too.
-X.IP -DNO_MKEXRC
-XThis removes the ":mkexrc" command,
-Xso you have to create any .exrc files manually.
-XThe size of the .text segment will be reduced by about 600 bytes.
-X.IP -DNO_CHARATTR
-XPermanently disables the charattr option.
-XThis reduces the size of your ".text" segment by about 850 bytes.
-X.IP -DNO_RECYCLE
-XNormally, \*E will recycle space (from the temporary file) which contains
-Xtotally obsolete text.
-XThis flag disables this recycling.
-XWithout recycling, the ".text" segment is about 1K smaller
-Xthan it would otherwise be,
-Xbut the tmp file grows much faster.
-XIf you have a lot of free space on your hard disk,
-Xbut \*E is too bulky to run with recycling,
-Xthen try it without recycling.
-X.IP
-XWhen using a version of \*E that has been compiled with -DNO_RECYCLE,
-Xyou should be careful to avoid making many small changes to a file
-Xbecause each individual change will cause the tmp file to grow by at least 1k.
-XHitting "x" thirty times counts as thirty changes,
-Xbut typing "30x" counts as one change.
-XAlso, you should occasionally do a ":w" followed by a ":e" to start with a
-Xfresh tmp file.
-X.IP
-XInterestingly, the real vi never recycles space from its temporary file.
-X.IP -DNO_SENTENCE
-XLeaves out the "(" and ")" visual mode commands.
-XAlso, the "[[", "]]", "{", and "}" commands will not recognize *roff macros.
-XThe sections and paragraphs options go away.
-XThis saves about 650 bytes in the ".text" segment.
-X.IP -DNO_CHARSEARCH
-XLeaves out the visual commands which locate a given character
-Xin the current line:
-X"f", "t", "F", "T", "," and ";".
-XThis saves about 900 bytes.
-X.IP -DNO_EXTENSIONS
-XLeaves out the "K" and "#" visual commands.
-XAlso, the arrow keys will no longer work in input mode.
-XRegular expressions will no longer recognize the \\{\\} operator.
-X(Other extensions are either inherent in the design of \*E,
-Xor are controlled by more specific flags,
-Xor are too tiny to be worth removing.)
-XThis saves about 250 bytes.
-X.IP -DNO_MAGIC
-XPermanently disables the "magic" option, so that most meta-characters
-Xin a regular expression are *NOT* recognized.
-XThis saves about 3k of space in the ".text" segment, because
-Xthe complex regular expression code can be replaced by much simpler code.
-X.IP -DNO_SHOWMODE
-XPermanently disables the "showmode" option, saving about 250 bytes.
-X.IP -DNO_CURSORSHAPE
-XNormally, \*E tries to adjust the shape of the cursor as a reminder
-Xof which mode you're in.
-XThe -DNO_CURSORSHAPE flag disables this, saving about 150 bytes.
-X.IP -DNO_DIGRAPH
-XTo allow entry of non-ASCII characters, \*E supports digraphs.
-XA digraph is a single (non-ASCII) character which is entered as a
-Xcombination of two other (ASCII) characters.
-XIf you don't need to input non-ASCII characters,
-Xor if your keyboard supports a better way of entering non-ASCII characters,
-Xthen you can disable the digraph code and save about 450 bytes.
-X.IP -DNO_ERRLIST
-X\*E adds a ":errlist" command, which is useful to programmers.
-XIf you don't need this feature, you can disable it via the -DNO_ERRLIST flag.
-XThis will reduce the .text segment by about 900 bytes, and the .bss segment
-Xby about 300 bytes.
-X.IP -DNO_ABBR
-XThe -DNO_ABBR flag disables the ":abbr" command,
-Xand reduces the size of \*E by about 250 bytes.
-X.IP -DNO_OPTCOLS
-XWhen \*E displays the current options settings via the ":set" command,
-Xthe options are normally sorted into columns.
-XThe -DNO_OPTCOLS flag causes the options to be sorted across the rows,
-Xwhich is much simpler for the computer.
-XThe -DNO_OPTCOLS flag will reduce the size of your .text segment by about
-X500 bytes.
-X.IP -DNO_MODELINES
-XThis removes all support for modelines.
-X.IP -DNO_TAG
-XThis disables tag lookup.
-XIt reduces the size of the .text segment by about 750 bytes.
-X.IP "-DNO_ALT_FKEY -DNO_CTRL_FKEY -DNO_SHIFT_FKEY -DNO_FKEY"
-XThese remove explicit support of function keys.
-X-DNO_ALT_FKEY removes support for the <alternate> versions function keys.
-X-DNO_CTRL_FKEY removes support for the <control> and <alternate> versions function keys.
-X-DNO_SHIFT_FKEY removes support for the <shift>, <control>, and <alternate> versions function keys.
-X-DNO_FKEY removes all support of function keys.
-X.IP
-X\*E's ":map" command normally allows you to use the special sequence "#<n>"
-Xto map function key <n>.
-XFor example, ":map #1 {!}fmt^M" will cause the <F1> key to reformat a paragraph.
-X\*E checks the :k1=: field in the termcap description of your terminal
-Xto figure out what code is sent by the <F1> key.
-XThis is handy because it allows you to create a .exrc file which maps function
-Xkeys the same way regardless of what type of terminal you use.
-X.IP
-XThat behaviour is standard; most implementations of the real vi supports it too.
-X\*E extends this to allow you to use "#1s" to refer to <shift>+<F1>,
-X"#1c" to refer to <control>+<F1>, and
-X"#1a" to refer to <alt>+<F1>.
-XThe termcap description for the terminal should have fields named
-X:s1=:c1=:a1=: respectively, to define the code sent by these key conbinations.
-X(You should also have :k2=:s2=:c2=:a2=: for the <F2> key, and so on.)
-X.IP
-XBut there may be problems.
-XThe terminfo database doesn't support :s1=:c1=:a1=:, so no terminfo terminal
-Xdescription could ever support shift/control/alt function keys;
-Xso you might as well add -DNO_SHIFT_FKEY to CFLAGS if you're using terminfo.
-X.IP
-XNote that, even if you have -DNO_FKEYS, you can still configure \*E to use
-Xyour function keys my mapping the literal character codes sent by the key.
-XYou just couldn't do it in a terminal-independent way.
-XTERM_925
-X.IP "-DTERM_AMIGA -DTERM_VT100 -DTERM_VT52 etc."
-XThe tinytcap.c file contains descriptions of several terminal types.
-XFor each system that uses tinytcap, a reasonable subset of the available
-Xdescriptions is actually compiled into \*E.
-XIf you wish to enlarge this subset, then you can add the appropriate -DTERM_XXX
-Xflag to your CFLAGS settings.
-X.IP
-XFor a list of the available terminal types, check the tinytcap.c file.
-X.IP -DINTERNAL_TAGS
-XNormally, \*E uses the "ref" program to perform tag lookup.
-XThis is more powerful than the real vi's tag lookup,
-Xbut it can be much slower.
-X.IP
-XIf you add -DINTERNAL_TAGS to your CFLAGS setting,
-Xthen \* will use its own internal tag lookup code, which is faster.
-X.IP -DPRSVDIR=\fIdirectory\fR
-XThis controls where preserved files will be placed.
-XAn appropriate default has been chosen for each Operating System,
-Xso you probably don't need to worry about it.
-X.IP -DFILEPERMS=\fInumber\fR
-XThis affects the attributes of files that are created by \*E;
-Xit is used as the second argument to the creat() function.
-XThe default is 0666 which (on UNIX systems at least) means that
-Xanybody can read or write the new file, but nobody can execute it.
-XOn UNIX systems, the creat() call modifies this via the umask setting.
-X.IP -DKEYBUFSIZE=\fInumber\fR
-XThis determines the size of the type-ahead buffer that elvis uses.
-XIt also limits the size of keymaps that it can handle.
-XThe default is 1000 characters, which should be plenty.
-/
-echo x - cutbufs.ms
-sed '/^X/s///' > cutbufs.ms << '/'
-X.Go 6 "CUT BUFFERS"
-X.PP
-XWhen \*E deletes text, it stores that text in a cut buffer.
-XThis happens in both visual mode and EX mode.
-XThere is no practical limit to how much text a cut buffer can hold.
-X.PP
-XThere are 36 cut buffers:
-X26 named buffers ("a through "z),
-X9 anonymous buffers ("1 through "9),
-Xand 1 extra cut buffer (".).
-X.PP
-XIn EX mode, the :move and :copy commands use a cut buffer to temporarily
-Xhold the text to be moved/copied.
-X.NH 2
-XPutting text into a Cut Buffer
-X.PP
-XIn visual mode, text is copied into a cut buffer when you use the
-Xd, y, c, C, s, or x commands.
-XThere are also a few others.
-X.PP
-XBy default, the text goes into the "1 buffer.
-XThe text that used to be in "1 gets shifted into "2,
-X"2 gets shifted into "3, and so on.
-XThe text that used to be in "9 is lost.
-XThis way, the last 9 things you deleted are still accessible.
-X.PP
-XYou can also put the text into a named buffer -- "a through "z.
-XTo do this, you should type the buffer's name
-X(two keystrokes: a double-quote and a lowercase letter)
-Xbefore the command that will cut the text.
-XWhen you do this, "1 through "9 are not affected by the cut.
-X.PP
-XYou can append text to one of the named buffers.
-XTo do this, type the buffer's name in uppercase
-X(a double-quote and an uppercase letter)
-Xbefore the d/y/c/C/s/x command.
-X.PP
-XThe ". buffer is special.
-XIt isn't affected by the d/y/c/C/s/x command.
-XInstead, it stores the text that you typed in
-Xthe last time you were in input mode.
-XIt is used to implement the . visual command,
-Xand ^A in input mode.
-X.PP
-XIn EX mode (also known as colon mode),
-Xthe :delete, :change, and :yank commands all copy text into a cut buffer.
-XLike the visual commands, these EX commands normally use the "1 buffer,
-Xbut you can use one of the named buffers by giving its name after the command.
-XFor example,
-X.sp 1
-X.ti +0.5i
-X:20,30y a
-X.sp
-X.LP
-Xwill copy lines 20 through 30 into cut buffer "a.
-X.PP
-XYou can't directly put text into the ". buffer, or the "2 through "9 buffers.
-X.NH 2
-XPasting from a Cut Buffer
-X.PP
-XThere are two styles of pasting:
-Xline-mode and character-mode.
-XIf a cut buffer contains whole lines (from a command like "dd")
-Xthen line-mode pasting is used;
-Xif it contains partial lines (from a command like "dw")
-Xthen character-mode pasting is used.
-XThe EX commands always cut whole lines.
-X.PP
-XCharacter-mode pasting causes the text to be inserted into the line that
-Xthe cursor is on.
-X.PP
-XLine-mode pasting inserts the text on a new line above or below the line
-Xthat the cursor is on.
-XIt doesn't affect the cursor's line at all.
-X.PP
-XIn visual mode, the p and P commands insert text from a cut buffer.
-XUppercase P will insert it before the cursor,
-Xand lowercase p will insert it after the cursor.
-XNormally, these commands will paste from the "1 buffer, but you can
-Xspecify any other buffer to paste from.
-XJust type its name (a double-quote and another character)
-Xbefore you type the P or p.
-X.PP
-XIn EX mode, the (pu)t command pastes text after a given line.
-XTo paste from a buffer other that "1,
-Xenter its name after the command.
-X.NH 2
-XMacros
-X.PP
-XThe contents of a named cut buffer can be executed as a series of
-Xex/vi commands.
-X.PP
-XTo put the instructions into the cut buffer, you must first insert
-Xthem into the file, and then delete them into a named cut buffer.
-X.PP
-XTo execute a cut buffer's contents as EX commands,
-Xyou should give the EX command "@" and the name of the buffer.
-XFor example, :@z will execute "z as a series of EX commands.
-X.PP
-XTo execute a cut buffer's contents as visual commands,
-Xyou should give the visual command "@" and the letter of the buffer's name.
-XThe visual "@" command is different from the EX "@" command.
-XThey interpret the cut buffer's contents differently.
-X.PP
-XThe visual @ command can be rather finicky.
-XEach character in the buffer is interpretted as a keystroke.
-XIf you load the instructions into the cut buffer via a "zdd command,
-Xthen the newline character at the end of the line will be executed just
-Xlike any other character, so the cursor would be moved down 1 line.
-XIf you don't want the cursor to move down 1 line at the end of each
-X@z command, then you should load the cut buffer by saying 0"zD instead.
-X.PP
-XAlthough cut buffers can hold any amount of text,
-X\*E can only \fIexecute\fR small buffers.
-XThe size limit is roughly 1000 characters, for either EX macros or VI macros.
-XIf a buffer is too large to execute, an error message is displayed.
-X.PP
-XYou can't nest :@ commands.
-XYou can't run :@ commands from your .exrc file,
-Xor any other :source file either.
-XSimilarly, you can't run a :source command from within an @ command.
-XHopefully, these restrictions will be lifted in a later version.
-X.NH 2
-XThe Effect of Switching Files
-X.PP
-XWhen \*E first starts up, all cut buffers are empty.
-XWhen you switch to a different file
-X(via the :n or :e commands perhaps)
-Xthe 9 anonymous cut buffers are emptied again,
-Xbut the other 27 buffers ("a through "z, and ".) retain their text.
-/
-echo x - differ.ms
-sed '/^X/s///' > differ.ms << '/'
-X.Go 7 "DIFFERENCES BETWEEN \*E & BSD VI/EX"
-X.PP
-X\*E is not 100% compatible with the real vi/ex.
-X\*E has many small extensions, some omissions, and a few features which
-Xare implemented in a slightly different manner.
-X.NH 2
-XExtensions
-X.IP "Save Configuration" 1i
-XThe :mkexrc command saves the current :set and :map configurations in
-Xthe ".exrc" file in your current directory.
-X.IP "Previous File" 1i
-XThe :N or :prev command moves backwards through the args list.
-X.IP "Center Current Row" 1i
-XIn visual command mode, the (lowercase) "zz" command will center the current
-Xline on the screen, like "z=".
-X.IP "Changing Repeat Count" 1i
-XThe default count value for . is the same as the previous command
-Xwhich . is meant to repeat.
-XHowever, you can supply a new count if you wish.
-XFor example, after "3dw", "." will delete 3 words,
-Xbut "5." will delete 5 words.
-X.IP "Previous Text" 1i
-XThe text which was most recently input
-X(via a "cw" command, or something similar)
-Xis saved in a cut buffer called ". (which
-Xis a pretty hard name to write in an English sentence).
-X.IP "Keyword Lookup" 1i
-XIn visual command mode, you can move the cursor onto a word and press
-Xshift-K to have \*E run a reference program to look that word up.
-XThis command alone is worth the price of admission!
-XSee the ctags and ref programs.
-X.IP "Increment/Decrement" 1i
-XIn visual command mode, you can move the cursor onto a number and
-Xthen hit ## or #+ to increment that number by 1.
-XTo increment it by a larger amount,
-Xtype in the increment value before hitting the initial #.
-XThe number can also be decremented or set by hitting #- or #=, respectively.
-X.IP "Input Mode" 1i
-XYou can backspace past the beginning of the line.
-X.IP "" 1i
-XThe arrow keys work in input mode.
-X.IP "" 1i
-XIf you type control-A, then the text that you input last time is inserted.
-XYou will remain in input mode, so you can backspace over part of it,
-Xor add more to it.
-X(This is sort of like control-@ on the real vi,
-Xexcept that control-A really works.)
-X.IP "" 1i
-XControl-P will insert the contents of the cut buffer.
-X.IP "" 1i
-XReal vi can only remember up to 128 characters of input,
-Xbut \*E can remember any amount.
-X.IP "" 1i
-XThe ^T and ^D keys can adjust the indent of a line no matter where
-Xthe cursor happens to be in that line.
-X.IP "" 1i
-XYou can save your file and exit \*E directly from input mode by hitting
-Xcontrol-Z twice.
-X.IP "" 1i
-X\*E supports digraphs as a way to enter non-ASCII characters.
-X.IP "Start in Input Mode" 1i
-XIf you ":set inputmode" in your .exrc file, then \*E will start up in
-Xinput mode instead of visual command mode.
-X.IP "Visible Fonts" 1i
-XWith ":set charattr", \*E can display "backslash-f" style character attributes on the
-Xscreen as you edit.
-XThe following example shows the recognized atributes:
-X.sp
-X.ti +0.5i
-Xnormal \\fBboldface\\fR \\fIitalics\\fR \\fUunderlined\\fR normal
-X.sp
-XNOTE: you must compile \*E without the -DNO_CHARATTR flag for
-Xthis to work.
-X.IP "File Syncing" 1i
-XAfter a crash, you can usually recover the altered form of the file
-Xfrom the temporary file that \*E uses -- unless the temporary file was
-Xcorrupted.
-X.IP "" 1i
-XUNIX systems use a delayed-write cache, which means that when \*E tries to
-Xwrite to the temporary file, the information might still be in RAM instead
-Xof on the disk.
-XA power failure at that time would cause the in-RAM information to be lost.
-XUNIX's sync() call will force all such information to disk.
-X.IP "" 1i
-XMS-DOS and Atari TOS don't write a file's length to disk until that file
-Xis closed.
-XConsequently, the temporary file would appear to be 0 bytes long if power
-Xfailed when we were editing.
-XTo avoid this problem, a sync() function has been written which will close
-Xthe temporary file and then immediately reopen it.
-X.IP "Cursor Shape" 1i
-X\*E changes the shape of the cursor to indicate which mode you're in,
-Xif your terminal's termcap entry includes the necessary capabilities.
-X.IP "Hide nroff Lines" 1i
-XTh ":set hideformat" option hides nroff format control lines.
-X(They are displayed on the screen as blank lines.)
-X.ne 7
-X.IP "Compiler Interface" 1i
-X\*E is clever enough to parse the error messages emitted by many compilers.
-XTo use this feature,
-Xyou should collect your compiler's error messages into a file called "errlist";
-X\*E will read this file,
-Xdetermine which source file caused the error messages,
-Xstart editing that file,
-Xmove the cursor to the line where the error was detected,
-Xand display the error message on the status line.
-XNifty!
-X.IP "Visible Text Selection" 1i
-XIn visual command mode, 'v' starts visibly selecting characters and
-X\&'V' starts visibly selecting whole lines.
-XThe character or line where the cursor is located becomes one
-Xendpoint of the selection.
-XYou can then use the standard cursor movement commands to move the cursor
-Xto the other endpoint, and then press one of the operator commands
-X(c/d/y/</>/!/=/\\).
-XThe operator will then immediately be applied to the selected text.
-X.IP "Pop-up Menu Operator" 1i
-XThe '\\' key is a new operator,
-Xsimilar in operation to the c/d/y/</>/! operators
-XIt conjures up a menu, from which you can select any of the other
-Xoperators plus a few other common commands.
-X.IP "Preset Filter Operator" 1i
-XThe '=' key is another new operator.
-XIt is similar to the '!' operator, except that while
-X\&'!' asks you to type in a filter command each time,
-X\&'=' assumes it should always run the command stored in the \fIequalprg\fR option.
-X.IP "Move to a Given Percentage" 1i
-XThe '%' movement key can now accept an optional count.
-XWithout a count, the '%' key still moves to a matching parenthesis
-Xlike it always did.
-XWith a count somewhere between 1 and 100, though, it moves the cursor to
-Xapproximately a given percentage of the way through the file.
-XFor example, typing "50%" will move the cursor to the middle of the file.
-X.IP "Regular Expressions"
-XIn regular expressions, several new forms of closure operators are supported:
-X\\{\fIn\fR}, \\{\fIn\fR,\fIm\fR}, \\+, and \\?.
-X.NH 2
-XOmissions
-X.PP
-XThe replace mode is a hack.
-XIt doesn't save the text that it overwrites.
-X.PP
-XLong lines are displayed differently -- where the real vi would
-Xwrap a long line onto several rows of the screen, \*E simply
-Xdisplays part of the line, and allows you to scroll the screen
-Xsideways to see the rest of it.
-X.PP
-XThe ":preserve" and ":recover" commands are missing.
-XSo is the -r flag.
-XI've never had a good reason to use ":preserve",
-Xand since ":recover" is used so rarely
-XI decided to implement it as a separate program.
-XThere's no need to load the recovery code into memory every
-Xtime you edit a file, I figured.
-X.PP
-XLISP support is missing.
-XHowever, the = key is still an operator that reformats lines of text.
-XBy default, it reformats lines by sending them through the \fIfmt\fP filter,
-Xbut you could write your own LISP beautifier and configure elvis to use it.
-XKey mappings could take care of most other differences.
-XAuto-indent is the only thing that is irrecoverably lost.
-X.PP
-XAutoindent mode acts a little different from the real vi, anyway.
-XIt doesn't handle ^^D or 0^D correctly.
-XOn the other hand, it \fIdoes\fP allow ^D and ^T to be used anywhere in the
-Xline, to adjust the indentation for the whole line.
-/
-echo x - environ.ms
-sed '/^X/s///' > environ.ms << '/'
-X.Go 11 "ENVIRONMENT VARIABLES"
-X.PP
-X\*E examines several environment variables when it starts up.
-XThe values of these variables are used internally for a variety
-Xof purposes.
-XYou don't need to define all of these;
-Xon most systems, \*E only requires TERM to be defined.
-XOn AmigaDOS, MS-DOS or TOS systems, even that is optional.
-X.SH
-XTERM, TERMCAP
-X.PP
-XTERM tells \*E the name of the termcap entry to use.
-XTERMCAP may contain either the entire termcap entry,
-Xor the full pathname of the termcap file to search through.
-X.PP
-XIf your version of \*E is using tinytcap instead of the full termcap library,
-Xthen the value of TERMCAP \fIcannot\fR contain any backslash escapes (\\E, \\r, etc.)
-Xor carat escapes (^[, ^M, etc.), because tinytcap doesn't understand them.
-XInstead, you should embed the actual control character into the string.
-X.SH
-XTMP, TEMP
-X.PP
-XThese only work for AmigaDOS, MS-DOS and Atari TOS.
-XEither of these variables may be used to set the "directory" option,
-Xwhich controls where temporary files are stored.
-XIf you define them both, then TMP is used, and TEMP is ignored.
-X.SH
-XLINES, COLUMNS
-X.PP
-XThe termcap entry for your terminal should specify the size of your screen.
-XIf you're using a windowing interface, then there is an ioctl() call which
-Xwill provide the size of the window; the ioctl() values will override the
-Xvalues in the termcap entry.
-XThe LINES and COLUMNS environment variables (if defined)
-Xwill override either of these sources.
-XThey, in turn, can be overridden by a ":set" command.
-X.PP
-XNormally, the LINES and COLUMNS variables shouldn't need to be defined.
-X.SH
-XEXINIT
-X.PP
-XThis variable's value may contain one or more colon-mode commands,
-Xwhich will be executed after all of the ".exrc" files
-Xbut before interactive editing begins.
-X.PP
-XTo put more than one command in EXINIT, you can separate the commands
-Xwith either a newline or a '|' character.
-X.SH
-XSHELL, COMSPEC
-X.PP
-XYou can use COMSPEC in MS-DOS, or SHELL in any other system,
-Xto specify which shell should be used for executing commands and
-Xexpanding wildcards.
-X.SH
-XHOME
-X.PP
-XThis variable should give the full pathname of your home directory.
-X\*E needs to know the name of your home directory so it can locate
-Xthe ".exrc" file there.
-X.SH
-XTAGPATH
-X.PP
-XThis variable is used by the "ref" program.
-XIt contains a list of directories that might contain a relevent "tags" file.
-XUnder AmigaDOS, MS-DOS or Atari TOS, the names of the directories should be separated by
-Xsemicolons (";").
-XUnder other operating systems, the names should be separated by colons (":").
-X.PP
-XIf you don't define TAGPATH, then "ref" will use a default list which includes
-Xthe current directory and a few other likely places.
-XSee the definition of DEFTAGPATH at the start of ref.c for an accurate list.
-/
-echo x - ex.ms
-sed '/^X/s///' > ex.ms << '/'
-X.Go 3 "COLON MODE COMMANDS"
-X.ID
-X.ps
-X.in 0.8i
-X.ta 2i 3.i
-X.\" NOTE: The following macro is used to output a single line of the
-X.\" command chart.  Its usage is:
-X.\"
-X.\"		.Cm <linespecs> <name> <arguments>...
-X.\"
-X.de Cm
-X.if "\\$1"0" \t\\$2\t\\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-X.if "\\$1"1" \s-2[line]\s+2\t\\$2\t\\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-X.if "\\$1"2" \s-2[line][,line]\s+2\t\\$2\t\\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
-X..
-X.if t .ds Q ``
-X.if t .ds U ''
-X.if n .ds Q "
-X.if n .ds U "
-X\s+2LINES	COMMAND	ARGUMENTS\s-2
-X.Cm 0 ab[br] [short] [expanded form]
-X.Cm 1 a[ppend][!]
-X.Cm 0 ar[gs] [files]
-X.Cm 0 cc [files]
-X.Cm 0 cd[!] [directory]
-X.Cm 2 c[hange]
-X.Cm 0 chd[ir][!] [directory]
-X.Cm 2 co[py] line
-X.Cm 0 col[or] [when] [[\*Qlight\*U] color] [\*Qon\*U color]
-X.Cm 2 d[elete] [\*Ux]
-X.Cm 0 dig[raph][!] [XX [Y]]
-X.Cm 0 e[dit][!] [file]
-X.Cm 0 er[rlist][!] [errlist]
-X.Cm 0 f[ile] [file]
-X.Cm 2 g[lobal] /regexp/ command
-X.Cm 1 i[nsert]
-X.Cm 2 j[oin][!]
-X.Cm 2 l[ist]
-X.Cm 0 mak[e] [target]
-X.Cm 0 map[!] key mapped_to
-X.Cm 1 ma[rk]  \*Ux
-X.Cm 0 mk[exrc]
-X.Cm 2 m[ove] line
-X.Cm 0 n[ext][!] [files]
-X.Cm 0 N[ext][!]
-X.Cm 2 nu[mber]
-X.Cm 2 p[rint]
-X.Cm 1 pu[t] [\*Ux]
-X.Cm 0 q[uit][!]
-X.Cm 1 r[ead] file
-X.Cm 0 rew[ind][!]
-X.Cm 0 se[t] [options]
-X.Cm 0 so[urce] file
-X.Cm 2 s[ubstitute] /regexp/replacement/[p][g][c]
-X.Cm 0 ta[g][!] tagname
-X.Cm 0 una[bbr] [short]
-X.Cm 0 u[ndo]
-X.Cm 0 unm[ap][!] key
-X.Cm 0 ve[rsion]
-X.Cm 2 v[global] /regexp/ command
-X.Cm 0 vi[sual] [filename]
-X.Cm 0 wq 
-X.Cm 2 w[rite][!] [[>>]file]
-X.Cm 0 x[it][!]
-X.Cm 2 y[ank] [\*Ux]
-X.Cm 2 ! command
-X.Cm 2 < 
-X.Cm 2 = 
-X.Cm 2 > 
-X.Cm 2 & 
-X.Cm 0 @ "" \*Ux
-X.DE
-X.TA
-X.PP
-XTo use colon mode commands, you must switch from visual command
-Xmode to colon command mode.
-XThe visual mode commands to do this are ":" for a single colon command,
-Xor "Q" for many colon mode commands.
-X.NH 2
-XLine Specifiers
-X.PP
-XLine specifiers are always optional.
-XThe first line specifier of most commands usually defaults to the current line.
-XThe second line specifier usually defaults to be the same
-Xas the first line specifier.
-XExceptions are :write, :global, and :vglobal, which act on all lines of the
-Xfile by default, and :!, which acts on no lines by default.
-X.PP
-XLine specifiers consist of an absolute part and a relative part.
-XThe absolute part of a line specifier may be either an explicit line number,
-Xa mark, a dot to denote the current line, a dollar sign to denote the last
-Xline of the file, or a forward or backward search.
-X.PP
-XAn explicit line number is simply a decimal number, expressed as a
-Xstring of digits.
-X.PP
-XA mark is typed in as an apostrophe followed by a letter.
-XMarks must be set before they can be used.
-XYou can set a mark in visual command mode by typing "m" and a letter,
-Xor you can set it in colon command mode via the "mark" command.
-X.PP
-XA forward search is typed in as a regular expression surrounded by
-Xslash characters; searching begins at the default line.
-XA backward search is typed in as a regular expression surrounded by
-Xquestion marks; searching begins at the line before the default line.
-X.PP
-XIf you omit the absolute part, then the default line is used.
-X.PP
-XThe relative part of a line specifier is typed as a "+" or "-" character
-Xfollowed by a decimal number.
-XThe number is added to or subtracted from the absolute part
-Xof the line specifier to produce the final line number.
-X.PP
-XAs a special case, the % character may be used to specify all lines of the file.
-XIt is roughly equivelent to saying 1,$.
-XThis can be a handy shortcut.
-X.PP
-XSome examples:
-X.LD
-X.ps
-X.ta 0.5i 1.8i
-X	:p	print the current line
-X	:37p	print line 37
-X	:'gp	print the line which contains mark g
-X	:/foo/p	print the next line that contains "foo"
-X	:$p	print the last line of the file
-X	:20,30p	print lines 20 through 30
-X	:1,$p	print all lines of the file
-X	:%p	print all lines of the file
-X	:/foo/-2,+4p	print 5 lines around the next "foo"
-X.TA
-X.DE
-X.NH 2
-XText Entry Commands
-X.if n .ul 0
-X.ID
-X.ps
-X[line] append
-X[line][,line] change ["x]
-X[line] insert
-X.DE
-X.PP
-XThe \fBa\fRppend command inserts text after the specified line.
-X.PP
-XThe \fBi\fRnsert command inserts text before the specified line.
-X.PP
-XThe \fBc\fRhange command copies the range of lines into a cut buffer,
-Xdeletes them, and inserts new text where the old text used to be.
-X.PP
-XFor all of these commands, you indicate the end of the text you're
-Xinserting by hitting ^D or by entering a line which contains only a
-Xperiod.
-X.NH 2
-XCut & Paste Commands
-X.if n .ul 0
-X.ID
-X.ps
-X[line][,line] delete ["x]
-X[line][,line] yank ["x]
-X[line] put ["x]
-X[line][,line] copy line
-X[line][,line] to line
-X[line][,line] move line
-X.DE
-X.PP
-XThe \fBd\fRelete command copies the specified range of lines into a
-Xcut buffer, and then deletes them.
-X.PP
-XThe \fBy\fRank command copies the specified range of lines into a cut
-Xbuffer, but does *not* delete them.
-X.PP
-XThe \fBpu\fRt command inserts text from a cut buffer after the
-Xspecified line.
-X.PP
-XThe \fBco\fRpy and \fBt\fRo commands yank the specified range of lines and
-Xthen immediately paste them after some other line.
-X.PP
-XThe \fBm\fRove command deletes the specified range of lines and then
-Ximmediately pastes them after some other line.
-XIf the destination line comes after the deleted text,
-Xthen it will be adjusted automatically to account for the deleted lines.
-X.NH 2
-XDisplay Text Commands
-X.if n .ul 0
-X.ID
-X.ps
-X[line][,line] print
-X[line][,line] list
-X[line][,line] number
-X.DE
-X.PP
-XThe \fBp\fRrint command displays the specified range of lines.
-X.PP
-XThe \fBnu\fRmber command displays the lines, with line numbers.
-X.PP
-XThe \fBl\fRist command also displays them, but it is careful to make
-Xcontrol characters visible.
-X.NH 2
-XGlobal Operations Commands
-X.if n .ul 0
-X.ID
-X.ps
-X[line][,line] global /regexp/ command
-X[line][,line] vglobal /regexp/ command
-X.DE
-X.PP
-XThe \fBg\fRlobal command searches through the lines of the specified range
-X(or through the whole file if no range is specified)
-Xfor lines that contain a given regular expression.
-XIt then moves the cursor to each of these lines and
-Xruns some other command on them.
-X.PP
-XThe \fBv\fRglobal command is similar, but it searches for lines that \fIdon't\fR
-Xcontain the regular expression.
-X.NH 2
-XLine Editing Commands
-X.if n .ul 0
-X.ID
-X.ps
-X[line][,line] join[!]
-X[line][,line] ! program
-X[line][,line] <
-X[line][,line] >
-X[line][,line] substitute /regexp/replacement/[p][g][c]
-X[line][,line] &
-X.DE
-X.PP
-XThe \fBj\fRoin command catenates all lines in the specified range together
-Xto form one big line.
-XIf only a single line is specified, then the following line is catenated
-Xonto it.
-XThe normal ":join" inserts one or two spaces between the lines;
-Xthe ":join!" variation (with a '!') doesn't insert spaces.
-X.PP
-XThe \fB!\fR command runs an external filter program,
-Xand feeds the specified range of lines to it's stdin.
-XThe lines are then replaced by the output of the filter.
-XA typical example would be ":'a,'z!sort" to sort the lines 'a,'z.
-X.PP
-XThe \fB<\fR and \fB>\fR commands shift the specified range of lines left or right,
-Xnormally by the width of 1 tab character.
-XThe "shiftwidth" option determines the shifting amount.
-X.PP
-XThe \fBs\fRubstitute command finds the regular expression in each line,
-Xand replaces it with the replacement text.
-XThe "p" option causes the altered lines to be printed.
-XThe "g" option permits all instances of the regular expression
-Xto be found & replaced.
-X(Without "g", only the first occurrence in each line is replaced.)
-XThe "c" option asks for confirmation before each substitution.
-X.PP
-XThe \fB&\fR command repeats the previous substitution command.
-XActually, "&" is equivelent to "s//~/" with the same options as last time.
-XIt searches for the last regular expression that you specified for any purpose,
-Xand replaces it with the the same text
-Xthat was used in the previous substitution.
-X.NH 2
-XUndo Command
-X.if n .ul 0
-X.ID
-X.ps
-Xundo
-X.DE
-X.PP
-XThe \fBu\fRndo command restores the file to the state it was in before
-Xyour most recent command which changed text.
-X.NH 2
-XConfiguration & Status Commands
-X.if n .ul 0
-X.ID
-X.ps
-Xmap[!] [key mapped_to]
-Xunmap[!] key
-Xabbr [word expanded_form_of_word]
-Xunabbr word
-Xdigraph[!] [XX [Y]]
-Xset [options]
-Xmkexrc
-X[line] mark "x
-Xvisual
-Xversion
-X[line][,line] =
-Xfile [file]
-Xsource file
-X@ "x
-Xcolor [when] [["light"] color] ["on" color]
-X.DE
-X.PP
-XThe \fBma\fRp command allows you to configure \*E to recognize your function keys,
-Xand treat them as though they transmitted some other sequence of characters.
-XNormally this mapping is done only when in the visual command mode,
-Xbut with the [!] present it will map keys under input and replace modes as well.
-XWhen this command is given with no arguments,
-Xit prints a table showing all mappings currently in effect.
-XWhen called with two arguments, the first is the sequence that your
-Xfunction key really sends, and the second is the sequence that you want
-X\*E to treat it as having sent.
-XAs a special case, if the first argument is a number then \*E will map the
-Xcorresponding function key;
-Xfor example, ":map 7 dd" will cause the <F7> key to delete a line.
-X.PP
-XThe \fBunm\fRap command removes key definitions that were made via the map command.
-X.PP
-XThe \fBab\fRbr command is used to define/list a table of abbreviations.
-XThe table contains both the abbreviated form and the fully spelled-out form.
-XWhen you're in visual input mode, and you type in the abbreviated form,
-X\*E will replace the abbreviated form with the fully spelled-out form.
-XWhen this command is called without arguments, it lists the table;
-Xwith two or more arguments, the first argument is taken as the abbreviated
-Xform, and the rest of the command line is the fully-spelled out form.
-X.PP
-XThe \fBuna\fRbbr command deletes entries from the abbr table.
-X.PP
-XThe \fBdi\fRgraph command allows you to display the set of digraphs that \*E is
-Xusing, or add/remove a digraph.
-XTo list the set of digraphs, use the digraph command with no arguments.
-XTo add a digraph, you should give the digraph command two arguments.
-XThe first argument is the two ASCII characters that are to be combined;
-Xthe second is the non-ASCII character that they represent.
-XThe non-ASCII character's most significant bit is automatically set by the
-Xdigraph command, unless to append a ! to the command name.
-XRemoval of a digraph is similar to adding a digraph, except that you should
-Xleave off the second argument.
-X.PP
-XThe \fBse\fRt command allows you examine or set various options.
-XWith no arguments, it displays the values of options that have been changed.
-XWith the single argument "all" it displays the values of all options,
-Xregardless of whether they've been explicitly set or not.
-XOtherwise, the arguments are treated as options to be set.
-X.PP
-XThe \fBmk\fRexrc command saves the current configuration to a file
-Xcalled ".exrc" in the current directory.
-X.PP
-XThe mar\fBk\fR command defines a named mark to refer to a specific place
-Xin the file.
-XThis mark may be used later to specify lines for other commands.
-X.PP
-XThe \fBvi\fRsual command puts the editor into visual mode.
-XInstead of emulating ex, \*E will start emulating vi.
-X.PP
-XThe \fBve\fRrsion command tells you that what version of \*E this is.
-X.PP
-XThe \fB=\fR command tells you what line you specified, or,
-Xif you specified a range of lines, it will tell you both endpoints and
-Xthe number of lines included in the range.
-X.PP
-XThe \fBf\fRile command tells you the name of the file,
-Xwhether it has been modified,
-Xthe number of lines in the file,
-Xand the current line number.
-XYou can also use it to change the name of the current file.
-X.PP
-XThe \fBso\fRurce command reads a sequence of colon mode commands from a file,
-Xand interprets them.
-X.PP
-XThe \fB@\fR command executes the contents of a cut-buffer as EX commands.
-X.PP
-XThe \fBcol\fRor command only works under MS-DOS, or if you have an ANSI-compatible
-Xcolor terminal.
-XIt allows you to set the foreground and background colors
-Xfor different types of text:
-Xnormal, bold, italic, underlined, standout, pop-up menu, and visible selection.
-XBy default, it changes the "normal" colors;
-Xto change other colors, the first argument to the :color command should be
-Xthe first letter of the type of text you want.
-XThe syntax for the colors themselves is fairly intuitive.
-XFor example, ":color light cyan on blue" causes normal text to be displayed
-Xin light cyan on a blue background, and
-X":color b bright white" causes bold text to be displayed in bright white on
-Xa blue background.
-XThe background color always defaults to the current background color of
-Xnormal text.
-XYour first :color command \fImust\fP specify both the foreground and background
-Xfor normal text.
-X.NH 2
-XMultiple File Commands
-X.if n .ul 0
-X.ID
-X.ps
-Xargs [files]
-Xnext[!] [files]
-XNext[!]
-Xprevious[!]
-Xrewind[!]
-X.DE
-X.PP
-XWhen you invoke \*E from your shell's command line,
-Xany filenames that you give to \*E as arguments are stored in the args list.
-XThe \fBar\fRgs command will display this list, or define a new one.
-X.PP
-XThe \fBn\fRext command switches from the current file to the next one
-Xin the args list.
-XYou may specify a new args list here, too.
-X.PP
-XThe \fBN\fRext and \fBpre\fRvious commands
-X(they're really aliases for the same command)
-Xswitch from the current file to the preceding file in the args list.
-X.PP
-XThe \fBrew\fRind command switches from the current file to the first file
-Xin the args list.
-X.NH 2
-XSwitching Files
-X.if n .ul 0
-X.ID
-X.ps
-Xedit[!] [file]
-Xtag[!] tagname
-X.DE
-X.PP
-XThe \fBe\fRdit command allows to switch from the current file to some other file.
-XThis has nothing to do with the args list, by the way.
-X.PP
-XThe \fBta\fRg command looks up a given tagname in a file called "tags".
-XThis tells it which file the tag is in, and how to find it in that file.
-X\*E then switches to the tag's file and finds the tag.
-X.NH 2
-XWorking with a Compiler
-X.if n .ul 0
-X.ID
-X.ps
-Xcc [files]
-Xmake [target]
-Xerrlist[!] [errlist]
-X.DE
-X.PP
-XThe \fBcc\fR and \fBmak\fRe commands execute your compiler or "make" utility
-Xand redirect any error messages into a file called "errlist".
-XBy default, cc is run on the current file.
-X(You should write it before running cc.)
-XThe contents of the "errlist" file are then scanned for error messages.
-XIf an error message is found, then the cursor is moved to the line where
-Xthe error was detected,
-Xand the description of the error is displayed on the status line.
-X.PP
-XAfter you've fixed one error, the \fBer\fRrlist command will move
-Xthe cursor to the next error.
-XIn visual command mode,
-Xhitting `*' will do this, too.
-X.PP
-XYou can also create an "errlist" file from outside of \*E,
-Xand use "\*E -m" to start elvis and have the cursor moved to the
-Xfirst error.
-XNote that you don't need to supply a filename with "\*E -m" because
-Xthe error messages always say which source file an error is in.
-X.PP
-XNote:
-XWhen you use errlist repeatedly to fix several errors in a single file,
-Xit will attempt to adjust the reported line numbers to allow for lines
-Xthat you have inserted or deleted.
-XThese adjustments are made with the assumption that you will work though
-Xthe file from the beginning to the end.
-X.NH 2
-XExit Commands
-X.if n .ul 0
-X.ID
-X.ps
-Xquit[!]
-Xwq
-Xxit
-X.DE
-X.PP
-XThe \fBq\fRuit command exits from the editor without saving your file.
-X.PP
-XThe \fBwq\fR command writes your file out, then then exits.
-X.PP
-XThe \fBx\fRit command is similar to the \fBwq\fR command, except that
-X\fBx\fRit won't bother to write your file if you haven't modified it.
-X.NH 2
-XFile I/O Commands
-X.if n .ul 0
-X.ID
-X.ps
-X[line] read file
-X[line][,line] write[!] [[>>]file]
-X.DE
-X.PP
-XThe \fBr\fRead command gets text from another file and inserts it
-Xafter the specified line.
-XIt can also read the output of a program;
-Xsimply precede the program name by a '!' and use it in place of the file name.
-X.PP
-XThe \fBw\fRrite command writes the whole file, or just part of it,
-Xto some other file.
-XThe !, if present, will permit the lines to be written even if you've set
-Xthe readonly option.
-XIf you precede the filename by >> then the lines will be appended to the file.
-XYou can send the lines to the standard input of a program by replacing the
-Xfilename with a '!' followed by the command and its arguments.
-X.PP
-XNote: Be careful not to confuse ":w!filename" and ":w !command".
-XTo write to a program, you must have at least one blank before the '!'.
-X.NH 2
-XDirectory Commands
-X.if n .ul 0
-X.ID
-X.ps
-Xcd [directory]
-Xchdir [directory]
-Xshell
-X.DE
-X.PP
-XThe \fBcd\fR and \fBchd\fRir commands
-X(really two names for one command)
-Xswitch the current working directory.
-X.PP
-XThe \fBsh\fRell command starts an interactive shell.
-X.NH 2
-XDebugging Commands
-X.if n .ul 0
-X.ID
-X.ps
-X[line][,line] debug[!]
-Xvalidate[!]
-X.DE
-X.PP
-XThese commands are only available if you compile \*E with the -DDEBUG flag.
-X.PP
-XThe de\fBb\fRug command lists statistics for the blocks which contain
-Xthe specified range of lines.
-XIf the ! is present, then the contents of those blocks is displayed, too.
-X.PP
-XThe \fBva\fRlidate command checks certain variables for internal consistency.
-XNormally it doesn't output anything unless it detects a problem.
-XWith the !, though, it will always produce *some* output.
-/
-echo x - index.ms
-sed '/^X/s///' > index.ms << '/'
-X.XS 1
-XINTRODUCTION
-XWhat E\s-2LVIS\s+2 does,
-XCopyright,
-XHow to compile E\s-2LVIS\s+2,
-XOverview
-X.XA 2
-XVISUAL MODE COMMANDS
-XNormal interactive editing,
-XInput mode,
-XArrow keys,
-XDigraphs,
-XAbbreviations,
-XAuto-indentation
-X.XA 3
-XCOLON MODE COMMANDS
-XLine specifiers,
-XText entry,
-XCut & paste,
-XDisplay text,
-XGlobal operations,
-XLine editing,
-XUndo,
-XConfiguration & status,
-XMultiple files,
-XSwitching files,
-XWorking with a compiler,
-XExiting,
-XFile I/O,
-XDirectory & shell,
-XDebugging
-X.XA 4
-XREGULAR EXPRESSIONS
-XSyntax,
-XOptions,
-XSubstitutions,
-XExamples
-X.XA 5
-XOPTIONS
-XAutoindent,
-XAutoprint,
-Xetc.
-X.XA 6
-XCUT BUFFERS
-XPutting text into a cut buffer,
-XPasting from a cut buffer,
-XMacros,
-XThe effect of switching files
-X.XA 7
-XDIFFERENCES BETWEEN E\s-2LVIS\s+2 AND THE REAL VI/EX
-XExtensions,
-XOmissions
-X.XA 8
-XINTERNAL
-XFor programmers only,
-XThe temporary file,
-XImplementation of editing,
-XMarks and the cursor,
-XColon command interpretation,
-XScreen control,
-XPortability
-X.XA 9
-XCFLAGS
-X.XA 10
-XTERMCAP
-X.XA 11
-XENVIRONMENT VARIABLES
-X.XA 12
-XVERSIONS
-X.XA 13
-XQUESTIONS & ANSWERS
-X.XE
-X.PX
-X.sp 0.3i
-X.ce 1
-XUNIX-style "man" pages appear at the end of this manual.
-/
-echo x - internal.ms
-sed '/^X/s///' > internal.ms << '/'
-X.Go 8 "INTERNAL"
-X.PP
-XYou don't need to know the material in this section to use \*E.
-XYou only need it if you intend to modify \*E.
-X.PP
-XYou should also check out the CFLAGS, TERMCAP, ENVIRONMENT VARIABLES,
-XVERSIONS, and QUIESTIONS & ANSWERS sections of this manual.
-X.NH 2
-XThe temporary file
-X.PP
-XThe temporary file is divided into blocks of 1024 bytes each.
-XThe functions in "blk.c" maintain a cache of the five most recently used blocks,
-Xto minimize file I/O.
-X.PP
-XWhen \*E starts up, the file is copied into the temporary file
-Xby the function \fBtmpstart()\fR in "tmp.c".
-XSmall amounts of extra space are inserted into the temporary file to
-Xinsure that no text lines cross block boundaries.
-XThis speeds up processing and simplifies storage management.
-XThe extra space is filled with NUL characters.
-Xthe input file must not contain any NULs, to avoid confusion.
-XThis also limits lines to a length of 1023 characters or less.
-X.PP
-XThe data blocks aren't necessarily stored in sequence.
-XFor example, it is entirely possible that the data block containing
-Xthe first lines of text will be stored after the block containing the
-Xlast lines of text.
-X.PP
-XIn RAM, \*E maintains two lists: one that describes the "proper"
-Xorder of the disk blocks, and another that records the line number of
-Xthe last line in each block.
-XWhen \*E needs to fetch a given line of text, it uses these tables
-Xto locate the data block which contains that line.
-X.PP
-XBefore each change is made to the file, these lists are copied.
-XThe copies can be used to "undo" the change.
-XAlso, the first list
-X-- the one that lists the data blocks in their proper order --
-Xis written to the first data block of the temp file.
-XThis list can be used during file recovery.
-X.PP
-XWhen blocks are altered, they are rewritten to a \fIdifferent\fR block in the file,
-Xand the order list is updated accordingly.
-XThe original block is left intact, so that "undo" can be performed easily.
-X\*E will eventually reclaim the original block, when it is no longer needed.
-X.NH 2
-XImplementation of Editing
-X.PP
-XThere are three basic operations which affect text:
-X.ID
-X\(bu delete text	- delete(from, to)
-X\(bu add text	- add(at, text)
-X\(bu yank text	- cut(from, to)
-X.DE
-X.PP
-XTo yank text, all text between two text positions is copied into a cut buffer.
-XThe original text is not changed.
-XTo copy the text into a cut buffer,
-Xyou need only remember which physical blocks that contain the cut text,
-Xthe offset into the first block of the start of the cut,
-Xthe offset into the last block of the end of the cut,
-Xand what kind of cut it was.
-X(Cuts may be either character cuts or line cuts;
-Xthe kind of a cut affects the way it is later "put".)
-XYanking is implemented in the function \fBcut()\fR,
-Xand pasting is implemented in the function \fBpaste()\fR.
-XThese functions are defined in "cut.c".
-X.PP
-XTo delete text, you must modify the first and last blocks, and
-Xremove any reference to the intervening blocks in the header's list.
-XThe text to be deleted is specified by two marks.
-XThis is implemented in the function \fBdelete()\fR.
-X.PP
-XTo add text, you must specify
-Xthe text to insert (as a NUL-terminated string)
-Xand the place to insert it (as a mark).
-XThe block into which the text is to be inserted may need to be split into
-Xas many as four blocks, with new intervening blocks needed as well...
-Xor it could be as simple as modifying a single block.
-XThis is implemented in the function \fBadd()\fR.
-X.PP
-XThere is also a \fBchange()\fR function,
-Xwhich generally just calls delete() and add().
-XFor the special case where a single character is being replaced by another
-Xsingle character, though, change() will optimize things somewhat.
-XThe add(), delete(), and change() functions are all defined in "modify.c".
-X.PP
-XThe \fBinput()\fR function reads text from a user and inserts it into the file.
-XIt makes heavy use of the add(), delete(), and change() functions.
-XIt inserts characters one at a time, as they are typed.
-X.PP
-XWhen text is modified, an internal file-revision counter, called \fBchanges\fR,
-Xis incremented.
-XThis counter is used to detect when certain caches are out of date.
-X(The "changes" counter is also incremented when we switch to a different file,
-Xand also in one or two similar situations -- all related to invalidating caches.)
-X.NH 2
-XMarks and the Cursor
-X.PP
-XMarks are places within the text.
-XThey are represented internally as 32-bit values which are split
-Xinto two bitfields:
-Xa line number and a character index.
-XLine numbers start with 1, and character indexes start with 0.
-XLines can be up to 1023 characters long, so the character index is 10 bits
-Xwide and the line number fills the remaining 22 bits in the long int.
-X.PP
-XSince line numbers start with 1,
-Xit is impossible for a valid mark to have a value of 0L.
-X0L is therefore used to represent unset marks.
-X.PP
-XWhen you do the "delete text" change, any marks that were part of
-Xthe deleted text are unset, and any marks that were set to points
-Xafter it are adjusted.
-XMarks are adjusted similarly after new text is inserted.
-X.PP
-XThe cursor is represented as a mark.
-X.NH 2
-XColon Command Interpretation
-X.PP
-XColon commands are parsed, and the command name is looked up in an array
-Xof structures which also contain a pointer to the function that implements
-Xthe command, and a description of the arguments that the command can take.
-XIf the command is recognized and its arguments are legal,
-Xthen the function is called.
-X.PP
-XEach function performs its task; this may cause the cursor to be
-Xmoved to a different line, or whatever.
-X.NH 2
-XScreen Control
-X.PP
-XIn input mode or visual command mode,
-Xthe screen is redrawn by a function called \fBredraw()\fR.
-XThis function is called in the getkey() function before each keystroke is
-Xread in, if necessary.
-X.PP
-XRedraw() write to the screen via a package which looks like the "curses"
-Xlibrary, but isn't.
-XIt is actually much simpler.
-XMost curses operations are implemented as macros which copy characters
-Xinto a large I/O buffer, which is then written with a single large
-Xwrite() call as part of the refresh() operation.
-X.PP
-X(Note: Under MS-DOS, the pseudo-curses macros check to see whether you're
-Xusing the pcbios interface.  If you are, then the macros call functions
-Xin "pc.c" to implement screen updates.)
-X.PP
-XThe low-level functions which modify text (namely add(), delete(), and change())
-Xsupply redraw() with clues to help redraw() decide which parts of the
-Xscreen must be redrawn.
-XThe clues are given via a function called \fBredrawrange()\fR.
-X.PP
-XMost EX commands use the pseudo-curses package to perform their output,
-Xlike redraw().
-X.PP
-XThere is also a function called \fBmsg()\fR which uses the same syntax as printf().
-XIn EX mode, msg() writes message to the screen and automatically adds a
-Xnewline.
-XIn VI mode, msg() writes the message on the bottom line of the screen
-Xwith the "standout" character attribute turned on.
-X.NH 2
-XOptions
-X.PP
-XFor each option available through the ":set" command,
-X\*E contains a character array variable, named "o_\fIoption\fR".
-XFor example, the "lines" option uses a variable called "o_lines".
-X.PP
-XFor boolean options, the array has a dimension of 1.
-XThe first (and only) character of the array will be NUL if the
-Xvariable's value is FALSE, and some other value if it is TRUE.
-XTo check the value, just by dereference the array name,
-Xas in "if (*o_autoindent)".
-X.PP
-XFor number options, the array has a dimension of 3.
-XThe array is treated as three unsigned one-byte integers.
-XThe first byte is the current value of the option.
-XThe second and third bytes are the lower and upper bounds of that
-Xoption.
-X.PP
-XFor string options, the array usually has a dimension of about 60
-Xbut this may vary.
-XThe option's value is stored as a normal NUL-terminated string.
-X.PP
-XAll of the options are declared in "opts.c".
-XMost are initialized to their default values;
-Xthe \fBinitopts()\fR function is used to perform any environment-specific
-Xinitialization.
-X.NH 2
-XPortability
-X.PP
-XTo improve portability, \*E collects as many of the system-dependent
-Xdefinitions as possible into the "config.h" file.
-XThis file begins with some preprocessor instructions which attempt to
-Xdetermine which compiler and operating system you have.
-XAfter that, it conditionally defines some macros and constants for your system.
-X.PP
-XOne of the more significant macros is \fBttyread()\fR.
-XThis macro is used to read raw characters from the keyboard, possibly
-Xwith timeout.
-XFor UNIX systems, this basically reads bytes from stdin.
-XFor MSDOS, TOS, and OS9, ttyread() is a function defined in curses.c.
-XThere is also a \fBttywrite()\fR macro.
-X.PP
-XThe \fBtread()\fR and \fBtwrite()\fR macros are versions of read() and write() that are
-Xused for text files.
-XOn UNIX systems, these are equivelent to read() and write().
-XOn MS-DOS, these are also equivelent to read() and write(),
-Xsince DOS libraries are generally clever enough to convert newline characters
-Xautomatically.
-XFor Atari TOS, though, the MWC library is too stupid to do this,
-Xso we had to do the conversion explicitly.
-X.PP
-XOther macros may substitute index() for strchr(), or bcopy() for memcpy(),
-Xor map the "void" data type to "int", or whatever.
-X.PP
-XThe file "tinytcap.c" contains a set of functions that emulate the termcap
-Xlibrary for a small set of terminal types.
-XThe terminal-specific info is hard-coded into this file.
-XIt is only used for systems that don't support real termcap.
-XAnother alternative for screen control can be seen in
-Xthe "curses.h" and "pc.c" files.
-XHere, macros named VOIDBIOS and CHECKBIOS are used to indirectly call
-Xfunctions which perform low-level screen manipulation via BIOS calls.
-X.PP
-XThe stat() function must be able to come up with UNIX-style major/minor/inode
-Xnumbers that uniquely identify a file or directory.
-X.PP
-XPlease try to keep you changes localized,
-Xand wrap them in #if/#endif pairs,
-Xso that \*E can still be compiled on other systems.
-XAnd PLEASE let me know about it, so I can incorporate your changes into
-Xmy latest-and-greatest version of \*E.
-/
-echo x - intro.ms
-sed '/^X/s///' > intro.ms << '/'
-X.Go 1 "INTRODUCTION"
-X.PP
-X\*E is a clone of vi/ex, the standard UNIX editor.
-X\*E supports nearly all of the vi/ex commands,
-Xin both visual mode and colon mode.
-X.PP
-XLike vi/ex, \*E stores most of the text in a temporary file, instead of RAM.
-XThis allows it to edit files that are too large to fit
-Xin a single process' data space.
-XAlso, the edit buffer can survive a power failure or crash.
-X.PP
-X\*E runs under BSD UNIX, AT&T SysV UNIX, Minix, MS-DOS, Atari TOS,
-XCoherent, OS9/68000, VMS and AmigaDos.
-XThe next version is also expected to add MS-Windows, OS/2 and MacOS.
-XContact me before you start porting it to some other OS,
-Xbecause somebody else may have already done it for you.
-X.PP
-X\*E is freely redistributable, in either source form or executable form.
-XThere are no restrictions on how you may use it.
-X.NH 2
-XCompiling
-X.PP
-XSee the "Versions" section of this manual for instructions on how to compile
-X\*E.
-X.PP
-XIf you want to port \*E to another O.S. or compiler, then
-Xyou should start be reading the "Portability" part of the "Internal" section.
-X.NH 2
-XOverview of \*E
-X.PP
-XThe user interface of \*E/vi/ex is weird.
-XThere are two major command modes in \*E, and a few text input modes as well.
-XEach command mode has a command which allows you to switch to the other mode.
-X.PP
-XYou will probably use the \fIvisual command mode\fR
-Xmost of the time.
-XThis is the mode that \*E normally starts up in.
-X.PP
-XIn visual command mode, the entire screen is filled with lines of text
-Xfrom your file.
-XEach keystroke is interpretted as part of a visual command.
-XIf you start typing text, it will \fInot\fR be inserted,
-Xit will be treated as part of a command.
-XTo insert text, you must first give an "insert text" command.
-XThis will take some getting used to.
-X(An alternative exists.
-XLookup the "inputmode" option.)
-X.PP
-XThe \fIcolon mode\fR is quite different.
-X\*E displays a ":" character on the bottom line of the screen, as a prompt.
-XYou are then expected to type in a command line and hit the <Return> key.
-XThe set of commands recognized in the colon mode is different
-Xfrom visual mode's.
-/
-echo x - options.ms
-sed '/^X/s///' > options.ms << '/'
-X.Go 5 "OPTIONS"
-X.PP
-XOptions may be set or examined via the colon command "set".
-XThe values of options will affect the operation of later commands.
-X.PP
-XFor convenience, options have both a long descriptive name and a short name
-Xwhich is easy to type.
-XYou may use either name interchangably.
-XI like the short names, myself.
-X.PP
-XThere are three types of options: Boolean, string, and numeric.
-XBoolean options are made TRUE by giving the name of the option as an
-Xargument to the "set" command;
-Xthey are made FALSE by prefixing the name with "no".
-XFor example, "set autoindent" makes the autoindent option TRUE,
-Xand "set noautoindent" makes it FALSE.
-X\*E also allows boolean options to be toggled by prefixing the name with "neg".
-XSo, ":map g :set neglist^M" will cause the <g> key to alternately toggle the
-X"list" option on and off.
-X(The "neg" prefix is an extension; the real vi doesn't support it.)
-X.PP
-XTo change the value of a string or numeric option, pass the "set" command
-Xthe name of the option, followed by an "=" sign and the option's new value.
-XFor example, "set tabstop=8" will give the tabstop option a value of 8.
-XFor string options, you may enclose the new value in quotes.
-X.LD
-X.ta 1.9i 2.4i 3.8i
-X.ps +2
-X\fBNAMES	TYPE	DEFAULT	MEANING\fP
-X.ps
-Xautoindent, ai	Bool	noai	auto-indent during input
-Xautoprint, ap	Bool	ap	in EX, print the current line
-Xautotab, at	Bool	at	auto-indent allowed to use tabs?
-Xautowrite, aw	Bool	noaw	auto-write when switching files
-Xbeautify,  bf	Bool	nobf	strip control chars from file?
-Xcharattr, ca	Bool	noca	interpret \\fX sequences?
-Xcc, cc	Str	cc="cc -c"	name of the C compiler
-Xcolumns, co	Num	co=80	width of the screen
-Xdigraph, dig	Bool	nodig	recognize digraphs?
-Xdirectory, dir	Str	dir="/usr/tmp"	where tmp files are kept
-Xedcompatible, ed	Bool	noed	remember ":s//" options
-Xequalprg, ep	Bool	ep="fmt"	program to run for = operator
-Xerrorbells, eb	Bool	eb	ring bell on error
-Xexrc, exrc	Bool	noexrc	read "./.exrc" file?
-Xexrefresh, er	Bool	er	write lines indiviually in EX
-Xflash, vbell	Bool	flash	use visible alternative to bell
-Xflipcase, fc	Str	fc=""	non-ASCII chars flipped by ~
-Xhideformat, hf	Bool	hf	hide text formatter commands
-Xignorecase, ic	Bool	noic	upper/lowercase match in search
-Xinputmode, im	Bool	noim	start vi in insert mode?
-Xkeytime, kt	Num	kt=2	timeout for mapped key entry
-Xkeywordprg, kp	Str	kp="ref"	full pathname of shift-K prog
-Xlines, ln	Num	ln=25	number of lines on the screen
-Xlist, li	Bool	noli	display lines in "list" mode
-Xmagic, ma	Bool	ma	use regular expression in search
-Xmake, mk	Str	mk="make"	name of the "make" program
-Xmesg, ms	Bool	ms	allow messages from other users?
-Xmodelines, ml	Bool	noml	are modelines processed?
-Xmore, more	Bool	more	pause between messages?
-Xnovice, nov	Bool	nonovice	set options for ease of use
-Xparagraphs, para	Str	para="PPppIPLPQP"	names of "paragraph" nroff cmd
-Xprompt, pr	Bool	pr	show ':' prompt in \fIex\fR mode
-Xreadonly, ro	Bool	noro	prevent overwriting of orig file
-Xremap, rem	Bool	remap	allow key maps to call key maps
-Xreport, re	Num	re=5	report when 5 or more changes
-Xruler, ru	Bool	noru	display line/column numbers
-Xscroll, sc	Num	sc=12	scroll amount for ^U and ^D
-Xsections, sect	Str	sect="NHSHSSSEse"	names of "section" nroff cmd
-Xshell, sh	Str	sh="/bin/sh"	full pathname of the shell
-Xshowmatch, sm	Bool	nosm	show matching ()[]{}
-Xshowmode, smd	Bool	nosmd	say when we're in input mode
-Xshiftwidth, sw	Num	sw=8	shift amount for < and >
-Xsidescroll, ss	Num	ss=8	amount of sideways scrolling
-Xsync, sy	Bool	nosy	call sync() often
-Xtabstop, ts	Num	ts=8	width of tab characters
-Xtaglength, tl	Num	tl=0	significant chars in tag name
-Xterm, te	Str	te="$TERM"	name of the termcap entry
-Xterse, tr	Bool	notr	give shorter error messages
-Xtimeout, to	Bool	to	distinguish <esc> from <arrow>?
-Xwarn, wa	Bool	wa	warn for ! if file modified
-Xwindow, wi	Num	wi=24	lines to redraw after long move
-Xwrapmargin, wm	Num	wm=0	wrap long lines in input mode
-Xwrapscan, ws	Bool	ws	at EOF, searches wrap to line 1
-Xwriteany, wr	Bool	nowr	allow :w to clobber files
-X.DE
-X.TA
-X.ne 6
-X.IP "autoindent, ai"
-XDuring input mode, the autoindent option will cause each added line
-Xto begin with the same amount of leading whitespace as the line above it.
-XWithout autoindent, added lines are initially empty.
-X.IP "autoprint, ap"
-XThis option only affects EX mode.
-XIf the autoprint option on,
-Xand either the cursor has moved to a different line
-Xor the previous command modified the file,
-Xthen \*E will print the current line.
-X.IP "autotab, at"
-XThis option affects the behaviour of the autoindent mode.
-XIf autoindent is turned off, then autotab has no effect.
-X.IP
-XWhen autotab is turned on, elvis will use a mixture of spaces and tabs
-Xto create the proper amount of indentation.
-XThis is the default.
-X.IP
-XWhen autotab is turned off, elvis will only use spaces for auto-indent.
-X\*E will still insert a real tab character when you hit the <Tab> key, though;
-Xthe autotab option only affects \fIautomatic\fR indentation.
-X.IP "autowrite, aw"
-XWhen you're editing one file and decide to switch to another
-X\- via the :tag command, or :next command, perhaps \-
-Xif your current file has been modified,
-Xthen \*E will normally print an error message and refuse to switch.
-X.IP
-XHowever, if the autowrite option is on,
-Xthen \*E will write the modified version of the current file
-Xand successfully switch to the new file.
-X.IP "beautify, bf"
-XThis option causes all control characters to be deleted from the text file,
-Xat the time when you start editing it.
-XIf you're already editing a file when you turn on the beautify option,
-Xthen that file won't be affected.
-X.IP cc
-XThe :cc command runs the C compiler.
-XThis option should be set to the name of your compiler.
-X.IP "charattr, ca"
-XMany text formatting programs allow you to designate portions of
-Xyour text to be underlined, italicized, or boldface by embedding
-Xthe special strings \\fU, \\fI, and \\fB in your text.
-XThe special string \\fP marks the end of underlined or boldface text.
-X.IP
-X\*E normally treats those special strings just like any other text.
-X.IP
-XHowever, if the charattr option is on, then \*E will interpret
-Xthose special strings correctly,
-Xto display underlined or boldface text on the screen.
-X(This only works, of course, if your terminal can display
-Xunderlined and boldface, and if the TERMCAP entry says how to do it.)
-X.IP "columns, co"
-XThis option shows how wide your screen is.
-X.IP "digraph, dig"
-XThis option is used to enable/disable recognition of digraphs.
-XThe default value is nodigraph, which means that digraphs will not be
-Xrecognized.
-X.IP "directory, dir"
-X\*E stores text in temporary files.
-XThis option allows you to control which directory those temporary files will
-Xappear in.
-XThe default is /usr/tmp.
-X.IP
-XThis option can only be set in a .exrc file;
-Xafter that, \*E will have already started making temporary files
-Xin some other directory, so it would be too late.
-X.IP "edcompatible, ed"
-XThis option affects the behaviour of the ":s/regexp/text/options" command.
-XIt is normally off (:se noed) which causes all of the substitution options
-Xto be off unless explicitly given.
-X.IP
-XHowever, with edcompatible on (:se ed), the substitution command remembers
-Xwhich options you used last time.
-XThose same options will continue to be used until you change them.
-XIn edcompatible mode, when you explicitly give the name of a
-Xsubstitution option, you will toggle the state of that option.
-X.IP
-XThis all seems very strange to me, but its implementation was almost free
-Xwhen I added the ":&" command to repeat the previous substitution,
-Xso there it is.
-X.IP "equalprg, ep"
-XThis holds the name & arguments of the external filter program
-Xused the the visual = operator.
-XThe defualt value is "fmt",
-Xso the = operator will adjust line breaks in text.
-X.IP "errorbells, eb"
-X\*E normally rings a bell when you do something wrong.
-XThis option lets you disable the bell.
-X.IP exrc
-XThis option specifies whether a .exrc file in the current directory
-Xshould be executed.
-XBy default, this option is off (":set noexrc") which prevents elvis from
-Xexecuting .exrc in the current directory.
-XIf the .exrc file in your home directory turns this option on (":set exrc")
-Xthen the \*E will attempt to execute the .exrc file in the current directory.
-X.IP
-XThis option exist mainly for security reasons.
-XA mean-spirited person could do something like
-X.br
-X	echo >/tmp/.exrc '!rm -rf $HOME'
-X.br
-Xand then anybody who attempted to edit or view a file in the /tmp directory
-Xwould lose most of their files.
-XWith the exrc option turned off, this couldn't happen to you.
-X.IP "exrefresh, er"
-XThe EX mode of \*E writes many lines to the screen.
-XYou can make \*E either write each line to the screen separately,
-Xor save up many lines and write them all at once.
-X.IP
-XThe exrefresh option is normally on, so each line is written to the
-Xscreen separately.
-X.IP
-XYou may wish to turn the exrefresh option off (:se noer) if the
-X"write" system call is costly on your machine, or if you're using a
-Xwindowing environment.
-X(Windowing environments scroll text a lot faster when you write
-Xmany lines at once.)
-X.IP
-XThis option has no effect in visual command mode or input mode.
-X.IP "flash, vbell"
-XIf your termcap entry describes a visible alternative to ringing
-Xyour terminal's bell, then this option will say whether the visible
-Xversion gets used or not.
-XNormally it will be.
-X.IP
-XIf your termcap does NOT include a visible bell capability,
-Xthen the flash option will be off, and you can't turn it on.
-X.IP "flipcase, fc"
-XThe flipcase option allows you to control how the non-ASCII characters are
-Xaltered by the "~" command.
-X.IP
-XThe string is divided into pairs of characters.
-XWhen "~" is applied to a non-ASCII character,
-X\*E looks up the character in the flipcase string to see which pair it's in,
-Xand replaces it by the other character of the pair.
-X.IP "hideformat, hf"
-XMany text formatters require you to embed format commands in your text,
-Xon lines that start with a "." character.
-X\*E normally displays these lines like any other text,
-Xbut if the hideformat option is on,
-Xthen format lines are displayed as blank lines.
-X.IP "ignorecase, ic"
-XNormally, when \*E searches for text, it treats uppercase letters
-Xas being different for lowercase letters.
-X.IP
-XWhen the ignorecase option is on, uppercase and lowercase are treated as equal.
-X.IP "inputmode, im"
-XThis option allows you to have \*E start up in insert mode.
-XYou can still exit insert mode at any time by hitting the ESC key, as usual.
-XUsually, this option would be set in your ".exrc" file.
-X.IP "keytime, kt"
-XThe arrow keys of most terminals send a multi-character sequence.
-XIt takes a measurable amount of time for these sequences to be transmitted.
-XThe keytime option allows you to control the maximum amount of time
-Xto allow for an arrow key (or other mapped key) to be received in full.
-X.IP
-XOn most systems, the setting is the number of tenths of a second to allow
-Xbetween characters.
-XOn some other systems, the setting is in whole seconds.
-X.IP
-XTry to avoid setting keytime=1.
-XMost systems just count clock beats, so if you tried to read a character
-Xshortly before a clock beat, you could allow almost no time at all for
-Xreading the characters.
-XFor higher keytime settings, the difference is less critical.
-X.IP
-XIf your system's response time is poor, you might want to increase the keytime.
-XIn particular, I've found that when keystrokes must be sent through a network
-X(via X windows, rlogin, or telnet, for example) the keytime should be set to
-Xat least 1 second.
-X.IP
-XAs a special case,
-Xyou can set keytime to 0 to disable this time limit stuff altogether.
-XThe big problem here is:
-XIf your arrow keys' sequences start with an ESC,
-Xthen every time you hit your ESC key \*E will wait... and wait...
-Xto see if maybe that ESC was part of an arrow key's sequence.
-X.IP
-XNOTE: this option is a generalization of the timeout option of the real vi.
-X.IP "keywordprg, kp"
-X\*E has a special keyword lookup feature.
-XYou move the cursor onto a word, and hit shift-K,
-Xand \*E uses another program to look up the word
-Xand display information about it.
-X.IP
-XThis option says which program gets run.
-X.IP
-XThe default value of this option is "ref",
-Xwhich is a program that looks up the definition of a function in C.
-XIt looks up the function name in a file called "refs" which is created by ctags.
-X.IP
-XYou can subtitute other programs, such as an English dictionary program
-Xor the online manual.
-X\*E runs the program, using the keyword as its only argument.
-XThe program should write information to stdout.
-XThe program's exit status should be 0, unless you want \*E to print
-X"<<< failed >>>".
-X.IP "lines, ln"
-XThis option says how many lines you screen has.
-X.IP "list, li"
-XIn nolist mode (the default), \*E displays text in a "normal" manner
-X-- with tabs expanded to an appropriate number of spaces, etc.
-X.IP
-XHowever, sometimes it is useful to have tab characters displayed differently.
-XIn list mode, tabs are displayed as "^I",
-Xand a "$" is displayed at the end of each line.
-X.IP "magic, ma"
-XThe search mechanism in \*E can accept "regular expressions"
-X-- strings in which certain characters have special meaning.
-X.IP
-XThe magic option is normally on, which causes these characters to be treated
-Xspecially.
-X.IP
-XIf you turn the magic option off (:se noma),
-Xthen all characters except ^ and $ are treated literally.
-X^ and $ retain their special meanings regardless of the setting of magic.
-X.IP "make, mk"
-XThe :make command runs your "make" program.
-XThis option defines the name of your "make" program.
-X.IP mesg
-XWith the real vi, running under real UNIX,
-X":set nomesg" would prevent other users from sending you messages.
-X\*E ignores it, though.
-X.IP "modelines, ml"
-X\*E supports modelines.
-XModelines are lines near the beginning or end of your text file which
-Xcontain "ex:yowza:",
-Xwhere "yowza" is any EX command.
-XA typical "yowza" would be something like "set ts=5 ca kp=spell wm=15".
-XOther text may also appear on a modeline,
-Xso you can place the "ex:yowza:" in a comment:
-X.br
-X.ID
-X/* ex:set sw=4 ai: */
-X.DE
-X.IP
-XNormally these lines are ignored, for security reasons,
-Xbut if you have "set modelines" in your .exrc file
-Xthen "yowza" is executed.
-X.IP "novice, nov"
-XThe command ":set novice" is equivelent to ":set nomagic report=1 showmode".
-X.IP "paragraphs, pa"
-XThe { and } commands move the cursor forward or backward in increments
-Xof one paragraph.
-XParagraphs may be separated by blank lines, or by a "dot" command of
-Xa text formatter.
-XDifferent text formatters use different "dot" commands.
-XThis option allows you to configure \*E to work with your text formatter.
-X.IP
-XIt is assumed that your formatter uses commands that start with a
-X"." character at the front of a line,
-Xand then have a one- or two-character command name.
-X.IP
-XThe value of the paragraphs option is a string in which each pair
-Xof characters is one possible form of your text formatter's paragraph
-Xcommand.
-X.IP "more"
-XWhen \*E must display a sequence of messages at the bottom line of the screen
-Xin visual mode, it normally pauses after all but the last one, so you have
-Xtime to read them all.
-X.IP
-XIf you turn off the "more" option, then \*E will not pause.
-XThis means you can only read the last message, but it is usually the most
-Ximportant one anyway.
-X.IP "prompt, pr"
-XIf you ":set noprompt", then \*E will no longer emit a ':' when it
-Xexpects you to type in an \fIex\fR command.
-XThis is slightly useful if you're using an astonishingly slow UNIX machine,
-Xbut the rest of us can just ignore this one.
-X.IP "readonly, ro"
-XNormally, \*E will let you write back any file to which you have
-Xwrite permission.
-XIf you don't have write permission, then you can only write the changed
-Xversion of the file to a \fIdifferent\fP file.
-X.IP
-XIf you set the readonly option,
-Xthen \*E will pretend you don't have write permission to \fIany\fP file you edit.
-XIt is useful when you really only mean to use \*E to look at a file,
-Xnot to change it.
-XThis way you can't change it accidentally.
-X.IP
-XThis option is normally off, unless you use the "view" alias of \*E.
-X"View" is like "vi" except that the readonly option is on.
-X.IP "remap"
-XThe ":map" command allows you to convert one key sequence into another.
-XThe remap option allows you to specify what should happen if portions of
-Xthat other sequence are also in the map table.
-XIf remap is on, then those portions will also be mapped, just as if they
-Xhad been typed on the keyboard.
-XIf remap is off, then the matching portions will not be mapped.
-X.IP
-XFor example, if you enter the commands ":map A B" and ":map B C",
-Xthen when remap is on, A will be converted to C.
-XBut when remap is off, A will be converted only to B.
-X.IP "report, re"
-XCommands in \*E may affect many lines.
-XFor commands that affect a lot of lines, \*E will output a message saying
-Xwhat was done and how many lines were affected.
-XThis option allows you to define what "a lot of lines" means.
-XThe default is 5, so any command which affects 5 or more lines will cause
-Xa message to be shown.
-X.IP "ruler, ru"
-XThis option is normally off.
-XIf you turn it on, then \*E will constantly display the line/column numbers
-Xof the cursor, at the bottom of the screen.
-X.IP "scroll, sc"
-XThe ^U and ^D keys normally scroll backward or forward by half a screenful,
-Xbut this is adjustable.
-XThe value of this option says how many lines those keys should scroll by.
-XIf you invoke ^U or ^D with a count argument (for example, "33^D") then
-Xthis option's value is set to the count.
-X.IP "sections, se"
-XThe [[ and ]] commands move the cursor backward or forward in increments of
-X1 section.
-XSections may be delimited by a { character in column 1
-X(which is useful for C source code)
-Xor by means of a text formatter's "dot" commands.
-X.IP
-XThis option allows you to configure \*E to work with your text formatter's
-X"section" command, in exectly the same way that the paragraphs option makes
-Xit work with the formatter's "paragraphs" command.
-X.IP "shell, sh"
-XWhen \*E forks a shell
-X(perhaps for the :! or :shell commands)
-Xthis is the program that is uses as a shell.
-XThis is "/bin/sh" by default,
-Xunless you have set the SHELL (or COMSPEC, for MS-DOS) environment variable,
-Xit which case the default value is copied from the environment.
-X.IP "shiftwidth, sw"
-XThe < and > commands shift text left or right by some uniform number of columns.
-XThe shiftwidth option defines that "uniform number".
-XThe default is 8.
-X.IP "showmatch, sm"
-XWith showmatch set,
-Xin input mode every time you hit one of )}],
-X\*E will momentarily move the cursor to the matching ({[.
-X.IP "showmode, smd"
-XIn visual mode, it is easy to forget whether you're in the visual command mode
-Xor input/replace mode.
-XNormally, the showmode option is off, and you haven't a clue as to which mode
-Xyou're in.
-XIf you turn the showmode option on, though, a little message will appear in the
-Xlower right-hand corner of your screen, telling you which mode you're in.
-X.IP "sidescroll, ss"
-XFor long lines, \*E scrolls sideways.
-X(This is different from the real vi,
-Xwhich wraps a single long line onto several rows of the screen.)
-X.IP
-XTo minimize the number of scrolls needed,
-X\*E moves the screen sideways by several characters at a time.
-XThe value of this option says how many characters' widths to scroll at a time.
-X.IP
-XGenerally, the faster your screen can be redrawn,
-Xthe lower the value you will want in this option.
-X.IP "sync, sy"
-XIf the system crashes during an edit session, then most of your work
-Xcan be recovered from the temporary file that \*E uses to store
-Xchanges.
-XHowever, sometimes the OS will not copy changes to the
-Xhard disk immediately, so recovery might not be possible.
-XThe [no]sync option lets you control this.
-X.IP
-XIn nosync mode (which is the default, for UNIX), \*E lets the operating system
-Xcontrol when data is written to the disk.
-XThis is generally faster.
-X.IP
-XIn sync mode (which is the default for MS-DOS, AmigaDos, and Atari TOS),
-X\*E forces all changes out
-Xto disk every time you make a change.
-XThis is generally safer, but slower.
-XIt can also be a rather rude thing to do on a multi-user system.
-X.IP "tabstop, ts"
-XTab characters are normally 8 characters wide,
-Xbut you can change their widths by means of this option.
-X.IP "taglength, tl"
-XThis option allows you to specify how many characters of a tag's name
-Xmust match when performing tag lookup.
-XAs a special case, ":set taglength=0" means that all characters of a tag's
-Xname must match.
-X.IP
-XNote: some configurations of \*E don't support this option.
-X.IP "term, te"
-XThis read-only option shows the name of the termcap entry that
-X\*E is using for your terminal.
-X.IP "terse, tr"
-XThe real vi uses this option to select longer vs. shorter error messages.
-X\*E has only one set of error messages, though, so this option has no effect.
-X.IP "timeout, to"
-XThe command ":set notimeout" is equivelent to ":set keytime=0",
-Xand ":set timeout" is equivelent to ":set keytime=1".
-XThis affects the behaviour of the <Esc> key.
-XSee the discussion of the "keytime" option for more information.
-X.IP "warn, wa"
-XIf you have modified a file but not yet written it back to disk, then
-X\*E will normally print a warning before executing a ":!cmd" command.
-XHowever, in nowarn mode, this warning is not given.
-X.IP
-X\*E also normally prints a message after a successful search that
-Xwrapped at EOF.
-XThe [no]warn option can also disable this warning.
-X.IP "window, wi"
-XThis option controls how many lines are redrawn after a long move.
-X.IP
-XOn fast terminals, this is usually set to the number of rows that the
-Xterminal can display, minus one.
-XThis causes the entire screen to be filled with text around the cursor.
-X.IP
-XOn slow terminals, you may wish to reduce this value to about 7 or so.
-XThat way, if you're doing something like repeatedly hitting 'n' to search
-Xfor each occurrence of some string and trying to find a particular occurrence,
-Xthen you don't need to wait as long for \*E to redraw the screen after each
-Xsearch.
-X.IP "wrapmargin, wm"
-XNormally (with wrapmargin=0) \*E will let you type in extremely long
-Xlines, if you wish.
-X.IP
-XHowever, with warpmargin set to something other that 0 (wrapmargin=10
-Xis nice), \*E will automatically cause long lines to be "wrapped"
-Xon a word break for lines come too close to the right-hand margin.
-XFor example: On an 80-column screen, ":set wm=10" will cause lines to
-Xwrap when their length exceeds 70 columns.
-X.IP "wrapscan, ws"
-XNormally, when you search for something, \*E will find it no matter
-Xwhere it is in the file.
-X\*E starts at the cursor position, and searches forward.
-XIf \*E hits EOF without finding what you're looking for,
-Xthen it wraps around to continue searching from line 1.
-XIf you turn off the wrapscan option (:se nows),
-Xthen when \*E hits EOF during a search, it will stop and say so.
-X.IP "writeany, wr"
-XWith "writeany" turned off, elvis will prevent you from accidentally
-Xoverwriting a file.
-XFor example, if "foo" exists then ":w foo" will fail.
-XIf you turn on the "writeany" option, then ":w foo" will work.
-X.IP
-XRegardless of the setting of "writeany", though, ":w! foo" will work.
-XThe '!' forces the ":w" command to write the file unless the operating system
-Xwon't allow it.
-/
-echo x - question.ms
-sed '/^X/s///' > question.ms << '/'
-X.nr Qn 0 1
-X.de QQ
-X.sp
-X.IP \fB\\n+(Qn) 0.3i
-X..
-X.de AA
-X.IP \fR 0.75i
-X..
-X.Go 13 "QUESTIONS & ANSWERS"
-X.QQ
-XHow can I make elvis run faster under DOS?
-X.AA
-XThere are several things you can do.
-XThe first thing to do is get a good screen driver such as NANSI.SYS.
-XThis can speed up screen redrawing by as much as a factor of eight!
-XThe DOS-specific part of section 12 tells you how to do this.
-X.AA
-XYou might also consider reducing the size of the blocks that elvis uses.
-XYou'll need to recompile \*E to do this.
-XThe default BLKSIZE is 1024 byte for the DOS version of \*E, which means
-Xthat for each keystroke that you insert, elvis must shift an average of
-Xabout 500 bytes.
-XThat's a lot to ask from a little old 5MHz 8088.
-XA BLKSIZE of 512 bytes might be more appropriate.
-X.AA
-XIf you're \fIreally\fR desperate for more speed, you might want to make
-X\*E store its temporary files on a RAM disk.
-XHowever, this limits the size of the file you can edit, and it eliminates any
-Xchance you may have had to recover your work after a power failure
-Xor system crash, but it might be worth it; you decide.
-XTo do this, add ":set dir=R:\\" (or whatever your RAM disk's name is)
-Xto the \fIelvis.rc\fP file.
-X.AA
-XNext, consider turning off the "sync" option.
-XWhen the sync option is turned on, \*E will close the temporary file
-Xand reopen it after every change, in order to force DOS to update
-Xthe file's directory entry.
-XIf you put ":set nosync" into the \fIelvis.rc\fP file, then elvis will
-Xonly close the file when you start editing a different text file, or
-Xwhen you're exiting \*E.
-XConsequently, there is no chance that you'll be able to recover your
-Xchanges after a power failure... so if you're going to this, then you
-Xmight as well store the temp files on the RAM disk, too.
-X.QQ
-XWhere's the <Esc> key on a DEC keyboard?
-X.AA
-XI don't know.  Maybe the <F11> key?
-XYou could always use ":map!" to make some other key act like the <Esc> key.
-XIf all else fails, use <Control><[>.
-X.QQ
-XIs there a way to show which keys do what?
-X.AA
-XYes.  The command ":map" will show what each key does in command mode,
-Xand ":map!" (with an exclamation mark) shows what each key does in
-Xinput mode.
-X.AA
-XThe table is divided into three columns: the key's label, the characters
-Xthat it sends, and the characters that \*E pretends you typed.
-X.QQ
-XHow can I make \*E display long lines like the real vi?
-X.AA
-XYou can't yet.
-XThe next version of \*E shouldsupport this, though.
-X.QQ
-XI can't recover my text [under MS-DOS or Atari TOS].
-XAccording to the directory listing, the temporary file is 0 bytes long.
-XWhat went wrong?
-X.AA
-XMS-DOS and TOS only update a file's directory entry when the file is closed.
-XIf the system crashes while the file is still open, then the file's length
-Xis stored as 0 bytes.
-XThe ":set sync" option is supposed to prevent this;
-Xyou probably turned it off in the interest of speed, right?
-X.AA
-XUnder MS-DOS [I don't know about TOS], you should delete the empty
-Xtemporary file, and then run CHKDSK/F.
-XThis \fImight\fP find the data that belonged in the empty file,
-Xand place it in a new file with a name like "000001.CHK" -- something like that.
-XYou can then try to extract the text from that temporary file by giving the
-Xcommand "elvprsv -R 000001.chk >goodnews.txt".
-XIf you're lucky, then your text might be in GOODNEWS.TXT.
-X.QQ
-XWhat is the most current version of \*E?
-X.AA
-XEach version of \*E that is released to the public has a version number
-Xof the form "number point number".
-XAs I write this, the most current version of elvis is 1.5.
-X.AA
-XThe intermediate steps between one release and the next are labeled with
-Xthe \fInext\fP version number, with a letter appended.
-XFor example, after 1.4 was released, I started working on 1.5a.
-XI am currently working on 2.0a.
-XWhen \*E reaches a stable state, I'll call it 2.0 and release it.
-X.AA
-XSometimes a beta-test version of elvis will be available via anonymous FTP
-Xfrom m2xenix.psg.com, in the directory "pub/elvis/beta".
-X.QQ
-XI only got executables, but now I want the source code.
-XWhere can I get it?
-X.AA
-XIf you have access to the Internet, then you should be able to fetch it
-Xfrom one of the public archives such as \fBplains.nodak.edu\fP.
-XIt is accessible via anonymous FTP, or via an email server named
-X"archive-server@plains.nodak.edu".
-XElvis is located in the directory "/pub/Minix/all.contrib".
-X.AA
-XI will also offer it to the C Users' Group.
-XThey sell C source code for us$8 per diskette
-X(or slightly more outside  North  America).
-XTheir phone number is (913) 841-1631,
-Xand their address is:
-X.ID
-XThe C Users' Group
-XPO Box 3127
-XLawrence KS 66046-0127
-X.DE
-X.QQ
-XIs this shareware, or public domain, or what?
-X.AA
-XIt is not public domain; it is copyrighted by me, Steve Kirkendall.
-XHowever, this particular version is freely redistributable, in either
-Xsource form or executable form.
-X(I would prefer that you give copies away for free, complete with the
-Xfull source code... but I'm not going to force you.)
-X.AA
-XIt is not shareware; you aren't expected to send me anything.
-XYou can use it without guilt.
-X.AA
-XIt is not "copylefted."
-XI hold a copyright, but currently I have not added any of the usual restrictions
-Xthat you would find on copylefted software.
-XIf people start doing really obnoxious things to \*E, then I will start
-Xadding restrictions to subsequent versions, but earlier versions won't
-Xbe affected.
-X(So far, everybody has been pretty good about this so no restrictions
-Xhave been necessary.)
-X.QQ
-XCan I reuse parts of your source code?
-X.AA
-XYes.  Please be careful, though, to make sure that the code really is mine.
-XSome of the code was contributed by other people, and I don't have the
-Xauthority to give you permission to use it.
-XThe author's name can be found near the top of each source file.
-XIf it says "Steve Kirkendall" then you may use it;
-Xotherwise, you'd better contact the author first.
-X.AA
-XPlease don't remove my name from the source code.
-XIf you modify the source, please make a note of that fact in a comment
-Xnear the top of the source code.
-XAnd, finally, please mention my name in your documentation.
-X.QQ
-XCan \*E work with non-ASCII files?
-X.AA
-X\*E can't edit binary files because it can't handle the NUL character,
-Xand because of line-length limitations.
-XHowever, it is 8-bit clean so you should be able to edit any European
-Xextended ASCII file without any surprises.
-X.AA
-X\*E has also been modified to work with 16-bit character sets.
-XYongguang Zhang (ygz@cs.purdue.edu) has created a Chinese version of \*E
-Xthat uses 16-bit characters and runs under cxterm (Chinese X-term)
-Xon X-windows systems.
-XJunichiro Itoh (itojun@foretune.co.jp) has modified \*E to edit Japanese
-Xtext under MS-DOS.
-/
-echo x - regexp.ms
-sed '/^X/s///' > regexp.ms << '/'
-X.Go 4 "REGULAR EXPRESSIONS"
-X
-X.PP
-X\*E uses regular expressions for searching and substututions.
-XA regular expression is a text string in which some characters have
-Xspecial meanings.
-XThis is much more powerful than simple text matching.
-X.SH
-XSyntax
-X.PP
-X\*E' regexp package treats the following one- or two-character
-Xstrings (called meta-characters) in special ways:
-X.IP "\\\\\\\\(\fIsubexpression\fP\\\\\\\\)" 0.8i
-XThe \\( and \\) metacharacters are used to delimit subexpressions.
-XWhen the regular expression matches a particular chunk of text,
-X\*E will remember which portion of that chunk matched the \fIsubexpression\fP.
-XThe :s/regexp/newtext/ command makes use of this feature.
-X.IP "^" 0.8i
-XThe ^ metacharacter matches the beginning of a line.
-XIf, for example, you wanted to find "foo" at the beginning of a line,
-Xyou would use a regular expression such as /^foo/.
-XNote that ^ is only a metacharacter if it occurs
-Xat the beginning of a regular expression;
-Xanyplace else, it is treated as a normal character.
-X.IP "$" 0.8i
-XThe $ metacharacter matches the end of a line.
-XIt is only a metacharacter when it occurs at the end of a regular expression;
-Xelsewhere, it is treated as a normal character.
-XFor example, the regular expression /$$/ will search for a dollar sign at
-Xthe end of a line.
-X.IP "\\\\\\\\<" 0.8i
-XThe \\< metacharacter matches a zero-length string at the beginning of
-Xa word.
-XA word is considered to be a string of 1 or more letters and digits.
-XA word can begin at the beginning of a line
-Xor after 1 or more non-alphanumeric characters.
-X.IP "\\\\\\\\>" 0.8i
-XThe \\> metacharacter matches a zero-length string at the end of a word.
-XA word can end at the end of the line
-Xor before 1 or more non-alphanumeric characters.
-XFor example, /\\<end\\>/ would find any instance of the word "end",
-Xbut would ignore any instances of e-n-d inside another word
-Xsuch as "calendar".
-X.IP "\&." 0.8i
-XThe . metacharacter matches any single character.
-X.IP "[\fIcharacter-list\fP]" 0.8i
-XThis matches any single character from the \fIcharacter-list\fP.
-XInside the \fIcharacter-list\fP, you can denote a span of characters
-Xby writing only the first and last characters, with a hyphen between
-Xthem.
-XIf the \fIcharacter-list\fP is preceded by a ^ character, then the
-Xlist is inverted -- it will match character that \fIisn't\fP mentioned
-Xin the list.
-XFor example, /[a-zA-Z]/ matches any letter, and /[^ ]/ matches anything
-Xother than a blank.
-X.IP "\\\\\\\\{\fIn\fP\\\\\\\\}" 0.8i
-XThis is a closure operator,
-Xwhich means that it can only be placed after something that matches a
-Xsingle character.
-XIt controls the number of times that the single-character expression
-Xshould be repeated.
-X.IP "" 0.8i
-XThe \\{\fIn\fP\\} operator, in particular, means that the preceding
-Xexpression should be repeated exactly \fIn\fP times.
-XFor example, /^-\\{80\\}$/ matches a line of eighty hyphens, and
-X/\\<[a-zA-Z]\\{4\\}\\>/ matches any four-letter word.
-X.IP "\\\\\\\\{\fIn\fP,\fIm\fP\\\\\\\\}" 0.8i
-XThis is a closure operator which means that the preceding single-character
-Xexpression should be repeated between \fIn\fP and \fIm\fP times, inclusive.
-XIf the \fIm\fP is omitted (but the comma is present) then \fIm\fP is
-Xtaken to be inifinity.
-XFor example, /"[^"]\\{3,5\\}"/ matches any pair of quotes which contains
-Xthree, four, or five non-quote characters.
-X.IP "*" 0.8i
-XThe * metacharacter is a closure operator which means that the preceding
-Xsingle-character expression can be repeated zero or more times.
-XIt is equivelent to \\{0,\\}.
-XFor example, /.*/ matches a whole line.
-X.IP "\\\\\\\\+" 0.8i
-XThe \\+ metacharacter is a closure operator which means that the preceding
-Xsingle-character expression can be repeated one or more times.
-XIt is equivelent to \\{1,\\}.
-XFor example, /.\\+/ matches a whole line, but only if the line contains
-Xat least one character.
-XIt doesn't match empty lines.
-X.IP "\\\\\\\\?" 0.8i
-XThe \\? metacharacter is a closure operator which indicates that the
-Xpreceding single-character expression is optional -- that is, that it
-Xcan occur 0 or 1 times.
-XIt is equivelent to \\{0,1\\}.
-XFor example, /no[ -]\\?one/ matches "no one", "no-one", or "noone".
-X.PP
-XAnything else is treated as a normal character which must exactly match
-Xa character from the scanned text.
-XThe special strings may all be preceded by a backslash to
-Xforce them to be treated normally.
-X.SH
-XSubstitutions
-X.PP
-XThe :s command has at least two arguments: a regular expression,
-Xand a substitution string.
-XThe text that matched the regular expression is replaced by text
-Xwhich is derived from the substitution string.
-X.br
-X.ne 15 \" so we don't mess up the table
-X.PP
-XMost characters in the substitution string are copied into the
-Xtext literally but a few have special meaning:
-X.LD
-X.ta 0.75i 1.3i
-X	&	Insert a copy of the original text
-X	~	Insert a copy of the previous replacement text
-X	\\1	Insert a copy of that portion of the original text which
-X		matched the first set of \\( \\) parentheses
-X	\\2-\\9	Do the same for the second (etc.) pair of \\( \\)
-X	\\U	Convert all chars of any later & or \\# to uppercase
-X	\\L	Convert all chars of any later & or \\# to lowercase
-X	\\E	End the effect of \\U or \\L
-X	\\u	Convert the first char of the next & or \\# to uppercase
-X	\\l	Convert the first char of the next & or \\# to lowercase
-X.TA
-X.DE
-X.PP
-XThese may be preceded by a backslash to force them to be treated normally.
-XIf "nomagic" mode is in effect,
-Xthen & and ~ will be treated normally,
-Xand you must write them as \\& and \\~ for them to have special meaning.
-X.SH
-XOptions
-X.PP
-X\*E has two options which affect the way regular expressions are used.
-XThese options may be examined or set via the :set command.
-X.PP
-XThe first option is called "[no]magic".
-XThis is a boolean option, and it is "magic" (TRUE) by default.
-XWhile in magic mode, all of the meta-characters behave as described above.
-XIn nomagic mode, only ^ and $ retain their special meaning.
-X.PP
-XThe second option is called "[no]ignorecase".
-XThis is a boolean option, and it is "noignorecase" (FALSE) by default.
-XWhile in ignorecase mode, the searching mechanism will not distinguish between
-Xan uppercase letter and its lowercase form.
-XIn noignorecase mode, uppercase and lowercase are treated as being different.
-X.PP
-XAlso, the "[no]wrapscan" option affects searches.
-X.SH
-XExamples
-X.PP
-XThis example changes every occurence of "utilize" to "use":
-X.sp
-X.ti +1i
-X:%s/utilize/use/g
-X.PP
-XThis example deletes all whitespace that occurs at the end of a line anywhere
-Xin the file.
-X(The brackets contain a single space and a single tab.):
-X.sp
-X.ti +1i
-X:%s/[   ]\\+$//
-X.PP
-XThis example converts the current line to uppercase:
-X.sp
-X.ti +1i
-X:s/.*/\\U&/
-X.PP
-XThis example underlines each letter in the current line,
-Xby changing it into an "underscore backspace letter" sequence.
-X(The ^H is entered as "control-V backspace".):
-X.sp
-X.ti +1i
-X:s/[a-zA-Z]/_^H&/g
-X.PP
-XThis example locates the last colon in a line,
-Xand swaps the text before the colon with the text after the colon.
-XThe first \\( \\) pair is used to delimit the stuff before the colon,
-Xand the second pair delimit the stuff after.
-XIn the substitution text, \\1 and \\2 are given in reverse order
-Xto perform the swap:
-X.sp
-X.ti +1i
-X:s/\\(.*\\):\\(.*\\)/\\2:\\1/
-/
-echo x - termcap.ms
-sed '/^X/s///' > termcap.ms << '/'
-X.Go 10 "TERMCAP"
-X.PP
-X\*E uses fairly standard termcap fields for most things.
-XI invented the cursor shape names
-Xbut other than that there should be few surprises.
-X.SH
-XRequired numeric fields
-X.if n .ul 0
-X.ID
-X:co#:	number of columns on the screen (chars per line)
-X:li#:	number of lines on the screen
-X.DE
-X.SH
-XRequired string fields
-X.ID
-X.if n .ul 0
-X:ce=:	clear to end-of-line
-X:cl=:	home the cursor & clear the screen
-X:cm=:	move the cursor to a given row/column
-X:up=:	move the cursor up one line
-X.DE
-X.SH
-XBoolean fields
-X.if n .ul 0
-X.ID
-X:am:	auto margins - wrap when char is written in last column?
-X:xn:	brain-damaged auto margins - newline ignored after wrap
-X:pt:	physical tabs?
-X.DE
-X.SH
-XOptional string fields
-X.if n .ul 0
-X.ID
-X:al=:	insert a blank row on the screen
-X:dl=:	delete a row from the screen
-X:cd=:	clear to end of display
-X:ei=:	end insert mode
-X:ic=:	insert a blank character
-X:im=:	start insert mode
-X:dc=:	delete a character
-X:sr=:	scroll reverse (insert row at top of screen)
-X:vb=:	visible bell
-X:ti=:	terminal initialization string, to start full-screen mode
-X:te=:	terminal termination, to end full-screen mode
-X:ks=:	enables the cursor keypad
-X:ke=:	disables the cursor keypad
-X.DE
-X.SH
-XOptional strings received from the keyboard
-X.if n .ul 0
-X.ID
-X:kd=:	sequence sent by the <down arrow> key
-X:kl=:	sequence sent by the <left arrow> key
-X:kr=:	sequence sent by the <right arrow> key
-X:ku=:	sequence sent by the <up arrow> key
-X:kP=:	sequence sent by the <PgUp> key
-X:kN=:	sequence sent by the <PgDn> key
-X:kh=:	sequence sent by the <Home> key
-X:kH=:	sequence sent by the <End> key
-X:kI=:	sequence sent by the <Insert> key
-X.DE
-X.PP
-XOriginally, termcap didn't have any names for the <PgUp>, <PgDn>, <Home>,
-Xand <End> keys.
-XAlthough the capability names shown in the table above are the most common,
-Xthey are \fInot\fR universal.
-XSCO Xenix uses :PU=:PD=:HM=:EN=: for those keys.
-XAlso, if the four arrow keys happen to be part of a 3x3 keypad,
-Xthen the five non-arrow keys may be named :K1=: through :K5=:,
-Xso an IBM PC keyboard may be described using those names instead.
-X\*E can find any of these names.
-X.SH
-XOptional strings sent by function keys
-X.if n .ul 0
-X.ID
-X:k1=:...:k9=:k0=:	codes sent by <F1> through <F10> keys
-X:s1=:...:s9=:s0=:	codes sent by <Shift F1> ... <Shift F10>
-X:c1=:...:c9=:c0=:	codes sent by <Ctrl F1> ... <Ctrl F10>
-X:a1=:...:a9=:a0=:	codes sent by <Alt F1> ... <Alt F10>
-X.DE
-X.PP
-XNote that :k0=: is used to describe the <F10> key.
-XSome termcap documents recommend :ka=: or even :k;=: for describing
-Xthe <F10> key, but \*E doesn't support that.
-X.PP
-XAlso, the :s1=:..., :c1=:..., and :a1=:... codes are very non-standard.
-XThe terminfo library doesn't support them.
-X.SH
-XOptional fields that describe character attributes
-X.if n .ul 0
-X.ID
-X:so=:se=:	start/end standout mode (We don't care about :sg#:)
-X:us=:ue=:	start/end underlined mode
-X:md=:me=:	start/end boldface mode
-X:as=:ae=:	start/end alternate character set (italics)
-X:ug#:		visible gap left by :us=:ue=:md=:me=:as=:ae=:
-X.DE
-X.SH
-XOptional fields that affect the cursor's shape
-X.PP
-XThe :cQ=: string is used by \*E immediately before exiting to undo
-Xthe effects of the other cursor shape strings.
-XIf :cQ=: is not given, then all other cursor shape strings are ignored.
-X.ID
-X:cQ=:	normal cursor
-X:cX=:	cursor used for reading EX command
-X:cV=:	cursor used for reading VI commands
-X:cI=:	cursor used during VI input mode
-X:cR=:	cursor used during VI replace mode
-X.DE
-X.PP
-XIf the capabilities above aren't given, then \*E will try to use the
-Xfollowing values instead.
-X.ID
-X:ve=:	normal cursor, used as :cQ=:cX=:cI=:cR=:
-X:vs=:	gaudy cursor, used as :cV=:
-X.DE
-X.SH
-XAn example
-X.PP
-XHere's the termcap entry I use on my Minix-ST system.
-XSome of the fields in it have nothing to do with \*E.
-XSome can only work on my system;
-XI have modified my kernel's screen driver.
-X.sp
-X.LD
-X.ne 14
-Xmx|minix|minixst|ansi:\\
-X	:is=\\E[0~:co#80:li#25:bs:pt:\\
-X	:cm=\\E[%i%d;%dH:up=\\E[A:do=^J:nd=\\E[C:sr=\\EM:\\
-X	:cd=\\E[J:ce=\\E[K:cl=\\E[H\\E[J:\\
-X	:al=\\E[L:dl=\\E[M:ic=\\E[@:dc=\\E[P:im=:ei=:\\
-X	:so=\\E[7m:se=\\E[m:us=\\E[4m:ue=\\E[m:\\
-X	:md=\\E[1m:me=\\E[m:as=\\E[1;3m:ae=\\E[m:\\
-X	:ku=\\E[A:kd=\\E[B:kr=\\E[C:kl=\\E[D:\\
-X	:k1=\\E[1~:k2=\\E[2~:k3=\\E[3~:k4=\\E[4~:k5=\\E[5~:\\
-X	:k6=\\E[6~:k7=\\E[17~:k8=\\E[18~:k9=\\E[19~:k0=\\E[20~:\\
-X	:kU=\\E[36~:kQ=\\E[32~:kH=\\E[28~:\\
-X	:GV=3:GH=D:G1=?:G2=Z:G3=@:G4=Y:GC=E:GL=4:GR=C:GU=A:GD=B:\\
-X	:cQ=\\E[k:cX=\\E[2;0k:cV=\\E[16;0k:cI=\\E[k:cR=\\E[16;20k:
-X.DE
-/
-echo x - title.ms
-sed '/^X/s///' > title.ms << '/'
-X.de tE
-X.ps 80
-X.ce 1
-X\*E
-X..
-X.de nE
-X.ce 7
-X#######                                
-X#        #       #    #     #     #### 
-X#        #       #    #     #    #     
-X#####    #       #    #     #     #### 
-X#        #       #    #     #         #
-X#        #        #  #      #    #    #
-X#######  ######    ##       #     #### 
-X..
-X.sp |2i
-X.if t .tE
-X.if n .nE
-X.ps 10
-X.sp 1
-X.ce 2
-X- a clone of vi/ex -
-Xversion \*V
-X.sp |7.5i
-X.IP Author: 0.9i
-XSteve Kirkendall
-X.br
-X14407 SW Teal Blvd., Apt C
-X.br
-XBeaverton, OR 97005
-X.IP E-Mail: 0.9i
-Xkirkenda@cs.pdx.edu
-X.IP Phone: 0.9i
-X(503) 643-6980
-/
-echo x - ver.ms
-sed '/^X/s///' > ver.ms << '/'
-X.ds V 1.5j-betatest
-X.if t .ds E E\s-2LVIS\s+2
-X.if n .ds E Elvis
-X.\"
-X.\" usage: .Go <section#> <title>
-X.de Go
-X.ds LH "\\$1-\\\\n%
-X.ds RH "\\$1-\\\\n%
-X.ds CH "\\$2
-X.NH S \\$1
-X\\$2
-X.\"if !\\n%=1 .bp 1
-X.if n .ul 0
-X..
-/
-echo x - versions.ms
-sed '/^X/s///' > versions.ms << '/'
-X.Go 12 "VERSIONS"
-X.PP
-X\*E currently works under BSD UNIX, AT&T System-V UNIX, SCO XENIX,
-XMinix, Coherent, MS-DOS, Atari TOS, OS9/68k, VAX/VMS, and AmigaDos.
-XThis section of the manual provides special information that applies to each
-Xparticular version of \*E.
-X.PP
-XFor all versions except MS-DOS,
-Xthe file "Makefile.mix" should be copied to "Makefile",
-Xand then edited to select the correct set of options for your system.
-XThere is more information about this embedded in the file itself.
-X.NH 2
-XBSD UNIX
-X.PP
-XTemporary files are stored in /tmp.
-X.PP
-XYou should modify /etc/rc so that
-Xthe temp files are preserved when the system is rebooted.
-XFind a line in /etc/rc which reads
-X.br
-X.ti +0.5i
-Xex4.3preserve /tmp
-X.PP
-Xor something like that, and append the following line after it:
-X.br
-X.ti +0.5i
-Xelvprsv /tmp/elv*
-X.PP
-XIf you do not have permission to modify /etc/rc, don't fret.
-XThe above modification is only needed to allow you to recover your changes
-Xafter a system crash.
-XYou can still run \*E without that modification,
-Xand you can still recover your changes when \*E crashes
-Xor when your dialup modem looses the carrier signal, or something like that.
-XOnly a system crash or power failure could hurt you.
-X.PP
-XBoth \*E and the real Vi
-Xread initialization commands from a file called ".exrc",
-Xbut the commands in that file might work on one but not the other.
-XFor example, "set keywordprg=man" will work for \*E,
-Xbut Vi will complain because it doesn't have a "keywordprg" option.
-XIf the warning messages annoy you, then you can edit the config.h file
-Xto change the name of the initialization file ".exrc" to something else,
-Xsuch as ".elvisrc".
-X.PP
-XIf you use X windows, you may wish to add "-DCS_LATIN1" to CFLAGS.
-XThis will cause the digraph table and the flipcase option to have default
-Xvalues that are appropriate for the LATIN-1 character set.
-XThat's the standard character set for X.
-X.PP
-XThe default keyboard macro time-out value is larger for BSD than it is for
-Xsome other systems, because I've had trouble running \*E via rlogin or Xterm.
-XI guess it takes a while for those keystokes to squirt through the net.
-X.NH 2
-XSystem-V UNIX
-X.PP
-XMost SysV UNIX systems use terminfo instead of termcap,
-Xbut  the  terminfo  library  doesn't seem to have a standard name.
-XAs shipped, Elvis' Makefile.mix  is  configured  with "LIBS=-lterm".
-XYou may need to change it to "LIBS=-ltermcap" or "LIBS=-lterminfo"
-Xor even "LIBS=-lcurses".
-X.PP
-XThe /etc/rc file should be modified as described for BSD systems, above.
-XThe only difference is that SysV systems tend to have directories for
-Xinitialization, instead of a single large /etc/rc file.
-XEditor recovery is usually done somewhere in the /etc/rc2.d directory.
-X.PP
-XThe potential trouble with ".exrc" described above for BSD UNIX applies
-Xto System-V UNIX as well.
-X.PP
-X\*E uses control-C as the interrupt key, not Delete.
-X.NH 2
-XSCO Xenix
-X.PP
-XFor Xenix-386, you can use the generic System-V settings.
-XYou may wish to add "-DCS_IBMPC" to CFLAGS, to have the digraph table and
-Xflipcase option start up in a mode that is appropriate for the console.
-X
-XThere is a separate group of settings for use with Xenix-286.
-XIt already has "-DCS_IBMPC" in CFLAGS.
-X.PP
-XBecause Xenix is so similar to System-V, everything I said earlier about
-XSystem-V applies to the Xenix version too, except that editor recovery
-Xprobably belongs in a directory called /etc/rc.d/8.
-X.NH 2
-XMinix
-X.PP
-XThere are separate settings in Makefile.mix for Minix-PC and Minix-68k.
-XThe differences between these two are that
-Xthe 68k version uses ".o" for the object file extension where
-Xthe PC version uses ".s", and
-Xthe PC version has some extra flags in CFLAGS to reduce the size of \*E.
-XThe PC version also uses tinytcap (instead of the full termcap) to make it smaller.
-X.PP
-XMinix-PC users should read the CFLAGS section of this manual very carefully.
-XYou have some choices to make...
-X.PP
-XThe temporary files are stored in /usr/tmp.
-XThe /usr/tmp directory must exist before you run \*E,
-Xand it must be readable/writable by everybody.
-XWe use /usr/tmp instead of /tmp because
-Xafter a system crash or power failure,
-Xyou can recover the altered version of a file from the temporary file
-Xin /usr/tmp.
-XIf it was stored in /tmp, though, then it would be lost because /tmp is
-Xnormally located on the RAM disk.
-X.PP
-X\*E uses control-C as the interrupt key, not Delete.
-X.NH 2
-XCoherent
-X.PP
-X\*E was ported to Coherent by Esa Ahola.
-X.PP
-X\*E is too large to run under Coherent unless you eliminate some
-Xfeatures via the CFLAGS setting.
-XThe recommended settings, in Makefile.mix, produce a working version
-Xof \*E which emulates Vi faithfully, but lacks most of the extensions.
-XYou should read the CFLAGS section of this manual carefully.
-X.PP
-XYou can probably reduce the size of \*E by using tinytcap.c instead of -lterm.
-XThis would allow you to keep most features of \*E,
-Xat the expense of terminal independence.
-X(Tinytcap.c has ANSI escape sequences hard-coded into it.)
-XTo use tinytcap, just add "tinytcap.o" to the "EXTRA=" line in the Makefile,
-Xand remove "-lterm" from the "LIBS=" line.
-X.PP
-XThe temporary files are stored in /tmp.
-XYou should modify your /etc/rc file as described for BSD earlier.
-X.NH 2
-XMS-DOS
-X.PP
-X\*E was ported to MS-DOS by Guntram Blohm and Martin Patzel.
-XWillett Kempton added support for the DEC Rainbow.
-X.PP
-XIdeally, \*E should be compiled with Microsoft C 5.10 and the standard
-XMicrosoft Make utility,
-Xvia the command "make elvis.mak".
-XThis will compile \*E and all related utilities.
-X.PP
-XWith Microsoft C 6.00, you may have trouble compiling regexp.c.
-XIf so, try compiling it without optimization.
-X.PP
-XThe "Makefile.mix" file contains a set of suggested settings for compiling
-Xelvis with Turbo-C or Borland C.
-X(If you have Turbo-C, but not the Make utility,
-Xthen you can \fIalmost\fR use the "\*E.prj" file to compile \*E,
-Xbut you must explicitly force Turbo-C to compile it with the "medium" memory model.
-XMost of the related programs [ctags, ref, virec, refont, and wildcard] are
-Xonly one file long, so you should have no trouble compiling them.)
-XThe "alias.c" file is meant to be compiled once into an executable named
-X"ex.exe".
-XYou should then copy "ex.exe" to "vi.exe" and "view.exe".
-X.PP
-X\*E stores its temporary files in C:\\tmp.
-XIf this is not satisfactory, then you should edit the CFLAGS line of
-Xyour Makefile to change TMPDIR to something else before compiling.
-XYou can also control the name of the temp directory via an environment
-Xvariable named TMP or TEMP.
-XThe directory must exist before you can run \*E.
-X.PP
-XThe TERM environment variable determines how elvis will write to the screen.
-XIt can be set to any one of the following values:
-X.LD
-X.ta 1.5i 2.5i
-X	pcbios	Use BIOS calls on an IBM-PC clone.
-X	rainbow	Use DEC Rainbow interface.
-X	ansi	Use ANSI.SYS driver.
-X	nansi	User faster NANSI.SYS driver.
-X.DE
-X.PP
-XIf the TERM variable isn't set, then elvis will automatically select either
-Xthe "rainbow" interface (when run on a Rainbow) or "pcbios" (on an IBM clone).
-X.PP
-XYou may prefer to use NANSI.SYS for speed;
-Xor you may NEED to use ANSI.SYS for a non-clone, such as a lap-top.
-XIf so, you should
-Xinstall one of these drivers by adding "driver = nansi.sys" (or whatever)
-Xto your CONFIG.SYS file,
-Xand then you should define TERM to be "nansi" (or whatever) by adding
-X"set TERM=nansi" to your AUTOEXEC.BAT file.
-XYou must then reboot for these changes to take effect.
-XAfter that, \*E will notice the "TERM" setting and use the driver.
-X.PP
-XSince ".exrc" is not a valid DOS filename,
-Xthe name of the initialization file has been changed to "elvis.rc".
-XElvis will look for an "elvis.rc" file first in your home directory,
-Xand then in the current directory.
-XNote that you must set an environment variable named "HOME" to the
-Xfull pathname of your home directory, for Elvis to check there;
-Xif "HOME" isn't set, then Elvis will only look in the current directory.
-XTo set "HOME", you would typically add the following line to your
-XAUTOEXEC.BAT file:
-X.br
-X.ti +0.5i
-Xset HOME c:\\
-X.PP
-XAn extra program, called "wildcard", is needed for MS-DOS.
-XIt expands wildcard characters in file names.
-XIf \*E flashes a "Bad command or filename" message when it starts,
-Xthen you've probably lost the WILDCARD.EXE program somehow.
-X.PP
-X\*E can run under Windows, but only in full-screen mode.
-XAlso, Windows uses an environment variable called TEMP which interferes with
-Xelvis' usage of TEMP;
-Xto work around this, you can simply set an environment variable named
-XTMP (with no 'E') to the name of elvis' temporary directory.
-XWhen TEMP and TMP are both set, \*E uses TMP and ignored TEMP.
-X.NH 2
-XAtari TOS
-X.PP
-X\*E was ported to Atari TOS by Guntram Blohm and Martin Patzel.
-XIt is very similar to the MS-DOS version.
-XIt has been tested with the Mark Williams C compiler and also GNU-C.
-X.PP
-XThe TERM environment variable is ignored;
-Xthe ST port always assumes that TERM=vt52.
-XThe SHELL (not COMSPEC!) variable should be set to
-Xthe name of a line-oriented shell.
-X.PP
-XA simple shell in included with \*E.
-XIts source is in "shell.c", and the name of the executable is "shell.ttp".
-XThe file "profile.sh" should contain a set of instructions to be executed
-Xwhen the shell first starts up.
-XAn example of this file is included, but you will almost certainly want to
-Xedit it right away to match your configuration.
-X(If you already have a command-line shell,
-Xthen you'll probably want to continue using it.
-XThe shell that comes with \*E is very limited.)
-X.PP
-XCurrently, character attributes cannot be displayed on the screen.
-X.PP
-X\*E runs under MiNT (a free multi-tasking extension to TOS)
-Xbut it can be a CPU hog because of the way that \*E reads from the
-Xkeyboard with timeout.
-XAlso, \*E doesn't use any of the special features of MiNT.
-XI have received a set of patches that optimize \*E for MiNT,
-Xbut they arrived too late to integrate into this release.
-X.NH 2
-XOS9/68k
-X.PP
-X\*E was ported to OS9/68k by Peter Reinig.
-X.PP
-XThe Makefile is currently configured to install \*E and the related
-Xprograms in /dd/usr/cmds
-XIf this this is unacceptable, then you should change the BIN setting
-Xto some other directory.
-XSimilarly, it expects the source code to reside in /dd/usr/src/elvis;
-Xthe ODIR setting is used to control this.
-X.PP
-XTemporary files are stored in the /dd/tmp directory.
-XYour /dd/startup file may need to be modified
-Xto prevent it from deleting \*E' temporary files;
-Xmake /dd/startup run the \fIelvprsv\fR program before it wipes out /dd/tmp.
-X.PP
-XThe program in alias.c is linked repeatedly to produce the
-X"vi", "view", and "input" aliases for \*E.
-XSadly, the "ex" alias is impossible to implement under OS9
-Xbecause the shell has a built-in command by that name.
-X.PP
-XFor some purposes,
-Xyou must give `make' the "-b" option.
-XSpecifically, you need this for "make -b clean" and "make -b install".
-X.NH 2
-XVAX/VMS
-X.PP
-XJohn Campbell ported \*E to VAX/VMS.
-X.PP
-XA heavily laden VAX can take half an hour to compile elvis.
-XThis is normal.
-XDon't panic.
-X.PP
-XWhile running, elvis will create temporary files in SYS$SCRATCH.
-XEnter SHOW LOGICAL SYS$SCRATCH to see what actual directory you are using.
-XMany sites have SYS$SCRATCH equivalenced to SYS$LOGIN.
-XThe elvis temporary files look like the following on VMS while elvis is running:
-X.br
-X.ti 0.75i
-XELV_1123A.1;1       ELV_1123A.2;1       SO070202.;1
-X.PP
-XAlso, filtering commands (like !!dir and !}fmt) should work on VMS.
-XThis assumes, however, that you can create temporary mailboxes and that
-Xyour mailbox quota (a sysgen parameter) is at least 256 bytes for a
-Xsingle write to the mailbox.
-XThis is the default sysgen parameter,
-Xso there should be few people who experience filter problems.
-X.PP
-XAdditionally, an attempt was made to support the standard terminals on VMS:
-X"vt52", "vt100", "vt200", "vt300", "vt101", "vt102".
-XNon-standard terminals could be supported by setting your terminal type to
-XUNKNOWN (by entering SET TERM/UNKNOWN)
-Xand defining the logical name ELVIS_TERM.
-XWhatever ELVIS_TERM translates to, however, will have to be included in
-Xtinytcap.c.
-XNote that the upper/lowercase distinctions are significant,
-Xand that DCL will upshift characters that are not quoted strings, so
-Xenter DEFINE ELVIS_TERM "hp2621a".
-XAs distributed, it would probably not be a good idea to have more than the
-Xstandard terminals in tinytcap.c (else it wouldn't be tiny, would it?).
-XChanges here, of course, would require a recompilation to take effect.
-X.PP
-XIf you have a version of the "termcap" library and database on your system,
-Xthen you may wish to replace tinytcap with the real termcap.
-X.NH 2
-XAmigaDOS
-X.PP
-XMike Rieser and Dale Rahn ported \*E to AmigaDOS.
-X.PP
-XThe port was done using Manx Aztec C version 5.2b.
-X\*E uses about as much space as it can and still be small code and data.
-X\*E should also compile under DICE, though there may be a little trouble with
-Xsigned versus unsigned chars.
-X.PP
-XThe port has been done so the same binary will run under both versions of AmigaDOS.
-XUnder AmigaDOS 2.04, \*E supports all the documented features.
-XIt also uses an external program ref to do tag lookup.
-XSo, the accompanying programs: ref and ctags are recommended.
-XUnder AmigaDOS 1.2/1.3 \*E works, buts lacks the more advanced features.
-X.PP
-XFor the port to AmigaDOS 2.04, we tried to use as many Native AmigaDOS
-Xcalls as we could.
-XThis should increase Elvis's chances at being compiled with other compilers.
-XDICE seems to have a different default char type.
-XYou may need to use the UCHAR() macro in tio.c.
-XTo test it, try the :map command; if it looks right, things are cool.
-X.PP
-XFor the port to AmigaDOS 1.3, we tried to make sure the program was at
-Xleast usable.
-XMany features are missing, most notably running commands in subshells.
-XAlso, what we could get working, we used Aztec functions to support them,
-Xso this part is little more compiler dependent.
-X.PP
-XAztec is compatible with the SAS libcall #pragma.
-XI personally prefer using the includes that come from Commodore over the ones
-Xsupplied with Aztec, but for people with a straight Aztec installation,
-XI went with the default names for the Aztec pragmas.
-X.PP
-XOne include you'll need is <sys/types.h>.
-XIts a common include when porting software just make yourself one.
-XIts a two line file that saves a lot of hassle especially in the elvis source.
-XSo, make a directory where your includes are located called `sys'
-Xand in a file below that type:
-X.br
-X.ti +0.8i
-X/* sys/types.h */
-X.br
-X.ti +0.8i
-X#include <exec/types.h>
-X.PP
-XWhen setting environment variables (either local or global) for
-Xvariables that specify a directory, make sure the variable ends in `:'
-Xor `/'.
-XThis saved from having to change much of the way elvis works.
-XThe default temporary directory (if TEMP and TMP aren't specified) is "T:".
-XThe default if HOME directory (if no HOME environment variable is set) is "S:".
-X.PP
-XTo avoid conlict with other uses, \*E uses elvis.rc instead of .exrc or
-Xwhere it looks for macros.
-X.NH 2
-XOther Systems
-X.PP
-XFor Sun workstations, use the BSD configuration.
-XEarlier versions of elvis didn't link correctly due to a quirk in Sun's
-Xversion of the "make" utility, but this version of elvis has a work-around
-Xfor that quirk so you should have no trouble at all.
-X.PP
-XFor Linux, use the SysV settings.
-XYou can probably just remove the "-lterm" from the "LIBS= -lterm" line,
-Xsince linux keeps the termcap functions in the standard C library.
-X.PP
-XFor other UNIXoid systems, I suggest you start with the Minix-68k settings
-Xand then grow from that.
-XMinix is a nice starting point because it is a clone of Version 7 UNIX,
-Xwhich was the last common ancestor of BSD UNIX and SysV UNIX.
-XAny Operating System which claims any UNIX compatibility what so ever
-Xwill therefore support V7/Minix code.
-XYou may need to fiddle with #include directives or something, though.
-XMinix-68k is a better starting point than Minix-PC because the PC compiler
-Xhas some severe quirks.
-/
-echo x - visual.ms
-sed '/^X/s///' > visual.ms << '/'
-X.Go 2 "VISUAL MODE COMMANDS"
-X.PP
-XMost visual mode commands are one keystroke long.
-XThe following table lists the operation performed by each keystroke,
-Xand also denotes any options or arguments that it accepts.
-XNotes at the end of the table describe the notation used in this table.
-X.PP
-XIn addition to the keys listed here, your keyboard's "arrow" keys
-Xwill be interpretted as the appropriate cursor movement commands.
-XThe same goes for <PgUp> and <PgDn>, if your keyboard has them.
-XThe <Insert> key will toggle between insert mode and replace mode.
-XThere is a colon mode command (":map", to be described later)
-Xwhich will allow you to define other keys, such as function keys.
-X.PP
-XA tip: visual command mode looks a lot like text input mode.
-XIf you forget which mode you're in, just hit the <Esc> key.
-XIf \*E beeps, then you're in visual command mode.
-XIf \*E does not beep, then you were in input mode,
-Xbut by hitting <Esc> you will have switched to visual command mode.
-XSo, one way or another, after <Esc> \*E will be ready for a command.
-X.LD
-X.ta 0.7i 1.3i
-X\s+2COMMAND	DESCRIPTION\s-2
-X	^A	Search for next occurence of word at cursor (MOVE)(EXT)
-X	^B	Move toward the top of the file by 1 screenful
-X	^C	--- (usually sends SIGINT, to interupt a command)
-Xcount	^D	Scroll down <count> lines (default 1/2 screen)
-Xcount	^E	Scroll up <count> lines
-X	^F	Move toward the bottom of the file by 1 screenful
-X	^G	Show file status, and the current line #
-Xcount	^H	Move left, like h (MOVE)
-X	^I	---
-Xcount	^J	Move down (MOVE)
-X	^K	---
-X	^L	Redraw the screen
-Xcount	^M	Move to the front of the next line (MOVE)
-Xcount	^N	Move down (MOVE)
-X	^O	---
-Xcount	^P	Move up (MOVE)
-X	^Q	--- (typically XON, which restarts screen updates)
-X	^R	Redraw the screen
-X	^S	--- (typically XOFF, which stops screen updates)
-X	^T	---
-Xcount	^U	Scroll up <count> lines (default 1/2 screen)
-X	^V	---
-X	^W	---
-Xcount	^X	Move to a physical column number on the screen (MOVE) (EXT)
-Xcount	^Y	Scroll down <count> lines
-X	^Z	--- (sometimes sends SIGSUSP, to suspend execution)
-X	ESC	---
-X	^\\	--- (usually sends SIGQUIT, which is ignored)
-X	^]	If the cursor is on a tag name, go to that tag
-X	^^	Switch to the previous file, like ":e #"
-X	^_	---
-Xcount	SPC	Move right,like l (MOVE)
-X	! \s-2mv\s+2	Run the selected lines thru an external filter program
-X	" \s-2key\s+2	Select which cut buffer to use next
-Xcount	# \s-2+\s+2	Increment a number (EDIT) (EXT)
-X	$	Move to the rear of the current line (MOVE)
-Xcount	%	Move to matching (){}[] or to a given % of file (MOVE) (EXT)
-Xcount	&	Repeat the previous ":s//" command here (EDIT)
-X	' \s-2key\s+2	Move to a marked line (MOVE)
-Xcount	(	Move backward <count> sentences (MOVE)
-Xcount	)	Move forward <count> sentences (MOVE)
-X	*	Go to the next error in the errlist (EXT)
-Xcount	+	Move to the front of the next line (MOVE)
-Xcount	,	Repeat the previous [fFtT] but in the other direction (MOVE)
-Xcount	-	Move to the front of the preceding line (MOVE)
-Xcount	.	Repeat the previous "edit" command
-X	/ \s-2text\s+2	Search forward for a given regular expression (MOVE)
-X	0	If not part of count, move to 1st char of this line (MOVE)
-X	1	Part of count
-X	2	Part of count
-X	3	Part of count
-X	4	Part of count
-X	5	Part of count
-X	6	Part of count
-X	7	Part of count
-X	8	Part of count
-X	9	Part of count
-X	: \s-2text\s+2	Run single EX cmd
-Xcount	;	Repeat the previous [fFtT] cmd (MOVE)
-X	< \s-2mv\s+2	Shift text left (EDIT)
-X	= \s-2mv\s+2	Reformat
-X	> \s-2mv\s+2	Shift text right (EDIT)
-X	? \s-2text\s+2	Search backward for a given regular expression (MOVE)
-X	@ \s-2key\s+2	Execute the contents of a cut-buffer as VI commands
-Xcount	A \s-2inp\s+2	Append at end of the line (EDIT)
-Xcount	B	Move back Word (MOVE)
-X	C \s-2inp\s+2	Change text from the cursor through the end of the line (EDIT)
-X	D	Delete text from the cursor through the end of the line (EDIT)
-Xcount	E	Move end of Word (MOVE)
-Xcount	F \s-2key\s+2	Move leftward to a given character (MOVE)
-Xcount	G	Move to line #<count> (default is the bottom line) (MOVE)
-Xcount	H	Move to home row (the line at the top of the screen)
-Xcount	I \s-2inp\s+2	Insert at the front of the line (after indents) (EDIT)
-Xcount	J	Join lines, to form one big line (EDIT)
-X	K	Look up keyword (EXT)
-Xcount	L	Move to last row (the line at the bottom of the screen)
-X	M	Move to middle row
-X	N	Repeat previous search, but in the opposite direction (MOVE)
-Xcount	O \s-2inp\s+2	Open up a new line above the current line (EDIT)
-X	P	Paste text before the cursor (EDIT)
-X	Q	Quit to EX mode
-X	R \s-2inp\s+2	Overtype (EDIT)
-Xcount	S \s-2inp\s+2	Change lines, like <count>cc
-Xcount	T \s-2key\s+2	Move leftward *almost* to a given character (MOVE)
-X	U	Undo all recent changes to the current line
-X	V	Start marking lines for c/d/y/</>/!/\\ (EXT)
-Xcount	W	Move forward <count> Words (MOVE)
-Xcount	X	Delete the character(s) to the left of the cursor (EDIT)
-Xcount	Y	Yank text line(s) (copy them into a cut buffer)
-X	Z Z	Save the file & exit
-X	[ [	Move back 1 section (MOVE)
-X	\\ \s-2mv\s+2	Pop-up menu for modifying text (EXT)
-X	] ]	Move forward 1 section (MOVE)
-X	^	Move to the front of the current line (after indent) (MOVE)
-Xcount	_	Move to the current line
-X	` \s-2key\s+2	Move to a marked character (MOVE)
-Xcount	a \s-2inp\s+2	Insert text after the cursor (EDIT)
-Xcount	b	Move back <count> words (MOVE)
-X	c \s-2mv\s+2	Change text (EDIT)
-X	d \s-2mv\s+2	Delete text (EDIT)
-Xcount	e	Move forward to the end of the current word (MOVE)
-Xcount	f \s-2key\s+2	Move rightward to a given character (MOVE)
-X	g	---
-Xcount	h	Move left (MOVE)
-Xcount	i \s-2inp\s+2	Insert text at the cursor (EDIT)
-Xcount	j	Move down (MOVE)
-Xcount	k	Move up (MOVE)
-Xcount	l	Move right (MOVE)
-X	m \s-2key\s+2	Mark a line or character
-X	n	Repeat the previous search (MOVE)
-Xcount	o \s-2inp\s+2	Open a new line below the current line (EDIT)
-X	p	Paste text after the cursor (EDIT)
-X	q	---
-Xcount	r \s-2key\s+2	Replace <count> chars by a given character (EDIT)
-Xcount	s \s-2inp\s+2	Replace <count> chars with text from the user (EDIT)
-Xcount	t \s-2key\s+2	Move rightward *almost* to a given character (MOVE)
-X	u	Undo the previous edit command
-X	v	Start marking characters for c/d/y/</>/!/\\ (EXT)
-Xcount	w	Move forward <count> words (MOVE)
-Xcount	x	Delete the character that the cursor's on (EDIT)
-X	y \s-2mv\s+2	Yank text (copy it into a cut buffer)
-X	z \s-2key\s+2	Scroll current line to the screen's +=top -=bottom .=middle
-Xcount	{	Move back <count> paragraphs (MOVE)
-Xcount	|	Move to column <count> (the leftmost column is 1)
-Xcount	}	Move forward <count> paragraphs (MOVE)
-Xcount	~	Switch a character between uppercase & lowercase (EDIT)
-X	DEL	--- (usually mapped to shift-X, so it deletes one character)
-X.DE
-X.IP count
-XMany commands may be preceded by a count.  This is a sequence of digits
-Xrepresenting a decimal number.  For most commands that use a count,
-Xthe command is repeated <count> times.  The count is always optional,
-Xand usually defaults to 1.
-X.IP key
-XSome commands require two keystrokes.  The first key always determines
-Xwhich command is to be executed.  The second key is used as a parameter
-Xto the command.
-X.IP mv
-XSome commands (! < > c d y \\ =) operate on text between the cursor and some
-Xother position.
-XThere are three ways that you can specifify that other position.
-X.IP
-XThe first way is to follow the command keystroke with a movement command.
-XFor example, "dw" deletes a single word.
-X"d3w" and "3dw" both delete three words.
-X.IP
-XThe second way is to type the command keystroke twice.
-XThis causes whole lines to be acted upon.
-XFor example, ">>" indents the current line.
-X"3>>" indents the current line and the following two lines.
-X.IP
-XThe last way is to move the cursor to one end of the text,
-Xtype 'v' or 'V' to start marking,
-Xmove the cursor to the other end,
-Xand then type the desired command key.
-X.IP inp
-XMany commands allow the user to interactively enter text.
-XSee the discussion of "input mode" in the following section.
-X.IP (EXT)
-XThese commands are extensions -- the real vi doesn't have them.
-X.IP (EDIT)
-XThese commands affect text, and may be repeated by the "." command.
-X.IP (MOVE)
-XThese commands move the cursor, and may be used to specify the extent
-Xof a member of the "mv" class of commands.
-X.NH 2
-XInput Mode
-X.PP
-XYou can't type text into your file directly from visual command mode.
-XInstead, you must first give a command which will put you into input mode.
-XThe commands to do this are A/C/I/O/R/S/a/i/o/s.
-X.PP
-XThe S/s/C/c commands temporarily place a $ at the end of the text that
-Xthey are going to change.
-X.PP
-XIn input mode, all keystrokes are inserted into the text at the
-Xcursor's position, except for the following:
-X.ID
-X^A	insert a copy of the last input text
-X^D	delete one indent character
-X^H	(backspace) erase the character before the cursor
-X^L	redraw the screen
-X^M	(carriage return) insert a newline (^J, linefeed)
-X^O	execute next key as a visual command (limited!)
-X^P	insert the contents of the cut buffer
-X^R	redraw the screen, like ^L
-X^T	insert an indent character
-X^U	backspace to the beginning of the line
-X^V	insert the following keystroke, even if special
-X^W	backspace to the beginning of the current word
-X^Z^Z	write the file & exit \*E
-X^[	(ESCape) exit from input mode, back to command mode
-X.DE
-X.PP
-XAlso, on some systems, ^S may stop output, ^Q may restart output,
-Xand ^C may interupt execution.
-X^@ (the NUL character) cannot be inserted.
-X.PP
-XThe R visual command puts you in overtype mode,
-Xwhich is a slightly different form of input mode.
-XIn overtype mode, each time you insert a character,
-Xone of the old characters is deleted from the file.
-X.NH 2
-XArrow keys in Input Mode
-X.PP
-XThe arrow keys can be used to move the cursor in input mode.
-X(This is an extension; the real Vi doesn't support arrow keys in input mode.)
-XThe <PgUp>, <PgDn>, <Home>, and <End> keys work in input mode, too.
-XThe <Delete> key deletes a single character in input mode.
-XThe <Insert> key toggles between input mode and replace mode.
-X.PP
-XThe best thing about allowing arrow keys to work in input mode is that
-Xas long as you're in input mode,
-X\*E seems to have a fairly ordinary user interface.
-XWith most other text editors, you are always in either insert mode or
-Xreplace mode, and you can use the arrow keys at any time to move the cursor.
-XNow, \*E can act like that, too.
-XIn fact, with the new "inputmode" option and the "control-Z control-Z" input
-Xcommand, you may never have to go into visual command mode for simple edit
-Xsessions.
-X.NH 2
-XDigraphs
-X.PP
-X\*E supports digraphs as a way to enter non-ASCII characters.
-XA digraph is a character which is composed of two other characters.
-XFor example, an apostrophe and the letter i could be defined as a digraph
-Xwhich is to be stored & displayed as an accented i.
-X.PP
-XThere is no single standard for extended ASCII character sets.
-X\*E can be compiled to fill the digraph with values appropriate for
-Xeither the IBM PC character set, or the LATIN-1 character set used by
-XX windows, or neither.
-X(See the discussions of -DCS_IBMPC and -DCS_LATIN1 in the CFLAGS section
-Xof this manual.)
-XYou can view or edit the digraph table via the ":digraph" colon command.
-X.PP
-XDigraphs will not be recognized until you've entered ":set digraph".
-X.PP
-XTo actually use a digraph
-Xtype the first character, then hit <Backspace>, and then type the
-Xsecond character.
-X\*E will then substitute the non-ASCII character in their place.
-X.NH 2
-XAbbreviations
-X.PP
-X\*E can expand abbreviations for you.
-XYou define an abbreviation with the :abbr command,
-Xand then whenever you type in the abbreviated form while in input mode,
-X\*E will immediately replace it with the long form.
-XCOBOL programmers should find this useful. :-)
-X.PP
-X\*E doesn't perform the substitution until you type a non-alphanumeric
-Xcharacter to mark the end of the word.
-XIf you type a control-V before that non-alphanumeric character, then
-X\*E will not perform the substitution.
-X.NH 2
-XAuto-Indent
-X.PP
-XWith the ":set autoindent" option turned on,
-X\*E will automatically insert leading whitespace at the beginning of each
-Xnew line that you type in.
-XThe leading whitespace is copied from the preceding line.
-X.PP
-XTo add more leading whitespace, type control-T.
-XTo remove some whitespace, type control-D.
-X.PP
-XIf you ":set noautotab", then the whitespace generated by control-T will
-Xalways consist of spaces -- never tabs.
-XSome people seem to prefer this.
-X.PP
-X\*E' autoindent mode isn't 100% compatible with vi's.
-XIn \*E, 0^D and ^^D don't work,
-X^U can wipeout all indentation, 
-Xand sometimes \*E will use a different amount of indentation than vi would.
-/
Index: trunk/minix/commands/elvis/Knownbug.txt
===================================================================
--- trunk/minix/commands/elvis/Knownbug.txt	(revision 9)
+++ 	(revision )
@@ -1,68 +1,0 @@
-The following options are missing:
-	[no]optimize	- affects screen redrawing method
-	[no]redraw	- simulate character insertion by redrawing line
-	[no]slowopen	- don't use character insertion
-	tags="tags"	- list of tags, used as TAGPATH
-
-I'd like to improve the versatility of the options whose value is a command:
-cc, make, kp, and ep.  I'd like to add some notation that allows you to say
-where to insert the current filename or current word.
--------------------------------------------------------------------------------
-Currently, elvis is configured to look for | only in .exrc files.  It doesn't
-look for | in any interactively entered command lines, yet.
--------------------------------------------------------------------------------
-The 'p', '#', and 'l' flags aren't supported.  Also, ex commands don't accept
-counts; e.g., ":c5" can't be used to change five lines. 
--------------------------------------------------------------------------------
-The following have been reported, but have not been verified.  If you have
-experienced any of the following, and haven't reported it yet, then please
-report it now!  I need more information about these bugs.
-
-[Bugs that are not in this list should also be reported, of course.]
-
-- Under VMS on an 80-column screen, after scolling sideways to approximately
-  column 110, a ^L will not redraw the part of the line after the cursor.
-- On an Atari ST running under TOS: some ASCII keys seem to send '#' plus
-  another key.  (This is normal for non-ASCII keys like <F1> or <Help>, but
-  ASCII keys should always send a single ASCII character.)
--------------------------------------------------------------------------------
-BIG JOBS:
-  Desirable extension: merge input mode and visual command mode.
-  Display long lines by wrapping, like the real vi (if ":set sidescroll=0")
--------------------------------------------------------------------------------
-
-- In the ":w >>filename" command, elvis doesn't allow any whitespace between
-  the ">>" and "filename".
-
-- Elvis doesn't allow "backslash newline" inside a single EX command.
-
-- VMS intercepts the control-T character, which is normally used to increase
-  indentation.  The <Tab> key works, but it doesn't do quite the same thing.
-  (":map! ^I ^T" helps.)
-
-- Under VMS, file I/O is very slow.  Looking over the vmsio.c file, I get the
-  impression that it is rather over-done for elvis.  Its speed could
-  probably be inproved.
-
-- The errlist feature doesn't seem to work with the Borland compilers.  Perhaps
-  they write to stderr instead of stdout?  This will probably be easy to solve
-  once I modify the "cc" and "make" options, as described earlier.
-
-- The command ":0" should move the cursor to line 1.  Currently, it doesn't
-  move the cursor at all.
-
-- File preservation is still flakey.  On DOS/TOS/VMS systems, it is also more
-  complex that it should be.
-
-- The act of appending to a cut buffer (as in "Ayy) sets file modification
-  flag.  It shouldn't!
-
-- The .exrc file is limited to BLKSIZE bytes -- 2048 on most systems, but
-  1024 on Minicx-PC, Coherent, and MS-DOS.
-
-- I *still* haven't quite perfected the screen update code.  If you suspect
-  that the screen doesn't accurately reflect the contents of the edit buffer,
-  then you should try doing a control-L.
-
-  I'll be overhauling the screen update code soon to make it wrap long lines
-  like the real vi.  I expect to fix this bug then.
Index: trunk/minix/commands/elvis/Makedoc
===================================================================
--- trunk/minix/commands/elvis/Makedoc	(revision 9)
+++ 	(revision )
@@ -1,87 +1,0 @@
-# This is the Makefile for Elvis' "doc" directory.  It makes use of a
-# troff-like formatter called mroff.  Since you probably don't have mroff,
-# you'll need to edit this Makefile before you can fully use it.  It can
-# also use nroff, though, so you should be able to get something out of it.
-#
-# make		Use nroff to create an ASCII version of the manual.
-# make foo.doc	Use nroff to create an ASCII version of foo.man or foo.ms
-# make manual	Use MROFF to print a typeset manual on a laser printer
-# make foo.1200	Use MROFF to print a typeset version of foo.man or foo.ms
-# make foo.100	Use MROFF to print a draft-quality version of foo.man or foo.ms
-# make foo.more	Use MROFF to preview foo.man or foo.more on your terminal
-#
-
-###############################################################################
-# Definitions...
-
-MAN=	ctags.man elvis.man elvprsv.man elvrec.man fmt.man ref.man
-MS=	title.ms index.ms intro.ms visual.ms ex.ms regexp.ms options.ms\
-	cutbufs.ms differ.ms internal.ms cflags.ms termcap.ms environ.ms\
-	versions.ms question.ms
-ASC=	title.doc index.doc intro.doc visual.doc ex.doc regexp.doc options.doc\
-	cutbufs.doc differ.doc internal.doc cflags.doc termcap.doc environ.doc\
-	versions.doc question.doc\
-	ctags.doc elvis.doc elvprsv.doc elvrec.doc fmt.doc ref.doc
-MANUAL=	title.1200 index.1200 intro.1200 visual.1200 ex.1200 regexp.1200 options.1200\
-	cutbufs.1200 differ.1200 internal.1200 cflags.1200 termcap.1200 environ.1200\
-	versions.1200\
-	ctags.1200 elvis.1200 elvprsv.1200 elvrec.1200 fmt.1200 ref.1200
-VER=	ver.ms
-TROFF=	mroff
-NROFF=	nroff
-
-###############################################################################
-# Rules...
-
-.SUFFIXES: .tmp .100 .1200 .more .doc .man .ms .vga .vgas
-
-.ms.tmp:
-	$(TROFF) -ms $(VER) $< >tmp
-
-.man.tmp:
-	$(TROFF) -man $< >tmp
-
-.ms.more:
-	$(TROFF) -ms $(VER) $< | draft | more
-
-.man.more:
-	$(TROFF) -man $< | draft | more
-
-.ms.1200:
-	$(TROFF) -ms $(VER) $< | hp2 1200 | lp -og $(PRINTER)
-
-.man.1200:
-	$(TROFF) -man $< | hp2 1200 | lp -og $(PRINTER)
-
-.ms.100:
-	$(TROFF) -ms $(VER) $< | hp2 100 | lp -og $(PRINTER)
-
-.man.100:
-	$(TROFF) -man $< | hp2 100 | lp -og $(PRINTER)
-
-.ms.doc:
-	$(NROFF) -ms $(VER) $< >$@
-
-.man.doc:
-	$(NROFF) -man $< >$@
-
-.ms.vga:
-	$(TROFF) -ms $(VER) $< >/tmp/foo
-	-vga /tmp/foo
-	rm /tmp/foo
-
-.ms.vgas:
-	$(TROFF) -ms $(VER) $< >/tmp/foo
-	-vgas /tmp/foo
-	rm /tmp/foo
-
-#############################################################################
-# Targets...
-
-asc: $(ASC)
-	cat $(ASC) >asc
-
-manual: $(MANUAL)
-
-clean:
-	rm -f *.doc *.sh
Index: trunk/minix/commands/elvis/Makefile
===================================================================
--- trunk/minix/commands/elvis/Makefile	(revision 9)
+++ 	(revision )
@@ -1,92 +1,0 @@
-# Makefile for elvis
-#
-# Several groups of Makefile settings are included below.  Choose *ONE* group
-# of settings for your particular system, and leave the others commented out.
-# The meanings of these settings are:
-#	EXTRA	version-specific object files used in elvis
-#	CC	the C compiler command, possibly with "memory model" flags
-#	CFLAGS	compiler flags used to select compile-time options
-#	PROGS	the list of all programs
-#	SORT	if the "tags" file must be sorted, then SORT=-DSORT
-
-CC = exec cc
-PROGS=	elvis ctags ref elvrec fmt elvprsv
-
-#---- These settings are recommended for Minix-PC ----
-EXTRA=	tinytcap.o tinyprnt.o
-CFLAGS=	-O -w -D_POSIX_SOURCE -D_MINIX -DCRUNCH \
-	-DNO_MKEXRC -DNO_CURSORSHAPE -DNO_CHARATTR -DNO_SHOWMODE \
-	-DNO_MODELINE -DNO_OPTCOLS -DNO_DIGRAPH -DNO_EXTENSIONS \
-	-DNO_ERRLIST -DNO_FKEY -DNO_VISIBLE -DNO_COLOR -DNO_POPUP
-LDFLAGS=-i
-
-#---- These settings are recommended for Minix-ST ----
-#EXTRA=
-#CFLAGS=
-
-###########################################################################
-###     The rest of this Makefile contains no user-serviceable parts    ###
-###########################################################################
-
-OBJ=blk.o cmd1.o cmd2.o ctype.o curses.o cut.o ex.o input.o \
-   main.o misc.o modify.o move1.o move2.o move3.o move4.o move5.o \
-   opts.o recycle.o redraw.o regexp.o regsub.o system.o tio.o tmp.o \
-   unix.o vars.o vcmd.o vi.o
-
-all:	$(PROGS)
-
-elvis:	$(OBJ)
-	$(CC) $(LDFLAGS) -o elvis $(OBJ)
-	install -S 18kw elvis
-
-ctags:	ctags.c
-	$(CC) $(CFLAGS) $(SORT) $(LDFLAGS) -o ctags ctags.c
-	install -S 4kw $@
-
-ref:	ref.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o ref ref.c
-	install -S 4kw $@
-
-elvrec:	elvrec.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o elvrec elvrec.c
-	install -S 4kw $@
-
-fmt:	fmt.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o fmt fmt.c
-	install -S 4kw $@
-
-elvprsv:	elvprsv.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o elvprsv elvprsv.c ctype.o
-	install -S 4kw $@
-
-install:	/usr/bin/elvis \
-		/bin/elvis \
-		/usr/bin/ctags /usr/bin/ref /usr/bin/fmt \
-		/usr/bin/elvrec /usr/bin/elvprsv
-
-/usr/bin/elvis:	elvis
-	install -cs -o bin elvis $@
-
-/bin/elvis:	elvis
-	install -cs -o bin elvis $@
-
-/usr/bin/ctags:	ctags
-	install -cs -o bin ctags $@
-
-/usr/bin/ref:	ref
-	install -cs -o bin ref $@
-
-/usr/bin/fmt:	fmt
-	install -cs -o bin fmt $@
-
-/usr/bin/elvrec:	elvrec
-	install -cs -o root -m 4755 elvrec $@
-
-/usr/bin/elvprsv:	elvprsv
-	install -cs -o root -m 4755 elvprsv $@
-
-# Dependencies
-$(OBJ):	vi.h curses.h config.h regexp.h ctype.h
-
-clean:	
-	rm -f *.o ctags ref elvrec fmt elvprsv elvis
Index: trunk/minix/commands/elvis/Man.sh
===================================================================
--- trunk/minix/commands/elvis/Man.sh	(revision 9)
+++ 	(revision )
@@ -1,414 +1,0 @@
-echo x - ctags.man
-sed '/^X/s///' > ctags.man << '/'
-X.TH CTAGS 1
-X.SH NAME
-Xctags - Generates "tags" and (optionally) "refs" files
-X.SH SYNOPSIS
-X\fBctags\fP [\fB-stvra\fP] \fIfilesnames\fP...
-X.SH DESCRIPTION
-X\fIctags\fP generates the "tags" and "refs" files
-Xfrom a group of C source files.
-XThe "tags" file is used by Elvis' ":tag" command,
-Xcontrol-] command,
-Xand -t option.
-XThe "refs" file is sometimes used by the \fIref(1)\fP program.
-X.PP
-XEach C source file is scanned for #define statements and
-Xglobal function definitions.
-XThe name of the macro or function becomes the name of a tag.
-XFor each tag, a line is added to the "tags" file which contains:
-X.RS
-X.nf
-X       - the name of the tag
-X       - a tab character
-X       - the name of the file containing the tag
-X       - a tab character
-X       - a way to find the particular line within the file.
-X.RE
-X.fi
-X.PP
-XThe filenames list will typically be the names of all C source
-Xfiles in the current directory, like this:
-X.RS
-X.nf
-X$ ctags -stv *.[ch]
-X.RE
-X.fi
-X.SH OPTIONS
-X.IP \fB-t\fR
-XInclude typedefs.
-XA tag will be generated for each user-defined type.
-XAlso tags will be generated for struct and enum names.
-XTypes are considered to be global if they are defined in a header file,
-Xand static if they are defined in a C source file.
-X.IP \fB-v\fR
-XInclude variable declarations.
-XA tag will be generated for each variable, except for those that are declared
-Xinside the body of a function.
-X.IP \fB-s\fR
-XInclude static tags.
-X\fICtags\fR will normally put global tags in the "tags" file, and silently ignore
-Xthe static tags.
-XThis flag causes both global and static tags to be added.
-XThe name of a static tag is generated by prefixing the name of the declared
-Xitem with the name of the file where it is defined, with a colon in between.
-XFor example, "static foo(){}" in "bar.c" results in a tag named "bar.c:foo".
-X.IP \fB-r\fP
-XThis causes \fIctags\fP to generate both "tags" and "refs".
-XWithout \fB-r\fP, it would only generate "tags".
-X.IP \fB-a\fR
-XAppend to "tags", and maybe "refs".
-XNormally, \fIctags\fR overwrites these files each time it is invoked.
-XThis flag is useful when you have to many files in the current directory
-Xfor you to list them on a single command-line;
-Xit allows you to split the arguments among several invocations.
-X.SH FILES
-X.IP tags
-XA cross-reference that lists each tag name, the name of the source file that
-Xcontains it, and a way to locate a particular line in the source file.
-X.IP refs
-XThe "refs" file contains the definitions for each tag in the "tags" file,
-Xand very little else.
-XThis file can be useful, for example, when licensing restrictions prevent
-Xyou from making the source code to the standard C library readable by everybody,
-Xbut you still everybody to know what arguments the library functions need.
-X.SH BUGS
-X.PP
-X\fIctags\fR is sensitive to indenting and line breaks.
-XConsequently, it might not discover all of the tags in a file that
-Xis formatted in an unusual way.
-X.SH "SEE ALSO"
-Xelvis(1), refs(1)
-X.SH AUTHOR
-X.nf
-XSteve Kirkendall
-Xkirkenda@cs.pdx.edu
-X.fi
-/
-echo x - elvis.man
-sed '/^X/s///' > elvis.man << '/'
-X.TH ELVIS 1
-X.SH NAME
-Xelvis, ex, vi, view, input - The editor
-X.SH SYNOPSIS
-X\fBelvis\fP [\fIflags\fP] [\fB+\fP\fIcmd\fP] [\fIfiles\fP...]
-X.SH DESCRIPTION
-X\fIElvis\fP is a text editor which emulates \fIvi\fP/\fIex\fP.
-X.PP
-XOn systems which pass the program name as an argument, such as Unix and Minix,
-Xyou may also install \fIelvis\fP under the names "ex", "vi", "view", and "input".
-XThese extra names would normally be links to elvis;
-Xsee the "ln" shell command.
-X.PP
-XWhen \fIelvis\fP is invoked as "vi",
-Xit behaves exactly as though it was invoked as "elvis".
-XHowever, if you invoke \fIelvis\fP as "view",
-Xthen the readonly option is set as though you had given it the "-R" flag.
-XIf you invoke \fIelvis\fP as "ex",
-Xthen \fIelvis\fP will start up in the colon command mode
-Xinstead of the visual command mode,
-Xas though you had given it the "-e" flag.
-XIf you invoke \fIelvis\fP as "input" or "edit",
-Xthen \fIelvis\fP will start up in input mode,
-Xas though the "-i" flag was given.
-X.SH OPTIONS
-X.IP \fB-r\fP
-XTo the real vi, this flag means that a previous edit should be recovered.
-X\fIElvis\fP, though, has a separate program, called \fIelvrec(1)\fP, for recovering
-Xfiles.
-XWhen you invoke \fIelvis\fP with -r, \fIelvis\fP will tell you to run \fIelvrec\fP.
-X.IP \fB-R\fP
-XThis sets the "readonly" option,
-Xso you won't accidentally overwrite a file.
-X.IP "\fB-t\fP \fItag\fP"
-XThis causes \fIelvis\fP to start editing at the given tag.
-X.IP "\fB-m\fP [\fIfile\fP]"
-X\fIElvis\fP will search through \fIfile\fP for something that looks like
-Xan error message from a compiler.
-XIt will then begin editing the source file that caused the error,
-Xwith the cursor sitting on the line where the error was detected.
-XIf you don't explicitly name a \fIfile\fP, then "errlist" is assumed.
-X.IP \fB-e\fP
-X\fIElvis\fP will start up in colon command mode.
-X.IP \fB-v\fP
-X\fIElvis\fP will start up in visual command mode.
-X.IP \fB-i\fP
-X\fIElvis\fP will start up in input mode.
-X.IP "\fB-w\fR \fIwinsize\fR"
-XSets the "window" option's value to \fIwinsize\fR.
-X.IP "\fB+\fP\fIcommand\fP or \fB-c\fP \fIcommand\fP"
-XIf you use the +\fIcommand\fP parameter,
-Xthen after the first file is loaded
-X\fIcommand\fP is executed as an EX command.
-XA typical example would be "elvis +237 foo",
-Xwhich would cause \fIelvis\fP to start editing foo and
-Xthen move directly to line 237.
-XThe "-c \fIcommand\fP" variant was added for UNIX SysV compatibility.
-X.SH FILES
-X.IP /tmp/elv*
-XDuring editing,
-X\fIelvis\fP stores text in a temporary file.
-XFor UNIX, this file will usually be stored in the /tmp directory,
-Xand the first three characters will be "elv".
-XFor other systems, the temporary files may be stored someplace else;
-Xsee the version-specific section of the documentation.
-X.IP tags
-XThis is the database used by the \fI:tags\fP command and the \fB-t\fP option.
-XIt is usually created by the \fIctags(1)\fP program.
-X.IP ".exrc or elvis.rc"
-XOn UNIX-like systems, a file called ".exrc" in your home directory
-Xis executed as a series of \fIex\fR commands.
-XA file by the same name may be executed in the current directory, too.
-XOn non-UNIX systems, ".exrc" is usually an invalid file name;
-Xthere, the initialization file is called "elvis.rc" instead.
-X.SH "SEE ALSO"
-Xctags(1), ref(1), virec(1)
-X.PP
-X\fIElvis - A Clone of Vi/Ex\fP, the complete \fIelvis\fP documentation.
-X.SH BUGS
-XThere is no LISP support.
-XCertain other features are missing, too.
-X.PP
-XAuto-indent mode is not quite compatible with the real vi.
-XAmong other things, 0^D and ^^D don't do what you might expect.
-X.PP
-XLong lines are displayed differently.
-XThe real vi wraps long lines onto multiple rows of the screen,
-Xbut \fIelvis\fP scrolls sideways.
-X.SH AUTHOR
-X.nf
-XSteve Kirkendall
-Xkirkenda@cs.pdx.edu
-X.fi
-X.PP
-XMany other people have worked to port \fIelvis\fP to various operating systems.
-XTo see who deserves credit, run the \fI:version\fP command from within \fIelvis\fP,
-Xor look in the system-specific section of the complete documentation.
-/
-echo x - elvprsv.man
-sed '/^X/s///' > elvprsv.man << '/'
-X.TH ELVPRSV 1
-X.SH NAME
-Xelvprsv - Preserve the the modified version of a file after a crash.
-X.SH SYNOPSIS
-X.nf
-X\fB\fBelvprsv\fP ["-\fIwhy elvis died\fP"] /tmp/\fIfilename\fP...
-X\fB\fBelvprsv\fP -R /tmp/\fIfilename\fP...
-X.fi
-X.SH DESCRIPTION
-X.PP
-X\fIelvprsv\fP preserves your edited text after \fIelvis\fP dies.
-XThe text can be recovered later, via the \fIelvprsv\fP program.
-X.PP
-XFor UNIX-like systems,
-Xyou should never need to run this program from the command line.
-XIt is run automatically when \fIelvis\fP is about to die,
-Xand it should be run (via /etc/rc) when the computer is booted.
-XTHAT'S ALL!
-X.PP
-XFor non-UNIX systems such as MS-DOS, you can either use \fIelvprsv\fP
-Xthe same way as under UNIX systems (by running it from your AUTOEXEC.BAT file),
-Xor you can run it separately with the "-R" flag to recover the files
-Xin one step.
-X.PP
-XIf you're editing a file when \fIelvis\fP dies
-X(due to a bug, system crash, power failure, etc.)
-Xthen \fIelvprsv\fP will preserve the most recent version of your text.
-XThe preserved text is stored in a special directory; it does NOT overwrite
-Xyour text file automatically.
-X.PP
-X\fIelvprsv\fP will send mail to any user whose work it preserves,
-Xif your operating system normally supports mail.
-X.SH FILES
-X.IP /tmp/elv*
-XThe temporary file that \fIelvis\fP was using when it died.
-X.IP /usr/preserve/p*
-XThe text that is preserved by \fIelvprsv\fP.
-X.IP /usr/preserve/Index
-XA text file which lists the names of all preserved files, and the names
-Xof the /usr/preserve/p* files which contain their preserved text.
-X.SH BUGS
-X.PP
-XDue to the permissions on the /usr/preserve directory, on UNIX systems
-X\fIelvprsv\fP must be run as superuser.
-XThis is accomplished by making the \fIelvprsv\fP executable be owned by "root"
-Xand turning on its "set user id" bit.
-X.PP
-XIf you're editing a nameless buffer when \fIelvis\fP dies, then \fIelvprsv\fP will pretend
-Xthat the file was named "foo".
-X.SH AUTHOR
-X.nf
-XSteve Kirkendall
-Xkirkenda@cs.pdx.edu
-X.fi
-/
-echo x - elvrec.man
-sed '/^X/s///' > elvrec.man << '/'
-X.TH ELVREC 1
-X.SH NAME
-Xelvrec - Recover the modified version of a file after a crash
-X.SH SYNOPSIS
-X.nf
-X\fBelvrec\fP [\fIpreservedfile\fP [\fInewfile\fR]]
-X.fi
-X.SH DESCRIPTION
-X.PP
-XIf you're editing a file when \fIelvis\fP dies, the system crashes, or power fails,
-Xthe most recent version of your text will be preserved.
-XThe preserved text is stored in a special directory; it does NOT overwrite
-Xyour text file automatically.
-X.PP
-XThe \fIelvrec\fP program locates the preserved version of a given file,
-Xand writes it over the top of your text file -- or to a new file, if you prefer.
-XThe recovered file will have nearly all of your changes.
-X.PP
-XTo see a list of all recoverable files, run \fIelvrec\fP with no arguments.
-X.SH FILES
-X.IP /usr/preserve/p*
-XThe text that was preserved when \fIelvis\fP died.
-X.IP /usr/preserve/Index
-XA text file which lists the names of all preserved files, and the names
-Xof the /usr/preserve/p* files which contain their preserved text.
-X.SH BUGS
-X.PP
-X\fIelvrec\fP is very picky about filenames.
-XYou must tell it to recover the file using exactly the same pathname as
-Xwhen you were editing it.
-XThe simplest way to do this is to go into the same directory that you were
-Xediting, and invoke \fIelvrec\fP with the same filename as \fIelvis\fP.
-XIf that doesn't work, then try running \fIelvrec\fP with no arguments,
-Xto see exactly which pathname it is using for the desired file.
-X.PP
-XDue to the permissions on the /usr/preserve directory, on UNIX systems
-X\fIelvrec\fP must be run as superuser.
-XThis is accomplished by making the \fIelvrec\fP executable be owned by "root"
-Xand setting its "set user id" bit.
-X.PP
-XIf you're editing a nameless buffer when \fIelvis\fP dies, then \fIelvrec\fP
-Xwill pretend that the file was named "foo".
-X.SH AUTHOR
-X.nf
-XSteve Kirkendall
-Xkirkenda@cs.pdx.edu
-X.fi
-/
-echo x - fmt.man
-sed '/^X/s///' > fmt.man << '/'
-X.TH FMT 1
-X.SH NAME
-Xfmt - adjust line-length for paragraphs of text
-X.SH SYNOPSIS
-X\fBfmt\fP [\-\fIwidth\fP] [\fIfiles\fP]...
-X.SH DESCRIPTION
-X\fIfmt\fR is a simple text formatter.
-XIt inserts or deletes newlines, as necessary, to make all lines in a
-Xparagraph be approximately the same width.
-XIt preserves indentation and word spacing.
-X.PP
-XThe default line width is 72 characters.
-XYou can override this with the \-\fIwidth\fR flag.
-XIf you don't name any files on the command line,
-Xthen \fIfmt\fR will read from stdin.
-X.PP
-XIt is typically used from within \fIvi\fR to adjust the line breaks
-Xin a single paragraph.
-XTo do this, move the cursor to the top of the paragraph,
-Xtype "!}fmt", and
-Xhit <Return>.
-X.SH AUTHOR
-X.nf
-XSteve Kirkendall
-Xkirkenda@cs.pdx.edu
-X.fi
-/
-echo x - ref.man
-sed '/^X/s///' > ref.man << '/'
-X.TH REF 1
-X.SH NAME
-Xref - Display a C function header
-X.SH SYNOPSIS
-X\fBref\fR [-t] [-c \fIclass\fR]... [-f \fIfile\fR]... \fItag\fR
-X.SH DESCRIPTION
-X\fIref\fP quickly locates and displays the header of a function.
-XTo do this, \fIref\fR
-Xlooks in the "tags" file for the line that describes the function, and then 
-Xscans the source file for the function.
-XWhen it locates the function, it displays an introductory comment
-X(if there is one), the function's declaration, and the declarations of all
-Xarguments.
-X.SH "SEARCH METHOD"
-X.PP
-X\fIref\fR uses a fairly sophisticated tag look-up algorithm.
-XIf you supply a filename via \fB-f\fR \fIfile\fR, then elvis first scans
-Xthe tags file for a static tag from that file.
-XThis search is limited to the tags file in the current directory.
-X.PP
-XIf you supply a classname via \fB-c\fR \fIclass\fR, then elvis searches
-Xfor a tag from that class.
-XThis search is not limited to the current directory;
-XYou can supply a list of directories in the environment variable \fITAGPATH\fR,
-Xand \fIref\fR will search through the "tags" file in each directory until it finds
-Xa tag in the desired class.
-X.PP
-XIf that fails, \fIref\fR will then try to look up an ordinary global tag.
-XThis search checks all of the directories listed in \fITAGPATH\fR, too.
-X.PP
-XIf you've given the \fB-t\fR flag, then \fIref\fR will simply output the tag line that
-Xit found, and then exit.
-XWithout \fB-t\fR, though, \fIref\fR will search for the tag line.
-XIt will try to open the source file, which should be in the same directory
-Xas the tags file where the tag was discovered.
-XIf the source file doesn't exist, or is unreadable, then \fIref\fR will try to open
-Xa file called "\fIrefs\fR" in that directory.
-XEither way, \fIref\fR will try to locate the tag, and display whatever it finds.
-X.SH "INTERACTION WITH ELVIS"
-X.PP
-X\fIref\fP is used by \fIelvis\fR' shift-K command.
-XIf the cursor is located on a word such as "splat", in the file "foo.c",
-Xthen \fIelvis\fR will invoke \fIref\fR with the command "ref -f foo.c splat".
-X.PP
-XIf \fIelvis\fR has been compiled with the -DEXTERNAL_TAGS flag, then \fIelvis\fR will
-Xuse \fIref\fR \fB\fRto scan the tags files.
-XThis is slower than the built-in tag searching, but it allows \fIelvis\fR to access
-Xthe more sophisticated tag lookup provided by \fIref\fR.
-XOther than that, external tags should act exactly like internal tags.
-X.SH OPTIONS
-X.IP \fB-t\fR
-XOutput tag info, instead of the function header.
-X.IP "\fB-f\fR \fIfile\fR"
-XThe tag might be a static function in \fIfile\fR.
-XYou can use several -f flags to have \fIref\fR consider static tags from more than one file.
-X.IP "\fB-c\fR \fIclass\fR"
-XThe tag might be a member of class \fIclass\fR.
-XYou can use several -c flags to have \fIref\fR consider tags from more than one class.
-X.SH FILES
-X.IP \fBtags\fR
-XList of function names and their locations, generated by \fIctags\fR.
-X.IP \fBrefs\fR
-XFunction headers extracted from source files (optional).
-X.SH ENVIRONMENT
-X.IP \fBTAGPATH\fR
-XList of directories to be searched.
-XThe elements in the list are separated by either
-Xsemicolons (for MS-DOS, Atari TOS, and AmigaDos), or
-Xby colons (every other operating system).
-XFor each operating system, \fIref\fR has a built-in default which is probably
-Xadequate.
-X.SH NOTES
-X.PP
-XYou might want to generate a "tags" file the directory that contains the
-Xsource code for standard C library on your system.
-XIf licensing restrictions prevent you from making the library source readable
-Xby everybody, then you can have \fIctags\fR generate a "refs" file,
-Xand make "refs" readable by everybody.
-X.PP
-XIf your system doesn't come with the library source code, then perhaps you
-Xcan produce something workable from the \fIlint\fR libraries.
-X.SH "SEE ALSO"
-Xelvis(1), ctags(1)
-X.SH AUTHOR
-X.nf
-XSteve Kirkendall
-Xkirkenda@cs.pdx.edu
-X.fi
-/
Index: trunk/minix/commands/elvis/Readme.txt
===================================================================
--- trunk/minix/commands/elvis/Readme.txt	(revision 9)
+++ 	(revision )
@@ -1,31 +1,0 @@
-Elvis is a clone of vi/ex, the standard UNIX editor.  Elvis supports
-nearly all of the vi/ex commands, in both visual mode and colon mode.
-
-Elvis runs under BSD UNIX, AT&T SysV UNIX, SCO Xenix, Minix, MS-DOS
-(Turbo-C or MSC 5.1), Atari TOS, OS9/68000, Coherent, VMS, and AmigaDos.
-Ports to other operating systems are in progress; contact me before you
-start porting it to some other OS, because somebody else may have
-already done it for you.
-
-Elvis is freely redistributable, in either source form or executable
-form.  There are no restrictions on how you may use it.
-
-The file "elvisman.txt" contains the manual for elvis.  It is a plain
-ASCII file with nothing more exotic than a newline character.  It is
-formatted for 66-line, 80-column pages.  There may also be an archive of
-"*.ms" and "*.man" files, which contain the TROFF source text used to
-generate that manual.
-
-The file named "Makefile.mix" is used to compile elvis for all systems
-except VMS and possibly MS-DOS.  You should copy "Makefile.mix" to
-"Makefile", and then edit "Makefile" to select the appropriate group of
-settings for your system.
-
-
-Author: Steve Kirkendall
-	14407 SW Teal Blvd. #C
-	Beaverton, OR   97005
-
-E-mail:	kirkenda@cs.pdx.edu
-
-Phone:	(503) 643-6980
Index: trunk/minix/commands/elvis/blk.c
===================================================================
--- trunk/minix/commands/elvis/blk.c	(revision 9)
+++ 	(revision )
@@ -1,469 +1,0 @@
-/* blk.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the functions that get/put blocks from the temp file.
- * It also contains the "do" and "undo" functions.
- */
-
-#include "config.h"
-#include "vi.h"
-
-#ifndef NBUFS
-# define NBUFS	5		/* must be at least 3 -- more is better */
-#endif
-
-
-/*------------------------------------------------------------------------*/
-
-BLK		hdr;		/* buffer for the header block */
-
-static int	b4cnt;		/* used to count context of beforedo/afterdo */
-static struct _blkbuf
-{
-	BLK		buf;		/* contents of a text block */
-	unsigned short	logical;	/* logical block number */
-	int		dirty;		/* must the buffer be rewritten? */
-}
-		blk[NBUFS],	/* buffers for text[?] blocks */
-		*toonew,	/* buffer which shouldn't be recycled yet */
-		*newtoo,	/* another buffer which should be recycled */
-		*recycle = blk;	/* next block to be recycled */
-
-
-
-
-
-/* This function wipes out all buffers */
-void blkinit()
-{
-	int	i;
-
-	for (i = 0; i < NBUFS; i++)
-	{
-		blk[i].logical = 0;
-		blk[i].dirty = FALSE;
-	}
-	for (i = 0; i < MAXBLKS; i++)
-	{
-		hdr.n[i] = 0;
-	}
-}
-
-/* This function allocates a buffer and fills it with a given block's text */
-BLK *blkget(logical)
-	int	logical;	/* logical block number to fetch */
-{
-	REG struct _blkbuf	*this;	/* used to step through blk[] */
-	REG int	i;
-
-	/* if logical is 0, just return the hdr buffer */
-	if (logical == 0)
-	{
-		return &hdr;
-	}
-
-	/* see if we have that block in mem already */
-	for (this = blk; this < &blk[NBUFS]; this++)
-	{
-		if (this->logical == logical)
-		{
-			newtoo = toonew;
-			toonew = this;
-			return &this->buf;
-		}
-	}
-
-	/* choose a block to be recycled */
-	do
-	{
-		this = recycle++;
-		if (recycle == &blk[NBUFS])
-		{
-			recycle = blk;
-		}
-	} while (this == toonew || this == newtoo);
-
-	/* if it contains a block, flush that block */
-	blkflush(this);
-
-	/* fill this buffer with the desired block */
-	this->logical = logical;
-	if (hdr.n[logical])
-	{
-		/* it has been used before - fill it from tmp file */
-		lseek(tmpfd, (long)hdr.n[logical] * (long)BLKSIZE, 0);
-		if (read(tmpfd, this->buf.c, (unsigned)BLKSIZE) != BLKSIZE)
-		{
-			msg("Error reading back from tmp file!");
-		}
-	}
-	else
-	{
-		/* it is new - zero it */
-		for (i = 0; i < BLKSIZE; i++)
-		{
-			this->buf.c[i] = 0;
-		}
-	}
-
-	/* This isn't really a change, but it does potentially invalidate
-	 * the kinds of shortcuts that the "changes" variable is supposed
-	 * to protect us from... so count it as a change.
-	 */
-	changes++;
-
-	/* mark it as being "not dirty" */
-	this->dirty = 0;
-
-	/* return it */
-	newtoo = toonew;
-	toonew = this;
-	return &this->buf;
-}
-
-
-
-/* This function writes a block out to the temporary file */
-void blkflush(this)
-	REG struct _blkbuf	*this;	/* the buffer to flush */
-{
-	long		seekpos;	/* seek position of the new block */
-	unsigned short	physical;	/* physical block number */
-
-	/* if its empty (an orphan blkadd() maybe?) then make it dirty */
-	if (this->logical && !*this->buf.c)
-	{
-		blkdirty(&this->buf);
-	}
-
-	/* if it's an empty buffer or a clean version is on disk, quit */
-	if (!this->logical || hdr.n[this->logical] && !this->dirty)
-	{
-		return;
-	}
-
-	/* find a free place in the file */
-#ifndef NO_RECYCLE
-	seekpos = allocate();
-	lseek(tmpfd, seekpos, 0);
-#else
-	seekpos = lseek(tmpfd, 0L, 2);
-#endif
-	physical = seekpos / BLKSIZE;
-
-	/* put the block there */
-	if (write(tmpfd, this->buf.c, (unsigned)BLKSIZE) != BLKSIZE)
-	{
-		msg("Trouble writing to tmp file");
-	}
-	this->dirty = FALSE;
-
-	/* update the header so it knows we put it there */
-	hdr.n[this->logical] = physical;
-}
-
-
-/* This function sets a block's "dirty" flag or deletes empty blocks */
-void blkdirty(bp)
-	BLK	*bp;	/* buffer returned by blkget() */
-{
-	REG int		i, j;
-	REG char	*scan;
-	REG int		k;
-
-	/* find the buffer */
-	for (i = 0; i < NBUFS && bp != &blk[i].buf; i++)
-	{
-	}
-#ifdef DEBUG
-	if (i >= NBUFS)
-	{
-		msg("blkdirty() called with unknown buffer at 0x%lx", bp);
-		return;
-	}
-	if (blk[i].logical == 0)
-	{
-		msg("blkdirty called with freed buffer");
-		return;
-	}
-#endif
-
-	/* if this block ends with line# INFINITY, then it must have been
-	 * allocated unnecessarily during tmpstart().  Forget it.
-	 */
-	if (lnum[blk[i].logical] == INFINITY)
-	{
-#ifdef DEBUG
-		if (blk[i].buf.c[0])
-		{
-			msg("bkldirty called with non-empty extra BLK");
-		}
-#endif
-		blk[i].logical = 0;
-		blk[i].dirty = FALSE;
-		return;
-	}
-
-	/* count lines in this block */
-	for (j = 0, scan = bp->c; *scan && scan < bp->c + BLKSIZE; scan++)
-	{
-		if (*scan == '\n')
-		{
-			j++;
-		}
-	}
-
-	/* adjust lnum, if necessary */
-	k = blk[i].logical;
-	j += (lnum[k - 1] - lnum[k]);
-	if (j != 0)
-	{
-		nlines += j;
-		while (k < MAXBLKS && lnum[k] != INFINITY)
-		{
-			lnum[k++] += j;
-		}
-	}
-
-	/* if it still has text, mark it as dirty */
-	if (*bp->c)
-	{
-		blk[i].dirty = TRUE;
-	}
-	else /* empty block, so delete it */
-	{
-		/* adjust the cache */
-		k = blk[i].logical;
-		for (j = 0; j < NBUFS; j++)
-		{
-			if (blk[j].logical >= k)
-			{
-				blk[j].logical--;
-			}
-		}
-
-		/* delete it from hdr.n[] and lnum[] */
-		blk[i].logical = 0;
-		blk[i].dirty = FALSE;
-		while (k < MAXBLKS - 1)
-		{
-			hdr.n[k] = hdr.n[k + 1];
-			lnum[k] = lnum[k + 1];
-			k++;
-		}
-		hdr.n[MAXBLKS - 1] = 0;
-		lnum[MAXBLKS - 1] = INFINITY;
-	}
-}
-
-
-/* insert a new block into hdr, and adjust the cache */
-BLK *blkadd(logical)
-	int	logical;	/* where to insert the new block */
-{
-	REG int	i;
-
-	/* adjust hdr and lnum[] */
-	for (i = MAXBLKS - 1; i > logical; i--)
-	{
-		hdr.n[i] = hdr.n[i - 1];
-		lnum[i] = lnum[i - 1];
-	}
-	hdr.n[logical] = 0;
-	lnum[logical] = lnum[logical - 1];
-
-	/* adjust the cache */
-	for (i = 0; i < NBUFS; i++)
-	{
-		if (blk[i].logical >= logical)
-		{
-			blk[i].logical++;
-		}
-	}
-
-	/* return the new block, via blkget() */
-	return blkget(logical);
-}
-
-
-/* This function forces all dirty blocks out to disk */
-void blksync()
-{
-	int	i;
-
-	for (i = 0; i < NBUFS; i++)
-	{
-		/* blk[i].dirty = TRUE; */
-		blkflush(&blk[i]);
-	}
-	if (*o_sync)
-	{
-		sync();
-	}
-}
-
-/*------------------------------------------------------------------------*/
-
-static MARK	undocurs;	/* where the cursor should go if undone */
-static long	oldnlines;
-static long	oldlnum[MAXBLKS];
-
-
-/* This function should be called before each command that changes the text.
- * It defines the state that undo() will reset the file to.
- */
-void beforedo(forundo)
-	int		forundo;	/* boolean: is this for an undo? */
-{
-	REG int		i;
-	REG long	l;
-
-	/* if this is a nested call to beforedo, quit! Use larger context */
-	if (b4cnt++ > 0)
-	{
-		return;
-	}
-
-	/* force all block buffers to disk */
-	blksync();
-
-#ifndef NO_RECYCLE
-	/* perform garbage collection on blocks from tmp file */
-	garbage();
-#endif
-
-	/* force the header out to disk */
-	lseek(tmpfd, 0L, 0);
-	if (write(tmpfd, hdr.c, (unsigned)BLKSIZE) != BLKSIZE)
-	{
-		msg("Trouble writing header to tmp file ");
-	}
-
-	/* copy or swap oldnlines <--> nlines, oldlnum <--> lnum */
-	if (forundo)
-	{
-		for (i = 0; i < MAXBLKS; i++)
-		{
-			l = lnum[i];
-			lnum[i] = oldlnum[i];
-			oldlnum[i] = l;
-		}
-		l = nlines;
-		nlines = oldnlines;
-		oldnlines = l;
-	}
-	else
-	{
-		for (i = 0; i < MAXBLKS; i++)
-		{
-			oldlnum[i] = lnum[i];
-		}
-		oldnlines = nlines;
-	}
-
-	/* save the cursor position */
-	undocurs = cursor;
-
-	/* upon return, the calling function continues and makes changes... */
-}
-
-/* This function marks the end of a (nested?) change to the file */
-void afterdo()
-{
-	if (--b4cnt)
-	{
-		/* after abortdo(), b4cnt may decribe nested beforedo/afterdo
-		 * pairs incorrectly.  If it is decremented to often, then
-		 * keep b4cnt sane but don't do anything else.
-		 */
-		if (b4cnt < 0)
-			b4cnt = 0;
-
-		return;
-	}
-
-	/* make sure the cursor wasn't left stranded in deleted text */
-	if (markline(cursor) > nlines)
-	{
-		cursor = MARK_LAST;
-	}
-	/* NOTE: it is still possible that markidx(cursor) is after the
-	 * end of a line, so the Vi mode will have to take care of that
-	 * itself */
-
-	/* if a significant change has been made to this file, then set the
-	 * MODIFIED flag.
-	 */
-	if (significant)
-	{
-		setflag(file, MODIFIED);
-		setflag(file, UNDOABLE);
-	}	
-}
-
-/* This function cuts short the current set of changes.  It is called after
- * a SIGINT.
- */
-void abortdo()
-{
-	/* finish the operation immediately. */
-	if (b4cnt > 0)
-	{
-		b4cnt = 1;
-		afterdo();
-	}
-
-	/* in visual mode, the screen is probably screwed up */
-	if (mode == MODE_COLON)
-	{
-		mode = MODE_VI;
-	}
-	if (mode == MODE_VI)
-	{
-		redraw(MARK_UNSET, FALSE);
-	}
-}
-
-/* This function discards all changes made since the last call to beforedo() */
-int undo()
-{
-	BLK		oldhdr;
-
-	/* if beforedo() has never been run, fail */
-	if (!tstflag(file, UNDOABLE))
-	{
-		msg("You haven't modified this file yet.");
-		return FALSE;
-	}
-
-	/* read the old header form the tmp file */
-	lseek(tmpfd, 0L, 0);
-	if (read(tmpfd, oldhdr.c, (unsigned)BLKSIZE) != BLKSIZE)
-	{
-		msg("Trouble rereading the old header from tmp file");
-	}
-
-	/* "do" the changed version, so we can undo the "undo" */
-	cursor = undocurs;
-	beforedo(TRUE);
-	afterdo();
-
-	/* wipe out the block buffers - we can't assume they're correct */
-	blkinit();
-
-	/* use the old header -- and therefore the old text blocks */
-	hdr = oldhdr;
-
-	/* This is a change */
-	significant = TRUE;
-	changes++;
-
-	return TRUE;
-}
Index: trunk/minix/commands/elvis/build
===================================================================
--- trunk/minix/commands/elvis/build	(revision 9)
+++ 	(revision )
@@ -1,2 +1,0 @@
-#!/bin/sh
-make && make install
Index: trunk/minix/commands/elvis/cmd1.c
===================================================================
--- trunk/minix/commands/elvis/cmd1.c	(revision 9)
+++ 	(revision )
@@ -1,1774 +1,0 @@
-/* cmd1.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains some of the EX commands - mostly ones that deal with
- * files, options, etc. -- anything except text.
- */
-
-#include "config.h"
-#include "ctype.h"
-#include "vi.h"
-#include "regexp.h"
-
-#ifdef DEBUG
-/* print the selected lines with info on the blocks */
-/*ARGSUSED*/
-void cmd_debug(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	REG char	*scan;
-	REG long	l;
-	REG int		i;
-	int		len;
-
-	/* scan lnum[] to determine which block its in */
-	l = markline(frommark);
-	for (i = 1; l > lnum[i]; i++)
-	{
-	}
-
-	do
-	{
-		/* fetch text of the block containing that line */
-		scan = blkget(i)->c;
-
-		/* calculate its length */
-		if (scan[BLKSIZE - 1])
-		{
-			len = BLKSIZE;
-		}
-		else
-		{
-			len = strlen(scan);
-		}
-
-		/* print block stats */
-		msg("##### hdr[%d]=%d, lnum[%d-1]=%ld, lnum[%d]=%ld (%ld lines)",
-			i, hdr.n[i], i, lnum[i-1], i, lnum[i], lnum[i] - lnum[i - 1]);
-		msg("##### len=%d, buf=0x%lx, %sdirty",
-			len, scan, ((int *)scan)[MAXBLKS + 1] ? "" : "not ");
-		if (bang)
-		{
-			while (--len >= 0)
-			{
-				addch(*scan);
-				scan++;
-			}
-		}
-		exrefresh();
-
-		/* next block */
-		i++;
-	} while (i < MAXBLKS && lnum[i] && lnum[i - 1] < markline(tomark));
-}
-
-
-/* This function checks a lot of conditions to make sure they aren't screwy */
-/*ARGSUSED*/
-void cmd_validate(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	char	*scan;
-	int	i;
-	int	nlcnt;	/* used to count newlines */
-	int	len;	/* counts non-NUL characters */
-
-	/* check lnum[0] */
-	if (lnum[0] != 0L)
-	{
-		msg("lnum[0] = %ld", lnum[0]);
-	}
-
-	/* check each block */
-	for (i = 1; lnum[i] <= nlines; i++)
-	{
-		scan = blkget(i)->c;
-		if (scan[BLKSIZE - 1])
-		{
-			msg("block %d has no NUL at the end", i);
-		}
-		else
-		{
-			for (nlcnt = len = 0; *scan; scan++, len++)
-			{
-				if (*scan == '\n')
-				{
-					nlcnt++;
-				}
-			}
-			if (scan[-1] != '\n')
-			{
-				msg("block %d doesn't end with '\\n' (length %d)", i, len);
-			}
-			if (bang || nlcnt != lnum[i] - lnum[i - 1])
-			{
-				msg("block %d (line %ld?) has %d lines, but should have %ld",
-					i, lnum[i - 1] + 1L, nlcnt, lnum[i] - lnum[i - 1]);
-			}
-		}
-		exrefresh();
-	}
-
-	/* check lnum again */
-	if (lnum[i] != INFINITY)
-	{
-		msg("hdr.n[%d] = %d, but lnum[%d] = %ld",
-			i, hdr.n[i], i, lnum[i]);
-	}
-
-	msg("# = \"%s\", %% = \"%s\"", prevorig, origname);
-	msg("V_from=%ld.%d, cursor=%ld.%d", markline(V_from), markidx(V_from), markline(cursor), markidx(cursor));
-}
-#endif /* DEBUG */
-
-
-/*ARGSUSED*/
-void cmd_mark(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	/* validate the name of the mark */
-	if (*extra == '"')
-	{
-		extra++;
-	}
-	/* valid mark names are lowercase ascii characters */
-	if (!isascii(*extra) || !islower(*extra) || extra[1])
-	{
-		msg("Invalid mark name");
-		return;
-	}
-
-	mark[*extra - 'a'] = tomark;
-}
-
-/*ARGSUSED*/
-void cmd_write(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	int		fd;
-	int		append;	/* boolean: write in "append" mode? */
-	REG long	l;
-	REG char	*scan;
-	REG int		i;
-
-	/* if writing to a filter, then let filter() handle it */
-	if (*extra == '!')
-	{
-		filter(frommark, tomark, extra + 1, FALSE);
-		return;
-	}
-
-	/* if all lines are to be written, use tmpsave() */
-	if (frommark == MARK_FIRST && tomark == MARK_LAST && cmd == CMD_WRITE)
-	{
-		tmpsave(extra, bang);
-		return;
-	}
-
-	/* see if we're going to do this in append mode or not */
-	append = FALSE;
-	if (extra[0] == '>' && extra[1] == '>')
-	{
-		extra += 2;
-		append = TRUE;
-	}
-
-	/* either the file must not exist, or we must have a ! or be appending */
-	if (access(extra, 0) == 0 && !bang && !append)
-	{
-		msg("File already exists - Use :w! to overwrite");
-		return;
-	}
-
-	/* else do it line-by-line, like cmd_print() */
-	if (append)
-	{
-#ifdef O_APPEND
-		fd = open(extra, O_WRONLY|O_APPEND);
-#else
-		fd = open(extra, O_WRONLY);
-		if (fd >= 0)
-		{
-			lseek(fd, 0L, 2);
-		}
-#endif
-	}
-	else
-	{
-		fd = -1; /* so we know the file isn't open yet */
-	}
-
-	if (fd < 0)
-	{
-		fd = creat(extra, FILEPERMS);
-		if (fd < 0)
-		{
-			msg("Can't write to \"%s\"", extra);
-			return;
-		}
-	}
-	for (l = markline(frommark); l <= markline(tomark); l++)
-	{
-		/* get the next line */
-		scan = fetchline(l);
-		i = strlen(scan);
-		scan[i++] = '\n';
-
-		/* print the line */
-		if (twrite(fd, scan, i) < i)
-		{
-			msg("Write failed");
-			break;
-		}
-	}
-	rptlines = markline(tomark) - markline(frommark) + 1;
-	rptlabel = "written";
-	close(fd);
-}	
-
-
-/*ARGSUSED*/
-void cmd_shell(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	static char	prevextra[80];
-
-	/* special case: ":sh" means ":!sh" */
-	if (cmd == CMD_SHELL)
-	{
-		extra = o_shell;
-		frommark = tomark = 0L;
-	}
-
-	/* if extra is "!", substitute previous command */
-	if (*extra == '!')
-	{
-		if (!*prevextra)
-		{
-			msg("No previous shell command to substitute for '!'");
-			return;
-		}
-		extra = prevextra;
-	}
-	else if (cmd == CMD_BANG && strlen(extra) < sizeof(prevextra) - 1)
-	{
-		strcpy(prevextra, extra);
-	}
-
-	/* warn the user if the file hasn't been saved yet */
-	if (*o_warn && tstflag(file, MODIFIED))
-	{
-		if (mode == MODE_VI)
-		{
-			mode = MODE_COLON;
-		}
-		msg("Warning: \"%s\" has been modified but not yet saved", origname);
-	}
-
-	/* if no lines were specified, just run the command */
-	suspend_curses();
-	if (frommark == 0L)
-	{
-		system(extra);
-	}
-	else /* pipe lines from the file through the command */
-	{
-		filter(frommark, tomark, extra, TRUE);
-	}
-
-	/* resume curses quietly for MODE_EX, but noisily otherwise */
-	resume_curses(mode == MODE_EX);
-}
-
-
-/*ARGSUSED*/
-void cmd_global(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;	/* rest of the command line */
-{
-	char	*cmdptr;	/* the command from the command line */
-	char	cmdln[100];	/* copy of the command from the command line */
-	char	*line;		/* a line from the file */
-	long	l;		/* used as a counter to move through lines */
-	long	lqty;		/* quantity of lines to be scanned */
-	long	nchanged;	/* number of lines changed */
-	regexp	*re;		/* the compiled search expression */
-
-	/* can't nest global commands */
-	if (doingglobal)
-	{
-		msg("Can't nest global commands.");
-		rptlines = -1L;
-		return;
-	}
-
-	/* ":g! ..." is the same as ":v ..." */
-	if (bang)
-	{
-		cmd = CMD_VGLOBAL;
-	}
-
-	/* make sure we got a search pattern */
-	if (*extra != '/' && *extra != '?')
-	{
-		msg("Usage: %c /regular expression/ command", cmd == CMD_GLOBAL ? 'g' : 'v');
-		return;
-	}
-
-	/* parse & compile the search pattern */
-	cmdptr = parseptrn(extra);
-	if (!extra[1])
-	{
-		msg("Can't use empty regular expression with '%c' command", cmd == CMD_GLOBAL ? 'g' : 'v');
-		return;
-	}
-	re = regcomp(extra + 1);
-	if (!re)
-	{
-		/* regcomp found & described an error */
-		return;
-	}
-
-	/* for each line in the range */
-	doingglobal = TRUE;
-	ChangeText
-	{
-		/* NOTE: we have to go through the lines in a forward order,
-		 * otherwise "g/re/p" would look funny.  *BUT* for "g/re/d"
-		 * to work, simply adding 1 to the line# on each loop won't
-		 * work.  The solution: count lines relative to the end of
-		 * the file.  Think about it.
-		 */
-		for (l = nlines - markline(frommark),
-			lqty = markline(tomark) - markline(frommark) + 1L,
-			nchanged = 0L;
-		     lqty > 0 && nlines - l >= 0 && nchanged >= 0L;
-		     l--, lqty--)
-		{
-			/* fetch the line */
-			line = fetchline(nlines - l);
-
-			/* if it contains the search pattern... */
-			if ((!regexec(re, line, 1)) == (cmd != CMD_GLOBAL))
-			{
-				/* move the cursor to that line */
-				cursor = MARK_AT_LINE(nlines - l);
-
-				/* do the ex command (without mucking up
-				 * the original copy of the command line)
-				 */
-				strcpy(cmdln, cmdptr);
-				rptlines = 0L;
-				doexcmd(cmdln);
-				nchanged += rptlines;
-			}
-		}
-	}
-	doingglobal = FALSE;
-
-	/* free the regexp */
-	free(re);
-
-	/* Reporting...*/
-	rptlines = nchanged;
-}
-
-
-/*ARGSUSED*/
-void cmd_file(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-#ifndef CRUNCH
-	/* if we're given a new filename, use it as this file's name */
-	if (extra && *extra)
-	{
-		strcpy(origname, extra);
-		storename(origname);
-		setflag(file, NOTEDITED);
-	}
-#endif
-	if (cmd == CMD_FILE)
-	{
-#ifndef CRUNCH
-		msg("\"%s\" %s%s%s %ld lines,  line %ld [%ld%%]",
-#else
-		msg("\"%s\" %s%s %ld lines,  line %ld [%ld%%]",
-#endif
-			*origname ? origname : "[NO FILE]",
-			tstflag(file, MODIFIED) ? "[MODIFIED]" : "",
-#ifndef CRUNCH
-			tstflag(file, NOTEDITED) ?"[NOT EDITED]":"",
-#endif
-			tstflag(file, READONLY) ? "[READONLY]" : "",
-			nlines,
-			markline(frommark),
-			markline(frommark) * 100 / nlines);
-	}
-#ifndef CRUNCH
-	else if (markline(frommark) != markline(tomark))
-	{
-		msg("range \"%ld,%ld\" contains %ld lines",
-			markline(frommark),
-			markline(tomark),
-			markline(tomark) - markline(frommark) + 1L);
-	}
-#endif
-	else
-	{
-		msg("%ld", markline(frommark));
-	}
-}
-
-
-/*ARGSUSED*/
-void cmd_edit(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	long	line = 1L;	/* might be set to prevline */
-#ifndef CRUNCH
-	char	*init = (char *)0;
-#endif
-
-
-	/* if ":vi", then switch to visual mode, and if no file is named
-	 * then don't switch files.
-	 */
-	if (cmd == CMD_VISUAL)
-	{
-		mode = MODE_VI;
-		msg("");
-		if (!*extra)
-		{
-			return;
-		}
-	}
-
-	/* Editing previous file?  Then start at previous line */
-	if (!strcmp(extra, prevorig))
-	{
-		line = prevline;
-	}
-
-#ifndef CRUNCH
-	/* if we were given an explicit starting line, then start there */
-	if (*extra == '+')
-	{
-		for (init = ++extra; !isspace(*extra); extra++)
-		{
-		}
-		while (isspace(*extra))
-		{
-			*extra++ = '\0';
-		}
-		if (!*init)
-		{
-			init = "$";
-		}
-		if (!extra)
-		{
-			extra = origname;
-		}
-	}
-#endif /* not CRUNCH */
-
-	/* switch files */
-	if (tmpabort(bang))
-	{
-		tmpstart(extra);
-		if (line <= nlines && line >= 1L)
-		{
-			cursor = MARK_AT_LINE(line);
-		}
-#ifndef CRUNCH
-		if (init)
-		{
-			doexcmd(init);
-		}
-#endif
-	}
-	else
-	{
-		msg("Use edit! to abort changes, or w to save changes");
-
-		/* so we can say ":e!#" next time... */
-		strcpy(prevorig, extra);
-		prevline = 1L;
-	}
-}
-
-/* This code is also used for rewind -- GB */
-
-/*ARGSUSED*/
-void cmd_next(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	int	i, j;
-	char	*scan;
-
-	/* if extra stuff given, use ":args" to define a new args list */
-	if (cmd == CMD_NEXT && extra && *extra)
-	{
-		cmd_args(frommark, tomark, cmd, bang, extra);
-	}
-
-	/* move to the next arg */
-	if (cmd == CMD_NEXT)
-	{
-		i = argno + 1;
-	}
-	else if (cmd == CMD_PREVIOUS)
-	{
-		i = argno - 1;
-	}
-	else /* cmd == CMD_REWIND */
-	{
-		i = 0;
-	}	
-	if (i < 0 || i >= nargs)
-	{
-		msg("No %sfiles to edit", cmd == CMD_REWIND ? "" : "more ");
-		return;
-	}
-
-	/* find & isolate the name of the file to edit */
-	for (j = i, scan = args; j > 0; j--)
-	{
-		while(*scan++)
-		{
-		}
-	}
-
-	/* switch to the next file */
-	if (tmpabort(bang))
-	{
-		tmpstart(scan);
-		argno = i;
-	}
-	else
-	{
-		msg("Use :%s! to abort changes, or w to save changes",
-			cmd == CMD_NEXT ? "next" :
-			cmd == CMD_PREVIOUS ? "previous" :
-					"rewind");
-	}
-}
-
-/* also called from :wq -- always writes back in this case */
-
-/*ARGSUSED*/
-void cmd_xit(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	static long	whenwarned;	/* when the user was last warned of extra files */
-	int		oldflag;
-
-	/* if there are more files to edit, then warn user */
-	if (argno >= 0 && argno + 1 < nargs && whenwarned != changes && (!bang || cmd != CMD_QUIT))
-	{
-		msg("More files to edit -- Use \":n\" to go to next file");
-		whenwarned = changes;
-		return;
-	}
-
-	if (cmd == CMD_QUIT)
-	{
-		oldflag = *o_autowrite;
-		*o_autowrite = FALSE;
-		if (tmpabort(bang))
-		{
-			mode = MODE_QUIT;
-		}
-		else
-		{
-			msg("Use q! to abort changes, or wq to save changes");
-		}
-		*o_autowrite = oldflag;
-	}
-	else
-	{
-		/* else try to save this file */
-		oldflag = tstflag(file, MODIFIED);
-		if (cmd == CMD_WQUIT)
-			setflag(file, MODIFIED);
-		if (tmpend(bang))
-		{
-			mode = MODE_QUIT;
-		}
-		else
-		{
-			msg("Could not save file -- use quit! to abort changes, or w filename");
-		}
-		if (!oldflag)
-			clrflag(file, MODIFIED);
-	}
-}
-
-
-/*ARGSUSED*/
-void cmd_args(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	char	*scan;
-	int	col;
-	int	arg;
-	int	scrolled = FALSE;
-	int	width;
-
-	/* if no extra names given, or just current name, then report the args
-	 * we have now.
-	 */
-	if (!extra || !*extra)
-	{
-		/* empty args list? */
-		if (nargs == 1 && !*args)
-		{
-			return;
-		}
-
-		/* list the arguments */
-		for (scan = args, col = arg = 0;
-		     arg < nargs;
-		     scan += width + 1, col += width, arg++)
-		{
-			width = strlen(scan);
-			if (col + width >= COLS - 4)
-			{
-				addch('\n');
-				col = 0;
-				scrolled = TRUE;
-			}
-			else if (col > 0)
-			{
-				addch(' ');
-				col++;
-			}
-			if (arg == argno)
-			{
-				addch('[');
-				addstr(scan);
-				addch(']');
-				col += 2;
-			}
-			else
-			{
-				addstr(scan);
-			}
-		}
-
-		/* write a trailing newline */
-		if ((mode == MODE_EX || mode == MODE_COLON || scrolled) && col)
-		{
-			addch('\n');
-		}
-		exrefresh();	
-	}
-	else /* new args list given */
-	{
-		for (scan = args, nargs = 1; *extra; )
-		{
-			if (isspace(*extra))
-			{
-				*scan++ = '\0';
-				while (isspace(*extra))
-				{
-					extra++;
-				}
-				if (*extra)
-				{
-					nargs++;
-				}
-			}
-			else
-			{
-				*scan++ = *extra++;
-			}
-		}
-		*scan = '\0';
-
-		/* reset argno to before the first, so :next will go to first */
-		argno = -1;
-
-		if (nargs != 1)
-		{
-                        msg("%d files to edit", nargs);
-		}
-	}
-}
-
-
-/*ARGSUSED*/
-void cmd_cd(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	char	*getenv();
-
-#ifndef CRUNCH
-	/* if current file is modified, and no '!' was given, then error */
-	if (tstflag(file, MODIFIED) && !bang)
-	{
-		msg("File modified; use \"cd! %s\" to switch anyway", extra);
-	}
-#endif
-
-	/* default directory name is $HOME */
-	if (!*extra)
-	{
-		extra = getenv("HOME");
-		if (!extra)
-		{
-			msg("environment variable $HOME not set");
-			return;
-		}
-	}
-
-	/* go to the directory */
-	if (chdir(extra) < 0)
-	{
-		perror(extra);
-	}
-}
-
-
-/*ARGSUSED*/
-void cmd_map(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	char	*mapto;
-	char	*build, *scan;
-#ifndef NO_FKEY
-	static char *fnames[NFKEYS] =
-	{
-		"#10", "#1", "#2", "#3", "#4",
-		"#5", "#6", "#7", "#8", "#9",
-# ifndef NO_SHIFT_FKEY
-		"#10s", "#1s", "#2s", "#3s", "#4s",
-		"#5s", "#6s", "#7s", "#8s", "#9s",
-#  ifndef NO_CTRL_FKEY
-		"#10c", "#1c", "#2c", "#3c", "#4c",
-		"#5c", "#6c", "#7c", "#8c", "#9c",
-#   ifndef NO_ALT_FKEY
-		"#10a", "#1a", "#2a", "#3a", "#4a",
-		"#5a", "#6a", "#7a", "#8a", "#9a",
-#   endif
-#  endif
-# endif
-	};
-	int	key;
-#endif
-
-	/* "map" with no extra will dump the map table contents */
-	if (!*extra)
-	{
-#ifndef NO_ABBR
-		if (cmd == CMD_ABBR)
-		{
-			dumpkey(bang ? WHEN_EX|WHEN_VIINP|WHEN_VIREP : WHEN_VIINP|WHEN_VIREP, TRUE);
-		}
-		else
-#endif
-		{
-			dumpkey(bang ? WHEN_VIINP|WHEN_VIREP : WHEN_VICMD, FALSE);
-		}
-	}
-	else
-	{
-		/* "extra" is key to map, followed by what it maps to */
-
-		/* handle quoting inside the "raw" string */
-		for (build = mapto = extra;
-		     *mapto && (*mapto != ' ' && *mapto != '\t');
-		     *build++ = *mapto++)
-		{
-			if (*mapto == ctrl('V') && mapto[1])
-			{
-				mapto++;
-			}
-		}
-
-		/* skip whitespace, and mark the end of the "raw" string */
-		while ((*mapto == ' ' || *mapto == '\t'))
-		{
-			*mapto++ = '\0';
-		}
-		*build = '\0';
-
-		/* strip ^Vs from the "cooked" string */
-		for (scan = build = mapto; *scan; *build++ = *scan++)
-		{
-			if (*scan == ctrl('V') && scan[1])
-			{
-				scan++;
-			}
-		}
-		*build = '\0';
-
-#ifndef NO_FKEY
-		/* if the mapped string is '#' and a number, then assume
-		 * the user wanted that function key
-		 */
-		if (extra[0] == '#' && isdigit(extra[1]))
-		{
-			key = atoi(extra + 1) % 10;
-# ifndef NO_SHIFT_FKEY
-			build = extra + strlen(extra) - 1;
-			if (*build == 's')
-				key += 10;
-#  ifndef NO_CTRL_FKEY
-			else if (*build == 'c')
-				key += 20;
-#   ifndef NO_ALT_FKEY
-			else if (*build == 'a')
-				key += 30;
-#   endif
-#  endif
-# endif
-			if (FKEY[key])
-				mapkey(FKEY[key], mapto, bang ? WHEN_VIINP|WHEN_VIREP : WHEN_VICMD, fnames[key]);
-			else
-				msg("This terminal has no %s key", fnames[key]);
-		}
-		else
-#endif
-#ifndef NO_ABBR
-		if (cmd == CMD_ABBR || cmd == CMD_UNABBR)
-		{
-			mapkey(extra, mapto, bang ? WHEN_EX|WHEN_VIINP|WHEN_VIREP : WHEN_VIINP|WHEN_VIREP, "abbr");
-		}
-		else
-#endif
-		{
-			mapkey(extra, mapto, bang ? WHEN_VIINP|WHEN_VIREP : WHEN_VICMD, (char *)0);
-		}
-	}
-}
-
-
-/*ARGSUSED*/
-void cmd_set(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	if (!*extra)
-	{
-		dumpopts(FALSE);/* "FALSE" means "don't dump all" - only set */
-	}
-	else if (!strcmp(extra, "all"))
-	{
-		dumpopts(TRUE);	/* "TRUE" means "dump all" - even unset vars */
-	}
-	else
-	{
-		setopts(extra);
-
-		/* That option may have affected the appearence of text */
-		changes++;
-	}
-}
-
-/*ARGSUSED*/
-void cmd_tag(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	int	fd;	/* file descriptor used to read the file */
-	char	*scan;	/* used to scan through the tmpblk.c */
-#ifdef INTERNAL_TAGS
-	char	*cmp;	/* char of tag name we're comparing, or NULL */
-	char	*end;	/* marks the end of chars in tmpblk.c */
-#else
-	int	i;
-#endif
-#ifndef NO_MAGIC
-	char	wasmagic; /* preserves the original state of o_magic */
-#endif
-	static char prevtag[30];
-
-	/* if no tag is given, use the previous tag */
-	if (!extra || !*extra)
-	{
-		if (!*prevtag)
-		{
-			msg("No previous tag");
-			return;
-		}
-		extra = prevtag;
-	}
-	else
-	{
-		strncpy(prevtag, extra, sizeof prevtag);
-		prevtag[sizeof prevtag - 1] = '\0';
-	}
-
-#ifndef INTERNAL_TAGS
-	/* use "ref" to look up the tag info for this tag */
-	sprintf(tmpblk.c, "ref -t %s%s %s", (*origname ? "-f" : ""),origname, prevtag);
-	fd = rpipe(tmpblk.c, 0);
-	if (fd < 0)
-	{
-		msg("Can't run \"%s\"", tmpblk.c);
-		return;
-	}
-
-	/* try to read the tag info */
-	for (scan = tmpblk.c;
-	     (i = tread(fd, scan, scan - tmpblk.c + BLKSIZE)) > 0;
-	     scan += i)
-	{
-	}
-	*scan = '\0';
-
-	/* close the pipe.  abort if error */
-	if (rpclose(fd) != 0 || scan < tmpblk.c + 3)
-	{
-		msg("tag \"%s\" not found", extra);
-		return;
-	}
-
-#else /* use internal code to look up the tag */
-	/* open the tags file */
-	fd = open(TAGS, O_RDONLY);
-	if (fd < 0)
-	{
-		msg("No tags file");
-		return;
-	}
-
-	/* Hmmm... this would have been a lot easier with <stdio.h> */
-
-	/* find the line with our tag in it */
-	for(scan = end = tmpblk.c, cmp = extra; ; scan++)
-	{
-		/* read a block, if necessary */
-		if (scan >= end)
-		{
-			end = tmpblk.c + tread(fd, tmpblk.c, BLKSIZE);
-			scan = tmpblk.c;
-			if (scan >= end)
-			{
-				msg("tag \"%s\" not found", extra);
-				close(fd);
-				return;
-			}
-		}
-
-		/* if we're comparing, compare... */
-		if (cmp)
-		{
-			/* matched??? wow! */
-			if (!*cmp && *scan == '\t')
-			{
-				break;
-			}
-			if (*cmp++ != *scan)
-			{
-				/* failed! skip to newline */
-				cmp = (char *)0;
-			}
-		}
-
-		/* if we're skipping to newline, do it fast! */
-		if (!cmp)
-		{
-			while (scan < end && *scan != '\n')
-			{
-				scan++;
-			}
-			if (scan < end)
-			{
-				cmp = extra;
-			}
-		}
-	}
-
-	/* found it! get the rest of the line into memory */
-	for (cmp = tmpblk.c, scan++; scan < end && *scan != '\n'; )
-	{
-		*cmp++ = *scan++;
-	}
-	if (scan == end)
-	{
-		tread(fd, cmp, BLKSIZE - (int)(cmp - tmpblk.c));
-	}
-	else
-		*cmp = *scan;
-
-	/* we can close the tags file now */
-	close(fd);
-#endif /* INTERNAL_TAGS */
-
-	/* extract the filename from the line, and edit the file */
-	for (scan = tmpblk.c; *scan != '\t'; scan++)
-	{
-	}
-	*scan++ = '\0';
-	if (strcmp(origname, tmpblk.c) != 0)
-	{
-		if (!tmpabort(bang))
-		{
-			msg("Use :tag! to abort changes, or :w to save changes");
-			return;
-		}
-		tmpstart(tmpblk.c);
-	}
-
-	/* move to the desired line (or to line 1 if that fails) */
-#ifndef NO_MAGIC
-	wasmagic = *o_magic;
-	*o_magic = FALSE;
-#endif
-	cursor = MARK_FIRST;
-	linespec(scan, &cursor);
-	if (cursor == MARK_UNSET)
-	{
-		cursor = MARK_FIRST;
-		msg("Tag's address is out of date");
-	}
-#ifndef NO_MAGIC
-	*o_magic = wasmagic;
-#endif
-}
-
-
-
-
-
-/* describe this version of the program */
-/*ARGSUSED*/
-void cmd_version(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	msg("%s", VERSION);
-#ifdef CREDIT
-	msg("%s", CREDIT);
-#endif
-#ifdef CREDIT2
-	msg("%s", CREDIT2);
-#endif
-#ifdef COMPILED_BY
-	msg("Compiled by %s", COMPILED_BY);
-#endif
-#ifdef COPYING
-	msg("%s", COPYING);
-#endif
-}
-
-
-#ifndef NO_MKEXRC
-/* make a .exrc file which describes the current configuration */
-/*ARGSUSED*/
-void cmd_mkexrc(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	int	fd;
-
-	/* the default name for the .exrc file EXRC */
-	if (!*extra)
-	{
-		extra = EXRC;
-	}
-
-	/* create the .exrc file */
-	fd = creat(extra, FILEPERMS);
-	if (fd < 0)
-	{
-		msg("Couldn't create a new \"%s\" file", extra);
-		return;
-	}
-
-	/* save stuff */
-	saveopts(fd);
-	savemaps(fd, FALSE);
-#ifndef NO_ABBR
-	savemaps(fd, TRUE);
-#endif
-#ifndef NO_DIGRAPH
-	savedigs(fd);
-#endif
-#ifndef NO_COLOR
-	savecolor(fd);
-#endif
-
-	/* close the file */
-	close(fd);
-	msg("Configuration saved");
-}
-#endif
-
-#ifndef NO_DIGRAPH
-/*ARGSUSED*/
-void cmd_digraph(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	do_digraph(bang, extra);
-}
-#endif
-
-
-#ifndef NO_ERRLIST 
-static char	errfile[256];	/* the name of a file containing an error */
-static long	errline;	/* the line number for an error */
-static int	errfd = -2;	/* fd of the errlist file */
-
-/* This static function tries to parse an error message.
- *
- * For most compilers, the first word is taken to be the name of the erroneous
- * file, and the first number after that is taken to be the line number where
- * the error was detected.  The description of the error follows, possibly
- * preceded by an "error ... :" or "warning ... :" label which is skipped.
- *
- * For Coherent, error messages look like "line#: filename: message".
- *
- * For non-error lines, or unparsable error lines, this function returns NULL.
- * Normally, though, it alters errfile and errline, and returns a pointer to
- * the description.
- */
-static char *parse_errmsg(text)
-	REG char	*text;
-{
-	REG char	*cpy;
-	long		atol();
-# if COHERENT || TOS /* any Mark Williams compiler */
-	/* Get the line number.  If no line number, then ignore this line. */
-	errline = atol(text);
-	if (errline == 0L)
-		return (char *)0;
-
-	/* Skip to the start of the filename */
-	while (*text && *text++ != ':')
-	{
-	}
-	if (!*text++)
-		return (char *)0;
-
-	/* copy the filename to errfile */
-	for (cpy = errfile; *text && (*cpy++ = *text++) != ':'; )
-	{
-	}
-	if (!*text++)
-		return (char *)0;
-	cpy[-1] = '\0';
-
-	return text;
-# else /* not a Mark Williams compiler */
-	char		*errmsg;
-
-	/* the error message is the whole line, by default */
-	errmsg = text;
-
-	/* skip leading garbage */
-	while (*text && !isalnum(*text))
-	{
-		text++;
-	}
-
-	/* copy over the filename */
-	cpy = errfile;
-	while(isalnum(*text) || *text == '.')
-	{
-		*cpy++ = *text++;
-	}
-	*cpy = '\0';
-
-	/* ignore the name "Error" and filenames that contain a '/' */
-	if (*text == '/' || !*errfile || !strcmp(errfile + 1, "rror") || access(errfile, 0) < 0)
-	{
-		return (char *)0;
-	}
-
-	/* skip garbage between filename and line number */
-	while (*text && !isdigit(*text))
-	{
-		text++;
-	}
-
-	/* if the number is part of a larger word, then ignore this line */
-	if (*text && isalpha(text[-1]))
-	{
-		return (char *)0;
-	}
-
-	/* get the error line */
-	errline = 0L;
-	while (isdigit(*text))
-	{
-		errline *= 10;
-		errline += (*text - '0');
-		text++;
-	}
-
-	/* any line which lacks a filename or line number should be ignored */
-	if (!errfile[0] || !errline)
-	{
-		return (char *)0;
-	}
-
-	/* locate the beginning of the error description */
-	while (*text && !isspace(*text))
-	{
-		text++;
-	}
-	while (*text)
-	{
-#  ifndef CRUNCH
-		/* skip "error #:" and "warning #:" clauses */
-		if (!strncmp(text + 1, "rror ", 5)
-		 || !strncmp(text + 1, "arning ", 7)
-		 || !strncmp(text + 1, "atal error", 10))
-		{
-			do
-			{
-				text++;
-			} while (*text && *text != ':');
-			continue;
-		}
-#  endif
-
-		/* anything other than whitespace or a colon is important */
-		if (!isspace(*text) && *text != ':')
-		{
-			errmsg = text;
-			break;
-		}
-
-		/* else keep looking... */
-		text++;
-	}
-
-	return errmsg;
-# endif /* not COHERENT */
-}
-
-/*ARGSUSED*/
-void cmd_errlist(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	static long	endline;/* original number of lines in this file */
-	static long	offset;	/* offset of the next line in the errlist file */
-	int		i;
-	char		*errmsg;
-
-	/* if a new errlist file is named, open it */
-	if (extra && extra[0])
-	{
-		/* close the old one */
-		if (errfd >= 0)
-		{
-			close(errfd);
-		}
-
-		/* open the new one */
-		errfd = open(extra, O_RDONLY);
-		offset = 0L;
-		endline = nlines;
-	}
-	else if (errfd < 0)
-	{
-		/* open the default file */
-		errfd = open(ERRLIST, O_RDONLY);
-		offset = 0L;
-		endline = nlines;
-	}
-
-	/* do we have an errlist file now? */
-	if (errfd < 0)
-	{
-		msg("There is no errlist file");
-		beep();
-		return;
-	}
-
-	/* find the next error message in the file */
-	do
-	{
-		/* read the next line from the errlist */
-		lseek(errfd, offset, 0);
-		if (tread(errfd, tmpblk.c, (unsigned)BLKSIZE) <= 0)
-		{
-			msg("No more errors");
-			beep();
-			close(errfd);
-			errfd = -2;
-			return;
-		}
-		for (i = 0; tmpblk.c[i] != '\n'; i++)
-		{
-		}
-		tmpblk.c[i++] = 0;
-
-		/* look for an error message in the line */
-		errmsg = parse_errmsg(tmpblk.c);
-		if (!errmsg)
-		{
-			offset += i;
-		}
-
-	} while (!errmsg);
-
-	/* switch to the file containing the error, if this isn't it */
-	if (strcmp(origname, errfile))
-	{
-		if (!tmpabort(bang))
-		{
-			msg("Use :er! to abort changes, or :w to save changes");
-			beep();
-			return;
-		}
-		tmpstart(errfile);
-		endline = nlines;
-	}
-	else if (endline == 0L)
-	{
-		endline = nlines;
-	}
-
-	/* go to the line where the error was detected */
-	cursor = MARK_AT_LINE(errline + (nlines - endline));
-	if (cursor > MARK_LAST)
-	{
-		cursor = MARK_LAST;
-	}
-	if (mode == MODE_VI)
-	{
-		redraw(cursor, FALSE);
-	}
-
-	/* display the error message */
-#ifdef CRUNCH
-	msg("%.70s", errmsg);
-#else
-	if (nlines > endline)
-	{
-		msg("line %ld(+%ld): %.60s", errline, nlines - endline, errmsg);
-	}
-	else if (nlines < endline)
-	{
-		msg("line %ld(-%ld): %.60s", errline, endline - nlines, errmsg);
-	}
-	else
-	{
-		msg("line %ld: %.65s", errline, errmsg);
-	}
-#endif
-
-	/* remember where the NEXT error line will start */
-	offset += i;
-}
-
-
-/*ARGSUSED*/
-void cmd_make(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	BLK	buf;
-
-	/* if the file hasn't been saved, then complain unless ! */
-	if (tstflag(file, MODIFIED) && !bang)
-	{
-		msg("\"%s\" not saved yet", origname);
-		return;
-	}
-
-	/* build the command */
-	sprintf(buf.c, "%s %s %s%s", (cmd == CMD_CC ? o_cc : o_make), extra, REDIRECT, ERRLIST);
-	qaddstr(buf.c);
-	addch('\n');
-
-	/* close the old errlist file, if any */
-	if (errfd >= 0)
-	{
-		close(errfd);
-		errfd = -3;
-	}
-
-	/* run the command, with curses temporarily disabled */
-	suspend_curses();
-	system(buf.c);
-	resume_curses(mode == MODE_EX);
-	if (mode == MODE_COLON)
-		mode = MODE_VI;
-
-	/* run the "errlist" command */
-	cmd_errlist(MARK_UNSET, MARK_UNSET, cmd, bang, ERRLIST);
-}
-#endif
-
-
-
-#ifndef NO_COLOR
-
-/* figure out the number of text colors we use with this configuration */
-# ifndef NO_POPUP
-#  ifndef NO_VISIBLE
-#   define NCOLORS 7
-#  else
-#   define NCOLORS 6
-#  endif
-# else
-#  ifndef NO_VISIBLE
-#   define NCOLORS 6
-#  else
-#   define NCOLORS 5
-#  endif
-# endif
-
-/* the attribute bytes used in each of "when"s */
-static char bytes[NCOLORS];
-
-static struct
-{
-	char	*word;	/* a legal word */
-	int	type;	/* what type of word this is */
-	int	val;	/* some other value */
-}
-	words[] =
-{
-	{"normal",	1,	A_NORMAL},	/* all "when" names must come */
-	{"standout",	1,	A_STANDOUT},	/* at the top of the list.    */
-	{"bold",	1,	A_BOLD},	/* The first 3 must be normal,*/
-	{"underlined",	1,	A_UNDERLINE},	/* standout, and bold; the    */
-	{"italics",	1,	A_ALTCHARSET},	/* remaining names follow.    */
-#ifndef NO_POPUP
-	{"popup",	1,	A_POPUP},
-#endif
-#ifndef NO_VISIBLE
-	{"visible",	1,	A_VISIBLE},
-#endif
-
-	{"black",	3,	0x00},		/* The color names start right*/
-	{"blue",	3,	0x01},		/* after the "when" names.    */
-	{"green",	3,	0x02},
-	{"cyan",	3,	0x03},
-	{"red",		3,	0x04},
-	{"magenta",	3,	0x05},
-	{"brown",	3,	0x06},
-	{"white",	3,	0x07},
-	{"yellow",	3,	0x0E}, /* bright brown */
-	{"gray",	3,	0x08}, /* bright black?  of course! */
-	{"grey",	3,	0x08},
-
-	{"bright",	2,	0x08},
-	{"light",	2,	0x08},
-	{"blinking",	2,	0x80},
-	{"on",		0,	0},
-	{"n",		1,	A_NORMAL},
-	{"s",		1,	A_STANDOUT},
-	{"b",		1,	A_BOLD},
-	{"u",		1,	A_UNDERLINE},
-	{"i",		1,	A_ALTCHARSET},
-#ifndef NO_POPUP
-	{"p",		1,	A_POPUP},
-	{"menu",	1,	A_POPUP},
-#endif
-#ifndef NO_VISIBLE
-	{"v",		1,	A_VISIBLE},
-#endif
-	{(char *)0,	0,	0}
-};
-
-/*ARGSUSED*/
-void cmd_color(frommark, tomark, cmd, bang, extra)
-	MARK	frommark, tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	int	attrbyte;
-	int	cmode;
-	int	nowbg;	/* BOOLEAN: is the next color background? */
-
-	REG char *scan;
-	REG	i;
-
-
-#ifndef CRUNCH
-	/* if no args are given, then report the current colors */
-	if (!*extra)
-	{
-		/* if no colors are set, then say so */
-		if (!bytes[0])
-		{
-			msg("no colors have been set");
-			return;
-		}
-
-		/* report all five color combinations */
-		for (i = 0; i < NCOLORS; i++)
-		{
-			qaddstr("color ");
-			qaddstr(words[i].word);
-			qaddch(' ');
-			if (bytes[i] & 0x80)
-				qaddstr("blinking ");
-			switch (bytes[i] & 0xf)
-			{
-			  case 0x08:	qaddstr("gray");	break;
-			  case 0x0e:	qaddstr("yellow");	break;
-			  case 0x0f:	qaddstr("bright white");break;
-			  default:
-				if (bytes[i] & 0x08)
-					qaddstr("light ");
-				qaddstr(words[(bytes[i] & 0x07) + NCOLORS].word);
-			}
-			qaddstr(" on ");
-			qaddstr(words[((bytes[i] >> 4) & 0x07) + NCOLORS].word);
-			addch('\n');
-			exrefresh();
-		}
-		return;
-	}
-#endif
-
-	/* The default background color is the same as "normal" chars.
-	 * There is no default foreground color.
-	 */
-	cmode = A_NORMAL;
-	attrbyte = bytes[0] & 0x70;
-	nowbg = FALSE;
-
-	/* parse each word in the "extra" text */
-	for (scan = extra; *extra; extra = scan)
-	{
-		/* locate the end of the word */
-		while (*scan && *scan != ' ')
-		{
-			scan++;
-		}
-
-		/* skip whitespace at the end of the word */
-		while(*scan == ' ')
-		{
-			*scan++ = '\0';
-		}
-
-		/* lookup the word */
-		for (i = 0; words[i].word && strcmp(words[i].word, extra); i++)
-		{
-		}
-
-		/* if not a word, then complain */
-		if (!words[i].word)
-		{
-			msg("Invalid color name: %s", extra);
-			return;
-		}
-
-		/* process the word */
-		switch (words[i].type)
-		{
-		  case 1:
-			cmode = words[i].val;
-			break;
-
-		  case 2:
-			attrbyte |= words[i].val;
-			break;
-
-		  case 3:
-			if (nowbg)
-				attrbyte = ((attrbyte & ~0x70) | ((words[i].val & 0x07) << 4));
-			else
-				attrbyte |= words[i].val;
-			nowbg = TRUE;
-			break;
-		}
-	}
-
-	/* if nowbg isn't set now, then we were never given a foreground color */
-	if (!nowbg)
-	{
-		msg("usage: color [when] [\"bright\"] [\"blinking\"] foreground [background]");
-		return;
-	}
-
-	/* the first ":color" command MUST define the "normal" colors */
-	if (!bytes[0])
-		cmode = A_NORMAL;
-
-	/* we should now have a cmode and an attribute byte... */
-
-	/* set the color */
-	setcolor(cmode, attrbyte);
-
-	/* remember what we just did */
-	bytes[cmode] = attrbyte;
-
-	/* if the other colors haven't been set yet, then set them to defaults */
-	if (!bytes[1])
-	{
-		/* standout is the opposite of normal */
-		bytes[1] = ((attrbyte << 4) & 0x70 | (attrbyte >> 4) & 0x07);
-		setcolor(A_STANDOUT, bytes[1]);
-
-		/* if "normal" isn't bright, then bold defaults to normal+bright
-		 * else bold defaults to bright white.
-		 */
-		bytes[2] = attrbyte | ((attrbyte & 0x08) ? 0x0f : 0x08);
-		setcolor(A_BOLD, bytes[2]);
-
-		/* all others default to the "standout" colors, without blinking */
-		for (i = 3; i < NCOLORS; i++)
-		{
-			bytes[i] = (bytes[1] & 0x7f);
-			setcolor(words[i].val, bytes[i]);
-		}
-	}
-
-	/* force a redraw, so we see the new colors */
-	redraw(MARK_UNSET, FALSE);
-}
-
-
-
-void savecolor(fd)
-	int	fd;	/* file descriptor to write colors to */
-{
-	int	i;
-	char	buf[80];
-
-	/* if no colors are set, then return */
-	if (!bytes[0])
-	{
-		return;
-	}
-
-	/* save all five color combinations */
-	for (i = 0; i < NCOLORS; i++)
-	{
-		strcpy(buf, "color ");
-		strcat(buf, words[i].word);
-		strcat(buf, " ");
-		if (bytes[i] & 0x80)
-			strcat(buf, "blinking ");
-		switch (bytes[i] & 0xf)
-		{
-		  case 0x08:	strcat(buf, "gray");	break;
-		  case 0x0e:	strcat(buf, "yellow");	break;
-		  case 0x0f:	strcat(buf, "bright white");break;
-		  default:
-			if (bytes[i] & 0x08)
-				strcat(buf, "light ");
-			strcat(buf, words[(bytes[i] & 0x07) + NCOLORS].word);
-		}
-		strcat(buf, " on ");
-		strcat(buf, words[((bytes[i] >> 4) & 0x07) + NCOLORS].word);
-		strcat(buf, "\n");
-		twrite(fd, buf, (unsigned)strlen(buf));
-	}
-}
-#endif
-
-#ifdef SIGTSTP
-/* temporarily suspend elvis */
-/*ARGSUSED*/
-void cmd_suspend(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	void	(*func)();	/* stores the previous setting of SIGTSTP */
-
-#if ANY_UNIX
-	/* the Bourne shell can't handle ^Z */
-	if (!strcmp(o_shell, "/bin/sh"))
-	{
-		msg("The /bin/sh shell doesn't support ^Z");
-		return;
-	}
-#endif
-
-	move(LINES - 1, 0);
-	if (tstflag(file, MODIFIED))
-	{
-		addstr("Warning: \"");
-		addstr(origname);
-		addstr("\" modified but not yet saved");
-		clrtoeol();
-	}
-	refresh();
-	suspend_curses();
-	func = signal(SIGTSTP, SIG_DFL);
-	kill (0, SIGTSTP);
-
-	/* the process stops and resumes here */
-
-	signal(SIGTSTP, func);
-	resume_curses(TRUE);
-	if (mode == MODE_VI || mode == MODE_COLON)
-		redraw(MARK_UNSET, FALSE);
-	else
-		refresh ();
-}
-#endif
Index: trunk/minix/commands/elvis/cmd2.c
===================================================================
--- trunk/minix/commands/elvis/cmd2.c	(revision 9)
+++ 	(revision )
@@ -1,942 +1,0 @@
-/* cmd2.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains some of the commands - mostly ones that change text */
-
-#include "config.h"
-#include "ctype.h"
-#include "vi.h"
-#include "regexp.h"
-#if TOS
-# include <stat.h>
-#else
-# if OSK
-#  include "osk.h"
-# else
-#  if AMIGA
-#   include "amistat.h"
-#  else
-#   include <sys/stat.h>
-#  endif
-# endif
-#endif
-
-
-/*ARGSUSED*/
-void cmd_substitute(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;	/* rest of the command line */
-{
-	char	*line;	/* a line from the file */
-	regexp	*re;	/* the compiled search expression */
-	char	*subst;	/* the substitution string */
-	char	*opt;	/* substitution options */
-	long	l;	/* a line number */
-	char	*s, *d;	/* used during subtitutions */
-	char	*conf;	/* used during confirmation */
-	long	chline;	/* # of lines changed */
-	long	chsub;	/* # of substitutions made */
-	static	optp;	/* boolean option: print when done? */
-	static	optg;	/* boolean option: substitute globally in line? */
-	static	optc;	/* boolean option: confirm before subst? */
-#ifndef CRUNCH
-	long	oldnlines;
-#endif
-
-
-	/* for now, assume this will fail */
-	rptlines = -1L;
-
-	if (cmd == CMD_SUBAGAIN)
-	{
-#ifndef NO_MAGIC
-		if (*o_magic)
-			subst = "~";
-		else
-#endif
-		subst = "\\~";
-		re = regcomp("");
-
-		/* if visual "&", then turn off the "p" and "c" options */
-		if (bang)
-		{
-			optp = optc = FALSE;
-		}
-	}
-	else /* CMD_SUBSTITUTE */
-	{
-		/* make sure we got a search pattern */
-		if (*extra != '/' && *extra != '?')
-		{
-			msg("Usage: s/regular expression/new text/");
-			return;
-		}
-
-		/* parse & compile the search pattern */
-		subst = parseptrn(extra);
-		re = regcomp(extra + 1);
-	}
-
-	/* abort if RE error -- error message already given by regcomp() */
-	if (!re)
-	{
-		return;
-	}
-
-	if (cmd == CMD_SUBSTITUTE)
-	{
-		/* parse the substitution string & find the option string */
-		for (opt = subst; *opt && *opt != *extra; opt++)
-		{
-			if (*opt == '\\' && opt[1])
-			{
-				opt++;
-			}
-		}
-		if (*opt)
-		{
-			*opt++ = '\0';
-		}
-
-		/* analyse the option string */
-		if (!*o_edcompatible)
-		{
-			optp = optg = optc = FALSE;
-		}
-		while (*opt)
-		{
-			switch (*opt++)
-			{
-			  case 'p':	optp = !optp;	break;
-			  case 'g':	optg = !optg;	break;
-			  case 'c':	optc = !optc;	break;
-			  case ' ':
-			  case '\t':			break;
-			  default:
-				msg("Subst options are p, c, and g -- not %c", opt[-1]);
-				return;
-			}
-		}
-	}
-
-	/* if "c" or "p" flag was given, and we're in visual mode, then NEWLINE */
-	if ((optc || optp) && mode == MODE_VI)
-	{
-		addch('\n');
-		exrefresh();
-	}
-
-	ChangeText
-	{
-		/* reset the change counters */
-		chline = chsub = 0L;
-
-		/* for each selected line */
-		for (l = markline(frommark); l <= markline(tomark); l++)
-		{
-			/* fetch the line */
-			line = fetchline(l);
-
-			/* if it contains the search pattern... */
-			if (regexec(re, line, TRUE))
-			{
-				/* increment the line change counter */
-				chline++;
-
-				/* initialize the pointers */
-				s = line;
-				d = tmpblk.c;
-
-				/* do once or globally ... */
-				do
-				{
-#ifndef CRUNCH
-					/* confirm, if necessary */
-					if (optc)
-					{
-						for (conf = line; conf < re->startp[0]; conf++)
-							addch(*conf);
-						standout();
-						for ( ; conf < re->endp[0]; conf++)
-							addch(*conf);
-						standend();
-						for (; *conf; conf++)
-							addch(*conf);
-						addch('\n');
-						exrefresh();
-						if (getkey(0) != 'y')
-						{
-							/* copy accross the original chars */
-							while (s < re->endp[0])
-								*d++ = *s++;
-
-							/* skip to next match on this line, if any */
-							goto Continue;
-						}
-					}
-#endif /* not CRUNCH */
-
-					/* increment the substitution change counter */
-					chsub++;
-
-					/* copy stuff from before the match */
-					while (s < re->startp[0])
-					{
-						*d++ = *s++;
-					}
-
-					/* substitute for the matched part */
-					regsub(re, subst, d);
-					s = re->endp[0];
-					d += strlen(d);
-
-Continue:
-					/* if this regexp could conceivably match
-					 * a zero-length string, then require at
-					 * least 1 unmatched character between
-					 * matches.
-					 */
-					if (re->minlen == 0)
-					{
-						if (!*s)
-							break;
-						*d++ = *s++;
-					}
-
-				} while (optg && regexec(re, s, FALSE));
-
-				/* copy stuff from after the match */
-				while (*d++ = *s++)	/* yes, ASSIGNMENT! */
-				{
-				}
-
-#ifndef CRUNCH
-				/* NOTE: since the substitution text is allowed to have ^Ms which are
-				 * translated into newlines, it is possible that the number of lines
-				 * in the file will increase after each line has been substituted.
-				 * we need to adjust for this.
-				 */
-				oldnlines = nlines;
-#endif
-
-				/* replace the old version of the line with the new */
-				d[-1] = '\n';
-				d[0] = '\0';
-				change(MARK_AT_LINE(l), MARK_AT_LINE(l + 1), tmpblk.c);
-
-#ifndef CRUNCH
-				l += nlines - oldnlines;
-				tomark += MARK_AT_LINE(nlines - oldnlines);
-#endif
-
-				/* if supposed to print it, do so */
-				if (optp)
-				{
-					addstr(tmpblk.c);
-					exrefresh();
-				}
-
-				/* move the cursor to that line */
-				cursor = MARK_AT_LINE(l);
-			}
-		}
-	}
-
-	/* free the regexp */
-	free(re);
-
-	/* if done from within a ":g" command, then finish silently */
-	if (doingglobal)
-	{
-		rptlines = chline;
-		rptlabel = "changed";
-		return;
-	}
-
-	/* Reporting */
-	if (chsub == 0)
-	{
-		msg("Substitution failed");
-	}
-	else if (chline >= *o_report)
-	{
-		msg("%ld substitutions on %ld lines", chsub, chline);
-	}
-	rptlines = 0L;
-}
-
-
-
-
-/*ARGSUSED*/
-void cmd_delete(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	MARK	curs2;	/* an altered form of the cursor */
-
-	/* choose your cut buffer */
-	if (*extra == '"')
-	{
-		extra++;
-	}
-	if (*extra)
-	{
-		cutname(*extra);
-	}
-
-	/* make sure we're talking about whole lines here */
-	frommark = frommark & ~(BLKSIZE - 1);
-	tomark = (tomark & ~(BLKSIZE - 1)) + BLKSIZE;
-
-	/* yank the lines */
-	cut(frommark, tomark);
-
-	/* if CMD_DELETE then delete the lines */
-	if (cmd != CMD_YANK)
-	{
-		curs2 = cursor;
-		ChangeText
-		{
-			/* delete the lines */
-			delete(frommark, tomark);
-		}
-		if (curs2 > tomark)
-		{
-			cursor = curs2 - tomark + frommark;
-		}
-		else if (curs2 > frommark)
-		{
-			cursor = frommark;
-		}
-	}
-}
-
-
-/*ARGSUSED*/
-void cmd_append(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	long	l;	/* line counter */
-
-#ifndef CRUNCH
-	/* if '!' then toggle auto-indent */
-	if (bang)
-	{
-		*o_autoindent = !*o_autoindent;
-	}
-#endif
-
-	ChangeText
-	{
-		/* if we're doing a change, delete the old version */
-		if (cmd == CMD_CHANGE)
-		{
-			/* delete 'em */
-			cmd_delete(frommark, tomark, cmd, bang, extra);
-		}
-
-		/* new lines start at the frommark line, or after it */
-		l = markline(frommark);
-		if (cmd == CMD_APPEND)
-		{
- 			l++;
-		}
-
-		/* get lines until no more lines, or "." line, and insert them */
-		while (vgets('\0', tmpblk.c, BLKSIZE) >= 0)
-		{
-			addch('\n');
-			if (!strcmp(tmpblk.c, "."))
-			{
-				break;
-			}
-
-			strcat(tmpblk.c, "\n");
-			add(MARK_AT_LINE(l), tmpblk.c);
-			l++;
-		}
-	}
-
-	/* on the odd chance that we're calling this from vi mode ... */
-	redraw(MARK_UNSET, FALSE);
-}
-
-
-/*ARGSUSED*/
-void cmd_put(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	/* choose your cut buffer */
-	if (*extra == '"')
-	{
-		extra++;
-	}
-	if (*extra)
-	{
-		cutname(*extra);
-	}
-
-	/* paste it */
-	ChangeText
-	{
-		cursor = paste(frommark, TRUE, FALSE);
-	}
-}
-
-
-/*ARGSUSED*/
-void cmd_join(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	long	l;
-	char	*scan;
-	int	len;	/* length of the new line */
-
-	/* if only one line is specified, assume the following one joins too */
-	if (markline(frommark) == nlines)
-	{
-		msg("Nothing to join with this line");
-		return;
-	}
-	if (markline(frommark) == markline(tomark))
-	{
-		tomark += BLKSIZE;
-	}
-
-	/* get the first line */
-	l = markline(frommark);
-	strcpy(tmpblk.c, fetchline(l));
-	len = strlen(tmpblk.c);
-
-	/* build the longer line */
-	while (++l <= markline(tomark))
-	{
-		/* get the next line */
-		scan = fetchline(l);
-
-		/* remove any leading whitespace */
-		while (*scan == '\t' || *scan == ' ')
-		{
-			scan++;
-		}
-
-		/* see if the line will fit */
-		if (strlen(scan) + len + 3 > BLKSIZE)
-		{
-			msg("Can't join -- the resulting line would be too long");
-			return;
-		}
-
-		/* catenate it, with a space (or two) in between */
-		if (!bang)
-		{
-			if (len >= 1)
-			{
-				if (tmpblk.c[len - 1] == '.'
-				 || tmpblk.c[len - 1] == '?'
-				 || tmpblk.c[len - 1] == '!')
-				{
-					 tmpblk.c[len++] = ' ';
-				}
-				tmpblk.c[len++] = ' ';
-			}
-		}
-		strcpy(tmpblk.c + len, scan);
-		len += strlen(scan);
-	}
-	tmpblk.c[len++] = '\n';
-	tmpblk.c[len] = '\0';
-
-	/* make the change */
-	ChangeText
-	{
-		frommark &= ~(BLKSIZE - 1);
-		tomark &= ~(BLKSIZE - 1);
-		tomark += BLKSIZE;
-		change(frommark, tomark, tmpblk.c);
-	}
-
-	/* Reporting... */
-	rptlines = markline(tomark) - markline(frommark) - 1L;
-	rptlabel = "joined";
-}
-
-
-
-/*ARGSUSED*/
-void cmd_shift(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	long	l;	/* line number counter */
-	int	oldidx;	/* number of chars previously used for indent */
-	int	newidx;	/* number of chars in the new indent string */
-	int	oldcol;	/* previous indent amount */
-	int	newcol;	/* new indent amount */
-	char	*text;	/* pointer to the old line's text */
-
-	ChangeText
-	{
-		/* for each line to shift... */
-		for (l = markline(frommark); l <= markline(tomark); l++)
-		{
-			/* get the line - ignore empty lines unless ! mode */
-			text = fetchline(l);
-			if (!*text && !bang)
-				continue;
-
-			/* calc oldidx and oldcol */
-			for (oldidx = 0, oldcol = 0;
-			     text[oldidx] == ' ' || text[oldidx] == '\t';
-			     oldidx++)
-			{
-				if (text[oldidx] == ' ')
-				{
-					oldcol += 1;
-				}
-				else
-				{
-					oldcol += *o_tabstop - (oldcol % *o_tabstop);
-				}
-			}
-
-			/* calc newcol */
-			if (cmd == CMD_SHIFTR)
-			{
-				newcol = oldcol + (*o_shiftwidth & 0xff);
-			}
-			else
-			{
-				newcol = oldcol - (*o_shiftwidth & 0xff);
-				if (newcol < 0)
-					newcol = 0;
-			}
-
-			/* if no change, then skip to next line */
-			if (oldcol == newcol)
-				continue;
-
-			/* build a new indent string */
-			newidx = 0;
-			if (*o_autotab)
-			{
-				while (newcol >= *o_tabstop)
-				{
-					tmpblk.c[newidx++] = '\t';
-					newcol -= *o_tabstop;
-				}
-			}
-			while (newcol > 0)
-			{
-				tmpblk.c[newidx++] = ' ';
-				newcol--;
-			}
-			tmpblk.c[newidx] = '\0';
-
-			/* change the old indent string into the new */
-			change(MARK_AT_LINE(l), MARK_AT_LINE(l) + oldidx, tmpblk.c);
-		}
-	}
-
-	/* Reporting... */
-	rptlines = markline(tomark) - markline(frommark) + 1L;
-	if (cmd == CMD_SHIFTR)
-	{
-		rptlabel = ">ed";
-	}
-	else
-	{
-		rptlabel = "<ed";
-	}
-}
-
-
-/*ARGSUSED*/
-void cmd_read(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	int	fd, rc;	/* used while reading from the file */
-	char	*scan;	/* used for finding NUL characters */
-	int	hadnul;	/* boolean: any NULs found? */
-	int	addnl;	/* boolean: forced to add newlines? */
-	int	len;	/* number of chars in current line */
-	long	lines;	/* number of lines in current block */
-	struct stat statb;
-
-	/* special case: if ":r !cmd" then let the filter() function do it */
-	if (extra[0] == '!')
-	{
-		filter(frommark, MARK_UNSET, extra + 1, TRUE);
-		return;
-	}
-
-	/* open the file */
-	fd = open(extra, O_RDONLY);
-	if (fd < 0)
-	{
-		msg("Can't open \"%s\"", extra);
-		return;
-	}
-
-#ifndef CRUNCH
-	if (stat(extra, &statb) < 0)
-	{
-		msg("Can't stat \"%s\"", extra);
-	}
-# if TOS
-	if (statb.st_mode & S_IJDIR)
-# else
-#  if OSK
-	if (statb.st_mode & S_IFDIR)
-#  else
-	if ((statb.st_mode & S_IFMT) != S_IFREG)
-#  endif
-# endif
-	{
-		msg("\"%s\" is not a regular file", extra);
-		return;
-	}
-#endif /* not CRUNCH */
-
-	/* get blocks from the file, and add them */
-	ChangeText
-	{
-		/* insertion starts at the line following frommark */
-		tomark = frommark = (frommark | (BLKSIZE - 1L)) + 1L;
-		len = 0;
-		hadnul = addnl = FALSE;
-
-		/* add an extra newline, so partial lines at the end of
-		 * the file don't trip us up
-		 */
-		add(tomark, "\n");
-
-		/* for each chunk of text... */
-		while ((rc = tread(fd, tmpblk.c, BLKSIZE - 1)) > 0)
-		{
-			/* count newlines, convert NULs, etc. ... */
-			for (lines = 0, scan = tmpblk.c; rc > 0; rc--, scan++)
-			{
-				/* break up long lines */
-				if (*scan != '\n' && len + 2 > BLKSIZE)
-				{
-					*scan = '\n';
-					addnl = TRUE;
-				}
-
-				/* protect against NUL chars in file */
-				if (!*scan)
-				{
-					*scan = 0x80;
-					hadnul = TRUE;
-				}
-
-				/* starting a new line? */
-				if (*scan == '\n')
-				{
-					/* reset length at newline */
-					len = 0;
-					lines++;
-				}
-				else
-				{
-					len++;
-				}
-			}
-
-			/* add the text */
-			*scan = '\0';
-			add(tomark, tmpblk.c);
-			tomark += MARK_AT_LINE(lines) + len - markidx(tomark);
-		}
-
-		/* if partial last line, then retain that first newline */
-		if (len > 0)
-		{
-			msg("Last line had no newline");
-			tomark += BLKSIZE; /* <- for the rptlines calc */
-		}
-		else /* delete that first newline */
-		{
-			delete(tomark, (tomark | (BLKSIZE - 1L)) + 1L);
-		}
-	}
-
-	/* close the file */
-	close(fd);
-
-	/* Reporting... */
-	rptlines = markline(tomark) - markline(frommark);
-	rptlabel = "read";
-	if (mode == MODE_EX)
-	{
-		cursor = (tomark & ~BLKSIZE) - BLKSIZE;
-	}
-	else
-	{
-		cursor = frommark;
-	}
-
-	if (addnl)
-		msg("Newlines were added to break up long lines");
-	if (hadnul)
-		msg("NULs were converted to 0x80");
-}
-
-
-
-/*ARGSUSED*/
-void cmd_undo(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	undo();
-}
-
-
-/* print the selected lines */
-/*ARGSUSED*/
-void cmd_print(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	REG char	*scan;
-	REG long	l;
-	REG int		col;
-
-	for (l = markline(frommark); l <= markline(tomark); l++)
-	{
-		/* display a line number, if CMD_NUMBER */
-		if (cmd == CMD_NUMBER)
-		{
-			sprintf(tmpblk.c, "%6ld  ", l);
-			qaddstr(tmpblk.c);
-			col = 8;
-		}
-		else
-		{
-			col = 0;
-		}
-
-		/* get the next line & display it */
-		for (scan = fetchline(l); *scan; scan++)
-		{
-			/* expand tabs to the proper width */
-			if (*scan == '\t' && cmd != CMD_LIST)
-			{
-				do
-				{
-					qaddch(' ');
-					col++;
-				} while (col % *o_tabstop != 0);
-			}
-			else if (*scan > 0 && *scan < ' ' || *scan == '\177')
-			{
-				qaddch('^');
-				qaddch(*scan ^ 0x40);
-				col += 2;
-			}
-			else if ((*scan & 0x80) && cmd == CMD_LIST)
-			{
-				sprintf(tmpblk.c, "\\%03o", UCHAR(*scan));
-				qaddstr(tmpblk.c);
-				col += 4;
-			}
-			else
-			{
-				qaddch(*scan);
-				col++;
-			}
-
-			/* wrap at the edge of the screen */
-			if (!has_AM && col >= COLS)
-			{
-				addch('\n');
-				col -= COLS;
-			}
-		}
-		if (cmd == CMD_LIST)
-		{
-			qaddch('$');
-		}
-		addch('\n');
-		exrefresh();
-	}
-}
-
-
-/* move or copy selected lines */
-/*ARGSUSED*/
-void cmd_move(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	MARK	destmark;
-
-	/* parse the destination linespec.  No defaults.  Line 0 is okay */
-	destmark = cursor;
-	if (!strcmp(extra, "0"))
-	{
-		destmark = 0L;
-	}
-	else if (linespec(extra, &destmark) == extra || !destmark)
-	{
-		msg("invalid destination address");
-		return;
-	}
-
-	/* flesh the marks out to encompass whole lines */
-	frommark &= ~(BLKSIZE - 1);
-	tomark = (tomark & ~(BLKSIZE - 1)) + BLKSIZE;
-	destmark = (destmark & ~(BLKSIZE - 1)) + BLKSIZE;
-
-	/* make sure the destination is valid */
-	if (cmd == CMD_MOVE && destmark >= frommark && destmark < tomark)
-	{
-		msg("invalid destination address");
-	}
-
-	/* Do it */
-	ChangeText
-	{
-		/* save the text to a cut buffer */
-		cutname('\0');
-		cut(frommark, tomark);
-
-		/* if we're not copying, delete the old text & adjust destmark */
-		if (cmd != CMD_COPY)
-		{
-			delete(frommark, tomark);
-			if (destmark >= frommark)
-			{
-				destmark -= (tomark - frommark);
-			}
-		}
-
-		/* add the new text */
-		paste(destmark, FALSE, FALSE);
-	}
-
-	/* move the cursor to the last line of the moved text */
-	cursor = destmark + (tomark - frommark) - BLKSIZE;
-	if (cursor < MARK_FIRST || cursor >= MARK_LAST + BLKSIZE)
-	{
-		cursor = MARK_LAST;
-	}
-
-	/* Reporting... */
-	rptlabel = ( (cmd == CMD_COPY) ? "copied" : "moved" );
-}
-
-
-
-/* execute EX commands from a file */
-/*ARGSUSED*/
-void cmd_source(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	/* must have a filename */
-	if (!*extra)
-	{
-		msg("\"source\" requires a filename");
-		return;
-	}
-
-	doexrc(extra);
-}
-
-
-#ifndef NO_AT
-/*ARGSUSED*/
-void cmd_at(frommark, tomark, cmd, bang, extra)
-	MARK	frommark;
-	MARK	tomark;
-	CMD	cmd;
-	int	bang;
-	char	*extra;
-{
-	static	nest = FALSE;
-	int	result;
-	char	buf[MAXRCLEN];
-
-	/* don't allow nested macros */
-	if (nest)
-	{
-		msg("@ macros can't be nested");
-		return;
-	}
-	nest = TRUE;
-
-	/* require a buffer name */
-	if (*extra == '"')
-		extra++;
-	if (!*extra || !isascii(*extra) ||!islower(*extra))
-	{
-		msg("@ requires a cut buffer name (a-z)");
-	}
-
-	/* get the contents of the buffer */
-	result = cb2str(*extra, buf, (unsigned)(sizeof buf));
-	if (result <= 0)
-	{
-		msg("buffer \"%c is empty", *extra);
-	}
-	else if (result >= sizeof buf)
-	{
-		msg("buffer \"%c is too large to execute", *extra);
-	}
-	else
-	{
-		/* execute the contents of the buffer as ex commands */
-		exstring(buf, result, '\\');
-	}
-
-	nest = FALSE;
-}
-#endif
Index: trunk/minix/commands/elvis/config.h
===================================================================
--- trunk/minix/commands/elvis/config.h	(revision 9)
+++ 	(revision )
@@ -1,525 +1,0 @@
-/*
- * vi configuration file
- * We try to automatically configure to various compilers and operating
- * systems. Extend the autoconf section as needed.
- */
-
-#ifndef _CONFIG_H
-# define _CONFIG_H
-
-/*************************** autoconf section ************************/
-
-/* Commodore-Amiga */
-#ifdef	amiga
-# define AMIGA		1
-# define COMPILED_BY	"Manx Aztec C 5.2b"
-#endif
-
-/* standard unix V (?) */
-#ifdef	M_SYSV
-# define UNIXV		1
-#endif
-
-/* xelos system, University of Ulm */
-#ifdef	xelos
-# define UNIXV		1
-#endif
-
-/* BSD UNIX? */
-#ifdef bsd
-# define BSD		1
-#else
-# ifdef sun
-#  define BSD		1
-# endif
-#endif
-
-/* Microsoft C: sorry, Watcom does the same thing */
-#ifdef	M_I86
-# ifndef M_SYSV
-#  define MSDOS		1
-#  ifdef IBMC2
-#   define COMPILED_BY	"IBM C/2 1.00"
-#  else
-#   define MICROSOFT	1
-#   define COMPILED_BY	"Microsoft C 5.10"
-#  endif
-# endif
-#endif
-
-/* Borland's Turbo C */
-#ifdef	__TURBOC__
-# define MSDOS		1
-# define TURBOC		1
-# ifdef __BORLANDC__
-# define COMPILED_BY	"Borland C 2.00"
-# else
-# define COMPILED_BY	(__TURBOC__ >= 661 ? "Turbo C++ 1.00" : "Turbo C 2.00")
-# endif
-#endif
-
-/* Tos Mark-Williams */
-#ifdef	M68000
-# define TOS 1
-# define COMPILED_BY	"Mark Williams C"
-#endif
-
-/* Tos GNU-C */
-#if defined(__atarist__) && defined(__gem__)
-# define TOS 1
-# define COMPILED_BY	"GNU-C " __VERSION__
-#endif
-
-/* OS9/68000 */
-#ifdef	OSK
-# define COMPILED_BY	"Microware C V2.3 Edition 40"
-#endif
-
-/* DEC Rainbow, running MS-DOS (handled by earlier MS-DOS tests) */
-/* (would need -DRAINBOW in CFLAGS to compile a Rainbow-compatible .EXE) */
-
-#ifdef VMS
-# define COMPILED_BY    "VAX/VMS VAXC compiler"
-# undef VMS
-# define VMS 1
-#endif
-
-/*************************** end of autoconf section ************************/
-
-/* All undefined symbols are defined to zero here, to allow for older    */
-/* compilers which dont understand #if defined() or #if UNDEFINED_SYMBOL */
-
-/*************************** operating systems *****************************/
- 
-#ifndef	BSD
-# define BSD	0		/* UNIX - Berkeley 4.x */
-#endif
-
-#ifndef	UNIXV
-# define UNIXV	0		/* UNIX - AT&T SYSV */
-#endif
-
-#ifndef	UNIX7
-# define UNIX7	0		/* UNIX - version 7 */
-#endif
-
-#ifndef	MSDOS
-# define MSDOS	0		/* PC		*/
-#endif
-
-#ifndef	TOS
-# define TOS	0		/* Atari ST	*/
-#endif
-
-#ifndef	AMIGA
-# define AMIGA	0		/* Commodore Amiga */
-#endif
-
-#ifndef OSK
-# define OSK	0		/* OS-9 / 68k */
-#endif
-
-#ifndef COHERENT
-# define COHERENT 0		/* Coherent */
-#endif
-
-#ifndef RAINBOW			/* DEC Rainbow support, under MS-DOS */
-# define RAINBOW 0
-#endif
-
-#ifndef VMS
-# define VMS 0                  /* VAX/VMS */
-#endif
-				/* Minix has no predefines */
-#if !BSD && !UNIXV && !UNIX7 && !MSDOS && !TOS && !AMIGA && !OSK && !COHERENT && !VMS
-# define MINIX	1
-#else
-# define MINIX	0
-#endif
-
-				/* generic combination of Unices */
-#if UNIXV || UNIX7 || BSD || MINIX || COHERENT
-# define ANY_UNIX 1
-#else
-# define ANY_UNIX 0
-#endif
-
-/*************************** compilers **************************************/
- 
-#ifndef	AZTEC_C
-# define AZTEC_C	0
-#endif
-
-#ifndef	MICROSOFT
-# define MICROSOFT	0
-#endif
-
-#ifndef	TURBOC
-# define TURBOC		0
-#endif
-
-/******************************* Credit ************************************/
-
-#if MSDOS
-# define CREDIT "Ported to MS-DOS by Guntram Blohm & Martin Patzel"
-# if RAINBOW
-#  define CREDIT2 "Rainbow support added by Willett Kempton"
-# endif
-#endif
-
-#if AMIGA
-# define CREDIT "Ported to AmigaDOS 2.04 by Mike Rieser & Dale Rahn"
-#endif
-
-#if TOS
-# define CREDIT "Ported to Atari/TOS by Guntram Blohm & Martin Patzel"
-#endif
-
-#if OSK
-# define CREDIT	"Ported to Microware OS9/68k by Peter Reinig"
-#endif
-
-#if COHERENT
-# define CREDIT	"Ported to Coherent by Esa Ahola"
-#endif
-
-#if VMS
-# define CREDIT "Ported to VAX/VMS by John Campbell"
-#endif
-/*************************** functions depending on OS *********************/
-
-/* There are two terminal-related functions that we need: ttyread() and
- * ttywrite().  The ttyread() function implements read-with-timeout and is
- * a true function on all systems.  The ttywrite() function is almost always
- * just a macro...
- */
-#if !TOS && !AMIGA
-# define ttywrite(buf, len)	write(1, buf, (unsigned)(len))	/* raw write */
-#endif
-
-/* The strchr() function is an official standard now, so everybody has it
- * except Unix version 7 (which is old) and BSD Unix (which is academic).
- * Those guys use something called index() to do the same thing.
- */
-#if BSD || UNIX7 || OSK
-# define strchr	index
-#endif
-extern char *strchr();
-
-/* BSD uses bcopy() instead of memcpy() */
-#if BSD
-# define memcpy(dest, src, siz)	bcopy(src, dest, siz)
-#endif
-
-/* BSD uses getwd() instead of getcwd().  The arguments are a little different,
- * but we'll ignore that and hope for the best; adding arguments to the macro
- * would mess up an "extern" declaration of the function.
- */
-#if BSD || COHERENT
-# define getcwd	getwd
-#endif
-extern char *getcwd();
-
-/* text versa binary mode for read/write */
-#if !TOS
-#define	tread(fd,buf,n)		read(fd,buf,(unsigned)(n))
-#define twrite(fd,buf,n)	write(fd,buf,(unsigned)(n))
-#endif
-
-/**************************** Compiler quirks *********************************/
-
-/* the UNIX version 7 and (some) TOS compilers, don't allow "void" */
-#if UNIX7 || TOS
-# define void int
-#endif
-
-/* as far as I know, all compilers except version 7 support unsigned char */
-/* NEWFLASH: the Minix-ST compiler has subtle problems with unsigned char */
-#if UNIX7 || MINIX
-# define UCHAR(c)	((c) & 0xff)
-# define uchar		char
-#else
-# define UCHAR(c)	((unsigned char)(c))
-# define uchar		unsigned char
-#endif
-
-/* Some compilers prefer to have malloc declared as returning a (void *) */
-#if BSD || AMIGA
-extern void *malloc();
-#else
-extern char *malloc();
-#endif
-
-/* everybody but Amiga wants lseek declared here */
-#if !AMIGA
-extern long lseek();
-#endif
-
-/******************* Names of files and environment vars **********************/
-
-#if ANY_UNIX
-# ifndef TMPDIR
-#  if MINIX
-#   define TMPDIR	"/tmp"
-#  endif
-# endif
-# ifndef PRSVDIR
-#  define PRSVDIR	"/usr/preserve"	/* directory where preserved file live */
-# endif
-# ifndef PRSVINDEX
-#  define PRSVINDEX	"/usr/preserve/Index" /* index of files in PRSVDIR */
-# endif
-# ifndef EXRC
-#  define EXRC		".exrc"		/* init file in current directory */
-# endif
-# define SCRATCHOUT	"%s/soXXXXXX"	/* temp file used as input to filter */
-# ifndef SHELL
-#  define SHELL		"/bin/sh"	/* default shell */
-# endif
-# if COHERENT
-#  ifndef REDIRECT
-#   define REDIRECT	">"		/* Coherent CC writes errors to stdout */
-#  endif
-# endif
-#endif
-
-#if AMIGA		/* Specify AMIGA environment */
-# ifndef CC_COMMAND
-#  define CC_COMMAND	"cc"		/* generic C compiler */
-# endif
-# ifndef COLON
-#  define COLON		':'		/* Amiga files can also end in `:' */
-# endif
-# ifndef SYSEXRC
-#  define SYSEXRC	"S:" EXRC	/* name of ".exrc" file in system dir */
-# endif
-# ifndef MAXRCLEN
-#  define MAXRCLEN	2048		/* max size of a .exrc file */
-# endif
-# ifndef NBUFS
-#  define NBUFS		10		/* must be at least 3 -- more is better */
-# endif
-# ifndef NEEDSYNC
-#  define NEEDSYNC	TRUE		/* assume ":se sync" by default */
-# endif
-# ifndef PRSVDIR
-#  define PRSVDIR	"Elvis:"	/* directory where preserved file live */
-# endif
-# ifndef PRSVINDEX
-#  define PRSVINDEX	"Elvis:Index"	/* index of files in PRSVDIR */
-# endif
-# ifndef REDIRECT
-#  define REDIRECT	">"		/* Amiga writes errors to stdout */
-# endif
-# ifndef SCRATCHIN
-#  define SCRATCHIN	"%sSIXXXXXX"
-# endif
-# ifndef SCRATCHOUT
-#  define SCRATCHOUT	"%sSOXXXXXX"
-# endif
-# ifndef SHELL
-#  define SHELL		"newshell"	/* default shell */
-# endif
-# ifndef TERMTYPE
-#  define TERMTYPE	"amiga"		/* default termtype */
-# endif
-# ifndef TMPDIR				/* for AMIGA should end in `:' or `/' */
-#  define TMPDIR	"T:"		/* directory where temp files live */
-# endif
-# ifndef TMPNAME
-#  define TMPNAME	"%selv_%x.%x"	/* format of names for temp files */
-# endif
-#endif
-
-#if MSDOS || TOS
-/* do not change TMPNAME and SCRATCH*: they MUST begin with '%s\\'! */
-# ifndef TMPDIR
-#  define TMPDIR	"C:\\tmp"	/* directory where temp files live */
-# endif
-# ifndef PRSVDIR
-#  define PRSVDIR	"C:\\preserve"	/* directory where preserved file live */
-# endif
-# ifndef PRSVINDEX
-#  define PRSVINDEX	"C:\\preserve\\Index" /* index of files in PRSVDIR */
-# endif
-# define TMPNAME	"%s\\elv_%x.%x" /* temp file */
-# if MSDOS
-#  if MICROSOFT
-#   define CC_COMMAND	"cl -c"		/* C compiler */
-#  else
-#   if __BORLANDC__  /* Borland C */
-#    define CC_COMMAND	"bcc"		/* C compiler */
-#   else
-#   if TURBOC        /* Turbo C */
-#    define CC_COMMAND	"tcc"		/* C compiler */
-#   endif	/* TURBOC */
-#   endif	/* BORLANDC */
-#  endif		/* MICROSOFT */
-# endif		/* MSDOS */
-# define SCRATCHIN	"%s\\siXXXXXX"	/* DOS ONLY - output of filter program */
-# define SCRATCHOUT	"%s\\soXXXXXX"	/* temp file used as input to filter */
-# define SLASH		'\\'
-# ifndef SHELL
-#  if TOS
-#   define SHELL	"shell.ttp"	/* default shell */
-#  else
-#   define SHELL	"command.com"	/* default shell */
-#  endif
-# endif
-# define NEEDSYNC	TRUE		/* assume ":se sync" by default */
-# if TOS && __GNUC__			/* probably on other systems, too */
-#  define REDIRECT	"2>"		/* GNUC reports on 2, others on 1 */
-#  define CC_COMMAND	"gcc -c"
-# else
-#  define REDIRECT	">"		/* shell's redirection of stderr */
-# endif
-#endif
-
-#if VMS
-/* do not change TMPNAME, and SCRATCH*: they MUST begin with '%s\\'! */
-# ifndef TMPDIR
-#  define TMPDIR        "sys$scratch:"  /* directory where temp files live */
-# endif
-# define TMPNAME        "%selv_%x.%x;1" /* temp file */
-# define SCRATCHIN      "%ssiXXXXXX"    /* DOS ONLY - output of filter program */
-# define SCRATCHOUT     "%ssoXXXXXX"    /* temp file used as input to filter */
-# define SLASH          '\:'  /* Worry point... jdc */
-# ifndef SHELL
-#   define SHELL        ""      /* default shell */
-# endif
-# define REDIRECT       ">"             /* shell's redirection of stderr */
-# define tread(fd,buf,n)  vms_read(fd,buf,(unsigned)(n))
-# define close vms_close
-# define lseek vms_lseek
-# define unlink vms_delete
-# define delete __delete   /* local routine conflicts w/VMS rtl routine. */
-# define rpipe vms_rpipe
-# define rpclose vms_rpclose
-# define ttyread vms_ttyread
-/* There is no sync() on vms */
-# define sync()
-/* jdc -- seems VMS external symbols are case insensitive */
-# define m_fWord m_fw_ord
-# define m_bWord m_bw_ord
-# define m_eWord m_ew_ord
-# define m_Nsrch m_n_srch
-# define m_Fch   m_f_ch
-# define m_Tch   m_t_ch
-# define v_Xchar v_x_char
-/* jdc -- also, braindead vms curses always found by linker. */
-# define LINES elvis_LINES
-# define COLS  elvis_COLS
-# define curscr elvis_curscr
-# define stdscr elvis_stdscr
-# define initscr elvis_initscr
-# define endwin  elvis_endwin
-# define wrefresh elvis_wrefresh
-#endif
-
-#if OSK
-# ifndef TMPDIR
-#  define TMPDIR	"/dd/tmp"	   /* directory where temp files live */
-# endif
-# ifndef PRSVDIR
-#  define PRSVDIR	"/dd/usr/preserve" /* directory where preserved file live */
-# endif
-# ifndef PRSVINDEX
-#  define PRSVINDEX	"/dd/usr/preserve/Index" /* index of files in PRSVDIR */
-# endif
-# ifndef CC_COMMAND
-#  define CC_COMMAND	"cc -r"		   /* name of the compiler */
-# endif
-# ifndef EXRC
-#  define EXRC		".exrc"		   /* init file in current directory */
-# endif
-# define SCRATCHOUT	"%s/soXXXXXX"	   /* temp file used as input to filter */
-# ifndef SHELL
-#  define SHELL		"shell"		   /* default shell */
-# endif
-# define FILEPERMS	(S_IREAD|S_IWRITE) /* file permissions used for creat() */
-# define REDIRECT	">>-"		   /* shell's redirection of stderr */
-# define sync()				   /* OS9 doesn't need a sync() */
-#endif
-
-#ifndef	TAGS
-# define TAGS		"tags"		/* name of the tags file */
-#endif
-
-#ifndef TMPNAME
-# define TMPNAME	"%s/elv_%x.%x"	/* format of names for temp files */
-#endif
-
-#ifndef EXINIT
-# define EXINIT		"EXINIT"	/* name of EXINIT environment variable */
-#endif
-
-#ifndef	EXRC
-# define EXRC		"elvis.rc"	/* name of ".exrc" file in current dir */
-#endif
-
-#ifndef HMEXRC
-# define HMEXRC		EXRC		/* name of ".exrc" file in home dir */
-#endif
-
-#ifndef	KEYWORDPRG
-# define KEYWORDPRG	"ref"
-#endif
-
-#ifndef	SCRATCHOUT
-# define SCRATCHIN	"%s/SIXXXXXX"
-# define SCRATCHOUT	"%s/SOXXXXXX"
-#endif
-
-#ifndef ERRLIST
-# define ERRLIST	"errlist"
-#endif
-
-#ifndef	SLASH
-# define SLASH		'/'
-#endif
-
-#ifndef SHELL
-# define SHELL		"shell"
-#endif
-
-#ifndef REG
-# define REG		register
-#endif
-
-#ifndef NEEDSYNC
-# define NEEDSYNC	FALSE
-#endif
-
-#ifndef FILEPERMS
-# define FILEPERMS	0666
-#endif
-
-#ifndef PRESERVE
-# define PRESERVE	"elvprsv"	/* name of the "preserve" program */
-#endif
-
-#ifndef CC_COMMAND
-# define CC_COMMAND	"cc -c"
-#endif
-
-#ifndef MAKE_COMMAND
-# define MAKE_COMMAND	"make"
-#endif
-
-#ifndef REDIRECT
-# define REDIRECT	"2>"
-#endif
-
-#ifndef BLKSIZE
-# ifdef CRUNCH
-#  define BLKSIZE	1024
-# else
-#  define BLKSIZE	2048
-# endif
-#endif
-
-#ifndef KEYBUFSIZE
-# define KEYBUFSIZE	1000
-#endif
-
-#endif  /* ndef _CONFIG_H */
Index: trunk/minix/commands/elvis/ctags.c
===================================================================
--- trunk/minix/commands/elvis/ctags.c	(revision 9)
+++ 	(revision )
@@ -1,819 +1,0 @@
-/* ctags.c */
-
-/* This is a reimplementation of the ctags(1) program.  It supports ANSI C,
- * and has heaps o' flags.  It is meant to be distributed with elvis.
- */
-
-#include <stdio.h>
-#include "config.h"
-#ifndef FALSE
-# define FALSE	0
-# define TRUE	1
-#endif
-#ifndef TAGS
-# define TAGS	"tags"
-#endif
-#ifndef REFS
-# define REFS	"refs"
-#endif
-#ifndef BLKSIZE
-# define BLKSIZE 1024
-#endif
-
-#include "ctype.c" /* yes, that really is the .c file, not the .h one. */
-
-/* -------------------------------------------------------------------------- */
-/* Some global variables */
-
-/* The following boolean variables are set according to command line flags */
-int	incl_static;	/* -s  include static tags */
-int	incl_types;	/* -t  include typedefs and structs */
-int	incl_vars;	/* -v  include variables */
-int	make_refs;	/* -r  generate a "refs" file */
-int	append_files;	/* -a  append to "tags" [and "refs"] files */
-
-/* The following are used for outputting to the "tags" and "refs" files */
-FILE	*tags;		/* used for writing to the "tags" file */
-FILE	*refs;		/* used for writing to the "refs" file */
-
-/* -------------------------------------------------------------------------- */
-/* These are used for reading a source file.  It keeps track of line numbers */
-char	*file_name;	/* name of the current file */
-FILE	*file_fp;	/* stream used for reading the file */
-long	file_lnum;	/* line number in the current file */
-long	file_seek;	/* fseek() offset to the start of current line */
-int	file_afternl;	/* boolean: was previous character a newline? */
-int	file_prevch;	/* a single character that was ungotten */
-int	file_header;	/* boolean: is the current file a header file? */
-
-/* This function opens a file, and resets the line counter.  If it fails, it
- * it will display an error message and leave the file_fp set to NULL.
- */
-void file_open(name)
-	char	*name;	/* name of file to be opened */
-{
-	/* if another file was already open, then close it */
-	if (file_fp)
-	{
-		fclose(file_fp);
-	}
-
-	/* try to open the file for reading.  The file must be opened in
-	 * "binary" mode because otherwise fseek() would misbehave under DOS.
-	 */
-#if MSDOS || TOS
-	file_fp = fopen(name, "rb");
-#else
-	file_fp = fopen(name, "r");
-#endif
-	if (!file_fp)
-	{
-		perror(name);
-	}
-
-	/* reset the name & line number */
-	file_name = name;
-	file_lnum = 0L;
-	file_seek = 0L;
-	file_afternl = TRUE;
-
-	/* determine whether this is a header file */
-	file_header = FALSE;
-	name += strlen(name) - 2;
-	if (name >= file_name && name[0] == '.' && (name[1] == 'h' || name[1] == 'H'))
-	{
-		file_header = TRUE;
-	}
-}
-
-/* This function reads a single character from the stream.  If the *previous*
- * character was a newline, then it also increments file_lnum and sets
- * file_offset.
- */
-int file_getc()
-{
-	int	ch;
-
-	/* if there is an ungotten character, then return it.  Don't do any
-	 * other processing on it, though, because we already did that the
-	 * first time it was read.
-	 */
-	if (file_prevch)
-	{
-		ch = file_prevch;
-		file_prevch = 0;
-		return ch;
-	}
-
-	/* if previous character was a newline, then we're starting a line */
-	if (file_afternl)
-	{
-		file_afternl = FALSE;
-		file_seek = ftell(file_fp);
-		file_lnum++;
-	}
-
-	/* Get a character.  If no file is open, then return EOF */
-	ch = (file_fp ? getc(file_fp) : EOF);
-
-	/* if it is a newline, then remember that fact */
-	if (ch == '\n')
-	{
-		file_afternl = TRUE;
-	}
-
-	/* return the character */
-	return ch;
-}
-
-/* This function ungets a character from the current source file */
-void file_ungetc(ch)
-	int	ch;	/* character to be ungotten */
-{
-	file_prevch = ch;
-}
-
-/* This function copies the current line out some other fp.  It has no effect
- * on the file_getc() function.  During copying, any '\' characters are doubled
- * and a leading '^' or trailing '$' is also quoted.  The newline character is
- * not copied.
- *
- * This is meant to be used when generating a tag line.
- */
-void file_copyline(seek, fp)
-	long	seek;	/* where the lines starts in the source file */
-	FILE	*fp;	/* the output stream to copy it to */
-{
-	long	oldseek;/* where the file's pointer was before we messed it up */
-	char	ch;	/* a single character from the file */
-	char	next;	/* the next character from this file */
-
-	/* go to the start of the line */
-	oldseek = ftell(file_fp);
-	fseek(file_fp, seek, 0);
-
-	/* if first character is '^', then emit \^ */
-	ch = getc(file_fp);
-	if (ch == '^')
-	{
-		putc('\\', fp);
-		putc('^', fp);
-		ch = getc(file_fp);
-	}
-
-	/* write everything up to, but not including, the newline */
-	while (ch != '\n')
-	{
-		/* preread the next character from this file */
-		next = getc(file_fp);
-
-		/* if character is '\', or a terminal '$', then quote it */
-		if (ch == '\\' || (ch == '$' && next == '\n'))
-		{
-			putc('\\', fp);
-		}
-		putc(ch, fp);
-
-		/* next character... */
-		ch = next;
-	}
-
-	/* seek back to the old position */
-	fseek(file_fp, oldseek, 0);
-}
-
-/* -------------------------------------------------------------------------- */
-/* This section handles preprocessor directives.  It strips out all of the
- * directives, and may emit a tag for #define directives.
- */
-
-int	cpp_afternl;	/* boolean: look for '#' character? */
-int	cpp_prevch;	/* an ungotten character, if any */
-int	cpp_refsok;	/* boolean: can we echo characters out to "refs"? */
-
-/* This function opens the file & resets variables */
-void cpp_open(name)
-	char	*name;	/* name of source file to be opened */
-{
-	/* use the lower-level file_open function to open the file */
-	file_open(name);
-
-	/* reset variables */
-	cpp_afternl = TRUE;
-	cpp_refsok = TRUE;
-}
-
-/* This function copies a character from the source file to the "refs" file */
-void cpp_echo(ch)
-	int	ch; /* the character to copy */
-{
-	static	wasnl;
-
-	/* echo non-EOF chars, unless not making "ref", or echo turned off */
-	if (ch != EOF && make_refs && cpp_refsok && !file_header)
-	{
-		/* try to avoid blank lines */
-		if (ch == '\n')
-		{
-			if (wasnl)
-			{
-				return;
-			}
-			wasnl = TRUE;
-		}
-		else
-		{
-			wasnl = FALSE;
-		}
-
-		/* add the character */
-		putc(ch, refs);
-	}
-}
-
-/* This function returns the next character which isn't part of a directive */
-int cpp_getc()
-{
-	static
-	int	ch;	/* the next input character */
-	char	*scan;
-
-	/* if we have an ungotten character, then return it */
-	if (cpp_prevch)
-	{
-		ch = cpp_prevch;
-		cpp_prevch = 0;
-		return ch;
-	}
-
-	/* Get a character from the file.  Return it if not special '#' */
-	ch = file_getc();
-	if (ch == '\n')
-	{
-		cpp_afternl = TRUE;
-		cpp_echo(ch);
-		return ch;
-	}
-	else if (ch != '#' || !cpp_afternl)
-	{
-		/* normal character.  Any non-whitespace should turn off afternl */
-		if (ch != ' ' && ch != '\t')
-		{
-			cpp_afternl = FALSE;
-		}
-		cpp_echo(ch);
-		return ch;
-	}
-
-	/* Yikes!  We found a directive */
-
-	/* see whether this is a #define line */
-	scan = " define ";
-	while (*scan)
-	{
-		if (*scan == ' ')
-		{
-			/* space character matches any whitespace */
-			do
-			{
-				ch = file_getc();
-			} while (ch == ' ' || ch == '\t');
-			file_ungetc(ch);
-		}
-		else
-		{
-			/* other characters should match exactly */
-			ch = file_getc();
-			if (ch != *scan)
-			{
-				file_ungetc(ch);
-				break;
-			}
-		}
-		scan++;
-	}
-
-	/* is this a #define line?  and should we generate a tag for it? */
-	if (!*scan && (file_header || incl_static))
-	{
-		/* if not a header, then this will be a static tag */
-		if (!file_header)
-		{
-			fputs(file_name, tags);
-			putc(':', tags);
-		}
-
-		/* output the tag name */
-		for (ch = file_getc(); isalnum(ch) || ch == '_'; ch = file_getc())
-		{
-			putc(ch, tags);
-		}
-
-		/* output a tab, the filename, another tab, and the line number */
-		fprintf(tags, "\t%s\t%ld\n", file_name, file_lnum);
-	}
-
-	/* skip to the end of the directive -- a newline that isn't preceded
-	 * by a '\' character.
-	 */
-	while (ch != EOF && ch != '\n')
-	{
-		if (ch == '\\')
-		{
-			ch = file_getc();
-		}
-		ch = file_getc();
-	}
-
-	/* return the newline that we found at the end of the directive */
-	cpp_echo(ch);
-	return ch;
-}
-
-/* This puts a character back into the input queue for the source file */
-cpp_ungetc(ch)
-	int	ch;	/* a character to be ungotten */
-{
-	cpp_prevch = ch;
-}
-
-
-/* -------------------------------------------------------------------------- */
-/* This is the lexical analyser.  It gets characters from the preprocessor,
- * and gives tokens to the parser.  Some special codes are...
- *   (deleted)  /*...* /	(comments)
- *   (deleted)	//...\n	(comments)
- *   (deleted)	(*	(parens used in complex declaration)
- *   (deleted)	[...]	(array subscript, when ... contains no ])
- *   (deleted)	struct	(intro to structure declaration)
- *   BODY	{...}	('{' can occur anywhere, '}' only at BOW if ... has '{')
- *   ARGS	(...{	(args of function, not extern or forward)
- *   ARGS	(...);	(args of an extern/forward function declaration)
- *   COMMA	,	(separate declarations that have same scope)
- *   SEMICOLON	;	(separate declarations that have different scope)
- *   SEMICOLON  =...;	(initializer)
- *   TYPEDEF	typedef	(the "typedef" keyword)
- *   STATIC	static	(the "static" keyword)
- *   STATIC	private	(the "static" keyword)
- *   STATIC	PRIVATE	(the "static" keyword)
- *   NAME	[a-z]+	(really any valid name that isn't reserved word)
- */
-
-/* #define EOF -1 */
-#define DELETED	  0
-#define BODY	  1
-#define ARGS	  2
-#define COMMA	  3
-#define SEMICOLON 4
-#define TYPEDEF   5
-#define STATIC	  6
-#define EXTERN	  7
-#define NAME	  8
-
-char	lex_name[BLKSIZE];	/* the name of a "NAME" token */
-long	lex_seek;		/* start of line that contains lex_name */
-
-lex_gettoken()
-{
-	int	ch;		/* a character from the preprocessor */
-	int	next;		/* the next character */
-	int	token;		/* the token that we'll return */
-	int	i;
-
-	/* loop until we get a token that isn't "DELETED" */
-	do
-	{
-		/* get the next character */
-		ch = cpp_getc();
-
-		/* process the character */
-		switch (ch)
-		{
-		  case ',':
-			token = COMMA;
-			break;
-
-		  case ';':
-			token = SEMICOLON;
-			break;
-
-		  case '/':
-			/* get the next character */
-			ch = cpp_getc();
-			switch (ch)
-			{
-			  case '*':	/* start of C comment */
-				ch = cpp_getc();
-				next = cpp_getc();
-				while (next != EOF && (ch != '*' || next != '/'))
-				{
-					ch = next;
-					next = cpp_getc();
-				}
-				break;
-
-			  case '/':	/* start of a C++ comment */
-				do
-				{
-					ch = cpp_getc();
-				} while (ch != '\n' && ch != EOF);
-				break;
-
-			  default:	/* some other slash */
-				cpp_ungetc(ch);
-			}
-			token = DELETED;
-			break;
-
-		  case '(':
-			ch = cpp_getc();
-			if (ch == '*')
-			{
-				token = DELETED;
-			}
-			else
-			{
-				next = cpp_getc();
-				while (ch != '{' && ch != EOF && (ch != ')' || next != ';'))/*}*/
-				{
-					ch = next;
-					next = cpp_getc();
-				}
-				if (ch == '{')/*}*/
-				{
-					cpp_ungetc(ch);
-				}
-				else if (next == ';')
-				{
-					cpp_ungetc(next);
-				}
-				token = ARGS;
-			}
-			break;
-
-		  case '{':/*}*/
-			/* don't send the next characters to "refs" */
-			cpp_refsok = FALSE;
-
-			/* skip ahead to closing '}', or to embedded '{' */
-			do
-			{
-				ch = cpp_getc();
-			} while (ch != '{' && ch != '}' && ch != EOF);
-
-			/* if has embedded '{', then skip to '}' in column 1 */
-			if (ch == '{') /*}*/
-			{
-				ch = cpp_getc();
-				next = cpp_getc();
-				while (ch != EOF && (ch != '\n' || next != '}'))/*{*/
-				{
-					ch = next;
-					next = cpp_getc();
-				}
-			}
-
-			/* resume "refs" processing */
-			cpp_refsok = TRUE;
-			cpp_echo('}');
-
-			token = BODY;
-			break;
-
-		  case '[':
-			/* skip to matching ']' */
-			do
-			{
-				ch = cpp_getc();
-			} while (ch != ']' && ch != EOF);
-			token = DELETED;
-			break;
-
-		  case '=':
-		  	/* skip to next ';' */
-			do
-			{
-				ch = cpp_getc();
-
-				/* leave array initializers out of "refs" */
-				if (ch == '{')
-				{
-					cpp_refsok = FALSE;
-				}
-			} while (ch != ';' && ch != EOF);
-
-			/* resume echoing to "refs" */
-			if (!cpp_refsok)
-			{
-				cpp_refsok = TRUE;
-				cpp_echo('}');
-				cpp_echo(';');
-			}
-			token = SEMICOLON;
-			break;
-
-		  case EOF:
-			token = EOF;
-			break;
-
-		  default:
-			/* is this the start of a name/keyword? */
-			if (isalpha(ch) || ch == '_')
-			{
-				/* collect the whole word */
-				lex_name[0] = ch;
-				for (i = 1, ch = cpp_getc();
-				     i < BLKSIZE - 1 && (isalnum(ch) || ch == '_');
-				     i++, ch = cpp_getc())
-				{
-					lex_name[i] = ch;
-				}
-				lex_name[i] = '\0';
-				cpp_ungetc(ch);
-
-				/* is it a reserved word? */
-				if (!strcmp(lex_name, "typedef"))
-				{
-					token = TYPEDEF;
-					lex_seek = -1L;
-				}
-				else if (!strcmp(lex_name, "static")
-				      || !strcmp(lex_name, "private")
-				      || !strcmp(lex_name, "PRIVATE"))
-				{
-					token = STATIC;
-					lex_seek = -1L;
-				}
-				else if (!strcmp(lex_name, "extern")
-				      || !strcmp(lex_name, "EXTERN")
-				      || !strcmp(lex_name, "FORWARD"))
-				{
-					token = EXTERN;
-					lex_seek = -1L;
-				}
-				else
-				{
-					token = NAME;
-					lex_seek = file_seek;
-				}
-			}
-			else /* not part of a name/keyword */
-			{
-				token = DELETED;
-			}
-
-		} /* end switch(ch) */
-
-	} while (token == DELETED);
-
-	return token;
-}
-
-/* -------------------------------------------------------------------------- */
-/* This is the parser.  It locates tag candidates, and then decides whether to
- * generate a tag for them.
- */
-
-/* This function generates a tag for the object in lex_name, whose tag line is
- * located at a given seek offset.
- */
-void maketag(scope, seek)
-	int	scope;	/* 0 if global, or STATIC if static */
-	long	seek;	/* the seek offset of the line */
-{
-	/* output the tagname and filename fields */
-	if (scope == EXTERN)
-	{
-		/* whoa!  we should *never* output a tag for "extern" decl */
-		return;
-	}
-	else if (scope == STATIC)
-	{
-		fprintf(tags, "%s:%s\t%s\t", file_name, lex_name, file_name);
-	}
-	else
-	{
-		fprintf(tags, "%s\t%s\t", lex_name, file_name);
-	}
-
-	/* output the target line */
-	putc('/', tags);
-	putc('^', tags);
-	file_copyline(seek, tags);
-	putc('$', tags);
-	putc('/', tags);
-	putc('\n', tags);
-}
-
-
-/* This function parses a source file, adding any tags that it finds */
-void ctags(name)
-	char	*name;	/* the name of a source file to be checked */
-{
-	int	prev;	/* the previous token from the source file */
-	int	token;	/* the current token from the source file */
-	int	scope;	/* normally 0, but could be a TYPEDEF or STATIC token */
-	int	gotname;/* boolean: does lex_name contain a tag candidate? */
-	long	tagseek;/* start of line that contains lex_name */
-
-	/* open the file */
-	cpp_open(name);
-
-	/* reset */
-	scope = 0;
-	gotname = FALSE;
-	token = SEMICOLON;
-
-	/* parse until the end of the file */
-	while (prev = token, (token = lex_gettoken()) != EOF)
-	{
-		/* scope keyword? */
-		if (token == TYPEDEF || token == STATIC || token == EXTERN)
-		{
-			scope = token;
-			gotname = FALSE;
-			continue;
-		}
-
-		/* name of a possible tag candidate? */
-		if (token == NAME)
-		{
-			tagseek = file_seek;
-			gotname = TRUE;
-			continue;
-		}
-
-		/* if NAME BODY, without ARGS, then NAME is a struct tag */
-		if (gotname && token == BODY && prev != ARGS)
-		{
-			gotname = FALSE;
-			
-			/* ignore if in typedef -- better name is coming soon */
-			if (scope == TYPEDEF)
-			{
-				continue;
-			}
-
-			/* generate a tag, if -t and maybe -s */
-			if (incl_types && (file_header || incl_static))
-			{
-				maketag(file_header ? 0 : STATIC, tagseek);
-			}
-		}
-
-		/* If NAME ARGS BODY, then NAME is a function */
-		if (gotname && prev == ARGS && token == BODY)
-		{
-			gotname = FALSE;
-			
-			/* generate a tag, maybe checking -s */
-			if (scope != STATIC || incl_static)
-			{
-				maketag(scope, tagseek);
-			}
-		}
-
-		/* If NAME SEMICOLON or NAME COMMA, then NAME is var/typedef */
-		if (gotname && (token == SEMICOLON || token == COMMA))
-		{
-			gotname = FALSE;
-
-			/* generate a tag, if -v/-t and maybe -s */
-			if (scope == TYPEDEF && incl_types && (file_header || incl_static)
-			 || scope == STATIC && incl_vars && incl_static
-			 || incl_vars)
-			{
-				/* a TYPEDEF outside of a header is STATIC */
-				if (scope == TYPEDEF && !file_header)
-				{
-					maketag(STATIC, tagseek);
-				}
-				else /* use whatever scope was declared */
-				{
-					maketag(scope, tagseek);
-				}
-			}
-		}
-
-		/* reset after a semicolon or ARGS BODY pair */
-		if (token == SEMICOLON || (prev == ARGS && token == BODY))
-		{
-			scope = 0;
-			gotname = FALSE;
-		}
-	}
-
-	/* The source file will be automatically closed */
-}
-
-/* -------------------------------------------------------------------------- */
-
-void usage()
-{
-	fprintf(stderr, "usage: ctags [flags] filenames...\n");
-	fprintf(stderr, "\t-s  include static functions\n");
-	fprintf(stderr, "\t-t  include typedefs\n");
-	fprintf(stderr, "\t-v  include variable declarations\n");
-	fprintf(stderr, "\t-r  generate a \"refs\" file, too\n");
-	fprintf(stderr, "\t-a  append to \"tags\", instead of overwriting\n");
-	exit(2);
-}
-
-
-
-#if AMIGA
-# include "amiwild.c"
-#endif
-
-#if VMS
-# include "vmswild.c"
-#endif
-
-main(argc, argv)
-	int	argc;
-	char	**argv;
-{
-	int	i, j;
-
-#if MSDOS || TOS
-	char	**wildexpand();
-	argv = wildexpand(&argc, argv);
-#endif
-
-	/* build the tables used by the ctype macros */
-	_ct_init("");
-
-	/* parse the option flags */
-	for (i = 1; i < argc && argv[i][0] == '-'; i++)
-	{
-		for (j = 1; argv[i][j]; j++)
-		{
-			switch (argv[i][j])
-			{
-			  case 's':	incl_static = TRUE;	break;
-			  case 't':	incl_types = TRUE;	break;
-			  case 'v':	incl_vars = TRUE;	break;
-			  case 'r':	make_refs = TRUE;	break;
-			  case 'a':	append_files = TRUE;	break;
-			  default:	usage();
-			}
-		}
-	}
-
-	/* There should always be at least one source file named in args */
-	if (i == argc)
-	{
-		usage();
-	}
-
-	/* open the "tags" and maybe "refs" files */
-	tags = fopen(TAGS, append_files ? "a" : "w");
-	if (!tags)
-	{
-		perror(TAGS);
-		exit(3);
-	}
-	if (make_refs)
-	{
-		refs = fopen(REFS, append_files ? "a" : "w");
-		if (!refs)
-		{
-			perror(REFS);
-			exit(4);
-		}
-	}
-
-	/* parse each source file */
-	for (; i < argc; i++)
-	{
-		ctags(argv[i]);
-	}
-
-	/* close "tags" and maybe "refs" */
-	fclose(tags);
-	if (make_refs)
-	{
-		fclose(refs);
-	}
-
-#ifdef SORT
-		/* This is a hack which will sort the tags list.   It should
-		 * on UNIX and OS-9.  You may have trouble with csh.   Note
-		 * that the tags list only has to be sorted if you intend to
-		 * use it with the real vi;  elvis permits unsorted tags.
-		 */
-# if OSK
-		system("qsort tags >-_tags; -nx; del tags; rename _tags tags");
-# else	
-		system("sort tags >_tags$$; mv _tags$$ tags");
-# endif
-#endif
-
-	exit(0);
-	/*NOTREACHED*/
-}
-
-#if MSDOS || TOS
-# define WILDCARD_NO_MAIN
-# include "wildcard.c"
-#endif
Index: trunk/minix/commands/elvis/ctype.c
===================================================================
--- trunk/minix/commands/elvis/ctype.c	(revision 9)
+++ 	(revision )
@@ -1,74 +1,0 @@
-/* ctype.c */
-
-/* This file contains the tables and initialization function for elvis'
- * version of <ctype.h>.  It should be portable.
- */
-
-#include "config.h"
-#include "ctype.h"
-
-uchar	_ct_toupper[256];
-uchar	_ct_tolower[256];
-uchar	_ct_ctypes[256];
-
-/* This function initializes the tables used by the ctype macros.  It should
- * be called at the start of the program.  It can be called again anytime you
- * wish to change the non-standard "flipcase" list.  The "flipcase" list is
- * a string of characters which are taken to be lowercase/uppercase pairs.
- * If you don't want to use any special flipcase characters, then pass an
- * empty string.
- */
-void _ct_init(flipcase)
-	uchar	*flipcase;	/* list of non-standard lower/upper letter pairs */
-{
-	int	i;
-	uchar	*scan;
-
-	/* reset all of the tables */
-	for (i = 0; i < 256; i++)
-	{
-		_ct_toupper[i] = _ct_tolower[i] = i;
-		_ct_ctypes[i] = 0;
-	}
-
-	/* add the digits */
-	for (scan = (uchar *)"0123456789"; *scan; scan++)
-	{
-		_ct_ctypes[*scan] |= _CT_DIGIT | _CT_ALNUM;
-	}
-
-	/* add the whitespace */
-	for (scan = (uchar *)" \t\n\r\f"; *scan; scan++)
-	{
-		_ct_ctypes[*scan] |= _CT_SPACE;
-	}
-
-	/* add the standard ASCII letters */
-	for (scan = (uchar *)"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"; *scan; scan += 2)
-	{
-		_ct_ctypes[scan[0]] |= _CT_LOWER | _CT_ALNUM;
-		_ct_ctypes[scan[1]] |= _CT_UPPER | _CT_ALNUM;
-		_ct_toupper[scan[0]] = scan[1];
-		_ct_tolower[scan[1]] = scan[0];
-	}
-
-	/* add the flipcase letters */
-	for (scan = flipcase; scan[0] && scan[1]; scan += 2)
-	{
-		_ct_ctypes[scan[0]] |= _CT_LOWER | _CT_ALNUM;
-		_ct_ctypes[scan[1]] |= _CT_UPPER | _CT_ALNUM;
-		_ct_toupper[scan[0]] = scan[1];
-		_ct_tolower[scan[1]] = scan[0];
-	}
-
-	/* include '_' in the isalnum() list */
-	_ct_ctypes[UCHAR('_')] |= _CT_ALNUM;
-
-	/* !!! find the control characters in an ASCII-dependent way */
-	for (i = 0; i < ' '; i++)
-	{
-		_ct_ctypes[i] |= _CT_CNTRL;
-	}
-	_ct_ctypes[127] |= _CT_CNTRL;
-	_ct_ctypes[255] |= _CT_CNTRL;
-}
Index: trunk/minix/commands/elvis/ctype.h
===================================================================
--- trunk/minix/commands/elvis/ctype.h	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-/* ctype.h */
-
-/* This file contains macros definitions and extern declarations for a
- * version of <ctype.h> which is aware of the o_flipcase letters used in
- * elvis.
- *
- * This file uses the "uchar" data type and "UCHAR" conversion macro which
- * are defined in "config.h".  Consequently, any file that includes this
- * header must include config.h first.
- */
-
-#ifndef _CT_UPPER
-
-#define _CT_UPPER	0x01
-#define _CT_LOWER	0x02
-#define _CT_SPACE	0x04
-#define _CT_DIGIT	0x08
-#define _CT_ALNUM	0x10
-#define _CT_CNTRL	0x20
-
-#define isalnum(c)	(_ct_ctypes[UCHAR(c)] & _CT_ALNUM)
-#define isalpha(c)	(_ct_ctypes[UCHAR(c)] & (_CT_LOWER|_CT_UPPER))
-#define isdigit(c)	(_ct_ctypes[UCHAR(c)] & _CT_DIGIT)
-#define islower(c)	(_ct_ctypes[UCHAR(c)] & _CT_LOWER)
-#define isspace(c)	(_ct_ctypes[UCHAR(c)] & _CT_SPACE)
-#define isupper(c)	(_ct_ctypes[UCHAR(c)] & _CT_UPPER)
-#define iscntrl(c)	(_ct_ctypes[UCHAR(c)] & _CT_CNTRL)
-#define ispunct(c)	(!_ct_ctypes[UCHAR(c)]) /* punct = "none of the above" */
-
-#define isascii(c)	(!((c) & 0x80))
-
-#define toupper(c)	_ct_toupper[UCHAR(c)]
-#define tolower(c)	_ct_tolower[UCHAR(c)]
-
-extern uchar	_ct_toupper[];
-extern uchar	_ct_tolower[];
-extern uchar	_ct_ctypes[];
-extern void	_ct_init(/* char *flipcase */);
-
-#endif /* ndef _CT_UPPER */
Index: trunk/minix/commands/elvis/curses.c
===================================================================
--- trunk/minix/commands/elvis/curses.c	(revision 9)
+++ 	(revision )
@@ -1,930 +1,0 @@
-/* curses.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the functions & variables needed for a tiny subset of
- * curses.  The principle advantage of this version of curses is its
- * extreme speed.  Disadvantages are potentially larger code, few supported
- * functions, limited compatibility with full curses, and only stdscr.
- */
-
-#include "config.h"
-#include "vi.h"
-
-#if ANY_UNIX
-/* The termios/termio/sgtty #ifdefs were a mess, so I removed all but termios.
- * (KJB)
- */
-# include	<termios.h>
-# if MINIX
-#  include	<sys/ioctl.h>
-# endif
-#endif
-
-#if TOS
-# include	<osbind.h>
-#endif
-
-#if OSK
-# include	<sgstat.h>
-#endif
-
-#if VMS
-extern int VMS_read_raw;  /* Set in initscr() */
-#endif
-
-
-extern char	*getenv();
-static void	 starttcap();
-
-/* variables, publicly available & used in the macros */
-char	*termtype;	/* name of terminal entry */
-short	ospeed;		/* speed of the tty, eg B2400 */
-#if OSK
-char	PC_;	/* Pad char */
-char	*BC;	/* backspace character string */
-#else
-char	PC;		/* Pad char */
-#endif
-WINDOW	*stdscr;	/* pointer into kbuf[] */
-WINDOW	kbuf[KBSIZ];	/* a very large output buffer */
-int	LINES;		/* :li#: number of rows */
-int	COLS;		/* :co#: number of columns */
-int	AM;		/* :am:  boolean: auto margins? */
-int	PT;		/* :pt:  boolean: physical tabs? */
-char	*VB;		/* :vb=: visible bell */
-char	*UP;		/* :up=: move cursor up */
-char	*SO = "";	/* :so=: standout start */
-char	*SE = "";	/* :se=: standout end */
-char	*US = "";	/* :us=: underline start */
-char	*UE = "";	/* :ue=: underline end */
-char	*MD = "";	/* :md=: bold start */
-char	*ME = "";	/* :me=: bold end */
-char	*AS = "";	/* :as=: alternate (italic) start */
-char	*AE = "";	/* :ae=: alternate (italic) end */
-#ifndef NO_VISIBLE
-char	*MV;		/* :mv=: "visible" selection start */
-#endif
-char	*CM;		/* :cm=: cursor movement */
-char	*CE;		/* :ce=: clear to end of line */
-char	*CD;		/* :cd=: clear to end of screen */
-char	*AL;		/* :al=: add a line */
-char	*DL;		/* :dl=: delete a line */
-#if OSK
-char	*SR_;		/* :sr=: scroll reverse */
-#else
-char	*SR;		/* :sr=: scroll reverse */
-#endif
-char	*KS = "";	/* :ks=: init string for cursor */
-char	*KE = "";	/* :ke=: restore string for cursor */
-char	*KU;		/* :ku=: key sequence sent by up arrow */
-char	*KD;		/* :kd=: key sequence sent by down arrow */
-char	*KL;		/* :kl=: key sequence sent by left arrow */
-char	*KR;		/* :kr=: key sequence sent by right arrow */
-char	*HM;		/* :HM=: key sequence sent by the <Home> key */
-char	*EN;		/* :EN=: key sequence sent by the <End> key */
-char	*PU;		/* :PU=: key sequence sent by the <PgUp> key */
-char	*PD;		/* :PD=: key sequence sent by the <PgDn> key */
-char	*KI;		/* :kI=: key sequence sent by the <Insert> key */
-#ifndef NO_FKEY
-char	*FKEY[NFKEYS];	/* :k0=: ... :k9=: sequences sent by function keys */
-#endif
-char	*IM = "";	/* :im=: insert mode start */
-char	*IC = "";	/* :ic=: insert the following character */
-char	*EI = "";	/* :ei=: insert mode end */
-char	*DC;		/* :dc=: delete a character */
-char	*TI = "";	/* :ti=: terminal init */	/* GB */
-char	*TE = "";	/* :te=: terminal exit */	/* GB */
-#ifndef NO_CURSORSHAPE
-#if 1
-char	*CQ = (char *)0;/* :cQ=: normal cursor */
-char	*CX = (char *)1;/* :cX=: cursor used for EX command/entry */
-char	*CV = (char *)2;/* :cV=: cursor used for VI command mode */
-char	*CI = (char *)3;/* :cI=: cursor used for VI input mode */
-char	*CR = (char *)4;/* :cR=: cursor used for VI replace mode */
-#else
-char	*CQ = "";	/* :cQ=: normal cursor */
-char	*CX = "";	/* :cX=: cursor used for EX command/entry */
-char	*CV = "";	/* :cV=: cursor used for VI command mode */
-char	*CI = "";	/* :cI=: cursor used for VI input mode */
-char	*CR = "";	/* :cR=: cursor used for VI replace mode */
-#endif
-#endif
-char	*aend = "";	/* end an attribute -- either UE or ME */
-char	ERASEKEY;	/* backspace key taken from ioctl structure */
-#ifndef NO_COLOR
-char	normalcolor[16];
-char	SOcolor[16];
-char	SEcolor[16];
-char	UScolor[16];
-char	UEcolor[16];
-char	MDcolor[16];
-char	MEcolor[16];
-char	AScolor[16];
-char	AEcolor[16];
-# ifndef NO_POPUP
-char	POPUPcolor[16];
-# endif
-# ifndef NO_VISIBLE
-char	VISIBLEcolor[16];
-# endif
-#endif
-
-#if ANY_UNIX
-static struct termios	oldtermio;	/* original tty mode */
-static struct termios	newtermio;	/* cbreak/noecho tty mode */
-#endif
-
-#if OSK
-static struct sgbuf	oldsgttyb;	/* orginal tty mode */
-static struct sgbuf	newsgttyb;	/* noecho tty mode */
-#endif
-
-static char	*capbuf;	/* capability string buffer */
-
-
-/* Initialize the Curses package. */
-void initscr()
-{
-	/* make sure TERM variable is set */
-	termtype = getenv("TERM");
-
-#if VMS
-	/* VMS getenv() handles TERM as a environment setting.  Foreign 
-	 * terminal support can be implemented by setting the ELVIS_TERM
-	 * logical or symbol to match a tinytcap entry.
-	 */
-	if (!strcmp(termtype,"unknown"))
-		termtype = getenv("ELVIS_TERM");
-#endif
-#if MSDOS
-	/* For MS-DOS, if TERM is unset we can default to "pcbios", or
-	 * maybe "rainbow".
-	 */
-	if (!termtype)
-	{
-#ifdef RAINBOW
-		if (*(unsigned char far*)(0xffff000eL) == 6   /* Rainbow 100a */
-		 || *(unsigned char far*)(0xffff000eL) == 148)/* Rainbow 100b */
-		{
-			termtype = "rainbow";
-		}
-		else
-#endif
-			termtype = "pcbios";
-	}
-	if (!strcmp(termtype, "pcbios"))
-#else
-	if (!termtype)
-#endif
-	{
-#if ANY_UNIX
-		write(2, "Environment variable TERM must be set\n", (unsigned)38);
-		exit(1);
-#endif
-#if OSK
-		writeln(2, "Environment variable TERM must be set\n", (unsigned)38);
-		exit(1);
-#endif
-#if AMIGA
-		termtype = TERMTYPE;
-		starttcap(termtype);
-#endif
-#if MSDOS
-		starttcap("pcbios");
-#endif
-#if TOS
-		termtype = "vt52";
-		starttcap(termtype);
-#endif
-#if VMS
-		write(2, "UNKNOWN terminal: define ELVIS_TERM\n", (unsigned)36);
-		exit(1);
-#endif
-	}
-	else
-	{
-#if MSDOS
-		*o_pcbios = 0;
-#endif
-		/* start termcap stuff */
-		starttcap(termtype);
-	}
-
-	/* create stdscr and curscr */
-	stdscr = kbuf;
-
-	/* change the terminal mode to cbreak/noecho */
-#if ANY_UNIX
-	tcgetattr(2, &oldtermio);
-#endif
-
-#if OSK
-	_gs_opt(0, &oldsgttyb);
-#endif
-
-#if VMS
-	VMS_read_raw = 1;   /* cbreak/noecho */
-	vms_open_tty();
-#endif
-	resume_curses(TRUE);
-}
-
-/* Shut down the Curses package. */
-void endwin()
-{
-	/* change the terminal mode back the way it was */
-	suspend_curses();
-#if AMIGA
-	amiclosewin();
-#endif
-}
-
-
-static int curses_active = FALSE;
-
-/* Send any required termination strings.  Turn off "raw" mode. */
-void suspend_curses()
-{
-#ifndef NO_CURSORSHAPE
-	if (has_CQ)
-	{
-		do_CQ();
-	}
-#endif
-	if (has_TE)					/* GB */
-	{
-		do_TE();
-	}
-	if (has_KE)
-	{
-		do_KE();
-	}
-#ifndef NO_COLOR
-	quitcolor();
-#endif
-	refresh();
-
-	/* change the terminal mode back the way it was */
-#if ANY_UNIX
-	tcsetattr(2, TCSADRAIN, &oldtermio);
-#endif
-#if OSK
-	_ss_opt(0, &oldsgttyb);
-#endif
-#if AMIGA
-	ttyshutdown();
-#endif
-#if MSDOS
-	raw_set_stdio(FALSE);
-#endif
-
-#if VMS
-	VMS_read_raw = 0;
-#endif
-	curses_active = FALSE;
-}
-
-
-/* put the terminal in RAW mode.  If "quietly" is FALSE, then ask the user
- * to hit a key, and wait for keystroke before returning.
- */
-void resume_curses(quietly)
-	int	quietly;
-{
-	if (!curses_active)
-	{
-		/* change the terminal mode to cbreak/noecho */
-#if ANY_UNIX
-		ospeed = cfgetospeed(&oldtermio);
-		ERASEKEY = oldtermio.c_cc[VERASE];
-		newtermio = oldtermio;
-		newtermio.c_iflag &= (IXON|IXOFF|IXANY|ISTRIP|IGNBRK);
-		newtermio.c_oflag &= ~OPOST;
-		newtermio.c_lflag &= ISIG;
-		newtermio.c_cc[VINTR] = ctrl('C'); /* always use ^C for interrupts */
-		newtermio.c_cc[VMIN] = 1;
-		newtermio.c_cc[VTIME] = 0;
-		newtermio.c_cc[VSUSP] = 0;
-		tcsetattr(2, TCSADRAIN, &newtermio);
-#endif
-#if OSK
-		newsgttyb = oldsgttyb;
-		newsgttyb.sg_echo = 0;
-		newsgttyb.sg_eofch = 0;
-		newsgttyb.sg_kbach = 0;
-		newsgttyb.sg_kbich = ctrl('C');
-		_ss_opt(0, &newsgttyb);
-		ospeed = oldsgttyb.sg_baud;
-		ERASEKEY = oldsgttyb.sg_bspch;
-#endif
-#if AMIGA
-		/* turn on window resize and RAW */
-		ttysetup();
-#endif
-#if MSDOS
-		raw_set_stdio(TRUE);
-#endif
-
-#if VMS
-		VMS_read_raw = 1;
-		{ int c;
-			read(0,&c,0);   /* Flush the tty buffer. */
-		}
-		ERASEKEY = '\177';  /* Accept <DEL> as <^H> for VMS */
-#endif
-
-		if (has_TI)					/* GB */
-		{
-			do_TI();
-		}
-		if (has_KS)
-		{
-			do_KS();
-		}
-
-		curses_active = TRUE;
-	}
-
-	/* If we're supposed to quit quietly, then we're done */
-	if (quietly)
-	{
-		return;
-	}
-
-	signal(SIGINT, SIG_IGN);
-
-	move(LINES - 1, 0);
-	do_SO();
-#if VMS
-	qaddstr("\n[Press <RETURN> to continue]");
-#else
-	qaddstr("[Press <RETURN> to continue]");
-#endif
-	do_SE();
-	refresh();
-	ttyread(kbuf, 20, 0); /* in RAW mode, so <20 is very likely */
-	if (kbuf[0] == ':')
-	{
-		mode = MODE_COLON;
-		addch('\n');
-		refresh();
-	}
-	else
-	{
-		mode = MODE_VI;
-		redraw(MARK_UNSET, FALSE);
-	}	
-	exwrote = FALSE;
-
-#if TURBOC || __GNUC__ || _ANSI
-	signal(SIGINT, (void(*)()) trapint);
-#else
-	signal(SIGINT, trapint);
-#endif
-}
-
-/* This function fetches an optional string from termcap */
-static void mayhave(T, s)
-	char	**T;	/* where to store the returned pointer */
-	char	*s;	/* name of the capability */
-{
-	char	*val;
-
-	val = tgetstr(s, &capbuf);
-	if (val)
-	{
-		*T = val;
-	}
-}
-
-
-/* This function fetches a required string from termcap */
-static void musthave(T, s)
-	char	**T;	/* where to store the returned pointer */
-	char	*s;	/* name of the capability */
-{
-	mayhave(T, s);
-	if (!*T)
-	{
-		write(2, "This termcap entry lacks the :", (unsigned)30);
-		write(2, s, (unsigned)2);
-		write(2, "=: capability\n", (unsigned)14);
-#if OSK
-		write(2, "\l", 1);
-#endif
-		exit(1);
-	}
-}
-
-
-/* This function fetches a pair of strings from termcap.  If one of them is
- * missing, then the other one is ignored.
- */
-static void pair(T, U, sT, sU)
-	char	**T;	/* where to store the first pointer */
-	char	**U;	/* where to store the second pointer */
-	char	*sT;	/* name of the first capability */
-	char	*sU;	/* name of the second capability */
-{
-	mayhave(T, sT);
-	mayhave(U, sU);
-	if (!**T || !**U)
-	{
-		*T = *U = "";
-	}
-}
-
-
-
-/* Read everything from termcap */
-static void starttcap(term)
-	char	*term;
-{
-	static char	cbmem[800];
-
-	/* allocate memory for capbuf */
-	capbuf = cbmem;
-
-	/* get the termcap entry */
-	switch (tgetent(kbuf, term))
-	{
-	  case -1:
-		write(2, "Can't read /etc/termcap\n", (unsigned)24);
-#if OSK
-		write(2, "\l", 1);
-#endif
-		exit(2);
-
-	  case 0:
-		write(2, "Unrecognized TERM type\n", (unsigned)23);
-#if OSK
-		write(2, "\l", 1);
-#endif
-		exit(3);
-	}
-
-	/* get strings */
-	musthave(&UP, "up");
-	mayhave(&VB, "vb");
-	musthave(&CM, "cm");
-	pair(&SO, &SE, "so", "se");
-	mayhave(&TI, "ti");
-	mayhave(&TE, "te");
-	if (tgetnum("ug") <= 0)
-	{
-		pair(&US, &UE, "us", "ue");
-		pair(&MD, &ME, "md", "me");
-
-		/* get italics, or have it default to underline */
-		pair(&AS, &AE, "as", "ae");
-		if (!*AS)
-		{
-			AS = US;
-			AE = UE;
-		}
-	}
-#ifndef NO_VISIBLE
-	MV = SO; /* by default */
-	mayhave(&MV, "mv");
-#endif
-	mayhave(&AL, "al");
-	mayhave(&DL, "dl");
-	musthave(&CE, "ce");
-	mayhave(&CD, "cd");
-#if OSK
-	mayhave(&SR_, "sr");
-#else	
-	mayhave(&SR, "sr");
-#endif
-	pair(&IM, &EI, "im", "ei");
-	mayhave(&IC, "ic");
-	mayhave(&DC, "dc");
-
-	/* other termcap stuff */
-	AM = (tgetflag("am") && !tgetflag("xn"));
-	PT = tgetflag("pt");
-#if AMIGA
-	amiopenwin(termtype);	/* Must run this before ttysetup(); */
-	ttysetup();	/* Must run this before getsize(0); */
-#endif
-	getsize(0);
-
-	/* Key sequences */
-	pair(&KS, &KE, "ks", "ke");
-	mayhave(&KU, "ku");		/* up */
-	mayhave(&KD, "kd");		/* down */
-	mayhave(&KL, "kl");		/* left */
-	mayhave(&KR, "kr");		/* right */
-	mayhave(&PU, "kP");		/* PgUp */
-	mayhave(&PD, "kN");		/* PgDn */
-	mayhave(&HM, "kh");		/* Home */
-	mayhave(&EN, "kH");		/* End */
-	mayhave(&KI, "kI");		/* Insert */
-#ifndef CRUNCH
-	if (!PU) mayhave(&PU, "K2");	/* "3x3 pad" names for PgUp, etc. */
-	if (!PD) mayhave(&PD, "K5");
-	if (!HM) mayhave(&HM, "K1");
-	if (!EN) mayhave(&EN, "K4");
-
-	mayhave(&PU, "PU");		/* old XENIX names for PgUp, etc. */
-	mayhave(&PD, "PD");		/* (overrides others, if used.) */
-	mayhave(&HM, "HM");
-	mayhave(&EN, "EN");
-#endif
-#ifndef NO_FKEY
-	mayhave(&FKEY[0], "k0");		/* function key codes */
-	mayhave(&FKEY[1], "k1");
-	mayhave(&FKEY[2], "k2");
-	mayhave(&FKEY[3], "k3");
-	mayhave(&FKEY[4], "k4");
-	mayhave(&FKEY[5], "k5");
-	mayhave(&FKEY[6], "k6");
-	mayhave(&FKEY[7], "k7");
-	mayhave(&FKEY[8], "k8");
-	mayhave(&FKEY[9], "k9");
-# ifndef NO_SHIFT_FKEY
-	mayhave(&FKEY[10], "s0");		/* shift function key codes */
-	mayhave(&FKEY[11], "s1");
-	mayhave(&FKEY[12], "s2");
-	mayhave(&FKEY[13], "s3");
-	mayhave(&FKEY[14], "s4");
-	mayhave(&FKEY[15], "s5");
-	mayhave(&FKEY[16], "s6");
-	mayhave(&FKEY[17], "s7");
-	mayhave(&FKEY[18], "s8");
-	mayhave(&FKEY[19], "s9");
-#  ifndef NO_CTRL_FKEY
-	mayhave(&FKEY[20], "c0");		/* control function key codes */
-	mayhave(&FKEY[21], "c1");
-	mayhave(&FKEY[22], "c2");
-	mayhave(&FKEY[23], "c3");
-	mayhave(&FKEY[24], "c4");
-	mayhave(&FKEY[25], "c5");
-	mayhave(&FKEY[26], "c6");
-	mayhave(&FKEY[27], "c7");
-	mayhave(&FKEY[28], "c8");
-	mayhave(&FKEY[29], "c9");
-#   ifndef NO_ALT_FKEY
-	mayhave(&FKEY[30], "a0");		/* alt function key codes */
-	mayhave(&FKEY[31], "a1");
-	mayhave(&FKEY[32], "a2");
-	mayhave(&FKEY[33], "a3");
-	mayhave(&FKEY[34], "a4");
-	mayhave(&FKEY[35], "a5");
-	mayhave(&FKEY[36], "a6");
-	mayhave(&FKEY[37], "a7");
-	mayhave(&FKEY[38], "a8");
-	mayhave(&FKEY[39], "a9");
-#   endif
-#  endif
-# endif
-#endif
-
-#ifndef NO_CURSORSHAPE
-	/* cursor shapes */
-	CQ = tgetstr("cQ", &capbuf);
-	if (has_CQ)
-	{
-		CX = tgetstr("cX", &capbuf);
-		if (!CX) CX = CQ;
-		CV = tgetstr("cV", &capbuf);
-		if (!CV) CV = CQ;
-		CI = tgetstr("cI", &capbuf);
-		if (!CI) CI = CQ;
-		CR = tgetstr("cR", &capbuf);
-		if (!CR) CR = CQ;
-	}
-# ifndef CRUNCH
-	else
-	{
-		CQ = CV = "";
-		pair(&CQ, &CV, "ve", "vs");
-		CX = CI = CR = CQ;
-	}
-# endif /* !CRUNCH */
-#endif /* !NO_CURSORSHAPE */
-
-#ifndef NO_COLOR
-	strcpy(SOcolor, SO);
-	strcpy(SEcolor, SE);
-	strcpy(AScolor, AS);
-	strcpy(AEcolor, AE);
-	strcpy(MDcolor, MD);
-	strcpy(MEcolor, ME);
-	strcpy(UScolor, US);
-	strcpy(UEcolor, UE);
-# ifndef NO_POPUP
-	strcpy(POPUPcolor, SO);
-# endif
-# ifndef NO_VISIBLE
-	strcpy(VISIBLEcolor, MV);
-# endif
-#endif
-
-}
-
-
-/* This function gets the window size.  It uses the TIOCGWINSZ ioctl call if
- * your system has it, or tgetnum("li") and tgetnum("co") if it doesn't.
- * This function is called once during initialization, and thereafter it is
- * called whenever the SIGWINCH signal is sent to this process.
- */
-int getsize(signo)
-	int	signo;
-{
-	int	lines;
-	int	cols;
-#ifdef TIOCGWINSZ
-	struct winsize size;
-#endif
-
-#ifdef SIGWINCH
-	/* reset the signal vector */
-	signal(SIGWINCH, getsize);
-#endif
-
-	/* get the window size, one way or another. */
-	lines = cols = 0;
-#ifdef TIOCGWINSZ
-	if (ioctl(2, TIOCGWINSZ, &size) >= 0)
-	{
-		lines = size.ws_row;
-		cols = size.ws_col;
-	}
-#endif
-#if AMIGA
-	/* Amiga gets window size by asking the console.device */
-	if (!strcmp(TERMTYPE, termtype))
-	{
-	    auto long len;
-	    auto char buf[30];
-	    
-	    Write(Output(), "\2330 q", 4); /* Ask the console.device */
-	    len = Read(Input(), buf, 29);
-	    buf[len] = '\000';
-	    sscanf(&buf[5], "%d;%d", &lines, &cols);
-	}
-#endif
-	if ((lines == 0 || cols == 0) && signo == 0)
-	{
-		LINES = tgetnum("li");
-		COLS = tgetnum("co");
-	}
-#if MSDOS
-# ifdef RAINBOW
-	if (!strcmp(termtype, "rainbow"))
-	{
-		/* Determine whether Rainbow is in 80-column or 132-column mode */
-		cols = *(unsigned char far *)0xee000f57L;
-	}
-	else
-# endif
-	{
-		lines = v_rows();
-		cols = v_cols();
-	}
-#endif
-	if (lines >= 2)
-	{
-		LINES = lines;
-	}
-
-	if (cols >= 30)
-	{
-		COLS = cols;
-	}
-
-	/* Make sure we got values that we can live with */
-	if (LINES < 2 || COLS < 30)
-	{
-		write(2, "Screen too small\n", (unsigned)17);
-#if OSK
-		write(2, "\l", 1);
-#endif
-		endwin();
-		exit(2);
-	}
-
-#if AMIGA
-	if (*o_lines != LINES || *o_columns != COLS)
-	{
-		*o_lines = LINES;
-		*o_columns = COLS;
-	}
-#endif
-
-	return 0;
-}
-
-
-/* This is a function version of addch() -- it is used by tputs() */
-int faddch(ch)
-	int	ch;
-{
-	addch(ch);
-
-	return 0;
-}
-
-/* This function quickly adds a string to the output queue.  It does *NOT*
- * convert \n into <CR><LF>.
- */
-void qaddstr(str)
-	char	*str;
-{
-	REG char *s_, *d_;
-
-#if MSDOS
-	if (o_pcbios[0])
-	{
-		while (*str)
-			qaddch(*str++);
-		return;
-	}
-#endif
-	for (s_=(str), d_=stdscr; *d_++ = *s_++; )
-	{
-	}
-	stdscr = d_ - 1;
-}
-
-/* Output the ESC sequence needed to go into any video mode, if supported */
-void attrset(a)
-	int	a;
-{
-	do_aend();
-	if (a == A_BOLD)
-	{
-		do_MD();
-		aend = ME;
-	}
-	else if (a == A_UNDERLINE)
-	{
-		do_US();
-		aend = UE;
-	}
-	else if (a == A_ALTCHARSET)
-	{
-		do_AS();
-		aend = AE;
-	}
-	else
-	{
-		aend = "";
-	}
-}
-
-
-/* Insert a single character into the display */
-void insch(ch)
-	int	ch;
-{
-	if (has_IM)
-		do_IM();
-	do_IC();
-	qaddch(ch);
-	if (has_EI)
-		do_EI();
-}
-
-void wrefresh()
-{
-	if (stdscr != kbuf)
-	{
-		VOIDBIOS(;,ttywrite(kbuf, (unsigned)(stdscr - kbuf)));
-		stdscr = kbuf;
-	}
-}
-
-void wqrefresh()
-{
-	if (stdscr - kbuf > 2000)
-	{
-		VOIDBIOS(stdscr = kbuf,
-		{
-			ttywrite(kbuf, (unsigned)(stdscr - kbuf)); 
-			stdscr = kbuf;
-		});
-	}
-}
-
-#ifndef NO_COLOR
-/* This function is called during termination.  It resets color modes */
-int ansiquit()
-{
-	/* if ANSI color terminal, then reset the colors */
-	if (!strcmp(UP, "\033[A"))
-	{
-		tputs("\033[37;40m\033[m", 1, faddch);
-		clrtoeol();
-		return 1;
-	}
-	return 0;
-}
-
-/* This sets the color strings that work for ANSI terminals.  If the TERMCAP
- * doesn't look like an ANSI terminal, then it returns FALSE.  If the colors
- * aren't understood, it also returns FALSE.  If all goes well, it returns TRUE
- */
-int ansicolor(cmode, attrbyte)
-	int	cmode;		/* mode to set, e.g. A_NORMAL */
-	int	attrbyte;	/* IBM PC attribute byte */
-{
-	char	temp[16];	/* hold the new mode string */
-
-	/* if not ANSI-ish, then fail */
-	if (strcmp(UP, "\033[A") && strcmp(UP, "\033OA"))
-	{
-		msg("Don't know how to set colors for this terminal");
-		return 0;
-	}
-
-	/* construct the color string */
-	sprintf(temp, "\033[m\033[3%c;4%c%s%sm",
-		"04261537"[attrbyte & 0x07],
-		"04261537"[(attrbyte >> 4) & 0x07],
-		(attrbyte & 0x08) ? ";1" : "",
-		(attrbyte & 0x80) ? ";5" : "");
-
-	/* stick it in the right place */
-	switch (cmode)
-	{
-	  case A_NORMAL:
-		if (!strcmp(MEcolor, normalcolor))
-			strcpy(MEcolor, temp);
-		if (!strcmp(UEcolor, normalcolor))
-			strcpy(UEcolor, temp);
-		if (!strcmp(AEcolor, normalcolor))
-			strcpy(AEcolor, temp);
-		if (!strcmp(SEcolor, normalcolor))
-			strcpy(SEcolor, temp);
-
-		strcpy(normalcolor, temp);
-		tputs(normalcolor, 1, faddch);
-		break;
-
-	  case A_BOLD:
-		strcpy(MDcolor, temp);
-		strcpy(MEcolor, normalcolor);
-		break;
-
-	  case A_UNDERLINE:
-		strcpy(UScolor, temp);
-		strcpy(UEcolor, normalcolor);
-		break;
-
-	  case A_ALTCHARSET:
-		strcpy(AScolor, temp);
-		strcpy(AEcolor, normalcolor);
-		break;
-
-	  case A_STANDOUT:
-		strcpy(SOcolor, temp);
-		strcpy(SEcolor, normalcolor);
-		break;
-
-#ifndef NO_POPUP
-	  case A_POPUP:
-		strcpy(POPUPcolor, temp);
-		break;
-#endif
-
-#ifndef NO_VISIBLE
-	  case A_VISIBLE:
-		strcpy(VISIBLEcolor, temp);
-		break;
-#endif
-	}
-
-	return 1;
-}
-
-
-/* This function outputs the ESC sequence needed to switch the screen back
- * to "normal" mode.  On color terminals which haven't had their color set
- * yet, this is one of the termcap strings; for color terminals that really
- * have had colors defined, we just the "normal color" escape sequence.
- */
-endcolor()
-{
-	if (aend == ME)
-		tputs(MEcolor, 1, faddch);
-	else if (aend == UE)
-		tputs(UEcolor, 1, faddch);
-	else if (aend == AE)
-		tputs(AEcolor, 1, faddch);
-	else if (aend == SE)
-		tputs(SEcolor, 1, faddch);
-	aend = "";
-	return 0;
-}
-
-
-#endif /* !NO_COLOR */
Index: trunk/minix/commands/elvis/curses.h
===================================================================
--- trunk/minix/commands/elvis/curses.h	(revision 9)
+++ 	(revision )
@@ -1,319 +1,0 @@
-/* curses.h */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This is the header file for a small, fast, fake curses package */
-
-/* termcap stuff */
-extern char	*tgoto();
-extern char	*tgetstr();
-extern void	tputs();
-
-#if MSDOS
-/* BIOS interface used instead of termcap for MS-DOS */
-extern int	vmode;
-extern void	v_up();
-extern void	v_cb();
-extern void	v_cs();
-extern void	v_ce();
-extern void	v_cl();
-extern void	v_cd();
-extern void	v_al();
-extern void	v_dl();
-extern void	v_sr();
-extern void	v_move();
-#endif
-
-/* faddch() is a function.  a pointer to it is passed to tputs() */
-extern int	faddch();
-
-/* data types */
-#define WINDOW	char
-
-/* CONSTANTS & SYMBOLS */
-#define TRUE		1
-#define FALSE		0
-#define A_NORMAL	0
-#define A_STANDOUT	1
-#define A_BOLD		2
-#define A_UNDERLINE	3
-#define A_ALTCHARSET	4
-#define A_POPUP		5
-#define A_VISIBLE	6
-#define KBSIZ		4096
-
-/* figure out how many function keys we need to allow. */
-#ifndef NO_FKEY
-# ifdef NO_SHIFT_FKEY
-#  define	NFKEYS	10
-# else
-#  ifdef NO_CTRL_FKEY
-#   define	NFKEYS	20
-#  else
-#   ifdef NO_ALT_FKEY
-#    define	NFKEYS	30
-#   else
-#    define	NFKEYS	40
-#   endif
-#  endif
-# endif
-extern char	*FKEY[NFKEYS];	/* :k0=:...:k9=: codes sent by function keys */
-#endif
-
-/* extern variables, defined in curses.c */
-extern char	*termtype;	/* name of terminal entry */
-extern short	ospeed;		/* tty speed, eg B2400 */
-#if OSK
-extern char PC_;	/* Pad char */
-extern char	*BC;	/* Backspace char string */
-#else
-extern char	PC;		/* Pad char */
-#endif
-extern WINDOW	*stdscr;	/* pointer into kbuf[] */
-extern WINDOW	kbuf[KBSIZ];	/* a very large output buffer */
-extern int	LINES;		/* :li#: number of rows */
-extern int	COLS;		/* :co#: number of columns */
-extern int	AM;		/* :am:  boolean: auto margins? */
-extern int	PT;		/* :pt:  boolean: physical tabs? */
-extern char	*VB;		/* :vb=: visible bell */
-extern char	*UP;		/* :up=: move cursor up */
-extern char	*SO;		/* :so=: standout start */
-extern char	*SE;		/* :se=: standout end */
-extern char	*US;		/* :us=: underline start */
-extern char	*UE;		/* :ue=: underline end */
-extern char	*MD;		/* :md=: bold start */
-extern char	*ME;		/* :me=: bold end */
-extern char	*AS;		/* :as=: alternate (italic) start */
-extern char	*AE;		/* :ae=: alternate (italic) end */
-#ifndef NO_VISIBLE
-extern char	*MV;		/* :mv=: "visible" selection start */
-#endif
-extern char	*CM;		/* :cm=: cursor movement */
-extern char	*CE;		/* :ce=: clear to end of line */
-extern char	*CD;		/* :cd=: clear to end of screen */
-extern char	*AL;		/* :al=: add a line */
-extern char	*DL;		/* :dl=: delete a line */
-#if OSK
-extern char	*SR_;		/* :sr=: scroll reverse */
-#else
-extern char	*SR;		/* :sr=: scroll reverse */
-#endif
-extern char	*KS;		/* :ks=: init string for cursor */
-extern char	*KE;		/* :ke=: restore string for cursor */
-extern char	*KU;		/* :ku=: sequence sent by up key */
-extern char	*KD;		/* :kd=: sequence sent by down key */
-extern char	*KL;		/* :kl=: sequence sent by left key */
-extern char	*KR;		/* :kr=: sequence sent by right key */
-extern char	*PU;		/* :PU=: key sequence sent by PgUp key */
-extern char	*PD;		/* :PD=: key sequence sent by PgDn key */
-extern char	*HM;		/* :HM=: key sequence sent by Home key */
-extern char	*EN;		/* :EN=: key sequence sent by End key */
-extern char	*KI;		/* :kI=: key sequence sent by Insert key */
-extern char	*IM;		/* :im=: insert mode start */
-extern char	*IC;		/* :ic=: insert following char */
-extern char	*EI;		/* :ei=: insert mode end */
-extern char	*DC;		/* :dc=: delete a character */
-extern char	*TI;		/* :ti=: terminal init */	/* GB */
-extern char	*TE;		/* :te=: terminal exit */	/* GB */
-#ifndef NO_CURSORSHAPE
-extern char	*CQ;		/* :cQ=: normal cursor */
-extern char	*CX;		/* :cX=: cursor used for EX command/entry */
-extern char	*CV;		/* :cV=: cursor used for VI command mode */
-extern char	*CI;		/* :cI=: cursor used for VI input mode */
-extern char	*CR;		/* :cR=: cursor used for VI replace mode */
-#endif
-extern char	*aend;		/* end an attribute -- either UE or ME */
-extern char	ERASEKEY;	/* taken from the ioctl structure */
-#ifndef NO_COLOR
-extern char	SOcolor[];
-extern char	SEcolor[];
-extern char	UScolor[];
-extern char	UEcolor[];
-extern char	MDcolor[];
-extern char	MEcolor[];
-extern char	AScolor[];
-extern char	AEcolor[];
-# ifndef NO_POPUP
-extern char	POPUPcolor[];
-# endif
-# ifndef NO_VISIBLE
-extern char	VISIBLEcolor[];
-# endif
-extern char	normalcolor[];
-#endif /* undef NO_COLOR */
-
-/* Msdos-versions may use bios; others always termcap.
- * Will emit some 'code has no effect' warnings in unix.
- */
- 
-#if MSDOS
-extern char o_pcbios[1];		/* BAH! */
-#define	CHECKBIOS(x,y)	(*o_pcbios ? (x) : (y))
-#define VOIDBIOS(x,y)	{if (*o_pcbios) {x;} else {y;}}
-#else
-#define	CHECKBIOS(x,y)	(y)
-#define VOIDBIOS(x,y)	{y;}
-#endif
-
-#ifndef NO_COLOR
-# define setcolor(m,a)	CHECKBIOS(bioscolor(m,a), ansicolor(m,a))
-# define fixcolor()	VOIDBIOS(;, tputs(normalcolor, 1, faddch))
-# define quitcolor()	CHECKBIOS(biosquit(), ansiquit())
-# define do_SO()	VOIDBIOS((vmode=A_STANDOUT), tputs(SOcolor, 1, faddch))
-# define do_SE()	VOIDBIOS((vmode=A_NORMAL), tputs(SEcolor, 1, faddch))
-# define do_US()	VOIDBIOS((vmode=A_UNDERLINE), tputs(UScolor, 1, faddch))
-# define do_UE()	VOIDBIOS((vmode=A_NORMAL), tputs(UEcolor, 1, faddch))
-# define do_MD()	VOIDBIOS((vmode=A_BOLD), tputs(MDcolor, 1, faddch))
-# define do_ME()	VOIDBIOS((vmode=A_NORMAL), tputs(MEcolor, 1, faddch))
-# define do_AS()	VOIDBIOS((vmode=A_ALTCHARSET), tputs(AScolor, 1, faddch))
-# define do_AE()	VOIDBIOS((vmode=A_NORMAL), tputs(AEcolor, 1, faddch))
-# define do_POPUP()	VOIDBIOS((vmode=A_POPUP), tputs(POPUPcolor, 1, faddch))
-# define do_VISIBLE()	VOIDBIOS((vmode=A_VISIBLE), tputs(VISIBLEcolor, 1, faddch))
-#else
-# define do_SO()	VOIDBIOS((vmode=A_STANDOUT), tputs(SO, 1, faddch))
-# define do_SE()	VOIDBIOS((vmode=A_NORMAL), tputs(SE, 1, faddch))
-# define do_US()	VOIDBIOS((vmode=A_UNDERLINE), tputs(US, 1, faddch))
-# define do_UE()	VOIDBIOS((vmode=A_NORMAL), tputs(UE, 1, faddch))
-# define do_MD()	VOIDBIOS((vmode=A_BOLD), tputs(MD, 1, faddch))
-# define do_ME()	VOIDBIOS((vmode=A_NORMAL), tputs(ME, 1, faddch))
-# define do_AS()	VOIDBIOS((vmode=A_ALTCHARSET), tputs(AS, 1, faddch))
-# define do_AE()	VOIDBIOS((vmode=A_NORMAL), tputs(AE, 1, faddch))
-# define do_POPUP()	VOIDBIOS((vmode=A_POPUP), tputs(SO, 1, faddch))
-# define do_VISIBLE()	VOIDBIOS((vmode=A_VISIBLE), tputs(MV, 1, faddch))
-#endif
-
-#define	do_VB()		VOIDBIOS(;, tputs(VB, 1, faddch))
-#define	do_UP()		VOIDBIOS(v_up(), tputs(UP, 1, faddch))
-#undef	do_CM		/* move */
-#define	do_CE()		VOIDBIOS(v_ce(), tputs(CE, 1, faddch))
-#define	do_CD()		VOIDBIOS(v_cd(), tputs(CD, 1, faddch))
-#define	do_AL()		VOIDBIOS(v_al(), tputs(AL, LINES, faddch))
-#define	do_DL()		VOIDBIOS(v_dl(), tputs(DL, LINES, faddch))
-#if OSK
-#define	do_SR()		VOIDBIOS(v_sr(), tputs(SR_, 1, faddch))
-#else
-#define	do_SR()		VOIDBIOS(v_sr(), tputs(SR, 1, faddch))
-#endif
-#define do_KS()		VOIDBIOS(1, tputs(KS, 1, faddch))
-#define do_KE()		VOIDBIOS(1, tputs(KE, 1, faddch))
-#define	do_IM()		VOIDBIOS(;, tputs(IM, 1, faddch))
-#define	do_IC()		VOIDBIOS(;, tputs(IC, 1, faddch))
-#define	do_EI()		VOIDBIOS(;, tputs(EI, 1, faddch))
-#define	do_DC()		VOIDBIOS(;, tputs(DC, COLS, faddch))
-#define	do_TI()		VOIDBIOS(;, (void)ttywrite(TI, (unsigned)strlen(TI)))
-#define	do_TE()		VOIDBIOS(;, (void)ttywrite(TE, (unsigned)strlen(TE)))
-#ifndef NO_CURSORSHAPE
-# define do_CQ()	VOIDBIOS(v_cs(), tputs(CQ, 1, faddch))
-# define do_CX()	VOIDBIOS(v_cs(), tputs(CX, 1, faddch))
-# define do_CV()	VOIDBIOS(v_cs(), tputs(CV, 1, faddch))
-# define do_CI()	VOIDBIOS(v_cb(), tputs(CI, 1, faddch))
-# define do_CR()	VOIDBIOS(v_cb(), tputs(CR, 1, faddch))
-#endif
-#ifndef NO_COLOR
-# define do_aend()	VOIDBIOS((vmode=A_NORMAL), endcolor())
-#else
-# define do_aend()	VOIDBIOS((vmode=A_NORMAL), tputs(aend, 1, faddch))
-#endif
-
-#define	has_AM		CHECKBIOS(1, AM)
-#define	has_PT		CHECKBIOS(0, PT)
-#define	has_VB		CHECKBIOS((char *)0, VB)
-#define	has_UP		CHECKBIOS((char *)1, UP)
-#define	has_SO		CHECKBIOS((char)1, (*SO))
-#define	has_SE		CHECKBIOS((char)1, (*SE))
-#define	has_US		CHECKBIOS((char)1, (*US))
-#define	has_UE		CHECKBIOS((char)1, (*UE))
-#define	has_MD		CHECKBIOS((char)1, (*MD))
-#define	has_ME		CHECKBIOS((char)1, (*ME))
-#define	has_AS		CHECKBIOS((char)1, (*AS))
-#define	has_AE		CHECKBIOS((char)1, (*AE))
-#undef	has_CM		/* cursor move: don't need */
-#define	has_CB		CHECKBIOS(1, 0)
-#define	has_CS		CHECKBIOS(1, 0)
-#define	has_CE		CHECKBIOS((char *)1, CE)
-#define	has_CD		CHECKBIOS((char *)1, CD)
-#define	has_AL		CHECKBIOS((char *)1, AL)
-#define	has_DL		CHECKBIOS((char *)1, DL)
-#if OSK
-#define	has_SR		CHECKBIOS((char *)1, SR_)
-#else
-#define	has_SR		CHECKBIOS((char *)1, SR)
-#endif
-#define has_KS		CHECKBIOS((char)1, (*KS))
-#define has_KE		CHECKBIOS((char)1, (*KE))
-#define	has_KU		KU
-#define	has_KD		KD
-#define	has_KL		KL
-#define	has_KR		KR
-#define has_HM		HM
-#define has_EN		EN
-#define has_PU		PU
-#define has_PD		PD
-#define has_KI		KI
-#define	has_IM		CHECKBIOS((char)0, (*IM))
-#define	has_IC		CHECKBIOS((char)0, (*IC))
-#define	has_EI		CHECKBIOS((char)0, (*EI))
-#define	has_DC		CHECKBIOS((char *)0, DC)
-#define	has_TI		CHECKBIOS((char)0, (*TI))
-#define	has_TE		CHECKBIOS((char)0, (*TE))
-#ifndef NO_CURSORSHAPE
-#define has_CQ		CHECKBIOS((char *)1, CQ)
-#endif
-
-/* (pseudo)-Curses-functions */
-
-#ifdef lint
-# define _addCR		VOIDBIOS(;, (stdscr[-1] == '\n' ? qaddch('\r') : (stdscr[-1] = '\n')))
-#else
-# if OSK
-#  define _addCR	VOIDBIOS(;, (stdscr[-1] == '\n' ? qaddch('\l') : (stdscr[-1] = stdscr[-1])))
-# else
-#  define _addCR	VOIDBIOS(;, (stdscr[-1] == '\n' ? qaddch('\r') : 0))
-# endif
-#endif
-
-#ifdef AZTEC_C
-# define qaddch(ch)	CHECKBIOS(v_put(ch), (*stdscr = (ch), *stdscr++))
-#else
-#define qaddch(ch)	CHECKBIOS(v_put(ch), (*stdscr++ = (ch)))
-#endif
-
-#if OSK
-#define addch(ch)	if (qaddch(ch) == '\n') qaddch('\l'); else
-#else
-#define addch(ch)	if (qaddch(ch) == '\n') qaddch('\r'); else
-#endif
-
-extern void initscr();
-extern void endwin();
-extern void suspend_curses();
-extern void resume_curses();
-extern void attrset();
-extern void insch();
-extern void qaddstr();
-extern void wrefresh();
-extern void wqrefresh();
-#define addstr(str)	{qaddstr(str); _addCR;}
-#define move(y,x)	VOIDBIOS(v_move(x,y), tputs(tgoto(CM, x, y), 1, faddch))
-#define mvaddch(y,x,ch)	{move(y,x); addch(ch);}
-#define refresh()	VOIDBIOS(;, wrefresh())
-#define standout()	do_SO()
-#define standend()	do_SE()
-#define clrtoeol()	do_CE()
-#define clrtobot()	do_CD()
-#define insertln()	do_AL()
-#define deleteln()	do_DL()
-#define delch()		do_DC()
-#define scrollok(w,b)
-#define raw()
-#define echo()
-#define cbreak()
-#define noraw()
-#define noecho()
-#define nocbreak()
Index: trunk/minix/commands/elvis/cut.c
===================================================================
--- trunk/minix/commands/elvis/cut.c	(revision 9)
+++ 	(revision )
@@ -1,700 +1,0 @@
-/* cut.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains function which manipulate the cut buffers. */
-
-#include "config.h"
-#include "vi.h"
-#if TURBOC
-#include <process.h>		/* needed for getpid */
-#endif
-#if TOS
-#include <osbind.h>
-#define	rename(a,b)	Frename(0,a,b)
-#endif
-
-# define NANONS	9	/* number of anonymous buffers */
-
-static struct cutbuf
-{
-	short	*phys;	/* pointer to an array of #s of BLKs containing text */
-	int	nblks;	/* number of blocks in phys[] array */
-	int	start;	/* offset into first block of start of cut */
-	int	end;	/* offset into last block of end of cut */
-	int	tmpnum;	/* ID number of the temp file */
-	char	lnmode;	/* boolean: line-mode cut? (as opposed to char-mode) */
-}
-	named[27],	/* cut buffers "a through "z and ". */
-	anon[NANONS];	/* anonymous cut buffers */
-
-static char	cbname;	/* name chosen for next cut/paste operation */
-static char	dotcb;	/* cut buffer to use if "doingdot" is set */
-
-
-#ifndef NO_RECYCLE
-/* This function builds a list of all blocks needed in the current tmp file
- * for the contents of cut buffers.
- * !!! WARNING: if you have more than ~450000 bytes of text in all of the
- * cut buffers, then this will fail disastrously, because buffer overflow
- * is *not* allowed for.
- */
-int cutneeds(need)
-	BLK		*need;	/* this is where we deposit the list */
-{
-	struct cutbuf	*cb;	/* used to count through cut buffers */
-	int		i;	/* used to count through blocks of a cut buffer */
-	int		n;	/* total number of blocks in list */
-
-	n = 0;
-
-	/* first the named buffers... */
-	for (cb = named; cb < &named[27]; cb++)
-	{
-		if (cb->tmpnum != tmpnum)
-			continue;
-
-		for (i = cb->nblks; i-- > 0; )
-		{
-			need->n[n++] = cb->phys[i];
-		}
-	}
-
-	/* then the anonymous buffers */
-	for (cb = anon; cb < &anon[NANONS]; cb++)
-	{
-		if (cb->tmpnum != tmpnum)
-			continue;
-
-		for (i = cb->nblks; i-- > 0; )
-		{
-			need->n[n++] = cb->phys[i];
-		}
-	}
-
-	/* return the length of the list */
-	return n;
-}
-#endif
-
-static void maybezap(num)
-	int	num;	/* the tmpnum of the temporary file to [maybe] delete */
-{
-	char	cutfname[80];
-	int	i;
-
-	/* if this is the current tmp file, then we'd better keep it! */
-	if (tmpfd >= 0 && num == tmpnum)
-	{
-		return;
-	}
-
-	/* see if anybody else needs this tmp file */
-	for (i = 27; --i >= 0; )
-	{
-		if (named[i].nblks > 0 && named[i].tmpnum == num)
-		{
-			break;
-		}
-	}
-	if (i < 0)
-	{
-		for (i = NANONS; --i >= 0 ; )
-		{
-			if (anon[i].nblks > 0 && anon[i].tmpnum == num)
-			{
-				break;
-			}
-		}
-	}
-
-	/* if nobody else needs it, then discard the tmp file */
-	if (i < 0)
-	{
-#if MSDOS || TOS
-		strcpy(cutfname, o_directory);
-		if ((i = strlen(cutfname)) && !strchr(":/\\", cutfname[i - 1]))
-			cutfname[i++] = SLASH;
-		sprintf(cutfname + i, TMPNAME + 3, getpid(), num);
-#else
-		sprintf(cutfname, TMPNAME, o_directory, getpid(), num);
-#endif
-		unlink(cutfname);
-	}
-}
-
-/* This function frees a cut buffer.  If it was the last cut buffer that
- * refered to an old temp file, then it will delete the temp file. */
-static void cutfree(buf)
-	struct cutbuf	*buf;
-{
-	int	num;
-
-	/* return immediately if the buffer is already empty */
-	if (buf->nblks <= 0)
-	{
-		return;
-	}
-
-	/* else free up stuff */
-	num = buf->tmpnum;
-	buf->nblks = 0;
-#ifdef DEBUG
-	if (!buf->phys)
-		msg("cutfree() tried to free a NULL buf->phys pointer.");
-	else
-#endif
-	free((char *)buf->phys);
-
-	/* maybe delete the temp file */
-	maybezap(num);
-}
-
-/* This function is called when we are about to abort a tmp file.
- *
- * To minimize the number of extra files lying around, only named cut buffers
- * are preserved in a file switch; the anonymous buffers just go away.
- */
-void cutswitch()
-{
-	int	i;
-
-	/* mark the current temp file as being "obsolete", and close it.  */
-	storename((char *)0);
-	close(tmpfd);
-	tmpfd = -1;
-
-	/* discard all anonymous cut buffers */
-	for (i = 0; i < NANONS; i++)
-	{
-		cutfree(&anon[i]);
-	}
-
-	/* delete the temp file, if we don't really need it */
-	maybezap(tmpnum);
-}
-
-/* This function should be called just before termination of vi */
-void cutend()
-{
-	int	i;
-
-	/* free the anonymous buffers, if they aren't already free */
-	cutswitch();
-
-	/* free all named cut buffers, since they might be forcing an older
-	 * tmp file to be retained.
-	 */
-	for (i = 0; i < 27; i++)
-	{
-		cutfree(&named[i]);
-	}
-
-	/* delete the temp file */
-	maybezap(tmpnum);
-}
-
-
-/* This function is used to select the cut buffer to be used next */
-void cutname(name)
-	int	name;	/* a single character */
-{
-	cbname = name;
-}
-
-
-
-
-/* This function copies a selected segment of text to a cut buffer */
-void cut(from, to)
-	MARK	from;		/* start of text to cut */
-	MARK	to;		/* end of text to cut */
-{
-	int		first;	/* logical number of first block in cut */
-	int		last;	/* logical number of last block used in cut */
-	long		line;	/* a line number */
-	int		lnmode;	/* boolean: will this be a line-mode cut? */
-	MARK		delthru;/* end of text temporarily inserted for apnd */
-	REG struct cutbuf *cb;
-	REG long	l;
-	REG int		i;
-	REG char	*scan;
-	char		*blkc;
-
-	/* detect whether this must be a line-mode cut or char-mode cut */
-	if (markidx(from) == 0 && markidx(to) == 0)
-		lnmode = TRUE;
-	else
-		lnmode = FALSE;
-
-	/* by default, we don't "delthru" anything */
-	delthru = MARK_UNSET;
-
-	/* handle the "doingdot" quirks */
-	if (doingdot)
-	{
-		if (!cbname)
-		{
-			cbname = dotcb;
-		}
-	}
-	else if (cbname != '.')
-	{
-		dotcb = cbname;
-	}
-
-	/* decide which cut buffer to use */
-	if (!cbname)
-	{
-		/* free up the last anonymous cut buffer */
-		cutfree(&anon[NANONS - 1]);
-
-		/* shift the anonymous cut buffers */
-		for (i = NANONS - 1; i > 0; i--)
-		{
-			anon[i] = anon[i - 1];
-		}
-
-		/* use the first anonymous cut buffer */
-		cb = anon;
-		cb->nblks = 0;
-	}
-	else if (cbname >= 'a' && cbname <= 'z')
-	{
-		cb = &named[cbname - 'a'];
-		cutfree(cb);
-	}
-#ifndef CRUNCH
-	else if (cbname >= 'A' && cbname <= 'Z')
-	{
-		cb = &named[cbname - 'A'];
-		if (cb->nblks > 0)
-		{
-			/* resolve linemode/charmode differences */
-			if (!lnmode && cb->lnmode)
-			{
-				from &= ~(BLKSIZE - 1);
-				if (markidx(to) != 0 || to == from)
-				{
-					to = to + BLKSIZE - markidx(to);
-				}
-				lnmode = TRUE;
-			}
-
-			/* insert the old cut-buffer before the new text */
-			mark[28] = to;
-			delthru = paste(from, FALSE, TRUE);
-			if (delthru == MARK_UNSET)
-			{
-				return;
-			}
-			delthru++;
-			to = mark[28];
-		}
-		cutfree(cb);
-	}
-#endif /* not CRUNCH */
-	else if (cbname == '.')
-	{
-		cb = &named[26];
-		cutfree(cb);
-	}
-	else
-	{
-		msg("Invalid cut buffer name: \"%c", cbname);
-		dotcb = cbname = '\0';
-		return;
-	}
-	cbname = '\0';
-	cb->tmpnum = tmpnum;
-
-	/* detect whether we're doing a line mode cut */
-	cb->lnmode = lnmode;
-
-	/* ---------- */
-
-	/* Reporting... */	
-	if (markidx(from) == 0 && markidx(to) == 0)
-	{
-		rptlines = markline(to) - markline(from);
-		rptlabel = "yanked";
-	}
-
-	/* ---------- */
-
-	/* make sure each block has a physical disk address */
-	blksync();
-
-	/* find the first block in the cut */
-	line = markline(from);
-	for (first = 1; line > lnum[first]; first++)
-	{
-	}
-
-	/* fetch text of the block containing that line */
-	blkc = scan = blkget(first)->c;
-
-	/* find the mark in the block */
-	for (l = lnum[first - 1]; ++l < line; )
-	{
-		while (*scan++ != '\n')
-		{
-		}
-	}
-	scan += markidx(from);
-
-	/* remember the offset of the start */
-	cb->start = scan - blkc;
-
-	/* ---------- */
-
-	/* find the last block in the cut */
-	line = markline(to);
-	for (last = first; line > lnum[last]; last++)
-	{
-	}
-
-	/* fetch text of the block containing that line */
-	if (last != first)
-	{
-		blkc = scan = blkget(last)->c;
-	}
-	else
-	{
-		scan = blkc;
-	}
-
-	/* find the mark in the block */
-	for (l = lnum[last - 1]; ++l < line; )
-	{
-		while (*scan++ != '\n')
-		{
-		}
-	}
-	if (markline(to) <= nlines)
-	{
-		scan += markidx(to);
-	}
-
-	/* remember the offset of the end */
-	cb->end = scan - blkc;
-
-	/* ------- */
-
-	/* remember the physical block numbers of all included blocks */
-	cb->nblks = last - first;
-	if (cb->end > 0)
-	{
-		cb->nblks++;
-	}
-#ifdef lint
-	cb->phys = (short *)0;
-#else
-	cb->phys = (short *)malloc((unsigned)(cb->nblks * sizeof(short)));
-#endif
-	for (i = 0; i < cb->nblks; i++)
-	{
-		cb->phys[i] = hdr.n[first++];
-	}
-
-#ifndef CRUNCH
-	/* if we temporarily inserted text for appending, then delete that
-	 * text now -- before the user sees it.
-	 */
-	if (delthru)
-	{
-		line = rptlines;
-		delete(from, delthru);
-		rptlines = line;
-		rptlabel = "yanked";
-	}
-#endif /* not CRUNCH */
-}
-
-
-static void readcutblk(cb, blkno)
-	struct cutbuf	*cb;
-	int		blkno;
-{
-	char		cutfname[50];/* name of an old temp file */
-	int		fd;	/* either tmpfd or the result of open() */
-#if MSDOS || TOS
-	int		i;
-#endif
-
-	/* decide which fd to use */
-	if (cb->tmpnum == tmpnum)
-	{
-		fd = tmpfd;
-	}
-	else
-	{
-#if MSDOS || TOS
-		strcpy(cutfname, o_directory);
-		if ((i = strlen(cutfname)) && !strchr(":/\\", cutfname[i-1]))
-			cutfname[i++]=SLASH;
-		sprintf(cutfname+i, TMPNAME+3, getpid(), cb->tmpnum);
-#else
-		sprintf(cutfname, TMPNAME, o_directory, getpid(), cb->tmpnum);
-#endif
-		fd = open(cutfname, O_RDONLY);
-	}
-
-	/* get the block */
-	lseek(fd, (long)cb->phys[blkno] * (long)BLKSIZE, 0);
-	if (read(fd, tmpblk.c, (unsigned)BLKSIZE) != BLKSIZE)
-	{
-		msg("Error reading back from tmp file for pasting!");
-	}
-
-	/* close the fd, if it isn't tmpfd */
-	if (fd != tmpfd)
-	{
-		close(fd);
-	}
-}
-
-
-/* This function inserts text from a cut buffer, and returns the MARK where
- * insertion ended.  Return MARK_UNSET on errors.
- */
-MARK paste(at, after, retend)
-	MARK	at;	/* where to insert the text */
-	int	after;	/* boolean: insert after mark? (rather than before) */
-	int	retend;	/* boolean: return end of text? (rather than start) */
-{
-	REG struct cutbuf	*cb;
-	REG int			i;
-
-	/* handle the "doingdot" quirks */
-	if (doingdot)
-	{
-		if (!cbname)
-		{
-			if (dotcb >= '1' && dotcb < '1' + NANONS - 1)
-			{
-				dotcb++;
-			}
-			cbname = dotcb;
-		}
-	}
-	else if (cbname != '.')
-	{
-		dotcb = cbname;
-	}
-
-	/* decide which cut buffer to use */
-	if (cbname >= 'A' && cbname <= 'Z')
-	{
-		cb = &named[cbname - 'A'];
-	}
-	else if (cbname >= 'a' && cbname <= 'z')
-	{
-		cb = &named[cbname - 'a'];
-	}
-	else if (cbname >= '1' && cbname <= '9')
-	{
-		cb = &anon[cbname - '1'];
-	}
-	else if (cbname == '.')
-	{
-		cb = &named[26];
-	}
-	else if (!cbname)
-	{
-		cb = anon;
-	}
-	else
-	{
-		msg("Invalid cut buffer name: \"%c", cbname);
-		cbname = '\0';
-		return MARK_UNSET;
-	}
-
-	/* make sure it isn't empty */
-	if (cb->nblks == 0)
-	{
-		if (cbname)
-			msg("Cut buffer \"%c is empty", cbname);
-		else
-			msg("Cut buffer is empty");
-		cbname = '\0';
-		return MARK_UNSET;
-	}
-	cbname = '\0';
-
-	/* adjust the insertion MARK for "after" and line-mode cuts */
-	if (cb->lnmode)
-	{
-		at &= ~(BLKSIZE - 1);
-		if (after)
-		{
-			at += BLKSIZE;
-		}
-	}
-	else if (after)
-	{
-		/* careful! if markidx(at) == 0 we might be pasting into an
-		 * empty line -- so we can't blindly increment "at".
-		 */
-		if (markidx(at) == 0)
-		{
-			pfetch(markline(at));
-			if (plen != 0)
-			{
-				at++;
-			}
-		}
-		else
-		{
-			at++;
-		}
-	}
-
-	/* put a copy of the "at" mark in the mark[] array, so it stays in
-	 * sync with changes made via add().
-	 */
-	mark[27] = at;
-
-	/* simple one-block paste? */
-	if (cb->nblks == 1)
-	{
-		/* get the block */
-		readcutblk(cb, 0);
-
-		/* isolate the text we need within it */
-		if (cb->end)
-		{
-			tmpblk.c[cb->end] = '\0';
-		}
-
-		/* insert it */
-		ChangeText
-		{
-			add(at, &tmpblk.c[cb->start]);
-		}
-	}
-	else
-	{
-		/* multi-block paste */
-
-		ChangeText
-		{
-			i = cb->nblks - 1;
-
-			/* add text from the last block first */
-			if (cb->end > 0)
-			{
-				readcutblk(cb, i);
-				tmpblk.c[cb->end] = '\0';
-				add(at, tmpblk.c);
-				i--;
-			}
-
-			/* add intervening blocks */
-			while (i > 0)
-			{
-				readcutblk(cb, i);
-				add(at, tmpblk.c);
-				i--;
-			}
-
-			/* add text from the first cut block */
-			readcutblk(cb, 0);
-			add(at, &tmpblk.c[cb->start]);
-		}
-	}
-
-	/* Reporting... */
-	rptlines = markline(mark[27]) - markline(at);
-	rptlabel = "pasted";
-
-	/* return the mark at the beginning/end of inserted text */
-	if (retend)
-	{
-		return mark[27] - 1L;
-	}
-	return at;
-}
-
-
-
-
-#ifndef NO_AT
-
-/* This function copies characters from a cut buffer into a string.
- * It returns the number of characters in the cut buffer.  If the cut
- * buffer is too large to fit in the string (i.e. if cb2str() returns
- * a number >= size) then the characters will not have been copied.
- * It returns 0 if the cut buffer is empty, and -1 for invalid cut buffers.
- */
-int cb2str(name, buf, size)
-	int	name;	/* the name of a cut-buffer to get: a-z only! */
-	char	*buf;	/* where to put the string */
-	unsigned size;	/* size of buf */
-{
-	REG struct cutbuf	*cb;
-	REG char		*src;
-	REG char		*dest;
-
-	/* decide which cut buffer to use */
-	if (name >= 'a' && name <= 'z')
-	{
-		cb = &named[name - 'a'];
-	}
-	else
-	{
-		return -1;
-	}
-
-	/* if the buffer is empty, return 0 */
-	if (cb->nblks == 0)
-	{
-		return 0;
-	}
-
-	/* !!! if not a single-block cut, then fail */
-	if (cb->nblks != 1)
-	{
-		return size;
-	}
-
-	/* if too big, return the size now, without doing anything */
-	if (cb->end - cb->start >= size)
-	{
-		return cb->end - cb->start;
-	}
-
-	/* get the block */
-	readcutblk(cb, 0);
-
-	/* isolate the string within that blk */
-	if (cb->start == 0)
-	{
-		tmpblk.c[cb->end] = '\0';
-	}
-	else
-	{
-		for (dest = tmpblk.c, src = dest + cb->start; src < tmpblk.c + cb->end; )
-		{
-			*dest++ = *src++;
-		}
-		*dest = '\0';
-	}
-
-	/* copy the string into the buffer */
-	if (buf != tmpblk.c)
-	{
-		strcpy(buf, tmpblk.c);
-	}
-
-	/* return the length */
-	return cb->end - cb->start;
-}
-#endif
Index: trunk/minix/commands/elvis/elvprsv.c
===================================================================
--- trunk/minix/commands/elvis/elvprsv.c	(revision 9)
+++ 	(revision )
@@ -1,287 +1,0 @@
-/* elvprsv.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the portable sources for the "elvprsv" program.
- * "Elvprsv" is run by Elvis when Elvis is about to die.  It is also
- * run when the computer boots up.  It is not intended to be run directly
- * by the user, ever.
- *
- * Basically, this program does the following four things:
- *    - It extracts the text from the temporary file, and places the text in
- *	a file in the /usr/preserve directory.
- *    - It adds a line to the /usr/preserve/Index file, describing the file
- *	that it just preserved.
- *    - It removes the temporary file.
- *    -	It sends mail to the owner of the file, saying that the file was
- *	preserved, and how it can be recovered.
- *
- * The /usr/preserve/Index file is a log file that contains one line for each
- * file that has ever been preserved.  Each line of this file describes one
- * preserved file.  The first word on the line is the name of the file that
- * contains the preserved text.  The second word is the full pathname of the
- * file that was being edited; for anonymous buffers, this is the directory
- * name plus "/foo".
- *
- * If elvprsv's first argument (after the command name) starts with a hyphen,
- * then the characters after the hyphen are used as a description of when
- * the editor went away.  This is optional.
- *
- * The remaining arguments are all the names of temporary files that are
- * to be preserved.  For example, on a UNIX system, the /etc/rc file might
- * invoke it this way:
- *
- *	elvprsv "-the system went down" /tmp/elv_*.*
- *
- * This file contains only the portable parts of the preserve program.
- * It must #include a system-specific file.  The system-specific file is
- * expected to define the following functions:
- *
- *	char *ownername(char *filename)	- returns name of person who owns file
- *
- *	void mail(char *user, char *name, char *when)
- *					- tell user that file was preserved
- */
-
-#include <stdio.h>
-#include "config.h"
-#include "vi.h"
-
-#if AMIGA
-BLK tmpblk;
-#error AMIGA here DEBUG
-# include "amiwild.c"
-# include "amiprsv.c"
-#endif
-
-#if OSK
-# undef sprintf
-#endif
-
-#if ANY_UNIX || OSK
-# include "prsvunix.c"
-#endif
-
-#if MSDOS || TOS
-# include "prsvdos.c"
-# define WILDCARD_NO_MAIN
-# include "wildcard.c"
-#endif
-
-
-BLK	buf;
-BLK	hdr;
-BLK	name;
-int	rewrite_now;	/* boolean: should we send text directly to orig file? */
-
-
-
-/* This function preserves a single file, and announces its success/failure
- * via an e-mail message.
- */
-void preserve(tname, when)
-	char	*tname;		/* name of a temp file to be preserved */
-	char	*when;		/* description of when the editor died */
-{
-	int	infd;		/* fd used for reading from the temp file */
-	FILE	*outfp;		/* fp used for writing to the recovery file */
-	FILE	*index;		/* fp used for appending to index file */
-	char	outname[100];	/* the name of the recovery file */
-	char	*user;		/* name of the owner of the temp file */
-#if AMIGA
-	char	*prsvdir;
-#endif
-	int	i;
-
-	/* open the temp file */
-	infd = open(tname, O_RDONLY|O_BINARY);
-	if (infd < 0)
-	{
-		/* if we can't open the file, then we should assume that
-		 * the filename contains wildcard characters that weren't
-		 * expanded... and also assume that they weren't expanded
-		 * because there are no files that need to be preserved.
-		 * THEREFORE... we should silently ignore it.
-		 * (Or loudly ignore it if the user was using -R)
-		 */
-		if (rewrite_now)
-		{
-			perror(tname);
-		}
-		return;
-	}
-
-	/* read the header and name from the file */
-	if (read(infd, hdr.c, BLKSIZE) != BLKSIZE
-	 || read(infd, name.c, BLKSIZE) != BLKSIZE)
-	{
-		/* something wrong with the file - sorry */
-		fprintf(stderr, "%s: trucated header blocks\n", tname);
-		close(infd);
-		return;
-	}
-
-	/* If the filename block contains an empty string, then Elvis was
-	 * only keeping the temp file around because it contained some text
-	 * that was needed for a named cut buffer.  The user doesn't care
-	 * about that kind of temp file, so we should silently delete it.
-	 */
-	if (name.c[0] == '\0' && name.c[1] == '\177')
-	{
-		close(infd);
-		unlink(tname);
-		return;
-	}
-
-	if (rewrite_now)
-	{
-		/* we don't need to open the index file */
-		index = (FILE *)0;
-
-		/* make sure we can read every block! */
-		for (i = 1; i < MAXBLKS && hdr.n[i]; i++)
-		{
-			lseek(infd, (long)hdr.n[i] * (long)BLKSIZE, 0);
-			if (read(infd, buf.c, BLKSIZE) != BLKSIZE)
-			{
-				/* messed up header */
-				fprintf(stderr, "%s: unrecoverable -- header trashed\n", name.c);
-				close(infd);
-				return;
-			}
-		}
-
-		/* open the user's file for writing */
-		outfp = fopen(name.c, "w");
-		if (!outfp)
-		{
-			perror(name.c);
-			close(infd);
-			return;
-		}
-	}
-	else
-	{
-		/* open/create the index file */
-		index = fopen(PRSVINDEX, "a");
-		if (!index)
-		{
-			perror(PRSVINDEX);
-			exit(1);
-		}
-
-		/* create the recovery file in the PRESVDIR directory */
-#if AMIGA
-		prsvdir = &PRSVDIR[strlen(PRSVDIR) - 1];
-		if (*prsvdir == '/' || *prsvdir == ':')
-		{
-			sprintf(outname, "%sp%ld", PRSVDIR, ftell(index));
-		}
-		else
-#endif
-		sprintf(outname, "%s%cp%ld", PRSVDIR, SLASH, ftell(index));
-		outfp = fopen(outname, "w");
-		if (!outfp)
-		{
-			perror(outname);
-			close(infd);
-			fclose(index);
-			return;
-		}
-	}
-
-	/* write the text of the file out to the recovery file */
-	for (i = 1; i < MAXBLKS && hdr.n[i]; i++)
-	{
-		lseek(infd, (long)hdr.n[i] * (long)BLKSIZE, 0);
-		if (read(infd, buf.c, BLKSIZE) != BLKSIZE)
-		{
-			/* messed up header */
-			fprintf(stderr, "%s: unrecoverable -- header trashed\n", name.c);
-			fclose(outfp);
-			close(infd);
-			if (index)
-			{
-				fclose(index);
-			}
-			unlink(outname);
-			return;
-		}
-		fputs(buf.c, outfp);
-	}
-
-	/* add a line to the index file */
-	if (index)
-	{
-		fprintf(index, "%s %s\n", outname, name.c);
-	}
-
-	/* close everything */
-	close(infd);
-	fclose(outfp);
-	if (index)
-	{
-		fclose(index);
-	}
-
-	/* Are we doing this due to something more frightening than just
-	 * a ":preserve" command?
-	 */
-	if (*when)
-	{
-		/* send a mail message */
-		mail(ownername(tname), name.c, when);
-
-		/* remove the temp file -- the editor has died already */
-		unlink(tname);
-	}
-}
-
-main(argc, argv)
-	int	argc;
-	char	**argv;
-{
-	int	i;
-	char	*when = "the editor went away";
-
-#if MSDOS || TOS
-	/* expand any wildcards in the command line */
-	argv = wildexpand(&argc, argv);
-#endif
-
-	/* do we have a "when" argument? */
-	i = 1;
-	if (argc >= i + 1 && !strcmp(argv[i], "-R"))
-	{
-		rewrite_now = 1;
-		when = "";
-		i++;
-#if ANY_UNIX
-		setuid(geteuid());
-#endif
-	}
-#if OSK
-	else
-	{
-		setuid(0);
-	}
-#endif
-	if (argc >= i + 1 && argv[i][0] == '-')
-	{
-		when = argv[i] + 1;
-		i++;
-	}
-
-	/* preserve everything we're supposed to */
-	while (i < argc)
-	{
-		preserve(argv[i], when);
-		i++;
-	}
-}
Index: trunk/minix/commands/elvis/elvrec.c
===================================================================
--- trunk/minix/commands/elvis/elvrec.c	(revision 9)
+++ 	(revision )
@@ -1,199 +1,0 @@
-/* elvrec.c */
-
-/* This file contains the file recovery program */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-#include <stdio.h>
-#include "config.h"
-#include "vi.h"
-#include <sys/stat.h>
-
-void recover(basename, outname)
-	char	*basename;	/* the name of the file to recover */
-	char	*outname;	/* the name of the file to write to */
-{
-	char	pathname[500];	/* full pathname of the file to recover */
-	char	line[600];	/* a line from the /usr/preserve/Index file */
-	int	ch;		/* a character from the text being recovered */
-	FILE	*from;		/* the /usr/preserve file, or /usr/preserve/Index */
-	FILE	*to;		/* the user's text file */
-	char	*ptr;
-	struct stat st;
-#if OSK
-	int		uid;
-#endif
-
-	/* convert basename to a full pathname */
-	if (basename)
-	{
-#ifndef CRUNCH
-# if MSDOS || TOS
-		if (!basename[0] || basename[1] != ':')
-# else
-		if (basename[0] != SLASH)
-# endif
-		{
-			ptr = getcwd(pathname, sizeof pathname);
-			if (ptr != pathname)
-			{
-				strcpy(pathname, ptr);
-			}
-			ptr = pathname + strlen(pathname);
-			*ptr++ = SLASH;
-			strcpy(ptr, basename);
-		}
-		else
-#endif
-		{
-			strcpy(pathname, basename);
-		}
-	}
-
-#if OSK
-	uid = getuid();
-	if(setuid(0))
-		exit(_errmsg(errno, "Can't set uid\n"));
-#endif
-	/* scan the /usr/preserve/Index file, for the *oldest* unrecovered
-	 * version of this file.
-	 */
-	from = fopen(PRSVINDEX, "r");
-	while (from && fgets(line, sizeof line, from))
-	{
-		/* strip off the newline from the end of the string */
-		line[strlen(line) - 1] = '\0';
-
-		/* parse the line into a "preserve" name and a "text" name */
-		for (ptr = line; *ptr != ' '; ptr++)
-		{
-		}
-		*ptr++ = '\0';
-
-		/* If the "preserve" file is missing, then ignore this line
-		 * because it describes a file that has already been recovered.
-		 */
-		if (stat(line, &st) < 0)
-		{
-			continue;
-		}
-
-		/* are we looking for a specific file? */
-		if (basename)
-		{
-			/* quit if we found it */
-			if (!strcmp(ptr, pathname))
-			{
-				break;
-			}
-		}
-		else
-		{
-			/* list this file as "available for recovery" */
-			puts(ptr);
-		}
-	}
-
-	/* file not found? */
-	if (!basename || !from || feof(from))
-	{
-		if (from != NULL) fclose(from);
-		if (basename)
-		{
-			fprintf(stderr, "%s: no recovered file has that exact name\n", pathname);
-		}
-		return;
-	}
-	if (from != NULL) fclose(from);
-
-	/* copy the recovered text back into the user's file... */
-
-	/* open the /usr/preserve file for reading */
-	from = fopen(line, "r");
-	if (!from)
-	{
-		perror(line);
-		exit(2);
-	}
-
-#if ANY_UNIX
-	/* Be careful about user-id.  We want to be running under the user's
-	 * real id when we open/create the user's text file... but we want
-	 * to be superuser when we delete the /usr/preserve file.  For UNIX,
-	 * we accomplish this by deleting the /usr/preserve file *now*,
-	 * when it is open but before we've read it.  Then we revert to the
-	 * user's real id.
-	 */
-	unlink(line);
-	setuid(getuid());
-#endif
-#if OSK
-	setuid(uid);
-#endif
-
-	if (outname == NULL) return;
-
-	/* open the user's file for writing */
-	to = fopen(outname, "w");
-	if (!to)
-	{
-		perror(ptr);
-		exit(2);
-	}
-
-	/* copy the text */
-	while ((ch = getc(from)) != EOF)
-	{
-		putc(ch, to);
-	}
-
-#if !ANY_UNIX
-#if OSK
-	fclose(from);
-	setuid(0);
-#endif
-	/* delete the /usr/preserve file */
-	unlink(line);
-#if OSK
-	setuid(uid);
-#endif
-#endif
-}
-
-main(argc, argv)
-	int	argc;
-	char	**argv;
-{
-	/* check arguments */
-	if (argc > 3)
-	{
-		fprintf(stderr, "usage: %s [preserved_file [recovery_file]]\n", argv[0]);
-		exit(1);
-	}
-
-	/* recover the requested file, or list recoverable files */
-	if (argc == 3)
-	{
-		/* recover the file, but write it to a different filename */
-		recover (argv[1], argv[2]);
-	}
-	else if (argc == 2)
-	{
-		/* recover the file */
-		recover(argv[1], argv[1]);
-	}
-	else
-	{
-		/* list the recoverable files */
-		recover((char *)0, (char *)0);
-	}
-
-	/* success! */
-	exit(0);
-}
Index: trunk/minix/commands/elvis/ex.c
===================================================================
--- trunk/minix/commands/elvis/ex.c	(revision 9)
+++ 	(revision )
@@ -1,722 +1,0 @@
-/* ex.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the code for reading ex commands. */
-
-#include "config.h"
-#include "ctype.h"
-#include "vi.h"
-
-/* This data type is used to describe the possible argument combinations */
-typedef short ARGT;
-#define FROM	1		/* allow a linespec */
-#define	TO	2		/* allow a second linespec */
-#define BANG	4		/* allow a ! after the command name */
-#define EXTRA	8		/* allow extra args after command name */
-#define XFILE	16		/* expand wildcards in extra part */
-#define NOSPC	32		/* no spaces allowed in the extra part */
-#define	DFLALL	64		/* default file range is 1,$ */
-#define DFLNONE	128		/* no default file range */
-#define NODFL	256		/* do not default to the current file name */
-#define EXRCOK	512		/* can be in a .exrc file */
-#define NL	1024		/* if mode!=MODE_EX, then write a newline first */
-#define PLUS	2048		/* allow a line number, as in ":e +32 foo" */
-#define ZERO	4096		/* allow 0 to be given as a line number */
-#define NOBAR	8192		/* treat following '|' chars as normal */
-#define FILES	(XFILE + EXTRA)	/* multiple extra files allowed */
-#define WORD1	(EXTRA + NOSPC)	/* one extra word allowed */
-#define FILE1	(FILES + NOSPC)	/* 1 file allowed, defaults to current file */
-#define NAMEDF	(FILE1 + NODFL)	/* 1 file allowed, defaults to "" */
-#define NAMEDFS	(FILES + NODFL)	/* multiple files allowed, default is "" */
-#define RANGE	(FROM + TO)	/* range of linespecs allowed */
-#define NONE	0		/* no args allowed at all */
-
-/* This array maps ex command names to command codes. The order in which
- * command names are listed below is significant -- ambiguous abbreviations
- * are always resolved to be the first possible match.  (e.g. "r" is taken
- * to mean "read", not "rewind", because "read" comes before "rewind")
- */
-static struct
-{
-	char	*name;	/* name of the command */
-	CMD	code;	/* enum code of the command */
-	void	(*fn)();/* function which executes the command */
-	ARGT	argt;	/* command line arguments permitted/needed/used */
-}
-	cmdnames[] =
-{   /*	cmd name	cmd code	function	arguments */
-	{"append",	CMD_APPEND,	cmd_append,	FROM+ZERO+BANG	},
-#ifdef DEBUG
-	{"bug",		CMD_DEBUG,	cmd_debug,	RANGE+BANG+EXTRA+NL},
-#endif
-	{"change",	CMD_CHANGE,	cmd_append,	RANGE+BANG	},
-	{"delete",	CMD_DELETE,	cmd_delete,	RANGE+WORD1	},
-	{"edit",	CMD_EDIT,	cmd_edit,	BANG+FILE1+PLUS	},
-	{"file",	CMD_FILE,	cmd_file,	NAMEDF		},
-	{"global",	CMD_GLOBAL,	cmd_global,	RANGE+BANG+EXTRA+DFLALL+NOBAR},
-	{"insert",	CMD_INSERT,	cmd_append,	FROM+BANG	},
-	{"join",	CMD_INSERT,	cmd_join,	RANGE+BANG	},
-	{"k",		CMD_MARK,	cmd_mark,	FROM+WORD1	},
-	{"list",	CMD_LIST,	cmd_print,	RANGE+NL	},
-	{"move",	CMD_MOVE,	cmd_move,	RANGE+EXTRA	},
-	{"next",	CMD_NEXT,	cmd_next,	BANG+NAMEDFS	},
-	{"Next",	CMD_PREVIOUS,	cmd_next,	BANG		},
-	{"print",	CMD_PRINT,	cmd_print,	RANGE+NL	},
-	{"quit",	CMD_QUIT,	cmd_xit,	BANG		},
-	{"read",	CMD_READ,	cmd_read,	FROM+ZERO+NAMEDF},
-	{"substitute",	CMD_SUBSTITUTE,	cmd_substitute,	RANGE+EXTRA	},
-	{"to",		CMD_COPY,	cmd_move,	RANGE+EXTRA	},
-	{"undo",	CMD_UNDO,	cmd_undo,	NONE		},
-	{"vglobal",	CMD_VGLOBAL,	cmd_global,	RANGE+EXTRA+DFLALL+NOBAR},
-	{"write",	CMD_WRITE,	cmd_write,	RANGE+BANG+FILE1+DFLALL},
-	{"xit",		CMD_XIT,	cmd_xit,	BANG+NL		},
-	{"yank",	CMD_YANK,	cmd_delete,	RANGE+WORD1	},
-
-	{"!",		CMD_BANG,	cmd_shell,	EXRCOK+RANGE+NAMEDFS+DFLNONE+NL+NOBAR},
-	{"#",		CMD_NUMBER,	cmd_print,	RANGE+NL	},
-	{"<",		CMD_SHIFTL,	cmd_shift,	RANGE		},
-	{">",		CMD_SHIFTR,	cmd_shift,	RANGE		},
-	{"=",		CMD_EQUAL,	cmd_file,	RANGE		},
-	{"&",		CMD_SUBAGAIN,	cmd_substitute,	RANGE		},
-#ifndef NO_AT
-	{"@",		CMD_AT,		cmd_at,		EXTRA		},
-#endif
-
-#ifndef NO_ABBR
-	{"abbreviate",	CMD_ABBR,	cmd_map,	EXRCOK+BANG+EXTRA},
-#endif
-	{"args",	CMD_ARGS,	cmd_args,	EXRCOK+NAMEDFS	},
-#ifndef NO_ERRLIST
-	{"cc",		CMD_CC,		cmd_make,	BANG+FILES	},
-#endif
-	{"cd",		CMD_CD,		cmd_cd,		EXRCOK+BANG+NAMEDF},
-	{"copy",	CMD_COPY,	cmd_move,	RANGE+EXTRA	},
-#ifndef NO_DIGRAPH
-	{"digraph",	CMD_DIGRAPH,	cmd_digraph,	EXRCOK+BANG+EXTRA},
-#endif
-#ifndef NO_ERRLIST
-	{"errlist",	CMD_ERRLIST,	cmd_errlist,	BANG+NAMEDF	},
-#endif
-	{"ex",		CMD_EDIT,	cmd_edit,	BANG+FILE1	},
-	{"mark",	CMD_MARK,	cmd_mark,	FROM+WORD1	},
-#ifndef NO_MKEXRC
-	{"mkexrc",	CMD_MKEXRC,	cmd_mkexrc,	NAMEDF		},
-#endif
-	{"number",	CMD_NUMBER,	cmd_print,	RANGE+NL	},
-	{"put",		CMD_PUT,	cmd_put,	FROM+ZERO+WORD1	},
-	{"set",		CMD_SET,	cmd_set,	EXRCOK+EXTRA	},
-	{"shell",	CMD_SHELL,	cmd_shell,	NL		},
-	{"source",	CMD_SOURCE,	cmd_source,	EXRCOK+NAMEDF	},
-#ifdef SIGTSTP
-	{"stop",	CMD_STOP,	cmd_suspend,	NONE		},
-#endif
-	{"tag",		CMD_TAG,	cmd_tag,	BANG+WORD1	},
-	{"version",	CMD_VERSION,	cmd_version,	EXRCOK+NONE	},
-	{"visual",	CMD_VISUAL,	cmd_edit,	BANG+NAMEDF	},
-	{"wq",		CMD_WQUIT,	cmd_xit,	NL		},
-
-#ifdef DEBUG
-	{"debug",	CMD_DEBUG,	cmd_debug,	RANGE+BANG+EXTRA+NL},
-	{"validate",	CMD_VALIDATE,	cmd_validate,	BANG+NL		},
-#endif
-	{"chdir",	CMD_CD,		cmd_cd,		EXRCOK+BANG+NAMEDF},
-#ifndef NO_COLOR
-	{"color",	CMD_COLOR,	cmd_color,	EXRCOK+EXTRA	},
-#endif
-#ifndef NO_ERRLIST
-	{"make",	CMD_MAKE,	cmd_make,	BANG+NAMEDFS	},
-#endif
-	{"map",		CMD_MAP,	cmd_map,	EXRCOK+BANG+EXTRA},
-	{"previous",	CMD_PREVIOUS,	cmd_next,	BANG		},
-	{"rewind",	CMD_REWIND,	cmd_next,	BANG		},
-#ifdef SIGTSTP
-	{"suspend",	CMD_SUSPEND,	cmd_suspend,	NONE		},
-#endif
-	{"unmap",	CMD_UNMAP,	cmd_map,	EXRCOK+BANG+EXTRA},
-#ifndef NO_ABBR
-	{"unabbreviate",CMD_UNABBR,	cmd_map,	EXRCOK+WORD1	},
-#endif
-
-	{(char *)0}
-};
-
-
-/* This function parses a search pattern - given a pointer to a / or ?,
- * it replaces the ending / or ? with a \0, and returns a pointer to the
- * stuff that came after the pattern.
- */
-char	*parseptrn(ptrn)
-	REG char	*ptrn;
-{
-	REG char 	*scan;
-
-	for (scan = ptrn + 1;
-	     *scan && *scan != *ptrn;
-	     scan++)
-	{
-		/* allow backslashed versions of / and ? in the pattern */
-		if (*scan == '\\' && scan[1] != '\0')
-		{
-			scan++;
-		}
-	}
-	if (*scan)
-	{
-		*scan++ = '\0';
-	}
-
-	return scan;
-}
-
-
-/* This function parses a line specifier for ex commands */
-char *linespec(s, markptr)
-	REG char	*s;		/* start of the line specifier */
-	MARK		*markptr;	/* where to store the mark's value */
-{
-	long		num;
-	REG char	*t;
-
-	/* parse each ;-delimited clause of this linespec */
-	do
-	{
-		/* skip an initial ';', if any */
-		if (*s == ';')
-		{
-			s++;
-		}
-
-		/* skip leading spaces */
-		while (isspace(*s))
-		{
-			s++;
-		}
-
-		/* dot means current position */
-		if (*s == '.')
-		{
-			s++;
-			*markptr = cursor;
-		}
-		/* '$' means the last line */
-		else if (*s == '$')
-		{
-			s++;
-			*markptr = MARK_LAST;
-		}
-		/* digit means an absolute line number */
-		else if (isdigit(*s))
-		{
-			for (num = 0; isdigit(*s); s++)
-			{
-				num = num * 10 + *s - '0';
-			}
-			*markptr = MARK_AT_LINE(num);
-		}
-		/* appostrophe means go to a set mark */
-		else if (*s == '\'')
-		{
-			s++;
-			*markptr = m_tomark(cursor, 1L, (int)*s);
-			s++;
-		}
-		/* slash means do a search */
-		else if (*s == '/' || *s == '?')
-		{
-			/* put a '\0' at the end of the search pattern */
-			t = parseptrn(s);
-
-			/* search for the pattern */
-			*markptr &= ~(BLKSIZE - 1);
-			if (*s == '/')
-			{
-				pfetch(markline(*markptr));
-				if (plen > 0)
-					*markptr += plen - 1;
-				*markptr = m_fsrch(*markptr, s);
-			}
-			else
-			{
-				*markptr = m_bsrch(*markptr, s);
-			}
-
-			/* adjust command string pointer */
-			s = t;
-		}
-
-		/* if linespec was faulty, quit now */
-		if (!*markptr)
-		{
-			return s;
-		}
-
-		/* maybe add an offset */
-		t = s;
-		if (*t == '-' || *t == '+')
-		{
-			s++;
-			for (num = 0; isdigit(*s); s++)
-			{
-				num = num * 10 + *s - '0';
-			}
-			if (num == 0)
-			{
-				num = 1;
-			}
-			*markptr = m_updnto(*markptr, num, *t);
-		}
-	} while (*s == ';' || *s == '+' || *s == '-');
-
-	/* protect against invalid line numbers */
-	num = markline(*markptr);
-	if (num < 1L || num > nlines)
-	{
-		msg("Invalid line number -- must be from 1 to %ld", nlines);
-		*markptr = MARK_UNSET;
-	}
-
-	return s;
-}
-
-
-
-/* This function reads an ex command and executes it. */
-void ex()
-{
-	char		cmdbuf[150];
-	REG int		cmdlen;
-	static long	oldline;
-
-	significant = FALSE;
-	oldline = markline(cursor);
-
-	while (mode == MODE_EX)
-	{
-		/* read a line */
-#ifdef CRUNCH
-		cmdlen = vgets(':', cmdbuf, sizeof(cmdbuf));
-#else
-		cmdlen = vgets(*o_prompt ? ':' : '\0', cmdbuf, sizeof(cmdbuf));
-#endif
-		if (cmdlen < 0)
-		{
-			return;
-		}
-
-		/* if empty line, assume ".+1" */
-		if (cmdlen == 0)
-		{
-			strcpy(cmdbuf, ".+1");
-			qaddch('\r');
-			clrtoeol();
-		}
-		else
-		{
-			addch('\n');
-		}
-		refresh();
-
-		/* parse & execute the command */
-		doexcmd(cmdbuf);
-
-		/* handle autoprint */
-		if (significant || markline(cursor) != oldline)
-		{
-			significant = FALSE;
-			oldline = markline(cursor);
-			if (*o_autoprint && mode == MODE_EX)
-			{
-				cmd_print(cursor, cursor, CMD_PRINT, FALSE, "");
-			}
-		}
-	}
-}
-
-void doexcmd(cmdbuf)
-	char		*cmdbuf;	/* string containing an ex command */
-{
-	REG char	*scan;		/* used to scan thru cmdbuf */
-	MARK		frommark;	/* first linespec */
-	MARK		tomark;		/* second linespec */
-	REG int		cmdlen;		/* length of the command name given */
-	CMD		cmd;		/* what command is this? */
-	ARGT		argt;		/* argument types for this command */
-	short		forceit;	/* bang version of a command? */
-	REG int		cmdidx;		/* index of command */
-	REG char	*build;		/* used while copying filenames */
-	int		iswild;		/* boolean: filenames use wildcards? */
-	int		isdfl;		/* using default line ranges? */
-	int		didsub;		/* did we substitute file names for % or # */
-
-	/* ex commands can't be undone via the shift-U command */
-	U_line = 0L;
-
-	/* permit extra colons at the start of the line */
-	for (; *cmdbuf == ':'; cmdbuf++)
-	{
-	}
-
-	/* ignore command lines that start with a double-quote */
-	if (*cmdbuf == '"')
-	{
-		return;
-	}
-	scan = cmdbuf;
-
-	/* parse the line specifier */
-	if (nlines < 1)
-	{
-		/* no file, so don't allow addresses */
-	}
-	else if (*scan == '%')
-	{
-		/* '%' means all lines */
-		frommark = MARK_FIRST;
-		tomark = MARK_LAST;
-		scan++;
-	}
-	else if (*scan == '0')
-	{
-		frommark = tomark = MARK_UNSET;
-		scan++;
-	}
-	else
-	{
-		frommark = cursor;
-		scan = linespec(scan, &frommark);
-		tomark = frommark;
-		if (frommark && *scan == ',')
-		{
-			scan++;
-			scan = linespec(scan, &tomark);
-		}
-		if (!tomark)
-		{
-			/* faulty line spec -- fault already described */
-			return;
-		}
-		if (frommark > tomark)
-		{
-			msg("first address exceeds the second");
-			return;
-		}
-	}
-	isdfl = (scan == cmdbuf);
-
-	/* skip whitespace */
-	while (isspace(*scan))
-	{
-		scan++;
-	}
-
-	/* if no command, then just move the cursor to the mark */
-	if (!*scan)
-	{
-		if (tomark != MARK_UNSET)
-			cursor = tomark;
-		return;
-	}
-
-	/* figure out how long the command name is */
-	if (!isalpha(*scan))
-	{
-		cmdlen = 1;
-	}
-	else
-	{
-		for (cmdlen = 1;
-		     isalpha(scan[cmdlen]);
-		     cmdlen++)
-		{
-		}
-	}
-
-	/* lookup the command code */
-	for (cmdidx = 0;
-	     cmdnames[cmdidx].name && strncmp(scan, cmdnames[cmdidx].name, cmdlen);
-	     cmdidx++)
-	{
-	}
-	argt = cmdnames[cmdidx].argt;
-	cmd = cmdnames[cmdidx].code;
-	if (cmd == CMD_NULL)
-	{
-		msg("Unknown command \"%.*s\"", cmdlen, scan);
-		return;
-	}
-
-	/* !!! if the command doesn't have NOBAR set, then replace | with \0 */
-
-	/* if the command ended with a bang, set the forceit flag */
-	scan += cmdlen;
-	if ((argt & BANG) && *scan == '!')
-	{
-		scan++;
-		forceit = 1;
-	}
-	else
-	{
-		forceit = 0;
-	}
-
-	/* skip any more whitespace, to leave scan pointing to arguments */
-	while (isspace(*scan))
-	{
-		scan++;
-	}
-
-	/* a couple of special cases for filenames */
-	if (argt & XFILE)
-	{
-		/* if names were given, process them */
-		if (*scan)
-		{
-			for (build = tmpblk.c, iswild = didsub = FALSE; *scan; scan++)
-			{
-				switch (*scan)
-				{
-				  case '\\':
-					if (scan[1] == '\\' || scan[1] == '%' || scan[1] == '#')
-					{
-						*build++ = *++scan;
-					}
-					else
-					{
-						*build++ = '\\';
-					}
-					break;
-
-				  case '%':
-					if (!*origname)
-					{
-						msg("No filename to substitute for %%");
-						return;
-					}
-					strcpy(build, origname);
-					while (*build)
-					{
-						build++;
-					}
-					didsub = TRUE;
-					break;
-
-				  case '#':
-					if (!*prevorig)
-					{
-						msg("No filename to substitute for #");
-						return;
-					}
-					strcpy(build, prevorig);
-					while (*build)
-					{
-						build++;
-					}
-					didsub = TRUE;
-					break;
-
-				  case '*':
-				  case '?':
-#if !(MSDOS || TOS)
-				  case '[':
-				  case '`':
-				  case '{': /* } */
-				  case '$':
-				  case '~':
-#endif
-					*build++ = *scan;
-					iswild = TRUE;
-					break;
-
-				  default:
-					*build++ = *scan;
-				}
-			}
-			*build = '\0';
-
-			if (cmd == CMD_BANG
-			 || cmd == CMD_READ && tmpblk.c[0] == '!'
-			 || cmd == CMD_WRITE && tmpblk.c[0] == '!')
-			{
-				if (didsub)
-				{
-					if (mode != MODE_EX)
-					{
-						addch('\n');
-					}
-					addstr(tmpblk.c);
-					addch('\n');
-					exrefresh();
-				}
-			}
-			else
-			{
-				if (iswild && tmpblk.c[0] != '>')
-				{
-					scan = wildcard(tmpblk.c);
-				}
-			}
-		}
-		else /* no names given, maybe assume origname */
-		{
-			if (!(argt & NODFL))
-			{
-				strcpy(tmpblk.c, origname);
-			}
-			else
-			{
-				*tmpblk.c = '\0';
-			}
-		}
-
-		scan = tmpblk.c;
-	}
-
-	/* bad arguments? */
-	if (!(argt & EXRCOK) && nlines < 1L)
-	{
-		msg("Can't use the \"%s\" command in a %s file", cmdnames[cmdidx].name, EXRC);
-		return;
-	}
-	if (!(argt & (ZERO | EXRCOK)) && frommark == MARK_UNSET)
-	{
-		msg("Can't use address 0 with \"%s\" command.", cmdnames[cmdidx].name);
-		return;
-	}
-	if (!(argt & FROM) && frommark != cursor && nlines >= 1L)
-	{
-		msg("Can't use address with \"%s\" command.", cmdnames[cmdidx].name);
-		return;
-	}
-	if (!(argt & TO) && tomark != frommark && nlines >= 1L)
-	{
-		msg("Can't use a range with \"%s\" command.", cmdnames[cmdidx].name);
-		return;
-	}
-	if (!(argt & EXTRA) && *scan)
-	{
-		msg("Extra characters after \"%s\" command.", cmdnames[cmdidx].name);
-		return;
-	}
-	if ((argt & NOSPC) && !(cmd == CMD_READ && (forceit || *scan == '!')))
-	{
-		build = scan;
-#ifndef CRUNCH
-		if ((argt & PLUS) && *build == '+')
-		{
-			while (*build && !isspace(*build))
-			{
-				build++;
-			}
-			while (*build && isspace(*build))
-			{
-				build++;
-			}
-		}
-#endif /* not CRUNCH */
-		for (; *build; build++)
-		{
-			if (isspace(*build))
-			{
-				msg("Too many %s to \"%s\" command.",
-					(argt & XFILE) ? "filenames" : "arguments",
-					cmdnames[cmdidx].name);
-				return;
-			}
-		}
-	}
-
-	/* some commands have special default ranges */
-	if (isdfl && (argt & DFLALL))
-	{
-		frommark = MARK_FIRST;
-		tomark = MARK_LAST;
-	}
-	else if (isdfl && (argt & DFLNONE))
-	{
-		frommark = tomark = 0L;
-	}
-
-	/* write a newline if called from visual mode */
-	if ((argt & NL) && mode != MODE_EX && !exwrote)
-	{
-		addch('\n');
-		exrefresh();
-	}
-
-	/* act on the command */
-	(*cmdnames[cmdidx].fn)(frommark, tomark, cmd, forceit, scan);
-}
-
-
-/* This function executes EX commands from a file.  It returns 1 normally, or
- * 0 if the file could not be opened for reading.
- */
-int doexrc(filename)
-	char	*filename;	/* name of a ".exrc" file */
-{
-	int	fd;		/* file descriptor */
-	int	len;		/* length of the ".exrc" file */
-
-	/* !!! kludge: we use U_text as the buffer.  This has the side-effect
-	 * of interfering with the shift-U visual command.  Disable shift-U.
-	 */
-	U_line = 0L;
-
-	/* open the file, read it, and close */
-	fd = open(filename, O_RDONLY);
-	if (fd < 0)
-	{
-		return 0;
-	}
-	len = tread(fd, U_text, BLKSIZE);
-	close(fd);
-
-	/* execute the string */
-	exstring(U_text, len, ctrl('V'));
-
-	return 1;
-}
-
-/* This function executes EX commands from a string.  The commands may be
- * separated by newlines or by | characters.  It also handles quoting.
- * Each individual command is limited to 132 bytes, but the total string
- * may be longer.
- */
-void exstring(buf, len, qchar)
-	char	*buf;	/* the commands to execute */
-	int	len;	/* the length of the string */
-	int	qchar;	/* the quote character -- ^V for file, or \ for kbd */
-{
-	char	single[133];	/* a single command */
-	char	*src, *dest;
-	int	i;
-
-	/* find & do each command */
-	for (src = buf; src < &buf[len]; src++)
-	{
-		/* Copy a single command into single[].  Convert any quoted |
-		 * into a normal |, and stop at a newline or unquoted |.
-		 */
-		for (dest = single, i = 0;
-		     i < 132 && src < &buf[len] && *src != '\n' && *src != '|';
-		     src++, i++)
-		{
-			if (src[0] == qchar && src[1] == '|')
-			{
-				src++;
-			}
-			*dest++ = *src;
-		}
-		*dest = '\0';
-
-		/* do it */
-		doexcmd(single);
-	}
-}
Index: trunk/minix/commands/elvis/fmt.c
===================================================================
--- trunk/minix/commands/elvis/fmt.c	(revision 9)
+++ 	(revision )
@@ -1,266 +1,0 @@
-/* fmt.c */
-
-/* usage: fmt [-width] [files]...
- *
- * Fmt rearrages text in order to make each line have roughly the
- * same width.  Indentation and word spacing is preserved.
- *
- * The default width is 72 characters, but you can override that via -width.
- * If no files are given on the command line, then it reads stdin.
- */
-
-#include <stdio.h>
-
-#ifndef TRUE
-# define TRUE	1
-# define FALSE	0
-#endif
-
-
-
-int	width = 72;	/* the desired line width */
-int	isblank;	/* is the current output line blank? */
-int	indent;		/* width of the indentation */
-char	ind[512];	/* indentation text */
-char	word[1024];	/* word buffer */
-
-/* This function displays a usage message and quits */
-void usage()
-{
-	fprintf(stderr, "usage: fmt [-width] [files]...\n");
-	exit(2);
-}
-
-
-
-/* This function outputs a single word.  It takes care of spacing and the
- * newlines within a paragraph.
- */
-void putword()
-{
-	int		i;		/* index into word[], or whatever */
-	int		ww;		/* width of the word */
-	int		sw;		/* width of spacing after word */
-	static int	psw;		/* space width of previous word */
-	static int	tab;		/* the width of text already written */
-
-
-	/* separate the word and its spacing */
-	for (ww = 0; word[ww] && word[ww] != ' '; ww++)
-	{
-	}
-	sw = strlen(word) - ww;
-	word[ww] = '\0';
-
-	/* if no spacing (that is, the word was at the end of the line) then
-	 * assume 1 space unless the last char of the word was punctuation
-	 */
-	if (sw == 0)
-	{
-		sw = 1;
-		if (word[ww - 1] == '.' || word[ww - 1] == '?' || word[ww - 1] == '!')
-			sw = 2;
-	}
-
-	/* if this is the first word on the line... */
-	if (isblank)
-	{
-		/* output the indentation first */
-		fputs(ind, stdout);
-		tab = indent;
-	}
-	else /* text has already been written to this output line */
-	{
-		/* will the word fit on this line? */
-		if (psw + ww + tab <= width)
-		{
-			/* yes - so write the previous word's spacing */
-			for (i = 0; i < psw; i++)
-			{
-				putchar(' ');
-			}
-			tab += psw;
-		}
-		else
-		{
-			/* no, so write a newline and the indentation */
-			putchar('\n');
-			fputs(ind, stdout);
-			tab = indent;
-		}
-	}
-
-	/* write the word itself */
-	fputs(word, stdout);
-	tab += ww;
-
-	/* remember this word's spacing */
-	psw = sw;
-
-	/* this output line isn't blank anymore. */
-	isblank = FALSE;
-}
-
-
-
-/* This function reformats text. */
-void fmt(in)
-	FILE	*in;		/* the name of the input stream */
-{
-	int	ch;		/* character from input stream */
-	int	prevch;		/* the previous character in the loop */
-	int	i;		/* index into ind[] or word[] */
-	int	inword;		/* boolean: are we between indent & newline? */
-
-
-	/* for each character in the stream... */
-	for (indent = -1, isblank = TRUE, inword = FALSE, i = 0, prevch = '\n';
-	     (ch = getc(in)) != EOF;
-	     prevch = ch)
-	{
-		/* is this the end of a line? */
-		if (ch == '\n')
-		{
-			/* if end of last word in the input line */
-			if (inword)
-			{
-				/* if it really is a word */
-				if (i > 0)
-				{
-					/* output it */
-					word[i] = '\0';
-					putword();
-				}
-			}
-			else /* blank line in input */
-			{
-				/* finish the previous paragraph */
-				if (!isblank)
-				{
-					putchar('\n');
-					isblank = TRUE;
-				}
-
-				/* output a blank line */
-				putchar('\n');
-			}
-
-			/* continue with next input line... */
-			indent = -1;
-			i = 0;
-			inword = FALSE;
-			continue;
-		}
-
-		/* if we're expecting indentation now... */
-		if (indent < 0)
-		{
-			/* if this is part of the indentation... */
-			if (ch == ' ' || ch == '\t')
-			{
-				/* remember it */
-				ind[i++] = ch;
-			}
-			else /* end of indentation */
-			{
-				/* mark the end of the indentation string */
-				ind[i] = '\0';
-
-				/* calculate the width of the indentation */
-				for (i = indent = 0; ind[i]; i++)
-				{
-					if (ind[i] == '\t')
-						indent = (indent | 7) + 1;
-					else
-						indent++;
-				}
-
-				/* reset the word index */
-				i = 0;
-
-				/* reprocess that last character */
-				ungetc(ch, in);
-			}
-
-			/* continue in the for-loop */
-			continue;
-		}
-
-		/* if we get here, we're either in a word or in the space
-		 * after a word.
-		 */
-		inword = TRUE;
-
-		/* is this the start of a new word? */
-		if (ch != ' ' && prevch == ' ')
-		{
-			/* yes!  output the previous word */
-			word[i] = '\0';
-			putword();
-
-			/* reset `i' to the start of the word[] buffer */
-			i = 0;
-		}
-		word[i++] = ch;
-	}
-
-	/* if necessary, write a final newline */
-	if (!isblank)
-	{
-		putchar('\n');
-		isblank = TRUE;
-	}
-}
-
-
-
-
-
-int main(argc, argv)
-	int	argc;
-	char	**argv;
-{
-	FILE	*in;	/* an input stream */
-	int	error;	/* if non-zero, then an error occurred */
-	int	i;
-
-
-	/* handle the -width flag, if given */
-	if (argc > 1 && argv[1][0] == '-')
-	{
-		width = atoi(argv[1] + 1);
-		if (width <= 0)
-		{
-			usage();
-		}
-		argc--;
-		argv++;
-	}
-
-	/* if no filenames given, then process stdin */
-	if (argc == 1)
-	{
-		fmt(stdin);
-	}
-	else /* one or more filenames given */
-	{
-		for (error = 0, i = 1; i < argc; i++)
-		{
-			in = fopen(argv[i], "r");
-			if (!in)
-			{
-				perror(argv[i]);
-				error = 3;
-			}
-			else
-			{
-				fmt(in);
-				fclose(in);
-			}
-		}
-	}
-
-	/* exit, possibly indicating an error */
-	exit(error);
-	/*NOTREACHED*/
-}
Index: trunk/minix/commands/elvis/input.c
===================================================================
--- trunk/minix/commands/elvis/input.c	(revision 9)
+++ 	(revision )
@@ -1,852 +1,0 @@
-/* input.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the input() function, which implements vi's INPUT mode.
- * It also contains the code that supports digraphs.
- */
-
-#include "config.h"
-#include "ctype.h"
-#include "vi.h"
-
-
-#ifndef NO_DIGRAPH
-static struct _DIG
-{
-	struct _DIG	*next;
-	char		key1;
-	char		key2;
-	char		dig;
-	char		save;
-} *digs;
-
-char digraph(key1, key2)
-	char	key1;	/* the underlying character */
-	char	key2;	/* the second character */
-{
-	int		newkey;
-	REG struct _DIG	*dp;
-
-	/* if digraphs are disabled, then just return the new char */
-	if (!*o_digraph)
-	{
-		return key2;
-	}
-
-	/* remember the new key, so we can return it if this isn't a digraph */
-	newkey = key2;
-
-	/* sort key1 and key2, so that their original order won't matter */
-	if (key1 > key2)
-	{
-		key2 = key1;
-		key1 = newkey;
-	}
-
-	/* scan through the digraph chart */
-	for (dp = digs;
-	     dp && (dp->key1 != key1 || dp->key2 != key2);
-	     dp = dp->next)
-	{
-	}
-
-	/* if this combination isn't in there, just use the new key */
-	if (!dp)
-	{
-		return newkey;
-	}
-
-	/* else use the digraph key */
-	return dp->dig;
-}
-
-/* this function lists or defines digraphs */
-void do_digraph(bang, extra)
-	int	bang;
-	char	extra[];
-{
-	int		dig;
-	REG struct _DIG	*dp;
-	struct _DIG	*prev;
-	static int	user_defined = FALSE; /* boolean: are all later digraphs user-defined? */
-	char		listbuf[8];
-
-	/* if "extra" is NULL, then we've reached the end of the built-ins */
-	if (!extra)
-	{
-		user_defined = TRUE;
-		return;
-	}
-
-	/* if no args, then display the existing digraphs */
-	if (*extra < ' ')
-	{
-		listbuf[0] = listbuf[1] = listbuf[2] = listbuf[5] = ' ';
-		listbuf[7] = '\0';
-		for (dig = 0, dp = digs; dp; dp = dp->next)
-		{
-			if (dp->save || bang)
-			{
-				dig += 7;
-				if (dig >= COLS)
-				{
-					addch('\n');
-					exrefresh();
-					dig = 7;
-				}
-				listbuf[3] = dp->key1;
-				listbuf[4] = dp->key2;
-				listbuf[6] = dp->dig;
-				qaddstr(listbuf);
-			}
-		}
-		addch('\n');
-		exrefresh();
-		return;
-	}
-
-	/* make sure we have at least two characters */
-	if (!extra[1])
-	{
-		msg("Digraphs must be composed of two characters");
-		return;
-	}
-
-	/* sort key1 and key2, so that their original order won't matter */
-	if (extra[0] > extra[1])
-	{
-		dig = extra[0];
-		extra[0] = extra[1];
-		extra[1] = dig;
-	}
-
-	/* locate the new digraph character */
-	for (dig = 2; extra[dig] == ' ' || extra[dig] == '\t'; dig++)
-	{
-	}
-	dig = extra[dig];
-	if (!bang && dig)
-	{
-		dig |= 0x80;
-	}
-
-	/* search for the digraph */
-	for (prev = (struct _DIG *)0, dp = digs;
-	     dp && (dp->key1 != extra[0] || dp->key2 != extra[1]);
-	     prev = dp, dp = dp->next)
-	{
-	}
-
-	/* deleting the digraph? */
-	if (!dig)
-	{
-		if (!dp)
-		{
-#ifndef CRUNCH
-			msg("%c%c not a digraph", extra[0], extra[1]);
-#endif
-			return;
-		}
-		if (prev)
-			prev->next = dp->next;
-		else
-			digs = dp->next;
-		free(dp);
-		return;
-	}
-
-	/* if necessary, create a new digraph struct for the new digraph */
-	if (dig && !dp)
-	{
-		dp = (struct _DIG *)malloc(sizeof *dp);
-		if (!dp)
-		{
-			msg("Out of space in the digraph table");
-			return;
-		}
-		if (prev)
-			prev->next = dp;
-		else
-			digs = dp;
-		dp->next = (struct _DIG *)0;
-	}
-
-	/* assign it the new digraph value */
-	dp->key1 = extra[0];
-	dp->key2 = extra[1];
-	dp->dig = dig;
-	dp->save = user_defined;
-}
-
-# ifndef NO_MKEXRC
-void savedigs(fd)
-	int		fd;
-{
-	static char	buf[] = "digraph! XX Y\n";
-	REG struct _DIG	*dp;
-
-	for (dp = digs; dp; dp = dp->next)
-	{
-		if (dp->save)
-		{
-			buf[9] = dp->key1;
-			buf[10] = dp->key2;
-			buf[12] = dp->dig;
-			write(fd, buf, (unsigned)14);
-		}
-	}
-}
-# endif
-#endif
-
-
-/* This function allows the user to replace an existing (possibly zero-length)
- * chunk of text with typed-in text.  It returns the MARK of the last character
- * that the user typed in.
- */
-MARK input(from, to, when, above)
-	MARK	from;	/* where to start inserting text */
-	MARK	to;	/* extent of text to delete */
-	int	when;	/* either WHEN_VIINP or WHEN_VIREP */
-	int	above;	/* boolean: take indentation from lower line? */
-{
-	char	key[2];	/* key char followed by '\0' char */
-	char	*build;	/* used in building a newline+indent string */
-	char	*scan;	/* used while looking at the indent chars of a line */
-	MARK	m;	/* some place in the text */
-#ifndef NO_EXTENSIONS
-	int	quit = FALSE;	/* boolean: are we exiting after this? */
-	int	inchg;	/* boolean: have we done a "beforedo()" yet? */
-#endif
-
-#ifdef DEBUG
-	/* if "from" and "to" are reversed, complain */
-	if (from > to)
-	{
-		msg("ERROR: input(%ld:%d, %ld:%d)",
-			markline(from), markidx(from),
-			markline(to), markidx(to));
-		return MARK_UNSET;
-	}
-#endif
-
-	key[1] = 0;
-
-	/* if we're replacing text with new text, save the old stuff */
-	/* (Alas, there is no easy way to save text for replace mode) */
-	if (from != to)
-	{
-		cut(from, to);
-	}
-
-	/* if doing a dot command, then reuse the previous text */
-	if (doingdot)
-	{
-		ChangeText
-		{
-			/* delete the text that's there now */
-			if (from != to)
-			{
-				delete(from, to);
-			}
-
-			/* insert the previous text */
-			cutname('.');
-			cursor = paste(from, FALSE, TRUE) + 1L;
-		}
-	}
-	else /* interactive version */
-	{
-		/* assume that whoever called this already did a beforedo() */
-#ifndef NO_EXTENSIONS
-		inchg = TRUE;
-#endif
-
-		/* if doing a change within the line... */
-		if (from != to && markline(from) == markline(to))
-		{
-			/* mark the end of the text with a "$" */
-			change(to - 1, to, "$");
-		}
-		else
-		{
-			/* delete the old text right off */
-			if (from != to)
-			{
-				delete(from, to);
-			}
-			to = from;
-		}
-
-		/* handle autoindent of the first line, maybe */
-		cursor = from;
-		m = (above ? (cursor + BLKSIZE) : (cursor - BLKSIZE));
-		if (*o_autoindent && markidx(m) == 0
-		 && markline(m) >= 1L && markline(m) <= nlines)
-		{
-			/* Only autoindent blank lines. */
-			pfetch(markline(cursor));
-			if (plen == 0)
-			{
-				/* Okay, we really want to autoindent */
-				pfetch(markline(m));
-				for (scan = ptext, build = tmpblk.c;
-				     *scan == ' ' || *scan == '\t';
-				     )
-				{
-					*build++ = *scan++;
-				}
-				if (build > tmpblk.c)
-				{
-					*build = '\0';
-					add(cursor, tmpblk.c);
-					cursor += (build - tmpblk.c);
-					if (cursor > to)
-						to = cursor;
-				}
-			}
-		}
-
-		/* repeatedly add characters from the user */
-		for (;;)
-		{
-			/* Get a character */
-			redraw(cursor, TRUE);
-#ifdef DEBUG2
-			msg("cursor=%ld.%d, to=%ld.%d",
-				markline(cursor), markidx(cursor),
-				markline(to), markidx(to));
-#endif
-#ifndef NO_ABBR
-			pfetch(markline(cursor));
-			build = ptext;
-			if (pline == markline(from))
-				build += markidx(from);
-			for (scan = ptext + markidx(cursor); --scan >= build && isalnum(*scan); )
-			{
-			}
-			scan++;
-			key[0] = getabkey(when, scan, (int)(ptext + markidx(cursor) - scan));
-#else
-			key[0] = getkey(when);
-#endif
-#ifndef NO_VISIBLE
-			if (key[0] != '\0' && V_from != MARK_UNSET)
-			{
-				msg("Can't modify text during a selection");
-				beep();
-				continue;
-			}
-#endif
-
-#ifndef NO_EXTENSIONS
-			if (key[0] == ctrl('O'))
-			{
-				if (inchg)
-				{
-					if (cursor < to)
-					{
-						delete(cursor, to);
-						redraw(cursor, TRUE);
-					}
-					afterdo();
-					inchg = FALSE;
-				}
-			}
-			else if (key[0] != ctrl('['))
-			{
-				if (!inchg)
-				{
-					beforedo(FALSE);
-					inchg = TRUE;
-				}
-			}
-#endif
-
-#ifndef CRUNCH
-			/* if wrapmargin is set & we're past the
-			 * warpmargin, then change the last whitespace
-			 * characters on line into a newline
-			 */
-			if (*o_wrapmargin != 0)
-			{
-				pfetch(markline(cursor));
-				if (idx2col(cursor, ptext, TRUE) > COLS - (*o_wrapmargin & 0xff))
-				{
-					build = tmpblk.c;
-					*build++ = '\n';
-					if (*o_autoindent)
-					{
-						/* figure out indent for next line */
-						for (scan = ptext; *scan == ' ' || *scan == '\t'; )
-						{
-							*build++ = *scan++;
-						}
-					}
-					*build = '\0';
-
-					scan = ptext + plen;
-					m = cursor & ~(BLKSIZE - 1);
-					while (ptext < scan)
-					{
-						scan--;
-						if (*scan != ' ' && *scan != '\t')
-							continue;
-
-						/*break up line, and we do autoindent if needed*/
-						change(m + (scan - ptext), m + (scan - ptext) + 1, tmpblk.c);
-						cursor = (cursor & ~(BLKSIZE - 1))
-							+ BLKSIZE
-							+ strlen(tmpblk.c) - 1
-							+ plen - (scan - ptext) - 1;
-
-						/*remove trailing spaces on previous line*/
-						pfetch(markline(m));
-						scan = ptext + plen;
-						while (ptext < scan)
-						{
-							scan--;
-							if (*scan != ' ' && *scan != '\t')
-								break;
-						}
-						delete(m + (scan-ptext) + 1, m + plen);
-
-						break;
-					}
-				}
-			}
-#endif /* !CRUNCH */
-
-			/* process it */
-			switch (*key)
-			{
-#ifndef NO_EXTENSIONS
-			  case ctrl('O'): /* special movement mapped keys */
-				*key = getkey(0);
-				switch (*key)
-				{
-				  case 'h':	m = m_left(cursor, 0L);		break;
-				  case 'j':
-				  case 'k':	m = m_updnto(cursor, 0L, *key);	break;
-				  case 'l':	m = cursor + 1;			break;
-				  case 'B':
-				  case 'b':	m = m_bword(cursor, 0L, *key);	break;
-				  case 'W':
-				  case 'w':	m = m_fword(cursor, 0L, *key, '\0');	break;
-				  case '^':	m = m_front(cursor, 0L);	break;
-				  case '$':	m = m_rear(cursor, 0L);		break;
-				  case ctrl('B'):
-				  case ctrl('F'):
-						m = m_scroll(cursor, 0L, *key); break;
-				  case 'x':
-#ifndef NO_VISIBLE
-						if (V_from)
-							beep();
-						else
-#endif
-						ChangeText
-						{
-							m = v_xchar(cursor, 0L, 'x');
-						}
-						break;
-				  case 'i':	m = to = from = cursor;
-						when = WHEN_VIINP + WHEN_VIREP - when;
-										break;
-				  case 'K':
-					pfetch(markline(cursor));
-					changes++; /* <- after this, we can alter ptext */
-					ptext[markidx(cursor)] = 0;
-					for (scan = ptext + markidx(cursor) - 1;
-					     scan >= ptext && isalnum(*scan);
-					     scan--)
-					{
-					}
-					scan++;
-					m = (*scan ? v_keyword(scan, cursor, 0L) : cursor);
-					break;
-
-# ifndef NO_VISIBLE
-				  case 'v':
-				  case 'V':
-					if (V_from)
-						V_from = MARK_UNSET;
-					else
-						V_from = cursor;
-					m = from = to = cursor;
-					V_linemd = (*key == 'V');
-					break;
-
-				  case 'd':
-				  case 'y':
-				  case '\\':
-					/* do nothing if unmarked */
-					if (!V_from)
-					{
-						msg("You must mark the text first");
-						beep();
-						break;
-					}
-
-					/* "from" must come before "to" */
-					if (V_from < cursor)
-					{
-						from = V_from;
-						to = cursor;
-					}
-					else
-					{
-						from = cursor;
-						to = V_from;
-					}
-
-					/* we don't need V_from anymore */
-					V_from = MARK_UNSET;
-
-					if (V_linemd)
-					{
-						/* adjust for line mode */
-						from &= ~(BLKSIZE - 1);
-						to |= (BLKSIZE - 1);
-					}
-					else
-					{
-						/* in character mode, we must
-						 * worry about deleting the newline
-						 * at the end of the last line
-						 */
-						pfetch(markline(to));
-						if (markidx(to) == plen)
-							to |= (BLKSIZE - 1);
-					}
-					to++;
-
-					switch (*key)
-					{
-					  case 'y':
-						cut(from, to);
-						break;
-
-					  case 'd':
-						ChangeText
-						{
-							cut(from, to);
-							delete(from, to);
-						}
-						cursor = from;
-						break;
-
-#ifndef NO_POPUP
-					  case '\\':
-						ChangeText
-						{
-							cursor = v_popup(from, to);
-						}
-						break;
-#endif
-					}
-					m = from = to = cursor;
-					break;
-
-				  case 'p':
-				  case 'P':
-					V_from = MARK_UNSET;
-					ChangeText
-					{
-						m = from = to = cursor = paste(cursor, (*key == 'p'), FALSE);
-					}
-					break;
-# endif /* !NO_VISIBLE */
-				  default:	m = MARK_UNSET;
-				}
-
-				/* adjust the moved cursor */
-				if (m != cursor)
-				{
-					m = adjmove(cursor, m, (*key == 'j' || *key == 'k' ? 0x20 : 0));
-					if (*key == '$' || (*key == 'l' && m <= cursor))
-					{
-						m++;
-					}
-				}
-
-				/* if the cursor is reasonable, use it */
-				if (m == MARK_UNSET)
-				{
-					beep();
-				}
-				else
-				{
-					from = to = cursor = m;
-				}
-				break;
-
-			  case ctrl('Z'):
-				if (getkey(0) == ctrl('Z'))
-				{
-					quit = TRUE;
-					goto BreakBreak;
-				}
-				break;
-#endif
-
-			  case ctrl('['):
-				/* if last line contains only whitespace, then remove whitespace */
-				if (*o_autoindent)
-				{
-					pfetch(markline(cursor));
-					for (scan = ptext; isspace(*scan); scan++)
-					{
-					}
-					if (scan > ptext && !*scan)
-					{
-						cursor &= ~(BLKSIZE - 1L);
-						if (to < cursor + plen)
-						{
-							to = cursor + plen;
-						}
-					}
-				}
-				goto BreakBreak;
-
-			  case ctrl('U'):
-				if (markline(cursor) == markline(from))
-				{
-					cursor = from;
-				}
-				else
-				{
-					cursor &= ~(BLKSIZE - 1);
-				}
-				break;
-
-			  case ctrl('D'):
-			  case ctrl('T'):
-				if (to > cursor)
-				{
-					delete(cursor, to);
-				}
-				mark[27] = cursor;
-				cmd_shift(cursor, cursor, *key == ctrl('D') ? CMD_SHIFTL : CMD_SHIFTR, TRUE, "");
-				if (mark[27])
-				{
-					cursor = mark[27];
-				}
-				else
-				{
-					cursor = m_front(cursor, 0L);
-				}
-				to = cursor;
-				break;
-
-			  case '\b':
-				if (cursor <= from)
-				{
-					beep();
-				}
-				else if (markidx(cursor) == 0)
-				{
-					cursor -= BLKSIZE;
-					pfetch(markline(cursor));
-					cursor += plen;
-				}
-				else
-				{
-					cursor--;
-				}
-				break;
-
-			  case ctrl('W'):
-				m = m_bword(cursor, 1L, 'b');
-				if (markline(m) == markline(cursor) && m >= from)
-				{
-					cursor = m;
-					if (from > cursor)
-					{
-						from = cursor;
-					}
-				}
-				else
-				{
-					beep();
-				}
-				break;
-
-			  case '\n':
-#if OSK
-			  case '\l':
-#else				  
-			  case '\r':
-#endif
-				build = tmpblk.c;
-				*build++ = '\n';
-				if (*o_autoindent)
-				{
-					/* figure out indent for next line */
-					pfetch(markline(cursor));
-					for (scan = ptext; *scan == ' ' || *scan == '\t'; )
-					{
-						*build++ = *scan++;
-					}
-
-					/* remove indent from this line, if blank */
-					if ((scan - ptext) >= markidx(cursor) && plen > 0)
-					{
-						to = cursor &= ~(BLKSIZE - 1);
-						delete(cursor, cursor + plen);
-					}
-				}
-				*build = 0;
-				if (cursor >= to && when != WHEN_VIREP)
-				{
-					add(cursor, tmpblk.c);
-				}
-				else
-				{
-					change(cursor, to, tmpblk.c);
-				}
-				redraw(cursor, TRUE);
-				to = cursor = (cursor & ~(BLKSIZE - 1))
-						+ BLKSIZE
-						+ (int)(build - tmpblk.c) - 1;
-				break;
-
-			  case ctrl('A'):
-			  case ctrl('P'):
-				if (cursor < to)
-				{
-					delete(cursor, to);
-				}
-				if (*key == ctrl('A'))
-				{
-					cutname('.');
-				}
-				to = cursor = paste(cursor, FALSE, TRUE) + 1L;
-				break;
-
-			  case ctrl('V'):
-				if (cursor >= to && when != WHEN_VIREP)
-				{
-					add(cursor, "^");
-				}
-				else
-				{
-					change(cursor, to, "^");
-					to = cursor + 1;
-				}
-				redraw(cursor, TRUE);
-				*key = getkey(0);
-				if (*key == '\n')
-				{
-					/* '\n' too hard to handle */
-#if OSK
-					*key = '\l';
-#else
-					*key = '\r';
-#endif
-				}
-				change(cursor, cursor + 1, key);
-				cursor++;
-				if (cursor > to)
-				{
-					to = cursor;
-				}
-				break;
-
-			  case ctrl('L'):
-			  case ctrl('R'):
-				redraw(MARK_UNSET, FALSE);
-				break;
-
-			  default:
-				if (cursor >= to && when != WHEN_VIREP)
-				{
-					add(cursor, key);
-					cursor++;
-					to = cursor;
-				}
-				else
-				{
-					pfetch(markline(cursor));
-					if (markidx(cursor) == plen)
-					{
-						add(cursor, key);
-					}
-					else
-					{
-#ifndef NO_DIGRAPH
-						*key = digraph(ptext[markidx(cursor)], *key);
-#endif
-						change(cursor, cursor + 1, key);
-					}
-					cursor++;
-				}
-#ifndef NO_SHOWMATCH
-				/* show matching "({[" if necessary */
-				if (*o_showmatch && strchr(")}]", *key))
-				{
-					redraw(cursor, TRUE);
-					m = m_match(cursor - 1, 0L);
-					if (markline(m) >= topline
-					 && markline(m) <= botline)
-					{
-						redraw(m, TRUE);
-						refresh();
-						sleep(1);
-					}
-				}
-#endif
-			} /* end switch(*key) */
-		} /* end for(;;) */
-BreakBreak:;
-		/* delete any excess characters */
-		if (cursor < to)
-		{
-#ifndef NO_EXTENSIONS
-			/* if we aren't in the middle of a change, start one! */
-			if (!inchg)
-			{
-				beforedo(FALSE);
-				inchg = TRUE;
-			}
-#endif
-			delete(cursor, to);
-		}
-
-	} /* end if doingdot else */
-
-	/* put the new text into a cut buffer for possible reuse */
-	if (!doingdot)
-	{
-		blksync();
-		cutname('.');
-		cut(from, cursor);
-	}
-
-	/* move to last char that we inputted, unless it was newline */
-	if (markidx(cursor) != 0)
-	{
-		cursor--;
-	}
-	redraw(cursor, FALSE);
-
-#ifndef NO_EXTENSIONS
-	if (quit)
-	{
-		/* if this is a nested "do", then cut it short */
-		abortdo();
-
-		/* exit, unless we can't write out the file */
-		cursor = v_xit(cursor, 0L, 'Z');
-	}
-#endif
-
-	rptlines = 0L;
-	return cursor;
-}
Index: trunk/minix/commands/elvis/main.c
===================================================================
--- trunk/minix/commands/elvis/main.c	(revision 9)
+++ 	(revision )
@@ -1,516 +1,0 @@
-/* main.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the main() function of vi */
-
-/* HACK! bcc needs to disable use of precompiled headers for this file,
-   or else command line args will not be passed to elvis */
-#if __BORLANDC__
-#include "borland.h"
-#endif
-
-#include "config.h"
-#include <setjmp.h>
-#include "vi.h"
-
-extern		trapint(); /* defined below */
-extern char	*getenv();
-jmp_buf		jmpenv;
-
-#ifndef NO_DIGRAPH
-static init_digraphs();
-#endif
-
-/*---------------------------------------------------------------------*/
-
-#if AMIGA
-# include "amiwild.c"
-main (argc, argv)
-#else
-# if VMS
-#  include "vmswild.c"
-main (argc, argv)
-# else
-void main(argc, argv)
-# endif
-#endif
-	int	argc;
-	char	*argv[];
-{
-	int	i;
-	char	*cmd = (char *)0;
-	char	*err = (char *)0;
-	char	*str;
-	char	*tag = (char *)0;
-
-	/* set mode to MODE_VI or MODE_EX depending on program name */
-	switch (argv[0][strlen(argv[0]) - 1])
-	{
-	  case 'x':			/* "ex" */
-		mode = MODE_EX;
-		break;
-
-	  case 'w':			/* "view" */
-		mode = MODE_VI;
-		*o_readonly = TRUE;
-		break;
-#ifndef NO_EXTENSIONS
-	  case 't':			/* "edit" or "input" */
-		mode = MODE_VI;
-		*o_inputmode = TRUE;
-		break;
-#endif
-	  default:			/* "vi" or "elvis" */
-		mode = MODE_VI;
-	}
-
-#ifndef DEBUG
-# ifdef	SIGQUIT
-	/* normally, we ignore SIGQUIT.  SIGINT is trapped later */
-	signal(SIGQUIT, SIG_IGN);
-# endif
-#endif
-
-	/* temporarily ignore SIGINT */
-	signal(SIGINT, SIG_IGN);
-
-	/* start curses */
-	initscr();
-	cbreak();
-	noecho();
-	scrollok(stdscr, TRUE);
-
-	/* arrange for deadly signals to be caught */
-# ifdef SIGHUP
-	signal(SIGHUP, (void(*)()) deathtrap);
-# endif
-# ifndef DEBUG
-#  ifdef SIGILL
-	signal(SIGILL, (void(*)()) deathtrap);
-#  endif
-#  ifdef SIGBUS
-	signal(SIGBUS, (void(*)()) deathtrap);
-#  endif
-#  ifdef SIGSEGV
-	signal(SIGSEGV, (void(*)()) deathtrap);
-#  endif
-#  ifdef SIGSYS
-	signal(SIGSYS, (void(*)()) deathtrap);
-#  endif
-# endif /* !DEBUG */
-# ifdef SIGPIPE
-	signal(SIGPIPE, (void(*)()) deathtrap);
-# endif
-# ifdef SIGTERM
-	signal(SIGTERM, (void(*)()) deathtrap);
-# endif
-# ifdef SIGUSR1
-	signal(SIGUSR1, (void(*)()) deathtrap);
-# endif
-# ifdef SIGUSR2
-	signal(SIGUSR2, (void(*)()) deathtrap);
-# endif
-
-	/* initialize the options - must be done after initscr(), so that
-	 * we can alter LINES and COLS if necessary.
-	 */
-	initopts();
-
-	/* map the arrow keys.  The KU,KD,KL,and KR variables correspond to
-	 * the :ku=: (etc.) termcap capabilities.  The variables are defined
-	 * as part of the curses package.
-	 */
-	if (has_KU) mapkey(has_KU, "k",    WHEN_VICMD|WHEN_INMV, "<Up>");
-	if (has_KD) mapkey(has_KD, "j",    WHEN_VICMD|WHEN_INMV, "<Down>");
-	if (has_KL) mapkey(has_KL, "h",    WHEN_VICMD|WHEN_INMV, "<Left>");
-	if (has_KR) mapkey(has_KR, "l",    WHEN_VICMD|WHEN_INMV, "<Right>");
-	if (has_HM) mapkey(has_HM, "^",    WHEN_VICMD|WHEN_INMV, "<Home>");
-	if (has_EN) mapkey(has_EN, "$",    WHEN_VICMD|WHEN_INMV, "<End>");
-	if (has_PU) mapkey(has_PU, "\002", WHEN_VICMD|WHEN_INMV, "<PageUp>");
-	if (has_PD) mapkey(has_PD, "\006", WHEN_VICMD|WHEN_INMV, "<PageDn>");
-	if (has_KI) mapkey(has_KI, "i",    WHEN_VICMD|WHEN_INMV, "<Insert>");
-#if MSDOS
-# if RAINBOW
-	if (!strcmp("rainbow", o_term))
-	{
-		mapkey("\033[1~",  "/",		WHEN_VICMD,		"<Find>");
-		mapkey("\033[3~",  "x",		WHEN_VICMD|WHEN_INMV,	"<Remove>");
-		mapkey("\033[4~",  "v",		WHEN_VICMD|WHEN_INMV,	"<Select>");
-		mapkey("\033[17~", ":sh\n",	WHEN_VICMD,		"<Intrpt>");
-		mapkey("\033[19~", ":q\n",	WHEN_VICMD,		"<Cancel>");
-		mapkey("\033[21~", "ZZ",	WHEN_VICMD,		"<Exit>");
-		mapkey("\033[26~", "V",		WHEN_VICMD|WHEN_INMV,	"<AddlOp>");
-		mapkey("\033[28~", "\\",	WHEN_VICMD|WHEN_INMV,	"<Help>");
-		mapkey("\033[29~", "K",		WHEN_VICMD|WHEN_INMV,	"<Do>");
-	}
-	else
-# endif /* RAINBOW */
-	{
-		mapkey("#S", "x", WHEN_VICMD|WHEN_INMV,	"<Delete>");
-		mapkey("#s", "B", WHEN_VICMD|WHEN_INMV,	"^<Left>");
-		mapkey("#t", "W", WHEN_VICMD|WHEN_INMV,	"^<Right>");
-	}
-#else /* not MSDOS */
-# if COHERENT
-	mapkey("\033[P", "x", WHEN_VICMD|WHEN_INMV, "<Del>");
-# else
-#if AMIGA
-	mapkey("\233?~", "\\",	WHEN_VICMD|WHEN_INMV,	"<Help>");
-#endif
-
-	if (ERASEKEY != '\177')
-	{
-		mapkey("\177", "x", WHEN_VICMD|WHEN_INMV, "<Del>");
-	}
-# endif
-#endif
-
-#ifndef NO_DIGRAPH
-	init_digraphs();
-#endif /* NO_DIGRAPH */
-
-	/* process any flags */
-	for (i = 1; i < argc && *argv[i] == '-'; i++)
-	{
-		switch (argv[i][1])
-		{
-		  case 'R':	/* readonly */
-			*o_readonly = TRUE;
-			break;
-
-		  case 'L':
-		  case 'r':	/* recover */
-			msg("Use the `elvrec` program to recover lost files");
-			endmsgs();
-			refresh();
-			endwin();
-			exit(0);
-			break;
-
-		  case 't':	/* tag */
-			if (argv[i][2])
-			{
-				tag = argv[i] + 2;
-			}
-			else
-			{
-				tag = argv[++i];
-			}
-			break;
-
-		  case 'v':	/* vi mode */
-			mode = MODE_VI;
-			break;
-
-		  case 'e':	/* ex mode */
-			mode = MODE_EX;
-			break;
-#ifndef NO_EXTENSIONS
-		  case 'i':	/* input mode */
-			*o_inputmode = TRUE;
-			break;
-#endif
-#ifndef NO_ERRLIST
-		  case 'm':	/* use "errlist" as the errlist */
-			if (argv[i][2])
-			{
-				err = argv[i] + 2;
-			}
-			else if (i + 1 < argc)
-			{
-				err = argv[++i];
-			}
-			else
-			{
-				err = "";
-			}
-			break;
-#endif
-#ifndef CRUNCH
-		 case 'c':	/* run the following command, later */
-			if (argv[i][2])
-			{
-				cmd = argv[i] + 2;
-			}
-			else
-			{
-				cmd = argv[++i];
-			}
-			break;
-
-		  case 'w':	/* set the window size */
-			if (argv[i][2])
-			{
-				*o_window = atoi(argv[i] + 2);
-				wset = TRUE;
-			}
-			else
-			{
-				*o_window = atoi(argv[++i]);
-				wset = TRUE;
-			}
-			break;
-#endif
-		  default:
-			msg("Ignoring unknown flag \"%s\"", argv[i]);
-		}
-	}
-
-	/* if we were given an initial ex command, save it... */
-	if (i < argc && *argv[i] == '+')
-	{
-		if (argv[i][1])
-		{
-			cmd = argv[i++] + 1;
-		}
-		else
-		{
-			cmd = "$"; /* "vi + file" means start at EOF */
-			i++;
-		}
-	}
-
-	/* the remaining args are file names. */
-	if (i < argc)
-	{
-		strcpy(args, argv[i]);
-		while (++i < argc && strlen(args) + 1 + strlen(argv[i]) < sizeof args)
-		{
-			strcat(args, " ");
-			strcat(args, argv[i]);
-		}
-#if MSDOS || TOS
-		/* expand wildcard characters, if necessary */
-		if (strchr(args, '*') || strchr(args, '?'))
-		{
-			strcpy(args, wildcard(args));
-		}
-#endif
-		strcpy(tmpblk.c, args);
-		cmd_args(MARK_UNSET, MARK_UNSET, CMD_ARGS, TRUE, tmpblk.c);
-	}
-	else
-	{
-		/* empty args list */
-		args[0] = '\0';
-		nargs = 1;
-		argno = -1;
-	}
-
-	/* perform the .exrc files and EXINIT environment variable */
-#ifdef SYSEXRC
-	doexrc(SYSEXRC);
-#endif
-#ifdef HMEXRC
-	str = getenv("HOME");
-	if (str && *str)
-	{
-		strcpy(tmpblk.c, str);
-		str = tmpblk.c + strlen(tmpblk.c);
-#if !VMS
-# if AMIGA	/* Don't SLASH a device. "Elvis:.exrc" */
-		if (str[-1] != COLON && str[-1] != SLASH)
-# else
-		if (str[-1] != SLASH)
-# endif
-		{
-			*str++ = SLASH;
-		}
-#endif
-		strcpy(str, HMEXRC);
-		doexrc(tmpblk.c);
-	}
-#endif
-#ifndef CRUNCH
-	if (*o_exrc)
-#endif
-	{
-		doexrc(EXRC);
-	}
-#ifdef EXINIT
-	str = getenv(EXINIT);
-	if (str)
-	{
-		exstring(str, strlen(str), ctrl('V'));
-	}
-#endif
-
-	/* search for a tag (or an error) now, if desired */
-	blkinit();
-	if (tag)
-	{
-		cmd_tag(MARK_FIRST, MARK_FIRST, CMD_TAG, 0, tag);
-	}
-#ifndef NO_ERRLIST
-	else if (err)
-	{
-		cmd_errlist(MARK_FIRST, MARK_FIRST, CMD_ERRLIST, 0, err);
-	}
-#endif
-
-	/* if no tag/err, or tag failed, then start with first arg */
-	if (tmpfd < 0)
-	{
-		/* start with first arg */
-		cmd_next(MARK_UNSET, MARK_UNSET, CMD_NEXT, FALSE, "");
-
-		/* pretend to do something, just to force a recoverable
-		 * version of the file out to disk
-		 */
-		ChangeText
-		{
-		}
-		clrflag(file, MODIFIED);
-	}
-
-	/* now we do the immediate ex command that we noticed before */
-	if (cmd)
-	{
-		doexcmd(cmd);
-	}
-
-	/* repeatedly call ex() or vi() (depending on the mode) until the
-	 * mode is set to MODE_QUIT
-	 */
-	while (mode != MODE_QUIT)
-	{
-		if (setjmp(jmpenv))
-		{
-			/* Maybe we just aborted a change? */
-			abortdo();
-		}
-		signal(SIGINT, (void(*)()) trapint);
-
-		switch (mode)
-		{
-		  case MODE_VI:
-			vi();
-			break;
-
-		  case MODE_EX:
-			ex();
-			break;
-#ifdef DEBUG
-		  default:
-			msg("mode = %d?", mode);
-			mode = MODE_QUIT;
-#endif
-		}
-	}
-
-	/* free up the cut buffers */
-	cutend();
-
-	/* end curses */
-#ifndef	NO_CURSORSHAPE
-	if (has_CQ)
-		do_CQ();
-#endif
-	endmsgs();
-	move(LINES - 1, 0);
-	clrtoeol();
-	refresh();
-	endwin();
-
-	exit(0);
-	/*NOTREACHED*/
-}
-
-
-/*ARGSUSED*/
-int trapint(signo)
-	int	signo;
-{
-	beep();
-	resume_curses(FALSE);
-	abortdo();
-#if OSK
-	sigmask(-1);
-#endif
-#if TURBOC || __GNUC__ || _ANSI
-	signal(signo, (void (*)())trapint);
-#else
-	signal(signo, trapint);
-#endif
-	doingglobal = FALSE;
-
-	longjmp(jmpenv, 1);
-
-	return 0;
-}
-
-
-
-#ifndef NO_DIGRAPH
-
-/* This stuff us used to build the default digraphs table. */
-static char	digtable[][4] =
-{
-# ifdef CS_IBMPC
-	"C,\200",	"u\"\1",	"e'\2",		"a^\3",
-	"a\"\4",	"a`\5",		"a@\6",		"c,\7",
-	"e^\10",	"e\"\211",	"e`\12",	"i\"\13",
-	"i^\14",	"i`\15",	"A\"\16",	"A@\17",
-	"E'\20",	"ae\21",	"AE\22",	"o^\23",
-	"o\"\24",	"o`\25",	"u^\26",	"u`\27",
-	"y\"\30",	"O\"\31",	"U\"\32",	"a'\240",
-	"i'!",		"o'\"",		"u'#",		"n~$",
-	"N~%",		"a-&",		"o-'",		"~?(",
-	"~!-",		"\"<.",		"\">/",
-#  ifdef CS_SPECIAL
-	"2/+",		"4/,",		"^+;",		"^q<",
-	"^c=",		"^r>",		"^t?",		"pp]",
-	"^^^",		"oo_",		"*a`",		"*ba",
-	"*pc",		"*Sd",		"*se",		"*uf",
-	"*tg",		"*Ph",		"*Ti",		"*Oj",
-	"*dk",		"*Hl",		"*hm",		"*En",
-	"*No",		"eqp",		"pmq",		"ger",
-	"les",		"*It",		"*iu",		"*/v",
-	"*=w",		"sq{",		"^n|",		"^2}",
-	"^3~",		"^_\377",
-#  endif /* CS_SPECIAL */
-# endif /* CS_IBMPC */
-# ifdef CS_LATIN1
-	"~!!",		"a-*",		"\">+",		"o-:",
-	"\"<>",		"~??",
-
-	"A`@",		"A'A",		"A^B",		"A~C",
-	"A\"D",		"A@E",		"AEF",		"C,G",
-	"E`H",		"E'I",		"E^J",		"E\"K",
-	"I`L",		"I'M",		"I^N",		"I\"O",
-	"-DP",		"N~Q",		"O`R",		"O'S",
-	"O^T",		"O~U",		"O\"V",		"O/X",
-	"U`Y",		"U'Z",		"U^[",		"U\"\\",
-	"Y'_",
-
-	"a``",		"a'a",		"a^b",		"a~c",
-	"a\"d",		"a@e",		"aef",		"c,g",
-	"e`h",		"e'i",		"e^j",		"e\"k",
-	"i`l",		"i'm",		"i^n",		"i\"o",
-	"-dp",		"n~q",		"o`r",		"o's",
-	"o^t",		"o~u",		"o\"v",		"o/x",
-	"u`y",		"u'z",		"u^{",		"u\"|",
-	"y'~",
-# endif /* CS_LATIN1 */
-	""
-};
-
-static init_digraphs()
-{
-	int	i;
-
-	for (i = 0; *digtable[i]; i++)
-	{
-		do_digraph(FALSE, digtable[i]);
-	}
-	do_digraph(FALSE, (char *)0);
-	return 0;
-}
-#endif /* NO_DIGRAPH */
Index: trunk/minix/commands/elvis/misc.c
===================================================================
--- trunk/minix/commands/elvis/misc.c	(revision 9)
+++ 	(revision )
@@ -1,103 +1,0 @@
-/* misc.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains functions which didn't seem happy anywhere else */
-
-#include "config.h"
-#include "vi.h"
-
-
-/* find a particular line & return a pointer to a copy of its text */
-char *fetchline(line)
-	long	line;	/* line number of the line to fetch */
-{
-	int		i;
-	REG char	*scan;	/* used to search for the line in a BLK */
-	long		l;	/* line number counter */
-	static BLK	buf;	/* holds ONLY the selected line (as string) */
-	REG char	*cpy;	/* used while copying the line */
-	static long	nextline;	/* }  These four variables are used */
-	static long	chglevel;	/*  } to implement a shortcut when  */
-	static char	*nextscan;	/*  } consecutive lines are fetched */
-	static long	nextlnum;	/* }                                */
-
-	/* can we do a shortcut? */
-	if (changes == chglevel && line == nextline)
-	{
-		scan = nextscan;
-	}
-	else
-	{
-		/* scan lnum[] to determine which block its in */
-		for (i = 1; line > lnum[i]; i++)
-		{
-		}
-		nextlnum = lnum[i];
-
-		/* fetch text of the block containing that line */
-		scan = blkget(i)->c;
-
-		/* find the line in the block */
-		for (l = lnum[i - 1]; ++l < line; )
-		{
-			while (*scan++ != '\n')
-			{
-			}
-		}
-	}
-
-	/* copy it into a block by itself, with no newline */
-	for (cpy = buf.c; *scan != '\n'; )
-	{
-		*cpy++ = *scan++;
-	}
-	*cpy = '\0';
-
-	/* maybe speed up the next call to fetchline() ? */
-	if (line < nextlnum)
-	{
-		nextline = line + 1;
-		chglevel = changes;
-		nextscan = scan + 1;
-	}
-	else
-	{
-		nextline = 0;
-	}
-
-	/* Calls to fetchline() interfere with calls to pfetch().  Make sure
-	 * that pfetch() resets itself on its next invocation.
-	 */
-	pchgs = 0L;
-
-	/* Return a pointer to the line's text */
-	return buf.c;
-}
-
-
-/* error message from the regexp code */
-void regerror(txt)
-	char	*txt;	/* an error message */
-{
-	msg("RE error: %s", txt);
-}
-
-/* This function is equivelent to the pfetch() macro */
-void	pfetch(l)
-	long	l;	/* line number of line to fetch */
-{
-	if(l != pline || changes != pchgs)
-	{
-		pline = (l);
-		ptext = fetchline(pline);
-		plen = strlen(ptext);
-		pchgs = changes;
-	}
-}
Index: trunk/minix/commands/elvis/modify.c
===================================================================
--- trunk/minix/commands/elvis/modify.c	(revision 9)
+++ 	(revision )
@@ -1,474 +1,0 @@
-/* modify.c */
-
-/* This file contains the low-level file modification functions:
- *	delete(frommark, tomark)	- removes line or portions of lines
- *	add(frommark, text)		- inserts new text
- *	change(frommark, tomark, text)	- delete, then add
- */
-
-#include "config.h"
-#include "vi.h"
-
-#ifdef DEBUG2
-# include <stdio.h>
-static FILE *dbg;
-
-/*VARARGS1*/
-debout(msg, arg1, arg2, arg3, arg4, arg5)
-	char	*msg, *arg1, *arg2, *arg3, *arg4, *arg5;
-{
-	if (!dbg)
-	{
-		dbg = fopen("debug.out", "w");
-		if (!dbg)
-			return;
-		setbuf(dbg, (FILE *)0);
-	}
-	fprintf(dbg, msg, arg1, arg2, arg3, arg4, arg5);
-}
-#endif /* DEBUG2 */
-
-/* delete a range of text from the file */
-void delete(frommark, tomark)
-	MARK		frommark;	/* first char to be deleted */
-	MARK		tomark;		/* AFTER last char to be deleted */
-{
-	int		i;		/* used to move thru logical blocks */
-	REG char	*scan;		/* used to scan thru text of the blk */
-	REG char	*cpy;		/* used when copying chars */
-	BLK		*blk;		/* a text block */
-	long		l;		/* a line number */
-	MARK		m;		/* a traveling version of frommark */
-
-#ifdef DEBUG2
-	debout("delete(%ld.%d, %ld.%d)\n", markline(frommark), markidx(frommark), markline(tomark), markidx(tomark));
-#endif
-
-	/* if not deleting anything, quit now */
-	if (frommark == tomark)
-	{
-		return;
-	}
-
-	/* This is a change */
-	changes++;
-	significant = TRUE;
-
-	/* supply clues to the redraw module */
-	redrawrange(markline(frommark), markline(tomark), markline(frommark));
-
-	/* adjust marks 'a through 'z and '' as needed */
-	l = markline(tomark);
-	for (i = 0; i < NMARKS; i++)
-	{
-		if (mark[i] < frommark)
-		{
-			continue;
-		}
-		else if (mark[i] < tomark)
-		{
-			mark[i] = MARK_UNSET;
-		}
-		else if (markline(mark[i]) == l)
-		{
-			if (markline(frommark) == l)
-			{
-				mark[i] -= markidx(tomark) - markidx(frommark);
-			}
-			else
-			{
-				mark[i] -= markidx(tomark);
-			}
-		}
-		else
-		{
-			mark[i] -= MARK_AT_LINE(l - markline(frommark));
-		}
-	}
-
-	/* Reporting... */
-	if (markidx(frommark) == 0 && markidx(tomark) == 0)
-	{
-		rptlines = markline(tomark) - markline(frommark);
-		rptlabel = "deleted";
-	}
-
-	/* find the block containing frommark */
-	l = markline(frommark);
-	for (i = 1; lnum[i] < l; i++)
-	{
-	}
-
-	/* process each affected block... */
-	for (m = frommark;
-	     m < tomark && lnum[i] < INFINITY;
-	     m = MARK_AT_LINE(lnum[i - 1] + 1))
-	{
-		/* fetch the block */
-		blk = blkget(i);
-
-		/* find the mark in the block */
-		scan = blk->c;
-		for (l = markline(m) - lnum[i - 1] - 1; l > 0; l--)
-		{
-			while (*scan++ != '\n')
-			{
-			}
-		}
-		scan += markidx(m);
-
-		/* figure out where the changes to this block end */
-		if (markline(tomark) > lnum[i])
-		{
-			cpy = blk->c + BLKSIZE;
-		}
-		else if (markline(tomark) == markline(m))
-		{
-			cpy = scan - markidx(m) + markidx(tomark);
-		}
-		else
-		{
-			cpy = scan;
-			for (l = markline(tomark) - markline(m);
-			     l > 0;
-			     l--)
-			{
-				while (*cpy++ != '\n')
-				{
-				}
-			}
-			cpy += markidx(tomark);
-		}
-
-		/* delete the stuff by moving chars within this block */
-		while (cpy < blk->c + BLKSIZE)
-		{
-			*scan++ = *cpy++;
-		}
-		while (scan < blk->c + BLKSIZE)
-		{
-			*scan++ = '\0';
-		}
-
-		/* adjust tomark to allow for lines deleted from this block */
-		tomark -= MARK_AT_LINE(lnum[i] + 1 - markline(m));
-
-		/* if this block isn't empty now, then advance i */
-		if (*blk->c)
-		{
-			i++;
-		}
-
-		/* the buffer has changed.  Update hdr and lnum. */
-		blkdirty(blk);
-	}
-
-	/* must have at least 1 line */
-	if (nlines == 0)
-	{
-		blk = blkadd(1);
-		blk->c[0] = '\n';
-		blkdirty(blk);
-		cursor = MARK_FIRST;
-	}
-}
-
-
-/* add some text at a specific place in the file */
-void add(atmark, newtext)
-	MARK		atmark;		/* where to insert the new text */
-	char		*newtext;	/* NUL-terminated string to insert */
-{
-	REG char	*scan;		/* used to move through string */
-	REG char	*build;		/* used while copying chars */
-	int		addlines;	/* number of lines we're adding */
-	int		lastpart;	/* size of last partial line */
-	BLK		*blk;		/* the block to be modified */
-	int		blkno;		/* the logical block# of (*blk) */
-	REG char	*newptr;	/* where new text starts in blk */
-	BLK		buf;		/* holds chars from orig blk */
-	BLK		linebuf;	/* holds part of line that didn't fit */
-	BLK		*following;	/* the BLK following the last BLK */
-	int		i;
-	long		l;
-
-#ifdef DEBUG2
-	debout("add(%ld.%d, \"%s\")\n", markline(atmark), markidx(atmark), newtext);
-#endif
-#ifdef lint
-	buf.c[0] = 0;
-#endif
-	/* if not adding anything, return now */
-	if (!*newtext)
-	{
-		return;
-	}
-
-	/* This is a change */
-	changes++;
-	significant = TRUE;
-
-	/* count the number of lines in the new text */
-	for (scan = newtext, lastpart = addlines = 0; *scan; )
-	{
-		if (*scan++ == '\n')
-		{
-			addlines++;
-			lastpart = 0;
-		}
-		else
-		{
-			lastpart++;
-		}
-	}
-
-	/* Reporting... */
-	if (lastpart == 0 && markidx(atmark) == 0)
-	{
-		rptlines = addlines;
-		rptlabel = "added";
-	}
-
-	/* extract the line# from atmark */
-	l = markline(atmark);
-
-	/* supply clues to the redraw module */
-	if ((markidx(atmark) == 0 && lastpart == 0) || addlines == 0)
-	{
-		redrawrange(l, l, l + addlines);
-	}
-	else
-	{
-		/* make sure the last line gets redrawn -- it was
-		 * split, so its appearance has changed
-		 */
-		redrawrange(l, l + 1L, l + addlines + 1L);
-	}
-
-	/* adjust marks 'a through 'z and '' as needed */
-	for (i = 0; i < NMARKS; i++)
-	{
-		if (mark[i] < atmark)
-		{
-			/* earlier line, or earlier in same line: no change */
-			continue;
-		}
-		else if (markline(mark[i]) > l)
-		{
-			/* later line: move down a whole number of lines */
-			mark[i] += MARK_AT_LINE(addlines);
-		}
-		else
-		{
-			/* later in same line */
-			if (addlines > 0)
-			{
-				/* multi-line add, which split this line:
-				 * move down, and possibly left or right,
-				 * depending on where the split was and how
-				 * much text was inserted after the last \n
-				 */
-				mark[i] += MARK_AT_LINE(addlines) + lastpart - markidx(atmark);
-			}
-			else
-			{
-				/* totally within this line: move right */
-				mark[i] += lastpart;
-			}
-		}
-	}
-
-	/* get the block to be modified */
-	for (blkno = 1; lnum[blkno] < l && lnum[blkno + 1] < INFINITY; blkno++)
-	{
-	}
-	blk = blkget(blkno);
-	buf = *blk;
-
-	/* figure out where the new text starts */
-	for (newptr = buf.c, l = markline(atmark) - lnum[blkno - 1] - 1;
-	     l > 0;
-	     l--)
-	{
-		while (*newptr++ != '\n')
-		{
-		}
-	}
-	newptr += markidx(atmark);
-
-	/* keep start of old block */
-	build = blk->c + (int)(newptr - buf.c);
-
-	/* fill this block (or blocks) from the newtext string */
-	while (*newtext)
-	{
-		while (*newtext && build < blk->c + BLKSIZE - 1)
-		{
-			*build++ = *newtext++;
-		}
-		if (*newtext)
-		{
-			/* save the excess */
-			for (scan = linebuf.c + BLKSIZE;
-			     build > blk->c && build[-1] != '\n';
-			     )
-			{
-				*--scan = *--build;
-			}
-
-			/* write the block */
-			while (build < blk->c + BLKSIZE)
-			{
-				*build++ = '\0';
-			}
-			blkdirty(blk);
-
-			/* add another block */
-			blkno++;
-			blk = blkadd(blkno);
-
-			/* copy in the excess from last time */
-			for (build = blk->c; scan < linebuf.c + BLKSIZE; )
-			{
-				*build++ = *scan++;
-			}
-		}
-	}
-
-	/* fill this block(s) from remainder of orig block */
-	while (newptr < buf.c + BLKSIZE && *newptr)
-	{
-		while (newptr < buf.c + BLKSIZE
-		    && *newptr
-		    && build < blk->c + BLKSIZE - 1)
-		{
-			*build++ = *newptr++;
-		}
-		if (newptr < buf.c + BLKSIZE && *newptr)
-		{
-			/* save the excess */
-			for (scan = linebuf.c + BLKSIZE;
-			     build > blk->c && build[-1] != '\n';
-			     )
-			{
-				*--scan = *--build;
-			}
-
-			/* write the block */
-			while (build < blk->c + BLKSIZE)
-			{
-				*build++ = '\0';
-			}
-			blkdirty(blk);
-
-			/* add another block */
-			blkno++;
-			blk = blkadd(blkno);
-
-			/* copy in the excess from last time */
-			for (build = blk->c; scan < linebuf.c + BLKSIZE; )
-			{
-				*build++ = *scan++;
-			}
-		}
-	}
-
-	/* see if we can combine our last block with the following block */
-	if (lnum[blkno] < nlines && lnum[blkno + 1] - lnum[blkno] < (BLKSIZE >> 6))
-	{
-		/* hey, we probably can!  Get the following block & see... */
-		following = blkget(blkno + 1);
-		if (strlen(following->c) + (build - blk->c) < BLKSIZE - 1)
-		{
-			/* we can!  Copy text from following to blk */
-			for (scan = following->c; *scan; )
-			{
-				*build++ = *scan++;
-			}
-			while (build < blk->c + BLKSIZE)
-			{
-				*build++ = '\0';
-			}
-			blkdirty(blk);
-
-			/* pretend the following was the last blk */
-			blk = following;
-			build = blk->c;
-		}
-	}
-
-	/* that last block is dirty by now */
-	while (build < blk->c + BLKSIZE)
-	{
-		*build++ = '\0';
-	}
-	blkdirty(blk);
-}
-
-
-/* change the text of a file */
-void change(frommark, tomark, newtext)
-	MARK	frommark, tomark;
-	char	*newtext;
-{
-	int	i;
-	long	l;
-	char	*text;
-	BLK	*blk;
-
-#ifdef DEBUG2
-	debout("change(%ld.%d, %ld.%d, \"%s\")\n", markline(frommark), markidx(frommark), markline(tomark), markidx(tomark), newtext);
-#endif
-
-	/* optimize for single-character replacement */
-	if (frommark + 1 == tomark && newtext[0] && !newtext[1] && newtext[0] != '\n')
-	{
-		/* find the block containing frommark */
-		l = markline(frommark);
-		for (i = 1; lnum[i] < l; i++)
-		{
-		}
-
-		/* get the block */
-		blk = blkget(i);
-
-		/* find the line within the block */
-		for (text = blk->c, i = l - lnum[i - 1] - 1; i > 0; text++)
-		{
-			if (*text == '\n')
-			{
-				i--;
-			}
-		}
-
-		/* replace the char */
-		text += markidx(frommark);
-		if (*text == newtext[0])
-		{
-			/* no change was needed - same char */
-			return;
-		}
-		else if (*text != '\n')
-		{
-			/* This is a change */
-			changes++;
-			significant = TRUE;
-			ChangeText
-			{
-				*text = newtext[0];
-				blkdirty(blk);
-			}
-			redrawrange(markline(frommark), markline(tomark), markline(frommark));
-			return;
-		}
-		/* else it is a complex change involving newline... */
-	}
-
-	/* couldn't optimize, so do delete & add */
-	ChangeText
-	{
-		delete(frommark, tomark);
-		add(frommark, newtext);
-		rptlabel = "changed";
-	}
-}
Index: trunk/minix/commands/elvis/move1.c
===================================================================
--- trunk/minix/commands/elvis/move1.c	(revision 9)
+++ 	(revision )
@@ -1,585 +1,0 @@
-/* move1.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains most movement functions */
-
-#include "config.h"
-#include "vi.h"
-#include "ctype.h"
-
-MARK	m_updnto(m, cnt, cmd)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument */
-	char	cmd;	/* the command character */
-{
-	DEFAULT(cmd == 'G' ? nlines : 1L);
-
-	/* move up or down 'cnt' lines */
-	switch (cmd)
-	{
-	  case ctrl('P'):
-	  case '-':
-	  case 'k':
-		m -= MARK_AT_LINE(cnt);
-		break;
-
-	  case 'G':
-		if (cnt < 1L || cnt > nlines)
-		{
-			msg("Only %ld lines", nlines);
-			return MARK_UNSET;
-		}
-		m = MARK_AT_LINE(cnt);
-		break;
-
-	  case '_':
-		cnt--;
-		/* fall through... */
-
-	  default:
-		m += MARK_AT_LINE(cnt);
-	}
-
-	/* if that left us screwed up, then fail */
-	if (m < MARK_FIRST || markline(m) > nlines)
-	{
-		return MARK_UNSET;
-	}
-
-	return m;
-}
-
-/*ARGSUSED*/
-MARK	m_right(m, cnt, key, prevkey)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument */
-	int	key;	/* movement keystroke */
-	int	prevkey;/* operator keystroke, or 0 if none */
-{
-	int		idx;	/* index of the new cursor position */
-
-	DEFAULT(1);
-
-	/* If used with an operator, then move 1 less character, since the 'l'
-	 * command includes the character that it moves onto.
-	 */
-	if (prevkey != '\0')
-	{
-		cnt--;
-	}
-
-	/* move to right, if that's OK */
-	pfetch(markline(m));
-	idx = markidx(m) + cnt;
-	if (idx < plen)
-	{
-		m += cnt;
-	}
-	else
-	{
-		return MARK_UNSET;
-	}
-
-	return m;
-}
-
-/*ARGSUSED*/
-MARK	m_left(m, cnt)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument */
-{
-	DEFAULT(1);
-
-	/* move to the left, if that's OK */
-	if (markidx(m) >= cnt)
-	{
-		m -= cnt;
-	}
-	else
-	{
-		return MARK_UNSET;
-	}
-
-	return m;
-}
-
-/*ARGSUSED*/
-MARK	m_tocol(m, cnt, cmd)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument */
-	int	cmd;	/* either ctrl('X') or '|' */
-{
-	char	*text;	/* text of the line */
-	int	col;	/* column number */
-	int	idx;	/* index into the line */
-
-
-	/* if doing ^X, then adjust for sideways scrolling */
-	if (cmd == ctrl('X'))
-	{
-		DEFAULT(*o_columns & 0xff);
-		cnt += leftcol;
-	}
-	else
-	{
-		DEFAULT(1);
-	}
-
-	/* internally, columns are numbered 0..COLS-1, not 1..COLS */
-	cnt--;
-
-	/* if 0, that's easy */
-	if (cnt == 0)
-	{
-		m &= ~(BLKSIZE - 1);
-		return m;
-	}
-
-	/* find that column within the line */
-	pfetch(markline(m));
-	text = ptext;
-	for (col = idx = 0; col < cnt && *text; text++, idx++)
-	{
-		if (*text == '\t' && !*o_list)
-		{
-			col += *o_tabstop;
-			col -= col % *o_tabstop;
-		}
-		else if (UCHAR(*text) < ' ' || *text == '\177')
-		{
-			col += 2;
-		}
-#ifndef NO_CHARATTR
-		else if (text[0] == '\\' && text[1] == 'f' && text[2] && *o_charattr)
-		{
-			text += 2; /* plus one more as part of for loop */
-		}
-#endif
-		else
-		{
-			col++;
-		}
-	}
-	if (!*text)
-	{
-		/* the desired column was past the end of the line, so
-		 * act like the user pressed "$" instead.
-		 */
-		return m | (BLKSIZE - 1);
-	}
-	else
-	{
-		m = (m & ~(BLKSIZE - 1)) + idx;
-	}
-	return m;
-}
-
-/*ARGSUSED*/
-MARK	m_front(m, cnt)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument (ignored) */
-{
-	char	*scan;
-
-	/* move to the first non-whitespace character */
-	pfetch(markline(m));
-	scan = ptext;
-	m &= ~(BLKSIZE - 1);
-	while (*scan == ' ' || *scan == '\t')
-	{
-		scan++;
-		m++;
-	}
-
-	return m;
-}
-
-/*ARGSUSED*/
-MARK	m_rear(m, cnt)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument (ignored) */
-{
-	/* Try to move *EXTREMELY* far to the right.  It is fervently hoped
-	 * that other code will convert this to a more reasonable MARK before
-	 * anything tries to actually use it.  (See adjmove() in vi.c)
-	 */
-	return m | (BLKSIZE - 1);
-}
-
-#ifndef NO_SENTENCE
-static int isperiod(ptr)
-	char	*ptr;	/* pointer to possible sentence-ender */
-{
-	/* if not '.', '?', or '!', then it isn't a sentence ender */
-	if (*ptr != '.' && *ptr != '?' && *ptr != '!')
-	{
-		return FALSE;
-	}
-
-	/* skip any intervening ')', ']', or '"' characters */
-	do
-	{
-		ptr++;
-	} while (*ptr == ')' || *ptr == ']' || *ptr == '"');
-
-	/* do we have two spaces or EOL? */
-	if (!*ptr || ptr[0] == ' ' && ptr[1] == ' ')
-	{
-		return TRUE;
-	}
-	return FALSE;
-}
-
-/*ARGSUSED*/
-MARK	m_sentence(m, cnt, cmd)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument */
-	int	cmd;	/* either '(' or ')' */
-{
-	REG char	*text;
-	REG long	l;
-
-	DEFAULT(1);
-
-	/* If '(' command, then move back one word, so that if we hit '(' at
-	 * the start of a sentence we don't simply stop at the end of the
-	 * previous sentence and bounce back to the start of this one again.
-	 */
-	if (cmd == '(')
-	{
-		m = m_bword(m, 1L, 'b');
-		if (!m)
-		{
-			return m;
-		}
-	}
-
-	/* get the current line */
-	l = markline(m);
-	pfetch(l);
-	text = ptext + markidx(m);
-
-	/* for each requested sentence... */
-	while (cnt-- > 0)
-	{
-		/* search forward for one of [.?!] followed by spaces or EOL */
-		do
-		{
-			if (cmd == ')')
-			{
-				/* move forward, wrap at end of line */
-				if (!text[0])
-				{
-					if (l >= nlines)
-					{
-						return MARK_UNSET;
-					}
-					l++;
-					pfetch(l);
-					text = ptext;
-				}
-				else
-				{
-					text++;
-				}
-			}
-			else
-			{
-				/* move backward, wrap at beginning of line */
-				if (text == ptext)
-				{
-					do
-					{
-						if (l <= 1)
-						{
-							return MARK_FIRST;
-						}
-						l--;
-						pfetch(l);
-					} while (!*ptext);
-					text = ptext + plen - 1;
-				}
-				else
-				{
-					text--;
-				}
-			}
-		} while (!isperiod(text));
-	}
-
-	/* construct a mark for this location */
-	m = buildmark(text);
-
-	/* move forward to the first word of the next sentence */
-	m = m_fword(m, 1L, 'w', '\0');
-
-	return m;
-}
-#endif
-
-MARK	m_paragraph(m, cnt, cmd)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument */
-	int	cmd;	/* either '{' or '}' */
-{
-	char	*text;	/* text of the current line */
-	char	*pscn;	/* used to scan thru value of "paragraphs" option */
-	long	l, ol;	/* current line number, original line number */
-	int	dir;	/* -1 if we're moving up, or 1 if down */
-	char	col0;	/* character to expect in column 0 */
-#ifndef NO_SENTENCE
-# define SENTENCE(x)	(x)
-	char	*list;	/* either o_sections or o_paragraph */
-#else
-# define SENTENCE(x)
-#endif
-
-	DEFAULT(1);
-
-	/* set the direction, based on the command */
-	switch (cmd)
-	{
-	  case '{':
-		dir = -1;
-		col0 = '\0';
-		SENTENCE(list = o_paragraphs); 
-		break;
-
-	  case '}':
-		dir = 1;
-		col0 = '\0';
-		SENTENCE(list = o_paragraphs); 
-		break;
-
-	  case '[':
-		if (getkey(0) != '[')
-		{
-			return MARK_UNSET;
-		}
-		dir = -1;
-		col0 = '{';
-		SENTENCE(list = o_sections); 
-		break;
-
-	  case ']':
-		if (getkey(0) != ']')
-		{
-			return MARK_UNSET;
-		}
-		dir = 1;
-		col0 = '{';
-		SENTENCE(list = o_sections); 
-		break;
-	}
-	ol = l = markline(m);
-
-	/* for each paragraph that we want to travel through... */
-	while (l > 0 && l <= nlines && cnt-- > 0)
-	{
-		/* skip blank lines between paragraphs */
-		while (l > 0 && l <= nlines && col0 == *(text = fetchline(l)))
-		{
-			l += dir;
-		}
-
-		/* skip non-blank lines that aren't paragraph separators
-		 */
-		do
-		{
-#ifndef NO_SENTENCE
-			if (*text == '.' && l != ol)
-			{
-				for (pscn = list; pscn[0] && pscn[1]; pscn += 2)
-				{
-					if (pscn[0] == text[1] && pscn[1] == text[2])
-					{
-						pscn = (char *)0;
-						goto BreakBreak;
-					}
-				}
-			}
-#endif
-			l += dir;
-		} while (l > 0 && l <= nlines && col0 != *(text = fetchline(l)));
-BreakBreak:	;
-	}
-
-	if (l > nlines)
-	{
-		m = MARK_LAST;
-	}
-	else if (l <= 0)
-	{
-		m = MARK_FIRST;
-	}
-	else
-	{
-		m = MARK_AT_LINE(l);
-	}
-	return m;
-}
-
-
-/*ARGSUSED*/
-MARK	m_match(m, cnt)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument (normally 0) */
-{
-	long	l;
-	REG char	*text;
-	REG char	match;
-	REG char	nest;
-	REG int		count;
-
-#ifndef NO_EXTENSIONS
-	/* if we're given a number, then treat it as a percentage of the file */
-	if (cnt > 0)
-	{
-		/* make sure it is a reasonable number */
-		if (cnt > 100)
-		{
-			msg("can only be from 1%% to 100%%");
-			return MARK_UNSET;
-		}
-
-		/* return the appropriate line number */
-		l = (nlines - 1L) * cnt / 100L + 1L;
-		return MARK_AT_LINE(l);
-	}
-#endif /* undef NO_EXTENSIONS */
-
-	/* get the current line */
-	l = markline(m);
-	pfetch(l);
-	text = ptext + markidx(m);
-
-	/* search forward within line for one of "[](){}" */
-	for (match = '\0'; !match && *text; text++)
-	{
-		/* tricky way to recognize 'em in ASCII */
-		nest = *text;
-		if ((nest & 0xdf) == ']' || (nest & 0xdf) == '[')
-		{
-			match = nest ^ ('[' ^ ']');
-		}
-		else if ((nest & 0xfe) == '(')
-		{
-			match = nest ^ ('(' ^ ')');
-		}
-		else
-		{
-			match = 0;
-		}
-	}
-	if (!match)
-	{
-		return MARK_UNSET;
-	}
-	text--;
-
-	/* search forward or backward for match */
-	if (match == '(' || match == '[' || match == '{')
-	{
-		/* search backward */
-		for (count = 1; count > 0; )
-		{
-			/* wrap at beginning of line */
-			if (text == ptext)
-			{
-				do
-				{
-					if (l <= 1L)
-					{
-						return MARK_UNSET;
-					}
-					l--;
-					pfetch(l);
-				} while (!*ptext);
-				text = ptext + plen - 1;
-			}
-			else
-			{
-				text--;
-			}
-
-			/* check the char */
-			if (*text == match)
-				count--;
-			else if (*text == nest)
-				count++;
-		}
-	}
-	else
-	{
-		/* search forward */
-		for (count = 1; count > 0; )
-		{
-			/* wrap at end of line */
-			if (!*text)
-			{
-				if (l >= nlines)
-				{
-					return MARK_UNSET;
-				}
-				l++;
-				pfetch(l);
-				text = ptext;
-			}
-			else
-			{
-				text++;
-			}
-
-			/* check the char */
-			if (*text == match)
-				count--;
-			else if (*text == nest)
-				count++;
-		}
-	}
-
-	/* construct a mark for this place */
-	m = buildmark(text);
-	return m;
-}
-
-/*ARGSUSED*/
-MARK	m_tomark(m, cnt, key)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* (ignored) */
-	int	key;	/* keystroke - the mark to move to */
-{
-	/* mark '' is a special case */
-	if (key == '\'' || key == '`')
-	{
-		if (mark[26] == MARK_UNSET)
-		{
-			return MARK_FIRST;
-		}
-		else
-		{
-			return mark[26];
-		}
-	}
-
-	/* if not a valid mark number, don't move */
-	if (key < 'a' || key > 'z')
-	{
-		return MARK_UNSET;
-	}
-
-	/* return the selected mark -- may be MARK_UNSET */
-	if (!mark[key - 'a'])
-	{
-		msg("mark '%c is unset", key);
-	}
-	return mark[key - 'a'];
-}
-
Index: trunk/minix/commands/elvis/move2.c
===================================================================
--- trunk/minix/commands/elvis/move2.c	(revision 9)
+++ 	(revision )
@@ -1,291 +1,0 @@
-/* move2.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This function contains the movement functions that perform RE searching */
-
-#include "config.h"
-#include "vi.h"
-#include "regexp.h"
-
-extern long	atol();
-
-static regexp	*re;	/* compiled version of the pattern to search for */
-static		prevsf;	/* boolean: previous search direction was forward? */
-
-#ifndef NO_EXTENSIONS
-/*ARGSUSED*/
-MARK m_wsrch(word, m, cnt)
-	char	*word;	/* the word to search for */
-	MARK	m;	/* the starting point */
-	int	cnt;	/* ignored */
-{
-	char	buffer[30];
-
-	/* wrap \< and \> around the word */
-	strcpy(buffer, "/\\<");
-	strcat(buffer, word);
-	strcat(buffer, "\\>");
-
-	/* show the searched-for word on the bottom line */
-	move(LINES - 1, 0);
-	qaddstr(buffer);
-	clrtoeol();
-	refresh();
-
-	/* search for the word */
-	return m_fsrch(m, buffer);
-}
-#endif
-
-MARK	m_nsrch(m)
-	MARK	m;	/* where to start searching */
-{
-	if (prevsf)
-	{
-		m = m_fsrch(m, (char *)0);
-		prevsf = TRUE;
-	}
-	else
-	{
-		m = m_bsrch(m, (char *)0);
-		prevsf = FALSE;
-	}
-	return m;
-}
-
-MARK	m_Nsrch(m)
-	MARK	m;	/* where to start searching */
-{
-	if (prevsf)
-	{
-		m = m_bsrch(m, (char *)0);
-		prevsf = TRUE;
-	}
-	else
-	{
-		m = m_fsrch(m, (char *)0);
-		prevsf = FALSE;
-	}
-	return m;
-}
-
-MARK	m_fsrch(m, ptrn)
-	MARK	m;	/* where to start searching */
-	char	*ptrn;	/* pattern to search for */
-{
-	long	l;	/* line# of line to be searched */
-	char	*line;	/* text of line to be searched */
-	int	wrapped;/* boolean: has our search wrapped yet? */
-	int	pos;	/* where we are in the line */
-#ifndef CRUNCH
-	long	delta = INFINITY;/* line offset, for things like "/foo/+1" */
-#endif
-
-	/* remember: "previous search was forward" */
-	prevsf = TRUE;
-
-	if (ptrn && *ptrn)
-	{
-		/* locate the closing '/', if any */
-		line = parseptrn(ptrn);
-#ifndef CRUNCH
-		if (*line)
-		{
-			delta = atol(line);
-		}
-#endif
-		ptrn++;
-
-		/* free the previous pattern */
-		if (re) free(re);
-
-		/* compile the pattern */
-		re = regcomp(ptrn);
-		if (!re)
-		{
-			return MARK_UNSET;
-		}
-	}
-	else if (!re)
-	{
-		msg("No previous expression");
-		return MARK_UNSET;
-	}
-
-	/* search forward for the pattern */
-	pos = markidx(m) + 1;
-	pfetch(markline(m));
-	if (pos >= plen)
-	{
-		pos = 0;
-		m = (m | (BLKSIZE - 1)) + 1;
-	}
-	wrapped = FALSE;
-	for (l = markline(m); l != markline(m) + 1 || !wrapped; l++)
-	{
-		/* wrap search */
-		if (l > nlines)
-		{
-			/* if we wrapped once already, then the search failed */
-			if (wrapped)
-			{
-				break;
-			}
-
-			/* else maybe we should wrap now? */
-			if (*o_wrapscan)
-			{
-				l = 0;
-				wrapped = TRUE;
-				continue;
-			}
-			else
-			{
-				break;
-			}
-		}
-
-		/* get this line */
-		line = fetchline(l);
-
-		/* check this line */
-		if (regexec(re, &line[pos], (pos == 0)))
-		{
-			/* match! */
-			if (wrapped && *o_warn)
-				msg("(wrapped)");
-#ifndef CRUNCH
-			if (delta != INFINITY)
-			{
-				l += delta;
-				if (l < 1 || l > nlines)
-				{
-					msg("search offset too big");
-					return MARK_UNSET;
-				}
-				force_flags = LNMD|INCL;
-				return MARK_AT_LINE(l);
-			}
-#endif
-			return MARK_AT_LINE(l) + (int)(re->startp[0] - line);
-		}
-		pos = 0;
-	}
-
-	/* not found */
-	msg(*o_wrapscan ? "Not found" : "Hit bottom without finding RE");
-	return MARK_UNSET;
-}
-
-MARK	m_bsrch(m, ptrn)
-	MARK	m;	/* where to start searching */
-	char	*ptrn;	/* pattern to search for */
-{
-	long	l;	/* line# of line to be searched */
-	char	*line;	/* text of line to be searched */
-	int	wrapped;/* boolean: has our search wrapped yet? */
-	int	pos;	/* last acceptable idx for a match on this line */
-	int	last;	/* remembered idx of the last acceptable match on this line */
-	int	try;	/* an idx at which we strat searching for another match */
-#ifndef CRUNCH
-	long	delta = INFINITY;/* line offset, for things like "/foo/+1" */
-#endif
-
-	/* remember: "previous search was not forward" */
-	prevsf = FALSE;
-
-	if (ptrn && *ptrn)
-	{
-		/* locate the closing '?', if any */
-		line = parseptrn(ptrn);
-#ifndef CRUNCH
-		if (*line)
-		{
-			delta = atol(line);
-		}
-#endif
-		ptrn++;
-
-		/* free the previous pattern, if any */
-		if (re) free(re);
-
-		/* compile the pattern */
-		re = regcomp(ptrn);
-		if (!re)
-		{
-			return MARK_UNSET;
-		}
-	}
-	else if (!re)
-	{
-		msg("No previous expression");
-		return MARK_UNSET;
-	}
-
-	/* search backward for the pattern */
-	pos = markidx(m);
-	wrapped = FALSE;
-	for (l = markline(m); l != markline(m) - 1 || !wrapped; l--)
-	{
-		/* wrap search */
-		if (l < 1)
-		{
-			if (*o_wrapscan)
-			{
-				l = nlines + 1;
-				wrapped = TRUE;
-				continue;
-			}
-			else
-			{
-				break;
-			}
-		}
-
-		/* get this line */
-		line = fetchline(l);
-
-		/* check this line */
-		if (regexec(re, line, 1) && (int)(re->startp[0] - line) < pos)
-		{
-			/* match!  now find the last acceptable one in this line */
-			do
-			{
-				last = (int)(re->startp[0] - line);
-				try = (int)(re->endp[0] - line);
-			} while (try > 0
-				 && regexec(re, &line[try], FALSE)
-				 && (int)(re->startp[0] - line) < pos);
-
-			if (wrapped && *o_warn)
-				msg("(wrapped)");
-#ifndef CRUNCH
-			if (delta != INFINITY)
-			{
-				l += delta;
-				if (l < 1 || l > nlines)
-				{
-					msg("search offset too big");
-					return MARK_UNSET;
-				}
-				force_flags = LNMD|INCL;
-				return MARK_AT_LINE(l);
-			}
-#endif
-			return MARK_AT_LINE(l) + last;
-		}
-		pos = BLKSIZE;
-	}
-
-	/* not found */
-	msg(*o_wrapscan ? "Not found" : "Hit top without finding RE");
-	return MARK_UNSET;
-}
-
Index: trunk/minix/commands/elvis/move3.c
===================================================================
--- trunk/minix/commands/elvis/move3.c	(revision 9)
+++ 	(revision )
@@ -1,163 +1,0 @@
-/* move3.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains movement functions that perform character searches */
-
-#include "config.h"
-#include "vi.h"
-
-#ifndef NO_CHARSEARCH
-static MARK	(*prevfwdfn)();	/* function to search in same direction */
-static MARK	(*prevrevfn)();	/* function to search in opposite direction */
-static char	prev_key;	/* sought cvhar from previous [fFtT] */
-
-MARK	m__ch(m, cnt, cmd)
-	MARK	m;	/* current position */
-	long	cnt;
-	char	cmd;	/* command: either ',' or ';' */
-{
-	MARK	(*tmp)();
-
-	if (!prevfwdfn)
-	{
-		msg("No previous f, F, t, or T command");
-		return MARK_UNSET;
-	}
-
-	if (cmd == ',')
-	{
-		m =  (*prevrevfn)(m, cnt, prev_key);
-
-		/* Oops! we didn't want to change the prev*fn vars! */
-		tmp = prevfwdfn;
-		prevfwdfn = prevrevfn;
-		prevrevfn = tmp;
-
-		return m;
-	}
-	else
-	{
-		return (*prevfwdfn)(m, cnt, prev_key);
-	}
-}
-
-/* move forward within this line to next occurrence of key */
-MARK	m_fch(m, cnt, key)
-	MARK	m;	/* where to search from */
-	long	cnt;
-	char	key;	/* what to search for */
-{
-	REG char	*text;
-
-	DEFAULT(1);
-
-	prevfwdfn = m_fch;
-	prevrevfn = m_Fch;
-	prev_key = key;
-
-	pfetch(markline(m));
-	text = ptext + markidx(m);
-	while (cnt-- > 0)
-	{
-		do
-		{
-			m++;
-			text++;
-		} while (*text && *text != key);
-	}
-	if (!*text)
-	{
-		return MARK_UNSET;
-	}
-	return m;
-}
-
-/* move backward within this line to previous occurrence of key */
-MARK	m_Fch(m, cnt, key)
-	MARK	m;	/* where to search from */
-	long	cnt;
-	char	key;	/* what to search for */
-{
-	REG char	*text;
-
-	DEFAULT(1);
-
-	prevfwdfn = m_Fch;
-	prevrevfn = m_fch;
-	prev_key = key;
-
-	pfetch(markline(m));
-	text = ptext + markidx(m);
-	while (cnt-- > 0)
-	{
-		do
-		{
-			m--;
-			text--;
-		} while (text >= ptext && *text != key);
-	}
-	if (text < ptext)
-	{
-		return MARK_UNSET;
-	}
-	return m;
-}
-
-/* move forward within this line almost to next occurrence of key */
-MARK	m_tch(m, cnt, key)
-	MARK	m;	/* where to search from */
-	long	cnt;
-	char	key;	/* what to search for */
-{
-	/* skip the adjacent char */
-	pfetch(markline(m));
-	if (plen <= markidx(m))
-	{
-		return MARK_UNSET;
-	}
-	m++;
-
-	m = m_fch(m, cnt, key);
-	if (m == MARK_UNSET)
-	{
-		return MARK_UNSET;
-	}
-
-	prevfwdfn = m_tch;
-	prevrevfn = m_Tch;
-
-	return m - 1;
-}
-
-/* move backward within this line almost to previous occurrence of key */
-MARK	m_Tch(m, cnt, key)
-	MARK	m;	/* where to search from */
-	long	cnt;
-	char	key;	/* what to search for */
-{
-	/* skip the adjacent char */
-	if (markidx(m) == 0)
-	{
-		return MARK_UNSET;
-	}
-	m--;
-
-	m = m_Fch(m, cnt, key);
-	if (m == MARK_UNSET)
-	{
-		return MARK_UNSET;
-	}
-
-	prevfwdfn = m_Tch;
-	prevrevfn = m_tch;
-
-	return m + 1;
-}
-#endif
Index: trunk/minix/commands/elvis/move4.c
===================================================================
--- trunk/minix/commands/elvis/move4.c	(revision 9)
+++ 	(revision )
@@ -1,211 +1,0 @@
-/* move4.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains movement functions which are screen-relative */
-
-#include "config.h"
-#include "vi.h"
-
-/* This moves the cursor to a particular row on the screen */
-/*ARGSUSED*/
-MARK m_row(m, cnt, key)
-	MARK	m;	/* the cursor position */
-	long	cnt;	/* the row we'll move to */
-	int	key;	/* the keystroke of this move - H/L/M */
-{
-	DEFAULT(1);
-
-	/* calculate destination line based on key */
-	cnt--;
-	switch (key)
-	{
-	  case 'H':
-		cnt = topline + cnt;
-		break;
-
-	  case 'M':
-		cnt = topline + (LINES - 1) / 2;
-		break;
-
-	  case 'L':
-		cnt = botline - cnt;
-		break;
-	}
-
-	/* return the mark of the destination line */
-	return MARK_AT_LINE(cnt);
-}
-
-
-/* This function repositions the current line to show on a given row */
-MARK m_z(m, cnt, key)
-	MARK	m;	/* the cursor */
-	long	cnt;	/* the line number we're repositioning */
-	int	key;	/* key struck after the z */
-{
-	long	newtop;
-	int	i;
-
-	/* Which line are we talking about? */
-	if (cnt < 0 || cnt > nlines)
-	{
-		return MARK_UNSET;
-	}
-	if (cnt)
-	{
-		m = MARK_AT_LINE(cnt);
-		newtop = cnt;
-	}
-	else
-	{
-		newtop = markline(m);
-	}
-
-	/* allow a "window size" number to be entered */
-	for (i = 0; key >= '0' && key <= '9'; key = getkey(0))
-	{
-		i = i * 10 + key - '0';
-	}
-#ifndef CRUNCH
-	if (i > 0 && i <= LINES - 1)
-	{
-		*o_window = i;
-		wset = TRUE;
-	}
-#else
-	/* the number is ignored if -DCRUNCH */
-#endif
-
-	/* figure out which line will have to be at the top of the screen */
-	switch (key)
-	{
-	  case '\n':
-#if OSK
-	  case '\l':
-#else
-	  case '\r':
-#endif
-	  case '+':
-		break;
-
-	  case '.':
-	  case 'z':
-		newtop -= LINES / 2;
-		break;
-
-	  case '-':
-		newtop -= LINES - 1;
-		break;
-
-	  default:
-		return MARK_UNSET;
-	}
-
-	/* make the new topline take effect */
-	redraw(MARK_UNSET, FALSE);
-	if (newtop >= 1)
-	{
-		topline = newtop;
-	}
-	else
-	{
-		topline = 1L;
-	}
-	redrawrange(0L, INFINITY, INFINITY);
-
-	/* The cursor doesn't move */
-	return m;
-}
-
-
-/* This function scrolls the screen.  It does this by calling redraw() with
- * an off-screen line as the argument.  It will move the cursor if necessary
- * so that the cursor is on the new screen.
- */
-/*ARGSUSED*/
-MARK m_scroll(m, cnt, key)
-	MARK	m;	/* the cursor position */
-	long	cnt;	/* for some keys: the number of lines to scroll */
-	int	key;	/* keystroke that causes this movement */
-{
-	MARK	tmp;	/* a temporary mark, used as arg to redraw() */
-
-	/* adjust cnt, and maybe *o_scroll, depending of key */
-	switch (key)
-	{
-	  case ctrl('F'):
-	  case ctrl('B'):
-		DEFAULT(1);
-		redrawrange(0L, INFINITY, INFINITY); /* force complete redraw */
-		cnt = cnt * (LINES - 1) - 2; /* keeps two old lines on screen */
-		break;
-
-	  case ctrl('E'):
-	  case ctrl('Y'):
-		DEFAULT(1);
-		break;
-
-	  case ctrl('U'):
-	  case ctrl('D'):
-		if (cnt == 0) /* default */
-		{
-			cnt = *o_scroll;
-		}
-		else
-		{
-			if (cnt > LINES - 1)
-			{
-				cnt = LINES - 1;
-			}
-			*o_scroll = cnt;
-		}
-		break;
-	}
-
-	/* scroll up or down, depending on key */
-	switch (key)
-	{
-	  case ctrl('B'):
-	  case ctrl('Y'):
-	  case ctrl('U'):
-		cnt = topline - cnt;
-		if (cnt < 1L)
-		{
-			cnt = 1L;
-			m = MARK_FIRST;
-		}
-		tmp = MARK_AT_LINE(cnt) + markidx(m);
-		redraw(tmp, FALSE);
-		if (markline(m) > botline)
-		{
-			m = MARK_AT_LINE(botline);
-		}
-		break;
-
-	  case ctrl('F'):
-	  case ctrl('E'):
-	  case ctrl('D'):
-		cnt = botline + cnt;
-		if (cnt > nlines)
-		{
-			cnt = nlines;
-			m = MARK_LAST;
-		}
-		tmp = MARK_AT_LINE(cnt) + markidx(m);
-		redraw(tmp, FALSE);
-		if (markline(m) < topline)
-		{
-			m = MARK_AT_LINE(topline);
-		}
-		break;
-	}
-
-	return m;
-}
Index: trunk/minix/commands/elvis/move5.c
===================================================================
--- trunk/minix/commands/elvis/move5.c	(revision 9)
+++ 	(revision )
@@ -1,256 +1,0 @@
-/* move5.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the word-oriented movement functions */
-
-#include "config.h"
-#include "ctype.h"
-#include "vi.h"
-
-MARK	m_fword(m, cnt, cmd, prevkey)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument */
-	int	cmd;	/* either 'w' or 'W' */
-	int	prevkey;/* previous command... if 'c' then exclude whitespace */
-{
-	REG long	l;
-	REG char	*text;
-	REG int		i;
-
-	DEFAULT(1);
-
-	l = markline(m);
-	pfetch(l);
-	text = ptext + markidx(m);
-
-#ifndef CRUNCH
-	/* As a special case, "cw" or "cW" on whitespace without a count
-	 * treats the single whitespace character under the cursor as a word.
-	 */
-	if (cnt == 1L && prevkey == 'c' && isspace(*text))
-	{
-		return m + 1L;
-	}
-#endif
-
-	while (cnt-- > 0) /* yes, ASSIGNMENT! */
-	{
-		i = *text++;
-
-		if (cmd == 'W')
-		{
-			/* include any non-whitespace */
-			while (i && !isspace(i))
-			{
-				i = *text++;
-			}
-		}
-		else if (isalnum(i) || i == '_')
-		{
-			/* include an alphanumeric word */
-			while (i && isalnum(i))
-			{
-				i = *text++;
-			}
-		}
-		else
-		{
-			/* include contiguous punctuation */
-			while (i && !isalnum(i) && !isspace(i))
-			{
-				i = *text++;
-			}
-		}
-
-		/* if not part of "cw" or "cW" command... */
-		if (prevkey != 'c' || cnt > 0)
-		{
-			/* include trailing whitespace */
-			while (!i || isspace(i))
-			{
-				/* did we hit the end of this line? */
-				if (!i)
-				{
-					/* "dw" shouldn't delete newline after word */
-					if (prevkey && cnt == 0)
-					{
-						break;
-					}
-
-					/* move to next line, if there is one */
-					l++;
-					if (l > nlines)
-					{
-						return MARK_UNSET;
-					}
-					pfetch(l);
-					text = ptext;
-				}
-
-				i = *text++;
-			}
-		}
-		text--;
-	}
-
-	/* if argument to operator, then back off 1 char since "w" and "W"
-	 * include the last char in the affected text.
-	 */
-	if (prevkey)
-	{
-		text--;
-	}
-
-	/* construct a MARK for this place */
-	m = buildmark(text);
-	return m;
-}
-
-
-MARK	m_bword(m, cnt, cmd)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument */
-	int	cmd;	/* either 'b' or 'B' */
-{
-	REG long	l;
-	REG char	*text;
-
-	DEFAULT(1);
-
-	l = markline(m);
-	pfetch(l);
-	text = ptext + markidx(m);
-	while (cnt-- > 0) /* yes, ASSIGNMENT! */
-	{
-		text--;
-
-		/* include preceding whitespace */
-		while (text < ptext || isspace(*text))
-		{
-			/* did we hit the end of this line? */
-			if (text < ptext)
-			{
-				/* move to preceding line, if there is one */
-				l--;
-				if (l <= 0)
-				{
-					return MARK_UNSET;
-				}
-				pfetch(l);
-				text = ptext + plen - 1;
-			}
-			else
-			{
-				text--;
-			}
-		}
-
-		if (cmd == 'B')
-		{
-			/* include any non-whitespace */
-			while (text >= ptext && !isspace(*text))
-			{
-				text--;
-			}
-		}
-		else if (isalnum(*text) || *text == '_')
-		{
-			/* include an alphanumeric word */
-			while (text >= ptext && isalnum(*text))
-			{
-				text--;
-			}
-		}
-		else
-		{
-			/* include contiguous punctuation */
-			while (text >= ptext && !isalnum(*text) && !isspace(*text))
-			{
-				text--;
-			}
-		}
-		text++;
-	}
-
-	/* construct a MARK for this place */
-	m = buildmark(text);
-	return m;
-}
-
-MARK	m_eword(m, cnt, cmd)
-	MARK	m;	/* movement is relative to this mark */
-	long	cnt;	/* a numeric argument */
-	int	cmd;	/* either 'e' or 'E' */
-{
-	REG long	l;
-	REG char	*text;
-	REG int		i;
-
-	DEFAULT(1);
-
-	l = markline(m);
-	pfetch(l);
-	text = ptext + markidx(m);
-	while (cnt-- > 0) /* yes, ASSIGNMENT! */
-	{
-		if (*text)
-			text++;
-		i = *text++;
-
-		/* include preceding whitespace */
-		while (!i || isspace(i))
-		{
-			/* did we hit the end of this line? */
-			if (!i)
-			{
-				/* move to next line, if there is one */
-				l++;
-				if (l > nlines)
-				{
-					return MARK_UNSET;
-				}
-				pfetch(l);
-				text = ptext;
-			}
-
-			i = *text++;
-		}
-
-		if (cmd == 'E')
-		{
-			/* include any non-whitespace */
-			while (i && !isspace(i))
-			{
-				i = *text++;
-			}
-		}
-		else if (isalnum(i) || i == '_')
-		{
-			/* include an alphanumeric word */
-			while (i && isalnum(i))
-			{
-				i = *text++;
-			}
-		}
-		else
-		{
-			/* include contiguous punctuation */
-			while (i && !isalnum(i) && !isspace(i))
-			{
-				i = *text++;
-			}
-		}
-		text -= 2;
-	}
-
-	/* construct a MARK for this place */
-	m = buildmark(text);
-	return m;
-}
Index: trunk/minix/commands/elvis/opts.c
===================================================================
--- trunk/minix/commands/elvis/opts.c	(revision 9)
+++ 	(revision )
@@ -1,797 +1,0 @@
-/* opts.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the code that manages the run-time options -- The 
- * values that can be modified via the "set" command.
- */
-
-#include "config.h"
-#include "vi.h"
-#include "ctype.h"
-#ifndef NULL
-#define NULL (char *)0
-#endif
-extern char	*getenv();
-
-/* maximum width to permit for strings, including ="" */
-#define MAXWIDTH 20
-
-/* These are the default values of all options */
-char	o_autoindent[1] =	{FALSE};
-char	o_autoprint[1] =	{TRUE};
-char	o_autotab[1] =		{TRUE};
-char	o_autowrite[1] = 	{FALSE};
-char	o_columns[3] =		{80, 32, 255};
-char	o_directory[30] =	TMPDIR;
-char	o_edcompatible[1] =	{FALSE};
-char	o_equalprg[80] =	{"fmt"};
-char	o_errorbells[1] =	{TRUE};
-char	o_exrefresh[1] =	{TRUE};
-char	o_ignorecase[1] =	{FALSE};
-char	o_keytime[3] =		{1, 0, 50};
-char	o_keywordprg[80] =	{KEYWORDPRG};
-char	o_lines[3] =		{25, 2, 96};
-char	o_list[1] =		{FALSE};
-char	o_number[1] =		{FALSE};
-char	o_readonly[1] =		{FALSE};
-char	o_remap[1] =		{TRUE};
-char	o_report[3] =		{5, 1, 127};
-char	o_scroll[3] =		{12, 1, 127};
-char	o_shell[60] =		SHELL;
-char	o_shiftwidth[3] =	{8, 1, 255};
-char	o_sidescroll[3] =	{8, 1, 40};
-char	o_sync[1] =		{NEEDSYNC};
-char	o_tabstop[3] =		{8, 1, 40};
-char	o_term[30] =		"?";
-char	o_flash[1] =		{TRUE};
-char	o_warn[1] =		{TRUE};
-char	o_wrapscan[1] =		{TRUE};
-
-#ifndef CRUNCH
-char	o_beautify[1] =		{FALSE};
-char	o_exrc[1] =		{FALSE};
-char	o_mesg[1] =		{TRUE};
-char	o_more[1] =		{TRUE};
-char	o_novice[1] =		{FALSE};
-char	o_prompt[1] =		{TRUE};
-char	o_taglength[3] =	{0, 0, 30};
-char	o_terse[1] =		{FALSE};
-char	o_window[3] =		{0, 1, 24};
-char	o_wrapmargin[3] =	{0, 0, 255};
-char	o_writeany[1] =		{FALSE};
-#endif
-
-#ifndef NO_ERRLIST
-char	o_cc[30] =		{CC_COMMAND};
-char	o_make[30] =		{MAKE_COMMAND};
-#endif
-
-#ifndef NO_CHARATTR
-char	o_charattr[1] =		{FALSE};
-#endif
-
-#ifndef NO_DIGRAPH
-char	o_digraph[1] =		{FALSE};
-char	o_flipcase[80]
-# ifdef CS_IBMPC
-	= {"\207\200\201\232\202\220\204\216\206\217\221\222\224\231\244\245"}
-# endif
-# ifdef CS_LATIN1
-	/* initialized by initopts() */
-# endif
-	;
-#endif
-
-#ifndef NO_SENTENCE
-char	o_hideformat[1] =	{FALSE};
-#endif
-
-#ifndef NO_EXTENSIONS
-char	o_inputmode[1] =	{FALSE};
-char	o_ruler[1] =		{FALSE};
-#endif
-
-#ifndef NO_MAGIC
-char	o_magic[1] =		{TRUE};
-#endif
-
-#ifndef NO_MODELINES
-char	o_modelines[1] =	{FALSE};
-#endif
-
-#ifndef NO_SENTENCE
-char	o_paragraphs[30] =	"PPppIPLPQP";
-char	o_sections[30] =	"NHSHSSSEse";
-#endif
-
-#if MSDOS
-char	o_pcbios[1] =		{TRUE};
-#endif
-
-#ifndef NO_SHOWMATCH
-char	o_showmatch[1] =	{FALSE};
-#endif
-
-#ifndef	NO_SHOWMODE
-char	o_smd[1] =		{FALSE};
-#endif
-
-
-/* The following describes the names & types of all options */
-#define BOOL	0
-#define	NUM	1
-#define	STR	2
-#define SET	0x01	/* this option has had its value altered */
-#define CANSET	0x02	/* this option can be set at any time */
-#define RCSET	0x06	/* this option can be set in a .exrc file only */
-#define NOSAVE	0x0a	/* this option should never be saved by mkexrc */
-#define WSET	0x20	/* is this the "window" size option? */
-#define MR	0x40	/* does this option affect the way text is displayed? */
-struct
-{
-	char	*name;	/* name of an option */
-	char	*nm;	/* short name of an option */
-	char	type;	/* type of an option */
-	char	flags;	/* boolean: has this option been set? */
-	char	*value;	/* value */
-}
-	opts[] =
-{
-	/* name			type	flags		value */
-	{ "autoindent",	"ai",	BOOL,	CANSET,		o_autoindent	},
-	{ "autoprint",	"ap",	BOOL,	CANSET,		o_autoprint	},
-	{ "autotab",	"at",	BOOL,	CANSET,		o_autotab	},
-	{ "autowrite",	"aw",	BOOL,	CANSET,		o_autowrite	},
-#ifndef CRUNCH
-	{ "beautify",	"bf",	BOOL,	CANSET,		o_beautify	},
-#endif
-#ifndef NO_ERRLIST
-	{ "cc",		"cc",	STR,	CANSET,		o_cc		},
-#endif
-#ifndef NO_CHARATTR
-	{ "charattr",	"ca",	BOOL,	CANSET|MR,	o_charattr	},
-#endif
-	{ "columns",	"co",	NUM,	SET|NOSAVE|MR,	o_columns	},
-#ifndef NO_DIGRAPH
-	{ "digraph",	"dig",	BOOL,	CANSET,		o_digraph	},
-#endif
-	{ "directory",	"dir",	STR,	RCSET,		o_directory	},
-	{ "edcompatible","ed",	BOOL,	CANSET,		o_edcompatible	},
-	{ "equalprg",	"ep",	STR,	CANSET,		o_equalprg	},
-	{ "errorbells",	"eb",	BOOL,	CANSET,		o_errorbells	},
-#ifndef CRUNCH
-	{ "exrc",	"exrc",	BOOL,	CANSET,		o_exrc		},
-#endif
-	{ "exrefresh",	"er",	BOOL,	CANSET,		o_exrefresh	},
-	{ "flash",	"vbell",BOOL,	CANSET,		o_flash		},
-#ifndef NO_DIGRAPH
-	{ "flipcase",	"fc",	STR,	CANSET,		o_flipcase	},
-#endif
-#ifndef NO_SENTENCE
-	{ "hideformat",	"hf",	BOOL,	CANSET|MR,	o_hideformat	},
-#endif
-	{ "ignorecase",	"ic",	BOOL,	CANSET,		o_ignorecase	},
-#ifndef NO_EXTENSIONS
-	{ "inputmode",	"im",	BOOL,	CANSET,		o_inputmode	},
-#endif
-	{ "keytime",	"kt",	NUM,	CANSET,		o_keytime	},
-	{ "keywordprg",	"kp",	STR,	CANSET,		o_keywordprg	},
-	{ "lines",	"ls",	NUM,	SET|NOSAVE|MR,	o_lines		},
-	{ "list",	"li",	BOOL,	CANSET|MR,	o_list		},
-#ifndef NO_MAGIC
-	{ "magic",	"ma",	BOOL,	CANSET,		o_magic		},
-#endif
-#ifndef NO_ERRLIST
-	{ "make",	"mk",	STR,	CANSET,		o_make		},
-#endif
-#ifndef CRUNCH
-	{ "mesg",	"me",	BOOL,	CANSET,		o_mesg		},
-#endif
-#ifndef NO_MODELINES
-	{ "modelines",	"ml",	BOOL,	CANSET,		o_modelines	},
-#endif
-#ifndef CRUNCH
-	{ "more",	"mo",	BOOL,	CANSET,		o_more		},
-	{ "novice",	"nov",	BOOL,	CANSET,		o_novice	},
-#endif
-	{ "number",	"nu",	BOOL,	CANSET|MR,	o_number	},
-#ifndef NO_SENTENCE
-	{ "paragraphs",	"para",	STR,	CANSET,		o_paragraphs	},
-#endif
-#if MSDOS
-	{ "pcbios",	"pc",	BOOL,	SET|NOSAVE,	o_pcbios	},
-#endif
-#ifndef CRUNCH
-	{ "prompt",	"pr",	BOOL,	CANSET,		o_prompt	},
-#endif
-	{ "readonly",	"ro",	BOOL,	CANSET,		o_readonly	},
-	{ "remap",	"remap",BOOL,	CANSET,		o_remap		},
-	{ "report",	"re",	NUM,	CANSET,		o_report	},
-#ifndef NO_EXTENSIONS
-	{ "ruler",	"ru",	BOOL,	CANSET,		o_ruler		},
-#endif
-	{ "scroll",	"sc",	NUM,	CANSET,		o_scroll	},
-#ifndef NO_SENTENCE
-	{ "sections",	"sect",	STR,	CANSET,		o_sections	},
-#endif
-	{ "shell",	"sh",	STR,	CANSET,		o_shell		},
-#ifndef NO_SHOWMATCH
-	{ "showmatch",	"sm",	BOOL,	CANSET,		o_showmatch	},
-#endif
-#ifndef	NO_SHOWMODE
-	{ "showmode",	"smd",	BOOL,	CANSET,		o_smd		},
-#endif
-	{ "shiftwidth",	"sw",	NUM,	CANSET,		o_shiftwidth	},
-	{ "sidescroll",	"ss",	NUM,	CANSET,		o_sidescroll	},
-	{ "sync",	"sy",	BOOL,	CANSET,		o_sync		},
-	{ "tabstop",	"ts",	NUM,	CANSET|MR,	o_tabstop	},
-#ifndef CRUNCH
-	{ "taglength",	"tl",	NUM,	CANSET,		o_taglength	},
-#endif
-	{ "term",	"te",	STR,	SET,		o_term		},
-#ifndef CRUNCH
-	{ "terse",	"tr",	BOOL,	CANSET,		o_terse		},
-	{ "timeout",	"to",	BOOL,	CANSET,		o_keytime	},
-#endif
-#ifndef CRUNCH
-	{ "window",	"wi",	NUM,	CANSET|MR|WSET,	o_window	},
-	{ "wrapmargin",	"wm",	NUM,	CANSET,		o_wrapmargin	},
-#endif
-	{ "wrapscan",	"ws",	BOOL,	CANSET,		o_wrapscan	},
-#ifndef CRUNCH
-	{ "writeany",	"wr",	BOOL,	CANSET,		o_writeany	},
-#endif
-	{ NULL, NULL, 0, CANSET, NULL }
-};
-
-
-/* This function initializes certain options from environment variables, etc. */
-void initopts()
-{
-	char	*val;
-	int	i;
-
-	/* set some stuff from environment variables */
-#if MSDOS
-	if (val = getenv("COMSPEC")) /* yes, ASSIGNMENT! */
-#else
-	if (val = getenv("SHELL")) /* yes, ASSIGNMENT! */
-#endif
-	{
-		strcpy(o_shell, val);
-	}
-
-	strcpy(o_term, termtype);
-#if MSDOS
-	if (strcmp(termtype, "pcbios"))
-	{
-		o_pcbios[0] = FALSE;
-	}
-	else
-	{
-		o_pcbios[0] = TRUE;
-	}
-#endif
-
-#if AMIGA || MSDOS || TOS
-	if ((val = getenv("TMP")) /* yes, ASSIGNMENT! */
-	||  (val = getenv("TEMP")))
-		strcpy(o_directory, val);
-#endif
-
-#ifndef CRUNCH
-	if ((val = getenv("LINES")) && atoi(val) > 4) /* yes, ASSIGNMENT! */
-	{
-		LINES = atoi(val);
-	}
-	if ((val = getenv("COLUMNS")) && atoi(val) > 30) /* yes, ASSIGNMENT! */
-	{
-		COLS = atoi(val);
-	}
-#endif
-	*o_lines = LINES;
-	*o_columns = COLS;
-	*o_scroll = LINES / 2 - 1;
-#ifndef CRUNCH
-	if (o_window[0] == 0)
-	{
-		o_window[0] = o_window[2] = *o_lines;
-	}
-#endif
-
-	/* disable the flash option if we don't know how to do a flash */
-	if (!has_VB)
-	{
-		for (i = 0; opts[i].value != o_flash; i++)
-		{
-		}
-		opts[i].flags &= ~CANSET;
-		*o_flash = FALSE;
-	}
-
-#ifndef NO_DIGRAPH
-# ifdef CS_LATIN1
-	for (i = 0, val = o_flipcase; i < 32; i++)
-	{
-		/* leave out the multiply/divide symbols */
-		if (i == 23)
-			continue;
-
-		/* add lower/uppercase pair */
-		*val++ = i + 0xe0;
-		*val++ = i + 0xc0;
-	}
-	*val = '\0';
-# endif /* CS_LATIN1 */
-
-	/* initialize the ctype package */
-	_ct_init(o_flipcase);
-#else
-	_ct_init("");
-#endif /* not NO_DIGRAPH */
-}
-
-/* This function lists the current values of all options */
-void dumpopts(all)
-	int	all;	/* boolean: dump all options, or just set ones? */
-{
-#ifndef NO_OPTCOLS
-	int	i, j, k;
-	char	nbuf[4];	/* used for converting numbers to ASCII */
-	int	widths[5];	/* width of each column, including gap */
-	int	ncols;		/* number of columns */
-	int	nrows;		/* number of options per column */
-	int	nset;		/* number of options to be output */
-	int	width;		/* width of a particular option */
-	int	todump[60];	/* indicies of options to be dumped */
-
-	/* step 1: count the number of set options */
-	for (nset = i = 0; opts[i].name; i++)
-	{
-		if (all || (opts[i].flags & SET))
-		{
-			todump[nset++] = i;
-		}
-	}
-
-	/* step two: try to use as many columns as possible */
-	for (ncols = (nset > 5 ? 5 : nset); ncols > 1; ncols--)
-	{
-		/* how many would go in this column? */
-		nrows = (nset + ncols - 1) / ncols;
-
-		/* figure out the width of each column */
-		for (i = 0; i < ncols; i++)
-		{
-			widths[i] = 0;
-			for (j = 0, k = nrows * i; j < nrows && k < nset; j++, k++)
-			{
-				/* figure out the width of a particular option */
-				switch (opts[todump[k]].type)
-				{
-				  case BOOL:
-					if (!*opts[todump[k]].value)
-						width = 2;
-					else
-						width = 0;
-					break;
-
-				  case STR:
-					width = 3 + strlen(opts[todump[k]].value);
-					if (width > MAXWIDTH)
-						width = MAXWIDTH;
-					break;
-
-				  case NUM:
-					width = 4;
-					break;
-				}
-				width += strlen(opts[todump[k]].name);
-
-				/* if this is the widest so far, widen col */
-				if (width > widths[i])
-				{
-					widths[i] = width;
-				}
-			}
-
-		}
-
-		/* if the total width is narrow enough, then use it */
-		for (width = -2, i = 0; i < ncols; i++)
-		{
-			width += widths[i] + 2;
-		}
-		if (width < COLS - 1)
-		{
-			break;
-		}
-	}
-
-	/* step 3: output the columns */
-	nrows = (nset + ncols - 1) / ncols;
-	for (i = 0; i < nrows; i++)
-	{
-		for (j = 0; j < ncols; j++)
-		{
-			/* if we hit the end of the options, quit */
-			k = i + j * nrows;
-			if (k >= nset)
-			{
-				break;
-			}
-
-			/* output this option's value */
-			width = 0;
-			switch (opts[todump[k]].type)
-			{
-			  case BOOL:
-				if (!*opts[todump[k]].value)
-				{
-					qaddch('n');
-					qaddch('o');
-					width = 2;
-				}
-				qaddstr(opts[todump[k]].name);
-				width += strlen(opts[todump[k]].name);
-				break;
-
-			  case NUM:
-				sprintf(nbuf, "%-3d", UCHAR(*opts[todump[k]].value));
-				qaddstr(opts[todump[k]].name);
-				qaddch('=');
-				qaddstr(nbuf);
-				width = 4 + strlen(opts[todump[k]].name);
-				break;
-
-			  case STR:
-				qaddstr(opts[todump[k]].name);
-				qaddch('=');
-				qaddch('"');
-				strcpy(tmpblk.c, opts[todump[k]].value);
-				width = 3 + strlen(tmpblk.c);
-				if (width > MAXWIDTH)
-				{
-					width = MAXWIDTH;
-					strcpy(tmpblk.c + MAXWIDTH - 6, "...");
-				}
-				qaddstr(tmpblk.c);
-				qaddch('"');
-				width += strlen(opts[todump[k]].name);
-				break;
-			}
-
-			/* pad the field to the correct size */
-			if (k + nrows <= nset)
-			{
-				while (width < widths[j] + 2)
-				{
-					qaddch(' ');
-					width++;
-				}
-			}
-		}
-		addch('\n');
-		exrefresh();
-	}
-#else
-	int	i;
-	int	col;
-	char	nbuf[4];
-
-	for (i = col = 0; opts[i].name; i++)
-	{
-		/* if not set and not all, ignore this option */
-		if (!all && !(opts[i].flags & SET))
-		{
-			continue;
-		}
-
-		/* align this option in one of the columns */
-		if (col > 52)
-		{
-			addch('\n');
-			col = 0;
-		}
-		else if (col > 26)
-		{
-			while (col < 52)
-			{
-				qaddch(' ');
-				col++;
-			}
-		}
-		else if (col > 0)
-		{
-			while (col < 26)
-			{
-				qaddch(' ');
-				col++;
-			}
-		}
-
-		switch (opts[i].type)
-		{
-		  case BOOL:
-			if (!*opts[i].value)
-			{
-				qaddch('n');
-				qaddch('o');
-				col += 2;
-			}
-			qaddstr(opts[i].name);
-			col += strlen(opts[i].name);
-			break;
-
-		  case NUM:
-			sprintf(nbuf, "%-3d", UCHAR(*opts[i].value));
-			qaddstr(opts[i].name);
-			qaddch('=');
-			qaddstr(nbuf);
-			col += 4 + strlen(opts[i].name);
-			break;
-
-		  case STR:
-			qaddstr(opts[i].name);
-			qaddch('=');
-			qaddch('"');
-			qaddstr(opts[i].value);
-			qaddch('"');
-			col += 3 + strlen(opts[i].name) + strlen(opts[i].value);
-			break;
-		}
-		exrefresh();
-	}
-	if (col > 0)
-	{
-		addch('\n');
-		exrefresh();
-	}
-#endif
-}
-
-#ifndef NO_MKEXRC
-/* This function saves the current configuration of options to a file */
-void saveopts(fd)
-	int	fd;	/* file descriptor to write to */
-{
-	int	i;
-	char	buf[256], *pos;
-
-	/* write each set options */
-	for (i = 0; opts[i].name; i++)
-	{
-		/* if unset or unsettable, ignore this option */
-		if ((opts[i].flags & (SET|CANSET|NOSAVE)) != (SET|CANSET))
-		{
-			continue;
-		}
-
-		strcpy(buf, "set ");
-		pos = &buf[4];
-		switch (opts[i].type)
-		{
-		  case BOOL:
-			if (!*opts[i].value)
-			{
-				*pos++='n';
-				*pos++='o';
-			}
-			strcpy(pos, opts[i].name);
-			strcat(pos, "\n");
-			break;
-
-		  case NUM:
-			sprintf(pos, "%s=%-3d\n", opts[i].name, *opts[i].value & 0xff);
-			break;
-
-		  case STR:
-			sprintf(pos, "%s=\"%s\"\n", opts[i].name, opts[i].value);
-			break;
-		}
-		twrite(fd, buf, (unsigned)strlen(buf));
-	}
-}
-#endif
-
-
-/* This function changes the values of one or more options. */
-void setopts(assignments)
-	char	*assignments;	/* a string containing option assignments */
-{
-	char	*name;		/* name of variable in assignments */
-	char	*value;		/* value of the variable */
-	char	*scan;		/* used for moving through strings */
-	char	*build;		/* used for copying chars from "scan" */
-	char	*prefix;	/* pointer to "neg" or "no" at front of a boolean */
-	int	quote;		/* boolean: inside '"' quotes? */
-	int	i, j;
-
-#ifndef CRUNCH
-	/* reset the upper limit of "window" option to lines-1 */
-	*o_window = *o_lines - 1;
-#endif
-
-	/* for each assignment... */
-	for (name = assignments; *name; )
-	{
-		/* skip whitespace */
-		if (*name == ' ' || *name == '\t')
-		{
-			name++;
-			continue;
-		}
-
-		/* after the name, find the value (if any) */
-		for (scan = name; isalnum(*scan); scan++)
-		{
-		}
-		if (*scan == '=')
-		{
-			*scan++ = '\0';
-			value = build = scan;
-			for (quote = FALSE; *scan && (quote || !isspace(*scan)); scan++)
-			{
-				if (*scan == '"')
-				{
-					quote = !quote;
-				}
-				else if (*scan == '\\' && scan[1])
-				{
-					*build++ = *++scan;
-				}
-				else
-				{
-					*build++ = *scan;
-				}
-			}
-			if (*scan)
-				scan++;
-			*build = '\0';
-		}
-		else /* no "=" so it is probably boolean... */
-		{
-			if (*scan)
-			{
-				*scan++ = '\0';
-			}
-			value = NULL;
-			prefix = name;
-#ifndef CRUNCH
-			if (!strcmp(name, "novice"))
-				/* don't check for a "no" prefix */;
-			else
-#endif
-			if (prefix[0] == 'n' && prefix[1] == 'o')
-				name += 2;
-			else if (prefix[0] == 'n' && prefix[1] == 'e' && prefix[2] == 'g')
-				name += 3;
-		}
-
-		/* find the variable */
-		for (i = 0;
-		     opts[i].name && strcmp(opts[i].name, name) && strcmp(opts[i].nm, name);
-		     i++)
-		{
-		}
-
-		/* change the variable */
-		if (!opts[i].name)
-		{
-			msg("invalid option name \"%s\"", name);
-		}
-		else if ((opts[i].flags & CANSET) != CANSET)
-		{
-			msg("option \"%s\" can't be altered", name);
-		}
-		else if ((opts[i].flags & RCSET) != CANSET && nlines >= 1L)
-		{
-			msg("option \"%s\" can only be set in a %s file", name, EXRC);
-		}
-		else if (value)
-		{
-			switch (opts[i].type)
-			{
-			  case BOOL:
-				msg("option \"[no]%s\" is boolean", name);
-				break;
-
-			  case NUM:
-				j = atoi(value);
-				if (j == 0 && *value != '0')
-				{
-					msg("option \"%s\" must have a numeric value", name);
-				}
-				else if (j < opts[i].value[1] || j > (opts[i].value[2] & 0xff))
-				{
-					msg("option \"%s\" must have a value between %d and %d",
-						name, opts[i].value[1], opts[i].value[2] & 0xff);
-				}
-				else
-				{
-					*opts[i].value = atoi(value);
-					opts[i].flags |= SET;
-				}
-				break;
-
-			  case STR:
-				strcpy(opts[i].value, value);
-				opts[i].flags |= SET;
-				break;
-			}
-			if (opts[i].flags & MR)
-			{
-				redraw(MARK_UNSET, FALSE);
-			}
-#ifndef CRUNCH
-			if (opts[i].flags & WSET)
-			{
-				wset = TRUE;
-			}
-#endif
-		}
-		else /* valid option, no value */
-		{
-			if (opts[i].type == BOOL)
-			{
-				if (prefix == name)
-					*opts[i].value = TRUE;
-				else if (prefix[1] == 'o')
-					*opts[i].value = FALSE;
-				else
-					*opts[i].value = !*opts[i].value;
-
-				opts[i].flags |= SET;
-				if (opts[i].flags & MR)
-				{
-					redraw(MARK_UNSET, FALSE);
-				}
-			}
-			else
-			{
-				msg("option \"%s\" must be given a value", name);
-			}
-		}
-
-		/* move on to the next option */
-		name = scan;
-	}
-
-	/* special processing ... */
-
-#ifndef CRUNCH
-	/* if "novice" is set, then ":set report=1 showmode nomagic" */
-	if (*o_novice)
-	{
-		*o_report = 1;
-# ifndef NO_SHOWMODE
-		*o_smd = TRUE;
-# endif
-# ifndef NO_MAGIC
-		*o_magic = FALSE;
-# endif
-	}
-#endif
-
-	/* if "readonly" then set the READONLY flag for this file */
-	if (*o_readonly)
-	{
-		setflag(file, READONLY);
-	}
-
-#ifndef NO_DIGRAPH
-	/* re-initialize the ctype package */
-	_ct_init(o_flipcase);
-#endif /* not NO_DIGRAPH */
-
-	/* copy o_lines and o_columns into LINES and COLS */
-	LINES = (*o_lines & 255);
-	COLS = (*o_columns & 255);
-}
Index: trunk/minix/commands/elvis/prsvunix.c
===================================================================
--- trunk/minix/commands/elvis/prsvunix.c	(revision 9)
+++ 	(revision )
@@ -1,106 +1,0 @@
-/* prsvunix.c */
-
-/* This file contains the UNIX-specific parts of the "elvprsv" program. */
-
-#if OSK
-#define ELVPRSV
-#include "osk.c"
-#else
-#include <sys/stat.h>
-#include <pwd.h>
-#endif
-extern struct passwd *getpwuid();
-
-/* This variable is used to add extra error messages for mail sent to root */
-char *ps;
-
-/* This function returns the login name of the owner of a file */
-char *ownername(filename)
-	char	*filename;	/* name of a file */
-{
-	struct stat	st;
-	struct passwd	*pw;
-
-	/* stat the file, to get its uid */
-	if (stat(filename, &st) < 0)
-	{
-		ps = "stat() failed";
-		return "root";
-	}
-
-	/* get the /etc/passwd entry for that user */
-	pw = getpwuid(st.st_uid);
-	if (!pw)
-	{
-		ps = "uid not found in password file";
-		return "root";
-	}
-
-	/* return the user's name */
-	return pw->pw_name;
-}
-
-
-/* This function sends a mail message to a given user, saying that a file
- * has been preserved.
- */
-void mail(user, file, when)
-	char	*user;	/* name of user who should receive the mail */
-	char	*file;	/* name of original text file that was preserved */
-	char	*when;	/* description of why the file was preserved */
-{
-	char	cmd[80];/* buffer used for constructing a "mail" command */
-	FILE	*m, *popen();	/* stream used for giving text to the "mail" program */
-	char	*base;	/* basename of the file */
-
-	/* separate the directory name from the basename. */
-	for (base = file + strlen(file); --base > file && *base != SLASH; )
-	{
-	}
-	if (*base == SLASH)
-	{
-		*base++ = '\0';
-	}
-
-	/* for anonymous buffers, pretend the name was "foo" */
-	if (!strcmp(base, "*"))
-	{
-		base = "foo";
-	}
-
-	/* open a pipe to the "mail" program */
-#if OSK
-	sprintf(cmd, "mail \"-s=%s preserved!\" %s", base, user);
-#else /* ANY_UNIX */
-	sprintf(cmd, "mail %s >/dev/null 2>/dev/null", user);
-#endif
-	m = popen(cmd, "w");
-	if (!m)
-	{
-		/* Can't send mail!  Hope the user figures it out. */
-		return;
-	}
-
-	/* Tell the user that the file was preserved */
-	fprintf(m, "A version of your file \"%s%c%s\"\n", file, SLASH, base);
-	fprintf(m, "was preserved when %s.\n", when);
-	fprintf(m, "To recover this file, do the following:\n");
-	fprintf(m, "\n");
-#if OSK
-	fprintf(m, "     chd %s\n", file);
-#else /* ANY_UNIX */
-	fprintf(m, "     cd %s\n", file);
-#endif
-	fprintf(m, "     elvrec %s\n", base);
-	fprintf(m, "\n");
-	fprintf(m, "With fond wishes for a speedy recovery,\n");
-	fprintf(m, "                                    Elvis\n");
-	if (ps)
-	{
-		fprintf(m, "\nP.S. %s\n", ps);
-		ps = (char *)0;
-	}
-
-	/* close the stream */
-	pclose(m);
-}
Index: trunk/minix/commands/elvis/recycle.c
===================================================================
--- trunk/minix/commands/elvis/recycle.c	(revision 9)
+++ 	(revision )
@@ -1,183 +1,0 @@
-/* recycle.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the functions perform garbage collection and allocate
- * reusable blocks.
- */
-
-#include "config.h"
-#include "vi.h"
-
-#ifndef NO_RECYCLE
-/* this whole file would have be skipped if NO_RECYCLE is defined */
-
-
-#define BTST(bitno, byte)	((byte) & (1 << (bitno)))
-#define BSET(bitno, byte)	((byte) |= (1 << (bitno)))
-#define BCLR(bitno, byte)	((byte) &= ~(1 << (bitno)))
-
-#define TST(blkno)		((blkno) < MAXBIT ? BTST((blkno) & 7, bitmap[(blkno) >> 3]) : 1)
-#define SET(blkno)		if ((blkno) < MAXBIT) BSET((blkno) & 7, bitmap[(blkno) >> 3])
-#define CLR(blkno)		if ((blkno) < MAXBIT) BCLR((blkno) & 7, bitmap[(blkno) >> 3])
-
-/* bitmap of free blocks in first 4096k of tmp file */
-static unsigned char bitmap[512];
-#define MAXBIT	(sizeof bitmap << 3)
-
-/* this function locates all free blocks in the current tmp file */
-void garbage()
-{
-	int	i;
-	BLK	oldhdr;
-
-	/* start by assuming every block is free */
-	for (i = 0; i < sizeof bitmap; i++)
-	{
-		bitmap[i] = 255;
-	}
-
-	/* header blocks aren't free */
-#ifndef lint
-	CLR(0);
-	CLR(1);
-#endif
-
-	/* blocks needed for current hdr aren't free */
-	for (i = 1; i < MAXBLKS; i++)
-	{
-		CLR(hdr.n[i]);
-	}
-
-	/* blocks needed for undo version aren't free */
-	lseek(tmpfd, 0L, 0);
-	if (read(tmpfd, &oldhdr, (unsigned)sizeof oldhdr) != sizeof oldhdr)
-	{
-		msg("garbage() failed to read oldhdr??");
-		for (i = 0; i < sizeof bitmap; i++)
-		{
-			bitmap[i] = 0;
-		}
-		return;
-	}
-	for (i = 1; i < MAXBLKS; i++)
-	{
-		CLR(oldhdr.n[i]);
-	}
-
-	/* blocks needed for cut buffers aren't free */
-	for (i = cutneeds(&oldhdr) - 1; i >= 0; i--)
-	{
-		CLR(oldhdr.n[i]);
-	}
-}
-
-/* This function allocates the first available block in the tmp file */
-long allocate()
-{
-	int	i;
-	long	offset;
-
-	/* search for the first byte with a free bit set */
-	for (i = 0; i < sizeof bitmap && bitmap[i] == 0; i++)
-	{
-	}
-
-	/* if we hit the end of the bitmap, return the end of the file */
-	if (i == sizeof bitmap)
-	{
-		offset = lseek(tmpfd, 0L, 2);
-	}
-	else /* compute the offset for the free block */
-	{
-		for (i <<= 3; TST(i) == 0; i++)
-		{
-		}
-		offset = (long)i * (long)BLKSIZE;
-
-		/* mark the block as "allocated" */
-		CLR(i);
-	}
-
-	return offset;
-}
-
-#endif
-
-#ifdef DEBUG
-# include <stdio.h>
-# undef malloc
-# undef free
-# define MEMMAGIC 0x19f72cc0L
-# define MAXALLOC 800
-static char *allocated[MAXALLOC];
-static char *fromfile[MAXALLOC];
-static int  fromline[MAXALLOC]; 
-static int  sizes[MAXALLOC];
-
-char *dbmalloc(size, file, line)
-	int	size;
-	char	*file;
-	int	line;
-{
-	char	*ret;
-	int	i;
-
-	size = size + sizeof(long) - (size % sizeof(long));
-	ret = (char *)malloc(size + 2 * sizeof(long)) + sizeof(long);
-	for (i = 0; i < MAXALLOC && allocated[i]; i++)
-	{
-	}
-	if (i == MAXALLOC)
-	{
-		endwin();
-		fprintf(stderr, "\r\n%s(%d): Too many malloc calls!\n", file, line);
-		abort();
-	}
-	sizes[i] = size/sizeof(long);
-	allocated[i] = ret;
-	fromfile[i] = file;
-	fromline[i] = line;
-	((long *)ret)[-1] = MEMMAGIC;
-	((long *)ret)[sizes[i]] = MEMMAGIC;
-	return ret;
-}
-
-dbfree(ptr, file, line)
-	char	*ptr;
-	char	*file;
-	int	line;
-{
-	int	i;
-
-	for (i = 0; i < MAXALLOC && allocated[i] != ptr; i++)
-	{
-	}
-	if (i == MAXALLOC)
-	{
-		endwin();
-		fprintf(stderr, "\r\n%s(%d): attempt to free mem that wasn't allocated\n", file, line);
-		abort();
-	}
-	allocated[i] = (char *)0;
-	if (((long *)ptr)[-1] != MEMMAGIC)
-	{
-		endwin();
-		fprintf(stderr, "\r\n%s(%d): underflowed malloc space, allocated at %s(%d)\n", file, line, fromfile[i], fromline[i]);
-		abort();
-	}
-	if (((long *)ptr)[sizes[i]] != MEMMAGIC)
-	{
-		endwin();
-		fprintf(stderr, "\r\n%s(%d): overflowed malloc space, allocated at %s(%d)\n", file, line, fromfile[i], fromline[i]);
-		abort();
-	}
-	free(ptr - sizeof(long));
-}
-#endif
Index: trunk/minix/commands/elvis/redraw.c
===================================================================
--- trunk/minix/commands/elvis/redraw.c	(revision 9)
+++ 	(revision )
@@ -1,1295 +1,0 @@
-/* redraw.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains functions that draw text on the screen.  The major entry
- * points are:
- *	redrawrange()	- called from modify.c to give hints about what parts
- *			  of the screen need to be redrawn.
- *	redraw()	- redraws the screen (or part of it) and positions
- *			  the cursor where it belongs.
- *	idx2col()	- converts a markidx() value to a logical column number.
- */
-
-#include "config.h"
-#include "vi.h"
-
-/* This variable contains the line number that smartdrawtext() knows best */
-static long smartlno;
-
-/* This function remembers where changes were made, so that the screen can be
- * redraw in a more efficient manner.
- */
-static long	redrawafter;	/* line# of first line that must be redrawn */
-static long	preredraw;	/* line# of last line changed, before change */
-static long	postredraw;	/* line# of last line changed, after change */
-static int	mustredraw;	/* boolean: anything forcing a screen update? */
-void redrawrange(after, pre, post)
-	long	after;	/* lower bound of redrawafter */
-	long	pre;	/* upper bound of preredraw */
-	long	post;	/* upper bound of postredraw */
-{
-	if (after == redrawafter)
-	{
-		/* multiple insertions/deletions at the same place -- combine
-		 * them
-		 */
-		preredraw -= (post - pre);
-		if (postredraw < post)
-		{
-			preredraw += (post - postredraw);
-			postredraw = post;
-		}
-		if (redrawafter > preredraw)
-		{
-			redrawafter = preredraw;
-		}
-		if (redrawafter < 1L)
-		{
-			redrawafter = 0L;
-			preredraw = postredraw = INFINITY;
-		}
-	}
-	else if (postredraw > 0L)
-	{
-		/* multiple changes in different places -- redraw everything
-		 * after "after".
-		 */
-		postredraw = preredraw = INFINITY;
-		if (after < redrawafter)
-			redrawafter = after;
-	}
-	else
-	{
-		/* first change */
-		redrawafter = after;
-		preredraw = pre;
-		postredraw = post;
-	}
-	mustredraw = TRUE;
-}
-
-
-#ifndef NO_CHARATTR
-/* see if a given line uses character attribute strings */
-static int hasattr(lno, text)
-	long		lno;	/* the line# of the cursor */
-	REG char	*text;	/* the text of the line, from fetchline */
-{
-	static long	plno;	/* previous line number */
-	static long	chgs;	/* previous value of changes counter */
-	static int	panswer;/* previous answer */
-	char		*scan;
-
-	/* if charattr is off, then the answer is "no, it doesn't" */
-	if (!*o_charattr)
-	{
-		chgs = 0; /* <- forces us to check if charattr is later set */
-		return FALSE;
-	}
-
-	/* if we already know the answer, return it... */
-	if (lno == plno && chgs == changes)
-	{
-		return panswer;
-	}
-
-	/* get the line & look for "\fX" */
-	if (!text[0] || !text[1] || !text[2])
-	{
-		panswer = FALSE;
-	}
-	else
-	{
-		for (scan = text; scan[2] && !(scan[0] == '\\' && scan[1] == 'f'); scan++)
-		{
-		}
-		panswer = (scan[2] != '\0');
-	}
-
-	/* save the results */
-	plno = lno;
-	chgs = changes;
-
-	/* return the results */
-	return panswer;
-}
-#endif
-
-
-#ifndef NO_VISIBLE
-/* This function checks to make sure that the correct lines are shown in
- * reverse-video.  This is used to handle the "v" and "V" commands.
- */
-static long	vizlow, vizhigh;	/* the starting and ending lines */
-static int	vizleft, vizright;	/* starting & ending indicies */
-static int	vizchange;		/* boolean: must use stupid drawtext? */
-static void setviz(curs)
-	MARK		curs;
-{
-	long		newlow, newhigh;
-	long		extra = 0L;
-
-	/* for now, assume the worst... */
-	vizchange = TRUE;
-
-	/* set newlow & newhigh according to V_from and cursor */
-	if (!V_from)
-	{
-		/* no lines should have reverse-video */
-		if (vizlow)
-		{
-			redrawrange(vizlow, vizhigh + 1L, vizhigh + 1L);
-			vizlow = vizhigh = 0L;
-		}
-		else
-		{
-			vizchange = FALSE;
-		}
-		return;
-	}
-
-	/* figure out which lines *SHOULD* have hilites */
-	if (V_from < curs)
-	{
-		newlow = markline(V_from);
-		newhigh = markline(curs);
-		vizleft = markidx(V_from);
-		vizright = markidx(curs) + 1;
-	}
-	else
-	{
-		newlow = markline(curs);
-		newhigh = markline(V_from);
-		vizleft = markidx(curs);
-		vizright = markidx(V_from) + 1;
-	}
-
-	/* adjust for line-mode hiliting */
-	if (V_linemd)
-	{
-		vizleft = 0;
-		vizright = BLKSIZE - 1;
-	}
-	else
-	{
-		extra = 1L;
-	}
-
-	/* arrange for the necessary lines to be redrawn */
-	if (vizlow == 0L)
-	{
-		/* just starting to redraw */
-		redrawrange(newlow, newhigh, newhigh);
-	}
-	else
-	{
-		/* Were new lines added/removed at the front? */
-		if (newlow != vizlow)
-		{
-			if (newlow < vizlow)
-				redrawrange(newlow, vizlow + extra, vizlow + extra);
-			else
-				redrawrange(vizlow, newlow + extra, newlow + extra);
-		}
-
-		/* Were new lines added/removed at the back? */
-		if (newhigh != vizhigh)
-		{
-			if (newhigh < vizhigh)
-				redrawrange(newhigh + 1L - extra, vizhigh + 1L, vizhigh + 1L);
-			else
-				redrawrange(vizhigh + 1L - extra, newhigh, newhigh);
-		}
-	}
-
-	/* remember which lines will contain hilighted text now */
-	vizlow = newlow;
-	vizhigh = newhigh;
-}
-#endif /* !NO_VISIBLE */
-
-
-/* This function converts a MARK to a column number.  It doesn't automatically
- * adjust for leftcol; that must be done by the calling function
- */
-int idx2col(curs, text, inputting)
-	MARK		curs;	/* the line# & index# of the cursor */
-	REG char	*text;	/* the text of the line, from fetchline */
-	int		inputting;	/* boolean: called from input() ? */
-{
-	static MARK	pcursor;/* previous cursor, for possible shortcut */
-	static MARK	pcol;	/* column number for pcol */
-	static long	chgs;	/* previous value of changes counter */
-	REG int		col;	/* used to count column numbers */
-	REG int		idx;	/* used to count down the index */
-	REG int		i;
-
-	/* for now, assume we have to start counting at the left edge */
-	col = 0;
-	idx = markidx(curs);
-
-	/* if the file hasn't changed & line number is the same & it has no
-	 * embedded character attribute strings, can we do shortcuts?
-	 */
-	if (chgs == changes
-	 && !((curs ^ pcursor) & ~(BLKSIZE - 1))
-#ifndef NO_CHARATTR
-	 && !hasattr(markline(curs), text)
-#endif
-	)
-	{
-		/* no movement? */
-		if (curs == pcursor)
-		{
-			/* return the column of the char; for tabs, return its last column */
-			if (text[idx] == '\t' && !inputting && !*o_list)
-			{
-				return pcol + *o_tabstop - (pcol % *o_tabstop) - 1;
-			}
-			else
-			{
-				return pcol;
-			}
-		}
-
-		/* movement to right? */
-		if (curs > pcursor)
-		{
-			/* start counting from previous place */
-			col = pcol;
-			idx = markidx(curs) - markidx(pcursor);
-			text += markidx(pcursor);
-		}
-	}
-
-	/* count over to the char after the idx position */
-	while (idx > 0 && (i = *text)) /* yes, ASSIGNMENT! */
-	{
-		if (i == '\t' && !*o_list)
-		{
-			col += *o_tabstop;
-			col -= col % *o_tabstop;
-		}
-		else if (i >= '\0' && i < ' ' || i == '\177')
-		{
-			col += 2;
-		}
-#ifndef NO_CHARATTR
-		else if (i == '\\' && text[1] == 'f' && text[2] && *o_charattr)
-		{
-			text += 2; /* plus one more at bottom of loop */
-			idx -= 2;
-		}			
-#endif
-		else
-		{
-			col++;
-		}
-		text++;
-		idx--;
-	}
-
-	/* save stuff to speed next call */
-	pcursor = curs;
-	pcol = col;
-	chgs = changes;
-
-	/* return the column of the char; for tabs, return its last column */
-	if (*text == '\t' && !inputting && !*o_list)
-	{
-		return col + *o_tabstop - (col % *o_tabstop) - 1;
-	}
-	else
-	{
-		return col;
-	}
-}
-
-
-/* This function is similar to idx2col except that it takes care of sideways
- * scrolling - for the given line, at least.
- */
-int mark2phys(m, text, inputting)
-	MARK	m;		/* a mark to convert */
-	char	*text;		/* the line that m refers to */
-	int	inputting;	/* boolean: caled from input() ? */
-{
-	int	i;
-
-	i = idx2col(m, text, inputting);
-	while (i < leftcol)
-	{
-		leftcol -= *o_sidescroll;
-		mustredraw = TRUE;
-		redrawrange(1L, INFINITY, INFINITY);
-	}
-	while (i > rightcol)
-	{
-		leftcol += *o_sidescroll;
-		mustredraw = TRUE;
-		redrawrange(1L, INFINITY, INFINITY);
-	}
-	physrow = markline(m) - topline;
-	physcol = i - leftcol;
-	if (*o_number)
-		physcol += 8;
-
-	return physcol;
-}
-
-/* This function draws a single line of text on the screen.  The screen's
- * cursor is assumed to be located at the leftmost column of the appropriate
- * row.
- */
-static void drawtext(text, lno, clr)
-	REG char	*text;	/* the text to draw */
-	long		lno;	/* the number of the line to draw */
-	int		clr;	/* boolean: do a clrtoeol? */
-{
-	REG int		col;	/* column number */
-	REG int		i;
-	REG int		tabstop;	/* *o_tabstop */
-	REG int		limitcol;	/* leftcol or leftcol + COLS */
-	int		abnormal;	/* boolean: charattr != A_NORMAL? */
-#ifndef NO_VISIBLE
-	int		rev;		/* boolean: standout mode, too? */
-	int		idx = 0;
-#endif
-	char		numstr[9];
-
-	/* show the line number, if necessary */
-	if (*o_number)
-	{
-		sprintf(numstr, "%6ld |", lno);
-		qaddstr(numstr);
-	}
-
-#ifndef NO_SENTENCE
-	/* if we're hiding format lines, and this is one of them, then hide it */
-	if (*o_hideformat && *text == '.')
-	{
-		clrtoeol();
-#if OSK
-		qaddch('\l');
-#else
-		qaddch('\n');
-#endif
-		return;
-	}
-#endif
-
-	/* move some things into registers... */
-	limitcol = leftcol;
-	tabstop = *o_tabstop;
-	abnormal = FALSE;
-
-#ifndef CRUNCH
-	if (clr)
-		clrtoeol();
-#endif
-
-	/* skip stuff that was scrolled off left edge */
-	for (col = 0;
-	     (i = *text) && col < limitcol; /* yes, ASSIGNMENT! */
-	     text++)
-	{
-#ifndef NO_VISIBLE
-		idx++;
-#endif
-		if (i == '\t' && !*o_list)
-		{
-			col = col + tabstop - (col % tabstop);
-		}
-		else if (i >= 0 && i < ' ' || i == '\177')
-		{
-			col += 2;
-		}
-#ifndef NO_CHARATTR
-		else if (i == '\\' && text[1] == 'f' && text[2] && *o_charattr)
-		{
-			text += 2; /* plus one more as part of "for" loop */
-
-			/* since this attribute might carry over, we need it */
-			switch (*text)
-			{
-			  case 'R':
-			  case 'P':
-				attrset(A_NORMAL);
-				abnormal = FALSE;
-				break;
-
-			  case 'B':
-				attrset(A_BOLD);
-				abnormal = TRUE;
-				break;
-
-			  case 'U':
-				attrset(A_UNDERLINE);
-				abnormal = TRUE;
-				break;
-
-			  case 'I':
-				attrset(A_ALTCHARSET);
-				abnormal = TRUE;
-				break;
-			}
-		}
-#endif
-		else
-		{
-			col++;
-		}
-	}
-
-#ifndef NO_VISIBLE
-	/* Should we start hiliting at the first char of this line? */
-	if ((lno > vizlow && lno <= vizhigh
-	    || lno == vizlow && vizleft < idx)
-	   && !(lno == vizhigh && vizright < idx))
-	{
-		do_VISIBLE();
-		rev = TRUE;
-	}
-#endif
-
-	/* adjust for control char that was partially visible */
-	while (col > limitcol)
-	{
-		qaddch(' ');
-		limitcol++;
-	}
-
-	/* now for the visible characters */
-	limitcol = leftcol + COLS;
-	if (*o_number)
-		limitcol -= 8;
-	for (; (i = *text) && col < limitcol; text++)
-	{
-#ifndef NO_VISIBLE
-		/* maybe turn hilite on/off in the middle of the line */
-		if (lno == vizlow && vizleft == idx)
-		{
-			do_VISIBLE();
-			rev = TRUE;
-		}
-		if (lno == vizhigh && vizright == idx)
-		{
-			do_SE();
-			rev = FALSE;
-		}
-		idx++;
-
-		/* if hiliting, never emit physical tabs */
-		if (rev && i == '\t' && !*o_list)
-		{
-			i = col + tabstop - (col % tabstop);
-			do
-			{
-				qaddch(' ');
-				col++;
-			} while (col < i);
-		}
-		else
-#endif /* !NO_VISIBLE */
-		if (i == '\t' && !*o_list)
-		{
-			i = col + tabstop - (col % tabstop);
-			if (i < limitcol)
-			{
-#ifdef CRUNCH
-				if (!clr && has_PT && !((i - leftcol) & 7))
-#else
-				if (has_PT && !((i - leftcol) & 7))
-#endif
-				{
-					do
-					{
-						qaddch('\t');
-						col += 8; /* not exact! */
-					} while (col < i);
-					col = i; /* NOW it is exact */
-				}
-				else
-				{
-					do
-					{
-						qaddch(' ');
-						col++;
-					} while (col < i);
-				}
-			}
-			else /* tab ending after screen? next line! */
-			{
-				col = limitcol;
-				if (has_AM)
-				{
-					addch('\n');	/* GB */
-				}
-			}
-		}
-		else if (i >= 0 && i < ' ' || i == '\177')
-		{
-			col += 2;
-			qaddch('^');
-			if (col <= limitcol)
-			{
-				qaddch(i ^ '@');
-			}
-		}
-#ifndef NO_CHARATTR
-		else if (i == '\\' && text[1] == 'f' && text[2] && *o_charattr)
-		{
-			text += 2; /* plus one more as part of "for" loop */
-			switch (*text)
-			{
-			  case 'R':
-			  case 'P':
-				attrset(A_NORMAL);
-				abnormal = FALSE;
-				break;
-
-			  case 'B':
-				attrset(A_BOLD);
-				abnormal = TRUE;
-				break;
-
-			  case 'U':
-				attrset(A_UNDERLINE);
-				abnormal = TRUE;
-				break;
-
-			  case 'I':
-				attrset(A_ALTCHARSET);
-				abnormal = TRUE;
-				break;
-			}
-		}
-#endif
-		else
-		{
-			col++;
-			qaddch(i);
-		}
-	}
-
-	/* get ready for the next line */
-#ifndef NO_CHARATTR
-	if (abnormal)
-	{
-		attrset(A_NORMAL);
-	}
-#endif
-	if (*o_list && col < limitcol)
-	{
-		qaddch('$');
-		col++;
-	}
-
-#ifndef NO_VISIBLE
-	/* did we hilite this whole line?  If so, STOP! */
-	if (rev)
-	{
-		do_SE();
-	}
-#endif
-
-#ifdef CRUNCH
-	if (clr && col < limitcol)
-	{
-		clrtoeol();
-	}
-#endif
-	if (!has_AM || col < limitcol)
-	{
-		addch('\n');
-	}
-
-	wqrefresh();
-}
-
-
-#ifndef CRUNCH
-static void nudgecursor(same, scan, new, lno)
-	int	same;	/* number of chars to be skipped over */
-	char	*scan;	/* where the same chars end */
-	char	*new;	/* where the visible part of the line starts */
-	long	lno;	/* line number of this line */
-{
-	int	col;
-
-	if (same > 0)
-	{
-		if (same < 5)
-		{
-			/* move the cursor by overwriting */
-			while (same > 0)
-			{
-				qaddch(scan[-same]);
-				same--;
-			}
-		}
-		else
-		{
-			/* move the cursor by calling move() */
-			col = (int)(scan - new);
-			if (*o_number)
-				col += 8;
-			move((int)(lno - topline), col);
-		}
-	}
-}
-#endif /* not CRUNCH */
-
-/* This function draws a single line of text on the screen, possibly with
- * some cursor optimization.  The cursor is repositioned before drawing
- * begins, so its position before doesn't really matter.
- */
-static void smartdrawtext(text, lno, showit)
-	REG char	*text;	/* the text to draw */
-	long		lno;	/* line number of the text */
-	int		showit;	/* boolean: output line? (else just remember it) */
-{
-#ifdef CRUNCH
-	move((int)(lno - topline), 0);
-	if (showit)
-	{
-		drawtext(text, lno, TRUE);
-	}
-#else /* not CRUNCH */
-	static char	old[256];	/* how the line looked last time */
-	char		new[256];	/* how it looks now */
-	char		*build;		/* used to put chars into new[] */
-	char		*scan;		/* used for moving thru new[] or old[] */
-	char		*end;		/* last non-blank changed char */
-	char		*shift;		/* used to insert/delete chars */
-	int		same;		/* length of a run of unchanged chars */
-	int		limitcol;
-	int		col;
-	int		i;
-	char		numstr[9];
-
-# ifndef NO_CHARATTR
-	/* if this line has attributes, do it the dumb way instead */
-	if (hasattr(lno, text))
-	{
-		move((int)(lno - topline), 0);
-		drawtext(text, lno, TRUE);
-		return;
-	}
-# endif
-# ifndef NO_SENTENCE
-	/* if this line is a format line, & we're hiding format lines, then
-	 * let the dumb drawtext() function handle it
-	 */
-	if (*o_hideformat && *text == '.')
-	{
-		move((int)(lno - topline), 0);
-		drawtext(text, lno, TRUE);
-		return;
-	}
-# endif
-# ifndef NO_VISIBLE
-	if (vizchange)
-	{
-		move((int)(lno - topline), 0);
-		drawtext(text, lno, TRUE);
-		smartlno = 0L;
-		return;
-	}
-# endif
-
-	/* skip stuff that was scrolled off left edge */
-	limitcol = leftcol;
-	for (col = 0;
-	     (i = *text) && col < limitcol; /* yes, ASSIGNMENT! */
-	     text++)
-	{
-		if (i == '\t' && !*o_list)
-		{
-			col = col + *o_tabstop - (col % *o_tabstop);
-		}
-		else if (i >= 0 && i < ' ' || i == '\177')
-		{
-			col += 2;
-		}
-		else
-		{
-			col++;
-		}
-	}
-
-	/* adjust for control char that was partially visible */
-	build = new;
-	while (col > limitcol)
-	{
-		*build++ = ' ';
-		limitcol++;
-	}
-
-	/* now for the visible characters */
-	limitcol = leftcol + COLS;
-	if (*o_number)
-		limitcol -= 8;
-	for (; (i = *text) && col < limitcol; text++)
-	{
-		if (i == '\t' && !*o_list)
-		{
-			i = col + *o_tabstop - (col % *o_tabstop);
-			while (col < i && col < limitcol)
-			{
-				*build++ = ' ';
-				col++;
-			}
-		}
-		else if (i >= 0 && i < ' ' || i == '\177')
-		{
-			col += 2;
-			*build++ = '^';
-			if (col <= limitcol)
-			{
-				*build++ = (i ^ '@');
-			}
-		}
-		else
-		{
-			col++;
-			*build++ = i;
-		}
-	}
-	if (col < limitcol && *o_list)
-	{
-		*build++ = '$';
-		col++;
-	}
-	end = build;
-	while (col < limitcol)
-	{
-		*build++ = ' ';
-		col++;
-	}
-
-	/* if we're just supposed to remember this line, then remember it */
-	if (!showit)
-	{
-		smartlno = lno;
-		strncpy(old, new, COLS);
-		return;
-	}
-
-	/* locate the last non-blank character */
-	while (end > new && end[-1] == ' ')
-	{
-		end--;
-	}
-
-	/* can we optimize the displaying of this line? */
-	if (lno != smartlno)
-	{
-		/* nope, can't optimize - different line */
-		move((int)(lno - topline), 0);
-
-		/* show the line number, if necessary */
-		if (*o_number)
-		{
-			sprintf(numstr, "%6ld |", lno);
-			qaddstr(numstr);
-		}
-
-		/* show the new line */
-		for (scan = new, build = old; scan < end; )
-		{
-			qaddch(*scan);
-			*build++ = *scan++;
-		}
-		if (end < new + COLS - (*o_number ? 8 : 0))
-		{
-			clrtoeol();
-			while (build < old + COLS)
-			{
-				*build++ = ' ';
-			}
-		}
-		smartlno = lno;
-		return;
-	}
-
-	/* skip any initial unchanged characters */
-	for (scan = new, build = old; scan < end && *scan == *build; scan++, build++)
-	{
-	}
-	i = (scan - new);
-	if (*o_number)
-		i += 8;
-	move((int)(lno - topline), i);
-
-	/* The in-between characters must be changed */
-	same = 0;
-	while (scan < end)
-	{
-		/* is this character a match? */
-		if (scan[0] == build[0])
-		{
-			same++;
-		}
-		else /* do we want to insert? */
-		if (scan < end - 1 && scan[1] == build[0] && (has_IC || has_IM))
-		{
-			nudgecursor(same, scan, new, lno);
-			same = 0;
-
-			insch(*scan);
-			for (shift = old + COLS; --shift > build; )
-			{
-				shift[0] = shift[-1];
-			}
-			*build = *scan;
-		}
-		else /* do we want to delete? */
-		if (build < old + COLS - 1 && scan[0] == build[1] && has_DC)
-		{
-			nudgecursor(same, scan, new, lno);
-			same = 0;
-
-			delch();
-			same++;
-			for (shift = build; shift < old + COLS - 1; shift++)
-			{
-				shift[0] = shift[1];
-			}
-			if (*o_number)
-				shift -= 8;
-			*shift = ' ';
-		}
-		else /* we must overwrite */
-		{
-			nudgecursor(same, scan, new, lno);
-			same = 0;
-
-			addch(*scan);
-			*build = *scan;
-		}
-
-		build++;
-		scan++;
-	}
-
-	/* maybe clear to EOL */
-	end = old + COLS - (*o_number ? 8 : 0);
-	while (build < end && *build == ' ')
-	{
-		build++;
-	}
-	if (build < end)
-	{
-		nudgecursor(same, scan, new, lno);
-		same = 0;
-
-		clrtoeol();
-		while (build < old + COLS)
-		{
-			*build++ = ' ';
-		}
-	}
-#endif /* not CRUNCH */
-}
-
-
-/* This function is used in visual mode for drawing the screen (or just parts
- * of the screen, if that's all thats needed).  It also takes care of
- * scrolling.
- */
-void redraw(curs, inputting)
-	MARK	curs;		/* where to leave the screen's cursor */
-	int	inputting;	/* boolean: being called from input() ? */
-{
-	char		*text;		/* a line of text to display */
-	static long	chgs;		/* previous changes level */
-	long		l;
-	int		i;
-#ifndef CRUNCH
-	static long	showtop;	/* top line in window */
-	static long	showbottom;	/* bottom line in window */
-#endif
-
-	/* if curs == MARK_UNSET, then we should reset internal vars */
-	if (curs == MARK_UNSET)
-	{
-		if (topline < 1 || topline > nlines)
-		{
-			topline = 1L;
-		}
-		else
-		{
-			move(LINES - 1, 0);
-			clrtoeol();
-		}
-		leftcol = 0;
-		mustredraw = TRUE;
-		redrawafter = INFINITY;
-		preredraw = 0L;
-		postredraw = 0L;
-		chgs = 0;
-		smartlno = 0L;
-#ifndef NO_VISIBLE
-		vizlow = vizhigh = 0L;
-		vizchange = FALSE;
-#endif
-#ifndef CRUNCH
-		showtop = 0;
-		showbottom = INFINITY;
-#endif
-		return;
-	}
-
-#ifndef NO_VISIBLE
-	/* adjustments to hilited area may force extra lines to be redrawn. */
-	setviz(curs);
-#endif
-
-	/* figure out which column the cursor will be in */
-	l = markline(curs);
-	text = fetchline(l);
-	mark2phys(curs, text, inputting);
-
-#ifndef NO_COLOR
-	fixcolor();
-#endif
-
-	/* adjust topline, if necessary, to get the cursor on the screen */
-	if (l >= topline && l <= botline)
-	{
-		/* it is on the screen already */
-
-		/* if the file was changed but !mustredraw, then redraw line */
-		if (!mustredraw && (chgs != changes
-#ifndef NO_VISIBLE
-			|| V_from
-#endif
-#ifndef CRUNCH
-			|| l < showtop || l > showbottom
-#endif
-							))
-		{
-			smartdrawtext(text, l, (chgs != changes));
-		}
-	}
-	else if (l < topline && l > topline - LINES && (has_SR || has_AL))
-	{
-		/* near top - scroll down */
-		if (!mustredraw)
-		{
-			move(0,0);
-			while (l < topline)
-			{
-				topline--;
-				if (has_SR)
-				{
-					do_SR();
-				}
-				else
-				{
-					insertln();
-				}
-				text = fetchline(topline);
-				drawtext(text, topline, FALSE);
-				do_UP();
-			}
-
-			/* blank out the last line */
-			move(LINES - 1, 0);
-			clrtoeol();
-		}
-		else
-		{
-			topline = l;
-			redrawrange(0L, INFINITY, INFINITY);
-		}
-	}
-	else if (l > topline && l < botline + LINES)
-	{
-		/* near bottom -- scroll up */
-		if (!mustredraw)
-		{
-			move(LINES - 1,0);
-			clrtoeol();
-			while (l > botline)
-			{
-				topline++; /* <-- also adjusts botline */
-				text = fetchline(botline);
-				drawtext(text, botline, FALSE);
-			}
-#ifndef CRUNCH
-			showbottom = l;
-#endif
-		}
-		else
-		{
-			topline = l - (LINES - 2);
-			redrawrange(0L, INFINITY, INFINITY);
-		}
-	}
-	else
-	{
-		/* distant line - center it & force a redraw */
-		topline = l - (LINES / 2) - 1;
-		if (topline < 1)
-		{
-			topline = 1;
-		}
-		redrawrange(0L, INFINITY, INFINITY);
-		changes++;
-	}
-
-#ifndef CRUNCH
-	/* make sure the current line is included in the "window" */
-	if (l < showtop)
-	{
-		redrawrange(l, showtop, showtop);
-		showtop = l;
-	}
-	if (l > showbottom)
-	{
-		redrawrange(showbottom, l, l);
-		showbottom = l;
-	}
-#endif
-
-
-	/* Now... do we really have to redraw? */
-	if (mustredraw)
-	{
-		/* If redrawfter (and friends) aren't set, assume we should
-		 * redraw everything.
-		 */
-		if (redrawafter == INFINITY)
-		{
-			redrawafter = 0L;
-			preredraw = postredraw = INFINITY;
-		}
-
-#ifndef CRUNCH
-		/* shrink the window, if possible */
-		if (showtop < topline)
-		{
-			showtop = topline;
-		}
-		if (showbottom > botline)
-		{
-			showbottom = botline;
-		}
-		if (postredraw == INFINITY)
-		{
-			/* these will be set to more reasonable values later */
-			showtop = INFINITY;
-			showbottom = 0L;
-		}
-#endif
-
-		/* adjust smartlno to correspond with inserted/deleted lines */
-		if (smartlno >= redrawafter)
-		{
-			if (smartlno < preredraw && postredraw != preredraw) /*!!!*/
-			{
-				smartlno = 0L;
-			}
-			else
-			{
-				smartlno += (postredraw - preredraw);
-			}
-		}
-
-		/* should we insert some lines into the screen? */
-		if (preredraw < postredraw && preredraw <= botline)
-		{
-			/* lines were inserted into the file */
-
-			/* decide where insertion should start */
-			if (preredraw < topline)
-			{
-				l = topline;
-			}
-			else
-			{
-				l = preredraw;
-			}
-
-			/* insert the lines... maybe */
-			if (l + postredraw - preredraw > botline || !has_AL || *o_number)
-			{
-				/* Whoa!  a whole screen full - just redraw */
-				preredraw = postredraw = INFINITY;
-			}
-			else
-			{
-				/* really insert 'em */
-				move((int)(l - topline), 0);
-				for (i = postredraw - preredraw; i > 0; i--)
-				{
-					insertln();
-				}
-
-				/* NOTE: the contents of those lines will be
-				 * drawn as part of the regular redraw loop.
-				 */
-
-				/* clear the last line */
-				move(LINES - 1, 0);
-				clrtoeol();
-			}
-		}
-
-		/* do we want to delete some lines from the screen? */
-		if (preredraw > postredraw && postredraw <= botline)
-		{
-			if (preredraw > botline || !has_DL || *o_number)
-			{
-				postredraw = preredraw = INFINITY;
-			}
-			else /* we'd best delete some lines from the screen */
-			{
-				/* clear the last line, so it doesn't look
-				 * ugly as it gets pulled up into the screen
-				 */
-				move(LINES - 1, 0);
-				clrtoeol();
-
-				/* delete the lines */
-				move((int)(postredraw - topline), 0);
-			 	for (l = postredraw;
-				     l < preredraw && l <= botline;
-				     l++)
-				{
-					deleteln();
-				}
-
-				/* draw the lines that are now newly visible
-				 * at the bottom of the screen
-				 */
-				i = LINES - 1 + (postredraw - preredraw);
-				move(i, 0);
-				for (l = topline + i; l <= botline; l++)
-				{
-					/* clear this line */
-					clrtoeol();
-
-					/* draw the line, or ~ for non-lines */
-					if (l <= nlines)
-					{
-						text = fetchline(l);
-						drawtext(text, l, FALSE);
-					}
-					else
-					{
-						addstr("~\n");
-					}
-				}
-			}
-		}
-
-		/* redraw the current line */
-		l = markline(curs);
-		pfetch(l);
-		smartdrawtext(ptext, l, TRUE);
-
-#ifndef CRUNCH
-		/* decide which lines must be in the "window" around the cursor */
-		l = markline(curs);
-		if ((*o_window & 0xff) + 1 == LINES)
-		{
-			showtop = 1;
-			showbottom = INFINITY;
-		}
-		else if (l < showtop || l > showbottom)
-		{
-			l -= (*o_window & 0xff) / 2;
-			if (l < topline)
-			{
-				l = topline;
-			}
-			if (l < showtop)
-			{
-				showtop = l;
-			}
-			l += (*o_window & 0xff) - 1;
-			if (l > botline)
-			{
-				showtop = showtop - l + botline;
-				l = botline;
-			}
-			if (l > showbottom)
-			{
-				showbottom = l;
-			}
-		}
-#endif
-
-		/* decide where we should start redrawing from */
-		if (redrawafter < topline)
-		{
-			l = topline;
-		}
-		else
-		{
-			l = redrawafter;
-		}
-		if (l <= botline && l < postredraw && (l != smartlno || botline != smartlno))
-		{
-			/* draw the other lines */
-			move((int)(l - topline), 0);
-			for (; l <= botline && l < postredraw; l++)
-			{
-				/* we already drew the current line, so skip it now */
-				if (l == smartlno)
-				{
-#if OSK
-					qaddch('\l');
-#else
-					qaddch('\n');
-#endif
-					continue;
-				}
-
-				/* draw the line, or ~ for non-lines */
-				if (l > nlines)
-				{
-					qaddch('~');
-					clrtoeol();
-					addch('\n');
-				}
-#ifndef CRUNCH
-				else if (l < showtop || l > showbottom)
-				{
-					qaddch('@');
-					clrtoeol();
-					addch('\n');
-				}
-#endif
-				else
-				{
-					text = fetchline(l);
-					drawtext(text, l, TRUE);
-				}
-			}
-		}
-
-		mustredraw = FALSE;
-	}
-
-	/* force total (non-partial) redraw next time if not set */
-	redrawafter = INFINITY;
-	preredraw = 0L;
-	postredraw = 0L;
-
-	/* move the cursor to where it belongs */
-	move((int)(markline(curs) - topline), physcol);
-	wqrefresh();
-
-	chgs = changes;
-}
Index: trunk/minix/commands/elvis/ref.c
===================================================================
--- trunk/minix/commands/elvis/ref.c	(revision 9)
+++ 	(revision )
@@ -1,521 +1,0 @@
-/* ref2.c */
-
-/* This is a totally rewritten version of ref.  This version looks for the
- * desired function name in the "tags" file, and then reads the header out
- * from the source file.  There is no longer any need for a "refs" file.
- *
- * Usage:	ref [-a] [-t] [-f file] [-c class] tag
- * Options:	-t	   output tag info, not the description
- *		-f file	   default filename for static functions
- *		-c class   default class names for class functions
- */
-
-#include <stdio.h>
-#include "config.h"
-extern char	*getenv();
-extern char	*fgets();
-
-
-/* This is the default path that is searched for tags */
-#if OSK
-# define DEFTAGPATH ".:/dd/defs:/dd/defs/sys:/dd/usr/src/lib:../lib:/dd/usr/lib"
-#else
-# if ANY_UNIX
-#  define DEFTAGPATH ".:/usr/include:/usr/include/sys:/usr/src/lib:../lib:/usr/local/lib"
-# else
-#  if MSDOS || TOS
-#   define DEFTAGPATH ".;C:\\include;C:\\include\\sys;C:\\lib;..\\lib"
-#   define SEP ';'
-#  else
-#   if AMIGA
-#    define DEFTAGPATH ".;Include:;Include:sys"
-#    define SEP ';'
-#   else /* any other OS */
-#    define DEFTAGPATH "."
-#   endif
-#  endif
-# endif
-#endif
-
-#ifndef SEP
-# define SEP ':'
-#endif
-
-
-/* These variables reflect the command-line options given by the user. */
-int	taginfo;	/* boolean: give only the tag info? (not header?) */
-char	*def_file;	/* default filename for static functions */
-char	*def_class;	/* default classname for class members */
-int	colons;		/* #colons in tag: 0=normal, 1=static, 2=member */
-
-/* This function checks for a tag in the "tags" file of given directory.
- * If the tag is found, then it returns a pointer to a static buffer which
- * contains the filename, a tab character, and a linespec for finding the
- * the tag.  If the tag is not found in the "tags" file, or if the "tags"
- * file cannot be opened or doesn't exist, then this function returns NULL.
- */
-char *cktagdir(tag, dir)
-	char	*tag;	/* name of the tag to look for */
-	char	*dir;	/* name of the directory to check */
-{
-	char	buf[BLKSIZE];
-	static char found[BLKSIZE];
-	FILE	*tfile;
-	int	len;
-
-#if AMIGA
-	if (dir[strlen(dir) - 1] == COLON)
-	    sprintf(buf, "%s%s", dir, TAGS);   /* no slash after colon. */
-	else
-#endif
-	/* construct the name of the "tags" file in this directory */
-	sprintf(buf, "%s%c%s", dir, SLASH, TAGS);
-
-	/* Try to open the tags file.  Return NULL if can't open */
-#if AMIGA
-	if (buf[0] == '.' && buf[1] == SLASH)
-	    tfile = fopen(&buf[2], "r");
-	else
-#endif
-	tfile = fopen(buf, "r");
-	if (!tfile)
-	{
-		return (char *)0;
-	}
-
-	/* compute the length of the tagname once */
-	len = strlen(tag);
-
-	/* read lines until we get the one for this tag */
-	found[0] = '\0';
-	while (fgets(buf, sizeof buf, tfile))
-	{
-		/* is this the one we want? */
-		if (!strncmp(buf, tag, len) && buf[len] == '\t')
-		{
-			/* we've found a match -- remember it */
-			strcpy(found, buf);
-
-			/* if there is no default file, or this match is in
-			 * the default file, then we've definitely found the
-			 * one we want.  Break out of the loop now.
-			 */
-			if (!def_file || !strncmp(&buf[len + 1], def_file, strlen(def_file)))
-			{
-				break;
-			}
-		}
-	}
-
-	/* we're through reading */
-	fclose(tfile);
-
-	/* if there's anything in found[], use it */
-	if (found[0])
-	{
-		return &found[len + 1];
-	}
-
-	/* else we didn't find it */
-	return (char *)0;
-}
-
-/* This function reads a single textline from a binary file.  It returns
- * the number of bytes read, or 0 at EOF.
- */
-int getline(buf, limit, fp)
-	char	*buf;	/* buffer to read into */
-	int	limit;	/* maximum characters to read */
-	FILE	*fp;	/* binary stream to read from */
-{
-	int	bytes;	/* number of bytes read so far */
-	int	ch;	/* single character from file */
-
-	for (bytes = 0, ch = 0; ch != '\n' && --limit > 0 && (ch = getc(fp)) != EOF; bytes++)
-	{
-#if MSDOS || TOS
-		/* since this is a binary file, we'll need to manually strip CR's */
-		if (ch == '\r')
-		{
-			continue;
-		}
-#endif
-		*buf++ = ch;
-	}
-	*buf = '\0';
-
-	return bytes;
-}
-
-
-/* This function reads a source file, looking for a given tag.  If it finds
- * the tag, then it displays it and returns TRUE.  Otherwise it returns FALSE.
- * To display the tag, it attempts to output any introductory comment, the
- * tag line itself, and any arguments.  Arguments are assumed to immediately
- * follow the tag line, and start with whitespace.  Comments are assumed to
- * start with lines that begin with "/*", "//", "(*", or "--", and end at the
- * tag line or at a blank line.
- */
-int lookup(dir, entry)
-	char	*dir;	/* name of the directory that contains the source */
-	char	*entry;	/* source filename, <Tab>, linespec */
-{
-	char	buf[BLKSIZE];	/* pathname of sourcefile */
-	long	lnum;		/* line number */
-	long	here;		/* seek position where current line began */
-	long	comment;	/* seek position of introductory comment, or -1L */
-	FILE	*sfile;		/* used for reading the source file */
-	int	len;		/* length of string */
-	char	*ptr;
-
-
-	/* construct the pathname of the source file */
-	strcpy(buf, dir);
-	ptr = buf + strlen(buf);
-#if AMIGA
-	if (ptr[-1] != COLON)
-#endif
-	*ptr++ = SLASH;
-	while (*entry != '\t')
-	{
-		*ptr++ = *entry++;
-	}
-	*ptr = '\0';
-	entry++;
-
-	/* searching for string or number? */
-	if (*entry >= '0' && *entry <= '9')
-	{
-		/* given a specific line number */
-		lnum = atol(entry);
-		entry = (char *)0;
-	}
-	else
-	{
-		/* given a string -- strip off "/^" and "$/\n" */
-		entry += 2;
-		len = strlen(entry) - 2;
-		if (entry[len - 1] == '$')
-		{
-			entry[len - 1] = '\n';
-		}
-		lnum = 0L;
-	}
-
-	/* Open the file.  Note that we open the file in binary mode even
-	 * though we know it is a text file, because ftell() and fseek()
-	 * don't work on text files.
-	 */
-#if MSDOS || TOS
-	sfile = fopen(buf, "rb");
-#else
-# if AMIGA
-	if (buf[0] == '.' && buf[1] == SLASH)
-	    sfile = fopen(&buf[2], "r");
-	else
-# endif
-	sfile = fopen(buf, "r");
-#endif
-	if (!sfile)
-	{
-		/* can't open the real source file.  Try "refs" instead */
-#if AMIGA
-		if (dir[strlen(dir) - 1] == COLON)
-			sprintf(buf, "%srefs", dir);
-		else
-#endif
-		sprintf(buf, "%s%crefs", dir, SLASH);
-#if MSDOS || TOS
-		sfile = fopen(buf, "rb");
-#else
-# if AMIGA
-		if (buf[0] == '.' && buf[1] == SLASH)
-		    sfile = fopen(&buf[2], "r");
-		else
-# endif
-		sfile = fopen(buf, "r");
-#endif
-		if (!sfile)
-		{
-			/* failed! */
-			return 0;
-		}
-	}
-
-	/* search the file */
-	for (comment = -1L; here = ftell(sfile), getline(buf, BLKSIZE, sfile) > 0; )
-	{
-		/* Is this the start/end of a comment? */
-		if (comment == -1L)
-		{
-			/* starting a comment? */
-			if (buf[0] == '/' && buf[1] == '*'
-			 || buf[0] == '/' && buf[1] == '/'
-			 || buf[0] == '(' && buf[1] == '*'
-			 || buf[0] == '-' && buf[1] == '-')
-			{
-				comment = here;
-			}
-		}
-		else
-		{
-			/* ending a comment? */
-			if (buf[0] == '\n' || buf[0] == '#')
-			{
-				comment = -1L;
-			}
-		}
-
-		/* is this the tag line? */
-		if (--lnum == 0L || (entry && !strncmp(buf, entry, len)))
-		{
-			/* if there were introductory comments, show them */
-			if (comment != -1L)
-			{
-				fseek(sfile, comment, 0);
-				while (comment != here)
-				{
-					getline(buf, BLKSIZE, sfile);
-					fputs(buf, stdout);
-					comment = ftell(sfile);
-				}
-
-				/* re-fetch the tag line */
-				fgets(buf, BLKSIZE, sfile);
-			}
-
-			/* show the tag line */
-			fputs(buf, stdout);
-
-			/* show any argument lines */
-			while (getline(buf, BLKSIZE, sfile) > 0
-			    && buf[0] != '#'
-			    && strchr(buf, '{') == (char *)0)
-			{
-				fputs(buf, stdout);
-			}
-
-			/* Done!  Close the file, and return TRUE */
-			fclose(sfile);
-			return 1;
-		}
-	}
-
-	/* not found -- return FALSE */
-	return 0;
-}
-
-/* This function searches through the entire search path for a given tag.
- * If it finds the tag, then it displays the info and returns TRUE;
- * otherwise it returns FALSE.
- */
-int find(tag)
-	char	*tag;	/* the tag to look up */
-{
-	char	*tagpath;
-	char	dir[80];
-	char	*ptr;
-	int	len;
-
-	if (colons == 1)
-	{
-		/* looking for static function -- only look in current dir */
-		tagpath = ".";
-	}
-	else
-	{
-		/* get the tagpath from the environment.  Default to DEFTAGPATH */
-		tagpath = getenv("TAGPATH");
-		if (!tagpath)
-		{
-			tagpath = DEFTAGPATH;
-		}
-	}
-
-	/* for each entry in the path... */
-	while (*tagpath)
-	{
-		/* Copy the entry into the dir[] buffer */
-		for (ptr = dir; *tagpath && *tagpath != SEP; tagpath++)
-		{
-			*ptr++ = *tagpath;
-		}
-		if (*tagpath == SEP)
-		{
-			tagpath++;
-		}
-
-		/* if the entry ended with "/tags", then strip that off */
-		len = strlen(TAGS);
-		if (&dir[len] < ptr && ptr[-len - 1] == SLASH && !strncmp(&ptr[-len], TAGS, len))
-		{
-			ptr -= len + 1;
-		}
-
-		/* if the entry is now an empty string, then assume "." */
-		if (ptr == dir)
-		{
-			*ptr++ = '.';
-		}
-		*ptr = '\0';
-
-		/* look for the tag in this path.  If found, then display it
-		 * and exit.
-		 */
-		ptr = cktagdir(tag, dir);
-		if (ptr)
-		{
-			/* just supposed to display tag info? */
-			if (taginfo)
-			{
-				/* then do only that! */
-				if (strcmp(dir, "."))
-				{
-					printf("%s%c%s", dir, SLASH, ptr);
-				}
-				else
-				{
-					/* avoid leading "./" if possible */
-					fputs(ptr, stdout);
-				}
-				return 1;
-			}
-			else
-			{
-				/* else look up the declaration of the thing */
-				return lookup(dir, ptr);
-			}
-		}
-	}
-
-	/* if we get here, then the tag wasn't found anywhere */
-	return 0;
-}
-
-void usage()
-{
-	fputs("usage: ref [-a] [-t] [-c class] [-f file] tag\n", stderr);
-	fputs("   -a        function's args may be flush against left margin\n", stderr);
-	fputs("   -t        output tag info, instead of the function header\n", stderr);
-	fputs("   -f File   tag might be a static function in File\n", stderr);
-	fputs("   -c Class  tag might be a member of class Class\n", stderr);
-	exit(2);
-}
-
-
-int countcolons(str)
-	char	*str;
-{
-	while (*str != ':' && *str)
-	{
-		str++;
-	}
-	if (str[0] != ':')
-	{
-		return 0;
-	}
-	else if (str[1] != ':')
-	{
-		return 1;
-	}
-	return 2;
-}
-
-int main(argc, argv)
-	int	argc;
-	char	**argv;
-{
-	char	def_tag[100];	/* used to build tag name with default file/class */
-	int	i;
-
-	/* parse flags */
-	for (i = 1; i < argc && argv[i][0] == '-'; i++)
-	{
-		switch (argv[i][1])
-		{
-		  case 't':
-			taginfo = 1;
-			break;
-
-		  case 'f':
-			if (argv[i][2])
-			{
-				def_file = &argv[i][2];
-			}
-			else if (++i < argc)
-			{
-				def_file = argv[i];
-			}
-			else
-			{
-				usage();
-			}
-			break;
-
-		  case 'c':
-			if (argv[i][2])
-			{
-				def_class = &argv[i][2];
-			}
-			else if (++i < argc)
-			{
-				def_class = argv[i];
-			}
-			else
-			{
-				usage();
-			}
-			break;
-
-		  default:
-			usage();
-		}
-	}
-
-	/* if no tag was given, complain */
-	if (i + 1 != argc)
-	{
-		usage();
-	}
-
-	/* does the tag have an explicit class or file? */
-	colons = countcolons(argv[i]);
-
-	/* if not, then maybe try some defaults */
-	if (colons == 0)
-	{
-		/* try a static function in the file first */
-		if (def_file)
-		{
-			sprintf(def_tag, "%s:%s", def_file, argv[i]);
-			colons = 1;
-			if (find(def_tag))
-			{
-				exit(0);
-			}
-		}
-
-		/* try a member function for a class */
-		if (def_class)
-		{
-			sprintf(def_tag, "%s::%s", def_class, argv[i]);
-			colons = 2;
-			if (find(def_tag))
-			{
-				exit(0);
-			}
-		}
-
-		/* oh, well */
-		colons = 0;
-	}
-
-	/* find the tag */
-	if (find(argv[i]))
-	{
-		exit(0);
-	}
-
-	exit(1);
-	/*NOTREACHED*/
-}
Index: trunk/minix/commands/elvis/regexp.c
===================================================================
--- trunk/minix/commands/elvis/regexp.c	(revision 9)
+++ 	(revision )
@@ -1,934 +1,0 @@
-/* regexp.c */
-
-/* This file contains the code that compiles regular expressions and executes
- * them.  It supports the same syntax and features as vi's regular expression
- * code.  Specifically, the meta characters are:
- *	^	matches the beginning of a line
- *	$	matches the end of a line
- *	\<	matches the beginning of a word
- *	\>	matches the end of a word
- *	.	matches any single character
- *	[]	matches any character in a character class
- *	\(	delimits the start of a subexpression
- *	\)	delimits the end of a subexpression
- *	*	repeats the preceding 0 or more times
- * NOTE: You cannot follow a \) with a *.
- *
- * The physical structure of a compiled RE is as follows:
- *	- First, there is a one-byte value that says how many character classes
- *	  are used in this regular expression
- *	- Next, each character class is stored as a bitmap that is 256 bits
- *	  (32 bytes) long.
- *	- A mixture of literal characters and compiled meta characters follows.
- *	  This begins with M_BEGIN(0) and ends with M_END(0).  All meta chars
- *	  are stored as a \n followed by a one-byte code, so they take up two
- *	  bytes apiece.  Literal characters take up one byte apiece.  \n can't
- *	  be used as a literal character.
- *
- * If NO_MAGIC is defined, then a different set of functions is used instead.
- * That right, this file contains TWO versions of the code.
- */
-
-#include <setjmp.h>
-#include "config.h"
-#include "ctype.h"
-#include "vi.h"
-#include "regexp.h"
-
-
-
-static char	*previous;	/* the previous regexp, used when null regexp is given */
-
-
-#ifndef NO_MAGIC
-/* THE REAL REGEXP PACKAGE IS USED UNLESS "NO_MAGIC" IS DEFINED */
-
-/* These are used to classify or recognize meta-characters */
-#define META		'\0'
-#define BASE_META(m)	((m) - 256)
-#define INT_META(c)	((c) + 256)
-#define IS_META(m)	((m) >= 256)
-#define IS_CLASS(m)	((m) >= M_CLASS(0) && (m) <= M_CLASS(9))
-#define IS_START(m)	((m) >= M_START(0) && (m) <= M_START(9))
-#define IS_END(m)	((m) >= M_END(0) && (m) <= M_END(9))
-#define IS_CLOSURE(m)	((m) >= M_SPLAT && (m) <= M_RANGE)
-#define ADD_META(s,m)	(*(s)++ = META, *(s)++ = BASE_META(m))
-#define GET_META(s)	(*(s) == META ? INT_META(*++(s)) : *s)
-
-/* These are the internal codes used for each type of meta-character */
-#define M_BEGLINE	256		/* internal code for ^ */
-#define M_ENDLINE	257		/* internal code for $ */
-#define M_BEGWORD	258		/* internal code for \< */
-#define M_ENDWORD	259		/* internal code for \> */
-#define M_ANY		260		/* internal code for . */
-#define M_SPLAT		261		/* internal code for * */
-#define M_PLUS		262		/* internal code for \+ */
-#define M_QMARK		263		/* internal code for \? */
-#define M_RANGE		264		/* internal code for \{ */
-#define M_CLASS(n)	(265+(n))	/* internal code for [] */
-#define M_START(n)	(275+(n))	/* internal code for \( */
-#define M_END(n)	(285+(n))	/* internal code for \) */
-
-/* These are used during compilation */
-static int	class_cnt;	/* used to assign class IDs */
-static int	start_cnt;	/* used to assign start IDs */
-static int	end_stk[NSUBEXP];/* used to assign end IDs */
-static int	end_sp;
-static char	*retext;	/* points to the text being compiled */
-
-/* error-handling stuff */
-jmp_buf	errorhandler;
-#define FAIL(why)	regerror(why); longjmp(errorhandler, 1)
-
-
-
-
-
-/* This function builds a bitmap for a particular class */
-static char *makeclass(text, bmap)
-	REG char	*text;	/* start of the class */
-	REG char	*bmap;	/* the bitmap */
-{
-	REG int		i;
-	int		complement = 0;
-
-
-	/* zero the bitmap */
-	for (i = 0; bmap && i < 32; i++)
-	{
-		bmap[i] = 0;
-	}
-
-	/* see if we're going to complement this class */
-	if (*text == '^')
-	{
-		text++;
-		complement = 1;
-	}
-
-	/* add in the characters */
-	while (*text && *text != ']')
-	{
-		/* is this a span of characters? */
-		if (text[1] == '-' && text[2])
-		{
-			/* spans can't be backwards */
-			if (text[0] > text[2])
-			{
-				FAIL("Backwards span in []");
-			}
-
-			/* add each character in the span to the bitmap */
-			for (i = text[0]; bmap && i <= text[2]; i++)
-			{
-				bmap[i >> 3] |= (1 << (i & 7));
-			}
-
-			/* move past this span */
-			text += 3;
-		}
-		else
-		{
-			/* add this single character to the span */
-			i = *text++;
-			if (bmap)
-			{
-				bmap[i >> 3] |= (1 << (i & 7));
-			}
-		}
-	}
-
-	/* make sure the closing ] is missing */
-	if (*text++ != ']')
-	{
-		FAIL("] missing");
-	}
-
-	/* if we're supposed to complement this class, then do so */
-	if (complement && bmap)
-	{
-		for (i = 0; i < 32; i++)
-		{
-			bmap[i] = ~bmap[i];
-		}
-	}
-
-	return text;
-}
-
-
-
-
-/* This function gets the next character or meta character from a string.
- * The pointer is incremented by 1, or by 2 for \-quoted characters.  For [],
- * a bitmap is generated via makeclass() (if re is given), and the
- * character-class text is skipped.
- */
-static int gettoken(sptr, re)
-	char	**sptr;
-	regexp	*re;
-{
-	int	c;
-
-	c = **sptr;
-	++*sptr;
-	if (c == '\\')
-	{
-		c = **sptr;
-		++*sptr;
-		switch (c)
-		{
-		  case '<':
-			return M_BEGWORD;
-
-		  case '>':
-			return M_ENDWORD;
-
-		  case '(':
-			if (start_cnt >= NSUBEXP)
-			{
-				FAIL("Too many \\(s");
-			}
-			end_stk[end_sp++] = start_cnt;
-			return M_START(start_cnt++);
-
-		  case ')':
-			if (end_sp <= 0)
-			{
-				FAIL("Mismatched \\)");
-			}
-			return M_END(end_stk[--end_sp]);
-
-		  case '*':
-			return (*o_magic ? c : M_SPLAT);
-
-		  case '.':
-			return (*o_magic ? c : M_ANY);
-
-		  case '+':
-			return M_PLUS;
-
-		  case '?':
-			return M_QMARK;
-#ifndef CRUNCH
-		  case '{':
-			return M_RANGE;
-#endif
-		  default:
-			return c;
-		}
-	}
-	else if (*o_magic)
-	{
-		switch (c)
-		{
-		  case '^':
-			if (*sptr == retext + 1)
-			{
-				return M_BEGLINE;
-			}
-			return c;
-
-		  case '$':
-			if (!**sptr)
-			{
-				return M_ENDLINE;
-			}
-			return c;
-
-		  case '.':
-			return M_ANY;
-
-		  case '*':
-			return M_SPLAT;
-
-		  case '[':
-			/* make sure we don't have too many classes */
-			if (class_cnt >= 10)
-			{
-				FAIL("Too many []s");
-			}
-
-			/* process the character list for this class */
-			if (re)
-			{
-				/* generate the bitmap for this class */
-				*sptr = makeclass(*sptr, re->program + 1 + 32 * class_cnt);
-			}
-			else
-			{
-				/* skip to end of the class */
-				*sptr = makeclass(*sptr, (char *)0);
-			}
-			return M_CLASS(class_cnt++);
-
-		  default:
-			return c;
-		}
-	}
-	else	/* unquoted nomagic */
-	{
-		switch (c)
-		{
-		  case '^':
-			if (*sptr == retext + 1)
-			{
-				return M_BEGLINE;
-			}
-			return c;
-
-		  case '$':
-			if (!**sptr)
-			{
-				return M_ENDLINE;
-			}
-			return c;
-
-		  default:
-			return c;
-		}
-	}
-	/*NOTREACHED*/
-}
-
-
-
-
-/* This function calculates the number of bytes that will be needed for a
- * compiled RE.  Its argument is the uncompiled version.  It is not clever
- * about catching syntax errors; that is done in a later pass.
- */
-static unsigned calcsize(text)
-	char		*text;
-{
-	unsigned	size;
-	int		token;
-
-	retext = text;
-	class_cnt = 0;
-	start_cnt = 1;
-	end_sp = 0;
-	size = 5;
-	while ((token = gettoken(&text, (regexp *)0)) != 0)
-	{
-		if (IS_CLASS(token))
-		{
-			size += 34;
-		}
-#ifndef CRUNCH
-		else if (token == M_RANGE)
-		{
-			size += 4;
-			while ((token = gettoken(&text, (regexp *)0)) != 0
-			    && token != '}')
-			{
-			}
-			if (!token)
-			{
-				return size;
-			}
-		}
-#endif
-		else if (IS_META(token))
-		{
-			size += 2;
-		}
-		else
-		{
-			size++;
-		}
-	}
-
-	return size;
-}
-
-
-
-/* This function compiles a regexp. */
-regexp *regcomp(exp)
-	char		*exp;
-{
-	int		needfirst;
-	unsigned	size;
-	int		token;
-	int		peek;
-	char		*build;
-	regexp		*re;
-#ifndef CRUNCH
-	int		from;
-	int		to;
-	int		digit;
-#endif
-
-
-	/* prepare for error handling */
-	re = (regexp *)0;
-	if (setjmp(errorhandler))
-	{
-		if (re)
-		{
-			free(re);
-		}
-		return (regexp *)0;
-	}
-
-	/* if an empty regexp string was given, use the previous one */
-	if (*exp == 0)
-	{
-		if (!previous)
-		{
-			FAIL("No previous RE");
-		}
-		exp = previous;
-	}
-	else /* non-empty regexp given, so remember it */
-	{
-		if (previous)
-			free(previous);
-		previous = (char *)malloc((unsigned)(strlen(exp) + 1));
-		if (previous)
-			strcpy(previous, exp);
-	}
-
-	/* allocate memory */
-	class_cnt = 0;
-	start_cnt = 1;
-	end_sp = 0;
-	retext = exp;
-	size = calcsize(exp) + sizeof(regexp) + 10; /* !!! 10 bytes for slop */
-#ifdef lint
-	re = ((regexp *)0) + size;
-#else
-	re = (regexp *)malloc((unsigned)size);
-#endif
-	if (!re)
-	{
-		FAIL("Not enough memory for this RE");
-	}
-
-	/* compile it */
-	build = &re->program[1 + 32 * class_cnt];
-	re->program[0] = class_cnt;
-	for (token = 0; token < NSUBEXP; token++)
-	{
-		re->startp[token] = re->endp[token] = (char *)0;
-	}
-	re->first = 0;
-	re->bol = 0;
-	re->minlen = 0;
-	needfirst = 1;
-	class_cnt = 0;
-	start_cnt = 1;
-	end_sp = 0;
-	retext = exp;
-	for (token = M_START(0), peek = gettoken(&exp, re);
-	     token;
-	     token = peek, peek = gettoken(&exp, re))
-	{
-		/* special processing for the closure operator */
-		if (IS_CLOSURE(peek))
-		{
-			/* detect misuse of closure operator */
-			if (IS_START(token))
-			{
-				FAIL("Closure operator follows nothing");
-			}
-			else if (IS_META(token) && token != M_ANY && !IS_CLASS(token))
-			{
-				FAIL("Closure operators can only follow a normal character or . or []");
-			}
-
-#ifndef CRUNCH
-			/* if \{ \} then read the range */
-			if (peek == M_RANGE)
-			{
-				from = 0;
-				for (digit = gettoken(&exp, re);
-				     !IS_META(digit) && isdigit(digit);
-				     digit = gettoken(&exp, re))
-				{
-					from = from * 10 + digit - '0';
-				}
-				if (digit == '}')
-				{
-					to = from;
-				}
-				else if (digit == ',')
-				{
-					to = 0;
-					for (digit = gettoken(&exp, re);
-					     !IS_META(digit) && isdigit(digit);
-					     digit = gettoken(&exp, re))
-					{
-						to = to * 10 + digit - '0';
-					}
-					if (to == 0)
-					{
-						to = 255;
-					}
-				}
-				if (digit != '}')
-				{
-					FAIL("Bad characters after \\{");
-				}
-				else if (to < from || to == 0 || from >= 255)
-				{
-					FAIL("Invalid range for \\{ \\}");
-				}
-				re->minlen += from;
-			}
-			else
-#endif
-			if (peek != M_SPLAT)
-			{
-				re->minlen++;
-			}
-
-			/* it is okay -- make it prefix instead of postfix */
-			ADD_META(build, peek);
-#ifndef CRUNCH
-			if (peek == M_RANGE)
-			{
-				*build++ = from;
-				*build++ = (to < 255 ? to : 255);
-			}
-#endif
-			
-
-			/* take care of "needfirst" - is this the first char? */
-			if (needfirst && peek == M_PLUS && !IS_META(token))
-			{
-				re->first = token;
-			}
-			needfirst = 0;
-
-			/* we used "peek" -- need to refill it */
-			peek = gettoken(&exp, re);
-			if (IS_CLOSURE(peek))
-			{
-				FAIL("* or \\+ or \\? doubled up");
-			}
-		}
-		else if (!IS_META(token))
-		{
-			/* normal char is NOT argument of closure */
-			if (needfirst)
-			{
-				re->first = token;
-				needfirst = 0;
-			}
-			re->minlen++;
-		}
-		else if (token == M_ANY || IS_CLASS(token))
-		{
-			/* . or [] is NOT argument of closure */
-			needfirst = 0;
-			re->minlen++;
-		}
-
-		/* the "token" character is not closure -- process it normally */
-		if (token == M_BEGLINE)
-		{
-			/* set the BOL flag instead of storing M_BEGLINE */
-			re->bol = 1;
-		}
-		else if (IS_META(token))
-		{
-			ADD_META(build, token);
-		}
-		else
-		{
-			*build++ = token;
-		}
-	}
-
-	/* end it with a \) which MUST MATCH the opening \( */
-	ADD_META(build, M_END(0));
-	if (end_sp > 0)
-	{
-		FAIL("Not enough \\)s");
-	}
-
-	return re;
-}
-
-
-
-/*---------------------------------------------------------------------------*/
-
-
-/* This function checks for a match between a character and a token which is
- * known to represent a single character.  It returns 0 if they match, or
- * 1 if they don't.
- */
-int match1(re, ch, token)
-	regexp		*re;
-	REG char	ch;
-	REG int		token;
-{
-	if (!ch)
-	{
-		/* the end of a line can't match any RE of width 1 */
-		return 1;
-	}
-	if (token == M_ANY)
-	{
-		return 0;
-	}
-	else if (IS_CLASS(token))
-	{
-		if (re->program[1 + 32 * (token - M_CLASS(0)) + (ch >> 3)] & (1 << (ch & 7)))
-			return 0;
-	}
-	else if (ch == token || *o_ignorecase && tolower(ch) == tolower(token))
-	{
-		return 0;
-	}
-	return 1;
-}
-
-
-
-/* This function checks characters up to and including the next closure, at
- * which point it does a recursive call to check the rest of it.  This function
- * returns 0 if everything matches, or 1 if something doesn't match.
- */
-int match(re, str, prog, here)
-	regexp		*re;	/* the regular expression */
-	char		*str;	/* the string */
-	REG char	*prog;	/* a portion of re->program, an compiled RE */
-	REG char	*here;	/* a portion of str, the string to compare it to */
-{
-	REG int		token;	/* the roken pointed to by prog */
-	REG int		nmatched;/* counter, used during closure matching */ 
-	REG int		closure;/* the token denoting the type of closure */
-	int		from;	/* minimum number of matches in closure */
-	int		to;	/* maximum number of matches in closure */
-
-	for (token = GET_META(prog); !IS_CLOSURE(token); prog++, token = GET_META(prog))
-	{
-		switch (token)
-		{
-		/*case M_BEGLINE: can't happen; re->bol is used instead */
-		  case M_ENDLINE:
-			if (*here)
-				return 1;
-			break;
-
-		  case M_BEGWORD:
-			if (here != str &&
-			   (here[-1] == '_' || isalnum(here[-1])))
-				return 1;
-			break;
-
-		  case M_ENDWORD:
-			if (here[0] == '_' || isalnum(here[0]))
-				return 1;
-			break;
-
-		  case M_START(0):
-		  case M_START(1):
-		  case M_START(2):
-		  case M_START(3):
-		  case M_START(4):
-		  case M_START(5):
-		  case M_START(6):
-		  case M_START(7):
-		  case M_START(8):
-		  case M_START(9):
-			re->startp[token - M_START(0)] = (char *)here;
-			break;
-
-		  case M_END(0):
-		  case M_END(1):
-		  case M_END(2):
-		  case M_END(3):
-		  case M_END(4):
-		  case M_END(5):
-		  case M_END(6):
-		  case M_END(7):
-		  case M_END(8):
-		  case M_END(9):
-			re->endp[token - M_END(0)] = (char *)here;
-			if (token == M_END(0))
-			{
-				return 0;
-			}
-			break;
-
-		  default: /* literal, M_CLASS(n), or M_ANY */
-			if (match1(re, *here, token) != 0)
-				return 1;
-			here++;
-		}
-	}
-
-	/* C L O S U R E */
-
-	/* step 1: see what we have to match against, and move "prog" to point
-	 * to the remainder of the compiled RE.
-	 */
-	closure = token;
-	prog++;
-	switch (closure)
-	{
-	  case M_SPLAT:
-		from = 0;
-		to = strlen(str);	/* infinity */
-		break;
-
-	  case M_PLUS:
-		from = 1;
-		to = strlen(str);	/* infinity */
-		break;
-
-	  case M_QMARK:
-		from = 0;
-		to = 1;
-		break;
-
-#ifndef CRUNCH
-	  case M_RANGE:
-		from = UCHAR(*prog++);
-		to = UCHAR(*prog++);
-		if (to == 255)
-		{
-			to = strlen(str); /* infinity */
-		}
-		break;
-#endif
-	}
-	token = GET_META(prog);
-	prog++;
-
-	/* step 2: see how many times we can match that token against the string */
-	for (nmatched = 0;
-	     nmatched < to && *here && match1(re, *here, token) == 0;
-	     nmatched++, here++)
-	{
-	}
-
-	/* step 3: try to match the remainder, and back off if it doesn't */
-	while (nmatched >= from && match(re, str, prog, here) != 0)
-	{
-		nmatched--;
-		here--;
-	}
-
-	/* so how did it work out? */
-	if (nmatched >= from)
-		return 0;
-	return 1;
-}
-
-
-
-/* This function searches through a string for text that matches an RE. */
-int regexec(re, str, bol)
-	regexp	*re;	/* the compiled regexp to search for */
-	char	*str;	/* the string to search through */
-	int	bol;	/* boolean: does str start at the beginning of a line? */
-{
-	char	*prog;	/* the entry point of re->program */
-	int	len;	/* length of the string */
-	REG char	*here;
-
-	/* if must start at the beginning of a line, and this isn't, then fail */
-	if (re->bol && !bol)
-	{
-		return 0;
-	}
-
-	len = strlen(str);
-	prog = re->program + 1 + 32 * re->program[0];
-
-	/* search for the RE in the string */
-	if (re->bol)
-	{
-		/* must occur at BOL */
-		if ((re->first
-			&& match1(re, *(char *)str, re->first))/* wrong first letter? */
-		 || len < re->minlen			/* not long enough? */
-		 || match(re, (char *)str, prog, str))	/* doesn't match? */
-			return 0;			/* THEN FAIL! */
-	}
-#ifndef CRUNCH
-	else if (!*o_ignorecase)
-	{
-		/* can occur anywhere in the line, noignorecase */
-		for (here = (char *)str;
-		     (re->first && re->first != *here)
-			|| match(re, (char *)str, prog, here);
-		     here++, len--)
-		{
-			if (len < re->minlen)
-				return 0;
-		}
-	}
-#endif
-	else
-	{
-		/* can occur anywhere in the line, ignorecase */
-		for (here = (char *)str;
-		     (re->first && match1(re, *here, (int)re->first))
-			|| match(re, (char *)str, prog, here);
-		     here++, len--)
-		{
-			if (len < re->minlen)
-				return 0;
-		}
-	}
-
-	/* if we didn't fail, then we must have succeeded */
-	return 1;
-}
-
-/*============================================================================*/
-#else /* NO_MAGIC */
-
-regexp *regcomp(exp)
-	char	*exp;
-{
-	char	*src;
-	char	*dest;
-	regexp	*re;
-	int	i;
-
-	/* allocate a big enough regexp structure */
-#ifdef lint
-	re = (regexp *)0;
-#else
-	re = (regexp *)malloc((unsigned)(strlen(exp) + 1 + sizeof(struct regexp)));
-#endif
-	if (!re)
-	{
-		regerror("Could not malloc a regexp structure");
-		return (regexp *)0;
-	}
-
-	/* initialize all fields of the structure */
-	for (i = 0; i < NSUBEXP; i++)
-	{
-		re->startp[i] = re->endp[i] = (char *)0;
-	}
-	re->minlen = 0;
-	re->first = 0;
-	re->bol = 0;
-
-	/* copy the string into it, translating ^ and $ as needed */
-	for (src = exp, dest = re->program + 1; *src; src++)
-	{
-		switch (*src)
-		{
-		  case '^':
-			if (src == exp)
-			{
-				re->bol += 1;
-			}
-			else
-			{
-				*dest++ = '^';
-				re->minlen++;
-			}
-			break;
-
-		  case '$':
-			if (!src[1])
-			{
-				re->bol += 2;
-			}
-			else
-			{
-				*dest++ = '$';
-				re->minlen++;
-			}
-			break;
-
-		  case '\\':
-			if (src[1])
-			{
-				*dest++ = *++src;
-				re->minlen++;
-			}
-			else
-			{
-				regerror("extra \\ at end of regular expression");
-			}
-			break;
-
-		  default:
-			*dest++ = *src;
-			re->minlen++;
-		}
-	}
-	*dest = '\0';
-
-	return re;
-}
-
-
-/* This "helper" function checks for a match at a given location.  It returns
- * 1 if it matches, 0 if it doesn't match here but might match later on in the
- * string, or -1 if it could not possibly match
- */
-static int reghelp(prog, string, bolflag)
-	struct regexp	*prog;
-	char		*string;
-	int		bolflag;
-{
-	char		*scan;
-	char		*str;
-
-	/* if ^, then require bolflag */
-	if ((prog->bol & 1) && !bolflag)
-	{
-		return -1;
-	}
-
-	/* if it matches, then it will start here */
-	prog->startp[0] = string;
-
-	/* compare, possibly ignoring case */
-	if (*o_ignorecase)
-	{
-		for (scan = &prog->program[1]; *scan; scan++, string++)
-			if (tolower(*scan) != tolower(*string))
-				return *string ? 0 : -1;
-	}
-	else
-	{
-		for (scan = &prog->program[1]; *scan; scan++, string++)
-			if (*scan != *string)
-				return *string ? 0 : -1;
-	}
-
-	/* if $, then require string to end here, too */
-	if ((prog->bol & 2) && *string)
-	{
-		return 0;
-	}
-
-	/* if we get to here, it matches */
-	prog->endp[0] = string;
-	return 1;
-}
-
-
-
-int regexec(prog, string, bolflag)
-	struct regexp	*prog;
-	char		*string;
-	int		bolflag;
-{
-	int		rc;
-
-	/* keep trying to match it */
-	for (rc = reghelp(prog, string, bolflag); rc == 0; rc = reghelp(prog, string, 0))
-	{
-		string++;
-	}
-
-	/* did we match? */
-	return rc == 1;
-}
-#endif
Index: trunk/minix/commands/elvis/regexp.h
===================================================================
--- trunk/minix/commands/elvis/regexp.h	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-/*
- * Definitions etc. for regexp(3) routines.
- *
- * Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
- * not the System V one.
- */
-#define NSUBEXP  10
-
-typedef struct regexp {
-	char	*startp[NSUBEXP];
-	char	*endp[NSUBEXP];
-	int	minlen;		/* length of shortest possible match */
-	char	first;		/* first character, if known; else \0 */
-	char	bol;		/* boolean: must start at beginning of line? */
-	char	program[1];	/* Unwarranted chumminess with compiler. */
-} regexp;
-
-extern regexp *regcomp();
-extern int regexec();
-extern void regsub();
-extern void regerror();
Index: trunk/minix/commands/elvis/regsub.c
===================================================================
--- trunk/minix/commands/elvis/regsub.c	(revision 9)
+++ 	(revision )
@@ -1,243 +1,0 @@
-/* regsub.c */
-
-/* This file contains the regsub() function, which performs substitutions
- * after a regexp match has been found.
- */
-
-#include "config.h"
-#include "ctype.h"
-#include "vi.h"
-#include "regexp.h"
-
-
-/* perform substitutions after a regexp match */
-void regsub(re, src, dst)
-	regexp		*re;	/* the regexp with pointers into matched text */
-	REG char	*src;	/* the replacement string */
-	REG char	*dst;	/* where to put the result of the subst */
-{
-	REG char	*cpy;	/* pointer to start of text to copy */
-	REG char	*end;	/* pointer to end of text to copy */
-	REG char	c;
-	char		*start;
-#ifndef CRUNCH
-	int		mod = 0;/* used to track \U, \L, \u, \l, and \E */
-	int		len;	/* used to calculate length of subst string */
-	static char	*prev;	/* a copy of the text from the previous subst */
-
-	/* replace \~ (or maybe ~) by previous substitution text */
-
-	/* step 1: calculate the length of the new substitution text */
-	for (len = strlen(src), c = '\0', cpy = src; *cpy; cpy++)
-	{
-# ifdef NO_MAGIC
-		if (c == '\\' && *cpy == '~')
-# else
-		if (c == (*o_magic ? '\0' : '\\') && *cpy == '~')
-# endif
-		{
-			if (!prev)
-			{
-				regerror("No prev text to substitute for ~");
-				return;
-			}
-			len += strlen(prev) - 1;
-# ifndef NO_MAGIC
-			if (!*o_magic)
-# endif
-				len -= 1; /* because we lose the \ too */
-		}
-
-		/* watch backslash quoting */
-		if (c != '\\' && *cpy == '\\')
-			c = '\\';
-		else
-			c = '\0';
-	}
-
-	/* allocate memory for the ~ed version of src */
-	start = cpy = (char *)malloc((unsigned)(len + 1));
-	if (!cpy)
-	{
-		regerror("Not enough memory for ~ expansion");
-		return;
-	}
-
-	/* copy src into start, replacing the ~s by the previous text */
-	while (*src)
-	{
-# ifndef NO_MAGIC
-		if (*o_magic && *src == '~')
-		{
-			strcpy(cpy, prev);
-			cpy += strlen(prev);
-			src++;
-		}
-		else if (!*o_magic && *src == '\\' && *(src + 1) == '~')
-# else /* NO_MAGIC */
-		if (*src == '\\' && *(src + 1) == '~')
-# endif /* NO_MAGIC */
-		{
-			strcpy(cpy, prev);
-			cpy += strlen(prev);
-			src += 2;
-		}
-		else
-		{
-			*cpy++ = *src++;
-		}
-	}
-	*cpy = '\0';
-#ifdef DEBUG
-	if ((int)(cpy - start) != len)
-	{
-		msg("Bug in regsub.c! Predicted length = %d, Actual length = %d", len, (int)(cpy - start));
-	}
-#endif
-
-	/* remember this as the "previous" for next time */
-	if (prev)
-		free(prev);
-	prev = src = start;
-
-#endif /* undef CRUNCH */
-
-	start = src;
-	while ((c = *src++) != '\0')
-	{
-#ifndef NO_MAGIC
-		/* recognize any meta characters */
-		if (c == '&' && *o_magic)
-		{
-			cpy = re->startp[0];
-			end = re->endp[0];
-		}
-		else
-#endif /* not NO_MAGIC */
-		if (c == '\\')
-		{
-			c = *src++;
-			switch (c)
-			{
-#ifndef NO_MAGIC
-			  case '0':
-			  case '1':
-			  case '2':
-			  case '3':
-			  case '4':
-			  case '5':
-			  case '6':
-			  case '7':
-			  case '8':
-			  case '9':
-				/* \0 thru \9 mean "copy subexpression" */
-				c -= '0';
-				cpy = re->startp[c];
-				end = re->endp[c];
-				break;
-# ifndef CRUNCH
-			  case 'U':
-			  case 'u':
-			  case 'L':
-			  case 'l':
-				/* \U and \L mean "convert to upper/lowercase" */
-				mod = c;
-				continue;
-
-			  case 'E':
-			  case 'e':
-				/* \E ends the \U or \L */
-				mod = 0;
-				continue;
-# endif /* not CRUNCH */
-			  case '&':
-				/* "\&" means "original text" */
-				if (*o_magic)
-				{
-					*dst++ = c;
-					continue;
-				}
-				cpy = re->startp[0];
-				end = re->endp[0];
-				break;
-
-#else /* NO_MAGIC */
-			  case '&':
-				/* "\&" means "original text" */
-				cpy = re->startp[0];
-				end = re->endp[0];
-				break;
-#endif /* NO_MAGIC */
-			  default:
-				/* ordinary char preceded by backslash */
-				*dst++ = c;
-				continue;
-			}
-		}
-#ifndef CRUNCH
-# if OSK
-		else if (c == '\l')
-# else
-		else if (c == '\r')
-# endif
-		{
-			/* transliterate ^M into newline */
-			*dst++ = '\n';
-			continue;
-		}
-#endif /* !CRUNCH */
-		else
-		{
-			/* ordinary character, so just copy it */
-			*dst++ = c;
-			continue;
-		}
-
-		/* Note: to reach this point in the code, we must have evaded
-		 * all "continue" statements.  To do that, we must have hit
-		 * a metacharacter that involves copying.
-		 */
-
-		/* if there is nothing to copy, loop */
-		if (!cpy)
-			continue;
-
-		/* copy over a portion of the original */
-		while (cpy < end)
-		{
-#ifndef NO_MAGIC
-# ifndef CRUNCH
-			switch (mod)
-			{
-			  case 'U':
-			  case 'u':
-				/* convert to uppercase */
-				*dst++ = toupper(*cpy++);
-				break;
-
-			  case 'L':
-			  case 'l':
-				/* convert to lowercase */
-				*dst++ = tolower(*cpy++);
-				break;
-
-			  default:
-				/* copy without any conversion */
-				*dst++ = *cpy++;
-			}
-
-			/* \u and \l end automatically after the first char */
-			if (mod && (mod == 'u' || mod == 'l'))
-			{
-				mod = 0;
-			}
-# else /* CRUNCH */
-			*dst++ = *cpy++;
-# endif /* CRUNCH */
-#else /* NO_MAGIC */
-			*dst++ = *cpy++;
-#endif /* NO_MAGIC */
-		}
-	}
-	*dst = '\0';
-}
Index: trunk/minix/commands/elvis/system.c
===================================================================
--- trunk/minix/commands/elvis/system.c	(revision 9)
+++ 	(revision )
@@ -1,423 +1,0 @@
-/* system.c  -- UNIX version */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains a new version of the system() function and related stuff.
- *
- * Entry points are:
- *	system(cmd)		- run a single shell command
- *	wildcard(names)		- expand wildcard characters in filanames
- *	filter(m,n,cmd,back)	- run text lines through a filter program
- *
- * This is probably the single least portable file in the program.  The code
- * shown here should work correctly if it links at all; it will work on UNIX
- * and any O.S./Compiler combination which adheres to UNIX forking conventions.
- */
-
-#include "config.h"
-#include "vi.h"
-extern char	**environ;
-
-#if ANY_UNIX
-
-/* This is a new version of the system() function.  The only difference
- * between this one and the library one is: this one uses the o_shell option.
- */
-int system(cmd)
-	char	*cmd;	/* a command to run */
-{
-	int	pid;	/* process ID of child */
-	int	died;
-	int	status;	/* exit status of the command */
-
-
-	signal(SIGINT, SIG_IGN);
-	pid = fork();
-	switch (pid)
-	{
-	  case -1:						/* error */
-		msg("fork() failed");
-		status = -1;
-		break;
-
-	  case 0:						/* child */
-		/* for the child, close all files except stdin/out/err */
-		for (status = 3; status < 60 && (close(status), errno != EINVAL); status++)
-		{
-		}
-
-		signal(SIGINT, SIG_DFL);
-		if (cmd == o_shell)
-		{
-			execle(o_shell, o_shell, (char *)0, environ);
-		}
-		else
-		{
-			execle(o_shell, o_shell, "-c", cmd, (char *)0, environ);
-		}
-		msg("execle(\"%s\", ...) failed", o_shell);
-		exit(1); /* if we get here, the exec failed */
-
-	  default:						/* parent */
-		do
-		{
-			died = wait(&status);
-		} while (died >= 0 && died != pid);
-		if (died < 0)
-		{
-			status = -1;
-		}
-#if __GNUC__ || _ANSI
-		signal(SIGINT, (void (*)()) trapint);
-#else
-		signal(SIGINT, trapint);
-#endif
-	}
-
-	return status;
-}
-
-/* This private function opens a pipe from a filter.  It is similar to the
- * system() function above, and to popen(cmd, "r").
- */
-int rpipe(cmd, in)
-	char	*cmd;	/* the filter command to use */
-	int	in;	/* the fd to use for stdin */
-{
-	int	r0w1[2];/* the pipe fd's */
-
-	/* make the pipe */
-	if (pipe(r0w1) < 0)
-	{
-		return -1;	/* pipe failed */
-	}
-
-	/* The parent process (elvis) ignores signals while the filter runs.
-	 * The child (the filter program) will reset this, so that it can
-	 * catch the signal.
-	 */
-	signal(SIGINT, SIG_IGN);
-
-	switch (fork())
-	{
-	  case -1:						/* error */
-		return -1;
-
-	  case 0:						/* child */
-		/* close the "read" end of the pipe */
-		close(r0w1[0]);
-
-		/* redirect stdout to go to the "write" end of the pipe */
-		close(1);
-		dup(r0w1[1]);
-		close(2);
-		dup(r0w1[1]);
-		close(r0w1[1]);
-
-		/* redirect stdin */
-		if (in != 0)
-		{
-			close(0);
-			dup(in);
-			close(in);
-		}
-
-		/* the filter should accept SIGINT signals */
-		signal(SIGINT, SIG_DFL);
-
-		/* exec the shell to run the command */
-		execle(o_shell, o_shell, "-c", cmd, (char *)0, environ);
-		exit(1); /* if we get here, exec failed */
-
-	  default:						/* parent */
-		/* close the "write" end of the pipe */	
-		close(r0w1[1]);
-
-		return r0w1[0];
-	}
-}
-
-#endif /* non-DOS */
-
-#if OSK
-
-/* This private function opens a pipe from a filter.  It is similar to the
- * system() function above, and to popen(cmd, "r").
- */
-int rpipe(cmd, in)
-	char	*cmd;	/* the filter command to use */
-	int	in;	/* the fd to use for stdin */
-{
-	return osk_popen(cmd, "r", in, 0);
-}	
-#endif
-
-#if ANY_UNIX || OSK
-
-/* This function closes the pipe opened by rpipe(), and returns 0 for success */
-int rpclose(fd)
-	int	fd;
-{
-	int	status;
-
-	close(fd);
-	wait(&status);
-#if __GNUC__ || _ANSI
-	signal(SIGINT, (void (*)()) trapint);
-#else
-	signal(SIGINT, trapint);
-#endif
-	return status;
-}
-
-#endif /* non-DOS */
-
-/* This function expands wildcards in a filename or filenames.  It does this
- * by running the "echo" command on the filenames via the shell; it is assumed
- * that the shell will expand the names for you.  If for any reason it can't
- * run echo, then it returns the names unmodified.
- */
-
-#if MSDOS || TOS
-#define	PROG	"wildcard "
-#define	PROGLEN	9
-#include <string.h>
-#else
-#define	PROG	"echo "
-#define	PROGLEN	5
-#endif
-
-#if !AMIGA
-char *wildcard(names)
-	char	*names;
-{
-
-# if VMS
-/* 
-   We could use expand() [vmswild.c], but what's the point on VMS? 
-   Anyway, echo is the wrong thing to do, it takes too long to build
-   a subprocess on VMS and any "echo" program would have to be supplied
-   by elvis.  More importantly, many VMS utilities expand names 
-   themselves (the shell doesn't do any expansion) so the concept is
-   non-native.  jdc
-*/
-	return names;
-# else
-
-	int	i, j, fd;
-	REG char *s, *d;
-
-
-	/* build the echo command */
-	if (names != tmpblk.c)
-	{
-		/* the names aren't in tmpblk.c, so we can do it the easy way */
-		strcpy(tmpblk.c, PROG);
-		strcat(tmpblk.c, names);
-	}
-	else
-	{
-		/* the names are already in tmpblk.c, so shift them to make
-		 * room for the word "echo "
-		 */
-		for (s = names + strlen(names) + 1, d = s + PROGLEN; s > names; )
-		{
-			*--d = *--s;
-		}
-		strncpy(names, PROG, PROGLEN);
-	}
-
-	/* run the command & read the resulting names */
-	fd = rpipe(tmpblk.c, 0);
-	if (fd < 0) return names;
-	i = 0;
-	do
-	{
-		j = tread(fd, tmpblk.c + i, BLKSIZE - i);
-		i += j;
-	} while (j > 0);
-
-	/* successful? */
-	if (rpclose(fd) == 0 && j == 0 && i < BLKSIZE && i > 0)
-	{
-		tmpblk.c[i-1] = '\0'; /* "i-1" so we clip off the newline */
-		return tmpblk.c;
-	}
-	else
-	{
-		return names;
-	}
-# endif
-}
-#endif
-
-/* This function runs a range of lines through a filter program, and replaces
- * the original text with the filtered version.  As a special case, if "to"
- * is MARK_UNSET, then it runs the filter program with stdin coming from
- * /dev/null, and inserts any output lines.
- */
-int filter(from, to, cmd, back)
-	MARK	from, to;	/* the range of lines to filter */
-	char	*cmd;		/* the filter command */
-	int	back;		/* boolean: will we read lines back? */
-{
-	int	scratch;	/* fd of the scratch file */
-	int	fd;		/* fd of the pipe from the filter */
-	char	scrout[50];	/* name of the scratch out file */
-	MARK	new;		/* place where new text should go */
-	long	sent, rcvd;	/* number of lines sent/received */
-	int	i, j;
-
-	/* write the lines (if specified) to a temp file */
-	if (to)
-	{
-		/* we have lines */
-#if MSDOS || TOS
-		strcpy(scrout, o_directory);
-		if ((i=strlen(scrout)) && !strchr("\\/:", scrout[i-1]))
-			scrout[i++]=SLASH;
-		strcpy(scrout+i, SCRATCHOUT+3);
-#else
-		sprintf(scrout, SCRATCHOUT, o_directory);
-#endif
-		mktemp(scrout);
-		cmd_write(from, to, CMD_BANG, FALSE, scrout);
-		sent = markline(to) - markline(from) + 1L;
-
-		/* use those lines as stdin */
-		scratch = open(scrout, O_RDONLY);
-		if (scratch < 0)
-		{
-			unlink(scrout);
-			return -1;
-		}
-	}
-	else
-	{
-		scratch = 0;
-		sent = 0L;
-	}
-
-	/* start the filter program */
-#if VMS
-	/* 
-	   VMS doesn't know a thing about file descriptor 0.  The rpipe
-	   concept is non-portable.  Hence we need a file name argument.
-	*/
-	fd = rpipe(cmd, scratch, scrout);
-#else
-	fd = rpipe(cmd, scratch);
-#endif
-	if (fd < 0)
-	{
-		if (to)
-		{
-			close(scratch);
-			unlink(scrout);
-		}
-		return -1;
-	}
-
-	if (back)
-	{
-		ChangeText
-		{
-			/* adjust MARKs for whole lines, and set "new" */
-			from &= ~(BLKSIZE - 1);
-			if (to)
-			{
-				to &= ~(BLKSIZE - 1);
-				to += BLKSIZE;
-				new = to;
-			}
-			else
-			{
-				new = from + BLKSIZE;
-			}
-
-#if VMS
-/* Reading from a VMS mailbox (pipe) is record oriented... */
-# define tread vms_pread
-#endif
-
-			/* repeatedly read in new text and add it */
-			rcvd = 0L;
-			while ((i = tread(fd, tmpblk.c, BLKSIZE - 1)) > 0)
-			{
-				tmpblk.c[i] = '\0';
-				add(new, tmpblk.c);
-#if VMS
-				/* What!  An advantage to record oriented reads? */
-				new += (i - 1);
-				new = (new & ~(BLKSIZE - 1)) + BLKSIZE;
-				rcvd++;
-#else
-				for (i = 0; tmpblk.c[i]; i++)
-				{
-					if (tmpblk.c[i] == '\n')
-					{
-						new = (new & ~(BLKSIZE - 1)) + BLKSIZE;
-						rcvd++;
-					}
-					else
-					{
-						new++;
-					}
-				}
-#endif
-			}
-		}
-
-		/* delete old text, if any */
-		if (to)
-		{
-			cut(from, to);
-			delete(from, to);
-		}
-	}
-	else
-	{
-		/* read the command's output, and copy it to the screen */
-		while ((i = tread(fd, tmpblk.c, BLKSIZE - 1)) > 0)
-		{
-			for (j = 0; j < i; j++)
-			{
-				addch(tmpblk.c[j]);
-			}
-		}
-		rcvd = 0;
-	}
-
-	/* Reporting... */
-	if (sent >= *o_report || rcvd >= *o_report)
-	{
-		if (sent > 0L && rcvd > 0L)
-		{
-			msg("%ld lines out, %ld lines back", sent, rcvd);
-		}
-		else if (sent > 0)
-		{
-			msg("%ld lines written to filter", sent);
-		}
-		else
-		{
-			msg("%ld lines read from filter", rcvd);
-		}
-	}
-	rptlines = 0L;
-
-	/* cleanup */
-	rpclose(fd);
-	if (to)
-	{
-		close(scratch);
-		unlink(scrout);
-	}
-	return 0;
-}
Index: trunk/minix/commands/elvis/tinyprnt.c
===================================================================
--- trunk/minix/commands/elvis/tinyprnt.c	(revision 9)
+++ 	(revision )
@@ -1,230 +1,0 @@
-/* tinyprnt.c */
-
-#if OSK
-#define sprintf Sprintf
-#endif
-
-/* This is a limited version of sprintf().  It is useful for Minix-PC and
- * Coherent-286 because those systems are both limited to 64k+64k and the
- * standard sprintf() is just too damn big.
- *
- * It should also be useful for OS-9 because OS-9's sprintf() doesn't
- * understand the true meaning of asterisks in a format string.  This one
- * does.
- */
-
-/* Place-holders in format strings look like "%<pad><clip><type>".
- *
- * The <pad> adds space to the front (or, if negative, to the back) of the
- * output value, to pad it to a given width.  If <pad> is absent, then 0 is
- * assumed.  If <pad> is an asterisk, then the next argument is assumed to
- * be an (int) which used as the pad width.
- *
- * The <clip> string can be absent, in which case no clipping is done.
- * However, if it is present, then it should be either a "." followed by
- * a number, or a "." followed by an asterisk.  The asterisk means that the
- * next argument is an (int) which should be used as the pad width.  Clipping
- * only affects strings; for other data types it is ignored.
- *
- * The <type> is one of "s" for strings, "c" for characters (really ints that
- * are assumed to be legal char values), "d" for ints, "ld" for long ints, or
- * "%" to output a percent sign.
- */
-
-/* NOTE: Variable argument lists are handled by direct stack-twiddling. Sorry! */
-
-static void cvtnum(buf, num, base)
-	char		*buf;	/* where to store the number */
-	unsigned long	num;	/* the number to convert */
-	int		base;	/* either 8, 10, or 16 */
-{
-	static char	digits[] = "0123456789abcdef";
-	unsigned long	tmp;
-
-	/* if the number is 0, then just stuff a "0" into the buffer */
-	if (num == 0L)
-	{
-		buf[0] = '0';
-		buf[1] = '\0';
-		return;
-	}
-
-	/* use tmp to figure out how many digits we'll need */
-	for (tmp = num; tmp > 0; tmp /= base)
-	{
-		buf++;
-	}
-
-	/* mark the spot that will be the end of the string */
-	*buf = '\0';
-
-	/* generate all digits, as needed */
-	for (tmp = num; tmp > 0; tmp /= base)
-	{
-		*--buf = digits[tmp % base];
-	}
-}
-
-int sprintf(buf, fmt, argref)
-	char	*buf;	/* where to deposit the formatted output */
-	char	*fmt;	/* the format string */
-	int	argref;	/* the first argument is located at &argref */
-{
-	char	*argptr;/* pointer to next argument on the stack */
-	int	pad;	/* value of the pad string */
-	int	clip;	/* value of the clip string */
-	long	num;	/* a binary number being converted to ASCII digits */
-	long	digit;	/* used during conversion */
-	char	*src, *dst;
-
-	/* make argptr point to the first argument after the format string */
-	argptr = (char *)&argref;
-
-	/* loop through the whole format string */
-	while (*fmt)
-	{
-		/* if not part of a place-holder, then copy it literally */
-		if (*fmt != '%')
-		{
-			*buf++ = *fmt++;
-			continue;
-		}
-
-		/* found a place-holder!  Get <pad> value */
-		fmt++;
-		if ('*' == *fmt)
-		{
-			pad = *((int *)argptr)++;
-			fmt++;
-		}
-		else if (*fmt == '-' || (*fmt >= '0' && *fmt <= '9'))
-		{
-			pad = atol(fmt);
-			do
-			{
-				fmt++;
-			} while (*fmt >= '0' && *fmt <= '9');
-		}
-		else
-		{
-			pad = 0;
-		}
-
-		/* get a <clip> value */
-		if (*fmt == '.')
-		{
-			fmt++;
-			if ('*' == *fmt)
-			{
-				clip = *((int *)argptr)++;
-				fmt++;
-			}
-			else if (*fmt >= '0' && *fmt <= '9')
-			{
-				clip = atol(fmt);
-				do
-				{
-					fmt++;
-				} while (*fmt >= '0' && *fmt <= '9');
-			}
-		}
-		else
-		{
-			clip = 0;
-		}
-
-		/* handle <type>, possibly noticing <clip> */
-		switch (*fmt++)
-		{
-		  case 'c':
-			buf[0] = *((int *)argptr)++;
-			buf[1] = '\0';
-			break;
-
-		  case 's':
-			src = *((char **)argptr)++;
-			if (!src)
-			{
-				src = "(null)";
-			}
-			if (clip)
-			{
-				strncpy(buf, src, clip);
-				buf[clip] = '\0';
-			}
-			else
-			{
-				strcpy(buf, src);
-			}
-			break;
-
-		  case 'l':
-			fmt++; /* to skip the "d" in "%ld" */
-			num = *((long *)argptr)++;
-			dst = buf;
-			if (num < 0)
-			{
-				*dst++ = '-';
-				num = -num;
-			}
-			cvtnum(dst, num, 10);
-			break;
-
-		  case 'x':
-			num = *((int *)argptr)++;
-			cvtnum(buf, num, 16);
-			break;
-
-		  case 'd':
-			num = *((int *)argptr)++;
-			dst = buf;
-			if (num < 0)
-			{
-				*dst++ = '-';
-				num = -num;
-			}
-			cvtnum(dst, num, 10);
-			break;
-
-		  default:
-			buf[0] = fmt[-1];
-			buf[1] = '\0';
-		}
-
-		/* now fix the padding, if the value is too short */
-		clip = strlen(buf);
-		if (pad < 0)
-		{
-			/* add spaces after the value */
-			pad = -pad - clip;
-			for (buf += clip; pad > 0; pad--)
-			{
-				*buf++ = ' ';
-			}
-			*buf = '\0';
-		}
-		else
-		{
-			/* add spaces before the value */
-			pad -= clip;
-			if (pad > 0)
-			{
-				src = buf + clip;
-				dst = src + pad;
-				*dst = '\0';
-				while (src > buf)
-				{
-					*--dst = *--src;
-				}
-				while (dst > buf)
-				{
-					*--dst = ' ';
-				}
-			}
-			buf += strlen(buf);
-		}
-	}
-
-	/* mark the end of the output string */
-	*buf = '\0';
-}
Index: trunk/minix/commands/elvis/tinytcap.c
===================================================================
--- trunk/minix/commands/elvis/tinytcap.c	(revision 9)
+++ 	(revision )
@@ -1,388 +1,0 @@
-/* tinytcap.c */
-
-/* This file contains functions which simulate the termcap functions.
- *
- * It doesn't access a "termcap" file.  Instead, it uses an initialized array
- * of strings to store the entries.  Any string that doesn't start with a ':'
- * is taken to be the name of a type of terminal.  Any string that does start
- * with a ':' is interpretted as the list of fields describing all of the
- * terminal types that precede it.
- *
- * Note: since these are C strings, you can't use special sequences like
- * ^M or \E in the fields; your C compiler won't understand them.  Also,
- * at run time there is no way to tell the difference between ':' and '\072'
- * so I sure hope your terminal definition doesn't require a ':' character.
- *
- * getenv(TERM) on VMS checks the SET TERM device setting.  To implement
- * non-standard terminals set the logical ELVIS_TERM in VMS. (jdc)
- *
- * Other possible terminal types are...
- * 	TERM_WYSE925	- "wyse925", a Wyse 50 terminal emulating Televideo 925
- * ... or you could set $TERMCAP to the terminal's description string, which
- * $TERM set up to match it.
- *
- * Note that you can include several terminal types at the same time.  Elvis
- * chooses which entry to use at runtime, based primarily on the value of $TERM.
- */
-
-
-#include "config.h"
-extern char *getenv();
-
-/* decide which terminal descriptions should *always* be included. */
-#if MSDOS
-# define	TERM_NANSI
-# define	TERM_DOSANSI
-# if RAINBOW
-#  define	TERM_RAINBOW
-# endif
-#endif
-
-#if VMS
-# define	TERM_VT100
-# define	TERM_VT100W
-# define	TERM_VT52
-#endif
-
-#if AMIGA
-# define	TERM_AMIGA	/* Internal Amiga termcap entry */
-/* # define	TERM_VT52	/* The rest of these are here for those */
-# define	TERM_VT100	/* people who want to use elvis over an */
-/* # define	TERM_NANSI	/* AUX: port (serial.device). */
-/* # define	TERM_DOSANSI	/* Take out all but AMIGA to save memory. */
-/* # define	TERM_MINIX	/* Vanilla ANSI? */
-/* # define	TERM_925	/* Hang a terminal off your Amiga */
-#endif
-
-#if MINIX || UNIXV
-# define	TERM_MINIX
-#endif
-
-#if COHERENT
-# define	TERM_COHERENT
-#endif
-
-#if TOS
-# define	TERM_ATARI
-#endif
-
-static char *termcap[] =
-{
-#ifdef TERM_AMIGA
-"AA",
-"amiga",
-"Amiga ANSI",
-/* Amiga termcap modified from version 1.3 by Kent Polk */
-":co#80:li#24:am:bs:bw:xn:\
-:AL=\233%dL:DC=\233%dP:DL=\233%dM:DO=\233%dB:\
-:LE=\233%dD:RI=\233%dC:SF=\233%dS:SR=\233%dT:UP=\233%dA:IC=\233%d@:\
-:ae=\2330m:al=\233L:as=\2333m:bl=\007:bt=\233Z:cd=\233J:\
-:ce=\233K:cl=\013:cm=\233%i%d;%dH:dc=\233P:dl=\233M:do=\233B:\
-:kb=^H:ho=\233H:ic=\233@:is=\23320l:\
-:mb=\2337;2m:md=\2331m:me=\2330m:mh=\2332m:mk=\2338m:mr=\2337m:nd=\233C:\
-:rs=\033c:se=\2330m:sf=\233S:so=\2337m:sb=\233T:sr=\233T:ue=\23323m:\
-:up=\233A:us=\2334m:vb=\007:ve=\233\040p:vi=\2330\040p:\
-:k1=\2330~:k2=\2331~:k3=\2332~:k4=\2333~:k5=\2334~:\
-:k6=\2335~:k7=\2336~:k8=\2337~:k9=\2338~:k0=\2339~:\
-:s1=\23310~:s2=\23311~:s3=\23312~:s4=\23313~:s5=\23314~:\
-:s6=\23315~:s7=\23316~:s8=\23317~:s9=\23318~:s0=\23319~:\
-:kd=\233B:kl=\233D:kn#10:kr=\233C:ku=\233A:le=\233D:\
-:kP=\233T:kN=\233S:kh=\233\040A:kH=\233\040@:",
-#endif
-
-#ifdef TERM_NANSI
-"fansi",
-"nnansi",
-"nansi",
-"pcbios",
-":al=\033[L:dl=\033[M:am:bs:ce=\033[K:cl=\033[2J:\
-:cm=\033[%i%d;%dH:co#80:do=\033[B:\
-:k1=#;:k2=#<:k3=#=:k4=#>:k5=#?:k6=#@:k7=#A:k8=#B:k9=#C:k0=#D:\
-:s1=#T:s2=#U:s3=#V:s4=#W:s5=#X:s6=#Y:s7=#Z:s8=#[:s9=#\\:s0=#]:\
-:c1=#^:c2=#_:c3=#`:c4=#a:c5=#b:c6=#c:c7=#d:c8=#e:c9=#f:c0=#g:\
-:a1=#h:a2=#i:a3=#j:a4=#k:a5=#l:a6=#m:a7=#n:a8=#o:a9=#p:a0=#q:\
-:kd=#P:kh=#G:kH=#O:kI=#R:kl=#K:kN=#Q:kP=#I:kr=#M:ku=#H:\
-:li#25:md=\033[1m:me=\033[m:nd=\033[C:se=\033[m:so=\033[7m:\
-:ue=\033[m:up=\033[A:us=\033[4m:",
-#endif
-
-#ifdef TERM_DOSANSI
-#if !ANY_UNIX
-"ansi",
-#endif
-"dosansi",
-":am:bs:ce=\033[K:cl=\033[2J:\
-:cm=\033[%i%d;%dH:co#80:do=\033[B:\
-:k1=#;:k2=#<:k3=#=:k4=#>:k5=#?:k6=#@:k7=#A:k8=#B:k9=#C:k0=#D:\
-:s1=#T:s2=#U:s3=#V:s4=#W:s5=#X:s6=#Y:s7=#Z:s8=#[:s9=#\\:s0=#]:\
-:c1=#^:c2=#_:c3=#`:c4=#a:c5=#b:c6=#c:c7=#d:c8=#e:c9=#f:c0=#g:\
-:a1=#h:a2=#i:a3=#j:a4=#k:a5=#l:a6=#m:a7=#n:a8=#o:a9=#p:a0=#q:\
-:kd=#P:kh=#G:kH=#O:kI=#R:kl=#K:kN=#Q:kP=#I:kr=#M:ku=#H:\
-:li#25:md=\033[1m:me=\033[m:nd=\033[C:se=\033[m:so=\033[7m:\
-:ue=\033[m:up=\033[A:us=\033[4m:",
-#endif
-
-#ifdef TERM_RAINBOW
-"vt220",
-"rainbow",
-":al=\033[L:dl=\033[M:am:bs:ce=\033[K:cl=\033[2J:\
-:cm=\033[%i%d;%dH:co#80:do=\033[B:kd=\033[B:kl=\033[D:\
-:kr=\033[C:ku=\033[A:kP=\033[5~:kN=\033[6~:kI=\033[2~:\
-:li#24:md=\033[1m:me=\033[m:nd=\033[C:se=\033[m:so=\033[7m:\
-:ue=\033[m:up=\033[A:us=\033[4m:xn:",
-#endif
-
-#ifdef TERM_VT100
-"vt100-80",
-"vt200-80",
-"vt300-80",
-"vt101-80",
-"vt102-80",
-":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
-:co#80:dl=\033[M:do=\033[B:k0=\033[20~:k1=\033[1~:\
-:k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
-:k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
-:kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
-:kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:nd=\033[C:\
-:se=\033[m:so=\033[7m:ti=\033[1;24r\033[24;1H:\
-:ue=\033[m:up=\033[A:us=\033[4m:xn:",
-#endif
-
-#ifdef TERM_VT100W
-"vt100-w",
-"vt200-w",
-"vt300-w",
-"vt101-w",
-"vt102-w",
-"vt100-132",
-"vt200-132",
-"vt300-132",
-"vt101-132",
-"vt102-132",
-":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
-:co#132:dl=\033[M:do=\033[B:k0=\033[20~:k1=\033[1~:\
-:k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
-:k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
-:kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
-:kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:nd=\033[C:\
-:se=\033[m:so=\033[7m:ti=\033[1;24r\033[24;1H:\
-:ue=\033[m:up=\033[A:us=\033[4m:xn:",
-#endif
-
-#ifdef TERM_VT52
-"vt52",
-":do=\n:le=\b:up=\033A:nd=\033C:cm=\033Y%+ %+ :ti=\033e\033v:\
-:sr=\033I:cd=\033J:ce=\033K:cl=\033H\033J:co#80:li#24:\
-:ku=\033A:kd=\033B:kr=\033C:kl=\033D:kb=\b:pt:am:xn:bs:",
-#endif
-
-#ifdef TERM_MINIX
-"minix",
-"ansi",
-"AT386",
-":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
-:co#80:dl=\033[M:do=\033[B:k0=\033[20~:k1=\033[1~:\
-:k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
-:k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
-:kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
-:kr=\033[C:ku=\033[A:li#25:md=\033[1m:me=\033[m:nd=\033[C:\
-:se=\033[m:so=\033[7m:ue=\033[m:up=\033[A:us=\033[4m:",
-#endif /* MINIX */
-
-#ifdef TERM_COHERENT
-"coherent",
-"ansipc",
-":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
-:co#80:dl=\033[M:do=\033[B:k0=\033[0x:k1=\033[1x:k2=\033[2x:\
-:k3=\033[3x:k4=\033[4x:k5=\033[5x:k6=\033[6x:\
-:k7=\033[7x:k8=\033[8x:k9=\033[9x:kd=\033[B:kh=\033[H:\
-:kH=\033[24H:kI=\033[@:kl=\033[D:kN=\033[U:kP=\033[V:\
-:kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:\
-:nd=\033[C:se=\033[m:so=\033[7m:ue=\033[m:up=\033[A:\
-:us=\033[4m:",
-#endif /* COHERENT */
-
-#ifdef TERM_ATARI
-"atari-st",
-"vt52",
-":al=\033L:am:bs:ce=\033K:cl=\033E:cm=\033Y%i%+ %+ :\
-:co#80:dl=\033M:do=\033B:\
-:k1=#;:k2=#<:k3=#=:k4=#>:k5=#?:k6=#@:k7=#A:k8=#B:k9=#C:k0=#D:\
-:s1=#T:s2=#U:s3=#V:s4=#W:s5=#X:s6=#Y:s7=#Z:s8=#[:s9=#\\:s0=#]:\
-:c1=#^:c2=#_:c3=#`:c4=#a:c5=#b:c6=#c:c7=#d:c8=#e:c9=#f:c0=#g:\
-:a1=#h:a2=#i:a3=#j:a4=#k:a5=#l:a6=#m:a7=#n:a8=#o:a9=#p:a0=#q:\
-kd=#P:kh=#G:kI=#R:kl=#K:kr=#M:ku=#H:li#25:nd=\033C:se=\033q:\
-:so=\033p:te=:ti=\033e\033v:up=\033A:",
-#endif
-
-#ifdef TERM_925
-"wyse925",
-":xn@:\
-:hs:am:bs:co#80:li#24:cm=\033=%+ %+ :cl=\033*:cd=\033y:\
-:ce=\033t:is=\033l\033\":\
-:al=\033E:dl=\033R:im=:ei=:ic=\033Q:dc=\033W:\
-:ho=\036:nd=\014:bt=\033I:pt:so=\033G4:se=\033G0:sg#1:us=\033G8:ue=\033G0:ug#1:\
-:up=\013:do=\026:kb=\010:ku=\013:kd=\026:kl=\010:kr=\014:\
-:kh=\036:ma=\026\012\014 :\
-:k1=\001@\r:k2=\001A\r:k3=\001B\r:k4=\001C\r:k5=\001D\r:k6=\001E\r:k7=\001F\r:\
-:k8=\001G\r:k9=\001H\r:k0=\001I\r:ko=ic,dc,al,dl,cl,ce,cd,bt:\
-:ts=\033f:fs=\033g:ds=\033h:sr=\033j:",  /* was :xn: for tvi925 alone*/
-#endif
-
-(char *)0
-};
-
-
-static char *fields;
-
-
-/*ARGSUSED*/
-int tgetent(bp, name)
-	char	*bp;	/* buffer for storing the entry -- ignored */
-	char	*name;	/* name of the entry */
-{
-	int	i;
-
-	/* if TERMCAP is defined, and seems to match, then use it */
-	fields = getenv("TERMCAP");
-	if (fields)
-	{
-		for (i = 0; fields[i] && fields[i] != ':'; i++)
-		{
-			if (!strncmp(fields + i, name, strlen(name)))
-			{
-				return 1;
-			}
-		}
-	}
-
-	/* locate the entry in termcap[] */
-	for (i = 0; termcap[i] && strcmp(termcap[i], name); i++)
-	{
-	}
-	if (!termcap[i])
-	{
-		return 0;
-	}
-
-	/* search forward for fields */
-	while (termcap[i][0] != ':')
-	{
-		i++;
-	}
-	fields = termcap[i];
-	return 1;
-}
-
-
-static char *find(id, vtype)
-	char	*id;	/* name of a value to locate */
-	int	vtype;	/* '=' for strings, '#' for numbers, or 0 for bools */
-{
-	int	i;
-
-	/* search for a ':' followed by the two-letter id */
-	for (i = 0; fields[i]; i++)
-	{
-		if (fields[i] == ':'
-		 && fields[i + 1] == id[0]
-		 && fields[i + 2] == id[1])
-		{
-			/* if correct type, then return its value */
-			if (fields[i + 3] == vtype)
-				return &fields[i + 4];
-			else
-				return (char *)0;
-		}
-	}
-	return (char *)0;
-}
-
-int tgetnum(id)
-	char	*id;
-{
-	id = find(id, '#');
-	if (id)
-	{
-		return atoi(id);
-	}
-	return -1;
-}
-
-int tgetflag(id)
-	char	*id;
-{
-	if (find(id, ':'))
-	{
-		return 1;
-	}
-	return 0;
-}
-
-/*ARGSUSED*/
-char *tgetstr(id, bp)
-	char	*id;
-	char	**bp;	/* pointer to pointer to buffer - ignored */
-{
-	char	*cpy;
-
-	/* find the string */
-	id = find(id, '=');
-	if (!id)
-	{
-		return (char *)0;
-	}
-
-	/* copy it into the buffer, and terminate it with NUL */
-	for (cpy = *bp; *id != ':'; )
-	{
-		if (id[0] == '\\' && id[1] == 'E')
-			*cpy++ = '\033', id += 2;
-		else
-			*cpy++ = *id++;
-	}
-	*cpy++ = '\0';
-
-	/* update the bp pointer */
-	id = *bp;
-	*bp = cpy;
-
-	/* return a pointer to the copy of the string */
-	return id;
-}
-
-/*ARGSUSED*/
-char *tgoto(cm, destcol, destrow)
-	char	*cm;	/* cursor movement string -- ignored */
-	int	destcol;/* destination column, 0 - 79 */
-	int	destrow;/* destination row, 0 - 24 */
-{
-	static char buf[30];
-
-#ifdef CRUNCH
-# if TOS
-	sprintf(buf, "\033Y%c%c", ' ' + destrow, ' ' + destcol);
-# else
-	sprintf(buf, "\033[%d;%dH", destrow + 1, destcol + 1);
-# endif
-#else
-	if (cm[1] == 'Y' || cm[1] == '=')
-		sprintf(buf, "\033%c%c%c", cm[1], ' ' + destrow, ' ' + destcol);
-	else
-		sprintf(buf, "\033[%d;%dH", destrow + 1, destcol + 1);
-#endif
-	return buf;
-}
-
-/*ARGSUSED*/
-void tputs(cp, affcnt, outfn)
-	char	*cp;		/* the string to output */
-	int	affcnt;		/* number of affected lines -- ignored */
-	int	(*outfn)();	/* the output function */
-{
-	while (*cp)
-	{
-		(*outfn)(*cp);
-		cp++;
-	}
-}
Index: trunk/minix/commands/elvis/tio.c
===================================================================
--- trunk/minix/commands/elvis/tio.c	(revision 9)
+++ 	(revision )
@@ -1,1026 +1,0 @@
-/* tio.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains terminal I/O functions */
-
-#include "config.h"
-#include "vi.h"
-#include "ctype.h"
-
-
-/* This function reads in a line from the terminal. */
-int vgets(prompt, buf, bsize)
-	char	prompt;	/* the prompt character, or '\0' for none */
-	char	*buf;	/* buffer into which the string is read */
-	int	bsize;	/* size of the buffer */
-{
-	int	len;	/* how much we've read so far */
-	int	ch;	/* a character from the user */
-	int	quoted;	/* is the next char quoted? */
-	int	tab;	/* column position of cursor */
-	char	widths[132];	/* widths of characters */
-	int	word;	/* index of first letter of word */
-#ifndef NO_DIGRAPH
-	int	erased;	/* 0, or first char of a digraph */
-#endif
-
-	/* show the prompt */
-	move(LINES - 1, 0);
-	tab = 0;
-	if (prompt)
-	{
-		addch(prompt);
-		tab = 1;
-	}
-	clrtoeol();
-	refresh();
-
-	/* read in the line */
-#ifndef NO_DIGRAPH
-	erased =
-#endif
-	quoted = len = 0;
-	for (;;)
-	{
-#ifndef NO_ABBR
-		if (quoted || mode == MODE_EX)
-		{
-			ch = getkey(0);
-		}
-		else
-		{
-			/* maybe expand an abbreviation while getting key */
-			for (word = len; --word >= 0 && isalnum(buf[word]); )
-			{
-			}
-			word++;
-			ch = getabkey(WHEN_EX, &buf[word], len - word);
-		}
-#else
-		ch = getkey(0);
-#endif
-#ifndef NO_EXTENSIONS
-		if (ch == ctrl('O'))
-		{
-			ch = getkey(quoted ? 0 : WHEN_EX);
-		}
-#endif
-
-		/* some special conversions */
-		if (ch == ctrl('D') && len == 0)
-			ch = ctrl('[');
-#ifndef NO_DIGRAPH
-		if (*o_digraph && erased != 0 && ch != '\b')
-		{
-			ch = digraph(erased, ch);
-			erased = 0;
-		}
-#endif
-
-		/* inhibit detection of special chars (except ^J) after a ^V */
-		if (quoted && ch != '\n')
-		{
-			ch |= 256;
-		}
-
-		/* process the character */
-		switch(ch)
-		{
-		  case ctrl('V'):
-			qaddch('^');
-			qaddch('\b');
-			quoted = TRUE;
-			break;
-
-		  case ctrl('['):
-			return -1;
-
-		  case '\n':
-#if OSK
-		  case '\l':
-#else
-		  case '\r':
-#endif
-			clrtoeol();
-			goto BreakBreak;
-
-		  case '\b':
-			if (len > 0)
-			{
-				len--;
-#ifndef NO_DIGRAPH
-				erased = buf[len];
-#endif
-				for (ch = widths[len]; ch > 0; ch--)
-					addch('\b');
-				if (mode == MODE_EX)
-				{
-					clrtoeol();
-				}
-				tab -= widths[len];
-			}
-			else
-			{
-				return -1;
-			}
-			break;
-
-		  default:
-			/* strip off quotation bit */
-			if (ch & 256)
-			{
-				ch &= ~256;
-				qaddch(' ');
-				qaddch('\b');
-			}
-
-			/* add & echo the char */
-			if (len < bsize - 1)
-			{
-				if (ch == '\t' && !quoted)
-				{
-					widths[len] = *o_tabstop - (tab % *o_tabstop);
-					addstr("        " + 8 - widths[len]);
-					tab += widths[len];
-				}
-				else if (ch > 0 && ch < ' ') /* > 0 by GB */
-				{
-					addch('^');
-					addch(ch + '@');
-					widths[len] = 2;
-					tab += 2;
-				}
-				else if (ch == '\177')
-				{
-					addch('^');
-					addch('?');
-					widths[len] = 2;
-					tab += 2;
-				}
-				else
-				{
-					addch(ch);
-					widths[len] = 1;
-					tab++;
-				}
-				buf[len++] = ch;
-			}
-			else
-			{
-				beep();
-			}
-			quoted = FALSE;
-		}
-	}
-BreakBreak:
-	refresh();
-	buf[len] = '\0';
-	return len;
-}
-
-
-static int	manymsgs; /* This variable keeps msgs from overwriting each other */
-static char	pmsg[80]; /* previous message (waiting to be displayed) */
-
-
-static int showmsg()
-{
-	/* if there is no message to show, then don't */
-	if (!manymsgs)
-		return FALSE;
-
-	/* display the message */
-	move(LINES - 1, 0);
-	if (*pmsg)
-	{
-		standout();
-		qaddch(' ');
-		qaddstr(pmsg);
-		qaddch(' ');
-		standend();
-	}
-	clrtoeol();
-
-	manymsgs = FALSE;
-	return TRUE;
-}
-
-
-void endmsgs()
-{
-	if (manymsgs)
-	{
-		showmsg();
-		addch('\n');
-	}
-}
-
-/* Write a message in an appropriate way.  This should really be a varargs
- * function, but there is no such thing as vwprintw.  Hack!!!
- *
- * In MODE_EX or MODE_COLON, the message is written immediately, with a
- * newline at the end.
- *
- * In MODE_VI, the message is stored in a character buffer.  It is not
- * displayed until getkey() is called.  msg() will call getkey() itself,
- * if necessary, to prevent messages from being lost.
- *
- * msg("")		- clears the message line
- * msg("%s %d", ...)	- does a printf onto the message line
- */
-/*VARARGS1*/
-void msg(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
-	char	*fmt;
-	long	arg1, arg2, arg3, arg4, arg5, arg6, arg7;
-{
-	if (mode != MODE_VI)
-	{
-		sprintf(pmsg, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
-		qaddstr(pmsg);
-		addch('\n');
-		exrefresh();
-	}
-	else
-	{
-		/* wait for keypress between consecutive msgs */
-		if (manymsgs)
-		{
-			getkey(WHEN_MSG);
-		}
-
-		/* real message */
-		sprintf(pmsg, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
-		if (*fmt)
-		{
-			manymsgs = TRUE;
-		}
-	}
-}
-
-
-/* This function calls refresh() if the option exrefresh is set */
-void exrefresh()
-{
-	char	*scan;
-
-	/* If this ex command wrote ANYTHING set exwrote so vi's  :  command
-	 * can tell that it must wait for a user keystroke before redrawing.
-	 */
-	for (scan=kbuf; scan<stdscr; scan++)
-		if (*scan == '\n')
-			exwrote = TRUE;
-
-	/* now we do the refresh thing */
-	if (*o_exrefresh)
-	{
-		refresh();
-	}
-	else
-	{
-		wqrefresh();
-	}
-	if (mode != MODE_VI)
-	{
-		manymsgs = FALSE;
-	}
-}
-
-
-/* This structure is used to store maps and abbreviations.  The distinction
- * between them is that maps are stored in the list referenced by the "maps"
- * pointer, while abbreviations are referenced by the "abbrs" pointer.
- */
-typedef struct _map
-{
-	struct _map	*next;	/* another abbreviation */
-	short		len;	/* length of the "rawin" characters */
-	short		flags;	/* various flags */
-	char		*label;	/* label of the map/abbr, or NULL */
-	char		*rawin;	/* the "rawin" characters */
-	char		*cooked;/* the "cooked" characters */
-} MAP;
-
-static char	keybuf[KEYBUFSIZE];
-static int	cend;	/* end of input characters */
-static int	user;	/* from user through end are chars typed by user */
-static int	next;	/* index of the next character to be returned */
-static MAP	*match;	/* the matching map, found by countmatch() */
-static MAP	*maps;	/* the map table */
-#ifndef NO_ABBR
-static MAP	*abbrs;	/* the abbreviation table */
-#endif
-
-
-
-/* ring the terminal's bell */
-void beep()
-{
-	/* do a visible/audible bell */
-	if (*o_flash)
-	{
-		do_VB();
-		refresh();
-	}
-	else if (*o_errorbells)
-	{
-		ttywrite("\007", 1);
-	}
-
-	/* discard any buffered input, and abort macros */
-	next = user = cend;
-}
-
-
-
-/* This function replaces a "rawin" character sequence with the "cooked" version,
- * by modifying the internal type-ahead buffer.
- */
-void execmap(rawlen, cookedstr, visual)
-	int	rawlen;		/* length of rawin text -- string to delete */
-	char	*cookedstr;	/* the cooked text -- string to insert */
-	int	visual;		/* boolean -- chars to be executed in visual mode? */
-{
-	int	cookedlen;
-	char	*src, *dst;
-	int	i;
-
-	/* find the length of the cooked string */
-	cookedlen = strlen(cookedstr);
-#ifndef NO_EXTENSIONS
-	if (visual)
-	{
-		cookedlen *= 2;
-	}
-#endif
-
-	/* if too big to fit in type-ahead buffer, then don't do it */
-	if (cookedlen + (cend - next) - rawlen > KEYBUFSIZE)
-	{
-		return;
-	}
-
-	/* shift to make room for cookedstr at the front of keybuf */
-	src = &keybuf[next + rawlen];
-	dst = &keybuf[cookedlen];
-	i = cend - (next + rawlen);
-	if (src >= dst)
-	{
-		while (i-- > 0)
-		{
-			*dst++ = *src++;
-		}
-	}
-	else
-	{
-		src += i;
-		dst += i;
-		while (i-- > 0)
-		{
-			*--dst = *--src;
-		}
-	}
-
-	/* insert cookedstr, and adjust offsets */
-	cend += cookedlen - rawlen - next;
-	user += cookedlen - rawlen - next;
-	next = 0;
-	for (dst = keybuf, src = cookedstr; *src; )
-	{
-#ifndef NO_EXTENSIONS
-		if (visual)
-		{
-			*dst++ = ctrl('O');
-			cookedlen--;
-		}
-#endif
-		*dst++ = *src++;
-	}
-
-#ifdef DEBUG2
-	{
-#include <stdio.h>
-		FILE	*debout;
-		int		i;
-
-		debout = fopen("debug.out", "a");
-		fprintf(debout, "After execmap(%d, \"%s\", %d)...\n", rawlen, cookedstr, visual);
-		for (i = 0; i < cend; i++)
-		{
-			if (i == next) fprintf(debout, "(next)");
-			if (i == user) fprintf(debout, "(user)");
-			if (UCHAR(keybuf[i]) < ' ')
-				fprintf(debout, "^%c", keybuf[i] ^ '@');
-			else
-				fprintf(debout, "%c", keybuf[i]);
-		}
-		fprintf(debout, "(end)\n");
-		fclose(debout);
-	}
-#endif
-}
-
-/* This function calls ttyread().  If necessary, it will also redraw the screen,
- * change the cursor shape, display the mode, and update the ruler.  If the
- * number of characters read is 0, and we didn't time-out, then it exits because
- * we've apparently reached the end of an EX script.
- */
-static int fillkeybuf(when, timeout)
-	int	when;	/* mixture of WHEN_XXX flags */
-	int	timeout;/* timeout in 1/10 second increments, or 0 */
-{
-	int	nkeys;
-#ifndef NO_SHOWMODE
-	static int	oldwhen;	/* "when" from last time */
-	static int	oldleft;
-	static long	oldtop;
-	static long	oldnlines;
-	char		*str;
-#endif
-#ifndef NO_CURSORSHAPE
-	static int	oldcurs;
-#endif
-
-#ifdef DEBUG
-	watch();
-#endif
-
-
-#ifndef NO_CURSORSHAPE
-	/* make sure the cursor is the right shape */
-	if (has_CQ)
-	{
-		if (when != oldcurs)
-		{
-			switch (when)
-			{
-			  case WHEN_EX:		do_CX();	break;
-			  case WHEN_VICMD:	do_CV();	break;
-			  case WHEN_VIINP:	do_CI();	break;
-			  case WHEN_VIREP:	do_CR();	break;
-			}
-			oldcurs = when;
-		}
-	}
-#endif
-
-#ifndef NO_SHOWMODE
-	/* if "showmode" then say which mode we're in */
-	if (*o_smd && (when & WHENMASK))
-	{
-		/* redraw the screen before we check to see whether the
-		 * "showmode" message needs to be redrawn.
-		 */
-		redraw(cursor, !(when & WHEN_VICMD));
-
-		/* now the "topline" test should be valid */
-		if (when != oldwhen || topline != oldtop || leftcol != oldleft || nlines != oldnlines)
-		{
-			oldwhen = when;
-			oldtop = topline;
-			oldleft = leftcol;
-			oldnlines = nlines;
-
-			if (when & WHEN_VICMD)	    str = "Command";
-			else if (when & WHEN_VIINP) str = " Input ";
-			else if (when & WHEN_VIREP) str = "Replace";
-			else if (when & WHEN_REP1)  str = " Rep 1 ";
-			else if (when & WHEN_CUT)   str = "BufName";
-			else if (when & WHEN_MARK)  str = "Mark AZ";
-			else if (when & WHEN_CHAR)  str = "Dest Ch";
-			else			    str = (char *)0;
-
-			if (str)
-			{
-				move(LINES - 1, COLS - 10);
-				standout();
-				qaddstr(str);
-				standend();
-			}
-		}
-	}
-#endif
-
-#ifndef NO_EXTENSIONS
-	/* maybe display the ruler */
-	if (*o_ruler && (when & (WHEN_VICMD|WHEN_VIINP|WHEN_VIREP)))
-	{
-		char	buf[20];
-
-		redraw(cursor, !(when & WHEN_VICMD));
-		pfetch(markline(cursor));
-		sprintf(buf, "%7ld,%-4d", markline(cursor), 1 + idx2col(cursor, ptext, when & (WHEN_VIINP|WHEN_VIREP)));
-		move(LINES - 1, COLS - 22);
-		addstr(buf);
-	}
-#endif
-
-	/* redraw, so the cursor is in the right place */
-	if (when & WHENMASK)
-	{
-		redraw(cursor, !(when & (WHENMASK & ~(WHEN_VIREP|WHEN_VIINP))));
-	}
-
-	/* Okay, now we can finally read the rawin keystrokes */
-	refresh();
-	nkeys = ttyread(keybuf + cend, sizeof keybuf - cend, timeout);
-
-	/* if nkeys == 0 then we've reached EOF of an ex script. */
-	if (nkeys == 0 && timeout == 0)
-	{
-		tmpabort(TRUE);
-		move(LINES - 1, 0);
-		clrtoeol();
-		refresh();
-		endwin();
-		exit(1);
-	}
-
-	cend += nkeys;
-	user += nkeys;
-	return nkeys;
-}
-
-
-/* This function counts the number of maps that could match the characters
- * between &keybuf[next] and &keybuf[cend], including incomplete matches.
- * The longest comlete match is remembered via the "match" variable.
- */
-static int countmatch(when)
-	int	when;	/* mixture of WHEN_XXX flags */
-{
-	MAP	*map;
-	int	count;
-
-	/* clear the "match" variable */
-	match = (MAP *)0;
-
-	/* check every map */
-	for (count = 0, map = maps; map; map = map->next)
-	{
-		/* can't match if wrong mode */
-		if ((map->flags & when) == 0)
-		{
-			continue;
-		}
-
-		/* would this be a complete match? */
-		if (map->len <= cend - next)
-		{
-			/* Yes, it would be.  Now does it really match? */
-			if (!strncmp(map->rawin, &keybuf[next], map->len))
-			{
-				count++;
-
-				/* if this is the longest complete match,
-				 * then remember it.
-				 */
-				if (!match || match->len < map->len)
-				{
-					match = map;
-				}
-			}
-		}
-		else
-		{
-			/* No, it wouldn't.  But check for partial match */
-			if (!strncmp(map->rawin, &keybuf[next], cend - next))
-			{
-				count++;
-			}
-		}
-	}
-	return count;
-}
-
-
-#ifndef NO_ABBR
-/* This function checks to see whether a word is an abbreviation.  If it is,
- * then an appropriate number of backspoace characters is inserted into the
- * type-ahead buffer, followed by the expanded form of the abbreviation.
- */
-static void expandabbr(word, wlen)
-	char	*word;
-	int	wlen;
-{
-	MAP	*abbr;
-
-	/* if the next character wouldn't end the word, then don't expand */
-	if (isalnum(keybuf[next]) || keybuf[next] == ctrl('V'))
-	{
-		return;
-	}
-
-	/* find the abbreviation, if any */
-	for (abbr = abbrs;
-	     abbr && (abbr->len != wlen || strncmp(abbr->rawin, word, wlen));
-	     abbr = abbr->next)
-	{
-	}
-
-	/* If an abbreviation was found, then expand it by inserting the long
-	 * version into the type-ahead buffer, and then inserting (in front of
-	 * the long version) enough backspaces to erase to the short version.
-	 */
-	if (abbr)
-	{
-		execmap(0, abbr->cooked, FALSE);
-		while (wlen > 15)
-		{
-			execmap(0, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", FALSE);
-			wlen -= 15;
-		}
-		if (wlen > 0)
-		{
-			execmap(0, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" + 15 - wlen, FALSE);
-		}
-	}
-}
-#endif
-
-
-/* This function calls getabkey() without attempting to expand abbreviations */
-int getkey(when)
-	int	when;	/* mixture of WHEN_XXX flags */
-{
-	return getabkey(when, "", 0);
-}
-
-
-/* This is it.  This function returns keystrokes one-at-a-time, after mapping
- * and abbreviations have been taken into account.
- */
-int getabkey(when, word, wlen)
-	int	when;	/* mixture of WHEN_XXX flags */
-	char	*word;	/* a word that may need to be expanded as an abbr */
-	int	wlen;	/* length of "word" -- since "word" might not have \0 */
-{
-	int	matches;
-
-	/* if this key is needed for delay between multiple error messages,
-	 * then reset the manymsgs flag and abort any mapped key sequence.
-	 */
-	if (showmsg())
-	{
-		if (when == WHEN_MSG)
-		{
-#ifndef CRUNCH
-			if (!*o_more)
-			{
-				refresh();
-				return ' ';
-			}
-#endif
-			qaddstr("[More...]");
-			refresh();
-			execmap(user, "", FALSE);
-		}
-	}
-
-#ifdef DEBUG
-	/* periodically check for screwed up internal tables */
-	watch();
-#endif
-
-	/* if buffer empty, read some characters without timeout */
-	if (next >= cend)
-	{
-		next = user = cend = 0;
-		fillkeybuf(when, 0);
-	}
-
-	/* try to map the key, unless already mapped and not ":set noremap" */
-	if (next >= user || *o_remap)
-	{
-		do
-		{
-			do
-			{
-				matches = countmatch(when);
-			} while (matches > 1 && fillkeybuf(when, *o_keytime) > 0);
-			if (matches == 1)
-			{
-				execmap(match->len, match->cooked,
-					(match->flags & WHEN_INMV) != 0 
-					 && (when & (WHEN_VIINP|WHEN_VIREP)) != 0);
-			}
-		} while (*o_remap && matches == 1);
-	}
-
-#ifndef NO_ABBR
-	/* try to expand an abbreviation, except in visual command mode */
-	if (wlen > 0 && (mode & (WHEN_EX|WHEN_VIINP|WHEN_VIREP)) != 0)
-	{
-		expandabbr(word, wlen);
-	}
-#endif
-
-	/* ERASEKEY should always be mapped to '\b'. */
-	if (keybuf[next] == ERASEKEY)
-	{
-		keybuf[next] = '\b';
-	}
-
-	/* return the next key */
-	return keybuf[next++];
-}
-
-/* This function maps or unmaps a key */
-void mapkey(rawin, cooked, when, name)
-	char	*rawin;	/* the input key sequence, before mapping */
-	char	*cooked;/* after mapping -- or NULL to remove map */
-	short	when;	/* bitmap of when mapping should happen */
-	char	*name;	/* name of the key, NULL for no name, "abbr" for abbr */
-{
-	MAP	**head;	/* head of list of maps or abbreviations */
-	MAP	*scan;	/* used for scanning through the list */
-	MAP	*prev;	/* used during deletions */
-
-	/* Is this a map or an abbreviation?  Choose the right list. */
-#ifndef NO_ABBR
-	head = ((!name || strcmp(name, "abbr")) ? &maps : &abbrs);
-#else
-	head = &maps;
-#endif
-
-	/* try to find the map in the list */
-	for (scan = *head, prev = (MAP *)0;
-	     scan && (strcmp(rawin, scan->rawin) ||
-		!(scan->flags & when & (WHEN_EX|WHEN_VICMD|WHEN_VIINP|WHEN_VIREP)));
-	     prev = scan, scan = scan->next)
-	{
-	}
-
-	/* trying to map? (not unmap) */
-	if (cooked && *cooked)
-	{
-		/* if map starts with "visual ", then mark it as a visual map */
-		if (head == &maps && !strncmp(cooked, "visual ", 7))
-		{
-			cooked += 7;
-			when |= WHEN_INMV;
-		}
-
-		/* "visual" maps always work in input mode */
-		if (when & WHEN_INMV)
-		{
-			when |= WHEN_VIINP|WHEN_VIREP|WHEN_POPUP;
-		}
-
-		/* if not already in the list, then allocate a new structure */
-		if (!scan)
-		{
-			scan = (MAP *)malloc(sizeof(MAP));
-			scan->len = strlen(rawin);
-			scan->rawin = malloc(scan->len + 1);
-			strcpy(scan->rawin, rawin);
-			scan->flags = when;
-			scan->label = name;
-			if (*head)
-			{
-				prev->next = scan;
-			}
-			else
-			{
-				*head = scan;
-			}
-			scan->next = (MAP *)0;
-		}
-		else /* recycle old structure */
-		{
-			free(scan->cooked);
-		}
-		scan->cooked = malloc(strlen(cooked) + 1);
-		strcpy(scan->cooked, cooked);
-	}
-	else /* unmapping */
-	{
-		/* if nothing to unmap, then exit silently */
-		if (!scan)
-		{
-			return;
-		}
-
-		/* unlink the structure from the list */
-		if (prev)
-		{
-			prev->next = scan->next;
-		}
-		else
-		{
-			*head = scan->next;
-		}
-
-		/* free it, and the strings that it refers to */
-		free(scan->rawin);
-		free(scan->cooked);
-		free(scan);
-	}
-}
-
-
-/* This function returns a printable version of a string.  It uses tmpblk.c */
-char *printable(str)
-	char	*str;	/* the string to convert */
-{
-	char	*build;	/* used for building the string */
-
-	for (build = tmpblk.c; *str; str++)
-	{
-#if AMIGA
-		if (*str == '\233')
-		{
-			*build++ = '<';
-			*build++ = 'C';
-			*build++ = 'S';
-			*build++ = 'I';
-			*build++ = '>';
-		} else 
-#endif
-		if (UCHAR(*str) < ' ' || *str == '\177')
-		{
-			*build++ = '^';
-			*build++ = *str ^ '@';
-		}
-		else
-		{
-			*build++ = *str;
-		}
-	}
-	*build = '\0';
-	return tmpblk.c;
-}
-
-/* This function displays the contents of either the map table or the
- * abbreviation table.  User commands call this function as follows:
- *	:map	dumpkey(WHEN_VICMD, FALSE);
- *	:map!	dumpkey(WHEN_VIREP|WHEN_VIINP, FALSE);
- *	:abbr	dumpkey(WHEN_VIINP|WHEN_VIREP, TRUE);
- *	:abbr!	dumpkey(WHEN_EX|WHEN_VIINP|WHEN_VIREP, TRUE);
- */
-void dumpkey(when, abbr)
-	int	when;	/* WHEN_XXXX of mappings to be dumped */
-	int	abbr;	/* boolean: dump abbreviations instead of maps? */
-{
-	MAP	*scan;
-	char	*str;
-	int	len;
-
-#ifndef NO_ABBR
-	for (scan = (abbr ? abbrs : maps); scan; scan = scan->next)
-#else
-	for (scan = maps; scan; scan = scan->next)
-#endif
-	{
-		/* skip entries that don't match "when" */
-		if ((scan->flags & when) == 0)
-		{
-			continue;
-		}
-
-		/* dump the key label, if any */
-		if (!abbr)
-		{
-			len = 8;
-			if (scan->label)
-			{
-				qaddstr(scan->label);
-				len -= strlen(scan->label);
-			}
-			do
-			{
-				qaddch(' ');
-			} while (len-- > 0);
-		}
-
-		/* dump the rawin version */
-		str = printable(scan->rawin);
-		qaddstr(str);
-		len = strlen(str);
-		do
-		{
-			qaddch(' ');
-		} while (len++ < 8);
-			
-		/* dump the mapped version */
-#ifndef NO_EXTENSIONS
-		if ((scan->flags & WHEN_INMV) && (when & (WHEN_VIINP|WHEN_VIREP)))
-		{
-			qaddstr("visual ");
-		}
-#endif
-		str = printable(scan->cooked);
-		qaddstr(str);
-		addch('\n');
-		exrefresh();
-	}
-}
-
-#ifndef NO_MKEXRC
-
-static safequote(str)
-	char	*str;
-{
-	char	*build;
-
-	build = tmpblk.c + strlen(tmpblk.c);
-	while (*str)
-	{
-		if (*str <= ' ' && *str >= 1 || *str == '|')
-		{
-			*build++ = ctrl('V');
-		}
-		*build++ = *str++;
-	}
-	*build = '\0';
-}
-
-/* This function saves the contents of either the map table or the
- * abbreviation table into a file.  Both the "bang" and "no bang" versions
- * are saved.
- *	:map	dumpkey(WHEN_VICMD, FALSE);
- *	:map!	dumpkey(WHEN_VIREP|WHEN_VIINP, FALSE);
- *	:abbr	dumpkey(WHEN_VIINP|WHEN_VIREP, TRUE);
- *	:abbr!	dumpkey(WHEN_EX|WHEN_VIINP|WHEN_VIREP, TRUE);
- */
-savemaps(fd, abbr)
-	int	fd;	/* file descriptor of an open file to write to */
-	int	abbr;	/* boolean: do abbr table? (else do map table) */
-{
-	MAP	*scan;
-	char	*str;
-	int	bang;
-	int	when;
-	int	len;
-
-# ifndef NO_ABBR
-	for (scan = (abbr ? abbrs : maps); scan; scan = scan->next)
-# else
-	for (scan = maps; scan; scan = scan->next)
-# endif
-	{
-		/* skip maps that have labels, except for function keys */
-		if (scan->label && *scan->label != '#')
-		{
-			continue;
-		}
-
-		for (bang = 0; bang < 2; bang++)
-		{
-			/* decide which "when" flags we want */
-# ifndef NO_ABBR
-			if (abbr)
-				when = (bang ? WHEN_EX|WHEN_VIINP|WHEN_VIREP : WHEN_VIINP|WHEN_VIREP);
-			else
-# endif
-				when = (bang ? WHEN_VIREP|WHEN_VIINP : WHEN_VICMD);
-
-			/* skip entries that don't match "when" */
-			if ((scan->flags & when) == 0)
-			{
-				continue;
-			}
-
-			/* write a "map" or "abbr" command name */
-# ifndef NO_ABBR
-			if (abbr)
-				strcpy(tmpblk.c, "abbr");
-			else
-# endif
-				strcpy(tmpblk.c, "map");
-
-			/* maybe write a bang.  Definitely write a space */
-			if (bang)
-				strcat(tmpblk.c, "! ");
-			else
-				strcat(tmpblk.c, " ");
-
-			/* write the rawin version */
-# ifndef NO_FKEY
-			if (scan->label)
-				strcat(tmpblk.c, scan->label);
-			else
-# endif
-				safequote(scan->rawin);
-			strcat(tmpblk.c, " ");
-				
-			/* dump the mapped version */
-# ifndef NO_EXTENSIONS
-			if ((scan->flags & WHEN_INMV) && (when & (WHEN_VIINP|WHEN_VIREP)))
-			{
-				strcat(tmpblk.c, "visual ");
-			}
-# endif
-			safequote(scan->cooked);
-			strcat(tmpblk.c, "\n");
-			twrite(fd, tmpblk.c, strlen(tmpblk.c));
-		}
-	}
-}
-#endif
Index: trunk/minix/commands/elvis/tmp.c
===================================================================
--- trunk/minix/commands/elvis/tmp.c	(revision 9)
+++ 	(revision )
@@ -1,759 +1,0 @@
-/* tmp.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains functions which create & readback a TMPFILE */
-
-
-#include "config.h"
-#include "vi.h"
-#if TOS
-# include <stat.h>
-#else
-# if OSK
-#  include "osk.h"
-# else
-#  if AMIGA
-#   include "amistat.h"
-#  else
-#   include <sys/stat.h>
-#  endif
-# endif
-#endif
-#if TURBOC
-# include <process.h>
-#endif
-
-#ifndef NO_MODELINES
-static void do_modelines(l, stop)
-	long	l;	/* line number to start at */
-	long	stop;	/* line number to stop at */
-{
-	char	*str;	/* used to scan through the line */
-	char	*start;	/* points to the start of the line */
-	char	buf[80];
-
-	/* if modelines are disabled, then do nothing */
-	if (!*o_modelines)
-	{
-		return;
-	}
-
-	/* for each line... */
-	for (; l <= stop; l++)
-	{
-		/* for each position in the line.. */
-		for (str = fetchline(l); *str; str++)
-		{
-			/* if it is the start of a modeline command... */
-			if ((str[0] == 'e' && str[1] == 'x'
-			  || str[0] == 'v' && str[1] == 'i')
-			  && str[2] == ':')
-			{
-				start = str += 3;
-
-				/* find the end */
-				for (str = start + strlen(start); *--str != ':'; )
-				{
-				}
-
-				/* if it is a well-formed modeline, execute it */
-				if (str > start && str - start < sizeof buf)
-				{
-					strncpy(buf, start, (int)(str - start));
-					exstring(buf, str - start, '\\');
-					break;
-				}
-			}
-		}
-	}
-}
-#endif
-
-
-/* The FAIL() macro prints an error message and then exits. */
-#define FAIL(why,arg)	mode = MODE_EX; msg(why, arg); endwin(); exit(9)
-
-/* This is the name of the temp file */
-static char	tmpname[80];
-
-/* This function creates the temp file and copies the original file into it.
- * Returns if successful, or stops execution if it fails.
- */
-int tmpstart(filename)
-	char		*filename; /* name of the original file */
-{
-	int		origfd;	/* fd used for reading the original file */
-	struct stat	statb;	/* stat buffer, used to examine inode */
-	REG BLK		*this;	/* pointer to the current block buffer */
-	REG BLK		*next;	/* pointer to the next block buffer */
-	int		inbuf;	/* number of characters in a buffer */
-	int		nread;	/* number of bytes read */
-	REG int		j, k;
-	int		i;
-	long		nbytes;
-
-	/* switching to a different file certainly counts as a change */
-	changes++;
-	redraw(MARK_UNSET, FALSE);
-
-	/* open the original file for reading */
-	*origname = '\0';
-	if (filename && *filename)
-	{
-		strcpy(origname, filename);
-		origfd = open(origname, O_RDONLY);
-		if (origfd < 0 && errno != ENOENT)
-		{
-			msg("Can't open \"%s\"", origname);
-			return tmpstart("");
-		}
-		if (origfd >= 0)
-		{
-			if (stat(origname, &statb) < 0)
-			{
-				FAIL("Can't stat \"%s\"", origname);
-			}
-#if TOS
-			if (origfd >= 0 && (statb.st_mode & S_IJDIR))
-#else
-# if OSK
-			if (origfd >= 0 && (statb.st_mode & S_IFDIR))
-# else
-			if (origfd >= 0 && (statb.st_mode & S_IFMT) != S_IFREG)
-# endif
-#endif
-			{
-				msg("\"%s\" is not a regular file", origname);
-				return tmpstart("");
-			}
-		}
-		else
-		{
-			stat(".", &statb);
-		}
-		if (origfd >= 0)
-		{
-			origtime = statb.st_mtime;
-#if OSK
-			if (*o_readonly || !(statb.st_mode &
-				  ((getuid() >> 16) == 0 ? S_IOWRITE | S_IWRITE :
-				  ((statb.st_gid != (getuid() >> 16) ? S_IOWRITE : S_IWRITE)))))
-#endif
-#if AMIGA || MSDOS || (TOS && defined(__GNUC__))
-			if (*o_readonly || !(statb.st_mode & S_IWRITE))
-#endif
-#if TOS && !defined(__GNUC__)
-			if (*o_readonly || (statb.st_mode & S_IJRON))
-#endif
-#if ANY_UNIX
-			if (*o_readonly || !(statb.st_mode &
-				  ((geteuid() == 0) ? 0222 :
-				  ((statb.st_uid != geteuid() ? 0022 : 0200)))))
-#endif
-#if VMS
-			if (*o_readonly)
-#endif
-			{
-				setflag(file, READONLY);
-			}
-		}
-		else
-		{
-			origtime = 0L;
-		}
-	}
-	else
-	{
-		setflag(file, NOFILE);
-		origfd = -1;
-		origtime = 0L;
-		stat(".", &statb);
-	}
-
-	/* make a name for the tmp file */
-	tmpnum++;
-#if MSDOS || TOS
-	/* MS-Dos doesn't allow multiple slashes, but supports drives
-	 * with current directories.
-	 * This relies on TMPNAME beginning with "%s\\"!!!!
-	 */
-	strcpy(tmpname, o_directory);
-	if ((i = strlen(tmpname)) && !strchr(":/\\", tmpname[i-1]))
-		tmpname[i++]=SLASH;
-	sprintf(tmpname+i, TMPNAME+3, getpid(), tmpnum);
-#else
-	sprintf(tmpname, TMPNAME, o_directory, getpid(), tmpnum);
-#endif
-
-	/* make sure nobody else is editing the same file */
-	if (access(tmpname, 0) == 0)
-	{
-		FAIL("Temp file \"%s\" already exists?", tmpname);
-	}
-
-	/* create the temp file */
-#if ANY_UNIX
-	close(creat(tmpname, 0600));		/* only we can read it */
-#else
-	close(creat(tmpname, FILEPERMS));	/* anybody body can read it, alas */
-#endif
-	tmpfd = open(tmpname, O_RDWR | O_BINARY);
-	if (tmpfd < 0)
-	{
-		FAIL("Can't create temp file... Does directory \"%s\" exist?", o_directory);
-		return 1;
-	}
-
-	/* allocate space for the header in the file */
-	write(tmpfd, hdr.c, (unsigned)BLKSIZE);
-	write(tmpfd, tmpblk.c, (unsigned)BLKSIZE);
-
-#ifndef NO_RECYCLE
-	/* initialize the block allocator */
-	/* This must already be done here, before the first attempt
-	 * to write to the new file! GB */
-	garbage();
-#endif
-
-	/* initialize lnum[] */
-	for (i = 1; i < MAXBLKS; i++)
-	{
-		lnum[i] = INFINITY;
-	}
-	lnum[0] = 0;
-
-	/* if there is no original file, then create a 1-line file */
-	if (origfd < 0)
-	{
-		hdr.n[0] = 0;	/* invalid inode# denotes new file */
-
-		this = blkget(1); 	/* get the new text block */
-		strcpy(this->c, "\n");	/* put a line in it */
-
-		lnum[1] = 1L;	/* block 1 ends with line 1 */
-		nlines = 1L;	/* there is 1 line in the file */
-		nbytes = 1L;
-
-		if (*origname)
-		{
-			msg("\"%s\" [NEW FILE]  1 line, 1 char", origname);
-		}
-		else
-		{
-			msg("\"[NO FILE]\"  1 line, 1 char");
-		}
-	}
-	else /* there is an original file -- read it in */
-	{
-		nbytes = nlines = 0;
-
-		/* preallocate 1 "next" buffer */
-		i = 1;
-		next = blkget(i);
-		inbuf = 0;
-
-		/* loop, moving blocks from orig to tmp */
-		for (;;)
-		{
-			/* "next" buffer becomes "this" buffer */
-			this = next;
-
-			/* read [more] text into this block */
-			nread = tread(origfd, &this->c[inbuf], BLKSIZE - 1 - inbuf);
-			if (nread < 0)
-			{
-				close(origfd);
-				close(tmpfd);
-				tmpfd = -1;
-				unlink(tmpname);
-				FAIL("Error reading \"%s\"", origname);
-			}
-
-			/* convert NUL characters to something else */
-			for (j = k = inbuf; k < inbuf + nread; k++)
-			{
-				if (!this->c[k])
-				{
-					setflag(file, HADNUL);
-					this->c[j++] = 0x80;
-				}
-#ifndef CRUNCH
-				else if (*o_beautify && this->c[k] < ' ' && this->c[k] > 0)
-				{
-					if (this->c[k] == '\t'
-					 || this->c[k] == '\n'
-					 || this->c[k] == '\f')
-					{
-						this->c[j++] = this->c[k];
-					}
-					else if (this->c[k] == '\b')
-					{
-						/* delete '\b', but complain */
-						setflag(file, HADBS);
-					}
-					/* else silently delete control char */
-				}
-#endif
-				else
-				{
-					this->c[j++] = this->c[k];
-				}
-			}
-			inbuf = j;
-
-			/* if the buffer is empty, quit */
-			if (inbuf == 0)
-			{
-				goto FoundEOF;
-			}
-
-#if MSDOS || TOS
-/* BAH! MS text mode read fills inbuf, then compresses eliminating \r
-   but leaving garbage at end of buf. The same is true for TURBOC. GB. */
-
-			memset(this->c + inbuf, '\0', BLKSIZE - inbuf);
-#endif
-
-			/* search backward for last newline */
-			for (k = inbuf; --k >= 0 && this->c[k] != '\n';)
-			{
-			}
-			if (k++ < 0)
-			{
-				if (inbuf >= BLKSIZE - 1)
-				{
-					k = 80;
-				}
-				else
-				{
-					k = inbuf;
-				}
-			}
-
-			/* allocate next buffer */
-			next = blkget(++i);
-
-			/* move fragmentary last line to next buffer */
-			inbuf -= k;
-			for (j = 0; k < BLKSIZE; j++, k++)
-			{
-				next->c[j] = this->c[k];
-				this->c[k] = 0;
-			}
-
-			/* if necessary, add a newline to this buf */
-			for (k = BLKSIZE - inbuf; --k >= 0 && !this->c[k]; )
-			{
-			}
-			if (this->c[k] != '\n')
-			{
-				setflag(file, ADDEDNL);
-				this->c[k + 1] = '\n';
-			}
-
-			/* count the lines in this block */
-			for (k = 0; k < BLKSIZE && this->c[k]; k++)
-			{
-				if (this->c[k] == '\n')
-				{
-					nlines++;
-				}
-				nbytes++;
-			}
-			lnum[i - 1] = nlines;
-		}
-FoundEOF:
-
-		/* if this is a zero-length file, add 1 line */
-		if (nlines == 0)
-		{
-			this = blkget(1); 	/* get the new text block */
-			strcpy(this->c, "\n");	/* put a line in it */
-
-			lnum[1] = 1;	/* block 1 ends with line 1 */
-			nlines = 1;	/* there is 1 line in the file */
-			nbytes = 1;
-		}
-
-#if MSDOS || TOS
-		/* each line has an extra CR that we didn't count yet */
-		nbytes += nlines;
-#endif
-
-		/* report the number of lines in the file */
-		msg("\"%s\" %s %ld line%s, %ld char%s",
-			origname,
-			(tstflag(file, READONLY) ? "[READONLY]" : ""),
-			nlines,
-			nlines == 1 ? "" : "s",
-			nbytes,
-			nbytes == 1 ? "" : "s");
-	}
-
-	/* initialize the cursor to start of line 1 */
-	cursor = MARK_FIRST;
-
-	/* close the original file */
-	close(origfd);
-
-	/* any other messages? */
-	if (tstflag(file, HADNUL))
-	{
-		msg("This file contained NULs.  They've been changed to \\x80 chars");
-	}
-	if (tstflag(file, ADDEDNL))
-	{
-		msg("Newline characters have been inserted to break up long lines");
-	}
-#ifndef CRUNCH
-	if (tstflag(file, HADBS))
-	{
-		msg("Backspace characters deleted due to ':set beautify'");
-	}
-#endif
-
-	storename(origname);
-
-#ifndef NO_MODELINES
-	if (nlines > 10)
-	{
-		do_modelines(1L, 5L);
-		do_modelines(nlines - 4L, nlines);
-	}
-	else
-	{
-		do_modelines(1L, nlines);
-	}
-#endif
-
-	/* force all blocks out onto the disk, to support file recovery */
-	blksync();
-
-	return 0;
-}
-
-
-
-/* This function copies the temp file back onto an original file.
- * Returns TRUE if successful, or FALSE if the file could NOT be saved.
- */
-int tmpsave(filename, bang)
-	char	*filename;	/* the name to save it to */
-	int	bang;		/* forced write? */
-{
-	int		fd;	/* fd of the file we're writing to */
-	REG int		len;	/* length of a text block */
-	REG BLK		*this;	/* a text block */
-	long		bytes;	/* byte counter */
-	REG int		i;
-
-	/* if no filename is given, assume the original file name */
-	if (!filename || !*filename)
-	{
-		filename = origname;
-	}
-
-	/* if still no file name, then fail */
-	if (!*filename)
-	{
-		msg("Don't know a name for this file -- NOT WRITTEN");
-		return FALSE;
-	}
-
-	/* can't rewrite a READONLY file */
-#if AMIGA
-	if (!strcmp(filename, origname) && tstflag(file, READONLY) && !bang)
-#else
-	if (!strcmp(filename, origname) && *o_readonly && !bang)
-#endif
-	{
-		msg("\"%s\" [READONLY] -- NOT WRITTEN", filename);
-		return FALSE;
-	}
-
-	/* open the file */
-	if (*filename == '>' && filename[1] == '>')
-	{
-		filename += 2;
-		while (*filename == ' ' || *filename == '\t')
-		{
-			filename++;
-		}
-#ifdef O_APPEND
-		fd = open(filename, O_WRONLY|O_APPEND);
-#else
-		fd = open(filename, O_WRONLY);
-		lseek(fd, 0L, 2);
-#endif
-	}
-	else
-	{
-		/* either the file must not exist, or it must be the original
-		 * file, or we must have a bang, or "writeany" must be set.
-		 */
-		if (strcmp(filename, origname) && access(filename, 0) == 0 && !bang
-#ifndef CRUNCH
-		    && !*o_writeany
-#endif
-				   )
-		{
-			msg("File already exists - Use :w! to overwrite");
-			return FALSE;
-		}
-#if VMS
-		/* Create a new VMS version of this file. */
-		{ 
-		char *strrchr(), *ptr = strrchr(filename,';');
-		if (ptr) *ptr = '\0';  /* Snip off any ;number in the name */
-		}
-#endif
-		fd = creat(filename, FILEPERMS);
-	}
-	if (fd < 0)
-	{
-		msg("Can't write to \"%s\" -- NOT WRITTEN", filename);
-		return FALSE;
-	}
-
-	/* write each text block to the file */
-	bytes = 0L;
-	for (i = 1; i < MAXBLKS && (this = blkget(i)) && this->c[0]; i++)
-	{
-		for (len = 0; len < BLKSIZE && this->c[len]; len++)
-		{
-		}
-		if (twrite(fd, this->c, len) < len)
-		{
-			msg("Trouble writing to \"%s\"", filename);
-			if (!strcmp(filename, origname))
-			{
-				setflag(file, MODIFIED);
-			}
-			close(fd);
-			return FALSE;
-		}
-		bytes += len;
-	}
-
-	/* reset the "modified" flag, but not the "undoable" flag */
-	clrflag(file, MODIFIED);
-	significant = FALSE;
-
-	/* report lines & characters */
-#if MSDOS || TOS
-	bytes += nlines; /* for the inserted carriage returns */
-#endif
-	msg("Wrote \"%s\"  %ld lines, %ld characters", filename, nlines, bytes);
-
-	/* close the file */
-	close(fd);
-
-	return TRUE;
-}
-
-
-/* This function deletes the temporary file.  If the file has been modified
- * and "bang" is FALSE, then it returns FALSE without doing anything; else
- * it returns TRUE.
- *
- * If the "autowrite" option is set, then instead of returning FALSE when
- * the file has been modified and "bang" is false, it will call tmpend().
- */
-int tmpabort(bang)
-	int	bang;
-{
-	/* if there is no file, return successfully */
-	if (tmpfd < 0)
-	{
-		return TRUE;
-	}
-
-	/* see if we must return FALSE -- can't quit */
-	if (!bang && tstflag(file, MODIFIED))
-	{
-		/* if "autowrite" is set, then act like tmpend() */
-		if (*o_autowrite)
-			return tmpend(bang);
-		else
-			return FALSE;
-	}
-
-	/* delete the tmp file */
-	cutswitch();
-	strcpy(prevorig, origname);
-	prevline = markline(cursor);
-	*origname = '\0';
-	origtime = 0L;
-	blkinit();
-	nlines = 0;
-	initflags();
-	return TRUE;
-}
-
-/* This function saves the file if it has been modified, and then deletes
- * the temporary file. Returns TRUE if successful, or FALSE if the file
- * needs to be saved but can't be.  When it returns FALSE, it will not have
- * deleted the tmp file, either.
- */
-int tmpend(bang)
-	int	bang;
-{
-	/* save the file if it has been modified */
-	if (tstflag(file, MODIFIED) && !tmpsave((char *)0, FALSE) && !bang)
-	{
-		return FALSE;
-	}
-
-	/* delete the tmp file */
-	tmpabort(TRUE);
-
-	return TRUE;
-}
-
-
-/* If the tmp file has been changed, then this function will force those
- * changes to be written to the disk, so that the tmp file will survive a
- * system crash or power failure.
- */
-#if AMIGA || MSDOS || TOS
-sync()
-{
-	/* MS-DOS and TOS don't flush their buffers until the file is closed,
-	 * so here we close the tmp file and then immediately reopen it.
-	 */
-	close(tmpfd);
-	tmpfd = open(tmpname, O_RDWR | O_BINARY);
-	return 0;
-}
-#endif
-
-
-/* This function stores the file's name in the second block of the temp file.
- * SLEAZE ALERT!  SLEAZE ALERT!  The "tmpblk" buffer is probably being used
- * to store the arguments to a command, so we can't use it here.  Instead,
- * we'll borrow the buffer that is used for "shift-U".
- */
-storename(name)
-	char	*name;	/* the name of the file - normally origname */
-{
-#ifndef CRUNCH
-	int	len;
-	char	*ptr;
-#endif
-
-	/* we're going to clobber the U_text buffer, so reset U_line */
-	U_line = 0L;
-
-	if (!name)
-	{
-		strncpy(U_text, "", BLKSIZE);
-		U_text[1] = 127;
-	}
-#ifndef CRUNCH
-	else if (*name != SLASH)
-	{
-		/* get the directory name */
-		ptr = getcwd(U_text, BLKSIZE);
-		if (ptr != U_text)
-		{
-			strcpy(U_text, ptr);
-		}
-
-		/* append a slash to the directory name */
-		len = strlen(U_text);
-		U_text[len++] = SLASH;
-
-		/* append the filename, padded with heaps o' NULs */
-		strncpy(U_text + len, *name ? name : "foo", BLKSIZE - len);
-	}
-#endif
-	else
-	{
-		/* copy the filename into U_text */
-		strncpy(U_text, *name ? name : "foo", BLKSIZE);
-	}
-
-	if (tmpfd >= 0)
-	{
-		/* write the name out to second block of the temp file */
-		lseek(tmpfd, (long)BLKSIZE, 0);
-		write(tmpfd, U_text, (unsigned)BLKSIZE);
-	}
-	return 0;
-}
-
-
-
-/* This function handles deadly signals.  It restores sanity to the terminal
- * preserves the current temp file, and deletes any old temp files.
- */
-int deathtrap(sig)
-	int	sig;	/* the deadly signal that we caught */
-{
-	char	*why;
-
-	/* restore the terminal's sanity */
-	endwin();
-
-#ifdef CRUNCH
-	why = "-Elvis died";
-#else
-	/* give a more specific description of how Elvis died */
-	switch (sig)
-	{
-# ifdef SIGHUP
-	  case SIGHUP:	why = "-the modem lost its carrier";		break;
-# endif
-# ifndef DEBUG
-#  ifdef SIGILL
-	  case SIGILL:	why = "-Elvis hit an illegal instruction";	break;
-#  endif
-#  ifdef SIGBUS
-	  case SIGBUS:	why = "-Elvis had a bus error";			break;
-#  endif
-#  if defined(SIGSEGV) && !defined(TOS)
-	  case SIGSEGV:	why = "-Elvis had a segmentation violation";	break;
-#  endif
-#  ifdef SIGSYS
-	  case SIGSYS:	why = "-Elvis munged a system call";		break;
-#  endif
-# endif /* !DEBUG */
-# ifdef SIGPIPE
-	  case SIGPIPE:	why = "-the pipe reader died";			break;
-# endif
-# ifdef SIGTERM
-	  case SIGTERM:	why = "-Elvis was terminated";			break;
-# endif
-# if !MINIX
-#  ifdef SIGUSR1
-	  case SIGUSR1:	why = "-Elvis was killed via SIGUSR1";		break;
-#  endif
-#  ifdef SIGUSR2
-	  case SIGUSR2:	why = "-Elvis was killed via SIGUSR2";		break;
-#  endif
-# endif
-	  default:	why = "-Elvis died";				break;
-	}
-#endif
-
-	/* if we had a temp file going, then preserve it */
-	if (tmpnum > 0 && tmpfd >= 0)
-	{
-		close(tmpfd);
-		sprintf(tmpblk.c, "%s \"%s\" %s", PRESERVE, why, tmpname);
-		system(tmpblk.c);
-	}
-
-	/* delete any old temp files */
-	cutend();
-
-	/* exit with the proper exit status */
-	exit(sig);
-}
Index: trunk/minix/commands/elvis/unix.c
===================================================================
--- trunk/minix/commands/elvis/unix.c	(revision 9)
+++ 	(revision )
@@ -1,226 +1,0 @@
-/* unix.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the unix-specific versions the ttyread() functions.
- * There are actually three versions of ttyread() defined here, because
- * BSD, SysV, and V7 all need quite different implementations.
- */
-
-#include "config.h"
-#if ANY_UNIX
-# include "vi.h"
-
-# if BSD
-/* For BSD, we use select() to wait for characters to become available,
- * and then do a read() to actually get the characters.  We also try to
- * handle SIGWINCH -- if the signal arrives during the select() call, then
- * we adjust the o_columns and o_lines variables, and fake a control-L.
- */
-#  include <sys/types.h>
-#  include <sys/time.h>
-int ttyread(buf, len, time)
-	char	*buf;	/* where to store the gotten characters */
-	int	len;	/* maximum number of characters to read */
-	int	time;	/* maximum time to allow for reading */
-{
-	fd_set	rd;	/* the file descriptors that we want to read from */
-	static	tty;	/* 'y' if reading from tty, or 'n' if not a tty */
-	int	i;
-	struct timeval t;
-	struct timeval *tp;
-
-
-	/* do we know whether this is a tty or not? */
-	if (!tty)
-	{
-		tty = (isatty(0) ? 'y' : 'n');
-	}
-
-	/* compute the timeout value */
-	if (time)
-	{
-		t.tv_sec = time / 10;
-		t.tv_usec = (time % 10) * 100000L;
-		tp = &t;
-	}
-	else
-	{
-		tp = (struct timeval *)0;
-	}
-
-	/* loop until we get characters or a definite EOF */
-	for (;;)
-	{
-		if (tty == 'y')
-		{
-			/* wait until timeout or characters are available */
-			FD_ZERO(&rd);
-			FD_SET(0, &rd);
-			i = select(1, &rd, (fd_set *)0, (fd_set *)0, tp);
-		}
-		else
-		{
-			/* if reading from a file or pipe, never timeout!
-			 * (This also affects the way that EOF is detected)
-			 */
-			i = 1;
-		}
-	
-		/* react accordingly... */
-		switch (i)
-		{
-		  case -1:	/* assume we got an EINTR because of SIGWINCH */
-			if (*o_lines != LINES || *o_columns != COLS)
-			{
-				*o_lines = LINES;
-				*o_columns = COLS;
-#ifndef CRUNCH
-				if (!wset)
-				{
-					*o_window = LINES - 1;
-				}
-#endif
-				if (mode != MODE_EX)
-				{
-					/* pretend the user hit ^L */
-					*buf = ctrl('L');
-					return 1;
-				}
-			}
-			break;
-	
-		  case 0:	/* timeout */
-			return 0;
-	
-		  default:	/* characters available */
-			return read(0, buf, len);
-		}
-	}
-}
-# else
-
-# if M_SYSV
-/* For System-V or Coherent, we use VMIN/VTIME to implement the timeout.
- * For no timeout, VMIN should be 1 and VTIME should be 0; for timeout,
- * VMIN should be 0 and VTIME should be the timeout value.
- */
-#  include <termio.h>
-int ttyread(buf, len, time)
-	char	*buf;	/* where to store the gotten characters */
-	int	len;	/* maximum number of characters to read */
-	int	time;	/* maximum time to allow for reading */
-{
-	struct termio tio;
-	int	bytes;	/* number of bytes actually read */
-
-	/* arrange for timeout */
-	ioctl(0, TCGETA, &tio);
-	if (time)
-	{
-		tio.c_cc[VMIN] = 0;
-		tio.c_cc[VTIME] = time;
-	}
-	else
-	{
-		tio.c_cc[VMIN] = 1;
-		tio.c_cc[VTIME] = 0;
-	}
-	ioctl(0, TCSETA, &tio);
-
-	/* Perform the read.  Loop if EINTR error happens */
-	while ((bytes = read(0, buf, len)) < 0)
-	{
-		/* probably EINTR error because a SIGWINCH was received */
-		if (*o_lines != LINES || *o_columns != COLS)
-		{
-			*o_lines = LINES;
-			*o_columns = COLS;
-#ifndef CRUNCH
-			if (!wset)
-			{
-				*o_window = LINES - 1;
-			}
-#endif
-			if (mode != MODE_EX)
-			{
-				/* pretend the user hit ^L */
-				*buf = ctrl('L');
-				return 1;
-			}
-		}
-	}
-
-	/* return the number of bytes read */
-	return bytes;
-
-	/* NOTE: The terminal may be left in a timeout-mode after this function
-	 * returns.  This shouldn't be a problem since Elvis *NEVER* tries to
-	 * read from the keyboard except through this function.
-	 */
-}
-
-# else /* any other version of UNIX, assume it is V7 compatible */
-
-/* For V7 UNIX (including Minix) we set an alarm() before doing a blocking
- * read(), and assume that the SIGALRM signal will cause the read() function
- * to give up.
- */
-
-#include <setjmp.h>
-
-static jmp_buf env;
-
-/*ARGSUSED*/
-int dummy(signo)
-	int	signo;
-{
-	longjmp(env, 1);
-}
-int ttyread(buf, len, time)
-	char	*buf;	/* where to store the gotten characters */
-	int	len;	/* maximum number of characters to read */
-	int	time;	/* maximum time to allow for reading */
-{
-	/* arrange for timeout */
-#if __GNUC__ || _ANSI
-	signal(SIGALRM, (void (*)()) dummy);
-#else
-	signal(SIGALRM, dummy);
-#endif
-	alarm(time);
-
-	/* perform the blocking read */
-	if (setjmp(env) == 0)
-	{
-		len = read(0, buf, len);
-	}
-	else /* I guess we timed out */
-	{
-		len = 0;
-	}
-
-	/* cancel the alarm */
-#if _ANSI
-	signal(SIGALRM, (void (*)())dummy); /* work around a bug in Minix */
-#else
-	signal(SIGALRM, dummy);		    /* work around a bug in Minix */
-#endif
-	alarm(0);
-
-	/* return the number of bytes read */
-	if (len < 0)
-		len = 0;
-	return len;
-}
-
-# endif /* !(M_SYSV || COHERENT) */
-# endif /* !BSD */
-
-#endif /* ANY_UNIX */
Index: trunk/minix/commands/elvis/vars.c
===================================================================
--- trunk/minix/commands/elvis/vars.c	(revision 9)
+++ 	(revision )
@@ -1,115 +1,0 @@
-/* vars.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains variables which weren't happy anyplace else */
-
-#include "config.h"
-#include "vi.h"
-
-/*------------------------------------------------------------------------*/
-
-/* used to remember whether the file has been modified */
-struct _viflags	viflags;
-
-/* used to access the tmp file */
-long		lnum[MAXBLKS];
-long		nlines;
-int		tmpfd = -1;
-int		tmpnum;
-#ifndef CRUNCH
-int		wset = FALSE;
-#endif
-
-/* used to keep track of the current file & alternate file */
-long		origtime;
-char		origname[256];
-char		prevorig[256];
-long		prevline = 1;
-
-/* used to track various places in the text */
-MARK		mark[NMARKS];	/* marks 'a through 'z, plus mark '' */
-MARK		cursor;		/* the cursor position within the file */
-
-/* which mode of the editor we're in */
-int		mode;		/* vi mode? ex mode? quitting? */
-
-/* used to manage the args list */
-char		args[BLKSIZE];	/* list of filenames to edit */
-int		argno;		/* index of current file in args list */
-int		nargs;		/* number of filenames in args[] */
-
-/* dummy var, never explicitly referenced */
-int		bavar;		/* used only in BeforeAfter macros */
-
-/* used to detect changes that invalidate cached text/blocks */
-long		changes;	/* incremented when file is changed */
-int		significant;	/* boolean: was a *REAL* change made? */
-
-/* used to support the pfetch() macro */
-int		plen;		/* length of the line */
-long		pline;		/* line number that len refers to */
-long		pchgs;		/* "changes" level that len refers to */
-char		*ptext;		/* text of previous line, if valid */
-
-/* misc temporary storage - mostly for strings */
-BLK		tmpblk;		/* a block used to accumulate changes */
-
-/* screen oriented stuff */
-long		topline;	/* file line number of top line */
-int		leftcol;	/* column number of left col */
-int		physcol;	/* physical column number that cursor is on */
-int		physrow;	/* physical row number that cursor is on */
-
-/* used to help minimize that "[Hit a key to continue]" message */
-int		exwrote;	/* Boolean: was the last ex command wordy? */
-
-/* This variable affects the behaviour of certain functions -- most importantly
- * the input function.
- */
-int		doingdot;	/* boolean: are we doing the "." command? */
-
-/* This variable affects the behaviour of the ":s" command, and it is also
- * used to detect & prohibit nesting of ":g" commands
- */
-int		doingglobal;	/* boolean: are doing a ":g" command? */
-
-/* This variable is zeroed before a command executes, and later ORed with the
- * command's flags after the command has been executed.  It is used to force
- * certain flags to be TRUE for *some* invocations of a particular command.
- * For example, "/regexp/+offset" forces the LNMD flag, and sometimes a "p"
- * or "P" command will force FRNT.
- */
-int		force_flags;
-
-/* These are used for reporting multi-line changes to the user */
-long		rptlines;	/* number of lines affected by a command */
-char		*rptlabel;	/* description of how lines were affected */
-
-/* These store info that pertains to the shift-U command */
-long	U_line;			/* line# of the undoable line, or 0l for none */
-char	U_text[BLKSIZE];	/* contents of the undoable line */
-
-
-#ifndef NO_VISIBLE
-/* These are used to implement the 'v' and 'V' commands */
-MARK	V_from;			/* starting point for v or V */
-int	V_linemd;		/* boolean: doing line-mode version? (V, not v) */
-#endif
-
-/* Bigger stack req'ed for TOS and TURBOC */
-
-#if TOS
-long	_stksize = 16384;
-#endif
-
-#if TURBOC
-#include <dos.h>
-extern unsigned _stklen = 16384U;
-#endif
Index: trunk/minix/commands/elvis/vcmd.c
===================================================================
--- trunk/minix/commands/elvis/vcmd.c	(revision 9)
+++ 	(revision )
@@ -1,975 +1,0 @@
-/* vcmd.c */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-/* This file contains the functions that handle VI commands */
-
-
-#include "config.h"
-#include "ctype.h"
-#include "vi.h"
-#if MSDOS
-# include <process.h>
-# include <string.h>
-#endif
-#if TOS
-# include <osbind.h>
-# include <string.h>
-#endif
-#if OSK
-# include <stdio.h>
-#endif
-
-
-/* This function puts the editor in EX mode */
-MARK v_quit()
-{
-	move(LINES - 1, 0);
-	mode = MODE_EX;
-	return cursor;
-}
-
-/* This function causes the screen to be redrawn */
-MARK v_redraw()
-{
-	redraw(MARK_UNSET, FALSE);
-	return cursor;
-}
-
-/* This function executes a string of EX commands, and waits for a user keystroke
- * before returning to the VI screen.  If that keystroke is another ':', then
- * another EX command is read and executed.
- */
-/*ARGSUSED*/
-MARK v_1ex(m, text)
-	MARK	m;	/* the current line */
-	char	*text;	/* the first command to execute */
-{
-	/* run the command.  be careful about modes & output */
-	exwrote = (mode == MODE_COLON);
-	doexcmd(text);
-	exrefresh();
-
-	/* if mode is no longer MODE_VI, then we should quit right away! */
-	if (mode != MODE_VI && mode != MODE_COLON)
-		return cursor;
-
-	/* The command did some output.  Wait for a keystoke. */
-	if (exwrote)
-	{
-		mode = MODE_VI;	
-		msg("[Hit <RETURN> to continue]");
-		if (getkey(0) == ':')
-		{	mode = MODE_COLON;
-			addch('\n');
-		}
-		else
-			redraw(MARK_UNSET, FALSE);
-	}
-
-	return cursor;
-}
-
-/* This function undoes the last change */
-/*ARGSUSED*/
-MARK v_undo(m)
-	MARK	m;	/* (ignored) */
-{
-	if (undo())
-	{
-		redraw(MARK_UNSET, FALSE);
-	}
-	return cursor;
-}
-
-/* This function deletes the character(s) that the cursor is on */
-MARK v_xchar(m, cnt, cmd)
-	MARK	m;	/* where to start deletions */
-	long	cnt;	/* number of chars to delete */
-	int	cmd;	/* either 'x' or 'X' */
-{
-	DEFAULT(1);
-
-	/* for 'X', adjust so chars are deleted *BEFORE* cursor */
-	if (cmd == 'X')
-	{
-		if (markidx(m) < cnt)
-			return MARK_UNSET;
-		m -= cnt;
-	}
-
-	/* make sure we don't try to delete more thars than there are */
-	pfetch(markline(m));
-	if (markidx(m + cnt) > plen)
-	{
-		cnt = plen - markidx(m);
-	}
-	if (cnt == 0L)
-	{
-		return MARK_UNSET;
-	}
-
-	/* do it */
-	ChangeText
-	{
-		cut(m, m + cnt);
-		delete(m, m + cnt);
-	}
-	return m;
-}
-
-/* This function defines a mark */
-/*ARGSUSED*/
-MARK v_mark(m, count, key)
-	MARK	m;	/* where the mark will be */
-	long	count;	/* (ignored) */
-	int	key;	/* the ASCII label of the mark */
-{
-	if (key < 'a' || key > 'z')
-	{
-		msg("Marks must be from a to z");
-	}
-	else
-	{
-		mark[key - 'a'] = m;
-	}
-	return m;
-}
-
-/* This function toggles upper & lower case letters */
-MARK v_ulcase(m, cnt)
-	MARK	m;	/* where to make the change */
-	long	cnt;	/* number of chars to flip */
-{
-	REG char 	*pos;
-	REG int		j;
-
-	DEFAULT(1);
-
-	/* fetch the current version of the line */
-	pfetch(markline(m));
-
-	/* for each position in the line */
-	for (j = 0, pos = &ptext[markidx(m)]; j < cnt && *pos; j++, pos++)
-	{
-		if (isupper(*pos))
-		{
-			tmpblk.c[j] = tolower(*pos);
-		}
-		else
-		{
-			tmpblk.c[j] = toupper(*pos);
-		}
-	}
-
-	/* if the new text is different from the old, then change it */
-	if (strncmp(tmpblk.c, &ptext[markidx(m)], j))
-	{
-		ChangeText
-		{
-			tmpblk.c[j] = '\0';
-			change(m, m + j, tmpblk.c);
-		}
-	}
-
-	return m + j;
-}
-
-
-MARK v_replace(m, cnt, key)
-	MARK	m;	/* first char to be replaced */
-	long	cnt;	/* number of chars to replace */
-	int	key;	/* what to replace them with */
-{
-	REG char	*text;
-	REG int		i;
-
-	DEFAULT(1);
-
-	/* map ^M to '\n' */
-	if (key == '\r')
-	{
-		key = '\n';
-	}
-
-	/* make sure the resulting line isn't too long */
-	if (cnt > BLKSIZE - 2 - markidx(m))
-	{
-		cnt = BLKSIZE - 2 - markidx(m);
-	}
-
-	/* build a string of the desired character with the desired length */
-	for (text = tmpblk.c, i = cnt; i > 0; i--)
-	{
-		*text++ = key;
-	}
-	*text = '\0';
-
-	/* make sure cnt doesn't extend past EOL */
-	pfetch(markline(m));
-	key = markidx(m);
-	if (key + cnt > plen)
-	{
-		cnt = plen - key;
-	}
-
-	/* do the replacement */
-	ChangeText
-	{
-		change(m, m + cnt, tmpblk.c);
-	}
-
-	if (*tmpblk.c == '\n')
-	{
-		return (m & ~(BLKSIZE - 1)) + cnt * BLKSIZE;
-	}
-	else
-	{
-		return m + cnt - 1;
-	}
-}
-
-MARK v_overtype(m)
-	MARK		m;	/* where to start overtyping */
-{
-	MARK		end;	/* end of a substitution */
-	static long	width;	/* width of a single-line replace */
-
-	/* the "doingdot" version of replace is really a substitution */
-	if (doingdot)
-	{
-		/* was the last one really repeatable? */
-		if (width < 0)
-		{
-			msg("Can't repeat a multi-line overtype command");
-			return MARK_UNSET;
-		}
-
-		/* replacing nothing by nothing?  Don't bother */
-		if (width == 0)
-		{
-			return m;
-		}
-
-		/* replace some chars by repeated text */
-		return v_subst(m, width);
-	}
-
-	/* Normally, we input starting here, in replace mode */
-	ChangeText
-	{
-		end = input(m, m, WHEN_VIREP, FALSE);
-	}
-
-	/* if we ended on the same line we started on, then this
-	 * overtype is repeatable via the dot key.
-	 */
-	if (markline(end) == markline(m) && end >= m - 1L)
-	{
-		width = end - m + 1L;
-	}
-	else /* it isn't repeatable */
-	{
-		width = -1L;
-	}
-
-	return end;
-}
-
-
-/* This function selects which cut buffer to use */
-/*ARGSUSED*/
-MARK v_selcut(m, cnt, key)
-	MARK	m;
-	long	cnt;
-	int	key;
-{
-	cutname(key);
-	return m;
-}
-
-/* This function pastes text from a cut buffer */
-/*ARGSUSED*/
-MARK v_paste(m, cnt, cmd)
-	MARK	m;	/* where to paste the text */
-	long	cnt;	/* (ignored) */
-	int	cmd;	/* either 'p' or 'P' */
-{
-	MARK	dest;
-
-	ChangeText
-	{
-		/* paste the text, and find out where it ends */
-		dest = paste(m, cmd == 'p', TRUE);
-
-		/* was that a line-mode paste? */
-		if (dest && markline(dest) != markline(m))
-		{
-			/* line-mode pastes leave the cursor at the front
-			 * of the first pasted line.
-			 */
-			dest = m;
-			if (cmd == 'p')
-			{
-				dest += BLKSIZE;
-			}
-			force_flags |= FRNT;
-		}
-	}
-	return dest;
-}
-
-/* This function yanks text into a cut buffer */
-MARK v_yank(m, n)
-	MARK	m, n;	/* range of text to yank */
-{
-	cut(m, n);
-	return m;
-}
-
-/* This function deletes a range of text */
-MARK v_delete(m, n)
-	MARK	m, n;	/* range of text to delete */
-{
-	/* illegal to try and delete nothing */
-	if (n <= m)
-	{
-		return MARK_UNSET;
-	}
-
-	/* Do it */
-	ChangeText
-	{
-		cut(m, n);
-		delete(m, n);
-	}
-	return m;
-}
-
-
-/* This starts input mode without deleting anything */
-MARK v_insert(m, cnt, key)
-	MARK	m;	/* where to start (sort of) */
-	long	cnt;	/* repeat how many times? */
-	int	key;	/* what command is this for? {a,A,i,I,o,O} */
-{
-	int	wasdot;
-	long	reps;
-	int	above;	/* boolean: new line going above old line? */
-
-	DEFAULT(1);
-
-	ChangeText
-	{
-		/* tweak the insertion point, based on command key */
-		above = FALSE;
-		switch (key)
-		{
-		  case 'i':
-			break;
-
-		  case 'a':
-			pfetch(markline(m));
-			if (plen > 0)
-			{
-				m++;
-			}
-			break;
-
-		  case 'I':
-			m = m_front(m, 1L);
-			break;
-
-		  case 'A':
-			pfetch(markline(m));
-			m = (m & ~(BLKSIZE - 1)) + plen;
-			break;
-
-		  case 'O':
-			m &= ~(BLKSIZE - 1);
-			add(m, "\n");
-			above = TRUE;
-			break;
-
-		  case 'o':
-			m = (m & ~(BLKSIZE - 1)) + BLKSIZE;
-			add(m, "\n");
-			break;
-		}
-
-		/* insert the same text once or more */
-		for (reps = cnt, wasdot = doingdot; reps > 0; reps--, doingdot = TRUE)
-		{
-			m = input(m, m, WHEN_VIINP, above) + 1;
-		}
-		if (markidx(m) > 0)
-		{
-			m--;
-		}
-
-		doingdot = wasdot;
-	}
-
-#ifndef CRUNCH
-# ifndef NO_EXTENSIONS
-	if (key == 'i' && *o_inputmode && mode == MODE_VI)
-	{
-		msg("Now in command mode!  To return to input mode, hit <i>");
-	}
-# endif
-#endif
-
-	return m;
-}
-
-/* This starts input mode with some text deleted */
-MARK v_change(m, n)
-	MARK	m, n;	/* the range of text to change */
-{
-	int	lnmode;	/* is this a line-mode change? */
-
-	/* swap them if they're in reverse order */
-	if (m > n)
-	{
-		MARK	tmp;
-		tmp = m;
-		m = n;
-		n = tmp;
-	}
-
-	/* for line mode, retain the last newline char */
-	lnmode = (markidx(m) == 0 && markidx(n) == 0 && m != n);
-	if (lnmode)
-	{
-		n -= BLKSIZE;
-		pfetch(markline(n));
-		n = (n & ~(BLKSIZE - 1)) + plen;
-	}
-
-	ChangeText
-	{
-		cut(m, n);
-		m = input(m, n, WHEN_VIINP, FALSE);
-	}
-
-	return m;
-}
-
-/* This function replaces a given number of characters with input */
-MARK v_subst(m, cnt)
-	MARK	m;	/* where substitutions start */
-	long	cnt;	/* number of chars to replace */
-{
-	DEFAULT(1);
-
-	/* make sure we don't try replacing past EOL */
-	pfetch(markline(m));
-	if (markidx(m) + cnt > plen)
-	{
-		cnt = plen - markidx(m);
-	}
-
-	/* Go for it! */
-	ChangeText
-	{
-		cut(m, m + cnt);
-		m = input(m, m + cnt, WHEN_VIINP, FALSE);
-	}
-	return m;
-}
-
-/* This calls the ex "join" command to join some lines together */
-MARK v_join(m, cnt)
-	MARK	m;	/* the first line to be joined */
-	long	cnt;	/* number of other lines to join */
-{
-	MARK	joint;	/* where the lines were joined */
-
-	DEFAULT(1);
-
-	/* figure out where the joint will be */
-	pfetch(markline(m));
-	joint = (m & ~(BLKSIZE - 1)) + plen;
-
-	/* join the lines */
-	cmd_join(m, m + MARK_AT_LINE(cnt), CMD_JOIN, 0, "");
-
-	/* the cursor should be left at the joint */
-	return joint;
-}
-
-
-/* This calls the ex "<" command to shift some lines left */
-MARK v_lshift(m, n)
-	MARK	m, n;	/* range of lines to shift */
-{
-	/* adjust for inclusive endmarks in ex */
-	n -= BLKSIZE;
-
-	cmd_shift(m, n, CMD_SHIFTL, FALSE, (char *)0);
-
-	return m;
-}
-
-/* This calls the ex ">" command to shift some lines right */
-MARK v_rshift(m, n)
-	MARK	m, n;	/* range of lines to shift */
-{
-	/* adjust for inclusive endmarks in ex */
-	n -= BLKSIZE;
-
-	cmd_shift(m, n, CMD_SHIFTR, FALSE, (char *)0);
-
-	return m;
-}
-
-/* This filters some lines through a preset program, to reformat them */
-MARK v_reformat(m, n)
-	MARK	m, n;	/* range of lines to shift */
-{
-	/* adjust for inclusive endmarks in ex */
-	n -= BLKSIZE;
-
-	/* run the filter command */
-	filter(m, n, o_equalprg, TRUE);
-
-	redraw(MARK_UNSET, FALSE);
-	return m;
-}
-
-
-/* This runs some lines through a filter program */
-MARK v_filter(m, n)
-	MARK	m, n;	/* range of lines to shift */
-{
-	char	cmdln[150];	/* a shell command line */
-
-	/* adjust for inclusive endmarks in ex */
-	n -= BLKSIZE;
-
-	if (vgets('!', cmdln, sizeof(cmdln)) > 0)
-	{
-		filter(m, n, cmdln, TRUE);
-	}
-
-	redraw(MARK_UNSET, FALSE);
-	return m;
-}
-
-
-/* This function runs the ex "file" command to show the file's status */
-MARK v_status()
-{
-	cmd_file(cursor, cursor, CMD_FILE, 0, "");
-	return cursor;
-}
-
-
-/* This function runs the ":&" command to repeat the previous :s// */
-MARK v_again(m, n)
-	MARK	m, n;
-{
-	cmd_substitute(m, n - BLKSIZE, CMD_SUBAGAIN, TRUE, "");
-	return cursor;
-}
-
-
-
-/* This function switches to the previous file, if possible */
-MARK v_switch()
-{
-	if (!*prevorig)
-		msg("No previous file");
-	else
-	{	strcpy(tmpblk.c, prevorig);
-		cmd_edit(cursor, cursor, CMD_EDIT, 0, tmpblk.c);
-	}
-	return cursor;
-}
-
-/* This function does a tag search on a keyword */
-/*ARGSUSED*/
-MARK v_tag(keyword, m, cnt)
-	char	*keyword;
-	MARK	m;
-	long	cnt;
-{
-	/* move the cursor to the start of the tag name, where m is */
-	cursor = m;
-
-	/* perform the tag search */
-	cmd_tag(cursor, cursor, CMD_TAG, 0, keyword);
-
-	return cursor;
-}
-
-#ifndef NO_EXTENSIONS
-/* This function looks up a keyword by calling the helpprog program */
-/*ARGSUSED*/
-MARK v_keyword(keyword, m, cnt)
-	char	*keyword;
-	MARK	m;
-	long	cnt;
-{
-	int	waswarn;
-	char	cmdline[130];
-
-	move(LINES - 1, 0);
-	addstr("---------------------------------------------------------\n");
-	clrtoeol();
-	refresh();
-	sprintf(cmdline, "%s %s", o_keywordprg, keyword);
-	waswarn = *o_warn;
-	*o_warn = FALSE;
-	suspend_curses();
-	if (system(cmdline))
-	{
-		addstr("<<< failed >>>\n");
-	}
-	resume_curses(FALSE);
-	mode = MODE_VI;
-	redraw(MARK_UNSET, FALSE);
-	*o_warn = waswarn;
-
-	return m;
-}
-
-
-
-MARK v_increment(keyword, m, cnt)
-	char	*keyword;
-	MARK	m;
-	long	cnt;
-{
-	static	sign;
-	char	newval[12];
-	long	atol();
-
-	DEFAULT(1);
-
-	/* get one more keystroke, unless doingdot */
-	if (!doingdot)
-	{
-		sign = getkey(0);
-	}
-
-	/* adjust the number, based on that second keystroke */
-	switch (sign)
-	{
-	  case '+':
-	  case '#':
-		cnt = atol(keyword) + cnt;
-		break;
-
-	  case '-':
-		cnt = atol(keyword) - cnt;
-		break;
-
-	  case '=':
-		break;
-
-	  default:
-		return MARK_UNSET;
-	}
-	sprintf(newval, "%ld", cnt);
-
-	ChangeText
-	{
-		change(m, m + strlen(keyword), newval);
-	}
-
-	return m;
-}
-#endif
-
-
-/* This function acts like the EX command "xit" */
-/*ARGSUSED*/
-MARK v_xit(m, cnt, key)
-	MARK	m;	/* ignored */
-	long	cnt;	/* ignored */
-	int	key;	/* must be a second 'Z' */
-{
-	/* if second char wasn't 'Z', fail */
-	if (key != 'Z')
-	{
-		return MARK_UNSET;
-	}
-
-	/* move the cursor to the bottom of the screen */
-	move(LINES - 1, 0);
-	clrtoeol();
-
-	/* do the xit command */
-	cmd_xit(m, m, CMD_XIT, FALSE, "");
-
-	/* return the cursor */
-	return m;
-}
-
-
-/* This function undoes changes to a single line, if possible */
-MARK v_undoline(m)
-	MARK	m;	/* where we hope to undo the change */
-{
-	/* make sure we have the right line in the buffer */
-	if (markline(m) != U_line)
-	{
-		return MARK_UNSET;
-	}
-
-	/* fix it */
-	ChangeText
-	{
-		strcat(U_text, "\n");
-		change(MARK_AT_LINE(U_line), MARK_AT_LINE(U_line + 1), U_text);
-	}
-
-	/* nothing in the buffer anymore */
-	U_line = -1L;
-
-	/* return, with the cursor at the front of the line */
-	return m & ~(BLKSIZE - 1);
-}
-
-
-#ifndef NO_ERRLIST
-MARK v_errlist(m)
-	MARK	m;
-{
-	cmd_errlist(m, m, CMD_ERRLIST, FALSE, "");
-	return cursor;
-}
-#endif
-
-
-#ifndef NO_AT
-/*ARGSUSED*/
-MARK v_at(m, cnt, key)
-	MARK	m;
-	long	cnt;
-	int	key;
-{
-	int	size;
-
-	size = cb2str(key, tmpblk.c, BLKSIZE);
-	if (size <= 0 || size == BLKSIZE)
-	{
-		return MARK_UNSET;
-	}
-
-	execmap(0, tmpblk.c, FALSE);
-	return cursor;
-}
-#endif
-
-
-#ifdef SIGTSTP
-MARK v_suspend()
-{
-	cmd_suspend(MARK_UNSET, MARK_UNSET, CMD_SUSPEND, FALSE, "");
-	return MARK_UNSET;
-}
-#endif
-
-
-#ifndef NO_VISIBLE
-/*ARGSUSED*/
-MARK v_start(m, cnt, cmd)
-	MARK	m;	/* starting point for a v or V command */
-	long	cnt;	/* ignored */
-	int	cmd;	/* either 'v' or 'V' */
-{
-	if (V_from)
-	{
-		V_from = MARK_UNSET;
-	}
-	else
-	{
-		V_from = m;
-		V_linemd = isupper(cmd);
-	}
-	return m;
-}
-#endif
-
-#ifndef NO_POPUP
-# define MENU_HEIGHT 11
-# define MENU_WIDTH  23
-MARK v_popup(m, n)
-	MARK		m, n;	/* the range of text to change */
-{
-	int		i;
-	int		y, x;	/* position where the window will pop up at */
-	int		key;	/* keystroke from the user */
-	int		sel;	/* index of the selected operation */
-	static int	dfltsel;/* default value of sel */
-	static char	*labels[11] =
-	{
-		"ESC cancel!         ",
-		" d  delete (cut)    ",
-		" y  yank (copy)     ",
-		" p  paste after     ",
-		" P  paste before    ",
-		" >  more indented   ",
-		" <  less indented   ",
-		" =  reformat        ",
-		" !  external filter ",
-		" ZZ save & exit     ",
-		" u  undo previous   "
-	};
-
-	/* try to position the menu near the cursor */
-	x = physcol - (MENU_WIDTH / 2);
-	if (x < 0)
-		x = 0;
-	else if (x + MENU_WIDTH + 2 > COLS)
-		x = COLS - MENU_WIDTH - 2;
-	if (markline(cursor) < topline || markline(cursor) > botline)
-		y = 0;
-	else if (markline(cursor) + 1L + MENU_HEIGHT > botline)
-		y = (int)(markline(cursor) - topline) - MENU_HEIGHT;
-	else
-		y = (int)(markline(cursor) - topline) + 1L;
-
-	/* draw the menu */
-	for (sel = 0; sel < MENU_HEIGHT; sel++)
-	{
-		move(y + sel, x);
-		do_POPUP();
-		if (sel == dfltsel)
-			qaddstr("-->");
-		else
-			qaddstr("   ");
-		qaddstr(labels[sel]);
-		do_SE();
-	}
-
-	/* get a selection */
-	move(y + dfltsel, x + 4);
-	for (sel = dfltsel; (key = getkey(WHEN_POPUP)) != '\\' && key != '\r'; )
-	{
-		/* erase the selection arrow */
-		move(y + sel, x);
-		do_POPUP();
-		qaddstr("   ");
-		qaddstr(labels[sel]);
-		do_SE();
-
-		/* process the user's keystroke */
-		if (key == 'j' && sel < MENU_HEIGHT - 1)
-		{
-			sel++;
-		}
-		else if (key == 'k' && sel > 0)
-		{
-			sel--;
-		}
-		else if (key == '\033')
-		{
-			sel = 0;
-			break;
-		}
-		else
-		{
-			for (i = 1; i < MENU_HEIGHT && labels[i][1] != key; i++)
-			{
-			}
-			if (i < MENU_HEIGHT)
-			{
-				sel = i;
-				break;
-			}
-		}
-
-		/* redraw the arrow, possibly in a new place */
-		move(y + sel, x);
-		do_POPUP();
-		qaddstr("-->");
-		qaddstr(labels[sel]);
-		do_SE();
-		move(y + sel, x + 4);
-	}
-
-	/* in most cases, the default selection is "paste after" */
-	dfltsel = 3;
-
-	/* perform the appropriate action */
-	switch (sel)
-	{
-	  case 0:
-		m = cursor;
-		dfltsel = 0;
-		break;
-
-	  case 1: /* delete (cut) */
-		m = v_delete(m, n);
-		break;
-
-	  case 2: /* yank (copy) */
-		m = v_yank(m, n);
-		break;
-
-	  case 3: /* paste after */
-		m = v_paste(n, 1L, 'P');
-		break;
-
-	  case 4: /* paste before */
-		m = v_paste(m, 1L, 'P');
-		dfltsel = 4;
-		break;
-
-	  case 5: /* more indented */
-		m = v_rshift(m, n);
-		dfltsel = 5;
-		break;
-
-	  case 6: /* less indented */
-		m = v_lshift(m, n);
-		dfltsel = 6;
-		break;
-
-	  case 7: /* reformat */
-		m = v_reformat(m, n);
-		dfltsel = 7;
-		break;
-
-	  case 8: /* external filter */
-		m = v_filter(m, n);
-		dfltsel = 0;
-		break;
-
-	  case 9: /* save & exit */
-		/* get confirmation first */
-		do
-		{
-			key = getkey(0);
-		} while (key != '\\' && key != 'Z' && key != '\r'    /* good */
-		      && key != '\033');			     /* bad  */
-		if (key != '\033')
-		{
-			m = v_xit(m, 0L, 'Z');
-		}
-		break;
-
-	  case 10: /* undo previous */
-		m = v_undo(m);
-		dfltsel = 9;
-		break;
-	}
-
-	/* arrange for the menu to be erased (except that "chg from kbd"
-	 * already erased it, and "save & exit" doesn't care)
-	 */
-	if (sel != 5 && sel != 9)
-		redraw(MARK_UNSET, FALSE);
-
-	return m;
-}
-#endif /* undef NO_POPUP */
Index: trunk/minix/commands/elvis/vi.c
===================================================================
--- trunk/minix/commands/elvis/vi.c	(revision 9)
+++ 	(revision )
@@ -1,815 +1,0 @@
-/* vi.c */
-
-/* Author:
- *	Steve Kirkendall
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-
-#include "config.h"
-#include "ctype.h"
-#include "vi.h"
-
-
-
-/* This array describes what each key does */
-#define NO_FUNC		(MARK (*)())0
-
-#define NO_ARGS		0
-#define CURSOR		1
-#define CURSOR_CNT_KEY	2
-#define CURSOR_MOVED	3
-#define CURSOR_EOL	4
-#define ZERO		5
-#define DIGIT		6
-#define CURSOR_TEXT	7
-#define KEYWORD		8
-#define ARGSMASK	0x0f
-#define	C_C_K_REP1	(CURSOR_CNT_KEY | 0x10)
-#define C_C_K_CUT	(CURSOR_CNT_KEY | 0x20)
-#define C_C_K_MARK	(CURSOR_CNT_KEY | 0x30)
-#define C_C_K_CHAR	(CURSOR_CNT_KEY | 0x40)
-#ifndef NO_SHOWMODE
-static int keymodes[] = {0, WHEN_REP1, WHEN_CUT, WHEN_MARK, WHEN_CHAR};
-# define KEYMODE(args) (keymodes[(args) >> 4])
-#else
-# define KEYMODE(args) 0
-#endif
-
-static struct keystru
-{
-	MARK	(*func)();	/* the function to run */
-	uchar	args;		/* description of the args needed */
-#ifndef NO_VISIBLE
-	short	flags;
-#else
-	uchar	flags;		/* other stuff */
-#endif
-}
-	vikeys[] =
-{
-/* NUL not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#ifndef NO_EXTENSIONS
-/* ^A  find cursor word */	{m_wsrch,	KEYWORD,	MVMT|NREL|VIZ},
-#else
-/* ^A  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/* ^B  page backward	*/	{m_scroll,	CURSOR,		FRNT|VIZ},
-/* ^C  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^D  scroll dn 1/2page*/	{m_scroll,	CURSOR,		NCOL|VIZ},
-/* ^E  scroll up	*/	{m_scroll,	CURSOR,		NCOL|VIZ},
-/* ^F  page forward	*/	{m_scroll,	CURSOR,		FRNT|VIZ},
-/* ^G  show file status	*/	{v_status,	NO_ARGS, 	NO_FLAGS},
-/* ^H  move left, like h*/	{m_left,	CURSOR,		MVMT|VIZ},
-/* ^I  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^J  move down	*/	{m_updnto,	CURSOR,		MVMT|LNMD|VIZ|INCL},
-/* ^K  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^L  redraw screen	*/	{v_redraw,	NO_ARGS,	NO_FLAGS|VIZ},
-/* ^M  mv front next ln */	{m_updnto,	CURSOR,		MVMT|FRNT|LNMD|VIZ|INCL},
-/* ^N  move down	*/	{m_updnto,	CURSOR,		MVMT|LNMD|VIZ|INCL|NCOL},
-/* ^O  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^P  move up		*/	{m_updnto,	CURSOR,		MVMT|LNMD|VIZ|INCL|NCOL},
-/* ^Q  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^R  redraw screen	*/	{v_redraw,	NO_ARGS,	NO_FLAGS|VIZ},
-/* ^S  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^T  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^U  scroll up 1/2page*/	{m_scroll,	CURSOR,		NCOL|VIZ},
-/* ^V  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^W  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^X  move to phys col	*/	{m_tocol,	CURSOR,		MVMT|NREL|VIZ},
-/* ^Y  scroll down	*/	{m_scroll,	CURSOR,		NCOL|VIZ},
-#ifdef SIGTSTP
-/* ^Z  suspend elvis	*/	{v_suspend,	NO_ARGS,	NO_FLAGS},
-#else
-/* ^Z  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/* ESC not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^\  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* ^]  keyword is tag	*/	{v_tag,		KEYWORD,	NO_FLAGS},
-/* ^^  previous file	*/	{v_switch,	CURSOR,		NO_FLAGS},
-/* ^_  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/* SPC move right,like l*/	{m_right,	CURSOR,		MVMT|INCL|VIZ},
-/*  !  run thru filter	*/	{v_filter,	CURSOR_MOVED,	FRNT|LNMD|INCL|VIZ},
-/*  "  select cut buffer*/	{v_selcut,	C_C_K_CUT,	PTMV|VIZ},
-#ifndef NO_EXTENSIONS
-/*  #  increment number	*/	{v_increment,	KEYWORD,	SDOT},
-#else
-/*  #  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  $  move to rear	*/	{m_rear,	CURSOR,		MVMT|INCL|VIZ},
-/*  %  move to match	*/	{m_match,	CURSOR,		MVMT|INCL|VIZ},
-/*  &  repeat subst	*/	{v_again,	CURSOR_MOVED,	SDOT|NCOL|LNMD|INCL},
-/*  '  move to a mark	*/	{m_tomark,	C_C_K_MARK,	MVMT|FRNT|NREL|LNMD|INCL|VIZ},
-#ifndef NO_SENTENCE
-/*  (  mv back sentence	*/	{m_sentence,	CURSOR,		MVMT|VIZ},
-/*  )  mv fwd sentence	*/	{m_sentence,	CURSOR,		MVMT|VIZ},
-#else
-/*  (  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/*  )  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-#ifndef NO_ERRLIST
-/*  *  errlist		*/	{v_errlist,	CURSOR,		FRNT|NREL},
-#else
-/*  *  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  +  mv front next ln */	{m_updnto,	CURSOR,		MVMT|FRNT|LNMD|VIZ|INCL},
-#ifndef NO_CHARSEARCH
-/*  ,  reverse [fFtT] cmd*/	{m__ch,		CURSOR,		MVMT|INCL|VIZ},
-#else
-/*  ,  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  -  mv front prev ln	*/	{m_updnto,	CURSOR,		MVMT|FRNT|LNMD|VIZ|INCL},
-/*  .  special...	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/*  /  forward search	*/	{m_fsrch,	CURSOR_TEXT,	MVMT|NREL|VIZ},
-/*  0  part of count?	*/	{NO_FUNC,	ZERO,		MVMT|PTMV|VIZ},
-/*  1  part of count	*/	{NO_FUNC,	DIGIT,		PTMV|VIZ},
-/*  2  part of count	*/	{NO_FUNC,	DIGIT,		PTMV|VIZ},
-/*  3  part of count	*/	{NO_FUNC,	DIGIT,		PTMV|VIZ},
-/*  4  part of count	*/	{NO_FUNC,	DIGIT,		PTMV|VIZ},
-/*  5  part of count	*/	{NO_FUNC,	DIGIT,		PTMV|VIZ},
-/*  6  part of count	*/	{NO_FUNC,	DIGIT,		PTMV|VIZ},
-/*  7  part of count	*/	{NO_FUNC,	DIGIT,		PTMV|VIZ},
-/*  8  part of count	*/	{NO_FUNC,	DIGIT,		PTMV|VIZ},
-/*  9  part of count	*/	{NO_FUNC,	DIGIT,		PTMV|VIZ},
-/*  :  run single EX cmd*/	{v_1ex,		CURSOR_TEXT,	NO_FLAGS},
-#ifndef NO_CHARSEARCH
-/*  ;  repeat [fFtT] cmd*/	{m__ch,		CURSOR,		MVMT|INCL|VIZ},
-#else
-/*  ;  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS|VIZ},
-#endif
-/*  <  shift text left	*/	{v_lshift,	CURSOR_MOVED,	SDOT|FRNT|LNMD|INCL|VIZ},
-/*  =  preset filter	*/	{v_reformat,	CURSOR_MOVED,	SDOT|FRNT|LNMD|INCL|VIZ},
-/*  >  shift text right	*/	{v_rshift,	CURSOR_MOVED,	SDOT|FRNT|LNMD|INCL|VIZ},
-/*  ?  backward search	*/	{m_bsrch,	CURSOR_TEXT,	MVMT|NREL|VIZ},
-#ifndef NO_AT
-/*  @  execute a cutbuf */	{v_at,		C_C_K_CUT,	NO_FLAGS},
-#else
-/*  @  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  A  append at EOL	*/	{v_insert,	CURSOR,		SDOT},
-/*  B  move back Word	*/	{m_bword,	CURSOR,		MVMT|VIZ},
-/*  C  change to EOL	*/	{v_change,	CURSOR_EOL,	SDOT},
-/*  D  delete to EOL	*/	{v_delete,	CURSOR_EOL,	SDOT},
-/*  E  move end of Word	*/	{m_eword,	CURSOR,		MVMT|INCL|VIZ},
-#ifndef NO_CHARSEARCH
-/*  F  move bk to char	*/	{m_Fch,		C_C_K_CHAR,	MVMT|INCL|VIZ},
-#else
-/*  F  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  G  move to line #	*/	{m_updnto,	CURSOR,		MVMT|NREL|LNMD|FRNT|INCL|VIZ},
-/*  H  move to row	*/	{m_row,		CURSOR,		MVMT|LNMD|FRNT|VIZ|INCL},
-/*  I  insert at front	*/	{v_insert,	CURSOR,		SDOT},
-/*  J  join lines	*/	{v_join,	CURSOR,		SDOT},
-#ifndef NO_EXTENSIONS
-/*  K  look up keyword	*/	{v_keyword,	KEYWORD,	NO_FLAGS},
-#else
-/*  K  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  L  move to last row	*/	{m_row,		CURSOR,		MVMT|LNMD|FRNT|VIZ|INCL},
-/*  M  move to mid row	*/	{m_row,		CURSOR,		MVMT|LNMD|FRNT|VIZ|INCL},
-/*  N  reverse prev srch*/	{m_Nsrch,	CURSOR,		MVMT|NREL|VIZ},
-/*  O  insert above line*/	{v_insert,	CURSOR,		SDOT},
-/*  P  paste before	*/	{v_paste,	CURSOR,		SDOT},
-/*  Q  quit to EX mode	*/	{v_quit,	NO_ARGS,	NO_FLAGS},
-/*  R  overtype		*/	{v_overtype,	CURSOR,		SDOT},
-/*  S  change line	*/	{v_change,	CURSOR_MOVED,	SDOT},
-#ifndef NO_CHARSEARCH
-/*  T  move bk to char	*/	{m_Tch,		C_C_K_CHAR,	MVMT|INCL|VIZ},
-#else
-/*  T  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  U  undo whole line	*/	{v_undoline,	CURSOR,		FRNT},
-#ifndef NO_VISIBLE
-/*  V  start visible	*/	{v_start,	CURSOR,		INCL|LNMD|VIZ},
-#else
-/*  V  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  W  move forward Word*/	{m_fword,	CURSOR,		MVMT|INCL|VIZ},
-/*  X  delete to left	*/	{v_xchar,	CURSOR,		SDOT},
-/*  Y  yank text	*/	{v_yank,	CURSOR_MOVED,	NCOL},
-/*  Z  save file & exit	*/	{v_xit,		CURSOR_CNT_KEY,	NO_FLAGS},
-/*  [  move back section*/	{m_paragraph,	CURSOR,		MVMT|LNMD|NREL|VIZ},
-#ifndef NO_POPUP
-/*  \  pop-up menu	*/	{v_popup,	CURSOR_MOVED,	VIZ},
-#else
-/*  \  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  ]  move fwd section */	{m_paragraph,	CURSOR,		MVMT|LNMD|NREL|VIZ},
-/*  ^  move to front	*/	{m_front,	CURSOR,		MVMT|VIZ},
-/*  _  current line	*/	{m_updnto,	CURSOR,		MVMT|LNMD|FRNT|INCL},
-/*  `  move to mark	*/	{m_tomark,	C_C_K_MARK,	MVMT|NREL|VIZ},
-/*  a  append at cursor	*/	{v_insert,	CURSOR,		SDOT},
-/*  b  move back word	*/	{m_bword,	CURSOR,		MVMT|VIZ},
-/*  c  change text	*/	{v_change,	CURSOR_MOVED,	SDOT|VIZ},
-/*  d  delete op	*/	{v_delete,	CURSOR_MOVED,	SDOT|VIZ},
-/*  e  move end word	*/	{m_eword,	CURSOR,		MVMT|INCL|VIZ},
-#ifndef NO_CHARSEARCH
-/*  f  move fwd for char*/	{m_fch,		C_C_K_CHAR,	MVMT|INCL|VIZ},
-#else
-/*  f  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  g  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/*  h  move left	*/	{m_left,	CURSOR,		MVMT|VIZ},
-/*  i  insert at cursor	*/	{v_insert,	CURSOR,		SDOT},
-/*  j  move down	*/	{m_updnto,	CURSOR,		MVMT|NCOL|LNMD|VIZ|INCL},
-/*  k  move up		*/	{m_updnto,	CURSOR,		MVMT|NCOL|LNMD|VIZ|INCL},
-/*  l  move right	*/	{m_right,	CURSOR,		MVMT|INCL|VIZ},
-/*  m  define a mark	*/	{v_mark,	C_C_K_MARK,	NO_FLAGS},
-/*  n  repeat prev srch	*/	{m_nsrch,	CURSOR, 	MVMT|NREL|VIZ},
-/*  o  insert below line*/	{v_insert,	CURSOR,		SDOT},
-/*  p  paste after	*/	{v_paste,	CURSOR,		SDOT},
-/*  q  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-/*  r  replace chars	*/	{v_replace,	C_C_K_REP1,	SDOT},
-/*  s  subst N chars	*/	{v_subst,	CURSOR,		SDOT},
-#ifndef NO_CHARSEARCH
-/*  t  move fwd to char	*/	{m_tch,		C_C_K_CHAR,	MVMT|INCL|VIZ},
-#else
-/*  t  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  u  undo		*/	{v_undo,	CURSOR,		NO_FLAGS},
-#ifndef NO_VISIBLE
-/*  v  start visible	*/	{v_start,	CURSOR,		INCL|VIZ},
-#else
-/*  v  not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS},
-#endif
-/*  w  move fwd word	*/	{m_fword,	CURSOR,		MVMT|INCL|VIZ},
-/*  x  delete character	*/	{v_xchar,	CURSOR,		SDOT},
-/*  y  yank text	*/	{v_yank,	CURSOR_MOVED,	NCOL|VIZ},
-/*  z  adjust scrn row	*/	{m_z, 		CURSOR_CNT_KEY,	NCOL|VIZ},
-/*  {  back paragraph	*/	{m_paragraph,	CURSOR,		MVMT|LNMD|VIZ},
-/*  |  move to column	*/	{m_tocol,	CURSOR,		MVMT|NREL|VIZ},
-/*  }  fwd paragraph	*/	{m_paragraph,	CURSOR,		MVMT|LNMD|VIZ},
-/*  ~  upper/lowercase	*/	{v_ulcase,	CURSOR,		SDOT},
-/* DEL not defined	*/	{NO_FUNC,	NO_ARGS,	NO_FLAGS}
-};
-
-
-
-void vi()
-{
-	REG int			key;	/* keystroke from user */
-	long			count;	/* numeric argument to some functions */
-	REG struct keystru	*keyptr;/* pointer to vikeys[] element */
-	MARK			tcurs;	/* temporary cursor */
-	int			prevkey;/* previous key, if d/c/y/</>/! */
-	MARK			range;	/* start of range for d/c/y/</>/! */
-	char			text[132];
-	int			dotkey;	/* last "key" of a change */
-	int			dotpkey;/* last "prevkey" of a change */
-	int			dotkey2;/* last extra "getkey()" of a change */
-	int			dotcnt;	/* last "count" of a change */
-	int			firstkey;
-	REG int			i;
-
-	/* tell the redraw() function to start from scratch */
-	redraw(MARK_UNSET, FALSE);
-
-#ifdef lint
-	/* lint says that "range" might be used before it is set.  This
-	 * can't really happen due to the way "range" and "prevkey" are used,
-	 * but lint doesn't know that.  This line is here ONLY to keep lint
-	 * happy.
-	 */
-	range = 0L;
-#endif
-
-	/* safeguard against '.' with no previous command */
-	dotkey = dotpkey = dotkey2 = dotcnt = 0;
-
-	/* go immediately into insert mode, if ":set inputmode" */
-	firstkey = 0;
-#ifndef NO_EXTENSIONS
-	if (*o_inputmode)
-	{
-		firstkey = 'i';
-	}
-#endif
-
-	/* Repeatedly handle VI commands */
-	for (count = 0, prevkey = '\0'; mode == MODE_VI; )
-	{
-		/* if we've moved off the undoable line, then we can't undo it at all */
-		if (markline(cursor) != U_line)
-		{
-			U_line = 0L;
-		}
-
-		/* report any changes from the previous command */
-		if (rptlines >= *o_report)
-		{
-			redraw(cursor, FALSE);
-			msg("%ld line%s %s", rptlines, (rptlines==1?"":"s"), rptlabel);
-		}
-		rptlines = 0L;
-
-		/* get the next command key.  It must be ASCII */
-		if (firstkey)
-		{
-			key = firstkey;
-			firstkey = 0;
-		}
-		else
-		{
-			do
-			{
-				key = getkey(WHEN_VICMD);
-			} while (key < 0 || key > 127);
-		}
-
-		/* Convert a doubled-up operator such as "dd" into "d_" */
-		if (prevkey && key == prevkey)
-		{
-			key = '_';
-		}
-
-		/* look up the structure describing this command */
-		keyptr = &vikeys[key];
-
-		/* '&' and uppercase operators always act like doubled */
-		if (!prevkey && keyptr->args == CURSOR_MOVED
-			&& (key == '&' || isupper(key)))
-		{
-			range = cursor;
-			prevkey = key;
-			key = '_';
-			keyptr = &vikeys[key];
-		}
-
-#ifndef NO_VISIBLE
-		/* if we're in the middle of a v/V command, reject commands
-		 * that aren't operators or movement commands
-		 */
-		if (V_from && !(keyptr->flags & VIZ))
-		{
-			beep();
-			prevkey = 0;
-			count = 0;
-			continue;
-		}
-#endif
-
-		/* if we're in the middle of a d/c/y/</>/! command, reject
-		 * anything but movement.
-		 */
-		if (prevkey && !(keyptr->flags & (MVMT|PTMV)))
-		{
-			beep();
-			prevkey = 0;
-			count = 0;
-			continue;
-		}
-
-		/* set the "dot" variables, if we're supposed to */
-		if (((keyptr->flags & SDOT)
-			|| (prevkey && vikeys[prevkey].flags & SDOT))
-#ifndef NO_VISIBLE
-		    && !V_from
-#endif
-		)
-		{
-			dotkey = key;
-			dotpkey = prevkey;
-			dotkey2 = '\0';
-			dotcnt = count;
-
-			/* remember the line before any changes are made */
-			if (U_line != markline(cursor))
-			{
-				U_line = markline(cursor);
-				strcpy(U_text, fetchline(U_line));
-			}
-		}
-
-		/* if this is "." then set other vars from the "dot" vars */
-		if (key == '.')
-		{
-			key = dotkey;
-			keyptr = &vikeys[key];
-			prevkey = dotpkey;
-			if (prevkey)
-			{
-				range = cursor;
-			}
-			if (count == 0)
-			{
-				count = dotcnt;
-			}
-			doingdot = TRUE;
-
-			/* remember the line before any changes are made */
-			if (U_line != markline(cursor))
-			{
-				U_line = markline(cursor);
-				strcpy(U_text, fetchline(U_line));
-			}
-		}
-		else
-		{
-			doingdot = FALSE;
-		}
-
-		/* process the key as a command */
-		tcurs = cursor;
-		force_flags = NO_FLAGS;
-		switch (keyptr->args & ARGSMASK)
-		{
-		  case ZERO:
-			if (count == 0)
-			{
-				tcurs = cursor & ~(BLKSIZE - 1);
-				break;
-			}
-			/* else fall through & treat like other digits... */
-
-		  case DIGIT:
-			count = count * 10 + key - '0';
-			break;
-
-		  case KEYWORD:
-			/* if not on a keyword, fail */
-			pfetch(markline(cursor));
-			key = markidx(cursor);
-			if (!isalnum(ptext[key]))
-			{
-				tcurs = MARK_UNSET;
-				break;
-			}
-
-			/* find the start of the keyword */
-			while (key > 0 && isalnum(ptext[key - 1]))
-			{
-				key--;
-			}
-			tcurs = (cursor & ~(BLKSIZE - 1)) + key;
-
-			/* copy it into a buffer, and NUL-terminate it */
-			i = 0;
-			do
-			{
-				text[i++] = ptext[key++];
-			} while (isalnum(ptext[key]));
-			text[i] = '\0';
-
-			/* call the function */
-			tcurs = (*keyptr->func)(text, tcurs, count);
-			count = 0L;
-			break;
-
-		  case NO_ARGS:
-			if (keyptr->func)
-			{
-				(*keyptr->func)();
-			}
-			else
-			{
-				beep();
-			}
-			count = 0L;
-			break;
-	
-		  case CURSOR:
-			tcurs = (*keyptr->func)(cursor, count, key, prevkey);
-			count = 0L;
-			break;
-
-		  case CURSOR_CNT_KEY:
-			if (doingdot)
-			{
-				tcurs = (*keyptr->func)(cursor, count, dotkey2);
-			}
-			else
-			{
-				/* get a key */
-				i = getkey(KEYMODE(keyptr->args));
-				if (i == '\033') /* ESC */
-				{
-					count = 0;
-					tcurs = MARK_UNSET;
-					break; /* exit from "case CURSOR_CNT_KEY" */
-				}
-				else if (i == ctrl('V'))
-				{
-					i = getkey(0);
-				}
-
-				/* if part of an SDOT command, remember it */
-				 if (keyptr->flags & SDOT
-				 || (prevkey && vikeys[prevkey].flags & SDOT))
-				{
-					dotkey2 = i;
-				}
-
-				/* do it */
-				tcurs = (*keyptr->func)(cursor, count, i);
-			}
-			count = 0L;
-			break;
-	
-		  case CURSOR_MOVED:
-#ifndef NO_VISIBLE
-			if (V_from)
-			{
-				range = cursor;
-				tcurs = V_from;
-				count = 0L;
-				prevkey = key;
-				key = (V_linemd ? 'V' : 'v');
-				keyptr = &vikeys[key];
-			}
-			else
-#endif
-			{
-				prevkey = key;
-				range = cursor;
-				force_flags = LNMD|INCL;
-			}
-			break;
-
-		  case CURSOR_EOL:
-			prevkey = key;
-			/* a zero-length line needs special treatment */
-			pfetch(markline(cursor));
-			if (plen == 0)
-			{
-				/* act on a zero-length section of text */
-				range = tcurs = cursor;
-				key = '0';
-			}
-			else
-			{
-				/* act like CURSOR_MOVED with '$' movement */
-				range = cursor;
-				tcurs = m_rear(cursor, 1L);
-				key = '$';
-			}
-			count = 0L;
-			keyptr = &vikeys[key];
-			break;
-
-		  case CURSOR_TEXT:
-		  	do
-		  	{	
-				text[0] = key;
-				if (vgets(key, text + 1, sizeof text - 1) >= 0)
-				{
-					/* reassure user that <CR> was hit */
-					qaddch('\r');
-					refresh();
-
-					/* call the function with the text */
-					tcurs = (*keyptr->func)(cursor, text);
-				}
-				else
-				{
-					if (exwrote || mode == MODE_COLON)
-					{
-						redraw(MARK_UNSET, FALSE);
-					}
-					mode = MODE_VI;
-				}
-			} while (mode == MODE_COLON);
-			count = 0L;
-			break;
-		}
-
-		/* if that command took us out of vi mode, then exit the loop
-		 * NOW, without tweaking the cursor or anything.  This is very
-		 * important when mode == MODE_QUIT.
-		 */
-		if (mode != MODE_VI)
-		{
-			break;
-		}
-
-		/* now move the cursor, as appropriate */
-		if (keyptr->args == CURSOR_MOVED)
-		{
-			/* the < and > keys have FRNT,
-			 * but it shouldn't be applied yet
-			 */
-			tcurs = adjmove(cursor, tcurs, 0);
-		}
-		else
-		{
-			tcurs = adjmove(cursor, tcurs, (int)keyptr->flags | force_flags);
-		}
-
-		/* was that the end of a d/c/y/</>/! command? */
-		if (prevkey && ((keyptr->flags & MVMT)
-#ifndef NO_VISIBLE
-					       || V_from
-#endif
-				) && count == 0L)
-		{
-#ifndef NO_VISIBLE
-			/* turn off the hilight */
-			V_from = 0L;
-#endif
-
-			/* if the movement command failed, cancel operation */
-			if (tcurs == MARK_UNSET)
-			{
-				prevkey = 0;
-				count = 0;
-				continue;
-			}
-
-			/* make sure range=front and tcurs=rear.  Either way,
-			 * leave cursor=range since that's where we started.
-			 */
-			cursor = range;
-			if (tcurs < range)
-			{
-				range = tcurs;
-				tcurs = cursor;
-			}
-
-			/* The 'w' and 'W' destinations should never take us
-			 * to the front of a line.  Instead, they should take
-			 * us only to the end of the preceding line.
-			 */
-			if ((keyptr->flags & (MVMT|NREL|LNMD|FRNT|INCL)) == MVMT
-			  && markline(range) < markline(tcurs)
-			  && (markline(tcurs) > nlines || tcurs == m_front(tcurs, 0L)))
-			{
-				tcurs = (tcurs & ~(BLKSIZE - 1)) - BLKSIZE;
-				pfetch(markline(tcurs));
-				tcurs += plen;
-			}
-
-			/* adjust for line mode & inclusion of last char/line */
-			i = (keyptr->flags | vikeys[prevkey].flags);
-			switch ((i | force_flags) & (INCL|LNMD))
-			{
-			  case INCL:
-				tcurs++;
-				break;
-
-			  case INCL|LNMD:
-				tcurs += BLKSIZE;
-				/* fall through... */
-
-			  case LNMD:
-				range &= ~(BLKSIZE - 1);
-				tcurs &= ~(BLKSIZE - 1);
-				break;
-			}
-
-			/* run the function */
-			tcurs = (*vikeys[prevkey].func)(range, tcurs);
-			if (mode == MODE_VI)
-			{
-				(void)adjmove(cursor, cursor, 0);
-				cursor = adjmove(cursor, tcurs, (int)vikeys[prevkey].flags);
-			}
-
-			/* cleanup */
-			prevkey = 0;
-		}
-		else if (!prevkey)
-		{
-			if (tcurs != MARK_UNSET)
-				cursor = tcurs;
-		}
-	}
-}
-
-/* This function adjusts the MARK value that they return; here we make sure
- * it isn't past the end of the line, and that the column hasn't been
- * *accidentally* changed.
- */
-MARK adjmove(old, new, flags)
-	MARK		old;	/* the cursor position before the command */
-	REG MARK	new;	/* the cursor position after the command */
-	int		flags;	/* various flags regarding cursor mvmt */
-{
-	static int	colno;	/* the column number that we want */
-	REG char	*text;	/* used to scan through the line's text */
-	REG int		i;
-
-#ifdef DEBUG
-	watch();
-#endif
-
-	/* if the command failed, bag it! */
-	if (new == MARK_UNSET)
-	{
-		beep();
-		return old;
-	}
-
-	/* if this is a non-relative movement, set the '' mark */
-	if (flags & NREL)
-	{
-		mark[26] = old;
-	}
-
-	/* make sure it isn't past the end of the file */
-	if (markline(new) < 1)
-	{
-		new = MARK_FIRST;
-	}
-	else if (markline(new) > nlines)
-	{
-		new = MARK_LAST;
-	}
-
-	/* fetch the new line */
-	pfetch(markline(new));
-
-	/* move to the front, if we're supposed to */
-	if (flags & FRNT)
-	{
-		new = m_front(new, 1L);
-	}
-
-	/* change the column#, or change the mark to suit the column# */
-	if (!(flags & NCOL))
-	{
-		/* change the column# */
-		i = markidx(new);
-		if (i == BLKSIZE - 1)
-		{
-			new &= ~(BLKSIZE - 1);
-			if (plen > 0)
-			{
-				new += plen - 1;
-			}
-			colno = BLKSIZE * 8; /* one heck of a big colno */
-		}
-		else if (plen > 0)
-		{
-			if (i >= plen)
-			{
-				new = (new & ~(BLKSIZE - 1)) + plen - 1;
-			}
-			colno = idx2col(new, ptext, FALSE);
-		}
-		else
-		{
-			new &= ~(BLKSIZE - 1);
-			colno = 0;
-		}
-	}
-	else
-	{
-		/* adjust the mark to get as close as possible to column# */
-		for (i = 0, text = ptext; i <= colno && *text; text++)
-		{
-			if (*text == '\t' && !*o_list)
-			{
-				i += *o_tabstop - (i % *o_tabstop);
-			}
-			else if (UCHAR(*text) < ' ' || *text == 127)
-			{
-				i += 2;
-			}
-#ifndef NO_CHARATTR
-			else if (*o_charattr && text[0] == '\\' && text[1] == 'f' && text[2])
-			{
-				text += 2; /* plus one more in "for()" stmt */
-			}
-#endif
-			else
-			{
-				i++;
-			}
-		}
-		if (text > ptext)
-		{
-			text--;
-		}
-		new = (new & ~(BLKSIZE - 1)) + (int)(text - ptext);
-	}
-
-	return new;
-}
-
-
-#ifdef DEBUG
-watch()
-{
-	static wasset;
-
-	if (*origname)
-	{
-		wasset = TRUE;
-	}
-	else if (wasset)
-	{
-		mode = MODE_EX;
-		msg("origname was clobbered");
-		endwin();
-		abort();
-	}
-
-	if (wasset && nlines == 0)
-	{
-		mode = MODE_EX;
-		msg("nlines=0");
-		endwin();
-		abort();
-	}
-}
-#endif
Index: trunk/minix/commands/elvis/vi.h
===================================================================
--- trunk/minix/commands/elvis/vi.h	(revision 9)
+++ 	(revision )
@@ -1,596 +1,0 @@
-/* vi.h */
-
-/* Author:
- *	Steve Kirkendall
- *	14407 SW Teal Blvd. #C
- *	Beaverton, OR 97005
- *	kirkenda@cs.pdx.edu
- */
-
-#define VERSION "ELVIS 1.5, by Steve Kirkendall (23 March 1992)"
-#define COPYING	"This version of ELVIS is freely redistributable."
-
-#include <errno.h>
-extern int errno;
-#if TOS && !defined(__GNUC__)
-#define ENOENT (-AEFILNF)
-#endif
-
-#if TOS || VMS
-# include <types.h>
-# define O_RDONLY	0
-# define O_WRONLY	1
-# define O_RDWR		2
-# ifdef __GNUC__
-#  define S_IJDIR	S_IFDIR
-# endif
-#else
-# if OSK
-#  include <modes.h>
-#  define O_RDONLY	S_IREAD
-#  define O_WRONLY	S_IWRITE
-#  define O_RDWR	(S_IREAD | S_IWRITE)
-#  define ENOENT	E_PNNF
-#  define sprintf	Sprintf
-# else
-#  include <sys/types.h>
-#  if COHERENT
-#   include <sys/fcntl.h>
-#  else
-#   include <fcntl.h>
-#  endif
-# endif
-#endif
-
-#ifndef O_BINARY
-# define O_BINARY	0
-#endif
-
-#include "curses.h"
-
-#include <signal.h>
-
-/*------------------------------------------------------------------------*/
-/* Miscellaneous constants.						  */
-
-#define INFINITY	2000000001L	/* a very large integer */
-#define LONGKEY		10		/* longest possible raw :map key */
-#ifndef MAXRCLEN
-# define MAXRCLEN	1000		/* longest possible :@ command */
-#endif
-
-/*------------------------------------------------------------------------*/
-/* These describe how temporary files are divided into blocks             */
-
-#define MAXBLKS	(BLKSIZE / sizeof(unsigned short))
-typedef union
-{
-	char		c[BLKSIZE];	/* for text blocks */
-	unsigned short	n[MAXBLKS];	/* for the header block */
-}
-	BLK;
-
-/*------------------------------------------------------------------------*/
-/* These are used manipulate BLK buffers.                                 */
-
-extern BLK	hdr;		/* buffer for the header block */
-extern BLK	*blkget();	/* given index into hdr.c[], reads block */
-extern BLK	*blkadd();	/* inserts a new block into hdr.c[] */
-
-/*------------------------------------------------------------------------*/
-/* These are used to keep track of various flags                          */
-extern struct _viflags
-{
-	short	file;		/* file flags */
-}
-	viflags;
-
-/* file flags */
-#define NEWFILE		0x0001	/* the file was just created */
-#define READONLY	0x0002	/* the file is read-only */
-#define HADNUL		0x0004	/* the file contained NUL characters */
-#define MODIFIED	0x0008	/* the file has been modified, but not saved */
-#define NOFILE		0x0010	/* no name is known for the current text */
-#define ADDEDNL		0x0020	/* newlines were added to the file */
-#define HADBS		0x0040	/* backspace chars were lost from the file */
-#define UNDOABLE	0x0080	/* file has been modified */
-#define NOTEDITED	0x0100	/* the :file command has been used */
-
-/* macros used to set/clear/test flags */
-#define setflag(x,y)	viflags.x |= y
-#define clrflag(x,y)	viflags.x &= ~y
-#define tstflag(x,y)	(viflags.x & y)
-#define initflags()	viflags.file = 0;
-
-/* The options */
-extern char	o_autoindent[1];
-extern char	o_autoprint[1];
-extern char	o_autotab[1];
-extern char	o_autowrite[1];
-extern char	o_columns[3];
-extern char	o_directory[30];
-extern char	o_edcompatible[1];
-extern char	o_equalprg[80];
-extern char	o_errorbells[1];
-extern char	o_exrefresh[1];
-extern char	o_ignorecase[1];
-extern char	o_keytime[3];
-extern char	o_keywordprg[80];
-extern char	o_lines[3];
-extern char	o_list[1];
-extern char	o_number[1];
-extern char	o_readonly[1];
-extern char	o_remap[1];
-extern char	o_report[3];
-extern char	o_scroll[3];
-extern char	o_shell[60];
-extern char	o_shiftwidth[3];
-extern char	o_sidescroll[3];
-extern char	o_sync[1];
-extern char	o_tabstop[3];
-extern char	o_term[30];
-extern char	o_flash[1];
-extern char	o_warn[1];
-extern char	o_wrapscan[1];
-
-#ifndef CRUNCH
-extern char	o_beautify[1];
-extern char	o_exrc[1];
-extern char	o_mesg[1];
-extern char	o_more[1];
-extern char	o_novice[1];
-extern char	o_prompt[1];
-extern char	o_taglength[3];
-extern char	o_terse[1];
-extern char	o_window[3];
-extern char	o_wrapmargin[3];
-extern char	o_writeany[1];
-#endif
-
-#ifndef NO_ERRLIST
-extern char	o_cc[30];
-extern char	o_make[30];
-#endif
-
-#ifndef NO_CHARATTR
-extern char	o_charattr[1];
-#endif
-
-#ifndef NO_DIGRAPH
-extern char	o_digraph[1];
-extern char	o_flipcase[80];
-#endif
-
-#ifndef NO_SENTENCE
-extern char	o_hideformat[1];
-#endif
-
-#ifndef NO_EXTENSIONS
-extern char	o_inputmode[1];
-extern char	o_ruler[1];
-#endif
-
-#ifndef NO_MAGIC
-extern char	o_magic[1];
-#endif
-
-#ifndef NO_MODELINES
-extern char	o_modelines[1];
-#endif
-
-#ifndef NO_SENTENCE
-extern char	o_paragraphs[30];
-extern char	o_sections[30];
-#endif
-
-#if MSDOS
-extern char	o_pcbios[1];
-#endif
-
-#ifndef NO_SHOWMATCH
-extern char	o_showmatch[1];
-#endif
-
-#ifndef	NO_SHOWMODE
-extern char	o_smd[1];
-#endif
-
-/*------------------------------------------------------------------------*/
-/* These help support the single-line multi-change "undo" -- shift-U      */
-
-extern char	U_text[BLKSIZE];
-extern long	U_line;
-
-/*------------------------------------------------------------------------*/
-/* These are used to refer to places in the text 			  */
-
-typedef long	MARK;
-#define markline(x)	(long)((x) / BLKSIZE)
-#define markidx(x)	(int)((x) & (BLKSIZE - 1))
-#define MARK_UNSET	((MARK)0)
-#define MARK_FIRST	((MARK)BLKSIZE)
-#define MARK_LAST	((MARK)(nlines * BLKSIZE))
-#define MARK_AT_LINE(x)	((MARK)(x) * BLKSIZE)
-
-#define NMARKS	29
-extern MARK	mark[NMARKS];	/* marks a-z, plus mark ' and two temps */
-extern MARK	cursor;		/* mark where line is */
-
-/*------------------------------------------------------------------------*/
-/* These are used to keep track of the current & previous files.	  */
-
-extern long	origtime;	/* modification date&time of the current file */
-extern char	origname[256];	/* name of the current file */
-extern char	prevorig[256];	/* name of the preceding file */
-extern long	prevline;	/* line number from preceding file */
-
-/*------------------------------------------------------------------------*/
-/* misc housekeeping variables & functions				  */
-
-extern int	tmpfd;		/* fd used to access the tmp file */
-extern int	tmpnum;		/* counter used to generate unique filenames */
-extern long	lnum[MAXBLKS];	/* last line# of each block */
-extern long	nlines;		/* number of lines in the file */
-extern char	args[BLKSIZE];	/* file names given on the command line */
-extern int	argno;		/* the current element of args[] */
-extern int	nargs;		/* number of filenames in args */
-extern long	changes;	/* counts changes, to prohibit short-cuts */
-extern int	significant;	/* boolean: was a *REAL* change made? */
-extern BLK	tmpblk;		/* a block used to accumulate changes */
-extern long	topline;	/* file line number of top line */
-extern int	leftcol;	/* column number of left col */
-#define		botline	 (topline + LINES - 2)
-#define		rightcol (leftcol + COLS - (*o_number ? 9 : 1))
-extern int	physcol;	/* physical column number that cursor is on */
-extern int	physrow;	/* physical row number that cursor is on */
-extern int	exwrote;	/* used to detect verbose ex commands */
-extern int	doingdot;	/* boolean: are we doing the "." command? */
-extern int	doingglobal;	/* boolean: are doing a ":g" command? */
-extern long	rptlines;	/* number of lines affected by a command */
-extern char	*rptlabel;	/* description of how lines were affected */
-extern char	*fetchline();	/* read a given line from tmp file */
-extern char	*parseptrn();	/* isolate a regexp in a line */
-extern MARK	paste();	/* paste from cut buffer to a given point */
-extern char	*wildcard();	/* expand wildcards in filenames */
-extern MARK	input();	/* inserts characters from keyboard */
-extern char	*linespec();	/* finds the end of a /regexp/ string */
-#define		ctrl(ch) ((ch)&037)
-#ifndef NO_RECYCLE
-extern long	allocate();	/* allocate a free block of the tmp file */
-#endif
-extern int	trapint();	/* trap handler for SIGINT */
-extern int	deathtrap();	/* trap handler for deadly signals */
-extern void	blkdirty();	/* marks a block as being "dirty" */
-extern void	blkflush();	/* writes a single dirty block to the disk */
-extern void	blksync();	/* forces all "dirty" blocks to disk */
-extern void	blkinit();	/* resets the block cache to "empty" state */
-extern void	beep();		/* rings the terminal's bell */
-extern void	exrefresh();	/* writes text to the screen */
-extern void	msg();		/* writes a printf-style message to the screen */
-extern void	endmsgs();	/* if "manymsgs" is set, then scroll up 1 line */
-extern void	garbage();	/* reclaims any garbage blocks */
-extern void	redraw();	/* updates the screen after a change */
-extern void	resume_curses();/* puts the terminal in "cbreak" mode */
-extern void	beforedo();	/* saves current revision before a new change */
-extern void	afterdo();	/* marks end of a beforedo() change */
-extern void	abortdo();	/* like "afterdo()" followed by "undo()" */
-extern int	undo();		/* restores file to previous undo() */
-extern void	dumpkey();	/* lists key mappings to the screen */
-extern void	mapkey();	/* defines a new key mapping */
-extern void	savekeys();	/* lists key mappings to a file */
-extern void	redrawrange();	/* records clues from modify.c */
-extern void	cut();		/* saves text in a cut buffer */
-extern void	delete();	/* deletes text */
-extern void	add();		/* adds text */
-extern void	change();	/* deletes text, and then adds other text */
-extern void	cutswitch();	/* updates cut buffers when we switch files */
-extern void	do_abbr();	/* defines or lists abbreviations */
-extern void	do_digraph();	/* defines or lists digraphs */
-extern void	exstring();	/* execute a string as EX commands */
-extern void	dumpopts();
-extern void	setopts();
-extern void	saveopts();
-extern void	savedigs();
-extern void	saveabbr();
-extern void	savecolor();
-extern void	cutname();
-extern void	cutname();
-extern void	initopts();
-extern void	cutend();
-#ifndef CRUNCH
-extern int	wset;		/* boolean: has the "window" size been set? */
-#endif
-
-/*------------------------------------------------------------------------*/
-/* macros that are used as control structures                             */
-
-#define BeforeAfter(before, after) for((before),bavar=1;bavar;(after),bavar=0)
-#define ChangeText	BeforeAfter(beforedo(FALSE),afterdo())
-
-extern int	bavar;		/* used only in BeforeAfter macros */
-
-/*------------------------------------------------------------------------*/
-/* These are the movement commands.  Each accepts a mark for the starting */
-/* location & number and returns a mark for the destination.		  */
-
-extern MARK	m_updnto();		/* k j G */
-extern MARK	m_right();		/* h */
-extern MARK	m_left();		/* l */
-extern MARK	m_tocol();		/* | */
-extern MARK	m_front();		/* ^ */
-extern MARK	m_rear();		/* $ */
-extern MARK	m_fword();		/* w */
-extern MARK	m_bword();		/* b */
-extern MARK	m_eword();		/* e */
-extern MARK	m_paragraph();		/* { } [[ ]] */
-extern MARK	m_match();		/* % */
-#ifndef NO_SENTENCE
- extern MARK	m_sentence();		/* ( ) */
-#endif
-extern MARK	m_tomark();		/* 'm */
-#ifndef NO_EXTENSIONS
-extern MARK	m_wsrch();		/* ^A */
-#endif
-extern MARK	m_nsrch();		/* n */
-extern MARK	m_Nsrch();		/* N */
-extern MARK	m_fsrch();		/* /regexp */
-extern MARK	m_bsrch();		/* ?regexp */
-#ifndef NO_CHARSEARCH
- extern MARK	m__ch();		/* ; , */
- extern MARK	m_fch();		/* f */
- extern MARK	m_tch();		/* t */
- extern MARK	m_Fch();		/* F */
- extern MARK	m_Tch();		/* T */
-#endif
-extern MARK	m_row();		/* H L M */
-extern MARK	m_z();			/* z */
-extern MARK	m_scroll();		/* ^B ^F ^E ^Y ^U ^D */
-
-/* Some stuff that is used by movement functions... */
-
-extern MARK	adjmove();		/* a helper fn, used by move fns */
-
-/* This macro is used to set the default value of cnt */
-#define DEFAULT(val)	if (cnt < 1) cnt = (val)
-
-/* These are used to minimize calls to fetchline() */
-extern int	plen;	/* length of the line */
-extern long	pline;	/* line number that len refers to */
-extern long	pchgs;	/* "changes" level that len refers to */
-extern char	*ptext;	/* text of previous line, if valid */
-extern void	pfetch();
-extern char	digraph();
-
-/* This is used to build a MARK that corresponds to a specific point in the
- * line that was most recently pfetch'ed.
- */
-#define buildmark(text)	(MARK)(BLKSIZE * pline + (int)((text) - ptext))
-
-
-/*------------------------------------------------------------------------*/
-/* These are used to handle EX commands.				  */
-
-#define  CMD_NULL	0	/* NOT A VALID COMMAND */
-#define  CMD_ABBR	1	/* "define an abbreviation" */
-#define  CMD_ARGS	2	/* "show me the args" */
-#define  CMD_APPEND	3	/* "insert lines after this line" */
-#define  CMD_AT		4	/* "execute a cut buffer's contents via EX" */
-#define  CMD_BANG	5	/* "run a single shell command" */
-#define  CMD_CC		6	/* "run `cc` and then do CMD_ERRLIST" */
-#define  CMD_CD		7	/* "change directories" */
-#define  CMD_CHANGE	8	/* "change some lines" */
-#define	 CMD_COLOR	9	/* "change the default colors" */
-#define  CMD_COPY	10	/* "copy the selected text to a given place" */
-#define  CMD_DELETE	11	/* "delete the selected text" */
-#define  CMD_DIGRAPH	12	/* "add a digraph, or display them all" */
-#define  CMD_EDIT	13	/* "switch to a different file" */
-#define  CMD_EQUAL	14	/* "display a line number" */
-#define  CMD_ERRLIST	15	/* "locate the next error in a list" */
-#define  CMD_FILE	16	/* "show the file's status" */
-#define  CMD_GLOBAL	17	/* "globally search & do a command" */
-#define  CMD_INSERT	18	/* "insert lines before the current line" */
-#define  CMD_JOIN	19	/* "join the selected line & the one after" */
-#define  CMD_LIST	20	/* "print lines, making control chars visible" */
-#define  CMD_MAKE	21	/* "run `make` and then do CMD_ERRLIST" */
-#define  CMD_MAP	22	/* "adjust the keyboard map" */
-#define  CMD_MARK	23	/* "mark this line" */
-#define  CMD_MKEXRC	24	/* "make a .exrc file" */
-#define  CMD_MOVE	25	/* "move the selected text to a given place" */
-#define  CMD_NEXT	26	/* "switch to next file in args" */
-#define  CMD_NUMBER	27	/* "print lines from the file w/ line numbers" */
-#define  CMD_PRESERVE	28	/* "act as though vi crashed" */
-#define  CMD_PREVIOUS	29	/* "switch to the previous file in args" */
-#define  CMD_PRINT	30	/* "print the selected text" */
-#define  CMD_PUT	31	/* "insert any cut lines before this line" */
-#define  CMD_QUIT	32	/* "quit without writing the file" */
-#define  CMD_READ	33	/* "append the given file after this line */
-#define  CMD_RECOVER	34	/* "recover file after vi crashes" - USE -r FLAG */
-#define  CMD_REWIND	35	/* "rewind to first file" */
-#define  CMD_SET	36	/* "set a variable's value" */
-#define  CMD_SHELL	37	/* "run some lines through a command" */
-#define  CMD_SHIFTL	38	/* "shift lines left" */
-#define  CMD_SHIFTR	39	/* "shift lines right" */
-#define  CMD_SOURCE	40	/* "interpret a file's contents as ex commands" */
-#define  CMD_STOP	41	/* same as CMD_SUSPEND */
-#define  CMD_SUBAGAIN	42	/* "repeat the previous substitution" */
-#define  CMD_SUBSTITUTE	43	/* "substitute text in this line" */
-#define  CMD_SUSPEND	44	/* "suspend the vi session" */
-#define  CMD_TR		45	/* "transliterate chars in the selected lines" */
-#define  CMD_TAG	46	/* "go to a particular tag" */
-#define  CMD_UNABBR	47	/* "remove an abbreviation definition" */
-#define  CMD_UNDO	48	/* "undo the previous command" */
-#define  CMD_UNMAP	49	/* "remove a key sequence map */
-#define  CMD_VERSION	50	/* "describe which version this is" */
-#define  CMD_VGLOBAL	51	/* "apply a cmd to lines NOT containing an RE" */
-#define  CMD_VISUAL	52	/* "go into visual mode" */
-#define  CMD_WQUIT	53	/* "write this file out (any case) & quit" */
-#define  CMD_WRITE	54	/* "write the selected(?) text to a given file" */
-#define  CMD_XIT	55	/* "write this file out (if modified) & quit" */
-#define  CMD_YANK	56	/* "copy the selected text into the cut buffer" */
-#ifdef DEBUG
-# define CMD_DEBUG	57	/* access to internal data structures */
-# define CMD_VALIDATE	58	/* check for internal consistency */
-#endif
-typedef int CMD;
-
-extern void	ex();
-extern void	vi();
-extern void	doexcmd();
-
-extern void	cmd_append();
-extern void	cmd_args();
-#ifndef NO_AT
-extern void	cmd_at();
-#endif
-extern void	cmd_cd();
-#ifndef NO_COLOR
-extern void	cmd_color();
-#endif
-extern void	cmd_delete();
-#ifndef NO_DIGRAPH
-extern void	cmd_digraph();
-#endif
-extern void	cmd_edit();
-#ifndef NO_ERRLIST
-extern void	cmd_errlist();
-#endif
-extern void	cmd_file();
-extern void	cmd_global();
-extern void	cmd_join();
-extern void	cmd_mark();
-#ifndef NO_ERRLIST
-extern void	cmd_make();
-#endif
-extern void	cmd_map();
-#ifndef NO_MKEXRC
-extern void	cmd_mkexrc();
-#endif
-extern void	cmd_next();
-extern void	cmd_print();
-extern void	cmd_put();
-extern void	cmd_read();
-extern void	cmd_set();
-extern void	cmd_shell();
-extern void	cmd_shift();
-extern void	cmd_source();
-extern void	cmd_substitute();
-extern void	cmd_tag();
-extern void	cmd_undo();
-extern void	cmd_version();
-extern void	cmd_write();
-extern void	cmd_xit();
-extern void	cmd_move();
-#ifdef DEBUG
-extern void	cmd_debug();
-extern void	cmd_validate();
-#endif
-#ifdef SIGTSTP
-extern void	cmd_suspend();
-#endif
-
-/*----------------------------------------------------------------------*/
-/* These are used to handle VI commands 				*/
-
-extern MARK	v_1ex();	/* : */
-extern MARK	v_mark();	/* m */
-extern MARK	v_quit();	/* Q */
-extern MARK	v_redraw();	/* ^L ^R */
-extern MARK	v_ulcase();	/* ~ */
-extern MARK	v_undo();	/* u */
-extern MARK	v_xchar();	/* x X */
-extern MARK	v_replace();	/* r */
-extern MARK	v_overtype();	/* R */
-extern MARK	v_selcut();	/* " */
-extern MARK	v_paste();	/* p P */
-extern MARK	v_yank();	/* y Y */
-extern MARK	v_delete();	/* d D */
-extern MARK	v_join();	/* J */
-extern MARK	v_insert();	/* a A i I o O */
-extern MARK	v_change();	/* c C */
-extern MARK	v_subst();	/* s */
-extern MARK	v_lshift();	/* < */
-extern MARK	v_rshift();	/* > */
-extern MARK	v_reformat();	/* = */
-extern MARK	v_filter();	/* ! */
-extern MARK	v_status();	/* ^G */
-extern MARK	v_switch();	/* ^^ */
-extern MARK	v_tag();	/* ^] */
-extern MARK	v_xit();	/* ZZ */
-extern MARK	v_undoline();	/* U */
-extern MARK	v_again();	/* & */
-#ifndef NO_EXTENSIONS
- extern MARK	v_keyword();	/* K */
- extern MARK	v_increment();	/* * */
-#endif
-#ifndef NO_ERRLIST
- extern MARK	v_errlist();	/* * */
-#endif
-#ifndef NO_AT
- extern MARK	v_at();		/* @ */
-#endif
-#ifdef SIGTSTP
- extern MARK	v_suspend();	/* ^Z */
-#endif
-#ifndef NO_POPUP
- extern MARK	v_popup();	/* \ */
-#endif
-
-/*----------------------------------------------------------------------*/
-/* These flags describe the quirks of the individual visual commands */
-#define NO_FLAGS	0x00
-#define	MVMT		0x01	/* this is a movement command */
-#define PTMV		0x02	/* this can be *part* of a movement command */
-#define FRNT		0x04	/* after move, go to front of line */
-#define INCL		0x08	/* include last char when used with c/d/y */
-#define LNMD		0x10	/* use line mode of c/d/y */
-#define NCOL		0x20	/* this command can't change the column# */
-#define NREL		0x40	/* this is "non-relative" -- set the '' mark */
-#define SDOT		0x80	/* set the "dot" variables, for the "." cmd */
-#ifndef NO_VISIBLE
-# define VIZ		0x100	/* commands which can be used with 'v' */
-#else
-# define VIZ		0
-#endif
-
-/* This variable is zeroed before a command executes, and later ORed with the
- * command's flags after the command has been executed.  It is used to force
- * certain flags to be TRUE for *some* invocations of a particular command.
- * For example, "/regexp/+offset" forces the LNMD flag, and sometimes a "p"
- * or "P" command will force FRNT.
- */
-extern int	force_flags;
-
-/*----------------------------------------------------------------------*/
-/* These describe what mode we're in */
-
-#define MODE_EX		1	/* executing ex commands */
-#define	MODE_VI		2	/* executing vi commands */
-#define	MODE_COLON	3	/* executing an ex command from vi mode */
-#define	MODE_QUIT	4
-extern int	mode;
-
-#define WHEN_VICMD	1	/* getkey: we're reading a VI command */
-#define WHEN_VIINP	2	/* getkey: we're in VI's INPUT mode */
-#define WHEN_VIREP	4	/* getkey: we're in VI's REPLACE mode */
-#define WHEN_EX		8	/* getkey: we're in EX mode */
-#define WHEN_MSG	16	/* getkey: we're at a "more" prompt */
-#define WHEN_POPUP	32	/* getkey: we're in the pop-up menu */
-#define WHEN_REP1	64	/* getkey: we're getting a single char for 'r' */
-#define WHEN_CUT	128	/* getkey: we're getting a cut buffer name */
-#define WHEN_MARK	256	/* getkey: we're getting a mark name */
-#define WHEN_CHAR	512	/* getkey: we're getting a destination for f/F/t/T */
-#define WHEN_INMV	4096	/* in input mode, interpret the key in VICMD mode */
-#define WHEN_FREE	8192	/* free the keymap after doing it once */
-#define WHENMASK	(WHEN_VICMD|WHEN_VIINP|WHEN_VIREP|WHEN_REP1|WHEN_CUT|WHEN_MARK|WHEN_CHAR)
-
-#ifndef NO_VISIBLE
-extern MARK	V_from;
-extern int	V_linemd;
-extern MARK	v_start();
-#endif
-
-#ifdef DEBUG
-# define malloc(size)	dbmalloc(size, __FILE__, __LINE__)
-# define free(ptr)	dbfree(ptr, __FILE__, __LINE__)
-extern char *dbmalloc();
-#endif
Index: trunk/minix/commands/ftp/Makefile
===================================================================
--- trunk/minix/commands/ftp/Makefile	(revision 9)
+++ 	(revision )
@@ -1,33 +1,0 @@
-# Makefile for ftp
-#
-# 01/25/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
-#
-
-CFLAGS=	-O -D_MINIX -D_POSIX_SOURCE
-LDFLAGS=-i
-BINDIR=/usr/bin
-PROG=	ftp
-
-OBJS=	ftp.o local.o file.o other.o net.o
-
-all:	$(PROG)
-
-CC = exec cc
-
-$(PROG):	$(OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(OBJS)
-	install -S 8kw $@
-
-clean:
-	rm -f $(PROG) $(OBJS)
-
-install:	$(BINDIR)/$(PROG)
-
-$(BINDIR)/$(PROG):	$(PROG)
-	install -cs -o bin $? $@
-
-ftp.o:		ftp.c	ftp.h	local.h	file.h	other.h	net.h
-local.o:	local.c	ftp.h	local.h
-file.o:		file.c	ftp.h		file.h		net.h
-other.o:	other.c	ftp.h			other.h
-net.o:		net.c	ftp.h		file.h		net.h
Index: trunk/minix/commands/ftp/build
===================================================================
--- trunk/minix/commands/ftp/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/ftp/file.c
===================================================================
--- trunk/minix/commands/ftp/file.c	(revision 9)
+++ 	(revision )
@@ -1,922 +1,0 @@
-/* file.c
- *
- * This file is part of ftp.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include "ftp.h"
-#include "file.h"
-#include "net.h"
-
-_PROTOTYPE(static char *dir, (char *path, int full));
-_PROTOTYPE(static int asciisend, (int fd, int fdout));
-_PROTOTYPE(static int binarysend, (int fd, int fdout));
-_PROTOTYPE(static int asciirecv, (int fd, int fdin));
-_PROTOTYPE(static int binaryrecv, (int fd, int fdin));
-_PROTOTYPE(static int asciisize, (int fd, off_t *filesize));
-_PROTOTYPE(static off_t asciisetsize, (int fd, off_t filesize));
-
-static char buffer[512 << sizeof(char *)];
-static char bufout[512 << sizeof(char *)];
-static char line2[512];
-
-static char *dir(path, full)
-char *path;
-int full;
-{
-char cmd[128];
-static char name[32];
-
-   tmpnam(name);
-
-   if(full)
-	sprintf(cmd, "ls -l %s > %s", path, name);
-   else
-	sprintf(cmd, "ls %s > %s", path, name);
-
-   system(cmd);
-
-   return(name);
-}
-
-static int asciisend(fd, fdout)
-int fd;
-int fdout;
-{
-int s, len;
-char c;
-char *p;
-char *op, *ope;
-unsigned long total=0L;
-
-   if(atty) {
-	printf("Sent ");
-	fflush(stdout);
-   }
-
-   op = bufout;
-   ope = bufout + sizeof(bufout) - 3;
-
-   while((s = read(fd, buffer, sizeof(buffer))) > 0) {
-	total += (long)s;
-	p = buffer;
-	while(s-- > 0) {
-		c = *p++;
-		if(c == '\r') {
-			*op++ = '\r';
-			total++;
-		}
-		*op++ = c;
-		if(op >= ope) {
-			write(fdout, bufout, op - bufout);
-			op = bufout;
-		}
-	}
-	if(atty) {
-		printf("%9lu bytes\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", total);
-		fflush(stdout);
-	}
-   }
-   if(op > bufout)
-	write(fdout, bufout, op - bufout);
-   if(atty) {
-	printf("\n");
-	fflush(stdout);
-   }
-
-   return(s);
-}
-
-static int binarysend(fd, fdout)
-int fd;
-int fdout;
-{
-int s;
-unsigned long total=0L;
-
-   if(atty) {
-	printf("Sent ");
-	fflush(stdout);
-   }
-
-   while((s = read(fd, buffer, sizeof(buffer))) > 0) {
-	write(fdout, buffer, s);
-	total += (long)s;
-	if(atty) {
-		printf("%9lu bytes\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", total);
-		fflush(stdout);
-	}
-   }
-   if(atty) {
-	printf("\n");
-	fflush(stdout);
-   }
-
-   return(s);
-}
-
-int sendfile(fd, fdout)
-int fd;
-int fdout;
-{
-int s;
-
-   switch(type) {
-	case TYPE_A:
-		s = asciisend(fd, fdout);
-		break;
-	default:
-		s = binarysend(fd, fdout);
-   }
-
-   if(s < 0)
-	return(-1);
-   else
-	return(0);
-}
-
-static int asciirecv(fd, fdin)
-int fd;
-int fdin;
-{
-int s, len;
-int gotcr;
-char c;
-char *p;
-char *op, *ope;
-unsigned long total=0L;
-
-   if(isatty && fd > 2) {
-	printf("Received ");
-	fflush(stdout);
-   }
-   gotcr = 0;
-   op = bufout; ope = bufout + sizeof(bufout) - 3;
-   while((s = read(fdin, buffer, sizeof(buffer))) > 0) {
-	p = buffer;
-	total += (long)s;
-	while(s-- > 0) {
-		c = *p++;
-		if(gotcr) {
-			gotcr = 0;
-			if(c != '\n')
-				*op++ = '\r';
-		}
-		if(c == '\r')
-			gotcr = 1;
-		else
-			*op++ = c;
-		if(op >= ope) {
-			write(fd, bufout, op - bufout);
-			op = bufout;
-		}
-	}
-	if(atty && fd > 2) {
-		printf("%9lu bytes\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", total);
-		fflush(stdout);
-	}
-   }
-   if(gotcr)
-	*op++ = '\r';
-   if(op > bufout)
-	write(fd, bufout, op - bufout);
-   if(atty && fd > 2) {
-	printf("\n");
-	fflush(stdout);
-   }
-   return(s);
-}
-
-static binaryrecv(fd, fdin)
-int fd;
-int fdin;
-{
-int s;
-unsigned long total=0L;
-
-   if(atty && fd > 2) {
-	printf("Received ");
-	fflush(stdout);
-   }
-   while((s = read(fdin, buffer, sizeof(buffer))) > 0) {
-	write(fd, buffer, s);
-	total += (long)s;
-	if(atty && fd > 2) {
-		printf("%9lu bytes\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", total);
-		fflush(stdout);
-	}
-   }
-   if(atty && fd > 2) {
-	printf("\n");
-	fflush(stdout);
-   }
-   return(s);
-}
-
-int recvfile(fd, fdin)
-int fd;
-int fdin;
-{
-int s;
-
-   switch(type) {
-	case TYPE_A:
-		s = asciirecv(fd, fdin);
-		break;
-	default:
-		s = binaryrecv(fd, fdin);
-   }
-
-   if(s < 0)
-	return(-1);
-   else
-	return(0);
-}
-
-int DOascii()
-{
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   s = DOcommand("TYPE", "A");
-
-   type = TYPE_A;
-
-   return(s);
-}
-
-int DObinary()
-{
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   s = DOcommand("TYPE", "I");
-
-   type = TYPE_I;
-
-   return(s);
-}
-
-int DOpwd()
-{
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   s = DOcommand("PWD", "");
-
-   if(s == 500 || s == 502)
-	s = DOcommand("XPWD", "");
-
-   return(s);
-}
-
-int DOcd()
-{
-char *path;
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   path = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Path: ", line2, sizeof(line2));
-	path = line2;
-   }
-
-   if(!strcmp(path, ".."))
-   	s = DOcommand("CDUP", "");
-   else
-   	s = DOcommand("CWD", path);
-
-   if(s == 500 || s == 502) {
-	if(!strcmp(path, ".."))
-		s = DOcommand("XCUP", "");
-	else
-		s = DOcommand("XCWD", path);
-   }
-
-   return(s);
-}
-
-int DOmkdir()
-{
-char *path;
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   path = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Directory: ", line2, sizeof(line2));
-	path = line2;
-   }
-
-   s = DOcommand("MKD", path);
-
-   if(s == 500 || s == 502)
-	s = DOcommand("XMKD", path);
-
-   return(s);
-}
-
-int DOrmdir()
-{
-char *path;
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   path = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Directory: ", line2, sizeof(line2));
-	path = line2;
-   }
-
-   s = DOcommand("RMD", path);
-
-   if(s == 500 || s == 502)
-	s = DOcommand("XRMD", path);
-
-   return(s);
-}
-
-int DOdelete()
-{
-char *file;
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   return(DOcommand("DELE", file));
-}
-
-int DOmdtm()
-{
-char *file;
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   return(DOcommand("MDTM", file));
-}
-
-int DOsize()
-{
-char *file;
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   return(DOcommand("SIZE", file));
-}
-
-int DOstat()
-{
-char *file;
-
-   if(cmdargc < 2)
-	if(!linkopen) {
-		printf("You must \"OPEN\" a connection first.\n");
-		return(0);
-	} else
-		return(DOcommand("STAT", ""));
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   return(DOcommand("STAT", file));
-}
-
-int DOlist()
-{
-char *path;
-char *local;
-int fd;
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   path = cmdargv[1];
-
-   if(cmdargc < 2)
-	path = "";
-
-   if(cmdargc < 3)
-	local = "";
-   else
-	local = cmdargv[2];
-
-   if(*local == '\0')
-	fd = 1;
-   else
-	fd = open(local, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-
-   if(fd < 0) {
-	printf("Could not open local file %s. Error %s\n", local, strerror(errno));
-	return(0);
-   }
-
-   s = DOdata("LIST", path, RETR, fd);
-
-   if(fd > 2)
-	close(fd);
-
-   return(s);
-}
-
-int DOnlst()
-{
-char *path;
-char *local;
-int fd;
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   path = cmdargv[1];
-
-   if(cmdargc < 2)
-	path = "";
-
-   if(cmdargc < 3)
-	local = "";
-   else
-	local = cmdargv[2];
-
-   if(*local == '\0')
-	fd = 1;
-   else
-	fd = open(local, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-
-   if(fd < 0) {
-	printf("Could not open local file %s. Error %s\n", local, strerror(errno));
-	return(0);
-   }
-
-   s = DOdata("NLST", path, RETR, fd);
-
-   if(fd > 2)
-	close(fd);
-
-   return(s);
-}
-
-int DOretr()
-{
-char *file, *localfile;
-int fd;
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Remote File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   if(cmdargc < 3)
-	localfile = file;
-   else
-	localfile = cmdargv[2];
-
-   fd = open(localfile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-
-   if(fd < 0) {
-	printf("Could not open local file %s. Error %s\n", localfile, strerror(errno));
-	return(0);
-   }
-
-   s = DOdata("RETR", file, RETR, fd);
-
-   close(fd);
-
-   return(s);
-}
-
-int DOrretr()
-{
-char *file, *localfile;
-int fd;
-int s;
-off_t filesize;
-char restart[16];
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Remote File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   if(cmdargc < 3)
-	localfile = file;
-   else
-	localfile = cmdargv[2];
-
-   fd = open(localfile, O_RDWR);
-
-   if(fd < 0) {
-	printf("Could not open local file %s. Error %s\n", localfile, strerror(errno));
-	return(0);
-   }
-
-   if(type == TYPE_A) {
-   	if(asciisize(fd, &filesize)) {
-   		printf("Could not determine ascii file size of %s\n", localfile);
-   		close(fd);
-   		return(0);
-   	}
-   } else
-	filesize = lseek(fd, 0, SEEK_END);
-
-   sprintf(restart, "%lu", filesize);
-
-   s = DOcommand("REST", restart);
-
-   if(s != 350) {
-   	close(fd);
-   	return(s);
-   }
-
-   s = DOdata("RETR", file, RETR, fd);
-
-   close(fd);
-
-   return(s);
-}
-
-int DOMretr()
-{
-char *files;
-int fd, s;
-FILE *fp;
-char name[32];
-
-   if(DOcmdcheck())
-	return(0);
-
-   files = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Files: ", line2, sizeof(line2));
-	files = line2;
-   }
-
-   tmpnam(name);
-
-   fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-
-   if(fd < 0) {
-	printf("Could not open local file %s. Error %s\n", name, strerror(errno));
-	return(0);
-   }
-
-   s = DOdata("NLST", files, RETR, fd);
-
-   close(fd);
-
-   if(s == 226) {
-	fp = fopen(name, "r");
-	unlink(name);
-	if(fp == (FILE *)NULL) {
-		printf("Unable to open file listing.\n");
-		return(0);
-	}
-	while(fgets(line2, sizeof(line2), fp) != (char *)NULL) {
-		line2[strlen(line2)-1] = '\0';
-		printf("Retrieving file: %s\n", line2); fflush(stdout);
-		fd = open(line2, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-		if(fd < 0)
-			printf("Unable to open local file %s\n", line2);
-		else {
-			s = DOdata("RETR", line2, RETR, fd);
-			close(fd);
-			if(s < 0) break;
-		}
-	}
-	fclose(fp);
-   } else
-	unlink(name);
-
-   return(s);
-}
-
-int DOappe()
-{
-char *file, *remotefile;
-int fd;
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Local File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   if(cmdargc < 3)
-	remotefile = file;
-   else
-	remotefile = cmdargv[2];
-
-   fd = open(file, O_RDONLY);
-
-   if(fd < 0) {
-	printf("Could not open local file %s. Error %s\n", file, strerror(errno));
-	return(0);
-   }
-
-   s = DOdata("APPE", remotefile, STOR, fd);
-
-   close(fd);
-
-   return(s);
-}
-
-int DOstor()
-{
-char *file, *remotefile;
-int fd;
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Local File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   if(cmdargc < 3)
-	remotefile = file;
-   else
-	remotefile = cmdargv[2];
-
-   fd = open(file, O_RDONLY);
-
-   if(fd < 0) {
-	printf("Could not open local file %s. Error %s\n", file, strerror(errno));
-	return(0);
-   }
-
-   s = DOdata("STOR", remotefile, STOR, fd);
-
-   close(fd);
-
-   return(s);
-}
-
-int DOrstor()
-{
-char *file, *remotefile;
-int fd;
-int s;
-off_t filesize, rmtsize;
-char restart[16];
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Local File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   if(cmdargc < 3)
-	remotefile = file;
-   else
-	remotefile = cmdargv[2];
-
-   s = DOcommand("SIZE", remotefile);
-
-   if(s != 215)
-   	return(s);
-
-   rmtsize = atol(reply+4);
-
-   fd = open(file, O_RDONLY);
-
-   if(fd < 0) {
-	printf("Could not open local file %s. Error %s\n", file, strerror(errno));
-	return(0);
-   }
-
-   if(type == TYPE_A)
-   	filesize = asciisetsize(fd, rmtsize);
-   else
-	filesize = lseek(fd, rmtsize, SEEK_SET);
-
-   if(filesize != rmtsize) {
-	printf("Could not set file start of %s\n", file);
-   	close(fd);
-   	return(0);
-   }
-
-   sprintf(restart, "%lu", rmtsize);
-
-   s = DOcommand("REST", restart);
-
-   if(s != 350) {
-   	close(fd);
-   	return(s);
-   }
-
-   s = DOdata("STOR", remotefile, STOR, fd);
-
-   close(fd);
-
-   return(s);
-}
-
-int DOstou()
-{
-char *file, *remotefile;
-int fd;
-int s;
-
-   if(DOcmdcheck())
-	return(0);
-
-   file = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Local File: ", line2, sizeof(line2));
-	file = line2;
-   }
-
-   if(cmdargc < 3)
-	remotefile = file;
-   else
-	remotefile = cmdargv[2];
-
-   fd = open(file, O_RDONLY);
-
-   if(fd < 0) {
-	printf("Could not open local file %s. Error %s\n", file, strerror(errno));
-	return(0);
-   }
-
-   s = DOdata("STOU", remotefile, STOR, fd);
-
-   close(fd);
-
-   return(s);
-}
-
-int DOMstor()
-{
-char *files;
-char *name;
-int fd, s;
-FILE *fp;
-
-   if(DOcmdcheck())
-	return(0);
-
-   files = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Files: ", line2, sizeof(line2));
-	files = line2;
-   }
-
-   name = dir(files, 0);
-
-   fp = fopen(name, "r");
-
-   if(fp == (FILE *)NULL) {
-	printf("Unable to open listing file.\n");
-	return(0);
-   }
-
-   while(fgets(line2, sizeof(line2), fp) != (char *)NULL) {
-	line2[strlen(line2)-1] = '\0';
-	printf("Sending file: %s\n", line2); fflush(stdout);
-	fd = open(line2, O_RDONLY);
-	if(fd < 0)
-		printf("Unable to open local file %s\n", line2);
-	else {
-		s = DOdata("STOR", line2, STOR, fd);
-		close(fd);
-		if(s < 0) break;
-	}
-   }
-   fclose(fp);
-   unlink(name);
-
-   return(s);
-}
-
-static int asciisize(fd, filesize)
-int fd;
-off_t *filesize;
-{
-unsigned long count;
-char *p, *pp;
-int cnt;
-
-   count = 0;
-
-   while((cnt = read(fd, buffer, sizeof(buffer))) > 0) {
-	p = buffer; pp = buffer + cnt;
-	count += cnt;
-	while(p < pp)
-		if(*p++ == '\n')
-			count++;
-   }
-
-   if(cnt == 0) {
-	*filesize = count;
-	return(0);
-   }
-
-   return(1);
-}
-
-static off_t asciisetsize(fd, filesize)
-int fd;
-off_t filesize;
-{
-off_t sp;
-int s;
-
-   sp = 0;
-
-   while(sp < filesize) {
-	s = read(fd, buffer, 1);
-	if(s < 0)
-		return(-1);
-	if(s == 0) break;
-	sp++;
-	if(*buffer == '\n')
-		sp++;
-   }
-
-   return(sp);
-}
Index: trunk/minix/commands/ftp/file.h
===================================================================
--- trunk/minix/commands/ftp/file.h	(revision 9)
+++ 	(revision )
@@ -1,30 +1,0 @@
-/* file.h
- *
- * This file is part of ftp.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
- */
-
-_PROTOTYPE(int recvfile, (int fd, int fdin));
-_PROTOTYPE(int sendfile, (int fd, int fdout));
-_PROTOTYPE(int DOascii, (void));
-_PROTOTYPE(int DObinary, (void));
-_PROTOTYPE(int DOpwd, (void));
-_PROTOTYPE(int DOcd, (void));
-_PROTOTYPE(int DOmkdir, (void));
-_PROTOTYPE(int DOrmdir, (void));
-_PROTOTYPE(int DOdelete, (void));
-_PROTOTYPE(int DOmdtm, (void));
-_PROTOTYPE(int DOsize, (void));
-_PROTOTYPE(int DOstat, (void));
-_PROTOTYPE(int DOlist, (void));
-_PROTOTYPE(int DOnlst, (void));
-_PROTOTYPE(int DOretr, (void));
-_PROTOTYPE(int DOrretr, (void));
-_PROTOTYPE(int DOMretr, (void));
-_PROTOTYPE(int DOappe, (void));
-_PROTOTYPE(int DOstor, (void));
-_PROTOTYPE(int DOrstor, (void));
-_PROTOTYPE(int DOstou, (void));
-_PROTOTYPE(int DOMstor, (void));
Index: trunk/minix/commands/ftp/ftp.c
===================================================================
--- trunk/minix/commands/ftp/ftp.c	(revision 9)
+++ 	(revision )
@@ -1,312 +1,0 @@
-/* ftp.c by Michael Temari 06/21/92
- *
- * ftp          An ftp client program for use with TNET.
- *
- * Usage:       ftp [[host] [port]]
- *
- * Version:     0.10    06/21/92 (pre-release not yet completed)
- *              0.20    07/01/92
- *              0.30    01/15/96 (Minix 1.7.1 initial release)
- *              0.40    08/27/96
- *
- * Author:      Michael Temari, <temari@ix.netcom.com>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "ftp.h"
-#include "local.h"
-#include "file.h"
-#include "other.h"
-#include "net.h"
-
-FILE *fpcommin;
-FILE *fpcommout;
-
-int linkopen;
-int loggedin;
-int type;
-int format;
-int mode;
-int structure;
-int passive;
-int atty;
-
-int cmdargc;
-char *cmdargv[NUMARGS];
-
-char reply[1024];
-
-_PROTOTYPE(static int makeargs, (char *buff));
-_PROTOTYPE(int DOhelp, (void));
-_PROTOTYPE(int main, (int argc, char *argv[]));
-
-static int makeargs(buff)
-char *buff;
-{
-char *p;
-int i;
-
-   for(i = 0; i < NUMARGS; i++)
-	cmdargv[i] = (char *)0;
-
-   p = buff + strlen(buff) - 1;
-   while(p != buff)
-	if(*p == '\r' || *p == '\n' || isspace(*p))
-		*p-- = '\0';
-	else
-		break;
-
-   p = buff;
-   cmdargc = 0;
-   while(cmdargc < NUMARGS) {
-	while(*p && isspace(*p))
-		p++;
-	if(*p == '\0')
-		break;
-	cmdargv[cmdargc++] = p;
-	while(*p && !isspace(*p)) {
-		if(cmdargc == 1)
-			*p = tolower(*p);
-		p++;
-	}
-	if(*p == '\0')
-		break;
-	*p = '\0';
-	p++;
-   }
-}
-
-int readline(prompt, buff, len)
-char *prompt;
-char *buff;
-int len;
-{
-   printf(prompt); fflush(stdout);
-
-   if(fgets(buff, len, stdin) == (char *)NULL) {
-	printf("\nEnd of file on input!\n");
-	exit(1);
-   }
-
-   *strchr(buff, '\n') = 0;
-
-   if(!atty) {
-	printf("%s\n", buff);
-	fflush(stdout);
-   }
-
-   return(0);
-}
-
-int DOgetreply()
-{
-char *p;
-char buff[6];
-int s;
-int firsttime;
-
-   do {
-	firsttime = 1;
-	do {
-		if(fgets(reply, sizeof(reply), fpcommin) == (char *)0)
-			return(-1);
-		p = reply + strlen(reply) - 1;
-		while(p != reply)
-			if(*p == '\r' || *p == '\n' || isspace(*p))
-				*p-- = '\0';
-			else
-				break;
-		printf("%s\n", reply); fflush(stdout);
-		if(firsttime) {
-			firsttime = 0;
-			strncpy(buff, reply, 4);
-			buff[3] = ' ';
-		}
-	   } while(strncmp(reply, buff, 3) || reply[3] == '-');
-	   s = atoi(buff);
-   } while(s < 200 && s != 125 & s != 150);
-
-   return(s);
-}
-
-int DOcmdcheck()
-{
-   if(!linkopen) {
-	printf("You must \"OPEN\" a connection first.\n");
-	return(1);
-   }
-
-   if(!loggedin) {
-	printf("You must login first.\n");
-	return(1);
-   }
-
-   return(0);
-}
-
-int DOcommand(ftpcommand, ftparg)
-char *ftpcommand;
-char *ftparg;
-{
-   if(*ftparg)
-	fprintf(fpcommout, "%s %s\r\n", ftpcommand, ftparg);
-   else
-   	fprintf(fpcommout, "%s\r\n", ftpcommand);
-
-   fflush(fpcommout);
-
-   return(DOgetreply());
-}
-
-int DOhelp()
-{
-char junk[10];
-
-   printf("Command:      Description\n");
-   printf("!             Escape to a shell\n");
-   printf("append        Append a file to remote host\n");
-   printf("ascii         Set file transfer mode to ascii\n");
-   printf("binary        Set file transfer mode to binary\n");
-   printf("bye           Close connection and exit\n");
-   printf("cd            Change directory on remote host\n");
-   printf("close         Close connection\n");
-   printf("del           Remove file on remote host\n");
-   printf("dir           Display long form remote host directory listing\n");
-   printf("exit          Close connection and exit\n");
-   printf("get           Retrieve a file from remote host\n");
-   printf("help          Display this text\n");
-   printf("lcd           Change directory on local host\n");
-   printf("ldir          Display long form local host directory listing\n");
-   printf("lls           Display local host directory listing\n");
-   printf("lmkdir        Create directory on local host\n");
-   printf("lpwd          Display current directory on local host\n");
-   printf("lrmdir        Remove directory on local host\n");
-   printf("ls            Display remote host directory listing\n");
-   printf("mget          Retrieve multiple files from remote host\n");
-   printf("mkdir         Create directory on remote host\n");
-   printf("mod           Get file modification time\n");
-
-   readline("Press ENTER to continue... ", junk, sizeof(junk));
-
-   printf("mput          Send multiple files to remote host\n");
-   printf("noop          Send the ftp NOOP command\n");
-   printf("open          Open connection to remote host\n");
-   printf("pass          Enter remote user password\n");
-   printf("passive       Toggle passive mode\n");
-   printf("put           Send a file to remote host\n");
-   printf("putu          Send a file to remote host(unique)\n");
-   printf("pwd           Display current directory on remote host\n");
-   printf("quit          Close connection and exit\n");
-   printf("quote         Send raw ftp command to remote host\n");
-   printf("reget         Restart a partial file retrieve from remote host\n");
-   printf("remotehelp    Display ftp commands implemented on remote host\n");
-   printf("reput         Restart a partial file send to remote host\n");
-   printf("rm            Remove file on remote host\n");
-   printf("rmdir         Remove directory on remote host\n");
-   printf("site          Send a site specific command\n");
-   printf("size          Get file size information\n");
-   printf("status        Get connection/file status information\n");
-   printf("system        Get remote system type information\n");
-   printf("user          Enter remote user information\n");
-
-   return(0);
-}
-
-struct commands {
-	char *name;
-	_PROTOTYPE(int (*func), (void));
-};
-
-static struct commands commands[] = {
-        "!",            DOlshell,
-	"append",	DOappe,
-	"ascii",        DOascii,
-	"binary",       DObinary,
-	"bin",          DObinary,
-	"bye",          DOquit,
-	"cd",           DOcd,
-	"close",        DOclose,
-	"del",          DOdelete,
-	"dir",          DOlist,
-	"exit",         DOquit,
-	"get",          DOretr,
-	"help",         DOhelp,
-	"lcd",          DOlcd,
-        "ldir",         DOllist,
-        "lls",          DOlnlst,
-	"lmkdir",       DOlmkdir,
-	"lpwd",         DOlpwd,
-	"lrmdir",       DOlrmdir,
-	"ls",           DOnlst,
-	"mget",         DOMretr,
-	"mkdir",        DOmkdir,
-	"mod",		DOmdtm,
-	"mput",         DOMstor,
-	"noop",         DOnoop,
-	"open",         DOopen,
-	"pass",		DOpass,
-	"passive",      DOpassive,
-	"put",          DOstor,
-	"putu",		DOstou,
-	"pwd",          DOpwd,
-	"quit",         DOquit,
-	"quote",        DOquote,
-	"reget",	DOrretr,
-	"remotehelp",   DOremotehelp,
-	"reput",	DOrstor,
-	"rm",           DOdelete,
-	"rmdir",        DOrmdir,
-	"site",		DOsite,
-	"size",		DOsize,
-	"status",	DOstat,
-	"system",	DOsyst,
-	"user",         DOuser,
-	"",     (int (*)())0
-};
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-int s;
-struct commands *cmd;
-static char buffer[128];
-
-   NETinit();
-
-   FTPinit();
-
-   s = 0;
-
-   if(argc > 1) {
-	sprintf(buffer, "open %s ", argv[1]);
-	makeargs(buffer);
-	s = DOopen();
-	if(atty && s > 0) {
-		sprintf(buffer, "user");
-		makeargs(buffer);
-		s = DOuser();
-	}
-   }
-
-   while(s >= 0) {
-	readline("ftp>", buffer, sizeof(buffer));
-	makeargs(buffer);
-	if(cmdargc == 0) continue;
-	for(cmd = commands; *cmd->name != '\0'; cmd++)
-		if(!strcmp(cmdargv[0], cmd->name))
-			break;
-	if(*cmd->name != '\0')
-		s = (*cmd->func)();
-	else {
-		s = 0;
-		printf("Command \"%s\" not recognized.\n", cmdargv[0]);
-	}
-   }
-
-   return(0);
-}
Index: trunk/minix/commands/ftp/ftp.h
===================================================================
--- trunk/minix/commands/ftp/ftp.h	(revision 9)
+++ 	(revision )
@@ -1,36 +1,0 @@
-/* ftp.h
- *
- * This file is part of ftp.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
- */
-
-extern FILE *fpcommin;
-extern FILE *fpcommout;
-
-extern int linkopen;
-extern int loggedin;
-extern int type;
-extern int format;
-extern int mode;
-extern int structure;
-extern int passive;
-extern int atty;
-
-#define	NUMARGS	10
-extern int cmdargc;
-extern char *cmdargv[NUMARGS];
-
-extern char reply[1024];
-
-#define	RETR	0
-#define	STOR	1
-
-#define	TYPE_A	0
-#define	TYPE_I	1
-
-_PROTOTYPE(int readline, (char *prompt, char *buff, int len));
-_PROTOTYPE(int DOgetreply, (void));
-_PROTOTYPE(int DOcmdcheck, (void));
-_PROTOTYPE(int DOcommand, (char *ftpcommand, char *ftparg));
Index: trunk/minix/commands/ftp/local.c
===================================================================
--- trunk/minix/commands/ftp/local.c	(revision 9)
+++ 	(revision )
@@ -1,128 +1,0 @@
-/* local.c
- *
- * This file is part of ftp.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "ftp.h"
-#include "local.h"
-
-static char line2[512];
-
-_PROTOTYPE(static void dodir, (char *path, int full));
-
-int DOlpwd()
-{
-   if(getcwd(line2, sizeof(line2)) == (char *)NULL)
-	printf("Could not determine local directory. %s\n", strerror(errno));
-   else
-	printf("Current local directory: %s\n", line2);
-
-   return(0);
-}
-
-int DOlcd()
-{
-char *path;
-int s;
-
-   path = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Path: ", line2, sizeof(line2));
-	path = line2;
-   }
-
-   if(chdir(path))
-	printf("Could not change local directory. %s\n", strerror(errno));
-   else
-	DOlpwd();
-   
-   return(0);
-}
-
-int DOlmkdir()
-{
-char *path;
-int s;
-
-   path = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Directory: ", line2, sizeof(line2));
-	path = line2;
-   }
-
-   if(mkdir(path, 0777))
-	printf("Could not make directory %s. %s\n", path, strerror(errno));
-   else
-	printf("Directory created.\n");
-   
-   return(0);
-}
-
-int DOlrmdir()
-{
-char *path;
-int s;
-
-   path = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Directory: ", line2, sizeof(line2));
-	path = line2;
-   }
-
-   if(rmdir(path))
-	printf("Could not remove directory %s. %s\n", path, strerror(errno));
-   else
-	printf("Directory removed.\n");
-   
-   return(0);
-}
-
-int DOllist(void)
-{
-   dodir(".", 1);
-}
-
-int DOlnlst(void)
-{
-   dodir(".", 0);
-}
-
-int DOlshell(void)
-{
-   system("$SHELL");
-}
-
-static void dodir(path, full)
-char *path;
-int full;
-{
-char cmd[128];
-static char name[32];
-
-   tmpnam(name);
-
-   if(full)
-	sprintf(cmd, "ls -l %s > %s", path, name);
-   else
-	sprintf(cmd, "ls %s > %s", path, name);
-
-   system(cmd);
-   sprintf(cmd, "more %s", name);
-   system(cmd);
-   sprintf(cmd, "rm %s", name);
-   system(cmd);
-}
Index: trunk/minix/commands/ftp/local.h
===================================================================
--- trunk/minix/commands/ftp/local.h	(revision 9)
+++ 	(revision )
@@ -1,15 +1,0 @@
-/* local.h
- *
- * This file is part of ftp.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
- */
-
-_PROTOTYPE(int DOlpwd, (void));
-_PROTOTYPE(int DOlcd, (void));
-_PROTOTYPE(int DOlmkdir, (void));
-_PROTOTYPE(int DOlrmdir, (void));
-_PROTOTYPE(int DOllist, (void));
-_PROTOTYPE(int DOlnlst, (void));
-_PROTOTYPE(int DOlshell, (void));
Index: trunk/minix/commands/ftp/net.c
===================================================================
--- trunk/minix/commands/ftp/net.c	(revision 9)
+++ 	(revision )
@@ -1,421 +1,0 @@
-/* net.c
- *
- * This file is part of ftp.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
- */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <errno.h>
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/netdb.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-
-#include "ftp.h"
-#include "file.h"
-#include "net.h"
-
-_PROTOTYPE(void donothing, (int sig));
-
-static int ftpcomm_fd;
-static ipaddr_t myip;
-static ipaddr_t hostip;
-static char host[256];
-static int lpid;
-
-void NETinit()
-{
-int s;
-char *tcp_device;
-int tcp_fd;
-nwio_tcpconf_t nwio_tcpconf;
-
-   /* All this just to get our ip address */
-
-   if((tcp_device = getenv("TCP_DEVICE")) == (char *)NULL)
-	tcp_device = TCP_DEVICE;
-
-   tcp_fd = open(tcp_device, O_RDWR);
-   if(tcp_fd < 0) {
-	perror("ftp: Could not open tcp_device");
-	exit(-1);
-   }
-   s = ioctl(tcp_fd, NWIOGTCPCONF, &nwio_tcpconf);
-   if(s < 0) {
-	perror("ftp: Could not get tcp configuration");
-	exit(-1);
-   }
-
-   myip = nwio_tcpconf.nwtc_locaddr;
-
-   close(tcp_fd);
-}
-
-int DOopen()
-{
-nwio_tcpconf_t tcpconf;
-nwio_tcpcl_t tcpcopt;
-char *tcp_device;
-tcpport_t port;
-int s;
-struct hostent *hp;
-struct servent *servent;
-
-   if(linkopen) {
-	printf("Use \"CLOSE\" to close the connection first.\n");
-	return(0);
-   }
-
-   if(cmdargc < 2)
-	readline("Host: ", host, sizeof(host));
-   else
-	strncpy(host, cmdargv[1], sizeof(host));
-
-   if((servent = getservbyname("ftp", "tcp")) == (struct servent *)NULL) {
-   	fprintf(stderr, "ftp: Could not find ftp tcp service\n");
-   	return(-1);
-   }
-   port = (tcpport_t)servent->s_port;
-
-   hp = gethostbyname(host);
-   if (hp == (struct hostent *)NULL) {
-	hostip = (ipaddr_t)0;
-	printf("Unresolved host %s\n", host);
-	return(0);
-   } else
-	memcpy((char *) &hostip, (char *) hp->h_addr, hp->h_length);
-
-   /* This HACK allows the server to establish data connections correctly */
-   /* when using the loopback device to talk to ourselves */
-   if(hostip == inet_addr("127.0.0.1"))
-	hostip = myip;
-
-   if((tcp_device = getenv("TCP_DEVICE")) == NULL)
-	tcp_device = "/dev/tcp";
-
-   if((ftpcomm_fd = open(tcp_device, O_RDWR)) < 0) {
-	perror("ftp: open error on tcp device");
-	return(-1);
-   }
-
-   tcpconf.nwtc_flags = NWTC_LP_SEL | NWTC_SET_RA | NWTC_SET_RP;
-   tcpconf.nwtc_remaddr = hostip;
-   tcpconf.nwtc_remport = port;
-
-   s = ioctl(ftpcomm_fd, NWIOSTCPCONF, &tcpconf);
-   if(s < 0) {
-	perror("ftp: ioctl error on NWIOSTCPCONF");
-	close(ftpcomm_fd);
-	return(s);
-   }
-
-   tcpcopt.nwtcl_flags = 0;
-
-   s = ioctl(ftpcomm_fd, NWIOTCPCONN, &tcpcopt);
-   if(s < 0) {
-	perror("ftp: ioctl error on NWIOTCPCONN");
-	close(ftpcomm_fd);
-	return(s);
-   }
-
-   s = ioctl(ftpcomm_fd, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-	perror("ftp: ioctl error on NWIOGTCPCONF");
-	close(ftpcomm_fd);
-	return(s);
-   }
-
-   fpcommin  = fdopen(ftpcomm_fd, "r");
-   fpcommout = fdopen(ftpcomm_fd, "w");
-
-   s = DOgetreply();
-
-   if(s < 0) {
-	fclose(fpcommin);
-	fclose(fpcommout);
-	close(ftpcomm_fd);
-	return(s);
-   }
-
-   if(s != 220) {
-	fclose(fpcommin);
-	fclose(fpcommout);
-	close(ftpcomm_fd);
-	return(0);
-   }
-
-   linkopen = 1;
-
-   return(s);
-}
-
-int DOclose()
-{
-   if(!linkopen) {
-	printf("You can't close a connection that isn't open.\n");
-	return(0);
-   }
-
-   fclose(fpcommin);
-   fclose(fpcommout);
-   close(ftpcomm_fd);
-
-   linkopen = 0;
-   loggedin = 0;
-
-   return(0);
-}
-
-int DOquit()
-{
-int s;
-
-   if(linkopen) {
-	s = DOcommand("QUIT", "");
-	s = DOclose();
-   }
-
-   printf("FTP done.\n");
-
-   exit(0);
-}
-
-void donothing(sig)
-int sig;
-{
-}
-
-int DOdata(datacom, file, direction, fd)
-char *datacom;
-char *file;
-int direction;  /* RETR or STOR */
-int fd;
-{
-nwio_tcpconf_t tcpconf;
-nwio_tcpcl_t tcplopt, tcpcopt;
-char *tcp_device;
-int ftpdata_fd;
-char *buff;
-ipaddr_t ripaddr;
-tcpport_t rport;
-static tcpport_t lport = HTONS(0xF000);
-int s;
-int i;
-int cs;
-int pfd[2];
-char dummy;
-char port[32];
-
-   ripaddr = hostip;
-   rport = HTONS(20);
-
-   /* here we set up a connection to listen on if not passive mode */
-   /* otherwise we use this to connect for passive mode */
-
-   if((tcp_device = getenv("TCP_DEVICE")) == NULL)
-	tcp_device = "/dev/tcp";
-
-   if((ftpdata_fd = open(tcp_device, O_RDWR)) < 0) {
-	perror("ftp: open error on tcp device");
-	return(-1);
-   }
-
-   if(passive) {
-	s = DOcommand("PASV", "");
-	if(s != 227) {
-		close(ftpdata_fd);
-		return(s);
-	}
-	/* decode host and port */
-	buff = reply;
-	while(*buff && (*buff != '(')) buff++;
-	buff++;
-	ripaddr = (ipaddr_t)0;
-	for(i = 0; i < 4; i++) {
-		ripaddr = (ripaddr << 8) + (ipaddr_t)atoi(buff);
-		if((buff = strchr(buff, ',')) == (char *)0) {
-			printf("Could not parse PASV reply\n");
-			return(-1);
-		}
-		buff++;
-	}
-	rport = (tcpport_t)atoi(buff);
-	if((buff = strchr(buff, ',')) == (char *)0) {
-		printf("Could not parse PASV reply\n");
-		return(-1);
-	}
-	buff++;
-	rport = (rport << 8) + (tcpport_t)atoi(buff);
-	ripaddr = ntohl(ripaddr);
-	rport = ntohs(rport);
-   }
-
-   for (;;) {
-	tcpconf.nwtc_flags = NWTC_SET_RA | NWTC_SET_RP;
-	if (passive || ntohs(lport) >= 0xF000) {
-		tcpconf.nwtc_flags |= NWTC_LP_SEL;
-	} else {
-		/* For no good reason Sun hosts don't like it if they have to
-		 * connect to the same port twice in a short time...
-		 */
-		lport = htons(ntohs(lport) + 1);
-		tcpconf.nwtc_flags |= NWTC_LP_SET;
-		tcpconf.nwtc_locport = lport;
-	}
-
-	tcpconf.nwtc_remaddr = ripaddr;
-	tcpconf.nwtc_remport = rport;
-
-	s = ioctl(ftpdata_fd, NWIOSTCPCONF, &tcpconf);
-	if(s < 0) {
-		if (errno == EADDRINUSE) continue;
-		perror("ftp: ioctl error on NWIOSTCPCONF");
-		close(ftpdata_fd);
-		return(s);
-	}
-	break;
-   }
-
-   s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-	perror("ftp: ioctl error on NWIOGTCPCONF");
-	close(ftpdata_fd);
-	return(s);
-   }
-   lport = tcpconf.nwtc_locport;
-
-   if(passive) {
-	tcplopt.nwtcl_flags = 0;
-	s = ioctl(ftpdata_fd, NWIOTCPCONN, &tcpcopt);
-	if(s < 0) {
-		perror("ftp: error on ioctl NWIOTCPCONN");
-		close(ftpdata_fd);
-		return(0);
-	}
-	s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
-	if(s < 0) {
-		perror("ftp: error on ioctl NWIOGTCPCONF");
-		close(ftpdata_fd);
-		return(0);
-	}
-   } else {
-	tcplopt.nwtcl_flags = 0;
-
-	if (pipe(pfd) < 0) {
-		perror("ftp: could not create a pipe");
-		return(s);
-	}
-	lpid = fork();
-	if(lpid < 0) {
-		perror("ftp: could not fork listener");
-		close(ftpdata_fd);
-		close(pfd[0]);
-		close(pfd[1]);
-		return(s);
-	} else if(lpid == 0) {
-		close(pfd[0]);
-		signal(SIGALRM, donothing);
-		alarm(15);
-		close(pfd[1]);
-		s = ioctl(ftpdata_fd, NWIOTCPLISTEN, &tcplopt);
-		alarm(0);
-		if(s < 0)
-			if(errno == EINTR)
-				exit(1);	/* timed out */
-			else
-				exit(-1);	/* error */
-		else
-			exit(0);		/* connection made */
-	}
-	/* Wait for the pipe to close, then the listener is ready (almost). */
-	close(pfd[1]);
-	(void) read(pfd[0], &dummy, 1);
-	close(pfd[0]);
-	while(1) {
-		signal(SIGALRM, donothing);
-		alarm(1);
-		s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
-		alarm(0);
-		if(s == -1) break;
-	}
-   }
-
-#define hiword(x)       ((u16_t)((x) >> 16))
-#define loword(x)       ((u16_t)(x & 0xffff)) 
-#define hibyte(x)       (((x) >> 8) & 0xff)
-#define lobyte(x)       ((x) & 0xff)
-
-   if(!passive) {
-	sprintf(port, "%u,%u,%u,%u,%u,%u",
-		hibyte(hiword(ntohl(myip))), lobyte(hiword(ntohl(myip))),
-		hibyte(loword(ntohl(myip))), lobyte(loword(ntohl(myip))),
-		hibyte(ntohs(lport)), lobyte(ntohs(lport)));
-	s = DOcommand("PORT", port);
-	if(s != 200) {
-		close(ftpdata_fd);
-		kill(lpid, SIGKILL);
-		return(s);
-	}
-   }
-
-   s = DOcommand(datacom, file);
-   if(s == 125 || s == 150) {
-	if(!passive) {
-		while(1) {
-			s = wait(&cs);
-			if(s < 0 || s == lpid)
-				break;
-		}
-		if(s < 0) {
-			perror("wait error:");
-			close(ftpdata_fd);
-			kill(lpid, SIGKILL);
-			return(s);
-		}
-		if((cs & 0x00ff)) {
-			printf("Child listener failed %04x\n", cs);
-			close(ftpdata_fd);
-			return(-1);
-		}
-		cs = (cs >> 8) & 0x00ff;
-		if(cs == 1) {
-			printf("Child listener timed out\n");
-			return(DOgetreply());
-		} else if(cs) {
-			printf("Child listener returned %02x\n", cs);
-			close(ftpdata_fd);
-			return(-1);
-		}
-	}
-	switch(direction) {
-		case RETR:
-			s = recvfile(fd, ftpdata_fd);
-			break;
-		case STOR:
-			s = sendfile(fd, ftpdata_fd);
-			break;
-	}
-	close(ftpdata_fd);
-	s = DOgetreply();
-   } else {
-	if(!passive)
-		kill(lpid, SIGKILL);
-	close(ftpdata_fd);
-   }
-
-   return(s);
-}
Index: trunk/minix/commands/ftp/net.h
===================================================================
--- trunk/minix/commands/ftp/net.h	(revision 9)
+++ 	(revision )
@@ -1,13 +1,0 @@
-/* net.h
- *
- * This file is part of ftp.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
- */
-
-_PROTOTYPE(void NETinit, (void));
-_PROTOTYPE(int DOopen, (void));
-_PROTOTYPE(int DOclose, (void));
-_PROTOTYPE(int DOquit, (void));
-_PROTOTYPE(int DOdata, (char *datacom, char *file, int direction, int fd));
Index: trunk/minix/commands/ftp/other.c
===================================================================
--- trunk/minix/commands/ftp/other.c	(revision 9)
+++ 	(revision )
@@ -1,163 +1,0 @@
-/* other.c by Michael Temari 06/21/92
- *
- * ftp          An ftp client program for use with TNET.
- *
- * Author:      Michael Temari, <temari@ix.netcom.com>
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "ftp.h"
-#include "other.h"
-
-void FTPinit()
-{
-   linkopen = 0;
-   loggedin = 0;
-   type = TYPE_A;
-   format = 0;
-   mode = 0;
-   structure = 0;
-   passive = 0;
-   atty = isatty(0);
-}
-
-int DOpass()
-{
-int s;
-struct termios oldtty, newtty;
-char *pass;
-char password[64];
-
-   if(!linkopen) {
-	printf("You must \"OPEN\" a connection first.\n");
-	return(0);
-   }
-
-   pass = cmdargv[1];
-
-   if(cmdargc < 2) {
-	tcgetattr(fileno(stdout), &oldtty);
-	newtty = oldtty;
-	newtty.c_lflag &= ~ECHO;
-	tcsetattr(fileno(stdout), TCSANOW, &newtty);
-	readline("Password: ", password, sizeof(password));
-	tcsetattr(fileno(stdout), TCSANOW, &oldtty);
-	printf("\n");
-	pass = password;
-   }
-
-   s = DOcommand("PASS", pass);
-
-   if(s == 230)
-	loggedin = 1;
-
-   return(s);
-}
-
-int DOuser()
-{
-char *user;
-int s;
-char username[64];
-
-   if(!linkopen) {
-	printf("You must \"OPEN\" a connection first.\n");
-	return(0);
-   }
-
-   loggedin = 0;
-
-   user = cmdargv[1];
-
-   if(cmdargc < 2) {
-	readline("Username: ", username, sizeof(username));
-	user = username;
-   }
-
-   s = DOcommand("USER", user);
-
-   if(atty && s == 331) {
-   	cmdargv[0] = "password";
-   	cmdargc = 1;
-	return(DOpass());
-   }
-
-   if(s == 230)
-	loggedin = 1;
-
-   return(s);
-}
-
-int DOnoop()
-{
-   if(DOcmdcheck())
-	return(0);
-
-   return(DOcommand("NOOP", ""));
-}
-
-int DOpassive()
-{
-   passive = 1 - passive;
-
-   printf("Passive mode is now %s\n", (passive ? "ON" : "OFF"));
-
-   return(0);
-}
-
-int DOsyst()
-{
-   if(DOcmdcheck())
-	return(0);
-
-   return(DOcommand("SYST", ""));
-}
-
-int DOremotehelp()
-{
-   if(!linkopen) {
-	printf("You must \"OPEN\" a connection first.\n");
-	return(0);
-   }
-
-   return(DOcommand("HELP", ""));
-}
-
-int DOquote()
-{
-int i;
-static char args[512];
-
-   args[0] = '\0';
-
-   for(i = 2; i < cmdargc; i++) {
-	if(i != 2)
-		strcat(args, " ");
-	strcat(args, cmdargv[i]);
-   }
-
-   return(DOcommand(cmdargv[1], args));
-}
-
-int DOsite()
-{
-int i;
-static char args[512];
-
-   args[0] = '\0';
-
-   for(i = 1; i < cmdargc; i++) {
-   	if(i != 1)
-		strcat(args, " ");
-	strcat(args, cmdargv[i]);
-   }
-
-   return(DOcommand("SITE", args));
-}
Index: trunk/minix/commands/ftp/other.h
===================================================================
--- trunk/minix/commands/ftp/other.h	(revision 9)
+++ 	(revision )
@@ -1,17 +1,0 @@
-/* other.h
- *
- * This file is part of ftp.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
- */
-
-_PROTOTYPE(void FTPinit, (void));
-_PROTOTYPE(int DOpass, (void));
-_PROTOTYPE(int DOuser, (void));
-_PROTOTYPE(int DOnoop, (void));
-_PROTOTYPE(int DOpassive, (void));
-_PROTOTYPE(int DOsyst, (void));
-_PROTOTYPE(int DOremotehelp, (void));
-_PROTOTYPE(int DOquote, (void));
-_PROTOTYPE(int DOsite, (void));
Index: trunk/minix/commands/ftpd200/Makefile
===================================================================
--- trunk/minix/commands/ftpd200/Makefile	(revision 9)
+++ 	(revision )
@@ -1,43 +1,0 @@
-# Makefile for ftpd
-#
-# 01/25/96 Initial Release	Michael Temari, <Michael@TemWare.Com>
-# 2005-02-25 version 2.00
-
-CFLAGS=	-O -D_MINIX -D_POSIX_SOURCE -m
-LDFLAGS=-i
-BINDIR=	/usr/bin
-PROG=	in.ftpd
-MANDIR= /usr/man/man8
-MANPAGE=ftpd.8
-CC = exec cc
-
-OBJS=	ftpd.o access.o file.o net.o
-
-all:	$(PROG)
-
-$(PROG):	$(OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(OBJS)
-	install -S 8kw $@
-
-clean:
-	rm -f $(PROG) $(OBJS)
-
-install:	$(BINDIR)/$(PROG) $(BINDIR)/setup.anonftp $(BINDIR)/ftpdsh
-
-$(BINDIR)/$(PROG):	$(PROG)
-	install -cs -o bin $? $@
-
-$(BINDIR)/setup.anonftp:	setup.anonftp
-	install -c -o bin $? $@
-
-$(BINDIR)/ftpdsh:	ftpdsh
-	install -m 755 -c -o bin $? $@
-
-ftpd.o:		ftpd.c   ftpd.h access.h file.h net.h
-access.o:	access.c ftpd.h access.h
-file.o:		file.c   ftpd.h access.h file.h net.h
-net.o:		net.c    ftpd.h                 net.h
-
-installman:	$(MANDIR)/$(MANPAGE)
-	cp $(MANPAGE) $(MANDIR)
-	echo "You may need to run makewhatis to update man page index"
Index: trunk/minix/commands/ftpd200/README
===================================================================
--- trunk/minix/commands/ftpd200/README	(revision 9)
+++ 	(revision )
@@ -1,35 +1,0 @@
-ftpd200 --- FTP server program for Minix 2.0  
-written by Michael Temari <Michael@TemWare.Com> release 2.00 2005-02-25
-
-Full download: <a href="/pub/contrib/ftpd200.tar.Z">ftpd200.tar.Z</a>
-
-Ftpd is the File Transfer Protocol (FTP) server.  
-
-Important: Release 2.00 incorporates an improved mechanism to restrict
-execution of commands on the server.  This is done through use of a
-shell script, ftpdsh.  Any earlier ftpd version in use on a system
-accessible from the Internet should be upgraded at least to version 1.01,
-version 2.00 is preferable.
-
-Installation: unpack the tarball in /usr/local/src or another directory 
-of your choice:
-zcat < ftpd200.tar.Z | tar xvfp -
-
-The ftpd200 directory will be created.  Read the Makefile to see how
-the program is compiled and installed:
-
-make (or make ftpd) -- compiles the binary
-make install        -- installs /usr/bin/in.ftpd, and ftpdsh. Also installs 
-                       setup.anonftp script.  
-make installman     -- installs new ftpd.8 man page in /usr/local/man/man8
-
-The shell script setup.anonftp sets up and verifies configuration for
-anonymous ftp.  If you provide anonymous ftp you are letting anyone in
-the whole wide world execute a program on your computer.  You want to
-make sure it's set up correctly so outsiders can't mess with things
-they shouldn't.  
-
-This file is included as README in the source directory.  For more
-notes on compiling and installing, also please see the file README2.
-
-notes updated by asw 2005-02-25
Index: trunk/minix/commands/ftpd200/README2
===================================================================
--- trunk/minix/commands/ftpd200/README2	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-README2: additional notes on compiling and installing ftpd.
-
-Note that the Makefile install options will replace files in /usr/bin
-and /usr/man that were installed with the Minix distribution.  If you
-are not sure you want to do this you can either rename the original
-in.ftpd binary, the anonftp.* scripts, and the ftpd.8 man page to
-prevent them from being replaced, or you can edit the Makefile to
-change the directory values:
-  BINDIR= /usr/local/bin
-  MANDIR= /usr/local/man/man8
-ASW's practice is to rename binaries with a suffix that indicates the
-original distribution from which they were obtained, i.e., in.ftpd.203
-for the version distributed with Minix 2.0.3, or with a date code or a
-version number.
-
-If you are sure you want to replace the original ftpd provided with your
-distribution you  may want to copy the contents of the unpacked tarball
-to the main directory tree, in this case /usr/src/commands/ftpd, so that
-a new version will be compiled if you do a general recompilation of all 
-commands using "make all" or "make compile" in /usr/src. ASW's practice
-is generally to make a directory in /usr/local/src for new versions of
-major programs. 
-Also note that if you create a new man page where one did not exist
-previously you will need to run makewhatis to rebuild the whatis
-database, i.e.:
-  makewhatis /usr/man
-or
-  makewhatis /usr/local/man
-
-Important: the scripts for setting up and maintaining an anonymous ftp
-installation haven't been checked for a long time, I would appreciate 
-comments.
-
-ASW 2005-02-06
Index: trunk/minix/commands/ftpd200/access.c
===================================================================
--- trunk/minix/commands/ftpd200/access.c	(revision 9)
+++ 	(revision )
@@ -1,134 +1,0 @@
-/* access.c Copyright 1992-2000 by Michael Temari All Rights Reserved
- *
- * This file is part of ftpd.
- *
- * This file handles:
- *
- *      USER PASS QUIT
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <Michael@TemWare.Com>
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <net/gen/in.h>
-#include <net/gen/tcp.h>
-
-#include "ftpd.h"
-#include "access.h"
-
-_PROTOTYPE(static int AreWeIn, (char *name, struct passwd *pwd));
-
-static char *msg530 = "530 Not logged in.\r\n";
-
-/* Returns -1 = not logged in, 0 = loggedin */
-int ChkLoggedIn()
-{
-   if(!loggedin) {
-	printf(msg530);
-	return(-1);
-   } else
-	return(0);
-}
-
-/* what a USER! */
-int doUSER(buff)
-char *buff;
-{
-   loggedin = 0;
-   gotuser = 0;
-   strncpy(username, buff, sizeof(username));
-   username[sizeof(username)-1] = '\0';
-
-   if(*username == '\0') {
-	printf("501 Bad user name.\r\n");
-	return(GOOD);
-   }
-
-   gotuser = 1;
-
-   printf("331 Password required for %s.\r\n", username);
-
-   return(GOOD);
-}
-
-/* secret, secret, secret */
-int doPASS(buff)
-char *buff;
-{
-char *name;
-struct passwd *pwd;
-int bad=0;
-
-   name = username;
-
-   if(!strcmp(name, "anonymous"))
-	name = "ftp";
-
-   if(!gotuser || ((pwd = getpwnam(name)) == (struct passwd *)0))
-	bad = 1;
-   else
-	if(strcmp(name, "ftp")) {
-		if(!strcmp(pwd->pw_passwd, crypt("", pwd->pw_passwd)))
-			bad = 1;
-		if(strcmp(pwd->pw_passwd, crypt(buff, pwd->pw_passwd)))
-			bad = 1;
-	} else {
-		strncpy(anonpass, buff, sizeof(anonpass));
-		anonpass[sizeof(anonpass)-1] = '\0';
-	}
-
-   if(bad) {
-	logit("LOGIN", "FAIL");
-	printf(msg530);
-	return(GOOD);
-   }
-
-   return(AreWeIn(name, pwd));
-}
-
-/* bye, bye don't let the door hit you in the butt on the way out */
-int doQUIT(buff)
-char *buff;
-{
-   printf("221 Service closing, don't be a stranger.\r\n");
-
-   return(BAD);
-}
-
-/* see if this user is okay */
-static int AreWeIn(name, pwd)
-char *name;
-struct passwd *pwd;
-{
-   if(!strcmp(name, "ftp")) {
-	if(chroot(pwd->pw_dir)) {
-		logit("LOGIN", "FAIL");
-		printf("530 Not logged in, could not chroot.\r\n");
-		return(GOOD);
-	}
-	strncpy(newroot, pwd->pw_dir, sizeof(newroot));
-	newroot[sizeof(newroot)-1] = '\0';
-	anonymous = 1;
-	strcpy(pwd->pw_dir, "/");
-   }
-
-   if(setgid(pwd->pw_gid) || setuid(pwd->pw_uid) || chdir(pwd->pw_dir)) {
-	logit("LOGIN", "FAIL");
-	printf(msg530);
-	anonymous = 0;
-   } else {
-	logit("LOGIN", "PASS");
-	showmsg("230", (char *)NULL);
-	printf("230 User %s logged in, directory %s.\r\n",
-		username, pwd->pw_dir);
-	loggedin = 1;
-   }
-
-   return(GOOD);
-}
Index: trunk/minix/commands/ftpd200/access.h
===================================================================
--- trunk/minix/commands/ftpd200/access.h	(revision 9)
+++ 	(revision )
@@ -1,12 +1,0 @@
-/* ftpd.h
- *
- * This file is part of ftpd.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <Michael@TemWare.Com>
- */
-
-_PROTOTYPE(int ChkLoggedIn, (void));
-_PROTOTYPE(int doUSER, (char *buff));
-_PROTOTYPE(int doPASS, (char *buff));
-_PROTOTYPE(int doQUIT, (char *buff));
Index: trunk/minix/commands/ftpd200/build
===================================================================
--- trunk/minix/commands/ftpd200/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/ftpd200/file.c
===================================================================
--- trunk/minix/commands/ftpd200/file.c	(revision 9)
+++ 	(revision )
@@ -1,1252 +1,0 @@
-/* file.c Copyright 1992-2000 by Michael Temari All Rights Reserved
- *
- * This file is part of ftpd.
- *
- * This file handles:
- *
- *      ALLO APPE CDUP CWD  DELE LIST MDTM MODE MKD  NLST PWD REST RETR
- *      RMD  RNFR RNTO SITE SIZE STAT STOR STOU STRU SYST TYPE
- *
- * 01/25/96 Initial Release	Michael Temari
- * 03/09/00 			Michael Temari, <Michael@TemWare.Com>
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <time.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-
-#include "ftpd.h"
-#include "access.h"
-#include "file.h"
-#include "net.h"
-
-_PROTOTYPE(static int fdxcmd, (int cmd, char *arg));
-_PROTOTYPE(static int endfdxcmd, (int fd));
-_PROTOTYPE(static int asciisize, (char *filename, unsigned long *filesize));
-_PROTOTYPE(static int cnvtfile, (char *name, char **name2));
-_PROTOTYPE(static int procfile, (char *name));
-_PROTOTYPE(static unsigned long fsize, (char *fname));
-_PROTOTYPE(static int sendfile, (char *name, int xmode));
-_PROTOTYPE(static int recvfile, (char *name, int xmode));
-_PROTOTYPE(static char *uniqname, (void));
-_PROTOTYPE(static int docrc, (char *buff, int xmode));
-_PROTOTYPE(static int dofdet, (char *buff));
-_PROTOTYPE(static char *path, (char *fname));
-
-#define	SEND_FILE	0
-#define	SEND_NLST	1
-#define	SEND_LIST	2
-
-#define	RECV_FILE	0
-#define	RECV_APND	1
-#define	RECV_UNIQ	2
-
-#define	CNVT_ERROR	0
-#define	CNVT_NONE	1
-#define	CNVT_TAR	2
-#define	CNVT_TAR_Z	3
-#define	CNVT_COMP	4
-#define	CNVT_TAR_GZ	5
-#define	CNVT_GZIP	6
-#define	CNVT_UNCOMP	7
-
-
-#define	PROG_FTPDSH	"ftpdsh"
-#define	CMD_NLST	1
-#define	CMD_LIST	2
-#define	CMD_CRC		3
-
-static char *msg550 = "550 %s %s.\r\n";
-
-static unsigned long file_restart = 0;
-
-static char rnfr[256];
-static char buffer[8192];
-static char bufout[8192];
-
-static cmdpid = -1;
-
-/* allocate, we don't need no stink'n allocate */
-int doALLO(buff)
-char *buff;
-{
-   printf("202 ALLO command not needed at this site.\r\n");
-
-   return(GOOD);
-}
-
-/* append to a file if it exists */
-int doAPPE(buff)
-char *buff;
-{
-   return(recvfile(buff, RECV_APND));
-}
-
-/* change to parent directory */
-int doCDUP(buff)
-char *buff;
-{
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   return(doCWD(".."));
-}
-
-/* change directory */
-int doCWD(buff)
-char *buff;
-{
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(chdir(buff))
-	printf(msg550, buff, strerror(errno));
-   else {
-	showmsg("250", ".ftpd_msg");
-	printf("250 %s command okay.\r\n", line);
-   }
-
-   return(GOOD);
-}
-
-/* remove a file */
-int doDELE(buff)
-char *buff;
-{
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(anonymous) {
-	printf("550 Command not allowed for anonymous user\r\n");
-	return(GOOD);
-   }
-
-   if(unlink(buff))
-	printf(msg550, buff, strerror(errno));
-   else {
-	printf("250 File \"%s\" deleted.\r\n", buff);
-	logit("DELE", path(buff));
-   }
-
-   return(GOOD);
-}
-
-/* directory listing */
-int doLIST(buff)
-char *buff;
-{
-   file_restart = 0;
-
-   return(sendfile(buff, SEND_LIST));
-}
-
-/* file modification time, btw when will this be put into an RFC */
-int doMDTM(buff)
-char *buff;
-{
-struct stat st;
-struct tm *t;
-
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(stat(buff, &st)) {
-	printf(msg550, buff, strerror(errno));
-	return(GOOD);
-   }
-
-   if((st.st_mode & S_IFMT) != S_IFREG) {
-	printf("550 Not a regular file.\r\n");
-	return(GOOD);
-   }
-
-   t = gmtime(&st.st_mtime);
-
-   printf("215 %04d%02d%02d%02d%02d%02d\r\n",
-	t->tm_year+1900, t->tm_mon+1, t->tm_mday,
-	t->tm_hour, t->tm_min, t->tm_sec);
-
-   return(GOOD);
-}
-
-/* mode */
-int doMODE(buff)
-char *buff;
-{
-   switch(*buff) {
-	case 'b':
-	case 'B':
-		printf("200 Mode set to %c.\r\n", *buff);
-		mode = MODE_B;
-		break;
-	case 's':
-	case 'S':
-		printf("200 Mode set to %c.\r\n", *buff);
-		mode = MODE_S;
-		break;
-	default:
-		printf("501 Unknown mode %c.\r\n", *buff);
-   }
-
-   return(GOOD);
-}
-
-/* make a directory */
-int doMKD(buff)
-char *buff;
-{
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(anonymous) {
-	printf("550 Command not allowed for anonymous user\r\n");
-	return(GOOD);
-   }
-
-   if(mkdir(buff, 0777))
-	printf(msg550, buff, strerror(errno));
-   else {
-	printf("257 \"%s\" directory created.\r\n", buff);
-	logit("MKD ", path(buff));
-   }
-
-   return(GOOD);
-}
-
-/* name listing */
-int doNLST(buff)
-char *buff;
-{
-   file_restart = 0;
-
-   return(sendfile(buff, SEND_NLST));
-}
-
-/* where are we */
-int doPWD(buff)
-char *buff;
-{
-char dir[128];
-
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(getcwd(dir, sizeof(dir)) == (char *)NULL)
-	printf(msg550, buff, strerror(errno));
-   else
-	printf("257 \"%s\" is current directory.\r\n", dir);
-
-   return(GOOD);
-}
-
-/* restart command */
-int doREST(buff)
-char *buff;
-{
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   file_restart = atol(buff);
-
-   printf("350 Next file transfer will restart at %lu.\r\n", file_restart);
-
-   return(GOOD);
-}
-
-/* they want a file */
-int doRETR(buff)
-char *buff;
-{
-   return(sendfile(buff, SEND_FILE));
-}
-
-/* remove a directory */
-int doRMD(buff)
-char *buff;
-{
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(anonymous) {
-	printf("550 Command not allowed for anonymous user\r\n");
-	return(GOOD);
-   }
-
-   if(rmdir(buff))
-	printf(msg550, buff, strerror(errno));
-   else {
-	printf("250 Directory \"%s\" deleted.\r\n", buff);
-	logit("RMD ", path(buff));
-   }
-
-   return(GOOD);
-}
-
-/* rename from */
-int doRNFR(buff)
-char *buff;
-{
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(anonymous) {
-	printf("550 Command not allowed for anonymous user\r\n");
-	return(GOOD);
-   }
-
-   strncpy(rnfr, buff, sizeof(rnfr));
-   rnfr[sizeof(rnfr)-1] = '\0';
-
-   printf("350 Got RNFR waiting for RNTO.\r\n");
-
-   return(GOOD);
-}
-
-/* rename to */
-int doRNTO(buff)
-char *buff;
-{
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(anonymous) {
-	printf("550 Command not allowed for anonymous user\r\n");
-	return(GOOD);
-   }
-
-   if(rnfr[0] == '\0') {
-	printf("550 Rename failed.\r\n");
-	return(GOOD);
-   }
-
-   if(rename(rnfr, buff) < 0)
-	printf("550 Rename failed. Error %s\r\n", strerror(errno));
-   else {
-	printf("250 Renamed %s to %s.\r\n", rnfr, buff);
-	logit("RNFR", path(rnfr));
-	logit("RNTO", path(buff));
-   }
-
-   rnfr[0] = '\0';
-
-   return(GOOD);
-}
-
-/* xmode = 0 for multiline crc, xmode <> 0 for single file single line crc */
-static int docrc(buff, xmode)
-char *buff;
-int xmode;
-{
-unsigned short cs;
-long fs;
-int fd;
-int s;
-char *p;
-
-   if((fd = fdxcmd(CMD_CRC, buff)) < 0) {
-	printf("501 Could not obtain CRC.\r\n");
-	return(GOOD);
-   }
-
-   if(xmode == 0)
-	printf("202-SITE CRC \"%s\"\r\n", buff);
-
-   while(1) {
-	p = buffer;
-	while(1) {
-		if((s = read(fd, p, 1)) != 1) {
-			if(xmode == 0)
-				printf("202 SITE CRC DONE.\r\n");
-			else
-				printf("501 Could not obtain CRC.\r\n");
-			endfdxcmd(fd);
-			return(GOOD);
-		}
-		if(*p == '\n') {
-			*p++ = '\r';
-			*p++ = '\n';
-			*p = '\0';
-			break;
-		}
-		p++;
-	}
-	if(xmode != 0)
-		break;
-	printf("    %s", buffer);
-   }
-
-   cs = atoi(buffer);
-
-   fs = atol(buffer+6);
-
-   printf("202 CRC %05u %ld.\r\n", cs, fs);
-
-   endfdxcmd(fd);
-
-   return(GOOD);
-}
-
-/* site specific */
-int doSITE(buff)
-char *buff;
-{
-char *args;
-
-   if(ChkLoggedIn())
-	return(GOOD);
-
-
-   strncpy(line, buff, sizeof(line));
-   line[sizeof(line)-1] = '\0';
-
-   cvtline(&args);
-
-   if(!strcmp(line, "CRC") || !strcmp(line, "CCRC"))
-	return(docrc(args, strcmp(line, "CRC")));
-
-   if(!strcmp(line, "FDET"))
-	return(dofdet(args));
-
-   printf("501 Unknown SITE command %s.\r\n", line);
-
-   return(GOOD);
-}
-
-static unsigned long fsize(fname)
-char *fname;
-{
-struct stat st;
-unsigned long fs = 0L;
-
-   if(stat(fname, &st))
-	return(fs);
-
-   if((st.st_mode & S_IFMT) != S_IFREG)
-	return(fs);
-
-   if(type == TYPE_A)
-	return(fs);
-
-   fs = st.st_size;
-
-   return(fs);
-}
-
-/* file size, btw when will this be put into an RFC */
-int doSIZE(buff)
-char *buff;
-{
-struct stat st;
-unsigned long filesize;
-
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(stat(buff, &st)) {
-	printf(msg550, buff, strerror(errno));
-	return(GOOD);
-   }
-
-   if((st.st_mode & S_IFMT) != S_IFREG) {
-	printf("550 Not a regular file.\r\n");
-	return(GOOD);
-   }
-
-   filesize = st.st_size;
-
-   if(type == TYPE_A)
-	if(asciisize(buff, &filesize))
-		return(GOOD);
-
-   printf("215 %lu\r\n", filesize);
-
-   return(GOOD);
-}
-
-/* server status, or file status */
-int doSTAT(buff)
-char *buff;
-{
-time_t now;
-struct tm *tm;
-int fd;
-int s;
-
-   if(!*buff) {
-	(void) time(&now);
-	tm = localtime(&now);
-	printf("211-%s(%s:%u) FTP server status:\r\n",
-		myhostname, inet_ntoa(myipaddr), ntohs(myport));
-	printf("    Version %s  ", FtpdVersion);
-	printf("%s, %02d %s %d %02d:%02d:%02d %s\r\n", days[tm->tm_wday],
-		tm->tm_mday, months[tm->tm_mon], 1900+tm->tm_year,
-		tm->tm_hour, tm->tm_min, tm->tm_sec, tzname[tm->tm_isdst]);
-	printf("    Connected to %s:%u\r\n", inet_ntoa(rmtipaddr), ntohs(rmtport));
-	if(!loggedin)
-		printf("    Not logged in\r\n");
-	else
-		printf("    Logged in %s\r\n", username);
-	printf("    MODE: %s\r\n",(mode == MODE_B) ? "Block" : "Stream");
-	printf("    TYPE: %s\r\n",(type == TYPE_A) ? "Ascii" : "Binary");
-	printf("211 End of status\r\n");
-	return(GOOD);
-   }
-
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   printf("211-Status of %s:\r\n", buff);
-
-   if((fd = fdxcmd(CMD_LIST, buff)) < 0)
-	printf("   Could not retrieve status");
-   else {
-	while((s = read(fd, buffer, 1)) == 1) {
-		if(*buffer == '\n')
-			printf("\r\n");
-		else
-			printf("%c", *buffer);
-	}
-	endfdxcmd(fd);
-   }
-
-   printf("211 End of status\r\n");
-
-   return(GOOD);
-}
-
-/* hey look, we're getting a file */
-int doSTOR(buff)
-char *buff;
-{
-   return(recvfile(buff, RECV_FILE));
-}
-
-/* hey, get a file unique */
-int doSTOU(buff)
-char *buff;
-{
-   return(recvfile(buff, RECV_UNIQ));
-}
-
-/* structure */
-int doSTRU(buff)
-char *buff;
-{
-   switch(*buff) {
-	case 'f':
-	case 'F':
-		printf("200 Structure set to %c.\r\n", *buff);
-		break;
-	default:
-		printf("501 Unknown structure %c.\r\n", *buff);
-   }
-
-   return(GOOD);
-}
-
-/* we're UNIX and proud of it! */
-int doSYST(buff)
-char *buff;
-{
-   printf("215 UNIX Type: L8\r\n");
-
-   return(GOOD);
-}
-
-/* change transfer type */
-int doTYPE(buff)
-char *buff;
-{
-   if(*(buff+1) != '\0') {
-	printf("501 Syntax error in parameters.\r\n");
-	return(GOOD);
-   }
-
-   switch(*buff) {
-	case 'A':
-	case 'a':
-		type = TYPE_A;
-		printf("200 Type set to A.\r\n");
-		break;
-	case 'I':
-	case 'i':
-		type = TYPE_I;
-		printf("200 Type set to I.\r\n");
-		break;
-	default:
-		printf("501 Invalid type %c.\r\n", *buff);
-   }
-
-   return(GOOD);
-}
-
-static int fdxcmd(cmd, arg)
-int   cmd;
-char *arg;
-{
-char xcmd[3];
-char *argv[5];
-int fds[2];
-char *smallenv[] = { "PATH=/bin:/usr/bin:/usr/local/bin", NULL, NULL };
-
-   if((smallenv[1] = getenv("TZ")) != NULL) smallenv[1] -= 3;	/* ouch... */
-
-   sprintf(xcmd, "%d", cmd);
-
-   argv[0] = PROG_FTPDSH;
-   argv[1] = xcmd;
-   argv[2] = arg;
-   argv[3] = (char *)NULL;
-
-   if(pipe(fds) < 0)
-	return(-1);
-
-   if((cmdpid = fork()) < 0) {
-	close(fds[0]);
-	close(fds[1]);
-	return(-1);
-   }
-
-   if(cmdpid == 0) { /* Child */
-	close(fds[0]);
-	close(0);
-	open("/dev/null", O_RDONLY);
-	dup2(fds[1], 1);
-	dup2(fds[1], 2);
-	close(fds[1]);
-	sprintf(argv[0], "/bin/%s", PROG_FTPDSH);
-	execve(argv[0], argv, smallenv);
-	sprintf(argv[0], "/usr/bin/%s", PROG_FTPDSH);
-	execve(argv[0], argv, smallenv);
-	sprintf(argv[0], "/usr/local/bin/%s", PROG_FTPDSH);
-	execve(argv[0], argv, smallenv);
-	exit(0);
-   }
-
-   close(fds[1]);
-
-   return(fds[0]);
-}
-
-/* Same as close if not cmd child started */
-static int endfdxcmd(fd)
-int fd;
-{
-int s;
-int cs;
-
-   close(fd);
-
-   if(cmdpid == -1)
-	return(0);
-
-   s = waitpid(cmdpid, &cs, 0);
-
-   cmdpid = -1;
-
-   return(0);
-}
-
-/* returns -1 = size could not be determined, */
-/*          0 = size determined and in filesize */
-static int asciisize(filename, filesize)
-char *filename;
-unsigned long *filesize;
-{
-unsigned long count;
-int fd;
-char *p, *pp;
-int cnt;
-
-   if((fd = open(filename, O_RDONLY)) < 0) {
-	printf(msg550, filename, strerror(errno));
-	return(-1);
-   }
-
-   count = 0;
-
-   while((cnt = read(fd, buffer, sizeof(buffer))) > 0) {
-	count += cnt;
-	p = buffer;
-	while(cnt > 0)
-		if((pp = memchr(p, '\n', cnt)) != (char *)NULL) {
-			count++;
-			cnt = cnt - 1 - (pp - p);
-			p = pp + 1;
-		} else
-			break;
-   }
-
-   if(cnt == 0) {
-	*filesize = count;
-	close(fd);
-	return(0);
-   }
-
-   printf(msg550, filename, strerror(errno));
-
-   close(fd);
-
-   return(-1);
-}
-
-/* see if we need to run a command to convert the file */
-static int cnvtfile(name, name2)
-char *name;
-char **name2;
-{
-struct stat st;
-static char fname[256];
-char *p;
-int cmode;
-
-   if(!stat(name, &st))			/* file exists can't be a conversion */
-   	if((st.st_mode & S_IFMT) != S_IFREG) {	/* must be regular file */
-		printf("550 Not a regular file.\r\n");
-		return(CNVT_ERROR);
-	} else
-		return(CNVT_NONE);
-
-   if(errno != ENOENT) {	/* doesn't exist is okay, others are not */
-	printf(msg550, name, strerror(errno));
-	return(CNVT_ERROR);
-   }
-
-   /* find out what kind of conversion */
-   strncpy(fname, name, sizeof(fname));
-   fname[sizeof(fname)-1] = '\0';
-
-   p = fname + strlen(fname);
-   cmode = CNVT_ERROR;
-   while(p > fname && cmode == CNVT_ERROR) {
-	if(*p == '.') {
-		if(!strcmp(p, ".tar"))
-			cmode = CNVT_TAR;
-		else
-		if(!strcmp(p, ".tar.Z"))
-			cmode = CNVT_TAR_Z;
-		else
-		if(!strcmp(p, ".Z"))
-			cmode = CNVT_COMP;
-		else
-		if(!strcmp(p, ".tar.gz"))
-			cmode = CNVT_TAR_GZ;
-		else
-		if(!strcmp(p, ".gz"))
-			cmode = CNVT_GZIP;
-
-		if (cmode != CNVT_ERROR) {
-			/* is there a file to convert? */
-			*p = '\0';
-			if (!stat(fname, &st)) break;
-			*p = '.';
-			cmode = CNVT_ERROR;
-		}
-	}
-	p--;
-   }
-
-   if(cmode == CNVT_ERROR) {
-	printf(msg550, fname, strerror(errno));
-	return(CNVT_ERROR);
-   }
-
-   if(cmode == CNVT_COMP || cmode == CNVT_GZIP || cmode == CNVT_UNCOMP)
-	if((st.st_mode & S_IFMT) != S_IFREG) {
-		printf("550 Not a regular file.\r\n");
-		return(CNVT_ERROR);
-	}
-
-   *name2 = fname;
-
-   return(cmode);
-}
-
-static int procfile(name)
-char *name;
-{
-int cmd;
-int fd;
-char *name2;
-
-   cmd = cnvtfile(name, &name2);
-
-   switch(cmd) {
-	case CNVT_TAR:
-		fd = fdxcmd(cmd + 10, name2);
-		break;
-	case CNVT_TAR_Z:
-		fd = fdxcmd(cmd + 10, name2);
-		break;
-	case CNVT_COMP:
-		fd = fdxcmd(cmd + 10, name2);
-		break;
-	case CNVT_TAR_GZ:
-		fd = fdxcmd(cmd + 10, name2);
-		break;
-	case CNVT_GZIP:
-		fd = fdxcmd(cmd + 10, name2);
-		break;
-	case CNVT_UNCOMP:
-		fd = fdxcmd(cmd + 10, name2);
-		break;
-	case CNVT_NONE:
-		fd = open(name, O_RDONLY);
-		break;
-	case CNVT_ERROR:
-	default:
-		return(-1);
-   }
-
-   if(fd < 0)
-	printf(msg550, name, strerror(errno));
-
-   return(fd);
-}
-
-/* oh no, they're taking a file */
-static int sendfile(name, xmode)
-char *name;
-int xmode;
-{
-char *fname;
-int fd, s;
-time_t datastart, dataend;
-unsigned long datacount;
-long kbs;
-char c;
-char *p;
-char *op, *ope;
-off_t sp;
-int doascii;
-unsigned long fs;
-char block[3];
-
-   if(ChkLoggedIn()) 
-	return(GOOD);
-
-   switch(xmode) {
-	case SEND_NLST:
-		fname = "NLST";
-		fd = fdxcmd(CMD_NLST, name);
-		if(fd < 0)
-			printf(msg550, name, strerror(errno));
-		break;
-	case SEND_LIST:
-		fname = "LIST";
-		fd = fdxcmd(CMD_LIST, name);
-		if(fd < 0)
-			printf(msg550, name, strerror(errno));
-		break;
-	default:
-		fname = name;
-		fd = procfile(name);
-		if(fd < 0)
-			logit("FAIL", path(fname));
-		else
-			logit("SEND", path(fname));
-   }
-
-   if(fd < 0)
-	return(GOOD);
-
-   /* set file position at approriate spot */
-   if(file_restart) {
-	if(type == TYPE_A) {
-		sp = 0;
-		while(sp < file_restart) {
-			sp++;
-			s = read(fd, buffer, 1);
-			if(s < 0) {
-				printf(msg550, fname, strerror(errno));
-				endfdxcmd(fd);
-				file_restart = 0;
-				return(GOOD);
-			}
-			if(s == 0) break;
-			if(*buffer == '\n')
-				sp++;
-		}
-	} else {
-		sp = lseek(fd, file_restart, SEEK_SET);
-		if(sp == -1) {
-			printf(msg550, fname, strerror(errno));
-			endfdxcmd(fd);
-			file_restart = 0;
-			return(GOOD);
-		}
-	}
-	if(sp != file_restart) {
-		printf("550 File restart point error. %lu not %lu\r\n", sp, file_restart);
-		endfdxcmd(fd);
-		file_restart = 0;
-		return(GOOD);
-	}
-   }
-   file_restart = 0;
-
-   fs = fsize(fname);
-   if(fs == 0L)
-	printf("%03d File %s okay.  Opening data connection.\r\n",
-		ftpdata_fd >= 0 ? 125 : 150, fname);
-   else
-	printf("%03d Opening %s mode data connection for %s (%ld bytes).\r\n",
-		ftpdata_fd >= 0 ? 125 : 150,
-		type == TYPE_A ? "ASCII" : "BINARY",
-		fname, fs);
-   fflush(stdout);
-
-#ifdef DEBUG
-   fprintf(logfile, "After 125/150 b4 DataConnect\n");
-   fflush(logfile);
-#endif
-
-   if(DataConnect()) {
-	endfdxcmd(fd);
-	return(GOOD);
-   }
-
-#ifdef DEBUG
-   fprintf(logfile, "After DataConnect\n");
-   fflush(logfile);
-   fprintf(logfile, "ftpd: parent %d start sendfile \n", getpid());
-   fflush(logfile);
-#endif
-
-   /* start transfer */
-   doascii = (type == TYPE_A) ||
-   	((xmode == SEND_LIST) || (xmode == SEND_NLST)); /* per RFC1123 4.1.2.7 */
-   datacount = 0;
-   time(&datastart);
-   op = bufout; ope = bufout + sizeof(bufout) - 3;
-   while((s = read(fd, buffer, sizeof(buffer))) > 0) {
-#ifdef DEBUG
-	fprintf(logfile, "sendfile read %d\n", s); fflush(logfile);
-#endif
-	datacount += s;
-	if(doascii) {
-		p = buffer;
-		while(s-- > 0) {
-			c = *p++;
-			if(c == '\n') {
-				*op++ = '\r';
-				datacount++;
-			}
-			*op++ = c;
-			if(op >= ope) {
-				if(mode == MODE_B) {
-					block[0] = '\0';
-					*(u16_t *)&block[1] = htons(op - bufout);
-					write(ftpdata_fd, block, sizeof(block));
-				}
-				write(ftpdata_fd, bufout, op - bufout);
-				op = bufout;
-			}
-		}
-	} else {
-		if(mode == MODE_B) {
-			block[0] = '\0';
-			*(u16_t *)&block[1] = htons(s);
-			write(ftpdata_fd, block, sizeof(block));
-		}
-		s = write(ftpdata_fd, buffer, s);
-	}
-   }
-   if(op > bufout) {
-	if(mode == MODE_B) {
-		block[0] = MODE_B_EOF;
-		*(u16_t *)&block[1] = htons(op - bufout);
-		write(ftpdata_fd, block, sizeof(block));
-	}
-	write(ftpdata_fd, bufout, op - bufout);
-   } else
-	if(mode == MODE_B) {
-		block[0] = MODE_B_EOF;
-		*(u16_t *)&block[1] = htons(0);
-		write(ftpdata_fd, block, sizeof(block));
-	}
-   time(&dataend);
-
-#ifdef DEBUG
-   fprintf(logfile, "ftpd: parent %d end sendfile \n", getpid());
-   fflush(logfile);
-#endif
-
-   endfdxcmd(fd);
-   if(mode != MODE_B) {
-	close(ftpdata_fd); 
-	ftpdata_fd = -1;
-   }
-
-   if(dataend == datastart) dataend++;
-   kbs = (datacount * 100 / (dataend - datastart)) / 1024;
-
-   if(s < 0)
-	printf("451 Transfer aborted.\r\n");
-   else
-	printf("%03d Transfer finished successfully. %ld.%02d KB/s\r\n",
-		mode == MODE_B ? 250 : 226,
-		(long)(kbs / 100), (int)(kbs % 100));
-
-   return(GOOD);
-}
-
-static int recvfile(name, xmode)
-char *name;
-int xmode;
-{
-char *fname;
-time_t datastart, dataend;
-unsigned long datacount;
-long kbs;
-char c;
-char *p;
-char *op, *ope;
-int fd, oflag;
-int s;
-int gotcr;
-off_t sp;
-char block[3];
-unsigned short cnt;
-
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   fname = name;
-
-   switch(xmode) {
-	case RECV_APND:
-		oflag = O_WRONLY | O_APPEND;
-		break;
-	case RECV_UNIQ:
-		fname = uniqname();
-		oflag = O_WRONLY | O_CREAT;
-		break;
-	default:
-		oflag = O_WRONLY | O_CREAT | O_TRUNC;
-   }
-
-   if(file_restart)
-	oflag = O_RDWR;
-
-   fd = open(fname, oflag, (anonymous ? 0000:0600));
-
-   if(fd < 0) {
-	printf(msg550, fname, strerror(errno));
-	return(GOOD);
-   }
-
-   /* log the received file */
-   logit("RECV", path(fname));
-
-   /* set file position at approriate spot */
-   if(file_restart) {
-	if(type == TYPE_A) {
-		sp = 0;
-		while(sp < file_restart) {
-			sp++;
-			s = read(fd, buffer, 1);
-			if(s < 0) {
-				printf(msg550, fname, strerror(errno));
-				close(fd);
-				file_restart = 0;
-				return(GOOD);
-			}
-			if(s == 0) break;
-			if(*buffer == '\n')
-				sp++;
-		}
-	} else {
-		sp = lseek(fd, file_restart, SEEK_SET);
-		if(sp == -1) {
-			printf(msg550, fname, strerror(errno));
-			close(fd);
-			file_restart = 0;
-			return(GOOD);
-		}
-	}
-	if(sp != file_restart) {
-		printf("550 File restart point error. %lu not %lu\r\n", sp, file_restart);
-		close(fd);
-		file_restart = 0;
-		return(GOOD);
-	}
-   }
-   file_restart = 0;
-
-   if(xmode == RECV_UNIQ)
-   	printf("%03d FILE: %s\r\n",
-   		ftpdata_fd >= 0 ? 125 : 150, fname);	/* per RFC1123 4.1.2.9 */
-   else
-	printf("%03d File %s okay.  Opening data connection.\r\n",
-		ftpdata_fd >= 0 ? 125 : 150, fname);
-   fflush(stdout);
-
-   if(DataConnect()) {
-   	close(fd);
-	return(GOOD);
-   }
-
-#ifdef DEBUG
-   fprintf(logfile, "ftpd: parent %d start recvfile \n", getpid());
-   fflush(logfile);
-#endif
-
-   /* start receiving file */
-   datacount = 0;
-   gotcr = 0;
-   op = bufout; ope = bufout + sizeof(bufout) - 3;
-   cnt = 0;
-   time(&datastart);
-   while(1) {
-   	if(mode != MODE_B)
-   		cnt = sizeof(buffer);
-   	else
-   		if(cnt == 0) {
-   			s = read(ftpdata_fd, block, sizeof(block));
-   			cnt = ntohs(*(u16_t *)&block[1]);
-   			s = 0;
-   			if(cnt == 0 && block[0] & MODE_B_EOF)
-   				break;
-   		}
-	s = read(ftpdata_fd, buffer, cnt > sizeof(buffer) ? sizeof(buffer) : cnt);
-	if(s <= 0) break;
-	cnt -= s;
-	datacount += (long)s;
-	if(type == TYPE_A) {
-		p = buffer;
-		while(s-- > 0) {
-			c = *p++;
-			if(gotcr) {
-				gotcr = 0;
-				if(c != '\n')
-					*op++ = '\r';
-			}
-			if(c == '\r')
-				gotcr = 1;
-			else
-				*op++ = c;
-			if(op >= ope) {
-				write(fd, bufout, op - bufout);
-				op = bufout;
-			}
-		}
-	} else
-		write(fd, buffer, s);
-	if(cnt == 0 && mode == MODE_B && block[0] & MODE_B_EOF) {
-		s = 0;
-		break;
-	}
-   }
-   if(gotcr)
-	*op++ = '\r';
-   if(op > bufout)
-	write(fd, bufout, op - bufout);
-   time(&dataend);
-
-#ifdef DEBUG
-   fprintf(logfile, "ftpd: parent %d end recvfile \n", getpid());
-   fflush(logfile);
-#endif
-
-   close(fd);
-   if(mode != MODE_B) {
-	close(ftpdata_fd); 
-	ftpdata_fd = -1;
-   }
-
-   if(dataend == datastart) dataend++;
-   kbs = (datacount * 100 / (dataend - datastart)) / 1024;
-
-   if((mode == MODE_B && cnt != 0) || s != 0)
-	printf("451 Transfer aborted.\r\n");
-   else {
-	printf("%03d Transfer finished successfully. ",
-		mode == MODE_B ? 250 : 226);
-	if(xmode == RECV_UNIQ)
-		printf("Unique file %s. ", fname);
-	printf("%ld.%02d KB/s\r\n", (long)(kbs / 100), (int)(kbs % 100));
-   }
-
-   return(GOOD);
-}
-
-static char *uniqname()
-{
-static char uniq[32];
-int i;
-struct stat st;
-
-   for(i = 0; i < 1000; i++) {
-	sprintf(uniq, "ftpd%d%d", getpid(), i);
-	if(stat(uniq, &st) == -1)
-		return(uniq);
-   }
-   return(uniq);
-}
-
-static char *spath[256];
-static char *path(fname)
-char *fname;
-{
-char dir[128];
-
-   if(getcwd(dir, sizeof(dir)) == (char *)NULL)
-	sprintf(dir, "???");
-
-   if(fname[0] == '/')
-	sprintf((char *)spath, "%s%s", newroot, fname);
-   else
-	if(dir[1] == '\0')
-		sprintf((char *)spath, "%s%s%s", newroot, dir, fname);
-	else
-		sprintf((char *)spath, "%s%s/%s", newroot, dir, fname);
-
-   return((char *)spath);
-}
-
-/* do file detail */
-static int dofdet(buff)
-char *buff;
-{
-struct stat st;
-char ft;
-
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   if(stat(buff, &st)) {
-	printf("501 Could not obtain file detail.\r\n");
-	return(GOOD);
-   }
-   switch(st.st_mode & S_IFMT) {
-   	case S_IFIFO:	ft = 'p'; break;
-   	case S_IFCHR:	ft = 'c'; break;
-   	case S_IFDIR:	ft = 'd'; break;
-   	case S_IFBLK:	ft = 'b'; break;
-   	case S_IFREG:	ft = 'f'; break;
-   	default:	ft = '?'; break;
-   }
-   printf("202 %c %u %u %u %u %u %lu %lu\r\n", 
-   	ft,					/* file type */
-   	st.st_rdev >> 8,			/* Major */
-   	st.st_rdev & 0xff,			/* Minor */
-   	st.st_uid,				/* UID */
-   	st.st_gid,				/* GID */
-   	st.st_mode,				/* File Modes */
-   	st.st_size,				/* SIZE */
-   	st.st_mtime);				/* Mod Time */
-
-   return(GOOD);
-}
Index: trunk/minix/commands/ftpd200/file.h
===================================================================
--- trunk/minix/commands/ftpd200/file.h	(revision 9)
+++ 	(revision )
@@ -1,32 +1,0 @@
-/* file.h Copyright 1992-2000 by Michael Temari All Rights Reserved
- *
- * This file is part of ftpd.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <Michael@TemWare.Com>
- */
-
-_PROTOTYPE(int doALLO, (char *buff));
-_PROTOTYPE(int doAPPE, (char *buff));
-_PROTOTYPE(int doCDUP, (char *buff));
-_PROTOTYPE(int doCWD,  (char *buff));
-_PROTOTYPE(int doDELE, (char *buff));
-_PROTOTYPE(int doLIST, (char *buff));
-_PROTOTYPE(int doMDTM, (char *buff));
-_PROTOTYPE(int doMODE, (char *buff));
-_PROTOTYPE(int doMKD,  (char *buff));
-_PROTOTYPE(int doNLST, (char *buff));
-_PROTOTYPE(int doPWD,  (char *buff));
-_PROTOTYPE(int doREST, (char *buff));
-_PROTOTYPE(int doRETR, (char *buff));
-_PROTOTYPE(int doRMD,  (char *buff));
-_PROTOTYPE(int doRNFR, (char *buff));
-_PROTOTYPE(int doRNTO, (char *buff));
-_PROTOTYPE(int doSITE, (char *buff));
-_PROTOTYPE(int doSIZE, (char *buff));
-_PROTOTYPE(int doSTAT, (char *buff));
-_PROTOTYPE(int doSTOR, (char *buff));
-_PROTOTYPE(int doSTOU, (char *buff));
-_PROTOTYPE(int doSTRU, (char *buff));
-_PROTOTYPE(int doSYST, (char *buff));
-_PROTOTYPE(int doTYPE, (char *buff));
Index: trunk/minix/commands/ftpd200/ftpd.8
===================================================================
--- trunk/minix/commands/ftpd200/ftpd.8	(revision 9)
+++ 	(revision )
@@ -1,161 +1,0 @@
-.\" Copyright (c) 1985 Regents of the University of California.
-.\" All rights reserved.  The Berkeley software License Agreement
-.\" specifies the terms and conditions for redistribution.
-.\"
-.\"	@(#)ftpd.8c	6.4 (Berkeley) 5/28/86
-.\"
-.TH FTPD 8
-.SH NAME
-ftpd, in.ftpd, ftpdsh, setup.anonftp \- DARPA Internet File Transfer Protocol server
-.SH SYNOPSIS
-.B "ftp stream tcp nowait root /usr/bin/in.ftpd in.ftpd"
-.br
-.B "tcpd ftp /usr/bin/in.ftpd"
-.SH DESCRIPTION
-.B Ftpd
-is the DARPA Internet File Transfer Prototocol
-server process.  The server uses the TCP protocol
-and listens at the port specified in the ``ftp''
-service specification; see
-.BR services (5).
-.PP
-The ftp server currently supports the following ftp
-requests;  case is not distinguished.
-.PP
-.nf
-.ta \w'Request        'u
-\fBRequest	Description\fP
-ABOR	abort previous command
-ACCT	specify account (ignored)
-ALLO	allocate storage (vacuously)
-APPE	append to a file
-CDUP	change to parent of current working directory
-CWD	change working directory
-DELE	delete a file
-HELP	give help information
-LIST	give list files in a directory (``ls -lA'')
-MKD	make a directory
-MODE	specify data transfer \fImode\fP
-NLST	give name list of files in directory (``ls'')
-NOOP	do nothing
-PASS	specify password
-PASV	prepare for server-to-server transfer
-PORT	specify data connection port
-PWD	print the current working directory
-QUIT	terminate session
-RETR	retrieve a file
-RMD	remove a directory
-RNFR	specify rename-from file name
-RNTO	specify rename-to file name
-STOR	store a file
-STOU	store a file with a unique name
-STRU	specify data transfer \fIstructure\fP
-TYPE	specify data transfer \fItype\fP
-USER	specify user name
-XCUP	change to parent of current working directory
-XCWD	change working directory
-XMKD	make a directory
-XPWD	print the current working directory
-XRMD	remove a directory
-.fi
-.PP
-The remaining ftp requests specified in Internet RFC 959 are
-recognized, but not implemented.
-.PP
-The ftp server will abort an active file transfer only when the
-ABOR command is preceded by a Telnet "Interrupt Process" (IP)
-signal and a Telnet "Synch" signal in the command Telnet stream,
-as described in Internet RFC 959.
-.PP
-.B Ftpd
-interprets file names according to the ``globbing''
-conventions used by
-.BR csh (1).
-This allows users to utilize the metacharacters ``*?[]{}~''.
-.PP
-.B Ftpd
-authenticates users according to two rules. 
-.IP 1)
-The user name must be in the password data base,
-.BR /etc/passwd ,
-and not have a null password.  In this case a password
-must be provided by the client before any file operations
-may be performed.
-.IP 2)
-If the user name is ``anonymous'' or ``ftp'', an
-anonymous ftp account must be present in the password
-file (user ``ftp'').  In this case the user is allowed
-to log in by specifying any password (by convention this
-is given as the client host's name).
-.PP
-In the last case, 
-.B ftpd
-takes special measures to restrict the client's access privileges.
-The server performs a 
-.BR chroot (2)
-command to the home directory of the ``ftp'' user.
-In order that system security is not breached, it is recommended
-that the ``ftp'' subtree be constructed with care;  the following
-rules are recommended.
-.IP ~ftp)
-Make the home directory owned by ``ftp'' and unwritable by anyone.
-.IP ~ftp/bin)
-Make this directory owned by the super-user and unwritable by
-anyone.  The program
-.BR ls (1)
-must be present to support the list commands.  
-Also, 
-.BR crc (1) 
-must be present to support generating crcs using the site command, 
-.BR tar (1)
-and 
-.BR compress (1)
-must be present to support on-the-fly generation of .tar and .tar.Z archives, 
-.BR gzip (1)
-must be present to support gzip compression, and 
-.BR sh (1)
-must be present to support 
-.BR ftpdsh (8)
-which also must be present. 
-.BR ftpdsh controls which binaries can be used.
-These programs should all have mode 111.
-.IP ~ftp/etc)
-Make this directory owned by the super-user and unwritable by
-anyone.  The files
-.BR passwd (5)
-and
-.BR group (5)
-must be present for the 
-.B ls
-command to work properly.  These files should be mode 444. They can (and 
-should) be stripped down versions so as not to reveal names of users who
-are not owners of files in the ~ftp/pub directory tree. 
-.IP ~ftp/pub)
-Make this directory mode 755 and owned by the super-user.  Create
-directories in it owned by users if those users want to manage an
-anonymous ftp directory.
-.IP ~ftp/pub/incoming)
-Optionally create this directory for anonymous uploads.  Make it mode
-777.  The FTP daemon will create files with mode 266, so remote users
-can write a file, but only local users can do something with it.
-.PP
-The script
-.B setup.anonftp
-can be used to create or check an anonymous FTP tree.
-.SH "SEE ALSO"
-.BR ftp (1).
-.SH BUGS
-The anonymous account is inherently dangerous and should
-avoided when possible.
-.ig \" Minix doesn't have privileged port numbers (yet?)
-.PP
-The server must run as the super-user
-to create sockets with privileged port numbers.  It maintains
-an effective user id of the logged in user, reverting to
-the super-user only when binding addresses to sockets.  The
-possible security holes have been extensively
-scrutinized, but are possibly incomplete.
-..
-.\" man page updated by Al Woodhull 2005-02-25
-
-
Index: trunk/minix/commands/ftpd200/ftpd.c
===================================================================
--- trunk/minix/commands/ftpd200/ftpd.c	(revision 9)
+++ 	(revision )
@@ -1,405 +1,0 @@
-/* ftpd.c Copyright 1992-2000 by Michael Temari All Rights Reserved
- *
- * ftpd         An FTP server program for use with Minix.
- *
- * Usage:       Minix usage: tcpd ftp ftpd
- *
- * 06/14/92 Tnet Release	Michael Temari
- * 01/15/96 0.30		Michael Temari
- * 01/25/96 0.90		Michael Temari
- * 03/17/96 0.91		Michael Temari
- * 06/27/96 0.92		Michael Temari
- * 07/02/96 0.93		Michael Temari
- * 07/15/96 0.94		Michael Temari
- * 08/27/96 0.95		Michael Temari
- * 02/09/97 0.96		Michael Temari
- * 02/10/97 0.97		Michael Temari
- * 09/25/97 0.98		Michael Temari
- * 03/10/00 0.99		Michael Temari, <Michael@TemWare.Com>
- * 12/12/03 1.00		Michael Temari, <Michael@TemWare.Com>
- * 02/06/05 1.01		Michael Temari, <Michael@TemWare.Com>
- * 02/12/05 2.00		Michael Temari, <Michael@TemWare.Com>
- */
-
-char *FtpdVersion = "2.00";
-
-#include <sys/types.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <net/gen/in.h>
-#include <net/gen/tcp.h>
-
-#include "ftpd.h"
-#include "access.h"
-#include "file.h"
-#include "net.h"
-
-_PROTOTYPE(static void init, (void));
-_PROTOTYPE(static int doHELP, (char *buff));
-_PROTOTYPE(static int doNOOP, (char *buff));
-_PROTOTYPE(static int doUNIMP, (char *buff));
-_PROTOTYPE(static int getline, (char *line, int len));
-
-FILE *msgfile = (FILE *)NULL;
-
-/* The following defines the inactivity timeout in seconds */
-#define	INACTIVITY_TIMEOUT	60*5
-
-char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
-char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
-		  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
-
-char line[512];
-
-int type, format, mode, structure;
-int ftpdata_fd = -1;
-int loggedin, gotuser, anonymous;
-char username[80];
-char anonpass[128];
-char newroot[128];
-
-ipaddr_t myipaddr, rmtipaddr, dataaddr;
-tcpport_t myport, rmtport, dataport;
-
-char myhostname[256], rmthostname[256];
-
-#define	FTPD_LOG	"/usr/adm/ftpd.log"
-#define	FTPD_MSG	"/etc/ftpd_msg"
-
-FILE *logfile;
-
-int timeout = 0;
-
-_PROTOTYPE(static int doHELP, (char *buff));
-_PROTOTYPE(int readline, (char **args));
-_PROTOTYPE(void Timeout, (int sig));
-_PROTOTYPE(int main, (int argc, char *argv[]));
-
-struct commands {
-	char *name;
-	_PROTOTYPE(int (*func), (char *buff));
-};
-
-struct commands commands[] = {
-	"ABOR", doUNIMP,
-	"ACCT", doUNIMP,
-	"ALLO", doALLO,
-	"APPE", doAPPE,
-	"CDUP", doCDUP,
-	"CWD",  doCWD,
-	"DELE", doDELE,
-	"HELP", doHELP,
-	"LIST", doLIST,
-	"MDTM", doMDTM,
-	"MKD",  doMKD,
-	"MODE", doMODE,
-	"NLST", doNLST,
-	"NOOP", doNOOP,
-	"PASS", doPASS,
-	"PASV", doPASV,
-	"PORT", doPORT,
-	"PWD",  doPWD,
-	"QUIT", doQUIT,
-	"REIN", doUNIMP,
-	"REST", doREST,
-	"RETR", doRETR,
-	"RMD",  doRMD,
-	"RNFR", doRNFR,
-	"RNTO", doRNTO,
-	"SITE", doSITE,
-	"SIZE", doSIZE,
-	"SMNT", doUNIMP,
-	"STAT", doSTAT,
-	"STOR", doSTOR,
-	"STOU", doSTOU,
-	"STRU", doSTRU,
-	"SYST", doSYST,
-	"TYPE", doTYPE,
-	"USER", doUSER,
-	"XCUP", doCDUP,
-	"XCWD", doCWD,
-	"XMKD", doMKD,
-	"XPWD", doPWD,
-	"XRMD", doRMD,
-	"",     (int (*)())0
-};
-
-static void init()
-{
-   loggedin = 0;
-   gotuser = 0;
-   anonymous = 0;
-   newroot[0] = '\0';
-   type = TYPE_A;
-   format = 0;
-   mode = MODE_S;
-   structure = 0;
-   ftpdata_fd = -1;
-   username[0] = '\0';
-   anonpass[0] = '\0';
-}
-
-/* nothing, nada, zilch... */
-static int doNOOP(buff)
-char *buff;
-{
-   printf("200 NOOP to you too!\r\n");
-
-   return(GOOD);
-}
-
-/* giv'em help, what a USER! */
-static int doHELP(buff)
-char *buff;
-{
-struct commands *cmd;
-char star;
-int i;
-char *space = "    ";
-
-   printf("214-Here is a list of available ftp commands\r\n");
-   printf("    Those with '*' are not yet implemented.\r\n");
-
-   i = 0;
-   for(cmd = commands; *cmd->name != '\0'; cmd++) {
-	if(cmd->func == doUNIMP)
-		star = '*';
-	else
-		star = ' ';
-	printf("     %s%c%s", cmd->name, star, space + strlen(cmd->name));
-	if(++i == 6) {
-		printf("\r\n");
-		i = 0;
-	}
-   }
-
-   if(i)
-	printf("\r\n");
-
-   printf("214 That's all the help you get.\r\n");
-
-   return(GOOD);
-}
-
-/* not implemented */
-static int doUNIMP(buff)
-char *buff;
-{
-   printf("502 Command \"%s\" not implemented!\r\n", line);
-
-   return(GOOD);
-}
-
-/* convert line for use */
-void cvtline(args)
-char **args;
-{
-char *p;
-
-   p = line + strlen(line);
-   while(--p >= line)
-	if(*p == '\r' || *p == '\n' || isspace(*p))
-		*p = '\0';
-	else
-		break;
-
-  p = line;
-
-#ifdef DEBUG
-  logit("COMMAND", line);
-#endif
-
-  while(*p && !isspace(*p)) {
-	*p = toupper(*p);
-	p++;
-  }
-
-  if(*p) {
-	*p = '\0';
-	p++;
-	while(*p && isspace(*p))
-		p++;
-   }
-
-   *args = p;
-
-   return;
-}
-
-static int getline(line, len)
-char *line;
-int len;
-{
-int s;
-int gotcr;
-
-   /* leave room for at end for null */
-   len--;
-
-   /* got to be able to put in at least 1 character */
-   if(len < 1)
-	return(-1);
-
-   gotcr = 0;
-   while(len-- > 0) {
-	s = read(0, line, 1);
-	if(s != 1)
-		return(-1);
-	if(*line == '\n')
-		break;
-	gotcr = (*line == '\r');
-	line++;
-   }
-   if(gotcr)
-	--line;
-
-   *line = '\0';
-
-   return(0);
-}
-
-int readline(args)
-char **args;
-{
-   if(getline(line, sizeof(line)))
-	return(BAD);
-
-   cvtline(args);
-
-   return(GOOD);
-}
-
-/* signal handler for inactivity timeout */
-void Timeout(sig)
-int sig;
-{
-   timeout = 1;
-
-   printf("421 Inactivity timer expired.\r\n");
-}
-
-/* logit */
-void logit(type, parm)
-char *type;
-char *parm;
-{
-time_t now;
-struct tm *tm;
-
-   if(logfile == (FILE *)NULL)
-	return;
-
-   time(&now);
-   tm = localtime(&now);
-   fprintf(logfile, "%4d%02d%02d%02d%02d%02d ",
-	1900+tm->tm_year,
-	tm->tm_mon + 1,
-	tm->tm_mday,
-	tm->tm_hour, tm->tm_min, tm->tm_sec);
-   fprintf(logfile, "%s %s %s %s %s\n",
-	rmthostname, username, anonymous ? anonpass : username, type, parm);
-   fflush(logfile);
-}
-
-void showmsg(reply, filename)
-char *reply;
-char *filename;
-{
-FILE *mfp;
-char *pe;
-static char mline[256];
-
-   if(filename == (char *)NULL)
-	mfp = msgfile;
-   else
-	mfp = fopen(filename, "r");
-
-   if(mfp == (FILE *)NULL)
-	return;
-
-   while(fgets(mline, sizeof(mline), mfp) != (char *)NULL) {
-	pe = mline + strlen(mline);
-	while(--pe >= mline)
-		if(*pe == '\r' || *pe == '\n')
-			*pe = '\0';
-		else
-			break;
-	printf("%s- %s\r\n", reply, mline);
-   }
-
-   if(filename != (char *)NULL)
-	fclose(mfp);
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-struct commands *cmd;
-char *args;
-int status;
-time_t now;
-struct tm *tm;
-int s;
-
-   GetNetInfo();
-
-   /* open transfer log file if it exists */
-   if((logfile = fopen(FTPD_LOG, "r")) != (FILE *)NULL) {
-	fclose(logfile);
-	logfile = fopen(FTPD_LOG, "a");
-   }
-
-   /* open login msg file */
-   msgfile = fopen(FTPD_MSG, "r");
-
-   /* Let's initialize some stuff */
-   init();
-
-   /* Log the connection */
-   logit("CONNECT", "");
-
-   /* Tell 'em we are ready */
-   time(&now);
-   tm = localtime(&now);
-   printf("220 FTP service (Ftpd %s) ready on %s at ",
-   	FtpdVersion, myhostname);
-   printf("%s, %02d %s %d %02d:%02d:%02d %s\r\n", days[tm->tm_wday],
-   	tm->tm_mday, months[tm->tm_mon], 1900+tm->tm_year,
-	tm->tm_hour, tm->tm_min, tm->tm_sec,
-	tzname[tm->tm_isdst]);
-   fflush(stdout);
-
-   /* Loop here getting commands */
-   while(1) {
-	signal(SIGALRM, Timeout);
-	alarm(INACTIVITY_TIMEOUT);
-	if(readline(&args) != GOOD) {
-		if(!timeout)
-			printf("221 Control connection closing (EOF).\r\n");
-		break;
-	}
-	alarm(0);
-	for(cmd = commands; *cmd->name != '\0'; cmd++)
-		if(!strcmp(line, cmd->name))
-			break;
-	if(*cmd->name != '\0')
-		status = (*cmd->func)(args);
-	else {
-		printf("500 Command \"%s\" not recognized.\r\n", line);
-		status = GOOD;
-	}
-	fflush(stdout);
-	if(status != GOOD)
-		break;
-   }
-
-   CleanUpPasv();
-
-   return(-1);
-}
Index: trunk/minix/commands/ftpd200/ftpd.h
===================================================================
--- trunk/minix/commands/ftpd200/ftpd.h	(revision 9)
+++ 	(revision )
@@ -1,37 +1,0 @@
-/* ftpd.h Copyright 1992-2000 by Michael Temari All Rights Reserved
- *
- * This file is part of ftpd.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <Michael@TemWare.Com>
- */
-
-#define	GOOD	0
-#define	BAD	1
-
-#define	TYPE_A	0
-#define	TYPE_I	1
-
-#define	MODE_S	0
-#define	MODE_B	1
-
-#define	MODE_B_EOF	64
-
-extern char *FtpdVersion;
-extern int type, format, mode, structure;
-extern ipaddr_t myipaddr, rmtipaddr, dataaddr;
-extern tcpport_t myport, rmtport, dataport;
-extern int ftpdata_fd;
-extern int loggedin, gotuser, anonymous;
-extern char newroot[128];
-extern char *days[], *months[];
-extern char username[80];
-extern char anonpass[128];
-extern char myhostname[256], rmthostname[256];
-extern char line[512];
-
-extern FILE *logfile;
-
-_PROTOTYPE(void cvtline, (char **args));
-_PROTOTYPE(void logit, (char *type, char *parm));
-_PROTOTYPE(void showmsg, (char *reply, char *filename));
Index: trunk/minix/commands/ftpd200/ftpdsh
===================================================================
--- trunk/minix/commands/ftpd200/ftpdsh	(revision 9)
+++ 	(revision )
@@ -1,14 +1,0 @@
-#!/bin/sh
-
-case $1 in
-	1)	ls -A $2 ;;
-	2)	ls -la $2 ;;
-	3)	crc $2 ;;
-	12)	tar cf - $2 ;;
-	13)	tar cf - $2 | compress -q ;;
-	14)	compress -cq $2 ;;
-	15)	tar cf - $2 | gzip ;;
-	16)	tar -c $2 ;;
-	17)	compress -dcq $2 ;;
-esac
-exit
Index: trunk/minix/commands/ftpd200/net.c
===================================================================
--- trunk/minix/commands/ftpd200/net.c	(revision 9)
+++ 	(revision )
@@ -1,431 +1,0 @@
-/* net.c Copyright 1992-2000 by Michael Temari All Rights Reserved
- *
- * This file is part of ftpd.
- *
- * This file handles:
- *
- *      PASV PORT
- *
- *
- * 01/25/1995 Initial Release	Michael Temari, <Michael@TemWare.Com>
- * 02/09/2005 Initial Release	Michael Temari, <Michael@TemWare.Com>
- */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-#include <time.h>
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include <net/gen/socket.h>
-#include <net/gen/netdb.h>
-
-#include "ftpd.h"
-#include "access.h"
-#include "net.h"
-
-_PROTOTYPE(static void timeout, (int sig));
-
-static char *msg425 = "425-Could not open data connection.\r\n";
-static char *msg501 = "501 Syntax error in parameters.\r\n";
-
-static int gottimeout = 0;
-static int lpid = -1;
-static int didpassive = 0;
-
-/* they must be behind a firewall or using a web browser */
-int doPASV(buff)
-char *buff;
-{
-nwio_tcpconf_t tcpconf;
-nwio_tcpcl_t tcplopt;
-char *tcp_device;
-ipaddr_t ipaddr;
-tcpport_t lport;
-int s;
-time_t starttime;
-int retry;
-
-   if(ChkLoggedIn())
-	return(GOOD);
-
-   CleanUpPasv();
-
-   /* here we set up a connection to listen on */
-   if((tcp_device = getenv("TCP_DEVICE")) == NULL)
-	tcp_device = TCP_DEVICE;
-
-   if(ftpdata_fd >= 0) {
-	close(ftpdata_fd);
-	ftpdata_fd = -1;
-   }
-
-   if((ftpdata_fd = open(tcp_device, O_RDWR)) < 0) {
-	printf(msg425); 
-	printf("425 Could not open tcp_device.  Error %s\r\n", strerror(errno));
-	return(GOOD);
-   }
-
-   tcpconf.nwtc_flags = NWTC_LP_SEL | NWTC_SET_RA | NWTC_UNSET_RP;
-
-   tcpconf.nwtc_remaddr = rmtipaddr;
-   tcpconf.nwtc_remport = htons(0);
-   tcpconf.nwtc_locport = htons(0);
-
-   s = ioctl(ftpdata_fd, NWIOSTCPCONF, &tcpconf);
-   if(s < 0) {
-	printf(msg425);
-	printf("425 Could not ioctl NWIOSTCPCONF. Error %s\r\n", strerror(errno));
-	close(ftpdata_fd);
-	ftpdata_fd = -1;
-	return(GOOD);
-   }
-
-   s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-	printf(msg425);
-	printf("425 Could not NWIOGTCPCONF. Error %s\r\n", strerror(errno));
-	close(ftpdata_fd);
-	ftpdata_fd = -1;
-	return(GOOD);
-   }
-   ipaddr = tcpconf.nwtc_locaddr;
-   lport = tcpconf.nwtc_locport;
-
-   /* Now lets fork a child to do the listening :-( */
-
-   tcplopt.nwtcl_flags = 0;
-
-   lpid = fork();
-   if(lpid < 0) {
-	printf(msg425);
-	printf("425 Could not fork listener.  Error %s\r\n", strerror(errno));
-	close(ftpdata_fd);
-	ftpdata_fd = -1;
-	return(GOOD);
-   } else if(lpid == 0) {
-	retry = 0;
-	while(1) {
-#ifdef DEBUG
-		fprintf(logfile, "ftpd: child %d  parent %d  listen try %d\n", getpid(), getppid(), retry);
-		fflush(logfile);
-#endif
-		s = ioctl(ftpdata_fd, NWIOTCPLISTEN, &tcplopt);
-		if(!(s == -1 && errno == EAGAIN)) break;
-		if(retry++ > 10) break;
-		sleep(1);
-	}
-#ifdef DEBUG
-	fprintf(logfile, "ftpd: child %d  s %d  errno %d\n", getpid(), s, errno);
-	fflush(logfile);
-#endif
-	if(s < 0) 
-		exit(errno);	/* tells parent listen failed */
-	else
-		exit(0);	/* tells parent listen okay */
-   }
-
-#ifdef DEBUG
-   fprintf(logfile, "ftpd: parent %d  wait for %d\n", getpid(), lpid);
-   fflush(logfile);
-#endif
-
-   /* wait for child to be listening, no more than serveral seconds */
-   (void) time(&starttime);
-   while(1) {
-	if(time((time_t *)NULL) > (starttime + 15)) break;
-   	signal(SIGALRM, timeout);
-   	alarm(1);
-   	s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
-#ifdef DEBUG
-	fprintf(logfile, "ftpd: parent %d  child %d  s %d  errno %d start %ld  now %ld\n",
-		getpid(), lpid, s, errno, starttime, time((time_t *)NULL));
-	fflush(logfile);
-#endif
-   	alarm(0);
-   	if(s == -1) break;
-	sleep(1);
-   }
-
-#define hiword(x)       ((u16_t)((x) >> 16))
-#define loword(x)       ((u16_t)(x & 0xffff)) 
-#define hibyte(x)       (((x) >> 8) & 0xff)
-#define lobyte(x)       ((x) & 0xff)
-
-   printf("227 Entering Passive Mode (%u,%u,%u,%u,%u,%u).\r\n",
-		hibyte(hiword(htonl(ipaddr))), lobyte(hiword(htonl(ipaddr))),
-		hibyte(loword(htonl(ipaddr))), lobyte(loword(htonl(ipaddr))),
-		hibyte(htons(lport)), lobyte(htons(lport)));
-
-#ifdef DEBUG
-   fprintf(logfile, "ftpd: parent %d  child %d  send 227\n", getpid(), lpid);
-   fflush(logfile);
-#endif
-
-   didpassive = -1;
-
-   return(GOOD);
-}
-
-/* they want us to connect here */
-int doPORT(buff)
-char *buff;
-{
-u32_t ipaddr;
-u16_t port;
-int i;
-
-   if(ftpdata_fd >= 0) {
-	close(ftpdata_fd);
-	ftpdata_fd = -1;
-   }
-
-   ipaddr = (u32_t)0;
-   for(i = 0; i < 4; i++) {
-	ipaddr = (ipaddr << 8) + (u32_t)atoi(buff);
-	if((buff = strchr(buff, ',')) == (char *)0) {
-		printf(msg501);
-		return(GOOD);
-	}
-	buff++;
-   }
-   port = (u16_t)atoi(buff);
-   if((buff = strchr(buff, ',')) == (char *)0) {
-	printf(msg501);
-	return(0);
-   }
-   buff++;
-   port = (port << 8) + (u16_t)atoi(buff);
-
-   dataaddr = htonl(ipaddr);
-   dataport = htons(port);
-   if(dataaddr != rmtipaddr) {
-	printf(msg501);
-	return(GOOD);
-   }
-
-   printf("200 Port command okay.\r\n");
-
-   return(GOOD);
-}
-
-/* connect, huh? */
-int DataConnect()
-{
-nwio_tcpconf_t tcpconf;
-nwio_tcpcl_t tcpcopt;
-nwio_tcpcl_t tcplopt;
-char *tcp_device;
-int s, cs;
-int retry;
-
-   if(didpassive && ftpdata_fd >= 0) {
-   	didpassive = 0;
-	gottimeout = 0;
-   	signal(SIGALRM, timeout);
-   	alarm(10);
-	while(!gottimeout) {
-		s = waitpid(lpid, &cs, 0);
-		if((s == lpid) || (s < 0 && errno == ECHILD)) break;
-#ifdef DEBUG
-		fprintf(logfile, "ftpd: parent %d  child %d waitpid s %d  cs %04x  errno %d\n", getpid(), lpid, s, cs, errno);
-		fflush(logfile);
-#endif
-	}
-	alarm(0);
-#ifdef DEBUG
-	fprintf(logfile, "ftpd: parent %d  child %d waitpid s %d  cs %04x  errno %d\n", getpid(), lpid, s, cs, errno);
-		fflush(logfile);
-#endif
-	if(gottimeout) {
-#ifdef DEBUG
-		fprintf(logfile, "ftpd: parent %d  child %d  got timeout\n", getpid(), lpid);
-		fflush(logfile);
-#endif
-		kill(lpid, SIGKILL);
-		s = waitpid(lpid, &cs, 0);
-	}
-#ifdef DEBUG
-	fprintf(logfile, "ftpd: parent %d  child %d continuing\n", getpid(), lpid);
-	fflush(logfile);
-#endif
-	lpid = -1;
-	if(gottimeout) {
-		printf(msg425);
-		printf("425 Child listener timeout.\r\n");
-		close(ftpdata_fd);
-		ftpdata_fd = -1;
-		return(BAD);
-	}
-	if(s < 0) {
-		printf(msg425);
-		printf("425 Child listener vanished.\r\n");
-		close(ftpdata_fd);
-		ftpdata_fd = -1;
-		return(BAD);
-	}
-	if((cs & 0x00ff)) {
-		printf(msg425);
-		printf("425 Child listener failed %04x\r\n", cs);
-		close(ftpdata_fd);
-		ftpdata_fd = -1;
-		return(BAD);
-	}
-	cs = (cs >> 8) & 0x00ff;
-	if(cs) {
-		printf(msg425);
-		printf("425 Child listener error %s\r\n", strerror(cs));
-		close(ftpdata_fd);
-		ftpdata_fd = -1;
-		return(BAD);
-	}
-#ifdef DEBUG
-	fprintf(logfile, "ftpd: parent %d  child %d pasv done\n", getpid(), lpid);
-	fflush(logfile);
-#endif
-	return(GOOD);
-   }
-
-   if(ftpdata_fd >= 0)
-   	return(GOOD);
-
-   if((tcp_device = getenv("TCP_DEVICE")) == NULL)
-	tcp_device = TCP_DEVICE;
-
-   if((ftpdata_fd = open(tcp_device, O_RDWR)) < 0) {
-	printf(msg425);
-	printf("425 Could not open tcp_device. Error %s\r\n", strerror(errno));
-	return(BAD);
-   }
-
-   tcpconf.nwtc_flags = NWTC_LP_SET | NWTC_SET_RA | NWTC_SET_RP;
-   tcpconf.nwtc_remaddr = dataaddr;
-   tcpconf.nwtc_remport = dataport;
-   tcpconf.nwtc_locport = htons(20);
-
-   s = ioctl(ftpdata_fd, NWIOSTCPCONF, &tcpconf);
-   if(s < 0) {
-	printf(msg425);
-	printf("425 Could not ioctl NWIOSTCPCONF. Error %s\r\n", strerror(errno));
-	close(ftpdata_fd);
-	ftpdata_fd = -1;
-	return(BAD);
-   }
-
-   s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-	printf(msg425);
-	printf("425 Could not ioctl NWIOGTCPCONF. Error %s\r\n", strerror(errno));
-	close(ftpdata_fd);
-	ftpdata_fd = -1;
-	return(BAD);
-   }
-
-   tcpcopt.nwtcl_flags = 0;
-
-   retry = 0;
-   do  {
-#ifdef DEBUG
-	fprintf(logfile, "try connect\n"); fflush(logfile);
-	fflush(logfile);
-#endif
-	sleep(2);
-	s = ioctl(ftpdata_fd, NWIOTCPCONN, &tcpcopt);
-#ifdef DEBUG
-	fprintf(logfile, "after connect %d %d\n", s, errno);
-	fflush(logfile);
-#endif
-	if(!(s == -1 && errno == EAGAIN)) break;
-	if(retry++ > 10) break;
-	sleep(1);
-   } while(1);
-   if(s < 0) {
-	printf(msg425);
-	printf("425 Could not ioctl NWIOTCPCONN. Error %s\r\n", strerror(errno));
-	close(ftpdata_fd);
-	ftpdata_fd = -1;
-	return(BAD);
-   }
-
-   s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-	printf(msg425);
-	printf("425 Could not ioctl NWIOGTCPCONF. Error %s\r\n", strerror(errno));
-	close(ftpdata_fd);
-	ftpdata_fd = -1;
-	return(BAD);
-   }
-
-   return(GOOD);
-}
-
-/* Clean up stuff we did to get a Pasv connection going */
-int CleanUpPasv()
-{
-int s, cs;
-
-   if(lpid >= 0) {
-	kill(lpid, SIGKILL);
-	while(1) {
-		s = waitpid(lpid, &cs, 0);
-		if(s == lpid || (s == -1 && errno == ECHILD))
-			break;
-	}
-   }
-
-   lpid = -1;
-
-   didpassive = 0;
-
-   return(GOOD);
-}
-
-void GetNetInfo()
-{
-nwio_tcpconf_t tcpconf;
-int s;
-struct hostent *hostent;
-
-   /* Ask the system what our hostname is. */
-   if(gethostname(myhostname, sizeof(myhostname)) < 0)
-	strcpy(myhostname, "unknown");
-
-   /* lets get our ip address and the clients ip address */
-   s = ioctl(0, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-	printf("421 FTP service unable to get remote ip address. Closing.\r\n");
-	fflush(stdout);
-	exit(1);
-   }
-
-   myipaddr = tcpconf.nwtc_locaddr;
-   myport = tcpconf.nwtc_locport;
-   rmtipaddr = tcpconf.nwtc_remaddr;
-   rmtport = tcpconf.nwtc_remport;
-
-   /* Look up the host name of the remote host. */
-   hostent = gethostbyaddr((char *) &rmtipaddr, sizeof(rmtipaddr), AF_INET);
-   if(!hostent)
-	strcpy(rmthostname, inet_ntoa(rmtipaddr));
-   else {
-	strncpy(rmthostname, hostent->h_name, sizeof(rmthostname)-1);
-	rmthostname[sizeof(rmthostname)-1] = '\0';
-   }
-}
-
-static void timeout(sig)
-int sig;
-{
-   gottimeout = 1;
-}
Index: trunk/minix/commands/ftpd200/net.h
===================================================================
--- trunk/minix/commands/ftpd200/net.h	(revision 9)
+++ 	(revision )
@@ -1,13 +1,0 @@
-/* net.h Copyright 1992-2000 by Michael Temari All Rights Reserved
- *
- * This file is part of ftpd.
- *
- *
- * 01/25/96 Initial Release	Michael Temari, <Michael@TemWare.Com>
- */
-
-_PROTOTYPE(int doPASV, (char *buff));
-_PROTOTYPE(int doPORT, (char *buff));
-_PROTOTYPE(int DataConnect, (void));
-_PROTOTYPE(int CleanUpPasv, (void));
-_PROTOTYPE(void GetNetInfo, (void));
Index: trunk/minix/commands/ftpd200/setup.anonftp
===================================================================
--- trunk/minix/commands/ftpd200/setup.anonftp	(revision 9)
+++ 	(revision )
@@ -1,75 +1,0 @@
-#!/bin/sh
-# setup.anonftp - Anonymous FTP setup and maintenance.
-#
-# 01/22/96 Initial Release	Al Woodhul, <asw@hampshire.edu>
-# 01/25/96			Michael Temari, <temari@ix.netcom.com>
-#
-
-# What is needed for anon ftp
-
-# ref: Hunt TCP/IP Net Admin pp. 338++
-# ref: Nemeth et al UNIX System Admin Handbook p. 295
-# ref: mail from M. Temari 18.01.96
-
-# programs possibly used by ftpd
-PROGS="sh ls crc tar compress gzip"
-
-echo Checking /etc/passwd
-if grep '^ftp:[^:]*:[1-9][0-9]*:[1-9][0-9]*:[^:]*:/[^:]*:[^:]*$' \
-						/etc/passwd >/dev/null
-then
-  echo -n "OK, ftp entry found: "
-  grep '^ftp:' /etc/passwd
-else
-  echo "Found no entry for ftp in /etc/passwd, please add one with the"
-  echo "home directory pointing to the anonymous FTP directory"
-  exit 1
-fi
-
-# ftp directory
-FTPDIR="`sed '/^ftp:/!d; s/^.*:\\([^:]*\\):[^:]*/\\1/' /etc/passwd`"
-
-if [ `whoami` != root ]
-then
-  echo You must be root to do this
-  exit 1
-fi
-
-echo Setting up for anonymous ftp
-
-echo Making $FTPDIR and subdirectories
-install -d -m 755 -o root -g operator $FTPDIR
-install -d -m 751 -o root -g operator $FTPDIR/bin
-install -d -m 751 -o root -g operator $FTPDIR/dev
-install -d -m 751 -o root -g operator $FTPDIR/etc
-install -d -m 755 -o root -g operator $FTPDIR/pub
-incoming=
-if [ -d $FTPDIR/pub/incoming ]
-then
-	incoming=t
-elif [ -t 0 ]
-then
-	echo -n "Create \"incoming\" directory? [n] "; read yn
-	case "$yn" in
-	[yY]*|ok|sure)	incoming=t
-	esac
-fi
-test "$incoming" && install -d -m 777 -o root -g operator $FTPDIR/pub/incoming
-
-echo Copying files
-for PROG in $PROGS
-do
-  test -f /usr/bin/$PROG && install -lcs /usr/bin/$PROG $FTPDIR/bin
-done
-cp -rp /dev/tcp $FTPDIR/dev/tcp
-install -lcs ftpdsh $FTPDIR/bin
-
-echo Copying a minimum of the password and group files
-sed 's/^\([^:]*\):[^:]*:\([^:]*:[^:]*\):.*$/\1:*:\2:::/' \
-					/etc/passwd >$FTPDIR/etc/passwd
-sed 's/^\([^:]*\):[^:]*:\([^:]*\):.*$/\1:*:\2:/' \
-					/etc/group >$FTPDIR/etc/group
-chown root:operator $FTPDIR/etc/*
-chmod 444 $FTPDIR/etc/*
-
-echo "Anonymous ftp setup complete"
Index: trunk/minix/commands/httpd/Makefile
===================================================================
--- trunk/minix/commands/httpd/Makefile	(revision 9)
+++ 	(revision )
@@ -1,65 +1,0 @@
-# Makefile for httpd
-#
-# 02/17/1996 			Michael Temari <Michael@TemWare.Com>
-# 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
-# 12/29/2002 			Michael Temari <Michael@TemWare.Com>
-# 07/07/2003			Al Woodhull <awoodhull@hampshire.edu>
-#
-
-CFLAGS=	-O -D_MINIX -D_POSIX_SOURCE -DDAEMON=1
-#CFLAGS=	-O -D_MINIX -D_POSIX_SOURCE -DDAEMON=1 -DDEBUG=9
-LDFLAGS=-i
-BINDIR=/usr/local/bin
-
-HTTPD_OBJS=	httpd.o utility.o request.o process.o reply.o \
-		police.o cgiexec.o net.o config.o pass.o proxy.o
-DIR2HTML_OBJS=	dir2html.o
-
-all:	httpd dir2html
-
-httpd:	$(HTTPD_OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(HTTPD_OBJS)
-	install -S 16kw $@
-
-dir2html:	$(DIR2HTML_OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(DIR2HTML_OBJS)
-	install -S 8kw $@
-
-clean:
-	rm -f httpd $(HTTPD_OBJS) dir2html $(DIR2HTML_OBJS) *.bak
-
-install:	$(BINDIR)/httpd $(BINDIR)/in.httpd $(BINDIR)/dir2html
-
-tar:
-	tar cvf ../httpd.tar Makefile README *.c *.h *.sh *.conf *.mtype
-
-$(BINDIR)/httpd:	httpd
-	install -cs -o bin $? $@
-
-$(BINDIR)/in.httpd:	$(BINDIR)/httpd
-	install -l $? $@
-
-$(BINDIR)/dir2html:	dir2html
-	install -cs -o bin $? $@
-
-httpd.o:	httpd.c		http.h	utility.h	net.h	config.h
-utility.o:	utility.c		utility.h		config.h
-request.o:	request.c	http.h	utility.h		config.h
-process.o:	process.c	http.h	utility.h
-reply.o:	reply.c		http.h	utility.h	net.h	config.h
-police.o:	police.c	http.h	utility.h		config.h pass.h
-cgiexec.o:	cgiexec.c	http.h				config.h
-net.o:		net.c					net.h
-config.o:	config.c		utility.h		config.h
-pass.o:		pass.c		pass.h
-proxy.o:	proxy.c		http.h
-dir2html.o:	dir2html.c
-
-installman:
-	mkdir -p /usr/local/man/man5 
-	mkdir -p /usr/local/man/man8 
-	cp -p httpd.conf.5 http_status.5 /usr/local/man/man5
-	cp -p httpd.8 /usr/local/man/man8
-	makewhatis /usr/local/man
-
-
Index: trunk/minix/commands/httpd/README
===================================================================
--- trunk/minix/commands/httpd/README	(revision 9)
+++ 	(revision )
@@ -1,242 +1,0 @@
-httpd documentation 7/16/96 by Michael Temari <Michael@TemWare.Com>
-updated 2003-07-05 by Al Woodhull <awoodhull@hampshire.edu>
-
-DISCLAIMER:
-
-Use at own risk etc...
-
-
-COMMENTS:
-
-Please send me any bug reports, comments, questions, etc...  My email
-address is Michael@TemWare.Com
-
-
-BACKGROUND:
-
-httpd is a World Wide Web (WWW) server.  I wrote it from scratch so
-the setup and configuration will not be like other web servers though
-hopefully by reading this document there will be no problems in getting
-my web server up and running on your Minix system.
-
-
-COMPILING:
-
-To compile httpd all you need to do is type "make" in the httpd source
-directory.  There should be no errors or warnings.  If you should run
-out of memory when compiling try adding the -m option to the CFLAGS
-list in the Makefile.
-
-
-INSTALLING:
-
-To install httpd all you need to do is type "make install" in the httpd
-source directory.  By default the place to install httpd is into
-/usr/local/bin.  If you would like to change this then change BINDIR in
-the Makefile.  Httpd will be linked to in.httpd, which is the preferred
-name for a program started by the tcpd internet access control program.
-The program dir2html is also installed -- this provides a directory
-listing when a web client accesses a directory which does not contain a
-file named index.html (or an alternative designated in /etc/httpd.conf).
-The man pages are installed by typing "make installman".
-
-CONFIGURING:
-
-Before running httpd it must be configured.  The name of the default
-configuration file is /etc/httpd.conf or you may pass the configuration
-file name to httpd.  Upon starting up, httpd will parse the configuration
-file and then process requests.  This README file and the sample httpd.conf
-may also help in configuring. The httpd.conf.5 man page presents the same
-information for reference use.
-
-
-The configuration file is an ascii file which consists of lines of the
-following form:
-
-directive LWS [parameters separated by LWS]
-
-NOTE: LWS denotes Linear White Space which is spaces and/or tabs
-
-The following are valid configuration file directives:
-  serverroot user chroot logfile dbgfile dirsend direxec vhost auth
-  proxyauth vpath include mtype 
-
-To make the file more readable, on directives which occupy multiple 
-lines you may omit the directive on lines after the first and begin 
-these lines with LWS.
-
-
-serverroot path
-
-The serverroot directive sets the translation for // to the given path.
-
-
-user username
-
-The user directive causes the server to run as the given username, otherwise
-the server will run as whoever started it (normally root).
-
-
-chroot directory
-
-The chroot directive causes the server to chroot to the given directory after
-the configuration and log files have been opened.  Normally this will be the
-home directory of the given username in the user directive.
-NOTE: /~user will be translated to the home directory of the given user
-      // will be translated to the serverroot directory
-NOTE: if this directive is used then beware of the consequences.
-
-
-logfile filename
-
-The logfile directive tells the server where to log http transactions.
-NOTE: the file must exist to enable logging
-
-
-dbgfile filename
-
-The dbgfile directive tells the server where to log debug http transactions.
-NOTE: the file must exist to enable logging
-
-dirsend filelist
-
-The dirsend directive tells the server that when a directory is requested
-that it should send the first file that it finds in the directory from the
-filelist for the request.
-
-
-direxec program
-
-The direxec directive tells the server that when a directory is requested
-and no file is found from the dirsend directive that it should run the
-given program.
-NOTE: the program normally generates a directory listing on the fly
-NOTE: the program access is considered X with no access restrictions.
-
-
-vhost hostname VhostRoot
-
-vhost is for defining access for virtual hosts.  If none are configured then
-any host is accepted.  If specified then access is only granted for requests
-for hosts which are configured here.  In the Vpath section below the /// gets
-translated to the corresponding VhostRoot.
-
-
-auth authname authdescription access [passwdfile [users]]
-
-The auth directive sets up different authorizations with the server.  The
-authname is the name given to the authorization and is case insensitive.
-The authdescription is the description of the authorization and is what
-the user will see when asked to enter a username and password.  The
-access is one or more of (rwx).  R tells the server the url can be
-read.  W tells the server the url can be overwritten.  X tells the server
-that the url can and should be executed.  Access is in addition to normal
-unix security considerations.  For instance a file that can be written to
-that does not have the W access will have an error returned.  The
-passwdfile is the name of the passwdfile to validate users against.  If
-the passwdfile is given as '.' then the system password file will be used
-which is /etc/passwd.  If no passwdfile is given then no authorization is
-allowed for anyone.  If no users are given then any validated users is
-authorized, otherwise only the given users are allowed.
-
-
-proxyauth authname authdescription access [passwdfile [users]]
-
-proxyauth defines any access authorization to be used for Proxy access
-authname = Same as auth above
-authdescription = Same as auth above
-access = Must be R to allow proxy
-passwdfile = Same as auth above
-users = Same as auth above
-
-
-vpath from to [auth [access]]
-
-The vpath directive sets up url path translations and authorizations.  A
-requested url that matches from will be translated to to with the given
-auth and access.  If auth does not exist then the url will have no access.
-If access is not given then the access is taken from the auth record (see
-above).  A '.' in place of the to means that the server should use a
-translation from another vpath record, but associate the given auth and
-access with the requested url.  A '*' maybe at the end only of the from
-which is a wildcard match.  For example if the from has /AB* then any of
-/ABCDEF or /AB or /ABmichael will match, but /AD or /a will not.  The
-requested url is first checked against each vpath record until an exact
-match (meaning url match from and from had no '*') is found or the end of
-the list.  Therefore a wildcard match will match the last from is the list
-in which it matched.
-NOTE: if at the beginning of the to field
-      /~user will get translated to the home directory of the given user
-      // wile get translated to the serverroot directory
-
-
-include filename
-
-The include directive tells the server to read configuration information
-from the given filename.
-NOTE: normally mtype directives are included from another file
-
-
-mtype mimetype extensions
-
-The mtype directive tells the server what mimetype to associate with files
-which have any of the given extensions.  If no match is found then the file
-will be treated as application/octet-stream.
-NOTE: normally you get mtype directives in included file
-
-
-
-USAGE:
-
-		httpd [-v|-t] [configuration-file]
-
-The -t tells the server to just parse the configuration file so that you
-can test it to see if it is the way you want it.  You may also pass the
-name of your configuration file if it is not the default /etc/httpd.conf.
-
-The -v option prints the server version and then exits.
-
-
-STARTING:
-
-First of all httpd is a server and therefore you will need to start it
-with tcpd.  Tcpd is a program which listens for incoming TCP connections
-on the passed port and when a connection comes in it forks and starts the
-given daemon program.  Therefore to start httpd you use:
-
-		tcpd http /usr/local/bin/in.httpd &
-
-You will more than likely have this line in your /etc/rc or /etc/rc.net
-file so that whenever your system is restarted the web server will also
-be started.  The first parameter http is the port that tcpd is going
-to be listening for connections on.  Here http (which should be defined
-in /etc/services as 80) is the standard port for a web server.  The second
-parameter is the program that tcpd will fork and exec when a connection
-comes in.  The program will then have its stdin and stderr connected to
-the client  Then the web server program will start running with the tcpd
-program waiting for the next connection.  Currently there is no ability to
-limit the number of simultaneous web servers running.  NOTE: At some point
-I will be adding the ability for httpd to start itself without the need of
-tcpd.  That way httpd will already be in memory and have parsed its
-configuration file.
-
-In Minix 2.0.3 and later versions you may use:
-
-		daemonize tcpd http /usr/local/bin/in.httpd
-
-(daemonize is a shell function defined in /usr/etc/rc which starts programs
-as daemons).
-
-
-FINAL WORDS
-
-I wanted to get the server out as soon as possible so I hurried up and
-created this document to help out.  Hopefully it will HELP more than
-it HURTS.  If anyone is interested in writing man pages for httpd or any
-of the other network programs please let me know.
-
-
-Michael Temari
-Michael@TemWare.Com
-
-Please note also the SECURITY document in this directory. (asw 2003-07-05)
Index: trunk/minix/commands/httpd/SECURITY
===================================================================
--- trunk/minix/commands/httpd/SECURITY	(revision 9)
+++ 	(revision )
@@ -1,48 +1,0 @@
-SECURITY NOTE 
-
-Al Woodhull <awoodhull@hampshire.edu> 2003-07-05
-
-Running a web server is fun, but it's also not without risks.  If, like
-many Minix users, you are a guest on someone else's network, you need
-to be very careful to operate your server in ways that will not put
-your system at risk or interfere with others on the net.  Here are some
-points to consider: 
-
-- Be sure to touch /usr/adm/httpd.log (or whatever you specify as the log
-file in httpd.conf) before you start your web server for the first time
--- nothing will be logged if the log file does not exist.  Then look at 
-your log file frequently and be alert for any unusual activity.  
-
-- You may also want to be sure that tcpd is configured to operate in
-PARANOID mode.  That will enable logging of connection attempts and
-allow you to use the serv.access (5) file to limit the kinds of
-connections that your system allows.
-
-- If you enable proxy webserving, be very careful, it can be used by
-people you don't know to visit sites that don't welcome visitors whose
-identity is hidden.  This may cause your network host and ultimately you 
-some unpleasantness.
-
-- The Minix httpd can also support CGI applications.  These are also
-dangerous -- a CGI application allows someone else to execute a program
-on your computer.  Make sure anything you allow this way cannot be
-abused. Many security violations are due to effects of input that was not 
-expected by the original author of a program.
-
-- It's an understatement to say that Minix is not a well-known 
-operating system.  There are not many Minix systems operating as
-servers on the internet.  A consequence of this is that there few, if
-any, people engaged in finding ways to attack weaknesses in Minix.  But
-the idea of "security through obscurity" is deprecated by serious
-computer security experts.  Any operating system or program of any
-degree of complexity is likely to have bugs or features that can be
-exploited in ways the original programmers did not foresee.  You can't
-count on the "good guys" being the first ones to discover a risk.
-There are two things you should be sure to do if you are running a
-network server of any kind: 
-
-(1) be alert for new versions of the program that may fix bugs
-discovered by other users, and 
-
-(2) be sure to report to the program author or maintainer anything you
-observe that looks like a bug or a way the program can be misused.
Index: trunk/minix/commands/httpd/build
===================================================================
--- trunk/minix/commands/httpd/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/httpd/cgiexec.c
===================================================================
--- trunk/minix/commands/httpd/cgiexec.c	(revision 9)
+++ 	(revision )
@@ -1,255 +1,0 @@
-/* cgiexec.c by Michael Temari 02/17/96
- *
- * This file is part of httpd.
- *
- * 02/17/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002 			Michael Temari <Michael@TemWare.Com>
- * 02/08/2005 			Michael Temari <Michael@TemWare.Com>
- *
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <time.h>
-
-#include "http.h"
-#include "config.h"
-#include "net.h"
-
-_PROTOTYPE(char **cgienv, (struct http_request *rq, struct http_reply *rp));
-_PROTOTYPE(static int addenv, (char *name, char *value, char **buf, int *len));
-
-int cgiexec(rq, rp)
-struct http_request *rq;
-struct http_reply *rp;
-{
-struct stat st;
-char *prog;
-int cmdpid;
-int status;
-char *argv[5];
-int ifds[2];
-int ofds[2];
-static char cmd[2048];
-char **cmdenv;
-int dirflag = 0;
-
-    if(stat(rp->realurl, &st)) {
-    	if(errno == EACCES)
-    		rp->status = HTTP_STATUS_FORBIDDEN;
-    	else
-    		rp->status = HTTP_STATUS_NOT_FOUND;
-    	strcpy(rp->statusmsg, strerror(errno));
-    	return(-1);
-    }
-
-    if((st.st_mode & S_IFMT) == S_IFDIR)
-    	if(direxec != NULL) {
-    		prog = direxec; dirflag = 1;
-    	} else
-    		return(0);
-    else
-    	prog = rp->realurl;
-
-    /* check if prog is allowed to be exec'd */
-    if(!dirflag && !(rp->urlaccess & URLA_EXEC))
-    	return(0);
-
-    /* if cannot exec mode then return */
-    if( (st.st_mode & S_IXUSR) == 0 &&
-    	(st.st_mode & S_IXGRP) == 0 &&
-    	(st.st_mode & S_IXOTH) == 0 )
-	return(0);
-
-   if((cmdenv = cgienv(rq, rp)) == NULL) {
-   	rp->status = HTTP_STATUS_SERVER_ERROR;
-   	strcpy(rp->statusmsg, "Could not setup cgi environment");
-   	return(-1);
-   }
-
-   argv[0] = prog;
-   argv[1] = rp->realurl;
-   argv[2] = rq->url;
-   argv[3] = (char *)NULL;
-
-   if(pipe(ifds) < 0) {
-	rp->status = HTTP_STATUS_NOT_FOUND;
-    	strcpy(rp->statusmsg, strerror(errno));
-	return(-1);
-   }
-
-   if(pipe(ofds) < 0) {
-	rp->status = HTTP_STATUS_NOT_FOUND;
-    	strcpy(rp->statusmsg, strerror(errno));
-    	close(ifds[0]); close(ifds[1]);
-	return(-1);
-   }
-
-   if((cmdpid = fork()) < 0) {
-	close(ifds[0]); close(ofds[0]);
-	close(ifds[1]); close(ofds[1]);
-	rp->status = HTTP_STATUS_NOT_FOUND;
-    	strcpy(rp->statusmsg, strerror(errno));
-	return(-1);
-   }
-
-   /* We don't know how much data is going to be passed back */
-   rp->size = 0;
-
-   if(cmdpid == 0) { /* Child */
-#if 0
-   	if((cmdpid = fork()) < 0) {
-		close(ifds[0]); close(ofds[0]);
-		close(ifds[1]); close(ofds[1]);
-   		exit(-1);
-   	}
-   	if(cmdpid != 0) {
-		close(ifds[0]); close(ofds[0]);
-		close(ifds[1]); close(ofds[1]);
-		exit(0);
-	}
-#endif
-	setsid();
-	close(ifds[0]); close(ofds[1]);
-	dup2(ofds[0], 0);
-	dup2(ifds[1], 1);
-	dup2(ifds[1], 2);
-	close(ifds[1]); close(ofds[0]);
-	execve(argv[0], argv, cmdenv);
-	exit(0);
-   }
-
-#if 0
-   /* Get rid of Zombie child */
-   (void) wait(&status);
-#endif
-
-   close(ifds[1]); close(ofds[0]);
-
-   rp->fd = ifds[0];
-   rp->ofd = ofds[1];
-   rp->pid = cmdpid;
-
-   if(rp->urlaccess & URLA_HEADERS)
-   	rp->headers = -1;
-
-   return(-1);
-}
-
-char **cgienv(rq, rp)
-struct http_request *rq;
-struct http_reply *rp;
-{
-static char buffer[4096];
-char *p, *p2;
-char **e;
-int len;
-char temp[20];
-
-   p = buffer;
-   len = sizeof(buffer);
-
-   if(addenv("PATH", "/usr/local/bin:/bin:/usr/bin", &p, &len)) return(NULL);
-   if(getenv("TZ") != (char *)NULL)
-   	if(addenv("TZ", getenv("TZ"), &p, &len)) return(NULL);
-
-   /* HACK - some of these are hardcoded and should not be MAT 3/17/96 */
-
-   /* HTTP_ */
-
-   if(addenv("SERVER_SOFTWARE", "Temari httpd/1.0", &p, &len)) return(NULL);
-   if(addenv("SERVER_NAME", myhostname, &p, &len)) return(NULL);
-   if(addenv("GATEWAY_INTERFACE", "CGI/1.1", &p, &len)) return(NULL);
-   if(addenv("SERVER_PROTOCOL", "HTTP/1.0", &p, &len)) return(NULL);
-   if(rq->port)
-	sprintf(temp, "%u", rq->port);
-   else
-   	strcpy(temp, "80");
-   if(addenv("SERVER_PORT", temp, &p, &len)) return(NULL);
-   switch(rq->method) {
-   	case HTTP_METHOD_GET:
-		if(addenv("REQUEST_METHOD", "GET", &p, &len)) return(NULL);
-		break;
-   	case HTTP_METHOD_POST:
-		if(addenv("REQUEST_METHOD", "POST", &p, &len)) return(NULL);
-		break;
-   	case HTTP_METHOD_HEAD:
-		if(addenv("REQUEST_METHOD", "HEAD", &p, &len)) return(NULL);
-		break;
-   	case HTTP_METHOD_PUT:
-		if(addenv("REQUEST_METHOD", "PUT", &p, &len)) return(NULL);
-		break;
-	default:
-		if(addenv("REQUEST_METHOD", "UNKNOWN", &p, &len)) return(NULL);
-   }
-   if(addenv("PATH_INFO", "?", &p, &len)) return(NULL);
-   if(addenv("PATH_TRANSLATED", "?", &p, &len)) return(NULL);
-   if(addenv("SCRIPT_NAME", rq->url, &p, &len)) return(NULL);
-   if(addenv("QUERY_STRING", rq->query, &p, &len)) return(NULL);
-   if(addenv("REMOTE_HOST", rmthostname, &p, &len)) return(NULL);
-   if(addenv("REMOTE_ADDR", rmthostaddr, &p, &len)) return(NULL);
-   if(rq->authuser != (char *)NULL)
-	if(addenv("AUTH_USER", rq->authuser, &p, &len)) return(NULL);
-   /* AUTH_TYPE */
-   /* REMOTE_USER */
-   /* REMOTE_IDENT */
-   if(rq->method == HTTP_METHOD_POST) {
-	if(addenv("CONTENT_TYPE", "application/x-www-form-urlencoded", &p, &len)) return(NULL);
-	sprintf(temp, "%lu", rq->size);
-	if(addenv("CONTENT_LENGTH", temp, &p, &len)) return(NULL);
-   }
-   /* COOKIE */
-   if(rq->cookie[0] != '\0')
-   	if(addenv("COOKIE", rq->cookie, &p, &len)) return(NULL);
-   /* HOST */
-   if(addenv("HOST", rq->host, &p, &len)) return(NULL);
-
-   if(len < 1) return(NULL);
-   *p++ = '\0';
-
-   p2 = buffer;
-   e = (char **)p;
-   while(*p2) {
-  	if(len < sizeof(e)) return(NULL);
-  	len -= sizeof(e);
-  	*e++ = p2;
-  	while(*p2) p2++;
-  	p2++;
-   }
-   if(len < sizeof(e)) return(NULL);
-   *e++ = NULL;
-
-   return((char **)p);
-}
-
-static int addenv(name, value, buf, len)
-char *name;
-char *value;
-char **buf;
-int *len;
-{
-char *p;
-int size;
-
-   p = *buf;
-
-   size = strlen(name)+1+strlen(value)+1;
-
-   if(size > *len)
-   	return(-1);
-
-   sprintf(p, "%s=%s", name, value);
-
-   p += size;
-   *buf = p;
-   *len -= size;
-
-   return(0);
-}
Index: trunk/minix/commands/httpd/config.c
===================================================================
--- trunk/minix/commands/httpd/config.c	(revision 9)
+++ 	(revision )
@@ -1,813 +1,0 @@
-/* config.c by Michael Temari 02/26/96
- *
- * This file is part of httpd.
- *
- * 02/26/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002 			Michael Temari <Michael@TemWare.Com>
- *
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <pwd.h>
-
-#include "utility.h"
-#include "config.h"
-
-struct mtype *mtype = NULL;
-struct msufx *msufx = NULL;
-struct vhost *vhost = NULL;
-struct vpath *vpath = NULL;
-struct dirsend *dirsend = NULL;
-struct auth *auth = NULL;
-struct auth *proxyauth = NULL;
-char *direxec = NULL;
-char *srvrroot = "";
-char *LogFile = NULL;
-char *DbgFile = NULL;
-char *User = NULL;
-char *Chroot = NULL;
-
-_PROTOTYPE(static int doconfig, (char *cfg_file));
-_PROTOTYPE(static int doinclude, (char *parms[], int np));
-_PROTOTYPE(static int domtype, (char *parms[], int np));
-_PROTOTYPE(static struct auth *findauth, (char *name));
-_PROTOTYPE(static int dovhost, (char *parms[], int np));
-_PROTOTYPE(static int dovpath, (char *parms[], int np));
-_PROTOTYPE(static int dosrvrroot, (char *parms[], int np));
-_PROTOTYPE(static int dodirsend, (char *parms[], int np));
-_PROTOTYPE(static int dodirexec, (char *parms[], int np));
-_PROTOTYPE(static char *subvpath, (char *s));
-_PROTOTYPE(static int dologfile, (char *parms[], int np));
-_PROTOTYPE(static int dodbgfile, (char *parms[], int np));
-_PROTOTYPE(static int douser, (char *parms[], int np));
-_PROTOTYPE(static int dochroot, (char *parms[], int np));
-_PROTOTYPE(static int adduser, (struct auth *pauth, char *user));
-_PROTOTYPE(static int doauth, (char *parms[], int np));
-_PROTOTYPE(static int doproxyauth, (char *parms[], int np));
-
-int readconfig(cfg_file, testing)
-char *cfg_file;
-int testing;
-{
-int s;
-char *cfg;
-struct msufx *ps;
-struct mtype *pt;
-struct vhost *ph;
-struct vpath *pv;
-struct dirsend *pd;
-struct auth *pa;
-
-   cfg = HTTPD_CONFIG_FILE;
-   if(cfg_file != (char *)NULL)
-	if(*cfg_file)
-		cfg = cfg_file;
-
-   s = doconfig(cfg);
-
-   if(testing) {
-	printf("ServerRoot: %s\n", srvrroot);
-	printf("UserName: %s\n", User == NULL ? "" : User);
-	printf("Chroot: %s\n", Chroot == NULL ? "" : Chroot);
-	printf("LogFile: %s\n", LogFile == NULL ? "" : LogFile);
-	printf("DbgFile: %s\n", DbgFile == NULL ? "" : DbgFile);
-	printf("DirSend:");
-	for(pd = dirsend; pd != NULL; pd = pd->next)
-   		printf(" %s", pd->file);
-	printf("\n");
-	printf("DirExec: %s\n", direxec == NULL ? "" : direxec);
-	for(ph = vhost; ph != NULL; ph = ph->next)
-		printf("VHost: %s %s\n", ph->hname, ph->root);
-	for(pa = auth; pa != NULL; pa = pa->next)
-   		printf("Auth: %s %s %d %s\n",
-			pa->name, pa->desc, pa->urlaccess, pa->passwdfile);
-	for(pa = proxyauth; pa != NULL; pa = pa->next)
-   		printf("ProxyAuth: %s %s %d %s\n",
-			pa->name, pa->desc, pa->urlaccess, pa->passwdfile);
-	for(pv = vpath; pv != NULL; pv = pv->next)
-   		printf("Vpath: %s %s %s %d\n",
-			pv->from, pv->to, pv->auth->name, pv->urlaccess);
-	for(pt = mtype; pt != NULL; pt = pt->next) {
-   		printf("MType: %s :", pt->mimetype);
-		for(ps = pt->msufx; ps != NULL; ps = ps->tnext)
-		   	printf(" '%s'", ps->suffix);
-		printf("\n");
-	}
-	for(ps = msufx; ps != NULL; ps = ps->snext)
-   		printf("Suffix: %s\t%s\n", ps->suffix, ps->mtype->mimetype);
-   }
-
-   return(s);
-}
-
-static int doconfig(cfg_file)
-char *cfg_file;
-{
-FILE *fp;
-int np;
-int s;
-char *p;
-char ltype[40];
-char *parms[30];
-static char buffer[2048];
-
-   if((fp = fopen(cfg_file, "r")) == (FILE *)NULL) {
-   	fprintf(stderr, "httpd: Could not read %s config file.\n", cfg_file);
-	return(-1);
-   }
-
-   *ltype = '\0';
-
-   while(fgets(buffer, sizeof(buffer), fp) != (char *)NULL) {
-   	if(buffer[0] == '#') continue;	/* skip comments */
-   	np = getparms(buffer, parms, sizeof(parms)/sizeof(parms[0]));
-   	if(np == 0) continue;	/* blank line */
-   	if(parms[0] == (char *)NULL)
-   		parms[0] = ltype;
-   	else {
-   		p = parms[0];
-   		while(*p) *p++ = tolower(*p);
-   		strncpy(ltype, parms[0], sizeof(ltype));
-   	}
-   	s = 0;
-   	if(!strcmp(parms[0], "mtype")) s = domtype(parms, np);
-   	else
-   	if(!strcmp(parms[0], "vhost")) s = dovhost(parms, np);
-   	else
-   	if(!strcmp(parms[0], "vpath")) s = dovpath(parms, np);
-   	else
-   	if(!strcmp(parms[0], "serverroot")) s = dosrvrroot(parms, np);
-   	else
-   	if(!strcmp(parms[0], "dirsend")) s = dodirsend(parms, np);
-   	else
-   	if(!strcmp(parms[0], "direxec")) s = dodirexec(parms, np);
-   	else
-   	if(!strcmp(parms[0], "logfile")) s = dologfile(parms, np);
-   	else
-   	if(!strcmp(parms[0], "dbgfile")) s = dodbgfile(parms, np);
-   	else
-   	if(!strcmp(parms[0], "user")) s = douser(parms, np);
-   	else
-   	if(!strcmp(parms[0], "chroot")) s = dochroot(parms, np);
-   	else
-   	if(!strcmp(parms[0], "auth")) s = doauth(parms, np);
-   	else
-   	if(!strcmp(parms[0], "proxyauth")) s = doproxyauth(parms, np);
-   	else
-	if(!strcmp(parms[0], "include")) s = doinclude(parms, np);
-	else
-   	fprintf(stderr, "httpd: Unknown directive: %s\n", parms[0]);
-   	if(s) {
-   		fprintf(stderr, "httpd: Error processing config file\n");
-		fclose(fp);
-   		return(-1);
-   	}
-   }
-
-   fclose(fp);
-
-   return(0);
-}
-
-static int doinclude(parms, np)
-char *parms[];
-int np;
-{
-char *p;
-
-   if(np < 2) return(0);
-
-   p = subvpath(parms[1]);
-
-   return(doconfig(p));
-}
-
-static int domtype(parms, np)
-char *parms[];
-int np;
-{
-int i;
-struct mtype *pt, *lpt, *newpt;
-struct msufx *ps, *lps, *newps, *psend;
-
-   if(np < 2) return(0);
-
-
-   /* check if this mime type already exists in the list */
-   for(pt = mtype, lpt = NULL; pt != NULL; lpt = pt, pt = pt->next)
-   	if(!strcmp(parms[1], pt->mimetype))
-   		break;
-
-   if(pt == NULL) {		/* not there so add it */
-   	newpt = malloc(sizeof(struct mtype));
-   	if(newpt == NULL) {
-   		fprintf(stderr, "httpd: malloc failed in domtype\n");
-   		return(-1);
-   	}
-   	newpt->mimetype = malloc(strlen(parms[1])+1);
-   	if(newpt->mimetype == NULL) {
-   		fprintf(stderr, "httpd: malloc failed in domtype\n");
-   		return(-1);
-   	}
-   	strcpy(newpt->mimetype, parms[1]);
-   	newpt->msufx = NULL;
-   	newpt->next = NULL;
-   	if(lpt == NULL)
-   		mtype = newpt;
-   	else
-   		lpt->next = newpt;
-   } else
-   	newpt = pt;
-
-   /* find end of suffix list */
-   for(ps = newpt->msufx, lps = NULL; ps != NULL; lps = ps, ps = ps->tnext) ;
-   psend = lps;
-
-   /* if no suffix given then add empty suffix for default */
-   if(np == 2)
-   	strcpy(parms[np++], "");
-
-   /* add each suffix to the mime type */
-   for(i = 2; i < np; i++) {
-	/* a suffix can only be for a single mime type */
-	for(ps = msufx, lps = NULL; ps != NULL; lps = ps, ps = ps->snext) {
-		if(!strcmp(ps->suffix, parms[i])) {
-			fprintf(stderr, "httpd: Suffix already found\n");
-			return(-1);
-		}
-		if(strlen(parms[i]) > strlen(ps->suffix)) break;
-	}
-	newps = malloc(sizeof(struct msufx));
-	if(newps == NULL) {
-   		fprintf(stderr, "httpd: malloc failed in domtype\n");
-   		return(-1);
-   	}
-	newps->suffix = malloc(strlen(parms[i])+1);
-	if(newps->suffix == NULL) {
-   		fprintf(stderr, "httpd: malloc failed in domtype\n");
-   		return(-1);
-   	}
-	strcpy(newps->suffix, parms[i]);
-	newps->mtype = newpt;
-	newps->snext = NULL;
-	newps->tnext = NULL;
-	if(lps == NULL) {
-		msufx = newps;
-		newps->snext = ps;
-	} else {
-		lps->snext = newps;
-		newps->snext = ps;
-	}
-	if(psend == NULL)
-		newpt->msufx = newps;
-	else
-		psend->tnext = newps;
-	psend = newps;
-   }
-
-   return(0);
-}
-
-static struct auth *findauth(name)
-char *name;
-{
-char lname[80];
-char *p, *p2;
-struct auth *a = NULL;
-
-   if(sizeof(lname) < (strlen(name)+1)) {
-   	fprintf(stderr, "httpd: lname too small in findauth\n");
-   	return(a);
-   }
-   p = name; p2 = lname;
-   while(*p)
-	*p2++ = tolower(*p++);
-   *p2 = '\0';
-
-   for(a = auth; a != NULL; a = a->next)
-	if(!strcmp(a->name, lname)) break;
-
-   return(a);
-}
-
-static int dovhost(parms, np)
-char *parms[];
-int np;
-{
-char *hname, *root;
-struct vhost *ph, *lph, *newph;
-
-   if(np < 2) return(0);
-
-   hname = parms[1];
-
-   if(np < 3)
-   	root = "";
-   else
-	root = parms[2];
-
-   for(ph = vhost, lph = NULL; ph != NULL; lph = ph, ph = ph->next)
-	;
-
-   newph = malloc(sizeof(struct vhost));
-   if(newph == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in dovhost\n");
-   	return(-1);
-   }
-   newph->hname = malloc(strlen(hname)+1);
-   if(newph->hname == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in dovhost\n");
-   	return(-1);
-   }
-   strcpy(newph->hname, hname);
-
-   root = subvpath(root);
-
-   newph->root = malloc(strlen(root)+1);
-   if(newph->root == NULL) {
-	fprintf(stderr, "httpd: malloc failed in dovhost\n");
-   	return(-1);
-   }
-   strcpy(newph->root, root);
-
-   if(np > 3)
-   	if(parms[3][0] != '#') {
-		fprintf(stderr, "httpd: junk at end of vhost line\n");
-   		return(-1);
-   	}
-
-   newph->next = NULL;
-   if(lph == NULL) {
-	vhost = newph;
-	newph->next = ph;
-   } else {
-	lph->next = newph;
-	newph->next = ph;
-   }
-
-   return(0);
-}
-
-static int dovpath(parms, np)
-char *parms[];
-int np;
-{
-char *from, *to;
-struct vpath *pv, *lpv, *newpv;
-
-   if(np < 3) return(0);
-
-   from = parms[1];
-   to = parms[2];
-
-   for(pv = vpath, lpv = NULL; pv != NULL; lpv = pv, pv = pv->next)
-	;
-
-   newpv = malloc(sizeof(struct vpath));
-   if(newpv == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in dovpath\n");
-   	return(-1);
-   }
-   newpv->from = malloc(strlen(from)+1);
-   if(newpv->from == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in dovpath\n");
-   	return(-1);
-   }
-   strcpy(newpv->from, from);
-
-   to = subvpath(to);
-
-   newpv->to = malloc(strlen(to)+1);
-   if(newpv->to == NULL) {
-	fprintf(stderr, "httpd: malloc failed in dovpath\n");
-   	return(-1);
-   }
-   strcpy(newpv->to, to);
-
-   newpv->auth = NULL;
-   newpv->urlaccess = -1;
-
-   if(np > 3)
-   	if(parms[3][0] != '#') {
-   		newpv->auth = findauth(parms[3]);
-   		if(np > 4)
-			if(parms[4][0] != '#') {
-				newpv->urlaccess = mkurlaccess(parms[4]);
-				if(np > 5)
-   					if(parms[5][0] != '#') {
-   						fprintf(stderr, "httpd: junk at end of vpath line\n");
-   						return(-1);
-   					}
-			}
-   	}
-
-   newpv->next = NULL;
-   if(lpv == NULL) {
-	vpath = newpv;
-	newpv->next = pv;
-   } else {
-	lpv->next = newpv;
-	newpv->next = pv;
-   }
-
-   return(0);
-}
-
-static int dosrvrroot(parms, np)
-char *parms[];
-int np;
-{
-char *newroot;
-
-   if(np < 2) return(0);
-
-   newroot = subvpath(parms[1]);
-
-   srvrroot = malloc(strlen(newroot)+1);
-   if(srvrroot == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in dosrvrroot\n");
-   	return(-1);
-   }
-   strcpy(srvrroot, newroot);
-   if(srvrroot[strlen(srvrroot)-1] == '/')
-   	srvrroot[strlen(srvrroot)-1] = '\0';
-
-   return(0);
-}
-
-static int dodirsend(parms, np)
-char *parms[];
-int np;
-{
-char *file;
-int i;
-struct dirsend *pd, *lpd, *npd;
-
-   if(np < 2) return(0);
-
-   /* find end of the list */
-   for(pd = dirsend, lpd = NULL; pd != NULL; lpd = pd, pd = pd->next) ;
-
-   for(i = 1; i < np; i++) {
-   	file = parms[i];
-   	if(file[0] == '#') break;
-	npd = malloc(sizeof(struct dirsend));
-	if(npd == NULL) {
-   		fprintf(stderr, "httpd: malloc failed in dodirsend\n");
-   		return(-1);
-	}
-	npd->file = malloc(strlen(file)+1);
-	if(npd->file == NULL) {
-		fprintf(stderr, "httpd: malloc failed in dodirsend\n");
-		return(-1);
-	}
-	strcpy(npd->file, file);
-	npd->next = NULL;
-	if(lpd == NULL)
-		dirsend = npd;
-	else
-		lpd->next = npd;
-	lpd = npd;
-   }
-
-   return(0);
-}
-
-static int dodirexec(parms, np)
-char *parms[];
-int np;
-{
-char *file;
-
-   if(np < 2) return(0);
-
-   if(direxec != NULL) {
-   	fprintf(stderr, "httpd: Error direxec line already present\n");
-   	return(-1);
-   }
-
-   file = subvpath(parms[1]);
-
-   direxec = malloc(strlen(file)+1);
-
-   if(direxec == NULL) {
-	fprintf(stderr, "httpd: malloc failed in dodirexec\n");
-   	return(-1);
-   }
-
-   strcpy(direxec, file);
-
-   if(np > 2)
-   	if(parms[2][0] != '#') {
-   		fprintf(stderr, "httpd: garbage on end of direxec line\n");
-   		return(-1);
-   	}
-
-   return(0);
-}
-
-static char *subvpath(s)
-char *s;
-{
-char *p, *p2;
-int len;
-static char buffer[1024];
-char user[80];
-struct passwd *pwd;
-
-   /* replace beginning // with srvrroot */
-   if(s[0] == '/' && s[1] == '/')
-   	/* but not /// if we have VHOST's */
-   	if(vhost == NULL || s[2] != '/') {
-   		strcpy(buffer, srvrroot);
-   		strncat(buffer, s+1, sizeof(buffer) - strlen(buffer));
-   		buffer[sizeof(buffer)-1] = '\0';
-   		return(buffer);
-	}
-
-   if(s[0] != '/' || s[1] != '~') return(s);
-
-   /* replace beginning /~user with user home directory */
-   p = s + 2;
-   p2 = user;
-   len = sizeof(user) - 1;
-   while(*p && *p != '/' && len-- > 0) *p2++ = *p++;
-   *p2 = '\0';
-   if(*p != '\0' && *p != '/') return(s);
-   if((pwd = getpwnam(user)) == (struct passwd *)NULL) return(s);
-   strcpy(buffer, pwd->pw_dir);
-   strncat(buffer, p, sizeof(buffer) - strlen(buffer));
-   buffer[sizeof(buffer)-1] = '\0';
-
-   return(buffer);
-}
-
-static int dologfile(parms, np)
-char *parms[];
-int np;
-{
-char *p;
-
-   if(np < 2) return(0);
-
-   p = subvpath(parms[1]);
-   LogFile = malloc(strlen(p)+1);
-   if(LogFile == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in dologfile\n");
-   	return(-1);
-   }
-   strcpy(LogFile, p);
-
-   return(0);
-}
-
-static int dodbgfile(parms, np)
-char *parms[];
-int np;
-{
-char *p;
-
-   if(np < 2) return(0);
-
-   p = subvpath(parms[1]);
-   DbgFile = malloc(strlen(p)+1);
-   if(DbgFile == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in dodbgfile\n");
-   	return(-1);
-   }
-   strcpy(DbgFile, p);
-
-   return(0);
-}
-
-static int douser(parms, np)
-char *parms[];
-int np;
-{
-   if(np < 2) return(0);
-
-   User = malloc(strlen(parms[1])+1);
-   if(User == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in douser\n");
-   	return(-1);
-   }
-   strcpy(User, parms[1]);
-
-   return(0);
-}
-
-static int dochroot(parms, np)
-char *parms[];
-int np;
-{
-char *newroot;
-
-   if(np < 2) return(0);
-
-   newroot = subvpath(parms[1]);
-
-   Chroot = malloc(strlen(newroot)+1);
-   if(Chroot == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in dochroot\n");
-   	return(-1);
-   }
-   strcpy(Chroot, newroot);
-
-   return(0);
-}
-
-static int adduser(pauth, user)
-struct auth *pauth;
-char *user;
-{
-struct authuser *pa, *lpa, *newpa;
-
-   for(pa = pauth->users, lpa = NULL; pa != NULL; lpa = pa, pa = pa->next)
-	;
-
-   newpa = malloc(sizeof(struct authuser));
-   if(newpa == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in adduser\n");
-   	return(-1);
-   }
-   newpa->user = malloc(strlen(user)+1);
-   if(newpa->user == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in adduser\n");
-   	return(-1);
-   }
-   strcpy(newpa->user, user);
-
-   newpa->next = NULL;
-   if(lpa == NULL) {
-	pauth->users = newpa;
-	newpa->next = pa;
-   } else {
-	lpa->next = newpa;
-	newpa->next = pa;
-   }
-
-   return(0);
-}
-
-static int doauth(parms, np)
-char *parms[];
-int np;
-{
-int i;
-char *name, *desc, *pf;
-char *p, *p2;
-struct auth *pa, *lpa, *newpa;
-
-   if(np < 3) return(0);
-
-   name = parms[1];
-   desc = parms[2];
-
-   for(pa = auth, lpa = NULL; pa != NULL; lpa = pa, pa = pa->next)
-	;
-
-   newpa = malloc(sizeof(struct auth));
-   if(newpa == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in doauth\n");
-   	return(-1);
-   }
-   newpa->name = malloc(strlen(name)+1);
-   if(newpa->name == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in doauth\n");
-   	return(-1);
-   }
-   p = name; p2 = newpa->name;
-   while(*p)
-	*p2++ = tolower(*p++);
-   *p2 = '\0';
-
-   newpa->desc = malloc(strlen(desc)+1);
-   if(newpa->desc == NULL) {
-	fprintf(stderr, "httpd: malloc failed in doauth\n");
-   	return(-1);
-   }
-   strcpy(newpa->desc, desc);
-
-   newpa->urlaccess = mkurlaccess(parms[3]);
-   newpa->passwdfile = NULL;
-   newpa->users = NULL;
-
-   if(np > 4)
-   	if(parms[4][0] != '#') {
-		if(!strcmp(parms[4], "."))
-			pf = "/etc/passwd";
-		else
-			pf = subvpath(parms[4]);
-   		newpa->passwdfile = malloc(strlen(pf)+1);
-   		if(newpa->passwdfile == NULL) {
-   			fprintf(stderr, "httpd: malloc failed in doauth\n");
-   			return(-1);
-   		}
-   		strcpy(newpa->passwdfile, pf);
-		i = 5;
-		while(i < np) {
-   			if(parms[i][0] == '#')
-				break;
-			if(adduser(newpa, parms[i]))
-				return(-1);
-			i++;
-		}
-   	}
-
-   newpa->next = NULL;
-   if(lpa == NULL) {
-	auth = newpa;
-	newpa->next = pa;
-   } else {
-	lpa->next = newpa;
-	newpa->next = pa;
-   }
-
-   return(0);
-}
-
-static int doproxyauth(parms, np)
-char *parms[];
-int np;
-{
-int i;
-char *name, *desc, *pf;
-char *p, *p2;
-struct auth *pa, *lpa, *newpa;
-
-   if(np < 3) return(0);
-
-   name = parms[1];
-   desc = parms[2];
-
-   if(proxyauth != (struct auth *)NULL) {
-   	fprintf(stderr, "httpd: ProxyAuth defined multiple times using 1st only\n");
-   	return(0);
-   }
-
-   for(pa = proxyauth, lpa = NULL; pa != NULL; lpa = pa, pa = pa->next)
-	;
-
-   newpa = malloc(sizeof(struct auth));
-   if(newpa == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in doproxyauth\n");
-   	return(-1);
-   }
-   newpa->name = malloc(strlen(name)+1);
-   if(newpa->name == NULL) {
-   	fprintf(stderr, "httpd: malloc failed in doproxyauth\n");
-   	return(-1);
-   }
-   p = name; p2 = newpa->name;
-   while(*p)
-	*p2++ = tolower(*p++);
-   *p2 = '\0';
-
-   newpa->desc = malloc(strlen(desc)+1);
-   if(newpa->desc == NULL) {
-	fprintf(stderr, "httpd: malloc failed in doproxyauth\n");
-   	return(-1);
-   }
-   strcpy(newpa->desc, desc);
-
-   newpa->urlaccess = mkurlaccess(parms[3]);
-   newpa->passwdfile = NULL;
-   newpa->users = NULL;
-
-   if(np > 4)
-   	if(parms[4][0] != '#') {
-		if(!strcmp(parms[4], "."))
-			pf = "/etc/passwd";
-		else
-			pf = subvpath(parms[4]);
-   		newpa->passwdfile = malloc(strlen(pf)+1);
-   		if(newpa->passwdfile == NULL) {
-   			fprintf(stderr, "httpd: malloc failed in doauth\n");
-   			return(-1);
-   		}
-   		strcpy(newpa->passwdfile, pf);
-		i = 5;
-		while(i < np) {
-   			if(parms[i][0] == '#')
-				break;
-			if(adduser(newpa, parms[i]))
-				return(-1);
-			i++;
-		}
-   	}
-
-   newpa->next = NULL;
-   if(lpa == NULL) {
-	proxyauth = newpa;
-	newpa->next = pa;
-   } else {
-	lpa->next = newpa;
-	newpa->next = pa;
-   }
-
-   return(0);
-}
Index: trunk/minix/commands/httpd/config.h
===================================================================
--- trunk/minix/commands/httpd/config.h	(revision 9)
+++ 	(revision )
@@ -1,84 +1,0 @@
-/* config.h
- *
- * This file is part of httpd.
- *
- * 02/26/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002 			Michael Temari <Michael@TemWare.Com>
- * 07/04/2003			Al Woodhull <awoodhull@hampshire.edu>	
- * 02/08/2005 			Michael Temari <Michael@TemWare.Com>
- *
- */
-
-#define VERSION  "Minix httpd 0.994"
-
-struct authuser {
-	char *user;
-	struct authuser *next;
-};
-
-struct auth {
-	char *name;
-	char *desc;
-	int urlaccess;
-	char *passwdfile;
-	struct authuser *users;
-	struct auth *next;
-};
-
-struct msufx {
-	char *suffix;
-	struct mtype *mtype;
-	struct msufx *snext;
-	struct msufx *tnext;
-};
-
-struct mtype {
-	char *mimetype;
-	struct msufx *msufx;
-	struct mtype *next;
-};
-
-struct vhost {
-	char *hname;
-	char *root;
-	struct vhost *next;
-};
-
-struct vpath {
-	char *from;
-	char *to;
-	struct auth *auth;
-	int urlaccess;
-	struct vpath *next;
-};
-
-struct dirsend {
-	char *file;
-	struct dirsend *next;
-};
-
-/* urlaccess bits */
-
-#define	URLA_READ	1
-#define	URLA_WRITE	2
-#define	URLA_EXEC	4
-#define	URLA_HEADERS	8
-
-#define	HTTPD_CONFIG_FILE	"/etc/httpd.conf"
-
-_PROTOTYPE(int readconfig, (char *cfg_file, int testing));
-
-extern struct mtype *mtype;
-extern struct msufx *msufx;
-extern struct vhost *vhost;
-extern struct vpath *vpath;
-extern struct dirsend *dirsend;
-extern struct auth *auth;
-extern struct auth *proxyauth;
-extern char *direxec;
-extern char *srvrroot;
-extern char *LogFile;
-extern char *DbgFile;
-extern char *User;
-extern char *Chroot;
Index: trunk/minix/commands/httpd/dir2html.c
===================================================================
--- trunk/minix/commands/httpd/dir2html.c	(revision 9)
+++ 	(revision )
@@ -1,187 +1,0 @@
-/* dir2html.c by Michael Temari 3/3/96 */
-
-#include <sys/types.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <time.h>
-#include <sys/stat.h>
-
-typedef struct namelist {	/* Obviously a list of names. */
-	struct namelist	*next;
-	char		name[1];
-} namelist_t;
-
-_PROTOTYPE(static void sort, (namelist_t **anl));
-_PROTOTYPE(static namelist_t *collect, (char *dir));
-_PROTOTYPE(int main, (int argc, char *argv[]));
-
-static void sort(anl)
-namelist_t **anl;
-/* A stable mergesort disguised as line noise.  Must be called like this:
- *	if (L != NULL && L->next != NULL) sort(&L);
- */
-{
-    /* static */ namelist_t *nl1, **mid;  /* Need not be local */
-    namelist_t *nl2;
-
-    nl1 = *(mid = &(*anl)->next);
-    do {
-	if ((nl1 = nl1->next) == NULL) break;
-	mid = &(*mid)->next;
-    } while ((nl1 = nl1->next) != NULL);
-
-    nl2 = *mid;
-    *mid = NULL;
-
-    if ((*anl)->next != NULL) sort(anl);
-    if (nl2->next != NULL) sort(&nl2);
-
-    nl1 = *anl;
-    for (;;) {
-	if (strcmp(nl1->name, nl2->name) <= 0) {
-	    if ((nl1 = *(anl = &nl1->next)) == NULL) {
-		*anl = nl2;
-		break;
-	    }
-	} else {
-	    *anl = nl2;
-	    nl2 = *(anl = &nl2->next);
-	    *anl = nl1;
-	    if (nl2 == NULL) break;
-	}
-    }
-}
-
-static namelist_t *collect(dir)
-char *dir;
-/* Return a sorted list of directory entries.  Returns null with errno != 0
- * on error.
- */
-{
-    namelist_t *names, **pn = &names;
-    DIR *dp;
-    struct dirent *entry;
-
-    if ((dp = opendir(dir)) == NULL) return NULL;
-
-    while ((entry = readdir(dp)) != NULL) {
-	if (strcmp(entry->d_name, ".") == 0) continue;
-	*pn = malloc(offsetof(namelist_t, name) + strlen(entry->d_name) + 1);
-	if (*pn == NULL) {
-	    closedir(dp);
-	    errno = ENOMEM;
-	    return NULL;
-	}
-	strcpy((*pn)->name, entry->d_name);
-	pn = &(*pn)->next;
-    }
-    closedir(dp);
-    *pn = NULL;
-    if (names != NULL && names->next != NULL) sort(&names);
-    errno = 0;
-    return names;
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-    namelist_t *np;
-    char *rpath, *vpath;
-    static char cwd[1024];
-    static char work[64];
-    char *filename;
-    struct stat st;
-    struct tm *tmp;
-    static char month[][4] = {
-	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
-	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
-    };
-
-    if(argc > 1) {
-	rpath = argv[1];
-	if (chdir(rpath) < 0) {
-	    fprintf(stderr, "dir2html: %s: %s\n", rpath, strerror(errno));
-	    return(-1);
-    	}
-    } else {
-	if(getcwd(cwd, sizeof(cwd)) == NULL) {
-	    fprintf(stderr, "dir2html: getcwd(): %s", strerror(errno));
-	    return(-1);
-	}
-	rpath = cwd;
-    }
-
-    if(argc > 2) {
-	vpath = argv[2];
-    } else {
-	vpath = rpath;
-    }
-
-    if ((np = collect(".")) == NULL && errno != 0) {
-	fprintf(stderr, "dir2html: %s: %s\n", vpath, strerror(errno));
-	return(-1);
-    }
-
-    printf("<HTML><HEAD><TITLE>Index of %s</TITLE></HEAD>\n", vpath);
-    printf("<BODY>\n");
-    printf("<H1>Index of %s</H1>\n", vpath);
-
-    printf("<PRE>\n");
-    printf("%-22s  %-17s  %s\n", "Name", "Last modified", "Size/Type");
-    printf("<HR>\n");
-
-    while (np != NULL) {
-	errno = 0;
-	filename = np->name;
-	np= np->next;
-
-	if (stat(filename, &st) < 0) continue;
-
-	printf("<A HREF=\"%s%s\">",
-	    filename, S_ISDIR(st.st_mode) ? "/" : "");
-	sprintf(work, "%.23s%s",
-	    filename, S_ISDIR(st.st_mode) ? "/" : "");
-	if (strcmp(filename, "..") == 0) strcpy(work, "Parent Directory");
-	printf("%-22.22s%s</A>",
-	    work, strlen(work) > 22 ? "&gt;" : " ");
-	tmp = localtime(&st.st_mtime);
-	printf(" %02d %s %d %02d:%02d",
-	    tmp->tm_mday, month[tmp->tm_mon], 1900+tmp->tm_year,
-	    tmp->tm_hour, tmp->tm_min);
-	if (S_ISREG(st.st_mode)) {
-	    if (st.st_size < 10240) {
-		sprintf(work, "%lu ", (unsigned long) st.st_size);
-	    } else
-	    if (st.st_size < 10240 * 1024L) {
-		sprintf(work, "%luK",
-		    ((unsigned long) st.st_size - 1) / 1024 + 1);
-	    } else {
-		sprintf(work, "%luM",
-		    ((unsigned long) st.st_size - 1) / (1024 * 1024L) + 1);
-	    }
-	} else {
-	    strcpy(work,
-		S_ISDIR(st.st_mode) ? "[dir]" :
-		S_ISBLK(st.st_mode) ? "[block]" :
-		S_ISCHR(st.st_mode) ? "[char]" :
-		S_ISFIFO(st.st_mode) ? "[pipe]" :
-					"[???]");
-	}
-	printf(" %8s\n", work);
-    }
-
-    printf("</PRE>\n");
-
-    printf("<HR>\n");
-    printf("<SMALL><i>Minix httpd 0.99</i></SMALL>\n");
-    printf("</BODY>\n");
-    printf("</HTML>\n");
-
-    return(0);
-}
Index: trunk/minix/commands/httpd/dir2html.sh
===================================================================
--- trunk/minix/commands/httpd/dir2html.sh	(revision 9)
+++ 	(revision )
@@ -1,42 +1,0 @@
-# dir2html.sh by Michael Temari 03/03/96
-#
-#!/bin/sh
-if [ $# != 0 ]
-then
-cd $1
-fi
-dname=`pwd`
-fdname=$2
-if [ $dname != / ]
-then
-  dname=${dname}/
-fi
-echo "<HTML>"
-echo "<TITLE>"
-echo Directory of $fdname
-echo "</TITLE>"
-echo "<H1>"
-echo Directory of $fdname
-echo "</H1>"
-echo "<HR>"
-#
-ls $dname |
-{
-while read fname
-do
-lname=$fdname$fname
-echo "<H3>"
-echo -n "<A HREF=\""
-echo -n $lname
-echo -n "\">"
-echo -n $fname
-echo "</A><BR>"
-echo "</H3>"
-done
-}
-echo "<HR>"
-echo "<H6>"
-echo Directory Generated at `date`
-echo "</H6>"
-echo "</HTML>"
-exit 0
Index: trunk/minix/commands/httpd/http.h
===================================================================
--- trunk/minix/commands/httpd/http.h	(revision 9)
+++ 	(revision )
@@ -1,118 +1,0 @@
-/* http.h
- *
- * This file is part of httpd.
- *
- * 02/17/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002			Michael Temari <Michael@TemWare.Com>
- *
- */
-
-#define	INDEX_FILE_NAME	"index.html"
-
-#define	HTTP_REQUEST_TYPE_SIMPLE	0
-#define	HTTP_REQUEST_TYPE_FULL		1
-#define	HTTP_REQUEST_TYPE_PROXY		2
-
-#define	HTTP_METHOD_UNKNOWN	0
-#define	HTTP_METHOD_OPTIONS	1
-#define	HTTP_METHOD_GET		2
-#define	HTTP_METHOD_HEAD	3
-#define	HTTP_METHOD_POST	4
-#define	HTTP_METHOD_PUT		5
-#define	HTTP_METHOD_PATCH	6
-#define	HTTP_METHOD_COPY	7
-#define	HTTP_METHOD_MOVE	8
-#define	HTTP_METHOD_DELETE	9
-#define	HTTP_METHOD_LINK	10
-#define	HTTP_METHOD_UNLINK	11
-#define	HTTP_METHOD_TRACE	12
-#define	HTTP_METHOD_WRAPPED	13
-
-#define	HTTP_STATUS_OK			200
-#define	HTTP_STATUS_CREATED		201
-#define	HTTP_STATUS_ACCEPTED		202
-#define	HTTP_STATUS_NO_CONTENT		204
-#define	HTTP_STATUS_MOVED_PERM		301
-#define	HTTP_STATUS_MOVED_TEMP		302
-#define	HTTP_STATUS_NOT_MODIFIED	304
-#define	HTTP_STATUS_USE_PROXY		305
-#define	HTTP_STATUS_BAD_REQUEST		400
-#define	HTTP_STATUS_UNAUTHORIZED	401
-#define	HTTP_STATUS_FORBIDDEN		403
-#define	HTTP_STATUS_NOT_FOUND		404
-#define	HTTP_STATUS_METHOD_NOT_ALLOWED	405
-#define	HTTP_STATUS_PROXY_AUTH_REQRD	407
-#define	HTTP_STATUS_LENGTH_REQUIRED	411
-#define	HTTP_STATUS_SERVER_ERROR	500
-#define	HTTP_STATUS_NOT_IMPLEMENTED	501
-#define	HTTP_STATUS_BAD_GATEWAY		502
-#define	HTTP_STATUS_SERVICE_UNAVAILABLE	503
-#define	HTTP_STATUS_GATEWAY_TIMEOUT	504
-#define	HTTP_STATUS_UNSUPPORTED_VERSION	505
-
-struct http_request {
-	int type;
-	int method;
-	char uri[256];
-	char url[256];
-	char query[256];
-	char host[256];
-	int port;
-	char useragent[256];
-	int vmajor;
-	int vminor;
-	time_t ifmodsince;
-	off_t size;
-	time_t msgdate;
-	int keepopen;
-	char wwwauth[128];
-	char authuser[128];
-	char authpass[128];
-	char cookie[128];
-};
-
-struct http_reply {
-	int status;
-	char statusmsg[128];
-	int keepopen;
-	int headers;
-	char *mtype;
-	char realurl[256];
-	struct auth *auth;
-	int urlaccess;
-	off_t size;
-	time_t modtime;
-	int fd;
-	int ofd;
-	int pid;
-};
-
-/* from httpd.c */
-
-extern FILE *stdlog;
-extern FILE *dbglog;
-
-/* from reply.c */
-
-_PROTOTYPE(int sendreply, (struct http_reply *rp, struct http_request *rq));
-
-/* from request.c */
-
-_PROTOTYPE(int getrequest, (struct http_request *rq));
-
-/* from process.c */
-
-_PROTOTYPE(int processrequest, (struct http_request *rq, struct http_reply *rp));
-
-/* from police.c */
-
-_PROTOTYPE(int police, (struct http_request *rq, struct http_reply *rp));
-
-/* from cgiexec.c */
-
-_PROTOTYPE(int cgiexec, (struct http_request *rq, struct http_reply *rp));
-
-/* from proxy.c */
-
-_PROTOTYPE(void proxy, (struct http_request *rq, struct http_reply *rp));
Index: trunk/minix/commands/httpd/http_status.5
===================================================================
--- trunk/minix/commands/httpd/http_status.5	(revision 9)
+++ 	(revision )
@@ -1,73 +1,0 @@
-.TH HTTP_STATUS 5
-.SH 
-http_status \- HTTP status numbers and their meanings
-.SH DESCRIPTION
-These are the HTTP status numbers defined in 
-.BI http.h
-in the source directory,
-.BI /usr/local/src/httpdxxx.
-The message you see on your screen when a page cannot be accessed is 
-normally generated by your browser.
-.P
-HTTP_STATUS_OK                  200
-.br
-HTTP_STATUS_CREATED             201
-.br
-HTTP_STATUS_ACCEPTED            202
-.br
-HTTP_STATUS_NO_CONTENT          204
-.br
-HTTP_STATUS_MOVED_PERM          301
-.br
-HTTP_STATUS_MOVED_TEMP          302
-.br
-HTTP_STATUS_NOT_MODIFIED        304
-.br
-HTTP_STATUS_USE_PROXY           305
-.br
-HTTP_STATUS_BAD_REQUEST         400
-.br
-HTTP_STATUS_UNAUTHORIZED        401
-.br
-HTTP_STATUS_FORBIDDEN           403
-.br
-HTTP_STATUS_NOT_FOUND           404
-.br
-HTTP_STATUS_METHOD_NOT_ALLOWED  405
-.br
-HTTP_STATUS_PROXY_AUTH_REQRD    407
-.br
-HTTP_STATUS_LENGTH_REQUIRED     411
-.br
-HTTP_STATUS_SERVER_ERROR        500
-.br
-HTTP_STATUS_NOT_IMPLEMENTED     501
-.br
-HTTP_STATUS_BAD_GATEWAY         502
-.br
-HTTP_STATUS_SERVICE_UNAVAILABLE 503
-.br
-HTTP_STATUS_GATEWAY_TIMEOUT     504
-.br
-HTTP_STATUS_UNSUPPORTED_VERSION 505
-.br
-
-.SH FILES
-.TP 25n
-.B /usr/local/src/httpdxxx/http.h 
-.SH "SEE ALSO"
-The definitive source of information on the HTTP protocol is the
-.B "World Wide Web Consortium"  
-web page at 
-.B http://www.w3c.org .
-.P
-A draft version of the HTTP 1.1 specification is available on the Minix1
-websites. For more information on status codes go to this URL:
-.B http://minix1.hampshire.edu/http11.html#Status-Codes
-.SH AUTHOR
-The Minix httpd server was created by and is maintained by Michael Temari 
-<Michael@TemWare.Com>
-.br
-This man page was compiled by Al Woodhull <awoodhull@hampshire.edu>
-.P
-updated 2003-07-06
Index: trunk/minix/commands/httpd/httpd.8
===================================================================
--- trunk/minix/commands/httpd/httpd.8	(revision 9)
+++ 	(revision )
@@ -1,104 +1,0 @@
-.TH HTTPD 8
-.SH NAME
-httpd, in.httpd, dir2html \- a web server for Minix
-.SH SYNOPSIS
-.B httpd
-.RB [\-t|\-v]
-.RI [ config_file ]
-.br
-.B "tcpd http /usr/local/bin/in.httpd"
-.br 
-.B dir2html
-.RB [directory] 
-.SH DESCRIPTION
-.B httpd
-is a World Wide Web (WWW) server written by Michael Temari.  It was
-written from scratch so the setup and configuration will not be like
-other web servers.
-.P
-.B in.httpd 
-is linked to 
-.B httpd.
-This alternate name is used to indicate the program is a server that is
-started by
-.B tcpd,  
-a program which listens for incoming TCP connections on the passed
-port (defined in 
-.BI /etc/services ).  
-When a connection comes in 
-.B tcpd
-forks and starts the given daemon program, after possibly checking for access
-restrictions and logging the connection.  Therefore to start 
-.B httpd
-you use:
-.br
-.B  "tcpd http /usr/local/bin/in.httpd &"
-.br
-or
-.br
-.B "daemonize tcpd http /usr/local/bin/in.httpd"
-.P
-.B (daemonize 
-is a shell function defined in 
-.BI/usr/etc/rc 
-in Minix 2.0.3 and later releases which starts programs as daemons).
-.P
-.B dir2html
-is an accessory program that produces a directory listing formatted as 
-web page for the current directory or for a directory specified as an 
-argument. It is called by
-.B httpd
-when a web client references a directory that includes no index.html
-file (or whatever alternative to index.html that may be defined in 
-/etc/httpd.conf). Since it writes to standard output it may also be called 
-as a standalone program.
-.P
-Options for 
-.B httpd
-are:
-.SH OPTIONS
-.TP
-.B \-t
-This tells the server to parse the configuration file so that you can
-see if it is the way you want it.  You may also pass the name of your
-configuration file if it is not the default /etc/httpd.conf.
-.TP
-.B \-v
-Shows the server version, then exits.
-.br
-.IR config_file
-normally /etc/httpd.conf
-.SH FILES
-.TP 25n
-.B /etc/httpd.conf
-The configuration file.
-.P
-.B /etc/httpd.mtype
-Extension to configuration file defining MIME types.
-.P
-.B /usr/adm/httpd.log
-Log file. The file must exist for logging to begin.
-.SH "SEE ALSO"
-.BR httpd.conf (5)
-.br
-.BR http_status (5)
-.br
-.BR serv.access (5)
-.br
-.BR tcpd (8)
-.SH NOTES
-Running a server exposed to the Internet is risky to the host system and 
-to the local network. Consult with the owner of your net before you go 
-public. Read the 
-.B SECURITY
-document in the source directory.
-.SH BUGS
-None are known, but there are surely some unknown ones. Be careful!
-.SH AUTHOR
-The Minix httpd server was created by and is maintained by Michael Temari
-<Michael@TemWare.Com>
-.br
-This man page was compiled by Al Woodhull <awoodhull@hampshire.edu>
-.P
-updated 2003-07-06
-
Index: trunk/minix/commands/httpd/httpd.c
===================================================================
--- trunk/minix/commands/httpd/httpd.c	(revision 9)
+++ 	(revision )
@@ -1,175 +1,0 @@
-/* httpd.c
- *
- * httpd	A Server implementing the HTTP protocol.
- *
- * usage:	tcpd http httpd &
- *
- * 02/17/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002 			Michael Temari <Michael@TemWare.Com>
- * 07/04/2003			Al Woodhull <awoodhull@hampshire.edu>
- *
- */
-
-#include <stdlib.h>	
-#include <sys/types.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include "http.h"
-#include "utility.h"
-#include "net.h"
-#include "config.h"
-
-FILE *stdlog = (FILE *)NULL;
-FILE *dbglog = (FILE *)NULL;
-
-char umsg[80];
-
-_PROTOTYPE(int main, (int argc, char *argv[]));
-
-struct http_request request;
-struct http_reply reply;
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-char *prog;
-int opt_t;
-char *cfg = (char *)NULL;
-struct passwd *pwd;
-int s;
-
-   strcpy(umsg, "Usage: ");
-   strcat(umsg, argv[0]);
-   strcat(umsg, " [-t|v] [config_file]\n");
-
-   /* parse program name */
-   prog = strrchr(*argv, '/');
-   if(prog == (char *)NULL)
-   	prog = *argv;
-   else
-   	prog++;
-   argv++;
-   argc--;
-
-   /* Any options */
-   if(argc)
-        if(argv[0][0] == '-') {
-             switch (argv[0][1]) {
-                  case 't' : opt_t = 1;
-                             argv++;
-                             argc--;
-                             break;
-                  case 'v' : fprintf(stderr, VERSION"\n"); 
-                             exit(EXIT_SUCCESS);
-                             break;
-                  default  : fprintf(stderr, VERSION"\n"); 
-                             fprintf(stderr, umsg); 
-                             exit(EXIT_FAILURE);
-             }
-        }
-
-   /* Did they specify an alternate configuration file? */
-   if(argc) {
-   	cfg = *argv++;
-   	argc--;
-   }
-
-   /* Read the configuration settings */
-   if(readconfig(cfg, opt_t)) {
-   	fprintf(stderr, "httpd: Error reading configuration file.\n");
-   	return(-1);
-   }
-
-   /* Option t is to test configuration only */
-   if(opt_t)
-	return(0);
-
-   /* Open log file for append if it exists */
-   if(LogFile != NULL)
-	if((stdlog = fopen(LogFile, "r")) != (FILE *)NULL) {
-		fclose(stdlog);
-		stdlog = fopen(LogFile, "a");
-	}
-
-   /* Open debug log file for append if it exists */
-   if(DbgFile != NULL)
-	if((dbglog = fopen(DbgFile, "r")) != (FILE *)NULL) {
-		fclose(dbglog);
-		dbglog = fopen(DbgFile, "a");
-   }
-
-#if 0
-   /* Get some network information */
-   GetNetInfo();
-#endif
-
-   /* If user defined then prepare to secure as user given */
-   if(User != NULL)
-	if((pwd = getpwnam(User)) == (struct passwd *)NULL) {
-   		fprintf(stderr, "httpd: unable to find user %s\n", User);
-  	 	return(-1);
-	}
-
-   /* If Chroot defined then secure even more by doing a chroot */
-   if(Chroot != NULL) {
-	if(chroot(Chroot)) {
-		fprintf(stderr, "httpd: unable to chroot\n");
-		return(-1);
-	}
-	if(chdir("/")) {
-   		fprintf(stderr, "httpd: unable to chroot\n");
-   		return(-1);
-	}
-   }
-
-   /* If user defined then secure as user given */
-   if(User != NULL)
-	if(setgid(pwd->pw_gid) || setuid(pwd->pw_uid)) {
-   		fprintf(stderr, "httpd: unable to set user\n");
-   		return(-1);
-	}
-
-#if DAEMON
-   /* Standalone? */
-   if (strncmp(prog, "in.", 3) != 0) {
-       /* Does not start with "in.", so not started from inetd/tcpd. */
-       /* XXX - Port name/number should be a config file option. */
-       daemonloop("http");
-   }
-#endif
-
-   /* Get some network information */
-   GetNetInfo();
-
-   /* log a connection */
-   if(dbglog != (FILE *)NULL) {
-	fprintf(dbglog, "CONNECT: %d %s %s\n", getpid(),
-		rmthostname, logdate((time_t *)NULL));
-	fflush(dbglog);
-   }
-
-   /* loop getting, processing and replying to requests */
-   while(!(s = getrequest(&request))) {
-	if(processrequest(&request, &reply)) break;
-	if(stdlog != (FILE *)NULL) {
-		fprintf(stdlog, "%s %s %d %d %s\n",
-			logdate((time_t *)NULL), rmthostname,
-			request.method, reply.status, request.url);
-		fflush(stdlog);
-	}
-	if(sendreply(&reply, &request)) break;
-	if(!reply.keepopen) break;
-   }
-   if(s == 1 && stdlog != (FILE *)NULL) {
-	fprintf(stdlog, "%s %s %d %d %s\n",
-		logdate((time_t *)NULL), rmthostname,
-		request.method, 999, request.url);
-	fflush(stdlog);
-   }
-
-   return(0);
-}
Index: trunk/minix/commands/httpd/httpd.conf
===================================================================
--- trunk/minix/commands/httpd/httpd.conf	(revision 9)
+++ 	(revision )
@@ -1,159 +1,0 @@
-# httpd.conf Sample httpd.conf file By Michael Temari 7/03/2003
-
-#serverroot path
-#
-# path = sets the translation for //
-#
-# these have special meaning if at beginning of path
-#
-# /~user = gets replaced with user home directory
-
-serverroot	/~www
-
-#user username
-#
-# if present the server will run as the given username otherwise the
-# server will run as who ever started it (normally root).
-
-user www
-
-#chroot directory
-#
-# if present the server will be chroot'ed to the given directory name
-# normally the home directory of username given above.  Be aware if this
-# is set then you can only access stuff off this new root.
-#
-# these have special meaning if at beginning of the directory
-#
-#  //    = gets replaced by serverroot directory
-# /~user = gets replaced with user home directory
-
-#chroot /~www
-
-#logfile filename
-#
-# the file must exist also and a log of http transactions will be kept
-#
-# these have special meaning if at the beginning of the filename
-#
-#  //    = gets replaced by serverroot directory
-# /~user = gets replaced with user home directory
-
-logfile	/usr/adm/httpd.log
-
-#dbgfile filename
-#
-# the file must exist also and a debug log of http transactions will be kept
-#
-# these have special meaning if at the beginning of the filename
-#
-#  //    = gets replaced by serverroot directory
-# /~user = gets replaced with user home directory
-
-dbgfile	/usr/adm/httpd.dbg
-
-# dirsend  [list of files to try until 1st one is found]
-#
-
-dirsend		index.htm
-
-# direxec [script to run for automatic directory page output]
-#
-#
-# these have special meaning if at beginning of script
-#
-#  //    = gets replaced by serverroot directory
-# /~user = gets replaced with user home directory
-#
-
-direxec		/usr/local/bin/dir2html
-
-# vhost hostname VhostRoot
-#
-# vhost is for defining access for virtual hosts.  If none are configured then
-# any host is accepted.  If specified then access is only granted for requests
-# for hosts which are configured here.  In the Vpath section below the /// gets
-# translated to the corresponding VhostRoot.
-
-# vhost	temware.dyndns.org	//doc/
-# vhost	minix.homeip.net	//doc2/
-
-# auth authname authdescription access [passwdfile [users]]
-#
-# auth defines any access authorization to be used in vpath
-#
-# authname = name to give to this authorization (case insensitive)
-# authdescription = Description of this authorization
-# access = r=read, w=write, x=execute, h=headers (other than rwxh then no access)
-# NOTE: r=file should be read, w=file can be overwrote
-# NOTE: x=file should be executed
-# NOTE: h=headers (executing program will produce all http headers)
-# NOTE: access is on top of unix access
-# passwdfile = Name of passwd file to be used (. means /etc/passwd)
-#              (if none given then no user check)
-# users = valid users for this authorization (if none given then all users valid)
-#
-# these have special meaning if at beginning of passwdfile
-#
-#  //    = gets replaced by serverroot directory
-# /~user = gets replaced with user home directory
-#
-
-auth	AnyBody		AnyBody			R
-	System		System_User		R	.
-	Uploads		Uploads			RW	.	root
-
-# proxyauth authname authdescription access [passwdfile [users]]
-#
-# proxyauth defines any access authorization to be used for Proxy access
-#
-# authname = Same as auth above
-# authdescription = Same as auth above
-# access = Must be R to allow proxy
-# passwdfile = Same as auth above
-# users = Same as auth above
-#
-
-# proxyauth
-#	Proxy		Proxy			R	.
-
-
-# vpath from to auth
-#
-# vpath sets up a list of url path translations and authorizations
-#
-#   from = user specified url
-#          *=wildcard, $=wildard, but keep path for passing to program
-#     to = real location
-#   auth = authname from above (null for no authorization)
-# access = r-read, w-write, x-execute (if not given taken from auth record)
-#        = h-headers (executing program will produce all http headers)
-#
-# these have special meaning if at beginning of to or serverroot fields
-#
-#  //    = gets replaced by serverroot directory
-#  ///   = gets replaced by vhost root directory if configured otherwise same as //
-#  .     = specified authorization only, use other translation elsewhere
-# /~user = gets replaced with user home directory
-#
-
-vpath	*			.			AnyBody
-	/*			///			AnyBody
-	/index.htm		.			AnyBody		X
-	/ip			.			AnyBody		X
-	/c1d1$			//exec/cdrom		AnyBody		X
-	/c1d2$			//exec/cdrom		AnyBody		X
-	/uploads*		.			Uploads
-	/src*			/usr/src		AnyBody		R
-
-# include filename
-#
-# include tells the server to continue parsing configuration information
-# in the given filename 
-#
-# these have special meaning if at beginning of filename
-#
-#  //    = gets replaced by serverroot directory
-# /~user = gets replaced with user home directory
-
-include	//etc/httpd.mtype
Index: trunk/minix/commands/httpd/httpd.conf.5
===================================================================
--- trunk/minix/commands/httpd/httpd.conf.5	(revision 9)
+++ 	(revision )
@@ -1,328 +1,0 @@
-.TH HTTPD.CONF 5
-.SH NAME
-httpd.conf httpd.mtype \- configuration files for the Minix httpd web server
-.SH SYNOPSIS
-.B /etc/httpd.conf
-.B /etc/httpd.mtype
-.SH DESCRIPTION
-.B /etc/httpd.conf 
-is the configuration file for the Minix httpd web server written by
-Michael Temari.  A sample version is included with the distribution
-archive and is unpacked in the source directory (normally
-.BI /usr/local/src/httpdxxx).
-Also provided is an example
-.B httpd.mtype
-file. This is an extension of the main configuration file which is normally
-included when the main file is read.
-.P
-The makefile does not install 
-.B httpd.conf 
-and 
-.B httpd.mtype
-automatically. The sample files included in the distribution are only  
-examples, you must copy it and edit them for the needs of your own 
-installation.
-.SH CONFIGURATION FILE FORMAT
-.B httpd.conf
-is an ascii file which consists of lines of the following form:
-.P
-.B directive LWS [parameters separated by LWS]
-.br
-NOTE: LWS denotes Linear White Space which is spaces and/or tabs
-.SH CONFIGURATION FILE DIRECTIVES
-The following are valid configuration file directives (listed in the order 
-they appear in the sample 
-.B httpd.conf 
-file provided in the distribution):
-.P
-.B serverroot user chroot logfile dbgfile dirsend direxec vhost auth
-.B proxyauth vpath include mtype 
-.P
-To make the file more readable, for directives which occupy multiple
-lines you may eliminate the directive on lines after the first and begin 
-these lines with LWS.
-
-.SH DESCRIPTIONS OF DIRECTIVES
-.P
-.B serverroot path
-
-The 
-.B serverroot 
-directive sets the translation for 
-.B // 
-to the given 
-.B path.
-
-.B user username
-
-The 
-.B user 
-directive causes the server to run as the given 
-.B username 
-otherwise the server will run as whoever started it (normally root).
-
-.B chroot directory
-
-The 
-.B chroot 
-directive causes the server to chroot to the given directory after
-the configuration and log files have been opened.  Normally this will be the
-home directory of the given username in the user directive.
-.br
-NOTE: 
-.B /~user 
-will be translated to the home directory of
-.B user.
-.br
-NOTE:
-.B // 
-will be translated to the serverroot directory.
-.br
-NOTE: if this directive is used then beware of the consequences.
-
-.B logfile filename
-
-The 
-.B logfile 
-directive tells the server where to log http transactions.
-.br
-NOTE: the log file must exist to enable logging.
-
-.B dbgfile filename
-
-The 
-.B dbgfile 
-directive tells the server where to log debugging of http transactions.
-.br
-NOTE: the debug log file must exist to enable debug logging.
-
-.B dirsend filelist
-
-The 
-.B dirsend 
-directive tells the server that when a directory is requested
-that it should send the first file that it finds in the directory from the
-.B filelist 
-for the request.
-
-.B direxec program
-
-The 
-.B direxec 
-directive tells the server that when a directory is requested
-and no file is found from the 
-.B dirsend 
-directive that it should run the given 
-.B program.
-.br
-NOTE: the program normally generates a directory listing on the fly using
-the 
-.B dir2html
-program.
-.br
-NOTE: the program access is considered 
-.B X 
-with no access restrictions.
-
-.B vhost hostname vhostroot
-
-The 
-.B vhost 
-directive is for defining access for virtual hosts.  If none are configured 
-then any host is accepted.  If specified then access is only granted for 
-requests for hosts which are configured here.  In the 
-.B vpath 
-section below the 
-.B /// 
-gets translated to the corresponding 
-.B vhostroot.
-
-
-.B auth authname authdescription access [passwdfile [users]]
-
-The 
-.B auth 
-directive sets up different authorizations with the server.  The
-.B authname 
-is the name given to the authorization and is case insensitive.
-The 
-.B authdescription 
-is the description of the authorization and is what
-the user will see when asked to enter a username and password.  The
-access is one or more of 
-.B (RWX).  
-.B R 
-tells the server the URL can be read.  
-.B W 
-tells the server the URL can be overwritten.  
-.B X 
-tells the server
-that the URL can and should be executed.  Access is in addition to normal
-Unix security considerations.  For instance a file that can be written to
-that does not have the 
-.B W 
-access will have an error returned.  The
-.B passwdfile 
-is the name of the password file to validate users against.  If
-.B passwdfile 
-is given as 
-.B '.' 
-then the system password file
-.B (/etc/passwd)
-will be used.  If no 
-.B passwdfile 
-is given then no authorization is allowed for anyone.  If no 
-.B users 
-are given then any validated user is authorized, otherwise only the given 
-.B users 
-are allowed.
-
-.B proxyauth authname authdescription access [passwdfile [users]]
-
-The 
-.B proxyauth 
-directive defines access authorization to be used for Proxy access.
-.br
-.B authname 
-= Same as auth above
-.br
-.B authdescription 
-= Same as auth above
-.br
-.B access 
-= Must be R to allow proxy
-.br
-.B passwdfile 
-= Same as auth above
-.br
-.B users 
-= Same as auth above
-
-.B vpath from to [auth [access]]
-
-The 
-.B vpath 
-directive sets up URL path translations and authorizations.  A
-requested  URL that matches 
-.B from 
-will be translated to 
-.B to 
-with the given 
-.B auth 
-and 
-.B access.  
-If 
-.B auth 
-does not exist then the URL will have no 
-.B access.
-If 
-.B access 
-is not given then the access is taken from the 
-.B auth 
-record (see above).  A 
-.B '.' 
-in place of the 
-.B to 
-means that the server should use a translation from another 
-.B vpath 
-record, but associate the given 
-.B auth 
-and access with the requested URL.  A 
-.B '*' 
-may be at the end only of the 
-.B from
-to provide a wildcard match.  For example if the 
-.B from 
-has 
-.B /AB* 
-then any of
-.B /ABCDEF 
-or 
-.B /AB 
-or 
-.B /ABmichael 
-will match, but 
-.B /AD or 
-.B /a 
-will not.  The requested URL is first checked against each 
-.B vpath 
-record until an exact match (meaning URL match 
-.B from 
-and 
-.B from 
-had no 
-.B '*') 
-is found or the end of the list.  Therefore a wildcard match will match 
-the last 
-.B from in the list in which it matched.
-.br
-NOTE: if at the beginning of the to field
-.br
-      /~user will get translated to the home directory of the given user
-.br
-      // wile get translated to the serverroot directory
-
-.B include filename
-
-The 
-.B include 
-directive tells the server to read configuration information
-from the given filename.
-.br
-NOTE: normally you get 
-.B mtype 
-directives in an included file.
-
-.B mtype mimetype extensions
-
-The 
-.B mtype 
-directive tells the server what 
-.B mimetype 
-to associate with files which have any of the given 
-.B extensions.  
-If no match is found then the file will be treated as 
-.B application/octet-stream.
-
-
-.SH FILES
-.B /etc/httpd.conf
-.B /etc/httpd.mtype
-.B /etc/passwd
-.SH "SEE ALSO"
-.BR httpd (8)
-.BR http_status (5)
-.SH NOTES
-The source directory contains a commented sample 
-.B httpd.conf 
-and 
-.B httpd.mtype
-files
-P. 
-You can run the server as
-.B httpd -t /etc/httpd.conf
-to see whether the configuration file is being parsed correctly.
-.P
-Although standard Minix does not have a graphical interface to support
-browsers such as Netscape and Microsoft Internet Explorer, the 
-.B lynx
-browser can be used on 32-bit Minix systems with enough memory. You can point 
-lynx to your own site to browse your own pages.
-When debugging a web server there is nothing quite like browsing your own
-pages to see whether things are working right. That said, be aware that
-different web browsers may vary in how they interpet standard web page 
-features, and will certainly vary in how they interpret "extensions" to
-the HTML standards. So checking a page with several browsers on several 
-platforms is always a good idea.
-.SH BUGS
-Not really a bug, but you can get in trouble if a real directory you want
-to access shares the first part of its name with a 
-.B vpath
-definition. You just have to pay attention to the directory names you use.
-.SH AUTHOR
-The Minix httpd server was created by and is maintained by Michael Temari
-<Michael@TemWare.Com>
-.br
-This man page was compiled by Al Woodhull <awoodhull@hampshire.edu>
-.P
-updated 2003-07-06
Index: trunk/minix/commands/httpd/httpd.mtype
===================================================================
--- trunk/minix/commands/httpd/httpd.mtype	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-# mime types By Michael Temari 12/29/2002 Ver 0.40
-
-# if a file extension is not found in the configuration below the default
-# mime type will be application/octet-stream.  This default can be changed
-# by entering a line with a mime type only with no extension.
-
-mtype
-	application/octet-stream
-	application/compress		.Z
-	application/msword		.doc
-	application/octet-stream	.bin	.exe
-	application/pdf			.pdf
-	application/postscript		.ps	.ai	.eps
-	application/smil		.smil
-	application/x-gtar		.gtar
-	application/x-gzip		.gz
-	application/x-sh		.sh
-	application/x-pn-realaudio	.ra	.ram
-	application/x-tar		.tar
-	application/zip			.zip
-	audio/basic			.au	.snd
-	audio/mpeg			.mp3
-	audio/x-aiff			.aif	.aiff	.aifc
-	audio/x-midi			.mid
-	audio/x-wav			.wav
-	image/bmp			.bmp
-	image/gif			.gif
-	image/jpeg			.jpg	.jpeg	.jpe
-	image/png			.png
-	image/tiff			.tiff	.tif
-	image/x-rgb			.rgb
-	image/x-xbitmap			.xbm
-	multipart/x-www-form-urlencoded	.wfu
-	text/html			.html	.htm
-	text/plain			.txt	.c	.h
-	text/richtext			.rtf	.rtx
-	video/mpeg			.mpg	.mpeg	.mpe
-	video/quicktime			.qt	.mov
-	video/x-msvideo			.avi
-	video/x-sgi-movie		.movie
Index: trunk/minix/commands/httpd/httpd0993.txt
===================================================================
--- trunk/minix/commands/httpd/httpd0993.txt	(revision 9)
+++ 	(revision )
@@ -1,41 +1,0 @@
-httpd0993 --- A www server for Minix 2.0  
-written by Michael Temari <Michael@TemWare.Com> release 0.993 2003-07-??
-
-Httpd is a World Wide Web (WWW) server.  I wrote it from scratch so
-the setup and configuration will not be like other web servers though
-hopefully by reading this document there will be no problems in getting
-my web server up and running on your Minix system.
-
-This is the web server in use on minix1.hampshire.edu and
-minix1.bio.umass.edu.
-
-Installation: unpack the tarball in /usr/local/src or another directory 
-of your choice:
-zcat < httpd0993.tar.Z | tar xvfp -
-
-An httpd0993 directory will be created and files will be unpacked
-there.  The README file explains compilation, installation,
-configuration, and use. 
-
-Changes for release 0.993: 
-
-- a new method of authorizing proxy.  You will no longer need the Proxy
-entry in Auth and can remove the http://* entry in vpath.  The old way
-allowed for having different authorizations depending on what URLs were
-asked for via proxy, i.e., you could allow proxy access only to
-http:://www.hampshire.edu/. Now it is just a simple authorization for
-allowing proxy or not.  
-
-- avoids using a Minix 2.0.3 library call that was not present in Minix
-2.0.2, and thus can be compiled with either of the two most recent
-Minix releases.  
-
-- a -v option has been added to display the current version then exit.
-
-- man pages added, other documentation updated.
-
-Changes for release 0.99: You can set a default in the httpd.mtype
-file.  A mime type with no extensions on a line will be the default.
-Previously recompilation was needed to change the default mime type. 
-
-updated 2003-07-07
Index: trunk/minix/commands/httpd/net.c
===================================================================
--- trunk/minix/commands/httpd/net.c	(revision 9)
+++ 	(revision )
@@ -1,240 +1,0 @@
-/* net.c
- *
- * This file is part of httpd.
- *
- * 01/25/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002 			Michael Temari <Michael@TemWare.Com>
- *
- */
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include <net/gen/socket.h>
-#include <net/gen/netdb.h>
-
-#include "net.h"
-
-_PROTOTYPE(static void release, (int *fd));
-
-ipaddr_t myipaddr, rmtipaddr;
-tcpport_t myport, rmtport;
-char myhostname[256];
-char rmthostname[256];
-char rmthostaddr[3+1+3+1+3+1+3+1];
-
-void GetNetInfo()
-{
-nwio_tcpconf_t tcpconf;
-int s;
-struct hostent *hostent;
-
-   /* Ask the system what our hostname is. */
-   if(gethostname(myhostname, sizeof(myhostname)) < 0)
-	strcpy(myhostname, "unknown");
-
-   /* lets get our ip address and the clients ip address */
-   s = ioctl(0, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-   	myipaddr = 0;
-   	myport = 0;
-   	rmtipaddr = 0;
-   	rmtport = 0;
-   	strcpy(rmthostname, "??Unknown??");
-	strcpy(rmthostaddr, "???.???.???.???");
-   	return;
-   }
-
-   myipaddr = tcpconf.nwtc_locaddr;
-   myport = tcpconf.nwtc_locport;
-   rmtipaddr = tcpconf.nwtc_remaddr;
-   rmtport = tcpconf.nwtc_remport;
-
-   /* Look up the host name of the remote host. */
-   hostent = gethostbyaddr((char *) &rmtipaddr, sizeof(rmtipaddr), AF_INET);
-   if(!hostent)
-	strncpy(rmthostname, inet_ntoa(rmtipaddr), sizeof(rmthostname)-1);
-   else
-	strncpy(rmthostname, hostent->h_name, sizeof(rmthostname)-1);
-
-   strcpy(rmthostaddr, inet_ntoa(rmtipaddr));
-
-   rmthostname[sizeof(rmthostname)-1] = '\0';
-
-   return;
-}
-
-static void release(fd)
-int *fd;
-{
-   if(*fd != -1) {
-	close(*fd);
-	*fd= -1;
-   }
-}
-
-void daemonloop(service)
-char *service;
-{
-tcpport_t port;
-struct nwio_tcpcl tcplistenopt;
-struct nwio_tcpconf tcpconf;
-struct nwio_tcpopt tcpopt;
-struct servent *servent;
-char *tcp_device;
-int tcp_fd, client_fd, r;
-int pfd[2];
-unsigned stall= 0;
-
-   if((servent= getservbyname(service, "tcp")) == NULL) {
-	unsigned long p;
-	char *end;
-
-	p = strtoul(service, &end, 0);
-	if(p <= 0 || p > 0xFFFF || *end != 0) {
-		fprintf(stderr, "httpd: %s: Unknown service\n", service);
-		exit(1);
-	}
-	port= htons((tcpport_t) p);
-   } else
-	port= servent->s_port;
-
-   /* No client yet. */
-   client_fd= -1;
-
-   while (1) {
-   	if((tcp_device = getenv("TCP_DEVICE")) == NULL)
-   		tcp_device = TCP_DEVICE;
-	if ((tcp_fd= open(tcp_device, O_RDWR)) < 0) {
-			fprintf(stderr, "httpd: Can't open %s: %s",
-				tcp_device, strerror(errno));
-			if (errno == ENOENT || errno == ENODEV
-							|| errno == ENXIO) {
-				exit(1);
-			}
-			goto bad;
-		}
-
-		tcpconf.nwtc_flags= NWTC_LP_SET | NWTC_UNSET_RA | NWTC_UNSET_RP;
-		tcpconf.nwtc_locport= port;
-
-		if (ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf) < 0) {
-			fprintf(stderr, "httpd: Can't configure TCP channel",
-				strerror(errno));
-			exit(1);
-		}
-
-#ifdef NWTO_DEL_RST
-		tcpopt.nwto_flags= NWTO_DEL_RST;
-
-		if (ioctl(tcp_fd, NWIOSTCPOPT, &tcpopt) < 0) {
-			fprintf(stderr, "httpd: Can't set TCP options",
-				strerror(errno));
-			exit(1);
-		}
-#endif
-
-		if (client_fd != -1) {
-			/* We have a client, so start a server for it. */
-
-#ifdef NWTO_DEL_RST
-			tcpopt.nwto_flags= 0;
-			(void) ioctl(client_fd, NWIOSTCPOPT, &tcpopt);
-#endif
-
-			fflush(NULL);
-
-			/* Create a pipe to serve as an error indicator. */
-			if (pipe(pfd) < 0) {
-				fprintf(stderr, "httpd: pipe", strerror(errno));
-				goto bad;
-			}
-
-			/* Fork twice to daemonize child. */
-			switch (fork()) {
-			case -1:
-				fprintf(stderr, "httpd: fork", strerror(errno));
-				close(pfd[0]);
-				close(pfd[1]);
-				goto bad;
-			case 0:
-				close(tcp_fd);
-				close(pfd[0]);
-				switch (fork()) {
-				case -1:
-					fprintf(stderr, "httpd: fork",
-						strerror(errno));
-					write(pfd[1], &errno, sizeof(errno));
-					exit(1);
-				case 0:
-					break;
-				default:
-					exit(0);
-				}
-				dup2(client_fd, 0);
-				dup2(client_fd, 1);
-				close(client_fd);
-				close(pfd[1]);
-
-				/* Break out of the daemon loop, continuing with
-				 * the normal httpd code to serve the client.
-				 */
-				return;
-
-			default:
-				release(&client_fd);
-				close(pfd[1]);
-				wait(NULL);
-				r= read(pfd[0], &errno, sizeof(errno));
-				close(pfd[0]);
-				if (r != 0) goto bad;
-				break;
-			}
-		}
-
-		/* Wait for a new connection. */
-		tcplistenopt.nwtcl_flags= 0;
-
-		while (ioctl(tcp_fd, NWIOTCPLISTEN, &tcplistenopt) < 0) {
-			if (errno != EAGAIN) {
-				fprintf(stderr, "httpd: Unable to listen: %s",
-					strerror(errno));
-			}
-			goto bad;
-		}
-
-		/* We got a connection. */
-		client_fd= tcp_fd;
-		tcp_fd= -1;
-
-		/* All is well, no need to stall. */
-		stall= 0;
-		continue;
-
-	bad:
-		/* All is not well, release resources. */
-		release(&tcp_fd);
-		release(&client_fd);
-
-		/* Wait a bit if this happens more than once. */
-		if (stall != 0) {
-			sleep(stall);
-			stall <<= 1;
-		} else {
-			stall= 1;
-		}
-	}
-}
Index: trunk/minix/commands/httpd/net.h
===================================================================
--- trunk/minix/commands/httpd/net.h	(revision 9)
+++ 	(revision )
@@ -1,17 +1,0 @@
-/* net.h
- *
- * This file is part of httpd.
- *
- *
- * 01/25/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002			Michael Temari <Michael@TemWare.Com>
- *
- */
-
-_PROTOTYPE(void GetNetInfo, (void));
-_PROTOTYPE(void daemonloop, (char *service));
-
-extern char myhostname[256];
-extern char rmthostname[256];
-extern char rmthostaddr[3+1+3+1+3+1+3+1];
Index: trunk/minix/commands/httpd/pass.c
===================================================================
--- trunk/minix/commands/httpd/pass.c	(revision 9)
+++ 	(revision )
@@ -1,213 +1,0 @@
-/* pass.c
- *
- * This file is part of httpd.
- *
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002 			Michael Temari <Michael@TemWare.Com>
- *
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <pwd.h>
-#ifdef _MINIX
-#include <minix/minlib.h>
-#endif
-
-#define	STD_PASSWD_FILE	"/etc/passwd"
-
-#include "pass.h"
-
-static char buffer[1024];
-static char *pwduser;
-static char *pwdpass;
-static char *pwde[4];
-
-_PROTOTYPE(static int getuser, (char *pwdfile, char *user));
-
-static int getuser(pwdfile, user)
-char *pwdfile;
-char *user;
-{
-FILE *fp;
-char *p;
-int i;
-
-   if((fp = fopen(pwdfile, "r")) == (FILE *)NULL)
-	return(-1);
-
-   for(i = 0; i < 4; i ++) pwde[i] = "";
-
-   while(1) {
-	if(fgets(buffer, sizeof(buffer), fp) == (char *)NULL) {
-		fclose(fp);
-		return(-1);
-	}
-	p = buffer;
-	pwduser = p;
-	while(*p && *p != ':') p++;
-	if(*p != ':') continue;
-	*p++ = '\0';
-	if(strcmp(pwduser, user)) continue;
-	pwdpass = p;
-	while(*p && *p != ':' && *p != '\r' && *p != '\n') p++;
-	if(*p == ':')
-		*p++ = '\0';
-	else {
-		if(*p) *p = '\0';
-		fclose(fp);
-	}
-	for(i = 0; i < 4; i++) {
-		pwde[i] = p;
-		while(*p && *p != ':' && *p != '\r' && *p != '\n') p++;
-		if(*p == ':')
-			*p++ = '\0';
-		else {
-			if(*p) *p = '\0';
-			break;
-		}
-	}
-	fclose(fp);
-
-	return(0);
-   }
-}
-
-int passfile(pwdfile)
-char *pwdfile;
-{
-FILE *fp;
-
-   if(!strcmp(pwdfile, STD_PASSWD_FILE))
-	return(0);
-
-   if((fp = fopen(pwdfile, "r")) == (FILE *)NULL)
-	return(-1);
-
-   fclose(fp);
-
-   return(0);
-}
-
-int passuser(pwdfile, user)
-char *pwdfile;
-char *user;
-{
-   if(!strcmp(pwdfile, STD_PASSWD_FILE))
-	if(getpwnam(user) == (struct passwd *)NULL)
-		return(-1);
-	else
-		return(0);
-
-   return(getuser(pwdfile, user));
-}
-
-int passnone(pwdfile, user)
-char *pwdfile;
-char *user;
-{
-struct passwd *pwd;
-
-   if(!strcmp(pwdfile, STD_PASSWD_FILE))
-	if((pwd = getpwnam(user)) == (struct passwd *)NULL)
-		return(-1);
-	else
-		if(!strcmp(pwd->pw_passwd, crypt("", pwd->pw_passwd)))
-			return(-1);
-		else
-			return(0);
-
-   if(getuser(pwdfile, user))
-	return(-1);
-
-   if(!strcmp(pwdpass, crypt("", pwdpass)))
-	return(-1);
-   else
-	return(0);
-}
-
-int passpass(pwdfile, user, pass)
-char *pwdfile;
-char *user;
-char *pass;
-{
-struct passwd *pwd;
-
-   if(!strcmp(pwdfile, STD_PASSWD_FILE))
-	if((pwd = getpwnam(user)) == (struct passwd *)NULL)
-		return(-1);
-	else
-		if(strcmp(pwd->pw_passwd, crypt(pass, pwd->pw_passwd)))
-			return(-1);
-		else
-			return(0);
-
-   if(getuser(pwdfile, user))
-	return(-1);
-
-   if(strcmp(pwdpass, crypt(pass, pwdpass)))
-	return(-1);
-   else
-	return(0);
-}
-
-int passadd(pwdfile, user, pass, e1, e2, e3, e4)
-char *pwdfile;
-char *user;
-char *pass;
-char *e1;
-char *e2;
-char *e3;
-char *e4;
-{
-FILE *fp;
-time_t salt;
-char sl[2];
-int cn;
-char *ee1;
-char *ee2;
-char *ee3;
-char *ee4;
-
-
-   if(pwdfile == (char *)NULL ||
-	 user == (char *)NULL ||
-	 pass == (char *)NULL)
-	return(PASS_ERROR);
-
-   if(!strcmp(pwdfile, STD_PASSWD_FILE))
-	return(PASS_ERROR);
-
-   if(!getuser(pwdfile, user))
-	return(PASS_USEREXISTS);
-
-   time(&salt);
-   sl[0] = (salt & 077) + '.';
-   sl[1] = ((salt >> 6) & 077) + '.';
-   for (cn = 0; cn < 2; cn++) {
-	if (sl[cn] > '9') sl[cn] += 7;
-	if (sl[cn] > 'Z') sl[cn] += 6;
-   }
-
-   if(e1 == (char *)NULL) ee1 = ""; else ee1 = e1;
-   if(e2 == (char *)NULL) ee2 = ""; else ee2 = e2;
-   if(e3 == (char *)NULL) ee3 = ""; else ee3 = e3;
-   if(e4 == (char *)NULL) ee4 = ""; else ee4 = e4;
-
-   /* XXX need to add locking mechanics to add new user */
-
-   if((fp = fopen(pwdfile, "a")) == (FILE *)NULL)
-	return(PASS_ERROR);
-
-   fprintf(fp, "%s:%s:%s:%s:%s:%s\n", user, crypt(pass, sl), ee1, ee2, ee3, ee4);
-
-   fclose(fp);
-
-   /* XXX need to add unlocking mechanics to add new user */
-
-   return(PASS_GOOD);
-}
Index: trunk/minix/commands/httpd/pass.h
===================================================================
--- trunk/minix/commands/httpd/pass.h	(revision 9)
+++ 	(revision )
@@ -1,18 +1,0 @@
-/* pass.h
- *
- * This file is part of httpd.
- *
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002 Initial Release	Michael Temari <Michael@TemWare.Com>
- *
- */
-
-_PROTOTYPE(int passfile, (char *pwdfile));
-_PROTOTYPE(int passuser, (char *pwdfile, char *user));
-_PROTOTYPE(int passnone, (char *pwdfile, char *user));
-_PROTOTYPE(int passpass, (char *pwdfile, char *user, char *pass));
-_PROTOTYPE(int passadd,  (char *pwdfile, char *user, char *pass, char *e1, char *e2, char *e3, char *e4));
-
-#define	PASS_GOOD	0
-#define	PASS_USEREXISTS	1
-#define	PASS_ERROR	-1	
Index: trunk/minix/commands/httpd/police.c
===================================================================
--- trunk/minix/commands/httpd/police.c	(revision 9)
+++ 	(revision )
@@ -1,407 +1,0 @@
-/* police.c
- *
- * This file is part of httpd.
- *
- * 02/17/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002			Michael Temari <Michael@TemWare.Com>
- *
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "http.h"
-#include "utility.h"
-#include "config.h"
-#include "pass.h"
-
-#define	MATCH_NONE	0
-#define	MATCH_WILD	1
-#define	MATCH_FULL	2
-
-_PROTOTYPE(static int authaccess, (struct http_request *rq, struct http_reply *rp));
-_PROTOTYPE(static void purl, (struct http_request *rq, struct http_reply *rp));
-_PROTOTYPE(static char *virt, (char *to, char *host));
-
-static int authaccess(rq, rp)
-struct http_request *rq;
-struct http_reply *rp;
-{
-struct auth *auth;
-struct authuser *pu;
-
-   /* set authorization to be checked against */
-   if(rq->type == HTTP_REQUEST_TYPE_PROXY)
-   	auth = proxyauth;
-   else
-   	auth = rp->auth;
-
-   /* no authorization so no access to anyone */
-   if(auth == NULL) {
-   	rp->status = HTTP_STATUS_FORBIDDEN;
-   	strcpy(rp->statusmsg, "No Authoriation");
-   	return(-1);
-   }
-
-   /* access must be R for PROXY */
-   if(rq->type == HTTP_REQUEST_TYPE_PROXY)
-	if(!(auth->urlaccess & URLA_READ)) {
-   		rp->status = HTTP_STATUS_FORBIDDEN;
-   		strcpy(rp->statusmsg, "Proxy not authorized");
-   		return(-1);
-	}
-
-   /* no password file so it is a free for all */
-   if(auth->passwdfile == NULL)
-	return(0);
-
-   /* they did not give us an authorized user */
-   if(rq->authuser[0] == '\0') {
-	if(rq->type == HTTP_REQUEST_TYPE_PROXY)
-   		rp->status = HTTP_STATUS_PROXY_AUTH_REQRD;
-   	else
-   		rp->status = HTTP_STATUS_UNAUTHORIZED;
-   	strcpy(rp->statusmsg, "No Authorized User Given");
-   	return(-1);
-   }
-
-   /* check if user okay */
-   pu = auth->users;
-   if(pu == NULL)
-	;	/* no user list we allow anyone in file */
-   else {
-	while(pu != NULL) {
-		if(!strcmp(pu->user, rq->authuser))
-			break;
-		pu = pu->next;
-	}
-	/* user is not in list so no access */
-	if(pu == NULL) {
-		if(rq->type == HTTP_REQUEST_TYPE_PROXY)
-   			rp->status = HTTP_STATUS_PROXY_AUTH_REQRD;
-   		else
-			rp->status = HTTP_STATUS_UNAUTHORIZED;
-		strcpy(rp->statusmsg, "Forbidden User not authorized");
-		return(-1);
-	}
-   }
-
-   /* check if password file exists, if not no access */
-   if(passfile(auth->passwdfile)) {
-   	rp->status = HTTP_STATUS_FORBIDDEN;
-   	strcpy(rp->statusmsg, "Invalid passwd file");
-   	return(-1);
-   }
-
-   /* check if user in password file, if not no access */
-   if(passuser(auth->passwdfile, rq->authuser)) {
-	if(rq->type == HTTP_REQUEST_TYPE_PROXY)
-   		rp->status = HTTP_STATUS_PROXY_AUTH_REQRD;
-   	else
-		rp->status = HTTP_STATUS_UNAUTHORIZED;
-	strcpy(rp->statusmsg, "Forbidden Bad User");
-	return(-1);
-   }
-
-   /* check if a password exists, if not no access */
-   if(passnone(auth->passwdfile, rq->authuser)) {
-	if(rq->type == HTTP_REQUEST_TYPE_PROXY)
-   		rp->status = HTTP_STATUS_PROXY_AUTH_REQRD;
-   	else
-		rp->status = HTTP_STATUS_UNAUTHORIZED;
-	strcpy(rp->statusmsg, "Forbidden no password");
-	return(-1);
-   }
-
-   /* check if password matches, if not no access */
-   if(passpass(auth->passwdfile, rq->authuser, rq->authpass)) {
-	if(rq->type == HTTP_REQUEST_TYPE_PROXY)
-   		rp->status = HTTP_STATUS_PROXY_AUTH_REQRD;
-   	else
-		rp->status = HTTP_STATUS_UNAUTHORIZED;
-	strcpy(rp->statusmsg, "Forbidden bad password");
-	return(-1);
-   }
-
-   /* whew, all the checks passed so I guess we let them have it */
-   return(0);
-}
-
-int police(rq, rp)
-struct http_request *rq;
-struct http_reply *rp;
-{
-int size;
-struct stat st;
-struct dirsend *ds;
-
-   purl(rq, rp);
-
-   rp->mtype = "text/html";
-
-#ifdef DEBUG
-   fprintf(stderr, "httpd: Trying %s\n", rp->realurl);
-#endif
-
-   /* now check authorizations */
-   if(authaccess(rq, rp)) {
-	/* Don't give them any details why authorization failed */
-   	strcpy(rp->statusmsg, "No Access Granted");
-	return(0);
-   }
-
-   /* a proxy request only needs an authorization check */
-   if(rq->type == HTTP_REQUEST_TYPE_PROXY)
-	return(0);
-
-   /* check access to real url */
-   if(stat(rp->realurl, &st)) {
-	if(errno == EACCES)
-		rp->status = HTTP_STATUS_FORBIDDEN;
-	else
-		rp->status = HTTP_STATUS_NOT_FOUND;
-	strcpy(rp->statusmsg, strerror(errno));
-	/* a PUT and NOT FOUND is okay since we are creating */
-	if(rq->method != HTTP_METHOD_PUT || rp->status != HTTP_STATUS_NOT_FOUND)
-		return(0);
-   }
-
-   /* If it is a directory do the appropriate thang! */
-   if(rq->method == HTTP_METHOD_GET || rq->method == HTTP_METHOD_HEAD)
-   if((st.st_mode & S_IFMT) == S_IFDIR) {
-	if(rq->url[strlen(rq->url) - 1] != '/') {
-		strncat(rq->url, "/", sizeof(rq->url) - strlen(rq->url));
-		rp->status = HTTP_STATUS_MOVED_TEMP;
-		sprintf(rp->statusmsg, "Moved to %s", rq->url);
-		return(0);
-	}
-	size = strlen(rq->url);
-	ds = dirsend;
-	while(ds != NULL) {
-		strncpy(rq->url+size, ds->file, sizeof(rq->url)-size);
-		purl(rq, rp);
-		if(stat(rp->realurl, &st)) {
-			if(errno == EACCES)
-				rp->status = HTTP_STATUS_FORBIDDEN;
-			else
-			if(errno != ENOENT)
-				rp->status = HTTP_STATUS_NOT_FOUND;
-		} else
-			break;
-		if(rp->status != HTTP_STATUS_OK) {
-			strcpy(rp->statusmsg, strerror(errno));
-			return(0);
-		}
-		ds = ds->next;
-	}
-	if(ds == NULL) {
-		rq->url[size] = '\0';
-		purl(rq, rp);
-		if(stat(rp->realurl, &st)) {
-	   		if(errno == EACCES)
-   				rp->status = HTTP_STATUS_FORBIDDEN;
-   			else
-				rp->status = HTTP_STATUS_NOT_FOUND;
-			strcpy(rp->statusmsg, strerror(errno));
-			return(0);
-		}
-	}
-   }
-
-   if(rq->method == HTTP_METHOD_PUT && !(rp->urlaccess & URLA_WRITE)) {
-	rp->status = HTTP_STATUS_METHOD_NOT_ALLOWED;
-	strcpy(rp->statusmsg, "Method not allowed");
-	return(0);
-   }
-
-   if(rp->status == HTTP_STATUS_OK) {
-	/* Here is where we check if it is a program or script to run */
-	if(cgiexec(rq, rp))
-   		return(0);
-
-	if((st.st_mode & S_IFMT) == S_IFDIR) {
-		rp->status = HTTP_STATUS_NOT_FOUND;
-		strcpy(rp->statusmsg, "Directory listing not available");
-		return(0);
-	}
-
-	if((st.st_mode & S_IFMT) != S_IFREG) {
-		rp->status = HTTP_STATUS_NOT_FOUND;
-		strcpy(rp->statusmsg, "Not a regular file");
-		return(0);
-	}
-   }
-
-   /* open the URL for updating */
-   if(rq->method == HTTP_METHOD_PUT) {
-	rp->status = HTTP_STATUS_OK;
-	strcpy(rp->statusmsg, "OK");
-	rp->ofd = open(rp->realurl, O_WRONLY | O_CREAT | O_TRUNC);
-	if(rp->ofd < 0) {
-   		if(errno == EACCES)
-   			rp->status = HTTP_STATUS_FORBIDDEN;
-   		else
-			rp->status = HTTP_STATUS_NOT_FOUND;
-		strcpy(rp->statusmsg, strerror(errno));
-		return(0);
-	}
-	return(0);
-   }
-
-   if(!(rp->urlaccess & URLA_READ)) {
-   	rp->status = HTTP_STATUS_FORBIDDEN;
-   	strcpy(rp->statusmsg, "No way...");
-	return(0);
-   }
-
-   rp->mtype = mimetype(rp->realurl);
-
-   rp->size = st.st_size;
-   rp->modtime = st.st_mtime;
-
-   /* open the url if it is a file */
-   rp->fd = open(rp->realurl, O_RDONLY);
-   if(rp->fd < 0) {
-	if(errno == EACCES)
-   		rp->status = HTTP_STATUS_FORBIDDEN;
-   	else
-		rp->status = HTTP_STATUS_NOT_FOUND;
-	strcpy(rp->statusmsg, strerror(errno));
-	return(0);
-   }
-
-   return(0);
-}
-
-static void purl(rq, rp)
-struct http_request *rq;
-struct http_reply *rp;
-{
-struct vpath *pv;
-int gotreal, gotperm;
-char *p;
-int match;
-int len;
-
-   gotreal = 0; gotperm = 0;
-
-#ifdef DEBUG
-   fprintf(stderr, "httpd: Processing url = \"%s\"\n", rq->url);
-#endif
-
-   /* remove any .. references */
-   p = rq->url;
-   while(*p) {
-	while(*p && *p != '/') p++;
-	if(*p != '/') continue;
-	p++;
-	if(*p != '.') continue;
-	p++;
-	if(*p != '.') continue;
-	p++;
-	strcpy(p - 3, p);
-	p = p - 3;
-   }
-
-   for(pv = vpath; pv != NULL; pv = pv->next) {
-   	len = strlen(pv->from) - 1;
-   	if(pv->from[len] == '*' || pv->from[len] == '$')
-   		if(len == 0)
-   			match = MATCH_WILD;
-   		else
-   			match = strncmp(rq->url, pv->from, len) ? MATCH_NONE : MATCH_WILD;
-   	else
-   		if(!strcmp(rq->url, pv->from))
-   			match = MATCH_FULL;
-   		else
-   			match = MATCH_NONE;
-#ifdef DEBUG
-   	fprintf(stderr, "httpd: Trying \"%s\" %d %d %d %s\n",
-		pv->from, match, gotreal, gotperm, pv->auth->name);
-#endif
-   	if(match != MATCH_NONE) {
-		gotperm = 1;
-		rp->auth = pv->auth;
-		if(pv->urlaccess == -1 && rp->auth != NULL)
-			rp->urlaccess = rp->auth->urlaccess;
-		else
-			rp->urlaccess = pv->urlaccess;
-   		if(strcmp(pv->to, ".")) {
-   			gotreal = 1;
-   			strncpy(rp->realurl, virt(pv->to, rq->host), sizeof(rp->realurl));
-			rp->realurl[sizeof(rp->realurl)-1] = '\0';
-			if(match == MATCH_WILD && pv->from[len] != '$') {
-   				strncat(rp->realurl, rq->url+len, sizeof(rp->realurl) - strlen(rp->realurl));
-				rp->realurl[sizeof(rp->realurl)-1] = '\0';
-			}
-   		}
-   	}
-   	if(match == MATCH_FULL) break;
-   }
-
-   if(rp->urlaccess == -1) rp->urlaccess = mkurlaccess("");
-
-   if(!gotreal) {
-	strncpy(rp->realurl, rq->url, sizeof(rp->realurl));
-	rp->realurl[sizeof(rp->realurl)-1] = '\0';
-   }
-
-   if(!gotperm)
-   	rp->auth = NULL;
-
-#ifdef DEBUG
-   fprintf(stderr, "DEBUG: url = \"%s\"  realurl = \"%s\"  auth = \"%s\"\n",
-	rq->url, rp->realurl, ((rp->auth == NULL) ? "No Access" : rp->auth->name));
-   fprintf(stderr, "DEBUG: query = %s\n", rq->query);
-#endif
-
-   return;
-}
-
-static char *virt(to, host)
-char *to;
-char *host;
-{
-static char vroot[256];
-struct vhost *ph;
-
-#ifdef DEBUG
-fprintf(stderr, "virt: %s %s\n", to, host);
-#endif
-
-   if(vhost == NULL) return(to);
-
-   if(to[0] != '/') return(to);
-   if(to[1] != '/') return(to);
-   if(to[2] != '/') return(to);
-
-   vroot[0] = '\0';
-
-   for(ph = vhost; ph != NULL; ph = ph->next) {
-#ifdef DEBUG
-   	fprintf(stderr, "ph: %s %s %s\n", ph->hname, ph->root, vroot);
-#endif
-   	if(!strcmp(ph->hname, "*") && vroot[0] == '\0')
-   		strncpy(vroot, ph->root, sizeof(vroot));
-   	if(!strcasecmp(ph->hname, host)) {
-   		strncpy(vroot, ph->root, sizeof(vroot));
-   		break;
-   	}
-   }
-
-   strncat(vroot, to+3, sizeof(vroot));
-
-#ifdef DEBUG
-   fprintf(stderr, "vroot: %s\n", vroot);
-#endif
-
-   return(vroot);
-}
Index: trunk/minix/commands/httpd/process.c
===================================================================
--- trunk/minix/commands/httpd/process.c	(revision 9)
+++ 	(revision )
@@ -1,81 +1,0 @@
-/* process.c
- *
- * This file is part of httpd.
- *
- * 02/17/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Relase	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002			Michael Temari <Michael@TemWare.Com>
- *
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "config.h"
-#include "http.h"
-#include "utility.h"
-
-int processrequest(rq, rp)
-struct http_request *rq;
-struct http_reply *rp;
-{
-   /* clear out http_reply */
-   memset(rp, 0, sizeof(*rp));
-   rp->status = HTTP_STATUS_OK;
-   strcpy(rp->statusmsg, "OK");
-   rp->modtime = (time_t) -1;
-   rp->urlaccess = -1;
-   rp->size = 0;
-   rp->fd = -1;
-   rp->ofd = -1;
-   rp->pid = 0;
-
-   /* Simple requests can only be a GET */
-   if(rq->type == HTTP_REQUEST_TYPE_SIMPLE && rq->method != HTTP_METHOD_GET) {
-   	rp->status = HTTP_STATUS_BAD_REQUEST;
-   	strcpy(rp->statusmsg, "Bad request");
-   	return(0);
-   }
-
-   /* I don't know this method */
-   if(rq->method == HTTP_METHOD_UNKNOWN) {
-	rp->status = HTTP_STATUS_NOT_IMPLEMENTED;
-	strcpy(rp->statusmsg, "Method not implemented");
-	return(0);
-   }
-
-   /* Check for access and real location of url */
-   if(police(rq, rp))
-   	return(-1);
-
-   /* We're done if there was an error accessing the url */
-   if(rp->status != HTTP_STATUS_OK)
-   	return(0);
-		
-   /* Check to see if we have a newer version for them */
-   if(rq->method == HTTP_METHOD_GET)
-	if(rq->ifmodsince != (time_t) -1)
-   		if(rq->ifmodsince < time((time_t *)NULL))
-   			if(rp->modtime != (time_t) -1 && rp->modtime <= rq->ifmodsince) {
-   				rp->status = HTTP_STATUS_NOT_MODIFIED;
-   				strcpy(rp->statusmsg, "Not modified");
-   				close(rp->fd);
-   				rp->fd = -1;
-   				return(0);
-   			}
-
-   rp->status = HTTP_STATUS_OK;
-   strcpy(rp->statusmsg, "OK");
-
-   if(rp->size != 0)
-	rp->keepopen = rq->keepopen;
-
-   return(0);
-}
Index: trunk/minix/commands/httpd/proxy.c
===================================================================
--- trunk/minix/commands/httpd/proxy.c	(revision 9)
+++ 	(revision )
@@ -1,292 +1,0 @@
-/* proxy.c Copyright 2000 by Michael Temari All Rights Reserved */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-#include <time.h>
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include <net/gen/socket.h>
-#include <net/gen/netdb.h>
-
-#include "config.h"
-#include "http.h"
-#include "utility.h"
-#include "net.h"
-
-_PROTOTYPE(static int connect, (char *host));
-#if 0
-_PROTOTYPE(static int readline, (char *p, int len));
-#endif
-_PROTOTYPE(static int sendout, (int fd, char *data));
-
-static int connect(host)
-char *host;
-{
-nwio_tcpconf_t tcpconf;
-nwio_tcpcl_t tcpcopt;
-char *tcp_device;
-int netfd;
-ipaddr_t nethost;
-tcpport_t netport = 0;
-struct hostent *hp;
-struct servent *sp;
-char *p;
-int s;
-int tries;
-
-   p = host;
-   while(*p && *p != ':') p++;
-   if(*p == ':') {
-   	*p++ = '\0';
-   	netport = htons(atoi(p));
-   }
-
-   if((hp = gethostbyname(host)) == (struct hostent *)NULL) {
-	fprintf(stderr, "Unknown host %s!\n", host);  
-	return(-1);
-   } else
-	memcpy((char *) &nethost, (char *) hp->h_addr, hp->h_length);
-
-   /* Now, to which port must we connect? */
-   if(netport == 0)
-	if((sp = getservbyname("http", "tcp")) == (struct servent *)NULL) {
-		fprintf(stderr, "HTTP port is unknown????\n");
-		return(-1);
-	} else
-		netport = sp->s_port;
-
-   /* Connect to the host */
-   if((tcp_device = getenv("TCP_DEVICE")) == NULL)
-	tcp_device = TCP_DEVICE;
-
-   if((netfd = open(tcp_device, O_RDWR)) < 0) {
-	perror("httpget: opening tcp");
-	return(-1);
-   }
-
-   tcpconf.nwtc_flags = NWTC_LP_SEL | NWTC_SET_RA | NWTC_SET_RP;
-   tcpconf.nwtc_remaddr = nethost;
-   tcpconf.nwtc_remport = netport;
-
-   s = ioctl(netfd, NWIOSTCPCONF, &tcpconf);
-   if(s < 0) {
-	perror("httpget: NWIOSTCPCONF");
-	close(netfd);
-	return(-1);
-   }
-
-   s = ioctl(netfd, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-	perror("httpget: NWIOGTCPCONF");
-	close(netfd);
-	return(-1);
-   }
-
-   tcpcopt.nwtcl_flags = 0;
-
-   tries = 0;
-   do {
-	s = ioctl(netfd, NWIOTCPCONN, &tcpcopt);
-	if(s == -1 && errno == EAGAIN) {
-		if(tries++ >= 10)
-			break;
-		sleep(10);
-	} else
-		break;
-   } while(1);
-
-   if(s < 0) {
-	perror("httpget: NWIOTCPCONN");
-	close(netfd);
-	return(-1);
-   }
-
-   return(netfd);
-}
-
-char buffer[8192];
-
-#if 0
-static int readline(p, len)
-char *p;
-int len;
-{
-int c;
-int cr = 0;
-int n = 0;
-
-   len--;
-   if(len < 0) return(-1);
-   while(len > 0 && (c = getchar()) != EOF) {
-   	if(c == '\n' && cr) {
-   		*p = '\0';
-   		return(n);
-   	}
-   	if(c == '\r') {
-   		cr = 1;
-   		continue;
-   	}
-   	n++;
-   	*p++ = c;
-   }
-   *p = '\0';
-   return(n);
-}
-#endif
-
-static int sendout(fd, data)
-int fd;
-char *data;
-{
-   if(strlen(data) > 0)
-	write(fd, data, strlen(data));
-	write(fd, "\r\n", 2);
-	if(dbglog != (FILE *)NULL) {
-		fprintf(dbglog, "REPLY: %s\n", data);
-	fflush(dbglog);
-   }
-
-   return(0);
-}
-
-void proxy(rq, rp)
-struct http_request *rq;
-struct http_reply *rp;
-{
-int s;
-char *p;
-char *ps;
-char *b;
-char *host;
-static char user[256];
-static char pass[256];
-char *url;
-char *at;
-int fd;
-int bad;
-
-   while(1) {
-   	bad = 0;
-   	p = rq->uri;
-   	if(tolower(*p++) != 'h') bad++;
-   	if(tolower(*p++) != 't') bad++;
-   	if(tolower(*p++) != 't') bad++;
-   	if(tolower(*p++) != 'p') bad++;
-   	if(tolower(*p++) != ':') bad++;
-   	if(tolower(*p++) != '/') bad++;
-   	if(tolower(*p++) != '/') bad++;
-   	if(bad) {
-		sprintf(buffer, "HTTP/%d.%d 400 Bad Request",
-			rq->vmajor, rq->vminor);
-		sendout(1, buffer);
-		sendout(1, "");
-		sendout(1, "Proxy Request was not http:");
-		return;
-   	}
-   	host = p;
-	while(*p && *p != '/') p++;
-	url = p;
-	*url = '\0';
-	at = strchr(host, '@');
-	if(at != (char *)NULL) {
-		*at = '\0';
-		p = host;
-		while(*p && *p != ':') p++;
-		if(*p)
-			*p++ = '\0';
-		strcpy(user, host);
-		strcpy(pass, p);
-		host = at + 1;
-	} else {
-		user[0] = '\0';
-		pass[0] = '\0';
-	}
-
-   	fd = connect(host);
-   	if(fd < 0) {
-		sprintf(buffer, "HTTP/%d.%d 400 Bad Request",
-			rq->vmajor, rq->vminor);
-		sendout(1, buffer);
-		sendout(1, "");
-		sendout(1, "Could not connect to host");
-		return;
-   	}
-   	if(rq->method == HTTP_METHOD_GET)
-   		write(fd, "GET ", 4); else
-   	if(rq->method == HTTP_METHOD_POST)
-   		write(fd, "POST ", 5);
-   	*url = '/';
-   	if(strlen(url) > 0)
-   		write(fd, url, strlen(url));
-   	write(fd, " ", 1);
-	sprintf(buffer, "HTTP/%d.%d", rq->vmajor, rq->vminor);
-	sendout(fd, buffer);
-   	if(rq->ifmodsince != -1) {
-   		write(fd, "If-Mod-Since: ", 14);
-   		sendout(fd, httpdate(&rq->ifmodsince));
-   	}
-	if(rq->size != 0) {
-		sendout(fd, "Content-Type: application/x-www-form-urlencoded");
-		sprintf(buffer, "Content-Length: %lu", rq->size);
-		sendout(fd, buffer);
-	}
-	if(*rq->cookie) {
-		sprintf(buffer, "Cookie: %s", rq->cookie);
-		sendout(fd, buffer);
-	}
-	if(*rq->useragent) {
-		sprintf(buffer, "User-Agent: %s", rq->useragent);
-		sendout(fd, buffer);
-	}
-	if(*rq->host) {
-		sprintf(buffer, "Host: %s", rq->host);
-		sendout(fd, buffer);
-	}
-	if(*rq->wwwauth) {
-		sprintf(buffer, "Authorization: %s", rq->wwwauth);
-		sendout(fd, buffer);
-	}
-	sprintf(buffer, "X-Forwarded-From: %s", rmthostaddr);
-	sendout(fd, buffer);
-   	sendout(fd, "");
-	if(rq->size != 0) {
-		if(stdlog != (FILE *)NULL) {
-			fprintf(stdlog, "%s %s %d %d ",
-				logdate((time_t *)NULL), rmthostname,
-				rq->method, rp->status);
-			fprintf(stdlog, "proxy %s?", rq->uri);
-		}
-	   	while((s = read(0, buffer, rq->size >
-   			sizeof(buffer) ? sizeof(buffer) : rq->size)) > 0) {
-   			write(fd, buffer, s);
-   			rq->size -= s;
-   			b = buffer;
-   			if(stdlog != (FILE *)NULL)
-   				while(s--) fputc(*b++, stdlog);
-			if(rq->size == 0) break;
-   		}
-   		if(stdlog != (FILE *)NULL) {
-   			fprintf(stdlog, "\n");
-			fflush(stdlog);
-		}
-   	}
-   	while((s = read(fd, buffer, sizeof(buffer))) > 0) {
-   		write(1, buffer, s);
-   	}
-   	close(fd);
-   	return;
-   }
-}
Index: trunk/minix/commands/httpd/reply.c
===================================================================
--- trunk/minix/commands/httpd/reply.c	(revision 9)
+++ 	(revision )
@@ -1,189 +1,0 @@
-/* reply.c
- *
- * This file is part of httpd.
- *
- * 02/17/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002 			Michael Temari <Michael@TemWare.Com>
- *
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <signal.h>
-
-#include "http.h"
-#include "utility.h"
-#include "net.h"
-#include "config.h"
-
-#define	SERVER	"Server: "VERSION
-
-_PROTOTYPE(static void GotAlarm, (int sig));
-_PROTOTYPE(static int sendout, (char *data));
-
-static void GotAlarm(sig)
-int sig;
-{
-}
-
-static int sendout(data)
-char *data;
-{
-   if(strlen(data) > 0)
-	write(1, data, strlen(data));
-   write(1, "\r\n", 2);
-   if(dbglog != (FILE *)NULL) {
-	fprintf(dbglog, "REPLY: %s\n", data);
-	fflush(dbglog);
-   }
-
-   return(0);
-}
-
-int sendreply(rp, rq)
-struct http_reply *rp;
-struct http_request *rq;
-{
-int s;
-int s2;
-int e;
-static char buffer[8192];
-
-   if(rq->type != HTTP_REQUEST_TYPE_PROXY)
-   /* We're receiving data from a */
-   if(rq->method == HTTP_METHOD_POST ||
-     (rq->method == HTTP_METHOD_PUT && rp->status == HTTP_STATUS_OK)) {
-   	if(rq->type != HTTP_REQUEST_TYPE_FULL)
-   		return(0);
-   	if(rq->method == HTTP_METHOD_PUT)
-   		rp->status = HTTP_STATUS_CREATED;
-   	else
-   		rp->status = HTTP_STATUS_OK;
-   	while(rq->size != 0) {
-   		s = read(0, buffer, (rq->size > sizeof(buffer)) ? sizeof(buffer) : rq->size);
-   		if(s <= 0) {
-   			rp->status = HTTP_STATUS_SERVER_ERROR;
-   			strcpy(rp->statusmsg, strerror(errno));
-   			close(rp->fd);
-   			close(rp->ofd);
-   			break;
-   		}
-   		rq->size -= s;
-   		s2 = write(rp->ofd, buffer, s);
-   		if(s2 != s) break;
-   	}
-   }
-
-   if(rp->status != HTTP_STATUS_OK && rp->status != HTTP_STATUS_CREATED &&
-      rp->status != HTTP_STATUS_NOT_MODIFIED)
-	rp->keepopen = 0;
-
-   if(rp->status == HTTP_STATUS_NOT_MODIFIED) {
-	sprintf(buffer, "<h2>Error %03d %s</h2>",
-		rp->status, rp->statusmsg);
-	rp->size = strlen(buffer);
-	rp->keepopen = rq->keepopen;
-   }
-
-   if(!rp->headers) {
-
-   if((rq->type == HTTP_REQUEST_TYPE_PROXY && rp->status != HTTP_STATUS_OK) ||
-       rq->type == HTTP_REQUEST_TYPE_FULL) {
-	sprintf(buffer, "HTTP/%d.%d %03d %s",
-		rq->vmajor, rq->vminor, rp->status, rp->statusmsg);
-	sendout(buffer);
-	sendout(SERVER);
-	if(rp->status == HTTP_STATUS_MOVED_PERM ||
-	   rp->status == HTTP_STATUS_MOVED_TEMP) {
-#if 1
-	   	sprintf(buffer, "Location: %s", rq->url);
-#else
-	   	sprintf(buffer, "Location: http://%s%s", myhostname, rq->url);
-#endif
-	   	sendout(buffer);
-	}
-	if(rp->keepopen)
-		sendout("Connection: Keep-Alive");
-	else
-		sendout("Connection: Close");
-	if(rp->status == HTTP_STATUS_UNAUTHORIZED && rp->auth != NULL) {
-		sprintf(buffer, "WWW-Authenticate: Basic realm=\"%s\"", rp->auth->desc);
-		sendout(buffer);
-	}
-	if(rp->status == HTTP_STATUS_PROXY_AUTH_REQRD && proxyauth != NULL) {
-		sprintf(buffer, "Proxy-Authenticate: Basic realm=\"%s\"", proxyauth->desc);
-		sendout(buffer);
-	}
-	if(rp->modtime != (time_t) -1) {
-		sprintf(buffer, "Last-Modified: %s", httpdate(&rp->modtime));
-		sendout(buffer);
-	}
-	if(rp->size != 0) {
-		sprintf(buffer, "Content-Length: %lu", rp->size);
-		sendout(buffer);
-	}
-	if(rp->status == HTTP_STATUS_OK) {
-		sprintf(buffer, "Content-Type: %s", rp->mtype);
-		sendout(buffer);
-	} else
-		sendout("Content-Type: text/html");
-	if(!rp->headers)
-		sendout("");
-   } else
-	if(rp->status != HTTP_STATUS_OK)
-		return(0);
-   }
-
-   if(rp->status != HTTP_STATUS_OK && rp->status != HTTP_STATUS_CREATED) {
-	sprintf(buffer, "<h2>Error %03d %s</h2>",
-		rp->status, rp->statusmsg);
-	sendout(buffer);
-	return(0);
-   }
-
-   if(rq->type == HTTP_REQUEST_TYPE_PROXY) {
-   	proxy(rq, rp);
-   	return(0);
-   }
-
-   /* send out entity body */
-   if(rq->method == HTTP_METHOD_GET || rq->method == HTTP_METHOD_POST) {
-   	errno = 0;
-   	while(1) {
-   		alarm(0);
-   		signal(SIGALRM, GotAlarm);
-   		alarm(10);
-   		s = read(rp->fd, buffer, sizeof(buffer));
-   		e = errno;
-   		alarm(0);
-   		if(s > 0) {
-			s2 = write(1, buffer, s);
-			e = errno;
-			if(s2 != s) break;
-			continue;
-		}
-		if(s == 0) break;
-		if(s < 0 && e != EINTR) break;
-   		signal(SIGALRM, GotAlarm);
-   		alarm(2);
-   		s = read(0, buffer, 1);
-   		e = errno;
-   		alarm(0);
-   		if(s < 0 && e != EINTR) break;
-	}
-   }
-
-   close(rp->fd);
-   rp->fd = -1;
-   if(rp->ofd != -1)
-	close(rp->ofd);
-   if(rp->pid != 0 && e != 0) {
-   	kill(-rp->pid, SIGHUP);
-   	rp->pid = 0;
-   }
-
-   return(0);
-}
Index: trunk/minix/commands/httpd/request.c
===================================================================
--- trunk/minix/commands/httpd/request.c	(revision 9)
+++ 	(revision )
@@ -1,369 +1,0 @@
-/* request.c
- *
- * This file is part of httpd.
- *
- * 02/17/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002			Michael Temari <Michael@TemWare.Com>
- *
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <pwd.h>
-#ifdef _MINIX
-#include <minix/minlib.h>
-#endif
-#include <errno.h>
-
-#include "http.h"
-#include "utility.h"
-#include "config.h"
-
-_PROTOTYPE(static void Timeout, (int sig));
-_PROTOTYPE(static int getline, (char *buffer, int size));
-_PROTOTYPE(static void authorize, (char *p, struct http_request *rq));
-_PROTOTYPE(static void decurl, (char *u));
-
-static int TimeOut;
-
-static void Timeout(sig)
-int sig;
-{
-   TimeOut = 1;
-}
-
-static int getline(buffer, size)
-char *buffer;
-int size;
-{
-char *p;
-int s;
-
-   p = buffer;
-
-   while(p < (buffer + size - 1)) {
-   	TimeOut = 0;
-   	signal(SIGALRM, Timeout);
-   	alarm(5*60);
-	s = read(0, p, 1);
-	alarm(0);
-	if(TimeOut)
-		return(-1);
-	if(s != 1)
-		return(-1);
-	if(*p == '\n') break;
-	p++;
-   }
-   *++p = '\0';
-
-   p = &buffer[strlen(buffer) - 1];
-   if(p >= buffer && (*p == '\r' || *p == '\n')) *p-- ='\0';
-   if(p >= buffer && (*p == '\r' || *p == '\n')) *p-- ='\0';
-
-   return(strlen(buffer));
-}
-
-static void authorize(p, rq)
-char *p;
-struct http_request *rq;
-{
-char *s;
-
-   if(toupper(*p++) == 'B' &&
-      toupper(*p++) == 'A' &&
-      toupper(*p++) == 'S' &&
-      toupper(*p++) == 'I' &&
-      toupper(*p++) == 'C' &&
-      toupper(*p++) == ' ') ;
-   else
-   	return;
-
-   s = decode64(p);
-
-   if((p = strchr(s, ':')) == (char *)NULL)
-   	p = "";
-   else
-   	*p++ = '\0';
-
-   strncpy(rq->authuser, s, sizeof(rq->authuser));
-   strncpy(rq->authpass, p, sizeof(rq->authpass));
-
-   return;
-}
-
-int getrequest(rq)
-struct http_request *rq;
-{
-static char line[4096];
-char *p, *p2, *ps;
-int s, len;
-struct vhost *ph;
-
-   /* get request, it may be simple */
-
-   s = getline(line, sizeof(line));
-   if(s < 0)
-	return(-1);
-
-   if(dbglog != (FILE *)NULL) {
-	fprintf(dbglog, "REQUEST: %s\n", line);
-	fflush(dbglog);
-   }
-
-   /* clear http_request */
-   memset(rq, 0, sizeof(*rq));
-   rq->ifmodsince = (time_t) -1;
-
-   /* assume simple request */
-   rq->type = HTTP_REQUEST_TYPE_SIMPLE;
-
-   /* parse the method */
-   p = line;
-   while(*p && !LWS(*p)) {
-   	*p = toupper(*p);
-   	p++;
-   }
-   if(*p) *p++ = '\0';
-
-   if(!strcmp(line, "GET"))
-	rq->method = HTTP_METHOD_GET; else
-   if(!strcmp(line, "HEAD"))
-	rq->method = HTTP_METHOD_HEAD; else
-   if(!strcmp(line, "POST"))
-	rq->method = HTTP_METHOD_POST; else
-   if(!strcmp(line, "PUT"))
-	rq->method = HTTP_METHOD_PUT; else
-#if 0
-   if(!strcmp(line, "OPTIONS"))
-	rq->method = HTTP_METHOD_OPTIONS; else
-   if(!strcmp(line, "PATCH"))
-	rq->method = HTTP_METHOD_PATCH; else
-   if(!strcmp(line, "COPY"))
-	rq->method = HTTP_METHOD_COPY; else
-   if(!strcmp(line, "MOVE"))
-	rq->method = HTTP_METHOD_MOVE; else
-   if(!strcmp(line, "DELETE"))
-	rq->method = HTTP_METHOD_DELETE; else
-   if(!strcmp(line, "LINK"))
-	rq->method = HTTP_METHOD_LINK; else
-   if(!strcmp(line, "UNLINK"))
-	rq->method = HTTP_METHOD_UNLINK; else
-   if(!strcmp(line, "TRACE"))
-	rq->method = HTTP_METHOD_TRACE; else
-   if(!strcmp(line, "WRAPPED"))
-	rq->method = HTTP_METHOD_WRAPPED; else
-#endif
-	rq->method = HTTP_METHOD_UNKNOWN;
-
-   /* parse the requested URI */
-   p2 = rq->uri;
-   len = sizeof(rq->uri) - 1;
-   while(*p && !LWS(*p) && len > 0) {
-	*p2++ = *p++;
-	len--;
-   }
-   *p2 = '\0';
-
-   /* eat up any leftovers if uri was too big */
-   while(*p && !LWS(*p))
-	p++;
-
-   /* save for continued processing later */
-   ps = p;
-
-   /* parse the requested URL */
-   p = rq->uri;
-   p2 = rq->url;
-   len = sizeof(rq->url) - 1;
-   while(*p && !LWS(*p) && *p != '?' && len > 0) {
-	*p2++ = *p++;
-	len--;
-   }
-   *p2 = '\0';
-
-   /* See if there is a query string */
-   if(*p == '?') {
-   	p++;
-   	p2 = rq->query;
-   	len = sizeof(rq->query) - 1;
-   	while(*p && !LWS(*p) && len > 0) {
-   		*p2++ = *p++;
-		len--;
-	}
-   }
-
-   /* eat up any leftovers */
-   while(*p && !LWS(*p)) p++;
-
-   if(rq->url[0] == '\0') {
-   	rq->url[0] = '/';
-   	rq->url[1] = '\0';
-   }
-
-   /* url is a decoded copy of the uri */
-   decurl(rq->url);
-
-   /* restore and continue processing */
-   p = ps;
-
-   /* if this is true it is a simple request */
-   if(*p == '\0')
-	return(0);
-
-   /* parse HTTP version */
-   while(*p && LWS(*p)) p++;
-   if(toupper(*p++) != 'H') return(0);
-   if(toupper(*p++) != 'T') return(0);
-   if(toupper(*p++) != 'T') return(0);
-   if(toupper(*p++) != 'P') return(0);
-   if(        *p++  != '/') return(0);
-
-   /* version major */
-   rq->vmajor = 0;
-   while((*p >= '0') && (*p <= '9'))
-	rq->vmajor = rq->vmajor * 10 + (*p++ - '0');
-   if(*p != '.')
-	return(0);
-   p++;
-
-   /* version minor */
-   rq->vminor = 0;
-   while((*p >= '0') && (*p <= '9'))
-	rq->vminor = rq->vminor * 10 + (*p++ - '0');
-   if(*p)
-	return(0);
-
-   rq->type = HTTP_REQUEST_TYPE_FULL;
-
-   p = rq->uri;
-
-   /* check if it is a proxy request */
-   if(toupper(*p++) == 'H' &&
-      toupper(*p++) == 'T' &&
-      toupper(*p++) == 'T' &&
-      toupper(*p++) == 'P' &&
-      toupper(*p++) == ':')
-      	rq->type = HTTP_REQUEST_TYPE_PROXY;
-
-   /* parse any header fields */
-   while((s = getline(line, sizeof(line))) > 0) {
-   	if(toupper(line[0]) == 'A' &&
-   	   toupper(line[1]) == 'U')
-		if(dbglog != (FILE *)NULL) {
-			fprintf(dbglog, "REQUEST: Authorization:\n");
-			fflush(dbglog);
-		} else ;
-	else
-		if(dbglog != (FILE *)NULL) {
-			fprintf(dbglog, "REQUEST: %s\n", line);
-			fflush(dbglog);
-		}
-	p = line;
-	while(*p && *p != ':') {
-		*p = toupper(*p);
-		p++;
-	}
-	if(*p != ':') continue;		/* bad header field, skip it */
-	*p++ = '\0';
-	while(*p && LWS(*p)) p++;
-
-	/* header field value parsing here */
-	if(!strcmp(line, "HOST")) {
-		strncpy(rq->host, p, sizeof(rq->host));
-		p2 = strrchr(rq->host, ':');
-		if(p2 != (char *)NULL) {
-			*p2++ = '\0';
-			rq->port = atoi(p2);
-		}
-		/* if unknown virtual host then exit quietly */
-		for(ph = vhost; ph != NULL; ph = ph->next) {
-			if(!strcasecmp(ph->hname, "*")) break;
-			if(!strcasecmp(ph->hname, rq->host)) break;
-		}
-		if(rq->type != HTTP_REQUEST_TYPE_PROXY)
-			if(ph == NULL && vhost != NULL) return(1);
-	} else
-	if(!strcmp(line, "USER-AGENT"))
-		strncpy(rq->useragent, p, sizeof(rq->useragent)); else
-	if(!strcmp(line, "CONNECTION"))
-		rq->keepopen = strcasecmp(p, "Keep-Alive") ? 0 : 1; else
-	if(!strcmp(line, "IF-MODIFIED-SINCE"))
-		rq->ifmodsince = httptime(p); else
-	if(!strcmp(line, "CONTENT-LENGTH"))
-		rq->size = atol(p); else
-	if(!strcmp(line, "AUTHORIZATION")) {
-		strncpy(rq->wwwauth, p, sizeof(rq->wwwauth));
-		if(rq->type != HTTP_REQUEST_TYPE_PROXY)
-			authorize(p, rq);
-	} else
-	if(!strcmp(line, "PROXY-AUTHORIZATION")) {
-		if(rq->type == HTTP_REQUEST_TYPE_PROXY)
-			authorize(p, rq);
-	} else
-	if(!strcmp(line, "DATE"))
-		rq->msgdate = httptime(p); else
-	if(!strcmp(line, "COOKIE")) {
-		strncpy(rq->cookie, p, sizeof(rq->cookie)-1);
-		rq->cookie[sizeof(rq->cookie)-1] = '\0';
-	}
-   }
-
-   if(rq->type != HTTP_REQUEST_TYPE_PROXY)
-	if(*rq->host == '\0' && vhost != NULL) return(1);
-
-   if(dbglog != (FILE *)NULL && rq->authuser[0] != '\0') {
-	fprintf(dbglog, "REQUEST: AuthUser=%s\n", rq->authuser);
-	fflush(dbglog);
-   }
-
-   if(s < 0) {
-	fprintf(stderr, "httpd: getrequest: Error getline (header fields)\n");
-	return(-1);
-   }
-
-   return(0);
-}
-
-static void decurl(u)
-char *u;
-{
-char *p;
-char h1, h2;
-char c;
-
-   p = u;
-   while(*p) {
-	switch(*p) {
-   		case '\0':
-   			c = '\0';
-   			break;
-   		case '+':
-   			c = ' ';
-   			p++;
-   			break;
-   		case '%':
-			h1 = '0';
-			h2 = '0';
-			p++;
-			h1 = tolower(*p);
-			if(*p) p++;
-			h2 = tolower(*p);
-			if(*p) p++;
-			c = (h1 > '9') ? (10 + h1 - 'a') : (h1 - '0');
-			c = 16 * c + ((h2 > '9') ? (10 + h2 - 'a') : (h2 - '0'));
-			break;
-		default:
-			c = *p++;
-	}
-	*u++ = c;
-   }
-   *u = '\0';
-}
Index: trunk/minix/commands/httpd/utility.c
===================================================================
--- trunk/minix/commands/httpd/utility.c	(revision 9)
+++ 	(revision )
@@ -1,265 +1,0 @@
-/* utility.c
- *
- * This file is part of httpd
- *
- * 02/17/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002 Initial Release	Michael Temari <Michael@TemWare.Com>
- *
- */
-#include <sys/types.h>
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "utility.h"
-#include "config.h"
-
-const char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
-const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-			 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
-
-char *logdate(t)
-time_t *t;
-{
-time_t worktime;
-struct tm *tm;
-static char datebuffer[80];
-
-  if(t == (time_t *)NULL)
-	(void) time(&worktime);
-  else
-  	worktime = *t;
-
-   tm = localtime(&worktime);
-
-   sprintf(datebuffer, "%4d%02d%02d%02d%02d%02d",
-		1900+tm->tm_year,
-		tm->tm_mon + 1,
-		tm->tm_mday,
-		tm->tm_hour, tm->tm_min, tm->tm_sec);
-
-   return(datebuffer);
-}
-
-char *httpdate(t)
-time_t *t;
-{
-time_t worktime;
-struct tm *tm;
-static char datebuffer[80];
-
-  if(t == (time_t *)NULL)
-	(void) time(&worktime);
-  else
-  	worktime = *t;
-
-   tm = gmtime(&worktime);
-
-   sprintf(datebuffer, "%s, %02d %s %4d %02d:%02d:%02d GMT",
-   		days[tm->tm_wday],
-		tm->tm_mday, months[tm->tm_mon], 1900+tm->tm_year,
-		tm->tm_hour, tm->tm_min, tm->tm_sec);
-
-   return(datebuffer);
-}
-
-time_t httptime(p)
-char *p;
-{
-time_t worktime, gtime, ltime;
-struct tm tm;
-struct tm *tm2;
-int i;
-
-   worktime = (time_t) -1;
-
-   tm.tm_yday = 0;
-   tm.tm_isdst = -1;
-
-   /* day of week */
-   for(i = 0; i < 7; i++)
-	if(!strncmp(p, days[i], 3)) break;
-   if(i < 7)
-	tm.tm_wday = i;
-   else
-	return(worktime);
-   while(*p && *p != ' ') p++;
-   if(!*p) return(worktime);
-   while(*p && *p == ' ') p++;
-   if(!*p) return(worktime);
-
-   if(*p >= '0' && *p <= '9') {
-   	/* day */
-   	if(*(p+1) >= '0' && *(p+1) <= '9')
-		tm.tm_mday = 10 * (*p - '0') + (*(p+1) - '0');
-	else
-		return(worktime);
-	p += 3;
-	/* month */
-	for(i = 0; i < 12; i++)
-		if(!strncmp(p, months[i], 3)) break;
-	if(i < 12)
-		tm.tm_mon = i;
-	else
-		return(worktime);
-	p += 3;
-	if(!*p++) return(worktime);
-	/* year */
-	tm.tm_year = atoi(p);
-	while(*p && *p != ' ') p++;
-	if(*p) p++;
-   } else {
-	/* day */
-	tm.tm_mday = atoi(p);
-	while(*p && *p != ' ') p++;
-	while(*p && *p == ' ') p++;
-	if(!*p) return(worktime);
-   }
-
-   /* hour */
-   if(*p < '0' || *p > '9' || *(p+1) < '0' || *(p+1) > '9' || *(p+2) != ':') return(worktime);
-   tm.tm_hour = 10 * (*p - '0') + (*(p+1) - '0');
-   p += 3;
-
-   /* minute */
-   if(*p < '0' || *p > '9' || *(p+1) < '0' || *(p+1) > '9' || *(p+2) != ':') return(worktime);
-   tm.tm_min  = 10 * (*p - '0') + (*(p+1) - '0');
-   p += 3;
-
-   /* second */
-   if(*p < '0' || *p > '9' || *(p+1) < '0' || *(p+1) > '9' || *(p+2) != ' ') return(worktime);
-   tm.tm_sec  = 10 * (*p - '0') + (*(p+1) - '0');
-   p += 3;
-   while(*p && *p == ' ') p++;
-   if(!*p) return(worktime);
-
-   if(*p >= '0' && *p <= '9')
-   	tm.tm_year = atoi(p);
-   else
-   	if(*p++ != 'G' || *p++ != 'M' || *p++ != 'T')
-   		return(worktime);
-
-   if(tm.tm_year == 0)
-   	return(worktime);
-
-   if(tm.tm_year > 1900)
-	tm.tm_year -= 1900;
-
-   worktime = mktime(&tm);
-
-   gtime = mktime(gmtime(&worktime));
-   tm2 = localtime(&worktime);
-   tm2->tm_isdst = 0;
-   ltime = mktime(tm2);
-
-   worktime = worktime - (gtime - ltime);
-
-   return(worktime);
-}
-
-char *mimetype(url)
-char *url;
-{
-char *p;
-struct msufx *ps;
-char *dmt;
-
-   dmt = (char *) NULL;
-   p = url;
-   while(*p) {
-   	if(*p != '.') {
-   		p++;
-   		continue;
-   	}
-   	for(ps = msufx; ps != NULL; ps = ps->snext)
-   		if(!strcmp(ps->suffix, "") && dmt == (char *) NULL)
-   			dmt = ps->mtype->mimetype;
-   		else
-   			if(!strcmp(p, ps->suffix))
-   				return(ps->mtype->mimetype);
-   	p++;
-   }
-
-   if(dmt == (char *) NULL)
-   	dmt = "application/octet-stream";
-
-   return(dmt);
-}
-
-char *decode64(p)
-char *p;
-{
-static char decode[80];
-char c[4];
-int i;
-int d;
-
-   i = 0;
-   d = 0;
-
-   while(*p) {
-   	if(*p >= 'A' && *p <= 'Z') c[i++] = *p++ - 'A'; else
-   	if(*p >= 'a' && *p <= 'z') c[i++] = *p++ - 'a' + 26; else
-   	if(*p >= '0' && *p <= '9') c[i++] = *p++ - '0' + 52; else
-   	if(*p == '+') c[i++] = *p++ - '+' + 62; else
-   	if(*p == '/') c[i++] = *p++ - '/' + 63; else
-   	if(*p == '=') c[i++] = *p++ - '='; else
-   		return("");
-   	if(i < 4) continue;
-   	decode[d++] = ((c[0] << 2) | (c[1] >> 4));
-   	decode[d++] = ((c[1] << 4) | (c[2] >> 2));
-   	decode[d++] = ((c[2] << 6) |  c[3]);
-   	decode[d] = '\0';
-   	i = 0;
-   }
-
-   return(decode);
-}
-
-int getparms(p, parms, maxparms)
-char *p;
-char *parms[];
-int maxparms;
-{
-int np;
-
-   np = 0;
-
-   if(LWS(*p)) {
-   	while(*p && LWS(*p)) p++;
-   	if(!*p) return(0);
-   	parms[np++] = (char *)NULL;
-   } else
-   	np = 0;
-
-   while(np < maxparms && *p) {
-   	parms[np++] = p;
-   	while(*p && !LWS(*p)) p++;
-   	if(*p) *p++ = '\0';
-   	while(*p && LWS(*p)) p++;
-   }
-
-   return(np);
-}
-
-int mkurlaccess(p)
-char *p;
-{
-int ua;
-
-   ua = 0;
-
-   while(*p) {
-	if(toupper(*p) == 'R') ua |= URLA_READ; else
-	if(toupper(*p) == 'W') ua |= URLA_WRITE; else
-	if(toupper(*p) == 'X') ua |= URLA_EXEC; else
-	if(toupper(*p) == 'H') ua |= URLA_HEADERS; else
-		return(0);
-	p++;
-   }
-
-   return(ua);
-}
Index: trunk/minix/commands/httpd/utility.h
===================================================================
--- trunk/minix/commands/httpd/utility.h	(revision 9)
+++ 	(revision )
@@ -1,19 +1,0 @@
-/* utility.h
- *
- * This file is part of httpd.
- *
- * 02/17/1996 			Michael Temari <Michael@TemWare.Com>
- * 07/07/1996 Initial Release	Michael Temari <Michael@TemWare.Com>
- * 12/29/2002			Michael Temari <Michael@TemWare.Com>
- *
- */
-
-#define	LWS(c)	((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n'))
-
-_PROTOTYPE(char *logdate, (time_t *t));
-_PROTOTYPE(char *httpdate, (time_t *t));
-_PROTOTYPE(time_t httptime, (char *p));
-_PROTOTYPE(char *mimetype, (char *url));
-_PROTOTYPE(char *decode64, (char *p));
-_PROTOTYPE(int getparms, (char *p, char *parms[], int maxparms));
-_PROTOTYPE(int mkurlaccess, (char *p));
Index: trunk/minix/commands/i386/Makefile
===================================================================
--- trunk/minix/commands/i386/Makefile	(revision 9)
+++ 	(revision )
@@ -1,27 +1,0 @@
-# Makefile for commands/i386.
-
-CFLAGS	= -D_MINIX -D_POSIX_SOURCE
-CCLD	= $(CC) -i $(CFLAGS)
-MAKE	= exec make -$(MAKEFLAGS)
-CC = exec cc
-
-all::	acd
-
-acd:	acd.c
-	$(CCLD) -o $@ -DARCH=\"`arch`\" -DDESCR=\"/usr/lib/descr\" $?
-	install -S 50kw $@
-
-install::	/usr/bin/acd /usr/bin/cc /usr/bin/m2 /usr/bin/pc
-
-/usr/bin/acd:	acd
-	install -cs -o bin $? $@
-
-/usr/bin/cc /usr/bin/m2 /usr/bin/pc:	/usr/bin/acd
-	install -l $? $@
-
-clean::
-	rm -rf a.out core acd
-
-all install clean::
-	cd asmconv && $(MAKE) $@
-	cd mtools-3.9.7 && $(MAKE) $@
Index: trunk/minix/commands/i386/acd.c
===================================================================
--- trunk/minix/commands/i386/acd.c	(revision 9)
+++ 	(revision )
@@ -1,2701 +1,0 @@
-/*	acd 1.10 - A compiler driver			Author: Kees J. Bot
- *								7 Jan 1993
- * Needs about 25kw heap + stack.
- */
-char version[] = "1.9";
-
-#define nil 0
-#define _POSIX_SOURCE	1
-#include <sys/types.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <signal.h>
-#include <errno.h>
-#include <ctype.h>
-#include <assert.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-
-#ifndef LIB
-#define LIB	"/usr/lib"	/* Default library directory. */
-#endif
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-char *program;		/* Call name. */
-
-int verbose= 0;		/* -v0: Silent.
-			 * -v1: Show abbreviated pass names.
-			 * -v2: Show executed UNIX commands.
-			 * -v3: Show executed ACD commands.
-			 * -v4: Show descr file as it is read.
-			 */
-
-int action= 2;		/*   0: An error occured, don't do anything anymore.
-			 *   1: (-vn) Do not execute, play-act.
-			 *   2: Execute UNIX commands.
-			 */
-
-void report(char *label)
-{
-	if (label == nil || label[0] == 0) {
-		fprintf(stderr, "%s: %s\n", program, strerror(errno));
-	} else {
-		fprintf(stderr, "%s: %s: %s\n",
-					program, label, strerror(errno));
-	}
-	action= 0;
-}
-
-void quit(int exit_code);
-
-void fatal(char *label)
-{
-	report(label);
-	quit(-1);
-}
-
-size_t heap_chunks= 0;
-
-void *allocate(void *mem, size_t size)
-/* Safe malloc/realloc.  (I have heard that one can call realloc with a
- * null first argument with the effect below, but that is of course to
- * ridiculous to believe.)
- */
-{
-	assert(size > 0);
-
-	if (mem != nil) {
-		mem= realloc(mem, size);
-	} else {
-		mem= malloc(size);
-		heap_chunks++;
-	}
-	if (mem == nil) fatal(nil);
-	return mem;
-}
-
-void deallocate(void *mem)
-{
-	if (mem != nil) {
-		free(mem);
-		heap_chunks--;
-	}
-}
-
-char *copystr(const char *s)
-{
-	char *c;
-	c= allocate(nil, (strlen(s)+1) * sizeof(*c));
-	strcpy(c, s);
-	return c;
-}
-
-/* Every object, list, letter, or variable, is made with cells. */
-typedef struct cell {
-	unsigned short	refc;		/* Reference count. */
-	char		type;		/* Type of object. */
-	unsigned char	letter;		/* Simply a letter. */
-	char		*name;		/* Name of a word. */
-	struct cell	*hash;		/* Hash chain. */
-	struct cell	*car, *cdr;	/* To form lists. */
-
-/* For a word: */
-#	define	value	car		/* Value of a variable. */
-#	define	base	cdr		/* Base-name in transformations. */
-#	define	suffix	cdr		/* Suffix in a treat-as. */
-#	define	flags	letter		/* Special flags. */
-
-/* A substitution: */
-#	define	subst	car
-
-} cell_t;
-
-typedef enum type {
-	CELL,		/* A list cell. */
-	STRING,		/* To make a list of characters and substs. */
-	SUBST,		/* Variable to substitute. */
-	/* Unique objects. */
-	LETTER,		/* A letter. */
-	WORD,		/* A string collapses to a word. */
-	EQUALS,		/* = operator, etc. */
-	OPEN,
-	CLOSE,
-	PLUS,
-	MINUS,
-	STAR,
-	INPUT,
-	OUTPUT,
-	WHITE,
-	COMMENT,
-	SEMI,
-	EOLN,
-	N_TYPES		/* number of different types */
-} type_t;
-
-#define is_unique(type) ((type) >= LETTER)
-
-/* Flags on a word. */
-#define W_SET		0x01	/* Not undefined, e.g. assigned to. */
-#define W_RDONLY	0x02	/* Read only. */
-#define W_LOCAL		0x04	/* Local variable, immediate substitution. */
-#define W_TEMP		0x08	/* Name of a temporary file, delete on quit. */
-#define W_SUFF		0x10	/* Has a suffix set on it. */
-
-void princhar(int c)
-/* Print a character, escaped if important to the shell *within* quotes. */
-{
-	if (strchr("\\'\"<>();~$^&*|{}[]?", c) != nil) fputc('\\', stdout);
-	putchar(c);
-}
-
-void prinstr(char *s)
-/* Print a string, in quotes if the shell might not like it. */
-{
-	int q= 0;
-	char *s2= s;
-
-	while (*s2 != 0)
-		if (strchr("~`$^&*()=\\|[]{};'\"<>?", *s2++) != nil) q= 1;
-
-	if (q) fputc('"', stdout);
-	while (*s != 0) princhar(*s++);
-	if (q) fputc('"', stdout);
-}
-
-void prin2(cell_t *p);
-
-void prin1(cell_t *p)
-/* Print a cell structure for debugging purposes. */
-{
-	if (p == nil) {
-		printf("(\b(\b()\b)\b)");
-		return;
-	}
-
-	switch (p->type) {
-	case CELL:
-		printf("(\b(\b(");
-		prin2(p);
-		printf(")\b)\b)");
-		break;
-	case STRING:
-		printf("\"\b\"\b\"");
-		prin2(p);
-		printf("\"\b\"\b\"");
-		break;
-	case SUBST:
-		printf("$\b$\b${%s}", p->subst->name);
-		break;
-	case LETTER:
-		princhar(p->letter);
-		break;
-	case WORD:
-		prinstr(p->name);
-		break;
-	case EQUALS:
-		printf("=\b=\b=");
-		break;
-	case PLUS:
-		printf("+\b+\b+");
-		break;
-	case MINUS:
-		printf("-\b-\b-");
-		break;
-	case STAR:
-		printf("*\b*\b*");
-		break;
-	case INPUT:
-		printf(verbose >= 3 ? "<\b<\b<" : "<");
-		break;
-	case OUTPUT:
-		printf(verbose >= 3 ? ">\b>\b>" : ">");
-		break;
-	default:
-		assert(0);
-	}
-}
-
-void prin2(cell_t *p)
-/* Print a list for debugging purposes. */
-{
-	while (p != nil && p->type <= STRING) {
-		prin1(p->car);
-
-		if (p->type == CELL && p->cdr != nil) fputc(' ', stdout);
-
-		p= p->cdr;
-	}
-	if (p != nil) prin1(p);		/* Dotted pair? */
-}
-
-void prin1n(cell_t *p) { prin1(p); fputc('\n', stdout); }
-
-void prin2n(cell_t *p) { prin2(p); fputc('\n', stdout); }
-
-/* A program is consists of a series of lists at a certain indentation level. */
-typedef struct program {
-	struct program	*next;
-	cell_t		*file;		/* Associated description file. */
-	unsigned	indent;		/* Line indentation level. */
-	unsigned	lineno;		/* Line number where this is found. */
-	cell_t		*line;		/* One line of tokens. */
-} program_t;
-
-program_t *pc;		/* Program Counter (what else?) */
-program_t *nextpc;	/* Next line to execute. */
-
-cell_t *oldcells;	/* Keep a list of old cells, don't deallocate. */
-
-cell_t *newcell(void)
-/* Make a new empty cell. */
-{
-	cell_t *p;
-
-	if (oldcells != nil) {
-		p= oldcells;
-		oldcells= p->cdr;
-		heap_chunks++;
-	} else {
-		p= allocate(nil, sizeof(*p));
-	}
-
-	p->refc= 0;
-	p->type= CELL;
-	p->letter= 0;
-	p->name= nil;
-	p->car= nil;
-	p->cdr= nil;
-	return p;
-}
-
-#define N_CHARS		(1 + (unsigned char) -1)
-#define HASHDENSE	0x400
-
-cell_t *oblist[HASHDENSE + N_CHARS + N_TYPES];
-
-unsigned hashfun(cell_t *p)
-/* Use a blender on a cell. */
-{
-	unsigned h;
-	char *name;
-
-	switch (p->type) {
-	case WORD:
-		h= 0;
-		name= p->name;
-		while (*name != 0) h= (h * 0x1111) + *name++;
-		return h % HASHDENSE;
-	case LETTER:
-		return HASHDENSE + p->letter;
-	default:
-		return HASHDENSE + N_CHARS + p->type;
-	}
-}
-
-cell_t *search(cell_t *p, cell_t ***hook)
-/* Search for *p, return the one found.  *hook may be used to insert or
- * delete.
- */
-{
-	cell_t *sp;
-
-	sp= *(*hook= &oblist[hashfun(p)]);
-
-	if (p->type == WORD) {
-		/* More than one name per hash slot. */
-		int cmp= 0;
-
-		while (sp != nil && (cmp= strcmp(p->name, sp->name)) > 0)
-			sp= *(*hook= &sp->hash);
-
-		if (cmp != 0) sp= nil;
-	}
-	return sp;
-}
-
-void dec(cell_t *p)
-/* Decrease the number of references to p, if zero delete and recurse. */
-{
-	if (p == nil || --p->refc > 0) return;
-
-	if (is_unique(p->type)) {
-		/* Remove p from the oblist. */
-		cell_t *o, **hook;
-
-		o= search(p, &hook);
-
-		if (o == p) {
-			/* It's there, remove it. */
-			*hook= p->hash;
-			p->hash= nil;
-		}
-
-		if (p->type == WORD && (p->flags & W_TEMP)) {
-			/* A filename to remove. */
-			if (verbose >= 2) {
-				printf("rm -f ");
-				prinstr(p->name);
-				fputc('\n', stdout);
-			}
-			if (unlink(p->name) < 0 && errno != ENOENT)
-				report(p->name);
-		}
-	}
-	deallocate(p->name);
-	dec(p->car);
-	dec(p->cdr);
-	p->cdr= oldcells;
-	oldcells= p;
-	heap_chunks--;
-}
-
-cell_t *inc(cell_t *p)
-/* Increase the number of references to p. */
-{
-	cell_t *o, **hook;
-
-	if (p == nil) return nil;
-
-	if (++p->refc > 1 || !is_unique(p->type)) return p;
-
-	/* First appearance, put p on the oblist. */
-	o= search(p, &hook);
-
-	if (o == nil) {
-		/* Not there yet, add it. */
-		p->hash= *hook;
-		*hook= p;
-	} else {
-		/* There is another object already there with the same info. */
-		o->refc++;
-		dec(p);
-		p= o;
-	}
-	return p;
-}
-
-cell_t *go(cell_t *p, cell_t *field)
-/* Often happening: You've got p, you want p->field. */
-{
-	field= inc(field);
-	dec(p);
-	return field;
-}
-
-cell_t *cons(type_t type, cell_t *p)
-/* P is to be added to a list (or a string). */
-{
-	cell_t *l= newcell();
-	l->type= type;
-	l->refc++;
-	l->car= p;
-	return l;
-}
-
-cell_t *append(type_t type, cell_t *p)
-/* P is to be appended to a list (or a string). */
-{
-	return p == nil || p->type == type ? p : cons(type, p);
-}
-
-cell_t *findnword(char *name, size_t n)
-/* Find the word with the given name of length n. */
-{
-	cell_t *w= newcell();
-	w->type= WORD;
-	w->name= allocate(nil, (n+1) * sizeof(*w->name));
-	memcpy(w->name, name, n);
-	w->name[n]= 0;
-	return inc(w);
-}
-
-cell_t *findword(char *name)
-/* Find the word with the given null-terminated name. */
-{
-	return findnword(name, strlen(name));
-}
-
-void quit(int exstat)
-/* Remove all temporary names, then exit. */
-{
-	cell_t **op, *p, *v, *b;
-	size_t chunks;
-
-	/* Remove cycles, like X = X. */
-	for (op= oblist; op < oblist + HASHDENSE; op++) {
-		p= *op;
-		while (p != nil) {
-			if (p->value != nil || p->base != nil) {
-				v= p->value;
-				b= p->base;
-				p->value= nil;
-				p->base= nil;
-				p= *op;
-				dec(v);
-				dec(b);
-			} else {
-				p= p->hash;
-			}
-		}
-	}
-	chunks= heap_chunks;
-
-	/* Something may remain on an early quit: tempfiles. */
-	for (op= oblist; op < oblist + HASHDENSE; op++) {
-
-		while (*op != nil) { (*op)->refc= 1; dec(*op); }
-	}
-
-	if (exstat != -1 && chunks > 0) {
-		fprintf(stderr,
-			"%s: internal fault: %d chunks still on the heap\n",
-						program, chunks);
-	}
-	exit(exstat);
-}
-
-void interrupt(int sig)
-{
-	signal(sig, interrupt);
-	if (verbose >= 2) write(1, "# interrupt\n", 12);
-	action= 0;
-}
-
-int extalnum(int c)
-/* Uppercase, lowercase, digit, underscore or anything non-American. */
-{
-	return isalnum(c) || c == '_' || c >= 0200;
-}
-
-char *descr;		/* Name of current description file. */
-FILE *dfp;		/* Open description file. */
-int dch;		/* Input character. */
-unsigned lineno;	/* Line number in file. */
-unsigned indent;	/* Indentation level. */
-
-void getdesc(void)
-{
-	if (dch == EOF) return;
-
-	if (dch == '\n') { lineno++; indent= 0; }
-
-	if ((dch = getc(dfp)) == EOF && ferror(dfp)) fatal(descr);
-
-	if (dch == 0) {
-		fprintf(stderr, "%s: %s is a binary file.\n", program, descr);
-		quit(-1);
-	}
-}
-
-#define E_BASH		0x01	/* Escaped by backslash. */
-#define E_QUOTE		0x02	/* Escaped by double quote. */
-#define E_SIMPLE	0x04	/* More simple characters? */
-
-cell_t *get_token(void)
-/* Read one token from the description file. */
-{
-	int whitetype= 0;
-	static int escape= 0;
-	cell_t *tok;
-	char *name;
-	int n, i;
-
-	if (escape & E_SIMPLE) {
-		/* More simple characters?  (Note: performance hack.) */
-		if (isalnum(dch)) {
-			tok= newcell();
-			tok->type= LETTER;
-			tok->letter= dch;
-			getdesc();
-			return inc(tok);
-		}
-		escape&= ~E_SIMPLE;
-	}
-
-	/* Gather whitespace. */
-	for (;;) {
-		if (dch == '\\' && whitetype == 0) {
-			getdesc();
-			if (isspace(dch)) {
-				/* \ whitespace: remove. */
-				do {
-					getdesc();
-					if (dch == '#' && !(escape & E_QUOTE)) {
-						/* \ # comment */
-						do
-							getdesc();
-						while (dch != '\n'
-								&& dch != EOF);
-					}
-				} while (isspace(dch));
-				continue;
-			}
-			escape|= E_BASH;	/* Escaped character. */
-		}
-
-		if (escape != 0) break;
-
-		if (dch == '#' && (indent == 0 || whitetype != 0)) {
-			/* # Comment. */
-			do getdesc(); while (dch != '\n' && dch != EOF);
-			whitetype= COMMENT;
-			break;
-		}
-
-		if (!isspace(dch) || dch == '\n' || dch == EOF) break;
-
-		whitetype= WHITE;
-
-		indent++;
-		if (dch == '\t') indent= (indent + 7) & ~7;
-
-		getdesc();
-	}
-
-	if (dch == EOF) return nil;
-
-	/* Make a token. */
-	tok= newcell();
-
-	if (whitetype != 0) {
-		tok->type= whitetype;
-		return inc(tok);
-	}
-
-	if (!(escape & E_BASH) && dch == '"') {
-		getdesc();
-		if (!(escape & E_QUOTE)) {
-			/* Start of a string, signal this with a string cell. */
-			escape|= E_QUOTE;
-			tok->type= STRING;
-			return inc(tok);
-		} else {
-			/* End of a string, back to normal mode. */
-			escape&= ~E_QUOTE;
-			deallocate(tok);
-			return get_token();
-		}
-	}
-
-	if (escape & E_BASH
-		|| strchr(escape & E_QUOTE ? "$" : "$=()+-*<>;\n", dch) == nil
-	) {
-		if (dch == '\n') {
-			fprintf(stderr,
-				"\"%s\", line %u: missing closing quote\n",
-				descr, lineno);
-			escape&= ~E_QUOTE;
-			action= 0;
-		}
-		if (escape & E_BASH && dch == 'n') dch= '\n';
-		escape&= ~E_BASH;
-
-		/* A simple character. */
-		tok->type= LETTER;
-		tok->letter= dch;
-		getdesc();
-		escape|= E_SIMPLE;
-		return inc(tok);
-	}
-
-	if (dch != '$') {
-		/* Single character token. */
-		switch (dch) {
-		case '=':	tok->type= EQUALS;	break;
-		case '(':	tok->type= OPEN;	break;
-		case ')':	tok->type= CLOSE;	break;
-		case '+':	tok->type= PLUS;	break;
-		case '-':	tok->type= MINUS;	break;
-		case '*':	tok->type= STAR;	break;
-		case '<':	tok->type= INPUT;	break;
-		case '>':	tok->type= OUTPUT;	break;
-		case ';':	tok->type= SEMI;	break;
-		case '\n':	tok->type= EOLN;	break;
-		}
-		getdesc();
-		return inc(tok);
-	}
-
-	/* Substitution. */
-	getdesc();
-	if (dch == EOF || isspace(dch)) {
-		fprintf(stderr, "\"%s\", line %u: Word expected after '$'\n",
-			descr, lineno);
-		action= 0;
-		deallocate(tok);
-		return get_token();
-	}
-
-	name= allocate(nil, (n= 16) * sizeof(*name));
-	i= 0;
-
-	if (dch == '{' || dch == '('  /* )} */ ) {
-		/* $(X), ${X} */
-		int lpar= dch;		/* ( */
-		int rpar= lpar == '{' ? '}' : ')';
-
-		for (;;) {
-			getdesc();
-			if (dch == rpar) { getdesc(); break; }
-			if (isspace(dch) || dch == EOF) {
-				fprintf(stderr,
-				"\"%s\", line %u: $%c unmatched, no '%c'\n",
-					descr, lineno, lpar, rpar);
-				action= 0;
-				break;
-			}
-			name[i++]= dch;
-			if (i == n)
-				name= allocate(name, (n*= 2) * sizeof(char));
-		}
-	} else
-	if (extalnum(dch)) {
-		/* $X */
-		do {
-			name[i++]= dch;
-			if (i == n)
-				name= allocate(name, (n*= 2) * sizeof(char));
-			getdesc();
-		} while (extalnum(dch));
-	} else {
-		/* $* */
-		name[i++]= dch;
-		getdesc();
-	}
-	name[i++]= 0;
-	name= allocate(name, i * sizeof(char));
-	tok->type= SUBST;
-	tok->subst= newcell();
-	tok->subst->type= WORD;
-	tok->subst->name= name;
-	tok->subst= inc(tok->subst);
-	return inc(tok);
-}
-
-typedef enum how { SUPERFICIAL, PARTIAL, FULL, EXPLODE, IMPLODE } how_t;
-
-cell_t *explode(cell_t *p, how_t how);
-
-cell_t *get_string(cell_t **pp)
-/* Get a string: A series of letters and substs.  Special tokens '=', '+', '-'
- * and '*' are also recognized if on their own.  A finished string is "exploded"
- * to a word if it consists of letters only.
- */
-{
-	cell_t *p= *pp, *s= nil, **ps= &s;
-	int quoted= 0;
-
-	while (p != nil) {
-		switch (p->type) {
-		case STRING:
-			quoted= 1;
-			dec(p);
-			break;
-		case EQUALS:
-		case PLUS:
-		case MINUS:
-		case STAR:
-		case SUBST:
-		case LETTER:
-			*ps= cons(STRING, p);
-			ps= &(*ps)->cdr;
-			break;
-		default:
-			goto got_string;
-		}
-		p= get_token();
-	}
-    got_string:
-	*pp= p;
-
-	/* A single special token must be folded up. */
-	if (!quoted && s != nil && s->cdr == nil) {
-		switch (s->car->type) {
-		case EQUALS:
-		case PLUS:
-		case MINUS:
-		case STAR:
-		case SUBST:
-			return go(s, s->car);
-		}
-	}
-
-	/* Go over the string changing '=', '+', '-', '*' to letters. */
-	for (p= s; p != nil; p= p->cdr) {
-		int c= 0;
-
-		switch (p->car->type) {
-		case EQUALS:
-			c= '='; break;
-		case PLUS:
-			c= '+'; break;
-		case MINUS:
-			c= '-'; break;
-		case STAR:
-			c= '*'; break;
-		}
-		if (c != 0) {
-			dec(p->car);
-			p->car= newcell();
-			p->car->type= LETTER;
-			p->car->letter= c;
-			p->car= inc(p->car);
-		}
-	}
-	return explode(s, SUPERFICIAL);
-}
-
-cell_t *get_list(cell_t **pp, type_t stop)
-/* Read a series of tokens upto a token of type "stop". */
-{
-	cell_t *p= *pp, *l= nil, **pl= &l;
-
-	while (p != nil && p->type != stop
-				&& !(stop == EOLN && p->type == SEMI)) {
-		switch (p->type) {
-		case WHITE:
-		case COMMENT:
-		case SEMI:
-		case EOLN:
-			dec(p);
-			p= get_token();
-			break;
-		case OPEN:
-			/* '(' words ')'. */
-			dec(p);
-			p= get_token();
-			*pl= cons(CELL, get_list(&p, CLOSE));
-			pl= &(*pl)->cdr;
-			dec(p);
-			p= get_token();
-			break;
-		case CLOSE:
-			/* Unexpected closing parenthesis. (*/
-			fprintf(stderr, "\"%s\", line %u: unmatched ')'\n",
-				descr, lineno);
-			action= 0;
-			dec(p);
-			p= get_token();
-			break;
-		case INPUT:
-		case OUTPUT:
-			*pl= cons(CELL, p);
-			pl= &(*pl)->cdr;
-			p= get_token();
-			break;
-		case STRING:
-		case EQUALS:
-		case PLUS:
-		case MINUS:
-		case STAR:
-		case LETTER:
-		case SUBST:
-			*pl= cons(CELL, get_string(&p));
-			pl= &(*pl)->cdr;
-			break;
-		default:
-			assert(0);
-		}
-	}
-
-	if (p == nil && stop == CLOSE) {
-		/* Couldn't get the closing parenthesis. */
-		fprintf(stderr, "\"%s\", lines %u-%u: unmatched '('\n",	/*)*/
-			descr, pc->lineno, lineno);
-		action= 0;
-	}
-	*pp= p;
-	return l;
-}
-
-program_t *get_line(cell_t *file)
-{
-	program_t *l;
-	cell_t *p;
-	static keep_indent= 0;
-	static unsigned old_indent= 0;
-
-	/* Skip leading whitespace to determine the indentation level. */
-	indent= 0;
-	while ((p= get_token()) != nil && p->type == WHITE) dec(p);
-
-	if (p == nil) return nil;		/* EOF */
-
-	if (p->type == EOLN) indent= old_indent;	/* Empty line. */
-
-	/* Make a program line. */
-	pc= l= allocate(nil, sizeof(*l));
-
-	l->next= nil;
-	l->file= inc(file);
-	l->indent= keep_indent ? old_indent : indent;
-	l->lineno= lineno;
-
-	l->line= get_list(&p, EOLN);
-
-	/* If the line ended in a semicolon then keep the indentation level. */
-	keep_indent= (p != nil && p->type == SEMI);
-	old_indent= l->indent;
-
-	dec(p);
-
-	if (verbose >= 4) {
-		if (l->line == nil)
-			fputc('\n', stdout);
-		else {
-			printf("%*s", (int) l->indent, "");
-			prin2n(l->line);
-		}
-	}
-	return l;
-}
-
-program_t *get_prog(void)
-/* Read the description file into core. */
-{
-	cell_t *file;
-	program_t *prog, **ppg= &prog;
-
-	descr= copystr(descr);
-
-	if (descr[0] == '-' && descr[1] == 0) {
-		/* -descr -: Read from standard input. */
-		deallocate(descr);
-		descr= copystr("stdin");
-		dfp= stdin;
-	} else {
-		char *d= descr;
-
-		if (*d == '.' && *++d == '.') d++;
-		if (*d != '/') {
-			/* -descr name: Read /usr/lib/<name>/descr. */
-
-			d= allocate(nil, sizeof(LIB) +
-					(strlen(descr) + 7) * sizeof(*d));
-			sprintf(d, "%s/%s/descr", LIB, descr);
-			deallocate(descr);
-			descr= d;
-		}
-		if ((dfp= fopen(descr, "r")) == nil) fatal(descr);
-	}
-	file= findword(descr);
-	deallocate(descr);
-	descr= file->name;
-
-	/* Preread the first character. */
-	dch= 0;
-	lineno= 1;
-	indent= 0;
-	getdesc();
-
-	while ((*ppg= get_line(file)) != nil) ppg= &(*ppg)->next;
-
-	if (dfp != stdin) (void) fclose(dfp);
-	dec(file);
-
-	return prog;
-}
-
-void makenames(cell_t ***ppr, cell_t *s, char **name, size_t i, size_t *n)
-/* Turn a string of letters and lists into words.  A list denotes a choice
- * between several paths, like a search on $PATH.
- */
-{
-	cell_t *p, *q;
-	size_t len;
-
-	/* Simply add letters, skip empty lists. */
-	while (s != nil && (s->car == nil || s->car->type == LETTER)) {
-		if (s->car != nil) {
-			if (i == *n) *name= allocate(*name,
-						(*n *= 2) * sizeof(**name));
-			(*name)[i++]= s->car->letter;
-		}
-		s= s->cdr;
-	}
-
-	/* If the end is reached then make a word out of the result. */
-	if (s == nil) {
-		**ppr= cons(CELL, findnword(*name, i));
-		*ppr= &(**ppr)->cdr;
-		return;
-	}
-
-	/* Elements of a list must be tried one by one. */
-	p= s->car;
-	s= s->cdr;
-
-	while (p != nil) {
-		if (p->type == WORD) {
-			q= p; p= nil;
-		} else {
-			assert(p->type == CELL);
-			q= p->car; p= p->cdr;
-			assert(q != nil);
-			assert(q->type == WORD);
-		}
-		len= strlen(q->name);
-		if (i + len > *n) *name= allocate(*name,
-					(*n += i + len) * sizeof(**name));
-		memcpy(*name + i, q->name, len);
-
-		makenames(ppr, s, name, i+len, n);
-	}
-}
-
-int constant(cell_t *p)
-/* See if a string has been partially evaluated to a constant so that it
- * can be imploded to a word.
- */
-{
-	while (p != nil) {
-		switch (p->type) {
-		case CELL:
-		case STRING:
-			if (!constant(p->car)) return 0;
-			p= p->cdr;
-			break;
-		case SUBST:
-			return 0;
-		default:
-			return 1;
-		}
-	}
-	return 1;
-}
-
-cell_t *evaluate(cell_t *p, how_t how);
-
-cell_t *explode(cell_t *s, how_t how)
-/* Explode a string with several choices to just one list of choices. */
-{
-	cell_t *t, *r= nil, **pr= &r;
-	size_t i, n;
-	char *name;
-	struct stat st;
-
-	if (how >= PARTIAL) {
-		/* Evaluate the string, expanding substitutions. */
-		while (s != nil) {
-			assert(s->type == STRING);
-			t= inc(s->car);
-			s= go(s, s->cdr);
-
-			t= evaluate(t, how == IMPLODE ? EXPLODE : how);
-
-			/* A list of one element becomes that element. */
-			if (t != nil && t->type == CELL && t->cdr == nil)
-				t= go(t, t->car);
-
-			/* Append the result, trying to flatten it. */
-			*pr= t;
-
-			/* Find the end of what has just been added. */
-			while ((*pr) != nil) {
-				*pr= append(STRING, *pr);
-				pr= &(*pr)->cdr;
-			}
-		}
-		s= r;
-	}
-
-	/* Is the result a simple string of constants? */
-	if (how <= PARTIAL && !constant(s)) return s;
-
-	/* Explode the string to all possible choices, by now the string is
-	 * a series of characters, words and lists of words.
-	 */
-	r= nil; pr= &r;
-	name= allocate(nil, (n= 16) * sizeof(char));
-	i= 0;
-
-	makenames(&pr, s, &name, i, &n);
-	deallocate(name);
-	assert(r != nil);
-	dec(s);
-	s= r;
-
-	/* "How" may specify that a choice must be made. */
-	if (how == IMPLODE) {
-		if (s->cdr != nil) {
-			/* More than one choice, find the file. */
-			do {
-				assert(s->car->type == WORD);
-				if (stat(s->car->name, &st) >= 0)
-					return go(r, s->car);	/* Found. */
-			} while ((s= s->cdr) != nil);
-		}
-		/* The first name is the default if nothing is found. */
-		return go(r, r->car);
-	}
-
-	/* If the result is a list of one word then return that word, otherwise
-	 * turn it into a string again unless this explode has been called
-	 * by another explode.  (Exploding a string inside a string, the joys
-	 * of recursion.)
-	 */
-	if (s->cdr == nil) return go(s, s->car);
-
-	return how >= EXPLODE ? s : cons(STRING, s);
-}
-
-void modify(cell_t **pp, cell_t *p, type_t mode)
-/* Add or remove the element p from the list *pp. */
-{
-	while (*pp != nil) {
-		*pp= append(CELL, *pp);
-
-		if ((*pp)->car == p) {
-			/* Found it, if adding then exit, else remove. */
-			if (mode == PLUS) break;
-			*pp= go(*pp, (*pp)->cdr);
-		} else
-			pp= &(*pp)->cdr;
-	}
-
-	if (*pp == nil && mode == PLUS) {
-		/* Not found, add it. */
-		*pp= cons(CELL, p);
-	} else
-		dec(p);
-}
-
-int tainted(cell_t *p)
-/* A variable is tainted (must be substituted) if either it is marked as a
- * local variable, or some subst in its value is.
- */
-{
-	if (p == nil) return 0;
-
-	switch (p->type) {
-	case CELL:
-	case STRING:
-		return tainted(p->car) || tainted(p->cdr);
-	case SUBST:
-		return p->subst->flags & W_LOCAL || tainted(p->subst->value);
-	default:
-		return 0;
-	}
-}
-
-cell_t *evaluate(cell_t *p, how_t how)
-/* Evaluate an expression, usually the right hand side of an assignment. */
-{
-	cell_t *q, *t, *r= nil, **pr= &r;
-	type_t mode;
-
-	if (p == nil) return nil;
-
-	switch (p->type) {
-	case CELL:
-		break;	/* see below */
-	case STRING:
-		return explode(p, how);
-	case SUBST:
-		if (how >= FULL || tainted(p))
-			p= evaluate(go(p, p->subst->value), how);
-		return p;
-	case EQUALS:
-		fprintf(stderr,
-			"\"%s\", line %u: Can't do nested assignments\n",
-			descr, pc->lineno);
-		action= 0;
-		dec(p);
-		return nil;
-	case LETTER:
-	case WORD:
-	case INPUT:
-	case OUTPUT:
-	case PLUS:
-	case MINUS:
-		return p;
-	default:
-		assert(0);
-	}
-
-	/* It's a list, see if there is a '*' there forcing a full expansion,
-	 * or a '+' or '-' forcing an implosive expansion.  (Yeah, right.)
-	 * Otherwise evaluate each element.
-	 */
-	q = inc(p);
-	while (p != nil) {
-		if ((t= p->car) != nil) {
-			if (t->type == STAR) {
-				if (how < FULL) how= FULL;
-				dec(q);
-				*pr= evaluate(go(p, p->cdr), how);
-				return r;
-			}
-			if (how>=FULL && (t->type == PLUS || t->type == MINUS))
-				break;
-		}
-
-		t= evaluate(inc(t), how);
-		assert(p->type == CELL);
-		p= go(p, p->cdr);
-
-		if (how >= FULL) {
-			/* Flatten the list. */
-			*pr= t;
-		} else {
-			/* Keep the nested list structure. */
-			*pr= cons(CELL, t);
-		}
-
-		/* Find the end of what has just been added. */
-		while ((*pr) != nil) {
-			*pr= append(CELL, *pr);
-			pr= &(*pr)->cdr;
-		}
-	}
-
-	if (p == nil) {
-		/* No PLUS or MINUS: done. */
-		dec(q);
-		return r;
-	}
-
-	/* A PLUS or MINUS, reevaluate the original list implosively. */
-	if (how < IMPLODE) {
-		dec(r);
-		dec(p);
-		return evaluate(q, IMPLODE);
-	}
-	dec(q);
-
-	/* Execute the PLUSes and MINUSes. */
-	while (p != nil) {
-		t= inc(p->car);
-		p= go(p, p->cdr);
-
-		if (t != nil && (t->type == PLUS || t->type == MINUS)) {
-			/* Change the add/subtract mode. */
-			mode= t->type;
-			dec(t);
-			continue;
-		}
-
-		t= evaluate(t, IMPLODE);
-
-		/* Add or remove all elements of t to/from r. */
-		while (t != nil) {
-			if (t->type == CELL) {
-				modify(&r, inc(t->car), mode);
-			} else {
-				modify(&r, t, mode);
-				break;
-			}
-			t= go(t, t->cdr);
-		}
-	}
-	return r;
-}
-
-/* An ACD program can be in three phases: Initialization (the first run
- * of the program), argument scanning, and compilation.
- */
-typedef enum phase { INIT, SCAN, COMPILE } phase_t;
-
-phase_t phase;
-
-typedef struct rule {		/* Transformation rule. */
-	struct rule	*next;
-	char		type;		/* arg, transform, combine */
-	char		flags;
-	unsigned short	npaths;		/* Number of paths running through. */
-#	define	match	from		/* Arg matching strings. */
-	cell_t		*from;		/* Transformation source suffixe(s) */
-	cell_t		*to;		/* Destination suffix. */
-	cell_t		*wait;		/* Files waiting to be transformed. */
-	program_t	*prog;		/* Program to execute. */
-	struct rule	*path;		/* Transformation path. */
-} rule_t;
-
-typedef enum ruletype { ARG, PREFER, TRANSFORM, COMBINE } ruletype_t;
-
-#define R_PREFER	0x01		/* A preferred transformation. */
-
-rule_t *rules= nil;
-
-void newrule(ruletype_t type, cell_t *from, cell_t *to)
-/* Make a new rule cell. */
-{
-	rule_t *r= nil, **pr= &rules;
-
-	/* See if there is a rule with the same suffixes, probably a matching
-	 * transform and prefer, or a re-execution of the same arg command.
-	 */
-	while ((r= *pr) != nil) {
-		if (r->from == from && r->to == to) break;
-		pr= &r->next;
-	}
-
-	if (*pr == nil) {
-		/* Add a new rule. */
-		*pr= r= allocate(nil, sizeof(*r));
-
-		r->next= nil;
-		r->type= type;
-		r->flags= 0;
-		r->from= r->to= r->wait= nil;
-		r->path= nil;
-	}
-	if (type == TRANSFORM) r->type= TRANSFORM;
-	if (type == PREFER) r->flags|= R_PREFER;
-	if (type != PREFER) r->prog= pc;
-	dec(r->from); r->from= from;
-	dec(r->to); r->to= to;
-}
-
-int talk(void)
-/* True if verbose and if so indent what is to come. */
-{
-	if (verbose < 3) return 0;
-	printf("%*s", (int) pc->indent, "");
-	return 1;
-}
-
-void unix_exec(cell_t *c)
-/* Execute the list of words p as a UNIX command. */
-{
-	cell_t *v, *a;
-	int fd[2];
-	int *pf;
-	char **argv;
-	int i, n;
-	int r, pid, status;
-
-	if (action == 0) return;	/* Error mode. */
-
-	if (talk() || verbose >= 2) prin2n(c);
-
-	fd[0]= fd[1]= -1;
-
-	argv= allocate(nil, (n= 16) * sizeof(*argv));
-	i= 0;
-
-	/* Gather argv[] and scan for I/O redirection. */
-	for (v= c; v != nil; v= v->cdr) {
-		a= v->car;
-		pf= nil;
-		if (a->type == INPUT) pf= &fd[0];
-		if (a->type == OUTPUT) pf= &fd[1];
-
-		if (pf == nil) {
-			/* An argument. */
-			argv[i++]= a->name;
-			if (i==n) argv= allocate(argv, (n*= 2) * sizeof(*argv));
-			continue;
-		}
-		/* I/O redirection. */
-		if ((v= v->cdr) == nil || (a= v->car)->type != WORD) {
-			fprintf(stderr,
-			"\"%s\", line %u: I/O redirection without a file\n",
-				descr, pc->lineno);
-			action= 0;
-			if (v == nil) break;
-		}
-		if (*pf >= 0) close(*pf);
-
-		if (action >= 2
-			&& (*pf= open(a->name, pf == &fd[0] ? O_RDONLY
-				: O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0
-		) {
-			report(a->name);
-			action= 0;
-		}
-	}
-	argv[i]= nil;
-
-	if (i >= 0 && action > 0 && verbose == 1) {
-		char *name= strrchr(argv[0], '/');
-
-		if (name == nil) name= argv[0]; else name++;
-
-		printf("%s\n", name);
-	}
-	if (i >= 0 && action >= 2) {
-		/* Really execute the command. */
-		fflush(stdout);
-		switch (pid= fork()) {
-		case -1:
-			fatal("fork()");
-		case 0:
-			if (fd[0] >= 0) { dup2(fd[0], 0); close(fd[0]); }
-			if (fd[1] >= 0) { dup2(fd[1], 1); close(fd[1]); }
-			execvp(argv[0], argv);
-			report(argv[0]);
-			exit(-1);
-		}
-	}
-	if (fd[0] >= 0) close(fd[0]);
-	if (fd[1] >= 0) close(fd[1]);
-
-	if (i >= 0 && action >= 2) {
-		/* Wait for the command to terminate. */
-		while ((r= wait(&status)) != pid && (r >= 0 || errno == EINTR));
-
-		if (status != 0) {
-			int sig= WTERMSIG(status);
-
-			if (!WIFEXITED(status)
-					&& sig != SIGINT && sig != SIGPIPE) {
-				fprintf(stderr, "%s: %s: Signal %d%s\n",
-					program, argv[0], sig,
-					status & 0x80 ? " - core dumped" : "");
-			}
-			action= 0;
-		}
-	}
-	deallocate(argv);
-}
-
-/* Special read-only variables ($*) and lists. */
-cell_t *V_star, **pV_star;
-cell_t *L_files, **pL_files= &L_files;
-cell_t *V_in, *V_out, *V_stop, *L_args, *L_predef;
-
-typedef enum exec { DOIT, DONT } exec_t;
-
-void execute(exec_t how, unsigned indent);
-
-int equal(cell_t *p, cell_t *q)
-/* Two lists are equal if they contain each others elements. */
-{
-	cell_t *t, *m1, *m2;
-
-	t= inc(newcell());
-	t->cdr= inc(newcell());
-	t->cdr->cdr= inc(newcell());
-	t->cdr->car= newcell();
-	t->cdr->car->type= MINUS;
-	t->cdr->car= inc(t->cdr->car);
-
-	/* Compute p - q. */
-	t->car= inc(p);
-	t->cdr->cdr->car= inc(q);
-	m1= evaluate(inc(t), IMPLODE);
-	dec(m1);
-
-	/* Compute q - p. */
-	t->car= q;
-	t->cdr->cdr->car= p;
-	m2= evaluate(t, IMPLODE);
-	dec(m2);
-
-	/* Both results must be empty. */
-	return m1 == nil && m2 == nil;
-}
-
-int wordlist(cell_t **pw, int atom)
-/* Check if p is a list of words, typically an imploded list.  Return
- * the number of words seen, -1 if they are not words (INPUT/OUTPUT?).
- * If atom is true than a list of one word is turned into a word.
- */
-{
-	int n= 0;
-	cell_t *p, **pp= pw;
-
-	while (*pp != nil) {
-		*pp= append(CELL, *pp);
-		p= (*pp)->car;
-		n= n >= 0 && p != nil && p->type == WORD ? n+1 : -1;
-		pp= &(*pp)->cdr;
-	}
-	if (atom && n == 1) *pw= go(*pw, (*pw)->car);
-	return n;
-}
-
-char *template;		/* Current name of a temporary file. */
-static char *tp;	/* Current place withing the tempfile. */
-
-char *maketemp(void)
-/* Return a name that can be used as a temporary filename. */
-{
-	int i= 0;
-
-	if (tp == nil) {
-		size_t len= strlen(template);
-
-		template= allocate(template, (len+20) * sizeof(*template));
-		sprintf(template+len, "/acd%d", getpid());
-		tp= template + strlen(template);
-	}
-
-	for (;;) {
-		switch (tp[i]) {
-		case 0:		tp[i]= 'a';
-				tp[i+1]= 0;	return template;
-		case 'z':	tp[i++]= 'a';	break;
-		default:	tp[i]++;	return template;
-		}
-	}
-}
-
-void inittemp(char *tmpdir)
-/* Initialize the temporary filename generator. */
-{
-	template= allocate(nil, (strlen(tmpdir)+20) * sizeof(*template));
-	sprintf(template, "%s/acd%d", tmpdir, getpid());
-	tp= template + strlen(template);
-
-	/* Create a directory within tempdir that we can safely play in. */
-	while (action != 1 && mkdir(template, 0700) < 0) {
-		if (errno == EEXIST) {
-			(void) maketemp();
-		} else {
-			report(template);
-			action= 0;
-		}
-	}
-	if (verbose >= 2) printf("mkdir %s\n", template);
-	while (*tp != 0) tp++;
-	*tp++= '/';
-	*tp= 0;
-}
-
-void deltemp(void)
-/* Remove our temporary temporaries directory. */
-{
-	while (*--tp != '/') {}
-	*tp = 0;
-	if (rmdir(template) < 0 && errno != ENOENT) report(template);
-	if (verbose >= 2) printf("rmdir %s\n", template);
-	deallocate(template);
-}
-
-cell_t *splitenv(char *env)
-/* Split a string from the environment into several words at whitespace
- * and colons.  Two colons (::) become a dot.
- */
-{
-	cell_t *r= nil, **pr= &r;
-	char *p;
-
-	do {
-		while (*env != 0 && isspace(*env)) env++;
-
-		if (*env == 0) break;
-
-		p= env;
-		while (*p != 0 && !isspace(*p) && *p != ':') p++;
-
-		*pr= cons(CELL,
-			p == env ? findword(".") : findnword(env, p-env));
-		pr= &(*pr)->cdr;
-		env= p;
-	} while (*env++ != 0);
-	return r;
-}
-
-void key_usage(char *how)
-{
-	fprintf(stderr, "\"%s\", line %u: Usage: %s %s\n",
-		descr, pc->lineno, pc->line->car->name, how);
-	action= 0;
-}
-
-void inappropriate(void)
-{
-	fprintf(stderr, "\"%s\", line %u: wrong execution phase for '%s'\n",
-		descr, pc->lineno, pc->line->car->name);
-	action= 0;
-}
-
-int readonly(cell_t *v)
-{
-	if (v->flags & W_RDONLY) {
-		fprintf(stderr, "\"%s\", line %u: %s is read-only\n",
-			descr, pc->lineno, v->name);
-		action= 0;
-		return 1;
-	}
-	return 0;
-}
-
-void complain(cell_t *err)
-/* acd: err ... */
-{
-	cell_t *w;
-
-	fprintf(stderr, "%s:", program);
-
-	while (err != nil) {
-		if (err->type == CELL) {
-			w= err->car; err= err->cdr;
-		} else {
-			w= err; err= nil;
-		}
-		fprintf(stderr, " %s", w->name);
-	}
-	action= 0;
-}
-
-int keyword(char *name)
-/* True if the current line is headed by the given keyword. */
-{
-	cell_t *t;
-
-	return (t= pc->line) != nil && t->type == CELL
-		&& (t= t->car) != nil && t->type == WORD
-		&& strcmp(t->name, name) == 0;
-}
-
-cell_t *getvar(cell_t *v)
-/* Return a word or the word referenced by a subst. */
-{
-	if (v == nil) return nil;
-	if (v->type == WORD) return v;
-	if (v->type == SUBST) return v->subst;
-	return nil;
-}
-
-void argscan(void), compile(void);
-void transform(rule_t *);
-
-void exec_one(void)
-/* Execute one line of the program. */
-{
-	cell_t *v, *p, *q, *r, *t;
-	unsigned n= 0;
-	static int last_if= 1;
-
-	/* Description file this line came from. */
-	descr= pc->file->name;
-
-	for (p= pc->line; p != nil; p= p->cdr) n++;
-
-	if (n == 0) return;	/* Null statement. */
-
-	p= pc->line;
-	q= p->cdr;
-	r= q == nil ? nil : q->cdr;
-
-	/* Try one by one all the different commands. */
-
-	if (n >= 2 && q->car != nil && q->car->type == EQUALS) {
-		/* An assignment. */
-		int flags;
-
-		if ((v= getvar(p->car)) == nil) {
-			fprintf(stderr,
-				"\"%s\", line %u: Usage: <var> = expr ...\n",
-				descr, pc->lineno);
-			action= 0;
-			return;
-		}
-
-		if (readonly(v)) return;
-
-		flags= v->flags;
-		v->flags|= W_LOCAL|W_RDONLY;
-		t= evaluate(inc(r), PARTIAL);
-		dec(v->value);
-		v->value= t;
-		v->flags= flags | W_SET;
-		if (talk()) {
-			printf("%s =\b=\b= ", v->name);
-			prin2n(t);
-		}
-	} else
-	if (keyword("unset")) {
-		/* Set a variable to "undefined". */
-
-		if (n != 2 || (v= getvar(q->car)) == nil) {
-			key_usage("<var>");
-			return;
-		}
-		if (readonly(v)) return;
-
-		if (talk()) prin2n(p);
-
-		dec(v->value);
-		v->value= nil;
-		v->flags&= ~W_SET;
-	} else
-	if (keyword("import")) {
-		/* Import a variable from the UNIX environment. */
-		char *env;
-
-		if (n != 2 || (v= getvar(q->car)) == nil) {
-			key_usage("<var>");
-			return;
-		}
-		if (readonly(v)) return;
-
-		if ((env= getenv(v->name)) == nil) return;
-
-		if (talk()) printf("import %s=%s\n", v->name, env);
-
-		t= splitenv(env);
-		dec(v->value);
-		v->value= t;
-		v->flags|= W_SET;
-	} else
-	if (keyword("mktemp")) {
-		/* Assign a variable the name of a temporary file. */
-		char *tmp, *suff;
-
-		r= evaluate(inc(r), IMPLODE);
-		if (n == 3 && wordlist(&r, 1) != 1) n= 0;
-
-		if ((n != 2 && n != 3) || (v= getvar(q->car)) == nil) {
-			dec(r);
-			key_usage("<var> [<suffix>]");
-			return;
-		}
-		if (readonly(v)) { dec(r); return; }
-
-		tmp= maketemp();
-		suff= r == nil ? "" : r->name;
-
-		t= newcell();
-		t->type= WORD;
-		t->name= allocate(nil,
-			(strlen(tmp) + strlen(suff) + 1) * sizeof(*t->name));
-		strcpy(t->name, tmp);
-		strcat(t->name, suff);
-		t= inc(t);
-		dec(r);
-		dec(v->value);
-		v->value= t;
-		v->flags|= W_SET;
-		t->flags|= W_TEMP;
-		if (talk()) printf("mktemp %s=%s\n", v->name, t->name);
-	} else
-	if (keyword("temporary")) {
-		/* Mark a word as a temporary file. */
-		cell_t *tmp;
-
-		tmp= evaluate(inc(q), IMPLODE);
-
-		if (wordlist(&tmp, 1) < 0) {
-			dec(tmp);
-			key_usage("<word>");
-			return;
-		}
-		if (talk()) printf("temporary %s\n", tmp->name);
-
-		tmp->flags|= W_TEMP;
-		dec(tmp);
-	} else
-	if (keyword("stop")) {
-		/* Set the suffix to stop the transformation on. */
-		cell_t *suff;
-
-		if (phase > SCAN) { inappropriate(); return; }
-
-		suff= evaluate(inc(q), IMPLODE);
-
-		if (wordlist(&suff, 1) != 1) {
-			dec(suff);
-			key_usage("<suffix>");
-			return;
-		}
-		dec(V_stop);
-		V_stop= suff;
-		if (talk()) printf("stop %s\n", suff->name);
-	} else
-	if (keyword("numeric")) {
-		/* Check if a string denotes a number, like $n in -O$n. */
-		cell_t *num;
-		char *pn;
-
-		num= evaluate(inc(q), IMPLODE);
-
-		if (wordlist(&num, 1) != 1) {
-			dec(num);
-			key_usage("<arg>");
-			return;
-		}
-		if (talk()) printf("numeric %s\n", num->name);
-
-		(void) strtoul(num->name, &pn, 10);
-		if (*pn != 0) {
-			complain(phase == SCAN ? V_star->value : nil);
-			if (phase == SCAN) fputc(':', stderr);
-			fprintf(stderr, " '%s' is not a number\n", num->name);
-		}
-		dec(num);
-	} else
-	if (keyword("error")) {
-		/* Signal an error. */
-		cell_t *err;
-
-		err= evaluate(inc(q), IMPLODE);
-
-		if (wordlist(&err, 0) < 1) {
-			dec(err);
-			key_usage("expr ...");
-			return;
-		}
-
-		if (talk()) { printf("error "); prin2n(err); }
-
-		complain(err);
-		fputc('\n', stderr);
-		dec(err);
-	} else
-	if (keyword("if")) {
-		/* if (list) = (list) using set comparison. */
-		int eq;
-
-		if (n != 4 || r->car == nil || r->car->type != EQUALS) {
-			key_usage("<expr> = <expr>");
-			execute(DONT, pc->indent+1);
-			last_if= 1;
-			return;
-		}
-		q= q->car;
-		r= r->cdr->car;
-		if (talk()) {
-			printf("if ");
-			prin1(t= evaluate(inc(q), IMPLODE));
-			dec(t);
-			printf(" = ");
-			prin1n(t= evaluate(inc(r), IMPLODE));
-			dec(t);
-		}
-		eq= equal(q, r);
-		execute(eq ? DOIT : DONT, pc->indent+1);
-		last_if= eq;
-	} else
-	if (keyword("ifdef") || keyword("ifndef")) {
-		/* Is a variable defined or undefined? */
-		int doit;
-
-		if (n != 2 || (v= getvar(q->car)) == nil) {
-			key_usage("<var>");
-			execute(DONT, pc->indent+1);
-			last_if= 1;
-			return;
-		}
-		if (talk()) prin2n(p);
-
-		doit= ((v->flags & W_SET) != 0) ^ (p->car->name[2] == 'n');
-		execute(doit ? DOIT : DONT, pc->indent+1);
-		last_if= doit;
-	} else
-	if (keyword("iftemp") || keyword("ifhash")) {
-		/* Is a file a temporary file? */
-		/* Does a file need preprocessing? */
-		cell_t *file;
-		int doit= 0;
-
-		file= evaluate(inc(q), IMPLODE);
-
-		if (wordlist(&file, 1) != 1) {
-			dec(file);
-			key_usage("<arg>");
-			return;
-		}
-		if (talk()) printf("%s %s\n", p->car->name, file->name);
-
-		if (p->car->name[2] == 't') {
-			/* iftemp file */
-			if (file->flags & W_TEMP) doit= 1;
-		} else {
-			/* ifhash file */
-			int fd;
-			char hash;
-
-			if ((fd= open(file->name, O_RDONLY)) >= 0) {
-				if (read(fd, &hash, 1) == 1 && hash == '#')
-					doit= 1;
-				close(fd);
-			}
-		}
-		dec(file);
-
-		execute(doit ? DOIT : DONT, pc->indent+1);
-		last_if= doit;
-	} else
-	if (keyword("else")) {
-		/* Else clause for an if, ifdef, or ifndef. */
-		if (n != 1) {
-			key_usage("");
-			execute(DONT, pc->indent+1);
-			return;
-		}
-		if (talk()) prin2n(p);
-
-		execute(!last_if ? DOIT : DONT, pc->indent+1);
-	} else
-	if (keyword("treat")) {
-		/* Treat a file as having a certain suffix. */
-
-		if (phase > SCAN) { inappropriate(); return; }
-
-		if (n == 3) {
-			q= evaluate(inc(q->car), IMPLODE);
-			r= evaluate(inc(r->car), IMPLODE);
-		}
-		if (n != 3 || wordlist(&q, 1) != 1 || wordlist(&r, 1) != 1) {
-			if (n == 3) { dec(q); dec(r); }
-			key_usage("<file> <suffix>");
-			return;
-		}
-		if (talk()) printf("treat %s %s\n", q->name, r->name);
-
-		dec(q->suffix);
-		q->suffix= r;
-		q->flags|= W_SUFF;
-		dec(q);
-	} else
-	if (keyword("apply")) {
-		/* Apply a transformation rule to the current input file. */
-		rule_t *rule, *sav_path;
-		cell_t *sav_wait, *sav_in, *sav_out;
-		program_t *sav_next;
-
-		if (phase != COMPILE) { inappropriate(); return; }
-
-		if (V_star->value->cdr != nil) {
-			fprintf(stderr, "\"%s\", line %u: $* is not one file\n",
-				descr, pc->lineno);
-			action= 0;
-			return;
-		}
-		if (n == 3) {
-			q= evaluate(inc(q->car), IMPLODE);
-			r= evaluate(inc(r->car), IMPLODE);
-		}
-		if (n != 3 || wordlist(&q, 1) != 1 || wordlist(&r, 1) != 1) {
-			if (n == 3) { dec(q); dec(r); }
-			key_usage("<file> <suffix>");
-			return;
-		}
-		if (talk()) printf("apply %s %s\n", q->name, r->name);
-
-		/* Find a rule */
-		for (rule= rules; rule != nil; rule= rule->next) {
-			if (rule->type == TRANSFORM
-				&& rule->from == q && rule->to == r) break;
-		}
-		if (rule == nil) {
-			fprintf(stderr,
-				"\"%s\", line %u: no %s %s transformation\n",
-				descr, pc->lineno, q->name, r->name);
-			action= 0;
-		}
-		dec(q);
-		dec(r);
-		if (rule == nil) return;
-
-		/* Save the world. */
-		sav_path= rule->path;
-		sav_wait= rule->wait;
-		sav_in= V_in->value;
-		sav_out= V_out->value;
-		sav_next= nextpc;
-
-		/* Isolate the rule and give it new input. */
-		rule->path= rule;
-		rule->wait= V_star->value;
-		V_star->value= nil;
-		V_in->value= nil;
-		V_out->value= nil;
-
-		transform(rule);
-
-		/* Retrieve the new $* and repair. */
-		V_star->value= rule->wait;
-		rule->path= sav_path;
-		rule->wait= sav_wait;
-		V_in->value= sav_in;
-		V_out->value= sav_out;
-		V_out->flags= W_SET|W_LOCAL;
-		nextpc= sav_next;
-	} else
-	if (keyword("include")) {
-		/* Include another description file into this program. */
-		cell_t *file;
-		program_t *incl, *prog, **ppg= &prog;
-
-		file= evaluate(inc(q), IMPLODE);
-
-		if (wordlist(&file, 1) != 1) {
-			dec(file);
-			key_usage("<file>");
-			return;
-		}
-		if (talk()) printf("include %s\n", file->name);
-		descr= file->name;
-		incl= pc;
-		prog= get_prog();
-		dec(file);
-
-		/* Raise the program to the include's indent level. */
-		while (*ppg != nil) {
-			(*ppg)->indent += incl->indent;
-			ppg= &(*ppg)->next;
-		}
-
-		/* Kill the include and splice the included program in. */
-		dec(incl->line);
-		incl->line= nil;
-		*ppg= incl->next;
-		incl->next= prog;
-		pc= incl;
-		nextpc= prog;
-	} else
-	if (keyword("arg")) {
-		/* An argument scanning rule. */
-
-		if (phase > SCAN) { inappropriate(); return; }
-
-		if (n < 2) {
-			key_usage("<string> ...");
-			execute(DONT, pc->indent+1);
-			return;
-		}
-		if (talk()) prin2n(p);
-
-		newrule(ARG, inc(q), nil);
-
-		/* Always skip the body, it comes later. */
-		execute(DONT, pc->indent+1);
-	} else
-	if (keyword("transform")) {
-		/* A file transformation rule. */
-
-		if (phase > SCAN) { inappropriate(); return; }
-
-		if (n == 3) {
-			q= evaluate(inc(q->car), IMPLODE);
-			r= evaluate(inc(r->car), IMPLODE);
-		}
-		if (n != 3 || wordlist(&q, 1) != 1 || wordlist(&r, 1) != 1) {
-			if (n == 3) { dec(q); dec(r); }
-			key_usage("<suffix1> <suffix2>");
-			execute(DONT, pc->indent+1);
-			return;
-		}
-		if (talk()) printf("transform %s %s\n", q->name, r->name);
-
-		newrule(TRANSFORM, q, r);
-
-		/* Body comes later. */
-		execute(DONT, pc->indent+1);
-	} else
-	if (keyword("prefer")) {
-		/* Prefer a transformation over others. */
-
-		if (phase > SCAN) { inappropriate(); return; }
-
-		if (n == 3) {
-			q= evaluate(inc(q->car), IMPLODE);
-			r= evaluate(inc(r->car), IMPLODE);
-		}
-		if (n != 3 || wordlist(&q, 1) != 1 || wordlist(&r, 1) != 1) {
-			if (n == 3) { dec(q); dec(r); }
-			key_usage("<suffix1> <suffix2>");
-			return;
-		}
-		if (talk()) printf("prefer %s %s\n", q->name, r->name);
-
-		newrule(PREFER, q, r);
-	} else
-	if (keyword("combine")) {
-		/* A file combination (loader) rule. */
-
-		if (phase > SCAN) { inappropriate(); return; }
-
-		if (n == 3) {
-			q= evaluate(inc(q->car), IMPLODE);
-			r= evaluate(inc(r->car), IMPLODE);
-		}
-		if (n != 3 || wordlist(&q, 0) < 1 || wordlist(&r, 1) != 1) {
-			if (n == 3) { dec(q); dec(r); }
-			key_usage("<suffix-list> <suffix>");
-			execute(DONT, pc->indent+1);
-			return;
-		}
-		if (talk()) {
-			printf("combine ");
-			prin1(q);
-			printf(" %s\n", r->name);
-		}
-
-		newrule(COMBINE, q, r);
-
-		/* Body comes later. */
-		execute(DONT, pc->indent+1);
-	} else
-	if (keyword("scan") || keyword("compile")) {
-		program_t *next= nextpc;
-
-		if (n != 1) { key_usage(""); return; }
-		if (phase != INIT) { inappropriate(); return; }
-
-		if (talk()) prin2n(p);
-
-		argscan();
-		if (p->car->name[0] == 'c') compile();
-		nextpc= next;
-	} else {
-		/* A UNIX command. */
-		t= evaluate(inc(pc->line), IMPLODE);
-		unix_exec(t);
-		dec(t);
-	}
-}
-
-void execute(exec_t how, unsigned indent)
-/* Execute (or skip) all lines with at least the given indent. */
-{
-	int work= 0;	/* Need to execute at least one line. */
-	unsigned firstline;
-	unsigned nice_indent= 0;	/* 0 = Don't know what's nice yet. */
-
-	if (pc == nil) return;	/* End of program. */
-
-	firstline= pc->lineno;
-
-	if (how == DONT) {
-		/* Skipping a body, but is there another guard? */
-		pc= pc->next;
-		if (pc != nil && pc->indent < indent && pc->line != nil) {
-			/* There is one!  Bail out, then it get's executed. */
-			return;
-		}
-	} else {
-		/* Skip lines with a lesser indentation, they are guards for
-		 * the same substatements.  Don't go past empty lines.
-		 */
-		while (pc != nil && pc->indent < indent && pc->line != nil)
-			pc= pc->next;
-	}
-
-	/* Execute all lines with an indentation of at least "indent". */
-	while (pc != nil && pc->indent >= indent) {
-		if (pc->indent != nice_indent && how == DOIT) {
-			if (nice_indent != 0) {
-				fprintf(stderr,
-			"\"%s\", line %u: (warning) sudden indentation shift\n",
-					descr, pc->lineno);
-			}
-			nice_indent= pc->indent;
-		}
-		nextpc= pc->next;
-		if (how == DOIT) exec_one();
-		pc= nextpc;
-		work= 1;
-	}
-
-	if (indent > 0 && !work) {
-		fprintf(stderr, "\"%s\", line %u: empty body, no statements\n",
-			descr, firstline);
-		action= 0;
-	}
-}
-
-int argmatch(int shift, cell_t *match, cell_t *match1, char *arg1)
-/* Try to match an arg rule to the input file list L_args.  Execute the arg
- * body (pc is set to it) on success.
- */
-{
-	cell_t *oldval, *v;
-	int m, oldflags;
-	size_t i, len;
-	int minus= 0;
-
-	if (shift) {
-		/* An argument has been accepted and may be shifted to $*. */
-		cell_t **oldpstar= pV_star;
-		*pV_star= L_args;
-		L_args= *(pV_star= &L_args->cdr);
-		*pV_star= nil;
-
-		if (argmatch(0, match->cdr, nil, nil)) return 1;
-
-		/* Undo the damage. */
-		*pV_star= L_args;
-		L_args= *(pV_star= oldpstar);
-		*pV_star= nil;
-		return 0;
-	}
-
-	if (match == nil) {
-		/* A full match, execute the arg body. */
-
-		/* Enable $>. */
-		V_out->flags= W_SET|W_LOCAL;
-
-		if (verbose >= 3) {
-			prin2(pc->line);
-			printf(" =\b=\b= ");
-			prin2n(V_star->value);
-		}
-		execute(DOIT, pc->indent+1);
-
-		/* Append $> to the file list. */
-		if (V_out->value != nil) {
-			*pL_files= cons(CELL, V_out->value);
-			pL_files= &(*pL_files)->cdr;
-		}
-
-		/* Disable $>. */
-		V_out->value= nil;
-		V_out->flags= W_SET|W_LOCAL|W_RDONLY;
-
-		return 1;
-	}
-
-	if (L_args == nil) return 0;	/* Out of arguments to match. */
-
-	/* Match is a list of words, substs and strings containing letters and
-	 * substs.  Match1 is the current element of the first element of match.
-	 * Arg1 is the current character of the first element of L_args.
-	 */
-	if (match1 == nil) {
-		/* match1 is at the end of a string, then arg1 must also. */
-		if (arg1 != nil) {
-			if (*arg1 != 0) return 0;
-			return argmatch(1, match, nil, nil);
-		}
-		/* If both are nil: Initialize. */
-		match1= match->car;
-		arg1= L_args->car->name;
-
-		/* A subst may not match a leading '-'. */
-		if (arg1[0] == '-') minus= 1;
-	}
-
-	if (match1->type == WORD && strcmp(match1->name, arg1) == 0) {
-		/* A simple match of an argument. */
-
-		return argmatch(1, match, nil, nil);
-	}
-
-	if (match1->type == SUBST && !minus) {
-		/* A simple match of a subst. */
-
-		/* The variable gets the first of the arguments as its value. */
-		v= match1->subst;
-		if (v->flags & W_RDONLY) return 0;	/* ouch */
-		oldflags= v->flags;
-		v->flags= W_SET|W_LOCAL|W_RDONLY;
-		oldval= v->value;
-		v->value= inc(L_args->car);
-
-		m= argmatch(1, match, nil, nil);
-
-		/* Recover the value of the variable. */
-		dec(v->value);
-		v->flags= oldflags;
-		v->value= oldval;
-		return m;
-	}
-	if (match1->type != STRING) return 0;
-
-	/* Match the first item in the string. */
-	if (match1->car == nil) return 0;
-
-	if (match1->car->type == LETTER
-			&& match1->car->letter == (unsigned char) *arg1) {
-		/* A letter matches, try the rest of the string. */
-
-		return argmatch(0, match, match1->cdr, arg1+1);
-	}
-
-	/* It can only be a subst in a string now. */
-	len= strlen(arg1);
-	if (match1->car->type != SUBST || minus || len == 0) return 0;
-
-	/* The variable can match from 1 character to all of the argument.
-	 * Matching as few characters as possible happens to be the Right Thing.
-	 */
-	v= match1->car->subst;
-	if (v->flags & W_RDONLY) return 0;	/* ouch */
-	oldflags= v->flags;
-	v->flags= W_SET|W_LOCAL|W_RDONLY;
-	oldval= v->value;
-
-	m= 0;
-	for (i= match1->cdr == nil ? len : 1; !m && i <= len; i++) {
-		v->value= findnword(arg1, i);
-
-		m= argmatch(0, match, match1->cdr, arg1+i);
-
-		dec(v->value);
-	}
-	/* Recover the value of the variable. */
-	v->flags= oldflags;
-	v->value= oldval;
-	return m;
-}
-
-void argscan(void)
-/* Match all the arguments to the arg rules, those that don't match are
- * used as files for transformation.
- */
-{
-	rule_t *rule;
-	int m;
-
-	phase= SCAN;
-
-	/* Process all the arguments. */
-	while (L_args != nil) {
-		pV_star= &V_star->value;
-
-		/* Try all the arg rules. */
-		m= 0;
-		for (rule= rules; !m && rule != nil; rule= rule->next) {
-			if (rule->type != ARG) continue;
-
-			pc= rule->prog;
-
-			m= argmatch(0, rule->match, nil, nil);
-		}
-		dec(V_star->value);
-		V_star->value= nil;
-
-		/* On failure, add the first argument to the list of files. */
-		if (!m) {
-			*pL_files= L_args;
-			L_args= *(pL_files= &L_args->cdr);
-			*pL_files= nil;
-		}
-	}
-	phase= INIT;
-}
-
-int member(cell_t *p, cell_t *l)
-/* True if p is a member of list l. */
-{
-	while (l != nil && l->type == CELL) {
-		if (p == l->car) return 1;
-		l= l->cdr;
-	}
-	return p == l;
-}
-
-long basefind(cell_t *f, cell_t *l)
-/* See if f has a suffix in list l + set the base name of f.
- * -1 if not found, preference number for a short basename otherwise. */
-{
-	cell_t *suff;
-	size_t blen, slen;
-	char *base;
-
-	/* Determine base name of f, with suffix. */
-	if ((base= strrchr(f->name, '/')) == nil) base= f->name; else base++;
-	blen= strlen(base);
-
-	/* Try suffixes. */
-	while (l != nil) {
-		if (l->type == CELL) {
-			suff= l->car; l= l->cdr;
-		} else {
-			suff= l; l= nil;
-		}
-		if (f->flags & W_SUFF) {
-			/* F has a suffix imposed on it. */
-			if (f->suffix == suff) return 0;
-			continue;
-		}
-		slen= strlen(suff->name);
-		if (slen < blen && strcmp(base+blen-slen, suff->name) == 0) {
-			/* Got it! */
-			dec(f->base);
-			f->base= findnword(base, blen-slen);
-			return 10000L * (blen - slen);
-		}
-	}
-	return -1;
-}
-
-#define NO_PATH		2000000000	/* No path found yet. */
-
-long shortest;		/* Length of the shortest path as yet. */
-
-rule_t *findpath(long depth, int seek, cell_t *file, rule_t *start)
-/* Find the path of the shortest transformation to the stop suffix. */
-{
-	rule_t *rule;
-
-	if (action == 0) return nil;
-
-	if (start == nil) {
-		/* No starting point defined, find one using "file". */
-
-		for (rule= rules; rule != nil; rule= rule->next) {
-			if (rule->type < TRANSFORM) continue;
-
-			if ((depth= basefind(file, rule->from)) >= 0) {
-				if (findpath(depth, seek, nil, rule) != nil)
-					return rule;
-			}
-		}
-		return nil;
-	}
-
-	/* Cycle? */
-	if (start->path != nil) {
-		/* We can't have cycles through combines. */
-		if (start->type == COMBINE) {
-			fprintf(stderr,
-				"\"%s\": contains a combine-combine cycle\n",
-				descr);
-			action= 0;
-		}
-		return nil;
-	}
-
-	/* Preferred transformations are cheap. */
-	if (start->flags & R_PREFER) depth-= 100;
-
-	/* Try to go from start closer to the stop suffix. */
-	for (rule= rules; rule != nil; rule= rule->next) {
-		if (rule->type < TRANSFORM) continue;
-
-		if (member(start->to, rule->from)) {
-			start->path= rule;
-			rule->npaths++;
-			if (findpath(depth+1, seek, nil, rule) != nil)
-				return start;
-			start->path= nil;
-			rule->npaths--;
-		}
-	}
-
-	if (V_stop == nil) {
-		fprintf(stderr, "\"%s\": no stop suffix has been defined\n",
-			descr);
-		action= 0;
-		return nil;
-	}
-
-	/* End of the line? */
-	if (start->to == V_stop) {
-		/* Got it. */
-		if (seek) {
-			/* Second hunt, do we find the shortest? */
-			if (depth == shortest) return start;
-		} else {
-			/* Is this path shorter than the last one? */
-			if (depth < shortest) shortest= depth;
-		}
-	}
-	return nil;	/* Fail. */
-}
-
-void transform(rule_t *rule)
-/* Transform the file(s) connected to the rule according to the rule. */
-{
-	cell_t *file, *in, *out;
-	char *base;
-
-	/* Let $* be the list of input files. */
-	while (rule->wait != nil) {
-		file= rule->wait;
-		rule->wait= file->cdr;
-		file->cdr= V_star->value;
-		V_star->value= file;
-	}
-
-	/* Set $< to the basename of the first input file. */
-	file= file->car;
-	V_in->value= in= inc(file->flags & W_SUFF ? file : file->base);
-	file->flags&= ~W_SUFF;
-
-	/* Set $> to the output file name of the transformation. */
-	out= newcell();
-	out->type= WORD;
-	base= rule->path == nil ? in->name : maketemp();
-	out->name= allocate(nil,
-		(strlen(base)+strlen(rule->to->name)+1) * sizeof(*out->name));
-	strcpy(out->name, base);
-	if (rule->path == nil || strchr(rule->to->name, '/') == nil)
-		strcat(out->name, rule->to->name);
-	out= inc(out);
-	if (rule->path != nil) out->flags|= W_TEMP;
-
-	V_out->value= out;
-	V_out->flags= W_SET|W_LOCAL;
-
-	/* Do a transformation.  (Finally) */
-	if (verbose >= 3) {
-		printf("%s ", rule->type==TRANSFORM ? "transform" : "combine");
-		prin2(V_star->value);
-		printf(" %s\n", out->name);
-	}
-	pc= rule->prog;
-	execute(DOIT, pc->indent+1);
-
-	/* Hand $> over to the next rule, it must be a single word. */
-	out= evaluate(V_out->value, IMPLODE);
-	if (wordlist(&out, 1) != 1) {
-		fprintf(stderr,
-		"\"%s\", line %u: $> should be returned as a single word\n",
-			descr, rule->prog->lineno);
-		action= 0;
-	}
-
-	if ((rule= rule->path) != nil) {
-		/* There is a next rule. */
-		dec(out->base);
-		out->base= in;		/* Basename of input file. */
-		file= inc(newcell());
-		file->car= out;
-		file->cdr= rule->wait;
-		rule->wait= file;
-	} else {
-		dec(in);
-		dec(out);
-	}
-
-	/* Undo the damage to $*, $<, and $>. */
-	dec(V_star->value);
-	V_star->value= nil;
-	V_in->value= nil;
-	V_out->value= nil;
-	V_out->flags= W_SET|W_LOCAL|W_RDONLY;
-}
-
-void compile(void)
-{
-	rule_t *rule;
-	cell_t *file, *t;
-
-	phase= COMPILE;
-
-	/* Implode the files list. */
-	L_files= evaluate(L_files, IMPLODE);
-	if (wordlist(&L_files, 0) < 0) {
-		fprintf(stderr, "\"%s\": An assignment to $> contained junk\n",
-			descr);
-		action= 0;
-	}
-
-	while (action != 0 && L_files != nil) {
-		file= L_files->car;
-
-		/* Initialize. */
-		shortest= NO_PATH;
-		for (rule= rules; rule != nil; rule= rule->next)
-			rule->path= nil;
-
-		/* Try all possible transformation paths. */
-		(void) findpath(0L, 0, file, nil);
-
-		if (shortest == NO_PATH) {	/* Can't match the file. */
-			fprintf(stderr,
-			"%s: %s: can't compile, no transformation applies\n",
-				program, file->name);
-			action= 0;
-			return;
-		}
-
-		/* Find the first short path. */
-		if ((rule= findpath(0L, 1, file, nil)) == nil) return;
-
-		/* Transform the file until you hit a combine. */
-		t= inc(newcell());
-		t->car= inc(file);
-		L_files= go(L_files, L_files->cdr);
-		t->cdr= rule->wait;
-		rule->wait= t;
-		while (action != 0 && rule != nil && rule->type != COMBINE) {
-			transform(rule);
-			rule= rule->path;
-		}
-	}
-
-	/* All input files have been transformed to combine rule(s).  Now
-	 * we need to find the combine rule with the least number of paths
-	 * running through it (this combine may be followed by another) and
-	 * transform from there.
-	 */
-	while (action != 0) {
-		int least;
-		rule_t *comb= nil;
-
-		for (rule= rules; rule != nil; rule= rule->next) {
-			rule->path= nil;
-
-			if (rule->type != COMBINE || rule->wait == nil)
-				continue;
-
-			if (comb == nil || rule->npaths < least) {
-				least= rule->npaths;
-				comb= rule;
-			}
-		}
-
-		/* No combine?  Then we're done. */
-		if (comb == nil) break;
-
-		/* Initialize. */
-		shortest= NO_PATH;
-
-		/* Try all possible transformation paths. */
-		(void) findpath(0L, 0, nil, comb);
-
-		if (shortest == NO_PATH) break;
-
-		/* Find the first short path. */
-		if ((rule= findpath(0L, 1, nil, comb)) == nil) return;
-
-		/* Transform until you hit another combine. */
-		do {
-			transform(rule);
-			rule= rule->path;
-		} while (action != 0 && rule != nil && rule->type != COMBINE);
-	}
-	phase= INIT;
-}
-
-cell_t *predef(char *var, char *val)
-/* A predefined variable var with value val, or a special variable. */
-{
-	cell_t *p, *t;
-
-	p= findword(var);
-	if (val != nil) {	/* Predefined. */
-		t= findword(val);
-		dec(p->value);
-		p->value= t;
-		p->flags|= W_SET;
-		if (verbose >= 3) {
-			prin1(p);
-			printf(" =\b=\b= ");
-			prin2n(t);
-		}
-	} else {		/* Special: $* and such. */
-		p->flags= W_SET|W_LOCAL|W_RDONLY;
-	}
-	t= inc(newcell());
-	t->car= p;
-	t->cdr= L_predef;
-	L_predef= t;
-	return p;
-}
-
-void usage(void)
-{
-	fprintf(stderr,
-	"Usage: %s -v<n> -vn<n> -name <name> -descr <descr> -T <dir> ...\n",
-		program);
-	exit(-1);
-}
-
-int main(int argc, char **argv)
-{
-	char *tmpdir;
-	program_t *prog;
-	cell_t **pa;
-	int i;
-
-	/* Call name of the program, decides which description to use. */
-	if ((program= strrchr(argv[0], '/')) == nil)
-		program= argv[0];
-	else
-		program++;
-
-	/* Directory for temporary files. */
-	if ((tmpdir= getenv("TMPDIR")) == nil || *tmpdir == 0)
-		tmpdir= "/tmp";
-
-	/* Transform arguments to a list, processing the few ACD options. */
-	pa= &L_args;
-	for (i= 1; i < argc; i++) {
-		if (argv[i][0] == '-' && argv[i][1] == 'v') {
-			char *a= argv[i]+2;
-
-			if (*a == 'n') { a++; action= 1; }
-			verbose= 2;
-
-			if (*a != 0) {
-				verbose= strtoul(a, &a, 10);
-				if (*a != 0) usage();
-			}
-		} else
-		if (strcmp(argv[i], "-name") == 0) {
-			if (++i == argc) usage();
-			program= argv[i];
-		} else
-		if (strcmp(argv[i], "-descr") == 0) {
-			if (++i == argc) usage();
-			descr= argv[i];
-		} else
-		if (argv[i][0] == '-' && argv[i][1] == 'T') {
-			if (argv[i][2] == 0) {
-				if (++i == argc) usage();
-				tmpdir= argv[i];
-			} else
-				tmpdir= argv[i]+2;
-		} else {
-			/* Any other argument must be processed. */
-			*pa= cons(CELL, findword(argv[i]));
-			pa= &(*pa)->cdr;
-		}
-	}
-#ifndef DESCR
-	/* Default description file is based on the program name. */
-	if (descr == nil) descr= program;
-#else
-	/* Default description file is predefined. */
-	if (descr == nil) descr= DESCR;
-#endif
-
-	inittemp(tmpdir);
-
-	/* Catch user signals. */
-	if (signal(SIGHUP, SIG_IGN) != SIG_IGN) signal(SIGHUP, interrupt);
-	if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, interrupt);
-	if (signal(SIGTERM, SIG_IGN) != SIG_IGN) signal(SIGTERM, interrupt);
-
-	/* Predefined or special variables. */
-	predef("PROGRAM", program);
-	predef("VERSION", version);
-#ifdef ARCH
-	predef("ARCH", ARCH);		/* Cross-compilers like this. */
-#endif
-	V_star= predef("*", nil);
-	V_in= predef("<", nil);
-	V_out= predef(">", nil);
-
-	/* Read the description file. */
-	if (verbose >= 3) printf("include %s\n", descr);
-	prog= get_prog();
-
-	phase= INIT;
-	pc= prog;
-	execute(DOIT, 0);
-
-	argscan();
-	compile();
-
-	/* Delete all allocated data to test inc/dec balance. */
-	while (prog != nil) {
-		program_t *junk= prog;
-		prog= junk->next;
-		dec(junk->file);
-		dec(junk->line);
-		deallocate(junk);
-	}
-	while (rules != nil) {
-		rule_t *junk= rules;
-		rules= junk->next;
-		dec(junk->from);
-		dec(junk->to);
-		dec(junk->wait);
-		deallocate(junk);
-	}
-	deltemp();
-	dec(V_stop);
-	dec(L_args);
-	dec(L_files);
-	dec(L_predef);
-
-	quit(action == 0 ? 1 : 0);
-}
Index: trunk/minix/commands/i386/asmconv/Makefile
===================================================================
--- trunk/minix/commands/i386/asmconv/Makefile	(revision 9)
+++ 	(revision )
@@ -1,32 +1,0 @@
-# Makefile for asmconv.
-
-CFLAGS=		$(OPT)
-LDFLAGS=	-i
-CC = exec cc
-
-all:	asmconv
-
-OBJ=	asm86.o asmconv.o parse_ack.o parse_gnu.o parse_bas.o \
-	tokenize.o emit_ack.o emit_gnu.o
-
-asmconv:	$(OBJ)
-	$(CC) $(LDFLAGS) -o $@ $(OBJ)
-	install -S 8kw $@
-
-install:	/usr/lib/asmconv
-
-/usr/lib/asmconv:	asmconv
-	install -cs -o bin asmconv $@
-
-clean:
-	rm -f $(OBJ) asmconv core
-
-# Dependencies.
-asm86.o:	asm86.h asmconv.h token.h
-asmconv.o:	asmconv.h languages.h asm86.h
-parse_ack.o:	asmconv.h languages.h token.h asm86.h
-parse_gnu.o:	asmconv.h languages.h token.h asm86.h
-parse_bas.o:	asmconv.h languages.h token.h asm86.h
-tokenize.o:	asmconv.h token.h
-emit_ack.o:	asmconv.h languages.h token.h asm86.h
-emit_gnu.o:	asmconv.h languages.h token.h asm86.h
Index: trunk/minix/commands/i386/asmconv/asm86.c
===================================================================
--- trunk/minix/commands/i386/asmconv/asm86.c	(revision 9)
+++ 	(revision )
@@ -1,85 +1,0 @@
-/*	asm86.c - 80X86 assembly intermediate		Author: Kees J. Bot
- *								24 Dec 1993
- */
-#define nil 0
-#include <stddef.h>
-#include <string.h>
-#include <assert.h>
-#include "asm86.h"
-#include "asmconv.h"
-#include "token.h"
-
-expression_t *new_expr(void)
-/* Make a new cell to build an expression. */
-{
-	expression_t *e;
-
-	e= allocate(nil, sizeof(*e));
-	e->operator= -1;
-	e->left= e->middle= e->right= nil;
-	e->name= nil;
-	e->magic= 31624;
-	return e;
-}
-
-void del_expr(expression_t *e)
-/* Delete an expression tree. */
-{
-	if (e != nil) {
-		assert(e->magic == 31624);
-		e->magic= 0;
-		deallocate(e->name);
-		del_expr(e->left);
-		del_expr(e->middle);
-		del_expr(e->right);
-		deallocate(e);
-	}
-}
-
-asm86_t *new_asm86(void)
-/* Make a new cell to hold an 80X86 instruction. */
-{
-	asm86_t *a;
-
-	a= allocate(nil, sizeof(*a));
-	a->opcode= -1;
-	get_file(&a->file, &a->line);
-	a->optype= -1;
-	a->oaz= 0;
-	a->rep= ONCE;
-	a->seg= DEFSEG;
-	a->args= nil;
-	a->magic= 37937;
-	return a;
-}
-
-void del_asm86(asm86_t *a)
-/* Delete an 80X86 instruction. */
-{
-	assert(a != nil);
-	assert(a->magic == 37937);
-	a->magic= 0;
-	del_expr(a->args);
-	deallocate(a);
-}
-
-int isregister(const char *name)
-/* True if the string is a register name.  Return its size. */
-{
-	static char *regs[] = {
-		"al", "bl", "cl", "dl", "ah", "bh", "ch", "dh",
-		"ax", "bx", "cx", "dx", "si", "di", "bp", "sp",
-		"cs", "ds", "es", "fs", "gs", "ss",
-		"eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp",
-		"cr0", "cr1", "cr2", "cr3",
-		"st",
-	};
-	int reg;
-
-	for (reg= 0; reg < arraysize(regs); reg++) {
-		if (strcmp(name, regs[reg]) == 0) {
-			return reg < 8 ? 1 : reg < 22 ? 2 : 4;
-		}
-	}
-	return 0;
-}
Index: trunk/minix/commands/i386/asmconv/asm86.h
===================================================================
--- trunk/minix/commands/i386/asmconv/asm86.h	(revision 9)
+++ 	(revision )
@@ -1,250 +1,0 @@
-/*	asm86.h - 80X86 assembly intermediate		Author: Kees J. Bot
- *								27 Jun 1993
- */
-
-typedef enum opcode {	/* 80486 opcodes, from the i486 reference manual.
-			 * Synonyms left out, some new words invented.
-			 */
-	DOT_ALIGN,
-	DOT_ASCII,	DOT_ASCIZ,
-	DOT_ASSERT,			/* Pseudo's invented */
-	DOT_BASE,
-	DOT_COMM,	DOT_LCOMM,
-	DOT_DATA1,
-	DOT_DATA2,
-	DOT_DATA4,
-	DOT_DEFINE,	DOT_EXTERN,
-	DOT_EQU,
-	DOT_FILE,	DOT_LINE,
-	DOT_LABEL,
-	DOT_LIST,	DOT_NOLIST,
-	DOT_SPACE,
-	DOT_SYMB,
-	DOT_TEXT,	DOT_ROM,	DOT_DATA,	DOT_BSS,	DOT_END,
-	DOT_USE16,	DOT_USE32,
-	AAA,
-	AAD,
-	AAM,
-	AAS,
-	ADC,
-	ADD,
-	AND,
-	ARPL,
-	BOUND,
-	BSF,
-	BSR,
-	BSWAP,
-	BT,
-	BTC,
-	BTR,
-	BTS,
-	CALL,	CALLF,			/* CALLF added */
-	CBW,
-	CLC,
-	CLD,
-	CLI,
-	CLTS,
-	CMC,
-	CMP,
-	CMPS,
-	CMPXCHG,
-	CWD,
-	DAA,
-	DAS,
-	DEC,
-	DIV,
-	ENTER,
-	F2XM1,
-	FABS,
-	FADD,	FADDD,	FADDS,	FADDP,	FIADDL,	FIADDS,
-	FBLD,
-	FBSTP,
-	FCHS,
-	FCLEX,
-	FCOMD,	FCOMS,	FCOMPD,	FCOMPS,	FCOMPP,
-	FCOS,
-	FDECSTP,
-	FDIVD,	FDIVS,	FDIVP,	FIDIVL,	FIDIVS,
-	FDIVRD,	FDIVRS,	FDIVRP,	FIDIVRL,	FIDIVRS,
-	FFREE,
-	FICOM,	FICOMP,
-	FILDQ,	FILDL,	FILDS,
-	FINCSTP,
-	FINIT,
-	FISTL,	FISTS,	FISTP,
-	FLDX,	FLDD,	FLDS,
-	FLD1,	FLDL2T,	FLDL2E,	FLDPI,	FLDLG2,	FLDLN2,	FLDZ,
-	FLDCW,
-	FLDENV,
-	FMULD,	FMULS,	FMULP,	FIMULL,	FIMULS,
-	FNOP,
-	FPATAN,
-	FPREM,
-	FPREM1,
-	FPTAN,
-	FRNDINT,
-	FRSTOR,
-	FSAVE,
-	FSCALE,
-	FSIN,
-	FSINCOS,
-	FSQRT,
-	FSTD,	FSTS,	FSTPX,	FSTPD,	FSTPS,
-	FSTCW,
-	FSTENV,
-	FSTSW,
-	FSUBD,	FSUBS,	FSUBP,	FISUBL,	FISUBS,
-	FSUBRD,	FSUBRS,	FSUBPR,	FISUBRL, FISUBRS,
-	FTST,
-	FUCOM,	FUCOMP,	FUCOMPP,
-	FXAM,
-	FXCH,
-	FXTRACT,
-	FYL2X,
-	FYL2XP1,
-	HLT,
-	IDIV,
-	IMUL,
-	IN,
-	INC,
-	INS,
-	INT,	INTO,
-	INVD,
-	INVLPG,
-	IRET,	IRETD,
-	JA,	JAE,	JB,	JBE,	JCXZ,	JE,	JG,	JGE,	JL,
-	JLE,	JNE,	JNO,	JNP,	JNS,	JO,	JP,	JS,
-	JMP,	JMPF,			/* JMPF added */
-	LAHF,
-	LAR,
-	LEA,
-	LEAVE,
-	LGDT,	LIDT,
-	LGS,	LSS,	LDS,	LES,	LFS,
-	LLDT,
-	LMSW,
-	LOCK,
-	LODS,
-	LOOP,	LOOPE,	LOOPNE,
-	LSL,
-	LTR,
-	MOV,
-	MOVS,
-	MOVSX,
-	MOVSXB,
-	MOVZX,
-	MOVZXB,
-	MUL,
-	NEG,
-	NOP,
-	NOT,
-	OR,
-	OUT,
-	OUTS,
-	POP,
-	POPA,
-	POPF,
-	PUSH,
-	PUSHA,
-	PUSHF,
-	RCL,	RCR,	ROL,	ROR,
-	RET,	RETF,			/* RETF added */
-	SAHF,
-	SAL,	SAR,	SHL,	SHR,
-	SBB,
-	SCAS,
-	SETA,	SETAE,	SETB,	SETBE,	SETE,	SETG,	SETGE,	SETL,
-	SETLE,	SETNE,	SETNO,	SETNP,	SETNS,	SETO,	SETP,	SETS,
-	SGDT,	SIDT,
-	SHLD,
-	SHRD,
-	SLDT,
-	SMSW,
-	STC,
-	STD,
-	STI,
-	STOS,
-	STR,
-	SUB,
-	TEST,
-	VERR,	VERW,
-	WAIT,
-	WBINVD,
-	XADD,
-	XCHG,
-	XLAT,
-	XOR
-} opcode_t;
-
-#define is_pseudo(o)	((o) <= DOT_USE32)
-#define N_OPCODES	((int) XOR + 1)
-
-#define OPZ	0x01		/* Operand size prefix. */
-#define ADZ	0x02		/* Address size prefix. */
-
-typedef enum optype {
-	PSEUDO,	JUMP,	BYTE,	WORD,	OWORD		/* Ordered list! */
-} optype_t;
-
-typedef enum repeat {
-	ONCE,	REP,	REPE,	REPNE
-} repeat_t;
-
-typedef enum segment {
-	DEFSEG,	CSEG,	DSEG,	ESEG,	FSEG,	GSEG,	SSEG
-} segment_t;
-
-typedef struct expression {
-	int		operator;
-	struct expression *left, *middle, *right;
-	char		*name;
-	size_t		len;
-	unsigned	magic;
-} expression_t;
-
-typedef struct asm86 {
-	opcode_t	opcode;		/* DOT_TEXT, MOV, ... */
-	char		*file;		/* Name of the file it is found in. */
-	long		line;		/* Line number. */
-	optype_t	optype;		/* Type of operands: byte, word... */
-	int		oaz;		/* Operand/address size prefix? */
-	repeat_t	rep;		/* Repeat prefix used on this instr. */
-	segment_t	seg;		/* Segment override. */
-	expression_t	*args;		/* Arguments in ACK order. */
-	unsigned	magic;
-} asm86_t;
-
-expression_t *new_expr(void);
-void del_expr(expression_t *a);
-asm86_t *new_asm86(void);
-void del_asm86(asm86_t *a);
-int isregister(const char *name);
-
-/*
- * Format of the arguments of the asm86_t structure:
- *
- *
- * ACK assembly operands	expression_t cell:
- * or part of operand:		{operator, left, middle, right, name, len}
- *
- * [expr]			{'[', nil, expr, nil}
- * word				{'W', nil, nil, nil, word}
- * "string"			{'S', nil, nil, nil, "string", strlen("string")}
- * label = expr			{'=', nil, expr, nil, label}
- * expr * expr			{'*', expr, nil, expr}
- * - expr			{'-', nil, expr, nil}
- * (memory)			{'(', nil, memory, nil}
- * offset(base)(index*n)	{'O', offset, base, index*n}
- * base				{'B', nil, nil, nil, base}
- * index*4			{'4', nil, nil, nil, index}
- * operand, oplist		{',', operand, nil, oplist}
- * label :			{':', nil, nil, nil, label}
- *
- * The precedence of operators is ignored.  The expression is simply copied
- * as is, including parentheses.  Problems like missing operators in the
- * target language will have to be handled by rewriting the source language.
- * 16-bit or 32-bit registers must be used where they are required by the
- * target assembler even though ACK makes no difference between 'ax' and
- * 'eax'.  Asmconv is smart enough to transform compiler output.  Human made
- * assembly can be fixed up to be transformable.
- */
Index: trunk/minix/commands/i386/asmconv/asmconv.c
===================================================================
--- trunk/minix/commands/i386/asmconv/asmconv.c	(revision 9)
+++ 	(revision )
@@ -1,157 +1,0 @@
-/*	asmconv 1.11 - convert 80X86 assembly		Author: Kees J. Bot
- *								24 Dec 1993
- */
-static char version[] = "1.11";
-
-#define nil 0
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include "asmconv.h"
-#include "asm86.h"
-#include "languages.h"
-
-void fatal(char *label)
-{
-	fprintf(stderr, "asmconv: %s: %s\n", label, strerror(errno));
-	exit(EXIT_FAILURE);
-}
-
-void *allocate(void *mem, size_t size)
-/* A checked malloc/realloc().  Yes, I know ISO C allows realloc(NULL, size). */
-{
-	mem= mem == nil ? malloc(size) : realloc(mem, size);
-	if (mem == nil) fatal("malloc()");
-	return mem;
-}
-
-void deallocate(void *mem)
-/* Free a malloc()d cell.  (Yes I know ISO C allows free(NULL) */
-{
-	if (mem != nil) free(mem);
-}
-
-char *copystr(const char *s)
-{
-	char *c;
-
-	c= allocate(nil, (strlen(s) + 1) * sizeof(s[0]));
-	strcpy(c, s);
-	return c;
-}
-
-int isanumber(const char *s)
-/* True if s can be turned into a number. */
-{
-	char *end;
-
-	(void) strtol(s, &end, 0);
-	return end != s && *end == 0;
-}
-
-/* "Invisible" globals. */
-int asm_mode32= (sizeof(int) == 4);
-int err_code= EXIT_SUCCESS;
-
-int main(int argc, char **argv)
-{
-	void (*parse_init)(char *file);
-	asm86_t *(*get_instruction)(void);
-	void (*emit_init)(char *file, const char *banner);
-	void (*emit_instruction)(asm86_t *instr);
-	char *lang_parse, *lang_emit, *input_file, *output_file;
-	asm86_t *instr;
-	char banner[80];
-
-	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'm') {
-		if (strcmp(argv[1], "-mi86") == 0) {
-			set_use16();
-		} else
-		if (strcmp(argv[1], "-mi386") == 0) {
-			set_use32();
-		} else {
-			fprintf(stderr, "asmconv: '%s': unknown machine\n",
-				argv[1]+2);
-		}
-		argc--;
-		argv++;
-	}
-
-	if (argc < 3 || argc > 5) {
-		fprintf(stderr,
-"Usage: asmconv <input-type> <output-type> [input-file [output-file]]\n");
-		exit(EXIT_FAILURE);
-	}
-
-	lang_parse= argv[1];
-	lang_emit= argv[2];
-	input_file= argc < 4 ? nil : argv[3];
-	output_file= argc < 5 ? nil : argv[4];
-
-	/* Choose the parsing routines. */
-	if (strcmp(lang_parse, "ack") == 0) {
-		/* Standard ACK. */
-		parse_init= ack_parse_init;
-		get_instruction= ack_get_instruction;
-	} else
-	if (strcmp(lang_parse, "ncc") == 0) {
-		/* ACK Xenix assembly, a black sheep among ACK assemblies. */
-		parse_init= ncc_parse_init;
-		get_instruction= ncc_get_instruction;
-	} else
-	if (strcmp(lang_parse, "gnu") == 0) {
-		/* GNU assembly.  Parser by R.S. Veldema. */
-		parse_init= gnu_parse_init;
-		get_instruction= gnu_get_instruction;
-	} else
-	if (strcmp(lang_parse, "bas") == 0) {
-		/* Bruce Evans' assembler. */
-		parse_init= bas_parse_init;
-		get_instruction= bas_get_instruction;
-	} else {
-		fprintf(stderr, "asmconv: '%s': unknown input language\n",
-			lang_parse);
-		exit(EXIT_FAILURE);
-	}
-
-	/* Choose the output language. */
-	if (strcmp(lang_emit, "ack") == 0) {
-		/* Standard ACK. */
-		emit_init= ack_emit_init;
-		emit_instruction= ack_emit_instruction;
-	} else
-	if (strcmp(lang_emit, "ncc") == 0) {
-		/* ACK Xenix assembly, can be read by BAS and the 8086 ACK
-		 * ANSI C compiler.  (Allows us to compile the Boot Monitor.)
-		 */
-		emit_init= ncc_emit_init;
-		emit_instruction= ncc_emit_instruction;
-	} else
-	if (strcmp(lang_emit, "gnu") == 0) {
-		/* GNU assembler.  So we can assemble the ACK stuff among the
-		 * kernel sources and in the library.
-		 */
-		emit_init= gnu_emit_init;
-		emit_instruction= gnu_emit_instruction;
-	} else {
-		fprintf(stderr, "asmconv: '%s': unknown output language\n",
-			lang_emit);
-		exit(EXIT_FAILURE);
-	}
-
-	sprintf(banner, "Translated from %s to %s by asmconv %s",
-					lang_parse, lang_emit, version);
-
-	(*parse_init)(input_file);
-	(*emit_init)(output_file, banner);
-	for (;;) {
-		instr= (*get_instruction)();
-		(*emit_instruction)(instr);
-		if (instr == nil) break;
-		del_asm86(instr);
-	}
-	exit(err_code);
-}
Index: trunk/minix/commands/i386/asmconv/asmconv.h
===================================================================
--- trunk/minix/commands/i386/asmconv/asmconv.h	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-/*	asmconv.h - shared functions			Author: Kees J. Bot
- *								19 Dec 1993
- */
-
-#define arraysize(a)	(sizeof(a)/sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-#define between(a, c, z)	\
-			((unsigned)((c) - (a)) <= (unsigned)((z) - (a)))
-
-void *allocate(void *mem, size_t size);
-void deallocate(void *mem);
-void fatal(char *label);
-char *copystr(const char *s);
-int isanumber(const char *s);
-
-extern int asm_mode32;	/* In 32 bit mode if true. */
-
-#define use16()		(!asm_mode32)
-#define use32()		((int) asm_mode32)
-#define set_use16()	((void) (asm_mode32= 0))
-#define set_use32()	((void) (asm_mode32= 1))
-
-extern int err_code;	/* Exit code. */
-#define set_error()	((void) (err_code= EXIT_FAILURE))
Index: trunk/minix/commands/i386/asmconv/build
===================================================================
--- trunk/minix/commands/i386/asmconv/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/i386/asmconv/emit_ack.c
===================================================================
--- trunk/minix/commands/i386/asmconv/emit_ack.c	(revision 9)
+++ 	(revision )
@@ -1,621 +1,0 @@
-/*	emit_ack.c - emit ACK assembly			Author: Kees J. Bot
- *		     emit NCC assembly				27 Dec 1993
- */
-#define nil 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <assert.h>
-#include "asmconv.h"
-#include "token.h"
-#include "asm86.h"
-#include "languages.h"
-
-typedef struct mnemonic {	/* ACK as86 mnemonics translation table. */
-	opcode_t	opcode;
-	char		*name;
-} mnemonic_t;
-
-static mnemonic_t mnemtab[] = {
-	{ AAA,		"aaa"		},
-	{ AAD,		"aad"		},
-	{ AAM,		"aam"		},
-	{ AAS,		"aas"		},
-	{ ADC,		"adc%"		},
-	{ ADD,		"add%"		},
-	{ AND,		"and%"		},
-	{ ARPL,		"arpl"		},
-	{ BOUND,	"bound"		},
-	{ BSF,		"bsf"		},
-	{ BSR,		"bsr"		},
-	{ BSWAP,	"bswap"		},
-	{ BT,		"bt"		},
-	{ BTC,		"btc"		},
-	{ BTR,		"btr"		},
-	{ BTS,		"bts"		},
-	{ CALL,		"call"		},
-	{ CALLF,	"callf"		},
-	{ CBW,		"cbw"		},
-	{ CLC,		"clc"		},
-	{ CLD,		"cld"		},
-	{ CLI,		"cli"		},
-	{ CLTS,		"clts"		},
-	{ CMC,		"cmc"		},
-	{ CMP,		"cmp%"		},
-	{ CMPS,		"cmps%"		},
-	{ CMPXCHG,	"cmpxchg"	},
-	{ CWD,		"cwd"		},
-	{ DAA,		"daa"		},
-	{ DAS,		"das"		},
-	{ DEC,		"dec%"		},
-	{ DIV,		"div%"		},
-	{ DOT_ALIGN,	".align"	},
-	{ DOT_ASCII,	".ascii"	},
-	{ DOT_ASCIZ,	".asciz"	},
-	{ DOT_ASSERT,	".assert"	},
-	{ DOT_BASE,	".base"		},
-	{ DOT_BSS,	".sect .bss"	},
-	{ DOT_COMM,	".comm"		},
-	{ DOT_DATA,	".sect .data"	},
-	{ DOT_DATA1,	".data1"	},
-	{ DOT_DATA2,	".data2"	},
-	{ DOT_DATA4,	".data4"	},
-	{ DOT_DEFINE,	".define"	},
-	{ DOT_END,	".sect .end"	},
-	{ DOT_EXTERN,	".extern"	},
-	{ DOT_FILE,	".file"		},
-	{ DOT_LCOMM,	".comm"		},
-	{ DOT_LINE,	".line"		},
-	{ DOT_LIST,	".list"		},
-	{ DOT_NOLIST,	".nolist"	},
-	{ DOT_ROM,	".sect .rom"	},
-	{ DOT_SPACE,	".space"	},
-	{ DOT_SYMB,	".symb"		},
-	{ DOT_TEXT,	".sect .text"	},
-	{ DOT_USE16,	".use16"	},
-	{ DOT_USE32,	".use32"	},
-	{ ENTER,	"enter"		},
-	{ F2XM1,	"f2xm1"		},
-	{ FABS,		"fabs"		},
-	{ FADD,		"fadd"		},
-	{ FADDD,	"faddd"		},
-	{ FADDP,	"faddp"		},
-	{ FADDS,	"fadds"		},
-	{ FBLD,		"fbld"		},
-	{ FBSTP,	"fbstp"		},
-	{ FCHS,		"fchs"		},
-	{ FCLEX,	"fclex"		},
-	{ FCOMD,	"fcomd"		},
-	{ FCOMPD,	"fcompd"	},
-	{ FCOMPP,	"fcompp"	},
-	{ FCOMPS,	"fcomps"	},
-	{ FCOMS,	"fcoms"		},
-	{ FCOS,		"fcos"		},
-	{ FDECSTP,	"fdecstp"	},
-	{ FDIVD,	"fdivd"		},
-	{ FDIVP,	"fdivp"		},
-	{ FDIVRD,	"fdivrd"	},
-	{ FDIVRP,	"fdivrp"	},
-	{ FDIVRS,	"fdivrs"	},
-	{ FDIVS,	"fdivs"		},
-	{ FFREE,	"ffree"		},
-	{ FIADDL,	"fiaddl"	},
-	{ FIADDS,	"fiadds"	},
-	{ FICOM,	"ficom"		},
-	{ FICOMP,	"ficomp"	},
-	{ FIDIVL,	"fidivl"	},
-	{ FIDIVRL,	"fidivrl"	},
-	{ FIDIVRS,	"fidivrs"	},
-	{ FIDIVS,	"fidivs"	},
-	{ FILDL,	"fildl"		},
-	{ FILDQ,	"fildq"		},
-	{ FILDS,	"filds"		},
-	{ FIMULL,	"fimull"	},
-	{ FIMULS,	"fimuls"	},
-	{ FINCSTP,	"fincstp"	},
-	{ FINIT,	"finit"		},
-	{ FISTL,	"fistl"		},
-	{ FISTP,	"fistp"		},
-	{ FISTS,	"fists"		},
-	{ FISUBL,	"fisubl"	},
-	{ FISUBRL,	"fisubrl"	},
-	{ FISUBRS,	"fisubrs"	},
-	{ FISUBS,	"fisubs"	},
-	{ FLD1,		"fld1"		},
-	{ FLDCW,	"fldcw"		},
-	{ FLDD,		"fldd"		},
-	{ FLDENV,	"fldenv"	},
-	{ FLDL2E,	"fldl2e"	},
-	{ FLDL2T,	"fldl2t"	},
-	{ FLDLG2,	"fldlg2"	},
-	{ FLDLN2,	"fldln2"	},
-	{ FLDPI,	"fldpi"		},
-	{ FLDS,		"flds"		},
-	{ FLDX,		"fldx"		},
-	{ FLDZ,		"fldz"		},
-	{ FMULD,	"fmuld"		},
-	{ FMULP,	"fmulp"		},
-	{ FMULS,	"fmuls"		},
-	{ FNOP,		"fnop"		},
-	{ FPATAN,	"fpatan"	},
-	{ FPREM,	"fprem"		},
-	{ FPREM1,	"fprem1"	},
-	{ FPTAN,	"fptan"		},
-	{ FRNDINT,	"frndint"	},
-	{ FRSTOR,	"frstor"	},
-	{ FSAVE,	"fsave"		},
-	{ FSCALE,	"fscale"	},
-	{ FSIN,		"fsin"		},
-	{ FSINCOS,	"fsincos"	},
-	{ FSQRT,	"fsqrt"		},
-	{ FSTCW,	"fstcw"		},
-	{ FSTD,		"fstd"		},
-	{ FSTENV,	"fstenv"	},
-	{ FSTPD,	"fstpd"		},
-	{ FSTPS,	"fstps"		},
-	{ FSTPX,	"fstpx"		},
-	{ FSTS,		"fsts"		},
-	{ FSTSW,	"fstsw"		},
-	{ FSUBD,	"fsubd"		},
-	{ FSUBP,	"fsubp"		},
-	{ FSUBPR,	"fsubpr"	},
-	{ FSUBRD,	"fsubrd"	},
-	{ FSUBRS,	"fsubrs"	},
-	{ FSUBS,	"fsubs"		},
-	{ FTST,		"ftst"		},
-	{ FUCOM,	"fucom"		},
-	{ FUCOMP,	"fucomp"	},
-	{ FUCOMPP,	"fucompp"	},
-	{ FXAM,		"fxam"		},
-	{ FXCH,		"fxch"		},
-	{ FXTRACT,	"fxtract"	},
-	{ FYL2X,	"fyl2x"		},
-	{ FYL2XP1,	"fyl2xp1"	},
-	{ HLT,		"hlt"		},
-	{ IDIV,		"idiv%"		},
-	{ IMUL,		"imul%"		},
-	{ IN,		"in%"		},
-	{ INC,		"inc%"		},
-	{ INS,		"ins%"		},
-	{ INT,		"int"		},
-	{ INTO,		"into"		},
-	{ INVD,		"invd"		},
-	{ INVLPG,	"invlpg"	},
-	{ IRET,		"iret"		},
-	{ IRETD,	"iretd"		},
-	{ JA,		"ja"		},
-	{ JAE,		"jae"		},
-	{ JB,		"jb"		},
-	{ JBE,		"jbe"		},
-	{ JCXZ,		"jcxz"		},
-	{ JE,		"je"		},
-	{ JG,		"jg"		},
-	{ JGE,		"jge"		},
-	{ JL,		"jl"		},
-	{ JLE,		"jle"		},
-	{ JMP,		"jmp"		},
-	{ JMPF,		"jmpf"		},
-	{ JNE,		"jne"		},
-	{ JNO,		"jno"		},
-	{ JNP,		"jnp"		},
-	{ JNS,		"jns"		},
-	{ JO,		"jo"		},
-	{ JP,		"jp"		},
-	{ JS,		"js"		},
-	{ LAHF,		"lahf"		},
-	{ LAR,		"lar"		},
-	{ LDS,		"lds"		},
-	{ LEA,		"lea"		},
-	{ LEAVE,	"leave"		},
-	{ LES,		"les"		},
-	{ LFS,		"lfs"		},
-	{ LGDT,		"lgdt"		},
-	{ LGS,		"lgs"		},
-	{ LIDT,		"lidt"		},
-	{ LLDT,		"lldt"		},
-	{ LMSW,		"lmsw"		},
-	{ LOCK,		"lock"		},
-	{ LODS,		"lods%"		},
-	{ LOOP,		"loop"		},
-	{ LOOPE,	"loope"		},
-	{ LOOPNE,	"loopne"	},
-	{ LSL,		"lsl"		},
-	{ LSS,		"lss"		},
-	{ LTR,		"ltr"		},
-	{ MOV,		"mov%"		},
-	{ MOVS,		"movs%"		},
-	{ MOVSX,	"movsx"		},
-	{ MOVSXB,	"movsxb"	},
-	{ MOVZX,	"movzx"		},
-	{ MOVZXB,	"movzxb"	},
-	{ MUL,		"mul%"		},
-	{ NEG,		"neg%"		},
-	{ NOP,		"nop"		},
-	{ NOT,		"not%"		},
-	{ OR,		"or%"		},
-	{ OUT,		"out%"		},
-	{ OUTS,		"outs%"		},
-	{ POP,		"pop"		},
-	{ POPA,		"popa"		},
-	{ POPF,		"popf"		},
-	{ PUSH,		"push"		},
-	{ PUSHA,	"pusha"		},
-	{ PUSHF,	"pushf"		},
-	{ RCL,		"rcl%"		},
-	{ RCR,		"rcr%"		},
-	{ RET,		"ret"		},
-	{ RETF,		"retf"		},
-	{ ROL,		"rol%"		},
-	{ ROR,		"ror%"		},
-	{ SAHF,		"sahf"		},
-	{ SAL,		"sal%"		},
-	{ SAR,		"sar%"		},
-	{ SBB,		"sbb%"		},
-	{ SCAS,		"scas%"		},
-	{ SETA,		"seta"		},
-	{ SETAE,	"setae"		},
-	{ SETB,		"setb"		},
-	{ SETBE,	"setbe"		},
-	{ SETE,		"sete"		},
-	{ SETG,		"setg"		},
-	{ SETGE,	"setge"		},
-	{ SETL,		"setl"		},
-	{ SETLE,	"setle"		},
-	{ SETNE,	"setne"		},
-	{ SETNO,	"setno"		},
-	{ SETNP,	"setnp"		},
-	{ SETNS,	"setns"		},
-	{ SETO,		"seto"		},
-	{ SETP,		"setp"		},
-	{ SETS,		"sets"		},
-	{ SGDT,		"sgdt"		},
-	{ SHL,		"shl%"		},
-	{ SHLD,		"shld"		},
-	{ SHR,		"shr%"		},
-	{ SHRD,		"shrd"		},
-	{ SIDT,		"sidt"		},
-	{ SLDT,		"sldt"		},
-	{ SMSW,		"smsw"		},
-	{ STC,		"stc"		},
-	{ STD,		"std"		},
-	{ STI,		"sti"		},
-	{ STOS,		"stos%"		},
-	{ STR,		"str"		},
-	{ SUB,		"sub%"		},
-	{ TEST,		"test%"		},
-	{ VERR,		"verr"		},
-	{ VERW,		"verw"		},
-	{ WAIT,		"wait"		},
-	{ WBINVD,	"wbinvd"	},
-	{ XADD,		"xadd"		},
-	{ XCHG,		"xchg%"		},
-	{ XLAT,		"xlat"		},
-	{ XOR,		"xor%"		},
-};
-
-#define farjmp(o)	((o) == JMPF || (o) == CALLF)
-
-static FILE *ef;
-static long eline= 1;
-static char *efile;
-static char *orig_efile;
-static char *opcode2name_tab[N_OPCODES];
-static enum dialect { ACK, NCC } dialect= ACK;
-
-static void ack_putchar(int c)
-/* LOOK, this programmer checks the return code of putc!  What an idiot, noone
- * does that!
- */
-{
-	if (putc(c, ef) == EOF) fatal(orig_efile);
-}
-
-static void ack_printf(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	if (vfprintf(ef, fmt, ap) == EOF) fatal(orig_efile);
-	va_end(ap);
-}
-
-void ack_emit_init(char *file, const char *banner)
-/* Prepare producing an ACK assembly file. */
-{
-	mnemonic_t *mp;
-
-	if (file == nil) {
-		file= "stdout";
-		ef= stdout;
-	} else {
-		if ((ef= fopen(file, "w")) == nil) fatal(file);
-	}
-	orig_efile= file;
-	efile= file;
-	ack_printf("! %s", banner);
-	if (dialect == ACK) {
-		/* Declare the four sections used under Minix. */
-		ack_printf(
-	"\n.sect .text; .sect .rom; .sect .data; .sect .bss\n.sect .text");
-	}
-
-	/* Initialize the opcode to mnemonic translation table. */
-	for (mp= mnemtab; mp < arraylimit(mnemtab); mp++) {
-		assert(opcode2name_tab[mp->opcode] == nil);
-		opcode2name_tab[mp->opcode]= mp->name;
-	}
-}
-
-#define opcode2name(op)		(opcode2name_tab[op] + 0)
-
-static void ack_put_string(const char *s, size_t n)
-/* Emit a string with weird characters quoted. */
-{
-	while (n > 0) {
-		int c= *s;
-
-		if (c < ' ' || c > 0177) {
-			ack_printf("\\%03o", c & 0xFF);
-		} else
-		if (c == '"' || c == '\\') {
-			ack_printf("\\%c", c);
-		} else {
-			ack_putchar(c);
-		}
-		s++;
-		n--;
-	}
-}
-
-static void ack_put_expression(asm86_t *a, expression_t *e, int deref)
-/* Send an expression, i.e. instruction operands, to the output file.  Deref
- * is true when the rewrite for the ncc dialect may be made.
- */
-{
-	assert(e != nil);
-
-	switch (e->operator) {
-	case ',':
-		if (dialect == NCC && farjmp(a->opcode)) {
-			/* ACK jmpf seg:off  ->  NCC jmpf off,seg */
-			ack_put_expression(a, e->right, deref);
-			ack_printf(", ");
-			ack_put_expression(a, e->left, deref);
-		} else {
-			ack_put_expression(a, e->left, deref);
-			ack_printf(farjmp(a->opcode) ? ":" : ", ");
-			ack_put_expression(a, e->right, deref);
-		}
-		break;
-	case 'O':
-		if (deref && a->optype == JUMP) ack_putchar('@');
-		if (e->left != nil) ack_put_expression(a, e->left, 0);
-		if (e->middle != nil) ack_put_expression(a, e->middle, 0);
-		if (e->right != nil) ack_put_expression(a, e->right, 0);
-		break;
-	case '(':
-		if (deref && a->optype == JUMP) ack_putchar('@');
-		if (!deref) ack_putchar('(');
-		ack_put_expression(a, e->middle, 0);
-		if (!deref) ack_putchar(')');
-		break;
-	case 'B':
-		ack_printf("(%s)", e->name);
-		break;
-	case '1':
-	case '2':
-	case '4':
-	case '8':
-		ack_printf((use16() && e->operator == '1')
-				? "(%s)" : "(%s*%c)", e->name, e->operator);
-		break;
-	case '+':
-	case '-':
-	case '~':
-		if (e->middle != nil) {
-			if (deref && a->optype != JUMP) ack_putchar('#');
-			ack_putchar(e->operator);
-			ack_put_expression(a, e->middle, 0);
-			break;
-		}
-		/*FALL THROUGH*/
-	case '*':
-	case '/':
-	case '%':
-	case '&':
-	case '|':
-	case '^':
-	case S_LEFTSHIFT:
-	case S_RIGHTSHIFT:
-		if (deref && a->optype != JUMP) ack_putchar('#');
-		ack_put_expression(a, e->left, 0);
-		if (e->operator == S_LEFTSHIFT) {
-			ack_printf("<<");
-		} else
-		if (e->operator == S_RIGHTSHIFT) {
-			ack_printf(">>");
-		} else {
-			ack_putchar(e->operator);
-		}
-		ack_put_expression(a, e->right, 0);
-		break;
-	case '[':
-		if (deref && a->optype != JUMP) ack_putchar('#');
-		ack_putchar('[');
-		ack_put_expression(a, e->middle, 0);
-		ack_putchar(']');
-		break;
-	case 'W':
-		if (deref && a->optype == JUMP && isregister(e->name))
-		{
-			ack_printf("(%s)", e->name);
-			break;
-		}
-		if (deref && a->optype != JUMP && !isregister(e->name)) {
-			ack_putchar('#');
-		}
-		ack_printf("%s", e->name);
-		break;
-	case 'S':
-		ack_putchar('"');
-		ack_put_string(e->name, e->len);
-		ack_putchar('"');
-		break;
-	default:
-		fprintf(stderr,
-		"asmconv: internal error, unknown expression operator '%d'\n",
-			e->operator);
-		exit(EXIT_FAILURE);
-	}
-}
-
-void ack_emit_instruction(asm86_t *a)
-/* Output one instruction and its operands. */
-{
-	int same= 0;
-	char *p;
-	static int high_seg;
-	int deref;
-
-	if (a == nil) {
-		/* Last call */
-		ack_putchar('\n');
-		return;
-	}
-
-	/* Make sure the line number of the line to be emitted is ok. */
-	if ((a->file != efile && strcmp(a->file, efile) != 0)
-				|| a->line < eline || a->line > eline+10) {
-		ack_putchar('\n');
-		ack_printf("# %ld \"%s\"\n", a->line, a->file);
-		efile= a->file;
-		eline= a->line;
-	} else {
-		if (a->line == eline) {
-			ack_printf("; ");
-			same= 1;
-		}
-		while (eline < a->line) {
-			ack_putchar('\n');
-			eline++;
-		}
-	}
-
-	if (a->opcode == DOT_LABEL) {
-		assert(a->args->operator == ':');
-		ack_printf("%s:", a->args->name);
-	} else
-	if (a->opcode == DOT_EQU) {
-		assert(a->args->operator == '=');
-		ack_printf("\t%s = ", a->args->name);
-		ack_put_expression(a, a->args->middle, 0);
-	} else
-	if ((p= opcode2name(a->opcode)) != nil) {
-		char *sep= dialect == ACK ? "" : ";";
-
-		if (!is_pseudo(a->opcode) && !same) ack_putchar('\t');
-
-		switch (a->rep) {
-		case ONCE:	break;
-		case REP:	ack_printf("rep");	break;
-		case REPE:	ack_printf("repe");	break;
-		case REPNE:	ack_printf("repne");	break;
-		default:	assert(0);
-		}
-		if (a->rep != ONCE) {
-			ack_printf(dialect == ACK ? " " : "; ");
-		}
-		switch (a->seg) {
-		case DEFSEG:	break;
-		case CSEG:	ack_printf("cseg");	break;
-		case DSEG:	ack_printf("dseg");	break;
-		case ESEG:	ack_printf("eseg");	break;
-		case FSEG:	ack_printf("fseg");	break;
-		case GSEG:	ack_printf("gseg");	break;
-		case SSEG:	ack_printf("sseg");	break;
-		default:	assert(0);
-		}
-		if (a->seg != DEFSEG) {
-			ack_printf(dialect == ACK ? " " : "; ");
-		}
-		if (a->oaz & OPZ) ack_printf(use16() ? "o32 " : "o16 ");
-		if (a->oaz & ADZ) ack_printf(use16() ? "a32 " : "a16 ");
-
-		if (a->opcode == CBW) {
-			p= !(a->oaz & OPZ) == use16() ? "cbw" : "cwde";
-		}
-
-		if (a->opcode == CWD) {
-			p= !(a->oaz & OPZ) == use16() ? "cwd" : "cdq";
-		}
-
-		if (a->opcode == DOT_COMM && a->args != nil
-			&& a->args->operator == ','
-			&& a->args->left->operator == 'W'
-		) {
-			ack_printf(".define\t%s; ", a->args->left->name);
-		}
-		while (*p != 0) {
-			if (*p == '%') {
-				if (a->optype == BYTE) ack_putchar('b');
-			} else {
-				ack_putchar(*p);
-			}
-			p++;
-		}
-		if (a->args != nil) {
-			ack_putchar('\t');
-			switch (a->opcode) {
-			case IN:
-			case OUT:
-			case INT:
-				deref= 0;
-				break;
-			default:
-				deref= (dialect == NCC && a->optype != PSEUDO);
-			}
-			ack_put_expression(a, a->args, deref);
-		}
-		if (a->opcode == DOT_USE16) set_use16();
-		if (a->opcode == DOT_USE32) set_use32();
-	} else {
-		fprintf(stderr,
-			"asmconv: internal error, unknown opcode '%d'\n",
-			a->opcode);
-		exit(EXIT_FAILURE);
-	}
-}
-
-/* A few ncc mnemonics are different. */
-static mnemonic_t ncc_mnemtab[] = {
-	{ DOT_BSS,	".bss"		},
-	{ DOT_DATA,	".data"		},
-	{ DOT_END,	".end"		},
-	{ DOT_ROM,	".rom"		},
-	{ DOT_TEXT,	".text"		},
-};
-
-void ncc_emit_init(char *file, const char *banner)
-/* The assembly produced by the Minix ACK ANSI C compiler for the 8086 is
- * different from the normal ACK assembly, and different from the old K&R
- * assembler.  This brings us endless joy.  (It was supposed to make
- * translation of the assembly used by the old K&R assembler easier by
- * not deviating too much from that dialect.)
- */
-{
-	mnemonic_t *mp;
-
-	dialect= NCC;
-	ack_emit_init(file, banner);
-
-	/* Replace a few mnemonics. */
-	for (mp= ncc_mnemtab; mp < arraylimit(ncc_mnemtab); mp++) {
-		opcode2name_tab[mp->opcode]= mp->name;
-	}
-}
-
-void ncc_emit_instruction(asm86_t *a)
-{
-	ack_emit_instruction(a);
-}
Index: trunk/minix/commands/i386/asmconv/emit_gnu.c
===================================================================
--- trunk/minix/commands/i386/asmconv/emit_gnu.c	(revision 9)
+++ 	(revision )
@@ -1,674 +1,0 @@
-/*	emit_gnu.c - emit GNU assembly			Author: Kees J. Bot
- *								28 Dec 1993
- */
-#define nil 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <assert.h>
-#include "asmconv.h"
-#include "token.h"
-#include "asm86.h"
-#include "languages.h"
-
-typedef struct mnemonic {	/* GNU as386 mnemonics translation table. */
-	opcode_t	opcode;
-	char		*name;
-} mnemonic_t;
-
-static mnemonic_t mnemtab[] = {
-	{ AAA,		"aaa"		},
-	{ AAD,		"aad"		},
-	{ AAM,		"aam"		},
-	{ AAS,		"aas"		},
-	{ ADC,		"adc%"		},
-	{ ADD,		"add%"		},
-	{ AND,		"and%"		},
-	{ ARPL,		"arpl"		},
-	{ BOUND,	"bound%"	},
-	{ BSF,		"bsf%"		},
-	{ BSR,		"bsr%"		},
-	{ BSWAP,	"bswap"		},
-	{ BT,		"bt%"		},
-	{ BTC,		"btc%"		},
-	{ BTR,		"btr%"		},
-	{ BTS,		"bts%"		},
-	{ CALL,		"call"		},
-	{ CALLF,	"lcall"		},
-	{ CBW,		"cbtw"		},
-	{ CLC,		"clc"		},
-	{ CLD,		"cld"		},
-	{ CLI,		"cli"		},
-	{ CLTS,		"clts"		},
-	{ CMC,		"cmc"		},
-	{ CMP,		"cmp%"		},
-	{ CMPS,		"cmps%"		},
-	{ CMPXCHG,	"cmpxchg"	},
-	{ CWD,		"cwtd"		},
-	{ DAA,		"daa"		},
-	{ DAS,		"das"		},
-	{ DEC,		"dec%"		},
-	{ DIV,		"div%"		},
-	{ DOT_ALIGN,	".align"	},
-	{ DOT_ASCII,	".ascii"	},
-	{ DOT_ASCIZ,	".asciz"	},
-	{ DOT_ASSERT,	".assert"	},
-	{ DOT_BASE,	".base"		},
-	{ DOT_BSS,	".bss"		},
-	{ DOT_COMM,	".comm"		},
-	{ DOT_DATA,	".data"		},
-	{ DOT_DATA1,	".byte"		},
-	{ DOT_DATA2,	".short"	},
-	{ DOT_DATA4,	".long"		},
-	{ DOT_DEFINE,	".globl"	},
-	{ DOT_EXTERN,	".globl"	},
-	{ DOT_FILE,	".file"		},
-	{ DOT_LCOMM,	".lcomm"	},
-	{ DOT_LINE,	".line"		},
-	{ DOT_LIST,	".list"		},
-	{ DOT_NOLIST,	".nolist"	},
-	{ DOT_ROM,	".data"		},	/* Minix -- separate I&D. */
-	{ DOT_SPACE,	".space"	},
-	{ DOT_SYMB,	".symb"		},
-	{ DOT_TEXT,	".text"		},
-	{ DOT_USE16,	".use16"	},
-	{ DOT_USE32,	".use32"	},
-	{ ENTER,	"enter"		},
-	{ F2XM1,	"f2xm1"		},
-	{ FABS,		"fabs"		},
-	{ FADD,		"fadd"		},
-	{ FADDD,	"faddl"		},
-	{ FADDP,	"faddp"		},
-	{ FADDS,	"fadds"		},
-	{ FBLD,		"fbld"		},
-	{ FBSTP,	"fbstp"		},
-	{ FCHS,		"fchs"		},
-	{ FCLEX,	"fnclex"	},
-	{ FCOMD,	"fcoml"		},
-	{ FCOMPD,	"fcompl"	},
-	{ FCOMPP,	"fcompp"	},
-	{ FCOMPS,	"fcomps"	},
-	{ FCOMS,	"fcoms"		},
-	{ FCOS,		"fcos"		},
-	{ FDECSTP,	"fdecstp"	},
-	{ FDIVD,	"fdivl"		},
-	{ FDIVP,	"fdivp"		},
-	{ FDIVRD,	"fdivrl"	},
-	{ FDIVRP,	"fdivrp"	},
-	{ FDIVRS,	"fdivrs"	},
-	{ FDIVS,	"fdivs"		},
-	{ FFREE,	"ffree"		},
-	{ FIADDL,	"fiaddl"	},
-	{ FIADDS,	"fiadds"	},
-	{ FICOM,	"ficom"		},
-	{ FICOMP,	"ficomp"	},
-	{ FIDIVL,	"fidivl"	},
-	{ FIDIVRL,	"fidivrl"	},
-	{ FIDIVRS,	"fidivrs"	},
-	{ FIDIVS,	"fidivs"	},
-	{ FILDL,	"fildl"		},
-	{ FILDQ,	"fildq"		},
-	{ FILDS,	"filds"		},
-	{ FIMULL,	"fimull"	},
-	{ FIMULS,	"fimuls"	},
-	{ FINCSTP,	"fincstp"	},
-	{ FINIT,	"fninit"	},
-	{ FISTL,	"fistl"		},
-	{ FISTP,	"fistp"		},
-	{ FISTS,	"fists"		},
-	{ FISUBL,	"fisubl"	},
-	{ FISUBRL,	"fisubrl"	},
-	{ FISUBRS,	"fisubrs"	},
-	{ FISUBS,	"fisubs"	},
-	{ FLD1,		"fld1"		},
-	{ FLDCW,	"fldcw"		},
-	{ FLDD,		"fldl"		},
-	{ FLDENV,	"fldenv"	},
-	{ FLDL2E,	"fldl2e"	},
-	{ FLDL2T,	"fldl2t"	},
-	{ FLDLG2,	"fldlg2"	},
-	{ FLDLN2,	"fldln2"	},
-	{ FLDPI,	"fldpi"		},
-	{ FLDS,		"flds"		},
-	{ FLDX,		"fldt"		},
-	{ FLDZ,		"fldz"		},
-	{ FMULD,	"fmull"		},
-	{ FMULP,	"fmulp"		},
-	{ FMULS,	"fmuls"		},
-	{ FNOP,		"fnop"		},
-	{ FPATAN,	"fpatan"	},
-	{ FPREM,	"fprem"		},
-	{ FPREM1,	"fprem1"	},
-	{ FPTAN,	"fptan"		},
-	{ FRNDINT,	"frndint"	},
-	{ FRSTOR,	"frstor"	},
-	{ FSAVE,	"fnsave"	},
-	{ FSCALE,	"fscale"	},
-	{ FSIN,		"fsin"		},
-	{ FSINCOS,	"fsincos"	},
-	{ FSQRT,	"fsqrt"		},
-	{ FSTCW,	"fnstcw"	},
-	{ FSTD,		"fstl"		},
-	{ FSTENV,	"fnstenv"	},
-	{ FSTPD,	"fstpl"		},
-	{ FSTPS,	"fstps"		},
-	{ FSTPX,	"fstpt"		},
-	{ FSTS,		"fsts"		},
-	{ FSTSW,	"fstsw"		},
-	{ FSUBD,	"fsubl"		},
-	{ FSUBP,	"fsubp"		},
-	{ FSUBPR,	"fsubpr"	},
-	{ FSUBRD,	"fsubrl"	},
-	{ FSUBRS,	"fsubrs"	},
-	{ FSUBS,	"fsubs"		},
-	{ FTST,		"ftst"		},
-	{ FUCOM,	"fucom"		},
-	{ FUCOMP,	"fucomp"	},
-	{ FUCOMPP,	"fucompp"	},
-	{ FXAM,		"fxam"		},
-	{ FXCH,		"fxch"		},
-	{ FXTRACT,	"fxtract"	},
-	{ FYL2X,	"fyl2x"		},
-	{ FYL2XP1,	"fyl2xp1"	},
-	{ HLT,		"hlt"		},
-	{ IDIV,		"idiv%"		},
-	{ IMUL,		"imul%"		},
-	{ IN,		"in%"		},
-	{ INC,		"inc%"		},
-	{ INS,		"ins%"		},
-	{ INT,		"int"		},
-	{ INTO,		"into"		},
-	{ INVD,		"invd"		},
-	{ INVLPG,	"invlpg"	},
-	{ IRET,		"iret"		},
-	{ IRETD,	"iret"		},
-	{ JA,		"ja"		},
-	{ JAE,		"jae"		},
-	{ JB,		"jb"		},
-	{ JBE,		"jbe"		},
-	{ JCXZ,		"jcxz"		},
-	{ JE,		"je"		},
-	{ JG,		"jg"		},
-	{ JGE,		"jge"		},
-	{ JL,		"jl"		},
-	{ JLE,		"jle"		},
-	{ JMP,		"jmp"		},
-	{ JMPF,		"ljmp"		},
-	{ JNE,		"jne"		},
-	{ JNO,		"jno"		},
-	{ JNP,		"jnp"		},
-	{ JNS,		"jns"		},
-	{ JO,		"jo"		},
-	{ JP,		"jp"		},
-	{ JS,		"js"		},
-	{ LAHF,		"lahf"		},
-	{ LAR,		"lar"		},
-	{ LDS,		"lds"		},
-	{ LEA,		"lea%"		},
-	{ LEAVE,	"leave"		},
-	{ LES,		"les"		},
-	{ LFS,		"lfs"		},
-	{ LGDT,		"lgdt"		},
-	{ LGS,		"lgs"		},
-	{ LIDT,		"lidt"		},
-	{ LLDT,		"lldt"		},
-	{ LMSW,		"lmsw"		},
-	{ LOCK,		"lock"		},
-	{ LODS,		"lods%"		},
-	{ LOOP,		"loop"		},
-	{ LOOPE,	"loope"		},
-	{ LOOPNE,	"loopne"	},
-	{ LSL,		"lsl"		},
-	{ LSS,		"lss"		},
-	{ LTR,		"ltr"		},
-	{ MOV,		"mov%"		},
-	{ MOVS,		"movs%"		},
-	{ MOVSX,	"movswl"	},
-	{ MOVSXB,	"movsb%"	},
-	{ MOVZX,	"movzwl"	},
-	{ MOVZXB,	"movzb%"	},
-	{ MUL,		"mul%"		},
-	{ NEG,		"neg%"		},
-	{ NOP,		"nop"		},
-	{ NOT,		"not%"		},
-	{ OR,		"or%"		},
-	{ OUT,		"out%"		},
-	{ OUTS,		"outs%"		},
-	{ POP,		"pop%"		},
-	{ POPA,		"popa%"		},
-	{ POPF,		"popf%"		},
-	{ PUSH,		"push%"		},
-	{ PUSHA,	"pusha%"	},
-	{ PUSHF,	"pushf%"	},
-	{ RCL,		"rcl%"		},
-	{ RCR,		"rcr%"		},
-	{ RET,		"ret"		},
-	{ RETF,		"lret"		},
-	{ ROL,		"rol%"		},
-	{ ROR,		"ror%"		},
-	{ SAHF,		"sahf"		},
-	{ SAL,		"sal%"		},
-	{ SAR,		"sar%"		},
-	{ SBB,		"sbb%"		},
-	{ SCAS,		"scas%"		},
-	{ SETA,		"setab"		},
-	{ SETAE,	"setaeb"	},
-	{ SETB,		"setbb"		},
-	{ SETBE,	"setbeb"	},
-	{ SETE,		"seteb"		},
-	{ SETG,		"setgb"		},
-	{ SETGE,	"setgeb"	},
-	{ SETL,		"setlb"		},
-	{ SETLE,	"setleb"	},
-	{ SETNE,	"setneb"	},
-	{ SETNO,	"setnob"	},
-	{ SETNP,	"setnpb"	},
-	{ SETNS,	"setnsb"	},
-	{ SETO,		"setob"		},
-	{ SETP,		"setpb"		},
-	{ SETS,		"setsb"		},
-	{ SGDT,		"sgdt"		},
-	{ SHL,		"shl%"		},
-	{ SHLD,		"shld%"		},
-	{ SHR,		"shr%"		},
-	{ SHRD,		"shrd%"		},
-	{ SIDT,		"sidt"		},
-	{ SLDT,		"sldt"		},
-	{ SMSW,		"smsw"		},
-	{ STC,		"stc"		},
-	{ STD,		"std"		},
-	{ STI,		"sti"		},
-	{ STOS,		"stos%"		},
-	{ STR,		"str"		},
-	{ SUB,		"sub%"		},
-	{ TEST,		"test%"		},
-	{ VERR,		"verr"		},
-	{ VERW,		"verw"		},
-	{ WAIT,		"wait"		},
-	{ WBINVD,	"wbinvd"	},
-	{ XADD,		"xadd"		},
-	{ XCHG,		"xchg%"		},
-	{ XLAT,		"xlat"		},
-	{ XOR,		"xor%"		},
-};
-
-static FILE *ef;
-static long eline= 1;
-static char *efile;
-static char *orig_efile;
-static char *opcode2name_tab[N_OPCODES];
-
-static void gnu_putchar(int c)
-/* LOOK, this programmer checks the return code of putc!  What an idiot, noone
- * does that!
- */
-{
-	if (putc(c, ef) == EOF) fatal(orig_efile);
-}
-
-static void gnu_printf(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	if (vfprintf(ef, fmt, ap) == EOF) fatal(orig_efile);
-	va_end(ap);
-}
-
-void gnu_emit_init(char *file, const char *banner)
-/* Prepare producing a GNU assembly file. */
-{
-	mnemonic_t *mp;
-
-	if (file == nil) {
-		file= "stdout";
-		ef= stdout;
-	} else {
-		if ((ef= fopen(file, "w")) == nil) fatal(file);
-	}
-	orig_efile= file;
-	efile= file;
-	gnu_printf("/ %s", banner);
-
-	/* Initialize the opcode to mnemonic translation table. */
-	for (mp= mnemtab; mp < arraylimit(mnemtab); mp++) {
-		assert(opcode2name_tab[mp->opcode] == nil);
-		opcode2name_tab[mp->opcode]= mp->name;
-	}
-}
-
-#define opcode2name(op)		(opcode2name_tab[op] + 0)
-
-static void gnu_put_string(const char *s, size_t n)
-/* Emit a string with weird characters quoted. */
-{
-	while (n > 0) {
-		int c= *s;
-
-		if (c < ' ' || c > 0177) {
-			gnu_printf("\\%03o", c);
-		} else
-		if (c == '"' || c == '\\') {
-			gnu_printf("\\%c", c & 0xFF);
-		} else {
-			gnu_putchar(c);
-		}
-		s++;
-		n--;
-	}
-}
-
-static void gnu_put_expression(asm86_t *a, expression_t *e, int deref)
-/* Send an expression, i.e. instruction operands, to the output file.  Deref
- * is true when the rewrite of "x" -> "#x" or "(x)" -> "x" may be made.
- */
-{
-	assert(e != nil);
-
-	switch (e->operator) {
-	case ',':
-		if (is_pseudo(a->opcode)) {
-			/* Pseudo's are normal. */
-			gnu_put_expression(a, e->left, deref);
-			gnu_printf(", ");
-			gnu_put_expression(a, e->right, deref);
-		} else {
-			/* He who invented GNU assembly has seen one VAX too
-			 * many, operands are given in the wrong order.  This
-			 * makes coding from an Intel databook a real delight.
-			 * A good thing this program allows us to write the
-			 * more normal ACK assembly.
-			 */
-			gnu_put_expression(a, e->right, deref);
-			gnu_printf(", ");
-			gnu_put_expression(a, e->left, deref);
-		}
-		break;
-	case 'O':
-		if (deref && a->optype == JUMP) gnu_putchar('*');
-		if (e->left != nil) gnu_put_expression(a, e->left, 0);
-		gnu_putchar('(');
-		if (e->middle != nil) gnu_put_expression(a, e->middle, 0);
-		if (e->right != nil) {
-			gnu_putchar(',');
-			gnu_put_expression(a, e->right, 0);
-		}
-		gnu_putchar(')');
-		break;
-	case '(':
-		if (!deref) gnu_putchar('(');
-		if (deref && a->optype == JUMP) gnu_putchar('*');
-		gnu_put_expression(a, e->middle, 0);
-		if (!deref) gnu_putchar(')');
-		break;
-	case 'B':
-		gnu_printf("%%%s", e->name);
-		break;
-	case '1':
-	case '2':
-	case '4':
-	case '8':
-		gnu_printf("%%%s,%c", e->name, e->operator);
-		break;
-	case '+':
-	case '-':
-	case '~':
-		if (e->middle != nil) {
-			if (deref && a->optype >= BYTE) gnu_putchar('$');
-			gnu_putchar(e->operator);
-			gnu_put_expression(a, e->middle, 0);
-			break;
-		}
-		/*FALL THROUGH*/
-	case '*':
-	case '/':
-	case '%':
-	case '&':
-	case '|':
-	case '^':
-	case S_LEFTSHIFT:
-	case S_RIGHTSHIFT:
-		if (deref && a->optype >= BYTE) gnu_putchar('$');
-		gnu_put_expression(a, e->left, 0);
-		if (e->operator == S_LEFTSHIFT) {
-			gnu_printf("<<");
-		} else
-		if (e->operator == S_RIGHTSHIFT) {
-			gnu_printf(">>");
-		} else {
-			gnu_putchar(e->operator);
-		}
-		gnu_put_expression(a, e->right, 0);
-		break;
-	case '[':
-		if (deref && a->optype >= BYTE) gnu_putchar('$');
-		gnu_putchar('(');
-		gnu_put_expression(a, e->middle, 0);
-		gnu_putchar(')');
-		break;
-	case 'W':
-		if (isregister(e->name)) {
-			if (a->optype == JUMP) gnu_putchar('*');
-			gnu_printf("%%%s", e->name);
-		} else {
-			if (deref && a->optype >= BYTE) gnu_putchar('$');
-			gnu_printf("%s", e->name);
-		}
-		break;
-	case 'S':
-		gnu_putchar('"');
-		gnu_put_string(e->name, e->len);
-		gnu_putchar('"');
-		break;
-	default:
-		fprintf(stderr,
-		"asmconv: internal error, unknown expression operator '%d'\n",
-			e->operator);
-		exit(EXIT_FAILURE);
-	}
-}
-
-void gnu_emit_instruction(asm86_t *a)
-/* Output one instruction and its operands. */
-{
-	int same= 0;
-	char *p;
-
-	if (a == nil) {
-		/* Last call */
-		gnu_putchar('\n');
-		return;
-	}
-
-	if (use16()) {
-		fprintf(stderr,
-		"asmconv: the GNU assembler can't translate 8086 code\n");
-		exit(EXIT_FAILURE);
-	}
-
-	/* Make sure the line number of the line to be emitted is ok. */
-	if ((a->file != efile && strcmp(a->file, efile) != 0)
-				|| a->line < eline || a->line > eline+10) {
-		gnu_putchar('\n');
-		gnu_printf("# %ld \"%s\"\n", a->line, a->file);
-		efile= a->file;
-		eline= a->line;
-	} else {
-		if (a->line == eline) {
-			gnu_printf("; ");
-			same= 1;
-		}
-		while (eline < a->line) {
-			gnu_putchar('\n');
-			eline++;
-		}
-	}
-
-	if (a->opcode == DOT_LABEL) {
-		assert(a->args->operator == ':');
-		gnu_printf("%s:", a->args->name);
-	} else
-	if (a->opcode == DOT_EQU) {
-		assert(a->args->operator == '=');
-		gnu_printf("\t%s = ", a->args->name);
-		gnu_put_expression(a, a->args->middle, 0);
-	} else
-	if (a->opcode == DOT_ALIGN) {
-		/* GNU .align thinks in powers of two. */
-		unsigned long n;
-		unsigned s;
-
-		assert(a->args->operator == 'W' && isanumber(a->args->name));
-		n= strtoul(a->args->name, nil, 0);
-		for (s= 0; s <= 4 && (1 << s) < n; s++) {}
-		gnu_printf(".align\t%u", s);
-	} else
-	if ((p= opcode2name(a->opcode)) != nil) {
-		if (!is_pseudo(a->opcode) && !same) gnu_putchar('\t');
-
-		switch (a->rep) {
-		case ONCE:	break;
-		case REP:	gnu_printf("rep; ");	break;
-		case REPE:	gnu_printf("repe; ");	break;
-		case REPNE:	gnu_printf("repne; ");	break;
-		default:	assert(0);
-		}
-		switch (a->seg) {
-		/* Kludge to avoid knowing where to put the "%es:" */
-		case DEFSEG:	break;
-		case CSEG:	gnu_printf(".byte 0x2e; ");	break;
-		case DSEG:	gnu_printf(".byte 0x3e; ");	break;
-		case ESEG:	gnu_printf(".byte 0x26; ");	break;
-		case FSEG:	gnu_printf(".byte 0x64; ");	break;
-		case GSEG:	gnu_printf(".byte 0x65; ");	break;
-		case SSEG:	gnu_printf(".byte 0x36; ");	break;
-		default:	assert(0);
-		}
-
-		/* Exceptions, exceptions... */
-		if (a->opcode == CBW) {
-			if (!(a->oaz & OPZ)) p= "cwtl";
-			a->oaz&= ~OPZ;
-		}
-		if (a->opcode == CWD) {
-			if (!(a->oaz & OPZ)) p= "cltd";
-			a->oaz&= ~OPZ;
-		}
-
-		if (a->opcode == RET || a->opcode == RETF) {
-			/* Argument of RET needs a '$'. */
-			a->optype= WORD;
-		}
-
-		if (a->opcode == MUL && a->args != nil
-						&& a->args->operator == ',') {
-			/* Two operand MUL is an IMUL? */
-			p="imul%";
-		}
-
-		/* GAS doesn't understand the interesting combinations. */
-		if (a->oaz & ADZ) gnu_printf(".byte 0x67; ");
-		if (a->oaz & OPZ && strchr(p, '%') == nil)
-			gnu_printf(".byte 0x66; ");
-
-		/* Unsupported instructions that Minix code needs. */
-		if (a->opcode == JMPF && a->args != nil
-					&& a->args->operator == ',') {
-			/* JMPF seg:off. */
-			gnu_printf(".byte 0xEA; .long ");
-			gnu_put_expression(a, a->args->right, 0);
-			gnu_printf("; .short ");
-			gnu_put_expression(a, a->args->left, 0);
-			return;
-		}
-		if (a->opcode == JMPF && a->args != nil
-			&& a->args->operator == 'O'
-			&& a->args->left != nil
-			&& a->args->right == nil
-			&& a->args->middle != nil
-			&& a->args->middle->operator == 'B'
-			&& strcmp(a->args->middle->name, "esp") == 0
-		) {
-			/* JMPF offset(ESP). */
-			gnu_printf(".byte 0xFF,0x6C,0x24,");
-			gnu_put_expression(a, a->args->left, 0);
-			return;
-		}
-		if (a->opcode == MOV && a->args != nil
-			&& a->args->operator == ','
-			&& a->args->left != nil
-			&& a->args->left->operator == 'W'
-			&& (strcmp(a->args->left->name, "ds") == 0
-				|| strcmp(a->args->left->name, "es") == 0)
-			&& a->args->right->operator == 'O'
-			&& a->args->right->left != nil
-			&& a->args->right->right == nil
-			&& a->args->right->middle != nil
-			&& a->args->right->middle->operator == 'B'
-			&& strcmp(a->args->right->middle->name, "esp") == 0
-		) {
-			/* MOV DS, offset(ESP); MOV ES, offset(ESP) */
-			gnu_printf(".byte 0x8E,0x%02X,0x24,",
-				a->args->left->name[0] == 'd' ? 0x5C : 0x44);
-			gnu_put_expression(a, a->args->right->left, 0);
-			return;
-		}
-		if (a->opcode == MOV && a->args != nil
-			&& a->args->operator == ','
-			&& a->args->left != nil
-			&& a->args->left->operator == 'W'
-			&& (strcmp(a->args->left->name, "ds") == 0
-				|| strcmp(a->args->left->name, "es") == 0)
-			&& a->args->right->operator == '('
-			&& a->args->right->middle != nil
-		) {
-			/* MOV DS, (memory); MOV ES, (memory) */
-			gnu_printf(".byte 0x8E,0x%02X; .long ",
-				a->args->left->name[0] == 'd' ? 0x1D : 0x05);
-			gnu_put_expression(a, a->args->right->middle, 0);
-			return;
-		}
-
-		while (*p != 0) {
-			if (*p == '%') {
-				if (a->optype == BYTE) {
-					gnu_putchar('b');
-				} else
-				if (a->optype == WORD) {
-					gnu_putchar((a->oaz & OPZ) ? 'w' : 'l');
-				} else {
-					assert(0);
-				}
-			} else {
-				gnu_putchar(*p);
-			}
-			p++;
-		}
-
-		if (a->args != nil) {
-			static char *aregs[] = { "al", "ax", "eax" };
-
-			gnu_putchar('\t');
-			switch (a->opcode) {
-			case IN:
-				gnu_put_expression(a, a->args, 1);
-				gnu_printf(", %%%s", aregs[a->optype - BYTE]);
-				break;
-			case OUT:
-				gnu_printf("%%%s, ", aregs[a->optype - BYTE]);
-				gnu_put_expression(a, a->args, 1);
-				break;
-			default:
-				gnu_put_expression(a, a->args, 1);
-			}
-		}
-		if (a->opcode == DOT_USE16) set_use16();
-		if (a->opcode == DOT_USE32) set_use32();
-	} else {
-		fprintf(stderr,
-			"asmconv: internal error, unknown opcode '%d'\n",
-			a->opcode);
-		exit(EXIT_FAILURE);
-	}
-}
Index: trunk/minix/commands/i386/asmconv/languages.h
===================================================================
--- trunk/minix/commands/i386/asmconv/languages.h	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-/*	languages.h - functions that parse or emit assembly
- *							Author: Kees J. Bot
- *								27 Dec 1993
- */
-
-void ack_parse_init(char *file);
-asm86_t *ack_get_instruction(void);
-
-void ncc_parse_init(char *file);
-asm86_t *ncc_get_instruction(void);
-
-void gnu_parse_init(char *file);
-asm86_t *gnu_get_instruction(void);
-
-void bas_parse_init(char *file);
-asm86_t *bas_get_instruction(void);
-
-void ack_emit_init(char *file, const char *banner);
-void ack_emit_instruction(asm86_t *instr);
-
-void ncc_emit_init(char *file, const char *banner);
-void ncc_emit_instruction(asm86_t *instr);
-
-void gnu_emit_init(char *file, const char *banner);
-void gnu_emit_instruction(asm86_t *instr);
Index: trunk/minix/commands/i386/asmconv/parse_ack.c
===================================================================
--- trunk/minix/commands/i386/asmconv/parse_ack.c	(revision 9)
+++ 	(revision )
@@ -1,910 +1,0 @@
-/*	parse_ack.c - parse ACK assembly		Author: Kees J. Bot
- *		      parse NCC assembly			18 Dec 1993
- */
-#define nil 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include "asmconv.h"
-#include "token.h"
-#include "asm86.h"
-#include "languages.h"
-
-typedef struct mnemonic {	/* ACK as86 mnemonics translation table. */
-	char		*name;
-	opcode_t	opcode;
-	optype_t	optype;
-} mnemonic_t;
-
-static mnemonic_t mnemtab[] = {			/* This array is sorted. */
-	{ ".align",	DOT_ALIGN,	PSEUDO },
-	{ ".ascii",	DOT_ASCII,	PSEUDO },
-	{ ".asciz",	DOT_ASCIZ,	PSEUDO },
-	{ ".assert",	DOT_ASSERT,	PSEUDO },
-	{ ".base",	DOT_BASE,	PSEUDO },
-	{ ".bss",	DOT_BSS,	PSEUDO },
-	{ ".comm",	DOT_LCOMM,	PSEUDO },
-	{ ".data",	DOT_DATA,	PSEUDO },
-	{ ".data1",	DOT_DATA1,	PSEUDO },
-	{ ".data2",	DOT_DATA2,	PSEUDO },
-	{ ".data4",	DOT_DATA4,	PSEUDO },
-	{ ".define",	DOT_DEFINE,	PSEUDO },
-	{ ".end",	DOT_END,	PSEUDO },
-	{ ".extern",	DOT_EXTERN,	PSEUDO },
-	{ ".file",	DOT_FILE,	PSEUDO },
-	{ ".line",	DOT_LINE,	PSEUDO },
-	{ ".list",	DOT_LIST,	PSEUDO },
-	{ ".nolist",	DOT_NOLIST,	PSEUDO },
-	{ ".rom",	DOT_ROM,	PSEUDO },
-	{ ".space",	DOT_SPACE,	PSEUDO },
-	{ ".symb",	DOT_SYMB,	PSEUDO },
-	{ ".text",	DOT_TEXT,	PSEUDO },
-	{ ".use16",	DOT_USE16,	PSEUDO },
-	{ ".use32",	DOT_USE32,	PSEUDO },
-	{ "aaa",	AAA,		WORD },
-	{ "aad",	AAD,		WORD },
-	{ "aam",	AAM,		WORD },
-	{ "aas",	AAS,		WORD },
-	{ "adc",	ADC,		WORD },
-	{ "adcb",	ADC,		BYTE },
-	{ "add",	ADD,		WORD },
-	{ "addb",	ADD,		BYTE },
-	{ "and",	AND,		WORD },
-	{ "andb",	AND,		BYTE },
-	{ "arpl",	ARPL,		WORD },
-	{ "bound",	BOUND,		WORD },
-	{ "bsf",	BSF,		WORD },
-	{ "bsr",	BSR,		WORD },
-	{ "bswap",	BSWAP,		WORD },
-	{ "bt",		BT,		WORD },
-	{ "btc",	BTC,		WORD },
-	{ "btr",	BTR,		WORD },
-	{ "bts",	BTS,		WORD },
-	{ "call",	CALL,		JUMP },
-	{ "callf",	CALLF,		JUMP },
-	{ "cbw",	CBW,		WORD },
-	{ "cdq",	CWD,		WORD },
-	{ "clc",	CLC,		WORD },
-	{ "cld",	CLD,		WORD },
-	{ "cli",	CLI,		WORD },
-	{ "clts",	CLTS,		WORD },
-	{ "cmc",	CMC,		WORD },
-	{ "cmp",	CMP,		WORD },
-	{ "cmpb",	CMP,		BYTE },
-	{ "cmps",	CMPS,		WORD },
-	{ "cmpsb",	CMPS,		BYTE },
-	{ "cmpxchg",	CMPXCHG,	WORD },
-	{ "cwd",	CWD,		WORD },
-	{ "cwde",	CBW,		WORD },
-	{ "daa",	DAA,		WORD },
-	{ "das",	DAS,		WORD },
-	{ "dec",	DEC,		WORD },
-	{ "decb",	DEC,		BYTE },
-	{ "div",	DIV,		WORD },
-	{ "divb",	DIV,		BYTE },
-	{ "enter",	ENTER,		WORD },
-	{ "f2xm1",	F2XM1,		WORD },
-	{ "fabs",	FABS,		WORD },
-	{ "fadd",	FADD,		WORD },
-	{ "faddd",	FADDD,		WORD },
-	{ "faddp",	FADDP,		WORD },
-	{ "fadds",	FADDS,		WORD },
-	{ "fbld",	FBLD,		WORD },
-	{ "fbstp",	FBSTP,		WORD },
-	{ "fchs",	FCHS,		WORD },
-	{ "fclex",	FCLEX,		WORD },
-	{ "fcomd",	FCOMD,		WORD },
-	{ "fcompd",	FCOMPD,		WORD },
-	{ "fcompp",	FCOMPP,		WORD },
-	{ "fcomps",	FCOMPS,		WORD },
-	{ "fcoms",	FCOMS,		WORD },
-	{ "fcos",	FCOS,		WORD },
-	{ "fdecstp",	FDECSTP,	WORD },
-	{ "fdivd",	FDIVD,		WORD },
-	{ "fdivp",	FDIVP,		WORD },
-	{ "fdivrd",	FDIVRD,		WORD },
-	{ "fdivrp",	FDIVRP,		WORD },
-	{ "fdivrs",	FDIVRS,		WORD },
-	{ "fdivs",	FDIVS,		WORD },
-	{ "ffree",	FFREE,		WORD },
-	{ "fiaddl",	FIADDL,		WORD },
-	{ "fiadds",	FIADDS,		WORD },
-	{ "ficom",	FICOM,		WORD },
-	{ "ficomp",	FICOMP,		WORD },
-	{ "fidivl",	FIDIVL,		WORD },
-	{ "fidivrl",	FIDIVRL,	WORD },
-	{ "fidivrs",	FIDIVRS,	WORD },
-	{ "fidivs",	FIDIVS,		WORD },
-	{ "fildl",	FILDL,		WORD },
-	{ "fildq",	FILDQ,		WORD },
-	{ "filds",	FILDS,		WORD },
-	{ "fimull",	FIMULL,		WORD },
-	{ "fimuls",	FIMULS,		WORD },
-	{ "fincstp",	FINCSTP,	WORD },
-	{ "finit",	FINIT,		WORD },
-	{ "fistl",	FISTL,		WORD },
-	{ "fistp",	FISTP,		WORD },
-	{ "fists",	FISTS,		WORD },
-	{ "fisubl",	FISUBL,		WORD },
-	{ "fisubrl",	FISUBRL,	WORD },
-	{ "fisubrs",	FISUBRS,	WORD },
-	{ "fisubs",	FISUBS,		WORD },
-	{ "fld1",	FLD1,		WORD },
-	{ "fldcw",	FLDCW,		WORD },
-	{ "fldd",	FLDD,		WORD },
-	{ "fldenv",	FLDENV,		WORD },
-	{ "fldl2e",	FLDL2E,		WORD },
-	{ "fldl2t",	FLDL2T,		WORD },
-	{ "fldlg2",	FLDLG2,		WORD },
-	{ "fldln2",	FLDLN2,		WORD },
-	{ "fldpi",	FLDPI,		WORD },
-	{ "flds",	FLDS,		WORD },
-	{ "fldx",	FLDX,		WORD },
-	{ "fldz",	FLDZ,		WORD },
-	{ "fmuld",	FMULD,		WORD },
-	{ "fmulp",	FMULP,		WORD },
-	{ "fmuls",	FMULS,		WORD },
-	{ "fnop",	FNOP,		WORD },
-	{ "fpatan",	FPATAN,		WORD },
-	{ "fprem",	FPREM,		WORD },
-	{ "fprem1",	FPREM1,		WORD },
-	{ "fptan",	FPTAN,		WORD },
-	{ "frndint",	FRNDINT,	WORD },
-	{ "frstor",	FRSTOR,		WORD },
-	{ "fsave",	FSAVE,		WORD },
-	{ "fscale",	FSCALE,		WORD },
-	{ "fsin",	FSIN,		WORD },
-	{ "fsincos",	FSINCOS,	WORD },
-	{ "fsqrt",	FSQRT,		WORD },
-	{ "fstcw",	FSTCW,		WORD },
-	{ "fstd",	FSTD,		WORD },
-	{ "fstenv",	FSTENV,		WORD },
-	{ "fstpd",	FSTPD,		WORD },
-	{ "fstps",	FSTPS,		WORD },
-	{ "fstpx",	FSTPX,		WORD },
-	{ "fsts",	FSTS,		WORD },
-	{ "fstsw",	FSTSW,		WORD },
-	{ "fsubd",	FSUBD,		WORD },
-	{ "fsubp",	FSUBP,		WORD },
-	{ "fsubpr",	FSUBPR,		WORD },
-	{ "fsubrd",	FSUBRD,		WORD },
-	{ "fsubrs",	FSUBRS,		WORD },
-	{ "fsubs",	FSUBS,		WORD },
-	{ "ftst",	FTST,		WORD },
-	{ "fucom",	FUCOM,		WORD },
-	{ "fucomp",	FUCOMP,		WORD },
-	{ "fucompp",	FUCOMPP,	WORD },
-	{ "fxam",	FXAM,		WORD },
-	{ "fxch",	FXCH,		WORD },
-	{ "fxtract",	FXTRACT,	WORD },
-	{ "fyl2x",	FYL2X,		WORD },
-	{ "fyl2xp1",	FYL2XP1,	WORD },
-	{ "hlt",	HLT,		WORD },
-	{ "idiv",	IDIV,		WORD },
-	{ "idivb",	IDIV,		BYTE },
-	{ "imul",	IMUL,		WORD },
-	{ "imulb",	IMUL,		BYTE },
-	{ "in",		IN,		WORD },
-	{ "inb",	IN,		BYTE },
-	{ "inc",	INC,		WORD },
-	{ "incb",	INC,		BYTE },
-	{ "ins",	INS,		WORD },
-	{ "insb",	INS,		BYTE },
-	{ "int",	INT,		WORD },
-	{ "into",	INTO,		JUMP },
-	{ "invd",	INVD,		WORD },
-	{ "invlpg",	INVLPG,		WORD },
-	{ "iret",	IRET,		JUMP },
-	{ "iretd",	IRETD,		JUMP },
-	{ "ja",		JA,		JUMP },
-	{ "jae",	JAE,		JUMP },
-	{ "jb",		JB,		JUMP },
-	{ "jbe",	JBE,		JUMP },
-	{ "jc",		JB,		JUMP },
-	{ "jcxz",	JCXZ,		JUMP },
-	{ "je",		JE,		JUMP },
-	{ "jecxz",	JCXZ,		JUMP },
-	{ "jg",		JG,		JUMP },
-	{ "jge",	JGE,		JUMP },
-	{ "jl",		JL,		JUMP },
-	{ "jle",	JLE,		JUMP },
-	{ "jmp",	JMP,		JUMP },
-	{ "jmpf",	JMPF,		JUMP },
-	{ "jna",	JBE,		JUMP },
-	{ "jnae",	JB,		JUMP },
-	{ "jnb",	JAE,		JUMP },
-	{ "jnbe",	JA,		JUMP },
-	{ "jnc",	JAE,		JUMP },
-	{ "jne",	JNE,		JUMP },
-	{ "jng",	JLE,		JUMP },
-	{ "jnge",	JL,		JUMP },
-	{ "jnl",	JGE,		JUMP },
-	{ "jnle",	JG,		JUMP },
-	{ "jno",	JNO,		JUMP },
-	{ "jnp",	JNP,		JUMP },
-	{ "jns",	JNS,		JUMP },
-	{ "jnz",	JNE,		JUMP },
-	{ "jo",		JO,		JUMP },
-	{ "jp",		JP,		JUMP },
-	{ "js",		JS,		JUMP },
-	{ "jz",		JE,		JUMP },
-	{ "lahf",	LAHF,		WORD },
-	{ "lar",	LAR,		WORD },
-	{ "lds",	LDS,		WORD },
-	{ "lea",	LEA,		WORD },
-	{ "leave",	LEAVE,		WORD },
-	{ "les",	LES,		WORD },
-	{ "lfs",	LFS,		WORD },
-	{ "lgdt",	LGDT,		WORD },
-	{ "lgs",	LGS,		WORD },
-	{ "lidt",	LIDT,		WORD },
-	{ "lldt",	LLDT,		WORD },
-	{ "lmsw",	LMSW,		WORD },
-	{ "lock",	LOCK,		WORD },
-	{ "lods",	LODS,		WORD },
-	{ "lodsb",	LODS,		BYTE },
-	{ "loop",	LOOP,		JUMP },
-	{ "loope",	LOOPE,		JUMP },
-	{ "loopne",	LOOPNE,		JUMP },
-	{ "loopnz",	LOOPNE,		JUMP },
-	{ "loopz",	LOOPE,		JUMP },
-	{ "lsl",	LSL,		WORD },
-	{ "lss",	LSS,		WORD },
-	{ "ltr",	LTR,		WORD },
-	{ "mov",	MOV,		WORD },
-	{ "movb",	MOV,		BYTE },
-	{ "movs",	MOVS,		WORD },
-	{ "movsb",	MOVS,		BYTE },
-	{ "movsx",	MOVSX,		WORD },
-	{ "movsxb",	MOVSXB,		WORD },
-	{ "movzx",	MOVZX,		WORD },
-	{ "movzxb",	MOVZXB,		WORD },
-	{ "mul",	MUL,		WORD },
-	{ "mulb",	MUL,		BYTE },
-	{ "neg",	NEG,		WORD },
-	{ "negb",	NEG,		BYTE },
-	{ "nop",	NOP,		WORD },
-	{ "not",	NOT,		WORD },
-	{ "notb",	NOT,		BYTE },
-	{ "or",		OR,		WORD },
-	{ "orb",	OR,		BYTE },
-	{ "out",	OUT,		WORD },
-	{ "outb",	OUT,		BYTE },
-	{ "outs",	OUTS,		WORD },
-	{ "outsb",	OUTS,		BYTE },
-	{ "pop",	POP,		WORD },
-	{ "popa",	POPA,		WORD },
-	{ "popad",	POPA,		WORD },
-	{ "popf",	POPF,		WORD },
-	{ "push",	PUSH,		WORD },
-	{ "pusha",	PUSHA,		WORD },
-	{ "pushad",	PUSHA,		WORD },
-	{ "pushf",	PUSHF,		WORD },
-	{ "rcl",	RCL,		WORD },
-	{ "rclb",	RCL,		BYTE },
-	{ "rcr",	RCR,		WORD },
-	{ "rcrb",	RCR,		BYTE },
-	{ "ret",	RET,		JUMP },
-	{ "retf",	RETF,		JUMP },
-	{ "rol",	ROL,		WORD },
-	{ "rolb",	ROL,		BYTE },
-	{ "ror",	ROR,		WORD },
-	{ "rorb",	ROR,		BYTE },
-	{ "sahf",	SAHF,		WORD },
-	{ "sal",	SAL,		WORD },
-	{ "salb",	SAL,		BYTE },
-	{ "sar",	SAR,		WORD },
-	{ "sarb",	SAR,		BYTE },
-	{ "sbb",	SBB,		WORD },
-	{ "sbbb",	SBB,		BYTE },
-	{ "scas",	SCAS,		WORD },
-	{ "scasb",	SCAS,		BYTE },
-	{ "seta",	SETA,		BYTE },
-	{ "setae",	SETAE,		BYTE },
-	{ "setb",	SETB,		BYTE },
-	{ "setbe",	SETBE,		BYTE },
-	{ "sete",	SETE,		BYTE },
-	{ "setg",	SETG,		BYTE },
-	{ "setge",	SETGE,		BYTE },
-	{ "setl",	SETL,		BYTE },
-	{ "setna",	SETBE,		BYTE },
-	{ "setnae",	SETB,		BYTE },
-	{ "setnb",	SETAE,		BYTE },
-	{ "setnbe",	SETA,		BYTE },
-	{ "setne",	SETNE,		BYTE },
-	{ "setng",	SETLE,		BYTE },
-	{ "setnge",	SETL,		BYTE },
-	{ "setnl",	SETGE,		BYTE },
-	{ "setnle",	SETG,		BYTE },
-	{ "setno",	SETNO,		BYTE },
-	{ "setnp",	SETNP,		BYTE },
-	{ "setns",	SETNS,		BYTE },
-	{ "seto",	SETO,		BYTE },
-	{ "setp",	SETP,		BYTE },
-	{ "sets",	SETS,		BYTE },
-	{ "setz",	SETE,		BYTE },
-	{ "sgdt",	SGDT,		WORD },
-	{ "shl",	SHL,		WORD },
-	{ "shlb",	SHL,		BYTE },
-	{ "shld",	SHLD,		WORD },
-	{ "shr",	SHR,		WORD },
-	{ "shrb",	SHR,		BYTE },
-	{ "shrd",	SHRD,		WORD },
-	{ "sidt",	SIDT,		WORD },
-	{ "sldt",	SLDT,		WORD },
-	{ "smsw",	SMSW,		WORD },
-	{ "stc",	STC,		WORD },
-	{ "std",	STD,		WORD },
-	{ "sti",	STI,		WORD },
-	{ "stos",	STOS,		WORD },
-	{ "stosb",	STOS,		BYTE },
-	{ "str",	STR,		WORD },
-	{ "sub",	SUB,		WORD },
-	{ "subb",	SUB,		BYTE },
-	{ "test",	TEST,		WORD },
-	{ "testb",	TEST,		BYTE },
-	{ "verr",	VERR,		WORD },
-	{ "verw",	VERW,		WORD },
-	{ "wait",	WAIT,		WORD },
-	{ "wbinvd",	WBINVD,		WORD },
-	{ "xadd",	XADD,		WORD },
-	{ "xchg",	XCHG,		WORD },
-	{ "xchgb",	XCHG,		BYTE },
-	{ "xlat",	XLAT,		WORD },
-	{ "xor",	XOR,		WORD },
-	{ "xorb",	XOR,		BYTE },
-};
-
-static enum dialect { ACK, NCC } dialect= ACK;
-
-void ack_parse_init(char *file)
-/* Prepare parsing of an ACK assembly file. */
-{
-	tok_init(file, '!');
-}
-
-void ncc_parse_init(char *file)
-/* Prepare parsing of an ACK Xenix assembly file.  See emit_ack.c for comments
- * on this fine assembly dialect.
- */
-{
-	dialect= NCC;
-	ack_parse_init(file);
-}
-
-static void zap(void)
-/* An error, zap the rest of the line. */
-{
-	token_t *t;
-
-	while ((t= get_token(0))->type != T_EOF && t->symbol != ';')
-		skip_token(1);
-}
-
-static mnemonic_t *search_mnem(char *name)
-/* Binary search for a mnemonic.  (That's why the table is sorted.) */
-{
-	int low, mid, high;
-	int cmp;
-	mnemonic_t *m;
-
-	low= 0;
-	high= arraysize(mnemtab)-1;
-	while (low <= high) {
-		mid= (low + high) / 2;
-		m= &mnemtab[mid];
-
-		if ((cmp= strcmp(name, m->name)) == 0) return m;
-
-		if (cmp < 0) high= mid-1; else low= mid+1;
-	}
-	return nil;
-}
-
-static expression_t *ack_get_C_expression(int *pn)
-/* Read a "C-like" expression.  Note that we don't worry about precedence,
- * the expression is printed later like it is read.  If the target language
- * does not have all the operators (like ~) then this has to be repaired by
- * changing the source file.  (No problem, you still have one source file
- * to maintain, not two.)
- */
-{
-	expression_t *e, *a1, *a2;
-	token_t *t;
-
-	if ((t= get_token(*pn))->symbol == '[') {
-		/* [ expr ]: grouping. */
-		(*pn)++;
-		if ((a1= ack_get_C_expression(pn)) == nil) return nil;
-		if (get_token(*pn)->symbol != ']') {
-			parse_err(1, t, "missing ]\n");
-			del_expr(a1);
-			return nil;
-		}
-		(*pn)++;
-		e= new_expr();
-		e->operator= '[';
-		e->middle= a1;
-	} else
-	if (t->type == T_WORD || t->type == T_STRING) {
-		/* Label, number, or string. */
-		e= new_expr();
-		e->operator= t->type == T_WORD ? 'W' : 'S';
-		e->name= allocate(nil, (t->len+1) * sizeof(e->name[0]));
-		memcpy(e->name, t->name, t->len+1);
-		e->len= t->len;
-		(*pn)++;
-	} else
-	if (t->symbol == '+' || t->symbol == '-' || t->symbol == '~') {
-		/* Unary operator. */
-		(*pn)++;
-		if ((a1= ack_get_C_expression(pn)) == nil) return nil;
-		e= new_expr();
-		e->operator= t->symbol;
-		e->middle= a1;
-	} else {
-		parse_err(1, t, "expression syntax error\n");
-		return nil;
-	}
-
-	switch ((t= get_token(*pn))->symbol) {
-	case '+':
-	case '-':
-	case '*':
-	case '/':
-	case '%':
-	case '&':
-	case '|':
-	case '^':
-	case S_LEFTSHIFT:
-	case S_RIGHTSHIFT:
-		(*pn)++;
-		a1= e;
-		if ((a2= ack_get_C_expression(pn)) == nil) {
-			del_expr(a1);
-			return nil;
-		}
-		e= new_expr();
-		e->operator= t->symbol;
-		e->left= a1;
-		e->right= a2;
-	}
-	return e;
-}
-
-static expression_t *ack_get_operand(int *pn, int deref)
-/* Get something like: (memory), offset(base)(index*scale), or simpler. */
-{
-	expression_t *e, *offset, *base, *index;
-	token_t *t;
-	int c;
-
-	/* Is it (memory)? */
-	if (get_token(*pn)->symbol == '('
-		&& ((t= get_token(*pn + 1))->type != T_WORD
-			|| !isregister(t->name))
-	) {
-		/* A memory dereference. */
-		(*pn)++;
-		if ((offset= ack_get_C_expression(pn)) == nil) return nil;
-		if (get_token(*pn)->symbol != ')') {
-			parse_err(1, t, "operand syntax error\n");
-			del_expr(offset);
-			return nil;
-		}
-		(*pn)++;
-		e= new_expr();
-		e->operator= '(';
-		e->middle= offset;
-		return e;
-	}
-
-	/* #constant? */
-	if (dialect == NCC && deref
-			&& ((c= get_token(*pn)->symbol) == '#' || c == '*')) {
-		/* NCC: mov ax,#constant  ->  ACK: mov ax,constant */
-		(*pn)++;
-		return ack_get_C_expression(pn);
-	}
-
-	/* @address? */
-	if (dialect == NCC && get_token(*pn)->symbol == '@') {
-		/* NCC: jmp @address  ->  ACK: jmp (address) */
-		(*pn)++;
-		if ((offset= ack_get_operand(pn, deref)) == nil) return nil;
-		e= new_expr();
-		e->operator= '(';
-		e->middle= offset;
-		return e;
-	}
-
-	/* Offset? */
-	if (get_token(*pn)->symbol != '(') {
-		/* There is an offset. */
-		if ((offset= ack_get_C_expression(pn)) == nil) return nil;
-	} else {
-		/* No offset. */
-		offset= nil;
-	}
-
-	/* (base)? */
-	if (get_token(*pn)->symbol == '('
-		&& (t= get_token(*pn + 1))->type == T_WORD
-		&& isregister(t->name)
-		&& get_token(*pn + 2)->symbol == ')'
-	) {
-		/* A base register expression. */
-		base= new_expr();
-		base->operator= 'B';
-		base->name= copystr(t->name);
-		(*pn)+= 3;
-	} else {
-		/* No base register expression. */
-		base= nil;
-	}
-
-	/* (index*scale)? */
-	if (get_token(*pn)->symbol == '(') {
-		/* An index most likely. */
-		token_t *m= nil;
-
-		if (!(		/* This must be true: */
-			(t= get_token(*pn + 1))->type == T_WORD
-			&& isregister(t->name)
-			&& (get_token(*pn + 2)->symbol == ')' || (
-				get_token(*pn + 2)->symbol == '*'
-				&& (m= get_token(*pn + 3))->type == T_WORD
-				&& strchr("1248", m->name[0]) != nil
-				&& m->name[1] == 0
-				&& get_token(*pn + 4)->symbol == ')'
-			))
-		)) {
-			/* Alas it isn't */
-			parse_err(1, t, "operand syntax error\n");
-			del_expr(offset);
-			del_expr(base);
-			return nil;
-		}
-		/* Found an index. */
-		index= new_expr();
-		index->operator= m == nil ? '1' : m->name[0];
-		index->name= copystr(t->name);
-		(*pn)+= (m == nil ? 3 : 5);
-	} else {
-		/* No index. */
-		index= nil;
-	}
-
-	if (dialect == NCC && deref && base == nil && index == nil
-		&& !(offset != nil && offset->operator == 'W'
-					&& isregister(offset->name))
-	) {
-		/* NCC: mov ax,thing  ->  ACK mov ax,(thing) */
-		e= new_expr();
-		e->operator= '(';
-		e->middle= offset;
-		return e;
-	}
-
-	if (base == nil && index == nil) {
-		/* Return a lone offset as is. */
-		e= offset;
-	} else {
-		e= new_expr();
-		e->operator= 'O';
-		e->left= offset;
-		e->middle= base;
-		e->right= index;
-	}
-	return e;
-}
-
-static expression_t *ack_get_oplist(int *pn, int deref)
-/* Get a comma (or colon for jmpf and callf) separated list of instruction
- * operands.
- */
-{
-	expression_t *e, *o1, *o2;
-	token_t *t;
-
-	if ((e= ack_get_operand(pn, deref)) == nil) return nil;
-
-	if ((t= get_token(*pn))->symbol == ',' || t->symbol == ':') {
-		o1= e;
-		(*pn)++;
-		if ((o2= ack_get_oplist(pn, deref)) == nil) {
-			del_expr(o1);
-			return nil;
-		}
-		e= new_expr();
-		e->operator= ',';
-		e->left= o1;
-		e->right= o2;
-	}
-	return e;
-}
-
-static asm86_t *ack_get_statement(void)
-/* Get a pseudo op or machine instruction with arguments. */
-{
-	token_t *t= get_token(0);
-	asm86_t *a;
-	mnemonic_t *m;
-	int n;
-	int prefix_seen;
-	int oaz_prefix;
-	int deref;
-
-	assert(t->type == T_WORD);
-
-	if (strcmp(t->name, ".sect") == 0) {
-		/* .sect .text etc.  Accept only four segment names. */
-		skip_token(1);
-		t= get_token(0);
-		if (t->type != T_WORD || (
-			strcmp(t->name, ".text") != 0
-			&& strcmp(t->name, ".rom") != 0
-			&& strcmp(t->name, ".data") != 0
-			&& strcmp(t->name, ".bss") != 0
-			&& strcmp(t->name, ".end") != 0
-		)) {
-			parse_err(1, t, "weird section name to .sect\n");
-			return nil;
-		}
-	}
-	a= new_asm86();
-
-	/* Process instruction prefixes. */
-	oaz_prefix= 0;
-	for (prefix_seen= 0;; prefix_seen= 1) {
-		if (strcmp(t->name, "o16") == 0) {
-			if (use16()) {
-				parse_err(1, t, "o16 in an 8086 section\n");
-			}
-			oaz_prefix|= OPZ;
-		} else
-		if (strcmp(t->name, "o32") == 0) {
-			if (use32()) {
-				parse_err(1, t, "o32 in an 80386 section\n");
-			}
-			oaz_prefix|= OPZ;
-		} else
-		if (strcmp(t->name, "a16") == 0) {
-			if (use16()) {
-				parse_err(1, t, "a16 in an 8086 section\n");
-			}
-			oaz_prefix|= ADZ;
-		} else
-		if (strcmp(t->name, "a32") == 0) {
-			if (use32()) {
-				parse_err(1, t, "a32 in an 80386 section\n");
-			}
-			oaz_prefix|= ADZ;
-		} else
-		if (strcmp(t->name, "rep") == 0
-			|| strcmp(t->name, "repe") == 0
-			|| strcmp(t->name, "repne") == 0
-			|| strcmp(t->name, "repz") == 0
-			|| strcmp(t->name, "repnz") == 0
-		) {
-			if (a->rep != ONCE) {
-				parse_err(1, t,
-					"can't have more than one rep\n");
-			}
-			switch (t->name[3]) {
-			case 0:		a->rep= REP;	break;
-			case 'e':
-			case 'z':	a->rep= REPE;	break;
-			case 'n':	a->rep= REPNE;	break;
-			}
-		} else
-		if (strchr("cdefgs", t->name[0]) != nil
-					&& strcmp(t->name+1, "seg") == 0) {
-			if (a->seg != DEFSEG) {
-				parse_err(1, t,
-				"can't have more than one segment prefix\n");
-			}
-			switch (t->name[0]) {
-			case 'c':	a->seg= CSEG;	break;
-			case 'd':	a->seg= DSEG;	break;
-			case 'e':	a->seg= ESEG;	break;
-			case 'f':	a->seg= FSEG;	break;
-			case 'g':	a->seg= GSEG;	break;
-			case 's':	a->seg= SSEG;	break;
-			}
-		} else
-		if (!prefix_seen) {
-			/* No prefix here, get out! */
-			break;
-		} else {
-			/* No more prefixes, next must be an instruction. */
-			if (t->type != T_WORD
-				|| (m= search_mnem(t->name)) == nil
-				|| m->optype == PSEUDO
-			) {
-				parse_err(1, t,
-		"machine instruction expected after instruction prefix\n");
-				del_asm86(a);
-				return nil;
-			}
-			if (oaz_prefix != 0 && m->optype != JUMP
-						&& m->optype != WORD) {
-				parse_err(1, t,
-			"'%s' can't have an operand size prefix\n", m->name);
-			}
-			break;
-		}
-
-		/* Skip the prefix and extra newlines. */
-		do {
-			skip_token(1);
-		} while ((t= get_token(0))->symbol == ';');
-	}
-
-	/* All the readahead being done upsets the line counter. */
-	a->line= t->line;
-
-	/* Read a machine instruction or pseudo op. */
-	if ((m= search_mnem(t->name)) == nil) {
-		parse_err(1, t, "unknown instruction '%s'\n", t->name);
-		del_asm86(a);
-		return nil;
-	}
-	a->opcode= m->opcode;
-	a->optype= m->optype;
-	a->oaz= oaz_prefix;
-
-	switch (a->opcode) {
-	case IN:
-	case OUT:
-	case INT:
-		deref= 0;
-		break;
-	default:
-		deref= (a->optype >= BYTE);
-	}
-	n= 1;
-	if (get_token(1)->symbol != ';'
-			&& (a->args= ack_get_oplist(&n, deref)) == nil) {
-		del_asm86(a);
-		return nil;
-	}
-	if (get_token(n)->symbol != ';') {
-		parse_err(1, t, "garbage at end of instruction\n");
-		del_asm86(a);
-		return nil;
-	}
-	switch (a->opcode) {
-	case DOT_ALIGN:
-		/* Restrict .align to have a single numeric argument, some
-		 * assemblers think of the argument as a power of two, so
-		 * we need to be able to change the value.
-		 */
-		if (a->args == nil || a->args->operator != 'W'
-					|| !isanumber(a->args->name)) {
-			parse_err(1, t,
-			  ".align is restricted to one numeric argument\n");
-			del_asm86(a);
-			return nil;
-		}
-		break;
-	case JMPF:
-	case CALLF:
-		/* NCC jmpf off,seg  ->  ACK jmpf seg:off */
-		if (dialect == NCC && a->args != nil
-						&& a->args->operator == ',') {
-			expression_t *t;
-
-			t= a->args->left;
-			a->args->left= a->args->right;
-			a->args->right= t;
-			break;
-		}
-		/*FALL THROUGH*/
-	case JMP:
-	case CALL:
-		/* NCC jmp @(reg)  ->  ACK jmp (reg) */
-		if (dialect == NCC && a->args != nil && (
-			(a->args->operator == '('
-				&& a->args->middle != nil
-				&& a->args->middle->operator == 'O')
-			|| (a->args->operator == 'O'
-				&& a->args->left == nil
-				&& a->args->middle != nil
-				&& a->args->right == nil)
-		)) {
-			expression_t *t;
-
-			t= a->args;
-			a->args= a->args->middle;
-			t->middle= nil;
-			del_expr(t);
-			if (a->args->operator == 'B') a->args->operator= 'W';
-		}
-		break;
-	default:;
-	}
-	skip_token(n+1);
-	return a;
-}
-
-asm86_t *ack_get_instruction(void)
-{
-	asm86_t *a= nil;
-	expression_t *e;
-	token_t *t;
-
-	while ((t= get_token(0))->symbol == ';')
-		skip_token(1);
-
-	if (t->type == T_EOF) return nil;
-
-	if (t->symbol == '#') {
-		/* Preprocessor line and file change. */
-
-		if ((t= get_token(1))->type != T_WORD || !isanumber(t->name)
-			|| get_token(2)->type != T_STRING
-		) {
-			parse_err(1, t, "file not preprocessed?\n");
-			zap();
-		} else {
-			set_file(get_token(2)->name,
-				strtol(get_token(1)->name, nil, 0) - 1);
-
-			/* GNU CPP adds extra cruft, simply zap the line. */
-			zap();
-		}
-		a= ack_get_instruction();
-	} else
-	if (t->type == T_WORD && get_token(1)->symbol == ':') {
-		/* A label definition. */
-		a= new_asm86();
-		a->line= t->line;
-		a->opcode= DOT_LABEL;
-		a->optype= PSEUDO;
-		a->args= e= new_expr();
-		e->operator= ':';
-		e->name= copystr(t->name);
-		skip_token(2);
-	} else
-	if (t->type == T_WORD && get_token(1)->symbol == '=') {
-		int n= 2;
-
-		if ((e= ack_get_C_expression(&n)) == nil) {
-			zap();
-			a= ack_get_instruction();
-		} else
-		if (get_token(n)->symbol != ';') {
-			parse_err(1, t, "garbage after assignment\n");
-			zap();
-			a= ack_get_instruction();
-		} else {
-			a= new_asm86();
-			a->line= t->line;
-			a->opcode= DOT_EQU;
-			a->optype= PSEUDO;
-			a->args= new_expr();
-			a->args->operator= '=';
-			a->args->name= copystr(t->name);
-			a->args->middle= e;
-			skip_token(n+1);
-		}
-	} else
-	if (t->type == T_WORD) {
-		if ((a= ack_get_statement()) == nil) {
-			zap();
-			a= ack_get_instruction();
-		}
-	} else {
-		parse_err(1, t, "syntax error\n");
-		zap();
-		a= ack_get_instruction();
-	}
-	return a;
-}
-
-asm86_t *ncc_get_instruction(void)
-{
-	return ack_get_instruction();
-}
Index: trunk/minix/commands/i386/asmconv/parse_bas.c
===================================================================
--- trunk/minix/commands/i386/asmconv/parse_bas.c	(revision 9)
+++ 	(revision )
@@ -1,940 +1,0 @@
-/*	parse_bas.c - parse BCC AS assembly		Author: Kees J. Bot
- *								13 Nov 1994
- */
-#define nil 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include "asmconv.h"
-#include "token.h"
-#include "asm86.h"
-#include "languages.h"
-
-typedef struct mnemonic {	/* BAS mnemonics translation table. */
-	char		*name;
-	opcode_t	opcode;
-	optype_t	optype;
-} mnemonic_t;
-
-static mnemonic_t mnemtab[] = {			/* This array is sorted. */
-	{ ".align",	DOT_ALIGN,	PSEUDO },
-	{ ".ascii",	DOT_ASCII,	PSEUDO },
-	{ ".asciz",	DOT_ASCIZ,	PSEUDO },
-	{ ".assert",	DOT_ASSERT,	PSEUDO },
-	{ ".base",	DOT_BASE,	PSEUDO },
-	{ ".blkb",	DOT_SPACE,	PSEUDO },
-	{ ".bss",	DOT_BSS,	PSEUDO },
-	{ ".byte",	DOT_DATA1,	PSEUDO },
-	{ ".comm",	DOT_COMM,	PSEUDO },
-	{ ".data",	DOT_DATA,	PSEUDO },
-	{ ".define",	DOT_DEFINE,	PSEUDO },
-	{ ".end",	DOT_END,	PSEUDO },
-	{ ".even",	DOT_ALIGN,	PSEUDO },
-	{ ".extern",	DOT_EXTERN,	PSEUDO },
-	{ ".file",	DOT_FILE,	PSEUDO },
-	{ ".globl",	DOT_DEFINE,	PSEUDO },
-	{ ".lcomm",	DOT_LCOMM,	PSEUDO },
-	{ ".line",	DOT_LINE,	PSEUDO },
-	{ ".list",	DOT_LIST,	PSEUDO },
-	{ ".long",	DOT_DATA4,	PSEUDO },
-	{ ".nolist",	DOT_NOLIST,	PSEUDO },
-	{ ".rom",	DOT_ROM,	PSEUDO },
-	{ ".space",	DOT_SPACE,	PSEUDO },
-	{ ".symb",	DOT_SYMB,	PSEUDO },
-	{ ".text",	DOT_TEXT,	PSEUDO },
-	{ ".use16",	DOT_USE16,	PSEUDO },
-	{ ".use32",	DOT_USE32,	PSEUDO },
-	{ ".word",	DOT_DATA2,	PSEUDO },
-	{ ".zerob",	DOT_SPACE,	PSEUDO },
-	{ ".zerow",	DOT_SPACE,	PSEUDO },
-	{ "aaa",	AAA,		WORD },
-	{ "aad",	AAD,		WORD },
-	{ "aam",	AAM,		WORD },
-	{ "aas",	AAS,		WORD },
-	{ "adc",	ADC,		WORD },
-	{ "add",	ADD,		WORD },
-	{ "and",	AND,		WORD },
-	{ "arpl",	ARPL,		WORD },
-	{ "bc",		JB,		JUMP },
-	{ "beq",	JE,		JUMP },
-	{ "bge",	JGE,		JUMP },
-	{ "bgt",	JG,		JUMP },
-	{ "bhi",	JA,		JUMP },
-	{ "bhis",	JAE,		JUMP },
-	{ "ble",	JLE,		JUMP },
-	{ "blo",	JB,		JUMP },
-	{ "blos",	JBE,		JUMP },
-	{ "blt",	JL,		JUMP },
-	{ "bnc",	JAE,		JUMP },
-	{ "bne",	JNE,		JUMP },
-	{ "bound",	BOUND,		WORD },
-	{ "br",		JMP,		JUMP },
-	{ "bsf",	BSF,		WORD },
-	{ "bsr",	BSR,		WORD },
-	{ "bswap",	BSWAP,		WORD },
-	{ "bt",		BT,		WORD },
-	{ "btc",	BTC,		WORD },
-	{ "btr",	BTR,		WORD },
-	{ "bts",	BTS,		WORD },
-	{ "bz",		JE,		JUMP },
-	{ "call",	CALL,		JUMP },
-	{ "callf",	CALLF,		JUMP },
-	{ "cbw",	CBW,		WORD },
-	{ "cdq",	CWD,		WORD },
-	{ "clc",	CLC,		WORD },
-	{ "cld",	CLD,		WORD },
-	{ "cli",	CLI,		WORD },
-	{ "clts",	CLTS,		WORD },
-	{ "cmc",	CMC,		WORD },
-	{ "cmp",	CMP,		WORD },
-	{ "cmps",	CMPS,		WORD },
-	{ "cmpsb",	CMPS,		BYTE },
-	{ "cmpxchg",	CMPXCHG,	WORD },
-	{ "cwd",	CWD,		WORD },
-	{ "cwde",	CBW,		WORD },
-	{ "daa",	DAA,		WORD },
-	{ "das",	DAS,		WORD },
-	{ "dd",		DOT_DATA4,	PSEUDO },
-	{ "dec",	DEC,		WORD },
-	{ "div",	DIV,		WORD },
-	{ "enter",	ENTER,		WORD },
-	{ "export",	DOT_DEFINE,	PSEUDO },
-	{ "f2xm1",	F2XM1,		WORD },
-	{ "fabs",	FABS,		WORD },
-	{ "fadd",	FADD,		WORD },
-	{ "faddd",	FADDD,		WORD },
-	{ "faddp",	FADDP,		WORD },
-	{ "fadds",	FADDS,		WORD },
-	{ "fbld",	FBLD,		WORD },
-	{ "fbstp",	FBSTP,		WORD },
-	{ "fchs",	FCHS,		WORD },
-	{ "fclex",	FCLEX,		WORD },
-	{ "fcomd",	FCOMD,		WORD },
-	{ "fcompd",	FCOMPD,		WORD },
-	{ "fcompp",	FCOMPP,		WORD },
-	{ "fcomps",	FCOMPS,		WORD },
-	{ "fcoms",	FCOMS,		WORD },
-	{ "fcos",	FCOS,		WORD },
-	{ "fdecstp",	FDECSTP,	WORD },
-	{ "fdivd",	FDIVD,		WORD },
-	{ "fdivp",	FDIVP,		WORD },
-	{ "fdivrd",	FDIVRD,		WORD },
-	{ "fdivrp",	FDIVRP,		WORD },
-	{ "fdivrs",	FDIVRS,		WORD },
-	{ "fdivs",	FDIVS,		WORD },
-	{ "ffree",	FFREE,		WORD },
-	{ "fiaddl",	FIADDL,		WORD },
-	{ "fiadds",	FIADDS,		WORD },
-	{ "ficom",	FICOM,		WORD },
-	{ "ficomp",	FICOMP,		WORD },
-	{ "fidivl",	FIDIVL,		WORD },
-	{ "fidivrl",	FIDIVRL,	WORD },
-	{ "fidivrs",	FIDIVRS,	WORD },
-	{ "fidivs",	FIDIVS,		WORD },
-	{ "fildl",	FILDL,		WORD },
-	{ "fildq",	FILDQ,		WORD },
-	{ "filds",	FILDS,		WORD },
-	{ "fimull",	FIMULL,		WORD },
-	{ "fimuls",	FIMULS,		WORD },
-	{ "fincstp",	FINCSTP,	WORD },
-	{ "finit",	FINIT,		WORD },
-	{ "fistl",	FISTL,		WORD },
-	{ "fistp",	FISTP,		WORD },
-	{ "fists",	FISTS,		WORD },
-	{ "fisubl",	FISUBL,		WORD },
-	{ "fisubrl",	FISUBRL,	WORD },
-	{ "fisubrs",	FISUBRS,	WORD },
-	{ "fisubs",	FISUBS,		WORD },
-	{ "fld1",	FLD1,		WORD },
-	{ "fldcw",	FLDCW,		WORD },
-	{ "fldd",	FLDD,		WORD },
-	{ "fldenv",	FLDENV,		WORD },
-	{ "fldl2e",	FLDL2E,		WORD },
-	{ "fldl2t",	FLDL2T,		WORD },
-	{ "fldlg2",	FLDLG2,		WORD },
-	{ "fldln2",	FLDLN2,		WORD },
-	{ "fldpi",	FLDPI,		WORD },
-	{ "flds",	FLDS,		WORD },
-	{ "fldx",	FLDX,		WORD },
-	{ "fldz",	FLDZ,		WORD },
-	{ "fmuld",	FMULD,		WORD },
-	{ "fmulp",	FMULP,		WORD },
-	{ "fmuls",	FMULS,		WORD },
-	{ "fnop",	FNOP,		WORD },
-	{ "fpatan",	FPATAN,		WORD },
-	{ "fprem",	FPREM,		WORD },
-	{ "fprem1",	FPREM1,		WORD },
-	{ "fptan",	FPTAN,		WORD },
-	{ "frndint",	FRNDINT,	WORD },
-	{ "frstor",	FRSTOR,		WORD },
-	{ "fsave",	FSAVE,		WORD },
-	{ "fscale",	FSCALE,		WORD },
-	{ "fsin",	FSIN,		WORD },
-	{ "fsincos",	FSINCOS,	WORD },
-	{ "fsqrt",	FSQRT,		WORD },
-	{ "fstcw",	FSTCW,		WORD },
-	{ "fstd",	FSTD,		WORD },
-	{ "fstenv",	FSTENV,		WORD },
-	{ "fstpd",	FSTPD,		WORD },
-	{ "fstps",	FSTPS,		WORD },
-	{ "fstpx",	FSTPX,		WORD },
-	{ "fsts",	FSTS,		WORD },
-	{ "fstsw",	FSTSW,		WORD },
-	{ "fsubd",	FSUBD,		WORD },
-	{ "fsubp",	FSUBP,		WORD },
-	{ "fsubpr",	FSUBPR,		WORD },
-	{ "fsubrd",	FSUBRD,		WORD },
-	{ "fsubrs",	FSUBRS,		WORD },
-	{ "fsubs",	FSUBS,		WORD },
-	{ "ftst",	FTST,		WORD },
-	{ "fucom",	FUCOM,		WORD },
-	{ "fucomp",	FUCOMP,		WORD },
-	{ "fucompp",	FUCOMPP,	WORD },
-	{ "fxam",	FXAM,		WORD },
-	{ "fxch",	FXCH,		WORD },
-	{ "fxtract",	FXTRACT,	WORD },
-	{ "fyl2x",	FYL2X,		WORD },
-	{ "fyl2xp1",	FYL2XP1,	WORD },
-	{ "hlt",	HLT,		WORD },
-	{ "idiv",	IDIV,		WORD },
-	{ "imul",	IMUL,		WORD },
-	{ "in",		IN,		WORD },
-	{ "inb",	IN,		BYTE },
-	{ "inc",	INC,		WORD },
-	{ "ins",	INS,		WORD },
-	{ "insb",	INS,		BYTE },
-	{ "int",	INT,		WORD },
-	{ "into",	INTO,		JUMP },
-	{ "invd",	INVD,		WORD },
-	{ "invlpg",	INVLPG,		WORD },
-	{ "iret",	IRET,		JUMP },
-	{ "iretd",	IRETD,		JUMP },
-	{ "j",		JMP,		JUMP },
-	{ "ja",		JA,		JUMP },
-	{ "jae",	JAE,		JUMP },
-	{ "jb",		JB,		JUMP },
-	{ "jbe",	JBE,		JUMP },
-	{ "jc",		JB,		JUMP },
-	{ "jcxz",	JCXZ,		JUMP },
-	{ "je",		JE,		JUMP },
-	{ "jecxz",	JCXZ,		JUMP },
-	{ "jeq",	JE,		JUMP },
-	{ "jg",		JG,		JUMP },
-	{ "jge",	JGE,		JUMP },
-	{ "jgt",	JG,		JUMP },
-	{ "jhi",	JA,		JUMP },
-	{ "jhis",	JAE,		JUMP },
-	{ "jl",		JL,		JUMP },
-	{ "jle",	JLE,		JUMP },
-	{ "jlo",	JB,		JUMP },
-	{ "jlos",	JBE,		JUMP },
-	{ "jlt",	JL,		JUMP },
-	{ "jmp",	JMP,		JUMP },
-	{ "jmpf",	JMPF,		JUMP },
-	{ "jna",	JBE,		JUMP },
-	{ "jnae",	JB,		JUMP },
-	{ "jnb",	JAE,		JUMP },
-	{ "jnbe",	JA,		JUMP },
-	{ "jnc",	JAE,		JUMP },
-	{ "jne",	JNE,		JUMP },
-	{ "jng",	JLE,		JUMP },
-	{ "jnge",	JL,		JUMP },
-	{ "jnl",	JGE,		JUMP },
-	{ "jnle",	JG,		JUMP },
-	{ "jno",	JNO,		JUMP },
-	{ "jnp",	JNP,		JUMP },
-	{ "jns",	JNS,		JUMP },
-	{ "jnz",	JNE,		JUMP },
-	{ "jo",		JO,		JUMP },
-	{ "jp",		JP,		JUMP },
-	{ "js",		JS,		JUMP },
-	{ "jz",		JE,		JUMP },
-	{ "lahf",	LAHF,		WORD },
-	{ "lar",	LAR,		WORD },
-	{ "lds",	LDS,		WORD },
-	{ "lea",	LEA,		WORD },
-	{ "leave",	LEAVE,		WORD },
-	{ "les",	LES,		WORD },
-	{ "lfs",	LFS,		WORD },
-	{ "lgdt",	LGDT,		WORD },
-	{ "lgs",	LGS,		WORD },
-	{ "lidt",	LIDT,		WORD },
-	{ "lldt",	LLDT,		WORD },
-	{ "lmsw",	LMSW,		WORD },
-	{ "lock",	LOCK,		WORD },
-	{ "lods",	LODS,		WORD },
-	{ "lodsb",	LODS,		BYTE },
-	{ "loop",	LOOP,		JUMP },
-	{ "loope",	LOOPE,		JUMP },
-	{ "loopne",	LOOPNE,		JUMP },
-	{ "loopnz",	LOOPNE,		JUMP },
-	{ "loopz",	LOOPE,		JUMP },
-	{ "lsl",	LSL,		WORD },
-	{ "lss",	LSS,		WORD },
-	{ "ltr",	LTR,		WORD },
-	{ "mov",	MOV,		WORD },
-	{ "movs",	MOVS,		WORD },
-	{ "movsb",	MOVS,		BYTE },
-	{ "movsx",	MOVSX,		WORD },
-	{ "movzx",	MOVZX,		WORD },
-	{ "mul",	MUL,		WORD },
-	{ "neg",	NEG,		WORD },
-	{ "nop",	NOP,		WORD },
-	{ "not",	NOT,		WORD },
-	{ "or",		OR,		WORD },
-	{ "out",	OUT,		WORD },
-	{ "outb",	OUT,		BYTE },
-	{ "outs",	OUTS,		WORD },
-	{ "outsb",	OUTS,		BYTE },
-	{ "pop",	POP,		WORD },
-	{ "popa",	POPA,		WORD },
-	{ "popad",	POPA,		WORD },
-	{ "popf",	POPF,		WORD },
-	{ "popfd",	POPF,		WORD },
-	{ "push",	PUSH,		WORD },
-	{ "pusha",	PUSHA,		WORD },
-	{ "pushad",	PUSHA,		WORD },
-	{ "pushf",	PUSHF,		WORD },
-	{ "pushfd",	PUSHF,		WORD },
-	{ "rcl",	RCL,		WORD },
-	{ "rcr",	RCR,		WORD },
-	{ "ret",	RET,		JUMP },
-	{ "retf",	RETF,		JUMP },
-	{ "rol",	ROL,		WORD },
-	{ "ror",	ROR,		WORD },
-	{ "sahf",	SAHF,		WORD },
-	{ "sal",	SAL,		WORD },
-	{ "sar",	SAR,		WORD },
-	{ "sbb",	SBB,		WORD },
-	{ "scas",	SCAS,		WORD },
-	{ "seta",	SETA,		BYTE },
-	{ "setae",	SETAE,		BYTE },
-	{ "setb",	SETB,		BYTE },
-	{ "setbe",	SETBE,		BYTE },
-	{ "sete",	SETE,		BYTE },
-	{ "setg",	SETG,		BYTE },
-	{ "setge",	SETGE,		BYTE },
-	{ "setl",	SETL,		BYTE },
-	{ "setna",	SETBE,		BYTE },
-	{ "setnae",	SETB,		BYTE },
-	{ "setnb",	SETAE,		BYTE },
-	{ "setnbe",	SETA,		BYTE },
-	{ "setne",	SETNE,		BYTE },
-	{ "setng",	SETLE,		BYTE },
-	{ "setnge",	SETL,		BYTE },
-	{ "setnl",	SETGE,		BYTE },
-	{ "setnle",	SETG,		BYTE },
-	{ "setno",	SETNO,		BYTE },
-	{ "setnp",	SETNP,		BYTE },
-	{ "setns",	SETNS,		BYTE },
-	{ "seto",	SETO,		BYTE },
-	{ "setp",	SETP,		BYTE },
-	{ "sets",	SETS,		BYTE },
-	{ "setz",	SETE,		BYTE },
-	{ "sgdt",	SGDT,		WORD },
-	{ "shl",	SHL,		WORD },
-	{ "shld",	SHLD,		WORD },
-	{ "shr",	SHR,		WORD },
-	{ "shrd",	SHRD,		WORD },
-	{ "sidt",	SIDT,		WORD },
-	{ "sldt",	SLDT,		WORD },
-	{ "smsw",	SMSW,		WORD },
-	{ "stc",	STC,		WORD },
-	{ "std",	STD,		WORD },
-	{ "sti",	STI,		WORD },
-	{ "stos",	STOS,		WORD },
-	{ "stosb",	STOS,		BYTE },
-	{ "str",	STR,		WORD },
-	{ "sub",	SUB,		WORD },
-	{ "test",	TEST,		WORD },
-	{ "verr",	VERR,		WORD },
-	{ "verw",	VERW,		WORD },
-	{ "wait",	WAIT,		WORD },
-	{ "wbinvd",	WBINVD,		WORD },
-	{ "xadd",	XADD,		WORD },
-	{ "xchg",	XCHG,		WORD },
-	{ "xlat",	XLAT,		WORD },
-	{ "xor",	XOR,		WORD },
-};
-
-void bas_parse_init(char *file)
-/* Prepare parsing of an BAS assembly file. */
-{
-	tok_init(file, '!');
-}
-
-static void zap(void)
-/* An error, zap the rest of the line. */
-{
-	token_t *t;
-
-	while ((t= get_token(0))->type != T_EOF && t->symbol != ';')
-		skip_token(1);
-}
-
-static mnemonic_t *search_mnem(char *name)
-/* Binary search for a mnemonic.  (That's why the table is sorted.) */
-{
-	int low, mid, high;
-	int cmp;
-	mnemonic_t *m;
-
-	low= 0;
-	high= arraysize(mnemtab)-1;
-	while (low <= high) {
-		mid= (low + high) / 2;
-		m= &mnemtab[mid];
-
-		if ((cmp= strcmp(name, m->name)) == 0) return m;
-
-		if (cmp < 0) high= mid-1; else low= mid+1;
-	}
-	return nil;
-}
-
-static expression_t *bas_get_C_expression(int *pn)
-/* Read a "C-like" expression.  Note that we don't worry about precedence,
- * the expression is printed later like it is read.  If the target language
- * does not have all the operators (like ~) then this has to be repaired by
- * changing the source file.  (No problem, you still have one source file
- * to maintain, not two.)
- */
-{
-	expression_t *e, *a1, *a2;
-	token_t *t;
-
-	if ((t= get_token(*pn))->symbol == '(') {
-		/* ( expr ): grouping. */
-		(*pn)++;
-		if ((a1= bas_get_C_expression(pn)) == nil) return nil;
-		if (get_token(*pn)->symbol != ')') {
-			parse_err(1, t, "missing )\n");
-			del_expr(a1);
-			return nil;
-		}
-		(*pn)++;
-		e= new_expr();
-		e->operator= '[';
-		e->middle= a1;
-	} else
-	if (t->type == T_WORD || t->type == T_STRING) {
-		/* Label, number, or string. */
-		e= new_expr();
-		e->operator= t->type == T_WORD ? 'W' : 'S';
-		e->name= allocate(nil, (t->len+1) * sizeof(e->name[0]));
-		memcpy(e->name, t->name, t->len+1);
-		e->len= t->len;
-		(*pn)++;
-	} else
-	if (t->symbol == '+' || t->symbol == '-' || t->symbol == '~') {
-		/* Unary operator. */
-		(*pn)++;
-		if ((a1= bas_get_C_expression(pn)) == nil) return nil;
-		e= new_expr();
-		e->operator= t->symbol;
-		e->middle= a1;
-	} else
-	if (t->symbol == '$' && get_token(*pn + 1)->type == T_WORD) {
-		/* A hexadecimal number. */
-		t= get_token(*pn + 1);
-		e= new_expr();
-		e->operator= 'W';
-		e->name= allocate(nil, (t->len+3) * sizeof(e->name[0]));
-		strcpy(e->name, "0x");
-		memcpy(e->name+2, t->name, t->len+1);
-		e->len= t->len+2;
-		(*pn)+= 2;
-	} else {
-		parse_err(1, t, "expression syntax error\n");
-		return nil;
-	}
-
-	switch ((t= get_token(*pn))->symbol) {
-	case '+':
-	case '-':
-	case '*':
-	case '/':
-	case '%':
-	case '&':
-	case '|':
-	case '^':
-	case S_LEFTSHIFT:
-	case S_RIGHTSHIFT:
-		(*pn)++;
-		a1= e;
-		if ((a2= bas_get_C_expression(pn)) == nil) {
-			del_expr(a1);
-			return nil;
-		}
-		e= new_expr();
-		e->operator= t->symbol;
-		e->left= a1;
-		e->right= a2;
-	}
-	return e;
-}
-
-/* We want to know the sizes of the first two operands. */
-static optype_t optypes[2];
-static int op_idx;
-
-static expression_t *bas_get_operand(int *pn)
-/* Get something like: [memory], offset[base+index*scale], or simpler. */
-{
-	expression_t *e, *offset, *base, *index;
-	token_t *t;
-	int c;
-	optype_t optype;
-
-	/* Prefixed by 'byte', 'word' or 'dword'? */
-	if ((t= get_token(*pn))->type == T_WORD && (
-		strcmp(t->name, "byte") == 0
-		|| strcmp(t->name, "word") == 0
-		|| strcmp(t->name, "dword") == 0)
-	) {
-		switch (t->name[0]) {
-		case 'b':	optype= BYTE; break;
-		case 'w':	optype= use16() ? WORD : OWORD; break;
-		case 'd':	optype= use32() ? WORD : OWORD; break;
-		}
-		if (op_idx < arraysize(optypes)) optypes[op_idx++]= optype;
-		(*pn)++;
-
-		/* It may even be "byte ptr"... */
-		if ((t= get_token(*pn))->type == T_WORD
-					&& strcmp(t->name, "ptr") == 0) {
-			(*pn)++;
-		}
-	}
-
-	/* Is it [memory]? */
-	if (get_token(*pn)->symbol == '['
-		&& ((t= get_token(*pn + 1))->type != T_WORD
-			|| !isregister(t->name))
-	) {
-		/* A memory dereference. */
-		(*pn)++;
-		if ((offset= bas_get_C_expression(pn)) == nil) return nil;
-		if (get_token(*pn)->symbol != ']') {
-			parse_err(1, t, "operand syntax error\n");
-			del_expr(offset);
-			return nil;
-		}
-		(*pn)++;
-		e= new_expr();
-		e->operator= '(';
-		e->middle= offset;
-		return e;
-	}
-
-	/* #something? *something? */
-	if ((c= get_token(*pn)->symbol) == '#' || c == '*') {
-		/* '#' and '*' are often used to introduce some constant. */
-		(*pn)++;
-	}
-
-	/* Offset? */
-	if (get_token(*pn)->symbol != '[') {
-		/* There is an offset. */
-		if ((offset= bas_get_C_expression(pn)) == nil) return nil;
-	} else {
-		/* No offset. */
-		offset= nil;
-	}
-
-	/* [base]? [base+? base-? */
-	c= 0;
-	if (get_token(*pn)->symbol == '['
-		&& (t= get_token(*pn + 1))->type == T_WORD
-		&& isregister(t->name)
-		&& ((c= get_token(*pn + 2)->symbol) == ']' || c=='+' || c=='-')
-	) {
-		/* A base register expression. */
-		base= new_expr();
-		base->operator= 'B';
-		base->name= copystr(t->name);
-		(*pn)+= c == ']' ? 3 : 2;
-	} else {
-		/* No base register expression. */
-		base= nil;
-	}
-
-	/* +offset]? -offset]? */
-	if (offset == nil
-		&& (c == '+' || c == '-')
-		&& (t= get_token(*pn + 1))->type == T_WORD
-		&& !isregister(t->name)
-	) {
-		(*pn)++;
-		if ((offset= bas_get_C_expression(pn)) == nil) return nil;
-		if (get_token(*pn)->symbol != ']') {
-			parse_err(1, t, "operand syntax error\n");
-			del_expr(offset);
-			del_expr(base);
-			return nil;
-		}
-		(*pn)++;
-		c= 0;
-	}
-
-	/* [index*scale]? +index*scale]? */
-	if (c == '+' || get_token(*pn)->symbol == '[') {
-		/* An index most likely. */
-		token_t *m= nil;
-
-		if (!(		/* This must be true: */
-			(t= get_token(*pn + 1))->type == T_WORD
-			&& isregister(t->name)
-			&& (get_token(*pn + 2)->symbol == ']' || (
-				get_token(*pn + 2)->symbol == '*'
-				&& (m= get_token(*pn + 3))->type == T_WORD
-				&& strchr("1248", m->name[0]) != nil
-				&& m->name[1] == 0
-				&& get_token(*pn + 4)->symbol == ']'
-			))
-		)) {
-			/* Alas it isn't */
-			parse_err(1, t, "operand syntax error\n");
-			del_expr(offset);
-			del_expr(base);
-			return nil;
-		}
-		/* Found an index. */
-		index= new_expr();
-		index->operator= m == nil ? '1' : m->name[0];
-		index->name= copystr(t->name);
-		(*pn)+= (m == nil ? 3 : 5);
-	} else {
-		/* No index. */
-		index= nil;
-	}
-
-	if (base == nil && index == nil) {
-		/* Return a lone offset as is. */
-		e= offset;
-
-		/* Lone registers tell operand size. */
-		if (offset->operator == 'W' && isregister(offset->name)) {
-			switch (isregister(offset->name)) {
-			case 1:	optype= BYTE; break;
-			case 2:	optype= use16() ? WORD : OWORD; break;
-			case 4:	optype= use32() ? WORD : OWORD; break;
-			}
-			if (op_idx < arraysize(optypes))
-				optypes[op_idx++]= optype;
-		}
-	} else {
-		e= new_expr();
-		e->operator= 'O';
-		e->left= offset;
-		e->middle= base;
-		e->right= index;
-	}
-	return e;
-}
-
-static expression_t *bas_get_oplist(int *pn)
-/* Get a comma (or colon for jmpf and callf) separated list of instruction
- * operands.
- */
-{
-	expression_t *e, *o1, *o2;
-	token_t *t;
-
-	if ((e= bas_get_operand(pn)) == nil) return nil;
-
-	if ((t= get_token(*pn))->symbol == ',' || t->symbol == ':') {
-		o1= e;
-		(*pn)++;
-		if ((o2= bas_get_oplist(pn)) == nil) {
-			del_expr(o1);
-			return nil;
-		}
-		e= new_expr();
-		e->operator= ',';
-		e->left= o1;
-		e->right= o2;
-	}
-	return e;
-}
-
-static asm86_t *bas_get_statement(void)
-/* Get a pseudo op or machine instruction with arguments. */
-{
-	token_t *t= get_token(0);
-	asm86_t *a;
-	mnemonic_t *m;
-	int n;
-	int prefix_seen;
-
-
-	assert(t->type == T_WORD);
-
-	if (strcmp(t->name, ".sect") == 0) {
-		/* .sect .text etc.  Accept only four segment names. */
-		skip_token(1);
-		t= get_token(0);
-		if (t->type != T_WORD || (
-			strcmp(t->name, ".text") != 0
-			&& strcmp(t->name, ".rom") != 0
-			&& strcmp(t->name, ".data") != 0
-			&& strcmp(t->name, ".bss") != 0
-			&& strcmp(t->name, ".end") != 0
-		)) {
-			parse_err(1, t, "weird section name to .sect\n");
-			return nil;
-		}
-	}
-	a= new_asm86();
-
-	/* Process instruction prefixes. */
-	for (prefix_seen= 0;; prefix_seen= 1) {
-		if (strcmp(t->name, "rep") == 0
-			|| strcmp(t->name, "repe") == 0
-			|| strcmp(t->name, "repne") == 0
-			|| strcmp(t->name, "repz") == 0
-			|| strcmp(t->name, "repnz") == 0
-		) {
-			if (a->rep != ONCE) {
-				parse_err(1, t,
-					"can't have more than one rep\n");
-			}
-			switch (t->name[3]) {
-			case 0:		a->rep= REP;	break;
-			case 'e':
-			case 'z':	a->rep= REPE;	break;
-			case 'n':	a->rep= REPNE;	break;
-			}
-		} else
-		if (strcmp(t->name, "seg") == 0
-					&& get_token(1)->type == T_WORD) {
-			if (a->seg != DEFSEG) {
-				parse_err(1, t,
-				"can't have more than one segment prefix\n");
-			}
-			switch (get_token(1)->name[0]) {
-			case 'c':	a->seg= CSEG;	break;
-			case 'd':	a->seg= DSEG;	break;
-			case 'e':	a->seg= ESEG;	break;
-			case 'f':	a->seg= FSEG;	break;
-			case 'g':	a->seg= GSEG;	break;
-			case 's':	a->seg= SSEG;	break;
-			}
-			skip_token(1);
-		} else
-		if (!prefix_seen) {
-			/* No prefix here, get out! */
-			break;
-		} else {
-			/* No more prefixes, next must be an instruction. */
-			if (t->type != T_WORD
-				|| (m= search_mnem(t->name)) == nil
-				|| m->optype == PSEUDO
-			) {
-				parse_err(1, t,
-		"machine instruction expected after instruction prefix\n");
-				del_asm86(a);
-				return nil;
-			}
-			break;
-		}
-
-		/* Skip the prefix and extra newlines. */
-		do {
-			skip_token(1);
-		} while ((t= get_token(0))->symbol == ';');
-	}
-
-	/* All the readahead being done upsets the line counter. */
-	a->line= t->line;
-
-	/* Read a machine instruction or pseudo op. */
-	if ((m= search_mnem(t->name)) == nil) {
-		parse_err(1, t, "unknown instruction '%s'\n", t->name);
-		del_asm86(a);
-		return nil;
-	}
-	a->opcode= m->opcode;
-	a->optype= m->optype;
-	if (a->opcode == CBW || a->opcode == CWD) {
-		a->optype= (strcmp(t->name, "cbw") == 0
-		    || strcmp(t->name, "cwd") == 0) == use16() ? WORD : OWORD;
-	}
-	for (op_idx= 0; op_idx < arraysize(optypes); op_idx++)
-		optypes[op_idx]= m->optype;
-	op_idx= 0;
-
-	n= 1;
-	if (get_token(1)->symbol != ';'
-				&& (a->args= bas_get_oplist(&n)) == nil) {
-		del_asm86(a);
-		return nil;
-	}
-
-	if (m->optype == WORD) {
-		/* Does one of the operands overide the optype? */
-		for (op_idx= 0; op_idx < arraysize(optypes); op_idx++) {
-			if (optypes[op_idx] != m->optype)
-				a->optype= optypes[op_idx];
-		}
-	}
-
-	if (get_token(n)->symbol != ';') {
-		parse_err(1, t, "garbage at end of instruction\n");
-		del_asm86(a);
-		return nil;
-	}
-	switch (a->opcode) {
-	case DOT_ALIGN:
-		/* Restrict .align to have a single numeric argument, some
-		 * assemblers think of the argument as a power of two, so
-		 * we need to be able to change the value.
-		 */
-		if (strcmp(t->name, ".even") == 0 && a->args == nil) {
-			/* .even becomes .align 2. */
-			expression_t *e;
-			a->args= e= new_expr();
-			e->operator= 'W';
-			e->name= copystr("2");
-			e->len= 2;
-		}
-		if (a->args == nil || a->args->operator != 'W'
-					|| !isanumber(a->args->name)) {
-			parse_err(1, t,
-			  ".align is restricted to one numeric argument\n");
-			del_asm86(a);
-			return nil;
-		}
-		break;
-	case MOVSX:
-	case MOVZX:
-		/* Types of both operands tell the instruction type. */
-		a->optype= optypes[0];
-		if (optypes[1] == BYTE) {
-			a->opcode= a->opcode == MOVSX ? MOVSXB : MOVZXB;
-		}
-		break;
-	case SAL:
-	case SAR:
-	case SHL:
-	case SHR:
-	case RCL:
-	case RCR:
-	case ROL:
-	case ROR:
-		/* Only the first operand tells the operand size. */
-		a->optype= optypes[0];
-		break;
-	default:;
-	}
-	skip_token(n+1);
-	return a;
-}
-
-asm86_t *bas_get_instruction(void)
-{
-	asm86_t *a= nil;
-	expression_t *e;
-	token_t *t;
-
-	while ((t= get_token(0))->symbol == ';')
-		skip_token(1);
-
-	if (t->type == T_EOF) return nil;
-
-	if (t->symbol == '#') {
-		/* Preprocessor line and file change. */
-
-		if ((t= get_token(1))->type != T_WORD || !isanumber(t->name)
-			|| get_token(2)->type != T_STRING
-		) {
-			parse_err(1, t, "file not preprocessed?\n");
-			zap();
-		} else {
-			set_file(get_token(2)->name,
-				strtol(get_token(1)->name, nil, 0) - 1);
-
-			/* GNU CPP adds extra cruft, simply zap the line. */
-			zap();
-		}
-		a= bas_get_instruction();
-	} else
-	if (t->type == T_WORD && get_token(1)->symbol == ':') {
-		/* A label definition. */
-		a= new_asm86();
-		a->line= t->line;
-		a->opcode= DOT_LABEL;
-		a->optype= PSEUDO;
-		a->args= e= new_expr();
-		e->operator= ':';
-		e->name= copystr(t->name);
-		skip_token(2);
-	} else
-	if (t->type == T_WORD && get_token(1)->symbol == '=') {
-		int n= 2;
-
-		if ((e= bas_get_C_expression(&n)) == nil) {
-			zap();
-			a= bas_get_instruction();
-		} else
-		if (get_token(n)->symbol != ';') {
-			parse_err(1, t, "garbage after assignment\n");
-			zap();
-			a= bas_get_instruction();
-		} else {
-			a= new_asm86();
-			a->line= t->line;
-			a->opcode= DOT_EQU;
-			a->optype= PSEUDO;
-			a->args= new_expr();
-			a->args->operator= '=';
-			a->args->name= copystr(t->name);
-			a->args->middle= e;
-			skip_token(n+1);
-		}
-	} else
-	if (t->type == T_WORD && get_token(1)->type == T_WORD
-				&& strcmp(get_token(1)->name, "lcomm") == 0) {
-		/* Local common block definition. */
-		int n= 2;
-
-		if ((e= bas_get_C_expression(&n)) == nil) {
-			zap();
-			a= bas_get_instruction();
-		} else
-		if (get_token(n)->symbol != ';') {
-			parse_err(1, t, "garbage after lcomm\n");
-			zap();
-			a= bas_get_instruction();
-		} else {
-			a= new_asm86();
-			a->line= t->line;
-			a->opcode= DOT_LCOMM;
-			a->optype= PSEUDO;
-			a->args= new_expr();
-			a->args->operator= ',';
-			a->args->right= e;
-			a->args->left= e= new_expr();
-			e->operator= 'W';
-			e->name= copystr(t->name);
-			e->len= strlen(e->name)+1;
-			skip_token(n+1);
-		}
-	} else
-	if (t->type == T_WORD) {
-		if ((a= bas_get_statement()) == nil) {
-			zap();
-			a= bas_get_instruction();
-		}
-	} else {
-		parse_err(1, t, "syntax error\n");
-		zap();
-		a= bas_get_instruction();
-	}
-	if (a->optype == OWORD) {
-		a->optype= WORD;
-		a->oaz|= OPZ;
-	}
-	return a;
-}
Index: trunk/minix/commands/i386/asmconv/parse_gnu.c
===================================================================
--- trunk/minix/commands/i386/asmconv/parse_gnu.c	(revision 9)
+++ 	(revision )
@@ -1,879 +1,0 @@
-/*	parse_ack.c - parse GNU assembly		Author: R.S. Veldema
- *							 <rveldema@cs.vu.nl>
- *								26 Aug 1996
- */
-#define nil 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <assert.h>
-#include "asmconv.h"
-#include "token.h"
-#include "asm86.h"
-#include "languages.h"
-
-typedef struct mnemonic {	/* GNU as86 mnemonics translation table. */
-	char		*name;
-	opcode_t	opcode;
-	optype_t	optype;
-} mnemonic_t;
-
-static mnemonic_t mnemtab[] = {			/* This array is sorted. */
-	{ ".align",	DOT_ALIGN,	PSEUDO },
-	{ ".ascii",	DOT_ASCII,	PSEUDO },
-	{ ".asciz",	DOT_ASCIZ,	PSEUDO },
-	{ ".assert",	DOT_ASSERT,	PSEUDO },
-	{ ".base",	DOT_BASE,	PSEUDO },
-	{ ".bss",	DOT_BSS,	PSEUDO },
-	{ ".byte",	DOT_DATA1,	PSEUDO },
-	{ ".comm",	DOT_COMM,	PSEUDO },
-	{ ".data",	DOT_DATA,	PSEUDO },
-	{ ".data1",	DOT_DATA1,	PSEUDO },
-	{ ".data2",	DOT_DATA2,	PSEUDO },
-	{ ".data4",	DOT_DATA4,	PSEUDO },
-	{ ".end",	DOT_END,	PSEUDO },
-	{ ".extern",	DOT_EXTERN,	PSEUDO },
-	{ ".file",	DOT_FILE,	PSEUDO },
-	{ ".globl",	DOT_DEFINE,	PSEUDO },
-	{ ".lcomm",	DOT_LCOMM,	PSEUDO },
-	{ ".line",	DOT_LINE,	PSEUDO },
-	{ ".list",	DOT_LIST,	PSEUDO },
-	{ ".long",	DOT_DATA4,	PSEUDO },
-	{ ".nolist",	DOT_NOLIST,	PSEUDO },
-	{ ".rom",	DOT_ROM,	PSEUDO },
-	{ ".space",	DOT_SPACE,	PSEUDO },
-	{ ".symb",	DOT_SYMB,	PSEUDO },
-	{ ".text",	DOT_TEXT,	PSEUDO },
-	{ ".word",	DOT_DATA2,	PSEUDO },
-	{ "aaa",	AAA,		WORD },
-	{ "aad",	AAD,		WORD },
-	{ "aam",	AAM,		WORD },
-	{ "aas",	AAS,		WORD },
-	{ "adcb",	ADC,		BYTE },
-	{ "adcl",	ADC,		WORD },
-	{ "adcw",	ADC,		OWORD },
-	{ "addb",	ADD,		BYTE },
-	{ "addl",	ADD,		WORD },
-	{ "addw",	ADD,		OWORD },
-	{ "andb",	AND,		BYTE },
-	{ "andl",	AND,		WORD },
-	{ "andw",	AND,		OWORD },
-	{ "arpl",	ARPL,		WORD },
-	{ "bound",	BOUND,		WORD },
-	{ "bsf",	BSF,		WORD },
-	{ "bsr",	BSR,		WORD },
-	{ "bswap",	BSWAP,		WORD },
-	{ "btc",	BTC,		WORD },
-	{ "btl",	BT,		WORD },
-	{ "btr",	BTR,		WORD },
-	{ "bts",	BTS,		WORD },
-	{ "btw",	BT,		OWORD },
-	{ "call",	CALL,		JUMP },
-	{ "callf",	CALLF,		JUMP },
-	{ "cbtw",	CBW,		OWORD },
-	{ "cbw",	CBW,		WORD },
-	{ "cdq",	CWD,		WORD },
-	{ "clc",	CLC,		WORD },
-	{ "cld",	CLD,		WORD },
-	{ "cli",	CLI,		WORD },
-	{ "cltd",	CWD,		WORD },
-	{ "clts",	CLTS,		WORD },
-	{ "cmc",	CMC,		WORD },
-	{ "cmpb",	CMP,		BYTE },
-	{ "cmpl",	CMP,		WORD },
-	{ "cmps",	CMPS,		WORD },
-	{ "cmpsb",	CMPS,		BYTE },
-	{ "cmpw",	CMP,		OWORD },
-	{ "cmpxchg",	CMPXCHG,	WORD },
-	{ "cwd",	CWD,		WORD },
-	{ "cwde",	CBW,		WORD },
-	{ "cwtd",	CWD,		OWORD },
-	{ "cwtl",	CBW,		WORD },
-	{ "daa",	DAA,		WORD },
-	{ "das",	DAS,		WORD },
-	{ "decb",	DEC,		BYTE },
-	{ "decl",	DEC,		WORD },
-	{ "decw",	DEC,		OWORD },
-	{ "divb",	DIV,		BYTE },
-	{ "divl",	DIV,		WORD },
-	{ "divw",	DIV,		OWORD },
-	{ "enter",	ENTER,		WORD },
-	{ "f2xm1",	F2XM1,		WORD },
-	{ "fabs",	FABS,		WORD },
-	{ "fadd",	FADD,		WORD },
-	{ "faddd",	FADDD,		WORD },
-	{ "faddp",	FADDP,		WORD },
-	{ "fadds",	FADDS,		WORD },
-	{ "fbld",	FBLD,		WORD },
-	{ "fbstp",	FBSTP,		WORD },
-	{ "fchs",	FCHS,		WORD },
-	{ "fcomd",	FCOMD,		WORD },
-	{ "fcompd",	FCOMPD,		WORD },
-	{ "fcompp",	FCOMPP,		WORD },
-	{ "fcomps",	FCOMPS,		WORD },
-	{ "fcoms",	FCOMS,		WORD },
-	{ "fcos",	FCOS,		WORD },
-	{ "fdecstp",	FDECSTP,	WORD },
-	{ "fdivd",	FDIVD,		WORD },
-	{ "fdivp",	FDIVP,		WORD },
-	{ "fdivrd",	FDIVRD,		WORD },
-	{ "fdivrp",	FDIVRP,		WORD },
-	{ "fdivrs",	FDIVRS,		WORD },
-	{ "fdivs",	FDIVS,		WORD },
-	{ "ffree",	FFREE,		WORD },
-	{ "fiaddl",	FIADDL,		WORD },
-	{ "fiadds",	FIADDS,		WORD },
-	{ "ficom",	FICOM,		WORD },
-	{ "ficomp",	FICOMP,		WORD },
-	{ "fidivl",	FIDIVL,		WORD },
-	{ "fidivrl",	FIDIVRL,	WORD },
-	{ "fidivrs",	FIDIVRS,	WORD },
-	{ "fidivs",	FIDIVS,		WORD },
-	{ "fildl",	FILDL,		WORD },
-	{ "fildq",	FILDQ,		WORD },
-	{ "filds",	FILDS,		WORD },
-	{ "fimull",	FIMULL,		WORD },
-	{ "fimuls",	FIMULS,		WORD },
-	{ "fincstp",	FINCSTP,	WORD },
-	{ "fistl",	FISTL,		WORD },
-	{ "fistp",	FISTP,		WORD },
-	{ "fists",	FISTS,		WORD },
-	{ "fisubl",	FISUBL,		WORD },
-	{ "fisubrl",	FISUBRL,	WORD },
-	{ "fisubrs",	FISUBRS,	WORD },
-	{ "fisubs",	FISUBS,		WORD },
-	{ "fld1",	FLD1,		WORD },
-	{ "fldcw",	FLDCW,		WORD },
-	{ "fldd",	FLDD,		WORD },
-	{ "fldenv",	FLDENV,		WORD },
-	{ "fldl2e",	FLDL2E,		WORD },
-	{ "fldl2t",	FLDL2T,		WORD },
-	{ "fldlg2",	FLDLG2,		WORD },
-	{ "fldln2",	FLDLN2,		WORD },
-	{ "fldpi",	FLDPI,		WORD },
-	{ "flds",	FLDS,		WORD },
-	{ "fldx",	FLDX,		WORD },
-	{ "fldz",	FLDZ,		WORD },
-	{ "fmuld",	FMULD,		WORD },
-	{ "fmulp",	FMULP,		WORD },
-	{ "fmuls",	FMULS,		WORD },
-	{ "fnclex",	FCLEX,		WORD },
-	{ "fninit",	FINIT,		WORD },
-	{ "fnop",	FNOP,		WORD },
-	{ "fnsave",	FSAVE,		WORD },
-	{ "fnstcw",	FSTCW,		WORD },
-	{ "fnstenv",	FSTENV,		WORD },
-	{ "fpatan",	FPATAN,		WORD },
-	{ "fprem",	FPREM,		WORD },
-	{ "fprem1",	FPREM1,		WORD },
-	{ "fptan",	FPTAN,		WORD },
-	{ "frndint",	FRNDINT,	WORD },
-	{ "frstor",	FRSTOR,		WORD },
-	{ "fscale",	FSCALE,		WORD },
-	{ "fsin",	FSIN,		WORD },
-	{ "fsincos",	FSINCOS,	WORD },
-	{ "fsqrt",	FSQRT,		WORD },
-	{ "fstd",	FSTD,		WORD },
-	{ "fstpd",	FSTPD,		WORD },
-	{ "fstps",	FSTPS,		WORD },
-	{ "fstpx",	FSTPX,		WORD },
-	{ "fsts",	FSTS,		WORD },
-	{ "fstsw",	FSTSW,		WORD },
-	{ "fsubd",	FSUBD,		WORD },
-	{ "fsubp",	FSUBP,		WORD },
-	{ "fsubpr",	FSUBPR,		WORD },
-	{ "fsubrd",	FSUBRD,		WORD },
-	{ "fsubrs",	FSUBRS,		WORD },
-	{ "fsubs",	FSUBS,		WORD },
-	{ "ftst",	FTST,		WORD },
-	{ "fucom",	FUCOM,		WORD },
-	{ "fucomp",	FUCOMP,		WORD },
-	{ "fucompp",	FUCOMPP,	WORD },
-	{ "fxam",	FXAM,		WORD },
-	{ "fxch",	FXCH,		WORD },
-	{ "fxtract",	FXTRACT,	WORD },
-	{ "fyl2x",	FYL2X,		WORD },
-	{ "fyl2xp1",	FYL2XP1,	WORD },
-	{ "hlt",	HLT,		WORD },
-	{ "idivb",	IDIV,		BYTE },
-	{ "idivl",	IDIV,		WORD },
-	{ "idivw",	IDIV,		OWORD },
-	{ "imulb",	IMUL,		BYTE },
-	{ "imull",	IMUL,		WORD },
-	{ "imulw",	IMUL,		OWORD },
-	{ "inb",	IN,		BYTE },
-	{ "incb",	INC,		BYTE },
-	{ "incl",	INC,		WORD },
-	{ "incw",	INC,		OWORD },
-	{ "inl",	IN,		WORD },
-	{ "insb",	INS,		BYTE },
-	{ "insl",	INS,		WORD },
-	{ "insw",	INS,		OWORD },
-	{ "int",	INT,		WORD },
-	{ "into",	INTO,		JUMP },
-	{ "invd",	INVD,		WORD },
-	{ "invlpg",	INVLPG,		WORD },
-	{ "inw",	IN,		OWORD },
-	{ "iret",	IRET,		JUMP },
-	{ "iretd",	IRETD,		JUMP },
-	{ "ja",		JA,		JUMP },
-	{ "jae",	JAE,		JUMP },
-	{ "jb",		JB,		JUMP },
-	{ "jbe",	JBE,		JUMP },
-	{ "jc",		JB,		JUMP },
-	{ "jcxz",	JCXZ,		JUMP },
-	{ "je",		JE,		JUMP },
-	{ "jecxz",	JCXZ,		JUMP },
-	{ "jg",		JG,		JUMP },
-	{ "jge",	JGE,		JUMP },
-	{ "jl",		JL,		JUMP },
-	{ "jle",	JLE,		JUMP },
-	{ "jmp",	JMP,		JUMP },
-	{ "jmpf",	JMPF,		JUMP },
-	{ "jna",	JBE,		JUMP },
-	{ "jnae",	JB,		JUMP },
-	{ "jnb",	JAE,		JUMP },
-	{ "jnbe",	JA,		JUMP },
-	{ "jnc",	JAE,		JUMP },
-	{ "jne",	JNE,		JUMP },
-	{ "jng",	JLE,		JUMP },
-	{ "jnge",	JL,		JUMP },
-	{ "jnl",	JGE,		JUMP },
-	{ "jnle",	JG,		JUMP },
-	{ "jno",	JNO,		JUMP },
-	{ "jnp",	JNP,		JUMP },
-	{ "jns",	JNS,		JUMP },
-	{ "jnz",	JNE,		JUMP },
-	{ "jo",		JO,		JUMP },
-	{ "jp",		JP,		JUMP },
-	{ "js",		JS,		JUMP },
-	{ "jz",		JE,		JUMP },
-	{ "lahf",	LAHF,		WORD },
-	{ "lar",	LAR,		WORD },
-	{ "lds",	LDS,		WORD },
-	{ "leal",	LEA,		WORD },
-	{ "leave",	LEAVE,		WORD },
-	{ "leaw",	LEA,		OWORD },
-	{ "les",	LES,		WORD },
-	{ "lfs",	LFS,		WORD },
-	{ "lgdt",	LGDT,		WORD },
-	{ "lgs",	LGS,		WORD },
-	{ "lidt",	LIDT,		WORD },
-	{ "lldt",	LLDT,		WORD },
-	{ "lmsw",	LMSW,		WORD },
-	{ "lock",	LOCK,		WORD },
-	{ "lods",	LODS,		WORD },
-	{ "lodsb",	LODS,		BYTE },
-	{ "loop",	LOOP,		JUMP },
-	{ "loope",	LOOPE,		JUMP },
-	{ "loopne",	LOOPNE,		JUMP },
-	{ "loopnz",	LOOPNE,		JUMP },
-	{ "loopz",	LOOPE,		JUMP },
-	{ "lsl",	LSL,		WORD },
-	{ "lss",	LSS,		WORD },
-	{ "ltr",	LTR,		WORD },
-	{ "movb",	MOV,		BYTE },
-	{ "movl",	MOV,		WORD },
-	{ "movsb",	MOVS,		BYTE },
-	{ "movsbl",	MOVSXB,		WORD },
-	{ "movsbw",	MOVSXB,		OWORD },
-	{ "movsl",	MOVS,		WORD },
-	{ "movsw",	MOVS,		OWORD },
-	{ "movswl",	MOVSX,		WORD },
-	{ "movw",	MOV,		OWORD },
-	{ "movzbl",	MOVZXB,		WORD },
-	{ "movzbw",	MOVZXB,		OWORD },
-	{ "movzwl",	MOVZX,		WORD },
-	{ "mulb",	MUL,		BYTE },
-	{ "mull",	MUL,		WORD },
-	{ "mulw",	MUL,		OWORD },
-	{ "negb",	NEG,		BYTE },
-	{ "negl",	NEG,		WORD },
-	{ "negw",	NEG,		OWORD },
-	{ "nop",	NOP,		WORD },
-	{ "notb",	NOT,		BYTE },
-	{ "notl",	NOT,		WORD },
-	{ "notw",	NOT,		OWORD },
-	{ "orb",	OR,		BYTE },
-	{ "orl",	OR,		WORD },
-	{ "orw",	OR,		OWORD },
-	{ "outb",	OUT,		BYTE },
-	{ "outl",	OUT,		WORD },
-	{ "outsb",	OUTS,		BYTE },
-	{ "outsl",	OUTS,		WORD },
-	{ "outsw",	OUTS,		OWORD },
-	{ "outw",	OUT,		OWORD },
-	{ "pop",	POP,		WORD },
-	{ "popa",	POPA,		WORD },
-	{ "popad",	POPA,		WORD },
-	{ "popf",	POPF,		WORD },
-	{ "popl",	POP,		WORD },
-	{ "push",	PUSH,		WORD },
-	{ "pusha",	PUSHA,		WORD },
-	{ "pushad",	PUSHA,		WORD },
-	{ "pushf",	PUSHF,		WORD },
-	{ "pushl",	PUSH,		WORD },
-	{ "rclb",	RCL,		BYTE },
-	{ "rcll",	RCL,		WORD },
-	{ "rclw",	RCL,		OWORD },
-	{ "rcrb",	RCR,		BYTE },
-	{ "rcrl",	RCR,		WORD },
-	{ "rcrw",	RCR,		OWORD },
-	{ "ret",	RET,		JUMP },
-	{ "retf",	RETF,		JUMP },
-	{ "rolb",	ROL,		BYTE },
-	{ "roll",	ROL,		WORD },
-	{ "rolw",	ROL,		OWORD },
-	{ "rorb",	ROR,		BYTE },
-	{ "rorl",	ROR,		WORD },
-	{ "rorw",	ROR,		OWORD },
-	{ "sahf",	SAHF,		WORD },
-	{ "salb",	SAL,		BYTE },
-	{ "sall",	SAL,		WORD },
-	{ "salw",	SAL,		OWORD },
-	{ "sarb",	SAR,		BYTE },
-	{ "sarl",	SAR,		WORD },
-	{ "sarw",	SAR,		OWORD },
-	{ "sbbb",	SBB,		BYTE },
-	{ "sbbl",	SBB,		WORD },
-	{ "sbbw",	SBB,		OWORD },
-	{ "scasb",	SCAS,		BYTE },
-	{ "scasl",	SCAS,		WORD },
-	{ "scasw",	SCAS,		OWORD },
-	{ "seta",	SETA,		BYTE },
-	{ "setae",	SETAE,		BYTE },
-	{ "setb",	SETB,		BYTE },
-	{ "setbe",	SETBE,		BYTE },
-	{ "sete",	SETE,		BYTE },
-	{ "setg",	SETG,		BYTE },
-	{ "setge",	SETGE,		BYTE },
-	{ "setl",	SETL,		BYTE },
-	{ "setna",	SETBE,		BYTE },
-	{ "setnae",	SETB,		BYTE },
-	{ "setnb",	SETAE,		BYTE },
-	{ "setnbe",	SETA,		BYTE },
-	{ "setne",	SETNE,		BYTE },
-	{ "setng",	SETLE,		BYTE },
-	{ "setnge",	SETL,		BYTE },
-	{ "setnl",	SETGE,		BYTE },
-	{ "setnle",	SETG,		BYTE },
-	{ "setno",	SETNO,		BYTE },
-	{ "setnp",	SETNP,		BYTE },
-	{ "setns",	SETNS,		BYTE },
-	{ "seto",	SETO,		BYTE },
-	{ "setp",	SETP,		BYTE },
-	{ "sets",	SETS,		BYTE },
-	{ "setz",	SETE,		BYTE },
-	{ "sgdt",	SGDT,		WORD },
-	{ "shlb",	SHL,		BYTE },
-	{ "shldl",	SHLD,		WORD },
-	{ "shll",	SHL,		WORD },
-	{ "shlw",	SHL,		OWORD },
-	{ "shrb",	SHR,		BYTE },
-	{ "shrdl",	SHRD,		WORD },
-	{ "shrl",	SHR,		WORD },
-	{ "shrw",	SHR,		OWORD },
-	{ "sidt",	SIDT,		WORD },
-	{ "sldt",	SLDT,		WORD },
-	{ "smsw",	SMSW,		WORD },
-	{ "stc",	STC,		WORD },
-	{ "std",	STD,		WORD },
-	{ "sti",	STI,		WORD },
-	{ "stosb",	STOS,		BYTE },
-	{ "stosl",	STOS,		WORD },
-	{ "stosw",	STOS,		OWORD },
-	{ "str",	STR,		WORD },
-	{ "subb",	SUB,		BYTE },
-	{ "subl",	SUB,		WORD },
-	{ "subw",	SUB,		OWORD },
-	{ "testb",	TEST,		BYTE },
-	{ "testl",	TEST,		WORD },
-	{ "testw",	TEST,		OWORD },
-	{ "verr",	VERR,		WORD },
-	{ "verw",	VERW,		WORD },
-	{ "wait",	WAIT,		WORD },
-	{ "wbinvd",	WBINVD,		WORD },
-	{ "xadd",	XADD,		WORD },
-	{ "xchgb",	XCHG,		BYTE },
-	{ "xchgl",	XCHG,		WORD },
-	{ "xchgw",	XCHG,		OWORD },
-	{ "xlat",	XLAT,		WORD },
-	{ "xorb",	XOR,		BYTE },
-	{ "xorl",	XOR,		WORD },
-	{ "xorw",	XOR,		OWORD },
-};
-
-void gnu_parse_init(char *file)
-/* Prepare parsing of an GNU assembly file. */
-{
-	tok_init(file, '#');
-}
-
-static void zap(void)
-/* An error, zap the rest of the line. */
-{
-	token_t *t;
-
-	while ((t= get_token(0))->type != T_EOF && t->symbol != ';')
-		skip_token(1);
-}
-
-static mnemonic_t *search_mnem(char *name)
-/* Binary search for a mnemonic.  (That's why the table is sorted.) */
-{
-	int low, mid, high;
-	int cmp;
-	mnemonic_t *m;
-
-	low= 0;
-	high= arraysize(mnemtab)-1;
-	while (low <= high) {
-		mid= (low + high) / 2;
-		m= &mnemtab[mid];
-
-		if ((cmp= strcmp(name, m->name)) == 0) return m;
-
-		if (cmp < 0) high= mid-1; else low= mid+1;
-	}
-	return nil;
-}
-
-static expression_t *gnu_get_C_expression(int *pn)
-/* Read a "C-like" expression.  Note that we don't worry about precedence,
- * the expression is printed later like it is read.  If the target language
- * does not have all the operators (like ~) then this has to be repaired by
- * changing the source file.  (No problem, you still have one source file
- * to maintain, not two.)
- */
-{
-	expression_t *e, *a1, *a2;
-	token_t *t;
-
-	if ((t= get_token(*pn))->symbol == '(') {
-		/* ( expr ): grouping. */
-		(*pn)++;
-		if ((a1= gnu_get_C_expression(pn)) == nil) return nil;
-		if (get_token(*pn)->symbol != ')') {
-			parse_err(1, t, "missing )\n");
-			del_expr(a1);
-			return nil;
-		}
-		(*pn)++;
-		e= new_expr();
-		e->operator= '[';
-		e->middle= a1;
-	} else
-	if (t->type == T_WORD || t->type == T_STRING) {
-		/* Label, number, or string. */
-		e= new_expr();
-		e->operator= t->type == T_WORD ? 'W' : 'S';
-		e->name= allocate(nil, (t->len+1) * sizeof(e->name[0]));
-		memcpy(e->name, t->name , t->len+1);
-		e->len= t->len;
-		(*pn)++;
-	} else
-	if (t->symbol == '+' || t->symbol == '-' || t->symbol == '~') {
-		/* Unary operator. */
-		(*pn)++;
-		if ((a1= gnu_get_C_expression(pn)) == nil) return nil;
-		e= new_expr();
-		e->operator= t->symbol;
-		e->middle= a1;
-	} else {
-		parse_err(1, t, "expression syntax error\n");
-		return nil;
-	}
-
-	switch ((t= get_token(*pn))->symbol) {
-	case '%': 
-	case '+':
-	case '-':
-	case '*':
-	case '/':
-	case '&':
-	case '|':
-	case '^':
-	case S_LEFTSHIFT:
-	case S_RIGHTSHIFT:
-		(*pn)++;
-		a1= e;
-		if ((a2= gnu_get_C_expression(pn)) == nil) {
-			del_expr(a1);
-			return nil;
-		}
-		e= new_expr();
-		e->operator= t->symbol;
-		e->left= a1;
-		e->right= a2;
-	}
-	return e;
-}
-
-static expression_t *gnu_get_operand(int *pn, int deref)
-/* Get something like: $immed, memory, offset(%base,%index,scale), or simpler. */
-{
-	expression_t *e, *offset, *base, *index;
-	token_t *t;
-	int c;
-
-	if (get_token(*pn)->symbol == '$') {
-		/* An immediate value. */
-		(*pn)++;
-		return gnu_get_C_expression(pn);
-	}
-
-	if (get_token(*pn)->symbol == '*') {
-		/* Indirection. */
-		(*pn)++;
-		if ((offset= gnu_get_operand(pn, deref)) == nil) return nil;
-		e= new_expr();
-		e->operator= '(';
-		e->middle= offset;
-		return e;
-	}
-
-	if ((get_token(*pn)->symbol == '%')
-		&& (t= get_token(*pn + 1))->type == T_WORD
-		&& isregister(t->name)
-	) {
-		/* A register operand. */
-		(*pn)+= 2;
-		e= new_expr();
-		e->operator= 'W';
-		e->name= copystr(t->name);
-		return e;
-	}
-
-	/* Offset? */
-	if (get_token(*pn)->symbol != '('
-				|| get_token(*pn + 1)->symbol != '%') {
-		/* There is an offset. */
-		if ((offset= gnu_get_C_expression(pn)) == nil) return nil;
-	} else {
-		/* No offset. */
-		offset= nil;
-	}
-
-	/* (%base,%index,scale) ? */
-	base= index= nil;
-	if (get_token(*pn)->symbol == '(') {
-		(*pn)++;
-
-		/* %base ? */
-		if (get_token(*pn)->symbol == '%'
-			&& (t= get_token(*pn + 1))->type == T_WORD
-			&& isregister(t->name)
-		) {
-			/* A base register expression. */
-			base= new_expr();
-			base->operator= 'B';
-			base->name= copystr(t->name);
-			(*pn)+= 2;
-		}
-
-		if (get_token(*pn)->symbol == ',') (*pn)++;
-
-		/* %index ? */
-		if (get_token(*pn)->symbol == '%'
-			&& (t= get_token(*pn + 1))->type == T_WORD
-			&& isregister(t->name)
-		) {
-			/* A index register expression. */
-			index= new_expr();
-			index->operator= '1';		/* for now */
-			index->name= copystr(t->name);
-			(*pn)+= 2;
-		}
-
-		if (get_token(*pn)->symbol == ',') (*pn)++;
-
-		/* scale ? */
-		if ((base != nil || index != nil)
-			&& (t= get_token(*pn))->type == T_WORD
-			&& strchr("1248", t->name[0]) != nil
-			&& t->name[1] == 0
-		) {		
-			if (index == nil) {
-				/* Base is really an index register. */
-				index= base;
-				base= nil;
-			}
-			index->operator= t->name[0];
-			(*pn)++;
-		}
-
-		if (get_token(*pn)->symbol == ')') {
-			/* Ending paren. */
-			(*pn)++;
-		} else {
-			/* Alas. */
-			parse_err(1, t, "operand syntax error\n");
-			del_expr(offset);
-			del_expr(base);
-			del_expr(index);
-			return nil;
-		}
-	}
-
-	if (base == nil && index == nil) {
-		if (deref) {
-			/* Return a lone offset as (offset). */
-			e= new_expr();
-			e->operator= '(';
-			e->middle= offset;
-		} else {
-			/* Return a lone offset as is. */
-			e= offset;
-		}
-	} else {
-		e= new_expr();
-		e->operator= 'O';
-		e->left= offset;
-
-		e->middle= base;
-		e->right= index;
-	}
-	return e;
-}
-
-static expression_t *gnu_get_oplist(int *pn, int deref)
-/* Get a comma (or colon for jmpf and callf) separated list of instruction
- * operands.
- */
-{
-	expression_t *e, *o1, *o2;
-	token_t *t;
-
-	if ((e= gnu_get_operand(pn, deref)) == nil) return nil;
-
-	if ((t= get_token(*pn))->symbol == ',' || t->symbol == ':') {
-		o1= e;
-		(*pn)++;
-		if ((o2= gnu_get_oplist(pn, deref)) == nil) {
-			del_expr(o1);
-			return nil;
-		}
-		e= new_expr();
-		e->operator= ',';
-		e->left= o1;
-		e->right= o2;
-	}
-	return e;
-}
-
-
-static asm86_t *gnu_get_statement(void)
-/* Get a pseudo op or machine instruction with arguments. */
-{
-	token_t *t= get_token(0);
-	asm86_t *a;
-	mnemonic_t *m;
-	int n;
-	int prefix_seen;
-	int deref;
-
-	assert(t->type == T_WORD);
-
-	a= new_asm86();
-
-	/* Process instruction prefixes. */
-	for (prefix_seen= 0;; prefix_seen= 1) {
-		if (strcmp(t->name, "rep") == 0
-			|| strcmp(t->name, "repe") == 0
-			|| strcmp(t->name, "repne") == 0
-			|| strcmp(t->name, "repz") == 0
-			|| strcmp(t->name, "repnz") == 0
-		) {
-			if (a->rep != ONCE) {
-				parse_err(1, t,
-					"can't have more than one rep\n");
-			}
-			switch (t->name[3]) {
-			case 0:		a->rep= REP;	break;
-			case 'e':
-			case 'z':	a->rep= REPE;	break;
-			case 'n':	a->rep= REPNE;	break;
-			}
-		} else
-		if (!prefix_seen) {
-			/* No prefix here, get out! */
-			break;
-		} else {
-			/* No more prefixes, next must be an instruction. */
-			if (t->type != T_WORD
-				|| (m= search_mnem(t->name)) == nil
-				|| m->optype == PSEUDO
-			) {
-				parse_err(1, t,
-		"machine instruction expected after instruction prefix\n");
-				del_asm86(a);
-				return nil;
-			}
-			break;
-		}
-
-		/* Skip the prefix and extra newlines. */
-		do {
-			skip_token(1);
-		} while ((t= get_token(0))->symbol == ';');
-	}
-
-	/* All the readahead being done upsets the line counter. */
-	a->line= t->line;
-
-	/* Read a machine instruction or pseudo op. */
-	if ((m= search_mnem(t->name)) == nil) {
-		parse_err(1, t, "unknown instruction '%s'\n", t->name);
-		del_asm86(a);
-		return nil;
-	}
-	a->opcode= m->opcode;
-	a->optype= m->optype;
-	a->oaz= 0;
-	if (a->optype == OWORD) {
-		a->oaz|= OPZ;
-		a->optype= WORD;
-	}
-
-	switch (a->opcode) {
-	case IN:
-	case OUT:
-	case INT:
-		deref= 0;
-		break;
-	default:
-		deref= (a->optype >= BYTE);
-	}
-	n= 1;
-	if (get_token(1)->symbol != ';'
-			&& (a->args= gnu_get_oplist(&n, deref)) == nil) {
-		del_asm86(a);
-		return nil;
-	}
-	if (get_token(n)->symbol != ';') {
-		parse_err(1, t, "garbage at end of instruction\n");
-		del_asm86(a);
-		return nil;
-	}
-	if (!is_pseudo(a->opcode)) {
-		/* GNU operand order is the other way around. */
-		expression_t *e, *t;
-
-		e= a->args;
-		while (e != nil && e->operator == ',') {
-			t= e->right; e->right= e->left; e->left= t;
-			e= e->left;
-		}
-	}
-	switch (a->opcode) {
-	case DOT_ALIGN:
-		/* Delete two argument .align, because ACK can't do it.
-		 * Raise 2 to the power of .align's argument.
-		 */
-		if (a->args == nil || a->args->operator != 'W') {	
-			del_asm86(a);
-			return nil;
-		}
-		if (a->args != nil && a->args->operator == 'W'
-			&& isanumber(a->args->name)
-		) {	
-			unsigned n;
-			char num[sizeof(int) * CHAR_BIT / 3 + 1];
-
-			n= 1 << strtoul(a->args->name, nil, 0);
-			sprintf(num, "%u", n);
-			deallocate(a->args->name);
-			a->args->name= copystr(num);
-		}
-		break;
-	case JMPF:
-	case CALLF:
-		/*FALL THROUGH*/
-	case JMP:
-	case CALL:
-		break;
-	default:;
-	}
-	skip_token(n+1);
-	return a;
-}
-
-
-asm86_t *gnu_get_instruction(void)
-{
-	asm86_t *a= nil;
-	expression_t *e;
-	token_t *t;
-
-	while ((t= get_token(0))->symbol == ';' || t->symbol == '/') {
-		zap();		/* if a comment started by a '/' */
-		skip_token(1);
-	}
-
-	if (t->type == T_EOF) return nil;
-
-	if (t->symbol == '#') {
-		/* Preprocessor line and file change. */
-
-		if ((t= get_token(1))->type != T_WORD || !isanumber(t->name)
-			|| get_token(2)->type != T_STRING
-		) {
-			parse_err(1, t, "file not preprocessed?\n");
-			zap();
-		} else {
-			set_file(get_token(2)->name,
-				strtol(get_token(1)->name, nil, 0) - 1);
-
-			/* GNU CPP adds extra cruft, simply zap the line. */
-			zap();
-		}
-		a= gnu_get_instruction();
-	} else
-	if (t->type == T_WORD && get_token(1)->symbol == ':') {
-		/* A label definition. */
-
-		a= new_asm86();
-		a->line= t->line;
-		a->opcode= DOT_LABEL;
-		a->optype= PSEUDO;
-		a->args= e= new_expr();
-		e->operator= ':';
-		e->name= copystr(t->name);
-		skip_token(2);
-	} else
-	if (t->type == T_WORD && get_token(1)->symbol == '=') {
-		int n= 2;
-
-		if ((e= gnu_get_C_expression(&n)) == nil) {
-			zap();
-			a= gnu_get_instruction();
-		} else
-		if (get_token(n)->symbol != ';') {
-			parse_err(1, t, "garbage after assignment\n");
-			zap();
-			a= gnu_get_instruction();
-		} else {
-			a= new_asm86();
-			a->line= t->line;
-			a->opcode= DOT_EQU;
-			a->optype= PSEUDO;
-			a->args= new_expr();
-			a->args->operator= '=';
-			a->args->name= copystr(t->name);
-			a->args->middle= e;
-			skip_token(n+1);
-		}
-	} else
-	if (t->type == T_WORD) {
-		if ((a= gnu_get_statement()) == nil) {
-			zap();
-			a= gnu_get_instruction();
-		}
-	} else {
-		parse_err(1, t, "syntax error\n");
-		zap();
-		a= gnu_get_instruction();
-	}
-	return a;
-}
Index: trunk/minix/commands/i386/asmconv/syntax.ack
===================================================================
--- trunk/minix/commands/i386/asmconv/syntax.ack	(revision 9)
+++ 	(revision )
@@ -1,107 +1,0 @@
-asmprog:
-	comment ?
-	statement
-	asmprog ; asmprog
-	asmprog comment ? \n asmprog
-
-letter:
-	[._a-zA-Z]
-
-digit:
-	[0-9]
-
-identifier:
-	letter (letter | digit)*
-	digit [bf]
-
-string:
-	'C-like string sequence'
-	"C-like string sequence"
-
-number:
-	C-like number
-
-comment:
-	! .*
-
-statement:
-	label-definition statement
-	empty
-	assignment
-	instruction
-	pseudo-instruction
-
-label-definition:
-	identifier :
-	digit :
-
-assignment:
-	identifier = expression
-
-instruction:
-	iX86-instruction
-
-pseudo-instruction:
-	.extern identifier (, identifier)*
-	.define identifier (, identifier)*
-	.data1 expression (, expression)*
-	.data2 expression (, expression)*
-	.data4 expression (, expression)*
-	.ascii string
-	.asciz string
-	.align expression
-	.space expression
-	.comm identifier , expression
-	.sect identifier
-	.base expression
-	.assert expression
-	.symb XXX
-	.line XXX
-	.file XXX
-	.nolist
-	.list
-	iX86-pseudo
-
-expression:
-	C-like expression with [ and ] for grouping
-
-iX86-instruction:
-	prefix
-	prefix iX86-instruction
-	identifier
-	identifier iX86operand
-	identifier iX86operand , iX86operand
-	identifier iX86operand : iX86operand
-
-prefix:
-	o16
-	o32
-	a16
-	a32
-	rep
-	repz
-	repnz
-	repe
-	repne
-	cseg | dseg | eseg | fseg | gseg | sseg
-
-iX86operand:
-	register
-	( register )
-	expression
-	( expression )
-	expression ( register )
-	expression ( register * [1248] )
-	expression ? ( register ) ( register )
-	expression ? ( register ) ( register * [1248] )
-
-register:
-	al | bl | cl | dl | ah | bh | ch | dh
-	ax | bx | cx | dx | si | di | bp | sp
-	eax | ebx | ecx | edx | esi | edi | ebp | esp
-	cs | ds | es | fs | gs | ss
-	cr0 | cr1 | cr2 | cr3
-
-iX86-pseudo:
-	.use16
-	.use32
Index: trunk/minix/commands/i386/asmconv/token.h
===================================================================
--- trunk/minix/commands/i386/asmconv/token.h	(revision 9)
+++ 	(revision )
@@ -1,29 +1,0 @@
-/*	token.h - token definition			Author: Kees J. Bot
- *								13 Dec 1993
- */
-
-typedef enum toktype {
-	T_EOF,
-	T_CHAR,
-	T_WORD,
-	T_STRING
-} toktype_t;
-
-typedef struct token {
-	struct token	*next;
-	long		line;
-	toktype_t	type;
-	int		symbol;		/* Single character symbol. */
-	char		*name;		/* Word, number, etc. */
-	size_t		len;		/* Length of string. */
-} token_t;
-
-#define S_LEFTSHIFT	0x100		/* << */
-#define S_RIGHTSHIFT	0x101		/* >> */
-
-void set_file(char *file, long line);
-void get_file(char **file, long *line);
-void parse_err(int err, token_t *where, const char *fmt, ...);
-void tok_init(char *file, int comment);
-token_t *get_token(int n);
-void skip_token(int n);
Index: trunk/minix/commands/i386/asmconv/tokenize.c
===================================================================
--- trunk/minix/commands/i386/asmconv/tokenize.c	(revision 9)
+++ 	(revision )
@@ -1,306 +1,0 @@
-/*	tokenize.c - split input into tokens		Author: Kees J. Bot
- *								13 Dec 1993
- */
-#define nil 0
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include "asmconv.h"
-#include "token.h"
-
-static FILE *tf;
-static char *tfile;
-static char *orig_tfile;
-static int tcomment;
-static int tc;
-static long tline;
-static token_t *tq;
-
-static void readtc(void)
-/* Read one character from the input file and put it in the global 'tc'. */
-{
-	static int nl= 0;
-
-	if (nl) tline++;
-	if ((tc= getc(tf)) == EOF && ferror(tf)) fatal(orig_tfile);
-	nl= (tc == '\n');
-}
-
-void set_file(char *file, long line)
-/* Set file name and line number, changed by a preprocessor trick. */
-{
-	deallocate(tfile);
-	tfile= allocate(nil, (strlen(file) + 1) * sizeof(tfile[0]));
-	strcpy(tfile, file);
-	tline= line;
-}
-
-void get_file(char **file, long *line)
-/* Get file name and line number. */
-{
-	*file= tfile;
-	*line= tline;
-}
-
-void parse_err(int err, token_t *t, const char *fmt, ...)
-/* Report a parsing error. */
-{
-	va_list ap;
-
-	fprintf(stderr, "\"%s\", line %ld: ", tfile,
-						t == nil ? tline : t->line);
-	va_start(ap, fmt);
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
-	if (err) set_error();
-}
-
-void tok_init(char *file, int comment)
-/* Open the file to tokenize and initialize the tokenizer. */
-{
-	if (file == nil) {
-		file= "stdin";
-		tf= stdin;
-	} else {
-		if ((tf= fopen(file, "r")) == nil) fatal(file);
-	}
-	orig_tfile= file;
-	set_file(file, 1);
-	readtc();
-	tcomment= comment;
-}
-
-static int isspace(int c)
-{
-	return between('\0', c, ' ') && c != '\n';
-}
-
-#define iscomment(c)	((c) == tcomment)
-
-static int isidentchar(int c)
-{
-	return between('a', c, 'z')
-		|| between('A', c, 'Z')
-		|| between('0', c, '9')
-		|| c == '.'
-		|| c == '_'
-		;
-}
-
-static token_t *new_token(void)
-{
-	token_t *new;
-
-	new= allocate(nil, sizeof(*new));
-	new->next= nil;
-	new->line= tline;
-	new->name= nil;
-	new->symbol= -1;
-	return new;
-}
-
-static token_t *get_word(void)
-/* Read one word, an identifier, a number, a label, or a mnemonic. */
-{
-	token_t *w;
-	char *name;
-	size_t i, len;
-
-	i= 0;
-	len= 16;
-	name= allocate(nil, len * sizeof(name[0]));
-
-	while (isidentchar(tc)) {
-		name[i++]= tc;
-		readtc();
-		if (i == len) name= allocate(name, (len*= 2) * sizeof(name[0]));
-	}
-	name[i]= 0;
-	name= allocate(name, (i+1) * sizeof(name[0]));
-	w= new_token();
-	w->type= T_WORD;
-	w->name= name;
-	w->len= i;
-	return w;
-}
-
-static token_t *get_string(void)
-/* Read a single or double quotes delimited string. */
-{
-	token_t *s;
-	int quote;
-	char *str;
-	size_t i, len;
-	int n, j;
-	int seen;
-
-	quote= tc;
-	readtc();
-
-	i= 0;
-	len= 16;
-	str= allocate(nil, len * sizeof(str[0]));
-
-	while (tc != quote && tc != '\n' && tc != EOF) {
-		seen= -1;
-		if (tc == '\\') {
-			readtc();
-			if (tc == '\n' || tc == EOF) break;
-
-			switch (tc) {
-			case 'a':	tc= '\a'; break;
-			case 'b':	tc= '\b'; break;
-			case 'f':	tc= '\f'; break;
-			case 'n':	tc= '\n'; break;
-			case 'r':	tc= '\r'; break;
-			case 't':	tc= '\t'; break;
-			case 'v':	tc= '\v'; break;
-			case 'x':
-				n= 0;
-				for (j= 0; j < 3; j++) {
-					readtc();
-					if (between('0', tc, '9'))
-						tc-= '0' + 0x0;
-					else
-					if (between('A', tc, 'A'))
-						tc-= 'A' + 0xA;
-					else
-					if (between('a', tc, 'a'))
-						tc-= 'a' + 0xa;
-					else {
-						seen= tc;
-						break;
-					}
-					n= n*0x10 + tc;
-				}
-				tc= n;
-				break;
-			default:
-				if (!between('0', tc, '9')) break;
-				n= 0;
-				for (j= 0; j < 3; j++) {
-					if (between('0', tc, '9'))
-						tc-= '0';
-					else {
-						seen= tc;
-						break;
-					}
-					n= n*010 + tc;
-					readtc();
-				}
-				tc= n;
-			}
-		}
-		str[i++]= tc;
-		if (i == len) str= allocate(str, (len*= 2) * sizeof(str[0]));
-
-		if (seen < 0) readtc(); else tc= seen;
-	}
-
-	if (tc == quote) {
-		readtc();
-	} else {
-		parse_err(1, nil, "string contains newline\n");
-	}
-	str[i]= 0;
-	str= allocate(str, (i+1) * sizeof(str[0]));
-	s= new_token();
-	s->type= T_STRING;
-	s->name= str;
-	s->len= i;
-	return s;
-}
-
-static int old_n= 0;		/* To speed up n, n+1, n+2, ... accesses. */
-static token_t **old_ptq= &tq;
-
-token_t *get_token(int n)
-/* Return the n-th token on the input queue. */
-{
-	token_t *t, **ptq;
-
-	assert(n >= 0);
-
-	if (0 && n >= old_n) {
-		/* Go forward from the previous point. */
-		n-= old_n;
-		old_n+= n;
-		ptq= old_ptq;
-	} else {
-		/* Restart from the head of the queue. */
-		old_n= n;
-		ptq= &tq;
-	}
-
-	for (;;) {
-		if ((t= *ptq) == nil) {
-			/* Token queue doesn't have element <n>, read a
-			 * new token from the input stream.
-			 */
-			while (isspace(tc) || iscomment(tc)) {
-				if (iscomment(tc)) {
-					while (tc != '\n' && tc != EOF)
-						readtc();
-				} else {
-					readtc();
-				}
-			}
-
-			if (tc == EOF) {
-				t= new_token();
-				t->type= T_EOF;
-			} else
-			if (isidentchar(tc)) {
-				t= get_word();
-			} else
-			if (tc == '\'' || tc == '"') {
-				t= get_string();
-			} else {
-				if (tc == '\n') tc= ';';
-				t= new_token();
-				t->type= T_CHAR;
-				t->symbol= tc;
-				readtc();
-				if (t->symbol == '<' && tc == '<') {
-					t->symbol= S_LEFTSHIFT;
-					readtc();
-				} else
-				if (t->symbol == '>' && tc == '>') {
-					t->symbol= S_RIGHTSHIFT;
-					readtc();
-				}
-			}
-			*ptq= t;
-		}
-		if (n == 0) break;
-		n--;
-		ptq= &t->next;
-	}
-	old_ptq= ptq;
-	return t;
-}
-
-void skip_token(int n)
-/* Remove n tokens from the input queue.  One is not allowed to skip unread
- * tokens.
- */
-{
-	token_t *junk;
-
-	assert(n >= 0);
-
-	while (n > 0) {
-		assert(tq != nil);
-
-		junk= tq;
-		tq= tq->next;
-		deallocate(junk->name);
-		deallocate(junk);
-		n--;
-	}
-	/* Reset the old reference. */
-	old_n= 0;
-	old_ptq= &tq;
-}
Index: trunk/minix/commands/i386/build
===================================================================
--- trunk/minix/commands/i386/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/i386/mtools-3.9.7/COPYING
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/COPYING	(revision 9)
+++ 	(revision )
@@ -1,351 +1,0 @@
-Copyright (C) 1995 Alain Knaff.
- You may use, distribute and copy this program according to the terms of the
-GNU General Public License version 2 or later.
-
- Alain Knaff
-----------------------------------------
-
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-                          675 Mass Ave, Cambridge, MA 02139, USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-
-	Appendix: How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) 19yy  <name of author>
-
-    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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) 19yy name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
Index: trunk/minix/commands/i386/mtools-3.9.7/Makefile
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/Makefile	(revision 9)
+++ 	(revision )
@@ -1,399 +1,0 @@
-# Generated automatically from Makefile.in by configure.
-#
-#       Makefile for Mtools
-#
-# check the Configure file for some examples of device-specific setups
-# Berkeley flavors of Unix should include -DBSD in the CFLAGS.  Pick
-# a lock method... either -DLOCKF, -DFLOCK, or -DFCNTL and put that
-# string in the CFLAGS line below.
-
-# User specified flags
-USERCFLAGS = 
-USERLDFLAGS = -stack 11m
-USERLDLIBS =
-
-MAKEINFO = makeinfo
-TEXI2DVI = texi2dvi
-TEXI2HTML = texi2html
-
-
-# do not edit below this line
-# =============================================================================
-
-SHELL = /bin/sh
-
-top_srcdir=.
-srcdir=.
-
-prefix      = /usr
-exec_prefix = ${prefix}
-bindir      = ${exec_prefix}/bin
-infodir     = ${prefix}/info
-mandir      = ${prefix}/man
-infodir     = ${prefix}/info
-sysconfdir  = /etc
-
-CC         = exec cc -D_MINIX
-CXX        = @CXX@
-MYCFLAGS   = 
-MYCXXFLAGS = 
-CPPFLAGS   = 
-HOST_ID    = -DCPU_i386 -DVENDOR_pc -DOS_Minix 
-DEFS       = -DHAVE_CONFIG_H -DNO_CONFIG $(HOST_ID)
-
-LDFLAGS     = 
-LIBS        = 
-SHLIB       = 
-MACHDEPLIBS = 	
-LN_S        = ln -s
-
-INSTALL         = /usr/bin/install -cs
-INSTALL_PROGRAM = ${INSTALL}
-INSTALL_DATA    = ${INSTALL} -m 644
-INSTALL_INFO	= 
-
-.SUFFIXES:
-.SUFFIXES: .o .c
-.SUFFIXES: .o .c
-
-MAN1 = floppyd.1 mattrib.1 mbadblocks.1 mcat.1 mcd.1 mcopy.1 mdel.1 mdeltree.1 mdir.1 \
-mdu.1 mformat.1 mkmanifest.1 mlabel.1 mmd.1 mmount.1 mmove.1 mpartition.1 \
-mrd.1 mread.1 mren.1 mshowfat.1 mtoolstest.1 mtools.1 mtype.1 mzip.1
-MAN1EXT	= 1
-MAN1DIR	= $(mandir)/man${MAN1EXT}
-MAN5	= mtools.5
-MAN5EXT	= 5
-MAN5DIR	= $(mandir)/man${MAN5EXT}
-
-# all files in this directory included in the distribution 
-DIST = \
-COPYING Changelog INSTALL Makefile Makefile.in README Release.notes \
-buffer.c buffer.h codepage.c codepage.h codepages.c config.c \
-config.guess config.h.in config.log config.sub configure configure.in \
-copyfile.c devices.c devices.h dirCache.c dirCache.h directory.c direntry.c \
-expand.c fat.c \
-fat_free.c file.c file.h file_name.c file_read.c files filter.c floppyd.1 \
-floppyd.c floppyd_io.c floppyd_io.h force_io.c fs.h fsP.h \
-getopt.h hash.c htable.h init.c llong.c mainloop.c match.c mattrib.1 \
-mattrib.c mbadblocks.1 mbadblocks.c mcat.1 mcat.c mcd.1 mcd.c mcopy.1 \
-mcopy.c mdel.1 mdel.c mdeltree.1 mdir.1 mdir.c mdu.c mdu.1 mformat.1 \
-mformat.c minfo.c \
-misc.c tty.c scsi.c missFuncs.c mk_direntry.c mkmanifest.1 mkmanifest.c \
-mlabel.1 mlabel.c mmd.1 mmd.c mmount.1 mmount.c mmove.1 mmove.c \
-mpartition.1 mpartition.c mrd.1 \
-mread.1 mren.1 msdos.h mshowfat.1 mtoolstest.1 mtools.1 mtools.5 mtools.c \
-mtools.conf mtools.h mtype.1 nameclash.h patchlevel.c \
-plain_io.c plain_io.h precmd.c privileges.c scripts signal.c stream.c stream.h \
-streamcache.c streamcache.h subdir.c sysincludes.h unixdir.c todo toupper.c \
-vfat.c vfat.h xdf_io.c xdf_io.h
-
-#OBJS1 = buffer.o codepage.o codepages.o config.o copyfile.o devices.o \
-#dirCache.o directory.o direntry.o expand.o fat.o fat_free.o file.o file_name.o \
-#file_read.o filter.o floppyd_io.o force_io.o hash.o init.o llong.o match.o \
-#mainloop.o mattrib.o mbadblocks.o mcat.o mcd.o mcopy.o mdel.o mdir.o \
-#mdoctorfat.o mdu.o \
-#mformat.o minfo.o misc.o missFuncs.o mk_direntry.o mlabel.o mmd.o mmount.o \
-#mmove.o mpartition.o mshowfat.o mzip.o mtools.o patchlevel.o plain_io.o \
-#precmd.o privileges.o scsi.o signal.o stream.o streamcache.o subdir.o \
-#unixdir.o toupper.o tty.o vfat.o xdf_io.o
-
-OBJS1 = buffer.o config.o copyfile.o devices.o \
-dirCache.o directory.o direntry.o expand.o fat.o fat_free.o file.o file_name.o \
-file_read.o filter.o floppyd_io.o force_io.o hash.o init.o llong.o match.o \
-mainloop.o mattrib.o mbadblocks.o mcat.o mcd.o mcopy.o mdel.o mdir.o \
-mdoctorfat.o mdu.o \
-mformat.o minfo.o misc.o missFuncs.o mk_direntry.o mlabel.o mmd.o mmount.o \
-mmove.o mpartition.o mshowfat.o mtools.o patchlevel.o plain_io.o \
-precmd.o privileges.o scsi.o signal.o stream.o streamcache.o subdir.o \
-unixdir.o toupper.o tty.o vfat.o xdf_io.o
-
-OBJS2 = missFuncs.o mkmanifest.o misc.o patchlevel.o
-
-SRCS3 = floppyd.c
-
-OBJS4 = floppyd_installtest.o misc.o expand.o privileges.o
-
-SRCS = buffer.c codepage.c codepages.c config.c copyfile.c devices.c \
-dirCache.c directory.c direntry.c expand.c fat.c fat_free.c file.c file_name.c \
-file_read.c filter.c floppyd_io.c force_io.c hash.c init.c match.c mainloop.c \
-mattrib.c mbadblocks.c mcat.c mcd.c mcopy.c mdel.c mdir.c mdu.c mdoctorfat.c \
-mformat.c minfo.c misc.c \
-missFuncs.c mk_direntry.c mlabel.c mmd.c mmount.c mmove.c mpartition.c \
-mshowfat.c mzip.c mtools.c plain_io.c precmd.c privileges.c scsi.o \
-signal.c stream.c streamcache.c subdir.c unixdir.c toupper.c tty.o vfat.c \
-xdf_io.c mkmanifest.c
-
-
-SCRIPTS = mcheck mxtar uz tgz mcomp
-
-LINKS=mattrib mcat mcd mcopy mdel mdeltree mdir mdu mformat minfo mlabel \
-mmd mmount mmove mpartition mrd mread mren mtype mtoolstest mshowfat \
-mbadblocks mzip
-
-X_CFLAGS = 
-X_LIBS = 
-X_EXTRA_LIBS = 
-X_PRE_LIBS = 
-CFLAGS = $(CPPFLAGS) $(DEFS) $(MYCFLAGS) -I.  -I. $(USERCFLAGS) 
-CXXFLAGS  = $(CPPFLAGS) $(DEFS) $(MYCXXFLAGS) -I.  -I. $(USERCFLAGS) 
-LINK      = $(CC) $(LDFLAGS) $(USERLDFLAGS) 
-ALLLIBS   = $(USERLDLIBS) $(MACHDEPLIBS) $(SHLIB) $(LIBS)
-X_LDFLAGS = $(X_EXTRA_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lXau -lX11 $(LIBS) 
-X_CCFLAGS = $(X_CFLAGS) $(CFLAGS)
-
-all:    mtools
-
-%.o: %.c
-	$(CC) $(CFLAGS) -c $<
-
-#%.o: %.cpp
-#	$(CXX) $(CXXFLAGS) -c $<
-
-mtools: $(OBJS1)
-	$(LINK) $(OBJS1) -o $@ $(ALLLIBS)
-
-mkmanifest: $(OBJS2)
-	$(LINK) $(OBJS2) -o $@ $(ALLLIBS)
-
-floppyd.o: floppyd.c
-	$(CC) $(X_CCFLAGS) -c $<
-
-floppyd: floppyd.o
-	$(LINK) $< -o $@ $(X_LDFLAGS)
-floppyd_installtest: $(OBJS4)
-	$(LINK) $(OBJS4) -o $@ $(ALLLIBS)
-
-
-$(LINKS): mtools
-	rm -f $@ && $(LN_S) mtools $@
-
-mostlyclean:
-	-rm -f *~ *.orig *.o a.out core 2>/dev/null
-
-clean:	mostlyclean
-	-rm -f mtools $(LINKS) floppyd floppyd_installtest mkmanifest *.info* *.dvi *.html 2>/dev/null
-
-
-texclean:
-	-rm mtools.aux mtools.toc mtools.log
-	-rm mtools.cps mtools.pgs mtools.vrs
-	-rm mtools.cp mtools.fn mtools.ky
-	-rm mtools.pg mtools.tp mtools.vr
-
-info: mtools.info
-%.info: %.texi
-	$(MAKEINFO) -I$(srcdir) $< --no-split --output=$@
-
-dvi: mtools.dvi
-%.dvi: %.texi
-	$(TEXI2DVI) $<
-
-ps: mtools.ps
-%.ps: %.dvi
-	dvips -f < $< > $@
-
-pdf: mtools.pdf
-%.pdf: %.ps
-	ps2pdf $< $@
-
-
-html: mtools.html mtools_toc.html
-%.html %_toc.html: %.texi
-	$(TEXI2HTML) $<
-
-# Don't cd, to avoid breaking install-sh references.
-install-info: info
-	$(top_srcdir)/mkinstalldirs $(infodir)
-	if test -f mtools.info; then \
-	  for i in mtools.info*; do \
-	    $(INSTALL_DATA) $$i $(infodir)/$$i; \
-	  done; \
-	else \
-	  for i in $(srcdir)/mtools.info*; do \
-	    $(INSTALL_DATA) $$i $(infodir)/`echo $$i | sed 's|^$(srcdir)/||'`; \
-	  done; \
-	fi; \
-	if [ -n "$(INSTALL_INFO)" ] ; then \
-		if [ -f $(infodir)/dir.info ] ; then \
-			$(INSTALL_INFO) $(infodir)/mtools.info $(infodir)/dir.info; \
-		fi; \
-		if [ -f $(infodir)/dir ] ; then \
-			$(INSTALL_INFO) $(infodir)/mtools.info $(infodir)/dir; \
-		fi; \
-	fi
-
-uninstall-info:
-	cd $(infodir) && rm -f mtools.info*
-
-install:	$(bindir)/mtools
-
-# The manual pages are of such horrible quality that one is better off without
-# them.  (Frankly this whole package is horrible.)  Using -? hopefully gives
-# enough clues for use.  -- kjb
-dontinstall:
-		$(MAN1DIR)/mattrib.1 $(MAN1DIR)/mbadblocks.1 \
-		$(MAN1DIR)/mcd.1 $(MAN1DIR)/mcopy.1 $(MAN1DIR)/mdel.1 \
-		$(MAN1DIR)/mdeltree.1 $(MAN1DIR)/mdir.1 $(MAN1DIR)/mdu.1 \
-		$(MAN1DIR)/mformat.1 $(MAN1DIR)/mlabel.1 \
-		$(MAN1DIR)/mmd.1 $(MAN1DIR)/mmove.1 $(MAN1DIR)/mrd.1 \
-		$(MAN1DIR)/mread.1 $(MAN1DIR)/mren.1 \
-		$(MAN1DIR)/mshowfat.1 $(MAN1DIR)/mtools.1 \
-		$(MAN1DIR)/mtype.1 $(MAN1DIR)/mzip.1
-
-$(bindir)/mtools:	mtools
-	install -c $? $@
-
-$(MAN1DIR)/mattrib.1:	mattrib.1
-	install -lc $? $@
-
-$(MAN1DIR)/mbadblocks.1:	mbadblocks.1
-	install -lc $? $@
-
-$(MAN1DIR)/mcd.1:	mcd.1
-	install -lc $? $@
-
-$(MAN1DIR)/mcopy.1:	mcopy.1
-	install -lc $? $@
-
-$(MAN1DIR)/mdel.1:	mdel.1
-	install -lc $? $@
-
-$(MAN1DIR)/mdeltree.1:	mdeltree.1
-	install -lc $? $@
-
-$(MAN1DIR)/mdir.1:	mdir.1
-	install -lc $? $@
-
-$(MAN1DIR)/mdu.1:	mdu.1
-	install -lc $? $@
-
-$(MAN1DIR)/mformat.1:	mformat.1
-	install -lc $? $@
-
-$(MAN1DIR)/mlabel.1:	mlabel.1
-	install -lc $? $@
-
-$(MAN1DIR)/mmd.1:	mmd.1
-	install -lc $? $@
-
-$(MAN1DIR)/mmove.1:	mmove.1
-	install -lc $? $@
-
-$(MAN1DIR)/mrd.1:	mrd.1
-	install -lc $? $@
-
-$(MAN1DIR)/mread.1:	mread.1
-	install -lc $? $@
-
-$(MAN1DIR)/mren.1:	mren.1
-	install -lc $? $@
-
-$(MAN1DIR)/mshowfat.1:	mshowfat.1
-	install -lc $? $@
-
-$(MAN1DIR)/mtools.1:	mtools.1
-	install -lc $? $@
-
-$(MAN1DIR)/mtype.1:	mtype.1
-	install -lc $? $@
-
-$(MAN1DIR)/mzip.1:	mzip.1
-	install -lc $? $@
-
-#install:	$(bindir)/mtools  install-man install-links \
-#		$(bindir)/mkmanifest install-scripts install-info
-#
-#uninstall:	uninstall-bin uninstall-man uninstall-links \
-#		uninstall-scripts
-
-distclean: clean texclean
-	rm -f config.cache config.h config.status config.log Makefile
-maintainer-clean: distclean
-
-
-#$(bindir)/floppyd: floppyd
-#	$(top_srcdir)/mkinstalldirs $(bindir)
-#	$(INSTALL_PROGRAM) floppyd $(bindir)/floppyd
-#
-#$(bindir)/floppyd_installtest: floppyd_installtest
-#	$(top_srcdir)/mkinstalldirs $(bindir)
-#	$(INSTALL_PROGRAM) floppyd_installtest $(bindir)/floppyd_installtest
-#
-#$(bindir)/mtools: mtools
-#	$(top_srcdir)/mkinstalldirs $(bindir)
-#	$(INSTALL_PROGRAM) mtools $(bindir)/mtools
-#
-#$(bindir)/mkmanifest: mkmanifest
-#	$(top_srcdir)/mkinstalldirs $(bindir)
-#	$(INSTALL_PROGRAM) mkmanifest $(bindir)/mkmanifest
-
-#$(ETCDIR)/mtools: mtools.etc
-#	cp mtools.etc $(ETCDIR)/mtools
-
-install-links: $(bindir)/mtools
-	@for j in $(LINKS); do \
-		rm -f $(bindir)/$$j ; \
-		$(LN_S) mtools $(bindir)/$$j ; \
-		echo $(bindir)/$$j ; \
-	done
-
-## "z" is the older version of "gz"; the name is just *too* short
-install-scripts: $(bindir)/mtools
-	@$(top_srcdir)/mkinstalldirs $(bindir)
-	@for j in $(SCRIPTS) ; do \
-		$(INSTALL_PROGRAM) $(srcdir)/scripts/$$j $(bindir)/$$j ; \
-		echo $(bindir)/$$j ; \
-	done
-	rm -f $(bindir)/lz
-	$(LN_S) uz $(bindir)/lz
-
-install-man:
-	@$(top_srcdir)/mkinstalldirs $(MAN1DIR)
-	@for j in $(MAN1); do \
-		$(INSTALL_DATA) $(srcdir)/$$j $(MAN1DIR)/$$j ; \
-		echo $(MAN1DIR)/$$j ; \
-	done
-	@$(top_srcdir)/mkinstalldirs $(MAN5DIR)
-	@for j in $(MAN5); do \
-		$(INSTALL_DATA) $(srcdir)/$$j $(MAN5DIR)/$$j ; \
-		echo $(MAN5DIR)/$$j ; \
-	done
-
-uninstall-bin:
-	@for j in mtools mkmanifest; do \
-		rm -f $(bindir)/$$j ; \
-		echo $(bindir)/$$j ; \
-	done
-
-uninstall-scripts:
-	@for j in $(SCRIPTS); do \
-		rm -f $(bindir)/$$j ; \
-		echo $(bindir)/$$j ; \
-	done
-
-uninstall-man:
-	@for j in $(MAN1); do \
-		rm -f $(MAN1DIR)/$$j ; \
-		echo $(MAN1DIR)/$$j ; \
-	done
-	@for j in $(MAN5); do \
-		rm -f $(MAN5DIR)/$$j ; \
-		echo $(MAN5DIR)/$$j ; \
-	done
-
-uninstall-links:
-	@for j in $(LINKS); \
-		do rm -f $(bindir)/$$j ; \
-		echo $(bindir)/$$j ; \
-	done
-
-depend: $(SRCS)
-	makedepend -- $(CFLAGS) -- $^
-
-check:
-	echo No self tests included
-# check target needed even if empty, in order to make life easyer for
-# automatic tools to install GNU soft
-
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
Index: trunk/minix/commands/i386/mtools-3.9.7/README
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/README	(revision 9)
+++ 	(revision )
@@ -1,53 +1,0 @@
-Compilation
------------
-
- Type 'make install'.
-
- This package has been heavily modified for Minix, and then minimized to
-only those files needed for Minix.  Don't use this as a basis for anything
-else, get the original package instead.  -- kjb
-
-Doc
----
-
- The most uptodate doc of this package is the texinfo doc. Type 'make
-info' to get online info doc, and 'make dvi ; dvips mtools.dvi' to get
-a printed copy.  The info doc has a concept index.  Make use of it.
- You may get an info copy using the following command 'make info'.
-This can then be viewed using emacs' info mode, or using a standalone
-info viewer.
- Man pages are still present, but contain less information, and are
-less uptodate than the texinfo documentation.
- If you do not have the necessary tools to view the texinfo doc, you
-may also find it on the Workd Wide Web at the following locations:
-  http://mtools.linux.lu/mtools_toc.html
-  http://www.tux.org/pub/knaff/mtools/mtools_toc.html
-
-Compiler
---------
-
- Mtools should be compiled with an Ansi compiler, preferably gcc
-
-Authors
--------
-
-Original code (versions through 2.0.7?) by Emmet P. Gray (Texas, USA), who
-no longer appears to be reachable by Internet e-mail.  Viktor Dukhovni (at
-Princeton, USA) had major input into v2.0.
-
-Since 2.0.7: maintained primarily and until now informally by Alain
-Knaff (Luxembourg) and David Niemi (Reston, Virginia, USA).
-
-Please report bugs to the mtools mailing list at mtools@www.tux.org.
-Before reporting any problems, check whether they have already been
-fixed in the Alpha patches at http://mtools.linux.lu and
-http://www.tux.org/pub/knaff
-
-You may subscribe to the mtools mailing list by sending a message
-containing 'subscribe mtools' in its body to majordomo@www.tux.org
-
-
-Current Status
---------------
-
-Stable release 3.3.
Index: trunk/minix/commands/i386/mtools-3.9.7/buffer.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/buffer.c	(revision 9)
+++ 	(revision )
@@ -1,365 +1,0 @@
-/*
- * Buffer read/write module
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "buffer.h"
-
-typedef struct Buffer_t {
-	Class_t *Class;
-	int refs;
-	Stream_t *Next;
-	Stream_t *Buffer;
-	
-	size_t size;     	/* size of read/write buffer */
-	int dirty;	       	/* is the buffer dirty? */
-
-	int sectorSize;		/* sector size: all operations happen
-				 * in multiples of this */
-	int cylinderSize;	/* cylinder size: preferred alignemnt,
-				 * but for efficiency, less data may be read */
-	int ever_dirty;	       	/* was the buffer ever dirty? */
-	int dirty_pos;
-	int dirty_end;
-	mt_off_t current;		/* first sector in buffer */
-	size_t cur_size;		/* the current size */
-	char *buf;		/* disk read/write buffer */
-} Buffer_t;
-
-/*
- * Flush a dirty buffer to disk.  Resets Buffer->dirty to zero.
- * All errors are fatal.
- */
-
-static int _buf_flush(Buffer_t *Buffer)
-{
-	int ret;
-
-	if (!Buffer->Next || !Buffer->dirty)
-		return 0;
-	if(Buffer->current < 0L) {
-		fprintf(stderr,"Should not happen\n");
-		return -1;
-	}
-#ifdef DEBUG
-	fprintf(stderr, "write %08x -- %02x %08x %08x\n",
-		Buffer,
-		(unsigned char) Buffer->buf[0],
-		Buffer->current + Buffer->dirty_pos,
-		Buffer->dirty_end - Buffer->dirty_pos);
-#endif
-
-	ret = force_write(Buffer->Next, 
-			  Buffer->buf + Buffer->dirty_pos,
-			  Buffer->current + Buffer->dirty_pos,
-			  Buffer->dirty_end - Buffer->dirty_pos);
-	if(ret != Buffer->dirty_end - Buffer->dirty_pos) {
-		if(ret < 0)
-			perror("buffer_flush: write");
-		else
-			fprintf(stderr,"buffer_flush: short write\n");
-		return -1;
-	}
-	Buffer->dirty = 0;
-	Buffer->dirty_end = 0;
-	Buffer->dirty_pos = 0;
-	return 0;
-}
-
-static int invalidate_buffer(Buffer_t *Buffer, mt_off_t start)
-{
-	/*fprintf(stderr, "invalidate %x\n", Buffer);*/
-	if(Buffer->sectorSize == 32) {
-		fprintf(stderr, "refreshing directory\n");
-	}
-
-	if(_buf_flush(Buffer) < 0)
-		return -1;
-
-	/* start reading at the beginning of start's sector
-	 * don't start reading too early, or we might not even reach
-	 * start */
-	Buffer->current = ROUND_DOWN(start, Buffer->sectorSize);
-	Buffer->cur_size = 0;
-	return 0;
-}
-
-#undef OFFSET
-#define OFFSET (start - This->current)
-
-typedef enum position_t {
-	OUTSIDE,
-	APPEND,
-	INSIDE,
-	ERROR 
-} position_t;
-
-static position_t isInBuffer(Buffer_t *This, mt_off_t start, size_t *len)
-{
-	if(start >= This->current &&
-	   start < This->current + This->cur_size) {
-		maximize(*len, This->cur_size - OFFSET);
-		return INSIDE;
-	} else if(start == This->current + This->cur_size &&
-		  This->cur_size < This->size &&
-		  *len >= This->sectorSize) {
-		/* append to the buffer for this, three conditions have to
-		 * be met:
-		 *  1. The start falls exactly at the end of the currently
-		 *     loaded data
-		 *  2. There is still space
-		 *  3. We append at least one sector
-		 */
-		maximize(*len, This->size - This->cur_size);
-		*len = ROUND_DOWN(*len, This->sectorSize);
-		return APPEND;
-	} else {
-		if(invalidate_buffer(This, start) < 0)
-			return ERROR;
-		maximize(*len, This->cylinderSize - OFFSET);
-		maximize(*len, This->cylinderSize - This->current % This->cylinderSize);
-		return OUTSIDE;
-	}
-}
-
-static int buf_read(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
-{
-	size_t length;
-	int offset;
-	char *disk_ptr;
-	int ret;
-	DeclareThis(Buffer_t);	
-
-	if(!len)
-		return 0;	
-
-	/*fprintf(stderr, "buf read %x   %x %x\n", Stream, start, len);*/
-	switch(isInBuffer(This, start, &len)) {
-		case OUTSIDE:
-		case APPEND:
-			/* always load until the end of the cylinder */
-			length = This->cylinderSize -
-				(This->current + This->cur_size) % This->cylinderSize;
-			maximize(length, This->size - This->cur_size);
-
-			/* read it! */
-			ret=READS(This->Next,
-				  This->buf + This->cur_size,
-				  This->current + This->cur_size,
-				  length);
-			if ( ret < 0 )
-				return ret;
-			This->cur_size += ret;
-			if (This->current+This->cur_size < start) {
-				fprintf(stderr, "Short buffer fill\n");
-				exit(1);
-			}														  
-			break;
-		case INSIDE:
-			/* nothing to do */
-			break;
-		case ERROR:
-			return -1;
-	}
-
-	offset = OFFSET;
-	disk_ptr = This->buf + offset;
-	maximize(len, This->cur_size - offset);
-	memcpy(buf, disk_ptr, len);
-	return len;
-}
-
-static int buf_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
-{
-	char *disk_ptr;
-	DeclareThis(Buffer_t);	
-	int offset, ret;
-
-	if(!len)
-		return 0;
-
-	This->ever_dirty = 1;
-
-#ifdef DEBUG
-	fprintf(stderr, "buf write %x   %02x %08x %08x -- %08x %08x -- %08x\n", 
-		Stream, (unsigned char) This->buf[0],
-		start, len, This->current, This->cur_size, This->size);
-	fprintf(stderr, "%d %d %d %x %x\n", 
-		start == This->current + This->cur_size,
-		This->cur_size < This->size,
-		len >= This->sectorSize, len, This->sectorSize);
-#endif
-	switch(isInBuffer(This, start, &len)) {
-		case OUTSIDE:
-#ifdef DEBUG
-			fprintf(stderr, "outside\n");
-#endif
-			if(start % This->cylinderSize || 
-			   len < This->sectorSize) {
-				size_t readSize;
-
-				readSize = This->cylinderSize - 
-					This->current % This->cylinderSize;
-
-				ret=READS(This->Next, This->buf, This->current, readSize);
-				/* read it! */
-				if ( ret < 0 )
-					return ret;
-				This->cur_size = ret;
-				/* for dosemu. Autoextend size */
-				if(!This->cur_size) {
-					memset(This->buf,0,readSize);
-					This->cur_size = readSize;
-				}
-				offset = OFFSET;
-				break;
-			}
-			/* FALL THROUGH */
-		case APPEND:
-#ifdef DEBUG
-			fprintf(stderr, "append\n");
-#endif
-			len = ROUND_DOWN(len, This->sectorSize);
-			offset = OFFSET;
-			maximize(len, This->size - offset);
-			This->cur_size += len;
-			if(This->Next->Class->pre_allocate)
-				PRE_ALLOCATE(This->Next,
-							 This->current + This->cur_size);
-			break;
-		case INSIDE:
-			/* nothing to do */
-#ifdef DEBUG
-			fprintf(stderr, "inside\n");
-#endif
-			offset = OFFSET;
-			maximize(len, This->cur_size - offset);
-			break;
-		case ERROR:
-			return -1;
-		default:
-#ifdef DEBUG
-			fprintf(stderr, "Should not happen\n");
-#endif
-			exit(1);
-	}
-
-	disk_ptr = This->buf + offset;
-
-	/* extend if we write beyond end */
-	if(offset + len > This->cur_size) {
-		len -= (offset + len) % This->sectorSize;
-		This->cur_size = len + offset;
-	}
-
-	memcpy(disk_ptr, buf, len);
-	if(!This->dirty || offset < This->dirty_pos)
-		This->dirty_pos = ROUND_DOWN(offset, This->sectorSize);
-	if(!This->dirty || offset + len > This->dirty_end)
-		This->dirty_end = ROUND_UP(offset + len, This->sectorSize);
-	
-	if(This->dirty_end > This->cur_size) {
-		fprintf(stderr, 
-			"Internal error, dirty end too big %x %x %x %d %x\n",
-			This->dirty_end, (unsigned int) This->cur_size, (unsigned int) len, 
-				(int) offset, (int) This->sectorSize);
-		fprintf(stderr, "offset + len + grain - 1 = %x\n",
-				(int) (offset + len + This->sectorSize - 1));
-		fprintf(stderr, "ROUNDOWN(offset + len + grain - 1) = %x\n",
-				(int)ROUND_DOWN(offset + len + This->sectorSize - 1,
-								This->sectorSize));
-		fprintf(stderr, "This->dirty = %d\n", This->dirty);
-		exit(1);
-	}
-
-	This->dirty = 1;
-	return len;
-}
-
-static int buf_flush(Stream_t *Stream)
-{
-	int ret;
-	DeclareThis(Buffer_t);
-
-	if (!This->ever_dirty)
-		return 0;
-	ret = _buf_flush(This);
-	if(ret == 0)
-		This->ever_dirty = 0;
-	return ret;
-}
-
-
-static int buf_free(Stream_t *Stream)
-{
-	DeclareThis(Buffer_t);
-
-	if(This->buf)
-		free(This->buf);
-	This->buf = 0;
-	return 0;
-}
-
-static Class_t BufferClass = {
-	buf_read,
-	buf_write,
-	buf_flush,
-	buf_free,
-	0, /* set_geom */
-	get_data_pass_through, /* get_data */
-	0, /* pre-allocate */
-};
-
-Stream_t *buf_init(Stream_t *Next, int size, 
-		   int cylinderSize, 
-		   int sectorSize)
-{
-	Buffer_t *Buffer;
-	Stream_t *Stream;
-
-
-	if(size % cylinderSize != 0) {
-		fprintf(stderr, "size not multiple of cylinder size\n");
-		exit(1);
-	}
-	if(cylinderSize % sectorSize != 0) {
-		fprintf(stderr, "cylinder size not multiple of sector size\n");
-		exit(1);
-	}
-
-	if(Next->Buffer){
-		Next->refs--;
-		Next->Buffer->refs++;
-		return Next->Buffer;
-	}
-
-	Stream = (Stream_t *) malloc (sizeof(Buffer_t));
-	if(!Stream)
-		return 0;
-	Buffer = (Buffer_t *) Stream;
-	Buffer->buf = malloc(size);
-	if ( !Buffer->buf){
-		Free(Stream);
-		return 0;
-	}
-	Buffer->size = size;
-	Buffer->dirty = 0;
-	Buffer->cylinderSize = cylinderSize;
-	Buffer->sectorSize = sectorSize;
-
-	Buffer->ever_dirty = 0;
-	Buffer->dirty_pos = 0;
-	Buffer->dirty_end = 0;
-	Buffer->current = 0;
-	Buffer->cur_size = 0; /* buffer currently empty */
-
-	Buffer->Next = Next;
-	Buffer->Class = &BufferClass;
-	Buffer->refs = 1;
-	Buffer->Buffer = 0;
-	Buffer->Next->Buffer = (Stream_t *) Buffer;
-	return Stream;
-}
-
Index: trunk/minix/commands/i386/mtools-3.9.7/buffer.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/buffer.h	(revision 9)
+++ 	(revision )
@@ -1,11 +1,0 @@
-#ifndef MTOOLS_BUFFER_H
-#define MTOOLS_BUFFER_H
-
-#include "stream.h"
-
-Stream_t *buf_init(Stream_t *Next, 
-		   int size, 
-		   int cylinderSize,
-		   int sectorSize);
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/build
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-
-make && make install
Index: trunk/minix/commands/i386/mtools-3.9.7/codepage.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/codepage.h	(revision 9)
+++ 	(revision )
@@ -1,35 +1,0 @@
-typedef struct Codepage_l {
-	int nr;   
-	unsigned char tounix[128];
-} Codepage_t;
-
-
-typedef struct country_l {
-	int country;
-	int codepage;
-	int default_codepage;
-	int to_upper;
-} country_t;
-
-
-#ifndef NO_CONFIG
-void init_codepage(void);
-unsigned char to_dos(unsigned char c);
-void to_unix(char *a, int n);
-#define mstoupper(c)	mstoupper[(c) & 0x7F]
-
-#else /* NO_CONFIG */
-
-/* Imagine a codepage with 128 uppercase letters for the top 128 characters. */
-#define mstoupper(c)	(c)
-#define to_dos(c)	(c)
-#define to_unix(a, n)	((void) 0)
-#define mstoupper(c)	(c)
-#endif
-
-extern Codepage_t *Codepage;
-extern char *mstoupper;
-extern country_t countries[];
-extern unsigned char toucase[][128];
-extern Codepage_t codepages[];
-extern char *country_string;
Index: trunk/minix/commands/i386/mtools-3.9.7/config.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/config.c	(revision 9)
+++ 	(revision )
@@ -1,808 +1,0 @@
-#include "sysincludes.h"
-#include "mtools.h"
-#include "codepage.h"
-#include "mtoolsPaths.h"
-
-/* global variables */
-/* they are not really harmful here, because there is only one configuration
- * file per invocations */
-
-#ifndef NO_CONFIG
-
-#define MAX_LINE_LEN 256
-
-/* scanner */
-static char buffer[MAX_LINE_LEN+1]; /* buffer for the whole line */
-static char *pos; /* position in line */
-static char *token; /* last scanned token */
-static int token_length; /* length of the token */
-static FILE *fp; /* file pointer for configuration file */
-static int linenumber; /* current line number. Only used for printing
-						* error messages */
-static int lastTokenLinenumber; /* line numnber for last token */
-static const char *filename; /* current file name. Only used for printing
-			      * error messages */
-static int file_nr=0;
-
-
-static int flag_mask; /* mask of currently set flags */
-
-/* devices */
-static int cur_devs; /* current number of defined devices */
-static int cur_dev; /* device being filled in. If negative, none */
-static int trusted=0; /* is the currently parsed device entry trusted? */
-static int nr_dev; /* number of devices that the current table can hold */
-static int token_nr; /* number of tokens in line */
-static char letters[][2] = { /* drive letter to letter-as-a-string */
-	"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
-	"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
-};
-
-#endif	/* !NO_CONFIG */
-
-struct device *devices; /* the device table */
-
-/* "environment" variables */
-unsigned int mtools_skip_check=0;
-unsigned int mtools_fat_compatibility=0;
-unsigned int mtools_ignore_short_case=0;
-unsigned int mtools_rate_0=0;
-unsigned int mtools_rate_any=0;
-unsigned int mtools_no_vfat=0;
-unsigned int mtools_numeric_tail=1;
-unsigned int mtools_dotted_dir=0;
-unsigned int mtools_twenty_four_hour_clock=1;
-char *mtools_date_string="mm-dd-yyyy";
-char *country_string=0;
-
-#ifndef NO_CONFIG
-
-typedef struct switches_l {
-    const char *name;
-    caddr_t address;
-    enum {
-	T_INT,
-	T_STRING,
-	T_UINT
-    } type;
-} switches_t;
-
-static switches_t switches[] = {
-    { "MTOOLS_LOWER_CASE", (caddr_t) & mtools_ignore_short_case, T_UINT },
-    { "MTOOLS_FAT_COMPATIBILITY", (caddr_t) & mtools_fat_compatibility, T_UINT },
-    { "MTOOLS_SKIP_CHECK", (caddr_t) & mtools_skip_check, T_UINT },
-    { "MTOOLS_NO_VFAT", (caddr_t) & mtools_no_vfat, T_UINT },
-    { "MTOOLS_RATE_0", (caddr_t) &mtools_rate_0, T_UINT },
-    { "MTOOLS_RATE_ANY", (caddr_t) &mtools_rate_any, T_UINT },
-    { "MTOOLS_NAME_NUMERIC_TAIL", (caddr_t) &mtools_numeric_tail, T_UINT },
-    { "MTOOLS_DOTTED_DIR", (caddr_t) &mtools_dotted_dir, T_UINT },
-    { "MTOOLS_TWENTY_FOUR_HOUR_CLOCK", 
-      (caddr_t) &mtools_twenty_four_hour_clock, T_UINT },
-    { "MTOOLS_DATE_STRING",
-      (caddr_t) &mtools_date_string, T_STRING },
-    { "COUNTRY", (caddr_t) &country_string, T_STRING }
-};
-
-typedef struct {
-    const char *name;
-    int flag;
-} flags_t;
-
-static flags_t openflags[] = {
-#ifdef O_SYNC
-    { "sync",		O_SYNC },
-#endif
-#ifdef O_NDELAY
-    { "nodelay",	O_NDELAY },
-#endif
-#ifdef O_EXCL
-    { "exclusive",	O_EXCL },
-#endif
-    { "none", 0 }  /* hack for those compilers that choke on commas
-		    * after the last element of an array */
-};
-
-static flags_t misc_flags[] = {
-#ifdef USE_XDF
-    { "use_xdf",		USE_XDF_FLAG },
-#endif
-    { "scsi",			SCSI_FLAG },
-    { "nolock",			NOLOCK_FLAG },
-    { "mformat_only",	MFORMAT_ONLY_FLAG },
-    { "filter",			FILTER_FLAG },
-    { "privileged",		PRIV_FLAG },
-    { "vold",			VOLD_FLAG },
-    { "remote",			FLOPPYD_FLAG }
-};
-
-static struct {
-    const char *name;
-    signed char fat_bits;
-    int tracks;
-    unsigned short heads;
-    unsigned short sectors;
-} default_formats[] = {
-    { "hd514",			12, 80, 2, 15 },
-    { "high-density-5-1/4",	12, 80, 2, 15 },
-    { "1.2m",			12, 80, 2, 15 },
-    
-    { "hd312",			12, 80, 2, 18 },
-    { "high-density-3-1/2",	12, 80, 2, 18 },
-    { "1.44m",	 		12, 80, 2, 18 },
-
-    { "dd312",			12, 80, 2, 9 },
-    { "double-density-3-1/2",	12, 80, 2, 9 },
-    { "720k",			12, 80, 2, 9 },
-
-    { "dd514",			12, 40, 2, 9 },
-    { "double-density-5-1/4",	12, 40, 2, 9 },
-    { "360k",			12, 40, 2, 9 },
-
-    { "320k",			12, 40, 2, 8 },
-    { "180k",			12, 40, 1, 9 },
-    { "160k",			12, 40, 1, 8 }
-};
-
-#define OFFS(x) ((caddr_t)&((struct device *)0)->x)
-
-static switches_t dswitches[]= {
-    { "FILE", OFFS(name), T_STRING },
-    { "OFFSET", OFFS(offset), T_UINT },
-    { "PARTITION", OFFS(partition), T_UINT },
-    { "FAT", OFFS(fat_bits), T_INT },
-    { "FAT_BITS", OFFS(fat_bits), T_UINT },
-    { "MODE", OFFS(mode), T_UINT },
-    { "TRACKS",  OFFS(tracks), T_UINT },
-    { "CYLINDERS",  OFFS(tracks), T_UINT },
-    { "HEADS", OFFS(heads), T_UINT },
-    { "SECTORS", OFFS(sectors), T_UINT },
-    { "HIDDEN", OFFS(hidden), T_UINT },
-    { "PRECMD", OFFS(precmd), T_STRING },
-    { "BLOCKSIZE", OFFS(blocksize), T_UINT }
-};
-
-static void syntax(const char *msg, int thisLine)
-{
-    char *drive=NULL;
-    if(thisLine)
-	lastTokenLinenumber = linenumber;
-    if(cur_dev >= 0)
-	drive = devices[cur_dev].drive;
-    fprintf(stderr,"Syntax error at line %d ", lastTokenLinenumber);
-    if(drive) fprintf(stderr, "for drive %s: ", drive);
-    if(token) fprintf(stderr, "column %ld ", (long)(token - buffer));
-    fprintf(stderr, "in file %s: %s\n", filename, msg);
-    exit(1);
-}
-
-static void get_env_conf(void)
-{
-    char *s;
-    int i;
-
-    for(i=0; i< sizeof(switches) / sizeof(*switches); i++) {
-	s = getenv(switches[i].name);
-	if(s) {
-	    if(switches[i].type == T_INT)
-		* ((int *)switches[i].address) = (int) strtol(s,0,0);
-	    if(switches[i].type == T_UINT)
-		* ((int *)switches[i].address) = (unsigned int) strtoul(s,0,0);
-	    else if (switches[i].type == T_STRING)
-		* ((char **)switches[i].address) = s;
-	}
-    }
-}
-
-static int mtools_getline(void)
-{
-    if(!fgets(buffer, MAX_LINE_LEN, fp))
-	return -1;
-    linenumber++;
-    pos = buffer;
-    token_nr = 0;
-    buffer[MAX_LINE_LEN] = '\0';
-    if(strlen(buffer) == MAX_LINE_LEN)
-	syntax("line too long", 1);
-    return 0;
-}
-		
-static void skip_junk(int expect)
-{
-    lastTokenLinenumber = linenumber;
-    while(!pos || !*pos || strchr(" #\n\t", *pos)) {
-	if(!pos || !*pos || *pos == '#') {
-	    if(mtools_getline()) {
-		pos = 0;
-		if(expect)
-		    syntax("end of file unexpected", 1);
-		return;
-	    }
-	} else
-	    pos++;
-    }
-    token_nr++;
-}
-
-/* get the next token */
-static char *get_next_token(void)
-{
-    skip_junk(0);
-    if(!pos) {
-	token_length = 0;
-	token = 0;
-	return 0;
-    }
-    token = pos;
-    token_length = strcspn(token, " \t\n#:=");
-    pos += token_length;
-    return token;
-}
-
-static int match_token(const char *template)
-{
-    return (strlen(template) == token_length &&
-	    !strncasecmp(template, token, token_length));
-}
-
-static void expect_char(char c)
-{
-    char buf[11];
-
-    skip_junk(1);
-    if(*pos != c) {
-	sprintf(buf, "expected %c", c);
-	syntax(buf, 1);
-    }
-    pos++;
-}
-
-static char *get_string(void)
-{
-    char *end, *str;
-
-    skip_junk(1);
-    if(*pos != '"')
-	syntax(" \" expected", 0);
-    str = pos+1;
-    end = strchr(str, '\"');
-    if(!end)
-	syntax("unterminated string constant", 1);
-    *end = '\0';
-    pos = end+1;
-    return str;
-}
-
-static unsigned int get_unumber(void)
-{
-    char *last;
-    unsigned int n;
-
-    skip_junk(1);
-    last = pos;
-    n=(unsigned int) strtoul(pos, &pos, 0);
-    if(last == pos)
-	syntax("numeral expected", 0);
-    pos++;
-    token_nr++;
-    return n;
-}
-
-static unsigned int get_number(void)
-{
-    char *last;
-    int n;
-
-    skip_junk(1);
-    last = pos;
-    n=(int) strtol(pos, &pos, 0);
-    if(last == pos)
-	syntax("numeral expected", 0);
-    pos++;
-    token_nr++;
-    return n;
-}
-
-/* purge all entries pertaining to a given drive from the table */
-static void purge(char drive, int fn)
-{
-    int i,j;
-
-    drive = toupper(drive);
-    for(j=0, i=0; i < cur_devs; i++) {
-	if(devices[i].drive[0] != drive ||
-	   devices[i].drive[1] != 0 ||
-	   devices[i].file_nr == fn)
-	    devices[j++] = devices[i];
-    }
-    cur_devs = j;
-}
-
-static void grow(void)
-{
-    if(cur_devs >= nr_dev - 2) {
-	nr_dev = (cur_devs + 2) << 1;
-	if(!(devices=Grow(devices, nr_dev, struct device))){
-	    printOom();
-	    exit(1);
-	}
-    }
-}
-	
-
-static void init_drive(void)
-{
-    memset((char *)&devices[cur_dev], 0, sizeof(struct device));
-    devices[cur_dev].ssize = 2;
-}
-
-/* prepends a device to the table */
-static void prepend(void)
-{
-    int i;
-
-    grow();
-    for(i=cur_devs; i>0; i--)
-	devices[i] = devices[i-1];
-    cur_dev = 0;
-    cur_devs++;
-    init_drive();
-}
-
-
-/* appends a device to the table */
-static void append(void)
-{
-    grow();
-    cur_dev = cur_devs;
-    cur_devs++;
-    init_drive();
-}
-
-
-static void finish_drive_clause(void)
-{
-    char *drive;
-    if(cur_dev == -1) {
-	trusted = 0;
-	return;
-    }
-    drive = devices[cur_dev].drive;
-    if(!devices[cur_dev].name)
-	syntax("missing filename", 0);
-    if(devices[cur_dev].tracks ||
-       devices[cur_dev].heads ||
-       devices[cur_dev].sectors) {
-	if(!devices[cur_dev].tracks ||
-	   !devices[cur_dev].heads ||
-	   !devices[cur_dev].sectors)
-	    syntax("incomplete geometry: either indicate all of track/heads/sectors or none of them", 0);
-	if(!(devices[cur_dev].misc_flags & 
-	     (MFORMAT_ONLY_FLAG | FILTER_FLAG)))
-	    syntax("if you supply a geometry, you also must supply one of the `mformat_only' or `filter' flags", 0);
-    }
-    devices[cur_dev].file_nr = file_nr;
-    devices[cur_dev].cfg_filename = filename;
-    if(! (flag_mask & PRIV_FLAG) && IS_SCSI(&devices[cur_dev]))
-	devices[cur_dev].misc_flags |= PRIV_FLAG;
-    if(!trusted && (devices[cur_dev].misc_flags & PRIV_FLAG)) {
-	fprintf(stderr,
-		"Warning: privileged flag ignored for drive %s: defined in file %s\n",
-		devices[cur_dev].drive, filename);
-	devices[cur_dev].misc_flags &= ~PRIV_FLAG;
-    }
-    trusted = 0;
-    cur_dev = -1;
-}
-
-static int set_var(struct switches_l *switches, int nr,
-		   caddr_t base_address)
-{
-    int i;
-    for(i=0; i < nr; i++) {
-	if(match_token(switches[i].name)) {
-	    expect_char('=');
-	    if(switches[i].type == T_UINT)
-		* ((int *)((long)switches[i].address+base_address)) = 
-		    get_unumber();
-	    if(switches[i].type == T_INT)
-		* ((int *)((long)switches[i].address+base_address)) = 
-		    get_number();
-	    else if (switches[i].type == T_STRING)
-		* ((char**)((long)switches[i].address+base_address))=
-		    strdup(get_string());
-	    return 0;
-	}
-    }
-    return 1;
-}
-
-static int set_openflags(struct device *dev)
-{
-    int i;
-
-    for(i=0; i < sizeof(openflags) / sizeof(*openflags); i++) {
-	if(match_token(openflags[i].name)) {
-	    dev->mode |= openflags[i].flag;
-	    return 0;
-	}
-    }
-    return 1;
-}
-
-static int set_misc_flags(struct device *dev)
-{
-    int i;
-
-    for(i=0; i < sizeof(misc_flags) / sizeof(*misc_flags); i++) {
-	if(match_token(misc_flags[i].name)) {
-	    flag_mask |= misc_flags[i].flag;
-	    skip_junk(0);
-	    if(pos && *pos == '=') {
-		pos++;
-		switch(get_number()) {
-		    case 0:
-			return 0;
-		    case 1:
-			break;
-		    default:
-			syntax("expected 0 or 1", 0);
-		}
-	    }
-	    dev->misc_flags |= misc_flags[i].flag;
-	    return 0;
-	}
-    }
-    return 1;
-}
-
-static int set_def_format(struct device *dev)
-{
-    int i;
-
-    for(i=0; i < sizeof(default_formats)/sizeof(*default_formats); i++) {
-	if(match_token(default_formats[i].name)) {
-	    if(!dev->ssize)
-		dev->ssize = 2;
-	    if(!dev->tracks)
-		dev->tracks = default_formats[i].tracks;
-	    if(!dev->heads)
-		dev->heads = default_formats[i].heads;
-	    if(!dev->sectors)
-		dev->sectors = default_formats[i].sectors;
-	    if(!dev->fat_bits)
-		dev->fat_bits = default_formats[i].fat_bits;
-	    return 0;
-	}
-    }
-    return 1;
-}    
-
-static void get_codepage(void)
-{
-    int i;
-    unsigned short n;
-
-    if(!Codepage)
-	Codepage = New(Codepage_t);
-    for(i=0; i<128; i++) {
-	n = get_number();
-	if(n > 0xff)
-	    n = 0x5f;
-	Codepage->tounix[i] = n;
-    }	
-}
-
-static void get_toupper(void)
-{
-    int i;
-
-    if(!mstoupper)
-	mstoupper = safe_malloc(128);
-    for(i=0; i<128; i++)
-	mstoupper[i] = get_number();
-}
-
-static void parse_old_device_line(char drive)
-{
-    char name[MAXPATHLEN];
-    int items;
-    long offset;
-    char newdrive;
-
-    /* finish any old drive */
-    finish_drive_clause();
-
-    /* purge out data of old configuration files */
-    purge(drive, file_nr);
-	
-    /* reserve slot */
-    append();
-    items = sscanf(token,"%c %s %i %i %i %i %li",
-		   &newdrive,name,&devices[cur_dev].fat_bits,
-		   &devices[cur_dev].tracks,&devices[cur_dev].heads,
-		   &devices[cur_dev].sectors, &offset);
-    devices[cur_dev].offset = (off_t) offset;
-    switch(items){
-	case 2:
-	    devices[cur_dev].fat_bits = 0;
-	    /* fall thru */
-	case 3:
-	    devices[cur_dev].sectors = 0;
-	    devices[cur_dev].heads = 0;
-	    devices[cur_dev].tracks = 0;
-	    /* fall thru */
-	case 6:
-	    devices[cur_dev].offset = 0;
-	    /* fall thru */
-	default:
-	    break;
-	case 0:
-	case 1:
-	case 4:
-	case 5:
-	    syntax("bad number of parameters", 1);
-	    exit(1);
-    }
-    if(!devices[cur_dev].tracks){
-	devices[cur_dev].sectors = 0;
-	devices[cur_dev].heads = 0;
-    }
-	
-    devices[cur_dev].drive = letters[toupper(newdrive) - 'A'];
-    if (!(devices[cur_dev].name = strdup(name))) {
-	printOom();
-	exit(1);
-    }
-    finish_drive_clause();
-    pos=0;
-}
-
-static int parse_one(int privilege)
-{
-    int action=0;
-
-    get_next_token();
-    if(!token)
-	return 0;
-
-    if((match_token("drive") && ((action = 1)))||
-       (match_token("drive+") && ((action = 2))) ||
-       (match_token("+drive") && ((action = 3))) ||
-       (match_token("clear_drive") && ((action = 4))) ) {
-	/* finish off the previous drive */
-	finish_drive_clause();
-
-	get_next_token();
-	if(token_length != 1)
-	    syntax("drive letter expected", 0);
-
-	if(action==1 || action==4)
-	    /* replace existing drive */			
-	    purge(token[0], file_nr);
-	if(action==4)
-	    return 1;
-	if(action==3)
-	    prepend();
-	else
-	    append();
-	memset((char*)(devices+cur_dev), 0, sizeof(*devices));
-	trusted = privilege;
-	flag_mask = 0;
-	devices[cur_dev].drive = letters[toupper(token[0]) - 'A'];
-	expect_char(':');
-	return 1;
-    }
-    if(token_nr == 1 && token_length == 1) {
-	parse_old_device_line(token[0]);
-	return 1;
-    }
-    if(match_token("default_fucase")) {
-	free(mstoupper);
-	mstoupper=0;
-    }
-    if(match_token("default_tounix")) {
-	Free(Codepage);
-	Codepage = 0;
-    }
-    if(match_token("fucase")) {
-	expect_char(':');
-	get_toupper();
-	return 1;
-    }
-    if(match_token("tounix")) {
-	expect_char(':');
-	get_codepage();
-	return 1;
-    }
-	
-    if((cur_dev < 0 || 
-	(set_var(dswitches,
-		 sizeof(dswitches)/sizeof(*dswitches),
-		 (caddr_t)&devices[cur_dev]) &&
-	 set_openflags(&devices[cur_dev]) &&
-	 set_misc_flags(&devices[cur_dev]) &&
-	 set_def_format(&devices[cur_dev]))) &&
-       set_var(switches,
-	       sizeof(switches)/sizeof(*switches), 0))
-	syntax("unrecognized keyword", 1);
-    return 1;
-}
-
-static int parse(const char *name, int privilege)
-{
-    fp = fopen(name, "r");
-    if(!fp)
-	return 0;
-    file_nr++;
-    filename = strdup(name);
-    linenumber = 0;
-    lastTokenLinenumber = 0;
-    pos = 0;
-    token = 0;
-    cur_dev = -1; /* no current device */
-
-    while(parse_one(privilege));
-    finish_drive_clause();
-    fclose(fp);
-    return 1;
-}
-
-void read_config(void)
-{
-    char *homedir;
-    char *envConfFile;
-    char conf_file[MAXPATHLEN+sizeof(CFG_FILE1)];
-
-	
-    /* copy compiled-in devices */
-    file_nr = 0;
-    cur_devs = nr_const_devices;
-    nr_dev = nr_const_devices + 2;
-    devices = NewArray(nr_dev, struct device);
-    if(!devices) {
-	printOom();
-	exit(1);
-    }
-    if(nr_const_devices)
-	memcpy(devices, const_devices,
-	       nr_const_devices*sizeof(struct device));
-
-    (void) ((parse(CONF_FILE,1) | 
-	     parse(LOCAL_CONF_FILE,1) |
-	     parse(SYS_CONF_FILE,1)) ||
-	    (parse(OLD_CONF_FILE,1) | 
-	     parse(OLD_LOCAL_CONF_FILE,1)));
-    /* the old-name configuration files only get executed if none of the
-     * new-name config files were used */
-
-    homedir = get_homedir();
-    if ( homedir ){
-	strncpy(conf_file, homedir, MAXPATHLEN );
-	conf_file[MAXPATHLEN]='\0';
-	strcat( conf_file, CFG_FILE1);
-	parse(conf_file,0);
-    }
-    memset((char *)&devices[cur_devs],0,sizeof(struct device));
-
-    envConfFile = getenv("MTOOLSRC");
-    if(envConfFile)
-	parse(envConfFile,0);
-
-    /* environmental variables */
-    get_env_conf();
-    if(mtools_skip_check)
-	mtools_fat_compatibility=1;
-    init_codepage();
-}
-
-void mtoolstest(int argc, char **argv, int type)
-{
-    /* testing purposes only */
-    struct device *dev;
-    int i,j;
-    char *drive=NULL;
-    char *path;
-
-    if (argc > 1 && (path = skip_drive(argv[1])) > argv[1]) {
-	drive = get_drive(argv[1], NULL);
-    }
-
-    for (dev=devices; dev->name; dev++) {
-	if(drive && strcmp(drive, dev->drive) != 0)
-	    continue;
-	printf("drive %s:\n", dev->drive);
-	printf("\t#fn=%d mode=%d ",
-	       dev->file_nr, dev->mode);
-	if(dev->cfg_filename)
-	    printf("defined in %s\n", dev->cfg_filename);
-	else
-	    printf("builtin\n");
-	printf("\tfile=\"%s\" fat_bits=%d \n",
-	       dev->name,dev->fat_bits);
-	printf("\ttracks=%d heads=%d sectors=%d hidden=%d\n",
-	       dev->tracks, dev->heads, dev->sectors, dev->hidden);
-	printf("\toffset=0x%lx\n", (long) dev->offset);
-	printf("\tpartition=%d\n", dev->partition);
-
-	if(dev->misc_flags)
-	    printf("\t");
-
-	if(IS_SCSI(dev))
-	    printf("scsi ");
-	if(IS_PRIVILEGED(dev))
-	    printf("privileged");
-	if(IS_MFORMAT_ONLY(dev))
-	    printf("mformat_only ");
-	if(SHOULD_USE_VOLD(dev))
-	    printf("vold ");
-#ifdef USE_XDF
-	if(SHOULD_USE_XDF(dev))
-	    printf("use_xdf ");
-#endif
-	if(dev->misc_flags)
-	    printf("\n");
-
-	if(dev->mode)
-	    printf("\t");
-#ifdef O_SYNC
-	if(dev->mode & O_SYNC)
-	    printf("sync ");
-#endif
-#ifdef O_NDELAY
-	if((dev->mode & O_NDELAY))
-	    printf("nodelay ");
-#endif
-#ifdef O_EXCL
-	if((dev->mode & O_EXCL))
-	    printf("exclusive ");
-#endif
-	if(dev->mode)
-	    printf("\n");
-
-	if(dev->precmd)
-	    printf("\tprecmd=%s\n", dev->precmd);
-
-	printf("\n");
-    }
-	
-    printf("tounix:\n");
-    for(i=0; i < 16; i++) {
-	putchar('\t');
-	for(j=0; j<8; j++)
-	    printf("0x%02x ",
-		   (unsigned char)Codepage->tounix[i*8+j]);
-	putchar('\n');
-    }
-    printf("\nfucase:\n");
-    for(i=0; i < 16; i++) {
-	putchar('\t');
-	for(j=0; j<8; j++)
-	    printf("0x%02x ",
-		   (unsigned char)mstoupper[i*8+j]);
-	putchar('\n');
-    }
-    if(country_string)
-	printf("COUNTRY=%s\n", country_string);
-    printf("mtools_fat_compatibility=%d\n",mtools_fat_compatibility);
-    printf("mtools_skip_check=%d\n",mtools_skip_check);
-    printf("mtools_lower_case=%d\n",mtools_ignore_short_case);
-
-    exit(0);
-}
-
-#else	/* NO_CONFIG */
-
-void read_config(void)
-{
-	/* only compiled-in devices */
-	devices = NewArray(nr_const_devices + 1, struct device);
-	if(!devices) {
-		fprintf(stderr,"Out of memory error\n");
-		exit(1);
-	}
-	if(nr_const_devices)
-	memcpy(devices, const_devices,
-		       nr_const_devices*sizeof(struct device));
-}
-
-#endif /* NO_CONFIG */
Index: trunk/minix/commands/i386/mtools-3.9.7/config.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/config.h	(revision 9)
+++ 	(revision )
@@ -1,301 +1,0 @@
-/* config.h.  Generated automatically by configure.  */
-/* config.h.in.  Generated automatically from configure.in by autoheader.  */
-
-/* Define if on AIX 3.
-   System headers sometimes define this.
-   We just want to avoid a redefinition error message.  */
-#ifndef _ALL_SOURCE
-/* #undef _ALL_SOURCE */
-#endif
-
-/* Define to empty if the keyword does not work.  */
-/* #undef const */
-
-/* Define if you have <sys/wait.h> that is POSIX.1 compatible.  */
-#define HAVE_SYS_WAIT_H 1
-
-/* Define as __inline if that's what the C compiler calls it.  */
-#define inline 
-
-/* Define if on MINIX.  */
-#define _MINIX 1
-
-/* Define if the system does not provide POSIX.1 features except
-   with this defined.  */
-#define _POSIX_1_SOURCE 2
-
-/* Define if you need to in order for stat and other things to work.  */
-#define _POSIX_SOURCE 1
-
-/* Define as the return type of signal handlers (int or void).  */
-#define RETSIGTYPE void
-
-/* Define if the `setpgrp' function takes no argument.  */
-#define SETPGRP_VOID 1
-
-/* Define to `unsigned' if <sys/types.h> doesn't define.  */
-/* #undef size_t */
-
-/* Define if you have the ANSI C header files.  */
-#define STDC_HEADERS 1
-
-/* Define if you can safely include both <sys/time.h> and <time.h>.  */
-/* #undef TIME_WITH_SYS_TIME */
-
-/* Define if your <sys/time.h> declares struct tm.  */
-/* #undef TM_IN_SYS_TIME */
-
-/* Define if the X Window System is missing or not being used.  */
-#define X_DISPLAY_MISSING 1
-
-/* Define this if you want to use Xdf */
-#define USE_XDF 1
-
-/* Define this if you use mtools together with Solaris' vold */
-/* #undef USING_VOLD */
-
-/* Define this if you use mtools together with the new Solaris' vold
- * support */
-/* #undef USING_NEW_VOLD */
-
-/* Define for debugging messages */
-/* #undef DEBUG */
-
-/* Define on non Unix OS'es which don't have the concept of tty's */
-/* #undef USE_RAWTERM */
-
-/* Define when sys_errlist is defined in the standard include files */
-/* #undef DECL_SYS_ERRLIST */
-
-/* Define when you want to include floppyd support */
-/* #undef USE_FLOPPYD */
-
-/* Define when the compiler supports LOFF_T type */
-/* #undef HAVE_LOFF_T */
-
-/* Define when the compiler supports OFFSET_T type */
-/* #undef HAVE_OFFSET_T */
-
-/* Define when the compiler supports LONG_LONG type */
-/* #undef HAVE_LONG_LONG */
-
-/* Define when the system has a 64 bit off_t type */
-/* #undef HAVE_OFF_T_64 */
-
-/* Define when you have an LLSEEK prototype */
-/* #undef HAVE_LLSEEK_PROTOTYPE */
-
-/* Define if you have the atexit function.  */
-#define HAVE_ATEXIT 1
-
-/* Define if you have the basename function.  */
-/* #undef HAVE_BASENAME */
-
-/* Define if you have the fchdir function.  */
-#ifdef __minix_vmd
-#define HAVE_FCHDIR 1
-#endif
-
-/* Define if you have the flock function.  */
-/* #undef HAVE_FLOCK */
-
-/* Define if you have the getpass function.  */
-#define HAVE_GETPASS 1
-
-/* Define if you have the gettimeofday function.  */
-#define HAVE_GETTIMEOFDAY 1
-
-/* Define if you have the htons function.  */
-/* #undef HAVE_HTONS */
-
-/* Define if you have the llseek function.  */
-/* #undef HAVE_LLSEEK */
-
-/* Define if you have the lockf function.  */
-#define HAVE_LOCKF 1
-
-/* Define if you have the lseek64 function.  */
-/* #undef HAVE_LSEEK64 */
-
-/* Define if you have the media_oldaliases function.  */
-/* #undef HAVE_MEDIA_OLDALIASES */
-
-/* Define if you have the memcpy function.  */
-#define HAVE_MEMCPY 1
-
-/* Define if you have the memmove function.  */
-#define HAVE_MEMMOVE 1
-
-/* Define if you have the memset function.  */
-#define HAVE_MEMSET 1
-
-/* Define if you have the on_exit function.  */
-/* #undef HAVE_ON_EXIT */
-
-/* Define if you have the random function.  */
-#define HAVE_RANDOM 1
-
-/* Define if you have the seteuid function.  */
-/* #undef HAVE_SETEUID */
-
-/* Define if you have the setresuid function.  */
-/* #undef HAVE_SETRESUID */
-
-/* Define if you have the snprintf function.  */
-#define HAVE_SNPRINTF 1
-
-/* Define if you have the srandom function.  */
-#define HAVE_SRANDOM 1
-
-/* Define if you have the strcasecmp function.  */
-#define HAVE_STRCASECMP 1
-
-/* Define if you have the strchr function.  */
-#define HAVE_STRCHR 1
-
-/* Define if you have the strcspn function.  */
-#define HAVE_STRCSPN 1
-
-/* Define if you have the strdup function.  */
-/* #undef HAVE_STRDUP */
-
-/* Define if you have the strerror function.  */
-#define HAVE_STRERROR 1
-
-/* Define if you have the strncasecmp function.  */
-#define HAVE_STRNCASECMP 1
-
-/* Define if you have the strpbrk function.  */
-#define HAVE_STRPBRK 1
-
-/* Define if you have the strrchr function.  */
-#define HAVE_STRRCHR 1
-
-/* Define if you have the strspn function.  */
-#define HAVE_STRSPN 1
-
-/* Define if you have the strtol function.  */
-#define HAVE_STRTOL 1
-
-/* Define if you have the strtoul function.  */
-#define HAVE_STRTOUL 1
-
-/* Define if you have the tcflush function.  */
-#define HAVE_TCFLUSH 1
-
-/* Define if you have the tcsetattr function.  */
-#define HAVE_TCSETATTR 1
-
-/* Define if you have the tzset function.  */
-#define HAVE_TZSET 1
-
-/* Define if you have the utime function.  */
-#define HAVE_UTIME 1
-
-/* Define if you have the utimes function.  */
-/* #undef HAVE_UTIMES */
-
-/* Define if you have the <arpa/inet.h> header file.  */
-/* #undef HAVE_ARPA_INET_H */
-
-/* Define if you have the <fcntl.h> header file.  */
-#define HAVE_FCNTL_H 1
-
-/* Define if you have the <getopt.h> header file.  */
-/* #undef HAVE_GETOPT_H */
-
-/* Define if you have the <libc.h> header file.  */
-/* #undef HAVE_LIBC_H */
-
-/* Define if you have the <limits.h> header file.  */
-#define HAVE_LIMITS_H 1
-
-/* Define if you have the <linux/unistd.h> header file.  */
-/* #undef HAVE_LINUX_UNISTD_H */
-
-/* Define if you have the <malloc.h> header file.  */
-/* #undef HAVE_MALLOC_H */
-
-/* Define if you have the <memory.h> header file.  */
-/* #undef HAVE_MEMORY_H */
-
-/* Define if you have the <mntent.h> header file.  */
-/* #undef HAVE_MNTENT_H */
-
-/* Define if you have the <netdb.h> header file.  */
-/* #undef HAVE_NETDB_H */
-
-/* Define if you have the <netinet/in.h> header file.  */
-/* #undef HAVE_NETINET_IN_H */
-
-/* Define if you have the <sgtty.h> header file.  */
-#define HAVE_SGTTY_H 1
-
-/* Define if you have the <signal.h> header file.  */
-#define HAVE_SIGNAL_H 1
-
-/* Define if you have the <stdlib.h> header file.  */
-#define HAVE_STDLIB_H 1
-
-/* Define if you have the <string.h> header file.  */
-#define HAVE_STRING_H 1
-
-/* Define if you have the <strings.h> header file.  */
-/* #undef HAVE_STRINGS_H */
-
-/* Define if you have the <sys/file.h> header file.  */
-/* #undef HAVE_SYS_FILE_H */
-
-/* Define if you have the <sys/floppy.h> header file.  */
-/* #undef HAVE_SYS_FLOPPY_H */
-
-/* Define if you have the <sys/ioctl.h> header file.  */
-#define HAVE_SYS_IOCTL_H 1
-
-/* Define if you have the <sys/param.h> header file.  */
-/* #undef HAVE_SYS_PARAM_H */
-
-/* Define if you have the <sys/signal.h> header file.  */
-/* #undef HAVE_SYS_SIGNAL_H */
-
-/* Define if you have the <sys/socket.h> header file.  */
-/* #undef HAVE_SYS_SOCKET_H */
-
-/* Define if you have the <sys/stat.h> header file.  */
-#define HAVE_SYS_STAT_H 1
-
-/* Define if you have the <sys/sysmacros.h> header file.  */
-/* #undef HAVE_SYS_SYSMACROS_H */
-
-/* Define if you have the <sys/termio.h> header file.  */
-/* #undef HAVE_SYS_TERMIO_H */
-
-/* Define if you have the <sys/termios.h> header file.  */
-/* #undef HAVE_SYS_TERMIOS_H */
-
-/* Define if you have the <sys/time.h> header file.  */
-/* #undef HAVE_SYS_TIME_H */
-
-/* Define if you have the <termio.h> header file.  */
-/* #undef HAVE_TERMIO_H */
-
-/* Define if you have the <termios.h> header file.  */
-#define HAVE_TERMIOS_H 1
-
-/* Define if you have the <unistd.h> header file.  */
-#define HAVE_UNISTD_H 1
-
-/* Define if you have the <utime.h> header file.  */
-#define HAVE_UTIME_H 1
-
-/* Define if you have the cam library (-lcam).  */
-/* #undef HAVE_LIBCAM */
-
-/* Define if you have the nsl library (-lnsl).  */
-/* #undef HAVE_LIBNSL */
-
-/* Define if you have the socket library (-lsocket).  */
-/* #undef HAVE_LIBSOCKET */
-
-/* Define if you have the sun library (-lsun).  */
-/* #undef HAVE_LIBSUN */
Index: trunk/minix/commands/i386/mtools-3.9.7/copyfile.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/copyfile.c	(revision 9)
+++ 	(revision )
@@ -1,62 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "file.h"
-#include "llong.h"
-
-/*
- * Copy the data from source to target
- */
-
-int copyfile(Stream_t *Source, Stream_t *Target)
-{
-	char buffer[8*16384];
-	int pos;
-	int ret, retw;
-	size_t len;
-	mt_size_t mt_len;
-
-	if (!Source){
-		fprintf(stderr,"Couldn't open source file\n");
-		return -1;
-	}
-
-	if (!Target){
-		fprintf(stderr,"Couldn't open target file\n");
-		return -1;
-	}
-
-	pos = 0;
-	GET_DATA(Source, 0, &mt_len, 0, 0);
-	if (mt_len & ~max_off_t_31) {
-		fprintf(stderr, "File too big\n");
-		return -1;
-	}
-	len = truncBytes32(mt_len);
-	while(1){
-		ret = READS(Source, buffer, (mt_off_t) pos, 8*16384);
-		if (ret < 0 ){
-			perror("file read");
-			return -1;
-		}
-		if(!ret)
-			break;
-		if(got_signal)
-			return -1;
-		if (ret == 0)
-			break;
-		if ((retw = force_write(Target, buffer, (mt_off_t) pos, ret)) != ret){
-			if(retw < 0 )
-				perror("write in copy");
-			else
-				fprintf(stderr,
-					"Short write %d instead of %d\n", retw,
-					ret);
-			if(errno == ENOSPC)
-				got_signal = 1;
-			return ret;
-		}
-		pos += ret;
-	}
-	return pos;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/devices.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/devices.c	(revision 9)
+++ 	(revision )
@@ -1,1115 +1,0 @@
-/*
- * This file is modified to perform on the UXP/DS operating system 
- * by FUJITSU Limited on 1996.6.4
- */
-
-/*
- * Device tables.  See the Configure file for a complete description.
- */
-
-#define NO_TERMIO
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "devices.h"
-
-#define INIT_NOOP
-
-#define DEF_ARG1(x) (x), 0x2,0,(char *)0, 0, 0
-#define DEF_ARG0(x) 0,DEF_ARG1(x)
-
-#define MDEF_ARG 0L,DEF_ARG0(MFORMAT_ONLY_FLAG)
-#define FDEF_ARG 0L,DEF_ARG0(0)
-#define VOLD_DEF_ARG 0L,DEF_ARG0(VOLD_FLAG|MFORMAT_ONLY_FLAG)
-
-#define MED312	12,0,80,2,36,0,MDEF_ARG /* 3 1/2 extra density */
-#define MHD312	12,0,80,2,18,0,MDEF_ARG /* 3 1/2 high density */
-#define MDD312	12,0,80,2, 9,0,MDEF_ARG /* 3 1/2 double density */
-#define MHD514	12,0,80,2,15,0,MDEF_ARG /* 5 1/4 high density */
-#define MDD514	12,0,40,2, 9,0,MDEF_ARG /* 5 1/4 double density (360k) */
-#define MSS514	12,0,40,1, 9,0,MDEF_ARG /* 5 1/4 single sided DD, (180k) */
-#define MDDsmall	12,0,40,2, 8,0,MDEF_ARG /* 5 1/4 double density (320k) */
-#define MSSsmall	12,0,40,1, 8,0,MDEF_ARG /* 5 1/4 single sided DD, (160k) */
-
-#define FED312	12,0,80,2,36,0,FDEF_ARG /* 3 1/2 extra density */
-#define FHD312	12,0,80,2,18,0,FDEF_ARG /* 3 1/2 high density */
-#define FDD312	12,0,80,2, 9,0,FDEF_ARG /* 3 1/2 double density */
-#define FHD514	12,0,80,2,15,0,FDEF_ARG /* 5 1/4 high density */
-#define FDD514	12,0,40,2, 9,0,FDEF_ARG /* 5 1/4 double density (360k) */
-#define FSS514	12,0,40,1, 9,0,FDEF_ARG /* 5 1/4 single sided DD, (180k) */
-#define FDDsmall	12,0,40,2, 8,0,FDEF_ARG /* 5 1/4 double density (320k) */
-#define FSSsmall	12,0,40,1, 8,0,FDEF_ARG /* 5 1/4 single sided DD, (160k) */
-
-#define GENHD	16,0, 0,0, 0,0,MDEF_ARG /* Generic 16 bit FAT fs */
-#define GENFD	12,0,80,2,18,0,MDEF_ARG /* Generic 12 bit FAT fs */
-#define VOLDFD	12,0,80,2,18,0,VOLD_DEF_ARG /* Generic 12 bit FAT fs with vold */
-#define GEN    	 0,0, 0,0, 0,0,MDEF_ARG /* Generic fs of any FAT bits */
-
-#define ZIPJAZ(x,c,h,s,y) 16,(x),(c),(h),(s),(s),0L, 4, \
-		DEF_ARG1((y)|MFORMAT_ONLY_FLAG) /* Jaz disks */
-
-#define JAZ(x)	 ZIPJAZ(x,1021, 64, 32, 0)
-#define RJAZ(x)	 ZIPJAZ(x,1021, 64, 32, SCSI_FLAG|PRIV_FLAG)
-#define ZIP(x)	 ZIPJAZ(x,96, 64, 32, 0)
-#define RZIP(x)	 ZIPJAZ(x,96, 64, 32, SCSI_FLAG|PRIV_FLAG)
-
-#define REMOTE    {"$DISPLAY", 'X', 0,0, 0,0, 0,0,0L, DEF_ARG0(FLOPPYD_FLAG)}
-
-
-
-#if defined(INIT_GENERIC) || defined(INIT_NOOP)
-static int compare_geom(struct device *dev, struct device *orig_dev)
-{
-	if(IS_MFORMAT_ONLY(orig_dev))
-		return 0; /* geometry only for mformatting ==> ok */
-	if(!orig_dev || !orig_dev->tracks || !dev || !dev->tracks)
-		return 0; /* no original device. This is ok */
-	return(orig_dev->tracks != dev->tracks ||
-	       orig_dev->heads != dev->heads ||
-	       orig_dev->sectors  != dev->sectors);
-}
-#endif
-
-#define devices const_devices
-
-
-#ifdef OS_aux
-#define predefined_devices
-struct device devices[] = {
-   {"/dev/floppy0", "A", GENFD },
-   {"/dev/rdsk/c104d0s31", "J", JAZ(O_EXCL) },
-   {"/dev/rdsk/c105d0s31", "Z", ZIP(O_EXCL) },
-   REMOTE
-};
-#endif /* aux */
-
-
-#ifdef OS_lynxos
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/fd1440.0", 	"A", MHD312 },
-	REMOTE
-};
-#endif
-
-
-#ifdef __BEOS__
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/disk/floppy/raw", 	"A", MHD312 },
-	REMOTE
-};
-#endif /* BEBOX */
-
-
-#ifdef OS_hpux
-
-#define predefined_devices
-struct device devices[] = {
-#ifdef OS_hpux10
-/* hpux10 uses different device names according to Frank Maritato
- * <frank@math.hmc.edu> */
-	{"/dev/floppy/c0t0d0",		"A", MHD312 },
-	{"/dev/floppy/c0t0d1",		"B", MHD312 }, /* guessed by me */
- 	{"/dev/rscsi",			"C", GENHD }, /* guessed by me */
-#else
-/* Use rfloppy, according to Simao Campos <simao@iris.ctd.comsat.com> */
-	{"/dev/rfloppy/c201d0s0",	"A", FHD312 },
-	{"/dev/rfloppy/c20Ad0s0", 	"A", FHD312 },
- 	{"/dev/rfloppy/c201d1s0",	"B", FHD312 },
- 	{"/dev/rfloppy/c20Ad1s0",	"B", FHD312 },
- 	{"/dev/rscsi",			"C", GENHD },
-#endif
-	{"/dev/rdsk/c201d4",		"J", RJAZ(O_EXCL) },
-	{"/dev/rdsk/c201d4s0",		"J", RJAZ(O_EXCL) },
-	{"/dev/rdsk/c201d5",		"Z", RZIP(O_EXCL) },
-	{"/dev/rdsk/c201d5s0",		"Z", RZIP(O_EXCL) },
-	REMOTE
-};
-
-#ifdef HAVE_SYS_FLOPPY
-/* geometry setting ioctl's contributed by Paolo Zeppegno
- * <paolo@to.sem.it>, may cause "Not a typewriter" messages on other
- * versions according to support@vital.com */
-
-#include <sys/floppy.h>
-#undef SSIZE
-
-struct generic_floppy_struct
-{
-  struct floppy_geometry fg;
-};
-
-#define BLOCK_MAJOR 24
-#define CHAR_MAJOR 112
-
-static inline int get_parameters(int fd, struct generic_floppy_struct *floppy)
-{
-	if (ioctl(fd, FLOPPY_GET_GEOMETRY, &(floppy->fg)) != 0) {
-		perror("FLOPPY_GET_GEOMETRY");
-		return(1);
-	}
-	
-	return 0;
-}
-
-#define TRACKS(floppy) floppy.fg.tracks
-#define HEADS(floppy) floppy.fg.heads
-#define SECTORS(floppy) floppy.fg.sectors
-#define FD_SECTSIZE(floppy) floppy.fg.sector_size
-#define FD_SET_SECTSIZE(floppy,v) { floppy.fg.sector_size = v; }
-
-static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, 
-				 struct stat *buf)
-{
-	if (ioctl(fd, FLOPPY_SET_GEOMETRY, &(floppy->fg)) != 0) {
-		perror("");
-		return(1);
-	}
-	
-	return 0;
-}
-#define INIT_GENERIC
-#endif
-
-#endif /* hpux */
- 
-
-#if (defined(OS_sinix) || defined(VENDOR_sni) || defined(SNI))
-#define predefined_devices
-struct device devices[] = {
-#ifdef CPU_mips     /* for Siemens Nixdorf's  SINIX-N/O (mips) 5.4x SVR4 */
-	{ "/dev/at/flp/f0t",    "A", FHD312},
-	{ "/dev/fd0",           "A", GENFD},
-#else
-#ifdef CPU_i386     /* for Siemens Nixdorf's  SINIX-D/L (intel) 5.4x SVR4 */
-	{ "/dev/fd0135ds18",	"A", FHD312},
-	{ "/dev/fd0135ds9",	"A", FDD312},
-	{ "/dev/fd0",		"A", GENFD},
-	{ "/dev/fd1135ds15",	"B", FHD514},
-	{ "/dev/fd1135ds9",	"B", FDD514},
-	{ "/dev/fd1",		"B", GENFD},
-#endif /* CPU_i386 */
-#endif /*mips*/
-	REMOTE
-};
-#endif
-
-#ifdef OS_ultrix
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rfd0a",		"A", GENFD}, /* guessed */
-	{"/dev/rfd0c",		"A", GENFD}, /* guessed */
-	REMOTE
-};
-
-#endif
-
-
-#ifdef OS_isc
-#define predefined_devices
-#if (defined(OS_isc2) && defined(OLDSTUFF))
-struct device devices[] = {
-	{"/dev/rdsk/f0d9dt",   	"A", FDD514},
-	{"/dev/rdsk/f0q15dt",	"A", FHD514},
-	{"/dev/rdsk/f0d8dt",	"A", FDDsmall},
-	{"/dev/rdsk/f13ht",	"B", FHD312},
-	{"/dev/rdsk/f13dt",	"B", FDD312},
-	{"/dev/rdsk/0p1",	"C", GENHD},
-	{"/usr/vpix/defaults/C:","D",12, 0, 0, 0, 0,8704L,DEF_ARG0},
-	{"$HOME/vpix/C:", 	"E", 12, 0, 0, 0, 0,8704L,MDEF_ARG},
-	REMOTE
-};
-#else
-/* contributed by larry.jones@sdrc.com (Larry Jones) */
-struct device devices[] = {
-	{"/dev/rfd0",		"A", GEN},
-	{"/dev/rfd1",		"B", GEN},
-	{"/dev/rdsk/0p1",	"C", GEN},
-	{"/usr/vpix/defaults/C:","D", GEN, 1},
-	{"$HOME/vpix/C:", 	"E", GEN, 1},
-	REMOTE
-};
-
-#include <sys/vtoc.h>
-#include <sys/sysmacros.h>
-#undef SSIZE
-#define BLOCK_MAJOR 1
-#define CHAR_MAJOR  1
-#define generic_floppy_struct disk_parms
-int ioctl(int, int, void *);
-
-static int get_parameters(int fd, struct generic_floppy_struct *floppy)
-{
-	mt_off_t off;
-	char buf[512];
-
-	off = lseek(fd, 0, SEEK_CUR);
-	if(off < 0) {
-		perror("device seek 1");
-		exit(1);
-	}
-	if (off == 0) {
-		/* need to read at least 1 sector to get correct info */
-		read(fd, buf, sizeof buf);
-		if(lseek(fd, 0, SEEK_SET) < 0) {
-			perror("device seek 2");
-			exit(1);
-		}
-	}
-	return ioctl(fd, V_GETPARMS, floppy);
-}
-
-#define TRACKS(floppy)  (floppy).dp_cyls
-#define HEADS(floppy)   (floppy).dp_heads
-#define SECTORS(floppy) (floppy).dp_sectors
-#define FD_SECTSIZE(floppy) (floppy).dp_secsiz
-#define FD_SET_SECTSIZE(floppy,v) { (floppy).dp_secsiz = (v); }
-
-static int set_parameters(int fd, struct generic_floppy_struct *floppy,
-	struct stat *buf)
-{
-	return 1;
-}
-
-#define INIT_GENERIC
-#endif
-#endif /* isc */
-
-#ifdef CPU_i370
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rfd0", "A", GENFD},
-	REMOTE
-};
-#endif /* CPU_i370 */
-
-#ifdef OS_aix
-/* modified by Federico Bianchi */
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/fd0","A",GENFD},
-	REMOTE
-};
-#endif /* aix */
-
-  
-#ifdef OS_osf4
-/* modified by Chris Samuel <chris@rivers.dra.hmg.gb> */
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/fd0c","A",GENFD},
-	REMOTE
-};
-#endif /* OS_osf4 */
-
-
-#ifdef OS_solaris
-
-#ifdef USING_NEW_VOLD
-
-char *alias_name = NULL;
-  
-extern char *media_oldaliases(char *);
-extern char *media_findname(char *);
-
-char *getVoldName(struct device *dev, char *name)
-{
-	char *rname;
-  
-	if(!SHOULD_USE_VOLD(dev))
-		return name;
-
-	/***
-	 * Solaris specific routines to use the volume management
-	 * daemon and libraries to get the correct device name...
-	 ***/
-	rname = media_findname(name);
-#ifdef HAVE_MEDIA_OLDALIASES
-	if (rname == NULL) {
-		if ((alias_name = media_oldaliases(name)) != NULL)
-			rname = media_findname(alias_name);
-	}
-#endif
-	if (rname == NULL) {
-		fprintf(stderr, 
-				"No such volume or no media in device: %s.\n", 
-				name);
-		exit(1);
-	}
-	return rname;
-}
-#endif /* USING_NEW_VOLD */
-
-#define predefined_devices
-struct device devices[] = {
-#ifdef  USING_NEW_VOLD
-	{"floppy", "A", VOLDFD },
-#elif	USING_VOLD
-	{"/vol/dev/aliases/floppy0", "A", GENFD},
-	{"/dev/rdiskette", "B", GENFD},
-#else	/* ! USING_VOLD */
-	{"/dev/rdiskette", "A", GENFD},
-	{"/vol/dev/aliases/floppy0", "B", GENFD},
-#endif	/* USING_VOLD */
-	{"/dev/rdsk/c0t4d0s2", "J", RJAZ(O_NDELAY)},
-	{"/dev/rdsk/c0t5d0s2", "Z", RZIP(O_NDELAY)},
-	REMOTE
-};
-
-
-
-/*
- * Ofer Licht <ofer@stat.Berkeley.EDU>, May 14, 1997.
- */
-
-#define INIT_GENERIC
-
-#include <sys/fdio.h>
-#include <sys/mkdev.h>	/* for major() */
-
-struct generic_floppy_struct
-{
-  struct fd_char fdchar;
-};
-
-#define BLOCK_MAJOR 36
-#define CHAR_MAJOR 36
-
-static inline int get_parameters(int fd, struct generic_floppy_struct *floppy)
-{
-	if (ioctl(fd, FDIOGCHAR, &(floppy->fdchar)) != 0) {
-		perror("");
-		ioctl(fd, FDEJECT, NULL);
-		return(1);
-	}
-	return 0;
-}
-
-#define TRACKS(floppy) floppy.fdchar.fdc_ncyl
-#define HEADS(floppy) floppy.fdchar.fdc_nhead
-#define SECTORS(floppy) floppy.fdchar.fdc_secptrack
-/* SECTORS_PER_DISK(floppy) not used */
-#define FD_SECTSIZE(floppy) floppy.fdchar.fdc_sec_size
-#define FD_SET_SECTSIZE(floppy,v) { floppy.fdchar.fdc_sec_size = v; }
-
-static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, 
-				 struct stat *buf)
-{
-	if (ioctl(fd, FDIOSCHAR, &(floppy->fdchar)) != 0) {
-		ioctl(fd, FDEJECT, NULL);
-		perror("");
-		return(1);
-	}
-	return 0;
-}
-#define INIT_GENERIC
-#endif /* solaris */
-
-#ifdef OS_sunos3
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rfdl0c",	"A", FDD312},
-	{"/dev/rfd0c",	"A", FHD312},
-	REMOTE
-};
-#endif /* OS_sunos3 */
-
-#ifdef OS_xenix
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/fd096ds15",	"A", FHD514},
-	{"/dev/fd048ds9",	"A", FDD514},
-	{"/dev/fd1135ds18",	"B", FHD312},
-	{"/dev/fd1135ds9",	"B", FDD312},
-	{"/dev/hd0d",		"C", GENHD},
-	REMOTE
-};
-#endif /* OS_xenix */
-
-#ifdef OS_sco
-#define predefined_devices
-struct device devices[] = {
-	{ "/dev/fd0135ds18",	"A", FHD312},
-	{ "/dev/fd0135ds9",	"A", FDD312},
-	{ "/dev/fd0",		"A", GENFD},
-	{ "/dev/fd1135ds15",	"B", FHD514},
-	{ "/dev/fd1135ds9",	"B", FDD514},
-	{ "/dev/fd1",		"B", GENFD},
-	{ "/dev/hd0d",		"C", GENHD},
-	REMOTE
-};
-#endif /* OS_sco */
-
-
-#ifdef OS_irix
-#define predefined_devices
-struct device devices[] = {
-  { "/dev/rdsk/fds0d2.3.5hi",	"A", FHD312},
-  { "/dev/rdsk/fds0d2.3.5",	"A", FDD312},
-  { "/dev/rdsk/fds0d2.96",	"A", FHD514},
-  {"/dev/rdsk/fds0d2.48",	"A", FDD514},
-  REMOTE
-};
-#endif /* OS_irix */
-
-
-#ifdef OS_sunos4
-#include <sys/ioctl.h>
-#include <sun/dkio.h>
-
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rfd0c",	"A", GENFD},
-	{"/dev/rsd4c",	"J", RJAZ(O_NDELAY)},
-	{"/dev/rsd5c",	"Z", RZIP(O_NDELAY)},
-	REMOTE
-};
-
-/*
- * Stuffing back the floppy parameters into the driver allows for gems
- * like 10 sector or single sided floppies from Atari ST systems.
- * 
- * Martin Schulz, Universite de Moncton, N.B., Canada, March 11, 1991.
- */
-
-#define INIT_GENERIC
-
-struct generic_floppy_struct
-{
-  struct fdk_char dkbuf;
-  struct dk_map dkmap;
-};
-
-#define BLOCK_MAJOR 16
-#define CHAR_MAJOR 54
-
-static inline int get_parameters(int fd, struct generic_floppy_struct *floppy)
-{
-	if (ioctl(fd, DKIOCGPART, &(floppy->dkmap)) != 0) {
-		perror("DKIOCGPART");
-		ioctl(fd, FDKEJECT, NULL);
-		return(1);
-	}
-	
-	if (ioctl(fd, FDKIOGCHAR, &( floppy->dkbuf)) != 0) {
-		perror("");
-		ioctl(fd, FDKEJECT, NULL);
-		return(1);
-	}
-	return 0;
-}
-
-#define TRACKS(floppy) floppy.dkbuf.ncyl
-#define HEADS(floppy) floppy.dkbuf.nhead
-#define SECTORS(floppy) floppy.dkbuf.secptrack
-#define SECTORS_PER_DISK(floppy) floppy.dkmap.dkl_nblk
-#define FD_SECTSIZE(floppy) floppy.dkbuf.sec_size
-#define FD_SET_SECTSIZE(floppy,v) { floppy.dkbuf.sec_size = v; }
-
-static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, 
-				 struct stat *buf)
-{
-	if (ioctl(fd, FDKIOSCHAR, &(floppy->dkbuf)) != 0) {
-		ioctl(fd, FDKEJECT, NULL);
-		perror("");
-		return(1);
-	}
-	
-	if (ioctl(fd, ( unsigned int) DKIOCSPART, &(floppy->dkmap)) != 0) {
-		ioctl(fd, FDKEJECT, NULL);
-		perror("");
-		return(1);
-	}
-	return 0;
-}
-#define INIT_GENERIC
-#endif /* sparc && sunos */
-
-
-#ifdef DPX1000
-#define predefined_devices
-struct device devices[] = {
-	/* [block device]: DPX1000 has /dev/flbm60, DPX2 has /dev/easyfb */
-	{"/dev/flbm60", "A", MHD514};
-	{"/dev/flbm60", "B", MDD514},
-	{"/dev/flbm60", "C", MDDsmall},
-	{"/dev/flbm60", "D", MSS},
-	{"/dev/flbm60", "E", MSSsmall},
-	REMOTE
-};
-#endif /* DPX1000 */
-
-#ifdef OS_bosx
-#define predefined_devices
-struct device devices[] = {
-	/* [block device]: DPX1000 has /dev/flbm60, DPX2 has /dev/easyfb */
-	{"/dev/easyfb", "A", MHD514},
-	{"/dev/easyfb", "B", MDD514},
-	{"/dev/easyfb", "C", MDDsmall},
-	{"/dev/easyfb", "D", MSS},
-	{"/dev/easyfb", "E", MSSsmall},
-	REMOTE
-};
-#endif /* OS_bosx */
-
-#ifdef OS_linux
-
-const char *error_msg[22]={
-"Missing Data Address Mark",
-"Bad cylinder",
-"Scan not satisfied",
-"Scan equal hit",
-"Wrong cylinder",
-"CRC error in data field",
-"Control Mark = deleted",
-0,
-
-"Missing Address Mark",
-"Write Protect",
-"No Data - unreadable",
-0,
-"OverRun",
-"CRC error in data or address",
-0,
-"End Of Cylinder",
-
-0,
-0,
-0,
-"Not ready",
-"Equipment check error",
-"Seek end" };
-
-
-static inline void print_message(RawRequest_t *raw_cmd,const char *message)
-{
-	int i, code;
-	if(!message)
-		return;
-
-	fprintf(stderr,"   ");
-	for (i=0; i< raw_cmd->cmd_count; i++)
-		fprintf(stderr,"%2.2x ", 
-			(int)raw_cmd->cmd[i] );
-	fprintf(stderr,"\n");
-	for (i=0; i< raw_cmd->reply_count; i++)
-		fprintf(stderr,"%2.2x ",
-			(int)raw_cmd->reply[i] );
-	fprintf(stderr,"\n");
-	code = (raw_cmd->reply[0] <<16) + 
-		(raw_cmd->reply[1] << 8) + 
-		raw_cmd->reply[2];
-	for(i=0; i<22; i++){
-		if ((code & (1 << i)) && error_msg[i])
-			fprintf(stderr,"%s\n",
-				error_msg[i]);
-	}
-}
-
-
-/* return values:
- *  -1: Fatal error, don't bother retrying.
- *   0: OK
- *   1: minor error, retry
- */
-
-int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message)
-{
-	if (ioctl( fd, FDRAWCMD, raw_cmd) >= 0) {
-		if (raw_cmd->reply_count < 7) {
-			fprintf(stderr,"Short reply from FDC\n");
-			return -1;
-		}		
-		return 0;
-	}
-
-	switch(errno) {
-		case EBUSY:
-			fprintf(stderr, "FDC busy, sleeping for a second\n");
-			sleep(1);
-			return 1;
-		case EIO:
-			fprintf(stderr,"resetting controller\n");
-			if(ioctl(fd, FDRESET, 2)  < 0){
-				perror("reset");
-				return -1;
-			}
-			return 1;
-		default:
-			perror(message);
-			return -1;
-	}
-}
-
-
-/*
- * return values
- *  -1: error
- *   0: OK, last sector
- *   1: more raw commands follow
- */
-
-int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print)
-{
-	
-	if(raw_cmd->reply_count == 7) {
-		int end;
-		
-		if (raw_cmd->reply[3] != raw_cmd->cmd[2]) {
-			/* end of cylinder */
-			end = raw_cmd->cmd[6] + 1;
-		} else {
-			end = raw_cmd->reply[5];
-		}
-
-		*bytes = end - raw_cmd->cmd[4];
-		/* FIXME: over/under run */
-		*bytes = *bytes << (7 + raw_cmd->cmd[5]);
-	} else
-		*bytes = 0;       
-
-	switch(raw_cmd->reply[0] & 0xc0){
-		case 0x40:
-			if ((raw_cmd->reply[0] & 0x38) == 0 &&
-			    (raw_cmd->reply[1]) == 0x80 &&
-			    (raw_cmd->reply[2]) == 0) {
-				*bytes += 1 << (7 + raw_cmd->cmd[5]);
-				break;
-			}
-
-			if ( raw_cmd->reply[1] & ST1_WP ){
-				*bytes = 0;
-				fprintf(stderr,
-					"This disk is write protected\n");
-				return -1;
-			}
-			if(!*bytes && do_print)
-				print_message(raw_cmd, "");
-			return -1;
-		case 0x80:
-			*bytes = 0;
-			fprintf(stderr,
-				"invalid command given\n");
-			return -1;
-		case 0xc0:
-			*bytes = 0;
-			fprintf(stderr,
-				"abnormal termination caused by polling\n");
-			return -1;
-		default:
-			break;
-	}	
-#ifdef FD_RAW_MORE
-	if(raw_cmd->flags & FD_RAW_MORE)
-		return 1;
-#endif
-	return 0;
-}
-
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/fd0", "A", 0, O_EXCL, 80,2, 18,0, MDEF_ARG},
-	{"/dev/fd1", "B", 0, O_EXCL, 0,0, 0,0, FDEF_ARG},
-	/* we assume that the Zip or Jaz drive is the second on the SCSI bus */
-	{"/dev/sdb4","J", GENHD },
-	{"/dev/sdb4","Z", GENHD },
-	/*	{"/dev/sda4","D", GENHD },*/
-	REMOTE
-};
-
-/*
- * Stuffing back the floppy parameters into the driver allows for gems
- * like 21 sector or single sided floppies from Atari ST systems.
- * 
- * Alain Knaff, Université Joseph Fourier, France, November 12, 1993.
- */
-
-
-#define INIT_GENERIC
-#define generic_floppy_struct floppy_struct
-#define BLOCK_MAJOR 2
-#define SECTORS(floppy) floppy.sect
-#define TRACKS(floppy) floppy.track
-#define HEADS(floppy) floppy.head
-#define SECTORS_PER_DISK(floppy) floppy.size
-#define STRETCH(floppy) floppy.stretch
-#define USE_2M(floppy) ((floppy.rate & FD_2M) ? 0xff : 0x80 )
-#define SSIZE(floppy) ((((floppy.rate & 0x38) >> 3 ) + 2) % 8)
-
-static inline void set_2m(struct floppy_struct *floppy, int value)
-{
-	if (value & 0x7f)
-		value = FD_2M;
-	else
-		value = 0;
-	floppy->rate = (floppy->rate & ~FD_2M) | value;       
-}
-#define SET_2M set_2m
-
-static inline void set_ssize(struct floppy_struct *floppy, int value)
-{
-	value = (( (value & 7) + 6 ) % 8) << 3;
-
-	floppy->rate = (floppy->rate & ~0x38) | value;	
-}
-
-#define SET_SSIZE set_ssize
-
-static inline int set_parameters(int fd, struct floppy_struct *floppy, 
-				 struct stat *buf)
-{
-	if ( ( MINOR(buf->st_rdev ) & 0x7f ) > 3 )
-		return 1;
-	
-	return ioctl(fd, FDSETPRM, floppy);
-}
-
-static inline int get_parameters(int fd, struct floppy_struct *floppy)
-{
-	return ioctl(fd, FDGETPRM, floppy);
-}
-
-#endif /* linux */
-
-
-/* OS/2, gcc+emx */
-#ifdef __EMX__
-#define predefined_devices
-struct device devices[] = {
-  {"A:", "A", GENFD},
-  {"B:", "B", GENFD},
-};
-#define INIT_NOOP
-#endif
-
-
-
-/*** /jes -- for D.O.S. 486 BL DX2/80 ***/
-#ifdef OS_freebsd
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rfd0.1440", "A", FHD312},
-	{"/dev/rfd0.720",  "A", FDD312},
-	{"/dev/rfd1.1200", "B", MHD514},
-	{"/dev/sd0s1",     "C", GENHD},
-	REMOTE
-};
-#endif /* __FreeBSD__ */
- 
-/*** /jes -- for ALR 486 DX4/100 ***/
-#if defined(OS_netbsd)
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rfd0a", "A", FHD312},
-	{"/dev/rfd0f", "A", FDD312},
-	{"/dev/rfd0f", "S", MDD312},
-	{"/dev/rfd1a", "B", FHD514},
-	{"/dev/rfd1d", "B", FDD514},
-	{"/dev/rfd1d", "T", MDD514},
-	{"/dev/rwd0d", "C", 16, 0, 0, 0, 0, 0, 63L*512L, DEF_ARG0(0)},
-	REMOTE
-};
-#endif /* OS_NetBSD */
-
-/* fgsch@openbsd.org 2000/05/19 */
-#if defined(OS_openbsd)
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rfd0Bc", "A", FHD312},
-	{"/dev/rfd0Fc", "A", FDD312},
-	{"/dev/rfd1Cc", "B", FHD514},
-	{"/dev/rfd1Dc", "B", FDD514},
-	{"/dev/rwd0c", "C", 16, 0, 0, 0, 0, 0, 63L*512L, DEF_ARG0(0)},
-	REMOTE
-};
-#endif /* OS_openbsd */
-
-
-
-#if (!defined(predefined_devices) && defined (CPU_m68000) && defined (OS_sysv))
-#include <sys/gdioctl.h>
-
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rfp020",		"A", 12,O_NDELAY,40,2, 9, 0, MDEF_ARG},
-	{"/usr/bin/DOS/dvd000", "C", GENFD},
-	REMOTE
-};
-
-#undef INIT_NOOP
-int init_geom(int fd, struct device *dev, struct device *orig_dev,
-	      struct stat *stat)
-{
-	struct gdctl gdbuf;
-
-	if (ioctl(fd, GDGETA, &gdbuf) == -1) {
-		ioctl(fd, GDDISMNT, &gdbuf);
-		return 1;
-	}
-	if((dev->use_2m & 0x7f) || (dev->ssize & 0x7f))
-		return 1;
-	
-	SET_INT(gdbuf.params.cyls,dev->ntracks);
-	SET_INT(gdbuf.params.heads,dev->nheads);
-	SET_INT(gdbuf.params.psectrk,dev->nsect);
-	dev->ntracks = gdbuf.params.cyls;
-	dev->nheads = gdbuf.params.heads;
-	dev->nsect = gdbuf.params.psectrk;
-	dev->use_2m = 0x80;
-	dev->ssize = 0x82;
-
-	gdbuf.params.pseccyl = gdbuf.params.psectrk * gdbuf.params.heads;
-	gdbuf.params.flags = 1;		/* disk type flag */
-	gdbuf.params.step = 0;		/* step rate for controller */
-	gdbuf.params.sectorsz = 512;	/* sector size */
-
-	if (ioctl(fd, GDSETA, &gdbuf) < 0) {
-		ioctl(fd, GDDISMNT, &gdbuf);
-		return(1);
-	}
-	return(0);
-}
-#endif /* (defined (m68000) && defined (sysv))*/
-
-#ifdef CPU_alpha
-#ifndef OS_osf4
-#ifdef __osf__
-#include <sys/fcntl.h>
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rfd0c",		"A", GENFD},
-	REMOTE
-};
-#endif
-#endif
-#endif
-
-#ifdef OS_osf
-#ifndef predefined_devices
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/fd0a", "A",  MHD312 } };
-	REMOTE
-#endif
-#endif
-
-
-#ifdef OS_nextstep
-#define predefined_devices
-struct device devices[] = {
-#ifdef CPU_m68k
-	{"/dev/rfd0b", "A", MED312 },
-	REMOTE
-#else
-	{"/dev/rfd0b", "A", MHD312 },
-	REMOTE
-#endif
-};
-#endif
-
-
-#if (!defined(predefined_devices) && defined(OS_sysv4))
-#ifdef __uxp__
-#define predefined_devices
-struct device devices[] = {
-      {"/dev/fpd0",   "A", FHD312},
-      {"/dev/fpd0",   "A", FDD312},
-	  REMOTE
-};
-#else
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/rdsk/f1q15dt",	"B", FHD514},
-	{"/dev/rdsk/f1d9dt",	"B", FDD514},
-	{"/dev/rdsk/f1d8dt",	"B", FDDsmall},
-	{"/dev/rdsk/f03ht",	"A", FHD312},
-	{"/dev/rdsk/f03dt",	"A", FDD312},
-	{"/dev/rdsk/dos",	"C", GENHD},
-	REMOTE
-};
-#endif
-#endif /* sysv4 */
-
-#ifdef OS_Minix
-/* Minix and Minix-vmd device list.  Only present to attach the A: and B:
- * drive letters to the floppies by default.  Other devices can be given
- * a drive letter by linking the device file to /dev/dosX, where X is a
- * drive letter.  Or one can use something like 'fd0:' for a drive name.
- *						Kees J. Bot <kjb@cs.vu.nl>
- */
-#include <minix/partition.h>
-#include <minix/u64.h>
-
-#define predefined_devices
-struct device devices[] = {
-	{"/dev/fd0", "A", GEN},
-	{"/dev/fd1", "B", GEN},
-};
-
-#undef INIT_NOOP
-int init_geom(int fd, struct device *dev, struct device *orig_dev,
-	      struct stat *stat)
-{
-	/* Try to obtain the device parameters from the device driver.
-	 * Don't fret if you can't, mtools will use the DOS boot block.
-	 */
-	struct partition geom;
-	unsigned long tot_sectors;
-
-	if (ioctl(fd, DIOCGETP, &geom) == 0) {
-		dev->hidden = div64u(geom.base, 512);
-		tot_sectors = div64u(geom.size, 512);
-		dev->tracks = tot_sectors / (geom.heads * geom.sectors);
-		dev->heads = geom.heads;
-		dev->sectors = geom.sectors;
-	}
-	return(0);
-}
-#endif /* OS_Minix */
-
-#ifdef INIT_GENERIC
-
-#ifndef USE_2M
-#define USE_2M(x) 0x80
-#endif
-
-#ifndef SSIZE
-#define SSIZE(x) 0x82
-#endif
-
-#ifndef SET_2M
-#define SET_2M(x,y) return -1
-#endif
-
-#ifndef SET_SSIZE
-#define SET_SSIZE(x,y) return -1
-#endif
-
-#undef INIT_NOOP
-int init_geom(int fd, struct device *dev, struct device *orig_dev,
-	      struct stat *stat)
-{
-	struct generic_floppy_struct floppy;
-	int change;
-	
-	/* 
-	 * succeed if we don't have a floppy
-	 * this is the case for dosemu floppy image files for instance
-	 */
-	if (!((S_ISBLK(stat->st_mode) && major(stat->st_rdev) == BLOCK_MAJOR)
-#ifdef CHAR_MAJOR
-	      || (S_ISCHR(stat->st_mode) && major(stat->st_rdev) == CHAR_MAJOR) 
-#endif
-		))
-		return compare_geom(dev, orig_dev);
-	
-	/*
-	 * We first try to get the current floppy parameters from the kernel.
-	 * This allows us to
-	 * 1. get the rate
-	 * 2. skip the parameter setting if the parameters are already o.k.
-	 */
-	
-	if (get_parameters( fd, & floppy ) )
-		/* 
-		 * autodetection failure.
-		 * This mostly occurs because of an absent or unformatted disks.
-		 *
-		 * It might also occur because of bizarre formats (for example 
-		 * rate 1 on a 3 1/2 disk).
-
-		 * If this is the case, the user should do an explicit 
-		 * setfdprm before calling mtools
-		 *
-		 * Another cause might be pre-existing wrong parameters. The 
-		 * user should do an setfdprm -c to repair this situation.
-		 *
-		 * ...fail immediately... ( Theoretically, we could try to save
-		 * the situation by trying out all rates, but it would be slow 
-		 * and awkward)
-		 */
-		return 1;
-
-
-	/* 
-	 * if we have already have the correct parameters, keep them.
-	 * the number of tracks doesn't need to match exactly, it may be bigger.
-	 * the number of heads and sectors must match exactly, to avoid 
-	 * miscalculation of the location of a block on the disk
-	 */
-	change = 0;
-	if(compare(dev->sectors, SECTORS(floppy))){
-		SECTORS(floppy) = dev->sectors;
-		change = 1;
-	} else
-		dev->sectors = SECTORS(floppy);
-
-	if(compare(dev->heads, HEADS(floppy))){
-		HEADS(floppy) = dev->heads;
-		change = 1;
-	} else
-		dev->heads = HEADS(floppy);
-	 
-	if(compare(dev->tracks, TRACKS(floppy))){
-		TRACKS(floppy) = dev->tracks;
-		change = 1;
-	} else
-		dev->tracks = TRACKS(floppy);
-
-
-	if(compare(dev->use_2m, USE_2M(floppy))){
-		SET_2M(&floppy, dev->use_2m);
-		change = 1;
-	} else
-		dev->use_2m = USE_2M(floppy);
-	
-	if( ! (dev->ssize & 0x80) )
-		dev->ssize = 0;
-	if(compare(dev->ssize, SSIZE(floppy) + 128)){
-		SET_SSIZE(&floppy, dev->ssize);
-		change = 1;
-	} else
-		dev->ssize = SSIZE(floppy);
-
-	if(!change)
-		/* no change, succeed */
-		return 0;
-
-#ifdef SECTORS_PER_TRACK
-	SECTORS_PER_TRACK(floppy) = dev->sectors * dev->heads;
-#endif
-
-#ifdef SECTORS_PER_DISK
-	SECTORS_PER_DISK(floppy) = dev->sectors * dev->heads * dev->tracks;
-#endif
-	
-#ifdef STRETCH
-	/* ... and the stretch */
-	if ( dev->tracks > 41 ) 
-		STRETCH(floppy) = 0;
-	else
-		STRETCH(floppy) = 1;
-#endif
-	
-	return set_parameters( fd, &floppy, stat) ;
-}
-#endif /* INIT_GENERIC */  
-
-#ifdef INIT_NOOP
-int init_geom(int fd, struct device *dev, struct device *orig_dev,
-			  struct stat *stat)
-{
-	return compare_geom(dev, orig_dev);
-}
-#endif
-
-#ifdef predefined_devices
-const int nr_const_devices = sizeof(const_devices) / sizeof(*const_devices);
-#else
-struct device devices[]={
-	{"/dev/fd0", "A", 0, O_EXCL, 0,0, 0,0, MDEF_ARG},
-	/* to shut up Ultrix's native compiler, we can't make this empty :( */
-};
-const nr_const_devices = 0;
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/devices.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/devices.h	(revision 9)
+++ 	(revision )
@@ -1,169 +1,0 @@
-#ifdef OS_linux
-
-#ifdef HAVE_SYS_SYSMACROS_H
-
-#include <sys/sysmacros.h>
-#ifndef MAJOR
-#define MAJOR(dev) major(dev)
-#endif  /* MAJOR not defined */
-#ifndef MINOR
-#define MINOR(dev) minor(dev)
-#endif  /* MINOR not defined */
-
-#else
- 
-#include <linux/fs.h>        /* get MAJOR/MINOR from Linux kernel */
-#ifndef major
-#define major(x) MAJOR(x)
-#endif
-
-#endif /* HAVE_SYS_SYSMACROS_H */
-
-#include <linux/fd.h>
-#include <linux/fdreg.h>
-#include <linux/major.h>
-
-
-typedef struct floppy_raw_cmd RawRequest_t;
-
-UNUSED(static inline void RR_INIT(struct floppy_raw_cmd *request))
-{
-	request->data = 0;
-	request->length = 0;
-	request->cmd_count = 9;
-	request->flags = FD_RAW_INTR | FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK
-#ifdef FD_RAW_SOFTFAILUE
-		| FD_RAW_SOFTFAILURE | FD_RAW_STOP_IF_FAILURE
-#endif
-		;
-	request->cmd[1] = 0;
-	request->cmd[6] = 0;
-	request->cmd[7] = 0x1b;
-	request->cmd[8] = 0xff;
-	request->reply_count = 0;
-}
-
-UNUSED(static inline void RR_SETRATE(struct floppy_raw_cmd *request, int rate))
-{
-	request->rate = rate;
-}
-
-UNUSED(static inline void RR_SETDRIVE(struct floppy_raw_cmd *request,int drive))
-{
-	request->cmd[1] = (request->cmd[1] & ~3) | (drive & 3);
-}
-
-UNUSED(static inline void RR_SETTRACK(struct floppy_raw_cmd *request,int track))
-{
-	request->cmd[2] = track;
-}
-
-UNUSED(static inline void RR_SETPTRACK(struct floppy_raw_cmd *request,
-				       int track))
-{
-	request->track = track;
-}
-
-UNUSED(static inline void RR_SETHEAD(struct floppy_raw_cmd *request, int head))
-{
-	if(head)
-		request->cmd[1] |= 4;
-	else
-		request->cmd[1] &= ~4;
-	request->cmd[3] = head;
-}
-
-UNUSED(static inline void RR_SETSECTOR(struct floppy_raw_cmd *request, 
-				       int sector))
-{
-	request->cmd[4] = sector;
-	request->cmd[6] = sector-1;
-}
-
-UNUSED(static inline void RR_SETSIZECODE(struct floppy_raw_cmd *request, 
-					 int sizecode))
-{
-	request->cmd[5] = sizecode;
-	request->cmd[6]++;
-	request->length += 128 << sizecode;
-}
-
-#if 0
-static inline void RR_SETEND(struct floppy_raw_cmd *request, int end)
-{
-	request->cmd[6] = end;
-}
-#endif
-
-UNUSED(static inline void RR_SETDIRECTION(struct floppy_raw_cmd *request, 
-					  int direction))
-{
-	if(direction == MT_READ) {
-		request->flags |= FD_RAW_READ;
-		request->cmd[0] = FD_READ & ~0x80;
-	} else {
-		request->flags |= FD_RAW_WRITE;
-		request->cmd[0] = FD_WRITE & ~0x80;
-	}
-}
-
-
-UNUSED(static inline void RR_SETDATA(struct floppy_raw_cmd *request, 
-				     caddr_t data))
-{
-	request->data = data;
-}
-
-
-#if 0
-static inline void RR_SETLENGTH(struct floppy_raw_cmd *request, int length)
-{
-	request->length += length;
-}
-#endif
-
-UNUSED(static inline void RR_SETCONT(struct floppy_raw_cmd *request))
-{
-#ifdef FD_RAW_MORE
-	request->flags |= FD_RAW_MORE;
-#endif
-}
-
-
-UNUSED(static inline int RR_SIZECODE(struct floppy_raw_cmd *request))
-{
-	return request->cmd[5];
-}
-
-
-
-UNUSED(static inline int RR_TRACK(struct floppy_raw_cmd *request))
-{
-	return request->cmd[2];
-}
-
-
-UNUSED(static inline int GET_DRIVE(int fd))
-{
-	struct stat statbuf;
-
-	if (fstat(fd, &statbuf) < 0 ){
-		perror("stat");
-		return -1;
-	}
-	  
-	if (!S_ISBLK(statbuf.st_mode) ||
-	    MAJOR(statbuf.st_rdev) != FLOPPY_MAJOR)
-		return -1;
-	
-	return MINOR( statbuf.st_rdev );
-}
-
-
-
-/* void print_message(RawRequest_t *raw_cmd,char *message);*/
-int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message);
-int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print);
-
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/dirCache.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/dirCache.c	(revision 9)
+++ 	(revision )
@@ -1,329 +1,0 @@
-#include "sysincludes.h"
-#include "vfat.h"
-#include "dirCache.h"
-
-
-void myfree(void *a)
-{
-	free(a);
-}
-
-#define free myfree
-
-
-#define BITS_PER_INT (sizeof(unsigned int) * 8)
-
-
-static inline unsigned int rol(unsigned int arg, int shift)
-{
-	arg &= 0xffffffff; /* for 64 bit machines */
-	return (arg << shift) | (arg >> (32 - shift));
-}
-
-
-static int calcHash(char *name)
-{
-	unsigned long hash;
-	int i;
-	unsigned char c;
-
-	hash = 0;
-	i = 0;
-	while(*name) {
-		/* rotate it */
-		hash = rol(hash,5); /* a shift of 5 makes sure we spread quickly
-				     * over the whole width, moreover, 5 is
-				     * prime with 32, which makes sure that
-				     * successive letters cannot cover each 
-				     * other easily */
-		c = toupper(*name);
-		hash ^=  (c * (c+2)) ^ (i * (i+2));
-		hash &= 0xffffffff;
-		i++, name++;
-	}
-	hash = hash * (hash + 2);
-	/* the following two xors make sure all info is spread evenly over all
-	 * bytes. Important if we only keep the low order bits later on */
-	hash ^= (hash & 0xfff) << 12;
-	hash ^= (hash & 0xff000) << 24;
-	return hash;
-}
-
-static int addBit(unsigned int *bitmap, int hash, int checkOnly)
-{
-	int bit, entry;
-
-	bit = 1 << (hash % BITS_PER_INT);
-	entry = (hash / BITS_PER_INT) % DC_BITMAP_SIZE;
-	
-	if(checkOnly)
-		return bitmap[entry] & bit;
-	else {
-		bitmap[entry] |= bit;
-		return 1;
-	}
-}
-
-static int _addHash(dirCache_t *cache, unsigned int hash, int checkOnly)
-{
-	return
-		addBit(cache->bm0, hash, checkOnly) &&
-		addBit(cache->bm1, rol(hash,12), checkOnly) &&
-		addBit(cache->bm2, rol(hash,24), checkOnly);
-}
-
-
-static void addNameToHash(dirCache_t *cache, char *name)
-{	
-	_addHash(cache, calcHash(name), 0);
-}
-
-static void hashDce(dirCache_t *cache, dirCacheEntry_t *dce)
-{
-	if(dce->beginSlot != cache->nrHashed)
-		return;
-	cache->nrHashed = dce->endSlot;
-	if(dce->longName)
-		addNameToHash(cache, dce->longName);
-	addNameToHash(cache, dce->shortName);
-}
-
-int isHashed(dirCache_t *cache, char *name)
-{
-	int ret;
-
-	ret =  _addHash(cache, calcHash(name), 1);
-	return ret;
-}
-
-void checkXYZ(dirCache_t *cache)
-{
-	if(cache->entries[2])
-		printf(" at 2 = %d\n", cache->entries[2]->beginSlot);
-}
-
-
-int growDirCache(dirCache_t *cache, int slot)
-{
-	if(slot < 0) {
-		fprintf(stderr, "Bad slot %d\n", slot);
-		exit(1);
-	}
-
-	if( cache->nr_entries <= slot) {
-		int i;
-		
-		cache->entries = realloc(cache->entries,
-					 (slot+1) * 2 * 
-					 sizeof(dirCacheEntry_t *));
-		if(!cache->entries)
-			return -1;
-		for(i= cache->nr_entries; i < (slot+1) * 2; i++) {
-			cache->entries[i] = 0;
-		}
-		cache->nr_entries = (slot+1) * 2;
-	}
-	return 0;
-}
-
-dirCache_t *allocDirCache(Stream_t *Stream, int slot)
-{       
-	dirCache_t **dcp;
-
-	if(slot < 0) {
-		fprintf(stderr, "Bad slot %d\n", slot);
-		exit(1);
-	}
-
-	dcp = getDirCacheP(Stream);
-	if(!*dcp) {
-		*dcp = New(dirCache_t);
-		if(!*dcp)
-			return 0;
-		(*dcp)->entries = NewArray((slot+1)*2+5, dirCacheEntry_t *);
-		if(!(*dcp)->entries) {
-			free(*dcp);
-			return 0;
-		}
-		(*dcp)->nr_entries = (slot+1) * 2;
-		memset( (*dcp)->bm0, 0, DC_BITMAP_SIZE);
-		memset( (*dcp)->bm1, 0, DC_BITMAP_SIZE);
-		memset( (*dcp)->bm2, 0, DC_BITMAP_SIZE);
-		(*dcp)->nrHashed = 0;
-	} else
-		if(growDirCache(*dcp, slot) < 0)
-			return 0;
-	return *dcp;
-}
-
-static void freeDirCacheRange(dirCache_t *cache, int beginSlot, int endSlot)
-{
-	dirCacheEntry_t *entry;
-	int clearBegin;
-	int clearEnd;
-	int i;
-
-	if(endSlot < beginSlot) {
-		fprintf(stderr, "Bad slots %d %d in free range\n", 
-			beginSlot, endSlot);
-		exit(1);
-	}
-
-	while(beginSlot < endSlot) {
-		entry = cache->entries[beginSlot];
-		if(!entry) {
-			beginSlot++;
-			continue;
-		}
-		
-		clearEnd = entry->endSlot;
-		if(clearEnd > endSlot)
-			clearEnd = endSlot;
-		clearBegin = beginSlot;
-		
-		for(i = clearBegin; i <clearEnd; i++)
-			cache->entries[i] = 0;
-
-		if(entry->endSlot == endSlot)
-			entry->endSlot = beginSlot;
-		else if(entry->beginSlot == beginSlot)
-			entry->beginSlot = endSlot;
-		else {
-			fprintf(stderr, 
-				"Internal error, non contiguous de-allocation\n");
-			fprintf(stderr, "%d %d\n", beginSlot, endSlot);
-			fprintf(stderr, "%d %d\n", entry->beginSlot, 
-				entry->endSlot);
-			exit(1);			
-		}
-
-		if(entry->beginSlot == entry->endSlot) {
-			if(entry->longName)
-				free(entry->longName);
-			if(entry->shortName)
-				free(entry->shortName);
-			free(entry);
-		}
-
-		beginSlot = clearEnd;
-	}
-}
-
-static dirCacheEntry_t *allocDirCacheEntry(dirCache_t *cache, int beginSlot, 
-					   int endSlot,
-					   dirCacheEntryType_t type)
-{
-	dirCacheEntry_t *entry;
-	int i;
-
-	if(growDirCache(cache, endSlot) < 0)
-		return 0;
-
-	entry = New(dirCacheEntry_t);
-	if(!entry)
-		return 0;
-	entry->type = type;
-	entry->longName = 0;
-	entry->shortName = 0;
-	entry->beginSlot = beginSlot;
-	entry->endSlot = endSlot;
-
-	freeDirCacheRange(cache, beginSlot, endSlot);
-	for(i=beginSlot; i<endSlot; i++) {
-		cache->entries[i] = entry;
-	}
-	return entry;
-}
-
-dirCacheEntry_t *addUsedEntry(dirCache_t *cache, int beginSlot, int endSlot, 
-			      char *longName, char *shortName,
-			      struct directory *dir)
-{
-	dirCacheEntry_t *entry;
-
-	if(endSlot < beginSlot) {
-		fprintf(stderr, 
-			"Bad slots %d %d in add used entry\n", 
-			beginSlot, endSlot);
-		exit(1);
-	}
-
-
-	entry = allocDirCacheEntry(cache, beginSlot, endSlot, DCET_USED);
-	if(!entry)
-		return 0;
-	
-	entry->beginSlot = beginSlot;
-	entry->endSlot = endSlot;
-	if(longName)
-		entry->longName = strdup(longName);
-	entry->shortName = strdup(shortName);
-	entry->dir = *dir;
-	hashDce(cache, entry);
-	return entry;
-}
-
-static void mergeFreeSlots(dirCache_t *cache, int slot)
-{
-	dirCacheEntry_t *previous, *next;
-	int i;
-
-	if(slot == 0)
-		return;
-	previous = cache->entries[slot-1];
-	next = cache->entries[slot];
-	if(next && next->type == DCET_FREE &&
-	   previous && previous->type == DCET_FREE) {
-		for(i=next->beginSlot; i < next->endSlot; i++)
-			cache->entries[i] = previous;
-		previous->endSlot = next->endSlot;
-		free(next);		
-	}
-}
-
-dirCacheEntry_t *addFreeEntry(dirCache_t *cache, int beginSlot, int endSlot)
-{
-	dirCacheEntry_t *entry;
-
-	if(beginSlot < cache->nrHashed)
-		cache->nrHashed = beginSlot;
-
-	if(endSlot < beginSlot) {
-		fprintf(stderr, "Bad slots %d %d in add free entry\n", 
-			beginSlot, endSlot);
-		exit(1);
-	}
-
-	if(endSlot == beginSlot)
-		return 0;
-	entry = allocDirCacheEntry(cache, beginSlot, endSlot, DCET_FREE);
-	mergeFreeSlots(cache, beginSlot);
-	mergeFreeSlots(cache, endSlot);
-	return cache->entries[beginSlot];
-}
-
-
-dirCacheEntry_t *addEndEntry(dirCache_t *cache, int pos)
-{
-	return allocDirCacheEntry(cache, pos, pos+1, DCET_END);
-}
-
-dirCacheEntry_t *lookupInDircache(dirCache_t *cache, int pos)
-{
-	if(growDirCache(cache, pos+1) < 0)
-		return 0;
-	return cache->entries[pos];	
-}
-
-void freeDirCache(Stream_t *Stream)
-{
-	dirCache_t *cache, **dcp;
-
-	dcp = getDirCacheP(Stream);
-	cache = *dcp;
-	if(cache) {
-		freeDirCacheRange(cache, 0, cache->nr_entries);
-		free(cache);
-		*dcp = 0;
-	}
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/dirCache.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/dirCache.h	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#ifndef MTOOLS_DIRCACHE_H
-#define MTOOLS_DIRCACHE_H
-
-typedef enum {
-	DCET_FREE,
-	DCET_USED,
-	DCET_END
-} dirCacheEntryType_t;
-
-#define DC_BITMAP_SIZE 128
-
-typedef struct dirCacheEntry_t {
-	dirCacheEntryType_t type;
-	int beginSlot;
-	int endSlot;
-	char *shortName;
-	char *longName;
-	struct directory dir;
-} dirCacheEntry_t;
-
-typedef struct dirCache_t {
-	struct dirCacheEntry_t **entries;
-	int nr_entries;
-	unsigned int nrHashed;
-	unsigned int bm0[DC_BITMAP_SIZE];
-	unsigned int bm1[DC_BITMAP_SIZE];
-	unsigned int bm2[DC_BITMAP_SIZE];
-} dirCache_t;
-
-int isHashed(dirCache_t *cache, char *name);
-int growDirCache(dirCache_t *cache, int slot);
-dirCache_t *allocDirCache(Stream_t *Stream, int slot);
-dirCacheEntry_t *addUsedEntry(dirCache_t *Stream, int begin, int end, 
-			      char *longName, char *shortName,
-			      struct directory *dir);
-void freeDirCache(Stream_t *Stream);
-dirCacheEntry_t *addFreeEntry(dirCache_t *Stream, int begin, int end);
-dirCacheEntry_t *addEndEntry(dirCache_t *Stream, int pos);
-dirCacheEntry_t *lookupInDircache(dirCache_t *Stream, int pos);
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/directory.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/directory.c	(revision 9)
+++ 	(revision )
@@ -1,106 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "stream.h"
-#include "mtools.h"
-#include "file.h"
-#include "fs.h"
-
-/* #define DEBUG */
-
-/*
- * Read a directory entry into caller supplied buffer
- */
-struct directory *dir_read(direntry_t *entry, int *error)
-{
-	int n;
-	*error = 0;
-	if((n=force_read(entry->Dir, (char *) (&entry->dir), 
-			 (mt_off_t) entry->entry * MDIR_SIZE, 
-			 MDIR_SIZE)) != MDIR_SIZE) {
-		if (n < 0) {
-			*error = -1;
-		}
-		return NULL;
-	}
-	return &entry->dir;
-}
-
-/*
- * Make a subdirectory grow in length.  Only subdirectories (not root)
- * may grow.  Returns a 0 on success, 1 on failure (disk full), or -1
- * on error.
- */
-
-int dir_grow(Stream_t *Dir, int size)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(FsPublic_t);
-	int ret;
-	int buflen;
-	char *buffer;
-	
-	if (!getfreeMinClusters(Dir, 1))
-		return -1;
-
-	buflen = This->cluster_size * This->sector_size;
-
-	if(! (buffer=malloc(buflen)) ){
-		perror("dir_grow: malloc");
-		return -1;
-	}
-		
-	memset((char *) buffer, '\0', buflen);
-	ret = force_write(Dir, buffer, (mt_off_t) size * MDIR_SIZE, buflen);
-	free(buffer);
-	if(ret < buflen)
-		return -1;
-	return 0;
-}
-
-
-void low_level_dir_write(direntry_t *entry)
-{
-	force_write(entry->Dir, 
-		    (char *) (&entry->dir), 
-		    (mt_off_t) entry->entry * MDIR_SIZE, MDIR_SIZE);
-}
-
-
-/*
- * Make a directory entry.  Builds a directory entry based on the
- * name, attribute, starting cluster number, and size.  Returns a pointer
- * to a static directory structure.
- */
-
-struct directory *mk_entry(const char *filename, char attr,
-			   unsigned int fat, size_t size, time_t date,
-			   struct directory *ndir)
-{
-	struct tm *now;
-	time_t date2 = date;
-	unsigned char hour, min_hi, min_low, sec;
-	unsigned char year, month_hi, month_low, day;
-
-	now = localtime(&date2);
-	strncpy(ndir->name, filename, 8);
-	strncpy(ndir->ext, filename + 8, 3);
-	ndir->attr = attr;
-	ndir->ctime_ms = 0;
-	hour = now->tm_hour << 3;
-	min_hi = now->tm_min >> 3;
-	min_low = now->tm_min << 5;
-	sec = now->tm_sec / 2;
-	ndir->ctime[1] = ndir->time[1] = hour + min_hi;
-	ndir->ctime[0] = ndir->time[0] = min_low + sec;
-	year = (now->tm_year - 80) << 1;
-	month_hi = (now->tm_mon + 1) >> 3;
-	month_low = (now->tm_mon + 1) << 5;
-	day = now->tm_mday;
-	ndir -> adate[1] = ndir->cdate[1] = ndir->date[1] = year + month_hi;
-	ndir -> adate[0] = ndir->cdate[0] = ndir->date[0] = month_low + day;
-
-	set_word(ndir->start, fat & 0xffff);
-	set_word(ndir->startHi, fat >> 16);
-	set_dword(ndir->size, size);
-	return ndir;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/direntry.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/direntry.c	(revision 9)
+++ 	(revision )
@@ -1,119 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "stream.h"
-#include "file.h"
-#include "mtoolsDirent.h"
-
-void initializeDirentry(direntry_t *entry, Stream_t *Dir)
-{
-	entry->entry = -1;
-/*	entry->parent = getDirentry(Dir);*/
-	entry->Dir = Dir;
-	entry->beginSlot = 0;
-	entry->endSlot = 0;
-}
-
-int isNotFound(direntry_t *entry)
-{
-	return entry->entry == -2;
-}
-
-void rewindEntry(direntry_t *entry)
-{
-	entry->entry = -1;
-}
-
-
-direntry_t *getParent(direntry_t *entry)
-{
-	return getDirentry(entry->Dir);
-}
-
-
-static int getPathLen(direntry_t *entry)
-{
-	int length=0;
-
-	while(1) {
-		if(entry->entry == -3) /* rootDir */
-			return strlen(getDrive(entry->Dir)) + 1 + length + 1;
-		
-		length += 1 + strlen(entry->name);
-		entry = getDirentry(entry->Dir);
-	}
-}
-
-static char *sprintPwd(direntry_t *entry, char *ptr)
-{
-	if(entry->entry == -3) {
-		strcpy(ptr, getDrive(entry->Dir));
-		strcat(ptr, ":/");
-		ptr = strchr(ptr, 0);
-	} else {
-		ptr = sprintPwd(getDirentry(entry->Dir), ptr);
-		if(ptr[-1] != '/')
-			*ptr++ = '/';
-		strcpy(ptr, entry->name);
-		ptr += strlen(entry->name);
-	}
-	return ptr;		
-}
-
-
-#define NEED_ESCAPE "\"$\\"
-
-static void _fprintPwd(FILE *f, direntry_t *entry, int recurs, int escape)
-{
-	if(entry->entry == -3) {
-		fputs(getDrive(entry->Dir), f);
-		putc(':', f);
-		if(!recurs)
-			putc('/', f);
-	} else {
-		_fprintPwd(f, getDirentry(entry->Dir), 1, escape);
-		if (escape && strpbrk(entry->name, NEED_ESCAPE)) {
-			char *ptr;
-			for(ptr = entry->name; *ptr; ptr++) {
-				if (strchr(NEED_ESCAPE, *ptr))
-					putc('\\', f);
-				putc(*ptr, f);
-			}
-		} else {
-			fprintf(f, "/%s", entry->name);
-		}
-	}
-}
-
-void fprintPwd(FILE *f, direntry_t *entry, int escape)
-{
-	if (escape)
-		putc('"', f);
-	_fprintPwd(f, entry, 0, escape);
-	if(escape)
-		putc('"', f);
-}
-
-char *getPwd(direntry_t *entry)
-{
-	int size;
-	char *ret;
-
-	size = getPathLen(entry);
-	ret = malloc(size+1);
-	if(!ret)
-		return 0;
-	sprintPwd(entry, ret);
-	return ret;
-}
-
-int isSubdirOf(Stream_t *inside, Stream_t *outside)
-{
-	while(1) {
-		if(inside == outside) /* both are the same */
-			return 1;
-		if(getDirentry(inside)->entry == -3) /* root directory */
-			return 0;
-		/* look further up */
-		inside = getDirentry(inside)->Dir;
-	}			
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/expand.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/expand.c	(revision 9)
+++ 	(revision )
@@ -1,83 +1,0 @@
-/*
- * Do filename expansion with the shell.
- */
-
-#define EXPAND_BUF	2048
-
-#include "sysincludes.h"
-#include "mtools.h"
-
-
-int safePopenOut(char **command, char *output, int len)
-{
-	int pipefd[2];
-	pid_t pid;
-	int status;
-	int last;
-
-	if(pipe(pipefd)) {
-		return -2;
-	}
-	switch((pid=fork())){
-		case -1:
-			return -2;
-		case 0: /* the son */
-			close(pipefd[0]);
-			destroy_privs();
-			close(1);
-			close(2); /* avoid nasty error messages on stderr */
-			dup(pipefd[1]);
-			close(pipefd[1]);
-			execvp(command[0], command+1);
-			exit(1);
-		default:
-			close(pipefd[1]);
-			break;
-	}
-	last=read(pipefd[0], output, len);
-	kill(pid,9);
-	wait(&status);
-	if(last<0) {
-		return -1;
-	}
-	return last;
-}
-
-
-
-const char *expand(const char *input, char *ans)
-{
-	int last;
-	char buf[256];
-	char *command[] = { "/bin/sh", "sh", "-c", 0, 0 };
-
-	ans[EXPAND_BUF-1]='\0';
-
-	if (input == NULL)
-		return(NULL);
-	if (*input == '\0')
-		return("");
-					/* any thing to expand? */
-	if (!strpbrk(input, "$*(){}[]\\?`~")) {
-		strncpy(ans, input, EXPAND_BUF-1);
-		return(ans);
-	}
-					/* popen an echo */
-#ifdef HAVE_SNPRINTF
-	snprintf(buf, 255, "echo %s", input);
-#else
-	sprintf(buf, "echo %s", input);
-#endif
-
-	command[3]=buf;
-	last=safePopenOut(command, ans, EXPAND_BUF-1);
-	if(last<0) {
-		perror("Pipe read error");
-		exit(1);
-	}
-	if(last)
-		ans[last-1] = '\0';
-	else
-		strncpy(ans, input, EXPAND_BUF-1);
-	return ans;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/fat.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/fat.c	(revision 9)
+++ 	(revision )
@@ -1,929 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "stream.h"
-#include "mtools.h"
-#include "fsP.h"
-
-extern Stream_t *default_drive;
-
-#ifdef HAVE_LONG_LONG
-typedef long long fatBitMask;
-#else
-typedef long fatBitMask;
-#endif
-
-typedef struct FatMap_t {
-	unsigned char *data;
-	fatBitMask dirty;
-	fatBitMask valid;
-} FatMap_t;
-
-#define SECT_PER_ENTRY (sizeof(fatBitMask)*8)
-#define ONE ((fatBitMask) 1)
-
-static inline int readSector(Fs_t *This, char *buf, unsigned int off,
-					  size_t size)
-{
-	return READS(This->Next, buf, sectorsToBytes((Stream_t *)This, off), 
-				 size << This->sectorShift);
-}
-
-
-static inline int forceReadSector(Fs_t *This, char *buf, unsigned int off,
-								  size_t size)
-{
-	return force_read(This->Next, buf, sectorsToBytes((Stream_t *)This, off), 
-					  size << This->sectorShift);
-}
-
-
-static inline int writeSector(Fs_t *This, char *buf, unsigned int off,
-							  size_t size)
-{
-	return WRITES(This->Next, buf, sectorsToBytes((Stream_t*)This, off), 
-				  size << This->sectorShift);
-}
-
-static inline int forceWriteSector(Fs_t *This, char *buf, unsigned int off,
-					  size_t size)
-{
-	return force_write(This->Next, buf, sectorsToBytes((Stream_t*)This, off), 
-					   size << This->sectorShift);
-}
-
-
-static FatMap_t *GetFatMap(Fs_t *Stream)
-{
-	int nr_entries,i;
-	FatMap_t *map;
-
-	Stream->fat_error = 0;
-	nr_entries = (Stream->fat_len + SECT_PER_ENTRY - 1) / SECT_PER_ENTRY;
-	map = NewArray(nr_entries, FatMap_t);
-	if(!map)
-		return 0;
-
-	for(i=0; i< nr_entries; i++) {
-		map[i].data = 0;
-		map[i].valid = 0;
-		map[i].dirty = 0;
-	}
-
-	return map;
-}
-
-static inline int locate(Fs_t *Stream, int offset, int *slot, int *bit)
-{
-	if(offset >= Stream->fat_len)
-		return -1;
-	*slot = offset / SECT_PER_ENTRY;
-	*bit = offset % SECT_PER_ENTRY;
-	return 0;
-}
-
-static inline int fatReadSector(Fs_t *This, int sector, int slot, 
-				int bit, int dupe)
-{
-	int fat_start, ret;
-
-	dupe = (dupe + This->primaryFat) % This->num_fat;
-	fat_start = This->fat_start + This->fat_len * dupe;
-	
-	/* first, read as much as the buffer can give us */
-	ret = readSector(This,
-					 (char *)(This->FatMap[slot].data+(bit<<This->sectorShift)),
-					 fat_start+sector,
-					 (SECT_PER_ENTRY - bit%SECT_PER_ENTRY));
-	if(ret < 0)
-		return 0;
-
-	if(ret < This->sector_size) {
-		/* if we got less than one sector's worth, insist to get at
-		 * least one sector */
-		ret = forceReadSector(This,
-							  (char *) (This->FatMap[slot].data + 
-										(bit << This->sectorShift)),
-							  fat_start+sector, 1);
-		if(ret < This->sector_size)
-			return 0;
-		return 1;
-	}
-
-	return ret >> This->sectorShift;
-}
-
-
-static int fatWriteSector(Fs_t *This, int sector, int slot, int bit, int dupe)
-{
-	int fat_start;
-
-	dupe = (dupe + This->primaryFat) % This->num_fat;
-	if(dupe && !This->writeAllFats)
-		return This->sector_size;
-
-	fat_start = This->fat_start + This->fat_len * dupe;
-
-	return forceWriteSector(This,
-							(char *) 
-							(This->FatMap[slot].data + bit * This->sector_size),
-							fat_start+sector, 1);
-}
-
-static unsigned char *loadSector(Fs_t *This,
-				 unsigned int sector, fatAccessMode_t mode,
-				 int recurs)
-{
-	int slot, bit, i, ret;
-
-	if(locate(This,sector, &slot, &bit) < 0)
-		return 0;
-#if 0
-        if (((This->fat_len + SECT_PER_ENTRY - 1) / SECT_PER_ENTRY) <= slot) {
-		fprintf(stderr,"This should not happen\n");
-		fprintf(stderr, "fat_len = %d\n", This->fat_len);
-		fprintf(stderr, "SECT_PER_ENTRY=%d\n", (int)SECT_PER_ENTRY);
-		fprintf(stderr, "sector = %d slot = %d bit=%d\n", 
-			sector, slot, bit);
-		fprintf(stderr, "left = %d",(int)
-			((This->fat_len+SECT_PER_ENTRY-1) / SECT_PER_ENTRY));
-                return 0;
-	}
-#endif
-	if(!This->FatMap[slot].data) {
-		/* allocate the storage space */
-		This->FatMap[slot].data = 
-			malloc(This->sector_size * SECT_PER_ENTRY);
-		if(!This->FatMap[slot].data)
-			return 0;
-		memset(This->FatMap[slot].data, 0xee,
-		       This->sector_size * SECT_PER_ENTRY);
-	}
-
-	if(! (This->FatMap[slot].valid & (ONE << bit))) {
-		ret = -1;
-		for(i=0; i< This->num_fat; i++) {
-			/* read the sector */
-			ret = fatReadSector(This, sector, slot, bit, i);
-
-			if(ret == 0) {
-				fprintf(stderr,
-					"Error reading fat number %d\n", i);
-				continue;
-			}
-			break;
-		}
-
-		/* all copies bad.  Return error */
-		if(ret == 0)
-			return 0;
-
-		for(i=0; i < ret; i++)
-			This->FatMap[slot].valid |= ONE << (bit + i);
-
-		if(!recurs && ret == 1)
-			/* do some prefetching, if we happened to only
-			 * get one sector */
-			loadSector(This, sector+1, mode, 1);
-		if(!recurs && batchmode)
-			for(i=0; i < 1024; i++)
-				loadSector(This, sector+i, mode, 1);
-	}
-
-	if(mode == FAT_ACCESS_WRITE) {
-		This->FatMap[slot].dirty |= ONE << bit;
-		This->fat_dirty = 1;
-	}
-	return This->FatMap[slot].data + (bit << This->sectorShift);
-}
-
-
-static unsigned char *getAddress(Fs_t *Stream,
-				 unsigned int num, fatAccessMode_t mode)
-{
-	unsigned char *ret;
-	int sector;
-	int offset;
-
-	sector = num >> Stream->sectorShift;
-	ret = 0;
-	if(sector == Stream->lastFatSectorNr &&
-	   Stream->lastFatAccessMode >= mode)
-		ret = Stream->lastFatSectorData;
-	if(!ret) {		
-		ret = loadSector(Stream, sector, mode, 0);
-		if(!ret)
-			return 0;
-		Stream->lastFatSectorNr = sector;
-		Stream->lastFatSectorData = ret;
-		Stream->lastFatAccessMode = mode;
-	}
-	offset = num & Stream->sectorMask;
-	return ret+offset;
-}
-
-
-static int readByte(Fs_t *Stream, int start)
-{
-	unsigned char *address;
-	
-	address = getAddress(Stream, start, FAT_ACCESS_READ);
-	if(!address)
-		return -1;
-	return *address;
-}
-
-
-/*
- * Fat 12 encoding:
- *	|    byte n     |   byte n+1    |   byte n+2    |
- *	|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
- *	| | | | | | | | | | | | | | | | | | | | | | | | |
- *	| n+0.0 | n+0.5 | n+1.0 | n+1.5 | n+2.0 | n+2.5 |
- *	    \_____  \____   \______/________/_____   /
- *	      ____\______\________/   _____/  ____\_/
- *	     /     \      \          /       /     \
- *	| n+1.5 | n+0.0 | n+0.5 | n+2.0 | n+2.5 | n+1.0 |
- *	|      FAT entry k      |    FAT entry k+1      |
- */
- 
- /*
- * Get and decode a FAT (file allocation table) entry.  Returns the cluster
- * number on success or 1 on failure.
- */
-
-static unsigned int fat12_decode(Fs_t *Stream, unsigned int num)
-{
-	unsigned int start = num * 3 / 2;
-	int byte0 = readByte(Stream, start);
-	int byte1 = readByte(Stream, start+1);
-       
-	if (num < 2 || byte0 < 0 || byte1 < 0 || num > Stream->num_clus+1) {
-		fprintf(stderr,"[1] Bad address %d\n", num);
-		return 1;
-	}
-
-	if (num & 1)
-		return (byte1 << 4) | ((byte0 & 0xf0)>>4);
-	else
-		return ((byte1 & 0xf) << 8) | byte0;
-}
-
-
-/*
- * Puts a code into the FAT table.  Is the opposite of fat_decode().  No
- * sanity checking is done on the code.  Returns a 1 on error.
- */
-static void fat12_encode(Fs_t *Stream, unsigned int num, unsigned int code)
-{
-	int start = num * 3 / 2;
-	unsigned char *address0 = getAddress(Stream, start, FAT_ACCESS_WRITE);
-	unsigned char *address1 = getAddress(Stream, start+1, FAT_ACCESS_WRITE);
-
-	if (num & 1) {
-		/* (odd) not on byte boundary */
-		*address0 = (*address0 & 0x0f) | ((code << 4) & 0xf0);
-		*address1 = (code >> 4) & 0xff;
-	} else {
-		/* (even) on byte boundary */
-		*address0 = code & 0xff;
-		*address1 = (*address1 & 0xf0) | ((code >> 8) & 0x0f);
-	}
-}
-
-
-/*
- * Fat 16 encoding:
- *	|    byte n     |   byte n+1    |
- *	|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
- *	| | | | | | | | | | | | | | | | |
- *	|         FAT entry k           |
- */
-
-static unsigned int fat16_decode(Fs_t *Stream, unsigned int num)
-{
-	unsigned char *address = getAddress(Stream, num << 1, FAT_ACCESS_READ);
-	return _WORD(address);
-}
-
-static void fat16_encode(Fs_t *Stream, unsigned int num, unsigned int code)
-{       
-	unsigned char *address = getAddress(Stream, num << 1, FAT_ACCESS_WRITE);
-	set_word(address, code);
-}
-
-
-static unsigned int fast_fat16_decode(Fs_t *Stream, unsigned int num)
-{
-	unsigned short *address = 
-		(unsigned short *) getAddress(Stream, num << 1, 
-					      FAT_ACCESS_READ);
-	return *address;
-}
-
-static void fast_fat16_encode(Fs_t *Stream, unsigned int num, unsigned int code)
-{       
-	unsigned short *address = 
-		(unsigned short *) getAddress(Stream, num << 1, 
-					      FAT_ACCESS_WRITE);
-	*address = code;
-}
-
-
-
-
-/*
- * Fat 32 encoding
- */
-static unsigned int fat32_decode(Fs_t *Stream, unsigned int num)
-{
-	unsigned char *address = getAddress(Stream, num << 2, FAT_ACCESS_READ);
-	return _DWORD(address);
-}
-
-static void fat32_encode(Fs_t *Stream, unsigned int num, unsigned int code)
-{       
-	unsigned char *address = getAddress(Stream, num << 2, FAT_ACCESS_WRITE);
-	set_dword(address, code);
-}
-
-
-static unsigned int fast_fat32_decode(Fs_t *Stream, unsigned int num)
-{
-	unsigned int *address = 
-		(unsigned int *) getAddress(Stream, num << 2, 
-					    FAT_ACCESS_READ);
-	return *address;
-}
-
-static void fast_fat32_encode(Fs_t *Stream, unsigned int num, unsigned int code)
-{       
-	unsigned int *address = 
-		(unsigned int *) getAddress(Stream, num << 2, 
-					    FAT_ACCESS_WRITE);
-	*address = code;
-}
-
-
-/*
- * Write the FAT table to the disk.  Up to now the FAT manipulation has
- * been done in memory.  All errors are fatal.  (Might not be too smart
- * to wait till the end of the program to write the table.  Oh well...)
- */
-
-void fat_write(Fs_t *This)
-{
-	int i, j, dups, ret, bit, slot;
-	int fat_start;
-
-	/*fprintf(stderr, "Fat write\n");*/
-
-	if (!This->fat_dirty)
-		return;
-
-	dups = This->num_fat;
-	if (This->fat_error)
-		dups = 1;
-
-
-	for(i=0; i<dups; i++){
-		j = 0;
-		fat_start = This->fat_start + i*This->fat_len;
-		for(slot=0;j<This->fat_len;slot++) {
-			if(!This->FatMap[slot].dirty) {
-				j += SECT_PER_ENTRY;
-				continue;
-			}
-			for(bit=0; 
-			    bit < SECT_PER_ENTRY && j<This->fat_len;
-			    bit++,j++) {
-				if(!(This->FatMap[slot].dirty & (ONE << bit)))
-					continue;
-				ret = fatWriteSector(This,j,slot, bit, i);
-				if (ret < This->sector_size){
-					if (ret < 0 ){
-						perror("error in fat_write");
-						exit(1);
-					} else {
-						fprintf(stderr,
-							"end of file in fat_write\n");
-						exit(1);
-					}
-				}
-				/* if last dupe, zero it out */
-				if(i==dups-1)
-					This->FatMap[slot].dirty &= ~(1<<bit);
-			}
-		}	 
-	}
-	/* write the info sector, if any */
-	if(This->infoSectorLoc && This->infoSectorLoc != MAX32) {
-		/* initialize info sector */
-		InfoSector_t *infoSector;
-		infoSector = (InfoSector_t *) safe_malloc(This->sector_size);
-		set_dword(infoSector->signature1, INFOSECT_SIGNATURE1);
-		memset(infoSector->filler1, sizeof(infoSector->filler1),0);
-		memset(infoSector->filler2, sizeof(infoSector->filler2),0);
-		set_dword(infoSector->signature2, INFOSECT_SIGNATURE2);
-		set_dword(infoSector->pos, This->last);
-		set_dword(infoSector->count, This->freeSpace);
-		set_dword(infoSector->signature3, 0xaa55);
-		if(forceWriteSector(This, (char *)infoSector, This->infoSectorLoc, 1) !=
-		   This->sector_size)
-			fprintf(stderr,"Trouble writing the info sector\n");
-		free(infoSector);
-	}
-	This->fat_dirty = 0;
-	This->lastFatAccessMode = FAT_ACCESS_READ;
-}
-
-
-
-/*
- * Zero-Fat
- * Used by mformat.
- */
-int zero_fat(Fs_t *Stream, int media_descriptor)
-{
-	int i, j;
-	int fat_start;
-	unsigned char *buf;
-
-	buf = malloc(Stream->sector_size);
-	if(!buf) {
-		perror("alloc fat sector buffer");
-		return -1;
-	}
-	for(i=0; i< Stream->num_fat; i++) {
-		fat_start = Stream->fat_start + i*Stream->fat_len;
-		for(j = 0; j < Stream->fat_len; j++) {
-			if(j <= 1)
-				memset(buf, 0, Stream->sector_size);
-			if(!j) {
-				buf[0] = media_descriptor;
-				buf[2] = buf[1] = 0xff;
-				if(Stream->fat_bits > 12)
-					buf[3] = 0xff;
-				if(Stream->fat_bits > 16) {
-					buf[4] = 0xff;
-					buf[5] = 0xff;
-					buf[6] = 0xff;
-					buf[7] = 0x0f;
-				}
-			}
-
-			if(forceWriteSector(Stream, (char *)buf,
-								fat_start + j, 1) !=
-			   Stream->sector_size) {
-				fprintf(stderr,
-						"Trouble initializing a FAT sector\n");
-				free(buf);
-				return -1;
-			}
-		}
-	}
-	
-	free(buf);
-	Stream->FatMap = GetFatMap(Stream);
-	if (Stream->FatMap == NULL) {
-		perror("alloc fat map");
-		return -1;
-	}
-	return 0;
-}
-
-
-void set_fat12(Fs_t *This)
-{
-	This->fat_bits = 12;
-	This->end_fat = 0xfff;
-	This->last_fat = 0xff6;
-	This->fat_decode = fat12_decode;
-	This->fat_encode = fat12_encode;
-}
-
-static char word_endian_test[] = { 0x34, 0x12 };
-
-void set_fat16(Fs_t *This)
-{
-	This->fat_bits = 16;
-	This->end_fat = 0xffff;
-	This->last_fat = 0xfff6;
-
-	if(sizeof(unsigned short) == 2 &&  
-	   * (unsigned short *) word_endian_test == 0x1234) {
-		This->fat_decode = fast_fat16_decode;
-		This->fat_encode = fast_fat16_encode;
-	} else {
-		This->fat_decode = fat16_decode;
-		This->fat_encode = fat16_encode;
-	}
-}
-
-static char dword_endian_test[] = { 0x78, 0x56, 0x34, 0x12 };
-
-void set_fat32(Fs_t *This)
-{
-	This->fat_bits = 32;
-	This->end_fat = 0xfffffff;
-	This->last_fat = 0xffffff6;
-	
-	if(sizeof(unsigned int) == 4 &&  
-	   * (unsigned int *) dword_endian_test == 0x12345678) {
-		This->fat_decode = fast_fat32_decode;
-		This->fat_encode = fast_fat32_encode;
-	} else {
-		This->fat_decode = fat32_decode;
-		This->fat_encode = fat32_encode;
-	}
-}
-
-
-static int check_fat(Fs_t *This)
-{
-	/* 
-	 * This is only a sanity check.  For disks with really big FATs,
-	 * there is no point in checking the whole FAT.
-	 */
-
-	int i, f, tocheck;
-	if(mtools_skip_check)
-		return 0;
-
-	/* too few sectors in the FAT */
-	if(This->fat_len < NEEDED_FAT_SIZE(This))
-		return -1;
-	/* we do not warn about too much sectors in FAT, which may
-	 * happen when a partition has been shrunk using FIPS, or on
-	 * other occurrences */
-	
-	tocheck = This->num_clus;
-	if (tocheck < 0 || tocheck + 1 >= This->last_fat) {
-		fprintf(stderr, "Too many clusters in FAT\n");
-		return -1;
-	}
-
-	if(tocheck > 4096)
-		tocheck = 4096;
-
-	for ( i= 3 ; i < tocheck; i++){
-		f = This->fat_decode(This,i);
-		if (f == 1 || (f < This->last_fat && f > This->num_clus)){
-			fprintf(stderr,
-				"Cluster # at %d too big(%#x)\n", i,f);
-			fprintf(stderr,"Probably non MS-DOS disk\n");
-			return -1;
-		}
-	}
-	return 0;
-}
-
-
-/*
- * Read the first sector of FAT table into memory.  Crude error detection on
- * wrong FAT encoding scheme.
- */
-static int check_media_type(Fs_t *This, struct bootsector *boot, 
-			    unsigned int tot_sectors)
-{
-	unsigned char *address;
-
-	This->num_clus = (tot_sectors - This->clus_start) / This->cluster_size;
-
-	This->FatMap = GetFatMap(This);
-	if (This->FatMap == NULL) {
-		perror("alloc fat map");
-		return -1;
-	}
-
-	address = getAddress(This, 0, FAT_ACCESS_READ);
-	if(!address) {
-		fprintf(stderr,
-			"Could not read first FAT sector\n");
-		return -1;
-	}
-
-	if(mtools_skip_check)
-		return 0;
-
-	if(!address[0] && !address[1] && !address[2])
-		/* Some Atari disks have zeroes where Dos has media descriptor
-		 * and 0xff.  Do not consider this as an error */
-		return 0;
-	
-	if((address[0] != boot->descr && boot->descr >= 0xf0 &&
-	    ((address[0] != 0xf9 && address[0] != 0xf7) 
-	     || boot->descr != 0xf0)) || address[0] < 0xf0) {
-		fprintf(stderr,
-			"Bad media types %02x/%02x, probably non-MSDOS disk\n", 
-				address[0],
-				boot->descr);
-		return -1;
-	}
-
-	if(address[1] != 0xff || address[2] != 0xff){
-		fprintf(stderr,"Initial byte of fat is not 0xff\n");
-		return -1;
-	}
-
-	return 0;
-}
-
-static int fat_32_read(Fs_t *This, struct bootsector *boot, 
-		       unsigned int tot_sectors)
-{
-	int size;
-
-	This->fat_len = DWORD(ext.fat32.bigFat);
-	This->writeAllFats = !(boot->ext.fat32.extFlags[0] & 0x80);
-	This->primaryFat = boot->ext.fat32.extFlags[0] & 0xf;
-	This->rootCluster = DWORD(ext.fat32.rootCluster);
-	This->clus_start = This->fat_start + This->num_fat * This->fat_len;
-
-	/* read the info sector */
-	size = This->sector_size;
-	This->infoSectorLoc = WORD(ext.fat32.infoSector);
-	if(This->sector_size >= 512 &&
-	   This->infoSectorLoc && This->infoSectorLoc != MAX32) {
-		InfoSector_t *infoSector;
-		infoSector = (InfoSector_t *) safe_malloc(size);
-		if(forceReadSector(This, (char *)infoSector,
-						   This->infoSectorLoc, 1) == This->sector_size &&
-		   _DWORD(infoSector->signature1) == INFOSECT_SIGNATURE1 &&
-		   _DWORD(infoSector->signature2) == INFOSECT_SIGNATURE2) {
-			This->freeSpace = _DWORD(infoSector->count);
-			This->last = _DWORD(infoSector->pos);
-		}
-		free(infoSector);
-	}
-	
-	set_fat32(This);
-	return(check_media_type(This,boot, tot_sectors) ||
-	       check_fat(This));
-}
-
-
-static int old_fat_read(Fs_t *This, struct bootsector *boot, 
-						int config_fat_bits,
-						size_t tot_sectors, int nodups)
-{
-	This->writeAllFats = 1;
-	This->primaryFat = 0;
-	This->dir_start = This->fat_start + This->num_fat * This->fat_len;
-	This->clus_start = This->dir_start + This->dir_len;
-	This->infoSectorLoc = MAX32;
-
-	if(nodups)
-		This->num_fat = 1;
-
-	if(check_media_type(This,boot, tot_sectors))
-		return -1;
-
-	if(This->num_clus > FAT12) {
-		set_fat16(This);
-		/* third FAT byte must be 0xff */
-		if(!mtools_skip_check && readByte(This, 3) != 0xff)
-			return -1;
-	} else
-		set_fat12(This);
-
-	return check_fat(This);
-}
-
-/*
- * Read the first sector of the  FAT table into memory and initialize 
- * structures.
- */
-int fat_read(Fs_t *This, struct bootsector *boot, int fat_bits,
-	   size_t tot_sectors, int nodups)
-{
-	This->fat_error = 0;
-	This->fat_dirty = 0;
-	This->last = MAX32;
-	This->freeSpace = MAX32;
-	This->lastFatSectorNr = 0;
-	This->lastFatSectorData = 0;
-
-	if(This->fat_len)
-		return old_fat_read(This, boot, fat_bits, tot_sectors, nodups);
-	else
-		return fat_32_read(This, boot, tot_sectors);
-}
-
-
-unsigned int fatDecode(Fs_t *This, unsigned int pos)
-{
-	int ret;
-
-	ret = This->fat_decode(This, pos);
-	if(ret && (ret < 2 || ret > This->num_clus+1) && ret < This->last_fat) {
-		fprintf(stderr, "Bad FAT entry %d at %d\n", ret, pos);
-		This->fat_error++;
-	}
-	return ret;
-}
-
-/* append a new cluster */
-void fatAppend(Fs_t *This, unsigned int pos, unsigned int newpos)
-{
-	This->fat_encode(This, pos, newpos);
-	This->fat_encode(This, newpos, This->end_fat);
-	if(This->freeSpace != MAX32)
-		This->freeSpace--;
-}
-
-/* de-allocates the given cluster */
-void fatDeallocate(Fs_t *This, unsigned int pos)
-{
-	This->fat_encode(This, pos, 0);
-	if(This->freeSpace != MAX32)
-		This->freeSpace++;
-}
-
-/* allocate a new cluster */
-void fatAllocate(Fs_t *This, unsigned int pos, unsigned int value)
-{
-	This->fat_encode(This, pos, value);
-	if(This->freeSpace != MAX32)
-		This->freeSpace--;
-}
-
-void fatEncode(Fs_t *This, unsigned int pos, unsigned int value)
-{
-	unsigned int oldvalue = This->fat_decode(This, pos);
-	This->fat_encode(This, pos, value);
-	if(This->freeSpace != MAX32) {
-		if(oldvalue)
-			This->freeSpace++;
-		if(value)
-			This->freeSpace--;
-	}
-}
-
-unsigned int get_next_free_cluster(Fs_t *This, unsigned int last)
-{
-	int i;
-
-	if(This->last != MAX32)
-		last = This->last;
-
-	if (last < 2 ||
-	    last >= This->num_clus+1)
-		last = 1;
-
-	for (i=last+1; i< This->num_clus+2; i++) {
-		if (!fatDecode(This, i)) {
-			This->last = i;
-			return i;
-		}
-	}
-
-	for(i=2; i < last+1; i++) {
-		if (!fatDecode(This, i)) {
-			This->last = i;
-			return i;
-		}
-	}
-
-
-	fprintf(stderr,"No free cluster %d %d\n", This->preallocatedClusters,
-		This->last);
-	return 1;
-}
-
-int fat_error(Stream_t *Dir)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(Fs_t);
-
-	if(This->fat_error)
-		fprintf(stderr,"Fat error detected\n");
-
-	return This->fat_error;
-}
-
-int fat32RootCluster(Stream_t *Dir)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(Fs_t);
-	
-	if(This->fat_bits == 32)
-		return This->rootCluster;
-	else
-		return 0;
-}
-
-
-/*
- * Get the amount of free space on the diskette
- */
-
-mt_size_t getfree(Stream_t *Dir)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(Fs_t);
-
-	if(This->freeSpace == MAX32 || This->freeSpace == 0) {
-		register unsigned int i;
-		size_t total;
-
-		total = 0L;
-		for (i = 2; i < This->num_clus + 2; i++)
-			if (!fatDecode(This,i))
-				total++;
-		This->freeSpace = total;
-	}
-	return sectorsToBytes((Stream_t*)This, 
-						  This->freeSpace * This->cluster_size);
-}
-
-
-/*
- * Ensure that there is a minimum of total sectors free
- */
-int getfreeMinClusters(Stream_t *Dir, size_t size)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(Fs_t);
-	register unsigned int i, last;
-	size_t total;
-
-	if(batchmode && This->freeSpace == MAX32)
-		getfree(Stream);
-
-	if(This->freeSpace != MAX32) {
-		if(This->freeSpace >= size)
-			return 1;
-		else {
-			fprintf(stderr, "Disk full\n");
-			got_signal = 1;
-			return 0;
-		}
-	}
-
-	total = 0L;
-
-	/* we start at the same place where we'll start later to actually
-	 * allocate the sectors.  That way, the same sectors of the FAT, which
-	 * are already loaded during getfreeMin will be able to be reused 
-	 * during get_next_free_cluster */
-	last = This->last;
-	
-	if ( last < 2 || last >= This->num_clus + 2)
-		last = 1;
-	for (i=last+1; i< This->num_clus+2; i++){
-		if (!fatDecode(This, i))
-			total++;
-		if(total >= size)
-			return 1;				
-	}
-	for(i=2; i < last+1; i++){
-		if (!fatDecode(This, i))
-			total++;
-		if(total >= size)
-			return 1;
-	}
-	fprintf(stderr, "Disk full\n");
-	got_signal = 1;
-	return 0;
-}
-
-
-int getfreeMinBytes(Stream_t *Dir, mt_size_t size)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(Fs_t);
-	size_t size2;
-
-	size2 = size  / (This->sector_size * This->cluster_size);
-	if(size % (This->sector_size * This->cluster_size))
-		size2++;
-	return getfreeMinClusters(Dir, size2);
-}
-
-
-unsigned int getStart(Stream_t *Dir, struct directory *dir)
-{
-	Stream_t *Stream = GetFs(Dir);
-	unsigned int first;
-
-	first = START(dir);
-	if(fat32RootCluster(Stream))
-		first |= STARTHI(dir) << 16;
-	return first;
-}
-
-int fs_free(Stream_t *Stream)
-{
-	DeclareThis(Fs_t);
-
-	if(This->FatMap) {
-		int i, nr_entries;
-		nr_entries = (This->fat_len + SECT_PER_ENTRY - 1) / 
-			SECT_PER_ENTRY;
-		for(i=0; i< nr_entries; i++)
-			if(This->FatMap[i].data)
-				free(This->FatMap[i].data);		
-		free(This->FatMap);
-	}
-	return 0;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/fat_free.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/fat_free.c	(revision 9)
+++ 	(revision )
@@ -1,55 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "fsP.h"
-#include "mtoolsDirent.h"
-
-/*
- * Remove a string of FAT entries (delete the file).  The argument is
- * the beginning of the string.  Does not consider the file length, so
- * if FAT is corrupted, watch out!
- */
-
-int fat_free(Stream_t *Dir, unsigned int fat)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(Fs_t);
-	unsigned int next_no_step;
-					/* a zero length file? */
-	if (fat == 0)
-		return(0);
-
-	/* CONSTCOND */
-	while (!This->fat_error) {
-		/* get next cluster number */
-		next_no_step = fatDecode(This,fat);
-		/* mark current cluster as empty */
-		fatDeallocate(This,fat);
-		if (next_no_step >= This->last_fat)
-			break;
-		fat = next_no_step;
-	}
-	return(0);
-}
-
-int fatFreeWithDir(Stream_t *Dir, struct directory *dir)
-{
-	unsigned int first;
-
-	if((!strncmp(dir->name,".      ",8) ||
-	    !strncmp(dir->name,"..     ",8)) &&
-	   !strncmp(dir->ext,"   ",3)) {
-		fprintf(stderr,"Trying to remove . or .. entry\n");
-		return -1;
-	}
-
-	first = START(dir);
-  	if(fat32RootCluster(Dir))
-		first |= STARTHI(dir) << 16;
-	return fat_free(Dir, first);
-}
-
-int fatFreeWithDirentry(direntry_t *entry)
-{
-	return fatFreeWithDir(entry->Dir, &entry->dir);
-}
-    
Index: trunk/minix/commands/i386/mtools-3.9.7/file.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/file.c	(revision 9)
+++ 	(revision )
@@ -1,676 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "stream.h"
-#include "mtools.h"
-#include "fsP.h"
-#include "file.h"
-#include "htable.h"
-#include "dirCache.h"
-
-typedef struct File_t {
-	Class_t *Class;
-	int refs;
-	struct Fs_t *Fs;	/* Filesystem that this fat file belongs to */
-	Stream_t *Buffer;
-
-	int (*map)(struct File_t *this, off_t where, size_t *len, int mode,
-			   mt_off_t *res);
-	size_t FileSize;
-
-	size_t preallocatedSize;
-	int preallocatedClusters;
-
-	/* Absolute position of first cluster of file */
-	unsigned int FirstAbsCluNr;
-
-	/* Absolute position of previous cluster */
-	unsigned int PreviousAbsCluNr;
-
-	/* Relative position of previous cluster */
-	unsigned int PreviousRelCluNr;
-	direntry_t direntry;
-	int hint;
-	struct dirCache_t *dcp;
-
-	unsigned int loopDetectRel;
-	unsigned int loopDetectAbs;
-} File_t;
-
-static Class_t FileClass;
-T_HashTable *filehash;
-
-static File_t *getUnbufferedFile(Stream_t *Stream)
-{
-	while(Stream->Class != &FileClass)
-		Stream = Stream->Next;
-	return (File_t *) Stream;
-}
-
-Fs_t *getFs(Stream_t *Stream)
-{
-	return getUnbufferedFile(Stream)->Fs;
-}
-
-struct dirCache_t **getDirCacheP(Stream_t *Stream)
-{
-	return &getUnbufferedFile(Stream)->dcp;
-}
-
-direntry_t *getDirentry(Stream_t *Stream)
-{
-	return &getUnbufferedFile(Stream)->direntry;
-}
-
-
-static int recalcPreallocSize(File_t *This)
-{
-	size_t currentClusters, neededClusters;
-	int clus_size;
-	int neededPrealloc;
-	Fs_t *Fs = This->Fs;
-	int r;
-
-	if(This->FileSize & 0xc0000000) {
-		fprintf(stderr, "Bad filesize\n");
-	}
-	if(This->preallocatedSize & 0xc0000000) {
-		fprintf(stderr, "Bad preallocated size %x\n", 
-				(int) This->preallocatedSize);
-	}
-
-	clus_size = Fs->cluster_size * Fs->sector_size;
-
-	currentClusters = (This->FileSize + clus_size - 1) / clus_size;
-	neededClusters = (This->preallocatedSize + clus_size - 1) / clus_size;
-	neededPrealloc = neededClusters - currentClusters;
-	if(neededPrealloc < 0)
-		neededPrealloc = 0;
-	r = fsPreallocateClusters(Fs, neededPrealloc - This->preallocatedClusters);
-	if(r)
-		return r;
-	This->preallocatedClusters = neededPrealloc;
-	return 0;
-}
-
-static int _loopDetect(unsigned int *oldrel, unsigned int rel, 
-					   unsigned int *oldabs, unsigned int abs)
-{
-	if(*oldrel && rel > *oldrel && abs == *oldabs) {
-		fprintf(stderr, "loop detected! oldrel=%d newrel=%d abs=%d\n",
-				*oldrel, rel, abs);
-		return -1;
-	}
-
-	if(rel >= 2 * *oldrel + 1) {
-		*oldrel = rel;
-		*oldabs = abs;
-	}
-	return 0;
-}
-
-
-static int loopDetect(File_t *This, unsigned int rel, unsigned int abs)
-{
-	return _loopDetect(&This->loopDetectRel, rel, &This->loopDetectAbs, abs);
-}
-
-static unsigned int _countBlocks(Fs_t *This, unsigned int block)
-{
-	unsigned int blocks;
-	unsigned int rel, oldabs, oldrel;
-
-	blocks = 0;
-	
-	oldabs = oldrel = rel = 0;
-
-	while (block <= This->last_fat && block != 1 && block) {
-		blocks++;
-		block = fatDecode(This, block);
-		rel++;
-		if(_loopDetect(&oldrel, rel, &oldabs, block) < 0)
-			block = -1;
-	}
-	return blocks;
-}
-
-unsigned int countBlocks(Stream_t *Dir, unsigned int block)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(Fs_t);
-
-	return _countBlocks(This, block);
-}
-
-/* returns number of bytes in a directory.  Represents a file size, and
- * can hence be not bigger than 2^32
- */
-static size_t countBytes(Stream_t *Dir, unsigned int block)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(Fs_t);
-
-	return _countBlocks(This, block) * 
-		This->sector_size * This->cluster_size;
-}
-
-void printFat(Stream_t *Stream)
-{
-	File_t *This = getUnbufferedFile(Stream);
-	unsigned long n;
-	int rel;
-	unsigned long begin, end;
-	int first;
-
-	n = This->FirstAbsCluNr;
-	if(!n) {
-		printf("Root directory or empty file\n");
-		return;
-	}
-
-	rel = 0;
-	first = 1;
-	begin = end = 0;
-	do {
-		if (first || n != end+1) {
-			if (!first) {
-				if (begin != end)
-					printf("-%lu", end);
-				printf("> ");
-			}
-			begin = end = n;
-			printf("<%lu", begin);
-		} else {
-			end++;
-		}
-		first = 0;
-		n = fatDecode(This->Fs, n);
-		rel++;
-		if(loopDetect(This, rel, n) < 0)
-			n = 1;
-	} while (n <= This->Fs->last_fat && n != 1);
-	if(!first) {
-		if (begin != end)
-			printf("-%lu", end);
-		printf(">");
-	}
-}
-
-static int normal_map(File_t *This, off_t where, size_t *len, int mode,
-						   mt_off_t *res)
-{
-	int offset;
-	off_t end;
-	int NrClu; /* number of clusters to read */
-	unsigned int RelCluNr;
-	unsigned int CurCluNr;
-	unsigned int NewCluNr;
-	unsigned int AbsCluNr;
-	int clus_size;
-	Fs_t *Fs = This->Fs;
-
-	*res = 0;
-	clus_size = Fs->cluster_size * Fs->sector_size;
-	offset = where % clus_size;
-
-	if (mode == MT_READ)
-		maximize(*len, This->FileSize - where);
-	if (*len == 0 )
-		return 0;
-
-	if (This->FirstAbsCluNr < 2){
-		if( mode == MT_READ || *len == 0){
-			*len = 0;
-			return 0;
-		}
-		NewCluNr = get_next_free_cluster(This->Fs, 1);
-		if (NewCluNr == 1 ){
-			errno = ENOSPC;
-			return -2;
-		}
-		hash_remove(filehash, (void *) This, This->hint);
-		This->FirstAbsCluNr = NewCluNr;
-		hash_add(filehash, (void *) This, &This->hint);
-		fatAllocate(This->Fs, NewCluNr, Fs->end_fat);
-	}
-
-	RelCluNr = where / clus_size;
-	
-	if (RelCluNr >= This->PreviousRelCluNr){
-		CurCluNr = This->PreviousRelCluNr;
-		AbsCluNr = This->PreviousAbsCluNr;
-	} else {
-		CurCluNr = 0;
-		AbsCluNr = This->FirstAbsCluNr;
-	}
-
-
-	NrClu = (offset + *len - 1) / clus_size;
-	while (CurCluNr <= RelCluNr + NrClu){
-		if (CurCluNr == RelCluNr){
-			/* we have reached the beginning of our zone. Save
-			 * coordinates */
-			This->PreviousRelCluNr = RelCluNr;
-			This->PreviousAbsCluNr = AbsCluNr;
-		}
-		NewCluNr = fatDecode(This->Fs, AbsCluNr);
-		if (NewCluNr == 1 || NewCluNr == 0){
-			fprintf(stderr,"Fat problem while decoding %d %x\n", 
-				AbsCluNr, NewCluNr);
-			exit(1);
-		}
-		if(CurCluNr == RelCluNr + NrClu)			
-			break;
-		if (NewCluNr > Fs->last_fat && mode == MT_WRITE){
-			/* if at end, and writing, extend it */
-			NewCluNr = get_next_free_cluster(This->Fs, AbsCluNr);
-			if (NewCluNr == 1 ){ /* no more space */
-				errno = ENOSPC;
-				return -2;
-			}
-			fatAppend(This->Fs, AbsCluNr, NewCluNr);
-		}
-
-		if (CurCluNr < RelCluNr && NewCluNr > Fs->last_fat){
-			*len = 0;
-			return 0;
-		}
-
-		if (CurCluNr >= RelCluNr && NewCluNr != AbsCluNr + 1)
-			break;
-		CurCluNr++;
-		AbsCluNr = NewCluNr;
-		if(loopDetect(This, CurCluNr, AbsCluNr)) {
-			errno = EIO;
-			return -2;
-		}
-	}
-
-	maximize(*len, (1 + CurCluNr - RelCluNr) * clus_size - offset);
-	
-	end = where + *len;
-	if(batchmode && mode == MT_WRITE && end >= This->FileSize) {
-		*len += ROUND_UP(end, clus_size) - end;
-	}
-
-	if((*len + offset) / clus_size + This->PreviousAbsCluNr-2 >
-		Fs->num_clus) {
-		fprintf(stderr, "cluster too big\n");
-		exit(1);
-	}
-
-	*res = sectorsToBytes((Stream_t*)Fs, 
-						  (This->PreviousAbsCluNr-2) * Fs->cluster_size +
-						  Fs->clus_start) + offset;
-	return 1;
-}
-
-
-static int root_map(File_t *This, off_t where, size_t *len, int mode,
-					mt_off_t *res)
-{
-	Fs_t *Fs = This->Fs;
-
-	if(Fs->dir_len * Fs->sector_size < where) {
-		*len = 0;
-		errno = ENOSPC;
-		return -2;
-	}
-
-	maximize(*len, Fs->dir_len * Fs->sector_size - where);
-        if (*len == 0)
-            return 0;
-	
-	*res = sectorsToBytes((Stream_t*)Fs, Fs->dir_start) + where;
-	return 1;
-}
-	
-
-static int read_file(Stream_t *Stream, char *buf, mt_off_t iwhere, 
-					 size_t len)
-{
-	DeclareThis(File_t);
-	mt_off_t pos;
-	int err;
-	off_t where = truncBytes32(iwhere);
-
-	Stream_t *Disk = This->Fs->Next;
-	
-	err = This->map(This, where, &len, MT_READ, &pos);
-	if(err <= 0)
-		return err;
-	return READS(Disk, buf, pos, len);
-}
-
-static int write_file(Stream_t *Stream, char *buf, mt_off_t iwhere, size_t len)
-{
-	DeclareThis(File_t);
-	mt_off_t pos;
-	int ret;
-	size_t requestedLen;
-	Stream_t *Disk = This->Fs->Next;
-	off_t where = truncBytes32(iwhere);
-	int err;
-
-	requestedLen = len;
-	err = This->map(This, where, &len, MT_WRITE, &pos);
-	if( err <= 0)
-		return err;
-	if(batchmode)
-		ret = force_write(Disk, buf, pos, len);
-	else
-		ret = WRITES(Disk, buf, pos, len);
-	if(ret > requestedLen)
-		ret = requestedLen;
-	if (ret > 0 && where + ret > This->FileSize )
-		This->FileSize = where + ret;
-	recalcPreallocSize(This);
-	return ret;
-}
-
-
-/*
- * Convert an MSDOS time & date stamp to the Unix time() format
- */
-
-static int month[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
-					  0, 0, 0 };
-static inline time_t conv_stamp(struct directory *dir)
-{
-	struct tm *tmbuf;
-	long tzone, dst;
-	time_t accum, tmp;
-
-	accum = DOS_YEAR(dir) - 1970; /* years past */
-
-	/* days passed */
-	accum = accum * 365L + month[DOS_MONTH(dir)-1] + DOS_DAY(dir);
-
-	/* leap years */
-	accum += (DOS_YEAR(dir) - 1972) / 4L;
-
-	/* back off 1 day if before 29 Feb */
-	if (!(DOS_YEAR(dir) % 4) && DOS_MONTH(dir) < 3)
-	        accum--;
-	accum = accum * 24L + DOS_HOUR(dir); /* hours passed */
-	accum = accum * 60L + DOS_MINUTE(dir); /* minutes passed */
-	accum = accum * 60L + DOS_SEC(dir); /* seconds passed */
-
-#ifndef OS_Minix
-	/* correct for Time Zone */
-#ifdef HAVE_GETTIMEOFDAY
-	{
-		struct timeval tv;
-		struct timezone tz;
-		
-		gettimeofday(&tv, &tz);
-		tzone = tz.tz_minuteswest * 60L;
-	}
-#else
-#ifdef HAVE_TZSET
-	{
-#ifndef OS_ultrix
-		/* Ultrix defines this to be a different type */
-		extern long timezone;
-#endif
-		tzset();
-		tzone = (long) timezone;
-	}
-#else
-	tzone = 0;
-#endif /* HAVE_TZSET */
-#endif /* HAVE_GETTIMEOFDAY */
-
-	accum += tzone;
-#endif /* OS_Minix */
-
-	/* correct for Daylight Saving Time */
-	tmp = accum;
-	tmbuf = localtime(&tmp);
-#ifndef OS_Minix
-	dst = (tmbuf->tm_isdst) ? (-60L * 60L) : 0L;
-	accum += dst;
-#endif
-	
-	return accum;
-}
-
-
-static int get_file_data(Stream_t *Stream, time_t *date, mt_size_t *size,
-			 int *type, int *address)
-{
-	DeclareThis(File_t);
-
-	if(date)
-		*date = conv_stamp(& This->direntry.dir);
-	if(size)
-		*size = (mt_size_t) This->FileSize;
-	if(type)
-		*type = This->direntry.dir.attr & ATTR_DIR;
-	if(address)
-		*address = This->FirstAbsCluNr;
-	return 0;
-}
-
-
-static int free_file(Stream_t *Stream)
-{
-	DeclareThis(File_t);
-	Fs_t *Fs = This->Fs;
-	fsPreallocateClusters(Fs, -This->preallocatedClusters);       
-	FREE(&This->direntry.Dir);
-	freeDirCache(Stream);
-	return hash_remove(filehash, (void *) Stream, This->hint);
-}
-
-
-static int flush_file(Stream_t *Stream)
-{
-	DeclareThis(File_t);
-	direntry_t *entry = &This->direntry;
-
-	if(isRootDir(Stream)) {
-		return 0;
-	}
-
-	if(This->FirstAbsCluNr != getStart(entry->Dir, &entry->dir)) {
-		set_word(entry->dir.start, This->FirstAbsCluNr & 0xffff);
-		set_word(entry->dir.startHi, This->FirstAbsCluNr >> 16);
-		dir_write(entry);
-	}
-	return 0;
-}
-
-
-static int pre_allocate_file(Stream_t *Stream, mt_size_t isize)
-{
-	DeclareThis(File_t);
-
-	size_t size = truncBytes32(isize);
-
-	if(size > This->FileSize &&
-	   size > This->preallocatedSize) {
-		This->preallocatedSize = size;
-		return recalcPreallocSize(This);
-	} else
-		return 0;
-}
-
-static Class_t FileClass = {
-	read_file, 
-	write_file, 
-	flush_file, /* flush */
-	free_file, /* free */
-	0, /* get_geom */
-	get_file_data,
-	pre_allocate_file
-};
-
-static unsigned int getAbsCluNr(File_t *This)
-{
-	if(This->FirstAbsCluNr)
-		return This->FirstAbsCluNr;
-	if(isRootDir((Stream_t *) This))
-		return 0;
-	return 1;
-}
-
-static unsigned int func1(void *Stream)
-{
-	DeclareThis(File_t);
-
-	return getAbsCluNr(This) ^ (long) This->Fs;
-}
-
-static unsigned int func2(void *Stream)
-{
-	DeclareThis(File_t);
-
-	return getAbsCluNr(This);
-}
-
-static int comp(void *Stream, void *Stream2)
-{
-	DeclareThis(File_t);
-
-	File_t *This2 = (File_t *) Stream2;
-
-	return This->Fs != This2->Fs ||
-		getAbsCluNr(This) != getAbsCluNr(This2);
-}
-
-static void init_hash(void)
-{
-	static int is_initialised=0;
-	
-	if(!is_initialised){
-		make_ht(func1, func2, comp, 20, &filehash);
-		is_initialised = 1;
-	}
-}
-
-
-static Stream_t *_internalFileOpen(Stream_t *Dir, unsigned int first, 
-				   size_t size, direntry_t *entry)
-{
-	Stream_t *Stream = GetFs(Dir);
-	DeclareThis(Fs_t);
-	File_t Pattern;
-	File_t *File;
-
-	init_hash();
-	This->refs++;
-
-	if(first != 1){
-		/* we use the illegal cluster 1 to mark newly created files.
-		 * do not manage those by hashtable */
-		Pattern.Fs = This;
-		Pattern.Class = &FileClass;
-		if(first || (entry && !IS_DIR(entry)))
-			Pattern.map = normal_map;
-		else
-			Pattern.map = root_map;
-		Pattern.FirstAbsCluNr = first;
-		Pattern.loopDetectRel = 0;
-		Pattern.loopDetectAbs = first;
-		if(!hash_lookup(filehash, (T_HashTableEl) &Pattern, 
-				(T_HashTableEl **)&File, 0)){
-			File->refs++;
-			This->refs--;
-			return (Stream_t *) File;
-		}
-	}
-
-	File = New(File_t);
-	if (!File)
-		return NULL;
-	File->dcp = 0;
-	File->preallocatedClusters = 0;
-	File->preallocatedSize = 0;
-	/* memorize dir for date and attrib */
-	File->direntry = *entry;
-	if(entry->entry == -3)
-		File->direntry.Dir = (Stream_t *) File; /* root directory */
-	else
-		COPY(File->direntry.Dir);
-
-	File->Class = &FileClass;
-	File->Fs = This;
-	if(first || (entry && !IS_DIR(entry)))
-		File->map = normal_map;
-	else
-		File->map = root_map; /* FAT 12/16 root directory */
-	if(first == 1)
-		File->FirstAbsCluNr = 0;
-	else
-		File->FirstAbsCluNr = first;
-
-	File->loopDetectRel = 0;
-	File->loopDetectAbs = 0;
-
-	File->PreviousRelCluNr = 0xffff;
-	File->FileSize = size;
-	File->refs = 1;
-	File->Buffer = 0;
-	hash_add(filehash, (void *) File, &File->hint);
-	return (Stream_t *) File;
-}
-
-Stream_t *OpenRoot(Stream_t *Dir)
-{
-	unsigned int num;
-	direntry_t entry;
-	size_t size;
-	Stream_t *file;
-
-	memset(&entry, 0, sizeof(direntry_t));
-
-	num = fat32RootCluster(Dir);
-
-	/* make the directory entry */
-	entry.entry = -3;
-	entry.name[0] = '\0';
-	mk_entry("/", ATTR_DIR, num, 0, 0, &entry.dir);
-
-	if(num)
-		size = countBytes(Dir, num);
-	else {
-		Fs_t *Fs = (Fs_t *) GetFs(Dir);
-		size = Fs->dir_len * Fs->sector_size;
-	}
-	file = _internalFileOpen(Dir, num, size, &entry);
-	bufferize(&file);
-	return file;
-}
-
-
-Stream_t *OpenFileByDirentry(direntry_t *entry)
-{
-	Stream_t *file;
-	unsigned int first;
-	size_t size;
-
-	first = getStart(entry->Dir, &entry->dir);
-
-	if(!first && IS_DIR(entry))
-		return OpenRoot(entry->Dir);
-	if (IS_DIR(entry))
-		size = countBytes(entry->Dir, first);
-	else 
-		size = FILE_SIZE(&entry->dir);
-	file = _internalFileOpen(entry->Dir, first, size, entry);
-	if(IS_DIR(entry)) {
-		bufferize(&file);
-		if(first == 1)
-			dir_grow(file, 0);
-	}
-
-	return file;
-}
-
-
-int isRootDir(Stream_t *Stream)
-{
-	File_t *This = getUnbufferedFile(Stream);
-
-	return This->map == root_map;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/file.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/file.h	(revision 9)
+++ 	(revision )
@@ -1,11 +1,0 @@
-#ifndef MTOOLS_FILE_H
-#define MTOOLS_FILE_H
-
-#include "stream.h"
-#include "mtoolsDirent.h"
-
-Stream_t *OpenFileByDirentry(direntry_t *entry);
-Stream_t *OpenRoot(Stream_t *Dir);
-void printFat(Stream_t *Stream);
-direntry_t *getDirentry(Stream_t *Stream);
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/file_name.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/file_name.c	(revision 9)
+++ 	(revision )
@@ -1,203 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "codepage.h"
-
-/* Write a DOS name + extension into a legal unix-style name.  */
-char *unix_normalize (char *ans, char *name, char *ext)
-{
-	char *a;
-	int j;
-	
-	for (a=ans,j=0; (j<8) && (name[j] > ' '); ++j,++a)
-		*a = name[j];
-	if(*ext > ' ') {
-		*a++ = '.';
-		for (j=0; j<3 && ext[j] > ' '; ++j,++a)
-			*a = ext[j];
-	}
-	*a++ = '\0';
-	return ans;
-}
-
-typedef enum Case_l {
-	NONE,
-	UPPER,
-	LOWER 
-} Case_t;
-
-static void TranslateToDos(const char *s, char *t, int count,
-			   char *end, Case_t *Case, int *mangled)
-{
-	*Case = NONE;
-	for( ;  *s && (s < end || !end); s++) {
-		if(!count) {
-			*mangled |= 3;
-			break;
-		}
-		/* skip spaces & dots */
-		if(*s == ' ' || *s == '.') {
-			*mangled |= 3;
-			continue;
-		}
-
-		/* convert to dos */
-		if((*s) & 0x80) {
-			*mangled |= 1;
-			*t = to_dos(*s);
-		}
-
-		if ((*s & 0x7f) < ' ' ) {
-			*mangled |= 3;
-			*t = '_';
-		} else if (islower((unsigned char)*s)) {
-			*t = toupper(*s);
-			if(*Case == UPPER && !mtools_no_vfat)
-				*mangled |= 1;
-			else
-				*Case = LOWER;
-		} else if (isupper((unsigned char)*s)) {
-			*t = *s;
-			if(*Case == LOWER && !mtools_no_vfat)
-				*mangled |= 1;
-			else
-				*Case = UPPER;
-		} else if((*s) & 0x80)
-			*t = mstoupper(*t);	/* upper case */
-		else
-			*t = *s;
-		count--;
-		t++;
-	}
-}
-
-/* dos_name
- *
- * Convert a Unix-style filename to a legal MSDOS name and extension.
- * Will truncate file and extension names, will substitute
- * the character '~' for any illegal character(s) in the name.
- */
-char *dos_name(char *name, int verbose, int *mangled, char *ans)
-{
-	char *s, *ext;
-	register int i;
-	Case_t BaseCase, ExtCase;
-
-	*mangled = 0;
-
-	/* skip drive letter */
-	name = skip_drive(name);
-
-	/* zap the leading path */
-	name = (char *) _basename(name);
-	if ((s = strrchr(name, '\\')))
-		name = s + 1;
-	
-	memset(ans, ' ', 11);
-	ans[11]='\0';
-
-	/* skip leading dots and spaces */
-	i = strspn(name, ". ");
-	if(i) {
-		name += i;
-		*mangled = 3;
-	}
-		
-	ext = strrchr(name, '.');
-
-	/* main name */
-	TranslateToDos(name, ans, 8, ext, &BaseCase, mangled);
-	if(ext)
-		TranslateToDos(ext+1, ans+8, 3, 0, &ExtCase,  mangled);
-
-	if(*mangled & 2)
-		autorename_short(ans, 0);
-
-	if(!*mangled) {
-		if(BaseCase == LOWER)
-			*mangled |= BASECASE;
-		if(ExtCase == LOWER)
-			*mangled |= EXTCASE;
-		if((BaseCase == LOWER || ExtCase == LOWER) &&
-		   !mtools_no_vfat) {
-		  *mangled |= 1;
-		}
-	}
-	return ans;
-}
-
-
-/*
- * Get rid of spaces in an MSDOS 'raw' name (one that has come from the
- * directory structure) so that it can be used for regular expression
- * matching with a Unix filename.  Also used to 'unfix' a name that has
- * been altered by dos_name().
- */
-
-char *unix_name(char *name, char *ext, char Case, char *ans)
-{
-	char *s, tname[9], text[4];
-	int i;
-
-	strncpy(tname, (char *) name, 8);
-	tname[8] = '\0';
-	if ((s = strchr(tname, ' ')))
-		*s = '\0';
-
-	if(!(Case & (BASECASE | EXTCASE)) && mtools_ignore_short_case)
-		Case |= BASECASE | EXTCASE;
-
-	if(Case & BASECASE)
-		for(i=0;i<8 && tname[i];i++)
-			tname[i] = tolower(tname[i]);
-
-	strncpy(text, (char *) ext, 3);
-	text[3] = '\0';
-	if ((s = strchr(text, ' ')))
-		*s = '\0';
-
-	if(Case & EXTCASE)
-		for(i=0;i<3 && text[i];i++)
-			text[i] = tolower(text[i]);
-
-	if (*text) {
-		strcpy(ans, tname);
-		strcat(ans, ".");
-		strcat(ans, text);
-	} else
-		strcpy(ans, tname);
-
-	/* fix special characters (above 0x80) */
-	to_unix(ans,11);
-	return(ans);
-}
-
-/* If null encountered, set *end to 0x40 and write nulls rest of way
- * 950820: Win95 does not like this!  It complains about bad characters.
- * So, instead: If null encountered, set *end to 0x40, write the null, and
- * write 0xff the rest of the way (that is what Win95 seems to do; hopefully
- * that will make it happy)
- */
-/* Always return num */
-int unicode_write(char *in, struct unicode_char *out, int num, int *end_p)
-{
-	int j;
-
-	for (j=0; j<num; ++j) {
-		out->uchar = '\0';	/* Hard coded to ASCII */
-		if (*end_p)
-			/* Fill with 0xff */
-			out->uchar = out->lchar = (char) 0xff;
-		else {
-			out->lchar = *in;
-			if (! *in) {
-				*end_p = VSE_LAST;
-			}
-		}
-
-		++out;
-		++in;
-	}
-	return num;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/file_read.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/file_read.c	(revision 9)
+++ 	(revision )
@@ -1,37 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "file.h"
-
-/*
- * Read the clusters given the beginning FAT entry.  Returns 0 on success.
- */
-
-int file_read(FILE *fp, Stream_t *Source, int textmode, int stripmode)
-{
-	char buffer[16384];
-	int pos;
-	int ret;
-
-	if (!Source){
-		fprintf(stderr,"Couldn't open source file\n");
-		return -1;
-	}
-	
-	pos = 0;
-	while(1){
-		ret = Source->Class->read(Source, buffer, (mt_off_t) pos, 16384);
-		if (ret < 0 ){
-			perror("file read");
-			return -1;
-		}
-		if ( ret == 0)
-			break;
-		if(!fwrite(buffer, 1, ret, fp)){
-			perror("write");
-			return -1;
-		}
-		pos += ret;
-	}
-	return 0;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/filter.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/filter.c	(revision 9)
+++ 	(revision )
@@ -1,140 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-
-typedef struct Filter_t {
-	Class_t *Class;
-	int refs;
-	Stream_t *Next;
-	Stream_t *Buffer;
-
-	int dospos;
-	int unixpos;
-	int mode;
-	int rw;
-	int lastchar;
-} Filter_t;
-
-#define F_READ 1
-#define F_WRITE 2
-
-/* read filter filters out messy dos' bizarre end of lines and final 0x1a's */
-
-static int read_filter(Stream_t *Stream, char *buf, mt_off_t iwhere, size_t len)
-{
-	DeclareThis(Filter_t);
-	int i,j,ret;
-
-	off_t where = truncBytes32(iwhere);
-
-	if ( where != This->unixpos ){
-		fprintf(stderr,"Bad offset\n");
-		exit(1);
-	}
-	if (This->rw == F_WRITE){
-		fprintf(stderr,"Change of transfer direction!\n");
-		exit(1);
-	}
-	This->rw = F_READ;
-	
-	ret = READS(This->Next, buf, (mt_off_t) This->dospos, len);
-	if ( ret < 0 )
-		return ret;
-
-	j = 0;
-	for (i=0; i< ret; i++){
-		if ( buf[i] == '\r' )
-			continue;
-		if (buf[i] == 0x1a)
-			break;
-		This->lastchar = buf[j++] = buf[i];	
-	}
-
-	This->dospos += i;
-	This->unixpos += j;
-	return j;
-}
-
-static int write_filter(Stream_t *Stream, char *buf, mt_off_t iwhere, 
-						size_t len)
-{
-	DeclareThis(Filter_t);
-	int i,j,ret;
-	char buffer[1025];
-
-	off_t where = truncBytes32(iwhere);
-
-	if(This->unixpos == -1)
-		return -1;
-
-	if (where != This->unixpos ){
-		fprintf(stderr,"Bad offset\n");
-		exit(1);
-	}
-	
-	if (This->rw == F_READ){
-		fprintf(stderr,"Change of transfer direction!\n");
-		exit(1);
-	}
-	This->rw = F_WRITE;
-
-	j=i=0;
-	while(i < 1024 && j < len){
-		if (buf[j] == '\n' ){
-			buffer[i++] = '\r';
-			buffer[i++] = '\n';
-			j++;
-			continue;
-		}
-		buffer[i++] = buf[j++];
-	}
-	This->unixpos += j;
-
-	ret = force_write(This->Next, buffer, (mt_off_t) This->dospos, i);
-	if(ret >0 )
-		This->dospos += ret;
-	if ( ret != i ){
-		/* no space on target file ? */
-		This->unixpos = -1;
-		return -1;
-	}
-	return j;
-}
-
-static int free_filter(Stream_t *Stream)
-{
-	DeclareThis(Filter_t);       
-	char buffer=0x1a;
-
-	/* write end of file */
-	if (This->rw == F_WRITE)
-		return force_write(This->Next, &buffer, (mt_off_t) This->dospos, 1);
-	else
-		return 0;
-}
-
-static Class_t FilterClass = { 
-	read_filter,
-	write_filter,
-	0, /* flush */
-	free_filter,
-	0, /* set geometry */
-	get_data_pass_through,
-	0
-};
-
-Stream_t *open_filter(Stream_t *Next)
-{
-	Filter_t *This;
-
-	This = New(Filter_t);
-	if (!This)
-		return NULL;
-	This->Class = &FilterClass;
-	This->dospos = This->unixpos = This->rw = 0;
-	This->Next = Next;
-	This->refs = 1;
-	This->Buffer = 0;
-
-	return (Stream_t *) This;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/floppyd_io.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/floppyd_io.c	(revision 9)
+++ 	(revision )
@@ -1,559 +1,0 @@
-/*
- * IO to the floppyd daemon running on the local X-Server Host
- *
- * written by:
- *
- * Peter Schlaile
- *
- * udbz@rz.uni-karlsruhe.de
- *
- */
-
-#include "sysincludes.h"
-#include "stream.h"
-#include "mtools.h"
-#include "msdos.h"
-#include "scsi.h"
-#include "partition.h"
-#include "floppyd_io.h"
-
-#ifdef USE_FLOPPYD
-
-/* ######################################################################## */
-
-
-typedef unsigned char Byte;
-typedef unsigned long Dword;
-
-char* AuthErrors[] = {
-	"Auth success!",
-	"Auth failed: Packet oversized!",
-	"Auth failed: X-Cookie doesn't match!",
-	"Auth failed: Wrong transmission protocol version!",
-	"Auth failed: Device locked!"
-};
-
-
-typedef struct RemoteFile_t {
-	Class_t *Class;
-	int refs;
-	Stream_t *Next;
-	Stream_t *Buffer;
-	int fd;
-	mt_off_t offset;
-	mt_off_t lastwhere;
-	mt_off_t size;
-} RemoteFile_t;
-
-
-#ifndef HAVE_HTONS
-unsigned short myhtons(unsigned short parm) 
-{
-	Byte val[2];
-	
-	val[0] = (parm >> 8) & 0xff;
-	val[1] = parm        & 0xff;
-
-	return *((unsigned short*) (val));
-}
-#endif
-
-Dword byte2dword(Byte* val) 
-{
-	Dword l;
-	l = (val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3];
-
-	return l;
-}	
-
-void dword2byte(Dword parm, Byte* rval) 
-{
-	rval[0] = (parm >> 24) & 0xff;
-	rval[1] = (parm >> 16) & 0xff;
-	rval[2] = (parm >> 8)  & 0xff;
-	rval[3] = parm         & 0xff;
-}
-
-Dword read_dword(int handle) 
-{
-	Byte val[4];
-	
-	read(handle, val, 4);
-
-	return byte2dword(val);
-}
-
-void write_dword(int handle, Dword parm) 
-{
-	Byte val[4];
-
-	dword2byte(parm, val);
-
-	write(handle, val, 4);
-}
-
-
-/* ######################################################################## */
-
-int authenticate_to_floppyd(int sock, char *display)
-{
-	off_t filelen;
-	Byte buf[16];
-	char *command[] = { "xauth", "xauth", "extract", "-", 0, 0 };
-	char *xcookie;
-	Dword errcode;
-
-	command[4] = display;
-
-	filelen=strlen(display);
-	filelen += 100;
-
-	xcookie = (char *) safe_malloc(filelen+4);
-	filelen = safePopenOut(command, xcookie+4, filelen);
-	if(filelen < 1)
-		return AUTH_AUTHFAILED;
-
-	dword2byte(4,buf);
-	dword2byte(FLOPPYD_PROTOCOL_VERSION,buf+4);
-	write(sock, buf, 8);
-
-	if (read_dword(sock) != 4) {
-		return AUTH_WRONGVERSION;
-	}
-
-	errcode = read_dword(sock);
-
-	if (errcode != AUTH_SUCCESS) {
-		return errcode;
-	}
-
-	dword2byte(filelen, xcookie);
-	write(sock, xcookie, filelen+4);
-
-	if (read_dword(sock) != 4) {
-		return AUTH_PACKETOVERSIZE;
-	}
-
-	errcode = read_dword(sock);
-	
-	return errcode;
-}
-
-
-static int floppyd_reader(int fd, char* buffer, int len) 
-{
-	Dword errcode;
-	Dword gotlen;
-	int l;
-	int start;
-	Byte buf[16];
-
-	dword2byte(1, buf);
-	buf[4] = OP_READ;
-	dword2byte(4, buf+5);
-	dword2byte(len, buf+9);
-	write(fd, buf, 13);
-
-	if (read_dword(fd) != 8) {
-		errno = EIO;
-		return -1;
-	}
-
-	gotlen = read_dword(fd);
-	errcode = read_dword(fd);
-
-	if (gotlen != -1) {
-		if (read_dword(fd) != gotlen) {
-			errno = EIO;
-			return -1;
-		}
-		for (start = 0, l = 0; start < gotlen; start += l) {
-			l = read(fd, buffer+start, gotlen-start);
-			if (l == 0) {
-				errno = EIO;
-				return -1;
-			}
-		}
-	} else {
-		errno = errcode;
-	}
-	return gotlen;
-}
-
-static int floppyd_writer(int fd, char* buffer, int len) 
-{
-	Dword errcode;
-	Dword gotlen;
-	Byte buf[16];
-
-	dword2byte(1, buf);
-	buf[4] = OP_WRITE;
-	dword2byte(len, buf+5);
-
-	write(fd, buf, 9);
-        write(fd, buffer, len);
-	
-	if (read_dword(fd) != 8) {
-		errno = EIO;
-		return -1;
-	}
-
-	gotlen = read_dword(fd);
-	errcode = read_dword(fd);
-
-	errno = errcode;
-	
-	return gotlen;
-}
-
-static int floppyd_lseek(int fd, mt_off_t offset, int whence) 
-{
-	Dword errcode;
-	Dword gotlen;
-	Byte buf[32];
-	
-	dword2byte(1, buf);
-	buf[4] = OP_SEEK;
-	
-	dword2byte(8, buf+5);
-	dword2byte(truncBytes32(offset), buf+9);
-	dword2byte(whence, buf+13);
-	
-	write(fd, buf, 17);
-       
-	if (read_dword(fd) != 8) {
-		errno = EIO;
-		return -1;
-	}
-
-	gotlen = read_dword(fd);
-	errcode = read_dword(fd);
-
-	errno = errcode;
-	
-	return gotlen;
-}
-
-/* ######################################################################## */
-
-typedef int (*iofn) (int, char *, int);
-
-static int floppyd_io(Stream_t *Stream, char *buf, mt_off_t where, int len,
-		   iofn io)
-{
-	DeclareThis(RemoteFile_t);
-	int ret;
-
-	where += This->offset;
-
-	if (where != This->lastwhere ){
-		if(floppyd_lseek( This->fd, where, SEEK_SET) < 0 ){
-			perror("floppyd_lseek");
-			This->lastwhere = (mt_off_t) -1;
-			return -1;
-		}
-	}
-	ret = io(This->fd, buf, len);
-	if ( ret == -1 ){
-		perror("floppyd_io");
-		This->lastwhere = (mt_off_t) -1;
-		return -1;
-	}
-	This->lastwhere = where + ret;
-	return ret;
-}
-
-static int floppyd_read(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
-{	
-	return floppyd_io(Stream, buf, where, len, (iofn) floppyd_reader);
-}
-
-static int floppyd_write(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
-{
-	return floppyd_io(Stream, buf, where, len, (iofn) floppyd_writer);
-}
-
-static int floppyd_flush(Stream_t *Stream)
-{
-#if 0
-	Byte buf[16];
-
-	DeclareThis(RemoteFile_t);
-
-	dword2byte(1, buf);
-	buf[4] = OP_FLUSH;
-
-	write(This->fd, buf, 5);
-
-	if (read_dword(This->fd) != 8) {
-		errno = EIO;
-		return -1;
-	}
-
-	read_dword(This->fd);
-	read_dword(This->fd);
-#endif
-	return 0;
-}
-
-static int floppyd_free(Stream_t *Stream)
-{
-	Byte buf[16];
-
-	DeclareThis(RemoteFile_t);
-
-	if (This->fd > 2) {
-		dword2byte(1, buf);
-		buf[4] = OP_CLOSE;
-		write(This->fd, buf, 5);
-		return close(This->fd);
-	} else {
-		return 0;
-	}
-}
-
-static int floppyd_geom(Stream_t *Stream, struct device *dev, 
-		     struct device *orig_dev,
-		     int media, struct bootsector *boot)
-{
-	size_t tot_sectors;
-	int sect_per_track;
-	DeclareThis(RemoteFile_t);
-
-	dev->ssize = 2; /* allow for init_geom to change it */
-	dev->use_2m = 0x80; /* disable 2m mode to begin */
-
-	if(media == 0xf0 || media >= 0x100){		
-		dev->heads = WORD(nheads);
-		dev->sectors = WORD(nsect);
-		tot_sectors = DWORD(bigsect);
-		SET_INT(tot_sectors, WORD(psect));
-		sect_per_track = dev->heads * dev->sectors;
-		tot_sectors += sect_per_track - 1; /* round size up */
-		dev->tracks = tot_sectors / sect_per_track;
-
-	} else if (media >= 0xf8){
-		media &= 3;
-		dev->heads = old_dos[media].heads;
-		dev->tracks = old_dos[media].tracks;
-		dev->sectors = old_dos[media].sectors;
-		dev->ssize = 0x80;
-		dev->use_2m = ~1;
-	} else {
-		fprintf(stderr,"Unknown media type\n");
-		exit(1);
-	}
-
-	This->size = (mt_off_t) 512 * dev->sectors * dev->tracks * dev->heads;
-
-	return 0;
-}
-
-
-static int floppyd_data(Stream_t *Stream, time_t *date, mt_size_t *size,
-		     int *type, int *address)
-{
-	DeclareThis(RemoteFile_t);
-
-	if(date)
-		/* unknown, and irrelevant anyways */
-		*date = 0;
-	if(size)
-		/* the size derived from the geometry */
-		*size = (mt_size_t) This->size;
-	if(type)
-		*type = 0; /* not a directory */
-	if(address)
-		*address = 0;
-	return 0;
-}
-
-/* ######################################################################## */
-
-static Class_t FloppydFileClass = {
-	floppyd_read, 
-	floppyd_write,
-	floppyd_flush,
-	floppyd_free,
-	floppyd_geom,
-	floppyd_data
-};
-
-/* ######################################################################## */
-
-int get_host_and_port(const char* name, char** hostname, char **display,
-					  short* port)
-{
-	char* newname = strdup(name);
-	char* p;
-	char* p2;
-
-	p = newname;
-	while (*p != '/' && *p) p++;
-	p2 = p;
-	if (*p) p++;
-	*p2 = 0;
-	
-	*port = atoi(p);
-	if (*port == 0) {
-		*port = FLOPPYD_DEFAULT_PORT;	
-	}
-
-	*display = strdup(newname);
-
-	p = newname;
-	while (*p != ':' && *p) p++;
-	p2 = p;
-	if (*p) p++;
-	*p2 = 0;
-
-	*port += atoi(p);  /* add display number to the port */
-
-	if (!*newname || strcmp(newname, "unix") == 0) {
-		free(newname);
-		newname = strdup("localhost");
-	}
-
-	*hostname = newname;
-	return 1;
-}
-
-/*
- *  * Return the IP address of the specified host.
- *  */
-static IPaddr_t getipaddress(char *ipaddr)
-{
-	
-	struct hostent  *host;
-	IPaddr_t        ip;
-
-	if (((ip = inet_addr(ipaddr)) == INADDR_NONE) &&
-	    (strcmp(ipaddr, "255.255.255.255") != 0)) {
-		
-		if ((host = gethostbyname(ipaddr)) != NULL) {
-			memcpy(&ip, host->h_addr, sizeof(ip));
-		}
-		
-		endhostent();
-	}
-	
-#ifdef DEBUG
-	fprintf(stderr, "IP lookup %s -> 0x%08lx\n", ipaddr, ip);
-#endif
-	  
-	return (ip);
-}
-
-/*
- *  * Connect to the floppyd server.
- *  */
-static int connect_to_server(IPaddr_t ip, short port)
-{
-	
-	struct sockaddr_in      addr;
-	int                     sock;
-	
-	/*
-	 * Allocate a socket.
-	 */
-	if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-		return (-1);
-	}
-	
-	/*
-	 * Set the address to connect to.
-	 */
-	
-	addr.sin_family = AF_INET;
-#ifndef HAVE_HTONS
-	addr.sin_port = myhtons(port);
-#else	
-	addr.sin_port = htons(port);
-#endif	
-	addr.sin_addr.s_addr = ip;
-	
-        /*
-	 * Connect our socket to the above address.
-	 */
-	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
-		return (-1);
-	}
-
-        /*
-	 * Set the keepalive socket option to on.
-	 */
-	{
-		int             on = 1;
-		setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, 
-			   (char *)&on, sizeof(on));
-	}
-	
-	return (sock);
-}
-
-static int ConnectToFloppyd(const char* name);
-
-Stream_t *FloppydOpen(struct device *dev, struct device *dev2,
-					  char *name, int mode, char *errmsg,
-					  int mode2, int locked)
-{
-	RemoteFile_t *This;
-
-	if (!dev ||  !(dev->misc_flags & FLOPPYD_FLAG))
-		return NULL;
-	
-	This = New(RemoteFile_t);
-	if (!This){
-		printOom();
-		return NULL;
-	}
-	This->Class = &FloppydFileClass;
-	This->Next = 0;
-	This->offset = 0;
-	This->lastwhere = 0;
-	This->refs = 1;
-	This->Buffer = 0;
-
-	This->fd = ConnectToFloppyd(name);
-	if (This->fd == -1) {
-		Free(This);
-		return NULL;
-	}
-	return (Stream_t *) This;
-}
-
-static int ConnectToFloppyd(const char* name) 
-{
-	char* hostname;
-	char* display;
-	short port;
-	int rval = get_host_and_port(name, &hostname, &display, &port);
-	int sock;
-	int reply;
-	
-	if (!rval) return -1;
-
-	sock = connect_to_server(getipaddress(hostname), port);
-
-	if (sock == -1) {
-		fprintf(stderr,
-			"Can't connect to floppyd server on %s, port %i!\n",
-			hostname, port);
-		return -1;
-	}
-	
-	reply = authenticate_to_floppyd(sock, display);
-
-	if (reply != 0) {
-		fprintf(stderr, 
-			"Permission denied, authentication failed!\n"
-			"%s\n", AuthErrors[reply]);
-		return -1;
-	}
-	
-	free(hostname);
-	free(display);
-
-	return sock;
-}
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/floppyd_io.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/floppyd_io.h	(revision 9)
+++ 	(revision )
@@ -1,37 +1,0 @@
-#ifndef MTOOLS_FLOPPYDIO_H
-#define MTOOLS_FLOPPYDIO_H
-
-#ifdef USE_FLOPPYD
-
-#include "stream.h"
-
-/*extern int ConnectToFloppyd(const char* name, Class_t** ioclass);*/
-Stream_t *FloppydOpen(struct device *dev, struct device *dev2,
-					  char *name, int mode, char *errmsg,
-					  int mode2, int locked);
-
-#define FLOPPYD_DEFAULT_PORT 5703
-#define FLOPPYD_PROTOCOL_VERSION 10
-
-enum FloppydOpcodes {
-	OP_READ,
-	OP_WRITE,
-	OP_SEEK,
-	OP_FLUSH,
-	OP_CLOSE,
-	OP_IOCTL
-};
-
-enum AuthErrorsEnum {
-	AUTH_SUCCESS,
-	AUTH_PACKETOVERSIZE,
-	AUTH_AUTHFAILED,
-	AUTH_WRONGVERSION,
-	AUTH_DEVLOCKED,
-	AUTH_BADPACKET
-};
-
-typedef unsigned long IPaddr_t;
-
-#endif
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/force_io.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/force_io.c	(revision 9)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/*
- * Force I/O to be done to complete transfer length
- *
- * written by:
- *
- * Alain L. Knaff			
- * alain@linux.lu
- *
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "stream.h"
-
-static int force_io(Stream_t *Stream,
-		    char *buf, mt_off_t start, size_t len,
-		    int (*io)(Stream_t *, char *, mt_off_t, size_t))
-{
-	int ret;
-	int done=0;
-	
-	while(len){
-		ret = io(Stream, buf, start, len);
-		if ( ret <= 0 ){
-			if (done)
-				return done;
-			else
-				return ret;
-		}
-		start += ret;
-		done += ret;
-		len -= ret;
-		buf += ret;
-	}
-	return done;
-}
-
-int force_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
-{
-	return force_io(Stream, buf, start, len,
-					Stream->Class->write);
-}
-
-int force_read(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
-{
-	return force_io(Stream, buf, start, len,
-					Stream->Class->read);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/fs.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/fs.h	(revision 9)
+++ 	(revision )
@@ -1,26 +1,0 @@
-#ifndef MTOOLS_FS_H
-#define MTOOLS_FS_H
-
-#include "stream.h"
-
-
-typedef struct FsPublic_t {
-	Class_t *Class;
-	int refs;
-	Stream_t *Next;
-	Stream_t *Buffer;
-
-	int serialized;
-	unsigned long serial_number;
-	int cluster_size;
-	unsigned int sector_size;
-} FsPublic_t;
-
-Stream_t *fs_init(char *drive, int mode);
-int fat_free(Stream_t *Dir, unsigned int fat);
-int fatFreeWithDir(Stream_t *Dir, struct directory *dir);
-int fat_error(Stream_t *Dir);
-int fat32RootCluster(Stream_t *Dir);
-char *getDrive(Stream_t *Stream);
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/fsP.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/fsP.h	(revision 9)
+++ 	(revision )
@@ -1,84 +1,0 @@
-#ifndef MTOOLS_FSP_H
-#define MTOOLS_FSP_H
-
-#include "stream.h"
-#include "msdos.h"
-#include "fs.h"
-
-typedef enum fatAccessMode_t { 
-	FAT_ACCESS_READ, 
-	FAT_ACCESS_WRITE
-} fatAccessMode_t;
-
-typedef struct Fs_t {
-	Class_t *Class;
-	int refs;
-	Stream_t *Next;
-	Stream_t *Buffer;
-	
-	int serialized;
-	unsigned long serial_number;
-	int cluster_size;
-	unsigned int sector_size;
-	int fat_error;
-
-	unsigned int (*fat_decode)(struct Fs_t *This, unsigned int num);
-	void (*fat_encode)(struct Fs_t *This, unsigned int num,
-			   unsigned int code);
-
-	Stream_t *Direct;
-	int fat_dirty;
-	unsigned int fat_start;
-	unsigned int fat_len;
-
-	int num_fat;
-	unsigned int end_fat;
-	unsigned int last_fat;
-	int fat_bits;
-	struct FatMap_t *FatMap;
-
-	int dir_start;
-	int dir_len;
-	int clus_start;
-
-	int num_clus;
-	char *drive; /* for error messages */
-
-	/* fat 32 */
-	unsigned int primaryFat;
-	unsigned int writeAllFats;
-	unsigned int rootCluster;
-	int infoSectorLoc;
-	unsigned int last; /* last sector allocated, or MAX32 if unknown */
-	unsigned int freeSpace; /* free space, or MAX32 if unknown */
-	int preallocatedClusters;
-
-	int lastFatSectorNr;
-	unsigned char *lastFatSectorData;
-	fatAccessMode_t lastFatAccessMode;
-	int sectorMask;
-	int sectorShift;
-} Fs_t;
-
-int fs_free(Stream_t *Stream);
-
-void set_fat12(Fs_t *Fs);
-void set_fat16(Fs_t *Fs);
-void set_fat32(Fs_t *Fs);
-unsigned int get_next_free_cluster(Fs_t *Fs, unsigned int last);
-unsigned int fatDecode(Fs_t *This, unsigned int pos);
-void fatAppend(Fs_t *This, unsigned int pos, unsigned int newpos);
-void fatDeallocate(Fs_t *This, unsigned int pos);
-void fatAllocate(Fs_t *This, unsigned int pos, unsigned int value);
-void fatEncode(Fs_t *This, unsigned int pos, unsigned int value);
-
-int fat_read(Fs_t *This, struct bootsector *boot, int fat_bits,
-			 size_t tot_sectors, int nodups);
-void fat_write(Fs_t *This);
-int zero_fat(Fs_t *Fs, int media_descriptor);
-extern Class_t FsClass;
-int fsPreallocateClusters(Fs_t *Fs, long);
-Fs_t *getFs(Stream_t *Stream);
-
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/hash.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/hash.c	(revision 9)
+++ 	(revision )
@@ -1,205 +1,0 @@
-/*
- * hash.c - hash table.
- */
-
-#include "sysincludes.h"
-#include "htable.h"
-#include "mtools.h"
-
-struct hashtable {
-  T_HashFunc f1,f2;
-  T_ComparFunc compar;
-  int size;  /* actual size of the array */
-  int fill;  /* number of deleted or in use slots */
-  int inuse; /* number of slots in use */
-  int max;   /* maximal number of elements to keep efficient */
-  T_HashTableEl *entries;
-};
-
-static int sizes[]={5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, 12853,
-		    25717, 51437, 102877, 205759, 411527, 823117, 1646237,
-		    3292489, 6584983, 13169977, 26339969, 52679969, 105359939,
-		    210719881, 421439783, 842879579, 1685759167, 0 };
-static int deleted=0;
-static int unallocated=0;
-
-static int alloc_ht(T_HashTable *H, int size)
-{
-  int i;
-
-  for(i=0; sizes[i]; i++)
-    if (sizes[i] > size*4 )
-      break;
-  if (!sizes[i])
-    for(i=0; sizes[i]; i++)
-      if (sizes[i] > size*2 )
-	break;
-  if (!sizes[i])
-    for(i=0; sizes[i]; i++)
-      if (sizes[i] > size)
-	break;
-  if(!sizes[i])
-    return -1;
-  size = sizes[i];
-  if(size < H->size)
-	  size = H->size; /* never shrink the table */
-  H->max = size * 4 / 5 - 2;
-  H->size = size;
-  H->fill = 0;
-  H->inuse = 0;
-  H->entries = NewArray(size, T_HashTableEl);
-  if (H->entries == NULL)
-    return -1; /* out of memory error */
-  
-  for(i=0; i < size; i++)
-    H->entries[i] = &unallocated;
-  return 0;
-}
-
-int make_ht(T_HashFunc f1, T_HashFunc f2, T_ComparFunc c, int size,
-	    T_HashTable **H)
-{
-  *H = New(T_HashTable);
-  if (*H == NULL){
-    return -1; /* out of memory error */
-  }
-  
-  (*H)->f1 = f1;
-  (*H)->f2 = f2;
-  (*H)->compar = c;
-  (*H)->size = 0;
-  if(alloc_ht(*H,size))
-    return -1;
-  return 0;
-}
-
-int free_ht(T_HashTable *H, T_HashFunc entry_free)
-{
-  int i;
-  if(entry_free)
-    for(i=0; i< H->size; i++)
-      if (H->entries[i] != &unallocated &&
-	  H->entries[i] != &deleted)
-	entry_free(H->entries[i]);
-  Free(H->entries);
-  Free(H);
-  return 0;
-}
-
-/* add into hash table without checking for repeats */
-static int _hash_add(T_HashTable *H,T_HashTableEl *E, int *hint)
-{
-  int f2, pos, ctr;
-
-  pos = H->f1(E) % H->size;
-  f2 = -1;
-  ctr = 0;
-  while(H->entries[pos] != &unallocated &&
-	H->entries[pos] != &deleted){
-    if (f2 == -1)
-      f2 = H->f2(E) % (H->size - 1);
-    pos = (pos+f2+1) % H->size;
-    ctr++;
-  }
-  if(H->entries[pos] == &unallocated)
-     H->fill++; /* only increase fill if the previous element was not yet
-		 * counted, i.e. unallocated */
-  H->inuse++;
-  H->entries[pos] = E;
-  if(hint)
-	  *hint = pos;
-  return 0;
-}
-
-static int rehash(T_HashTable *H)
-{
-  int size,i;
-  T_HashTableEl *oldentries;
-  /* resize the table */
-  
-  size = H->size;
-  oldentries = H->entries;
-  if(alloc_ht(H,((H->inuse+1)*4+H->fill)/5))
-	  return -1;
-
-  for(i=0; i < size; i++){
-    if(oldentries[i] != &unallocated && oldentries[i] != &deleted)
-      _hash_add(H, oldentries[i], 0);
-  }
-  Free(oldentries);
-  return 0;
-}
-
-int hash_add(T_HashTable *H, T_HashTableEl *E, int *hint)
-{
-  if (H->fill >= H->max)
-    rehash(H);
-  if (H->fill == H->size)
-    return -1; /*out of memory error */
-  return _hash_add(H,E, hint);
-}
-
-
-/* add into hash table without checking for repeats */
-static int _hash_lookup(T_HashTable *H,T_HashTableEl *E, T_HashTableEl **E2,
-			int *hint, int isIdentity)
-{
-  int f2, pos, upos, ttl;
-
-  pos = H->f1(E) % H->size;
-  ttl = H->size;
-  f2 = -1;
-  upos = -1;
-  while(ttl &&
-	H->entries[pos] != &unallocated &&
-	(H->entries[pos] == &deleted ||
-	 ((isIdentity || H->compar(H->entries[pos], E) != 0) &&
-	  (!isIdentity || H->entries[pos] != E)))){
-    if (f2 == -1)
-      f2 = H->f2(E) % (H->size - 1);
-    if (upos == -1 && H->entries[pos] == &deleted)
-      upos = pos;
-    pos = (pos+f2+1) % H->size;
-    ttl--;
-  }
-  if(H->entries[pos] == &unallocated || !ttl)
-    return -1;
-  if (upos != -1){
-    H->entries[upos] = H->entries[pos];
-    H->entries[pos] = &deleted;
-    pos = upos;
-  }
-  if(hint)
-    *hint = pos;
-  *E2= H->entries[pos];
-  return 0;
-}
-
-
-int hash_lookup(T_HashTable *H,T_HashTableEl *E, T_HashTableEl **E2,
-		int *hint)
-{
-	return _hash_lookup(H, E, E2, hint, 0);
-}
-
-/* add into hash table without checking for repeats */
-int hash_remove(T_HashTable *H,T_HashTableEl *E, int hint)
-{
-  T_HashTableEl *E2;
-
-  if (hint >=0 && hint < H->size &&
-      H->entries[hint] == E){
-    H->inuse--;
-    H->entries[hint] = &deleted;
-    return 0;
-  }
-
-  if(_hash_lookup(H, E, &E2, &hint, 1)) {
-	  fprintf(stderr, "Removing non-existent entry\n");
-	  exit(1);
-	  return -1;
-  }
-  H->inuse--;
-  H->entries[hint] = &deleted;
-  return 0;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/htable.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/htable.h	(revision 9)
+++ 	(revision )
@@ -1,17 +1,0 @@
-/*
- * hashtable
- */
-
-typedef struct hashtable T_HashTable;
-typedef void *T_HashTableEl;
-typedef unsigned int (*T_HashFunc)(void *);
-typedef int (*T_ComparFunc)(void *, void *);
-
-
-int make_ht(T_HashFunc f1, T_HashFunc f2, T_ComparFunc c, int size, T_HashTable **H);
-int hash_add(T_HashTable *H, T_HashTableEl *E, int *hint);
-int hash_remove(T_HashTable *H, T_HashTableEl *E, int hint);
-int hash_lookup(T_HashTable *H, T_HashTableEl *E, T_HashTableEl **E2,
-		int *hint);
-int free_ht(T_HashTable *H, T_HashFunc entry_free);
-
Index: trunk/minix/commands/i386/mtools-3.9.7/init.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/init.c	(revision 9)
+++ 	(revision )
@@ -1,414 +1,0 @@
-/*
- * Initialize an MSDOS diskette.  Read the boot sector, and switch to the
- * proper floppy disk device to match the format on the disk.  Sets a bunch
- * of global variables.  Returns 0 on success, or 1 on failure.
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "stream.h"
-#include "mtools.h"
-#include "fsP.h"
-#include "plain_io.h"
-#include "floppyd_io.h"
-#include "xdf_io.h"
-#include "buffer.h"
-
-extern int errno;
-
-
-#ifndef OS_Minix		/* Minix is memory starved. */
-#define FULL_CYL
-#endif
-
-unsigned int num_clus;			/* total number of cluster */
-
-
-/*
- * Read the boot sector.  We glean the disk parameters from this sector.
- */
-static int read_boot(Stream_t *Stream, struct bootsector * boot, int size)
-{	
-	/* read the first sector, or part of it */
-	if(!size)
-		size = BOOTSIZE;
-	if(size > 1024)
-		size = 1024;
-
-	if (force_read(Stream, (char *) boot, 0, size) != size)
-		return -1;
-	return 0;
-}
-
-static int fs_flush(Stream_t *Stream)
-{
-	DeclareThis(Fs_t);
-
-	fat_write(This);
-	return 0;
-}
-
-Class_t FsClass = {
-	read_pass_through, /* read */
-	write_pass_through, /* write */
-	fs_flush, 
-	fs_free, /* free */
-	0, /* set geometry */
-	get_data_pass_through,
-	0 /* pre allocate */
-};
-
-static int get_media_type(Stream_t *St, struct bootsector *boot)
-{
-	int media;
-
-	media = boot->descr;
-	if(media < 0xf0){
-		char temp[512];
-		/* old DOS disk. Media descriptor in the first FAT byte */
-		/* old DOS disk always have 512-byte sectors */
-		if (force_read(St,temp,(mt_off_t) 512,512) == 512)
-			media = (unsigned char) temp[0];
-		else
-			media = 0;
-	} else
-		media += 0x100;
-	return media;
-}
-
-
-Stream_t *GetFs(Stream_t *Fs)
-{
-	while(Fs && Fs->Class != &FsClass)
-		Fs = Fs->Next;
-	return Fs;
-}
-
-Stream_t *find_device(char *drive, int mode, struct device *out_dev,
-		      struct bootsector *boot,
-		      char *name, int *media, mt_size_t *maxSize)
-{
-	char errmsg[200];
-	Stream_t *Stream;
-	struct device *dev;
-	int r;
-#ifdef OS_Minix
-	static char *devname;
-	struct device onedevice[2];
-	struct stat stbuf;
-
-	free(devname);
-	devname = safe_malloc((9 + strlen(drive)) * sizeof(devname[0]));
-	strcpy(devname, "/dev/dosX");
-	if (isupper(drive[0]) && drive[1] == 0) {
-		/* single letter device name, use /dev/dos$drive */
-		devname[8]= drive[0];
-	} else
-	if (strchr(drive, '/') == NULL) {
-		/* a simple name, use /dev/$drive */
-		strcpy(devname+5, drive);
-	} else {
-		/* a pathname, use as is. */
-		strcpy(devname, drive);
-	}
-	if (stat(devname, &stbuf) != -1) {
-		memset(onedevice, 0, sizeof(onedevice));
-		onedevice[0].name = devname;
-		onedevice[0].drive = drive;
-		onedevice[1].name = NULL;
-		onedevice[1].drive = NULL;
-		dev = onedevice;
-	} else {
-		dev = devices;
-	}
-#else
-	dev = devices;
-#endif
-
-	Stream = NULL;
-	sprintf(errmsg, "Drive '%s:' not supported", drive);	
-					/* open the device */
-	for (; dev->name; dev++) {
-		FREE(&Stream);
-		if (strcmp(dev->drive, drive) != 0)
-			continue;
-		*out_dev = *dev;
-		expand(dev->name,name);
-#ifdef USING_NEW_VOLD
-		strcpy(name, getVoldName(dev, name));
-#endif
-
-		Stream = 0;
-#ifdef USE_XDF
-		Stream = XdfOpen(out_dev, name, mode, errmsg, 0);
-		if(Stream) {
-			out_dev->use_2m = 0x7f;
-			if(maxSize)
-			    *maxSize = max_off_t_31;
-		}
-#endif
-
-#ifdef USE_FLOPPYD
-		if(!Stream) {
-			Stream = FloppydOpen(out_dev, dev, name, mode, errmsg, 0, 1);
-			if(Stream && maxSize)
-				*maxSize = max_off_t_31;
-		}
-#endif
-
-		if (!Stream)
-			Stream = SimpleFileOpen(out_dev, dev, name, mode,
-						errmsg, 0, 1, maxSize);
-
-		if( !Stream)
-			continue;
-
-		/* read the boot sector */
-		if ((r=read_boot(Stream, boot, out_dev->blocksize)) < 0){
-			sprintf(errmsg,
-				"init %s: could not read boot sector",
-				drive);
-			continue;
-		}
-
-		if((*media= get_media_type(Stream, boot)) <= 0xf0 ){
-			if (boot->jump[2]=='L') 
-				sprintf(errmsg,
-					"diskette %s: is Linux LILO, not DOS", 
-					drive);
-			else 
-				sprintf(errmsg,"init %s: non DOS media", drive);
-			continue;
-		}
-
-		/* set new parameters, if needed */
-		errno = 0;
-		if(SET_GEOM(Stream, out_dev, dev, *media, boot)){
-			if(errno)
-#ifdef HAVE_SNPRINTF
-				snprintf(errmsg, 199,
-					"Can't set disk parameters for %s: %s", 
-					drive, strerror(errno));
-#else
-				sprintf(errmsg,
-					"Can't set disk parameters for %s: %s", 
-					drive, strerror(errno));
-#endif
-			else
-				sprintf(errmsg, 
-					"Can't set disk parameters for %s", 
-					drive);
-			continue;
-		}
-		break;
-	}
-
-	/* print error msg if needed */	
-	if ( dev->drive == 0 ){
-		FREE(&Stream);
-		fprintf(stderr,"%s\n",errmsg);
-		return NULL;
-	}
-#ifdef OS_Minix
-	/* Minix can lseek up to 4G. */
-	if (maxSize) *maxSize = 0xFFFFFFFFUL;
-#endif
-	return Stream;
-}
-
-
-Stream_t *fs_init(char *drive, int mode)
-{
-	int blocksize;
-	int media,i;
-	int nhs;
-	int disk_size = 0;	/* In case we don't happen to set this below */
-	size_t tot_sectors;
-	char name[EXPAND_BUF];
-	int cylinder_size;
-	struct device dev;
-	mt_size_t maxSize;
-
-	struct bootsector boot0;
-#define boot (&boot0)
-	Fs_t *This;
-
-	This = New(Fs_t);
-	if (!This)
-		return NULL;
-
-	This->Direct = NULL;
-	This->Next = NULL;
-	This->refs = 1;
-	This->Buffer = 0;
-	This->Class = &FsClass;
-	This->preallocatedClusters = 0;
-	This->lastFatSectorNr = 0;
-	This->lastFatAccessMode = 0;
-	This->lastFatSectorData = 0;
-	This->drive = drive;
-	This->last = 0;
-
-	This->Direct = find_device(drive, mode, &dev, &boot0, name, &media, 
-							   &maxSize);
-	if(!This->Direct)
-		return NULL;
-	
-	This->sector_size = WORD(secsiz);
-	if(This->sector_size > MAX_SECTOR){
-		fprintf(stderr,"init %s: sector size too big\n", drive);
-		return NULL;
-	}
-
-	i = log_2(This->sector_size);
-
-	if(i == 24) {
-		fprintf(stderr, 
-			"init %c: sector size (%d) not a small power of two\n",
-			drive, This->sector_size);
-		return NULL;
-	}
-	This->sectorShift = i;
-	This->sectorMask = This->sector_size - 1;
-
-
-	cylinder_size = dev.heads * dev.sectors;
-	if (!tot_sectors) tot_sectors = dev.tracks * cylinder_size;
-
-	This->serialized = 0;
-	if ((media & ~7) == 0xf8){
-		i = media & 3;
-		This->cluster_size = old_dos[i].cluster_size;
-		tot_sectors = cylinder_size * old_dos[i].tracks;
-		This->fat_start = 1;
-		This->fat_len = old_dos[i].fat_len;
-		This->dir_len = old_dos[i].dir_len;
-		This->num_fat = 2;
-		This->sector_size = 512;
-		This->sectorShift = 9;
-		This->sectorMask = 511;
-		This->fat_bits = 12;
-		nhs = 0;
-	} else {
-		struct label_blk_t *labelBlock;
-		/*
-		 * all numbers are in sectors, except num_clus 
-		 * (which is in clusters)
-		 */
-		tot_sectors = WORD(psect);
-		if(!tot_sectors) {
-			tot_sectors = DWORD(bigsect);			
-			nhs = DWORD(nhs);
-		} else
-			nhs = WORD(nhs);
-
-
-		This->cluster_size = boot0.clsiz; 		
-		This->fat_start = WORD(nrsvsect);
-		This->fat_len = WORD(fatlen);
-		This->dir_len = WORD(dirents) * MDIR_SIZE / This->sector_size;
-		This->num_fat = boot0.nfat;
-
-		if (This->fat_len) {
-			labelBlock = &boot0.ext.old.labelBlock;
-		} else {
-			labelBlock = &boot0.ext.fat32.labelBlock;
-		}
-
-		if(labelBlock->dos4 == 0x29) {
-			This->serialized = 1;
-			This->serial_number = _DWORD(labelBlock->serial);
-		}
-	}
-
-	if (tot_sectors >= (maxSize >> This->sectorShift)) {
-		fprintf(stderr, "Big disks not supported on this architecture\n");
-		exit(1);
-	}
-
-#ifndef OS_Minix   /* Strange check, MS-DOS isn't that picky. */
-
-	if(!mtools_skip_check && (tot_sectors % dev.sectors)){
-		fprintf(stderr,
-			"Total number of sectors not a multiple of"
-			" sectors per track!\n");
-		fprintf(stderr,
-			"Add mtools_skip_check=1 to your .mtoolsrc file "
-			"to skip this test\n");
-		exit(1);
-	}
-#endif
-
-	/* full cylinder buffering */
-#ifdef FULL_CYL
-	disk_size = (dev.tracks) ? cylinder_size : 512;
-#else /* FULL_CYL */
-	disk_size = (dev.tracks) ? dev.sectors : 512;
-#endif /* FULL_CYL */
-
-#if (defined OS_sysv4 && !defined OS_solaris)
-	/*
-	 * The driver in Dell's SVR4 v2.01 is unreliable with large writes.
-	 */
-        disk_size = 0;
-#endif /* (defined sysv4 && !defined(solaris)) */
-
-#ifdef OS_linux
-	disk_size = cylinder_size;
-#endif
-
-#if 1
-	if(disk_size > 256) {
-		disk_size = dev.sectors;
-		if(dev.sectors % 2)
-			disk_size <<= 1;
-	}
-#endif
-	if (disk_size % 2)
-		disk_size *= 2;
-
-	if(!dev.blocksize || dev.blocksize < This->sector_size)
-		blocksize = This->sector_size;
-	else
-		blocksize = dev.blocksize;
-	if (disk_size)
-		This->Next = buf_init(This->Direct,
-				      8 * disk_size * blocksize,
-				      disk_size * blocksize,
-				      This->sector_size);
-	else
-		This->Next = This->Direct;
-
-	if (This->Next == NULL) {
-		perror("init: allocate buffer");
-		This->Next = This->Direct;
-	}
-
-	/* read the FAT sectors */
-	if(fat_read(This, &boot0, dev.fat_bits, tot_sectors, dev.use_2m&0x7f)){
-		This->num_fat = 1;
-		FREE(&This->Next);
-		Free(This->Next);
-		return NULL;
-	}
-	return (Stream_t *) This;
-}
-
-char *getDrive(Stream_t *Stream)
-{
-	DeclareThis(Fs_t);
-
-	if(This->Class != &FsClass)
-		return getDrive(GetFs(Stream));
-	else
-		return This->drive;
-}
-
-int fsPreallocateClusters(Fs_t *Fs, long size)
-{
-	if(size > 0 && getfreeMinClusters((Stream_t *)Fs, size) != 1)
-		return -1;
-
-	Fs->preallocatedClusters += size;
-	return 0;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/llong.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/llong.c	(revision 9)
+++ 	(revision )
@@ -1,84 +1,0 @@
-#include "sysincludes.h"
-#include "stream.h"
-#include "fsP.h"
-#include "llong.h"
-#include "mtools.h"
-
-/* Warnings about integer overflow in expression can be ignored.  These are
- * due to the way that maximal values for those integers are computed: 
- * intentional overflow from smallest negative number (1000...) to highest 
- * positive number (0111...) by substraction of 1 */
-#ifdef __GNUC__
-/*
-#warning "The following warnings about integer overflow in expression can be safely ignored"
-*/
-#endif
-
-#if 1
-const mt_off_t max_off_t_31 = MAX_OFF_T_B(31); /* Floppyd */
-const mt_off_t max_off_t_41 = MAX_OFF_T_B(41); /* SCSI */
-const mt_off_t max_off_t_seek = MAX_OFF_T_B(SEEK_BITS); /* SCSI */
-#else
-const mt_off_t max_off_t_31 = MAX_OFF_T_B(10); /* Floppyd */
-const mt_off_t max_off_t_41 = MAX_OFF_T_B(10); /* SCSI */
-const mt_off_t max_off_t_seek = MAX_OFF_T_B(10); /* SCSI */
-#endif
-
-off_t truncBytes32(mt_off_t off)
-{
-	if (off & ~max_off_t_31) {
-		fprintf(stderr, "Internal error, offset too big\n");
-		exit(1);
-	}
-	return (off_t) off;
-}
-
-mt_off_t sectorsToBytes(Stream_t *Stream, off_t off)
-{
-	DeclareThis(Fs_t);
-	return (mt_off_t) off << This->sectorShift;
-}
-
-#if defined HAVE_LLSEEK
-# ifndef HAVE_LLSEEK_PROTOTYPE
-extern long long llseek (int fd, long long offset, int origin);
-# endif
-#endif
-
-#if defined HAVE_LSEEK64
-# ifndef HAVE_LSEEK64_PROTOTYPE
-extern long long lseek64 (int fd, long long offset, int origin);
-# endif
-#endif
-
-
-int mt_lseek(int fd, mt_off_t where, int whence)
-{
-#if defined HAVE_LSEEK64
-	if(lseek64(fd, where, whence) >= 0)
-		return 0;
-	else
-		return -1;
-#elif defined HAVE_LLSEEK
-	if(llseek(fd, where, whence) >= 0)
-		return 0;
-	else
-		return -1;		
-#else
-	if (lseek(fd, (off_t) where, whence) >= 0)
-		return 0;
-	else
-		return 1;
-#endif
-}
-
-int log_2(int size)
-{
-	int i;
-
-	for(i=0; i<24; i++) {
-		if(1 << i == size)
-			return i;
-	}
-	return 24;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/llong.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/llong.h	(revision 9)
+++ 	(revision )
@@ -1,81 +1,0 @@
-#ifndef MTOOLS_LLONG_H
-#define MTOOLS_LLONG_H
-
-#if 1
-
-
-#ifdef HAVE_OFF_T_64
-/* if off_t is already 64 bits, be happy, and don't worry about the
- * loff_t and llseek stuff */
-#define MT_OFF_T off_t
-#endif
-
-#ifndef MT_OFF_T
-# ifdef HAVE_LLSEEK
-/* we have llseek. Now, what's its type called? loff_t or offset_t ? */
-#  ifdef HAVE_LOFF_T
-#   define MT_OFF_T loff_t
-#  else
-#   ifdef HAVE_OFFSET_T
-#    define MT_OFF_T offset_t
-#   endif
-#  endif
-# endif
-#endif
-
-#ifndef MT_OFF_T
-/* we still don't have a suitable mt_off_t type...*/
-# ifdef HAVE_LONG_LONG
-/* ... first try long long ... */
-#  define MT_OFF_T long long
-# else
-/* ... and if that fails, fall back on good ole' off_t */
-#  define MT_OFF_T off_t
-# endif
-#endif
-
-typedef MT_OFF_T mt_off_t;
-
-#else
-/* testing: meant to flag dubious assignments between 32 bit length types
- * and 64 bit ones */
-typedef struct {
-	int lo;
-	int high;
-} *mt_off_t;
-
-
-#endif
-
-typedef mt_off_t mt_size_t;
-
-#define min(a,b) ((a) < (b) ? (a) : (b))
-#define MAX_OFF_T_B(bits) \
-	(((mt_off_t) 1 << min(bits, sizeof(mt_off_t)*8 - 1)) - 1)
-
-#ifdef HAVE_LLSEEK
-# define SEEK_BITS 63
-#else
-# define SEEK_BITS (sizeof(off_t) * 8 - 1)
-#endif
-
-extern const mt_off_t max_off_t_31;
-extern const mt_off_t max_off_t_41;
-extern const mt_off_t max_off_t_seek;
-
-extern off_t truncBytes32(mt_off_t off);
-mt_off_t sectorsToBytes(Stream_t *This, off_t off);
-
-mt_size_t getfree(Stream_t *Stream);
-int getfreeMinBytes(Stream_t *Stream, mt_size_t ref);
-
-Stream_t *find_device(char *drive, int mode, struct device *out_dev,
-					  struct bootsector *boot,
-					  char *name, int *media, mt_size_t *maxSize);
-
-int mt_lseek(int fd, mt_off_t where, int whence);
-
-
-int log_2(int);
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/mainloop.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mainloop.c	(revision 9)
+++ 	(revision )
@@ -1,557 +1,0 @@
-/*
- * mainloop.c
- * Iterating over all the command line parameters, and matching patterns
- * where needed
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "fs.h"
-#include "mainloop.h"
-#include "plain_io.h"
-#include "file.h"
-
-
-int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); 
-int unix_loop(Stream_t *Stream, MainParam_t *mp, char *arg, 
-	      int follow_dir_link);
-
-static int _unix_loop(Stream_t *Dir, MainParam_t *mp, const char *filename)
-{
-	unix_dir_loop(Dir, mp);
-	return GOT_ONE;
-}
-
-int unix_loop(Stream_t *Stream, MainParam_t *mp, char *arg, int follow_dir_link)
-{
-	int ret;
-	int isdir;
-
-	mp->File = NULL;
-	mp->direntry = NULL;
-	mp->unixSourceName = arg;
-	/*	mp->dir.attr = ATTR_ARCHIVE;*/
-	mp->loop = _unix_loop;
-	if((mp->lookupflags & DO_OPEN)){
-		mp->File = SimpleFileOpen(0, 0, arg, O_RDONLY, 0, 0, 0, 0);
-		if(!mp->File){
-			perror(arg);
-#if 0
-			tmp = _basename(arg);
-			strncpy(mp->filename, tmp, VBUFSIZE);
-			mp->filename[VBUFSIZE-1] = '\0';
-#endif
-			return ERROR_ONE;
-		}
-		GET_DATA(mp->File, 0, 0, &isdir, 0);
-		if(isdir) {
-			struct stat buf;
-
-			FREE(&mp->File);
-#ifdef S_ISLNK
-			if(!follow_dir_link &&
-			   lstat(arg, &buf) == 0 &&
-			   S_ISLNK(buf.st_mode)) {
-				/* skip links to directories in order to avoid
-				 * infinite loops */
-				fprintf(stderr, 
-					"skipping directory symlink %s\n", 
-					arg);
-				return 0;				
-			}
-#endif
-			if(! (mp->lookupflags & ACCEPT_DIR))
-				return 0;
-			mp->File = OpenDir(Stream, arg);
-		}
-	}
-
-	if(isdir)
-		ret = mp->dirCallback(0, mp);
-	else
-		ret = mp->unixcallback(mp);
-	FREE(&mp->File);
-	return ret;
-}
-
-
-int isSpecial(const char *name)
-{
-	if(name[0] == '\0')
-		return 1;
-	if(!strcmp(name,"."))
-		return 1;
-	if(!strcmp(name,".."))
-		return 1;
-	return 0;			
-}
-
-
-static int checkForDot(int lookupflags, const char *name)
-{
-	return (lookupflags & NO_DOTS) && isSpecial(name);
-}
-
-
-typedef struct lookupState_t {
-	Stream_t *container;
-	int nbContainers;
-	Stream_t *Dir;
-	int nbDirs;
-	const char *filename;
-} lookupState_t;
-
-static int isUniqueTarget(const char *name)
-{
-	return name && strcmp(name, "-");
-}
-
-static int handle_leaf(direntry_t *direntry, MainParam_t *mp,
-		       lookupState_t *lookupState)
-{
-	Stream_t *MyFile=0;
-	int ret;
-
-	if(got_signal)
-		return ERROR_ONE;
-	if(lookupState) {
-		/* we are looking for a "target" file */
-		switch(lookupState->nbDirs) {
-			case 0: /* no directory yet, open it */
-				lookupState->Dir = OpenFileByDirentry(direntry);
-				lookupState->nbDirs++;
-				/* dump the container, we have
-				 * better now */
-				FREE(&lookupState->container);
-				return 0;
-			case 1: /* we have already a directory */
-				FREE(&lookupState->Dir);
-				fprintf(stderr,"Ambigous\n");
-				return STOP_NOW | ERROR_ONE;
-			default:
-				return STOP_NOW | ERROR_ONE;
-		}
-	}
-
-	mp->direntry = direntry;
-	if(IS_DIR(direntry)) {
-		if(mp->lookupflags & (DO_OPEN | DO_OPEN_DIRS))
-			MyFile = mp->File = OpenFileByDirentry(direntry);
-		ret = mp->dirCallback(direntry, mp);
-	} else {
-		if(mp->lookupflags & DO_OPEN)
-			MyFile = mp->File = OpenFileByDirentry(direntry);
-		ret = mp->callback(direntry, mp);
-	}
-	FREE(&MyFile);
-	if(isUniqueTarget(mp->targetName))
-		ret |= STOP_NOW;
-	return ret;
-}
-
-static int _dos_loop(Stream_t *Dir, MainParam_t *mp, const char *filename)
-{	
-	Stream_t *MyFile=0;
-	direntry_t entry;
-	int ret;
-	int r;
-	
-	ret = 0;
-	r=0;
-	initializeDirentry(&entry, Dir);
-	while(!got_signal &&
-	      (r=vfat_lookup(&entry, filename, -1,
-			     mp->lookupflags, mp->shortname, 
-			     mp->longname)) == 0 ){
-		mp->File = NULL;
-		if(!checkForDot(mp->lookupflags,entry.name)) {
-			MyFile = 0;
-			if((mp->lookupflags & DO_OPEN) ||
-			   (IS_DIR(&entry) && 
-			    (mp->lookupflags & DO_OPEN_DIRS))) {
-				MyFile = mp->File = OpenFileByDirentry(&entry);
-			}
-			if(got_signal)
-				break;
-			mp->direntry = &entry;
-			if(IS_DIR(&entry))
-				ret |= mp->dirCallback(&entry,mp);
-			else
-				ret |= mp->callback(&entry, mp);
-			FREE(&MyFile);
-		}
-		if (fat_error(Dir))
-			ret |= ERROR_ONE;
-		if(mp->fast_quit && (ret & ERROR_ONE))
-			break;
-	}
-	if (r == -2)
-	    return ERROR_ONE;
-	if(got_signal)
-		ret |= ERROR_ONE;
-	return ret;
-}
-
-static int recurs_dos_loop(MainParam_t *mp, const char *filename0, 
-			   const char *filename1,
-			   lookupState_t *lookupState)
-{
-	/* Dir is de-allocated by the same entity which allocated it */
-	const char *ptr;
-	direntry_t entry;
-	int length;
-	int lookupflags;
-	int ret;
-	int have_one;
-	int doing_mcwd;
-	int r;
-
-	while(1) {
-		/* strip dots and // */
-		if(!strncmp(filename0,"./", 2)) {
-			filename0 += 2;
-			continue;
-		}
-		if(!strcmp(filename0,".") && filename1) {
-			filename0 ++;
-			continue;
-		}
-		if(filename0[0] == '/') {
-			filename0++;
-			continue;
-		}
-		if(!filename0[0]) {
-			if(!filename1)
-				break;
-			filename0 = filename1;
-			filename1 = 0;
-			continue;
-		}
-		break;
-	}
-
-	if(!strncmp(filename0,"../", 3) || 
-	   (!strcmp(filename0, "..") && filename1)) {
-		/* up one level */
-		mp->File = getDirentry(mp->File)->Dir;
-		return recurs_dos_loop(mp, filename0+2, filename1, lookupState);
-	}
-
-	doing_mcwd = !!filename1;
-
-	ptr = strchr(filename0, '/');
-	if(!ptr) {			
-		length = strlen(filename0);		
-		ptr = filename1;
-		filename1 = 0;
-	} else {
-		length = ptr - filename0;
-		ptr++;
-	}
-	if(!ptr) {
-		if(mp->lookupflags & OPEN_PARENT) {
-			mp->targetName = filename0;
-			ret = handle_leaf(getDirentry(mp->File), mp, 
-					  lookupState);
-			mp->targetName = 0;
-			return ret;
-		}
-		
-		if(!strcmp(filename0, ".") || !filename0[0]) {
-			return handle_leaf(getDirentry(mp->File), 
-					   mp, lookupState);
-		}
-
-		if(!strcmp(filename0, "..")) {
-			return handle_leaf(getParent(getDirentry(mp->File)), mp,
-					   lookupState);
-		}
-
-		lookupflags = mp->lookupflags;
-		
-		if(lookupState) {
-			lookupState->filename = filename0;
-			if(lookupState->nbContainers + lookupState->nbDirs > 0){
-				/* we have already one target, don't bother 
-				 * with this one. */
-				FREE(&lookupState->container);
-			} else {
-				/* no match yet.  Remember this container for 
-				 * later use */
-				lookupState->container = COPY(mp->File);
-			}
-			lookupState->nbContainers++;
-		}
-	} else
-		lookupflags = ACCEPT_DIR | DO_OPEN | NO_DOTS;
-
-	ret = 0;
-	r = 0;
-	have_one = 0;
-	initializeDirentry(&entry, mp->File);
-	while(!(ret & STOP_NOW) &&
-	      !got_signal &&
-	      (r=vfat_lookup(&entry, filename0, length,
-			     lookupflags | NO_MSG, 
-			     mp->shortname, mp->longname)) == 0 ){
-		if(checkForDot(lookupflags, entry.name))
-			/* while following the path, ignore the
-			 * special entries if they were not
-			 * explicitly given */
-			continue;
-		have_one = 1;
-		if(ptr) {
-			Stream_t *SubDir;
-			SubDir = mp->File = OpenFileByDirentry(&entry);
-			ret |= recurs_dos_loop(mp, ptr, filename1, lookupState);
-			FREE(&SubDir);
-		} else {
-			ret |= handle_leaf(&entry, mp, lookupState);
-			if(isUniqueTarget(mp->targetName))
-				return ret | STOP_NOW;
-		}
-		if(doing_mcwd)
-			break;
-	}
-	if (r == -2)
-		return ERROR_ONE;
-	if(got_signal)
-		return ret | ERROR_ONE;
-	if(doing_mcwd & !have_one)
-		return NO_CWD;
-	return ret;
-}
-
-static int common_dos_loop(MainParam_t *mp, const char *pathname,
-			   lookupState_t *lookupState, int open_mode)
-
-{
-	Stream_t *RootDir;
-	char *cwd;
-	char *drive;
-	char *rest;
-
-	int ret;
-	mp->loop = _dos_loop;
-	
-	drive='\0';
-	cwd = "";
-	if((rest = skip_drive(pathname)) > pathname) {
-		drive = get_drive(pathname, NULL);
-		if (strncmp(pathname, mp->mcwd, rest - pathname) == 0)
-			cwd = skip_drive(mp->mcwd);
-		pathname = rest;
-	} else {
-		drive = get_drive(mp->mcwd, NULL);
-		cwd = skip_drive(mp->mcwd);
-	}
-
-	if(*pathname=='/') /* absolute path name */
-		cwd = "";
-
-	RootDir = mp->File = open_root_dir(drive, open_mode);
-	if(!mp->File)
-		return ERROR_ONE;
-
-	ret = recurs_dos_loop(mp, cwd, pathname, lookupState);
-	if(ret & NO_CWD) {
-		/* no CWD */
-		*mp->mcwd = '\0';
-		unlink_mcwd();
-		ret = recurs_dos_loop(mp, "", pathname, lookupState);
-	}
-	FREE(&RootDir);
-	return ret;
-}
-
-static int dos_loop(MainParam_t *mp, const char *arg)
-{
-	return common_dos_loop(mp, arg, 0, mp->openflags);
-}
-
-
-static int dos_target_lookup(MainParam_t *mp, const char *arg)
-{
-	lookupState_t lookupState;
-	int ret;
-	int lookupflags;
-
-	lookupState.nbDirs = 0;
-	lookupState.Dir = 0;
-	lookupState.nbContainers = 0;
-	lookupState.container = 0;
-
-	lookupflags = mp->lookupflags;
-	mp->lookupflags = DO_OPEN | ACCEPT_DIR;
-	ret = common_dos_loop(mp, arg, &lookupState, O_RDWR);
-	mp->lookupflags = lookupflags;
-	if(ret & ERROR_ONE)
-		return ret;
-
-	if(lookupState.nbDirs) {
-		mp->targetName = 0;
-		mp->targetDir = lookupState.Dir;
-		FREE(&lookupState.container); /* container no longer needed */
-		return ret;
-	}
-
-	switch(lookupState.nbContainers) {
-		case 0:
-			/* no match */
-			fprintf(stderr,"%s: no match for target\n", arg);
-			return MISSED_ONE;
-		case 1:
-			mp->targetName = strdup(lookupState.filename);
-			mp->targetDir = lookupState.container;
-			return ret;
-		default:
-			/* too much */
-			fprintf(stderr, "Ambigous %s\n", arg);
-			return ERROR_ONE;			
-	}
-}
-
-int unix_target_lookup(MainParam_t *mp, const char *arg)
-{
-	char *ptr;
-	mp->unixTarget = strdup(arg);
-	/* try complete filename */
-	if(access(mp->unixTarget, F_OK) == 0)
-		return GOT_ONE;
-	ptr = strrchr(mp->unixTarget, '/');
-	if(!ptr) {
-		mp->targetName = mp->unixTarget;
-		mp->unixTarget = strdup(".");
-		return GOT_ONE;
-	} else {
-		*ptr = '\0';
-		mp->targetName = ptr+1;
-		return GOT_ONE;
-	}
-}
-
-int target_lookup(MainParam_t *mp, const char *arg)
-{
-	if((mp->lookupflags & NO_UNIX) || skip_drive(arg) > arg)
-		return dos_target_lookup(mp, arg);
-	else
-		return unix_target_lookup(mp, arg);
-}
-
-int main_loop(MainParam_t *mp, char **argv, int argc)
-{
-	int i;
-	int ret, Bret;
-	
-	Bret = 0;
-
-	if(argc != 1 && mp->targetName) {
-		fprintf(stderr,
-			"Several file names given, but last argument (%s) not a directory\n", mp->targetName);
-	}
-
-	for (i = 0; i < argc; i++) {
-		if ( got_signal )
-			break;
-		mp->originalArg = argv[i];
-		mp->basenameHasWildcard = strpbrk(_basename(mp->originalArg), 
-						  "*[?") != 0;
-		if (mp->unixcallback && skip_drive(argv[i]) == argv[i])
-			ret = unix_loop(0, mp, argv[i], 1);
-		else
-			ret = dos_loop(mp, argv[i]);
-		
-		if (! (ret & (GOT_ONE | ERROR_ONE)) ) {
-			/* one argument was unmatched */
-			fprintf(stderr, "%s: File \"%s\" not found\n",
-				progname, argv[i]);
-			ret |= ERROR_ONE;
-		}
-		Bret |= ret;
-		if(mp->fast_quit && (Bret & (MISSED_ONE | ERROR_ONE)))
-			break;
-	}
-	FREE(&mp->targetDir);
-	if(Bret & ERROR_ONE)
-		return 1;
-	if ((Bret & GOT_ONE) && ( Bret & MISSED_ONE))
-		return 2;
-	if (Bret & MISSED_ONE)
-		return 1;
-	return 0;
-}
-
-static int dispatchToFile(direntry_t *entry, MainParam_t *mp)
-{
-	if(entry)
-		return mp->callback(entry, mp);
-	else
-		return mp->unixcallback(mp);
-}
-
-
-void init_mp(MainParam_t *mp)
-{
-	fix_mcwd(mp->mcwd);
-	mp->openflags = 0;
-	mp->targetName = 0;
-	mp->targetDir = 0;
-	mp->unixTarget = 0;
-	mp->dirCallback = dispatchToFile;
-	mp->unixcallback = NULL;
-	mp->shortname = mp->longname = 0;
-	mp->File = 0;
-	mp->fast_quit = 0;
-}
-
-const char *mpGetBasename(MainParam_t *mp)
-{
-	if(mp->direntry)
-		return mp->direntry->name;
-	else
-		return _basename(mp->unixSourceName);
-}
-
-void mpPrintFilename(FILE *fp, MainParam_t *mp)
-{
-	if(mp->direntry)
-		fprintPwd(fp, mp->direntry, 0);
-	else
-		fprintf(fp,"%s",mp->originalArg);
-}
-
-const char *mpPickTargetName(MainParam_t *mp)
-{
-	/* picks the target name: either the one explicitly given by the
-	 * user, or the same as the source */
-	if(mp->targetName)
-		return mp->targetName;
-	else
-		return mpGetBasename(mp);
-}
-
-char *mpBuildUnixFilename(MainParam_t *mp)
-{
-	const char *target;
-	char *ret;
-
-	target = mpPickTargetName(mp);
-	ret = malloc(strlen(mp->unixTarget) + 2 + strlen(target));
-	if(!ret)
-		return 0;
-	strcpy(ret, mp->unixTarget);
-	if(*target) {
-#if 1 /* fix for 'mcopy -n x:file existingfile' -- H. Lermen 980816 */
-		if(!mp->targetName && !mp->targetDir) {
-			struct stat buf;
-			if (!stat(ret, &buf) && !S_ISDIR(buf.st_mode))
-				return ret;
-		}
-#endif
-		strcat(ret, "/");
-		strcat(ret, target);
-	}
-	return ret;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mainloop.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mainloop.h	(revision 9)
+++ 	(revision )
@@ -1,79 +1,0 @@
-#ifndef MTOOLS_MAINLOOP_H
-#define MTOOLS_MAINLOOP_H
-
-#ifndef OS_Minix
-#include <sys/param.h>
-#endif
-#include "vfat.h"
-#include "mtoolsDirent.h"
-
-typedef struct MainParam_t {
-	/* stuff needing to be initialised by the caller */
-	int (*loop)(Stream_t *Dir, struct MainParam_t *mp, 
-		    const char *filename);
-	int (*dirCallback)(direntry_t *, struct MainParam_t *);
-	int (*callback)(direntry_t *, struct MainParam_t *);
-	int (*unixcallback)(struct MainParam_t *mp);
-
-	void *arg; /* command-specific parameters 
-		    * to be passed to callback */
-
-       	int openflags; /* flags used to open disk */
-	int lookupflags; /* flags used to lookup up using vfat_lookup */
-	int fast_quit; /* for commands manipulating multiple files, quit
-			* as soon as even _one_ file has a problem */
-
-	char *shortname; /* where to put the short name of the matched file */
-	char *longname; /* where to put the long name of the matched file */
-
-	/* out parameters */
-	Stream_t *File;
-
-	direntry_t *direntry;  /* dir of this entry */
-	char *unixSourceName;  /* filename of the last opened Unix source 
-				* file (Unix equiv of Dos direntry) */
-
-	Stream_t *targetDir; /* directory where to place files */
-	char *unixTarget; /* directory on Unix where to put files */
-
-	const char *targetName; /* basename of target file, or NULL if same
-				 * basename as source should be conserved */
-
-	char *originalArg; /* original argument, complete with wildcards */
-	int basenameHasWildcard; /* true if there are wildcards in the
-				  * basename */
-
-
-	/* internal data */
-	char mcwd[MAX_PATH+4];
-
-	char *fileName; /* resolved Unix filename */
-} MainParam_t;
-
-void init_mp(MainParam_t *MainParam);
-int main_loop(MainParam_t *MainParam, char **argv, int argc);
-
-int target_lookup(MainParam_t *mp, const char *arg);
-
-Stream_t *open_root_dir(char *drivename, int flags);
-
-const char *mpGetBasename(MainParam_t *mp); /* statically allocated 
-					     * string */
-
-void mpPrintFilename(FILE *file, MainParam_t *mp);
-const char *mpPickTargetName(MainParam_t *mp); /* statically allocated string */
-
-char *mpBuildUnixFilename(MainParam_t *mp); /* dynamically allocated, must
-					     * be freed */
-
-int isSpecial(const char *name);
-
-#define MISSED_ONE 2  /* set if one cmd line argument didn't match any files */
-#define GOT_ONE 4     /* set if a match was found, used for exit status */
-#define NO_CWD 8     /* file not found while looking for current working 
-		      * directory */
-#define ERROR_ONE 16 /* flat out error, such as problems with target file, 
-			interrupt by user, etc. */
-#define STOP_NOW 32 /* stop as soon as possible, not necessarily an error */
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/match.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/match.c	(revision 9)
+++ 	(revision )
@@ -1,142 +1,0 @@
-/*
- * Do shell-style pattern matching for '?', '\', '[..]', and '*' wildcards.
- * Returns 1 if match, 0 if not.
- */
-
-#include "sysincludes.h"
-#include "mtools.h"
-
-
-static int casecmp(char a,char b)
-{
-	return toupper(a) == toupper(b);
-}
-
-static int exactcmp(char a,char b)
-{
-	return a == b;
-}
-
-
-static int parse_range(const char **p, const char *s, char *out, 
-		       int (*compfn)(char a, char b))
-{
-	char table[256];
-	int reverse;
-	int i;
-	short first, last;
-
-	if (**p == '^') {
-		reverse = 1;
-		(*p)++;
-	} else
-		reverse=0;	
-	for(i=0; i<256; i++)
-		table[i]=0;
-	while(**p != ']') {
-		if(!**p)
-			return 0;
-		if((*p)[1] == '-') {
-			first = **p;
-			(*p)+=2;
-			if(**p == ']')
-				last = 256;
-			else
-				last = *((*p)++);				
-			for(i=first; i<last; i++)
-				table[i] = 1;
-		} else
-			table[(int) *((*p)++)] = 1;
-	}
-	if(out)
-		*out = *s;
-	if(table[(int) *s])
-		return 1 ^ reverse;
-	if(compfn == exactcmp)
-		return reverse;
-	if(table[tolower(*s)]) {
-		if(out)
-			*out = tolower(*s);
-		return 1 ^ reverse;
-	}
-	if(table[toupper(*s)]) {
-		if(out)
-			*out = toupper(*s);
-		return 1 ^ reverse;
-	}
-	return reverse;
-}
-
-
-static int _match(const char *s, const char *p, char *out, int Case,
-		  int length,
-		  int (*compfn) (char a, char b))
-{
-	for (; *p != '\0' && length; ) {
-		switch (*p) {
-			case '?':	/* match any one character */
-				if (*s == '\0')
-					return(0);
-				if(out)
-					*(out++) = *s;
-				break;
-			case '*':	/* match everything */
-				while (*p == '*' && length) {
-					p++;
-					length--;
-				}
-
-					/* search for next char in pattern */
-				while(*s) {
-					if(_match(s, p, out, Case, length, 
-						  compfn))
-						return 1;
-					if(out)
-						*out++ = *s;
-					s++;
-				}
-				continue;
-			case '[':	 /* match range of characters */
-				p++;
-				length--;
-				if(!parse_range(&p, s, out++, compfn))
-					return 0;
-				break;
-			case '\\':	/* Literal match with next character */
-				p++;
-				length--;
-				/* fall thru */
-			default:
-				if (!compfn(*s,*p))
-					return(0);
-				if(out)
-					*(out++) = *p;
-				break;
-		}
-		p++;
-		length--;
-		s++;
-	}
-	if(out)
-		*out = '\0';
-
-					/* string ended prematurely ? */
-	if (*s != '\0')
-		return(0);
-	else
-		return(1);
-}
-
-
-int match(const char *s, const char *p, char *out, int Case, int length)
-{
-	int (*compfn)(char a, char b);
-
-	if(Case)
-		compfn = casecmp;
-	else
-		/*compfn = exactcmp;*/
-		compfn = casecmp;
-	return _match(s, p, out, Case, length, compfn);
-}
-
Index: trunk/minix/commands/i386/mtools-3.9.7/mattrib.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mattrib.c	(revision 9)
+++ 	(revision )
@@ -1,233 +1,0 @@
-/*
- * mattrib.c
- * Change MSDOS file attribute flags
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "mainloop.h"
-
-typedef struct Arg_t {
-	char add;
-	unsigned char remove;
-	struct MainParam_t mp;
-	int recursive;
-	int doPrintName;
-} Arg_t;
-
-int concise;
-
-static int attrib_file(direntry_t *entry, MainParam_t *mp)
-{
-	Arg_t *arg=(Arg_t *) mp->arg;
-
-	if(entry->entry != -3) {
-		/* if not root directory, change it */
-		entry->dir.attr = (entry->dir.attr & arg->remove) | arg->add;
-		dir_write(entry);
-	}
-	return GOT_ONE;
-}
-
-static int replay_attrib(direntry_t *entry, MainParam_t *mp)
-{
-	if ( (IS_ARCHIVE(entry) && IS_DIR(entry)) ||
-		 (!IS_ARCHIVE(entry) && !IS_DIR(entry)) ||
-		 IS_SYSTEM(entry) || IS_HIDDEN(entry)) {
-
-		printf("mattrib ");
-
-		if (IS_ARCHIVE(entry) && IS_DIR(entry)) {
-			printf("+a ");
-		}
-
-		if (!IS_ARCHIVE(entry) && !IS_DIR(entry)) {
-			printf("-a ");
-		}
-
-		if (IS_SYSTEM(entry)) {
-			printf("+s ");
-		}
-
-		if (IS_HIDDEN(entry)) {
-			printf("+h ");
-		}
-
-		fprintPwd(stdout, entry, 1);
-		printf("\n");
-	}
-	return GOT_ONE;
-}
-
-
-
-static int view_attrib(direntry_t *entry, MainParam_t *mp)
-{
-	printf("  ");
-	if(IS_ARCHIVE(entry))
-		putchar('A');
-	else
-		putchar(' ');
-	fputs("  ",stdout);
-	if(IS_SYSTEM(entry))
-		putchar('S');
-	else
-		putchar(' ');
-	if(IS_HIDDEN(entry))
-		putchar('H');
-	else
-		putchar(' ');
-	if(IS_READONLY(entry))
-		putchar('R');
-	else
-		putchar(' ');
-	printf("     ");
-	fprintPwd(stdout, entry, 0);
-	printf("\n");
-	return GOT_ONE;
-}
-
-
-static int concise_view_attrib(direntry_t *entry, MainParam_t *mp)
-{
-	Arg_t *arg=(Arg_t *) mp->arg;
-
-	if(IS_ARCHIVE(entry))
-		putchar('A');
-	if(IS_DIR(entry))
-		putchar('D');	
-	if(IS_SYSTEM(entry))
-		putchar('S');
-	if(IS_HIDDEN(entry))
-		putchar('H');
-	if(IS_READONLY(entry))
-		putchar('R');
-	if(arg->doPrintName) {
-		putchar(' ');
-		fprintPwd(stdout, entry, 0);
-	}
-	putchar('\n');
-	return GOT_ONE;
-}
-
-static int recursive_attrib(direntry_t *entry, MainParam_t *mp)
-{
-	mp->callback(entry, mp);
-	return mp->loop(mp->File, mp, "*");
-}
-
-
-static void usage(void) NORETURN;
-static void usage(void)
-{
-	fprintf(stderr, "Mtools version %s, dated %s\n", 
-		mversion, mdate);
-	fprintf(stderr, 
-		"Usage: %s [-p/X] [-a|+a] [-h|+h] [-r|+r] [-s|+s] msdosfile [msdosfiles...]\n"
-		"\t-p Replay how mattrib would set up attributes\n"
-		"\t-/ Recursive\n"
-		"\t-X Concise\n",
-		progname);
-	exit(1);
-}
-
-static int letterToCode(int letter)
-{
-	switch (toupper(letter)) {
-		case 'A':
-			return ATTR_ARCHIVE;
-		case 'H':
-			return ATTR_HIDDEN;
-		case 'R':
-			return ATTR_READONLY;
-		case 'S':
-			return ATTR_SYSTEM;
-		default:
-			usage();
-	}
-}
-
-
-void mattrib(int argc, char **argv, int type)
-{
-	Arg_t arg;
-	int view;
-	int c;
-	int concise;
-	int replay;
-	char *ptr;
-
-	arg.add = 0;
-	arg.remove = 0xff;
-	arg.recursive = 0;
-	arg.doPrintName = 1;
-	view = 0;
-	concise = 0;
-	replay = 0;
-	
-	while ((c = getopt(argc, argv, "/ahrsAHRSXp")) != EOF) {
-		switch (c) {
-			default:
-				arg.remove &= ~letterToCode(c);
-				break;
-			case 'p':
-				replay = 1;
-				break;
-			case '/':
-				arg.recursive = 1;
-				break;
-			case 'X':
-				concise = 1;
-				break;
-			case '?':
-				usage();
-		}
-	}
-
-	for(;optind < argc;optind++) {
-		switch(argv[optind][0]) {
-			case '+':
-				for(ptr = argv[optind] + 1; *ptr; ptr++)
-					arg.add |= letterToCode(*ptr);
-				continue;
-			case '-':
-				for(ptr = argv[optind] + 1; *ptr; ptr++)
-					arg.remove &= ~letterToCode(*ptr);
-				continue;
-		}
-		break;
-	}
-
-	if(arg.remove == 0xff && !arg.add)
-		view = 1;
-
-	if (optind >= argc)
-		usage();
-
-	init_mp(&arg.mp);
-	if(view){
-		if(concise) {
-			arg.mp.callback = concise_view_attrib;
-			arg.doPrintName = (argc - optind > 1 ||
-					   arg.recursive ||
-					   strpbrk(argv[optind], "*[?") != 0);
-		} else if (replay) {
-			arg.mp.callback = replay_attrib;
-		} else
-			arg.mp.callback = view_attrib;
-		arg.mp.openflags = O_RDONLY;
-	} else {
-		arg.mp.callback = attrib_file;
-		arg.mp.openflags = O_RDWR;
-	}
-
-	if(arg.recursive)
-		arg.mp.dirCallback = recursive_attrib;
-
-	arg.mp.arg = (void *) &arg;
-	arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR;
-	if(arg.recursive)
-		arg.mp.lookupflags |= DO_OPEN_DIRS | NO_DOTS;
-	exit(main_loop(&arg.mp, argv + optind, argc - optind));
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mbadblocks.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mbadblocks.c	(revision 9)
+++ 	(revision )
@@ -1,77 +1,0 @@
-/*
- * mbadblocks.c
- * Mark bad blocks on disk
- *
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "mainloop.h"
-#include "fsP.h"
-
-void mbadblocks(int argc, char **argv, int type)
-{
-	int i;
-	char *in_buf;
-	int in_len;
-	off_t start;
-	struct MainParam_t mp;
-	Fs_t *Fs;
-	Stream_t *Dir;
-	int ret;
-
-	if (argc != 2 || skip_drive(argv[1]) == argv[1]) {
-		fprintf(stderr, "Mtools version %s, dated %s\n", 
-			mversion, mdate);
-		fprintf(stderr, "Usage: %s drive:\n", argv[0]);
-		exit(1);
-	}
-
-	init_mp(&mp);
-
-	Dir = open_root_dir(get_drive(argv[1], NULL), O_RDWR);
-	if (!Dir) {
-		fprintf(stderr,"%s: Cannot initialize drive\n", argv[0]);
-		exit(1);
-	}
-
-	Fs = (Fs_t *)GetFs(Dir);
-	in_len = Fs->cluster_size * Fs->sector_size;
-	in_buf = malloc(in_len);
-	if(!in_buf) {
-		FREE(&Dir);
-		printOom();
-		exit(1);
-	}
-	for(i=0; i < Fs->clus_start; i++ ){
-		ret = READS(Fs->Next, 
-					in_buf, sectorsToBytes((Stream_t*)Fs, i), Fs->sector_size);
-		if( ret < 0 ){
-			perror("early error");
-			exit(1);
-		}
-		if(ret < Fs->sector_size){
-			fprintf(stderr,"end of file in file_read\n");
-			exit(1);
-		}
-	}
-		
-	in_len = Fs->cluster_size * Fs->sector_size;
-	for(i=2; i< Fs->num_clus + 2; i++){
-		if(got_signal)
-			break;
-		if(Fs->fat_decode((Fs_t*)Fs,i))
-			continue;
-		start = (i - 2) * Fs->cluster_size + Fs->clus_start;
-		ret = force_read(Fs->Next, in_buf, 
-						 sectorsToBytes((Stream_t*)Fs, start), in_len);
-		if(ret < in_len ){
-			printf("Bad cluster %d found\n", i);
-			fatEncode((Fs_t*)Fs, i, 0xfff7);
-			continue;
-		}
-	}
-	FREE(&Dir);
-	exit(0);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mcat.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mcat.c	(revision 9)
+++ 	(revision )
@@ -1,129 +1,0 @@
-/*
- * mcat.c
- * Same thing as cat /dev/fd0 or cat file >/dev/fd0
- * Something, that isn't possible with floppyd anymore.
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "mainloop.h"
-#include "fsP.h"
-#include "xdf_io.h"
-#include "floppyd_io.h"
-#include "plain_io.h"
-
-void usage(void) 
-{
-	fprintf(stderr, "Mtools version %s, dated %s\n", 
-		mversion, mdate);
-	fprintf(stderr, "Usage: mcat [-w] device\n");
-	fprintf(stderr, "       -w write on device else read\n");
-	exit(1);
-}
-
-#define BUF_SIZE 16000
-
-void mcat(int argc, char **argv, int type)
-{
-	struct device *dev;
-	struct device out_dev;
-	char *drive, name[EXPAND_BUF];
-        char errmsg[200];
-        Stream_t *Stream;
-	char buf[BUF_SIZE];
-
-	mt_off_t address = 0;
-
-	char mode = O_RDONLY;
-	int optindex = 1;
-	size_t len;
-
-	noPrivileges = 1;
-
-	if (argc < 2) {
-		usage();
-	}
-
-	if (argv[1][0] == '-') {
-		if (argv[1][1] != 'w') {
-			usage();
-		}
-		mode = O_WRONLY;
-		optindex++;
-	}
-
-	if (argc - optindex < 1)
-		usage();
-
-
-	if (skip_drive(argv[optindex]) == argv[optindex])
-		usage();
-
-        drive = get_drive(argv[optindex], NULL);
-
-        /* check out a drive whose letter and parameters match */       
-        sprintf(errmsg, "Drive '%s:' not supported", drive);    
-        Stream = NULL;
-        for (dev=devices; dev->name; dev++) {
-                FREE(&Stream);
-                if (strcmp(dev->drive, drive) != 0)
-                        continue;
-                out_dev = *dev;
-                expand(dev->name,name);
-#ifdef USING_NEW_VOLD
-                strcpy(name, getVoldName(dev, name));
-#endif
-
-                Stream = 0;
-#ifdef USE_XDF
-                Stream = XdfOpen(&out_dev, name, mode, errmsg, 0);
-				if(Stream)
-                        out_dev.use_2m = 0x7f;
-
-#endif
-
-#ifdef USE_FLOPPYD
-                if(!Stream)
-                        Stream = FloppydOpen(&out_dev, dev, name, 
-					     mode, errmsg, 0, 1);
-#endif
-
-
-                if (!Stream)
-                        Stream = SimpleFileOpen(&out_dev, dev, name, mode,
-						errmsg, 0, 1, 0);
-
-                if( !Stream)
-                        continue;
-                break;
-        }
-
-        /* print error msg if needed */ 
-        if ( dev->drive == 0 ){
-                FREE(&Stream);
-                fprintf(stderr,"%s\n",errmsg);
-                exit(1);
-        }
-
-	if (mode == O_WRONLY) {
-		while ((len = fread(buf, 1, BUF_SIZE, stdin)) 
-		       == BUF_SIZE) {
-			WRITES(Stream, buf, address, BUF_SIZE);
-			address += BUF_SIZE;
-		}
-		if (len)
-			WRITES(Stream, buf, address, len);
-	} else {
-		while ((len = READS(Stream, buf, address, BUF_SIZE)) 
-		       == BUF_SIZE) {
-			fwrite(buf, 1, BUF_SIZE, stdout);
-			address += BUF_SIZE;
-		}
-		if (len)
-			fwrite(buf, 1, len, stdout);
-	}
-
-	FREE(&Stream);
-	exit(0);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mcd.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mcd.c	(revision 9)
+++ 	(revision )
@@ -1,46 +1,0 @@
-/*
- * mcd.c: Change MSDOS directories
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mainloop.h"
-#include "mtools.h"
-
-
-static int mcd_callback(direntry_t *entry, MainParam_t *mp)
-{
-	FILE *fp;
-
-	if (!(fp = open_mcwd("w"))){
-		fprintf(stderr,"mcd: Can't open mcwd .file for writing\n");
-		return ERROR_ONE;
-	}
-	
-	fprintPwd(fp, entry,0);
-	fprintf(fp, "\n");
-	fclose(fp);
-	return GOT_ONE | STOP_NOW;
-}
-
-
-void mcd(int argc, char **argv, int type)
-{
-	struct MainParam_t mp;
-
-	if (argc > 2) {
-		fprintf(stderr, "Mtools version %s, dated %s\n", 
-			mversion, mdate);
-		fprintf(stderr, "Usage: %s: msdosdirectory\n", argv[0]);
-		exit(1);
-	}
-
-	init_mp(&mp);
-	mp.lookupflags = ACCEPT_DIR | NO_DOTS;
-	mp.dirCallback = mcd_callback;
-	if (argc == 1) {
-		printf("%s\n", mp.mcwd);
-		exit(0);
-	} else 
-		exit(main_loop(&mp, argv + 1, 1));
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mcopy.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mcopy.c	(revision 9)
+++ 	(revision )
@@ -1,584 +1,0 @@
-/*
- * mcopy.c
- * Copy an MSDOS files to and from Unix
- *
- */
-
-
-#define LOWERCASE
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "mainloop.h"
-#include "plain_io.h"
-#include "nameclash.h"
-#include "file.h"
-#include "fs.h"
-
-
-/*
- * Preserve the file modification times after the fclose()
- */
-
-static void set_mtime(const char *target, time_t mtime)
-{
-	if (target && strcmp(target, "-") && mtime != 0L) {
-#ifdef HAVE_UTIMES
-		struct timeval tv[2];	
-		tv[0].tv_sec = mtime;
-		tv[0].tv_usec = 0;
-		tv[1].tv_sec = mtime;
-		tv[1].tv_usec = 0;
-		utimes((char *)target, tv);
-#else
-#ifdef HAVE_UTIME
-		struct utimbuf utbuf;
-
-		utbuf.actime = mtime;
-		utbuf.modtime = mtime;
-		utime(target, &utbuf);
-#endif
-#endif
-	}
-	return;
-}
-
-typedef struct Arg_t {
-	int recursive;
-	int preserveAttributes;
-	int preserveTime;
-	unsigned char attr;
-	char *path;
-	int textmode;
-	int needfilter;
-	int nowarn;
-	int verbose;
-	int type;
-	MainParam_t mp;
-	ClashHandling_t ch;
-} Arg_t;
-
-/* Write the Unix file */
-static int unix_write(direntry_t *entry, MainParam_t *mp, int needfilter)
-{
-	Arg_t *arg=(Arg_t *) mp->arg;
-	time_t mtime;
-	Stream_t *File=mp->File;
-	Stream_t *Target, *Source;
-	struct stat stbuf;
-	int ret;
-	char errmsg[80];
-	char *unixFile;
-
-	File->Class->get_data(File, &mtime, 0, 0, 0);
-
-	if (!arg->preserveTime)
-		mtime = 0L;
-
-	if(arg->type)
-		unixFile = "-";
-	else
-		unixFile = mpBuildUnixFilename(mp);
-	if(!unixFile) {
-		printOom();
-		return ERROR_ONE;
-	}
-
-	/* if we are creating a file, check whether it already exists */
-	if(!arg->type) {
-		if (!arg->nowarn && &arg->type && !access(unixFile, 0)){
-			if( ask_confirmation("File \"%s\" exists, overwrite (y/n) ? ",
-					     unixFile,0)) {
-				free(unixFile);
-				return ERROR_ONE;
-			}
-			
-			/* sanity checking */
-			if (!stat(unixFile, &stbuf) && !S_ISREG(stbuf.st_mode)) {
-				fprintf(stderr,"\"%s\" is not a regular file\n",
-					unixFile);
-				
-				free(unixFile);
-				return ERROR_ONE;
-			}
-		}
-	}
-
-	if(!arg->type && arg->verbose) {
-		fprintf(stderr,"Copying ");
-		mpPrintFilename(stderr,mp);
-		fprintf(stderr,"\n");
-	}
-	
-	if(got_signal) {
-		free(unixFile);
-		return ERROR_ONE;
-	}
-
-	if ((Target = SimpleFileOpen(0, 0, unixFile,
-				     O_WRONLY | O_CREAT | O_TRUNC,
-				     errmsg, 0, 0, 0))) {
-		ret = 0;
-		if(needfilter && arg->textmode){
-			Source = open_filter(COPY(File));
-			if (!Source)
-				ret = -1;
-		} else
-			Source = COPY(File);
-
-		if (ret == 0 )
-			ret = copyfile(Source, Target);
-		FREE(&Source);
-		FREE(&Target);
-		if(ret <= -1){
-			if(!arg->type) {
-				unlink(unixFile);
-				free(unixFile);
-			}
-			return ERROR_ONE;
-		}
-		if(!arg->type) {
-			set_mtime(unixFile, mtime);
-			free(unixFile);
-		}
-		return GOT_ONE;
-	} else {
-		fprintf(stderr,"%s\n", errmsg);
-		if(!arg->type)
-			free(unixFile);
-		return ERROR_ONE;
-	}
-}
-
-static int makeUnixDir(char *filename)
-{
-	if(!mkdir(filename, 0777))
-		return 0;
-	if(errno == EEXIST) {
-		struct stat buf;
-		if(stat(filename, &buf) < 0)
-			return -1;
-		if(S_ISDIR(buf.st_mode))
-			return 0;
-		errno = ENOTDIR;
-	}
-	return -1;
-}
-
-/* Copy a directory to Unix */
-static int unix_copydir(direntry_t *entry, MainParam_t *mp)
-{
-	Arg_t *arg=(Arg_t *) mp->arg;
-	time_t mtime;
-	Stream_t *File=mp->File;
-	int ret;
-	char *unixFile;
-
-	if (!arg->recursive && mp->basenameHasWildcard)
-		return 0;
-
-	File->Class->get_data(File, &mtime, 0, 0, 0);	
-	if (!arg->preserveTime)
-		mtime = 0L;
-	if(!arg->type && arg->verbose) {
-		fprintf(stderr,"Copying ");
-		fprintPwd(stderr, entry,0);
-		fprintf(stderr, "\n");
-	}
-	if(got_signal)
-		return ERROR_ONE;
-	unixFile = mpBuildUnixFilename(mp);
-	if(!unixFile) {
-		printOom();
-		return ERROR_ONE;
-	}
-	if(arg->type || !*mpPickTargetName(mp) || !makeUnixDir(unixFile)) {
-		Arg_t newArg;
-
-		newArg = *arg;
-		newArg.mp.arg = (void *) &newArg;
-		newArg.mp.unixTarget = unixFile;
-		newArg.mp.targetName = 0;
-		newArg.mp.basenameHasWildcard = 1;
-
-		ret = mp->loop(File, &newArg.mp, "*");
-		set_mtime(unixFile, mtime);
-		free(unixFile);
-		return ret | GOT_ONE;		
-	} else {
-		perror("mkdir");
-		fprintf(stderr, 
-			"Failure to make directory %s\n", 
-			unixFile);
-		free(unixFile);
-		return ERROR_ONE;
-	}
-}
-
-static  int dos_to_unix(direntry_t *entry, MainParam_t *mp)
-{
-	return unix_write(entry, mp, 1);
-}
-
-
-static  int unix_to_unix(MainParam_t *mp)
-{
-	return unix_write(0, mp, 0);
-}
-
-
-static int directory_dos_to_unix(direntry_t *entry, MainParam_t *mp)
-{
-	return unix_copydir(entry, mp);
-}
-
-/*
- * Open the named file for read, create the cluster chain, return the
- * directory structure or NULL on error.
- */
-static int writeit(char *dosname,
-		   char *longname,
-		   void *arg0,
-		   direntry_t *entry)
-{
-	Stream_t *Target;
-	time_t now;
-	int type, fat, ret;
-	time_t date;
-	mt_size_t filesize, newsize;
-	Arg_t *arg = (Arg_t *) arg0;
-
-
-
-	if (arg->mp.File->Class->get_data(arg->mp.File,
-									  & date, &filesize, &type, 0) < 0 ){
-		fprintf(stderr, "Can't stat source file\n");
-		return -1;
-	}
-
-	if (type){
-		if (arg->verbose)
-			fprintf(stderr, "\"%s\" is a directory\n", longname);
-		return -1;
-	}
-
-	/*if (!arg->single || arg->recursive)*/
-	if(arg->verbose)
-		fprintf(stderr,"Copying %s\n", longname);
-	if(got_signal)
-		return -1;
-
-	/* will it fit? */
-	if (!getfreeMinBytes(arg->mp.targetDir, filesize))
-		return -1;
-	
-	/* preserve mod time? */
-	if (arg->preserveTime)
-		now = date;
-	else
-		getTimeNow(&now);
-
-	mk_entry(dosname, arg->attr, 1, 0, now, &entry->dir);
-
-	Target = OpenFileByDirentry(entry);
-	if(!Target){
-		fprintf(stderr,"Could not open Target\n");
-		exit(1);
-	}
-	if (arg->needfilter & arg->textmode)
-		Target = open_filter(Target);
-
-
-
-	ret = copyfile(arg->mp.File, Target);
-	GET_DATA(Target, 0, &newsize, 0, &fat);
-	FREE(&Target);
-	if (arg->needfilter & arg->textmode)
-	    newsize++; /* ugly hack: we gathered the size before the Ctrl-Z
-			* was written.  Increment it manually */
-	if(ret < 0 ){
-		fat_free(arg->mp.targetDir, fat);
-		return -1;
-	} else {
-		mk_entry(dosname, arg->attr, fat, truncBytes32(newsize),
-				 now, &entry->dir);
-		return 0;
-	}
-}
-
-
-
-static int dos_write(direntry_t *entry, MainParam_t *mp, int needfilter)
-/* write a messy dos file to another messy dos file */
-{
-	int result;
-	Arg_t * arg = (Arg_t *) (mp->arg);
-	const char *targetName = mpPickTargetName(mp);
-
-	if(entry && arg->preserveAttributes)
-		arg->attr = entry->dir.attr;
-	else
-		arg->attr = ATTR_ARCHIVE;
-
-	arg->needfilter = needfilter;
-	if (entry && mp->targetDir == entry->Dir){
-		arg->ch.ignore_entry = -1;
-		arg->ch.source = entry->entry;
-	} else {
-		arg->ch.ignore_entry = -1;
-		arg->ch.source = -2;
-	}
-	result = mwrite_one(mp->targetDir, targetName, 0,
-			    writeit, (void *)arg, &arg->ch);
-	if(result == 1)
-		return GOT_ONE;
-	else
-		return ERROR_ONE;
-}
-
-static Stream_t *subDir(Stream_t *parent, const char *filename)
-{
-	direntry_t entry;		
-	initializeDirentry(&entry, parent);
-
-	switch(vfat_lookup(&entry, filename, -1, ACCEPT_DIR, 0, 0)) {
-	    case 0:
-		return OpenFileByDirentry(&entry);
-	    case -1:
-		return NULL;
-	    default: /* IO Error */
-		return NULL;
-	}
-}
-
-static int dos_copydir(direntry_t *entry, MainParam_t *mp)
-/* copyes a directory to Dos */
-{
-	Arg_t * arg = (Arg_t *) (mp->arg);
-	Arg_t newArg;
-	time_t now;
-	time_t date;
-	int ret;
-	const char *targetName = mpPickTargetName(mp);
-
-	if (!arg->recursive && mp->basenameHasWildcard)
-		return 0;
-
-	if(entry && isSubdirOf(mp->targetDir, mp->File)) {
-		fprintf(stderr, "Cannot recursively copy directory ");
-		fprintPwd(stderr, entry,0);
-		fprintf(stderr, " into one of its own subdirectories ");
-		fprintPwd(stderr, getDirentry(mp->targetDir),0);
-		fprintf(stderr, "\n");
-		return ERROR_ONE;
-	}
-
-	if (arg->mp.File->Class->get_data(arg->mp.File,
-					  & date, 0, 0, 0) < 0 ){
-		fprintf(stderr, "Can't stat source file\n");
-		return ERROR_ONE;
-	}
-
-	if(!arg->type && arg->verbose)
-		fprintf(stderr,"Copying %s\n", mpGetBasename(mp));
-
-	if(entry && arg->preserveAttributes)
-		arg->attr = entry->dir.attr;
-	else
-		arg->attr = 0;
-
-	if (entry && (mp->targetDir == entry->Dir)){
-		arg->ch.ignore_entry = -1;
-		arg->ch.source = entry->entry;
-	} else {
-		arg->ch.ignore_entry = -1;
-		arg->ch.source = -2;
-	}
-
-	/* preserve mod time? */
-	if (arg->preserveTime)
-		now = date;
-	else
-		getTimeNow(&now);
-
-	newArg = *arg;
-	newArg.mp.arg = &newArg;
-	newArg.mp.targetName = 0;
-	newArg.mp.basenameHasWildcard = 1;
-	if(*targetName) {
-		/* maybe the directory already exist. Use it */
-		newArg.mp.targetDir = subDir(mp->targetDir, targetName);
-		if(!newArg.mp.targetDir)
-			newArg.mp.targetDir = createDir(mp->targetDir, 
-							targetName,
-							&arg->ch, arg->attr, 
-							now);
-	} else
-		newArg.mp.targetDir = mp->targetDir;
-
-	if(!newArg.mp.targetDir)
-		return ERROR_ONE;
-
-	ret = mp->loop(mp->File, &newArg.mp, "*");
-	if(*targetName)
-		FREE(&newArg.mp.targetDir);
-	return ret | GOT_ONE;
-}
-
-
-static int dos_to_dos(direntry_t *entry, MainParam_t *mp)
-{
-	return dos_write(entry, mp, 0);
-}
-
-static int unix_to_dos(MainParam_t *mp)
-{
-	return dos_write(0, mp, 1);
-}
-
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Mtools version %s, dated %s\n", mversion, mdate);
-	fprintf(stderr,
-		"Usage: %s [-/spabtnmvQB] [-D clash_option] sourcefile targetfile\n", progname);
-	fprintf(stderr,
-		"       %s [-/spabtnmvQB] [-D clash_option] sourcefile [sourcefiles...] targetdirectory\n", 
-		progname);
-	fprintf(stderr,
-		"\t-/ -s Recursive\n"
-		"\t-p Preserve attributes\n"
-		"\t-a -t Textmode\n"
-		"\t-n Overwrite UNIX files without confirmation\n"
-		"\t-m Preserve file time (default under Minix)\n"
-		"\t-v Verbose\n"
-		"\t-Q Quit on the first error\n"
-		"\t-b -B Batch mode (faster, but less crash resistent)\n"
-		"\t-o Overwrite DOS files without confirmation\n");
-	exit(1);
-}
-
-void mcopy(int argc, char **argv, int mtype)
-{
-	Arg_t arg;
-	int c, ret, fastquit;
-	int todir;
-	
-
-	/* get command line options */
-
-	init_clash_handling(& arg.ch);
-
-	/* get command line options */
-	todir = 0;
-	arg.recursive = 0;
-#ifdef OS_Minix
-	arg.preserveTime = 1;	/* Copy file time as DOS does. */
-#else
-	arg.preserveTime = 0;
-#endif
-	arg.preserveAttributes = 0;
-	arg.nowarn = 0;
-	arg.textmode = 0;
-	arg.verbose = 0;
-	arg.type = mtype;
-	fastquit = 0;
-	while ((c = getopt(argc, argv, "abB/sptnmvQD:o")) != EOF) {
-		switch (c) {
-			case 's':
-			case '/':
-				arg.recursive = 1;
-				break;
-			case 'p':
-				arg.preserveAttributes = 1;
-				break;
-			case 'a':
-			case 't':
-				arg.textmode = 1;
-				break;
-			case 'n':
-				arg.nowarn = 1;
-				break;
-			case 'm':
-				arg.preserveTime = 1;
-				break;
-			case 'v':
-				arg.verbose = 1;
-				break;
-			case 'Q':
-				fastquit = 1;
-				break;
-			case 'B':
-			case 'b':
-				batchmode = 1;
-				break;
-			case 'o':
-				handle_clash_options(&arg.ch, c);
-				break;
-			case 'D':
-				if(handle_clash_options(&arg.ch, *optarg))
-					usage();
-				break;
-			case '?':
-				usage();
-			default:
-				break;
-		}
-	}
-
-	if (argc - optind < 1)
-		usage();
-
-	init_mp(&arg.mp);
-	arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN | NO_DOTS;
-	arg.mp.fast_quit = fastquit;
-	arg.mp.arg = (void *) &arg;
-	arg.mp.openflags = O_RDONLY;
-
-	/* last parameter is "-", use mtype mode */
-	if(!mtype && !strcmp(argv[argc-1], "-")) {
-		arg.type = mtype = 1;
-		argc--;
-	}
-
-	if(mtype){
-		/* Mtype = copying to stdout */
-		arg.mp.targetName = strdup("-");
-		arg.mp.unixTarget = strdup("");
-		arg.mp.callback = dos_to_unix;
-		arg.mp.dirCallback = unix_copydir;
-		arg.mp.unixcallback = unix_to_unix;		
-	} else {
-		char *target;
-		if (argc - optind == 1) {
-			/* copying to the current directory */
-			target = ".";
-		} else {
-			/* target is the last item mentioned */
-			argc--;
-			target = argv[argc];
-		}
-
-		ret = target_lookup(&arg.mp, target);
-		if(!arg.mp.targetDir && !arg.mp.unixTarget) {
-			fprintf(stderr,"Bad target %s\n", target);
-			exit(1);
-		}
-
-		/* callback functions */
-		if(arg.mp.unixTarget) {
-			arg.mp.callback = dos_to_unix;
-			arg.mp.dirCallback = directory_dos_to_unix;
-			arg.mp.unixcallback = unix_to_unix;
-		} else {
-			arg.mp.dirCallback = dos_copydir;
-			arg.mp.callback = dos_to_dos;
-			arg.mp.unixcallback = unix_to_dos;
-		}
-	}
-
-	exit(main_loop(&arg.mp, argv + optind, argc - optind));
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mdel.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mdel.c	(revision 9)
+++ 	(revision )
@@ -1,173 +1,0 @@
-/*
- * mdel.c
- * Delete an MSDOS file
- *
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "stream.h"
-#include "mainloop.h"
-#include "fs.h"
-#include "file.h"
-
-typedef struct Arg_t {
-	int deltype;
-	int verbose;
-} Arg_t;
-
-static int del_entry(direntry_t *entry, MainParam_t *mp)
-{
-	Arg_t *arg=(Arg_t *) mp->arg;
-	direntry_t longNameEntry;
-	int i;
-
-	if(got_signal)
-		return ERROR_ONE;
-
-	if(entry->entry == -3) {
-		fprintf(stderr, "Cannot remove root directory\n");
-		return ERROR_ONE;
-	}
-
-	if (arg->verbose) {
-		fprintf(stderr,"Removing ");
-		fprintPwd(stdout, entry,0);
-		putchar('\n');
-	}
-
-	if ((entry->dir.attr & (ATTR_READONLY | ATTR_SYSTEM)) &&
-	    (ask_confirmation("%s: \"%s\" is read only, erase anyway (y/n) ? ",
-			      progname, entry->name)))
-		return ERROR_ONE;
-	if (fatFreeWithDirentry(entry)) 
-		return ERROR_ONE;
-
-	initializeDirentry(&longNameEntry, entry->Dir);
-	for(i=entry->beginSlot; i< entry->endSlot; i++) {
-	    int error;
-	    longNameEntry.entry=i;
-	    dir_read(&longNameEntry, &error);
-	    if(error)
-		break;
-	    longNameEntry.dir.name[0] = (char) DELMARK;
-	    dir_write(&longNameEntry);
-	}
-
-	entry->dir.name[0] = (char) DELMARK;
-	dir_write(entry);
-	return GOT_ONE;
-}
-
-static int del_file(direntry_t *entry, MainParam_t *mp)
-{
-	char shortname[13];
-	direntry_t subEntry;
-	Stream_t *SubDir;
-	Arg_t *arg = (Arg_t *) mp->arg;
-	MainParam_t sonmp;
-	int ret;
-	int r;
-
-	sonmp = *mp;
-	sonmp.arg = mp->arg;
-
-	r = 0;
-	if (IS_DIR(entry)){
-		/* a directory */
-		SubDir = OpenFileByDirentry(entry);
-		initializeDirentry(&subEntry, SubDir);
-		ret = 0;
-		while((r=vfat_lookup(&subEntry, "*", 1,
-				     ACCEPT_DIR | ACCEPT_PLAIN,
-				     shortname, NULL)) == 0 ){
-			if(shortname[0] != DELMARK &&
-			   shortname[0] &&
-			   shortname[0] != '.' ){
-				if(arg->deltype != 2){
-					fprintf(stderr,
-						"Directory ");
-					fprintPwd(stderr, entry,0);
-					fprintf(stderr," non empty\n");
-					ret = ERROR_ONE;
-					break;
-				}
-				if(got_signal) {
-					ret = ERROR_ONE;
-					break;
-				}
-				ret = del_file(&subEntry, &sonmp);
-				if( ret & ERROR_ONE)
-					break;
-				ret = 0;
-			}
-		}
-		FREE(&SubDir);
-		if (r == -2)
-			return ERROR_ONE;
-		if(ret)
-			return ret;
-	}
-	return del_entry(entry, mp);
-}
-
-
-static void usage(void)
-{
-	fprintf(stderr, 
-		"Mtools version %s, dated %s\n", mversion, mdate);
-	fprintf(stderr, 
-		"Usage: %s [-v] msdosfile [msdosfiles...]\n"
-		"\t-v Verbose\n",
-		progname);
-	exit(1);
-}
-
-void mdel(int argc, char **argv, int deltype)
-{
-	Arg_t arg;
-	MainParam_t mp;
-	int c,i;
-
-	arg.verbose = 0;
-	while ((c = getopt(argc, argv, "v")) != EOF) {
-		switch (c) {
-			case 'v':
-				arg.verbose = 1;
-				break;
-			default:
-				usage();
-		}
-	}
-
-	if(argc == optind)
-		usage();
-
-	init_mp(&mp);
-	mp.callback = del_file;
-	mp.arg = (void *) &arg;
-	mp.openflags = O_RDWR;
-	arg.deltype = deltype;
-	switch(deltype){
-	case 0:
-		mp.lookupflags = ACCEPT_PLAIN; /* mdel */
-		break;
-	case 1:
-		mp.lookupflags = ACCEPT_DIR; /* mrd */
-		break;
-	case 2:
-		mp.lookupflags = ACCEPT_DIR | ACCEPT_PLAIN; /* mdeltree */
-		break;
-	}
-	mp.lookupflags |= NO_DOTS;
-	for(i=optind;i<argc;i++) {
-		int b,l;
-		b = skip_drive(argv[i]) - argv[i];
-		l = strlen(argv[i]+b);
-		if(l > 1 && argv[i][b+l-1] == '/')
-			argv[i][b+l-1] = '\0';
-	}
-		
-	exit(main_loop(&mp, argv + optind, argc - optind));
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mdir.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mdir.c	(revision 9)
+++ 	(revision )
@@ -1,579 +1,0 @@
-/*
- * mdir.c:
- * Display an MSDOS directory
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "vfat.h"
-#include "mtools.h"
-#include "file.h"
-#include "mainloop.h"
-#include "fs.h"
-#include "codepage.h"
-
-#ifdef TEST_SIZE
-#include "fsP.h"
-#endif
-
-static int recursive;
-static int wide;
-static int all;
-static int concise;
-static int fast=0;
-#if 0
-static int testmode = 0;
-#endif
-static char *dirPath;
-static char *currentDrive;
-static Stream_t *currentDir;
-
-static int filesInDir; /* files in current dir */
-static int filesOnDrive; /* files on drive */
-	
-static int dirsOnDrive; /* number of listed directories on this drive */
-
-static int debug = 0; /* debug mode */
-
-static mt_size_t bytesInDir;
-static mt_size_t bytesOnDrive;
-static Stream_t *RootDir;	
-
-
-static char shortname[13];
-static char longname[VBUFSIZE];
-
-
-/*
- * Print an MSDOS directory date stamp.
- */
-static inline void print_date(struct directory *dir)
-{
-	char year[5];
-	char day[3];
-	char month[3];
-	char *p;
-
-	sprintf(year, "%04d", DOS_YEAR(dir));
-	sprintf(day, "%02d", DOS_DAY(dir));
-	sprintf(month, "%02d", DOS_MONTH(dir));
-
-	for(p=mtools_date_string; *p; p++) {
-		if(!strncasecmp(p, "yyyy", 4)) {
-			printf("%04d", DOS_YEAR(dir));
-			p+= 3;
-			continue;
-		} else if(!strncasecmp(p, "yy", 2)) {
-			printf("%02d", DOS_YEAR(dir) % 100);
-			p++;
-			continue;
-		} else if(!strncasecmp(p, "dd", 2)) {
-			printf("%02d", DOS_DAY(dir));
-			p++;
-			continue;
-		} else if(!strncasecmp(p, "mm", 2)) {
-			printf("%02d", DOS_MONTH(dir));
-			p++;
-			continue;
-		}
-		putchar(*p);
-	}
-}
-
-/*
- * Print an MSDOS directory time stamp.
- */
-static inline void print_time(struct directory *dir)
-{
-	char am_pm;
-	int hour = DOS_HOUR(dir);
-       
-	if(!mtools_twenty_four_hour_clock) {
-		am_pm = (hour >= 12) ? 'p' : 'a';
-		if (hour > 12)
-			hour = hour - 12;
-		if (hour == 0)
-			hour = 12;
-	} else
-		am_pm = ' ';
-
-	printf("%2d:%02d%c", hour, DOS_MINUTE(dir), am_pm);
-}
-
-/*
- * Return a number in dotted notation
- */
-static const char *dotted_num(mt_size_t num, int width, char **buf)
-{
-	int      len;
-	register char *srcp, *dstp;
-	int size;
-
-	unsigned long numlo;
-	unsigned long numhi;
-
-	if (num < 0) {
-	    /* warn about negative numbers here.  They should not occur */
-	    fprintf(stderr, "Invalid negative number\n");
-	}
-
-	size = width + width;
-	*buf = malloc(size+1);
-
-	if (*buf == NULL)
-		return "";
-	
-	/* Create the number in maximum width; make sure that the string
-	 * length is not exceeded (in %6ld, the result can be longer than 6!)
-	 */
-
-	numlo = num % 1000000000;
-	numhi = num / 1000000000;
-
-	if(numhi && size > 9) {
-		sprintf(*buf, "%.*lu%09lu", size-9, numhi, numlo);
-	} else {
-		sprintf(*buf, "%.*lu", size, numlo);
-	}
-
-	for (srcp=*buf; srcp[1] != '\0'; ++srcp)
-		if (srcp[0] == '0')
-			srcp[0] = ' ';
-		else
-			break;
-	
-	len = strlen(*buf);
-	srcp = (*buf)+len;
-	dstp = (*buf)+len+1;
-
-	for ( ; dstp >= (*buf)+4 && isdigit (srcp[-1]); ) {
-		srcp -= 3;  /* from here we copy three digits */
-		dstp -= 4;  /* that's where we put these 3 digits */
-	}
-
-	/* now finally copy the 3-byte blocks to their new place */
-	while (dstp < (*buf) + len) {
-		dstp[0] = srcp[0];
-		dstp[1] = srcp[1];
-		dstp[2] = srcp[2];
-		if (dstp + 3 < (*buf) + len)
-			/* use spaces instead of dots: they please both
-			 * Americans and Europeans */
-			dstp[3] = ' ';		
-		srcp += 3;
-		dstp += 4;
-	}
-
-	return (*buf) + len-width;
-}
-
-static inline int print_volume_label(Stream_t *Dir, char *drive)
-{
-	Stream_t *Stream = GetFs(Dir);
-	direntry_t entry;
-	DeclareThis(FsPublic_t);
-	char shortname[13];
-	char longname[VBUFSIZE];
-	int r;
-
-	RootDir = OpenRoot(Stream);
-	if(concise)
-		return 0;
-	
-	/* find the volume label */
-
-	initializeDirentry(&entry, RootDir);
-	if((r=vfat_lookup(&entry, 0, 0, ACCEPT_LABEL | MATCH_ANY,
-			  shortname, longname)) ) {
-		if (r == -2) {
-			/* I/O Error */
-			return -1;
-		}
-		printf(" Volume in drive %s has no label", drive);
-	} else if (*longname)
-		printf(" Volume in drive %s is %s (abbr=%s)",
-		       drive, longname, shortname);
-	else
-		printf(" Volume in drive %s is %s",
-		       drive, shortname);
-	if(This->serialized)
-		printf("\n Volume Serial Number is %04lX-%04lX",
-		       (This->serial_number >> 16) & 0xffff, 
-		       This->serial_number & 0xffff);
-	return 0;
-}
-
-
-static void printSummary(int files, mt_size_t bytes)
-{
-	if(!filesInDir)
-		printf("No files\n");
-	else {		
-		char *s1;
-		printf("      %3d file", files);
-		if(files == 1)
-			putchar(' ');
-		else
-			putchar('s');
-		printf("       %s bytes\n",
-		       dotted_num(bytes, 13, &s1));
-		if(s1)
-			free(s1);
-	}
-}
-
-static void leaveDirectory(int haveError);
-
-static void leaveDrive(int haveError)
-{
-	if(!currentDrive)
-		return;
-	leaveDirectory(haveError);
-	if(!concise && !haveError) {
-		char *s1;
-
-		if(dirsOnDrive > 1) {
-			printf("\nTotal files listed:\n");
-			printSummary(filesOnDrive, bytesOnDrive);
-		}
-		if(RootDir && !fast) {
-			mt_off_t bytes = getfree(RootDir);
-			printf("                  %s bytes free\n\n",
-			       dotted_num(bytes,17, &s1));
-#ifdef TEST_SIZE
-			((Fs_t*)GetFs(RootDir))->freeSpace = 0;
-			bytes = getfree(RootDir);
-			printf("                  %s bytes free\n\n",
-			       dotted_num(bytes,17, &s1));
-#endif
-		}
-		if(s1)
-			free(s1);
-	}
-	FREE(&RootDir);
-	currentDrive = NULL;
-}
-
-
-static int enterDrive(Stream_t *Dir, char *drive)
-{
-	int r;
-	if(currentDrive != NULL && strcmp(currentDrive, drive) == 0)
-		return 0; /* still the same */
-	
-	leaveDrive(0);
-	currentDrive = drive;
-	
-	r = print_volume_label(Dir, drive);
-	if (r)
-		return r;
-
-
-	bytesOnDrive = 0;
-	filesOnDrive = 0;
-	dirsOnDrive = 0;
-	return 0;
-}
-
-static char *emptyString="<out-of-memory>";
-
-static void leaveDirectory(int haveError)
-{
-	if(!currentDir)
-		return;
-
-	if (!haveError) {
-		if(dirPath && dirPath != emptyString)
-			free(dirPath);
-		if(wide)
-			putchar('\n');
-		
-		if(!concise)
-			printSummary(filesInDir, bytesInDir);
-	}
-	FREE(&currentDir);
-}
-
-static int enterDirectory(Stream_t *Dir)
-{
-	int r;
-	char *drive;
-	char *slash;
-
-	if(currentDir == Dir)
-		return 0; /* still the same directory */
-
-	leaveDirectory(0);
-
-	drive = getDrive(Dir);
-	r=enterDrive(Dir, drive);
-	if(r)
-		return r;
-	currentDir = COPY(Dir);
-
-	dirPath = getPwd(getDirentry(Dir));
-	if(!dirPath)
-		dirPath=emptyString;
-	if(concise &&
-	    (slash = strrchr(dirPath, '/')) != NULL && slash[1] == '\0')
-		*slash = '\0';
-
-	/* print directory title */
-	if(!concise)
-		printf("\nDirectory for %s\n", dirPath);
-
-	if(!wide && !concise)
-		printf("\n");
-
-	dirsOnDrive++;
-	bytesInDir = 0;
-	filesInDir = 0;
-	return 0;
-}
-
-static int list_file(direntry_t *entry, MainParam_t *mp)
-{
-	unsigned long size;
-	int i;
-	int Case;
-	int r;
-
-	if(!all && (entry->dir.attr & 0x6))
-		return 0;
-
-	if(concise && isSpecial(entry->name))
-		return 0;
-
-	r=enterDirectory(entry->Dir);
-	if (r)
-		return ERROR_ONE;
-	if (wide) {
-		if(filesInDir % 5)
-			putchar(' ');				
-		else
-			putchar('\n');
-	}
-	
-	if(IS_DIR(entry)){
-		size = 0;
-	} else
-		size = FILE_SIZE(&entry->dir);
-	
-	Case = entry->dir.Case;
-	if(!(Case & (BASECASE | EXTCASE)) && 
-	   mtools_ignore_short_case)
-		Case |= BASECASE | EXTCASE;
-	
-	if(Case & EXTCASE){
-		for(i=0; i<3;i++)
-			entry->dir.ext[i] = tolower(entry->dir.ext[i]);
-	}
-	to_unix(entry->dir.ext,3);
-	if(Case & BASECASE){
-		for(i=0; i<8;i++)
-			entry->dir.name[i] = tolower(entry->dir.name[i]);
-	}
-	to_unix(entry->dir.name,8);
-	if(wide){
-		if(IS_DIR(entry))
-			printf("[%s]%*s", shortname,
-			       (int) (15 - 2 - strlen(shortname)), "");
-		else
-			printf("%-15s", shortname);
-	} else if(!concise) {				
-		/* is a subdirectory */
-		if(mtools_dotted_dir)
-			printf("%-13s", shortname);
-		else
-			printf("%-8.8s %-3.3s ",
-			       entry->dir.name, 
-			       entry->dir.ext);
-		if(IS_DIR(entry))
-			printf("<DIR>    ");
-		else
-			printf(" %8ld", (long) size);
-		printf(" ");
-		print_date(&entry->dir);
-		printf("  ");
-		print_time(&entry->dir);
-
-		if(debug)
-			printf(" %s %d ", entry->dir.name, START(&entry->dir));
-		
-		if(*longname)
-			printf(" %s", longname);
-		printf("\n");
-	} else {
-		printf("%s/%s", dirPath, entry->name);
-		if(IS_DIR(entry))
-			putchar('/');
-		putchar('\n');
-	}
-
-	filesOnDrive++;
-	filesInDir++;
-
-	bytesOnDrive += (mt_size_t) size;
-	bytesInDir += (mt_size_t) size;
-	return GOT_ONE;
-}
-
-static int list_non_recurs_directory(direntry_t *entry, MainParam_t *mp)
-{
-	int r;
-	/* list top-level directory
-	 *   If this was matched by wildcard in the basename, list it as
-	 *   file, otherwise, list it as directory */
-	if (mp->basenameHasWildcard) {
-		/* wildcard, list it as file */
-		return list_file(entry, mp);
-	} else {
-		/* no wildcard, list it as directory */
-		MainParam_t subMp;
-
-		r=enterDirectory(mp->File);
-		if(r)
-			return ERROR_ONE;
-
-		subMp = *mp;
-		subMp.dirCallback = subMp.callback;
-		return mp->loop(mp->File, &subMp, "*") | GOT_ONE;
-	}
-}
-
-
-static int list_recurs_directory(direntry_t *entry, MainParam_t *mp)
-{
-	MainParam_t subMp;
-	int ret;
-
-	/* first list the files */
-	subMp = *mp;
-	subMp.lookupflags = ACCEPT_DIR | ACCEPT_PLAIN;
-	subMp.dirCallback = list_file;
-	subMp.callback = list_file;
-
-	ret = mp->loop(mp->File, &subMp, "*");
-
-	/* then list subdirectories */
-	subMp = *mp;
-	subMp.lookupflags = ACCEPT_DIR | NO_DOTS | NO_MSG | DO_OPEN;
-	return ret | mp->loop(mp->File, &subMp, "*");
-}
-
-#if 0
-static int test_directory(direntry_t *entry, MainParam_t *mp)
-{
-	Stream_t *File=mp->File;
-	Stream_t *Target;
-	char errmsg[80];
-
-	if ((Target = SimpleFileOpen(0, 0, "-",
-				     O_WRONLY,
-				     errmsg, 0, 0, 0))) {
-		copyfile(File, Target);
-		FREE(&Target);
-	}
-	return GOT_ONE;
-}
-#endif
-
-static void usage(void)
-{
-		fprintf(stderr, "Mtools version %s, dated %s\n",
-			mversion, mdate);
-		fprintf(stderr, "Usage: %s: [-waXbfds/] msdosdirectory\n",
-			progname);
-		fprintf(stderr,
-			"       %s: [-waXbfds/] msdosfile [msdosfiles...]\n",
-			progname);
-		fprintf(stderr,
-			"\t-w Wide listing\n"
-			"\t-a All, including hidden files\n"
-			"\t-b -X Concise listing\n"
-			"\t-f Fast, no free space summary\n"
-			"\t-d Debug mode\n"
-			"\t-s -/ Recursive\n");
-		exit(1);
-}
-
-
-void mdir(int argc, char **argv, int type)
-{
-	int ret;
-	MainParam_t mp;
-	int faked;
-	int c;
-	char *fakedArgv[] = { "." };
-	
-	concise = 0;
-	recursive = 0;
-	wide = all = 0;
-					/* first argument */
-	while ((c = getopt(argc, argv, "waXbfds/")) != EOF) {
-		switch(c) {
-			case 'w':
-				wide = 1;
-				break;
-			case 'a':
-				all = 1;
-				break;
-			case 'b':
-			case 'X':
-				concise = 1;
-				/*recursive = 1;*/
-				break;
-			case 's':
-			case '/':
-				recursive = 1;
-				break;
-			case 'f':
-				fast = 1;
-				break;
-			case 'd':
-				debug = 1;
-				break;
-#if 0
-			case 't': /* test mode */
-				testmode = 1;
-				break;
-#endif
-			default:
-				usage();
-		}
-	}
-
-	/* fake an argument */
-	faked = 0;
-	if (optind == argc) {
-		argv = fakedArgv;
-		argc = 1;
-		optind = 0;
-	}
-
-	init_mp(&mp);
-	currentDrive = '\0';
-	currentDir = 0;
-	RootDir = 0;
-	dirPath = 0;
-#if 0
-	if (testmode) {
-		mp.lookupflags = ACCEPT_DIR | NO_DOTS;
-		mp.dirCallback = test_directory;
-	} else 
-#endif
-		if(recursive) {
-		mp.lookupflags = ACCEPT_DIR | DO_OPEN_DIRS | NO_DOTS;
-		mp.dirCallback = list_recurs_directory;
-	} else {
-		mp.lookupflags = ACCEPT_DIR | ACCEPT_PLAIN | DO_OPEN_DIRS;
-		mp.dirCallback = list_non_recurs_directory;
-		mp.callback = list_file;
-	}
-	mp.longname = longname;
-	mp.shortname = shortname;
-	ret=main_loop(&mp, argv + optind, argc - optind);
-	leaveDirectory(ret);
-	leaveDrive(ret);
-	exit(ret);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mdoctorfat.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mdoctorfat.c	(revision 9)
+++ 	(revision )
@@ -1,166 +1,0 @@
-/* Test program for doctoring the fat */
-
-
-/*
- * mcopy.c
- * Copy an MSDOS files to and from Unix
- *
- */
-
-
-#define LOWERCASE
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "mainloop.h"
-#include "plain_io.h"
-#include "nameclash.h"
-#include "file.h"
-#include "fs.h"
-#include "fsP.h"
-
-typedef struct Arg_t {
-	char *target;
-	MainParam_t mp;
-	ClashHandling_t ch;
-	Stream_t *sourcefile;
-	unsigned long fat;
-	int markbad;
-	int setsize;
-	unsigned long size;
-	Fs_t *Fs;
-} Arg_t;
-
-static int dos_doctorfat(direntry_t *entry, MainParam_t *mp)
-{
-	Fs_t *Fs = getFs(mp->File);
-	Arg_t *arg=(Arg_t *) mp->arg;
-	
-	if(!arg->markbad && entry->entry != -3) {
-		/* if not root directory, change it */
-		set_word(entry->dir.start, arg->fat & 0xffff);
-		set_word(entry->dir.startHi, arg->fat >> 16);
-		if(arg->setsize)
-			set_dword(entry->dir.size, arg->size);
-		dir_write(entry);		
-	}
-	arg->Fs = Fs; 
-	return GOT_ONE;
-}
-
-static int unix_doctorfat(MainParam_t *mp)
-{
-	fprintf(stderr,"File does not reside on a Dos fs\n");
-	return ERROR_ONE;
-}
-
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Mtools version %s, dated %s\n", mversion, mdate);
-	fprintf(stderr,
-		"Usage: %s [-b] [-o offset] [-s size] file fat\n", progname);
-	exit(1);
-}
-
-void mdoctorfat(int argc, char **argv, int mtype)
-{
-	Arg_t arg;
-	int c, ret;
-	long address, begin, end;
-	char *number, *eptr;
-	int i, j;
-	long offset;
-	
-	/* get command line options */
-
-	init_clash_handling(& arg.ch);
-
-	offset = 0;
-
-	arg.markbad = 0;
-	arg.setsize = 0;
-
-	/* get command line options */
-	while ((c = getopt(argc, argv, "bo:s:")) != EOF) {
-		switch (c) {
-			case 'b':
-				arg.markbad = 1;
-				break;
-			case 'o':
-				offset = strtoul(optarg,0,0);
-				break;
-			case 's':
-				arg.setsize=1;
-				arg.size = strtoul(optarg,0,0);
-				break;
-			case '?':
-				usage();
-				break;
-		}
-	}
-
-	if (argc - optind < 2)
-		usage();
-
-
-	/* only 1 file to copy... */
-	init_mp(&arg.mp);
-	arg.mp.arg = (void *) &arg;
-		
-	arg.mp.callback = dos_doctorfat;
-	arg.mp.unixcallback = unix_doctorfat;
-	
-	arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN;
-	arg.mp.openflags = O_RDWR;
-	arg.fat = strtoul(argv[optind+1], 0, 0) + offset;
-	ret=main_loop(&arg.mp, argv + optind, 1);
-	if(ret)
-		exit(ret);
-	address = 0;
-	for(i=optind+1; i < argc; i++) {
-		number = argv[i];
-		if (*number == '<') {
-			number++;
-		}
-		begin = strtoul(number, &eptr, 0);
-		if (eptr && *eptr == '-') {
-			number = eptr+1;
-			end = strtoul(number, &eptr, 0);
-		} else {
-			end = begin;
-		}
-		if (eptr == number) {
-			fprintf(stderr, "Not a number: %s\n", number);
-			exit(-1);
-		}
-
-		if (eptr && *eptr == '>') {
-			eptr++;
-		}
-		if (eptr && *eptr) {
-			fprintf(stderr, "Not a number: %s\n", eptr);
-			exit(-1);
-		}
-
-		for (j=begin; j <= end; j++) {
-			if(arg.markbad) {
-				arg.Fs->fat_encode(arg.Fs, j+offset, arg.Fs->last_fat ^ 6 ^ 8);
-			} else {
-				if(address) {
-					arg.Fs->fat_encode(arg.Fs, address, j+offset);
-				}
-				address = j+offset;
-			}
-		}
-	}
-
-	if (address && !arg.markbad) {
-		arg.Fs->fat_encode(arg.Fs, address, arg.Fs->end_fat);
-	}
-
-	exit(ret);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mdu.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mdu.c	(revision 9)
+++ 	(revision )
@@ -1,121 +1,0 @@
-/*
- * mdu.c:
- * Display the space occupied by an MSDOS directory
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "vfat.h"
-#include "mtools.h"
-#include "file.h"
-#include "mainloop.h"
-#include "fs.h"
-#include "codepage.h"
-
-
-typedef struct Arg_t {
-	int all;
-	int inDir;
-	int summary;
-	struct Arg_t *parent;
-	char *target;
-	char *path;
-	unsigned int blocks;
-	MainParam_t mp;
-} Arg_t;
-
-static void usage(void)
-{
-		fprintf(stderr, "Mtools version %s, dated %s\n",
-			mversion, mdate);
-		fprintf(stderr, "Usage: %s [-as] msdosdirectory\n"
-			"\t-a All (also show individual files)\n"
-			"\t-s Summary for directory only\n",
-			progname);
-		exit(1);
-}
-
-static int file_mdu(direntry_t *entry, MainParam_t *mp)
-{
-	unsigned int blocks;
-	Arg_t * arg = (Arg_t *) (mp->arg);
-
-	blocks = countBlocks(entry->Dir,getStart(entry->Dir, &entry->dir));
-	if(arg->all || !arg->inDir) {
-		printf("%-7d ", blocks);
-		fprintPwd(stdout, entry,0);
-		fputc('\n', stdout);
-	}
-	arg->blocks += blocks;
-	return GOT_ONE;
-}
-
-
-static int dir_mdu(direntry_t *entry, MainParam_t *mp)
-{
-	Arg_t *parentArg = (Arg_t *) (mp->arg);
-	Arg_t arg;
-	int ret;
-	
-	arg = *parentArg;
-	arg.mp.arg = (void *) &arg;
-	arg.parent = parentArg;
-	arg.inDir = 1;
-
-	/* account for the space occupied by the directory itself */
-	if(!isRootDir(entry->Dir)) {
-		arg.blocks = countBlocks(entry->Dir,
-					 getStart(entry->Dir, &entry->dir));
-	} else {
-		arg.blocks = 0;
-	}
-
-	/* recursion */
-	ret = mp->loop(mp->File, &arg.mp, "*");
-	if(!arg.summary || !parentArg->inDir) {
-		printf("%-7d ", arg.blocks);
-		fprintPwd(stdout, entry,0);
-		fputc('\n', stdout);
-	}
-	arg.parent->blocks += arg.blocks;
-	return ret;
-}
-
-void mdu(int argc, char **argv, int type)
-{
-	Arg_t arg;
-	int c;
-
-	arg.all = 0;
-	arg.inDir = 0;
-	arg.summary = 0;
-	while ((c = getopt(argc, argv, "as")) != EOF) {
-		switch (c) {
-			case 'a':
-				arg.all = 1;
-				break;
-			case 's':
-				arg.summary = 1;
-				break;
-			case '?':
-				usage();
-		}
-	}
-
-	if (optind >= argc)
-		usage();
-
-	if(arg.summary && arg.all) {
-		fprintf(stderr,"-a and -s options are mutually exclusive\n");
-		usage();
-	}
-
-	init_mp(&arg.mp);
-	arg.mp.callback = file_mdu;
-	arg.mp.openflags = O_RDONLY;
-	arg.mp.dirCallback = dir_mdu;
-
-	arg.mp.arg = (void *) &arg;
-	arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN_DIRS | NO_DOTS;
-	exit(main_loop(&arg.mp, argv + optind, argc - optind));
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mformat.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mformat.c	(revision 9)
+++ 	(revision )
@@ -1,1140 +1,0 @@
-/*
- * mformat.c
- */
-
-#define DONT_NEED_WAIT
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "mainloop.h"
-#include "fsP.h"
-#include "file.h"
-#include "plain_io.h"
-#include "floppyd_io.h"
-#include "nameclash.h"
-#include "buffer.h"
-#ifdef USE_XDF
-#include "xdf_io.h"
-#endif
-#include "partition.h"
-
-#ifndef abs
-#define abs(x) ((x)>0?(x):-(x))
-#endif
-
-#ifdef OS_linux
-#include "linux/hdreg.h"
-
-#define _LINUX_STRING_H_
-#define kdev_t int
-#include "linux/fs.h"
-#undef _LINUX_STRING_H_
-
-#endif
-
-
-extern int errno;
-
-static int init_geometry_boot(struct bootsector *boot, struct device *dev,
-			       int sectors0, int rate_0, int rate_any,
-			       int *tot_sectors, int keepBoot)
-{
-	int i;
-	int nb_renum;
-	int sector2;
-	int size2;
-	int j;
-	int sum;
-
-	set_word(boot->nsect, dev->sectors);
-	set_word(boot->nheads, dev->heads);
-
-	*tot_sectors = dev->heads * dev->sectors * dev->tracks - DWORD(nhs);
-
-	if (*tot_sectors < 0x10000){
-		set_word(boot->psect, *tot_sectors);
-		set_dword(boot->bigsect, 0);
-	} else {
-		set_word(boot->psect, 0);
-		set_dword(boot->bigsect, *tot_sectors);
-	}
-
-	if (dev->use_2m & 0x7f){
-		int bootOffset;
-		strncpy(boot->banner, "2M-STV04", 8);
-		boot->ext.old.res_2m = 0;
-		boot->ext.old.fmt_2mf = 6;
-		if ( dev->sectors % ( ((1 << dev->ssize) + 3) >> 2 ))
-			boot->ext.old.wt = 1;
-		else
-			boot->ext.old.wt = 0;
-		boot->ext.old.rate_0= rate_0;
-		boot->ext.old.rate_any= rate_any;
-		if (boot->ext.old.rate_any== 2 )
-			boot->ext.old.rate_any= 1;
-		i=76;
-
-		/* Infp0 */
-		set_word(boot->ext.old.Infp0, i);
-		boot->jump[i++] = sectors0;
-		boot->jump[i++] = 108;
-		for(j=1; j<= sectors0; j++)
-			boot->jump[i++] = j;
-
-		set_word(boot->ext.old.InfpX, i);
-		
-		boot->jump[i++] = 64;
-		boot->jump[i++] = 3;
-		nb_renum = i++;
-		sector2 = dev->sectors;
-		size2 = dev->ssize;
-		j=1;
-		while( sector2 ){
-			while ( sector2 < (1 << size2) >> 2 )
-				size2--;
-			boot->jump[i++] = 128 + j;
-			boot->jump[i++] = j++;
-			boot->jump[i++] = size2;
-			sector2 -= (1 << size2) >> 2;
-		}
-		boot->jump[nb_renum] = ( i - nb_renum - 1 ) / 3;
-
-		set_word(boot->ext.old.InfTm, i);
-
-		sector2 = dev->sectors;
-		size2= dev->ssize;
-		while(sector2){
-			while ( sector2 < 1 << ( size2 - 2) )
-				size2--;
-			boot->jump[i++] = size2;
-			sector2 -= 1 << (size2 - 2 );
-		}
-		
-		set_word(boot->ext.old.BootP,i);
-		bootOffset = i;
-
-		/* checksum */		
-		for (sum=0, j=64; j<i; j++) 
-			sum += boot->jump[j];/* checksum */
-		boot->ext.old.CheckSum=-sum;
-		return bootOffset;
-	} else {
-		if(!keepBoot) {
-			boot->jump[0] = 0xeb;
-			boot->jump[1] = 0;
-			boot->jump[2] = 0x90;
-			strncpy(boot->banner, "MTOOL397", 8);
-			/* It looks like some versions of DOS are
-			 * rather picky about this, and assume default
-			 * parameters without this, ignoring any
-			 * indication about cluster size et al. */
-		}
-		return 0;
-	}
-}
-
-
-static int comp_fat_bits(Fs_t *Fs, int estimate, 
-			 unsigned int tot_sectors, int fat32)
-{
-	int needed_fat_bits;
-
-	needed_fat_bits = 12;
-
-#define MAX_DISK_SIZE(bits,clusters) \
-	TOTAL_DISK_SIZE((bits), Fs->sector_size, (clusters), \
-			Fs->num_fat, MAX_SECT_PER_CLUSTER)
-
-	if(tot_sectors > MAX_DISK_SIZE(12, FAT12))
-		needed_fat_bits = 16;
-	if(fat32 || tot_sectors > MAX_DISK_SIZE(16, FAT16))
-		needed_fat_bits = 32;
-
-#undef MAX_DISK_SIZE
-
-	if(abs(estimate) && abs(estimate) < needed_fat_bits) {
-		if(fat32) {
-			fprintf(stderr,
-				"Contradiction between FAT size on command line and FAT size in conf file\n");
-			exit(1);
-		}
-		fprintf(stderr,
-			"Device too big for a %d bit FAT\n",
-			estimate);
-		exit(1);
-	}
-
-	if(needed_fat_bits == 32 && !fat32 && abs(estimate) !=32){
-		fprintf(stderr,"Warning: Using 32 bit FAT.  Drive will only be accessibly by Win95 OEM / Win98\n");
-	}
-
-	if(!estimate) {
-		int min_fat16_size;
-
-		if(needed_fat_bits > 12)
-			return needed_fat_bits;
-		min_fat16_size = DISK_SIZE(16, Fs->sector_size, FAT12+1,
-					   Fs->num_fat, 1);
-		if(tot_sectors < min_fat16_size)
-			return 12;
-		else if(tot_sectors >= 2* min_fat16_size)
-			return 16; /* heuristics */
-	}
-
-	return estimate;
-}
-
-static void calc_fat_bits2(Fs_t *Fs, unsigned int tot_sectors, int fat_bits)
-{
-	unsigned int rem_sect;
-
-	/*
-	 * the "remaining sectors" after directory and boot
-	 * hasve been accounted for.
-	 */
-	rem_sect = tot_sectors - Fs->dir_len - Fs->fat_start;
-	switch(abs(fat_bits)) {
-		case 0:
-
-#define MY_DISK_SIZE(bits,clusters) \
-			DISK_SIZE( (bits), Fs->sector_size, (clusters), \
-				   Fs->num_fat, Fs->cluster_size)
-
-			if(rem_sect >= MY_DISK_SIZE(16, FAT12 + 1))
-				/* big enough for FAT16 */
-				set_fat16(Fs);
-			else if(rem_sect <= MY_DISK_SIZE(12, FAT12))
-				 /* small enough for FAT12 */
-				 set_fat12(Fs);
-			else {
-				/* "between two chairs",
-				 * augment cluster size, and
-				 * settle it */
-				if(Fs->cluster_size < MAX_SECT_PER_CLUSTER)
-					Fs->cluster_size <<= 1;
-				set_fat12(Fs);
-			}
-			break;
-#undef MY_DISK_SIZE
-
-		case 12:
-			set_fat12(Fs);
-			break;
-		case 16:
-			set_fat16(Fs);
-			break;
-		case 32:
-			set_fat32(Fs);
-			break;
-	}
-}
-
-static inline void format_root(Fs_t *Fs, char *label, struct bootsector *boot)
-{
-	Stream_t *RootDir;
-	char *buf;
-	int i;
-	struct ClashHandling_t ch;
-	int dirlen;
-
-	init_clash_handling(&ch);
-	ch.name_converter = label_name;
-	ch.ignore_entry = -2;
-
-	buf = safe_malloc(Fs->sector_size);
-	RootDir = OpenRoot((Stream_t *)Fs);
-	if(!RootDir){
-		fprintf(stderr,"Could not open root directory\n");
-		exit(1);
-	}
-
-	memset(buf, '\0', Fs->sector_size);
-
-	if(Fs->fat_bits == 32) {
-		/* on a FAT32 system, we only write one sector,
-		 * as the directory can be extended at will...*/
-		dirlen = 1;
-		fatAllocate(Fs, Fs->rootCluster, Fs->end_fat);
-	} else
-		dirlen = Fs->dir_len; 
-	for (i = 0; i < dirlen; i++)
-		WRITES(RootDir, buf, sectorsToBytes((Stream_t*)Fs, i),  
-			   Fs->sector_size);
-
-	ch.ignore_entry = 1;
-	if(label[0])
-		mwrite_one(RootDir,label, 0, labelit, NULL,&ch);
-
-	FREE(&RootDir);
-	if(Fs->fat_bits == 32)
-		set_word(boot->dirents, 0);
-	else
-		set_word(boot->dirents, Fs->dir_len * (Fs->sector_size / 32));
-	free(buf);
-}
-
-
-static void xdf_calc_fat_size(Fs_t *Fs, unsigned int tot_sectors, int fat_bits)
-{
-	unsigned int rem_sect;
-
-	rem_sect = tot_sectors - Fs->dir_len - Fs->fat_start - 2 * Fs->fat_len;
-
-	if(Fs->fat_len) {
-		/* an XDF disk, we know the fat_size and have to find
-		 * out the rest. We start with a cluster size of 1 and
-		 * keep doubling until everything fits into the
-		 * FAT. This will occur eventually, as our FAT has a
-		 * minimal size of 1 */
-		for(Fs->cluster_size = 1; 1 ; Fs->cluster_size <<= 1) {
-			Fs->num_clus = rem_sect / Fs->cluster_size;
-			if(abs(fat_bits) == 16 || Fs->num_clus > FAT12)
-				set_fat16(Fs);
-			else
-				set_fat12(Fs);
-			if (Fs->fat_len >= NEEDED_FAT_SIZE(Fs))
-				return;
-		}
-	}
-	fprintf(stderr,"Internal error while calculating Xdf fat size\n");
-	exit(1);
-}
-
-
-static void calc_fat_size(Fs_t *Fs, unsigned int tot_sectors)
-{
-	unsigned int rem_sect;
-	int tries;
-	int occupied;
-	
-	tries=0;
-	/* rough estimate of fat size */
-	Fs->fat_len = 1;
-	rem_sect = tot_sectors - Fs->dir_len - Fs->fat_start;
-	while(1){
-		Fs->num_clus = (rem_sect - 2 * Fs->fat_len ) /Fs->cluster_size;
-		Fs->fat_len = NEEDED_FAT_SIZE(Fs);
-		occupied = 2 * Fs->fat_len + Fs->cluster_size * Fs->num_clus;
-		
-		/* if we have used up more than we have,
-		 * we'll have to reloop */
-		
-		if ( occupied > rem_sect )
-			continue;
-
-
-		/* if we have exactly used up all
-		 * sectors, fine */
-		if ( rem_sect - occupied < Fs->cluster_size )
-			break;
-
-		/* if we have not used up all our
-		 * sectors, try again.  After the second
-		 * try, decrease the amount of available
-		 * space. This is to deal with the case of
-		 * 344 or 345, ..., 1705, ... available
-		 * sectors.  */
-		
-		switch(tries++){
-			default:
-				/* this should never happen */
-				fprintf(stderr,
-					"Internal error in cluster/fat repartition"
-					" calculation.\n");
-				exit(1);
-			case 2:
-				/* FALLTHROUGH */
-			case 1:
-				rem_sect-= Fs->cluster_size;
-				Fs->dir_len += Fs->cluster_size;
-			case 0:
-				continue;
-		}
-	}
-
-	if ( Fs->num_clus > FAT12 && Fs->fat_bits == 12 ){
-		fprintf(stderr,"Too many clusters for this fat size."
-			" Please choose a 16-bit fat in your /etc/mtools"
-			" or .mtoolsrc file\n");
-		exit(1);
-	}
-	if ( Fs->num_clus <= FAT12 && Fs->fat_bits > 12 ){
-		fprintf(stderr,"Too few clusters for this fat size."
-			" Please choose a 12-bit fat in your /etc/mtools"
-			" or .mtoolsrc file\n");
-		exit(1);
-	}
-}
-
-
-static unsigned char bootprog[]=
-{0xfa, 0x31, 0xc0, 0x8e, 0xd8, 0x8e, 0xc0, 0xfc, 0xb9, 0x00, 0x01,
- 0xbe, 0x00, 0x7c, 0xbf, 0x00, 0x80, 0xf3, 0xa5, 0xea, 0x00, 0x00,
- 0x00, 0x08, 0xb8, 0x01, 0x02, 0xbb, 0x00, 0x7c, 0xba, 0x80, 0x00,
- 0xb9, 0x01, 0x00, 0xcd, 0x13, 0x72, 0x05, 0xea, 0x00, 0x7c, 0x00,
- 0x00, 0xcd, 0x19};
-
-static inline void inst_boot_prg(struct bootsector *boot, int offset)
-{
-	memcpy((char *) boot->jump + offset, 
-	       (char *) bootprog, sizeof(bootprog) /sizeof(bootprog[0]));
-	boot->jump[0] = 0xeb;
-	boot->jump[1] = offset - 1;
-	boot->jump[2] = 0x90;
-	set_word(boot->jump + offset + 20, offset + 24);
-}
-
-static void calc_cluster_size(struct Fs_t *Fs, unsigned int tot_sectors,
-			      int fat_bits)
-			      
-{
-	unsigned int max_clusters; /* maximal possible number of sectors for
-				   * this FAT entry length (12/16/32) */
-	unsigned int max_fat_size; /* maximal size of the FAT for this FAT
-				    * entry length (12/16/32) */
-	unsigned int rem_sect; /* remaining sectors after we accounted for
-				* the root directory and boot sector(s) */
-
-	switch(abs(fat_bits)) {
-		case 12:			
-			max_clusters = FAT12;
-			max_fat_size = Fs->num_fat * 
-				FAT_SIZE(12, Fs->sector_size, max_clusters);
-			break;
-		case 16:
-		case 0: /* still hesititating between 12 and 16 */
-			max_clusters = FAT16;
-			max_fat_size = Fs->num_fat * 
-				FAT_SIZE(16, Fs->sector_size, max_clusters);
-			break;
-		case 32:		  
-			Fs->cluster_size = 8;
-			/* According to
-			 * http://www.microsoft.com/kb/articles/q154/9/97.htm,
-			 * Micro$oft does not support FAT32 with less than 4K
-			 */
-			return;
-		default:
-			fprintf(stderr,"Bad fat size\n");
-			exit(1);
-	}
-
-	rem_sect = tot_sectors - Fs->dir_len - Fs->fat_start;
-
-	/* double the cluster size until we can fill up the disk with
-	 * the maximal number of sectors of this size */
-	while(Fs->cluster_size * max_clusters  + max_fat_size < rem_sect) {
-		if(Fs->cluster_size > 64) {
-			/* bigger than 64. Should fit */
-			fprintf(stderr,
-				"Internal error while calculating cluster size\n");
-			exit(1);
-		}
-		Fs->cluster_size <<= 1;
-	}
-}
-
-
-struct OldDos_t old_dos[]={
-{   40,  9,  1, 4, 1, 2, 0xfc },
-{   40,  9,  2, 7, 2, 2, 0xfd },
-{   40,  8,  1, 4, 1, 1, 0xfe },
-{   40,  8,  2, 7, 2, 1, 0xff },
-{   80,  9,  2, 7, 2, 3, 0xf9 },
-{   80, 15,  2,14, 1, 7, 0xf9 },
-{   80, 18,  2,14, 1, 9, 0xf0 },
-{   80, 36,  2,15, 2, 9, 0xf0 },
-{    1,  8,  1, 1, 1, 1, 0xf0 },
-};
-
-static int old_dos_size_to_geom(int size, int *cyls, int *heads, int *sects)
-{
-	int i;
-	size = size * 2;
-	for(i=0; i < sizeof(old_dos) / sizeof(old_dos[0]); i++){
-		if (old_dos[i].sectors * 
-		    old_dos[i].tracks * 
-		    old_dos[i].heads == size) {
-			*cyls = old_dos[i].tracks;
-			*heads = old_dos[i].heads;
-			*sects = old_dos[i].sectors;
-			return 0;
-		}
-	}
-	return 1;
-}
-
-
-static void calc_fs_parameters(struct device *dev, unsigned int tot_sectors,
-			       struct Fs_t *Fs, struct bootsector *boot)
-{
-	int i;
-
-	for(i=0; i < sizeof(old_dos) / sizeof(old_dos[0]); i++){
-		if (dev->sectors == old_dos[i].sectors &&
-		    dev->tracks == old_dos[i].tracks &&
-		    dev->heads == old_dos[i].heads &&
-		    (dev->fat_bits == 0 || abs(dev->fat_bits) == 12)){
-			boot->descr = old_dos[i].media;
-			Fs->cluster_size = old_dos[i].cluster_size;
-			Fs->dir_len = old_dos[i].dir_len;
-			Fs->fat_len = old_dos[i].fat_len;
-			Fs->fat_bits = 12;
-			break;
-		}
-	}
-	if (i == sizeof(old_dos) / sizeof(old_dos[0]) ){
-		/* a non-standard format */
-		if(DWORD(nhs))
-			boot->descr = 0xf8;
-		  else
-			boot->descr = 0xf0;
-
-
-		if(!Fs->cluster_size) {
-			if (dev->heads == 1)
-				Fs->cluster_size = 1;
-			else {
-				Fs->cluster_size = (tot_sectors > 2000 ) ? 1:2;
-				if (dev->use_2m & 0x7f)
-					Fs->cluster_size = 1;
-			}
-		}
-		
-		if(!Fs->dir_len) {
-			if (dev->heads == 1)
-				Fs->dir_len = 4;
-			else
-				Fs->dir_len = (tot_sectors > 2000) ? 11 : 7;
-		}			
-
-		calc_cluster_size(Fs, tot_sectors, dev->fat_bits);
-		if(Fs->fat_len)
-			xdf_calc_fat_size(Fs, tot_sectors, dev->fat_bits);
-		else {
-			calc_fat_bits2(Fs, tot_sectors, dev->fat_bits);
-			calc_fat_size(Fs, tot_sectors);
-		}
-	}
-
-	set_word(boot->fatlen, Fs->fat_len);
-}
-
-
-
-static void calc_fs_parameters_32(unsigned int tot_sectors,
-				  struct Fs_t *Fs, struct bootsector *boot)
-{
-	if(DWORD(nhs))
-		boot->descr = 0xf8;
-	else
-		boot->descr = 0xf0;
-	if(!Fs->cluster_size)
-		/* According to
-		 * http://www.microsoft.com/kb/articles/q154/9/97.htm,
-		 * Micro$oft does not support FAT32 with less than 4K
-		 */
-		Fs->cluster_size = 8;
-	
-	Fs->dir_len = 0;
-	Fs->num_clus = tot_sectors / Fs->cluster_size;
-	set_fat32(Fs);
-	calc_fat_size(Fs, tot_sectors);
-	set_word(boot->fatlen, 0);
-	set_dword(boot->ext.fat32.bigFat, Fs->fat_len);
-}
-
-
-
-
-static void usage(void)
-{
-	fprintf(stderr, 
-		"Mtools version %s, dated %s\n", mversion, mdate);
-	fprintf(stderr, 
-		"Usage: %s [-t tracks] [-h heads] [-n sectors] "
-		"[-v label] [-1] [-4] [-8] [-f size] "
-		"[-N serialnumber] "
-		"[-k] [-B bootsector] [-r root_dir_len] [-L fat_len] "
-		"[-F] [-I fsVersion] [-C] [-c cluster_size] "
-		"[-H hidden_sectors] "
-#ifdef USE_XDF
-		"[-X] "
-#endif
-		"[-S hardsectorsize] [-M softsectorsize] [-3] "
-		"[-2 track0sectors] [-0 rate0] [-A rateany] [-a]"
-		"device\n", progname);
-	exit(1);
-}
-
-void mformat(int argc, char **argv, int dummy)
-{
-	int r; /* generic return value */
-	Fs_t Fs;
-	int hs, hs_set;
-	int arguse_2m = 0;
-	int sectors0=18; /* number of sectors on track 0 */
-	int create = 0;
-	int rate_0, rate_any;
-	int mangled;
-	int argssize=0; /* sector size */
-	int msize=0;
-	int fat32 = 0;
-	struct label_blk_t *labelBlock;
-	int bootOffset;
-
-#ifdef USE_XDF
-	int i;
-	int format_xdf = 0;
-	struct xdf_info info;
-#endif
-	struct bootsector *boot;
-	char *bootSector=0;
-	int c;
-	int keepBoot = 0;
-	struct device used_dev;
-	int argtracks, argheads, argsectors;
-	int tot_sectors;
-	int blocksize;
-
-	char *drive, name[EXPAND_BUF];
-
-	char label[VBUFSIZE], buf[MAX_SECTOR], shortlabel[13];
-	struct device *dev;
-	char errmsg[200];
-
-	unsigned long serial;
- 	int serial_set;
-	int fsVersion;
-
-	mt_off_t maxSize;
-
-	int Atari = 0; /* should we add an Atari-style serial number ? */
-#ifdef OS_Minix
-	char *devname;
-	struct device onedevice[2];
-	struct stat stbuf;
-#endif
- 
-	hs = hs_set = 0;
-	argtracks = 0;
-	argheads = 0;
-	argsectors = 0;
-	arguse_2m = 0;
-	argssize = 0x2;
-	label[0] = '\0';
-	serial_set = 0;
-	serial = 0;
-	fsVersion = 0;
-	
-	Fs.cluster_size = 0;
-	Fs.refs = 1;
-	Fs.dir_len = 0;
-	Fs.fat_len = 0;
-	Fs.Class = &FsClass;	
-	rate_0 = mtools_rate_0;
-	rate_any = mtools_rate_any;
-
-	/* get command line options */
-	while ((c = getopt(argc,argv,
-			   "148f:t:n:v:qub"
-			   "kB:r:L:IFCc:Xh:s:l:N:H:M:S:230:Aa"))!= EOF) {
-		switch (c) {
-			/* standard DOS flags */
-			case '1':
-				argheads = 1;
-				break;
-			case '4':
-				argsectors = 9;
-				argtracks = 40;
-				break;
-			case '8':
-				argsectors = 8;
-				argtracks = 40;
-				break;
-			case 'f':
-				r=old_dos_size_to_geom(atoi(optarg),
-						       &argtracks, &argheads,
-						       &argsectors);
-				if(r) {
-					fprintf(stderr, 
-						"Bad size %s\n", optarg);
-					exit(1);
-				}
-				break;
-			case 't':
-				argtracks = atoi(optarg);
-				break;
-
-			case 'n': /*non-standard*/
-			case 's':
-				argsectors = atoi(optarg);
-				break;
-
-			case 'l': /* non-standard */
-			case 'v':
-				strncpy(label, optarg, VBUFSIZE-1);
-				label[VBUFSIZE-1] = '\0';
-				break;
-
-			/* flags supported by Dos but not mtools */
-			case 'q':
-			case 'u':
-			case 'b':
-			/*case 's': leave this for compatibility */
-				fprintf(stderr, 
-					"Flag %c not supported by mtools\n",c);
-				exit(1);
-				
-
-
-			/* flags added by mtools */
-			case 'F':
-				fat32 = 1;
-				break;
-
-
-			case 'S':
-				argssize = atoi(optarg) | 0x80;
-				if(argssize < 0x81)
-					usage();
-				break;
-
-#ifdef USE_XDF
-			case 'X':
-				format_xdf = 1;
-				break;
-#endif
-
-			case '2':
-				arguse_2m = 0xff;
-				sectors0 = atoi(optarg);
-				break;
-			case '3':
-				arguse_2m = 0x80;
-				break;
-
-			case '0': /* rate on track 0 */
-				rate_0 = atoi(optarg);
-				break;
-			case 'A': /* rate on other tracks */
-				rate_any = atoi(optarg);
-				break;
-
-			case 'M':
-				msize = atoi(optarg);
-				if (msize % 256 || msize > 8192 )
-					usage();
-				break;
-
-			case 'N':
- 				serial = strtoul(optarg,0,16);
- 				serial_set = 1;
- 				break;
-			case 'a': /* Atari style serial number */
-				Atari = 1;
-				break;
-
-			case 'C':
-				create = O_CREAT;
-				break;
-
-			case 'H':
-				hs = atoi(optarg);
-				hs_set = 1;
-				break;
-
-			case 'I':
-				fsVersion = strtoul(optarg,0,0);
-				break;
-
-			case 'c':
-				Fs.cluster_size = atoi(optarg);
-				break;
-
-			case 'r': 
-				Fs.dir_len = strtoul(optarg,0,0);
-				break;
-			case 'L':
-				Fs.fat_len = strtoul(optarg,0,0);
-				break;
-
-
-			case 'B':
-				bootSector = optarg;
-				break;
-			case 'k':
-				keepBoot = 1;
-				break;
-			case 'h':
-				argheads = atoi(optarg);
-				break;
-
-			default:
-				usage();
-		}
-	}
-
-	if (argc - optind != 1 ||
-	    skip_drive(argv[optind]) == argv[optind])
-		usage();
-
-#ifdef USE_XDF
-	if(create && format_xdf) {
-		fprintf(stderr,"Create and XDF can't be used together\n");
-		exit(1);
-	}
-#endif
-	
-	drive = get_drive(argv[argc -1], NULL);
-
-#ifdef OS_Minix
-	devname = safe_malloc((9 + strlen(drive)) * sizeof(devname[0]));
-	strcpy(devname, "/dev/dosX");
-	if (isupper(drive[0]) && drive[1] == 0) {
-		/* single letter device name, use /dev/dos$drive */
-		devname[8]= drive[0];
-	} else
-	if (strchr(drive, '/') == NULL) {
-		/* a simple name, use /dev/$drive */
-		strcpy(devname+5, drive);
-	} else {
-		/* a pathname, use as is. */
-		strcpy(devname, drive);
-	}
-	if (stat(devname, &stbuf) != -1) {
-		memset(onedevice, 0, sizeof(onedevice));
-		onedevice[0].name = devname;
-		onedevice[0].drive = drive;
-		onedevice[1].name = NULL;
-		onedevice[1].drive = NULL;
-		dev = onedevice;
-	} else {
-		dev = devices;
-	}
-#else
-	dev = devices;
-#endif
-
-	/* check out a drive whose letter and parameters match */	
-	sprintf(errmsg, "Drive '%s:' not supported", drive);	
-	Fs.Direct = NULL;
-	blocksize = 0;
-	for(;dev->drive;dev++) {
-		FREE(&(Fs.Direct));
-		/* drive name */
-		if (strcmp(dev->drive, drive) != 0)
-			continue;
-		used_dev = *dev;
-
-		SET_INT(used_dev.tracks, argtracks);
-		SET_INT(used_dev.heads, argheads);
-		SET_INT(used_dev.sectors, argsectors);
-		SET_INT(used_dev.use_2m, arguse_2m);
-		SET_INT(used_dev.ssize, argssize);
-		if(hs_set)
-			used_dev.hidden = hs;
-		
-		expand(dev->name, name);
-#ifdef USING_NEW_VOLD
-		strcpy(name, getVoldName(dev, name));
-#endif
-
-#ifdef USE_XDF
-		if(!format_xdf) {
-#endif
-			Fs.Direct = 0;
-#ifdef USE_FLOPPYD
-			Fs.Direct = FloppydOpen(&used_dev, dev, name, O_RDWR | create,
-									errmsg, 0, 1);
-			if(Fs.Direct) {
-				maxSize = max_off_t_31;
-			}
-#endif
-			if(!Fs.Direct) {			
-				Fs.Direct = SimpleFileOpen(&used_dev, dev, name,
-										   O_RDWR | create,
-										   errmsg, 0, 1, &maxSize);
-			}
-#ifdef USE_XDF
-		} else {
-			used_dev.misc_flags |= USE_XDF_FLAG;
-			Fs.Direct = XdfOpen(&used_dev, name, O_RDWR,
-					    errmsg, &info);
-			if(Fs.Direct && !Fs.fat_len)
-				Fs.fat_len = info.FatSize;
-			if(Fs.Direct && !Fs.dir_len)
-				Fs.dir_len = info.RootDirSize;
-		}
-#endif
-
-		if (!Fs.Direct)
-			continue;
-
-#ifdef OS_linux
-		if ((!used_dev.tracks || !used_dev.heads || !used_dev.sectors) &&
-			(!IS_SCSI(dev))) {
-			int fd= get_fd(Fs.Direct);
-			struct stat buf;
-
-			if (fstat(fd, &buf) < 0) {
-				sprintf(errmsg, "Could not stat file (%s)", strerror(errno));
-				continue;						
-			}
-
-			if (S_ISBLK(buf.st_mode)) {
-				struct hd_geometry geom;
-				long size;
-				int sect_per_track;
-
-				if (ioctl(fd, HDIO_GETGEO, &geom) < 0) {
-					sprintf(errmsg, "Could not get geometry of device (%s)",
-							strerror(errno));
-					continue;
-				}
-
-				if (ioctl(fd, BLKGETSIZE, &size) < 0) {
-					sprintf(errmsg, "Could not get size of device (%s)",
-							strerror(errno));
-					continue;
-				}
-
-				sect_per_track = geom.heads * geom.sectors;
-				used_dev.heads = geom.heads;
-				used_dev.sectors = geom.sectors;
-				used_dev.hidden = geom.start % sect_per_track;
-				used_dev.tracks = (size + used_dev.hidden) / sect_per_track;
-			}
-		}
-#endif
-
-		/* no way to find out geometry */
-		if (!used_dev.tracks || !used_dev.heads || !used_dev.sectors){
-			sprintf(errmsg, 
-				"Unknown geometry "
-				"(You must tell the complete geometry "
-				"of the disk, \neither in /etc/mtools.conf or "
-				"on the command line) ");
-			continue;
-		}
-
-#if 0
-		/* set parameters, if needed */
-		if(SET_GEOM(Fs.Direct, &used_dev, 0xf0, boot)){
-			sprintf(errmsg,"Can't set disk parameters: %s", 
-				strerror(errno));
-			continue;
-		}
-#endif
-		Fs.sector_size = 512;
-		if( !(used_dev.use_2m & 0x7f)) {
-			Fs.sector_size = 128 << (used_dev.ssize & 0x7f);
-		}
-
-		SET_INT(Fs.sector_size, msize);
-		{
-		    int i;
-		    for(i = 0; i < 31; i++) {
-			if (Fs.sector_size == 1 << i) {
-			    Fs.sectorShift = i;
-			    break;
-			}
-		    }
-		    Fs.sectorMask = Fs.sector_size - 1;
-		}
-
-		if(!used_dev.blocksize || used_dev.blocksize < Fs.sector_size)
-			blocksize = Fs.sector_size;
-		else
-			blocksize = used_dev.blocksize;
-		
-		if(blocksize > MAX_SECTOR)
-			blocksize = MAX_SECTOR;
-
-		/* do a "test" read */
-		if (!create &&
-		    READS(Fs.Direct, (char *) buf, 0, Fs.sector_size) != 
-		    Fs.sector_size) {
-			sprintf(errmsg, 
-				"Error reading from '%s', wrong parameters?",
-				name);
-			continue;
-		}
-		break;
-	}
-
-
-	/* print error msg if needed */	
-	if ( dev->drive == 0 ){
-		FREE(&Fs.Direct);
-		fprintf(stderr,"%s: %s\n", argv[0],errmsg);
-		exit(1);
-	}
-
-	/* the boot sector */
-	boot = (struct bootsector *) buf;
-	if(bootSector) {
-		int fd;
-
-		fd = open(bootSector, O_RDONLY);
-		if(fd < 0) {
-			perror("open boot sector");
-			exit(1);
-		}
-		read(fd, buf, blocksize);
-		keepBoot = 1;
-	}
-	if(!keepBoot) {
-		memset((char *)boot, '\0', Fs.sector_size);
-		if(Fs.sector_size == 512 && !used_dev.partition) {
-			/* install fake partition table pointing to itself */
-			struct partition *partTable=(struct partition *)
-				(((char*) boot) + 0x1ae);
-			setBeginEnd(&partTable[1], 0,
-						used_dev.heads * used_dev.sectors * used_dev.tracks,
-						used_dev.heads, used_dev.sectors, 1, 0);
-		}
-	}
-	set_dword(boot->nhs, used_dev.hidden);
-
-	Fs.Next = buf_init(Fs.Direct,
-			   blocksize * used_dev.heads * used_dev.sectors,
-			   blocksize * used_dev.heads * used_dev.sectors,
-			   blocksize);
-	Fs.Buffer = 0;
-
-	boot->nfat = Fs.num_fat = 2;
-	if(!keepBoot)
-		set_word(boot->jump + 510, 0xaa55);
-	
-	/* get the parameters */
-	tot_sectors = used_dev.tracks * used_dev.heads * used_dev.sectors - 
-		DWORD(nhs);
-
-	set_word(boot->nsect, dev->sectors);
-	set_word(boot->nheads, dev->heads);
-
-	dev->fat_bits = comp_fat_bits(&Fs,dev->fat_bits, tot_sectors, fat32);
-
-	if(dev->fat_bits == 32) {
-		Fs.primaryFat = 0;
-		Fs.writeAllFats = 1;
-		Fs.fat_start = 32;
-		calc_fs_parameters_32(tot_sectors, &Fs, boot);
-
-		Fs.clus_start = Fs.num_fat * Fs.fat_len + Fs.fat_start;
-
-		/* extension flags: mirror fats, and use #0 as primary */
-		set_word(boot->ext.fat32.extFlags,0);
-
-		/* fs version.  What should go here? */
-		set_word(boot->ext.fat32.fsVersion,fsVersion);
-
-		/* root directory */
-		set_dword(boot->ext.fat32.rootCluster, Fs.rootCluster = 2);
-
-		/* info sector */
-		set_word(boot->ext.fat32.infoSector, Fs.infoSectorLoc = 1);
-		Fs.infoSectorLoc = 1;
-
-		/* no backup boot sector */
-		set_word(boot->ext.fat32.backupBoot, 6);
-		
-		labelBlock = & boot->ext.fat32.labelBlock;
-	} else {
-		Fs.infoSectorLoc = 0;
-		Fs.fat_start = 1;
-		calc_fs_parameters(&used_dev, tot_sectors, &Fs, boot);
-		Fs.dir_start = Fs.num_fat * Fs.fat_len + Fs.fat_start;
-		Fs.clus_start = Fs.dir_start + Fs.dir_len;
-		labelBlock = & boot->ext.old.labelBlock;
-
-	}
-	
-	if (!keepBoot)
-		/* only zero out physdrive if we don't have a template
-		 * bootsector */
-		labelBlock->physdrive = 0x00;
-	labelBlock->reserved = 0;
-	labelBlock->dos4 = 0x29;
-
-	if (!serial_set || Atari)
-		srandom((long)time (0));
-	if (!serial_set)
-		serial=random();
-	set_dword(labelBlock->serial, serial);	
-	if(!label[0])
-		strncpy(shortlabel, "NO NAME    ",11);
-	else
-		label_name(label, 0, &mangled, shortlabel);
-	strncpy(labelBlock->label, shortlabel, 11);
-	sprintf(labelBlock->fat_type, "FAT%2.2d  ", Fs.fat_bits);
-	labelBlock->fat_type[7] = ' ';
-
-	set_word(boot->secsiz, Fs.sector_size);
-	boot->clsiz = (unsigned char) Fs.cluster_size;
-	set_word(boot->nrsvsect, Fs.fat_start);
-
-	bootOffset = init_geometry_boot(boot, &used_dev, sectors0, 
-					rate_0, rate_any,
-					&tot_sectors, keepBoot);
-	if(!bootOffset) {
-		bootOffset = ((char *) labelBlock) - ((char *) boot) +
-			sizeof(struct label_blk_t);
-	}
-	if(Atari) {
-		boot->banner[4] = 0;
-		boot->banner[5] = random();
-		boot->banner[6] = random();
-		boot->banner[7] = random();
-	}		
-
-	if (create) {
-		WRITES(Fs.Direct, (char *) buf,
-		       sectorsToBytes((Stream_t*)&Fs, tot_sectors-1),
-		       Fs.sector_size);
-	}
-
-	if(!keepBoot)
-		inst_boot_prg(boot, bootOffset);
-	if(dev->use_2m & 0x7f)
-		Fs.num_fat = 1;
-	Fs.lastFatSectorNr = 0;
-	Fs.lastFatSectorData = 0;
-	zero_fat(&Fs, boot->descr);
-	Fs.freeSpace = Fs.num_clus;
-	Fs.last = 2;
-
-#ifdef USE_XDF
-	if(format_xdf)
-		for(i=0; 
-		    i < (info.BadSectors+Fs.cluster_size-1)/Fs.cluster_size; 
-		    i++)
-			fatEncode(&Fs, i+2, 0xfff7);
-#endif
-
-	format_root(&Fs, label, boot);
-	WRITES((Stream_t *)&Fs, (char *) boot, (mt_off_t) 0, Fs.sector_size);
-	if(Fs.fat_bits == 32 && WORD(ext.fat32.backupBoot) != MAX32) {
-		WRITES((Stream_t *)&Fs, (char *) boot, 
-		       sectorsToBytes((Stream_t*)&Fs, WORD(ext.fat32.backupBoot)),
-		       Fs.sector_size);
-	}
-	FLUSH((Stream_t *)&Fs); /* flushes Fs. 
-				 * This triggers the writing of the FAT */
-	FREE(&Fs.Next);
-	Fs.Class->freeFunc((Stream_t *)&Fs);
-#ifdef USE_XDF
-	if(format_xdf && isatty(0) && !getenv("MTOOLS_USE_XDF"))
-		fprintf(stderr,
-			"Note:\n"
-			"Remember to set the \"MTOOLS_USE_XDF\" environmental\n"
-			"variable before accessing this disk\n\n"
-			"Bourne shell syntax (sh, ash, bash, ksh, zsh etc):\n"
-			" export MTOOLS_USE_XDF=1\n\n"
-			"C shell syntax (csh and tcsh):\n"
-			" setenv MTOOLS_USE_XDF 1\n" );	
-#endif
-	exit(0);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/minfo.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/minfo.c	(revision 9)
+++ 	(revision )
@@ -1,172 +1,0 @@
-/*
- * mlabel.c
- * Make an MSDOS volume label
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mainloop.h"
-#include "vfat.h"
-#include "mtools.h"
-#include "nameclash.h"
-
-static void usage(void)
-{
-	fprintf(stderr, 
-		"Mtools version %s, dated %s\n", mversion, mdate);
-	fprintf(stderr, 
-		"Usage: %s [-v] drive\n\t-v Verbose\n", progname);
-	exit(1);
-}
-
-
-static void displayInfosector(Stream_t *Stream, struct bootsector *boot)
-{
-	InfoSector_t *infosec;
-
-	if(WORD(ext.fat32.infoSector) == MAX32)
-		return;
-
-	infosec = (InfoSector_t *) safe_malloc(WORD(secsiz));
-	force_read(Stream, (char *) infosec, 
-			   (mt_off_t) WORD(secsiz) * WORD(ext.fat32.infoSector),
-			   WORD(secsiz));
-	printf("\nInfosector:\n");
-	printf("signature=0x%08x\n", _DWORD(infosec->signature1));
-	if(_DWORD(infosec->count) != MAX32)
-		printf("free clusters=%u\n", _DWORD(infosec->count));
-	if(_DWORD(infosec->pos) != MAX32)
-		printf("last allocated cluster=%u\n", _DWORD(infosec->pos));
-}
-
-
-void minfo(int argc, char **argv, int type)
-{
-	struct bootsector boot0;
-#define boot (&boot0)
-	char name[EXPAND_BUF];
-	int media;
-	int tot_sectors;
-	struct device dev;
-	char *drive;
-	int verbose=0;
-	int c;
-	Stream_t *Stream;
-	struct label_blk_t *labelBlock;
-	
-	while ((c = getopt(argc, argv, "v")) != EOF) {
-		switch (c) {
-			case 'v':
-				verbose = 1;
-				break;
-			default:
-				usage();
-		}
-	}
-
-	if(argc == optind)
-		usage();
-
-	for(;optind < argc; optind++) {
-		if(skip_drive(argv[optind]) == argv[optind])
-			usage();
-		drive = get_drive(argv[optind], NULL);
-
-		if(! (Stream = find_device(drive, O_RDONLY, &dev, boot, 
-					   name, &media, 0)))
-			exit(1);
-
-		tot_sectors = DWORD(bigsect);
-		SET_INT(tot_sectors, WORD(psect));
-		printf("device information:\n");
-		printf("===================\n");
-		printf("filename=\"%s\"\n", name);
-		printf("sectors per track: %d\n", dev.sectors);
-		printf("heads: %d\n", dev.heads);
-		printf("cylinders: %d\n\n", dev.tracks);
-		printf("mformat command line: mformat -t %d -h %d -s %d ",
-		       dev.tracks, dev.heads, dev.sectors);
-		if(DWORD(nhs))
-			printf("-H %d ", DWORD(nhs));
-		printf("%s:\n", drive);
-		printf("\n");
-		
-		printf("bootsector information\n");
-		printf("======================\n");
-		printf("banner:\"%8s\"\n", boot->banner);
-		printf("sector size: %d bytes\n", WORD(secsiz));
-		printf("cluster size: %d sectors\n", boot->clsiz);
-		printf("reserved (boot) sectors: %d\n", WORD(nrsvsect));
-		printf("fats: %d\n", boot->nfat);
-		printf("max available root directory slots: %d\n", 
-		       WORD(dirents));
-		printf("small size: %d sectors\n", WORD(psect));
-		printf("media descriptor byte: 0x%x\n", boot->descr);
-		printf("sectors per fat: %d\n", WORD(fatlen));
-		printf("sectors per track: %d\n", WORD(nsect));
-		printf("heads: %d\n", WORD(nheads));
-		printf("hidden sectors: %d\n", DWORD(nhs));
-		printf("big size: %d sectors\n", DWORD(bigsect));
-
-		if(WORD(fatlen)) {
-		    labelBlock = &boot->ext.old.labelBlock;
-		} else {
-		    labelBlock = &boot->ext.fat32.labelBlock;
-		}
-
-		printf("physical drive id: 0x%x\n", 
-		       labelBlock->physdrive);
-		printf("reserved=0x%x\n", 
-		       labelBlock->reserved);
-		printf("dos4=0x%x\n", 
-		       labelBlock->dos4);
-		printf("serial number: %08X\n", 
-		       _DWORD(labelBlock->serial));
-		printf("disk label=\"%11.11s\"\n", 
-		       labelBlock->label);
-		printf("disk type=\"%8.8s\"\n", 
-		       labelBlock->fat_type);
-
-		if(!WORD(fatlen)){
-			printf("Big fatlen=%u\n",
-			       DWORD(ext.fat32.bigFat));
-			printf("Extended flags=0x%04x\n",
-			       WORD(ext.fat32.extFlags));
-			printf("FS version=0x%04x\n",
-			       WORD(ext.fat32.fsVersion));
-			printf("rootCluster=%u\n",
-			       DWORD(ext.fat32.rootCluster));
-			if(WORD(ext.fat32.infoSector) != MAX32)
-				printf("infoSector location=%d\n",
-				       WORD(ext.fat32.infoSector));
-			if(WORD(ext.fat32.backupBoot) != MAX32)
-				printf("backup boot sector=%d\n",
-				       WORD(ext.fat32.backupBoot));
-			displayInfosector(Stream,boot);
-		}
-
-		if(verbose) {
-			int size;
-			unsigned char *buf;
-
-			printf("\n");
-			size = WORD(secsiz);
-			
-			buf = (unsigned char *) malloc(size);
-			if(!buf) {
-				fprintf(stderr, "Out of memory error\n");
-				exit(1);
-			}
-
-			size = READS(Stream, buf, (mt_off_t) 0, size);
-			if(size < 0) {
-				perror("read boot sector");
-				exit(1);
-			}
-
-			print_sector("Boot sector hexdump", buf, size);
-		}
-	}
-
-	exit(0);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/misc.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/misc.c	(revision 9)
+++ 	(revision )
@@ -1,307 +1,0 @@
-/*
- * Miscellaneous routines.
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "stream.h"
-#include "vfat.h"
-#include "mtools.h"
-
-
-void printOom(void)
-{
-	fprintf(stderr, "Out of memory error");
-}
-
-char *get_homedir(void)
-{
-	struct passwd *pw;
-	uid_t uid;
-	char *homedir;
-	char *username;
-	
-	homedir = getenv ("HOME");    
-	/* 
-	 * first we call getlogin. 
-	 * There might be several accounts sharing one uid 
-	 */
-	if ( homedir )
-		return homedir;
-	
-	pw = 0;
-	
-	username = getenv("LOGNAME");
-	if ( !username )
-		username = getlogin();
-	if ( username )
-		pw = getpwnam( username);
-  
-	if ( pw == 0 ){
-		/* if we can't getlogin, look up the pwent by uid */
-		uid = geteuid();
-		pw = getpwuid(uid);
-	}
-	
-	/* we might still get no entry */
-	if ( pw )
-		return pw->pw_dir;
-	return 0;
-}
-
-
-static void get_mcwd_file_name(char *file)
-{
-	char *mcwd_path;
-	char *homedir;
-
-	mcwd_path = getenv("MCWD");
-	if (mcwd_path == NULL || *mcwd_path == '\0'){
-		homedir= get_homedir();
-		if(!homedir)
-			homedir="/tmp";
-		strncpy(file, homedir, MAXPATHLEN-6);
-		file[MAXPATHLEN-6]='\0';
-		strcat( file, "/.mcwd");
-	} else {
-		strncpy(file, mcwd_path, MAXPATHLEN);
-		file[MAXPATHLEN]='\0';
-	}
-}
-
-void unlink_mcwd()
-{
-	char file[MAXPATHLEN+1];
-	get_mcwd_file_name(file);
-	unlink(file);
-}
-
-FILE *open_mcwd(const char *mode)
-{
-	struct stat sbuf;
-	char file[MAXPATHLEN+1];
-	time_t now;
-	
-	get_mcwd_file_name(file);
-	if (*mode == 'r'){
-		if (stat(file, &sbuf) < 0)
-			return NULL;
-		/*
-		 * Ignore the info, if the file is more than 6 hours old
-		 */
-		getTimeNow(&now);
-		if (now - sbuf.st_mtime > 6 * 60 * 60) {
-			fprintf(stderr,
-				"Warning: \"%s\" is out of date, removing it\n",
-				file);
-			unlink(file);
-			return NULL;
-		}
-	}
-	
-	return  fopen(file, mode);
-}
-	
-
-/* Fix the info in the MCWD file to be a proper directory name.
- * Always has a leading separator.  Never has a trailing separator
- * (unless it is the path itself).  */
-
-const char *fix_mcwd(char *ans)
-{
-	FILE *fp;
-	char *s;
-	char buf[MAX_PATH];
-
-	fp = open_mcwd("r");
-	if(!fp){
-		strcpy(ans, "A:/");
-		return ans;
-	}
-
-	if (!fgets(buf, MAX_PATH, fp))
-		return("A:/");
-
-	buf[strlen(buf) -1] = '\0';
-	fclose(fp);
-					/* drive letter present? */
-	s = skip_drive(buf);
-	if (s > buf) {
-		strncpy(ans, buf, s - buf);
-		ans[s - buf] = '\0';
-	} else 
-		strcpy(ans, "A:");
-					/* add a leading separator */
-	if (*s != '/' && *s != '\\') {
-		strcat(ans, "/");
-		strcat(ans, s);
-	} else
-		strcat(ans, s);
-
-#if 0
-					/* translate to upper case */
-	for (s = ans; *s; ++s) {
-		*s = toupper(*s);
-		if (*s == '\\')
-			*s = '/';
-	}
-#endif
-					/* if only drive, colon, & separator */
-	if (strlen(ans) == 3)
-		return(ans);
-					/* zap the trailing separator */
-	if (*--s == '/')
-		*s = '\0';
-	return ans;
-}
-
-void *safe_malloc(size_t size)
-{
-	void *p;
-
-	p = malloc(size);
-	if(!p){
-		printOom();
-		exit(1);
-	}
-	return p;
-}
-
-void print_sector(char *message, unsigned char *data, int size)
-{
-	int col;
-	int row;
-
-	printf("%s:\n", message);
-	
-	for(row = 0; row * 16 < size; row++){
-		printf("%03x  ", row * 16);
-		for(col = 0; col < 16; col++)			
-			printf("%02x ", data [row*16+col]);
-		for(col = 0; col < 16; col++) {
-			if(isprint(data [row*16+col]))
-				printf("%c", data [row*16+col]);
-			else
-				printf(".");
-		}
-		printf("\n");
-	}
-}
-
-
-time_t getTimeNow(time_t *now)
-{
-	static int haveTime = 0;
-	static time_t sharedNow;
-
-	if(!haveTime) {
-		time(&sharedNow);
-		haveTime = 1;
-	}
-	if(now)
-		*now = sharedNow;
-	return sharedNow;
-}
-
-char *skip_drive(const char *filename)
-{
-	char *p;
-
-	/* Skip drive name.  Return pointer just after the `:', or a pointer
-	 * to the start of the file name if there is is no drive name.
-	 */
-	p = strchr(filename, ':');
-	return (p == NULL || p == filename) ? (char *) filename : p + 1;
-}
-
-char *get_drive(const char *filename, const char *def)
-{
-	const char *path;
-	char *drive;
-	const char *rest;
-	size_t len;
-
-	/* Return the drive name part of a full filename. */
-
-	path = filename;
-	rest = skip_drive(path);
-	if (rest == path) {
-		if (def == NULL) def = "A:";
-		path = def;
-		rest = skip_drive(path);
-		if (rest == path) {
-			path = "A:";
-			rest = path+2;
-		}
-	}
-	len = rest - path;
-	drive = safe_malloc(len * sizeof(drive[0]));
-	len--;
-	memcpy(drive, path, len);
-	drive[len] = 0;
-	if (len == 1) drive[0] = toupper(drive[0]);
-	return drive;
-}
-
-#if 0
-
-#undef free
-#undef malloc
-
-static int total=0;
-
-void myfree(void *ptr)
-{
-	int *size = ((int *) ptr)-1;
-	total -= *size;
-	fprintf(stderr, "freeing %d bytes at %p total alloced=%d\n",
-		*size, ptr, total);
-	free(size);
-}
-
-void *mymalloc(size_t size)
-{
-	int *ptr;
-	ptr = (int *)malloc(size+sizeof(int));
-	if(!ptr)
-		return 0;
-	*ptr = size;
-	ptr++;
-	total += size;
-	fprintf(stderr, "allocating %d bytes at %p total allocated=%d\n",
-		size, ptr, total);
-	return (void *) ptr;
-}
-
-void *mycalloc(size_t nmemb, size_t size)
-{
-	void *ptr = mymalloc(nmemb * size);
-	if(!ptr)
-		return 0;
-	memset(ptr, 0, size);
-	return ptr;
-}
-
-void *myrealloc(void *ptr, size_t size)
-{
-	int oldsize = ((int *)ptr) [-1];
-	void *new = mymalloc(size);
-	if(!new)
-		return 0;
-	memcpy(new, ptr, oldsize);
-	myfree(ptr);
-	return new;
-}
-
-char *mystrdup(char *src)
-{
-	char *dest;
-	dest = mymalloc(strlen(src)+1);
-	if(!dest)
-		return 0;
-	strcpy(dest, src);
-	return dest;
-}
-
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/missFuncs.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/missFuncs.c	(revision 9)
+++ 	(revision )
@@ -1,386 +1,0 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
-This file contains excerpts of the GNU C Library.
-
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-The GNU C Library 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
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
-
-#include "sysincludes.h"
-#include "mtools.h"
-
-#ifndef HAVE_STRDUP
-
-
-char *strdup(const char *str)
-{
-    char *nstr;
-
-    if (str == (char*)0)
-        return 0;
-
-    nstr = (char*)malloc((strlen(str) + 1));
-
-    if (nstr == (char*)0)
-    {
-        (void)fprintf(stderr, "strdup(): not enough memory to duplicate `%s'\n",
-		      str);
-	exit(1);
-    }
-
-    (void)strcpy(nstr, str);
-
-    return nstr;
-}
-#endif /* HAVE_STRDUP */
-
-
-#ifndef HAVE_MEMCPY
-/*
- * Copy contents of memory (with possible overlapping).
- */
-char *memcpy(char *s1, const char *s2, size_t n)
-{
-	bcopy(s2, s1, n);
-	return(s1);
-}
-#endif
-
-#ifndef HAVE_MEMSET
-/*
- * Copies the character c, n times to string s
- */
-char *memset(char *s, char c, size_t n)
-{
-	char *s1 = s;
-
-	while (n > 0) {
-		--n;
-		*s++ = c;
-	}
-	return(s1);
-}
-#endif /* HAVE_MEMSET */
-
-
-#ifndef HAVE_STRCHR
-
-char * strchr (const char* s, int c)
-{
-	if (!s) return NULL;
-	while (*s && *s != c) s++;
-	if (*s) 
-		return (char*) s;
-	else
-		return NULL;
-}
-
-#endif
-
-#ifndef HAVE_STRRCHR
-
-char * strrchr (const char* s1, int c) 
-{
-	char* s = (char*) s1;
-	char* start = (char*) s;
-	if (!s) return NULL;
-	s += strlen(s)-1;
-	while (*s != c && (unsigned long) s != (unsigned long) start) s--;
-	if ((unsigned long) s == (unsigned long) start && *s != c)
-		return NULL;
-	else
-		return s;
-}
-
-#endif
-
-#ifndef HAVE_STRPBRK
-/*
- * Return ptr to first occurrence of any character from `brkset'
- * in the character string `string'; NULL if none exists.
- */
-char *strpbrk(const char *string, const char *brkset)
-{
-	register char *p;
-
-	if (!string || !brkset)
-		return(0);
-	do {
-		for (p = brkset; *p != '\0' && *p != *string; ++p)
-			;
-		if (*p != '\0')
-			return(string);
-	}
-	while (*string++);
-	return(0);
-}
-#endif /* HAVE_STRPBRK */
-
-
-#ifndef HAVE_STRTOUL
-static int getdigit(char a, int max)
-{
-	int dig;
-	
-	if(a < '0')
-		return -1;
-	if(a <= '9') {
-		dig = a - '0';
-	} else if(a >= 'a')
-		dig = a - 'a' + 10;
-	else if(a >= 'A')
-		dig = a - 'A' + 10;
-	if(dig >= max)
-		return -1;
-	else
-		return dig;
-}
-
-unsigned long strtoul(const char *string, char **eptr, int base)
-{
-	int accu, dig;
-
-	if(base < 1 || base > 36) {
-		if(string[0] == '0') {
-			switch(string[1]) {
-			       	case 'x':
-				case 'X':
-					return strtoul(string+2, eptr, 16);
-				case 'b':
-			       	case 'B':
-					return strtoul(string+2, eptr, 2);
-				default:
-					return strtoul(string, eptr, 8);
-			}
-		}
-	       	return strtoul(string, eptr, 10);
-	}
-	if(base == 16 && string[0] == '0' &&
-	   (string[1] == 'x' || string[1] == 'X'))
-		string += 2;
-
-	if(base == 2 && string[0] == '0' &&
-	   (string[1] == 'b' || string[1] == 'B'))
-		string += 2;
-	accu = 0;
-	while( (dig = getdigit(*string, base)) != -1 ) {
-		accu = accu * base + dig;
-		string++;
-	}
-	if(eptr)
-		*eptr = (char *) string;
-	return accu;
-}
-#endif /* HAVE_STRTOUL */
-
-#ifndef HAVE_STRTOL
-long strtol(const char *string, char **eptr, int base)
-{
-	long l;
-
-	if(*string == '-') {
-		return -(long) strtoul(string+1, eptr, base);
-	} else {
-		if (*string == '+')
-			string ++;
-		return (long) strtoul(string, eptr, base);
-	}
-}
-#endif
-
-
-
-#ifndef HAVE_STRSPN
-/* Return the length of the maximum initial segment
-   of S which contains only characters in ACCEPT.  */
-size_t strspn(const char *s, const char *accept)
-{
-  register char *p;
-  register char *a;
-  register size_t count = 0;
-
-  for (p = s; *p != '\0'; ++p)
-    {
-      for (a = accept; *a != '\0'; ++a)
-	if (*p == *a)
-	  break;
-      if (*a == '\0')
-	return count;
-      else
-	++count;
-    }
-
-  return count;
-}
-#endif /* HAVE_STRSPN */
-
-#ifndef HAVE_STRCSPN
-/* Return the length of the maximum inital segment of S
-   which contains no characters from REJECT.  */
-size_t strcspn (const char *s, const char *reject)
-{
-  register size_t count = 0;
-
-  while (*s != '\0')
-    if (strchr (reject, *s++) == NULL)
-      ++count;
-    else
-      return count;
-
-  return count;
-}
-
-#endif /* HAVE_STRCSPN */
-
-#ifndef HAVE_STRERROR
-
-#ifndef DECL_SYS_ERRLIST
-extern char *sys_errlist[];
-#endif
-
-char *strerror(int errno)
-{
-  return sys_errlist[errno];
-}
-#endif
-
-#ifndef HAVE_STRCASECMP
-/* Compare S1 and S2, ignoring case, returning less than, equal to or
-   greater than zero if S1 is lexiographically less than,
-   equal to or greater than S2.  */
-int strcasecmp(const char *s1, const char *s2)
-{
-  register const unsigned char *p1 = (const unsigned char *) s1;
-  register const unsigned char *p2 = (const unsigned char *) s2;
-  unsigned char c1, c2;
-
-  if (p1 == p2)
-    return 0;
-
-  do
-    {
-      c1 = tolower (*p1++);
-      c2 = tolower (*p2++);
-      if (c1 == '\0')
-	break;
-    }
-  while (c1 == c2);
-
-  return c1 - c2;
-}
-#endif
-
-
-
-#ifndef HAVE_STRCASECMP
-/* Compare S1 and S2, ignoring case, returning less than, equal to or
-   greater than zero if S1 is lexiographically less than,
-   equal to or greater than S2.  */
-int strncasecmp(const char *s1, const char *s2, size_t n)
-{
-  register const unsigned char *p1 = (const unsigned char *) s1;
-  register const unsigned char *p2 = (const unsigned char *) s2;
-  unsigned char c1, c2;
-
-  if (p1 == p2)
-    return 0;
-
-  c1 = c2 = 1;
-  while (c1 && c1 == c2 && n-- > 0)
-    {
-      c1 = tolower (*p1++);
-      c2 = tolower (*p2++);
-    }
-
-  return c1 - c2;
-}
-#endif
-
-#ifndef HAVE_GETPASS
-char *getpass(const char *prompt)
-{
-	static char password[129];
-	int l;
-
-	fprintf(stderr,"%s",prompt);
-	fgets(password, 128, stdin);
-	l = strlen(password);
-	if(l && password[l-1] == '\n')
-		password[l-1] = '\0';
-	return password;
-
-}
-#endif
-
-#ifndef HAVE_ATEXIT
-
-#ifdef HAVE_ON_EXIT
-int atexit(void (*function)(void))
-{
-	return on_exit( (void(*)(int,void*)) function, 0);
-}
-#else
-
-typedef struct exitCallback {
-	void (*function) (void);
-	struct exitCallback *next;
-} exitCallback_t;
-
-static exitCallback_t *callback = 0;
-
-int atexit(void (*function) (void))
-{
-	exitCallback_t *newCallback;
-		
-	newCallback = New(exitCallback_t);
-	if(!newCallback) {
-		printOom();
-		exit(1);
-	}
-	newCallback->function = function;
-	newCallback->next = callback;
-	callback = newCallback;
-	return 0;
-}
-#undef exit
-
-void myexit(int code)
-{
-  void (*function)(void);
-
-  while(callback) {
-    function = callback->function;
-    callback = callback->next;
-    function();
-  }
-  exit(code);
-}
-
-#endif
-
-#endif
-
-/*#ifndef HAVE_BASENAME*/
-const char *_basename(const char *filename)
-{
-	char *ptr;
-
-	ptr = strrchr(filename, '/');
-	if(ptr)
-		return ptr+1;
-	else
-		return filename;
-}
-/*#endif*/
-
-
Index: trunk/minix/commands/i386/mtools-3.9.7/mk_direntry.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mk_direntry.c	(revision 9)
+++ 	(revision )
@@ -1,618 +1,0 @@
-/*
- * mk_direntry.c
- * Make new directory entries, and handles name clashes
- *
- */
-
-/*
- * This file is used by those commands that need to create new directory entries
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "nameclash.h"
-#include "fs.h"
-#include "stream.h"
-#include "mainloop.h"
-
-static inline int ask_rename(ClashHandling_t *ch,
-			     char *longname, int isprimary, char *argname)
-{
-	char shortname[13];
-	int mangled;
-
-	/* TODO: Would be nice to suggest "autorenamed" version of name, press 
-	 * <Return> to get it.
-	 */
-#if 0
-	fprintf(stderr,"Entering ask_rename, isprimary=%d.\n", isprimary);
-#endif
-
-	if(!opentty(0))
-		return 0;
-
-#define maxsize (isprimary ?  MAX_VNAMELEN+1 : 11+1)
-#define name (isprimary ? argname : shortname)
-
-	mangled = 0;
-	do {
-		fprintf(stderr, "New %s name for \"%s\": ",
-			isprimary ? "primary" : "secondary", longname);
-		fflush(stderr);
-		if (! fgets(name, maxsize, opentty(0)))
-			return 0;
-
-		/* Eliminate newline(s) in the file name */
-		name[strlen(name)-1]='\0';
-		if (!isprimary)
-			ch->name_converter(shortname,0, &mangled, argname);
-	} while (mangled & 1);
-	return 1;
-#undef maxsize
-#undef name
-}
-
-static inline clash_action ask_namematch(char *name, int isprimary, 
-					 ClashHandling_t *ch, int no_overwrite,
-					 int reason)
-{
-	char ans[10];
-	clash_action a;
-	int perm;
-	char unix_shortname[13];
-
-
-#define EXISTS 0
-#define RESERVED 1
-#define ILLEGALS 2
-
-	static const char *reasons[]= {
-		"already exists",
-		"is reserved",
-		"contains illegal character(s)"};
-
-
-	if (!isprimary)
-		name = unix_normalize(unix_shortname, name, name+8);
-
-	a = ch->action[isprimary];
-
-	if(a == NAMEMATCH_NONE && !opentty(1)) {
-		/* no default, and no tty either . Skip the troublesome file */
-		return NAMEMATCH_SKIP;
-	}
-
-	perm = 0;
-	while (a == NAMEMATCH_NONE) {
-		fprintf(stderr, "%s file name \"%s\" %s.\n",
-			isprimary ? "Long" : "Short", name, reasons[reason]);
-		fprintf(stderr,
-			"a)utorename A)utorename-all r)ename R)ename-all ");
-		if(!no_overwrite)
-			fprintf(stderr,"o)verwrite O)verwrite-all");
-		fprintf(stderr,
-			"\ns)kip S)kip-all q)uit (aArR");
-		if(!no_overwrite)
-			fprintf(stderr,"oO");
-		fprintf(stderr,"sSq): ");
-		fflush(stderr);
-		fflush(opentty(1));
-		if (mtools_raw_tty) {
-			int rep;
-			rep = fgetc(opentty(1));			
-			fputs("\n", stderr);
-			if(rep == EOF)
-				ans[0] = 'q';
-			else
-				ans[0] = rep;
-		} else {
-			fgets(ans, 9, opentty(0));
-		}
-		perm = isupper((unsigned char)ans[0]);
-		switch(tolower((unsigned char)ans[0])) {
-			case 'a':
-				a = NAMEMATCH_AUTORENAME;
-				break;
-			case 'r':
-				if(isprimary)
-					a = NAMEMATCH_PRENAME;
-				else
-					a = NAMEMATCH_RENAME;
-				break;
-			case 'o':
-				if(no_overwrite)
-					continue;
-				a = NAMEMATCH_OVERWRITE;
-				break;
-			case 's':
-				a = NAMEMATCH_SKIP;
-				break;
-			case 'q':
-				perm = 0;
-				a = NAMEMATCH_QUIT;
-				break;
-			default:
-				perm = 0;
-		}
-	}
-
-	/* Keep track of this action in case this file collides again */
-	ch->action[isprimary]  = a;
-	if (perm)
-		ch->namematch_default[isprimary] = a;
-
-	/* if we were asked to overwrite be careful. We can't set the action
-	 * to overwrite, else we get won't get a chance to specify another
-	 * action, should overwrite fail. Indeed, we'll be caught in an
-	 * infinite loop because overwrite will fail the same way for the
-	 * second time */
-	if(a == NAMEMATCH_OVERWRITE)
-		ch->action[isprimary] = NAMEMATCH_NONE;
-	return a;
-}
-
-/* Returns:
- * 2 if file is to be overwritten
- * 1 if file was renamed
- * 0 if it was skipped
- *
- * If a short name is involved, handle conversion between the 11-character
- * fixed-length record DOS name and a literal null-terminated name (e.g.
- * "COMMAND  COM" (no null) <-> "COMMAND.COM" (null terminated)).
- *
- * Also, immediately copy the original name so that messages can use it.
- */
-static inline clash_action process_namematch(char *name,
-					     char *longname,
-					     int isprimary,
-					     ClashHandling_t *ch,
-					     int no_overwrite,
-					     int reason)
-{
-	clash_action action;
-
-#if 0
-	fprintf(stderr,
-		"process_namematch: name=%s, default_action=%d, ask=%d.\n",
-		name, default_action, ch->ask);
-#endif
-
-	action = ask_namematch(name, isprimary, ch, no_overwrite, reason);
-
-	switch(action){
-	case NAMEMATCH_QUIT:
-		got_signal = 1;
-		return NAMEMATCH_SKIP;
-	case NAMEMATCH_SKIP:
-		return NAMEMATCH_SKIP;
-	case NAMEMATCH_RENAME:
-	case NAMEMATCH_PRENAME:
-		/* We need to rename the file now.  This means we must pass
-		 * back through the loop, a) ensuring there isn't a potential
-		 * new name collision, and b) finding a big enough VSE.
-		 * Change the name, so that it won't collide again.
-		 */
-		ask_rename(ch, longname, isprimary, name);
-		return action;
-	case NAMEMATCH_AUTORENAME:
-		/* Very similar to NAMEMATCH_RENAME, except that we need to
-		 * first generate the name.
-		 * TODO: Remember previous name so we don't
-		 * keep trying the same one.
-		 */
-		if (isprimary) {
-			autorename_long(name, 1);
-			return NAMEMATCH_PRENAME;
-		} else {
-			autorename_short(name, 1);
-			return NAMEMATCH_RENAME;
-		}
-	case NAMEMATCH_OVERWRITE:
-		if(no_overwrite)
-			return NAMEMATCH_SKIP;
-		else
-			return NAMEMATCH_OVERWRITE;
-	default:
-		return NAMEMATCH_NONE;
-	}
-}
-
-
-static void clear_scan(char *longname, int use_longname, struct scan_state *s)
-{
-	s->shortmatch = s->longmatch = s->slot = -1;
-	s->free_end = s->got_slots = s->free_start = 0;
-
-	if (use_longname & 1)
-                s->size_needed = 2 + (strlen(longname)/VSE_NAMELEN);
-	else
-                s->size_needed = 1;
-}
-
-
-static int contains_illegals(const char *string, const char *illegals)
-{
-	for(; *string ; string++)
-		if((*string < ' ' && *string != '\005' && !(*string & 0x80)) ||
-		   strchr(illegals, *string))
-			return 1;
-	return 0;
-}
-
-static int is_reserved(char *ans, int islong)
-{
-	int i;
-	static const char *dev3[] = {"CON", "AUX", "PRN", "NUL", "   "};
-	static const char *dev4[] = {"COM", "LPT" };
-
-	for (i = 0; i < sizeof(dev3)/sizeof(*dev3); i++)
-		if (!strncasecmp(ans, dev3[i], 3) &&
-		    ((islong && !ans[3]) ||
-		     (!islong && !strncmp(ans+3,"     ",5))))
-			return 1;
-
-	for (i = 0; i < sizeof(dev4)/sizeof(*dev4); i++)
-		if (!strncasecmp(ans, dev4[i], 3) &&
-		    (ans[3] >= '1' && ans[3] <= '4') &&
-		    ((islong && !ans[4]) ||
-		     (!islong && !strncmp(ans+4,"    ",4))))
-			return 1;
-	
-	return 0;
-}
-
-static inline clash_action get_slots(Stream_t *Dir,
-				     char *dosname, char *longname,
-				     struct scan_state *ssp,
-				     ClashHandling_t *ch)
-{
-	int error;
-	clash_action ret;
-	int match=0;
-	direntry_t entry;
-	int isprimary;
-	int no_overwrite;
-	int reason;
-	int pessimisticShortRename;
-
-	pessimisticShortRename = (ch->action[0] == NAMEMATCH_AUTORENAME);
-
-	entry.Dir = Dir;
-	no_overwrite = 1;
-	if((is_reserved(longname,1)) ||
-	   longname[strspn(longname,". ")] == '\0'){
-		reason = RESERVED;
-		isprimary = 1;
-	} else if(contains_illegals(longname,long_illegals)) {
-		reason = ILLEGALS;
-		isprimary = 1;
-	} else if(is_reserved(dosname,0)) {
-		reason = RESERVED;
-		ch->use_longname = 1;
-		isprimary = 0;
-	} else if(contains_illegals(dosname,short_illegals)) {
-		reason = ILLEGALS;
-		ch->use_longname = 1;
-		isprimary = 0;
-	} else {
-		reason = EXISTS;
-		clear_scan(longname, ch->use_longname, ssp);
-		switch (lookupForInsert(Dir, dosname, longname, ssp,
-								ch->ignore_entry, 
-								ch->source_entry,
-								pessimisticShortRename && 
-								ch->use_longname)) {
-			case -1:
-				return NAMEMATCH_ERROR;
-				
-			case 0:
-				return NAMEMATCH_SKIP; 
-				/* Single-file error error or skip request */
-				
-			case 5:
-				return NAMEMATCH_GREW;
-				/* Grew directory, try again */
-				
-			case 6:
-				return NAMEMATCH_SUCCESS; /* Success */
-		}	    
-		match = -2;
-		if (ssp->longmatch > -1) {
-			/* Primary Long Name Match */
-#ifdef debug
-			fprintf(stderr,
-				"Got longmatch=%d for name %s.\n", 
-				longmatch, longname);
-#endif			
-			match = ssp->longmatch;
-			isprimary = 1;
-		} else if ((ch->use_longname & 1) && (ssp->shortmatch != -1)) {
-			/* Secondary Short Name Match */
-#ifdef debug
-			fprintf(stderr,
-				"Got secondary short name match for name %s.\n", 
-				longname);
-#endif
-
-			match = ssp->shortmatch;
-			isprimary = 0;
-		} else if (ssp->shortmatch >= 0) {
-			/* Primary Short Name Match */
-#ifdef debug
-			fprintf(stderr,
-				"Got primary short name match for name %s.\n", 
-				longname);
-#endif
-			match = ssp->shortmatch;
-			isprimary = 1;
-		} else 
-			return NAMEMATCH_RENAME;
-
-		if(match > -1) {
-			entry.entry = match;
-			dir_read(&entry, &error);
-			if (error)
-			    return NAMEMATCH_ERROR;
-			/* if we can't overwrite, don't propose it */
-			no_overwrite = (match == ch->source || IS_DIR(&entry));
-		}
-	}
-	ret = process_namematch(isprimary ? longname : dosname, longname,
-				isprimary, ch, no_overwrite, reason);
-	
-	if (ret == NAMEMATCH_OVERWRITE && match > -1){
-		if((entry.dir.attr & 0x5) &&
-		   (ask_confirmation("file is read only, overwrite anyway (y/n) ? ",0,0)))
-			return NAMEMATCH_RENAME;
-		
-		/* Free up the file to be overwritten */
-		if(fatFreeWithDirentry(&entry))
-			return NAMEMATCH_ERROR;
-		
-#if 0
-		if(isprimary &&
-		   match - ssp->match_free + 1 >= ssp->size_needed){
-			/* reuse old entry and old short name for overwrite */
-			ssp->free_start = match - ssp->size_needed + 1;
-			ssp->free_size = ssp->size_needed;
-			ssp->slot = match;
-			ssp->got_slots = 1;
-			strncpy(dosname, dir.name, 3);
-			strncpy(dosname + 8, dir.ext, 3);
-			return ret;
-		} else
-#endif
-			{
-			entry.dir.name[0] = DELMARK;
-			dir_write(&entry);
-			return NAMEMATCH_RENAME;
-		}
-	}
-
-	return ret;
-}
-
-
-static inline int write_slots(Stream_t *Dir,
-			      char *dosname, 
-			      char *longname,
-			      struct scan_state *ssp,
-			      write_data_callback *cb,
-			      void *arg,
-			      int Case)
-{
-	direntry_t entry;
-
-	/* write the file */
-	if (fat_error(Dir))
-		return 0;
-
-	entry.Dir = Dir;
-	entry.entry = ssp->slot;
-	strncpy(entry.name, longname, sizeof(entry.name)-1);
-	entry.name[sizeof(entry.name)-1]='\0';
-	entry.dir.Case = Case & (EXTCASE | BASECASE);
-	if (cb(dosname, longname, arg, &entry) >= 0) {
-		if ((ssp->size_needed > 1) &&
-		    (ssp->free_end - ssp->free_start >= ssp->size_needed)) {
-			ssp->slot = write_vfat(Dir, dosname, longname,
-					       ssp->free_start, &entry);
-		} else {
-			ssp->size_needed = 1;
-			write_vfat(Dir, dosname, 0,
-				   ssp->free_start, &entry);
-		}
-		/* clear_vses(Dir, ssp->free_start + ssp->size_needed, 
-		   ssp->free_end); */
-	} else
-		return 0;
-
-	return 1;	/* Successfully wrote the file */
-}
-
-static void stripspaces(char *name)
-{
-	char *p,*non_space;
-
-	non_space = name;
-	for(p=name; *p; p++)
-		if (*p != ' ')
-			non_space = p;
-	if(name[0])
-		non_space[1] = '\0';
-}
-
-
-int _mwrite_one(Stream_t *Dir,
-		char *argname,
-		char *shortname,
-		write_data_callback *cb,
-		void *arg,
-		ClashHandling_t *ch)
-{
-	char longname[VBUFSIZE];
-	const char *dstname;
-	char dosname[13];
-	int expanded;
-	struct scan_state scan;
-	clash_action ret;
-
-	expanded = 0;
-
-	if(isSpecial(argname)) {
-		fprintf(stderr, "Cannot create entry named . or ..\n");
-		return -1;
-	}
-
-	if(ch->name_converter == dos_name) {
-		if(shortname)
-			stripspaces(shortname);
-		if(argname)
-			stripspaces(argname);
-	}
-
-	if(shortname){
-		ch->name_converter(shortname,0, &ch->use_longname, dosname);
-		if(ch->use_longname & 1){
-			/* short name mangled, treat it as a long name */
-			argname = shortname;
-			shortname = 0;
-		}
-	}
-						
-	/* Skip drive letter */
-	dstname = skip_drive(argname);
-
-	/* Copy original argument dstname to working value longname */
-	strncpy(longname, dstname, VBUFSIZE-1);
-
-	if(shortname) {
-		ch->name_converter(shortname,0, &ch->use_longname, dosname);
-		if(strcmp(shortname, longname))
-			ch->use_longname |= 1;
-	} else
-		ch->name_converter(longname,0, &ch->use_longname, dosname);
-
-	ch->action[0] = ch->namematch_default[0];
-	ch->action[1] = ch->namematch_default[1];
-
-	while (1) {
-		switch((ret=get_slots(Dir, dosname, longname,
-				      &scan, ch))){
-			case NAMEMATCH_ERROR:
-				return -1;	/* Non-file-specific error, 
-						 * quit */
-				
-			case NAMEMATCH_SKIP:
-				return -1;	/* Skip file (user request or 
-						 * error) */
-
-			case NAMEMATCH_PRENAME:
-				ch->name_converter(longname,0,
-						   &ch->use_longname, dosname);
-				continue;
-			case NAMEMATCH_RENAME:
-				continue;	/* Renamed file, loop again */
-
-			case NAMEMATCH_GREW:
-				/* No collision, and not enough slots.
-				 * Try to grow the directory
-				 */
-				if (expanded) {	/* Already tried this 
-						 * once, no good */
-					fprintf(stderr, 
-						"%s: No directory slots\n",
-						progname);
-					return -1;
-				}
-				expanded = 1;
-				
-				if (dir_grow(Dir, scan.max_entry))
-					return -1;
-				continue;
-			case NAMEMATCH_OVERWRITE:
-			case NAMEMATCH_SUCCESS:
-				return write_slots(Dir, dosname, longname,
-						   &scan, cb, arg,
-						   ch->use_longname);
-			default:
-				fprintf(stderr,
-					"Internal error: clash_action=%d\n",
-					ret);
-				return -1;
-		}
-
-	}
-}
-
-int mwrite_one(Stream_t *Dir,
-	       const char *_argname,
-	       const char *_shortname,
-	       write_data_callback *cb,
-	       void *arg,
-	       ClashHandling_t *ch)
-{
-	char *argname;
-	char *shortname;
-	int ret;
-
-	if(_argname)
-		argname = strdup(_argname);
-	else
-		argname = 0;
-	if(_shortname)
-		shortname = strdup(_shortname);
-	else
-		shortname = 0;
-	ret = _mwrite_one(Dir, argname, shortname, cb, arg, ch);
-	if(argname)
-		free(argname);
-	if(shortname)
-		free(shortname);
-	return ret;
-}
-
-void init_clash_handling(ClashHandling_t *ch)
-{
-	ch->ignore_entry = -1;
-	ch->source_entry = -2;
-	ch->nowarn = 0;	/*Don't ask, just do default action if name collision */
-	ch->namematch_default[0] = NAMEMATCH_AUTORENAME;
-	ch->namematch_default[1] = NAMEMATCH_NONE;
-	ch->name_converter = dos_name; /* changed by mlabel */
-	ch->source = -2;
-}
-
-int handle_clash_options(ClashHandling_t *ch, char c)
-{
-	int isprimary;
-	if(isupper(c))
-		isprimary = 0;
-	else
-		isprimary = 1;
-	c = tolower(c);
-	switch(c) {
-		case 'o':
-			/* Overwrite if primary name matches */
-			ch->namematch_default[isprimary] = NAMEMATCH_OVERWRITE;
-			return 0;
-		case 'r':
-				/* Rename primary name interactively */
-			ch->namematch_default[isprimary] = NAMEMATCH_RENAME;
-			return 0;
-		case 's':
-			/* Skip file if primary name collides */
-			ch->namematch_default[isprimary] = NAMEMATCH_SKIP;
-			return 0;
-		case 'm':
-			ch->namematch_default[isprimary] = NAMEMATCH_NONE;
-			return 0;
-		case 'a':
-			ch->namematch_default[isprimary] = NAMEMATCH_AUTORENAME;
-			return 0;
-		default:
-			return -1;
-	}
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mlabel.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mlabel.c	(revision 9)
+++ 	(revision )
@@ -1,251 +1,0 @@
-/*
- * mlabel.c
- * Make an MSDOS volume label
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mainloop.h"
-#include "vfat.h"
-#include "mtools.h"
-#include "nameclash.h"
-
-char *label_name(char *filename, int verbose, 
-		 int *mangled, char *ans)
-{
-	int len;
-	int i;
-	int have_lower, have_upper;
-
-	strcpy(ans,"           ");
-	len = strlen(filename);
-	if(len > 11){
-		*mangled = 1;
-		len = 11;
-	} else
-		*mangled = 0;
-	strncpy(ans, filename, len);
-	have_lower = have_upper = 0;
-	for(i=0; i<11; i++){
-		if(islower((unsigned char)ans[i]))
-			have_lower = 1;
-		if(isupper(ans[i]))
-			have_upper = 1;
-		ans[i] = toupper((unsigned char)ans[i]);
-
-		if(strchr("^+=/[]:,?*\\<>|\".", ans[i])){
-			*mangled = 1;
-			ans[i] = '~';
-		}
-	}
-	if (have_lower && have_upper)
-		*mangled = 1;
-	return ans;
-}
-
-int labelit(char *dosname,
-	    char *longname,
-	    void *arg0,
-	    direntry_t *entry)
-{
-	time_t now;
-
-	/* find out current time */
-	getTimeNow(&now);
-	mk_entry(dosname, 0x8, 0, 0, now, &entry->dir);
-	return 0;
-}
-
-static void usage(void)
-{
-	fprintf(stderr, "Mtools version %s, dated %s\n",
-		mversion, mdate);
-	fprintf(stderr, "Usage: %s [-vscn] [-N serial] drive:[label]\n"
-		"\t-v Verbose\n"
-		"\t-s Show label\n"
-		"\t-c Clear label\n"
-		"\t-n New random serial number\n"
-		"\t-N New given serial number\n", progname);
-	exit(1);
-}
-
-
-void mlabel(int argc, char **argv, int type)
-{
-    
-	char *drive, *newLabel;
-	int verbose, clear, interactive, show, open_mode;
-	direntry_t entry;
-	int result=0;
-	char longname[VBUFSIZE];
-	char shortname[13];
-	ClashHandling_t ch;
-	struct MainParam_t mp;
-	Stream_t *RootDir;
-	int c;
-	int mangled;
-	enum { SER_NONE, SER_RANDOM, SER_SET }  set_serial = SER_NONE;
-	long serial = 0;
-	int need_write_boot = 0;
-	int have_boot = 0;
-	char *eptr = "";
-	struct bootsector boot;
-	Stream_t *Fs=0;
-	int r;
-	struct label_blk_t *labelBlock;
-
-	init_clash_handling(&ch);
-	ch.name_converter = label_name;
-	ch.ignore_entry = -2;
-
-	verbose = 0;
-	clear = 0;
-	show = 0;
-
-	while ((c = getopt(argc, argv, "vcsnN:")) != EOF) {
-		switch (c) {
-			case 'v':
-				verbose = 1;
-				break;
-			case 'c':
-				clear = 1;
-				break;
-			case 's':
-				show = 1;
-				break;
-			case 'n':
-				set_serial = SER_RANDOM;
-				srandom((long)time (0));
-				serial=random();
-				break;
-			case 'N':
-				set_serial = SER_SET;
-				serial = strtol(optarg, &eptr, 16);
-				if(*eptr) {
-					fprintf(stderr,
-						"%s not a valid serial number\n",
-						optarg);
-					exit(1);
-				}
-				break;
-			default:
-				usage();
-			}
-	}
-
-	if (argc - optind != 1 || skip_drive(argv[optind]) == argv[optind]) 
-		usage();
-
-	init_mp(&mp);
-	newLabel = skip_drive(argv[optind]);
-	interactive = !show && !clear &&!newLabel[0] && 
-		(set_serial == SER_NONE);
-	open_mode = O_RDWR;
-	drive = get_drive(argv[optind], NULL);
-	RootDir = open_root_dir(drive, open_mode);
-	if(strlen(newLabel) > VBUFSIZE) {
-		fprintf(stderr, "Label too long\n");
-		FREE(&RootDir);
-		exit(1);
-	}
-
-	if(!RootDir && open_mode == O_RDWR && !clear && !newLabel[0] &&
-	   ( errno == EACCES || errno == EPERM) ) {
-		show = 1;
-		interactive = 0;
-		RootDir = open_root_dir(drive, O_RDONLY);
-	}	    
-	if(!RootDir) {
-		fprintf(stderr, "%s: Cannot initialize drive\n", argv[0]);
-		exit(1);
-	}
-
-	initializeDirentry(&entry, RootDir);
-	r=vfat_lookup(&entry, 0, 0, ACCEPT_LABEL | MATCH_ANY,
-		      shortname, longname);
-	if (r == -2) {
-		FREE(&RootDir);
-		exit(1);
-	}
-
-	if(show || interactive){
-		if(isNotFound(&entry))
-			printf(" Volume has no label\n");
-		else if (*longname)
-			printf(" Volume label is %s (abbr=%s)\n",
-			       longname, shortname);
-		else
-			printf(" Volume label is %s\n", shortname);
-
-	}
-
-	/* ask for new label */
-	if(interactive){
-		newLabel = longname;
-		fprintf(stderr,"Enter the new volume label : ");
-		fgets(newLabel, VBUFSIZE, stdin);
-		if(newLabel[0])
-			newLabel[strlen(newLabel)-1] = '\0';
-	}
-
-	if((!show || newLabel[0]) && !isNotFound(&entry)){
-		/* if we have a label, wipe it out before putting new one */
-		if(interactive && newLabel[0] == '\0')
-			if(ask_confirmation("Delete volume label (y/n): ",0,0)){
-				FREE(&RootDir);
-				exit(0);
-			}		
-		entry.dir.name[0] = DELMARK;
-		entry.dir.attr = 0; /* for old mlabel */
-		dir_write(&entry);
-	}
-
-	if (newLabel[0] != '\0') {
-		ch.ignore_entry = 1;
-		result = mwrite_one(RootDir,newLabel,0,labelit,NULL,&ch) ? 
-		  0 : 1;
-	}
-
-	have_boot = 0;
-	if( (!show || newLabel[0]) || set_serial != SER_NONE) {
-		Fs = GetFs(RootDir);
-		have_boot = (force_read(Fs,(char *)&boot,0,sizeof(boot)) == 
-			     sizeof(boot));
-	}
-
-	if(_WORD(boot.fatlen)) {
-	    labelBlock = &boot.ext.old.labelBlock;
-	} else {
-	    labelBlock = &boot.ext.fat32.labelBlock;
-	}
-
-	if(!show || newLabel[0]){
-
-		if(!newLabel[0])
-			strncpy(shortname, "NO NAME    ",11);
-		else
-			label_name(newLabel, verbose, &mangled, shortname);
-
-		if(have_boot && boot.descr >= 0xf0 &&
-		   labelBlock->dos4 == 0x29) {
-			strncpy(labelBlock->label, shortname, 11);
-			need_write_boot = 1;
-
-		}
-	}
-
-	if((set_serial != SER_NONE) & have_boot) {
-		if(have_boot && boot.descr >= 0xf0 &&
-		   labelBlock->dos4 == 0x29) {
-			set_dword(labelBlock->serial, serial);	
-			need_write_boot = 1;
-		}
-	}
-
-	if(need_write_boot) {
-		force_write(Fs, (char *)&boot, 0, sizeof(boot));
-	}
-
-	FREE(&RootDir);
-	exit(result);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mmd.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mmd.c	(revision 9)
+++ 	(revision )
@@ -1,174 +1,0 @@
-/*
- * mmd.c
- * Makes an MSDOS directory
- */
-
-
-#define LOWERCASE
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "mainloop.h"
-#include "plain_io.h"
-#include "nameclash.h"
-#include "file.h"
-#include "fs.h"
-
-/*
- * Preserve the file modification times after the fclose()
- */
-
-typedef struct Arg_t {
-	char *target;
-	MainParam_t mp;
-
-	Stream_t *SrcDir;
-	int entry;
-	ClashHandling_t ch;
-	Stream_t *targetDir;
-} Arg_t;
-
-
-typedef struct CreateArg_t {
-	Stream_t *Dir;
-	Stream_t *NewDir;
-	unsigned char attr;
-	time_t mtime;
-} CreateArg_t;
-
-/*
- * Open the named file for read, create the cluster chain, return the
- * directory structure or NULL on error.
- */
-int makeit(char *dosname,
-	    char *longname,
-	    void *arg0,
-	    direntry_t *targetEntry)
-{
-	Stream_t *Target;
-	CreateArg_t *arg = (CreateArg_t *) arg0;
-	int fat;
-	direntry_t subEntry;	
-
-	/* will it fit? At least one cluster must be free */
-	if (!getfreeMinClusters(targetEntry->Dir, 1))
-		return -1;
-	
-	mk_entry(dosname, ATTR_DIR, 1, 0, arg->mtime, &targetEntry->dir);
-	Target = OpenFileByDirentry(targetEntry);
-	if(!Target){
-		fprintf(stderr,"Could not open Target\n");
-		return -1;
-	}
-
-	/* this allocates the first cluster for our directory */
-
-	initializeDirentry(&subEntry, Target);
-
-	subEntry.entry = 1;
-	GET_DATA(targetEntry->Dir, 0, 0, 0, &fat);
-	if (fat == fat32RootCluster(targetEntry->Dir)) {
-	    fat = 0;
-	}
-	mk_entry("..         ", ATTR_DIR, fat, 0, arg->mtime, &subEntry.dir);
-	dir_write(&subEntry);
-
-	FLUSH((Stream_t *) Target);
-	subEntry.entry = 0;
-	GET_DATA(Target, 0, 0, 0, &fat);
-	mk_entry(".          ", ATTR_DIR, fat, 0, arg->mtime, &subEntry.dir);
-	dir_write(&subEntry);
-
-	mk_entry(dosname, ATTR_DIR | arg->attr, fat, 0, arg->mtime, 
-		 &targetEntry->dir);
-	arg->NewDir = Target;
-	return 0;
-}
-
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Mtools version %s, dated %s\n", mversion, mdate);
-	fprintf(stderr,
-		"Usage: %s [-D clash_option] file targetfile\n", progname);
-	fprintf(stderr,
-		"       %s [-D clash_option] file [files...] target_directory\n", 
-		progname);
-	exit(1);
-}
-
-Stream_t *createDir(Stream_t *Dir, const char *filename, ClashHandling_t *ch, 
-					unsigned char attr, time_t mtime)
-{
-	CreateArg_t arg;
-	int ret;
-
-	arg.Dir = Dir;
-	arg.attr = attr;
-	arg.mtime = mtime;
-
-	if (!getfreeMinClusters(Dir, 1))
-		return NULL;
-
-	ret = mwrite_one(Dir, filename,0, makeit, &arg, ch);
-	if(ret < 1)
-		return NULL;
-	else
-		return arg.NewDir;
-}
-
-static int createDirCallback(direntry_t *entry, MainParam_t *mp)
-{
-	Stream_t *ret;
-	time_t now;
-
-	ret = createDir(mp->File, mp->targetName, &((Arg_t *)(mp->arg))->ch, 
-					ATTR_DIR, getTimeNow(&now));
-	if(ret == NULL)
-		return ERROR_ONE;
-	else {
-		FREE(&ret);
-		return GOT_ONE;
-	}
-	
-}
-
-void mmd(int argc, char **argv, int type)
-{
-	Arg_t arg;
-	int c;
-
-	/* get command line options */
-
-	init_clash_handling(& arg.ch);
-
-	/* get command line options */
-	while ((c = getopt(argc, argv, "D:o")) != EOF) {
-		switch (c) {
-			case '?':
-				usage();
-			case 'o':
-				handle_clash_options(&arg.ch, c);
-				break;
-			case 'D':
-				if(handle_clash_options(&arg.ch, *optarg))
-					usage();
-				break;
-			default:
-				break;
-		}
-	}
-
-	if (argc - optind < 1)
-		usage();
-
-	init_mp(&arg.mp);
-	arg.mp.arg = (void *) &arg;
-	arg.mp.openflags = O_RDWR;
-	arg.mp.callback = createDirCallback;
-	arg.mp.lookupflags = OPEN_PARENT | DO_OPEN_DIRS;
-	exit(main_loop(&arg.mp, argv + optind, argc - optind));
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mmount.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mmount.c	(revision 9)
+++ 	(revision )
@@ -1,85 +1,0 @@
-/*
- * Mount an MSDOS disk
- *
- * written by:
- *
- * Alain L. Knaff			
- * alain@linux.lu
- *
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-
-#ifdef OS_linux
-#include <sys/wait.h>
-#include "mainloop.h"
-#include "fs.h"
-
-extern int errno;
-
-void mmount(int argc, char **argv, int type)
-{
-	char drive;
-	int pid;
-	int status;
-	struct device dev;
-	char name[EXPAND_BUF];
-	int media;
-	struct bootsector boot;
-	Stream_t *Stream;
-	
-	if (argc<2 || !argv[1][0]  || argv[1][1] != ':' || argv[1][2]){
-		fprintf(stderr,"Usage: %s -V drive:\n", argv[0]);
-		exit(1);
-	}
-	drive = toupper(argv[1][0]);
-	Stream = find_device(drive, O_RDONLY, &dev, &boot, name, &media, 0);
-	if(!Stream)
-		exit(1);
-	FREE(&Stream);
-
-	destroy_privs();
-
-	if ( dev.partition ) {
-		char part_name[4];
-		sprintf(part_name, "%d", dev.partition %1000);
-		strcat(name, part_name); 
-	}
-
-	/* and finally mount it */
-	switch((pid=fork())){
-	case -1:
-		fprintf(stderr,"fork failed\n");
-		exit(1);
-	case 0:
-		close(2);
-		open("/dev/null", O_RDWR);
-		argv[1] = strdup("mount");
-		if ( argc > 2 )
-			execvp("mount", argv + 1 );
-		else
-			execlp("mount", "mount", name, 0);
-		perror("exec mount");
-		exit(1);
-	default:
-		while ( wait(&status) != pid );
-	}	
-	if ( WEXITSTATUS(status) == 0 )
-		exit(0);
-	argv[0] = strdup("mount");
-	argv[1] = strdup("-r");
-	if(!argv[0] || !argv[1]){
-		printOom();
-		exit(1);
-	}
-	if ( argc > 2 )
-		execvp("mount", argv);
-	else
-		execlp("mount", "mount","-r", name, 0);
-	exit(1);
-}
-
-#endif /* linux */
-
Index: trunk/minix/commands/i386/mtools-3.9.7/mmove.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mmove.c	(revision 9)
+++ 	(revision )
@@ -1,314 +1,0 @@
-/*
- * mmove.c
- * Renames/moves an MSDOS file
- *
- */
-
-
-#define LOWERCASE
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "mainloop.h"
-#include "plain_io.h"
-#include "nameclash.h"
-#include "file.h"
-#include "fs.h"
-
-/*
- * Preserve the file modification times after the fclose()
- */
-
-typedef struct Arg_t {
-	const char *fromname;
-	int verbose;
-	MainParam_t mp;
-
-	direntry_t *entry;
-	ClashHandling_t ch;
-} Arg_t;
-
-
-/*
- * Open the named file for read, create the cluster chain, return the
- * directory structure or NULL on error.
- */
-int renameit(char *dosname,
-	     char *longname,
-	     void *arg0,
-	     direntry_t *targetEntry)
-{
-	Arg_t *arg = (Arg_t *) arg0;
-	int fat;
-
-	targetEntry->dir = arg->entry->dir;
-	strncpy(targetEntry->dir.name, dosname, 8);
-	strncpy(targetEntry->dir.ext, dosname + 8, 3);
-
-	if(IS_DIR(targetEntry)) {
-		direntry_t *movedEntry;
-
-		/* get old direntry. It is important that we do this
-		 * on the actual direntry which is stored in the file,
-		 * and not on a copy, because we will modify it, and the
-		 * modification should be visible at file 
-		 * de-allocation time */
-		movedEntry = getDirentry(arg->mp.File);
-		if(movedEntry->Dir != targetEntry->Dir) {
-			/* we are indeed moving it to a new directory */
-			direntry_t subEntry;
-			Stream_t *oldDir;
-			/* we have a directory here. Change its parent link */
-			
-			initializeDirentry(&subEntry, arg->mp.File);
-
-			switch(vfat_lookup(&subEntry, "..", 2, ACCEPT_DIR,
-					   NULL, NULL)) {
-			    case -1:
-				fprintf(stderr,
-					" Directory has no parent entry\n");
-				break;
-			    case -2:
-				return ERROR_ONE;
-			    case 0:
-				GET_DATA(targetEntry->Dir, 0, 0, 0, &fat);
-				if (fat == fat32RootCluster(targetEntry->Dir)) {
-				    fat = 0;
-				}
-
-				subEntry.dir.start[1] = (fat >> 8) & 0xff;
-				subEntry.dir.start[0] = fat & 0xff;
-				dir_write(&subEntry);
-				if(arg->verbose){
-					fprintf(stderr,
-						"Easy, isn't it? I wonder why DOS can't do this.\n");
-				}
-				break;
-			}
-			
-			/* wipe out original entry */			
-			movedEntry->dir.name[0] = DELMARK;
-			dir_write(movedEntry);
-			
-			/* free the old parent, allocate the new one. */
-			oldDir = movedEntry->Dir;
-			*movedEntry = *targetEntry;
-			COPY(targetEntry->Dir);
-			FREE(&oldDir);
-			return 0;
-		}
-	}
-
-	/* wipe out original entry */
-	arg->mp.direntry->dir.name[0] = DELMARK;
-	dir_write(arg->mp.direntry);
-	return 0;
-}
-
-
-
-static int rename_file(direntry_t *entry, MainParam_t *mp)
-/* rename a messy DOS file to another messy DOS file */
-{
-	int result;
-	Stream_t *targetDir;
-	char *shortname;
-	const char *longname;
-
-	Arg_t * arg = (Arg_t *) (mp->arg);
-
-	arg->entry = entry;
-	targetDir = mp->targetDir;
-
-	if (targetDir == entry->Dir){
-		arg->ch.ignore_entry = -1;
-		arg->ch.source = entry->entry;
-		arg->ch.source_entry = entry->entry;
-	} else {
-		arg->ch.ignore_entry = -1;
-		arg->ch.source = -2;
-	}
-
-	longname = mpPickTargetName(mp);
-	shortname = 0;
-	result = mwrite_one(targetDir, longname, shortname,
-			    renameit, (void *)arg, &arg->ch);
-	if(result == 1)
-		return GOT_ONE;
-	else
-		return ERROR_ONE;
-}
-
-
-static int rename_directory(direntry_t *entry, MainParam_t *mp)
-{
-	int ret;
-
-	/* moves a DOS dir */
-	if(isSubdirOf(mp->targetDir, mp->File)) {
-		fprintf(stderr, "Cannot move directory ");
-		fprintPwd(stderr, entry,0);
-		fprintf(stderr, " into one of its own subdirectories (");
-		fprintPwd(stderr, getDirentry(mp->targetDir),0);
-		fprintf(stderr, ")\n");
-		return ERROR_ONE;
-	}
-
-	if(entry->entry == -3) {
-		fprintf(stderr, "Cannot move a root directory: ");
-		fprintPwd(stderr, entry,0);
-		return ERROR_ONE;
-	}
-
-	ret = rename_file(entry, mp);
-	if(ret & ERROR_ONE)
-		return ret;
-	
-	return ret;
-}
-
-static int rename_oldsyntax(direntry_t *entry, MainParam_t *mp)
-{
-	int result;
-	Stream_t *targetDir;
-	const char *shortname, *longname;
-
-	Arg_t * arg = (Arg_t *) (mp->arg);
-	arg->entry = entry;
-	targetDir = entry->Dir;
-
-	arg->ch.ignore_entry = -1;
-	arg->ch.source = entry->entry;
-	arg->ch.source_entry = entry->entry;
-
-#if 0
-	if(!strcasecmp(mp->shortname, arg->fromname)){
-		longname = mp->longname;
-		shortname = mp->targetName;
-	} else {
-#endif
-		longname = mp->targetName;
-		shortname = 0;
-#if 0
-	}
-#endif
-	result = mwrite_one(targetDir, longname, shortname,
-			    renameit, (void *)arg, &arg->ch);
-	if(result == 1)
-		return GOT_ONE;
-	else
-		return ERROR_ONE;
-}
-
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Mtools version %s, dated %s\n", mversion, mdate);
-	fprintf(stderr,
-		"Usage: %s [-vo] [-D clash_option] file targetfile\n", progname);
-	fprintf(stderr,
-		"       %s [-vo] [-D clash_option] file [files...] target_directory\n", 
-		progname);
-	fprintf(stderr, "\t-v Verbose\n");
-	exit(1);
-}
-
-void mmove(int argc, char **argv, int oldsyntax)
-{
-	Arg_t arg;
-	int c;
-	char shortname[13];
-	char longname[VBUFSIZE];
-	char *def_drive;
-	int i;
-
-	/* get command line options */
-
-	init_clash_handling(& arg.ch);
-
-	/* get command line options */
-	arg.verbose = 0;
-	while ((c = getopt(argc, argv, "vD:o")) != EOF) {
-		switch (c) {
-			case 'v':	/* dummy option for mcopy */
-				arg.verbose = 1;
-				break;
-			case '?':
-				usage();
-			case 'o':
-				handle_clash_options(&arg.ch, c);
-				break;
-			case 'D':
-				if(handle_clash_options(&arg.ch, *optarg))
-					usage();
-				break;
-			default:
-				break;
-		}
-	}
-
-	if (argc - optind < 2)
-		usage();
-
-	init_mp(&arg.mp);		
-	arg.mp.arg = (void *) &arg;
-	arg.mp.openflags = O_RDWR;
-
-	/* look for a default drive */
-	def_drive = NULL;
-	for(i=optind; i<argc; i++)
-		if(skip_drive(argv[i]) > argv[i]){
-			char *drive = get_drive(argv[i], NULL);
-			if(!def_drive)
-				def_drive = drive;
-			else if(strcmp(def_drive, drive) != 0){
-				fprintf(stderr,
-					"Cannot move files across different drives\n");
-				exit(1);
-			}
-		}
-
-	if(def_drive) {
-		char mcwd[MAXPATHLEN];
-
-		strcpy(mcwd, skip_drive(arg.mp.mcwd));
-		if(strlen(def_drive) + 1 + strlen(mcwd) + 1 > MAXPATHLEN){
-			fprintf(stderr,
-				"Path name to current directory too long\n");
-			exit(1);
-		}
-		strcpy(arg.mp.mcwd, def_drive);
-		strcat(arg.mp.mcwd, ":");
-		strcat(arg.mp.mcwd, mcwd);
-	}
-
-	if (oldsyntax && (argc - optind != 2 || strpbrk(":/", argv[argc-1])))
-		oldsyntax = 0;
-
-	arg.mp.lookupflags = 
-	  ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN_DIRS | NO_DOTS | NO_UNIX;
-
-	if (!oldsyntax){
-		target_lookup(&arg.mp, argv[argc-1]);
-		arg.mp.callback = rename_file;
-		arg.mp.dirCallback = rename_directory;
-	} else {
-		/* do not look up the target; it will be the same dir as the
-		 * source */
-		arg.fromname = _basename(skip_drive(argv[optind]));
-		arg.mp.targetName = strdup(argv[argc-1]);
-		arg.mp.callback = rename_oldsyntax;
-	}
-
-
-	arg.mp.longname = longname;
-	longname[0]='\0';
-
-	arg.mp.shortname = shortname;
-	shortname[0]='\0';
-
-	exit(main_loop(&arg.mp, argv + optind, argc - optind - 1));
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mpartition.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mpartition.c	(revision 9)
+++ 	(revision )
@@ -1,706 +1,0 @@
-/*
- * mformat.c
- */
-#define DONT_NEED_WAIT
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "mainloop.h"
-#include "fsP.h"
-#include "file.h"
-#include "plain_io.h"
-#include "nameclash.h"
-#include "buffer.h"
-#include "scsi.h"
-#include "partition.h"
-
-#ifdef OS_linux
-#include "linux/hdreg.h"
-
-#define _LINUX_STRING_H_
-#define kdev_t int
-#include "linux/fs.h"
-#undef _LINUX_STRING_H_
-
-#endif
-
-#define tolinear(x) \
-(sector(x)-1+(head(x)+cyl(x)*used_dev->heads)*used_dev->sectors)
-
-
-static inline void print_hsc(hsc *h)
-{
-	printf(" h=%d s=%d c=%d\n", 
-	       head(*h), sector(*h), cyl(*h));
-}
-
-static void set_offset(hsc *h, int offset, int heads, int sectors)
-{
-	int head, sector, cyl;
-
-	if(! heads || !sectors)
-		head = sector = cyl = 0; /* linear mode */
-	else {
-		sector = offset % sectors;
-		offset = offset / sectors;
-
-		head = offset % heads;
-		cyl = offset / heads;
-		if(cyl > 1023) cyl = 1023;
-	}
-
-	h->head = head;
-	h->sector = ((sector+1) & 0x3f) | ((cyl & 0x300)>>2);
-	h->cyl = cyl & 0xff;
-}
-
-void setBeginEnd(struct partition *partTable, int begin, int end,
-				 int heads, int sectors, int activate, int type)
-{
-	set_offset(&partTable->start, begin, heads, sectors);
-	set_offset(&partTable->end, end-1, heads, sectors);
-	set_dword(partTable->start_sect, begin);
-	set_dword(partTable->nr_sects, end-begin);
-	if(activate)
-		partTable->boot_ind = 0x80;
-	else
-		partTable->boot_ind = 0;
-	if(!type) {
-		if(end-begin < 4096)
-			type = 1; /* DOS 12-bit FAT */
-		else if(end-begin<32*2048)
-			type = 4; /* DOS 16-bit FAT, <32M */
-		else
-			type = 6; /* DOS 16-bit FAT >= 32M */
-	}
-	partTable->sys_ind = type;
-}
-
-int consistencyCheck(struct partition *partTable, int doprint, int verbose,
-		     int *has_activated, int *last_end, int *j, 
-		     struct device *used_dev, int target_partition)
-{
-	int i;
-	int inconsistency;
-	
-	*j = 0;
-	*last_end = 1;
-
-	/* quick consistency check */
-	inconsistency = 0;
-	*has_activated = 0;
-	for(i=1; i<5; i++){
-		if(!partTable[i].sys_ind)
-			continue;
-		if(partTable[i].boot_ind)
-			(*has_activated)++;
-		if((used_dev && 
-		    (used_dev->heads != head(partTable[i].end)+1 ||
-		     used_dev->sectors != sector(partTable[i].end))) ||
-		   sector(partTable[i].start) != 1){
-			fprintf(stderr,
-				"Partition %d is not aligned\n",
-				i);
-			inconsistency=1;
-		}
-		
-		if(*j && *last_end > BEGIN(partTable[i])) {
-			fprintf(stderr,
-				"Partitions %d and %d badly ordered or overlapping\n",
-				*j,i);
-			inconsistency=1;
-		}
-			
-		*last_end = END(partTable[i]);
-		*j = i;
-
-		if(used_dev &&
-		   cyl(partTable[i].start) != 1023 &&
-		   tolinear(partTable[i].start) != BEGIN(partTable[i])) {
-			fprintf(stderr,
-				"Start position mismatch for partition %d\n",
-				i);
-			inconsistency=1;
-		}
-		if(used_dev &&
-		   cyl(partTable[i].end) != 1023 &&
-		   tolinear(partTable[i].end)+1 != END(partTable[i])) {
-			fprintf(stderr,
-				"End position mismatch for partition %d\n",
-				i);
-			inconsistency=1;
-		}
-
-		if(doprint && verbose) {
-			if(i==target_partition)
-				putchar('*');
-			else
-				putchar(' ');
-			printf("Partition %d\n",i);
-
-			printf("  active=%x\n", partTable[i].boot_ind);
-			printf("  start:");
-			print_hsc(&partTable[i].start);
-			printf("  type=0x%x\n", partTable[i].sys_ind);
-			printf("  end:");
-			print_hsc(&partTable[i].end);
-			printf("  start=%d\n", BEGIN(partTable[i]));
-			printf("  nr=%d\n", _DWORD(partTable[i].nr_sects));
-			printf("\n");
-		}
-	}
-	return inconsistency;
-}
-
-/* setsize function.  Determines scsicam mapping if this cannot be inferred from
- * any existing partitions. Shamelessly snarfed from the Linux kernel ;-) */
-
-/*
- * Function : static int setsize(unsigned long capacity,unsigned int *cyls,
- *	unsigned int *hds, unsigned int *secs);
- *
- * Purpose : to determine a near-optimal int 0x13 mapping for a
- *	SCSI disk in terms of lost space of size capacity, storing
- *	the results in *cyls, *hds, and *secs.
- *
- * Returns : -1 on failure, 0 on success.
- *
- * Extracted from
- *
- * WORKING                                                    X3T9.2
- * DRAFT                                                        792D
- *
- *
- *                                                        Revision 6
- *                                                         10-MAR-94
- * Information technology -
- * SCSI-2 Common access method
- * transport and SCSI interface module
- * 
- * ANNEX A :
- *
- * setsize() converts a read capacity value to int 13h
- * head-cylinder-sector requirements. It minimizes the value for
- * number of heads and maximizes the number of cylinders. This
- * will support rather large disks before the number of heads
- * will not fit in 4 bits (or 6 bits). This algorithm also
- * minimizes the number of sectors that will be unused at the end
- * of the disk while allowing for very large disks to be
- * accommodated. This algorithm does not use physical geometry. 
- */
-
-static int setsize(unsigned long capacity,unsigned int *cyls,unsigned int *hds,
-    unsigned int *secs) { 
-    unsigned int rv = 0; 
-    unsigned long heads, sectors, cylinders, temp; 
-
-    cylinders = 1024L;			/* Set number of cylinders to max */ 
-    sectors = 62L;      		/* Maximize sectors per track */ 
-
-    temp = cylinders * sectors;		/* Compute divisor for heads */ 
-    heads = capacity / temp;		/* Compute value for number of heads */
-    if (capacity % temp) {		/* If no remainder, done! */ 
-    	heads++;                	/* Else, increment number of heads */ 
-    	temp = cylinders * heads;	/* Compute divisor for sectors */ 
-    	sectors = capacity / temp;	/* Compute value for sectors per
-					       track */ 
-    	if (capacity % temp) {		/* If no remainder, done! */ 
-      	    sectors++;                  /* Else, increment number of sectors */ 
-      	    temp = heads * sectors;	/* Compute divisor for cylinders */
-      	    cylinders = capacity / temp;/* Compute number of cylinders */ 
-      	} 
-    } 
-    if (cylinders == 0) rv=(unsigned)-1;/* Give error if 0 cylinders */ 
-
-    *cyls = (unsigned int) cylinders;	/* Stuff return values */ 
-    *secs = (unsigned int) sectors; 
-    *hds  = (unsigned int) heads; 
-    return(rv); 
-} 
-
-static void setsize0(unsigned long capacity,unsigned int *cyls,
-		     unsigned int *hds, unsigned int *secs)
-{
-	int r;
-
-	/* 1. First try "Megabyte" sizes */
-	if(capacity < 1024 * 2048 && !(capacity % 1024)) {
-		*cyls = capacity >> 11;
-		*hds  = 64;
-		*secs = 32;
-		return;
-	}
-
-	/* then try scsicam's size */
-	r = setsize(capacity,cyls,hds,secs);
-	if(r || *hds > 255 || *secs > 63) {
-		/* scsicam failed. Do megabytes anyways */
-		*cyls = capacity >> 11;
-		*hds  = 64;
-		*secs = 32;
-		return;
-	}
-}
-
-
-static void usage(void)
-{
-	fprintf(stderr, 
-		"Mtools version %s, dated %s\n", mversion, mdate);
-	fprintf(stderr, 
-		"Usage: %s [-pradcv] [-I [-B bootsect-template] [-s sectors] "
-			"[-t cylinders] "
-		"[-h heads] [-T type] [-b begin] [-l length] "
-		"drive\n", progname);
-	exit(1);
-}
-
-void mpartition(int argc, char **argv, int dummy)
-{
-	Stream_t *Stream;
-	unsigned int dummy2;
-
-	int i,j;
-
-	int sec_per_cyl;
-	int doprint = 0;
-	int verbose = 0;
-	int create = 0;
-	int force = 0;
-	int length = 0;
-	int remove = 0;
-	int initialize = 0;
-	int tot_sectors=0;
-	int type = 0;
-	int begin_set = 0;
-	int size_set = 0;
-	int end_set = 0;
-	int last_end = 0;
-	int activate = 0;
-	int has_activated = 0;
-	int inconsistency=0;
-	int begin=0;
-	int end=0;
-	int sizetest=0;
-	int dirty = 0;
-	int open2flags = NO_OFFSET;
-	
-	int c;
-	struct device used_dev;
-	int argtracks, argheads, argsectors;
-
-	char *drive, name[EXPAND_BUF];
-	unsigned char buf[512];
-	struct partition *partTable=(struct partition *)(buf+ 0x1ae);
-	struct device *dev;
-	char errmsg[200];
-	char *bootSector=0;
-
-	argtracks = 0;
-	argheads = 0;
-	argsectors = 0;
-
-	/* get command line options */
-	while ((c = getopt(argc, argv, "adprcIT:t:h:s:fvpb:l:S:B:")) != EOF) {
-		switch (c) {
-			case 'B':
-				bootSector = optarg;
-				break;
-			case 'a':
-				/* no privs, as it could be abused to
-				 * make other partitions unbootable, or
-				 * to boot a rogue kernel from this one */
-				open2flags |= NO_PRIV;
-				activate = 1;
-				dirty = 1;
-				break;
-			case 'd':
-				activate = -1;
-				dirty = 1;
-				break;
-			case 'p':
-				doprint = 1;
-				break;
-			case 'r':
-				remove = 1;
-				dirty = 1;
-				break;
-			case 'I':
-				/* could be abused to nuke all other 
-				 * partitions */
-				open2flags |= NO_PRIV;
-				initialize = 1;
-				dirty = 1;
-				break;
-			case 'c':
-				create = 1;
-				dirty = 1;
-				break;
-
-			case 'T':
-				/* could be abused to "manually" create
-				 * extended partitions */
-				open2flags |= NO_PRIV;
-				type = strtoul(optarg,0,0);
-				break;
-
-			case 't':
-				argtracks = atoi(optarg);
-				break;
-			case 'h':
-				argheads = atoi(optarg);
-				break;
-			case 's':
-				argsectors = atoi(optarg);
-				break;
-
-			case 'f':
-				/* could be abused by creating overlapping
-				 * partitions and other such Snafu */
-				open2flags |= NO_PRIV;
-				force = 1;
-				break;
-
-			case 'v':
-				verbose++;
-				break;
-			case 'S':
-				/* testing only */
-				/* could be abused to create partitions
-				 * extending beyond the actual size of the
-				 * device */
-				open2flags |= NO_PRIV;
-				tot_sectors = strtoul(optarg,0,0);
-				sizetest = 1;
-				break;
-			case 'b':
-				begin_set = 1;
-				begin = atoi(optarg);
-				break;
-			case 'l':
-				size_set = 1;
-				length = atoi(optarg);
-				break;
-
-			default:
-				usage();
-		}
-	}
-
-	if (argc - optind != 1 || skip_drive(argv[optind]) == argv[optind])
-		usage();
-	
-	drive = get_drive(argv[optind], NULL);
-
-	/* check out a drive whose letter and parameters match */	
-	sprintf(errmsg, "Drive '%s:' not supported", drive);
-	Stream = 0;
-	for(dev=devices;dev->drive;dev++) {
-		FREE(&(Stream));
-		/* drive letter */
-		if (strcmp(dev->drive, drive) != 0)
-			continue;
-		if (dev->partition < 1 || dev->partition > 4) {
-			sprintf(errmsg, 
-				"Drive '%c:' is not a partition", 
-				drive);
-			continue;
-		}
-		used_dev = *dev;
-
-		SET_INT(used_dev.tracks, argtracks);
-		SET_INT(used_dev.heads, argheads);
-		SET_INT(used_dev.sectors, argsectors);
-		
-		expand(dev->name, name);
-		Stream = SimpleFileOpen(&used_dev, dev, name,
-					dirty ? O_RDWR : O_RDONLY, 
-					errmsg, open2flags, 1, 0);
-
-		if (!Stream) {
-#ifdef HAVE_SNPRINTF
-			snprintf(errmsg,199,"init: open: %s", strerror(errno));
-#else
-			sprintf(errmsg,"init: open: %s", strerror(errno));
-#endif
-			continue;
-		}			
-
-
-		/* try to find out the size */
-		if(!sizetest)
-			tot_sectors = 0;
-		if(IS_SCSI(dev)) {
-			unsigned char cmd[10];
-			unsigned char data[10];
-			cmd[0] = SCSI_READ_CAPACITY;
-			memset ((void *) &cmd[2], 0, 8);
-			memset ((void *) &data[0], 137, 10);
-			scsi_cmd(get_fd(Stream), cmd, 10, SCSI_IO_READ,
-				 data, 10, get_extra_data(Stream));
-			
-			tot_sectors = 1 +
-				(data[0] << 24) +
-				(data[1] << 16) +
-				(data[2] <<  8) +
-				(data[3]      );
-			if(verbose)
-				printf("%d sectors in total\n", tot_sectors);
-		}
-
-#ifdef OS_linux
-		if (tot_sectors == 0) {
-			ioctl(get_fd(Stream), BLKGETSIZE, &tot_sectors);
-		}
-#endif
-
-		/* read the partition table */
-		if (READS(Stream, (char *) buf, 0, 512) != 512) {
-#ifdef HAVE_SNPRINTF
-			snprintf(errmsg, 199,
-				"Error reading from '%s', wrong parameters?",
-				name);
-#else
-			sprintf(errmsg,
-				"Error reading from '%s', wrong parameters?",
-				name);
-#endif
-			continue;
-		}
-		if(verbose>=2)
-			print_sector("Read sector", buf, 512);
-		break;
-	}
-
-	/* print error msg if needed */	
-	if ( dev->drive == 0 ){
-		FREE(&Stream);
-		fprintf(stderr,"%s: %s\n", argv[0],errmsg);
-		exit(1);
-	}
-
-	if((used_dev.sectors || used_dev.heads) &&
-	   (!used_dev.sectors || !used_dev.heads)) {
-		fprintf(stderr,"You should either indicate both the number of sectors and the number of heads,\n");
-		fprintf(stderr," or none of them\n");
-		exit(1);
-	}
-
-	if(initialize) {
-		if (bootSector) {
-			int fd;
-			fd = open(bootSector, O_RDONLY);
-			if (fd < 0) {
-				perror("open boot sector");
-				exit(1);
-			}
-			read(fd, (char *) buf, 512);
-		}
-		memset((char *)(partTable+1), 0, 4*sizeof(*partTable));
-		set_dword(((unsigned char*)buf)+510, 0xaa55);
-	}
-
-	/* check for boot signature, and place it if needed */
-	if((buf[510] != 0x55) || (buf[511] != 0xaa)) {
-		fprintf(stderr,"Boot signature not set\n");
-		fprintf(stderr,
-			"Use the -I flag to initialize the partition table, and set the boot signature\n");
-		inconsistency = 1;
-	}
-	
-	if(remove){
-		if(!partTable[dev->partition].sys_ind)
-			fprintf(stderr,
-				"Partition for drive %c: does not exist\n",
-				drive);
-		if((partTable[dev->partition].sys_ind & 0x3f) == 5) {
-			fprintf(stderr,
-				"Partition for drive %c: may be an extended partition\n",
-				drive);
-			fprintf(stderr,
-				"Use the -f flag to remove it anyways\n");
-			inconsistency = 1;
-		}
-		memset(&partTable[dev->partition], 0, sizeof(*partTable));
-	}
-
-	if(create && partTable[dev->partition].sys_ind) {
-		fprintf(stderr,
-			"Partition for drive %c: already exists\n", drive);
-		fprintf(stderr,
-			"Use the -r flag to remove it before attempting to recreate it\n");
-	}
-
-
-	/* find out number of heads and sectors, and whether there is
-	* any activated partition */
-	has_activated = 0;
-	for(i=1; i<5; i++){
-		if(!partTable[i].sys_ind)
-			continue;
-		
-		if(partTable[i].boot_ind)
-			has_activated++;
-
-		/* set geometry from entry */
-		if (!used_dev.heads)
-			used_dev.heads = head(partTable[i].end)+1;
-		if(!used_dev.sectors)
-			used_dev.sectors = sector(partTable[i].end);
-		if(i<dev->partition && !begin_set)
-			begin = END(partTable[i]);
-		if(i>dev->partition && !end_set && !size_set) {
-			end = BEGIN(partTable[i]);
-			end_set = 1;
-		}
-	}
-
-#ifdef OS_linux
-	if(!used_dev.sectors && !used_dev.heads) {
-		if(!IS_SCSI(dev)) {
-			struct hd_geometry geom;
-			if(ioctl(get_fd(Stream), HDIO_GETGEO, &geom) == 0) {
-				used_dev.heads = geom.heads;
-				used_dev.sectors = geom.sectors;
-			}
-		}
-	}
-#endif
-
-	if(!used_dev.sectors && !used_dev.heads) {
-		if(tot_sectors)
-			setsize0(tot_sectors,&dummy2,&used_dev.heads,
-					 &used_dev.sectors);
-		else {
-			used_dev.heads = 64;
-			used_dev.sectors = 32;
-		}
-	}
-
-	if(verbose)
-		fprintf(stderr,"sectors: %d heads: %d %d\n",
-			used_dev.sectors, used_dev.heads, tot_sectors);
-
-	sec_per_cyl = used_dev.sectors * used_dev.heads;
-	if(create) {
-		if(!end_set && tot_sectors) {
-			end = tot_sectors - tot_sectors % sec_per_cyl;
-			end_set = 1;
-		}
-		
-		/* if the partition starts right at the beginning of
-		 * the disk, keep one track unused to allow place for
-		 * the master boot record */
-		if(!begin && !begin_set)
-			begin = used_dev.sectors;
-		if(!size_set && used_dev.tracks) {
-			size_set = 2;
-			length = sec_per_cyl * used_dev.tracks;
-
-			/*  round the size in order to take
-			 * into account any "hidden" sectors */
-
-			/* do we anchor this at the beginning ?*/
-			if(begin_set || dev->partition <= 2 || !end_set)
-				length -= begin % sec_per_cyl;
-			else if(end - length < begin)
-				/* truncate any overlap */
-				length = end - begin;
-		}
-		if(size_set) {
-			if(!begin_set && dev->partition >2 && end_set)
-				begin = end - length;
-			else
-				end = begin + length;
-		} else if(!end_set) {
-			fprintf(stderr,"Unknown size\n");
-			exit(1);
-		}
-
-		setBeginEnd(&partTable[dev->partition], begin, end,
-					used_dev.heads, used_dev.sectors, 
-					!has_activated, type);
-	}
-
-	if(activate) {
-		if(!partTable[dev->partition].sys_ind) {
-			fprintf(stderr,
-				"Partition for drive %c: does not exist\n",
-				drive);
-		} else {
-			switch(activate) {
-				case 1:
-					partTable[dev->partition].boot_ind=0x80;
-					break;
-				case -1:
-					partTable[dev->partition].boot_ind=0x00;
-					break;
-			}
-		}
-	}
-
-
-	inconsistency |= consistencyCheck(partTable, doprint, verbose,
-					  &has_activated, &last_end, &j,
-					  &used_dev, dev->partition);
-
-	if(doprint && !inconsistency && partTable[dev->partition].sys_ind) {
-		printf("The following command will recreate the partition for drive %c:\n", 
-		       drive);
-		used_dev.tracks = 
-			(_DWORD(partTable[dev->partition].nr_sects) +
-			 (BEGIN(partTable[dev->partition]) % sec_per_cyl)) / 
-			sec_per_cyl;
-		printf("mpartition -c -t %d -h %d -s %d -b %u %c:\n",
-		       used_dev.tracks, used_dev.heads, used_dev.sectors,
-		       BEGIN(partTable[dev->partition]), drive);
-	}
-
-	if(tot_sectors && last_end >tot_sectors) {
-		fprintf(stderr,
-			"Partition %d exceeds beyond end of disk\n",
-			j);
-		exit(1);
-	}
-
-	
-	switch(has_activated) {
-		case 0:
-			fprintf(stderr,
-				"Warning: no active (bootable) partition present\n");
-			break;
-		case 1:
-			break;
-		default:
-			fprintf(stderr,
-				"Warning: %d active (bootable) partitions present\n",
-				has_activated);
-			fprintf(stderr,
-				"Usually, a disk should have exactly one active partition\n");
-			break;
-	}
-	
-	if(inconsistency && !force) {
-		fprintf(stderr,
-			"inconsistency detected!\n" );
-		if(dirty)
-			fprintf(stderr,
-				"Retry with the -f switch to go ahead anyways\n");
-		exit(1);
-	}
-
-	if(dirty) {
-		/* write data back to the disk */
-		if(verbose>=2)
-			print_sector("Writing sector", buf, 512);
-		if (WRITES(Stream, (char *) buf, 0, 512) != 512) {
-			fprintf(stderr,"Error writing partition table");
-			exit(1);
-		}
-		if(verbose>=3)
-			print_sector("Sector written", buf, 512);
-		FREE(&Stream);
-	}
-	exit(0);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/msdos.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/msdos.h	(revision 9)
+++ 	(revision )
@@ -1,237 +1,0 @@
-#ifndef MTOOLS_MSDOS_H
-#define MTOOLS_MSDOS_H
-
-/*
- * msdos common header file
- */
-
-#define MAX_SECTOR	8192   		/* largest sector size */
-#define MDIR_SIZE	32		/* MSDOS directory entry size in bytes*/
-#define MAX_CLUSTER	8192		/* largest cluster size */
-#define MAX_PATH	128		/* largest MSDOS path length */
-#define MAX_DIR_SECS	64		/* largest directory (in sectors) */
-#define MSECTOR_SIZE    msector_size
-
-#define NEW		1
-#define OLD		0
-
-#define _WORD(x) ((unsigned char)(x)[0] + (((unsigned char)(x)[1]) << 8))
-#define _DWORD(x) (_WORD(x) + (_WORD((x)+2) << 16))
-
-#define DELMARK ((char) 0xe5)
-
-struct directory {
-	char name[8];			/*  0 file name */
-	char ext[3];			/*  8 file extension */
-	unsigned char attr;		/* 11 attribute byte */
-	unsigned char Case;		/* 12 case of short filename */
-	unsigned char ctime_ms;		/* 13 creation time, milliseconds (?) */
-	unsigned char ctime[2];		/* 14 creation time */
-	unsigned char cdate[2];		/* 16 creation date */
-	unsigned char adate[2];		/* 18 last access date */
-	unsigned char startHi[2];	/* 20 start cluster, Hi */
-	unsigned char time[2];		/* 22 time stamp */
-	unsigned char date[2];		/* 24 date stamp */
-	unsigned char start[2];		/* 26 starting cluster number */
-	unsigned char size[4];		/* 28 size of the file */
-};
-
-#define EXTCASE 0x10
-#define BASECASE 0x8
-
-#define MAX32 0xffffffff
-#define MAX_SIZE 0x7fffffff
-
-#define FILE_SIZE(dir)  (_DWORD((dir)->size))
-#define START(dir) (_WORD((dir)->start))
-#define STARTHI(dir) (_WORD((dir)->startHi))
-
-/* ASSUMPTION: long is at least 32 bits */
-UNUSED(static inline void set_dword(unsigned char *data, unsigned long value))
-{
-	data[3] = (value >> 24) & 0xff;
-	data[2] = (value >> 16) & 0xff;
-	data[1] = (value >>  8) & 0xff;
-	data[0] = (value >>  0) & 0xff;
-}
-
-
-/* ASSUMPTION: short is at least 16 bits */
-UNUSED(static inline void set_word(unsigned char *data, unsigned short value))
-{
-	data[1] = (value >>  8) & 0xff;
-	data[0] = (value >>  0) & 0xff;
-}
-
-
-/*
- *	    hi byte     |    low byte
- *	|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
- *  | | | | | | | | | | | | | | | | |
- *  \   7 bits    /\4 bits/\ 5 bits /
- *     year +80     month     day
- */
-#define	DOS_YEAR(dir) (((dir)->date[1] >> 1) + 1980)
-#define	DOS_MONTH(dir) (((((dir)->date[1]&0x1) << 3) + ((dir)->date[0] >> 5)))
-#define	DOS_DAY(dir) ((dir)->date[0] & 0x1f)
-
-/*
- *	    hi byte     |    low byte
- *	|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
- *      | | | | | | | | | | | | | | | | |
- *      \  5 bits /\  6 bits  /\ 5 bits /
- *         hour      minutes     sec*2
- */
-#define	DOS_HOUR(dir) ((dir)->time[1] >> 3)
-#define	DOS_MINUTE(dir) (((((dir)->time[1]&0x7) << 3) + ((dir)->time[0] >> 5)))
-#define	DOS_SEC(dir) (((dir)->time[0] & 0x1f) * 2)
-
-
-typedef struct InfoSector_t {
-	unsigned char signature1[4];
-	unsigned char filler1[0x1e0];
-	unsigned char signature2[4];
-	unsigned char count[4];
-	unsigned char pos[4];
-	unsigned char filler2[14];
-	unsigned char signature3[2];
-} InfoSector_t;
-
-#define INFOSECT_SIGNATURE1 0x41615252
-#define INFOSECT_SIGNATURE2 0x61417272
-
-
-typedef struct label_blk_t {
-	unsigned char physdrive;	/* 36 physical drive ? */
-	unsigned char reserved;		/* 37 reserved */
-	unsigned char dos4;		/* 38 dos > 4.0 diskette */
-	unsigned char serial[4];       	/* 39 serial number */
-	char label[11];			/* 43 disk label */
-	char fat_type[8];		/* 54 FAT type */
-} label_blk_t;
-
-/* FAT32 specific info in the bootsector */
-typedef struct fat32_t {
-	unsigned char bigFat[4];	/* 36 nb of sectors per FAT */
-	unsigned char extFlags[2];     	/* 40 extension flags */
-	unsigned char fsVersion[2];	/* 42 ? */
-	unsigned char rootCluster[4];	/* 44 start cluster of root dir */
-	unsigned char infoSector[2];	/* 48 changeable global info */
-	unsigned char backupBoot[2];	/* 50 back up boot sector */
-	unsigned char reserved[6];	/* 52 ? */
-	unsigned char reserved2[6];	/* 52 ? */
-	struct label_blk_t labelBlock;
-} fat32; /* ends at 58 */
-
-typedef struct oldboot_t {
-	struct label_blk_t labelBlock;
-	unsigned char res_2m;		/* 62 reserved by 2M */
-	unsigned char CheckSum;		/* 63 2M checksum (not used) */
-	unsigned char fmt_2mf;		/* 64 2MF format version */
-	unsigned char wt;		/* 65 1 if write track after format */
-	unsigned char rate_0;		/* 66 data transfer rate on track 0 */
-	unsigned char rate_any;		/* 67 data transfer rate on track<>0 */
-	unsigned char BootP[2];		/* 68 offset to boot program */
-	unsigned char Infp0[2];		/* 70 T1: information for track 0 */
-	unsigned char InfpX[2];		/* 72 T2: information for track<>0 */
-	unsigned char InfTm[2];		/* 74 T3: track sectors size table */
-	unsigned char DateF[2];		/* 76 Format date */
-	unsigned char TimeF[2];		/* 78 Format time */
-	unsigned char junk[1024 - 80];	/* 80 remaining data */
-} oldboot_t;
-
-struct bootsector {
-	unsigned char jump[3];		/* 0  Jump to boot code */
-	char banner[8] PACKED;	       	/* 3  OEM name & version */
-	unsigned char secsiz[2] PACKED;	/* 11 Bytes per sector hopefully 512 */
-	unsigned char clsiz;    	/* 13 Cluster size in sectors */
-	unsigned char nrsvsect[2];	/* 14 Number of reserved (boot) sectors */
-	unsigned char nfat;		/* 16 Number of FAT tables hopefully 2 */
-	unsigned char dirents[2] PACKED;/* 17 Number of directory slots */
-	unsigned char psect[2] PACKED; 	/* 19 Total sectors on disk */
-	unsigned char descr;		/* 21 Media descriptor=first byte of FAT */
-	unsigned char fatlen[2];	/* 22 Sectors in FAT */
-	unsigned char nsect[2];		/* 24 Sectors/track */
-	unsigned char nheads[2];	/* 26 Heads */
-	unsigned char nhs[4];		/* 28 number of hidden sectors */
-	unsigned char bigsect[4];	/* 32 big total sectors */
-
-	union {
-		struct fat32_t fat32;
-		struct oldboot_t old;
-	} ext;
-};
-
-#define CHAR(x) (boot->x[0])
-#define WORD(x) (_WORD(boot->x))
-#define DWORD(x) (_DWORD(boot->x))
-#define OFFSET(x) (((char *) (boot->x)) - ((char *)(boot->jump)))
-
-
-extern struct OldDos_t {
-	int tracks;
-	int sectors;
-	int heads;
-	
-	int dir_len;
-	int cluster_size;
-	int fat_len;
-
-	int media;
-} old_dos[];
-
-#define FAT12 4085 /* max. number of clusters described by a 12 bit FAT */
-#define FAT16 65525
-
-#define ATTR_ARCHIVE 0x20
-#define ATTR_DIR 0x10
-#define ATTR_LABEL 0x8
-#define ATTR_SYSTEM 0x4
-#define ATTR_HIDDEN 0x2
-#define ATTR_READONLY 0x1
-
-#define HAS_BIT(entry,x) ((entry)->dir.attr & (x))
-
-#define IS_ARCHIVE(entry) (HAS_BIT((entry),ATTR_ARCHIVE))
-#define IS_DIR(entry) (HAS_BIT((entry),ATTR_DIR))
-#define IS_LABEL(entry) (HAS_BIT((entry),ATTR_LABEL))
-#define IS_SYSTEM(entry) (HAS_BIT((entry),ATTR_SYSTEM))
-#define IS_HIDDEN(entry) (HAS_BIT((entry),ATTR_HIDDEN))
-#define IS_READONLY(entry) (HAS_BIT((entry),ATTR_READONLY))
-
-
-#define MAX_SECT_PER_CLUSTER 64
-/* Experimentally, it turns out that DOS only accepts cluster sizes
- * which are powers of two, and less than 128 sectors (else it gets a
- * divide overflow) */
-
-
-#define FAT_SIZE(bits, sec_siz, clusters) \
-	((((clusters)+2) * ((bits)/4) - 1) / 2 / (sec_siz) + 1)
-
-#define NEEDED_FAT_SIZE(x) FAT_SIZE((x)->fat_bits, (x)->sector_size, \
-				    (x)->num_clus)
-
-/* disk size taken by FAT and clusters */
-#define DISK_SIZE(bits, sec_siz, clusters, n, cluster_size) \
-	((n) * FAT_SIZE(bits, sec_siz, clusters) + \
-	 (clusters) * (cluster_size))
-
-#define TOTAL_DISK_SIZE(bits, sec_siz, clusters, n, cluster_size) \
-	(DISK_SIZE(bits, sec_siz, clusters, n, cluster_size) + 2)
-/* approx. total disk size: assume 1 boot sector and one directory sector */
-
-extern const char *mversion;
-extern const char *mdate;
-
-extern char *Version;
-extern char *Date;
-
-
-int init(char drive, int mode);
-
-#define MT_READ 1
-#define MT_WRITE 2
-
-#endif
-
Index: trunk/minix/commands/i386/mtools-3.9.7/mshowfat.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mshowfat.c	(revision 9)
+++ 	(revision )
@@ -1,87 +1,0 @@
-/*
- * mcopy.c
- * Copy an MSDOS files to and from Unix
- *
- */
-
-
-#define LOWERCASE
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "mainloop.h"
-#include "plain_io.h"
-#include "nameclash.h"
-#include "file.h"
-#include "fs.h"
-
-
-
-typedef struct Arg_t {
-	char *target;
-	MainParam_t mp;
-	ClashHandling_t ch;
-	Stream_t *sourcefile;
-} Arg_t;
-
-static int dos_showfat(direntry_t *entry, MainParam_t *mp)
-{
-	Stream_t *File=mp->File;
-
-	fprintPwd(stdout, entry,0);
-	putchar(' ');
-	printFat(File);
-	printf("\n");
-	return GOT_ONE;
-}
-
-static int unix_showfat(MainParam_t *mp)
-{
-	fprintf(stderr,"File does not reside on a Dos fs\n");
-	return ERROR_ONE;
-}
-
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Mtools version %s, dated %s\n", mversion, mdate);
-	fprintf(stderr,
-		"Usage: %s file ...\n", progname);
-	exit(1);
-}
-
-void mshowfat(int argc, char **argv, int mtype)
-{
-	Arg_t arg;
-	int c, ret;
-	
-	/* get command line options */
-
-	init_clash_handling(& arg.ch);
-
-	/* get command line options */
-	while ((c = getopt(argc, argv, "")) != EOF) {
-		switch (c) {
-			case '?':
-				usage();
-				break;
-		}
-	}
-
-	if (argc - optind < 1)
-		usage();
-
-	/* only 1 file to copy... */
-	init_mp(&arg.mp);
-	arg.mp.arg = (void *) &arg;
-
-	arg.mp.callback = dos_showfat;
-	arg.mp.unixcallback = unix_showfat;
-
-	arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN;
-	ret=main_loop(&arg.mp, argv + optind, argc - optind);
-	exit(ret);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mtools.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mtools.c	(revision 9)
+++ 	(revision )
@@ -1,186 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "partition.h"
-#include "vfat.h"
-
-const char *progname;
-
-static const struct dispatch {
-	const char *cmd;
-	void (*fn)(int, char **, int);
-	int type;
-} dispatch[] = {
-	{"attrib",mattrib, 0},
-	{"badblocks",mbadblocks, 0},
-	{"cat",mcat, 0},
-	{"cd",mcd, 0},
-	{"copy",mcopy, 0},
-	{"del",mdel, 0},
-	{"deltree",mdel, 2},
-	{"dir",mdir, 0},
-	{"doctorfat",mdoctorfat, 0},
-	{"du",mdu, 0},
-	{"format",mformat, 0},
-	{"info", minfo, 0},
-	{"label",mlabel, 0},
-	{"md",mmd, 0},
-	{"mkdir",mmd, 0},
-#ifdef OS_linux
-	{"mount",mmount, 0},
-#endif
-	{"partition",mpartition, 0},
-	{"rd",mdel, 1},
-	{"rmdir",mdel, 1},
-	{"read",mcopy, 0},
-	{"move",mmove, 0},
-	{"ren",mmove, 1},
-	{"showfat", mshowfat, 0},
-#ifndef NO_CONFIG
-	{"toolstest", mtoolstest, 0},
-#endif
-	{"type",mcopy, 1},
-	{"write",mcopy, 0},
-#ifndef OS_Minix
-	{"zip", mzip, 0}
-#endif
-};
-#define NDISPATCH (sizeof dispatch / sizeof dispatch[0])
-
-int main(int argc,char **argv)
-{
-	const char *name;
-	int i;
-
-	init_privs();
-#ifdef __EMX__
-	_wildcard(&argc,&argv);
-#endif
-
-/*#define PRIV_TEST*/
-
-#ifdef PRIV_TEST
-	{ 
-		int euid;
-		char command[100];
-	
-		printf("INIT: %d %d\n", getuid(), geteuid());
-		drop_privs();
-		printf("DROP: %d %d\n", getuid(), geteuid());
-		reclaim_privs();
-		printf("RECLAIM: %d %d\n", getuid(), geteuid());
-		euid = geteuid();
-		if(argc & 1) {
-			drop_privs();
-			printf("DROP: %d %d\n", getuid(), geteuid());
-		}
-		if(!((argc-1) & 2)) {
-			destroy_privs();
-			printf("DESTROY: %d %d\n", getuid(), geteuid());
-		}
-		sprintf(command, "a.out %d", euid);
-		system(command);
-		return 1;
-	}
-#endif
-
-
-#ifdef __EMX__
-       _wildcard(&argc,&argv);
-#endif 
-
-
-	/* check whether the compiler lays out structures in a sane way */
-	if(sizeof(struct partition) != 16 ||
-	   sizeof(struct directory) != 32 ||
-	   sizeof(struct vfat_subentry) !=32) {
-		fprintf(stderr,"Mtools has not been correctly compiled\n");
-		fprintf(stderr,"Recompile it using a more recent compiler\n");
-		return 137;
-	}
-
-#ifdef __EMX__
-       argv[0] = _getname(argv[0]); _remext(argv[0]); name = argv[0];
-#else  
-	name = _basename(argv[0]);
-#endif
-
-#if 0
-	/* this allows the different tools to be called as "mtools -c <command>"
-	** where <command> is mdir, mdel, mcopy etcetera
-	** Mainly done for the BeOS, which doesn't support links yet.
-	*/
-
-	if(argc >= 3 && 
-	   !strcmp(argv[1], "-c") &&
-	   !strcmp(name, "mtools")) {
-		argc-=2;
-		argv+=2;
-		name = argv[0];
-	}
-#endif
-
-	/* print the version */
-	if(argc >= 2 && 
-	   (strcmp(argv[1], "-V") == 0 || strcmp(argv[1], "--version") ==0)) {
-		printf("%c%s version %s, dated %s\n", 
-		       toupper(name[0]), name+1,
-		       mversion, mdate);
-		printf("configured with the following options: ");
-#ifdef USE_XDF
-		printf("enable-xdf ");
-#else
-		printf("disable-xdf ");
-#endif
-#ifdef USING_VOLD
-		printf("enable-vold ");
-#else
-		printf("disable-vold ");
-#endif
-#ifdef USING_NEW_VOLD
-		printf("enable-new-vold ");
-#else
-		printf("disable-new-vold ");
-#endif
-#ifdef DEBUG
-		printf("enable-debug ");
-#else
-		printf("disable-debug ");
-#endif
-#ifdef USE_RAWTERM
-		printf("enable-raw-term ");
-#else
-		printf("disable-raw-term ");
-#endif
-		printf("\n");
-		return 0;
-	}
-
-	if (argc >= 2 && strcmp(name, "mtools") == 0) {
-		/* mtools command ... */
-		argc--;
-		argv++;
-		name = argv[0];
-	}
-	progname = argv[0];
-
-	read_config();
-	setup_signal();
-	for (i = 0; i < NDISPATCH; i++) {
-		if (!strcmp(name,dispatch[i].cmd)
-		    || (name[0] == 'm' && !strcmp(name+1,dispatch[i].cmd)))
-			dispatch[i].fn(argc, argv, dispatch[i].type);
-	}
-	if (strcmp(name,"mtools"))
-		fprintf(stderr,"Unknown mtools command '%s'\n",name);
-	fprintf(stderr,"Usage: mtools [-V] command [-options] arguments ...\n");
-	fprintf(stderr,"Supported commands:");
-	for (i = 0; i < NDISPATCH; i++) {
-		fprintf(stderr, i%8 == 0 ? "\n\t" : ", ");
-		fprintf(stderr, "%s", dispatch[i].cmd);
-	}
-	putc('\n', stderr);
-	fprintf(stderr, "Use 'mtools command -?' for help per command\n");
-
-	return 1;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/mtools.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mtools.h	(revision 9)
+++ 	(revision )
@@ -1,234 +1,0 @@
-#ifndef MTOOLS_MTOOLS_H
-#define MTOOLS_MTOOLS_H
-
-#include "msdos.h"
-
-#if defined(OS_sco3)
-#define MAXPATHLEN 1024
-#include <signal.h>
-extern int lockf(int, int, off_t);  /* SCO has no proper include file for lockf */
-#endif 
-
-#define SCSI_FLAG 1
-#define PRIV_FLAG 2
-#define NOLOCK_FLAG 4
-#define USE_XDF_FLAG 8
-#define MFORMAT_ONLY_FLAG 16
-#define VOLD_FLAG 32
-#define FLOPPYD_FLAG 64
-#define FILTER_FLAG 128
-
-#define IS_SCSI(x)  ((x) && ((x)->misc_flags & SCSI_FLAG))
-#define IS_PRIVILEGED(x) ((x) && ((x)->misc_flags & PRIV_FLAG))
-#define IS_NOLOCK(x) ((x) && ((x)->misc_flags & NOLOCK_FLAG))
-#define IS_MFORMAT_ONLY(x) ((x) && ((x)->misc_flags & MFORMAT_ONLY_FLAG))
-#define SHOULD_USE_VOLD(x) ((x)&& ((x)->misc_flags & VOLD_FLAG))
-#define SHOULD_USE_XDF(x) ((x)&& ((x)->misc_flags & USE_XDF_FLAG))
-
-typedef struct device {
-	const char *name;       /* full path to device */
-
-	char *drive;	   	    	/* the drive letter / device name */
-	int fat_bits;			/* FAT encoding scheme */
-
-	unsigned int mode;		/* any special open() flags */
-	unsigned int tracks;	/* tracks */
-	unsigned int heads;		/* heads */
-	unsigned int sectors;	/* sectors */
-	unsigned int hidden;	/* number of hidden sectors. Used for
-							 * mformatting partitioned devices */
-
-	off_t offset;	       	/* skip this many bytes */
-
-	unsigned int partition;
-
-	unsigned int misc_flags;
-
-	/* Linux only stuff */
-	unsigned int ssize;
-	unsigned int use_2m;
-
-	char *precmd;		/* command to be executed before opening
-						 * the drive */
-
-	/* internal variables */
-	int file_nr;		/* used during parsing */
-	int blocksize;	        /* size of disk block in bytes */
-
-	const char *cfg_filename; /* used for debugging purposes */
-} device_t;
-
-
-#ifndef OS_linux
-#define BOOTSIZE 512
-#else
-#define BOOTSIZE 256
-#endif
-
-#include "stream.h"
-
-
-extern const char *short_illegals, *long_illegals;
-
-#define maximize(target, max) do { \
-  if(max < 0) { \
-    if(target > 0) \
-      target = 0; \
-  } else if(target > max) { \
-    target = max; \
-  } \
-} while(0)
-
-#define minimize(target, min) do { \
-  if(target < min) \
-    target = min; \
-} while(0) 
-
-int init_geom(int fd, struct device *dev, struct device *orig_dev,
-	      struct stat *stat);
-
-int readwrite_sectors(int fd, /* file descriptor */
-		      int *drive,
-		      int rate,
-		      int seektrack,
-		      int track, int head, int sector, int size, /* address */
-		      char *data, 
-		      int bytes,
-		      int direction,
-		      int retries);
-
-int lock_dev(int fd, int mode, struct device *dev);
-
-char *unix_normalize (char *ans, char *name, char *ext);
-char *dos_name(char *filename, int verbose, int *mangled, char *buffer);
-struct directory *mk_entry(const char *filename, char attr,
-			   unsigned int fat, size_t size, time_t date,
-			   struct directory *ndir);
-int copyfile(Stream_t *Source, Stream_t *Target);
-int getfreeMinClusters(Stream_t *Stream, size_t ref);
-
-FILE *opentty(int mode);
-
-int is_dir(Stream_t *Dir, char *path);
-void bufferize(Stream_t **Dir);
-
-int dir_grow(Stream_t *Dir, int size);
-int match(const char *, const char *, char *, int, int);
-
-char *unix_name(char *name, char *ext, char Case, char *answer);
-void *safe_malloc(size_t size);
-Stream_t *open_filter(Stream_t *Next);
-
-extern int got_signal;
-/* int do_gotsignal(char *, int);
-#define got_signal do_gotsignal(__FILE__, __LINE__) */
-
-void setup_signal(void);
-
-
-#define SET_INT(target, source) \
-if(source)target=source
-
-
-UNUSED(static inline int compare (long ref, long testee))
-{
-	return (ref && ref != testee);
-}
-
-Stream_t *GetFs(Stream_t *Fs);
-
-char *label_name(char *filename, int verbose, 
-		 int *mangled, char *ans);
-
-/* environmental variables */
-extern unsigned int mtools_skip_check;
-extern unsigned int mtools_fat_compatibility;
-extern unsigned int mtools_ignore_short_case;
-extern unsigned int mtools_no_vfat;
-extern unsigned int mtools_numeric_tail;
-extern unsigned int mtools_dotted_dir;
-extern unsigned int mtools_twenty_four_hour_clock;
-extern char *mtools_date_string;
-extern unsigned int mtools_rate_0, mtools_rate_any;
-extern int mtools_raw_tty;
-
-extern int batchmode;
-
-void read_config(void);
-extern struct device *devices;
-extern struct device const_devices[];
-extern const int nr_const_devices;
-
-#define New(type) ((type*)(malloc(sizeof(type))))
-#define Grow(adr,n,type) ((type*)(realloc((char *)adr,n*sizeof(type))))
-#define Free(adr) (free((char *)adr));
-#define NewArray(size,type) ((type*)(calloc((size),sizeof(type))))
-
-void mattrib(int argc, char **argv, int type);
-void mbadblocks(int argc, char **argv, int type);
-void mcat(int argc, char **argv, int type);
-void mcd(int argc, char **argv, int type);
-void mcopy(int argc, char **argv, int type);
-void mdel(int argc, char **argv, int type);
-void mdir(int argc, char **argv, int type);
-void mdoctorfat(int argc, char **argv, int type);
-void mdu(int argc, char **argv, int type);
-void mformat(int argc, char **argv, int type);
-void minfo(int argc, char **argv, int type);
-void mlabel(int argc, char **argv, int type);
-void mmd(int argc, char **argv, int type);
-void mmount(int argc, char **argv, int type);
-void mmove(int argc, char **argv, int type);
-void mpartition(int argc, char **argv, int type);
-void mshowfat(int argc, char **argv, int mtype);
-void mtoolstest(int argc, char **argv, int type);
-void mzip(int argc, char **argv, int type);
-
-extern int noPrivileges;
-void init_privs(void);
-void reclaim_privs(void);
-void drop_privs(void);
-void destroy_privs(void);
-uid_t get_real_uid(void);
-void closeExec(int fd);
-
-extern const char *progname;
-
-void precmd(struct device *dev);
-
-void print_sector(char *message, unsigned char *data, int size);
-time_t getTimeNow(time_t *now);
-
-#ifdef USING_NEW_VOLD
-char *getVoldName(struct device *dev, char *name);
-#endif
-
-
-Stream_t *OpenDir(Stream_t *Parent, const char *filename);
-/* int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); 
-int unix_loop(MainParam_t *mp, char *arg); */
-
-struct dirCache_t **getDirCacheP(Stream_t *Stream);
-int isRootDir(Stream_t *Stream);
-unsigned int getStart(Stream_t *Dir, struct directory *dir);
-unsigned int countBlocks(Stream_t *Dir, unsigned int block);
-char *getDrive(Stream_t *Stream);
-
-
-void printOom(void);
-int ask_confirmation(const char *, const char *, const char *);
-char *get_homedir(void);
-#define EXPAND_BUF 2048
-const char *expand(const char *, char *);
-const char *fix_mcwd(char *);
-FILE *open_mcwd(const char *mode);
-void unlink_mcwd(void);
-char *skip_drive(const char *path);
-char *get_drive(const char *path, const char *def);
-
-int safePopenOut(char **command, char *output, int len);
-
-#define ROUND_DOWN(value, grain) ((value) - (value) % (grain))
-#define ROUND_UP(value, grain) ROUND_DOWN((value) + (grain)-1, (grain))
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/mtoolsDirent.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mtoolsDirent.h	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#ifndef MTOOLS_DIRENTRY_H
-#define MTOOLS_DIRENTRY_H
-
-#include "sysincludes.h"
-#include "vfat.h"
-
-typedef struct direntry_t {
-	struct Stream_t *Dir;
-	/* struct direntry_t *parent; parent level */	
-	int entry; /* slot in parent directory (-3 if root) */
-	struct directory dir; /* descriptor in parent directory (random if 
-			       * root)*/
-	char name[MAX_VNAMELEN+1]; /* name in its parent directory, or 
-				    * NULL if root */
-	int beginSlot; /* begin and end slot, for delete */
-	int endSlot;
-} direntry_t;
-
-#include "stream.h"
-
-int vfat_lookup(direntry_t *entry, const char *filename, int length,
-		int flags, char *shortname, char *longname);
-
-struct directory *dir_read(direntry_t *entry, int *error);
-
-void initializeDirentry(direntry_t *entry, struct Stream_t *Dir);
-int isNotFound(direntry_t *entry);
-direntry_t *getParent(direntry_t *entry);
-void dir_write(direntry_t *entry);
-void low_level_dir_write(direntry_t *entry);
-int fatFreeWithDirentry(direntry_t *entry);
-int labelit(char *dosname,
-	    char *longname,
-	    void *arg0,
-	    direntry_t *entry);
-int isSubdirOf(Stream_t *inside, Stream_t *outside);
-char *getPwd(direntry_t *entry);
-void fprintPwd(FILE *f, direntry_t *entry, int escape);
-int write_vfat(Stream_t *, char *, char *, int, direntry_t *);
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/mtoolsPaths.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/mtoolsPaths.h	(revision 9)
+++ 	(revision )
@@ -1,32 +1,0 @@
-/*
- * Paths of the configuration files.
- * This file may be changed by the user as needed.
- * There are three empty lines between each definition.
- * These ensure that "local" patches and official patches have
- * only a very low probability of conflicting.
- */
-
-
-#define CONF_FILE "/etc/mtools.conf"
-
-
-#define OLD_CONF_FILE "/etc/mtools"
-
-
-
-#define LOCAL_CONF_FILE "/etc/default/mtools.conf"
-/* Use this if you like to keep the configuration file in a non-standard
- * place such as /etc/default, /opt/etc, /usr/etc, /usr/local/etc ...
- */
-
-#define SYS_CONF_FILE SYSCONFDIR "/mtools.conf"
-
-#define OLD_LOCAL_CONF_FILE "/etc/default/mtools"
-
-
-
-#define CFG_FILE1 "/.mtoolsrc"
-
-
-
-/* END */
Index: trunk/minix/commands/i386/mtools-3.9.7/nameclash.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/nameclash.h	(revision 9)
+++ 	(revision )
@@ -1,57 +1,0 @@
-#ifndef MTOOLS_NAMECLASH_H
-#define MTOOLS_NAMECLASH_H
-
-#include "stream.h"
-
-typedef enum clash_action {
-	NAMEMATCH_NONE,
-	NAMEMATCH_AUTORENAME,
-	NAMEMATCH_QUIT,
-	NAMEMATCH_SKIP,
-	NAMEMATCH_RENAME,
-	NAMEMATCH_PRENAME, /* renaming of primary name */
-	NAMEMATCH_OVERWRITE,
-	NAMEMATCH_ERROR,
-	NAMEMATCH_SUCCESS,
-	NAMEMATCH_GREW
-} clash_action;
-
-/* clash handling structure */
-typedef struct ClashHandling_t {
-	clash_action action[2];
-	clash_action namematch_default[2];
-		
-	int nowarn;	/* Don't ask, just do default action if name collision*/
-	int got_slots;
-	int mod_time;
-	/* unsigned int dot; */
-	char *myname;
-	unsigned char *dosname;
-	int single;
-
-	int use_longname;
-	int ignore_entry;
-	int source; /* to prevent the source from overwriting itself */
-	int source_entry; /* to account for the space freed up by the original 
-					   * name */
-	char * (*name_converter)(char *filename, int verbose, 
-				 int *mangled, char *ans);
-} ClashHandling_t;
-
-/* write callback */
-typedef int (write_data_callback)(char *,char *, void *, struct direntry_t *);
-
-int mwrite_one(Stream_t *Dir,
-	       const char *argname,
-	       const char *shortname,
-	       write_data_callback *cb,
-	       void *arg,
-	       ClashHandling_t *ch);
-
-int handle_clash_options(ClashHandling_t *ch, char c);
-void init_clash_handling(ClashHandling_t *ch);
-Stream_t *createDir(Stream_t *Dir, const char *filename, ClashHandling_t *ch,
-		    unsigned char attr, time_t mtime);
-
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/partition.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/partition.h	(revision 9)
+++ 	(revision )
@@ -1,31 +1,0 @@
-typedef struct hsc {
-	unsigned char byte0;
-	unsigned char head;		/* starting head */
-	unsigned char sector;		/* starting sector */
-	unsigned char cyl;		/* starting cylinder */
-} hsc;
-
-#define head(x) ((x).head)
-#define sector(x) ((x).sector & 0x3f)
-#define cyl(x) ((x).cyl | (((x).sector & 0xc0)<<2))
-
-#define BEGIN(p) _DWORD((p).start_sect)
-#define END(p) (_DWORD((p).start_sect)+(_DWORD((p).nr_sects)))
-
-
-struct partition {
-	hsc start;
-	hsc end;
-	unsigned char start_sect[4];	/* starting sector counting from 0 */
-	unsigned char nr_sects[4];     	/* nr of sectors in partition */
-};
-
-#define boot_ind start.byte0
-#define sys_ind end.byte0
-
-int consistencyCheck(struct partition *partTable, int doprint, int verbose,
-		     int *has_activated, int *last_end, int *j, 
-		     struct device *used_dev, int target_partition);
-
-void setBeginEnd(struct partition *partTable, int begin, int end,
-				 int heads, int sector, int activate, int type);
Index: trunk/minix/commands/i386/mtools-3.9.7/patchlevel.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/patchlevel.c	(revision 9)
+++ 	(revision )
@@ -1,2 +1,0 @@
-const char *mversion="3.9.7";
-const char *mdate = "1 jun 2000";
Index: trunk/minix/commands/i386/mtools-3.9.7/plain_io.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/plain_io.c	(revision 9)
+++ 	(revision )
@@ -1,749 +1,0 @@
-/*
- * Io to a plain file or device
- *
- * written by:
- *
- * Alain L. Knaff			
- * alain@linux.lu
- *
- */
-
-#include "sysincludes.h"
-#include "stream.h"
-#include "mtools.h"
-#include "msdos.h"
-#include "plain_io.h"
-#include "scsi.h"
-#include "partition.h"
-#include "llong.h"
-
-typedef struct SimpleFile_t {
-    Class_t *Class;
-    int refs;
-    Stream_t *Next;
-    Stream_t *Buffer;
-    struct stat stat;
-    int fd;
-    mt_off_t offset;
-    mt_off_t lastwhere;
-    int seekable;
-    int privileged;
-#ifdef OS_hpux
-    int size_limited;
-#endif
-    int scsi_sector_size;
-    void *extra_data; /* extra system dependant information for scsi */
-} SimpleFile_t;
-
-
-/*
- * Create an advisory lock on the device to prevent concurrent writes.
- * Uses either lockf, flock, or fcntl locking methods.  See the Makefile
- * and the Configure files for how to specify the proper method.
- */
-
-int lock_dev(int fd, int mode, struct device *dev)
-{
-#if (defined(HAVE_FLOCK) && defined (LOCK_EX) && defined(LOCK_NB))
-	/**/
-#else /* FLOCK */
-
-#if (defined(HAVE_LOCKF) && defined(F_TLOCK))
-	/**/
-#else /* LOCKF */
-
-#if (defined(F_SETLK) && defined(F_WRLCK))
-	struct flock flk;
-
-#endif /* FCNTL */
-#endif /* LOCKF */
-#endif /* FLOCK */
-
-	if(IS_NOLOCK(dev))
-		return 0;
-
-#if (defined(HAVE_FLOCK) && defined (LOCK_EX) && defined(LOCK_NB))
-	if (flock(fd, (mode ? LOCK_EX : LOCK_SH)|LOCK_NB) < 0)
-#else /* FLOCK */
-
-#if (defined(HAVE_LOCKF) && defined(F_TLOCK))
-	if (mode && lockf(fd, F_TLOCK, 0) < 0)
-#else /* LOCKF */
-
-#if (defined(F_SETLK) && defined(F_WRLCK))
-	flk.l_type = mode ? F_WRLCK : F_RDLCK;
-	flk.l_whence = 0;
-	flk.l_start = 0L;
-	flk.l_len = 0L;
-
-	if (fcntl(fd, F_SETLK, &flk) < 0)
-#endif /* FCNTL */
-#endif /* LOCKF */
-#endif /* FLOCK */
-	{
-		if(errno == EINVAL
-#ifdef  EOPNOTSUPP 
-		   || errno ==  EOPNOTSUPP
-#endif
-		  )
-			return 0;
-		else
-			return 1;
-	}
-	return 0;
-}
-
-typedef int (*iofn) (int, char *, int);
-
-
-
-static int file_io(Stream_t *Stream, char *buf, mt_off_t where, int len,
-				   iofn io)
-{
-	DeclareThis(SimpleFile_t);
-	int ret;
-
-	where += This->offset;
-
-	if (This->seekable && where != This->lastwhere ){
-		if(mt_lseek( This->fd, where, SEEK_SET) < 0 ){
-			perror("seek");
-			This->lastwhere = (mt_off_t) -1;
-			return -1;
-		}
-	}
-
-#ifdef OS_hpux
-	/*
-	 * On HP/UX, we can not write more than MAX_LEN bytes in one go.
-	 * If more are written, the write fails with EINVAL
-	 */
-	#define MAX_SCSI_LEN (127*1024)
-	if(This->size_limited && len > MAX_SCSI_LEN)
-		len = MAX_SCSI_LEN;
-#endif
-	ret = io(This->fd, buf, len);
-
-#ifdef OS_hpux
-	if (ret == -1 && 
-		errno == EINVAL && /* if we got EINVAL */
-		len > MAX_SCSI_LEN) {
-		This->size_limited = 1;
-		len = MAX_SCSI_LEN;
-		ret = io(This->fd, buf, len);
-	}
-#endif
-
-	if ( ret == -1 ){
-		perror("plain_io");
-		This->lastwhere = (mt_off_t) -1;
-		return -1;
-	}
-	This->lastwhere = where + ret;
-	return ret;
-}
-	
-
-
-static int file_read(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
-{	
-	return file_io(Stream, buf, where, len, (iofn) read);
-}
-
-static int file_write(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
-{
-	return file_io(Stream, buf, where, len, (iofn) write);
-}
-
-static int file_flush(Stream_t *Stream)
-{
-#if 0
-	DeclareThis(SimpleFile_t);
-
-	return fsync(This->fd);
-#endif
-	return 0;
-}
-
-static int file_free(Stream_t *Stream)
-{
-	DeclareThis(SimpleFile_t);
-
-	if (This->fd > 2)
-		return close(This->fd);
-	else
-		return 0;
-}
-
-static int file_geom(Stream_t *Stream, struct device *dev, 
-		     struct device *orig_dev,
-		     int media, struct bootsector *boot)
-{
-	int ret;
-	DeclareThis(SimpleFile_t);
-	size_t tot_sectors;
-	int BootP, Infp0, InfpX, InfTm;
-	int sectors, j;
-	unsigned char sum;
-	int sect_per_track;
-	struct label_blk_t *labelBlock;
-
-	dev->ssize = 2; /* allow for init_geom to change it */
-	dev->use_2m = 0x80; /* disable 2m mode to begin */
-
-	if(media == 0xf0 || media >= 0x100){		
-		dev->heads = WORD(nheads);
-		dev->sectors = WORD(nsect);
-		tot_sectors = DWORD(bigsect);
-		SET_INT(tot_sectors, WORD(psect));
-		sect_per_track = dev->heads * dev->sectors;
-		tot_sectors += sect_per_track - 1; /* round size up */
-		dev->tracks = tot_sectors / sect_per_track;
-
-		BootP = WORD(ext.old.BootP);
-		Infp0 = WORD(ext.old.Infp0);
-		InfpX = WORD(ext.old.InfpX);
-		InfTm = WORD(ext.old.InfTm);
-		
-		if(WORD(fatlen)) {
-			labelBlock = &boot->ext.old.labelBlock;
-		} else {
-			labelBlock = &boot->ext.fat32.labelBlock;
-		}
-
-		if (boot->descr >= 0xf0 &&
-		    labelBlock->dos4 == 0x29 &&
-		    strncmp( boot->banner,"2M", 2 ) == 0 &&
-		    BootP < 512 && Infp0 < 512 && InfpX < 512 && InfTm < 512 &&
-		    BootP >= InfTm + 2 && InfTm >= InfpX && InfpX >= Infp0 && 
-		    Infp0 >= 76 ){
-			for (sum=0, j=63; j < BootP; j++) 
-				sum += boot->jump[j];/* checksum */
-			dev->ssize = boot->jump[InfTm];
-			if (!sum && dev->ssize <= 7){
-				dev->use_2m = 0xff;
-				dev->ssize |= 0x80; /* is set */
-			}
-		}
-	} else if (media >= 0xf8){
-		media &= 3;
-		dev->heads = old_dos[media].heads;
-		dev->tracks = old_dos[media].tracks;
-		dev->sectors = old_dos[media].sectors;
-		dev->ssize = 0x80;
-		dev->use_2m = ~1;
-	} else {
-		fprintf(stderr,"Unknown media type\n");
-		exit(1);
-	}
-
-	sectors = dev->sectors;
-	dev->sectors = dev->sectors * WORD(secsiz) / 512;
-
-#ifdef JPD
-	printf("file_geom:media=%0X=>cyl=%d,heads=%d,sects=%d,ssize=%d,use2m=%X\n",
-	       media, dev->tracks, dev->heads, dev->sectors, dev->ssize,
-	       dev->use_2m);
-#endif
-	ret = init_geom(This->fd,dev, orig_dev, &This->stat);
-	dev->sectors = sectors;
-#ifdef JPD
-	printf("f_geom: after init_geom(), sects=%d\n", dev->sectors);
-#endif
-	return ret;
-}
-
-
-static int file_data(Stream_t *Stream, time_t *date, mt_size_t *size,
-		     int *type, int *address)
-{
-	DeclareThis(SimpleFile_t);
-
-	if(date)
-		*date = This->stat.st_mtime;
-	if(size)
-		*size = This->stat.st_size;
-	if(type)
-		*type = S_ISDIR(This->stat.st_mode);
-	if(address)
-		*address = 0;
-	return 0;
-}
-
-/* ZIP or other scsi device on Solaris or SunOS system.
-   Since Sun won't accept a non-Sun label on a scsi disk, we must
-   bypass Sun's disk interface and use low-level SCSI commands to read
-   or write the ZIP drive.  We thus replace the file_read and file_write
-   routines with our own scsi_read and scsi_write routines, that use the
-   uscsi ioctl interface.  By James Dugal, jpd@usl.edu, 11-96.  Tested
-   under Solaris 2.5 and SunOS 4.3.1_u1 using GCC.
-
-   Note: the mtools.conf entry for a ZIP drive would look like this:
-(solaris) drive C: file="/dev/rdsk/c0t5d0s2" partition=4  FAT=16 nodelay  exclusive scsi=&
-(sunos) drive C: file="/dev/rsd5c" partition=4  FAT=16 nodelay  exclusive scsi=1
-
-   Note 2: Sol 2.5 wants mtools to be suid-root, to use the ioctl.  SunOS is
-   happy if we just have access to the device, so making mtools sgid to a
-   group called, say, "ziprw" which has rw permission on /dev/rsd5c, is fine.
- */
-
-#define MAXBLKSPERCMD 255
-
-static void scsi_init(SimpleFile_t *This)
-{
-   int fd = This->fd;
-   unsigned char cdb[10],buf[8];
-
-   memset(cdb, 0, sizeof cdb);
-   memset(buf,0, sizeof(buf));
-   cdb[0]=SCSI_READ_CAPACITY;
-   if (scsi_cmd(fd, (unsigned char *)cdb, 
-		sizeof(cdb), SCSI_IO_READ, buf, sizeof(buf), This->extra_data)==0)
-   {
-       This->scsi_sector_size=
-	       ((unsigned)buf[5]<<16)|((unsigned)buf[6]<<8)|(unsigned)buf[7];
-       if (This->scsi_sector_size != 512)
-	   fprintf(stderr,"  (scsi_sector_size=%d)\n",This->scsi_sector_size);
-   }
-}
-
-int scsi_io(Stream_t *Stream, char *buf,  mt_off_t where, size_t len, int rwcmd)
-{
-	unsigned int firstblock, nsect;
-	int clen,r,max;
-	off_t offset;
-	unsigned char cdb[10];
-	DeclareThis(SimpleFile_t);
-
-	firstblock=truncBytes32((where + This->offset)/This->scsi_sector_size);
-	/* 512,1024,2048,... bytes/sector supported */
-	offset=truncBytes32(where + This->offset - 
-						firstblock*This->scsi_sector_size);
-	nsect=(offset+len+This->scsi_sector_size-1)/ This->scsi_sector_size;
-#if defined(OS_sun) && defined(OS_i386)
-	if (This->scsi_sector_size>512)
-		firstblock*=This->scsi_sector_size/512; /* work around a uscsi bug */
-#endif /* sun && i386 */
-
-	if (len>512) {
-		/* avoid buffer overruns. The transfer MUST be smaller or
-		* equal to the requested size! */
-		while (nsect*This->scsi_sector_size>len)
-			--nsect;
-		if(!nsect) {			
-			fprintf(stderr,"Scsi buffer too small\n");
-			exit(1);
-		}
-		if(rwcmd == SCSI_IO_WRITE && offset) {
-			/* there seems to be no memmove before a write */
-			fprintf(stderr,"Unaligned write\n");
-			exit(1);
-		}
-		/* a better implementation should use bounce buffers.
-		 * However, in normal operation no buffer overruns or
-		 * unaligned writes should happen anyways, as the logical
-		 * sector size is (hopefully!) equal to the physical one
-		 */
-	}
-
-
-	max = scsi_max_length();
-	
-	if (nsect > max)
-		nsect=max;
-	
-	/* set up SCSI READ/WRITE command */
-	memset(cdb, 0, sizeof cdb);
-
-	switch(rwcmd) {
-		case SCSI_IO_READ:
-			cdb[0] = SCSI_READ;
-			break;
-		case SCSI_IO_WRITE:
-			cdb[0] = SCSI_WRITE;
-			break;
-	}
-
-	cdb[1] = 0;
-
-	if (firstblock > 0x1fffff || nsect > 0xff) {
-		/* I suspect that the ZIP drive also understands Group 1
-		 * commands. If that is indeed true, we may chose Group 1
-		 * more agressively in the future */
-
-		cdb[0] |= SCSI_GROUP1;
-		clen=10; /* SCSI Group 1 cmd */
-
-		/* this is one of the rare case where explicit coding is
-		 * more portable than macros... The meaning of scsi command
-		 * bytes is standardised, whereas the preprocessor macros
-		 * handling it might be not... */
-
-		cdb[2] = (unsigned char) (firstblock >> 24) & 0xff;
-		cdb[3] = (unsigned char) (firstblock >> 16) & 0xff;
-		cdb[4] = (unsigned char) (firstblock >> 8) & 0xff;
-		cdb[5] = (unsigned char) firstblock & 0xff;
-		cdb[6] = 0;
-		cdb[7] = (unsigned char) (nsect >> 8) & 0xff;
-		cdb[8] = (unsigned char) nsect & 0xff;
-		cdb[9] = 0;
-	} else {
-		clen = 6; /* SCSI Group 0 cmd */
-		cdb[1] |= (unsigned char) ((firstblock >> 16) & 0x1f);
-		cdb[2] = (unsigned char) ((firstblock >> 8) & 0xff);
-		cdb[3] = (unsigned char) firstblock & 0xff;
-		cdb[4] = (unsigned char) nsect;
-		cdb[5] = 0;
-	}
-	
-	if(This->privileged)
-		reclaim_privs();
-
-	r=scsi_cmd(This->fd, (unsigned char *)cdb, clen, rwcmd, buf,
-		   nsect*This->scsi_sector_size, This->extra_data);
-
-	if(This->privileged)
-		drop_privs();
-
-	if(r) {
-		perror(rwcmd == SCSI_IO_READ ? "SCMD_READ" : "SCMD_WRITE");
-		return -1;
-	}
-#ifdef JPD
-	printf("finished %u for %u\n", firstblock, nsect);
-#endif
-
-#ifdef JPD
-	printf("zip: read or write OK\n");
-#endif
-	if (offset>0) memmove(buf,buf+offset,nsect*This->scsi_sector_size-offset);
-	if (len==256) return 256;
-	else if (len==512) return 512;
-	else return nsect*This->scsi_sector_size-offset;
-}
-
-int scsi_read(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
-{
-	
-#ifdef JPD
-	printf("zip: to read %d bytes at %d\n", len, where);
-#endif
-	return scsi_io(Stream, buf, where, len, SCSI_IO_READ);
-}
-
-int scsi_write(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
-{
-#ifdef JPD
-	Printf("zip: to write %d bytes at %d\n", len, where);
-#endif
-	return scsi_io(Stream, buf, where, len, SCSI_IO_WRITE);
-}
-
-static Class_t ScsiClass = {
-	scsi_read, 
-	scsi_write,
-	file_flush,
-	file_free,
-	file_geom,
-	file_data,
-	0 /* pre-allocate */
-};
-
-
-static Class_t SimpleFileClass = {
-	file_read, 
-	file_write,
-	file_flush,
-	file_free,
-	file_geom,
-	file_data,
-	0 /* pre_allocate */
-};
-
-
-Stream_t *SimpleFileOpen(struct device *dev, struct device *orig_dev,
-			 const char *name, int mode, char *errmsg, 
-			 int mode2, int locked, mt_size_t *maxSize)
-{
-	SimpleFile_t *This;
-#ifdef __EMX__
-HFILE FileHandle;
-ULONG Action;
-APIRET rc;
-#endif
-	This = New(SimpleFile_t);
-	if (!This){
-		printOom();
-		return 0;
-	}
-	This->scsi_sector_size = 512;
-	This->seekable = 1;
-#ifdef OS_hpux
-	This->size_limited = 0;
-#endif
-	This->Class = &SimpleFileClass;
-	if (!name || strcmp(name,"-") == 0 ){
-		if (mode == O_RDONLY)
-			This->fd = 0;
-		else
-			This->fd = 1;
-		This->seekable = 0;
-		This->refs = 1;
-		This->Next = 0;
-		This->Buffer = 0;
-		if (fstat(This->fd, &This->stat) < 0) {
-		    Free(This);
-		    if(errmsg)
-#ifdef HAVE_SNPRINTF
-			snprintf(errmsg,199,"Can't stat -: %s", 
-				strerror(errno));   
-#else
-			sprintf(errmsg,"Can't stat -: %s", 
-				strerror(errno));
-#endif
-		    return NULL;
-		}
-
-		return (Stream_t *) This;
-	}
-
-	
-	if(dev) {
-		if(!(mode2 & NO_PRIV))
-			This->privileged = IS_PRIVILEGED(dev);
-		mode |= dev->mode;
-	}
-
-	precmd(dev);
-	if(IS_PRIVILEGED(dev) && !(mode2 & NO_PRIV))
-		reclaim_privs();
-
-#ifdef __EMX__
-#define DOSOPEN_FLAGS	(OPEN_FLAGS_DASD | OPEN_FLAGS_WRITE_THROUGH | \
-			OPEN_FLAGS_NOINHERIT | OPEN_FLAGS_RANDOM | \
-			OPEN_FLAGS_NO_CACHE)
-#define DOSOPEN_FD_ACCESS (OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE)
-#define DOSOPEN_HD_ACCESS (OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY)
-
-	if (skip_drive(name) > name) {
-		rc = DosOpen(
-			name, &FileHandle, &Action, 0L, FILE_NORMAL,
-			OPEN_ACTION_OPEN_IF_EXISTS, DOSOPEN_FLAGS |
-			(IS_NOLOCK(dev)?DOSOPEN_HD_ACCESS:DOSOPEN_FD_ACCESS),
-			0L);
-#ifdef DEBUG
-		if (rc != NO_ERROR) fprintf (stderr, "DosOpen() returned %d\n", rc);
-#endif
-		if (!IS_NOLOCK(dev)) {
-			rc = DosDevIOCtl(
-			FileHandle, 0x08L, DSK_LOCKDRIVE, 0, 0, 0, 0, 0, 0);
-#ifdef DEBUG
-			if (rc != NO_ERROR) fprintf (stderr, "DosDevIOCtl() returned %d\n", rc);
-#endif
-		}
-		if (rc == NO_ERROR)
-			This->fd = _imphandle(FileHandle); else This->fd = -1;
-	} else
-#endif
-	    {
-		if (IS_SCSI(dev))
-		    This->fd = scsi_open(name, mode, IS_NOLOCK(dev)?0444:0666,
-					 &This->extra_data);
-		else
-		    This->fd = open(name, mode, IS_NOLOCK(dev)?0444:0666);
-	    }
-
-	if(IS_PRIVILEGED(dev) && !(mode2 & NO_PRIV))
-		drop_privs();
-		
-	if (This->fd < 0) {
-		Free(This);
-		if(errmsg)
-#ifdef HAVE_SNPRINTF
-			snprintf(errmsg, 199, "Can't open %s: %s",
-				name, strerror(errno));
-#else
-			sprintf(errmsg, "Can't open %s: %s",
-				name, strerror(errno));
-#endif
-		return NULL;
-	}
-
-	if(IS_PRIVILEGED(dev) && !(mode2 & NO_PRIV))
-		closeExec(This->fd);
-
-#ifdef __EMX__
-	if (*(name+1) != ':')
-#endif
-	if (fstat(This->fd, &This->stat) < 0){
-		Free(This);
-		if(errmsg) {
-#ifdef HAVE_SNPRINTF
-			snprintf(errmsg,199,"Can't stat %s: %s", 
-				name, strerror(errno));
-#else
-			if(strlen(name) > 50) {
-			    sprintf(errmsg,"Can't stat file: %s", 
-				    strerror(errno));
-			} else {
-			    sprintf(errmsg,"Can't stat %s: %s", 
-				name, strerror(errno));
-			}
-#endif
-		}
-		return NULL;
-	}
-#ifndef __EMX__
-	/* lock the device on writes */
-	if (locked && lock_dev(This->fd, mode == O_RDWR, dev)) {
-		if(errmsg)
-#ifdef HAVE_SNPRINTF
-			snprintf(errmsg,199,
-				"plain floppy: device \"%s\" busy (%s):",
-				dev ? dev->name : "unknown", strerror(errno));
-#else
-			sprintf(errmsg,
-				"plain floppy: device \"%s\" busy (%s):",
-				(dev && strlen(dev->name) < 50) ? 
-				 dev->name : "unknown", strerror(errno));
-#endif
-
-		close(This->fd);
-		Free(This);
-		return NULL;
-	}
-#endif
-	/* set default parameters, if needed */
-	if (dev){		
-		if ((IS_MFORMAT_ONLY(dev) || !dev->tracks) &&
-			init_geom(This->fd, dev, orig_dev, &This->stat)){
-			close(This->fd);
-			Free(This);
-			if(errmsg)
-				sprintf(errmsg,"init: set default params");
-			return NULL;
-		}
-		This->offset = (mt_off_t) dev->offset;
-	} else
-		This->offset = 0;
-
-	This->refs = 1;
-	This->Next = 0;
-	This->Buffer = 0;
-
-	if(maxSize) {
-		if (IS_SCSI(dev)) {
-			*maxSize = MAX_OFF_T_B(31+log_2(This->scsi_sector_size));
-		} else {
-			*maxSize = max_off_t_seek;
-		}
-		if(This->offset > *maxSize) {
-			close(This->fd);
-			Free(This);
-			if(errmsg)
-				sprintf(errmsg,"init: Big disks not supported");
-			return NULL;
-		}
-		
-		*maxSize -= This->offset;
-	}
-	/* partitioned drive */
-
-	/* jpd@usl.edu: assume a partitioned drive on these 2 systems is a ZIP*/
-	/* or similar drive that must be accessed by low-level scsi commands */
-	/* AK: introduce new "scsi=1" statement to specifically set
-	 * this option. Indeed, there could conceivably be partitioned
-	 * devices where low level scsi commands will not be needed */
-	if(IS_SCSI(dev)) {
-		This->Class = &ScsiClass;
-		if(This->privileged)
-			reclaim_privs();
-		scsi_init(This);
-		if(This->privileged)
-			drop_privs();
-	}
-	while(!(mode2 & NO_OFFSET) &&
-	      dev && dev->partition && dev->partition <= 4) {
-		int has_activated, last_end, j;
-		unsigned char buf[2048];
-		struct partition *partTable=(struct partition *)(buf+ 0x1ae);
-		size_t partOff;
-		
-		/* read the first sector, or part of it */
-		if (force_read((Stream_t *)This, (char*) buf, 0, 512) != 512)
-			break;
-		if( _WORD(buf+510) != 0xaa55)
-			break;
-
-		partOff = BEGIN(partTable[dev->partition]);
-		if (maxSize) {
-			if (partOff > *maxSize >> 9) {
-				close(This->fd);
-				Free(This);
-				if(errmsg)
-					sprintf(errmsg,"init: Big disks not supported");
-				return NULL;
-			}
-			*maxSize -= (mt_off_t) partOff << 9;
-		}
-			
-		This->offset += (mt_off_t) partOff << 9;
-		if(!partTable[dev->partition].sys_ind) {
-			if(errmsg)
-				sprintf(errmsg,
-					"init: non-existant partition");
-			close(This->fd);
-			Free(This);
-			return NULL;
-		}
-
-		if(!dev->tracks) {
-			dev->heads = head(partTable[dev->partition].end)+1;
-			dev->sectors = sector(partTable[dev->partition].end);
-			dev->tracks = cyl(partTable[dev->partition].end) -
-				cyl(partTable[dev->partition].start)+1;
-		}
-		dev->hidden=dev->sectors*head(partTable[dev->partition].start);
-		if(!mtools_skip_check &&
-		   consistencyCheck((struct partition *)(buf+0x1ae), 0, 0,
-				    &has_activated, &last_end, &j, dev, 0)) {
-			fprintf(stderr,
-				"Warning: inconsistent partition table\n");
-			fprintf(stderr,
-				"Possibly unpartitioned device\n");
-			fprintf(stderr,
-				"\n*** Maybe try without partition=%d in "
-				"device definition ***\n\n",
-				dev->partition);
-			fprintf(stderr,
-                                "If this is a PCMCIA card, or a disk "
-				"partitioned on another computer, this "
-				"message may be in error: add "
-				"mtools_skip_check=1 to your .mtoolsrc "
-				"file to suppress this warning\n");
-
-		}
-		break;
-		/* NOTREACHED */
-	}
-
-	This->lastwhere = -This->offset;
-	/* provoke a seek on those devices that don't start on a partition
-	 * boundary */
-
-	return (Stream_t *) This;
-}
-
-int get_fd(Stream_t *Stream)
-{
-	DeclareThis(SimpleFile_t);
-	
-	return This->fd;
-}
-
-void *get_extra_data(Stream_t *Stream)
-{
-	DeclareThis(SimpleFile_t);
-	
-	return This->extra_data;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/plain_io.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/plain_io.h	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-#ifndef MTOOLS_PLAINIO_H
-#define MTOOLS_PLAINIO_H
-
-#include "stream.h"
-#include "msdos.h"
-#ifdef __EMX__
-#include <io.h>
-#endif
-
-/* plain io */
-#define NO_PRIV 1
-#define NO_OFFSET 2
-
-Stream_t *SimpleFileOpen(struct device *dev, struct device *orig_dev,
-			 const char *name, int mode, char *errmsg, int mode2,
-			 int locked, mt_size_t *maxSize);
-int check_parameters(struct device *ref, struct device *testee);
-
-int get_fd(Stream_t *Stream);
-void *get_extra_data(Stream_t *Stream);
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/precmd.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/precmd.c	(revision 9)
+++ 	(revision )
@@ -1,31 +1,0 @@
-/*
- * Do filename expansion with the shell.
- */
-
-#define EXPAND_BUF	2048
-
-#include "sysincludes.h"
-#include "mtools.h"
-
-void precmd(struct device *dev)
-{
-	int status;
-	pid_t pid;
-
-	if(!dev || !dev->precmd)
-		return;
-	
-	switch((pid=fork())){
-		case -1:
-			perror("Could not fork");
-			exit(1);
-			break;
-		case 0: /* the son */
-			execl("/bin/sh", "sh", "-c", dev->precmd, 0);
-			break;
-		default:
-			wait(&status);
-			break;
-	}
-}
-		
Index: trunk/minix/commands/i386/mtools-3.9.7/privileges.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/privileges.c	(revision 9)
+++ 	(revision )
@@ -1,166 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-
-/*#define PRIV_DEBUG*/
-
-#if 0
-#undef HAVE_SETEUID
-#define HAVE_SETRESUID
-#include <asm/unistd.h>
-int setresuid(int a, int b, int c)
-{
-	syscall(164, a, b, c);
-
-}
-#endif
-
-static inline void print_privs(const char *message)
-{
-#ifdef PRIV_DEBUG
-	/* for debugging purposes only */
-	fprintf(stderr,"%s egid=%d rgid=%d\n", message, getegid(), getgid());
-	fprintf(stderr,"%s euid=%d ruid=%d\n", message, geteuid(), getuid());
-#endif
-}
-
-int noPrivileges=0;
-
-
-static gid_t rgid, egid;
-static uid_t ruid, euid;
-
-/* privilege management routines for SunOS and Solaris.  These are
- * needed in order to issue raw SCSI read/write ioctls.  Mtools drops
- * its privileges at the beginning, and reclaims them just for the
- * above-mentioned ioctl's.  Before popen(), exec() or system, it
- * drops its privileges completely, and issues a warning.
- */
-
-
-/* group id handling is lots easyer, as long as we don't use group 0.
- * If you want to use group id's, create a *new* group mtools or
- * floppy.  Chgrp any devices that you only want to be accessible to
- * mtools to this group, and give them the appropriate privs.  Make
- * sure this group doesn't own any other files: be aware that any user
- * with access to mtools may mformat these files!
- */
-
-
-static inline void Setuid(uid_t uid)
-{
-#if defined HAVE_SETEUID || defined HAVE_SETRESUID
-	if(euid == 0) {
-#ifdef HAVE_SETEUID
-		seteuid(uid);
-#else
-		setresuid(ruid, uid, euid);
-#endif
-	} else
-#endif
-		setuid(uid);
-}
-
-/* In reclaim_privs and drop privs, we have to manipulate group privileges
- * when having no root privileges, else we might lose them */
-
-void reclaim_privs(void)
-{
-	if(noPrivileges)
-		return;
-	setgid(egid);
-	Setuid(euid);
-	print_privs("after reclaim privs, both uids should be 0 ");
-}
-
-void drop_privs(void)
-{
-	Setuid(ruid);
-	setgid(rgid);
-	print_privs("after drop_privs, real should be 0, effective should not ");
-}
-
-void destroy_privs(void)
-{
-
-#if defined HAVE_SETEUID || defined HAVE_SETRESUID
-	if(euid == 0) {
-#ifdef HAVE_SETEUID
-		setuid(0); /* get the necessary privs to drop real root id */
-		setuid(ruid); /* this should be enough to get rid of the three
-			       * ids */
-		seteuid(ruid); /* for good measure... just in case we came
-				* accross a system which implemented sane
-				* semantics instead of POSIXly broken
-				* semantics for setuid */
-#else
-		setresuid(ruid, ruid, ruid);
-#endif
-	}
-#endif
-
-	/* we also destroy group privileges */
-	drop_privs();
-
-	/* saved set [ug]id will go away by itself on exec */
-
-	print_privs("destroy_privs, no uid should be zero  ");
-}
-
-
-uid_t get_real_uid(void)
-{
-	return ruid;
-}
-
-void init_privs(void)
-{
-	euid = geteuid();
-	ruid = getuid();
-	egid = getegid();
-	rgid = getgid();
-
-#ifndef F_SETFD
-	if(euid != ruid) {
-		fprintf(stderr,
-			"Setuid installation not supported on this platform\n");
-		fprintf(stderr,
-			"Missing F_SETFD");
-		exit(1);
-	}
-#endif
-	
-	if(euid == 0 && ruid != 0) {
-#ifdef HAVE_SETEUID
-		setuid(0); /* set real uid to 0 */
-#else
-#ifndef HAVE_SETRESUID
-		/* on this machine, it is not possible to reversibly drop
-		 * root privileges.  We print an error and quit */
-
-		/* BEOS is no longer a special case, as both euid and ruid
-		 * return 0, and thus we do not get any longer into this
-		 * branch */
-		fprintf(stderr,
-			"Seteuid call not supported on this architecture.\n");
-		fprintf(stderr,
-			"Mtools cannot be installed setuid root.\n");
-		fprintf(stderr,
-			"However, it can be installed setuid to a non root");
-		fprintf(stderr,
-			"user or setgid to any id.\n");
-		exit(1);
-#endif
-#endif
-	}
-	
-	drop_privs();
-	print_privs("after init, real should be 0, effective should not ");
-}
-
-void closeExec(int fd)
-{
-#ifdef F_SETFD
-	fcntl(fd, F_SETFD, 1);
-#endif
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/scsi.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/scsi.c	(revision 9)
+++ 	(revision )
@@ -1,274 +1,0 @@
-/*
- * scsi.c
- * Iomega Zip/Jaz drive tool
- * change protection mode and eject disk
- */
-
-/* scis.c by Markus Gyger <mgyger@itr.ch> */
-/* This code is based on ftp://gear.torque.net/pub/ziptool.c */
-/* by Grant R. Guenther with the following copyright notice: */
-
-/*  (c) 1996   Grant R. Guenther,  based on work of Itai Nahshon  */
-/*  http://www.torque.net/ziptool.html  */
-
-
-/* A.K. Moved this from mzip.c to a separate file in order to share with
- * plain_io.c */
-
-#include "sysincludes.h"
-#include "mtools.h"
-#include "scsi.h"
-
-#if defined OS_hpux
-#include <sys/scsi.h>
-#endif
-
-#ifdef OS_solaris
-#include <sys/scsi/scsi.h>
-#endif /* solaris */
-
-#ifdef OS_sunos
-#include <scsi/generic/commands.h>
-#include <scsi/impl/uscsi.h>
-#endif /* sunos */
-
-#ifdef sgi
-#include <sys/dsreq.h>
-#endif
-
-#ifdef OS_linux
-#define SCSI_IOCTL_SEND_COMMAND 1
-struct scsi_ioctl_command {
-    int  inlen;
-    int  outlen;
-    char cmd[5008];
-};
-#endif
-
-#ifdef _SCO_DS
-#include <sys/scsicmd.h>
-#endif
-
-#if (defined(OS_freebsd)) && (__FreeBSD__ >= 2)
-#include <camlib.h>
-#endif
-
-int scsi_max_length(void)
-{
-#ifdef OS_linux
-	return 8;
-#else
-	return 255;
-#endif
-}
-
-int scsi_open(const char *name, int flag, int mode, void **extra_data)
-{
-#if (defined(OS_freebsd)) && (__FreeBSD__ >= 2)
-    struct cam_device *cam_dev;
-    cam_dev = cam_open_device(name, O_RDWR);
-    *extra_data = (void *) cam_dev;
-    if (cam_dev)
-        return cam_dev->fd;
-    else
-        return -1;
-#else
-    return open(name, O_RDONLY
-#ifdef O_NDELAY
-		| O_NDELAY
-#endif
-	/* O_RDONLY  | dev->mode*/);
-#endif
-}
-
-int scsi_cmd(int fd, unsigned char *cdb, int cmdlen, scsi_io_mode_t mode,
-	     void *data, size_t len, void *extra_data)
-{
-#if defined OS_hpux
-	struct sctl_io sctl_io;
-	
-	memset(&sctl_io, 0, sizeof sctl_io);   /* clear reserved fields */
-	memcpy(sctl_io.cdb, cdb, cmdlen);      /* copy command */
-	sctl_io.cdb_length = cmdlen;           /* command length */
-	sctl_io.max_msecs = 2000;              /* allow 2 seconds for cmd */
-
-	switch (mode) {
-		case SCSI_IO_READ:
-			sctl_io.flags = SCTL_READ;
-			sctl_io.data_length = len;
-			sctl_io.data = data;
-			break;
-		case SCSI_IO_WRITE: 
-			sctl_io.flags = 0;
-			sctl_io.data_length = data ? len : 0;
-			sctl_io.data = len ? data : 0;
-			break;
-	}
-
-	if (ioctl(fd, SIOC_IO, &sctl_io) == -1) {
-		perror("scsi_io");
-		return -1;
-	}
-
-	return sctl_io.cdb_status;
-	
-#elif defined OS_sunos || defined OS_solaris
-	struct uscsi_cmd uscsi_cmd;
-	memset(&uscsi_cmd, 0, sizeof uscsi_cmd);
-	uscsi_cmd.uscsi_cdb = (char *)cdb;
-	uscsi_cmd.uscsi_cdblen = cmdlen;
-#ifdef OS_solaris
-	uscsi_cmd.uscsi_timeout = 20;  /* msec? */
-#endif /* solaris */
-	
-	uscsi_cmd.uscsi_buflen = (u_int)len;
-	uscsi_cmd.uscsi_bufaddr = data;
-
-	switch (mode) {
-		case SCSI_IO_READ:
-			uscsi_cmd.uscsi_flags = USCSI_READ;
-			break;
-		case SCSI_IO_WRITE:
-			uscsi_cmd.uscsi_flags = USCSI_WRITE;
-			break;
-	}
-
-	if (ioctl(fd, USCSICMD, &uscsi_cmd) == -1) {
-		perror("scsi_io");
-		return -1;
-	}
-
-	if(uscsi_cmd.uscsi_status) {
-		errno = 0;
-		fprintf(stderr,"scsi status=%x\n",  
-			(unsigned short)uscsi_cmd.uscsi_status);
-		return -1;
-	}
-	
-	return 0;
-	
-#elif defined OS_linux
-	struct scsi_ioctl_command scsi_cmd;
-
-
-	memcpy(scsi_cmd.cmd, cdb, cmdlen);        /* copy command */
-
-	switch (mode) {
-		case SCSI_IO_READ:
-			scsi_cmd.inlen = 0;
-			scsi_cmd.outlen = len;
-			break;
-		case SCSI_IO_WRITE:
-			scsi_cmd.inlen = len;
-			scsi_cmd.outlen = 0;
-			memcpy(scsi_cmd.cmd + cmdlen,data,len);
-			break;
-	}
-	
-	if (ioctl(fd, SCSI_IOCTL_SEND_COMMAND, &scsi_cmd) < 0) {
-		perror("scsi_io");
-		return -1;
-	}
-	
-	switch (mode) {
-		case SCSI_IO_READ:
-			memcpy(data, &scsi_cmd.cmd[0], len);
-			break;
-		case SCSI_IO_WRITE:
-			break;
-    }
-
-	return 0;  /* where to get scsi status? */
-
-#elif defined _SCO_DS
-	struct scsicmd scsi_cmd;
-
-	memset(scsi_cmd.cdb, 0, SCSICMDLEN);	/* ensure zero pad */
-	memcpy(scsi_cmd.cdb, cdb, cmdlen);
-	scsi_cmd.cdb_len = cmdlen;
-	scsi_cmd.data_len = len;
-	scsi_cmd.data_ptr = data;
-	scsi_cmd.is_write = mode == SCSI_IO_WRITE;
-	if (ioctl(fd,SCSIUSERCMD,&scsi_cmd) == -1) {
-		perror("scsi_io");
-		printf("scsi status: host=%x; target=%x\n",
-		(unsigned)scsi_cmd.host_sts,(unsigned)scsi_cmd.target_sts);
-		return -1;
-	}
-	return 0;
-#elif defined sgi
- 	struct dsreq scsi_cmd;
-
-	scsi_cmd.ds_cmdbuf = (char *)cdb;
-	scsi_cmd.ds_cmdlen = cmdlen;
-	scsi_cmd.ds_databuf = data;
-	scsi_cmd.ds_datalen = len;
-       	switch (mode) {
-	case SCSI_IO_READ:
-	  scsi_cmd.ds_flags = DSRQ_READ|DSRQ_SENSE;
-	  break;
-	case SCSI_IO_WRITE:
-	  scsi_cmd.ds_flags = DSRQ_WRITE|DSRQ_SENSE;
-	  break;
-        } 
-	scsi_cmd.ds_time = 10000;
-	scsi_cmd.ds_link = 0;
-	scsi_cmd.ds_synch =0;
-	scsi_cmd.ds_ret =0;
-	if (ioctl(fd, DS_ENTER, &scsi_cmd) == -1) {
-                perror("scsi_io");
-                return -1;
-        }
-
-        if(scsi_cmd.ds_status) {
-                errno = 0;
-                fprintf(stderr,"scsi status=%x\n",  
-                        (unsigned short)scsi_cmd.ds_status);
-                return -1;
-        }
-        
-        return 0;
-#elif (defined OS_freebsd) && (__FreeBSD__ >= 2)
-#define MSG_SIMPLE_Q_TAG 0x20 /* O/O */
-      union ccb *ccb;
-      int flags;
-      int r;
-      struct cam_device *cam_dev = (struct cam_device *) extra_data;
-
-
-      if (cam_dev==NULL || cam_dev->fd!=fd)
-      {
-                fprintf(stderr,"invalid file descriptor\n");
-              return -1;
-      }
-      ccb = cam_getccb(cam_dev);
-
-      bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cmdlen);
-
-      if (mode == SCSI_IO_READ)
-              flags = CAM_DIR_IN;
-      else if (data && len)
-              flags = CAM_DIR_OUT;
-      else
-              flags = CAM_DIR_NONE;
-      cam_fill_csio(&ccb->csio,
-                    /* retry */ 1,
-                    /* cbfcnp */ NULL,
-                    flags,
-                    /* tag_action */ MSG_SIMPLE_Q_TAG,
-                    /*data_ptr*/ len ? data : 0,
-                    /*data_len */ data ? len : 0,
-                    96,
-                    cmdlen,
-                    5000);
-                    
-      if (cam_send_ccb(cam_dev, ccb) < 0 ||
-	  (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
-	  return -1;
-      }
-      return 0;
-#else
-      fprintf(stderr, "scsi_io not implemented\n");
-      return -1;
-#endif
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/scsi.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/scsi.h	(revision 9)
+++ 	(revision )
@@ -1,22 +1,0 @@
-#ifndef __mtools_scsi_h
-#define __mtools_scsi_h
-
-
-#define SCSI_READ 0x8
-#define SCSI_WRITE 0xA
-#define SCSI_IOMEGA 0xC
-#define SCSI_INQUIRY 0x12
-#define SCSI_MODE_SENSE 0x1a
-#define SCSI_START_STOP 0x1b
-#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1e
-#define SCSI_GROUP1 0x20
-#define SCSI_READ_CAPACITY 0x25
-
-
-typedef enum { SCSI_IO_READ, SCSI_IO_WRITE } scsi_io_mode_t;
-int scsi_max_length(void);
-int scsi_cmd(int fd, unsigned char cdb[6], int clen, scsi_io_mode_t mode,
-	     void *data, size_t len, void *extra_data);
-int scsi_open(const char *name, int flags, int mode, void **extra_data);
-
-#endif /* __mtools_scsi_h */
Index: trunk/minix/commands/i386/mtools-3.9.7/signal.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/signal.c	(revision 9)
+++ 	(revision )
@@ -1,35 +1,0 @@
-#include "sysincludes.h"
-#include "mtools.h"
-
-#undef got_signal
-
-int got_signal = 0;
-
-void signal_handler(int dummy)
-{
-	got_signal = 1;
-#if 0
-	signal(SIGHUP, SIG_IGN);
-	signal(SIGINT, SIG_IGN);
-	signal(SIGTERM, SIG_IGN);
-	signal(SIGQUIT, SIG_IGN);
-#endif
-}
-
-#if 0
-int do_gotsignal(char *f, int n)
-{
-	if(got_signal)
-		fprintf(stderr, "file=%s line=%d\n", f, n);
-	return got_signal;
-}
-#endif
-
-void setup_signal(void)
-{
-	/* catch signals */
-	signal(SIGHUP, (SIG_CAST)signal_handler);
-	signal(SIGINT, (SIG_CAST)signal_handler);
-	signal(SIGTERM, (SIG_CAST)signal_handler);
-	signal(SIGQUIT, (SIG_CAST)signal_handler);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/stream.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/stream.c	(revision 9)
+++ 	(revision )
@@ -1,65 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "stream.h"
-
-int batchmode = 0;
-
-int flush_stream(Stream_t *Stream)
-{
-	int ret=0;
-	if(!batchmode) {
-		if(Stream->Class->flush)
-			ret |= Stream->Class->flush(Stream);
-		if(Stream->Next)
-			ret |= flush_stream(Stream->Next);
-	}
-	return ret;
-}
-
-Stream_t *copy_stream(Stream_t *Stream)
-{
-	if(Stream)
-		Stream->refs++;
-	return Stream;
-}
-
-int free_stream(Stream_t **Stream)
-{
-	int ret=0;
-
-	if(!*Stream)
-		return -1;
-	if(! --(*Stream)->refs){
-		if((*Stream)->Class->flush)
-			ret |= (*Stream)->Class->flush(*Stream);
-		if((*Stream)->Class->freeFunc)
-			ret |= (*Stream)->Class->freeFunc(*Stream);
-		if((*Stream)->Next)
-			ret |= free_stream(&(*Stream)->Next);
-		Free(*Stream);
-	} else if ( (*Stream)->Next )
-		ret |= flush_stream((*Stream)->Next);		
-	*Stream = NULL;
-	return ret;
-}
-
-
-#define GET_DATA(stream, date, size, type, address) \
-(stream)->Class->get_data( (stream), (date), (size), (type), (address) )
-
-
-int get_data_pass_through(Stream_t *Stream, time_t *date, mt_size_t *size,
-			  int *type, int *address)
-{
-       return GET_DATA(Stream->Next, date, size, type, address);
-}
-
-int read_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
-{
-	return READS(Stream->Next, buf, start, len);
-}
-
-int write_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
-{
-	return WRITES(Stream->Next, buf, start, len);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/stream.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/stream.h	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-#ifndef MTOOLS_STREAM_H
-#define MTOOLS_STREAM_H
-
-typedef struct Stream_t {
-	struct Class_t *Class;
-	int refs;
-	struct Stream_t *Next;
-	struct Stream_t *Buffer;
-} Stream_t;
-
-#include "mtools.h"
-#include "msdos.h"
-
-#include "llong.h"
-
-typedef struct Class_t {
-	int (*read)(Stream_t *, char *, mt_off_t, size_t);
-	int (*write)(Stream_t *, char *, mt_off_t, size_t);
-	int (*flush)(Stream_t *);
-	int (*freeFunc)(Stream_t *);
-	int (*set_geom)(Stream_t *, device_t *, device_t *, int media,
-					struct bootsector *);
-	int (*get_data)(Stream_t *, time_t *, mt_size_t *, int *, int *);
-	int (*pre_allocate)(Stream_t *, mt_size_t);
-} Class_t;
-
-#define READS(stream, buf, address, size) \
-(stream)->Class->read( (stream), (char *) (buf), (address), (size) )
-
-#define WRITES(stream, buf, address, size) \
-(stream)->Class->write( (stream), (char *) (buf), (address), (size) )
-
-#define SET_GEOM(stream, dev, orig_dev, media, boot) \
-(stream)->Class->set_geom( (stream), (dev), (orig_dev), (media), (boot) )
-
-#define GET_DATA(stream, date, size, type, address) \
-(stream)->Class->get_data( (stream), (date), (size), (type), (address) )
-
-#define PRE_ALLOCATE(stream, size) \
-(stream)->Class->pre_allocate((stream), (size))
-
-int flush_stream(Stream_t *Stream);
-Stream_t *copy_stream(Stream_t *Stream);
-int free_stream(Stream_t **Stream);
-
-#define FLUSH(stream) \
-flush_stream( (stream) )
-
-#define FREE(stream) \
-free_stream( (stream) )
-
-#define COPY(stream) \
-copy_stream( (stream) )
-
-
-#define DeclareThis(x) x *This = (x *) Stream
-
-int force_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
-int force_read(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
-
-extern struct Stream_t *default_drive;
-
-int get_data_pass_through(Stream_t *Stream, time_t *date, mt_size_t *size,
-						  int *type, int *address);
-
-int read_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
-int write_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
-
-
-#endif
-
Index: trunk/minix/commands/i386/mtools-3.9.7/streamcache.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/streamcache.c	(revision 9)
+++ 	(revision )
@@ -1,77 +1,0 @@
-/*
- * streamcache.c
- * Managing a cache of open disks
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "fs.h"
-#include "mainloop.h"
-#include "plain_io.h"
-#include "file.h"
-
-static int is_initialized = 0;
-static Stream_t *fss[256]; /* open drives */
-
-static void finish_sc(void)
-{
-	int i;
-
-	for(i=0; i<256; i++){
-		if(fss[i] && fss[i]->refs != 1 )
-			fprintf(stderr,"Streamcache allocation problem:%c %d\n",
-				i, fss[i]->refs);
-		FREE(&(fss[i]));
-	}
-}
-
-static void init_streamcache(void)
-{
-	int i;
-
-	if(is_initialized)
-		return;
-	is_initialized = 1;
-	for(i=0; i<256; i++)
-		fss[i]=0;
-	atexit(finish_sc);
-}
-
-Stream_t *open_root_dir(char *drive, int flags)
-{
-	Stream_t *Fs;
-	int i, k;
-
-	init_streamcache();
-
-	k = -1;
-	for(i=0; i<256; i++) {
-		if (fss[i] == NULL || strcmp(getDrive(fss[i]), drive) == 0) {
-			k = i;
-			break;
-		}
-	}
-
-	if(k == -1) {
-		fprintf(stderr, "Cannot initialize '%s:', out of table space\n",
-			drive);
-		return NULL;
-	}
-
-	/* open the drive */
-	if(fss[k])
-		Fs = fss[k];
-	else {
-		Fs = fs_init(drive, flags);
-		if (!Fs){
-			fprintf(stderr, "Cannot initialize '%s:'\n", drive);
-			return NULL;
-		}
-
-		fss[k] = Fs;
-	}
-
-	return OpenRoot(Fs);
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/subdir.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/subdir.c	(revision 9)
+++ 	(revision )
@@ -1,26 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "file.h"
-#include "buffer.h"
-
-/*
- * Find the directory and load a new dir_chain[].  A null directory
- * is OK.  Returns a 1 on error.
- */
-
-
-void bufferize(Stream_t **Dir)
-{
-	Stream_t *BDir;
-
-	if(!*Dir)
-		return;
-	BDir = buf_init(*Dir, 64*16384, 512, MDIR_SIZE);
-	if(!BDir){
-		FREE(Dir);
-		*Dir = NULL;
-	} else
-		*Dir = BDir;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/sysincludes.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/sysincludes.h	(revision 9)
+++ 	(revision )
@@ -1,518 +1,0 @@
-/* System includes for mtools */
-
-#ifndef SYSINCLUDES_H
-#define SYSINCLUDES_H
-
-#include "config.h"
-
-/* OS/2 needs __inline__, but for some reason is not autodetected */
-#ifdef __EMX__
-# ifndef inline
-#  define inline __inline__
-# endif
-#endif
-
-/***********************************************************************/
-/*                                                                     */
-/* OS dependancies which cannot be covered by the autoconfigure script */
-/*                                                                     */
-/***********************************************************************/
-
-
-#ifdef OS_aux
-/* A/UX needs POSIX_SOURCE, just as AIX does. Unlike SCO and AIX, it seems
- * to prefer TERMIO over TERMIOS */
-#ifndef _POSIX_SOURCE
-# define _POSIX_SOURCE
-#endif
-#ifndef POSIX_SOURCE
-# define POSIX_SOURCE
-#endif
-
-#endif
-
-
-/* On AIX, we have to prefer strings.h, as string.h lacks a prototype 
- * for strcasecmp. On most other architectures, it's string.h which seems
- * to be more complete */
-#if (defined OS_aix && defined HAVE_STRINGS_H)
-# undef HAVE_STRING_H
-#endif
-
-
-#ifdef OS_ultrix
-/* on ultrix, if termios present, prefer it instead of termio */
-# ifdef HAVE_TERMIOS_H
-#  undef HAVE_TERMIO_H
-# endif
-#endif
-
-#ifdef OS_linux_gnu
-/* RMS strikes again */
-# ifndef OS_linux
-#  define OS_linux
-# endif
-#endif
-
-#ifdef OS_Minix
-/* typedef unsigned char *caddr_t; */
-#endif
-
-
-/***********************************************************************/
-/*                                                                     */
-/* Compiler dependancies                                               */
-/*                                                                     */
-/***********************************************************************/
-
-
-#if defined __GNUC__ && defined __STDC__
-/* gcc -traditional doesn't have PACKED, UNUSED and NORETURN */
-# define PACKED __attribute__ ((packed))
-# if __GNUC__ == 2 && __GNUC_MINOR__ > 6 || __GNUC__ >= 3
-/* gcc 2.6.3 doesn't have "unused" */		/* mool */
-#  define UNUSED(x) x __attribute__ ((unused));x
-# else
-#  define UNUSED(x) x
-# endif
-# define NORETURN __attribute__ ((noreturn))
-#else
-# define UNUSED(x) x
-# define PACKED /* */
-# define NORETURN /* */
-#endif
-
-
-/***********************************************************************/
-/*                                                                     */
-/* Include files                                                       */
-/*                                                                     */
-/***********************************************************************/
-
-
-#include <sys/types.h>
-
-#ifdef OS_Minix
-typedef unsigned long uoff_t;
-#define off_t uoff_t
-#endif
-
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
-
-#include <stdio.h>
-
-#ifndef OS_Minix
-# include <ctype.h>
-#else
-# ifdef __minix_vmd
-#  include <bsd/asciictype.h>	/* Minix-vmd: Ignore locales on purpose. */
-# else
-#  include <ctype.h>		/* Minix: What's that "locale" thing? */
-# endif
-#endif
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#ifdef HAVE_LINUX_UNISTD_H
-# include <linux/unistd.h>
-#endif
-
-#ifdef HAVE_LIBC_H
-# include <libc.h>
-#endif
-
-#ifdef HAVE_GETOPT_H
-# include <getopt.h>
-#else
-# ifndef OS_Minix
-int getopt();
-extern char *optarg;
-extern int optind, opterr;
-# endif
-#endif
-
-#ifdef HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
-
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
-
-#ifdef HAVE_SYS_FILE_H
-# include <sys/file.h>
-#endif
-
-#ifdef HAVE_SYS_IOCTL_H
-# ifndef sunos
-# include <sys/ioctl.h>
-#endif
-#endif
-/* if we don't have sys/ioctl.h, we rely on unistd to supply a prototype
- * for it. If it doesn't, we'll only get a (harmless) warning. The idea
- * is to get mtools compile on as many platforms as possible, but to not
- * suppress warnings if the platform is broken, as long as these warnings do
- * not prevent compilation */
-
-#ifdef TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# ifdef HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-#ifndef NO_TERMIO
-# ifdef HAVE_TERMIO_H
-#  include <termio.h>
-# elif defined HAVE_SYS_TERMIO_H
-#  include <sys/termio.h>
-# endif
-# if !defined OS_ultrix || !(defined HAVE_TERMIO_H || defined HAVE_TERMIO_H)
-/* on Ultrix, avoid double inclusion of both termio and termios */
-#  ifdef HAVE_TERMIOS_H
-#   include <termios.h>
-#  elif defined HAVE_SYS_TERMIOS_H
-#   include <sys/termios.h>
-#  endif
-# endif
-# ifdef HAVE_STTY_H
-#  include <sgtty.h>
-# endif
-#endif
-
-
-#if defined(OS_aux) && !defined(_SYSV_SOURCE)
-/* compiled in POSIX mode, this is left out unless SYSV */
-#define	NCC	8
-struct termio {
-	unsigned short	c_iflag;	/* input modes */
-	unsigned short	c_oflag;	/* output modes */
-	unsigned short	c_cflag;	/* control modes */
-	unsigned short	c_lflag;	/* line discipline modes */
-	char	c_line;			/* line discipline */
-	unsigned char	c_cc[NCC];	/* control chars */
-};
-extern int ioctl(int fildes, int request, void *arg);
-#endif
-
-
-#ifdef HAVE_MNTENT_H
-# include <mntent.h>
-#endif
-
-#ifdef HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif
-
-/* Can only be done here, as BSD is defined in sys/param.h :-( */
-#if defined BSD || defined __BEOS__
-/* on BSD and on BEOS, we prefer gettimeofday, ... */
-# ifdef HAVE_GETTIMEOFDAY
-#  undef HAVE_TZSET
-# endif
-#else /* BSD */
-/* ... elsewhere we prefer tzset */
-# ifdef HAVE_TZSET
-#  undef HAVE_GETTIMEOFDAY
-# endif
-#endif
-
-
-#include <sys/stat.h>
-
-#include <errno.h>
-extern int errno;
-
-#include <pwd.h>
-
-
-#ifdef HAVE_STRING_H
-# include <string.h>
-#else
-# ifdef HAVE_STRINGS_H
-#  include <strings.h>
-# endif
-#endif
-
-#ifdef HAVE_MEMORY_H
-# include <memory.h>
-#endif
-
-#ifdef HAVE_MALLOC_H
-# include <malloc.h>
-#endif
-
-#ifdef HAVE_SIGNAL_H
-# include <signal.h>
-#else
-# ifdef HAVE_SYS_SIGNAL_H
-#  include <sys/signal.h>
-# endif
-#endif
-
-#ifdef HAVE_UTIME_H
-# include <utime.h>
-#endif
-
-#ifdef HAVE_SYS_WAIT_H
-# ifndef DONT_NEED_WAIT
-#  include <sys/wait.h>
-# endif
-#endif
-
-
-#ifdef USE_FLOPPYD
-
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
-#ifdef HAVE_X11_XAUTH_H
-#include <X11/Xauth.h>
-#endif
-
-#ifdef HAVE_X11_XLIB_H
-#include <X11/Xlib.h>
-#endif
-
-#endif
-
-#ifndef INADDR_NONE
-#define INADDR_NONE (-1)
-#endif
-
-
-#ifdef sgi
-#define MSGIHACK __EXTENSIONS__
-#undef __EXTENSIONS__
-#endif
-#include <math.h>
-#ifdef sgi
-#define __EXTENSIONS__ MSGIHACK
-#undef MSGIHACK
-#endif
-
-/* missing functions */
-#ifndef HAVE_SRANDOM
-# define srandom srand48
-#endif
-
-#ifndef HAVE_RANDOM
-# define random (long)lrand48
-#endif
-
-#if __minix && !__minix_vmd
-# define srandom srand
-# define random rand
-#endif
-
-#ifndef HAVE_STRCHR
-# define strchr index
-#endif
-
-#ifndef HAVE_STRRCHR
-# define strrchr rindex
-#endif
-
-
-#define SIG_CAST RETSIGTYPE(*)()
-
-#ifndef HAVE_STRDUP
-extern char *strdup(const char *str);
-#endif /* HAVE_STRDUP */
-
-
-#ifndef HAVE_MEMCPY
-extern char *memcpy(char *s1, const char *s2, size_t n);
-#endif
-
-#ifndef HAVE_MEMSET
-extern char *memset(char *s, char c, size_t n);
-#endif /* HAVE_MEMSET */
-
-
-#ifndef HAVE_STRPBRK
-extern char *strpbrk(const char *string, const char *brkset);
-#endif /* HAVE_STRPBRK */
-
-
-#ifndef HAVE_STRTOUL
-unsigned long strtoul(const char *string, char **eptr, int base);
-#endif /* HAVE_STRTOUL */
-
-#ifndef HAVE_STRSPN
-size_t strspn(const char *s, const char *accept);
-#endif /* HAVE_STRSPN */
-
-#ifndef HAVE_STRCSPN
-size_t strcspn(const char *s, const char *reject);
-#endif /* HAVE_STRCSPN */
-
-#ifndef HAVE_STRERROR
-char *strerror(int errno);
-#endif
-
-#ifndef HAVE_ATEXIT
-int atexit(void (*function)(void)); 
-
-#ifndef HAVE_ON_EXIT
-void myexit(int code) NORETURN;
-#define exit myexit
-#endif
-
-#endif
-
-
-#ifndef HAVE_MEMMOVE
-# define memmove(DST, SRC, N) bcopy(SRC, DST, N)
-#endif
-
-#ifndef HAVE_STRCASECMP
-int strcasecmp(const char *s1, const char *s2);
-#endif
-
-#ifndef HAVE_STRNCASECMP
-int strncasecmp(const char *s1, const char *s2, size_t n);
-#endif
-
-#ifndef HAVE_GETPASS
-char *getpass(const char *prompt);
-#endif
-
-#if 0
-#ifndef HAVE_BASENAME
-const char *basename(const char *filename);
-#endif
-#endif
-
-const char *_basename(const char *filename);
-
-#ifndef __STDC__
-# ifndef signed
-#  define signed /**/
-# endif 
-#endif /* !__STDC__ */
-
-
-
-/***************************************************************************/
-/*                                                                         */
-/* Prototypes for systems where the functions exist but not the prototypes */
-/*                                                                         */
-/***************************************************************************/
-
-
-
-/* prototypes which might be missing on some platforms, even if the functions
- * are present.  Do not declare argument types, in order to avoid conflict
- * on platforms where the prototypes _are_ correct.  Indeed, for most of
- * these, there are _several_ "correct" parameter definitions, and not all
- * platforms use the same.  For instance, some use the const attribute for
- * strings not modified by the function, and others do not.  By using just
- * the return type, which rarely changes, we avoid these problems.
- */
-
-/* Correction:  Now it seems that even return values are not standardized :-(
-  For instance  DEC-ALPHA, OSF/1 3.2d uses ssize_t as a return type for read
-  and write.  NextStep uses a non-void return value for exit, etc.  With the
-  advent of 64 bit system, we'll expect more of these problems in the future.
-  Better uncomment the lot, except on SunOS, which is known to have bad
-  incomplete files.  Add other OS'es with incomplete include files as needed
-  */
-#if (defined OS_sunos || defined OS_ultrix)
-int read();
-int write();
-int fflush();
-char *strdup();
-int strcasecmp();
-int strncasecmp();
-char *getenv();
-unsigned long strtoul();
-int pclose();
-void exit();
-char *getpass();
-int atoi();
-FILE *fdopen();
-FILE *popen();
-#endif
-
-#ifndef MAXPATHLEN
-# ifdef PATH_MAX
-#  define MAXPATHLEN PATH_MAX
-# else
-#  define MAXPATHLEN 1024
-# endif
-#endif
-
-
-#ifndef OS_linux
-# undef USE_XDF
-#endif
-
-#ifdef NO_XDF
-# undef USE_XDF
-#endif
-
-#ifdef __EMX__
-#define INCL_BASE
-#define INCL_DOSDEVIOCTL
-#include <os2.h>
-#endif
-
-#ifdef OS_nextstep
-/* nextstep doesn't have this.  Unfortunately, we cannot test its presence
-   using AC_EGREP_HEADER, as we don't know _which_ header to test, and in
-   the general case utime.h might be non-existent */
-struct utimbuf
-{
-  time_t actime,modtime;
-};
-#endif
-
-/* NeXTStep doesn't have these */
-#if !defined(S_ISREG) && defined (_S_IFMT) && defined (_S_IFREG)
-#define S_ISREG(mode)   (((mode) & (_S_IFMT)) == (_S_IFREG))
-#endif
-
-#if !defined(S_ISDIR) && defined (_S_IFMT) && defined (_S_IFDIR)
-#define S_ISDIR(mode)   (((mode) & (_S_IFMT)) == (_S_IFDIR))
-#endif
-
-
-#if 0
-
-#define malloc(x) mymalloc(x)
-#define calloc(x,y) mycalloc(x,y)
-#define free(x) myfree(x)
-#define realloc(x,y) myrealloc(x,y)
-#define strdup(a) mystrdup(a)
-
-void *mycalloc(size_t nmemb, size_t size);
-void *mymalloc(size_t size);
-void myfree(void *ptr);
-void *myrealloc(void *ptr, size_t size);
-char *mystrdup(char *a);
-
-#endif
-
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/toupper.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/toupper.c	(revision 9)
+++ 	(revision )
@@ -1,491 +1,0 @@
-#include "codepage.h"
-
-/* MS-DOS doesn't use the same ASCII code as Unix does. The appearance
- * of the characters is defined using code pages. These code pages
- * aren't the same for all countries. For instance, some code pages
- * don't contain upper case accented characters. This affects two
- * things, relating to filenames:
-
- * 1. upper case characters. In short names, only upper case
- * characters are allowed.  This also holds for accented characters.
- * For instance, in a code page which doesn't contain accented
- * uppercase characters, the accented lowercase characters get
- * transformed into their unaccented counterparts. This is very bad
- * design. Indeed, stuff like national language support should never
- * affect filesystem integrity. And it does: A filename which is legal
- * in one country could be illegal in another one. Bad News for
- * frequent travellers.
-
- * 2. long file names: Micro$oft has finally come to their senses and
- * uses a more standard mapping for the long file names.  They use
- * Unicode, which is basically a 32 bit version of ASCII. Its first
- * 256 characters are identical to Unix ASCII. Thus, the code page
- * also affects the correspondence between the codes used in long
- * names and those used in short names.
-
- * Such a bad design is rather unbelievable. That's why I quoted the
- * translation tables. BEGIN FAIR USE EXCERPT:
- */
-
-unsigned char toucase[][128]={
-	/* 0 */
-	/* 437 German Umlauts upcased, French accents 
-	 * upcased and lose accent */
-	{ 0x80, 0x9a, 0x45, 0x41, 0x8e, 0x41, 0x8f, 0x80, 
-	  0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x8e, 0x8f, 
-	  0x90, 0x92, 0x92, 0x4f, 0x99, 0x4f, 0x55, 0x55, 
-	  0x59, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 
-	  0x41, 0x49, 0x4f, 0x55, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 
-	  0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 1 */
-	{ 0x43, 0x55, 0x45, 0x41, 0x41, 0x41, 0x86, 0x43, 
-	  0x45, 0x45, 0x45, 0x49, 0x49, 0x8d, 0x41, 0x8f, 
-	  0x45, 0x45, 0x45, 0x4f, 0x45, 0x49, 0x55, 0x55, 
-	  0x98, 0x4f, 0x55, 0x9b, 0x9c, 0x55, 0x55, 0x9f, 
-	  0xa0, 0xa1, 0x4f, 0x55, 0xa4, 0xa5, 0xa6, 0xa7, 
-	  0x49, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 
-	  0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 2 */
-	{ 0x80, 0x9a, 0x90, 0x41, 0x8e, 0x41, 0x8f, 0x80, 
-	  0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x8e, 0x8f, 
-	  0x90, 0x92, 0x92, 0x4f, 0x99, 0x4f, 0x55, 0x55, 
-	  0x59, 0x99, 0x9a, 0x9d, 0x9c, 0x9d, 0x9e, 0x9f, 
-	  0x41, 0x49, 0x4f, 0x55, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 
-	  0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 3 */
-	{ 0x80, 0x9a, 0x90, 0x41, 0x8e, 0x41, 0x8f, 0x80, 
-	  0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x8e, 0x8f, 
-	  0x90, 0x92, 0x92, 0x4f, 0x99, 0x4f, 0x55, 0x55, 
-	  0x59, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 
-	  0x41, 0x49, 0x4f, 0x55, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 
-	  0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 4 
-	 * 437: all accented characters lose their accent */
-	{ 0x80, 0x55, 0x45, 0x41, 0x41, 0x41, 0x8f, 0x80, 
-	  0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x41, 0x8f, 
-	  0x45, 0x92, 0x92, 0x4f, 0x4f, 0x4f, 0x55, 0x55, 
-	  0x98, 0x4f, 0x55, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 
-	  0x41, 0x49, 0x4f, 0x55, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 
-	  0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 5 */
-	{ 0x80, 0x9a, 0x90, 0x8f, 0x8e, 0x91, 0x86, 0x80, 
-	  0x89, 0x89, 0x92, 0x8b, 0x8c, 0x98, 0x8e, 0x8f, 
-	  0x90, 0x91, 0x92, 0x8c, 0x99, 0xa9, 0x96, 0x9d, 
-	  0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 
-	  0x86, 0x8b, 0x9f, 0x96, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 
-	  0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 6 All accented characters lose their accent
-	   when upcased. C loses cedilla. æ upcased. ø
-	   loses slash. Ð, ñ, ß intact */
-	{ 0x43, 0x55, 0x45, 0x41, 0x41, 0x41, 0x41, 0x43, 
-	  0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x41, 0x41, 
-	  0x45, 0x92, 0x92, 0x4f, 0x4f, 0x4f, 0x55, 0x55, 
-	  0x59, 0x4f, 0x55, 0x4f, 0x9c, 0x4f, 0x9e, 0x9f, 
-	  0x41, 0x49, 0x4f, 0x55, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0x41, 0x41, 0x41, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0x41, 0x41, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd1, 0xd1, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 
-	  0x49, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0x49, 0xdf, 
-	  0x4f, 0xe1, 0x4f, 0x4f, 0x4f, 0x4f, 0xe6, 0xe8, 
-	  0xe8, 0x55, 0x55, 0x55, 0x59, 0x59, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 7: As 6, but German Umlauts keep their Umlaut */
-	{ 0x43, 0x9a, 0x45, 0x41, 0x8e, 0x41, 0x41, 0x43, 
-	  0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x8e, 0x41, 
-	  0x45, 0x92, 0x92, 0x4f, 0x99, 0x4f, 0x55, 0x55, 
-	  0x59, 0x99, 0x9a, 0x4f, 0x9c, 0x4f, 0x9e, 0x9f, 
-	  0x41, 0x49, 0x4f, 0x55, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0x41, 0x41, 0x41, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0x41, 0x41, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd1, 0xd1, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 
-	  0x49, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0x49, 0xdf, 
-	  0x4f, 0xe1, 0x4f, 0x4f, 0x4f, 0x4f, 0xe6, 0xe8, 
-	  0xe8, 0x55, 0x55, 0x55, 0x59, 0x59, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 8: All characters except ÿ keep their accent
-	 */
-	{ 0x80, 0x9a, 0x90, 0xb6, 0x8e, 0xb7, 0x8f, 0x80, 
-	  0xd2, 0xd3, 0xd4, 0xd8, 0xd7, 0xde, 0x8e, 0x8f, 
-	  0x90, 0x92, 0x92, 0xe2, 0x99, 0xe3, 0xea, 0xeb, 
-	  0x59, 0x99, 0x9a, 0x9d, 0x9c, 0x9d, 0x9e, 0x9f, 
-	  0xb5, 0xd6, 0xe0, 0xe9, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc7, 0xc7, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd1, 0xd1, 0xd2, 0xd3, 0xd4, 0x49, 0xd6, 0xd7, 
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe5, 0xe5, 0xe6, 0xe8, 
-	  0xe8, 0xe9, 0xea, 0xeb, 0xed, 0xed, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 9: As 6, but Ç and Å preserved */
-	{ 0x80, 0x55, 0x45, 0x41, 0x41, 0x41, 0x8f, 0x80, 
-	  0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x41, 0x8f, 
-	  0x45, 0x92, 0x92, 0x4f, 0x4f, 0x4f, 0x55, 0x55, 
-	  0x98, 0x4f, 0x55, 0x4f, 0x9c, 0x4f, 0x9e, 0x9f, 
-	  0x41, 0x49, 0x4f, 0x55, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0x41, 0x41, 0x41, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0x41, 0x41, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd1, 0xd1, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 
-	  0x49, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0x49, 0xdf, 
-	  0x4f, 0xe1, 0x4f, 0x4f, 0x4f, 0x4f, 0xe6, 0xe8, 
-	  0xe8, 0x55, 0x55, 0x55, 0x59, 0x59, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 10: every accented character keeps its accent */
-	{ 0x80, 0x9a, 0x90, 0xb6, 0x8e, 0xb7, 0x8f, 0x80, 
-	  0xd2, 0xd3, 0xd4, 0xd8, 0xd7, 0xde, 0x8e, 0x8f, 
-	  0x90, 0x92, 0x92, 0xe2, 0x99, 0xe3, 0xea, 0xeb, 
-	  0x98, 0x99, 0x9a, 0x9d, 0x9c, 0x9d, 0x9e, 0x9f, 
-	  0xb5, 0xd6, 0xe0, 0xe9, 0xa5, 0xa5, 0xa6, 0xa7, 
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc7, 0xc7, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd1, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe5, 0xe5, 0xe6, 0xe8, 
-	  0xe8, 0xe9, 0xea, 0xeb, 0xed, 0xed, 0xee, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-	/* 11 */
-	{ 0x80, 0x9a, 0x90, 0xb6, 0x8e, 0xde, 0x8f, 0x80, 
-	  0x9d, 0xd3, 0x8a, 0x8a, 0xd7, 0x8d, 0x8e, 0x8f, 
-	  0x90, 0x91, 0x91, 0xe2, 0x99, 0x95, 0x95, 0x97, 
-	  0x97, 0x99, 0x9a, 0x9b, 0x9b, 0x9d, 0x9e, 0xac, 
-	  0xb5, 0xd6, 0xe0, 0xe9, 0xa4, 0xa4, 0xa6, 0xa6, 
-	  0xa8, 0xa8, 0xaa, 0x8d, 0xac, 0xb8, 0xae, 0xaf, 
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbd, 0xbf, 
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc6, 
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
-	  0xd1, 0xd1, 0xd2, 0xd3, 0xd2, 0xd5, 0xd6, 0xd7, 
-	  0xb7, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe3, 0xd5, 0xe6, 0xe6, 
-	  0xe8, 0xe9, 0xe8, 0xeb, 0xed, 0xed, 0xdd, 0xef, 
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
-	  0xf8, 0xf9, 0xfa, 0xeb, 0xfc, 0xfc, 0xfe, 0xff },
-
-
-	/* 14 All accented characters lose their accent, C loses cedilla,
-	 * ø loses slash.  æ upcased. Ð, ñ, ß intact */
-	{ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-	  0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
-
-	  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
-	  0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
-
-	  0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
-
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
-
-	  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0xc6, 0x43,
-	  0x45, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49,
-
-	  0xd0, 0xd1, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0xd7,
-	  0x4f, 0x55, 0x55, 0x55, 0x55, 0x59, 0xde, 0xdf,
-
-	  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0xc6, 0x43,
-	  0x45, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49,
-
-	  0xd0, 0xd1, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0xf7,
-	  0x4f, 0x55, 0x55, 0x55, 0x55, 0x59, 0xde, 0x59  },
-
-
-
-	/* 15 as 14, but German Umlauts (ä, ö, ü) keep their Umlaut when
-	   upcased */
-	{ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-	  0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
-
-	  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
-	  0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
-
-	  0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
-
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
-
-	  0x41, 0x41, 0x41, 0x41, 0xc4, 0x41, 0xc6, 0x43,
-	  0x45, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49,
-
-	  0xd0, 0xd1, 0x4f, 0x4f, 0x4f, 0x4f, 0xd6, 0xd7,
-	  0x4f, 0x55, 0x55, 0x55, 0xdc, 0x59, 0xde, 0xdf,
-
-	  0x41, 0x41, 0x41, 0x41, 0xc4, 0x41, 0xc6, 0x43,
-	  0x45, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49,
-
-	  0xd0, 0xd1, 0x4f, 0x4f, 0x4f, 0x4f, 0xd6, 0xf7,
-	  0x4f, 0x55, 0x55, 0x55, 0xdc, 0x59, 0xde, 0x59  },
-
-
-	/* 16 every accented character except ÿ keeps its accent */
-	{ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-	  0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
-
-	  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
-	  0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
-
-	  0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
-
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
-
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
-
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
-
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
-
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xf7,
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0x59 },
-
-
-
-	/* 17: As 6, but Ç, Å and ÿ preserved */
-	{ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-	  0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
-
-	  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
-	  0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
-
-	  0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
-
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
-
-	  0x41, 0x41, 0x41, 0x41, 0x41, 0xc5, 0xc6, 0xc7,
-	  0x45, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49,
-
-	  0xd0, 0xd1, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0xd7,
-	  0x4f, 0x55, 0x55, 0x55, 0x55, 0x59, 0xde, 0xdf,
-
-	  0x41, 0x41, 0x41, 0x41, 0x41, 0xc5, 0xc6, 0xc7,
-	  0x45, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49,
-
-	  0xd0, 0xd1, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0xf7,
-	  0x4f, 0x55, 0x55, 0x55, 0x55, 0x59, 0xde, 0xff  },
-
-
-	/* 18 every accented character keeps its accent */
-	{ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-	  0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
-
-	  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
-	  0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
-
-	  0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
-
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
-
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
-
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
-
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
-
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xf7,
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xff },
-
-
-	/* 19 */
-	{ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-	  0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
-	  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
-	  0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
-	  0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
-	  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
-	  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
-	  0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
-	  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
-	  0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
-	  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
-	  0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
-	  0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
-	  0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
-	  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
-	  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff },
-
-};
-
-country_t countries[]={
-	{   1, 437, 437,   0 },
-	{   1, 850, 437,   6 },
-	{   1, 819, 437,  14 },
-	{  44, 437, 437,   0 },
-	{  44, 850, 437,   6 },
-	{  44, 819, 437,  14 },
-	{  33, 437, 437,   0 },
-	{  33, 850, 437,   6 },
-	{  33, 819, 437,  14 },
-	{  49, 437, 437,   0 },
-	{  49, 850, 437,   7 },
-	{  49, 819, 437,  15 },
-	{  34, 850, 437,   8 },
-	{  34, 819, 437,  16 },
-	{  34, 437, 437,   0 },
-	{  39, 437, 437,   0 },
-	{  39, 850, 437,   6 },
-	{  39, 819, 437,  14 },
-	{  46, 437, 437,   3 },
-	{  46, 850, 437,   8 },
-	{  46, 819, 437,  16 },
-	{  45, 850, 865,   8 },
-	{  45, 819, 865,  16 },
-	{  45, 865, 865,   2 },
-	{  41, 850, 437,   8 },
-	{  41, 819, 437,  16 },
-	{  41, 437, 437,   3 },
-	{  47, 850, 865,   8 },
-	{  47, 819, 865,  16 },
-	{  47, 865, 865,   2 },
-	{  31, 437, 437,   4 },
-	{  31, 850, 437,   9 },
-	{  31, 819, 437,  17 },
-	{  32, 850, 437,   8 },
-	{  32, 819, 437,  16 },
-	{  32, 437, 437,   3 },
-	{ 358, 850, 437,   8 },
-	{ 358, 819, 437,  16 },
-	{ 358, 437, 437,   3 },
-	{   2, 863, 863,   1 },
-	{   2, 850, 863,   6 },
-	{   2, 819, 863,  14 },
-	{ 351, 850, 860,   6 },
-	{ 351, 819, 860,  14 },
-	{ 351, 860, 860,   5 },
-	{   3, 850, 437,   8 },
-	{   3, 819, 437,  16 },
-	{   3, 437, 437,   0 },
-	{  61, 437, 437,   0 },
-	{  61, 850, 437,   6 },
-	{  61, 819, 437,  16 },
-	{  81, 437, 437,   0 },
-	{  81, 819, 437,  14 },
-	{  82, 437, 437,   0 },
-	{  82, 819, 437,  14 },
-	{  86, 437, 437,   0 },
-	{  86, 819, 437,  14 },
-	{  88, 437, 437,   0 },
-	{  88, 819, 437,  14 },
-	{  55, 850, 850,  10 },
-	{  55, 819, 850,  18 },
-	{  55, 437, 850,   0 },
-	{ 354, 850, 850,  10 },
-	{ 354, 819, 850,  18 },
-	{  90, 850, 850,  10 },
-	{  90, 819, 850,  18 },
-	{  38, 852, 852,  11 },
-	{  38, 850, 852,  10 },
-	{  38, 819, 852,  18 },
-	{  42, 852, 852,  11 },
-	{  42, 850, 852,  10 },
-	{  42, 819, 852,  18 },
-	{  48, 852, 852,  11 },
-	{  48, 850, 852,  10 },
-	{  48, 819, 852,  18 },
-	{  36, 852, 852,  11 },
-	{  36, 850, 852,  10 },
-	{  36, 819, 852,  18 },
-	{ 886, 950, 950,  19 }, 	/* for Taiwan support (Country code) */
-	{   0,   0,   0,   0 }
-};
-
-/* END FAIR USE EXCERPT */
Index: trunk/minix/commands/i386/mtools-3.9.7/tty.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/tty.c	(revision 9)
+++ 	(revision )
@@ -1,201 +1,0 @@
-#include "sysincludes.h"
-#include "mtools.h"
-
-static FILE *tty=NULL;
-static int notty=0;	
-static int ttyfd=-1;
-#ifdef USE_RAWTERM
-int	mtools_raw_tty = 1;
-#else
-int	mtools_raw_tty = 0;
-#endif
-
-#ifdef USE_RAWTERM
-# if defined TCSANOW && defined HAVE_TCSETATTR
-/* we have tcsetattr & tcgetattr. Good */
-typedef struct termios Terminal;
-#  define stty(a,b)        (void)tcsetattr(a,TCSANOW,b)
-#  define gtty(a,b)        (void)tcgetattr(a,b)
-#  define USE_TCIFLUSH
-
-# elif defined TCSETS && defined TCGETS
-typedef struct termios Terminal;
-#  define stty(a,b) (void)ioctl(a,TCSETS,(char *)b)
-#  define gtty(a,b) (void)ioctl(a,TCGETS,(char *)b)
-#  define USE_TCIFLUSH
-
-# elif defined TCSETA && defined TCGETA
-typedef struct termio Terminal;
-#  define stty(a,b) (void)ioctl(a,TCSETA,(char *)b)
-#  define gtty(a,b) (void)ioctl(a,TCGETA,(char *)b)
-#  define USE_TCIFLUSH
-
-# elif defined(HAVE_SGTTY_H) && defined(TIOCSETP) && defined(TIOCGETP)
-typedef struct sgttyb Terminal;
-#  define stty(a,b) (void)ioctl(a,TIOCSETP,(char *)b)
-#  define gtty(a,b) (void)ioctl(a,TIOCGETP,(char *)b)
-#  define USE_SGTTY
-#  define discard_input(a) /**/
-
-# else
-/* no way to use raw terminal */
-/*
-#  warning Cannot use raw terminal code (disabled)
-*/
-#  undef USE_RAWTERM
-# endif
-
-#endif
-
-#ifdef USE_TCIFLUSH
-# if defined TCIFLUSH && defined HAVE_TCFLUSH
-#  define discard_input(a) tcflush(a,TCIFLUSH)
-# else
-#  define discard_input(a) /**/
-# endif
-#endif
-
-#ifdef USE_RAWTERM
-
-static int tty_mode = -1; /* 1 for raw, 0 for cooked, -1 for initial */
-static int need_tty_reset = 0;
-static int handlerIsSet = 0;
-
-#define restore_tty(a) stty(STDIN,a)
-
-
-#define STDIN ttyfd
-#define FAIL (-1)
-#define DONE 0
-static Terminal in_orig;
-
-/*--------------- Signal Handler routines -------------*/
-
-static void tty_time_out(void)
-{
-	int exit_code;
-	signal(SIGALRM, SIG_IGN);
-	if(tty && need_tty_reset)
-		restore_tty (&in_orig);	
-#if future
-	if (fail_on_timeout)
-		exit_code=SHFAIL;
-	else {
-		if (default_choice && mode_defined) {
-			if (yes_no) {
-				if ('Y' == default_choice)
-					exit_code=0;
-				else
-					exit_code=1;
-			} else
-				exit_code=default_choice-minc+1;
-		} else
-			exit_code=DONE;
-	}
-#else
-	exit_code = DONE;
-#endif
-	exit(exit_code);
-}
-
-static void cleanup_tty(void)
-{ 
-	if(tty && need_tty_reset) {
-		restore_tty (&in_orig);
-		setup_signal();
-	}
-}
-
-static void set_raw_tty(int mode)
-{
-	Terminal in_raw;
-
-	if(mode != tty_mode && mode != -1) {
-		if(!handlerIsSet) {
-			/* Determine existing TTY settings */
-			gtty (STDIN, &in_orig);
-			need_tty_reset = 1;
-
-			/* Restore original TTY settings on exit */
-			atexit(cleanup_tty);
-			handlerIsSet = 1;
-		}
-
-
-		setup_signal();
-		signal (SIGALRM, (SIG_CAST) tty_time_out);
-	
-		/* Change STDIN settings to raw */
-
-		gtty (STDIN, &in_raw);
-		if(mode) {
-#ifdef USE_SGTTY
-			in_raw.sg_flags |= CBREAK;
-#else
-			in_raw.c_lflag &= ~ICANON;
-			in_raw.c_cc[VMIN]=1;
-			in_raw.c_cc[VTIME]=0;			
-#endif
-			stty (STDIN, &in_raw);
-		} else {
-#ifdef USE_SGTTY
-			in_raw.sg_flags &= ~CBREAK;
-#else
-			in_raw.c_lflag |= ICANON;
-#endif
-			stty (STDIN, &in_raw);
-		}
-		tty_mode = mode;
-		discard_input(STDIN);
-	}
-}
-#endif
-
-FILE *opentty(int mode)
-{
-	if(notty)
-		return NULL;
-	if (tty == NULL) {
-		ttyfd = open("/dev/tty", O_RDONLY);
-		if(ttyfd >= 0) {
-			tty = fdopen(ttyfd, "r");
-		}
-	}
-	if  (tty == NULL){
-		if ( !isatty(0) ){
-			notty = 1;
-			return NULL;
-		}
-		ttyfd = 0;
-		tty = stdin;
-	}
-#ifdef USE_RAWTERM
-	if(mtools_raw_tty)
-		set_raw_tty(mode);
-#endif
-	return tty;
-}
-
-int ask_confirmation(const char *format, const char *p1, const char *p2)
-{
-	char ans[10];
-
-	if(!opentty(-1))
-		return 0;
-
-	while (1) {
-		fprintf(stderr, format, p1, p2);
-		fflush(stderr);
-		fflush(opentty(-1));
-		if (mtools_raw_tty) {
-			ans[0] = fgetc(opentty(1));
-			fputs("\n", stderr);
-		} else {
-			fgets(ans,9, opentty(0));
-		}
-		if (ans[0] == 'y' || ans[0] == 'Y')
-			return 0;
-		if (ans[0] == 'n' || ans[0] == 'N')
-			return -1;
-	}
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/unixdir.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/unixdir.c	(revision 9)
+++ 	(revision )
@@ -1,144 +1,0 @@
-#include "sysincludes.h"
-#include "msdos.h"
-#include "stream.h"
-#include "mtools.h"
-#include "fsP.h"
-#include "file.h"
-#include "htable.h"
-#include "mainloop.h"
-#include <dirent.h>
-
-typedef struct Dir_t {
-	Class_t *Class;
-	int refs;
-	Stream_t *Next;
-	Stream_t *Buffer;
-
-	struct stat stat;
-	char *pathname;
-	DIR *dir;
-#ifdef HAVE_FCHDIR
-	int fd;
-#endif
-} Dir_t;
-
-/*#define FCHDIR_MODE*/
-
-static int get_dir_data(Stream_t *Stream, time_t *date, mt_size_t *size,
-			int *type, int *address)
-{
-	DeclareThis(Dir_t);
-
-	if(date)
-		*date = This->stat.st_mtime;
-	if(size)
-		*size = (mt_size_t) This->stat.st_size;
-	if(type)
-		*type = 1;
-	if(address)
-		*address = 0;
-	return 0;
-}
-
-static int dir_free(Stream_t *Stream)
-{
-	DeclareThis(Dir_t);
-
-	Free(This->pathname);
-	closedir(This->dir);
-	return 0;
-}
-
-static Class_t DirClass = { 
-	0, /* read */
-	0, /* write */
-	0, /* flush */
-	dir_free, /* free */
-	0, /* get_geom */
-	get_dir_data ,
-	0 /* pre-allocate */
-};
-
-#ifdef HAVE_FCHDIR
-#define FCHDIR_MODE
-#endif
-
-int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); 
-int unix_loop(Stream_t *Stream, MainParam_t *mp, char *arg, 
-	      int follow_dir_link);
-
-int unix_dir_loop(Stream_t *Stream, MainParam_t *mp)
-{
-	DeclareThis(Dir_t);
-	struct dirent *entry;
-	char *newName;
-	int ret=0;
-
-#ifdef FCHDIR_MODE
-	int fd;
-
-	fd = open(".", O_RDONLY);
-	chdir(This->pathname);
-#endif
-	while((entry=readdir(This->dir)) != NULL) {
-		if(got_signal)
-			break;
-		if(isSpecial(entry->d_name))
-			continue;
-#ifndef FCHDIR_MODE
-		newName = malloc(strlen(This->pathname) + 1 + 
-				 strlen(entry->d_name) + 1);
-		if(!newName) {
-			ret = ERROR_ONE;
-			break;
-		}
-		strcpy(newName, This->pathname);
-		strcat(newName, "/");
-		strcat(newName, entry->d_name);
-#else
-		newName = entry->d_name;
-#endif
-		ret |= unix_loop(Stream, mp, newName, 0);
-#ifndef FCHDIR_MODE
-		free(newName);
-#endif
-	}
-#ifdef FCHDIR_MODE
-	fchdir(fd);
-	close(fd);
-#endif
-	return ret;
-}
-
-Stream_t *OpenDir(Stream_t *Stream, const char *filename)
-{
-	Dir_t *This;
-
-	This = New(Dir_t);
-	
-	This->Class = &DirClass;
-	This->Next = 0;
-	This->refs = 1;
-	This->Buffer = 0;
-	This->pathname = malloc(strlen(filename)+1);
-	if(This->pathname == NULL) {
-		Free(This);
-		return NULL;
-	}
-	strcpy(This->pathname, filename);
-
-	if(stat(filename, &This->stat) < 0) {
-		Free(This->pathname);
-		Free(This);
-		return NULL;
-	}
-
-	This->dir = opendir(filename);
-	if(!This->dir) {
-		Free(This->pathname);
-		Free(This);
-		return NULL;
-	}
-
-	return (Stream_t *) This;
-}
Index: trunk/minix/commands/i386/mtools-3.9.7/vfat.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/vfat.c	(revision 9)
+++ 	(revision )
@@ -1,748 +1,0 @@
-/* vfat.c
- *
- * Miscellaneous VFAT-related functions
- */
-
-#include "sysincludes.h"
-#include "msdos.h"
-#include "mtools.h"
-#include "vfat.h"
-#include "file.h"
-#include "dirCache.h"
-
-/* #define DEBUG */
-
-const char *short_illegals=";+=[]',\"*\\<>/?:|";
-const char *long_illegals = "\"*\\<>/?:|\005";
-
-/* Automatically derive a new name */
-static void autorename(char *name,
-		       char tilda, char dot, const char *illegals,
-		       int limit, int bump)
-{
-	int tildapos, dotpos;
-	unsigned int seqnum=0, maxseq=0;
-	char tmp;
-	char *p;
-	
-#ifdef DEBUG
-	printf("In autorename for name=%s.\n", name);
-#endif
-	tildapos = -1;
-
-	for(p=name; *p ; p++)
-		if((*p < ' ' && *p != '\005') || strchr(illegals, *p)) {
-			*p = '_';
-			bump = 0;
-		}
-
-	for(dotpos=0;
-	    name[dotpos] && dotpos < limit && name[dotpos] != dot ;
-	    dotpos++) {
-		if(name[dotpos] == tilda) {
-			tildapos = dotpos;
-			seqnum = 0;
-			maxseq = 1;
-		} else if (name[dotpos] >= '0' && name[dotpos] <= '9') {
-			seqnum = seqnum * 10 + name[dotpos] - '0';
-			maxseq = maxseq * 10;
-		} else
-			tildapos = -1; /* sequence number interrupted */
-	}
-	if(tildapos == -1) {
-		/* no sequence number yet */
-		if(dotpos > limit - 2) {
-			tildapos = limit - 2;
-			dotpos = limit;
-		} else {
-			tildapos = dotpos;
-			dotpos += 2;
-		}
-		seqnum = 1;
-	} else {
-		if(bump)
-			seqnum++;
-		if(seqnum > 999999) {
-			seqnum = 1;
-			tildapos = dotpos - 2;
-			/* this matches Win95's behavior, and also guarantees
-			 * us that the sequence numbers never get shorter */
-		}
-		if (seqnum == maxseq) {
-		    if(dotpos >= limit)
-			tildapos--;
-		    else
-			dotpos++;
-		}
-	}
-
-	tmp = name[dotpos];
-	if((bump && seqnum == 1) || seqnum > 1 || mtools_numeric_tail)
-		sprintf(name+tildapos,"%c%d",tilda, seqnum);
-	if(dot)
-	    name[dotpos]=tmp;
-	/* replace the character if it wasn't a space */
-}
-
-
-void autorename_short(char *name, int bump)
-{
-	autorename(name, '~', ' ', short_illegals, 8, bump);
-}
-
-void autorename_long(char *name, int bump)
-{
-	autorename(name, '-', '\0', long_illegals, 255, bump);
-}
-
-
-static inline int unicode_read(struct unicode_char *in, char *out, int num)
-{
-	char *end_out = out+num;
-
-	while(out < end_out) {
-		if (in->uchar)
-			*out = '_';
-		else
-			*out = in->lchar;
-		++out;
-		++in;
-	}
-	return num;
-}
-
-
-void clear_vfat(struct vfat_state *v)
-{
-	v->subentries = 0;
-	v->status = 0;
-	v->present = 0;
-}
-
-
-/* sum_shortname
- *
- * Calculate the checksum that results from the short name in *dir.
- *
- * The sum is formed by circularly right-shifting the previous sum
- * and adding in each character, from left to right, padding both
- * the name and extension to maximum length with spaces and skipping
- * the "." (hence always summing exactly 11 characters).
- * 
- * This exact algorithm is required in order to remain compatible
- * with Microsoft Windows-95 and Microsoft Windows NT 3.5.
- * Thanks to Jeffrey Richter of Microsoft Systems Journal for
- * pointing me to the correct algorithm.
- *
- * David C. Niemi (niemi@tux.org) 95.01.19
- */
-static inline unsigned char sum_shortname(char *name)
-{
-	unsigned char sum;
-	char *end = name+11;
-
-	for (sum=0; name<end; ++name)
-		sum = ((sum & 1) ? 0x80 : 0) + (sum >> 1) 
-		  + (*name ? *name : ' ');
-	return(sum);
-}
-
-/* check_vfat
- *
- * Inspect a directory and any associated VSEs.
- * Return 1 if the VSEs comprise a valid long file name,
- * 0 if not.
- */
-static inline void check_vfat(struct vfat_state *v, struct directory *dir)
-{
-	char name[12];
-
-	if (! v->subentries) {
-#ifdef DEBUG
-		fprintf(stderr, "check_vfat: no VSEs.\n");
-#endif
-		return;
-	}
-
-	strncpy((char *)name, (char *)dir->name, 8);
-	strncpy((char *)name + 8, (char *)dir->ext, 3);
-	name[11] = '\0';
-
-	if (v->sum != sum_shortname(name))
-		return;
-	
-	if( (v->status & ((1<<v->subentries) - 1)) != (1<<v->subentries) - 1)
-		return; /* missing entries */
-
-	/* zero out byte following last entry, for good measure */
-	v->name[VSE_NAMELEN * v->subentries] = 0;
-	v->present = 1;
-}
-
-
-int clear_vses(Stream_t *Dir, int entrySlot, size_t last)
-{
-	direntry_t entry;
-	dirCache_t *cache;
-	int error;
-
-	entry.Dir = Dir;
-	entry.entry = entrySlot;
-
-	/*maximize(last, entry.entry + MAX_VFAT_SUBENTRIES);*/
-	cache = allocDirCache(Dir, last);
-	if(!cache) {
-		fprintf(stderr, "Out of memory error in clear_vses\n");
-		exit(1);
-	}
-	addFreeEntry(cache, entry.entry, last);
-	for (; entry.entry < last; ++entry.entry) {
-#ifdef DEBUG
-		fprintf(stderr,"Clearing entry %d.\n", entry.entry);
-#endif
-		dir_read(&entry, &error);
-		if(error)
-		    return error;
-		if(!entry.dir.name[0] || entry.dir.name[0] == DELMARK)
-			break;
-		entry.dir.name[0] = DELMARK;
-		if (entry.dir.attr == 0xf)
-			entry.dir.attr = '\0';
-		low_level_dir_write(&entry);
-	}
-	return 0;
-}
-
-int write_vfat(Stream_t *Dir, char *shortname, char *longname, int start,
-	       direntry_t *mainEntry)
-{
-	struct vfat_subentry *vse;
-	int vse_id, num_vses;
-	char *c;
-	direntry_t entry;
-	dirCache_t *cache;
-	char unixyName[13];
-	
-	if(longname) {
-#ifdef DEBUG
-		printf("Entering write_vfat with longname=\"%s\", start=%d.\n",
-		       longname,start);
-#endif
-		entry.Dir = Dir;
-		vse = (struct vfat_subentry *) &entry.dir;
-		/* Fill in invariant part of vse */
-		vse->attribute = 0x0f;
-		vse->hash1 = vse->sector_l = vse->sector_u = 0;
-		vse->sum = sum_shortname(shortname);
-#ifdef DEBUG
-		printf("Wrote checksum=%d for shortname %s.\n", 
-		       vse->sum,shortname);
-#endif
-		num_vses = strlen(longname)/VSE_NAMELEN + 1;
-		for (vse_id = num_vses; vse_id; --vse_id) {
-			int end = 0;
-			
-			c = longname + (vse_id - 1) * VSE_NAMELEN;
-			
-			c += unicode_write(c, vse->text1, VSE1SIZE, &end);
-			c += unicode_write(c, vse->text2, VSE2SIZE, &end);
-			c += unicode_write(c, vse->text3, VSE3SIZE, &end);
-
-			vse->id = (vse_id == num_vses) ? (vse_id | VSE_LAST) : vse_id;
-#ifdef DEBUG
-			printf("Writing longname=(%s), VSE %d (%13s) at %d, end = %d.\n",
-			       longname, vse_id, longname + (vse_id-1) * VSE_NAMELEN,
-			       start + num_vses - vse_id, start + num_vses);
-#endif
-			
-			entry.entry = start + num_vses - vse_id;
-			low_level_dir_write(&entry);
-		}
-	} else
-		num_vses = 0;
-	cache = allocDirCache(Dir, start + num_vses + 1);
-	if(!cache) {
-		fprintf(stderr, "Out of memory error\n");
-		exit(1);
-	}
-	unix_name(shortname, shortname+8, 0, unixyName);
-	addUsedEntry(cache, start, start + num_vses + 1, longname, unixyName,
-		     &mainEntry->dir);
-	low_level_dir_write(mainEntry);
-	return start + num_vses;
-}
-
-void dir_write(direntry_t *entry)
-{
-	dirCacheEntry_t *dce;
-	dirCache_t *cache;
-
-	if(entry->entry == -3) {
-		fprintf(stderr, "Attempt to write root directory pointer\n");
-		exit(1);
-	}
-
-	cache = allocDirCache(entry->Dir, entry->entry + 1);
-	if(!cache) {
-		fprintf(stderr, "Out of memory error in dir_write\n");
-		exit(1);
-	}
-	dce = cache->entries[entry->entry];
-	if(dce) {
-		if(entry->dir.name[0] == DELMARK) {
-			addFreeEntry(cache, dce->beginSlot, dce->endSlot);
-		} else {
-			dce->dir = entry->dir;
-		}
-	}
-	low_level_dir_write(entry);
-}
-
-
-/* 
- * The following function translates a series of vfat_subentries into
- * data suitable for a dircache entry
- */
-static inline void parse_vses(direntry_t *entry,			      
-			      struct vfat_state *v)
-{
-	struct vfat_subentry *vse;
-	unsigned char id, last_flag;
-	char *c;
-	
-	vse = (struct vfat_subentry *) &entry->dir;
-	
-	id = vse->id & VSE_MASK;
-	last_flag = (vse->id & VSE_LAST);
-	if (id > MAX_VFAT_SUBENTRIES) {
-		fprintf(stderr, "parse_vses: invalid VSE ID %d at %d.\n",
-			id, entry->entry);
-		return;
-	}
-	
-/* 950819: This code enforced finding the VSEs in order.  Well, Win95
- * likes to write them in *reverse* order for some bizarre reason!  So
- * we pretty much have to tolerate them coming in any possible order.
- * So skip this check, we'll do without it (What does this do, Alain?).
- *
- * 950820: Totally rearranged code to tolerate any order but to warn if
- * they are not in reverse order like Win95 uses.
- *
- * 950909: Tolerate any order. We recognize new chains by mismatching
- * checksums. In the event that the checksums match, new entries silently
- * overwrite old entries of the same id. This should accept all valid
- * entries, but may fail to reject invalid entries in some rare cases.
- */
-
-	/* bad checksum, begin new chain */
-	if(v->sum != vse->sum) {
-		clear_vfat(v);
-		v->sum = vse->sum;
-	}
-	
-#ifdef DEBUG
-	if(v->status & (1 << (id-1)))
-		fprintf(stderr,
-			"parse_vses: duplicate VSE %d\n", vse->id);
-#endif
-	
-	v->status |= 1 << (id-1);
-	if(last_flag)
-		v->subentries = id;
-	
-#ifdef DEBUG
-	if (id > v->subentries)
-		/* simple test to detect entries preceding
-		 * the "last" entry (really the first) */
-		fprintf(stderr,
-			"parse_vses: new VSE %d sans LAST flag\n",
-			vse->id);
-#endif
-
-	c = &(v->name[VSE_NAMELEN * (id-1)]);
-	c += unicode_read(vse->text1, c, VSE1SIZE);
-	c += unicode_read(vse->text2, c, VSE2SIZE);
-	c += unicode_read(vse->text3, c, VSE3SIZE);
-#ifdef DEBUG
-	printf("Read VSE %d at %d, subentries=%d, = (%13s).\n",
-	       id,entry->entry,v->subentries,&(v->name[VSE_NAMELEN * (id-1)]));
-#endif		
-	if (last_flag)
-		*c = '\0';	/* Null terminate long name */
-}
-
-
-static dirCacheEntry_t *vfat_lookup_loop_common(direntry_t *direntry,
-						dirCache_t *cache,
-						int lookForFreeSpace,
-						int *io_error)
-{
-	char newfile[13];
-	int initpos = direntry->entry + 1;
-	struct vfat_state vfat;
-	char *longname;
-	int error;
-
-	/* not yet cached */
-	*io_error = 0;
-	clear_vfat(&vfat);
-	while(1) {
-		++direntry->entry;
-		if(!dir_read(direntry, &error)){
-			if(error) {
-			    *io_error = error;
-			    return NULL;
-			}
-			addFreeEntry(cache, initpos, direntry->entry);
-			return addEndEntry(cache, direntry->entry);
-		}
-		
-		if (direntry->dir.name[0] == '\0'){
-				/* the end of the directory */
-			if(lookForFreeSpace)
-				continue;
-			return addEndEntry(cache, direntry->entry);
-		}
-		if(direntry->dir.name[0] != DELMARK &&
-		   direntry->dir.attr == 0x0f)
-			parse_vses(direntry, &vfat);
-		else
-			/* the main entry */
-			break;
-	}
-	
-	/* If we get here, it's a short name FAT entry, maybe erased.
-	 * thus we should make sure that the vfat structure will be
-	 * cleared before the next loop run */
-	
-	/* deleted file */
-	if (direntry->dir.name[0] == DELMARK) {
-		return addFreeEntry(cache, initpos, 
-				    direntry->entry + 1);
-	}
-	
-	check_vfat(&vfat, &direntry->dir);
-	if(!vfat.present)
-		vfat.subentries = 0;
-	
-	/* mark space between last entry and this one as free */
-	addFreeEntry(cache, initpos, 
-		     direntry->entry - vfat.subentries);
-	
-	if (direntry->dir.attr & 0x8){
-		strncpy(newfile, direntry->dir.name,8);
-		newfile[8]='\0';
-		strncat(newfile, direntry->dir.ext,3);
-		newfile[11]='\0';
-	} else
-		unix_name(direntry->dir.name, 
-			  direntry->dir.ext, 
-			  direntry->dir.Case, 
-			  newfile);
-
-	if(vfat.present)
-		longname = vfat.name;
-	else
-		longname = 0;
-
-	return addUsedEntry(cache, direntry->entry - vfat.subentries,
-			    direntry->entry + 1, longname, 
-			    newfile, &direntry->dir);
-}
-
-static inline dirCacheEntry_t *vfat_lookup_loop_for_read(direntry_t *direntry,
-							 dirCache_t *cache,
-							 int *io_error)
-{
-	int initpos = direntry->entry + 1;
-	dirCacheEntry_t *dce;
-
-	*io_error = 0;
-	dce = cache->entries[initpos];
-	if(dce) {
-		direntry->entry = dce->endSlot - 1;
-		return dce;
-	} else {
-		return vfat_lookup_loop_common(direntry, cache, 0, io_error);
-	}
-}
-
-
-typedef enum result_t {
-	RES_NOMATCH,
-	RES_MATCH,
-	RES_END,
-	RES_ERROR
-} result_t;
-
-
-/* 
- * 0 does not match
- * 1 matches
- * 2 end
- */
-static result_t checkNameForMatch(struct direntry_t *direntry, 
-				  dirCacheEntry_t *dce,
-				  const char *filename,
-				  char *longname,
-				  char *shortname,
-				  int length,
-				  int flags)
-{
-	switch(dce->type) {
-		case DCET_FREE:
-			return RES_NOMATCH;
-		case DCET_END:
-			return RES_END;
-		case DCET_USED:
-			break;
-		default:
-			fprintf(stderr, "Unexpected entry type %d\n",
-				dce->type);
-			return RES_ERROR;
-	}
-
-	direntry->dir = dce->dir;
-
-	/* make sure the entry is of an accepted type */
-	if((direntry->dir.attr & 0x8) && !(flags & ACCEPT_LABEL))
-		return RES_NOMATCH;
-
-
-	/*---------- multiple files ----------*/
-	if(!((flags & MATCH_ANY) ||
-	     (dce->longName && 
-	      match(dce->longName, filename, direntry->name, 0, length)) ||
-	     match(dce->shortName, filename, direntry->name, 1, length))) {
-
-		return RES_NOMATCH;
-	}
-
-	/* entry of non-requested type, has to come after name
-	 * checking because of clash handling */
-	if(IS_DIR(direntry) && !(flags & ACCEPT_DIR)) {
-		if(!(flags & (ACCEPT_LABEL|MATCH_ANY|NO_MSG)))
-			fprintf(stderr,
-				"Skipping \"%s\", is a directory\n",
-				dce->shortName);
-		return RES_NOMATCH;
-	}
-
-	if(!(direntry->dir.attr & (ATTR_LABEL | ATTR_DIR)) && 
-	   !(flags & ACCEPT_PLAIN)) {
-		if(!(flags & (ACCEPT_LABEL|MATCH_ANY|NO_MSG)))
-			fprintf(stderr,
-				"Skipping \"%s\", is not a directory\n",
-				dce->shortName);
-		return RES_NOMATCH;
-	}
-
-	return RES_MATCH;
-}
-
-
-/*
- * vfat_lookup looks for filenames in directory dir.
- * if a name if found, it is returned in outname
- * if applicable, the file is opened and its stream is returned in File
- */
-
-int vfat_lookup(direntry_t *direntry, const char *filename, int length,
-		int flags, char *shortname, char *longname)
-{
-	dirCacheEntry_t *dce;
-	result_t result;
-	dirCache_t *cache;
-	int io_error;
-
-	if(length == -1 && filename)
-		length = strlen(filename);
-
-	if (direntry->entry == -2)
-		return -1;
-
-	cache = allocDirCache(direntry->Dir, direntry->entry+1);
-	if(!cache) {
-		fprintf(stderr, "Out of memory error in vfat_lookup [0]\n");
-		exit(1);
-	}
-
-	do {
-		dce = vfat_lookup_loop_for_read(direntry, cache, &io_error);
-		if(!dce) {
-			if (io_error)
-				return -2;
-			fprintf(stderr, "Out of memory error in vfat_lookup\n");
-			exit(1);
-		}
-		result = checkNameForMatch(direntry, dce,
-					   filename, 
-					   longname, shortname,
-					   length, flags);
-	} while(result == RES_NOMATCH);
-
-	if(result == RES_MATCH){
-		if(longname){
-			if(dce->longName)
-				strcpy(longname, dce->longName);
-			else
-				*longname ='\0';
-		}
-		if(shortname)
-			strcpy(shortname, dce->shortName);
-		direntry->beginSlot = dce->beginSlot;
-		direntry->endSlot = dce->endSlot-1;
-		return 0; /* file found */
-	} else {
-		direntry->entry = -2;
-		return -1; /* no file found */
-	}
-}
-
-static inline dirCacheEntry_t *vfat_lookup_loop_for_insert(direntry_t *direntry,
-							   int initpos,
-							   dirCache_t *cache)
-{
-	dirCacheEntry_t *dce;
-	int io_error;
-
-	dce = cache->entries[initpos];
-	if(dce && dce->type != DCET_END) {
-		return dce;
-	} else {
-		direntry->entry = initpos - 1;
-		dce = vfat_lookup_loop_common(direntry, cache, 1, &io_error);
-		if(!dce) {
-			if (io_error) {
-				return NULL;
-			}
-			fprintf(stderr, 
-				"Out of memory error in vfat_lookup_loop\n");
-			exit(1);
-		}
-		return cache->entries[initpos];
-	}
-}
-
-static void accountFreeSlots(struct scan_state *ssp, dirCacheEntry_t *dce)
-{
-	if(ssp->got_slots)
-		return;
-
-	if(ssp->free_end != dce->beginSlot) {
-		ssp->free_start = dce->beginSlot;
-	}
-	ssp->free_end = dce->endSlot;
-
-	if(ssp->free_end - ssp->free_start >= ssp->size_needed) {
-		ssp->got_slots = 1;
-		ssp->slot = ssp->free_start + ssp->size_needed - 1;
-	}
-}
-
-/* lookup_for_insert replaces the old scandir function.  It directly
- * calls into vfat_lookup_loop, thus eliminating the overhead of the
- * normal vfat_lookup
- */
-int lookupForInsert(Stream_t *Dir,
-					char *dosname,
-					char *longname,
-					struct scan_state *ssp, 
-					int ignore_entry,
-					int source_entry,
-					int pessimisticShortRename)
-{
-	direntry_t entry;
-	int ignore_match;
-	dirCacheEntry_t *dce;
-	dirCache_t *cache;
-	int pos; /* position _before_ the next answered entry */
-	char shortName[13];
-
-	ignore_match = (ignore_entry == -2 );
-
-	initializeDirentry(&entry, Dir);
-	ssp->match_free = 0;
-
-	/* hash bitmap of already encountered names.  Speeds up batch appends
-	 * to huge directories, because in the best case, we only need to scan
-	 * the new entries rather than the whole directory */
-	cache = allocDirCache(Dir, 1);
-	if(!cache) {
-		fprintf(stderr, "Out of memory error in lookupForInsert\n");
-		exit(1);
-	}
-
-	if(!ignore_match)
-		unix_name(dosname, dosname + 8, 0, shortName);
-
-	pos = cache->nrHashed;
-	if(source_entry >= 0 ||
-	   (pos && isHashed(cache, longname))) {
-		pos = 0;
-	} else if(pos && !ignore_match && isHashed(cache, shortName)) {
-		if(pessimisticShortRename) {
-			ssp->shortmatch = -2;
-			return 1;
-		}
-		pos = 0;
-	} else if(growDirCache(cache, pos) < 0) {
-		fprintf(stderr, "Out of memory error in vfat_looup [0]\n");
-		exit(1);
-	}
-	do {
-		dce = vfat_lookup_loop_for_insert(&entry, pos, cache);
-		switch(dce->type) {
-			case DCET_FREE:
-				accountFreeSlots(ssp, dce);
-				break;
-			case DCET_USED:
-				if(!(dce->dir.attr & 0x8) &&
-				   dce->endSlot - 1 == source_entry)
-				   accountFreeSlots(ssp, dce);
-
-				/* labels never match, neither does the 
-				 * ignored entry */
-				if( (dce->dir.attr & 0x8) ||
-				    (dce->endSlot - 1 == ignore_entry) )
-					break;
-
-				/* check long name */
-				if((dce->longName && 
-				    !strcasecmp(dce->longName, longname)) ||
-				   (dce->shortName &&
-				    !strcasecmp(dce->shortName, longname))) {
-					ssp->longmatch = dce->endSlot - 1;
-					/* long match is a reason for
-					 * immediate stop */
-					return 1;
-				}
-
-				/* Long name or not, always check for 
-				 * short name match */
-				if (!ignore_match &&
-				    !strcasecmp(shortName, dce->shortName))
-					ssp->shortmatch = dce->endSlot - 1;
-				break;
-			case DCET_END:
-				break;
-		}
-		pos = dce->endSlot;
-	} while(dce->type != DCET_END);
-	if (ssp->shortmatch > -1)
-		return 1;
-	ssp->max_entry = dce->beginSlot;
-	if (ssp->got_slots)
-		return 6;	/* Success */
-
-	/* Need more room.  Can we grow the directory? */
-	if(!isRootDir(Dir))		
-		return 5;	/* OK, try to grow the directory */
-
-	fprintf(stderr, "No directory slots\n");
-	return -1;
-}
-
-
-
-/* End vfat.c */
Index: trunk/minix/commands/i386/mtools-3.9.7/vfat.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/vfat.h	(revision 9)
+++ 	(revision )
@@ -1,100 +1,0 @@
-#ifndef MTOOLS_VFAT_H
-#define MTOOLS_VFAT_H
-
-#include "msdos.h"
-
-/*
- * VFAT-related common header file
- */
-#define VFAT_SUPPORT
-
-struct unicode_char {
-	char lchar;
-	char uchar;
-};
-
-
-/* #define MAX_VFAT_SUBENTRIES 32 */ /* Theoretical max # of VSEs */
-#define MAX_VFAT_SUBENTRIES 20		/* Max useful # of VSEs */
-#define VSE_NAMELEN 13
-
-#define VSE1SIZE 5
-#define VSE2SIZE 6
-#define VSE3SIZE 2
-
-#include "stream.h"
-
-struct vfat_subentry {
-	unsigned char id;		/* 0x40 = last; & 0x1f = VSE ID */
-	struct unicode_char text1[VSE1SIZE] PACKED;
-	unsigned char attribute;	/* 0x0f for VFAT */
-	unsigned char hash1;		/* Always 0? */
-	unsigned char sum;		/* Checksum of short name */
-	struct unicode_char text2[VSE2SIZE] PACKED;
-	unsigned char sector_l;		/* 0 for VFAT */
-	unsigned char sector_u;		/* 0 for VFAT */
-	struct unicode_char text3[VSE3SIZE] PACKED;
-};
-
-/* Enough size for a worst case number of full VSEs plus a null */
-#define VBUFSIZE ((MAX_VFAT_SUBENTRIES*VSE_NAMELEN) + 1)
-
-/* Max legal length of a VFAT long name */
-#define MAX_VNAMELEN (255)
-
-#define VSE_PRESENT 0x01
-#define VSE_LAST 0x40
-#define VSE_MASK 0x1f
-
-struct vfat_state {
-	char name[VBUFSIZE];
-	int status; /* is now a bit map of 32 bits */
-	int subentries;
-	unsigned char sum; /* no need to remember the sum for each entry,
-			    * it is the same anyways */
-	int present;
-};
-
-
-struct scan_state {
-	int match_free;
-	int shortmatch;
-	int longmatch;
-	int free_start;
-	int free_end;
-	int slot;
-	int got_slots;
-	int size_needed;
-	int max_entry;
-};
-
-#include "mtoolsDirent.h"
-
-void clear_vfat(struct vfat_state  *);
-int unicode_write(char *, struct unicode_char *, int num, int *end);
-
-int clear_vses(Stream_t *, int, size_t);
-void autorename_short(char *, int);
-void autorename_long(char *, int);
-
-int lookupForInsert(Stream_t *Dir,
-					char *dosname,
-					char *longname,
-					struct scan_state *ssp, 
-					int ignore_entry,
-					int source_entry,
-					int pessimisticShortRename);
-
-#define DO_OPEN 1 /* open all files that are found */
-#define ACCEPT_LABEL 0x08
-#define ACCEPT_DIR 0x10
-#define ACCEPT_PLAIN 0x20
-#define MATCH_ANY 0x40
-#define NO_MSG 0x80
-#define NO_DOTS 0x100 /* accept no dots if matched by wildcard */
-#define DO_OPEN_DIRS 0x400 /* open all directories that are found */
-#define OPEN_PARENT 0x1000  /* in target lookup, open parent
-			     * instead of file itself */
-#define NO_UNIX 0x2000 /* in target lookup, consider all files to reside on
-			* the DOS fs */
-#endif
Index: trunk/minix/commands/i386/mtools-3.9.7/xdf_io.c
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/xdf_io.c	(revision 9)
+++ 	(revision )
@@ -1,696 +1,0 @@
-/*
- * Io to an xdf disk
- *
- * written by:
- *
- * Alain L. Knaff
- * alain@linux.lu
- *
- */
-
-
-#include "sysincludes.h"
-#ifdef OS_linux
-#include "msdos.h"
-#include "mtools.h"
-#include "devices.h"
-#include "xdf_io.h"
-
-extern int errno;
-
-/* Algorithms can't be patented */
-
-typedef struct sector_map {
-	unsigned int head:1;
-	unsigned int size:7;
-} sector_map_t;
-
-
-struct {
-  unsigned char track_size;
-  unsigned int track0_size:7;
-  unsigned int rootskip:1;
-  unsigned char rate;
-  sector_map_t map[9];
-} xdf_table[]= {
-  {
-    19, 16, 0, 0,
-    {	{0,3},	{0,6},	{1,2},	{0,2},	{1,6},	{1,3},	{0,0} }
-  },
-  {
-    23, 19, 0, 0,
-    {	{0,3},	{0,4},	{1,6},	{0,2},	{1,2},	{0,6},	{1,4},	{1,3},	{0,0} }
-  },
-  {
-    46, 37, 0x43, 1,
-    {	{0,3},	{0,4},	{0,5},	{0,7},	{1,3},	{1,4},	{1,5},	{1,7},	{0,0} }
-  },
-  {
-    24, 20, 0, 1,
-    {	{0,5},	{1,6},	{0,6},	{1, 5} }
-  },
-  {
-    48, 41, 0, 1,
-    {	{0,6},	{1,7},	{0,7},	{1, 6} }
-  }
-};
-
-#define NUMBER(x) (sizeof(x)/sizeof(x[0]))
-
-typedef struct {
-	unsigned char begin; /* where it begins */
-	unsigned char end;       
-	unsigned char sector;
-	unsigned char sizecode;
-
-	unsigned int dirty:1;
-	unsigned int phantom:2;
-	unsigned int valid:1;
-	unsigned int head:1;
-} TrackMap_t;
-
-
-
-typedef struct Xdf_t {
-	Class_t *Class;
-	int refs;
-	Stream_t *Next;
-	Stream_t *Buffer;
-
-	int fd;
-	char *buffer;
-	
-	int current_track;
-	
-	sector_map_t *map;
-
-	int track_size;
-	int track0_size;
-	int sector_size;
-	int FatSize;
-	int RootDirSize;
-	TrackMap_t *track_map;
-
-	unsigned char last_sector;
-	unsigned char rate;
-
-	unsigned int stretch:1;
-	unsigned int rootskip:1;
-	signed  int drive:4;
-} Xdf_t;
-
-typedef struct {
-	unsigned char head;
-	unsigned char sector;
-	unsigned char ptr;
-} Compactify_t;
-
-
-static int analyze_reply(RawRequest_t *raw_cmd, int do_print)
-{
-	int ret, bytes, newbytes;
-
-	bytes = 0;
-	while(1) {
-		ret = analyze_one_reply(raw_cmd, &newbytes, do_print);
-		bytes += newbytes;
-		switch(ret) {
-			case 0:
-				return bytes;
-			case 1:
-				raw_cmd++;
-				break;
-			case -1:
-				if(bytes)
-					return bytes;
-				else
-					return 0;
-		}
-	}
-}
-				
-
-
-static int send_cmd(int fd, RawRequest_t *raw_cmd, int nr,
-		    const char *message, int retries)
-{
-	int j;
-	int ret=-1;
-	
-	if(!nr)
-		return 0;
-	for (j=0; j< retries; j++){
-		switch(send_one_cmd(fd, raw_cmd, message)) {
-			case -1:
-				return -1;
-			case 1:
-				j++;
-				continue;
-			case 0:
-				break;
-		}
-		if((ret=analyze_reply(raw_cmd, j)) > 0)
-			return ret; /* ok */
-	}
-	if(j > 1 && j == retries) {
-		fprintf(stderr,"Too many errors, giving up\n");
-		return 0;
-	}
-	return -1;
-}
-
-
-
-#define REC (This->track_map[ptr])
-#define END(x) (This->track_map[(x)].end)
-#define BEGIN(x) (This->track_map[(x)].begin)
-
-static int add_to_request(Xdf_t *This, int ptr,
-			  RawRequest_t *request, int *nr,
-			  int direction, Compactify_t *compactify)
-{
-#if 0
-	if(direction == MT_WRITE) {
-		printf("writing %d: %d %d %d %d [%02x]\n", 
-		       ptr, This->current_track,
-		       REC.head, REC.sector, REC.sizecode,
-		       *(This->buffer + ptr * This->sector_size));
-	} else
-			printf(" load %d.%d\n", This->current_track, ptr);
-#endif
-	if(REC.phantom) {
-		if(direction== MT_READ)			
-			memset(This->buffer + ptr * This->sector_size, 0,
-			       128 << REC.sizecode);
-		return 0;
-	}
-	
-	if(*nr &&
-	   RR_SIZECODE(request+(*nr)-1) == REC.sizecode &&	   
-	   compactify->head == REC.head &&
-	   compactify->ptr + 1 == ptr &&
-	   compactify->sector +1 == REC.sector) {
-		RR_SETSIZECODE(request+(*nr)-1, REC.sizecode);
-	} else {
-		if(*nr)
-			RR_SETCONT(request+(*nr)-1);
-		RR_INIT(request+(*nr));
-		RR_SETDRIVE(request+(*nr), This->drive);
-		RR_SETRATE(request+(*nr), This->rate);
-		RR_SETTRACK(request+(*nr), This->current_track);
-		RR_SETPTRACK(request+(*nr), 
-			     This->current_track << This->stretch);
-		RR_SETHEAD(request+(*nr), REC.head);
-		RR_SETSECTOR(request+(*nr), REC.sector);
-		RR_SETSIZECODE(request+(*nr), REC.sizecode);
-		RR_SETDIRECTION(request+(*nr), direction);
-		RR_SETDATA(request+(*nr),
-			   (caddr_t) This->buffer + ptr * This->sector_size);
-		(*nr)++;
-	}
-	compactify->ptr = ptr;
-	compactify->head = REC.head;
-	compactify->sector = REC.sector;
-	return 0;
-}
-
-
-static void add_to_request_if_invalid(Xdf_t *This, int ptr,
-				     RawRequest_t *request, int *nr,
-				     Compactify_t *compactify)
-{
-	if(!REC.valid)
-		add_to_request(This, ptr, request, nr, MT_READ, compactify);
-
-}
-
-
-static void adjust_bounds(Xdf_t *This, off_t *begin, off_t *end)
-{
-	/* translates begin and end from byte to sectors */
-	*begin = *begin / This->sector_size;
-	*end = (*end + This->sector_size - 1) / This->sector_size;
-}
-
-
-static inline int try_flush_dirty(Xdf_t *This)
-{
-	int ptr, nr, bytes;
-	RawRequest_t requests[100];
-	Compactify_t compactify;
-
-	if(This->current_track < 0)
-		return 0;
-	
-	nr = 0;
-	for(ptr=0; ptr < This->last_sector; ptr=REC.end)
-		if(REC.dirty)
-			add_to_request(This, ptr,
-				       requests, &nr,
-				       MT_WRITE, &compactify);
-#if 1
-	bytes = send_cmd(This->fd,requests, nr, "writing", 4);
-	if(bytes < 0)
-		return bytes;
-#else
-	bytes = 0xffffff;
-#endif
-	for(ptr=0; ptr < This->last_sector; ptr=REC.end)
-		if(REC.dirty) {
-			if(bytes >= REC.end - REC.begin) {
-				bytes -= REC.end - REC.begin;
-				REC.dirty = 0;
-			} else
-				return 1;
-		}
-	return 0;
-}
-
-
-
-static int flush_dirty(Xdf_t *This)
-{	
-	int ret;
-
-	while((ret = try_flush_dirty(This))) {
-		if(ret < 0)		       
-			return ret;
-	}
-	return 0;
-}
-
-
-static int load_data(Xdf_t *This, off_t begin, off_t end, int retries)
-{
-	int ptr, nr, bytes;
-	RawRequest_t requests[100];
-	Compactify_t compactify;
-
-	adjust_bounds(This, &begin, &end);
-	
-	ptr = begin;
-	nr = 0;
-	for(ptr=REC.begin; ptr < end ; ptr = REC.end)
-		add_to_request_if_invalid(This, ptr, requests, &nr,
-					  &compactify);
-	bytes = send_cmd(This->fd,requests, nr, "reading", retries);
-	if(bytes < 0)
-		return bytes;
-	ptr = begin;
-	for(ptr=REC.begin; ptr < end ; ptr = REC.end) {
-		if(!REC.valid) {
-			if(bytes >= REC.end - REC.begin) {
-				bytes -= REC.end - REC.begin;
-				REC.valid = 1;
-			} else if(ptr > begin)
-				return ptr * This->sector_size;
-			else
-				return -1;
-		}
-	}
-	return end * This->sector_size;
-}
-
-static void mark_dirty(Xdf_t *This, off_t begin, off_t end)
-{
-	int ptr;
-
-	adjust_bounds(This, &begin, &end);
-	
-	ptr = begin;
-	for(ptr=REC.begin; ptr < end ; ptr = REC.end) {
-		REC.valid = 1;
-		if(!REC.phantom)
-			REC.dirty = 1;
-	}
-}
-
-
-static int load_bounds(Xdf_t *This, off_t begin, off_t end)
-{
-	off_t lbegin, lend;
-	int endp1, endp2;
-
-	lbegin = begin;
-	lend = end;
-
-	adjust_bounds(This, &lbegin, &lend);	
-
-	if(begin != BEGIN(lbegin) * This->sector_size &&
-	   end != BEGIN(lend) * This->sector_size &&
-	   lend < END(END(lbegin)))
-		/* contiguous end & begin, load them in one go */
-		return load_data(This, begin, end, 4);
-
-	if(begin != BEGIN(lbegin) * This->sector_size) {
-		endp1 = load_data(This, begin, begin, 4);
-		if(endp1 < 0)
-			return endp1;
-	}
-
-	if(end != BEGIN(lend) * This->sector_size) {
-		endp2 = load_data(This, end, end, 4);
-		if(endp2 < 0)
-			return BEGIN(lend) * This->sector_size;
-	}
-	return lend * This->sector_size;
-}
-
-
-static int fill_t0(Xdf_t *This, int ptr, int size, int *sector, int *head)
-{
-	int n;
-
-	for(n = 0; n < size; ptr++,n++) {
-		REC.head = *head;
-		REC.sector = *sector + 129;
-		REC.phantom = 0;
-		(*sector)++;
-		if(!*head && *sector >= This->track0_size - 8) {
-			*sector = 0;
-			*head = 1;
-		}
-	}
-	return ptr;
-}
-
-
-static int fill_phantoms(Xdf_t *This, int ptr, int size)
-{
-	int n;
-
-	for(n = 0; n < size; ptr++,n++)
-		REC.phantom = 1;
-	return ptr;
-}
-
-static void decompose(Xdf_t *This, int where, int len, off_t *begin, 
-					  off_t *end, int boot)
-{
-	int ptr, track;
-	sector_map_t *map;
-	int lbegin, lend;
-	
-	track = where / This->track_size / 1024;
-	
-	*begin = where - track * This->track_size * 1024;
-	*end = where + len - track * This->track_size * 1024;
-	maximize(*end, This->track_size * 1024);
-
-	if(This->current_track == track && !boot)
-		/* already OK, return immediately */
-		return;
-	if(!boot)
-		flush_dirty(This);
-	This->current_track = track;
-
-	if(track) {
-		for(ptr=0, map=This->map; map->size; map++) {
-			/* iterate through all sectors */
-			lbegin = ptr;
-			lend = ptr + (128 << map->size) / This->sector_size;
-			for( ; ptr < lend ; ptr++) {
-				REC.begin = lbegin;
-				REC.end = lend;
-				
-				REC.head = map->head;
-				REC.sector = map->size + 128;
-				REC.sizecode = map->size;
-				
-				REC.valid = 0;
-				REC.dirty = 0;
-				REC.phantom = 0;
-			}
-		}
-		REC.begin = REC.end = ptr;
-	} else {
-		int sector, head;
-
-		head = 0;
-		sector = 0;
-
-		for(ptr=boot; ptr < 2 * This->track_size; ptr++) {
-			REC.begin = ptr;
-			REC.end = ptr+1;
-			
-			REC.sizecode = 2;
-			
-			REC.valid = 0;
-			REC.dirty = 0;
-		}
-
-		/* boot & 1st fat */
-		ptr=fill_t0(This, 0, 1 + This->FatSize, &sector, &head);
-
-		/* second fat */
-		ptr=fill_phantoms(This, ptr, This->FatSize);
-
-		/* root dir */
-		ptr=fill_t0(This, ptr, This->RootDirSize, &sector, &head);
-		
-		/* "bad sectors" at the beginning of the fs */
-		ptr=fill_phantoms(This, ptr, 5);
-
-		if(This->rootskip)
-			sector++;
-
-		/* beginning of the file system */
-		ptr = fill_t0(This, ptr,
-			      (This->track_size - This->FatSize) * 2 -
-			      This->RootDirSize - 6,
-			      &sector, &head);
-	}
-	This->last_sector = ptr;
-}
-
-
-static int xdf_read(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
-{	
-	off_t begin, end;
-	size_t len2;
-	DeclareThis(Xdf_t);
-
-	decompose(This, truncBytes32(where), len, &begin, &end, 0);
-	len2 = load_data(This, begin, end, 4);
-	if(len2 < 0)
-		return len2;
-	len2 -= begin;
-	maximize(len, len2);
-	memcpy(buf, This->buffer + begin, len);
-	return end - begin;
-}
-
-static int xdf_write(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
-{	
-	off_t begin, end;
-	size_t len2;
-	DeclareThis(Xdf_t);
-
-	decompose(This, truncBytes32(where), len, &begin, &end, 0);
-	len2 = load_bounds(This, begin, end);
-	if(len2 < 0)
-		return len2;
-	maximize(end, len2);
-	len2 -= begin;
-	maximize(len, len2);
-	memcpy(This->buffer + begin, buf, len);
-	mark_dirty(This, begin, end);
-	return end - begin;
-}
-
-static int xdf_flush(Stream_t *Stream)
-{
-	DeclareThis(Xdf_t);
-
-	return flush_dirty(This);       
-}
-
-static int xdf_free(Stream_t *Stream)
-{
-	DeclareThis(Xdf_t);
-	Free(This->track_map);
-	Free(This->buffer);
-	return close(This->fd);
-}
-
-
-static int check_geom(struct device *dev, int media, struct bootsector *boot)
-{
-	int sect;
-
-	if(media >= 0xfc && media <= 0xff)
-		return 1; /* old DOS */
-
-	if (!IS_MFORMAT_ONLY(dev)) {
-	    if(compare(dev->sectors, 19) &&
-	       compare(dev->sectors, 23) &&
-	       compare(dev->sectors, 24) &&
-	       compare(dev->sectors, 46) &&
-	       compare(dev->sectors, 48))
-		return 1;
-	    
-	    /* check against contradictory info from configuration file */
-	    if(compare(dev->heads, 2))
-		return 1;
-	}
-
-	/* check against info from boot */
-	if(boot) {
-		sect = WORD(nsect);
-		if((sect != 19 && sect != 23 && sect != 24 &&
-		    sect != 46 && sect != 48) ||
-		   (!IS_MFORMAT_ONLY(dev) && compare(dev->sectors, sect)) || 
-		   WORD(nheads) !=2)
-		    return 1;
-	}
-	return 0;
-}
-
-static void set_geom(struct bootsector *boot, struct device *dev)
-{
-	/* fill in config info to be returned to user */
-	dev->heads = 2;
-	dev->use_2m = 0xff;
-	if(boot) {
-		dev->sectors = WORD(nsect);
-		if(WORD(psect))
-			dev->tracks = WORD(psect) / dev->sectors / 2;
-	}
-}
-
-static int config_geom(Stream_t *Stream, struct device *dev, 
-		       struct device *orig_dev, int media,
-		       struct bootsector *boot)
-{
-	if(check_geom(dev, media, boot))
-		return 1;
-	set_geom(boot,dev);
-	return 0;
-}
-
-static Class_t XdfClass = {
-	xdf_read, 
-	xdf_write, 
-	xdf_flush, 
-	xdf_free, 
-	config_geom, 
-	0, /* get_data */
-	0 /* pre-allocate */
-};
-
-Stream_t *XdfOpen(struct device *dev, char *name,
-		  int mode, char *errmsg, struct xdf_info *info)
-{
-	Xdf_t *This;
-	off_t begin, end;
-	struct bootsector *boot;
-	int type;
-
-	if(dev && (!SHOULD_USE_XDF(dev) || check_geom(dev, 0, 0)))
-		return NULL;
-
-	This = New(Xdf_t);
-	if (!This)
-		return NULL;
-
-	This->Class = &XdfClass;
-	This->sector_size = 512;
-	This->stretch = 0;
-
-	precmd(dev);
-	This->fd = open(name, mode | dev->mode | O_EXCL | O_NDELAY);
-	if(This->fd < 0) {
-#ifdef HAVE_SNPRINTF
-		snprintf(errmsg,199,"xdf floppy: open: \"%s\"", strerror(errno));
-#else
-		sprintf(errmsg,"xdf floppy: open: \"%s\"", strerror(errno));
-#endif
-		goto exit_0;
-	}
-	closeExec(This->fd);
-
-	This->drive = GET_DRIVE(This->fd);
-	if(This->drive < 0)
-		goto exit_1;
-
-	/* allocate buffer */
-	This->buffer = (char *) malloc(96 * 512);
-	if (!This->buffer)
-		goto exit_1;
-
-	This->current_track = -1;
-	This->track_map = (TrackMap_t *)
-		calloc(96, sizeof(TrackMap_t));
-	if(!This->track_map)
-		goto exit_2;
-
-	/* lock the device on writes */
-	if (lock_dev(This->fd, mode == O_RDWR, dev)) {
-#ifdef HAVE_SNPRINTF
-		snprintf(errmsg,199,"xdf floppy: device \"%s\" busy:", 
-			dev->name);
-#else
-		sprintf(errmsg,"xdf floppy: device \"%s\" busy:", 
-			dev->name);
-#endif
-		goto exit_3;
-	}
-
-	/* Before reading the boot sector, assume dummy values suitable
-	 * for reading at least the boot sector */
-	This->track_size = 11;
-	This->track0_size = 6;
-	This->rate = 0;
-	This->FatSize = 9;
-	This->RootDirSize = 1;
-	decompose(This, 0, 512, &begin, &end, 0);
-	if (load_data(This, 0, 1, 1) < 0 ) {
-		This->rate = 0x43;
-		if(load_data(This, 0, 1, 1) < 0)
-			goto exit_3;
-	}
-
-	boot = (struct bootsector *) This->buffer;
-	This->FatSize = WORD(fatlen);
-	This->RootDirSize = WORD(dirents)/16;
-	This->track_size = WORD(nsect);
-	for(type=0; type < NUMBER(xdf_table); type++) {
-		if(xdf_table[type].track_size == This->track_size) {
-			This->map = xdf_table[type].map;
-			This->track0_size = xdf_table[type].track0_size;
-			This->rootskip = xdf_table[type].rootskip;
-			break;
-		}
-	}
-	if(type == NUMBER(xdf_table))
-		goto exit_3;
-
-	if(info) {
-		info->RootDirSize = This->RootDirSize;
-		info->FatSize = This->FatSize;
-		info->BadSectors = 5;
-	}
-	decompose(This, 0, 512, &begin, &end, 1);
-
-	This->refs = 1;
-	This->Next = 0;
-	This->Buffer = 0;
-	if(dev)
-		set_geom(boot, dev);
-	return (Stream_t *) This;
-
-exit_3:
-	Free(This->track_map);
-exit_2:
-	Free(This->buffer);
-exit_1:
-	close(This->fd);
-exit_0:
-	Free(This);
-	return NULL;
-}
-
-#endif
-
-/* Algorithms can't be patented */
-
Index: trunk/minix/commands/i386/mtools-3.9.7/xdf_io.h
===================================================================
--- trunk/minix/commands/i386/mtools-3.9.7/xdf_io.h	(revision 9)
+++ 	(revision )
@@ -1,16 +1,0 @@
-#ifndef MTOOLS_XDFIO_H
-#define MTOOLS_XDFIO_H
-
-#include "msdos.h"
-#include "stream.h"
-
-struct xdf_info {
-  int FatSize;
-  int RootDirSize;
-  int BadSectors;
-};
-
-Stream_t *XdfOpen(struct device *dev, char *name,
-		  int mode, char *errmsg, struct xdf_info *info);
-
-#endif
Index: trunk/minix/commands/i86/Makefile
===================================================================
--- trunk/minix/commands/i86/Makefile	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-# Makefile for commands/i86.
-
-CFLAGS	= -D_MINIX -D_POSIX_SOURCE
-CCLD	= $(CC) -i $(CFLAGS)
-MAKE	= exec make -$(MAKEFLAGS)
-CC = exec cc
-
-all:	cc
-
-cc:	cc.c
-	$(CCLD) -o $@ $?
-	install -S 6kb $@
-
-install:	/usr/bin/cc /usr/bin/m2 /usr/bin/pc
-
-/usr/bin/cc:	cc
-	install -cs -o bin $? $@
-
-/usr/bin/m2 /usr/bin/pc:	/usr/bin/cc
-	install -l $? $@
-
-clean:
-	rm -rf a.out core cc
Index: trunk/minix/commands/i86/cc.c
===================================================================
--- trunk/minix/commands/i86/cc.c	(revision 9)
+++ 	(revision )
@@ -1,1059 +1,0 @@
-/*	Driver for Minix compilers.
-	Written june 1987 by Ceriel J.H. Jacobs, partly derived from old
-	cc-driver, written by Erik Baalbergen.
-	This driver is mostly table-driven, the table being in the form of
-	some global initialized structures.
-*/
-/* $Header: /cvsup/minix/src/commands/i86/cc.c,v 1.1.1.1 2005/04/21 14:54:55 beng Exp $ */
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <signal.h>
-#include <string.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-/* Paths.  (Executables in /usr are first tried with /usr stripped off.) */
-#define SHELL		"/bin/sh"
-#define PP		"/usr/lib/ncpp"
-#define IRREL		"/usr/lib/irrel"
-#define CEM		"/usr/lib/ncem"
-#define M2EM		"/usr/lib/nm2em"
-#define ENCODE		"/usr/lib/em_encode"
-#define OPT		"/usr/lib/nopt"
-#define CG		"/usr/lib/ncg"
-#define AS		"/usr/lib/as"
-#define LD		"/usr/lib/ld"
-#define CV		"/usr/lib/cv"
-#define LIBDIR		"/usr/lib"
-#define CRT		"/usr/lib/ncrtso.o"
-#define PEM		"/usr/lib/npem"
-#define PRT		"/usr/lib/nprtso.o"
-#define M2RT		"/usr/lib/nm2rtso.o"
-#define LIBC            "/usr/lib/libd.a", "/usr/lib/libc.a"
-#define LIBP		"/usr/lib/libp.a", "/usr/lib/libc.a"
-#define LIBM2		"/usr/lib/libm2.a", "/usr/lib/libc.a"
-#define END             "/usr/lib/libe.a", "/usr/lib/end.a"
-#define M2DEF		"-I/usr/lib/m2"
-
-
-/*	every pass that this program knows about has associated with it
-	a structure, containing such information as its name, where it
-	resides, the flags it accepts, and the like.
-*/
-struct passinfo {
-	char *p_name;		/* name of this pass */
-	char *p_path;		/* where is it */
-	char *p_from;		/* suffix of source (comma-separated list) */
-	char *p_to;		/* suffix of destination */
-	char *p_acceptflags;	/* comma separated list; format:
-			   		flag
-			   		flag*
-			   		flag=xxx
-					flag*=xxx[*]
-				   where a star matches a, possibly empty, 
-				   string
-				*/
-	int  p_flags;
-#define INPUT	01		/* needs input file as argument */
-#define OUTPUT	02		/* needs output file as argument */
-#define LOADER	04		/* this pass is the loader */
-#define STDIN	010		/* reads from standard input */
-#define STDOUT	020		/* writes on standard output */
-#define NOCLEAN	040		/* do not remove target if this pass fails */
-#define O_OUTPUT 0100		/* -o outputfile, hack for as */
-#define PREPALWAYS	0200	/* always to be preprocessed */
-#define PREPCOND	0400	/* preprocessed when starting with '#' */
-#define PREPNOLN	01000	/* suppress line number info (cpp -P) */
-};
-
-#define MAXHEAD	10
-#define MAXTAIL	5
-#define MAXPASS	7
-
-/*	Every language handled by this program has a "compile" structure
-	associated with it, describing the start-suffix, how the driver for
-	this language is called, which passes must be called, which flags
-	and arguments must be passed to these passes, etc.
-	The language is determined by the suffix of the argument program.
-	However, if this suffix does not determine a language (DEFLANG),
-	the callname is used.
-	Notice that the 's' suffix does not determine a language, because
-	the input file could have been derived from f.i. a C-program.
-	So, if you use "cc x.s", the C-runtime system will be used, but if
-	you use "as x.s", it will not.
-*/
-struct compile {
-	char *c_suffix;		/* starting suffix of this list of passes */
-	char *c_callname;	/* affects runtime system loaded with program */
-	struct pass {
-		char *pp_name;		/* name of the pass */
-		char *pp_head[MAXHEAD];	/* args in front of filename */
-		char *pp_tail[MAXTAIL];	/* args after filename */
-	} c_passes[MAXPASS];
-	int  c_flags;
-#define DEFLANG		010	/* this suffix determines a language */
-};
-
-struct passinfo passinfo[] = {
-	{ "cpp", PP, "CPP", "i", "wo=o,I*,D*,U*,P", INPUT|STDOUT },
-	{ "irrel", IRREL, "i", "i", "m", INPUT},
-	{ "cem", CEM, "i,c", "k", "m=o,p,wa=a,wo=o,ws=s,w,T*", INPUT|OUTPUT|PREPALWAYS },
-	{ "pc", PEM, "i,p", "k", "n=L,w,a,A,R", INPUT|OUTPUT|PREPCOND },
-	{ "m2", M2EM, "i,mod", "k", "n=L,w*,A,R,W*,3,I*", INPUT|OUTPUT|PREPCOND },
-	{ "encode", ENCODE, "i,e", "k", "", INPUT|STDOUT|PREPCOND|PREPNOLN },
-	{ "opt", OPT, "k", "m", "", STDIN|STDOUT },
-	{ "cg", CG, "m", "s", "O=p4", INPUT|OUTPUT },
-	{ "as", AS, "i,s", "o", "T*", INPUT|O_OUTPUT|PREPCOND },
-	{ "ld", LD, "o", "out", "i,s", INPUT|LOADER },	/* changed */
-	{ "cv", CV, "out", 0, "", INPUT|OUTPUT|NOCLEAN },	/* must come after loader */
-	{ 0}
-};
-
-#define	PREP_FLAGS	"-D_EM_WSIZE=2", "-D_EM_PSIZE=2", "-D_EM_SSIZE=2", \
-			"-D_EM_LSIZE=4", "-D_EM_FSIZE=4", "-D_EM_DSIZE=8", \
-			"-D__ACK__", "-D__minix", "-D__i86"
-
-struct pass preprocessor = { "cpp",
-			    { PREP_FLAGS }
-			    , {0}
-			    };
-
-struct pass prepnoln = { "cpp",
-			    { PREP_FLAGS, "-P" }
-			    , {0}
-			    };
-
-struct pass irrel = { "irrel",
-			    {0}
-			};
-
-/* The "*" in the arguments for the loader indicates the place where the
- * fp-emulation library should come.
- */
-struct compile passes[] = {
-{	"c", "cc", 
-	{	{ "cem", {"-L"}, {0} },	/* changed */
-		{ "opt", {0}, {0} },
-		{ "cg", {0}, {0} },
-		{ "as", {"-"}, {0} },
-		{ "ld", {CRT}, /* changed */
-			  {LIBC, "*",  END}},
-		{ "cv", {0}, {0} }
-	},
-	DEFLANG
-},
-{	"p", "pc",
-	{	{ "pc", {0}, {0} },
-		{ "opt", {0}, {0} },
-		{ "cg", {0}, {0} },
-		{ "as", {"-"}, {0} },
-		{ "ld", {PRT}, 
-			  {LIBP,
-			    "*", END}},
-		{ "cv", {0}, {0} }
-	},
-	DEFLANG
-},
-{	"mod", "m2",
-	{	{ "m2", {M2DEF}, {0} },
-		{ "opt", {0}, {0} },
-		{ "cg", {0}, {0} },
-		{ "as", {"-"}, {0} },
-		{ "ld", {M2RT}, 
-			  {LIBM2,
-			    "*", END}},
-		{ "cv", {0}, {0} }
-	},
-	DEFLANG
-},
-{	"e", "encode",
-	{	{ "encode", {0}, {0}},
-		{ "opt", {0}, {0} },
-		{ "cg", {0}, {0} },
-		{ "as", {"-"}, {0} },
-		{ "ld", {0}, {"*", END}},
-		{ "cv", {0}, {0} }
-	},
-	DEFLANG
-},
-{	"s", "as",
-	{	{ "as", {0}, {0}}
-	},
-	0
-},
-{	"CPP", "cpp",
-	{	{ "cpp", {PREP_FLAGS}, {0}}
-	},
-	DEFLANG
-},
-{	0},
-};
-
-#define MAXARGC	150	/* maximum number of arguments allowed in a list */
-#define USTR_SIZE	64	/* maximum length of string variable */
-
-typedef char USTRING[USTR_SIZE];
-
-struct arglist {
-	int al_argc;
-	char *al_argv[MAXARGC];
-};
-
-struct arglist CALLVEC;
-
-int kids = -1;
-
-char *o_FILE = "a.out"; /* default name for executable file */
-
-#define init(a)		((a)->al_argc = 1)
-#define cleanup(str)		(str && remove(str))
-
-char *ProgCall = 0;
-
-int RET_CODE = 0;
-
-char *stopsuffix;
-int v_flag = 0;
-int t_flag = 0;
-int noexec = 0;
-int fp_lib = 1;
-int E_flag = 0;
-int i_flag = 1;
-
-
-USTRING curfil;
-USTRING newfil;
-struct arglist SRCFILES;
-struct arglist LDIRS;
-struct arglist LDFILES;
-struct arglist GEN_LDFILES;
-struct arglist FLAGS;
-
-char *tmpdir = "/tmp";
-char tmpname[64];
-
-struct compile *compbase;
-struct pass *loader;
-struct passinfo *loaderinfo;
-char *source;
-int maxLlen;
-
-_PROTOTYPE(char *library, (char *nm ));
-_PROTOTYPE(void trapcc, (int sig ));
-_PROTOTYPE(int main, (int argc, char *argv []));
-_PROTOTYPE(int remove, (char *str ));
-_PROTOTYPE(char *alloc, (unsigned u ));
-_PROTOTYPE(int append, (struct arglist *al, char *arg ));
-_PROTOTYPE(int concat, (struct arglist *al1, struct arglist *al2 ));
-_PROTOTYPE(char *mkstr, (char *dst, char *arg1, char *arg2, char *arg3 ));
-_PROTOTYPE(int basename, (char *str, char *dst ));
-_PROTOTYPE(char *extension, (char *fln ));
-_PROTOTYPE(int runvec, (struct arglist *vec, struct passinfo *pass, char *in, char *out ));
-_PROTOTYPE(int prnum, (unsigned x ));
-_PROTOTYPE(int prs, (char *str ));
-_PROTOTYPE(int panic, (char *str ));
-_PROTOTYPE(int pr_vec, (struct arglist *vec ));
-_PROTOTYPE(int ex_vec, (struct arglist *vec ));
-_PROTOTYPE(int mktempname, (char *nm ));
-_PROTOTYPE(int mkbase, (void));
-_PROTOTYPE(int mkloader, (void));
-_PROTOTYPE(int needsprep, (char *name ));
-_PROTOTYPE(int cfile, (char *name ));
-_PROTOTYPE(char *apply, (struct passinfo *pinf, struct compile *cp, char *name, int passindex, int noremove, int first, char *resultname ));
-_PROTOTYPE(int applicable, (struct passinfo *pinf, char *suffix ));
-_PROTOTYPE(char *process, (char *name, int noremove ));
-_PROTOTYPE(int mkvec, (struct arglist *call, char *in, char *out, struct pass *pass, struct passinfo *pinf ));
-_PROTOTYPE(int callld, (struct arglist *in, char *out, struct pass *pass, struct passinfo *pinf ));
-_PROTOTYPE(int clean, (struct arglist *c ));
-_PROTOTYPE(int scanflags, (struct arglist *call, struct passinfo *pinf ));
-
-
-
-char *
-library(nm)
-	char	*nm;
-{
-	static char	f[512];
-	int	Lcount;
-
-	for (Lcount = 0; Lcount < LDIRS.al_argc; Lcount++) {
-		mkstr(f, LDIRS.al_argv[Lcount], "/lib", nm);
-		strcat(f, ".a");
-		if (access(f, 0) != 0) {
-			f[strlen(f)-1] = 'a';
-			if (access(f, 0) != 0) continue;
-		}
-		return f;
-	}
-	mkstr(f, LIBDIR, "/lib", nm);
-	strcat(f, ".a");
-	if (access(f, 0) != 0) {
-		int i = strlen(f) - 1;
-		f[i] = 'a';
-		if (access(f, 0) != 0) f[i] = 'A';
-	}
-	return f;
-}
-
-void trapcc(sig)
-	int sig;
-{
-	signal(sig, SIG_IGN);
-	if (kids != -1) kill(kids, sig);
-	cleanup(newfil);
-	cleanup(curfil);
-	exit(1);
-}
-
-main(argc, argv)
-	char *argv[];
-{
-	char *str;
-	char **argvec;
-	int count;
-	char *file;
-
-	maxLlen = strlen(LIBDIR);
-	ProgCall = *argv++;
-
-	mkbase();
-
-	if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
-		signal(SIGHUP, trapcc);
-	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
-		signal(SIGINT, trapcc);
-	if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
-		signal(SIGQUIT, trapcc);
-	while (--argc > 0) {
-		if (*(str = *argv++) != '-' || str[1] == 0) {
-			append(&SRCFILES, str);
-			continue;
-		}
-
-		if (strcmp(str, "-com") == 0) {
-			i_flag = 0;
-		} else
-		if (strcmp(str, "-sep") == 0) {
-			i_flag = 1;
-		} else {
-			switch (str[1]) {
-
-			case 'c':
-				stopsuffix = "o";
-				if (str[2] == '.') stopsuffix = str + 3;
-				break;
-			case 'f':
-				fp_lib = (strcmp(str+2, "hard") != 0);
-				break;
-			case 'F':
-			case 'W':
-				/* Ignore. */
-				break;
-			case 'L':
-				append(&LDIRS, &str[2]);
-				count = strlen(&str[2]);
-				if (count > maxLlen) maxLlen = count;
-				break;
-			case 'l':
-				append(&SRCFILES, library(&str[2]));
-				break;
-			case 'm':
-				/* Use -m, ignore -mxxx. */
-				if (str[2] == 0) append(&FLAGS, str);
-				break;
-			case 'o':
-				if (argc-- >= 0)
-					o_FILE = *argv++;
-				break;
-			case 'S':
-				stopsuffix = "s";
-				break;
-			case 'E':
-				E_flag = 1;
-				stopsuffix = "i";
-				break;
-			case 'P':
-				stopsuffix = "i";
-				append(&FLAGS, str);
-				break;
-			case 'v':
-				v_flag++;
-				if (str[2] == 'n')
-					noexec = 1;
-				break;
-			case 't':
-				/* save temporaries */
-				t_flag++;
-				break;
-			case '.':
-				if (str[2] == 'o') {
-					/* no runtime start-off */
-					loader->pp_head[0] = 0;
-				}
-				break;
-			case 'i':
-				i_flag++;
-				break;
-			case 'T':
-				tmpdir = &str[2];
-				/*FALLTHROUGH*/
-			default:
-				append(&FLAGS, str);
-
-			}
-		}
-	}
-
-	if (i_flag) append(&FLAGS, "-i");
-
-	mktempname(tmpname);
-
-	count = SRCFILES.al_argc;
-	argvec = &(SRCFILES.al_argv[0]);
-
-	while (count-- > 0) {
-
-		file = *argvec++;
-		source = file;
-
-		file = process(file, 1);
-	
-		if (file && ! stopsuffix) append(&LDFILES, file);
-	}
-
-	clean(&SRCFILES);
-
-	/* loader ... */
-	if (RET_CODE == 0 && LDFILES.al_argc > 0) {
-		register struct passinfo *pp = passinfo;
-
-		while (!(pp->p_flags & LOADER)) pp++;
-		mkstr(newfil, tmpname, pp->p_to, "");
-		callld(&LDFILES, !((pp+1)->p_name) ? o_FILE : newfil, loader, pp);
-		if (RET_CODE == 0) {
-			register int i = GEN_LDFILES.al_argc;
-
-			while (i-- > 0) {
-				remove(GEN_LDFILES.al_argv[i]);
-				free(GEN_LDFILES.al_argv[i]);
-			}
-			if ((++pp)->p_name) {
-				process(newfil, 0);
-			}
-		}
-	}
-	exit(RET_CODE);
-}
-
-remove(str)
-	char *str;
-{
-	if (t_flag)
-		return;
-	if (v_flag) {
-		prs("rm ");
-		prs(str);
-		prs("\n");
-	}
-	if (noexec)
-		return;
-	unlink(str);
-}
-
-char *
-alloc(u)
-	unsigned u;
-{
-	register char *p = malloc(u);
-
-	if (p == 0) panic("no space\n");
-	return p;
-}
-
-append(al, arg)
-	struct arglist *al;
-	char *arg;
-{
-	char *a = alloc((unsigned) (strlen(arg) + 1));
-
-	strcpy(a, arg);
-	if (al->al_argc >= MAXARGC)
-		panic("argument list overflow\n");
-	al->al_argv[(al->al_argc)++] = a;
-}
-
-concat(al1, al2)
-	struct arglist *al1, *al2;
-{
-	register i = al2->al_argc;
-	register char **p = &(al1->al_argv[al1->al_argc]);
-	register char **q = &(al2->al_argv[0]);
-
-	if ((al1->al_argc += i) >= MAXARGC)
-		panic("argument list overflow\n");
-	while (i-- > 0)
-		*p++ = *q++;
-}
-
-char *
-mkstr(dst, arg1, arg2, arg3)
-	char *dst, *arg1, *arg2, *arg3;
-{
-	register char *p;
-	register char *q = dst;
-
-	p = arg1;
-	while (*q++ = *p++);
-	q--;
-	p = arg2;
-	while (*q++ = *p++);
-	q--;
-	p = arg3;
-	while (*q++ = *p++);
-	q--;
-	return dst;
-}
-
-basename(str, dst)
-	char *str;
-	register char *dst;
-{
-	register char *p1 = str;
-	register char *p2 = p1;
-
-	while (*p1)
-		if (*p1++ == '/')
-			p2 = p1;
-	p1--;
-	while (*p1 != '.' && p1 > p2) p1--;
-	if (*p1 == '.') {
-		*p1 = '\0';
-		while (*dst++ = *p2++);
-		*p1 = '.';
-	}
-	else
-		while (*dst++ = *p2++);
-}
-
-char *
-extension(fln)
-	char *fln;
-{
-	register char *fn = fln;
-
-	while (*fn) fn++;
-	while (fn > fln && *fn != '.') fn--;
-	if (fn != fln) return fn+1;
-	return (char *)0;
-}
-
-runvec(vec, pass, in, out)
-	struct arglist *vec;
-	struct passinfo *pass;
-	char *in, *out;
-{
-	int pid, status;
-	int shifted = 0;
-
-	if (
-		strncmp(vec->al_argv[1], "/usr/", 5) == 0
-		&&
-		access(vec->al_argv[1] + 4, 1) == 0
-	) {
-		vec->al_argv[1] += 4;
-		shifted = 1;
-	}
-
-	if (v_flag) {
-		pr_vec(vec);
-		if (pass->p_flags & STDIN) {
-			prs(" <");
-			prs(in);
-		}
-		if (pass->p_flags & STDOUT && !E_flag) {
-			prs(" >");
-			prs(out);
-		}
-		prs("\n");
-	}
-	if (noexec) {
-		if (shifted) vec->al_argv[1] -= 4;
-		clean(vec);
-		return 1;
-	}
-	if ((pid = fork()) == 0) {	/* start up the process */
-		if (pass->p_flags & STDIN && strcmp(in, "-") != 0) {
-			/* redirect standard input */
-			close(0);
-			if (open(in, 0) != 0)
-				panic("cannot open input file\n");
-		}
-		if (pass->p_flags & STDOUT && !E_flag) {
-			/* redirect standard output */
-			close(1);
-			if (creat(out, 0666) != 1)
-				panic("cannot create output file\n");
-		}
-		ex_vec(vec);
-	}
-	if (pid == -1)
-		panic("no more processes\n");
-	kids = pid;
-	wait(&status);
-	if (status) switch(status & 0177) {
-	case SIGHUP:
-	case SIGINT:
-	case SIGQUIT:
-	case SIGTERM:
-	case 0:
-		break;
-	default:
-		if (E_flag && (status & 0177) == SIGPIPE) break;
-		prs(vec->al_argv[1]);
-		prs(" died with signal ");
-		prnum(status & 0177);
-		prs("\n");
-	}
-	if (shifted) vec->al_argv[1] -= 4;
-	clean(vec);
-	kids = -1;
-	return status ? ((RET_CODE = 1), 0) : 1;
-}
-
-prnum(x)
-	register unsigned x;
-{
-	static char numbuf[8];			/* though it prints at most 3 characters */
-	register char *cp = numbuf + sizeof(numbuf) - 1;
-
-	*cp = '\0';
-	while (x >= 10) {
-		*--cp = (x % 10) + '0';
-		x /= 10;
-	}
-	*--cp = x + '0';
-	prs(cp);
-
-}
-
-prs(str)
-	char *str;
-{
-	if (str && *str)
-		write(2, str, strlen(str));
-}
-
-panic(str)
-	char *str;
-{
-	prs(str);
-	trapcc(SIGINT);
-}
-
-pr_vec(vec)
-	register struct arglist *vec;
-{
-	register char **ap = &vec->al_argv[1];
-	
-	vec->al_argv[vec->al_argc] = 0;
-	prs(*ap);
-	while (*++ap) {
-		prs(" ");
-		if (strlen(*ap))
-			prs(*ap);
-		else
-			prs("(empty)");
-	}
-}
-
-ex_vec(vec)
-	register struct arglist *vec;
-{
-	extern int errno;
-
-	vec->al_argv[vec->al_argc] = 0;
-	execv(vec->al_argv[1], &(vec->al_argv[1]));
-	if (errno == ENOEXEC) { /* not an a.out, try it with the SHELL */
-		vec->al_argv[0] = SHELL;
-		execv(SHELL, &(vec->al_argv[0]));
-	}
-	if (access(vec->al_argv[1], 1) == 0) {
-		/* File is executable. */
-		prs("Cannot execute ");
-		prs(vec->al_argv[1]);
-		prs(". Not enough memory.\n");
-		prs("Reduce the memory use of your system and try again\n");
-	} else {
-		prs(vec->al_argv[1]);
-		prs(" is not executable\n");
-	}
-	exit(1);
-}
-
-mktempname(nm)
-	register char *nm;
-{
-	register int i;
-	register int pid = getpid();
-
-	mkstr(nm, tmpdir, "/", compbase->c_callname);
-	while (*nm) nm++;
-
-	for (i = 9; i > 3; i--) {
-		*nm++ = (pid % 10) + '0';
-		pid /= 10;
-	}
-	*nm++ = '.';
-	*nm++ = '\0'; /* null termination */
-}
-
-mkbase()
-{
-	register struct compile *p = passes;
-	USTRING callname;
-	register int len;
-
-	basename(ProgCall, callname);
-	len = strlen(callname);
-	while (p->c_suffix) {
-		if (strcmp(p->c_callname, callname+len-strlen(p->c_callname)) == 0) {
-			compbase = p;
-			mkloader();
-			return;
-		}
-		p++;
-	}
-	/* we should not get here */
-	panic("internal error\n");
-}
-
-mkloader()
-{
-	register struct passinfo *p = passinfo;
-	register struct pass *pass;
-
-	while (!(p->p_flags & LOADER)) p++;
-	loaderinfo = p;
-	pass = &(compbase->c_passes[0]);
-	while (strcmp(pass->pp_name, p->p_name)) pass++;
-	loader = pass;
-}
-
-needsprep(name)
-	char *name;
-{
-	int file;
-	char fc;
-
-	file = open(name,0);
-	if (file <0) return 0;
-	if (read(file, &fc, 1) != 1) fc = 0;
-	close(file);
-	return fc == '#';
-}
-
-cfile(name)
-	char *name;
-{
-	while (*name != '\0' && *name != '.')
-		name++;
-
-	if (*name == '\0') return 0;
-	return (*++name == 'c' && *++name == '\0');
-}
-
-char *
-apply(pinf, cp, name, passindex, noremove, first, resultname)
-	register struct passinfo *pinf;
-	register struct compile *cp;
-	char *name, *resultname;
-{
-	/*	Apply a pass, indicated by "pinf", with args in 
-		cp->c_passes[passindex], to name "name", leaving the result
-		in a file with name "resultname", concatenated with result
-		suffix.
-		When neccessary, the preprocessor is run first.
-		If "noremove" is NOT set, the file "name" is removed.
-	*/
-
-	struct arglist *call = &CALLVEC;
-	struct pass *pass = &(cp->c_passes[passindex]);
-	char *outname;
-
-	if ( /* this pass is the first pass */
-	     first
-	   &&
-	     ( /* preprocessor always needed */
-	       (pinf->p_flags & PREPALWAYS)
-	     ||/* or only when "needsprep" says so */
-	       ( (pinf->p_flags & PREPCOND) && needsprep(name))
-	     )
-	   ) {
-		mkstr(newfil, tmpname, passinfo[0].p_to, "");
-		mkvec(call, name, newfil,
-			(pinf->p_flags & PREPNOLN) ? &prepnoln : &preprocessor,
-			&passinfo[0]);
-		if (! runvec(call, &passinfo[0], name, newfil)) {
-			cleanup(newfil);
-			return 0;
-		}
-
-		/* A .c file must always be mishandled by irrel. */
-		if (cfile(name)) {
-			/* newfil is OK */
-			mkvec(call, newfil, newfil, &irrel, &passinfo[1]);
-			if (! runvec(call, &passinfo[1], newfil, newfil)) {
-				cleanup(newfil);
-				return 0;
-			}
-		}
-		strcpy(curfil, newfil);
-		newfil[0] = '\0';
-		name = curfil;
-		noremove = 0;
-	}
-	if (pinf->p_to) outname = mkstr(newfil, resultname, pinf->p_to, "");
-	else outname = o_FILE;
-	mkvec(call, name, outname, pass, pinf);
-	if (! runvec(call, pinf, name, outname)) {
-		if (! (pinf->p_flags & NOCLEAN)) cleanup(outname);
-		if (! noremove) cleanup(name);
-		return 0;
-	}
-	if (! noremove) cleanup(name);
-	strcpy(curfil, newfil);
-	newfil[0] = '\0';
-	return curfil;
-}
-
-int
-applicable(pinf, suffix)
-	struct passinfo *pinf;
-	char *suffix;
-{
-	/*	Return one if the pass indicated by "pinfo" is applicable to
-		a file with suffix "suffix".
-	*/
-	register char *sfx = pinf->p_from;
-	int l;
-
-	if (! suffix) return 0;
-	l = strlen(suffix);
-	while (*sfx) {
-		register char *p = sfx;
-
-		while (*p && *p != ',') p++;
-		if (l == p - sfx && strncmp(sfx, suffix, l) == 0) {
-			return 1;
-		}
-		if (*p == ',') sfx = p+1;
-		else sfx = p;
-	}
-	return 0;
-}
-		
-char *
-process(name, noremove)
-	char *name;
-{
-	register struct compile *cp = passes;
-	char *suffix = extension(name);
-	USTRING base;
-	register struct pass *pass;
-	register struct passinfo *pinf;
-
-	if (E_flag) {
-		/* -E uses the cpp pass. */
-		suffix = "CPP";
-	}
-
-	if (! suffix) return name;
-
-	basename(name, base);
-
-	while (cp->c_suffix) {
-		if ((cp->c_flags & DEFLANG) &&
-		    strcmp(cp->c_suffix, suffix) == 0)
-			break;
-		cp++;
-	}
-	if (! cp->c_suffix) cp = compbase;
-	pass = cp->c_passes;
-	while (pass->pp_name) {
-		int first = 1;
-
-		for (pinf=passinfo; strcmp(pass->pp_name,pinf->p_name);pinf++)
-			;
-		if (! (pinf->p_flags & LOADER) && applicable(pinf, suffix)) {
-			int cont = ! stopsuffix || ! pinf->p_to ||
-					strcmp(stopsuffix, pinf->p_to) != 0;
-			name = apply(pinf,
-				     cp,
-				     name,
-				     (int) (pass - cp->c_passes),
-				     noremove,
-				     first,
-				     applicable(loaderinfo, pinf->p_to) ||
-				      !cont ?
-					strcat(base, ".") :
-					tmpname);
-			first = noremove = 0;
-			suffix = pinf->p_to;
-			if (!cont || !name) break;
-		}
-		pass++;
-	}
-	if (!noremove && name)
-		append(&GEN_LDFILES, name);
-	return name;
-}
-
-mkvec(call, in, out, pass, pinf)
-	struct arglist *call;
-	char *in, *out;
-	struct pass *pass;
-	register struct passinfo *pinf;
-{
-	register int i;
-
-	init(call);
-	append(call, pinf->p_path);
-	scanflags(call, pinf);
-	if (pass) for (i = 0; i < MAXHEAD; i++)
-		if (pass->pp_head[i])
-			append(call, pass->pp_head[i]);
-		else	break;
-	if (pinf->p_flags & INPUT && strcmp(in, "-") != 0)
-		append(call, in);
-	if (pinf->p_flags & OUTPUT)
-		append(call, out);
-	if (pinf->p_flags & O_OUTPUT) {
-		append(call, "-o");
-		append(call, out);
-	}
-	if (pass) for (i = 0; i < MAXTAIL; i++)
-		if (pass->pp_tail[i])
-			append(call, pass->pp_tail[i]);
-		else	break;
-}
-
-callld(in, out, pass, pinf)
-	struct arglist *in;
-	char *out;
-	struct pass *pass;
-	register struct passinfo *pinf;
-{
-	struct arglist *call = &CALLVEC;
-	register int i;
-
-	init(call);
-	append(call, pinf->p_path);
-	scanflags(call, pinf);
-	append(call, "-o");
-	append(call, out);
-	for (i = 0; i < MAXHEAD; i++)
-		if (pass->pp_head[i])
-			append(call, pass->pp_head[i]);
-		else	break;
-	if (pinf->p_flags & INPUT)
-		concat(call, in);
-	if (pinf->p_flags & OUTPUT)
-		append(call, out);
-	for (i = 0; i < MAXTAIL; i++) {
-		if (pass->pp_tail[i]) {
-			if (pass->pp_tail[i][0] == '-' &&
-			    pass->pp_tail[i][1] == 'l') {
-				append(call, library(&(pass->pp_tail[i][2])));
-			}
-			else if (*(pass->pp_tail[i]) != '*')
-				append(call, pass->pp_tail[i]);
-			else if (fp_lib)
-				append(call, library("fp"));
-		} else	break;
-	}
-	if (! runvec(call, pinf, (char *) 0, out)) {
-		cleanup(out);
-		RET_CODE = 1;
-	}
-}
-
-clean(c)
-	register struct arglist *c;
-{
-	register int i;
-
-	for (i = 1; i < c->al_argc; i++) {
-		free(c->al_argv[i]);
-		c->al_argv[i] = 0;
-	}
-	c->al_argc = 0;
-}
-
-scanflags(call, pinf)
-	struct arglist *call;
-	struct passinfo *pinf;
-{
-	/*	Find out which flags from FLAGS must be passed to pass "pinf",
-		and how. 
-		Append them to "call"
-	*/
-	register int i;
-	USTRING flg;
-
-	for (i = 0; i < FLAGS.al_argc; i++) {
-		register char *q = pinf->p_acceptflags;
-
-		while (*q)  {
-			register char *p = FLAGS.al_argv[i] + 1;
-
-			while (*q && *q == *p) {
-				q++; p++;
-			}
-			if (*q == ',' || !*q) {
-				if (! *p) {
-					/* append literally */
-					append(call, FLAGS.al_argv[i]);
-				}
-				break;
-			}
-			if (*q == '*') {
-				register char *s = flg;
-
-				if (*++q != '=') {
-					/* append literally */
-					append(call, FLAGS.al_argv[i]);
-					break;
-				}
-				*s++ = '-';
-				if (*q) q++;	/* skip ',' */
-				while (*q && *q != ',' && *q != '*') {
-					/* copy replacement flag */
-					*s++ = *q++;
-				}
-				if (*q == '*') {
-					/* copy rest */
-					while (*p) *s++ = *p++;
-				}
-				*s = 0;
-				append(call, flg);
-				break;
-			}
-			if (*q == '=') {
-				/* copy replacement */
-				register char *s = flg;
-
-				*s++ = '-';
-				q++;
-				while (*q && *q != ',') *s++ = *q++;
-				*s = 0;
-				append(call, flg);
-				break;
-			}
-			while (*q && *q++ != ',')
-				;
-		}
-	}
-}
Index: trunk/minix/commands/ibm/Makefile
===================================================================
--- trunk/minix/commands/ibm/Makefile	(revision 9)
+++ 	(revision )
@@ -1,183 +1,0 @@
-# Makefile for commands/ibm.
-
-# See commands/simple/Makefile for a description.
-
-CFLAGS	= -D_MINIX -D_POSIX_SOURCE
-CCLD	= $(CC) -i $(CFLAGS)
-MAKE	= exec make -$(MAKEFLAGS)
-CC = exec cc
-
-ALL	= \
-	atnormalize \
-	dosread \
-	fdisk \
-	format \
-	loadfont \
-	loadkeys \
-	mixer \
-	autopart \
-	part \
-	partition \
-	playwave \
-	postmort \
-	readclock \
-	recwave \
-	repartition \
-	screendump \
-	sdump \
-
-all:	$(ALL)
-
-dosread:	dosread.c
-	$(CCLD) -o $@ $?
-	install -S 16kw $@
-
-atnormalize:	atnormalize.c
-	$(CCLD) -o $@ $?
-	install -S 16kw $@
-
-fdisk:	fdisk.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-format:	format.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-loadfont:	loadfont.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-loadkeys:	loadkeys.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-mixer:	mixer.c
-	$(CCLD) -o $@ $? -lcurses
-	install -S 16kw $@
-
-autopart:	autopart.c
-	$(CCLD) -o $@ $?
-	install -S 11kw $@
-
-part:	part.c
-	$(CCLD) -o $@ $?
-	install -S 11kw $@
-
-partition:	partition.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-playwave:	playwave.c
-	$(CCLD) -o $@ $?
-	install -S 16kw $@
-
-postmort:	postmort.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-readclock:	readclock.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-recwave:	recwave.c
-	$(CCLD) -o $@ $?
-	install -S 16kw $@
-
-repartition:	repartition.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-screendump:	screendump.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-sdump:	sdump.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-install:	\
-	/usr/bin/atnormalize \
-	/usr/bin/dosread \
-		/usr/bin/dosdir \
-		/usr/bin/doswrite \
-	/usr/bin/fdisk \
-	/usr/bin/format \
-	/usr/bin/loadfont \
-	/usr/bin/loadkeys \
-	/usr/bin/mixer \
-	/usr/bin/autopart \
-	/usr/bin/part \
-	/usr/bin/partition \
-	/usr/bin/playwave \
-	/usr/bin/postmort \
-	/usr/bin/readclock \
-	/usr/bin/recwave \
-	/usr/bin/repartition \
-	/usr/bin/screendump \
-	/usr/bin/sdump \
-	/bin/loadkeys \
-	/bin/readclock \
-
-/usr/bin/atnormalize:	atnormalize
-	install -cs -o bin $? $@
-
-/usr/bin/dosread:	dosread
-	install -cs -o bin $? $@
-
-/usr/bin/dosdir /usr/bin/doswrite:	/usr/bin/dosread
-	install -l $? $@
-
-/usr/bin/fdisk:	fdisk
-	install -cs -o bin $? $@
-
-/usr/bin/format:	format
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/loadfont:	loadfont
-	install -cs -o bin $? $@
-
-/usr/bin/loadkeys:	loadkeys
-	install -cs -o bin $? $@
-
-/usr/bin/mixer:	mixer
-	install -cs -o bin $? $@
-
-/usr/bin/autopart:	autopart
-	install -lcs $? $@
-
-/usr/bin/part:	part
-	install -cs -o bin $? $@
-
-/usr/bin/partition:	partition
-	install -cs -o bin $? $@
-
-/usr/bin/playwave:	playwave
-	install -cs -o bin $? $@
-
-/usr/bin/postmort:	postmort
-	install -cs -o bin $? $@
-
-/usr/bin/readclock:	readclock
-	install -cs -o bin $? $@
-
-/usr/bin/recwave:	recwave
-	install -cs -o bin $? $@
-
-/usr/bin/repartition:	repartition
-	install -cs -o bin $? $@
-
-/usr/bin/screendump:	screendump
-	install -cs -o bin $? $@
-
-/usr/bin/sdump:	sdump
-	install -cs -o bin $? $@
-
-/bin/loadkeys:	/usr/bin/loadkeys
-	install -lcs $? $@
-
-/bin/readclock:	/usr/bin/readclock
-	install -lcs $? $@
-
-clean:
-	rm -rf $(ALL) a.out core
Index: trunk/minix/commands/ibm/atnormalize.c
===================================================================
--- trunk/minix/commands/ibm/atnormalize.c	(revision 9)
+++ 	(revision )
@@ -1,43 +1,0 @@
-#include <sys/types.h>
-#include <stdio.h>
-#include <termcap.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <time.h>
-#include <dirent.h>
-#include <limits.h>
-#include <a.out.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/ioctl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <termios.h>
-#include <stdarg.h>
-
-int main(void)
-{
-	int v, d;
-	char name[20];
-
-	for(d = 0; d < 4; d++) {
-		int device;
-		sprintf(name, "/dev/c0d%d", d);
-		if((device=open(name, O_RDONLY)) >= 0) {
-			v = 0;
-			ioctl(device, DIOCTIMEOUT, &v);
-			close(device);
-		}
-	}
-
-	return 0;
-}
Index: trunk/minix/commands/ibm/autopart.c
===================================================================
--- trunk/minix/commands/ibm/autopart.c	(revision 9)
+++ 	(revision )
@@ -1,2838 +1,0 @@
-/*	part 1.57 - Partition table editor		Author: Kees J. Bot
- *								13 Mar 1992
- * Needs about 22k heap+stack.
- *
- * Forked july 2005 into autopart (Ben Gras), a mode which gives the user
- * an easier time.
- *
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <termcap.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <time.h>
-#include <dirent.h>
-#include <limits.h>
-#include <a.out.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/ioctl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <termios.h>
-#include <stdarg.h>
-
-/* Declare prototype. */
-static void printstep(int step, char *message);
-
-/* True if a partition is an extended partition. */
-#define ext_part(s)	((s) == 0x05 || (s) == 0x0F)
-
-/* Minix master bootstrap code. */
-static char MASTERBOOT[] = "/usr/mdec/masterboot";
-
-/* Template:
-                      ----first----  --geom/last--  ------sectors-----
-    Device             Cyl Head Sec   Cyl Head Sec      Base      Size        Kb
-    /dev/c0d0                          977    5  17
-    /dev/c0d0:2          0    0   2   976    4  16         2     83043     41521
-Num Sort   Type
- 0* p0   81 MINIX        0    0   3    33    4   9         3      2880      1440
- 1  p1   81 MINIX       33    4  10   178    2   2      2883     12284      6142
- 2  p2   81 MINIX      178    2   3   976    4  16     15167     67878     33939
- 3  p3   00 None         0    0   0     0    0  -1         0         0         0
-
- */
-#define MAXSIZE		999999999L
-#define SECTOR_SIZE	512
-#define DEV_FD0		0x200		/* Device number of /dev/fd0 */
-#define DEV_C0D0	0x300		/* Device number of /dev/c0d0 */
-
-int min_region_mb = 500;
-
-#define MIN_REGION_SECTORS (1024*1024*min_region_mb/SECTOR_SIZE)
-
-#define MAX_REGION_MB	4095
-#define MAX_REGION_SECTORS (1024*(1024/SECTOR_SIZE)*MAX_REGION_MB)
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-#define SORNOT(n) ((n) == 1 ? "" : "s")
-
-/* screen colours */
-#define COL_RED		1
-#define COL_GREEN	2
-#define COL_ORANGE	3
-#define COL_BLUE	4
-#define COL_MAGENTA	5
-#define COL_CYAN	6
-
-#define SURE_SERIOUS	1
-#define SURE_BACK	2
-
-void col(int col)
-{
-	if(!col) printf("\033[0m");
-	else printf("\033[3%dm", col % 10);
-}
-
-void type2col(int type)
-{
-	switch(type) {
-		/* minix */
-		case 0x80:
-		case MINIX_PART:	col(COL_GREEN);	break;
-
-		/* dos/windows */
-		case 0x0B: case 0x0C: case 0x0E: case 0x0F: case 0x42:
-		case 0x07: 		col(COL_CYAN);		break;
-
-		/* linux */
-		case 0x82: case 0x83:	col(COL_ORANGE);	break;
-	}
-}
-
-int open_ct_ok(int fd)
-{
-	int c = -1;
-	if(ioctl(fd, DIOCOPENCT, &c) < 0) {
-		printf("Warning: couldn't verify opencount, continuing\n");
-		return 1;
-	}
-
-	if(c == 1) return 1;
-	if(c < 1) { printf("Error: open count %d\n", c); }
-
-	return 0;
-}
-
-void report(const char *label)
-{
-	fprintf(stderr, "part: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-struct termios termios;
-
-void save_ttyflags(void)
-/* Save tty attributes for later restoration. */
-{
-	if (tcgetattr(0, &termios) < 0) fatal("");
-}
-
-void restore_ttyflags(void)
-/* Reset the tty flags to how we got 'em. */
-{
-	if (tcsetattr(0, TCSANOW, &termios) < 0) fatal("");
-}
-
-void tty_raw(void)
-/* Set the terminal to raw mode, no signals, no echoing. */
-{
-	struct termios rawterm;
-
-	rawterm= termios;
-	rawterm.c_lflag &= ~(ICANON|ISIG|ECHO);
-	rawterm.c_iflag &= ~(ICRNL);
-	if (tcsetattr(0, TCSANOW, &rawterm) < 0) fatal("");
-}
-
-#define ctrl(c)		((c) == '?' ? '\177' : ((c) & '\37'))
-
-char t_cd[16], t_cm[32], t_so[16], t_se[16], t_md[16], t_me[16];
-int t_li, t_co;
-#define STATUSROW	10
-
-void init_tty(void)
-/* Get terminal capabilities and set the tty to "editor" mode. */
-{
-	char *term;
-	static char termbuf[1024];
-	char *tp;
-
-	if ((term= getenv("TERM")) == nil || tgetent(termbuf, term) != 1) {
-		fprintf(stderr, "part: Can't get terminal capabilities\n");
-		exit(1);
-	}
-	if (tgetstr("cd", (tp= t_cd, &tp)) == nil
-				|| tgetstr("cm", (tp= t_cm, &tp)) == nil) {
-		fprintf(stderr, "part: This terminal is too dumb\n");
-		exit(1);
-	}
-	t_li= tgetnum("li");
-	t_co= tgetnum("co");
-	(void) tgetstr("so", (tp= t_so, &tp));
-	(void) tgetstr("se", (tp= t_se, &tp));
-	(void) tgetstr("md", (tp= t_md, &tp));
-	(void) tgetstr("me", (tp= t_me, &tp));
-
-	save_ttyflags();
-	tty_raw();
-}
-
-void putchr(int c)
-{
-	putchar(c);
-}
-
-void putstr(char *s)
-{
-	int c;
-
-	while ((c= *s++) != 0) putchr(c);
-}
-
-void set_cursor(int row, int col)
-{
-	tputs(tgoto(t_cm, col, row), 1, putchr);
-}
-
-int statusrow= STATUSROW;
-int stat_ktl= 1;
-int need_help= 1;
-
-void stat_start(int serious)
-/* Prepare for printing on a fresh status line, possibly highlighted. */
-{
-	set_cursor(statusrow++, 0);
-	tputs(t_cd, 1, putchr);
-	if (serious) tputs(t_so, 1, putchr);
-}
-
-void stat_end(int ktl)
-/* Closing bracket for stat_start.  Sets "keystrokes to live" of message. */
-{
-	tputs(t_se, 1, putchr);
-	stat_ktl= ktl;
-	need_help= 1;
-}
-
-void stat_reset(void)
-/* Reset the statusline pointer and clear old messages if expired. */
-{
-	if (stat_ktl > 0 && --stat_ktl == 0) {
-		statusrow= STATUSROW;
-		need_help= 1;
-	}
-	if (need_help && statusrow < (24-2)) {
-		if (statusrow > STATUSROW) stat_start(0);
-		stat_start(0);
-		putstr(
-"Type '+' or '-' to change, 'r' to read, '?' for more help, '!' for advice");
-	}
-	statusrow= STATUSROW;
-	need_help= 0;
-}
-
-void clear_screen(void)
-{
-	set_cursor(0, 0);
-	tputs(t_cd, 1, putchr);
-	stat_ktl= 1;
-	stat_reset();
-}
-
-void reset_tty(void)
-/* Reset the tty to cooked mode. */
-{
-	restore_ttyflags();
-	set_cursor(statusrow, 0);
-	tputs(t_cd, 1, putchr);
-}
-
-void *alloc(size_t n)
-{
-	void *m;
-
-	if ((m= malloc(n)) == nil) { reset_tty(); fatal(""); }
-
-	return m;
-}
-
-#ifndef makedev		/* Missing in sys/types.h */
-#define minor(dev)	(((dev) >> MINOR) & BYTE)
-#define major(dev)	(((dev) >> MAJOR) & BYTE)
-#define makedev(major, minor)	\
-			((dev_t) (((major) << MAJOR) | ((minor) << MINOR)))
-#endif
-
-typedef enum parttype { DUNNO, SUBPART, PRIMARY, FLOPPY } parttype_t;
-
-typedef struct device {
-	struct device *next, *prev;	/* Circular dequeue. */
-	dev_t	rdev;			/* Device number (sorting only). */
-	char	*name;			/* E.g. /dev/c0d0 */
-	char	*subname;		/* E.g. /dev/c0d0:2 */
-	parttype_t parttype;
-	int biosdrive;
-} device_t;
-
-typedef struct region {
-	/* A region is either an existing top-level partition
-	 * entry (used_part is non-NULL) or free space (free_*
-	 * contains data).
-	 */
-	struct part_entry used_part;
-	int is_used_part;
-	int tableno;
-	int free_sec_start, free_sec_last;
-} region_t;
-
-/* A disk has between 1 and 2*partitions+1 regions;
- * the last case is free space before and after every partition.
- */
-#define NR_REGIONS (2*NR_PARTITIONS+1)
-region_t regions[NR_REGIONS];
-int nr_partitions = 0, nr_regions = 0, free_regions, used_regions;
-int nordonly = 0;
-
-device_t *firstdev= nil, *curdev;
-
-#define MAX_DEVICES 100
-	static struct {
-		device_t *dev;
-		int nr_partitions, free_regions, used_regions, sectors, nr_regions;
-		int biosdrive;
-		region_t regions[NR_REGIONS];
-	} devices[MAX_DEVICES];
-
-void newdevice(char *name, int scanning, int disk_only)
-/* Add a device to the device list.  If scanning is set then we are reading
- * /dev, so insert the device in device number order and make /dev/c0d0 current.
- */
-{
-	device_t *new, *nextdev, *prevdev;
-	struct stat st;
-
-	st.st_rdev= 0;
-	if (scanning) {
-		if (stat(name, &st) < 0 || !S_ISBLK(st.st_mode)) return;
-
-		switch (major(st.st_rdev)) {
-		case 3:
-			/* Disk controller */
-			if (minor(st.st_rdev) >= 0x80
-					|| minor(st.st_rdev) % 5 != 0) return;
-			break;
-		default:
-			return;
-		}
-		/* Interesting device found. */
-	} else {
-		if(stat(name, &st) < 0) { perror(name); return; }
-	}
-
-	new= alloc(sizeof(*new));
-	new->rdev= st.st_rdev;
-	new->name= alloc((strlen(name) + 1) * sizeof(new->name[0]));
-	strcpy(new->name, name);
-	new->subname= new->name;
-	new->parttype= DUNNO;
-	if (major(st.st_rdev) == major(DEV_FD0) && minor(st.st_rdev) < 112) {
-		new->parttype= FLOPPY;
-	} else
-	if (st.st_rdev >= DEV_C0D0 && minor(st.st_rdev) < 128
-			&& minor(st.st_rdev) % 5 == 0) {
-		new->parttype= PRIMARY;
-	}
-
-	if (firstdev == nil) {
-		firstdev= new;
-		new->next= new->prev= new;
-		curdev= firstdev;
-		return;
-	}
-	nextdev= firstdev;
-	while (new->rdev >= nextdev->rdev
-				&& (nextdev= nextdev->next) != firstdev) {}
-	prevdev= nextdev->prev;
-	new->next= nextdev;
-	nextdev->prev= new;
-	new->prev= prevdev;
-	prevdev->next= new;
-
-	if (new->rdev < firstdev->rdev) firstdev= new;
-	if (new->rdev == DEV_C0D0) curdev= new;
-	if (curdev->rdev != DEV_C0D0) curdev= firstdev;
-}
-
-void getdevices(int disk_only)
-/* Get all block devices from /dev that look interesting. */
-{
-	DIR *d;
-	struct dirent *e;
-	char name[5 + NAME_MAX + 1];
-
-	if ((d= opendir("/dev")) == nil) fatal("/dev");
-
-	while ((e= readdir(d)) != nil) {
-		strcpy(name, "/dev/");
-		strcpy(name + 5, e->d_name);
-		newdevice(name, 1, disk_only);
-	}
-	(void) closedir(d);
-}
-
-/* One featureful master bootstrap. */
-unsigned char bootstrap[] = {
-0353,0001,0000,0061,0300,0216,0330,0216,0300,0372,0216,0320,0274,0000,0174,0373,
-0275,0276,0007,0211,0346,0126,0277,0000,0006,0271,0000,0001,0374,0363,0245,0352,
-0044,0006,0000,0000,0264,0002,0315,0026,0250,0010,0164,0033,0350,0071,0001,0174,
-0007,0060,0344,0315,0026,0242,0205,0007,0054,0060,0074,0012,0163,0363,0120,0350,
-0046,0001,0205,0007,0130,0353,0012,0240,0002,0006,0204,0300,0165,0003,0351,0147,
-0000,0230,0262,0005,0366,0362,0262,0200,0000,0302,0210,0340,0120,0350,0234,0000,
-0163,0003,0351,0147,0000,0130,0054,0001,0175,0003,0351,0141,0000,0276,0276,0175,
-0211,0357,0271,0040,0000,0363,0245,0200,0301,0004,0211,0356,0215,0174,0020,0070,
-0154,0004,0164,0016,0213,0135,0010,0053,0134,0010,0213,0135,0012,0033,0134,0012,
-0163,0014,0212,0044,0206,0144,0020,0210,0044,0106,0071,0376,0162,0364,0211,0376,
-0201,0376,0356,0007,0162,0326,0342,0322,0211,0356,0264,0020,0366,0344,0001,0306,
-0200,0174,0004,0001,0162,0026,0353,0021,0204,0322,0175,0041,0211,0356,0200,0174,
-0004,0000,0164,0013,0366,0004,0200,0164,0006,0350,0070,0000,0162,0053,0303,0203,
-0306,0020,0201,0376,0376,0007,0162,0346,0350,0215,0000,0211,0007,0376,0302,0204,
-0322,0174,0023,0315,0021,0321,0340,0321,0340,0200,0344,0003,0070,0342,0167,0355,
-0350,0011,0000,0162,0350,0303,0350,0003,0000,0162,0146,0303,0211,0356,0214,0134,
-0010,0214,0134,0012,0277,0003,0000,0122,0006,0127,0264,0010,0315,0023,0137,0007,
-0200,0341,0077,0376,0306,0210,0310,0366,0346,0211,0303,0213,0104,0010,0213,0124,
-0012,0367,0363,0222,0210,0325,0366,0361,0060,0322,0321,0352,0321,0352,0010,0342,
-0210,0321,0376,0301,0132,0210,0306,0273,0000,0174,0270,0001,0002,0315,0023,0163,
-0020,0200,0374,0200,0164,0011,0117,0174,0006,0060,0344,0315,0023,0163,0270,0371,
-0303,0201,0076,0376,0175,0125,0252,0165,0001,0303,0350,0013,0000,0243,0007,0353,
-0005,0350,0004,0000,0227,0007,0353,0376,0136,0255,0126,0211,0306,0254,0204,0300,
-0164,0011,0264,0016,0273,0001,0000,0315,0020,0353,0362,0303,0057,0144,0145,0166,
-0057,0150,0144,0077,0010,0000,0015,0012,0000,0116,0157,0156,0145,0040,0141,0143,
-0164,0151,0166,0145,0015,0012,0000,0122,0145,0141,0144,0040,0145,0162,0162,0157,
-0162,0040,0000,0116,0157,0164,0040,0142,0157,0157,0164,0141,0142,0154,0145,0040,
-0000,0000,
-};
-
-int dirty= 0;
-unsigned char bootblock[SECTOR_SIZE];
-struct part_entry table[1 + NR_PARTITIONS];
-int existing[1 + NR_PARTITIONS];
-unsigned long offset= 0, extbase= 0, extsize;
-int submerged= 0;
-char sort_index[1 + NR_PARTITIONS], sort_order[1 + NR_PARTITIONS];
-unsigned cylinders= 1, heads= 1, sectors= 1, secpcyl= 1;
-unsigned alt_cyls= 1, alt_heads= 1, alt_secs= 1;
-int precise= 0;
-int device= -1;
-
-unsigned long sortbase(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? -1 : pe->lowsec;
-}
-
-void sort(void)
-/* Let the sort_index array show the order partitions are sorted in. */
-{
-	int i, j;
-
-	for (i= 1; i <= NR_PARTITIONS; i++) sort_order[i]= i;
-
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		for (j= 1; j <= NR_PARTITIONS-1; j++) {
-			int sj= sort_order[j], sj1= sort_order[j+1];
-
-			if (sortbase(&table[sj]) > sortbase(&table[sj1])) {
-				sort_order[j]= sj1;
-				sort_order[j+1]= sj;
-			}
-		}
-	}
-	for (i= 1; i <= NR_PARTITIONS; i++) sort_index[sort_order[i]]= i;
-}
-
-void dos2chs(unsigned char *dos, unsigned *chs)
-/* Extract cylinder, head and sector from the three bytes DOS uses to address
- * a sector.  Note that bits 8 & 9 of the cylinder number come from bit 6 & 7
- * of the sector byte.  The sector number is rebased to count from 0.
- */
-{
-	chs[0]= ((dos[1] & 0xC0) << 2) | dos[2];
-	chs[1]= dos[0];
-	chs[2]= (dos[1] & 0x3F) - 1;
-}
-
-void abs2dos(unsigned char *dos, unsigned long pos)
-/* Translate a sector offset to three DOS bytes. */
-{
-	unsigned h, c, s;
-
-	c= pos / secpcyl;
-	h= (pos % secpcyl) / sectors;
-	s= pos % sectors + 1;
-
-	dos[0]= h;
-	dos[1]= s | ((c >> 2) & 0xC0);
-	dos[2]= c & 0xFF;
-}
-
-void recompute0(void)
-/* Recompute the partition size for the device after a geometry change. */
-{
-	if (device < 0) {
-		cylinders= heads= sectors= 1;
-		memset(table, 0, sizeof(table));
-	} else
-	if (!precise && offset == 0) {
-		table[0].lowsec= 0;
-		table[0].size= (unsigned long) cylinders * heads * sectors;
-	}
-	table[0].sysind= device < 0 ? NO_PART : MINIX_PART;
-	secpcyl= heads * sectors;
-}
-
-void guess_geometry(void)
-/* With a bit of work one can deduce the disk geometry from the partition
- * table.  This may be necessary if the driver gets it wrong.  (If partition
- * tables didn't have C/H/S numbers we would not care at all...)
- */
-{
-	int i, n;
-	struct part_entry *pe;
-	unsigned chs[3];
-	unsigned long sec;
-	unsigned h, s;
-	unsigned char HS[256][8];	/* Bit map off all possible H/S */
-
-	alt_cyls= alt_heads= alt_secs= 0;
-
-	/* Initially all possible H/S combinations are possible.  HS[h][0]
-	 * bit 0 is used to rule out a head value.
-	 */
-	for (h= 1; h <= 255; h++) {
-		for (s= 0; s < 8; s++) HS[h][s]= 0xFF;
-	}
-
-	for (i= 0; i < 2*NR_PARTITIONS; i++) {
-		pe= &(table+1)[i >> 1];
-		if (pe->sysind == NO_PART) continue;
-
-		/* Get the end or start sector numbers (in that order). */
-		if ((i & 1) == 0) {
-			dos2chs(&pe->last_head, chs);
-			sec= pe->lowsec + pe->size - 1;
-		} else {
-			dos2chs(&pe->start_head, chs);
-			sec= pe->lowsec;
-		}
-
-		if (chs[0] >= alt_cyls) alt_cyls= chs[0]+1;
-
-		/* Which H/S combinations can be ruled out? */
-		for (h= 1; h <= 255; h++) {
-			if (HS[h][0] == 0) continue;
-			n = 0;
-			for (s= 1; s <= 63; s++) {
-				if ((chs[0] * h + chs[1]) * s + chs[2] != sec) {
-					HS[h][s/8] &= ~(1 << (s%8));
-				}
-				if (HS[h][s/8] & (1 << (s%8))) n++;
-			}
-			if (n == 0) HS[h][0]= 0;
-		}
-	}
-
-	/* See if only one remains. */
-	i= 0;
-	for (h= 1; h <= 255; h++) {
-		if (HS[h][0] == 0) continue;
-		for (s= 1; s <= 63; s++) {
-			if (HS[h][s/8] & (1 << (s%8))) {
-				i++;
-				alt_heads= h;
-				alt_secs= s;
-			}
-		}
-	}
-
-	/* Forget it if more than one choice... */
-	if (i > 1) alt_cyls= alt_heads= alt_secs= 0;
-}
-
-void geometry(void)
-/* Find out the geometry of the device by querying the driver, or by looking
- * at the partition table.  These numbers are crosschecked to make sure that
- * the geometry is correct.  Master bootstraps other than the Minix one use
- * the CHS numbers in the partition table to load the bootstrap of the active
- * partition.
- */
-{
-	struct stat dst;
-	int err= 0;
-	struct partition geometry;
-
-	if (submerged) {
-		/* Geometry already known. */
-		sort();
-		return;
-	}
-	precise= 0;
-	cylinders= 0;
-	recompute0();
-	if (device < 0) return;
-
-	/* Try to guess the geometry from the partition table. */
-	guess_geometry();
-
-	/* Try to get the geometry from the driver. */
-	(void) fstat(device, &dst);
-
-	if (S_ISBLK(dst.st_mode) || S_ISCHR(dst.st_mode)) {
-		/* Try to get the drive's geometry from the driver. */
-
-		if (ioctl(device, DIOCGETP, &geometry) < 0)
-			err= errno;
-		else {
-			table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
-			table[0].size= div64u(geometry.size, SECTOR_SIZE);
-			cylinders= geometry.cylinders;
-			heads= geometry.heads;
-			sectors= geometry.sectors;
-			precise= 1;
-		}
-	} else {
-		err= ENODEV;
-	}
-
-	if (err != 0) {
-		/* Getting the geometry from the driver failed, so use the
-		 * alternate geometry.
-		 */
-		if (alt_heads == 0) {
-			alt_cyls= table[0].size / (64 * 32);
-			alt_heads= 64;
-			alt_secs= 32;
-		}
-
-		cylinders= alt_cyls;
-		heads= alt_heads;
-		sectors= alt_secs;
-
-		stat_start(1);
-		printf("Failure to get the geometry of %s: %s", curdev->name,
-			errno == ENOTTY ? "No driver support" : strerror(err));
-		stat_end(5);
-		stat_start(0);
-		printf("The geometry has been guessed as %ux%ux%u",
-						cylinders, heads, sectors);
-		stat_end(5);
-	} else {
-		if (alt_heads == 0) {
-			alt_cyls= cylinders;
-			alt_heads= heads;
-			alt_secs= sectors;
-		}
-
-		if (heads != alt_heads || sectors != alt_secs) {
-printf(
-"The %ux%ux%u geometry obtained from the driver\n"
-"does not match the %ux%ux%u geometry implied by the partition\n"
-"table. Please use expert mode instead.\n");
-exit(1);
-		}
-	}
-
-	/* Show the base and size of the device instead of the whole drive.
-	 * This makes sense for subpartitioning primary partitions.
-	 */
-	if (precise && ioctl(device, DIOCGETP, &geometry) >= 0) {
-		table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
-		table[0].size= div64u(geometry.size, SECTOR_SIZE);
-	} else {
-		precise= 0;
-	}
-	recompute0();
-	sort();
-}
-
-typedef struct indicators {	/* Partition type to partition name. */
-	unsigned char	ind;
-	char		name[10];
-} indicators_t;
-
-indicators_t ind_table[]= {
-	{ 0x00,		"None"		},
-	{ 0x01,		"FAT-12"	},
-	{ 0x02,		"XENIX /"	},
-	{ 0x03,		"XENIX usr"	},
-	{ 0x04,		"FAT-16"	},
-	{ 0x05,		"EXTENDED"	},
-	{ 0x06,		"FAT-16"	},
-	{ 0x07,		"HPFS/NTFS"	},
-	{ 0x08,		"AIX"		},
-	{ 0x09,		"COHERENT"	},
-	{ 0x0A,		"OS/2"		},
-	{ 0x0B,		"FAT-32"	},
-	{ 0x0C,		"FAT?"		},
-	{ 0x0E,		"FAT?"		},
-	{ 0x0F,		"EXTENDED"	},
-	{ 0x10,		"OPUS"		},
-	{ 0x40,		"VENIX286"	},
-	{ 0x42,		"W2000 Dyn"	},
-	{ 0x52,		"MICROPORT"	},
-	{ 0x63,		"386/IX"	},
-	{ 0x64,		"NOVELL286"	},
-	{ 0x65,		"NOVELL386"	},
-	{ 0x75,		"PC/IX"		},
-	{ 0x80,		"MINIX-OLD"	},
-	{ 0x81,		"MINIX"		},
-	{ 0x82,		"LINUXswap"	},
-	{ 0x83,		"LINUX"		},
-	{ 0x93,		"AMOEBA"	},
-	{ 0x94,		"AMOEBAbad"	},
-	{ 0xA5,		"386BSD"	},
-	{ 0xB7,		"BSDI"		},
-	{ 0xB8,		"BSDI swap"	},
-	{ 0xC7,		"SYRINX"	},
-	{ 0xDB,		"CPM"		},
-	{ 0xFF,		"BADBLOCKS"	},
-};
-
-char *typ2txt(int ind)
-/* Translate a numeric partition indicator for human eyes. */
-{
-	indicators_t *pind;
-
-	for (pind= ind_table; pind < arraylimit(ind_table); pind++) {
-		if (pind->ind == ind) return pind->name;
-	}
-	return "unknown system";
-}
-
-int round_sysind(int ind, int delta)
-/* Find the next known partition type starting with ind in direction delta. */
-{
-	indicators_t *pind;
-
-	ind= (ind + delta) & 0xFF;
-
-	if (delta < 0) {
-		for (pind= arraylimit(ind_table)-1; pind->ind > ind; pind--) {}
-	} else {
-		for (pind= ind_table; pind->ind < ind; pind++) {}
-	}
-	return pind->ind;
-}
-
-/* Objects on the screen, either simple pieces of the text or the cylinder
- * number of the start of partition three.
- */
-typedef enum objtype {
-	O_INFO, O_TEXT, O_DEV, O_SUB,
-	O_TYPTXT, O_SORT, O_NUM, O_TYPHEX,
-	O_CYL, O_HEAD, O_SEC,
-	O_SCYL, O_SHEAD, O_SSEC, O_LCYL, O_LHEAD, O_LSEC, O_BASE, O_SIZE, O_KB
-} objtype_t;
-
-#define rjust(type)	((type) >= O_TYPHEX)
-#define computed(type)	((type) >= O_TYPTXT)
-
-typedef struct object {
-	struct object	*next;
-	objtype_t	type;		/* Text field, cylinder number, etc. */
-	char		flags;		/* Modifiable? */
-	char		row;
-	char		col;
-	char		len;
-	struct part_entry *entry;	/* What does the object refer to? */
-	char		  *text;
-	char		value[20];	/* Value when printed. */
-} object_t;
-
-#define OF_MOD		0x01	/* Object value is modifiable. */
-#define OF_ODD		0x02	/* It has a somewhat odd value. */
-#define OF_BAD		0x04	/* Its value is no good at all. */
-
-/* Events: (Keypress events are the value of the key pressed.) */
-#define E_ENTER		(-1)	/* Cursor moves onto object. */
-#define E_LEAVE		(-2)	/* Cursor leaves object. */
-#define E_WRITE		(-3)	/* Write, but not by typing 'w'. */
-
-/* The O_SIZE objects have a dual identity. */
-enum howend { SIZE, LAST } howend= SIZE;
-
-object_t *world= nil;
-object_t *curobj= nil;
-
-object_t *newobject(objtype_t type, int flags, int row, int col, int len)
-/* Make a new object given a type, flags, position and length on the screen. */
-{
-	object_t *new;
-	object_t **aop= &world;
-
-	new= alloc(sizeof(*new));
-
-	new->type= type;
-	new->flags= flags;
-	new->row= row;
-	new->col= col;
-	new->len= len;
-	new->entry= nil;
-	new->text= "";
-	new->value[0]= 0;
-
-	new->next= *aop;
-	*aop= new;
-
-	return new;
-}
-
-unsigned long entry2base(struct part_entry *pe)
-/* Return the base sector of the partition if defined. */
-{
-	return pe->sysind == NO_PART ? 0 : pe->lowsec;
-}
-
-unsigned long entry2last(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? -1 : pe->lowsec + pe->size - 1;
-}
-
-unsigned long entry2size(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? 0 : pe->size;
-}
-
-int overlap(unsigned long sec)
-/* See if sec is part of another partition. */
-{
-	struct part_entry *pe;
-
-	for (pe= table + 1; pe <= table + NR_PARTITIONS; pe++) {
-		if (pe->sysind == NO_PART) continue;
-
-		if (pe->lowsec < sec && sec < pe->lowsec + pe->size)
-			return 1;
-	}
-	return 0;
-}
-
-int aligned(unsigned long sec, unsigned unit)
-/* True if sec is aligned to unit or if it is no problem if it is unaligned. */
-{
-	return (offset != 0 && extbase == 0) || (sec % unit == 0);
-}
-
-void print(object_t *op)
-/* Print an object's value if it changed. */
-{
-	struct part_entry *pe= op->entry;
-	int n;
-	unsigned long t;
-	char *name;
-	int oldflags;
-	char oldvalue[20];
-
-	/* Remember the old flags and value. */
-	oldflags= op->flags;
-	strcpy(oldvalue, op->value);
-
-	op->flags&= ~(OF_ODD | OF_BAD);
-
-	switch (op->type) {
-	case O_INFO:		{
-				/* Current field. */
-		static struct field { int type; char *name; } fields[]= {
-			{ O_DEV,	"Select device"		},
-			{ O_NUM,	"Active flag"		},
-			{ O_TYPHEX,	"Hex partition type"	},
-			{ O_TYPTXT,	"Partition type"	},
-			{ O_SCYL,	"Start cylinder"	},
-			{ O_SHEAD,	"Start head"		},
-			{ O_SSEC,	"Start sector"		},
-			{ O_CYL,	"Number of cylinders"	},
-			{ O_HEAD,	"Number of heads"	},
-			{ O_SEC,	"Sectors per track"	},
-			{ O_LCYL,	"Last cylinder"		},
-			{ O_LHEAD,	"Last head"		},
-			{ O_LSEC,	"Last sector"		},
-			{ O_BASE,	"Base sector"		},
-			{ O_SIZE,	"Size in sectors"	},
-			{ O_KB,		"Size in kilobytes"	},
-			{ -1,		"?"			},
-		};
-		struct field *fp= fields;
-
-		while (fp->type >= 0 && fp->type != curobj->type) fp++;
-		strcpy(op->value, fp->name);
-		op->flags|= OF_ODD;
-		break;		}
-	case O_TEXT:
-				/* Simple text field. */
-		strcpy(op->value, op->text);
-		break;
-	case O_DEV:
-	case O_SUB:
-				/* Name of currently edited device. */
-		name= op->type == O_DEV ? curdev->name :
-					offset == 0 ? "" : curdev->subname;
-		if ((n= strlen(name)) < op->len) n= op->len;
-		strcpy(op->value, name + (n - op->len));
-		if (device < 0 && op->type == O_DEV) op->flags|= OF_BAD;
-		break;
-	case O_NUM:
-				/* Position and active flag. */
-		sprintf(op->value, "%d%c", (int) (pe - table - 1),
-					pe->bootind & ACTIVE_FLAG ? '*' : ' ');
-		break;
-	case O_SORT:
-				/* Position if the driver sorts the table. */
-		sprintf(op->value, "%s%d",
-			curdev->parttype >= PRIMARY ? "p" :
-				curdev->parttype == SUBPART ? "s" : "",
-			(curdev->parttype == SUBPART ||
-				curdev->parttype == FLOPPY ? pe - table
-					: sort_index[pe - table]) - 1);
-		break;
-	case O_TYPHEX:
-				/* Hex partition type indicator. */
-		sprintf(op->value, "%02X", pe->sysind);
-		break;
-	case O_TYPTXT:
-				/* Ascii partition type indicator. */
-		strcpy(op->value, typ2txt(pe->sysind));
-		break;
-	case O_SCYL:
-				/* Partition's start cylinder. */
-		sprintf(op->value, "%lu", entry2base(pe) / secpcyl);
-		break;
-	case O_SHEAD:
-				/* Start head. */
-		t= entry2base(pe);
-		sprintf(op->value, "%lu", t % secpcyl / sectors);
-		if (!aligned(t, secpcyl) && t != table[0].lowsec + sectors)
-			op->flags|= OF_ODD;
-		break;
-	case O_SSEC:
-				/* Start sector. */
-		t= entry2base(pe);
-		sprintf(op->value, "%lu", t % sectors);
-		if (!aligned(t, sectors)) op->flags|= OF_ODD;
-		break;
-	case O_CYL:
-				/* Number of cylinders. */
-		sprintf(op->value, "%u", cylinders);
-		break;
-	case O_HEAD:
-				/* Number of heads. */
-		sprintf(op->value, "%u", heads);
-		break;
-	case O_SEC:
-				/* Number of sectors per track. */
-		sprintf(op->value, "%u", sectors);
-		break;
-	case O_LCYL:
-				/* Partition's last cylinder. */
-		t= entry2last(pe);
-		sprintf(op->value, "%lu", t == -1 ? 0 : t / secpcyl);
-		break;
-	case O_LHEAD:
-				/* Partition's last head. */
-		t= entry2last(pe);
-		sprintf(op->value, "%lu", t == -1 ? 0 : t % secpcyl / sectors);
-		if (!aligned(t + 1, secpcyl)) op->flags|= OF_ODD;
-		break;
-	case O_LSEC:
-				/* Partition's last sector. */
-		t= entry2last(pe);
-		sprintf(op->value, t == -1 ? "-1" : "%lu", t % sectors);
-		if (!aligned(t + 1, sectors)) op->flags|= OF_ODD;
-		break;
-	case O_BASE:
-				/* Partition's base sector. */
-		sprintf(op->value, "%lu", entry2base(pe));
-		if (pe->sysind != NO_PART && pe != &table[0]
-		   && (pe->lowsec <= table[0].lowsec || overlap(pe->lowsec)))
-			op->flags|= OF_BAD;
-		break;
-	case O_SIZE:
-				/* Size of partitition in sectors. */
-		t= howend == SIZE ? entry2size(pe) : entry2last(pe);
-		sprintf(op->value, "%lu", pe->sysind == NO_PART ? 0 : t);
-		if (pe->sysind != NO_PART && (pe->size == 0
-		    || pe->lowsec + pe->size > table[0].lowsec + table[0].size
-		    || overlap(pe->lowsec + pe->size)))
-			op->flags|= OF_BAD;
-		break;
-	case O_KB:
-				/* Size of partitition in kilobytes. */
-		sprintf(op->value, "%lu", entry2size(pe) / 2);
-		break;
-	default:
-		sprintf(op->value, "?? %d ??", op->type);
-	}
-
-	if (device < 0 && computed(op->type)) strcpy(op->value, "?");
-
-	/* If a value overflows the print field then show a blank
-	 * reverse video field.
-	 */
-	if ((n= strlen(op->value)) > op->len) {
-		n= 0;
-		op->flags|= OF_BAD;
-	}
-
-	/* Right or left justified? */
-	if (rjust(op->type)) {
-		memmove(op->value + (op->len - n), op->value, n);
-		memset(op->value, ' ', op->len - n);
-	} else {
-		memset(op->value + n, ' ', op->len - n);
-	}
-	op->value[op->len]= 0;
-
-	if ((op->flags & (OF_ODD | OF_BAD)) == (oldflags & (OF_ODD | OF_BAD))
-				&& strcmp(op->value, oldvalue) == 0) {
-		/* The value did not change. */
-		return;
-	}
-
-	set_cursor(op->row, rjust(op->type) ? op->col - (op->len-1) : op->col);
-
-	if (op->flags & OF_BAD) tputs(t_so, 1, putchr);
-	else
-	if (op->flags & OF_ODD) tputs(t_md, 1, putchr);
-	putstr(op->value);
-	if (op->flags & OF_BAD) tputs(t_se, 1, putchr);
-	else
-	if (op->flags & OF_ODD) tputs(t_me, 1, putchr);
-}
-
-void display(void)
-/* Repaint all objects that changed. */
-{
-	object_t *op;
-
-	for (op= world; op != nil; op= op->next) print(op);
-}
-
-int typing;	/* Set if a digit has been typed to set a value. */
-int magic;	/* Changes when using the magic key. */
-
-void event(int ev, object_t *op);
-
-void m_redraw(int ev, object_t *op)
-/* Redraw the screen. */
-{
-	object_t *op2;
-
-	if (ev != ctrl('L')) return;
-
-	clear_screen();
-	for (op2= world; op2 != nil; op2= op2->next) op2->value[0]= 0;
-}
-
-void m_toggle(int ev, object_t *op)
-/* Toggle between the driver and alternate geometry. */
-{
-	unsigned t;
-
-	if (ev != 'X') return;
-	if (alt_cyls == cylinders && alt_heads == heads && alt_secs == sectors)
-		return;
-
-	t= cylinders; cylinders= alt_cyls; alt_cyls= t;
-	t= heads; heads= alt_heads; alt_heads= t;
-	t= sectors; sectors= alt_secs; alt_secs= t;
-	dirty= 1;
-	recompute0();
-}
-
-char size_last[]= "Size";
-
-void m_orientation(int ev, object_t *op)
-{
-	if (ev != ' ') return;
-
-	switch (howend) {
-	case SIZE:
-		howend= LAST;
-		strcpy(size_last, "Last");
-		break;
-	case LAST:
-		howend= SIZE;
-		strcpy(size_last, "Size");
-	}
-}
-
-void m_move(int ev, object_t *op)
-/* Move to the nearest modifiably object in the intended direction.  Objects
- * on the same row or column are really near.
- */
-{
-	object_t *near, *op2;
-	unsigned dist, d2, dr, dc;
-
-	if (ev != 'h' && ev != 'j' && ev != 'k' && ev != 'l' && ev != 'H')
-		return;
-
-	if (device < 0) {
-		/* No device open?  Then try to read first. */
-		event('r', op);
-		if (device < 0) return;
-	}
-
-	near= op;
-	dist= -1;
-
-	for (op2= world; op2 != nil; op2= op2->next) {
-		if (op2 == op || !(op2->flags & OF_MOD)) continue;
-
-		dr= abs(op2->row - op->row);
-		dc= abs(op2->col - op->col);
-
-		d2= 25*dr*dr + dc*dc;
-		if (op2->row != op->row && op2->col != op->col) d2+= 1000;
-
-		switch (ev) {
-		case 'h':	/* Left */
-			if (op2->col >= op->col) d2= -1;
-			break;
-		case 'j':	/* Down */
-			if (op2->row <= op->row) d2= -1;
-			break;
-		case 'k':	/* Up */
-			if (op2->row >= op->row) d2= -1;
-			break;
-		case 'l':	/* Right */
-			if (op2->col <= op->col) d2= -1;
-			break;
-		case 'H':	/* Home */
-			if (op2->type == O_DEV) d2= 0;
-		}
-		if (d2 < dist) { near= op2; dist= d2; }
-	}
-	if (near != op) event(E_LEAVE, op);
-	event(E_ENTER, near);
-}
-
-void m_updown(int ev, object_t *op)
-/* Move a partition table entry up or down. */
-{
-	int i, j;
-	struct part_entry tmp;
-	int tmpx;
-
-	if (ev != ctrl('K') && ev != ctrl('J')) return;
-	if (op->entry == nil) return;
-
-	i= op->entry - table;
-	if (ev == ctrl('K')) {
-		if (i <= 1) return;
-		j= i-1;
-	} else {
-		if (i >= NR_PARTITIONS) return;
-		j= i+1;
-	}
-
-	tmp= table[i]; table[i]= table[j]; table[j]= tmp;
-	tmpx= existing[i]; existing[i]= existing[j]; existing[j]= tmpx;
-	sort();
-	dirty= 1;
-	event(ev == ctrl('K') ? 'k' : 'j', op);
-}
-
-void m_enter(int ev, object_t *op)
-/* We've moved onto this object. */
-{
-	if (ev != E_ENTER && ev != ' ' && ev != '<' && ev != '>' && ev != 'X')
-		return;
-	curobj= op;
-	typing= 0;
-	magic= 0;
-}
-
-void m_leave(int ev, object_t *op)
-/* About to leave this object. */
-{
-	if (ev != E_LEAVE) return;
-}
-
-int within(unsigned *var, unsigned low, unsigned value, unsigned high)
-/* Only set *var to value if it looks reasonable. */
-{
-	if (low <= value && value <= high) {
-		*var= value;
-		return 1;
-	} else
-		return 0;
-}
-
-int lwithin(unsigned long *var, unsigned long low, unsigned long value,
-							unsigned long high)
-{
-	if (low <= value && value <= high) {
-		*var= value;
-		return 1;
-	} else
-		return 0;
-}
-
-int nextdevice(object_t *op, int delta)
-/* Select the next or previous device from the device list. */
-{
-	dev_t rdev;
-
-	if (offset != 0) return 0;
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return 0;
-
-	if (device >= 0) {
-		(void) close(device);
-		device= -1;
-	}
-	recompute0();
-
-	rdev= curdev->rdev;
-	if (delta < 0) {
-		do
-			curdev= curdev->prev;
-		while (delta < -1 && major(curdev->rdev) == major(rdev)
-			&& curdev->rdev < rdev);
-	} else {
-		do
-			curdev= curdev->next;
-		while (delta > 1 && major(curdev->rdev) == major(rdev)
-			&& curdev->rdev > rdev);
-	}
-	return 1;
-}
-
-void check_ind(struct part_entry *pe)
-/* If there are no other partitions then make this new one active. */
-{
-	struct part_entry *pe2;
-	int i = 0;
-
-	for (pe2= table + 1; pe2 < table + 1 + NR_PARTITIONS; pe2++, i++)
-		if (pe2->sysind != NO_PART && (pe2->bootind & ACTIVE_FLAG))
-			return;
-
-	pe->bootind= ACTIVE_FLAG;
-	dirty = 1;
-}
-
-int check_existing(struct part_entry *pe)
-/* Check and if not ask if an existing partition may be modified. */
-{
-	static int expert= 0;
-	int c;
-
-	if (expert || pe == nil || !existing[pe - table]) return 1;
-
-	stat_start(1);
-	putstr("Do you wish to modify existing partitions? (y/n) ");
-	fflush(stdout);
-	while ((c= getchar()) != 'y' && c != 'n') {}
-	putchr(c);
-	stat_end(3);
-	return (expert= (c == 'y'));
-}
-
-void m_modify(int ev, object_t *op)
-/* Increment, decrement, set, or toggle the value of an object, using
- * arithmetic tricks the author doesn't understand either.
- */
-{
-	object_t *op2;
-	struct part_entry *pe= op->entry;
-	int mul, delta;
-	unsigned level= 1;
-	unsigned long surplus;
-	int radix= op->type == O_TYPHEX ? 0x10 : 10;
-	unsigned long t;
-
-	if (device < 0 && op->type != O_DEV) return;
-
-	switch (ev) {
-	case '-':
-		mul= radix; delta= -1; typing= 0;
-		break;
-	case '+':
-		mul= radix; delta= 1; typing= 0;
-		break;
-	case '\b':
-		if (!typing) return;
-		mul= 1; delta= 0;
-		break;
-	case '\r':
-		typing= 0;
-		return;
-	default:
-		if ('0' <= ev && ev <= '9')
-			delta= ev - '0';
-		else
-		if (radix == 0x10 && 'a' <= ev && ev <= 'f')
-			delta= ev - 'a' + 10;
-		else
-		if (radix == 0x10 && 'A' <= ev && ev <= 'F')
-			delta= ev - 'A' + 10;
-		else
-			return;
-
-		mul= typing ? radix*radix : 0;
-		typing= 1;
-	}
-	magic= 0;
-
-	if (!check_existing(pe)) return;
-
-	switch (op->type) {
-	case O_DEV:
-		if (ev != '-' && ev != '+') return;
-		if (!nextdevice(op, delta)) return;
-		break;
-	case O_CYL:
-		if (!within(&cylinders, 1,
-			cylinders * mul / radix + delta, 1024)) return;
-		recompute0();
-		break;
-	case O_HEAD:
-		if (!within(&heads, 1, heads * mul / radix + delta, 255))
-			return;
-		recompute0();
-		break;
-	case O_SEC:
-		if (!within(&sectors, 1, sectors * mul / radix + delta, 63))
-			return;
-		recompute0();
-		break;
-	case O_NUM:
-		if (ev != '-' && ev != '+') return;
-		for (op2= world; op2 != nil; op2= op2->next) {
-			if (op2->type == O_NUM && ev == '+')
-				op2->entry->bootind= 0;
-		}
-		op->entry->bootind= ev == '+' ? ACTIVE_FLAG : 0;
-		break;
-	case O_TYPHEX:
-		check_ind(pe);
-		pe->sysind= pe->sysind * mul / radix + delta;
-		break;
-	case O_TYPTXT:
-		if (ev != '-' && ev != '+') return;
-		check_ind(pe);
-		pe->sysind= round_sysind(pe->sysind, delta);
-		break;
-	case O_SCYL:
-		level= heads;
-	case O_SHEAD:
-		level*= sectors;
-	case O_SSEC:
-		if (op->type != O_SCYL && ev != '-' && ev != '+') return;
-	case O_BASE:
-		if (pe->sysind == NO_PART) memset(pe, 0, sizeof(*pe));
-		t= pe->lowsec;
-		surplus= t % level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		if (howend == LAST || op->type != O_BASE)
-			pe->size-= t - pe->lowsec;
-		pe->lowsec= t;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	case O_LCYL:
-		level= heads;
-	case O_LHEAD:
-		level*= sectors;
-	case O_LSEC:
-		if (op->type != O_LCYL && ev != '-' && ev != '+') return;
-
-		if (pe->sysind == NO_PART) memset(pe, 0, sizeof(*pe));
-		t= pe->lowsec + pe->size - 1 + level;
-		surplus= t % level - mul / radix * level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		pe->size= t - pe->lowsec + 1;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	case O_KB:
-		level= 2;
-		if (mul == 0) pe->size= 0;	/* new value, no surplus */
-	case O_SIZE:
-		if (pe->sysind == NO_PART) {
-			if (op->type == O_KB || howend == SIZE) {
-				/* First let loose magic to set the base. */
-				event('m', op);
-				magic= 0;
-				pe->size= 0;
-				event(ev, op);
-				return;
-			}
-			memset(pe, 0, sizeof(*pe));
-		}
-		t= (op->type == O_KB || howend == SIZE) ? pe->size
-						: pe->lowsec + pe->size - 1;
-		surplus= t % level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		pe->size= (op->type == O_KB || howend == SIZE) ? t :
-							t - pe->lowsec + 1;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	default:
-		return;
-	}
-
-	/* The order among the entries may have changed. */
-	sort();
-	dirty= 1;
-}
-
-unsigned long spell[3 + 4 * (1+NR_PARTITIONS)];
-int nspells;
-objtype_t touching;
-
-void newspell(unsigned long charm)
-/* Add a new spell, descending order for the base, ascending for the size. */
-{
-	int i, j;
-
-	if (charm - table[0].lowsec > table[0].size) return;
-
-	for (i= 0; i < nspells; i++) {
-		if (charm == spell[i]) return;	/* duplicate */
-
-		if (touching == O_BASE) {
-			if (charm == table[0].lowsec + table[0].size) return;
-			if ((spell[0] - charm) < (spell[0] - spell[i])) break;
-		} else {
-			if (charm == table[0].lowsec) return;
-			if ((charm - spell[0]) < (spell[i] - spell[0])) break;
-		}
-	}
-	for (j= ++nspells; j > i; j--) spell[j]= spell[j-1];
-	spell[i]= charm;
-}
-
-void m_magic(int ev, object_t *op)
-/* Apply magic onto a base or size number. */
-{
-	struct part_entry *pe= op->entry, *pe2;
-	int rough= (offset != 0 && extbase == 0);
-
-	if (ev != 'm' || device < 0) return;
-	typing= 0;
-
-	if (!check_existing(pe)) return;
-
-	if (magic == 0) {
-		/* See what magic we can let loose on this value. */
-		nspells= 1;
-
-		/* First spell, the current value. */
-		switch (op->type) {
-		case O_SCYL:
-		case O_SHEAD:	/* Start of partition. */
-		case O_SSEC:
-		case O_BASE:
-			touching= O_BASE;
-			spell[0]= pe->lowsec;
-			break;
-		case O_LCYL:
-		case O_LHEAD:
-		case O_LSEC:	/* End of partition. */
-		case O_KB:
-		case O_SIZE:
-			touching= O_SIZE;
-			spell[0]= pe->lowsec + pe->size;
-			break;
-		default:
-			return;
-		}
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-			check_ind(pe);
-			pe->sysind= MINIX_PART;
-			spell[0]= 0;
-			if (touching == O_SIZE) {
-				/* First let loose magic on the base. */
-				object_t *op2;
-
-				for (op2= world; op2 != nil; op2= op2->next) {
-					if (op2->row == op->row &&
-							op2->type == O_BASE) {
-						event('m', op2);
-					}
-				}
-				magic= 0;
-				event('m', op);
-				return;
-			}
-		}
-		/* Avoid the first sector on the device. */
-		if (spell[0] == table[0].lowsec) newspell(spell[0] + 1);
-
-		/* Further interesting values are the the bases of other
-		 * partitions or their ends.
-		 */
-		for (pe2= table; pe2 < table + 1 + NR_PARTITIONS; pe2++) {
-			if (pe2 == pe || pe2->sysind == NO_PART) continue;
-			if (pe2->lowsec == table[0].lowsec)
-				newspell(table[0].lowsec + 1);
-			else
-				newspell(pe2->lowsec);
-			newspell(pe2->lowsec + pe2->size);
-			if (touching == O_BASE && howend == SIZE) {
-				newspell(pe2->lowsec - pe->size);
-				newspell(pe2->lowsec + pe2->size - pe->size);
-			}
-			if (pe2->lowsec % sectors != 0) rough= 1;
-		}
-		/* Present values rounded up to the next cylinder unless
-		 * the table is already a mess.  Use "start + 1 track" instead
-		 * of "start + 1 cylinder".  Also add the end of the last
-		 * cylinder.
-		 */
-		if (!rough) {
-			unsigned long n= spell[0];
-			if (n == table[0].lowsec) n++;
-			n= (n + sectors - 1) / sectors * sectors;
-			if (n != table[0].lowsec + sectors)
-				n= (n + secpcyl - 1) / secpcyl * secpcyl;
-			newspell(n);
-			if (touching == O_SIZE)
-				newspell(table[0].size / secpcyl * secpcyl);
-		}
-	}
-	/* Magic has been applied, a spell needs to be chosen. */
-
-	if (++magic == nspells) magic= 0;
-
-	if (touching == O_BASE) {
-		if (howend == LAST) pe->size-= spell[magic] - pe->lowsec;
-		pe->lowsec= spell[magic];
-	} else
-		pe->size= spell[magic] - pe->lowsec;
-
-	/* The order among the entries may have changed. */
-	sort();
-	dirty= 1;
-}
-
-typedef struct diving {
-	struct diving	*up;
-	struct part_entry  old0;
-	char		*oldsubname;
-	parttype_t	oldparttype;
-	unsigned long	oldoffset;
-	unsigned long	oldextbase;
-} diving_t;
-
-diving_t *diving= nil;
-
-void m_in(int ev, object_t *op)
-/* Go down into a primary or extended partition. */
-{
-	diving_t *newdiv;
-	struct part_entry *pe= op->entry, ext;
-	int n;
-
-	if (ev != '>' || device < 0 || pe == nil || pe == &table[0]
-		|| (!(pe->sysind == MINIX_PART && offset == 0)
-					&& !ext_part(pe->sysind))
-		|| pe->size == 0) return;
-
-	ext= *pe;
-	if (extbase != 0) ext.size= extbase + extsize - ext.lowsec;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return;
-	if (device >= 0) { close(device); device= -1; }
-
-	newdiv= alloc(sizeof(*newdiv));
-	newdiv->old0= table[0];
-	newdiv->oldsubname= curdev->subname;
-	newdiv->oldparttype= curdev->parttype;
-	newdiv->oldoffset= offset;
-	newdiv->oldextbase= extbase;
-	newdiv->up= diving;
-	diving= newdiv;
-
-	table[0]= ext;
-
-	n= strlen(diving->oldsubname);
-	curdev->subname= alloc((n + 3) * sizeof(curdev->subname[0]));
-	strcpy(curdev->subname, diving->oldsubname);
-	curdev->subname[n++]= ':';
-	curdev->subname[n++]= '0' + (pe - table - 1);
-	curdev->subname[n]= 0;
-
-	curdev->parttype= curdev->parttype == PRIMARY ? SUBPART : DUNNO;
-	offset= ext.lowsec;
-	if (ext_part(ext.sysind) && extbase == 0) {
-		extbase= ext.lowsec;
-		extsize= ext.size;
-		curdev->parttype= DUNNO;
-	}
-
-	submerged= 1;
-	event('r', op);
-}
-
-void m_out(int ev, object_t *op)
-/* Go up from an extended or subpartition table to its enclosing. */
-{
-	diving_t *olddiv;
-
-	if (ev != '<' || diving == nil) return;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return;
-	if (device >= 0) { close(device); device= -1; }
-
-	olddiv= diving;
-	diving= olddiv->up;
-
-	table[0]= olddiv->old0;
-
-	free(curdev->subname);
-	curdev->subname= olddiv->oldsubname;
-
-	curdev->parttype= olddiv->oldparttype;
-	offset= olddiv->oldoffset;
-	extbase= olddiv->oldextbase;
-
-	free(olddiv);
-
-	event('r', op);
-	if (diving == nil) submerged= 0;	/* We surfaced. */
-}
-
-void installboot(unsigned char *bootblock, char *masterboot)
-/* Install code from a master bootstrap into a boot block. */
-{
-	FILE *mfp;
-	struct exec hdr;
-	int n;
-	char *err;
-
-	if ((mfp= fopen(masterboot, "r")) == nil) {
-		err= strerror(errno);
-		goto m_err;
-	}
-
-	n= fread(&hdr, sizeof(char), A_MINHDR, mfp);
-	if (ferror(mfp)) {
-		err= strerror(errno);
-		fclose(mfp);
-		goto m_err;
-	}
-
-	if (n < A_MINHDR || BADMAG(hdr) || hdr.a_cpu != A_I8086) {
-		err= "Not an 8086 executable";
-		fclose(mfp);
-		goto m_err;
-	}
-
-	if (hdr.a_text + hdr.a_data > PART_TABLE_OFF) {
-		err= "Does not fit in a boot sector";
-		fclose(mfp);
-		goto m_err;
-	}
-
-	fseek(mfp, hdr.a_hdrlen, 0);
-	fread(bootblock, sizeof(char), (size_t) (hdr.a_text + hdr.a_data), mfp);
-	if (ferror(mfp)) {
-		err= strerror(errno);
-		fclose(mfp);
-		goto m_err;
-	}
-	fclose(mfp);
-
-	/* Bootstrap installed. */
-	return;
-
-    m_err:
-	stat_start(1);
-	printf("%s: %s", masterboot, err);
-	stat_end(5);
-}
-
-ssize_t boot_readwrite(int rw)
-/* Read (0) or write (1) the boot sector. */
-{
-	u64_t off64 = mul64u(offset, SECTOR_SIZE);
-	int r;
-
-#if __minix_vmd
-	/* Minix-vmd has a 64 bit seek. */
-	if (fcntl(device, F_SEEK, off64) < 0) return -1;
-#else
-	/* Minix has to gross things with the partition base. */
-	struct partition geom0, geom_seek;
-
-	if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) {
-		/* Move partition base. */
-		if (ioctl(device, DIOCGETP, &geom0) < 0) return -1;
-		geom_seek.base = add64(geom0.base, off64);
-		geom_seek.size = cvu64(cmp64(add64u(off64, SECTOR_SIZE),
-			geom0.size) <= 0 ? _STATIC_BLOCK_SIZE : 0);
-		sync();
-		if (ioctl(device, DIOCSETP, &geom_seek) < 0) return -1;
-		if (lseek(device, (off_t) 0, SEEK_SET) == -1) return -1;
-	} else {
-		/* Can reach this point normally. */
-		if (lseek(device, (off_t) offset * SECTOR_SIZE, SEEK_SET) == -1)
-			return -1;
-	}
-#endif
-
-	switch (rw) {
-	case 0:	r= read(device, bootblock, SECTOR_SIZE);	break;
-	case 1:	r= write(device, bootblock, SECTOR_SIZE);	break;
-	}
-
-#if !__minix_vmd
-	if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) {
-		/* Restore partition base and size. */
-		sync();
-		if (ioctl(device, DIOCSETP, &geom0) < 0) return -1;
-	}
-#endif
-	return r;
-}
-
-int cylinderalign(region_t *reg)
-{
-	if(reg->is_used_part) {
-		if(reg->used_part.lowsec != table[0].lowsec + sectors
-			&& (reg->used_part.lowsec % secpcyl)) {
-			int extra;
-			extra = secpcyl - (reg->used_part.lowsec % secpcyl);
-			reg->used_part.lowsec += extra;
-			reg->used_part.size -= extra;
-		}
-		if((reg->used_part.size+1) % secpcyl) {
-			reg->used_part.size -= secpcyl - ((reg->used_part.size + 1) % secpcyl);
-		}
-		return reg->used_part.size > 0;
-	}
-
-	if(reg->free_sec_start != table[0].lowsec + sectors && (reg->free_sec_start % secpcyl)) {
-		/* Start is unaligned. Round up. */
-		reg->free_sec_start += secpcyl - (reg->free_sec_start % secpcyl);
-	}
-	if((reg->free_sec_last+1) % secpcyl) {
-		/* End is unaligned. Round down. */
-		reg->free_sec_last -= (reg->free_sec_last+1) % secpcyl;
-	}
-	
-	/* Return nonzero if anything remains of the region after rounding. */
-	return reg->free_sec_last > reg->free_sec_start;
-}
-
-void regionize(void)
-{
-	int free_sec, i, si;
-
-	sort();
-
-	free_sec = table[0].lowsec + sectors;
-
-	/* Create region data used in autopart mode. */
-	free_regions = used_regions = nr_regions = nr_partitions = 0;
-	if(table[0].lowsec > table[sort_order[1]].lowsec &&
-		table[sort_order[1]].sysind != NO_PART) {
-		printf("\nSanity check failed on %s - first partition starts before disk.\n"
-			"Please use expert mode to correct it.\n", curdev->name);
-		exit(1);
-	}
-	for(si = 1; si <= NR_PARTITIONS; si++) {
-		i = sort_order[si];
-		if(i < 1 || i > NR_PARTITIONS) {
-			printf("Sorry, something unexpected has happened (%d out of range).\n", i);
-			exit(1);
-		}
-
-		if(table[i].sysind == NO_PART)
-			break;
-
-		/* Free space before this partition? */
-		if(table[i].lowsec > free_sec) {
-			/* Free region before this partition. */
-			regions[nr_regions].free_sec_start = free_sec;
-			regions[nr_regions].free_sec_last = table[i].lowsec-1;
-			regions[nr_regions].is_used_part = 0;
-			if(cylinderalign(&regions[nr_regions])) {
-				nr_regions++;
-				free_regions++;
-			}
-		}
-
-		/* Sanity check. */
-		if(si > 1) {
-			if(table[i].lowsec < table[sort_order[si-1]].lowsec ||
-			   table[i].lowsec < table[sort_order[si-1]].lowsec + table[sort_order[si-1]].size) {
-				printf("\nSanity check failed on %s - partitions overlap.\n"
-					"Please use expert mode to correct it.\n", curdev->name);
-				exit(1);
-			}
-		}
-		if(table[i].size > table[0].size) {
-			printf("\nSanity check failed on %s - partition is larger than disk.\n"
-				"Please use expert mode to correct it.\n", curdev->name);
-			exit(1);
-		}
-		if(table[i].size < 1) {
-			printf("\nSanity check failed on %s - zero-sized partition.\n"
-				"Please use expert mode to correct it.\n", curdev->name);
-			exit(1);
-		} 
-
-		/* Remember used region. */
-		memcpy(&regions[nr_regions].used_part, &table[i], sizeof(table[i]));
-		free_sec = table[i].lowsec+table[i].size;
-		regions[nr_regions].is_used_part = 1;
-		regions[nr_regions].tableno = i;
-		nr_partitions++;
-		nr_regions++;
-		used_regions++;
-	}
-
-	/* Special case: space after partitions. */
-	if(free_sec <   table[0].lowsec + table[0].size-1) {
-		regions[nr_regions].free_sec_start = free_sec;
-		regions[nr_regions].free_sec_last = table[0].lowsec + table[0].size-1;
-		regions[nr_regions].is_used_part = 0;
-		if(cylinderalign(&regions[nr_regions])) {
-			nr_regions++;
-			free_regions++;
-		}
-	}
-
-}
-
-void m_read(int ev, int *biosdrive)
-/* Read the partition table from the current device. */
-{
-	int si, i, mode, n, r, v;
-	struct part_entry *pe;
-
-	if (ev != 'r' || device >= 0) return;
-
-	/* Open() may cause kernel messages: */
-	stat_start(0);
-	fflush(stdout);
-
-	if ((device= open(curdev->name, mode= O_RDWR, 0666)) < 0) {
-		if (device >= 0) { close(device); device= -1; }
-		return;
-	}
-
-	v = 2*HZ;
-	ioctl(device, DIOCTIMEOUT, &v);
-
-	memset(bootblock, 0, sizeof(bootblock));
-
-	n= boot_readwrite(0);
-
-	if (n <= 0) stat_start(1);
-	if (n < 0) {
-		close(device);
-		device= -1;
-	} else
-	if (n < SECTOR_SIZE) {
-		close(device);
-		device= -1;
-		return;
-	}
-	if (n <= 0) stat_end(5);
-
-	if (n < SECTOR_SIZE) n= SECTOR_SIZE;
-
-	if(biosdrive) (*biosdrive)++;
-
-	if(!open_ct_ok(device)) {
-		printf("\n%s: device in use! skipping it.", curdev->subname);
-		fflush(stdout);
-		close(device);
-		device= -1;
-		return;
-	}
-
-	memcpy(table+1, bootblock+PART_TABLE_OFF,
-					NR_PARTITIONS * sizeof(table[1]));
-	if (bootblock[510] != 0x55 || bootblock[511] != 0xAA) {
-		/* Invalid boot block, install bootstrap, wipe partition table.
-		 */
-		memset(bootblock, 0, sizeof(bootblock));
-		installboot(bootblock, MASTERBOOT);
-		memset(table+1, 0, NR_PARTITIONS * sizeof(table[1]));
-	}
-
-	/* Fix an extended partition table up to something mere mortals can
-	 * understand.  Record already defined partitions.
-	 */
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		pe= &table[i];
-		if (extbase != 0 && pe->sysind != NO_PART)
-			pe->lowsec+= ext_part(pe->sysind) ? extbase : offset;
-		existing[i]= pe->sysind != NO_PART;
-	}
-	geometry();
-	dirty= 0;
-
-	/* Warn about grave dangers ahead. */
-	if (extbase != 0) {
-		stat_start(1);
-		printf("Warning: You are in an extended partition.");
-		stat_end(5);
-	}
-
-	regionize();
-}
-
-void m_write(int ev, object_t *op)
-/* Write the partition table back if modified. */
-{
-	int c;
-	struct part_entry new_table[NR_PARTITIONS], *pe;
-
-	if (ev != 'w' && ev != E_WRITE) return;
-	if (device < 0) { dirty= 0; return; }
-	if (!dirty) {
-		if (ev == 'w') {
-			stat_start(1);
-			printf("%s is not changed, or has already been written",
-							curdev->subname);
-			stat_end(2);
-		}
-		return;
-	}
-
-	if (extbase != 0) {
-		/* Will this stop him?  Probably not... */
-		stat_start(1);
-		printf("You have changed an extended partition.  Bad Idea.");
-		stat_end(5);
-	}
-
-	memcpy(new_table, table+1, NR_PARTITIONS * sizeof(table[1]));
-	for (pe= new_table; pe < new_table + NR_PARTITIONS; pe++) {
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-		} else {
-			abs2dos(&pe->start_head, pe->lowsec);
-			abs2dos(&pe->last_head, pe->lowsec + pe->size - 1);
-
-			/* Fear and loathing time: */
-			if (extbase != 0)
-				pe->lowsec-= ext_part(pe->sysind)
-						? extbase : offset;
-		}
-	}
-	memcpy(bootblock+PART_TABLE_OFF, new_table, sizeof(new_table));
-	bootblock[510]= 0x55;
-	bootblock[511]= 0xAA;
-
-	if (boot_readwrite(1) < 0) {
-		stat_start(1);
-		printf("%s: %s", curdev->name, strerror(errno));
-		stat_end(5);
-		return;
-	}
-	dirty= 0;
-}
-
-void m_shell(int ev, object_t *op)
-/* Shell escape, to do calculations for instance. */
-{
-	int r, pid, status;
-	void (*sigint)(int), (*sigquit)(int), (*sigterm)(int);
-
-	if (ev != 's') return;
-
-	reset_tty();
-	fflush(stdout);
-
-	switch (pid= fork()) {
-	case -1:
-		stat_start(1);
-		printf("can't fork: %s\n", strerror(errno));
-		stat_end(3);
-		break;
-	case 0:
-		if (device >= 0) (void) close(device);
-		execl("/bin/sh", "sh", (char *) nil);
-		r= errno;
-		stat_start(1);
-		printf("/bin/sh: %s\n", strerror(errno));
-		stat_end(3);
-		exit(127);
-	}
-	sigint= signal(SIGINT, SIG_IGN);
-	sigquit= signal(SIGQUIT, SIG_IGN);
-	sigterm= signal(SIGTERM, SIG_IGN);
-	while (pid >= 0 && (r= wait(&status)) >= 0 && r != pid) {}
-	(void) signal(SIGINT, sigint);
-	(void) signal(SIGQUIT, sigquit);
-	(void) signal(SIGTERM, sigterm);
-	tty_raw();
-	if (pid < 0)
-		;
-	else
-	if (WIFEXITED(status) && WEXITSTATUS(status) == 127)
-		stat_start(0);	/* Match the stat_start in the child. */
-	else
-		event(ctrl('L'), op);
-}
-
-void m_dump(struct part_entry *print_table)
-/* Raw dump of the partition table. */
-{
-	struct part_entry *pe;
-	int i;
-	unsigned chs[3];
-
-printf(" Partition + type      Cyl Head Sec   Cyl Head Sec      Base      Size       Kb\n");
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		pe= &print_table[i];
-		dos2chs(&pe->start_head, chs);
-		printf("%2d%c      %02X%15d%5d%4d",
-			i,
-			pe->bootind & ACTIVE_FLAG ? '*' : ' ',
-			pe->sysind,
-			chs[0], chs[1], chs[2]);
-		dos2chs(&pe->last_head, chs);
-		printf("%6d%5d%4d%10lu%10ld%9lu\n",
-			chs[0], chs[1], chs[2],
-			pe->lowsec,
-			howend == SIZE ? pe->size : pe->size + pe->lowsec - 1,
-			pe->size / 2);
-	}
-}
-
-int quitting= 0;
-
-void m_quit(int ev, object_t *op)
-/* Write the partition table if modified and exit. */
-{
-	if (ev != 'q' && ev != 'x') return;
-
-	quitting= 1;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) quitting= 0;
-}
-
-void m_help(int ev, object_t *op)
-/* For people without a clue; let's hope they can find the '?' key. */
-{
-	static struct help {
-		char	*keys;
-		char	*what;
-	} help[]= {
-	 { "? !",		 "This help / more advice!" },
-	 { "+ - (= _ PgUp PgDn)","Select/increment/decrement/make active" },
-	 { "0-9 (a-f)",		 "Enter value" },
-	 { "hjkl (arrow keys)",	 "Move around" },
-	 { "CTRL-K CTRL-J",	 "Move entry up/down" },
-	 { "CTRL-L",		 "Redraw screen" },
-	 { ">",			 "Start a subpartition table" },
-	 { "<",			 "Back to the primary partition table" },
-	 { "m",			 "Cycle through magic values" },
-	 { "spacebar",		 "Show \"Size\" or \"Last\"" },
-	 { "r w",		 "Read/write partition table" },
-	 { "p s q x",		 "Raw dump / Shell escape / Quit / Exit" },
-	 { "y n DEL",		 "Answer \"yes\", \"no\", \"cancel\"" },
-	};
-	static char *advice[] = {
-"* Choose a disk with '+' and '-', then hit 'r'.",
-"* To change any value: Move to it and use '+', '-' or type the desired value.",
-"* To make a new partition:  Move over to the Size or Kb field of an unused",
-"  partition and type the size.  Hit the 'm' key to pad the partition out to",
-"  a cylinder boundary.  Hit 'm' again to pad it out to the end of the disk.",
-"  You can hit 'm' more than once on a base or size field to see several",
-"  interesting values go by.  Note: Other Operating Systems can be picky about",
-"  partitions that are not padded to cylinder boundaries.  Look for highlighted",
-"  head or sector numbers.",
-"* To reuse a partition:  Change the type to MINIX.",
-"* To delete a partition:  Type a zero in the hex Type field.",
-"* To make a partition active:  Type '+' in the Num field.",
-"* To study the list of keys:  Type '?'.",
-	};
-
-	if (ev == '?') {
-		struct help *hp;
-
-		for (hp= help; hp < arraylimit(help); hp++) {
-			stat_start(0);
-			printf("%-25s - %s", hp->keys, hp->what);
-			stat_end(0);
-		}
-		stat_start(0);
-		putstr("Things like ");
-		putstr(t_so); putstr("this"); putstr(t_se);
-		putstr(" must be checked, but ");
-		putstr(t_md); putstr("this"); putstr(t_me);
-		putstr(" is not really a problem");
-		stat_end(0);
-	} else
-	if (ev == '!') {
-		char **ap;
-
-		for (ap= advice; ap < arraylimit(advice); ap++) {
-			stat_start(0);
-			putstr(*ap);
-			stat_end(0);
-		}
-	}
-}
-
-void event(int ev, object_t *op)
-/* Simply call all modifiers for an event, each one knows when to act. */
-{
-	m_help(ev, op);
-	m_redraw(ev, op);
-	m_toggle(ev, op);
-	m_orientation(ev, op);
-	m_move(ev, op);
-	m_updown(ev, op);
-	m_enter(ev, op);
-	m_leave(ev, op);
-	m_modify(ev, op);
-	m_magic(ev, op);
-	m_in(ev, op);
-	m_out(ev, op);
-	m_read(ev, NULL);
-	m_write(ev, op);
-	m_shell(ev, op);
-	m_quit(ev, op);
-}
-
-int keypress(void)
-/* Get a single keypress.  Translate compound keypresses (arrow keys) to
- * their simpler equivalents.
- */
-{
-	char ch;
-	int c;
-	int esc= 0;
-
-	set_cursor(curobj->row, curobj->col);
-	fflush(stdout);
-
-	do {
-		if (read(0, &ch, sizeof(ch)) < 0) fatal("stdin");
-		c= (unsigned char) ch;
-		switch (esc) {
-		case 0:
-			switch (c) {
-			case ctrl('['):	esc= 1; break;
-			case '_':	c= '-'; break;
-			case '=':	c= '+'; break;
-			}
-			break;
-		case 1:
-			esc= c == '[' ? 2 : 0;
-			break;
-		case 2:
-			switch (c) {
-			case 'D':	c= 'h';	break;
-			case 'B':	c= 'j';	break;
-			case 'A':	c= 'k';	break;
-			case 'C':	c= 'l';	break;
-			case 'H':	c= 'H';	break;
-			case 'U':
-			case 'S':	c= '-';	break;
-			case 'V':
-			case 'T':	c= '+';	break;
-			}
-			/*FALL THROUGH*/
-		default:
-			esc= 0;
-		}
-	} while (esc > 0);
-
-	switch (c) {
-	case ctrl('B'):	c= 'h';	break;
-	case ctrl('N'):	c= 'j';	break;
-	case ctrl('P'):	c= 'k';	break;
-	case ctrl('F'):	c= 'l';	break;
-	}
-
-	return c;
-}
-
-void mainloop(void)
-/* Get keypress, handle event, display results, reset screen, ad infinitum. */
-{
-	int key;
-
-	while (!quitting) {
-		stat_reset();
-
-		key= keypress();
-
-		event(key, curobj);
-
-		display();
-	}
-}
-
-char *
-prettysizeprint(int kb)
-{
-	int toosmall = 0;
-	static char str[200];
-	char unit = 'k';
-	if(MIN_REGION_SECTORS > kb*2)
-		toosmall = 1;
-	if(kb >= 5*1024) {
-		kb /= 1024;
-		unit = 'M';
-		if(kb >= 5*1024) {
-			kb /= 1024;
-			unit = 'G';
-		}
-	}
-	sprintf(str, "%4d %cB%s", kb, unit,
-		toosmall ? ", too small for MINIX 3" : "");
-	return str;
-}
-
-void
-printregions(region_t *theregions, int indent, int p_nr_partitions, int p_free_regions, int p_nr_regions, int numbers)
-{
-	int r, nofree = 0;
-	region_t *reg;
-	reg = theregions;
-
-	if((p_nr_partitions >= NR_PARTITIONS || !p_free_regions) && p_free_regions)
-		nofree = 1;
-	for(r = 0; r < p_nr_regions; r++, reg++) {
-		unsigned long units;
-		if(reg->is_used_part) {
-			char *name;
-			name = typ2txt(reg->used_part.sysind);
-			printf("%*s", indent, ""); type2col(reg->used_part.sysind);
-			if(numbers) printf("[%d]  ", r);
-			printf("In use by %-10s ", name);
-			units = reg->used_part.size / 2;
-			col(0);
-			printf(" (%s)\n", prettysizeprint(units));
-		} else {
-			printf("%*s", indent, ""); 
-			if(numbers) {
-				if(!nofree) printf("[%d]  ", r);
-				else printf("[-]  ");
-			}
-			printf("Free space           ");
-			units = ((reg->free_sec_last - reg->free_sec_start+1))/2;
-			printf(" (%s)\n", prettysizeprint(units));
-		}
-	}
-
-	if(numbers && p_nr_partitions >= NR_PARTITIONS && p_free_regions) {
-		printf(
-"\nNote: there is free space on this disk, but you can't select it,\n"
-"because there isn't a free slot in the partition table to use it.\n"
-"You can reclaim the free space by deleting an adjacent region.\n");
-	}
-
-	return;
-}
-
-#define IS_YES   3
-#define IS_NO    4
-#define IS_OTHER 5
-int
-is_sure(char *fmt, ...)
-{
-	char yesno[10];
-	va_list ap;
-	va_start (ap, fmt);
-	vprintf(fmt, ap);
-	va_end(ap);
-	printf("  Please enter 'yes' or 'no': ");
-	fflush(stdout);
-	if(!fgets(yesno, sizeof(yesno)-1, stdin)) exit(1);
-
-	if (strcmp(yesno, "yes\n") == 0) return(IS_YES);
-	if (strcmp(yesno, "no\n") == 0) return(IS_NO);
-	return IS_OTHER;
-}
-
-void warn(char *message)
-{
-	printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ! %s\n",message);
-}
-
-int
-may_kill_region(void)
-{
-        int confirmation;
-	char line[100];
-	int r, i;
-
-	if(used_regions < 1) return 1;
-
-	printf("\n -- Delete in-use region? --\n\n");
-
-	printregions(regions, 3, nr_partitions, free_regions, nr_regions, 1);
-	printf("\nEnter the region number to delete or ENTER to continue: ");
-	fflush(NULL);
-	fgets(line, sizeof(line)-2, stdin);
-	if(!isdigit(line[0]))
-		return 1;
-
-	r=atoi(line);
-	if(r < 0 || r >= nr_regions) {
-		printf("This choice is out of range.\n");
-		return 0;
-	}
-
-	if(!regions[r].is_used_part) {
-		printf("This region is not in use.\n");
-		return 0;
-	}
-
-	i = regions[r].tableno;
-
-	printf("\nPlease confirm that you want to delete region %d, losing all data it", r); 
-	printf("\ncontains. You're disk is not actually updated right away, but still.");
-	printf("\n\n");
-
- 	do {
-		confirmation = is_sure("Are you sure you want to continue?");
-		if (confirmation == IS_NO) return 0;
-	} while (confirmation != IS_YES);
-
-		table[i].sysind = NO_PART;
-		dirty = 1;
-		regionize();
-
-	/* User may go again. */
-	return 0;
-}
-
-
-region_t *
-select_region(void)
-{
-	int r, rem, rn, done = 0;
-	static char line[100];
-	region_t *reg;
-	int nofree = 0;
-
-	printstep(2, "Select a disk region");
-
-	if(nr_regions < 1) {
-		printf("\nNo regions found - maybe the drive is too small.\n"
-			"Please try expert mode.\n");
-		exit(1);
-	}
-
-	if(nr_partitions >= NR_PARTITIONS || !free_regions) {
-		if(free_regions) {
-			nofree = 1;
-		}
-	}
-
-
-	printf("\nPlease select the region that you want to use for the MINIX 3 setup.");
-	printf("\nIf you select an in-use region it will be overwritten by MINIX. The");
-	printf("\nfollowing region%s were found on the selected disk:\n\n",
-		SORNOT(nr_regions));
-	printregions(regions, 3, nr_partitions, free_regions, nr_regions, 1);
-
-
-	printf("\n");
-	do {
-		printf("Enter the region number to use or type 'delete': ");
-		if(nr_regions == 1) printf(" [0] ");
-		fflush(NULL);
-
-		if(!fgets(line, sizeof(line)-2, stdin))
-			exit(1);
-
-		if (nr_regions == 1 && line[0] == '\n') {
-		    rn = 0;
-		    done = 1;
-		}
-		else {
-			if(strcmp(line,"delete\n") == 0) {
-				may_kill_region();
-				return NULL;
-			}
-
-			if(sscanf(line, "%d", &rn) != 1)  {
-				warn("invalid choice");
-				continue;
-			}
-
-			if(rn < 0 || rn >= nr_regions) {
-				warn("out of range");
-				continue;
-			}
-
-			if(nofree && !regions[rn].is_used_part) {
-				warn("not available");
-				continue;
-			}
-
-			done = 1;
-		} 
-	} while(! done);
-
-	return(&regions[rn]);
-}
-
-static void printstep(int step, char *str)
-{
-	int n;
-	n = printf("\n --- Substep 4.%d: %s ---", step, str);
-	while(n++ < 73) printf("-");
-	printf("\n");
-}
-
-device_t *
-select_disk(void)
-{
-	int done = 0;
-	int i, choice, drives;
-	static char line[500];
-	int biosdrive = 0;
-
-	printstep(1, "Select a disk to install MINIX 3");
-	printf("\nProbing for disks. This may take a short while.");
-
-		i = 0;
-		curdev=firstdev;
-
-		for(; i < MAX_DEVICES;) {
-			printf("."); 
-			fflush(stdout);
-			m_read('r', &biosdrive);
-			if(device >= 0) {
-				devices[i].dev = curdev;
-				devices[i].free_regions = free_regions;
-				devices[i].nr_regions = nr_regions;
-				devices[i].nr_partitions = nr_partitions;
-				devices[i].used_regions = used_regions;
-				devices[i].sectors = table[0].size;
-				curdev->biosdrive = biosdrive-1;
-				memcpy(devices[i].regions, regions, sizeof(regions));
-				i++;
-			}
-
-			nextdevice(NULL, 1);
-			if(curdev == firstdev)
-				break;
-		}
-
-		drives = i;
-
-		if(drives < 1) {
-			printf("\nFound no drives - can't partition.\n");
-			exit(1);
-		}
-
-		printf(" Probing done.\n"); 
-		printf("The following disk%s %s found on your system:\n\n", SORNOT(drives),
-			drives == 1 ? "was" : "were");
-
-			for(i = 0; i < drives; i++) {
-				printf("  ");
-				printf("Disk [%d]:  ", i);
-				printf("%s, ", devices[i].dev->name);
-				printf("%s\n", prettysizeprint(devices[i].sectors/2));
-				printregions(devices[i].regions, 8,
-					devices[i].nr_partitions,
-					devices[i].free_regions,
-					devices[i].nr_regions, 0);
-			}
-	
-	   printf("\n");
-		do {
-			printf("Enter the disk number to use: ");
-	   		if (drives == 1) printf("[0] ");
-			fflush(NULL);
-			if(!fgets(line, sizeof(line)-2, stdin))
-				exit(1);
-			if (line[0] == '\n' && drives == 1) {
-				choice = 0;
-				done = 1;
-			} else {
-			    if(sscanf(line, "%d", &choice) != 1) {
-				warn("choose a disk");
-			 	continue;
-			    }
-			    if(choice < 0 || choice >= i) {
-				warn("out of range");
-				continue;
-			    }
-			    done = 1;
-			}
-		} while(! done);
-	return devices[choice].dev;
-}
-
-int
-scribble_region(region_t *reg, struct part_entry **pe, int *made_new)
-{
-	int ex, trunc = 0, changed = 0, i;
-	struct part_entry *newpart;
-	if(reg->is_used_part && reg->used_part.size > MAX_REGION_SECTORS) {
-		reg->used_part.size = MAX_REGION_SECTORS;
-		trunc = 1;
-		changed = 1;
-		cylinderalign(reg);
-	}
-	if(!reg->is_used_part) {
-		ex = reg->free_sec_last - reg->free_sec_start + 1;
-		if(ex > MAX_REGION_SECTORS) {
-			reg->free_sec_last -= ex - MAX_REGION_SECTORS;
-			trunc = 1;
-			changed = 1;
-			cylinderalign(reg);
-		}
-		if(made_new) *made_new = 1;
-	} else if(made_new) *made_new = 0;
-#if 0
-	if(trunc) {
-		printf("\nWill only use %dMB.\n", MAX_REGION_MB);
-	}
-#endif
-	if(!reg->is_used_part) {
-		for(i = 1; i <= NR_PARTITIONS; i++)
-			if(table[i].sysind == NO_PART)
-				break;
-		if(i > NR_PARTITIONS) {
-			/* Bug, should've been caught earlier. */
-			printf("Couldn't find a free slot. Please try expert mode.\n");
-			exit(1);
-		}
-		newpart = &table[i];
-		newpart->lowsec = reg->free_sec_start;
-		newpart->size = reg->free_sec_last - reg->free_sec_start + 1;
-		changed = 1;
-		newpart->sysind = MINIX_PART;
-	} else  {
-		newpart = &reg->used_part;
-	}
-	*pe = newpart;
-	changed = 1;
-	dirty = 1;
-	return changed;
-}
-
-int
-sanitycheck_failed(char *dev, struct part_entry *pe)
-{
-	struct partition part;
-	int fd;
-	unsigned long it_lowsec, it_secsize;
-
-	if((fd = open(dev, O_RDONLY)) < 0) {
-		perror(dev);
-		return 1;
-	}
-
-	if (ioctl(fd, DIOCGETP, &part) < 0) {
-		fprintf(stderr, "DIOCGETP failed\n");
-		perror(dev);
-		return 1;
-	}
-
-	if(!open_ct_ok(fd)) {
-		printf("\nAutopart error: the disk is in use. This means that although a\n"
-			"new table has been written, it won't be in use by the system\n"
-			"until it's no longer in use (or a reboot is done). Just in case,\n"
-			"I'm not going to continue. Please un-use the disk (or reboot) and try\n"
-			"again.\n\n");
-		return 1;
-	}
-
-	close(fd);
-
-	it_lowsec = div64u(part.base, SECTOR_SIZE);
-	it_secsize = div64u(part.size, SECTOR_SIZE);
-
-	if(it_lowsec != pe->lowsec || it_secsize != pe->size) {
-		fprintf(stderr, "\nReturned and set numbers don't match up!\n");
-		fprintf(stderr, "This can happen if the disk is still opened.\n");
-		return 1;
-	}
-
-	return 0;
-}
-
-int
-do_autopart(int resultfd)
-{
-	int confirmation;
-	region_t *r;
-	struct part_entry *pe;
-	char sure[50];
-	struct part_entry orig_table[1 + NR_PARTITIONS];
-	int region, disk, newp;
-
-	nordonly = 1; 
-
-	do {
-		curdev = select_disk();
-	} while(!curdev);
-
-	if(device >= 0) {
-		close(device);
-		device = -1;
-	}
-	recompute0();
-
-	m_read('r', NULL);
-
-	memcpy(orig_table, table, sizeof(table));
-
-	do {
-		/* Show regions. */
-		r = select_region();
-	} while(!r);	/* Back to step 2. */
-
-	/* Write things. */
-	if(scribble_region(r, &pe, &newp)) {
-		char *name;
-		int i, found = -1;
-		char partbuf[100], devname[100];
-		struct part_entry *tpe;
-
-		printstep(3, "Confirm your choices");
-
-		region =  (int)(r-regions); 
-		/* disk = (int) (curdev-devices); */
-
-		printf("\nThis is the point of no return.  You have selected to install MINIX 3\n");
-		printf("into region %d of disk %s.  Please confirm that you want\n",
-			region, curdev->name);
-		printf("to use this selection to install MINIX 3.\n\n");
-
-		do {
-			confirmation = is_sure("Are you sure you want to continue?");
-			if (confirmation == IS_NO) return 1;
-		} while (confirmation != IS_YES);
-
-		/* Retrieve partition number in sorted order that we
-		 * have scribbled in.
-		 */
-		sort();
-		for(i = 1; i <= NR_PARTITIONS; i++) {
-			int si;
-			si = sort_order[i];
-			if(si < 1 || si > NR_PARTITIONS) {
-				fprintf(stderr, "Autopart internal error (out of range) (nothing written).\n");
-				exit(1);
-			}
-			if(table[si].lowsec == pe->lowsec) {
-				if(found > 0) {
-					fprintf(stderr, "Autopart internal error (part found twice) (nothing written).\n");
-					exit(1);
-				}
-				check_ind(&table[si]);
-				table[si].sysind = MINIX_PART;
-				found = i;
-				tpe = &table[si];
-			}
-		}
-		if(found < 1) {
-			fprintf(stderr, "Autopart internal error (part not found) (nothing written).\n");
-			exit(1);
-		}
-		m_write('w', NULL);
-		if(dirty) {
-			fprintf(stderr, "Autopart internal error (couldn't update disk).\n");
-			exit(1);
-		}
-		name=strrchr(curdev->name, '/');
-		if(!name) name = curdev->name;
-		else name++;
-
-		sprintf(partbuf, "%sp%d d%dp%d\n", name, found-1,
-			curdev->biosdrive, found-1);
-		sprintf(devname, "/dev/%sp%d", name, found-1);
-		if(resultfd >= 0 && write(resultfd, partbuf, strlen(partbuf)) < strlen(partbuf)) {
-			fprintf(stderr, "Autopart internal error (couldn't write result).\n");
-			exit(1);
-		}
-		if(device >= 0) {
-			close(device);
-			device = -1;
-		}
-
-#if 0
-		m_dump(orig_table);
-		printf("\n");
-		m_dump(table);
-#endif
-
-		if(sanitycheck_failed(devname, tpe)) {
-			fprintf(stderr, "Autopart internal error (disk sanity check failed).\n");
-			exit(1);
-		}
-
-		if(newp) {
-			int fd;
-			if((fd=open(devname, O_WRONLY)) < 0) {
-				perror(devname);
-			} else {
-				/* Clear any subpartitioning. */
-				static unsigned char sub[2048];
-				sub[510] = 0x55;
-				sub[511] = 0xAA;
-				write(fd, sub, sizeof(sub));
-				close(fd);
-			}
-		}
-		return 0;
-	}
-
-	return 1;
-}
-
-int main(int argc, char **argv)
-{
-	object_t *op;
-	int i, r, key;
-	struct part_entry *pe;
-	char *name;
-	int autopart = 0;
-	int resultfd = -1;
-
-	/* Autopilot mode if invoked as autopart. */
-	if(!(name = strrchr(argv[0], '/'))) name = argv[0];
-	else name++;
-	if(!strcmp(name, "autopart"))
-		autopart = 1;
-
-    if(!autopart) {
-	/* Define a few objects to show on the screen.  First text: */
-	op= newobject(O_INFO, 0, 0,  2, 19);
-	op= newobject(O_TEXT, 0, 0, 22, 13); op->text= "----first----";
-	op= newobject(O_TEXT, 0, 0, 37, 13); op->text= "--geom/last--";
-	op= newobject(O_TEXT, 0, 0, 52, 18); op->text= "------sectors-----";
-	op= newobject(O_TEXT, 0, 1,  4,  6); op->text= "Device";
-	op= newobject(O_TEXT, 0, 1, 23, 12); op->text= "Cyl Head Sec";
-	op= newobject(O_TEXT, 0, 1, 38, 12); op->text= "Cyl Head Sec";
-	op= newobject(O_TEXT, 0, 1, 56,  4); op->text= "Base";
-	op= newobject(O_TEXT, 0, 1, 66,  4); op->text= size_last;
-	op= newobject(O_TEXT, 0, 1, 78,  2); op->text= "Kb";
-	op= newobject(O_TEXT, 0, 4,  0, 15); op->text= "Num Sort   Type";
-
-	/* The device is the current object: */
-    curobj= newobject(O_DEV,  OF_MOD, 2,  4, 15);
-	op= newobject(O_SUB,       0, 3,  4, 15);
-
-	/* Geometry: */
-	op= newobject(O_CYL,  OF_MOD, 2, 40,  5); op->entry= &table[0];
-	op= newobject(O_HEAD, OF_MOD, 2, 45,  3); op->entry= &table[0];
-	op= newobject(O_SEC,  OF_MOD, 2, 49,  2); op->entry= &table[0];
-
-	/* Objects for the device: */
-	op= newobject(O_SCYL,  0, 3, 25,  5); op->entry= &table[0];
-	op= newobject(O_SHEAD, 0, 3, 30,  3); op->entry= &table[0];
-	op= newobject(O_SSEC,  0, 3, 34,  2); op->entry= &table[0];
-	op= newobject(O_LCYL,  0, 3, 40,  5); op->entry= &table[0];
-	op= newobject(O_LHEAD, 0, 3, 45,  3); op->entry= &table[0];
-	op= newobject(O_LSEC,  0, 3, 49,  2); op->entry= &table[0];
-	op= newobject(O_BASE,  0, 3, 59,  9); op->entry= &table[0];
-	op= newobject(O_SIZE,  0, 3, 69,  9); op->entry= &table[0];
-	op= newobject(O_KB,    0, 3, 79,  9); op->entry= &table[0];
-
-	/* Objects for each partition: */
-	for (r= 5, pe= table+1; pe <= table+NR_PARTITIONS; r++, pe++) {
-		op= newobject(O_NUM,    OF_MOD, r,  1,  2); op->entry= pe;
-		op= newobject(O_SORT,        0, r,  5,  2); op->entry= pe;
-		op= newobject(O_TYPHEX, OF_MOD, r, 10,  2); op->entry= pe;
-		op= newobject(O_TYPTXT, OF_MOD, r, 12,  9); op->entry= pe;
-		op= newobject(O_SCYL,   OF_MOD, r, 25,  5); op->entry= pe;
-		op= newobject(O_SHEAD,  OF_MOD, r, 30,  3); op->entry= pe;
-		op= newobject(O_SSEC,   OF_MOD, r, 34,  2); op->entry= pe;
-		op= newobject(O_LCYL,   OF_MOD, r, 40,  5); op->entry= pe;
-		op= newobject(O_LHEAD,  OF_MOD, r, 45,  3); op->entry= pe;
-		op= newobject(O_LSEC,   OF_MOD, r, 49,  2); op->entry= pe;
-		op= newobject(O_BASE,   OF_MOD, r, 59,  9); op->entry= pe;
-		op= newobject(O_SIZE,   OF_MOD, r, 69,  9); op->entry= pe;
-		op= newobject(O_KB,     OF_MOD, r, 79,  9); op->entry= pe;
-	}
-     } else {
-     	int c;
-     	/* autopart uses getopt() */
-     	while((c = getopt(argc, argv, "m:f:")) != EOF) {
-     		switch(c) {
-			case 'm':
-				min_region_mb = atoi(optarg);
-				break;
-     			case 'f':
-				/* Make sure old data file is gone. */
-     				unlink(optarg);
-     				if((resultfd=open(optarg, O_CREAT | O_WRONLY | O_TRUNC)) < 0) {
-     					perror(optarg);
-     					return 1;
-     				}
-     				sync();	/* Make sure no old data file lingers. */
-     				break;
-     			default:
-     				fprintf(stderr, "Unknown option\n");
-     				return 1;
-     		}
-     	}
-     }
-     argc -= optind;
-     argv += optind;
-
-	for (i= 0; i < argc; i++) {
-	 newdevice(argv[i], 0, 0);
-	 }
-
-	if (firstdev == nil) {
-		getdevices(autopart);
-		key= ctrl('L');
-	} else {
-		key= 'r';
-	}
-
-	if(autopart) {
-		int r;
-		if (firstdev == nil) {
-			fprintf(stderr, "autopart couldn't find any devices.\n");
-			return 1;
-		}
-		r = do_autopart(resultfd);
-		if(resultfd >= 0) { close(resultfd); }
-		return r;
-	}
-
-	if (firstdev != nil) {
-		init_tty();
-		clear_screen();
-		event(key, curobj);
-		display();
-		mainloop();
-		reset_tty();
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/backup.c
===================================================================
--- trunk/minix/commands/ibm/backup.c	(revision 9)
+++ 	(revision )
@@ -1,398 +1,0 @@
-/* readclock - read the real time clock		Authors: T. Holm & E. Froese */
-
-/************************************************************************/
-/*									*/
-/*   readclock.c							*/
-/*									*/
-/*		Read the clock value from the 64 byte CMOS RAM		*/
-/*		area, then set system time.				*/
-/*									*/
-/*		If the machine ID byte is 0xFC or 0xF8, the device	*/
-/*		/dev/mem exists and can be opened for reading,		*/
-/*		and no errors in the CMOS RAM are reported by the	*/
-/*		RTC, then the time is read from the clock RAM		*/
-/*		area maintained by the RTC.				*/
-/*									*/
-/*		The clock RAM values are decoded and fed to mktime	*/
-/*		to make a time_t value, then stime(2) is called.	*/
-/*									*/
-/*		This fails if:						*/
-/*									*/
-/*		If the machine ID does not match 0xFC or 0xF8 (no	*/
-/*		error message.)						*/
-/*									*/
-/*		If the machine ID is 0xFC or 0xF8 and /dev/mem		*/
-/*		is missing, or cannot be accessed.			*/
-/*									*/
-/*		If the RTC reports errors in the CMOS RAM.		*/
-/*									*/
-/************************************************************************/
-/*    origination          1987-Dec-29              efth                */
-/*    robustness	   1990-Oct-06		    C. Sylvain		*/
-/* incorp. B. Evans ideas  1991-Jul-06		    C. Sylvain		*/
-/*    set time & calibrate 1992-Dec-17		    Kees J. Bot		*/
-/*    clock timezone	   1993-Oct-10		    Kees J. Bot		*/
-/*    set CMOS clock	   1994-Jun-12		    Kees J. Bot		*/
-/************************************************************************/
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <signal.h>
-#include <ibm/portio.h>
-#include <ibm/cmos.h>
-#include <sys/svrctl.h>
-
-int nflag = 0;		/* Tell what, but don't do it. */
-int wflag = 0;		/* Set the CMOS clock. */
-int Wflag = 0;		/* Also set the CMOS clock register bits. */
-int y2kflag = 0;	/* Interpret 1980 as 2000 for clock with Y2K bug. */
-
-char clocktz[128];	/* Timezone of the clock. */
-
-#define MACH_ID_ADDR	0xFFFFE		/* BIOS Machine ID at FFFF:000E */
-
-#define PC_AT		   0xFC		/* Machine ID byte for PC/AT,
-					   PC/XT286, and PS/2 Models 50, 60 */
-#define PS_386		   0xF8		/* Machine ID byte for PS/2 Model 80 */
-
-/* Manufacturers usually use the ID value of the IBM model they emulate.
- * However some manufacturers, notably HP and COMPAQ, have had different
- * ideas in the past.
- *
- * Machine ID byte information source:
- *	_The Programmer's PC Sourcebook_ by Thom Hogan,
- *	published by Microsoft Press
- */
-
-void errmsg(char *s);
-void get_time(struct tm *t);
-int read_register(int reg_addr);
-void set_time(struct tm *t);
-void write_register(int reg_addr, int value);
-int bcd_to_dec(int n);
-int dec_to_bcd(int n);
-void usage(void);
-
-int main(int argc, char **argv)
-{
-  struct tm time1;
-  struct tm time2;
-  struct tm tmnow;
-  char date[64];
-  time_t now, rtc;
-  int i, mem;
-  unsigned char mach_id, cmos_state;
-  struct sysgetenv sysgetenv;
-
-  /* Open /dev/mem to get access to physical memory. */
-  if ((mem = open("/dev/mem", O_RDONLY)) == -1) {
-	errmsg( "Permission denied." );
-	exit(1);
-  }
-  if (lseek(mem, (off_t) MACH_ID_ADDR, SEEK_SET) == -1
-		|| read(mem, (void *) &mach_id, sizeof(mach_id)) < 0) {
-	mach_id = -1;
-  }
-  if (mach_id != PS_386 && mach_id != PC_AT) {
-	errmsg( "Machine ID unknown." );
-	fprintf( stderr, "Machine ID byte = %02x\n", mach_id );
-
-	exit(1);
-  }
-  cmos_state = read_register(CMOS_STATUS);
-  if (cmos_state & (CS_LOST_POWER | CS_BAD_CHKSUM | CS_BAD_TIME)) {
-	errmsg( "CMOS RAM error(s) found..." );
-	fprintf( stderr, "CMOS state = 0x%02x\n", cmos_state );
-
-	if (cmos_state & CS_LOST_POWER)
-	    errmsg( "RTC lost power. Reset CMOS RAM with SETUP." );
-	if (cmos_state & CS_BAD_CHKSUM)
-	    errmsg( "CMOS RAM checksum is bad. Run SETUP." );
-	if (cmos_state & CS_BAD_TIME)
-	    errmsg( "Time invalid in CMOS RAM. Reset clock." );
-	exit(1);
-  }
-
-  /* Process options. */
-  while (argc > 1) {
-	char *p = *++argv;
-
-	if (*p++ != '-') usage();
-
-	while (*p != 0) {
-		switch (*p++) {
-		case 'n':	nflag = 1;	break;
-		case 'w':	wflag = 1;	break;
-		case 'W':	Wflag = 1;	break;
-		case '2':	y2kflag = 1;	break;
-		default:	usage();
-		}
-	}
-	argc--;
-  }
-  if (Wflag) wflag = 1;		/* -W implies -w */
-
-  /* The hardware clock may run in a different time zone, likely GMT or
-   * winter time.  Select that time zone.
-   */
-  strcpy(clocktz, "TZ=");
-  sysgetenv.key = "TZ";
-  sysgetenv.keylen = 2+1;
-  sysgetenv.val = clocktz+3;
-  sysgetenv.vallen = sizeof(clocktz)-3;
-  if (svrctl(SYSGETENV, &sysgetenv) == 0) {
-	putenv(clocktz);
-	tzset();
-  }
-
-  /* Read the CMOS real time clock. */
-  for (i = 0; i < 10; i++) {
-	get_time(&time1);
-	now = time(NULL);
-
-	time1.tm_isdst = -1;	/* Do timezone calculations. */
-	time2 = time1;
-
-	rtc= mktime(&time1);	/* Transform to a time_t. */
-	if (rtc != -1) break;
-
-	fprintf(stderr,
-"readclock: Invalid time read from CMOS RTC: %d-%02d-%02d %02d:%02d:%02d\n",
-		time2.tm_year+1900, time2.tm_mon+1, time2.tm_mday,
-		time2.tm_hour, time2.tm_min, time2.tm_sec);
-	sleep(5);
-  }
-  if (i == 10) exit(1);
-
-  if (!wflag) {
-	/* Set system time. */
-	if (nflag) {
-		printf("stime(%lu)\n", (unsigned long) rtc);
-	} else {
-		if (stime(&rtc) < 0) {
-			errmsg( "Not allowed to set time." );
-			exit(1);
-		}
-	}
-	tmnow = *localtime(&rtc);
-	if (strftime(date, sizeof(date),
-				"%a %b %d %H:%M:%S %Z %Y", &tmnow) != 0) {
-		if (date[8] == '0') date[8]= ' ';
-		printf("Result: %s\n", date);
-	}
-  } else {
-	/* Set the CMOS clock to the system time. */
-	tmnow = *localtime(&now);
-	if (nflag) {
-		printf("%04d-%02d-%02d %02d:%02d:%02d\n",
-			tmnow.tm_year + 1900,
-			tmnow.tm_mon + 1,
-			tmnow.tm_mday,
-			tmnow.tm_hour,
-			tmnow.tm_min,
-			tmnow.tm_sec);
-	} else {
-		set_time(&tmnow);
-	}
-  }
-  exit(0);
-}
-
-void errmsg(char *s)
-{
-  static char *prompt = "readclock: ";
-
-  fprintf(stderr, "%s%s\n", prompt, s);
-  prompt = "";
-}
-
-
-/***********************************************************************/
-/*                                                                     */
-/*    get_time( time )                                                 */
-/*                                                                     */
-/*    Update the structure pointed to by time with the current time    */
-/*    as read from CMOS RAM of the RTC.				       */
-/*    If necessary, the time is converted into a binary format before  */
-/*    being stored in the structure.                                   */
-/*                                                                     */
-/***********************************************************************/
-
-int dead;
-void timeout(int sig) { dead= 1; }
-
-void get_time(struct tm *t)
-{
-  int osec, n;
-  unsigned long i;
-  struct sigaction sa;
-
-  /* Start a timer to keep us from getting stuck on a dead clock. */
-  sigemptyset(&sa.sa_mask);
-  sa.sa_flags = 0;
-  sa.sa_handler = timeout;
-  sigaction(SIGALRM, &sa, NULL);
-  dead = 0;
-  alarm(5);
-
-  do {
-	osec = -1;
-	n = 0;
-	do {
-		if (dead) {
-			fprintf(stderr, "readclock: CMOS clock appears dead\n");
-			exit(1);
-		}
-
-		/* Clock update in progress? */
-		if (read_register(RTC_REG_A) & RTC_A_UIP) continue;
-
-		t->tm_sec = read_register(RTC_SEC);
-		if (t->tm_sec != osec) {
-			/* Seconds changed.  First from -1, then because the
-			 * clock ticked, which is what we're waiting for to
-			 * get a precise reading.
-			 */
-			osec = t->tm_sec;
-			n++;
-		}
-	} while (n < 2);
-
-	/* Read the other registers. */
-	t->tm_min = read_register(RTC_MIN);
-	t->tm_hour = read_register(RTC_HOUR);
-	t->tm_mday = read_register(RTC_MDAY);
-	t->tm_mon = read_register(RTC_MONTH);
-	t->tm_year = read_register(RTC_YEAR);
-
-	/* Time stable? */
-  } while (read_register(RTC_SEC) != t->tm_sec
-	|| read_register(RTC_MIN) != t->tm_min
-	|| read_register(RTC_HOUR) != t->tm_hour
-	|| read_register(RTC_MDAY) != t->tm_mday
-	|| read_register(RTC_MONTH) != t->tm_mon
-	|| read_register(RTC_YEAR) != t->tm_year);
-
-  if ((read_register(RTC_REG_B) & RTC_B_DM_BCD) == 0) {
-	/* Convert BCD to binary (default RTC mode). */
-	t->tm_year = bcd_to_dec(t->tm_year);
-	t->tm_mon = bcd_to_dec(t->tm_mon);
-	t->tm_mday = bcd_to_dec(t->tm_mday);
-	t->tm_hour = bcd_to_dec(t->tm_hour);
-	t->tm_min = bcd_to_dec(t->tm_min);
-	t->tm_sec = bcd_to_dec(t->tm_sec);
-  }
-  t->tm_mon--;	/* Counts from 0. */
-
-  /* Correct the year, good until 2080. */
-  if (t->tm_year < 80) t->tm_year += 100;
-
-  if (y2kflag) {
-	/* Clock with Y2K bug, interpret 1980 as 2000, good until 2020. */
-	if (t->tm_year < 100) t->tm_year += 20;
-  }
-}
-
-
-int read_register(int reg_addr)
-{
-  int r;
-
-  intr_disable();
-  outb(RTC_INDEX, reg_addr);
-  r= inb(RTC_IO);
-  intr_enable();
-  return r;
-}
-
-
-
-/***********************************************************************/
-/*                                                                     */
-/*    set_time( time )                                                 */
-/*                                                                     */
-/*    Set the CMOS RTC to the time found in the structure.             */
-/*                                                                     */
-/***********************************************************************/
-
-void set_time(struct tm *t)
-{
-  int regA, regB;
-
-  if (Wflag) {
-	/* Set A and B registers to their proper values according to the AT
-	 * reference manual.  (For if it gets messed up, but the BIOS doesn't
-	 * repair it.)
-	 */
-	write_register(RTC_REG_A, RTC_A_DV_OK | RTC_A_RS_DEF);
-	write_register(RTC_REG_B, RTC_B_24);
-  }
-
-  /* Inhibit updates. */
-  regB= read_register(RTC_REG_B);
-  write_register(RTC_REG_B, regB | RTC_B_SET);
-
-  t->tm_mon++;	/* Counts from 1. */
-
-  if (y2kflag) {
-	/* Set the clock back 20 years to avoid Y2K bug, good until 2020. */
-	if (t->tm_year >= 100) t->tm_year -= 20;
-  }
-
-  if ((regB & 0x04) == 0) {
-	/* Convert binary to BCD (default RTC mode) */
-	t->tm_year = dec_to_bcd(t->tm_year % 100);
-	t->tm_mon = dec_to_bcd(t->tm_mon);
-	t->tm_mday = dec_to_bcd(t->tm_mday);
-	t->tm_hour = dec_to_bcd(t->tm_hour);
-	t->tm_min = dec_to_bcd(t->tm_min);
-	t->tm_sec = dec_to_bcd(t->tm_sec);
-  }
-  write_register(RTC_YEAR, t->tm_year);
-  write_register(RTC_MONTH, t->tm_mon);
-  write_register(RTC_MDAY, t->tm_mday);
-  write_register(RTC_HOUR, t->tm_hour);
-  write_register(RTC_MIN, t->tm_min);
-  write_register(RTC_SEC, t->tm_sec);
-
-  /* Stop the clock. */
-  regA= read_register(RTC_REG_A);
-  write_register(RTC_REG_A, regA | RTC_A_DV_STOP);
-
-  /* Allow updates and restart the clock. */
-  write_register(RTC_REG_B, regB);
-  write_register(RTC_REG_A, regA);
-}
-
-
-void write_register(int reg_addr, int value)
-{
-  intr_disable();
-  outb(RTC_INDEX, reg_addr);
-  outb(RTC_IO, value);
-  intr_enable();
-}
-
-int bcd_to_dec(int n)
-{
-  return ((n >> 4) & 0x0F) * 10 + (n & 0x0F);
-}
-
-int dec_to_bcd(int n)
-{
-  return ((n / 10) << 4) | (n % 10);
-}
-
-void usage(void)
-{
-  fprintf(stderr, "Usage: readclock [-nwW2]\n");
-  exit(1);
-}
Index: trunk/minix/commands/ibm/build
===================================================================
--- trunk/minix/commands/ibm/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/ibm/dosread.c
===================================================================
--- trunk/minix/commands/ibm/dosread.c	(revision 9)
+++ 	(revision )
@@ -1,1120 +1,0 @@
-/* dos{dir|read|write} - {list|read|write} MS-DOS disks	 Author: M. Huisjes */
-
-/* Dosdir - list MS-DOS directories. doswrite - write stdin to DOS-file
- * dosread - read DOS-file to stdout
- *
- * Author: Michiel Huisjes.
- *
- * Usage: dos... [-lra] drive [file/dir]
- *	  l: Give long listing.
- *	  r: List recursively.
- *	  a: Set ASCII bit.
- */
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <sys/times.h>
-#include <unistd.h>
-
-
-#define MAX_CLUSTER_SIZE	4096
-#define MAX_ROOT_ENTRIES	512
-#define FAT_START		512L	/* After bootsector */
-#define ROOTADDR		(FAT_START + 2L * fat_size)
-#define clus_add(cl_no)		((long) (((long) cl_no - 2L) \
-				 * (long) cluster_size \
-				 + data_start \
-			        ))
-struct dir_entry {
-  unsigned char d_name[8];
-  unsigned char d_ext[3];
-  unsigned char d_attribute;
-  unsigned char d_reserved[10];
-  unsigned short d_time;
-  unsigned short d_date;
-  unsigned short d_cluster;
-  unsigned long d_size;
-};
-
-typedef struct dir_entry DIRECTORY;
-
-#define NOT_USED	0x00
-#define ERASED		0xE5
-#define DIR		0x2E
-#define DIR_SIZE	(sizeof (struct dir_entry))
-#define SUB_DIR		0x10
-#define NIL_DIR		((DIRECTORY *) 0)
-
-#define LAST_CLUSTER12	0xFFF
-#define LAST_CLUSTER	0xFFFF
-#define FREE		0x000
-#define BAD		0xFF0
-#define BAD16		0xFFF0
-
-typedef int BOOL;
-
-#define TRUE	1
-#define FALSE	0
-#define NIL_PTR	((char *) 0)
-
-#define DOS_TIME	315532800L	/* 1970 - 1980 */
-
-#define READ			0
-#define WRITE			1
-
-#define FIND	3
-#define LABEL	4
-#define ENTRY	5
-#define find_entry(d, e, p)	directory(d, e, FIND, p)
-#define list_dir(d, e, f)	(void) directory(d, e, f, NIL_PTR)
-#define label()			directory(root, root_entries, LABEL, NIL_PTR)
-#define new_entry(d, e)		directory(d, e, ENTRY, NIL_PTR)
-
-#define is_dir(d)		((d)->d_attribute & SUB_DIR)
-
-#define STD_OUT			1
-
-char	*cmnd;
-
-static int disk;	/* File descriptor for disk I/O */
-
-static DIRECTORY root[MAX_ROOT_ENTRIES];
-static DIRECTORY save_entry;
-static char drive[] = "/dev/dosX";
-#define DRIVE_NR	(sizeof (drive) - 2)
-static char null[MAX_CLUSTER_SIZE], *device = drive, path[128];
-static long data_start;
-static long mark;	/* offset of directory entry to be written */
-static unsigned short total_clusters, cluster_size, root_entries, sub_entries;
-static unsigned long fat_size;
-
-static BOOL Rflag, Lflag, Aflag, dos_read, dos_write, dos_dir, fat_16 = 0;
-static BOOL big_endian;
-
-/* maximum size of a cooked 12bit FAT. Also Size of 16bit FAT cache
- * if not enough memory for whole FAT
- */
-#define COOKED_SIZE		8192
-/* raw FAT. Only used for 12bit FAT to make conversion easier 
- */
-static unsigned char	*raw_fat;
-/* Cooked FAT. May be only part of the FAT for 16 bit FATs
- */
-static unsigned short	*cooked_fat;
-/* lowest and highest entry in fat cache
- */
-static unsigned short	fat_low = USHRT_MAX,
-			fat_high = 0;
-static BOOL		fat_dirty = FALSE;
-static unsigned int	cache_size;
-
-
-/* Prototypes. */
-_PROTOTYPE(void usage, (char *prog_name) );
-_PROTOTYPE(unsigned c2u2, (unsigned char *ucarray) );
-_PROTOTYPE(unsigned long c4u4, (unsigned char *ucarray) );
-_PROTOTYPE(void determine, (void));
-_PROTOTYPE(int main, (int argc, char *argv []));
-_PROTOTYPE(DIRECTORY *directory, (DIRECTORY *dir, int entries, BOOL function, char *pathname) );
-_PROTOTYPE(void extract, (DIRECTORY *entry) );
-_PROTOTYPE(void make_file, (DIRECTORY *dir_ptr, int entries, char *name) );
-_PROTOTYPE(void fill_date, (DIRECTORY *entry) );
-_PROTOTYPE(char *make_name, (DIRECTORY *dir_ptr, int dir_fl) );
-_PROTOTYPE(int fill, (char *buffer, size_t size) );
-_PROTOTYPE(void xmodes, (int mode) );
-_PROTOTYPE(void show, (DIRECTORY *dir_ptr, char *name) );
-_PROTOTYPE(void free_blocks, (void));
-_PROTOTYPE(DIRECTORY *read_cluster, (unsigned int cluster) );
-_PROTOTYPE(unsigned short free_cluster, (BOOL leave_fl) );
-_PROTOTYPE(void link_fat, (unsigned int cl_1, unsigned int cl_2) );
-_PROTOTYPE(unsigned short next_cluster, (unsigned int cl_no) );
-_PROTOTYPE(char *slash, (char *str) );
-_PROTOTYPE(void add_path, (char *file, BOOL slash_fl) );
-_PROTOTYPE(void disk_io, (BOOL op, unsigned long seek, void *address, unsigned bytes) );
-_PROTOTYPE(void flush_fat, (void));
-_PROTOTYPE(void read_fat, (unsigned int cl_no));
-_PROTOTYPE(BOOL free_range, (unsigned short *first, unsigned short *last));
-_PROTOTYPE(long lmin, (long a, long b));
-
-
-void usage(prog_name)
-register char *prog_name;
-{
-  fprintf (stderr, "Usage: %s [%s\n", prog_name,
-	     (dos_dir ? "-lr] drive [dir]" : "-a] drive file"));
-  exit(1);
-}
-
-unsigned c2u2(ucarray)
-unsigned char *ucarray;
-{
-  return ucarray[0] + (ucarray[1] << 8);	/* parens vital */
-}
-
-unsigned long c4u4(ucarray)
-unsigned char *ucarray;
-{
-  return ucarray[0] + ((unsigned long) ucarray[1] << 8) +
-		      ((unsigned long) ucarray[2] << 16) +
-		      ((unsigned long) ucarray[3] << 24);
-}
-
-void determine()
-{
-  struct dosboot {
-	unsigned char cjump[2];	/* unsigneds avoid bugs */
-	unsigned char nop;
-	unsigned char name[8];
-	unsigned char cbytepers[2];	/* don't use shorts, etc */
-	unsigned char secpclus;		/* to avoid struct member */
-	unsigned char creservsec[2];	/* alignment and byte */
-	unsigned char fats;		/* order bugs */
-	unsigned char cdirents[2];
-	unsigned char ctotsec[2];
-	unsigned char media;
-	unsigned char csecpfat[2];
-	unsigned char csecptrack[2];
-	unsigned char cheads[2];
-	unsigned char chiddensec[2];
-	unsigned char dos4hidd2[2];
-	unsigned char dos4totsec[4];
-	/* Char    fill[476]; */
-  } boot;
-  unsigned short boot_magic;	/* last of boot block */
-  unsigned bytepers, reservsec, dirents;
-  unsigned secpfat, secptrack, heads, hiddensec;
-  unsigned long totsec;
-  unsigned char fat_info, fat_check;
-  unsigned short endiantest = 1;
-  int errcount = 0;
-
-  big_endian = !(*(unsigned char *)&endiantest);
-
-  /* Read Bios-Parameterblock */
-  disk_io(READ, 0L, &boot, sizeof boot);
-  disk_io(READ, 0x1FEL, &boot_magic, sizeof boot_magic);
-
-  /* Convert some arrays */
-  bytepers = c2u2(boot.cbytepers);
-  reservsec = c2u2(boot.creservsec);
-  dirents = c2u2(boot.cdirents);
-  totsec = c2u2(boot.ctotsec);
-  if (totsec == 0) totsec = c4u4(boot.dos4totsec);
-  secpfat = c2u2(boot.csecpfat);
-  secptrack = c2u2(boot.csecptrack);
-  heads = c2u2(boot.cheads);
-
-  /* The `hidden sectors' are the sectors before the partition.
-   * The calculation here is probably wrong (I think the dos4hidd2
-   * bytes are the msbs), but that doesn't matter, since the
-   * value isn't used anyway
-   */
-  hiddensec = c2u2(boot.chiddensec);
-  if (hiddensec == 0) hiddensec = c2u2 (boot.dos4hidd2);
-
-  /* Safety checking */
-  if (boot_magic != 0xAA55) {
-	fprintf (stderr, "%s: magic != 0xAA55\n", cmnd);
-	++errcount;
-  }
-
-  /* Check sectors per track instead of inadequate media byte */
-  if (secptrack < 15 &&		/* assume > 15 hard disk & wini OK */
-#ifdef SECT10			/* BIOS modified for 10 sec/track */
-      secptrack != 10 &&
-#endif
-#ifdef SECT8			/* BIOS modified for 8 sec/track */
-      secptrack != 8 &&
-#endif
-      secptrack != 9) {
-	fprintf (stderr, "%s: %d sectors per track not supported\n", cmnd, secptrack);
-	++errcount;
-  }
-  if (bytepers == 0) {
-	fprintf (stderr, "%s: bytes per sector == 0\n", cmnd);
-	++errcount;
-  }
-  if (boot.secpclus == 0) {
-	fprintf (stderr, "%s: sectors per cluster == 0\n", cmnd);
-	++errcount;
-  }
-  if (boot.fats != 2 && dos_write) {
-	fprintf (stderr, "%s: fats != 2\n", cmnd);
-	++errcount;
-  }
-  if (reservsec != 1) {
-	fprintf (stderr, "%s: reserved != 1\n", cmnd);
-	++errcount;
-  }
-  if (errcount != 0) {
-	fprintf (stderr, "%s: Can't handle disk\n", cmnd);
-	exit(2);
-  }
-
-  /* Calculate everything. */
-  if (boot.secpclus == 0) boot.secpclus = 1;
-  total_clusters =
-	(totsec - boot.fats * secpfat - reservsec -
-	 dirents * 32L / bytepers		    ) / boot.secpclus + 2;
-  	/* first 2 entries in FAT aren't used */
-  cluster_size = bytepers * boot.secpclus;
-  fat_size = (unsigned long) secpfat * (unsigned long) bytepers;
-  data_start = (long) bytepers + (long) boot.fats * fat_size
-	+ (long) dirents *32L;
-  root_entries = dirents;
-  sub_entries = boot.secpclus * bytepers / 32;
-  if (total_clusters > 4096) fat_16 = 1;
-
-  /* Further safety checking */
-  if (cluster_size > MAX_CLUSTER_SIZE) {
-	fprintf (stderr, "%s: cluster size too big\n", cmnd);
-	++errcount;
-  }
-
-  disk_io(READ, FAT_START, &fat_info, 1);
-  disk_io(READ, FAT_START + fat_size, &fat_check, 1);
-  if (fat_check != fat_info) {
-	fprintf (stderr, "%s: Disk type in FAT copy differs from disk type in FAT original.\n", cmnd);
-	++errcount;
-  }
-  if (errcount != 0) {
-	fprintf (stderr, "%s: Can't handle disk\n", cmnd);
-	exit(2);
-  }
-}
-
-int main(argc, argv)
-int argc;
-register char *argv[];
-{
-  register char *arg_ptr = slash(argv[0]);
-  DIRECTORY *entry;
-  short idx = 1;
-  char dev_nr = '0';
-
-  cmnd = arg_ptr;	/* needed for error messages */
-  if (!strcmp(arg_ptr, "dosdir"))
-	dos_dir = TRUE;
-  else if (!strcmp(arg_ptr, "dosread"))
-	dos_read = TRUE;
-  else if (!strcmp(arg_ptr, "doswrite"))
-	dos_write = TRUE;
-  else {
-	fprintf (stderr, "%s: Program should be named dosread, doswrite or dosdir.\n", cmnd);
-	exit(1);
-  }
-
-  if (argc == 1) usage(argv[0]);
-
-  if (argv[1][0] == '-') {
-	for (arg_ptr = &argv[1][1]; *arg_ptr; arg_ptr++) {
-		if (*arg_ptr == 'l' && dos_dir) {
-			Lflag = TRUE;
-		} else if (*arg_ptr == 'r' && dos_dir) {
-			Rflag = TRUE;
-		} else if (*arg_ptr == 'a' && !dos_dir) {
-			assert ('\n' == 10);
-			assert ('\r' == 13);
-			Aflag = TRUE;
-		} else {
-			usage(argv[0]);
-		}
-	}
-	idx++;
-  }
-  if (idx == argc) usage(argv[0]);
-
-  if (strlen(argv[idx]) > 1) {
-	device = argv[idx++];
-
-	/* If the device does not contain a / we assume that it
-	 * is the name of a device in /dev. Instead of prepending
-	 * /dev/ we try to chdir there.
-	 */
-	if (strchr(device, '/') == NULL && chdir("/dev") < 0) {
-		perror("/dev");
-		exit(1);
-	}
-  } else {
-	if ((dev_nr = toupper (*argv[idx++])) < 'A' || dev_nr > 'Z')
-		usage(argv[0]);
-
-	device[DRIVE_NR] = dev_nr;
-  }
-
-  if ((disk = open(device, dos_write ? O_RDWR : O_RDONLY)) < 0) {
-	fprintf (stderr, "%s: cannot open %s: %s\n",
-		 cmnd, device, strerror (errno));
-	exit(1);
-  }
-  determine();
-  disk_io(READ, ROOTADDR, root, DIR_SIZE * root_entries);
-
-  if (dos_dir && Lflag) {
-	entry = label();
-	printf ("Volume in drive %c ", dev_nr);
-	if (entry == NIL_DIR)
-		printf("has no label.\n\n");
-	else
-		printf ("is %.11s\n\n", entry->d_name);
-  }
-  if (argv[idx] == NIL_PTR) {
-	if (!dos_dir) usage(argv[0]);
-	if (Lflag) printf ("Root directory:\n");
-	list_dir(root, root_entries, FALSE);
-	if (Lflag) free_blocks();
-	fflush (stdout);
-	exit(0);
-  }
-  for (arg_ptr = argv[idx]; *arg_ptr; arg_ptr++)
-	if (*arg_ptr == '\\')	*arg_ptr = '/';
-	else		     	*arg_ptr = toupper (*arg_ptr);
-  if (*--arg_ptr == '/') *arg_ptr = '\0';	/* skip trailing '/' */
-
-  add_path(argv[idx], FALSE);
-  add_path("/", FALSE);
-
-  if (dos_dir && Lflag) printf ( "Directory %s:\n", path);
-
-  entry = find_entry(root, root_entries, argv[idx]);
-
-  if (dos_dir) {
-	list_dir(entry, sub_entries, FALSE);
-	if (Lflag) free_blocks();
-  } else if (dos_read)
-	extract(entry);
-  else {
-	if (entry != NIL_DIR) {
-		fflush (stdout);
-		if (is_dir(entry))
-			fprintf (stderr, "%s: %s is a directory.\n", cmnd, path);
-		else
-			fprintf (stderr, "%s: %s already exists.\n", cmnd, argv[idx]);
-		exit(1);
-	}
-	add_path(NIL_PTR, TRUE);
-
-	if (*path) make_file(find_entry(root, root_entries, path),
-			  sub_entries, slash(argv[idx]));
-	else
-		make_file(root, root_entries, argv[idx]);
-  }
-
-  (void) close(disk);
-  fflush (stdout);
-  exit(0);
-  return(0);
-}
-
-
-/* General directory search routine.
- * 
- * dir:
- *	Points to one or more directory entries
- * entries:
- *	number of entries
- *	if entries == root_entries, dir points to the entire
- *	root directory. Otherwise it points to a single directory
- *	entry describing the directory to be searched.
- *	
- * function:
- *	FIND ... find pathname relative to directory dir.
- *	LABEL ... find first label entry in dir.
- *	ENTRY ... create a new empty entry.
- *	FALSE ... list directory
- *
- * pathname:
- *	name of the file to be found or directory to be listed.
- *	must be in upper case, pathname components must be
- *	separated by slashes, but can be longer than than 
- *	8+3 characters (The rest is ignored).
- */
-DIRECTORY *directory(dir, entries, function, pathname)
-DIRECTORY *dir;
-int entries;
-int function;
-register char *pathname;
-{
-  register DIRECTORY *dir_ptr = dir;
-  DIRECTORY *mem = NIL_DIR;
-  unsigned short cl_no = dir->d_cluster;
-  unsigned short type, last = 0;
-  char file_name[14];
-  char *name;
-  int i = 0;
-
-  if (function == FIND) {
-	while (*pathname != '/' && *pathname != '.' && *pathname &&
-	       i < 8) {
-		file_name[i++] = *pathname++;
-	}
-	if (*pathname == '.') {
-		int j = 0;
-		file_name[i++] = *pathname++;
-		while (*pathname != '/' && *pathname != '.' && *pathname &&
-		       j++ < 3) {
-			file_name[i++] = *pathname++;
-		}
-	}
-	while (*pathname != '/' && *pathname) pathname++;
-	file_name[i] = '\0';
-  }
-  do {
-	if (entries != root_entries) {
-		mem = dir_ptr = read_cluster(cl_no);
-		last = cl_no;
-		cl_no = next_cluster(cl_no);
-	}
-	for (i = 0; i < entries; i++, dir_ptr++) {
-		type = dir_ptr->d_name[0] & 0x0FF;
-		if (function == ENTRY) {
-			if (type == NOT_USED || type == ERASED) {
-				if (!mem)
-					mark = ROOTADDR + (long) i *(long) DIR_SIZE;
-				else
-					mark = clus_add(last) + (long) i *(long) DIR_SIZE;
-				return dir_ptr;
-			}
-			continue;
-		}
-		if (type == NOT_USED) break;
-		if (dir_ptr->d_attribute & 0x08) {
-			if (function == LABEL) return dir_ptr;
-			continue;
-		}
-		if (type == DIR || type == ERASED || function == LABEL)
-			continue;
-		type = is_dir(dir_ptr);
-		name = make_name(dir_ptr,
-				 (function == FIND) ?  FALSE : type);
-		if (function == FIND) {
-			if (strcmp(file_name, name) != 0) continue;
-			if (!type) {
-				if (dos_dir || *pathname) {
-					fflush (stdout);
-					fprintf (stderr, "%s: Not a directory: %s\n", cmnd, file_name);
-					exit(1);
-				}
-			} else if (*pathname == '\0' && dos_read) {
-				fflush (stdout);
-				fprintf (stderr, "%s: %s is a directory.\n", cmnd, path);
-				exit(1);
-			}
-			if (*pathname) {
-				dir_ptr = find_entry(dir_ptr,
-					 sub_entries, pathname + 1);
-			}
-			if (mem) {
-				if (dir_ptr) {
-					memcpy((char *)&save_entry, (char *)dir_ptr, DIR_SIZE);
-					dir_ptr = &save_entry;
-				}
-				free( (void *) mem);
-			}
-			return dir_ptr;
-		} else {
-			if (function == FALSE) {
-				show(dir_ptr, name);
-			} else if (type) {	/* Recursive */
-				printf ( "Directory %s%s:\n", path, name);
-				add_path(name, FALSE);
-				list_dir(dir_ptr, sub_entries, FALSE);
-				add_path(NIL_PTR, FALSE);
-			}
-		}
-	}
-	if (mem) free( (void *) mem);
-  } while (cl_no != LAST_CLUSTER && mem);
-
-  switch (function) {
-      case FIND:
-	if (dos_write && *pathname == '\0') return NIL_DIR;
-	fflush (stdout);
-	fprintf (stderr, "%s: Cannot find `%s'.\n", cmnd, file_name);
-	exit(1);
-      case LABEL:
-	return NIL_DIR;
-      case ENTRY:
-	if (!mem) {
-		fflush (stdout);
-		fprintf (stderr, "%s: No entries left in root directory.\n", cmnd);
-		exit(1);
-	}
-	cl_no = free_cluster(TRUE);
-	link_fat(last, cl_no);
-	link_fat(cl_no, LAST_CLUSTER);
-	disk_io(WRITE, clus_add(cl_no), null, cluster_size);
-
-	return new_entry(dir, entries);
-      case FALSE:
-	if (Rflag) {
-		printf ("\n");
-		list_dir(dir, entries, TRUE);
-	}
-  }
-  return NULL;
-}
-
-void extract(entry)
-register DIRECTORY *entry;
-{
-  register unsigned short cl_no = entry->d_cluster;
-  char buffer[MAX_CLUSTER_SIZE];
-  int rest, i;
-
-  if (entry->d_size == 0)	/* Empty file */
-	return;
-
-  do {
-	disk_io(READ, clus_add(cl_no), buffer, cluster_size);
-	rest = (entry->d_size > (long) cluster_size) ? cluster_size : (short) entry->d_size;
-
-	if (Aflag) {
-		for (i = 0; i < rest; i ++) {
-			if (buffer [i] != '\r') putchar (buffer [i]);
-		}
-		if (ferror (stdout)) {
-			fprintf (stderr, "%s: cannot write to stdout: %s\n",
-				 cmnd, strerror (errno));
-			exit (1);
-		}
-	} else {
-		if (fwrite (buffer, 1, rest, stdout) != rest) {
-			fprintf (stderr, "%s: cannot write to stdout: %s\n",
-				 cmnd, strerror (errno));
-			exit (1);
-		}
-	}
-	entry->d_size -= (long) rest;
-	cl_no = next_cluster(cl_no);
-	if (cl_no == BAD16) {
-		fflush (stdout);
-		fprintf (stderr, "%s: reserved cluster value %x encountered.\n",
-			 cmnd, cl_no);
-		exit (1);
-	}
-  } while (entry->d_size && cl_no != LAST_CLUSTER);
-
-  if (cl_no != LAST_CLUSTER)
-	fprintf (stderr, "%s: Too many clusters allocated for file.\n", cmnd);
-  else if (entry->d_size != 0)
-	fprintf (stderr, "%s: Premature EOF: %ld bytes left.\n", cmnd,
-		     entry->d_size);
-}
-
-
-/* Minimum of two long values
- */
-long lmin (a, b)
-long a, b;
-{
-	if (a < b) return a;
-	else return b;
-}
-
-
-void make_file(dir_ptr, entries, name)
-DIRECTORY *dir_ptr;
-int entries;
-char *name;
-{
-  register DIRECTORY *entry = new_entry(dir_ptr, entries);
-  register char *ptr;
-  char buffer[MAX_CLUSTER_SIZE];
-  unsigned short cl_no = 0;
-  int i, r;
-  long size = 0L;
-  unsigned short first_cluster, last_cluster;
-  long chunk;
-
-  memset (&entry->d_name[0], ' ', 11);    /* clear entry */
-  for (i = 0, ptr = name; i < 8 && *ptr != '.' && *ptr; i++)
-	entry->d_name[i] = *ptr++;
-  while (*ptr != '.' && *ptr) ptr++;
-  if (*ptr == '.') ptr++;
-  for (i = 0; i < 3 && *ptr != '.' && *ptr; i++) entry->d_ext[i] = *ptr++;
-
-  for (i = 0; i < 10; i++) entry->d_reserved[i] = '\0';
-  entry->d_attribute = '\0';
-
-  entry->d_cluster = 0;
-
-  while (free_range (&first_cluster, &last_cluster)) {
-	do {
-		unsigned short	nr_clus;
-
-		chunk = lmin ((long) (last_cluster - first_cluster + 1) *
-			     		  cluster_size,
-			      (long) MAX_CLUSTER_SIZE);
-		r = fill(buffer, chunk);
-		if (r == 0) goto done;
-		nr_clus = (r + cluster_size - 1) / cluster_size;
-		disk_io(WRITE, clus_add(first_cluster), buffer, r);
-
-		for (i = 0; i < nr_clus; i ++) {
-			if (entry->d_cluster == 0)
-				cl_no = entry->d_cluster = first_cluster;
-			else {
-				link_fat(cl_no, first_cluster);
-				cl_no = first_cluster;
-			}
-			first_cluster ++;
-		}
-
-		size += r;
-	} while (first_cluster <= last_cluster);
-  }
-  fprintf (stderr, "%s: disk full. File truncated\n", cmnd);
-done:
-  if (entry->d_cluster != 0) link_fat(cl_no, LAST_CLUSTER);
-  entry->d_size = size;
-  fill_date(entry);
-  disk_io(WRITE, mark, entry, DIR_SIZE);
-
-  if (fat_dirty) flush_fat ();
-
-}
-
-
-#define SEC_MIN	60L
-#define SEC_HOUR	(60L * SEC_MIN)
-#define SEC_DAY	(24L * SEC_HOUR)
-#define SEC_YEAR	(365L * SEC_DAY)
-#define SEC_LYEAR	(366L * SEC_DAY)
-
-unsigned short mon_len[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
-void fill_date(entry)
-DIRECTORY *entry;
-{
-  register long cur_time = time((long *) 0) - DOS_TIME;
-  unsigned short year = 0, month = 1, day, hour, minutes, seconds;
-  int i;
-  long tmp;
-
-  if (cur_time < 0)		/* Date not set on booting ... */
-	cur_time = 0;
-  for (;;) {
-	tmp = (year % 4 == 0) ? SEC_LYEAR : SEC_YEAR;
-	if (cur_time < tmp) break;
-	cur_time -= tmp;
-	year++;
-  }
-
-  day = (unsigned short) (cur_time / SEC_DAY);
-  cur_time -= (long) day *SEC_DAY;
-
-  hour = (unsigned short) (cur_time / SEC_HOUR);
-  cur_time -= (long) hour *SEC_HOUR;
-
-  minutes = (unsigned short) (cur_time / SEC_MIN);
-  cur_time -= (long) minutes *SEC_MIN;
-
-  seconds = (unsigned short) cur_time;
-
-  mon_len[1] = (year % 4 == 0) ? 29 : 28;
-  i = 0;
-  while (day >= mon_len[i]) {
-	month++;
-	day -= mon_len[i++];
-  }
-  day++;
-
-  entry->d_date = (year << 9) | (month << 5) | day;
-  entry->d_time = (hour << 11) | (minutes << 5) | seconds;
-}
-
-char *make_name(dir_ptr, dir_fl)
-register DIRECTORY *dir_ptr;
-short dir_fl;
-{
-  static char name_buf[14];
-  register char *ptr = name_buf;
-  short i;
-
-  for (i = 0; i < 8; i++) *ptr++ = dir_ptr->d_name[i];
-
-  while (*--ptr == ' ');
-  assert (ptr >= name_buf);
-
-  ptr++;
-  if (dir_ptr->d_ext[0] != ' ') {
-	*ptr++ = '.';
-	for (i = 0; i < 3; i++) *ptr++ = dir_ptr->d_ext[i];
-	while (*--ptr == ' ');
-	ptr++;
-  }
-  if (dir_fl) *ptr++ = '/';
-  *ptr = '\0';
-
-  return name_buf;
-}
-
-
-int fill(buffer, size)
-register char *buffer;
-size_t	size;
-{
-  static BOOL nl_mark = FALSE;
-  char *last = &buffer[size];
-  char *begin = buffer;
-  register int c;
-
-  while (buffer < last) {
-  	if (nl_mark) {
-  		*buffer ++ = '\n';
-  		nl_mark = FALSE;
-  	} else {
-		c = getchar();
-		if (c == EOF) break;
-		if (Aflag && c == '\n') {
-			*buffer ++ = '\r';
-			nl_mark = TRUE;
-		} else {
-			*buffer++ = c;
-		}
-	}
-  }
-
-  return (buffer - begin);
-}
-
-#define HOUR	0xF800		/* Upper 5 bits */
-#define MIN	0x07E0		/* Middle 6 bits */
-#define YEAR	0xFE00		/* Upper 7 bits */
-#define MONTH	0x01E0		/* Mid 4 bits */
-#define DAY	0x01F		/* Lowest 5 bits */
-
-char *month[] = {
-	 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-	 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-void xmodes(mode)
-int mode;
-{
-  printf ( "\t%c%c%c%c%c", (mode & SUB_DIR) ? 'd' : '-',
-	     (mode & 02) ? 'h' : '-', (mode & 04) ? 's' : '-',
-	     (mode & 01) ? '-' : 'w', (mode & 0x20) ? 'a' : '-');
-}
-
-void show(dir_ptr, name)
-DIRECTORY *dir_ptr;
-char *name;
-{
-  register unsigned short e_date = dir_ptr->d_date;
-  register unsigned short e_time = dir_ptr->d_time;
-  unsigned short next;
-  char bname[20];
-  short i = 0;
-
-  while (*name && *name != '/') bname[i++] = *name++;
-  bname[i] = '\0';
-  if (!Lflag) {
-	printf ( "%s\n", bname);
-	return;
-  }
-  xmodes( (int) dir_ptr->d_attribute);
-  printf ( "\t%s%s", bname, strlen(bname) < 8 ? "\t\t" : "\t");
-  i = 1;
-  if (is_dir(dir_ptr)) {
-	next = dir_ptr->d_cluster;
-	while ((next = next_cluster(next)) != LAST_CLUSTER) i++;
-	printf ("%8ld", (long) i * (long) cluster_size);
-  } else
-	printf ("%8ld", dir_ptr->d_size);
-  printf (" %02d:%02d %2d %s %d\n", ((e_time & HOUR) >> 11),
-	     ((e_time & MIN) >> 5), (e_date & DAY),
-   month[((e_date & MONTH) >> 5) - 1], ((e_date & YEAR) >> 9) + 1980);
-}
-
-void free_blocks()
-{
-  register unsigned short cl_no;
-  long nr_free = 0;
-  long nr_bad = 0;
-
-  for (cl_no = 2; cl_no < total_clusters; cl_no++) {
-	switch (next_cluster(cl_no)) {
-	    case FREE:	nr_free++;	break;
-	    case BAD16:	nr_bad++;	break;
-	}
-  }
-
-  printf ("Free space: %ld bytes.\n", nr_free * (long) cluster_size);
-  if (nr_bad != 0)
-	printf ("Bad sectors: %ld bytes.\n", nr_bad * (long) cluster_size);
-}
-
-
-DIRECTORY *read_cluster(cluster)
-register unsigned int cluster;
-{
-  register DIRECTORY *sub_dir;
-
-  if ((sub_dir = malloc(cluster_size)) == NULL) {
-	fprintf (stderr, "%s: Cannot set break!\n", cmnd);
-	exit(1);
-  }
-  disk_io(READ, clus_add(cluster), sub_dir, cluster_size);
-
-  return sub_dir;
-}
-
-static unsigned short cl_index = 2;
-
-/* find a range of consecutive free clusters. Return TRUE if found
- * and return the first and last cluster in the |*first| and |*last|.
- * If no free clusters are left, return FALSE.
- *
- * Warning: Assumes that all of the range is used before the next call
- *	to free_range or free_cluster.
- */
-BOOL free_range (first, last)
-unsigned short *first, *last;
-{
-  while (cl_index < total_clusters && next_cluster(cl_index) != FREE)
-	cl_index++;
-  if (cl_index >= total_clusters) return FALSE;
-  *first = cl_index;
-  while (cl_index < total_clusters && next_cluster(cl_index) == FREE)
-	cl_index++;
-  *last = cl_index - 1;
-  return TRUE;
-}
-
-
-/* find a free cluster.
- * Return the number of the free cluster or a number > |total_clusters|
- * if none is found.
- * If |leave_fl| is TRUE, the the program will be terminated if 
- * no free cluster can be found
- *
- * Warning: Assumes that the cluster is used before the next call
- *	to free_range or free_cluster.
- */
-unsigned short free_cluster(leave_fl)
-BOOL leave_fl;
-{
-  while (cl_index < total_clusters && next_cluster(cl_index) != FREE)
-	cl_index++;
-
-  if (leave_fl && cl_index >= total_clusters) {
-	fprintf (stderr, "%s: Diskette full. File not added.\n", cmnd);
-	exit(1);
-  }
-  return cl_index++;
-}
-
-
-/* read a portion of the fat containing |cl_no| into the cache
- */
-void read_fat (cl_no) 
-  unsigned int cl_no;
-{
-
-  if (!cooked_fat) {
-  	/* Read the fat for the first time. We have to allocate all the
-  	 * buffers
-  	 */
-  	if (fat_16) {
-		/* FAT consists of little endian shorts. Easy to convert
-		 */
-		if ((cooked_fat = malloc (fat_size)) == NULL) {
-			/* Oops, FAT doesn't fit into memory, just read
-			 * a chunk
-			 */
-			if ((cooked_fat = malloc (COOKED_SIZE)) == NULL) {
-				fprintf (stderr, "%s: not enough memory for FAT cache. Use chmem\n",
-					 cmnd);
-				exit (1);
-			}
-			cache_size = COOKED_SIZE / 2;
-		} else {
-			cache_size = fat_size / 2;
-		}
-	} else {
-		/* 12 bit FAT. Difficult encoding, but small. Keep
-		 * both raw FAT and cooked version in memory.
-		 */
-		if ((cooked_fat = malloc (total_clusters * sizeof (short))) == NULL ||
-		    (raw_fat = malloc (fat_size)) == NULL) {
-			fprintf (stderr, "%s: not enough memory for FAT cache. Use chmem\n",
-				 cmnd);
-			exit (1);
-		}
-		cache_size = total_clusters;
-	}
-  }
-  fat_low = cl_no / cache_size * cache_size;
-  fat_high = fat_low + cache_size - 1;
-
-  if (!fat_16) {
-  	unsigned short	*cp;
-  	unsigned char	*rp;
-  	unsigned short	i;
-
-	disk_io (READ, FAT_START, raw_fat, fat_size);
-	for (rp = raw_fat, cp = cooked_fat, i = 0;
-	     i < cache_size;
-	     rp += 3, i += 2) {
-	     	*cp = *rp + ((*(rp + 1) & 0x0f) << 8);
-	     	if (*cp == BAD) *cp = BAD16;
-	     	else if (*cp == LAST_CLUSTER12) *cp = LAST_CLUSTER;
-	     	cp ++;
-	     	*cp = ((*(rp + 1) & 0xf0) >> 4) + (*(rp + 2) << 4);
-	     	if (*cp == BAD) *cp = BAD16;
-	     	else if (*cp == LAST_CLUSTER12) *cp = LAST_CLUSTER;
-	     	cp ++;
-	}
-  } else {
-
-	assert (sizeof (short) == 2);
-	assert (CHAR_BIT == 8);		/* just in case */
-
-	disk_io (READ, FAT_START + fat_low * 2, (void *)cooked_fat, cache_size * 2);
-	if (big_endian) {
-		unsigned short	*cp;
-		unsigned char	*rp;
-		unsigned short	i;
-
-		for (i = 0, rp = (unsigned char *)cooked_fat /* sic */, cp = cooked_fat;
-		     i < cache_size;
-		     rp += 2, cp ++, i ++) {
-		     	*cp = c2u2 (rp);
-		}
-	}
-  }
-}
-
-
-/* flush the fat cache out to disk
- */
-void flush_fat ()
-{
-  if (fat_16) {
-	if (big_endian) {
-		unsigned short	*cp;
-		unsigned char	*rp;
-		unsigned short	i;
-
-		for (i = 0, rp = (unsigned char *)cooked_fat /* sic */, cp = cooked_fat;
-		     i < cache_size;
-		     rp += 2, cp ++, i ++) {
-		     	*rp = *cp;
-		     	*(rp + 1) = *cp >> 8;
-		}
-	}
-	disk_io (WRITE, FAT_START + fat_low * 2, (void *)cooked_fat, cache_size * 2);
-	disk_io (WRITE, FAT_START + fat_size + fat_low * 2, (void *)cooked_fat, cache_size * 2);
-  } else {
-  	unsigned short	*cp;
-  	unsigned char	*rp;
-  	unsigned short	i;
-
-	for (rp = raw_fat, cp = cooked_fat, i = 0;
-	     i < cache_size;
-	     rp += 3, cp += 2, i += 2) {
-	     	*rp = *cp;
-	     	*(rp + 1) = ((*cp & 0xf00) >> 8) |
-	     		    ((*(cp + 1) & 0x00f) << 4);
-	     	*(rp + 2) = ((*(cp + 1) & 0xff0) >> 4);
-	}
-	disk_io (WRITE, FAT_START, raw_fat, fat_size);
-	disk_io (WRITE, FAT_START + fat_size, raw_fat, fat_size);
-  }
-}
-
-
-/* make cl_2 the successor of cl_1
- */
-void link_fat(cl_1, cl_2)
-unsigned int cl_1;
-unsigned int cl_2;
-{
-  if (cl_1 < fat_low || cl_1 > fat_high) {
-  	if (fat_dirty) flush_fat ();
-  	read_fat (cl_1);
-  }
-  cooked_fat [cl_1 - fat_low] = cl_2;
-  fat_dirty = TRUE;
-}
-
-
-unsigned short next_cluster(cl_no)
-register unsigned int cl_no;
-{
-  if (cl_no < fat_low || cl_no > fat_high) {
-  	if (fat_dirty) flush_fat ();
-  	read_fat (cl_no);
-  }
-  return cooked_fat [cl_no - fat_low];
-}
-
-char *slash(str)
-register char *str;
-{
-  register char *result = str;
-
-  while (*str)
-	if (*str++ == '/') result = str;
-
-  return result;
-}
-
-void add_path(file, slash_fl)
-char *file;
-BOOL slash_fl;
-{
-  register char *ptr = path;
-
-  while (*ptr) ptr++;
-
-  if (file == NIL_PTR) {
-	if (ptr != path) ptr--;
-	if (ptr != path) do {
-			ptr--;
-		} while (*ptr != '/' && ptr != path);
-	if (ptr != path && !slash_fl) *ptr++ = '/';
-	*ptr = '\0';
-  } else
-	strcpy (ptr, file);
-}
-
-
-void disk_io(op, seek, address, bytes)
-register BOOL op;
-unsigned long seek;
-void *address;
-register unsigned bytes;
-{
-  unsigned int r;
-
-  if (lseek(disk, seek, SEEK_SET) < 0L) {
-	fflush (stdout);
-	fprintf (stderr, "%s: Bad lseek: %s\n", cmnd, strerror (errno));
-	exit(1);
-  }
-  if (op == READ)
-	r = read(disk, (char *) address, bytes);
-  else {
-	r = write(disk, (char *) address, bytes);
-  }
-
-  if (r != bytes) {
-  	fprintf (stderr, "%s: read error: %s\n", cmnd, strerror (errno));
-  	exit (1);
-  }
-}
-
-char dosread_c_rcs_id [] = 
-	"$Id: dosread.c,v 1.2 2005/07/13 10:02:14 beng Exp $";
Index: trunk/minix/commands/ibm/fdisk.c
===================================================================
--- trunk/minix/commands/ibm/fdisk.c	(revision 9)
+++ 	(revision )
@@ -1,1009 +1,0 @@
-/* fdisk - partition a hard disk	Author: Jakob Schripsema */
-
-/* Run this with:
- *
- *	fdisk [-hheads] [-ssectors] [device]
- *
- * e.g.,
- *
- *	fdisk				(to get the default)
- *	fdisk -h4 -s17 /dev/hd0		(MINIX default)
- *	fdisk -h4 -s17 c:		(DOS default)
- *	fdisk -h6 -s25 /dev/hd5		(second drive, probably RLL)
- *	fdisk junkfile			(to experiment safely)
- *
- * The device is opened in read-only mode if the file permissions do not
- * permit read-write mode, so it is convenient to use a login account with
- * only read permission to look at the partition table safely.
- *
- * Compile with:
- *
- *	cc -i -o fdisk fdisk.c		(MINIX)
- *	cl -DDOS fdisk.c		(DOS with MS C compiler)
- *
- * This was modified extensively by Bruce Evans 28 Dec 89.
- * The new version has not been tried with DOS.  The open modes are suspect
- * (everyone should convert to use fcntl.h).
- *
- * Changed 18 Dec 92 by Kees J. Bot: Bootstrap code and geometry from device.
- *
- * modified 01 March 95 by asw: updated list of known partition types. Also
- * changed display format slightly to allow for partition type names of
- * up to 9 chars (previous format allowed for 7, but there were already
- * some 8 char names in the list).
-*/
-
-#include <sys/types.h>
-#include <ibm/partition.h>
-#include <minix/partition.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-
-#ifdef DOS
-#include <dos.h>
-#define DEFAULT_DEV	"c:"
-#define LOAD_OPEN_MODE	0x8000
-#define SAVE_CREAT_MODE	0644
-#else
-#define DEFAULT_DEV	"/dev/hd0"
-#define LOAD_OPEN_MODE	0
-#define SAVE_CREAT_MODE	0644
-#define UNIX			/* for MINIX */
-#endif
-
-/* Constants */
-
-#define	DEFAULT_NHEAD	4	/* # heads		 */
-#define	DEFAULT_NSEC	17	/* sectors / track	 */
-#define SECSIZE		512	/* sector size		 */
-#define	OK		0
-#define	ERR		1
-
-#define CYL_MASK	0xc0	/* mask to extract cyl bits from sec field */
-#define CYL_SHIFT	2	/* shift to extract cyl bits from sec field */
-#define SEC_MASK	0x3f	/* mask to extract sec bits from sec field */
-
-/* Globals  */
-char rawsecbuf[SECSIZE + sizeof(long)];
-char *secbuf;
-int badbases;
-int badsizes;
-int badorders;
-char *devname;
-int nhead;
-int nsec;
-int ncyl = 1024;
-int readonly;
-int override= 0;
-
-_PROTOTYPE(int main, (int argc, char *argv []));
-_PROTOTYPE(void getgeom, (void));
-_PROTOTYPE(int getboot, (char *buffer));
-_PROTOTYPE(int putboot, (char *buffer));
-_PROTOTYPE(int load_from_file, (void));
-_PROTOTYPE(int save_to_file, (void));
-_PROTOTYPE(int dpl_partitions, (int rawflag));
-_PROTOTYPE(int chk_table, (void));
-_PROTOTYPE(int sec_to_hst, (long logsec, unsigned char *hd, unsigned char *sec,
-							 unsigned char *cyl));
-_PROTOTYPE(int mark_partition, (struct part_entry *pe));
-_PROTOTYPE(int change_partition, (struct part_entry *entry));
-_PROTOTYPE(int get_a_char, (void));
-_PROTOTYPE(int print_menu, (void));
-_PROTOTYPE(void adj_base, (struct part_entry *pe));
-_PROTOTYPE(void adj_size, (struct part_entry *pe));
-_PROTOTYPE(struct part_entry *ask_partition, (void));
-_PROTOTYPE(void footnotes, (void));
-_PROTOTYPE(int get_an_int, (char *prompt, int *intptr));
-_PROTOTYPE(void list_part_types, (void));
-_PROTOTYPE(void mark_npartition, (struct part_entry *pe));
-_PROTOTYPE(int mygets, (char *buf, int length));
-_PROTOTYPE(char *systype, (int type));
-_PROTOTYPE(void toggle_active, (struct part_entry *pe));
-_PROTOTYPE(void usage, (void));
-
-/* One featureful master bootstrap. */
-char bootstrap[] = {
-0353,0001,0000,0061,0300,0216,0330,0216,0300,0372,0216,0320,0274,0000,0174,0373,
-0275,0276,0007,0211,0346,0126,0277,0000,0006,0271,0000,0001,0374,0363,0245,0352,
-0044,0006,0000,0000,0264,0002,0315,0026,0250,0010,0164,0033,0350,0071,0001,0174,
-0007,0060,0344,0315,0026,0242,0205,0007,0054,0060,0074,0012,0163,0363,0120,0350,
-0046,0001,0205,0007,0130,0353,0012,0240,0002,0006,0204,0300,0165,0003,0351,0147,
-0000,0230,0262,0005,0366,0362,0262,0200,0000,0302,0210,0340,0120,0350,0234,0000,
-0163,0003,0351,0147,0000,0130,0054,0001,0175,0003,0351,0141,0000,0276,0276,0175,
-0211,0357,0271,0040,0000,0363,0245,0200,0301,0004,0211,0356,0215,0174,0020,0070,
-0154,0004,0164,0016,0213,0135,0010,0053,0134,0010,0213,0135,0012,0033,0134,0012,
-0163,0014,0212,0044,0206,0144,0020,0210,0044,0106,0071,0376,0162,0364,0211,0376,
-0201,0376,0356,0007,0162,0326,0342,0322,0211,0356,0264,0020,0366,0344,0001,0306,
-0200,0174,0004,0001,0162,0026,0353,0021,0204,0322,0175,0041,0211,0356,0200,0174,
-0004,0000,0164,0013,0366,0004,0200,0164,0006,0350,0070,0000,0162,0053,0303,0203,
-0306,0020,0201,0376,0376,0007,0162,0346,0350,0215,0000,0211,0007,0376,0302,0204,
-0322,0174,0023,0315,0021,0321,0340,0321,0340,0200,0344,0003,0070,0342,0167,0355,
-0350,0011,0000,0162,0350,0303,0350,0003,0000,0162,0146,0303,0211,0356,0214,0134,
-0010,0214,0134,0012,0277,0003,0000,0122,0006,0127,0264,0010,0315,0023,0137,0007,
-0200,0341,0077,0376,0306,0210,0310,0366,0346,0211,0303,0213,0104,0010,0213,0124,
-0012,0367,0363,0222,0210,0325,0366,0361,0060,0322,0321,0352,0321,0352,0010,0342,
-0210,0321,0376,0301,0132,0210,0306,0273,0000,0174,0270,0001,0002,0315,0023,0163,
-0020,0200,0374,0200,0164,0011,0117,0174,0006,0060,0344,0315,0023,0163,0270,0371,
-0303,0201,0076,0376,0175,0125,0252,0165,0001,0303,0350,0013,0000,0243,0007,0353,
-0005,0350,0004,0000,0227,0007,0353,0376,0136,0255,0126,0211,0306,0254,0204,0300,
-0164,0011,0264,0016,0273,0001,0000,0315,0020,0353,0362,0303,0057,0144,0145,0166,
-0057,0150,0144,0077,0010,0000,0015,0012,0000,0116,0157,0156,0145,0040,0141,0143,
-0164,0151,0166,0145,0015,0012,0000,0122,0145,0141,0144,0040,0145,0162,0162,0157,
-0162,0040,0000,0116,0157,0164,0040,0142,0157,0157,0164,0141,0142,0154,0145,0040,
-0000,0000,
-};
-
-main(argc, argv)
-int argc;
-char *argv[];
-{
-  int argn;
-  char *argp;
-  int ch;
-
-  /* Init */
-
-  nhead = DEFAULT_NHEAD;
-  nsec = DEFAULT_NSEC;
-  for (argn = 1; argn < argc && (argp = argv[argn])[0] == '-'; ++argn) {
-	if (argp[1] == 'h')
-		nhead = atoi(argp + 2);
-	else
-		if (argp[1] == 's') nsec = atoi(argp + 2);
-	else
-		usage();
-	override= 1;
-  }
-
-  if (argn == argc)
-	devname = DEFAULT_DEV;
-  else if (argn == argc - 1)
-	devname = argv[argn];
-  else
-	usage();
-
-  /* Align the sector buffer in such a way that the partition table is at
-   * a mod 4 offset in memory.  Some weird people add alignment checks to
-   * their Minix!
-   */
-  secbuf = rawsecbuf;
-  while ((long)(secbuf + PART_TABLE_OFF) % sizeof(long) != 0) secbuf++;
-
-  getgeom();
-  getboot(secbuf);
-  chk_table();
-
-  do {
-	putchar('\n');
-	dpl_partitions(0);
-	printf(
-	  "\n(Enter 'h' for help.  A null line will abort any operation) ");
-	ch = get_a_char();
-	putchar('\n');
-	switch (ch) {
-	    case '+':	footnotes();			break;
-	    case 'a':	toggle_active(ask_partition());	break;
-	    case 'B':	adj_base(ask_partition()); 	break;
-	    case 'c':	change_partition(ask_partition());	break;
-	    case 'h':	print_menu();			break;
-	    case 'l':	load_from_file();	  	break;
-	    case 'm':	mark_partition(ask_partition());	break;
-	    case 'n':	mark_npartition(ask_partition());	break;
-	    case 'p':	dpl_partitions(1);  		break;
-	    case 0:
-	    case 'q':	exit(0);
-	    case 'S':	adj_size(ask_partition()); 	break;
-	    case 's':	save_to_file();	  		break;
-	    case 't':	list_part_types();	 	break;
-	    case 'v':
-		printf("Partition table is %svalid\n",
-			chk_table() == OK ? "" : "in");
-		break;
-	    case 'w':
-		if (readonly)
-			printf("Write disabled\n");
-		else if(chk_table() == OK) {
-			putboot(secbuf);
-			printf(
-	"Partition table has been updated and the file system synced.\n");
-			printf("Please reboot now.\n");
-			exit(0);
-		} else
-			printf("Not written\n");
-		break;
-	    default:	printf(" %c ????\n", ch);	break;
-  	}
-  }
-  while (1);
-}
-
-
-#ifdef UNIX
-
-void getgeom()
-{
-  struct partition geom;
-  int fd, r;
-
-  if (override) return;
-
-  if ((fd= open(devname, O_RDONLY)) < 0) return;
-
-  r = ioctl(fd, DIOCGETP, &geom);
-  close(fd);
-  if (r < 0) return;
-
-  nhead = geom.heads;
-  nsec = geom.sectors;
-  ncyl = geom.cylinders;
-
-  printf("Geometry of %s: %dx%dx%d\n", devname, ncyl, nhead, nsec);
-}
-
-static int devfd;
-
-getboot(buffer)
-char *buffer;
-{
-  devfd = open(devname, 2);
-  if (devfd < 0) {
-	printf("No write permission on %s\n", devname);
-	readonly = 1;
-	devfd = open(devname, 0);
-  }
-  if (devfd < 0) {
-	printf("Cannot open device %s\n", devname);
-	exit(1);
-  }
-  if (read(devfd, buffer, SECSIZE) != SECSIZE) {
-	printf("Cannot read boot sector\n");
-	exit(1);
-  }
-  if (* (unsigned short *) &buffer[510] != 0xAA55) {
-	printf("Invalid boot sector on %s.\n", devname);
-	printf("Partition table reset and boot code installed.\n");
-	memset(buffer, 0, 512);
-	memcpy(buffer, bootstrap, sizeof(bootstrap));
-	* (unsigned short *) &buffer[510] = 0xAA55;
-  }
-}
-
-putboot(buffer)
-char *buffer;
-{
-  if (lseek(devfd, 0L, 0) < 0) {
-	printf("Seek error during write\n");
-	exit(1);
-  }
-  if (write(devfd, buffer, SECSIZE) != SECSIZE) {
-	printf("Write error\n");
-	exit(1);
-  }
-  sync();
-}
-
-#endif
-
-
-load_from_file()
-{
-/* Load buffer from file  */
-
-  char file[80];
-  int fd;
-
-  printf("Enter name of file to load from: ");
-  if (!mygets(file, (int) sizeof file)) return;
-  fd = open(file, LOAD_OPEN_MODE);
-  if (fd < 0) {
-	printf("Cannot open %s\n", file);
-	return;
-  }
-  if (read(fd, secbuf, SECSIZE) != SECSIZE || close(fd) != 0) {
-	printf("Read error\n");
-	exit(1);
-  }
-  printf("Loaded from %s OK\n", file);
-  chk_table();
-}
-
-
-save_to_file()
-{
-/* Save to file  */
-
-  char file[80];
-  int fd;
-
-  printf("Enter name of file to save to: ");
-  if (!mygets(file, (int) sizeof file)) return;
-  if(chk_table() != OK) printf("Saving anyway\n");
-  fd = creat(file, SAVE_CREAT_MODE);
-#ifdef DOS
-  if (fd < 0) {
-	printf("Cannot creat %s\n", file);
-	return;
-  }
-  close(fd);
-  fd = open(file, 0x8001);
-#endif
-  if (fd < 0)
-	printf("Cannot open %s\n", file);
-  else if (write(fd, secbuf, SECSIZE) != SECSIZE || close(fd) != 0)
-	printf("Write error\n");
-  else
-	printf("Saved to %s OK\n", file);
-}
-
-
-dpl_partitions(rawflag)
-int rawflag;
-{
-/* Display partition table */
-
-  char active[5];
-  char basefootnote;
-  int cyl_mask;
-  int devnum;
-  char *format;
-  int i;
-  int i1;
-  char orderfootnote;
-  struct part_entry *pe;
-  struct part_entry *pe1;
-  int sec_mask;
-  char sizefootnote;
-  char type[10];
-
-  badbases = 0;
-  badsizes = 0;
-  badorders = 0;
-  if (rawflag) {
-	cyl_mask = 0;		/* no contribution of cyl to sec */
-	sec_mask = 0xff;
-        format =
-"%2d   %3d%c  %4s %-9s  x%02x %3d  x%02x   x%02x %3d  x%02x %7ld%c%7ld %7ld%c\n";
-  } else {
-	cyl_mask = CYL_MASK;
-	sec_mask = SEC_MASK;
-	format =
-"%2d   %3d%c  %4s %-9s %4d %3d %3d   %4d %3d  %3d %7ld%c%7ld %7ld%c\n";
-  }
-  printf(
-"                          ----first----  -----last----  --------sectors-------\n"
-	);
-  printf(
-"Num Sorted Act  Type     Cyl Head Sec   Cyl Head Sec    Base    Last    Size\n"
-	);
-  pe = (struct part_entry *) &secbuf[PART_TABLE_OFF];
-  for (i = 1; i <= NR_PARTITIONS; i++, pe++) {
-	if (rawflag) {
-		sprintf(active, "0x%02x", pe->bootind);
-		sprintf(type, "0x%02x", pe->sysind);
-	} else {
-		sprintf(active, "%s", pe->bootind == ACTIVE_FLAG ? "A  " : "");
-		sprintf(type, "%s", systype(pe->sysind));
-	}
-
-	/* Prepare warnings about confusing setups from old versions. */
-	basefootnote = orderfootnote = sizefootnote = ' ';
-	if (pe->sysind == MINIX_PART && pe->lowsec & 1) {
-		basefootnote = '+';
-		++badbases;
-	}
-	if (pe->size & 1) {
-		sizefootnote = '-';
-		++badsizes;
-	}
-
-	/* Calculate the "device numbers" resulting from the misguided sorting
-	 * in the wini drivers.  The drivers use this conditional for
-	 * swapping wn[j] > wn[j+1]:
-	 *
-	 *	if ((wn[j].wn_low == 0 && wn[j+1].wn_low != 0) ||
-	 *	    (wn[j].wn_low > wn[j+1].wn_low && wn[j+1].wn_low != 0)) {
-	 *
-	 * which simplifies to:
-	 *
-	 *	if (wn[j+1].wn_low != 0 &&
-	 *	    (wn[j].wn_low == 0 || wn[j].wn_low > wn[j+1].wn_low)) {
-	 */
-	devnum = 1;
-	for (i1 = 1, pe1 = (struct part_entry *) &secbuf[PART_TABLE_OFF];
-	     i1 <= NR_PARTITIONS; ++i1, ++pe1)
-		if (pe1->lowsec == 0 && pe->lowsec == 0 && pe1 < pe ||
-		    pe1->lowsec != 0 &&
-		    (pe->lowsec == 0 || pe->lowsec > pe1->lowsec))
-			++devnum;	/* pe1 contents < pe contents */
-	if (devnum != i) {
-		orderfootnote = '#';
-		++badorders;
-	}
-
-	printf(format,
-		i,
-		devnum,
-		orderfootnote,
-		active,
-		type,
-		pe->start_cyl + ((pe->start_sec & cyl_mask) << CYL_SHIFT),
-		pe->start_head,
-		pe->start_sec & sec_mask,
-		pe->last_cyl + ((pe->last_sec & cyl_mask) << CYL_SHIFT),
-		pe->last_head,
-		pe->last_sec & sec_mask,
-		pe->lowsec,
-		basefootnote,
-		pe->lowsec + (pe->size == 0 ? 0 : pe->size - 1),
-		pe->size,
-		sizefootnote);
-  }
-}
-
-
-int chk_table()
-{
-/* Check partition table */
-
-  int active;
-  unsigned char cylinder;
-  unsigned char head;
-  int i;
-  int i1;
-  int maxhead;
-  int maxsec;
-  struct part_entry *pe;
-  struct part_entry *pe1;
-  unsigned char sector;
-  int seenpart;
-  int status;
-
-  active = 0;
-  maxhead = 0;
-  maxsec = 0;
-  pe = (struct part_entry *) &secbuf[PART_TABLE_OFF];
-  seenpart = 0;
-  status = OK;
-  for (i = 1; i <= NR_PARTITIONS; i++, ++pe) {
-	if (pe->bootind == ACTIVE_FLAG) active++;
-	sec_to_hst(pe->lowsec, &head, &sector, &cylinder);
-	if (pe->size == 0 && pe->lowsec == 0) sector = 0;
-	if (head != pe->start_head || sector != pe->start_sec ||
-	    cylinder != pe->start_cyl) {
-		printf("Inconsistent base in partition %d.\n", i);
-		printf("Suspect head and sector parameters.\n");
-		status = ERR;
-	}
-	if (pe->size != 0 || pe->lowsec != 0)
-	      sec_to_hst(pe->lowsec + pe->size - 1, &head, &sector, &cylinder);
-	if (head != pe->last_head || sector != pe->last_sec ||
-	    cylinder != pe->last_cyl) {
-		printf("Inconsistent size in partition %d.\n", i);
-		printf("Suspect head and sector parameters.\n");
-		status = ERR;
-	}
-	if (pe->size == 0) continue;
-	seenpart = 1;
-	for (i1 = i + 1, pe1 = pe + 1; i1 <= NR_PARTITIONS; ++i1, ++pe1) {
-		if (pe->lowsec >= pe1->lowsec &&
-		    pe->lowsec < pe1->lowsec + pe1->size ||
-		    pe->lowsec + pe->size - 1 >= pe1->lowsec &&
-		    pe->lowsec + pe->size - 1 < pe1->lowsec + pe1->size)
-		{
-			printf("Overlap between partitions %d and %d\n",
-				i, i1);
-			status = ERR;
-		}
-	}
-	if (pe->lowsec + pe->size < pe->lowsec) {
-		printf("Overflow from preposterous size in partition %d.\n",
-			i);
-		status = ERR;
-	}
-	if (maxhead < pe->start_head) maxhead = pe->start_head;
-	if (maxhead < pe->last_head) maxhead = pe->last_head;
-	if (maxsec < (pe->start_sec & SEC_MASK))
-		maxsec = (pe->start_sec & SEC_MASK);
-	if (maxsec < (pe->last_sec & SEC_MASK))
-		maxsec = (pe->last_sec & SEC_MASK);
-  }
-  if (seenpart) {
-	if (maxhead + 1 != nhead || maxsec != nsec) {
-		printf(
-	"Disk appears to have mis-specified number of heads or sectors.\n");
-		printf("Try  fdisk -h%d -s%d %s  instead of\n",
-			maxhead + 1, maxsec, devname);
-		printf("     fdisk -h%d -s%d %s\n", nhead, nsec, devname);
-		seenpart = 0;
-	}
-  } else {
-	printf(
-	"Empty table - skipping test on number of heads and sectors.\n");
-	printf("Assuming %d heads and %d sectors.\n", nhead, nsec);
-  }
-  if (!seenpart) printf("Do not write the table if you are not sure!.\n");
-  if (active > 1) {
-	printf("%d active partitions\n", active);
-	status = ERR;	
-  }
-  return(status);
-}
-
-sec_to_hst(logsec, hd, sec, cyl)
-long logsec;
-unsigned char *hd, *sec, *cyl;
-{
-/* Convert a logical sector number to  head / sector / cylinder */
-
-  int bigcyl;
-
-  bigcyl = logsec / (nhead * nsec);
-  *sec = (logsec % nsec) + 1 + ((bigcyl >> CYL_SHIFT) & CYL_MASK);
-  *cyl = bigcyl;
-  *hd = (logsec % (nhead * nsec)) / nsec;
-}
-
-mark_partition(pe)
-struct part_entry *pe;
-{
-/* Mark a partition as being of type MINIX. */
-
-  if (pe != NULL) {
-	pe->sysind = MINIX_PART;
-	printf("Partition type is now MINIX\n");
-  }
-}
-
-change_partition(entry)
-struct part_entry *entry;
-{
-/* Get partition info : first & last cylinder */
-
-  int first, last;
-  long low, high;
-  int ch;
-
-  if (entry == NULL) return;
-  while (1) {
-	if (!get_an_int("\tEnter first cylinder (an integer >= 0): ", &first))
-		return;
-	if (first >= 0) break;
-	printf("\t\tThat looks like %d which is negative\n", first);
-  }
-  while (1) {
-	if (!get_an_int(
-	"\tEnter last cylinder (an integer >= the first cylinder): ", &last))
-		return;
-	if (last >= first) break;
-	printf("\t\tThat looks like %d which is too small\n", last);
-  }
-  if (first == 0 && last == 0) {
-	entry->bootind = 0;
-	entry->start_head = 0;
-	entry->start_sec = 0;
-	entry->start_cyl = 0;
-	entry->sysind = NO_PART;
-	entry->last_head = 0;
-	entry->last_sec = 0;
-	entry->last_cyl = 0;
-	entry->lowsec = 0;
-	entry->size = 0;
-	printf("Partition deleted\n");
-	return;
-  }
-  low = first & 0xffff;
-  low = low * nsec * nhead;
-  if (low == 0) low = 1;	/* sec0 is master boot record */
-  high = last & 0xffff;
-  high = (high + 1) * nsec * nhead - 1;
-  entry->lowsec = low;
-  entry->size = high - low + 1;
-  if (entry->size & 1) {
-	/* Adjust size to even since Minix works with blocks of 2 sectors. */
-	--high;
-	--entry->size;
-	printf("Size reduced by 1 to make it even\n");
-  }
-  sec_to_hst(low, &entry->start_head, &entry->start_sec, &entry->start_cyl);
-  sec_to_hst(high, &entry->last_head, &entry->last_sec, &entry->last_cyl);
-  printf("Base of partition changed to %ld, size changed to %ld\n",
-	 entry->lowsec, entry->size);
-
-  /* Accept the MINIX partition type.  Usually ignore foreign types, so this
-   * fdisk can be used on foreign partitions.  Don't allow NO_PART, because
-   * many DOS fdisks crash on it.
-   */
-  if (entry->sysind == NO_PART) {
-	entry->sysind = MINIX_PART;
-	printf("Partition type changed from None to MINIX\n");
-  } else if (entry->sysind == MINIX_PART)
-	printf("Leaving partition type as MINIX\n");
-  else while (1) {
-	printf("\tChange partition type from %s to MINIX? (y/n) ",
-		systype(entry->sysind));
-	ch = get_a_char();
-	if (ch == 0 || ch == 'n') {
-		printf("Leaving partition type as %s\n",
-			systype(entry->sysind));
-		break;
-	} else if (ch == 'y') {
-		entry->sysind = MINIX_PART;
-		printf("Partition type changed from %s to MINIX\n",
-			systype(entry->sysind));
-		break;
-	}
-  }
-
-  if (entry->bootind == ACTIVE_FLAG)
-	printf("Leaving partition active\n");
-  else while (1) {
-	printf("\tChange partition to active? (y/n) ");
-	ch = get_a_char();
-	if (ch == 0 || ch == 'n') {
-		printf("Leaving partition inactive\n");
-		break;
-	} else if (ch == 'y') {
-		toggle_active(entry);
-		break;
-	}
-  }
-}
-
-get_a_char()
-{
-/* Read 1 character and discard rest of line */
-
-  char buf[80];
-  int ch;
-
-  if (!mygets(buf, (int) sizeof buf)) return(0);
-  return(*buf);
-}
-
-print_menu()
-{
-  printf("Type a command letter, then a carriage return:\n");
-  printf("   + - explain any footnotes (+, -, #)\n");
-  printf("   a - toggle an active flag\n");
-  printf("   B - adjust a base sector\n");
-  printf("   c - change a partition\n");
-  printf("   l - load boot block (including partition table) from a file\n");
-  printf("   m - mark a partition as a MINIX partition\n");
-  printf("   n - mark a partition as a non-MINIX partition\n");
-  printf("   p - print raw partition table\n");
-  printf("   q - quit without making any changes\n");
-  printf("   S - adjust a size (by changing the last sector)\n");
-  printf("   s - save boot block (including partition table) on a file\n");
-  printf("   t - print known partition types\n");
-  printf("   v - verify partition table\n");
- if (readonly)
-  printf("   w - write (disabled)\n");
- else
-  printf("   w - write changed partition table back to disk and exit\n");
-}
-
-
-/* Here are the DOS routines for reading and writing the boot sector. */
-
-#ifdef DOS
-
-union REGS regs;
-struct SREGS sregs;
-int drivenum;
-
-getboot(buffer)
-char *buffer;
-{
-/* Read boot sector  */
-
-  segread(&sregs);		/* get ds */
-
-  if (devname[1] != ':') {
-	printf("Invalid drive %s\n", devname);
-	exit(1);
-  }
-  if (*devname >= 'a') *devname += 'A' - 'a';
-  drivenum = (*devname - 'C') & 0xff;
-  if (drivenum < 0 || drivenum > 7) {
-	printf("Funny drive number %d\n", drivenum);
-	exit(1);
-  }
-  regs.x.ax = 0x201;		/* read 1 sectors	 */
-  regs.h.ch = 0;		/* cylinder		 */
-  regs.h.cl = 1;		/* first sector = 1	 */
-  regs.h.dh = 0;		/* head = 0		 */
-  regs.h.dl = 0x80 + drivenum;	/* drive = 0		 */
-  sregs.es = sregs.ds;		/* buffer address	 */
-  regs.x.bx = (int) buffer;
-
-  int86x(0x13, &regs, &regs, &sregs);
-  if (regs.x.cflag) {
-	printf("Cannot read boot sector\n");
-	exit(1);
-  }
-}
-
-
-putboot(buffer)
-char *buffer;
-{
-/* Write boot sector  */
-
-  regs.x.ax = 0x301;		/* read 1 sectors	 */
-  regs.h.ch = 0;		/* cylinder		 */
-  regs.h.cl = 1;		/* first sector = 1	 */
-  regs.h.dh = 0;		/* head = 0		 */
-  regs.h.dl = 0x80 + drivenum;	/* drive = 0		 */
-  sregs.es = sregs.ds;		/* buffer address	 */
-  regs.x.bx = (int) buffer;
-
-  int86x(0x13, &regs, &regs, &sregs);
-  if (regs.x.cflag) {
-	printf("Cannot write boot sector\n");
-	exit(1);
-  }
-}
-
-#endif
-
-void adj_base(pe)
-struct part_entry *pe;
-{
-/* Adjust base sector of partition, usually to make it even. */
-
-  int adj;
-
-  if (pe == NULL) return;
-  while (1) {
-	
-	if (!get_an_int("\tEnter adjustment to base (an integer): ", &adj))
-		return;
-	if (pe->lowsec + adj < 1)
-		printf(
-    "\t\tThat would make the base %d and too small\n", pe->lowsec + adj);
-	else if (pe->size - adj < 1)
-		printf(
-    "\t\tThat would make the size %d and too small\n", pe->size - adj);
-	else
-		break;
-  }
-  pe->lowsec += adj; 
-  pe->size -= adj;
-  sec_to_hst(pe->lowsec, &pe->start_head, &pe->start_sec, &pe->start_cyl);
-  printf("Base of partition adjusted to %ld, size adjusted to %ld\n",
-	 pe->lowsec, pe->size);
-}
-
-void adj_size(pe)
-struct part_entry *pe;
-{
-/* Adjust size of partition by reducing high sector. */
-
-  int adj;
-
-  if (pe == NULL) return;
-  while (1) {
-	if (!get_an_int("\tEnter adjustment to size (an integer): ", &adj))
-		return;
-	if (pe->size + adj >= 1) break;
-	printf("\t\tThat would make the size %d and too small \n",
-		pe->size + adj);
-  }
-  pe->size += adj;
-  sec_to_hst(pe->lowsec + pe->size - 1,
-	     &pe->last_head, &pe->last_sec, &pe->last_cyl);
-  printf("Size of partition adjusted to %ld\n", pe->size);
-}
-
-struct part_entry *ask_partition()
-{
-/* Ask for a valid partition number and return its entry. */
-
-  int num;
-
-  while (1) {
-	
-	if (!get_an_int("Enter partition number (1 to 4): ", &num))
-		return(NULL);
-	if (num >= 1 && num <= NR_PARTITIONS) break;
-	printf("\tThat does not look like 1 to 4\n");
-  }
-  printf("Partition %d\n", num);
-  return((struct part_entry *) &secbuf[PART_TABLE_OFF] + (num - 1));
-}
-
-void footnotes()
-{
-/* Explain the footnotes. */
-
-  if (badbases != 0) {
-	printf(
-"+ The old Minix wini drivers (before V1.5) discarded odd base sectors.\n");
-	printf(
-"  This causes some old (Minix) file systems to be offset by 1 sector.\n");
-	printf(
-"  To use these with the new drivers, increase the base by 1 using 'B'.\n");
-  }
-
-  if (badsizes != 0) {
-	if (badbases != 0) putchar('\n');
-	printf(
-"- Minix cannot access the last sector on an odd-sized partition.  This\n");
-	printf(
-"  causes trouble for programs like dosread.  This program will by default\n");
-	printf(
-"  only create partitions with even sizes.  If possible, the current odd\n");
-	printf(
-"  sizes should be decreased by 1 using 'S'.  This is safe for all Minix\n");
-	printf(
-"  partitions, and may be safe for other partitions which are about to be\n");
-	printf(
-"  reformatted.\n");
-  }
-
-  if (badorders!= 0 ) {
-	if (badbases != 0 || badsizes != 0) putchar('\n');
-	printf(
-"# The partitions are in a funny order. This is normal if they were created\n");
-	printf(
-"  by DOS fdisks prior to DOS 3.3.  The Minix wini drivers further confuse\n");
-	printf(
-"  the order by sorting the partitions on their base.  Be careful if the\n");
-	printf(
-"  device numbers of unchanged partitions have changed.\n");
-  }
-}
-
-int get_an_int(prompt, intptr)
-char *prompt;
-int *intptr;
-{
-/* Read an int from the start of line of stdin, discard rest of line. */
-
-  char buf[80];
-
-  while (1) {
-	printf("%s", prompt);
-	if (!mygets(buf, (int) sizeof buf)) return(0);
-	if ((sscanf(buf, "%d", intptr)) == 1) return(1);
-	printf("\t\tThat does not look like an integer\n");
-  }
-}
-
-void list_part_types()
-{
-/* Print all known partition types. */
-
-  int column;
-  int type;
-
-  for (column = 0, type = 0; type < 0x100; ++type)
-	if (strcmp(systype(type), "Unknown") != 0) {
-		printf("0x%02x: %-9s", type, systype(type));
-		column += 16;
-		if (column < 80)
-			putchar(' ');
-		else {
-			putchar('\n');
-			column = 0;
-		}
-	}
-  if (column != 0) putchar('\n');
-}
-
-void mark_npartition(pe)
-struct part_entry *pe;
-{
-/* Mark a partition with arbitrary type. */
-
-  char buf[80];
-  unsigned type;
-
-  if (pe == NULL) return;
-  printf("\nKnown partition types are:\n\n");
-  list_part_types();
-  while (1) {
-	printf("\nEnter partition type (in 2-digit hex): ");
-	if (!mygets(buf, (int) sizeof buf)) return;
-	if (sscanf(buf, "%x", &type) != 1)
-		printf("Invalid hex number\n");
-  	else if (type >= 0x100)
-		printf("Hex number too large\n");
-	else
-		break;
-  }
-  pe->sysind = type;
-  printf("Partition type changed to 0x%02x (%s)\n", type, systype(type));
-}
-
-int mygets(buf, length)
-char *buf;
-int length;			/* as for fgets(), but must be >= 2 */
-{
-/* Get a non-empty line of maximum length 'length'. */
-
-  while (1) {
-	fflush(stdout);
-	if (fgets(buf, length, stdin) == NULL) {
-		putchar('\n');
-		return(0);
-	}
-	if (strrchr(buf, '\n') != NULL) *strrchr(buf, '\n') = 0;
-	if (*buf != 0) return(1);
-	printf("Use the EOF character to create a null line.\n");
-	printf("Otherwise, please type something before the newline: ");
-  }
-}
-
-char *systype(type)
-int type;
-{
-/* Convert system indicator into system name. */
-/* asw 01.03.95: added types based on info in kjb's part.c and output
- * from Linux (1.0.8) fdisk. Note comments here, there are disagreements.
-*/
-  switch(type) {
-	case NO_PART: 
-	           return("None");
-	case 1:    return("DOS-12");
-	case 2:    return("XENIX");
-	case 3:    return("XENIX usr");
-	case 4:    return("DOS-16");
-	case 5:    return("DOS-EXT");
-	case 6:    return("DOS-BIG");
-	case 7:    return("HPFS");
-	case 8:    return("AIX");
-	case 9:    return("COHERENT");	/* LINUX says AIX bootable */
-	case 0x0a: return("OS/2");	/* LINUX says OPUS */
-	case 0x10: return("OPUS");
-	case 0x40: return("VENIX286");
-	case 0x51: return("NOVELL?");
-	case 0x52: return("MICROPORT");
-	case 0x63: return("386/IX");	/*LINUX calls this GNU HURD */
-	case 0x64: return("NOVELL286");
-	case 0x65: return("NOVELL386");
-	case 0x75: return("PC/IX");
-	case 0x80: return("MINIX old");
-	case 0x81: return("MINIX");
-	case 0x82: return("LINUXswap");
-	case 0x83: return("LINUX");
-	case 0x93: return("AMOEBA");
-	case 0x94: return("AMOEBAbad");
-	case 0xa5: return("386BSD");
-	case 0xb7: return("BSDI");
-	case 0xb8: return("BSDIswap");
-	case 0xc7: return("Syrinx");
-	case 0xDB: return("CP/M");
-	case 0xe1: return("DOS acc");
-	case 0xe3: return("DOS r/o");
-	case 0xf2: return("DOS 2ary");
-	case 0xFF: return("Badblocks");
-	default:   return("Unknown");
-  }
-}
-
-void toggle_active(pe)
-struct part_entry *pe;
-{
-/* Toggle active flag of a partition. */
-
-  if (pe == NULL) return;
-  pe->bootind = (pe->bootind == ACTIVE_FLAG) ? 0 : ACTIVE_FLAG;
-  printf("Partition changed to %sactive\n", pe->bootind ? "" : "in");
-}
-
-void usage()
-{
-/* Print usage message and exit. */
-
-  printf("Usage: fdisk [-hheads] [-ssectors] [device]\n");
-  exit(1);
-}
-
Index: trunk/minix/commands/ibm/format.c
===================================================================
--- trunk/minix/commands/ibm/format.c	(revision 9)
+++ 	(revision )
@@ -1,422 +1,0 @@
-/*	format 1.1 - format PC floppy disk		Author: Kees J. Bot
- *								5 Mar 1994
- */
-#define nil 0
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <limits.h>
-#include <ibm/diskparm.h>
-#include <minix/minlib.h>
-
-/* Constants. */
-#define SECTOR_SIZE	512
-#define NR_HEADS	  2
-#define MAX_SECTORS	 18	/* 1.44Mb is the largest. */
-
-/* Name error in <ibm/diskparm.h>, left over from the days floppies were
- * single sided.
- */
-#define sectors_per_track	sectors_per_cylinder
-
-/* From floppy device number to drive/type/format-bit and back.  See fd(4). */
-#define isfloppy(dev)		(((dev) & 0xFF00) == 0x0200)
-#define fl_drive(dev)		(((dev) & 0x0003) >> 0)
-#define fl_type(dev)		(((dev) & 0x007C) >> 2)
-#define fl_format(dev)		(((dev) & 0x0080) >> 7)
-#define fl_makedev(drive, type, fmt)	\
-	((dev_t) (0x0200 | ((fmt) << 7) | ((type) << 2) | ((drive) << 0)))
-
-/* Recognize floppy types. */
-#define NR_TYPES		7	/* # non-auto types */
-#define isflauto(type)		((type) == 0)
-#define isfltyped(type)		((unsigned) ((type) - 1) < NR_TYPES)
-#define isflpart(type)		((unsigned) (type) >= 28)
-
-/* Formatting parameters per type.  (Most of these parameters have no use
- * for formatting, disk_parameter_s probably matches a BIOS parameter table.)
- */
-typedef struct disk_parameter_s	fmt_params_t;
-
-typedef struct type_parameters {
-	unsigned		media_size;
-	unsigned		drive_size;
-	fmt_params_t		fmt_params;
-} type_parameters_t;
-
-#define DC	0	/* Don't care. */
-
-type_parameters_t parameters[NR_TYPES] = {
-	/* mediasize       s1     off   sec/cyl  dlen       fill    start */
-	/*       drivesize     s2   sizecode  gap    fmtgap     settle    */
-  /* pc */ {  360,  360, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* at */ { 1200, 1200, { DC, DC, DC, 2, 15, DC, DC, 0x54, 0xF6, DC, DC }},
-  /* qd */ {  360,  720, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* ps */ {  720,  720, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* pat */{  360, 1200, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* qh */ {  720, 1200, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* PS */ { 1440, 1440, { DC, DC, DC, 2, 18, DC, DC, 0x54, 0xF6, DC, DC }},
-};
-
-/* Per sector ID to be sent to the controller by the driver. */
-typedef struct sector_id {
-	unsigned char	cyl;
-	unsigned char	head;
-	unsigned char	sector;
-	unsigned char	sector_size_code;
-} sector_id_t;
-
-/* Data to be "written" to the driver to format a track.  (lseek to the track
- * first.)  The first sector contains sector ID's, the second format params.
- */
-
-typedef struct track_data {
-	sector_id_t	sec_ids[SECTOR_SIZE / sizeof(sector_id_t)];
-	fmt_params_t	fmt_params;
-	char		padding[SECTOR_SIZE - sizeof(fmt_params_t)];
-} track_data_t;
-
-void report(const char *label)
-{
-	fprintf(stderr, "format: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-void format_track(int ffd, unsigned type, unsigned cyl, unsigned head)
-/* Format a single track on a floppy. */
-{
-	type_parameters_t *tparams= &parameters[type - 1];
-	track_data_t track_data;
-	off_t track_pos;
-	unsigned sector;
-	unsigned nr_sectors= tparams->fmt_params.sectors_per_track;
-	sector_id_t *sid;
-
-	memset(&track_data, 0, sizeof(track_data));
-
-	/* Set the sector id's.  (Note that sectors count from 1.) */
-	for (sector= 0; sector <= nr_sectors; sector++) {
-		sid= &track_data.sec_ids[sector];
-
-		sid->cyl= cyl;
-		sid->head= head;
-		sid->sector= sector + 1;
-		sid->sector_size_code= tparams->fmt_params.sector_size_code;
-	}
-
-	/* Format parameters. */
-	track_data.fmt_params= tparams->fmt_params;
-
-	/* Seek to the right track. */
-	track_pos= (off_t) (cyl * NR_HEADS + head) * nr_sectors * SECTOR_SIZE;
-	if (lseek(ffd, track_pos, SEEK_SET) == -1) {
-		fprintf(stderr,
-		"format: seeking to cyl %u, head %u (pos %ld) failed: %s\n",
-			cyl, head, track_pos, strerror(errno));
-		exit(1);
-	}
-
-	/* Format track. */
-	if (write(ffd, &track_data, sizeof(track_data)) < 0) {
-		fprintf(stderr,
-			"format: formatting cyl %d, head %d failed: %s\n",
-			cyl, head, strerror(errno));
-		exit(1);
-	}
-}
-
-void verify_track(int vfd, unsigned type, unsigned cyl, unsigned head)
-/* Verify a track by reading it.  On error read sector by sector. */
-{
-	type_parameters_t *tparams= &parameters[type - 1];
-	off_t track_pos;
-	unsigned sector;
-	unsigned nr_sectors= tparams->fmt_params.sectors_per_track;
-	size_t track_bytes;
-	static char buf[MAX_SECTORS * SECTOR_SIZE];
-	static unsigned bad_count;
-
-	/* Seek to the right track. */
-	track_pos= (off_t) (cyl * NR_HEADS + head) * nr_sectors * SECTOR_SIZE;
-	if (lseek(vfd, track_pos, SEEK_SET) == -1) {
-		fprintf(stderr,
-		"format: seeking to cyl %u, head %u (pos %ld) failed: %s\n",
-			cyl, head, track_pos, strerror(errno));
-		exit(1);
-	}
-
-	/* Read the track whole. */
-	track_bytes= nr_sectors * SECTOR_SIZE;
-	if (read(vfd, buf, track_bytes) == track_bytes) return;
-
-	/* An error occurred, retry sector by sector. */
-	for (sector= 0; sector < nr_sectors; sector++) {
-		if (lseek(vfd, track_pos, SEEK_SET) == -1) {
-			fprintf(stderr,
-	"format: seeking to cyl %u, head %u, sector %u (pos %ld) failed: %s\n",
-				cyl, head, sector, track_pos, strerror(errno));
-			exit(1);
-		}
-
-		switch (read(vfd, buf, SECTOR_SIZE)) {
-		case -1:
-			fprintf(stderr,
-		"format: bad sector at cyl %u, head %u, sector %u (pos %ld)\n",
-				cyl, head, sector, track_pos);
-			bad_count++;
-			break;
-		case SECTOR_SIZE:
-			/* Fine. */
-			break;
-		default:
-			fprintf(stderr, "format: short read at pos %ld\n",
-				track_pos);
-			bad_count++;
-		}
-		track_pos+= SECTOR_SIZE;
-		if (bad_count >= nr_sectors) {
-	fprintf(stderr, "format: too many bad sectors, floppy unusable\n");
-			exit(1);
-		}
-	}
-}
-
-void format_device(unsigned drive, unsigned type, int verify)
-{
-	int ffd, vfd;
-	char *fmt_dev, *ver_dev;
-	struct stat st;
-	unsigned cyl, head;
-	unsigned nr_cyls;
-	type_parameters_t *tparams= &parameters[type - 1];
-	int verbose= isatty(1);
-
-	fmt_dev= tmpnam(nil);
-
-	if (mknod(fmt_dev, S_IFCHR | 0700, fl_makedev(drive, type, 1)) < 0) {
-		fprintf(stderr, "format: making format device failed: %s\n",
-			strerror(errno));
-		exit(1);
-	}
-
-	if ((ffd= open(fmt_dev, O_WRONLY)) < 0 || fstat(ffd, &st) < 0) {
-		report(fmt_dev);
-		(void) unlink(fmt_dev);
-		exit(1);
-	}
-
-	(void) unlink(fmt_dev);
-
-	if (st.st_rdev != fl_makedev(drive, type, 1)) {
-		/* Someone is trying to trick me. */
-		exit(1);
-	}
-
-	if (verify) {
-		ver_dev= tmpnam(nil);
-
-		if (mknod(ver_dev, S_IFCHR | 0700, fl_makedev(drive, type, 0))
-									< 0) {
-			fprintf(stderr,
-				"format: making verify device failed: %s\n",
-				strerror(errno));
-			exit(1);
-		}
-
-		if ((vfd= open(ver_dev, O_RDONLY)) < 0) {
-			report(ver_dev);
-			(void) unlink(ver_dev);
-			exit(1);
-		}
-
-		(void) unlink(ver_dev);
-	}
-
-	nr_cyls= tparams->media_size * (1024 / SECTOR_SIZE) / NR_HEADS
-				/ tparams->fmt_params.sectors_per_track;
-
-	if (verbose) {
-		printf("Formatting a %uk diskette in a %uk drive\n",
-			tparams->media_size, tparams->drive_size);
-	}
-
-	for (cyl= 0; cyl < nr_cyls; cyl++) {
-		for (head= 0; head < NR_HEADS; head++) {
-			if (verbose) {
-				printf(" Cyl. %2u, Head %u\r", cyl, head);
-				fflush(stdout);
-			}
-#if __minix_vmd
-			/* After formatting a track we are too late to format
-			 * the next track.  So we can sleep at most 1/6 sec to
-			 * allow the above printf to get displayed before we
-			 * lock Minix into the floppy driver again.
-			 */
-			usleep(50000);	/* 1/20 sec will do. */
-#endif
-			format_track(ffd, type, cyl, head);
-			if (verify) verify_track(vfd, type, cyl, head);
-		}
-	}
-	if (verbose) fputc('\n', stdout);
-}
-
-void usage(void)
-{
-	fprintf(stderr,
-		"Usage: format [-v] <device> [<media size> [<drive size>]]\n");
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	char *device;
-	unsigned drive;
-	unsigned type;
-	unsigned media_size;
-	unsigned drive_size;
-	int verify= 0;
-	struct stat st0, st;
-	FILE *mfp;
-	char special[PATH_MAX + 1], mounted_on[PATH_MAX + 1];
-	char version[10], rw_flag[10];
-
-	/* Option -v. */
-	while (argc > 1 && argv[1][0] == '-') {
-		char *p;
-
-		for (p= argv[1]; *p == '-' || *p == 'v'; p++) {
-			if (*p == 'v') verify= 1;
-		}
-		if (*p != 0) usage();
-		argc--;
-		argv++;
-		if (strcmp(argv[0], "--") == 0) break;
-	}
-
-	if (argc < 2 || argc > 4) usage();
-
-	/* Check if the caller has read-write permission.  Use the access()
-	 * call to check with the real uid & gid.  This program is usually
-	 * set-uid root.
-	 */
-	device= argv[1];
-	if (stat(device, &st0) < 0
-		|| access(device, R_OK|W_OK) < 0
-		|| stat(device, &st) < 0
-		|| (errno= EACCES, 0)	/* set errno for following tests */
-		|| st.st_dev != st0.st_dev
-		|| st.st_ino != st0.st_ino
-	) {
-		fatal(device);
-	}
-
-	if ((!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
-						|| !isfloppy(st.st_rdev)) {
-		fprintf(stderr, "format: %s: not a floppy device\n", device);
-		exit(1);
-	}
-
-	drive= fl_drive(st.st_rdev);
-	type= fl_type(st.st_rdev);
-
-	/* The drive should not be mounted. */
-	if (load_mtab("mkfs") < 0) return;
-
-	while (get_mtab_entry(special, mounted_on, version, rw_flag) == 0) {
-		if (stat(special, &st) >= 0 && isfloppy(st.st_rdev)
-					&& fl_drive(st.st_rdev) == drive) {
-			fprintf(stderr, "format: %s is mounted on %s\n",
-				device, mounted_on);
-			exit(1);
-		}
-	}
-
-	if (isflauto(type)) {
-		/* Auto type 0 requires size(s). */
-		unsigned long lmedia, ldrive;
-		char *end;
-
-		if (argc < 3) {
-			fprintf(stderr,
-			"format: no size specified for auto floppy device %s\n",
-				device);
-			usage();
-		}
-
-		lmedia= strtoul(argv[2], &end, 10);
-		if (end == argv[2] || *end != 0 || lmedia > 20 * 1024)
-			usage();
-
-		if (argc == 4) {
-			ldrive= strtoul(argv[3], &end, 10);
-			if (end == argv[3] || *end != 0 || ldrive > 20 * 1024)
-				usage();
-		} else {
-			ldrive= lmedia;
-		}
-
-		/* Silently correct wrong ordered sizes. */
-		if (lmedia > ldrive) {
-			media_size= ldrive;
-			drive_size= lmedia;
-		} else {
-			media_size= lmedia;
-			drive_size= ldrive;
-		}
-
-		/* A 1.44M drive can do 720k diskettes with no extra tricks.
-		 * Diddle with the 720k params so it is found.
-		 */
-		if (media_size == 720 && drive_size == 1440)
-			parameters[4 - 1].drive_size= 1440;
-
-		/* Translate the auto type to a known type. */
-		for (type= 1; type <= NR_TYPES; type++) {
-			if (parameters[type - 1].media_size == media_size
-				&& parameters[type - 1].drive_size == drive_size
-			) break;
-		}
-
-		if (!isfltyped(type)) {
-			fprintf(stderr,
-			"format: can't format a %uk floppy in a %uk drive\n",
-				media_size, drive_size);
-			exit(1);
-		}
-	} else
-	if (isfltyped(type)) {
-		/* No sizes needed for a non-auto type. */
-
-		if (argc > 2) {
-			fprintf(stderr,
-	"format: no sizes need to be specified for non-auto floppy device %s\n",
-				device);
-			usage();
-		}
-	} else
-	if (isflpart(type)) {
-		fprintf(stderr,
-			"format: floppy partition %s can't be formatted\n",
-			device);
-		exit(1);
-	} else {
-		fprintf(stderr,
-			"format: %s: can't format strange type %d\n",
-			device, type);
-	}
-
-	format_device(drive, type, verify);
-	exit(0);
-}
Index: trunk/minix/commands/ibm/loadfont.c
===================================================================
--- trunk/minix/commands/ibm/loadfont.c	(revision 9)
+++ 	(revision )
@@ -1,122 +1,0 @@
-/* loadfont.c - Load custom font into EGA, VGA video card
- *
- * Author: Hrvoje Stipetic (hs@hck.hr) Jun-1995.
- *
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-void tell(char *s)
-{
-  write(2, s, strlen(s));
-}
-
-char *itoa(unsigned i)
-{
-  static char a[3*sizeof(int)];
-  char *p = a+sizeof(a)-1;
-
-  do {
-	*--p = '0' + i%10;
-  } while ((i /= 10) > 0);
-
-  return p;
-}
-
-void report(char *say)
-{
-  int err = errno;
-  tell("loadfont: ");
-  if (say != NULL) {
-	tell(say);
-	tell(": ");
-  }
-  tell(strerror(err));
-  tell("\n");
-}
-
-void usage(void)
-{
-  tell("Usage: loadfont fontfile\n");
-  exit(1);
-}
-
-
-int main(int argc, char *argv[])
-{
-  static u8_t font[256][32];
-  static u8_t font_file[256 * (16+14+8) + 1];
-  u8_t *ff;
-  int fd, size, tsize, ch, ln;
-  struct winsize ws;
-
-
-  if (argc != 2)
-	usage();
-
-  if ((fd = open(argv[1], O_RDONLY)) < 0) {
-	report(argv[1]);
-	exit(1);
-  }
-
-  switch (read(fd, font_file, sizeof(font_file))) {
-  case 256 * 8:
-  	size = 8;
-  	break;
-  case 256 * 14:
-  	size = 14;
-  	break;
-  case 256 * 16:
-  	size = 16;
-  	break;
-  case 256 * (16+14+8):
-  	size = 0;
-  	break;
-  case -1:
-	report(argv[1]);
-	exit(1);
-  default:
-	tell("loadfont: ");
-	tell(argv[1]);
-	tell(": fontfile is not an 8x8, 8x14, 8x16, or compound font\n");
-	exit(1);
-  }
-  close(fd);
-
-  if (ioctl(0, TIOCGWINSZ, &ws) < 0 || (errno= ENOTTY, ws.ws_row == 0)) {
-	report(NULL);
-	exit(1);
-  }
-  tsize = ws.ws_ypixel / ws.ws_row;
-
-  if (size == 0) {
-	if (tsize >= 16) {
-		ff = font_file + 256 * (0);
-	} else
-	if (tsize >= 14) {
-		ff = font_file + 256 * (16);
-	} else {
-		ff = font_file + 256 * (16 + 14);
-	}
-	size = tsize;
-  } else {
-	ff = font_file;
-  }
-
-  for (ch = 0; ch < 256; ch++) {
-	for (ln = 0; ln < size; ln++) font[ch][ln] = ff[ch * size + ln]; 
-  }
-
-  if (ioctl(0, TIOCSFON, font) < 0) {
-	report(NULL);
-	exit(1);
-  }
-  exit(0);
-}
Index: trunk/minix/commands/ibm/loadkeys.c
===================================================================
--- trunk/minix/commands/ibm/loadkeys.c	(revision 9)
+++ 	(revision )
@@ -1,91 +1,0 @@
-/*	loadkeys - load national keyboard map		Author: Marcus Hampel
- */
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <minix/keymap.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#if __minix_vmd
-#define KBD_DEVICE	"/dev/kbd"
-#else
-#define KBD_DEVICE	"/dev/console"
-#endif
-
-u16_t keymap[NR_SCAN_CODES * MAP_COLS];
-u8_t comprmap[4 + NR_SCAN_CODES * MAP_COLS * 9/8 * 2 + 1];
-
-
-void tell(char *s)
-{
-  write(2, s, strlen(s));
-}
-
-
-void fatal(char *say)
-{
-  int err = errno;
-  tell("loadkeys: ");
-  if (say != NULL) {
-	tell(say);
-	tell(": ");
-  }
-  tell(strerror(err));
-  tell("\n");
-  exit(1);
-}
-
-
-void usage(void)
-{
-  tell("Usage: loadkeys mapfile\n");
-  exit(1);
-}
-
-
-int main(int argc, char *argv[])
-{
-  u8_t *cm;
-  u16_t *km;
-  int fd, n, fb;
-
-  if (argc != 2)
-	usage();
-
-  if ((fd = open(argv[1], O_RDONLY)) < 0) fatal(argv[1]);
-
-  if (read(fd, comprmap, sizeof(comprmap)) < 0) fatal(argv[1]);
-
-  if (memcmp(comprmap, KEY_MAGIC, 4) != 0) {
-	tell("loadkeys: ");
-	tell(argv[1]);
-	tell(": not a keymap file\n");
-	exit(1);
-  }
-  close(fd);
-
-  /* Decompress the keymap data. */
-  cm = comprmap + 4;
-  n = 8;
-  for (km = keymap; km < keymap + NR_SCAN_CODES * MAP_COLS; km++) {
-	if (n == 8) {
-		/* Need a new flag byte. */
-		fb = *cm++;
-		n = 0;
-	}
-	*km = *cm++;			/* Low byte. */
-	if (fb & (1 << n)) {
-		*km |= (*cm++ << 8);	/* One of the few special keys. */
-	}
-	n++;
-  }
-
-  if ((fd = open(KBD_DEVICE, O_WRONLY)) < 0) fatal(KBD_DEVICE);
-
-  if (ioctl(fd, KIOCSMAP, keymap) < 0) fatal(KBD_DEVICE);
-
-  return 0;
-}
Index: trunk/minix/commands/ibm/mixer.c
===================================================================
--- trunk/minix/commands/ibm/mixer.c	(revision 9)
+++ 	(revision )
@@ -1,658 +1,0 @@
-/*   
- *  mixer
- *
- *  Michel R. Prevenier.
- */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <curses.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <minix/sound.h>
-
-#define CURS_CTRL	'\033'
-#define ESCAPE		27
-#define UP   		'A'
-#define DOWN		'B'
-#define LEFT		'D'
-#define RIGHT		'C'
-#define SPACE		' '
-
-
-_PROTOTYPE ( int main, (int arg, char **argv));
-_PROTOTYPE ( void usage, (void));
-_PROTOTYPE ( void non_interactive, (void));
-_PROTOTYPE ( void setup_screen, (void));
-_PROTOTYPE ( int read_settings, (void));
-_PROTOTYPE ( int write_settings, (void));
-_PROTOTYPE ( void rdwr_levels, (int flag));
-_PROTOTYPE ( void rdwr_inputs, (int flag));
-_PROTOTYPE ( void rdwr_outputs, (int flag));
-_PROTOTYPE ( void create_slider, (int x, int y, enum Device device));
-_PROTOTYPE ( void show_inputs, (int x, int y));
-_PROTOTYPE ( void show_outputs, (int x, int y));
-_PROTOTYPE ( char *d_name, (enum Device device, char *name));
-_PROTOTYPE ( void user_interface, (void));
-_PROTOTYPE ( void terminate, (int s));
-
-WINDOW *main_win;
-int old_stdin;
-int fd;
-char name[9];
-char *file_name;
-struct volume_level levels[9];
-struct inout_ctrl inputs_left[9];
-struct inout_ctrl inputs_right[9];
-struct inout_ctrl outputs[9];
-
-
-void usage()
-{
-  fprintf(stderr, "Usage: mixer [-r]\n");
-  exit(-1);
-}
-
-
-void terminate(s)
-int s;
-{
-  /* Restore terminal parameters and exit */
-
-  (void) fcntl(0,F_SETFL,old_stdin);
-  move(23, 0);			
-  refresh();			
-  resetty();
-  endwin();			
-  exit(1);		
-}
-
-
-int write_settings()
-{
-  /* Write the current mixer settings to $HOME/.mixer */
-
-  int fd;
-
-  if ((fd = creat(file_name, 0x124)) > 0)
-  {
-    write(fd, levels, sizeof(levels));
-    write(fd, inputs_left, sizeof(inputs_left));
-    write(fd, inputs_right, sizeof(inputs_right));
-    write(fd, outputs, sizeof(outputs));
-    close(fd);
-    return 1;
-  }
-
-  return 0;
-}
-
-
-int read_settings()
-{
-  /* Restore mixer settings saved in $HOME/.mixer */
-
-  int fd;
-
-  if ((fd = open(file_name, O_RDONLY)) > 0)
-  {
-    read(fd, levels, sizeof(levels));
-    read(fd, inputs_left, sizeof(inputs_left));
-    read(fd, inputs_right, sizeof(inputs_right));
-    read(fd, outputs, sizeof(outputs));
-    close(fd);
-    rdwr_levels(1);
-    rdwr_outputs(1);
-    rdwr_inputs(1);
-    return 1;
-  }
-  return 0;
-}
-
-
-void rdwr_levels(flag)
-int flag;             /* 0 = read, 1 = write */
-{
-  /* Get or set mixer settings */
-
-  int i;
-  int cmd;
- 
-  cmd = (flag == 0 ? MIXIOGETVOLUME : MIXIOSETVOLUME);  
-  
-  for(i = Master; i <= Bass; i++)
-    (void) (ioctl(fd, cmd, &levels[i])); 
-}    
-
-
-void rdwr_inputs(flag)
-int flag;              /* 0 = read, 1 = write */
-{
-  /* Get or set input settings */
-
-  int i;
-  int cmd_left, cmd_right;
-  
-  cmd_left = (flag == 0 ? MIXIOGETINPUTLEFT : MIXIOSETINPUTLEFT);  
-  cmd_right = (flag == 0 ? MIXIOGETINPUTRIGHT : MIXIOSETINPUTRIGHT);  
-
-  for(i = Fm; i <= Mic; i++)
-  {
-    (void) (ioctl(fd, cmd_left, &inputs_left[i])); 
-    (void) (ioctl(fd, cmd_right, &inputs_right[i])); 
-  }
-}
-
-
-void rdwr_outputs(flag)
-int flag;               /* 0 = read, 1 = write */
-{
-  /* Get or set output settings */
-
-  int i;
-  int cmd; 
-
-  cmd = (flag == 0 ? MIXIOGETOUTPUT : MIXIOSETOUTPUT);  
-
-  for(i = Cd; i <= Mic; i++)
-    (void) (ioctl(fd, cmd, &outputs[i])); 
-}
-
-
-int main(argc, argv)
-int argc;
-char **argv;
-
-{
-  int i;
-  char *home_ptr;
-  int fd2;
-
-  /* Open mixer */
-  if ((fd = open("/dev/mixer",O_RDONLY)) < 0)
-  {
-    fprintf(stderr, "Cannot open /dev/mixer\n");
-    exit(-1);
-  }
-
-  /* Get user's home directory and construct the $HOME/.mixer
-   * file name 
-   */
-  home_ptr = getenv("HOME");
-  file_name = malloc(strlen(home_ptr)+strlen("mixer.ini\0"));
-  if (file_name == (char *)0) 
-  {
-    fprintf(stderr, "Not enough memory\n");
-    exit(-1);
-  }
-  strncpy(file_name, home_ptr, strlen(home_ptr));
-  strncpy(file_name+strlen(home_ptr), "/.mixer\0", 9);
-
-  /* Fill in the device numbers */    
-  for(i = Master; i <= Bass; i++) 
-  {
-    levels[i].device = i;
-    inputs_left[i].device = i;
-    inputs_right[i].device = i;
-    outputs[i].device = i;
-  }
-
-  /* Get arguments */
-  if (argc > 1)
-  {
-    if (strncmp(argv[1], "-r", 2) == 0)
-    {
-      if (read_settings())
-      {
-        printf("Mixer settings restored\n");
-        exit(0);
-      }
-      else
-      {
-        fprintf(stderr, "Could not restore mixer settings\n");
-        exit(-1);
-      }
-    } 
-    else usage();
-  }
-
-  /* Initialize windows. */
-  (void) initscr();
-  signal(SIGINT, terminate);
-  old_stdin = fcntl(0,F_GETFL);
-  cbreak();
-  noecho();
-  main_win = newwin(23,80,0,0);
-  scrollok(main_win, FALSE);
-
-  /* Read all current mixer settings */
-  rdwr_levels(0);
-  rdwr_inputs(0);
-  rdwr_outputs(0);
-
-  /* Set up the user screen and handle user input */
-  setup_screen();
-  user_interface();
-}
-
-
-void user_interface()
-{
-  /* This is the user interface. */
- 
-  char c;
-  int x,y;
-  int right;
-  int input_scr, input_pos;
-  int output_scr, output_pos;
-  int max_level;
-  enum Device device;
-  int fd2;
- 
-  device = Master;
-  right = 0;
-  input_scr = 0;
-  output_scr = 0;
-  input_pos = 0;
-  output_pos = 0;
-
-  while(1)
-  {
-    if (input_scr)
-    {
-      y = device + 9;
-      x = 51 + input_pos + (device == Mic ? 2 : 0);
-    }
-    else if (output_scr)
-    {
-      y = device + 15;
-      x = 53 + output_pos + (device == Mic ? 4 : 0);
-    }
-    else
-    {
-      y = (device != Speaker ? 2 : 1) + 
-          (device - (device < Treble ? 0 : Treble)) * 3 + 
-          (right == 0 ? 0 : 1);
-      if (!right)
-        x = 9 + levels[device].left / (device < Speaker ? 2 : 1 ) +
-              (device > Speaker ? 39 : 0);
-      else
-        x = 9 + levels[device].right / (device < Speaker ? 2 : 1) +
-              (device > Speaker ? 39 : 0);
-    }
-    
-    wmove(main_win,y,x);
-    wrefresh(main_win);
-    c = wgetch(main_win);
-
-    switch(c)
-    {
-      case CURS_CTRL:
-      {
-        (void) wgetch(main_win);
-        c = wgetch(main_win);
-        
-        switch(c)
-        { 
-          case DOWN: 
-          {
-           if (output_scr) 
-           {
-             if (device < Mic)
-             {
-                device++;
-                if (device == Mic) output_pos = 0;
-             }
-           }
-           else if (right || input_scr)
-           {
-             if (!input_scr)
-             {
-               if (device < Bass) 
-               {
-                 device++;         
-                 right = 0;
-               }
-               else
-               {  
-                 input_scr = 1;
-                 input_pos = 0;
-                 device = Fm;
-               }
-             }
-             else
-             {
-               if (device < Mic) 
-               {
-                 device++;
-                 if (device == Mic && input_pos > 8) input_pos = 8;
-               }
-               else 
-               { 
-                 device = Cd; 
-                 output_scr = 1; 
-                 input_scr = 0; 
-                 output_pos = 0; 
-               }
-             }
-           }
-           else 
-           {
-             if (device != Mic && device != Speaker)  right = 1;
-             else { device++; right = 0; }
-           }
-          };break;
-          case UP: 
-          {
-           if (output_scr) 
-           {
-             if (device > Cd) device--;
-             else 
-             {
-               device = Mic; 
-               output_scr = 0;
-               input_scr = 1;
-             }
-           }
-           else if (!right || input_scr)
-           {
-             if (input_scr)
-             {
-               if (device > Fm) device--;
-               else 
-               {
-                 input_scr = 0;
-                 device = Bass;
-                 right = 1;
-               }
-             }
-             else 
-             {
-               if (device > Master) 
-               {
-                 device--;         
-                 if (device != Mic && device != Speaker) right = 1;
-               }
-             }
-           }
-           else 
-             right = 0;
-          };break;
-          case RIGHT: 
-          {
-            if (output_scr) 
-            {
-              if (output_pos < 8 && device != Mic) output_pos = 8;
-            }
-            else if (!input_scr)
-            {
-              if (device < Speaker) max_level = 31;
-              else if (device > Speaker) max_level = 15;
-              else max_level = 4;
-
-              if (!right) 
-              {
-                if (levels[device].left < max_level) levels[device].left+=
-                  (device < Speaker ? 2 : 1);
-              }
-              else
-              {
-                if (levels[device].right < max_level) levels[device].right+=
-                  (device < Speaker ? 2 : 1);
-              }
-              ioctl(fd, MIXIOSETVOLUME, &levels[device]); 
-              ioctl(fd, MIXIOGETVOLUME, &levels[device]); 
-              create_slider(1 + (device < Treble ? 0 : 39), 
-                            (device - (device < Treble ? 0 : Treble))*3 +
-                            (device != Speaker ? 2 : 1), device);
-            }
-            else
-            {
-              if ((device != Mic && input_pos < 12) ||
-                  (device == Mic && input_pos < 8))
-                input_pos += (4 + (device == Mic ? 4 : 0));
-            }
-          };break;
-          case LEFT: 
-          {
-            if (output_scr)
-            {
-              if (output_pos > 0) output_pos = 0;
-            }
-            else if (!input_scr)
-            {
-              if (!right)
-              {
-                if (levels[device].left > 0) levels[device].left-=
-                  (device < Speaker ? 2 : 1);
-              }
-              else
-              {
-                if (levels[device].right > 0) levels[device].right-=
-                  (device < Speaker ? 2 : 1);
-              }
-              ioctl(fd, MIXIOSETVOLUME, &levels[device]); 
-              ioctl(fd, MIXIOGETVOLUME, &levels[device]); 
-              create_slider(1 + (device < Treble ? 0 : 39), 
-                            (device - (device < Treble ? 0 : Treble))*3 +
-                            (device != Speaker ? 2 : 1), device);
-            }
-            else
-            {
-              if (input_pos > 0) 
-                input_pos -= (4 + (device == Mic ? 4 : 0));
-            } 
-          };break;
-        } 
-      };break;
-    case SPACE:
-      {
-        if (output_scr)
-        {
-          switch(output_pos)
-          {
-            case 0:
-            case 4:
-            {
-              outputs[device].left = 
-               (outputs[device].left == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETOUTPUT, &outputs[device]);
-            };break;
-            case 8:
-            {
-              outputs[device].right = 
-               (outputs[device].right == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETOUTPUT, &outputs[device]);
-            };break;
-          }
-          ioctl(fd, MIXIOGETOUTPUT, &outputs[device]);
-          show_outputs(41,16);
-        }
-        else if (input_scr)
-        { 
-          switch(input_pos)
-          {
-            case 0:
-            {
-              inputs_left[device].left = 
-               (inputs_left[device].left == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETINPUTLEFT, &inputs_left[device]);
-            };break;
-            case 4:
-            {
-              inputs_left[device].right = 
-               (inputs_left[device].right == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETINPUTLEFT, &inputs_left[device]);
-            };break;
-            case 8:
-            {
-              inputs_right[device].left = 
-               (inputs_right[device].left == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETINPUTRIGHT, &inputs_right[device]);
-            };break;
-            case 12:
-            {
-              inputs_right[device].right = 
-               (inputs_right[device].right == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETINPUTRIGHT, &inputs_right[device]);
-            };break;
-          }
-          ioctl(fd, MIXIOGETINPUTLEFT, &inputs_left[device]);
-          ioctl(fd, MIXIOGETINPUTRIGHT, &inputs_right[device]);
-          show_inputs(41,8);
-        }
-      };break;
-      case 's':
-      {
-        if (write_settings())  
-          mvwprintw(main_win,22,28, "mixer settings saved");
-        else
-          mvwprintw(main_win,22,28, "error: file not saved");
-        wrefresh(main_win);
-        sleep(1);
-        mvwprintw(main_win,22,28, "                           ");
-      };break;
-      case 'r':
-      {
-        if (read_settings())
-          mvwprintw(main_win,22,28, "mixer settings restored");
-        else
-          mvwprintw(main_win,22,28, "error: could not open");
-        wrefresh(main_win);
-        sleep(1);
-        setup_screen();
-      };break;
-      case 'e': terminate(1);
-    }
-  } 
-}
-
-
-char *d_name(device, name)
-enum Device device;
-char *name;
-{
-  /* Convert the device number to a name */
-
-  switch (device)
-  {
-    case Master:	strncpy(name, "Master  \0", 9);break;
-    case Dac:		strncpy(name, "Dac     \0", 9);break;
-    case Fm:		strncpy(name, "Fm      \0", 9);break;
-    case Cd:		strncpy(name, "CD      \0", 9);break;
-    case Line:		strncpy(name, "Line    \0", 9);break;
-    case Mic:		strncpy(name, "Mic     \0", 9);break;
-    case Speaker:	strncpy(name, "Speaker \0", 9);break;
-    case Treble:	strncpy(name, "Treble  \0", 9);break;
-    case Bass:		strncpy(name, "Bass    \0", 9);break;
-  }
-  return name;
-}
-
-
-void create_slider(x, y, device)
-int x;
-int y;
-enum Device device;
-{
-  /* Create a slider on the screen */
-
-  int left;
-  int right;
-  int i;
-
-  mvwprintw(main_win,y,x, "%s", d_name(device, name));
-
-  left = levels[device].left / (device < Speaker ? 2 : 1); 
-  right = levels[device].right / (device < Speaker ? 2 : 1); 
-
-  for (i = 0; i < 16; i++)
-  {
-    if (device != Speaker || i < 4)
-      mvwprintw(main_win,y,x+i+8, (i == left ? "*" : "-"));
-    if (device < Mic || device > Speaker) 
-      mvwprintw(main_win,y+1,x+i+8, (i == right ? "*" : "-"));
-  }
-
-  if (device < Mic || device > Speaker)
-  {
-    mvwprintw(main_win,y,x+i+10, "left");
-    mvwprintw(main_win,y+1,x+i+10, "right");
-  }
-  wrefresh(main_win);
-} 
-  
-void show_inputs(x,y)
-int x;
-int y;
-{
-  /* Show the input settings */
-
-  int i;
-
-  mvwprintw(main_win,y,x,  "             Rec-In  ");
-  mvwprintw(main_win,y+1,x,"          left    right");
-  mvwprintw(main_win,y+2,x,"          l   r   l   r");
-  for (i = Fm; i <= Line; i++)
-  {
-    mvwprintw(main_win,y+i+1,x,  "%s  %d   %d   %d   %d", 
-      d_name(i, (char *)name),
-      (inputs_left[i].left == ON ? 1 : 0),
-      (inputs_left[i].right == ON ? 1 : 0),
-      (inputs_right[i].left == ON ? 1 : 0),
-      (inputs_right[i].right == ON ? 1 : 0));
-  }
-  mvwprintw(main_win,y+i+1,x,  "%s    %d       %d", 
-    d_name(Mic, (char *)name),
-    (inputs_left[Mic].left == ON ? 1 : 0),
-    (inputs_right[Mic].left == ON ? 1 : 0));
-  wrefresh(main_win);
-}
-
-void show_outputs(x,y)
-int x;
-int y;
-{
-  /* Show the output settings */
-
-  int i;
-
-  mvwprintw(main_win,y,x,      "            Mix-Out  ");
-  mvwprintw(main_win,y+1,x,    "          left    right");
-  for (i = Cd; i <= Line; i++)
-  {
-    mvwprintw(main_win,y+i-1,x,"%s    %d       %d", 
-      d_name(i, (char *)name),
-      (outputs[i].left == ON ? 1 : 0),
-      (outputs[i].right == ON ? 1 : 0));
-  }
-  mvwprintw(main_win,y+i-1,x,"%s        %d", 
-    d_name(Mic, (char *)name),
-    (outputs[Mic].left == ON ? 1 : 0));
-
-  wrefresh(main_win);
-}
-
-
-void setup_screen()
-{
-  int i;
-
-  wclear(main_win);
-  mvwprintw(main_win,0,23,"------- Mixer Controls -------");
-  wrefresh(main_win);
- 
-  for(i = 0; i <= Speaker; i++)
-   create_slider(1, i*3+(i <= Mic ? 2 : 1), i);
-
-   create_slider(40, 2, Treble);
-   create_slider(40, 5, Bass);
- 
-   show_inputs(41,8);
-   show_outputs(41,16);
-}
Index: trunk/minix/commands/ibm/part.c
===================================================================
--- trunk/minix/commands/ibm/part.c	(revision 9)
+++ 	(revision )
@@ -1,2124 +1,0 @@
-/*	part 1.57 - Partition table editor		Author: Kees J. Bot
- *								13 Mar 1992
- * Needs about 22k heap+stack.
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <termcap.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <time.h>
-#include <dirent.h>
-#include <limits.h>
-#include <a.out.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/ioctl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <termios.h>
-
-/* True if a partition is an extended partition. */
-#define ext_part(s)	((s) == 0x05 || (s) == 0x0F)
-
-/* Minix master bootstrap code. */
-static char MASTERBOOT[] = "/usr/mdec/masterboot";
-
-/* Template:
-                      ----first----  --geom/last--  ------sectors-----
-    Device             Cyl Head Sec   Cyl Head Sec      Base      Size        Kb
-    /dev/c0d0                          977    5  17
-    /dev/c0d0:2          0    0   2   976    4  16         2     83043     41521
-Num Sort   Type
- 0* p0   81 MINIX        0    0   3    33    4   9         3      2880      1440
- 1  p1   81 MINIX       33    4  10   178    2   2      2883     12284      6142
- 2  p2   81 MINIX      178    2   3   976    4  16     15167     67878     33939
- 3  p3   00 None         0    0   0     0    0  -1         0         0         0
-
- */
-#define MAXSIZE		999999999L	/* Will 1T be enough this year? */
-#define SECTOR_SIZE	512
-#define DEV_FD0		0x200		/* Device number of /dev/fd0 */
-#define DEV_C0D0	0x300		/* Device number of /dev/c0d0 */
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-void report(const char *label)
-{
-	fprintf(stderr, "part: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-struct termios termios;
-
-void save_ttyflags(void)
-/* Save tty attributes for later restoration. */
-{
-	if (tcgetattr(0, &termios) < 0) fatal("");
-}
-
-void restore_ttyflags(void)
-/* Reset the tty flags to how we got 'em. */
-{
-	if (tcsetattr(0, TCSANOW, &termios) < 0) fatal("");
-}
-
-void tty_raw(void)
-/* Set the terminal to raw mode, no signals, no echoing. */
-{
-	struct termios rawterm;
-
-	rawterm= termios;
-	rawterm.c_lflag &= ~(ICANON|ISIG|ECHO);
-	rawterm.c_iflag &= ~(ICRNL);
-	if (tcsetattr(0, TCSANOW, &rawterm) < 0) fatal("");
-}
-
-#define ctrl(c)		((c) == '?' ? '\177' : ((c) & '\37'))
-
-char t_cd[16], t_cm[32], t_so[16], t_se[16], t_md[16], t_me[16];
-int t_li, t_co;
-#define STATUSROW	10
-
-void init_tty(void)
-/* Get terminal capabilities and set the tty to "editor" mode. */
-{
-	char *term;
-	static char termbuf[1024];
-	char *tp;
-
-	if ((term= getenv("TERM")) == nil || tgetent(termbuf, term) != 1) {
-		fprintf(stderr, "part: Can't get terminal capabilities\n");
-		exit(1);
-	}
-	if (tgetstr("cd", (tp= t_cd, &tp)) == nil
-				|| tgetstr("cm", (tp= t_cm, &tp)) == nil) {
-		fprintf(stderr, "part: This terminal is too dumb\n");
-		exit(1);
-	}
-	t_li= tgetnum("li");
-	t_co= tgetnum("co");
-	(void) tgetstr("so", (tp= t_so, &tp));
-	(void) tgetstr("se", (tp= t_se, &tp));
-	(void) tgetstr("md", (tp= t_md, &tp));
-	(void) tgetstr("me", (tp= t_me, &tp));
-
-	save_ttyflags();
-	tty_raw();
-}
-
-void putchr(int c)
-{
-	putchar(c);
-}
-
-void putstr(char *s)
-{
-	int c;
-
-	while ((c= *s++) != 0) putchr(c);
-}
-
-void set_cursor(int row, int col)
-{
-	tputs(tgoto(t_cm, col, row), 1, putchr);
-}
-
-int statusrow= STATUSROW;
-int stat_ktl= 1;
-int need_help= 1;
-
-void stat_start(int serious)
-/* Prepare for printing on a fresh status line, possibly highlighted. */
-{
-	set_cursor(statusrow++, 0);
-	tputs(t_cd, 1, putchr);
-	if (serious) tputs(t_so, 1, putchr);
-}
-
-void stat_end(int ktl)
-/* Closing bracket for stat_start.  Sets "keystrokes to live" of message. */
-{
-	tputs(t_se, 1, putchr);
-	stat_ktl= ktl;
-	need_help= 1;
-}
-
-void stat_reset(void)
-/* Reset the statusline pointer and clear old messages if expired. */
-{
-	if (stat_ktl > 0 && --stat_ktl == 0) {
-		statusrow= STATUSROW;
-		need_help= 1;
-	}
-	if (need_help && statusrow < (24-2)) {
-		if (statusrow > STATUSROW) stat_start(0);
-		stat_start(0);
-		putstr(
-"Type '+' or '-' to change, 'r' to read, '?' for more help, 'q' to exit");
-	}
-	statusrow= STATUSROW;
-	need_help= 0;
-}
-
-void clear_screen(void)
-{
-	set_cursor(0, 0);
-	tputs(t_cd, 1, putchr);
-	stat_ktl= 1;
-	stat_reset();
-}
-
-void reset_tty(void)
-/* Reset the tty to cooked mode. */
-{
-	restore_ttyflags();
-	set_cursor(statusrow, 0);
-	tputs(t_cd, 1, putchr);
-}
-
-void *alloc(size_t n)
-{
-	void *m;
-
-	if ((m= malloc(n)) == nil) { reset_tty(); fatal(""); }
-
-	return m;
-}
-
-#ifndef makedev		/* Missing in sys/types.h */
-#define minor(dev)	(((dev) >> MINOR) & BYTE)
-#define major(dev)	(((dev) >> MAJOR) & BYTE)
-#define makedev(major, minor)	\
-			((dev_t) (((major) << MAJOR) | ((minor) << MINOR)))
-#endif
-
-typedef enum parttype { DUNNO, SUBPART, PRIMARY, FLOPPY } parttype_t;
-
-typedef struct device {
-	struct device *next, *prev;	/* Circular dequeue. */
-	dev_t	rdev;			/* Device number (sorting only). */
-	char	*name;			/* E.g. /dev/c0d0 */
-	char	*subname;		/* E.g. /dev/c0d0:2 */
-	parttype_t parttype;
-} device_t;
-
-device_t *firstdev= nil, *curdev;
-
-void newdevice(char *name, int scanning)
-/* Add a device to the device list.  If scanning is set then we are reading
- * /dev, so insert the device in device number order and make /dev/c0d0 current.
- */
-{
-	device_t *new, *nextdev, *prevdev;
-	struct stat st;
-
-	st.st_rdev= 0;
-	if (scanning) {
-		if (stat(name, &st) < 0 || !S_ISBLK(st.st_mode)) return;
-
-		switch (major(st.st_rdev)) {
-		case 2:
-			/* Floppy */
-			if (minor(st.st_rdev) >= 4) return;
-			break;
-		case 3:
-		case 8:
-		case 10:
-		case 12:
-		case 16:
-			/* Disk controller */
-			if (minor(st.st_rdev) >= 0x80
-					|| minor(st.st_rdev) % 5 != 0) return;
-			break;
-		default:
-			return;
-		}
-		/* Interesting device found. */
-	} else {
-		(void) stat(name, &st);
-	}
-
-	new= alloc(sizeof(*new));
-	new->rdev= st.st_rdev;
-	new->name= alloc((strlen(name) + 1) * sizeof(new->name[0]));
-	strcpy(new->name, name);
-	new->subname= new->name;
-	new->parttype= DUNNO;
-	if (major(st.st_rdev) == major(DEV_FD0) && minor(st.st_rdev) < 112) {
-		new->parttype= FLOPPY;
-	} else
-	if (st.st_rdev >= DEV_C0D0 && minor(st.st_rdev) < 128
-			&& minor(st.st_rdev) % 5 == 0) {
-		new->parttype= PRIMARY;
-	}
-
-	if (firstdev == nil) {
-		firstdev= new;
-		new->next= new->prev= new;
-		curdev= firstdev;
-		return;
-	}
-	nextdev= firstdev;
-	while (new->rdev >= nextdev->rdev
-				&& (nextdev= nextdev->next) != firstdev) {}
-	prevdev= nextdev->prev;
-	new->next= nextdev;
-	nextdev->prev= new;
-	new->prev= prevdev;
-	prevdev->next= new;
-
-	if (new->rdev < firstdev->rdev) firstdev= new;
-	if (new->rdev == DEV_C0D0) curdev= new;
-	if (curdev->rdev != DEV_C0D0) curdev= firstdev;
-}
-
-void getdevices(void)
-/* Get all block devices from /dev that look interesting. */
-{
-	DIR *d;
-	struct dirent *e;
-	char name[5 + NAME_MAX + 1];
-
-	if ((d= opendir("/dev")) == nil) fatal("/dev");
-
-	while ((e= readdir(d)) != nil) {
-		strcpy(name, "/dev/");
-		strcpy(name + 5, e->d_name);
-		newdevice(name, 1);
-	}
-	(void) closedir(d);
-}
-
-/* One featureful master bootstrap. */
-unsigned char bootstrap[] = {
-0353,0001,0000,0061,0300,0216,0330,0216,0300,0372,0216,0320,0274,0000,0174,0373,
-0275,0276,0007,0211,0346,0126,0277,0000,0006,0271,0000,0001,0374,0363,0245,0352,
-0044,0006,0000,0000,0264,0002,0315,0026,0250,0010,0164,0033,0350,0071,0001,0174,
-0007,0060,0344,0315,0026,0242,0205,0007,0054,0060,0074,0012,0163,0363,0120,0350,
-0046,0001,0205,0007,0130,0353,0012,0240,0002,0006,0204,0300,0165,0003,0351,0147,
-0000,0230,0262,0005,0366,0362,0262,0200,0000,0302,0210,0340,0120,0350,0234,0000,
-0163,0003,0351,0147,0000,0130,0054,0001,0175,0003,0351,0141,0000,0276,0276,0175,
-0211,0357,0271,0040,0000,0363,0245,0200,0301,0004,0211,0356,0215,0174,0020,0070,
-0154,0004,0164,0016,0213,0135,0010,0053,0134,0010,0213,0135,0012,0033,0134,0012,
-0163,0014,0212,0044,0206,0144,0020,0210,0044,0106,0071,0376,0162,0364,0211,0376,
-0201,0376,0356,0007,0162,0326,0342,0322,0211,0356,0264,0020,0366,0344,0001,0306,
-0200,0174,0004,0001,0162,0026,0353,0021,0204,0322,0175,0041,0211,0356,0200,0174,
-0004,0000,0164,0013,0366,0004,0200,0164,0006,0350,0070,0000,0162,0053,0303,0203,
-0306,0020,0201,0376,0376,0007,0162,0346,0350,0215,0000,0211,0007,0376,0302,0204,
-0322,0174,0023,0315,0021,0321,0340,0321,0340,0200,0344,0003,0070,0342,0167,0355,
-0350,0011,0000,0162,0350,0303,0350,0003,0000,0162,0146,0303,0211,0356,0214,0134,
-0010,0214,0134,0012,0277,0003,0000,0122,0006,0127,0264,0010,0315,0023,0137,0007,
-0200,0341,0077,0376,0306,0210,0310,0366,0346,0211,0303,0213,0104,0010,0213,0124,
-0012,0367,0363,0222,0210,0325,0366,0361,0060,0322,0321,0352,0321,0352,0010,0342,
-0210,0321,0376,0301,0132,0210,0306,0273,0000,0174,0270,0001,0002,0315,0023,0163,
-0020,0200,0374,0200,0164,0011,0117,0174,0006,0060,0344,0315,0023,0163,0270,0371,
-0303,0201,0076,0376,0175,0125,0252,0165,0001,0303,0350,0013,0000,0243,0007,0353,
-0005,0350,0004,0000,0227,0007,0353,0376,0136,0255,0126,0211,0306,0254,0204,0300,
-0164,0011,0264,0016,0273,0001,0000,0315,0020,0353,0362,0303,0057,0144,0145,0166,
-0057,0150,0144,0077,0010,0000,0015,0012,0000,0116,0157,0156,0145,0040,0141,0143,
-0164,0151,0166,0145,0015,0012,0000,0122,0145,0141,0144,0040,0145,0162,0162,0157,
-0162,0040,0000,0116,0157,0164,0040,0142,0157,0157,0164,0141,0142,0154,0145,0040,
-0000,0000,
-};
-
-int dirty= 0;
-unsigned char bootblock[SECTOR_SIZE];
-struct part_entry table[1 + NR_PARTITIONS];
-int existing[1 + NR_PARTITIONS];
-unsigned long offset= 0, extbase= 0, extsize;
-int submerged= 0;
-char sort_index[1 + NR_PARTITIONS];
-unsigned cylinders= 1, heads= 1, sectors= 1, secpcyl= 1;
-unsigned alt_cyls= 1, alt_heads= 1, alt_secs= 1;
-int precise= 0;
-int device= -1;
-
-unsigned long sortbase(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? -1 : pe->lowsec;
-}
-
-void sort(void)
-/* Let the sort_index array show the order partitions are sorted in. */
-{
-	int i, j;
-	int idx[1 + NR_PARTITIONS];
-
-	for (i= 1; i <= NR_PARTITIONS; i++) idx[i]= i;
-
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		for (j= 1; j <= NR_PARTITIONS-1; j++) {
-			int sj= idx[j], sj1= idx[j+1];
-
-			if (sortbase(&table[sj]) > sortbase(&table[sj1])) {
-				idx[j]= sj1;
-				idx[j+1]= sj;
-			}
-		}
-	}
-	for (i= 1; i <= NR_PARTITIONS; i++) sort_index[idx[i]]= i;
-}
-
-void dos2chs(unsigned char *dos, unsigned *chs)
-/* Extract cylinder, head and sector from the three bytes DOS uses to address
- * a sector.  Note that bits 8 & 9 of the cylinder number come from bit 6 & 7
- * of the sector byte.  The sector number is rebased to count from 0.
- */
-{
-	chs[0]= ((dos[1] & 0xC0) << 2) | dos[2];
-	chs[1]= dos[0];
-	chs[2]= (dos[1] & 0x3F) - 1;
-}
-
-void abs2dos(unsigned char *dos, unsigned long pos)
-/* Translate a sector offset to three DOS bytes. */
-{
-	unsigned h, c, s;
-
-	c= pos / secpcyl;
-	h= (pos % secpcyl) / sectors;
-	s= pos % sectors + 1;
-
-	dos[0]= h;
-	dos[1]= s | ((c >> 2) & 0xC0);
-	dos[2]= c & 0xFF;
-}
-
-void recompute0(void)
-/* Recompute the partition size for the device after a geometry change. */
-{
-	if (device < 0) {
-		cylinders= heads= sectors= 1;
-		memset(table, 0, sizeof(table));
-	} else
-	if (!precise && offset == 0) {
-		table[0].lowsec= 0;
-		table[0].size= (unsigned long) cylinders * heads * sectors;
-	}
-	table[0].sysind= device < 0 ? NO_PART : MINIX_PART;
-	secpcyl= heads * sectors;
-}
-
-void guess_geometry(void)
-/* With a bit of work one can deduce the disk geometry from the partition
- * table.  This may be necessary if the driver gets it wrong.  (If partition
- * tables didn't have C/H/S numbers we would not care at all...)
- */
-{
-	int i, n;
-	struct part_entry *pe;
-	unsigned chs[3];
-	unsigned long sec;
-	unsigned h, s;
-	unsigned char HS[256][8];	/* Bit map off all possible H/S */
-
-	alt_cyls= alt_heads= alt_secs= 0;
-
-	/* Initially all possible H/S combinations are possible.  HS[h][0]
-	 * bit 0 is used to rule out a head value.
-	 */
-	for (h= 1; h <= 255; h++) {
-		for (s= 0; s < 8; s++) HS[h][s]= 0xFF;
-	}
-
-	for (i= 0; i < 2*NR_PARTITIONS; i++) {
-		pe= &(table+1)[i >> 1];
-		if (pe->sysind == NO_PART) continue;
-
-		/* Get the end or start sector numbers (in that order). */
-		if ((i & 1) == 0) {
-			dos2chs(&pe->last_head, chs);
-			sec= pe->lowsec + pe->size - 1;
-		} else {
-			dos2chs(&pe->start_head, chs);
-			sec= pe->lowsec;
-		}
-
-		if (chs[0] >= alt_cyls) alt_cyls= chs[0]+1;
-
-		/* Which H/S combinations can be ruled out? */
-		for (h= 1; h <= 255; h++) {
-			if (HS[h][0] == 0) continue;
-			n = 0;
-			for (s= 1; s <= 63; s++) {
-				if ((chs[0] * h + chs[1]) * s + chs[2] != sec) {
-					HS[h][s/8] &= ~(1 << (s%8));
-				}
-				if (HS[h][s/8] & (1 << (s%8))) n++;
-			}
-			if (n == 0) HS[h][0]= 0;
-		}
-	}
-
-	/* See if only one remains. */
-	i= 0;
-	for (h= 1; h <= 255; h++) {
-		if (HS[h][0] == 0) continue;
-		for (s= 1; s <= 63; s++) {
-			if (HS[h][s/8] & (1 << (s%8))) {
-				i++;
-				alt_heads= h;
-				alt_secs= s;
-			}
-		}
-	}
-
-	/* Forget it if more than one choice... */
-	if (i > 1) alt_cyls= alt_heads= alt_secs= 0;
-}
-
-void geometry(void)
-/* Find out the geometry of the device by querying the driver, or by looking
- * at the partition table.  These numbers are crosschecked to make sure that
- * the geometry is correct.  Master bootstraps other than the Minix one use
- * the CHS numbers in the partition table to load the bootstrap of the active
- * partition.
- */
-{
-	struct stat dst;
-	int err= 0;
-	struct partition geometry;
-
-	if (submerged) {
-		/* Geometry already known. */
-		sort();
-		return;
-	}
-	precise= 0;
-	cylinders= 0;
-	recompute0();
-	if (device < 0) return;
-
-	/* Try to guess the geometry from the partition table. */
-	guess_geometry();
-
-	/* Try to get the geometry from the driver. */
-	(void) fstat(device, &dst);
-
-	if (S_ISBLK(dst.st_mode) || S_ISCHR(dst.st_mode)) {
-		/* Try to get the drive's geometry from the driver. */
-
-		if (ioctl(device, DIOCGETP, &geometry) < 0)
-			err= errno;
-		else {
-			table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
-			table[0].size= div64u(geometry.size, SECTOR_SIZE);
-			cylinders= geometry.cylinders;
-			heads= geometry.heads;
-			sectors= geometry.sectors;
-			precise= 1;
-		}
-	} else {
-		err= ENODEV;
-	}
-
-	if (err != 0) {
-		/* Getting the geometry from the driver failed, so use the
-		 * alternate geometry.
-		 */
-		if (alt_heads == 0) {
-			alt_cyls= table[0].size / (64 * 32);
-			alt_heads= 64;
-			alt_secs= 32;
-		}
-
-		cylinders= alt_cyls;
-		heads= alt_heads;
-		sectors= alt_secs;
-
-		stat_start(1);
-		printf("Failure to get the geometry of %s: %s", curdev->name,
-			errno == ENOTTY ? "No driver support" : strerror(err));
-		stat_end(5);
-		stat_start(0);
-		printf("The geometry has been guessed as %ux%ux%u",
-						cylinders, heads, sectors);
-		stat_end(5);
-	} else {
-		if (alt_heads == 0) {
-			alt_cyls= cylinders;
-			alt_heads= heads;
-			alt_secs= sectors;
-		}
-
-		if (heads != alt_heads || sectors != alt_secs) {
-			stat_start(1);
-			printf("WARNING:");
-			stat_end(10);
-			stat_start(0);
-			printf(
-"The %ux%ux%u geometry obtained from the device driver does not match",
-				cylinders, heads, sectors);
-			stat_end(10);
-			stat_start(0);
-			printf(
-"the %ux%ux%u geometry implied by the partition table.  Hit 'X' to switch",
-				alt_cyls, alt_heads, alt_secs);
-			stat_end(10);
-			stat_start(0);
-			printf(
-"between the two geometries to see what is best.  Note that the geometry");
-			stat_end(10);
-			stat_start(0);
-			printf(
-"must be correct when the table is written or the system may not boot!");
-			stat_end(10);
-		}
-	}
-
-	/* Show the base and size of the device instead of the whole drive.
-	 * This makes sense for subpartitioning primary partitions.
-	 */
-	if (precise && ioctl(device, DIOCGETP, &geometry) >= 0) {
-		table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
-		table[0].size= div64u(geometry.size, SECTOR_SIZE);
-	} else {
-		precise= 0;
-	}
-	recompute0();
-	sort();
-}
-
-typedef struct indicators {	/* Partition type to partition name. */
-	unsigned char	ind;
-	char		name[10];
-} indicators_t;
-
-indicators_t ind_table[]= {
-	{ 0x00,		"None"		},
-	{ 0x01,		"FAT-12"	},
-	{ 0x02,		"XENIX /"	},
-	{ 0x03,		"XENIX usr"	},
-	{ 0x04,		"FAT-16"	},
-	{ 0x05,		"EXTENDED"	},
-	{ 0x06,		"FAT-16"	},
-	{ 0x07,		"HPFS/NTFS"	},
-	{ 0x08,		"AIX"		},
-	{ 0x09,		"COHERENT"	},
-	{ 0x0A,		"OS/2"		},
-	{ 0x0B,		"FAT-32"	},
-	{ 0x0C,		"FAT?"		},
-	{ 0x0E,		"FAT?"		},
-	{ 0x0F,		"EXTENDED"	},
-	{ 0x10,		"OPUS"		},
-	{ 0x40,		"VENIX286"	},
-	{ 0x42,		"W2000 Dyn"	},
-	{ 0x52,		"MICROPORT"	},
-	{ 0x63,		"386/IX"	},
-	{ 0x64,		"NOVELL286"	},
-	{ 0x65,		"NOVELL386"	},
-	{ 0x75,		"PC/IX"		},
-	{ 0x80,		"MINIX-OLD"	},
-	{ 0x81,		"MINIX"		},
-	{ 0x82,		"LINUXswap"	},
-	{ 0x83,		"LINUX"		},
-	{ 0x93,		"AMOEBA"	},
-	{ 0x94,		"AMOEBAbad"	},
-	{ 0xA5,		"386BSD"	},
-	{ 0xB7,		"BSDI"		},
-	{ 0xB8,		"BSDI swap"	},
-	{ 0xC7,		"SYRINX"	},
-	{ 0xDB,		"CPM"		},
-	{ 0xFF,		"BADBLOCKS"	},
-};
-
-char *typ2txt(int ind)
-/* Translate a numeric partition indicator for human eyes. */
-{
-	indicators_t *pind;
-
-	for (pind= ind_table; pind < arraylimit(ind_table); pind++) {
-		if (pind->ind == ind) return pind->name;
-	}
-	return "";
-}
-
-int round_sysind(int ind, int delta)
-/* Find the next known partition type starting with ind in direction delta. */
-{
-	indicators_t *pind;
-
-	ind= (ind + delta) & 0xFF;
-
-	if (delta < 0) {
-		for (pind= arraylimit(ind_table)-1; pind->ind > ind; pind--) {}
-	} else {
-		for (pind= ind_table; pind->ind < ind; pind++) {}
-	}
-	return pind->ind;
-}
-
-/* Objects on the screen, either simple pieces of the text or the cylinder
- * number of the start of partition three.
- */
-typedef enum objtype {
-	O_INFO, O_TEXT, O_DEV, O_SUB,
-	O_TYPTXT, O_SORT, O_NUM, O_TYPHEX,
-	O_CYL, O_HEAD, O_SEC,
-	O_SCYL, O_SHEAD, O_SSEC, O_LCYL, O_LHEAD, O_LSEC, O_BASE, O_SIZE, O_KB
-} objtype_t;
-
-#define rjust(type)	((type) >= O_TYPHEX)
-#define computed(type)	((type) >= O_TYPTXT)
-
-typedef struct object {
-	struct object	*next;
-	objtype_t	type;		/* Text field, cylinder number, etc. */
-	char		flags;		/* Modifiable? */
-	char		row;
-	char		col;
-	char		len;
-	struct part_entry *entry;	/* What does the object refer to? */
-	char		  *text;
-	char		value[20];	/* Value when printed. */
-} object_t;
-
-#define OF_MOD		0x01	/* Object value is modifiable. */
-#define OF_ODD		0x02	/* It has a somewhat odd value. */
-#define OF_BAD		0x04	/* Its value is no good at all. */
-
-/* Events: (Keypress events are the value of the key pressed.) */
-#define E_ENTER		(-1)	/* Cursor moves onto object. */
-#define E_LEAVE		(-2)	/* Cursor leaves object. */
-#define E_WRITE		(-3)	/* Write, but not by typing 'w'. */
-
-/* The O_SIZE objects have a dual identity. */
-enum howend { SIZE, LAST } howend= SIZE;
-
-object_t *world= nil;
-object_t *curobj= nil;
-
-object_t *newobject(objtype_t type, int flags, int row, int col, int len)
-/* Make a new object given a type, flags, position and length on the screen. */
-{
-	object_t *new;
-	object_t **aop= &world;
-
-	new= alloc(sizeof(*new));
-
-	new->type= type;
-	new->flags= flags;
-	new->row= row;
-	new->col= col;
-	new->len= len;
-	new->entry= nil;
-	new->text= "";
-	new->value[0]= 0;
-
-	new->next= *aop;
-	*aop= new;
-
-	return new;
-}
-
-unsigned long entry2base(struct part_entry *pe)
-/* Return the base sector of the partition if defined. */
-{
-	return pe->sysind == NO_PART ? 0 : pe->lowsec;
-}
-
-unsigned long entry2last(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? -1 : pe->lowsec + pe->size - 1;
-}
-
-unsigned long entry2size(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? 0 : pe->size;
-}
-
-int overlap(unsigned long sec)
-/* See if sec is part of another partition. */
-{
-	struct part_entry *pe;
-
-	for (pe= table + 1; pe <= table + NR_PARTITIONS; pe++) {
-		if (pe->sysind == NO_PART) continue;
-
-		if (pe->lowsec < sec && sec < pe->lowsec + pe->size)
-			return 1;
-	}
-	return 0;
-}
-
-int aligned(unsigned long sec, unsigned unit)
-/* True if sec is aligned to unit or if it is no problem if it is unaligned. */
-{
-	return (offset != 0 && extbase == 0) || (sec % unit == 0);
-}
-
-void print(object_t *op)
-/* Print an object's value if it changed. */
-{
-	struct part_entry *pe= op->entry;
-	int n;
-	unsigned long t;
-	char *name;
-	int oldflags;
-	char oldvalue[20];
-
-	/* Remember the old flags and value. */
-	oldflags= op->flags;
-	strcpy(oldvalue, op->value);
-
-	op->flags&= ~(OF_ODD | OF_BAD);
-
-	switch (op->type) {
-	case O_INFO:		{
-				/* Current field. */
-		static struct field { int type; char *name; } fields[]= {
-			{ O_DEV,	"Select device"		},
-			{ O_NUM,	"Active flag"		},
-			{ O_TYPHEX,	"Hex partition type"	},
-			{ O_TYPTXT,	"Partition type"	},
-			{ O_SCYL,	"Start cylinder"	},
-			{ O_SHEAD,	"Start head"		},
-			{ O_SSEC,	"Start sector"		},
-			{ O_CYL,	"Number of cylinders"	},
-			{ O_HEAD,	"Number of heads"	},
-			{ O_SEC,	"Sectors per track"	},
-			{ O_LCYL,	"Last cylinder"		},
-			{ O_LHEAD,	"Last head"		},
-			{ O_LSEC,	"Last sector"		},
-			{ O_BASE,	"Base sector"		},
-			{ O_SIZE,	"Size in sectors"	},
-			{ O_KB,		"Size in kilobytes"	},
-			{ -1,		"?"			},
-		};
-		struct field *fp= fields;
-
-		while (fp->type >= 0 && fp->type != curobj->type) fp++;
-		strcpy(op->value, fp->name);
-		op->flags|= OF_ODD;
-		break;		}
-	case O_TEXT:
-				/* Simple text field. */
-		strcpy(op->value, op->text);
-		break;
-	case O_DEV:
-	case O_SUB:
-				/* Name of currently edited device. */
-		name= op->type == O_DEV ? curdev->name :
-					offset == 0 ? "" : curdev->subname;
-		if ((n= strlen(name)) < op->len) n= op->len;
-		strcpy(op->value, name + (n - op->len));
-		if (device < 0 && op->type == O_DEV) op->flags|= OF_BAD;
-		break;
-	case O_NUM:
-				/* Position and active flag. */
-		sprintf(op->value, "%d%c", (int) (pe - table - 1),
-					pe->bootind & ACTIVE_FLAG ? '*' : ' ');
-		break;
-	case O_SORT:
-				/* Position if the driver sorts the table. */
-		sprintf(op->value, "%s%d",
-			curdev->parttype >= PRIMARY ? "p" :
-				curdev->parttype == SUBPART ? "s" : "",
-			(curdev->parttype == SUBPART ||
-				curdev->parttype == FLOPPY ? pe - table
-					: sort_index[pe - table]) - 1);
-		break;
-	case O_TYPHEX:
-				/* Hex partition type indicator. */
-		sprintf(op->value, "%02X", pe->sysind);
-		break;
-	case O_TYPTXT:
-				/* Ascii partition type indicator. */
-		strcpy(op->value, typ2txt(pe->sysind));
-		break;
-	case O_SCYL:
-				/* Partition's start cylinder. */
-		sprintf(op->value, "%lu", entry2base(pe) / secpcyl);
-		break;
-	case O_SHEAD:
-				/* Start head. */
-		t= entry2base(pe);
-		sprintf(op->value, "%lu", t % secpcyl / sectors);
-		if (!aligned(t, secpcyl) && t != table[0].lowsec + sectors)
-			op->flags|= OF_ODD;
-		break;
-	case O_SSEC:
-				/* Start sector. */
-		t= entry2base(pe);
-		sprintf(op->value, "%lu", t % sectors);
-		if (!aligned(t, sectors)) op->flags|= OF_ODD;
-		break;
-	case O_CYL:
-				/* Number of cylinders. */
-		sprintf(op->value, "%u", cylinders);
-		break;
-	case O_HEAD:
-				/* Number of heads. */
-		sprintf(op->value, "%u", heads);
-		break;
-	case O_SEC:
-				/* Number of sectors per track. */
-		sprintf(op->value, "%u", sectors);
-		break;
-	case O_LCYL:
-				/* Partition's last cylinder. */
-		t= entry2last(pe);
-		sprintf(op->value, "%lu", t == -1 ? 0 : t / secpcyl);
-		break;
-	case O_LHEAD:
-				/* Partition's last head. */
-		t= entry2last(pe);
-		sprintf(op->value, "%lu", t == -1 ? 0 : t % secpcyl / sectors);
-		if (!aligned(t + 1, secpcyl)) op->flags|= OF_ODD;
-		break;
-	case O_LSEC:
-				/* Partition's last sector. */
-		t= entry2last(pe);
-		sprintf(op->value, t == -1 ? "-1" : "%lu", t % sectors);
-		if (!aligned(t + 1, sectors)) op->flags|= OF_ODD;
-		break;
-	case O_BASE:
-				/* Partition's base sector. */
-		sprintf(op->value, "%lu", entry2base(pe));
-		if (pe->sysind != NO_PART && pe != &table[0]
-		   && (pe->lowsec <= table[0].lowsec || overlap(pe->lowsec)))
-			op->flags|= OF_BAD;
-		break;
-	case O_SIZE:
-				/* Size of partitition in sectors. */
-		t= howend == SIZE ? entry2size(pe) : entry2last(pe);
-		sprintf(op->value, "%lu", pe->sysind == NO_PART ? 0 : t);
-		if (pe->sysind != NO_PART && (pe->size == 0
-		    || pe->lowsec + pe->size > table[0].lowsec + table[0].size
-		    || overlap(pe->lowsec + pe->size)))
-			op->flags|= OF_BAD;
-		break;
-	case O_KB:
-				/* Size of partitition in kilobytes. */
-		sprintf(op->value, "%lu", entry2size(pe) / 2);
-		break;
-	default:
-		sprintf(op->value, "?? %d ??", op->type);
-	}
-
-	if (device < 0 && computed(op->type)) strcpy(op->value, "?");
-
-	/* If a value overflows the print field then show a blank
-	 * reverse video field.
-	 */
-	if ((n= strlen(op->value)) > op->len) {
-		n= 0;
-		op->flags|= OF_BAD;
-	}
-
-	/* Right or left justified? */
-	if (rjust(op->type)) {
-		memmove(op->value + (op->len - n), op->value, n);
-		memset(op->value, ' ', op->len - n);
-	} else {
-		memset(op->value + n, ' ', op->len - n);
-	}
-	op->value[op->len]= 0;
-
-	if ((op->flags & (OF_ODD | OF_BAD)) == (oldflags & (OF_ODD | OF_BAD))
-				&& strcmp(op->value, oldvalue) == 0) {
-		/* The value did not change. */
-		return;
-	}
-
-	set_cursor(op->row, rjust(op->type) ? op->col - (op->len-1) : op->col);
-
-	if (op->flags & OF_BAD) tputs(t_so, 1, putchr);
-	else
-	if (op->flags & OF_ODD) tputs(t_md, 1, putchr);
-	putstr(op->value);
-	if (op->flags & OF_BAD) tputs(t_se, 1, putchr);
-	else
-	if (op->flags & OF_ODD) tputs(t_me, 1, putchr);
-}
-
-void display(void)
-/* Repaint all objects that changed. */
-{
-	object_t *op;
-
-	for (op= world; op != nil; op= op->next) print(op);
-}
-
-int typing;	/* Set if a digit has been typed to set a value. */
-int magic;	/* Changes when using the magic key. */
-
-void event(int ev, object_t *op);
-
-void m_redraw(int ev, object_t *op)
-/* Redraw the screen. */
-{
-	object_t *op2;
-
-	if (ev != ctrl('L')) return;
-
-	clear_screen();
-	for (op2= world; op2 != nil; op2= op2->next) op2->value[0]= 0;
-}
-
-void m_toggle(int ev, object_t *op)
-/* Toggle between the driver and alternate geometry. */
-{
-	unsigned t;
-
-	if (ev != 'X') return;
-	if (alt_cyls == cylinders && alt_heads == heads && alt_secs == sectors)
-		return;
-
-	t= cylinders; cylinders= alt_cyls; alt_cyls= t;
-	t= heads; heads= alt_heads; alt_heads= t;
-	t= sectors; sectors= alt_secs; alt_secs= t;
-	dirty= 1;
-	recompute0();
-}
-
-char size_last[]= "Size";
-
-void m_orientation(int ev, object_t *op)
-{
-	if (ev != ' ') return;
-
-	switch (howend) {
-	case SIZE:
-		howend= LAST;
-		strcpy(size_last, "Last");
-		break;
-	case LAST:
-		howend= SIZE;
-		strcpy(size_last, "Size");
-	}
-}
-
-void m_move(int ev, object_t *op)
-/* Move to the nearest modifiably object in the intended direction.  Objects
- * on the same row or column are really near.
- */
-{
-	object_t *near, *op2;
-	unsigned dist, d2, dr, dc;
-
-	if (ev != 'h' && ev != 'j' && ev != 'k' && ev != 'l' && ev != 'H')
-		return;
-
-	if (device < 0) {
-		/* No device open?  Then try to read first. */
-		event('r', op);
-		if (device < 0) return;
-	}
-
-	near= op;
-	dist= -1;
-
-	for (op2= world; op2 != nil; op2= op2->next) {
-		if (op2 == op || !(op2->flags & OF_MOD)) continue;
-
-		dr= abs(op2->row - op->row);
-		dc= abs(op2->col - op->col);
-
-		d2= 25*dr*dr + dc*dc;
-		if (op2->row != op->row && op2->col != op->col) d2+= 1000;
-
-		switch (ev) {
-		case 'h':	/* Left */
-			if (op2->col >= op->col) d2= -1;
-			break;
-		case 'j':	/* Down */
-			if (op2->row <= op->row) d2= -1;
-			break;
-		case 'k':	/* Up */
-			if (op2->row >= op->row) d2= -1;
-			break;
-		case 'l':	/* Right */
-			if (op2->col <= op->col) d2= -1;
-			break;
-		case 'H':	/* Home */
-			if (op2->type == O_DEV) d2= 0;
-		}
-		if (d2 < dist) { near= op2; dist= d2; }
-	}
-	if (near != op) event(E_LEAVE, op);
-	event(E_ENTER, near);
-}
-
-void m_updown(int ev, object_t *op)
-/* Move a partition table entry up or down. */
-{
-	int i, j;
-	struct part_entry tmp;
-	int tmpx;
-
-	if (ev != ctrl('K') && ev != ctrl('J')) return;
-	if (op->entry == nil) return;
-
-	i= op->entry - table;
-	if (ev == ctrl('K')) {
-		if (i <= 1) return;
-		j= i-1;
-	} else {
-		if (i >= NR_PARTITIONS) return;
-		j= i+1;
-	}
-
-	tmp= table[i]; table[i]= table[j]; table[j]= tmp;
-	tmpx= existing[i]; existing[i]= existing[j]; existing[j]= tmpx;
-	sort();
-	dirty= 1;
-	event(ev == ctrl('K') ? 'k' : 'j', op);
-}
-
-void m_enter(int ev, object_t *op)
-/* We've moved onto this object. */
-{
-	if (ev != E_ENTER && ev != ' ' && ev != '<' && ev != '>' && ev != 'X')
-		return;
-	curobj= op;
-	typing= 0;
-	magic= 0;
-}
-
-void m_leave(int ev, object_t *op)
-/* About to leave this object. */
-{
-	if (ev != E_LEAVE) return;
-}
-
-int within(unsigned *var, unsigned low, unsigned value, unsigned high)
-/* Only set *var to value if it looks reasonable. */
-{
-	if (low <= value && value <= high) {
-		*var= value;
-		return 1;
-	} else
-		return 0;
-}
-
-int lwithin(unsigned long *var, unsigned long low, unsigned long value,
-							unsigned long high)
-{
-	if (low <= value && value <= high) {
-		*var= value;
-		return 1;
-	} else
-		return 0;
-}
-
-int nextdevice(object_t *op, int delta)
-/* Select the next or previous device from the device list. */
-{
-	dev_t rdev;
-
-	if (offset != 0) return 0;
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return 0;
-
-	if (device >= 0) {
-		(void) close(device);
-		device= -1;
-	}
-	recompute0();
-
-	rdev= curdev->rdev;
-	if (delta < 0) {
-		do
-			curdev= curdev->prev;
-		while (delta < -1 && major(curdev->rdev) == major(rdev)
-			&& curdev->rdev < rdev);
-	} else {
-		do
-			curdev= curdev->next;
-		while (delta > 1 && major(curdev->rdev) == major(rdev)
-			&& curdev->rdev > rdev);
-	}
-	return 1;
-}
-
-void check_ind(struct part_entry *pe)
-/* If there are no other partitions then make this new one active. */
-{
-	struct part_entry *pe2;
-
-	if (pe->sysind != NO_PART) return;
-
-	for (pe2= table + 1; pe2 < table + 1 + NR_PARTITIONS; pe2++)
-		if (pe2->sysind != NO_PART || pe2->bootind & ACTIVE_FLAG) break;
-
-	if (pe2 == table + 1 + NR_PARTITIONS) pe->bootind= ACTIVE_FLAG;
-}
-
-int check_existing(struct part_entry *pe)
-/* Check and if not ask if an existing partition may be modified. */
-{
-	static int expert= 0;
-	int c;
-
-	if (expert || pe == nil || !existing[pe - table]) return 1;
-
-	stat_start(1);
-	putstr("Do you wish to modify existing partitions? (y/n) ");
-	fflush(stdout);
-	while ((c= getchar()) != 'y' && c != 'n') {}
-	putchr(c);
-	stat_end(3);
-	return (expert= (c == 'y'));
-}
-
-void m_modify(int ev, object_t *op)
-/* Increment, decrement, set, or toggle the value of an object, using
- * arithmetic tricks the author doesn't understand either.
- */
-{
-	object_t *op2;
-	struct part_entry *pe= op->entry;
-	int mul, delta;
-	unsigned level= 1;
-	unsigned long surplus;
-	int radix= op->type == O_TYPHEX ? 0x10 : 10;
-	unsigned long t;
-
-	if (device < 0 && op->type != O_DEV) return;
-
-	switch (ev) {
-	case '-':
-		mul= radix; delta= -1; typing= 0;
-		break;
-	case '+':
-		mul= radix; delta= 1; typing= 0;
-		break;
-	case '\b':
-		if (!typing) return;
-		mul= 1; delta= 0;
-		break;
-	case '\r':
-		typing= 0;
-		return;
-	default:
-		if ('0' <= ev && ev <= '9')
-			delta= ev - '0';
-		else
-		if (radix == 0x10 && 'a' <= ev && ev <= 'f')
-			delta= ev - 'a' + 10;
-		else
-		if (radix == 0x10 && 'A' <= ev && ev <= 'F')
-			delta= ev - 'A' + 10;
-		else
-			return;
-
-		mul= typing ? radix*radix : 0;
-		typing= 1;
-	}
-	magic= 0;
-
-	if (!check_existing(pe)) return;
-
-	switch (op->type) {
-	case O_DEV:
-		if (ev != '-' && ev != '+') return;
-		if (!nextdevice(op, delta)) return;
-		break;
-	case O_CYL:
-		if (!within(&cylinders, 1,
-			cylinders * mul / radix + delta, 1024)) return;
-		recompute0();
-		break;
-	case O_HEAD:
-		if (!within(&heads, 1, heads * mul / radix + delta, 255))
-			return;
-		recompute0();
-		break;
-	case O_SEC:
-		if (!within(&sectors, 1, sectors * mul / radix + delta, 63))
-			return;
-		recompute0();
-		break;
-	case O_NUM:
-		if (ev != '-' && ev != '+') return;
-		for (op2= world; op2 != nil; op2= op2->next) {
-			if (op2->type == O_NUM && ev == '+')
-				op2->entry->bootind= 0;
-		}
-		op->entry->bootind= ev == '+' ? ACTIVE_FLAG : 0;
-		break;
-	case O_TYPHEX:
-		check_ind(pe);
-		pe->sysind= pe->sysind * mul / radix + delta;
-		break;
-	case O_TYPTXT:
-		if (ev != '-' && ev != '+') return;
-		check_ind(pe);
-		pe->sysind= round_sysind(pe->sysind, delta);
-		break;
-	case O_SCYL:
-		level= heads;
-	case O_SHEAD:
-		level*= sectors;
-	case O_SSEC:
-		if (op->type != O_SCYL && ev != '-' && ev != '+') return;
-	case O_BASE:
-		if (pe->sysind == NO_PART) memset(pe, 0, sizeof(*pe));
-		t= pe->lowsec;
-		surplus= t % level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		if (howend == LAST || op->type != O_BASE)
-			pe->size-= t - pe->lowsec;
-		pe->lowsec= t;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	case O_LCYL:
-		level= heads;
-	case O_LHEAD:
-		level*= sectors;
-	case O_LSEC:
-		if (op->type != O_LCYL && ev != '-' && ev != '+') return;
-
-		if (pe->sysind == NO_PART) memset(pe, 0, sizeof(*pe));
-		t= pe->lowsec + pe->size - 1 + level;
-		surplus= t % level - mul / radix * level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		pe->size= t - pe->lowsec + 1;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	case O_KB:
-		level= 2;
-		if (mul == 0) pe->size= 0;	/* new value, no surplus */
-	case O_SIZE:
-		if (pe->sysind == NO_PART) {
-			if (op->type == O_KB || howend == SIZE) {
-				/* First let loose magic to set the base. */
-				event('m', op);
-				magic= 0;
-				pe->size= 0;
-				event(ev, op);
-				return;
-			}
-			memset(pe, 0, sizeof(*pe));
-		}
-		t= (op->type == O_KB || howend == SIZE) ? pe->size
-						: pe->lowsec + pe->size - 1;
-		surplus= t % level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		pe->size= (op->type == O_KB || howend == SIZE) ? t :
-							t - pe->lowsec + 1;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	default:
-		return;
-	}
-
-	/* The order among the entries may have changed. */
-	sort();
-	dirty= 1;
-}
-
-unsigned long spell[3 + 4 * (1+NR_PARTITIONS)];
-int nspells;
-objtype_t touching;
-
-void newspell(unsigned long charm)
-/* Add a new spell, descending order for the base, ascending for the size. */
-{
-	int i, j;
-
-	if (charm - table[0].lowsec > table[0].size) return;
-
-	for (i= 0; i < nspells; i++) {
-		if (charm == spell[i]) return;	/* duplicate */
-
-		if (touching == O_BASE) {
-			if (charm == table[0].lowsec + table[0].size) return;
-			if ((spell[0] - charm) < (spell[0] - spell[i])) break;
-		} else {
-			if (charm == table[0].lowsec) return;
-			if ((charm - spell[0]) < (spell[i] - spell[0])) break;
-		}
-	}
-	for (j= ++nspells; j > i; j--) spell[j]= spell[j-1];
-	spell[i]= charm;
-}
-
-void m_magic(int ev, object_t *op)
-/* Apply magic onto a base or size number. */
-{
-	struct part_entry *pe= op->entry, *pe2;
-	int rough= (offset != 0 && extbase == 0);
-
-	if (ev != 'm' || device < 0) return;
-	typing= 0;
-
-	if (!check_existing(pe)) return;
-
-	if (magic == 0) {
-		/* See what magic we can let loose on this value. */
-		nspells= 1;
-
-		/* First spell, the current value. */
-		switch (op->type) {
-		case O_SCYL:
-		case O_SHEAD:	/* Start of partition. */
-		case O_SSEC:
-		case O_BASE:
-			touching= O_BASE;
-			spell[0]= pe->lowsec;
-			break;
-		case O_LCYL:
-		case O_LHEAD:
-		case O_LSEC:	/* End of partition. */
-		case O_KB:
-		case O_SIZE:
-			touching= O_SIZE;
-			spell[0]= pe->lowsec + pe->size;
-			break;
-		default:
-			return;
-		}
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-			check_ind(pe);
-			pe->sysind= MINIX_PART;
-			spell[0]= 0;
-			if (touching == O_SIZE) {
-				/* First let loose magic on the base. */
-				object_t *op2;
-
-				for (op2= world; op2 != nil; op2= op2->next) {
-					if (op2->row == op->row &&
-							op2->type == O_BASE) {
-						event('m', op2);
-					}
-				}
-				magic= 0;
-				event('m', op);
-				return;
-			}
-		}
-		/* Avoid the first sector on the device. */
-		if (spell[0] == table[0].lowsec) newspell(spell[0] + 1);
-
-		/* Further interesting values are the the bases of other
-		 * partitions or their ends.
-		 */
-		for (pe2= table; pe2 < table + 1 + NR_PARTITIONS; pe2++) {
-			if (pe2 == pe || pe2->sysind == NO_PART) continue;
-			if (pe2->lowsec == table[0].lowsec)
-				newspell(table[0].lowsec + 1);
-			else
-				newspell(pe2->lowsec);
-			newspell(pe2->lowsec + pe2->size);
-			if (touching == O_BASE && howend == SIZE) {
-				newspell(pe2->lowsec - pe->size);
-				newspell(pe2->lowsec + pe2->size - pe->size);
-			}
-			if (pe2->lowsec % sectors != 0) rough= 1;
-		}
-		/* Present values rounded up to the next cylinder unless
-		 * the table is already a mess.  Use "start + 1 track" instead
-		 * of "start + 1 cylinder".  Also add the end of the last
-		 * cylinder.
-		 */
-		if (!rough) {
-			unsigned long n= spell[0];
-			if (n == table[0].lowsec) n++;
-			n= (n + sectors - 1) / sectors * sectors;
-			if (n != table[0].lowsec + sectors)
-				n= (n + secpcyl - 1) / secpcyl * secpcyl;
-			newspell(n);
-			if (touching == O_SIZE)
-				newspell(table[0].size / secpcyl * secpcyl);
-		}
-	}
-	/* Magic has been applied, a spell needs to be chosen. */
-
-	if (++magic == nspells) magic= 0;
-
-	if (touching == O_BASE) {
-		if (howend == LAST) pe->size-= spell[magic] - pe->lowsec;
-		pe->lowsec= spell[magic];
-	} else
-		pe->size= spell[magic] - pe->lowsec;
-
-	/* The order among the entries may have changed. */
-	sort();
-	dirty= 1;
-}
-
-typedef struct diving {
-	struct diving	*up;
-	struct part_entry  old0;
-	char		*oldsubname;
-	parttype_t	oldparttype;
-	unsigned long	oldoffset;
-	unsigned long	oldextbase;
-} diving_t;
-
-diving_t *diving= nil;
-
-void m_in(int ev, object_t *op)
-/* Go down into a primary or extended partition. */
-{
-	diving_t *newdiv;
-	struct part_entry *pe= op->entry, ext;
-	int n;
-
-	if (ev != '>' || device < 0 || pe == nil || pe == &table[0]
-		|| (!(pe->sysind == MINIX_PART && offset == 0)
-					&& !ext_part(pe->sysind))
-		|| pe->size == 0) return;
-
-	ext= *pe;
-	if (extbase != 0) ext.size= extbase + extsize - ext.lowsec;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return;
-	if (device >= 0) { close(device); device= -1; }
-
-	newdiv= alloc(sizeof(*newdiv));
-	newdiv->old0= table[0];
-	newdiv->oldsubname= curdev->subname;
-	newdiv->oldparttype= curdev->parttype;
-	newdiv->oldoffset= offset;
-	newdiv->oldextbase= extbase;
-	newdiv->up= diving;
-	diving= newdiv;
-
-	table[0]= ext;
-
-	n= strlen(diving->oldsubname);
-	curdev->subname= alloc((n + 3) * sizeof(curdev->subname[0]));
-	strcpy(curdev->subname, diving->oldsubname);
-	curdev->subname[n++]= ':';
-	curdev->subname[n++]= '0' + (pe - table - 1);
-	curdev->subname[n]= 0;
-
-	curdev->parttype= curdev->parttype == PRIMARY ? SUBPART : DUNNO;
-	offset= ext.lowsec;
-	if (ext_part(ext.sysind) && extbase == 0) {
-		extbase= ext.lowsec;
-		extsize= ext.size;
-		curdev->parttype= DUNNO;
-	}
-
-	submerged= 1;
-	event('r', op);
-}
-
-void m_out(int ev, object_t *op)
-/* Go up from an extended or subpartition table to its enclosing. */
-{
-	diving_t *olddiv;
-
-	if (ev != '<' || diving == nil) return;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return;
-	if (device >= 0) { close(device); device= -1; }
-
-	olddiv= diving;
-	diving= olddiv->up;
-
-	table[0]= olddiv->old0;
-
-	free(curdev->subname);
-	curdev->subname= olddiv->oldsubname;
-
-	curdev->parttype= olddiv->oldparttype;
-	offset= olddiv->oldoffset;
-	extbase= olddiv->oldextbase;
-
-	free(olddiv);
-
-	event('r', op);
-	if (diving == nil) submerged= 0;	/* We surfaced. */
-}
-
-void installboot(unsigned char *bootblock, char *masterboot)
-/* Install code from a master bootstrap into a boot block. */
-{
-	FILE *mfp;
-	struct exec hdr;
-	int n;
-	char *err;
-
-	if ((mfp= fopen(masterboot, "r")) == nil) {
-		err= strerror(errno);
-		goto m_err;
-	}
-
-	n= fread(&hdr, sizeof(char), A_MINHDR, mfp);
-	if (ferror(mfp)) {
-		err= strerror(errno);
-		fclose(mfp);
-		goto m_err;
-	}
-
-	if (n < A_MINHDR || BADMAG(hdr) || hdr.a_cpu != A_I8086) {
-		err= "Not an 8086 executable";
-		fclose(mfp);
-		goto m_err;
-	}
-
-	if (hdr.a_text + hdr.a_data > PART_TABLE_OFF) {
-		err= "Does not fit in a boot sector";
-		fclose(mfp);
-		goto m_err;
-	}
-
-	fseek(mfp, hdr.a_hdrlen, 0);
-	fread(bootblock, sizeof(char), (size_t) (hdr.a_text + hdr.a_data), mfp);
-	if (ferror(mfp)) {
-		err= strerror(errno);
-		fclose(mfp);
-		goto m_err;
-	}
-	fclose(mfp);
-
-	/* Bootstrap installed. */
-	return;
-
-    m_err:
-	stat_start(1);
-	printf("%s: %s", masterboot, err);
-	stat_end(5);
-}
-
-ssize_t boot_readwrite(int rw)
-/* Read (0) or write (1) the boot sector. */
-{
-	u64_t off64 = mul64u(offset, SECTOR_SIZE);
-	int r;
-
-#if __minix_vmd
-	/* Minix-vmd has a 64 bit seek. */
-	if (fcntl(device, F_SEEK, off64) < 0) return -1;
-#else
-	/* Minix has to gross things with the partition base. */
-	struct partition geom0, geom_seek;
-
-	if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) {
-		/* Move partition base. */
-		if (ioctl(device, DIOCGETP, &geom0) < 0) return -1;
-		geom_seek.base = add64(geom0.base, off64);
-		geom_seek.size = cvu64(cmp64(add64u(off64, SECTOR_SIZE),
-			geom0.size) <= 0 ? _STATIC_BLOCK_SIZE : 0);
-		sync();
-		if (ioctl(device, DIOCSETP, &geom_seek) < 0) return -1;
-		if (lseek(device, (off_t) 0, SEEK_SET) == -1) return -1;
-	} else {
-		/* Can reach this point normally. */
-		if (lseek(device, (off_t) offset * SECTOR_SIZE, SEEK_SET) == -1)
-			return -1;
-	}
-#endif
-
-	switch (rw) {
-	case 0:	r= read(device, bootblock, SECTOR_SIZE);	break;
-	case 1:	r= write(device, bootblock, SECTOR_SIZE);	break;
-	}
-
-#if !__minix_vmd
-	if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) {
-		/* Restore partition base and size. */
-		sync();
-		if (ioctl(device, DIOCSETP, &geom0) < 0) return -1;
-	}
-#endif
-	return r;
-}
-
-void m_read(int ev, object_t *op)
-/* Read the partition table from the current device. */
-{
-	int i, mode, n;
-	struct part_entry *pe;
-
-	if (ev != 'r' || device >= 0) return;
-
-	/* Open() may cause kernel messages: */
-	stat_start(0);
-	fflush(stdout);
-
-	if (((device= open(curdev->name, mode= O_RDWR, 0666)) < 0
-		&& (errno != EACCES
-			|| (device= open(curdev->name, mode= O_RDONLY)) < 0))
-	) {
-		stat_start(1);
-		printf("%s: %s", curdev->name, strerror(errno));
-		stat_end(5);
-		if (device >= 0) { close(device); device= -1; }
-		return;
-	}
-
-	/* Assume up to five lines of kernel messages. */
-	statusrow+= 5-1;
-	stat_end(5);
-
-	if (mode == O_RDONLY) {
-		stat_start(1);
-		printf("%s: Readonly", curdev->name);
-		stat_end(5);
-	}
-	memset(bootblock, 0, sizeof(bootblock));
-
-	n= boot_readwrite(0);
-
-	if (n <= 0) stat_start(1);
-	if (n < 0) {
-		printf("%s: %s", curdev->name, strerror(errno));
-		close(device);
-		device= -1;
-	} else
-	if (n < SECTOR_SIZE) printf("%s: Unexpected EOF", curdev->subname);
-	if (n <= 0) stat_end(5);
-
-	if (n < SECTOR_SIZE) n= SECTOR_SIZE;
-
-	memcpy(table+1, bootblock+PART_TABLE_OFF,
-					NR_PARTITIONS * sizeof(table[1]));
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		if ((table[i].bootind & ~ACTIVE_FLAG) != 0) break;
-	}
-	if (i <= NR_PARTITIONS || bootblock[510] != 0x55
-				|| bootblock[511] != 0xAA) {
-		/* Invalid boot block, install bootstrap, wipe partition table.
-		 */
-		memset(bootblock, 0, sizeof(bootblock));
-		installboot(bootblock, MASTERBOOT);
-		memset(table+1, 0, NR_PARTITIONS * sizeof(table[1]));
-		stat_start(1);
-		printf("%s: Invalid partition table (reset)", curdev->subname);
-		stat_end(5);
-	}
-
-	/* Fix an extended partition table up to something mere mortals can
-	 * understand.  Record already defined partitions.
-	 */
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		pe= &table[i];
-		if (extbase != 0 && pe->sysind != NO_PART)
-			pe->lowsec+= ext_part(pe->sysind) ? extbase : offset;
-		existing[i]= pe->sysind != NO_PART;
-	}
-	geometry();
-	dirty= 0;
-
-	/* Warn about grave dangers ahead. */
-	if (extbase != 0) {
-		stat_start(1);
-		printf("Warning: You are in an extended partition.");
-		stat_end(5);
-	}
-}
-
-void m_write(int ev, object_t *op)
-/* Write the partition table back if modified. */
-{
-	int c;
-	struct part_entry new_table[NR_PARTITIONS], *pe;
-
-	if (ev != 'w' && ev != E_WRITE) return;
-	if (device < 0) { dirty= 0; return; }
-	if (!dirty) {
-		if (ev == 'w') {
-			stat_start(1);
-			printf("%s is not changed, or has already been written",
-							curdev->subname);
-			stat_end(2);
-		}
-		return;
-	}
-
-	if (bootblock[510] != 0x55 || bootblock[511] != 0xAA) {
-		/* Invalid boot block, warn user. */
-		stat_start(1);
-		printf("Warning: About to write a new table on %s",
-							curdev->subname);
-		stat_end(5);
-	}
-	if (extbase != 0) {
-		/* Will this stop the luser?  Probably not... */
-		stat_start(1);
-		printf("You have changed an extended partition.  Bad Idea.");
-		stat_end(5);
-	}
-	stat_start(1);
-	putstr("Save partition table? (y/n) ");
-	fflush(stdout);
-
-	while ((c= getchar()) != 'y' && c != 'n' && c != ctrl('?')) {}
-
-	if (c == ctrl('?')) putstr("DEL"); else putchr(c);
-	stat_end(5);
-	if (c == 'n' && ev == E_WRITE) dirty= 0;
-	if (c != 'y') return;
-
-	memcpy(new_table, table+1, NR_PARTITIONS * sizeof(table[1]));
-	for (pe= new_table; pe < new_table + NR_PARTITIONS; pe++) {
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-		} else {
-			abs2dos(&pe->start_head, pe->lowsec);
-			abs2dos(&pe->last_head, pe->lowsec + pe->size - 1);
-
-			/* Fear and loathing time: */
-			if (extbase != 0)
-				pe->lowsec-= ext_part(pe->sysind)
-						? extbase : offset;
-		}
-	}
-	memcpy(bootblock+PART_TABLE_OFF, new_table, sizeof(new_table));
-	bootblock[510]= 0x55;
-	bootblock[511]= 0xAA;
-
-	if (boot_readwrite(1) < 0) {
-		stat_start(1);
-		printf("%s: %s", curdev->name, strerror(errno));
-		stat_end(5);
-		return;
-	}
-	dirty= 0;
-}
-
-void m_shell(int ev, object_t *op)
-/* Shell escape, to do calculations for instance. */
-{
-	int r, pid, status;
-	void (*sigint)(int), (*sigquit)(int), (*sigterm)(int);
-
-	if (ev != 's') return;
-
-	reset_tty();
-	fflush(stdout);
-
-	switch (pid= fork()) {
-	case -1:
-		stat_start(1);
-		printf("can't fork: %s\n", strerror(errno));
-		stat_end(3);
-		break;
-	case 0:
-		if (device >= 0) (void) close(device);
-		execl("/bin/sh", "sh", (char *) nil);
-		r= errno;
-		stat_start(1);
-		printf("/bin/sh: %s\n", strerror(errno));
-		stat_end(3);
-		exit(127);
-	}
-	sigint= signal(SIGINT, SIG_IGN);
-	sigquit= signal(SIGQUIT, SIG_IGN);
-	sigterm= signal(SIGTERM, SIG_IGN);
-	while (pid >= 0 && (r= wait(&status)) >= 0 && r != pid) {}
-	(void) signal(SIGINT, sigint);
-	(void) signal(SIGQUIT, sigquit);
-	(void) signal(SIGTERM, sigterm);
-	tty_raw();
-	if (pid < 0)
-		;
-	else
-	if (WIFEXITED(status) && WEXITSTATUS(status) == 127)
-		stat_start(0);	/* Match the stat_start in the child. */
-	else
-		event(ctrl('L'), op);
-}
-
-void m_dump(int ev, object_t *op)
-/* Raw dump of the partition table. */
-{
-	struct part_entry table[NR_PARTITIONS], *pe;
-	int i;
-	unsigned chs[3];
-
-	if (ev != 'p' || device < 0) return;
-
-	memcpy(table, bootblock+PART_TABLE_OFF,
-					NR_PARTITIONS * sizeof(table[0]));
-	for (i= 0; i < NR_PARTITIONS; i++) {
-		pe= &table[i];
-		stat_start(0);
-		dos2chs(&pe->start_head, chs);
-		printf("%2d%c      %02X%15d%5d%4d",
-			i+1,
-			pe->bootind & ACTIVE_FLAG ? '*' : ' ',
-			pe->sysind,
-			chs[0], chs[1], chs[2]);
-		dos2chs(&pe->last_head, chs);
-		printf("%6d%5d%4d%10lu%10ld%9lu",
-			chs[0], chs[1], chs[2],
-			pe->lowsec,
-			howend == SIZE ? pe->size : pe->size + pe->lowsec - 1,
-			pe->size / 2);
-		stat_end(10);
-	}
-	stat_start(0);
-	printf("(Raw dump of the original %.40s table)",
-		curdev->subname);
-	stat_end(10);
-}
-
-int quitting= 0;
-
-void m_quit(int ev, object_t *op)
-/* Write the partition table if modified and exit. */
-{
-	if (ev != 'q' && ev != 'x') return;
-
-	quitting= 1;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) quitting= 0;
-}
-
-void m_help(int ev, object_t *op)
-/* For people without a clue; let's hope they can find the '?' key. */
-{
-	static struct help {
-		char	*keys;
-		char	*what;
-	} help[]= {
-	 { "? !",		 "This help / more advice!" },
-	 { "+ - (= _ PgUp PgDn)","Select/increment/decrement/make active" },
-	 { "0-9 (a-f)",		 "Enter value" },
-	 { "hjkl (arrow keys)",	 "Move around" },
-	 { "CTRL-K CTRL-J",	 "Move entry up/down" },
-	 { "CTRL-L",		 "Redraw screen" },
-	 { ">",			 "Start a subpartition table" },
-	 { "<",			 "Back to the primary partition table" },
-	 { "m",			 "Cycle through magic values" },
-	 { "spacebar",		 "Show \"Size\" or \"Last\"" },
-	 { "r w",		 "Read/write partition table" },
-	 { "p s q x",		 "Raw dump / Shell escape / Quit / Exit" },
-	 { "y n DEL",		 "Answer \"yes\", \"no\", \"cancel\"" },
-	};
-	static char *advice[] = {
-"* Choose a disk with '+' and '-', then hit 'r'.",
-"* To change any value: Move to it and use '+', '-' or type the desired value.",
-"* To make a new partition:  Move over to the Size or Kb field of an unused",
-"  partition and type the size.  Hit the 'm' key to pad the partition out to",
-"  a cylinder boundary.  Hit 'm' again to pad it out to the end of the disk.",
-"  You can hit 'm' more than once on a base or size field to see several",
-"  interesting values go by.  Note: Other Operating Systems can be picky about",
-"  partitions that are not padded to cylinder boundaries.  Look for highlighted",
-"  head or sector numbers.",
-"* To reuse a partition:  Change the type to MINIX.",
-"* To delete a partition:  Type a zero in the hex Type field.",
-"* To make a partition active:  Type '+' in the Num field.",
-"* To study the list of keys:  Type '?'.",
-	};
-
-	if (ev == '?') {
-		struct help *hp;
-
-		for (hp= help; hp < arraylimit(help); hp++) {
-			stat_start(0);
-			printf("%-25s - %s", hp->keys, hp->what);
-			stat_end(0);
-		}
-		stat_start(0);
-		putstr("Things like ");
-		putstr(t_so); putstr("this"); putstr(t_se);
-		putstr(" must be checked, but ");
-		putstr(t_md); putstr("this"); putstr(t_me);
-		putstr(" is not really a problem");
-		stat_end(0);
-	} else
-	if (ev == '!') {
-		char **ap;
-
-		for (ap= advice; ap < arraylimit(advice); ap++) {
-			stat_start(0);
-			putstr(*ap);
-			stat_end(0);
-		}
-	}
-}
-
-void event(int ev, object_t *op)
-/* Simply call all modifiers for an event, each one knows when to act. */
-{
-	m_help(ev, op);
-	m_redraw(ev, op);
-	m_toggle(ev, op);
-	m_orientation(ev, op);
-	m_move(ev, op);
-	m_updown(ev, op);
-	m_enter(ev, op);
-	m_leave(ev, op);
-	m_modify(ev, op);
-	m_magic(ev, op);
-	m_in(ev, op);
-	m_out(ev, op);
-	m_read(ev, op);
-	m_write(ev, op);
-	m_shell(ev, op);
-	m_dump(ev, op);
-	m_quit(ev, op);
-}
-
-int keypress(void)
-/* Get a single keypress.  Translate compound keypresses (arrow keys) to
- * their simpler equivalents.
- */
-{
-	char ch;
-	int c;
-	int esc= 0;
-
-	set_cursor(curobj->row, curobj->col);
-	fflush(stdout);
-
-	do {
-		if (read(0, &ch, sizeof(ch)) < 0) fatal("stdin");
-		c= (unsigned char) ch;
-		switch (esc) {
-		case 0:
-			switch (c) {
-			case ctrl('['):	esc= 1; break;
-			case '_':	c= '-'; break;
-			case '=':	c= '+'; break;
-			}
-			break;
-		case 1:
-			esc= c == '[' ? 2 : 0;
-			break;
-		case 2:
-			switch (c) {
-			case 'D':	c= 'h';	break;
-			case 'B':	c= 'j';	break;
-			case 'A':	c= 'k';	break;
-			case 'C':	c= 'l';	break;
-			case 'H':	c= 'H';	break;
-			case 'U':
-			case 'S':	c= '-';	break;
-			case 'V':
-			case 'T':	c= '+';	break;
-			}
-			/*FALL THROUGH*/
-		default:
-			esc= 0;
-		}
-	} while (esc > 0);
-
-	switch (c) {
-	case ctrl('B'):	c= 'h';	break;
-	case ctrl('N'):	c= 'j';	break;
-	case ctrl('P'):	c= 'k';	break;
-	case ctrl('F'):	c= 'l';	break;
-	}
-
-	return c;
-}
-
-void mainloop(void)
-/* Get keypress, handle event, display results, reset screen, ad infinitum. */
-{
-	int key;
-
-	while (!quitting) {
-		stat_reset();
-
-		key= keypress();
-
-		event(key, curobj);
-
-		display();
-	}
-}
-
-int main(int argc, char **argv)
-{
-	object_t *op;
-	int i, r, key;
-	struct part_entry *pe;
-
-	/* Define a few objects to show on the screen.  First text: */
-	op= newobject(O_INFO, 0, 0,  2, 19);
-	op= newobject(O_TEXT, 0, 0, 22, 13); op->text= "----first----";
-	op= newobject(O_TEXT, 0, 0, 37, 13); op->text= "--geom/last--";
-	op= newobject(O_TEXT, 0, 0, 52, 18); op->text= "------sectors-----";
-	op= newobject(O_TEXT, 0, 1,  4,  6); op->text= "Device";
-	op= newobject(O_TEXT, 0, 1, 23, 12); op->text= "Cyl Head Sec";
-	op= newobject(O_TEXT, 0, 1, 38, 12); op->text= "Cyl Head Sec";
-	op= newobject(O_TEXT, 0, 1, 56,  4); op->text= "Base";
-	op= newobject(O_TEXT, 0, 1, 66,  4); op->text= size_last;
-	op= newobject(O_TEXT, 0, 1, 78,  2); op->text= "Kb";
-	op= newobject(O_TEXT, 0, 4,  0, 15); op->text= "Num Sort   Type";
-
-	/* The device is the current object: */
-    curobj= newobject(O_DEV,  OF_MOD, 2,  4, 15);
-	op= newobject(O_SUB,       0, 3,  4, 15);
-
-	/* Geometry: */
-	op= newobject(O_CYL,  OF_MOD, 2, 40,  5); op->entry= &table[0];
-	op= newobject(O_HEAD, OF_MOD, 2, 45,  3); op->entry= &table[0];
-	op= newobject(O_SEC,  OF_MOD, 2, 49,  2); op->entry= &table[0];
-
-	/* Objects for the device: */
-	op= newobject(O_SCYL,  0, 3, 25,  5); op->entry= &table[0];
-	op= newobject(O_SHEAD, 0, 3, 30,  3); op->entry= &table[0];
-	op= newobject(O_SSEC,  0, 3, 34,  2); op->entry= &table[0];
-	op= newobject(O_LCYL,  0, 3, 40,  5); op->entry= &table[0];
-	op= newobject(O_LHEAD, 0, 3, 45,  3); op->entry= &table[0];
-	op= newobject(O_LSEC,  0, 3, 49,  2); op->entry= &table[0];
-	op= newobject(O_BASE,  0, 3, 59,  9); op->entry= &table[0];
-	op= newobject(O_SIZE,  0, 3, 69,  9); op->entry= &table[0];
-	op= newobject(O_KB,    0, 3, 79,  9); op->entry= &table[0];
-
-	/* Objects for each partition: */
-	for (r= 5, pe= table+1; pe <= table+NR_PARTITIONS; r++, pe++) {
-		op= newobject(O_NUM,    OF_MOD, r,  1,  2); op->entry= pe;
-		op= newobject(O_SORT,        0, r,  5,  2); op->entry= pe;
-		op= newobject(O_TYPHEX, OF_MOD, r, 10,  2); op->entry= pe;
-		op= newobject(O_TYPTXT, OF_MOD, r, 12,  9); op->entry= pe;
-		op= newobject(O_SCYL,   OF_MOD, r, 25,  5); op->entry= pe;
-		op= newobject(O_SHEAD,  OF_MOD, r, 30,  3); op->entry= pe;
-		op= newobject(O_SSEC,   OF_MOD, r, 34,  2); op->entry= pe;
-		op= newobject(O_LCYL,   OF_MOD, r, 40,  5); op->entry= pe;
-		op= newobject(O_LHEAD,  OF_MOD, r, 45,  3); op->entry= pe;
-		op= newobject(O_LSEC,   OF_MOD, r, 49,  2); op->entry= pe;
-		op= newobject(O_BASE,   OF_MOD, r, 59,  9); op->entry= pe;
-		op= newobject(O_SIZE,   OF_MOD, r, 69,  9); op->entry= pe;
-		op= newobject(O_KB,     OF_MOD, r, 79,  9); op->entry= pe;
-	}
-
-	for (i= 1; i < argc; i++) newdevice(argv[i], 0);
-
-	if (firstdev == nil) {
-		getdevices();
-		key= ctrl('L');
-	} else {
-		key= 'r';
-	}
-
-	if (firstdev != nil) {
-		init_tty();
-		clear_screen();
-		event(key, curobj);
-		display();
-		mainloop();
-		reset_tty();
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/partition.c
===================================================================
--- trunk/minix/commands/ibm/partition.c	(revision 9)
+++ 	(revision )
@@ -1,437 +1,0 @@
-/*	partition 1.13 - Make a partition table		Author: Kees J. Bot
- *								27 Apr 1992
- */
-#define nil ((void*)0)
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <limits.h>
-
-#define SECTOR_SIZE	512
-
-#define arraysize(a)	(sizeof(a)/sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-char *arg0;
-
-void report(const char *label)
-{
-	fprintf(stderr, "%s: %s: %s\n", arg0, label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-#ifndef makedev
-#define minor(dev)	(((dev) >> MINOR) & BYTE)
-#define major(dev)	(((dev) >> MAJOR) & BYTE)
-#define makedev(major, minor)	\
-			((dev_t) (((major) << MAJOR) | ((minor) << MINOR)))
-#endif
-
-int aflag;			/* Add a new partition to the current table. */
-int mflag;			/* Minix rules, no need for alignment. */
-int rflag;			/* Report current partitions. */
-int fflag;			/* Force making a table even if too small. */
-int nflag;			/* Play-act, don't really do it. */
-
-int cylinders, heads, sectors;	/* Device's geometry */
-int pad;			/* Partitions must be padded. */
-
-/* Descriptions of the device to divide and the partitions to make, including
- * gaps between partitions.
- */
-char *device;
-struct part_entry primary, table[2 * NR_PARTITIONS + 1];
-int npart;
-
-/* Extra flags at construction time. */
-#define EXPAND_FLAG	0x01	/* Add the remaining sectors to this one */
-#define EXIST_FLAG	0x02	/* Use existing partition */
-
-void find_exist(struct part_entry *exist, int sysind, int nr)
-{
-	int f;
-	u16_t signature;
-	struct part_entry oldtable[NR_PARTITIONS];
-	int n, i;
-	u32_t minlow, curlow;
-	struct part_entry *cur;
-	char *nr_s[] = { "", "second ", "third ", "fourth" };
-
-	if ((f= open(device, O_RDONLY)) < 0
-
-		|| lseek(f, (off_t) PART_TABLE_OFF, SEEK_SET) == -1
-
-		|| read(f, oldtable, sizeof(oldtable)) < 0
-
-		|| read(f, &signature, sizeof(signature)) < 0
-
-		|| close(f) < 0
-	) fatal(device);
-
-	minlow= 0;
-	n= 0;
-	for (;;) {
-		curlow= -1;
-		cur= nil;
-		for (i= 0; i < NR_PARTITIONS; i++) {
-			if (signature == 0xAA55
-				&& oldtable[i].sysind != NO_PART
-				&& oldtable[i].lowsec >= minlow
-				&& oldtable[i].lowsec < curlow
-			) {
-				cur= &oldtable[i];
-				curlow= oldtable[i].lowsec;
-			}
-		}
-		if (n == nr) break;
-		n++;
-		minlow= curlow+1;
-	}
-
-	if (cur == nil || cur->sysind != sysind) {
-		fprintf(stderr,
-		"%s: Can't find a %sexisting partition of type 0x%02X\n",
-			arg0, nr_s[nr], sysind);
-		exit(1);
-	}
-	*exist = *cur;
-}
-
-void write_table(void)
-{
-	int f;
-	u16_t signature= 0xAA55;
-	struct part_entry newtable[NR_PARTITIONS];
-	int i;
-
-	if (nflag) {
-		printf("(Table not written)\n");
-		return;
-	}
-
-	for (i= 0; i < NR_PARTITIONS; i++) newtable[i]= table[1 + 2*i];
-
-	if ((f= open(device, O_WRONLY)) < 0
-
-		|| lseek(f, (off_t) PART_TABLE_OFF, SEEK_SET) == -1
-
-		|| write(f, newtable, sizeof(newtable)) < 0
-
-		|| write(f, &signature, sizeof(signature)) < 0
-
-		|| close(f) < 0
-	) fatal(device);
-}
-
-void sec2dos(unsigned long sec, unsigned char *dos)
-/* Translate a sector number into the three bytes DOS uses. */
-{
-	unsigned secspcyl= heads * sectors;
-	unsigned cyl;
-
-	cyl= sec / secspcyl;
-	dos[2]= cyl;
-	dos[1]= ((sec % sectors) + 1) | ((cyl >> 2) & 0xC0);
-	dos[0]= (sec % secspcyl) / sectors;
-}
-
-void show_chs(unsigned long pos)
-{
-	int cyl, head, sec;
-
-	if (pos == -1) {
-		cyl= head= 0;
-		sec= -1;
-	} else {
-		cyl= pos / (heads * sectors);
-		head= (pos / sectors) - (cyl * heads);
-		sec= pos % sectors;
-	}
-	printf("  %4d/%03d/%02d", cyl, head, sec);
-}
-
-void show_part(struct part_entry *p)
-{
-	static int banner= 0;
-	int n;
-
-	n= p - table;
-	if ((n % 2) == 0) return;
-
-	if (!banner) {
-		printf(
-	"Part     First         Last         Base      Size       Kb\n");
-		banner= 1;
-	}
-
-	printf("%3d ", (n-1) / 2);
-	show_chs(p->lowsec);
-	show_chs(p->lowsec + p->size - 1);
-	printf("  %8lu  %8lu  %7lu\n", p->lowsec, p->size, p->size / 2);
-}
-
-void usage(void)
-{
-	fprintf(stderr,
-		"Usage: partition [-mfn] device [type:]length[+*] ...\n");
-	exit(1);
-}
-
-#define between(a, c, z)	((unsigned) ((c) - (a)) <= ((z) - (a)))
-
-void parse(char *descr)
-{
-	int seen= 0, sysind, flags, c;
-	unsigned long lowsec, size;
-
-	lowsec= 0;
-
-	if (strchr(descr, ':') == nil) {
-		/* A hole. */
-		if ((npart % 2) != 0) {
-			fprintf(stderr, "%s: Two holes can't be adjacent.\n",
-				arg0);
-			exit(1);
-		}
-		sysind= NO_PART;
-		seen|= 1;
-	} else {
-		/* A partition. */
-		if ((npart % 2) == 0) {
-			/* Need a hole before this partition. */
-			if (npart == 0) {
-				/* First hole contains the partition table. */
-				table[0].size= 1;
-			}
-			npart++;
-		}
-		sysind= 0;
-		for (;;) {
-			c= *descr++;
-			if (between('0', c, '9'))
-				c= (c - '0') + 0x0;
-			else
-			if (between('a', c, 'z'))
-				c= (c - 'a') + 0xa;
-			else
-			if (between('A', c, 'Z'))
-				c= (c - 'A') + 0xA;
-			else
-				break;
-			sysind= 0x10 * sysind + c;
-			seen|= 1;
-		}
-		if (c != ':') usage();
-	}
-
-	flags= 0;
-
-	if (strncmp(descr, "exist", 5) == 0 && (npart % 2) == 1) {
-		struct part_entry exist;
-
-		find_exist(&exist, sysind, (npart - 1) / 2);
-		sysind= exist.sysind;
-		lowsec= exist.lowsec;
-		size= exist.size;
-		flags |= EXIST_FLAG;
-		descr += 5;
-		c= *descr++;
-		seen|= 2;
-	} else {
-		size= 0;
-		while (between('0', (c= *descr++), '9')) {
-			size= 10 * size + (c - '0');
-			seen|= 2;
-		}
-	}
-
-	for (;;) {
-		if (c == '*')
-			flags|= ACTIVE_FLAG;
-		else
-		if (c == '+' && !(flags & EXIST_FLAG))
-			flags|= EXPAND_FLAG;
-		else
-			break;
-		c= *descr++;
-	}
-
-	if (seen != 3 || c != 0) usage();
-
-	if (npart == arraysize(table)) {
-		fprintf(stderr, "%s: too many partitions, only %d possible.\n",
-			arg0, NR_PARTITIONS);
-		exit(1);
-	}
-	table[npart].bootind= flags;
-	table[npart].sysind= sysind;
-	table[npart].lowsec= lowsec;
-	table[npart].size= size;
-	npart++;
-}
-
-void geometry(void)
-/* Get the geometry of the drive the device lives on, and the base and size
- * of the device.
- */
-{
-	int fd;
-	struct partition geometry;
-	struct stat sb;
-
-	if ((fd= open(device, O_RDONLY)) < 0) fatal(device);
-
-	/* Get the geometry of the drive, and the device's base and size. */
-	if (ioctl(fd, DIOCGETP, &geometry) < 0)
-	{
-		/* Use the same fake geometry as part. */
-		if (fstat(fd, &sb) < 0)
-			fatal(device);
-		geometry.base= cvul64(0);
-		geometry.size= cvul64(sb.st_size);
-		geometry.sectors= 32;
-		geometry.heads= 64;
-		geometry.cylinders= (sb.st_size-1)/SECTOR_SIZE/
-			(geometry.sectors*geometry.heads) + 1;
-	}
-	close(fd);
-	primary.lowsec= div64u(geometry.base, SECTOR_SIZE);
-	primary.size= div64u(geometry.size, SECTOR_SIZE);
-	cylinders= geometry.cylinders;
-	heads= geometry.heads;
-	sectors= geometry.sectors;
-
-	/* Is this a primary partition table?  If so then pad partitions. */
-	pad= (!mflag && primary.lowsec == 0);
-}
-
-void boundary(struct part_entry *pe, int exp)
-/* Expand or reduce a primary partition to a track or cylinder boundary to
- * avoid giving the fdisk's of simpler operating systems a fit.
- */
-{
-	unsigned n;
-
-	n= !pad ? 1 : pe == &table[0] ? sectors : heads * sectors;
-	if (exp) pe->size+= n - 1;
-	pe->size= ((pe->lowsec + pe->size) / n * n) - pe->lowsec;
-}
-
-void distribute(void)
-/* Fit the partitions onto the device.  Try to start and end them on a
- * cylinder boundary if so required.  The first partition is to start on
- * track 1, not on cylinder 1.
- */
-{
-	struct part_entry *pe, *exp;
-	long count;
-	unsigned long base, size, oldbase;
-
-	do {
-		exp= nil;
-		base= primary.lowsec;
-		count= primary.size;
-
-		for (pe= table; pe < arraylimit(table); pe++) {
-			oldbase= base;
-			if (pe->bootind & EXIST_FLAG) {
-				if (base > pe->lowsec) {
-					fprintf(stderr,
-	"%s: fixed partition %d is preceded by too big partitions/holes\n",
-						arg0, ((pe - table) - 1) / 2);
-					exit(1);
-				}
-				exp= nil;	/* XXX - Extend before? */
-			} else {
-				pe->lowsec= base;
-				boundary(pe, 1);
-				if (pe->bootind & EXPAND_FLAG) exp= pe;
-			}
-			base= pe->lowsec + pe->size;
-			count-= base - oldbase;
-		}
-		if (count < 0) {
-			if (fflag) break;
-			fprintf(stderr, "%s: %s is %ld sectors too small\n",
-				arg0, device, -count);
-			exit(1);
-		}
-		if (exp != nil) {
-			/* Add leftover space to the partition marked for
-			 * expanding.
-			 */
-			exp->size+= count;
-			boundary(exp, 0);
-			exp->bootind&= ~EXPAND_FLAG;
-		}
-	} while (exp != nil);
-
-	for (pe= table; pe < arraylimit(table); pe++) {
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-		} else {
-			sec2dos(pe->lowsec, &pe->start_head);
-			sec2dos(pe->lowsec + pe->size - 1, &pe->last_head);
-			pe->bootind&= ACTIVE_FLAG;
-		}
-		show_part(pe);
-	}
-}
-
-int main(int argc, char **argv)
-{
-	int i;
-
-	if ((arg0= strrchr(argv[0], '/')) == nil) arg0= argv[0]; else arg0++;
-
-	i= 1;
-	while (i < argc && argv[i][0] == '-') {
-		char *opt= argv[i++] + 1;
-
-		if (opt[0] == '-' && opt[1] == 0) break;
-
-		while (*opt != 0) switch (*opt++) {
-		case 'a':	aflag= 1;	break;
-		case 'm':	mflag= 1;	break;
-		case 'r':	rflag= 1;	break;
-		case 'f':	fflag= 1;	break;
-		case 'n':	nflag= 1;	break;
-		default:	usage();
-		}
-	}
-
-	if (rflag) {
-		if (aflag) usage();
-		if ((argc - i) != 1) usage();
-		fprintf(stderr, "%s: -r is not yet implemented\n");
-		exit(1);
-	} else {
-		if ((argc - i) < 1) usage();
-		if (aflag) fprintf(stderr, "%s: -a is not yet implemented\n");
-
-		device= argv[i++];
-		geometry();
-
-		while (i < argc) parse(argv[i++]);
-
-		distribute();
-		write_table();
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/playwave.c
===================================================================
--- trunk/minix/commands/ibm/playwave.c	(revision 9)
+++ 	(revision )
@@ -1,201 +1,0 @@
-/*   
- *  playwave.c
- *
- *  Play sound files in wave format. Only MicroSoft PCM is supported. 
- *
- *  Michel R. Prevenier.
- */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <minix/sound.h>
-
-_PROTOTYPE( void main, (int argc, char **argv));
-_PROTOTYPE( void usage, (void));
-
-/******* Wave format definitions *********/
-
-#define RIFF_ID		0x46464952
-#define WAVE_ID1	0x45564157
-#define WAVE_ID2	0x20746D66
-#define DATA_ID		0x61746164
-#define MS_PCM_FORMAT	0x0001
-	
-#define WORD	short  
-#define DWORD   unsigned long
-
-struct RIFF_fields
-{
-  DWORD RIFF_id;
-  DWORD RIFF_len;
-  DWORD WAVE_id1;
-  DWORD WAVE_id2;
-  DWORD data_ptr;
-} r_fields; 
-
-struct common_fields
-{
-  WORD  FormatTag;
-  WORD  Channels;
-  DWORD SamplesPerSec;
-  DWORD AvgBytesPerSec;
-  WORD  BlockAlign;
-} c_fields;
-
-struct specific_fields
-{
-  WORD BitsPerSample;
-} s_fields;
-
-DWORD data_id;
-DWORD data_len;
-
-/******** End of wave definitions *********/
-
-
-void usage()
-{
-  fprintf(stderr, "Usage: playwav [-i] file\n");
-  exit(-1);
-}
-
-
-void main ( int argc, char *argv[] )
-{
-  int i, audio, file;
-  char *buffer, *file_name;
-  unsigned int sign;
-  unsigned int fragment_size;
-  unsigned int channels;
-  unsigned int bits;
-  long data_pos;  
-  int showinfo = 0;
-
-  /* Check Parameters */
-  if (argc > 2)
-  {
-    if (strncmp(argv[1], "-i", 2) == 0)
-    {
-      showinfo = 1;
-      file_name = argv[2];
-    }
-    else
-      usage();
-  }
-  else file_name = argv[1];
-
-  /* Open DSP */
-  if ((audio = open("/dev/audio", O_RDWR)) < 0) 
-  {
-    printf("Cannot open /dev/audio\n");
-    exit(-1);
-  }
-
-  /* Get maximum fragment size and try to allocate a buffer */
-  ioctl(audio, DSPIOMAX, &fragment_size);
-  if ((buffer = malloc(fragment_size)) == (char *)0)
-  {
-    fprintf(stderr, "Cannot allocate buffer\n");
-    exit(-1);
-  } 
-  ioctl(audio, DSPIOSIZE, &fragment_size);
-
-  /* Open wav file */
-  if((file = open(file_name, O_RDONLY)) < 0)
-  {
-    printf("Cannot open %s\n", file_name);
-    exit(-1);
-  }
-
-  /* Check for valid wave format */
-  read(file, &r_fields, 20);
-  if(r_fields.RIFF_id != RIFF_ID)
-  {
-      printf("%s not in RIFF format\n", file_name);
-      exit(1);
-  }
-  if(r_fields.WAVE_id1 != WAVE_ID1 || r_fields.WAVE_id2 != WAVE_ID2)
-  {
-      printf("%s not in WAVE format\n", file_name);
-      exit(1);
-  }
-
-  /* Store data_chunk position */
-  data_pos = lseek(file, 0L, 1) + r_fields.data_ptr;
-
-  /* Read the common and specific fields */
-  read(file, &c_fields, 14);
-  read(file, &s_fields, 2);
-
-  /* Check for valid wave format, we can only play MicroSoft PCM */
-  if(c_fields.FormatTag != MS_PCM_FORMAT)
-  {
-    printf("%s not in MicroSoft PCM format\n", file_name);
-    exit(1);
-  }
-
-  /* Set DSP parameters */
-  channels = c_fields.Channels;
-  channels--;
-  bits = s_fields.BitsPerSample;
-  ioctl(audio, DSPIOSTEREO, &channels); 
-  ioctl(audio, DSPIORATE, &c_fields.SamplesPerSec);
-  ioctl(audio, DSPIOBITS, &bits); 
-  sign = (bits == 16 ? 1 : 0);
-  ioctl(audio, DSPIOSIGN, &sign); 
-
-  /* Goto data chunk */
-  lseek(file, data_pos, SEEK_SET);
-
-  /* Check for valid data chunk */
-  read(file, &data_id, sizeof(data_id));
-  if(data_id != DATA_ID)
-  {
-    printf("Invalid data chunk\n");
-    exit(1);
-  }
-
-  /* Get length of data */
-  read(file, &data_len, sizeof(data_len));
-
-  if (showinfo)
-  {
-    printf("\nBits per sample   : %d \n", s_fields.BitsPerSample);
-    printf("Stereo            : %s \n", (c_fields.Channels == 1 ? "yes" : "no"));
-    printf("Samples per second: %ld \n", c_fields.SamplesPerSec); 
-    printf("Average bytes/sec : %ld \n", c_fields.AvgBytesPerSec);
-    printf("Block alignment   : %d \n", c_fields.BlockAlign);
-    printf("Datalength (bytes): %ld \n\n", data_len);
-  }
-    
-  /* Play data */
-  while(data_len > 0)
-  {
-    if (data_len > fragment_size) 
-    {
-      /* Read next fragment */
-      read(file, buffer, fragment_size); 
-      data_len-= fragment_size;
-    }
-    else 
-    { 
-      /* Read until end of file and fill rest of buffer with silence,
-       * in PCM this means: fill buffer with last played value
-       */
-      read(file, buffer, data_len); 
-      for (i = data_len; i< fragment_size; i++) 
-        buffer[i] = buffer[(int)data_len-1];
-      data_len = 0;
-    }
-
-    /* Copy data to DSP */
-    write(audio, buffer,  fragment_size);
-  }
-}
Index: trunk/minix/commands/ibm/postmort.c
===================================================================
--- trunk/minix/commands/ibm/postmort.c	(revision 9)
+++ 	(revision )
@@ -1,656 +1,0 @@
-/* postmort - post mortem dump		Author: C. W. Rose */
-
-/* Postmort: perform post-mortem on PC Minix 1.7 core files.
- *
- */
-
- /* The 1.5 core file structure is a struct mem_map, the segment memory map,
-  * followed by a struct proc, the process table, followed by a dump of the
-  * text, data, and stack segments.
-  * 
-  * This is the 8086/Intel version; 386 and 68K will differ.  It defaults to
-  * using the name 'core' for the core file, and 'a.out' for the symbol file.
-  * If there is no 'a.out', it will try and read the symbol table from
-  * 'symbol.out', then give up.  A non-existant symbol table is not a fatal
-  * error unless the -s option was used.
-  * 
-  * The PC 1.5 kernel dump routines are odd - they dump the memory maps twice,
-  * the second time as part of the kernel process table, and the kernel
-  * process table size must be a multiple of 4.  Should a core file have a
-  * header with a magic number in future?
-  * 
-  * The kernel include file paths need to be edited for each machine. */
-
-#include <sys/types.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include <minix/ipc.h>
-#include <limits.h>
-#include <timers.h>
-#include <signal.h>
-#include <stdlib.h>
-
-#undef EXTERN			/* <minix/const.h> defined this */
-#define EXTERN			/* so we get proc & mproc */
-#include "../../kernel/const.h"
-#include "../../kernel/type.h"
-#include "../../kernel/proc.h"
-#undef printf			/* kernel's const.h defined this */
-#include "../../servers/pm/mproc.h"
-
-#include <a.out.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#undef NULL
-#include <string.h>
-#include <unistd.h>
-
-#define FALSE		0
-#undef TRUE
-#define TRUE		~FALSE
-#define OK		1
-#define FAILED		-1
-
-#define CORE		"core"
-#define AOUT		"a.out"
-#define SYMB		"symbol.out"
-#define LINE_LEN	16
-#define MAXSYM		200
-#define SYMLEN		8
-
-/* Global variables */
-int opt_c = FALSE;		/* name of core file */
-int opt_d = FALSE;		/* dump raw data and stack segments */
-int opt_p = FALSE;		/* dump the kernel process table */
-int opt_s = FALSE;		/* name of symbol file */
-int opt_t = FALSE;		/* trace back the stack */
-int opt_x = FALSE;		/* debugging flag */
-
-char progname[20];		/* program name */
-char *segment_name[] = {	/* array of segment names */
-  "Text",
-  "Data",
-  "Stack"
-};
-
-int dbglvl = 0;			/* debugging level */
-int maxsym;			/* maximum symbol number */
-unsigned int baseptr;		/* reference copy of stack base pointer */
-unsigned int stackptr;		/* reference copy of stack pointer */
-long int lengths[NR_LOCAL_SEGS];	/* segment lengths */
-long int bases[NR_LOCAL_SEGS];	/* segment base addresses */
-
-struct sym {			/* symbol table addresses and labels */
-  unsigned int addr;
-  char label[SYMLEN + 1];
-} symtab[MAXSYM];
-
-/* Used by getopt(3) package */
-extern int optind, opterr, optopt;
-extern char *optarg;
-
-_PROTOTYPE(int binary, (int uc, char *sp));
-_PROTOTYPE(void dump_all_segs, (int fd));
-_PROTOTYPE(void dump_maps, (struct mem_map * mp));
-_PROTOTYPE(void dump_one_seg, (int fd, int segindex));
-_PROTOTYPE(void dump_proc_table, (struct proc * pt));
-_PROTOTYPE(void dump_registers, (struct proc * pt));
-_PROTOTYPE(void dump_sym_tab, (struct sym *st));
-_PROTOTYPE(void dump_stack, (struct stackframe_s * sp));
-_PROTOTYPE(int main, (int argc, char *argv[]));
-_PROTOTYPE(int parse_line, (char *ps));
-_PROTOTYPE(int read_symbol, (int fd));
-_PROTOTYPE(void stack_trace, (int fd));
-_PROTOTYPE(void usage, (void));
-
-
-/* B i n a r y
- *
- * Produce a binary representation of an 8-bit number.
- */
-int binary(ucc, sp)
-int ucc;
-char *sp;
-{
-  int j;
-  unsigned char k, uc;
-
-  uc = (unsigned char) ucc;
-  for (k = 0x80, j = 0; j < 8; j++) {
-	if ((uc & k) == 0)
-		*sp++ = '0';
-	else
-		*sp++ = '1';
-	if (j == 3) *sp++ = '$';
-	k >>= 1;
-  }
-  *sp = '\0';
-
-  return(0);
-}
-
-
-/* D u m p _ a l l _ s e g s
- *
- * Dump all the segments except for text
- */
-void dump_all_segs(fd)
-int fd;
-{
-  int j;
-  long int start;
-
-  start = (long) (NR_LOCAL_SEGS * sizeof(struct mem_map)) + sizeof(struct proc);
-  for (j = 1; j < NR_LOCAL_SEGS; j++) {
-	start += lengths[j - 1];
-	(void) lseek(fd, start, 0);
-	printf("\n");
-	dump_one_seg(fd, j);
-  }
-}
-
-
-/* D u m p _ m a p s
- *
- * Dump the memory maps
- */
-void dump_maps(mp)
-struct mem_map *mp;
-{
-  int j;
-  long int vir, phy, len;
-
-  printf("\t  Virtual\t  Physical\tLength\n");
-  printf("\t  address\t  address\n");
-  for (j = 0; j < NR_LOCAL_SEGS; j++) {
-	vir = (long) mp[j].mem_vir << CLICK_SHIFT;
-	phy = (long) mp[j].mem_phys << CLICK_SHIFT;
-	len = (long) mp[j].mem_len << CLICK_SHIFT;
-	printf("%s:\t0x%08.8lx\t0x%08.8lx\t%8ld (0x%08.8lx)\n",
-	       segment_name[j], vir, phy, len, len);
-	lengths[j] = len;
-	bases[j] = vir;
-  }
-}
-
-
-/* D u m p _ o n e _ s e g
- *
- * Dump a single segment
- */
-void dump_one_seg(fd, segindex)
-int fd, segindex;
-{
-  unsigned char dlen[LINE_LEN];
-  int i, amt, amt_read;
-  long int len, offset;
-
-  printf("%s segment\n\n", segment_name[segindex]);
-  len = lengths[segindex];
-  amt = LINE_LEN;
-  for (offset = 0; offset < len; offset += amt) {
-	if ((len - offset) < LINE_LEN) amt = (int) (len - offset);
-	if (dbglvl > 0)
-		printf("Length %ld, offset %ld, amt %d\n", len, offset, amt);
-	if ((amt_read = read(fd, (char *) dlen, (unsigned int) amt)) == -1) {
-		printf("Unexpected end of file\n");
-		exit(1);
-	}
-	printf("%08.8lx: ", bases[segindex] + offset);
-	for (i = 0; i < amt_read; i++) {
-		if (i == LINE_LEN / 2) printf("- ");
-		printf("%02.2x ", dlen[i]);
-	}
-	printf("  ");
-	for (i = 0; i < amt_read; i++) {
-		if (isprint(dlen[i]))
-			(void) putchar((char) dlen[i]);
-		else
-			(void) putchar('.');
-	}
-	(void) putchar('\n');
-	if (dbglvl > 0 && amt_read != amt)
-		printf("wanted = %d, got = %d, offset = %ld\n",
-		       amt, amt_read, offset);
-  }
-}
-
-
-/* D u m p _ p r o c _ t a b l e
- *
- * Dump the entire kernel proc table
- */
-void dump_proc_table(pt)
-struct proc *pt;
-{
-  printf("Kernel process table entries:\n\n");
-#if 0
-  printf("Process' registers:			0x%04.4x\n", pt->p_reg);	/* struct stackframe_s */
-  printf("Selector in gdt:			0x%04.4x\n", pt->p_ldt_sel);	/* reg_t */
-  printf("Descriptors for code and data:	0x%04.4x\n", pt->p_ldt[2]);	/* struct segdesc_s */
-#endif
-  printf("Number of this process:			0x%04.4x\n", pt->p_nr);	/* int */
-#if 0
-  printf("Nonzero if blocked by busy task:	0x%04.4x\n", pt->p_ntf_blocked);	/* int */
-  printf("Nonzero if held by busy syscall:	0x%04.4x\n", pt->p_ntf_held);	/* int */
-  printf("Next in chain of held-up processes:	0x%04.4x\n", pt->p_ntf_nextheld);	/* struct proc * */
-#endif
-  printf("SENDING, RECEIVING, etc.:		0x%04.4x\n", pt->p_rts_flags);	/* int */
-#if 0
-  printf("Memory map:				0x%04.4x\n", pt->p_map[NR_LOCAL_SEGS]);	/* struct mem_map */
-#endif
-#if DEAD_CODE
-  printf("Process id passed in from MM:		0x%04.4x\n", pt->p_pid);	/* int */
-#endif
-#if 0
-  printf("User time in ticks:			%ld\n", pt->user_time);	/* time_t */
-  printf("Sys time in ticks:			%ld\n", pt->sys_time);	/* time_t */
-  printf("Cumulative user time of children:	%ld\n", pt->child_utime);	/* time_t */
-  printf("Cumulative sys time of children:	%ld\n", pt->child_stime);	/* time_t */
-  printf("Ticks used in current quantum:	%d\n", pt->quantum_time);	/* int */
-  printf("Ticks used in last quantum:		%d\n", pt->quantum_last);	/* int */
-  printf("Current priority of the process:	%d\n", pt->curr_prio);	/* int */
-  printf("Base priority of the process:		%d\n", pt->base_prio);	/* int */
-  printf("Scale for profiling, 0 = none:	%u\n", pt->p_pscale);	/* unsigned */
-  printf("Profiling pc lower boundary:		%d\n", pt->p_plow);	/* vir_bytes */
-  printf("Profiling pc upper boundary:		%d\n", pt->p_phigh);	/* vir_bytes */
-  printf("Profiling buffer:			%d\n", pt->p_pbuf);	/* vir_bytes */
-  printf("Profiling buffer size:		%d\n", pt->p_psiz);	/* vir_bytes */
-#endif
-#if 0
-  printf("First proc wishing to send:		0x%04.4x\n", pt->p_callerq);	/* struct proc * */
-  printf("Link to next proc wishing to send:	0x%04.4x\n", pt->p_sendlink);	/* struct proc * */
-  printf("Pointer to message buffer:		0x%04.4x\n", pt->p_messbuf);	/* message * */
-#endif
-  printf("Expecting message from:			0x%04.4x\n", pt->p_getfrom_e);	/* int */
-#if 0
-  printf("Pointer to next ready process:	0x%04.4x\n", pt->p_nextready);	/* struct proc * */
-#endif
-  printf("Bit map for pending signals 1-16:	0x%04.4x\n", pt->p_pending);	/* int */
-#if 0
-  printf("Count of pending/unfinished signals:	0x%04.4x\n", pt->p_pendcount);	/* unsigned */
-#endif
-}
-
-
-/* D u m p _ r e g i s t e r s
- *
- * Dump the registers from the proc table
- */
-void dump_registers(pt)
-struct proc *pt;
-{
-  char buff[32];
-  unsigned char uc;
-
-  /* Print the registers */
-  dump_stack(&pt->p_reg);
-
-  /* Build up a binary representation of the signal flags */
-  uc = (pt->p_pending >> 8) & 0xff;
-  (void) binary((int) uc, buff);
-  buff[9] = '$';
-  uc = pt->p_pending & 0xff;
-  (void) binary((int) uc, buff + 10);
-  printf("Pending signals = %s\n", buff);
-}
-
-
-/* D u m p _ s y m _ t a b
- *
- * Dump the symbol table
- */
-void dump_sym_tab(st)
-struct sym *st;
-{
-  int j;
-
-  printf("Symbol table entries (text):\n\n");
-  for (j = 0; j < maxsym; j++) 
-	printf("0x%08.8x T %s\n", symtab[j].addr, symtab[j].label);
-}
-
-
-/* D u m p _ s t a c k
- *
- * Dump the stack frame
- */
-void dump_stack(sp)
-struct stackframe_s *sp;
-{
-  char buff[32];
-  unsigned char uc;
-
-  /* Build up the binary PSW representation */
-  uc = (sp->psw >> 8) & 0xff;
-  (void) binary((int) uc, buff);
-  uc = sp->psw & 0xff;
-  buff[9] = '$';
-  (void) binary((int) uc, buff + 10);
-
-  /* Print all the information */
-  printf("Stack Frame:\tPC = %04.4x\t\t   PSW = %s\n",
-         sp->pc, buff);
-  printf("\t\t\t\t\tStatus = ____ ODIT SZ_A _P_C\n");
-
-  printf("  ax	bx	cx	dx	di	si\n");
-  printf("  %04.4x\t%04.4x\t%04.4x\t%04.4x\t%04.4x\t%04.4x\n",
-         sp->retreg, sp->bx, sp->cx, sp->dx, sp->di, sp->si);
-  printf("  sp	bp	ss\n");
-  printf("  %04.4x\t%04.4x\t%04.4x\n",
-         sp->sp, sp->fp, sp->ss);
-  printf("  cs	ds	es\n");
-  printf("  %04.4x\t%04.4x\t%04.4x\n",
-         sp->cs, sp->ds, sp->es);
-
-  /* Store for future reference */
-  stackptr = sp->sp;
-  baseptr = sp->fp;
-  if (dbglvl > 0)
-	printf("\nStack pointer 0x%x, Base pointer 0x%x\n", stackptr, baseptr);
-}
-
-
-/* M a i n
- *
- * Main program
- */
-main(argc, argv)
-int argc;
-char *argv[];
-{
-  int j, fdc, fds;
-  char *cp, corefile[132], symbfile[132];
-  struct proc proc_entry;
-  struct mem_map mp_segs[NR_LOCAL_SEGS];
-
-  /* Initial set up */
-  if ((cp = strrchr(argv[0], '/')) == (char *) NULL)
-	cp = argv[0];
-  else
-	cp++;
-  strncpy(progname, cp, 19);
-  strncpy(corefile, CORE, 131);
-  strncpy(symbfile, AOUT, 131);
-
-  /* Parse arguments */
-  opterr = 0;
-  while ((j = getopt(argc, argv, "c:dps:tx:")) != EOF) {
-	switch (j & 0177) {
-	    case 'c':
-		opt_c = TRUE;
-		strncpy(corefile, optarg, 131);
-		break;
-	    case 'd':	opt_d = TRUE;	break;
-	    case 'p':	opt_p = TRUE;	break;
-	    case 's':
-		opt_s = TRUE;
-		strncpy(symbfile, optarg, 131);
-		break;
-	    case 't':	opt_t = TRUE;	break;
-	    case 'x':
-		dbglvl = atoi(optarg);
-		opt_x = TRUE;
-		break;
-	    case '?':
-	    default:
-		usage();
-		exit(1);
-		break;
-	}
-  }
-
-  /* We must have a core file */
-  if ((fdc = open(corefile, O_RDONLY)) == -1) {
-	fprintf(stderr, "Cannot open %s\n", corefile);
-	exit(1);
-  }
-
-  /* We'd like an a.out file or a symbol table */
-  if ((fds = open(symbfile, O_RDONLY)) == -1) {
-	if (opt_s)
-		j = FAILED;
-	else {
-		strncpy(symbfile, AOUT, 131);
-		if ((fds = open(symbfile, O_RDONLY)) == -1)
-			j = FAILED;
-		else
-			j = read_symbol(fds);
-	}
-  } else
-	j = read_symbol(fds);
-
-  /* Only fatal if we insisted */
-  if (opt_s && j == FAILED) {
-	fprintf(stderr, "Cannot find symbols in %s\n", symbfile);
-	exit(1);
-  }
-
-  /* Read the process table */
-  if (dbglvl > 0) {
-	printf("\n");
-	printf("Size of mproc entry %d\n", NR_LOCAL_SEGS * sizeof(struct mem_map));
-	printf("Size of process table %d\n", sizeof(proc_entry));
-  }
-  if (read(fdc, (char *) mp_segs, sizeof(mp_segs)) != sizeof(mp_segs) ||
-      read(fdc, (char *) &proc_entry,
-	 sizeof(struct proc)) != sizeof(struct proc)) {
-	fprintf(stderr, "Cannot open %s\n", corefile);
-	exit(1);
-  }
-
-  /* Do the work */
-#if 0
-  dump_maps(mp_segs);		/* duplicated in the kernel */
-  printf("\n");
-	/* XXX broken */
-  dump_maps(proc_entry.p_map);
-#endif
-  printf("\n");
-  dump_registers(&proc_entry);
-  if (opt_t) {
-	printf("\n");
-	stack_trace(fdc);
-  }
-  if (opt_p) {
-	printf("\n");
-	dump_proc_table(&proc_entry);
-  }
-  if (opt_d) {
-	printf("\n");
-	dump_sym_tab(symtab);
-	dump_all_segs(fdc);
-  }
-
-  /* Wrap up */
-  (void) close(fdc);
-  if (fds != -1) (void) close(fds);
-
-  exit(0);
-  /* NOTREACHED */
-}
-
-
-/* P a r s e _ l i n e
- *
- * Parse a line of the symbol table
- */
-int parse_line(ps)
-char *ps;
-{
-  char c, s[80];
-  int j, k;
-  unsigned int u;
-
-  /* We must have space in the table */
-  if (maxsym == MAXSYM) return(FAILED);
-
-  /* Lines must be a minimum length to contain information */
-  if (strlen(ps) < 8) return(FAILED);
-
-  /* Lines must have a definite structure */
-  if (ps[1] != ' ' || ps[6] != ' ') return(FAILED);
-  for (j = 2; j < 6; j++)
-	if (!isxdigit(ps[j])) return(FAILED);
-  if (sscanf(ps, "%c %x %s", &c, &u, s) != 3) return (FAILED);
-
-  if (dbglvl > 0) printf("Address 0x%04.4x, label %s\n", u, s);
-
-  /* Load the symbol table in sorted order */
-  for (j = 0; j < maxsym; j++) {
-	if (u < symtab[j].addr) {
-		for (k = maxsym; k > j; k--) symtab[k] = symtab[k - 1];
-		break;
-	}
-  }
-  symtab[j].addr = u;
-  strncpy(symtab[j].label, s, SYMLEN);
-  maxsym++;
-
-  return(OK);
-}
-
-
-/* R e a d _ s y m b o l
- *
- * Read the symbol table
- */
-int read_symbol(fd)
-int fd;
-{
-  char sym[80], buff[BUFSIZ];
-  int j, k, m;
-  long int offset;
-  struct exec *ep;
-  struct nlist *np;
-
-  /* We collect only text symbols, since that's all that's needed here */
-
-  /* Initialise the buffer */
-  if ((j = read(fd, buff, BUFSIZ)) == 0 || j == -1) return(FAILED);
-
-  k = maxsym = 0;
-
-  /* Find out what we've got */
-  ep = (struct exec *) buff;
-  np = (struct nlist *) buff;
-  if (BADMAG(*ep)) {
-	/* Must be a separate symbol table */
-	while (TRUE) {
-		if (buff[k] == 'T') {
-			for (m = 0; m < 78; m++) {
-				sym[m] = buff[k];
-				if (++k == j) {
-					if ((j = read(fd, buff, BUFSIZ)) == 0 || j == -1)
-						break;
-					k = 0;
-				}
-				if (buff[k] == '\n') break;
-			}
-			sym[m + 1] = '\0';
-			(void) parse_line(sym);
-		}
-		if (++k == j) {
-			if ((j = read(fd, buff, BUFSIZ)) == 0 || j == -1)
-				break;
-			k = 0;
-		}
-	}
-  } else if (ep->a_syms != 0L) {
-	/* There's symbols in them thar hills */
-	offset = 8 * sizeof(long) + ep->a_text + ep->a_data;
-	if (lseek(fd, offset, 0) == -1L) return(FAILED);
-	/* Symbols are in an unsorted list */
-	while (read(fd, buff, sizeof(struct nlist)) == sizeof(struct nlist)) {
-		if (np->n_sclass == (N_TEXT + C_EXT)) {	/* external text symbols */
-			for (j = 0; j < maxsym; j++) {
-				if (np->n_value < symtab[j].addr) {
-					for (k = maxsym; k > j; k--)
-						symtab[k] = symtab[k - 1];
-					break;
-				}
-			}
-			symtab[j].addr = np->n_value;
-			strncpy(symtab[j].label, np->n_name, SYMLEN);
-			if (maxsym++ == MAXSYM) break;
-		}
-	}
-  } else if (opt_s)
-	return(FAILED);
-
-  if (dbglvl > 0) {
-	for (m = 0; m < maxsym; m++) printf("Addr 0x%04.4x, label %s\n",
-		       symtab[m].addr, symtab[m].label);
-	printf("Maxsym %d\n", maxsym);
-  }
-  return(OK);
-}
-
-
-/* S t a c k _ t r a c e
- *
- * Trace back down the stack frames.
- *
- * WARNING: very, very, non-portable code
- */
-void stack_trace(fd)
-int fd;
-{
-  int j;
-  unsigned int framepointer, lastpointer, returnvalue, end;
-  long int offset, bp;
-
-  /* Bp actually gives the offset from the base of the data segment */
-  bp = (long) (NR_LOCAL_SEGS * sizeof(struct mem_map)) + sizeof(struct proc)
-	+ lengths[0] + lengths[1] - bases[2];
-  if ((offset = lseek(fd, bp + (long int) baseptr, 0)) == -1L) return;
-  end = (bases[2] + lengths[2] - 1) & 0xffff;
-
-  if (dbglvl > 0)
-	printf("Baseptr %x, End %x, Bp %ld, Offset %ld\n", baseptr, end, bp, offset);
-
-  /* Print the header, then try to backtrace  */
-  printf("Stack back trace:\n\n");
-  printf("Frame address.  Contents.  Return address.");
-  if (maxsym != 0) printf("  Previous label.");
-  printf("\n");
-
-  lastpointer = baseptr;
-  while (TRUE) {
-	/* Read the frame pointer and return address values */
-	if (read(fd, (char *) &framepointer, sizeof(int)) == -1 ||
-	    read(fd, (char *) &returnvalue, sizeof(int)) == -1)
-		break;
-
-	/* Look up the return address - ignored if maxsym == 0 */
-	for (j = 0; j < maxsym; j++) {
-		if (symtab[j].addr >= returnvalue) break;
-	}
-	if (j > 0) j--;
-	printf("    0x%04.4x        0x%04.4x      0x%04.4x          %s\n",
-	       lastpointer, framepointer, returnvalue,
-	       (maxsym == 0) ? "" : symtab[j].label);
-
-	/* If the result is clearly invalid, quit */
-	if (framepointer == 0 || framepointer >= end || framepointer <= lastpointer)
-		break;
-
-	/* Otherwise try to move to the next frame base */
-	lastpointer = framepointer;
-	if ((offset = lseek(fd, bp + (long int) framepointer, 0)) == -1L || offset == 0L)
-		break;
-  }
-}
-
-
-/* U s a g e
- *
- * Usage message
- */
-void usage()
-{
-  fprintf(stderr, "Usage: %s [-dpt] [-c corefile] [-s symbfile]\n", progname);
-}
Index: trunk/minix/commands/ibm/readclock.c
===================================================================
--- trunk/minix/commands/ibm/readclock.c	(revision 9)
+++ 	(revision )
@@ -1,226 +1,0 @@
-/* setime - set the system time from the real time clock
-					Authors: T. Holm & E. Froese
-					Adapted by: Jorrit .N. Herder */
-
-/************************************************************************/
-/*   Readclock was updated for security reasons: openeing /dev/mem no	*/
-/*   longer automatically grants I/O privileges to the calling process	*/
-/*   so that the CMOS' clock could not be read from this program. The	*/
-/*   new approach is to rely on the FS to do the CMOS I/O, via the new  */
-/*   system call CMOSTIME (which only reads the current clock value and */
-/*   cannot update the CMOS clock). 					*/
-/*   The original readclock.c is still available under backup.c.	*/
-/************************************************************************/
-/*									*/
-/*   readclock.c							*/
-/*									*/
-/*		Read the clock value from the 64 byte CMOS RAM		*/
-/*		area, then set system time.				*/
-/*									*/
-/*		If the machine ID byte is 0xFC or 0xF8, the device	*/
-/*		/dev/mem exists and can be opened for reading,		*/
-/*		and no errors in the CMOS RAM are reported by the	*/
-/*		RTC, then the time is read from the clock RAM		*/
-/*		area maintained by the RTC.				*/
-/*									*/
-/*		The clock RAM values are decoded and fed to mktime	*/
-/*		to make a time_t value, then stime(2) is called.	*/
-/*									*/
-/*		This fails if:						*/
-/*									*/
-/*		If the machine ID does not match 0xFC or 0xF8 (no	*/
-/*		error message.)						*/
-/*									*/
-/*		If the machine ID is 0xFC or 0xF8 and /dev/mem		*/
-/*		is missing, or cannot be accessed.			*/
-/*									*/
-/*		If the RTC reports errors in the CMOS RAM.		*/
-/*									*/
-/************************************************************************/
-/*    origination          1987-Dec-29              efth                */
-/*    robustness	   1990-Oct-06		    C. Sylvain		*/
-/* incorp. B. Evans ideas  1991-Jul-06		    C. Sylvain		*/
-/*    set time & calibrate 1992-Dec-17		    Kees J. Bot		*/
-/*    clock timezone	   1993-Oct-10		    Kees J. Bot		*/
-/*    set CMOS clock	   1994-Jun-12		    Kees J. Bot		*/
-/*    removed set CMOS	   2004-Sep-06		    Jorrit N. Herder    */
-/************************************************************************/
-
-#include <minix/callnr.h>
-#include <minix/config.h>
-#include <minix/type.h>
-#include <minix/const.h>
-#include <minix/com.h>
-#include <minix/syslib.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioc_cmos.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <signal.h>
-#include <ibm/portio.h>
-#include <ibm/cmos.h>
-#include <sys/svrctl.h>
-
-#define MAX_RETRIES	1
-
-int nflag = 0;		/* Tell what, but don't do it. */
-int y2kflag = 0;	/* Interpret 1980 as 2000 for clock with Y2K bug. */
-
-char clocktz[128];	/* Timezone of the clock. */
-
-#define MACH_ID_ADDR	0xFFFFE		/* BIOS Machine ID at FFFF:000E */
-
-#define PC_AT		   0xFC		/* Machine ID byte for PC/AT,
-					   PC/XT286, and PS/2 Models 50, 60 */
-#define PS_386		   0xF8		/* Machine ID byte for PS/2 Model 80 */
-
-/* Manufacturers usually use the ID value of the IBM model they emulate.
- * However some manufacturers, notably HP and COMPAQ, have had different
- * ideas in the past.
- *
- * Machine ID byte information source:
- *	_The Programmer's PC Sourcebook_ by Thom Hogan,
- *	published by Microsoft Press
- */
-
-void errmsg(char *s);
-int bcd_to_dec(int n);
-int dec_to_bcd(int n);
-void usage(void);
-
-#define CMOS_DEV "/dev/cmos"
-
-PUBLIC int main(int argc, char **argv)
-{
-  int fd;
-  struct tm time1;
-  struct tm time2;
-  struct tm tmnow;
-  char date[64];
-  time_t now, rtc;
-  int i, s, mem;
-  unsigned char mach_id, cmos_state;
-  struct sysgetenv sysgetenv;
-  message m;
-  int request;
-
-
-  /* Process options. */
-  while (argc > 1) {
-	char *p = *++argv;
-
-	if (*p++ != '-') usage();
-
-	while (*p != 0) {
-		switch (*p++) {
-		case 'n':	nflag = 1;	break;
-		case '2':	y2kflag = 1;	break;
-		default:	usage();
-		}
-	}
-	argc--;
-  }
-
-#if DEAD_CODE
-  /* The hardware clock may run in a different time zone, likely GMT or
-   * winter time.  Select that time zone.
-   */
-  strcpy(clocktz, "TZ=");
-  sysgetenv.key = "TZ";
-  sysgetenv.keylen = 2+1;
-  sysgetenv.val = clocktz+3;
-  sysgetenv.vallen = sizeof(clocktz)-3;
-  if (svrctl(SYSGETENV, &sysgetenv) == 0) {
-	putenv(clocktz);
-	tzset();
-  }
-#endif
-
-  /* Read the CMOS real time clock. */
-  for (i = 0; i < MAX_RETRIES; i++) {
-
-	/* sleep, unless first iteration */
-	if (i > 0) sleep(5);
-
-	/* Open the CMOS device to read the system time. */
-	if ((fd = open(CMOS_DEV, O_RDONLY)) < 0) {
-		perror(CMOS_DEV);
-		fprintf(stderr, "Couldn't open CMOS device.\n");
-		exit(1);
-	}
-        request = (y2kflag) ? CIOCGETTIME : CIOCGETTIMEY2K;
-	if ((s=ioctl(fd, request, (void *) &time1)) < 0) {
-		perror("ioctl");
-		fprintf(stderr, "Couldn't do CMOS ioctl.\n");
-		exit(1);
-	}
-	close(fd);
-
-	now = time(NULL);
-
-	time1.tm_isdst = -1;	/* Do timezone calculations. */
-	time2 = time1;
-
-	rtc= mktime(&time1);	/* Transform to a time_t. */
-	if (rtc != -1) {
-		break;
-	}
-
-	fprintf(stderr,
-"readclock: Invalid time read from CMOS RTC: %d-%02d-%02d %02d:%02d:%02d\n",
-		time2.tm_year+1900, time2.tm_mon+1, time2.tm_mday,
-		time2.tm_hour, time2.tm_min, time2.tm_sec);
-  }
-  if (i >= MAX_RETRIES) exit(1);
-
-  /* Now set system time. */
-  if (nflag) {
-		printf("stime(%lu)\n", (unsigned long) rtc);
-  } else {
-	if (stime(&rtc) < 0) {
-		errmsg( "Not allowed to set time." );
-		exit(1);
-	}
-  }
-  tmnow = *localtime(&rtc);
-  if (strftime(date, sizeof(date),
-			"%a %b %d %H:%M:%S %Z %Y", &tmnow) != 0) {
-	if (date[8] == '0') date[8]= ' ';
-#if 0
-	printf("%s [CMOS read via FS, see command/ibm/readclock.c]\n", date);
-#endif
-  }
-  exit(0);
-}
-
-void errmsg(char *s)
-{
-  static char *prompt = "readclock: ";
-
-  fprintf(stderr, "%s%s\n", prompt, s);
-  prompt = "";
-}
-
-
-int bcd_to_dec(int n)
-{
-  return ((n >> 4) & 0x0F) * 10 + (n & 0x0F);
-}
-
-int dec_to_bcd(int n)
-{
-  return ((n / 10) << 4) | (n % 10);
-}
-
-void usage(void)
-{
-  fprintf(stderr, "Usage: settime [-n2]\n");
-  exit(1);
-}
Index: trunk/minix/commands/ibm/recwave.c
===================================================================
--- trunk/minix/commands/ibm/recwave.c	(revision 9)
+++ 	(revision )
@@ -1,237 +1,0 @@
-/*   
- *  recwave.c
- *
- *  Record sound files in wave format. Only MicroSoft PCM is supported. 
- *
- *  Michel R. Prevenier.
- */
-
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <termios.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/ioctl.h>
-#include <minix/sound.h>
-
-_PROTOTYPE (void main, (int argc, char **argv));
-_PROTOTYPE (void usage, (void));
-_PROTOTYPE ( void write_wave_header, (void));
-_PROTOTYPE ( void terminate, (int s));
-
-
-/******* Wave format definitions *********/
-
-#define RIFF_ID		0x46464952
-#define WAVE_ID1	0x45564157
-#define WAVE_ID2	0x20746D66
-#define DATA_ID		0x61746164
-#define MS_PCM_FORMAT	0x0001
-
-#define WORD	short 
-#define DWORD   unsigned long
-
-struct RIFF_fields
-{
-  DWORD RIFF_id;
-  DWORD RIFF_len;
-  DWORD WAVE_id1;
-  DWORD WAVE_id2;
-  DWORD data_ptr;
-} r_fields; 
-
-struct common_fields
-{
-  WORD  FormatTag;
-  WORD  Channels;
-  DWORD SamplesPerSec;
-  DWORD AvgBytesPerSec;
-  WORD  BlockAlign;
-} c_fields;
-
-struct specific_fields
-{
-  WORD BitsPerSample;
-} s_fields;
-
-DWORD data_id;
-DWORD data_len;
-
-/******** End of wave format definitions *********/
-
-/* Default recording values */
-unsigned int sign = 0; 
-unsigned int bits = 8; 
-unsigned int stereo = 0; 
-unsigned int rate = 22050; 
-unsigned int time = 10;
-
-int old_stdin;
-struct termios old_tty, new_tty;
-int audio, file;
-
-void usage()
-{
-  fprintf(stderr, "Usage: recwav [-b -s -r] file_name\n");
-  exit(-1);
-}
-
-void terminate(s)
-int s;
-{
-  /* Restore terminal parameters */
-  tcsetattr(0, TCSANOW, &old_tty);
-  (void) fcntl(0,F_SETFL,old_stdin);
-  close(audio);
-  close(file);
-  exit(0);		
-}
-
-void write_wave_header()
-{
-  /* RIFF fields */
-  r_fields.RIFF_id = RIFF_ID;
-  r_fields.WAVE_id1 = WAVE_ID1;
-  r_fields.WAVE_id2 = WAVE_ID2;
-  r_fields.data_ptr = 16;
-  r_fields.RIFF_len = 20 + r_fields.data_ptr + data_len;
-
-  /* MicroSoft PCM specific fields */
-  s_fields.BitsPerSample = bits;
-
-  /* Common fields */
-  c_fields.FormatTag = MS_PCM_FORMAT;
-  c_fields.Channels = stereo + 1;
-  c_fields.SamplesPerSec = rate;
-  c_fields.AvgBytesPerSec =  c_fields.Channels * rate * (bits / 8);
-  c_fields.BlockAlign = c_fields.Channels * (bits / 8);
-
-  /* Data chunk */
-  data_id = DATA_ID;
-
-  /* Write wave-file header */
-  lseek(file, 0L, SEEK_SET);
-  write(file, &r_fields, 20);
-  write(file, &c_fields, 14);
-  write(file, &s_fields, 2);
-  write(file, &data_id, sizeof(data_id)); 
-  write(file, &data_len, sizeof(data_len)); 
-}
-
-
-void main(argc, argv)
-int argc;
-char **argv;
-{
-  unsigned int fragment_size;
-  char *buffer, *file_name;
-  char c;
-  int i;
-
-  /* Read parameters */
-  if (argc < 2) usage();
-
-  i = 1;
-  while (argv[i][0] == '-' && i < argc)
-  {
-    if (strncmp(argv[i], "-b", 2) == 0)
-      bits = atoi(argv[i] + 2);
-    else if (strncmp(argv[i], "-s", 2) == 0) 
-      stereo = atoi(argv[i] + 2);
-    else if (strncmp(argv[i], "-r", 2) == 0) 
-      rate = (unsigned int) atol(argv[i] + 2);
-    else usage();
-    i++;
-  }
-  if (i == argc) usage();
-
-  file_name = argv[i];
-
-  /* Some sanity checks */
-  if ((bits != 8 && bits != 16) || 
-      (rate < 4000 || rate > 44100) ||
-      (stereo != 0 && stereo != 1))
-  {
-    fprintf(stderr, "Invalid parameters\n");
-    exit(-1);
-  }
-
-  /* Open DSP */
-  if ((audio = open("/dev/rec", O_RDWR)) < 0) 
-  {
-    fprintf(stderr, "Cannot open /dev/rec\n");
-    exit(-1);
-  }
-
-  /* Get maximum fragment size and try to allocate a buffer */
-  ioctl(audio, DSPIOMAX, &fragment_size);
-  if ((buffer = malloc(fragment_size)) == (char *) 0)
-  {
-    fprintf(stderr, "Cannot allocate buffer\n");
-    exit(-1);
-  } 
-
-  /* Set sample parameters */
-  ioctl(audio, DSPIOSIZE, &fragment_size); 
-  ioctl(audio, DSPIOSTEREO, &stereo); 
-  ioctl(audio, DSPIORATE, &rate);
-  ioctl(audio, DSPIOBITS, &bits); 
-  sign = (bits == 16 ? 1 : 0);
-  ioctl(audio, DSPIOSIGN, &sign); 
-
-  /* Create sample file */
-  if ((file = creat(file_name, 511)) < 0) 
-  {
-    fprintf(stderr, "Cannot create %s\n", argv[1]);
-    exit(-1);
-  } 
-  /* Skip wave header */
-  lseek(file, (long)(sizeof(r_fields) + 
-                     sizeof(c_fields) + 
-                     sizeof(s_fields) + 
-                     sizeof(data_id) + 
-                     sizeof(data_len)), SEEK_SET); 
-
-  printf("\nBits per sample   : %u\n", bits);
-  printf("Stereo            : %s\n", (stereo == 1 ? "yes" : "no"));
-  printf("Samples per second: %u\n", rate);
-
-  /* Set terminal parameters and remember the old ones */
-  tcgetattr(0, &old_tty);
-  new_tty = old_tty;
-  new_tty.c_lflag &= ~(ICANON|ECHO);
-  old_stdin = fcntl(0, F_GETFL);
-
-  /* Catch break signal to be able to restore terminal parameters in case
-   * of a user interrupt
-   */
-  signal(SIGINT, terminate);
-
-  /* Go to non-blocking mode */
-  tcsetattr(0, TCSANOW, &new_tty);
-  (void) fcntl(0, F_SETFL, old_stdin | O_NONBLOCK);
-
-  printf("\nPress spacebar to start sampling...\n");
-  while(!(read(0, &c, 1) == 1 && c == ' '));
-
-  printf("Sampling, press spacebar to stop...\n");
-  while(!(read(0, &c, 1) == 1 && c == ' '))
-  {
-    /* Read sample fragment and write to sample file */
-    read(audio, buffer, fragment_size);
-    write(file, buffer, fragment_size);
-    data_len+= fragment_size;
-  }
-  printf("%ld bytes sampled. \n\n", data_len);
- 
-  /* Construct the wave header in front of the raw sample data */
-  write_wave_header();
-  
-  /* Restore terminal parameters and exit */
-  terminate(1);
-}
Index: trunk/minix/commands/ibm/repartition.c
===================================================================
--- trunk/minix/commands/ibm/repartition.c	(revision 9)
+++ 	(revision )
@@ -1,283 +1,0 @@
-/*	repartition 1.18 - Load a partition table	Author: Kees J. Bot
- *								30 Nov 1991
- */
-#define nil 0
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <errno.h>
-#include <dirent.h>
-#include <limits.h>
-
-#define DEV_FD0		0x200
-
-#define SECTOR_SIZE	512
-
-#define arraysize(a)	(sizeof(a)/sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-char *arg0;
-char *dev_file;		/* Device to repartition. */
-
-#ifndef S_ISLNK
-/* There were no symlinks in medieval times. */
-#define lstat		stat
-#endif
-
-void report(const char *label)
-{
-	fprintf(stderr, "%s: %s: %s\n", arg0, label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-#ifndef makedev
-#define minor(dev)	(((dev) >> MINOR) & BYTE)
-#define major(dev)	(((dev) >> MAJOR) & BYTE)
-#define makedev(major, minor)	\
-			((dev_t) (((major) << MAJOR) | ((minor) << MINOR)))
-#endif
-
-#define MINOR_d0p0s0	128
-
-void partsort(struct part_entry *pe)
-/* DOS has the misguided idea that partition tables must be sorted. */
-{
-  int i,j;
-  struct part_entry tmp;
-
-  for (i = 0; i < NR_PARTITIONS; i++)
-	for (j = 0; j < NR_PARTITIONS-1; j++)
-		if ((pe[j].sysind == NO_PART && pe[j+1].sysind != NO_PART) ||
-		 (pe[j].lowsec > pe[j+1].lowsec && pe[j+1].sysind != NO_PART)) {
-			tmp = pe[j];
-			pe[j] = pe[j+1];
-			pe[j+1] = tmp;
-		}
-}
-
-char *finddev(dev_t device)
-/* Find the device next to dev_file with the given device number. */
-{
-	DIR *dp;
-	struct dirent *de;
-	static char name[PATH_MAX];
-	char *np;
-	size_t nlen;
-	struct stat st;
-
-	if ((np= strrchr(dev_file, '/')) == nil) np= dev_file; else np++;
-	nlen= np - dev_file;
-	if (nlen > PATH_MAX - NAME_MAX - 1) {
-		fprintf(stderr, "%s: %s: Name is way too long\n",
-			arg0, dev_file);
-		exit(1);
-	}
-	memcpy(name, dev_file, nlen);
-
-	if ((dp= opendir("/dev")) == nil) fatal("/dev");
-	while ((de= readdir(dp)) != nil) {
-		strcpy(name+nlen, de->d_name);
-		if (lstat(name, &st) == 0
-			&& (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
-			&& st.st_rdev == device
-		) {
-			closedir(dp);
-			return name;
-		}
-	}
-	fprintf(stderr, "%s: Can't find partition devices associated with %s\n",
-		arg0, dev_file);
-	exit(1);
-}
-
-#define DSETP	0
-#define DGETP	1
-
-int diocntl(dev_t device, int request, struct partition *entry)
-/* Get or set the geometry of a device. */
-{
-	char *name;
-	int r, f, err;
-	struct partition geometry;
-
-	name= finddev(device);
-	if ((f= open(name, O_RDONLY)) < 0) return -1;
-	r= ioctl(f, request == DSETP ? DIOCSETP : DIOCGETP, (void *) entry);
-	err= errno;
-	(void) close(f);
-	errno= err;
-	return r;
-}
-
-struct partition geometry;	/* Geometry of the device. */
-
-void print_chs(unsigned long sector)
-{
-	unsigned secspcyl = geometry.heads * geometry.sectors;
-	int delta= 0;
-
-	if (sector == -1) { sector= 0; delta= -1; }
-
-	printf(" %5d/%03d/%02d",
-		(int) (sector / secspcyl),
-		(int) (sector % secspcyl) / geometry.sectors,
-		(int) (sector % geometry.sectors) + delta);
-}
-
-void show_part(char *name, unsigned long base, unsigned long size)
-{
-	int i;
-	static int len= 0;
-
-	if (len == 0) {
-		len= strlen(name) + 3;
-		printf("device");
-		for (i = 6; i < len; i++) fputc(' ', stdout);
-		printf(
-	"      first         last        base      size        kb\n");
-	}
-
-	printf("%s", name);
-	for (i = strlen(name); i < len; i++) fputc(' ', stdout);
-
-	print_chs(base);
-	print_chs(base + size - 1);
-	printf(" %9lu %9lu %9lu\n", base, size, size / (1024/SECTOR_SIZE));
-}
-
-int main(int argc, char **argv)
-{
-	struct stat hdst;
-	struct partition whole, entry;
-	struct part_entry table[4], *pe;
-	int drive, par, device, incr;
-	int partf;
-	char *table_file;
-	int hd_major, hd_minor;
-	int needsort;
-	int shrink;		/* True if partitions are shrinked to fit. */
-	unsigned long base, size, limit;
-
-	if ((arg0= strrchr(argv[0], '/')) == nil) arg0= argv[0]; else arg0++;
-
-	if (argc < 2 || argc > 3) {
-		fprintf(stderr,
-			"Usage: %s device [partition-file]\n", arg0);
-		exit(1);
-	}
-	dev_file= argv[1];
-	table_file= argv[argc - 1];
-	shrink= (argc == 2);
-
-	if (stat(dev_file, &hdst) < 0) fatal(dev_file);
-
-	/* Geometry (to print nice numbers.) */
-	if (diocntl(hdst.st_rdev, DGETP, &geometry) < 0) fatal(dev_file);
-
-	if (!S_ISBLK(hdst.st_mode)) {
-		fprintf(stderr, "%s: %s is not a device\n", arg0, dev_file);
-		exit(1);
-	}
-	hd_major= major(hdst.st_rdev);
-	hd_minor= minor(hdst.st_rdev);
-
-	if (hd_minor >= MINOR_d0p0s0) {
-		errno= EINVAL;
-		fatal(dev_file);
-	}
-
-	if (hd_major == major(DEV_FD0)) {
-		/* HD is actually a floppy. */
-		if (hd_minor >= 4) {
-			errno= EINVAL;
-			fatal(dev_file);
-		}
-		device= hd_minor + (28 << 2);
-		incr= 4;
-		needsort= 0;
-	} else
-	if (hd_minor % (1 + NR_PARTITIONS) == 0) {
-		/* Partitioning hd0, hd5, ... */
-		device= hd_minor + 1;
-		incr= 1;
-		needsort= 1;
-	} else {
-		/* Subpartitioning hd[1-4], hd[6-9], ... */
-		drive= hd_minor / (1 + NR_PARTITIONS);
-		par= hd_minor % (1 + NR_PARTITIONS) - 1;
-
-		device= MINOR_d0p0s0
-				+ (drive * NR_PARTITIONS + par) * NR_PARTITIONS;
-		if (device + NR_PARTITIONS - 1 > BYTE) {
-			errno= EINVAL;
-			fatal(dev_file);
-		}
-		incr= 1;
-		needsort= 0;
-	}
-	/* Device is now the first of the minor devices to be repartitioned. */
-
-	/* Read the partition table from the boot block. */
-	if ((partf= open(table_file, O_RDONLY)) < 0
-		|| lseek(partf, (off_t) PART_TABLE_OFF, SEEK_SET) == -1
-		|| (par= read(partf, (char *) table, (int) sizeof(table))) < 0
-	) fatal(table_file);
-
-	if (par < sizeof(table)) {
-		fprintf(stderr, "%s: %s does not contain a partition table\n",
-			arg0, table_file);
-		exit(1);
-	}
-	if (needsort) partsort(table);
-
-	/* Show the geometry of the affected drive or partition. */
-	if (diocntl(hdst.st_rdev, DGETP, &whole) < 0) fatal(dev_file);
-
-	/* Use sector numbers. */
-	base = div64u(whole.base, SECTOR_SIZE);
-	size = div64u(whole.size, SECTOR_SIZE);
-	limit = base + size;
-
-	show_part(dev_file, base, size);
-
-	/* Send the partition table entries to the device driver. */
-	for (par= 0; par < NR_PARTITIONS; par++, device+= incr) {
-		pe = &table[par];
-		if (shrink && pe->size != 0) {
-			/* Shrink the partition entry to fit within the
-			 * enclosing device just like the driver does.
-			 */
-			unsigned long part_limit= pe->lowsec + pe->size;
-
-			if (part_limit < pe->lowsec) part_limit= limit;
-			if (part_limit > limit) part_limit= limit;
-			if (pe->lowsec < base) pe->lowsec= base;
-			if (part_limit < pe->lowsec) part_limit= pe->lowsec;
-			pe->size= part_limit - pe->lowsec;
-		}
-
-		entry.base= mul64u(pe->lowsec, SECTOR_SIZE);
-		entry.size= mul64u(pe->size, SECTOR_SIZE);
-		if (diocntl(makedev(hd_major, device), DSETP, &entry) < 0)
-			fatal(dev_file);
-
-		show_part(finddev(makedev(hd_major, device)),
-							pe->lowsec, pe->size);
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/screendump.c
===================================================================
--- trunk/minix/commands/ibm/screendump.c	(revision 9)
+++ 	(revision )
@@ -1,136 +1,0 @@
-/*	screendump 1.2 - dump the contents of the console
- *							Author: Kees J. Bot
- *								16 Dec 1994
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-#define BIOS_CRTBASE	0x00463L	/* BIOS parameters: CRT base. */
-#define CRTBASE_MONO	0x03B4		/* Value of CRT base for mono mode. */
-
-#define MONO_BASE	0xB0000L	/* Screen memory in monochrome mode. */
-#define COLOR_BASE	0xB8000L	/* ... colour mode. */
-
-#define DEF_COLS	80		/* Default screen geometry. */
-#define DEF_ROWS	25
-
-#define MAX_COLS	132		/* Maximum screen geometry. */
-#define MAX_ROWS	60
-
-char MEMORY[] =		"/dev/mem";	/* Memory device to read screen. */
-int mfd;				/* Open memory device. */
-
-void tell(const char *message)
-{
-	write(2, message, strlen(message));
-}
-
-void fatal(const char *label)
-{
-	const char *err= strerror(errno);
-
-	tell("screendump: ");
-	tell(label);
-	tell(": ");
-	tell(err);
-	tell("\n");
-	exit(1);
-}
-
-long video_base(void)
-/* Is it monochrome or colour? */
-{
-	static unsigned short bios_crtbase;
-
-	if (lseek(mfd, (off_t) BIOS_CRTBASE, SEEK_SET) == -1) fatal(MEMORY);
-	switch (read(mfd, &bios_crtbase, sizeof(bios_crtbase))) {
-	case -1:
-		fatal(MEMORY);
-	default:
-		tell("screendump: can't obtain BIOS parameter: short read\n");
-		exit(1);
-	case sizeof(bios_crtbase):
-		/* Fine */;
-	}
-
-	return bios_crtbase == CRTBASE_MONO ? MONO_BASE : COLOR_BASE;
-}
-
-void main(void)
-{
-	static unsigned char screen[MAX_COLS * MAX_ROWS * 2];
-	unsigned char *ps;
-	long base;
-	int lfd;
-	int row;
-	int nrows, ncols;
-	struct winsize winsize;
-
-	/* Open the memory device. */
-	if ((mfd= open(MEMORY, O_RDONLY)) < 0) fatal(MEMORY);
-
-	base= video_base();
-
-	/* Read screen memory. */
-	if (lseek(mfd, base, SEEK_SET) == -1) fatal(MEMORY);
-
-	switch (read(mfd, screen, sizeof(screen))) {
-	case -1:
-		fatal(MEMORY);
-	default:
-		tell("screendump: can't obtain screen dump: short read\n");
-		exit(1);
-	case sizeof(screen):
-		/* Fine */;
-	}
-
-	/* Try to obtain the screen geometry from /dev/log. */
-	ncols= DEF_COLS;
-	nrows= DEF_ROWS;
-	if ((lfd= open("/dev/log", O_WRONLY)) != -1
-		&& ioctl(lfd, TIOCGWINSZ, &winsize) == 0
-	) {
-		if (40 <= winsize.ws_col && winsize.ws_col <= MAX_COLS) {
-			ncols= winsize.ws_col;
-		}
-		if (25 <= winsize.ws_row && winsize.ws_row <= MAX_COLS) {
-			nrows= winsize.ws_row;
-		}
-	}
-	if (lfd != -1) close(lfd);
-
-	/* Print the contents of the screen line by line.  Omit trailing
-	 * blanks.  Note that screen memory consists of pairs of characters
-	 * and attribute bytes.
-	 */
-	ps= screen;
-	for (row= 0; row < nrows; row++) {
-		char line[MAX_COLS + 1];
-		char *pl= line;
-		int column;
-		int blanks= 0;
-
-		for (column= 0; column < ncols; column++) {
-			if (*ps <= ' ') {
-				/* Skip trailing junk. */
-				blanks++;
-			} else {
-				/* Reinsert blanks and add a character. */
-				while (blanks > 0) { *pl++= ' '; blanks--; }
-				*pl++= *ps;
-			}
-			/* Skip character and attribute byte. */
-			ps+= 2;
-		}
-		*pl++= '\n';
-		if (write(1, line, pl - line) < 0) fatal("stdout");
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/sdump.c
===================================================================
--- trunk/minix/commands/ibm/sdump.c	(revision 9)
+++ 	(revision )
@@ -1,191 +1,0 @@
-/* sdump - dump memory */
-
-#include <minix/config.h>
-#include <sys/types.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include <minix/ipc.h>
-#include <timers.h>
-#include <signal.h>
-
-#undef EXTERN
-#define EXTERN
-#include "../../servers/pm/const.h"
-#include "../../servers/pm/type.h"
-#include "../../servers/pm/mproc.h"
-#include "../../kernel/const.h"
-#include "../../kernel/type.h"
-#include "../../kernel/proc.h"
-#undef printf			/* printf was misdefined by the sys headers */
-
-#include <ctype.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#define STACK_BYTES 30000
-
-char *default_core = "core";
-int stack[STACK_BYTES / sizeof (int)];
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void read_segmap, (int fd, struct mproc *mp, long *seg_size));
-_PROTOTYPE(void read_registers, (int fd, struct proc *p));
-_PROTOTYPE(void dump_stack, (int fd, struct mproc *mp, long *seg_size));
-_PROTOTYPE(void error, (char *s1, char *s2));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int fd;
-  long seg_size[NR_LOCAL_SEGS];	/* segment sizes in bytes */
-  struct mproc *mp;
-  struct proc *p;
-  char *file;
-
-  if (argc > 2) error("Usage: rdump [core_file]\n", "");
-
-  if (argc == 1)
-	file = default_core;
-  else
-	file = argv[1];
-
-  if ( (fd = open(file, O_RDONLY)) < 0) error("Cannot open", file);
-
-  mp = &mproc[0];
-  p = &proc[0];
-  read_segmap(fd, mp, seg_size);
-  read_registers(fd, p);
-  dump_stack(fd, mp, seg_size);
-  return(0);
-}
-
-void read_segmap(fd, mp, seg_size)
-int fd;
-struct mproc *mp;
-long seg_size[NR_LOCAL_SEGS];
-{
-  int i, segmap_size;
-
-  /* Read in the segment map. */
-  segmap_size = sizeof mp->mp_seg;
-  if (read(fd, (char *) mp, segmap_size) != segmap_size)
-	error("Cannot read segmap map from core image file", "");
-
-  for (i = 0; i < NR_LOCAL_SEGS; i++)
-	seg_size[i] = (long) mp->mp_seg[i].mem_len << CLICK_SHIFT;
-  printf("Seg sizes in bytes:  Text: %ld  Data: %ld, Stack: %ld\n",
-	 seg_size[T], seg_size[D], seg_size[S]);
-}
-
-void read_registers(fd, p)
-int fd;
-struct proc *p;
-{
-  int proctblsize;
-  struct stackframe_s r;
-
-  proctblsize = sizeof (struct proc);
-  if (read(fd, (char *) p, proctblsize) != proctblsize)
-	error("Cannot read process table from core image file", "");
-  r = p->p_reg;
-
-  /* Print proc table. */
-  printf("\n");
-#if (CHIP == INTEL)
-#if _WORD_SIZE == 4
-  printf("eax=%8lX   ebx=%8lX   ecx=%8lX   edx=%8lX\n",
-	 r.retreg, r.bx, r.cx, r.dx);
-  printf("esi=%8lX   edi=%8lX   ebp=%8lX   esp=%8lX   eip=%8lX\n",
-	 r.si, r.di, r.fp, r.sp, r.pc);
-  printf(" ds=%8lX    es=%8lX                   ss=%8lX    cs=%8lX\n",
-	 r.ds, r.es, r.ss, r.cs);
-  printf(" fs=%8lX    gs=%8lX                                  ef=%8lX\n",
-         r.fs, r.gs, r.psw);
-#else
-  printf(
-"ax=%4X  bx=%4X  cx=%4X  dx=%4X  si=%4X  di=%4X  bp=%4X  sp=%4X  ip=%4X\n",
-	 r.retreg, r.bx, r.cx, r.dx, r.si, r.di, r.fp, r.sp, r.pc);
-  printf(
-" f=%4X                             ds=%4X  es=%4X           ss=%4X  cs=%4X\n",
-	 r.psw, r.ds, r.es, r.ss, r.cs);
-#endif
-#endif /* (CHIP == INTEL) */
-#if (CHIP == M68000)
-  printf("pc=%8lx   psw=%4x\n", r.pc, r.psw);
-  printf("d0=%8lx   d1=%8lx   d2=%8lx   d3=%8lx\n", r.retreg, r.d1, r.d2, r.d3);
-  printf("d4=%8lx   d5=%8lx   d6=%8lx   d7=%8lx\n", r.d4, r.d5, r.d6, r.d7);
-  printf("a0=%8lx   a1=%8lx   a2=%8lx   a3=%8lx\n", r.a0, r.a1, r.a2, r.a3);
-  printf("a4=%8lx   a5=%8lx   a6=%8lx   a7=%8lx\n", r.a4, r.a5, r.a6, r.sp);
-#endif
-  printf("\n");
-}
-
-void dump_stack(fd, mp, seg_size)
-int fd;
-struct mproc *mp;
-long seg_size[NR_LOCAL_SEGS];
-{
-  unsigned char ch;
-  char format[32];
-  int word, i, stack_size, j;
-  vir_bytes v, vi;
-
-  /* Seek past text and data segments. */
-  lseek(fd, seg_size[T] + seg_size[D], SEEK_CUR);
-  v = mp->mp_seg[S].mem_vir << CLICK_SHIFT;
-
-  stack_size = (int) seg_size[S];
-  if (stack_size != seg_size[S] || stack_size < 0 || stack_size > STACK_BYTES)
-	error("Stack too large", "");
-
-  /* Dump the stack. */
-  if (read(fd, (char *) stack, stack_size) != stack_size)
-	error("Error reading stack from core file", "");
-
-#define BYTES(num)      ((unsigned) sizeof (num))
-#define DEC_DIGITS(num) (sizeof (num) <= 2 ? 6 : 11)	/* for 16/32 bit num */
-#define HEX_DIGITS(num) (((unsigned) sizeof (num) * CHAR_BIT + 3) / 4)
-
-  printf("%*s   %*s  %*s  %*s\n",
-	 HEX_DIGITS(vi), "Addr",
-	 HEX_DIGITS(word), "Hex",
-	 DEC_DIGITS(word), "Dec",
-	 BYTES(word), "Char");
-
-  /* The format string depends messily on the size of various things. */
-  strcpy(format, "%*");
-  if (sizeof v > sizeof (int)) strcat(format, "l");
-  strcat(format, "X:  %*");
-  if (sizeof word > sizeof (int)) strcat(format, "l");
-  strcat(format, "X  %*");
-  if (sizeof word > sizeof (int)) strcat(format, "l");
-  strcat(format, "d  ");
-  
-  for (i = stack_size / sizeof (int) - 1, vi = v + stack_size - sizeof (int);
-       i >= 0; --i, vi -= sizeof (int)) {
-	word = stack[i];
-	printf(format,
-	       HEX_DIGITS(vi), vi,
-	       HEX_DIGITS(word), word,
-	       DEC_DIGITS(word), word);
-	for (j = 0; j < BYTES(word); ++j, word >>= CHAR_BIT) {
-		ch = (unsigned char) word;
-		if (!isprint(ch)) ch = '.';
-		putchar(ch);
-	}
-	putchar('\n');
-  }
-}
-
-void error(s1, s2)
-char *s1, *s2;
-{
-  printf("%s %s\n", s1, s2);
-  exit(1);
-}
Index: trunk/minix/commands/indent/Makefile
===================================================================
--- trunk/minix/commands/indent/Makefile	(revision 9)
+++ 	(revision )
@@ -1,22 +1,0 @@
-# Makefile for indent
-
-CFLAGS= -c -O -D_MINIX -D_POSIX_SOURCE -wo -m
-CC = exec cc
-
-all:	indent
-
-OBJ = args.o comment.o lexi.o indent.o parse.o io.o
-
-indent: ${OBJ}
-	$(CC) -o indent -i ${OBJ}
-	install -S 32kw $@
-
-install:	/usr/bin/indent
-
-/usr/bin/indent:	indent
-	install -cs -o bin indent $@
-
-$(OBJ): globs.h codes.h
-
-clean:
-	rm -f *.bak *.o core indent
Index: trunk/minix/commands/indent/args.c
===================================================================
--- trunk/minix/commands/indent/args.c	(revision 9)
+++ 	(revision )
@@ -1,287 +1,0 @@
-/**
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
- * Copyright (c) 1976 Board of Trustees of the University of Illinois.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley, the University of Illinois,
- * Urbana, and Sun Microsystems, Inc.  The name of either University
- * or Sun Microsystems 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 WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-/*
- * Argument scanning and profile reading code.  Default parameters are set
- * here as well.
- */
-
-#define PUBLIC extern
-#include <sys/types.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-#include "globs.h"
-#include "proto.h"
-
-/* profile types */
-#define	PRO_SPECIAL	1		/* special case */
-#define	PRO_BOOL	2		/* boolean */
-#define	PRO_INT		3		/* integer */
-#define PRO_FONT	4		/* troff font */
-
-/* profile specials for booleans */
-#define	ON		1		/* turn it on */
-#define	OFF		0		/* turn it off */
-
-/* profile specials for specials */
-#define	IGN		1		/* ignore it */
-#define	CLI		2		/* case label indent (float) */
-#define	STDIN		3		/* use stdin */
-#define	KEY		4		/* type (keyword) */
-
-/*
- * N.B.: because of the way the table here is scanned, options whose names
- * are substrings of other options must occur later; that is, with -lp vs -l,
- * -lp must be first.  Also, while (most) booleans occur more than once, the
- * last default value is the one actually assigned.
- */
-struct pro
-{
-   char           *p_name;		/* name, eg -bl, -cli */
-   int             p_type;		/* type (int, bool, special) */
-   int             p_default;		/* the default value (if int) */
-   int             p_special;		/* depends on type */
-   int            *p_obj;		/* the associated variable */
-}               pro[] =
-
-{
-
-   "T", PRO_SPECIAL, 0, KEY, 0,
-   "bacc", PRO_BOOL, false, ON, &bl_around,
-   "badp", PRO_BOOL, false, ON, &bl_at_proctop,
-   "bad", PRO_BOOL, false, ON, &bl_aft_decl,
-   "bap", PRO_BOOL, false, ON, &bl_a_procs,
-   "bbb", PRO_BOOL, false, ON, &bl_bef_bk,
-   "bc", PRO_BOOL, true, OFF, &ps.leave_comma,
-   "bl", PRO_BOOL, true, OFF, &btype_2,
-   "br", PRO_BOOL, true, ON, &btype_2,
-   "bs", PRO_BOOL, false, ON, &Bill_Shannon,
-   "cdb", PRO_BOOL, true, ON, &del_on_bl,
-   "cd", PRO_INT, 0, 0, &ps.decl_com_ind,
-   "ce", PRO_BOOL, true, ON, &cuddle_else,
-   "ci", PRO_INT, 0, 0, &continuation_indent,
-   "cli", PRO_SPECIAL, 0, CLI, 0,
-   "c", PRO_INT, 33, 0, &ps.com_ind,
-   "di", PRO_INT, 16, 0, &ps.decl_indent,
-   "dj", PRO_BOOL, false, ON, &ps.ljust_decl,
-   "d", PRO_INT, 0, 0, &ps.unindent_displace,
-   "eei", PRO_BOOL, false, ON, &ex_expr_indent,
-   "ei", PRO_BOOL, true, ON, &ps.else_if,
-   "fbc", PRO_FONT, 0, 0, (int *) &blkcomf,
-   "fbx", PRO_FONT, 0, 0, (int *) &boxcomf,
-   "fb", PRO_FONT, 0, 0, (int *) &bodyf,
-   "fc1", PRO_BOOL, true, ON, &format_col1_comments,
-   "fc", PRO_FONT, 0, 0, (int *) &scomf,
-   "fk", PRO_FONT, 0, 0, (int *) &keywordf,
-   "fs", PRO_FONT, 0, 0, (int *) &stringf,
-   "ip", PRO_BOOL, true, ON, &ps.indent_parameters,
-   "i", PRO_INT, 8, 0, &ps.ind_size,
-   "lc", PRO_INT, 0, 0, &bk_max_col,
-   "lp", PRO_BOOL, true, ON, &lineup_to_parens,
-   "l", PRO_INT, 78, 0, &max_col,
-   "nbacc", PRO_BOOL, false, OFF, &bl_around,
-   "nbadp", PRO_BOOL, false, OFF, &bl_at_proctop,
-   "nbad", PRO_BOOL, false, OFF, &bl_aft_decl,
-   "nbap", PRO_BOOL, false, OFF, &bl_a_procs,
-   "nbbb", PRO_BOOL, false, OFF, &bl_bef_bk,
-   "nbc", PRO_BOOL, true, ON, &ps.leave_comma,
-   "nbs", PRO_BOOL, false, OFF, &Bill_Shannon,
-   "ncdb", PRO_BOOL, true, OFF, &del_on_bl,
-   "nce", PRO_BOOL, true, OFF, &cuddle_else,
-   "ndj", PRO_BOOL, false, OFF, &ps.ljust_decl,
-   "neei", PRO_BOOL, false, OFF, &ex_expr_indent,
-   "nei", PRO_BOOL, true, OFF, &ps.else_if,
-   "nfc1", PRO_BOOL, true, OFF, &format_col1_comments,
-   "nip", PRO_BOOL, true, OFF, &ps.indent_parameters,
-   "nlp", PRO_BOOL, true, OFF, &lineup_to_parens,
-   "npcs", PRO_BOOL, false, OFF, &proc_calls_space,
-   "npro", PRO_SPECIAL, 0, IGN, 0,
-   "npsl", PRO_BOOL, true, OFF, &proc_str_line,
-   "nps", PRO_BOOL, false, OFF, &ptr_binop,
-   "nsc", PRO_BOOL, true, OFF, &star_comment_cont,
-   "nsob", PRO_BOOL, false, OFF, &swallow_opt_bl,
-   "nv", PRO_BOOL, false, OFF, &verbose,
-   "pcs", PRO_BOOL, false, ON, &proc_calls_space,
-   "psl", PRO_BOOL, true, ON, &proc_str_line,
-   "ps", PRO_BOOL, false, ON, &ptr_binop,
-   "sc", PRO_BOOL, true, ON, &star_comment_cont,
-   "sob", PRO_BOOL, false, ON, &swallow_opt_bl,
-   "st", PRO_SPECIAL, 0, STDIN, 0,
-   "troff", PRO_BOOL, false, ON, &troff,
-   "v", PRO_BOOL, false, ON, &verbose,
-   /* whew! */
-   0, 0, 0, 0, 0
-};
-
-/*
- * set_profile reads $HOME/.indent.pro and ./.indent.pro and handles
- * arguments given in these files.
- */
-void set_profile()
-{
-   register FILE  *f;
-   char            fname[BUFSIZ];
-   static char     prof[] = ".indent.pro";
-
-   sprintf(fname, "%s/%s", getenv("HOME"), prof);
-   if ((f = fopen(fname, "r")) != NULL)
-   {
-      scan_profile(f);
-      (void) fclose(f);
-   }
-   if ((f = fopen(prof, "r")) != NULL)
-   {
-      scan_profile(f);
-      (void) fclose(f);
-   }
-}
-
-void scan_profile(f)
-   register FILE  *f;
-{
-   register int    i;
-   register char  *p;
-   char            buf[BUFSIZ];
-
-   while (1)
-   {
-      for (p = buf; (i = getc(f)) != EOF && (*p = (char)i) > ' '; ++p);
-      if (p != buf)
-      {
-	 *p++ = 0;
-	 if (verbose)
-	    printf("profile: %s\n", buf);
-	 set_option(buf);
-      } else if (i == EOF)
-	 return;
-   }
-}
-
-char           *param_start;
-
-int eqin(s1, s2)
-   register char  *s1;
-   register char  *s2;
-{
-   while (*s1)
-   {
-      if (*s1++ != *s2++)
-	 return (false);
-   }
-   param_start = s2;
-   return (true);
-}
-
-/*
- * Set the defaults.
- */
-void set_defaults()
-{
-   register struct pro *p;
-
-   /* Because ps.case_indent is a float, we can't initialize it from
-      the table: */
-   ps.case_indent = 0;			/* -cli0.0 */
-   for (p = pro; p->p_name; p++)
-      if (p->p_type != PRO_SPECIAL && p->p_type != PRO_FONT)
-	 *p->p_obj = p->p_default;
-}
-
-void set_option(arg)
-   register char  *arg;
-{
-   register struct pro *p;
-
-   arg++;				/* ignore leading "-" */
-   for (p = pro; p->p_name; p++)
-      if (*p->p_name == *arg && eqin(p->p_name, arg))
-	 goto found;
-   fprintf(stderr, "indent: unknown parameter \"%s\"\n", arg - 1);
-   exit(1);
-found:
-   switch (p->p_type)
-   {
-
-   case PRO_SPECIAL:
-      switch (p->p_special)
-      {
-
-      case IGN:
-	 break;
-
-      case CLI:
-	 if (*param_start == 0)
-	    goto need_param;
-	 ps.case_indent = atoi(param_start);
-	 break;
-
-      case STDIN:
-	 if (input == 0)
-	    input = stdin;
-	 if (output == 0)
-	    output = stdout;
-	 break;
-
-      case KEY:
-	 if (*param_start == 0)
-	    goto need_param;
-	 {
-	    register char  *str = (char *) malloc(strlen(param_start) + 1);
-	    strcpy(str, param_start);
-	    addkey(str, 4);
-	 }
-	 break;
-
-      default:
-	 fprintf(stderr, "\
-indent: set_option: internal error: p_special %d\n", p->p_special);
-	 exit(1);
-      }
-      break;
-
-   case PRO_BOOL:
-      if (p->p_special == OFF)
-	 *p->p_obj = false;
-      else
-	 *p->p_obj = true;
-      break;
-
-   case PRO_INT:
-      if (*param_start == 0)
-      {
-   need_param:
-	 fprintf(stderr, "indent: ``%s'' requires a parameter\n",
-		 arg - 1);
-	 exit(1);
-      }
-      *p->p_obj = atoi(param_start);
-      break;
-
-   case PRO_FONT:
-      parsefont((struct fstate *) p->p_obj, param_start);
-      break;
-
-   default:
-      fprintf(stderr, "indent: set_option: internal error: p_type %d\n",
-	      p->p_type);
-      exit(1);
-   }
-}
Index: trunk/minix/commands/indent/build
===================================================================
--- trunk/minix/commands/indent/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/indent/codes.h
===================================================================
--- trunk/minix/commands/indent/codes.h	(revision 9)
+++ 	(revision )
@@ -1,54 +1,0 @@
-/**
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
- * Copyright (c) 1976 Board of Trustees of the University of Illinois.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley, the University of Illinois,
- * Urbana, and Sun Microsystems, Inc.  The name of either University
- * or Sun Microsystems 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 WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- * @(#)indent_codes.h	5.6 (Berkeley) 9/15/88
- */
-
-#define newline		1
-#define lparen		2
-#define rparen		3
-#define unary_op	4
-#define binary_op	5
-#define postop		6
-#define question	7
-#define casestmt	8
-#define colon		9
-#define semicolon	10
-#define lbrace		11
-#define rbrace		12
-#define ident		13
-#define comma		14
-#define comment		15
-#define swstmt		16
-#define preesc		17
-#define form_feed	18
-#define decl		19
-#define sp_paren	20
-#define sp_nparen	21
-#define ifstmt		22
-#define whilestmt	23
-#define forstmt		24
-#define stmt		25
-#define stmtl		26
-#define elselit		27
-#define dolit		28
-#define dohead		29
-#define ifhead		30
-#define elsehead	31
-#define period		32
Index: trunk/minix/commands/indent/comment.c
===================================================================
--- trunk/minix/commands/indent/comment.c	(revision 9)
+++ 	(revision )
@@ -1,458 +1,0 @@
-/**
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
- * Copyright (c) 1976 Board of Trustees of the University of Illinois.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley, the University of Illinois,
- * Urbana, and Sun Microsystems, Inc.  The name of either University
- * or Sun Microsystems 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 WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-/*
- * NAME: pr_comment
- *
- * FUNCTION: This routine takes care of scanning and printing comments.
- *
- * ALGORITHM: 1) Decide where the comment should be aligned, and if lines should
- * be broken. 2) If lines should not be broken and filled, just copy up to
- * end of comment. 3) If lines should be filled, then scan thru input_buffer
- * copying characters to com_buf.  Remember where the last blank, tab, or
- * newline was.  When line is filled, print up to last blank and continue
- * copying.
- *
- * HISTORY: November 1976	D A Willcox of CAC	Initial coding 12/6/76
- *  A Willcox of CAC	Modification to handle UNIX-style comments
- *
- */
-
-
-/*
- * this routine processes comments.  It makes an attempt to keep comments
- * from going over the max line length.  If a line is too long, it moves
- * everything from the last blank to the next comment line.  Blanks and tabs
- * from the beginning of the input line are removed
- */
-
-
-#define PUBLIC extern
-#include <stdlib.h>
-#include "globs.h"
-#include "proto.h"
-
-
-void pr_comment()
-{
-   int             now_col;		/* column we are in now */
-
-   int             adj_max_col;		/* Adjusted max_col for when we
-					 * decide to spill comments
-					 *  over the right margin
-					 */
-
-   char           *last_bl;		/* points to the last blank in
-					 * the output buffer 
-					 */
-
-   char           *t_ptr;		/* used for moving string */
-
-   int             unix_comment;	/* tri-state variable used to
-					 * decide if it is a unix-style
-					 * comment. 0 means only blanks
-					 * since / *, 1 means regular
-					 * style comment, 2 means unix
-					 * style comment 
-					 */
-
-   int             break_delim = del_on_bl;
-   int             l_just_saw_decl = ps.just_saw_decl;
-   /* int         ps.last_nl = 0; */	/* true iff the last
-				      	   sig thing we have seen is a nl */
-
-   int             one_liner = 1;	/* true iff this comment is a
-					   one-liner */
-   adj_max_col = max_col;
-   ps.just_saw_decl = 0;
-   last_bl = 0;				/* no blanks found so far */
-   ps.box_com = false;			/* at first, assume that we are
-					   not in a boxed comment or
-					   some other comment that
-					   should not be touched */
-   ++ps.out_coms;			/* keep track of number of
-					   comments */
-   unix_comment = 1;			/* set flag to let us figure
-					   out if there is a unix-style
-					   comment ** DISABLED: use 0
-					   to reenable this hack! */
-
-   /* Figure where to align and how to treat the comment */
-
-   if (ps.col_1 && !format_col1_comments)
-   {					/* if comment starts in column
-					   1 it should not be touched */
-      ps.box_com = true;
-      ps.com_col = 1;
-   } else
-   {
-      if (*buf_ptr == '-' || *buf_ptr == '*')
-      {
-	 ps.box_com = true;		/* a comment with a '-' or '*'
-					   immediately after the / * is
-					   assumed to be a boxed
-					   comment */
-	 break_delim = 0;
-      }
-      if ( /* ps.bl_line && */ (s_lab == e_lab) && (s_code == e_code))
-      {
-	 /* klg: check only if this line is blank */
-	 /* If this (*and previous lines are*) blank, dont put comment
-	    way out at left */
-	 ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1;
-	 adj_max_col = bk_max_col;
-	 if (ps.com_col <= 1)
-	    ps.com_col = 1 + !format_col1_comments;
-      } else
-      {
-	 register        target_col;
-	 break_delim = 0;
-	 if (s_code != e_code)
-	    target_col = count_spaces(code_target(), s_code);
-	 else
-	 {
-	    target_col = 1;
-	    if (s_lab != e_lab)
-	       target_col = count_spaces(label_target(), s_lab);
-	 }
-	 ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? ps.decl_com_ind : ps.com_ind;
-	 if (ps.com_col < target_col)
-	    ps.com_col = ((target_col + 7) & ~7) + 1;
-	 if (ps.com_col + 24 > adj_max_col)
-	    adj_max_col = ps.com_col + 24;
-      }
-   }
-   if (ps.box_com)
-   {
-      buf_ptr[-2] = 0;
-      ps.n_comment_delta = 1 - count_spaces(1, in_buffer);
-      buf_ptr[-2] = '/';
-   } else
-   {
-      ps.n_comment_delta = 0;
-      while (*buf_ptr == ' ' || *buf_ptr == '\t')
-	 buf_ptr++;
-   }
-   ps.comment_delta = 0;
-   *e_com++ = '/';			/* put '/ *' into buffer */
-   *e_com++ = '*';
-   if (*buf_ptr != ' ' && !ps.box_com)
-      *e_com++ = ' ';
-
-   *e_com = '\0';
-   if (troff)
-   {
-      now_col = 1;
-      adj_max_col = 80;
-   } else
-      now_col = count_spaces(ps.com_col, s_com);	/* figure what column we
-							   would be in if we
-							   printed the comment
-							   now */
-
-   /* Start to copy the comment */
-
-   while (1)
-   {					/* this loop will go until the
-					   comment is copied */
-      if (*buf_ptr > 040 && *buf_ptr != '*')
-	 ps.last_nl = 0;
-      if (e_com >= l_com)
-      {
-	 register        nsize = l_com - s_com + 400;
-	 combuf = (char *) realloc(combuf, nsize);
-	 e_com = combuf + (e_com - s_com) + 1;
-	 l_com = combuf + nsize - 5;
-	 s_com = combuf + 1;
-      }
-      switch (*buf_ptr)
-      {					/* this checks for various spcl
-					   cases */
-      case 014:			/* check for a form feed */
-	 if (!ps.box_com)
-	 {				/* in a text comment, break the
-					   line here */
-	    ps.use_ff = true;
-	    /* fix so dump_line uses a form feed */
-	    dump_line();
-	    last_bl = 0;
-	    *e_com++ = ' ';
-	    *e_com++ = '*';
-	    *e_com++ = ' ';
-	    while (*++buf_ptr == ' ' || *buf_ptr == '\t');
-	 } else
-	 {
-	    if (++buf_ptr >= buf_end)
-	       fill_buffer();
-	    *e_com++ = 014;
-	 }
-	 break;
-
-      case '\n':
-	 if (had_eof)
-	 {				/* check for unexpected eof */
-	    printf("Unterminated comment\n");
-	    *e_com = '\0';
-	    dump_line();
-	    return;
-	 }
-	 one_liner = 0;
-	 if (ps.box_com || ps.last_nl)
-	 {				/* if this is a boxed comment,
-					   we dont ignore the newline */
-	    if (s_com == e_com)
-	    {
-	       *e_com++ = ' ';
-	       *e_com++ = ' ';
-	    }
-	    *e_com = '\0';
-	    if (!ps.box_com && e_com - s_com > 3)
-	    {
-	       if (break_delim == 1 && s_com[0] == '/'
-		   && s_com[1] == '*' && s_com[2] == ' ')
-	       {
-		  char           *t = e_com;
-		  break_delim = 2;
-		  e_com = s_com + 2;
-		  *e_com = 0;
-		  if (bl_bef_bk)
-		     prefix_blankline_requested = 1;
-		  dump_line();
-		  e_com = t;
-		  s_com[0] = s_com[1] = s_com[2] = ' ';
-	       }
-	       dump_line();
-	       if (e_com >= l_com)
-	       {
-		  register        nsize = l_com - s_com + 400;
-		  combuf = (char *) realloc(combuf, nsize);
-		  e_com = combuf + (e_com - s_com) + 1;
-		  l_com = combuf + nsize - 5;
-		  s_com = combuf + 1;
-	       }
-	       *e_com++ = ' ';
-	       *e_com++ = ' ';
-	    }
-	    dump_line();
-	    now_col = ps.com_col;
-	 } else
-	 {
-	    ps.last_nl = 1;
-	    if (unix_comment != 1)
-	    {				/* we not are in unix_style
-					   comment */
-	       if (unix_comment == 0 && s_code == e_code)
-	       {
-		  /* if it is a UNIX-style comment, ignore the
-		     requirement that previous line be blank for
-		     unindention */
-		  ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1;
-		  if (ps.com_col <= 1)
-		     ps.com_col = 2;
-	       }
-	       unix_comment = 2;	/* permanently remember that we
-					   are in this type of comment */
-	       dump_line();
-	       ++line_no;
-	       now_col = ps.com_col;
-	       *e_com++ = ' ';
-	       /* fix so that the star at the start of the line will
-	          line up */
-	       do			/* flush leading white space */
-		  if (++buf_ptr >= buf_end)
-		     fill_buffer();
-	       while (*buf_ptr == ' ' || *buf_ptr == '\t');
-	       break;
-	    }
-	    if (*(e_com - 1) == ' ' || *(e_com - 1) == '\t')
-	       last_bl = e_com - 1;
-	    /* if there was a space at the end of the last line,
-	       remember where it was */
-	    else
-	    {				/* otherwise, insert one */
-	       last_bl = e_com;
-	       *e_com++ = ' ';
-	       if (e_com >= l_com)
-	       {
-		  register        nsize = l_com - s_com + 400;
-		  combuf = (char *) realloc(combuf, nsize);
-		  e_com = combuf + (e_com - s_com) + 1;
-		  l_com = combuf + nsize - 5;
-		  s_com = combuf + 1;
-	       }
-	       ++now_col;
-	    }
-	 }
-	 ++line_no;			/* keep track of input line
-					   number */
-	 if (!ps.box_com)
-	 {
-	    int             nstar = 1;
-	    do
-	    {				/* flush any blanks and/or tabs
-					   at start of next line */
-	       if (++buf_ptr >= buf_end)
-		  fill_buffer();
-	       if (*buf_ptr == '*' && --nstar >= 0)
-	       {
-		  if (++buf_ptr >= buf_end)
-		     fill_buffer();
-		  if (*buf_ptr == '/')
-		     goto end_of_comment;
-	       }
-	    } while (*buf_ptr == ' ' || *buf_ptr == '\t');
-	 } else if (++buf_ptr >= buf_end)
-	    fill_buffer();
-	 break;				/* end of case for newline */
-
-      case '*':			/* must check for possibility
-					   of being at end of comment */
-	 if (++buf_ptr >= buf_end)	/* get to next char after * */
-	    fill_buffer();
-
-	 if (unix_comment == 0)		/* set flag to show we are not
-					   in unix-style comment */
-	    unix_comment = 1;
-
-	 if (*buf_ptr == '/')
-	 {				/* it is the end!!! */
-      end_of_comment:
-	    if (++buf_ptr >= buf_end)
-	       fill_buffer();
-
-	    if (*(e_com - 1) != ' ' && !ps.box_com)
-	    {				/* insure blank before end */
-	       *e_com++ = ' ';
-	       ++now_col;
-	    }
-	    if (break_delim == 1 && !one_liner && s_com[0] == '/'
-		&& s_com[1] == '*' && s_com[2] == ' ')
-	    {
-	       char           *t = e_com;
-	       break_delim = 2;
-	       e_com = s_com + 2;
-	       *e_com = 0;
-	       if (bl_bef_bk)
-		  prefix_blankline_requested = 1;
-	       dump_line();
-	       e_com = t;
-	       s_com[0] = s_com[1] = s_com[2] = ' ';
-	    }
-	    if (break_delim == 2 && e_com > s_com + 3
-		 /* now_col > adj_max_col - 2 && !ps.box_com */ )
-	    {
-	       *e_com = '\0';
-	       dump_line();
-	       now_col = ps.com_col;
-	    }
-	    if (e_com >= l_com)
-	    {
-	       register        nsize = l_com - s_com + 400;
-	       combuf = (char *) realloc(combuf, nsize);
-	       e_com = combuf + (e_com - s_com) + 1;
-	       l_com = combuf + nsize - 5;
-	       s_com = combuf + 1;
-	    }
-	    *e_com++ = '*';
-	    *e_com++ = '/';
-	    *e_com = '\0';
-	    ps.just_saw_decl = l_just_saw_decl;
-	    return;
-	 } else
-	 {				/* handle isolated '*' */
-	    *e_com++ = '*';
-	    ++now_col;
-	 }
-	 break;
-      default:				/* we have a random char */
-	 if (unix_comment == 0 && *buf_ptr != ' ' && *buf_ptr != '\t')
-	    unix_comment = 1;		/* we are not in unix-style
-					   comment */
-
-	 *e_com = *buf_ptr++;
-	 if (buf_ptr >= buf_end)
-	    fill_buffer();
-
-	 if (*e_com == '\t')		/* keep track of column */
-	    now_col = ((now_col - 1) & tabmask) + tabsize + 1;
-	 else if (*e_com == '\b')	/* this is a backspace */
-	    --now_col;
-	 else
-	    ++now_col;
-
-	 if (*e_com == ' ' || *e_com == '\t')
-	    last_bl = e_com;
-	 /* remember we saw a blank */
-
-	 ++e_com;
-	 if (now_col > adj_max_col && !ps.box_com && unix_comment == 1 && e_com[-1] > ' ')
-	 {
-	    /* the comment is too long, it must be broken up */
-	    if (break_delim == 1 && s_com[0] == '/'
-		&& s_com[1] == '*' && s_com[2] == ' ')
-	    {
-	       char           *t = e_com;
-	       break_delim = 2;
-	       e_com = s_com + 2;
-	       *e_com = 0;
-	       if (bl_bef_bk)
-		  prefix_blankline_requested = 1;
-	       dump_line();
-	       e_com = t;
-	       s_com[0] = s_com[1] = s_com[2] = ' ';
-	    }
-	    if (last_bl == 0)
-	    {				/* we have seen no blanks */
-	       last_bl = e_com;		/* fake it */
-	       *e_com++ = ' ';
-	    }
-	    *e_com = '\0';		/* print what we have */
-	    *last_bl = '\0';
-	    while (last_bl > s_com && last_bl[-1] < 040)
-	       *--last_bl = 0;
-	    e_com = last_bl;
-	    dump_line();
-
-	    *e_com++ = ' ';		/* add blanks for continuation */
-	    *e_com++ = ' ';
-	    *e_com++ = ' ';
-
-	    t_ptr = last_bl + 1;
-	    last_bl = 0;
-	    if (t_ptr >= e_com)
-	    {
-	       while (*t_ptr == ' ' || *t_ptr == '\t')
-		  t_ptr++;
-	       while (*t_ptr != '\0')
-	       {			/* move unprinted part of
-					   comment down in buffer */
-		  if (*t_ptr == ' ' || *t_ptr == '\t')
-		     last_bl = e_com;
-		  *e_com++ = *t_ptr++;
-	       }
-	    }
-	    *e_com = '\0';
-	    now_col = count_spaces(ps.com_col, s_com);	/* recompute current
-							   position */
-	 }
-	 break;
-      }
-   }
-}
Index: trunk/minix/commands/indent/globs.h
===================================================================
--- trunk/minix/commands/indent/globs.h	(revision 9)
+++ 	(revision )
@@ -1,308 +1,0 @@
-/**
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
- * Copyright (c) 1976 Board of Trustees of the University of Illinois.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley, the University of Illinois,
- * Urbana, and Sun Microsystems, Inc.  The name of either University
- * or Sun Microsystems 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 WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- * @(#)indent_globs.h	5.7 (Berkeley) 9/15/88
- */
-
-#include <stdio.h>
-
-#define BACKSLASH '\\'
-#define bufsize 200			/* size of internal buffers */
-#define inp_bufs 600			/* size of input buffer */
-#define sc_size 5000			/* size of save_com buffer */
-#define label_offset 2			/* number of levels a label is
-					   placed to left of code */
-
-#define tabsize 8			/* the size of a tab */
-#define tabmask 0177770			/* mask used when figuring
-					   length of lines with tabs */
-
-
-#define false 0
-#define true  !false
-
-
-PUBLIC FILE    *input;			/* the fid for the input file */
-PUBLIC FILE    *output;			/* the output file */
-
-PUBLIC char    *labbuf;			/* buffer for label */
-PUBLIC char    *s_lab;			/* start ... */
-PUBLIC char    *e_lab;			/* .. and end of stored label */
-PUBLIC char    *l_lab;			/* limit of label buffer */
-
-PUBLIC char    *codebuf;		/* buffer for code section */
-PUBLIC char    *s_code;			/* start ... */
-PUBLIC char    *e_code;			/* .. and end of stored code */
-PUBLIC char    *l_code;			/* limit of code section */
-
-PUBLIC char    *combuf;			/* buffer for comments */
-PUBLIC char    *s_com;			/* start ... */
-PUBLIC char    *e_com;			/* ... and end of stored
-					   comments */
-PUBLIC char    *l_com;			/* limit of comment buffer */
-
-PUBLIC char     in_buffer[inp_bufs];	/* input buffer */
-PUBLIC char    *buf_ptr;		/* ptr to next character to be
-					   taken from in_buffer */
-PUBLIC char    *buf_end;		/* ptr to first after last char
-					   in in_buffer */
-
-PUBLIC char     save_com[sc_size];	/* input text is saved here
-					   when looking for the brace
-					   after an if, while, etc */
-PUBLIC char    *sc_end;			/* pointer into save_com buffer */
-
-PUBLIC char    *bp_save;		/* saved value of buf_ptr when
-					   taking input from save_com */
-PUBLIC char    *be_save;		/* similarly saved value of
-					   buf_end */
-
-PUBLIC char     token[bufsize];		/* the last token scanned */
-
-
-PUBLIC int      ptr_binop;		/* pointer as binop */
-PUBLIC int      bl_aft_decl;		/* blanklines after
-					   declarations */
-PUBLIC int      bl_bef_bk;		/* blanklines before
-					   blockcomments */
-PUBLIC int      bl_a_procs;		/* blanklines after procs */
-PUBLIC int      bl_around;		/* blanklines around
-					   conditional compilation */
-PUBLIC int      swallow_opt_bl;		/* swallow optional blanklines */
-PUBLIC int      n_real_blanklines;
-PUBLIC int      prefix_blankline_requested;
-PUBLIC int      postfix_blankline_requested;
-PUBLIC int      break_comma;		/* when true and not in parens,
-					   break after a comma */
-PUBLIC int      btype_2;		/* when true, brace should be
-					   on same line as if, while,
-					   etc */
-PUBLIC long     case_ind;		/* indentation level to be used
-					   for a "case n:" */
-PUBLIC int      code_lines;		/* count of lines with code */
-PUBLIC int      had_eof;		/* set to true when input is
-					   exhausted */
-PUBLIC int      line_no;		/* the current line number. */
-PUBLIC int      max_col;		/* the maximum allowable line
-					   length */
-PUBLIC int      verbose;		/* when true, non-essential
-					   error messages are printed */
-PUBLIC int      cuddle_else;		/* true if else should cuddle
-					   up to '}' */
-PUBLIC int      star_comment_cont;	/* true iff comment
-					   continuation lines should
-					   have stars at the beginning
-					   of each line. */
-PUBLIC int      del_on_bl;		/* comment_delimiter_on_blanklin
-					    e */
-PUBLIC int      troff;			/* true iff were generating
-					   troff input */
-PUBLIC int      proc_str_line;		/* if true, the names of
-					   procedures being defined get
-					   placed in column 1 (ie. a
-					   newline is placed between
-					   the type of the procedure
-					   and its name) */
-PUBLIC int      proc_calls_space;	/* If true, procedure calls
-					   look like: foo(bar) rather
-					   than foo (bar) */
-PUBLIC int      format_col1_comments;	/* If comments which start in
-					   column 1 are to be magically
-					   reformatted (just like
-					   comments that begin in later
-					   columns) */
-PUBLIC int      inhibit_formatting;	/* true if INDENT OFF is in
-					   effect */
-PUBLIC int      suppress_blanklines;	/* set iff following blanklines
-					   should be suppressed */
-PUBLIC int      continuation_indent;	/* set to the indentation
-					   between the edge of code and
-					   continuation lines */
-PUBLIC int      lineup_to_parens;	/* if true, continued code
-					   within parens will be lined
-					   up to the open paren */
-PUBLIC int      Bill_Shannon;		/* true iff a blank should
-					   always be inserted after
-					   sizeof */
-PUBLIC int      bl_at_proctop;		/* This is vaguely similar to
-					   blanklines_after_declarations
-					    except that it only applies
-					   to the first set of
-					   declarations in a procedure
-					   (just after the first '{')
-					   and it causes a blank line
-					   to be generated even if
-					   there are no declarations */
-PUBLIC int      bk_max_col;
-PUBLIC int      ex_expr_indent;		/* True if continuation lines
-					   from the expression part of
-					   "if(e)", "while(e)",
-					   "for(e;e;e)" should be
-					   indented an extra tab stop
-					   so that they don't conflict
-					   with the code that follows */
-
-/* -troff font state information */
-
-struct fstate
-{
-   char            font[4];
-   char            size;
-   int             allcaps;
-};
-
-PUBLIC struct fstate
-                keywordf,		/* keyword font */
-                stringf,		/* string font */
-                boxcomf,		/* Box comment font */
-                blkcomf,		/* Block comment font */
-                scomf,			/* Same line comment font */
-                bodyf;			/* major body font */
-
-
-#define STACKSIZE 150
-
-PUBLIC struct parser_state
-{
-   int             last_token;
-   struct fstate   cfont;		/* Current font */
-   int             p_stack[STACKSIZE];	/* this is the parsers stack */
-   int             il[STACKSIZE];	/* this stack stores
-					   indentation levels */
-   long            cstk[STACKSIZE];	/* used to store case stmt
-					   indentation levels */
-   int             box_com;		/* set to true when we are in a
-					   "boxed" comment. In that
-					   case, the first non-blank
-					   char should be lined up with
-					   the / in / *     */
-   int             comment_delta, n_comment_delta;
-   int             cast_mask;		/* indicates which close parens
-					   close off casts */
-   int             sizeof_mask;		/* indicates which close parens
-					   close off sizeof''s */
-   int             block_init;		/* true iff inside a block
-					   initialization */
-   int             block_init_level;	/* The level of brace nesting
-					   in an initialization */
-   int             last_nl;		/* this is true if the last
-					   thing scanned was a newline */
-   int             in_or_st;		/* Will be true iff there has
-					   been a declarator (e.g. int
-					   or char) and no left paren
-					   since the last semicolon.
-					   When true, a '{' is starting
-					   a structure definition or an
-					   initialization list */
-   int             bl_line;		/* set to 1 by dump_line if the
-					   line is blank */
-   int             col_1;		/* set to true if the last
-					   token started in column 1 */
-   int             com_col;		/* this is the column in which
-					   the current coment should
-					   start */
-   int             com_ind;		/* the column in which comments
-					   to the right of code should
-					   start */
-   int             com_lines;		/* the number of lines with
-					   comments, set by dump_line */
-   int             dec_nest;		/* current nesting level for
-					   structure or init */
-   int             decl_com_ind;	/* the column in which comments
-					   after declarations should be
-					   put */
-   int             decl_on_line;	/* set to true if this line of
-					   code has part of a
-					   declaration on it */
-   int             i_l_follow;		/* the level to which ind_level
-					   should be set after the
-					   current line is printed */
-   int             in_decl;		/* set to true when we are in a
-					   declaration stmt.  The
-					   processing of braces is then
-					   slightly different */
-   int             in_stmt;		/* set to 1 while in a stmt */
-   int             ind_level;		/* the current indentation
-					   level */
-   int             ind_size;		/* the size of one indentation
-					   level */
-   int             ind_stmt;		/* set to 1 if next line should
-					   have an extra indentation
-					   level because we are in the
-					   middle of a stmt */
-   int             last_u_d;		/* set to true after scanning a
-					   token which forces a
-					   following operator to be
-					   unary */
-   int             leave_comma;		/* if true, never break
-					   declarations after commas */
-   int             ljust_decl;		/* true if declarations should
-					   be left justified */
-   int             out_coms;		/* the number of comments
-					   processed, set by pr_comment */
-   int             out_lines;		/* the number of lines written,
-					   set by dump_line */
-   int             p_l_follow;		/* used to remember how to
-					   indent following statement */
-   int             paren_level;		/* parenthesization level. used
-					   to indent within stmts */
-   short           paren_indents[20];	/* column positions of each
-					   paren */
-   int             pcase;		/* set to 1 if the current line
-					   label is a case.  It is
-					   printed differently from a
-					   regular label */
-   int             search_brace;	/* set to true by parse when it
-					   is necessary to buffer up
-					   all info up to the start of
-					   a stmt after an if, while,
-					   etc */
-   int             unindent_displace;	/* comments not to the right of
-					   code will be placed this
-					   many indentation levels to
-					   the left of code */
-   int             use_ff;		/* set to one if the current
-					   line should be terminated
-					   with a form feed */
-   int             want_blank;		/* set to true when the
-					   following token should be
-					   prefixed by a blank. (Said
-					   prefixing is ignored in some
-					   cases.) */
-   int             else_if;		/* True iff else if pairs
-					   should be handled specially */
-   int             decl_indent;		/* column to indent declared
-					   identifiers to */
-   int             its_a_keyword;
-   int             sizeof_keyword;
-   int             dumped_decl_indent;
-   int            case_indent;		/* The distance to indent case
-					   labels from the switch
-					   statement */
-   int             in_par_decl;
-   int             indent_parameters;
-   int             tos;			/* pointer to top of stack */
-   char            procname[100];	/* The name of the current
-					   procedure */
-   int             just_saw_decl;
-}               ps;
-
-PUBLIC int      ifdef_level;
-PUBLIC struct parser_state state_stack[5];
-PUBLIC struct parser_state match_state[5];
Index: trunk/minix/commands/indent/indent.c
===================================================================
--- trunk/minix/commands/indent/indent.c	(revision 9)
+++ 	(revision )
@@ -1,1374 +1,0 @@
-/**
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
- * Copyright (c) 1976 Board of Trustees of the University of Illinois.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley, the University of Illinois,
- * Urbana, and Sun Microsystems, Inc.  The name of either University
- * or Sun Microsystems 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 WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-/* ported to MINIX by: Robert R. Hall <hall@pnet01.cts.com>  */
-
-#define _POSIX_SOURCE 1
-#define	PUBLIC
-#define NAME_SIZE _POSIX_NAME_MAX
-
-#include <ctype.h>
-#include <string.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <limits.h>
-#include "globs.h"
-#include "codes.h"
-#include "proto.h"
-
-char           *in_name = "Standard Input";	/* will always point to
-						   name of input file */
-char           *out_name = "Standard Output";	/* will always point to
-						   name of output file */
-char            bakfile[60];
-
-void main(argc, argv)
-   int             argc;
-   char          **argv;
-{
-
-   extern int      found_err;		/* flag set in diag() on error */
-   int             dec_ind;		/* current indentation for
-					   declarations */
-   int             di_stack[20];	/* a stack of structure
-					   indentation levels */
-   int             flushed_nl;		/* used when buffering up
-					   comments to remember that a
-					   newline was passed over */
-   int             force_nl;		/* when true, code must be
-					   broken */
-   int             hd_type;		/* used to store type of stmt
-					   for if (...), for (...), etc */
-   register int    i;			/* local loop counter */
-   int             scase;		/* set to true when we see a
-					   case, so we will know what
-					   to do with the following
-					   colon */
-   int             sp_sw;		/* when true, we are in the
-					   expressin of if(...),
-					   while(...), etc. */
-   int             squest;		/* when this is positive, we
-					   have seen a ? without the
-					   matching : in a <c>?<s>:<s>
-					   construct */
-   register char  *t_ptr;		/* used for copying tokens */
-   int             type_code;		/* the type of token, returned
-					   by lexi */
-
-   int             last_else = 0;	/* true iff last keyword was an
-					   else */
-
-
-   /*-----------------------------------------------*\
-    |		      INITIALIZATION		      |
-    \*-----------------------------------------------*/
-
-
-   ps.p_stack[0] = stmt;		/* this is the parser's stack */
-   ps.last_nl = true;			/* this is true if the last
-					   thing scanned was a newline */
-   ps.last_token = semicolon;
-   combuf = (char *) malloc(bufsize);
-   labbuf = (char *) malloc(bufsize);
-   codebuf = (char *) malloc(bufsize);
-   l_com = combuf + bufsize - 5;
-   l_lab = labbuf + bufsize - 5;
-   l_code = codebuf + bufsize - 5;
-   combuf[0] = codebuf[0] = labbuf[0] = ' ';	/* set up code, label,
-						   and comment buffers */
-   combuf[1] = codebuf[1] = labbuf[1] = '\0';
-   ps.else_if = 1;			/* Default else-if special
-					   processing to on */
-   s_lab = e_lab = labbuf + 1;
-   s_code = e_code = codebuf + 1;
-   s_com = e_com = combuf + 1;
-
-   buf_ptr = buf_end = in_buffer;
-   line_no = 1;
-   had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
-   sp_sw = force_nl = false;
-   ps.in_or_st = false;
-   ps.bl_line = true;
-   dec_ind = 0;
-   di_stack[ps.dec_nest = 0] = 0;
-   ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
-
-
-   scase = ps.pcase = false;
-   squest = 0;
-   sc_end = 0;
-   bp_save = 0;
-   be_save = 0;
-
-   output = 0;
-
-
-
-   /*--------------------------------------------------*\
-    |   		COMMAND LINE SCAN		 |
-    \*--------------------------------------------------*/
-
-#ifdef undef
-   max_col = 78;			/* -l78 */
-   lineup_to_parens = 1;		/* -lp */
-   ps.ljust_decl = 0;			/* -ndj */
-   ps.com_ind = 33;			/* -c33 */
-   star_comment_cont = 1;		/* -sc */
-   ps.ind_size = 8;			/* -i8 */
-   verbose = 0;
-   ps.decl_indent = 16;			/* -di16 */
-   ps.indent_parameters = 1;		/* -ip */
-   ps.decl_com_ind = 0;			/* if this is not set to some
-					   positive value by an arg, we
-					   will set this equal to
-					   ps.com_ind */
-   btype_2 = 1;				/* -br */
-   cuddle_else = 1;			/* -ce */
-   ps.unindent_displace = 0;		/* -d0 */
-   ps.case_indent = 0;			/* -cli0 */
-   format_col1_comments = 1;		/* -fc1 */
-   procnames_start_line = 1;		/* -psl */
-   proc_calls_space = 0;		/* -npcs */
-   comment_delimiter_on_blankline = 1;	/* -cdb */
-   ps.leave_comma = 1;			/* -nbc */
-#endif
-
-   for (i = 1; i < argc; ++i)
-      if (strcmp(argv[i], "-npro") == 0)
-	 break;
-   set_defaults();
-   if (i >= argc)
-      set_profile();
-
-   for (i = 1; i < argc; ++i)
-   {
-
-      /* look thru args (if any) for changes to defaults */
-      if (argv[i][0] != '-')
-      {					/* no flag on parameter */
-	 if (input == 0)
-	 {				/* we must have the input file */
-	    in_name = argv[i];		/* remember name of input file */
-	    input = fopen(in_name, "r");
-	    if (input == 0)
-	    {				/* check for open error */
-	       fprintf(stderr, "indent: can't open %s\n", argv[i]);
-	       exit(1);
-	    }
-	    continue;
-	 } else if (output == 0)
-	 {				/* we have the output file */
-	    out_name = argv[i];		/* remember name of output file */
-	    if (strcmp(in_name, out_name) == 0)
-	    {				/* attempt to overwrite the
-					   file */
-	       fprintf(stderr, "indent: input and output files must be different\n");
-	       exit(1);
-	    }
-	    output = fopen(out_name, "w");
-	    if (output == 0)
-	    {				/* check for create error */
-	       fprintf(stderr, "indent: can't create %s\n", argv[i]);
-	       exit(1);
-	    }
-	    continue;
-	 }
-	 fprintf(stderr, "indent: unknown parameter: %s\n", argv[i]);
-	 exit(1);
-      } else
-	 set_option(argv[i]);
-   }					/* end of for */
-   if (input == 0)
-   {
-      fprintf(stderr, "indent: usage: indent file [ outfile ] [ options ]\n");
-      exit(1);
-   }
-   if (output == 0)
-      if (troff)
-	 output = stdout;
-      else
-      {
-	 out_name = in_name;
-	 bakcopy();
-      }
-   if (ps.com_ind <= 1)
-      ps.com_ind = 2;			/* dont put normal comments
-					   before column 2 */
-   if (troff)
-   {
-      if (bodyf.font[0] == 0)
-	 parsefont(&bodyf, "R");
-      if (scomf.font[0] == 0)
-	 parsefont(&scomf, "I");
-      if (blkcomf.font[0] == 0)
-	 blkcomf = scomf, blkcomf.size += 2;
-      if (boxcomf.font[0] == 0)
-	 boxcomf = blkcomf;
-      if (stringf.font[0] == 0)
-	 parsefont(&stringf, "L");
-      if (keywordf.font[0] == 0)
-	 parsefont(&keywordf, "B");
-      writefdef(&bodyf, 'B');
-      writefdef(&scomf, 'C');
-      writefdef(&blkcomf, 'L');
-      writefdef(&boxcomf, 'X');
-      writefdef(&stringf, 'S');
-      writefdef(&keywordf, 'K');
-   }
-   if (bk_max_col <= 0)
-      bk_max_col = max_col;
-   if (ps.decl_com_ind <= 0)		/* if not specified by user,
-					   set this */
-      ps.decl_com_ind = ps.ljust_decl ? (ps.com_ind <= 10 ? 2 : ps.com_ind - 8) : ps.com_ind;
-   if (continuation_indent == 0)
-      continuation_indent = ps.ind_size;
-   fill_buffer();			/* get first batch of stuff
-					   into input buffer */
-
-   parse(semicolon);
-   {
-      register char  *p = buf_ptr;
-      register        col = 1;
-
-      while (1)
-      {
-	 if (*p == ' ')
-	    col++;
-	 else if (*p == '\t')
-	    col = ((col - 1) & ~7) + 9;
-	 else
-	    break;
-	 p++;
-      };
-      if (col > ps.ind_size)
-	 ps.ind_level = ps.i_l_follow = col / ps.ind_size;
-   }
-   if (troff)
-   {
-      register char  *p = in_name, *beg = in_name;
-
-      while (*p)
-	 if (*p++ == '/')
-	    beg = p;
-      fprintf(output, ".Fn \"%s\"\n", beg);
-   }
-   /* START OF MAIN LOOP */
-
-   while (1)
-   {					/* this is the main loop.  it
-					   will go until we reach eof */
-      int             is_procname;
-
-      type_code = lexi();		/* lexi reads one token.  The
-					   actual characters read are
-					   stored in "token". lexi
-					   returns a code indicating
-					   the type of token */
-      is_procname = ps.procname[0];
-
-      /* The following code moves everything following an if (), while
-         (), else, etc. up to the start of the following stmt to a
-         buffer. This allows proper handling of both kinds of brace
-         placement. */
-
-      flushed_nl = false;
-      while (ps.search_brace)
-      {					/* if we scanned an if(),
-					   while(), etc., we might need
-					   to copy stuff into a buffer
-					   we must loop, copying stuff
-					   into save_com, until we find
-					   the start of the stmt which
-					   follows the if, or whatever */
-	 switch (type_code)
-	 {
-	 case newline:
-	    ++line_no;
-	    flushed_nl = true;
-	 case form_feed:
-	    break;			/* form feeds and newlines
-					   found here will be ignored */
-
-	 case lbrace:			/* this is a brace that starts
-					   the compound stmt */
-	    if (sc_end == 0)
-	    {				/* ignore buffering if a
-					   comment wasnt stored up */
-	       ps.search_brace = false;
-	       goto check_type;
-	    }
-	    if (btype_2)
-	    {
-	       save_com[0] = '{';	/* we either want to put the
-					   brace right after the if */
-	       goto sw_buffer;		/* go to common code to get out
-					   of this loop */
-	    }
-/*
- * Something is buffered up in save_com, and -bl processing is in effect.
- * Add the brace after the comment so it will come out on the next line.
- */
-	    flushed_nl = 0;	/* comment can start on the same line */
-	    *sc_end++ = '\n';	/* break line after comment */
-	    *sc_end++ = '{';
-	    goto sw_buffer;
-
-	 case comment:			/* we have a comment, so we
-					   must copy it into the buffer */
-	    if (!flushed_nl || sc_end != 0)
-	    {
-	       if (sc_end == 0)
-	       {			/* if this is the first
-					   comment, we must set up the
-					   buffer */
-		  save_com[0] = save_com[1] = ' ';
-		  sc_end = &(save_com[2]);
-	       } else
-	       {
-		  *sc_end++ = '\n';	/* add newline between comments */
-		  *sc_end++ = ' ';
-		  --line_no;
-	       }
-	       *sc_end++ = '/';		/* copy in start of comment */
-	       *sc_end++ = '*';
-
-	       for (;;)
-	       {			/* loop until we get to the end
-					   of the comment */
-		  *sc_end = *buf_ptr++;
-		  if (buf_ptr >= buf_end)
-		     fill_buffer();
-
-		  if (*sc_end++ == '*' && *buf_ptr == '/')
-		     break;		/* we are at end of comment */
-
-		  if (sc_end >= &(save_com[sc_size]))
-		  {			/* check for temp buffer
-					   overflow */
-		     diag(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever.");
-		     fflush(output);
-		     exit(1);
-		  }
-	       }
-	       *sc_end++ = '/';		/* add ending slash */
-	       if (++buf_ptr >= buf_end)/* get past / in buffer */
-		  fill_buffer();
-	       break;
-	    }
-	 default:			/* it is the start of a normal
-					   statment */
-	    if (flushed_nl)		/* if we flushed a newline,
-					   make sure it is put back */
-	       force_nl = true;
-	    if ((type_code == sp_paren && *token == 'i'
-		    && last_else && ps.else_if)
-		|| (type_code == sp_nparen && *token == 'e'
-		    && e_code != s_code && e_code[-1] == '}'))
-	       force_nl = false;
-
-	    if (sc_end == 0)
-	    {				/* ignore buffering if comment
-					   wasnt saved up */
-	       ps.search_brace = false;
-	       goto check_type;
-	    }
-	    if (force_nl)
-	    {				/* if we should insert a nl
-					   here, put it into the buffer */
-	       force_nl = false;
-	       --line_no;		/* this will be re-increased
-					   when the nl is read from the
-					   buffer */
-	       *sc_end++ = '\n';
-	       *sc_end++ = ' ';
-	       if (verbose && !flushed_nl)	/* print error msg if
-						   the line was not
-						   already broken */
-		  diag(0, "Line broken");
-	       flushed_nl = false;
-	    }
-	    for (t_ptr = token; *t_ptr; ++t_ptr)
-	       *sc_end++ = *t_ptr;	/* copy token into temp buffer */
-	    ps.procname[0] = 0;
-
-      sw_buffer:
-	    ps.search_brace = false;	/* stop looking for start of
-					   stmt */
-	    bp_save = buf_ptr;		/* save current input buffer */
-	    be_save = buf_end;
-	    buf_ptr = save_com;		/* fix so that subsequent calls
-					   to lexi will take tokens out
-					   of save_com */
-	    *sc_end++ = ' ';		/* add trailing blank, just in
-					   case */
-	    buf_end = sc_end;
-	    sc_end = 0;
-	    break;
-	 }				/* end of switch */
-	 if (type_code != 0)		/* we must make this check,
-					   just in case there was an
-					   unexpected EOF */
-	    type_code = lexi();		/* read another token */
-	 /* if (ps.search_brace) ps.procname[0] = 0; */
-	 if ((is_procname = ps.procname[0]) && flushed_nl
-	     && !proc_str_line && ps.in_decl
-	     && type_code == ident)
-	    flushed_nl = 0;
-      }					/* end of while (search_brace) */
-      last_else = 0;
-check_type:
-      if (type_code == 0)
-      {					/* we got eof */
-	 if (s_lab != e_lab || s_code != e_code
-	     || s_com != e_com)		/* must dump end of line */
-	    dump_line();
-	 if (ps.tos > 1)		/* check for balanced braces */
-	    diag(1, "Stuff missing from end of file.");
-
-	 if (verbose)
-	 {
-	    printf("There were %d output lines and %d comments\n",
-		   ps.out_lines, ps.out_coms);
-	    printf("(Lines with comments)/(Lines with code): %6d\n",
-		   ps.com_lines / code_lines);
-	 }
-	 fflush(output);
-	 exit(found_err);
-      }
-      if (
-	  (type_code != comment) &&
-	  (type_code != newline) &&
-	  (type_code != preesc) &&
-	  (type_code != form_feed))
-      {
-	 if (force_nl &&
-	     (type_code != semicolon) &&
-	     (type_code != lbrace || !btype_2))
-	 {
-	    /* we should force a broken line here */
-	    if (verbose && !flushed_nl)
-	       diag(0, "Line broken");
-	    flushed_nl = false;
-	    dump_line();
-	    ps.want_blank = false;	/* dont insert blank at line
-					   start */
-	    force_nl = false;
-	 }
-	 ps.in_stmt = true;		/* turn on flag which causes an
-					   extra level of indentation.
-					   this is turned off by a ; or
-					   '}' */
-	 if (s_com != e_com)
-	 {				/* the turkey has embedded a
-					   comment in a line. fix it */
-	    *e_code++ = ' ';
-	    for (t_ptr = s_com; *t_ptr; ++t_ptr)
-	    {
-	       if (e_code >= l_code)
-	       {
-		  register        nsize = l_code - s_code + 400;
-		  codebuf = (char *) realloc(codebuf, nsize);
-		  e_code = codebuf + (e_code - s_code) + 1;
-		  l_code = codebuf + nsize - 5;
-		  s_code = codebuf + 1;
-	       }
-	       *e_code++ = *t_ptr;
-	    }
-	    *e_code++ = ' ';
-	    *e_code = '\0';		/* null terminate code sect */
-	    ps.want_blank = false;
-	    e_com = s_com;
-	 }
-      } else if (type_code != comment)	/* preserve force_nl thru a
-					   comment */
-	 force_nl = false;		/* cancel forced newline after
-					   newline, form feed, etc */
-
-
-
-      /*-----------------------------------------------------*\
-        |	   do switch on type of token scanned		|
-        \*-----------------------------------------------------*/
-      if (e_code >= l_code)
-      {
-	 register        nsize = l_code - s_code + 400;
-	 codebuf = (char *) realloc(codebuf, nsize);
-	 e_code = codebuf + (e_code - s_code) + 1;
-	 l_code = codebuf + nsize - 5;
-	 s_code = codebuf + 1;
-      }
-      switch (type_code)
-      {					/* now, decide what to do with
-					   the token */
-
-      case form_feed:			/* found a form feed in line */
-	 ps.use_ff = true;		/* a form feed is treated much
-					   like a newline */
-	 dump_line();
-	 ps.want_blank = false;
-	 break;
-
-      case newline:
-	 if (ps.last_token != comma || ps.p_l_follow > 0
-	     || !ps.leave_comma || ps.block_init || !break_comma || s_com != e_com)
-	 {
-	    dump_line();
-	    ps.want_blank = false;
-	 }
-	 ++line_no;			/* keep track of input line
-					   number */
-	 break;
-
-      case lparen:			/* got a '(' or '[' */
-	 ++ps.p_l_follow;		/* count parens to make Healy
-					   happy */
-	 if (ps.want_blank && *token != '[' &&
-	     (ps.last_token != ident || proc_calls_space
-	      || (ps.its_a_keyword && (!ps.sizeof_keyword || Bill_Shannon))))
-	    *e_code++ = ' ';
-	 if (ps.in_decl && !ps.block_init)
-	    if (troff && !ps.dumped_decl_indent && !is_procname && ps.last_token == decl)
-	    {
-	       ps.dumped_decl_indent = 1;
-	       sprintf(e_code, "\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token);
-	       e_code += strlen(e_code);
-	    } else
-	    {
-	       while ((e_code - s_code) < dec_ind)
-	       {
-		  if (e_code >= l_code)
-		  {
-		     register        nsize = l_code - s_code + 400;
-		     codebuf = (char *) realloc(codebuf, nsize);
-		     e_code = codebuf + (e_code - s_code) + 1;
-		     l_code = codebuf + nsize - 5;
-		     s_code = codebuf + 1;
-		  }
-		  *e_code++ = ' ';
-	       }
-	       *e_code++ = token[0];
-	    }
-	 else
-	    *e_code++ = token[0];
-	 ps.paren_indents[ps.p_l_follow - 1] = e_code - s_code;
-	 if (sp_sw && ps.p_l_follow == 1 && ex_expr_indent
-	     && ps.paren_indents[0] < 2 * ps.ind_size)
-	    ps.paren_indents[0] = 2 * ps.ind_size;
-	 ps.want_blank = false;
-	 if (ps.in_or_st && *token == '(' && ps.tos <= 2)
-	 {
-	    /* this is a kluge to make sure that declarations will be
-	       aligned right if proc decl has an explicit type on it,
-	       i.e. "int a(x) {..." */
-	    parse(semicolon);		/* I said this was a kluge... */
-	    ps.in_or_st = false;	/* turn off flag for structure
-					   decl or initialization */
-	 }
-	 if (ps.sizeof_keyword)
-	    ps.sizeof_mask |= 1 << ps.p_l_follow;
-	 break;
-
-      case rparen:			/* got a ')' or ']' */
-	 if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.sizeof_mask)
-	 {
-	    ps.last_u_d = true;
-	    ps.cast_mask &= (1 << ps.p_l_follow) - 1;
-	 }
-	 ps.sizeof_mask &= (1 << ps.p_l_follow) - 1;
-	 if (--ps.p_l_follow < 0)
-	 {
-	    ps.p_l_follow = 0;
-	    diag(0, "Extra %c", *token);
-	 }
-	 if (e_code == s_code)		/* if the paren starts the line */
-	    ps.paren_level = ps.p_l_follow;	/* then indent it */
-
-	 *e_code++ = token[0];
-	 ps.want_blank = true;
-
-	 if (sp_sw && (ps.p_l_follow == 0))
-	 {				/* check for end of if (...),
-					   or some such */
-	    sp_sw = false;
-	    force_nl = true;		/* must force newline after if */
-	    ps.last_u_d = true;		/* inform lexi that a following
-					   operator is unary */
-	    ps.in_stmt = false;		/* dont use stmt continuation
-					   indentation */
-
-	    parse(hd_type);		/* let parser worry about if,
-					   or whatever */
-	 }
-	 ps.search_brace = btype_2;	/* this should insure that
-					   constructs such as
-					   main(){...} and int[]{...}
-					   have their braces put in the
-					   right place */
-	 break;
-
-      case unary_op:			/* this could be any unary
-					   operation */
-	 if (ps.want_blank)
-	    *e_code++ = ' ';
-
-	 if (troff && !ps.dumped_decl_indent && ps.in_decl && !is_procname)
-	 {
-	    sprintf(e_code, "\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token);
-	    ps.dumped_decl_indent = 1;
-	    e_code += strlen(e_code);
-	 } else
-	 {
-	    char           *res = token;
-
-	    if (ps.in_decl && !ps.block_init)
-	    {				/* if this is a unary op in a
-					   declaration, we should
-					   indent this token */
-	       for (i = 0; token[i]; ++i);	/* find length of token */
-	       while ((e_code - s_code) < (dec_ind - i))
-	       {
-		  if (e_code >= l_code)
-		  {
-		     register        nsize = l_code - s_code + 400;
-		     codebuf = (char *) realloc(codebuf, nsize);
-		     e_code = codebuf + (e_code - s_code) + 1;
-		     l_code = codebuf + nsize - 5;
-		     s_code = codebuf + 1;
-		  }
-		  *e_code++ = ' ';	/* pad it */
-	       }
-	    }
-	    if (troff && token[0] == '-' && token[1] == '>')
-	       res = "\\(->";
-	    for (t_ptr = res; *t_ptr; ++t_ptr)
-	    {
-	       if (e_code >= l_code)
-	       {
-		  register        nsize = l_code - s_code + 400;
-		  codebuf = (char *) realloc(codebuf, nsize);
-		  e_code = codebuf + (e_code - s_code) + 1;
-		  l_code = codebuf + nsize - 5;
-		  s_code = codebuf + 1;
-	       }
-	       *e_code++ = *t_ptr;
-	    }
-	 }
-	 ps.want_blank = false;
-	 break;
-
-      case binary_op:			/* any binary operation */
-	 if (ps.want_blank)
-	    *e_code++ = ' ';
-	 {
-	    char           *res = token;
-
-	    if (troff)
-	       switch (token[0])
-	       {
-	       case '<':
-		  if (token[1] == '=')
-		     res = "\\(<=";
-		  break;
-	       case '>':
-		  if (token[1] == '=')
-		     res = "\\(>=";
-		  break;
-	       case '!':
-		  if (token[1] == '=')
-		     res = "\\(!=";
-		  break;
-	       case '|':
-		  if (token[1] == '|')
-		     res = "\\(br\\(br";
-		  else if (token[1] == 0)
-		     res = "\\(br";
-		  break;
-	       }
-	    for (t_ptr = res; *t_ptr; ++t_ptr)
-	    {
-	       if (e_code >= l_code)
-	       {
-		  register        nsize = l_code - s_code + 400;
-		  codebuf = (char *) realloc(codebuf, nsize);
-		  e_code = codebuf + (e_code - s_code) + 1;
-		  l_code = codebuf + nsize - 5;
-		  s_code = codebuf + 1;
-	       }
-	       *e_code++ = *t_ptr;	/* move the operator */
-	    }
-	 }
-	 ps.want_blank = true;
-	 break;
-
-      case postop:			/* got a trailing ++ or -- */
-	 *e_code++ = token[0];
-	 *e_code++ = token[1];
-	 ps.want_blank = true;
-	 break;
-
-      case question:			/* got a ? */
-	 squest++;			/* this will be used when a
-					   later colon appears so we
-					   can distinguish the
-					   <c>?<n>:<n> construct */
-	 if (ps.want_blank)
-	    *e_code++ = ' ';
-	 *e_code++ = '?';
-	 ps.want_blank = true;
-	 break;
-
-      case casestmt:			/* got word 'case' or 'default' */
-	 scase = true;			/* so we can process the later
-					   colon properly */
-	 goto copy_id;
-
-      case colon:			/* got a ':' */
-	 if (squest > 0)
-	 {				/* it is part of the <c>?<n>:
-					   <n> construct */
-	    --squest;
-	    if (ps.want_blank)
-	       *e_code++ = ' ';
-	    *e_code++ = ':';
-	    ps.want_blank = true;
-	    break;
-	 }
-	 if (ps.in_decl)
-	 {
-	    *e_code++ = ':';
-	    ps.want_blank = false;
-	    break;
-	 }
-	 ps.in_stmt = false;		/* seeing a label does not
-					   imply we are in a stmt */
-	 for (t_ptr = s_code; *t_ptr; ++t_ptr)
-	    *e_lab++ = *t_ptr;		/* turn everything so far into
-					   a label */
-	 e_code = s_code;
-	 *e_lab++ = ':';
-	 *e_lab++ = ' ';
-	 *e_lab = '\0';
-
-	 force_nl = ps.pcase = scase;	/* ps.pcase will be used by
-					   dump_line to decide how to
-					   indent the label. force_nl
-					   will force a case n: to be
-					   on a line by itself */
-	 scase = false;
-	 ps.want_blank = false;
-	 break;
-
-      case semicolon:			/* got a ';' */
-	 ps.in_or_st = false;		/* we are not in an
-					   initialization or structure
-					   declaration */
-	 scase = false;			/* these will only need
-					   resetting in a error */
-	 squest = 0;
-	 if (ps.last_token == rparen)
-	    ps.in_par_decl = 0;
-	 ps.cast_mask = 0;
-	 ps.sizeof_mask = 0;
-	 ps.block_init = 0;
-	 ps.block_init_level = 0;
-	 ps.just_saw_decl--;
-
-	 if (ps.in_decl && s_code == e_code && !ps.block_init)
-	    while ((e_code - s_code) < (dec_ind - 1))
-	    {
-	       if (e_code >= l_code)
-	       {
-		  register        nsize = l_code - s_code + 400;
-		  codebuf = (char *) realloc(codebuf, nsize);
-		  e_code = codebuf + (e_code - s_code) + 1;
-		  l_code = codebuf + nsize - 5;
-		  s_code = codebuf + 1;
-	       }
-	       *e_code++ = ' ';
-	    }
-
-	 ps.in_decl = (ps.dec_nest > 0);/* if we were in a first level
-					   structure declaration, we
-					   arent any more */
-
-	 if ((!sp_sw || hd_type != forstmt) && ps.p_l_follow > 0)
-	 {
-
-	    /* This should be true iff there were unbalanced parens in
-	       the stmt.  It is a bit complicated, because the
-	       semicolon might be in a for stmt */
-	    diag(1, "Unbalanced parens");
-	    ps.p_l_follow = 0;
-	    if (sp_sw)
-	    {				/* this is a check for a if,
-					   while, etc. with unbalanced
-					   parens */
-	       sp_sw = false;
-	       parse(hd_type);		/* dont lose the if, or
-					   whatever */
-	    }
-	 }
-	 *e_code++ = ';';
-	 ps.want_blank = true;
-	 ps.in_stmt = (ps.p_l_follow > 0);	/* we are no longer in
-						   the middle of a stmt */
-
-	 if (!sp_sw)
-	 {				/* if not if for (;;) */
-	    parse(semicolon);		/* let parser know about end of
-					   stmt */
-	    force_nl = true;		/* force newline after a end of
-					   stmt */
-	 }
-	 break;
-
-      case lbrace:			/* got a '{' */
-	 ps.in_stmt = false;		/* dont indent the {} */
-	 if (!ps.block_init)
-	    force_nl = true;		/* force other stuff on same
-					   line as '{' onto new line */
-	 else if (ps.block_init_level <= 0)
-	    ps.block_init_level = 1;
-	 else
-	    ps.block_init_level++;
-
-	 if (s_code != e_code && !ps.block_init)
-	 {
-	    if (!btype_2)
-	    {
-	       dump_line();
-	       ps.want_blank = false;
-	    } else if (ps.in_par_decl && !ps.in_or_st)
-	    {
-	       ps.i_l_follow = 0;
-	       dump_line();
-	       ps.want_blank = false;
-	    }
-	 }
-	 if (ps.in_par_decl)
-	    prefix_blankline_requested = 0;
-
-	 if (ps.p_l_follow > 0)
-	 {				/* check for preceeding
-					   unbalanced parens */
-	    diag(1, "Unbalanced parens");
-	    ps.p_l_follow = 0;
-	    if (sp_sw)
-	    {				/* check for unclosed if, for,
-					   etc. */
-	       sp_sw = false;
-	       parse(hd_type);
-	       ps.ind_level = ps.i_l_follow;
-	    }
-	 }
-	 if (s_code == e_code)
-	    ps.ind_stmt = false;	/* dont put extra indentation
-					   on line with '{' */
-	 if (ps.in_decl && ps.in_or_st)
-	 {				/* this is either a structure
-					   declaration or an init */
-	    di_stack[ps.dec_nest++] = dec_ind;
-	    /* ?		dec_ind = 0; */
-	 } else
-	 {
-	    ps.decl_on_line = false;	/* we cant be in the middle of
-					   a declaration, so dont do
-					   special indentation of
-					   comments */
-	    if (bl_at_proctop
-		&& ps.in_par_decl)
-	       postfix_blankline_requested = 1;
-	    ps.in_par_decl = 0;
-	 }
-	 dec_ind = 0;
-	 parse(lbrace);			/* let parser know about this */
-	 if (ps.want_blank)		/* put a blank before '{' if
-					   '{' is not at start of line */
-	    *e_code++ = ' ';
-	 ps.want_blank = false;
-	 *e_code++ = '{';
-	 ps.just_saw_decl = 0;
-	 break;
-
-      case rbrace:			/* got a '}' */
-	 if (ps.p_stack[ps.tos] == decl && !ps.block_init)	/* semicolons can be
-								   omitted in
-								   declarations */
-	    parse(semicolon);
-	 if (ps.p_l_follow)
-	 {				/* check for unclosed if, for,
-					   else. */
-	    diag(1, "Unbalanced parens");
-	    ps.p_l_follow = 0;
-	    sp_sw = false;
-	 }
-	 ps.just_saw_decl = 0;
-	 ps.block_init_level--;
-	 if (s_code != e_code && !ps.block_init)
-	 {				/* '}' must be first on line */
-	    if (verbose)
-	       diag(0, "Line broken");
-	    dump_line();
-	 }
-	 *e_code++ = '}';
-	 ps.want_blank = true;
-	 ps.in_stmt = ps.ind_stmt = false;
-	 if (ps.dec_nest > 0)
-	 {				/* we are in multi-level
-					   structure declaration */
-	    dec_ind = di_stack[--ps.dec_nest];
-	    if (ps.dec_nest == 0 && !ps.in_par_decl)
-	       ps.just_saw_decl = 2;
-	    ps.in_decl = true;
-	 }
-	 prefix_blankline_requested = 0;
-	 parse(rbrace);			/* let parser know about this */
-	 ps.search_brace = cuddle_else && ps.p_stack[ps.tos] == ifhead
-	    && ps.il[ps.tos] >= ps.ind_level;
-	 if (ps.tos <= 1 && bl_a_procs && ps.dec_nest <= 0)
-	    postfix_blankline_requested = 1;
-	 break;
-
-      case swstmt:			/* got keyword "switch" */
-	 sp_sw = true;
-	 hd_type = swstmt;		/* keep this for when we have
-					   seen the expression */
-	 goto copy_id;			/* go move the token into
-					   buffer */
-
-      case sp_paren:			/* token is if, while, for */
-	 sp_sw = true;			/* the interesting stuff is
-					   done after the expression is
-					   scanned */
-	 hd_type = (*token == 'i' ? ifstmt :
-		    (*token == 'w' ? whilestmt : forstmt));
-
-	 /* remember the type of header for later use by parser */
-	 goto copy_id;			/* copy the token into line */
-
-      case sp_nparen:			/* got else, do */
-	 ps.in_stmt = false;
-	 if (*token == 'e')
-	 {
-	    if (e_code != s_code && (!cuddle_else || e_code[-1] != '}'))
-	    {
-	       if (verbose)
-		  diag(0, "Line broken");
-	       dump_line();		/* make sure this starts a line */
-	       ps.want_blank = false;
-	    }
-	    force_nl = true;		/* also, following stuff must
-					   go onto new line */
-	    last_else = 1;
-	    parse(elselit);
-	 } else
-	 {
-	    if (e_code != s_code)
-	    {				/* make sure this starts a line */
-	       if (verbose)
-		  diag(0, "Line broken");
-	       dump_line();
-	       ps.want_blank = false;
-	    }
-	    force_nl = true;		/* also, following stuff must
-					   go onto new line */
-	    last_else = 0;
-	    parse(dolit);
-	 }
-	 goto copy_id;			/* move the token into line */
-
-      case decl:			/* we have a declaration type
-					   (int, register, etc.) */
-	 parse(decl);			/* let parser worry about
-					   indentation */
-	 if (ps.last_token == rparen && ps.tos <= 1)
-	 {
-	    ps.in_par_decl = 1;
-	    if (s_code != e_code)
-	    {
-	       dump_line();
-	       ps.want_blank = 0;
-	    }
-	 }
-	 if (ps.in_par_decl && ps.indent_parameters && ps.dec_nest == 0)
-	 {
-	    ps.ind_level = ps.i_l_follow = 1;
-	    ps.ind_stmt = 0;
-	 }
-	 ps.in_or_st = true;		/* this might be a structure or
-					   initialization declaration */
-	 ps.in_decl = ps.decl_on_line = true;
-	 if ( /* !ps.in_or_st && */ ps.dec_nest <= 0)
-	    ps.just_saw_decl = 2;
-	 prefix_blankline_requested = 0;
-	 for (i = 0; token[i++];);	/* get length of token */
-
-	 /* dec_ind = e_code - s_code + (ps.decl_indent>i ?
-	    ps.decl_indent : i); */
-	 dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
-	 goto copy_id;
-
-      case ident:			/* got an identifier or
-					   constant */
-	 if (ps.in_decl)
-	 {				/* if we are in a declaration,
-					   we must indent identifier */
-	    if (ps.want_blank)
-	       *e_code++ = ' ';
-	    ps.want_blank = false;
-	    if (is_procname == 0 || !proc_str_line)
-	    {
-	       if (!ps.block_init)
-		  if (troff && !ps.dumped_decl_indent)
-		  {
-		     sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
-		     ps.dumped_decl_indent = 1;
-		     e_code += strlen(e_code);
-		  } else
-		     while ((e_code - s_code) < dec_ind)
-		     {
-			if (e_code >= l_code)
-			{
-			   register        nsize = l_code - s_code + 400;
-			   codebuf = (char *) realloc(codebuf, nsize);
-			   e_code = codebuf + (e_code - s_code) + 1;
-			   l_code = codebuf + nsize - 5;
-			   s_code = codebuf + 1;
-			}
-			*e_code++ = ' ';
-		     }
-	    } else
-	    {
-	       if (dec_ind && s_code != e_code)
-		  dump_line();
-	       dec_ind = 0;
-	       ps.want_blank = false;
-	    }
-	 } else if (sp_sw && ps.p_l_follow == 0)
-	 {
-	    sp_sw = false;
-	    force_nl = true;
-	    ps.last_u_d = true;
-	    ps.in_stmt = false;
-	    parse(hd_type);
-	 }
-   copy_id:
-	 if (ps.want_blank)
-	    *e_code++ = ' ';
-	 if (troff && ps.its_a_keyword)
-	 {
-	    e_code = chfont(&bodyf, &keywordf, e_code);
-	    for (t_ptr = token; *t_ptr; ++t_ptr)
-	    {
-	       if (e_code >= l_code)
-	       {
-		  register        nsize = l_code - s_code + 400;
-		  codebuf = (char *) realloc(codebuf, nsize);
-		  e_code = codebuf + (e_code - s_code) + 1;
-		  l_code = codebuf + nsize - 5;
-		  s_code = codebuf + 1;
-	       }
-	       *e_code++ = keywordf.allcaps && islower(*t_ptr)
-		  ? toupper(*t_ptr) : *t_ptr;
-	    }
-	    e_code = chfont(&keywordf, &bodyf, e_code);
-	 } else
-	    for (t_ptr = token; *t_ptr; ++t_ptr)
-	    {
-	       if (e_code >= l_code)
-	       {
-		  register        nsize = l_code - s_code + 400;
-		  codebuf = (char *) realloc(codebuf, nsize);
-		  e_code = codebuf + (e_code - s_code) + 1;
-		  l_code = codebuf + nsize - 5;
-		  s_code = codebuf + 1;
-	       }
-	       *e_code++ = *t_ptr;
-	    }
-	 ps.want_blank = true;
-	 break;
-
-      case period:			/* treat a period kind of like
-					   a binary operation */
-	 *e_code++ = '.';		/* move the period into line */
-	 ps.want_blank = false;		/* dont put a blank after a
-					   period */
-	 break;
-
-      case comma:
-	 ps.want_blank = (s_code != e_code);	/* only put blank after
-						   comma if comma does
-						   not start the line */
-	 if (ps.in_decl && is_procname == 0 && !ps.block_init)
-	    while ((e_code - s_code) < (dec_ind - 1))
-	    {
-	       if (e_code >= l_code)
-	       {
-		  register        nsize = l_code - s_code + 400;
-		  codebuf = (char *) realloc(codebuf, nsize);
-		  e_code = codebuf + (e_code - s_code) + 1;
-		  l_code = codebuf + nsize - 5;
-		  s_code = codebuf + 1;
-	       }
-	       *e_code++ = ' ';
-	    }
-
-	 *e_code++ = ',';
-	 if (ps.p_l_follow == 0)
-	 {
-	    if (ps.block_init_level <= 0)
-	       ps.block_init = 0;
-	    if (break_comma && !ps.leave_comma)
-	       force_nl = true;
-	 }
-	 break;
-
-      case preesc:			/* got the character '#' */
-	 if ((s_com != e_com) ||
-	     (s_lab != e_lab) ||
-	     (s_code != e_code))
-	    dump_line();
-	 *e_lab++ = '#';		/* move whole line to 'label'
-					   buffer */
-	 {
-	    int             in_comment = 0;
-	    int             com_start = 0;
-	    char            quote = 0;
-	    int             com_end = 0;
-
-	    while (*buf_ptr != '\n' || in_comment)
-	    {
-	       if (e_lab >= l_lab)
-	       {
-		  register        nsize = l_lab - s_lab + 400;
-		  labbuf = (char *) realloc(labbuf, nsize);
-		  e_lab = labbuf + (e_lab - s_lab) + 1;
-		  l_lab = labbuf + nsize - 5;
-		  s_lab = labbuf + 1;
-	       }
-	       *e_lab = *buf_ptr++;
-	       if (buf_ptr >= buf_end)
-		  fill_buffer();
-	       switch (*e_lab++)
-	       {
-	       case BACKSLASH:
-		  if (troff)
-		     *e_lab++ = BACKSLASH;
-		  if (!in_comment)
-		  {
-		     *e_lab++ = *buf_ptr++;
-		     if (buf_ptr >= buf_end)
-			fill_buffer();
-		  }
-		  break;
-	       case '/':
-		  if (*buf_ptr == '*' && !in_comment && !quote)
-		  {
-		     in_comment = 1;
-		     *e_lab++ = *buf_ptr++;
-		     com_start = e_lab - s_lab - 2;
-		  }
-		  break;
-	       case '"':
-		  if (quote == '"')
-		     quote = 0;
-		  break;
-	       case '\'':
-		  if (quote == '\'')
-		     quote = 0;
-		  break;
-	       case '*':
-		  if (*buf_ptr == '/' && in_comment)
-		  {
-		     in_comment = 0;
-		     *e_lab++ = *buf_ptr++;
-		     com_end = e_lab - s_lab;
-		  }
-		  break;
-	       }
-	    }
-
-	    while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
-	       e_lab--;
-	    if (e_lab - s_lab == com_end && bp_save == 0)
-	    {				/* comment on preprocessor line */
-	       if (sc_end == 0)		/* if this is the first
-					   comment, we must set up the
-					   buffer */
-		  sc_end = &(save_com[0]);
-	       else
-	       {
-		  *sc_end++ = '\n';	/* add newline between comments */
-		  *sc_end++ = ' ';
-		  --line_no;
-	       }
-	       memcpy(sc_end, s_lab + com_start, com_end - com_start);
-	       sc_end += com_end - com_start;
-	       if (sc_end >= &save_com[sc_size])
-		  abort();
-	       e_lab = s_lab + com_start;
-	       while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
-		  e_lab--;
-	       bp_save = buf_ptr;	/* save current input buffer */
-	       be_save = buf_end;
-	       buf_ptr = save_com;	/* fix so that subsequent calls
-					   to lexi will take tokens out
-					   of save_com */
-	       *sc_end++ = ' ';		/* add trailing blank, just in
-					   case */
-	       buf_end = sc_end;
-	       sc_end = 0;
-	    }
-	    *e_lab = '\0';		/* null terminate line */
-	    ps.pcase = false;
-	 }
-
-	 if (strncmp(s_lab, "#if", 3) == 0)
-	 {
-	    if (bl_around)
-	    {
-	       register        c;
-	       prefix_blankline_requested++;
-	       while ((c = getc(input)) == '\n');
-	       ungetc(c, input);
-	    }
-	    if (ifdef_level < sizeof state_stack / sizeof state_stack[0])
-	    {
-	       match_state[ifdef_level].tos = -1;
-	       state_stack[ifdef_level++] = ps;
-	    } else
-	       diag(1, "#if stack overflow");
-	 } else if (strncmp(s_lab, "#else", 5) == 0)
-	    if (ifdef_level <= 0)
-	       diag(1, "Unmatched #else");
-	    else
-	    {
-	       match_state[ifdef_level - 1] = ps;
-	       ps = state_stack[ifdef_level - 1];
-	    }
-	 else if (strncmp(s_lab, "#endif", 6) == 0)
-	 {
-	    if (ifdef_level <= 0)
-	       diag(1, "Unmatched #endif");
-	    else
-	    {
-	       ifdef_level--;
-
-#ifdef undef
-	       /* This match needs to be more intelligent before the
-	          message is useful */
-	       if (match_state[ifdef_level].tos >= 0
-		   && bcmp(&ps, &match_state[ifdef_level], sizeof ps))
-		  diag(0, "Syntactically inconsistant #ifdef alternatives.");
-#endif
-	    }
-	    if (bl_around)
-	    {
-	       postfix_blankline_requested++;
-	       n_real_blanklines = 0;
-	    }
-	 }
-	 break;				/* subsequent processing of the
-					   newline character will cause
-					   the line to be printed */
-
-      case comment:			/* we have gotten a / *  this is
-					   a biggie */
-	 if (flushed_nl)
-	 {				/* we should force a broken
-					   line here */
-	    flushed_nl = false;
-	    dump_line();
-	    ps.want_blank = false;	/* dont insert blank at line
-					   start */
-	    force_nl = false;
-	 }
-	 pr_comment();
-	 break;
-      }					/* end of big switch stmt */
-
-      *e_code = '\0';			/* make sure code section is
-					   null terminated */
-      if (type_code != comment && type_code != newline && type_code != preesc)
-	 ps.last_token = type_code;
-   }					/* end of main while (1) loop */
-}
-
-/*
- * copy input file to backup file if in_name is /blah/blah/blah/file, then
- * backup file will be ".Bfile" then make the backup file the input and
- * original input file the output
- */
-void bakcopy()
-{
-   int             n, bakchn;
-   char            buff[8 * 1024];
-   register char  *p;
-
-   /* construct file name .Bfile */
-   for (p = in_name; *p; p++);		/* skip to end of string */
-   while (p > in_name && *p != '/')	/* find last '/' */
-      p--;
-   if (*p == '/')
-      p++;
-   sprintf(bakfile, "%s.BAK", p);
-   if (strlen(p) >= NAME_SIZE) *bakfile ^= 040;	/* toggle char */
-
-   /* copy in_name to backup file */
-   bakchn = creat(bakfile, 0600);
-   if (bakchn < 0)
-   {
-      fprintf(stderr, "indent: can't create backup file \"%s\"\n", bakfile);
-      exit(1);
-   }
-   while (n = read(fileno(input), buff, sizeof buff))
-      if (write(bakchn, buff, n) != n)
-      {
-	 fprintf(stderr, "indent: error writing backup file \"%s\"\n",
-		 bakfile);
-	 exit(1);
-      }
-   if (n < 0)
-   {
-      fprintf(stderr, "indent: error reading input file \"%s\"\n", in_name);
-      exit(1);
-   }
-   close(bakchn);
-   fclose(input);
-
-   /* re-open backup file as the input file */
-   input = fopen(bakfile, "r");
-   if (input == 0)
-   {
-      fprintf(stderr, "indent: can't re-open backup file\n");
-      exit(1);
-   }
-   /* now the original input file will be the output */
-   output = fopen(in_name, "w");
-   if (output == 0)
-   {
-      fprintf(stderr, "indent: can't create %s\n", in_name);
-      unlink(bakfile);
-      exit(1);
-   }
-}
Index: trunk/minix/commands/indent/indent.pro
===================================================================
--- trunk/minix/commands/indent/indent.pro	(revision 9)
+++ 	(revision )
@@ -1,1 +1,0 @@
--bap -bbb -br -ncdb -cli0.5 -di1 -lp -npsl -nfc1 -nip
Index: trunk/minix/commands/indent/io.c
===================================================================
--- trunk/minix/commands/indent/io.c	(revision 9)
+++ 	(revision )
@@ -1,639 +1,0 @@
-/**
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
- * Copyright (c) 1976 Board of Trustees of the University of Illinois.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley, the University of Illinois,
- * Urbana, and Sun Microsystems, Inc.  The name of either University
- * or Sun Microsystems 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 WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#define PUBLIC extern
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-#include "globs.h"
-#include "proto.h"
-
-
-int             comment_open;
-static          paren_target;
-
-void dump_line()
-{					/* dump_line is the routine
-					   that actually effects the
-					   printing of the new source.
-					   It prints the label section,
-					   followed by the code section
-					   with the appropriate nesting
-					   level, followed by any
-					   comments */
-   register int    cur_col, target_col;
-   static          not_first_line;
-
-   if (ps.procname[0])
-   {
-      if (troff)
-      {
-	 if (comment_open)
-	 {
-	    comment_open = 0;
-	    fprintf(output, ".*/\n");
-	 }
-	 fprintf(output, ".Pr \"%s\"\n", ps.procname);
-      }
-      ps.ind_level = 0;
-      ps.procname[0] = 0;
-   }
-   if (s_code == e_code && s_lab == e_lab && s_com == e_com)
-   {
-      if (suppress_blanklines > 0)
-	 suppress_blanklines--;
-      else
-      {
-	 ps.bl_line = true;
-	 n_real_blanklines++;
-      }
-   } else if (!inhibit_formatting)
-   {
-      suppress_blanklines = 0;
-      ps.bl_line = false;
-      if (prefix_blankline_requested && not_first_line)
-	 if (swallow_opt_bl)
-	 {
-	    if (n_real_blanklines == 1)
-	       n_real_blanklines = 0;
-	 } else
-	 {
-	    if (n_real_blanklines == 0)
-	       n_real_blanklines = 1;
-	 }
-      while (--n_real_blanklines >= 0)
-	 putc('\n', output);
-      n_real_blanklines = 0;
-      if (ps.ind_level == 0)
-	 ps.ind_stmt = 0;		/* this is a class A kludge.
-					   dont do additional statement
-					   indentation if we are at
-					   bracket level 0 */
-
-      if (e_lab != s_lab || e_code != s_code)
-	 ++code_lines;			/* keep count of lines with
-					   code */
-
-
-      if (e_lab != s_lab)
-      {					/* print lab, if any */
-	 if (comment_open)
-	 {
-	    comment_open = 0;
-	    fprintf(output, ".*/\n");
-	 }
-	 while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
-	    e_lab--;
-	 cur_col = pad_output(1, label_target());
-	 fprintf(output, "%.*s", (int)(e_lab - s_lab), s_lab);
-	 cur_col = count_spaces(cur_col, s_lab);
-      } else
-	 cur_col = 1;			/* there is no label section */
-
-      ps.pcase = false;
-
-      if (s_code != e_code)
-      {					/* print code section, if any */
-	 register char  *p;
-
-	 if (comment_open)
-	 {
-	    comment_open = 0;
-	    fprintf(output, ".*/\n");
-	 }
-	 target_col = code_target();
-	 {
-	    register        i;
-
-	    for (i = 0; i < ps.p_l_follow; i++)
-	       if (ps.paren_indents[i] >= 0)
-		  ps.paren_indents[i] = -(ps.paren_indents[i] + target_col);
-	 }
-	 cur_col = pad_output(cur_col, target_col);
-	 for (p = s_code; p < e_code; p++)
-	    if (*p == (char) 0200)
-	       fprintf(output, "%d", target_col * 7);
-	    else
-	       putc(*p, output);
-	 cur_col = count_spaces(cur_col, s_code);
-      }
-      if (s_com != e_com)
-	 if (troff)
-	 {
-	    int             all_here = 0;
-	    register char  *p;
-
-	    if (e_com[-1] == '/' && e_com[-2] == '*')
-	       e_com -= 2, all_here++;
-	    while (e_com > s_com && e_com[-1] == ' ')
-	       e_com--;
-	    *e_com = 0;
-	    p = s_com;
-	    while (*p == ' ')
-	       p++;
-	    if (p[0] == '/' && p[1] == '*')
-	       p += 2, all_here++;
-	    else if (p[0] == '*')
-	       p += p[1] == '/' ? 2 : 1;
-	    while (*p == ' ')
-	       p++;
-	    if (*p == 0)
-	       goto inhibit_newline;
-	    if (comment_open < 2 && ps.box_com)
-	    {
-	       comment_open = 0;
-	       fprintf(output, ".*/\n");
-	    }
-	    if (comment_open == 0)
-	    {
-	       if ('a' <= *p && *p <= 'z')
-		  *p = *p + 'A' - 'a';
-	       if (e_com - p < 50 && all_here == 2)
-	       {
-		  register char  *follow = p;
-		  fprintf(output, "\n.nr C! \\w\1");
-		  while (follow < e_com)
-		  {
-		     switch (*follow)
-		     {
-		     case '\n':
-			putc(' ', output);
-		     case 1:
-			break;
-		     case '\\':
-			putc('\\', output);
-		     default:
-			putc(*follow, output);
-		     }
-		     follow++;
-		  }
-		  putc(1, output);
-	       }
-	       fprintf(output, "\n./* %dp %d %dp\n",
-		       ps.com_col * 7,
-		    (s_code != e_code || s_lab != e_lab) - ps.box_com,
-		       target_col * 7);
-	    }
-	    comment_open = 1 + ps.box_com;
-	    while (*p)
-	    {
-	       if (*p == BACKSLASH)
-		  putc(BACKSLASH, output);
-	       putc(*p++, output);
-	    }
-	 } else
-	 {				/* print comment, if any */
-	    register        target = ps.com_col;
-	    register char  *com_st = s_com;
-
-	    target += ps.comment_delta;
-	    while (*com_st == '\t')
-	       com_st++, target += 8;	/* ? */
-	    while (target <= 0)
-	       if (*com_st == ' ')
-		  target++, com_st++;
-	       else if (*com_st == '\t')
-		  target = ((target - 1) & ~7) + 9, com_st++;
-	       else
-		  target = 1;
-	    if (cur_col > target)
-	    {				/* if comment cant fit on this
-					   line, put it on next line */
-	       putc('\n', output);
-	       cur_col = 1;
-	       ++ps.out_lines;
-	    }
-	    while (e_com > com_st && isspace(e_com[-1]))
-	       e_com--;
-	    cur_col = pad_output(cur_col, target);
-	    if (!ps.box_com)
-	    {
-	       if (star_comment_cont && (com_st[1] != '*' || e_com <= com_st + 1))
-		  if (com_st[1] == ' ' && com_st[0] == ' ' && e_com > com_st + 1)
-		     com_st[1] = '*';
-		  else
-		     fwrite(" * ", com_st[0] == '\t' ? 2 : com_st[0] == '*' ? 1 : 3, 1, output);
-	    }
-	    fwrite(com_st, (int)(e_com - com_st), 1, output);
-	    ps.comment_delta = ps.n_comment_delta;
-	    cur_col = count_spaces(cur_col, com_st);
-	    ++ps.com_lines;		/* count lines with comments */
-	 }
-      if (ps.use_ff)
-	 putc('\014', output);
-      else
-	 putc('\n', output);
-inhibit_newline:
-      ++ps.out_lines;
-      if (ps.just_saw_decl == 1 && bl_aft_decl)
-      {
-	 prefix_blankline_requested = 1;
-	 ps.just_saw_decl = 0;
-      } else
-	 prefix_blankline_requested = postfix_blankline_requested;
-      postfix_blankline_requested = 0;
-   }
-   ps.decl_on_line = ps.in_decl;	/* if we are in the middle of a
-					   declaration, remember that
-					   fact for proper comment
-					   indentation */
-   ps.ind_stmt = ps.in_stmt & ~ps.in_decl;	/* next line should be
-						   indented if we have
-						   not completed this
-						   stmt and if we are
-						   not in the middle of
-						   a declaration */
-   ps.use_ff = false;
-   ps.dumped_decl_indent = 0;
-   *(e_lab = s_lab) = '\0';		/* reset buffers */
-   *(e_code = s_code) = '\0';
-   *(e_com = s_com) = '\0';
-   ps.ind_level = ps.i_l_follow;
-   ps.paren_level = ps.p_l_follow;
-   paren_target = -ps.paren_indents[ps.paren_level - 1];
-   not_first_line = 1;
-   return;
-}
-
-int code_target()
-{
-   register        target_col = ps.ind_size * ps.ind_level + 1;
-
-   if (ps.paren_level)
-      if (!lineup_to_parens)
-	 target_col += continuation_indent * ps.paren_level;
-      else
-      {
-	 register        w;
-	 register        t = paren_target;
-
-	 if ((w = count_spaces(t, s_code) - max_col) > 0
-	     && count_spaces(target_col, s_code) <= max_col)
-	 {
-	    t -= w + 1;
-	    if (t > target_col)
-	       target_col = t;
-	 } else
-	    target_col = t;
-      }
-   else if (ps.ind_stmt)
-      target_col += continuation_indent;
-   return target_col;
-}
-
-int label_target()
-{
-   return
-      ps.pcase ? (int) (case_ind * ps.ind_size) + 1
-      : *s_lab == '#' ? 1
-      : ps.ind_size * (ps.ind_level - label_offset) + 1;
-}
-
-
-/*
- * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
- *
- * All rights reserved
- *
- *
- * NAME: fill_buffer
- *
- * FUNCTION: Reads one block of input into input_buffer
- *
- * HISTORY: initial coding 	November 1976	D A Willcox of CAC 1/7/77 A
- * Willcox of CAC	Added check for switch back to partly full input
- * buffer from temporary buffer
- *
- */
-
-void
-fill_buffer()
-{					/* this routine reads stuff
-					   from the input */
-   register char  *p;
-   register int    i;
-   register FILE  *f = input;
-
-   if (bp_save != 0)
-   {					/* there is a partly filled
-					   input buffer left */
-      buf_ptr = bp_save;		/* dont read anything, just
-					   switch buffers */
-      buf_end = be_save;
-      bp_save = be_save = 0;
-      if (buf_ptr < buf_end)
-	 return;			/* only return if there is
-					   really something in this
-					   buffer */
-   }
-   for (p = buf_ptr = in_buffer;;)
-   {
-      if ((i = getc(f)) == EOF)
-      {
-	 *p++ = ' ';
-	 *p++ = '\n';
-	 had_eof = true;
-	 break;
-      }
-      *p++ = (char)i;
-      if (i == '\n')
-	 break;
-   }
-   buf_end = p;
-   if (p[-2] == '/' && p[-3] == '*')
-   {
-      if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)
-	 fill_buffer();			/* flush indent error message */
-      else
-      {
-	 int             com = 0;
-
-	 p = in_buffer;
-	 while (*p == ' ' || *p == '\t')
-	    p++;
-	 if (*p == '/' && p[1] == '*')
-	 {
-	    p += 2;
-	    while (*p == ' ' || *p == '\t')
-	       p++;
-	    if (p[0] == 'I' && p[1] == 'N' && p[2] == 'D' && p[3] == 'E'
-		&& p[4] == 'N' && p[5] == 'T')
-	    {
-	       p += 6;
-	       while (*p == ' ' || *p == '\t')
-		  p++;
-	       if (*p == '*')
-		  com = 1;
-	       else if (*p == 'O')
-		  if (*++p == 'N')
-		     p++, com = 1;
-		  else if (*p == 'F' && *++p == 'F')
-		     p++, com = 2;
-	       while (*p == ' ' || *p == '\t')
-		  p++;
-	       if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && com)
-	       {
-		  if (s_com != e_com || s_lab != e_lab || s_code != e_code)
-		     dump_line();
-		  if (!(inhibit_formatting = com - 1))
-		  {
-		     n_real_blanklines = 0;
-		     postfix_blankline_requested = 0;
-		     prefix_blankline_requested = 0;
-		     suppress_blanklines = 1;
-		  }
-	       }
-	    }
-	 }
-      }
-   }
-   if (inhibit_formatting)
-   {
-      p = in_buffer;
-      do
-	 putc(*p, output);
-      while (*p++ != '\n');
-   }
-   return;
-}
-
-/*
- * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
- *
- * All rights reserved
- *
- *
- * NAME: pad_output
- *
- * FUNCTION: Writes tabs and spaces to move the current column up to the desired
- * position.
- *
- * ALGORITHM: Put tabs and/or blanks into pobuf, then write pobuf.
- *
- * PARAMETERS: current		integer		The current column target
- * nteger		The desired column
- *
- * RETURNS: Integer value of the new column.  (If current >= target, no action
- * is taken, and current is returned.
- *
- * GLOBALS: None
- *
- * CALLS: write (sys)
- *
- * CALLED BY: dump_line
- *
- * HISTORY: initial coding 	November 1976	D A Willcox of CAC
- *
- */
-
-int pad_output(current, target)		/* writes tabs and blanks (if
-					   necessary) to get the
-					   current output position up
-					   to the target column */
-   int             current;		/* the current column value */
-   int             target;		/* position we want it at */
-{
-   register int    curr;		/* internal column pointer */
-   register int    tcur;
-
-   if (troff)
-      fprintf(output, "\\h'|%dp'", (target - 1) * 7);
-   else
-   {
-      if (current >= target)
-	 return (current);		/* line is already long enough */
-      curr = current;
-      while ((tcur = ((curr - 1) & tabmask) + tabsize + 1) <= target)
-      {
-	 putc('\t', output);
-	 curr = tcur;
-      }
-      while (curr++ < target)
-	 putc(' ', output);		/* pad with final blanks */
-   }
-   return (target);
-}
-
-/*
- * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
- *
- * All rights reserved
- *
- *
- * NAME: count_spaces
- *
- * FUNCTION: Find out where printing of a given string will leave the current
- * character position on output.
- *
- * ALGORITHM: Run thru input string and add appropriate values to current
- * position.
- *
- * RETURNS: Integer value of position after printing "buffer" starting in column
- * "current".
- *
- * HISTORY: initial coding 	November 1976	D A Willcox of CAC
- *
- */
-
-int
-count_spaces(current, buffer)
-/*
- * this routine figures out where the character position will be after
- * printing the text in buffer starting at column "current"
- */
-   int             current;
-   char           *buffer;
-{
-   register char  *buf;			/* used to look thru buffer */
-   register int    cur;			/* current character counter */
-
-   cur = current;
-
-   for (buf = buffer; *buf != '\0'; ++buf)
-   {
-      switch (*buf)
-      {
-
-      case '\n':
-      case 014:			/* form feed */
-	 cur = 1;
-	 break;
-
-      case '\t':
-	 cur = ((cur - 1) & tabmask) + tabsize + 1;
-	 break;
-
-      case '':				/* this is a backspace */
-	 --cur;
-	 break;
-
-      default:
-	 ++cur;
-	 break;
-      }					/* end of switch */
-   }					/* end of for loop */
-   return (cur);
-}
-
-int             found_err;
-void diag(level, msg, a, b)
-int level;
-char *msg;
-int a, b;
-{
-   if (level)
-      found_err = 1;
-   if (output == stdout)
-   {
-      fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
-      fprintf(stdout, msg, a, b);
-      fprintf(stdout, " */\n");
-   } else
-   {
-      fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
-      fprintf(stderr, msg, a, b);
-      fprintf(stderr, "\n");
-   }
-}
-
-void writefdef(f, nm)
-   register struct fstate *f;
-   int nm;
-{
-   fprintf(output, ".ds f%c %s\n.nr s%c %d\n",
-	   nm, f->font, nm, f->size);
-}
-
-char           *
-chfont(of, nf, s)
-   register struct fstate *of, *nf;
-   char           *s;
-{
-   if (of->font[0] != nf->font[0]
-       || of->font[1] != nf->font[1])
-   {
-      *s++ = '\\';
-      *s++ = 'f';
-      if (nf->font[1])
-      {
-	 *s++ = '(';
-	 *s++ = nf->font[0];
-	 *s++ = nf->font[1];
-      } else
-	 *s++ = nf->font[0];
-   }
-   if (nf->size != of->size)
-   {
-      *s++ = '\\';
-      *s++ = 's';
-      if (nf->size < of->size)
-      {
-	 *s++ = '-';
-	 *s++ = (char)'0' + of->size - nf->size;
-      } else
-      {
-	 *s++ = '+';
-	 *s++ = (char)'0' + nf->size - of->size;
-      }
-   }
-   return s;
-}
-
-
-void parsefont(f, s0)
-   register struct fstate *f;
-   char           *s0;
-{
-   register char  *s = s0;
-   int             sizedelta = 0;
-   memset(f, '\0', sizeof *f);
-   while (*s)
-   {
-      if (isdigit(*s))
-	 f->size = f->size * 10 + *s - '0';
-      else if (isupper(*s))
-	 if (f->font[0])
-	    f->font[1] = *s;
-	 else
-	    f->font[0] = *s;
-      else if (*s == 'c')
-	 f->allcaps = 1;
-      else if (*s == '+')
-	 sizedelta++;
-      else if (*s == '-')
-	 sizedelta--;
-      else
-      {
-	 fprintf(stderr, "indent: bad font specification: %s\n", s0);
-	 exit(1);
-      }
-      s++;
-   }
-   if (f->font[0] == 0)
-      f->font[0] = 'R';
-   if (bodyf.size == 0)
-      bodyf.size = 11;
-   if (f->size == 0)
-      f->size = bodyf.size + sizedelta;
-   else if (sizedelta > 0)
-      f->size += bodyf.size;
-   else
-      f->size = bodyf.size - f->size;
-}
Index: trunk/minix/commands/indent/lexi.c
===================================================================
--- trunk/minix/commands/indent/lexi.c	(revision 9)
+++ 	(revision )
@@ -1,571 +1,0 @@
-/**
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
- * Copyright (c) 1976 Board of Trustees of the University of Illinois.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley, the University of Illinois,
- * Urbana, and Sun Microsystems, Inc.  The name of either University
- * or Sun Microsystems 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 WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-/*
- * Here we have the token scanner for indent.  It scans off one token and
- * puts it in the global variable "token".  It returns a code, indicating the
- * type of token scanned.
- */
-
-#define PUBLIC extern
-#include <ctype.h>
-#include <string.h>
-#include "globs.h"
-#include "codes.h"
-#include "proto.h"
-
-#define alphanum 1
-#define opchar 3
-
-struct templ
-{
-   char           *rwd;
-   int             rwcode;
-};
-
-struct templ    specials[100] =
-{
-   "switch", 1,
-   "case", 2,
-   "break", 0,
-   "struct", 3,
-   "union", 3,
-   "enum", 3,
-   "default", 2,
-   "int", 4,
-   "char", 4,
-   "float", 4,
-   "double", 4,
-   "long", 4,
-   "short", 4,
-   "typedef", 4,
-   "unsigned", 4,
-   "register", 4,
-   "static", 4,
-   "global", 4,
-   "extern", 4,
-   "void", 4,
-   "goto", 0,
-   "return", 0,
-   "if", 5,
-   "while", 5,
-   "for", 5,
-   "else", 6,
-   "do", 6,
-   "sizeof", 7,
-   0, 0
-};
-
-char            chartype[128] =
-{					/* this is used to facilitate
-					   the decision of what type
-					   (alphanumeric, operator)
-					   each character is */
-   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, 3, 0, 0, 1, 3, 3, 0,
-   0, 0, 3, 3, 0, 3, 0, 3,
-   1, 1, 1, 1, 1, 1, 1, 1,
-   1, 1, 0, 0, 3, 3, 3, 3,
-   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, 1, 1, 0, 0, 0, 3, 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, 1, 1, 0, 3, 0, 3, 0
-};
-
-
-
-
-int
-lexi()
-{
-   register char  *tok;			/* local pointer to next char
-					   in token */
-   int             unary_delim;		/* this is set to 1 if the
-					   current token
-					
-					forces a following operator to
-					   be unary */
-   static int      last_code;		/* the last token type returned */
-   static int      l_struct;		/* set to 1 if the last token
-					   was 'struct' */
-   int             code;		/* internal code to be returned */
-   char            qchar;		/* the delimiter character for
-					   a string */
-
-   tok = token;				/* point to start of place to
-					   save token */
-   unary_delim = false;
-   ps.col_1 = ps.last_nl;		/* tell world that this token
-					   started in column 1 iff the
-					   last thing scanned was nl */
-   ps.last_nl = false;
-
-   while (*buf_ptr == ' ' || *buf_ptr == '\t')
-   {					/* get rid of blanks */
-      ps.col_1 = false;			/* leading blanks imply token
-					   is not in column 1 */
-      if (++buf_ptr >= buf_end)
-	 fill_buffer();
-   }
-
-   /* Scan an alphanumeric token */
-   if (chartype[*buf_ptr] == alphanum || (buf_ptr[0] == '.' && isdigit(buf_ptr[1])))
-   {
-      /* we have a character or number */
-      register char  *j;		/* used for searching thru list
-					   of
-					
-					reserved words */
-      register struct templ *p;
-
-      if (isdigit(*buf_ptr) || (buf_ptr[0] == '.' && isdigit(buf_ptr[1])))
-      {
-	 int             seendot = 0, seenexp = 0;
-	 if (*buf_ptr == '0' &&
-	     (buf_ptr[1] == 'x' || buf_ptr[1] == 'X'))
-	 {
-	    *tok++ = *buf_ptr++;
-	    *tok++ = *buf_ptr++;
-	    while (isxdigit(*buf_ptr))
-	       *tok++ = *buf_ptr++;
-	 } else
-	    while (1)
-	    {
-	       if (*buf_ptr == '.')
-		  if (seendot)
-		     break;
-		  else
-		     seendot++;
-	       *tok++ = *buf_ptr++;
-	       if (!isdigit(*buf_ptr) && *buf_ptr != '.')
-		  if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp)
-		     break;
-		  else
-		  {
-		     seenexp++;
-		     seendot++;
-		     *tok++ = *buf_ptr++;
-		     if (*buf_ptr == '+' || *buf_ptr == '-')
-			*tok++ = *buf_ptr++;
-		  }
-	    }
-	 if (*buf_ptr == 'L' || *buf_ptr == 'l')
-	    *tok++ = *buf_ptr++;
-      } else
-	 while (chartype[*buf_ptr] == alphanum)
-	 {				/* copy it over */
-	    *tok++ = *buf_ptr++;
-	    if (buf_ptr >= buf_end)
-	       fill_buffer();
-	 }
-      *tok++ = '\0';
-      while (*buf_ptr == ' ' || *buf_ptr == '\t')
-      {					/* get rid of blanks */
-	 if (++buf_ptr >= buf_end)
-	    fill_buffer();
-      }
-      ps.its_a_keyword = false;
-      ps.sizeof_keyword = false;
-      if (l_struct)
-      {					/* if last token was 'struct',
-					   then this token should be
-					   treated as a declaration */
-	 l_struct = false;
-	 last_code = ident;
-	 ps.last_u_d = true;
-	 return (decl);
-      }
-      ps.last_u_d = false;		/* Operator after indentifier
-					   is binary */
-      last_code = ident;		/* Remember that this is the
-					   code we will return */
-
-      /* This loop will check if the token is a keyword. */
-      for (p = specials; (j = p->rwd) != 0; p++)
-      {
-	 tok = token;			/* point at scanned token */
-	 if (*j++ != *tok++ || *j++ != *tok++)
-	    continue;			/* This test depends on the
-					   fact that identifiers are
-					   always at least 1 character
-					   long (ie. the first two
-					   bytes of the identifier are
-					   always meaningful) */
-	 if (tok[-1] == 0)
-	    break;			/* If its a one-character
-					   identifier */
-	 while (*tok++ == *j)
-	    if (*j++ == 0)
-	       goto found_keyword;	/* I wish that C had a
-					   multi-level break... */
-      }
-      if (p->rwd)
-      {					/* we have a keyword */
-   found_keyword:
-	 ps.its_a_keyword = true;
-	 ps.last_u_d = true;
-	 switch (p->rwcode)
-	 {
-	 case 1:			/* it is a switch */
-	    return (swstmt);
-	 case 2:			/* a case or default */
-	    return (casestmt);
-
-	 case 3:			/* a "struct" */
-	    if (ps.p_l_follow)
-	       break;			/* inside parens: cast */
-	    l_struct = true;
-
-	    /* Next time around, we will want to know that we have had
-	       a 'struct' */
-	 case 4:			/* one of the declaration
-					   keywords */
-	    if (ps.p_l_follow)
-	    {
-	       ps.cast_mask |= 1 << ps.p_l_follow;
-	       break;			/* inside parens: cast */
-	    }
-	    last_code = decl;
-	    return (decl);
-
-	 case 5:			/* if, while, for */
-	    return (sp_paren);
-
-	 case 6:			/* do, else */
-	    return (sp_nparen);
-
-	 case 7:
-	    ps.sizeof_keyword = true;
-	 default:			/* all others are treated like
-					   any other identifier */
-	    return (ident);
-	 }				/* end of switch */
-      }					/* end of if (found_it) */
-      if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0)
-      {
-	 register char  *tp = buf_ptr;
-	 while (tp < buf_end)
-	    if (*tp++ == ')' && *tp == ';')
-	       goto not_proc;
-	 strncpy(ps.procname, token, sizeof ps.procname - 1);
-	 ps.in_par_decl = 1;
-   not_proc:;
-      }
-      /* The following hack attempts to guess whether or not the
-         current token is in fact a declaration keyword -- one that has
-         been typedefd */
-      if (((*buf_ptr == '*' && buf_ptr[1] != '=') || isalpha(*buf_ptr) || *buf_ptr == '_')
-	  && !ps.p_l_follow
-	  && !ps.block_init
-	  && (ps.last_token == rparen || ps.last_token == semicolon ||
-	      ps.last_token == decl ||
-	      ps.last_token == lbrace || ps.last_token == rbrace))
-      {
-	 ps.its_a_keyword = true;
-	 ps.last_u_d = true;
-	 last_code = decl;
-	 return decl;
-      }
-      if (last_code == decl)		/* if this is a declared
-					   variable, then following
-					   sign is unary */
-	 ps.last_u_d = true;		/* will make "int a -1" work */
-      last_code = ident;
-      return (ident);			/* the ident is not in the list */
-   }					/* end of procesing for alpanum
-					   character */
-   /* l l l Scan a non-alphanumeric token */
-   *tok++ = *buf_ptr;			/* if it is only a
-					   one-character token, it is
-					   moved here */
-   *tok = '\0';
-   if (++buf_ptr >= buf_end)
-      fill_buffer();
-
-   switch (*token)
-   {
-   case '\n':
-      unary_delim = ps.last_u_d;
-      ps.last_nl = true;		/* remember that we just had a
-					   newline */
-      code = (had_eof ? 0 : newline);
-
-      /* if data has been exausted, the newline is a dummy, and we
-         should return code to stop */
-      break;
-
-   case '\'':				/* start of quoted character */
-   case '"':				/* start of string */
-      qchar = *token;
-      if (troff)
-      {
-	 tok[-1] = '`';
-	 if (qchar == '"')
-	    *tok++ = '`';
-	 tok = chfont(&bodyf, &stringf, tok);
-      }
-      do
-      {					/* copy the string */
-	 while (1)
-	 {				/* move one character or
-					   [/<char>]<char> */
-	    if (*buf_ptr == '\n')
-	    {
-	       printf("%d: Unterminated literal\n", line_no);
-	       goto stop_lit;
-	    }
-	    *tok = *buf_ptr++;
-	    if (buf_ptr >= buf_end)
-	       fill_buffer();
-	    if (had_eof || ((tok - token) > (bufsize - 2)))
-	    {
-	       printf("Unterminated literal\n");
-	       ++tok;
-	       goto stop_lit;
-	       /* get outof literal copying loop */
-	    }
-	    if (*tok == BACKSLASH)
-	    {				/* if escape, copy extra char */
-	       if (*buf_ptr == '\n')	/* check for escaped newline */
-		  ++line_no;
-	       if (troff)
-	       {
-		  *++tok = BACKSLASH;
-		  if (*buf_ptr == BACKSLASH)
-		     *++tok = BACKSLASH;
-	       }
-	       *++tok = *buf_ptr++;
-	       ++tok;			/* we must increment this again
-					   because we copied two chars */
-	       if (buf_ptr >= buf_end)
-		  fill_buffer();
-	    } else
-	       break;			/* we copied one character */
-	 }				/* end of while (1) */
-      } while (*tok++ != qchar);
-      if (troff)
-      {
-	 tok = chfont(&stringf, &bodyf, tok - 1);
-	 if (qchar == '"')
-	    *tok++ = '\'';
-      }
-stop_lit:
-      code = ident;
-      break;
-
-   case ('('):
-   case ('['):
-      unary_delim = true;
-      code = lparen;
-      break;
-
-   case (')'):
-   case (']'):
-      code = rparen;
-      break;
-
-   case '#':
-      unary_delim = ps.last_u_d;
-      code = preesc;
-      break;
-
-   case '?':
-      unary_delim = true;
-      code = question;
-      break;
-
-   case (':'):
-      code = colon;
-      unary_delim = true;
-      break;
-
-   case (';'):
-      unary_delim = true;
-      code = semicolon;
-      break;
-
-   case ('{'):
-      unary_delim = true;
-
-      /* if (ps.in_or_st) ps.block_init = 1; */
-      code = ps.block_init ? lparen : lbrace;
-      break;
-
-   case ('}'):
-      unary_delim = true;
-      code = ps.block_init ? rparen : rbrace;
-      break;
-
-   case 014:				/* a form feed */
-      unary_delim = ps.last_u_d;
-      ps.last_nl = true;		/* remember this so we can set
-					   'ps.col_1' right */
-      code = form_feed;
-      break;
-
-   case (','):
-      unary_delim = true;
-      code = comma;
-      break;
-
-   case '.':
-      unary_delim = false;
-      code = period;
-      break;
-
-   case '-':
-   case '+':				/* check for -, +, --, ++ */
-      code = (ps.last_u_d ? unary_op : binary_op);
-      unary_delim = true;
-
-      if (*buf_ptr == token[0])
-      {
-	 /* check for doubled character */
-	 *tok++ = *buf_ptr++;
-	 /* buffer overflow will be checked at end of loop */
-	 if (last_code == ident || last_code == rparen)
-	 {
-	    code = (ps.last_u_d ? unary_op : postop);
-	    /* check for following ++ or -- */
-	    unary_delim = false;
-	 }
-      } else if (*buf_ptr == '=')
-	 /* check for operator += */
-	 *tok++ = *buf_ptr++;
-      else if (*buf_ptr == '>')
-      {
-	 /* check for operator -> */
-	 *tok++ = *buf_ptr++;
-	 if (!ptr_binop)
-	 {
-	    unary_delim = false;
-	    code = unary_op;
-	    ps.want_blank = false;
-	 }
-      }
-      break;				/* buffer overflow will be
-					   checked at end of switch */
-
-   case '=':
-      if (ps.in_or_st)
-	 ps.block_init = 1;
-#ifdef undef
-      if (chartype[*buf_ptr] == opchar)
-      {					/* we have two char assignment */
-	 tok[-1] = *buf_ptr++;
-	 if ((tok[-1] == '<' || tok[-1] == '>') && tok[-1] == *buf_ptr)
-	    *tok++ = *buf_ptr++;
-	 *tok++ = '=';			/* Flip =+ to += */
-	 *tok = 0;
-      }
-#else
-      if (*buf_ptr == '=')
-      {					/* == */
-	 *tok++ = '=';			/* Flip =+ to += */
-	 buf_ptr++;
-	 *tok = 0;
-      }
-#endif
-      code = binary_op;
-      unary_delim = true;
-      break;
-      /* can drop thru!!! */
-
-   case '>':
-   case '<':
-   case '!':				/* ops like <, <<, <=, !=, etc */
-      if (*buf_ptr == '>' || *buf_ptr == '<' || *buf_ptr == '=')
-      {
-	 *tok++ = *buf_ptr;
-	 if (++buf_ptr >= buf_end)
-	    fill_buffer();
-      }
-      if (*buf_ptr == '=')
-	 *tok++ = *buf_ptr++;
-      code = (ps.last_u_d ? unary_op : binary_op);
-      unary_delim = true;
-      break;
-
-   default:
-      if (token[0] == '/' && *buf_ptr == '*')
-      {
-	 /* it is start of comment */
-	 *tok++ = '*';
-
-	 if (++buf_ptr >= buf_end)
-	    fill_buffer();
-
-	 code = comment;
-	 unary_delim = ps.last_u_d;
-	 break;
-      }
-      while (*(tok - 1) == *buf_ptr || *buf_ptr == '=')
-      {
-	 /* handle ||, &&, etc, and also things as in int *****i */
-	 *tok++ = *buf_ptr;
-	 if (++buf_ptr >= buf_end)
-	    fill_buffer();
-      }
-      code = (ps.last_u_d ? unary_op : binary_op);
-      unary_delim = true;
-
-
-   }					/* end of switch */
-   if (code != newline)
-   {
-      l_struct = false;
-      last_code = code;
-   }
-   if (buf_ptr >= buf_end)		/* check for input buffer empty */
-      fill_buffer();
-   ps.last_u_d = unary_delim;
-   *tok = '\0';				/* null terminate the token */
-   return (code);
-}
-
-/*
- * Add the given keyword to the keyword table, using val as the keyword type
- */
-void addkey(key, val)
-   char           *key;
-   int val;
-{
-   register struct templ *p = specials;
-   while (p->rwd)
-      if (p->rwd[0] == key[0] && strcmp(p->rwd, key) == 0)
-	 return;
-      else
-	 p++;
-   if (p >= specials + sizeof specials / sizeof specials[0])
-      return;				/* For now, table overflows are
-					   silently ignored */
-   p->rwd = key;
-   p->rwcode = val;
-   p[1].rwd = 0;
-   p[1].rwcode = 0;
-   return;
-}
Index: trunk/minix/commands/indent/parse.c
===================================================================
--- trunk/minix/commands/indent/parse.c	(revision 9)
+++ 	(revision )
@@ -1,320 +1,0 @@
-/**
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
- * Copyright (c) 1976 Board of Trustees of the University of Illinois.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley, the University of Illinois,
- * Urbana, and Sun Microsystems, Inc.  The name of either University
- * or Sun Microsystems 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 WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#define PUBLIC	extern
-#include "./globs.h"
-#include "./codes.h"
-#include "proto.h"
-
-
-
-
-void parse(tk)
-   int             tk;			/* the code for the construct
-					   scanned */
-{
-   int             i;
-
-#ifdef debug
-   printf("%2d - %s\n", tk, token);
-#endif
-
-   while (ps.p_stack[ps.tos] == ifhead && tk != elselit)
-   {
-      /* true if we have an if without an else */
-      ps.p_stack[ps.tos] = stmt;	/* apply the if(..) stmt ::=
-					   stmt reduction */
-      reduce();				/* see if this allows any
-					   reduction */
-   }
-
-
-   switch (tk)
-   {					/* go on and figure out what to
-					   do with the input */
-
-   case decl:				/* scanned a declaration word */
-      ps.search_brace = btype_2;
-      /* indicate that following brace should be on same line */
-      if (ps.p_stack[ps.tos] != decl)
-      {					/* only put one declaration
-					   onto stack */
-	 break_comma = true;		/* while in declaration,
-					   newline should be forced
-					   after comma */
-	 ps.p_stack[++ps.tos] = decl;
-	 ps.il[ps.tos] = ps.i_l_follow;
-
-	 if (ps.ljust_decl)
-	 {				/* only do if we want left
-					   justified declarations */
-	    ps.ind_level = 0;
-	    for (i = ps.tos - 1; i > 0; --i)
-	       if (ps.p_stack[i] == decl)
-		  ++ps.ind_level;	/* indentation is number of
-					   declaration levels deep we
-					   are */
-	    ps.i_l_follow = ps.ind_level;
-	 }
-      }
-      break;
-
-   case ifstmt:			/* scanned if (...) */
-      if (ps.p_stack[ps.tos] == elsehead && ps.else_if)	/* "else if ..." */
-	 ps.i_l_follow = ps.il[ps.tos];
-   case dolit:				/* 'do' */
-   case forstmt:			/* for (...) */
-      ps.p_stack[++ps.tos] = tk;
-      ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
-      ++ps.i_l_follow;			/* subsequent statements should
-					   be indented 1 */
-      ps.search_brace = btype_2;
-      break;
-
-   case lbrace:			/* scanned { */
-      break_comma = false;		/* don't break comma in an
-					   initial list */
-      if (ps.p_stack[ps.tos] == stmt || ps.p_stack[ps.tos] == decl
-	  || ps.p_stack[ps.tos] == stmtl)
-	 ++ps.i_l_follow;		/* it is a random, isolated
-					   stmt group or a declaration */
-      else
-      {
-	 if (s_code == e_code)
-	 {
-	    /* only do this if there is nothing on the line */
-	    --ps.ind_level;
-	    /* it is a group as part of a while, for, etc. */
-	    if (ps.p_stack[ps.tos] == swstmt && ps.case_indent >= 1)
-	       --ps.ind_level;
-	    /* for a switch, brace should be two levels out from the
-	       code */
-	 }
-      }
-
-      ps.p_stack[++ps.tos] = lbrace;
-      ps.il[ps.tos] = ps.ind_level;
-      ps.p_stack[++ps.tos] = stmt;
-      /* allow null stmt between braces */
-      ps.il[ps.tos] = ps.i_l_follow;
-      break;
-
-   case whilestmt:			/* scanned while (...) */
-      if (ps.p_stack[ps.tos] == dohead)
-      {
-	 /* it is matched with do stmt */
-	 ps.ind_level = ps.i_l_follow = ps.il[ps.tos];
-	 ps.p_stack[++ps.tos] = whilestmt;
-	 ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
-      } else
-      {					/* it is a while loop */
-	 ps.p_stack[++ps.tos] = whilestmt;
-	 ps.il[ps.tos] = ps.i_l_follow;
-	 ++ps.i_l_follow;
-	 ps.search_brace = btype_2;
-      }
-
-      break;
-
-   case elselit:			/* scanned an else */
-
-      if (ps.p_stack[ps.tos] != ifhead)
-	 diag(1, "Unmatched 'else'");
-      else
-      {
-	 ps.ind_level = ps.il[ps.tos];	/* indentation for else should
-					   be same as for if */
-	 ps.i_l_follow = ps.ind_level + 1;	/* everything following
-						   should be in 1 level */
-	 ps.p_stack[ps.tos] = elsehead;
-	 /* remember if with else */
-	 ps.search_brace = btype_2 | ps.else_if;
-      }
-      break;
-
-   case rbrace:			/* scanned a } */
-      /* stack should have <lbrace> <stmt> or <lbrace> <stmtl> */
-      if (ps.p_stack[ps.tos - 1] == lbrace)
-      {
-	 ps.ind_level = ps.i_l_follow = ps.il[--ps.tos];
-	 ps.p_stack[ps.tos] = stmt;
-      } else
-	 diag(1, "Stmt nesting error.");
-      break;
-
-   case swstmt:			/* had switch (...) */
-      ps.p_stack[++ps.tos] = swstmt;
-      ps.cstk[ps.tos] = case_ind;
-      /* save current case indent level */
-      ps.il[ps.tos] = ps.i_l_follow;
-      case_ind = ps.i_l_follow + ps.case_indent;	/* cases should be one
-							   level down from
-							   switch */
-      ps.i_l_follow += ps.case_indent + 1;	/* statements should be
-						   two levels in */
-      ps.search_brace = btype_2;
-      break;
-
-   case semicolon:			/* this indicates a simple stmt */
-      break_comma = false;		/* turn off flag to break after
-					   commas in a declaration */
-      ps.p_stack[++ps.tos] = stmt;
-      ps.il[ps.tos] = ps.ind_level;
-      break;
-
-   default:				/* this is an error */
-      diag(1, "Unknown code to parser");
-      return;
-
-
-   }					/* end of switch */
-
-   reduce();				/* see if any reduction can be
-					   done */
-
-#ifdef debug
-   for (i = 1; i <= ps.tos; ++i)
-      printf("(%d %d)", ps.p_stack[i], ps.il[i]);
-   printf("\n");
-#endif
-
-   return;
-}
-
-/*
- * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
- *
- * All rights reserved
- *
- *
- * NAME: reduce
- *
- * FUNCTION: Implements the reduce part of the parsing algorithm
- *
- * ALGORITHM: The following reductions are done.  Reductions are repeated until
- * no more are possible.
- *
- * Old TOS		New TOS <stmt> <stmt>	<stmtl> <stmtl> <stmt>	<stmtl> do
- * <stmt>	"dostmt" if <stmt>	"ifstmt" switch <stmt>	<stmt> decl
- * <stmt>	<stmt> "ifelse" <stmt>	<stmt> for <stmt>	<stmt> while
- * <stmt>	<stmt> "dostmt" while	<stmt>
- *
- * On each reduction, ps.i_l_follow (the indentation for the following line) is
- * set to the indentation level associated with the old TOS.
- *
- * PARAMETERS: None
- *
- * RETURNS: Nothing
- *
- * GLOBALS: ps.cstk ps.i_l_follow = ps.il ps.p_stack = ps.tos =
- *
- * CALLS: None
- *
- * CALLED BY: parse
- *
- * HISTORY: initial coding 	November 1976	D A Willcox of CAC
- *
- */
-
-/*----------------------------------------------*\
-|   REDUCTION PHASE				    |
-\*----------------------------------------------*/
-void reduce()
-{
-
-   register int    i;
-
-   for (;;)
-   {					/* keep looping until there is
-					   nothing left to reduce */
-
-      switch (ps.p_stack[ps.tos])
-      {
-
-      case stmt:
-	 switch (ps.p_stack[ps.tos - 1])
-	 {
-
-	 case stmt:
-	 case stmtl:
-	    /* stmtl stmt or stmt stmt */
-	    ps.p_stack[--ps.tos] = stmtl;
-	    break;
-
-	 case dolit:			/* <do> <stmt> */
-	    ps.p_stack[--ps.tos] = dohead;
-	    ps.i_l_follow = ps.il[ps.tos];
-	    break;
-
-	 case ifstmt:
-	    /* <if> <stmt> */
-	    ps.p_stack[--ps.tos] = ifhead;
-	    for (i = ps.tos - 1;
-		 (
-		  ps.p_stack[i] != stmt
-		  &&
-		  ps.p_stack[i] != stmtl
-		  &&
-		  ps.p_stack[i] != lbrace
-		  );
-		 --i);
-	    ps.i_l_follow = ps.il[i];
-	    /* for the time being, we will assume that there is no else
-	       on this if, and set the indentation level accordingly.
-	       If an else is scanned, it will be fixed up later */
-	    break;
-
-	 case swstmt:
-	    /* <switch> <stmt> */
-	    case_ind = ps.cstk[ps.tos - 1];
-
-	 case decl:			/* finish of a declaration */
-	 case elsehead:
-	    /* <<if> <stmt> else> <stmt> */
-	 case forstmt:
-	    /* <for> <stmt> */
-	 case whilestmt:
-	    /* <while> <stmt> */
-	    ps.p_stack[--ps.tos] = stmt;
-	    ps.i_l_follow = ps.il[ps.tos];
-	    break;
-
-	 default:			/* <anything else> <stmt> */
-	    return;
-
-	 }				/* end of section for <stmt> on
-					   top of stack */
-	 break;
-
-      case whilestmt:			/* while (...) on top */
-	 if (ps.p_stack[ps.tos - 1] == dohead)
-	 {
-	    /* it is termination of a do while */
-	    ps.p_stack[--ps.tos] = stmt;
-	    break;
-	 } else
-	    return;
-
-      default:				/* anything else on top */
-	 return;
-
-      }
-   }
-}
Index: trunk/minix/commands/indent/proto.h
===================================================================
--- trunk/minix/commands/indent/proto.h	(revision 9)
+++ 	(revision )
@@ -1,26 +1,0 @@
-/* _PROTOTYPE(   void diag, (int level,char *msg, int a, int b)    ); */
-void diag();			/* HACK.  should be varargs */
-
-_PROTOTYPE(   void set_profile, (void )    );
-_PROTOTYPE(   void scan_profile, (FILE *f)    );
-_PROTOTYPE(   int eqin, (char *s1,char *s2)    );
-_PROTOTYPE(   void set_defaults, (void )    );
-_PROTOTYPE(   void set_option, (char *arg)    );
-_PROTOTYPE(   void pr_comment, (void )    );
-_PROTOTYPE(   void main, (int argc,char * *argv)    );
-_PROTOTYPE(   void bakcopy, (void )    );
-_PROTOTYPE(   void dump_line, (void )    );
-_PROTOTYPE(   int code_target, (void )    );
-_PROTOTYPE(   int label_target, (void )    );
-_PROTOTYPE(   void fill_buffer, (void )    );
-_PROTOTYPE(   int pad_output, (int current,int target)    );
-_PROTOTYPE(   int count_spaces, (int current,char *buffer)    );
-_PROTOTYPE(   void writefdef, (struct fstate *f,int nm)    );
-_PROTOTYPE(   char *chfont, (struct fstate *of,struct fstate *nf,char *s)    );
-_PROTOTYPE(   void parsefont, (struct fstate *f,char *s0)    );
-_PROTOTYPE(   int lexi, (void )    );
-_PROTOTYPE(   void addkey, (char *key,int val)    );
-_PROTOTYPE(   void makext, (char *newname,char *newext)    );
-_PROTOTYPE(   void parse, (int tk)    );
-_PROTOTYPE(   void reduce, (void )    );
-
Index: trunk/minix/commands/m4/Ack.m4
===================================================================
--- trunk/minix/commands/m4/Ack.m4	(revision 9)
+++ 	(revision )
@@ -1,2 +1,0 @@
-define(ack, `ifelse($1,0,incr($2),$2,0,`ack(DECR($1),1)',
-`ack(DECR($1), ack($1,DECR($2)))')')
Index: trunk/minix/commands/m4/Hanoi.m4
===================================================================
--- trunk/minix/commands/m4/Hanoi.m4	(revision 9)
+++ 	(revision )
@@ -1,7 +1,0 @@
-define(hanoi, `trans(A, B, C, $1)')
-
-define(moved,`move disk from $1 to $2
-')
-
-define(trans, `ifelse($4,1,`moved($1,$2)',
-	`trans($1,$3,$2,DECR($4))moved($1,$2)trans($3,$2,$1,DECR($4))')')
Index: trunk/minix/commands/m4/Hash.m4
===================================================================
--- trunk/minix/commands/m4/Hash.m4	(revision 9)
+++ 	(revision )
@@ -1,17 +1,0 @@
-dnl	This probably will not run on any m4 that cannot
-dnl	handle char constants in eval.
-dnl
-changequote(<,>) define(HASHVAL,99) dnl
-define(hash,<eval(str(substr($1,1),0)%HASHVAL)>) dnl
-define(str,
-	<ifelse($1,",$2,
-		<str(substr(<$1>,1),<eval($2+'substr($1,0,1)')>)>)
-	>) dnl
-define(KEYWORD,<$1,hash($1),>) dnl
-define(TSTART,
-<struct prehash {
-	char *keyword;
-	int   hashval;
-} keytab[] = {>) dnl
-define(TEND,<	"",0
-};>) dnl
Index: trunk/minix/commands/m4/M4.out
===================================================================
--- trunk/minix/commands/m4/M4.out	(revision 9)
+++ 	(revision )
@@ -1,462 +1,0 @@
-#
-# test file for mp (not comprehensive)
-#
-# v7 m4 does not have `decr'.
-#
-
-#
-# include string macros
-#
-
-
-
-
-
-#
-# create some fortrash strings for an even uglier language
-#
-integer TEXT(5)
-data TEXT(1)/LETt/
-data TEXT(2)/LETe/
-data TEXT(3)/LETx/
-data TEXT(4)/LETt/
-
-data TEXT(5)/EOS/
-
-integer DATA(5)
-data DATA(1)/LETd/
-data DATA(2)/LETa/
-data DATA(3)/LETt/
-data DATA(4)/LETa/
-
-data DATA(5)/EOS/
-
-integer BEGIN(6)
-data BEGIN(1)/LETb/
-data BEGIN(2)/LETe/
-data BEGIN(3)/LETg/
-data BEGIN(4)/LETi/
-data BEGIN(5)/LETn/
-
-data BEGIN(6)/EOS/
-
-integer END(4)
-data END(1)/LETe/
-data END(2)/LETn/
-data END(3)/LETd/
-
-data END(4)/EOS/
-
-integer IF(3)
-data IF(1)/LETi/
-data IF(2)/LETf/
-
-data IF(3)/EOS/
-
-integer THEN(5)
-data THEN(1)/LETt/
-data THEN(2)/LETh/
-data THEN(3)/LETe/
-data THEN(4)/LETn/
-
-data THEN(5)/EOS/
-
-integer ELSE(5)
-data ELSE(1)/LETe/
-data ELSE(2)/LETl/
-data ELSE(3)/LETs/
-data ELSE(4)/LETe/
-
-data ELSE(5)/EOS/
-
-integer CASE(5)
-data CASE(1)/LETc/
-data CASE(2)/LETa/
-data CASE(3)/LETs/
-data CASE(4)/LETe/
-
-data CASE(5)/EOS/
-
-integer REPEAT(7)
-data REPEAT(1)/LETr/
-data REPEAT(2)/LETe/
-data REPEAT(3)/LETp/
-data REPEAT(4)/LETe/
-data REPEAT(5)/LETa/
-data REPEAT(6)/LETt/
-
-data REPEAT(7)/EOS/
-
-integer WHILE(6)
-data WHILE(1)/LETw/
-data WHILE(2)/LETh/
-data WHILE(3)/LETi/
-data WHILE(4)/LETl/
-data WHILE(5)/LETe/
-
-data WHILE(6)/EOS/
-
-integer DEFAULT(8)
-data DEFAULT(1)/LETd/
-data DEFAULT(2)/LETe/
-data DEFAULT(3)/LETf/
-data DEFAULT(4)/LETa/
-data DEFAULT(5)/LETu/
-data DEFAULT(6)/LETl/
-data DEFAULT(7)/LETt/
-
-data DEFAULT(8)/EOS/
-
-integer UNTIL(6)
-data UNTIL(1)/LETu/
-data UNTIL(2)/LETn/
-data UNTIL(3)/LETt/
-data UNTIL(4)/LETi/
-data UNTIL(5)/LETl/
-
-data UNTIL(6)/EOS/
-
-integer FUNCTION(9)
-data FUNCTION(1)/LETf/
-data FUNCTION(2)/LETu/
-data FUNCTION(3)/LETn/
-data FUNCTION(4)/LETc/
-data FUNCTION(5)/LETt/
-data FUNCTION(6)/LETi/
-data FUNCTION(7)/LETo/
-data FUNCTION(8)/LETn/
-
-data FUNCTION(9)/EOS/
-
-integer PROCEDURE(10)
-data PROCEDURE(1)/LETp/
-data PROCEDURE(2)/LETr/
-data PROCEDURE(3)/LETo/
-data PROCEDURE(4)/LETc/
-data PROCEDURE(5)/LETe/
-data PROCEDURE(6)/LETd/
-data PROCEDURE(7)/LETu/
-data PROCEDURE(8)/LETr/
-data PROCEDURE(9)/LETe/
-
-data PROCEDURE(10)/EOS/
-
-integer EXTERNAL(9)
-data EXTERNAL(1)/LETe/
-data EXTERNAL(2)/LETx/
-data EXTERNAL(3)/LETt/
-data EXTERNAL(4)/LETe/
-data EXTERNAL(5)/LETr/
-data EXTERNAL(6)/LETn/
-data EXTERNAL(7)/LETa/
-data EXTERNAL(8)/LETl/
-
-data EXTERNAL(9)/EOS/
-
-integer FORWARD(8)
-data FORWARD(1)/LETf/
-data FORWARD(2)/LETo/
-data FORWARD(3)/LETr/
-data FORWARD(4)/LETw/
-data FORWARD(5)/LETa/
-data FORWARD(6)/LETr/
-data FORWARD(7)/LETd/
-
-data FORWARD(8)/EOS/
-
-integer TYPE(5)
-data TYPE(1)/LETt/
-data TYPE(2)/LETy/
-data TYPE(3)/LETp/
-data TYPE(4)/LETe/
-
-data TYPE(5)/EOS/
-
-integer VAR(4)
-data VAR(1)/LETv/
-data VAR(2)/LETa/
-data VAR(3)/LETr/
-
-data VAR(4)/EOS/
-
-integer CONST(6)
-data CONST(1)/LETc/
-data CONST(2)/LETo/
-data CONST(3)/LETn/
-data CONST(4)/LETs/
-data CONST(5)/LETt/
-
-data CONST(6)/EOS/
-
-integer PROGRAM(8)
-data PROGRAM(1)/LETp/
-data PROGRAM(2)/LETr/
-data PROGRAM(3)/LETo/
-data PROGRAM(4)/LETg/
-data PROGRAM(5)/LETr/
-data PROGRAM(6)/LETa/
-data PROGRAM(7)/LETm/
-
-data PROGRAM(8)/EOS/
-
-integer INPUT(6)
-data INPUT(1)/LETi/
-data INPUT(2)/LETn/
-data INPUT(3)/LETp/
-data INPUT(4)/LETu/
-data INPUT(5)/LETt/
-
-data INPUT(6)/EOS/
-
-integer OUTPUT(7)
-data OUTPUT(1)/LETo/
-data OUTPUT(2)/LETu/
-data OUTPUT(3)/LETt/
-data OUTPUT(4)/LETp/
-data OUTPUT(5)/LETu/
-data OUTPUT(6)/LETt/
-
-data OUTPUT(7)/EOS/
-
-#
-
-
-defined
-#
-# v7 m4 does this wrong. The right output is
-#      this is A vEry lon sEntEnCE
-# see m4 documentation for translit.
-#
-this is A vEry lon sEntEnCE
-#
-# include towers-of-hanoi
-#
-
-
-
-
-
-
-#
-# some reasonable set of disks
-#
-move disk from A to C
-move disk from A to B
-move disk from C to B
-move disk from A to C
-move disk from B to A
-move disk from B to C
-move disk from A to C
-move disk from A to B
-move disk from C to B
-move disk from C to A
-move disk from B to A
-move disk from C to B
-move disk from A to C
-move disk from A to B
-move disk from C to B
-move disk from A to C
-move disk from B to A
-move disk from B to C
-move disk from A to C
-move disk from B to A
-move disk from C to B
-move disk from C to A
-move disk from B to A
-move disk from B to C
-move disk from A to C
-move disk from A to B
-move disk from C to B
-move disk from A to C
-move disk from B to A
-move disk from B to C
-move disk from A to C
-move disk from A to B
-move disk from C to B
-move disk from C to A
-move disk from B to A
-move disk from C to B
-move disk from A to C
-move disk from A to B
-move disk from C to B
-move disk from C to A
-move disk from B to A
-move disk from B to C
-move disk from A to C
-move disk from B to A
-move disk from C to B
-move disk from C to A
-move disk from B to A
-move disk from C to B
-move disk from A to C
-move disk from A to B
-move disk from C to B
-move disk from A to C
-move disk from B to A
-move disk from B to C
-move disk from A to C
-move disk from A to B
-move disk from C to B
-move disk from C to A
-move disk from B to A
-move disk from C to B
-move disk from A to C
-move disk from A to B
-move disk from C to B
-
-#
-# include ackermann's function
-#
-
-
-#
-# something like (3,3) will blow away un*x m4.
-#
-9
-#
-# include a square_root function for fixed nums
-#
-
-
-
-#
-# some square roots.
-#
-3
-10
-negative-square-root
-146
-#
-# some textual material for enjoyment.
-#
-[taken from the 'Clemson University Computer Newsletter',
- September 1981, pp. 6-7]
-
-I am a wizard in the magical Kingdom of Transformation and I
-slay dragons for a living.  Actually, I am a systems programmer.
-One of the problems with systems programming is explaining to
-non-computer enthusiasts what that is.  All of the terms I use to
-describe my job are totally meaningless to them.  Usually my response
-to questions about my work is to say as little as possible.  For
-instance, if someone asks what happened at work this week, I say
-"Nothing much" and then I change the subject.
-
-With the assistance of my brother, a mechanical engineer, I have devised
-an analogy that everyone can understand.  The analogy describes the
-"Kingdom of Transformation" where travelers wander and are magically
-transformed.  This kingdom is the computer and the travelers are information.
-The purpose of the computer is to change information to a more meaningful
-forma.  The law of conservation applies here:  The computer never creates
-and never intentionally destroys data.  With no further ado, let us travel
-to the Kingdom of Transformation:
-
-In a land far, far away, there is a magical kingdom called the Kingdom of
-Transformation.  A king rules over this land and employs a Council of
-Wizardry.  The main purpose of this kingdom is to provide a way for
-neighboring kingdoms to transform citizens into more useful citizens.  This
-is done by allowing the citizens to enter the kingdom at one of its ports
-and to travel any of the many routes in the kingdom.  They are magically
-transformed along the way.  The income of the Kingdom of Transformation
-comes from the many toll roads within its boundaries.
-
-The Kingdom of Transformation was created when several kingdoms got
-together and discovered a mutual need for new talents and abilities for
-citizens.  They employed CTK, Inc. (Creators of Transformation, Inc.) to
-create this kingdom.  CTK designed the country, its transportation routes,
-and its laws of transformation, and created the major highway system.
-
-Hazards
-=======
-
-Because magic is not truly controllable, CTK invariably, but unknowingly,
-creates dragons.  Dragons are huge fire-breathing beasts which sometimes
-injure or kill travelers.  Fortunately, they do not travel, but always
-remain near their den.
-
-Other hazards also exist which are potentially harmful.  As the roads
-become older and more weatherbeaten, pot-holes will develop, trees will
-fall on travelers, etc.  CTK maintenance men are called to fix these
-problems.
-
-Wizards
-=======
-
-The wizards play a major role in creating and maintaining the kingdom but
-get little credit for their work because it is performed secretly.  The
-wizards do not wan the workers or travelers to learn their incantations
-because many laws would be broken and chaos would result.
-
-CTK's grand design is always general enough to be applicable in many
-different situations.  As a result, it is often difficult to use.  The
-first duty of the wizards is to tailor the transformation laws so as to be
-more beneficial and easier to use in their particular environment.
-
-After creation of the kingdom, a major duty of the wizards is to search for
-and kill dragons.  If travelers do not return on time or if they return
-injured, the ruler of the country contacts the wizards.  If the wizards
-determine that the injury or death occurred due to the traveler's
-negligence, they provide the traveler's country with additional warnings.
-If not, they must determine if the cause was a road hazard or a dragon.  If
-the suspect a road hazard, they call in a CTK maintenance man to locate the
-hazard and to eliminate it, as in repairing the pothole in the road.  If
-they think that cause was a dragon, then they must find and slay it.
-
-The most difficult part of eliminating a dragon is finding it.  Sometimes
-the wizard magically knows where the dragon's lair it, but often the wizard
-must send another traveler along the same route and watch to see where he
-disappears.  This sounds like a failsafe method for finding dragons (and a
-suicide mission for thr traveler) but the second traveler does not always
-disappear.  Some dragons eat any traveler who comes too close; others are
-very picky.
-
-The wizards may call in CTK who designed the highway system and
-transformation laws to help devise a way to locate the dragon.  CTK also
-helps provide the right spell or incantation to slay the dragon. (There is
-no general spell to slay dragons; each dragon must be eliminated with a
-different spell.)
-
-Because neither CTK nor wizards are perfect, spells to not always work
-correctly.  At best, nothing happens when the wrong spell is uttered.  At
-worst, the dragon becomes a much larger dragon or multiplies into several
-smaller ones.  In either case, new spells must be found.
-
-If all existing dragons are quiet (i.e. have eaten sufficiently), wizards
-have time to do other things.  They hide in castles and practice spells and
-incatations.  They also devise shortcuts for travelers and new laws of
-transformation.
-
-Changes in the Kingdom
-======================
-
-As new transformation kingdoms are created and old ones are maintained,
-CTK, Inc. is constantly learning new things.  It learns ways to avoid
-creating some of the dragons that they have previously created.  It also
-discovers new and better laws of transformation.  As a result, CTK will
-periodically create a new grand design which is far better than the old.
-The wizards determine when is a good time to implement this new design.
-This is when the tourist season is slow or when no important travelers
-(VIPs) are to arrive.  The kingdom must be closed for the actual
-implementation and is leter reopened as a new and better place to go.
-
-A final question you might ask is what happens when the number of tourists
-becomes too great for the kingdom to handle in a reasonable period of time
-(i.e., the tourist lines at the ports are too long).  The Kingdom of
-Transformation has three options: (1) shorten the paths that a tourist must
-travel, or (2) convince CTK to develop a faster breed of horses so that the
-travelers can finish sooner, or (3) annex more territories so that the
-kingdom can handle more travelers.
-
-Thus ends the story of the Kingdom of Transformation.  I hope this has
-explained my job to you:  I slay dragons for a living.
-
-#
-#should do an automatic undivert..
-#
-
-diversion #1
-
-diversion #2
-
-diversion #3
-
-diversion #4
Index: trunk/minix/commands/m4/Makefile
===================================================================
--- trunk/minix/commands/m4/Makefile	(revision 9)
+++ 	(revision )
@@ -1,27 +1,0 @@
-# Makefile for M4
-
-#	-DEXTENDED	#if you like to get paste & spaste macros.
-#	-DVOID 		#if your C compiler does NOT support void.
-#	-DGETOPT	#if you STILL do not have getopt in your library.
-#	-DDUFFCP	#if you do not have fast memcpy in your library.
-#
-
-CFLAGS = -DEXTENDED -O -D_POSIX_SOURCE -D_MINIX
-CC = exec cc
-
-OBJ =  main.o eval.o serv.o look.o misc.o expr.o
-INCL =  mdef.h extr.h patchlevel.h
-
-all:	m4
-
-m4: $(OBJ) $(INCL)
-	cc -i -o m4 $(OBJ)
-	install -S 4kw m4
-
-install:	/usr/bin/m4
-
-/usr/bin/m4:	m4
-	install -cs -o bin m4 $@
-
-clean:	
-	rm -f *.o m4 core *bak
Index: trunk/minix/commands/m4/READ_ME
===================================================================
--- trunk/minix/commands/m4/READ_ME	(revision 9)
+++ 	(revision )
@@ -1,32 +1,0 @@
-This code *is* PD. You (public) have all the rights to the code.  [But
-this also means you (singular) do not have any *extra* rights to the code,
-hence it is impossible for you to restrict the use and distribution of
-this code (original) in any way.]
-
-Dedication:
-
-This posting is a dedication to an old 750 that started out running 4.1BSD
-and had 1.5 meg, 1 dz11, and 2 Rk07 drives.  It was named yetti [sic] by
-accident, and was managed by the author until its retirement two years
-ago. [the name yetti now identifies a different machine]
-
-If you have any important fixes and/or speed improvements, I am much
-interested. I am also interested in hearing about any unique applica-
-tions of M4. I am NOT interested in gratuitous hacks or "neat"
-kitchen-sink features. 
-
-Author:
-	Usenet: uunet!utai!yunexus!oz || oz@nexus.yorku.ca
-	Bitnet: oz@yulibra.BITNET
-	Phonet: [416] 736-5257 x 3976
-
-
-enjoy.	oz
-
-Testing: 
-
-This directory contains a test file called test.m4.  To use it, type
-
-	m4 <Test.m4 >out
-
-The output file, out, should be identical to M4.out
Index: trunk/minix/commands/m4/Sqroot.m4
===================================================================
--- trunk/minix/commands/m4/Sqroot.m4	(revision 9)
+++ 	(revision )
@@ -1,7 +1,0 @@
-define(square_root, 
-	`ifelse(eval($1<0),1,negative-square-root,
-			     `square_root_aux($1, 1, eval(($1+1)/2))')')
-define(square_root_aux,
-	`ifelse($3, $2, $3,
-		$3, eval($1/$2), $3,
-		`square_root_aux($1, $3, eval(($3+($1/$3))/2))')')
Index: trunk/minix/commands/m4/String.m4
===================================================================
--- trunk/minix/commands/m4/String.m4	(revision 9)
+++ 	(revision )
@@ -1,8 +1,0 @@
-
-define(string,`integer $1(len(substr($2,1)))
-str($1,substr($2,1),0)
-data $1(len(substr($2,1)))/EOS/
-')
-
-define(str,`ifelse($2,",,data $1(incr($3))/`LET'substr($2,0,1)/
-`str($1,substr($2,1),incr($3))')')
Index: trunk/minix/commands/m4/Test.m4
===================================================================
--- trunk/minix/commands/m4/Test.m4	(revision 9)
+++ 	(revision )
@@ -1,206 +1,0 @@
-#
-# test file for mp (not comprehensive)
-#
-# v7 m4 does not have `decr'.
-#
-define(DECR,`eval($1-1)')
-#
-# include string macros
-#
-include(String.m4)
-#
-# create some fortrash strings for an even uglier language
-#
-string(TEXT, "text")
-string(DATA, "data")
-string(BEGIN, "begin")
-string(END, "end")
-string(IF, "if")
-string(THEN, "then")
-string(ELSE, "else")
-string(CASE, "case")
-string(REPEAT, "repeat")
-string(WHILE, "while")
-string(DEFAULT, "default")
-string(UNTIL, "until")
-string(FUNCTION, "function")
-string(PROCEDURE, "procedure")
-string(EXTERNAL, "external")
-string(FORWARD, "forward")
-string(TYPE, "type")
-string(VAR, "var")
-string(CONST, "const")
-string(PROGRAM, "program")
-string(INPUT, "input")
-string(OUTPUT, "output")
-#
-divert(2)
-diversion #1
-divert(3)
-diversion #2
-divert(4)
-diversion #3
-divert(5)
-diversion #4
-divert(0)
-define(abc,xxx)
-ifdef(`abc',defined,undefined)
-#
-# v7 m4 does this wrong. The right output is
-#      this is A vEry lon sEntEnCE
-# see m4 documentation for translit.
-#
-translit(`this is a very long sentence', abcdefg, ABCDEF)
-#
-# include towers-of-hanoi
-#
-include(Hanoi.m4)
-#
-# some reasonable set of disks
-#
-hanoi(6)
-#
-# include ackermann's function
-#
-include(Ack.m4)
-#
-# something like (3,3) will blow away un*x m4.
-#
-ack(2,3)
-#
-# include a square_root function for fixed nums
-#
-include(Sqroot.m4)
-#
-# some square roots.
-#
-square_root(15)
-square_root(100)
-square_root(-4)
-square_root(21372)
-#
-# some textual material for enjoyment.
-#
-[taken from the 'Clemson University Computer Newsletter',
- September 1981, pp. 6-7]
-
-I am a wizard in the magical Kingdom of Transformation and I
-slay dragons for a living.  Actually, I am a systems programmer.
-One of the problems with systems programming is explaining to
-non-computer enthusiasts what that is.  All of the terms I use to
-describe my job are totally meaningless to them.  Usually my response
-to questions about my work is to say as little as possible.  For
-instance, if someone asks what happened at work this week, I say
-"Nothing much" and then I change the subject.
-
-With the assistance of my brother, a mechanical engineer, I have devised
-an analogy that everyone can understand.  The analogy describes the
-"Kingdom of Transformation" where travelers wander and are magically
-transformed.  This kingdom is the computer and the travelers are information.
-The purpose of the computer is to change information to a more meaningful
-forma.  The law of conservation applies here:  The computer never creates
-and never intentionally destroys data.  With no further ado, let us travel
-to the Kingdom of Transformation:
-
-In a land far, far away, there is a magical kingdom called the Kingdom of
-Transformation.  A king rules over this land and employs a Council of
-Wizardry.  The main purpose of this kingdom is to provide a way for
-neighboring kingdoms to transform citizens into more useful citizens.  This
-is done by allowing the citizens to enter the kingdom at one of its ports
-and to travel any of the many routes in the kingdom.  They are magically
-transformed along the way.  The income of the Kingdom of Transformation
-comes from the many toll roads within its boundaries.
-
-The Kingdom of Transformation was created when several kingdoms got
-together and discovered a mutual need for new talents and abilities for
-citizens.  They employed CTK, Inc. (Creators of Transformation, Inc.) to
-create this kingdom.  CTK designed the country, its transportation routes,
-and its laws of transformation, and created the major highway system.
-
-Hazards
-=======
-
-Because magic is not truly controllable, CTK invariably, but unknowingly,
-creates dragons.  Dragons are huge fire-breathing beasts which sometimes
-injure or kill travelers.  Fortunately, they do not travel, but always
-remain near their den.
-
-Other hazards also exist which are potentially harmful.  As the roads
-become older and more weatherbeaten, pot-holes will develop, trees will
-fall on travelers, etc.  CTK maintenance men are called to fix these
-problems.
-
-Wizards
-=======
-
-The wizards play a major role in creating and maintaining the kingdom but
-get little credit for their work because it is performed secretly.  The
-wizards do not wan the workers or travelers to learn their incantations
-because many laws would be broken and chaos would result.
-
-CTK's grand design is always general enough to be applicable in many
-different situations.  As a result, it is often difficult to use.  The
-first duty of the wizards is to tailor the transformation laws so as to be
-more beneficial and easier to use in their particular environment.
-
-After creation of the kingdom, a major duty of the wizards is to search for
-and kill dragons.  If travelers do not return on time or if they return
-injured, the ruler of the country contacts the wizards.  If the wizards
-determine that the injury or death occurred due to the traveler's
-negligence, they provide the traveler's country with additional warnings.
-If not, they must determine if the cause was a road hazard or a dragon.  If
-the suspect a road hazard, they call in a CTK maintenance man to locate the
-hazard and to eliminate it, as in repairing the pothole in the road.  If
-they think that cause was a dragon, then they must find and slay it.
-
-The most difficult part of eliminating a dragon is finding it.  Sometimes
-the wizard magically knows where the dragon's lair it, but often the wizard
-must send another traveler along the same route and watch to see where he
-disappears.  This sounds like a failsafe method for finding dragons (and a
-suicide mission for thr traveler) but the second traveler does not always
-disappear.  Some dragons eat any traveler who comes too close; others are
-very picky.
-
-The wizards may call in CTK who designed the highway system and
-transformation laws to help devise a way to locate the dragon.  CTK also
-helps provide the right spell or incantation to slay the dragon. (There is
-no general spell to slay dragons; each dragon must be eliminated with a
-different spell.)
-
-Because neither CTK nor wizards are perfect, spells to not always work
-correctly.  At best, nothing happens when the wrong spell is uttered.  At
-worst, the dragon becomes a much larger dragon or multiplies into several
-smaller ones.  In either case, new spells must be found.
-
-If all existing dragons are quiet (i.e. have eaten sufficiently), wizards
-have time to do other things.  They hide in castles and practice spells and
-incatations.  They also devise shortcuts for travelers and new laws of
-transformation.
-
-Changes in the Kingdom
-======================
-
-As new transformation kingdoms are created and old ones are maintained,
-CTK, Inc. is constantly learning new things.  It learns ways to avoid
-creating some of the dragons that they have previously created.  It also
-discovers new and better laws of transformation.  As a result, CTK will
-periodically create a new grand design which is far better than the old.
-The wizards determine when is a good time to implement this new design.
-This is when the tourist season is slow or when no important travelers
-(VIPs) are to arrive.  The kingdom must be closed for the actual
-implementation and is leter reopened as a new and better place to go.
-
-A final question you might ask is what happens when the number of tourists
-becomes too great for the kingdom to handle in a reasonable period of time
-(i.e., the tourist lines at the ports are too long).  The Kingdom of
-Transformation has three options: (1) shorten the paths that a tourist must
-travel, or (2) convince CTK to develop a faster breed of horses so that the
-travelers can finish sooner, or (3) annex more territories so that the
-kingdom can handle more travelers.
-
-Thus ends the story of the Kingdom of Transformation.  I hope this has
-explained my job to you:  I slay dragons for a living.
-
-#
-#should do an automatic undivert..
-#
Index: trunk/minix/commands/m4/build
===================================================================
--- trunk/minix/commands/m4/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/m4/eval.c
===================================================================
--- trunk/minix/commands/m4/eval.c	(revision 9)
+++ 	(revision )
@@ -1,331 +1,0 @@
-/*
- * eval.c
- * Facility: m4 macro processor
- * by: oz
- */
-
-#include "mdef.h"
-#include "extr.h"
-
-/*
- * eval - evaluate built-in macros.
- *	  argc - number of elements in argv.
- *	  argv - element vector :
- *			argv[0] = definition of a user
- *				  macro or nil if built-in.
- *			argv[1] = name of the macro or
- *				  built-in.
- *			argv[2] = parameters to user-defined
- *			   .	  macro or built-in.
- *			   .
- *
- * Note that the minimum value for argc is 3. A call in the form
- * of macro-or-builtin() will result in:
- *			argv[0] = nullstr
- *			argv[1] = macro-or-builtin
- *			argv[2] = nullstr
- *
- */
-
-void eval (argv, argc, td)
-register char *argv[];
-register int argc;
-register int  td;
-{
-	register int c, n;
-	static int sysval;
-
-#ifdef DEBUG
-	printf("argc = %d\n", argc);
-	for (n = 0; n < argc; n++)
-		printf("argv[%d] = %s\n", n, argv[n]);
-#endif
-	/*
-	 * if argc == 3 and argv[2] is null,
-	 * then we have macro-or-builtin() type call.
-	 * We adjust argc to avoid further checking..
-	 *
-	 */
-	if (argc == 3 && !*(argv[2]))
-		argc--;
-
-	switch (td & ~STATIC) {
-
-	case DEFITYPE:
-		if (argc > 2)
-			dodefine(argv[2], (argc > 3) ? argv[3] : null);
-		break;
-
-	case PUSDTYPE:
-		if (argc > 2)
-			dopushdef(argv[2], (argc > 3) ? argv[3] : null);
-		break;
-
-	case DUMPTYPE:
-		dodump(argv, argc);
-		break;
-
-	case EXPRTYPE:
-		/*
-		 * doexpr - evaluate arithmetic expression
-		 *
-		 */
-		if (argc > 2)
-			pbnum(expr(argv[2]));
-		break;
-
-	case IFELTYPE:
-		if (argc > 4)
-			doifelse(argv, argc);
-		break;
-
-	case IFDFTYPE:
-		/*
-		 * doifdef - select one of two alternatives based
-		 *	     on the existence of another definition
-		 */
-		if (argc > 3) {
-			if (lookup(argv[2]) != nil)
-				pbstr(argv[3]);
-			else if (argc > 4)
-				pbstr(argv[4]);
-		}
-		break;
-
-	case LENGTYPE:
-		/*
-		 * dolen - find the length of the argument
-		 *
-		 */
-		if (argc > 2)
-			pbnum((argc > 2) ? strlen(argv[2]) : 0);
-		break;
-
-	case INCRTYPE:
-		/*
-		 * doincr - increment the value of the argument
-		 *
-		 */
-		if (argc > 2)
-			pbnum(atoi(argv[2]) + 1);
-		break;
-
-	case DECRTYPE:
-		/*
-		 * dodecr - decrement the value of the argument
-		 *
-		 */
-		if (argc > 2)
-			pbnum(atoi(argv[2]) - 1);
-		break;
-
-#if unix || vms
-
-	case SYSCTYPE:
-		/*
-		 * dosys - execute system command
-		 *
-		 */
-		if (argc > 2)
-			sysval = system(argv[2]);
-		break;
-
-	case SYSVTYPE:
-		/*
-		 * dosysval - return value of the last system call.
-		 *
-		 */
-		pbnum(sysval);
-		break;
-#endif
-
-	case INCLTYPE:
-		if (argc > 2)
-			if (!doincl(argv[2])) {
-				fprintf(stderr,"m4: %s: ",argv[2]);
-				error("cannot open for read.");
-			}
-		break;
-
-	case SINCTYPE:
-		if (argc > 2)
-			(void) doincl(argv[2]);
-		break;
-#ifdef EXTENDED
-	case PASTTYPE:
-		if (argc > 2)
-			if (!dopaste(argv[2])) {
-				fprintf(stderr,"m4: %s: ",argv[2]);
-				error("cannot open for read.");
-			}
-		break;
-
-	case SPASTYPE:
-		if (argc > 2)
-			(void) dopaste(argv[2]);
-		break;
-#endif
-	case CHNQTYPE:
-		dochq(argv, argc);
-		break;
-
-	case CHNCTYPE:
-		dochc(argv, argc);
-		break;
-
-	case SUBSTYPE:
-		/*
-		 * dosub - select substring
-		 *
-		 */
-		if (argc > 3)
-			dosub(argv,argc);
-		break;
-
-	case SHIFTYPE:
-		/*
-		 * doshift - push back all arguments except the
-		 *	     first one (i.e. skip argv[2])
-		 */
-		if (argc > 3) {
-			for (n = argc-1; n > 3; n--) {
-				putback(rquote);
-				pbstr(argv[n]);
-				putback(lquote);
-				putback(',');
-			}
-			putback(rquote);
-			pbstr(argv[3]);
-			putback(lquote);
-		}
-		break;
-
-	case DIVRTYPE:
-		if (argc > 2 && (n = atoi(argv[2])) != 0)
-			dodiv(n);
-		else {
-			active = stdout;
-			oindex = 0;
-		}
-		break;
-
-	case UNDVTYPE:
-		doundiv(argv, argc);
-		break;
-
-	case DIVNTYPE:
-		/*
-		 * dodivnum - return the number of current
-		 * output diversion
-		 *
-		 */
-		pbnum(oindex);
-		break;
-
-	case UNDFTYPE:
-		/*
-		 * doundefine - undefine a previously defined
-		 *		macro(s) or m4 keyword(s).
-		 */
-		if (argc > 2)
-			for (n = 2; n < argc; n++)
-				remhash(argv[n], ALL);
-		break;
-
-	case POPDTYPE:
-		/*
-		 * dopopdef - remove the topmost definitions of
-		 *	      macro(s) or m4 keyword(s).
-		 */
-		if (argc > 2)
-			for (n = 2; n < argc; n++)
-				remhash(argv[n], TOP);
-		break;
-
-	case MKTMTYPE:
-		/*
-		 * dotemp - create a temporary file
-		 *
-		 */
-		if (argc > 2)
-			pbstr(mktemp(argv[2]));
-		break;
-
-	case TRNLTYPE:
-		/*
-		 * dotranslit - replace all characters in the
-		 *		source string that appears in
-		 *		the "from" string with the corresponding
-		 *		characters in the "to" string.
-		 *
-		 */
-		if (argc > 3) {
-			char temp[MAXTOK];
-			if (argc > 4)
-				map(temp, argv[2], argv[3], argv[4]);
-			else
-				map(temp, argv[2], argv[3], null);
-			pbstr(temp);
-		}
-		else
-		    if (argc > 2)
-			pbstr(argv[2]);
-		break;
-
-	case INDXTYPE:
-		/*
-		 * doindex - find the index of the second argument
-		 *	     string in the first argument string.
-		 *	     -1 if not present.
-		 */
-		pbnum((argc > 3) ? indx(argv[2], argv[3]) : -1);
-		break;
-
-	case ERRPTYPE:
-		/*
-		 * doerrp - print the arguments to stderr file
-		 *
-		 */
-		if (argc > 2) {
-			for (n = 2; n < argc; n++)
-				fprintf(stderr,"%s ", argv[n]);
-			fprintf(stderr, "\n");
-		}
-		break;
-
-	case DNLNTYPE:
-		/*
-		 * dodnl - eat-up-to and including newline
-		 *
-		 */
-		while ((c = gpbc()) != '\n' && c != EOF)
-			;
-		break;
-
-	case M4WRTYPE:
-		/*
-		 * dom4wrap - set up for wrap-up/wind-down activity
-		 *
-		 */
-		m4wraps = (argc > 2) ? strsave(argv[2]) : null;
-		break;
-
-	case EXITTYPE:
-		/*
-		 * doexit - immediate exit from m4.
-		 *
-		 */
-		exit((argc > 2) ? atoi(argv[2]) : 0);
-		break;
-
-	case DEFNTYPE:
-		if (argc > 2)
-			for (n = 2; n < argc; n++)
-				dodefn(argv[n]);
-		break;
-
-	default:
-		error("m4: major botch in eval.");
-		break;
-	}
-}
Index: trunk/minix/commands/m4/expr.c
===================================================================
--- trunk/minix/commands/m4/expr.c	(revision 9)
+++ 	(revision )
@@ -1,587 +1,0 @@
-/*
- *      expression evaluator: performs a standard recursive
- *      descent parse to evaluate any expression permissible
- *      within the following grammar:
- *
- *      expr    :       query EOS
- *      query   :       lor
- *              |       lor "?" query ":" query
- *      lor     :       land { "||" land }
- *      land    :       bor { "&&" bor }
- *      bor     :       bxor { "|" bxor }
- *      bxor    :       band { "^" band }
- *      band    :       eql { "&" eql }
- *      eql     :       relat { eqrel relat }
- *      relat   :       shift { rel shift }
- *      shift   :       primary { shop primary }
- *      primary :       term { addop term }
- *      term    :       unary { mulop unary }
- *      unary   :       factor
- *              |       unop unary
- *      factor  :       constant
- *              |       "(" query ")"
- *      constant:       num
- *              |       "'" CHAR "'"
- *      num     :       decnum
- *              |       "0" octnum
- *		|	"0x" hexnum
- *	octnum	:	OCTDIGIT
- *		|	OCTDIGIT octnum
- *	decnum	:	DECDIGIT
- *		|	DECDIGIT decnum
- *	hexnum	:	HEXDIGIT
- *		|	HEXDIGIT hexnum
- *      shop    :       "<<"
- *              |       ">>"
- *      eqlrel  :       "="
- *              |       "=="
- *              |       "!="
- *      rel     :       "<"
- *              |       ">"
- *              |       "<="
- *              |       ">="
- *
- *
- *      This expression evaluator is lifted from a public-domain
- *      C Pre-Processor included with the DECUS C Compiler distribution.
- *      It is hacked somewhat to be suitable for m4.
- *
- *      Originally by:  Mike Lutz
- *                      Bob Harper
- */
- 
-#include "mdef.h"
-
-#define TRUE    1
-#define FALSE   0
-#define EOS     (char) 0
-#define EQL     0
-#define NEQ     1
-#define LSS     2
-#define LEQ     3
-#define GTR     4
-#define GEQ     5
- 
-static char *nxtch;     /* Parser scan pointer */
- 
-/*
- * For longjmp
- */
-#include <setjmp.h>
-static jmp_buf  expjump;
- 
-/*
- * macros:
- *
- *      ungetch - Put back the last character examined.
- *      getch   - return the next character from expr string.
- */
-#define ungetch()       nxtch--
-#define getch()         *nxtch++
- 
-int expr(expbuf)
-char *expbuf;
-{
-        register int rval;
- 
-        nxtch = expbuf;
-        if (setjmp(expjump) != 0)
-                return (FALSE);
-        rval = query();
-        if (skipws() == EOS)
-                return(rval);
-        experr("Ill-formed expression");
-	/* NOTREACHED */
-	return(0);
-}
- 
-/*
- * query : lor | lor '?' query ':' query
- *
- */
-int query()
-{
-        register int bool, true_val, false_val;
- 
-        bool = lor();
-        if (skipws() != '?') {
-                ungetch();
-                return(bool);
-        }
- 
-        true_val = query();
-        if (skipws() != ':')
-                experr("Bad query");
- 
-        false_val = query();
-        return(bool ? true_val : false_val);
-}
- 
-/*
- * lor : land { '||' land }
- *
- */
-int lor()
-{
-        register int c, vl, vr;
- 
-        vl = land();
-        while ((c = skipws()) == '|' && getch() == '|') {
-                vr = land();
-                vl = vl || vr;
-        }
- 
-        if (c == '|')
-                ungetch();
-        ungetch();
-        return(vl);
-}
- 
-/*
- * land : bor { '&&' bor }
- *
- */
-int land()
-{
-        register int c, vl, vr;
- 
-        vl = bor();
-        while ((c = skipws()) == '&' && getch() == '&') {
-                vr = bor();
-                vl = vl && vr;
-        }
- 
-        if (c == '&')
-                ungetch();
-        ungetch();
-        return(vl);
-}
- 
-/*
- * bor : bxor { '|' bxor }
- *
- */
-int bor()
-{
-        register int vl, vr, c;
- 
-        vl = bxor();
-        while ((c = skipws()) == '|' && getch() != '|') {
-                ungetch();
-                vr = bxor();
-                vl |= vr;
-        }
- 
-        if (c == '|')
-                ungetch();
-        ungetch();
-        return(vl);
-}
- 
-/*
- * bxor : band { '^' band }
- *
- */
-int bxor()
-{
-        register int vl, vr;
- 
-        vl = band();
-        while (skipws() == '^') {
-                vr = band();
-                vl ^= vr;
-        }
- 
-        ungetch();
-        return(vl);
-}
- 
-/*
- * band : eql { '&' eql }
- *
- */
-int band()
-{
-        register int vl, vr, c;
- 
-        vl = eql();
-        while ((c = skipws()) == '&' && getch() != '&') {
-                ungetch();
-                vr = eql();
-                vl &= vr;
-        }
- 
-        if (c == '&')
-                ungetch();
-        ungetch();
-        return(vl);
-}
- 
-/*
- * eql : relat { eqrel relat }
- *
- */
-int eql()
-{
-        register int vl, vr, rel;
- 
-        vl = relat();
-        while ((rel = geteql()) != -1) {
-                vr = relat();
- 
-                switch (rel) {
- 
-                case EQL:
-                        vl = (vl == vr);
-                        break;
-                case NEQ:
-                        vl = (vl != vr);
-                        break;
-                }
-        }
-        return(vl);
-}
- 
-/*
- * relat : shift { rel shift }
- *
- */
-int relat()
-{
-        register int vl, vr, rel;
- 
-        vl = shift();
-        while ((rel = getrel()) != -1) {
- 
-                vr = shift();
-                switch (rel) {
- 
-                case LEQ:
-                        vl = (vl <= vr);
-                        break;
-                case LSS:
-                        vl = (vl < vr);
-                        break;
-                case GTR:
-                        vl = (vl > vr);
-                        break;
-                case GEQ:
-                        vl = (vl >= vr);
-                        break;
-                }
-        }
-        return(vl);
-}
- 
-/*
- * shift : primary { shop primary }
- *
- */
-int shift()
-{
-        register int vl, vr, c;
- 
-        vl = primary();
-        while (((c = skipws()) == '<' || c == '>') && c == getch()) {
-                vr = primary();
- 
-                if (c == '<')
-                        vl <<= vr;
-                else
-                        vl >>= vr;
-        }
- 
-        if (c == '<' || c == '>')
-                ungetch();
-        ungetch();
-        return(vl);
-}
- 
-/*
- * primary : term { addop term }
- *
- */
-int primary()
-{
-        register int c, vl, vr;
- 
-        vl = term();
-        while ((c = skipws()) == '+' || c == '-') {
-                vr = term();
-                if (c == '+')
-                        vl += vr;
-                else
-                        vl -= vr;
-        }
- 
-        ungetch();
-        return(vl);
-}
- 
-/*
- * <term> := <unary> { <mulop> <unary> }
- *
- */
-int term()
-{
-        register int c, vl, vr;
- 
-        vl = unary();
-        while ((c = skipws()) == '*' || c == '/' || c == '%') {
-                vr = unary();
- 
-                switch (c) {
-                case '*':
-                        vl *= vr;
-                        break;
-                case '/':
-                        vl /= vr;
-                        break;
-                case '%':
-                        vl %= vr;
-                        break;
-                }
-        }
-        ungetch();
-        return(vl);
-}
- 
-/*
- * unary : factor | unop unary
- *
- */
-int unary()
-{
-        register int val, c;
- 
-        if ((c = skipws()) == '!' || c == '~' || c == '-') {
-                val = unary();
- 
-                switch (c) {
-                case '!':
-                        return(! val);
-                case '~':
-                        return(~ val);
-                case '-':
-                        return(- val);
-                }
-        }
- 
-        ungetch();
-        return(factor());
-}
- 
-/*
- * factor : constant | '(' query ')'
- *
- */
-int factor()
-{
-        register int val;
- 
-        if (skipws() == '(') {
-                val = query();
-                if (skipws() != ')')
-                        experr("Bad factor");
-                return(val);
-        }
- 
-        ungetch();
-        return(constant());
-}
- 
-/*
- * constant: num | 'char'
- *
- */
-int constant()
-{
-        /*
-         * Note: constant() handles multi-byte constants
-         */
- 
-        register int    i;
-        register int    value;
-        register char   c;
-        int             v[sizeof (int)];
- 
-        if (skipws() != '\'') {
-                ungetch();
-                return(num());
-        }
-        for (i = 0; i < sizeof(int); i++) {
-                if ((c = getch()) == '\'') {
-                        ungetch();
-                        break;
-                }
-                if (c == '\\') {
-                        switch (c = getch()) {
-                        case '0':
-                        case '1':
-                        case '2':
-                        case '3':
-                        case '4':
-                        case '5':
-                        case '6':
-                        case '7':
-                                ungetch();
-                                c = num();
-                                break;
-                        case 'n':
-                                c = 012;
-                                break;
-                        case 'r':
-                                c = 015;
-                                break;
-                        case 't':
-                                c = 011;
-                                break;
-                        case 'b':
-                                c = 010;
-                                break;
-                        case 'f':
-                                c = 014;
-                                break;
-                        }
-                }
-                v[i] = c;
-        }
-        if (i == 0 || getch() != '\'')
-                experr("Illegal character constant");
-        for (value = 0; --i >= 0;) {
-                value <<= 8;
-                value += v[i];
-        }
-        return(value);
-}
- 
-/*
- * num : digit | num digit
- *
- */
-int num()
-{
-        register int rval, c, base;
-        int ndig;
- 
-        ndig = 0;
-        if ((c = skipws()) == '0') {
-        	c = getch ();
-        	if (c == 'x' || c == 'X') {
-        		base = 16;
-        		c = getch ();
-        	} else {
-        		base = 8;
-        		ndig = 1;
-        	}
-        } else {
-        	base = 10;
-        }
-        rval = 0;
-        for (;;) {
-		if (isdigit(c))         c -= '0';
-		else if (isupper (c))   c -= ('A' - 10);
-		else if (islower (c))   c -= ('a' - 10);
-		else                    break;
-		if (c < 0 || c >= base)
-			break;
-
-                rval *= base;
-                rval += c;
-                c = getch();
-                ndig++;
-        }
-        ungetch();
-        if (ndig)
-                return(rval);
-        experr("Bad constant");
-	/* NOTREACHED */
-	return(0);
-}
- 
-/*
- * eqlrel : '=' | '==' | '!='
- *
- */
-int geteql()
-{
-        register int c1, c2;
- 
-        c1 = skipws();
-        c2 = getch();
- 
-        switch (c1) {
- 
-        case '=':
-                if (c2 != '=')
-                        ungetch();
-                return(EQL);
- 
-        case '!':
-                if (c2 == '=')
-                        return(NEQ);
-                ungetch();
-                ungetch();
-                return(-1);
- 
-        default:
-                ungetch();
-                ungetch();
-                return(-1);
-        }
-}
- 
-/*
- * rel : '<' | '>' | '<=' | '>='
- *
- */
-int getrel()
-{
-        register int c1, c2;
- 
-        c1 = skipws();
-        c2 = getch();
- 
-        switch (c1) {
- 
-        case '<':
-                if (c2 == '=')
-                        return(LEQ);
-                ungetch();
-                return(LSS);
- 
-        case '>':
-                if (c2 == '=')
-                        return(GEQ);
-                ungetch();
-                return(GTR);
- 
-        default:
-                ungetch();
-                ungetch();
-                return(-1);
-        }
-}
- 
-/*
- * Skip over any white space and return terminating char.
- */
-int skipws()
-{
-        register char c;
- 
-        while ((c = getch()) <= ' ' && c > EOS)
-                ;
-        return(c);
-}
- 
-/*
- * Error handler - resets environment to eval(), prints an error,
- * and returns FALSE.
- */
-int experr(msg)
-char *msg;
-{
-        printf("mp: %s\n",msg);
-        longjmp(expjump, -1);          /* Force eval() to return FALSE */
-}
Index: trunk/minix/commands/m4/extr.h
===================================================================
--- trunk/minix/commands/m4/extr.h	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-extern ndptr hashtab[];		/* hash table for macros etc.  */
-extern char buf[];		/* push-back buffer	       */
-extern char *bp;		/* first available character   */
-extern char *endpbb;		/* end of push-back buffer     */
-extern stae mstack[];		/* stack of m4 machine         */
-extern char *ep;		/* first free char in strspace */
-extern char *endest;		/* end of string space	       */
-extern int sp; 			/* current m4  stack pointer   */
-extern int fp; 			/* m4 call frame pointer       */
-extern FILE *infile[];		/* input file stack (0=stdin)  */
-extern FILE *outfile[];		/* diversion array(0=bitbucket)*/
-extern FILE *active;		/* active output file pointer  */
-extern char *m4temp;		/* filename for diversions     */
-extern int ilevel;		/* input file stack pointer    */
-extern int oindex;		/* diversion index..	       */
-extern char *null;		/* as it says.. just a null..  */
-extern char *m4wraps;		/* m4wrap string default..     */
-extern char lquote;		/* left quote character  (`)   */
-extern char rquote;		/* right quote character (')   */
-extern char scommt;		/* start character for comment */
-extern char ecommt;		/* end character for comment   */
Index: trunk/minix/commands/m4/look.c
===================================================================
--- trunk/minix/commands/m4/look.c	(revision 9)
+++ 	(revision )
@@ -1,110 +1,0 @@
-/*
- * look.c
- * Facility: m4 macro processor
- * by: oz
- */
-
-#include "mdef.h"
-#include "extr.h"
-
-/*
- *  hash - compute hash value using the proverbial
- *	   hashing function. Taken from K&R.
- */
-int hash (name)
-register char *name;
-{
-	register int h = 0;
-	while (*name)
-		h += *name++;
-	return (h % HASHSIZE);
-}
-
-/*
- * lookup - find name in the hash table
- *
- */
-ndptr lookup(name)
-char *name;
-{
-	register ndptr p;
-
-	for (p = hashtab[hash(name)]; p != nil; p = p->nxtptr)
-		if (strcmp(name, p->name) == 0)
-			break;
-	return (p);
-}
-
-/*
- * addent - hash and create an entry in the hash
- *	    table. The new entry is added in front
- *	    of a hash bucket.
- */
-ndptr addent(name)
-char *name;
-{
-	register int h;
-	ndptr p;
-
-	h = hash(name);
-	if ((p = (ndptr) malloc(sizeof(struct ndblock))) != NULL) {
-		p->nxtptr = hashtab[h];
-		hashtab[h] = p;
-		p->name = strsave(name);
-	}
-	else
-		error("m4: no more memory.");
-	return p;
-}
-
-/*
- * remhash - remove an entry from the hashtable
- *
- */
-void remhash(name, all)
-char *name;
-int all;
-{
-	register int h;
-	register ndptr xp, tp, mp;
-
-	h = hash(name);
-	mp = hashtab[h];
-	tp = nil;
-	while (mp != nil) {
-		if (strcmp(mp->name, name) == 0) {
-			mp = mp->nxtptr;
-			if (tp == nil) {
-				freent(hashtab[h]);
-				hashtab[h] = mp;
-			}
-			else {
-				xp = tp->nxtptr;
-				tp->nxtptr = mp;
-				freent(xp);
-			}
-			if (!all)
-				break;
-		}
-		else {
-			tp = mp;
-			mp = mp->nxtptr;
-		}
-	}
-}
-
-/*
- * freent - free a hashtable information block
- *
- */
-void freent(p)
-ndptr p;
-{
-	if (!(p->type & STATIC)) {
-		free(p->name);
-		if (p->defn != null)
-			free(p->defn);
-	}
-	free(p);
-}
-
Index: trunk/minix/commands/m4/main.c
===================================================================
--- trunk/minix/commands/m4/main.c	(revision 9)
+++ 	(revision )
@@ -1,457 +1,0 @@
-/*
- * main.c
- * Facility: m4 macro processor
- * by: oz
- */
-
-#include "mdef.h"
-
-/*
- * m4 - macro processor
- *
- * PD m4 is based on the macro tool distributed with the software 
- * tools (VOS) package, and described in the "SOFTWARE TOOLS" and 
- * "SOFTWARE TOOLS IN PASCAL" books. It has been expanded to include 
- * most of the command set of SysV m4, the standard UN*X macro processor.
- *
- * Since both PD m4 and UN*X m4 are based on SOFTWARE TOOLS macro,
- * there may be certain implementation similarities between
- * the two. The PD m4 was produced without ANY references to m4
- * sources.
- *
- * References:
- *
- *	Software Tools distribution: macro
- *
- *	Kernighan, Brian W. and P. J. Plauger, SOFTWARE
- *	TOOLS IN PASCAL, Addison-Wesley, Mass. 1981
- *
- *	Kernighan, Brian W. and P. J. Plauger, SOFTWARE
- *	TOOLS, Addison-Wesley, Mass. 1976
- *
- *	Kernighan, Brian W. and Dennis M. Ritchie,
- *	THE M4 MACRO PROCESSOR, Unix Programmer's Manual,
- *	Seventh Edition, Vol. 2, Bell Telephone Labs, 1979
- *
- *	System V man page for M4
- *
- * Modification History:
- *
- * Jan 28 1986 Oz	Break the whole thing into little
- *			pieces, for easier (?) maintenance.
- *
- * Dec 12 1985 Oz	Optimize the code, try to squeeze
- *			few microseconds out..
- *
- * Dec 05 1985 Oz	Add getopt interface, define (-D),
- *			undefine (-U) options.
- *
- * Oct 21 1985 Oz	Clean up various bugs, add comment handling.
- *
- * June 7 1985 Oz	Add some of SysV m4 stuff (m4wrap, pushdef,
- *			popdef, decr, shift etc.).
- *
- * June 5 1985 Oz	Initial cut.
- *
- * Implementation Notes:
- *
- * [1]	PD m4 uses a different (and simpler) stack mechanism than the one 
- *	described in Software Tools and Software Tools in Pascal books. 
- *	The triple stack nonsense is replaced with a single stack containing 
- *	the call frames and the arguments. Each frame is back-linked to a 
- * 	previous stack frame, which enables us to rewind the stack after 
- * 	each nested call is completed. Each argument is a character pointer 
- *	to the beginning of the argument string within the string space.
- *	The only exceptions to this are (*) arg 0 and arg 1, which are
- * 	the macro definition and macro name strings, stored dynamically
- *	for the hash table.
- *
- *	    .					   .
- *	|   .	|  <-- sp			|  .  |
- *	+-------+				+-----+
- *	| arg 3 ------------------------------->| str |
- *	+-------+				|  .  |
- *	| arg 2 --------------+ 		   .
- *	+-------+	      |
- *	    *		      |			|     |
- *	+-------+	      | 		+-----+
- *	| plev	|  <-- fp     +---------------->| str |
- *	+-------+				|  .  |
- *	| type	|				   .
- *	+-------+
- *	| prcf	-----------+		plev: paren level
- *	+-------+  	   |		type: call type
- *	|   .	| 	   |		prcf: prev. call frame
- *	    .	   	   |
- *	+-------+	   |
- *	|	<----------+
- *	+-------+
- *
- * [2]	We have three types of null values:
- *
- *		nil  - nodeblock pointer type 0
- *		null - null string ("")
- *		NULL - Stdio-defined NULL
- *
- */
-
-ndptr hashtab[HASHSIZE];	/* hash table for macros etc.  */
-char buf[BUFSIZE];		/* push-back buffer	       */
-char *bp = buf; 		/* first available character   */
-char *endpbb = buf+BUFSIZE;	/* end of push-back buffer     */
-stae mstack[STACKMAX+1]; 	/* stack of m4 machine         */
-char strspace[STRSPMAX+1];	/* string space for evaluation */
-char *ep = strspace;		/* first free char in strspace */
-char *endest= strspace+STRSPMAX;/* end of string space	       */
-int sp; 			/* current m4  stack pointer   */
-int fp; 			/* m4 call frame pointer       */
-FILE *infile[MAXINP];		/* input file stack (0=stdin)  */
-FILE *outfile[MAXOUT];		/* diversion array(0=bitbucket)*/
-FILE *active;			/* active output file pointer  */
-char *m4temp;			/* filename for diversions     */
-int ilevel = 0; 		/* input file stack pointer    */
-int oindex = 0; 		/* diversion index..	       */
-char *null = "";                /* as it says.. just a null..  */
-char *m4wraps = "";             /* m4wrap string default..     */
-char lquote = LQUOTE;		/* left quote character  (`)   */
-char rquote = RQUOTE;		/* right quote character (')   */
-char scommt = SCOMMT;		/* start character for comment */
-char ecommt = ECOMMT;		/* end character for comment   */
-struct keyblk keywrds[] = {	/* m4 keywords to be installed */
-	"include",      INCLTYPE,
-	"sinclude",     SINCTYPE,
-	"define",       DEFITYPE,
-	"defn",         DEFNTYPE,
-	"divert",       DIVRTYPE,
-	"expr",         EXPRTYPE,
-	"eval",         EXPRTYPE,
-	"substr",       SUBSTYPE,
-	"ifelse",       IFELTYPE,
-	"ifdef",        IFDFTYPE,
-	"len",          LENGTYPE,
-	"incr",         INCRTYPE,
-	"decr",         DECRTYPE,
-	"dnl",          DNLNTYPE,
-	"changequote",  CHNQTYPE,
-	"changecom",    CHNCTYPE,
-	"index",        INDXTYPE,
-#ifdef EXTENDED
-	"paste",        PASTTYPE,
-	"spaste",       SPASTYPE,
-#endif
-	"popdef",       POPDTYPE,
-	"pushdef",      PUSDTYPE,
-	"dumpdef",      DUMPTYPE,
-	"shift",        SHIFTYPE,
-	"translit",     TRNLTYPE,
-	"undefine",     UNDFTYPE,
-	"undivert",     UNDVTYPE,
-	"divnum",       DIVNTYPE,
-	"maketemp",     MKTMTYPE,
-	"errprint",     ERRPTYPE,
-	"m4wrap",       M4WRTYPE,
-	"m4exit",       EXITTYPE,
-#if unix || vms
-	"syscmd",       SYSCTYPE,
-	"sysval",       SYSVTYPE,
-#endif
-#if unix
-	"unix",         MACRTYPE,
-#else
-#if vms
-	"vms",          MACRTYPE,
-#endif
-#endif
-};
-
-#define MAXKEYS	(sizeof(keywrds)/sizeof(struct keyblk))
-
-extern int optind;
-extern char *optarg;
-
-int main(argc,argv)
-int argc;
-char *argv[];
-{
-	register int c;
-	register int n;
-	char *p;
-	static char divnam[] = DIVNAM;
-
-	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
-		signal(SIGINT, onintr);
-#ifdef NONZEROPAGES
-	initm4();
-#endif
-	initkwds();
-
-	while ((c = getopt(argc, argv, "tD:U:o:")) != EOF) {
-		switch(c) {
-
-		case 'D':               /* define something..*/
-			for (p = optarg; *p; p++)
-				if (*p == '=')
-					break;
-			if (*p)
-				*p++ = EOS;
-			dodefine(optarg, p);
-			break;
-		case 'U':               /* undefine...       */
-			remhash(optarg, TOP);
-			break;
-		case 'o':		/* specific output   */
-		case '?':
-		default:
-			usage();
-		}
-	}
-
-	argc -= optind;
-	argv += optind;
-
-	if(argc > 1) { usage(); }
-	infile[0] = stdin;		/* default input (naturally) */
-	if(argc == 1) {
-		if(!(infile[0] = fopen(argv[0], "r"))) {
-			perror(argv[0]);
-			return 1;
-		}
-	}
-
-	active = stdout;		/* default active output     */
-	m4temp = mktemp(divnam);	/* filename for diversions   */
-
-	sp = -1;			/* stack pointer initialized */
-	fp = 0; 			/* frame pointer initialized */
-
-	macro();			/* get some work done here   */
-
-	if (*m4wraps) { 		/* anything for rundown ??   */
-		ilevel = 0;		/* in case m4wrap includes.. */
-		putback(EOF);		/* eof is a must !!	     */
-		pbstr(m4wraps); 	/* user-defined wrapup act   */
-		macro();		/* last will and testament   */
-	}
-	else				/* default wrap-up: undivert */
-		for (n = 1; n < MAXOUT; n++)
-			if (outfile[n] != NULL)
-				getdiv(n);
-
-					/* remove bitbucket if used  */
-	if (outfile[0] != NULL) {
-		(void) fclose(outfile[0]);
-		m4temp[UNIQUE] = '0';
-#if vms
-		(void) remove(m4temp);
-#else
-		(void) unlink(m4temp);
-#endif
-	}
-
-	exit(0);
-}
-
-/*
- * macro - the work horse..
- *
- */
-void macro() {
-	char token[MAXTOK];
-	register char *s;
-	register int t, l;
-	register ndptr p;
-	register int  nlpar;
-
-	cycle {
-		if ((t = gpbc()) == '_' || isalpha(t)) {
-			putback(t);
-			if ((p = inspect(s = token)) == nil) {
-				if (sp < 0)
-					while (*s)
-						putc(*s++, active);
-				else
-					while (*s)
-						chrsave(*s++);
-			}
-			else {
-		/*
-		 * real thing.. First build a call frame:
-		 *
-		 */
-				pushf(fp);	/* previous call frm */
-				pushf(p->type); /* type of the call  */
-				pushf(0);	/* parenthesis level */
-				fp = sp;	/* new frame pointer */
-		/*
-		 * now push the string arguments:
-		 *
-		 */
-				pushs(p->defn);	      /* defn string */
-				pushs(p->name);	      /* macro name  */
-				pushs(ep);	      /* start next..*/
-
-				putback(l = gpbc());
-				if (l != LPAREN)  {   /* add bracks  */
-					putback(RPAREN);
-					putback(LPAREN);
-				}
-			}
-		}
-		else if (t == EOF) {
-			if (sp > -1)
-				error("m4: unexpected end of input");
-			if (--ilevel < 0)
-				break;			/* all done thanks.. */
-			(void) fclose(infile[ilevel+1]);
-			continue;
-		}
-	/*
-	 * non-alpha single-char token seen..
-	 * [the order of else if .. stmts is
-	 * important.]
-	 *
-	 */
-		else if (t == lquote) { 		/* strip quotes */
-			nlpar = 1;
-			do {
-				if ((l = gpbc()) == rquote)
-					nlpar--;
-				else if (l == lquote)
-					nlpar++;
-				else if (l == EOF)
-					error("m4: missing right quote");
-				if (nlpar > 0) {
-					if (sp < 0)
-						putc(l, active);
-					else
-						chrsave(l);
-				}
-			}
-			while (nlpar != 0);
-		}
-
-		else if (sp < 0) {		/* not in a macro at all */
-			if (t == scommt) {	/* comment handling here */
-				putc(t, active);
-				while ((t = gpbc()) != ecommt)
-					putc(t, active);
-			}
-			putc(t, active);	/* output directly..	 */
-		}
-
-		else switch(t) {
-
-		case LPAREN:
-			if (PARLEV > 0)
-				chrsave(t);
-			while (isspace(l = gpbc()))
-				;		/* skip blank, tab, nl.. */
-			putback(l);
-			PARLEV++;
-			break;
-
-		case RPAREN:
-			if (--PARLEV > 0)
-				chrsave(t);
-			else {			/* end of argument list */
-				chrsave(EOS);
-
-				if (sp == STACKMAX)
-					error("m4: internal stack overflow");
-
-				if (CALTYP == MACRTYPE)
-					expand((char**)mstack+fp+1,(int)sp-fp);
-				else
-					eval((char**)mstack+fp+1,sp-fp,CALTYP);
-
-				ep = PREVEP;	/* flush strspace */
-				sp = PREVSP;	/* previous sp..  */
-				fp = PREVFP;	/* rewind stack...*/
-			}
-			break;
-
-		case COMMA:
-			if (PARLEV == 1)	{
-				chrsave(EOS);		/* new argument   */
-				while (isspace(l = gpbc()))
-					;
-				putback(l);
-				pushs(ep);
-			}
-			break;
-		default:
-			chrsave(t);			/* stack the char */
-			break;
-		}
-	}
-}
-
-
-/*
- * build an input token..
- * consider only those starting with _ or A-Za-z. This is a
- * combo with lookup to speed things up.
- */
-ndptr
-inspect(tp) 
-register char *tp;
-{
-	register int h = 0;
-	register char c;
-	register char *name = tp;
-	register char *etp = tp+MAXTOK;
-	register ndptr p;
-
-	while (tp < etp && (isalnum(c = gpbc()) || c == '_'))
-		h += (*tp++ = c);
-	putback(c);
-	if (tp == etp)
-		error("m4: token too long");
-	*tp = EOS;
-	for (p = hashtab[h%HASHSIZE]; p != nil; p = p->nxtptr)
-		if (strcmp(name, p->name) == 0)
-			break;
-	return(p);
-}
-
-#ifdef NONZEROPAGES
-/*
- * initm4 - initialize various tables. Useful only if your system 
- * does not know anything about demand-zero pages.
- *
- */
-void initm4()
-{
-	register int i;
-
-	for (i = 0; i < HASHSIZE; i++)
-		hashtab[i] = nil;
-	for (i = 0; i < MAXOUT; i++)
-		outfile[i] = NULL;
-}
-#endif
-
-/*
- * initkwds - initialise m4 keywords as fast as possible. 
- * This very similar to install, but without certain overheads,
- * such as calling lookup. Malloc is not used for storing the 
- * keyword strings, since we simply use the static  pointers
- * within keywrds block. We also assume that there is enough memory 
- * to at least install the keywords (i.e. malloc won't fail).
- *
- */
-void initkwds() {
-	register int i;
-	register int h;
-	register ndptr p;
-
-	for (i = 0; i < MAXKEYS; i++) {
-		h = hash(keywrds[i].knam);
-		p = (ndptr) malloc(sizeof(struct ndblock));
-		p->nxtptr = hashtab[h];
-		hashtab[h] = p;
-		p->name = keywrds[i].knam;
-		p->defn = null;
-		p->type = keywrds[i].ktyp | STATIC;
-	}
-}
Index: trunk/minix/commands/m4/mdef.h
===================================================================
--- trunk/minix/commands/m4/mdef.h	(revision 9)
+++ 	(revision )
@@ -1,276 +1,0 @@
-/*
- * mdef.h
- * Facility: m4 macro processor
- * by: oz
- */
-
-
-#define unix	1	/* (kjb) */
-
-#ifndef unix
-#define unix 0
-#endif 
-
-#ifndef vms
-#define vms 0
-#endif
-
-#if vms
-
-#include stdio
-#include ctype
-#include signal
-
-#else 
-
-#include <sys/types.h>
-#include <ctype.h>
-#include <signal.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#endif
-
-/*
- *
- * m4 constants..
- *
- */
- 
-#define MACRTYPE        1
-#define DEFITYPE        2
-#define EXPRTYPE        3
-#define SUBSTYPE        4
-#define IFELTYPE        5
-#define LENGTYPE        6
-#define CHNQTYPE        7
-#define SYSCTYPE        8
-#define UNDFTYPE        9
-#define INCLTYPE        10
-#define SINCTYPE        11
-#define PASTTYPE        12
-#define SPASTYPE        13
-#define INCRTYPE        14
-#define IFDFTYPE        15
-#define PUSDTYPE        16
-#define POPDTYPE        17
-#define SHIFTYPE        18
-#define DECRTYPE        19
-#define DIVRTYPE        20
-#define UNDVTYPE        21
-#define DIVNTYPE        22
-#define MKTMTYPE        23
-#define ERRPTYPE        24
-#define M4WRTYPE        25
-#define TRNLTYPE        26
-#define DNLNTYPE        27
-#define DUMPTYPE        28
-#define CHNCTYPE        29
-#define INDXTYPE        30
-#define SYSVTYPE        31
-#define EXITTYPE        32
-#define DEFNTYPE        33
- 
-#define STATIC          128
-
-/*
- * m4 special characters
- */
- 
-#define ARGFLAG         '$'
-#define LPAREN          '('
-#define RPAREN          ')'
-#define LQUOTE          '`'
-#define RQUOTE          '\''
-#define COMMA           ','
-#define SCOMMT          '#'
-#define ECOMMT          '\n'
-
-/*
- * definitions of diversion files. If the name of
- * the file is changed, adjust UNIQUE to point to the
- * wildcard (*) character in the filename.
- */
-
-#if unix
-#define DIVNAM  "/tmp/m4*XXXXXX"        /* unix diversion files    */
-#define UNIQUE          7               /* unique char location    */
-#else
-#if vms
-#define DIVNAM  "sys$login:m4*XXXXXX"   /* vms diversion files     */
-#define UNIQUE          12              /* unique char location    */
-#else
-#define DIVNAM	"\M4*XXXXXX"		/* msdos diversion files   */
-#define	UNIQUE	    3			/* unique char location    */
-#endif
-#endif
-
-/*
- * other important constants
- */
-
-#define EOS             (char) 0
-#define MAXINP          10              /* maximum include files   */
-#define MAXOUT          10              /* maximum # of diversions */
-#define MAXSTR          512             /* maximum size of string  */
-#define BUFSIZE         4096            /* size of pushback buffer */
-#define STACKMAX        1024            /* size of call stack      */
-#define STRSPMAX        4096            /* size of string space    */
-#define MAXTOK          MAXSTR          /* maximum chars in a tokn */
-#define HASHSIZE        199             /* maximum size of hashtab */
- 
-#define ALL             1
-#define TOP             0
- 
-#define TRUE            1
-#define FALSE           0
-#define cycle           for(;;)
-
-#ifdef VOID
-#define void            int             /* define if void is void. */
-#endif
-
-/*
- * m4 data structures
- */
- 
-typedef struct ndblock *ndptr;
- 
-struct ndblock {                /* hastable structure         */
-        char    *name;          /* entry name..               */
-        char    *defn;          /* definition..               */
-        int     type;           /* type of the entry..        */
-        ndptr   nxtptr;         /* link to next entry..       */
-};
- 
-#define nil     ((ndptr) 0)
- 
-struct keyblk {
-        char    *knam;          /* keyword name */
-        int     ktyp;           /* keyword type */
-};
-
-typedef union {			/* stack structure */
-	int	sfra;		/* frame entry  */
-	char 	*sstr;		/* string entry */
-} stae;
-
-/*
- * macros for readibility and/or speed
- *
- *      gpbc()  - get a possibly pushed-back character
- *      min()   - select the minimum of two elements
- *      pushf() - push a call frame entry onto stack
- *      pushs() - push a string pointer onto stack
- */
-#define gpbc() 	 (bp > buf) ? *--bp : getc(infile[ilevel])
-#define min(x,y) ((x > y) ? y : x)
-#define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x)
-#define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x)
-
-/*
- *	    .				   .
- *	|   .	|  <-- sp		|  .  |
- *	+-------+			+-----+
- *	| arg 3 ----------------------->| str |
- *	+-------+			|  .  |
- *	| arg 2 ---PREVEP-----+ 	   .
- *	+-------+	      |
- *	    .		      |		|     |
- *	+-------+	      | 	+-----+
- *	| plev	|  PARLEV     +-------->| str |
- *	+-------+			|  .  |
- *	| type	|  CALTYP		   .
- *	+-------+
- *	| prcf	---PREVFP--+
- *	+-------+  	   |
- *	|   .	|  PREVSP  |
- *	    .	   	   |
- *	+-------+	   |
- *	|	<----------+
- *	+-------+
- *
- */
-#define PARLEV  (mstack[fp].sfra)
-#define CALTYP  (mstack[fp-1].sfra)
-#define PREVEP	(mstack[fp+3].sstr)
-#define PREVSP	(fp-3)
-#define PREVFP	(mstack[fp-2].sfra)
-
-/* function prototypes */
-
-/* eval.c */
-
-_PROTOTYPE(void eval, (char *argv [], int argc, int td ));
-
-/* expr.c */
-
-_PROTOTYPE(int expr, (char *expbuf ));
-_PROTOTYPE(int query, (void));
-_PROTOTYPE(int lor, (void));
-_PROTOTYPE(int land, (void));
-_PROTOTYPE(int bor, (void));
-_PROTOTYPE(int bxor, (void));
-_PROTOTYPE(int band, (void));
-_PROTOTYPE(int eql, (void));
-_PROTOTYPE(int relat, (void));
-_PROTOTYPE(int shift, (void));
-_PROTOTYPE(int primary, (void));
-_PROTOTYPE(int term, (void));
-_PROTOTYPE(int unary, (void));
-_PROTOTYPE(int factor, (void));
-_PROTOTYPE(int constant, (void));
-_PROTOTYPE(int num, (void));
-_PROTOTYPE(int geteql, (void));
-_PROTOTYPE(int getrel, (void));
-_PROTOTYPE(int skipws, (void));
-_PROTOTYPE(int experr, (char *msg ));
-
-/* look.c */
-
-_PROTOTYPE(int hash, (char *name ));
-_PROTOTYPE(ndptr lookup, (char *name ));
-_PROTOTYPE(ndptr addent, (char *name ));
-_PROTOTYPE(void remhash, (char *name, int all ));
-_PROTOTYPE(void freent, (ndptr p ));
-
-/* main.c */
-
-_PROTOTYPE(int main, (int argc, char *argv []));
-_PROTOTYPE(void macro, (void));
-_PROTOTYPE(ndptr inspect, (char *tp ));
-_PROTOTYPE(void initm4, (void));
-_PROTOTYPE(void initkwds, (void));
-
-/* misc.c */
-
-_PROTOTYPE(int indx, (char *s1, char *s2 ));
-_PROTOTYPE(void putback, (int c ));
-_PROTOTYPE(void pbstr, (char *s ));
-_PROTOTYPE(void pbnum, (int n ));
-_PROTOTYPE(void chrsave, (int c ));
-_PROTOTYPE(void getdiv, (int ind ));
-_PROTOTYPE(void error, (char *s ));
-_PROTOTYPE(void onintr, (int s ));
-_PROTOTYPE(void killdiv, (void));
-_PROTOTYPE(char *strsave, (char *s ));
-_PROTOTYPE(void usage, (void));
-
-/* serv.c */
-
-_PROTOTYPE(void expand, (char *argv [], int argc ));
-_PROTOTYPE(void dodefine, (char *name, char *defn ));
-_PROTOTYPE(void dodefn, (char *name ));
-_PROTOTYPE(void dopushdef, (char *name, char *defn ));
-_PROTOTYPE(void dodump, (char *argv [], int argc ));
-_PROTOTYPE(void doifelse, (char *argv [], int argc ));
-_PROTOTYPE(int doincl, (char *ifile ));
-_PROTOTYPE(int dopaste, (char *pfile ));
-_PROTOTYPE(void dochq, (char *argv [], int argc ));
-_PROTOTYPE(void dochc, (char *argv [], int argc ));
-_PROTOTYPE(void dodiv, (int n ));
-_PROTOTYPE(void doundiv, (char *argv [], int argc ));
-_PROTOTYPE(void dosub, (char *argv [], int argc ));
-_PROTOTYPE(void map, (char *dest, char *src, char *from, char *to ));
Index: trunk/minix/commands/m4/misc.c
===================================================================
--- trunk/minix/commands/m4/misc.c	(revision 9)
+++ 	(revision )
@@ -1,292 +1,0 @@
-/*
- * misc.c
- * Facility: m4 macro processor
- * by: oz
- */
- 
-#include "mdef.h"
-#include "extr.h" 
- 
-/*
- * indx - find the index of second str in the
- *        first str.
- */
-int indx(s1, s2)
-char *s1;
-char *s2;
-{
-        register char *t;
-        register char *p;
-        register char *m;
- 
-        for (p = s1; *p; p++) {
-                for (t = p, m = s2; *m && *m == *t; m++, t++)
-                        ;
-                if (!*m)
-                        return(p - s1);
-        }
-        return (-1);
-}
- 
-/*
- *  putback - push character back onto input
- *
- */
-void putback (c)
-char c;
-{
-        if (bp < endpbb)
-                *bp++ = c;
-        else
-                error("m4: too many characters pushed back");
-}
- 
-/*
- *  pbstr - push string back onto input
- *          putback is replicated to improve
- *          performance.
- *
- */
-void pbstr(s)
-register char *s;
-{
-        register char *es;
-	register char *zp;
-
-	es = s;
-	zp = bp;
-
-        while (*es)
-                es++;
-        es--;
-        while (es >= s)
-                if (zp < endpbb)
-                        *zp++ = *es--;
-        if ((bp = zp) == endpbb)
-                error("m4: too many characters pushed back");
-}
- 
-/*
- *  pbnum - convert number to string, push back on input.
- *
- */
-void pbnum (n)
-int n;
-{
-        register int num;
- 
-        num = (n < 0) ? -n : n;
-        do {
-                putback(num % 10 + '0');
-        }
-        while ((num /= 10) > 0);
-
-        if (n < 0) putback('-');
-}
- 
-/*
- *  chrsave - put single char on string space
- *
- */
-void chrsave (c)
-char c;
-{
-/***        if (sp < 0)
-                putc(c, active);
-        else ***/ if (ep < endest)
-                *ep++ = c;
-        else
-                error("m4: string space overflow");
-}
- 
-/*
- * getdiv - read in a diversion file, and
- *          trash it.
- */
-void getdiv(ind)
-int ind;
-{
-        register int c;
-        register FILE *dfil;
- 
-        if (active == outfile[ind])
-                error("m4: undivert: diversion still active.");
-        (void) fclose(outfile[ind]);
-        outfile[ind] = NULL;
-        m4temp[UNIQUE] = ind + '0';
-        if ((dfil = fopen(m4temp, "r")) == NULL)
-                error("m4: cannot undivert.");
-        else
-                while((c = getc(dfil)) != EOF)
-                        putc(c, active);
-        (void) fclose(dfil);
-
-#if vms
-        if (remove(m4temp))
-#else
-	if (unlink(m4temp) == -1)
-#endif
-                error("m4: cannot unlink.");
-}
- 
-/*
- * Very fatal error. Close all files
- * and die hard.
- */
-void error(s)
-char *s;
-{
-        killdiv();
-        fprintf(stderr,"%s\n",s);
-        exit(1);
-}
- 
-/*
- * Interrupt handling
- */
-static char *msg = "\ninterrupted.";
- 
-void onintr(s) 
-int s;				/* ANSI requires the parameter */
-{
-        error(msg);
-}
- 
-/*
- * killdiv - get rid of the diversion files
- *
- */
-void killdiv() {
-        register int n;
- 
-        for (n = 0; n < MAXOUT; n++)
-                if (outfile[n] != NULL) {
-                        (void) fclose (outfile[n]);
-                        m4temp[UNIQUE] = n + '0';
-#if vms
-			(void) remove (m4temp);
-#else
-                        (void) unlink (m4temp);
-#endif
-                }
-}
- 
-/*
- * save a string somewhere..
- *
- */
-char *strsave(s)
-char *s;
-{
-	register int n;
-        char *p;
-
-	n = strlen(s)+1;
-	p = (char *) malloc(n);
-        if (p != NULL) (void) memcpy(p, s, n);
-        return (p);
-}
- 
-void usage() {
-        fprintf(stderr, "Usage: m4 [-Dname[=val]] [-Uname]\n");
-        exit(1);
-}
-
-#ifdef GETOPT
-/*
- * H. Spencer getopt - get option letter from argv
- * 
- *
-#include <stdio.h>
- *
- */
-
-char	*optarg;	/* Global argument pointer. */
-int	optind = 0;	/* Global argv index. */
-
-static char	*scan = NULL;	/* Private scan pointer. */
-
-int
-getopt(argc, argv, optstring)
-int argc;
-char *argv[];
-char *optstring;
-{
-	register char c;
-	register char *place;
-
-	optarg = NULL;
-
-	if (scan == NULL || *scan == '\0') {
-		if (optind == 0)
-			optind++;
-	
-		if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
-			return(EOF);
-		if (strcmp(argv[optind], "--")==0) {
-			optind++;
-			return(EOF);
-		}
-	
-		scan = argv[optind]+1;
-		optind++;
-	}
-
-	c = *scan++;
-	place = index(optstring, c);
-
-	if (place == NULL || c == ':') {
-		fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
-		return('?');
-	}
-
-	place++;
-	if (*place == ':') {
-		if (*scan != '\0') {
-			optarg = scan;
-			scan = NULL;
-		} else {
-			optarg = argv[optind];
-			optind++;
-		}
-	}
-
-	return(c);
-}
-   
-#endif
-
-#ifdef DUFFCP
-/*
- * This code uses Duff's Device (tm Tom Duff)
- * to unroll the copying loop:
- * while (count-- > 0)
- *	*to++ = *from++;
- */
-
-#define COPYBYTE 	*to++ = *from++
-
-void memcpy(to, from, count)
-register char *from, *to;
-register int count;
-{
-	if (count > 0) {
-		register int loops = (count+8-1) >> 3;	/* div 8 round up */
-
-		switch (count&(8-1)) {			/* mod 8 */
-		case 0: do {
-			COPYBYTE;
-		case 7:	COPYBYTE;
-		case 6:	COPYBYTE;
-		case 5:	COPYBYTE;
-		case 4:	COPYBYTE;
-		case 3:	COPYBYTE;
-		case 2:	COPYBYTE;
-		case 1:	COPYBYTE;
-			} while (--loops > 0);
-		}
-
-	}
-}
-
-#endif
Index: trunk/minix/commands/m4/patchlevel.h
===================================================================
--- trunk/minix/commands/m4/patchlevel.h	(revision 9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-#define PATCHLEVEL 1
Index: trunk/minix/commands/m4/serv.c
===================================================================
--- trunk/minix/commands/m4/serv.c	(revision 9)
+++ 	(revision )
@@ -1,423 +1,0 @@
-/*
- * serv.c
- * Facility: m4 macro processor
- * by: oz
- */
- 
-#include "mdef.h"
-#include "extr.h" 
-
-char *dumpfmt = "`%s'\t`%s'\n"; /* format string for dumpdef   */
- 
-/*
- * expand - user-defined macro expansion
- *
- */
-void expand(argv, argc)
-register char *argv[];
-register int argc;
-{
-        register char *t;
-        register char *p;
-        register int  n;
-        register int  argno;
- 
-        t = argv[0];    /* defn string as a whole */
-        p = t;
-        while (*p)
-                p++;
-        p--;            /* last character of defn */
-        while (p > t) {
-                if (*(p-1) != ARGFLAG)
-                        putback(*p);
-                else {
-                        switch (*p) {
- 
-                        case '#':
-                                pbnum(argc-2);
-                                break;
-                        case '0':
-                        case '1':
-                        case '2':
-                        case '3':
-                        case '4':
-                        case '5':
-                        case '6':
-                        case '7':
-                        case '8':
-                        case '9':
-                                if ((argno = *p - '0') < argc-1)
-                                        pbstr(argv[argno+1]);
-                                break;
-                        case '*':
-                                for (n = argc - 1; n > 2; n--) {
-                                        pbstr(argv[n]);
-                                        putback(',');
-                                }
-                                pbstr(argv[2]);
-                                break;
-                        default :
-                                putback(*p);
-                                break;
-                        }
-                        p--;
-                }
-                p--;
-        }
-        if (p == t)         /* do last character */
-                putback(*p);
-}
- 
-/*
- * dodefine - install definition in the table
- *
- */
-void dodefine(name, defn)
-register char *name;
-register char *defn;
-{
-        register ndptr p;
- 
-        if (!*name)
-                error("m4: null definition.");
-        if (strcmp(name, defn) == 0)
-                error("m4: recursive definition.");
-        if ((p = lookup(name)) == nil)
-                p = addent(name);
-        else if (p->defn != null)
-                free(p->defn);
-        if (!*defn)
-                p->defn = null;
-        else
-                p->defn = strsave(defn);
-        p->type = MACRTYPE;
-}
- 
-/*
- * dodefn - push back a quoted definition of
- *      the given name.
- */
- 
-void dodefn(name)
-char *name;
-{
-        register ndptr p;
- 
-        if ((p = lookup(name)) != nil && p->defn != null) {
-                putback(rquote);
-                pbstr(p->defn);
-                putback(lquote);
-        }
-}
-     
-/*
- * dopushdef - install a definition in the hash table
- *      without removing a previous definition. Since
- *      each new entry is entered in *front* of the
- *      hash bucket, it hides a previous definition from
- *      lookup.
- */
-void dopushdef(name, defn)
-register char *name;
-register char *defn;
-{
-        register ndptr p;
- 
-        if (!*name)
-                error("m4: null definition");
-        if (strcmp(name, defn) == 0)
-                error("m4: recursive definition.");
-        p = addent(name);
-        if (!*defn)
-                p->defn = null;
-        else
-                p->defn = strsave(defn);
-        p->type = MACRTYPE;
-}
- 
-/*
- * dodumpdef - dump the specified definitions in the hash
- *      table to stderr. If nothing is specified, the entire
- *      hash table is dumped.
- *
- */
-void dodump(argv, argc)
-register char *argv[];
-register int argc;
-{
-        register int n;
-        ndptr p;
- 
-        if (argc > 2) {
-                for (n = 2; n < argc; n++)
-                        if ((p = lookup(argv[n])) != nil)
-                                fprintf(stderr, dumpfmt, p->name,
-                                p->defn);
-        }
-        else {
-                for (n = 0; n < HASHSIZE; n++)
-                        for (p = hashtab[n]; p != nil; p = p->nxtptr)
-                                fprintf(stderr, dumpfmt, p->name,
-                                p->defn);
-        }
-}
- 
-/*
- * doifelse - select one of two alternatives - loop.
- *
- */
-void doifelse(argv,argc)
-register char *argv[];
-register int argc;
-{
-        cycle {
-                if (strcmp(argv[2], argv[3]) == 0)
-                        pbstr(argv[4]);
-                else if (argc == 6)
-                        pbstr(argv[5]);
-                else if (argc > 6) {
-                        argv += 3;
-                        argc -= 3;
-                        continue;
-                }
-                break;
-        }
-}
- 
-/*
- * doinclude - include a given file.
- *
- */
-int doincl(ifile)
-char *ifile;
-{
-        if (ilevel+1 == MAXINP)
-                error("m4: too many include files.");
-        if ((infile[ilevel+1] = fopen(ifile, "r")) != NULL) {
-                ilevel++;
-                return (1);
-        }
-        else
-                return (0);
-}
- 
-#ifdef EXTENDED
-/*
- * dopaste - include a given file without any
- *           macro processing.
- */
-int dopaste(pfile)
-char *pfile;
-{
-        FILE *pf;
-        register int c;
- 
-        if ((pf = fopen(pfile, "r")) != NULL) {
-                while((c = getc(pf)) != EOF)
-                        putc(c, active);
-                (void) fclose(pf);
-                return(1);
-        }
-        else
-                return(0);
-}
-#endif
- 
-/*
- * dochq - change quote characters
- *
- */
-void dochq(argv, argc)
-register char *argv[];
-register int argc;
-{
-        if (argc > 2) {
-                if (*argv[2])
-                        lquote = *argv[2];
-                if (argc > 3) {
-                        if (*argv[3])
-                                rquote = *argv[3];
-                }
-                else
-                        rquote = lquote;
-        }
-        else {
-                lquote = LQUOTE;
-                rquote = RQUOTE;
-        }
-}
- 
-/*
- * dochc - change comment characters
- *
- */
-void dochc(argv, argc)
-register char *argv[];
-register int argc;
-{
-        if (argc > 2) {
-                if (*argv[2])
-                        scommt = *argv[2];
-                if (argc > 3) {
-                        if (*argv[3])
-                                ecommt = *argv[3];
-                }
-                else
-                        ecommt = ECOMMT;
-        }
-        else {
-                scommt = SCOMMT;
-                ecommt = ECOMMT;
-        }
-}
- 
-/*
- * dodivert - divert the output to a temporary file
- *
- */
-void dodiv(n)
-register int n;
-{
-        if (n < 0 || n >= MAXOUT)
-                n = 0;                  /* bitbucket */
-        if (outfile[n] == NULL) {
-                m4temp[UNIQUE] = n + '0';
-                if ((outfile[n] = fopen(m4temp, "w")) == NULL)
-                        error("m4: cannot divert.");
-        }
-        oindex = n;
-        active = outfile[n];
-}
- 
-/*
- * doundivert - undivert a specified output, or all
- *              other outputs, in numerical order.
- */
-void doundiv(argv, argc)
-register char *argv[];
-register int argc;
-{
-        register int ind;
-        register int n;
- 
-        if (argc > 2) {
-                for (ind = 2; ind < argc; ind++) {
-                        n = atoi(argv[ind]);
-                        if (n > 0 && n < MAXOUT && outfile[n] != NULL)
-                                getdiv(n);
- 
-                }
-        }
-        else
-                for (n = 1; n < MAXOUT; n++)
-                        if (outfile[n] != NULL)
-                                getdiv(n);
-}
- 
-/*
- * dosub - select substring
- *
- */
-void dosub (argv, argc)
-register char *argv[];
-register int  argc;
-{
-        register char *ap, *fc, *k;
-        register int nc;
- 
-        if (argc < 5)
-                nc = MAXTOK;
-        else
-#ifdef EXPR
-                nc = expr(argv[4]);
-#else
-		nc = atoi(argv[4]);
-#endif
-        ap = argv[2];                   /* target string */
-#ifdef EXPR
-        fc = ap + expr(argv[3]);        /* first char */
-#else
-        fc = ap + atoi(argv[3]);        /* first char */
-#endif
-        if (fc >= ap && fc < ap+strlen(ap))
-                for (k = fc+min(nc,strlen(fc))-1; k >= fc; k--)
-                        putback(*k);
-}
- 
-/*
- * map:
- * map every character of s1 that is specified in from
- * into s3 and replace in s. (source s1 remains untouched)
- *
- * This is a standard implementation of map(s,from,to) function of ICON 
- * language. Within mapvec, we replace every character of "from" with 
- * the corresponding character in "to". If "to" is shorter than "from", 
- * than the corresponding entries are null, which means that those 
- * characters dissapear altogether. Furthermore, imagine 
- * map(dest, "sourcestring", "srtin", "rn..*") type call. In this case, 
- * `s' maps to `r', `r' maps to `n' and `n' maps to `*'. Thus, `s' 
- * ultimately maps to `*'. In order to achieve this effect in an efficient 
- * manner (i.e. without multiple passes over the destination string), we 
- * loop over mapvec, starting with the initial source character. if the 
- * character value (dch) in this location is different than the source 
- * character (sch), sch becomes dch, once again to index into mapvec, until 
- * the character value stabilizes (i.e. sch = dch, in other words 
- * mapvec[n] == n). Even if the entry in the mapvec is null for an ordinary 
- * character, it will stabilize, since mapvec[0] == 0 at all times. At the 
- * end, we restore mapvec* back to normal where mapvec[n] == n for 
- * 0 <= n <= 127. This strategy, along with the restoration of mapvec, is 
- * about 5 times faster than any algorithm that makes multiple passes over 
- * destination string.
- *
- */
-     
-void map(dest,src,from,to)
-register char *dest;
-register char *src;
-register char *from;
-register char *to;
-{
-        register char *tmp;
-        register char sch, dch;
-        static char mapvec[128] = {
-                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
-                12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
-                24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
-                36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-                48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
-                60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
-                72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
-                84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-                96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
-                108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
-                120, 121, 122, 123, 124, 125, 126, 127
-        };
- 
-        if (*src) {
-                tmp = from;
-	/*
-	 * create a mapping between "from" and "to"
-	 */
-                while (*from)
-                        mapvec[*from++] = (*to) ? *to++ : (char) 0;
-     
-                while (*src) {
-                        sch = *src++;
-                        dch = mapvec[sch];
-                        while (dch != sch) {
-                                sch = dch;
-                                dch = mapvec[sch];
-                        }
-                        if (*dest = dch)
-                                dest++;
-                }
-	/*
-	 * restore all the changed characters
-	 */
-                while (*tmp) {
-                        mapvec[*tmp] = *tmp;
-                        tmp++;
-                }
-        }
-        *dest = (char) 0;
-}
Index: trunk/minix/commands/make/Makefile
===================================================================
--- trunk/minix/commands/make/Makefile	(revision 9)
+++ 	(revision )
@@ -1,22 +1,0 @@
-# Makefile for make (!)
-
-CFLAGS = -O -Dunix -D_MINIX -D_POSIX_SOURCE
-CC = exec cc
-
-OBJ =	check.o input.o macro.o main.o make.o reader.o rules.o archive.o
-
-all:	make
-
-make :	$(OBJ)
-	$(CC) -i -o make $(OBJ)
-	install -S 330k make
-
-install:	/usr/bin/make
-
-/usr/bin/make:	make
-	install -c -o bin make $@
- 
-$(OBJ): h.h
-
-clean:
-	rm -f *.o *.bak core make
Index: trunk/minix/commands/make/archive.c
===================================================================
--- trunk/minix/commands/make/archive.c	(revision 9)
+++ 	(revision )
@@ -1,309 +1,0 @@
-/*	archive.c - archive support			Author: Kees J. Bot
- *								13 Nov 1993
- */
-#include "h.h"
-
-#ifdef unix
-
-#include <unistd.h>
-#include <fcntl.h>
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-/* ASCII ar header. */
-
-#define ASCII_ARMAG	"!<arch>\n"
-#define ASCII_SARMAG	8
-#define ASCII_ARFMAG	"`\n"
-
-struct ascii_ar_hdr {
-	char	ar_name[16];
-	char	ar_date[12];
-	char	ar_uid[6];
-	char	ar_gid[6];
-	char	ar_mode[8];
-	char	ar_size[10];
-	char	ar_fmag[2];
-};
-
-/* ACK ar header. */
-
-#define	ACK_ARMAG	0177545
-#define ACK_AALMAG	0177454
-
-struct ack_ar_hdr {
-	char		ar_name[14];
-	unsigned long	ar_date;
-	unsigned char	ar_uid;
-	unsigned char	ar_gid;
-	unsigned short	ar_mode;
-	unsigned long	ar_size;
-};
-
-typedef struct archname {
-	struct archname	*next;		/* Next on the hash chain. */
-	char		name[16];	/* One archive entry. */
-	time_t		date;		/* The timestamp. */
-	/* (no need for other attibutes) */
-} archname_t;
-
-static size_t namelen;			/* Max name length, 14 or 16. */
-
-#define HASHSIZE	(64 << sizeof(int))
-
-static archname_t *nametab[HASHSIZE];
-
-_PROTOTYPE( static int hash, (char *name) );
-_PROTOTYPE( static int searchtab, (char *name, time_t *date, int scan) );
-_PROTOTYPE( static void deltab, (void) );
-_PROTOTYPE( static long ar_atol, (char *s, size_t n) );
-_PROTOTYPE( static int read_ascii_archive, (int afd) );
-_PROTOTYPE( static int read_ack_archive, (int afd) );
-
-static char *lpar, *rpar;	/* Leave these at '(' and ')'. */
-
-int is_archive_ref(name) char *name;
-/* True if name is of the form "archive(file)". */
-{
-  char *p = name;
-
-  while (*p != 0 && *p != '(' && *p != ')') p++;
-  lpar = p;
-  if (*p++ != '(') return 0;
-
-  while (*p != 0 && *p != '(' && *p != ')') p++;
-  rpar = p;
-  if (*p++ != ')') return 0;
-
-  return *p == 0;
-}
-
-static int hash(name) char *name;
-/* Compute a hash value out of a name. */
-{
-	unsigned h = 0;
-	unsigned char *p = (unsigned char *) name;
-	int n = namelen;
-
-	while (*p != 0) {
-		h = h * 0x1111 + *p++;
-		if (--n == 0) break;
-	}
-
-	return h % arraysize(nametab);
-}
-
-static int searchtab(name, date, scan) char *name; time_t *date; int scan;
-/* Enter a name to the table, or return the date of one already there. */
-{
-	archname_t **pnp, *np;
-	int cmp = 1;
-
-	pnp = &nametab[hash(name)];
-
-	while ((np = *pnp) != NULL
-			&& (cmp = strncmp(name, np->name, namelen)) > 0) {
-		pnp= &np->next;
-	}
-
-	if (cmp != 0) {
-		if (scan) {
-			errno = ENOENT;
-			return -1;
-		}
-		if ((np = (archname_t *) malloc(sizeof(*np))) == NULL)
-			fatal("No memory for archive name cache",(char *)0,0);
-		strncpy(np->name, name, namelen);
-		np->date = *date;
-		np->next = *pnp;
-		*pnp = np;
-	}
-	if (scan) *date = np->date;
-	return 0;
-}
-
-static void deltab()
-/* Delete the name cache, a different library is to be read. */
-{
-	archname_t **pnp, *np, *junk;
-
-	for (pnp = nametab; pnp < arraylimit(nametab); pnp++) {
-		for (np = *pnp; np != NULL; ) {
-			junk = np;
-			np = np->next;
-			free(junk);
-		}
-		*pnp = NULL;
-	}
-}
-
-static long ar_atol(s, n) char *s; size_t n;
-/* Transform a string into a number.  Ignore the space padding. */
-{
-  long l= 0;
-
-  while (n > 0) {
-	if (*s != ' ') l= l * 10 + (*s - '0');
-	s++;
-	n--;
-  }
-  return l;
-}
-
-static int read_ascii_archive(afd)
-int afd;
-/* Read a modern ASCII type archive. */
-{
-  struct ascii_ar_hdr hdr;
-  off_t pos= 8;
-  char *p;
-  time_t date;
-
-  namelen = 16;
-
-  for (;;) {
-	if (lseek(afd, pos, SEEK_SET) == -1) return -1;
-
-	switch (read(afd, &hdr, sizeof(hdr))) {
-	case sizeof(hdr):
-		break;
-	case -1:
-		return -1;
-	default:
-		return 0;
-	}
-
-	if (strncmp(hdr.ar_fmag, ASCII_ARFMAG, sizeof(hdr.ar_fmag)) != 0) {
-		errno= EINVAL;
-		return -1;
-	}
-
-	/* Strings are space padded! */
-	for (p= hdr.ar_name; p < hdr.ar_name + sizeof(hdr.ar_name); p++) {
-		if (*p == ' ') {
-			*p= 0;
-			break;
-		}
-	}
-
-	/* Add a file to the cache. */
-	date = ar_atol(hdr.ar_date, sizeof(hdr.ar_date));
-	searchtab(hdr.ar_name, &date, 0);
-
-	pos+= sizeof(hdr) + ar_atol(hdr.ar_size, sizeof(hdr.ar_size));
-	pos= (pos + 1) & (~ (off_t) 1);
-  }
-}
-
-static int read_ack_archive(afd)
-int afd;
-/* Read an ACK type archive. */
-{
-  unsigned char raw_hdr[14 + 4 + 1 + 1 + 2 + 4];
-  struct ack_ar_hdr hdr;
-  off_t pos= 2;
-  time_t date;
-
-  namelen = 14;
-
-  for (;;) {
-	if (lseek(afd, pos, SEEK_SET) == -1) return -1;
-
-	switch (read(afd, raw_hdr, sizeof(raw_hdr))) {
-	case sizeof(raw_hdr):
-		break;
-	case -1:
-		return -1;
-	default:
-		return 0;
-	}
-
-	/* Copy the useful fields from the raw bytes transforming PDP-11
-	 * style numbers to native format.
-	 */
-	memcpy(hdr.ar_name, raw_hdr + 0, 14);
-	hdr.ar_date=	  (long) raw_hdr[14 + 1] << 24
-			| (long) raw_hdr[14 + 0] << 16
-			| (long) raw_hdr[14 + 3] <<  8
-			| (long) raw_hdr[14 + 2] <<  0;
-	hdr.ar_size=	  (long) raw_hdr[22 + 1] << 24
-			| (long) raw_hdr[22 + 0] << 16
-			| (long) raw_hdr[22 + 3] <<  8
-			| (long) raw_hdr[22 + 2] <<  0;
-
-	/* Add a file to the cache. */
-	date = hdr.ar_date;
-	searchtab(hdr.ar_name, &date, 0);
-
-	pos= (pos + 26 + hdr.ar_size + 1) & (~ (off_t) 1);
-  }
-}
-
-int archive_stat(name, stp) char *name; struct stat *stp;
-/* Search an archive for a file and return that file's stat info. */
-{
-  int afd;
-  int r= -1;
-  char magic[8];
-  char *file;
-  static dev_t ardev;
-  static ino_t arino = 0;
-  static time_t armtime;
-
-  if (!is_archive_ref(name)) { errno = EINVAL; return -1; }
-  *lpar= 0;
-  *rpar= 0;
-  file= lpar + 1;
-
-  if (stat(name, stp) < 0) goto bail_out;
-
-  if (stp->st_ino != arino || stp->st_dev != ardev) {
-	/* Either the first (and probably only) library, or a different
-	 * library.
-	 */
-	arino = stp->st_ino;
-	ardev = stp->st_dev;
-	armtime = stp->st_mtime;
-	deltab();
-
-	if ((afd= open(name, O_RDONLY)) < 0) goto bail_out;
-
-	switch (read(afd, magic, sizeof(magic))) {
-	case 8:
-		if (strncmp(magic, ASCII_ARMAG, 8) == 0) {
-			r= read_ascii_archive(afd);
-			break;
-		}
-		if ((magic[0] & 0xFF) == ((ACK_AALMAG >> 0) & 0xFF)
-			&& (magic[1] & 0xFF) == ((ACK_AALMAG >> 8) & 0xFF)
-		) {
-			r= read_ack_archive(afd);
-			break;
-		}
-		/*FALL THROUGH*/
-	default:
-		errno = EINVAL;
-		/*FALL THROUGH*/
-	case -1:
-		/* r= -1 */;
-	}
-	{ int e= errno; close(afd); errno= e; }
-  } else {
-	/* Library is cached. */
-	r = 0;
-  }
-
-  if (r == 0) {
-	/* Search the cache. */
-	r = searchtab(file, &stp->st_mtime, 1);
-	if (stp->st_mtime > armtime) stp->st_mtime = armtime;
-  }
-
-bail_out:
-  /* Repair the name(file) thing. */
-  *lpar= '(';
-  *rpar= ')';
-  return r;
-}
-#endif
Index: trunk/minix/commands/make/build
===================================================================
--- trunk/minix/commands/make/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/make/check.c
===================================================================
--- trunk/minix/commands/make/check.c	(revision 9)
+++ 	(revision )
@@ -1,128 +1,0 @@
-/*************************************************************************
- *
- *  m a k e :   c h e c k . c
- *
- *  debugging stuff: Check structures for make.
- *========================================================================
- * Edition history
- *
- *  #    Date                         Comments                       By
- * --- -------- ---------------------------------------------------- ---
- *   1    ??                                                         ??
- *   2 23.08.89 adapted to new name tree structure                   RAL
- *   3 30.08.89 indention changed                                    PSH,RAL
- *   4 06.09.89 prt output redirected to stdout                      RAL
- * ------------ Version 2.0 released ------------------------------- RAL
- *
- *************************************************************************/
-
-#include "h.h"
-
-
-/*
- *	Prints out the structures as defined in memory.  Good for check
- *	that you make file does what you want (and for debugging make).
- */
-void prt()
-{
-  register struct name   *np;
-  register struct depend *dp;
-  register struct line   *lp;
-  register struct cmd    *cp;
-  register struct macro  *mp;
-
-  register int   		i;
-
-  for (mp = macrohead; mp; mp = mp->m_next)
-	printf("%s = %s\n", mp->m_name, mp->m_val);
-
-  putchar('\n');
-
-  for (i = 0; i <= maxsuffarray ; i++)
-	    for (np = suffparray[i]->n_next; np; np = np->n_next)
-	    {
-		if (np->n_flag & N_DOUBLE)
-			printf("%s::\n", np->n_name);
-		else
-			printf("%s:\n", np->n_name);
-		if (np == firstname)
-			printf("(MAIN NAME)\n");
-		for (lp = np->n_line; lp; lp = lp->l_next)
-		{
-			putchar(':');
-			for (dp = lp->l_dep; dp; dp = dp->d_next)
-				printf(" %s", dp->d_name->n_name);
-			putchar('\n');
-
-			for (cp = lp->l_cmd; cp; cp = cp->c_next)
-#ifdef os9
-				printf("-   %s\n", cp->c_cmd);
-#else
-				printf("-\t%s\n", cp->c_cmd);
-#endif
-			putchar('\n');
-		}
-		putchar('\n');
-	    }
-}
-
-
-/*
- *	Recursive routine that does the actual checking.
- */
-void check(np)
-struct name *np;
-{
-  register struct depend *dp;
-  register struct line   *lp;
-
-
-	if (np->n_flag & N_MARK)
-		fatal("Circular dependency from %s", np->n_name,0);
-
-	np->n_flag |= N_MARK;
-
-	for (lp = np->n_line; lp; lp = lp->l_next)
-		for (dp = lp->l_dep; dp; dp = dp->d_next)
-			check(dp->d_name);
-
-	np->n_flag &= ~N_MARK;
-}
-
-
-/*
- *	Look for circular dependancies.
- *	ie.
- *		a: b
- *		b: a
- *	is a circular dep
- */
-void circh()
-{
-  register struct name *np;
-  register int          i;
-
-
-  for (i = 0; i <= maxsuffarray ; i++)
-	   for (np = suffparray[i]->n_next; np; np = np->n_next)
-		check(np);
-}
-
-
-/*
- *	Check the target .PRECIOUS, and mark its dependentd as precious
- */
-void precious()
-{
-  register struct depend *dp;
-  register struct line   *lp;
-  register struct name   *np;
-
-
-  if (!((np = newname(".PRECIOUS"))->n_flag & N_TARG))
-	return;
-
-  for (lp = np->n_line; lp; lp = lp->l_next)
-	for (dp = lp->l_dep; dp; dp = dp->d_next)
-		dp->d_name->n_flag |= N_PREC;
-}
Index: trunk/minix/commands/make/h.h
===================================================================
--- trunk/minix/commands/make/h.h	(revision 9)
+++ 	(revision )
@@ -1,319 +1,0 @@
-/*************************************************************************
- *
- *  m a k e :   h . h
- *
- *  include file for make
- *========================================================================
- * Edition history
- *
- *  #    Date                         Comments                       By
- * --- -------- ---------------------------------------------------- ---
- *   1    ??                                                         ??
- *   2 23.08.89 LZ increased,N_EXISTS added,suffix as macro added    RAL
- *   3 30.08.89 macro flags added, indention changed                 PSH,RAL
- *   4 03.09.89 fixed LZ eliminated, struct str added,...            RAL
- *   5 06.09.89 TABCHAR,M_MAKE added                                 RAL
- *   6 09.09.89 tos support added, EXTERN,INIT,PARMS added           PHH,RAL
- *   7 17.09.89 __STDC__ added, make1 decl. fixed , N_EXEC added     RAL
- * ------------ Version 2.0 released ------------------------------- RAL
- *
- *************************************************************************/
-
-#ifdef unix
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <utime.h>
-#include <stdio.h>
-#include <limits.h>
-#endif
-
-#ifdef eon
-#include <sys/stat.h>
-#include <sys/err.h>
-#endif
-
-#ifdef os9
-#include <time.h>
-#include <os9.h>
-#include <modes.h>
-#include <direct.h>
-#include <errno.h>
-#endif
-
-#ifdef tos
-struct DOSTIME {short time,date; };     /* time structure of TOS */
-
-#ifdef LATTICE
-#include <error.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <osbind.h>
-#endif /* LATTICE */
-
-#ifdef TURBO
-#include <tos.h>
-#include <errno.h>
-#include <string.h>
-#endif /* TURBO */
-
-#endif /* tos */
-
-#include <ctype.h>
-#include <stdio.h>
-#include <assert.h>
-
-#ifdef eon
-#define MNOENT ER_NOTF
-#else
-#define MNOENT ENOENT
-#endif
-
-#ifndef uchar
-#ifdef os9
-#define uchar  char
-#define void   int
-#define fputc  putc
-#else
-#define uchar  unsigned char
-#endif
-#endif
-
-#define bool   uchar
-#ifndef time_t
-#define time_t long
-#endif
-#define TRUE   (1)
-#define FALSE  (0)
-#define max(a,b) ((a)>(b)?(a):(b))
-
-#ifdef unix
-#define DEFN1   "makefile"
-#define DEFN2   "Makefile"
-#endif
-#ifdef eon
-#define DEFN1   "makefile"
-#define DEFN2   "Makefile"
-#endif
-#ifdef tos
-#define DEFN1   "makefile."
-#define DEFN2   (char *)0
-#endif
-#ifdef os9
-#define DEFN1   "makefile"
-#define DEFN2   (char *)0
-#endif
-
-
-#ifdef os9
-#define TABCHAR ' '
-#else
-#define TABCHAR '\t'
-#endif
-
-#define LZ1	(2048)		/*  Initial input/expand string size  */
-#define LZ2	(256)		/*  Initial input/expand string size  */
-
-
-
-/*
- *	A name.  This represents a file, either to be made, or existant
- */
-
-struct name
-{
-  struct name  *n_next;		/* Next in the list of names */
-  char         *n_name;		/* Called */
-  struct line  *n_line;		/* Dependencies */
-  time_t        n_time;		/* Modify time of this name */
-  uchar         n_flag;		/* Info about the name */
-};
-
-#define N_MARK    0x01			/* For cycle check */
-#define N_DONE    0x02			/* Name looked at */
-#define N_TARG    0x04			/* Name is a target */
-#define N_PREC    0x08			/* Target is precious */
-#define N_DOUBLE  0x10			/* Double colon target */
-#define N_EXISTS  0x20			/* File exists */
-#define N_ERROR   0x40			/* Error occured */
-#define N_EXEC    0x80			/* Commands executed */
-
-/*
- *	Definition of a target line.
- */
-struct	line
-{
-  struct line    *l_next;		/* Next line (for ::) */
-  struct depend  *l_dep;		/* Dependents for this line */
-  struct cmd     *l_cmd;		/* Commands for this line */
-};
-
-
-/*
- *	List of dependents for a line
- */
-struct	depend
-{
-  struct depend  *d_next;		/* Next dependent */
-  struct name    *d_name;		/* Name of dependent */
-};
-
-
-/*
- *	Commands for a line
- */
-struct	cmd
-{
-  struct cmd  *c_next;		/* Next command line */
-  char        *c_cmd;		/* Command line */
-};
-
-
-/*
- *	Macro storage
- */
-struct	macro
-{
-  struct macro *m_next;	/* Next variable */
-  char *m_name;		/* Called ... */
-  char *m_val;		/* Its value */
-  uchar m_flag;		/* Infinite loop check */
-};
-
-
-#define M_MARK		0x01	/* for infinite loop check */
-#define M_OVERRIDE	0x02	/* command-line override */
-#define M_MAKE		0x04	/* for MAKE macro */
-
-/*
- *	String
- */
-struct	str
-{
-  char **ptr;		/* ptr to real ptr. to string */
-  int    len;		/* length of string */
-  int    pos;		/* position */
-};
-
-
-/* Declaration, definition & initialization of variables */
-
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
-#ifndef INIT
-#define INIT(x)
-#endif
-
-extern int    errno;
-extern char **environ;
-
-EXTERN char *myname;
-EXTERN bool  domake   INIT(TRUE);  /*  Go through the motions option  */
-EXTERN bool  ignore   INIT(FALSE); /*  Ignore exit status option      */
-EXTERN bool  conterr  INIT(FALSE); /*  continue on errors  */
-EXTERN bool  silent   INIT(FALSE); /*  Silent option  */
-EXTERN bool  print    INIT(FALSE); /*  Print debuging information  */
-EXTERN bool  rules    INIT(TRUE);  /*  Use inbuilt rules  */
-EXTERN bool  dotouch  INIT(FALSE); /*  Touch files instead of making  */
-EXTERN bool  quest    INIT(FALSE); /*  Question up-to-dateness of file  */
-EXTERN bool  useenv   INIT(FALSE); /*  Env. macro def. overwrite makefile def.*/
-EXTERN bool  dbginfo  INIT(FALSE); /*  Print lot of debugging information */
-EXTERN bool  ambigmac INIT(TRUE);  /*  guess undef. ambiguous macros (*,<) */
-EXTERN struct name  *firstname;
-EXTERN char         *str1;
-EXTERN char         *str2;
-EXTERN struct str    str1s;
-EXTERN struct str    str2s;
-EXTERN struct name **suffparray; /* ptr. to array of ptrs. to name chains */
-EXTERN int           sizesuffarray INIT(20); /* size of suffarray */
-EXTERN int           maxsuffarray INIT(0);   /* last used entry in suffarray */
-EXTERN struct macro *macrohead;
-EXTERN bool          expmake; /* TRUE if $(MAKE) has been expanded */
-EXTERN char	    *makefile;     /*  The make file  */
-EXTERN int           lineno;
-
-#ifdef tos
-#ifdef LATTICE
-EXTERN int _mneed INIT(60000);    /* VERY important for TOS with LATTICE C*/
-#endif /* LATTICE */
-#endif /* tos */
-#ifdef eon
-#define MEMSPACE  (16384)
-EXTERN unsigned  memspace = MEMSPACE;
-#endif
-
-#define  suffix(name)   strrchr(name,(int)'.')
-
-EXTERN int _ctypech;
-#define mylower(x)  (islower(_ctypech=(x)) ? _ctypech :tolower(_ctypech))
-#define myupper(x)  (isupper(_ctypech=(x)) ? _ctypech :toupper(_ctypech))
-
-/* Prototypes. */
-struct sgtbuf;
-
-/* check.c */
-_PROTOTYPE(void prt, (void));
-_PROTOTYPE(void check, (struct name *np ));
-_PROTOTYPE(void circh, (void));
-_PROTOTYPE(void precious, (void));
-
-/* input.c */
-_PROTOTYPE(void init, (void));
-_PROTOTYPE(void strrealloc, (struct str *strs ));
-_PROTOTYPE(struct name *newname, (char *name ));
-_PROTOTYPE(struct name *testname, (char *name ));
-_PROTOTYPE(struct depend *newdep, (struct name *np, struct depend *dp ));
-_PROTOTYPE(struct cmd *newcmd, (char *str, struct cmd *cp ));
-_PROTOTYPE(void newline, (struct name *np, struct depend *dp, struct cmd *cp, 
-								   int flag ));
-_PROTOTYPE(void input, (FILE *fd ));
-
-/* macro.c */
-_PROTOTYPE(struct macro *getmp, (char *name ));
-_PROTOTYPE(char *getmacro, (char *name ));
-_PROTOTYPE(struct macro *setmacro, (char *name, char *val ));
-_PROTOTYPE(void setDFmacro, (char *name, char *val ));
-_PROTOTYPE(void doexp, (struct str *to, char *from ));
-_PROTOTYPE(void expand, (struct str *strs ));
-
-/* main.c */
-_PROTOTYPE(void main, (int argc, char **argv ));
-_PROTOTYPE(void setoption, (char option ));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void fatal, (char *msg, char *a1, int a2 ));
-
-/* make.c */
-_PROTOTYPE(int dosh, (char *string, char *shell ));
-_PROTOTYPE(int makeold, (char *name ));
-_PROTOTYPE(void docmds1, (struct name *np, struct line *lp ));
-_PROTOTYPE(void docmds, (struct name *np ));
-_PROTOTYPE(int Tosexec, (char *string ));
-_PROTOTYPE(time_t mstonix, (unsigned int date, unsigned int time ));
-_PROTOTYPE(void getmdate, (int fd, struct sgtbuf *tbp ));
-_PROTOTYPE(time_t cnvtime, (struct sgtbuf *tbp ));
-_PROTOTYPE(void modtime, (struct name *np ));
-_PROTOTYPE(void touch, (struct name *np ));
-_PROTOTYPE(int make, (struct name *np, int level ));
-_PROTOTYPE(void make1, (struct name *np, struct line *lp, struct depend *qdp, 
-					char *basename, char *inputname ));
-_PROTOTYPE(void implmacros, (struct name *np, struct line *lp, 
-					char **pbasename, char **pinputname ));
-_PROTOTYPE(void dbgprint, (int level, struct name *np, char *comment ));
-
-/* reader.c */
-_PROTOTYPE(void error, (char *msg, char *a1 ));
-_PROTOTYPE(bool getline, (struct str *strs, FILE *fd ));
-_PROTOTYPE(char *gettok, (char **ptr ));
-
-/* rules.c */
-_PROTOTYPE(bool dyndep, (struct name *np, char **pbasename,char **pinputname));
-_PROTOTYPE(void makerules, (void));
-
-/* archive.c */
-_PROTOTYPE(int is_archive_ref, (char *name));
-_PROTOTYPE(int archive_stat, (char *name, struct stat *stp));
Index: trunk/minix/commands/make/input.c
===================================================================
--- trunk/minix/commands/make/input.c	(revision 9)
+++ 	(revision )
@@ -1,439 +1,0 @@
-/*************************************************************************
- *
- *  m a k e :   i n p u t . c
- *
- *  Parse a makefile
- *========================================================================
- * Edition history
- *
- *  #    Date                         Comments                       By
- * --- -------- ---------------------------------------------------- ---
- *   1    ??                                                         ??
- *   2 23.08.89 new name tree structure introduced to speed up make,
- *              testname introduced to shrink the memory usage       RAL
- *   3 30.08.89 indention changed                                    PSH,RAL
- *   4 03.09.89 fixed LZ eliminated                                  RAL
- *   5 06.09.89 ; command added                                      RAL
- * ------------ Version 2.0 released ------------------------------- RAL
- *
- *************************************************************************/
-
-
-#include "h.h"
-
-
-static struct name *lastrrp;
-static struct name *freerp = (struct name *)NULL;
-
-void init()
-{
-  if( (suffparray = (struct name **) malloc( sizesuffarray *
-           sizeof(struct name *)))  == (struct name **) NULL)
-     fatal("No memory for suffarray",(char *)0,0);
-  if ((*suffparray = (struct name *)malloc(sizeof (struct name)))
-                          == (struct name *)0)
-     fatal("No memory for name",(char *)0,0);
-  (*suffparray)->n_next = (struct name *)0;
-
-  if ((str1 = (char *) malloc(LZ1)) == ((char *)0))
-     fatal("No memory for str1",(char *)0,0);
-  str1s.ptr = &str1;
-  str1s.len = LZ1;
-  if ((str2 = (char *) malloc(LZ2)) == (char *)0)
-     fatal("No memory for str2",(char *)0,0);
-  str2s.ptr = &str2;
-  str2s.len = LZ2;
-}
-
-void strrealloc(strs)
-struct str *strs;
-{
-  strs->len *= 2;
-  *strs->ptr = (char *) realloc(*strs->ptr, strs->len + 16);
-  if(*strs->ptr == (char *) NULL)
-       fatal("No memory for string reallocation",(char *)0,0);
-}
-
-/*
- *	Intern a name.  Return a pointer to the name struct
- */
-struct name *newname(name)
-char *name;
-{
-  register struct name *rp;
-  register struct name *rrp;
-  register char        *cp;
-
-  register int           i;
-  register char         *suff;   /* ptr. to suffix in current name */
-  register struct name **sp;     /* ptr. to ptr. to chain of names */
-
-  if ( (suff = suffix(name)) != (char *)NULL) {
-     for (i = 1, sp = suffparray, sp++;
-          i <= maxsuffarray && strcmp(suff, (*sp)->n_name) != 0;
-          sp++,i++);
-     if (i > maxsuffarray) {
-        if ( i >= sizesuffarray) { /* must realloc suffarray */
-           sizesuffarray *= 2;
-           if( (suffparray = (struct name **) realloc((char *) suffparray,
-                sizesuffarray * sizeof(struct name *))) == (struct name **) NULL)
-              fatal("No memory for suffarray",(char *)0,0);
-        }
-        maxsuffarray++;
-        sp = &suffparray[i];
-        if ((*sp = (struct name *)malloc(sizeof (struct name)))
-                                   == (struct name *)0)
-           fatal("No memory for name",(char *)0,0);
-        (*sp)->n_next = (struct name *)0;
-        if ((cp = (char *) malloc(strlen(suff)+1)) == (char *)0)
-           fatal("No memory for name",(char *)0,0);
-        strcpy(cp, suff);
-        (*sp)->n_name = cp;
-     }
-  }
-  else
-     sp = suffparray;
-
-  for ( rp = (*sp)->n_next, rrp = *sp; rp; rp = rp->n_next, rrp = rrp->n_next )
-     if (strcmp(name, rp->n_name) == 0)  return rp;
-
-  if ( freerp ==  (struct name *)NULL) {
-     if ((rp = (struct name *)malloc(sizeof (struct name))) == (struct name *)0)
-        fatal("No memory for name",(char *)0,0);
-  }
-  else  {
-     rp = freerp;
-     freerp =  (struct name *)NULL;
-  }
-  rrp->n_next = rp;
-  rp->n_next = (struct name *)0;
-  if ((cp = (char *) malloc(strlen(name)+1)) == (char *)0)
-     fatal("No memory for name",(char *)0,0);
-  strcpy(cp, name);
-  rp->n_name = cp;
-  rp->n_line = (struct line *)0;
-  rp->n_time = (time_t)0;
-  rp->n_flag = 0;
-  lastrrp = rrp;
-
-  return rp;
-}
-
-/*
- *     Test a name.
- *     If the name already exists return the ptr. to its name structure.
- *     Else if the file exists 'intern' the name and return the ptr.
- *     Otherwise don't waste memory and return a NULL pointer
- */
-struct name *testname(name)
-char *name;
-{
-  register struct name *rp;
-
-  lastrrp = (struct name *)NULL;
-  rp = newname( name);
-  if (rp->n_line || rp->n_flag & N_EXISTS)
-     return(rp);
-  modtime(rp);
-  if (rp->n_flag & N_EXISTS)
-     return(rp);
-  if (lastrrp != (struct name *)NULL) {
-     free (rp->n_name);
-     lastrrp->n_next = (struct name *)NULL;
-     freerp = rp;
-  }
-  return((struct name *)NULL);
-}
-
-
-
-/*
- *	Add a dependant to the end of the supplied list of dependants.
- *	Return the new head pointer for that list.
- */
-struct depend *newdep(np, dp)
-struct name   *np;
-struct depend *dp;
-{
-  register struct depend *rp;
-  register struct depend *rrp;
-
-
-  if ((rp = (struct depend *)malloc(sizeof (struct depend)))
-          == (struct depend *)0)
-	fatal("No memory for dependant",(char *)0,0);
-  rp->d_next = (struct depend *)0;
-  rp->d_name = np;
-
-  if (dp == (struct depend *)0)  return rp;
-
-  for (rrp = dp; rrp->d_next; rrp = rrp->d_next) ;
-
-  rrp->d_next = rp;
-
-  return dp;
-}
-
-
-/*
- *	Add a command to the end of the supplied list of commands.
- *	Return the new head pointer for that list.
- */
-struct cmd *newcmd(str, cp)
-char       *str;
-struct cmd *cp;
-{
-  register struct cmd *rp;
-  register struct cmd *rrp;
-  register char       *rcp;
-
-
-  if (rcp = strrchr(str, '\n'))  *rcp = '\0';	/*  Loose newline  */
-
-  while (isspace(*str))  str++;
-
-  if (*str == '\0')  return cp;		/*  If nothing left, the exit  */
-
-  if ((rp = (struct cmd *)malloc(sizeof (struct cmd))) == (struct cmd *)0)
-	fatal("No memory for command",(char *)0,0);
-  rp->c_next = (struct cmd *)0;
-  if ((rcp = (char *) malloc(strlen(str)+1)) == (char *)0)
-	fatal("No memory for command",(char *)0,0);
-  strcpy(rcp, str);
-  rp->c_cmd = rcp;
-
-  if (cp == (struct cmd *)0)  return rp;
-
-  for (rrp = cp; rrp->c_next; rrp = rrp->c_next) ;
-
-  rrp->c_next = rp;
-
-  return cp;
-}
-
-
-/*
- *	Add a new 'line' of stuff to a target.  This check to see
- *	if commands already exist for the target.  If flag is set,
- *	the line is a double colon target.
- *
- *	Kludges:
- *	i)  If the new name begins with a '.', and there are no dependents,
- *	    then the target must cease to be a target.  This is for .SUFFIXES.
- *	ii) If the new name begins with a '.', with no dependents and has
- *	    commands, then replace the current commands.  This is for
- *	    redefining commands for a default rule.
- *	Neither of these free the space used by dependents or commands,
- *	since they could be used by another target.
- */
-
-void newline(np, dp, cp, flag)
-struct name   *np;
-struct depend *dp;
-struct cmd    *cp;
-int            flag;
-{
-  bool                  hascmds = FALSE;  /*  Target has commands  */
-  register struct line *rp;
-  register struct line *rrp;
-
-
-  /* Handle the .SUFFIXES case */
-  if (np->n_name[0] == '.' && !dp && !cp) {
-	for (rp = np->n_line; rp; rp = rrp) {
-		rrp = rp->l_next;
-		free(rp);
-	}
-	np->n_line = (struct line *)0;
-	np->n_flag &= ~N_TARG;
-	return;
-  }
-
-  /* This loop must happen since rrp is used later. */
-  for ( rp = np->n_line, rrp = (struct line *)0; rp; rrp = rp, rp = rp->l_next)
-	if (rp->l_cmd)  hascmds = TRUE;
-
-  if (hascmds && cp && !(np->n_flag & N_DOUBLE))
-	/* Handle the implicit rules redefinition case */
-	if (np->n_name[0] == '.' && dp == (struct depend *)0) {
-		np->n_line->l_cmd = cp;
-		return;
-	}
-	else
-		error("Commands defined twice for target %s", np->n_name);
-  if (np->n_flag & N_TARG)
-	if (!(np->n_flag & N_DOUBLE) != !flag)		/* like xor */
-		error("Inconsistent rules for target %s", np->n_name);
-
-  if ((rp = (struct line *)malloc(sizeof (struct line))) == (struct line *)0)
-	fatal("No memory for line",(char *)0,0);
-  rp->l_next = (struct line *)0;
-  rp->l_dep = dp;
-  rp->l_cmd = cp;
-
-  if (rrp)
-         rrp->l_next = rp;
-  else
-         np->n_line = rp;
-
-  np->n_flag |= N_TARG;
-  if (flag)  np->n_flag |= N_DOUBLE;
-}
-
-
-/*
- *	Parse input from the makefile, and construct a tree structure
- *	of it.
- */
-void input(fd)
-FILE *fd;
-{
-  char          *p;		/*  General  */
-  char          *q;
-  register char *a;
-  struct name   *np;
-  struct depend *dp;
-  struct cmd    *cp;
-  bool dbl;
-
-
-  if (getline(&str1s, fd))  return;	/*  Read the first line  */
-
-  for(;;) {
-	if (*str1 == TABCHAR)	/*  Rules without targets  */
-		error("Rules not allowed here",(char *)0);
-
-	p = str1;
-
-	while (isspace(*p))  p++;	/*  Find first target  */
-
-
-	while (((q = strchr(p, '=')) != (char *)0) &&
-	    (p != q) && (q[-1] == '\\'))	/*  Find value */
-	{
-		a = q - 1;	/*  Del \ chr; move rest back  */
-		p = q;
-		while(*a++ = *q++)
-			;
-	}
-
-	if (q != (char *)0) {
-
-		*q++ = '\0';		/*  Separate name and val  */
-		while (isspace(*q))
-			q++;
-		if (p = strrchr(q, '\n'))
-			*p = '\0';
-
-		p = str1;
-		if ((a = gettok(&p)) == (char *)0)
-			error("No macro name",(char *)0);
-
-		setmacro(a, q);
-
-		if (getline(&str1s, fd))
-			return;
-		continue;
-	}
-
-	/* include? */
-	p = str1;
-	while (isspace(*p)) p++;
-	if (strncmp(p, "include", 7) == 0 && isspace(p[7])) {
-		char *old_makefile = makefile;
-		int old_lineno = lineno;
-		FILE *ifd;
-
-		p += 8;
-		memmove(str1, p, strlen(p)+1);
-		expand(&str1s);
-		p = str1;
-		while (isspace(*p)) p++;
-
-		if ((q = malloc(strlen(p)+1)) == (char *)0)
-			fatal("No memory for include",(char *)0,0);
-
-		strcpy(q, p);
-		p = q;
-		while ((makefile = gettok(&q)) != (char *)0) {
-			if ((ifd = fopen(makefile, "r")) == (FILE *)0)
-				fatal("Can't open %s: %s", makefile, errno);
-			lineno = 0;
-			input(ifd);
-			fclose(ifd);
-		}
-		free(p);
-		makefile = old_makefile;
-		lineno = old_lineno;
-
-		if (getline(&str1s, fd))
-			return;
-		continue;
-	}
-
-	/* Search for commands on target line --- do not expand them ! */
-	q = str1;
-	cp = (struct cmd *)0;
-	if ((a = strchr(q, ';')) != (char *)0) {
-		*a++ = '\0';	/*  Separate dependents and commands */
-		if ( a) cp = newcmd(a, cp);
-	}
-
-	expand(&str1s);
-	p = str1;
-
-	while (isspace(*p)) p++;
-
-	while (((q = strchr(p, ':')) != (char *)0) &&
-	    (p != q) && (q[-1] == '\\'))	/*  Find dependents  */
-	{
-		a = q - 1;	/*  Del \ chr; move rest back  */
-		p = q;
-		while(*a++ = *q++) ;
-	}
-
-	if (q == (char *)0)
-		error("No targets provided",(char *)0);
-
-	*q++ = '\0';	/*  Separate targets and dependents  */
-
-	if (*q == ':') {		/* Double colon */
-		dbl = 1;
-		q++;
-	}
-	else
-		dbl = 0;
-
-	for (dp = (struct depend *)0; ((p = gettok(&q)) != (char *)0);)
-				/*  get list of dep's */
-	{
-		np = newname(p);		/*  Intern name  */
-		dp = newdep(np, dp);		/*  Add to dep list */
-	}
-
-	*((q = str1) + strlen(str1) + 1) = '\0';
-		/*  Need two nulls for gettok (Remember separation)  */
-
-	if (getline(&str2s, fd) == FALSE) {		/*  Get commands  */
-		while (*str2 == TABCHAR) {
-			cp = newcmd(&str2[0], cp);
-			if (getline(&str2s, fd))
-				break;
-		}
-	}
-
-	while ((p = gettok(&q)) != (char *)0)	/* Get list of targ's */
-	{
-		np = newname(p);		/*  Intern name  */
-		newline(np, dp, cp, dbl);
-		if (!firstname && p[0] != '.')
-			firstname = np;
-	}
-
-	if (feof(fd))				/*  EOF?  */
-		return;
-
-	while (strlen(str2) >= str1s.len) strrealloc(&str1s);
-	strcpy(str1, str2);
-  }
-}
Index: trunk/minix/commands/make/macro.c
===================================================================
--- trunk/minix/commands/make/macro.c	(revision 9)
+++ 	(revision )
@@ -1,197 +1,0 @@
-/*************************************************************************
- *
- *  m a k e :   m a c r o . c
- *
- *  Macro control for make
- *========================================================================
- * Edition history
- *
- *  #    Date                         Comments                       By
- * --- -------- ---------------------------------------------------- ---
- *   1    ??                                                         ??
- *   2 23.08.89 Error message corrected                              RAL
- *   3 30.08.89 macro flags added, indention ch.                     PSH,RAL
- *   4 03.09.89 fixed LZ eliminated, doexp(...) changed              RAL
- *   5 06.09.89 M_MAKE added, setDFmacro added                       RAL
- *   6 20.09.89 work around for Minix PC ACK bug                     BE,RAL
- * ------------ Version 2.0 released ------------------------------- RAL
- *
- *************************************************************************/
-
-#include "h.h"
-
-
-static char   buf[256];
-
-struct macro *getmp(name)
-char *name;
-{
-  register struct macro *rp;
-
-  for (rp = macrohead; rp; rp = rp->m_next)
-		if (strcmp(name, rp->m_name) == 0)
-			return rp;
-  return (struct macro *)0;
-}
-
-
-char *getmacro(name)
-char *name;
-{
-  struct macro *mp;
-
-  if (mp = getmp(name))
-		return mp->m_val;
-/*	else*/
-		return "";
-}
-
-
-struct macro *setmacro(name, val)
-char *name;
-char *val;
-{
-  register struct macro *rp;
-  register char         *cp;
-
-
-		/*  Replace macro definition if it exists  */
-  for (rp = macrohead; rp; rp = rp->m_next)
-	if (strcmp(name, rp->m_name) == 0) {
-		if(rp->m_flag & M_OVERRIDE) return rp;	/* mustn't change */
-		free(rp->m_val);	/*  Free space from old  */
-		break;
-		}
-
-	if (!rp)		/*  If not defined, allocate space for new  */
-	{
-		if ((rp = (struct macro *)malloc(sizeof (struct macro)))
-					 == (struct macro *)0)
-			fatal("No memory for macro",(char *)0,0);
-
-		rp->m_next = macrohead;
-		macrohead = rp;
-		rp->m_flag = FALSE;
-
-		if ((cp = (char *) malloc(strlen(name)+1)) == (char *)0)
-			fatal("No memory for macro",(char *)0,0);
-		strcpy(cp, name);
-		rp->m_name = cp;
-	}
-
-	if ((cp = (char *) malloc(strlen(val)+1)) == (char *)0)
-		fatal("No memory for macro",(char *)0,0);
-	strcpy(cp, val);		/*  Copy in new value  */
-	rp->m_val = cp;
-
-  return rp;
-}
-
-
-void setDFmacro(name, val)
-char *name;
-char *val;
-{
-  char        *c,*tmp;
-  int          len;
-  static char  filename[]="@F";
-  static char  dirname[] ="@D";
-
-  setmacro(name,val);
-  *filename = *name;
-  *dirname  = *name;
-  /* Null string -- not defined macro */
-  if ( !(*val)) {
-     setmacro(filename,"");
-     setmacro(dirname,"");
-     return;
-  }
-  if (!(c = strrchr(val,(int)'/'))) {
-     setmacro(filename,val);
-     setmacro(dirname,"./");
-     return;
-  }
-  setmacro(filename,c+1);
-  len = c - val + 1;
-  if((tmp = (char *) malloc(len + 1)) == (char *) 0)
-     fatal("No memory for tmp",(char *)0,0);
-  strncpy(tmp,val,len);
-  tmp[len] = '\0';
-  setmacro(dirname,tmp);
-  free(tmp);
-  return;
-}
-
-/*
- *	Do the dirty work for expand
- */
-void doexp(to, from)
-struct str *to;
-char  *from;
-{
-  register char *rp;
-  register char *p;
-  char *q;
-  struct macro *mp;
-
-
-  rp = from;
-  p  = &(*to->ptr)[to->pos];
-  while (*rp) {
-	if (*rp != '$') {
-		*p++ = *rp++;
-		to->pos++;
-	}
-	else {
-		q = buf;
-		if (*++rp == '{')
-			while (*++rp && *rp != '}')
-				*q++ = *rp;
-		else if (*rp == '(')
-			while (*++rp && *rp != ')')
-				*q++ = *rp;
-		else if (!*rp) {
-			*p++ = '$';
-			to->pos++;
-			goto bail;
-		}
-		else
-			*q++ = *rp;
-		*q = '\0';
-		if (*rp)
-			rp++;
-		if (!(mp = getmp(buf)))
-			mp = setmacro(buf, "");
-		if (mp->m_flag & M_MARK)
-			fatal("Infinitely recursive macro %s", mp->m_name,0);
-		mp->m_flag |= M_MARK;
-		if ( mp->m_flag & M_MAKE) expmake = TRUE;
-		doexp(to, mp->m_val);
-		p = &(*to->ptr)[to->pos];
-		mp->m_flag &= ~M_MARK;
-	}
-  bail:
-	if (to->pos >= to->len) {
-		strrealloc(to);
-		p = &(*to->ptr)[to->pos];
-	}
-  }
-  *p = '\0';
-}
-
-
-/*
- *	Expand any macros in str.
- */
-void expand(strs)
-struct str *strs;
-{
-  char  *a;
-
-  if ((a = (char *) malloc(strlen(*strs->ptr)+1)) == (char *)0)
-     fatal("No memory for temporary string",(char *)0,0);
-  strcpy(a, *strs->ptr);
-  strs->pos = 0;
-  doexp(strs, a);
-  free(a);
-}
Index: trunk/minix/commands/make/main.c
===================================================================
--- trunk/minix/commands/make/main.c	(revision 9)
+++ 	(revision )
@@ -1,288 +1,0 @@
-/*************************************************************************
- *
- *  m a k e :   m a i n . c
- *
- *========================================================================
- * Edition history
- *
- *  #    Date                         Comments                       By
- * --- -------- ---------------------------------------------------- ---
- *   1    ??                                                         ??
- *   2 01.07.89 strcmp(makefile,..) only if makefile a valid ptr.    RAL
- *   3 23.08.89 initname() added                                     RAL
- *   4 30.08.89 argument parsing impr., indention ch., macro fl. add.PSH,RAL
- *   5 03.09.89 k-option added, initname -> init changed             RAL
- *   6 06.09.89 environment, MAKEFLAGS, e,d,a options added,         RAL
- *   7 09.09.89 tos support added, fatal args added, fopen makefile  PHH,RAL
- *   8 17.09.89 setoptions fixed for __STDC__                        RAL
- * ------------ Version 2.0 released ------------------------------- RAL
- *
- *************************************************************************/
-
-/*
- *	make:
- *
- *	-a try to guess undefined ambiguous macros (*,<)
- *	-d print debugging info
- *	-e environment macro def. overwrite makefile def.
- *	-f makefile name
- *	-i ignore exit status
- *	-k continue on errors
- *	-n pretend to make
- *	-p print all macros & targets
- *	-q question up-to-dateness of target.  Return exit status 1 if not
- *	-r don't not use inbuilt rules
- *	-s make silently
- *	-t touch files instead of making them
- *	-m Change memory requirements (EON only)
- */
-
-#define EXTERN
-#define INIT(x) = x
-#define INITARRAY
-#include "h.h"
-
-static char version[]= "2.0";
-
-static FILE *ifd;           /*  Input file desciptor  */
-static char *ptrmakeflags;
-
-/* There must be enough 'space' for all possible flags ! */
-static char  makeflags[] = "MAKEFLAGS=                    ";
-
-void main(argc, argv)
-int    argc;
-char **argv;
-{
-  register char        *p;		/*  For argument processing  */
-  int                   estat = 0;	/*  For question  */
-  register struct name *np;
-  struct macro         *mp;
-  int                   targc;		/* temporary for multiple scans */
-  char                **targv;
-  char                **nargv;		/* for removing items from argv */
-  char                **envp;      /* enivironment ptr */
-
-
-  ptrmakeflags = &makeflags[10];
-  myname = (argc-- < 1) ? "make" : *argv++;
-#ifdef tos
-  myname = "Make";
-#endif
-
-  targc = argc;
-  targv = nargv = argv;
-  while (targc--) {
-	if((p = strchr(*targv, '=')) != (char *)NULL) {
-		*p = '\0';
-		mp = setmacro(*targv, p + 1);
-		mp->m_flag |= M_OVERRIDE;
-		--argc;
-	} else
-		*nargv++ = *targv;
-
-	++targv;
-  }
-
-  targc = argc;
-  targv = nargv = argv;
-  while (targc--) {
-	if (**targv == '-') {
-		--argc;
-		p = *targv++;
-		while (*++p != '\0') {
-			switch(mylower(*p)) {
-			case 'f':	/*  Alternate file name  */
-				if (*++p == '\0') {
-					--argc;
-					if (targc-- == 0)
-						usage();
-					p = *targv++;
-				}
-				makefile = p;
-				goto end_of_args;
-#ifdef eon
-			case 'm':	/*  Change space requirements  */
-				if (*++p == '\0') {
-					--argc;
-					if (targc-- <= 0)
-						usage();
-					p = *targv++;
-				}
-				memspace = atoi(p);
-				goto end_of_args;
-#endif
-			default :
-				setoption(*p);
-				break;
-			}
-		}
-	end_of_args:;
-	} else
-		*nargv++ = *targv++;
-  }
-
-  /* evaluate and update environment MAKEFLAGS */
-  if((p =getenv("MAKEFLAGS")) != (char *)0)
-	while(*p) setoption(*p++);
-  for( p = ptrmakeflags; !isspace((int)*p); p++) ;
-  *p = '\0';
-  putenv(makeflags);
-
-
-#ifdef eon
-  if (initalloc(memspace) == 0xffff)  /*  Must get memory for alloc  */
-	fatal("Cannot initalloc memory",(char *)0,0);
-#endif
-
-  if (makefile && strcmp(makefile, "-") == 0)  /*   use stdin as makefile  */
-	ifd = stdin;
-  else if (!makefile) {    /*  If no file, then use default */
-	if ((ifd = fopen(makefile = DEFN1, "r")) == (FILE *)0) {
-		if (errno != MNOENT || !DEFN2)
-			fatal("Can't open %s: %s", DEFN1, errno);
-		else if ((ifd = fopen(makefile = DEFN2, "r")) == (FILE *)0)
-			fatal("Can't open %s: %s", DEFN2, errno);
-	}
-  }
-  else if ((ifd = fopen(makefile, "r")) == (FILE *)0)
-	fatal("Can't open %s: %s", makefile, errno);
-
-  init();
-
-  makerules();
-
-  mp = setmacro("MAKE", myname);
-  mp->m_flag |= M_MAKE;
-  setmacro("$", "$");
-
-  /* set environment macros */
-  envp = environ; /* get actual environment ptr. */
-  while (*envp) {
-	if((p = strchr(*envp, '=')) != (char *)NULL) {
-		*p = '\0';
-		mp = setmacro(*envp, p + 1);
-		*p = '=';
-		if (useenv) mp->m_flag |= M_OVERRIDE;
-	} else
-		fatal("invalid environment: %s",*envp,0);
-
-	++envp;
-  }
-
-  input(ifd);	/*  Input all the gunga  */
-  fclose(ifd);	/*  Finished with makefile  */
-  lineno = 0;	/*  Any calls to error now print no line number */
-
-  if (print)
-	prt();	/*  Print out structures  */
-
-  np = newname(".SILENT");
-  if (np->n_flag & N_TARG)  silent = TRUE;
-
-  np = newname(".IGNORE");
-  if (np->n_flag & N_TARG)  ignore = TRUE;
-
-  precious();
-
-  if (!firstname)
-	fatal("No targets defined",(char *)0,0);
-
-  circh();	/*  Check circles in target definitions  */
-
-  if (!argc)
-	estat = make(firstname, 0);
-  else
-	while (argc--) {
-		estat |= make(newname(*argv++), 0);
-	}
-
-  if (quest)
-	exit(estat);
-  else
-		exit(0);
-}
-
-#ifdef __STDC__
-void setoption(char option)
-#else
-void setoption(option)
-char option;
-#endif
-{
-  register char *c;
-
-  option = mylower(option);
-  switch(option) {
-	case 'n':	/*  Pretend mode  */
-		domake = FALSE;
-		break;
-	case 'i':	/*  Ignore fault mode  */
-		ignore = TRUE;
-		break;
-	case 'k':	/*  Continue on errror  */
-		conterr = TRUE;
-		break;
-	case 's':	/*  Silent about commands  */
-		silent = TRUE;
-		break;
-	case 'p':
-		print = TRUE;
-		break;
-	case 'r':
-		rules = FALSE;
-		break;
-	case 't':
-		dotouch = TRUE;
-		break;
-	case 'q':
-		quest = TRUE;
-		break;
-	case 'e':
-		useenv = TRUE;
-		break;
-	case 'd':
-		dbginfo = TRUE;
-		break;
-	case 'a':
-		ambigmac = TRUE;
-		break;
-	default:	/*  Wrong option  */
-		usage();
-  }
-  for( c = ptrmakeflags; !isspace((int)*c); c++)
-	if ( *c == option) return;
-  *c = option;
-}
-
-void usage()
-{
-  fprintf(stderr, "Syntax: %s [{options | macro=val | target}]\n", myname);
-  fprintf(stderr, "Function: maintaining computer programs      V%s\n",version);
-  fprintf(stderr, "Options : -a : try to guess undefined ambiguous macros (*,<)\n");
-  fprintf(stderr, "          -d : print debugging information\n");
-  fprintf(stderr, "          -e : environment macro def. overwrite makefile def.\n");
-  fprintf(stderr, "          -f filename : makefile name (default: makefile, Makefile)\n");
-  fprintf(stderr, "          -i : ignore exit status of executed commands\n");
-  fprintf(stderr, "          -k : continue with unrelated branches on errors\n");
-  fprintf(stderr, "          -n : pretend to make\n");
-  fprintf(stderr, "          -p : print all macros & targets\n");
-  fprintf(stderr, "          -q : question up-to-dateness of target\n");
-  fprintf(stderr, "          -r : don't use inbuilt rules\n");
-  fprintf(stderr, "          -s : make silently\n");
-  fprintf(stderr, "          -t : touch files instead of making them\n");
-  fprintf(stderr, "Environment: MAKEFLAGS\n");
-  exit(1);
-}
-
-
-void fatal(msg, a1, a2)
-char *msg;
-char *a1;
-int   a2;
-{
-  fprintf(stderr, "%s: ", myname);
-  fprintf(stderr, msg, a1, strerror(a2));
-  fputc('\n', stderr);
-  exit(1);
-}
Index: trunk/minix/commands/make/make.c
===================================================================
--- trunk/minix/commands/make/make.c	(revision 9)
+++ 	(revision )
@@ -1,782 +1,0 @@
-/*************************************************************************
- *
- *  m a k e :   m a k e . c
- *
- *  Do the actual making for make plus system dependent stuff
- *========================================================================
- * Edition history
- *
- *  #    Date                         Comments                       By
- * --- -------- ---------------------------------------------------- ---
- *   1    ??                                                         ??
- *   2 01.07.89 $<,$* bugs fixed                                     RAL
- *   3 23.08.89 (time_t)time((time_t*)0) bug fixed, N_EXISTS added   RAL
- *   4 30.08.89 leading sp. in cmd. output eliminated, indention ch. PSH,RAL
- *   5 03.09.89 :: time fixed, error output -> stderr, N_ERROR intr.
- *              fixed LZ elimintaed                                  RAL
- *   6 07.09.89 implmacro, DF macros,debug stuff added               RAL
- *   7 09.09.89 tos support added                                    PHH,RAL
- *   8 17.09.89 make1 arg. fixed, N_EXEC introduced                  RAL
- * ------------ Version 2.0 released ------------------------------- RAL
- *     18.05.90 fixed -n bug with silent rules.  (Now echos them.)   PAN
- *
- *************************************************************************/
-
-#include "h.h"
-#include <sys/wait.h>
-#include <unistd.h>
-
-_PROTOTYPE(static void tellstatus, (FILE *out, char *name, int status));
-
-static bool  execflag;
-
-/*
- *	Exec a shell that returns exit status correctly (/bin/esh).
- *	The standard EON shell returns the process number of the last
- *	async command, used by the debugger (ugg).
- *	[exec on eon is like a fork+exec on unix]
- */
-int dosh(string, shell)
-char *string;
-char *shell;
-{
-  int number;
-
-#ifdef unix
-  return system(string);
-#endif
-#ifdef tos
-  return Tosexec(string);
-#endif
-#ifdef eon
-  return ((number = execl(shell, shell,"-c", string, 0)) == -1) ?
-	-1:	/* couldn't start the shell */
-	wait(number);	/* return its exit status */
-#endif
-#ifdef os9
-  int	status, pid;
-
-  strcat(string, "\n");
-  if ((number = os9fork(shell, strlen(string), string, 0, 0, 0)) == -1)
-	return -1;		/* Couldn't start a shell */
-  do {
-	if ((pid = wait(&status)) == -1)
-		return -1;	/* child already died!?!? */
-  } while (pid != number);
-
-  return status;
-#endif
-}
-
-
-#ifdef unix
-/*
- *    Make a file look very outdated after an error trying to make it.
- *    Don't remove, this keeps hard links intact.  (kjb)
- */
-int makeold(name) char *name;
-{
-  struct utimbuf a;
-
-  a.actime = a.modtime = 0;	/* The epoch */
-
-  return utime(name, &a);
-}
-#endif
-
-
-static void tellstatus(out, name, status)
-FILE *out;
-char *name;
-int status;
-{
-  char cwd[PATH_MAX];
-
-  fprintf(out, "%s in %s: ",
-	name, getcwd(cwd, sizeof(cwd)) == NULL ? "?" : cwd);
-
-  if (WIFEXITED(status)) {
-	fprintf(out, "Exit code %d", WEXITSTATUS(status));
-  } else {
-	fprintf(out, "Signal %d%s",
-		WTERMSIG(status), status & 0x80 ? " - core dumped" : "");
-  }
-}
-
-
-/*
- *	Do commands to make a target
- */
-void docmds1(np, lp)
-struct name *np;
-struct line *lp;
-{
-  register char       *q;
-  register char       *p;
-  register struct cmd *cp;
-  bool                 ssilent;
-  bool                 signore;
-  int                  estat;
-  char                *shell;
-
-
-  if (*(shell = getmacro("SHELL")) == '\0')
-#ifdef eon
-	shell = ":bin/esh";
-#endif
-#ifdef unix
-	shell = "/bin/sh";
-#endif
-#ifdef os9
-	shell = "shell";
-#endif
-#ifdef tos
-	shell = "DESKTOP";      /* TOS has no shell */
-#endif
-
-  for (cp = lp->l_cmd; cp; cp = cp->c_next) {
-	execflag = TRUE;
-	strcpy(str1, cp->c_cmd);
-	expmake = FALSE;
-	expand(&str1s);
-	q = str1;
-	ssilent = silent;
-	signore = ignore;
-	while ((*q == '@') || (*q == '-')) {
-		if (*q == '@')	   /*  Specific silent  */
-			ssilent = TRUE;
-		else		   /*  Specific ignore  */
-			signore = TRUE;
-		if (!domake) putchar(*q);  /* Show all characters. */
-		q++;		   /*  Not part of the command  */
-	}
-
-	for (p=q; *p; p++) {
-		if (*p == '\n' && p[1] != '\0') {
-			*p = ' ';
-			if (!ssilent || !domake)
-				fputs("\\\n", stdout);
-		}
-		else if (!ssilent || !domake)
-			putchar(*p);
-	}
-	if (!ssilent || !domake)
-		putchar('\n');
-
-	if (domake || expmake) {	/*  Get the shell to execute it  */
-		fflush(stdout);
-		if ((estat = dosh(q, shell)) != 0) {
-		    if (estat == -1)
-			fatal("Couldn't execute %s", shell,0);
-		    else if (signore) {
-			tellstatus(stdout, myname, estat);
-			printf(" (Ignored)\n");
-		    } else {
-			tellstatus(stderr, myname, estat);
-			fprintf(stderr, "\n");
-			if (!(np->n_flag & N_PREC))
-#ifdef unix
-			    if (makeold(np->n_name) == 0)
-				fprintf(stderr,"%s: made '%s' look old.\n", myname, np->n_name);
-#else
-			    if (unlink(np->n_name) == 0)
-				fprintf(stderr,"%s: '%s' removed.\n", myname, np->n_name);
-#endif
-			if (!conterr) exit(estat != 0);
-			np->n_flag |= N_ERROR;
-			return;
-		    }
-		}
-	}
-  }
-}
-
-
-void docmds(np)
-struct name *np;
-{
-  register struct line *lp;
-
-  for (lp = np->n_line; lp; lp = lp->l_next)
-	docmds1(np, lp);
-}
-
-#ifdef tos
-/*
- *      execute the command submitted by make,
- *      needed because TOS has no internal shell,
- *      so we use Pexec to do the job
- *        v 1.1 of 10/sep/89 by yeti
- */
-
-#define DELM1 ';'
-#define DELM2 ' '
-#define DELM3 ','
-
-int Tosexec(string)
-char *string;
-{
-  register char *help, *help2, c;
-  register unsigned char l=1;
-  char progname[80], command[255], plain[15];
-  static char **envp,*env;
-  register int error,i;
-
-  /* generate strange TOS environment (RAL) */
-  for ( i = 0, envp = environ; *envp; envp++) i += strlen(*envp) +1;
-  if ((env = malloc(i+1)) == (char *)0)
-     fatal("No memory for TOS environment",(char *)0,0);
-  for ( envp = environ, help = env; *envp; envp++) {
-     strcpy ( help, *envp);
-     while ( *(help++)) ;
-  }
-  *help = '\0';
-
-  help = progname;
-  while((*help++=*string++) != ' '); /* progname is command name */
-  *--help = '\0';
-
-  l = strlen(string);             /* build option list */
-  command[0] = l;                 /* TOS likes it complicated */
-  strcpy(&command[1],string);
-  if ((error = (int) Pexec(0,progname,command,env)) != -33) {
-    free(env);
-    return(error);
-  }
-
-  /* could'nt find program, try to search the PATH */
-  if((help=strrchr(progname,'\\')) != (char *) 0)  /* just the */
-          strcpy(plain,++help);                     /* name     */
-  else if((help=strrchr(progname,'/')) != (char *) 0)
-          strcpy(plain,++help);
-  else if((help=strrchr(progname,':')) != (char *) 0)
-          strcpy(plain,++help);
-  else
-          strcpy(plain,progname);
-
-  if(*(help=getmacro("PATH")) == '\0') {
-    free(env);
-    return(-33);
-  }
-  c = 1;
-  while(c)
-  {       help2 = &progname[-1];
-          i = 0;
-          while((c=*help++) != '\0' && i<80 && c != DELM1
-                 && c != DELM2 && c != DELM3)
-                  *++help2 = c, i++;
-          *++help2 = '\\';
-          strcpy(++help2,plain);
-          if((error=(int) Pexec(0,progname,command,env))!=-33) {
-                  free(env);
-                  return(error);
-          }
-  }
-  free(env);
-  return(-33);
-}
-
-
-/* (stolen from ZOO -- thanks to Rahul Dehsi)
-Function mstonix() accepts an MSDOS format date and time and returns
-a **IX format time.  No adjustment is done for timezone.
-*/
-
-time_t mstonix (date, time)
-unsigned int date, time;
-{
-   int year, month, day, hour, min, sec, daycount;
-   time_t longtime;
-   /* no. of days to beginning of month for each month */
-   static int dsboy[12] = { 0, 31, 59, 90, 120, 151, 181, 212,
-                              243, 273, 304, 334};
-
-   if (date == 0 && time == 0)			/* special case! */
-      return (0L);
-
-   /* part of following code is common to zoolist.c */
-   year  =  (((unsigned int) date >> 9) & 0x7f) + 1980;
-   month =  ((unsigned int) date >> 5) & 0x0f;
-   day   =  date        & 0x1f;
-
-   hour =  ((unsigned int) time >> 11)& 0x1f;
-   min   =  ((unsigned int) time >> 5) & 0x3f;
-   sec   =  ((unsigned int) time & 0x1f) * 2;
-
-/* DEBUG and leap year fixes thanks to Mark Alexander <uunet!amdahl!drivax!alexande>*/
-#ifdef DEBUG
-   printf ("mstonix:  year=%d  month=%d  day=%d  hour=%d  min=%d  sec=%d\n",
-         year, month, day, hour, min, sec);
-#endif
-   /* Calculate days since 1970/01/01 */
-   daycount = 365 * (year - 1970) +    /* days due to whole years */
-               (year - 1969) / 4 +     /* days due to leap years */
-               dsboy[month-1] +        /* days since beginning of this year */
-               day-1;                  /* days since beginning of month */
-
-   if (year % 4 == 0 &&
-       year % 400 != 0 && month >= 3)  /* if this is a leap year and month */
-      daycount++;                      /* is March or later, add a day */
-
-   /* Knowing the days, we can find seconds */
-   longtime = daycount * 24L * 60L * 60L    +
-          hour * 60L * 60L   +   min * 60   +    sec;
-	return (longtime);
-}
-#endif /* tos */
-
-#ifdef os9
-/*
- *	Some stuffing around to get the modified time of a file
- *	in an os9 file system
- */
-void getmdate(fd, tbp)
-int fd;
-struct sgtbuf *tbp;
-{
-  struct registers     regs;
-  static struct fildes fdbuf;
-
-
-  regs.rg_a = fd;
-  regs.rg_b = SS_FD;
-  regs.rg_x = &fdbuf;
-  regs.rg_y = sizeof (fdbuf);
-
-  if (_os9(I_GETSTT, &regs) == -1) {
-	errno = regs.rg_b & 0xff;
-	return -1;
-  }
-  if (tbp)
-  {
-	_strass(tbp, fdbuf.fd_date, sizeof (fdbuf.fd_date));
-	tbp->t_second = 0;	/* Files are only acurate to mins */
-  }
-  return 0;
-}
-
-
-/*
- *	Kludge routine to return an aproximation of how many
- *	seconds since 1980.  Dates will be in order, but will not
- *	be lineer
- */
-time_t cnvtime(tbp)
-struct sgtbuf *tbp;
-{
-  long acc;
-
-  acc = tbp->t_year - 80;		/* Baseyear is 1980 */
-  acc = acc * 12 + tbp->t_month;
-  acc = acc * 31 + tbp->t_day;
-  acc = acc * 24 + tbp->t_hour;
-  acc = acc * 60 + tbp->t_minute;
-  acc = acc * 60 + tbp->t_second;
-
-  return acc;
-}
-
-
-/*
- *	Get the current time in the internal format
- */
-void time(tp)
-time_t *tp;
-{
-  struct sgtbuf tbuf;
-
-
-  if (getime(&tbuf) < 0)
-	return -1;
-
-  if (tp)
-	*tp = cnvtime(&tbuf);
-
-  return 0;
-}
-#endif
-
-
-/*
- *	Get the modification time of a file.  If the first
- *	doesn't exist, it's modtime is set to 0.
- */
-void modtime(np)
-struct name *np;
-{
-#ifdef unix
-  struct stat info;
-  int r;
-
-  if (is_archive_ref(np->n_name)) {
-	r = archive_stat(np->n_name, &info);
-  } else {
-	r = stat(np->n_name, &info);
-  }
-  if (r < 0) {
-	if (errno != ENOENT)
-		fatal("Can't open %s: %s", np->n_name, errno);
-
-	np->n_time = 0L;
-	np->n_flag &= ~N_EXISTS;
-  } else {
-	np->n_time = info.st_mtime;
-	np->n_flag |= N_EXISTS;
-  }
-#endif
-#ifdef tos
-  struct DOSTIME fm;
-  int fd;
-
-  if((fd=Fopen(np->n_name,0)) < 0) {
-        np->n_time = 0L;
-	np->n_flag &= ~N_EXISTS;
-  }
-  else {
-        Fdatime(&fm,fd,0);
-        Fclose(fd);
-        np->n_time = mstonix((unsigned int)fm.date,(unsigned int)fm.time);
-        np->n_flag |= N_EXISTS;
-  }
-#endif
-#ifdef eon
-  struct stat  info;
-  int          fd;
-
-  if ((fd = open(np->n_name, 0)) < 0) {
-	if (errno != ER_NOTF)
-		fatal("Can't open %s: %s", np->n_name, errno);
-
-	np->n_time = 0L;
-	np->n_flag &= ~N_EXISTS;
-  }
-  else if (getstat(fd, &info) < 0)
-	fatal("Can't getstat %s: %s", np->n_name, errno);
-  else {
-	np->n_time = info.st_mod;
-	np->n_flag |= N_EXISTS;
-  }
-
-  close(fd);
-#endif
-#ifdef os9
-  struct sgtbuf  info;
-  int            fd;
-
-  if ((fd = open(np->n_name, 0)) < 0) {
-  if (errno != E_PNNF)
-		fatal("Can't open %s: %s", np->n_name, errno);
-
-	np->n_time = 0L;
-	np->n_flag &= ~N_EXISTS;
-  }
-  else if (getmdate(fd, &info) < 0)
-	fatal("Can't getstat %s: %s", np->n_name, errno);
-  else {
-	np->n_time = cnvtime(&info);
-	np->n_flag |= N_EXISTS;
-  }
-
-  close(fd);
-#endif
-}
-
-
-/*
- *	Update the mod time of a file to now.
- */
-void touch(np)
-struct name *np;
-{
-  char  c;
-  int   fd;
-
-  if (!domake || !silent) printf("touch(%s)\n", np->n_name);
-
-  if (domake) {
-#ifdef unix
-	struct utimbuf   a;
-
-	a.actime = a.modtime = time((time_t *)NULL);
-	if (utime(np->n_name, &a) < 0)
-		printf("%s: '%s' not touched - non-existant\n",
-				myname, np->n_name);
-#endif
-#ifdef tos
-        struct DOSTIME fm;
-        int fd;
-
-        if((fd=Fopen(np->n_name,0)) < 0) {
-                printf("%s: '%s' not touched - non-existant\n",
-                                myname, np->n_name);
-        }
-        else {
-                fm.date = Tgetdate();
-                fm.time = Tgettime();
-                Fdatime(&fm,fd,1);
-                Fclose(fd);
-        }
-#endif
-#ifdef eon
-	if ((fd = open(np->n_name, 0)) < 0)
-		printf("%s: '%s' not touched - non-existant\n",
-				myname, np->n_name);
-	else
-	{
-		uread(fd, &c, 1, 0);
-		uwrite(fd, &c, 1);
-	}
-	close(fd);
-#endif
-#ifdef os9
-	/*
-	 *	Strange that something almost as totally useless
-	 *	as this is easy to do in os9!
-	 */
-	if ((fd = open(np->n_name, S_IWRITE)) < 0)
-		printf("%s: '%s' not touched - non-existant\n",
-				myname, np->n_name);
-	close(fd);
-#endif
-  }
-}
-
-
-/*
- *	Recursive routine to make a target.
- */
-int make(np, level)
-struct name *np;
-int          level;
-{
-  register struct depend  *dp;
-  register struct line    *lp;
-  register struct depend  *qdp;
-  time_t  now, t, dtime = 0;
-  bool    dbgfirst     = TRUE;
-  char   *basename  = (char *) 0;
-  char   *inputname = (char *) 0;
-
-  if (np->n_flag & N_DONE) {
-     if(dbginfo) dbgprint(level,np,"already done");
-     return 0;
-  }
-
-  modtime(np);		/*  Gets modtime of this file  */
-
-  while (time(&now) == np->n_time) {
-     /* Time of target is equal to the current time.  This bothers us, because
-      * we can't tell if it needs to be updated if we update a file it depends
-      * on within a second.  So wait until the second is over.
-      */
-     usleep(10000);
-  }
-
-  if (rules) {
-     for (lp = np->n_line; lp; lp = lp->l_next)
-        if (lp->l_cmd)
-           break;
-     if (!lp)
-        dyndep(np,&basename,&inputname);
-  }
-
-  if (!(np->n_flag & (N_TARG | N_EXISTS))) {
-     fprintf(stderr,"%s: Don't know how to make %s\n", myname, np->n_name);
-     if (conterr) {
-        np->n_flag |= N_ERROR;
-        if (dbginfo) dbgprint(level,np,"don't know how to make");
-        return 0;
-     }
-     else  exit(1);
-  }
-
-  for (qdp = (struct depend *)0, lp = np->n_line; lp; lp = lp->l_next) {
-     for (dp = lp->l_dep; dp; dp = dp->d_next) {
-        if(dbginfo && dbgfirst) {
-           dbgprint(level,np," {");
-           dbgfirst = FALSE;
-        }
-        make(dp->d_name, level+1);
-        if (np->n_time < dp->d_name->n_time)
-           qdp = newdep(dp->d_name, qdp);
-        dtime = max(dtime, dp->d_name->n_time);
-        if (dp->d_name->n_flag & N_ERROR) np->n_flag |= N_ERROR;
-        if (dp->d_name->n_flag & N_EXEC ) np->n_flag |= N_EXEC;
-     }
-     if (!quest && (np->n_flag & N_DOUBLE) &&
-           (np->n_time < dtime || !( np->n_flag & N_EXISTS))) {
-        execflag = FALSE;
-        make1(np, lp, qdp, basename, inputname); /* free()'s qdp */
-        dtime = 0;
-        qdp = (struct depend *)0;
-        if(execflag) np->n_flag |= N_EXEC;
-     }
-  }
-
-  np->n_flag |= N_DONE;
-
-  if (quest) {
-     t = np->n_time;
-     np->n_time = now;
-     return (t < dtime);
-  }
-  else if ((np->n_time < dtime || !( np->n_flag & N_EXISTS))
-               && !(np->n_flag & N_DOUBLE)) {
-     execflag = FALSE;
-     make1(np, (struct line *)0, qdp, basename, inputname); /* free()'s qdp */
-     np->n_time = now;
-     if ( execflag) np->n_flag |= N_EXEC;
-  }
-  else if ( np->n_flag & N_EXEC ) {
-     np->n_time = now;
-  }
-
-  if (dbginfo) {
-     if(dbgfirst) {
-        if(np->n_flag & N_ERROR)
-              dbgprint(level,np,"skipped because of error");
-        else if(np->n_flag & N_EXEC)
-              dbgprint(level,np,"successfully made");
-        else  dbgprint(level,np,"is up to date");
-     }
-     else {
-        if(np->n_flag & N_ERROR)
-              dbgprint(level,(struct name *)0,"} skipped because of error");
-        else if(np->n_flag & N_EXEC)
-              dbgprint(level,(struct name *)0,"} successfully made");
-        else  dbgprint(level,(struct name *)0,"} is up to date");
-     }
-  }
-  if (level == 0 && !(np->n_flag & N_EXEC))
-     printf("%s: '%s' is up to date\n", myname, np->n_name);
-
-  if(basename)
-     free(basename);
-  return 0;
-}
-
-
-void make1(np, lp, qdp, basename, inputname)
-struct name *np;
-struct line *lp;
-register struct depend *qdp;
-char        *basename;
-char        *inputname;
-{
-  register struct depend *dp;
-  size_t l1, l2;
-
-  if (dotouch)
-    touch(np);
-  else if (!(np->n_flag & N_ERROR)) {
-    strcpy(str1, "");
-
-    if(!inputname) {
-       inputname = str1;  /* default */
-       if (ambigmac) implmacros(np,lp,&basename,&inputname);
-    }
-    setDFmacro("<",inputname);
-
-    if(!basename)
-       basename = str1;
-    setDFmacro("*",basename);
-
-    for (dp = qdp; dp; dp = qdp) {
-       l1= strlen(str1);
-       l2= strlen(dp->d_name->n_name);
-       while (l1 + 1 + l2 +1 > str1s.len)
-       		strrealloc(&str1s);
-       if (strlen(str1))
-          strcat(str1, " ");
-       strcat(str1, dp->d_name->n_name);
-       qdp = dp->d_next;
-       free(dp);
-    }
-    setmacro("?", str1);
-    setDFmacro("@", np->n_name);
-
-    if (lp)		/* lp set if doing a :: rule */
-       docmds1(np, lp);
-    else
-       docmds(np);
-  }
-}
-
-void implmacros(np,lp, pbasename,pinputname)
-struct name *np;
-struct line *lp;
-char        **pbasename;		/*  Name without suffix  */
-char        **pinputname;
-{
-  struct line   *llp;
-  register char *p;
-  register char *q;
-  register char *suff;				/*  Old suffix  */
-  int            baselen;
-  struct depend *dp;
-  bool           dpflag = FALSE;
-
-  /* get basename out of target name */
-  p = str2;
-  q = np->n_name;
-  suff = suffix(q);
-  while ( *q && (q < suff || !suff)) *p++ = *q++;
-  *p = '\0';
-  if ((*pbasename = (char *) malloc(strlen(str2)+1)) == (char *)0 )
-     fatal("No memory for basename",(char *)0,0);
-  strcpy(*pbasename,str2);
-  baselen = strlen(str2);
-
-  if ( lp)
-     llp = lp;
-  else
-     llp = np->n_line;
-
-  while (llp) {
-     for (dp = llp->l_dep; dp; dp = dp->d_next) {
-        if( strncmp(*pbasename,dp->d_name->n_name,baselen) == 0) {
-           *pinputname = dp->d_name->n_name;
-           return;
-        }
-        if( !dpflag) {
-           *pinputname = dp->d_name->n_name;
-           dpflag = TRUE;
-        }
-     }
-     if (lp) break;
-     llp = llp->l_next;
-  }
-
-#if NO_WE_DO_WANT_THIS_BASENAME
-  free(*pbasename);  /* basename ambiguous or no dependency file */
-  *pbasename = (char *)0;
-#endif
-  return;
-}
-
-void dbgprint(level,np,comment)
-int          level;
-struct name *np;
-char        *comment;
-{
-  char *timep;
-
-  if(np) {
-     timep = ctime(&np->n_time);
-     timep[24] = '\0';
-     fputs(&timep[4],stdout);
-  }
-  else fputs("                    ",stdout);
-  fputs("   ",stdout);
-  while(level--) fputs("  ",stdout);
-  if (np) {
-     fputs(np->n_name,stdout);
-     if (np->n_flag & N_DOUBLE) fputs("  :: ",stdout);
-     else                       fputs("  : ",stdout);
-  }
-  fputs(comment,stdout);
-  putchar((int)'\n');
-  fflush(stdout);
-  return;
-}
-
Index: trunk/minix/commands/make/reader.c
===================================================================
--- trunk/minix/commands/make/reader.c	(revision 9)
+++ 	(revision )
@@ -1,134 +1,0 @@
-/*************************************************************************
- *
- *  m a k e :   r e a d e r . c
- *
- *  Read in makefile
- *========================================================================
- * Edition history
- *
- *  #    Date                         Comments                       By
- * --- -------- ---------------------------------------------------- ---
- *   1    ??                                                         ??
- *   2 23.08.89 cast to NULL added                                   RAL
- *   3 30.08.89 indention changed                                    PSH,RAL
- *   4 03.09.89 fixed LZ eliminated                                  RAL
- * ------------ Version 2.0 released ------------------------------- RAL
- *
- *************************************************************************/
-
-#include "h.h"
-
-
-/*
- *	Syntax error handler.  Print message, with line number, and exits.
- */
-void error(msg, a1)
-char *msg;
-char *a1;
-{
-  fprintf(stderr, "%s: ", myname);
-  fprintf(stderr, msg, a1);
-  if (lineno)  fprintf(stderr, " in %s near line %d", makefile, lineno);
-  fputc('\n', stderr);
-  exit(1);
-}
-
-
-/*
- *	Read a line into the supplied string.  Remove
- *	comments, ignore blank lines. Deal with	quoted (\) #, and
- *	quoted newlines.  If EOF return TRUE.
- *
- *	The comment handling code has been changed to leave comments and
- *	backslashes alone in shell commands (lines starting with a tab).
- *	This is not what POSIX wants, but what all makes do.  (KJB)
- */
-bool getline(strs, fd)
-struct str *strs;
-FILE *fd;
-{
-  register char *p;
-  char          *q;
-  int            c;
-
-  for (;;) {
-	strs->pos = 0;
-	for (;;) {
-		do {
-			if (strs->pos >= strs->len)
-				strrealloc(strs);
-			if ((c = getc(fd)) == EOF)
-				return TRUE;		/* EOF */
-			(*strs->ptr)[strs->pos++] = c;
-		} while (c != '\n');
-
-		lineno++;
-
-		if (strs->pos >= 2 && (*strs->ptr)[strs->pos - 2] == '\\') {
-			(*strs->ptr)[strs->pos - 2] = '\n';
-			strs->pos--;
-		} else {
-			break;
-		}
-	}
-
-	if (strs->pos >= strs->len)
-		strrealloc(strs);
-	(*strs->ptr)[strs->pos] = '\0';
-
-	p = q =  *strs->ptr;
-	while (isspace(*q)) q++;
-	if (*p != '\t' || *q == '#') {
-		while (((q = strchr(p, '#')) != (char *)0) &&
-		    (p != q) && (q[-1] == '\\'))
-		{
-			char	*a;
-
-			a = q - 1;	/*  Del \ chr; move rest back  */
-			p = q;
-			while (*a++ = *q++)
-				;
-		}
-		if (q != (char *)0)
-			{
-			q[0] = '\n';
-			q[1] = '\0';
-		}
-	}
-
-	p = *strs->ptr;
-	while (isspace(*p))	/*  Checking for blank  */
-		p++;
-
-	if (*p != '\0')
-		return FALSE;
-  }
-}
-
-
-/*
- *	Get a word from the current line, surounded by white space.
- *	return a pointer to it. String returned has no white spaces
- *	in it.
- */
-char  *gettok(ptr)
-register char **ptr;
-{
-  register char *p;
-
-
-  while (isspace(**ptr))	/*  Skip spaces  */
-	(*ptr)++;
-
-  if (**ptr == '\0')	/*  Nothing after spaces  */
-	return ((char *)NULL);
-
-  p = *ptr;		/*  word starts here  */
-
-  while ((**ptr != '\0') && (!isspace(**ptr)))
-	(*ptr)++;	/*  Find end of word  */
-
-  *(*ptr)++ = '\0';	/*  Terminate it  */
-
-  return(p);
-}
Index: trunk/minix/commands/make/rules.c
===================================================================
--- trunk/minix/commands/make/rules.c	(revision 9)
+++ 	(revision )
@@ -1,314 +1,0 @@
-/*************************************************************************
- *
- *  m a k e :   r u l e s . c
- *
- *  Control of the implicit suffix rules
- *========================================================================
- * Edition history
- *
- *  #    Date                         Comments                       By
- * --- -------- ---------------------------------------------------- ---
- *   1    ??                                                         ??
- *   2 01.07.89 $<,$* bugs fixed, impl. r. ending in expl. r. added  RAL
- *   3 23.08.89 suffix as macro, testname intr., algorithem to find
- *              source dep. made more intelligent (see Readme3)      RAL
- *   4 30.08.89 indention changed                                    PSH,RAL
- *   5 03.09.89 fixed LZ eliminated                                  RAL
- *   6 07.09.89 rules of type '.c', .DEFAULT added, dep. search impr.RAL
- * ------------ Version 2.0 released ------------------------------- RAL
- *
- *************************************************************************/
-
-#include "h.h"
-
-
-/*
- *	Dynamic dependency.  This routine applies the suffis rules
- *	to try and find a source and a set of rules for a missing
- *	target.  If found, np is made into a target with the implicit
- *	source name, and rules.  Returns TRUE if np was made into
- *	a target.
- */
-bool dyndep(np,pbasename,pinputname)
-struct name  *np;
-char        **pbasename;		/*  Name without suffix  */
-char        **pinputname;
-{
-  register char *p;
-  register char *q;
-  register char *suff;				/*  Old suffix  */
-  struct name   *op = (struct name *)0,*optmp;	/*  New dependent  */
-  struct name   *sp;				/*  Suffix  */
-  struct line   *lp,*nlp;
-  struct depend *dp,*ndp;
-  struct cmd    *cmdp;
-  char          *newsuff;
-  bool           depexists = FALSE;
-
-
-  p = str1;
-  q = np->n_name;
-  suff = suffix(q);
-  while (*q && (q < suff || !suff)) *p++ = *q++;
-  *p = '\0';
-  if ((*pbasename = (char *) malloc(strlen(str1)+1)) == (char *)0 )
-     fatal("No memory for basename",(char *)0,0);
-  strcpy(*pbasename,str1);
-  if ( !suff) suff = p - str1 + *pbasename;  /* set suffix to nullstring */
-
-  if (!((sp = newname(".SUFFIXES"))->n_flag & N_TARG))  return FALSE;
-
-  /* search all .SUFFIXES lines */
-  for (lp = sp->n_line; lp; lp = lp->l_next)
-     /* try all suffixes */
-     for (dp = lp->l_dep; dp; dp = dp->d_next) {
-        /* compose implicit rule name (.c.o)...*/
-        newsuff = dp->d_name->n_name;
-        while (strlen(suff)+strlen(newsuff)+1 >= str1s.len) strrealloc(&str1s);
-        p = str1;
-        q = newsuff;
-        while (*p++ = *q++) ;
-        p--;
-        q = suff;
-        while (*p++ = *q++) ;
-        /* look if the rule exists */
-        sp = newname(str1);
-        if (sp->n_flag & N_TARG) {
-           /* compose resulting dependency name */
-           while (strlen(*pbasename) + strlen(newsuff)+1 >= str1s.len)
-              strrealloc(&str1s);
-           q = *pbasename;
-           p = str1;
-           while (*p++ = *q++) ;
-           p--;
-           q = newsuff;
-           while (*p++ = *q++) ;
-           /* test if dependency file or an explicit rule exists */
-           if ((optmp= testname(str1)) != (struct name *)0) {
-              /* store first possible dependency as default */
-              if ( op == (struct name *)0) {
-                 op = optmp;
-                 cmdp = sp->n_line->l_cmd;
-              }
-              /* check if testname is an explicit dependency */
-              for ( nlp=np->n_line; nlp; nlp=nlp->l_next) {
-                 for( ndp=nlp->l_dep; ndp; ndp=ndp->d_next) {
-                    if ( strcmp( ndp->d_name->n_name, str1) == 0) {
-                       op = optmp;
-                       cmdp = sp->n_line->l_cmd;
-                       ndp = (struct depend *) 0;
-                       goto found2;
-                    }
-                    depexists = TRUE;
-                 }
-              }
-              /* if no explicit dependencies : accept testname */
-              if (!depexists)  goto found;
-           }
-        }
-     }
-
-  if ( op == (struct name *)0) {
-     if( np->n_flag & N_TARG) {     /* DEFAULT handling */
-        if (!((sp = newname(".DEFAULT"))->n_flag & N_TARG))  return FALSE;
-        if (!(sp->n_line)) return FALSE;
-        cmdp = sp->n_line->l_cmd;
-        for ( nlp=np->n_line; nlp; nlp=nlp->l_next) {
-           if ( ndp=nlp->l_dep) {
-              op = ndp->d_name;
-              ndp = (struct depend *)0;
-              goto found2;
-           }
-        }
-        newline(np, (struct depend *)0, cmdp, 0);
-        *pinputname = (char *)0;
-        *pbasename  = (char *)0;
-        return TRUE;
-     }
-  else return FALSE;
-  }
-
-found:
-  ndp = newdep(op, (struct depend *)0);
-found2:
-  newline(np, ndp, cmdp, 0);
-  *pinputname = op->n_name;
-  return TRUE;
-}
-
-
-/*
- *	Make the default rules
- */
-void makerules()
-{
-  struct cmd    *cp;
-  struct name   *np;
-  struct depend *dp;
-
-
-#ifdef eon
-  setmacro("BDSCC", "asm");
-  /*	setmacro("BDSCFLAGS", "");	*/
-  cp = newcmd("$(BDSCC) $(BDSCFLAGS) -n $<", (struct cmd *)0);
-  np = newname(".c.o");
-  newline(np, (struct depend *)0, cp, 0);
-
-  setmacro("CC", "c");
-  setmacro("CFLAGS", "-O");
-  cp = newcmd("$(CC) $(CFLAGS) -c $<", (struct cmd *)0);
-  np = newname(".c.obj");
-  newline(np, (struct depend *)0, cp, 0);
-
-  setmacro("M80", "asm -n");
-  /*	setmacro("M80FLAGS", "");	*/
-  cp = newcmd("$(M80) $(M80FLAGS) $<", (struct cmd *)0);
-  np = newname(".mac.o");
-  newline(np, (struct depend *)0, cp, 0);
-
-  setmacro("AS", "zas");
-  /*	setmacro("ASFLAGS", "");	*/
-  cp = newcmd("$(ZAS) $(ASFLAGS) -o $@ $<", (struct cmd *)0);
-  np = newname(".as.obj");
-  newline(np, (struct depend *)0, cp, 0);
-
-  np = newname(".as");
-  dp = newdep(np, (struct depend *)0);
-  np = newname(".obj");
-  dp = newdep(np, dp);
-  np = newname(".c");
-  dp = newdep(np, dp);
-  np = newname(".o");
-  dp = newdep(np, dp);
-  np = newname(".mac");
-  dp = newdep(np, dp);
-  np = newname(".SUFFIXES");
-  newline(np, dp, (struct cmd *)0, 0);
-#endif
-
-#ifdef tos
-#define unix
-#endif
-
-/*
- *	Some of the UNIX implicit rules
- */
-
-#ifdef unix
-
-  setmacro("CC", "cc");
-  setmacro("CFLAGS", "");
-
-  cp = newcmd("$(CC) -S $(CFLAGS) $<", (struct cmd *)0);
-  np = newname(".c.s");
-  newline(np, (struct depend *)0, cp, 0);
-
-  cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *)0);
-  np = newname(".c.o");
-  newline(np, (struct depend *)0, cp, 0);
-
-#if this_rule_is_a_bit_too_much_of_a_good_thing
-#ifdef MINIXPC
-  cp = newcmd("$(CC) $(CFLAGS) -i -o $@ $<", (struct cmd *)0);
-#else
-  cp = newcmd("$(CC) $(CFLAGS) -o $@ $<", (struct cmd *)0);
-#endif /* MINIXPC */
-  np = newname(".c");
-  newline(np, (struct depend *)0, cp, 0);
-#endif
-
-  cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *)0);
-  np = newname(".s.o");
-  newline(np, (struct depend *)0, cp, 0);
-
-  setmacro("YACC", "yacc");
-  /*setmacro("YFLAGS", "");	*/
-  cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
-  cp = newcmd("mv y.tab.c $@", cp);
-  np = newname(".y.c");
-  newline(np, (struct depend *)0, cp, 0);
-
-  cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
-  cp = newcmd("$(CC) $(CFLAGS) -c y.tab.c", cp);
-  cp = newcmd("mv y.tab.o $@", cp);
-  np = newname(".y.o");
-  cp = newcmd("rm y.tab.c", cp);
-  newline(np, (struct depend *)0, cp, 0);
-
-  setmacro("FLEX", "flex");
-  cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
-  cp = newcmd("mv lex.yy.c $@", cp);
-  np = newname(".l.c");
-  newline(np, (struct depend *)0, cp, 0);
-
-  cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
-  cp = newcmd("$(CC) $(CFLAGS) -c lex.yy.c", cp);
-  cp = newcmd("mv lex.yy.o $@", cp);
-  np = newname(".l.o");
-  cp = newcmd("rm lex.yy.c", cp);
-  newline(np, (struct depend *)0, cp, 0);
-
-  np = newname(".o");
-  dp = newdep(np, (struct depend *)0);
-  np = newname(".s");
-  dp = newdep(np, dp);
-  np = newname(".c");
-  dp = newdep(np, dp);
-  np = newname(".y");
-  dp = newdep(np, dp);
-  np = newname(".l");
-  dp = newdep(np, dp);
-  np = newname(".SUFFIXES");
-  newline(np, dp, (struct cmd *)0, 0);
-
-#endif /* unix */
-
-
-#ifdef os9
-/*
- *	Fairlight use an enhanced version of the C sub-system.
- *	They have a specialised macro pre-processor.
- */
-  setmacro("CC", "cc");
-  setmacro("CFLAGS", "-z");
-  cp = newcmd("$(CC) $(CFLAGS) -r $<", (struct cmd *)0);
-
-  np = newname(".c.r");
-  newline(np, (struct depend *)0, cp, 0);
-  np = newname(".ca.r");
-  newline(np, (struct depend *)0, cp, 0);
-  np = newname(".a.r");
-  newline(np, (struct depend *)0, cp, 0);
-  np = newname(".o.r");
-  newline(np, (struct depend *)0, cp, 0);
-  np = newname(".mc.r");
-  newline(np, (struct depend *)0, cp, 0);
-  np = newname(".mca.r");
-  newline(np, (struct depend *)0, cp, 0);
-  np = newname(".ma.r");
-  newline(np, (struct depend *)0, cp, 0);
-  np = newname(".mo.r");
-  newline(np, (struct depend *)0, cp, 0);
-
-  np = newname(".r");
-  dp = newdep(np, (struct depend *)0);
-  np = newname(".mc");
-  dp = newdep(np, dp);
-  np = newname(".mca");
-  dp = newdep(np, dp);
-  np = newname(".c");
-  dp = newdep(np, dp);
-  np = newname(".ca");
-  dp = newdep(np, dp);
-  np = newname(".ma");
-  dp = newdep(np, dp);
-  np = newname(".mo");
-  dp = newdep(np, dp);
-  np = newname(".o");
-  dp = newdep(np, dp);
-  np = newname(".a");
-  dp = newdep(np, dp);
-  np = newname(".SUFFIXES");
-  newline(np, dp, (struct cmd *)0, 0);
-#endif
-}
Index: trunk/minix/commands/mdb/Dist
===================================================================
--- trunk/minix/commands/mdb/Dist	(revision 9)
+++ 	(revision )
@@ -1,38 +1,0 @@
-Mdb (Minix debugger) Distribution
-=================================
-
-Version: 	2.6.0
-Date:		Sept 9/96
-Author:		Philip Murton
-E-mail:		philip.murton@utoronto.ca
-
-
-Files included: 
-===============
-
-Dist		This file
-Makefile	Makefile 
-MDB.TXT		Cover file
-README		README file 
-a.out.h		GNU a.out.h (copied to /usr/include/gnu)
-core.c		core file functions
-decode.c	Optional for syscalls support
-gnu_load.c	Optional for GNU EXEC support
-io.c		I/O done here
-ioctl.c		Optional for syscalls support
-kernel.c	kernel functions
-log		Log from sample command file (See README)
-mdb.c		main program
-mdb.h		main header
-mdb.1		man page
-mdbdis86.c	Disassembler 
-mdbexp.c	Expression parsing
-misc.c		misc functions including help
-gnu_sym.c	Optional for GNU EXEC support
-proto.h		Prototypes 
-ptrace.2	man page
-sample		sample command file
-sym.c		Symbolic names read from exec file
-syscalls.c	Optional for syscalls support
-trace.c		ptrace() called here
-
Index: trunk/minix/commands/mdb/MDB.TXT
===================================================================
--- trunk/minix/commands/mdb/MDB.TXT	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-INFORMATION on mdb version 2.6.0 (Sept 9/96).
-   
-MDB is the MINIX debugger which allows you to place breakpoints and
-control the execution of a program. It has a lot of the features that
-you would expect in a program debugger; for example, stack traces and
-single step execution.
-
-The current version works with MINIX for PC and was developed and tested
-under MINIX 1.7.x (32 bit version). It should work with 16 bit MINIX. 
-
-How to Install
-
-1) Unpack mdb.tar.Z and review additional information in the README file.
-   (If you got this from the Minix CD-ROM or an MS-DOS system rename 
-   MDB.TAZ to mdb.tar.Z)   
-2) Edit Makefile for Compiler and extra options as required.
-3) make 
-4) make install
-5) make install_man
-
-Comments to:
-
-Philip Murton. 
-philip.murton@utoronto.ca
-
Index: trunk/minix/commands/mdb/Makefile
===================================================================
--- trunk/minix/commands/mdb/Makefile	(revision 9)
+++ 	(revision )
@@ -1,129 +1,0 @@
-#
-# Makefile for mdb
-#
-#
-# Edit as indicated below.
-#
-USR		=/usr
-#
-# (1) For Compiler and target system:
-#
-#
-# For ANSI C and Minix 1.7.x 32-bit 
-#
-CC		=exec cc 
-LD		=exec cc
-LDFLAGS		=-i
-TARGET		=mdb
-STACK		=200000
-#
-# (2) If kernel and mm are not in "/usr/src" change this
-#
-SYSTEM	=$(USR)/src
-#
-# (3) Select Options
-# 
-# i)   For GNU_EXEC Support, uncomment:
-#
-#FOR_GNU		=gnu_sym.o gnu_load.o
-#DEF_GNU		=-DGNU_SUPPORT
-# 
-# ii)  For tracing of syscalls, uncomment:
-#
-#FOR_SYSCALLS 	=syscalls.o decode.o ioctl.o
-#DEF_SYSCALLS	=-DSYSCALLS_SUPPORT
-#
-# iii) For no debugging of mdb, uncomment:
-#
-#DEF_DEBUG	=-DNDEBUG
-
-EXTRA_OBJS	=$(FOR_GNU) $(FOR_SYSCALLS)
-EXTRA_DEFS	=$(DEF_GNU) $(DEF_SYSCALLS) $(DEF_DEBUG)
-
-all:	$(TARGET)
-
-CFLAGS	=-I$(SYSTEM) -I$(SYSTEM)/servers -I$(INCLUDE) -D_MINIX -D_POSIX_SOURCE $(EXTRA_DEFS)
-
-# For various included files or system files
-# 
-INCLUDE		=$(USR)/include
-KERNEL		=$(SYSTEM)/kernel
-PTRACE		=$(INCLUDE)/sys/ptrace.h
-
-
-# Header files from pm (used by core.c) 
-#
-MMFILES=	$(SYSTEM)/servers/pm/const.h \
-		$(SYSTEM)/servers/pm/type.h \
-		$(SYSTEM)/servers/pm/mproc.h
-
-# Header files from system and kernel in "mdb.h" 
-#
-SYSFILES=	$(INCLUDE)/minix/config.h \
-		$(INCLUDE)/minix/const.h \
-		$(INCLUDE)/ansi.h \
-		$(INCLUDE)/minix/type.h \
-		$(INCLUDE)/limits.h \
-		$(INCLUDE)/errno.h \
-		$(INCLUDE)/sys/types.h \
-		$(KERNEL)/const.h \
-		$(KERNEL)/type.h \
-		$(KERNEL)/proc.h
-
-# Common objects 
-#
-OBJCOMMON	=mdb.o mdbexp.o kernel.o sym.o trace.o core.o misc.o io.o
-
-# Common source
-#
-SRCCOMMON	=mdb.c mdbexp.c kernel.o sym.c trace.c core.c misc.c io.c
-
-# Object files for PC
-#
-OBJPC		=$(OBJCOMMON) mdbdis86.o 
-
-# Source file
-#
-SRCPC		=$(SRCCOMMON) mdbdis86.c
-
-
-mdb:	$(OBJPC) $(EXTRA_OBJS)
-	$(LD) $(LDFLAGS) -o mdb $(OBJPC) $(EXTRA_OBJS)
-	install -S $(STACK) mdb
-
-#
-# Dependencies for objects
-#
-mdb.o:		mdb.c mdb.h $(SYSFILES) proto.h
-mdbdis86.o:	mdbdis86.c mdb.h $(SYSFILES) proto.h
-mdbexp.o:	mdbexp.c mdb.h $(SYSFILES) proto.h
-sym.o:		sym.c mdb.h $(SYSFILES) proto.h
-trace.o:	trace.c mdb.h $(PTRACE) $(SYSFILES) proto.h
-core.o:		core.c mdb.h $(MMFILES) $(SYSFILES) proto.h
-misc.o:		misc.c mdb.h  $(SYSFILES) proto.h
-io.o:		io.c mdb.h $(SYSFILES) proto.h
-
-syscalls.o:	syscalls.c mdb.h $(SYSFILES) proto.h
-decode.o:	decode.c mdb.h $(INCLUDE)/minix/callnr.h $(SYSFILES) proto.h
-ioctl.o:	ioctl.c mdb.h  $(SYSFILES) proto.h
-
-gnu_sym.o:	gnu_sym.c mdb.h $(INCLUDE)/gnu/a.out.h $(SYSFILES) proto.h
-gnu_load.o:	gnu_load.c $(INCLUDE)/gnu/a.out.h $(SYSFILES) proto.h
-
-$(INCLUDE)/gnu/a.out.h:	a.out.h
-		install -c -o bin a.out.h $(INCLUDE)/gnu
-
-
-#
-# install
-#
-
-install:	mdb 
-		install -cs -o bin mdb /usr/bin
-
-install_man:	mdb.1 ptrace.2
-		install -c -o bin mdb.1 /usr/man/man1
-		install -c -o bin ptrace.2 /usr/man/man2
-clean:
-		rm -f *.o mdb
-
Index: trunk/minix/commands/mdb/README
===================================================================
--- trunk/minix/commands/mdb/README	(revision 9)
+++ 	(revision )
@@ -1,32 +1,0 @@
-README for mdb version 2.6.0
-
-Sept 9/96
-
-Please note the following: 
-
-1) Has been tested with Minix 1.7.4 (32-bit version).
-   A previous version was tested with Minix 1.7.x (16 bit version).
-   Some optional parts of mdb have not been extensively tested. 
-   This is especially true on the code to trace system calls.
-   See options in Makefile.
-
-2) I know that the commands are somewhat cryptic; thus  
-   there are currently two types of 'help' for mdb
-   a) the "?" gives a help page. 
-   b) typing "command ?" will give help on a specific command. 
-
-3) The sample comand file and log output. 
-   To test this, type something like the following 
-   "mdb -llog.new /usr/bin/sleep @sample"
-   The output "log.new' should be similar to the distributed "log" file;
-   but not necessarily exactly the same.
-
-4) Man pages need some more work.
-
-5) See top part of mdb.c for version history.
-
-Send comments to Philip Murton. Thanks. 
-
-philip.murton@utoronto.ca
-
-
Index: trunk/minix/commands/mdb/a.out.h
===================================================================
--- trunk/minix/commands/mdb/a.out.h	(revision 9)
+++ 	(revision )
@@ -1,299 +1,0 @@
-/* 
- * MINIX 1.7.x
- * GNU version based on Linux 1.1.45 version
- * if _MINIX_EXEC defined use old MINIX GNU format
- */
-
-#ifndef __A_OUT_GNU_H__
-#define __A_OUT_GNU_H__
-
-#define __GNU_EXEC_MACROS__
-
-#ifndef __STRUCT_EXEC_OVERRIDE__
-
-struct exec
-{
-  unsigned long a_info;		/* Use macros N_MAGIC, etc for access */
-  unsigned a_text;		/* length of text, in bytes */
-  unsigned a_data;		/* length of data, in bytes */
-  unsigned a_bss;		/* length of uninitialized data area for file, in bytes */
-  unsigned a_syms;		/* length of symbol table data in file, in bytes */
-  unsigned a_entry;		/* start address */
-  unsigned a_trsize;		/* length of relocation info for text, in bytes */
-  unsigned a_drsize;		/* length of relocation info for data, in bytes */
-#ifdef	_MINIX_EXEC
-  unsigned a_smagic;		/* SMAGIC */
-  unsigned a_memsize;		/* Dynamic Memory Size */
-#endif
-};
-
-#ifdef	_MINIX_EXEC
-#define GNU_SMAGIC	0xdeadbabe
-#define GNU_DYNMEM	(64 * 1024)
-#else
-#define GNU_STACK	64	/* Default Stack */
-#endif
-
-#endif /* __STRUCT_EXEC_OVERRIDE__ */
-
-/* these go in the N_MACHTYPE field */
-enum machine_type {
-#if defined (M_OLDSUN2)
-  M__OLDSUN2 = M_OLDSUN2,
-#else
-  M_OLDSUN2 = 0,
-#endif
-#if defined (M_68010)
-  M__68010 = M_68010,
-#else
-  M_68010 = 1,
-#endif
-#if defined (M_68020)
-  M__68020 = M_68020,
-#else
-  M_68020 = 2,
-#endif
-#if defined (M_SPARC)
-  M__SPARC = M_SPARC,
-#else
-  M_SPARC = 3,
-#endif
-  /* skip a bunch so we don't run into any of sun's numbers */
-  M_386 = 100
-};
-
-#if !defined (N_MAGIC)
-#define N_MAGIC(exec) ((exec).a_info & 0xffff)
-#endif
-#define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
-#define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
-#define N_SET_INFO(exec, magic, type, flags) \
-	((exec).a_info = ((magic) & 0xffff) \
-	 | (((int)(type) & 0xff) << 16) \
-	 | (((flags) & 0xff) << 24))
-#define N_SET_MAGIC(exec, magic) \
-	((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
-
-#define N_SET_MACHTYPE(exec, machtype) \
-	((exec).a_info = \
-	 ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
-
-#define N_SET_FLAGS(exec, flags) \
-	((exec).a_info = \
-	 ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
-
-#ifdef	_MINIX
-#define N_SET_MEMORY(exec, mem) \
-	((exec).a_info = \
-	 ((exec).a_info & 0x0000FFFF) | (((mem) & 0xFFFF) << 16))
-#define N_MEMORY(exec) (((exec).a_info >> 16) & 0xFFFF)
-#endif
-
-/* Code indicating object file or impure executable.  */
-#define OMAGIC 0407
-/* Code indicating pure executable.  */
-#define NMAGIC 0410
-/* Code indicating demand-paged executable.  */
-#define ZMAGIC 0413
-/* This indicates a demand-paged executable with the header in the text. 
-   The first page is unmapped to help trap NULL pointer references */
-#define QMAGIC 0314
-
-/* Code indicating core file.  */
-#define CMAGIC 0421
-
-#if !defined (N_BADMAG)
-#define N_BADMAG(x)	  (N_MAGIC(x) != OMAGIC		\
-			&& N_MAGIC(x) != NMAGIC		\
-  			&& N_MAGIC(x) != ZMAGIC \
-		        && N_MAGIC(x) != QMAGIC)
-#endif
-
-#define _N_HDROFF(x) (1024 - sizeof (struct exec))
-
-#if !defined (N_TXTOFF)
-#define N_TXTOFF(x) \
- (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \
-  (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
-#endif
-
-#if !defined (N_DATOFF)
-#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
-#endif
-
-#if !defined (N_TRELOFF)
-#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
-#endif
-
-#if !defined (N_DRELOFF)
-#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
-#endif
-
-#if !defined (N_SYMOFF)
-#define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
-#endif
-
-#if !defined (N_STROFF)
-#define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
-#endif
-
-/* Address of text segment in memory after it is loaded.  */
-#if !defined (N_TXTADDR)
-#define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? PAGE_SIZE : 0)
-#endif
-
-/* Address of data segment in memory after it is loaded.
-   Note that it is up to you to define SEGMENT_SIZE
-   on machines not listed here.  */
-#if defined(vax) || defined(hp300) || defined(pyr)
-#define SEGMENT_SIZE page_size
-#endif
-#ifdef	sony
-#define	SEGMENT_SIZE	0x2000
-#endif	/* Sony.  */
-#ifdef is68k
-#define SEGMENT_SIZE 0x20000
-#endif
-#if defined(m68k) && defined(PORTAR)
-#define PAGE_SIZE 0x400
-#define SEGMENT_SIZE PAGE_SIZE
-#endif
-
-#ifndef PAGE_SIZE
-#define PAGE_SIZE	1024
-#endif
-
-#ifndef SEGMENT_SIZE
-#define SEGMENT_SIZE	PAGE_SIZE
-#endif
-
-#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
-
-#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
-
-#ifndef N_DATADDR
-#define N_DATADDR(x) \
-    (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
-     : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
-#endif
-
-/* Address of bss segment in memory after it is loaded.  */
-#if !defined (N_BSSADDR)
-#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
-#endif
-
-
-#if !defined (N_NLIST_DECLARED)
-struct nlist {
-  union {
-    char *n_name;
-    struct nlist *n_next;
-    long n_strx;
-  } n_un;
-  unsigned char n_type;
-  char n_other;
-  short n_desc;
-  unsigned long n_value;
-};
-#endif /* no N_NLIST_DECLARED.  */
-
-#if !defined (N_UNDF)
-#define N_UNDF 0
-#endif
-#if !defined (N_ABS)
-#define N_ABS 2
-#endif
-#if !defined (N_TEXT)
-#define N_TEXT 4
-#endif
-#if !defined (N_DATA)
-#define N_DATA 6
-#endif
-#if !defined (N_BSS)
-#define N_BSS 8
-#endif
-#if !defined (N_FN)
-#define N_FN 15
-#endif
-
-#if !defined (N_EXT)
-#define N_EXT 1
-#endif
-#if !defined (N_TYPE)
-#define N_TYPE 036
-#endif
-#if !defined (N_STAB)
-#define N_STAB 0340
-#endif
-
-/* The following type indicates the definition of a symbol as being
-   an indirect reference to another symbol.  The other symbol
-   appears as an undefined reference, immediately following this symbol.
-
-   Indirection is asymmetrical.  The other symbol's value will be used
-   to satisfy requests for the indirect symbol, but not vice versa.
-   If the other symbol does not have a definition, libraries will
-   be searched to find a definition.  */
-#define N_INDR 0xa
-
-/* The following symbols refer to set elements.
-   All the N_SET[ATDB] symbols with the same name form one set.
-   Space is allocated for the set in the text section, and each set
-   element's value is stored into one word of the space.
-   The first word of the space is the length of the set (number of elements).
-
-   The address of the set is made into an N_SETV symbol
-   whose name is the same as the name of the set.
-   This symbol acts like a N_DATA global symbol
-   in that it can satisfy undefined external references.  */
-
-/* These appear as input to LD, in a .o file.  */
-#define	N_SETA	0x14		/* Absolute set element symbol */
-#define	N_SETT	0x16		/* Text set element symbol */
-#define	N_SETD	0x18		/* Data set element symbol */
-#define	N_SETB	0x1A		/* Bss set element symbol */
-
-/* This is output from LD.  */
-#define N_SETV	0x1C		/* Pointer to set vector in data area.  */
-
-
-#if !defined (N_RELOCATION_INFO_DECLARED)
-/* This structure describes a single relocation to be performed.
-   The text-relocation section of the file is a vector of these structures,
-   all of which apply to the text section.
-   Likewise, the data-relocation section applies to the data section.  */
-
-struct relocation_info
-{
-  /* Address (within segment) to be relocated.  */
-  int r_address;
-  /* The meaning of r_symbolnum depends on r_extern.  */
-  unsigned int r_symbolnum:24;
-  /* Nonzero means value is a pc-relative offset
-     and it should be relocated for changes in its own address
-     as well as for changes in the symbol or section specified.  */
-  unsigned int r_pcrel:1;
-  /* Length (as exponent of 2) of the field to be relocated.
-     Thus, a value of 2 indicates 1<<2 bytes.  */
-  unsigned int r_length:2;
-  /* 1 => relocate with value of symbol.
-          r_symbolnum is the index of the symbol
-	  in file's the symbol table.
-     0 => relocate with the address of a segment.
-          r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
-	  (the N_EXT bit may be set also, but signifies nothing).  */
-  unsigned int r_extern:1;
-  /* Four bits that aren't used, but when writing an object file
-     it is desirable to clear them.  */
-#ifdef NS32K
-  unsigned r_bsr:1;
-  unsigned r_disp:1;
-  unsigned r_pad:2;
-#else
-  unsigned int r_pad:4;
-#endif
-};
-#endif /* no N_RELOCATION_INFO_DECLARED.  */
-
-
-#endif /* __A_OUT_GNU_H__ */
Index: trunk/minix/commands/mdb/build
===================================================================
--- trunk/minix/commands/mdb/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/mdb/core.c
===================================================================
--- trunk/minix/commands/mdb/core.c	(revision 9)
+++ 	(revision )
@@ -1,394 +1,0 @@
-/* 
- * core.c for mdb
- *
- * reads information from 'core' file
- * Partly derived from 'adb' by D. Dugger.
- */
-#include <pm/const.h>
-
-#include "mdb.h"
-
-#include <signal.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/ptrace.h>
-
-#include <pm/type.h>
-#include <pm/mproc.h>
-
-#include <kernel/const.h>
-#include <kernel/type.h>
-#include <kernel/proc.h>
-
-/* defined in kernel.c */
-extern struct proc *prc; 
-
-#include "proto.h"
-
-#define BSIZE  512
-#define LOGBS  9
-
-PRIVATE struct file {
-  int fid;
-  char *name;
-  long cblock;
-  long tmap[3];
-  long dmap[3];
-  long smap[3];
-  char buf[BSIZE + BSIZE];
-} Core_File, *core_file;
-
-#define b1	tmap[0]
-#define e1	tmap[1]
-#define f1	tmap[2]
-#define b2	dmap[0]
-#define e2	dmap[1]
-#define f2	dmap[2]
-#define b3	smap[0]
-#define e3	smap[1]
-#define f3	smap[2]
-
-PRIVATE long cnt[3];			/* Sizes of segments   */
-PRIVATE int h_size;			/* Size of core header */
-PRIVATE char def_name[] = "core";	/* Default core name   */
-
-#define SIZE_MP_SEG (sizeof(struct mem_map) * NR_LOCAL_SEGS)
-#define SIZE_KINFO sizeof(struct proc)
-#define SIZE_HEADER SIZE_MP_SEG
-
-FORWARD _PROTOTYPE( int kernel_info , (int fd ));
-FORWARD _PROTOTYPE( void setmap , (struct file *fp ));
-FORWARD _PROTOTYPE( void read_info , (struct file *fp ));
-FORWARD _PROTOTYPE( void ill_addr , (long d , int segment ));
-FORWARD _PROTOTYPE( long map_addr , (long d , int segment ));
-FORWARD _PROTOTYPE( unsigned long c_status, (void));
-FORWARD _PROTOTYPE( long getn, (long d, int s) );
-
-/* 
- * set and display mapping for core file 
- */
-PRIVATE void setmap(fp)
-struct file *fp;
-{
-long h = (long) h_size;
-
-  fp->b1 = st_addr;
-  fp->e1 = st_addr + cnt[T];
-  fp->f1 = h;
-
-  fp->b2 = sd_addr; 
-  fp->e2 = sd_addr + cnt[D];
-  fp->f2 = cnt[T] + h;
-
-  fp->b3 = sk_addr;
-  fp->e3 = sk_addr + cnt[S];
-  fp->f3 = cnt[T] + cnt[D] + h;
-
-#ifdef MINIX_PC
-  if(is_separate) {
-	if ( end_addr < et_addr ) end_addr = et_addr;
-  }
-  else {
-	fp->b2 = st_addr;
-	fp->e2 = st_addr + cnt[T] + cnt[D];
-	fp->f2 = h;
-	end_addr = fp->e2;
-
-	fp->b1 = 0;
-	fp->e1 = -1;
-	fp->f1 = 0;
-  }
-#endif
-  Printf("From core file:\n");
-  Printf("T\t%8lx %8lx %8lx\n", core_file->b1, core_file->e1, core_file->f1);
-  Printf("D\t%8lx %8lx %8lx\n", core_file->b2, core_file->e2, core_file->f2);
-  Printf("S\t%8lx %8lx %8lx\n", core_file->b3, core_file->e3, core_file->f3);
-  Printf("\n");
-
-}
-
-/* Print mapping */
-PUBLIC void prtmap()
-{
-  Printf("%s I & D space\t", (is_separate) ? "Separate " : "Combined ");
-  if (corepid > 0) {
-	Printf("File: %s\n\n", core_file->name);
-	setmap(core_file);
-	disp_maps();
-  }
-  else {
-	Printf("Pid:  %d\n\n", curpid);
-	update();
-	disp_maps();
-  }
-}
-
-/* Illegal address */
-PRIVATE void ill_addr(d, segment)
-long d;
-int segment;
-{
-  Printf("Bad addr=%lx seg=%d",d,segment);
-  mdb_error("\n");
-}
-
-/* Map virtual address -> core file addresses
- * depends on current segment if Separate I & D
- */
-PRIVATE long map_addr(d, segment)
-long d;
-int segment;
-{
-#ifdef MINIX_PC
-  if (is_separate) 
-	switch (segment) {
-	    case T:
-		if (d >= core_file->b1 && d < core_file->e1)
-			d += core_file->f1 - core_file->b1;
-		else
-			ill_addr(d,segment);
-		break;
-	    case D:
-	    case S:
-		if (d >= core_file->b2 && d < core_file->e2)
-			d += core_file->f2 - core_file->b2;
-		else if (d >= core_file->b3 && d < core_file->e3)
-			d += core_file->f3 - core_file->b3;
-		else
-			ill_addr(d,segment);
-		break;
-	}
-  else {
-#endif
-	if (d >= core_file->b1 && d < core_file->e1)
-		d += core_file->f1 - core_file->b1;
-	else if (d >= core_file->b2 && d < core_file->e2)
-		d += core_file->f2 - core_file->b2;
-	else if (d >= core_file->b3 && d < core_file->e3)
-		d += core_file->f3 - core_file->b3;
-	else
-		ill_addr(d,segment);
-#ifdef	MINIX_PC
-  }
-#endif
-  return d;
-}
-
-
-/* Get value with address d and segment s */
-PRIVATE long getn(d, s)
-long d;
-int s;
-{
-  long b;
-  register int o,i;
-  union {
-	unsigned long l;
-	unsigned char c[4];
-  } data;
-
-  /* Map address */
-  d = map_addr(d, s);
-
-  b = d >> LOGBS;
-  o = d & (BSIZE - 1);
-
-  if (core_file->cblock != b) {
-	core_file->cblock = b;
-	lseek(core_file->fid, b << LOGBS, 0);
-	read(core_file->fid, core_file->buf, sizeof(core_file->buf));
-  }
-
-  for(i = 0; i<4; i++) 
-	data.c[i] = core_file->buf[o+i];
-
-#ifdef DEBUG
-  if (debug) 
-	Printf("getn at %8lx val %8lx\n", d, data.l);
-#endif
-  return data.l;
-}
-
-/* Read kernel info from core file into lbuf[] */
-PRIVATE int kernel_info(fd)
-int fd;
-{
-  int r;
-  int ks;
-
-  /* Round SIZE_KINFO to multiple of sizeof(long) */
-  /* See mm/signal.c to see how a 'core' file is written */
-  ks = ( SIZE_KINFO / sizeof(long) ) * sizeof(long);  	
-  r = read(fd, (char *)lbuf, ks);
-  return(r == ks) ? ks : -1;
-}
-
-/* 
- * Print status info from core  - returns PC
- */
-PRIVATE unsigned long c_status()
-{
-  fprintf(stderr, "WARNING: don't know pid from core; using proc nr for pid.\n");
-
-  Printf("Proc = %6d\n", prc->p_nr);
-
-  /* Set current pid to that of core */
-  curpid = corepid = prc->p_nr;
-  disp_maps();
-  Printf("\nPC  = 0x%0*lx\t", 2 * ADDRSIZE, PC_MEMBER(prc) & MASK(ADDRSIZE));
-  symbolic((long) PC_MEMBER(prc), '\n');
-  dasm((long) PC_MEMBER(prc), 1, 1);
-  return PC_MEMBER(prc);
-}
-
-/* Read memory maps and kernel info from core file */
-PRIVATE void read_info(fp)
-struct file *fp;
-{
-  struct mproc mm_info;
-  struct mproc *rmp;
-  int r;
-  int i;
-
-  rmp = &mm_info;
-  lseek(fp->fid, 0L, 0L);
-
-  /* First read memory map of all segments. */
-  if (read(fp->fid, (char *) rmp->mp_seg, (int) SIZE_MP_SEG) < 0) {
-	close(fp->fid);
-	Printf("mdb: cannot read core header\n");
-	fp->fid = -1;
-	return; 
-  }
-  h_size = SIZE_HEADER;
-
-  /* Read kernel dependent info */
-  r = kernel_info(fp->fid);
-  if (r < 0) {
-	close(fp->fid);
-	Printf("mdb: cannot read kernel info from 'core' file\n");
-	fp->fid = -1;
-	return;
-  } else
-	h_size += r;
-
-  /* copy info */ 	
-  for (i = T; i <= S; i++)
-	cnt[i] = (long) rmp->mp_seg[i].mem_len << CLICK_SHIFT;
-
-  /* This needs to be set for map_addr() below */
-  if(coreonly && cnt[T] != 0) is_separate = TRUE;
-
-  st_addr = (long) rmp->mp_seg[T].mem_vir << CLICK_SHIFT;
-  et_addr = st_addr + ((long) rmp->mp_seg[T].mem_len << CLICK_SHIFT);
-
-  sd_addr = (long) rmp->mp_seg[D].mem_vir << CLICK_SHIFT;
-  end_addr = ed_addr = 
-	sd_addr + ((long) rmp->mp_seg[D].mem_len << CLICK_SHIFT);
-
-  sk_addr = (long) rmp->mp_seg[S].mem_vir << CLICK_SHIFT;
-  sk_size = (long) rmp->mp_seg[S].mem_len << CLICK_SHIFT;
-
-  setmap(fp);
-}
-
-/* initialization for core files 
- * returns PC address from core file 
- */ 
-PUBLIC unsigned long core_init(filename)
-char *filename;
-{
-  core_file = &Core_File;
-  core_file->name = (filename != NULL) ? filename : def_name;
-
-  core_file->fid = open(core_file->name, 0);
-  if (filename != NULL && core_file->fid < 0) {
-	Printf("mdb - warning cannot open: %s\n", core_file->name);
-	return -1;
-  }
-
-  core_file->b1 = core_file->b2 = core_file->b3 = 0;
-  core_file->e1 = core_file->e2 = core_file->e3 = -1;
-  core_file->f1 = core_file->f2 = core_file->f3 = 0;
-  core_file->cblock = -1;
-
-  if (core_file->fid > 0) {
-	read_info(core_file);
-	return c_status();
-  }
-  return 0;
-}
-
-
-/* initialization for a file ( -f option )  
- * always returns 0
- * Similar to core files.
- */ 
-PUBLIC unsigned long file_init(filename)
-char *filename;
-{
-  core_file = &Core_File;
-  core_file->name = (filename != NULL) ? filename : def_name;
-
-  core_file->fid = open(core_file->name, 0);
-  if (filename != NULL && core_file->fid < 0) {
-	Printf("mdb - warning cannot open: %s\n", core_file->name);
-	return -1;
-  }
-
-  core_file->b1 = core_file->b2 = core_file->b3 = 0;
-  core_file->e1 = core_file->e2 = core_file->e3 = -1;
-  core_file->f1 = core_file->f2 = core_file->f3 = 0;
-  core_file->cblock = -1;
-
-  is_separate = FALSE;	
-  core_file->e1 = file_size(core_file->fid);
-  curpid = corepid = 1;
-  return 0;
-
-}
-
-/* 
- * Read from core file 
- * Called by mdbtrace()
- */
-PUBLIC long read_core(req,  addr, data)
-int req;
-long addr, data;
-{
-int i;
-int segment;
-long val;
-
-	switch (req) {
-	    case T_GETINS:
-	    case T_GETDATA:
-		/* Check segment and address - call getn to read core file */
-		segment = (req == T_GETINS) ? T : D;
-		addr &= MASK(ADDRSIZE);
-		val = getn(addr, segment);
-#ifdef  DEBUG
-		if (debug) Printf("val=>%lx\n", val);
-#endif
-		return val;
-		break;
-	    case T_GETUSER:
-		/* Convert addr to index to long array */
-		i = (int) (addr >> 2);
-#ifdef DEBUG
-		if (debug) Printf("lbuf[%d] %lx\n", i, lbuf[i]);
-#endif
-		return lbuf[i];
-		break;
-	    case T_OK:
-	    case T_EXIT:	
-		return 0L;
-		break;
-	    default:
-		mdb_error("Not supported with 'core' files\n");
-	}
-}
-
Index: trunk/minix/commands/mdb/decode.c
===================================================================
--- trunk/minix/commands/mdb/decode.c	(revision 9)
+++ 	(revision )
@@ -1,360 +1,0 @@
-/* 
- * decode.c for mdb -- decodes a Minix system call
- */
-#include "mdb.h"
-#ifdef SYSCALLS_SUPPORT
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#define ptrace mdbtrace
-#include <sys/ptrace.h>
-#include <minix/type.h>
-#include <minix/callnr.h>
-#include "proto.h"
-
-FORWARD _PROTOTYPE( void get_message, (message *m, unsigned bx) );
-FORWARD _PROTOTYPE( void get_data, (char *s, unsigned bx, int cnt) );
-
-PRIVATE message sent;
-PRIVATE message recv;
-PRIVATE unsigned saved_addr;
-PRIVATE int last_call;
-
-#define NOSYS		0
-#define NOP		1
-
-#define _M1		0x0100
-#define _M2		0x0200
-#define _M3		0x0400
-#define _M4		0x0800
-
-#define _M13		0x0500
-
-#define M1_I1		(_M1|1)
-#define M1_I2		(_M1|2)
-#define M1_I3		(_M1|4)
-#define M1_P1		(_M1|8)
-#define M1_P2		(_M1|16)
-#define M1_P3		(_M1|32)
-
-#define M2_I1		(_M2|1)
-#define M2_I2		(_M2|2)
-#define M2_I3		(_M2|4)
-#define M2_L1		(_M2|8)
-#define M2_L2		(_M2|16)
-#define M2_P1		(_M2|32)
-
-#define M3_I1		(_M3|1)
-#define M3_I2		(_M3|2)
-#define M3_P1		(_M3|4)
-#define M3_C1		(_M3|8)
-
-#define M4_L1		(_M4|1)
-#define M4_L2		(_M4|2)
-#define M4_L3		(_M4|4)
-#define M4_L4		(_M4|8)
-#define M4_L5		(_M4|16)
-
-#define M13_OPEN	(_M13|1)
-
-#define M1_I12		(M1_I1|M1_I2)
-#define M1_NAME1	(M1_I1|M1_P1)
-#define M1_NAME2	(M1_I2|M1_P2)
-#define M1_2NAMES	(M1_I1|M1_P1|M1_I2|M1_P2)
-#define M1_SIGACTION	(M1_I2|M1_P1|M1_P2|M1_P3)
-
-#define M2_IOCTL	(M2_I1|M2_I3|M2_L1|M2_L2)
-#define M2_4P		(M2_I1|M2_I2|M2_L1|M2_L2)
-#define M2_SIGRETURN	(M2_I2|M2_L1|M2_P1)
-#define M2_SIGPROC	(M2_I1|M2_L1)
-#define M2_UTIME	(M2_I1|M2_I2|M2_L1|M2_L2|M2_P1)
-
-#define M3_LOAD 	(M3_I1|M3_C1)
-
-struct decode_system {
-	int syscall;
-	unsigned int sflag;
-	unsigned int rflag;
-	char *name;
-} decode[NCALLS] = {  	
-	0,		NOSYS,		NOP,	NULL,
-	EXIT,		M1_I1,		NOP,	"EXIT",
-	FORK,		NOP,		NOP,	"FORK",
-	READ,		M1_I12,		NOP,	"READ",
-	WRITE,		M1_I12,		NOP,	"WRITE",
- 	OPEN,		M13_OPEN,	NOP,	"OPEN",
-	CLOSE,		M1_I1,		NOP,	"CLOSE",
-	WAIT,		NOP,		M2_I1,	"WAIT",
-	CREAT,		M3_LOAD,	NOP,	"CREAT",
-	LINK,		M1_2NAMES,	NOP,	"LINK",
-	UNLINK,		M3_LOAD,	NOP,	"UNLINK",
-	WAITPID,	M1_I1,		M2_I1,	"WAITPID",
-	CHDIR,		M3_LOAD,	NOP,	"CHDIR",
-	TIME,		NOP,		M2_L1,	"TIME",
-	MKNOD,		M1_NAME1,	NOP,	"MKNOD",
-	CHMOD,		M3_LOAD,	NOP,	"CHMOD",
-	CHOWN,		M1_NAME1,	NOP,	"CHOWN",
-	BRK,		M1_P1,		M2_P1,	"BRK",
-	STAT,		M1_NAME1,	NOP,	"STAT",
-	LSEEK,		M1_I1,		NOP,	"LSEEK",
-	GETPID,		NOP,		NOP,	"GETPID",
-	MOUNT,		M1_2NAMES,	NOP,	"MOUNT",
-	UMOUNT,		M3_LOAD,	NOP,	"UMOUNT",
-	SETUID,		M1_I1,		NOP,	"SETUID",
-	GETUID,		NOP,		NOP,	"GETUID",
-	STIME,		M2_L1,		NOP,	"STIME",
-	PTRACE,		M2_4P,		NOP,	"PTRACE",
-	ALARM,		M1_I1,		NOP,	"ALARM",
-	FSTAT,		M1_I1,		NOP,	"FSTAT",
-	PAUSE,		NOP,		NOP,	"PAUSE",
-	UTIME,		M2_UTIME,	NOP,	"UTIME",
-	31,		NOSYS,		NOP,	NULL,
-	32,		NOSYS,		NOP,	NULL,
-	ACCESS,		M3_LOAD,	NOP,	"ACCESS",
-	34,		NOSYS,		NOP,	NULL,
-	35,		NOSYS,		NOP,	NULL,
-	SYNC,		NOP,		NOP,	"SYNC",
-	KILL,		M1_I12,		NOP,	"KILL",
-	RENAME,		M1_2NAMES,	NOP,	"RENAME",
-	MKDIR,		M1_NAME1,	NOP,	"MKDIR",
-	RMDIR,		M3_LOAD,	NOP,	"RMDIR",
-	DUP,		NOP,		NOP,	"DUP",
-	PIPE,		NOP,		M1_I12,	"PIPE",
-	TIMES,		M4_L5,		NOP,	"TIMES",
-	44,		NOSYS,		NOP,	NULL,
-	45,		NOSYS,		NOP,	NULL,
-	SETGID,		M1_I1,		NOP,	"SETGID",
-	GETGID,		NOP,		NOP,	"GETGID",
-	SIGNAL,		NOP,		NOP,	"SIGNAL",
-	49,		NOSYS,		NOP,	NULL,
-	50,		NOSYS,		NOP,	NULL,
-	51,		NOSYS,		NOP,	NULL,
-	52,		NOSYS,		NOP,	NULL,
-	53,		NOSYS,		NOP,	NULL,
-	IOCTL,		M2_IOCTL,	M2_IOCTL,	"IOCTL",
-	FCNTL,		M1_I12,		NOP,	"FCNTL",
-#if	ENABLE_SYMLINK
-	RDLINK,		M1_NAME1,	NOP,	"RDLINK",
-	SLINK,		M1_NAME1,	NOP,	"SLINK",
-	LSTAT,		M1_NAME1,	NOP,	"LSTAT",
-#else
-	56,		NOSYS,		NOP,	NULL,
-	57,		NOSYS,		NOP,	NULL,
-	58,		NOSYS,		NOP,	NULL,
-#endif
-	EXEC,		M1_NAME1,	NOP,	"EXEC",
-	UMASK,		M1_I1,		NOP,	"UMASK",
-	CHROOT,		M3_LOAD,	NOP,	"CHROOT",
-	SETSID,		NOP,		NOP,	"SETSID",
-	GETPGRP,	NOP,		NOP,	"GETPGRP",
-	KSIG,		NOSYS,		NOP,	"KSIG",
-	UNPAUSE,	NOSYS,		NOP,	"UNPAUSE",
-	66,		NOSYS,		NOP,	NULL,
-	REVIVE,		NOSYS,		NOP,	"REVIVE",
-	TASK_REPLY,	NOSYS,		NOP,	"TASK_REPLY",
-   	69,		NOSYS,		NOP,	NULL,
-	70,		NOSYS,		NOP,	NULL,
-	SIGACTION,	M1_SIGACTION,	NOP,	"SIGACTION",
-	SIGSUSPEND,	M2_L1,		NOP,	"SIGSUSPEND",
-	SIGPENDING,	NOP,		M2_L1,	"SIGPENDING",
-	SIGPROCMASK,	M2_SIGPROC,	NOP,	"SIGPROCMASK",
-	SIGRETURN,	M2_SIGRETURN,	NOP,	"SIGRETURN",
-	REBOOT,		M1_I1,		NOP,	"REBOOT"
-};
-
-PRIVATE void get_message(m,bx)
-message *m;
-unsigned bx;
-{
-  unsigned addr;
-  int i;
-  long buffer[ MESS_SIZE/4 + 1 ];
-
-  addr = bx;  
-  for (i = 0; i< sizeof(buffer)/4; i++)
-	buffer[i] = ptrace(T_GETDATA,curpid,
-		(long) (addr+i*4) ,0L);
-
-  memcpy(m,buffer,MESS_SIZE);
-
-}
-
-PRIVATE void get_data(s, bx, cnt)
-char *s;
-unsigned bx;
-int cnt;
-{
-  unsigned addr;
-  int i,nl;
-  long buffer[PATH_MAX/4 + 1];
-
-  addr = bx;
-  nl = (cnt / 4) + 1;  
-  for (i = 0; i< nl; i++)
-	buffer[i] = ptrace(T_GETDATA, curpid, (long) (addr+i*4) ,0L);
-
-  memcpy(s, buffer, cnt);
-}
-
-
-PUBLIC void decode_result()
-{
-
-   /* Update message */
-   get_message(&recv,saved_addr);
-   Printf("result=%d\n", recv.m_type);
-
-   if (last_call < 0 || last_call >NCALLS) {
-	Printf("Bad call in decode_result\n");
-	return;
-   }	 
-
-   switch (decode[last_call].rflag) {
-   case NOP:	
-		return; 
-		break;
-   case M1_I12:
-		Printf("m1_l1=%d m1_i2=%d ",recv.m1_i1,recv.m1_i2);
-		break;
-   case M2_IOCTL:
-		decode_ioctl('R',&recv);
-		break;
-   case M2_P1:	
-		Printf("m2_p1=%lx ",(unsigned long)recv.m2_p1);
-		break;
-   case M2_L1:	
-		Printf("m2_l1=%lx ",recv.m2_l1);
-		break;
-   case M2_I1:
-		Printf("m2_i1=%x ",recv.m2_i1);
-		break;
-   default:	
-		Printf("rflag=%d ",decode[last_call].rflag);
-		break;
-   }
-   Printf("\n");	
-}
-
-
-void decode_message(bx)
-unsigned bx;
-{
-int t; 
-int slen;
-unsigned int flag;
-char path[PATH_MAX];
-
-   /* Save address of message */
-   saved_addr = bx;
-   get_message(&sent,bx);
-
-   t = sent.m_type;
-   
-   if ( t <= 0 || t >= NCALLS ) {
-	Printf("Bad call - not in range\n");
-	last_call = 0;
-	return;
-   }
-
-   flag = decode[t].sflag;
-
-   if ( flag == NOSYS) {
-	Printf("Bad call - not in system\n");
-	last_call = 0;
-	return;
-   }
-   else 
-  	last_call = t; 
-
-   Printf(" type %s (%d) ", decode[last_call].name, last_call);
-
-   switch (flag) {
-   case NOP:	
-		break;
-   case M1_I1:	
-   case M1_I12:	
-		Printf("i1=%d ",sent.m1_i1);
-		if ( flag == M1_I1) break;
-   case M1_I2:	
-		Printf("i2=%d ",sent.m1_i2);
-		break;
-   case M1_P1:	
-		Printf("p1=%lx ",(unsigned long)sent.m1_p1);
-		break;
-   case M1_NAME1:
-   case M1_2NAMES:
-		slen = sent.m1_i1;
-		get_data(path, (unsigned long) sent.m1_p1, slen);
-		path[slen] = '\0';
-		Printf("s1=%s ",path);
-		if ( flag == M1_NAME1) break;
-		slen = sent.m1_i2;
-		get_data(path, (unsigned long) sent.m1_p2, slen);
-		path[slen] = '\0';
-		Printf("s2=%s ",path);
-		break;
-   case M2_UTIME:
-		if ( sent.m2_i1 == 0 )
-			slen = sent.m2_i2;
-		else
-			slen = sent.m2_i1;
-		get_data(path, (unsigned long) sent.m2_p1, slen);
-		path[slen] = '\0';
-		Printf("p1=%s ",path);
-		if ( sent.m2_i1 != 0 )
-			Printf("l1=%lx l2=%lx ",sent.m2_l1,sent.m2_l2);
-		break;
-   case M1_SIGACTION:
-		Printf("m1_i2=%d p1=%lx p2=%lx p3=%lx\n",
-			sent.m1_i2,
-			(unsigned long)sent.m1_p1,
-			(unsigned long)sent.m1_p2,
-			(unsigned long)sent.m1_p3);
-		break;
-   case M2_4P:	Printf("m2_i1=%d m2_i2=%d m2_l1=%lx m2_l2=%lx ",
-			sent.m2_i1,sent.m2_i2,sent.m2_l1,sent.m2_l2);
-		break;
-   case M2_L1:
-		Printf("m2_l1=%ld ",sent.m2_l1);
-		break;
-   case M2_IOCTL:
-		decode_ioctl('S',&sent);
-		break;
-   case M2_SIGRETURN:
-		Printf("m2_i2=%d l1=%lx p1=%lx ",
-			sent.m2_i2,sent.m2_l1,
-			(unsigned long)sent.m1_p1);
-		break;
-   case M2_SIGPROC:
-		Printf("m2_i1=%d l1=%lx ", sent.m2_i1,sent.m2_l1);
-		break;
-   case M13_OPEN:
-		if (sent.m1_i2 & O_CREAT) {
-			slen = sent.m1_i1;
-			get_data(path, (unsigned long) sent.m1_p1, slen);
-			path[slen] = '\0';
-			Printf("s1=%s ",path);
-			break;
-		} 		
-		/* fall to M3_LOAD */
-   case M3_LOAD:
-		slen = sent.m3_i1;
-		if ( slen <= M3_STRING) 
-			strncpy(path,sent.m3_ca1,M3_STRING);
-		else
-			get_data(path, (unsigned long) sent.m3_ca1, slen);
-		path[slen] = '\0';
-		Printf("m3_name=%s ",path);
-		break;
-   case M4_L5:
-		Printf("m4_l5=%ld ",sent.m4_l5);
-		break;
-   default:	Printf("sflag=%d ",decode[last_call].sflag);
-		break;
-   }
-   Printf("\n");
-}
-
-#endif /* SYSCALLS_SUPPORT */
Index: trunk/minix/commands/mdb/gnu_load.c
===================================================================
--- trunk/minix/commands/mdb/gnu_load.c	(revision 9)
+++ 	(revision )
@@ -1,76 +1,0 @@
-/* 
- * gnu_load for mdb.c
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <gnu/a.out.h>
-
-_PROTOTYPE( unsigned int gnu_load, (char *filename, struct nlist **start) );
-_PROTOTYPE( void do_error, (char *message) );
-
-unsigned int gnu_load( filename, start)
-char *filename;
-struct nlist **start;
-{
-        struct exec header;
-	unsigned int nsym, string_size;
-        char *names;
-        struct nlist *p;
-	int fd;
-
-	if ( (fd = open( filename, 0)) < 0 ||
-	     read( fd, (char *) &header, sizeof header ) != sizeof header )
-	{
-                do_error( "gnu_load" );
-                if ( fd >= 0) close( fd );
-		return 0;
-        }       
-
-        if ( lseek( fd, N_STROFF( header ), 0 ) != N_STROFF( header ) )
-        {
-                do_error( "gnu_load - reading header" );
-                close( fd );
-		return 0;
-        }
-
-        if ( read( fd, (char *) &string_size, sizeof string_size ) < 0 )
-        {
-                do_error( "gnu_load - reading header" );
-                close( fd );
-		return 0;
-        }
-        
-        if ( (int) header.a_syms < 0 || 
-		(unsigned) header.a_syms != header.a_syms ||
-             (*start = (struct nlist *) malloc( (unsigned) header.a_syms + 
-                        string_size ))
-                                == (struct nlist *) NULL &&
-             header.a_syms != 0 )
-        {
-                close( fd );
-                return 0;
-        }
-
-        lseek( fd, N_SYMOFF( header ), 0 );
-
-        if ( read( fd, (char *) *start, (int) header.a_syms + string_size ) < 0 )
-        {
-                do_error( "gnu_load - reading symbols" );
-                close( fd );
-                return 0;
-        }
-        close( fd );
-
-        nsym = (unsigned int) header.a_syms / sizeof (struct nlist);
-        names = (char *) *start + header.a_syms;
-	
-        for ( p = *start; p < *start + nsym; p++) 
-                if(p->n_un.n_strx)
-                        p->n_un.n_name = names + p->n_un.n_strx;
-
-	return nsym;
-}
Index: trunk/minix/commands/mdb/gnu_sym.c
===================================================================
--- trunk/minix/commands/mdb/gnu_sym.c	(revision 9)
+++ 	(revision )
@@ -1,365 +1,0 @@
-/* 
- * gnu_sym.c for mdb 
- * copied and modified from sym.c
- * Support GNU Exec symbol tables
- */
-
-#include "mdb.h"
-
-#ifdef	EXTRA_SYMBOLS
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#if	GNU_SUPPORT
-#include <gnu/a.out.h>
-#endif
-#include "proto.h"
-
-#if	GNU_SUPPORT
-_PROTOTYPE( PUBLIC unsigned int gnu_load, (char *filename, struct nlist **start) );
-#endif
-
-struct symtab_s
-{
-	struct nlist *start;
-	struct nlist *end;
-	unsigned int nsym;
-};
-
-PRIVATE struct symtab_s symtab;
-
-FORWARD _PROTOTYPE( void gnu_sort , (struct nlist *array , struct nlist *top ));
-FORWARD _PROTOTYPE( int gnu_symeq , (char *t , struct nlist *sp ));
-FORWARD _PROTOTYPE( int gnu_symprefix , (char *t , struct nlist *sp ));
-FORWARD _PROTOTYPE( struct nlist *gnu_sname, (char *name, int is_text, int allflag) );
-FORWARD _PROTOTYPE( struct nlist *gnu_sval, (off_t value, int where) );
-FORWARD _PROTOTYPE( void gnu_sym, (struct nlist *sp, off_t off) );
-
-PUBLIC void gnu_init( filename )
-char *filename;
-{
-	register struct symtab_s *tp;
-
-	tp = &symtab;
-		
-	tp->nsym = gnu_load(filename, &tp->start);
-	tp->end = tp->start + tp->nsym;
-
-	/* sort on value only, name search not used much and storage a problem */
-	Printf("Sorting %d GNU symbols ....", tp->nsym );
-	gnu_sort( tp->start, tp->end );
-	Printf("\n");
-}
-
-
-
-PUBLIC long gnu_symbolvalue( name, is_text )
-char *name;
-int is_text;
-{
-  register struct nlist *sp;
-  sp = gnu_sname(name,is_text,0);
-  if (sp != NULL)  
-	return sp->n_value;
-  else
-	return 0L;
-}
-
-
-PRIVATE struct nlist *gnu_sname( name, is_text, allflag )
-char *name;
-int is_text;
-int allflag;
-{
-	char *s;
-	unsigned char sclass;
-	int schar;
-	char *send;
-	register struct nlist *sp;
-	register struct symtab_s *tp;
-
-	tp = &symtab;
-
-	if ( allflag )
-	{
-		/* find and print all matching symbols */
-		for ( sp = tp->start; sp < tp->end; ++sp )
-		{
-			if ( gnu_symprefix( name, sp ) )
-			{
-				sp = sp;
-				for ( s = sp->n_un.n_name, send = s + strlen(s);
-				      *s != 0 && s < send; ++s )
-					outbyte( *s );
-				for ( ; s <= send; ++s )
-					outspace();
-				switch( sp->n_type & N_TYPE )
-				{
-					case N_ABS: schar = 'a'; break;
-					case N_TEXT: schar = 't'; break;
-					case N_DATA: schar = 'd'; break;
-					case N_BSS: schar = 'b'; break;
-					default: schar = '?'; break;
-				}
-				if ( (sp->n_type & N_EXT) && schar != '?' )
-					schar += 'A' - 'a';
-				outbyte( schar );
-				outspace();
-				outh32( sp->n_value );
-				outbyte('\n');
-			}
-		}
-	}
-	else
-	{
-		/* find symbol by dumb linear search */
-		for ( sp = tp->start; sp < tp->end; ++sp )
-		{
-			sclass = sp->n_type & N_TYPE;
-			if ( (is_text && sclass == N_TEXT ||
-			      !is_text && (sclass == N_DATA || sclass == N_BSS)) &&
-					 gnu_symeq( name, sp ) )
-				return sp;
-		}
-	}
-	return NULL;
-}
-
-PRIVATE struct nlist *gnu_sval( value, where )
-off_t value;
-int where;
-{
-	int left;
-	int middle;
-	int right;
-	unsigned char sclass;
-	register struct nlist *sp;
-	register struct symtab_s *tp;
-
-	tp = &symtab;
-
-	/* find last symbol with value <= desired one by binary search */
-	for ( left = 0, right = tp->nsym - 1; left <= right; )
-	{
-		middle = (left + right) / 2;
-		sp = tp->start + middle;
-		if ( value < sp->n_value )
-			right = middle - 1;
-		else
-			left = middle + 1;
-	}
-	if ( right >= 0 )
-		/* otherwise tp->start + right may wrap around to > tp->start !! */
-		for ( sp = tp->start + right; sp >= tp->start; --sp )
-		{
-			if ( !(sp->n_type & N_EXT) ) continue; 
-			sclass = sp->n_type & N_TYPE;
-			if ( (where == CSEG && sclass == N_TEXT ||
-						where != CSEG && (sclass == N_DATA || sclass == N_BSS)) )
-			return sp;
-		}
-	return NULL;
-}
-
-
-PRIVATE void gnu_sym( sp, off )
-struct nlist *sp;
-off_t off;
-{
-	register char *s;
-	char *send;
-
-	for ( s = sp->n_un.n_name, send = s + strlen(s); *s != 0 && s < send; ++s )
-		outbyte( *s );
-	if ( (off -= sp->n_value) != 0 )
-	{
-		outbyte( '+' );
-		printhex(off);
-	}
-}
-
-/* shell sort symbols on value */
-
-PRIVATE void gnu_sort( array, top )
-struct nlist *array;
-struct nlist *top;
-{
-	int gap;
-	int i;
-	int j;
-	register struct nlist *left;
-	register struct nlist *right;
-	struct nlist swaptemp;
-	int size;
-
-	size = top - array;
-	/* choose gaps according to Knuth V3 p95 */
-	for ( gap = 1, i = 4; (j = 3 * i + 1) < size; gap = i, i = j )
-		;
-	do
-	{
-		for ( j = gap; j < size; ++j )
-			for ( i = j - gap; i >= 0; i -= gap )
-			{
-				left = array + i; 
-				right = array + (i + gap);
-				if ( (off_t) left->n_value <=
-				     right->n_value )
-					break;
-				swaptemp = *left;
-				*left = *right;
-				*right = swaptemp;
-			}
-	}
-	while ( (gap /= 3) != 0 );
-}
-
-PUBLIC void gnu_symbolic( value, separator )
-off_t value;
-int separator;
-{
-	register struct nlist *sp;
-	long off;
-
-	if (value < st_addr || value > end_addr) {
-		outstr("0x");
-		printhex(value);
-		outbyte(separator);
-		return;
-	}
-
-	if ( (sp = gnu_sval( value, CSEG )) != NULL )
-	{
-		gnu_sym( sp, value );
-	}
-	else if ( (sp = gnu_sval( value, DSEG )) != NULL )
-	{
-		gnu_sym( sp, value );
-	}
-	else
-	{
-		outstr("_start");
-		off = value - st_addr; 
-		if ( off != 0 )  
-		{
-		outbyte( '+' );
-		printhex(off);
-		}
-	}
-	outbyte( separator );
-}
-
-
-PRIVATE int gnu_symeq( t, sp )
-register char *t;
-struct nlist *sp;
-{
-	return strncmp( t, sp->n_un.n_name, strlen(t) ) == 0;
-}
-
-PRIVATE int gnu_symprefix( t, sp )
-register char *t;
-struct nlist *sp;
-{
-	register char *s;
-	char *send;
-
-	for ( ; *t == '_'; ++t )
-		;
-	for ( s = sp->n_un.n_name, send = s + strlen(s);
-	      s < send && *s == '_'; ++s )
-		;
-	return strncmp( s, t, send - s ) == 0;
-}
-
-
-
-/* list all symbols - test for selection criteria */
-
-PUBLIC void gnu_listsym( tchar )
-char tchar;
-{
-	register struct symtab_s *tp;
-	register struct nlist *sp;
-	char *s;
-	char *send;
-	char schar;
-
-	outbyte('\n');	
-	tp = &symtab;
-    	for ( sp = tp->start; sp < tp->end; ++sp )
-	{
-	     switch( sp->n_type & N_TYPE )
-	     {
-			case N_ABS:	schar = 'a'; break;
-			case N_TEXT:	schar = 't'; break;
-			case N_DATA:	schar = 'd'; break;
-			case N_BSS:	schar = 'b'; break;
-			default: 	schar = '?'; break;
-	     }
-
-	     if ( (sp->n_type & N_EXT) && schar != '?' )
-		schar += 'A' - 'a';
-
-	     /* check for selection */	
-	     if ( tchar != '*' && schar != tchar)
-		continue; 	
-
-	     /* print symbol type and value */	
-	     outh32( sp->n_value );
-	     outspace();
-	     outbyte( schar );
-	     outbyte( '\t' );	
-	     for ( s = sp->n_un.n_name, send = s + strlen(s);
-		 *s != 0 && s < send; ++s ) outbyte( *s );
-	     outbyte('\n');	
-	}
-}
-
-PUBLIC int gnu_text_symbol(value)
-off_t value;
-{
-struct nlist *sp;
-
-    if ((sp = gnu_sval(value, CSEG)) != NULL && sp->n_value == value)
-    {
-	gnu_sym(sp, value);
-	return TRUE;
-    }
-    else
-	return FALSE;
-}
-
-PUBLIC int gnu_finds_data(off,data_seg)
-off_t off;
-int data_seg;
-{
-struct nlist *sp;
-
-	if ((sp = gnu_sval(off, data_seg)) != NULL)
-   	{
-	    gnu_sym(sp, off);
-	    return TRUE;
-    	}
-    	else 
-	    return FALSE;
-}
-
-PUBLIC int gnu_finds_pc(pc)
-off_t pc;
-{
-struct nlist *sp;
-
-	if ((sp = gnu_sval(pc, CSEG)) != NULL)
-    	{
-	    gnu_sym(sp, pc);
-	    return TRUE;
-        }
-	else
-	    return FALSE;
-}
-
-
-#endif /* EXTRA_SYMBOLS */
Index: trunk/minix/commands/mdb/io.c
===================================================================
--- trunk/minix/commands/mdb/io.c	(revision 9)
+++ 	(revision )
@@ -1,304 +1,0 @@
-/* 
- * io.c for mdb
- * all the i/o is here
- * NB: Printf()
- */
-#include "mdb.h"
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <sys/types.h>
-#include "proto.h"
-
-#define OUTBUFSIZE	512
-#define PAGESIZE	24
-
-PRIVATE int forceupper = FALSE;
-PRIVATE int someupper = FALSE;
-PRIVATE int stringcount = 0;
-PRIVATE char *string_ptr = NULL;	/* stringptr ambiguous at 8th char */
-PRIVATE char *stringstart = NULL;
-
-PRIVATE char outbuf[OUTBUFSIZE];
-PRIVATE FILE *cmdfile = stdin;
-PRIVATE FILE *outfile = stdout;
-PRIVATE FILE *logfile;
-PRIVATE int lineno;
-
-_PROTOTYPE( int _doprnt, (const char *format, va_list ap, FILE *stream ));
-
-PUBLIC char *get_cmd(cbuf, csize)
-char *cbuf;
-int csize;
-{
-char *r;
-
-  fflush(stdout);
-  if( cmdfile == stdin && outfile == stdout )
-	printf("* ");
-  r = fgets(cbuf, csize, cmdfile);
-  if ( r == NULL && cmdfile != stdin ) {
-	cmdfile = stdin;
-	return get_cmd(cbuf, csize);
-  }
-
-  if ( logfile != NULL ) { 
-	fprintf( logfile, "%s", cbuf );		
-	lineno++;
-  }
-
-  return r;
-}
-
-PUBLIC void openin(s)
-char *s;
-{
-char *t;
-
-  if ((t = strchr(s,'\n')) != NULL) *t = '\0';
-  if ((t = strchr(s,' ')) != NULL) *t = '\0';
-  cmdfile = fopen(s,"r");
-  if (cmdfile == NULL) {
-	Printf("Cannot open %s for input\n",s);
-	cmdfile = stdin; 
-  }
-}
-
-
-/* Special version of printf 
- * really sprintf()
- * from MINIX library
- * followed by outstr()
- */
-PUBLIC int Printf(const char *format, ...)
-{
-	va_list ap;
-	int retval;
-	FILE tmp_stream;
-
-	va_start(ap, format);
-
-	tmp_stream._fd     = -1;
-	tmp_stream._flags  = _IOWRITE + _IONBF + _IOWRITING;
-	tmp_stream._buf    = (unsigned char *) outbuf;
-	tmp_stream._ptr    = (unsigned char *) outbuf;
-	tmp_stream._count  = 512;
-
-	retval = _doprnt(format, ap, &tmp_stream);
-	putc('\0',&tmp_stream);
-
-	va_end(ap);
-
-        outstr(outbuf);
-
-	return retval;
-}
-
-/* 
- * Set logging options 
- */
-PUBLIC void logging( c, name )
-int c;
-char *name;
-{
-char *t;
-
-  if ( c == 'q' && logfile != NULL ) {
-	fclose(logfile);
-	return;
-  }
-
-  if ((t = strchr(name,'\n')) != NULL) *t = '\0';
-  if ((t = strchr(name,' ' )) != NULL) *t = '\0';
-  if ( logfile != NULL ) fclose(logfile);
- 
-  if ( strlen(name) > 0 ) {
-	logfile = fopen(name,"w");
-
-	if (logfile == NULL) {
-		Printf("Cannot open %s for output\n",name);
-		return; 
-	}
-
-	/* Close standard output file for L */
-  	if ( c == 'L' ) {
-		fclose(outfile);
-		outfile = NULL;
-  	}
-  }
-  else 
-  /* Reset */
-  {
-	if ( logfile != NULL ) fclose(logfile);
-	outfile = stdout;
-	outbyte('\n');
-  }
-
-}
-
-/* Output system error string */
-PUBLIC void do_error(m)
-char *m;
-{
-    outstr(m);
-    outstr(": ");
-    outstr(strerror(errno));   
-    outstr("\n");
-}
-
-PUBLIC void closestring()
-{
-/* close string device */
-
-    stringcount = 0;
-    stringstart = string_ptr = NULL;
-}
-
-PUBLIC int mytolower(ch)
-int ch;
-{
-/* convert char to lower case */
-
-    if (ch >= 'A' && ch <= 'Z')
-	ch += 'a' - 'A';
-    return ch;
-}
-
-
-PUBLIC void openstring(string)
-char *string;
-{
-/* open string device */
-
-    stringcount = 0;
-    stringstart = string_ptr = string;
-}
-
-PUBLIC void outbyte(byte)
-int byte;
-{
-/* print char to currently open output devices */
-
-    if (forceupper && byte >= 'a' && byte <= 'z')
-	byte += 'A' - 'a';
-    if (string_ptr != NULL)
-    {
-	if ((*string_ptr++ = byte) == '\t')
-	    stringcount = 8 * (stringcount / 8 + 1);
-	else
-	    ++stringcount;
-    }
-    else 
-    {
-	if ( paging && byte == '\n' ) {
-		lineno++;		
-		if ( lineno >= PAGESIZE) {
-			if ( cmdfile == stdin ) {
-			     printf("\nMore...any key to continue");
-			     fgets( outbuf, OUTBUFSIZE-1, cmdfile );
-		     	}
-		}
-		lineno = 0;
-	}
-
-	if ( outfile != NULL )  
-		putc(byte,outfile);
-	/* Do not log CR */
-	if ( logfile != NULL && byte != '\r' ) 	
-		putc(byte,logfile); 
-    }
-}
-
-
-PUBLIC void outcomma()
-{
-/* print comma */
-
-    outbyte(',');
-}
-
-PRIVATE char hexdigits[] = "0123456789ABCDEF";
-PUBLIC void outh4(num)
-unsigned num;
-{
-/* print 4 bits hex */
-
-    outbyte(hexdigits[num % 16]);
-}
-
-PUBLIC void outh8(num)
-unsigned num;
-{
-/* print 8 bits hex */
-
-    outh4(num / 16);
-    outh4(num);
-}
-
-PUBLIC void outh16(num)
-unsigned num;
-{
-/* print 16 bits hex */
-
-    outh8(num / 256);
-    outh8(num);
-}
-
-PUBLIC void outh32(num)
-unsigned num;
-{
-/* print 32 bits hex */
-
-    outh16((u16_t) (num >> 16));
-    outh16((u16_t) num);
-}
-
-PUBLIC void outspace()
-{
-/* print space */
-
-    outbyte(' ');
-}
-
-PUBLIC void outstr(s)
-register char *s;
-{
-/* print string */
-
-    while (*s)
-	outbyte(*s++);
-}
-
-PUBLIC void outtab()
-{
-/* print tab */
-
-    outbyte('\t');
-}
-
-PUBLIC void outustr(s)
-register char *s;
-{
-/* print string, perhaps converting case to upper */
-
-    forceupper = someupper;
-    while (*s)
-	outbyte(*s++);
-    forceupper = FALSE;
-}
-
-
-PUBLIC int stringpos()
-{
-/* return current offset of string device */
-
-    return string_ptr - stringstart;
-}
-
-PUBLIC int stringtab()
-{
-/* return current "tab" spot of string device */
-
-    return stringcount;
-}
-
Index: trunk/minix/commands/mdb/ioctl.c
===================================================================
--- trunk/minix/commands/mdb/ioctl.c	(revision 9)
+++ 	(revision )
@@ -1,146 +1,0 @@
-/* 
- * ioctl.c for mdb -- decode an IOCTL system call
- */
-#include "mdb.h"
-#ifdef SYSCALLS_SUPPORT
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <minix/type.h>
-#include <minix/callnr.h>
-#include <minix/com.h>
-#include <sys/ioctl.h>
-#include <sgtty.h>
-#include "proto.h"
-
-PRIVATE int get_request;
-
-PRIVATE char *rnames[] = {
-	"TIOCGETP",  
-	"TIOCSETP",
-	"TIOCGETC",
-	"TIOCSETC"
-};
-
-#define GETPNAME	0
-#define SETPNAME	1
-#define GETCNAME	2
-#define SETCNAME	3
-
-/* 
- * decode ioctl call
- * send or receive = 'R' or 'S'
- */
-void decode_ioctl(sr, m)
-int sr;
-message *m;
-{
-int rq;
-int request, device;
-int high;
-long spek, flags;
-int ispeed, ospeed, speed, erase, kill;
-int t_intrc, t_quitc, t_startc, t_stopc, t_brk, t_eof;
-
-   device  = m->m2_i1;
-   request = m->m2_i3;
-   spek    = m->m2_l1;
-   flags   = m->m2_l2;
-
-#ifdef DEBUG
-   if( debug )
-   Printf("%c device=%d request=%c|%d m2_l1=%lx m2_l2=%lx\n",
-	sr,device,
-	(request >> 8) & BYTE,
-	request & BYTE,
-	spek,flags);
-#endif 
-
-   if ( sr == 'R') request = get_request;
-
-   switch(request) {
-     case TIOCGETP:
-     case TIOCSETP:
-	rq = (request == TIOCGETP) ? GETPNAME : SETPNAME;
-	if (sr == 'S') {
-		get_request = request;
-		Printf( "Sending %s ",rnames[rq] );
-		if ( request == TIOCGETP ) break;
-	}
-		
-	if ( (sr == 'R') && (request == TIOCSETP) ) break;
-
-	erase = (spek >> 8) & BYTE;
-	kill  = spek & BYTE;
-  	flags = flags & 0xFFFF;
-	speed = (spek >> 16) & 0xFFFFL;
-	ispeed = speed & BYTE;
-	ospeed = (speed >> 8) & BYTE;
-	Printf("%s erase=%d kill=%d speed=%d/%d flags=%lx ",
-		rnames[rq], erase, kill, ispeed, ospeed, flags);
-	break;
-
-     case TIOCGETC:
-     case TIOCSETC:
-	rq = (request == TIOCGETC) ? GETCNAME : SETCNAME;
-	if (sr == 'S') {
-		get_request = request;
-		Printf( "Sending %s ",rnames[rq] );
-		if ( request == TIOCGETC ) break;
-	}
-
-	if ( (sr == 'R') && (request == TIOCSETC) ) break;
-
-  	t_intrc  = (spek >> 24) & BYTE;
-  	t_quitc  = (spek >> 16) & BYTE;
-  	t_startc = (spek >>  8) & BYTE;
-  	t_stopc  = (spek >>  0) & BYTE;
-	t_brk    = flags & BYTE;
-	t_eof    = (flags >> 8 ) & BYTE;
-	Printf("%s int %d quit %d start %d stop %d brk %d eof %d\n",
-		rnames[rq],
-		t_intrc, t_quitc, t_startc, t_stopc, t_brk, t_eof);
-	break;
-
-     default:
-
-#ifdef	__i86	/* 16 bit */	
-	if ( sr == 'S' ) {
-		Printf("Sending ");
-		get_request = request;
-	}
-	else
-		Printf("Receiving ");
-	
-	Printf("Other IOCTL device=%d request=%c|%d\n",
-		device, (request >> 8) & BYTE, request & BYTE );
-
-	break;
-#endif
-
-#ifdef	__i386	      /* 32 bit encoding */
-	if ( sr == 'S' ) {
-		Printf("Sending (%lx) ",   request);
-		get_request = request;
-	}
-	else
-		Printf("Receiving (%lx) ", request);
-	
-	high = ( request & 0xFFFF0000 ) >> 16 ;
-	request &= _IOCTYPE_MASK;
-
-	Printf("Other IOCTL device=%d request=%c|%d flags=%x size =%d\n",
-		device, (request >> 8) & BYTE, request & BYTE,
-		(high  &  ~_IOCPARM_MASK ),
-		(high  &   _IOCPARM_MASK )
-		);
-	break;
-#endif
-     }	
-     Printf("\n");
-}
-
-
-#endif /* SYSCALLS_SUPPORT */
Index: trunk/minix/commands/mdb/kernel.c
===================================================================
--- trunk/minix/commands/mdb/kernel.c	(revision 9)
+++ 	(revision )
@@ -1,249 +1,0 @@
-/*
- * kernel.c for mdb
- */
-
-#include "mdb.h"
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#define ptrace mdbtrace
-#include <sys/ptrace.h>
-#include "proto.h"
-
-#include <kernel/const.h>
-#include <kernel/type.h>
-#include <kernel/proc.h>
-
-/* Define these here */
-/* buffer for proc and pointer to proc */
-
-#define SIZ (1 + sizeof(struct proc)/sizeof(long))
-
-struct proc *prc;
-long lbuf[SIZ];		
-
-PRIVATE char segment_name[] = "TDS";
-
-/* 
- * Display memory maps 
- */
-PUBLIC void disp_maps()
-{
-  int i;
-  long int vir, phy, len;
-
-  Printf("\t  Virtual\t  Physical\tLength\n");
-  Printf("\t  address\t  address\n");
-  for (i = 0; i < strlen(segment_name); i++) {
-	vir = (long) prc->p_memmap[i].mem_vir << CLICK_SHIFT;
-	phy = (long) prc->p_memmap[i].mem_phys << CLICK_SHIFT;
-	len = (long) prc->p_memmap[i].mem_len << CLICK_SHIFT;
-	Printf("%c:\t0x%08.8lx\t0x%08.8lx\t%8ld (0x%08.8lx)\n",
-	       segment_name[i], vir, phy, len, len);
-  }
-}
-
-PUBLIC void update()
-{
-  int i;
-
-  for (i = 0; i < (SIZ - 1); i++)
-	lbuf[i] = ptrace(T_GETUSER, curpid, (long) (i * sizeof(long)), 0L);
-
-  st_addr = (long) prc->p_memmap[T].mem_vir << CLICK_SHIFT;
-  et_addr = st_addr + ( (long) prc->p_memmap[T].mem_len << CLICK_SHIFT );
-
-  sd_addr  = (long) prc->p_memmap[D].mem_vir << CLICK_SHIFT;
-  ed_addr = end_addr = 
-		sd_addr + ( (long) prc->p_memmap[D].mem_len << CLICK_SHIFT );
-
-  sk_addr = (long) prc->p_memmap[S].mem_vir << CLICK_SHIFT;
-  sk_size = (long) prc->p_memmap[S].mem_len << CLICK_SHIFT;
-
-#ifdef MINIX_PC
-  if ( end_addr < et_addr ) end_addr = et_addr;
-#endif
-
-}
-
-PUBLIC int disp_regs()
-{
-   int i;
-
-   if (curpid <= 0) {
-	Printf("No active process.\n");
-	return 1;
-   }
-
-/* Look at kernel/type.h see how this data from the stackframe is laid out */
-
-#if defined(MINIX_PC) && defined(__i86)
-   Printf("\
- es   ds   di   si   bp   bx   dx   cx   ax   ip   cs   psw  sp   ss\
-\n");
-   for (i = 0; i < 16; i++) 
-	if ( i != 5 && i != 10 ) Printf("%04x ", ((reg_t *) &prc->p_reg)[i]);
-   Printf("\n");
-#endif
-
-#if defined(MINIX_PC) && defined(__i386)
-   Printf("\n");
-   Printf("\
- fs  gs   ds  es    edi      esi      ebp      ebx      edx\n");
-   for (i = 0; i < 8; i++) 
-	if ( i != 6 ) Printf("%08lx ", ((reg_t *) &prc->p_reg)[i]);
-   Printf("\n\
-  ecx      eax      eip       cs      psw      esp       ss\n");
-   for (; i < 16; i++) 
-	if ( i != 10 ) Printf("%08lx ", ((reg_t *) &prc->p_reg)[i]);
-   Printf("\n");
-#endif
-
-#ifdef MINIX_ST
-   Printf("\npc=%lx psw=%x\n\n",(long)PC_MEMBER(prc), PSW_MEMBER(prc));
-   Printf(
-"      0        1        2        3        4        5        6        7\nD");
-   for (i = 0; i < 8; i++) Printf(" %08lx", ((reg_t *) &prc->p_reg)[i]);
-   Printf("\nA");
-   for (; i < NR_REGS; i++) Printf(" %08lx", ((reg_t *) &prc->p_reg)[i]);
-   Printf(" %08lx\n\n", (long)SP_MEMBER(prc));
-#endif
-   return 0;
-}
-
-/* System dependent core */
-
-#ifdef MINIX_PC
-
-#ifdef __i386
-PRIVATE char regs[] = "fs gs ds es di si bp    bx dx cx ax    ip cs ps sp ss";
-#else
-PRIVATE char regs[] = "es ds di si bp    bx dx cx ax    ip cs ps sp ss";
-#endif
-
-/* Get register for pid at offset k */
-PUBLIC long get_reg(pid, k)
-int pid;
-long k;
-{
-  long off;
-  long val;
-  int reg_size;
-
-  /* Calculate size of register */
-  reg_size = (k < N_REG16 * 2) ? 2 : sizeof(reg_t);
-
-  /* Adjust offset */
-  off = k - (k & (sizeof(long) - 1));
-
-  val = ptrace(T_GETUSER, pid, off, 0L);
-
-  if (k & (sizeof(long) - 1))
-	val >>= BITSIZE(reg_size);
-  else
-	val &= MASK(reg_size);
-  return val;
-}
-
-
-/* Set register for pid at offset k */
-PUBLIC void set_reg(pid, k, value)
-int pid;
-long k;
-long value;
-{
-  long off;
-
-  /* Adjust offset */
-  off = k - (k & (sizeof(long) - 1));
-
-  ptrace(T_SETUSER, pid, off, value);
-
-}
-
-
-PUBLIC long reg_addr(s)
-char *s;
-{
-  long val;
-  char *t;
-  char *send;
-  char q[3];
-
-  if (*s == ' ')
-	mdb_error("Invalid syntax\n");
-  q[0] = tolower(*s);
-  q[1] = tolower(*++s);
-  q[2] = '\0';
-
-  t = regs;
-  send = regs + sizeof(regs);
-  while (t < send) {
-	if (strncmp(q, t, 2) == 0) {
-		val = (long) (t - regs);
-		val /= 3L;
-		if (val < N_REG16 - 1)
-			val = val * 2;
-		else
-			val = (N_REG16 - 1) * 2 +
-				(val - N_REG16 + 1) * sizeof(reg_t);
-		return val;
-	}
-	t += 3;
-  }
-  Printf("Unknown register: %s", q);
-  mdb_error("\n");
-}
-
-
-PUBLIC int outsegreg(num)
-off_t num;
-{
-/* print segment register */
-
-    if ((num % HCLICK_SIZE) != 0 || num >= 0x100000)
-    {
-	Printf("%08x",num);
-	return 8;
-    }
-    Printf("%04x", (u16_t) (num / HCLICK_SIZE) );
-    return 4;
-}
-
-#endif
-
-#ifdef MINIX_ST
-
-/* Get register for pid at offset k */
-PUBLIC long get_reg(pid, k)
-int pid;
-long k;
-{
-  return ptrace(T_GETUSER, pid, k, 0L);
-}
-
-PUBLIC long reg_addr(s)
-char *s;
-{
-  long val;
-
-  switch (*s++) {
-      case 'a':
-      case 'A':	val = 32;	break;
-      case 'd':
-      case 'D':	val = 0;	break;
-      case 'P':
-      case 'p': if (*s != 'c' && *s != 'C') goto error;
-		return 64; 
-		break;
-      default:	goto error;
-  }
-  if (*s >= '0' && *s <= '7') 
-	return val + 4 * (*s - '0');
-error:
-  Printf("Unknown register: %2.2s", s);
-  mdb_error("\n");
-}
-
-#endif
Index: trunk/minix/commands/mdb/mdb.1
===================================================================
--- trunk/minix/commands/mdb/mdb.1	(revision 9)
+++ 	(revision )
@@ -1,154 +1,0 @@
-.TH MDB 1
-.SH NAME
-mdb \- Minix debugger
-.SH SYNOPSIS
-.B mdb
-.RB [ \-fc ]
-.I file
-.br
-.B mdb 
-.BR [-L|-l]log\-file
-.I exec-file 
-.RI [ core\-file ]
-.RI [ @command\-file ]
-.SH DESCRIPTION
-.de SP
-.if t .sp 0.4
-.if n .sp
-..
-.B mdb
-is the Minix debugger. 
-.SH OPTIONS
-Its command line options are:
-.TP
-.B \-f
-Just examine the specified file.
-.TP
-.B \-c
-Examine 'core' file. No exec-file will be supplied.
-.TP
-.B \-Llog\-file
-Log to file only
-.TP
-.B \-llog\-file
-Log to file.
-.SP 
-.IR exec\-file
-Unless the -c option has been specified, the exec-file is required.
-.SP
-.IR core\-file
-The core-file is optional.
-.SP
-If the core-file is supplied, 
-.B mdb
-assumes that the user wishes to examine the core file.
-Otherwise 
-.B mdb 
-assumes that the user will run the exec-file and trace it.
-.SP
-.IR @command\-file
-.B mdb 
-executes command from command-file.
-.SH OVERVIEW
-.br
-.B mdb 
-commands are of the form: 
-.I [ expression ]
-.I command
-.SP
-.I expression
-can be of the form:
-.IP
-.I address 
-which defaults to text segment
-.IP
-address 
-.I overriden
-by 
-.I T:
-for Text segment
-or 
-.I D:
-for Data segment
-or
-.I S:
-for Stack segment
-.IP
-.I symbol
-where 
-.B mdb 
-does a lookup for the symbol first as a 
-.I text 
-symbol and then as a 
-.I data 
-symbol.
-.SP
-.TP
-.I command
-.SP
-The help command is ?. 
-.SP
-For detailed help on a command type: 
-.I command ?.
-.SP
-A semi-colon can be used to separate commands on a line.
-.SP
-.SH MDB COMMANDS
-.SP
-! Shell escape
-.SP
-#  Set Variable or register
-.SP 
-Tt Current call / Backtrace all
-.SP
-/nsf Display for n size s with format f
-.SP
-Xx [n] Disasm / & display reg for n instructions
-.SP
-Rr a Run / with arguments a
-.SP
-Cc [n] Continue with current signal / no signal n times
-.SP
-Ii [n] Single step with / no signal for n instructions
-.SP
-Mm t n Trace until / Stop when modified t type for n instructions
-.SP
-k  Kill
-.SP
-Bb Display / Set Break-pt
-.SP
-Dd Delete all / one break-points
-.SP
-P Toggle Pagging
-.SP
-Ll name Log to file name / and to standard output
-.SP
-Vv Toggle debug flag / Version info
-.SP
-V Version info
-.SP
-e [t] List symbols for type t
-.SP
-y Print segment mappings
-.SP
-s [n] Dump stack for n words
-.SP
-z [a] Trace syscalls with address a
-.SP
-? Help - short help
-.SP
-@ file Execute commands from file
-.SP
-Qq Quit / and kill traced process
-.SP
-.SH "SEE ALSO"
-.SP
-trace(2).
-.SH DIAGNOSTICS
-
-.SH NOTES
-
-.SH BUGS
-
-.SH AUTHOR
-Philip Murton and others
Index: trunk/minix/commands/mdb/mdb.c
===================================================================
--- trunk/minix/commands/mdb/mdb.c	(revision 9)
+++ 	(revision )
@@ -1,1028 +1,0 @@
-/*
- * mdb.c - MINIX program debugger
- *
- * Written by Bruce D. Szablak
- *
- * This free software is provided for non-commerical use. No warrantee
- * of fitness for any use is implied. You get what you pay for. Anyone
- * may make modifications and distribute them, but please keep this header
- * in the distribution.
- */
-
-/*
- * Originally ported to MINIX-PC and MINIX-386 by Bruce Evans.
- * NB: the original sym.c and mdbdis86.c come from his 'db'
- *
- * Added by Philip Murton:
- *
- *  2.0		'Core' file functions
- *  2.1		Support for GNU exec
- *  2.2		Changes for Minix 1.6.x Beta
- *  2.3		Changes for Minix 1.7.0 and trace syscalls
- *  2.4		Changes for Minix 1.7.2 and clean up
- *  2.5.1	Add better help 
- *  2.5.2	Added io.c for logging options
- *  2.5.3	Minor changes and tested with Minix 1.7.4
- *  2.5.4	Command arguments processing improved (Thanks to Will Rose)
- *  2.6.0	Final Version for MINIX CD (Sept/96)
- */
-
-#define _MAIN_MDB
-#include "mdb.h"
-
-#include <minix/type.h>
-
-#include <stdio.h>
-#include <signal.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <errno.h>
-#include <sys/wait.h>
-#define ptrace mdbtrace
-#include <sys/ptrace.h>
-#include <setjmp.h>
-#include "proto.h"
-
-#include <kernel/const.h>
-#include <kernel/type.h>
-#include <kernel/proc.h>
-
-/* buffer for proc and pointer to proc */
-extern struct proc *prc;
-
-#define MAXLINE	128
-#define MAXARG	20
-
-PRIVATE unsigned long lastexp = 0L;	/* last expression and segment */
-PRIVATE int lastseg = NOSEG;
-PRIVATE char *prog;		/* prog name */
-PRIVATE char sbuf[MAXLINE];
-PRIVATE char cbuf[MAXLINE];
-PRIVATE char *cmd;		/* current command   */
-PRIVATE char *cmdstart;		/* start of command  */
-PRIVATE jmp_buf mainlp;
-
-
-struct b_pnt {
-  struct b_pnt *nxt, *prv;
-  long addr;
-  long oldval;
-  char cmd[1];
-} *b_head, *curpnt;
-
-_PROTOTYPE( void main , (int argc, char *argv[]));
-
-FORWARD _PROTOTYPE( void cleanup , (void));
-FORWARD _PROTOTYPE( void freepnt , (struct b_pnt *pnt ));
-FORWARD _PROTOTYPE( void findbpnt , (int verbose ));
-FORWARD _PROTOTYPE( int exebpnt , (int restart ));
-FORWARD _PROTOTYPE( void catch , (int sig ));
-FORWARD _PROTOTYPE( int run , (char *name , char *argstr , int tflg ));
-FORWARD _PROTOTYPE( int dowait , (void));
-FORWARD _PROTOTYPE( void backtrace , (int all ));
-FORWARD _PROTOTYPE( void modify , (long addr , int cnt , int verbose , int size ));
-FORWARD _PROTOTYPE( void display , (long addr , int req ));
-FORWARD _PROTOTYPE( void fill , (long addr , int req ));
-FORWARD _PROTOTYPE( void dorun , (char *cmd ));
-FORWARD _PROTOTYPE( void not_for_core , (void));
-FORWARD _PROTOTYPE( void command , (void));
-
-
-PRIVATE void cleanup()
-{
-  curpid = 0;
-  curpnt = NULL;
-  while (b_head) freepnt(b_head);
-}
-
-PRIVATE void findbpnt(verbose)
-int verbose;
-{
-  for (curpnt = b_head; curpnt; curpnt = curpnt->nxt) {
-	if (curpnt->addr == PC_MEMBER(prc) - BREAKPOINT_ADVANCE) {
-		ptrace(T_SETINS, curpid, curpnt->addr, curpnt->oldval);
-		ptrace(T_SETUSER, curpid, PC_OFF, curpnt->addr);
-#if	SYSCALLS_SUPPORT
-		if( syscalls ) 
-			do_syscall(curpnt->addr);
-		else if (curpnt->cmd[0] != '\n')
-#else
-		if (curpnt->cmd[0] != '\n')
-#endif
-			cmd = strcpy(cbuf, curpnt->cmd);
-		else if (verbose)
-			Printf("Breakpoint hit.\n");
-		return;
-	}
-  }
-  if (verbose) Printf("Unknown breakpoint hit.\n");
-}
-
-PRIVATE int exebpnt(restart)
-int restart;
-{
-  ptrace(T_STEP, curpid, 0L, (long) restart);
-  if (dowait() == 0) return TRUE;
-  ptrace(T_SETINS, curpid, curpnt->addr, BREAK(curpnt->oldval));
-  curpnt = NULL;
-  return FALSE;
-}
-
-
-PRIVATE void freepnt(pnt)
-struct b_pnt *pnt;
-{
-  if (pnt->prv)
-	pnt->prv->nxt = pnt->nxt;
-  else
-	b_head = pnt->nxt;
-  if (pnt->nxt) pnt->nxt->prv = pnt->prv;
-  if (curpid > 0) ptrace(T_SETINS, curpid, pnt->addr, pnt->oldval);
-  free(pnt);
-  if (pnt == curpnt) curpnt = NULL;
-}
-
-
-PUBLIC long breakpt(addr, cmd)
-long addr;
-char *cmd;
-{
-  struct b_pnt *new;
-
-  if (curpid <= 0) {
-	Printf("No active process.\n");
-	return 0L;
-  }
-  for (new = b_head; new; new = new->nxt)
-	if (new->addr == addr) {
-		Printf("Breakpoint already exists here.\n");
-		return 0L;
-	}
-  new = (struct b_pnt *) malloc(sizeof(struct b_pnt) + strlen(cmd));
-  if (new == NULL) {
-	Printf("No room for new breakpoint.\n");
-	return 0L;
-  }
-  new->nxt = b_head;
-  new->prv = 0;
-  if (b_head) b_head->prv = new;
-  b_head = new;
-  new->addr = addr;
-  strcpy(new->cmd, cmd);
-  new->oldval = ptrace(T_GETINS, curpid, addr, 0L);
-  ptrace(T_SETINS, curpid, addr, BREAK(new->oldval));
-  if (ptrace(T_GETINS, curpid, addr, 0L) != BREAK(new->oldval)) {
-	do_error("Can't set breakpoint");
-	freepnt(new);
-	return 0L;
-  }
-  return new->oldval;
-}
-
-PRIVATE void catch(sig)
-int sig;
-{
-  signal(sig, catch);
-  if (sig == SIGINT || sig == SIGQUIT) return;
-  tstart(T_EXIT, 0, sig, 0);
-  exit(0);
-}
-
-
-PRIVATE int dowait()
-{
-  int stat;
-
-  if (corepid > 0) return cursig = 0;
-  while (wait(&stat) != curpid) {};
-  if ( WIFEXITED(stat) ) {
-	if (WEXITSTATUS(stat) != 127) 
-		Printf("child exited with status %d\n", WEXITSTATUS(stat));
-	cleanup();
-	return 0;
-  }
-  if ( WIFSIGNALED(stat) ) {
-	Printf("child terminated by signal %d\n", WTERMSIG(stat) );
-	if (_LOW(stat) & 0x80) Printf("(core dumped)\n");
-	cleanup();
-	return 0;
-  }
-  return cursig = WSTOPSIG(stat);
-}
-
-
-
-PUBLIC void tstart(req, verbose, val, cnt)
-int req, verbose, val, cnt;
-{
-  if (curpid == 0) {
-	if (verbose) Printf("No active process.\n");
-	return;
-  }
-  if (req == T_EXIT) {
-	ptrace(T_EXIT, curpid, 0L, (long) val);
-	dowait();
-	return;
-  }
-  if (cnt == 0) cnt = 1;
-  do {
-	if (curpnt) {
-		if (exebpnt(val)) return;
-		if (req == T_RESUME) cnt++;
-		val = 0;
-	} else {
-		ptrace(req, curpid, 0L, (long) val);
-		if (dowait() == 0) return;
-		val = 0;
-		switch (cursig) {
-		    case SIGEMT:	/* breakpoint */
-			update();
-			findbpnt(cnt <= 1);
-			break;
-		    case SIGTRAP:	/* trace trap? */
-			if (req == T_STEP) break;
-		    default:		/* signal */
-			val = cursig;
-			break;
-		}
-	}
-  }
-  while (--cnt > 0);
-  update();
-  if ( verbose ) dasm((long) PC_MEMBER(prc), 1, 1);
-}
-
-PRIVATE int run(name, argstr, tflg)
-char *name, *argstr;
-int tflg;
-{
-  int procid;
-  char *argv[MAXARG], *inf = NULL, *outf = NULL;
-  int argc;
-
-  if ((procid = fork()) == 0) {
-	/* trace me */
-	if (tflg) ptrace(T_OK, 0, 0L, 0L); 
-	argv[0] = name;
-	for (argc = 1;;) {
-		argstr = skip(argstr);
-		if (*argstr == '\n' || *argstr == ';') {
-			argv[argc] = 0;
-			if (inf) freopen(inf, "r", stdin);
-			if (outf) freopen(outf, "w", stdout);
-			if (tflg) {
-				execv(name, argv);
-				do_error("execv");
-			} else {
-				execvp(name, argv);
-				do_error("execvp");
-			}
-			exit(127);
-		}
-		if (*argstr == '<')
-			inf = argstr + 1;
-		else if (*argstr == '>')
-			outf = argstr + 1;
-		else if (argc == MAXARG) {
-			Printf("Too many arguments.\n");
-			exit(127);
-		} else
-			argv[argc++] = argstr;
-		while (!isspace(*argstr)) argstr++;
-		if (*argstr == '\n') argstr[1] = '\n', argstr[2] = 0;
-		*argstr++ = 0;
-	}
-  }
-  if (procid < 0) do_error("Fork failed.\n");
-  return procid;
-}
-
-
-PRIVATE void dorun(cmd)
-char *cmd;
-{
-  if (curpid = run(prog, cmd, 1)) {
-	if (dowait()) {
-		ptrace(T_SETUSER, curpid, BP_OFF, 0L);
-		update();
-		Printf("Process stopped.\n");
-	}
-  }
-}
-
-/* 
- * backtrace - inspect the stack
- */ 
-PRIVATE void backtrace(all)
-int all;
-{
-  unsigned long pc, bp, off, val, obp;
-
-  if (curpid <= 0) {
-	Printf("No process.\n");
-	return;
-  }
-  pc = get_reg(curpid,PC_OFF);
-  bp = get_reg(curpid,BP_OFF);
-  if (bp == 0) {
-	Printf("No active frame.\n");
-	return;
-  }
-  errno = 0;
-  do {
-	symbolic(pc, '(');
-	pc = (ptrace(T_GETDATA, curpid, bp + ADDRSIZE, 0L)
-	      >> SHIFT(ADDRSIZE)) & MASK(ADDRSIZE);
-	off = ptrace(T_GETINS, curpid, pc, 0L);
-#ifdef	DEBUG
-	if(debug)
-	    Printf("Return address %lx Value %lx\n",pc,off);
-#endif
-	obp = bp;
-	bp += 2 * ADDRSIZE;
-
-	/* Check for various instruction used to restore the stack. 
-	 * Should gives us the number of arguments.
-	 * This is obvious dependent on interal features of the 
-	 * compiler used.
-         */ 
-	if (ADDQ(off)) off = ADDQ_CNT(off) + bp;
-#ifdef __mc68000__
-	else if (LEA(off))
-		off = LEA_DISP(off) + bp;
-#endif
-	else if (ADDA(off))
-		off = ADDA_CNT(ptrace(T_GETINS, curpid, pc + 2, 0L)) + bp;
-#if (CHIP == INTEL)
-	else if (INCSP2(off))
-		off = bp + 2*INTSIZE;
-	else if (POPBX2(off))
-		off = bp + 2*INTSIZE;
-	else if (POPCX2(off))
-		off = bp + 2*INTSIZE;
-	else if (POPBX(off))
-		off = bp + INTSIZE;
-	else if (POPCX(off))
-		off = bp + INTSIZE;
-#endif
-	else
-		goto skiplp;
-
-#ifdef DEBUG
-	if (debug) 
-	    Printf("Number of arguments: %d\n",(off-bp)/INTSIZE);
-#endif
-
-	for (;;) {
-		if (errno) return;
-		val = (ptrace(T_GETDATA, curpid, bp, 0L)
-		       >> SHIFT(INTSIZE)) & MASK(INTSIZE);
-		Printf("0x%0*lx", 2 * INTSIZE, val);
-		bp += INTSIZE;
-		if (bp >= off) break;
-		Printf(",");
-	}
-
-skiplp:
-	Printf(")\n");
-	bp = (long) ( (reg_t) ptrace(T_GETDATA, curpid, obp, 0L) );
-#ifdef	DEBUG
-	if(debug)
-		Printf("Old BP %lx New %lx\n",obp,bp);
-#endif
-  }
-  while (all && (reg_t) bp);
-}
-
-PRIVATE void modify(addr, cnt, verbose, size)
-long addr;
-int cnt, verbose, size;
-{
-  long curval, off;
-
-  if (curpid == 0) {
-	Printf("No active process.\n");
-	return;
-  }
-  curval = ptrace(T_GETDATA, curpid, addr, 0L) & MASK(size);
-  do {
-	if (cursig == SIGTRAP) cursig = 0;
-	if (verbose) {
-		off = get_reg(curpid, PC_OFF);
-		dasm(off, 1, 0);
-	}
-	if (curpnt && exebpnt(cursig))
-		return;
-	else {
-		ptrace(T_STEP, curpid, addr, 0L);
-		switch (dowait()) {
-		    case 0:
-			return;
-		    case SIGEMT:
-			update();
-			findbpnt(0);
-			break;
-		}
-	}
-	if (curval != ptrace(T_GETDATA, curpid, addr, 0L) & MASK(size)) {
-		Printf("Modification detected\n");
-		break;
-	}
-  }
-  while (--cnt);
-  update();
-  dasm((long) PC_MEMBER(prc), 1, 1);
-  return;
-}
-
-PRIVATE void display(addr, req)
-long addr;
-int req;
-{
-  int count, size, out, shift;
-  long val, msk;
-  char fmt;
-
-  if (curpid == 0) {
-	Printf("No active process\n");
-	return;
-  }
-  if (req == T_GETDATA && seg == T) req = T_GETINS;
-  count = strtol(cmd, &cmd, 0);
-  if (count == 0) count = 1;
-  cmd = skip(cmd);
-  if (*cmd == 'i' || *cmd == 'I') {
-	dasm(addr, count, *cmd == 'i');
-	return;
-  }
-  if (*cmd == 'y') {
-	symbolic(addr, '\n');
-	return;
-  }
-  switch (*cmd++) {
-      case 'b':	size = sizeof(char);	break;
-      case 'h':	size = sizeof(short);	break;
-      case 'l':	size = sizeof(long);	break;
-      default:  
-	size = sizeof(int);
-	--cmd;
-	break;
-  }
-  switch (fmt = *cmd) {
-      case 'X':
-      case 'D':	
-	size = sizeof(long);
-	break;
-      case 's':
-	addr = ptrace(req, curpid, addr, 0L);
-	req = T_GETDATA;
-      /* Fallthrough */	
-      case 'a':	
-      case 'c':
-	size = sizeof(char);	
-	break;
-  }
-  out = 0;
-  msk = MASK(size);
-  shift = SHIFT(size);
-  do {
-	val = (ptrace(req, curpid, addr, 0L) >> shift) & msk;
-	if (out == 0) Printf("\n0x%0*lx: ", 2 * ADDRSIZE,
-		       (addr >> SHIFT(ADDRSIZE)) & MASK(ADDRSIZE));
-	switch (fmt) {
-	    case 'c':
-		Printf(isprint((int) (UCHAR(val))) ? "   %c " : "\\%03o ",
-					(int) (UCHAR(val)));
-		if (++out == 8) out = 0;
-		break;
-	    case 'u':
-		Printf("%12lu ", val);
-		if (++out == 4) out = 0;
-		break;
-	    case 'x':
-	    case 'X':
-		Printf("%*lx ", 2 * size, val);
-		if (++out == (size == 4 ? 4 : 8)) out = 0;
-		break;
-	    case 'o':
-		Printf("%*lo ", 3 * size, val);
-		if (++out == (size == 4 ? 4 : 8)) out = 0;
-		break;
-	    case 's':
-	    case 'a':
-		if (val)
-			Printf("%c",val);
-		else
-			goto exitlp;
-		if (++out == 64) out = 0;
-		break;
-	    default:
-	    case 'd':
-	    case 'D':
-		Printf("%12ld ", val);
-		if (++out == 4) out = 0;
-		break;
-	}
-	addr += size;
-  }
-  while (--count > 0 || fmt == 's' || fmt == 'a');
-exitlp:
-  Printf("\n");
-}
-
-PRIVATE void fill(addr, req)
-long addr;
-int req;
-{
-  int count, size, shift;
-  long val, msk, nval;
-
-  if (curpid == 0) {
-	Printf("No active process\n");
-	return;
-  }
-  
-  if (req == T_GETDATA && seg == T) {
-	req = T_GETINS;
-	Printf("mdb: warning - modifying text\n");
-  }
-  count = strtol(cmd, &cmd, 0);
-  if ( count == 0 ) count = 1;
-  switch (*cmd++) {
-      case 'b':	size = sizeof(char);	break;
-      case 'h':	size = sizeof(short);	break;
-      case 'l':	size = sizeof(long);	break;
-      default:
-	size = sizeof(int);
-	--cmd;
-	break;
-  }
-  shift = SHIFT(size);
-  msk = MASK(size);
-  cmd = getexp(cmd, &nval, &seg);
-
-#ifdef DEBUG
-  if (debug)
-	Printf("Filling for Count=%d Size=%d val=%lx\n",count,size,nval);
-#endif
-
-  nval <<= shift;
-  do {
-	val = ptrace(req, curpid, addr, 0L) | (nval & msk);
-	val &= (nval | ~msk);
-	ptrace(req + 3, curpid, addr, val);
-	addr += size;
-  }
-  while (--count > 0);
-}
-
-PRIVATE void not_for_core()
-{
-  if (corepid > 0)
-	mdb_error("Illegal command for 'core' file\n");
-}
-
-PRIVATE void command()
-{
-  char c, *p;
-  int i;
-  int size;
-  int stat;
-  long exp, lj, lk;
-  struct b_pnt *bp;
-
-  seg = NOSEG;		/* don't restrict segment expressions are in */
-  cmdstart = cmd = skip(cmd);
-  cmd = getexp(cmd, &exp, &seg);
-
-  if (cmd == cmdstart) {	
-	/* Not an expression */
-	if (corepid < 0) {	/* default to pc for running processs */
-		seg = T;
-		exp = PC_MEMBER(prc);
-	} else {
-		seg = lastseg;
-		exp = lastexp;
-	}
-
-	/* Is it a help command */
-	cmd = skip(cmd+1);
-	if (*cmd == '?') {
- 		help_on(*cmdstart);
-		*cmd = '\n';
-		return;
-	}
-	else
-	    	cmd = cmdstart;
-  }
-
-  if (seg == NOSEG) seg = T;	/* Absolute becomes Text */
-  lastexp = exp;		/* save last expression	 */
-  lastseg = seg;
-#ifdef DEBUG
-  if(debug)
-	Printf("Current address 0x%0*lx and segment %d\n",  2 * ADDRSIZE, exp, seg);
-
-#endif
-
-  /* Check commands */
-  switch (c = *cmd++) {
-      case 'r':		/* illegal for 'core' files */
-      case 'R':
-      case 'k':
-      case 'B':
-      case 'd':
-      case 'D':		not_for_core();	
-			break;
-
-      case 'b':		/* illegal for 'core' files     */
-      case 'c':		/* Otherwise run process first  */
-      case 'C':
-      case 'm':
-      case 'M':
-#if	SYSCALLS_SUPPORT
-      case 'z':
-#endif
-      case 'i':
-      case 'I':		not_for_core();
-			if (curpid <= 0) dorun("\n");
-			break;
-
-      case 's':		if (curpid <= 0) dorun("\n");
-			break;
-	
-      default:		break;
-  }
-
-  switch (c) {
-      case '!':		/* escape to shell */
-	if (cmd == cmdstart + 1) {
-		cmd = skip(cmd);
-		if (*cmd == '\n' || *cmd == ';') {
-			i = run("/bin/sh", "\n", 0);
-		} else {
-			for (p = cmd + 1; *p && !isspace(*p); p++) {
-			};
-			*p++ = 0;
-			i = run(cmd, *p ? p : "\n", 0);
-		}
-		if (i > 0) while (wait(&stat) != i) {};
-		break;
-	}
-	if (corepid > 0) longjmp(mainlp, 0);
-	break;
-      case 'T':		/* top line of backtrace */
-	backtrace(0);
-	break;
-      case 't':		/* back trace */
-	backtrace(1);
-	break;
-      case '/':		/* print variable value */
-	display(exp, T_GETDATA);
-	break;
-      case 'x':		/* print registers and instruction */
-	if (disp_regs()) break;
-	/* FALLTHROUGH */
-      case 'X':		/* print instruction - X n [, n] */
-	lj = strtol(cmd, &cmd, 0);
-	lk = 0;
-	if (*cmd != '\0') 
-		lk = strtol(++cmd, &cmd, 0);
-	if (curpid > 0)
-		dasm(exp + lk, lj ? lj : 1, 1);
-	else
-		Printf("No active process.\n");
-	break;
-      case 'R':		/* run program with no args */
-      case 'r':		/* run program with args (possibly defaulted) */
-	tstart(T_EXIT, 0, 0, 0);
-	if (c == 'r') {
-		cmd = skip(cmd);
-		if (*cmd == '\n' || *cmd == ';')
-			cmd = sbuf;
-		else
-			strcpy(sbuf, cmd);
-	} else {
-		cmd = "\n";
-	}
-	dorun(cmd);
-	break;
-      case 'c':		/* continue program - ignore signal */
-	cursig = 0;
-      case 'C':		/* continue program - handle signal */
-	i = 0;
-	if (seg == T && curpnt == 0 && cmd != cmdstart + 1) {
-		breakpt(exp, "\n");
-		curpnt = b_head;
-		ptrace(T_SETINS, curpid, curpnt->addr, curpnt->oldval);
-		i = 1;
-	}
-	tstart(T_RESUME, 1, cursig, (int) strtol(cmd, &cmd, 0));
-	/* remove temporary bp */
-	if (i) freepnt(b_head);
-	if (cursig == SIGEMT) return;
-	if (curpid) Printf("Process stopped by signal %d\n", cursig);
-	break;
-      case 'i':		/* single step - ignore signal */
-	tstart(T_STEP, 1, 0, (int) strtol(cmd, &cmd, 0));
-	break;
-      case 'I':		/* single step - handle signal */
-	tstart(T_STEP, 1, cursig, (int) strtol(cmd, &cmd, 0));
-	break;
-      case 'm':		/* single step until location modified */
-      case 'M':		/* single step until location modified - verbose */
-	cmd = skip(cmd);
-	switch (*cmd++) {
-	    case 'b':	size = sizeof(char);	break;
-	    case 'h':	size = sizeof(short);	break;
-	    case 'l':	size = sizeof(long);	break;
-	    default:
-		size = sizeof(int);
-		--cmd;
-		break;
-	}
-	modify(exp, (int) strtol(cmd, &cmd, 0), c == 'M', size);
-	break;
-      case 'k':		/* kill current program */
-	tstart(T_EXIT, 1, 0, 0);
-	break;
-      case 'b':		/* set a breakpoint at the given line */
-#ifdef	MINIX_PC
-	if (seg != T || exp > end_addr ) {
-#else
-	if (seg != T || exp < st_addr || exp > et_addr ) {
-#endif	
-		Printf("Address not in text space.\n");
-		return;
-	}
-	breakpt(exp, skip(cmd));
-	cmd = "\n";
-	return;
-      case 'B':		/* print list of currently active breakpoints */
-	for (i = 1, bp = b_head; bp; bp = bp->nxt, i++) {
-		Printf("%2d: ", i);
-		symbolic((long) bp->addr, '\t');
-		Printf("(0x%lx)\t- %s", bp->addr, bp->cmd);
-	}
-	break;
-      case 'd':		/* delete breakpoint */
-	if (seg == T) {
-		for (bp = b_head; bp && bp->addr != exp; bp = bp->nxt);
-		if (bp) {
-			freepnt(bp);
-			break;
-		}
-	}
-	Printf("No such breakpoint.\n");
-	break;
-      case 'D':		/* delete all breakpoints */
-	while (b_head) freepnt(b_head);
-	break;
-      case 's':
-	dump_stack( strtol(cmd, &cmd, 0) );
-	break;
-      case 'P':
-	paging = !paging;
-	if (paging) Printf("Paging is ON\n");
-	break;
-      case 'l':
-      case 'L':
-	logging(c,skip(cmd));
-	break;
-#if	SYSCALLS_SUPPORT
-      case 'z':
-	start_syscall( strtol(cmd, &cmd, 0) );
-	if ( syscalls ) 
-		Printf("Break point set - use the 'c n' command\n");
-	break;
-#endif
-      case 'q':		/* quit */
-	tstart(T_EXIT, 0, 0, 0);
-	logging(c,cmd);
-      case 'Q':
-	exit(0);	
-	break;
-      case '\n':
-      case ';':
-	if (isdigit(*cmdstart))
-		symbolic(exp, '\n');
-	else
-	        Printf("0x%0*lx\n", 2 * ADDRSIZE, exp);
-	--cmd;
-	break;
-#ifdef	DEBUG
-      case 'v':		/* toggle debug */
-	debug = !debug;
-	if (debug) Printf("Debug flag ON\n");
-	break;
-#endif
-      case 'e':		/* list symbols */
-	listsym(cmd);
-	break;
-      case 'y':		/* print mapping */
-	prtmap();
-	break;
-      case '?':		/* print help */
-	help_page();
-	break;
-      case 'V':		/* print version info */
-	version_info();
-	break;
-      case '@':		/* command file  */
-	cmd = skip(cmd);
-	openin(cmd);
-	*cmd = '\n';
-	return;
-      case '#':		/* set register or variable */
-	cmd = skip(cmd + 1);
-	if (*cmd == '$') {
-		cmd++;
-		i = reg_addr(cmd); 
-		set_reg(curpid, i, strtol(cmd+2, &cmd, 0) );
-		update();
-		break;
-	}
-	cmd = getexp(cmd, &exp, &seg);
-	fill(exp, T_GETDATA);
-	break;
-      default:  
-	help_page();
-	break;
-  }
-  while (*cmd != '\n' && *cmd != ';') ++cmd;
-  if (*cmd == ';') cmd = skip(cmd + 1);
-}
-
-PUBLIC void mdb_error(s)
-char *s;
-{
-  Printf("%s",s);
-  longjmp(mainlp, 0);
-}
-
-PUBLIC void main(argc, argv)
-int argc;
-char *argv[];
-{
-  int i, c;
-  char *p, *q, *r;
-  int opt_c = FALSE;	/* load core file */
-  int opt_f = FALSE;	/* load object file */
-  int opt_l = FALSE;	/* log to file */
-  int opt_L = FALSE;	/* log to file and screen */
-
-
-  prc = (struct proc *) lbuf;
-  strcpy(sbuf, "\n");
-  corepid = -1;	/* set to indicate none */
-  prog = p = q = r = NULL;
-
-  if ( argc == 1 )
-  {
-	help_page();
-	exit(0);
-  }
-
-  /* Possible combinations of arguments:
-   * A single file name:
-   *	If the name is 'core', the coreonly flag is set.
-   * The -c flag: examine a core file.
-   *	One filename is required with this flag.
-   * The -f flag: examine an object file.
-   *	One file name is required with this flag.
-   * The -L or -l flag: write to a log file.
-   *	One file name is required with these flags.
-   * The -x flag: turn on debugging.
-   *	Used for debugging, and followed by an integer
-   *	argument which is the debugging level.
-   *
-   * If any files remain on the argument list, the first
-   * file is an executable, and the second a core file.
-   * If any filename starts with '@' it is assumed to
-   * to be a command file.  Only one command file is
-   * loaded.
-   */
-
-  /* check for default file name and fake out getopt */
-  if (strcmp(argv[1], "core") == 0) {
-	for (i = argc ; i > 1 ; i--)
-		argv[i] = argv[i - 1];
-	argv[i] = "-c";
-	argc++;
-  }
-
-  /* parse options */
-  opterr = 0;
-  while ((i = getopt(argc, argv, "c:f:L:l:x:")) != EOF) {
-	switch (i & 0377) {
-	case 'c':		/* examine a core file */
-		if (opt_c == TRUE || opt_f == TRUE) {
-			help_page();
-			exit(1);
-		}
-		p = optarg;
-		opt_c = TRUE;
-		break;
-	case 'f':		/* examine an object file */
-		if (opt_c == TRUE || opt_f == TRUE) {
-			help_page();
-			exit(1);
-		}
-		p = optarg;
-		opt_f = TRUE;
-		break;
-	case 'l':		/* start logging */
-		if (opt_l == TRUE || opt_L == TRUE) {
-			help_page();
-			exit(1);
-		}
-		opt_l = TRUE;
-		logging(i, optarg);
-		break;
-	case 'L':		/* start logging */
-		if (opt_l == TRUE || opt_L == TRUE) {
-			help_page();
-			exit(1);
-		}
-		opt_L = TRUE;
-		logging(i, optarg);
-		break;
-#ifdef DEBUG
-	case 'x':		/* set debug level */
-		debug = atoi(optarg);
-		break;
-#endif
-	case '?':		/* default arguments arrive here */
-	default:
-		help_page();
-		exit(1);
-	}
-  }
-
-  /* can't cope without filenames */
-  if (!opt_c && !opt_f && optind >= argc) {
-	help_page();
-	exit(1);
-  }
-
-  /* any remaining arguments are (optional) file names */
-  for (i = optind ; i < argc ; i++) {
-	if (*argv[i] == '@') {			/* command file */
-		if (r == NULL) r = argv[i] + 1;
-	}
-	/* you can't combine a -c or -f object file and a core file */
-	else if (!opt_c && !opt_f && p == NULL) p = argv[i];
-	else if (q == NULL) q = argv[i];	/* core file */
-  }
-
-  /* initialise stuff - fairly tricky logic */
-  coreonly = opt_c;
-  fileonly = opt_f;
-  /* when examining files, prog == NULL */
-  if (!opt_c && !opt_f) {
-	prog = p;
-	syminit(prog);
-  }
-
-  /* file_init is called for non-core files. 
-   * It is very similar to core_init. It opens the file and set
-   * various pointers so that we can read it using the same routines
-   * as a core file. 
-   * NB: Currently there is no special provision to handle object files.
-   */
-
-  /* A comment from Will Rose:
-   * It would be nice to have
-   * symbol tables available when reading a core
-   * or a.out, either as part of the executable or
-   * as a separate file.
-   * At least three separate types of file structure
-   * may be used by mdb - core files, a.out files, and
-   * object files (which may have several flavours).
-   * A set of routines is needed for each type, with
-   * a function switch table initialised  when mdb is
-   * started up.
-   */
-
-  if (opt_c) lastexp = core_init(p);
-  if (opt_f) lastexp = file_init(p);
-  if (q != NULL) lastexp = core_init(q);
-  if (r != NULL) openin(r);
-  for (i = 1; i < _NSIG; i++) signal(i, catch);
-
-  setjmp(mainlp);
-
-  while (get_cmd( cbuf, MAXLINE ) != NULL) {
-	if (strlen(cbuf) == sizeof(cbuf) - 1) {
-		Printf("Command line too long.\n");
-		continue;
-	}
-	cmd = cbuf;
-	command();
-	while (*cmd != '\n') command();
-  }
-  tstart(T_EXIT, 0, 0, 0);
-  exit(0);
-}
Index: trunk/minix/commands/mdb/mdb.h
===================================================================
--- trunk/minix/commands/mdb/mdb.h	(revision 9)
+++ 	(revision )
@@ -1,182 +1,0 @@
-/*
- * mdb.h for mdb
- */ 
-#define MDBVERSION	"2.6"
-#define MDBBUILD	0
-
-#define	MINIX_SYMBOLS	1
-#define	GNU_SYMBOLS	2
-
-/*
- * Handle options here 
- */
-#ifndef GNU_SUPPORT
-#define	GNU_SUPPORT		0
-#endif
-
-#ifndef SYSCALLS_SUPPORT
-#define SYSCALLS_SUPPORT	0
-#endif
-
-#ifdef DEBUG
-#undef DEBUG
-#endif
-
-#ifdef  NDEBUG
-#undef  DEBUG
-#else
-#define DEBUG			1
-#endif
-
-#ifdef	__i386
-#define EXTRA_SYMBOLS		GNU_SUPPORT
-#else
-#define EXTRA_SYMBOLS		0
-#endif
-
-
-#include <minix/config.h>
-#include <ansi.h>
-#include <sys/types.h>
-
-#include <minix/const.h>
-#include <minix/type.h>
-
-#include <limits.h>
-#include <errno.h>
-#include <minix/ipc.h>
-#include <timers.h>
-
-#undef printf		/* defined as printk in <minix/const.h> */
-
-#if (CHIP == M68000)
-#define __mc68000__	/* controls processor-dependent stuff */
-#if (MACHINE == ATARI)
-#define MINIX_ST	/* controls system-dependent stuff */
-#else
-#error "only the MINIX_ST 1.5.x implementation works on 68K's"
-#endif
-#endif
-
-#if (CHIP == INTEL)
-#if (MACHINE == IBM_PC)
-#define MINIX_PC
-#else
-#error "only the MINIX_PC 1.5.x and later versions works on *86's"
-#endif
-#endif
-
-#ifdef MINIX_ST	
-#define BP_OFF ((long)&((struct proc *)0)->p_reg.a6)
-#define PC_MEMBER(rp) ((rp)->p_reg.pc)
-#define PC_OFF ((long)&((struct proc *)0)->p_reg.pc)
-#define SP_MEMBER(rp) ((rp)->p_reg.sp)
-#define PSW_MEMBER(rp) ((rp)->p_reg.psw)
-#endif
-
-#ifdef MINIX_PC
-#define BP_OFF ((long)&((struct proc *)0)->p_reg.fp)
-#define PC_MEMBER(rp) ((rp)->p_reg.pc)
-#define PC_OFF ((long)&((struct proc *)0)->p_reg.pc)
-#endif
-
-#define ADDRSIZE	_WORD_SIZE
-#define BITSIZE(size)	(8 * (size))
-#define INTSIZE		(sizeof(int))	/* not quite right for cross-debugger */
-#define LONGSIZE	(sizeof(long))
-#define UCHAR(x)	((x) & 0xFF)
-#define NOSEG		(-1)	/* no segment */
-
-/* use hardware codes for segments for simplest decoding */
-#define CSEG		0x2E	/* 8088 through 80386 */
-#define DSEG		0x3E
-
-#if (CHIP == INTEL )
-#ifdef __i86
-#define N_REG16	2
-#endif
-#ifdef __i386
-#define N_REG16	4  /* 16 bit registers at start of stackframe */ 
-#endif
-#ifndef N_REG16
-#error "N_REG16 not defined"
-#endif
-#endif
-
-#if (CHIP == INTEL )
-#define ADDA(l) ((u16_t) (l) == 0xC481)
-
-#ifdef __i386
-#define ADDA_CNT(l) ((i32_t) (l))
-#else
-#define ADDA_CNT(l) ((i16_t) (l))
-#endif
-
-#define ADDQ(l) ((u16_t) (l) == 0xC483)
-#define ADDQ_CNT(l) (((((l) >> 16) + 128) & 0x000000FF) - 128)
-#define BREAK(l) (0x000000CC | ((l) & 0xFFFFFF00))
-#define BREAKPOINT_ADVANCE 1
-#define INCSP2(l) ((u16_t) (l) == 0x4444)
-#define POPBX2(l) ((u16_t) (l) == 0x5B5B)
-#define POPBX(l)  ( (l & 0xFF) == 0x5B) 
-
-/* Added for ANSI CC */
-#define POPCX2(l) ((u16_t) (l) == 0x5959)
-#define POPCX(l)  ( (l & 0xFF) == 0x59) 
-
-#endif
-
-#ifdef __mc68000__
-#define ADDA(l) ((int)((l) >> 16) == 0xDFFC)
-#define ADDA_CNT(l) (l)
-#define ADDQ(l) (((l >> 16) & 0xF13F) == 0x500F)
-#define ADDQ_CNT(l) (((((l) >> 25) - 1) & 7) + 1)
-#define BREAK(l) (0xA0000000 | ((l) & 0xFFFF))
-#define BREAKPOINT_ADVANCE 0
-#define BYTES_SWAPPED	/* this assumes WORDS_SWAPPED too */
-#define LEA(l) (((l) >> 16) == 0x4FEF)
-#define LEA_DISP(l) ((long)( l & 0xFFFF)) 
-#endif
-
-#define MASK(size) ((size) >= LONGSIZE ? -1L : (1L << BITSIZE(size)) - 1)
-
-#ifdef BYTES_SWAPPED
-#define SHIFT(size) BITSIZE(LONGSIZE - (size))
-#else
-#define SHIFT(size) (0)
-#endif
-
-#ifdef _MAIN_MDB
-#undef EXTERN
-#define EXTERN
-#endif
-
-extern long lbuf[];		/* buffer for proc	  */ 
-
-EXTERN long st_addr;		/* starting address of text  */
-EXTERN long et_addr;		/* ending address of text    */
-EXTERN long sd_addr;		/* starting address of data  */
-EXTERN long ed_addr;		/* ending address of data  */
-EXTERN long end_addr;		/* ending address of text/data */
-EXTERN long sk_addr;		/* starting address of stack   */
-EXTERN long sk_size;		/* size of stack   */
-EXTERN int curpid;		/* current pid of process/core */
-EXTERN int corepid;		/* pid of core file */
-EXTERN int coreonly;		/* core file only   */
-EXTERN int fileonly;		/* file only        */
-EXTERN int cursig;		/* current signal   */
-EXTERN int seg;			/* segment 	    */
-EXTERN int is_separate;		/* separate I & D   */ 
-EXTERN int paging;		/* paging flag      */
-#ifdef	DEBUG
-EXTERN int debug;		/* debug flag	    */
-#endif
-#if	SYSCALLS_SUPPORT
-EXTERN int syscalls;		/* trace syscalls   */
-#endif
-
-#ifdef _MAIN_MDB
-#undef EXTERN
-#define EXTERN extern
-#endif
-
Index: trunk/minix/commands/mdb/mdbdis86.c
===================================================================
--- trunk/minix/commands/mdb/mdbdis86.c	(revision 9)
+++ 	(revision )
@@ -1,1564 +1,0 @@
-/* 
- * mdbdis86.c for mdb.c - 8086-386 and 8087 disassembler
- * From Bruce Evans db
- */
-
-#include "mdb.h"
-#include <stddef.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include "proto.h"
-
-struct address_s
-{
-    off_t off;
-    off_t base;
-};
-
-PRIVATE int bits32;
-PRIVATE struct address_s uptr;
-
-FORWARD _PROTOTYPE( u8_t  get8, (void) );
-FORWARD _PROTOTYPE( u16_t get16, (void) );
-FORWARD _PROTOTYPE( u32_t get32, (void) );
-FORWARD _PROTOTYPE( u8_t  peek_byte,  (off_t addr) );
-FORWARD _PROTOTYPE( u16_t peek_word,  (off_t addr) );
-FORWARD _PROTOTYPE( int puti, (void) );
-FORWARD _PROTOTYPE( int outsegaddr, (struct address_s *addr) );
-FORWARD _PROTOTYPE( int outssegaddr, (struct address_s *addr) );
-FORWARD _PROTOTYPE( int show1instruction , (void));
-
-/************************* UNASM ******************************/
-
-
-#define LINDIRECT	'['
-#define RINDIRECT	']'
-
-#define BASE_MASK	0x07
-#define INDEX_MASK	0x38
-#define INDEX_SHIFT	3
-#define MOD_MASK	0xC0	/* mod reg r/m  is  mmrrrRRR */
-#define REG_MOD		0xC0
-#define MEM0_MOD	0x00
-#define MEM1_MOD	0x40
-#define MEM2_MOD	0x80
-#define REG_MASK	0x38
-#define REG_SHIFT	3
-#define RM_MASK		0x07
-#define RM_SHIFT	0
-#define SS_MASK		0xC0
-#define SS_SHIFT	6
-
-#define SIGNBIT		0x02	/* opcode bits xxxxxxsw for immediates */
-#define WORDBIT		0x01
-#define TOREGBIT	0x02	/* opcode bit for non-immediates */
-
-#define MAX_SIGNED_CHAR	0x7F	/* will assume 2's complement */
-#define MAX_UNSIGNED_CHAR	0xFF
-
-typedef unsigned opcode_pt;	/* promote to unsigned and not int */
-
-typedef int reg_pt;
-typedef int su16_t;
-typedef int su8_pt;
-
-FORWARD _PROTOTYPE(  su8_pt get8s , (void));
-FORWARD _PROTOTYPE(  void getmodregrm , (void));
-FORWARD _PROTOTYPE(  void i_00_to_3f , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_40_to_5f , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_60_to_6f , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_70_to_7f , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_80 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_88 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_90 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_98 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_a0 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_a8 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_b0 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_b8 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_c0 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_c8 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_d0 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_d8 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_e0 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_e8 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_f0 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void i_f8 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void outad , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void outad1 , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void outalorx , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void outax , (void));
-FORWARD _PROTOTYPE(  void outbptr , (void));
-FORWARD _PROTOTYPE(  void outbwptr , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void outea , (opcode_pt wordflags ));
-FORWARD _PROTOTYPE(  void outf1 , (void));
-FORWARD _PROTOTYPE(  void out32offset , (void));
-FORWARD _PROTOTYPE(  void outfishy , (void));
-FORWARD _PROTOTYPE(  void outgetaddr , (void));
-FORWARD _PROTOTYPE(  void outimmed , (opcode_pt signwordflag ));
-FORWARD _PROTOTYPE(  void outpc , (off_t pc ));
-FORWARD _PROTOTYPE(  void outsegpc , (void));
-FORWARD _PROTOTYPE(  void oututstr , (char *s ));
-FORWARD _PROTOTYPE(  void outword , (void));
-FORWARD _PROTOTYPE(  void outwptr , (void));
-FORWARD _PROTOTYPE(  void outwsize , (void));
-FORWARD _PROTOTYPE(  void pagef , (void));
-FORWARD _PROTOTYPE(  void shift , (opcode_pt opc ));
-FORWARD _PROTOTYPE(  void checkmemory , (void));
-FORWARD _PROTOTYPE(  void CL , (void));
-FORWARD _PROTOTYPE(  void Eb , (void));
-FORWARD _PROTOTYPE(  void Ev , (void));
-FORWARD _PROTOTYPE(  void EvGv , (void));
-FORWARD _PROTOTYPE(  void EvIb , (void));
-FORWARD _PROTOTYPE(  void Ew , (void));
-FORWARD _PROTOTYPE(  void EwRw , (void));
-FORWARD _PROTOTYPE(  void Gv , (void));
-FORWARD _PROTOTYPE(  void Gv1 , (void));
-FORWARD _PROTOTYPE(  void GvEv , (void));
-FORWARD _PROTOTYPE(  void GvEw , (void));
-FORWARD _PROTOTYPE(  void GvM , (void));
-FORWARD _PROTOTYPE(  void GvMa , (void));
-FORWARD _PROTOTYPE(  void GvMp , (void));
-FORWARD _PROTOTYPE(  void Ib , (void));
-FORWARD _PROTOTYPE(  void Iw , (void));
-FORWARD _PROTOTYPE(  void Iv , (void));
-FORWARD _PROTOTYPE(  void Jb , (void));
-FORWARD _PROTOTYPE(  void Jv , (void));
-FORWARD _PROTOTYPE(  void Ms , (void));
-
-_PROTOTYPE( typedef void (*pfv_t),(opcode_pt opc ));
-
-PRIVATE pfv_t optable[] =
-{
- i_00_to_3f,
- i_00_to_3f,
- i_00_to_3f,
- i_00_to_3f,
- i_00_to_3f,
- i_00_to_3f,
- i_00_to_3f,
- i_00_to_3f,
- i_40_to_5f,
- i_40_to_5f,
- i_40_to_5f,
- i_40_to_5f,
- i_60_to_6f,
- i_60_to_6f,
- i_70_to_7f,
- i_70_to_7f,
- i_80,
- i_88,
- i_90,
- i_98,
- i_a0,
- i_a8,
- i_b0,
- i_b8,
- i_c0,
- i_c8,
- i_d0,
- i_d8,
- i_e0,
- i_e8,
- i_f0,
- i_f8,
-};
-
-PRIVATE char fishy[] = "???";
-PRIVATE char movtab[] = "mov\t";
-
-PRIVATE char *genreg[] =
-{
- "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
- "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
- "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
-};
-
-PRIVATE char *segreg[] =
-{
- "es", "cs", "ss", "ds", "fs", "gs", "?s", "?s",
-};
-
-PRIVATE char *indreg[] =
-{
- "bx+si", "bx+di", "bp+si", "bp+di", "si", "di", "bp", "bx",
-};
-
-PRIVATE char *str_00_to_3f[] =
-{
- /* index by (opcode >> 3) & 7 */
- "add", "or", "adc", "sbb", "and", "sub", "xor", "cmp",
-};
-
-PRIVATE char *sstr_00_to_3f[] =
-{
- /* index ((opc>>2) & 0x0E) + (opc & 7) - 6 */
- "push\tes", "pop\tes", "push\tcs", "pop\tcs",
- "push\tss", "pop\tss", "push\tds", "pop\tds",
- "es:", "daa", "cs:", "das", "ss:", "aaa", "ds:", "aas",
-};
-
-PRIVATE char *sstr_0f[] =
-{
- "push\tfs", "pop\tfs", fishy, "bt\t", "shld\t", "shld\t", fishy, fishy,
- "push\tgs", "pop\tgs", fishy, "bts\t", "shrd\t", "shrd\t", fishy, "imul\t",
- fishy, fishy, "lss\t", "btr\t", "lfs\t", "lgs\t", "movzx\t", "movzx\t",
- fishy, fishy, "", "btc\t", "bsf\t", "bsr\t", "movsx\t", "movsx\t",
-};
-
-PRIVATE char *ssstr_0f[] =
-{
- "sldt\t", "str\t", "lldt\t", "ltr\t", "verr\t", "verw\t", fishy, fishy,
- "sgdt\t", "sidt\t", "lgdt\t", "lidt\t", "smsw\t", fishy, "lmsw\t", fishy,
- fishy, fishy, fishy, fishy, "bt\t", "bts\t", "btr\t", "btc\t",
-};
-
-PRIVATE char *str_40_to_5f[] =
-{
- /* index by (opcode >> 3) & 3 */
- "inc\t", "dec\t", "push\t", "pop\t",
-};
-
-PRIVATE char *str_60_to_6f[] =
-{
- "pusha", "popa", "bound\t", "arpl\t", "fs:", "gs:", "os:", "as:",
- "push\t", "imul\t", "push\t", "imul\t", "insb", "ins", "outsb", "outs",
-};
-
-PRIVATE char *str_flags[] =
-{
- /* opcodes 0x70 to 0x7F, and 0x0F80 to 0x0F9F */
- "o", "no", "b", "nb", "z", "nz", "be", "a",
- "s", "ns", "pe", "po", "l", "ge", "le", "g",
-};
-
-PRIVATE char *str_98[] =
-{
- "cbw", "cwd", "call\t", "wait", "pushf", "popf", "sahf", "lahf",
- "cwde", "cdq", "call\t", "wait", "pushfd", "popfd", "sahf", "lahf",
-};
-
-PRIVATE char *str_a0[] =
-{
- movtab, movtab, movtab, movtab, "movsb", "movs", "cmpsb", "cmps",
-};
-
-PRIVATE char *str_a8[] =
-{
- "test\t", "test\t", "stosb", "stos", "lodsb", "lods", "scasb", "scas",
-};
-
-PRIVATE char *str_c0[] =
-{
- "", "", "ret\t", "ret", "les\t", "lds\t", movtab, movtab,
-};
-
-PRIVATE char *str_c8[] =
-{
- "enter\t", "leave", "retf\t", "retf", "int\t3", "int\t", "into", "iret",
-};
-
-PRIVATE char *str_d0[] =
-{
- "aam", "aad", "db\td6", "xlat",
-};
-
-PRIVATE char *sstr_d0[] =
-{
- "rol", "ror", "rcl", "rcr", "shl", "shr", fishy, "sar",
-};
-
-PRIVATE char *str_d8[] =
-{
- "fadd", "fmul", "fcom", "fcomp", "fsub", "fsubr", "fdiv", "fdivr",
- "fld", NULL, "fst", "fstp", "fldenv", "fldcw", "fstenv", "fstcw",
- "fiadd", "fimul", "ficom", "ficomp", "fisub", "fisubr", "fidiv", "fidivr",
- "fild", NULL, "fist", "fistp", NULL, "fld", NULL, "fstp",
- "fadd", "fmul", "fcom", "fcomp", "fsub", "fsubr", "fdiv", "fdivr",
- "fld", NULL, "fst", "fstp", "frstor", NULL, "fsave", "fstsw",
- "fiadd", "fimul", "ficom", "ficomp", "fisub", "fisubr", "fidiv", "fidivr",
- "fild", NULL, "fist", "fistp", "fbld", "fild", "fbstp", "fistp",
-};
-
-PRIVATE char *str1_d8[] =
-{
- "fadd", "fmul", "fcom", "fcomp", "fsub", "fsubr", "fdiv", "fdivr",
- "fld", "fxch", "\0\0", NULL, "\0\10", "\0\20", "\0\30", "\0\40",
- NULL, NULL, NULL, NULL, NULL, "\0\50", NULL, NULL,
- NULL, NULL, NULL, NULL, "\0\60", NULL, NULL, NULL,
- "fadd", "fmul", NULL, NULL, "fsubr", "fsub", "fdivr", "fdiv",
- "ffree", NULL, "fst", "fstp", "fucom", "fucomp", NULL, NULL,
- "faddp", "fmulp", NULL, "\0\70", "fsubrp", "fsubp", "fdivrp", "fdivp",
- NULL, NULL, NULL, NULL, "\0\100", NULL, NULL, NULL,
-};
-
-PRIVATE unsigned char size_d8[] =
-{
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 14-28, 2, 14-28, 2,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 0, 10, 0, 10,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 8, 8, 94-108, 0, 94-108, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 10, 8, 10, 8,
-};
-
-PRIVATE char *sstr_d8[] =
-{
- "fnop", NULL, NULL, NULL,			/* D9D0 */
- NULL, NULL, NULL, NULL,
- "fchs", "fabs", NULL, NULL,			/* D9E0 */
- "ftst", "fxam", NULL, NULL,
- "fld1", "fldl2t", "fldl2e", "fldpi",		/* D9E8 */
- "fldlg2", "fldln2", "fldz", NULL,
- "f2xm1", "fyl2x", "fptan", "fpatan",		/* D9F0 */
- "fxtract", "fprem1", "fdecstp", "fincstp",
- "fprem", "fyl2xp1", "fsqrt", "fsincos",	/* D9F8 */
- "frndint", "fscale", "fsin", "fcos",
- NULL, "fucompp", NULL, NULL,			/* DAE8 */
- NULL, NULL, NULL, NULL,
- "feni", "fdisi", "fclex", "finit",		/* DBE0 */
- "fsetpm", NULL, NULL, NULL,
- NULL, "fcompp", NULL, NULL,			/* DED8 */
- NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL,			/* DFE0 */
- "fstsw\tax", NULL, NULL, NULL,
-};
-
-PRIVATE char *str_e0[] =
-{
- "loopnz\t", "loopz\t", "loop\t", "jcxz\t",
- "in\t", "in\t", "out\t", "out\t",
-};
-
-PRIVATE char *str_e8[] =
-{
- "call\t", "jmp\t", "jmp\t", "jmp\t",
- "in\t", "in\t", "out\t", "out\t",
-};
-
-PRIVATE char *str_f0[] =
-{
- "lock\t", "db\tf1", "repnz\t", "repz\t",
- "hlt", "cmc",
- /* other 2 from sstr_f0 */
-};
-
-PRIVATE char *sstr_f0[] =
-{
- "test\t", fishy, "not\t", "neg\t",
- "mul\t", "imul\t", "div\t", "idiv\t",
-};
-
-PRIVATE char *str_f8[] =
-{
- "clc", "stc", "cli", "sti",
- "cld", "std",
- /* other 2 from sstr_f8 */
-};
-
-PRIVATE char *sstr_f8[] =
-{
- "inc\t", "dec\t", "call\t", "call\tfar ",
- "jmp\t", "jmp\tfar ", "push\t", "???\t",
-};
-
-PRIVATE int data_seg;		/* data segment (munged name for asld) */
-PRIVATE unsigned hasize;	/* half address size in bits */
-PRIVATE unsigned hdefsize;
-PRIVATE unsigned hosize;	/* half operand size in bits */
-				/* for easy index into reg tables */
-PRIVATE opcode_pt mod;
-PRIVATE off_t offtable[2];
-PRIVATE off_t *offptr;
-PRIVATE off_t *off1ptr;
-PRIVATE opcode_pt reg;
-PRIVATE opcode_pt rm;
-
-PRIVATE su8_pt get8s()
-{
-    u8_t got;
-
-    if ((got = get8()) > MAX_SIGNED_CHAR)
-	got -= (MAX_UNSIGNED_CHAR + 1);
-    return got;
-}
-
-PRIVATE void getmodregrm()
-{
-    opcode_pt modregrm;
-    
-    modregrm = get8();
-    mod = modregrm & MOD_MASK;
-    reg = (modregrm & REG_MASK) >> REG_SHIFT;
-    rm = (modregrm & RM_MASK) >> RM_SHIFT;
-}
-
-PRIVATE void i_00_to_3f(opc)
-opcode_pt opc;
-{
-    opcode_pt sub;
-    
-    if (opc == 15)
-	pagef();
-    else if ((sub = opc & 7) >= 6)
-    {
-	outustr((sstr_00_to_3f - 6)[((opc >> 2) & 0x0E) + sub]);
-	if (!(opc & 1))
-	    data_seg = opc;
-    }
-    else
-    {
-	oututstr(str_00_to_3f[(opc >> 3) & 7]);
-	if (sub == 4)
-	{
-	    outustr(genreg[0]);
-	    outcomma();
-	    Ib();
-	}
-	else if (sub == 5)
-	{
-	    outax();
-	    outcomma();
-	    Iv();
-	}
-	else
-	    outad(sub);
-    }
-}
-
-PRIVATE void i_40_to_5f(opc)
-opcode_pt opc;
-{
-    outustr(str_40_to_5f[(opc >> 3) & 3]);
-    outustr(genreg[hosize + (opc & 7)]);
-}
-
-PRIVATE void i_60_to_6f(opc)
-opcode_pt opc;
-{
-/* most for 386, some for 286 */
-
-    outustr((str_60_to_6f - 0x60)[opc]);
-    switch (opc)
-    {
-    case 0x60:
-    case 0x61:
-	if (hosize == 16)
-	    outwsize();
-	break;
-    case 0x62:
-	GvMa();
-	break;
-    case 0x63:
-	EwRw();
-	break;
-    case 0x64:
-    case 0x65:
-	data_seg = opc;
-	break;
-    case 0x66:
-	hosize = (16 + 8) - hdefsize;
-	break;
-    case 0x67:
-	hasize = (16 + 8) - hdefsize;
-	break;
-    case 0x68:
-	outword();
-	Iv();
-	break;
-    case 0x6A:
-	outword();
-	outimmed(SIGNBIT | WORDBIT);
-	break;
-    case 0x69:
-	GvEv();
-	outcomma();
-	Iv();
-	break;
-    case 0x6B:
-	GvEv();
-	outcomma();
-	outimmed(SIGNBIT | WORDBIT);
-	break;
-    case 0x6D:
-    case 0x6F:
-	outwsize();
-	break;
-    }
-}
-
-PRIVATE void i_70_to_7f(opc)
-opcode_pt opc;
-{
-    outustr("j");
-    oututstr((str_flags - 0x70)[opc]);
-    Jb();
-}
-
-PRIVATE void i_80(opc)
-opcode_pt opc;
-{
-    if (opc >= 4)
-    {
-	outustr(opc >= 6 ? "xchg\t" : "test\t");
-	outad(opc);
-    }
-    else
-    {
-	getmodregrm();
-	oututstr(str_00_to_3f[reg]);
-	outbwptr(opc);
-	outea(opc);
-	outcomma();
-	outimmed(opc);
-#ifdef SIGNED_LOGICALS
-	if (opc & SIGNBIT && (reg == 1 || reg == 4 || reg == 6))
-	    /* and, or and xor with signe extension are not documented in some
-	     * 8086 and 80286 manuals, but make sense and work
-	     */
-	    outfishy();
-#endif
-    }
-}
-
-PRIVATE void i_88(opc)
-opcode_pt opc;
-{
-    if (opc < 4)
-    {
-	outustr(movtab);
-	outad(opc);
-    }
-    else if (opc == 5)
-    {
-	oututstr("lea");
-	GvM();
-    }
-    else if (opc == 7)
-    {
-	oututstr("pop");
-	getmodregrm();
-	outwptr();
-	Ev();
-	if (reg != 0)
-	    outfishy();
-    }
-    else
-    {
-	getmodregrm();
-	outustr(movtab);
-	if (!(opc & TOREGBIT))
-	{
-	    Ev();
-	    outcomma();
-	}
-	outustr(segreg[reg]);
-	if (opc & TOREGBIT)
-	{
-	    outcomma();
-	    Ev();
-	}
-    }
-}
-
-PRIVATE void i_90(opc)
-opcode_pt opc;
-{
-    if (opc == 0)
-	outustr("nop");
-    else
-    {
-	outustr("xchg\t");
-	outax();
-	outcomma();
-	outustr(genreg[hosize + opc]);
-    }
-}
-
-PRIVATE void i_98(opc)
-opcode_pt opc;
-{
-    outustr((str_98 - 8)[opc + hosize]);
-    if (opc == 2)
-	outsegpc();
-}
-
-PRIVATE void i_a0(opc)
-opcode_pt opc;
-{
-    outustr(str_a0[opc]);
-    if (opc < 4)
-    {
-	mod = MEM0_MOD;		/* fake */
-	reg = 0;		/* fake ax */
-	if (hasize == 16)
-	    rm = 5;		/* fake [d16] */
-	else
-	    rm = 6;		/* fake [d32] */
-	outad1(opc ^ TOREGBIT);
-    }
-    else if (opc & 1)
-	outwsize();
-}
-
-PRIVATE void i_a8(opc)
-opcode_pt opc;
-{
-    outustr(str_a8[opc]);
-    if (opc < 2)
-    {
-	outalorx(opc);
-	outcomma();
-	outimmed(opc);
-    }
-    else if (opc & 1)
-	outwsize();
-}
-
-PRIVATE void i_b0(opc)
-opcode_pt opc;
-{
-    outustr(movtab);
-    outustr(genreg[opc]);
-    outcomma();
-    Ib();
-}
-
-PRIVATE void i_b8(opc)
-opcode_pt opc;
-{
-    outustr(movtab);
-    outustr(genreg[hosize + opc]);
-    outcomma();
-    Iv();
-}
-
-PRIVATE void i_c0(opc)
-opcode_pt opc;
-{
-    outustr(str_c0[opc]);
-    if (opc >= 6)
-    {
-	getmodregrm();
-	outbwptr(opc);
-	outea(opc);
-	outcomma();
-	outimmed(opc & WORDBIT);
-	if (reg != 0)
-	    /* not completely decoded (like DEBUG) */
-	    outfishy();
-    }
-    else if (opc >= 4)
-	GvMp();
-    else if (opc == 2)
-	Iv();
-    else if (opc < 2)
-	shift(opc);
-}
-
-PRIVATE void i_c8(opc)
-opcode_pt opc;
-{
-    outustr(str_c8[opc]);
-    if (opc == 0)
-    {
-	Iw();
-	outcomma();
-	Ib();
-    }
-    if (opc == 2)
-	Iv();
-    else if (opc == 5)
-	Ib();
-    else if (opc == 7 && hosize == 16)
-	outwsize();
-}
-
-PRIVATE void i_d0(opc)
-opcode_pt opc;
-{
-    opcode_pt aabyte;
-
-    if (opc < 4)
-	shift(opc | 0xD0);
-    else
-    {
-	outustr((str_d0 - 4)[opc]);
-	if (opc < 6 && (aabyte = get8()) != 0x0A)
-	{
-	    outtab();
-	    outh8(aabyte);
-	    outfishy();
-	}
-    }
-}
-
-PRIVATE void i_d8(opc)
-opcode_pt opc;
-{
-    opcode_pt esc;
-    char *str;
-
-    getmodregrm();
-    esc = (opc << 3) | reg;
-    if ((str = (mod == REG_MOD ? str1_d8 : str_d8)[esc]) == NULL)
-    {
-escape:
-	oututstr("esc");
-	outh8(esc);
-	outcomma();
-	outea(0);
-	return;
-    }
-    if (*str == 0)
-    {
-	str = sstr_d8[str[1] + rm];
-	if (str == NULL)
-	    goto escape;
-	outustr(str);
-	return;
-    }
-    outustr(str);
-    outtab(); 
-    if (mod == REG_MOD)
-    {
-	if (opc == 0 && reg != 2 && reg != 3)
-	    outustr("st,");
-	outf1();
-	if (opc == 4 || opc == 6)
-	    outustr(",st");
-	return; 
-    }
-    switch(size_d8[esc])
-    {
-    case 4:
-	outustr("d");
-    case 2:
-	outwptr();
-	break;
-    case 8:
-	outustr("q");
-	outwptr();
-	break;
-    case 10:
-	outustr("t");
-	outbptr();
-	break;
-    }
-    outea(opc);
-}
-
-PRIVATE void i_e0(opc)
-opcode_pt opc;
-{
-    outustr(str_e0[opc]);
-    if (opc < 4)
-	Jb();
-    else if (opc < 6)
-    {
-	outalorx(opc);
-	outcomma();
-	Ib();
-    }
-    else
-    {
-	Ib();
-	outcomma();
-	outalorx(opc);
-    }
-}
-
-PRIVATE void i_e8(opc)
-opcode_pt opc;
-{
-    outustr(str_e8[opc]);
-    if (opc < 2)
-	Jv();
-    else if (opc == 2)
-	outsegpc();
-    else if (opc == 3)
-	Jb();
-    else
-    {
-	if (opc & TOREGBIT)
-	{
-	    outustr(genreg[10]);
-	    outcomma();
-	    outalorx(opc);
-	}
-	else
-	{
-	    outalorx(opc);
-	    outcomma();
-	    outustr(genreg[10]);
-	}
-    }
-}
-
-PRIVATE void i_f0(opc)
-opcode_pt opc;
-{
-    if (opc < 6)
-	outustr(str_f0[opc]);
-    else
-    {
-	getmodregrm();
-	outustr(sstr_f0[reg]);
-	outbwptr(opc);
-	outea(opc);
-	if (reg == 0)
-	{
-	    outcomma();
-	    outimmed(opc & WORDBIT);
-	}
-    }
-}
-
-PRIVATE void i_f8(opc)
-opcode_pt opc;
-{
-    if (opc < 6)
-	outustr(str_f8[opc]);
-    else
-    {
-	getmodregrm();
-	if (opc == 6 && reg >= 2)
-	    outustr("fishy\t");
-	else
-	    outustr(sstr_f8[reg]);
-	outbwptr(opc);
-	outea(opc);
-    }
-}
-
-PRIVATE void outad(opc)
-opcode_pt opc;
-{
-    getmodregrm();
-    outad1(opc);
-}
-
-PRIVATE void outad1(opc)
-opcode_pt opc;
-{
-    if (!(opc & TOREGBIT))
-    {
-	outea(opc);
-	outcomma();
-    }
-    if (opc & WORDBIT)
-	Gv1();
-    else
-	outustr(genreg[reg]);
-    if (opc & TOREGBIT)
-    {
-	outcomma();
-	outea(opc);
-    }
-}
-
-PRIVATE void outalorx(opc)
-opcode_pt opc;
-{
-    if (opc & WORDBIT)
-	outax();
-    else
-	outustr(genreg[0]);
-}
-
-PRIVATE void outax()
-{
-    outustr(genreg[hosize]);
-}
-
-PRIVATE void outbptr()
-{
-    outustr("byte ptr ");
-}
-
-PRIVATE void outbwptr(opc)
-opcode_pt opc;
-{
-    if (mod != REG_MOD)
-    {
-	if (opc & WORDBIT)
-	    outwptr();
-	else
-	    outbptr();
-    }
-}
-
-PRIVATE void outea(wordflags)
-opcode_pt wordflags;
-{
-    reg_pt base;
-    reg_pt index;
-    opcode_pt ss;
-    opcode_pt ssindexbase;
-
-    if (mod == REG_MOD)
-	outustr(genreg[hosize * (wordflags & WORDBIT) + rm]);
-    else
-    {
-	outbyte(LINDIRECT);
-	if (hasize == 16)
-	{
-	    if (rm == 4)
-	    {
-		base = (ssindexbase = get8()) & BASE_MASK;
-		if (mod == MEM0_MOD && base == 5)
-		    outgetaddr();
-		else
-		    outustr((genreg + 16)[base]);
-		ss = (ssindexbase & SS_MASK) >> SS_SHIFT;
-		if ((index = (ssindexbase & INDEX_MASK) >> INDEX_SHIFT) != 4)
-		{
-		    outbyte('+');
-		    outustr((genreg + 16)[index]);
-		    outstr("\0\0\0*2\0*4\0*8\0" + (3 * ss));
-		}
-	    }
-	    else if (mod == MEM0_MOD && rm == 5)
-		outgetaddr();
-	    else
-		outustr((genreg + 16)[rm]);
-	}
-	else if (mod == MEM0_MOD && rm == 6)
-	    outgetaddr();
-	else
-	    outustr(indreg[rm]);
-	if (mod == MEM1_MOD)
-	    /* fake sign extension to get +- */
-	    outimmed(SIGNBIT | WORDBIT);
-	else if (mod == MEM2_MOD)
-	{
-	    outbyte('+');
-#if (_WORD_SIZE == 4)
-	    out32offset();
-#else
-	    outgetaddr();
-#endif
-	}
-	outbyte(RINDIRECT);
-	if (hasize == 16 && rm == 4 && index == 4 && ss != 0)
-	    outfishy();
-    }
-}
-
-PRIVATE void outf1()
-{
-    outustr("st(");
-    outbyte((int) (rm + '0'));
-    outbyte(')');
-}
-
-#if (_WORD_SIZE == 4)
-
-PRIVATE void out32offset()
-{
-    off_t off;
-
-    if (hasize == 16)
-	off = get32();
-    else
-	outfishy();
-
-    outh32(off);
-}
-#endif
-
-PRIVATE void outfishy()
-{
-    outustr("\t???");
-}
-
-PRIVATE void outgetaddr()
-{
-    off_t off;
-
-    if (hasize == 16)
-	off = get32();
-    else
-	off = get16();
-
-    if ( finds_data(off,data_seg) )
-  	*offptr++ = off;
-    else if (hasize == 16)
-	outh32(off);
-    else
-	outh16((u16_t) off);
-}
-
-PRIVATE void outimmed(signwordflag)
-opcode_pt signwordflag;
-{
-    su8_pt byte;
-
-    if (signwordflag & WORDBIT)
-    {
-	if (signwordflag & SIGNBIT)
-	{
-	    if ((byte = get8s()) < 0)
-	    {
-		outbyte('-');
-		byte = -byte;
-	    }
-	    else
-		outbyte('+');
-	    outh8((u8_t) byte);
-	}
-	else
-	    Iv();
-    }
-    else
-	Ib();
-}
-
-PRIVATE void outpc(pc)
-off_t pc;
-{
-    if (hosize == 8)
-	pc = (u16_t) pc;
-
-    if ( finds_pc(pc) )
-	*offptr++ = pc;
-    else if (hosize == 16)
-	outh32(pc);
-    else
-	outh16((u16_t) pc);
-}
-
-PRIVATE void outsegpc()
-{
-    off_t oldbase;
-    off_t pc;
-
-    if (hosize == 16)
-	pc = get32();
-    else
-	pc = get16();
-    oldbase = uptr.base;
-    outh16((u16_t) (uptr.base = get16()));	/* fake seg for lookup of pc */
-			/* TODO - convert to offset in protected mode */
-    outbyte(':');
-    outpc(pc);
-    uptr.base = oldbase;
-}
-
-PRIVATE void oututstr(s)
-char *s;
-{
-    outustr(s);
-    outtab();
-}
-
-PRIVATE void outword()
-{
-    outustr("dword " + ((16 - hosize) >> 3));
-}
-
-PRIVATE void outwptr()
-{
-    outword();
-    outustr("ptr ");
-}
-
-PRIVATE void outwsize()
-{
-    if (hosize == 16)
-	outustr("d");
-    else
-	outustr("w");
-}
-
-PRIVATE void pagef()
-{
-    opcode_pt opc;
-    int regbad;
-
-    if ((opc = get8()) <= 1 || opc == 0xBA)
-    {
-	if (opc == 0xBA)
-	    opc = 16;
-	else
-	    opc *= 8;
-	getmodregrm();
-	outustr(ssstr_0f[opc += reg]);
-	if (opc < 6 || opc == 12 || opc == 14)
-	    Ew();
-	else if (opc >= 8 && opc < 13)
-	    Ms();
-	else if (opc >= 20)
-	{
-	    outbwptr(WORDBIT);
-	    EvIb();
-	}
-    }
-    else if (opc < 4)
-    {
-	oututstr("lar\0lsl" + 4 * (opc - 2));
-	GvEw();
-    }
-    else if (opc == 5)
-    {
-	outustr("loadall");
-	outfishy();
-    }
-    else if (opc == 6)
-	outustr("clts");
-    else if (opc < 0x20)
-	outstr(fishy);
-    else if (opc < 0x27 && opc != 0x25)
-    {
-	outustr(movtab);
-	getmodregrm();
-	hosize = 16;
-	if (!(opc & TOREGBIT))
-	{
-	    Ev();		/* Rd() since hosize is 16 */
-	    outcomma();
-	}
-	regbad = FALSE;
-	if (opc & 1)
-	{
-	    outustr("dr");
-	    if (reg == 4 || reg == 5)
-		regbad = TRUE;
-	}
-	else if (opc < 0x24)
-	{
-	    outustr("cr");
-	    if (reg >= 4 || reg == 1)
-		regbad = TRUE;
-	}
-	else
-	{
-	    outustr("tr");
-	    if (reg < 6)
-		regbad = TRUE;
-	}
-	outbyte((int) (reg + '0'));
-	if (opc & TOREGBIT)
-	{
-	    outcomma();
-	    Ev();
-	}
-	if (regbad || mod != REG_MOD)
-	    outfishy();
-    }
-    else if (opc < 0x80)
-	outstr(fishy);
-    else if (opc < 0x90)
-    {
-	outustr("j");
-	oututstr((str_flags - 0x80)[opc]);
-	Jv();
-    }
-    else if (opc < 0xA0)
-    {
-	outustr("set");
-	oututstr((str_flags - 0x90)[opc]);
-	getmodregrm();
-	outbwptr(0);
-	Eb();
-    }
-    else if (opc < 0xC0)
-    {
-	outustr((sstr_0f - 0xA0)[opc]);
-	switch (opc)
-	{
-	case 0xA3:
-	case 0xAB:
-	case 0xB3:
-	case 0xBB:
-	    EvGv();
-	    break;
-	case 0xA4:
-	case 0xAC:
-	    EvGv();
-	    outcomma();
-	    Ib();
-	    break;
-	case 0xA5:
-	case 0xAD:
-	    EvGv();
-	    outcomma();
-	    CL();
-	    break;
-	case 0xAF:
-	case 0xBC:
-	case 0xBD:
-	    GvEv();
-	    break;
-	case 0xB2:
-	case 0xB4:
-	case 0xB5:
-	    GvMp();
-	    break;
-	case 0xB6:
-	case 0xBE:
-	    Gv();
-	    outcomma();
-	    outbwptr(opc);
-	    Eb();
-	    break;
-	case 0xB7:
-	case 0xBF:
-	    Gv();
-	    outcomma();
-	    hosize = 8;		/* done in Ew(), but too late */
-	    outbwptr(opc);
-	    Ew();
-	    break;
-	}
-    }
-    else
-	outstr(fishy);
-}
-
-PRIVATE int puti()
-{
-    static int hadprefix;
-    opcode_pt opcode;
-
-more:
-    offptr = offtable;
-    opcode = get8();
-    if (!hadprefix)
-    {
-	data_seg = DSEG;
-	hdefsize = 8;
-	if (bits32)
-	    hdefsize = 16;
-	hosize =
-	    hasize = hdefsize;
-    }
-    (*optable[opcode >> 3])(opcode < 0x80 ? opcode : opcode & 7);
-    if (offptr > offtable)
-    {
-	if (stringtab() >= 31)
-	{
-	    outspace();
-	    outspace();
-	}
-	else
-	    while (stringtab() < 32)
-		outtab();
-	outbyte(';');
-	for (off1ptr = offtable; off1ptr < offptr; ++off1ptr)
-	{
-	    outspace();
-	    if (*off1ptr < 0x10000)
-		outh16((u16_t) *off1ptr);
-	    else
-		outh32(*off1ptr);
-	}
-	offptr = offtable;
-    }
-    if ((opcode & 0xE7) == 0x26 ||
-	opcode >= 0x64 && opcode < 0x68 ||
-	opcode == 0xF0 || opcode == 0xF2 || opcode == 0xF3)
-	/* not finished instruction for 0x26, 0x2E, 0x36, 0x3E seg overrides
-	 * and 0x64, 0x65 386 seg overrides
-	 * and 0x66, 0x67 386 size prefixes
-	 * and 0xF0 lock, 0xF2 repne, 0xF3 rep
-	 */
-    {
-	hadprefix = TRUE;
-	goto more;		/* TODO - print prefixes better */
-	return FALSE;
-    }
-    hadprefix = FALSE;
-    return TRUE;
-}
-
-PRIVATE void shift(opc)
-opcode_pt opc;
-{
-    getmodregrm();
-    oututstr(sstr_d0[reg]);
-    outbwptr(opc);
-    outea(opc);
-    outcomma();
-    if (opc < 0xD0)
-	Ib();
-    else if (opc & 2)
-	CL();
-    else
-	outbyte('1');
-}
-
-PRIVATE void checkmemory()
-{
-    if (mod == REG_MOD)
-	outfishy();
-}
-
-PRIVATE void CL()
-{
-    outustr(genreg[1]);
-}
-
-PRIVATE void Eb()
-{
-    outea(0);
-}
-
-PRIVATE void Ev()
-{
-    outea(WORDBIT);
-}
-
-PRIVATE void EvGv()
-{
-    getmodregrm();
-    Ev();
-    outcomma();
-    Gv1();
-}
-
-PRIVATE void EvIb()
-{
-    Ev();
-    outcomma();
-    Ib();
-}
-
-PRIVATE void Ew()
-{
-    hosize = 8;
-    Ev();
-}
-
-PRIVATE void EwRw()
-{
-    hosize = 8;
-    EvGv();
-}
-
-PRIVATE void Gv()
-{
-    getmodregrm();
-    Gv1();
-}
-
-PRIVATE void Gv1()
-{
-    outustr(genreg[hosize + reg]);
-}
-
-PRIVATE void GvEv()
-{
-    Gv();
-    outcomma();
-    Ev();
-}
-
-PRIVATE void GvEw()
-{
-    Gv();
-    outcomma();
-    Ew();
-}
-
-PRIVATE void GvM()
-{
-    GvEv();
-    checkmemory();
-}
-
-PRIVATE void GvMa()
-{
-    GvM();
-}
-
-PRIVATE void GvMp()
-{
-    GvM();
-}
-
-PRIVATE void Ib()
-{
-    outh8(get8());
-}
-
-PRIVATE void Iw()
-{
-    outh16(get16());
-}
-
-PRIVATE void Iv()
-{
-    if (hosize == 16)
-	outh32(get32());
-    else
-	Iw();
-}
-
-PRIVATE void Jb()
-{
-    off_t pcjump;
-
-    pcjump = get8s();
-    outpc(pcjump + uptr.off);
-}
-
-PRIVATE void Jv()
-{
-    off_t pcjump;
-
-    if (hosize == 16)
-	pcjump = get32();
-    else
-	pcjump = (su16_t) get16();
-    outpc(pcjump + uptr.off);
-}
-
-PRIVATE void Ms()
-{
-    Ev();
-    checkmemory();
-}
-
-/********************* DASM ******************************/
-
-PUBLIC long dasm( addr, count, symflg )
-long addr;
-int count;
-int symflg;
-{
-#if (_WORD_SIZE == 4)
-	bits32 = TRUE;		/* Set mode */
-#else
-	bits32 = FALSE;
-#endif
-	uptr.off = addr;
-	uptr.base = 0;		/* not known */
-	while ( count-- != 0 && show1instruction() )
-		;
-}
-
-
-PRIVATE int show1instruction()
-{
-    register int column;
-    int idone;
-    static char line[81];
-    int maxcol;
-    struct address_s newuptr;
-    struct address_s olduptr;
-
-    outbyte('\r');
-    do
-    {
-	if ( text_symbol(uptr.off) ) {
-	    outbyte(':');
-	    outbyte('\n');
-	}
-	olduptr = uptr;
-	openstring(line);
-	idone = puti();
-	line[stringpos()] = 0;
-	closestring();
-	newuptr = uptr;
-	uptr = olduptr;
-	column = outssegaddr(&uptr);
-	while (uptr.off != newuptr.off)
-	{
-	    outh8(get8());
-	    column += 2;
-	}
-	maxcol = bits32 ? 24 : 16;
-	while (column < maxcol)
-	{
-	    outtab();
-	    column += 8;
-	}
-	outtab();
-	outstr(line);
-	outbyte('\n');
-    }
-    while (!idone);		/* eat all prefixes */
-    return TRUE;
-}
-
-
-PRIVATE u8_t get8()
-{
-/* get 8 bits current instruction pointer and advance pointer */
-
-    u8_t temp;
-
-    temp = peek_byte(uptr.off + uptr.base);
-    ++uptr.off;
-    return temp;
-}
-
-PRIVATE u16_t get16()
-{
-/* get 16 bits from current instruction pointer and advance pointer */
-
-    u16_t temp;
-
-    temp = peek_word(uptr.off + uptr.base);
-    uptr.off += 2;
-    return temp;
-}
-
-PRIVATE u32_t get32()
-{
-/* get 32 bits from current instruction pointer and advance pointer */
-
-    u32_t temp;
-
-    temp = peek_dword(uptr.off + uptr.base);
-    uptr.off += 4;
-    return temp;
-}
-
-
-PRIVATE int outsegaddr(addr)
-struct address_s *addr;
-{
-/* print segmented address */
-
-    int bytes_printed;
-
-    bytes_printed = 2;
-	bytes_printed = outsegreg(addr->base);
-    if (bytes_printed > 4)
-	outbyte('+');
-    else
-	outbyte(':');
-    ++bytes_printed;
-    if (addr->off >= 0x10000)
-    {
-	outh32(addr->off);
-	return bytes_printed + 8;
-    }
-    outh16((u16_t) addr->off);
-    return bytes_printed + 4;
-}
-
-PRIVATE int outssegaddr(addr)
-struct address_s *addr;
-{
-/* print 32 bit segmented address and 2 spaces */
-
-    int bytes_printed;
-
-    bytes_printed = outsegaddr(addr);
-    outspace();
-    outspace();
-    return bytes_printed + 2;
-}
-
-PRIVATE u8_t peek_byte(addr)
-off_t addr;
-{
-    return (u8_t) peek_dword(addr) & 0xFF; /* 8 bits only */
-}
-
-PRIVATE u16_t peek_word(addr)
-off_t addr;
-{
-    return (u16_t) peek_dword(addr);
-}
Index: trunk/minix/commands/mdb/mdbexp.c
===================================================================
--- trunk/minix/commands/mdb/mdbexp.c	(revision 9)
+++ 	(revision )
@@ -1,157 +1,0 @@
-/*
- * mdbexp.c - MINIX expresion parser
- *
- * Written by Bruce D. Szablak
- *
- * This free software is provided for non-commerical use. No warrantee
- * of fitness for any use is implied. You get what you pay for. Anyone
- * may make modifications and distribute them, but please keep this header
- * in the distribution.
- */
-
-#include "mdb.h"
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "proto.h"
-
-FORWARD _PROTOTYPE(long value , (char *s , char **s_p , int *seg_p ));
-FORWARD _PROTOTYPE(long lookup , (char *s , char **s_p , int *seg_p ));
-
-#define idchar(c) (isalpha(c) || isdigit(c) || (c) == '_')
-
-/* 
- * Get an expression for mdb
- */
-PUBLIC char *getexp(buf, exp_p, seg_p)
-char *buf;
-int *seg_p;
-long *exp_p;
-{
-  long v = 0L;
-
-  buf = skip(buf);
-  if ((isalpha(*buf) && (isspace(buf[1]) || buf[1] == ';')) 
-      || *buf == '\n'
-      || *buf == ';'
-      || *buf == '/'
-      || *buf == '!'
-      || *buf == '?'
-      || *buf == '@'
-      || *buf == '#') {
-	*exp_p = 0L;
-	return buf;
-  }
-  v = value(buf, &buf, seg_p);
-  buf = skip(buf);
-  if (*buf == '+')
-	v += value(skip(buf + 1), &buf, seg_p);
-  else if (*buf == '-')
-	v -= value(skip(buf + 1), &buf, seg_p);
-  *exp_p = v;
-  return skip(buf);
-}
-
-/* 
- * Get value 
- *
- * 	\c 	escaped characters
- * 	digits	number
- * 	$xx	registers 
- *	\n	0L
- *	then calls lookup for symbols
- */
-PRIVATE long value(s, s_p, seg_p)
-char *s, **s_p;
-int *seg_p;
-{
-  long k;
-
-  if (*s == '\'') {		/* handle character constants here */
-	*s_p = s + 2;
-	return s[1];
-  }
-  if (*s == '-' || isdigit(*s))
-	return strtol(s, s_p, 0);
-  if (*s == '$') {
-	k = reg_addr(s + 1);
-	*s_p = s + 3;
-	return get_reg(curpid, k);
-	k = reg_addr(s + 1);
-	*s_p = s + 3;
-	return get_reg(curpid, k);
-  }
-  if (*s == '\n') {
-	*s_p = s + 1;
-	return 0L;
-  }
-  return lookup(s, s_p, seg_p);
-}
-
-/* 
- * Lookup symbol - return value
- * Handle special cases: _start T: D: S: 
- * then call symbolvalue()
- */
-PRIVATE long lookup(s, s_p, seg_p)
-char *s, **s_p;
-int *seg_p;
-{
-  long value;
-  char c;
-  int l;
-
-  for (l = 1; idchar(s[l]); ++l) {}
-  c = s[l];
-  s[l] = 0;
-
-  if (strcmp("_start", s) == 0) {
-	*seg_p = T;
-	if (c == ':') c = '+';
-	*(*s_p = s + 6) = c;
-	return st_addr;
-  }
-  if (strcmp("T", s) == 0) {
-	*seg_p = T;
-	if (c == ':') c = '+';
-	*(*s_p = s + 1) = c;
-	return st_addr;
-  }
-  if (strcmp("D", s) == 0) {
-	*seg_p = D;
-	if (c == ':') c = '+';
-	*(*s_p = s + 1) = c;
-	return sd_addr;
-  }
-  if (strcmp("S", s) == 0) {
-	*seg_p = S;
-	if (c == ':') c = '+';
-	*(*s_p = s + 1) = c;
-	return sk_addr;
-  }
-
-  if ((value = symbolvalue(s, TRUE)) != 0L) {
-	*seg_p = T;
-	*(*s_p = s + l) = c;
-	return value;
-  }
-
-  if ((value = symbolvalue(s, FALSE)) != 0L) {
-	*seg_p = D;
-	*(*s_p = s + l) = c;
-	return value;
-  }
-
-  Printf("%s: ", s);
-  mdb_error("symbol not found\n");
-}
-
-/* Skip spaces */
-PUBLIC char *skip(s)
-register char *s;
-{
-  while (isspace(*s)) ++s;
-  return *s ? s : s - 1;
-}
-
Index: trunk/minix/commands/mdb/misc.c
===================================================================
--- trunk/minix/commands/mdb/misc.c	(revision 9)
+++ 	(revision )
@@ -1,289 +1,0 @@
-/* 
- *  misc.c for mdb
- */
-
-#include "mdb.h"
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#define ptrace mdbtrace
-#include <sys/ptrace.h>
-#include "proto.h"
-
-FORWARD _PROTOTYPE( void pr_ascii , (long val , int size ));
-
-/* Print ascii */
-PRIVATE void pr_ascii(val, size)
-long val;
-int size;
-{
-  int i;
-  int v;
-  int sh;
-
-#ifdef	BYTES_SWAPPED
-  sh = 8 * size;
-#else
-  sh = 0;
-#endif
-
-  for (i = 0; i < size; i++) {
-	v = (int) (val >> sh) & 0xFF;
-#ifdef	BYTES_SWAPPED
-	sh -= 8;
-#else
-	sh += 8;
-#endif
-	Printf(isprint(v) ? "%c" : "\\%03o", v);
-  }
-  Printf("\n");
-}
-
-/* Dump stack */
-PUBLIC void dump_stack(cnt)
-long cnt;
-{
-  vir_bytes v, vi;
-  long val, sp;
-  int num, size, nmode;
-
-  size = INTSIZE;		/* size of stack element */
-  num = (int) cnt;
-  if (num <= 0) num = 0;
-  if (num > sk_size) num = (int) sk_size / size;
-  nmode = num;			/* Save mode */
-
-  /* Get current SP */
-  sp = get_reg(curpid, reg_addr("sp"));
-
-  /* Starting address is top of stack seg -1 */
-  vi = (vir_bytes) sk_addr + (vir_bytes) sk_size - size;
-
-  /* Ending address */
-  v = (vir_bytes) end_addr;
-  if (nmode == 0) v = MAX(v, sp);
-
-  Printf("Stack Dump SP=%*lx\nAddr\tHex\tAscii\n", 2 * size, sp);
-  do {
-	val = (ptrace(T_GETDATA, curpid, (long) vi, 0L) >> SHIFT(size))
-								& MASK(size);
-	Printf("%*lx\t", 2 * ADDRSIZE, (vi >> SHIFT(ADDRSIZE))
-						       & MASK(ADDRSIZE));
-	Printf("%*lx\t", 2 * size, val);
-	pr_ascii(val, size);
-	num -= 1;
-	vi -= size;
-  } while (vi >= v && (nmode ? num > 0 : 1));
-
-}
-
-
-/* Get file size */ 
-PUBLIC off_t file_size(fd)
-int fd;
-{
-struct stat st;
-
-  if(fstat(fd,&st) <0 ) {
-	Printf("Cannot stat\n");
-	return 0L;
-  }
-  else
-	return st.st_size;
-}
-
-/* Print help page */
-PUBLIC void help_page()
-{
-  outstr("\nHelp for mdb. For more details, type 'command ?'\n");
-  outstr("!#\t- Shell escape / Set Variable or register\n");
-  outstr("Tt\t- Current call / Backtrace all\n");
-  outstr("/nsf\t- Display for n size s with format f\n");
-  outstr("Xx [n]\t- Disasm / & display reg for n instructions\n");
-  outstr("Rr a\t- Run / with arguments a\n");
-  outstr("Cc [n]\t- Continue with current signal / no signal n times\n");
-  outstr("Ii [n]\t- Single step with / no signal for n instructions\n");
-  outstr("Mm t n\t- Trace until / Stop when modified t type for n instructions\n");
-  outstr("k \t- Kill traced process\n");
-  outstr("Bb\t- Display / Set Break-pt\n");
-  outstr("Dd\t- Delete all / one break-points\n");
-  outstr("P\t- Toggle Paging\n");
-  outstr("Ll name\t- Log to file name / and to standard output\n");
-#ifdef  DEBUG
-  outstr("Vv\t- Version info / Toggle debug flag\n");
-#else
-  outstr("V\t- Version info\n");
-#endif
-  outstr("e [t]\t- List symbols for type t\n");
-  outstr("y\t- Print segment mappings\n");
-  outstr("s [n]\t- Dump stack for n words\n");
-#if	SYSCALLS_SUPPORT
-  outstr("z [a]\t- Trace syscalls with address a\n");
-#endif
-  outstr("? \t- Help - this screen\n");
-  outstr("@ file\t- Execute commands from file\n");
-  outstr("Qq\t- Quit / and kill traced process\n");
-#ifdef DEBUG
-  outstr("Usage: mdb -x debug-level [-Ll]logfile exec-file core-file @command-file\n");
-#else
-  outstr("Usage: mdb [-Ll]logfile exec-file core-file @command-file\n");
-#endif
-  outstr("       mdb [-fc] file\n");
-}
-
-PUBLIC void version_info()
-{
-	Printf("\nmdb version %s.%d for Minix", MDBVERSION, MDBBUILD );
-	Printf(" %s.%s",  OS_RELEASE, OS_VERSION);
-#ifdef MINIX_PC
-#ifdef __i386
-	Printf(" (32-bit)");
-#else
-	Printf(" (16-bit)");
-#endif
-#endif
-#ifdef MINIX_ST
-	Printf("-ST");
-#endif
-	Printf("\n");
-}
-
-/* Print help message on command */
-PUBLIC void help_on(h)
-int h;
-{
-
-  switch (h) {
-  case '/':	
-	outstr("<address> /nsf\t- Display for n items of size s with format f from address\n");
-	outstr("\t  n defaults to 1\n");
-	outstr("\t  s defaults to size of int\n");
-	outstr("\t    can be b for byte h for short l for long\n");
-	outstr("\t  f defaults to d for decimal\n");
-	outstr("\t    can be x X o d D c s or u as in printf\n");
-	outstr("\t    y treat value as address\n");
-	outstr("\t    i disasm\n");
-	break;
-  case '@':	
-	outstr("@ file\t- Execute commands from file\n");
-	break;
-  case '#':	
-	outstr("# <address> cs value\t- Set Variable(s) at address to value\n");
-	outstr("\t\t\t  for c count and size s\n");
- 	outstr("\t\t\t  b for byte h for short or l for long\n");
-	outstr("\t\t\t  Count or size must be specified\n");
-	outstr("# $xx value\t\t- Set register $xx to value\n");
-	break;
-  case 'C':	
-	outstr("C [n]\t- Continue with curent signal n times\n");
-	outstr("\t  n defaults to 1\n");
-	break;
-  case 'c':	
-	outstr("c [n]\t- Continue with no signal n times\n");
-	outstr("\t  n defaults to 1\n");
-	break;
-  case 'e':
-	outstr("e [t]\t- List symbols for type t\n");
-	break;
-  case 's':
-	outstr("s [n]\t- Dump stack for n words\n");
-	outstr("\t  n defaults to whole stack\n");
-	break;
-  case 'I':
-	outstr("I n\t- Single step with signal for n instructions n defaults to 1\n");
-	break;
-  case 'i':
-	outstr("i n\t- Single step with no signal for n instructions n defaults to 1\n");
-	break;
-  case 'M':
-  case 'm':
-	if ( h == 'M') 
-		outstr("<address> M t n\t- Trace until\n");
-	else
-		outstr("<address> m t n\t- Stop when\n");
-	outstr("\t\t<address> is modified t type for n instructions\n");
-	outstr("\t\tn defaults to 1\n");
-	outstr("\t\tb for byte h for short l for long defaults to size of int\n");
-	break;
-  case 'T':	
-	outstr("T\t- Display current call\n");
-	break;
-  case 't':
-	outstr("t\t- Backtrace all calls\n");
-	break;
-  case '!':
-	outstr("![command]\t- Shell escape or spawn command\n");
-	break;
-  case 'R':	
-	outstr("R\t- Run the exec-file\n");
-	break;
-  case 'r':
-	outstr("r [arguments]\t- Run the exec-file with arguments\n");
-	break;
-  case 'k':
-	outstr("k\t- Kill traced process\n");
-	break;
-  case 'B':
-	outstr("B\t- Display all the Break points\n");
-	break;
-  case 'b':
-	outstr("<address> b [commands]\t- Set Break-pt at address\n");
-	outstr("\t\t\t  commands will be executed by mdb at break-pt\n");
-	break;
-  case 'D':
-	outstr("D\t- Delete all break-points\n");
-	break;
-  case 'd':
-	outstr("<address> d\t- Delete one break-point at address\n");
-	break;
-  case 'q':
-	outstr("q\t- Quit mdb (and kill traced program)\n");
-	break;
-  case 'Q':
-	outstr("Q\t- Quit mdb immediately\n");
-	break;
-  case 'P':
-	outstr("P\t- Toggle Paging\n");
-	outstr("\t  Defaults is OFF\n");
-	break;
-  case 'L':
-	outstr("L name\t- Log to file name\n");
-	outstr("L\t- Reset output to standard output\n");
-	break;
-  case 'l':
-	outstr("l name\t- Log to file name and standard output\n");
-	outstr("l\t- Reset output to standard output\n");
-	outstr("\t  Defaults to none\n");
-	break;
-#ifdef  DEBUG
-  case 'v':
-	outstr("v\t- Toggle debug flag\n");
-	break;
-#endif
-  case 'V':
-	outstr("V\t- Print Version Information for mdb\n");
-	break;
-  case 'X':
-	outstr("<address> X [n] [offset]\t- Disasm for n instructions\n");
-	outstr("\t\t\t  Starting at address+offset\n");
-	break;
-  case 'x':
-	outstr("<address> x [n] offset\t- Disasm & display registers for n instructions\n");
-	outstr("\t\t\t  Starting at address+offset\n");
-	break;
-  case 'y':
-	outstr("y\t- Print segment mappings\n");
-	break;
-#if	SYSCALLS_SUPPORT
-  case 'z':
-	outstr("z [address]\t- Trace system calls using address\n");
-	outstr("\t\t  If the exec-file has symbols, mdb looks for __sendrec\n");
-	break;
-#endif
-  default:
-	Printf("No help on command '%c' is available\n",h);
-	break;
-  }
-}
-
Index: trunk/minix/commands/mdb/proto.h
===================================================================
--- trunk/minix/commands/mdb/proto.h	(revision 9)
+++ 	(revision )
@@ -1,105 +1,0 @@
-/* 
- * proto.h for mdb 
- */
-
-/* core.c */
-
-_PROTOTYPE( void prtmap, (void) );
-_PROTOTYPE( unsigned long core_init, (char *filename) );
-_PROTOTYPE( unsigned long file_init, (char *filename) );
-_PROTOTYPE( long read_core, (int req, long addr, long data) );
-
-/* mdb.c */ 
-
-_PROTOTYPE( void mdb_error, (char *s) );
-_PROTOTYPE( long breakpt , (long addr , char *cmd ));
-_PROTOTYPE( void tstart , (int req , int verbose , int val , int cnt ));
-
-/* io.c */
-
-_PROTOTYPE( char *get_cmd , (char *cbuf, int csize) );
-_PROTOTYPE( void openin , (char *s ));
-_PROTOTYPE( void logging, (int c, char *name) );
-_PROTOTYPE( void do_error, (char *message) );
-_PROTOTYPE( int Printf, (const char *format, ...));
-_PROTOTYPE( void outbyte, (int byte) );
-_PROTOTYPE( void outcomma, (void) );
-_PROTOTYPE( void outh8,  (unsigned num) );
-_PROTOTYPE( void outh16, (unsigned num) );
-_PROTOTYPE( void outh32, (unsigned num) );
-_PROTOTYPE( void outh4,  (unsigned num) );
-_PROTOTYPE( void outspace, (void) );
-_PROTOTYPE( void outstr, (char *s) );
-_PROTOTYPE( void outtab, (void) );
-_PROTOTYPE( void outustr, (char *s) );
-_PROTOTYPE( void closestring, (void) );
-_PROTOTYPE( int mytolower, (int ch) );
-_PROTOTYPE( void openstring, (char *string) );
-_PROTOTYPE( int stringpos, (void) );
-_PROTOTYPE( int stringtab, (void) );
-
-/* mdbdis86.c */
-
-_PROTOTYPE( long dasm, (long addr, int count, int symflg) );
-
-/* mdbexp.c */ 
-
-_PROTOTYPE( char *getexp, (char *buf, long *exp_p, int *seg_p) );
-_PROTOTYPE( char *skip, (char *s) );
-
-/* kernel.c */
-_PROTOTYPE( long get_reg, (int pid, long k) );
-_PROTOTYPE( void set_reg, (int pid, long k, long value) );
-_PROTOTYPE( long reg_addr, (char *s) );
-_PROTOTYPE( int disp_regs, (void) );
-_PROTOTYPE( int outsegreg, (off_t num) );
-_PROTOTYPE( void update , (void));
-_PROTOTYPE( void disp_maps , (void));
-
-/* misc.c */
-
-_PROTOTYPE( void dump_stack, (long count) );
-_PROTOTYPE( off_t file_size, (int fd) );
-_PROTOTYPE( void help_on, (int h) );
-_PROTOTYPE( void version_info, (void) );
-_PROTOTYPE( void help_page, (void) );
-
-#if EXTRA_SYMBOLS
-/* gnu_sym.c */
-_PROTOTYPE( void gnu_init, (char *filename) );
-_PROTOTYPE( long gnu_symbolvalue, (char *name, int is_text ) );
-_PROTOTYPE( void gnu_symbolic, (off_t value, int separator) );
-_PROTOTYPE( void gnu_listsym, (int tchar) );
-_PROTOTYPE( int gnu_text_symbol, (off_t value) );
-_PROTOTYPE( int gnu_finds_pc, (off_t pc) );
-_PROTOTYPE( int gnu_finds_data, (off_t off, int data_seg) );
-#endif /* EXTRA_SYMBOLS */
-
-/* sym.c */
-_PROTOTYPE( void syminit, (char *filename) );
-_PROTOTYPE( long symbolvalue, (char *name, int is_text ) );
-_PROTOTYPE( void printhex, (off_t v) );
-_PROTOTYPE( void symbolic, (off_t value, int separator) );
-_PROTOTYPE( void listsym, (char *cmd) );
-_PROTOTYPE( int text_symbol, (off_t value) );
-_PROTOTYPE( int finds_pc, (off_t pc) );
-_PROTOTYPE( int finds_data, (off_t off, int data_seg) );
-
-/* trace.c */
-_PROTOTYPE( long mdbtrace, (int req, int pid, long addr, long data) );
-_PROTOTYPE( u32_t peek_dword, (off_t addr));
-
-#if SYSCALLS_SUPPORT
-
-/* syscalls.c */
-_PROTOTYPE( void start_syscall, (long addr) );
-_PROTOTYPE( void do_syscall, (long addr) );
-
-/* decode.c */
-_PROTOTYPE( void decode_message, (unsigned addr) );
-_PROTOTYPE( void decode_result, (void) );
-
-/* ioctl.c */
-_PROTOTYPE( void decode_ioctl, (int sr, message *m) );
-
-#endif /* SYSCALLS_SUPPORT */
Index: trunk/minix/commands/mdb/ptrace.2
===================================================================
--- trunk/minix/commands/mdb/ptrace.2	(revision 9)
+++ 	(revision )
@@ -1,87 +1,0 @@
-.TH PTRACE 2
-.SH NAME
-ptrace \- ptrace system call. 
-.SH SYNOPSIS
-.ft B
-.nf
-.sp
-#include <sys/ptrace.h>
-
-long ptrace( int req, pid_t pid, long addr, long data)
-
-.fi
-.ft P
-.SH DESCRIPTION
-.sp
-Ptrace(2) is called with following arguments:
-.sp 
-.br
-req
-request
-.br
-pid 
-process id
-.br
-addr
-address
-.br
-data
-data
-.br
-.SH REQUESTS
-.sp
-.I
-T_STOP
-stop the process.
-.br
-.I
-T_OK
-enable tracing by parent for this process. 
-.br
-.I
-T_GETINS
-return value from instruction space 
-.br
-.I
-T_GETDATA
-return value from data space. 
-.br
-.I
-T_GETUSER
-return value from process table. See proc.h in kernel.
-.br
-.I
-T_SETINS
-set value from instruction space. 
-.br
-.I
-T_SETDATA
-set value from data space.
-.br
-.I
-T_SETUSER
-set value in process table. 
-.br
-.I
-T_RESUME
-resume execution.
-.br
-.I
-T_EXIT
-exit. Turn off tracing.
-.br
-.I
-T_STEP
-set trace bit to enable single step.
-.SH "SEE ALSO"
-.sp
-mdb(1)
-.SH DIAGNOSTICS
-.sp
-errno is set by ptrace().
-.SH FILES
-.sp
-/usr/src/kernel/proc.h for process table info. 
-
-
-
Index: trunk/minix/commands/mdb/sample
===================================================================
--- trunk/minix/commands/mdb/sample	(revision 9)
+++ 	(revision )
@@ -1,9 +1,0 @@
-r 10 
-y
-__sendrec b 
-B
-c
-x 2
-t
-q
-
Index: trunk/minix/commands/mdb/sym.c
===================================================================
--- trunk/minix/commands/mdb/sym.c	(revision 9)
+++ 	(revision )
@@ -1,546 +1,0 @@
-/* 
- * sym.c for mdb 
- */
-
-#include "mdb.h"
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <a.out.h>
-#include "proto.h"
-
-#if	GNU_SUPPORT
-#define ZMAGIC 0413
-#define NMAGIC 0410
-#define QMAGIC 0314
-#endif
-
-struct symtab_s
-{
-	struct nlist *start;
-	struct nlist *end;
-	int text;
-	int data;
-	unsigned nsym;
-};
-
-PRIVATE struct symtab_s symtab;
-PRIVATE int type_of_exec;
-
-FORWARD _PROTOTYPE( int check_exec, (struct exec *hdr) );
-FORWARD _PROTOTYPE( void sortsyms , (struct nlist *array , struct nlist *top ));
-FORWARD _PROTOTYPE( int symeq , (char *t , struct nlist *sp ));
-FORWARD _PROTOTYPE( int symprefix , (char *t , struct nlist *sp ));
-FORWARD _PROTOTYPE( struct nlist *findsname, (char *name, int is_text, int allflag) );
-FORWARD _PROTOTYPE( void outsym, (struct nlist *sp, off_t off) );
-FORWARD _PROTOTYPE( struct nlist *findsval, (off_t value, int where) );
-
-PUBLIC void syminit( filename )
-char *filename;
-{
-	int fd;
-	struct exec header;
-	register struct symtab_s *tp;
-
-	tp = &symtab;
-	if ( (fd = open( filename, O_RDONLY)) < 0) {
-		fprintf(stderr, "Couldn't open %s.\n", filename);
-		perror(filename);
-		exit(1);
-	}
-
-	if( read( fd, (char *) &header, sizeof header ) != sizeof header )
-	{
-		fprintf(stderr, "Couldn't read %d bytes from %s.\n", sizeof(header), filename);
-		close( fd );
-		exit(1);
-	}	
-	type_of_exec = check_exec(&header);
-
-#if	EXTRA_SYMBOLS
-	if ( type_of_exec == GNU_SYMBOLS) {
-		close(fd);
-		gnu_init(filename);
-		return;
-	}
-#endif
-
-	/* For MINIX EXEC */
-	if ( lseek( fd, A_SYMPOS( header ), 0 ) != A_SYMPOS( header ) )
-	{
-		do_error( "mdb - reading header" );
-		close( fd );
-		exit(1);
-	}
-	if ( (int) header.a_syms < 0 ||
-             (unsigned) header.a_syms != header.a_syms ||
-	     (tp->start = (struct nlist *) malloc( (unsigned) header.a_syms ))
-	     			== (struct nlist *) NULL &&
-	     header.a_syms != 0 )
-	{
-		Printf("mdb: no room for symbol table" );
-		close( fd );
-		return;
-	}
-	if ( read( fd, (char *) tp->start, (int) header.a_syms ) < 0 )
-	{
-		do_error( "mdb - reading symbol table" );
-		close( fd );
-		return;
-	}
-	close( fd );
-	tp->nsym = (unsigned) header.a_syms / sizeof (struct nlist);
-	tp->end = tp->start + tp->nsym;
-	tp->text = 0x07;
-	tp->data = 0x0F;
-
-	/* sort on value only, name search not used much and storage a problem */
-	Printf("Sorting %d MINIX symbols ....", tp->nsym );
-	sortsyms( tp->start, tp->end );
-	Printf("\n");
-}
-
-/* Check exec file 
- * return type of exec
- * or exit
- */
-PRIVATE int check_exec(hdr)
-struct exec *hdr;
-{
-long magic;
-
-  /* Check MAGIC number */
-  if (hdr->a_magic[0] != A_MAGIC0 || hdr->a_magic[1] != A_MAGIC1) {
-#if	GNU_SUPPORT
-	memcpy(&magic, hdr, sizeof(long));
-	/* Clear bits */
-	magic &= 0xFFFF;
-
-	if ( magic == ZMAGIC || magic == QMAGIC ) {
-	    is_separate = FALSE;
-	    return GNU_SYMBOLS;
-	}
-	if ( magic == NMAGIC ) {
-	    is_separate = TRUE;
-	    return GNU_SYMBOLS;
-	}
-#endif
-	Printf("mdb: invalid magic number in exec header - %02x %02x\n",
-	hdr->a_magic[0], 
-	hdr->a_magic[1]);
-	exit(1);
-  }
-
-  /* Check CPU */
-#if (CHIP == INTEL)
-#if (_WORD_SIZE == 4)
-  if (hdr->a_cpu != A_I80386)
-#else
-  if (hdr->a_cpu != A_I8086)
-#endif
-#endif 
-#if (CHIP == M68000)
-  if (hdr->a_cpu != A_M68K)
-#endif 
-  {
- 	Printf("mdb: invalid cpu in exec header - %04x\n",
-	hdr->a_cpu);
-	exit(1);
-  }
-
-  is_separate = FALSE;
-#ifdef MINIX_PC
-  if (hdr->a_flags & A_SEP)
-  	is_separate = TRUE;
-#endif 
-/* 
- * A_EXEC is not being set by current cc 
- * It was set in Minix 1.5.0
- */ 
-#if 0 
-  /* Check flags - separate I & D or not */
-  if (hdr->a_flags & A_EXEC)
-	is_separate = FALSE;
-  else {
-	Printf("mdb: object file not exec %04x\n", 
-	hdr->a_flags);
-	exit(1);
-  }
-#endif
-  return MINIX_SYMBOLS;
-}
-
-
-PUBLIC long symbolvalue( name, is_text )
-char *name;
-int is_text;
-{
-register struct nlist *sp;
-
-#if	EXTRA_SYMBOLS
-	if ( type_of_exec == GNU_SYMBOLS )
-		return gnu_symbolvalue( name, is_text );
-#endif
-	
-	/* For MINIX EXEC */
-	sp = findsname(name, is_text, 0);
-	if (sp != NULL) 
-		return sp->n_value;
-	else 
-		return 0L;
-}
-
-PRIVATE struct nlist *findsname( name, is_text, allflag )
-char *name;
-int is_text;
-int allflag;
-{
-	char *s;
-	unsigned char sclass;
-	int schar;
-	char *send;
-	register struct nlist *sp;
-	register struct symtab_s *tp;
-
-	tp = &symtab;
-	if ( allflag )
-	{
-		/* find and print all matching symbols */
-		for ( sp = tp->start; sp < tp->end; ++sp )
-		{
-			if ( symprefix( name, sp ) )
-			{
-				sp = sp;
-				for ( s = sp->n_name, send = s + sizeof sp->n_name;
-				      *s != 0 && s < send; ++s )
-					outbyte( *s );
-				for ( ; s <= send; ++s )
-					outspace();
-				switch( sp->n_sclass & N_SECT )
-				{
-					case N_ABS: schar = 'a'; break;
-					case N_TEXT: schar = 't'; break;
-					case N_DATA: schar = 'd'; break;
-					case N_BSS: schar = 'b'; break;
-					default: schar = '?'; break;
-				}
-				if ( (sp->n_sclass & N_CLASS) == C_EXT && schar != '?' )
-					schar += 'A' - 'a';
-				outbyte( schar );
-				outspace();
-#if (_WORD_SIZE == 2)
-				outh16( (u16_t) sp->n_value );
-#else
-				outh32( sp->n_value );
-#endif
-				outbyte('\n');
-			}
-		}
-	}
-	else
-	{
-		/* find symbol by dumb linear search */
-		for ( sp = tp->start; sp < tp->end; ++sp )
-		{
-			sclass = sp->n_sclass & N_SECT;
-			if ( (is_text && sclass == N_TEXT ||
-			      !is_text && (sclass == N_DATA || sclass == N_BSS)) &&
-					 symeq( name, sp ) )
-				return sp;
-		}
-	}
-	return NULL;
-}
-
-PRIVATE struct nlist *findsval( value, where )
-off_t value;
-int where;
-{
-	int left;
-	int middle;
-	int right;
-	unsigned char sclass;
-	register struct nlist *sp;
-	register struct symtab_s *tp;
-
-	tp = &symtab;
-
-	/* find last symbol with value <= desired one by binary search */
-	for ( left = 0, right = tp->nsym - 1; left <= right; )
-	{
-		middle = (left + right) / 2;
-		sp = tp->start + middle;
-		if ( value < sp->n_value )
-			right = middle - 1;
-		else
-			left = middle + 1;
-	}
-	if ( right >= 0 )
-		/* otherwise tp->start + right may wrap around to > tp->start !! */
-		for ( sp = tp->start + right; sp >= tp->start; --sp )
-		{
-			if ( (sp->n_sclass & N_CLASS) != C_EXT ) continue; 
-			sclass = sp->n_sclass & N_SECT;
-			if ( (where == CSEG && sclass == N_TEXT ||
-						where != CSEG && (sclass == N_DATA || sclass == N_BSS)) )
-			return sp;
-		}
-	return NULL;
-}
-
-
-PUBLIC void printhex(v)
-off_t v;
-{
-    if ( v >= 65536L )
-	outh32( v );
-    else if ( v >= 256 )
-	outh16( (u16_t) v );
-    else
-	outh8(  (u8_t) v );
-}
-
-
-PRIVATE void outsym( sp, off )
-struct nlist *sp;
-off_t off;
-{
-	register char *s;
-	char *send;
-
-	for ( s = sp->n_name, send = s + sizeof sp->n_name; *s != 0 && s < send; ++s )
-		outbyte( *s );
-	if ( (off -= sp->n_value) != 0 )
-	{
-		outbyte( '+' );
-		printhex(off);
-	}
-}
-
-/* shell sort symbols on value */
-
-PRIVATE void sortsyms( array, top )
-struct nlist *array;
-struct nlist *top;
-{
-	int gap;
-	int i;
-	int j;
-	register struct nlist *left;
-	register struct nlist *right;
-	struct nlist swaptemp;
-	int size;
-
-	size = top - array;
-	/* choose gaps according to Knuth V3 p95 */
-	for ( gap = 1, i = 4; (j = 3 * i + 1) < size; gap = i, i = j )
-		;
-	do
-	{
-		for ( j = gap; j < size; ++j )
-			for ( i = j - gap; i >= 0; i -= gap )
-			{
-				left = array + i; 
-				right = array + (i + gap);
-				if ( (off_t) left->n_value <=
-				     right->n_value )
-					break;
-				swaptemp = *left;
-				*left = *right;
-				*right = swaptemp;
-			}
-	}
-	while ( (gap /= 3) != 0 );
-}
-
-PUBLIC void symbolic( value, separator )
-off_t value;
-int separator;
-{
-	register struct nlist *sp;
-	long off;
-
-#if	EXTRA_SYMBOLS
-	if ( type_of_exec == GNU_SYMBOLS ) {
-		gnu_symbolic( value, separator );
-		return;
-	}
-#endif
-
-	/* For MINIX EXEC */
-
-	if (value < st_addr || value > end_addr) {
-		outstr("0x");
-		printhex(value);
-		outbyte(separator);
-		return;
-	}
-
-	if ( (sp = findsval( value, CSEG )) != NULL )
-	{
-		outsym( sp, value );
-	}
-	else if ( (sp = findsval( value, DSEG )) != NULL )
-	{
-		outsym( sp, value );
-	}
-	else
-	{
-		outstr("_start");
-		off = value - st_addr; 
-		if ( off != 0 )  
-		{
-		outbyte( '+' );
-		printhex(off);
-		}
-	}
-	outbyte( separator );
-}
-
-
-PRIVATE int symeq( t, sp )
-register char *t;
-struct nlist *sp;
-{
-	return strncmp( t, sp->n_name, sizeof sp->n_name ) == 0;
-}
-
-PRIVATE int symprefix( t, sp )
-register char *t;
-struct nlist *sp;
-{
-	register char *s;
-	char *send;
-
-	for ( ; *t == '_'; ++t )
-		;
-	for ( s = sp->n_name, send = s + sizeof sp->n_name;
-	      s < send && *s == '_'; ++s )
-		;
-	return strncmp( s, t, (size_t)(send - s) ) == 0;
-}
-
-
-
-/* list all symbols - test for selection criteria */
-
-PUBLIC void listsym(cmd)
-char *cmd;
-{
-	register struct symtab_s *tp;
-	register struct nlist *sp;
-	char *s;
-	char *send;
-	char schar;	
-	char tchar;
-
-	/* set selection */
-	cmd = skip(cmd+1);
-	if( *cmd == '\n' || *cmd == ';' ) 
-		tchar = '*';
-	else
-		tchar = *cmd;
-
-#if	EXTRA_SYMBOLS
-	if ( type_of_exec == GNU_SYMBOLS ) {
-		gnu_listsym(tchar);
-		return;
-	}
-#endif
-
-	/* For MINIX EXEC */
-
-	tp = &symtab;
-    	for ( sp = tp->start; sp < tp->end; ++sp )
-	{
-	     switch( sp->n_sclass & N_SECT )
-	     {
-			case N_ABS:	schar = 'a'; break;
-			case N_TEXT:	schar = 't'; break;
-			case N_DATA:	schar = 'd'; break;
-			case N_BSS:	schar = 'b'; break;
-			default: 	schar = '?'; break;
-	     }
-
-	     if ( (sp->n_sclass & N_CLASS) == C_EXT && schar != '?' )
-		schar += 'A' - 'a';
-
-	     /* check for selection */	
-	     if ( tchar != '*' && schar != tchar)
-		continue; 	
-
-	     /* print symbol type and value */	
-	     for ( s = sp->n_name, send = s + sizeof sp->n_name;
-		 *s != 0 && s < send; ++s ) outbyte( *s );
-	     for ( ; s <= send; ++s ) outspace();
-	     outbyte( schar );
-	     outspace();
-#if (_WORD_SIZE == 2)
-	     outh16( (u16_t) sp->n_value );
-#else
-	     outh32( sp->n_value );
-#endif
-	     outbyte('\n');
-	}
-}
-
-
-PUBLIC int text_symbol(value)
-off_t value;
-{
-struct nlist *sp;
-
-#if	EXTRA_SYMBOLS
-	if ( type_of_exec == GNU_SYMBOLS ) 
-	    return gnu_text_symbol(value);
-#endif
-
-	if ((sp = findsval(value, CSEG)) != NULL && sp->n_value == value)
-	{
-	    outsym(sp, value);
-	    return TRUE;
-	 }
-	else
-	    return FALSE;
-}
-
-PUBLIC int finds_data(off,data_seg)
-off_t off;
-int data_seg;
-{
-struct nlist *sp;
-
-#if	EXTRA_SYMBOLS
-	if ( type_of_exec == GNU_SYMBOLS )
-		return gnu_finds_data(off,data_seg);
-#endif
-
-	if ((sp = findsval(off, data_seg)) != NULL)
-   	{
-	    outsym(sp, off);
-	    return TRUE;
-    	}
-    	else 
-	    return FALSE;
-}
-
-PUBLIC int finds_pc(pc)
-off_t pc;
-{
-struct nlist *sp;
-
-#if	EXTRA_SYMBOLS
-	if ( type_of_exec == GNU_SYMBOLS )
-		return gnu_finds_pc(pc);
-#endif
-
-	if ((sp = findsval(pc, CSEG)) != NULL)
-    	{
-	    outsym(sp, pc);
-	    return TRUE;
-        }
-	else
-	    return FALSE;
-}
Index: trunk/minix/commands/mdb/syscalls.c
===================================================================
--- trunk/minix/commands/mdb/syscalls.c	(revision 9)
+++ 	(revision )
@@ -1,85 +1,0 @@
-/* 
- * syscall.c for mdb 
- */
-#include "mdb.h"
-#ifdef SYSCALLS_SUPPORT
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/ptrace.h>
-#include "proto.h"
-
-#define SYSCALL_NAME	"__sendrec"
-#ifdef __i386
-#define SYSCALL_OFFSET	0xF
-#define SYSCALL_OLD	0x21CD
-#else
-#define SYSCALL_OFFSET  0xE
-#define SYSCALL_OLD	0x20CD
-#endif
-
-PRIVATE long intaddr;
-
-PUBLIC void start_syscall(addr)
-long addr;
-{
-long old; 
-
-  syscalls = FALSE;
-
-  if ( addr == 0 ) {
-	intaddr = symbolvalue( SYSCALL_NAME, TRUE );
-  	if ( intaddr == 0 ) 
-		return;
-	intaddr += SYSCALL_OFFSET;
-  }
-  else {
-	intaddr = addr;
-	Printf("Using %lx as syscall address\n",addr);
-  }
-
-  old = breakpt(intaddr,"\n");
-
-  /* Check instruction */
-  if ( (old & 0xFFFF) == SYSCALL_OLD)
-	syscalls = TRUE;
-
-}
-
-PUBLIC void do_syscall(addr)
-long addr;
-{
-  unsigned reg_ax,reg_bx;
-
-  if ( addr != intaddr ) return;
-
-  Printf("syscall to ");
-
-  reg_ax = get_reg(curpid,reg_addr("AX"));
-
-  switch (reg_ax) {
-  case 0:	Printf(" MM ");
-		break;
-  case 1:	Printf(" FS ");
-		break;
-  case 2:	Printf(" INET ");
-		break;
-  default:	Printf("Invalid dest = %d", reg_ax);
-		exit(0);
-  }
-
-
-  reg_bx = get_reg(curpid,reg_addr("BX"));
-  decode_message(reg_bx);
-
-  /* Single step */	
-  tstart(T_STEP, 0, 0, 1);
-
-  /* Check return code */
-  reg_ax = get_reg(curpid,reg_addr("AX"));
-  if ( reg_ax != 0 )
-	Printf("syscall failed AX=%d\n",reg_ax);
-  else 
-	decode_result();
-}
-
-#endif /* SYSCALLS_SUPPORT */
Index: trunk/minix/commands/mdb/trace.c
===================================================================
--- trunk/minix/commands/mdb/trace.c	(revision 9)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/* 
- * trace.c for mdb 
- */
-
-#include "mdb.h"
-#include <stdio.h>
-#include <sys/ptrace.h>
-#include "proto.h"
-
-/* mdbtrace()
- * Call ptrace and check for error if debugging running process
- * Otherwise read 'core' file
- */ 
-PUBLIC long mdbtrace(req, pid, addr, data)
-int req, pid;
-long addr, data;
-{
-  long val;
-  int i;
-  int segment;
-
-#ifdef  DEBUG
-  if (debug) Printf("ptrace: req=%d pid=%d addr=%lx data=%lx\n",
-		req, pid, addr, data);
-#endif
-
-  if (corepid < 0) 
-  {
-	errno = 0;
-	/* Call normal ptrace and check for error */
-	val = ptrace(req, pid, addr, data);
-	if (errno != 0) {
-		do_error("mdb ptrace error ");
-		mdb_error("\n");
-	}
-#ifdef  DEBUG
-	if (debug) Printf("ptrace: val=>%lx\n", val);
-#endif
-	return val;
-  } 
-  else
-	return read_core(req, addr, data);
-}
-
-/* Used by disassembler */
-PUBLIC u32_t peek_dword(addr)
-off_t addr;
-{
-    return mdbtrace(T_GETINS, curpid, addr, 0L);
-}
-
Index: trunk/minix/commands/mined/Makefile
===================================================================
--- trunk/minix/commands/mined/Makefile	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-# Makefile for mined
-
-CC = exec cc
-
-CFLAGS	= -O -wo -D_MINIX -D_POSIX_SOURCE
-
-OBJ = mined1.o mined2.o
-
-all:	mined
-
-mined:	$(OBJ)
-	$(CC) -i -o $@ $(OBJ)
-	install -S 64k $@
-
-install:	/usr/bin/mined
-
-/usr/bin/mined:	mined
-	install -cs -o bin mined $@
-
-$(OBJ):	mined.h
-
-clean:
-	rm -f mined *.o *.s core *.bak
Index: trunk/minix/commands/mined/build
===================================================================
--- trunk/minix/commands/mined/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/mined/mined.h
===================================================================
--- trunk/minix/commands/mined/mined.h	(revision 9)
+++ 	(revision )
@@ -1,373 +1,0 @@
-/*========================================================================*
- *				Mined.h					  *
- *========================================================================*/
-
-#include <minix/config.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <limits.h>
-
-#ifndef YMAX
-#ifdef UNIX
-#include <stdio.h>
-#undef putchar
-#undef getchar
-#undef NULL
-#undef EOF
-extern char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
-#define YMAX		49
-#else
-#define YMAX		24		/* Maximum y coordinate starting at 0 */
-/* Escape sequences. */
-extern char *enter_string;	/* String printed on entering mined */
-extern char *rev_video;		/* String for starting reverse video */
-extern char *normal_video;	/* String for leaving reverse video */
-extern char *rev_scroll;	/* String for reverse scrolling */
-extern char *pos_string;	/* Absolute cursor positioning */
-#define X_PLUS	' '		/* To be added to x for cursor sequence */
-#define Y_PLUS	' '		/* To be added to y for cursor sequence */
-#endif /* UNIX */
-
-#define XMAX		79		/* Maximum x coordinate starting at 0*/
-#define SCREENMAX	(YMAX - 1)	/* Number of lines displayed */
-#define XBREAK		(XMAX - 0)	/* Line shift at this coordinate */
-#define SHIFT_SIZE	25		/* Number of chars to shift */
-#define SHIFT_MARK	'!'		/* Char indicating line continues */
-#define MAX_CHARS	1024		/* Maximum chars on one line */
-
-/* LINE_START must be rounded up to the lowest SHIFT_SIZE */
-#define LINE_START	(((-MAX_CHARS - 1) / SHIFT_SIZE) * SHIFT_SIZE \
-  				   - SHIFT_SIZE)
-#define LINE_END	(MAX_CHARS + 1)	/* Highest x-coordinate for line */
-
-#define LINE_LEN	(XMAX + 1)	/* Number of characters on line */
-#define SCREEN_SIZE	(XMAX * YMAX)	/* Size of I/O buffering */
-#define BLOCK_SIZE	1024
-
-/* Return values of functions */
-#define ERRORS		-1
-#define NO_LINE		(ERRORS - 1)	/* Must be < 0 */
-#define FINE	 	(ERRORS + 1)
-#define NO_INPUT	(ERRORS + 2)
-
-#define STD_OUT	 	1		/* File descriptor for terminal */
-
-#if (CHIP == INTEL)
-#define MEMORY_SIZE	(50 * 1024)	/* Size of data space to malloc */
-#endif
-
-#define REPORT	2			/* Report change of lines on # lines */
-
-typedef int FLAG;
-
-/* General flags */
-#define	FALSE		0
-#define	TRUE		1
-#define	NOT_VALID	2
-#define	VALID		3
-#define	OFF		4
-#define	ON		5
-
-/* Expression flags */
-#define	FORWARD		6
-#define	REVERSE		7
-
-/* Yank flags */
-#define	SMALLER		8
-#define	BIGGER		9
-#define	SAME		10
-#define	EMPTY		11
-#define	NO_DELETE	12
-#define	DELETE		13
-#define	READ		14
-#define	WRITE		15
-
-/*
- * The Line structure.  Each line entry contains a pointer to the next line,
- * a pointer to the previous line, a pointer to the text and an unsigned char
- * telling at which offset of the line printing should start (usually 0).
- */
-struct Line {
-  struct Line *next;
-  struct Line *prev;
-  char *text;
-  unsigned char shift_count;
-};
-
-typedef struct Line LINE;
-
-/* Dummy line indicator */
-#define DUMMY		0x80
-#define DUMMY_MASK	0x7F
-
-/* Expression definitions */
-#define NO_MATCH	0
-#define MATCH		1
-#define REG_ERROR	2
-
-#define BEGIN_LINE	(2 * REG_ERROR)
-#define END_LINE	(2 * BEGIN_LINE)
-
-/*
- * The regex structure. Status can be any of 0, BEGIN_LINE or REG_ERROR. In
- * the last case, the result.err_mess field is assigned. Start_ptr and end_ptr
- * point to the match found. For more details see the documentation file.
- */
-struct regex {
-  union {
-  	char *err_mess;
-  	int *expression;
-  } result;
-  char status;
-  char *start_ptr;
-  char *end_ptr;
-};
-
-typedef struct regex REGEX;
-
-/* NULL definitions */
-#define NIL_PTR		((char *) 0)
-#define NIL_LINE	((LINE *) 0)
-#define NIL_REG		((REGEX *) 0)
-#define NIL_INT		((int *) 0)
-
-/*
- * Forward declarations
- */
-extern int nlines;		/* Number of lines in file */
-extern LINE *header;		/* Head of line list */
-extern LINE *tail;		/* Last line in line list */
-extern LINE *top_line;		/* First line of screen */
-extern LINE *bot_line;		/* Last line of screen */
-extern LINE *cur_line;		/* Current line in use */
-extern char *cur_text;		/* Pointer to char on current line in use */
-extern int last_y;		/* Last y of screen. Usually SCREENMAX */
-extern int ymax;
-extern int screenmax;
-extern char screen[SCREEN_SIZE];/* Output buffer for "writes" and "reads" */
-
-extern int x, y;			/* x, y coordinates on screen */
-extern FLAG modified;			/* Set when file is modified */
-extern FLAG stat_visible;		/* Set if status_line is visible */
-extern FLAG writable;			/* Set if file cannot be written */
-extern FLAG quit;			/* Set when quit character is typed */
-extern FLAG rpipe;		/* Set if file should be read from stdin */
-extern int input_fd;			/* Fd for command input */
-extern FLAG loading;			/* Set if we're loading a file */
-extern int out_count;			/* Index in output buffer */
-extern char file_name[LINE_LEN];	/* Name of file in use */
-extern char text_buffer[MAX_CHARS];	/* Buffer for modifying text */
-extern char *blank_line;		/* Clear line to end */
-
-extern char yank_file[];		/* Temp file for buffer */
-extern FLAG yank_status;		/* Status of yank_file */
-extern long chars_saved;		/* Nr of chars saved in buffer */
-
-/*
- * Empty output buffer
- */
-#define clear_buffer()			(out_count = 0)
-
-/*
- * Print character on terminal
- */
-#define putchar(c)			(void) write_char(STD_OUT, (c))
-
-/*
- * Ring bell on terminal
- */
-#define ring_bell()			putchar('\07')
-
-/*
- * Print string on terminal
- */
-#define string_print(str)		(void) writeline(STD_OUT, (str))
-
-/*
- * Flush output buffer
- */
-#define flush()				(void) flush_buffer(STD_OUT)
-
-/*
- * Convert cnt to nearest tab position
- */
-#define tab(cnt)			(((cnt) + 8) & ~07)
-#define is_tab(c)			((c) == '\t')
-
-/*
- * Word defenitions
- */
-#define white_space(c)	((c) == ' ' || (c) == '\t')
-#define alpha(c)	((c) != ' ' && (c) != '\t' && (c) != '\n')
-
-/*
- * Print line on terminal at offset 0 and clear tail of line
- */
-#define line_print(line)		put_line(line, 0, TRUE)
-
-/*
- * Move to coordinates and set textp. (Don't use address)
- */
-#define move_to(nx, ny)			move((nx), NIL_PTR, (ny))
-
-/*
- * Move to coordinates on screen as indicated by textp.
- */
-#define move_address(address)		move(0, (address), y)
-
-/*
- * Functions handling status_line. ON means in reverse video.
- */
-#define status_line(str1, str2)	(void) bottom_line(ON, (str1), \
-						    (str2), NIL_PTR, FALSE)
-#define error(str1, str2)	(void) bottom_line(ON, (str1), \
-						    (str2), NIL_PTR, FALSE)
-#define get_string(str1,str2, fl) bottom_line(ON, (str1), NIL_PTR, (str2), fl)
-#define clear_status()		(void) bottom_line(OFF, NIL_PTR, NIL_PTR, \
-						    NIL_PTR, FALSE)
-
-/*
- * Print info about current file and buffer.
- */
-#define fstatus(mess, cnt)	file_status((mess), (cnt), file_name, \
-					     nlines, writable, modified)
-
-/*
- * Get real shift value.
- */
-#define get_shift(cnt)		((cnt) & DUMMY_MASK)
-
-#endif /* YMAX */
-
-/* mined1.c */
-
-_PROTOTYPE(void FS, (void));
-_PROTOTYPE(void VI, (void));
-_PROTOTYPE(int WT, (void));
-_PROTOTYPE(void XWT, (void));
-_PROTOTYPE(void SH, (void));
-_PROTOTYPE(LINE *proceed, (LINE *line, int count ));
-_PROTOTYPE(int bottom_line, (FLAG revfl, char *s1, char *s2, char *inbuf, FLAG statfl ));
-_PROTOTYPE(int count_chars, (LINE *line ));
-_PROTOTYPE(void move, (int new_x, char *new_address, int new_y ));
-_PROTOTYPE(int find_x, (LINE *line, char *address ));
-_PROTOTYPE(char *find_address, (LINE *line, int x_coord, int *old_x ));
-_PROTOTYPE(int length_of, (char *string ));
-_PROTOTYPE(void copy_string, (char *to, char *from ));
-_PROTOTYPE(void reset, (LINE *head_line, int screen_y ));
-_PROTOTYPE(void set_cursor, (int nx, int ny ));
-_PROTOTYPE(void open_device, (void));
-_PROTOTYPE(int getchar, (void));
-_PROTOTYPE(void display, (int x_coord, int y_coord, LINE *line, int count ));
-_PROTOTYPE(int write_char, (int fd, int c ));
-_PROTOTYPE(int writeline, (int fd, char *text ));
-_PROTOTYPE(void put_line, (LINE *line, int offset, FLAG clear_line ));
-_PROTOTYPE(int flush_buffer, (int fd ));
-_PROTOTYPE(void bad_write, (int fd ));
-_PROTOTYPE(void catch, (int sig ));
-_PROTOTYPE(void abort_mined, (void));
-_PROTOTYPE(void raw_mode, (FLAG state ));
-_PROTOTYPE(void panic, (char *message ));
-_PROTOTYPE(char *alloc, (int bytes ));
-_PROTOTYPE(void free_space, (char *p ));
-/*
-#ifdef UNIX
-_PROTOTYPE(void (*key_map [128]), (void));
-#else
-_PROTOTYPE(void (*key_map [256]), (void));
-#endif
-*/
-_PROTOTYPE(void initialize, (void));
-_PROTOTYPE(char *basename, (char *path ));
-_PROTOTYPE(void load_file, (char *file ));
-_PROTOTYPE(int get_line, (int fd, char *buffer ));
-_PROTOTYPE(LINE *install_line, (char *buffer, int length ));
-_PROTOTYPE(void main, (int argc, char *argv []));
-_PROTOTYPE(void RD, (void));
-_PROTOTYPE(void I, (void));
-_PROTOTYPE(void XT, (void));
-_PROTOTYPE(void ESC, (void));
-_PROTOTYPE(int ask_save, (void));
-_PROTOTYPE(int line_number, (void));
-_PROTOTYPE(void file_status, (char *message, long count, char *file, int lines,
-						 FLAG writefl, FLAG changed ));
-#if __STDC__
-void build_string(char *buf, char *fmt, ...);
-#else
-void build_string();
-#endif
-_PROTOTYPE(char *num_out, (long number ));
-_PROTOTYPE(int get_number, (char *message, int *result ));
-_PROTOTYPE(int input, (char *inbuf, FLAG clearfl ));
-_PROTOTYPE(int get_file, (char *message, char *file ));
-_PROTOTYPE(int _getchar, (void));
-_PROTOTYPE(void _flush, (void));
-_PROTOTYPE(void _putchar, (int c ));
-_PROTOTYPE(void get_term, (void));
-
-/* mined2.c */
-
-_PROTOTYPE(void UP, (void));
-_PROTOTYPE(void DN, (void));
-_PROTOTYPE(void LF, (void));
-_PROTOTYPE(void RT, (void));
-_PROTOTYPE(void HIGH, (void));
-_PROTOTYPE(void LOW, (void));
-_PROTOTYPE(void BL, (void));
-_PROTOTYPE(void EL, (void));
-_PROTOTYPE(void GOTO, (void));
-_PROTOTYPE(void PD, (void));
-_PROTOTYPE(void PU, (void));
-_PROTOTYPE(void HO, (void));
-_PROTOTYPE(void EF, (void));
-_PROTOTYPE(void SU, (void));
-_PROTOTYPE(void SD, (void));
-_PROTOTYPE(int forward_scroll, (void));
-_PROTOTYPE(int reverse_scroll, (void));
-_PROTOTYPE(void MP, (void));
-_PROTOTYPE(void move_previous_word, (FLAG remove ));
-_PROTOTYPE(void MN, (void));
-_PROTOTYPE(void move_next_word, (FLAG remove ));
-_PROTOTYPE(void DCC, (void));
-_PROTOTYPE(void DPC, (void));
-_PROTOTYPE(void DLN, (void));
-_PROTOTYPE(void DNW, (void));
-_PROTOTYPE(void DPW, (void));
-_PROTOTYPE(void S, (int character ));
-_PROTOTYPE(void CTL, (void));
-_PROTOTYPE(void LIB, (void));
-_PROTOTYPE(LINE *line_insert, (LINE *line, char *string, int len ));
-_PROTOTYPE(int insert, (LINE *line, char *location, char *string ));
-_PROTOTYPE(LINE *line_delete, (LINE *line ));
-_PROTOTYPE(void delete, (LINE *start_line, char *start_textp, LINE *end_line, char *end_textp ));
-_PROTOTYPE(void PT, (void));
-_PROTOTYPE(void IF, (void));
-_PROTOTYPE(void file_insert, (int fd, FLAG old_pos ));
-_PROTOTYPE(void WB, (void));
-_PROTOTYPE(void MA, (void));
-_PROTOTYPE(void YA, (void));
-_PROTOTYPE(void DT, (void));
-_PROTOTYPE(void set_up, (FLAG remove ));
-_PROTOTYPE(FLAG checkmark, (void));
-_PROTOTYPE(int legal, (void));
-_PROTOTYPE(void yank, (LINE *start_line, char *start_textp, LINE *end_line, char *end_textp, FLAG remove ));
-_PROTOTYPE(int scratch_file, (FLAG mode ));
-_PROTOTYPE(void SF, (void));
-_PROTOTYPE(void SR, (void));
-_PROTOTYPE(REGEX *get_expression, (char *message ));
-_PROTOTYPE(void GR, (void));
-_PROTOTYPE(void LR, (void));
-_PROTOTYPE(void change, (char *message, FLAG file ));
-_PROTOTYPE(char *substitute, (LINE *line, REGEX *program, char *replacement ));
-_PROTOTYPE(void search, (char *message, FLAG method ));
-_PROTOTYPE(int find_y, (LINE *match_line ));
-_PROTOTYPE(void finished, (REGEX *program, int *last_exp ));
-_PROTOTYPE(void compile, (char *pattern, REGEX *program ));
-_PROTOTYPE(LINE *match, (REGEX *program, char *string, FLAG method ));
-_PROTOTYPE(int line_check, (REGEX *program, char *string, FLAG method ));
-_PROTOTYPE(int check_string, (REGEX *program, char *string, int *expression ));
-_PROTOTYPE(int star, (REGEX *program, char *end_position, char *string, int *expression ));
-_PROTOTYPE(int in_list, (int *list, int c, int list_length, int opcode ));
-_PROTOTYPE(void dummy_line, (void));
Index: trunk/minix/commands/mined/mined1.c
===================================================================
--- trunk/minix/commands/mined/mined1.c	(revision 9)
+++ 	(revision )
@@ -1,1987 +1,0 @@
-/*
- * Part one of the mined editor.
- */
-
-/*
- * Author: Michiel Huisjes.
- * 
- * 1. General remarks.
- * 
- *   Mined is a screen editor designed for the MINIX operating system.
- *   It is meant to be used on files not larger than 50K and to be fast.
- *   When mined starts up, it reads the file into its memory to minimize
- *   disk access. The only time that disk access is needed is when certain
- *   save, write or copy commands are given.
- * 
- *   Mined has the style of Emacs or Jove, that means that there are no modes.
- *   Each character has its own entry in an 256 pointer to function array,
- *   which is called when that character is typed. Only ASCII characters are
- *   connected with a function that inserts that character at the current
- *   location in the file. Two execptions are <linefeed> and <tab> which are
- *   inserted as well. Note that the mapping between commands and functions
- *   called is implicit in the table. Changing the mapping just implies
- *   changing the pointers in this table.
- * 
- *   The display consists of SCREENMAX + 1 lines and XMAX + 1 characters. When
- *   a line is larger (or gets larger during editing) than XBREAK characters,
- *   the line is either shifted SHIFT_SIZE characters to the left (which means
- *   that the first SHIFT_SIZE characters are not printed) or the end of the
- *   line is marked with the SHIFT_MARK character and the rest of the line is
- *   not printed.  A line can never exceed MAX_CHARS characters. Mined will
- *   always try to keep the cursor on the same line and same (relative)
- *   x-coordinate if nothing changed. So if you scroll one line up, the cursor
- *   stays on the same line, or when you move one line down, the cursor will
- *   move to the same place on the line as it was on the previous.
- *   Every character on the line is available for editing including the
- *   linefeed at the the of the line. When the linefeed is deleted, the current
- *   line and the next line are joined. The last character of the file (which
- *   is always a linefeed) can never be deleted.
- *   The bottomline (as indicated by YMAX + 1) is used as a status line during
- *   editing. This line is usually blank or contains information mined needs
- *   during editing. This information (or rather questions) is displayed in
- *   reverse video.
- * 
- *   The terminal modes are changed completely. All signals like start/stop,
- *   interrupt etc. are unset. The only signal that remains is the quit signal.
- *   The quit signal (^\) is the general abort signal for mined. Typing a ^\
- *   during searching or when mined is asking for filenames, etc. will abort
- *   the function and mined will return to the main loop.  Sending a quit
- *   signal during the main loop will abort the session (after confirmation)
- *   and the file is not (!) saved.
- *   The session will also be aborted when an unrecoverable error occurs. E.g
- *   when there is no more memory available. If the file has been modified,
- *   mined will ask if the file has to be saved or not.
- *   If there is no more space left on the disk, mined will just give an error 
- *   message and continue.
- * 
- *   The number of system calls are minized. This is done to keep the editor
- *   as fast as possible. I/O is done in SCREEN_SIZE reads/writes. Accumulated
- *   output is also flushed at the end of each character typed.
- * 
- * 2. Regular expressions
- *   
- *   Mined has a build in regular expression matcher, which is used for
- *   searching and replace routines. A regular expression consists of a
- *   sequence of:
- * 
- *      1. A normal character matching that character.
- *      2. A . matching any character.
- *      3. A ^ matching the begin of a line.
- *      4. A $ (as last character of the pattern) mathing the end of a line.
- *      5. A \<character> matching <character>.
- *      6. A number of characters enclosed in [] pairs matching any of these
- *        characters. A list of characters can be indicated by a '-'. So
- *        [a-z] matches any letter of the alphabet. If the first character
- *        after the '[' is a '^' then the set is negated (matching none of
- *        the characters). 
- *        A ']', '^' or '-' can be escaped by putting a '\' in front of it.
- *        Of course this means that a \ must be represented by \\.
- *      7. If one of the expressions as described in 1-6 is followed by a
- *        '*' than that expressions matches a sequence of 0 or more of
- *        that expression.
- * 
- *   Parsing of regular expression is done in two phases. In the first phase
- *   the expression is compiled into a more comprehensible form. In the second
- *   phase the actual matching is done. For more details see 3.6.
- * 
- * 
- * 3. Implementation of mined.
- * 
- *   3.1 Data structures.
- * 
- *      The main data structures are as follows. The whole file is kept in a
- *      double linked list of lines. The LINE structure looks like this:
- * 
- *         typedef struct Line {
- *              struct Line *next;
- *              struct Line *prev;
- *              char *text;
- *              unsigned char shift_count;
- *         } LINE;
- * 
- *      Each line entry contains a pointer to the next line, a pointer to the
- *      previous line and a pointer to the text of that line. A special field
- *      shift_count contains the number of shifts (in units of SHIFT_SIZE)
- *      that is performed on that line. The total size of the structure is 7
- *      bytes so a file consisting of 1000 empty lines will waste a lot of
- *      memory. A LINE structure is allocated for each line in the file. After
- *      that the number of characters of the line is counted and sufficient
- *      space is allocated to store them (including a linefeed and a '\0').
- *      The resulting address is assigned to the text field in the structure.
- * 
- *      A special structure is allocated and its address is assigned to the
- *      variable header as well as the variable tail. The text field of this
- *      structure is set to NIL_PTR. The tail->prev of this structure points
- *      to the last LINE of the file and the header->next to the first LINE.
- *      Other LINE *variables are top_line and bot_line which point to the
- *      first line resp. the last line on the screen.
- *      Two other variables are important as well. First the LINE *cur_line,
- *      which points to the LINE currently in use and the char *cur_text,
- *      which points to the character at which the cursor stands.
- *      Whenever an ASCII character is typed, a new line is build with this
- *      character inserted. Then the old data space (pointed to by
- *      cur_line->text) is freed, data space for the new line is allocated and
- *      assigned to cur_line->text.
- * 
- *      Two global variables called x and y represent the x and y coordinates
- *      from the cursor. The global variable nlines contains the number of
- *      lines in the file. Last_y indicates the maximum y coordinate of the
- *      screen (which is usually SCREENMAX).
- * 
- *      A few strings must be initialized by hand before compiling mined.
- *      These string are enter_string, which is printed upon entering mined,
- *      rev_video (turn on reverse video), normal_video, rev_scroll (perform a
- *      reverse scroll) and pos_string. The last string should hold the
- *      absolute position string to be printed for cursor motion. The #define
- *      X_PLUS and Y_PLUS should contain the characters to be added to the
- *      coordinates x and y (both starting at 0) to finish cursor positioning.
- * 
- *   3.2 Starting up.
- *      
- *      Mined can be called with or without argument and the function
- *      load_file () is called with these arguments. load_file () checks
- *      if the file exists if it can be read and if it is writable and
- *      sets the writable flag accordingly. If the file can be read, 
- *      load_file () reads a line from the file and stores this line into
- *      a structure by calling install_line () and line_insert () which
- *      installs the line into the double linked list, until the end of the
- *      file is reached.
- *      Lines are read by the function get_line (), which buffers the
- *      reading in blocks of SCREEN_SIZE. Load_file () also initializes the
- *      LINE *variables described above.
- * 
- *   3.3 Moving around.
- * 
- *      Several commands are implemented for moving through the file.
- *      Moving up (UP), down (DN) left (LF) and right (RT) are done by the
- *      arrow keys. Moving one line below the screen scrolls the screen one
- *      line up. Moving one line above the screen scrolls the screen one line
- *      down. The functions forward_scroll () and reverse_scroll () take care
- *      of that.
- *      Several other move functions exist: move to begin of line (BL), end of
- *      line (EL) top of screen (HIGH), bottom of screen (LOW), top of file
- *      (HO), end of file (EF), scroll one page down (PD), scroll one page up
- *      (PU), scroll one line down (SD), scroll one line up (SU) and move to a
- *      certain line number (GOTO).
- *      Two functions called MN () and MP () each move one word further or 
- *      backwards. A word is a number of non-blanks seperated by a space, a
- *      tab or a linefeed.
- * 
- *   3.4 Modifying text.
- * 
- *      The modifying commands can be separated into two modes. The first
- *      being inserting text, and the other deleting text. Two functions are
- *      created for these purposes: insert () and delete (). Both are capable
- *      of deleting or inserting large amounts of text as well as one
- *      character. Insert () must be given the line and location at which
- *      the text must be inserted. Is doesn't make any difference whether this
- *      text contains linefeeds or not. Delete () must be given a pointer to
- *      the start line, a pointer from where deleting should start on that
- *      line and the same information about the end position. The last
- *      character of the file will never be deleted. Delete () will make the
- *      necessary changes to the screen after deleting, but insert () won't.
- *      The functions for modifying text are: insert one char (S), insert a
- *      file (file_insert (fd)), insert a linefeed and put cursor back to
- *      end of line (LIB), delete character under the cursor (DCC), delete
- *      before cursor (even linefeed) (DPC), delete next word (DNW), delete
- *      previous word (DPC) and delete to end of line (if the cursor is at
- *      a linefeed delete line) (DLN).
- * 
- *   3.5 Yanking.
- * 
- *      A few utilities are provided for yanking pieces of text. The function
- *      MA () marks the current position in the file. This is done by setting 
- *      LINE *mark_line and char *mark_text to the current position. Yanking
- *      of text can be done in two modes. The first mode just copies the text
- *      from the mark to the current position (or visa versa) into a buffer
- *      (YA) and the second also deletes the text (DT). Both functions call
- *      the function set_up () with the delete flag on or off. Set_up ()
- *      checks if the marked position is still a valid one (by using
- *      check_mark () and legal ()), and then calls the function yank () with
- *      a start and end position in the file. This function copies the text
- *      into a scratch_file as indicated by the variable yank_file. This
- *      scratch_file is made uniq by the function scratch_file (). At the end
- *      of copying yank will (if necessary) delete the text. A global flag
- *      called yank_status keeps track of the buffer (or file) status. It is
- *      initialized on NOT_VALID and set to EMPTY (by set_up ()) or VALID (by
- *      yank ()). Several things can be done with the buffer. It can be
- *      inserted somewhere else in the file (PT) or it can be copied into
- *      another file (WB), which will be prompted for.
- * 
- *   3.6 Search and replace routines.
- * 
- *      Searching for strings and replacing strings are done by regular
- *      expressions. For any expression the function compile () is called
- *      with as argument the expression to compile. Compile () returns a
- *      pointer to a structure which looks like this:
- * 
- *         typedef struct regex {
- *              union {
- *                    char *err_mess;
- *                    int *expression;
- *              } result;
- *              char status;
- *              char *start_ptr;
- *              char *end_ptr;
- *         } REGEX;
- *      
- *    If something went wrong during compiling (e.g. an illegal expression
- *    was given), the function reg_error () is called, which sets the status
- *    field to REG_ERROR and the err_mess field to the error message. If the
- *    match must be anchored at the beginning of the line (end of line), the
- *    status field is set to BEGIN_LINE (END_LINE). If none of these special
- *    cases are true, the field is set to 0 and the function finished () is
- *    called.  Finished () allocates space to hold the compiled expression
- *    and copies this expression into the expression field of the union
- *    (bcopy ()). Matching is done by the routines match() and line_check().
- *    Match () takes as argument the REGEX *program, a pointer to the
- *    startposition on the current line, and a flag indicating FORWARD or
- *    REVERSE search.  Match () checks out the whole file until a match is
- *    found. If match is found it returns a pointer to the line in which the
- *    match was found else it returns a NIL_LINE. Line_check () takes the
- *    same arguments, but return either MATCH or NO_MATCH.
- *    During checking, the start_ptr and end_ptr fields of the REGEX
- *    structure are assigned to the start and end of the match. 
- *    Both functions try to find a match by walking through the line
- *    character by character. For each possibility, the function
- *    check_string () is called with as arguments the REGEX *program and the
- *    string to search in. It starts walking through the expression until
- *    the end of the expression or the end of the string is reached.
- *    Whenever a * is encountered, this position of the string is marked,
- *    the maximum number of matches are performed and the function star ()
- *    is called in order to try to find the longest match possible. Star ()
- *    takes as arguments the REGEX program, the current position of the
- *    string, the marked position and the current position of the expression
- *    Star () walks from the current position of the string back to the
- *    marked position, and calls string_check () in order to find a match.
- *    It returns MATCH or NO_MATCH, just as string_check () does.
- *    Searching is now easy. Both search routines (forward (SF) and
- *    backwards search (SR)) call search () with an apropiate message and a
- *    flag indicating FORWARD or REVERSE search. Search () will get an
- *    expression from the user by calling get_expression(). Get_expression()
- *    returns a pointer to a REGEX structure or NIL_REG upon errors and
- *    prompts for the expression. If no expression if given, the previous is
- *    used instead. After that search will call match (), and if a match is
- *    found, we can move to that place in the file by the functions find_x()
- *    and find_y () which will find display the match on the screen.
- *    Replacing can be done in two ways. A global replace (GR) or a line
- *    replace (LR). Both functions call change () with a message an a flag
- *    indicating global or line replacement. Change () will prompt for the
- *    expression and for the replacement. Every & in the replacement pattern
- *    means substitute the match instead. An & can be escaped by a \. When
- *    a match is found, the function substitute () will perform the
- *    substitution.
- * 
- *  3.6 Miscellaneous commands.
- * 
- *    A few commands haven't be discussed yet. These are redraw the screen
- *    (RD) fork a shell (SH), print file status (FS), write file to disc
- *    (WT), insert a file at current position (IF), leave editor (XT) and
- *    visit another file (VI). The last two functions will check if the file
- *    has been modified. If it has, they will ask if you want to save the
- *    file by calling ask_save ().
- *    The function ESC () will repeat a command n times. It will prompt for
- *    the number. Aborting the loop can be done by sending the ^\ signal.
- * 
- *  3.7 Utility functions.
- * 
- *    Several functions exists for internal use. First allocation routines:
- *    alloc (bytes) and newline () will return a pointer to free data space
- *    if the given size. If there is no more memory available, the function
- *    panic () is called.
- *    Signal handling: The only signal that can be send to mined is the 
- *    SIGQUIT signal. This signal, functions as a general abort command.
- *    Mined will abort if the signal is given during the main loop. The 
- *    function abort_mined () takes care of that.
- *    Panic () is a function with as argument a error message. It will print
- *    the message and the error number set by the kernel (errno) and will
- *    ask if the file must be saved or not. It resets the terminal
- *    (raw_mode ()) and exits.
- *    String handling routines like copy_string(to, from), length_of(string)
- *    and build_string (buffer, format, arg1, arg2, ...). The latter takes
- *    a description of the string out out the format field and puts the
- *    result in the buffer. (It works like printf (3), but then into a
- *    string). The functions status_line (string1, string2), error (string1,
- *    string2), clear_status () and bottom_line () all print information on
- *    the status line.
- *    Get_string (message, buffer) reads a string and getchar () reads one
- *    character from the terminal.
- *    Num_out ((long) number) prints the number into a 11 digit field
- *    without leading zero's. It returns a pointer to the resulting string.
- *    File_status () prints all file information on the status line.
- *    Set_cursor (x, y) prints the string to put the cursor at coordinates
- *    x and y.
- *    Output is done by four functions: writeline(fd,string), clear_buffer()
- *    write_char (fd, c) and flush_buffer (fd). Three defines are provided
- *    to write on filedescriptor STD_OUT (terminal) which is used normally:
- *    string_print (string), putchar (c) and flush (). All these functions
- *    use the global I/O buffer screen and the global index for this array
- *    called out_count. In this way I/O can be buffered, so that reads or
- *    writes can be done in blocks of SCREEN_SIZE size.
- *    The following functions all handle internal line maintenance. The
- *    function proceed (start_line, count) returns the count'th line after
- *    start_line.  If count is negative, the count'th line before the
- *    start_line is returned. If header or tail is encountered then that
- *    will be returned. Display (x, y, start_line, count) displays count
- *    lines starting at coordinates [x, y] and beginning at start_line. If
- *    the header or tail is encountered, empty lines are displayed instead.
- *    The function reset (head_line, ny) reset top_line, last_y, bot_line,
- *    cur_line and y-coordinate. This is not a neat way to do the
- *    maintenance, but it sure saves a lot of code. It is usually used in
- *    combination with display ().
- *    Put_line(line, offset, clear_line), prints a line (skipping characters
- *    according to the line->shift_size field) until XBREAK - offset
- *    characters are printed or a '\n' is encountered. If clear_line is
- *	  TRUE, spaces are printed until XBREAK - offset characters.
- *	  Line_print (line) is a #define from put_line (line, 0, TRUE).
- *    Moving is done by the functions move_to (x, y), move_addres (address)
- *    and move (x, adress, y). This function is the most important one in
- *    mined. New_y must be between 0 and last_y, new_x can be about
- *    anything, address must be a pointer to an character on the current
- *    line (or y). Move_to () first adjust the y coordinate together with
- *    cur_line. If an address is given, it finds the corresponding
- *    x-coordinate. If an new x-coordinate was given, it will try to locate
- *    the corresponding character. After that it sets the shift_count field
- *    of cur_line to an apropiate number according to new_x. The only thing
- *    left to do now is to assign the new values to cur_line, cur_text, x
- *    and y.
- * 
- * 4. Summary of commands.
- *  
- *  CURSOR MOTION
- *    up-arrow  Move cursor 1 line up.  At top of screen, reverse scroll
- *    down-arrow  Move cursor 1 line down.  At bottom, scroll forward.
- *    left-arrow  Move cursor 1 character left or to end of previous line
- *    right-arrow Move cursor 1 character right or to start of next line
- *    CTRL-A   Move cursor to start of current line
- *    CTRL-Z   Move cursor to end of current line
- *    CTRL-^   Move cursor to top of screen
- *    CTRL-_   Move cursor to bottom of screen
- *    CTRL-F   Forward to start of next word (even to next line)
- *    CTRL-B   Backward to first character of previous word
- *   
- *  SCREEN MOTION
- *    Home key  Move cursor to first character of file
- *    End key   Move cursor to last character of file
- *    PgUp    Scroll backward 1 page. Bottom line becomes top line
- *    PgD    Scroll backward 1 page. Top line becomes bottom line
- *    CTRL-D   Scroll screen down one line (reverse scroll)
- *    CTRL-U   Scroll screen up one line (forward scroll)
- *   
- *  MODIFYING TEXT
- *    ASCII char  Self insert character at cursor
- *    tab    Insert tab at cursor
- *    backspace  Delete the previous char (left of cursor), even line feed
- *    Del    Delete the character under the cursor
- *    CTRL-N   Delete next word
- *    CTRL-P   Delete previous word
- *    CTRL-O   Insert line feed at cursor and back up 1 character
- *    CTRL-T   Delete tail of line (cursor to end); if empty, delete line
- *    CTRL-@   Set the mark (remember the current location)
- *    CTRL-K   Delete text from the mark to current position save on file
- *    CTRL-C   Save the text from the mark to the current position
- *    CTRL-Y   Insert the contents of the save file at current position
- *    CTRL-Q   Insert the contents of the save file into a new file
- *    CTRL-G   Insert a file at the current position
- *   
- *  MISCELLANEOUS
- *    CTRL-E   Erase and redraw the screen
- *    CTRL-V   Visit file (read a new file); complain if old one changed
- *    CTRL-W   Write the current file back to the disk
- *    numeric +  Search forward (prompt for regular expression)
- *    numeric -  Search backward (prompt for regular expression)
- *    numeric 5  Print the current status of the file
- *    CTRL-R   (Global) Replace str1 by str2 (prompts for each string)
- *    CTRL-L   (Line) Replace string1 by string2
- *    CTRL-S   Fork off a shell and wait for it to finish
- *    CTRL-X   EXIT (prompt if file modified)
- *    CTRL-]   Go to a line. Prompts for linenumber
- *    CTRL-\   Abort whatever editor was doing and start again
- *    escape key  Repeat a command count times; (prompts for count)
- */
-
-/*  ========================================================================  *
- *				Utilities				      *	
- *  ========================================================================  */
-
-#include "mined.h"
-#include <signal.h>
-#include <termios.h>
-#include <limits.h>
-#include <errno.h>
-#include <sys/wait.h>
-#include <sys/ioctl.h>
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-extern int errno;
-int ymax = YMAX;
-int screenmax = SCREENMAX;
-
-
-/*
- * Print file status.
- */
-void FS()
-{
-  fstatus(file_name[0] ? "" : "[buffer]", -1L);
-}
-
-/*
- * Visit (edit) another file. If the file has been modified, ask the user if
- * he wants to save it.
- */
-void VI()
-{
-  char new_file[LINE_LEN];	/* Buffer to hold new file name */
-
-  if (modified == TRUE && ask_save() == ERRORS)
-  	return;
-  
-/* Get new file name */
-  if (get_file("Visit file:", new_file) == ERRORS)
-  	return;
-
-/* Free old linked list, initialize global variables and load new file */
-  initialize();
-#ifdef UNIX
-  tputs(CL, 0, _putchar);
-#else
-  string_print (enter_string);
-#endif /* UNIX */
-  load_file(new_file[0] == '\0' ? NIL_PTR : new_file);
-}
-
-/*
- * Write file in core to disc.
- */
-int WT()
-{
-  register LINE *line;
-  register long count = 0L;	/* Nr of chars written */
-  char file[LINE_LEN];		/* Buffer for new file name */
-  int fd;				/* Filedescriptor of file */
-
-  if (modified == FALSE) {
-	error ("Write not necessary.", NIL_PTR);
-	return FINE;
-  }
-
-/* Check if file_name is valid and if file can be written */
-  if (file_name[0] == '\0' || writable == FALSE) {
-  	if (get_file("Enter file name:", file) != FINE)
-  		return ERRORS;
-  	copy_string(file_name, file);		/* Save file name */
-  }
-  if ((fd = creat(file_name, 0644)) < 0) {	/* Empty file */
-  	error("Cannot create ", file_name);
-  	writable = FALSE;
-  	return ERRORS;
-  }
-  else
-  	writable = TRUE;
-
-  clear_buffer();
-
-  status_line("Writing ", file_name);
-  for (line = header->next; line != tail; line = line->next) {
-	if (line->shift_count & DUMMY) {
-		if (line->next == tail && line->text[0] == '\n')
-			continue;
-	}
-  	if (writeline(fd, line->text) == ERRORS) {
-  		count = -1L;
-  		break;
-  	}
-  	count += (long) length_of(line->text);
-  }
-
-  if (count > 0L && flush_buffer(fd) == ERRORS)
-  	count = -1L;
-
-  (void) close(fd);
-
-  if (count == -1L)
-  	return ERRORS;
-
-  modified = FALSE;
-  rpipe = FALSE;		/* File name is now assigned */
-
-/* Display how many chars (and lines) were written */
-  fstatus("Wrote", count);
-  return FINE;
-}
-
-/* Call WT and discard value returned. */
-void XWT()
-{
-  (void) WT();
-}
-
-
-
-/*
- * Call an interactive shell.
- */
-void SH()
-{
-  register int w;
-  int pid, status;
-  char *shell;
-
-  if ((shell = getenv("SHELL")) == NIL_PTR) shell = "/bin/sh";
-
-  switch (pid = fork()) {
-  	case -1:			/* Error */
-  		error("Cannot fork.", NIL_PTR);
-  		return;
-  	case 0:				/* This is the child */
-  		set_cursor(0, ymax);
-  		putchar('\n');
-  		flush();
-  		raw_mode(OFF);
-		if (rpipe) {			/* Fix stdin */
-			close (0);
-			if (open("/dev/tty", 0) < 0)
-				exit (126);
-		}
-  		execl(shell, shell, (char *) 0);
-  		exit(127);			/* Exit with 127 */
-  	default :				/* This is the parent */
-  		signal(SIGINT, SIG_IGN);
-  		signal(SIGQUIT, SIG_IGN);
-  		do {
-  			w = wait(&status);
-  		} while (w != -1 && w != pid);
-  }
-
-  raw_mode(ON);
-  RD();
-
-  if ((status >> 8) == 127)		/* Child died with 127 */
-  	error("Cannot exec ", shell);
-  else if ((status >> 8) == 126)
-  	error("Cannot open /dev/tty as fd #0", NIL_PTR);
-}
-
-/*
- * Proceed returns the count'th line after `line'. When count is negative
- * it returns the count'th line before `line'. When the next (previous)
- * line is the tail (header) indicating EOF (tof) it stops.
- */
-LINE *proceed(line, count)
-register LINE *line;
-register int count;
-{
-  if (count < 0)
-  	while (count++ < 0 && line != header)
-  		line = line->prev;
-  else
-  	while (count-- > 0 && line != tail)
-  		line = line->next;
-  return line;
-}
-
-/*
- * Show concatenation of s1 and s2 on the status line (bottom of screen)
- * If revfl is TRUE, turn on reverse video on both strings. Set stat_visible
- * only if bottom_line is visible.
- */
-int bottom_line(revfl, s1, s2, inbuf, statfl)
-FLAG revfl;
-char *s1, *s2;
-char *inbuf;
-FLAG statfl;
-{
-  int ret = FINE;
-  char buf[LINE_LEN];
-  register char *p = buf;
-
-  *p++ = ' ';
-  if (s1 != NIL_PTR)
-	while (*p = *s1++)
-		p++;
-  if (s2 != NIL_PTR)
-	while (*p = *s2++)
-		p++;
-  *p++ = ' ';
-  *p++ = 0;
-
-  if (revfl == ON && stat_visible == TRUE)
-	clear_status ();
-  set_cursor(0, ymax);
-  if (revfl == ON) {		/* Print rev. start sequence */
-#ifdef UNIX
-  	tputs(SO, 0, _putchar);
-#else
-  	string_print(rev_video);
-#endif /* UNIX */
-  	stat_visible = TRUE;
-  }
-  else				/* Used as clear_status() */
-  	stat_visible = FALSE;
-
-  string_print(buf);
-  
-  if (inbuf != NIL_PTR)
-  	ret = input(inbuf, statfl);
-
-  /* Print normal video */
-#ifdef UNIX
-  tputs(SE, 0, _putchar);
-  tputs(CE, 0, _putchar);
-#else
-  string_print(normal_video);
-  string_print(blank_line);	/* Clear the rest of the line */
-#endif /* UNIX */
-  if (inbuf != NIL_PTR)
-  	set_cursor(0, ymax);
-  else
-  	set_cursor(x, y);	/* Set cursor back to old position */
-  flush();			/* Perform the actual write */
-  if (ret != FINE)
-  	clear_status();
-  return ret;
-}
-
-/*
- * Count_chars() count the number of chars that the line would occupy on the
- * screen. Counting starts at the real x-coordinate of the line.
- */
-int count_chars(line)
-LINE *line;
-{
-  register int cnt = get_shift(line->shift_count) * -SHIFT_SIZE;
-  register char *textp = line->text;
-
-/* Find begin of line on screen */
-  while (cnt < 0) {
-  	if (is_tab(*textp++))
-  		cnt = tab(cnt);
-  	else
-  		cnt++;
-  }
-
-/* Count number of chars left */
-  cnt = 0;
-  while (*textp != '\n') {
-  	if (is_tab(*textp++))
-  		 cnt = tab(cnt);
-  	else
-  		cnt++;
-  }
-  return cnt;
-}
-
-/*
- * Move to coordinates nx, ny at screen.  The caller must check that scrolling
- * is not needed.
- * If new_x is lower than 0 or higher than XBREAK, move_to() will check if
- * the line can be shifted. If it can it sets(or resets) the shift_count field
- * of the current line accordingly.
- * Move also sets cur_text to the right char.
- * If we're moving to the same x coordinate, try to move the the x-coordinate
- * used on the other previous call.
- */
-void move(new_x, new_address, new_y)
-register int new_x;
-int new_y;
-char *new_address;
-{
-  register LINE *line = cur_line;	/* For building new cur_line */
-  int shift = 0;			/* How many shifts to make */
-  static int rel_x = 0;		/* Remember relative x position */
-  int tx = x;
-
-/* Check for illegal values */
-  if (new_y < 0 || new_y > last_y)
-  	return;
-
-/* Adjust y-coordinate and cur_line */
-  if (new_y < y)
-  	while (y != new_y) {
-  		y--;
-  		line = line->prev;
-  	}
-  else
-  	while (y != new_y) {
-  		y++;
-  		line = line->next;
-  	}
-
-/* Set or unset relative x-coordinate */
-  if (new_address == NIL_PTR) {
-  	new_address = find_address(line, (new_x == x) ? rel_x : new_x , &tx);
-	if (new_x != x)
-		rel_x = tx;
-  	new_x = tx;
-  }
-  else
-  	rel_x = new_x = find_x(line, new_address);
-
-/* Adjust shift_count if new_x lower than 0 or higher than XBREAK */
-  if (new_x < 0 || new_x >= XBREAK) {
-  	if (new_x > XBREAK || (new_x == XBREAK && *new_address != '\n'))
-  		shift = (new_x - XBREAK) / SHIFT_SIZE + 1;
-  	else {
-  		shift = new_x / SHIFT_SIZE;
-		if (new_x % SHIFT_SIZE)
-			shift--;
-  	}
-
-  	if (shift != 0) {
-  		line->shift_count += shift;
-  		new_x = find_x(line, new_address);
-  		set_cursor(0, y);
-  		line_print(line);
-  		rel_x = new_x;
-  	}
-  }
-
-/* Assign and position cursor */
-  x = new_x;
-  cur_text = new_address;
-  cur_line = line;
-  set_cursor(x, y);
-}
-
-/*
- * Find_x() returns the x coordinate belonging to address.
- * (Tabs are expanded).
- */
-int find_x(line, address)
-LINE *line;
-char *address;
-{
-  register char *textp = line->text;
-  register int nx = get_shift(line->shift_count) * -SHIFT_SIZE;
-
-  while (textp != address && *textp != '\0') {
-  	if (is_tab(*textp++)) 	/* Expand tabs */
-  		nx = tab(nx);
-  	else
-  		nx++;
-  }
-  return nx;
-}
-
-/*
- * Find_address() returns the pointer in the line with offset x_coord.
- * (Tabs are expanded).
- */
-char *find_address(line, x_coord, old_x)
-LINE *line;
-int x_coord;
-int *old_x;
-{
-  register char *textp = line->text;
-  register int tx = get_shift(line->shift_count) * -SHIFT_SIZE;
-
-  while (tx < x_coord && *textp != '\n') {
-  	if (is_tab(*textp)) {
-  		if (*old_x - x_coord == 1 && tab(tx) > x_coord)
-  			break;		/* Moving left over tab */
-  		else
-  			tx = tab(tx);
-  	}
-  	else
-  		tx++;
-  	textp++;
-  }
-  
-  *old_x = tx;
-  return textp;
-}
-
-/*
- * Length_of() returns the number of characters int the string `string'
- * excluding the '\0'.
- */
-int length_of(string)
-register char *string;
-{
-  register int count = 0;
-
-  if (string != NIL_PTR) {
-  	while (*string++ != '\0')
-  		count++;
-  }
-  return count;
-}
-
-/*
- * Copy_string() copies the string `from' into the string `to'. `To' must be
- * long enough to hold `from'.
- */
-void copy_string(to, from)
-register char *to;
-register char *from;
-{
-  while (*to++ = *from++)
-  	;
-}
-
-/*
- * Reset assigns bot_line, top_line and cur_line according to `head_line'
- * which must be the first line of the screen, and an y-coordinate,
- * which will be the current y-coordinate (if it isn't larger than last_y)
- */
-void reset(head_line, screen_y)
-LINE *head_line;
-int screen_y;
-{
-  register LINE *line;
-
-  top_line = line = head_line;
-
-/* Search for bot_line (might be last line in file) */
-  for (last_y = 0; last_y < nlines - 1 && last_y < screenmax
-						&& line->next != tail; last_y++)
-  	line = line->next;
-
-  bot_line = line;
-  y = (screen_y > last_y) ? last_y : screen_y;
-
-/* Set cur_line according to the new y value */
-  cur_line = proceed(top_line, y);
-}
-
-/*
- * Set cursor at coordinates x, y.
- */
-void set_cursor(nx, ny)
-int nx, ny;
-{
-#ifdef UNIX
-  extern char *tgoto();
-
-  tputs(tgoto(CM, nx, ny), 0, _putchar);
-#else
-  char text_buffer[10];
-
-  build_string(text_buffer, pos_string, ny+1, nx+1);
-  string_print(text_buffer);
-#endif /* UNIX */
-}
-
-/*
- * Routine to open terminal when mined is used in a pipeline.
- */
-void open_device()
-{
-  if ((input_fd = open("/dev/tty", 0)) < 0)
-	panic("Cannot open /dev/tty for read");
-}
-
-/*
- * Getchar() reads one character from the terminal. The character must be
- * masked with 0377 to avoid sign extension.
- */
-int getchar()
-{
-#ifdef UNIX
-  return (_getchar() & 0377);
-#else
-  char c;
-
-  if (read(input_fd, &c, 1) != 1 && quit == FALSE)
-  	panic("Can't read one char from fd #0");
-
-  return c & 0377;
-#endif /* UNIX */
-}
-
-/*
- * Display() shows count lines on the terminal starting at the given
- * coordinates. When the tail of the list is encountered it will fill the
- * rest of the screen with blank_line's.
- * When count is negative, a backwards print from `line' will be done.
- */
-void display(x_coord, y_coord, line, count)
-int x_coord, y_coord;
-register LINE *line;
-register int count;
-{
-  set_cursor(x_coord, y_coord);
-
-/* Find new startline if count is negative */
-  if (count < 0) {
-  	line = proceed(line, count);
-  	count = -count;
-  }
-
-/* Print the lines */
-  while (line != tail && count-- >= 0) {
-  	line_print(line);
-  	line = line->next;
-  }
-
-/* Print the blank lines (if any) */
-  if (loading == FALSE) {
-	while (count-- >= 0) {
-#ifdef UNIX
-		tputs(CE, 0, _putchar);
-#else
-		string_print(blank_line);
-#endif /* UNIX */
-		putchar('\n');
-	}
-  }
-}
-
-/*
- * Write_char does a buffered output. 
- */
-int write_char(fd, c)
-int fd;
-char c;
-{
-  screen [out_count++] = c;
-  if (out_count == SCREEN_SIZE)		/* Flush on SCREEN_SIZE chars */
-  	return flush_buffer(fd);
-  return FINE;
-}
-
-/*
- * Writeline writes the given string on the given filedescriptor.
- */
-int writeline(fd, text)
-register int fd;
-register char *text;
-{
-  while(*text)
-  	 if (write_char(fd, *text++) == ERRORS)
-  		return ERRORS;
-  return FINE;
-}
-
-/*
- * Put_line print the given line on the standard output. If offset is not zero
- * printing will start at that x-coordinate. If the FLAG clear_line is TRUE,
- * then (screen) line will be cleared when the end of the line has been
- * reached.
- */
-void put_line(line, offset, clear_line)
-LINE *line;				/* Line to print */
-int offset;				/* Offset to start */
-FLAG clear_line;			/* Clear to eoln if TRUE */
-{
-  register char *textp = line->text;
-  register int count = get_shift(line->shift_count) * -SHIFT_SIZE;
-  int tab_count;			/* Used in tab expansion */
-
-/* Skip all chars as indicated by the offset and the shift_count field */
-  while (count < offset) {
-  	if (is_tab(*textp++))
-  		count = tab(count);
-  	else
-  		count++;
-  }
-
-  while (*textp != '\n' && count < XBREAK) {
-  	if (is_tab(*textp)) {		/* Expand tabs to spaces */
-  		tab_count = tab(count);
-  		while (count < XBREAK && count < tab_count) {
-  			count++;
-  			putchar(' ');
-  		}
-  		textp++;
-  	}
-  	else {
-		if (*textp >= '\01' && *textp <= '\037') {
-#ifdef UNIX
-			tputs(SO, 0, _putchar);
-#else
-			string_print (rev_video);
-#endif /* UNIX */
-  			putchar(*textp++ + '\100');
-#ifdef UNIX
-			tputs(SE, 0, _putchar);
-#else
-			string_print (normal_video);
-#endif /* UNIX */
-		}
-		else
-  			putchar(*textp++);
-  		count++;
-  	}
-  }
-
-/* If line is longer than XBREAK chars, print the shift_mark */
-  if (count == XBREAK && *textp != '\n')
-  	putchar(textp[1]=='\n' ? *textp : SHIFT_MARK);
-
-/* Clear the rest of the line is clear_line is TRUE */
-  if (clear_line == TRUE) {
-#ifdef	UNIX
-  	tputs(CE, 0, _putchar);
-#else
-	string_print(blank_line);
-#endif /* UNIX */
-  	putchar('\n');
-  }
-}
-
-/*
- * Flush the I/O buffer on filedescriptor fd.
- */
-int flush_buffer(fd)
-int fd;
-{
-  if (out_count <= 0)		/* There is nothing to flush */
-  	return FINE;
-#ifdef UNIX
-  if (fd == STD_OUT) {
-  	printf("%.*s", out_count, screen);
-  	_flush();
-  }
-  else
-#endif /* UNIX */
-  if (write(fd, screen, out_count) != out_count) {
-  	bad_write(fd);
-  	return ERRORS;
-  }
-  clear_buffer();		/* Empty buffer */
-  return FINE;
-}
-
-/*
- * Bad_write() is called when a write failed. Notify the user.
- */
-void bad_write(fd)
-int fd;
-{
-  if (fd == STD_OUT)		/* Cannot write to terminal? */
-  	exit(1);
-  
-  clear_buffer();
-  build_string(text_buffer, "Command aborted: %s (File incomplete)",
-  		            (errno == ENOSPC || errno == -ENOSPC) ?
-  			    "No space on device" : "Write error");
-  error(text_buffer, NIL_PTR);
-}
-
-/*
- * Catch the SIGQUIT signal (^\) send to mined. It turns on the quitflag.
- */
-void catch(sig)
-int sig;
-{
-/* Reset the signal */
-  signal(SIGQUIT, catch);
-  quit = TRUE;
-}
-
-/*
- * Abort_mined() will leave mined. Confirmation is asked first.
- */
-void abort_mined()
-{
-  quit = FALSE;
-
-/* Ask for confirmation */
-  status_line("Really abort? ", NIL_PTR);
-  if (getchar() != 'y') {
-  	clear_status();
-  	return;
-  }
-
-/* Reset terminal */
-  raw_mode(OFF);
-  set_cursor(0, ymax);
-  putchar('\n');
-  flush();
-#ifdef UNIX
-  abort();
-#else
-  exit(1);
-#endif /* UNIX */
-}
-
-#define UNDEF	_POSIX_VDISABLE
-
-/*
- * Set and reset tty into CBREAK or old mode according to argument `state'. It
- * also sets all signal characters (except for ^\) to UNDEF. ^\ is caught.
- */
-void raw_mode(state)
-FLAG state;
-{
-  static struct termios old_tty;
-  static struct termios new_tty;
-
-  if (state == OFF) {
-  	tcsetattr(input_fd, TCSANOW, &old_tty);
-  	return;
-  }
-
-/* Save old tty settings */
-  tcgetattr(input_fd, &old_tty);
-
-/* Set tty to CBREAK mode */
-  tcgetattr(input_fd, &new_tty);
-  new_tty.c_lflag &= ~(ICANON|ECHO|ECHONL);
-  new_tty.c_iflag &= ~(IXON|IXOFF);
-
-/* Unset signal chars, leave only SIGQUIT set to ^\ */
-  new_tty.c_cc[VINTR] = new_tty.c_cc[VSUSP] = UNDEF;
-  new_tty.c_cc[VQUIT] = '\\' & 037;
-  signal(SIGQUIT, catch);		/* Which is caught */
-
-  tcsetattr(input_fd, TCSANOW, &new_tty);
-}
-
-/*
- * Panic() is called with an error number and a message. It is called when
- * something unrecoverable has happened.
- * It writes the message to the terminal, resets the tty and exits.
- * Ask the user if he wants to save his file.
- */
-void panic(message)
-register char *message;
-{
-  extern char yank_file[];
-
-#ifdef UNIX
-  tputs(CL, 0, _putchar);
-  build_string(text_buffer, "%s\nError code %d\n", message, errno);
-#else
-  build_string(text_buffer, "%s%s\nError code %d\n", enter_string, message, errno);
-#endif /* UNIX */
-  (void) write(STD_OUT, text_buffer, length_of(text_buffer));
-
-  if (loading == FALSE)
-  	XT();			/* Check if file can be saved */
-  else
-  	(void) unlink(yank_file);
-  raw_mode(OFF);
-
-#ifdef UNIX
-  abort();
-#else
-  exit(1);
-#endif /* UNIX */
-}
-
-char *alloc(bytes)
-int bytes;
-{
-  char *p;
-
-  p = malloc((unsigned) bytes);
-  if (p == NIL_PTR) {
-	if (loading == TRUE)
-		panic("File too big.");
-	panic("Out of memory.");
-  }
-  return(p);
-}
-
-void free_space(p)
-char *p;
-{
-  free(p);
-}
-
-/*  ========================================================================  *
- *				Main loops				      *
- *  ========================================================================  */
-
-/* The mapping between input codes and functions. */
-
-void (*key_map[256])() = {       /* map ASCII characters to functions */
-   /* 000-017 */ MA, BL, MP, YA, SD, RD, MN, IF, DPC, S, S, DT, LR, S, DNW,LIB,
-   /* 020-037 */ DPW, WB, GR, SH, DLN, SU, VI, XWT, XT, PT, EL, ESC, I, GOTO,
-		 HIGH, LOW,
-   /* 040-057 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 060-077 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 100-117 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 120-137 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 140-157 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 160-177 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, DCC,
-   /* 200-217 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 220-237 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 240-257 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 260-277 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 300-317 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 320-337 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 340-357 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-   /* 360-377 */ S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
-};
-
-int nlines;			/* Number of lines in file */
-LINE *header;			/* Head of line list */
-LINE *tail;			/* Last line in line list */
-LINE *cur_line;			/* Current line in use */
-LINE *top_line;			/* First line of screen */
-LINE *bot_line;			/* Last line of screen */
-char *cur_text;			/* Current char on current line in use */
-int last_y;			/* Last y of screen. Usually SCREENMAX */
-char screen[SCREEN_SIZE];	/* Output buffer for "writes" and "reads" */
-
-int x, y;			/* x, y coordinates on screen */
-FLAG modified = FALSE;		/* Set when file is modified */
-FLAG stat_visible;		/* Set if status_line is visible */
-FLAG writable;			/* Set if file cannot be written */
-FLAG loading;			/* Set if we are loading a file. */
-FLAG quit = FALSE;		/* Set when quit character is typed */
-FLAG rpipe = FALSE;		/* Set if file should be read from stdin */
-int input_fd = 0;		/* Fd for command input */
-int out_count;			/* Index in output buffer */
-char file_name[LINE_LEN];	/* Name of file in use */
-char text_buffer[MAX_CHARS];	/* Buffer for modifying text */
-
-/* Escape sequences. */
-#ifdef UNIX
-char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
-#else
-char   *enter_string = "\033[H\033[J";	/* String printed on entering mined */
-char   *pos_string = "\033[%d;%dH";	/* Absolute cursor position */
-char   *rev_scroll = "\033M";		/* String for reverse scrolling */
-char   *rev_video = "\033[7m";		/* String for starting reverse video */
-char   *normal_video = "\033[m";	/* String for leaving reverse video */
-char   *blank_line = "\033[K";		/* Clear line to end */
-#endif /* UNIX */
-
-/* 
- * Yank variables.
- */
-FLAG yank_status = NOT_VALID;		/* Status of yank_file */
-char yank_file[] = "/tmp/mined.XXXXXX";
-long chars_saved;			/* Nr of chars in buffer */
-
-/*
- * Initialize is called when a another file is edited. It free's the allocated
- * space and sets modified back to FALSE and fixes the header/tail pointer.
- */
-void initialize()
-{
-  register LINE *line, *next_line;
-
-/* Delete the whole list */
-  for (line = header->next; line != tail; line = next_line) {
-  	next_line = line->next;
-  	free_space(line->text);
-  	free_space((char*)line);
-  }
-
-/* header and tail should point to itself */
-  line->next = line->prev = line;
-  x = y = 0;
-  rpipe = modified = FALSE;
-}
-
-/*
- * Basename() finds the absolute name of the file out of a given path_name.
- */
-char *basename(path)
-char *path;
-{
-  register char *ptr = path;
-  register char *last = NIL_PTR;
-
-  while (*ptr != '\0') {
-  	if (*ptr == '/')
-  		last = ptr;
-  	ptr++;
-  }
-  if (last == NIL_PTR)
-  	return path;
-  if (*(last + 1) == '\0') {	/* E.g. /usr/tmp/pipo/ */
-  	*last = '\0';
-  	return basename(path);/* Try again */
-  }
-  return last + 1;
-}
-
-/*
- * Load_file loads the file `file' into core. If file is a NIL_PTR or the file
- * couldn't be opened, just some initializations are done, and a line consisting
- * of a `\n' is installed.
- */
-void load_file(file)
-char *file;
-{
-  register LINE *line = header;
-  register int len;
-  long nr_of_chars = 0L;
-  int fd = -1;			/* Filedescriptor for file */
-
-  nlines = 0;			/* Zero lines to start with */
-
-/* Open file */
-  writable = TRUE;		/* Benefit of the doubt */
-  if (file == NIL_PTR) {
-	if (rpipe == FALSE)
-  		status_line("No file.", NIL_PTR);
-	else {
-		fd = 0;
-		file = "standard input";
-	}
-	file_name[0] = '\0';
-  }
-  else {
-  	copy_string(file_name, file);	/* Save file name */
-  	if (access(file, 0) < 0)	/* Cannot access file. */
-  		status_line("New file ", file);
-  	else if ((fd = open(file, 0)) < 0)
-  		status_line("Cannot open ", file);
-  	else if (access(file, 2) != 0)	/* Set write flag */
-  		writable = FALSE;
-  }
-
-/* Read file */
-  loading = TRUE;				/* Loading file, so set flag */
-
-  if (fd >= 0) {
-  	status_line("Reading ", file);
-  	while ((len = get_line(fd, text_buffer)) != ERRORS) {
-  		line = line_insert(line, text_buffer, len);
-  		nr_of_chars += (long) len;
-  	}
-  	if (nlines == 0)		/* The file was empty! */
-  		line = line_insert(line, "\n", 1);
-  	clear_buffer();		/* Clear output buffer */
-  	cur_line = header->next;
-  	fstatus("Read", nr_of_chars);
-  	(void) close(fd);		/* Close file */
-  }
-  else					/* Just install a "\n" */
-  	(void) line_insert(line, "\n", 1);
-
-  reset(header->next, 0);		/* Initialize pointers */
-
-/* Print screen */
-  display (0, 0, header->next, last_y);
-  move_to (0, 0);
-  flush();				/* Flush buffer */
-  loading = FALSE;			/* Stop loading, reset flag */
-}
-
-
-/*
- * Get_line reads one line from filedescriptor fd. If EOF is reached on fd,
- * get_line() returns ERRORS, else it returns the length of the string.
- */
-int get_line(fd, buffer)
-int fd;
-register char *buffer;
-{
-  static char *last = NIL_PTR;
-  static char *current = NIL_PTR;
-  static int read_chars;
-  register char *cur_pos = current;
-  char *begin = buffer;
-
-  do {
-  	if (cur_pos == last) {
-  		if ((read_chars = read(fd, screen, SCREEN_SIZE)) <= 0)
-  			break;
-  		last = &screen[read_chars];
-  		cur_pos = screen;
-  	}
-	if (*cur_pos == '\0')
-		*cur_pos = ' ';
-  } while ((*buffer++ = *cur_pos++) != '\n');
-
-  current = cur_pos;
-  if (read_chars <= 0) {
-  	if (buffer == begin)
-  		return ERRORS;
-  	if (*(buffer - 1) != '\n')
-  		if (loading == TRUE) /* Add '\n' to last line of file */
-  			*buffer++ = '\n';
-  		else {
-  			*buffer = '\0';
-  			return NO_LINE;
-  		}
-  }
-
-  *buffer = '\0';
-  return buffer - begin;
-}
-
-/*
- * Install_line installs the buffer into a LINE structure It returns a pointer
- * to the allocated structure.
- */
-LINE *install_line(buffer, length)
-char *buffer;
-int length;
-{
-  register LINE *new_line = (LINE *) alloc(sizeof(LINE));
-
-  new_line->text = alloc(length + 1);
-  new_line->shift_count = 0;
-  copy_string(new_line->text, buffer);
-
-  return new_line;
-}
-
-void main(argc, argv)
-int argc;
-char *argv[];
-{
-/* mined is the Minix editor. */
-
-  register int index;		/* Index in key table */
-  struct winsize winsize;
-
-#ifdef UNIX
-  get_term();
-  tputs(VS, 0, _putchar);
-  tputs(CL, 0, _putchar);
-#else
-  string_print(enter_string);			/* Hello world */
-#endif /* UNIX */
-  if (ioctl(STD_OUT, TIOCGWINSZ, &winsize) == 0 && winsize.ws_row != 0) {
-	ymax = winsize.ws_row - 1;
-	screenmax = ymax - 1;
-  }
-
-  if (!isatty(0)) {		/* Reading from pipe */
-	if (argc != 1) {
-		write(2, "Cannot find terminal.\n", 22);
-		exit (1);
-	}
-	rpipe = TRUE;
-	modified = TRUE;	/* Set modified so he can write */
-	open_device();
-  }
-
-  raw_mode(ON);			/* Set tty to appropriate mode */
-
-  header = tail = (LINE *) alloc(sizeof(LINE));	/* Make header of list*/
-  header->text = NIL_PTR;
-  header->next = tail->prev = header;
-
-/* Load the file (if any) */
-  if (argc < 2)
-  	load_file(NIL_PTR);
-  else {
-  	(void) get_file(NIL_PTR, argv[1]);	/* Truncate filename */
-  	load_file(argv[1]);
-  }
-
- /* Main loop of the editor. */
-  for (;;) {
-  	index = getchar();
-  	if (stat_visible == TRUE)
-  		clear_status();
-  	if (quit == TRUE)
-  		abort_mined();
-  	else {			/* Call the function for this key */
-  		(*key_map[index])(index);
-  		flush();       /* Flush output (if any) */
-  		if (quit == TRUE)
-  			quit = FALSE;
-  	}
-  }
-  /* NOTREACHED */
-}
-
-/*  ========================================================================  *
- *				Miscellaneous				      *
- *  ========================================================================  */
-
-/*
- * Redraw the screen
- */
-void RD()
-{
-/* Clear screen */
-#ifdef UNIX
-  tputs(VS, 0, _putchar);
-  tputs(CL, 0, _putchar);
-#else
-  string_print(enter_string);
-#endif /* UNIX */
-
-/* Print first page */
-  display(0, 0, top_line, last_y);
-
-/* Clear last line */
-  set_cursor(0, ymax);
-#ifdef UNIX
-  tputs(CE, 0, _putchar);
-#else
-  string_print(blank_line);
-#endif /* UNIX */
-  move_to(x, y);
-}
-
-/*
- * Ignore this keystroke.
- */
-void I()
-{
-}
-
-/*
- * Leave editor. If the file has changed, ask if the user wants to save it.
- */
-void XT()
-{
-  if (modified == TRUE && ask_save() == ERRORS)
-  	return;
-
-  raw_mode(OFF);
-  set_cursor(0, ymax);
-  putchar('\n');
-  flush();
-  (void) unlink(yank_file);		/* Might not be necessary */
-  exit(0);
-}
-
-void (*escfunc(c))()
-int c;
-{
-#if (CHIP == M68000)
-#ifndef COMPAT
-  int ch;
-#endif
-#endif
-  if (c == '[') {
-	/* Start of ASCII escape sequence. */
-	c = getchar();
-#if (CHIP == M68000)
-#ifndef COMPAT
-	if ((c >= '0') && (c <= '9')) ch = getchar();
-	/* ch is either a tilde or a second digit */
-#endif
-#endif
-	switch (c) {
-	case 'H': return(HO);
-	case 'A': return(UP);
-	case 'B': return(DN);
-	case 'C': return(RT);
-	case 'D': return(LF);
-#if (CHIP == M68000)
-#ifndef COMPAT
-	/* F1 = ESC [ 1 ~ */
-	/* F2 = ESC [ 2 ~ */
-	/* F3 = ESC [ 3 ~ */
-	/* F4 = ESC [ 4 ~ */
-	/* F5 = ESC [ 5 ~ */
-	/* F6 = ESC [ 6 ~ */
-	/* F7 = ESC [ 17 ~ */
-	/* F8 = ESC [ 18 ~ */
-	case '1': 
-	 	  switch (ch) {
-		  case '~': return(SF);
-		  case '7': (void) getchar(); return(MA);
-		  case '8': (void) getchar(); return(CTL);
-                  }
-	case '2': return(SR);
-	case '3': return(PD);
-	case '4': return(PU);
-	case '5': return(FS);
-	case '6': return(EF);
-#endif
-#endif
-#if (CHIP == INTEL)
-	case 'G': return(FS);
-	case 'S': return(SR);
-	case 'T': return(SF);
-	case 'U': return(PD);
-	case 'V': return(PU);
-	case 'Y': return(EF);
-#endif
-	}
-	return(I);
-  }
-#if (CHIP == M68000)
-#ifdef COMPAT
-  if (c == 'O') {
-	/* Start of ASCII function key escape sequence. */
-	switch (getchar()) {
-	case 'P': return(SF);
-	case 'Q': return(SR);
-	case 'R': return(PD);
-	case 'S': return(PU);
-	case 'T': return(FS);
-	case 'U': return(EF);
-	case 'V': return(MA);
-	case 'W': return(CTL);
-	}
-    }
-#endif
-#endif
-  return(I);
-}
-
-/*
- * ESC() wants a count and a command after that. It repeats the 
- * command count times. If a ^\ is given during repeating, stop looping and
- * return to main loop.
- */
-void ESC()
-{
-  register int count = 0;
-  register void (*func)();
-  int index;
-
-  index = getchar();
-  while (index >= '0' && index <= '9' && quit == FALSE) {
-  	count *= 10;
-  	count += index - '0';
-  	index = getchar();
-  }
-  if (count == 0) {
-	count = 1;
-	func = escfunc(index);
-  } else {
-	func = key_map[index];
-	if (func == ESC)
-		func = escfunc(getchar());
-  }
-
-  if (func == I) {	/* Function assigned? */
-  	clear_status();
-  	return;
-  }
-
-  while (count-- > 0 && quit == FALSE) {
-  	if (stat_visible == TRUE)
-  		clear_status();
-  	(*func)(index);
-  	flush();
-  }
-
-  if (quit == TRUE)		/* Abort has been given */
-  	error("Aborted", NIL_PTR);
-}
-
-/*
- * Ask the user if he wants to save his file or not.
- */
-int ask_save()
-{
-  register int c;
-
-  status_line(file_name[0] ? basename(file_name) : "[buffer]" ,
-					     " has been modified. Save? (y/n)");
-
-  while((c = getchar()) != 'y' && c != 'n' && quit == FALSE) {
-  	ring_bell();
-  	flush();
-  }
-
-  clear_status();
-
-  if (c == 'y')
-  	return WT();
-
-  if (c == 'n')
-  	return FINE;
-
-  quit = FALSE;	/* Abort character has been given */
-  return ERRORS;
-}
-
-/*
- * Line_number() finds the line number we're on.
- */
-int line_number()
-{
-  register LINE *line = header->next;
-  register int count = 1;
-
-  while (line != cur_line) {
-  	count++;
-  	line = line->next;
-  }
-  
-  return count;
-}
-  
-/*
- * Display a line telling how many chars and lines the file contains. Also tell
- * whether the file is readonly and/or modified.
- */
-void file_status(message, count, file, lines, writefl, changed)
-char *message;
-register long count;		/* Contains number of characters in file */
-char *file;
-int lines;
-FLAG writefl, changed;
-{
-  register LINE *line;
-  char msg[LINE_LEN + 40];/* Buffer to hold line */
-  char yank_msg[LINE_LEN];/* Buffer for msg of yank_file */
-
-  if (count < 0)		/* Not valid. Count chars in file */
-  	for (line = header->next; line != tail; line = line->next)
-  		count += length_of(line->text);
-
-  if (yank_status != NOT_VALID)	/* Append buffer info */
-  	build_string(yank_msg, " Buffer: %D char%s.", chars_saved,
-						(chars_saved == 1L) ? "" : "s");
-  else
-  	yank_msg[0] = '\0';
-
-  build_string(msg, "%s %s%s%s %d line%s %D char%s.%s Line %d", message,
-  		    (rpipe == TRUE && *message != '[') ? "standard input" : basename(file),
-  		    (changed == TRUE) ? "*" : "",
-  		    (writefl == FALSE) ? " (Readonly)" : "",
-  		    lines, (lines == 1) ? "" : "s", 
-		    count, (count == 1L) ? "" : "s",
-		    yank_msg, line_number());
-
-  if (length_of(msg) + 1 > LINE_LEN - 4) {
-  	msg[LINE_LEN - 4] = SHIFT_MARK;	/* Overflow on status line */
-  	msg[LINE_LEN - 3] = '\0';
-  }
-  status_line(msg, NIL_PTR);		/* Print the information */
-}
-
-/*
- * Build_string() prints the arguments as described in fmt, into the buffer.
- * %s indicates an argument string, %d indicated an argument number.
- */
-#if __STDC__
-void build_string(char *buf, char *fmt, ...)
-{
-#else
-void build_string(buf, fmt, va_alist)
-char *buf, *fmt;
-va_dcl
-{
-#endif
-  va_list argptr;
-  char *scanp;
-
-#if __STDC__
-  va_start(argptr, fmt);
-#else
-  va_start(argptr);
-#endif
-
-  while (*fmt) {
-  	if (*fmt == '%') {
-  		fmt++;
-  		switch (*fmt++) {
-  		case 's' :
-  			scanp = va_arg(argptr, char *);
-  			break;
-  		case 'd' :
-  			scanp = num_out((long) va_arg(argptr, int));
-  			break;
-  		case 'D' :
-  			scanp = num_out((long) va_arg(argptr, long));
-  			break;
-  		default :
-  			scanp = "";
-  		}
-  		while (*buf++ = *scanp++)
-  			;
-  		buf--;
-  	}
-  	else
-  		*buf++ = *fmt++;
-  }
-  va_end(argptr);
-  *buf = '\0';
-}
-
-/*
- * Output an (unsigned) long in a 10 digit field without leading zeros.
- * It returns a pointer to the first digit in the buffer.
- */
-char *num_out(number)
-long number;
-{
-  static char num_buf[11];		/* Buffer to build number */
-  register long digit;			/* Next digit of number */
-  register long pow = 1000000000L;	/* Highest ten power of long */
-  FLAG digit_seen = FALSE;
-  int i;
-
-  for (i = 0; i < 10; i++) {
-  	digit = number / pow;		/* Get next digit */
-  	if (digit == 0L && digit_seen == FALSE && i != 9)
-  		num_buf[i] = ' ';
-  	else {
-  		num_buf[i] = '0' + (char) digit;
-  		number -= digit * pow;	/* Erase digit */
-  		digit_seen = TRUE;
-  	}
-  	pow /= 10L;			/* Get next digit */
-  }
-  for (i = 0; num_buf[i] == ' '; i++)	/* Skip leading spaces */
-  	;
-  return (&num_buf[i]);
-}
-
-/*
- * Get_number() read a number from the terminal. The last character typed in is
- * returned.  ERRORS is returned on a bad number. The resulting number is put
- * into the integer the arguments points to.
- */
-int get_number(message, result)
-char *message;
-int *result;
-{
-  register int index;
-  register int count = 0;
-
-  status_line(message, NIL_PTR);
-
-  index = getchar();
-  if (quit == FALSE && (index < '0' || index > '9')) {
-  	error("Bad count", NIL_PTR);
-  	return ERRORS;
-  }
-
-/* Convert input to a decimal number */
-  while (index >= '0' && index <= '9' && quit == FALSE) {
-  	count *= 10;
-  	count += index - '0';
-  	index = getchar();
-  }
-
-  if (quit == TRUE) {
-  	clear_status();
-  	return ERRORS;
-  }
-
-  *result = count;
-  return index;
-}
-
-/*
- * Input() reads a string from the terminal.  When the KILL character is typed,
- * it returns ERRORS.
- */
-int input(inbuf, clearfl)
-char *inbuf;
-FLAG clearfl;
-{
-  register char *ptr;
-  register char c;			/* Character read */
-
-  ptr = inbuf;
-
-  *ptr = '\0';
-  while (quit == FALSE) {
-  	flush();
-  	switch (c = getchar()) {
-  		case '\b' :		/* Erase previous char */
-  			if (ptr > inbuf) {
-  				ptr--;
-#ifdef UNIX
-  				tputs(SE, 0, _putchar);
-#else
-  				string_print(normal_video);
-#endif /* UNIX */
-  				if (is_tab(*ptr))
-  					string_print(" \b\b\b  \b\b");
-  				else
-  					string_print(" \b\b \b");
-#ifdef UNIX
-  				tputs(SO, 0, _putchar);
-#else
-  				string_print(rev_video);
-#endif /* UNIX */
-  				string_print(" \b");
-  				*ptr = '\0';
-  			}
-  			else
-  				ring_bell();
-  			break;
-  		case '\n' :		/* End of input */
-  			/* If inbuf is empty clear status_line */
-  			return (ptr == inbuf && clearfl == TRUE) ? NO_INPUT :FINE;
-  		default :		/* Only read ASCII chars */
-  			if ((c >= ' ' && c <= '~') || c == '\t') {
-  				*ptr++ = c;
-  				*ptr = '\0';
-  				if (c == '\t')
-  					string_print("^I");
-  				else
-  					putchar(c);
-  				string_print(" \b");
-  			}
-  			else
-  				ring_bell();
-  	}
-  }
-  quit = FALSE;
-  return ERRORS;
-}
-
-/*
- * Get_file() reads a filename from the terminal. Filenames longer than 
- * FILE_LENGHT chars are truncated.
- */
-int get_file(message, file)
-char *message, *file;
-{
-  char *ptr;
-  int ret;
-
-  if (message == NIL_PTR || (ret = get_string(message, file, TRUE)) == FINE) {
-  	if (length_of((ptr = basename(file))) > NAME_MAX)
-  		ptr[NAME_MAX] = '\0';
-  }
-  return ret;
-}
-
-/*  ========================================================================  *
- *				UNIX I/O Routines			      *
- *  ========================================================================  */
-
-#ifdef UNIX
-#undef putchar
-
-int _getchar()
-{
-  char c;
-
-  if (read(input_fd, &c, 1) != 1 && quit == FALSE)
-	panic ("Cannot read 1 byte from input");
-  return c & 0377;
-}
-
-void _flush()
-{
-  (void) fflush(stdout);
-}
-
-void _putchar(c)
-char c;
-{
-  (void) write_char(STD_OUT, c);
-}
-
-void get_term()
-{
-  static char termbuf[50];
-  extern char *tgetstr(), *getenv();
-  char *loc = termbuf;
-  char entry[1024];
-
-  if (tgetent(entry, getenv("TERM")) <= 0) {
-  	printf("Unknown terminal.\n");
-  	exit(1);
-  }
-
-  AL = tgetstr("al", &loc);
-  CE = tgetstr("ce", &loc);
-  VS = tgetstr("vs", &loc);
-  CL = tgetstr("cl", &loc);
-  SO = tgetstr("so", &loc);
-  SE = tgetstr("se", &loc);
-  CM = tgetstr("cm", &loc);
-  ymax = tgetnum("li") - 1;
-  screenmax = ymax - 1;
-
-  if (!CE || !SO || !SE || !CL || !AL || !CM) {
-  	printf("Sorry, no mined on this type of terminal\n");
-  	exit(1);
-  }
-}
-#endif /* UNIX */
Index: trunk/minix/commands/mined/mined2.c
===================================================================
--- trunk/minix/commands/mined/mined2.c	(revision 9)
+++ 	(revision )
@@ -1,1724 +1,0 @@
-/*
- * Part 2 of the mined editor.
- */
-
-/*  ========================================================================  *
- *				Move Commands				      *	
- *  ========================================================================  */
-
-#include "mined.h"
-#include <string.h>
-
-/*
- * Move one line up.
- */
-void UP()
-{
-  if (y == 0) {		/* Top line of screen. Scroll one line */
-  	(void) reverse_scroll();
-  	move_to(x, y);
-  }
-  else			/* Move to previous line */
-  	move_to(x, y - 1);
-}
-
-/*
- * Move one line down.
- */
-void DN()
-{
-  if (y == last_y) {	/* Last line of screen. Scroll one line */
-	if (bot_line->next == tail && bot_line->text[0] != '\n') {
-		dummy_line();		/* Create new empty line */
-		DN();
-		return;
-	}
-	else {
-		(void) forward_scroll();
-		move_to(x, y);
-	}
-  }
-  else			/* Move to next line */
-  	move_to(x, y + 1);
-}
-
-/*
- * Move left one position.
- */
-void LF()
-{
-  if (x == 0 && get_shift(cur_line->shift_count) == 0) {/* Begin of line */
-	if (cur_line->prev != header) {
-		UP();					/* Move one line up */
-		move_to(LINE_END, y);
-	}
-  }
-  else
-  	move_to(x - 1, y);
-}
-
-/*
- * Move right one position.
- */
-void RT()
-{
-  if (*cur_text == '\n') {
-  	if (cur_line->next != tail) {		/* Last char of file */
-		DN();				/* Move one line down */
-		move_to(LINE_START, y);
-	}
-  }
-  else
-  	move_to(x + 1, y);
-}
-
-/*
- * Move to coordinates [0, 0] on screen.
- */
-void HIGH()
-{
-  move_to(0, 0);
-}
-
-/*
- * Move to coordinates [0, YMAX] on screen.
- */
-void LOW()
-{
-  move_to(0, last_y);
-}
-
-/*
- * Move to begin of line.
- */
-void BL()
-{
-  move_to(LINE_START, y);
-}
-
-/*
- * Move to end of line.
- */
-void EL()
-{
-  move_to(LINE_END, y);
-}
-
-/*
- * GOTO() prompts for a linenumber and moves to that line.
- */
-void GOTO()
-{
-  int number;
-  LINE *line;
-
-  if (get_number("Please enter line number.", &number) == ERRORS)
-  	return;
-
-  if (number <= 0 || (line = proceed(header->next, number - 1)) == tail)
-  	error("Illegal line number: ", num_out((long) number));
-  else
-  	move_to(x, find_y(line));
-}
-
-/*
- * Scroll forward one page or to eof, whatever comes first. (Bot_line becomes 
- * top_line of display.) Try to leave the cursor on the same line. If this is
- * not possible, leave cursor on the line halfway the page.
- */
-void PD()
-{
-  register int i;
-
-  for (i = 0; i < screenmax; i++)
-  	if (forward_scroll() == ERRORS)
-  		break;			/* EOF reached */
-  if (y - i < 0)				/* Line no longer on screen */
-  	move_to(0, screenmax >> 1);
-  else
-  	move_to(0, y - i);
-}
-
-
-/*
- * Scroll backwards one page or to top of file, whatever comes first. (Top_line
- * becomes bot_line of display).  The very bottom line (YMAX) is always blank.
- * Try to leave the cursor on the same line. If this is not possible, leave
- * cursor on the line halfway the page.
- */
-void PU()
-{
-  register int i;
-
-  for (i = 0; i < screenmax; i++)
-  	if (reverse_scroll() == ERRORS)
-  		break;			/* Top of file reached */
-  set_cursor(0, ymax);			/* Erase very bottom line */
-#ifdef UNIX
-  tputs(CE, 0, _putchar);
-#else
-  string_print(blank_line);
-#endif /* UNIX */
-  if (y + i > screenmax)			/* line no longer on screen */
-  	move_to(0, screenmax >> 1);
-  else
-  	move_to(0, y + i);
-}
-
-/*
- * Go to top of file, scrolling if possible, else redrawing screen.
- */
-void HO()
-{
-  if (proceed(top_line, -screenmax) == header)
-  	PU();			/* It fits. Let PU do it */
-  else {
-  	reset(header->next, 0);/* Reset top_line, etc. */
-  	RD();			/* Display full page */
-  }
-  move_to(LINE_START, 0);
-}
-
-/*
- * Go to last line of file, scrolling if possible, else redrawing screen
- */
-void EF()
-{
-  if (tail->prev->text[0] != '\n')
-	dummy_line();
-  if (proceed(bot_line, screenmax) == tail)
-  	PD();			/* It fits. Let PD do it */
-  else {
-  	reset(proceed(tail->prev, -screenmax), screenmax);
-  	RD();			/* Display full page */
-  }
-  move_to(LINE_START, last_y);
-}
-
-/*
- * Scroll one line up. Leave the cursor on the same line (if possible).
- */
-void SU()
-{
-  if (top_line->prev == header)	/* Top of file. Can't scroll */
-  	return;
-
-  (void) reverse_scroll();
-  set_cursor(0, ymax);		/* Erase very bottom line */
-#ifdef UNIX
-  tputs(CE, 0, _putchar);
-#else
-  string_print(blank_line);
-#endif /* UNIX */
-  move_to(x, (y == screenmax) ? screenmax : y + 1);
-}
-
-/*
- * Scroll one line down. Leave the cursor on the same line (if possible).
- */
-void SD()
-{
-  if (forward_scroll() != ERRORS) 
-  	move_to(x, (y == 0) ? 0 : y - 1);
-  else
-  	set_cursor(x, y);
-}
-
-/*
- * Perform a forward scroll. It returns ERRORS if we're at the last line of the
- * file.
- */
-int forward_scroll()
-{
-  if (bot_line->next == tail)		/* Last line of file. No dice */
-  	return ERRORS;
-  top_line = top_line->next;
-  bot_line = bot_line->next;
-  cur_line = cur_line->next;
-  set_cursor(0, ymax);
-  line_print(bot_line);
-
-  return FINE;
-}
-
-/*
- * Perform a backwards scroll. It returns ERRORS if we're at the first line
- * of the file.
- */
-int reverse_scroll()
-{
-  if (top_line->prev == header)
-  	return ERRORS;		/* Top of file. Can't scroll */
-
-  if (last_y != screenmax)	/* Reset last_y if necessary */
-  	last_y++;
-  else
-  	bot_line = bot_line->prev;	/* Else adjust bot_line */
-  top_line = top_line->prev;
-  cur_line = cur_line->prev;
-
-/* Perform the scroll */
-  set_cursor(0, 0);
-#ifdef UNIX
-  tputs(AL, 0, _putchar);
-#else
-  string_print(rev_scroll);
-#endif /* UNIX */
-  set_cursor(0, 0);
-  line_print(top_line);
-
-  return FINE;
-}
-
-/*
- * A word is defined as a number of non-blank characters separated by tabs
- * spaces or linefeeds.
- */
-
-/*
- * MP() moves to the start of the previous word. A word is defined as a
- * number of non-blank characters separated by tabs spaces or linefeeds.
- */
-void MP()
-{
-  move_previous_word(NO_DELETE);
-}
-
-void move_previous_word(remove)
-FLAG remove;
-{
-  register char *begin_line;
-  register char *textp;
-  char start_char = *cur_text;
-  char *start_pos = cur_text;
-
-/* Fist check if we're at the beginning of line. */
-  if (cur_text == cur_line->text) {
-  	if (cur_line->prev == header)
-  		return;
-  	start_char = '\0';
-  }
-
-  LF();
-
-  begin_line = cur_line->text;
-  textp = cur_text;
-
-/* Check if we're in the middle of a word. */
-  if (!alpha(*textp) || !alpha(start_char)) {
-  	while (textp != begin_line && (white_space(*textp) || *textp == '\n'))
-  		textp--;
-  }
-
-/* Now we're at the end of previous word. Skip non-blanks until a blank comes */
-  while (textp != begin_line && alpha(*textp))
-  	textp--;
-
-/* Go to the next char if we're not at the beginning of the line */
-  if (textp != begin_line && *textp != '\n')
-  	textp++;
-
-/* Find the x-coordinate of this address, and move to it */
-  move_address(textp);
-  if (remove == DELETE)
-  	delete(cur_line, textp, cur_line, start_pos);
-}
-
-/*
- * MN() moves to the start of the next word. A word is defined as a number of
- * non-blank characters separated by tabs spaces or linefeeds. Always keep in
- * mind that the pointer shouldn't pass the '\n'.
- */
-void MN()
-{
-  move_next_word(NO_DELETE);
-}
-
-void move_next_word(remove)
-FLAG remove;
-{
-  register char *textp = cur_text;
-
-/* Move to the end of the current word. */
-  while (*textp != '\n' && alpha(*textp))
-  	textp++;
-
-/* Skip all white spaces */
-  while (*textp != '\n' && white_space(*textp))
-  	textp++;
-/* If we're deleting. delete the text in between */
-  if (remove == DELETE) {
-  	delete(cur_line, cur_text, cur_line, textp);
-  	return;
-  }
-
-/* If we're at end of line. move to the first word on the next line. */
-  if (*textp == '\n' && cur_line->next != tail) {
-  	DN();
-  	move_to(LINE_START, y);
-  	textp = cur_text;
-  	while (*textp != '\n' && white_space(*textp))
-  		textp++;
-  }
-  move_address(textp);
-}
-
-/*  ========================================================================  *
- *				Modify Commands				      *
- *  ========================================================================  */
-
-/*
- * DCC deletes the character under the cursor.  If this character is a '\n' the
- * current line is joined with the next one.
- * If this character is the only character of the line, the current line will
- * be deleted.
- */
-void DCC()
-{
-  if (*cur_text == '\n')
-  	delete(cur_line,cur_text, cur_line->next,cur_line->next->text);
-  else
-  	delete(cur_line, cur_text, cur_line, cur_text + 1);
-}
-
-/*
- * DPC deletes the character on the left side of the cursor.  If the cursor is
- * at the beginning of the line, the last character if the previous line is
- * deleted. 
- */
-void DPC()
-{
-  if (x == 0 && cur_line->prev == header)
-  	return;			/* Top of file */
-  
-  LF();				/* Move one left */
-  DCC();				/* Delete character under cursor */
-}
-
-/*
- * DLN deletes all characters until the end of the line. If the current
- * character is a '\n', then delete that char.
- */
-void DLN()
-{
-  if (*cur_text == '\n')
-  	DCC();
-  else
-  	delete(cur_line, cur_text, cur_line, cur_text + length_of(cur_text) -1);
-}
-
-/*
- * DNW() deletes the next word (as described in MN())
- */
-void DNW()
-{
-  if (*cur_text == '\n')
-  	DCC();
-  else
-  	move_next_word(DELETE);
-}
-
-/*
- * DPW() deletes the next word (as described in MP())
- */
-void DPW()
-{
-  if (cur_text == cur_line->text)
-  	DPC();
-  else
-  	move_previous_word(DELETE);
-}
-
-/*
- * Insert character `character' at current location.
- */
-void S(character)
-register char character;
-{
-  static char buffer[2];
-
-  buffer[0] = character;
-/* Insert the character */
-  if (insert(cur_line, cur_text, buffer) == ERRORS)
-  	return;
-
-/* Fix screen */
-  if (character == '\n') {
-  	set_cursor(0, y);
-  	if (y == screenmax) {		/* Can't use display */
-  		line_print(cur_line);
-  		(void) forward_scroll();
-  	}
-  	else {
-  		reset(top_line, y);	/* Reset pointers */
-  		display(0, y, cur_line, last_y - y);
-  	}
-  	move_to(0, (y == screenmax) ? y : y + 1);
-  }
-  else if (x + 1 == XBREAK)/* If line must be shifted, just call move_to*/
-  	move_to(x + 1, y);
-  else {			 /* else display rest of line */
-  	put_line(cur_line, x, FALSE);
-  	move_to(x + 1, y);
-  }
-}
-
-/*
- * CTL inserts a control-char at the current location. A message that this
- * function is called is displayed at the status line.
- */
-void CTL()
-{
-  register char ctrl;
-
-  status_line("Enter control character.", NIL_PTR);
-  if ((ctrl = getchar()) >= '\01' && ctrl <= '\037') {
-  	S(ctrl);		/* Insert the char */
-	clear_status();
-  }
-  else
-	error ("Unknown control character", NIL_PTR);
-}
-
-/*
- * LIB insert a line at the current position and moves back to the end of
- * the previous line.
- */
-void LIB()
-{
-  S('\n');	  		/* Insert the line */
-  UP();				/* Move one line up */
-  move_to(LINE_END, y);		/* Move to end of this line */
-}
-
-/*
- * Line_insert() inserts a new line with text pointed to by `string'.
- * It returns the address of the new line.
- */
-LINE *line_insert(line, string, len)
-register LINE *line;
-char *string;
-int len;
-{
-  register LINE *new_line;
-
-/* Allocate space for LINE structure and text */
-  new_line = install_line(string, len);
-
-/* Install the line into the double linked list */
-  new_line->prev = line;
-  new_line->next = line->next;
-  line->next = new_line;
-  new_line->next->prev = new_line;
-
-/* Increment nlines */
-  nlines++;
-
-  return new_line;
-}
-
-/*
- * Insert() insert the string `string' at the given line and location.
- */
-int insert(line, location, string)
-register LINE *line;
-char *location, *string;
-{
-  register char *bufp = text_buffer;	/* Buffer for building line */
-  register char *textp = line->text;
-
-  if (length_of(textp) + length_of(string) >= MAX_CHARS) {
-  	error("Line too long", NIL_PTR);
-  	return ERRORS;
-  }
-
-  modified = TRUE;			/* File has been modified */
-
-/* Copy part of line until `location' has been reached */
-  while (textp != location)
-  	*bufp++ = *textp++;
-  
-/* Insert string at this location */
-  while (*string != '\0')
-  	*bufp++ = *string++;
-  *bufp = '\0';
-  
-  if (*(string - 1) == '\n')		/* Insert a new line */
-  	(void) line_insert(line, location, length_of(location));
-  else					/* Append last part of line */
-  	copy_string(bufp, location);
-
-/* Install the new text in this line */
-  free_space(line->text);
-  line->text = alloc(length_of(text_buffer) + 1);
-  copy_string(line->text, text_buffer);
-
-  return FINE;
-}
-
-/*
- * Line_delete() deletes the argument line out of the line list. The pointer to
- * the next line is returned.
- */
-LINE *line_delete(line)
-register LINE *line;
-{
-  register LINE *next_line = line->next;
-
-/* Delete the line */
-  line->prev->next = line->next;
-  line->next->prev = line->prev;
-
-/* Free allocated space */
-  free_space(line->text);
-  free_space((char*)line);
-
-/* Decrement nlines */
-  nlines--;
-
-  return next_line;
-}
-
-/*
- * Delete() deletes all the characters (including newlines) between the
- * startposition and endposition and fixes the screen accordingly. It
- * returns the number of lines deleted.
- */
-void delete(start_line, start_textp, end_line, end_textp)
-register LINE *start_line;
-LINE *end_line;
-char *start_textp, *end_textp;
-{
-  register char *textp = start_line->text;
-  register char *bufp = text_buffer;	/* Storage for new line->text */
-  LINE *line, *stop;
-  int line_cnt = 0;			/* Nr of lines deleted */
-  int count = 0;
-  int shift = 0;				/* Used in shift calculation */
-  int nx = x;
-
-  modified = TRUE;			/* File has been modified */
-
-/* Set up new line. Copy first part of start line until start_position. */
-  while (textp < start_textp) {
-  	*bufp++ = *textp++;
-  	count++;
-  }
-
-/* Check if line doesn't exceed MAX_CHARS */
-  if (count + length_of(end_textp) >= MAX_CHARS) {
-  	error("Line too long", NIL_PTR);
-  	return;
-  }
-
-/* Copy last part of end_line if end_line is not tail */
-  copy_string(bufp, (end_textp != NIL_PTR) ? end_textp : "\n");
-
-/* Delete all lines between start and end_position (including end_line) */
-  line = start_line->next;
-  stop = end_line->next;
-  while (line != stop && line != tail) {
-  	line = line_delete(line);
-  	line_cnt++;
-  }
-
-/* Check if last line of file should be deleted */
-  if (end_textp == NIL_PTR && length_of(start_line->text) == 1 && nlines > 1) {
-  	start_line = start_line->prev;
-  	(void) line_delete(start_line->next);
-  	line_cnt++;
-  }
-  else {	/* Install new text */
-  	free_space(start_line->text);
-  	start_line->text = alloc(length_of(text_buffer) + 1);
-  	copy_string(start_line->text, text_buffer);
-  }
-
-/* Fix screen. First check if line is shifted. Perhaps we should shift it back*/
-  if (get_shift(start_line->shift_count)) {
-  	shift = (XBREAK - count_chars(start_line)) / SHIFT_SIZE;
-  	if (shift > 0) {		/* Shift line `shift' back */
-  		if (shift >= get_shift(start_line->shift_count))
-  			start_line->shift_count = 0;
-  		else
-  			start_line->shift_count -= shift;
-  		nx += shift * SHIFT_SIZE;/* Reset x value */
-  	}
-  }
-
-  if (line_cnt == 0) {		    /* Check if only one line changed */
-  	if (shift > 0) {	    /* Reprint whole line */
-  		set_cursor(0, y);
-  		line_print(start_line);
-  	}
-  	else {			    /* Just display last part of line */
-  		set_cursor(x, y);
-  		put_line(start_line, x, TRUE);
-  	}
-  	move_to(nx, y);	   /* Reset cur_text */
-  	return;
-  }
-
-  shift = last_y;	   /* Save value */
-  reset(top_line, y);
-  display(0, y, start_line, shift - y);
-  move_to((line_cnt == 1) ? nx : 0, y);
-}
-
-/*  ========================================================================  *
- *				Yank Commands				      *	
- *  ========================================================================  */
-
-LINE *mark_line;			/* For marking position. */
-char *mark_text;
-int lines_saved;			/* Nr of lines in buffer */
-
-/*
- * PT() inserts the buffer at the current location.
- */
-void PT()
-{
-  register int fd;		/* File descriptor for buffer */
-
-  if ((fd = scratch_file(READ)) == ERRORS)
-  	error("Buffer is empty.", NIL_PTR);
-  else {
-  	file_insert(fd, FALSE);/* Insert the buffer */
-  	(void) close(fd);
-  }
-}
-
-/*
- * IF() prompt for a filename and inserts the file at the current location 
- * in the file.
- */
-void IF()
-{
-  register int fd;		/* File descriptor of file */
-  char name[LINE_LEN];		/* Buffer for file name */
-
-/* Get the file name */
-  if (get_file("Get and insert file:", name) != FINE)
-  	return;
-  
-  if ((fd = open(name, 0)) < 0)
-  	error("Cannot open ", name);
-  else {
-  	file_insert(fd, TRUE);	/* Insert the file */
-  	(void) close(fd);
-  }
-}
-
-/*
- * File_insert() inserts a an opened file (as given by filedescriptor fd)
- * at the current location.
- */
-void file_insert(fd, old_pos)
-int fd;
-FLAG old_pos;
-{
-  char line_buffer[MAX_CHARS];		/* Buffer for next line */
-  register LINE *line = cur_line;
-  register int line_count = nlines;	/* Nr of lines inserted */
-  LINE *page = cur_line;
-  int ret = ERRORS;
-  
-/* Get the first piece of text (might be ended with a '\n') from fd */
-  if (get_line(fd, line_buffer) == ERRORS)
-  	return;				/* Empty file */
-
-/* Insert this text at the current location. */
-  if (insert(line, cur_text, line_buffer) == ERRORS)
-  	return;
-
-/* Repeat getting lines (and inserting lines) until EOF is reached */
-  while ((ret = get_line(fd, line_buffer)) != ERRORS && ret != NO_LINE)
-  	line = line_insert(line, line_buffer, ret);
-  
-  if (ret == NO_LINE) {		/* Last line read not ended by a '\n' */
-  	line = line->next;
-  	(void) insert(line, line->text, line_buffer);
-  }
-
-/* Calculate nr of lines added */
-  line_count = nlines - line_count;
-
-/* Fix the screen */
-  if (line_count == 0) {		/* Only one line changed */
-  	set_cursor(0, y);
-  	line_print(line);
-  	move_to((old_pos == TRUE) ? x : x + length_of(line_buffer), y);
-  }
-  else {				/* Several lines changed */
-  	reset(top_line, y);	/* Reset pointers */
-  	while (page != line && page != bot_line->next)
-  		page = page->next;
-  	if (page != bot_line->next || old_pos == TRUE)
-  		display(0, y, cur_line, screenmax - y);
-  	if (old_pos == TRUE)
-  		move_to(x, y);
-  	else if (ret == NO_LINE)
-		move_to(length_of(line_buffer), find_y(line));
-	else 
-		move_to(0, find_y(line->next));
-  }
-
-/* If nr of added line >= REPORT, print the count */
-  if (line_count >= REPORT)
-  	status_line(num_out((long) line_count), " lines added.");
-}
-
-/*
- * WB() writes the buffer (yank_file) into another file, which
- * is prompted for.
- */
-void WB()
-{
-  register int new_fd;		/* Filedescriptor to copy file */
-  int yank_fd;			/* Filedescriptor to buffer */
-  register int cnt;		/* Count check for read/write */
-  int ret = 0;			/* Error check for write */
-  char file[LINE_LEN];		/* Output file */
-  
-/* Checkout the buffer */
-  if ((yank_fd = scratch_file(READ)) == ERRORS) {
-  	error("Buffer is empty.", NIL_PTR);
-  	return;
-  }
-
-/* Get file name */
-  if (get_file("Write buffer to file:", file) != FINE)
-  	return;
-  
-/* Creat the new file */
-  if ((new_fd = creat(file, 0644)) < 0) {
-  	error("Cannot create ", file);
-  	return;
-  }
-
-  status_line("Writing ", file);
-  
-/* Copy buffer into file */
-  while ((cnt = read(yank_fd, text_buffer, sizeof(text_buffer))) > 0)
-  	if (write(new_fd, text_buffer, cnt) != cnt) {
-  		bad_write(new_fd);
-  		ret = ERRORS;
-  		break;
-  	}
-
-/* Clean up open files and status_line */
-  (void) close(new_fd);
-  (void) close(yank_fd);
-
-  if (ret != ERRORS)			/* Bad write */
-  	file_status("Wrote", chars_saved, file, lines_saved, TRUE, FALSE);
-}
-
-/*
- * MA sets mark_line (mark_text) to the current line (text pointer). 
- */
-void MA()
-{
-  mark_line = cur_line;
-  mark_text = cur_text;
-  status_line("Mark set", NIL_PTR);
-}
-
-/*
- * YA() puts the text between the marked position and the current
- * in the buffer.
- */
-void YA()
-{
-  set_up(NO_DELETE);
-}
-
-/*
- * DT() is essentially the same as YA(), but in DT() the text is deleted.
- */
-void DT()
-{
-  set_up(DELETE);
-}
-
-/*
- * Set_up is an interface to the actual yank. It calls checkmark () to check
- * if the marked position is still valid. If it is, yank is called with the
- * arguments in the right order.
- */
-void set_up(remove)
-FLAG remove;				/* DELETE if text should be deleted */
-{
-  switch (checkmark()) {
-  	case NOT_VALID :
-  		error("Mark not set.", NIL_PTR);
-  		return;
-  	case SMALLER :
-  		yank(mark_line, mark_text, cur_line, cur_text, remove);
-  		break;
-  	case BIGGER :
-  		yank(cur_line, cur_text, mark_line, mark_text, remove);
-  		break;
-  	case SAME :		/* Ignore stupid behaviour */
-  		yank_status = EMPTY;
-  		chars_saved = 0L;
-  		status_line("0 characters saved in buffer.", NIL_PTR);
-  		break;
-  }
-}
-
-/*
- * Check_mark() checks if mark_line and mark_text are still valid pointers. If
- * they are it returns SMALLER if the marked position is before the current,
- * BIGGER if it isn't or SAME if somebody didn't get the point.
- * NOT_VALID is returned when mark_line and/or mark_text are no longer valid.
- * Legal() checks if mark_text is valid on the mark_line.
- */
-FLAG checkmark()
-{
-  register LINE *line;
-  FLAG cur_seen = FALSE;
-
-/* Special case: check is mark_line and cur_line are the same. */
-  if (mark_line == cur_line) {
-  	if (mark_text == cur_text)	/* Even same place */
-  		return SAME;
-  	if (legal() == ERRORS)		/* mark_text out of range */
-  		return NOT_VALID;
-  	return (mark_text < cur_text) ? SMALLER : BIGGER;
-  }
-
-/* Start looking for mark_line in the line structure */
-  for (line = header->next; line != tail; line = line->next) {
-  	if (line == cur_line)
-  		cur_seen = TRUE;
-  	else if (line == mark_line)
-  		break;
-  }
-
-/* If we found mark_line (line != tail) check for legality of mark_text */
-  if (line == tail || legal() == ERRORS)
-  	return NOT_VALID;
-
-/* cur_seen is TRUE if cur_line is before mark_line */
-  return (cur_seen == TRUE) ? BIGGER : SMALLER;
-}
-
-/*
- * Legal() checks if mark_text is still a valid pointer.
- */
-int legal()
-{
-  register char *textp = mark_line->text;
-
-/* Locate mark_text on mark_line */
-  while (textp != mark_text && *textp++ != '\0')
-  	;
-  return (*textp == '\0') ? ERRORS : FINE;
-}
-
-/*
- * Yank puts all the text between start_position and end_position into
- * the buffer.
- * The caller must check that the arguments to yank() are valid. (E.g. in
- * the right order)
- */
-void yank(start_line, start_textp, end_line, end_textp, remove)
-LINE *start_line, *end_line;
-char *start_textp, *end_textp;
-FLAG remove;				/* DELETE if text should be deleted */
-{
-  register LINE *line = start_line;
-  register char *textp = start_textp;
-  int fd;
-
-/* Creat file to hold buffer */
-  if ((fd = scratch_file(WRITE)) == ERRORS)
-  	return;
-  
-  chars_saved = 0L;
-  lines_saved = 0;
-  status_line("Saving text.", NIL_PTR);
-
-/* Keep writing chars until the end_location is reached. */
-  while (textp != end_textp) {
-  	if (write_char(fd, *textp) == ERRORS) {
-  		(void) close(fd);
-  		return;
-  	}
-  	if (*textp++ == '\n') {	/* Move to the next line */
-  		line = line->next;
-  		textp = line->text;
-  		lines_saved++;
-  	}
-  	chars_saved++;
-  }
-
-/* Flush the I/O buffer and close file */
-  if (flush_buffer(fd) == ERRORS) {
-  	(void) close(fd);
-  	return;
-  }
-  (void) close(fd);
-  yank_status = VALID;
-
-/*
- * Check if the text should be deleted as well. If it should, the following
- * hack is used to save a lot of code. First move back to the start_position.
- * (This might be the location we're on now!) and them delete the text.
- * It might be a bit confusing the first time somebody uses it.
- * Delete() will fix the screen.
- */
-  if (remove == DELETE) {
-  	move_to(find_x(start_line, start_textp), find_y(start_line));
-  	delete(start_line, start_textp, end_line, end_textp);
-  }
-
-  status_line(num_out(chars_saved), " characters saved in buffer.");
-}
-
-/*
- * Scratch_file() creates a uniq file in /usr/tmp. If the file couldn't
- * be created other combinations of files are tried until a maximum
- * of MAXTRAILS times. After MAXTRAILS times, an error message is given
- * and ERRORS is returned.
- */
-
-#define MAXTRAILS	26
-
-int scratch_file(mode)
-FLAG mode;				/* Can be READ or WRITE permission */
-{
-  static int trials = 0;		/* Keep track of trails */
-  register char *y_ptr, *n_ptr;
-  int fd;				/* Filedescriptor to buffer */
-
-/* If yank_status == NOT_VALID, scratch_file is called for the first time */
-  if (yank_status == NOT_VALID && mode == WRITE) { /* Create new file */
-  	/* Generate file name. */
-	y_ptr = &yank_file[11];
-	n_ptr = num_out((long) getpid());
-	while ((*y_ptr = *n_ptr++) != '\0')
-		y_ptr++;
-	*y_ptr++ = 'a' + trials;
-	*y_ptr = '\0';
-  	/* Check file existence */
-  	if (access(yank_file, 0) == 0 || (fd = creat(yank_file, 0644)) < 0) {
-  		if (trials++ >= MAXTRAILS) {
-  			error("Unable to creat scratchfile.", NIL_PTR);
-  			return ERRORS;
-  		}
-  		else
-  			return scratch_file(mode);/* Have another go */
-  	}
-  }
-  else if ((mode == READ && (fd = open(yank_file, 0)) < 0) ||
-			(mode == WRITE && (fd = creat(yank_file, 0644)) < 0)) {
-  	yank_status = NOT_VALID;
-  	return ERRORS;
-  }
-
-  clear_buffer();
-  return fd;
-}
-
-/*  ========================================================================  *
- *				Search Routines				      *	
- *  ========================================================================  */
-
-/*
- * A regular expression consists of a sequence of:
- * 	1. A normal character matching that character.
- * 	2. A . matching any character.
- * 	3. A ^ matching the begin of a line.
- * 	4. A $ (as last character of the pattern) mathing the end of a line.
- * 	5. A \<character> matching <character>.
- * 	6. A number of characters enclosed in [] pairs matching any of these
- * 	   characters. A list of characters can be indicated by a '-'. So
- * 	   [a-z] matches any letter of the alphabet. If the first character
- * 	   after the '[' is a '^' then the set is negated (matching none of
- * 	   the characters). 
- * 	   A ']', '^' or '-' can be escaped by putting a '\' in front of it.
- * 	7. If one of the expressions as described in 1-6 is followed by a
- * 	   '*' than that expressions matches a sequence of 0 or more of
- * 	   that expression.
- */
-
-char typed_expression[LINE_LEN];	/* Holds previous expr. */
-
-/*
- * SF searches forward for an expression.
- */
-void SF()
-{
-  search("Search forward:", FORWARD);
-}
-
-/*
- * SF searches backwards for an expression.
- */
-void SR()
-{
-  search("Search reverse:", REVERSE);
-}
-
-/*
- * Get_expression() prompts for an expression. If just a return is typed, the
- * old expression is used. If the expression changed, compile() is called and
- * the returning REGEX structure is returned. It returns NIL_REG upon error.
- * The save flag indicates whether the expression should be appended at the
- * message pointer.
- */
-REGEX *get_expression(message)
-char *message;
-{
-  static REGEX program;			/* Program of expression */
-  char exp_buf[LINE_LEN];			/* Buffer for new expr. */
-
-  if (get_string(message, exp_buf, FALSE) == ERRORS)
-  	return NIL_REG;
-  
-  if (exp_buf[0] == '\0' && typed_expression[0] == '\0') {
-  	error("No previous expression.", NIL_PTR);
-  	return NIL_REG;
-  }
-
-  if (exp_buf[0] != '\0') {		/* A new expr. is typed */
-  	copy_string(typed_expression, exp_buf);/* Save expr. */
-  	compile(exp_buf, &program);	/* Compile new expression */
-  }
-
-  if (program.status == REG_ERROR) {	/* Error during compiling */
-  	error(program.result.err_mess, NIL_PTR);
-  	return NIL_REG;
-  }
-  return &program;
-}
-
-/*
- * GR() a replaces all matches from the current position until the end
- * of the file.
- */
-void GR()
-{
-  change("Global replace:", VALID);
-}
-
-/*
- * LR() replaces all matches on the current line.
- */
-void LR()
-{
-  change("Line replace:", NOT_VALID);
-}
-
-/*
- * Change() prompts for an expression and a substitution pattern and changes
- * all matches of the expression into the substitution. change() start looking
- * for expressions at the current line and continues until the end of the file
- * if the FLAG file is VALID.
- */
-void change(message, file)
-char *message;				/* Message to prompt for expression */
-FLAG file;
-{
-  char mess_buf[LINE_LEN];	/* Buffer to hold message */
-  char replacement[LINE_LEN];	/* Buffer to hold subst. pattern */
-  REGEX *program;			/* Program resulting from compilation */
-  register LINE *line = cur_line;
-  register char *textp;
-  long lines = 0L;		/* Nr of lines on which subs occurred */
-  long subs = 0L;			/* Nr of subs made */
-  int page = y;			/* Index to check if line is on screen*/
-
-/* Save message and get expression */
-  copy_string(mess_buf, message);
-  if ((program = get_expression(mess_buf)) == NIL_REG)
-  	return;
-  
-/* Get substitution pattern */
-  build_string(mess_buf, "%s %s by:", mess_buf, typed_expression);
-  if (get_string(mess_buf, replacement, FALSE) == ERRORS)
-  	return;
-  
-  set_cursor(0, ymax);
-  flush();
-/* Substitute until end of file */
-  do {
-  	if (line_check(program, line->text, FORWARD)) {
-  		lines++;
-  		/* Repeat sub. on this line as long as we find a match*/
-  		do {
-  			subs++;	/* Increment subs */
-  			if ((textp = substitute(line, program,replacement))
-								     == NIL_PTR)
-  				return;	/* Line too long */
-  		} while ((program->status & BEGIN_LINE) != BEGIN_LINE &&
-			 (program->status & END_LINE) != END_LINE &&
-					  line_check(program, textp, FORWARD));
-  		/* Check to see if we can print the result */
-  		if (page <= screenmax) {
-  			set_cursor(0, page);
-  			line_print(line);
-  		}
-  	}
-  	if (page <= screenmax)
-  		page++;
-  	line = line->next;
-  } while (line != tail && file == VALID && quit == FALSE);
-
-  copy_string(mess_buf, (quit == TRUE) ? "(Aborted) " : "");
-/* Fix the status line */
-  if (subs == 0L && quit == FALSE)
-  	error("Pattern not found.", NIL_PTR);
-  else if (lines >= REPORT || quit == TRUE) {
-  	build_string(mess_buf, "%s %D substitutions on %D lines.", mess_buf,
-								   subs, lines);
-  	status_line(mess_buf, NIL_PTR);
-  }
-  else if (file == NOT_VALID && subs >= REPORT)
-  	status_line(num_out(subs), " substitutions.");
-  else
-  	clear_status();
-  move_to (x, y);
-}
-
-/*
- * Substitute() replaces the match on this line by the substitute pattern
- * as indicated by the program. Every '&' in the replacement is replaced by 
- * the original match. A \ in the replacement escapes the next character.
- */
-char *substitute(line, program, replacement)
-LINE *line;
-REGEX *program;
-char *replacement;		/* Contains replacement pattern */
-{
-  register char *textp = text_buffer;
-  register char *subp = replacement;
-  char *linep = line->text;
-  char *amp;
-
-  modified = TRUE;
-
-/* Copy part of line until the beginning of the match */
-  while (linep != program->start_ptr)
-  	*textp++ = *linep++;
-  
-/*
- * Replace the match by the substitution pattern. Each occurrence of '&' is
- * replaced by the original match. A \ escapes the next character.
- */
-  while (*subp != '\0' && textp < &text_buffer[MAX_CHARS]) {
-  	if (*subp == '&') {		/* Replace the original match */
-  		amp = program->start_ptr;
-  		while (amp < program->end_ptr && textp<&text_buffer[MAX_CHARS])
-  			*textp++ = *amp++;
-  		subp++;
-  	}
-  	else {
-  		if (*subp == '\\' && *(subp + 1) != '\0')
-  			subp++;
-  		*textp++ = *subp++;
-  	}
-  }
-
-/* Check for line length not exceeding MAX_CHARS */
-  if (length_of(text_buffer) + length_of(program->end_ptr) >= MAX_CHARS) {
-  	error("Substitution result: line too big", NIL_PTR);
-  	return NIL_PTR;
-  }
-
-/* Append last part of line to the new build line */
-  copy_string(textp, program->end_ptr);
-
-/* Free old line and install new one */
-  free_space(line->text);
-  line->text = alloc(length_of(text_buffer) + 1);
-  copy_string(line->text, text_buffer);
-
-  return(line->text + (textp - text_buffer));
-}
-
-/*
- * Search() calls get_expression to fetch the expression. If this went well,
- * the function match() is called which returns the line with the next match.
- * If this line is the NIL_LINE, it means that a match could not be found.
- * Find_x() and find_y() display the right page on the screen, and return
- * the right coordinates for x and y. These coordinates are passed to move_to()
- */
-void search(message, method)
-char *message;
-FLAG method;
-{
-  register REGEX *program;
-  register LINE *match_line;
-
-/* Get the expression */
-  if ((program = get_expression(message)) == NIL_REG)
-  	return;
-
-  set_cursor(0, ymax);
-  flush();
-/* Find the match */
-  if ((match_line = match(program, cur_text, method)) == NIL_LINE) {
-  	if (quit == TRUE)
-  		status_line("Aborted", NIL_PTR);
-  	else
-  		status_line("Pattern not found.", NIL_PTR);
-  	return;
-  }
-
-  move(0, program->start_ptr, find_y(match_line));
-  clear_status();
-}
-
-/*
- * find_y() checks if the matched line is on the current page.  If it is, it
- * returns the new y coordinate, else it displays the correct page with the
- * matched line in the middle and returns the new y value;
- */
-int find_y(match_line)
-LINE *match_line;
-{
-  register LINE *line;
-  register int count = 0;
-
-/* Check if match_line is on the same page as currently displayed. */
-  for (line = top_line; line != match_line && line != bot_line->next;
-  						      line = line->next)
-  	count++;
-  if (line != bot_line->next)
-  	return count;
-
-/* Display new page, with match_line in center. */
-  if ((line = proceed(match_line, -(screenmax >> 1))) == header) {
-  /* Can't display in the middle. Make first line of file top_line */
-  	count = 0;
-  	for (line = header->next; line != match_line; line = line->next)
-  		count++;
-  	line = header->next;
-  }
-  else	/* New page is displayed. Set cursor to middle of page */
-  	count = screenmax >> 1;
-
-/* Reset pointers and redraw the screen */
-  reset(line, 0);
-  RD();
-
-  return count;
-}
-
-/* Opcodes for characters */
-#define	NORMAL		0x0200
-#define DOT		0x0400
-#define EOLN		0x0800
-#define STAR		0x1000
-#define BRACKET		0x2000
-#define NEGATE		0x0100
-#define DONE		0x4000
-
-/* Mask for opcodes and characters */
-#define LOW_BYTE	0x00FF
-#define HIGH_BYTE	0xFF00
-
-/* Previous is the contents of the previous address (ptr) points to */
-#define previous(ptr)		(*((ptr) - 1))
-
-/* Buffer to store outcome of compilation */
-int exp_buffer[BLOCK_SIZE];
-
-/* Errors often used */
-char *too_long = "Regular expression too long";
-
-/*
- * Reg_error() is called by compile() is something went wrong. It set the
- * status of the structure to error, and assigns the error field of the union.
- */
-#define reg_error(str)	program->status = REG_ERROR, \
-  					program->result.err_mess = (str)
-/*
- * Finished() is called when everything went right during compilation. It
- * allocates space for the expression, and copies the expression buffer into
- * this field.
- */
-void finished(program, last_exp)
-register REGEX *program;
-int *last_exp;
-{
-  register int length = (last_exp - exp_buffer) * sizeof(int);
-
-/* Allocate space */
-  program->result.expression = (int *) alloc(length);
-/* Copy expression. (expression consists of ints!) */
-  bcopy(exp_buffer, program->result.expression, length);
-}
-
-/*
- * Compile compiles the pattern into a more comprehensible form and returns a 
- * REGEX structure. If something went wrong, the status field of the structure
- * is set to REG_ERROR and an error message is set into the err_mess field of
- * the union. If all went well the expression is saved and the expression
- * pointer is set to the saved (and compiled) expression.
- */
-void compile(pattern, program)
-register char *pattern;			/* Pointer to pattern */
-REGEX *program;
-{
-  register int *expression = exp_buffer;
-  int *prev_char;			/* Pointer to previous compiled atom */
-  int *acct_field;		/* Pointer to last BRACKET start */
-  FLAG negate;			/* Negate flag for BRACKET */
-  char low_char;			/* Index for chars in BRACKET */
-  char c;
-
-/* Check for begin of line */
-  if (*pattern == '^') {
-  	program->status = BEGIN_LINE;
-  	pattern++;
-  }
-  else {
-  	program->status = 0;
-/* If the first character is a '*' we have to assign it here. */
-  	if (*pattern == '*') {
-  		*expression++ = '*' + NORMAL;
-  		pattern++;
-  	}
-  }
-
-  for (; ;) {
-  	switch (c = *pattern++) {
-  	case '.' :
-  		*expression++ = DOT;
-  		break;
-  	case '$' :
-  		/*
-  		 * Only means EOLN if it is the last char of the pattern
-  		 */
-  		if (*pattern == '\0') {
-  			*expression++ = EOLN | DONE;
-  			program->status |= END_LINE;
-  			finished(program, expression);
-  			return;
-  		}
-  		else
-  			*expression++ = NORMAL + '$';
-  		break;
-  	case '\0' :
-  		*expression++ = DONE;
-  		finished(program, expression);
-  		return;
-  	case '\\' :
-  		/* If last char, it must! mean a normal '\' */
-  		if (*pattern == '\0')
-  			*expression++ = NORMAL + '\\';
-  		else
-  			*expression++ = NORMAL + *pattern++;
-  		break;
-  	case '*' :
-  		/*
-  		 * If the previous expression was a [] find out the
-  		 * begin of the list, and adjust the opcode.
-  		 */
-  		prev_char = expression - 1;
-  		if (*prev_char & BRACKET)
-  			*(expression - (*acct_field & LOW_BYTE))|= STAR;
-  		else
-  			*prev_char |= STAR;
-  		break;
-  	case '[' :
-  		/*
-  		 * First field in expression gives information about
-  		 * the list.
-  		 * The opcode consists of BRACKET and if necessary
-  		 * NEGATE to indicate that the list should be negated
-  		 * and/or STAR to indicate a number of sequence of this 
-  		 * list.
-  		 * The lower byte contains the length of the list.
-  		 */
-  		acct_field = expression++;
-  		if (*pattern == '^') {	/* List must be negated */
-  			pattern++;
-  			negate = TRUE;
-  		}
-  		else
-  			negate = FALSE;
-  		while (*pattern != ']') {
-  			if (*pattern == '\0') {
-  				reg_error("Missing ]");
-  				return;
-  			}
-  			if (*pattern == '\\')
-  				pattern++;
-  			*expression++ = *pattern++;
-  			if (*pattern == '-') {
-  						/* Make list of chars */
-  				low_char = previous(pattern);
-  				pattern++;	/* Skip '-' */
-  				if (low_char++ > *pattern) {
-  					reg_error("Bad range in [a-z]");
-  					return;
-  				}
-  				/* Build list */
-  				while (low_char <= *pattern)
-  					*expression++ = low_char++;
-  				pattern++;
-  			}
-  			if (expression >= &exp_buffer[BLOCK_SIZE]) {
-  				reg_error(too_long);
-  				return;
-  			}
-  		}
-  		pattern++;			/* Skip ']' */
-  		/* Assign length of list in acct field */
-  		if ((*acct_field = (expression - acct_field)) == 1) {
-  			reg_error("Empty []");
-  			return;
-  		}
-  		/* Assign negate and bracket field */
-  		*acct_field |= BRACKET;
-  		if (negate == TRUE)
-  			*acct_field |= NEGATE;
-  		/*
-  		 * Add BRACKET to opcode of last char in field because
-  		 * a '*' may be following the list.
-  		 */
-  		previous(expression) |= BRACKET;
-  		break;
-  	default :
-  		*expression++ = c + NORMAL;
-  	}
-  	if (expression == &exp_buffer[BLOCK_SIZE]) {
-  		reg_error(too_long);
-  		return;
-  	}
-  }
-  /* NOTREACHED */
-}
-
-/*
- * Match gets as argument the program, pointer to place in current line to 
- * start from and the method to search for (either FORWARD or REVERSE).
- * Match() will look through the whole file until a match is found.
- * NIL_LINE is returned if no match could be found.
- */
-LINE *match(program, string, method)
-REGEX *program;
-char *string;
-register FLAG method;
-{
-  register LINE *line = cur_line;
-  char old_char;				/* For saving chars */
-
-/* Corrupted program */
-  if (program->status == REG_ERROR)
-  	return NIL_LINE;
-
-/* Check part of text first */
-  if (!(program->status & BEGIN_LINE)) {
-  	if (method == FORWARD) {
-  		if (line_check(program, string + 1, method) == MATCH)
-  			return cur_line;	/* Match found */
-  	}
-  	else if (!(program->status & END_LINE)) {
-  		old_char = *string;	/* Save char and */
-  		*string = '\n';		/* Assign '\n' for line_check */
-  		if (line_check(program, line->text, method) == MATCH) {
-  			*string = old_char; /* Restore char */
-  			return cur_line;    /* Found match */
-  		}
-  		*string = old_char;	/* No match, but restore char */
-  	}
-  }
-
-/* No match in last (or first) part of line. Check out rest of file */
-  do {
-  	line = (method == FORWARD) ? line->next : line->prev;
-  	if (line->text == NIL_PTR)	/* Header/tail */
-  		continue;
-  	if (line_check(program, line->text, method) == MATCH)
-  		return line;
-  } while (line != cur_line && quit == FALSE);
-
-/* No match found. */
-  return NIL_LINE;
-}
-
-/*
- * Line_check() checks the line (or rather string) for a match. Method
- * indicates FORWARD or REVERSE search. It scans through the whole string
- * until a match is found, or the end of the string is reached.
- */
-int line_check(program, string, method)
-register REGEX *program;
-char *string;
-FLAG method;
-{
-  register char *textp = string;
-
-/* Assign start_ptr field. We might find a match right away! */
-  program->start_ptr = textp;
-
-/* If the match must be anchored, just check the string. */
-  if (program->status & BEGIN_LINE)
-  	return check_string(program, string, NIL_INT);
-  
-  if (method == REVERSE) {
-  	/* First move to the end of the string */
-  	for (textp = string; *textp != '\n'; textp++)
-  		;
-  	/* Start checking string until the begin of the string is met */
-  	while (textp >= string) {
-  		program->start_ptr = textp;
-  		if (check_string(program, textp--, NIL_INT))
-  			return MATCH;
-  	}
-  }
-  else {
-  	/* Move through the string until the end of is found */
-	while (quit == FALSE && *textp != '\0') {
-  		program->start_ptr = textp;
-  		if (check_string(program, textp, NIL_INT))
-  			return MATCH;
-		if (*textp == '\n')
-			break;
-		textp++;
-  	}
-  }
-
-  return NO_MATCH;
-}
-
-/*
- * Check() checks of a match can be found in the given string. Whenever a STAR
- * is found during matching, then the begin position of the string is marked
- * and the maximum number of matches is performed. Then the function star()
- * is called which starts to finish the match from this position of the string
- * (and expression). Check() return MATCH for a match, NO_MATCH is the string 
- * couldn't be matched or REG_ERROR for an illegal opcode in expression.
- */
-int check_string(program, string, expression)
-REGEX *program;
-register char *string;
-int *expression;
-{
-  register int opcode;		/* Holds opcode of next expr. atom */
-  char c;				/* Char that must be matched */
-  char *mark;			/* For marking position */
-  int star_fl;			/* A star has been born */
-
-  if (expression == NIL_INT)
-  	expression = program->result.expression;
-
-/* Loop until end of string or end of expression */
-  while (quit == FALSE && !(*expression & DONE) &&
-					   *string != '\0' && *string != '\n') {
-  	c = *expression & LOW_BYTE;	  /* Extract match char */
-  	opcode = *expression & HIGH_BYTE; /* Extract opcode */
-  	if (star_fl = (opcode & STAR)) {  /* Check star occurrence */
-  		opcode &= ~STAR;	  /* Strip opcode */
-  		mark = string;		  /* Mark current position */
-  	}
-  	expression++;		/* Increment expr. */
-  	switch (opcode) {
-  	case NORMAL :
-  		if (star_fl)
-  			while (*string++ == c)	/* Skip all matches */
-  				;
-  		else if (*string++ != c)
-  			return NO_MATCH;
-  		break;
-  	case DOT :
-  		string++;
-  		if (star_fl)			/* Skip to eoln */
-  			while (*string != '\0' && *string++ != '\n')
-  				;
-  		break;
-  	case NEGATE | BRACKET:
-  	case BRACKET :
-  		if (star_fl)
-  			while (in_list(expression, *string++, c, opcode)
-								       == MATCH)
-  				;
-  		else if (in_list(expression, *string++, c, opcode) == NO_MATCH)
-  			return NO_MATCH;
-  		expression += c - 1;	/* Add length of list */
-  		break;
-  	default :
-  		panic("Corrupted program in check_string()");
-  	}
-  	if (star_fl) 
-  		return star(program, mark, string, expression);
-  }
-  if (*expression & DONE) {
-  	program->end_ptr = string;	/* Match ends here */
-  	/*
-  	 * We might have found a match. The last thing to do is check
-  	 * whether a '$' was given at the end of the expression, or
-  	 * the match was found on a null string. (E.g. [a-z]* always
-  	 * matches) unless a ^ or $ was included in the pattern.
-  	 */
-  	if ((*expression & EOLN) && *string != '\n' && *string != '\0')
-  		return NO_MATCH;
-	if (string == program->start_ptr && !(program->status & BEGIN_LINE)
-					 && !(*expression & EOLN))
-  		return NO_MATCH;
-  	return MATCH;
-  }
-  return NO_MATCH;
-}
-
-/*
- * Star() calls check_string() to find out the longest match possible.
- * It searches backwards until the (in check_string()) marked position
- * is reached, or a match is found.
- */
-int star(program, end_position, string, expression)
-REGEX *program;
-register char *end_position;
-register char *string;
-int *expression;
-{
-  do {
-  	string--;
-  	if (check_string(program, string, expression))
-  		return MATCH;
-  } while (string != end_position);
-
-  return NO_MATCH;
-}
-
-/*
- * In_list() checks if the given character is in the list of []. If it is
- * it returns MATCH. if it isn't it returns NO_MATCH. These returns values
- * are reversed when the NEGATE field in the opcode is present.
- */
-int in_list(list, c, list_length, opcode)
-register int *list;
-char c;
-register int list_length;
-int opcode;
-{
-  if (c == '\0' || c == '\n')	/* End of string, never matches */
-  	return NO_MATCH;
-  while (list_length-- > 1) {	/* > 1, don't check acct_field */
-  	if ((*list & LOW_BYTE) == c)
-  		return (opcode & NEGATE) ? NO_MATCH : MATCH;
-  	list++;
-  }
-  return (opcode & NEGATE) ? MATCH : NO_MATCH;
-}
-
-/*
- * Dummy_line() adds an empty line at the end of the file. This is sometimes
- * useful in combination with the EF and DN command in combination with the
- * Yank command set.
- */
-void dummy_line()
-{
-	(void) line_insert(tail->prev, "\n", 1);
-	tail->prev->shift_count = DUMMY;
-	if (last_y != screenmax) {
-		last_y++;
-		bot_line = bot_line->next;
-	}
-}
Index: trunk/minix/commands/patch/EXTERN.h
===================================================================
--- trunk/minix/commands/patch/EXTERN.h	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/EXTERN.h,v 1.1.1.1 2005/04/21 14:55:10 beng Exp $
- *
- * $Log: EXTERN.h,v $
- * Revision 1.1.1.1  2005/04/21 14:55:10  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:18  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0  86/09/17  15:35:37  lwall
- * Baseline for netwide release.
- * 
- */
-
-#undef EXT
-#define EXT extern
-
-#undef INIT
-#define INIT(x)
-
-#undef DOINIT
Index: trunk/minix/commands/patch/INTERN.h
===================================================================
--- trunk/minix/commands/patch/INTERN.h	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/INTERN.h,v 1.1.1.1 2005/04/21 14:55:10 beng Exp $
- *
- * $Log: INTERN.h,v $
- * Revision 1.1.1.1  2005/04/21 14:55:10  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:18  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0  86/09/17  15:35:58  lwall
- * Baseline for netwide release.
- * 
- */
-
-#undef EXT
-#define EXT
-
-#undef INIT
-#define INIT(x) = x
-
-#define DOINIT
Index: trunk/minix/commands/patch/Makefile
===================================================================
--- trunk/minix/commands/patch/Makefile	(revision 9)
+++ 	(revision )
@@ -1,28 +1,0 @@
-# Makefile for patch
-
-CFLAGS= -O -DVOIDSIG -wo -D_MINIX -D_POSIX_SOURCE -DSMALL
-
-CC = exec cc
-
-OBJ = patch.o pch.o inp.o util.o version.o
-
-all:	patch
-
-patch: $(OBJ)
-	cc -i -o patch $(OBJ)
-	install -S 1M patch
-
-install:	/usr/bin/patch
-
-/usr/bin/patch:	patch
-	install -cs -o bin patch $@
-
-patch.o:	config.h common.h patch.c inp.h pch.h util.h version.h
-pch.o:		config.h common.h pch.c pch.h util.h
-inp.o:		config.h common.h inp.c inp.h util.h
-util.o:		config.h common.h util.c util.h
-version.o:	config.h common.h version.c version.h patchlevel.h util.h
-
-
-clean:	
-	rm -f *.bak *.o *.s core patch
Index: trunk/minix/commands/patch/build
===================================================================
--- trunk/minix/commands/patch/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/patch/common.h
===================================================================
--- trunk/minix/commands/patch/common.h	(revision 9)
+++ 	(revision )
@@ -1,162 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/common.h,v 1.1.1.1 2005/04/21 14:55:10 beng Exp $
- *
- * $Log: common.h,v $
- * Revision 1.1.1.1  2005/04/21 14:55:10  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:18  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0.1.2  88/06/22  20:44:53  lwall
- * patch12: sprintf was declared wrong
- * 
- * Revision 2.0.1.1  88/06/03  15:01:56  lwall
- * patch10: support for shorter extensions.
- * 
- * Revision 2.0  86/09/17  15:36:39  lwall
- * Baseline for netwide release.
- * 
- */
-
-#define DEBUGGING
-
-#include "config.h"
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-/* shut lint up about the following when return value ignored */
-
-#define Signal (void)signal
-#define Unlink (void)unlink
-#define Lseek (void)lseek
-#define Fseek (void)fseek
-#define Fstat (void)fstat
-#define Pclose (void)pclose
-#define Close (void)close
-#define Fclose (void)fclose
-#define Fflush (void)fflush
-#define Sprintf (void)sprintf
-#define Mktemp (void)mktemp
-#define Strcpy (void)strcpy
-#define Strcat (void)strcat
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <assert.h>
-#include <ctype.h>
-#include <signal.h>
-#include <stdio.h>
-
-/* constants */
-
-#define TRUE (1)
-#define FALSE (0)
-
-#define MAXHUNKSIZE 100000		/* is this enough lines? */
-#define INITHUNKMAX 125			/* initial dynamic allocation size */
-#define MAXLINELEN 1024
-#define BUFFERSIZE 1024
-#define SCCSPREFIX "s."
-#define GET "get -e %s"
-#define RCSSUFFIX ",v"
-#define CHECKOUT "co -l %s"
-
-#ifdef FLEXFILENAMES
-#define ORIGEXT ".orig"
-#define REJEXT ".rej"
-#else
-#define ORIGEXT "~"
-#define REJEXT "#"
-#endif
-
-/* handy definitions */
-
-#define Null(t) ((t)0)
-#define Nullch Null(char *)
-#define Nullfp Null(FILE *)
-#define Nulline Null(LINENUM)
-
-#define Ctl(ch) ((ch) & 037)
-
-#define strNE(s1,s2) (strcmp(s1, s2))
-#define strEQ(s1,s2) (!strcmp(s1, s2))
-#define strnNE(s1,s2,l) (strncmp(s1, s2, l))
-#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
-
-/* typedefs */
-
-typedef int bool;
-typedef long LINENUM;			/* must be signed */
-typedef unsigned MEM;			/* what to feed malloc */
-
-/* globals */
-
-EXT int Argc;				/* guess */
-EXT char **Argv;
-EXT int Argc_last;			/* for restarting plan_b */
-EXT char **Argv_last;
-
-EXT struct stat filestat;		/* file statistics area */
-EXT int filemode INIT(0644);
-
-EXT char buf[MAXLINELEN];		/* general purpose buffer */
-EXT FILE *ofp INIT(Nullfp);		/* output file pointer */
-EXT FILE *rejfp INIT(Nullfp);		/* reject file pointer */
-
-EXT bool using_plan_a INIT(TRUE);	/* try to keep everything in memory */
-EXT bool out_of_mem INIT(FALSE);	/* ran out of memory in plan a */
-
-#define MAXFILEC 2
-EXT int filec INIT(0);			/* how many file arguments? */
-EXT char *filearg[MAXFILEC];
-EXT bool ok_to_create_file INIT(FALSE);
-EXT char *bestguess INIT(Nullch);	/* guess at correct filename */
-
-EXT char *outname INIT(Nullch);
-EXT char rejname[128];
-
-EXT char *origext INIT(Nullch);
-EXT char *origprae INIT(Nullch);
-
-EXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX");
-EXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX");	/* might want /usr/tmp here */
-EXT char TMPREJNAME[] INIT("/tmp/patchrXXXXXX");
-EXT char TMPPATNAME[] INIT("/tmp/patchpXXXXXX");
-#ifdef SMALL
-EXT char TMPSTRNAME[] INIT("/tmp/patchsXXXXXX");
-#endif
-EXT bool toutkeep INIT(FALSE);
-EXT bool trejkeep INIT(FALSE);
-
-EXT LINENUM last_offset INIT(0);
-#ifdef DEBUGGING
-EXT int debug INIT(0);
-#endif
-EXT LINENUM maxfuzz INIT(2);
-EXT bool force INIT(FALSE);
-EXT bool verbose INIT(TRUE);
-EXT bool reverse INIT(FALSE);
-EXT bool noreverse INIT(FALSE);
-EXT bool skip_rest_of_patch INIT(FALSE);
-EXT int strippath INIT(957);
-EXT bool canonicalize INIT(FALSE);
-
-#define CONTEXT_DIFF 1
-#define NORMAL_DIFF 2
-#define ED_DIFF 3
-#define NEW_CONTEXT_DIFF 4
-EXT int diff_type INIT(0);
-
-EXT bool do_defines INIT(FALSE);	/* patch using ifdef, ifndef, etc. */
-EXT char if_defined[128];		/* #ifdef xyzzy */
-EXT char not_defined[128];		/* #ifndef xyzzy */
-EXT char else_defined[] INIT("#else\n");/* #else */
-EXT char end_defined[128];		/* #endif xyzzy */
-
-EXT char *revision INIT(Nullch);	/* prerequisite revision, if any */
-
-_PROTOTYPE(void my_exit , (int status ));
Index: trunk/minix/commands/patch/config.h
===================================================================
--- trunk/minix/commands/patch/config.h	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-/* config.h
- * This file was produced by running the Configure script.
- * Feel free to modify any of this as the need arises.
- */
-
-/* How many register declarations are paid attention to? */
-
-#define Reg1 register
-#define Reg2 register
-#define Reg3
-#define Reg4
-#define Reg5
-#define Reg6
-#define Reg7 
-#define Reg8 
-#define Reg9 
-#define Reg10 
-#define Reg11 
-#define Reg12 
-#define Reg13 
-#define Reg14 
-#define Reg15 
-#define Reg16 
Index: trunk/minix/commands/patch/inp.c
===================================================================
--- trunk/minix/commands/patch/inp.c	(revision 9)
+++ 	(revision )
@@ -1,331 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/inp.c,v 1.1.1.1 2005/04/21 14:55:10 beng Exp $
- *
- * $Log: inp.c,v $
- * Revision 1.1.1.1  2005/04/21 14:55:10  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:18  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0.1.1  88/06/03  15:06:13  lwall
- * patch10: made a little smarter about sccs files
- * 
- * Revision 2.0  86/09/17  15:37:02  lwall
- * Baseline for netwide release.
- * 
- */
-
-#include "EXTERN.h"
-#include "common.h"
-#include "util.h"
-#include "pch.h"
-#include "INTERN.h"
-#include "inp.h"
-
-/* Input-file-with-indexable-lines abstract type */
-
-static long i_size;			/* size of the input file */
-static char *i_womp;			/* plan a buffer for entire file */
-static char **i_ptr;			/* pointers to lines in i_womp */
-
-static int tifd = -1;			/* plan b virtual string array */
-static char *tibuf[2];			/* plan b buffers */
-static LINENUM tiline[2] = {-1, -1};	/* 1st line in each buffer */
-static LINENUM lines_per_buf;		/* how many lines per buffer */
-static int tireclen;			/* length of records in tmp file */
-
-/* New patch--prepare to edit another file. */
-
-void
-re_input()
-{
-    if (using_plan_a) {
-	i_size = 0;
-#ifndef lint
-	if (i_ptr != Null(char**))
-	    free((char *)i_ptr);
-#endif
-	if (i_womp != Nullch)
-	    free(i_womp);
-	i_womp = Nullch;
-	i_ptr = Null(char **);
-    }
-    else {
-#ifndef SMALL
-	using_plan_a = TRUE;		/* maybe the next one is smaller */
-#endif
-	Close(tifd);
-	tifd = -1;
-	free(tibuf[0]);
-	free(tibuf[1]);
-	tibuf[0] = tibuf[1] = Nullch;
-	tiline[0] = tiline[1] = -1;
-	tireclen = 0;
-    }
-}
-
-/* Constuct the line index, somehow or other. */
-
-void
-scan_input(filename)
-char *filename;
-{
-#ifndef SMALL
-    if (!plan_a(filename))
-#endif
-	plan_b(filename);
-    if (verbose) {
-	say3("Patching file %s using Plan %s...\n", filename,
-	  (using_plan_a ? "A" : "B") );
-    }
-}
-
-#ifndef SMALL
-/* Try keeping everything in memory. */
-
-bool
-plan_a(filename)
-char *filename;
-{
-    int ifd;
-    Reg1 char *s;
-    Reg2 LINENUM iline;
-
-    if (ok_to_create_file && stat(filename, &filestat) < 0) {
-	if (verbose)
-	    say2("(Creating file %s...)\n",filename);
-	makedirs(filename, TRUE);
-	close(creat(filename, 0666));
-    }
-    if (stat(filename, &filestat) < 0) {
-	Sprintf(buf, "RCS/%s%s", filename, RCSSUFFIX);
-	if (stat(buf, &filestat) >= 0 || stat(buf+4, &filestat) >= 0) {
-	    Sprintf(buf, CHECKOUT, filename);
-	    if (verbose)
-		say2("Can't find %s--attempting to check it out from RCS.\n",
-		    filename);
-	    if (system(buf) || stat(filename, &filestat))
-		fatal2("Can't check out %s.\n", filename);
-	}
-	else {
-	    Sprintf(buf+20, "SCCS/%s%s", SCCSPREFIX, filename);
-	    if (stat(s=buf+20, &filestat) >= 0 ||
-	      stat(s=buf+25, &filestat) >= 0) {
-		Sprintf(buf, GET, s);
-		if (verbose)
-		    say2("Can't find %s--attempting to get it from SCCS.\n",
-			filename);
-		if (system(buf) || stat(filename, &filestat))
-		    fatal2("Can't get %s.\n", filename);
-	    }
-	    else
-		fatal2("Can't find %s.\n", filename);
-	}
-    }
-    filemode = filestat.st_mode;
-    if ((filemode & S_IFMT) & ~S_IFREG)
-	fatal2("%s is not a normal file--can't patch.\n", filename);
-    i_size = filestat.st_size;
-    if (out_of_mem) {
-	set_hunkmax();		/* make sure dynamic arrays are allocated */
-	out_of_mem = FALSE;
-	return FALSE;			/* force plan b because plan a bombed */
-    }
-#ifdef lint
-    i_womp = Nullch;
-#else
-    i_womp = malloc((MEM)(i_size+2));	/* lint says this may alloc less than */
-					/* i_size, but that's okay, I think. */
-#endif
-    if (i_womp == Nullch)
-	return FALSE;
-    if ((ifd = open(filename, 0)) < 0)
-	fatal2("Can't open file %s\n", filename);
-#ifndef lint
-    if (read(ifd, i_womp, (int)i_size) != i_size) {
-	Close(ifd);	/* probably means i_size > 15 or 16 bits worth */
-	free(i_womp);	/* at this point it doesn't matter if i_womp was */
-	return FALSE;	/*   undersized. */
-    }
-#endif
-    Close(ifd);
-    if (i_size && i_womp[i_size-1] != '\n')
-	i_womp[i_size++] = '\n';
-    i_womp[i_size] = '\0';
-
-    /* count the lines in the buffer so we know how many pointers we need */
-
-    iline = 0;
-    for (s=i_womp; *s; s++) {
-	if (*s == '\n')
-	    iline++;
-    }
-#ifdef lint
-    i_ptr = Null(char**);
-#else
-    i_ptr = (char **)malloc((MEM)((iline + 2) * sizeof(char *)));
-#endif
-    if (i_ptr == Null(char **)) {	/* shucks, it was a near thing */
-	free((char *)i_womp);
-	return FALSE;
-    }
-    
-    /* now scan the buffer and build pointer array */
-
-    iline = 1;
-    i_ptr[iline] = i_womp;
-    for (s=i_womp; *s; s++) {
-	if (*s == '\n')
-	    i_ptr[++iline] = s+1;	/* these are NOT null terminated */
-    }
-    input_lines = iline - 1;
-
-    /* now check for revision, if any */
-
-    if (revision != Nullch) { 
-	if (!rev_in_string(i_womp)) {
-	    if (force) {
-		if (verbose)
-		    say2(
-"Warning: this file doesn't appear to be the %s version--patching anyway.\n",
-			revision);
-	    }
-	    else {
-		ask2(
-"This file doesn't appear to be the %s version--patch anyway? [n] ",
-		    revision);
-	    if (*buf != 'y')
-		fatal1("Aborted.\n");
-	    }
-	}
-	else if (verbose)
-	    say2("Good.  This file appears to be the %s version.\n",
-		revision);
-    }
-    return TRUE;			/* plan a will work */
-}
-#endif
-
-/* Keep (virtually) nothing in memory. */
-
-void
-plan_b(filename)
-char *filename;
-{
-    Reg3 FILE *ifp;
-    Reg1 int i = 0;
-    Reg2 int maxlen = 1;
-    Reg4 bool found_revision = (revision == Nullch);
-
-    using_plan_a = FALSE;
-    if ((ifp = fopen(filename, "r")) == Nullfp)
-	fatal2("Can't open file %s\n", filename);
-    if ((tifd = creat(TMPINNAME, 0666)) < 0)
-	fatal2("Can't open file %s\n", TMPINNAME);
-    while (fgets(buf, sizeof buf, ifp) != Nullch) {
-	if (revision != Nullch && !found_revision && rev_in_string(buf))
-	    found_revision = TRUE;
-	if ((i = strlen(buf)) > maxlen)
-	    maxlen = i;			/* find longest line */
-    }
-    if (revision != Nullch) {
-	if (!found_revision) {
-	    if (force) {
-		if (verbose)
-		    say2(
-"Warning: this file doesn't appear to be the %s version--patching anyway.\n",
-			revision);
-	    }
-	    else {
-		ask2(
-"This file doesn't appear to be the %s version--patch anyway? [n] ",
-		    revision);
-		if (*buf != 'y')
-		    fatal1("Aborted.\n");
-	    }
-	}
-	else if (verbose)
-	    say2("Good.  This file appears to be the %s version.\n",
-		revision);
-    }
-    Fseek(ifp, 0L, 0);		/* rewind file */
-    lines_per_buf = BUFFERSIZE / maxlen;
-    tireclen = maxlen;
-    tibuf[0] = (char *)malloc((MEM)(BUFFERSIZE + 1));
-    tibuf[1] = (char *)malloc((MEM)(BUFFERSIZE + 1));
-    if (tibuf[1] == Nullch)
-	fatal1("Can't seem to get enough memory.\n");
-    for (i=1; ; i++) {
-	if (! (i % lines_per_buf))	/* new block */
-	    if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
-		fatal1("patch: can't write temp file.\n");
-	if (fgets(tibuf[0] + maxlen * (i%lines_per_buf), maxlen + 1, ifp)
-	  == Nullch) {
-	    input_lines = i - 1;
-	    if (i % lines_per_buf)
-		if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
-		    fatal1("patch: can't write temp file.\n");
-	    break;
-	}
-    }
-    Fclose(ifp);
-    Close(tifd);
-    if ((tifd = open(TMPINNAME, 0)) < 0) {
-	fatal2("Can't reopen file %s\n", TMPINNAME);
-    }
-}
-
-/* Fetch a line from the input file, \n terminated, not necessarily \0. */
-
-char *
-ifetch(line,whichbuf)
-Reg1 LINENUM line;
-int whichbuf;				/* ignored when file in memory */
-{
-    if (line < 1 || line > input_lines)
-	return "";
-    if (using_plan_a)
-	return i_ptr[line];
-    else {
-	LINENUM offline = line % lines_per_buf;
-	LINENUM baseline = line - offline;
-
-	if (tiline[0] == baseline)
-	    whichbuf = 0;
-	else if (tiline[1] == baseline)
-	    whichbuf = 1;
-	else {
-	    tiline[whichbuf] = baseline;
-#ifndef lint		/* complains of long accuracy */
-	    Lseek(tifd, (long)baseline / lines_per_buf * BUFFERSIZE, 0);
-#endif
-	    if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
-		fatal2("Error reading tmp file %s.\n", TMPINNAME);
-	}
-	return tibuf[whichbuf] + (tireclen*offline);
-    }
-}
-
-/* True if the string argument contains the revision number we want. */
-
-bool
-rev_in_string(string)
-char *string;
-{
-    Reg1 char *s;
-    Reg2 int patlen;
-
-    if (revision == Nullch)
-	return TRUE;
-    patlen = strlen(revision);
-    if (strnEQ(string,revision,patlen) && isspace(s[patlen]))
-	return TRUE;
-    for (s = string; *s; s++) {
-	if (isspace(*s) && strnEQ(s+1, revision, patlen) && 
-		isspace(s[patlen+1] )) {
-	    return TRUE;
-	}
-    }
-    return FALSE;
-}
-
Index: trunk/minix/commands/patch/inp.h
===================================================================
--- trunk/minix/commands/patch/inp.h	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/inp.h,v 1.1.1.1 2005/04/21 14:55:10 beng Exp $
- *
- * $Log: inp.h,v $
- * Revision 1.1.1.1  2005/04/21 14:55:10  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:18  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0  86/09/17  15:37:25  lwall
- * Baseline for netwide release.
- * 
- */
-
-EXT LINENUM input_lines INIT(0);	/* how long is input file in lines */
-EXT LINENUM last_frozen_line INIT(0);	/* how many input lines have been */
-					/* irretractibly output */
-
-_PROTOTYPE(bool rev_in_string , (char *string ));
-_PROTOTYPE(void scan_input , (char *filename ));
-_PROTOTYPE(bool plan_a , (char *filename )); 
-_PROTOTYPE(void plan_b , (char *filename ));
-_PROTOTYPE(char *ifetch , (Reg1 LINENUM line , int whichbuf ));
-_PROTOTYPE(void re_input , (void));
Index: trunk/minix/commands/patch/patch.c
===================================================================
--- trunk/minix/commands/patch/patch.c	(revision 9)
+++ 	(revision )
@@ -1,843 +1,0 @@
-char rcsid[] =
-	"$Header: /cvsup/minix/src/commands/patch/patch.c,v 1.1.1.1 2005/04/21 14:55:10 beng Exp $";
-
-/* patch - a program to apply diffs to original files
- *
- * Copyright 1986, Larry Wall
- *
- * This program may be copied as long as you don't try to make any
- * money off of it, or pretend that you wrote it.
- *
- * $Log: patch.c,v $
- * Revision 1.1.1.1  2005/04/21 14:55:10  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:19  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0.1.6  88/06/22  20:46:39  lwall
- * patch12: rindex() wasn't declared
- * 
- * Revision 2.0.1.5  88/06/03  15:09:37  lwall
- * patch10: exit code improved.
- * patch10: better support for non-flexfilenames.
- * 
- * Revision 2.0.1.4  87/02/16  14:00:04  lwall
- * Short replacement caused spurious "Out of sync" message.
- * 
- * Revision 2.0.1.3  87/01/30  22:45:50  lwall
- * Improved diagnostic on sync error.
- * Moved do_ed_script() to pch.c.
- * 
- * Revision 2.0.1.2  86/11/21  09:39:15  lwall
- * Fuzz factor caused offset of installed lines.
- * 
- * Revision 2.0.1.1  86/10/29  13:10:22  lwall
- * Backwards search could terminate prematurely.
- * 
- * Revision 2.0  86/09/17  15:37:32  lwall
- * Baseline for netwide release.
- * 
- * Revision 1.5  86/08/01  20:53:24  lwall
- * Changed some %d's to %ld's.
- * Linted.
- * 
- * Revision 1.4  86/08/01  19:17:29  lwall
- * Fixes for machines that can't vararg.
- * Added fuzz factor.
- * Generalized -p.
- * General cleanup.
- * 
- * 85/08/15 van%ucbmonet@berkeley
- * Changes for 4.3bsd diff -c.
- *
- * Revision 1.3  85/03/26  15:07:43  lwall
- * Frozen.
- * 
- * Revision 1.2.1.9  85/03/12  17:03:35  lwall
- * Changed pfp->_file to fileno(pfp).
- * 
- * Revision 1.2.1.8  85/03/12  16:30:43  lwall
- * Check i_ptr and i_womp to make sure they aren't null before freeing.
- * Also allow ed output to be suppressed.
- * 
- * Revision 1.2.1.7  85/03/12  15:56:13  lwall
- * Added -p option from jromine@uci-750a.
- * 
- * Revision 1.2.1.6  85/03/12  12:12:51  lwall
- * Now checks for normalness of file to patch.
- * 
- * Revision 1.2.1.5  85/03/12  11:52:12  lwall
- * Added -D (#ifdef) option from joe@fluke.
- * 
- * Revision 1.2.1.4  84/12/06  11:14:15  lwall
- * Made smarter about SCCS subdirectories.
- * 
- * Revision 1.2.1.3  84/12/05  11:18:43  lwall
- * Added -l switch to do loose string comparison.
- * 
- * Revision 1.2.1.2  84/12/04  09:47:13  lwall
- * Failed hunk count not reset on multiple patch file.
- * 
- * Revision 1.2.1.1  84/12/04  09:42:37  lwall
- * Branch for sdcrdcf changes.
- * 
- * Revision 1.2  84/11/29  13:29:51  lwall
- * Linted.  Identifiers uniqified.  Fixed i_ptr malloc() bug.  Fixed
- * multiple calls to mktemp().  Will now work on machines that can only
- * read 32767 chars.  Added -R option for diffs with new and old swapped.
- * Various cosmetic changes.
- * 
- * Revision 1.1  84/11/09  17:03:58  lwall
- * Initial revision
- * 
- */
-/*
- * 1992-01-15
- * Modified by Saeko & Kouichi Hirabayashi to fit small memory (64K+64K)
- * system by adding "#if[n]def SMALL" parts.
- */
-
-#include "INTERN.h"
-#include "common.h"
-#include "EXTERN.h"
-#include "version.h"
-#include "util.h"
-#include "pch.h"
-#include "inp.h"
-
-/* procedures */
-
-_PROTOTYPE(int main , (int argc , char **argv ));
-_PROTOTYPE(void reinitialize_almost_everything , (void));
-_PROTOTYPE(void get_some_switches , (void));
-_PROTOTYPE(LINENUM locate_hunk , (LINENUM fuzz ));
-_PROTOTYPE(void abort_hunk , (void));
-_PROTOTYPE(void apply_hunk , (LINENUM where ));
-_PROTOTYPE(void init_output , (char *name ));
-_PROTOTYPE(void init_reject , (char *name ));
-_PROTOTYPE(void copy_till , (Reg1 LINENUM lastline ));
-_PROTOTYPE(void spew_output , (void));
-_PROTOTYPE(void dump_line , (LINENUM line ));
-_PROTOTYPE(bool patch_match , (LINENUM base , LINENUM offset , LINENUM fuzz ));
-_PROTOTYPE(bool similar , (Reg1 char *a , Reg2 char *b , Reg3 int len ));
-
-/* Apply a set of diffs as appropriate. */
-
-int main(argc,argv)
-int argc;
-char **argv;
-{
-    LINENUM where;
-    LINENUM newwhere;
-    LINENUM fuzz;
-    LINENUM mymaxfuzz;
-    int hunk = 0;
-    int failed = 0;
-    int failtotal = 0;
-    int i;
-
-    setbuf(stderr, serrbuf);
-    for (i = 0; i<MAXFILEC; i++)
-	filearg[i] = Nullch;
-    Mktemp(TMPOUTNAME);
-    Mktemp(TMPINNAME);
-    Mktemp(TMPREJNAME);
-    Mktemp(TMPPATNAME);
-#ifdef SMALL
-    Mktemp(TMPSTRNAME);
-#endif
-
-    /* parse switches */
-    Argc = argc;
-    Argv = argv;
-    get_some_switches();
-    
-    /* make sure we clean up /tmp in case of disaster */
-    set_signals(0);
-
-    for (
-	open_patch_file(filearg[1]);
-	there_is_another_patch();
-	reinitialize_almost_everything()
-    ) {					/* for each patch in patch file */
-
-	if (outname == Nullch)
-	    outname = savestr(filearg[0]);
-    
-	/* initialize the patched file */
-	if (!skip_rest_of_patch)
-	    init_output(TMPOUTNAME);
-    
-	/* for ed script just up and do it and exit */
-	if (diff_type == ED_DIFF) {
-	    do_ed_script();
-	    continue;
-	}
-    
-	/* initialize reject file */
-	init_reject(TMPREJNAME);
-    
-	/* find out where all the lines are */
-	if (!skip_rest_of_patch)
-	    scan_input(filearg[0]);
-    
-	/* from here on, open no standard i/o files, because malloc */
-	/* might misfire and we can't catch it easily */
-    
-	/* apply each hunk of patch */
-	hunk = 0;
-	failed = 0;
-	out_of_mem = FALSE;
-	while (another_hunk()) {
-	    hunk++;
-	    fuzz = Nulline;
-	    mymaxfuzz = pch_context();
-	    if (maxfuzz < mymaxfuzz)
-		mymaxfuzz = maxfuzz;
-	    if (!skip_rest_of_patch) {
-		do {
-		    where = locate_hunk(fuzz);
-		    if (hunk == 1 && where == Nulline && !force) {
-						/* dwim for reversed patch? */
-			if (!pch_swap()) {
-			    if (fuzz == Nulline)
-				say1(
-"Not enough memory to try swapped hunk!  Assuming unswapped.\n");
-			    continue;
-			}
-			reverse = !reverse;
-			where = locate_hunk(fuzz);  /* try again */
-			if (where == Nulline) {	    /* didn't find it swapped */
-			    if (!pch_swap())         /* put it back to normal */
-				fatal1("Lost hunk on alloc error!\n");
-			    reverse = !reverse;
-			}
-			else if (noreverse) {
-			    if (!pch_swap())         /* put it back to normal */
-				fatal1("Lost hunk on alloc error!\n");
-			    reverse = !reverse;
-			    say1(
-"Ignoring previously applied (or reversed) patch.\n");
-			    skip_rest_of_patch = TRUE;
-			}
-			else {
-			    ask3(
-"%seversed (or previously applied) patch detected!  %s -R? [y] ",
-				reverse ? "R" : "Unr",
-				reverse ? "Assume" : "Ignore");
-			    if (*buf == 'n') {
-				ask1("Apply anyway? [n] ");
-				if (*buf != 'y')
-				    skip_rest_of_patch = TRUE;
-				where = Nulline;
-				reverse = !reverse;
-				if (!pch_swap())  /* put it back to normal */
-				    fatal1("Lost hunk on alloc error!\n");
-			    }
-			}
-		    }
-		} while (!skip_rest_of_patch && where == Nulline &&
-		    ++fuzz <= mymaxfuzz);
-
-		if (skip_rest_of_patch) {		/* just got decided */
-		    Fclose(ofp);
-		    ofp = Nullfp;
-		}
-	    }
-
-	    newwhere = pch_newfirst() + last_offset;
-	    if (skip_rest_of_patch) {
-		abort_hunk();
-		failed++;
-		if (verbose)
-		    say3("Hunk #%d ignored at %ld.\n", hunk, newwhere);
-	    }
-	    else if (where == Nulline) {
-		abort_hunk();
-		failed++;
-		if (verbose)
-		    say3("Hunk #%d failed at %ld.\n", hunk, newwhere);
-	    }
-	    else {
-		apply_hunk(where);
-		if (verbose) {
-		    say3("Hunk #%d succeeded at %ld", hunk, newwhere);
-		    if (fuzz)
-			say2(" with fuzz %ld", fuzz);
-		    if (last_offset)
-			say3(" (offset %ld line%s)",
-			    last_offset, last_offset==1L?"":"s");
-		    say1(".\n");
-		}
-	    }
-	}
-
-	if (out_of_mem && using_plan_a) {
-	    Argc = Argc_last;
-	    Argv = Argv_last;
-	    say1("\n\nRan out of memory using Plan A--trying again...\n\n");
-	    continue;
-	}
-    
-	assert(hunk);
-    
-	/* finish spewing out the new file */
-	if (!skip_rest_of_patch)
-	    spew_output();
-	
-	/* and put the output where desired */
-	ignore_signals();
-	if (!skip_rest_of_patch) {
-	    if (move_file(TMPOUTNAME, outname) < 0) {
-		toutkeep = TRUE;
-		chmod(TMPOUTNAME, filemode);
-	    }
-	    else
-		chmod(outname, filemode);
-	}
-	Fclose(rejfp);
-	rejfp = Nullfp;
-	if (failed) {
-	    failtotal += failed;
-	    if (!*rejname) {
-		Strcpy(rejname, outname);
-#ifndef FLEXFILENAMES
-		{
-		    char *s = rindex(rejname,'/');
-
-		    if (!s)
-			s = rejname;
-		    if (strlen(s) > 13)
-			if (s[12] == '.')	/* try to preserve difference */
-			    s[12] = s[13];	/* between .h, .c, .y, etc. */
-			s[13] = '\0';
-		}
-#endif
-		Strcat(rejname, REJEXT);
-	    }
-	    if (skip_rest_of_patch) {
-		say4("%d out of %d hunks ignored--saving rejects to %s\n",
-		    failed, hunk, rejname);
-	    }
-	    else {
-		say4("%d out of %d hunks failed--saving rejects to %s\n",
-		    failed, hunk, rejname);
-	    }
-	    if (move_file(TMPREJNAME, rejname) < 0)
-		trejkeep = TRUE;
-	}
-	set_signals(1);
-    }
-#ifdef SMALL
-    if (sfp != Nullfp)
-	Fclose(sfp);
-#endif
-    my_exit(failtotal);
-}
-
-/* Prepare to find the next patch to do in the patch file. */
-
-void
-reinitialize_almost_everything()
-{
-    re_patch();
-    re_input();
-
-    input_lines = 0;
-    last_frozen_line = 0;
-
-    filec = 0;
-    if (filearg[0] != Nullch && !out_of_mem) {
-	free(filearg[0]);
-	filearg[0] = Nullch;
-    }
-
-    if (outname != Nullch) {
-	free(outname);
-	outname = Nullch;
-    }
-
-    last_offset = 0;
-
-    diff_type = 0;
-
-    if (revision != Nullch) {
-	free(revision);
-	revision = Nullch;
-    }
-
-    reverse = FALSE;
-    skip_rest_of_patch = FALSE;
-
-    get_some_switches();
-
-    if (filec >= 2)
-	fatal1("You may not change to a different patch file.\n");
-}
-
-/* Process switches and filenames up to next '+' or end of list. */
-
-void
-get_some_switches()
-{
-    Reg1 char *s;
-
-    rejname[0] = '\0';
-    Argc_last = Argc;
-    Argv_last = Argv;
-    if (!Argc)
-	return;
-    for (Argc--,Argv++; Argc; Argc--,Argv++) {
-	s = Argv[0];
-	if (strEQ(s, "+")) {
-	    return;			/* + will be skipped by for loop */
-	}
-	if (*s != '-' || !s[1]) {
-	    if (filec == MAXFILEC)
-		fatal1("Too many file arguments.\n");
-	    filearg[filec++] = savestr(s);
-	}
-	else {
-	    switch (*++s) {
-	    case 'b':
-		origext = savestr(Argv[1]);
-		Argc--,Argv++;
-		break;
-	    case 'B':
-		origprae = savestr(Argv[1]);
-		Argc--,Argv++;
-		break;
-	    case 'c':
-		diff_type = CONTEXT_DIFF;
-		break;
-	    case 'd':
-		if (!*++s) {
-		    Argc--,Argv++;
-		    s = Argv[0];
-		}
-		if (chdir(s) < 0)
-		    fatal2("Can't cd to %s.\n", s);
-		break;
-	    case 'D':
-	    	do_defines = TRUE;
-		if (!*++s) {
-		    Argc--,Argv++;
-		    s = Argv[0];
-		}
-		if (!isalpha(*s))
-		    fatal1("Argument to -D not an identifier.\n");
-		Sprintf(if_defined, "#ifdef %s\n", s);
-		Sprintf(not_defined, "#ifndef %s\n", s);
-		Sprintf(end_defined, "#endif /* %s */\n", s);
-		break;
-	    case 'e':
-		diff_type = ED_DIFF;
-		break;
-	    case 'f':
-		force = TRUE;
-		break;
-	    case 'F':
-		if (*++s == '=')
-		    s++;
-		maxfuzz = atoi(s);
-		break;
-	    case 'l':
-		canonicalize = TRUE;
-		break;
-	    case 'n':
-		diff_type = NORMAL_DIFF;
-		break;
-	    case 'N':
-		noreverse = TRUE;
-		break;
-	    case 'o':
-		outname = savestr(Argv[1]);
-		Argc--,Argv++;
-		break;
-	    case 'p':
-		if (*++s == '=')
-		    s++;
-		strippath = atoi(s);
-		break;
-	    case 'r':
-		Strcpy(rejname, Argv[1]);
-		Argc--,Argv++;
-		break;
-	    case 'R':
-		reverse = TRUE;
-		break;
-	    case 's':
-		verbose = FALSE;
-		break;
-	    case 'S':
-		skip_rest_of_patch = TRUE;
-		break;
-	    case 'v':
-		version();
-		break;
-#ifdef DEBUGGING
-	    case 'x':
-		debug = atoi(s+1);
-		break;
-#endif
-	    default:
-		fatal2("Unrecognized switch: %s\n", Argv[0]);
-	    }
-	}
-    }
-}
-
-/* Attempt to find the right place to apply this hunk of patch. */
-
-LINENUM
-locate_hunk(fuzz)
-LINENUM fuzz;
-{
-    Reg1 LINENUM first_guess = pch_first() + last_offset;
-    Reg2 LINENUM offset;
-    LINENUM pat_lines = pch_ptrn_lines();
-    Reg3 LINENUM max_pos_offset = input_lines - first_guess
-				- pat_lines + 1; 
-    Reg4 LINENUM max_neg_offset = first_guess - last_frozen_line - 1
-				+ pch_context();
-
-    if (!pat_lines)			/* null range matches always */
-	return first_guess;
-    if (max_neg_offset >= first_guess)	/* do not try lines < 0 */
-	max_neg_offset = first_guess - 1;
-    if (first_guess <= input_lines && patch_match(first_guess, Nulline, fuzz))
-	return first_guess;
-    for (offset = 1; ; offset++) {
-	Reg5 bool check_after = (offset <= max_pos_offset);
-	Reg6 bool check_before = (offset <= max_neg_offset);
-
-	if (check_after && patch_match(first_guess, offset, fuzz)) {
-#ifdef DEBUGGING
-	    if (debug & 1)
-		say3("Offset changing from %ld to %ld\n", last_offset, offset);
-#endif
-	    last_offset = offset;
-	    return first_guess+offset;
-	}
-	else if (check_before && patch_match(first_guess, -offset, fuzz)) {
-#ifdef DEBUGGING
-	    if (debug & 1)
-		say3("Offset changing from %ld to %ld\n", last_offset, -offset);
-#endif
-	    last_offset = -offset;
-	    return first_guess-offset;
-	}
-	else if (!check_before && !check_after)
-	    return Nulline;
-    }
-}
-
-/* We did not find the pattern, dump out the hunk so they can handle it. */
-
-void
-abort_hunk()
-{
-    Reg1 LINENUM i;
-    Reg2 LINENUM pat_end = pch_end();
-    /* add in last_offset to guess the same as the previous successful hunk */
-    LINENUM oldfirst = pch_first() + last_offset;
-    LINENUM newfirst = pch_newfirst() + last_offset;
-    LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1;
-    LINENUM newlast = newfirst + pch_repl_lines() - 1;
-    char *stars = (diff_type == NEW_CONTEXT_DIFF ? " ****" : "");
-    char *minuses = (diff_type == NEW_CONTEXT_DIFF ? " ----" : " -----");
-
-    fprintf(rejfp, "***************\n");
-    for (i=0; i<=pat_end; i++) {
-	switch (pch_char(i)) {
-	case '*':
-	    if (oldlast < oldfirst)
-		fprintf(rejfp, "*** 0%s\n", stars);
-	    else if (oldlast == oldfirst)
-		fprintf(rejfp, "*** %ld%s\n", oldfirst, stars);
-	    else
-		fprintf(rejfp, "*** %ld,%ld%s\n", oldfirst, oldlast, stars);
-	    break;
-	case '=':
-	    if (newlast < newfirst)
-		fprintf(rejfp, "--- 0%s\n", minuses);
-	    else if (newlast == newfirst)
-		fprintf(rejfp, "--- %ld%s\n", newfirst, minuses);
-	    else
-		fprintf(rejfp, "--- %ld,%ld%s\n", newfirst, newlast, minuses);
-	    break;
-	case '\n':
-	    fprintf(rejfp, "%s", pfetch(i));
-	    break;
-	case ' ': case '-': case '+': case '!':
-	    fprintf(rejfp, "%c %s", pch_char(i), pfetch(i));
-	    break;
-	default:
-	    say1("Fatal internal error in abort_hunk().\n"); 
-	    abort();
-	}
-    }
-}
-
-/* We found where to apply it (we hope), so do it. */
-
-void
-apply_hunk(where)
-LINENUM where;
-{
-    Reg1 LINENUM old = 1;
-    Reg2 LINENUM lastline = pch_ptrn_lines();
-    Reg3 LINENUM new = lastline+1;
-#define OUTSIDE 0
-#define IN_IFNDEF 1
-#define IN_IFDEF 2
-#define IN_ELSE 3
-    Reg4 int def_state = OUTSIDE;
-    Reg5 bool R_do_defines = do_defines;
-    Reg6 LINENUM pat_end = pch_end();
-
-    where--;
-    while (pch_char(new) == '=' || pch_char(new) == '\n')
-	new++;
-    
-    while (old <= lastline) {
-	if (pch_char(old) == '-') {
-	    copy_till(where + old - 1);
-	    if (R_do_defines) {
-		if (def_state == OUTSIDE) {
-		    fputs(not_defined, ofp);
-		    def_state = IN_IFNDEF;
-		}
-		else if (def_state == IN_IFDEF) {
-		    fputs(else_defined, ofp);
-		    def_state = IN_ELSE;
-		}
-		fputs(pfetch(old), ofp);
-	    }
-	    last_frozen_line++;
-	    old++;
-	}
-	else if (new > pat_end)
-	    break;
-	else if (pch_char(new) == '+') {
-	    copy_till(where + old - 1);
-	    if (R_do_defines) {
-		if (def_state == IN_IFNDEF) {
-		    fputs(else_defined, ofp);
-		    def_state = IN_ELSE;
-		}
-		else if (def_state == OUTSIDE) {
-		    fputs(if_defined, ofp);
-		    def_state = IN_IFDEF;
-		}
-	    }
-	    fputs(pfetch(new), ofp);
-	    new++;
-	}
-	else {
-	    if (pch_char(new) != pch_char(old)) {
-		say3("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n",
-		    pch_hunk_beg() + old,
-		    pch_hunk_beg() + new);
-#ifdef DEBUGGING
-		say3("oldchar = '%c', newchar = '%c'\n",
-		    pch_char(old), pch_char(new));
-#endif
-		my_exit(1);
-	    }
-	    if (pch_char(new) == '!') {
-		copy_till(where + old - 1);
-		if (R_do_defines) {
-		   fputs(not_defined, ofp);
-		   def_state = IN_IFNDEF;
-		}
-		while (pch_char(old) == '!') {
-		    if (R_do_defines) {
-			fputs(pfetch(old), ofp);
-		    }
-		    last_frozen_line++;
-		    old++;
-		}
-		if (R_do_defines) {
-		    fputs(else_defined, ofp);
-		    def_state = IN_ELSE;
-		}
-		while (pch_char(new) == '!') {
-		    fputs(pfetch(new), ofp);
-		    new++;
-		}
-		if (R_do_defines) {
-		    fputs(end_defined, ofp);
-		    def_state = OUTSIDE;
-		}
-	    }
-	    else {
-		assert(pch_char(new) == ' ');
-		old++;
-		new++;
-	    }
-	}
-    }
-    if (new <= pat_end && pch_char(new) == '+') {
-	copy_till(where + old - 1);
-	if (R_do_defines) {
-	    if (def_state == OUTSIDE) {
-	    	fputs(if_defined, ofp);
-		def_state = IN_IFDEF;
-	    }
-	    else if (def_state == IN_IFNDEF) {
-		fputs(else_defined, ofp);
-		def_state = IN_ELSE;
-	    }
-	}
-	while (new <= pat_end && pch_char(new) == '+') {
-	    fputs(pfetch(new), ofp);
-	    new++;
-	}
-    }
-    if (R_do_defines && def_state != OUTSIDE) {
-	fputs(end_defined, ofp);
-    }
-}
-
-/* Open the new file. */
-
-void
-init_output(name)
-char *name;
-{
-    ofp = fopen(name, "w");
-    if (ofp == Nullfp)
-	fatal2("patch: can't create %s.\n", name);
-}
-
-/* Open a file to put hunks we can't locate. */
-
-void
-init_reject(name)
-char *name;
-{
-    rejfp = fopen(name, "w");
-    if (rejfp == Nullfp)
-	fatal2("patch: can't create %s.\n", name);
-}
-
-/* Copy input file to output, up to wherever hunk is to be applied. */
-
-void
-copy_till(lastline)
-Reg1 LINENUM lastline;
-{
-    Reg2 LINENUM R_last_frozen_line = last_frozen_line;
-
-    if (R_last_frozen_line > lastline)
-	say1("patch: misordered hunks! output will be garbled.\n");
-    while (R_last_frozen_line < lastline) {
-	dump_line(++R_last_frozen_line);
-    }
-    last_frozen_line = R_last_frozen_line;
-}
-
-/* Finish copying the input file to the output file. */
-
-void
-spew_output()
-{
-#ifdef DEBUGGING
-    if (debug & 256)
-	say3("il=%ld lfl=%ld\n",input_lines,last_frozen_line);
-#endif
-    if (input_lines)
-	copy_till(input_lines);		/* dump remainder of file */
-    Fclose(ofp);
-    ofp = Nullfp;
-}
-
-/* Copy one line from input to output. */
-
-void
-dump_line(line)
-LINENUM line;
-{
-    Reg1 char *s;
-    Reg2 char R_newline = '\n';
-
-    /* Note: string is not null terminated. */
-    for (s=ifetch(line, 0); putc(*s, ofp) != R_newline; s++) ;
-}
-
-/* Does the patch pattern match at line base+offset? */
-
-bool
-patch_match(base, offset, fuzz)
-LINENUM base;
-LINENUM offset;
-LINENUM fuzz;
-{
-    Reg1 LINENUM pline = 1 + fuzz;
-    Reg2 LINENUM iline;
-    Reg3 LINENUM pat_lines = pch_ptrn_lines() - fuzz;
-
-    for (iline=base+offset+fuzz; pline <= pat_lines; pline++,iline++) {
-	if (canonicalize) {
-	    if (!similar(ifetch(iline, (offset >= 0)),
-			 pfetch(pline),
-			 pch_line_len(pline) ))
-		return FALSE;
-	}
-	else if (strnNE(ifetch(iline, (offset >= 0)),
-		   pfetch(pline),
-		   pch_line_len(pline) ))
-	    return FALSE;
-    }
-    return TRUE;
-}
-
-/* Do two lines match with canonicalized white space? */
-
-bool
-similar(a,b,len)
-Reg1 char *a;
-Reg2 char *b;
-Reg3 int len;
-{
-    while (len) {
-	if (isspace(*b)) {		/* whitespace (or \n) to match? */
-	    if (!isspace(*a))		/* no corresponding whitespace? */
-		return FALSE;
-	    while (len && isspace(*b) && *b != '\n')
-		b++,len--;		/* skip pattern whitespace */
-	    while (isspace(*a) && *a != '\n')
-		a++;			/* skip target whitespace */
-	    if (*a == '\n' || *b == '\n')
-		return (*a == *b);	/* should end in sync */
-	}
-	else if (*a++ != *b++)		/* match non-whitespace chars */
-	    return FALSE;
-	else
-	    len--;			/* probably not necessary */
-    }
-    return TRUE;			/* actually, this is not reached */
-					/* since there is always a \n */
-}
-
-/* Exit with cleanup. */
-
-void
-my_exit(status)
-int status;
-{
-    Unlink(TMPINNAME);
-    if (!toutkeep) {
-	Unlink(TMPOUTNAME);
-    }
-    if (!trejkeep) {
-	Unlink(TMPREJNAME);
-    }
-    Unlink(TMPPATNAME);
-#ifdef SMALL
-    Unlink(TMPSTRNAME);
-#endif
-    exit(status);
-}
Index: trunk/minix/commands/patch/patchlevel.h
===================================================================
--- trunk/minix/commands/patch/patchlevel.h	(revision 9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-#define PATCHLEVEL 12
Index: trunk/minix/commands/patch/pch.c
===================================================================
--- trunk/minix/commands/patch/pch.c	(revision 9)
+++ 	(revision )
@@ -1,1307 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/pch.c,v 1.1.1.1 2005/04/21 14:55:11 beng Exp $
- *
- * $Log: pch.c,v $
- * Revision 1.1.1.1  2005/04/21 14:55:11  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:19  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0.1.7  88/06/03  15:13:28  lwall
- * patch10: Can now find patches in shar scripts.
- * patch10: Hunks that swapped and then swapped back could core dump.
- * 
- * Revision 2.0.1.6  87/06/04  16:18:13  lwall
- * pch_swap didn't swap p_bfake and p_efake.
- * 
- * Revision 2.0.1.5  87/01/30  22:47:42  lwall
- * Improved responses to mangled patches.
- * 
- * Revision 2.0.1.4  87/01/05  16:59:53  lwall
- * New-style context diffs caused double call to free().
- * 
- * Revision 2.0.1.3  86/11/14  10:08:33  lwall
- * Fixed problem where a long pattern wouldn't grow the hunk.
- * Also restored p_input_line when backtracking so error messages are right.
- * 
- * Revision 2.0.1.2  86/11/03  17:49:52  lwall
- * New-style delete triggers spurious assertion error.
- * 
- * Revision 2.0.1.1  86/10/29  15:52:08  lwall
- * Could falsely report new-style context diff.
- * 
- * Revision 2.0  86/09/17  15:39:37  lwall
- * Baseline for netwide release.
- * 
- */
-
-#include "EXTERN.h"
-#include "common.h"
-#include "util.h"
-#include "INTERN.h"
-#include "pch.h"
-
-/* Patch (diff listing) abstract type. */
-
-static long p_filesize;			/* size of the patch file */
-static LINENUM p_first;			/* 1st line number */
-static LINENUM p_newfirst;		/* 1st line number of replacement */
-static LINENUM p_ptrn_lines;		/* # lines in pattern */
-static LINENUM p_repl_lines;		/* # lines in replacement text */
-static LINENUM p_end = -1;		/* last line in hunk */
-static LINENUM p_max;			/* max allowed value of p_end */
-static LINENUM p_context = 3;		/* # of context lines */
-static LINENUM p_input_line = 0;	/* current line # from patch file */
-#ifdef SMALL
-static long *p_line = Null(long *);	/* the text of the hunk */
-#else
-static char **p_line = Null(char**);	/* the text of the hunk */
-#endif
-static short *p_len = Null(short*);	/* length of each line */
-static char *p_char = Nullch;		/* +, -, and ! */
-static int hunkmax = INITHUNKMAX;	/* size of above arrays to begin with */
-static int p_indent;			/* indent to patch */
-static LINENUM p_base;			/* where to intuit this time */
-static LINENUM p_bline;			/* line # of p_base */
-static LINENUM p_start;			/* where intuit found a patch */
-static LINENUM p_sline;			/* and the line number for it */
-static LINENUM p_hunk_beg;		/* line number of current hunk */
-static LINENUM p_efake = -1;		/* end of faked up lines--don't free */
-static LINENUM p_bfake = -1;		/* beg of faked up lines */
-
-/* Prepare to look for the next patch in the patch file. */
-
-void
-re_patch()
-{
-    p_first = Nulline;
-    p_newfirst = Nulline;
-    p_ptrn_lines = Nulline;
-    p_repl_lines = Nulline;
-    p_end = (LINENUM)-1;
-    p_max = Nulline;
-    p_indent = 0;
-}
-
-/* Open the patch file at the beginning of time. */
-
-void
-open_patch_file(filename)
-char *filename;
-{
-    if (filename == Nullch || !*filename || strEQ(filename, "-")) {
-	pfp = fopen(TMPPATNAME, "w");
-	if (pfp == Nullfp)
-	    fatal2("patch: can't create %s.\n", TMPPATNAME);
-	while (fgets(buf, sizeof buf, stdin) != Nullch)
-	    fputs(buf, pfp);
-	Fclose(pfp);
-	filename = TMPPATNAME;
-    }
-    pfp = fopen(filename, "r");
-    if (pfp == Nullfp)
-	fatal2("patch file %s not found\n", filename);
-    Fstat(fileno(pfp), &filestat);
-    p_filesize = filestat.st_size;
-    next_intuit_at(0L,1L);			/* start at the beginning */
-    set_hunkmax();
-}
-
-/* Make sure our dynamically realloced tables are malloced to begin with. */
-
-void
-set_hunkmax()
-{
-#ifndef lint
-#ifdef SMALL
-    if (p_line == Null(long*))
-#else
-    if (p_line == Null(char**))
-#endif
-#ifdef SMALL
-	p_line = (long *) malloc((MEM)hunkmax * sizeof(long));
-#else
-	p_line = (char**) malloc((MEM)hunkmax * sizeof(char *));
-#endif
-    if (p_len == Null(short*))
-	p_len  = (short*) malloc((MEM)hunkmax * sizeof(short));
-#endif
-    if (p_char == Nullch)
-	p_char = (char*)  malloc((MEM)hunkmax * sizeof(char));
-}
-
-/* Enlarge the arrays containing the current hunk of patch. */
-
-void
-grow_hunkmax()
-{
-    hunkmax *= 2;
-    /* 
-     * Note that on most systems, only the p_line array ever gets fresh memory
-     * since p_len can move into p_line's old space, and p_char can move into
-     * p_len's old space.  Not on PDP-11's however.  But it doesn't matter.
-     */
-#ifdef SMALL
-    assert(p_line != Null(long*) && p_len != Null(short*) && p_char != Nullch);
-#else
-    assert(p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch);
-#endif
-#ifndef lint
-#ifdef SMALL
-    p_line = (long*) realloc((char*)p_line, (MEM)hunkmax * sizeof(long));
-#else
-    p_line = (char**) realloc((char*)p_line, (MEM)hunkmax * sizeof(char *));
-#endif
-    p_len  = (short*) realloc((char*)p_len,  (MEM)hunkmax * sizeof(short));
-    p_char = (char*)  realloc((char*)p_char, (MEM)hunkmax * sizeof(char));
-#endif
-#ifdef SMALL
-    if (p_line != Null(long*) && p_len != Null(short*) && p_char != Nullch)
-#else
-    if (p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch)
-#endif
-	return;
-    if (!using_plan_a)
-	fatal1("patch: out of memory (grow_hunkmax)\n");
-    out_of_mem = TRUE;		/* whatever is null will be allocated again */
-				/* from within plan_a(), of all places */
-}
-
-/* True if the remainder of the patch file contains a diff of some sort. */
-
-bool
-there_is_another_patch()
-{
-    if (p_base != 0L && p_base >= p_filesize) {
-	if (verbose)
-	    say1("done\n");
-	return FALSE;
-    }
-    if (verbose)
-	say1("Hmm...");
-    diff_type = intuit_diff_type();
-    if (!diff_type) {
-	if (p_base != 0L) {
-	    if (verbose)
-		say1("  Ignoring the trailing garbage.\ndone\n");
-	}
-	else
-	    say1("  I can't seem to find a patch in there anywhere.\n");
-	return FALSE;
-    }
-    if (verbose)
-	say3("  %sooks like %s to me...\n",
-	    (p_base == 0L ? "L" : "The next patch l"),
-	    diff_type == CONTEXT_DIFF ? "a context diff" :
-	    diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
-	    diff_type == NORMAL_DIFF ? "a normal diff" :
-	    "an ed script" );
-    if (p_indent && verbose)
-	say3("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s");
-    skip_to(p_start,p_sline);
-    while (filearg[0] == Nullch) {
-	if (force) {
-	    say1("No file to patch.  Skipping...\n");
-	    filearg[0] = savestr(bestguess);
-	    return TRUE;
-	}
-	ask1("File to patch: ");
-	if (*buf != '\n') {
-	    if (bestguess)
-		free(bestguess);
-	    bestguess = savestr(buf);
-	    filearg[0] = fetchname(buf, 0, FALSE);
-	}
-	if (filearg[0] == Nullch) {
-	    ask1("No file found--skip this patch? [n] ");
-	    if (*buf != 'y') {
-		continue;
-	    }
-	    if (verbose)
-		say1("Skipping patch...\n");
-	    filearg[0] = fetchname(bestguess, 0, TRUE);
-	    skip_rest_of_patch = TRUE;
-	    return TRUE;
-	}
-    }
-    return TRUE;
-}
-
-/* Determine what kind of diff is in the remaining part of the patch file. */
-
-int
-intuit_diff_type()
-{
-    Reg4 long this_line = 0;
-    Reg5 long previous_line;
-    Reg6 long first_command_line = -1;
-    long fcl_line;
-    Reg7 bool last_line_was_command = FALSE;
-    Reg8 bool this_is_a_command = FALSE;
-    Reg9 bool stars_last_line = FALSE;
-    Reg10 bool stars_this_line = FALSE;
-    Reg3 int indent;
-    Reg1 char *s;
-    Reg2 char *t;
-    char *indtmp = Nullch;
-    char *oldtmp = Nullch;
-    char *newtmp = Nullch;
-    char *indname = Nullch;
-    char *oldname = Nullch;
-    char *newname = Nullch;
-    Reg11 int retval;
-    bool no_filearg = (filearg[0] == Nullch);
-
-    ok_to_create_file = FALSE;
-    Fseek(pfp, p_base, 0);
-    p_input_line = p_bline - 1;
-    for (;;) {
-	previous_line = this_line;
-	last_line_was_command = this_is_a_command;
-	stars_last_line = stars_this_line;
-	this_line = ftell(pfp);
-	indent = 0;
-	p_input_line++;
-	if (fgets(buf, sizeof buf, pfp) == Nullch) {
-	    if (first_command_line >= 0L) {
-					/* nothing but deletes!? */
-		p_start = first_command_line;
-		p_sline = fcl_line;
-		retval = ED_DIFF;
-		goto scan_exit;
-	    }
-	    else {
-		p_start = this_line;
-		p_sline = p_input_line;
-		retval = 0;
-		goto scan_exit;
-	    }
-	}
-	for (s = buf; *s == ' ' || *s == '\t' || *s == 'X'; s++) {
-	    if (*s == '\t')
-		indent += 8 - (indent % 8);
-	    else
-		indent++;
-	}
-	for (t=s; isdigit(*t) || *t == ','; t++) ; 
-	this_is_a_command = (isdigit(*s) &&
-	  (*t == 'd' || *t == 'c' || *t == 'a') );
-	if (first_command_line < 0L && this_is_a_command) { 
-	    first_command_line = this_line;
-	    fcl_line = p_input_line;
-	    p_indent = indent;		/* assume this for now */
-	}
-	if (!stars_last_line && strnEQ(s, "*** ", 4))
-	    oldtmp = savestr(s+4);
-	else if (strnEQ(s, "--- ", 4))
-	    newtmp = savestr(s+4);
-	else if (strnEQ(s, "Index:", 6))
-	    indtmp = savestr(s+6);
-	else if (strnEQ(s, "Prereq:", 7)) {
-	    for (t=s+7; isspace(*t); t++) ;
-	    revision = savestr(t);
-	    for (t=revision; *t && !isspace(*t); t++) ;
-	    *t = '\0';
-	    if (!*revision) {
-		free(revision);
-		revision = Nullch;
-	    }
-	}
-	if ((!diff_type || diff_type == ED_DIFF) &&
-	  first_command_line >= 0L &&
-	  strEQ(s, ".\n") ) {
-	    p_indent = indent;
-	    p_start = first_command_line;
-	    p_sline = fcl_line;
-	    retval = ED_DIFF;
-	    goto scan_exit;
-	}
-	stars_this_line = strnEQ(s, "********", 8);
-	if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line &&
-		 strnEQ(s, "*** ", 4)) {
-	    if (!atol(s+4))
-		ok_to_create_file = TRUE;
-	    /* if this is a new context diff the character just before */
-	    /* the newline is a '*'. */
-	    while (*s != '\n')
-		s++;
-	    p_indent = indent;
-	    p_start = previous_line;
-	    p_sline = p_input_line - 1;
-	    retval = (*(s-1) == '*' ? NEW_CONTEXT_DIFF : CONTEXT_DIFF);
-	    goto scan_exit;
-	}
-	if ((!diff_type || diff_type == NORMAL_DIFF) && 
-	  last_line_was_command &&
-	  (strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2)) ) {
-	    p_start = previous_line;
-	    p_sline = p_input_line - 1;
-	    p_indent = indent;
-	    retval = NORMAL_DIFF;
-	    goto scan_exit;
-	}
-    }
-  scan_exit:
-    if (no_filearg) {
-	if (indtmp != Nullch)
-	    indname = fetchname(indtmp, strippath, ok_to_create_file);
-	if (oldtmp != Nullch)
-	    oldname = fetchname(oldtmp, strippath, ok_to_create_file);
-	if (newtmp != Nullch)
-	    newname = fetchname(newtmp, strippath, ok_to_create_file);
-	if (oldname && newname) {
-	    if (strlen(oldname) < strlen(newname))
-		filearg[0] = savestr(oldname);
-	    else
-		filearg[0] = savestr(newname);
-	}
-	else if (oldname)
-	    filearg[0] = savestr(oldname);
-	else if (newname)
-	    filearg[0] = savestr(newname);
-	else if (indname)
-	    filearg[0] = savestr(indname);
-    }
-    if (bestguess) {
-	free(bestguess);
-	bestguess = Nullch;
-    }
-    if (filearg[0] != Nullch)
-	bestguess = savestr(filearg[0]);
-    else if (indtmp != Nullch)
-	bestguess = fetchname(indtmp, strippath, TRUE);
-    else {
-	if (oldtmp != Nullch)
-	    oldname = fetchname(oldtmp, strippath, TRUE);
-	if (newtmp != Nullch)
-	    newname = fetchname(newtmp, strippath, TRUE);
-	if (oldname && newname) {
-	    if (strlen(oldname) < strlen(newname))
-		bestguess = savestr(oldname);
-	    else
-		bestguess = savestr(newname);
-	}
-	else if (oldname)
-	    bestguess = savestr(oldname);
-	else if (newname)
-	    bestguess = savestr(newname);
-    }
-    if (indtmp != Nullch)
-	free(indtmp);
-    if (oldtmp != Nullch)
-	free(oldtmp);
-    if (newtmp != Nullch)
-	free(newtmp);
-    if (indname != Nullch)
-	free(indname);
-    if (oldname != Nullch)
-	free(oldname);
-    if (newname != Nullch)
-	free(newname);
-    return retval;
-}
-
-/* Remember where this patch ends so we know where to start up again. */
-
-void
-next_intuit_at(file_pos,file_line)
-long file_pos;
-long file_line;
-{
-    p_base = file_pos;
-    p_bline = file_line;
-}
-
-/* Basically a verbose fseek() to the actual diff listing. */
-
-void
-skip_to(file_pos,file_line)
-long file_pos;
-long file_line;
-{
-    char *ret;
-
-    assert(p_base <= file_pos);
-    if (verbose && p_base < file_pos) {
-	Fseek(pfp, p_base, 0);
-	say1("The text leading up to this was:\n--------------------------\n");
-	while (ftell(pfp) < file_pos) {
-	    ret = fgets(buf, sizeof buf, pfp);
-	    assert(ret != Nullch);
-	    say2("|%s", buf);
-	}
-	say1("--------------------------\n");
-    }
-    else
-	Fseek(pfp, file_pos, 0);
-    p_input_line = file_line - 1;
-}
-
-/* True if there is more of the current diff listing to process. */
-
-bool
-another_hunk()
-{
-    Reg1 char *s;
-    Reg8 char *ret;
-    Reg2 int context = 0;
-
-    while (p_end >= 0) {
-	if (p_end == p_efake)
-	    p_end = p_bfake;		/* don't free twice */
-#ifndef SMALL
-	else
-	    free(p_line[p_end]);
-#endif
-	p_end--;
-    }
-    assert(p_end == -1);
-    p_efake = -1;
-#ifdef SMALL
-    if (sfp != Nullfp)
-	Fclose(sfp);
-    sfp = fopen(TMPSTRNAME, "w");
-    if (sfp == Nullfp)
-	fatal2("patch: can't create %s.\n", TMPSTRNAME);
-#endif
-
-    p_max = hunkmax;			/* gets reduced when --- found */
-    if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) {
-	long line_beginning = ftell(pfp);
-					/* file pos of the current line */
-	LINENUM repl_beginning = 0;	/* index of --- line */
-	Reg4 LINENUM fillcnt = 0;	/* #lines of missing ptrn or repl */
-	Reg5 LINENUM fillsrc;		/* index of first line to copy */
-	Reg6 LINENUM filldst;		/* index of first missing line */
-	bool ptrn_spaces_eaten = FALSE;	/* ptrn was slightly misformed */
-	Reg9 bool repl_could_be_missing = TRUE;
-					/* no + or ! lines in this hunk */
-	bool repl_missing = FALSE;	/* we are now backtracking */
-	long repl_backtrack_position = 0;
-					/* file pos of first repl line */
-	LINENUM repl_patch_line;	/* input line number for same */
-	Reg7 LINENUM ptrn_copiable = 0;
-					/* # of copiable lines in ptrn */
-
-	ret = pgets(buf, sizeof buf, pfp);
-	p_input_line++;
-	if (ret == Nullch || strnNE(buf, "********", 8)) {
-	    next_intuit_at(line_beginning,p_input_line);
-	    return FALSE;
-	}
-	p_context = 100;
-	p_hunk_beg = p_input_line + 1;
-	while (p_end < p_max) {
-	    line_beginning = ftell(pfp);
-	    ret = pgets(buf, sizeof buf, pfp);
-	    p_input_line++;
-	    if (ret == Nullch) {
-		if (p_max - p_end < 4)
-		    Strcpy(buf, "  \n");  /* assume blank lines got chopped */
-		else {
-		    if (repl_beginning && repl_could_be_missing) {
-			repl_missing = TRUE;
-			goto hunk_done;
-		    }
-		    fatal1("Unexpected end of file in patch.\n");
-		}
-	    }
-	    p_end++;
-	    assert(p_end < hunkmax);
-	    p_char[p_end] = *buf;
-#ifdef zilog
-	    p_line[(short)p_end] = Nullch;
-#else
-#ifdef SMALL
-	    p_line[p_end] = -1L;
-	    p_len[p_end] = 0;
-#else
-	    p_line[p_end] = Nullch;
-#endif
-#endif
-	    switch (*buf) {
-	    case '*':
-		if (strnEQ(buf, "********", 8)) {
-		    if (repl_beginning && repl_could_be_missing) {
-			repl_missing = TRUE;
-			goto hunk_done;
-		    }
-		    else
-			fatal2("Unexpected end of hunk at line %ld.\n",
-			    p_input_line);
-		}
-		if (p_end != 0) {
-		    if (repl_beginning && repl_could_be_missing) {
-			repl_missing = TRUE;
-			goto hunk_done;
-		    }
-		    fatal3("Unexpected *** at line %ld: %s", p_input_line, buf);
-		}
-		context = 0;
-#ifdef SMALL
-		p_line[p_end] = saveStr(buf, p_len+p_end);
-#else
-		p_line[p_end] = savestr(buf);
-		if (out_of_mem) {
-		    p_end--;
-		    return FALSE;
-		}
-#endif
-		for (s=buf; *s && !isdigit(*s); s++) ;
-		if (!*s)
-		    goto malformed;
-		if (strnEQ(s,"0,0",3))
-		    strcpy(s,s+2);
-		p_first = (LINENUM) atol(s);
-		while (isdigit(*s)) s++;
-		if (*s == ',') {
-		    for (; *s && !isdigit(*s); s++) ;
-		    if (!*s)
-			goto malformed;
-		    p_ptrn_lines = ((LINENUM)atol(s)) - p_first + 1;
-		}
-		else if (p_first)
-		    p_ptrn_lines = 1;
-		else {
-		    p_ptrn_lines = 0;
-		    p_first = 1;
-		}
-		p_max = p_ptrn_lines + 6;	/* we need this much at least */
-		while (p_max >= hunkmax)
-		    grow_hunkmax();
-		p_max = hunkmax;
-		break;
-	    case '-':
-		if (buf[1] == '-') {
-		    if (repl_beginning ||
-			(p_end != p_ptrn_lines + 1 + (p_char[p_end-1] == '\n')))
-		    {
-			if (p_end == 1) {
-			    /* `old' lines were omitted - set up to fill */
-			    /* them in from 'new' context lines. */
-			    p_end = p_ptrn_lines + 1;
-			    fillsrc = p_end + 1;
-			    filldst = 1;
-			    fillcnt = p_ptrn_lines;
-			}
-			else {
-			    if (repl_beginning) {
-				if (repl_could_be_missing){
-				    repl_missing = TRUE;
-				    goto hunk_done;
-				}
-				fatal3(
-"Duplicate \"---\" at line %ld--check line numbers at line %ld.\n",
-				    p_input_line, p_hunk_beg + repl_beginning);
-			    }
-			    else {
-				fatal4(
-"%s \"---\" at line %ld--check line numbers at line %ld.\n",
-				    (p_end <= p_ptrn_lines
-					? "Premature"
-					: "Overdue" ),
-				    p_input_line, p_hunk_beg);
-			    }
-			}
-		    }
-		    repl_beginning = p_end;
-		    repl_backtrack_position = ftell(pfp);
-		    repl_patch_line = p_input_line;
-#ifdef SMALL
-		    p_line[p_end] = saveStr(buf, p_len+p_end);
-#else
-		    p_line[p_end] = savestr(buf);
-		    if (out_of_mem) {
-			p_end--;
-			return FALSE;
-		    }
-#endif
-		    p_char[p_end] = '=';
-		    for (s=buf; *s && !isdigit(*s); s++) ;
-		    if (!*s)
-			goto malformed;
-		    p_newfirst = (LINENUM) atol(s);
-		    while (isdigit(*s)) s++;
-		    if (*s == ',') {
-			for (; *s && !isdigit(*s); s++) ;
-			if (!*s)
-			    goto malformed;
-			p_repl_lines = ((LINENUM)atol(s)) - p_newfirst + 1;
-		    }
-		    else if (p_newfirst)
-			p_repl_lines = 1;
-		    else {
-			p_repl_lines = 0;
-			p_newfirst = 1;
-		    }
-		    p_max = p_repl_lines + p_end;
-		    if (p_max > MAXHUNKSIZE)
-			fatal4("Hunk too large (%ld lines) at line %ld: %s",
-			      p_max, p_input_line, buf);
-		    while (p_max >= hunkmax)
-			grow_hunkmax();
-		    if (p_repl_lines != ptrn_copiable)
-			repl_could_be_missing = FALSE;
-		    break;
-		}
-		goto change_line;
-	    case '+':  case '!':
-		repl_could_be_missing = FALSE;
-	      change_line:
-		if (buf[1] == '\n' && canonicalize)
-		    strcpy(buf+1," \n");
-		if (!isspace(buf[1]) && buf[1] != '>' && buf[1] != '<' &&
-		  repl_beginning && repl_could_be_missing) {
-		    repl_missing = TRUE;
-		    goto hunk_done;
-		}
-		if (context > 0) {
-		    if (context < p_context)
-			p_context = context;
-		    context = -1000;
-		}
-#ifdef SMALL
-		p_line[p_end] = saveStr(buf+2, p_len+p_end);
-#else
-		p_line[p_end] = savestr(buf+2);
-		if (out_of_mem) {
-		    p_end--;
-		    return FALSE;
-		}
-#endif
-		break;
-	    case '\t': case '\n':	/* assume the 2 spaces got eaten */
-		if (repl_beginning && repl_could_be_missing &&
-		  (!ptrn_spaces_eaten || diff_type == NEW_CONTEXT_DIFF) ) {
-		    repl_missing = TRUE;
-		    goto hunk_done;
-		}
-#ifdef SMALL
-		p_line[p_end] = saveStr(buf, p_len+p_end);
-#else
-		p_line[p_end] = savestr(buf);
-		if (out_of_mem) {
-		    p_end--;
-		    return FALSE;
-		}
-#endif
-		if (p_end != p_ptrn_lines + 1) {
-		    ptrn_spaces_eaten |= (repl_beginning != 0);
-		    context++;
-		    if (!repl_beginning)
-			ptrn_copiable++;
-		    p_char[p_end] = ' ';
-		}
-		break;
-	    case ' ':
-		if (!isspace(buf[1]) &&
-		  repl_beginning && repl_could_be_missing) {
-		    repl_missing = TRUE;
-		    goto hunk_done;
-		}
-		context++;
-		if (!repl_beginning)
-		    ptrn_copiable++;
-#ifdef SMALL
-		p_line[p_end] = saveStr(buf+2, p_len+p_end);
-#else
-		p_line[p_end] = savestr(buf+2);
-		if (out_of_mem) {
-		    p_end--;
-		    return FALSE;
-		}
-#endif
-		break;
-	    default:
-		if (repl_beginning && repl_could_be_missing) {
-		    repl_missing = TRUE;
-		    goto hunk_done;
-		}
-		goto malformed;
-	    }
-	    /* set up p_len for strncmp() so we don't have to */
-	    /* assume null termination */
-#ifndef SMALL
-	    if (p_line[p_end])
-		p_len[p_end] = strlen(p_line[p_end]);
-	    else
-		p_len[p_end] = 0;
-#endif
-	}
-	
-    hunk_done:
-	if (p_end >=0 && !repl_beginning)
-	    fatal2("No --- found in patch at line %ld\n", pch_hunk_beg());
-
-	if (repl_missing) {
-	    
-	    /* reset state back to just after --- */
-	    p_input_line = repl_patch_line;
-#ifndef SMALL
-	    for (p_end--; p_end > repl_beginning; p_end--)
-		free(p_line[p_end]);
-#endif
-	    Fseek(pfp, repl_backtrack_position, 0);
-	    
-	    /* redundant 'new' context lines were omitted - set */
-	    /* up to fill them in from the old file context */
-	    fillsrc = 1;
-	    filldst = repl_beginning+1;
-	    fillcnt = p_repl_lines;
-	    p_end = p_max;
-	}
-
-	if (diff_type == CONTEXT_DIFF &&
-	  (fillcnt || (p_first > 1 && ptrn_copiable > 2*p_context)) ) {
-	    if (verbose)
-		say4("%s\n%s\n%s\n",
-"(Fascinating--this is really a new-style context diff but without",
-"the telltale extra asterisks on the *** line that usually indicate",
-"the new style...)");
-	    diff_type = NEW_CONTEXT_DIFF;
-	}
-	
-	/* if there were omitted context lines, fill them in now */
-	if (fillcnt) {
-	    p_bfake = filldst;		/* remember where not to free() */
-	    p_efake = filldst + fillcnt - 1;
-	    while (fillcnt-- > 0) {
-		while (fillsrc <= p_end && p_char[fillsrc] != ' ')
-		    fillsrc++;
-		if (fillsrc > p_end)
-		    fatal2("Replacement text or line numbers mangled in hunk at line %ld\n",
-			p_hunk_beg);
-		p_line[filldst] = p_line[fillsrc];
-		p_char[filldst] = p_char[fillsrc];
-		p_len[filldst] = p_len[fillsrc];
-		fillsrc++; filldst++;
-	    }
-	    while (fillsrc <= p_end && fillsrc != repl_beginning &&
-	      p_char[fillsrc] != ' ')
-		fillsrc++;
-#ifdef DEBUGGING
-	    if (debug & 64)
-		printf("fillsrc %ld, filldst %ld, rb %ld, e+1 %ld\n",
-		    fillsrc,filldst,repl_beginning,p_end+1);
-#endif
-	    assert(fillsrc==p_end+1 || fillsrc==repl_beginning);
-	    assert(filldst==p_end+1 || filldst==repl_beginning);
-	}
-    }
-    else {				/* normal diff--fake it up */
-	char hunk_type;
-	Reg3 int i;
-	LINENUM min, max;
-	long line_beginning = ftell(pfp);
-
-	p_context = 0;
-	ret = pgets(buf, sizeof buf, pfp);
-	p_input_line++;
-	if (ret == Nullch || !isdigit(*buf)) {
-	    next_intuit_at(line_beginning,p_input_line);
-	    return FALSE;
-	}
-	p_first = (LINENUM)atol(buf);
-	for (s=buf; isdigit(*s); s++) ;
-	if (*s == ',') {
-	    p_ptrn_lines = (LINENUM)atol(++s) - p_first + 1;
-	    while (isdigit(*s)) s++;
-	}
-	else
-	    p_ptrn_lines = (*s != 'a');
-	hunk_type = *s;
-	if (hunk_type == 'a')
-	    p_first++;			/* do append rather than insert */
-	min = (LINENUM)atol(++s);
-	for (; isdigit(*s); s++) ;
-	if (*s == ',')
-	    max = (LINENUM)atol(++s);
-	else
-	    max = min;
-	if (hunk_type == 'd')
-	    min++;
-	p_end = p_ptrn_lines + 1 + max - min + 1;
-	if (p_end > MAXHUNKSIZE)
-	    fatal4("Hunk too large (%ld lines) at line %ld: %s",
-		  p_end, p_input_line, buf);
-	while (p_end >= hunkmax)
-	    grow_hunkmax();
-	p_newfirst = min;
-	p_repl_lines = max - min + 1;
-	Sprintf(buf, "*** %ld,%ld\n", p_first, p_first + p_ptrn_lines - 1);
-#ifdef SMALL
-	p_line[0] = saveStr(buf, p_len);
-#else
-	p_line[0] = savestr(buf);
-	if (out_of_mem) {
-	    p_end = -1;
-	    return FALSE;
-	}
-#endif
-	p_char[0] = '*';
-	for (i=1; i<=p_ptrn_lines; i++) {
-	    ret = pgets(buf, sizeof buf, pfp);
-	    p_input_line++;
-	    if (ret == Nullch)
-		fatal2("Unexpected end of file in patch at line %ld.\n",
-		  p_input_line);
-	    if (*buf != '<')
-		fatal2("< expected at line %ld of patch.\n", p_input_line);
-#ifdef SMALL
-	    p_line[i] = saveStr(buf+2, p_len+i);
-#else
-	    p_line[i] = savestr(buf+2);
-	    if (out_of_mem) {
-		p_end = i-1;
-		return FALSE;
-	    }
-#endif
-#ifndef SMALL
-	    p_len[i] = strlen(p_line[i]);
-#endif
-	    p_char[i] = '-';
-	}
-	if (hunk_type == 'c') {
-	    ret = pgets(buf, sizeof buf, pfp);
-	    p_input_line++;
-	    if (ret == Nullch)
-		fatal2("Unexpected end of file in patch at line %ld.\n",
-		    p_input_line);
-	    if (*buf != '-')
-		fatal2("--- expected at line %ld of patch.\n", p_input_line);
-	}
-	Sprintf(buf, "--- %ld,%ld\n", min, max);
-#ifdef SMALL
-	p_line[i] = saveStr(buf, p_len+i);
-#else
-	p_line[i] = savestr(buf);
-	if (out_of_mem) {
-	    p_end = i-1;
-	    return FALSE;
-	}
-#endif
-	p_char[i] = '=';
-	for (i++; i<=p_end; i++) {
-	    ret = pgets(buf, sizeof buf, pfp);
-	    p_input_line++;
-	    if (ret == Nullch)
-		fatal2("Unexpected end of file in patch at line %ld.\n",
-		    p_input_line);
-	    if (*buf != '>')
-		fatal2("> expected at line %ld of patch.\n", p_input_line);
-#ifdef SMALL
-	    p_line[i] = saveStr(buf+2, p_len+i);
-#else
-	    p_line[i] = savestr(buf+2);
-	    if (out_of_mem) {
-		p_end = i-1;
-		return FALSE;
-	    }
-#endif
-#ifndef SMALL
-	    p_len[i] = strlen(p_line[i]);
-#endif
-	    p_char[i] = '+';
-	}
-    }
-    if (reverse)			/* backwards patch? */
-	if (!pch_swap())
-	    say1("Not enough memory to swap next hunk!\n");
-#ifdef SMALL
-    Fclose(sfp);
-    sfp = fopen(TMPSTRNAME, "r");
-#endif
-#ifdef DEBUGGING
-    if (debug & 2) {
-	int i;
-	char special;
-
-	for (i=0; i <= p_end; i++) {
-	    if (i == p_ptrn_lines)
-		special = '^';
-	    else
-		special = ' ';
-#ifdef SMALL
-	    fprintf(stderr, "%3d %c %c %s", i, p_char[i], special, pfetch(i));
-#else
-	    fprintf(stderr, "%3d %c %c %s", i, p_char[i], special, p_line[i]);
-#endif
-	    Fflush(stderr);
-	}
-    }
-#endif
-    if (p_end+1 < hunkmax)	/* paranoia reigns supreme... */
-	p_char[p_end+1] = '^';  /* add a stopper for apply_hunk */
-    return TRUE;
-
-malformed:
-#ifdef SMALL
-    Fclose(sfp);
-    sfp = Nullfp;
-#endif
-    fatal3("Malformed patch at line %ld: %s", p_input_line, buf);
-		/* about as informative as "Syntax error" in C */
-    return FALSE;	/* for lint */
-}
-
-/* Input a line from the patch file, worrying about indentation. */
-
-char *
-pgets(bf,sz,fp)
-char *bf;
-int sz;
-FILE *fp;
-{
-    char *ret = fgets(bf, sz, fp);
-    Reg1 char *s;
-    Reg2 int indent = 0;
-
-    if (p_indent && ret != Nullch) {
-	for (s=buf;
-	  indent < p_indent && (*s == ' ' || *s == '\t' || *s == 'X'); s++) {
-	    if (*s == '\t')
-		indent += 8 - (indent % 7);
-	    else
-		indent++;
-	}
-	if (buf != s)
-	    Strcpy(buf, s);
-    }
-    return ret;
-}
-
-/* Reverse the old and new portions of the current hunk. */
-
-bool
-pch_swap()
-{
-#ifdef SMALL
-    long *tp_line;		/* the text of the hunk */
-#else
-    char **tp_line;		/* the text of the hunk */
-#endif
-    short *tp_len;		/* length of each line */
-    char *tp_char;		/* +, -, and ! */
-    Reg1 LINENUM i;
-    Reg2 LINENUM n;
-    bool blankline = FALSE;
-    Reg3 char *s;
-
-    i = p_first;
-    p_first = p_newfirst;
-    p_newfirst = i;
-    
-    /* make a scratch copy */
-
-    tp_line = p_line;
-    tp_len = p_len;
-    tp_char = p_char;
-#ifdef SMALL
-    p_line = Null(long*);	/* force set_hunkmax to allocate again */
-#else
-    p_line = Null(char**);	/* force set_hunkmax to allocate again */
-#endif
-    p_len = Null(short*);
-    p_char = Nullch;
-    set_hunkmax();
-#ifdef SMALL
-    if (p_line == Null(long*) || p_len == Null(short*) || p_char == Nullch) {
-#else
-    if (p_line == Null(char**) || p_len == Null(short*) || p_char == Nullch) {
-#endif
-#ifndef lint
-#ifdef SMALL
-	if (p_line == Null(long*))
-#else
-	if (p_line == Null(char**))
-#endif
-	    free((char*)p_line);
-	p_line = tp_line;
-	if (p_len == Null(short*))
-	    free((char*)p_len);
-	p_len = tp_len;
-#endif
-	if (p_char == Nullch)
-	    free((char*)p_char);
-	p_char = tp_char;
-	return FALSE;		/* not enough memory to swap hunk! */
-    }
-
-    /* now turn the new into the old */
-
-    i = p_ptrn_lines + 1;
-    if (tp_char[i] == '\n') {		/* account for possible blank line */
-	blankline = TRUE;
-	i++;
-    }
-    if (p_efake >= 0) {			/* fix non-freeable ptr range */
-	if (p_efake <= i)
-	    n = p_end - i + 1;
-	else
-	    n = -i;
-	p_efake += n;
-	p_bfake += n;
-    }
-    for (n=0; i <= p_end; i++,n++) {
-	p_line[n] = tp_line[i];
-	p_char[n] = tp_char[i];
-	if (p_char[n] == '+')
-	    p_char[n] = '-';
-	p_len[n] = tp_len[i];
-    }
-    if (blankline) {
-	i = p_ptrn_lines + 1;
-	p_line[n] = tp_line[i];
-	p_char[n] = tp_char[i];
-	p_len[n] = tp_len[i];
-	n++;
-    }
-    assert(p_char[0] == '=');
-    p_char[0] = '*';
-#ifdef SMALL
-    strEdit(p_line[0], '*', '-');
-#else
-    for (s=p_line[0]; *s; s++)
-	if (*s == '-')
-	    *s = '*';
-#endif
-
-    /* now turn the old into the new */
-
-    assert(tp_char[0] == '*');
-    tp_char[0] = '=';
-#ifdef SMALL
-    strEdit(tp_line[0], '-', '*');
-#else
-    for (s=tp_line[0]; *s; s++)
-	if (*s == '*')
-	    *s = '-';
-#endif
-    for (i=0; n <= p_end; i++,n++) {
-	p_line[n] = tp_line[i];
-	p_char[n] = tp_char[i];
-	if (p_char[n] == '-')
-	    p_char[n] = '+';
-	p_len[n] = tp_len[i];
-    }
-    assert(i == p_ptrn_lines + 1);
-    i = p_ptrn_lines;
-    p_ptrn_lines = p_repl_lines;
-    p_repl_lines = i;
-#ifndef lint
-#ifdef SMALL
-    if (tp_line == Null(long*))
-#else
-    if (tp_line == Null(char**))
-#endif
-	free((char*)tp_line);
-    if (tp_len == Null(short*))
-	free((char*)tp_len);
-#endif
-    if (tp_char == Nullch)
-	free((char*)tp_char);
-    return TRUE;
-}
-
-/* Return the specified line position in the old file of the old context. */
-
-LINENUM
-pch_first()
-{
-    return p_first;
-}
-
-/* Return the number of lines of old context. */
-
-LINENUM
-pch_ptrn_lines()
-{
-    return p_ptrn_lines;
-}
-
-/* Return the probable line position in the new file of the first line. */
-
-LINENUM
-pch_newfirst()
-{
-    return p_newfirst;
-}
-
-/* Return the number of lines in the replacement text including context. */
-
-LINENUM
-pch_repl_lines()
-{
-    return p_repl_lines;
-}
-
-/* Return the number of lines in the whole hunk. */
-
-LINENUM
-pch_end()
-{
-    return p_end;
-}
-
-/* Return the number of context lines before the first changed line. */
-
-LINENUM
-pch_context()
-{
-    return p_context;
-}
-
-/* Return the length of a particular patch line. */
-
-short
-pch_line_len(line)
-LINENUM line;
-{
-    return p_len[line];
-}
-
-/* Return the control character (+, -, *, !, etc) for a patch line. */
-
-char
-pch_char(line)
-LINENUM line;
-{
-    return p_char[line];
-}
-
-/* Return a pointer to a particular patch line. */
-
-#ifdef SMALL
-long
-saveStr(str, plen)
-char *str;
-short *plen;
-{
-    long pos, ftell();
-    int len;
-
-    pos = ftell(sfp);
-    len = strlen(str);
-    fwrite(str, sizeof(char), len+1, sfp);
-    *plen = len;
-    return pos;
-}
-
-char *
-pfetch(line)
-LINENUM line;
-{
-    static char *s, strbuf[BUFSIZ];
-    int i, c;
-
-    if (p_line[line] == -1L)
-	return Nullch;
-    else {
-	Fseek(sfp, p_line[line], 0);
-	for (i = 0, s = strbuf;
-		i < BUFSIZ && (c = fgetc(sfp)) != EOF && c; i++)
-	    *s++ = c;
-	if (i == BUFSIZ)
-		fatal2("too long line (%.40s ..\n", strbuf);
-    }
-    *s = '\0';
-    return strbuf;
-}
-
-void
-strEdit(pos, to, from)
-long pos;
-int to, from;
-{
-    static char *s, strbuf[BUFSIZ];
-    int i, c;
-
-    if (pos != -1L) {
-	for (i = 0, s = strbuf;
-		i < BUFSIZ && (c = fgetc(sfp)) != EOF && c; i++)
-	    *s++ = c;
-	for (s = strbuf; *s; s++)
-	    if (*s == from)
-		*s = to;
-	fwrite(strbuf, sizeof(char), i+1, sfp);
-    }
-}
-#else
-char *
-pfetch(line)
-LINENUM line;
-{
-    return p_line[line];
-}
-#endif
-
-/* Return where in the patch file this hunk began, for error messages. */
-
-LINENUM
-pch_hunk_beg()
-{
-    return p_hunk_beg;
-}
-
-/* Apply an ed script by feeding ed itself. */
-
-void
-do_ed_script()
-{
-    Reg1 char *t;
-    Reg2 long beginning_of_this_line;
-    Reg3 bool this_line_is_command = FALSE;
-    Reg4 FILE *pipefp;
-
-    if (!skip_rest_of_patch) {
-	Unlink(TMPOUTNAME);
-	copy_file(filearg[0], TMPOUTNAME);
-	if (verbose)
-	    Sprintf(buf, "/bin/ed %s", TMPOUTNAME);
-	else
-	    Sprintf(buf, "/bin/ed - %s", TMPOUTNAME);
-	pipefp = popen(buf, "w");
-    }
-    for (;;) {
-	beginning_of_this_line = ftell(pfp);
-	if (pgets(buf, sizeof buf, pfp) == Nullch) {
-	    next_intuit_at(beginning_of_this_line,p_input_line);
-	    break;
-	}
-	p_input_line++;
-	for (t=buf; isdigit(*t) || *t == ','; t++) ;
-	this_line_is_command = (isdigit(*buf) &&
-	  (*t == 'd' || *t == 'c' || *t == 'a') );
-	if (this_line_is_command) {
-	    if (!skip_rest_of_patch)
-		fputs(buf, pipefp);
-	    if (*t != 'd') {
-		while (pgets(buf, sizeof buf, pfp) != Nullch) {
-		    p_input_line++;
-		    if (!skip_rest_of_patch)
-			fputs(buf, pipefp);
-		    if (strEQ(buf, ".\n"))
-			break;
-		}
-	    }
-	}
-	else {
-	    next_intuit_at(beginning_of_this_line,p_input_line);
-	    break;
-	}
-    }
-    if (skip_rest_of_patch)
-	return;
-    fprintf(pipefp, "w\n");
-    fprintf(pipefp, "q\n");
-    Fflush(pipefp);
-    Pclose(pipefp);
-    ignore_signals();
-    if (move_file(TMPOUTNAME, outname) < 0) {
-	toutkeep = TRUE;
-	chmod(TMPOUTNAME, filemode);
-    }
-    else
-	chmod(outname, filemode);
-    set_signals(1);
-}
Index: trunk/minix/commands/patch/pch.h
===================================================================
--- trunk/minix/commands/patch/pch.h	(revision 9)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/pch.h,v 1.1.1.1 2005/04/21 14:55:11 beng Exp $
- *
- * $Log: pch.h,v $
- * Revision 1.1.1.1  2005/04/21 14:55:11  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:19  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0.1.1  87/01/30  22:47:16  lwall
- * Added do_ed_script().
- * 
- * Revision 2.0  86/09/17  15:39:57  lwall
- * Baseline for netwide release.
- * 
- */
-
-EXT FILE *pfp INIT(Nullfp);		/* patch file pointer */
-#ifdef SMALL
-EXT FILE *sfp INIT(Nullfp);		/* string file pointer */
-#endif
-
-_PROTOTYPE(void re_patch , (void));
-_PROTOTYPE(void open_patch_file , (char *filename ));
-_PROTOTYPE(void set_hunkmax , (void));
-_PROTOTYPE(void grow_hunkmax , (void));
-_PROTOTYPE(bool there_is_another_patch , (void));
-_PROTOTYPE(int intuit_diff_type , (void));
-_PROTOTYPE(void next_intuit_at , (long file_pos , long file_line ));
-_PROTOTYPE(void skip_to , (long file_pos , long file_line ));
-_PROTOTYPE(bool another_hunk , (void));
-_PROTOTYPE(char *pgets , (char *bf , int sz , FILE *fp ));
-_PROTOTYPE(bool pch_swap , (void));
-_PROTOTYPE(LINENUM pch_first , (void));
-_PROTOTYPE(LINENUM pch_ptrn_lines , (void));
-_PROTOTYPE(LINENUM pch_newfirst , (void));
-_PROTOTYPE(LINENUM pch_repl_lines , (void));
-_PROTOTYPE(LINENUM pch_end , (void));
-_PROTOTYPE(LINENUM pch_context , (void));
-_PROTOTYPE(short pch_line_len , (LINENUM line ));
-_PROTOTYPE(char pch_char , (LINENUM line ));
-_PROTOTYPE(char *pfetch , (LINENUM line ));
-_PROTOTYPE(LINENUM pch_hunk_beg , (void));
-_PROTOTYPE(void do_ed_script , (void));
-#ifdef SMALL
-_PROTOTYPE(long saveStr , (char *string , short *length ));
-_PROTOTYPE(void strEdit , (long pos , int from , int to ));
-#endif
Index: trunk/minix/commands/patch/util.c
===================================================================
--- trunk/minix/commands/patch/util.c	(revision 9)
+++ 	(revision )
@@ -1,361 +1,0 @@
-#include "EXTERN.h"
-#include "common.h"
-#include "INTERN.h"
-#include "util.h"
-
-/* Rename a file, copying it if necessary. */
-
-int
-move_file(from,to)
-char *from, *to;
-{
-    char bakname[512];
-    Reg1 char *s;
-    Reg2 int i;
-    Reg3 int fromfd;
-
-    /* to stdout? */
-
-    if (strEQ(to, "-")) {
-#ifdef DEBUGGING
-	if (debug & 4)
-	    say2("Moving %s to stdout.\n", from);
-#endif
-	fromfd = open(from, 0);
-	if (fromfd < 0)
-	    fatal2("patch: internal error, can't reopen %s\n", from);
-	while ((i=read(fromfd, buf, sizeof buf)) > 0)
-	    if (write(1, buf, i) != i)
-		fatal1("patch: write failed\n");
-	Close(fromfd);
-	return 0;
-    }
-
-	if (origprae) {
-		Strcpy (bakname, origprae);
-    	Strcat(bakname, to);
-	} else {
-   		Strcpy(bakname, to);
-    	Strcat(bakname, origext?origext:ORIGEXT);
-	}
-    if (stat(to, &filestat) >= 0) {	/* output file exists */
-	dev_t to_device = filestat.st_dev;
-	ino_t to_inode  = filestat.st_ino;
-	char *simplename = bakname;
-	
-	for (s=bakname; *s; s++) {
-	    if (*s == '/')
-		simplename = s+1;
-	}
-	/* find a backup name that is not the same file */
-	while (stat(bakname, &filestat) >= 0 &&
-		to_device == filestat.st_dev && to_inode == filestat.st_ino) {
-	    for (s=simplename; *s && !islower(*s); s++) ;
-	    if (*s)
-		*s = toupper(*s);
-	    else
-		Strcpy(simplename, simplename+1);
-	}
-	while (unlink(bakname) >= 0) ;	/* while() is for benefit of Eunice */
-#ifdef DEBUGGING
-	if (debug & 4)
-	    say3("Moving %s to %s.\n", to, bakname);
-#endif
-	if (link(to, bakname) < 0) {
-	    say3("patch: can't backup %s, output is in %s\n",
-		to, from);
-	    return -1;
-	}
-	while (unlink(to) >= 0) ;
-    }
-#ifdef DEBUGGING
-    if (debug & 4)
-	say3("Moving %s to %s.\n", from, to);
-#endif
-    if (link(from, to) < 0) {		/* different file system? */
-	Reg4 int tofd;
-	
-	tofd = creat(to, 0666);
-	if (tofd < 0) {
-	    say3("patch: can't create %s, output is in %s.\n",
-	      to, from);
-	    return -1;
-	}
-	fromfd = open(from, 0);
-	if (fromfd < 0)
-	    fatal2("patch: internal error, can't reopen %s\n", from);
-	while ((i=read(fromfd, buf, sizeof buf)) > 0)
-	    if (write(tofd, buf, i) != i)
-		fatal1("patch: write failed\n");
-	Close(fromfd);
-	Close(tofd);
-    }
-    Unlink(from);
-    return 0;
-}
-
-/* Copy a file. */
-
-void
-copy_file(from,to)
-char *from, *to;
-{
-    Reg3 int tofd;
-    Reg2 int fromfd;
-    Reg1 int i;
-    
-    tofd = creat(to, 0666);
-    if (tofd < 0)
-	fatal2("patch: can't create %s.\n", to);
-    fromfd = open(from, 0);
-    if (fromfd < 0)
-	fatal2("patch: internal error, can't reopen %s\n", from);
-    while ((i=read(fromfd, buf, sizeof buf)) > 0)
-	if (write(tofd, buf, i) != i)
-	    fatal2("patch: write (%s) failed\n", to);
-    Close(fromfd);
-    Close(tofd);
-}
-
-/* Allocate a unique area for a string. */
-
-char *
-savestr(s)
-Reg1 char *s;
-{
-    Reg3 char *rv;
-    Reg2 char *t;
-
-    if (!s)
-	s = "Oops";
-    t = s;
-    while (*t++);
-    rv = (char *)malloc((MEM) (t - s));
-    if (rv == Nullch) {
-	if (using_plan_a)
-	    out_of_mem = TRUE;
-	else
-	    fatal1("patch: out of memory (savestr)\n");
-    }
-    else {
-	t = rv;
-	while (*t++ = *s++);
-    }
-    return rv;
-}
-
-#if defined(lint) && defined(CANVARARG)
-
-/*VARARGS ARGSUSED*/
-say(pat) char *pat; { ; }
-/*VARARGS ARGSUSED*/
-fatal(pat) char *pat; { ; }
-/*VARARGS ARGSUSED*/
-ask(pat) char *pat; { ; }
-
-#else
-
-/* Vanilla terminal output (buffered). */
-
-void
-say(pat,arg1,arg2,arg3)
-char *pat;
-long arg1,arg2,arg3;
-{
-    fprintf(stderr, pat, arg1, arg2, arg3);
-    Fflush(stderr);
-}
-
-/* Terminal output, pun intended. */
-
-void				/* very void */
-fatal(pat,arg1,arg2,arg3)
-char *pat;
-long arg1,arg2,arg3;
-{
-    say(pat, arg1, arg2, arg3);
-    my_exit(1);
-}
-
-/* Get a response from the user, somehow or other. */
-
-void
-ask(pat,arg1,arg2,arg3)
-char *pat;
-long arg1,arg2,arg3;
-{
-    int ttyfd;
-    int r;
-    bool tty2 = isatty(2);
-
-    Sprintf(buf, pat, arg1, arg2, arg3);
-    Fflush(stderr);
-    write(2, buf, strlen(buf));
-    if (tty2) {				/* might be redirected to a file */
-	r = read(2, buf, sizeof buf);
-    }
-    else if (isatty(1)) {		/* this may be new file output */
-	Fflush(stdout);
-	write(1, buf, strlen(buf));
-	r = read(1, buf, sizeof buf);
-    }
-    else if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) {
-					/* might be deleted or unwriteable */
-	write(ttyfd, buf, strlen(buf));
-	r = read(ttyfd, buf, sizeof buf);
-	Close(ttyfd);
-    }
-    else if (isatty(0)) {		/* this is probably patch input */
-	Fflush(stdin);
-	write(0, buf, strlen(buf));
-	r = read(0, buf, sizeof buf);
-    }
-    else {				/* no terminal at all--default it */
-	buf[0] = '\n';
-	r = 1;
-    }
-    if (r <= 0)
-	buf[0] = 0;
-    else
-	buf[r] = '\0';
-    if (!tty2)
-	say1(buf);
-}
-#endif /* lint */
-
-/* How to handle certain events when not in a critical region. */
-
-void
-set_signals(reset)
-int reset;
-{
-#ifndef lint
-#ifdef VOIDSIG
-    static void (*hupval)(),(*intval)();
-#else
-    static int (*hupval)(),(*intval)();
-#endif
-
-    if (!reset) {
-	hupval = signal(SIGHUP, SIG_IGN);
-	if (hupval != SIG_IGN)
-#ifdef VOIDSIG
-	    hupval = my_exit;
-#else
-	    hupval = (int(*)())my_exit;
-#endif
-	intval = signal(SIGINT, SIG_IGN);
-	if (intval != SIG_IGN)
-#ifdef VOIDSIG
-	    intval = my_exit;
-#else
-	    intval = (int(*)())my_exit;
-#endif
-    }
-    Signal(SIGHUP, hupval);
-    Signal(SIGINT, intval);
-#endif
-}
-
-/* How to handle certain events when in a critical region. */
-
-void
-ignore_signals()
-{
-#ifndef lint
-    Signal(SIGHUP, SIG_IGN);
-    Signal(SIGINT, SIG_IGN);
-#endif
-}
-
-/* Make sure we'll have the directories to create a file. */
-
-void
-makedirs(filename,striplast)
-Reg1 char *filename;
-bool striplast;
-{
-    char tmpbuf[256];
-    Reg2 char *s = tmpbuf;
-    char *dirv[20];
-    Reg3 int i;
-    Reg4 int dirvp = 0;
-
-    while (*filename) {
-	if (*filename == '/') {
-	    filename++;
-	    dirv[dirvp++] = s;
-	    *s++ = '\0';
-	}
-	else {
-	    *s++ = *filename++;
-	}
-    }
-    *s = '\0';
-    dirv[dirvp] = s;
-    if (striplast)
-	dirvp--;
-    if (dirvp < 0)
-	return;
-    strcpy(buf, "mkdir");
-    s = buf;
-    for (i=0; i<=dirvp; i++) {
-	while (*s) s++;
-	*s++ = ' ';
-	strcpy(s, tmpbuf);
-	*dirv[i] = '/';
-    }
-    system(buf);
-}
-
-/* Make filenames more reasonable. */
-
-char *
-fetchname(at,strip_leading,assume_exists)
-char *at;
-int strip_leading;
-int assume_exists;
-{
-    char *s;
-    char *name;
-    Reg1 char *t;
-    char tmpbuf[200];
-
-    if (!at)
-	return Nullch;
-    s = savestr(at);
-    for (t=s; isspace(*t); t++) ;
-    name = t;
-#ifdef DEBUGGING
-    if (debug & 128)
-	say4("fetchname %s %d %d\n",name,strip_leading,assume_exists);
-#endif
-    if (strnEQ(name, "/dev/null", 9))	/* so files can be created by diffing */
-	return Nullch;			/*   against /dev/null. */
-    for (; *t && !isspace(*t); t++)
-	if (*t == '/')
-	    if (--strip_leading >= 0)
-		name = t+1;
-    *t = '\0';
-    if (name != s && *s != '/') {
-	name[-1] = '\0';
-	if (stat(s, &filestat) && filestat.st_mode & S_IFDIR) {
-	    name[-1] = '/';
-	    name=s;
-	}
-    }
-    name = savestr(name);
-    Sprintf(tmpbuf, "RCS/%s", name);
-    free(s);
-    if (stat(name, &filestat) < 0 && !assume_exists) {
-	Strcat(tmpbuf, RCSSUFFIX);
-	if (stat(tmpbuf, &filestat) < 0 && stat(tmpbuf+4, &filestat) < 0) {
-	    Sprintf(tmpbuf, "SCCS/%s%s", SCCSPREFIX, name);
-	    if (stat(tmpbuf, &filestat) < 0 && stat(tmpbuf+5, &filestat) < 0) {
-		free(name);
-		name = Nullch;
-	    }
-	}
-    }
-    return name;
-}
Index: trunk/minix/commands/patch/util.h
===================================================================
--- trunk/minix/commands/patch/util.h	(revision 9)
+++ 	(revision )
@@ -1,80 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/util.h,v 1.1.1.1 2005/04/21 14:55:11 beng Exp $
- *
- * $Log: util.h,v $
- * Revision 1.1.1.1  2005/04/21 14:55:11  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:20  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0  86/09/17  15:40:06  lwall
- * Baseline for netwide release.
- * 
- */
-
-/* and for those machine that can't handle a variable argument list */
-
-#ifdef CANVARARG
-
-#define say1 say
-#define say2 say
-#define say3 say
-#define say4 say
-#define ask1 ask
-#define ask2 ask
-#define ask3 ask
-#define ask4 ask
-#define fatal1 fatal
-#define fatal2 fatal
-#define fatal3 fatal
-#define fatal4 fatal
-
-#else /* hope they allow multi-line macro actual arguments */
-
-#ifdef lint
-
-#define say1(a) say(a, 0, 0, 0)
-#define say2(a,b) say(a, (b)==(b), 0, 0)
-#define say3(a,b,c) say(a, (b)==(b), (c)==(c), 0)
-#define say4(a,b,c,d) say(a, (b)==(b), (c)==(c), (d)==(d))
-#define ask1(a) ask(a, 0, 0, 0)
-#define ask2(a,b) ask(a, (b)==(b), 0, 0)
-#define ask3(a,b,c) ask(a, (b)==(b), (c)==(c), 0)
-#define ask4(a,b,c,d) ask(a, (b)==(b), (c)==(c), (d)==(d))
-#define fatal1(a) fatal(a, 0, 0, 0)
-#define fatal2(a,b) fatal(a, (b)==(b), 0, 0)
-#define fatal3(a,b,c) fatal(a, (b)==(b), (c)==(c), 0)
-#define fatal4(a,b,c,d) fatal(a, (b)==(b), (c)==(c), (d)==(d))
-
-#else /* lint */
-    /* if this doesn't work, try defining CANVARARG above */
-#define say1(a) say(a, Nullch, Nullch, Nullch)
-#define say2(a,b) say(a, b, Nullch, Nullch)
-#define say3(a,b,c) say(a, b, c, Nullch)
-#define say4 say
-#define ask1(a) ask(a, Nullch, Nullch, Nullch)
-#define ask2(a,b) ask(a, b, Nullch, Nullch)
-#define ask3(a,b,c) ask(a, b, c, Nullch)
-#define ask4 ask
-#define fatal1(a) fatal(a, Nullch, Nullch, Nullch)
-#define fatal2(a,b) fatal(a, b, Nullch, Nullch)
-#define fatal3(a,b,c) fatal(a, b, c, Nullch)
-#define fatal4 fatal
-
-#endif /* lint */
-
-/* if neither of the above work, join all multi-line macro calls. */
-#endif
-
-EXT char serrbuf[BUFSIZ];		/* buffer for stderr */
-
-_PROTOTYPE(int move_file , (char *from , char *to ));
-_PROTOTYPE(void copy_file , (char *from , char *to ));
-_PROTOTYPE(char *savestr , (Reg1 char *s ));
-void say();
-void fatal();
-void ask();
-_PROTOTYPE(void set_signals , (int reset ));
-_PROTOTYPE(void ignore_signals , (void));
-_PROTOTYPE(void makedirs , (Reg1 char *filename , bool striplast ));
-_PROTOTYPE(char *fetchname , (char *at , int strip_leading , int assume_exists ));
Index: trunk/minix/commands/patch/version.c
===================================================================
--- trunk/minix/commands/patch/version.c	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/version.c,v 1.1.1.1 2005/04/21 14:55:11 beng Exp $
- *
- * $Log: version.c,v $
- * Revision 1.1.1.1  2005/04/21 14:55:11  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:20  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0  86/09/17  15:40:11  lwall
- * Baseline for netwide release.
- * 
- */
-
-#include "EXTERN.h"
-#include "common.h"
-#include "util.h"
-#include "INTERN.h"
-#include "patchlevel.h"
-#include "version.h"
-
-/* Print out the version number and die. */
-
-void
-version()
-{
-    extern char rcsid[];
-
-#ifdef lint
-    rcsid[0] = rcsid[0];
-#else
-    fatal3("%s\nPatch level: %d\n", rcsid, PATCHLEVEL);
-#endif
-}
Index: trunk/minix/commands/patch/version.h
===================================================================
--- trunk/minix/commands/patch/version.h	(revision 9)
+++ 	(revision )
@@ -1,15 +1,0 @@
-/* $Header: /cvsup/minix/src/commands/patch/version.h,v 1.1.1.1 2005/04/21 14:55:11 beng Exp $
- *
- * $Log: version.h,v $
- * Revision 1.1.1.1  2005/04/21 14:55:11  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:20  beng
- * Initial import of minix 2.0.4
- *
- * Revision 2.0  86/09/17  15:40:14  lwall
- * Baseline for netwide release.
- * 
- */
-
-_PROTOTYPE(void version , (void));
Index: trunk/minix/commands/pax/Makefile
===================================================================
--- trunk/minix/commands/pax/Makefile	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-# Makefile for pax
-
-CC = exec cc
-CFLAGS = -O -D_POSIX_SOURCE -DNET2_STAT=1 -D_MINIX=1
-LDFLAGS= -i
-
-all:	pax
-
-OBJ = ar_io.o ar_subs.o buf_subs.o cache.o cpio.o file_subs.o ftree.o \
-gen_subs.o getoldopt.o options.o pat_rep.o pax.o sel_subs.o \
-tables.o tar.o tty_subs.o fgetln.o
-
-pax:	$(OBJ)
-	$(CC) $(LDFLAGS) -o $@ $(OBJ)
-	install -S 256k $@
-
-install: pax
-	install -cs -o bin pax /usr/bin/pax
-
-clean:	
-	rm -f *.o *.bak core pax
Index: trunk/minix/commands/pax/ar_io.c
===================================================================
--- trunk/minix/commands/pax/ar_io.c	(revision 9)
+++ 	(revision )
@@ -1,1298 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)ar_io.c	8.2 (Berkeley) 4/18/94";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/mtio.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "pax.h"
-#include "options.h"
-#include "extern.h"
-
-/*
- * Routines which deal directly with the archive I/O device/file.
- */
-
-#define DMOD		0666		/* default mode of created archives */
-#define EXT_MODE	O_RDONLY	/* open mode for list/extract */
-#define AR_MODE		(O_WRONLY | O_CREAT | O_TRUNC)	/* mode for archive */
-#define APP_MODE	O_RDWR		/* mode for append */
-
-static char none[] = "<NONE>";		/* pseudo name for no file */
-static char stdo[] = "<STDOUT>";	/* pseudo name for stdout */
-static char stdn[] = "<STDIN>";		/* pseudo name for stdin */
-static int arfd = -1;			/* archive file descriptor */
-static int artyp = ISREG;		/* archive type: file/FIFO/tape */
-static int arvol = 1;			/* archive volume number */
-static int lstrval = -1;		/* return value from last i/o */
-static int io_ok;			/* i/o worked on volume after resync */
-static int did_io;			/* did i/o ever occur on volume? */
-static int done;			/* set via tty termination */
-static struct stat arsb;		/* stat of archive device at open */
-static int invld_rec;			/* tape has out of spec record size */
-static int wr_trail = 1;		/* trailer was rewritten in append */
-static int can_unlnk = 0;		/* do we unlink null archives?  */
-const char *arcname;		  	/* printable name of archive */
-const char *gzip_program;		/* name of gzip program */
-static pid_t zpid = -1;			/* pid of child process */
-
-static int get_phys(void);
-extern sigset_t s_mask;
-static void ar_start_gzip(int, const char *, int);
-
-/*
- * ar_open()
- *	Opens the next archive volume. Determines the type of the device and
- *	sets up block sizes as required by the archive device and the format.
- *	Note: we may be called with name == NULL on the first open only.
- * Return:
- *	-1 on failure, 0 otherwise
- */
-
-int
-ar_open(const char *name)
-{
-	struct mtget mb;
-
-	if (arfd != -1)
-		(void)close(arfd);
-	arfd = -1;
-	can_unlnk = did_io = io_ok = invld_rec = 0;
-	artyp = ISREG;
-	flcnt = 0;
-
-	/*
-	 * open based on overall operation mode
-	 */
-	switch (act) {
-	case LIST:
-	case EXTRACT:
-		if (name == NULL) {
-			arfd = STDIN_FILENO;
-			arcname = stdn;
-		} else if ((arfd = open(name, EXT_MODE, DMOD)) < 0)
-			syswarn(0, errno, "Failed open to read on %s", name);
-		if (arfd != -1 && gzip_program != NULL)
-			ar_start_gzip(arfd, gzip_program, 0);
-		break;
-	case ARCHIVE:
-		if (name == NULL) {
-			arfd = STDOUT_FILENO;
-			arcname = stdo;
-		} else if ((arfd = open(name, AR_MODE, DMOD)) < 0)
-			syswarn(0, errno, "Failed open to write on %s", name);
-		else
-			can_unlnk = 1;
-		if (arfd != -1 && gzip_program != NULL)
-			ar_start_gzip(arfd, gzip_program, 1);
-		break;
-	case APPND:
-		if (name == NULL) {
-			arfd = STDOUT_FILENO;
-			arcname = stdo;
-		} else if ((arfd = open(name, APP_MODE, DMOD)) < 0)
-			syswarn(0, errno, "Failed open to read/write on %s",
-				name);
-		break;
-	case COPY:
-		/*
-		 * arfd not used in COPY mode
-		 */
-		arcname = none;
-		lstrval = 1;
-		return(0);
-	}
-	if (arfd < 0)
-		return(-1);
-
-	if (chdname != NULL)
-		if (chdir(chdname) != 0) {
-			syswarn(1, errno, "Failed chdir to %s", chdname);
-			return(-1);
-		}
-	/*
-	 * set up is based on device type
-	 */
-	if (fstat(arfd, &arsb) < 0) {
-		syswarn(0, errno, "Failed stat on %s", arcname);
-		(void)close(arfd);
-		arfd = -1;
-		can_unlnk = 0;
-		return(-1);
-	}
-	if (S_ISDIR(arsb.st_mode)) {
-		paxwarn(0, "Cannot write an archive on top of a directory %s",
-		    arcname);
-		(void)close(arfd);
-		arfd = -1;
-		can_unlnk = 0;
-		return(-1);
-	}
-
-	if (S_ISCHR(arsb.st_mode))
-		artyp = ioctl(arfd, MTIOCGET, &mb) ? ISCHR : ISTAPE;
-	else if (S_ISBLK(arsb.st_mode))
-		artyp = ISBLK;
-	else if ((lseek(arfd, (off_t)0L, SEEK_CUR) == -1) && (errno == ESPIPE))
-		artyp = ISPIPE;
-	else
-		artyp = ISREG;
-
-	/*
-	 * make sure we beyond any doubt that we only can unlink regular files
-	 * we created
-	 */
-	if (artyp != ISREG)
-		can_unlnk = 0;
-	/*
-	 * if we are writing, we are done
-	 */
-	if (act == ARCHIVE) {
-		blksz = rdblksz = wrblksz;
-		lstrval = 1;
-		return(0);
-	}
-
-	/*
-	 * set default blksz on read. APPNDs writes rdblksz on the last volume
-	 * On all new archive volumes, we shift to wrblksz (if the user
-	 * specified one, otherwize we will continue to use rdblksz). We
-	 * must to set blocksize based on what kind of device the archive is
-	 * stored.
-	 */
-	switch(artyp) {
-	case ISTAPE:
-		/*
-		 * Tape drives come in at least two flavors. Those that support
-		 * variable sized records and those that have fixed sized
-		 * records. They must be treated differently. For tape drives
-		 * that support variable sized records, we must make large
-		 * reads to make sure we get the entire record, otherwise we
-		 * will just get the first part of the record (up to size we
-		 * asked). Tapes with fixed sized records may or may not return
-		 * multiple records in a single read. We really do not care
-		 * what the physical record size is UNLESS we are going to
-		 * append. (We will need the physical block size to rewrite
-		 * the trailer). Only when we are appending do we go to the
-		 * effort to figure out the true PHYSICAL record size.
-		 */
-		blksz = rdblksz = MAXBLK;
-		break;
-	case ISPIPE:
-	case ISBLK:
-	case ISCHR:
-		/*
-		 * Blocksize is not a major issue with these devices (but must
-		 * be kept a multiple of 512). If the user specified a write
-		 * block size, we use that to read. Under append, we must
-		 * always keep blksz == rdblksz. Otherwise we go ahead and use
-		 * the device optimal blocksize as (and if) returned by stat
-		 * and if it is within pax specs.
-		 */
-		if ((act == APPND) && wrblksz) {
-			blksz = rdblksz = wrblksz;
-			break;
-		}
-
-#if 0	/* Not on minix */
-		if ((arsb.st_blksize > 0) && (arsb.st_blksize < MAXBLK) &&
-		    ((arsb.st_blksize % BLKMULT) == 0))
-			rdblksz = arsb.st_blksize;
-		else
-#endif
-			rdblksz = DEVBLK;
-		/*
-		 * For performance go for large reads when we can without harm
-		 */
-		if ((act == APPND) || (artyp == ISCHR))
-			blksz = rdblksz;
-		else
-			blksz = MAXBLK;
-		break;
-	case ISREG:
-		/*
-		 * if the user specified wrblksz works, use it. Under appends
-		 * we must always keep blksz == rdblksz
-		 */
-		if ((act == APPND) && wrblksz && ((arsb.st_size%wrblksz)==0)){
-			blksz = rdblksz = wrblksz;
-			break;
-		}
-		/*
-		 * See if we can find the blocking factor from the file size
-		 */
-		for (rdblksz = MAXBLK; rdblksz > 0; rdblksz -= BLKMULT)
-			if ((arsb.st_size % rdblksz) == 0)
-				break;
-		/*
-		 * When we cannot find a match, we may have a flawed archive.
-		 */
-		if (rdblksz <= 0)
-			rdblksz = FILEBLK;
-		/*
-		 * for performance go for large reads when we can
-		 */
-		if (act == APPND)
-			blksz = rdblksz;
-		else
-			blksz = MAXBLK;
-		break;
-	default:
-		/*
-		 * should never happen, worse case, slow...
-		 */
-		blksz = rdblksz = BLKMULT;
-		break;
-	}
-	lstrval = 1;
-	return(0);
-}
-
-/*
- * ar_close()
- *	closes archive device, increments volume number, and prints i/o summary
- */
-void
-ar_close(void)
-{
-	int status;
-
-	if (arfd < 0) {
-		did_io = io_ok = flcnt = 0;
-		return;
-	}
-
-	/*
-	 * Close archive file. This may take a LONG while on tapes (we may be
-	 * forced to wait for the rewind to complete) so tell the user what is
-	 * going on (this avoids the user hitting control-c thinking pax is
-	 * broken).
-	 */
-	if (vflag && (artyp == ISTAPE)) {
-		if (vfpart)
-			(void)putc('\n', listf);
-		(void)fprintf(listf,
-			"%s: Waiting for tape drive close to complete...",
-			argv0);
-		(void)fflush(listf);
-	}
-
-	/*
-	 * if nothing was written to the archive (and we created it), we remove
-	 * it
-	 */
-	if (can_unlnk && (fstat(arfd, &arsb) == 0) && (S_ISREG(arsb.st_mode)) &&
-	    (arsb.st_size == 0)) {
-		(void)unlink(arcname);
-		can_unlnk = 0;
-	}
-
-	/*
-	 * for a quick extract/list, pax frequently exits before the child
-	 * process is done
-	 */
-	if ((act == LIST || act == EXTRACT) && nflag && zpid > 0)
-		kill(zpid, SIGINT);
-
-	(void)close(arfd);
-
-	/* Do not exit before child to ensure data integrity */
-	if (zpid > 0)
-		waitpid(zpid, &status, 0);
-
-	if (vflag && (artyp == ISTAPE)) {
-		(void)fputs("done.\n", listf);
-		vfpart = 0;
-		(void)fflush(listf);
-	}
-	arfd = -1;
-
-	if (!io_ok && !did_io) {
-		flcnt = 0;
-		return;
-	}
-	did_io = io_ok = 0;
-
-	/*
-	 * The volume number is only increased when the last device has data
-	 * and we have already determined the archive format.
-	 */
-	if (frmt != NULL)
-		++arvol;
-
-	if (!vflag) {
-		flcnt = 0;
-		return;
-	}
-
-	/*
-	 * Print out a summary of I/O for this archive volume.
-	 */
-	if (vfpart) {
-		(void)putc('\n', listf);
-		vfpart = 0;
-	}
-
-	/*
-	 * If we have not determined the format yet, we just say how many bytes
-	 * we have skipped over looking for a header to id. there is no way we
-	 * could have written anything yet.
-	 */
-	if (frmt == NULL) {
-#	ifdef NET2_STAT
-		(void)fprintf(listf, "%s: unknown format, %lu bytes skipped.\n",
-		    argv0, rdcnt);
-#	else
-		(void)fprintf(listf, "%s: unknown format, %ju bytes skipped.\n",
-		    argv0, (uintmax_t)rdcnt);
-#	endif
-		(void)fflush(listf);
-		flcnt = 0;
-		return;
-	}
-
-	if (strcmp(NM_CPIO, argv0) == 0)
-		(void)fprintf(listf, "%llu blocks\n",
-		    (unsigned long)((rdcnt ? rdcnt : wrcnt) / 5120));
-	else if (strcmp(NM_TAR, argv0) != 0)
-		(void)fprintf(listf,
-#	ifdef NET2_STAT
-		    "%s: %s vol %d, %lu files, %lu bytes read, %lu bytes written.\n",
-		    argv0, frmt->name, arvol-1, flcnt, rdcnt, wrcnt);
-#	else
-		    "%s: %s vol %d, %ju files, %ju bytes read, %ju bytes written.\n",
-		    argv0, frmt->name, arvol-1, (uintmax_t)flcnt,
-		    (uintmax_t)rdcnt, (uintmax_t)wrcnt);
-#	endif
-	(void)fflush(listf);
-	flcnt = 0;
-}
-
-/*
- * ar_drain()
- *	drain any archive format independent padding from an archive read
- *	from a socket or a pipe. This is to prevent the process on the
- *	other side of the pipe from getting a SIGPIPE (pax will stop
- *	reading an archive once a format dependent trailer is detected).
- */
-void
-ar_drain(void)
-{
-	int res;
-	char drbuf[MAXBLK];
-
-	/*
-	 * we only drain from a pipe/socket. Other devices can be closed
-	 * without reading up to end of file. We sure hope that pipe is closed
-	 * on the other side so we will get an EOF.
-	 */
-	if ((artyp != ISPIPE) || (lstrval <= 0))
-		return;
-
-	/*
-	 * keep reading until pipe is drained
-	 */
-	while ((res = read(arfd, drbuf, sizeof(drbuf))) > 0)
-		;
-	lstrval = res;
-}
-
-/*
- * ar_set_wr()
- *	Set up device right before switching from read to write in an append.
- *	device dependent code (if required) to do this should be added here.
- *	For all archive devices we are already positioned at the place we want
- *	to start writing when this routine is called.
- * Return:
- *	0 if all ready to write, -1 otherwise
- */
-
-int
-ar_set_wr(void)
-{
-	off_t cpos;
-
-	/*
-	 * we must make sure the trailer is rewritten on append, ar_next()
-	 * will stop us if the archive containing the trailer was not written
-	 */
-	wr_trail = 0;
-
-	/*
-	 * Add any device dependent code as required here
-	 */
-	if (artyp != ISREG)
-		return(0);
-	/*
-	 * Ok we have an archive in a regular file. If we were rewriting a
-	 * file, we must get rid of all the stuff after the current offset
-	 * (it was not written by pax).
-	 */
-	if (((cpos = lseek(arfd, (off_t)0L, SEEK_CUR)) < 0) ||
-	    (ftruncate(arfd, cpos) < 0)) {
-		syswarn(1, errno, "Unable to truncate archive file");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * ar_app_ok()
- *	check if the last volume in the archive allows appends. We cannot check
- *	this until we are ready to write since there is no spec that says all
- *	volumes in a single archive have to be of the same type...
- * Return:
- *	0 if we can append, -1 otherwise.
- */
-
-int
-ar_app_ok(void)
-{
-	if (artyp == ISPIPE) {
-		paxwarn(1, "Cannot append to an archive obtained from a pipe.");
-		return(-1);
-	}
-
-	if (!invld_rec)
-		return(0);
-	paxwarn(1,"Cannot append, device record size %d does not support %s spec",
-		rdblksz, argv0);
-	return(-1);
-}
-
-/*
- * ar_read()
- *	read up to a specified number of bytes from the archive into the
- *	supplied buffer. When dealing with tapes we may not always be able to
- *	read what we want.
- * Return:
- *	Number of bytes in buffer. 0 for end of file, -1 for a read error.
- */
-
-int
-ar_read(char *buf, int cnt)
-{
-	int res = 0;
-
-	/*
-	 * if last i/o was in error, no more reads until reset or new volume
-	 */
-	if (lstrval <= 0)
-		return(lstrval);
-
-	/*
-	 * how we read must be based on device type
-	 */
-	switch (artyp) {
-	case ISTAPE:
-		if ((res = read(arfd, buf, cnt)) > 0) {
-			/*
-			 * CAUTION: tape systems may not always return the same
-			 * sized records so we leave blksz == MAXBLK. The
-			 * physical record size that a tape drive supports is
-			 * very hard to determine in a uniform and portable
-			 * manner.
-			 */
-			io_ok = 1;
-			if (res != rdblksz) {
-				/*
-				 * Record size changed. If this is happens on
-				 * any record after the first, we probably have
-				 * a tape drive which has a fixed record size
-				 * we are getting multiple records in a single
-				 * read). Watch out for record blocking that
-				 * violates pax spec (must be a multiple of
-				 * BLKMULT).
-				 */
-				rdblksz = res;
-				if (rdblksz % BLKMULT)
-					invld_rec = 1;
-			}
-			return(res);
-		}
-		break;
-	case ISREG:
-	case ISBLK:
-	case ISCHR:
-	case ISPIPE:
-	default:
-		/*
-		 * Files are so easy to deal with. These other things cannot
-		 * be trusted at all. So when we are dealing with character
-		 * devices and pipes we just take what they have ready for us
-		 * and return. Trying to do anything else with them runs the
-		 * risk of failure.
-		 */
-		if ((res = read(arfd, buf, cnt)) > 0) {
-			io_ok = 1;
-			return(res);
-		}
-		break;
-	}
-
-	/*
-	 * We are in trouble at this point, something is broken...
-	 */
-	lstrval = res;
-	if (res < 0)
-		syswarn(1, errno, "Failed read on archive volume %d", arvol);
-	else
-		paxwarn(0, "End of archive volume %d reached", arvol);
-	return(res);
-}
-
-/*
- * ar_write()
- *	Write a specified number of bytes in supplied buffer to the archive
- *	device so it appears as a single "block". Deals with errors and tries
- *	to recover when faced with short writes.
- * Return:
- *	Number of bytes written. 0 indicates end of volume reached and with no
- *	flaws (as best that can be detected). A -1 indicates an unrecoverable
- *	error in the archive occured.
- */
-
-int
-ar_write(char *buf, int bsz)
-{
-	int res;
-	off_t cpos;
-
-	/*
-	 * do not allow pax to create a "bad" archive. Once a write fails on
-	 * an archive volume prevent further writes to it.
-	 */
-	if (lstrval <= 0)
-		return(lstrval);
-
-	if ((res = write(arfd, buf, bsz)) == bsz) {
-		wr_trail = 1;
-		io_ok = 1;
-		return(bsz);
-	}
-	/*
-	 * write broke, see what we can do with it. We try to send any partial
-	 * writes that may violate pax spec to the next archive volume.
-	 */
-	if (res < 0)
-		lstrval = res;
-	else
-		lstrval = 0;
-
-	switch (artyp) {
-	case ISREG:
-		if ((res > 0) && (res % BLKMULT)) {
-			/*
-		 	 * try to fix up partial writes which are not BLKMULT
-			 * in size by forcing the runt record to next archive
-			 * volume
-		 	 */
-			if ((cpos = lseek(arfd, (off_t)0L, SEEK_CUR)) < 0)
-				break;
-			cpos -= (off_t)res;
-			if (ftruncate(arfd, cpos) < 0)
-				break;
-			res = lstrval = 0;
-			break;
-		}
-		if (res >= 0)
-			break;
-		/*
-		 * if file is out of space, handle it like a return of 0
-		 */
-		if ((errno == ENOSPC) || (errno == EFBIG)
-#ifdef EDQUOT
-			|| (errno == EDQUOT)
-#endif
-			)
-			res = lstrval = 0;
-		break;
-	case ISTAPE:
-	case ISCHR:
-	case ISBLK:
-		if (res >= 0)
-			break;
-		if (errno == EACCES) {
-			paxwarn(0, "Write failed, archive is write protected.");
-			res = lstrval = 0;
-			return(0);
-		}
-		/*
-		 * see if we reached the end of media, if so force a change to
-		 * the next volume
-		 */
-		if ((errno == ENOSPC) || (errno == EIO) || (errno == ENXIO))
-			res = lstrval = 0;
-		break;
-	case ISPIPE:
-	default:
-		/*
-		 * we cannot fix errors to these devices
-		 */
-		break;
-	}
-
-	/*
-	 * Better tell the user the bad news...
-	 * if this is a block aligned archive format, we may have a bad archive
-	 * if the format wants the header to start at a BLKMULT boundary. While
-	 * we can deal with the mis-aligned data, it violates spec and other
-	 * archive readers will likely fail. if the format is not block
-	 * aligned, the user may be lucky (and the archive is ok).
-	 */
-	if (res >= 0) {
-		if (res > 0)
-			wr_trail = 1;
-		io_ok = 1;
-	}
-
-	/*
-	 * If we were trying to rewrite the trailer and it didn't work, we
-	 * must quit right away.
-	 */
-	if (!wr_trail && (res <= 0)) {
-		paxwarn(1,"Unable to append, trailer re-write failed. Quitting.");
-		return(res);
-	}
-
-	if (res == 0)
-		paxwarn(0, "End of archive volume %d reached", arvol);
-	else if (res < 0)
-		syswarn(1, errno, "Failed write to archive volume: %d", arvol);
-	else if (!frmt->blkalgn || ((res % frmt->blkalgn) == 0))
-		paxwarn(0,"WARNING: partial archive write. Archive MAY BE FLAWED");
-	else
-		paxwarn(1,"WARNING: partial archive write. Archive IS FLAWED");
-	return(res);
-}
-
-/*
- * ar_rdsync()
- *	Try to move past a bad spot on a flawed archive as needed to continue
- *	I/O. Clears error flags to allow I/O to continue.
- * Return:
- *	0 when ok to try i/o again, -1 otherwise.
- */
-
-int
-ar_rdsync(void)
-{
-	long fsbz;
-	off_t cpos;
-	off_t mpos;
-	struct mtop mb;
-
-	/*
-	 * Fail resync attempts at user request (done) or this is going to be
-	 * an update/append to an existing archive. If last i/o hit media end,
-	 * we need to go to the next volume not try a resync.
-	 */
-	if ((done > 0) || (lstrval == 0))
-		return(-1);
-
-	if ((act == APPND) || (act == ARCHIVE)) {
-		paxwarn(1, "Cannot allow updates to an archive with flaws.");
-		return(-1);
-	}
-	if (io_ok)
-		did_io = 1;
-
-	switch(artyp) {
-	case ISTAPE:
-		/*
-		 * if the last i/o was a successful data transfer, we assume
-		 * the fault is just a bad record on the tape that we are now
-		 * past. If we did not get any data since the last resync try
-		 * to move the tape forward one PHYSICAL record past any
-		 * damaged tape section. Some tape drives are stubborn and need
-		 * to be pushed.
-		 */
-		if (io_ok) {
-			io_ok = 0;
-			lstrval = 1;
-			break;
-		}
-		mb.mt_op = MTFSR;
-		mb.mt_count = 1;
-		if (ioctl(arfd, MTIOCTOP, &mb) < 0)
-			break;
-		lstrval = 1;
-		break;
-	case ISREG:
-	case ISCHR:
-	case ISBLK:
-		/*
-		 * try to step over the bad part of the device.
-		 */
-		io_ok = 0;
-#if 0
-	/* no blksize on minix */
-		if (((fsbz = arsb.st_blksize) <= 0) || (artyp != ISREG))
-#endif
-			fsbz = BLKMULT;
-		if ((cpos = lseek(arfd, (off_t)0L, SEEK_CUR)) < 0)
-			break;
-		mpos = fsbz - (cpos % (off_t)fsbz);
-		if (lseek(arfd, mpos, SEEK_CUR) < 0)
-			break;
-		lstrval = 1;
-		break;
-	case ISPIPE:
-	default:
-		/*
-		 * cannot recover on these archive device types
-		 */
-		io_ok = 0;
-		break;
-	}
-	if (lstrval <= 0) {
-		paxwarn(1, "Unable to recover from an archive read failure.");
-		return(-1);
-	}
-	paxwarn(0, "Attempting to recover from an archive read failure.");
-	return(0);
-}
-
-/*
- * ar_fow()
- *	Move the I/O position within the archive foward the specified number of
- *	bytes as supported by the device. If we cannot move the requested
- *	number of bytes, return the actual number of bytes moved in skipped.
- * Return:
- *	0 if moved the requested distance, -1 on complete failure, 1 on
- *	partial move (the amount moved is in skipped)
- */
-
-int
-ar_fow(off_t sksz, off_t *skipped)
-{
-	off_t cpos;
-	off_t mpos;
-
-	*skipped = 0;
-	if (sksz <= 0)
-		return(0);
-
-	/*
-	 * we cannot move foward at EOF or error
-	 */
-	if (lstrval <= 0)
-		return(lstrval);
-
-	/*
-	 * Safer to read forward on devices where it is hard to find the end of
-	 * the media without reading to it. With tapes we cannot be sure of the
-	 * number of physical blocks to skip (we do not know physical block
-	 * size at this point), so we must only read foward on tapes!
-	 */
-	if (artyp != ISREG)
-		return(0);
-
-	/*
-	 * figure out where we are in the archive
-	 */
-	if ((cpos = lseek(arfd, (off_t)0L, SEEK_CUR)) >= 0) {
-		/*
-	 	 * we can be asked to move farther than there are bytes in this
-		 * volume, if so, just go to file end and let normal buf_fill()
-		 * deal with the end of file (it will go to next volume by
-		 * itself)
-	 	 */
-		if ((mpos = cpos + sksz) > arsb.st_size) {
-			*skipped = arsb.st_size - cpos;
-			mpos = arsb.st_size;
-		} else
-			*skipped = sksz;
-		if (lseek(arfd, mpos, SEEK_SET) >= 0)
-			return(0);
-	}
-	syswarn(1, errno, "Forward positioning operation on archive failed");
-	lstrval = -1;
-	return(-1);
-}
-
-/*
- * ar_rev()
- *	move the i/o position within the archive backwards the specified byte
- *	count as supported by the device. With tapes drives we RESET rdblksz to
- *	the PHYSICAL blocksize.
- *	NOTE: We should only be called to move backwards so we can rewrite the
- *	last records (the trailer) of an archive (APPEND).
- * Return:
- *	0 if moved the requested distance, -1 on complete failure
- */
-
-int
-ar_rev(off_t sksz)
-{
-	off_t cpos;
-	struct mtop mb;
-	int phyblk;
-
-	/*
-	 * make sure we do not have try to reverse on a flawed archive
-	 */
-	if (lstrval < 0)
-		return(lstrval);
-
-	switch(artyp) {
-	case ISPIPE:
-		if (sksz <= 0)
-			break;
-		/*
-		 * cannot go backwards on these critters
-		 */
-		paxwarn(1, "Reverse positioning on pipes is not supported.");
-		lstrval = -1;
-		return(-1);
-	case ISREG:
-	case ISBLK:
-	case ISCHR:
-	default:
-		if (sksz <= 0)
-			break;
-
-		/*
-		 * For things other than files, backwards movement has a very
-		 * high probability of failure as we really do not know the
-		 * true attributes of the device we are talking to (the device
-		 * may not even have the ability to lseek() in any direction).
-		 * First we figure out where we are in the archive.
-		 */
-		if ((cpos = lseek(arfd, (off_t)0L, SEEK_CUR)) < 0) {
-			syswarn(1, errno,
-			   "Unable to obtain current archive byte offset");
-			lstrval = -1;
-			return(-1);
-		}
-
-		/*
-		 * we may try to go backwards past the start when the archive
-		 * is only a single record. If this hapens and we are on a
-		 * multi volume archive, we need to go to the end of the
-		 * previous volume and continue our movement backwards from
-		 * there.
-		 */
-		if ((cpos -= sksz) < (off_t)0L) {
-			if (arvol > 1) {
-				/*
-				 * this should never happen
-				 */
-				paxwarn(1,"Reverse position on previous volume.");
-				lstrval = -1;
-				return(-1);
-			}
-			cpos = (off_t)0L;
-		}
-		if (lseek(arfd, cpos, SEEK_SET) < 0) {
-			syswarn(1, errno, "Unable to seek archive backwards");
-			lstrval = -1;
-			return(-1);
-		}
-		break;
-	case ISTAPE:
-		/*
-	 	 * Calculate and move the proper number of PHYSICAL tape
-		 * blocks. If the sksz is not an even multiple of the physical
-		 * tape size, we cannot do the move (this should never happen).
-		 * (We also cannot handler trailers spread over two vols).
-		 * get_phys() also makes sure we are in front of the filemark.
-	 	 */
-		if ((phyblk = get_phys()) <= 0) {
-			lstrval = -1;
-			return(-1);
-		}
-
-		/*
-		 * make sure future tape reads only go by physical tape block
-		 * size (set rdblksz to the real size).
-		 */
-		rdblksz = phyblk;
-
-		/*
-		 * if no movement is required, just return (we must be after
-		 * get_phys() so the physical blocksize is properly set)
-		 */
-		if (sksz <= 0)
-			break;
-
-		/*
-		 * ok we have to move. Make sure the tape drive can do it.
-		 */
-		if (sksz % phyblk) {
-			paxwarn(1,
-			    "Tape drive unable to backspace requested amount");
-			lstrval = -1;
-			return(-1);
-		}
-
-		/*
-		 * move backwards the requested number of bytes
-		 */
-		mb.mt_op = MTBSR;
-		mb.mt_count = sksz/phyblk;
-		if (ioctl(arfd, MTIOCTOP, &mb) < 0) {
-			syswarn(1,errno, "Unable to backspace tape %d blocks.",
-			    mb.mt_count);
-			lstrval = -1;
-			return(-1);
-		}
-		break;
-	}
-	lstrval = 1;
-	return(0);
-}
-
-/*
- * get_phys()
- *	Determine the physical block size on a tape drive. We need the physical
- *	block size so we know how many bytes we skip over when we move with
- *	mtio commands. We also make sure we are BEFORE THE TAPE FILEMARK when
- *	return.
- *	This is one really SLOW routine...
- * Return:
- *	physical block size if ok (ok > 0), -1 otherwise
- */
-
-static int
-get_phys(void)
-{
-	int padsz = 0;
-	int res;
-	int phyblk;
-	struct mtop mb;
-	char scbuf[MAXBLK];
-
-	/*
-	 * move to the file mark, and then back up one record and read it.
-	 * this should tell us the physical record size the tape is using.
-	 */
-	if (lstrval == 1) {
-		/*
-		 * we know we are at file mark when we get back a 0 from
-		 * read()
-		 */
-		while ((res = read(arfd, scbuf, sizeof(scbuf))) > 0)
-			padsz += res;
-		if (res < 0) {
-			syswarn(1, errno, "Unable to locate tape filemark.");
-			return(-1);
-		}
-	}
-
-	/*
-	 * move backwards over the file mark so we are at the end of the
-	 * last record.
-	 */
-	mb.mt_op = MTBSF;
-	mb.mt_count = 1;
-	if (ioctl(arfd, MTIOCTOP, &mb) < 0) {
-		syswarn(1, errno, "Unable to backspace over tape filemark.");
-		return(-1);
-	}
-
-	/*
-	 * move backwards so we are in front of the last record and read it to
-	 * get physical tape blocksize.
-	 */
-	mb.mt_op = MTBSR;
-	mb.mt_count = 1;
-	if (ioctl(arfd, MTIOCTOP, &mb) < 0) {
-		syswarn(1, errno, "Unable to backspace over last tape block.");
-		return(-1);
-	}
-	if ((phyblk = read(arfd, scbuf, sizeof(scbuf))) <= 0) {
-		syswarn(1, errno, "Cannot determine archive tape blocksize.");
-		return(-1);
-	}
-
-	/*
-	 * read foward to the file mark, then back up in front of the filemark
-	 * (this is a bit paranoid, but should be safe to do).
-	 */
-	while ((res = read(arfd, scbuf, sizeof(scbuf))) > 0)
-		;
-	if (res < 0) {
-		syswarn(1, errno, "Unable to locate tape filemark.");
-		return(-1);
-	}
-	mb.mt_op = MTBSF;
-	mb.mt_count = 1;
-	if (ioctl(arfd, MTIOCTOP, &mb) < 0) {
-		syswarn(1, errno, "Unable to backspace over tape filemark.");
-		return(-1);
-	}
-
-	/*
-	 * set lstrval so we know that the filemark has not been seen
-	 */
-	lstrval = 1;
-
-	/*
-	 * return if there was no padding
-	 */
-	if (padsz == 0)
-		return(phyblk);
-
-	/*
-	 * make sure we can move backwards over the padding. (this should
-	 * never fail).
-	 */
-	if (padsz % phyblk) {
-		paxwarn(1, "Tape drive unable to backspace requested amount");
-		return(-1);
-	}
-
-	/*
-	 * move backwards over the padding so the head is where it was when
-	 * we were first called (if required).
-	 */
-	mb.mt_op = MTBSR;
-	mb.mt_count = padsz/phyblk;
-	if (ioctl(arfd, MTIOCTOP, &mb) < 0) {
-		syswarn(1,errno,"Unable to backspace tape over %d pad blocks",
-		    mb.mt_count);
-		return(-1);
-	}
-	return(phyblk);
-}
-
-/*
- * ar_next()
- *	prompts the user for the next volume in this archive. For some devices
- *	we may allow the media to be changed. Otherwise a new archive is
- *	prompted for. By pax spec, if there is no controlling tty or an eof is
- *	read on tty input, we must quit pax.
- * Return:
- *	0 when ready to continue, -1 when all done
- */
-
-int
-ar_next(void)
-{
-	char buf[PAXPATHLEN+2];
-	static int freeit = 0;
-	sigset_t o_mask;
-
-	/*
-	 * WE MUST CLOSE THE DEVICE. A lot of devices must see last close, (so
-	 * things like writing EOF etc will be done) (Watch out ar_close() can
-	 * also be called via a signal handler, so we must prevent a race.
-	 */
-	if (sigprocmask(SIG_BLOCK, &s_mask, &o_mask) < 0)
-		syswarn(0, errno, "Unable to set signal mask");
-	ar_close();
-	if (sigprocmask(SIG_SETMASK, &o_mask, NULL) < 0)
-		syswarn(0, errno, "Unable to restore signal mask");
-
-	if (done || !wr_trail || strcmp(NM_TAR, argv0) == 0)
-		return(-1);
-
-	tty_prnt("\nATTENTION! %s archive volume change required.\n", argv0);
-
-	/*
-	 * if i/o is on stdin or stdout, we cannot reopen it (we do not know
-	 * the name), the user will be forced to type it in.
-	 */
-	if (strcmp(arcname, stdo) && strcmp(arcname, stdn) && (artyp != ISREG)
-	    && (artyp != ISPIPE)) {
-		if (artyp == ISTAPE) {
-			tty_prnt("%s ready for archive tape volume: %d\n",
-				arcname, arvol);
-			tty_prnt("Load the NEXT TAPE on the tape drive");
-		} else {
-			tty_prnt("%s ready for archive volume: %d\n",
-				arcname, arvol);
-			tty_prnt("Load the NEXT STORAGE MEDIA (if required)");
-		}
-
-		if ((act == ARCHIVE) || (act == APPND))
-			tty_prnt(" and make sure it is WRITE ENABLED.\n");
-		else
-			tty_prnt("\n");
-
-		for(;;) {
-			tty_prnt("Type \"y\" to continue, \".\" to quit %s,",
-				argv0);
-			tty_prnt(" or \"s\" to switch to new device.\nIf you");
-			tty_prnt(" cannot change storage media, type \"s\"\n");
-			tty_prnt("Is the device ready and online? > ");
-
-			if ((tty_read(buf,sizeof(buf))<0) || !strcmp(buf,".")){
-				done = 1;
-				lstrval = -1;
-				tty_prnt("Quitting %s!\n", argv0);
-				vfpart = 0;
-				return(-1);
-			}
-
-			if ((buf[0] == '\0') || (buf[1] != '\0')) {
-				tty_prnt("%s unknown command, try again\n",buf);
-				continue;
-			}
-
-			switch (buf[0]) {
-			case 'y':
-			case 'Y':
-				/*
-				 * we are to continue with the same device
-				 */
-				if (ar_open(arcname) >= 0)
-					return(0);
-				tty_prnt("Cannot re-open %s, try again\n",
-					arcname);
-				continue;
-			case 's':
-			case 'S':
-				/*
-				 * user wants to open a different device
-				 */
-				tty_prnt("Switching to a different archive\n");
-				break;
-			default:
-				tty_prnt("%s unknown command, try again\n",buf);
-				continue;
-			}
-			break;
-		}
-	} else
-		tty_prnt("Ready for archive volume: %d\n", arvol);
-
-	/*
-	 * have to go to a different archive
-	 */
-	for (;;) {
-		tty_prnt("Input archive name or \".\" to quit %s.\n", argv0);
-		tty_prnt("Archive name > ");
-
-		if ((tty_read(buf, sizeof(buf)) < 0) || !strcmp(buf, ".")) {
-			done = 1;
-			lstrval = -1;
-			tty_prnt("Quitting %s!\n", argv0);
-			vfpart = 0;
-			return(-1);
-		}
-		if (buf[0] == '\0') {
-			tty_prnt("Empty file name, try again\n");
-			continue;
-		}
-		if (!strcmp(buf, "..")) {
-			tty_prnt("Illegal file name: .. try again\n");
-			continue;
-		}
-		if (strlen(buf) > PAXPATHLEN) {
-			tty_prnt("File name too long, try again\n");
-			continue;
-		}
-
-		/*
-		 * try to open new archive
-		 */
-		if (ar_open(buf) >= 0) {
-			if (freeit) {
-				(void)free((char *)(uintptr_t)arcname);
-				freeit = 0;
-			}
-			if ((arcname = strdup(buf)) == NULL) {
-				done = 1;
-				lstrval = -1;
-				paxwarn(0, "Cannot save archive name.");
-				return(-1);
-			}
-			freeit = 1;
-			break;
-		}
-		tty_prnt("Cannot open %s, try again\n", buf);
-		continue;
-	}
-	return(0);
-}
-
-/*
- * ar_start_gzip()
- * starts the gzip compression/decompression process as a child, using magic
- * to keep the fd the same in the calling function (parent).
- */
-static void
-ar_start_gzip(int fd, const char *gzip_prog, int wr)
-{
-	int fds[2];
-	const char *gzip_flags;
-
-	if (pipe(fds) < 0)
-		err(1, "could not pipe");
-	zpid = fork();
-	if (zpid < 0)
-		err(1, "could not fork");
-
-	/* parent */
-	if (zpid) {
-		if (wr)
-			dup2(fds[1], fd);
-		else
-			dup2(fds[0], fd);
-		close(fds[0]);
-		close(fds[1]);
-	} else {
-		if (wr) {
-			dup2(fds[0], STDIN_FILENO);
-			dup2(fd, STDOUT_FILENO);
-			gzip_flags = "-c";
-		} else {
-			dup2(fds[1], STDOUT_FILENO);
-			dup2(fd, STDIN_FILENO);
-			gzip_flags = "-dc";
-		}
-		close(fds[0]);
-		close(fds[1]);
-		if (execlp(gzip_prog, gzip_prog, gzip_flags,
-		    (char *)NULL) < 0)
-			err(1, "could not exec");
-		/* NOTREACHED */
-	}
-}
Index: trunk/minix/commands/pax/ar_subs.c
===================================================================
--- trunk/minix/commands/pax/ar_subs.c	(revision 9)
+++ 	(revision )
@@ -1,1237 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)ar_subs.c	8.2 (Berkeley) 4/18/94";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <string.h>
-#include <time.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "pax.h"
-#include "extern.h"
-
-static void wr_archive(ARCHD *, int is_app);
-static int get_arc(void);
-static int next_head(ARCHD *);
-extern sigset_t s_mask;
-
-/*
- * Routines which control the overall operation modes of pax as specified by
- * the user: list, append, read ...
- */
-
-static char hdbuf[BLKMULT];		/* space for archive header on read */
-u_long flcnt;				/* number of files processed */
-
-/*
- * list()
- *	list the contents of an archive which match user supplied pattern(s)
- *	(no pattern matches all).
- */
-
-void
-list(void)
-{
-	ARCHD *arcn;
-	int res;
-	ARCHD archd;
-	time_t now;
-
-	arcn = &archd;
-	/*
-	 * figure out archive type; pass any format specific options to the
-	 * archive option processing routine; call the format init routine. We
-	 * also save current time for ls_list() so we do not make a system
-	 * call for each file we need to print. If verbose (vflag) start up
-	 * the name and group caches.
-	 */
-	if ((get_arc() < 0) || ((*frmt->options)() < 0) ||
-	    ((*frmt->st_rd)() < 0))
-		return;
-
-	if (vflag && ((uidtb_start() < 0) || (gidtb_start() < 0)))
-		return;
-
-	now = time(NULL);
-
-	/*
-	 * step through the archive until the format says it is done
-	 */
-	while (next_head(arcn) == 0) {
-		/*
-		 * check for pattern, and user specified options match.
-		 * When all patterns are matched we are done.
-		 */
-		if ((res = pat_match(arcn)) < 0)
-			break;
-
-		if ((res == 0) && (sel_chk(arcn) == 0)) {
-			/*
-			 * pattern resulted in a selected file
-			 */
-			if (pat_sel(arcn) < 0)
-				break;
-
-			/*
-			 * modify the name as requested by the user if name
-			 * survives modification, do a listing of the file
-			 */
-			if ((res = mod_name(arcn)) < 0)
-				break;
-			if (res == 0)
-				ls_list(arcn, now, stdout);
-		}
-
-		/*
-		 * skip to next archive format header using values calculated
-		 * by the format header read routine
-		 */
-		if (rd_skip(arcn->skip + arcn->pad) == 1)
-			break;
-	}
-
-	/*
-	 * all done, let format have a chance to cleanup, and make sure that
-	 * the patterns supplied by the user were all matched
-	 */
-	(void)(*frmt->end_rd)();
-	(void)sigprocmask(SIG_BLOCK, &s_mask, NULL);
-	ar_close();
-	pat_chk();
-}
-
-/*
- * extract()
- *	extract the member(s) of an archive as specified by user supplied
- *	pattern(s) (no patterns extracts all members)
- */
-
-void
-extract(void)
-{
-	ARCHD *arcn;
-	int res;
-	off_t cnt;
-	ARCHD archd;
-	struct stat sb;
-	int fd;
-	time_t now;
-
-	arcn = &archd;
-	/*
-	 * figure out archive type; pass any format specific options to the
-	 * archive option processing routine; call the format init routine;
-	 * start up the directory modification time and access mode database
-	 */
-	if ((get_arc() < 0) || ((*frmt->options)() < 0) ||
-	    ((*frmt->st_rd)() < 0) || (dir_start() < 0))
-		return;
-
-	/*
-	 * When we are doing interactive rename, we store the mapping of names
-	 * so we can fix up hard links files later in the archive.
-	 */
-	if (iflag && (name_start() < 0))
-		return;
-
-	now = time(NULL);
-
-	/*
-	 * step through each entry on the archive until the format read routine
-	 * says it is done
-	 */
-	while (next_head(arcn) == 0) {
-
-		/*
-		 * check for pattern, and user specified options match. When
-		 * all the patterns are matched we are done
-		 */
-		if ((res = pat_match(arcn)) < 0)
-			break;
-
-		if ((res > 0) || (sel_chk(arcn) != 0)) {
-			/*
-			 * file is not selected. skip past any file data and
-			 * padding and go back for the next archive member
-			 */
-			(void)rd_skip(arcn->skip + arcn->pad);
-			continue;
-		}
-
-		/*
-		 * with -u or -D only extract when the archive member is newer
-		 * than the file with the same name in the file system (nos
-		 * test of being the same type is required).
-		 * NOTE: this test is done BEFORE name modifications as
-		 * specified by pax. this operation can be confusing to the
-		 * user who might expect the test to be done on an existing
-		 * file AFTER the name mod. In honesty the pax spec is probably
-		 * flawed in this respect.
-		 */
-		if ((uflag || Dflag) && ((lstat(arcn->name, &sb) == 0))) {
-			if (uflag && Dflag) {
-				if ((arcn->sb.st_mtime <= sb.st_mtime) &&
-				    (arcn->sb.st_ctime <= sb.st_ctime)) {
-					(void)rd_skip(arcn->skip + arcn->pad);
-					continue;
-				}
-			} else if (Dflag) {
-				if (arcn->sb.st_ctime <= sb.st_ctime) {
-					(void)rd_skip(arcn->skip + arcn->pad);
-					continue;
-				}
-			} else if (arcn->sb.st_mtime <= sb.st_mtime) {
-				(void)rd_skip(arcn->skip + arcn->pad);
-				continue;
-			}
-		}
-
-		/*
-		 * this archive member is now been selected. modify the name.
-		 */
-		if ((pat_sel(arcn) < 0) || ((res = mod_name(arcn)) < 0))
-			break;
-		if (res > 0) {
-			/*
-			 * a bad name mod, skip and purge name from link table
-			 */
-			purg_lnk(arcn);
-			(void)rd_skip(arcn->skip + arcn->pad);
-			continue;
-		}
-
-		/*
-		 * Non standard -Y and -Z flag. When the existing file is
-		 * same age or newer skip
-		 */
-		if ((Yflag || Zflag) && ((lstat(arcn->name, &sb) == 0))) {
-			if (Yflag && Zflag) {
-				if ((arcn->sb.st_mtime <= sb.st_mtime) &&
-				    (arcn->sb.st_ctime <= sb.st_ctime)) {
-					(void)rd_skip(arcn->skip + arcn->pad);
-					continue;
-				}
-			} else if (Yflag) {
-				if (arcn->sb.st_ctime <= sb.st_ctime) {
-					(void)rd_skip(arcn->skip + arcn->pad);
-					continue;
-				}
-			} else if (arcn->sb.st_mtime <= sb.st_mtime) {
-				(void)rd_skip(arcn->skip + arcn->pad);
-				continue;
-			}
-		}
-
-		if (vflag) {
-			if (vflag > 1)
-				ls_list(arcn, now, listf);
-			else {
-				(void)fputs(arcn->name, listf);
-				vfpart = 1;
-			}
-		}
-
-		/*
-		 * if required, chdir around.
-		 */
-		if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL))
-			if (chdir(arcn->pat->chdname) != 0)
-				syswarn(1, errno, "Cannot chdir to %s",
-				    arcn->pat->chdname);
-
-		/*
-		 * all ok, extract this member based on type
-		 */
-		if ((arcn->type != PAX_REG) && (arcn->type != PAX_CTG)) {
-			/*
-			 * process archive members that are not regular files.
-			 * throw out padding and any data that might follow the
-			 * header (as determined by the format).
-			 */
-			if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))
-				res = lnk_creat(arcn);
-			else
-				res = node_creat(arcn);
-
-			(void)rd_skip(arcn->skip + arcn->pad);
-			if (res < 0)
-				purg_lnk(arcn);
-
-			if (vflag && vfpart) {
-				(void)putc('\n', listf);
-				vfpart = 0;
-			}
-			continue;
-		}
-		/*
-		 * we have a file with data here. If we can not create it, skip
-		 * over the data and purge the name from hard link table
-		 */
-		if ((fd = file_creat(arcn)) < 0) {
-			(void)rd_skip(arcn->skip + arcn->pad);
-			purg_lnk(arcn);
-			continue;
-		}
-		/*
-		 * extract the file from the archive and skip over padding and
-		 * any unprocessed data
-		 */
-		res = (*frmt->rd_data)(arcn, fd, &cnt);
-		file_close(arcn, fd);
-		if (vflag && vfpart) {
-			(void)putc('\n', listf);
-			vfpart = 0;
-		}
-		if (!res)
-			(void)rd_skip(cnt + arcn->pad);
-
-		/*
-		 * if required, chdir around.
-		 */
-		if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL))
-			if (fchdir(cwdfd) != 0)
-				syswarn(1, errno,
-				    "Can't fchdir to starting directory");
-	}
-
-	/*
-	 * all done, restore directory modes and times as required; make sure
-	 * all patterns supplied by the user were matched; block off signals
-	 * to avoid chance for multiple entry into the cleanup code.
-	 */
-	(void)(*frmt->end_rd)();
-	(void)sigprocmask(SIG_BLOCK, &s_mask, NULL);
-	ar_close();
-	proc_dir();
-	pat_chk();
-}
-
-/*
- * wr_archive()
- *	Write an archive. used in both creating a new archive and appends on
- *	previously written archive.
- */
-
-static void
-wr_archive(ARCHD *arcn, int is_app)
-{
-	int res;
-	int hlk;
-	int wr_one;
-	off_t cnt;
-	int (*wrf)(ARCHD *);
-	int fd = -1;
-	time_t now;
-
-	/*
-	 * if this format supports hard link storage, start up the database
-	 * that detects them.
-	 */
-	if (((hlk = frmt->hlk) == 1) && (lnk_start() < 0))
-		return;
-
-	/*
-	 * start up the file traversal code and format specific write
-	 */
-	if ((ftree_start() < 0) || ((*frmt->st_wr)() < 0))
-		return;
-	wrf = frmt->wr;
-
-	/*
-	 * When we are doing interactive rename, we store the mapping of names
-	 * so we can fix up hard links files later in the archive.
-	 */
-	if (iflag && (name_start() < 0))
-		return;
-
-	/*
-	 * if this not append, and there are no files, we do no write a trailer
-	 */
-	wr_one = is_app;
-
-	now = time(NULL);
-
-	/*
-	 * while there are files to archive, process them one at at time
-	 */
-	while (next_file(arcn) == 0) {
-		/*
-		 * check if this file meets user specified options match.
-		 */
-		if (sel_chk(arcn) != 0) {
-			ftree_notsel();
-			continue;
-		}
-		fd = -1;
-		if (uflag) {
-			/*
-			 * only archive if this file is newer than a file with
-			 * the same name that is already stored on the archive
-			 */
-			if ((res = chk_ftime(arcn)) < 0)
-				break;
-			if (res > 0)
-				continue;
-		}
-
-		/*
-		 * this file is considered selected now. see if this is a hard
-		 * link to a file already stored
-		 */
-		ftree_sel(arcn);
-		if (hlk && (chk_lnk(arcn) < 0))
-			break;
-
-		if ((arcn->type == PAX_REG) || (arcn->type == PAX_HRG) ||
-		    (arcn->type == PAX_CTG)) {
-			/*
-			 * we will have to read this file. by opening it now we
-			 * can avoid writing a header to the archive for a file
-			 * we were later unable to read (we also purge it from
-			 * the link table).
-			 */
-			if ((fd = open(arcn->org_name, O_RDONLY, 0)) < 0) {
-				syswarn(1,errno, "Unable to open %s to read",
-					arcn->org_name);
-				purg_lnk(arcn);
-				continue;
-			}
-		}
-
-		/*
-		 * Now modify the name as requested by the user
-		 */
-		if ((res = mod_name(arcn)) < 0) {
-			/*
-			 * name modification says to skip this file, close the
-			 * file and purge link table entry
-			 */
-			rdfile_close(arcn, &fd);
-			purg_lnk(arcn);
-			break;
-		}
-
-		if ((res > 0) || (docrc && (set_crc(arcn, fd) < 0))) {
-			/*
-			 * unable to obtain the crc we need, close the file,
-			 * purge link table entry
-			 */
-			rdfile_close(arcn, &fd);
-			purg_lnk(arcn);
-			continue;
-		}
-
-		if (vflag) {
-			if (vflag > 1)
-				ls_list(arcn, now, listf);
-			else {
-				(void)fputs(arcn->name, listf);
-				vfpart = 1;
-			}
-		}
-		++flcnt;
-
-		/*
-		 * looks safe to store the file, have the format specific
-		 * routine write routine store the file header on the archive
-		 */
-		if ((res = (*wrf)(arcn)) < 0) {
-			rdfile_close(arcn, &fd);
-			break;
-		}
-		wr_one = 1;
-		if (res > 0) {
-			/*
-			 * format write says no file data needs to be stored
-			 * so we are done messing with this file
-			 */
-			if (vflag && vfpart) {
-				(void)putc('\n', listf);
-				vfpart = 0;
-			}
-			rdfile_close(arcn, &fd);
-			continue;
-		}
-
-		/*
-		 * Add file data to the archive, quit on write error. if we
-		 * cannot write the entire file contents to the archive we
-		 * must pad the archive to replace the missing file data
-		 * (otherwise during an extract the file header for the file
-		 * which FOLLOWS this one will not be where we expect it to
-		 * be).
-		 */
-		res = (*frmt->wr_data)(arcn, fd, &cnt);
-		rdfile_close(arcn, &fd);
-		if (vflag && vfpart) {
-			(void)putc('\n', listf);
-			vfpart = 0;
-		}
-		if (res < 0)
-			break;
-
-		/*
-		 * pad as required, cnt is number of bytes not written
-		 */
-		if (((cnt > 0) && (wr_skip(cnt) < 0)) ||
-		    ((arcn->pad > 0) && (wr_skip(arcn->pad) < 0)))
-			break;
-	}
-
-	/*
-	 * tell format to write trailer; pad to block boundary; reset directory
-	 * mode/access times, and check if all patterns supplied by the user
-	 * were matched. block off signals to avoid chance for multiple entry
-	 * into the cleanup code
-	 */
-	if (wr_one) {
-		(*frmt->end_wr)();
-		wr_fin();
-	}
-	(void)sigprocmask(SIG_BLOCK, &s_mask, NULL);
-	ar_close();
-	if (tflag)
-		proc_dir();
-	ftree_chk();
-}
-
-/*
- * append()
- *	Add file to previously written archive. Archive format specified by the
- *	user must agree with archive. The archive is read first to collect
- *	modification times (if -u) and locate the archive trailer. The archive
- *	is positioned in front of the record with the trailer and wr_archive()
- *	is called to add the new members.
- *	PAX IMPLEMENTATION DETAIL NOTE:
- *	-u is implemented by adding the new members to the end of the archive.
- *	Care is taken so that these do not end up as links to the older
- *	version of the same file already stored in the archive. It is expected
- *	when extraction occurs these newer versions will over-write the older
- *	ones stored "earlier" in the archive (this may be a bad assumption as
- *	it depends on the implementation of the program doing the extraction).
- *	It is really difficult to splice in members without either re-writing
- *	the entire archive (from the point were the old version was), or having
- *	assistance of the format specification in terms of a special update
- *	header that invalidates a previous archive record. The POSIX spec left
- *	the method used to implement -u unspecified. This pax is able to
- *	over write existing files that it creates.
- */
-
-void
-append(void)
-{
-	ARCHD *arcn;
-	int res;
-	ARCHD archd;
-	FSUB *orgfrmt;
-	int udev;
-	off_t tlen;
-
-	arcn = &archd;
-	orgfrmt = frmt;
-
-	/*
-	 * Do not allow an append operation if the actual archive is of a
-	 * different format than the user specified format.
-	 */
-	if (get_arc() < 0)
-		return;
-	if ((orgfrmt != NULL) && (orgfrmt != frmt)) {
-		paxwarn(1, "Cannot mix current archive format %s with %s",
-		    frmt->name, orgfrmt->name);
-		return;
-	}
-
-	/*
-	 * pass the format any options and start up format
-	 */
-	if (((*frmt->options)() < 0) || ((*frmt->st_rd)() < 0))
-		return;
-
-	/*
-	 * if we only are adding members that are newer, we need to save the
-	 * mod times for all files we see.
-	 */
-	if (uflag && (ftime_start() < 0))
-		return;
-
-	/*
-	 * some archive formats encode hard links by recording the device and
-	 * file serial number (inode) but copy the file anyway (multiple times)
-	 * to the archive. When we append, we run the risk that newly added
-	 * files may have the same device and inode numbers as those recorded
-	 * on the archive but during a previous run. If this happens, when the
-	 * archive is extracted we get INCORRECT hard links. We avoid this by
-	 * remapping the device numbers so that newly added files will never
-	 * use the same device number as one found on the archive. remapping
-	 * allows new members to safely have links among themselves. remapping
-	 * also avoids problems with file inode (serial number) truncations
-	 * when the inode number is larger than storage space in the archive
-	 * header. See the remap routines for more details.
-	 */
-	if ((udev = frmt->udev) && (dev_start() < 0))
-		return;
-
-	/*
-	 * reading the archive may take a long time. If verbose tell the user
-	 */
-	if (vflag) {
-		(void)fprintf(listf,
-			"%s: Reading archive to position at the end...", argv0);
-		vfpart = 1;
-	}
-
-	/*
-	 * step through the archive until the format says it is done
-	 */
-	while (next_head(arcn) == 0) {
-		/*
-		 * check if this file meets user specified options.
-		 */
-		if (sel_chk(arcn) != 0) {
-			if (rd_skip(arcn->skip + arcn->pad) == 1)
-				break;
-			continue;
-		}
-
-		if (uflag) {
-			/*
-			 * see if this is the newest version of this file has
-			 * already been seen, if so skip.
-			 */
-			if ((res = chk_ftime(arcn)) < 0)
-				break;
-			if (res > 0) {
-				if (rd_skip(arcn->skip + arcn->pad) == 1)
-					break;
-				continue;
-			}
-		}
-
-		/*
-		 * Store this device number. Device numbers seen during the
-		 * read phase of append will cause newly appended files with a
-		 * device number seen in the old part of the archive to be
-		 * remapped to an unused device number.
-		 */
-		if ((udev && (add_dev(arcn) < 0)) ||
-		    (rd_skip(arcn->skip + arcn->pad) == 1))
-			break;
-	}
-
-	/*
-	 * done, finish up read and get the number of bytes to back up so we
-	 * can add new members. The format might have used the hard link table,
-	 * purge it.
-	 */
-	tlen = (*frmt->end_rd)();
-	lnk_end();
-
-	/*
-	 * try to position for write, if this fails quit. if any error occurs,
-	 * we will refuse to write
-	 */
-	if (appnd_start(tlen) < 0)
-		return;
-
-	/*
-	 * tell the user we are done reading.
-	 */
-	if (vflag && vfpart) {
-		(void)fputs("done.\n", listf);
-		vfpart = 0;
-	}
-
-	/*
-	 * go to the writing phase to add the new members
-	 */
-	wr_archive(arcn, 1);
-}
-
-/*
- * archive()
- *	write a new archive
- */
-
-void
-archive(void)
-{
-	ARCHD archd;
-
-	/*
-	 * if we only are adding members that are newer, we need to save the
-	 * mod times for all files; set up for writing; pass the format any
-	 * options write the archive
-	 */
-	if ((uflag && (ftime_start() < 0)) || (wr_start() < 0))
-		return;
-	if ((*frmt->options)() < 0)
-		return;
-
-	wr_archive(&archd, 0);
-}
-
-/*
- * copy()
- *	copy files from one part of the file system to another. this does not
- *	use any archive storage. The EFFECT OF THE COPY IS THE SAME as if an
- *	archive was written and then extracted in the destination directory
- *	(except the files are forced to be under the destination directory).
- */
-
-void
-copy(void)
-{
-	ARCHD *arcn;
-	int res;
-	int fddest;
-	char *dest_pt;
-	int dlen;
-	int drem;
-	int fdsrc = -1;
-	struct stat sb;
-	ARCHD archd;
-	char dirbuf[PAXPATHLEN+1];
-
-	arcn = &archd;
-	/*
-	 * set up the destination dir path and make sure it is a directory. We
-	 * make sure we have a trailing / on the destination
-	 */
-	dlen = l_strncpy(dirbuf, dirptr, sizeof(dirbuf) - 1);
-	dest_pt = dirbuf + dlen;
-	if (*(dest_pt-1) != '/') {
-		*dest_pt++ = '/';
-		++dlen;
-	}
-	*dest_pt = '\0';
-	drem = PAXPATHLEN - dlen;
-
-	if (stat(dirptr, &sb) < 0) {
-		syswarn(1, errno, "Cannot access destination directory %s",
-			dirptr);
-		return;
-	}
-	if (!S_ISDIR(sb.st_mode)) {
-		paxwarn(1, "Destination is not a directory %s", dirptr);
-		return;
-	}
-
-	/*
-	 * start up the hard link table; file traversal routines and the
-	 * modification time and access mode database
-	 */
-	if ((lnk_start() < 0) || (ftree_start() < 0) || (dir_start() < 0))
-		return;
-
-	/*
-	 * When we are doing interactive rename, we store the mapping of names
-	 * so we can fix up hard links files later in the archive.
-	 */
-	if (iflag && (name_start() < 0))
-		return;
-
-	/*
-	 * set up to cp file trees
-	 */
-	cp_start();
-
-	/*
-	 * while there are files to archive, process them
-	 */
-	while (next_file(arcn) == 0) {
-		fdsrc = -1;
-
-		/*
-		 * check if this file meets user specified options
-		 */
-		if (sel_chk(arcn) != 0) {
-			ftree_notsel();
-			continue;
-		}
-
-		/*
-		 * if there is already a file in the destination directory with
-		 * the same name and it is newer, skip the one stored on the
-		 * archive.
-		 * NOTE: this test is done BEFORE name modifications as
-		 * specified by pax. this can be confusing to the user who
-		 * might expect the test to be done on an existing file AFTER
-		 * the name mod. In honesty the pax spec is probably flawed in
-		 * this respect
-		 */
-		if (uflag || Dflag) {
-			/*
-			 * create the destination name
-			 */
-			if (*(arcn->name) == '/')
-				res = 1;
-			else
-				res = 0;
-			if ((arcn->nlen - res) > drem) {
-				paxwarn(1, "Destination pathname too long %s",
-					arcn->name);
-				continue;
-			}
-			(void)strncpy(dest_pt, arcn->name + res, drem);
-			dirbuf[PAXPATHLEN] = '\0';
-
-			/*
-			 * if existing file is same age or newer skip
-			 */
-			res = lstat(dirbuf, &sb);
-			*dest_pt = '\0';
-
-		    	if (res == 0) {
-				if (uflag && Dflag) {
-					if ((arcn->sb.st_mtime<=sb.st_mtime) &&
-			    		    (arcn->sb.st_ctime<=sb.st_ctime))
-						continue;
-				} else if (Dflag) {
-					if (arcn->sb.st_ctime <= sb.st_ctime)
-						continue;
-				} else if (arcn->sb.st_mtime <= sb.st_mtime)
-					continue;
-			}
-		}
-
-		/*
-		 * this file is considered selected. See if this is a hard link
-		 * to a previous file; modify the name as requested by the
-		 * user; set the final destination.
-		 */
-		ftree_sel(arcn);
-		if ((chk_lnk(arcn) < 0) || ((res = mod_name(arcn)) < 0))
-			break;
-		if ((res > 0) || (set_dest(arcn, dirbuf, dlen) < 0)) {
-			/*
-			 * skip file, purge from link table
-			 */
-			purg_lnk(arcn);
-			continue;
-		}
-
-		/*
-		 * Non standard -Y and -Z flag. When the exisiting file is
-		 * same age or newer skip
-		 */
-		if ((Yflag || Zflag) && ((lstat(arcn->name, &sb) == 0))) {
-			if (Yflag && Zflag) {
-				if ((arcn->sb.st_mtime <= sb.st_mtime) &&
-				    (arcn->sb.st_ctime <= sb.st_ctime))
-					continue;
-			} else if (Yflag) {
-				if (arcn->sb.st_ctime <= sb.st_ctime)
-					continue;
-			} else if (arcn->sb.st_mtime <= sb.st_mtime)
-				continue;
-		}
-
-		if (vflag) {
-			(void)fputs(arcn->name, listf);
-			vfpart = 1;
-		}
-		++flcnt;
-
-		/*
-		 * try to create a hard link to the src file if requested
-		 * but make sure we are not trying to overwrite ourselves.
-		 */
-		if (lflag)
-			res = cross_lnk(arcn);
-		else
-			res = chk_same(arcn);
-		if (res <= 0) {
-			if (vflag && vfpart) {
-				(void)putc('\n', listf);
-				vfpart = 0;
-			}
-			continue;
-		}
-
-		/*
-		 * have to create a new file
-		 */
-		if ((arcn->type != PAX_REG) && (arcn->type != PAX_CTG)) {
-			/*
-			 * create a link or special file
-			 */
-			if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))
-				res = lnk_creat(arcn);
-			else
-				res = node_creat(arcn);
-			if (res < 0)
-				purg_lnk(arcn);
-			if (vflag && vfpart) {
-				(void)putc('\n', listf);
-				vfpart = 0;
-			}
-			continue;
-		}
-
-		/*
-		 * have to copy a regular file to the destination directory.
-		 * first open source file and then create the destination file
-		 */
-		if ((fdsrc = open(arcn->org_name, O_RDONLY, 0)) < 0) {
-			syswarn(1, errno, "Unable to open %s to read",
-			    arcn->org_name);
-			purg_lnk(arcn);
-			continue;
-		}
-		if ((fddest = file_creat(arcn)) < 0) {
-			rdfile_close(arcn, &fdsrc);
-			purg_lnk(arcn);
-			continue;
-		}
-
-		/*
-		 * copy source file data to the destination file
-		 */
-		cp_file(arcn, fdsrc, fddest);
-		file_close(arcn, fddest);
-		rdfile_close(arcn, &fdsrc);
-
-		if (vflag && vfpart) {
-			(void)putc('\n', listf);
-			vfpart = 0;
-		}
-	}
-
-	/*
-	 * restore directory modes and times as required; make sure all
-	 * patterns were selected block off signals to avoid chance for
-	 * multiple entry into the cleanup code.
-	 */
-	(void)sigprocmask(SIG_BLOCK, &s_mask, NULL);
-	ar_close();
-	proc_dir();
-	ftree_chk();
-}
-
-/*
- * next_head()
- *	try to find a valid header in the archive. Uses format specific
- *	routines to extract the header and id the trailer. Trailers may be
- *	located within a valid header or in an invalid header (the location
- *	is format specific. The inhead field from the option table tells us
- *	where to look for the trailer).
- *	We keep reading (and resyncing) until we get enough contiguous data
- *	to check for a header. If we cannot find one, we shift by a byte
- *	add a new byte from the archive to the end of the buffer and try again.
- *	If we get a read error, we throw out what we have (as we must have
- *	contiguous data) and start over again.
- *	ASSUMED: headers fit within a BLKMULT header.
- * Return:
- *	0 if we got a header, -1 if we are unable to ever find another one
- *	(we reached the end of input, or we reached the limit on retries. see
- *	the specs for rd_wrbuf() for more details)
- */
-
-static int
-next_head(ARCHD *arcn)
-{
-	int ret;
-	char *hdend;
-	int res;
-	int shftsz;
-	int hsz;
-	int in_resync = 0; 	/* set when we are in resync mode */
-	int cnt = 0;			/* counter for trailer function */
-	int first = 1;			/* on 1st read, EOF isn't premature. */
-
-	/*
-	 * set up initial conditions, we want a whole frmt->hsz block as we
-	 * have no data yet.
-	 */
-	res = hsz = frmt->hsz;
-	hdend = hdbuf;
-	shftsz = hsz - 1;
-	for(;;) {
-		/*
-		 * keep looping until we get a contiguous FULL buffer
-		 * (frmt->hsz is the proper size)
-		 */
-		for (;;) {
-			if ((ret = rd_wrbuf(hdend, res)) == res)
-				break;
-
-			/*
-			 * If we read 0 bytes (EOF) from an archive when we
-			 * expect to find a header, we have stepped upon
-			 * an archive without the customary block of zeroes
-			 * end marker.  It's just stupid to error out on
-			 * them, so exit gracefully.
-			 */
-			if (first && ret == 0)
-				return(-1);
-			first = 0;
-
-			/*
-			 * some kind of archive read problem, try to resync the
-			 * storage device, better give the user the bad news.
-			 */
-			if ((ret == 0) || (rd_sync() < 0)) {
-				paxwarn(1,"Premature end of file on archive read");
-				return(-1);
-			}
-			if (!in_resync) {
-				if (act == APPND) {
-					paxwarn(1,
-					  "Archive I/O error, cannot continue");
-					return(-1);
-				}
-				paxwarn(1,"Archive I/O error. Trying to recover.");
-				++in_resync;
-			}
-
-			/*
-			 * oh well, throw it all out and start over
-			 */
-			res = hsz;
-			hdend = hdbuf;
-		}
-
-		/*
-		 * ok we have a contiguous buffer of the right size. Call the
-		 * format read routine. If this was not a valid header and this
-		 * format stores trailers outside of the header, call the
-		 * format specific trailer routine to check for a trailer. We
-		 * have to watch out that we do not mis-identify file data or
-		 * block padding as a header or trailer. Format specific
-		 * trailer functions must NOT check for the trailer while we
-		 * are running in resync mode. Some trailer functions may tell
-		 * us that this block cannot contain a valid header either, so
-		 * we then throw out the entire block and start over.
-		 */
-		if ((*frmt->rd)(arcn, hdbuf) == 0)
-			break;
-
-		if (!frmt->inhead) {
-			/*
-			 * this format has trailers outside of valid headers
-			 */
-			if ((ret = (*frmt->trail_tar)(hdbuf,in_resync,&cnt)) == 0){
-				/*
-				 * valid trailer found, drain input as required
-				 */
-				ar_drain();
-				return(-1);
-			}
-
-			if (ret == 1) {
-				/*
-				 * we are in resync and we were told to throw
-				 * the whole block out because none of the
-				 * bytes in this block can be used to form a
-				 * valid header
-				 */
-				res = hsz;
-				hdend = hdbuf;
-				continue;
-			}
-		}
-
-		/*
-		 * Brute force section.
-		 * not a valid header. We may be able to find a header yet. So
-		 * we shift over by one byte, and set up to read one byte at a
-		 * time from the archive and place it at the end of the buffer.
-		 * We will keep moving byte at a time until we find a header or
-		 * get a read error and have to start over.
-		 */
-		if (!in_resync) {
-			if (act == APPND) {
-				paxwarn(1,"Unable to append, archive header flaw");
-				return(-1);
-			}
-			paxwarn(1,"Invalid header, starting valid header search.");
-			++in_resync;
-		}
-		memmove(hdbuf, hdbuf+1, shftsz);
-		res = 1;
-		hdend = hdbuf + shftsz;
-	}
-
-	/*
-	 * ok got a valid header, check for trailer if format encodes it in the
-	 * the header.
-	 */
-	if (frmt->inhead && ((*frmt->trail_cpio)(arcn) == 0)) {
-		/*
-		 * valid trailer found, drain input as required
-		 */
-		ar_drain();
-		return(-1);
-	}
-
-	++flcnt;
-	return(0);
-}
-
-/*
- * get_arc()
- *	Figure out what format an archive is. Handles archive with flaws by
- *	brute force searches for a legal header in any supported format. The
- *	format id routines have to be careful to NOT mis-identify a format.
- *	ASSUMED: headers fit within a BLKMULT header.
- * Return:
- *	0 if archive found -1 otherwise
- */
-
-static int
-get_arc(void)
-{
-	int i;
-	int hdsz = 0;
-	int res;
-	int minhd = BLKMULT;
-	char *hdend;
-	int notice = 0;
-
-	/*
-	 * find the smallest header size in all archive formats and then set up
-	 * to read the archive.
-	 */
-	for (i = 0; ford[i] >= 0; ++i) {
-		if (fsub[ford[i]].hsz < minhd)
-			minhd = fsub[ford[i]].hsz;
-	}
-	if (rd_start() < 0)
-		return(-1);
-	res = BLKMULT;
-	hdsz = 0;
-	hdend = hdbuf;
-	for(;;) {
-		for (;;) {
-			/*
-			 * fill the buffer with at least the smallest header
-			 */
-			i = rd_wrbuf(hdend, res);
-			if (i > 0)
-				hdsz += i;
-			if (hdsz >= minhd)
-				break;
-
-			/*
-			 * if we cannot recover from a read error quit
-			 */
-			if ((i == 0) || (rd_sync() < 0))
-				goto out;
-
-			/*
-			 * when we get an error none of the data we already
-			 * have can be used to create a legal header (we just
-			 * got an error in the middle), so we throw it all out
-			 * and refill the buffer with fresh data.
-			 */
-			res = BLKMULT;
-			hdsz = 0;
-			hdend = hdbuf;
-			if (!notice) {
-				if (act == APPND)
-					return(-1);
-				paxwarn(1,"Cannot identify format. Searching...");
-				++notice;
-			}
-		}
-
-		/*
-		 * we have at least the size of the smallest header in any
-		 * archive format. Look to see if we have a match. The array
-		 * ford[] is used to specify the header id order to reduce the
-		 * chance of incorrectly id'ing a valid header (some formats
-		 * may be subsets of each other and the order would then be
-		 * important).
-		 */
-		for (i = 0; ford[i] >= 0; ++i) {
-			if ((*fsub[ford[i]].id)(hdbuf, hdsz) < 0)
-				continue;
-			frmt = &(fsub[ford[i]]);
-			/*
-			 * yuck, to avoid slow special case code in the extract
-			 * routines, just push this header back as if it was
-			 * not seen. We have left extra space at start of the
-			 * buffer for this purpose. This is a bit ugly, but
-			 * adding all the special case code is far worse.
-			 */
-			pback(hdbuf, hdsz);
-			return(0);
-		}
-
-		/*
-		 * We have a flawed archive, no match. we start searching, but
-		 * we never allow additions to flawed archives
-		 */
-		if (!notice) {
-			if (act == APPND)
-				return(-1);
-			paxwarn(1, "Cannot identify format. Searching...");
-			++notice;
-		}
-
-		/*
-		 * brute force search for a header that we can id.
-		 * we shift through byte at a time. this is slow, but we cannot
-		 * determine the nature of the flaw in the archive in a
-		 * portable manner
-		 */
-		if (--hdsz > 0) {
-			memmove(hdbuf, hdbuf+1, hdsz);
-			res = BLKMULT - hdsz;
-			hdend = hdbuf + hdsz;
-		} else {
-			res = BLKMULT;
-			hdend = hdbuf;
-			hdsz = 0;
-		}
-	}
-
-    out:
-	/*
-	 * we cannot find a header, bow, apologize and quit
-	 */
-	paxwarn(1, "Sorry, unable to determine archive format.");
-	return(-1);
-}
Index: trunk/minix/commands/pax/buf_subs.c
===================================================================
--- trunk/minix/commands/pax/buf_subs.c	(revision 9)
+++ 	(revision )
@@ -1,993 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)buf_subs.c	8.2 (Berkeley) 4/18/94";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "pax.h"
-#include "extern.h"
-
-/*
- * routines which implement archive and file buffering
- */
-
-#define MINFBSZ		512		/* default block size for hole detect */
-#define MAXFLT		10		/* default media read error limit */
-
-/*
- * Need to change bufmem to dynamic allocation when the upper
- * limit on blocking size is removed (though that will violate pax spec)
- * MAXBLK define and tests will also need to be updated.
- */
-static char bufmem[MAXBLK+BLKMULT];	/* i/o buffer + pushback id space */
-static char *buf;			/* normal start of i/o buffer */
-static char *bufend;			/* end or last char in i/o buffer */
-static char *bufpt;			/* read/write point in i/o buffer */
-int blksz = MAXBLK;			/* block input/output size in bytes */
-int wrblksz;				/* user spec output size in bytes */
-int maxflt = MAXFLT;			/* MAX consecutive media errors */
-int rdblksz;				/* first read blksize (tapes only) */
-off_t wrlimit;				/* # of bytes written per archive vol */
-off_t wrcnt;				/* # of bytes written on current vol */
-off_t rdcnt;				/* # of bytes read on current vol */
-
-/*
- * wr_start()
- *	set up the buffering system to operate in a write mode
- * Return:
- *	0 if ok, -1 if the user specified write block size violates pax spec
- */
-
-int
-wr_start(void)
-{
-	buf = &(bufmem[BLKMULT]);
-	/*
-	 * Check to make sure the write block size meets pax specs. If the user
-	 * does not specify a blocksize, we use the format default blocksize.
-	 * We must be picky on writes, so we do not allow the user to create an
-	 * archive that might be hard to read elsewhere. If all ok, we then
-	 * open the first archive volume
-	 */
-	if (!wrblksz)
-		wrblksz = frmt->bsz;
-	if (wrblksz > MAXBLK) {
-		paxwarn(1, "Write block size of %d too large, maximum is: %d",
-			wrblksz, MAXBLK);
-		return(-1);
-	}
-	if (wrblksz % BLKMULT) {
-		paxwarn(1, "Write block size of %d is not a %d byte multiple",
-		    wrblksz, BLKMULT);
-		return(-1);
-	}
-	if (wrblksz > MAXBLK_POSIX) {
-		paxwarn(0, "Write block size of %d larger than POSIX max %d, archive may not be portable",
-			wrblksz, MAXBLK_POSIX);
-		return(-1);
-	}
-
-	/*
-	 * we only allow wrblksz to be used with all archive operations
-	 */
-	blksz = rdblksz = wrblksz;
-	if ((ar_open(arcname) < 0) && (ar_next() < 0))
-		return(-1);
-	wrcnt = 0;
-	bufend = buf + wrblksz;
-	bufpt = buf;
-	return(0);
-}
-
-/*
- * rd_start()
- *	set up buffering system to read an archive
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-rd_start(void)
-{
-	/*
-	 * leave space for the header pushback (see get_arc()). If we are
-	 * going to append and user specified a write block size, check it
-	 * right away
-	 */
-	buf = &(bufmem[BLKMULT]);
-	if ((act == APPND) && wrblksz) {
-		if (wrblksz > MAXBLK) {
-			paxwarn(1,"Write block size %d too large, maximum is: %d",
-				wrblksz, MAXBLK);
-			return(-1);
-		}
-		if (wrblksz % BLKMULT) {
-			paxwarn(1, "Write block size %d is not a %d byte multiple",
-		    	wrblksz, BLKMULT);
-			return(-1);
-		}
-	}
-
-	/*
-	 * open the archive
-	 */
-	if ((ar_open(arcname) < 0) && (ar_next() < 0))
-		return(-1);
-	bufend = buf + rdblksz;
-	bufpt = bufend;
-	rdcnt = 0;
-	return(0);
-}
-
-/*
- * cp_start()
- *	set up buffer system for copying within the file system
- */
-
-void
-cp_start(void)
-{
-	buf = &(bufmem[BLKMULT]);
-	rdblksz = blksz = MAXBLK;
-}
-
-/*
- * appnd_start()
- *	Set up the buffering system to append new members to an archive that
- *	was just read. The last block(s) of an archive may contain a format
- *	specific trailer. To append a new member, this trailer has to be
- *	removed from the archive. The first byte of the trailer is replaced by
- *	the start of the header of the first file added to the archive. The
- *	format specific end read function tells us how many bytes to move
- *	backwards in the archive to be positioned BEFORE the trailer. Two
- *	different postions have to be adjusted, the O.S. file offset (e.g. the
- *	position of the tape head) and the write point within the data we have
- *	stored in the read (soon to become write) buffer. We may have to move
- *	back several records (the number depends on the size of the archive
- *	record and the size of the format trailer) to read up the record where
- *	the first byte of the trailer is recorded. Trailers may span (and
- *	overlap) record boundries.
- *	We first calculate which record has the first byte of the trailer. We
- *	move the OS file offset back to the start of this record and read it
- *	up. We set the buffer write pointer to be at this byte (the byte where
- *	the trailer starts). We then move the OS file pointer back to the
- *	start of this record so a flush of this buffer will replace the record
- *	in the archive.
- *	A major problem is rewriting this last record. For archives stored
- *	on disk files, this is trival. However, many devices are really picky
- *	about the conditions under which they will allow a write to occur.
- *	Often devices restrict the conditions where writes can be made writes,
- *	so it may not be feasable to append archives stored on all types of
- *	devices.
- * Return:
- *	0 for success, -1 for failure
- */
-
-int
-appnd_start(off_t skcnt)
-{
-	int res;
-	off_t cnt;
-
-	if (exit_val != 0) {
-		paxwarn(0, "Cannot append to an archive that may have flaws.");
-		return(-1);
-	}
-	/*
-	 * if the user did not specify a write blocksize, inherit the size used
-	 * in the last archive volume read. (If a is set we still use rdblksz
-	 * until next volume, cannot shift sizes within a single volume).
-	 */
-	if (!wrblksz)
-		wrblksz = blksz = rdblksz;
-	else
-		blksz = rdblksz;
-
-	/*
-	 * make sure that this volume allows appends
-	 */
-	if (ar_app_ok() < 0)
-		return(-1);
-
-	/*
-	 * Calculate bytes to move back and move in front of record where we
-	 * need to start writing from. Remember we have to add in any padding
-	 * that might be in the buffer after the trailer in the last block. We
-	 * travel skcnt + padding ROUNDED UP to blksize.
-	 */
-	skcnt += bufend - bufpt;
-	if ((cnt = (skcnt/blksz) * blksz) < skcnt)
-		cnt += blksz;
-	if (ar_rev((off_t)cnt) < 0)
-		goto out;
-
-	/*
-	 * We may have gone too far if there is valid data in the block we are
-	 * now in front of, read up the block and position the pointer after
-	 * the valid data.
-	 */
-	if ((cnt -= skcnt) > 0) {
-		/*
-		 * watch out for stupid tape drives. ar_rev() will set rdblksz
-		 * to be real physical blocksize so we must loop until we get
-		 * the old rdblksz (now in blksz). If ar_rev() fouls up the
-		 * determination of the physical block size, we will fail.
-		 */
-		bufpt = buf;
-		bufend = buf + blksz;
-		while (bufpt < bufend) {
-			if ((res = ar_read(bufpt, rdblksz)) <= 0)
-				goto out;
-			bufpt += res;
-		}
-		if (ar_rev((off_t)(bufpt - buf)) < 0)
-			goto out;
-		bufpt = buf + cnt;
-		bufend = buf + blksz;
-	} else {
-		/*
-		 * buffer is empty
-		 */
-		bufend = buf + blksz;
-		bufpt = buf;
-	}
-	rdblksz = blksz;
-	rdcnt -= skcnt;
-	wrcnt = 0;
-
-	/*
-	 * At this point we are ready to write. If the device requires special
-	 * handling to write at a point were previously recorded data resides,
-	 * that is handled in ar_set_wr(). From now on we operate under normal
-	 * ARCHIVE mode (write) conditions
-	 */
-	if (ar_set_wr() < 0)
-		return(-1);
-	act = ARCHIVE;
-	return(0);
-
-    out:
-	paxwarn(1, "Unable to rewrite archive trailer, cannot append.");
-	return(-1);
-}
-	
-/*
- * rd_sync()
- *	A read error occurred on this archive volume. Resync the buffer and
- *	try to reset the device (if possible) so we can continue to read. Keep
- *	trying to do this until we get a valid read, or we reach the limit on
- *	consecutive read faults (at which point we give up). The user can
- *	adjust the read error limit through a command line option.
- * Returns:
- *	0 on success, and -1 on failure
- */
-
-int
-rd_sync(void)
-{
-	int errcnt = 0;
-	int res;
-
-	/*
-	 * if the user says bail out on first fault, we are out of here...
-	 */
-	if (maxflt == 0)
-		return(-1);
-	if (act == APPND) {
-		paxwarn(1, "Unable to append when there are archive read errors.");
-		return(-1);
-	}
-
-	/*
-	 * poke at device and try to get past media error
-	 */
-	if (ar_rdsync() < 0) {
-		if (ar_next() < 0)
-			return(-1);
-		else
-			rdcnt = 0;
-	}
-
-	for (;;) {
-		if ((res = ar_read(buf, blksz)) > 0) {
-			/*
-			 * All right! got some data, fill that buffer
-			 */
-			bufpt = buf;
-			bufend = buf + res;
-			rdcnt += res;
-			return(0);
-		}
-
-		/*
-		 * Oh well, yet another failed read...
-		 * if error limit reached, ditch. o.w. poke device to move past
-		 * bad media and try again. if media is badly damaged, we ask
-		 * the poor (and upset user at this point) for the next archive
-		 * volume. remember the goal on reads is to get the most we
-		 * can extract out of the archive.
-		 */
-		if ((maxflt > 0) && (++errcnt > maxflt))
-			paxwarn(0,"Archive read error limit (%d) reached",maxflt);
-		else if (ar_rdsync() == 0)
-			continue;
-		if (ar_next() < 0)
-			break;
-		rdcnt = 0;
-		errcnt = 0;
-	}
-	return(-1);
-}
-
-/*
- * pback()
- *	push the data used during the archive id phase back into the I/O
- *	buffer. This is required as we cannot be sure that the header does NOT
- *	overlap a block boundry (as in the case we are trying to recover a
- *	flawed archived). This was not designed to be used for any other
- *	purpose. (What software engineering, HA!)
- *	WARNING: do not even THINK of pback greater than BLKMULT, unless the
- *	pback space is increased.
- */
-
-void
-pback(char *pt, int cnt)
-{
-	bufpt -= cnt;
-	memcpy(bufpt, pt, cnt);
-	return;
-}
-
-/*
- * rd_skip()
- *	skip foward in the archive during an archive read. Used to get quickly
- *	past file data and padding for files the user did NOT select.
- * Return:
- *	0 if ok, -1 failure, and 1 when EOF on the archive volume was detected.
- */
-
-int
-rd_skip(off_t skcnt)
-{
-	off_t res;
-	off_t cnt;
-	off_t skipped = 0;
-
-	/*
-	 * consume what data we have in the buffer. If we have to move foward
-	 * whole records, we call the low level skip function to see if we can
-	 * move within the archive without doing the expensive reads on data we
-	 * do not want.
-	 */
-	if (skcnt == 0)
-		return(0);
-	res = MIN((bufend - bufpt), skcnt);
-	bufpt += res;
-	skcnt -= res;
-
-	/*
-	 * if skcnt is now 0, then no additional i/o is needed
-	 */
-	if (skcnt == 0)
-		return(0);
-
-	/*
-	 * We have to read more, calculate complete and partial record reads
-	 * based on rdblksz. we skip over "cnt" complete records
-	 */
-	res = skcnt%rdblksz;
-	cnt = (skcnt/rdblksz) * rdblksz;
-
-	/*
-	 * if the skip fails, we will have to resync. ar_fow will tell us
-	 * how much it can skip over. We will have to read the rest.
-	 */
-	if (ar_fow(cnt, &skipped) < 0)
-		return(-1);
-	res += cnt - skipped;
-	rdcnt += skipped;
-
-	/*
-	 * what is left we have to read (which may be the whole thing if
-	 * ar_fow() told us the device can only read to skip records);
-	 */
-	while (res > 0L) {
-		cnt = bufend - bufpt;
-		/*
-		 * if the read fails, we will have to resync
-		 */
-		if ((cnt <= 0) && ((cnt = buf_fill()) < 0))
-			return(-1);
-		if (cnt == 0)
-			return(1);
-		cnt = MIN(cnt, res);
-		bufpt += cnt;
-		res -= cnt;
-	}
-	return(0);
-}
-
-/*
- * wr_fin()
- *	flush out any data (and pad if required) the last block. We always pad
- *	with zero (even though we do not have to). Padding with 0 makes it a
- *	lot easier to recover if the archive is damaged. zero paddding SHOULD
- *	BE a requirement....
- */
-
-void
-wr_fin(void)
-{
-	if (bufpt > buf) {
-		memset(bufpt, 0, bufend - bufpt);
-		bufpt = bufend;
-		(void)buf_flush(blksz);
-	}
-}
-
-/*
- * wr_rdbuf()
- *	fill the write buffer from data passed to it in a buffer (usually used
- *	by format specific write routines to pass a file header). On failure we
- *	punt. We do not allow the user to continue to write flawed archives.
- *	We assume these headers are not very large (the memory copy we use is
- *	a bit expensive).
- * Return:
- *	0 if buffer was filled ok, -1 o.w. (buffer flush failure)
- */
-
-int
-wr_rdbuf(char *out, int outcnt)
-{
-	int cnt;
-
-	/*
-	 * while there is data to copy copy into the write buffer. when the
-	 * write buffer fills, flush it to the archive and continue
-	 */
-	while (outcnt > 0) {
-		cnt = bufend - bufpt;
-		if ((cnt <= 0) && ((cnt = buf_flush(blksz)) < 0))
-			return(-1);
-		/*
-		 * only move what we have space for
-		 */
-		cnt = MIN(cnt, outcnt);
-		memcpy(bufpt, out, cnt);
-		bufpt += cnt;
-		out += cnt;
-		outcnt -= cnt;
-	}
-	return(0);
-}
-
-/*
- * rd_wrbuf()
- *	copy from the read buffer into a supplied buffer a specified number of
- *	bytes. If the read buffer is empty fill it and continue to copy.
- *	usually used to obtain a file header for processing by a format
- *	specific read routine.
- * Return
- *	number of bytes copied to the buffer, 0 indicates EOF on archive volume,
- *	-1 is a read error
- */
-
-int
-rd_wrbuf(char *in, int cpcnt)
-{
-	int res;
-	int cnt;
-	int incnt = cpcnt;
-
-	/*
-	 * loop until we fill the buffer with the requested number of bytes
-	 */
-	while (incnt > 0) {
-		cnt = bufend - bufpt;
-		if ((cnt <= 0) && ((cnt = buf_fill()) <= 0)) {
-			/*
-			 * read error, return what we got (or the error if
-			 * no data was copied). The caller must know that an
-			 * error occured and has the best knowledge what to
-			 * do with it
-			 */
-			if ((res = cpcnt - incnt) > 0)
-				return(res);
-			return(cnt);
-		}
-
-		/*
-		 * calculate how much data to copy based on whats left and
-		 * state of buffer
-		 */
-		cnt = MIN(cnt, incnt);
-		memcpy(in, bufpt, cnt);
-		bufpt += cnt;
-		incnt -= cnt;
-		in += cnt;
-	}
-	return(cpcnt);
-}
-
-/*
- * wr_skip()
- *	skip forward during a write. In other words add padding to the file.
- *	we add zero filled padding as it makes flawed archives much easier to
- *	recover from. the caller tells us how many bytes of padding to add
- *	This routine was not designed to add HUGE amount of padding, just small
- *	amounts (a few 512 byte blocks at most)
- * Return:
- *	0 if ok, -1 if there was a buf_flush failure
- */
-
-int
-wr_skip(off_t skcnt)
-{
-	int cnt;
-
-	/*
-	 * loop while there is more padding to add
-	 */
-	while (skcnt > 0L) {
-		cnt = bufend - bufpt;
-		if ((cnt <= 0) && ((cnt = buf_flush(blksz)) < 0))
-			return(-1);
-		cnt = MIN(cnt, skcnt);
-		memset(bufpt, 0, cnt);
-		bufpt += cnt;
-		skcnt -= cnt;
-	}
-	return(0);
-}
-
-/*
- * wr_rdfile()
- *	fill write buffer with the contents of a file. We are passed an	open
- *	file descriptor to the file and the archive structure that describes the
- *	file we are storing. The variable "left" is modified to contain the
- *	number of bytes of the file we were NOT able to write to the archive.
- *	it is important that we always write EXACTLY the number of bytes that
- *	the format specific write routine told us to. The file can also get
- *	bigger, so reading to the end of file would create an improper archive,
- *	we just detect this case and warn the user. We never create a bad
- *	archive if we can avoid it. Of course trying to archive files that are
- *	active is asking for trouble. It we fail, we pass back how much we
- *	could NOT copy and let the caller deal with it.
- * Return:
- *	0 ok, -1 if archive write failure. a short read of the file returns a
- *	0, but "left" is set to be greater than zero.
- */
-
-int
-wr_rdfile(ARCHD *arcn, int ifd, off_t *left)
-{
-	int cnt;
-	int res = 0;
-	off_t size = arcn->sb.st_size;
-	struct stat sb;
-
-	/*
-	 * while there are more bytes to write
-	 */
-	while (size > 0L) {
-		cnt = bufend - bufpt;
-		if ((cnt <= 0) && ((cnt = buf_flush(blksz)) < 0)) {
-			*left = size;
-			return(-1);
-		}
-		cnt = MIN(cnt, size);
-		if ((res = read(ifd, bufpt, cnt)) <= 0)
-			break;
-		size -= res;
-		bufpt += res;
-	}
-
-	/*
-	 * better check the file did not change during this operation
-	 * or the file read failed.
-	 */
-	if (res < 0)
-		syswarn(1, errno, "Read fault on %s", arcn->org_name);
-	else if (size != 0L)
-		paxwarn(1, "File changed size during read %s", arcn->org_name);
-	else if (fstat(ifd, &sb) < 0)
-		syswarn(1, errno, "Failed stat on %s", arcn->org_name);
-	else if (arcn->sb.st_mtime != sb.st_mtime)
-		paxwarn(1, "File %s was modified during copy to archive",
-			arcn->org_name);
-	*left = size;
-	return(0);
-}
-
-/*
- * rd_wrfile()
- *	extract the contents of a file from the archive. If we are unable to
- *	extract the entire file (due to failure to write the file) we return
- *	the numbers of bytes we did NOT process. This way the caller knows how
- *	many bytes to skip past to find the next archive header. If the failure
- *	was due to an archive read, we will catch that when we try to skip. If
- *	the format supplies a file data crc value, we calculate the actual crc
- *	so that it can be compared to the value stored in the header
- * NOTE:
- *	We call a special function to write the file. This function attempts to
- *	restore file holes (blocks of zeros) into the file. When files are
- *	sparse this saves space, and is a LOT faster. For non sparse files
- *	the performance hit is small. As of this writing, no archive supports
- *	information on where the file holes are.
- * Return:
- *	0 ok, -1 if archive read failure. if we cannot write the entire file,
- *	we return a 0 but "left" is set to be the amount unwritten
- */
-
-int
-rd_wrfile(ARCHD *arcn, int ofd, off_t *left)
-{
-	int cnt = 0;
-	off_t size = arcn->sb.st_size;
-	int res = 0;
-	char *fnm = arcn->name;
-	int isem = 1;
-	int rem;
-	int sz = MINFBSZ;
- 	struct stat sb;
-	u_long crc = 0L;
-
-	/*
-	 * pass the blocksize of the file being written to the write routine,
-	 * if the size is zero, use the default MINFBSZ
-	 */
-	if (fstat(ofd, &sb) == 0) {
-#if 0
-	/* not under minix */
-		if (sb.st_blksize > 0)
-			sz = (int)sb.st_blksize;
-#endif
-	} else
-		syswarn(0,errno,"Unable to obtain block size for file %s",fnm);
-	rem = sz;
-	*left = 0L;
-
-	/*
-	 * Copy the archive to the file the number of bytes specified. We have
-	 * to assume that we want to recover file holes as none of the archive
-	 * formats can record the location of file holes.
-	 */
-	while (size > 0L) {
-		cnt = bufend - bufpt;
-		/*
-		 * if we get a read error, we do not want to skip, as we may
-		 * miss a header, so we do not set left, but if we get a write
-		 * error, we do want to skip over the unprocessed data.
-		 */
-		if ((cnt <= 0) && ((cnt = buf_fill()) <= 0))
-			break;
-		cnt = MIN(cnt, size);
-		if ((res = file_write(ofd,bufpt,cnt,&rem,&isem,sz,fnm)) <= 0) {
-			*left = size;
-			break;
-		}
-
-		if (docrc) {
-			/*
-			 * update the actual crc value
-			 */
-			cnt = res;
-			while (--cnt >= 0)
-				crc += *bufpt++ & 0xff;
-		} else
-			bufpt += res;
-		size -= res;
-	}
-
-	/*
-	 * if the last block has a file hole (all zero), we must make sure this
-	 * gets updated in the file. We force the last block of zeros to be
-	 * written. just closing with the file offset moved forward may not put
-	 * a hole at the end of the file.
-	 */
-	if (isem && (arcn->sb.st_size > 0L))
-		file_flush(ofd, fnm, isem);
-
-	/*
-	 * if we failed from archive read, we do not want to skip
-	 */
-	if ((size > 0L) && (*left == 0L))
-		return(-1);
-
-	/*
-	 * some formats record a crc on file data. If so, then we compare the
-	 * calculated crc to the crc stored in the archive
-	 */
-	if (docrc && (size == 0L) && (arcn->crc != crc))
-		paxwarn(1,"Actual crc does not match expected crc %s",arcn->name);
-	return(0);
-}
-
-/*
- * cp_file()
- *	copy the contents of one file to another. used during -rw phase of pax
- *	just as in rd_wrfile() we use a special write function to write the
- *	destination file so we can properly copy files with holes.
- */
-
-void
-cp_file(ARCHD *arcn, int fd1, int fd2)
-{
-	int cnt;
-	off_t cpcnt = 0L;
-	int res = 0;
-	char *fnm = arcn->name;
-	int no_hole = 0;
-	int isem = 1;
-	int rem;
-	int sz = MINFBSZ;
-	struct stat sb;
-
-	/*
-	 * check for holes in the source file. If none, we will use regular
-	 * write instead of file write.
-	 */
-#if 0
-	/* not under minix */
-	 if (((off_t)(arcn->sb.st_blocks * BLKMULT)) >= arcn->sb.st_size)
-#endif
-		++no_hole;
-
-	/*
-	 * pass the blocksize of the file being written to the write routine,
-	 * if the size is zero, use the default MINFBSZ
-	 */
-	if (fstat(fd2, &sb) == 0) {
-#if 0
-	/* not under minix */
-		if (sb.st_blksize > 0)
-			sz = sb.st_blksize;
-#endif
-	} else
-		syswarn(0,errno,"Unable to obtain block size for file %s",fnm);
-	rem = sz;
-
-	/*
-	 * read the source file and copy to destination file until EOF
-	 */
-	for(;;) {
-		if ((cnt = read(fd1, buf, blksz)) <= 0)
-			break;
-		if (no_hole)
-			res = write(fd2, buf, cnt);
-		else
-			res = file_write(fd2, buf, cnt, &rem, &isem, sz, fnm);
-		if (res != cnt)
-			break;
-		cpcnt += cnt;
-	}
-
-	/*
-	 * check to make sure the copy is valid.
-	 */
-	if (res < 0)
-		syswarn(1, errno, "Failed write during copy of %s to %s",
-			arcn->org_name, arcn->name);
-	else if (cpcnt != arcn->sb.st_size)
-		paxwarn(1, "File %s changed size during copy to %s",
-			arcn->org_name, arcn->name);
-	else if (fstat(fd1, &sb) < 0)
-		syswarn(1, errno, "Failed stat of %s", arcn->org_name);
-	else if (arcn->sb.st_mtime != sb.st_mtime)
-		paxwarn(1, "File %s was modified during copy to %s",
-			arcn->org_name, arcn->name);
-
-	/*
-	 * if the last block has a file hole (all zero), we must make sure this
-	 * gets updated in the file. We force the last block of zeros to be
-	 * written. just closing with the file offset moved forward may not put
-	 * a hole at the end of the file.
-	 */
-	if (!no_hole && isem && (arcn->sb.st_size > 0L))
-		file_flush(fd2, fnm, isem);
-	return;
-}
-
-/*
- * buf_fill()
- *	fill the read buffer with the next record (or what we can get) from
- *	the archive volume.
- * Return:
- *	Number of bytes of data in the read buffer, -1 for read error, and
- *	0 when finished (user specified termination in ar_next()).
- */
-
-int
-buf_fill(void)
-{
-	int cnt;
-	static int fini = 0;
-
-	if (fini)
-		return(0);
-
-	for(;;) {
-		/*
-		 * try to fill the buffer. on error the next archive volume is
-		 * opened and we try again.
-		 */
-		if ((cnt = ar_read(buf, blksz)) > 0) {
-			bufpt = buf;
-			bufend = buf + cnt;
-			rdcnt += cnt;
-			return(cnt);
-		}
-
-		/*
-		 * errors require resync, EOF goes to next archive
-		 */
-		if (cnt < 0)
-			break;
-		if (ar_next() < 0) {
-			fini = 1;
-			return(0);
-		}
-		rdcnt = 0;
-	}
-	exit_val = 1;
-	return(-1);
-}
-
-/*
- * buf_flush()
- *	force the write buffer to the archive. We are passed the number of
- *	bytes in the buffer at the point of the flush. When we change archives
- *	the record size might change. (either larger or smaller).
- * Return:
- *	0 if all is ok, -1 when a write error occurs.
- */
-
-int
-buf_flush(int bufcnt)
-{
-	int cnt;
-	int push = 0;
-	int totcnt = 0;
-
-	/*
-	 * if we have reached the user specified byte count for each archive
-	 * volume, prompt for the next volume. (The non-standrad -R flag).
-	 * NOTE: If the wrlimit is smaller than wrcnt, we will always write
-	 * at least one record. We always round limit UP to next blocksize.
-	 */
-	if ((wrlimit > 0) && (wrcnt > wrlimit)) {
-		paxwarn(0, "User specified archive volume byte limit reached.");
-		if (ar_next() < 0) {
-			wrcnt = 0;
-			exit_val = 1;
-			return(-1);
-		}
-		wrcnt = 0;
-
-		/*
-		 * The new archive volume might have changed the size of the
-		 * write blocksize. if so we figure out if we need to write
-		 * (one or more times), or if there is now free space left in
-		 * the buffer (it is no longer full). bufcnt has the number of
-		 * bytes in the buffer, (the blocksize, at the point we were
-		 * CALLED). Push has the amount of "extra" data in the buffer
-		 * if the block size has shrunk from a volume change.
-		 */
-		bufend = buf + blksz;
-		if (blksz > bufcnt)
-			return(0);
-		if (blksz < bufcnt)
-			push = bufcnt - blksz;
-	}
-
-	/*
-	 * We have enough data to write at least one archive block
-	 */
-	for (;;) {
-		/*
-		 * write a block and check if it all went out ok
-		 */
-		cnt = ar_write(buf, blksz);
-		if (cnt == blksz) {
-			/*
-			 * the write went ok
-			 */
-			wrcnt += cnt;
-			totcnt += cnt;
-			if (push > 0) {
-				/* we have extra data to push to the front.
-				 * check for more than 1 block of push, and if
-				 * so we loop back to write again
-				 */
-				memcpy(buf, bufend, push);
-				bufpt = buf + push;
-				if (push >= blksz) {
-					push -= blksz;
-					continue;
-				}
-			} else
-				bufpt = buf;
-			return(totcnt);
-		} else if (cnt > 0) {
-			/*
-			 * Oh drat we got a partial write!
-			 * if format doesnt care about alignment let it go,
-			 * we warned the user in ar_write().... but this means
-			 * the last record on this volume violates pax spec....
-			 */
-			totcnt += cnt;
-			wrcnt += cnt;
-			bufpt = buf + cnt;
-			cnt = bufcnt - cnt;
-			memcpy(buf, bufpt, cnt);
-			bufpt = buf + cnt;
-			if (!frmt->blkalgn || ((cnt % frmt->blkalgn) == 0))
-				return(totcnt);
-			break;
-		}
-
-		/*
-		 * All done, go to next archive
-		 */
-		wrcnt = 0;
-		if (ar_next() < 0)
-			break;
-
-		/*
-		 * The new archive volume might also have changed the block
-		 * size. if so, figure out if we have too much or too little
-		 * data for using the new block size
-		 */
-		bufend = buf + blksz;
-		if (blksz > bufcnt)
-			return(0);
-		if (blksz < bufcnt)
-			push = bufcnt - blksz;
-	}
-
-	/*
-	 * write failed, stop pax. we must not create a bad archive!
-	 */
-	exit_val = 1;
-	return(-1);
-}
Index: trunk/minix/commands/pax/build
===================================================================
--- trunk/minix/commands/pax/build	(revision 9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-make
Index: trunk/minix/commands/pax/cache.c
===================================================================
--- trunk/minix/commands/pax/cache.c	(revision 9)
+++ 	(revision )
@@ -1,430 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)cache.c	8.1 (Berkeley) 5/31/93";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <stdio.h>
-#include <pwd.h>
-#include <grp.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "pax.h"
-#include "cache.h"
-#include "extern.h"
-
-/*
- * routines that control user, group, uid and gid caches (for the archive
- * member print routine).
- * IMPORTANT:
- * these routines cache BOTH hits and misses, a major performance improvement
- */
-
-static	int pwopn = 0;		/* is password file open */
-static	int gropn = 0;		/* is group file open */
-static UIDC **uidtb = NULL;	/* uid to name cache */
-static GIDC **gidtb = NULL;	/* gid to name cache */
-static UIDC **usrtb = NULL;	/* user name to uid cache */
-static GIDC **grptb = NULL;	/* group name to gid cache */
-
-/*
- * uidtb_start
- *	creates an an empty uidtb
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-uidtb_start(void)
-{
-	static int fail = 0;
-
-	if (uidtb != NULL)
-		return(0);
-	if (fail)
-		return(-1);
-	if ((uidtb = (UIDC **)calloc(UID_SZ, sizeof(UIDC *))) == NULL) {
-		++fail;
-		paxwarn(1, "Unable to allocate memory for user id cache table");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * gidtb_start
- *	creates an an empty gidtb
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-gidtb_start(void)
-{
-	static int fail = 0;
-
-	if (gidtb != NULL)
-		return(0);
-	if (fail)
-		return(-1);
-	if ((gidtb = (GIDC **)calloc(GID_SZ, sizeof(GIDC *))) == NULL) {
-		++fail;
-		paxwarn(1, "Unable to allocate memory for group id cache table");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * usrtb_start
- *	creates an an empty usrtb
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-usrtb_start(void)
-{
-	static int fail = 0;
-
-	if (usrtb != NULL)
-		return(0);
-	if (fail)
-		return(-1);
-	if ((usrtb = (UIDC **)calloc(UNM_SZ, sizeof(UIDC *))) == NULL) {
-		++fail;
-		paxwarn(1, "Unable to allocate memory for user name cache table");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * grptb_start
- *	creates an an empty grptb
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-grptb_start(void)
-{
-	static int fail = 0;
-
-	if (grptb != NULL)
-		return(0);
-	if (fail)
-		return(-1);
-	if ((grptb = (GIDC **)calloc(GNM_SZ, sizeof(GIDC *))) == NULL) {
-		++fail;
-		paxwarn(1,"Unable to allocate memory for group name cache table");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * name_uid()
- *	caches the name (if any) for the uid. If frc set, we always return the
- *	the stored name (if valid or invalid match). We use a simple hash table.
- * Return
- *	Pointer to stored name (or an empty string).
- */
-
-const char *
-name_uid(uid_t uid, int frc)
-{
-	struct passwd *pw;
-	UIDC *ptr;
-
-	if ((uidtb == NULL) && (uidtb_start() < 0))
-		return("");
-
-	/*
-	 * see if we have this uid cached
-	 */
-	ptr = uidtb[uid % UID_SZ];
-	if ((ptr != NULL) && (ptr->valid > 0) && (ptr->uid == uid)) {
-		/*
-		 * have an entry for this uid
-		 */
-		if (frc || (ptr->valid == VALID))
-			return(ptr->name);
-		return("");
-	}
-
-	/*
-	 * No entry for this uid, we will add it
-	 */
-	if (!pwopn) {
-		setpassent(1);
-		++pwopn;
-	}
-	if (ptr == NULL)
-		ptr = uidtb[uid % UID_SZ] = (UIDC *)malloc(sizeof(UIDC));
-
-	if ((pw = getpwuid(uid)) == NULL) {
-		/*
-		 * no match for this uid in the local password file
-		 * a string that is the uid in numeric format
-		 */
-		if (ptr == NULL)
-			return("");
-		ptr->uid = uid;
-		ptr->valid = INVALID;
-#		ifdef NET2_STAT
-		(void)snprintf(ptr->name, sizeof(ptr->name), "%u", uid);
-#		else
-		(void)snprintf(ptr->name, sizeof(ptr->name), "%lu",
-			       (unsigned long)uid);
-#		endif
-		if (frc == 0)
-			return("");
-	} else {
-		/*
-		 * there is an entry for this uid in the password file
-		 */
-		if (ptr == NULL)
-			return(pw->pw_name);
-		ptr->uid = uid;
-		(void)strncpy(ptr->name, pw->pw_name, UNMLEN - 1);
-		ptr->name[UNMLEN-1] = '\0';
-		ptr->valid = VALID;
-	}
-	return(ptr->name);
-}
-
-/*
- * name_gid()
- *	caches the name (if any) for the gid. If frc set, we always return the
- *	the stored name (if valid or invalid match). We use a simple hash table.
- * Return
- *	Pointer to stored name (or an empty string).
- */
-
-const char *
-name_gid(gid_t gid, int frc)
-{
-	struct group *gr;
-	GIDC *ptr;
-
-	if ((gidtb == NULL) && (gidtb_start() < 0))
-		return("");
-
-	/*
-	 * see if we have this gid cached
-	 */
-	ptr = gidtb[gid % GID_SZ];
-	if ((ptr != NULL) && (ptr->valid > 0) && (ptr->gid == gid)) {
-		/*
-		 * have an entry for this gid
-		 */
-		if (frc || (ptr->valid == VALID))
-			return(ptr->name);
-		return("");
-	}
-
-	/*
-	 * No entry for this gid, we will add it
-	 */
-	if (!gropn) {
-		setgroupent(1);
-		++gropn;
-	}
-	if (ptr == NULL)
-		ptr = gidtb[gid % GID_SZ] = (GIDC *)malloc(sizeof(GIDC));
-
-	if ((gr = getgrgid(gid)) == NULL) {
-		/*
-		 * no match for this gid in the local group file, put in
-		 * a string that is the gid in numeric format
-		 */
-		if (ptr == NULL)
-			return("");
-		ptr->gid = gid;
-		ptr->valid = INVALID;
-#		ifdef NET2_STAT
-		(void)snprintf(ptr->name, sizeof(ptr->name), "%u", gid);
-#		else
-		(void)snprintf(ptr->name, sizeof(ptr->name), "%lu",
-			       (unsigned long)gid);
-#		endif
-		if (frc == 0)
-			return("");
-	} else {
-		/*
-		 * there is an entry for this group in the group file
-		 */
-		if (ptr == NULL)
-			return(gr->gr_name);
-		ptr->gid = gid;
-		(void)strncpy(ptr->name, gr->gr_name, GNMLEN - 1);
-		ptr->name[GNMLEN-1] = '\0';
-		ptr->valid = VALID;
-	}
-	return(ptr->name);
-}
-
-/*
- * uid_name()
- *	caches the uid for a given user name. We use a simple hash table.
- * Return
- *	the uid (if any) for a user name, or a -1 if no match can be found
- */
-
-int
-uid_name(char *name, uid_t *uid)
-{
-	struct passwd *pw;
-	UIDC *ptr;
-	int namelen;
-
-	/*
-	 * return -1 for mangled names
-	 */
-	if (((namelen = strlen(name)) == 0) || (name[0] == '\0'))
-		return(-1);
-	if ((usrtb == NULL) && (usrtb_start() < 0))
-		return(-1);
-
-	/*
-	 * look up in hash table, if found and valid return the uid,
-	 * if found and invalid, return a -1
-	 */
-	ptr = usrtb[st_hash(name, namelen, UNM_SZ)];
-	if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) {
-		if (ptr->valid == INVALID)
-			return(-1);
-		*uid = ptr->uid;
-		return(0);
-	}
-
-	if (!pwopn) {
-		setpassent(1);
-		++pwopn;
-	}
-
-	if (ptr == NULL)
-		ptr = usrtb[st_hash(name, namelen, UNM_SZ)] =
-		  (UIDC *)malloc(sizeof(UIDC));
-
-	/*
-	 * no match, look it up, if no match store it as an invalid entry,
-	 * or store the matching uid
-	 */
-	if (ptr == NULL) {
-		if ((pw = getpwnam(name)) == NULL)
-			return(-1);
-		*uid = pw->pw_uid;
-		return(0);
-	}
-	(void)strncpy(ptr->name, name, UNMLEN - 1);
-	ptr->name[UNMLEN-1] = '\0';
-	if ((pw = getpwnam(name)) == NULL) {
-		ptr->valid = INVALID;
-		return(-1);
-	}
-	ptr->valid = VALID;
-	*uid = ptr->uid = pw->pw_uid;
-	return(0);
-}
-
-/*
- * gid_name()
- *	caches the gid for a given group name. We use a simple hash table.
- * Return
- *	the gid (if any) for a group name, or a -1 if no match can be found
- */
-
-int
-gid_name(char *name, gid_t *gid)
-{
-	struct group *gr;
-	GIDC *ptr;
-	int namelen;
-
-	/*
-	 * return -1 for mangled names
-	 */
-	if (((namelen = strlen(name)) == 0) || (name[0] == '\0'))
-		return(-1);
-	if ((grptb == NULL) && (grptb_start() < 0))
-		return(-1);
-
-	/*
-	 * look up in hash table, if found and valid return the uid,
-	 * if found and invalid, return a -1
-	 */
-	ptr = grptb[st_hash(name, namelen, GID_SZ)];
-	if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) {
-		if (ptr->valid == INVALID)
-			return(-1);
-		*gid = ptr->gid;
-		return(0);
-	}
-
-	if (!gropn) {
-		setgroupent(1);
-		++gropn;
-	}
-	if (ptr == NULL)
-		ptr = grptb[st_hash(name, namelen, GID_SZ)] =
-		  (GIDC *)malloc(sizeof(GIDC));
-
-	/*
-	 * no match, look it up, if no match store it as an invalid entry,
-	 * or store the matching gid
-	 */
-	if (ptr == NULL) {
-		if ((gr = getgrnam(name)) == NULL)
-			return(-1);
-		*gid = gr->gr_gid;
-		return(0);
-	}
-
-	(void)strncpy(ptr->name, name, GNMLEN - 1);
-	ptr->name[GNMLEN-1] = '\0';
-	if ((gr = getgrnam(name)) == NULL) {
-		ptr->valid = INVALID;
-		return(-1);
-	}
-	ptr->valid = VALID;
-	*gid = ptr->gid = gr->gr_gid;
-	return(0);
-}
Index: trunk/minix/commands/pax/cache.h
===================================================================
--- trunk/minix/commands/pax/cache.h	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *      @(#)cache.h	8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/bin/pax/cache.h,v 1.9 2004/04/06 20:06:48 markm Exp $
- */
-
-/*
- * Constants and data structures used to implement group and password file
- * caches. Traditional passwd/group cache routines perform quite poorly with
- * archives. The chances of hitting a valid lookup with an archive is quite a
- * bit worse than with files already resident on the file system. These misses
- * create a MAJOR performance cost. To address this problem, these routines
- * cache both hits and misses.
- *
- * NOTE:  name lengths must be as large as those stored in ANY PROTOCOL and
- * as stored in the passwd and group files. CACHE SIZES MUST BE PRIME
- */
-#define UNMLEN		32	/* >= user name found in any protocol */
-#define GNMLEN		32	/* >= group name found in any protocol */
-#define UID_SZ		317	/* size of user_name/uid cache */
-#define UNM_SZ		317	/* size of user_name/uid cache */
-#define GID_SZ		251	/* size of gid cache */
-#define GNM_SZ		317	/* size of group name cache */
-#define VALID		1	/* entry and name are valid */
-#define INVALID		2	/* entry valid, name NOT valid */
-
-/*
- * Node structures used in the user, group, uid, and gid caches.
- */
-
-typedef struct uidc {
-	int valid;		/* is this a valid or a miss entry */
-	char name[UNMLEN];	/* uid name */
-	uid_t uid;		/* cached uid */
-} UIDC;
-
-typedef struct gidc {
-	int valid;		/* is this a valid or a miss entry */
-	char name[GNMLEN];	/* gid name */
-	gid_t gid;		/* cached gid */
-} GIDC;
Index: trunk/minix/commands/pax/cpio.c
===================================================================
--- trunk/minix/commands/pax/cpio.c	(revision 9)
+++ 	(revision )
@@ -1,1152 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)cpio.c	8.1 (Berkeley) 5/31/93";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "pax.h"
-#include "cpio.h"
-#include "extern.h"
-
-static int rd_nm(ARCHD *, int);
-static int rd_ln_nm(ARCHD *);
-static int com_rd(ARCHD *);
-
-/*
- * Routines which support the different cpio versions
- */
-
-static int swp_head;		/* binary cpio header byte swap */
-
-/*
- * Routines common to all versions of cpio
- */
-
-/*
- * cpio_strd()
- *	Fire up the hard link detection code
- * Return:
- *      0 if ok -1 otherwise (the return values of lnk_start())
- */
-
-int
-cpio_strd(void)
-{
-	return(lnk_start());
-}
-
-/*
- * cpio_trail()
- *	Called to determine if a header block is a valid trailer. We are
- *	passed the block, the in_sync flag (which tells us we are in resync
- *	mode; looking for a valid header), and cnt (which starts at zero)
- *	which is used to count the number of empty blocks we have seen so far.
- * Return:
- *	0 if a valid trailer, -1 if not a valid trailer,
- */
-
-int
-cpio_trail(ARCHD *arcn)
-{
-	/*
-	 * look for trailer id in file we are about to process
-	 */
-	if ((strcmp(arcn->name, TRAILER) == 0) && (arcn->sb.st_size == 0))
-		return(0);
-	return(-1);
-}
-
-/*
- * com_rd()
- *	operations common to all cpio read functions.
- * Return:
- *	0
- */
-
-static int
-com_rd(ARCHD *arcn)
-{
-	arcn->skip = 0;
-	arcn->pat = NULL;
-	arcn->org_name = arcn->name;
-	switch(arcn->sb.st_mode & C_IFMT) {
-	case C_ISFIFO:
-		arcn->type = PAX_FIF;
-		break;
-	case C_ISDIR:
-		arcn->type = PAX_DIR;
-		break;
-	case C_ISBLK:
-		arcn->type = PAX_BLK;
-		break;
-	case C_ISCHR:
-		arcn->type = PAX_CHR;
-		break;
-	case C_ISLNK:
-		arcn->type = PAX_SLK;
-		break;
-	case C_ISOCK:
-		arcn->type = PAX_SCK;
-		break;
-	case C_ISCTG:
-	case C_ISREG:
-	default:
-		/*
-		 * we have file data, set up skip (pad is set in the format
-		 * specific sections)
-		 */
-		arcn->sb.st_mode = (arcn->sb.st_mode & 0xfff) | C_ISREG;
-		arcn->type = PAX_REG;
-		arcn->skip = arcn->sb.st_size;
-		break;
-	}
-	if (chk_lnk(arcn) < 0)
-		return(-1);
-	return(0);
-}
-
-/*
- * cpio_end_wr()
- *	write the special file with the name trailer in the proper format
- * Return:
- *	result of the write of the trailer from the cpio specific write func
- */
-
-int
-cpio_endwr(void)
-{
-	ARCHD last;
-
-	/*
-	 * create a trailer request and call the proper format write function
-	 */
-	memset(&last, 0, sizeof(last));
-	last.nlen = sizeof(TRAILER) - 1;
-	last.type = PAX_REG;
-	last.sb.st_nlink = 1;
-	(void)strcpy(last.name, TRAILER);
-	return((*frmt->wr)(&last));
-}
-
-/*
- * rd_nam()
- *	read in the file name which follows the cpio header
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-static int
-rd_nm(ARCHD *arcn, int nsz)
-{
-	/*
-	 * do not even try bogus values
-	 */
-	if ((nsz == 0) || (nsz > (int)sizeof(arcn->name))) {
-		paxwarn(1, "Cpio file name length %d is out of range", nsz);
-		return(-1);
-	}
-
-	/*
-	 * read the name and make sure it is not empty and is \0 terminated
-	 */
-	if ((rd_wrbuf(arcn->name,nsz) != nsz) || (arcn->name[nsz-1] != '\0') ||
-	    (arcn->name[0] == '\0')) {
-		paxwarn(1, "Cpio file name in header is corrupted");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * rd_ln_nm()
- *	read in the link name for a file with links. The link name is stored
- *	like file data (and is NOT \0 terminated!)
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-static int
-rd_ln_nm(ARCHD *arcn)
-{
-	/*
-	 * check the length specified for bogus values
-	 */
-	if ((arcn->sb.st_size == 0) ||
-	    ((size_t)arcn->sb.st_size >= sizeof(arcn->ln_name))) {
-#		ifdef NET2_STAT
-		paxwarn(1, "Cpio link name length is invalid: %lu",
-		    arcn->sb.st_size);
-#		else
-		paxwarn(1, "Cpio link name length is invalid: %ju",
-		    (uintmax_t)arcn->sb.st_size);
-#		endif
-		return(-1);
-	}
-
-	/*
-	 * read in the link name and \0 terminate it
-	 */
-	if (rd_wrbuf(arcn->ln_name, (int)arcn->sb.st_size) !=
-	    (int)arcn->sb.st_size) {
-		paxwarn(1, "Cpio link name read error");
-		return(-1);
-	}
-	arcn->ln_nlen = arcn->sb.st_size;
-	arcn->ln_name[arcn->ln_nlen] = '\0';
-
-	/*
-	 * watch out for those empty link names
-	 */
-	if (arcn->ln_name[0] == '\0') {
-		paxwarn(1, "Cpio link name is corrupt");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * Routines common to the extended byte oriented cpio format
- */
-
-/*
- * cpio_id()
- *      determine if a block given to us is a valid extended byte oriented
- *	cpio header
- * Return:
- *      0 if a valid header, -1 otherwise
- */
-
-int
-cpio_id(char *blk, int size)
-{
-	if ((size < (int)sizeof(HD_CPIO)) ||
-	    (strncmp(blk, AMAGIC, sizeof(AMAGIC) - 1) != 0))
-		return(-1);
-	return(0);
-}
-
-/*
- * cpio_rd()
- *	determine if a buffer is a byte oriented extended cpio archive entry.
- *	convert and store the values in the ARCHD parameter.
- * Return:
- *	0 if a valid header, -1 otherwise.
- */
-
-int
-cpio_rd(ARCHD *arcn, char *buf)
-{
-	int nsz;
-	HD_CPIO *hd;
-
-	/*
-	 * check that this is a valid header, if not return -1
-	 */
-	if (cpio_id(buf, sizeof(HD_CPIO)) < 0)
-		return(-1);
-	hd = (HD_CPIO *)buf;
-
-	/*
-	 * byte oriented cpio (posix) does not have padding! extract the octal
-	 * ascii fields from the header
-	 */
-	arcn->pad = 0L;
-	arcn->sb.st_dev = (dev_t)asc_ul(hd->c_dev, sizeof(hd->c_dev), OCT);
-	arcn->sb.st_ino = (ino_t)asc_ul(hd->c_ino, sizeof(hd->c_ino), OCT);
-	arcn->sb.st_mode = (mode_t)asc_ul(hd->c_mode, sizeof(hd->c_mode), OCT);
-	arcn->sb.st_uid = (uid_t)asc_ul(hd->c_uid, sizeof(hd->c_uid), OCT);
-	arcn->sb.st_gid = (gid_t)asc_ul(hd->c_gid, sizeof(hd->c_gid), OCT);
-	arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink),
-	    OCT);
-	arcn->sb.st_rdev = (dev_t)asc_ul(hd->c_rdev, sizeof(hd->c_rdev), OCT);
-#ifdef NET2_STAT
-	arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime, sizeof(hd->c_mtime),
-	    OCT);
-#else
-	arcn->sb.st_mtime = (time_t)asc_uqd(hd->c_mtime, sizeof(hd->c_mtime),
-	    OCT);
-#endif
-	arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
-#ifdef NET2_STAT
-	arcn->sb.st_size = (off_t)asc_ul(hd->c_filesize,sizeof(hd->c_filesize),
-	    OCT);
-#else
-	arcn->sb.st_size = (off_t)asc_uqd(hd->c_filesize,sizeof(hd->c_filesize),
-	    OCT);
-#endif
-
-	/*
-	 * check name size and if valid, read in the name of this entry (name
-	 * follows header in the archive)
-	 */
-	if ((nsz = (int)asc_ul(hd->c_namesize,sizeof(hd->c_namesize),OCT)) < 2)
-		return(-1);
-	arcn->nlen = nsz - 1;
-	if (rd_nm(arcn, nsz) < 0)
-		return(-1);
-
-	if (((arcn->sb.st_mode&C_IFMT) != C_ISLNK)||(arcn->sb.st_size == 0)) {
-		/*
-	 	 * no link name to read for this file
-	 	 */
-		arcn->ln_nlen = 0;
-		arcn->ln_name[0] = '\0';
-		return(com_rd(arcn));
-	}
-
-	/*
-	 * check link name size and read in the link name. Link names are
-	 * stored like file data.
-	 */
-	if (rd_ln_nm(arcn) < 0)
-		return(-1);
-
-	/*
-	 * we have a valid header (with a link)
-	 */
-	return(com_rd(arcn));
-}
-
-/*
- * cpio_endrd()
- *      no cleanup needed here, just return size of the trailer (for append)
- * Return:
- *      size of trailer header in this format
- */
-
-off_t
-cpio_endrd(void)
-{
-	return((off_t)(sizeof(HD_CPIO) + sizeof(TRAILER)));
-}
-
-/*
- * cpio_stwr()
- *	start up the device mapping table
- * Return:
- *	0 if ok, -1 otherwise (what dev_start() returns)
- */
-
-int
-cpio_stwr(void)
-{
-	return(dev_start());
-}
-
-/*
- * cpio_wr()
- *	copy the data in the ARCHD to buffer in extended byte oriented cpio
- *	format.
- * Return
- *      0 if file has data to be written after the header, 1 if file has NO
- *	data to write after the header, -1 if archive write failed
- */
-
-int
-cpio_wr(ARCHD *arcn)
-{
-	HD_CPIO *hd;
-	int nsz;
-	char hdblk[sizeof(HD_CPIO)];
-
-	/*
-	 * check and repair truncated device and inode fields in the header
-	 */
-	if (map_dev(arcn, (u_long)CPIO_MASK, (u_long)CPIO_MASK) < 0)
-		return(-1);
-
-	arcn->pad = 0L;
-	nsz = arcn->nlen + 1;
-	hd = (HD_CPIO *)hdblk;
-	if ((arcn->type != PAX_BLK) && (arcn->type != PAX_CHR))
-		arcn->sb.st_rdev = 0;
-
-	switch(arcn->type) {
-	case PAX_CTG:
-	case PAX_REG:
-	case PAX_HRG:
-		/*
-		 * set data size for file data
-		 */
-#		ifdef NET2_STAT
-		if (ul_asc((u_long)arcn->sb.st_size, hd->c_filesize,
-		    sizeof(hd->c_filesize), OCT)) {
-#		else
-		if (uqd_asc((u_quad_t)arcn->sb.st_size, hd->c_filesize,
-		    sizeof(hd->c_filesize), OCT)) {
-#		endif
-			paxwarn(1,"File is too large for cpio format %s",
-			    arcn->org_name);
-			return(1);
-		}
-		break;
-	case PAX_SLK:
-		/*
-		 * set data size to hold link name
-		 */
-		if (ul_asc((u_long)arcn->ln_nlen, hd->c_filesize,
-		    sizeof(hd->c_filesize), OCT))
-			goto out;
-		break;
-	default:
-		/*
-		 * all other file types have no file data
-		 */
-		if (ul_asc((u_long)0, hd->c_filesize, sizeof(hd->c_filesize),
-		     OCT))
-			goto out;
-		break;
-	}
-
-	/*
-	 * copy the values to the header using octal ascii
-	 */
-	if (ul_asc((u_long)MAGIC, hd->c_magic, sizeof(hd->c_magic), OCT) ||
-	    ul_asc((u_long)arcn->sb.st_dev, hd->c_dev, sizeof(hd->c_dev),
-		OCT) ||
-	    ul_asc((u_long)arcn->sb.st_ino, hd->c_ino, sizeof(hd->c_ino),
-		OCT) ||
-	    ul_asc((u_long)arcn->sb.st_mode, hd->c_mode, sizeof(hd->c_mode),
-		OCT) ||
-	    ul_asc((u_long)arcn->sb.st_uid, hd->c_uid, sizeof(hd->c_uid),
-		OCT) ||
-	    ul_asc((u_long)arcn->sb.st_gid, hd->c_gid, sizeof(hd->c_gid),
-		OCT) ||
-	    ul_asc((u_long)arcn->sb.st_nlink, hd->c_nlink, sizeof(hd->c_nlink),
-		 OCT) ||
-	    ul_asc((u_long)arcn->sb.st_rdev, hd->c_rdev, sizeof(hd->c_rdev),
-		OCT) ||
-	    ul_asc((u_long)arcn->sb.st_mtime,hd->c_mtime,sizeof(hd->c_mtime),
-		OCT) ||
-	    ul_asc((u_long)nsz, hd->c_namesize, sizeof(hd->c_namesize), OCT))
-		goto out;
-
-	/*
-	 * write the file name to the archive
-	 */
-	if ((wr_rdbuf(hdblk, (int)sizeof(HD_CPIO)) < 0) ||
-	    (wr_rdbuf(arcn->name, nsz) < 0)) {
-		paxwarn(1, "Unable to write cpio header for %s", arcn->org_name);
-		return(-1);
-	}
-
-	/*
-	 * if this file has data, we are done. The caller will write the file
-	 * data, if we are link tell caller we are done, go to next file
-	 */
-	if ((arcn->type == PAX_CTG) || (arcn->type == PAX_REG) ||
-	    (arcn->type == PAX_HRG))
-		return(0);
-	if (arcn->type != PAX_SLK)
-		return(1);
-
-	/*
-	 * write the link name to the archive, tell the caller to go to the
-	 * next file as we are done.
-	 */
-	if (wr_rdbuf(arcn->ln_name, arcn->ln_nlen) < 0) {
-		paxwarn(1,"Unable to write cpio link name for %s",arcn->org_name);
-		return(-1);
-	}
-	return(1);
-
-    out:
-	/*
-	 * header field is out of range
-	 */
-	paxwarn(1, "Cpio header field is too small to store file %s",
-	    arcn->org_name);
-	return(1);
-}
-
-/*
- * Routines common to the system VR4 version of cpio (with/without file CRC)
- */
-
-/*
- * vcpio_id()
- *      determine if a block given to us is a valid system VR4 cpio header
- *	WITHOUT crc. WATCH it the magic cookies are in OCTAL, the header
- *	uses HEX
- * Return:
- *      0 if a valid header, -1 otherwise
- */
-
-int
-vcpio_id(char *blk, int size)
-{
-	if ((size < (int)sizeof(HD_VCPIO)) ||
-	    (strncmp(blk, AVMAGIC, sizeof(AVMAGIC) - 1) != 0))
-		return(-1);
-	return(0);
-}
-
-/*
- * crc_id()
- *      determine if a block given to us is a valid system VR4 cpio header
- *	WITH crc. WATCH it the magic cookies are in OCTAL the header uses HEX
- * Return:
- *      0 if a valid header, -1 otherwise
- */
-
-int
-crc_id(char *blk, int size)
-{
-	if ((size < (int)sizeof(HD_VCPIO)) ||
-	    (strncmp(blk, AVCMAGIC, (int)sizeof(AVCMAGIC) - 1) != 0))
-		return(-1);
-	return(0);
-}
-
-/*
- * crc_strd()
- w	set file data CRC calculations. Fire up the hard link detection code
- * Return:
- *      0 if ok -1 otherwise (the return values of lnk_start())
- */
-
-int
-crc_strd(void)
-{
-	docrc = 1;
-	return(lnk_start());
-}
-
-/*
- * vcpio_rd()
- *	determine if a buffer is a system VR4 archive entry. (with/without CRC)
- *	convert and store the values in the ARCHD parameter.
- * Return:
- *	0 if a valid header, -1 otherwise.
- */
-
-int
-vcpio_rd(ARCHD *arcn, char *buf)
-{
-	HD_VCPIO *hd;
-	dev_t devminor;
-	dev_t devmajor;
-	int nsz;
-
-	/*
-	 * during the id phase it was determined if we were using CRC, use the
-	 * proper id routine.
-	 */
-	if (docrc) {
-		if (crc_id(buf, sizeof(HD_VCPIO)) < 0)
-			return(-1);
-	} else {
-		if (vcpio_id(buf, sizeof(HD_VCPIO)) < 0)
-			return(-1);
-	}
-
-	hd = (HD_VCPIO *)buf;
-	arcn->pad = 0L;
-
-	/*
-	 * extract the hex ascii fields from the header
-	 */
-	arcn->sb.st_ino = (ino_t)asc_ul(hd->c_ino, sizeof(hd->c_ino), HEX);
-	arcn->sb.st_mode = (mode_t)asc_ul(hd->c_mode, sizeof(hd->c_mode), HEX);
-	arcn->sb.st_uid = (uid_t)asc_ul(hd->c_uid, sizeof(hd->c_uid), HEX);
-	arcn->sb.st_gid = (gid_t)asc_ul(hd->c_gid, sizeof(hd->c_gid), HEX);
-#ifdef NET2_STAT
-	arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime,sizeof(hd->c_mtime),HEX);
-#else
-	arcn->sb.st_mtime = (time_t)asc_uqd(hd->c_mtime,sizeof(hd->c_mtime),HEX);
-#endif
-	arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
-#ifdef NET2_STAT
-	arcn->sb.st_size = (off_t)asc_ul(hd->c_filesize,
-	    sizeof(hd->c_filesize), HEX);
-#else
-	arcn->sb.st_size = (off_t)asc_uqd(hd->c_filesize,
-	    sizeof(hd->c_filesize), HEX);
-#endif
-	arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink),
-	    HEX);
-	devmajor = (dev_t)asc_ul(hd->c_maj, sizeof(hd->c_maj), HEX);
-	devminor = (dev_t)asc_ul(hd->c_min, sizeof(hd->c_min), HEX);
-	arcn->sb.st_dev = TODEV(devmajor, devminor);
-	devmajor = (dev_t)asc_ul(hd->c_rmaj, sizeof(hd->c_maj), HEX);
-	devminor = (dev_t)asc_ul(hd->c_rmin, sizeof(hd->c_min), HEX);
-	arcn->sb.st_rdev = TODEV(devmajor, devminor);
-	arcn->crc = asc_ul(hd->c_chksum, sizeof(hd->c_chksum), HEX);
-
-	/*
-	 * check the length of the file name, if ok read it in, return -1 if
-	 * bogus
-	 */
-	if ((nsz = (int)asc_ul(hd->c_namesize,sizeof(hd->c_namesize),HEX)) < 2)
-		return(-1);
-	arcn->nlen = nsz - 1;
-	if (rd_nm(arcn, nsz) < 0)
-		return(-1);
-
-	/*
-	 * skip padding. header + filename is aligned to 4 byte boundries
-	 */
-	if (rd_skip((off_t)(VCPIO_PAD(sizeof(HD_VCPIO) + nsz))) < 0)
-		return(-1);
-
-	/*
-	 * if not a link (or a file with no data), calculate pad size (for
-	 * padding which follows the file data), clear the link name and return
-	 */
-	if (((arcn->sb.st_mode&C_IFMT) != C_ISLNK)||(arcn->sb.st_size == 0)) {
-		/*
-		 * we have a valid header (not a link)
-		 */
-		arcn->ln_nlen = 0;
-		arcn->ln_name[0] = '\0';
-		arcn->pad = VCPIO_PAD(arcn->sb.st_size);
-		return(com_rd(arcn));
-	}
-
-	/*
-	 * read in the link name and skip over the padding
-	 */
-	if ((rd_ln_nm(arcn) < 0) ||
-	    (rd_skip((off_t)(VCPIO_PAD(arcn->sb.st_size))) < 0))
-		return(-1);
-
-	/*
-	 * we have a valid header (with a link)
-	 */
-	return(com_rd(arcn));
-}
-
-/*
- * vcpio_endrd()
- *      no cleanup needed here, just return size of the trailer (for append)
- * Return:
- *      size of trailer header in this format
- */
-
-off_t
-vcpio_endrd(void)
-{
-	return((off_t)(sizeof(HD_VCPIO) + sizeof(TRAILER) +
-		(VCPIO_PAD(sizeof(HD_VCPIO) + sizeof(TRAILER)))));
-}
-
-/*
- * crc_stwr()
- *	start up the device mapping table, enable crc file calculation
- * Return:
- *	0 if ok, -1 otherwise (what dev_start() returns)
- */
-
-int
-crc_stwr(void)
-{
-	docrc = 1;
-	return(dev_start());
-}
-
-/*
- * vcpio_wr()
- *	copy the data in the ARCHD to buffer in system VR4 cpio
- *	(with/without crc) format.
- * Return
- *	0 if file has data to be written after the header, 1 if file has
- *	NO data to write after the header, -1 if archive write failed
- */
-
-int
-vcpio_wr(ARCHD *arcn)
-{
-	HD_VCPIO *hd;
-	unsigned int nsz;
-	char hdblk[sizeof(HD_VCPIO)];
-
-	/*
-	 * check and repair truncated device and inode fields in the cpio
-	 * header
-	 */
-	if (map_dev(arcn, (u_long)VCPIO_MASK, (u_long)VCPIO_MASK) < 0)
-		return(-1);
-	nsz = arcn->nlen + 1;
-	hd = (HD_VCPIO *)hdblk;
-	if ((arcn->type != PAX_BLK) && (arcn->type != PAX_CHR))
-		arcn->sb.st_rdev = 0;
-
-	/*
-	 * add the proper magic value depending whether we were asked for
-	 * file data crc's, and the crc if needed.
-	 */
-	if (docrc) {
-		if (ul_asc((u_long)VCMAGIC, hd->c_magic, sizeof(hd->c_magic),
-	    		OCT) ||
-		    ul_asc((u_long)arcn->crc,hd->c_chksum,sizeof(hd->c_chksum),
-	    		HEX))
-			goto out;
-	} else {
-		if (ul_asc((u_long)VMAGIC, hd->c_magic, sizeof(hd->c_magic),
-	    		OCT) ||
-		    ul_asc((u_long)0L, hd->c_chksum, sizeof(hd->c_chksum),HEX))
-			goto out;
-	}
-
-	switch(arcn->type) {
-	case PAX_CTG:
-	case PAX_REG:
-	case PAX_HRG:
-		/*
-		 * caller will copy file data to the archive. tell him how
-		 * much to pad.
-		 */
-		arcn->pad = VCPIO_PAD(arcn->sb.st_size);
-#		ifdef NET2_STAT
-		if (ul_asc((u_long)arcn->sb.st_size, hd->c_filesize,
-		    sizeof(hd->c_filesize), HEX)) {
-#		else
-		if (uqd_asc((u_quad_t)arcn->sb.st_size, hd->c_filesize,
-		    sizeof(hd->c_filesize), HEX)) {
-#		endif
-			paxwarn(1,"File is too large for sv4cpio format %s",
-			    arcn->org_name);
-			return(1);
-		}
-		break;
-	case PAX_SLK:
-		/*
-		 * no file data for the caller to process, the file data has
-		 * the size of the link
-		 */
-		arcn->pad = 0L;
-		if (ul_asc((u_long)arcn->ln_nlen, hd->c_filesize,
-		    sizeof(hd->c_filesize), HEX))
-			goto out;
-		break;
-	default:
-		/*
-		 * no file data for the caller to process
-		 */
-		arcn->pad = 0L;
-		if (ul_asc((u_long)0L, hd->c_filesize, sizeof(hd->c_filesize),
-		    HEX))
-			goto out;
-		break;
-	}
-
-	/*
-	 * set the other fields in the header
-	 */
-	if (ul_asc((u_long)arcn->sb.st_ino, hd->c_ino, sizeof(hd->c_ino),
-		HEX) ||
-	    ul_asc((u_long)arcn->sb.st_mode, hd->c_mode, sizeof(hd->c_mode),
-		HEX) ||
-	    ul_asc((u_long)arcn->sb.st_uid, hd->c_uid, sizeof(hd->c_uid),
-		HEX) ||
-	    ul_asc((u_long)arcn->sb.st_gid, hd->c_gid, sizeof(hd->c_gid),
-    		HEX) ||
-	    ul_asc((u_long)arcn->sb.st_mtime, hd->c_mtime, sizeof(hd->c_mtime),
-    		HEX) ||
-	    ul_asc((u_long)arcn->sb.st_nlink, hd->c_nlink, sizeof(hd->c_nlink),
-    		HEX) ||
-	    ul_asc((u_long)major(arcn->sb.st_dev),hd->c_maj, sizeof(hd->c_maj),
-		HEX) ||
-	    ul_asc((u_long)minor(arcn->sb.st_dev),hd->c_min, sizeof(hd->c_min),
-		HEX) ||
-	    ul_asc((u_long)major(arcn->sb.st_rdev),hd->c_rmaj,sizeof(hd->c_maj),
-		HEX) ||
-	    ul_asc((u_long)minor(arcn->sb.st_rdev),hd->c_rmin,sizeof(hd->c_min),
-		HEX) ||
-	    ul_asc((u_long)nsz, hd->c_namesize, sizeof(hd->c_namesize), HEX))
-		goto out;
-
-	/*
-	 * write the header, the file name and padding as required.
-	 */
-	if ((wr_rdbuf(hdblk, (int)sizeof(HD_VCPIO)) < 0) ||
-	    (wr_rdbuf(arcn->name, (int)nsz) < 0)  ||
-	    (wr_skip((off_t)(VCPIO_PAD(sizeof(HD_VCPIO) + nsz))) < 0)) {
-		paxwarn(1,"Could not write sv4cpio header for %s",arcn->org_name);
-		return(-1);
-	}
-
-	/*
-	 * if we have file data, tell the caller we are done, copy the file
-	 */
-	if ((arcn->type == PAX_CTG) || (arcn->type == PAX_REG) ||
-	    (arcn->type == PAX_HRG))
-		return(0);
-
-	/*
-	 * if we are not a link, tell the caller we are done, go to next file
-	 */
-	if (arcn->type != PAX_SLK)
-		return(1);
-
-	/*
-	 * write the link name, tell the caller we are done.
-	 */
-	if ((wr_rdbuf(arcn->ln_name, arcn->ln_nlen) < 0) ||
-	    (wr_skip((off_t)(VCPIO_PAD(arcn->ln_nlen))) < 0)) {
-		paxwarn(1,"Could not write sv4cpio link name for %s",
-		    arcn->org_name);
-		return(-1);
-	}
-	return(1);
-
-    out:
-	/*
-	 * header field is out of range
-	 */
-	paxwarn(1,"Sv4cpio header field is too small for file %s",arcn->org_name);
-	return(1);
-}
-
-/*
- * Routines common to the old binary header cpio
- */
-
-/*
- * bcpio_id()
- *      determine if a block given to us is an old binary cpio header
- *	(with/without header byte swapping)
- * Return:
- *      0 if a valid header, -1 otherwise
- */
-
-int
-bcpio_id(char *blk, int size)
-{
-	if (size < (int)sizeof(HD_BCPIO))
-		return(-1);
-
-	/*
-	 * check both normal and byte swapped magic cookies
-	 */
-	if (((u_short)SHRT_EXT(blk)) == MAGIC)
-		return(0);
-	if (((u_short)RSHRT_EXT(blk)) == MAGIC) {
-		if (!swp_head)
-			++swp_head;
-		return(0);
-	}
-	return(-1);
-}
-
-/*
- * bcpio_rd()
- *	determine if a buffer is an old binary archive entry. (It may have byte
- *	swapped header) convert and store the values in the ARCHD parameter.
- *	This is a very old header format and should not really be used.
- * Return:
- *	0 if a valid header, -1 otherwise.
- */
-
-int
-bcpio_rd(ARCHD *arcn, char *buf)
-{
-	HD_BCPIO *hd;
-	int nsz;
-
-	/*
-	 * check the header
-	 */
-	if (bcpio_id(buf, sizeof(HD_BCPIO)) < 0)
-		return(-1);
-
-	arcn->pad = 0L;
-	hd = (HD_BCPIO *)buf;
-	if (swp_head) {
-		/*
-		 * header has swapped bytes on 16 bit boundaries
-		 */
-		arcn->sb.st_dev = (dev_t)(RSHRT_EXT(hd->h_dev));
-		arcn->sb.st_ino = (ino_t)(RSHRT_EXT(hd->h_ino));
-		arcn->sb.st_mode = (mode_t)(RSHRT_EXT(hd->h_mode));
-		arcn->sb.st_uid = (uid_t)(RSHRT_EXT(hd->h_uid));
-		arcn->sb.st_gid = (gid_t)(RSHRT_EXT(hd->h_gid));
-		arcn->sb.st_nlink = (nlink_t)(RSHRT_EXT(hd->h_nlink));
-		arcn->sb.st_rdev = (dev_t)(RSHRT_EXT(hd->h_rdev));
-		arcn->sb.st_mtime = (time_t)(RSHRT_EXT(hd->h_mtime_1));
-		arcn->sb.st_mtime =  (arcn->sb.st_mtime << 16) |
-			((time_t)(RSHRT_EXT(hd->h_mtime_2)));
-		arcn->sb.st_size = (off_t)(RSHRT_EXT(hd->h_filesize_1));
-		arcn->sb.st_size = (arcn->sb.st_size << 16) |
-			((off_t)(RSHRT_EXT(hd->h_filesize_2)));
-		nsz = (int)(RSHRT_EXT(hd->h_namesize));
-	} else {
-		arcn->sb.st_dev = (dev_t)(SHRT_EXT(hd->h_dev));
-		arcn->sb.st_ino = (ino_t)(SHRT_EXT(hd->h_ino));
-		arcn->sb.st_mode = (mode_t)(SHRT_EXT(hd->h_mode));
-		arcn->sb.st_uid = (uid_t)(SHRT_EXT(hd->h_uid));
-		arcn->sb.st_gid = (gid_t)(SHRT_EXT(hd->h_gid));
-		arcn->sb.st_nlink = (nlink_t)(SHRT_EXT(hd->h_nlink));
-		arcn->sb.st_rdev = (dev_t)(SHRT_EXT(hd->h_rdev));
-		arcn->sb.st_mtime = (time_t)(SHRT_EXT(hd->h_mtime_1));
-		arcn->sb.st_mtime =  (arcn->sb.st_mtime << 16) |
-			((time_t)(SHRT_EXT(hd->h_mtime_2)));
-		arcn->sb.st_size = (off_t)(SHRT_EXT(hd->h_filesize_1));
-		arcn->sb.st_size = (arcn->sb.st_size << 16) |
-			((off_t)(SHRT_EXT(hd->h_filesize_2)));
-		nsz = (int)(SHRT_EXT(hd->h_namesize));
-	}
-	arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
-
-	/*
-	 * check the file name size, if bogus give up. otherwise read the file
-	 * name
-	 */
-	if (nsz < 2)
-		return(-1);
-	arcn->nlen = nsz - 1;
-	if (rd_nm(arcn, nsz) < 0)
-		return(-1);
-
-	/*
-	 * header + file name are aligned to 2 byte boundries, skip if needed
-	 */
-	if (rd_skip((off_t)(BCPIO_PAD(sizeof(HD_BCPIO) + nsz))) < 0)
-		return(-1);
-
-	/*
-	 * if not a link (or a file with no data), calculate pad size (for
-	 * padding which follows the file data), clear the link name and return
-	 */
-	if (((arcn->sb.st_mode & C_IFMT) != C_ISLNK)||(arcn->sb.st_size == 0)){
-		/*
-		 * we have a valid header (not a link)
-		 */
-		arcn->ln_nlen = 0;
-		arcn->ln_name[0] = '\0';
-		arcn->pad = BCPIO_PAD(arcn->sb.st_size);
-		return(com_rd(arcn));
-	}
-
-	if ((rd_ln_nm(arcn) < 0) ||
-	    (rd_skip((off_t)(BCPIO_PAD(arcn->sb.st_size))) < 0))
-		return(-1);
-
-	/*
-	 * we have a valid header (with a link)
-	 */
-	return(com_rd(arcn));
-}
-
-/*
- * bcpio_endrd()
- *      no cleanup needed here, just return size of the trailer (for append)
- * Return:
- *      size of trailer header in this format
- */
-
-off_t
-bcpio_endrd(void)
-{
-	return((off_t)(sizeof(HD_BCPIO) + sizeof(TRAILER) +
-		(BCPIO_PAD(sizeof(HD_BCPIO) + sizeof(TRAILER)))));
-}
-
-/*
- * bcpio_wr()
- *	copy the data in the ARCHD to buffer in old binary cpio format
- *	There is a real chance of field overflow with this critter. So we
- *	always check the conversion is ok. nobody in his their right mind
- *	should write an achive in this format...
- * Return
- *      0 if file has data to be written after the header, 1 if file has NO
- *	data to write after the header, -1 if archive write failed
- */
-
-int
-bcpio_wr(ARCHD *arcn)
-{
-	HD_BCPIO *hd;
-	int nsz;
-	char hdblk[sizeof(HD_BCPIO)];
-	off_t t_offt;
-	int t_int;
-	time_t t_timet;
-
-	/*
-	 * check and repair truncated device and inode fields in the cpio
-	 * header
-	 */
-	if (map_dev(arcn, (u_long)BCPIO_MASK, (u_long)BCPIO_MASK) < 0)
-		return(-1);
-
-	if ((arcn->type != PAX_BLK) && (arcn->type != PAX_CHR))
-		arcn->sb.st_rdev = 0;
-	hd = (HD_BCPIO *)hdblk;
-
-	switch(arcn->type) {
-	case PAX_CTG:
-	case PAX_REG:
-	case PAX_HRG:
-		/*
-		 * caller will copy file data to the archive. tell him how
-		 * much to pad.
-		 */
-		arcn->pad = BCPIO_PAD(arcn->sb.st_size);
-		hd->h_filesize_1[0] = CHR_WR_0(arcn->sb.st_size);
-		hd->h_filesize_1[1] = CHR_WR_1(arcn->sb.st_size);
-		hd->h_filesize_2[0] = CHR_WR_2(arcn->sb.st_size);
-		hd->h_filesize_2[1] = CHR_WR_3(arcn->sb.st_size);
-		t_offt = (off_t)(SHRT_EXT(hd->h_filesize_1));
-		t_offt = (t_offt<<16) | ((off_t)(SHRT_EXT(hd->h_filesize_2)));
-		if (arcn->sb.st_size != t_offt) {
-			paxwarn(1,"File is too large for bcpio format %s",
-			    arcn->org_name);
-			return(1);
-		}
-		break;
-	case PAX_SLK:
-		/*
-		 * no file data for the caller to process, the file data has
-		 * the size of the link
-		 */
-		arcn->pad = 0L;
-		hd->h_filesize_1[0] = CHR_WR_0(arcn->ln_nlen);
-		hd->h_filesize_1[1] = CHR_WR_1(arcn->ln_nlen);
-		hd->h_filesize_2[0] = CHR_WR_2(arcn->ln_nlen);
-		hd->h_filesize_2[1] = CHR_WR_3(arcn->ln_nlen);
-		t_int = (int)(SHRT_EXT(hd->h_filesize_1));
-		t_int = (t_int << 16) | ((int)(SHRT_EXT(hd->h_filesize_2)));
-		if (arcn->ln_nlen != t_int)
-			goto out;
-		break;
-	default:
-		/*
-		 * no file data for the caller to process
-		 */
-		arcn->pad = 0L;
-		hd->h_filesize_1[0] = (char)0;
-		hd->h_filesize_1[1] = (char)0;
-		hd->h_filesize_2[0] = (char)0;
-		hd->h_filesize_2[1] = (char)0;
-		break;
-	}
-
-	/*
-	 * build up the rest of the fields
-	 */
-	hd->h_magic[0] = CHR_WR_2(MAGIC);
-	hd->h_magic[1] = CHR_WR_3(MAGIC);
-	hd->h_dev[0] = CHR_WR_2(arcn->sb.st_dev);
-	hd->h_dev[1] = CHR_WR_3(arcn->sb.st_dev);
-	if (arcn->sb.st_dev != (dev_t)(SHRT_EXT(hd->h_dev)))
-		goto out;
-	hd->h_ino[0] = CHR_WR_2(arcn->sb.st_ino);
-	hd->h_ino[1] = CHR_WR_3(arcn->sb.st_ino);
-	if (arcn->sb.st_ino != (ino_t)(SHRT_EXT(hd->h_ino)))
-		goto out;
-	hd->h_mode[0] = CHR_WR_2(arcn->sb.st_mode);
-	hd->h_mode[1] = CHR_WR_3(arcn->sb.st_mode);
-	if (arcn->sb.st_mode != (mode_t)(SHRT_EXT(hd->h_mode)))
-		goto out;
-	hd->h_uid[0] = CHR_WR_2(arcn->sb.st_uid);
-	hd->h_uid[1] = CHR_WR_3(arcn->sb.st_uid);
-	if (arcn->sb.st_uid != (uid_t)(SHRT_EXT(hd->h_uid)))
-		goto out;
-	hd->h_gid[0] = CHR_WR_2(arcn->sb.st_gid);
-	hd->h_gid[1] = CHR_WR_3(arcn->sb.st_gid);
-	if (arcn->sb.st_gid != (gid_t)(SHRT_EXT(hd->h_gid)))
-		goto out;
-	hd->h_nlink[0] = CHR_WR_2(arcn->sb.st_nlink);
-	hd->h_nlink[1] = CHR_WR_3(arcn->sb.st_nlink);
-	if (arcn->sb.st_nlink != (nlink_t)(SHRT_EXT(hd->h_nlink)))
-		goto out;
-	hd->h_rdev[0] = CHR_WR_2(arcn->sb.st_rdev);
-	hd->h_rdev[1] = CHR_WR_3(arcn->sb.st_rdev);
-	if (arcn->sb.st_rdev != (dev_t)(SHRT_EXT(hd->h_rdev)))
-		goto out;
-	hd->h_mtime_1[0] = CHR_WR_0(arcn->sb.st_mtime);
-	hd->h_mtime_1[1] = CHR_WR_1(arcn->sb.st_mtime);
-	hd->h_mtime_2[0] = CHR_WR_2(arcn->sb.st_mtime);
-	hd->h_mtime_2[1] = CHR_WR_3(arcn->sb.st_mtime);
-	t_timet = (time_t)(SHRT_EXT(hd->h_mtime_1));
-	t_timet =  (t_timet << 16) | ((time_t)(SHRT_EXT(hd->h_mtime_2)));
-	if (arcn->sb.st_mtime != t_timet)
-		goto out;
-	nsz = arcn->nlen + 1;
-	hd->h_namesize[0] = CHR_WR_2(nsz);
-	hd->h_namesize[1] = CHR_WR_3(nsz);
-	if (nsz != (int)(SHRT_EXT(hd->h_namesize)))
-		goto out;
-
-	/*
-	 * write the header, the file name and padding as required.
-	 */
-	if ((wr_rdbuf(hdblk, (int)sizeof(HD_BCPIO)) < 0) ||
-	    (wr_rdbuf(arcn->name, nsz) < 0) ||
-	    (wr_skip((off_t)(BCPIO_PAD(sizeof(HD_BCPIO) + nsz))) < 0)) {
-		paxwarn(1, "Could not write bcpio header for %s", arcn->org_name);
-		return(-1);
-	}
-
-	/*
-	 * if we have file data, tell the caller we are done
-	 */
-	if ((arcn->type == PAX_CTG) || (arcn->type == PAX_REG) ||
-	    (arcn->type == PAX_HRG))
-		return(0);
-
-	/*
-	 * if we are not a link, tell the caller we are done, go to next file
-	 */
-	if (arcn->type != PAX_SLK)
-		return(1);
-
-	/*
-	 * write the link name, tell the caller we are done.
-	 */
-	if ((wr_rdbuf(arcn->ln_name, arcn->ln_nlen) < 0) ||
-	    (wr_skip((off_t)(BCPIO_PAD(arcn->ln_nlen))) < 0)) {
-		paxwarn(1,"Could not write bcpio link name for %s",arcn->org_name);
-		return(-1);
-	}
-	return(1);
-
-    out:
-	/*
-	 * header field is out of range
-	 */
-	paxwarn(1,"Bcpio header field is too small for file %s", arcn->org_name);
-	return(1);
-}
Index: trunk/minix/commands/pax/cpio.h
===================================================================
--- trunk/minix/commands/pax/cpio.h	(revision 9)
+++ 	(revision )
@@ -1,148 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *	@(#)cpio.h	8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/bin/pax/cpio.h,v 1.7 2004/04/06 20:06:48 markm Exp $
- */
-
-/*
- * Defines common to all versions of cpio
- */
-#define TRAILER		"TRAILER!!!"	/* name in last archive record */
-
-/*
- * Header encoding of the different file types
- */
-#define	C_ISDIR		 040000		/* Directory */
-#define	C_ISFIFO	 010000		/* FIFO */
-#define	C_ISREG		0100000		/* Regular file */
-#define	C_ISBLK		 060000		/* Block special file */
-#define	C_ISCHR		 020000		/* Character special file */
-#define	C_ISCTG		0110000		/* Reserved for contiguous files */
-#define	C_ISLNK		0120000		/* Reserved for symbolic links */
-#define	C_ISOCK		0140000		/* Reserved for sockets */
-#define C_IFMT		0170000		/* type of file */
-
-/*
- * Data Interchange Format - Extended cpio header format - POSIX 1003.1-1990
- */
-typedef struct {
-	char	c_magic[6];		/* magic cookie */
-	char	c_dev[6];		/* device number */
-	char	c_ino[6];		/* inode number */
-	char	c_mode[6];		/* file type/access */
-	char	c_uid[6];		/* owners uid */
-	char	c_gid[6];		/* owners gid */
-	char	c_nlink[6];		/* # of links at archive creation */
-	char	c_rdev[6];		/* block/char major/minor # */
-	char	c_mtime[11];		/* modification time */
-	char	c_namesize[6];		/* length of pathname */
-	char	c_filesize[11];		/* length of file in bytes */
-} HD_CPIO;
-
-#define	MAGIC		070707		/* transportable archive id */
-
-#ifdef _PAX_
-#define	AMAGIC		"070707"	/* ascii equivalent string of MAGIC */
-#define CPIO_MASK	0x3ffff		/* bits valid in the dev/ino fields */
-					/* used for dev/inode remaps */
-#endif /* _PAX_ */
-
-/*
- * Binary cpio header structure
- *
- * CAUTION! CAUTION! CAUTION!
- * Each field really represents a 16 bit short (NOT ASCII). Described as
- * an array of chars in an attempt to improve portability!!
- */
-typedef struct {
-	u_char	h_magic[2];
-	u_char	h_dev[2];
-	u_char	h_ino[2];
-	u_char	h_mode[2];
-	u_char	h_uid[2];
-	u_char	h_gid[2];
-	u_char	h_nlink[2];
-	u_char	h_rdev[2];
-	u_char	h_mtime_1[2];
-	u_char	h_mtime_2[2];
-	u_char	h_namesize[2];
-	u_char	h_filesize_1[2];
-	u_char	h_filesize_2[2];
-} HD_BCPIO;
-
-#ifdef _PAX_
-/*
- * extraction and creation macros for binary cpio
- */
-#define SHRT_EXT(ch)	((((unsigned)(ch)[0])<<8) | (((unsigned)(ch)[1])&0xff))
-#define RSHRT_EXT(ch)	((((unsigned)(ch)[1])<<8) | (((unsigned)(ch)[0])&0xff))
-#define CHR_WR_0(val)	((char)(((val) >> 24) & 0xff))
-#define CHR_WR_1(val)	((char)(((val) >> 16) & 0xff))
-#define CHR_WR_2(val)	((char)(((val) >> 8) & 0xff))
-#define CHR_WR_3(val)	((char)((val) & 0xff))
-
-/*
- * binary cpio masks and pads
- */
-#define BCPIO_PAD(x)	((2 - ((x) & 1)) & 1)	/* pad to next 2 byte word */
-#define BCPIO_MASK	0xffff			/* mask for dev/ino fields */
-#endif /* _PAX_ */
-
-/*
- * System VR4 cpio header structure (with/without file data crc)
- */
-typedef struct {
-	char	c_magic[6];		/* magic cookie */
-	char	c_ino[8];		/* inode number */
-	char	c_mode[8];		/* file type/access */
-	char	c_uid[8];		/* owners uid */
-	char	c_gid[8];		/* owners gid */
-	char	c_nlink[8];		/* # of links at archive creation */
-	char	c_mtime[8];		/* modification time */
-	char	c_filesize[8];		/* length of file in bytes */
-	char	c_maj[8];		/* block/char major # */
-	char	c_min[8];		/* block/char minor # */
-	char	c_rmaj[8];		/* special file major # */
-	char	c_rmin[8];		/* special file minor # */
-	char	c_namesize[8];		/* length of pathname */
-	char	c_chksum[8];		/* 0 OR CRC of bytes of FILE data */
-} HD_VCPIO;
-
-#define	VMAGIC		070701		/* sVr4 new portable archive id */
-#define	VCMAGIC		070702		/* sVr4 new portable archive id CRC */
-#ifdef _PAX_
-#define	AVMAGIC		"070701"	/* ascii string of above */
-#define	AVCMAGIC	"070702"	/* ascii string of above */
-#define VCPIO_PAD(x)	((4 - ((x) & 3)) & 3)	/* pad to next 4 byte word */
-#define VCPIO_MASK	0xffffffff	/* mask for dev/ino fields */
-#endif /* _PAX_ */
Index: trunk/minix/commands/pax/extern.h
===================================================================
--- trunk/minix/commands/pax/extern.h	(revision 9)
+++ 	(revision )
@@ -1,293 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *	@(#)extern.h	8.2 (Berkeley) 4/18/94
- * $FreeBSD: src/bin/pax/extern.h,v 1.16 2005/01/12 03:25:55 brian Exp $
- */
-
-/*
- * External references from each source file
- */
-
-/*
- * ar_io.c
- */
-extern const char *arcname;
-extern const char *gzip_program;
-int ar_open(const char *);
-void ar_close(void);
-void ar_drain(void);
-int ar_set_wr(void);
-int ar_app_ok(void);
-int ar_read(char *, int);
-int ar_write(char *, int);
-int ar_rdsync(void);
-int ar_fow(off_t, off_t *);
-int ar_rev(off_t );
-int ar_next(void);
-
-/*
- * ar_subs.c
- */
-extern u_long flcnt;
-void list(void);
-void extract(void);
-void append(void);
-void archive(void);
-void copy(void);
-
-/*
- * buf_subs.c
- */
-extern int blksz;
-extern int wrblksz;
-extern int maxflt;
-extern int rdblksz;
-extern off_t wrlimit;
-extern off_t rdcnt;
-extern off_t wrcnt;
-int wr_start(void);
-int rd_start(void);
-void cp_start(void);
-int appnd_start(off_t);
-int rd_sync(void);
-void pback(char *, int);
-int rd_skip(off_t);
-void wr_fin(void);
-int wr_rdbuf(char *, int);
-int rd_wrbuf(char *, int);
-int wr_skip(off_t);
-int wr_rdfile(ARCHD *, int, off_t *);
-int rd_wrfile(ARCHD *, int, off_t *);
-void cp_file(ARCHD *, int, int);
-int buf_fill(void);
-int buf_flush(int);
-
-/*
- * cache.c
- */
-int uidtb_start(void);
-int gidtb_start(void);
-int usrtb_start(void);
-int grptb_start(void);
-const char * name_uid(uid_t, int);
-const char * name_gid(gid_t, int);
-int uid_name(char *, uid_t *);
-int gid_name(char *, gid_t *);
-
-/*
- * cpio.c
- */
-int cpio_strd(void);
-int cpio_trail(ARCHD *);
-int cpio_endwr(void);
-int cpio_id(char *, int);
-int cpio_rd(ARCHD *, char *);
-off_t cpio_endrd(void);
-int cpio_stwr(void);
-int cpio_wr(ARCHD *);
-int vcpio_id(char *, int);
-int crc_id(char *, int);
-int crc_strd(void);
-int vcpio_rd(ARCHD *, char *);
-off_t vcpio_endrd(void);
-int crc_stwr(void);
-int vcpio_wr(ARCHD *);
-int bcpio_id(char *, int);
-int bcpio_rd(ARCHD *, char *);
-off_t bcpio_endrd(void);
-int bcpio_wr(ARCHD *);
-
-/*
- * file_subs.c
- */
-int file_creat(ARCHD *);
-void file_close(ARCHD *, int);
-int lnk_creat(ARCHD *);
-int cross_lnk(ARCHD *);
-int chk_same(ARCHD *);
-int node_creat(ARCHD *);
-int unlnk_exist(char *, int);
-int chk_path(char *, uid_t, gid_t);
-void set_ftime(char *fnm, time_t mtime, time_t atime, int frc);
-int set_ids(char *, uid_t, gid_t);
-int set_lids(char *, uid_t, gid_t);
-void set_pmode(char *, mode_t);
-int file_write(int, char *, int, int *, int *, int, char *);
-void file_flush(int, char *, int);
-void rdfile_close(ARCHD *, int *);
-int set_crc(ARCHD *, int);
-
-/*
- * ftree.c
- */
-int ftree_start(void);
-int ftree_add(char *, int);
-void ftree_sel(ARCHD *);
-void ftree_notsel(void);
-void ftree_chk(void);
-int next_file(ARCHD *);
-
-/*
- * gen_subs.c
- */
-void ls_list(ARCHD *, time_t, FILE *);
-void ls_tty(ARCHD *);
-int l_strncpy(char *, const char *, int);
-u_long asc_ul(char *, int, int);
-int ul_asc(u_long, char *, int, int);
-#ifndef NET2_STAT
-u_quad_t asc_uqd(char *, int, int);
-int uqd_asc(u_quad_t, char *, int, int);
-#endif
-
-/*
- * getoldopt.c
- */
-int getoldopt(int, char **, const char *);
-
-/*
- * options.c
- */
-extern FSUB fsub[];
-extern int ford[];
-void options(int, char **);
-OPLIST * opt_next(void);
-int opt_add(const char *);
-int bad_opt(void);
-char *chdname;
-
-/*
- * pat_rep.c
- */
-int rep_add(char *);
-int pat_add(char *, char *);
-void pat_chk(void);
-int pat_sel(ARCHD *);
-int pat_match(ARCHD *);
-int mod_name(ARCHD *);
-int set_dest(ARCHD *, char *, int);
-
-/*
- * pax.c
- */
-extern int act;
-extern FSUB *frmt;
-extern int cflag;
-extern int cwdfd;
-extern int dflag;
-extern int iflag;
-extern int kflag;
-extern int lflag;
-extern int nflag;
-extern int tflag;
-extern int uflag;
-extern int vflag;
-extern int Dflag;
-extern int Hflag;
-extern int Lflag;
-extern int Xflag;
-extern int Yflag;
-extern int Zflag;
-extern int vfpart;
-extern int patime;
-extern int pmtime;
-extern int nodirs;
-extern int pmode;
-extern int pids;
-extern int rmleadslash;
-extern int exit_val;
-extern int docrc;
-extern char *dirptr;
-extern const char *argv0;
-extern FILE *listf;
-extern char *tempfile;
-extern char *tempbase;
-
-void sig_cleanup(int);
-
-/*
- * sel_subs.c
- */
-int sel_chk(ARCHD *);
-int grp_add(char *);
-int usr_add(char *);
-int trng_add(char *);
-
-/*
- * tables.c
- */
-int lnk_start(void);
-int chk_lnk(ARCHD *);
-void purg_lnk(ARCHD *);
-void lnk_end(void);
-int ftime_start(void);
-int chk_ftime(ARCHD *);
-int name_start(void);
-int add_name(char *, int, char *);
-void sub_name(char *, int *, size_t);
-int dev_start(void);
-int add_dev(ARCHD *);
-int map_dev(ARCHD *, u_long, u_long);
-int atdir_start(void);
-void atdir_end(void);
-void add_atdir(char *, dev_t, ino_t, time_t, time_t);
-int get_atdir(dev_t, ino_t, time_t *, time_t *);
-int dir_start(void);
-void add_dir(char *, int, struct stat *, int);
-void proc_dir(void);
-u_int st_hash(char *, int, int);
-
-/*
- * tar.c
- */
-int tar_endwr(void);
-off_t tar_endrd(void);
-int tar_trail(char *, int, int *);
-int tar_id(char *, int);
-int tar_opt(void);
-int tar_rd(ARCHD *, char *);
-int tar_wr(ARCHD *);
-int ustar_strd(void);
-int ustar_stwr(void);
-int ustar_id(char *, int);
-int ustar_rd(ARCHD *, char *);
-int ustar_wr(ARCHD *);
-
-/*
- * tty_subs.c
- */
-int tty_init(void);
-void tty_prnt(const char *, ...);
-int tty_read(char *, int);
-void paxwarn(int, const char *, ...);
-void syswarn(int, int, const char *, ...);
Index: trunk/minix/commands/pax/fgetln.c
===================================================================
--- trunk/minix/commands/pax/fgetln.c	(revision 9)
+++ 	(revision )
@@ -1,38 +1,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-char *
-fgetln(FILE *fp, size_t *lenp)
-{
-#define EXTRA 80
-	char *buf = NULL;
-	int used = 0, len = 0, remain = 0, final = 0;
-	while(!final) {
-		char *b;
-		int r;
-		if(remain < EXTRA) {
-			int newlen;
-			char *newbuf;
-			newlen = len + EXTRA;
-			if(!(newbuf = realloc(buf, newlen))) {
-				if(buf) free(buf);
-				return NULL;
-			}
-			buf = newbuf;
-			len = newlen;
-			remain += EXTRA;
-		}
-		buf[used] = '\0';
-		if(!fgets(buf + used, remain, fp))
-			break;
-		r = strlen(buf+used);
-		used += r;
-		remain -= r;
-		len += r;
-	}
-	*lenp = len;
-	return buf;
-}
-
Index: trunk/minix/commands/pax/file_subs.c
===================================================================
--- trunk/minix/commands/pax/file_subs.c	(revision 9)
+++ 	(revision )
@@ -1,989 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)file_subs.c	8.1 (Berkeley) 5/31/93";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <utime.h>
-#include <sys/uio.h>
-#include <stdlib.h>
-#include "pax.h"
-#include "options.h"
-#include "extern.h"
-
-static int
-mk_link(char *,struct stat *,char *, int);
-
-/*
- * routines that deal with file operations such as: creating, removing;
- * and setting access modes, uid/gid and times of files
- */
-
-#define FILEBITS		(S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
-#define SETBITS			(S_ISUID | S_ISGID)
-#define ABITS			(FILEBITS | SETBITS)
-
-/*
- * file_creat()
- *	Create and open a file.
- * Return:
- *	file descriptor or -1 for failure
- */
-
-int
-file_creat(ARCHD *arcn)
-{
-	int fd = -1;
-	mode_t file_mode;
-	int oerrno;
-
-	/*
-	 * assume file doesn't exist, so just try to create it, most times this
-	 * works. We have to take special handling when the file does exist. To
-	 * detect this, we use O_EXCL. For example when trying to create a
-	 * file and a character device or fifo exists with the same name, we
-	 * can accidently open the device by mistake (or block waiting to open)
-	 * If we find that the open has failed, then figure spend the effort to
-	 * figure out why. This strategy was found to have better average
-	 * performance in common use than checking the file (and the path)
-	 * first with lstat.
-	 */
-	file_mode = arcn->sb.st_mode & FILEBITS;
-	if ((fd = open(arcn->name, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,
-	    file_mode)) >= 0)
-		return(fd);
-
-	/*
-	 * the file seems to exist. First we try to get rid of it (found to be
-	 * the second most common failure when traced). If this fails, only
-	 * then we go to the expense to check and create the path to the file
-	 */
-	if (unlnk_exist(arcn->name, arcn->type) != 0)
-		return(-1);
-
-	for (;;) {
-		/*
-		 * try to open it again, if this fails, check all the nodes in
-		 * the path and give it a final try. if chk_path() finds that
-		 * it cannot fix anything, we will skip the last attempt
-		 */
-		if ((fd = open(arcn->name, O_WRONLY | O_CREAT | O_TRUNC,
-		    file_mode)) >= 0)
-			break;
-		oerrno = errno;
-		if (nodirs || chk_path(arcn->name,arcn->sb.st_uid,arcn->sb.st_gid) < 0) {
-			syswarn(1, oerrno, "Unable to create %s", arcn->name);
-			return(-1);
-		}
-	}
-	return(fd);
-}
-
-/*
- * file_close()
- *	Close file descriptor to a file just created by pax. Sets modes,
- *	ownership and times as required.
- * Return:
- *	0 for success, -1 for failure
- */
-
-void
-file_close(ARCHD *arcn, int fd)
-{
-	int res = 0;
-
-	if (fd < 0)
-		return;
-	if (close(fd) < 0)
-		syswarn(0, errno, "Unable to close file descriptor on %s",
-		    arcn->name);
-
-	/*
-	 * set owner/groups first as this may strip off mode bits we want
-	 * then set file permission modes. Then set file access and
-	 * modification times.
-	 */
-	if (pids)
-		res = set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid);
-
-	/*
-	 * IMPORTANT SECURITY NOTE:
-	 * if not preserving mode or we cannot set uid/gid, then PROHIBIT
-	 * set uid/gid bits
-	 */
-	if (!pmode || res)
-		arcn->sb.st_mode &= ~(SETBITS);
-	if (pmode)
-		set_pmode(arcn->name, arcn->sb.st_mode);
-	if (patime || pmtime)
-		set_ftime(arcn->name, arcn->sb.st_mtime, arcn->sb.st_atime, 0);
-}
-
-/*
- * lnk_creat()
- *	Create a hard link to arcn->ln_name from arcn->name. arcn->ln_name
- *	must exist;
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-lnk_creat(ARCHD *arcn)
-{
-	struct stat sb;
-
-	/*
-	 * we may be running as root, so we have to be sure that link target
-	 * is not a directory, so we lstat and check
-	 */
-	if (lstat(arcn->ln_name, &sb) < 0) {
-		syswarn(1,errno,"Unable to link to %s from %s", arcn->ln_name,
-		    arcn->name);
-		return(-1);
-	}
-
-	if (S_ISDIR(sb.st_mode)) {
-		paxwarn(1, "A hard link to the directory %s is not allowed",
-		    arcn->ln_name);
-		return(-1);
-	}
-
-	return(mk_link(arcn->ln_name, &sb, arcn->name, 0));
-}
-
-/*
- * cross_lnk()
- *	Create a hard link to arcn->org_name from arcn->name. Only used in copy
- *	with the -l flag. No warning or error if this does not succeed (we will
- *	then just create the file)
- * Return:
- *	1 if copy() should try to create this file node
- *	0 if cross_lnk() ok, -1 for fatal flaw (like linking to self).
- */
-
-int
-cross_lnk(ARCHD *arcn)
-{
-	/*
-	 * try to make a link to original file (-l flag in copy mode). make sure
-	 * we do not try to link to directories in case we are running as root
-	 * (and it might succeed).
-	 */
-	if (arcn->type == PAX_DIR)
-		return(1);
-	return(mk_link(arcn->org_name, &(arcn->sb), arcn->name, 1));
-}
-
-/*
- * chk_same()
- *	In copy mode if we are not trying to make hard links between the src
- *	and destinations, make sure we are not going to overwrite ourselves by
- *	accident. This slows things down a little, but we have to protect all
- *	those people who make typing errors.
- * Return:
- *	1 the target does not exist, go ahead and copy
- *	0 skip it file exists (-k) or may be the same as source file
- */
-
-int
-chk_same(ARCHD *arcn)
-{
-	struct stat sb;
-
-	/*
-	 * if file does not exist, return. if file exists and -k, skip it
-	 * quietly
-	 */
-	if (lstat(arcn->name, &sb) < 0)
-		return(1);
-	if (kflag)
-		return(0);
-
-	/*
-	 * better make sure the user does not have src == dest by mistake
-	 */
-	if ((arcn->sb.st_dev == sb.st_dev) && (arcn->sb.st_ino == sb.st_ino)) {
-		paxwarn(1, "Unable to copy %s, file would overwrite itself",
-		    arcn->name);
-		return(0);
-	}
-	return(1);
-}
-
-/*
- * mk_link()
- *	try to make a hard link between two files. if ign set, we do not
- *	complain.
- * Return:
- *	0 if successful (or we are done with this file but no error, such as
- *	finding the from file exists and the user has set -k).
- *	1 when ign was set to indicates we could not make the link but we
- *	should try to copy/extract the file as that might work (and is an
- *	allowed option). -1 an error occurred.
- */
-
-static int
-mk_link(char *to, struct stat *to_sb, char *from,
-	int ign)
-{
-	struct stat sb;
-	int oerrno;
-
-	/*
-	 * if from file exists, it has to be unlinked to make the link. If the
-	 * file exists and -k is set, skip it quietly
-	 */
-	if (lstat(from, &sb) == 0) {
-		if (kflag)
-			return(0);
-
-		/*
-		 * make sure it is not the same file, protect the user
-		 */
-		if ((to_sb->st_dev==sb.st_dev)&&(to_sb->st_ino == sb.st_ino)) {
-			paxwarn(1, "Unable to link file %s to itself", to);
-			return(-1);;
-		}
-
-		/*
-		 * try to get rid of the file, based on the type
-		 */
-		if (S_ISDIR(sb.st_mode)) {
-			if (rmdir(from) < 0) {
-				syswarn(1, errno, "Unable to remove %s", from);
-				return(-1);
-			}
-		} else if (unlink(from) < 0) {
-			if (!ign) {
-				syswarn(1, errno, "Unable to remove %s", from);
-				return(-1);
-			}
-			return(1);
-		}
-	}
-
-	/*
-	 * from file is gone (or did not exist), try to make the hard link.
-	 * if it fails, check the path and try it again (if chk_path() says to
-	 * try again)
-	 */
-	for (;;) {
-		if (link(to, from) == 0)
-			break;
-		oerrno = errno;
-		if (!nodirs && chk_path(from, to_sb->st_uid, to_sb->st_gid) == 0)
-			continue;
-		if (!ign) {
-			syswarn(1, oerrno, "Could not link to %s from %s", to,
-			    from);
-			return(-1);
-		}
-		return(1);
-	}
-
-	/*
-	 * all right the link was made
-	 */
-	return(0);
-}
-
-/*
- * node_creat()
- *	create an entry in the file system (other than a file or hard link).
- *	If successful, sets uid/gid modes and times as required.
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-node_creat(ARCHD *arcn)
-{
-	int res;
-	int ign = 0;
-	int oerrno;
-	int pass = 0;
-	mode_t file_mode;
-	struct stat sb;
-
-	/*
-	 * create node based on type, if that fails try to unlink the node and
-	 * try again. finally check the path and try again. As noted in the
-	 * file and link creation routines, this method seems to exhibit the
-	 * best performance in general use workloads.
-	 */
-	file_mode = arcn->sb.st_mode & FILEBITS;
-
-	for (;;) {
-		switch(arcn->type) {
-		case PAX_DIR:
-			res = mkdir(arcn->name, file_mode);
-			if (ign)
-				res = 0;
-			break;
-		case PAX_CHR:
-			file_mode |= S_IFCHR;
-			res = mknod(arcn->name, file_mode, arcn->sb.st_rdev);
-			break;
-		case PAX_BLK:
-			file_mode |= S_IFBLK;
-			res = mknod(arcn->name, file_mode, arcn->sb.st_rdev);
-			break;
-		case PAX_FIF:
-			res = mkfifo(arcn->name, file_mode);
-			break;
-		case PAX_SCK:
-			/*
-			 * Skip sockets, operation has no meaning under BSD
-			 */
-			paxwarn(0,
-			    "%s skipped. Sockets cannot be copied or extracted",
-			    arcn->name);
-			return(-1);
-		case PAX_SLK:
-			res = symlink(arcn->ln_name, arcn->name);
-			break;
-		case PAX_CTG:
-		case PAX_HLK:
-		case PAX_HRG:
-		case PAX_REG:
-		default:
-			/*
-			 * we should never get here
-			 */
-			paxwarn(0, "%s has an unknown file type, skipping",
-				arcn->name);
-			return(-1);
-		}
-
-		/*
-		 * if we were able to create the node break out of the loop,
-		 * otherwise try to unlink the node and try again. if that
-		 * fails check the full path and try a final time.
-		 */
-		if (res == 0)
-			break;
-
-		/*
-		 * we failed to make the node
-		 */
-		oerrno = errno;
-		if ((ign = unlnk_exist(arcn->name, arcn->type)) < 0)
-			return(-1);
-
-		if (++pass <= 1)
-			continue;
-
-		if (nodirs || chk_path(arcn->name,arcn->sb.st_uid,arcn->sb.st_gid) < 0) {
-			syswarn(1, oerrno, "Could not create: %s", arcn->name);
-			return(-1);
-		}
-	}
-
-	/*
-	 * we were able to create the node. set uid/gid, modes and times
-	 */
-	if (pids)
-		res = ((arcn->type == PAX_SLK) ?
-		    set_lids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid) :
-		    set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid));
-	else
-		res = 0;
-
-	/*
-	 * symlinks are done now.
-	 */
-	if (arcn->type == PAX_SLK)
-		return(0);
-
-	/*
-	 * IMPORTANT SECURITY NOTE:
-	 * if not preserving mode or we cannot set uid/gid, then PROHIBIT any
-	 * set uid/gid bits
-	 */
-	if (!pmode || res)
-		arcn->sb.st_mode &= ~(SETBITS);
-	if (pmode)
-		set_pmode(arcn->name, arcn->sb.st_mode);
-
-	if (arcn->type == PAX_DIR && strcmp(NM_CPIO, argv0) != 0) {
-		/*
-		 * Dirs must be processed again at end of extract to set times
-		 * and modes to agree with those stored in the archive. However
-		 * to allow extract to continue, we may have to also set owner
-		 * rights. This allows nodes in the archive that are children
-		 * of this directory to be extracted without failure. Both time
-		 * and modes will be fixed after the entire archive is read and
-		 * before pax exits.
-		 */
-		if (access(arcn->name, R_OK | W_OK | X_OK) < 0) {
-			if (lstat(arcn->name, &sb) < 0) {
-				syswarn(0, errno,"Could not access %s (stat)",
-				    arcn->name);
-				set_pmode(arcn->name,file_mode | S_IRWXU);
-			} else {
-				/*
-				 * We have to add rights to the dir, so we make
-				 * sure to restore the mode. The mode must be
-				 * restored AS CREATED and not as stored if
-				 * pmode is not set.
-				 */
-				set_pmode(arcn->name,
-				    ((sb.st_mode & FILEBITS) | S_IRWXU));
-				if (!pmode)
-					arcn->sb.st_mode = sb.st_mode;
-			}
-
-			/*
-			 * we have to force the mode to what was set here,
-			 * since we changed it from the default as created.
-			 */
-			add_dir(arcn->name, arcn->nlen, &(arcn->sb), 1);
-		} else if (pmode || patime || pmtime)
-			add_dir(arcn->name, arcn->nlen, &(arcn->sb), 0);
-	}
-
-	if (patime || pmtime)
-		set_ftime(arcn->name, arcn->sb.st_mtime, arcn->sb.st_atime, 0);
-	return(0);
-}
-
-/*
- * unlnk_exist()
- *	Remove node from file system with the specified name. We pass the type
- *	of the node that is going to replace it. When we try to create a
- *	directory and find that it already exists, we allow processing to
- *	continue as proper modes etc will always be set for it later on.
- * Return:
- *	0 is ok to proceed, no file with the specified name exists
- *	-1 we were unable to remove the node, or we should not remove it (-k)
- *	1 we found a directory and we were going to create a directory.
- */
-
-int
-unlnk_exist(char *name, int type)
-{
-	struct stat sb;
-
-	/*
-	 * the file does not exist, or -k we are done
-	 */
-	if (lstat(name, &sb) < 0)
-		return(0);
-	if (kflag)
-		return(-1);
-
-	if (S_ISDIR(sb.st_mode)) {
-		/*
-		 * try to remove a directory, if it fails and we were going to
-		 * create a directory anyway, tell the caller (return a 1)
-		 */
-		if (rmdir(name) < 0) {
-			if (type == PAX_DIR)
-				return(1);
-			syswarn(1,errno,"Unable to remove directory %s", name);
-			return(-1);
-		}
-		return(0);
-	}
-
-	/*
-	 * try to get rid of all non-directory type nodes
-	 */
-	if (unlink(name) < 0) {
-		syswarn(1, errno, "Could not unlink %s", name);
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * chk_path()
- *	We were trying to create some kind of node in the file system and it
- *	failed. chk_path() makes sure the path up to the node exists and is
- *	writeable. When we have to create a directory that is missing along the
- *	path somewhere, the directory we create will be set to the same
- *	uid/gid as the file has (when uid and gid are being preserved).
- *	NOTE: this routine is a real performance loss. It is only used as a
- *	last resort when trying to create entries in the file system.
- * Return:
- *	-1 when it could find nothing it is allowed to fix.
- *	0 otherwise
- */
-
-int
-chk_path( char *name, uid_t st_uid, gid_t st_gid)
-{
-	char *spt = name;
-	struct stat sb;
-	int retval = -1;
-
-	/*
-	 * watch out for paths with nodes stored directly in / (e.g. /bozo)
-	 */
-	if (*spt == '/')
-		++spt;
-
-	for(;;) {
-		/*
-		 * work foward from the first / and check each part of the path
-		 */
-		spt = strchr(spt, '/');
-		if (spt == NULL)
-			break;
-		*spt = '\0';
-
-		/*
-		 * if it exists we assume it is a directory, it is not within
-		 * the spec (at least it seems to read that way) to alter the
-		 * file system for nodes NOT EXPLICITLY stored on the archive.
-		 * If that assumption is changed, you would test the node here
-		 * and figure out how to get rid of it (probably like some
-		 * recursive unlink()) or fix up the directory permissions if
-		 * required (do an access()).
-		 */
-		if (lstat(name, &sb) == 0) {
-			*(spt++) = '/';
-			continue;
-		}
-
-		/*
-		 * the path fails at this point, see if we can create the
-		 * needed directory and continue on
-		 */
-		if (mkdir(name, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
-			*spt = '/';
-			retval = -1;
-			break;
-		}
-
-		/*
-		 * we were able to create the directory. We will tell the
-		 * caller that we found something to fix, and it is ok to try
-		 * and create the node again.
-		 */
-		retval = 0;
-		if (pids)
-			(void)set_ids(name, st_uid, st_gid);
-
-		/*
-		 * make sure the user doen't have some strange umask that
-		 * causes this newly created directory to be unusable. We fix
-		 * the modes and restore them back to the creation default at
-		 * the end of pax
-		 */
-		if ((access(name, R_OK | W_OK | X_OK) < 0) &&
-		    (lstat(name, &sb) == 0)) {
-			set_pmode(name, ((sb.st_mode & FILEBITS) | S_IRWXU));
-			add_dir(name, spt - name, &sb, 1);
-		}
-		*(spt++) = '/';
-		continue;
-	}
-	return(retval);
-}
-
-/*
- * set_ftime()
- *	Set the access time and modification time for a named file. If frc is
- *	non-zero we force these times to be set even if the user did not
- *	request access and/or modification time preservation (this is also
- *	used by -t to reset access times).
- *	When ign is zero, only those times the user has asked for are set, the
- *	other ones are left alone. We do not assume the un-documented feature
- *	of many utimes() implementations that consider a 0 time value as a do
- *	not set request.
- */
-
-void
-set_ftime(char *fnm, time_t mtime, time_t atime, int frc)
-{
-#if 0
-	static struct timeval tv[2] = {{0L, 0L}, {0L, 0L}};
-#endif
-	struct stat sb;
-	struct utimbuf ut;
-
-#if 0
-	tv[0].tv_sec = atime;
-	tv[1].tv_sec = mtime;
-#endif
-
-	ut.actime = atime;
-	ut.modtime = mtime;
-
-	if (!frc && (!patime || !pmtime)) {
-		/*
-		 * if we are not forcing, only set those times the user wants
-		 * set. We get the current values of the times if we need them.
-		 */
-		if (lstat(fnm, &sb) == 0) {
-			if (!patime)
-				ut.actime = sb.st_atime;
-			if (!pmtime)
-				ut.modtime = sb.st_mtime;
-		} else
-			syswarn(0,errno,"Unable to obtain file stats %s", fnm);
-	}
-
-	/*
-	 * set the times
-	 */
-	if (utime(fnm, &ut) < 0)
-		syswarn(1, errno, "Access/modification time set failed on: %s",
-		    fnm);
-	return;
-}
-
-/*
- * set_ids()
- *	set the uid and gid of a file system node
- * Return:
- *	0 when set, -1 on failure
- */
-
-int
-set_ids(char *fnm, uid_t uid, gid_t gid)
-{
-	if (chown(fnm, uid, gid) < 0) {
-		/*
-		 * ignore EPERM unless in verbose mode or being run by root.
-		 * if running as pax, POSIX requires a warning.
-		 */
-		if (strcmp(NM_PAX, argv0) == 0 || errno != EPERM || vflag ||
-		    geteuid() == 0)
-			syswarn(1, errno, "Unable to set file uid/gid of %s",
-			    fnm);
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * set_lids()
- *	set the uid and gid of a file system node
- * Return:
- *	0 when set, -1 on failure
- */
-
-int
-set_lids(char *fnm, uid_t uid, gid_t gid)
-{
-
-#if 0
-	if (lchown(fnm, uid, gid) < 0) {
-		/*
-		 * ignore EPERM unless in verbose mode or being run by root.
-		 * if running as pax, POSIX requires a warning.
-		 */
-		if (strcmp(NM_PAX, argv0) == 0 || errno != EPERM || vflag ||
-		    geteuid() == 0)
-			syswarn(1, errno, "Unable to set file uid/gid of %s",
-			    fnm);
-		return(-1);
-	}
-#else
-	return(-1);	/* No lchown() in minix. */
-#endif
-	return(0);
-}
-
-/*
- * set_pmode()
- *	Set file access mode
- */
-
-void
-set_pmode(char *fnm, mode_t mode)
-{
-	mode &= ABITS;
-	if (chmod(fnm, mode) < 0)
-		syswarn(1, errno, "Could not set permissions on %s", fnm);
-	return;
-}
-
-/*
- * file_write()
- *	Write/copy a file (during copy or archive extract). This routine knows
- *	how to copy files with lseek holes in it. (Which are read as file
- *	blocks containing all 0's but do not have any file blocks associated
- *	with the data). Typical examples of these are files created by dbm
- *	variants (.pag files). While the file size of these files are huge, the
- *	actual storage is quite small (the files are sparse). The problem is
- *	the holes read as all zeros so are probably stored on the archive that
- *	way (there is no way to determine if the file block is really a hole,
- *	we only know that a file block of all zero's can be a hole).
- *	At this writing, no major archive format knows how to archive files
- *	with holes. However, on extraction (or during copy, -rw) we have to
- *	deal with these files. Without detecting the holes, the files can
- *	consume a lot of file space if just written to disk. This replacement
- *	for write when passed the basic allocation size of a file system block,
- *	uses lseek whenever it detects the input data is all 0 within that
- *	file block. In more detail, the strategy is as follows:
- *	While the input is all zero keep doing an lseek. Keep track of when we
- *	pass over file block boundries. Only write when we hit a non zero
- *	input. once we have written a file block, we continue to write it to
- *	the end (we stop looking at the input). When we reach the start of the
- *	next file block, start checking for zero blocks again. Working on file
- *	block boundries significantly reduces the overhead when copying files
- *	that are NOT very sparse. This overhead (when compared to a write) is
- *	almost below the measurement resolution on many systems. Without it,
- *	files with holes cannot be safely copied. It does has a side effect as
- *	it can put holes into files that did not have them before, but that is
- *	not a problem since the file contents are unchanged (in fact it saves
- *	file space). (Except on paging files for diskless clients. But since we
- *	cannot determine one of those file from here, we ignore them). If this
- *	ever ends up on a system where CTG files are supported and the holes
- *	are not desired, just do a conditional test in those routines that
- *	call file_write() and have it call write() instead. BEFORE CLOSING THE
- *	FILE, make sure to call file_flush() when the last write finishes with
- *	an empty block. A lot of file systems will not create an lseek hole at
- *	the end. In this case we drop a single 0 at the end to force the
- *	trailing 0's in the file.
- *	---Parameters---
- *	rem: how many bytes left in this file system block
- *	isempt: have we written to the file block yet (is it empty)
- *	sz: basic file block allocation size
- *	cnt: number of bytes on this write
- *	str: buffer to write
- * Return:
- *	number of bytes written, -1 on write (or lseek) error.
- */
-
-int
-file_write(int fd, char *str, int cnt, int *rem, int *isempt, int sz,
-	char *name)
-{
-	char *pt;
-	char *end;
-	int wcnt;
-	char *st = str;
-
-	/*
-	 * while we have data to process
-	 */
-	while (cnt) {
-		if (!*rem) {
-			/*
-			 * We are now at the start of file system block again
-			 * (or what we think one is...). start looking for
-			 * empty blocks again
-			 */
-			*isempt = 1;
-			*rem = sz;
-		}
-
-		/*
-		 * only examine up to the end of the current file block or
-		 * remaining characters to write, whatever is smaller
-		 */
-		wcnt = MIN(cnt, *rem);
-		cnt -= wcnt;
-		*rem -= wcnt;
-		if (*isempt) {
-			/*
-			 * have not written to this block yet, so we keep
-			 * looking for zero's
-			 */
-			pt = st;
-			end = st + wcnt;
-
-			/*
-			 * look for a zero filled buffer
-			 */
-			while ((pt < end) && (*pt == '\0'))
-				++pt;
-
-			if (pt == end) {
-				/*
-				 * skip, buf is empty so far
-				 */
-				if (lseek(fd, (off_t)wcnt, SEEK_CUR) < 0) {
-					syswarn(1,errno,"File seek on %s",
-					    name);
-					return(-1);
-				}
-				st = pt;
-				continue;
-			}
-			/*
-			 * drat, the buf is not zero filled
-			 */
-			*isempt = 0;
-		}
-
-		/*
-		 * have non-zero data in this file system block, have to write
-		 */
-		if (write(fd, st, wcnt) != wcnt) {
-			syswarn(1, errno, "Failed write to file %s", name);
-			return(-1);
-		}
-		st += wcnt;
-	}
-	return(st - str);
-}
-
-/*
- * file_flush()
- *	when the last file block in a file is zero, many file systems will not
- *	let us create a hole at the end. To get the last block with zeros, we
- *	write the last BYTE with a zero (back up one byte and write a zero).
- */
-
-void
-file_flush(int fd, char *fname, int isempt)
-{
-	static char blnk[] = "\0";
-
-	/*
-	 * silly test, but make sure we are only called when the last block is
-	 * filled with all zeros.
-	 */
-	if (!isempt)
-		return;
-
-	/*
-	 * move back one byte and write a zero
-	 */
-	if (lseek(fd, (off_t)-1, SEEK_CUR) < 0) {
-		syswarn(1, errno, "Failed seek on file %s", fname);
-		return;
-	}
-
-	if (write(fd, blnk, 1) < 0)
-		syswarn(1, errno, "Failed write to file %s", fname);
-	return;
-}
-
-/*
- * rdfile_close()
- *	close a file we have beed reading (to copy or archive). If we have to
- *	reset access time (tflag) do so (the times are stored in arcn).
- */
-
-void
-rdfile_close(ARCHD *arcn, int *fd)
-{
-	/*
-	 * make sure the file is open
-	 */
-	if (*fd < 0)
-		return;
-
-	(void)close(*fd);
-	*fd = -1;
-	if (!tflag)
-		return;
-
-	/*
-	 * user wants last access time reset
-	 */
-	set_ftime(arcn->org_name, arcn->sb.st_mtime, arcn->sb.st_atime, 1);
-	return;
-}
-
-/*
- * set_crc()
- *	read a file to calculate its crc. This is a real drag. Archive formats
- *	that have this, end up reading the file twice (we have to write the
- *	header WITH the crc before writing the file contents. Oh well...
- * Return:
- *	0 if was able to calculate the crc, -1 otherwise
- */
-
-int
-set_crc(ARCHD *arcn, int fd)
-{
-	int i;
-	int res;
-	off_t cpcnt = 0L;
-	u_long size;
-	unsigned long crc = 0L;
-	char tbuf[FILEBLK];
-	struct stat sb;
-
-	if (fd < 0) {
-		/*
-		 * hmm, no fd, should never happen. well no crc then.
-		 */
-		arcn->crc = 0L;
-		return(0);
-	}
-
-#if 0
-	/* not in minix */
-	if ((size = (u_long)arcn->sb.st_blksize) > (u_long)sizeof(tbuf))
-		size = (u_long)sizeof(tbuf);
-#endif
-
-	/*
-	 * read all the bytes we think that there are in the file. If the user
-	 * is trying to archive an active file, forget this file.
-	 */
-	for(;;) {
-		if ((res = read(fd, tbuf, size)) <= 0)
-			break;
-		cpcnt += res;
-		for (i = 0; i < res; ++i)
-			crc += (tbuf[i] & 0xff);
-	}
-
-	/*
-	 * safety check. we want to avoid archiving files that are active as
-	 * they can create inconsistant archive copies.
-	 */
-	if (cpcnt != arcn->sb.st_size)
-		paxwarn(1, "File changed size %s", arcn->org_name);
-	else if (fstat(fd, &sb) < 0)
-		syswarn(1, errno, "Failed stat on %s", arcn->org_name);
-	else if (arcn->sb.st_mtime != sb.st_mtime)
-		paxwarn(1, "File %s was modified during read", arcn->org_name);
-	else if (lseek(fd, (off_t)0L, SEEK_SET) < 0)
-		syswarn(1, errno, "File rewind failed on: %s", arcn->org_name);
-	else {
-		arcn->crc = crc;
-		return(0);
-	}
-	return(-1);
-}
Index: trunk/minix/commands/pax/ftree.c
===================================================================
--- trunk/minix/commands/pax/ftree.c	(revision 9)
+++ 	(revision )
@@ -1,535 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)ftree.c	8.2 (Berkeley) 4/18/94";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <fts.h>
-#include "pax.h"
-#include "ftree.h"
-#include "extern.h"
-
-/*
- * routines to interface with the fts library function.
- *
- * file args supplied to pax are stored on a single linked list (of type FTREE)
- * and given to fts to be processed one at a time. pax "selects" files from
- * the expansion of each arg into the corresponding file tree (if the arg is a
- * directory, otherwise the node itself is just passed to pax). The selection
- * is modified by the -n and -u flags. The user is informed when a specific
- * file arg does not generate any selected files. -n keeps expanding the file
- * tree arg until one of its files is selected, then skips to the next file
- * arg. when the user does not supply the file trees as command line args to
- * pax, they are read from stdin
- */
-
-static FTS *ftsp = NULL;		/* current FTS handle */
-static int ftsopts;			/* options to be used on fts_open */
-static char *farray[2];			/* array for passing each arg to fts */
-static FTREE *fthead = NULL;		/* head of linked list of file args */
-static FTREE *fttail = NULL;		/* tail of linked list of file args */
-static FTREE *ftcur = NULL;		/* current file arg being processed */
-static FTSENT *ftent = NULL;		/* current file tree entry */
-static int ftree_skip;			/* when set skip to next file arg */
-
-static int ftree_arg(void);
-
-/*
- * ftree_start()
- *	initialize the options passed to fts_open() during this run of pax
- *	options are based on the selection of pax options by the user
- *	fts_start() also calls fts_arg() to open the first valid file arg. We
- *	also attempt to reset directory access times when -t (tflag) is set.
- * Return:
- *	0 if there is at least one valid file arg to process, -1 otherwise
- */
-
-int
-ftree_start(void)
-{
-	/*
-	 * Set up the operation mode of fts, open the first file arg. We must
-	 * use FTS_NOCHDIR, as the user may have to open multiple archives and
-	 * if fts did a chdir off into the boondocks, we may create an archive
-	 * volume in a place where the user did not expect to.
-	 */
-	ftsopts = FTS_NOCHDIR;
-
-	/*
-	 * optional user flags that effect file traversal
-	 * -H command line symlink follow only (half follow)
-	 * -L follow sylinks (logical)
-	 * -P do not follow sylinks (physical). This is the default.
-	 * -X do not cross over mount points
-	 * -t preserve access times on files read.
-	 * -n select only the first member of a file tree when a match is found
-	 * -d do not extract subtrees rooted at a directory arg.
-	 */
-	if (Lflag)
-		ftsopts |= FTS_LOGICAL;
-	else
-		ftsopts |= FTS_PHYSICAL;
-	if (Hflag)
-#	ifdef NET2_FTS
-		paxwarn(0, "The -H flag is not supported on this version");
-#	else
-		ftsopts |= FTS_COMFOLLOW;
-#	endif
-	if (Xflag)
-		ftsopts |= FTS_XDEV;
-
-	if ((fthead == NULL) && ((farray[0] = malloc(PAXPATHLEN+2)) == NULL)) {
-		paxwarn(1, "Unable to allocate memory for file name buffer");
-		return(-1);
-	}
-
-	if (ftree_arg() < 0)
-		return(-1);
-	if (tflag && (atdir_start() < 0))
-		return(-1);
-	return(0);
-}
-
-/*
- * ftree_add()
- *	add the arg to the linked list of files to process. Each will be
- *	processed by fts one at a time
- * Return:
- *	0 if added to the linked list, -1 if failed
- */
-
-int
-ftree_add(char *str, int chflg)
-{
-	FTREE *ft;
-	int len;
-
-	/*
-	 * simple check for bad args
-	 */
-	if ((str == NULL) || (*str == '\0')) {
-		paxwarn(0, "Invalid file name argument");
-		return(-1);
-	}
-
-	/*
-	 * allocate FTREE node and add to the end of the linked list (args are
-	 * processed in the same order they were passed to pax). Get rid of any
-	 * trailing / the user may pass us. (watch out for / by itself).
-	 */
-	if ((ft = (FTREE *)malloc(sizeof(FTREE))) == NULL) {
-		paxwarn(0, "Unable to allocate memory for filename");
-		return(-1);
-	}
-
-	if (((len = strlen(str) - 1) > 0) && (str[len] == '/'))
-		str[len] = '\0';
-	ft->fname = str;
-	ft->refcnt = 0;
-	ft->chflg = chflg;
-	ft->fow = NULL;
-	if (fthead == NULL) {
-		fttail = fthead = ft;
-		return(0);
-	}
-	fttail->fow = ft;
-	fttail = ft;
-	return(0);
-}
-
-/*
- * ftree_sel()
- *	this entry has been selected by pax. bump up reference count and handle
- *	-n and -d processing.
- */
-
-void
-ftree_sel(ARCHD *arcn)
-{
-	/*
-	 * set reference bit for this pattern. This linked list is only used
-	 * when file trees are supplied pax as args. The list is not used when
-	 * the trees are read from stdin.
-	 */
-	if (ftcur != NULL)
-		ftcur->refcnt = 1;
-
-	/*
-	 * if -n we are done with this arg, force a skip to the next arg when
-	 * pax asks for the next file in next_file().
-	 * if -d we tell fts only to match the directory (if the arg is a dir)
-	 * and not the entire file tree rooted at that point.
-	 */
-	if (nflag)
-		ftree_skip = 1;
-
-	if (!dflag || (arcn->type != PAX_DIR))
-		return;
-
-	if (ftent != NULL)
-		(void)fts_set(ftsp, ftent, FTS_SKIP);
-}
-
-/*
- * ftree_notsel()
- *	this entry has not been selected by pax.
- */
-
-void
-ftree_notsel()
-{
-	if (ftent != NULL)
-		(void)fts_set(ftsp, ftent, FTS_SKIP);
-}
-
-/*
- * ftree_chk()
- *	called at end on pax execution. Prints all those file args that did not
- *	have a selected member (reference count still 0)
- */
-
-void
-ftree_chk(void)
-{
-	FTREE *ft;
-	int wban = 0;
-
-	/*
-	 * make sure all dir access times were reset.
-	 */
-	if (tflag)
-		atdir_end();
-
-	/*
-	 * walk down list and check reference count. Print out those members
-	 * that never had a match
-	 */
-	for (ft = fthead; ft != NULL; ft = ft->fow) {
-		if ((ft->refcnt > 0) || ft->chflg)
-			continue;
-		if (wban == 0) {
-			paxwarn(1,"WARNING! These file names were not selected:");
-			++wban;
-		}
-		(void)fprintf(stderr, "%s\n", ft->fname);
-	}
-}
-
-/*
- * ftree_arg()
- *	Get the next file arg for fts to process. Can be from either the linked
- *	list or read from stdin when the user did not them as args to pax. Each
- *	arg is processed until the first successful fts_open().
- * Return:
- *	0 when the next arg is ready to go, -1 if out of file args (or EOF on
- *	stdin).
- */
-
-static int
-ftree_arg(void)
-{
-	char *pt;
-
-	/*
-	 * close off the current file tree
-	 */
-	if (ftsp != NULL) {
-		(void)fts_close(ftsp);
-		ftsp = NULL;
-	}
-
-	/*
-	 * keep looping until we get a valid file tree to process. Stop when we
-	 * reach the end of the list (or get an eof on stdin)
-	 */
-	for(;;) {
-		if (fthead == NULL) {
-			/*
-			 * the user didn't supply any args, get the file trees
-			 * to process from stdin;
-			 */
-			if (fgets(farray[0], PAXPATHLEN+1, stdin) == NULL)
-				return(-1);
-			if ((pt = strchr(farray[0], '\n')) != NULL)
-				*pt = '\0';
-		} else {
-			/*
-			 * the user supplied the file args as arguments to pax
-			 */
-			if (ftcur == NULL)
-				ftcur = fthead;
-			else if ((ftcur = ftcur->fow) == NULL)
-				return(-1);
-			if (ftcur->chflg) {
-				/* First fchdir() back... */
-				if (fchdir(cwdfd) < 0) {
-					syswarn(1, errno,
-					  "Can't fchdir to starting directory");
-					return(-1);
-				}
-				if (chdir(ftcur->fname) < 0) {
-					syswarn(1, errno, "Can't chdir to %s",
-					    ftcur->fname);
-					return(-1);
-				}
-				continue;
-			} else
-				farray[0] = ftcur->fname;
-		}
-
-		/*
-		 * Watch it, fts wants the file arg stored in an array of char
-		 * ptrs, with the last one a null. We use a two element array
-		 * and set farray[0] to point at the buffer with the file name
-		 * in it. We cannot pass all the file args to fts at one shot
-		 * as we need to keep a handle on which file arg generates what
-		 * files (the -n and -d flags need this). If the open is
-		 * successful, return a 0.
-		 */
-		if ((ftsp = fts_open(farray, ftsopts, NULL)) != NULL)
-			break;
-	}
-	return(0);
-}
-
-/*
- * next_file()
- *	supplies the next file to process in the supplied archd structure.
- * Return:
- *	0 when contents of arcn have been set with the next file, -1 when done.
- */
-
-int
-next_file(ARCHD *arcn)
-{
-	int cnt;
-	time_t atime;
-	time_t mtime;
-
-	/*
-	 * ftree_sel() might have set the ftree_skip flag if the user has the
-	 * -n option and a file was selected from this file arg tree. (-n says
-	 * only one member is matched for each pattern) ftree_skip being 1
-	 * forces us to go to the next arg now.
-	 */
-	if (ftree_skip) {
-		/*
-		 * clear and go to next arg
-		 */
-		ftree_skip = 0;
-		if (ftree_arg() < 0)
-			return(-1);
-	}
-
-	/*
-	 * loop until we get a valid file to process
-	 */
-	for(;;) {
-		if ((ftent = fts_read(ftsp)) == NULL) {
-			/*
-			 * out of files in this tree, go to next arg, if none
-			 * we are done
-			 */
-			if (ftree_arg() < 0)
-				return(-1);
-			continue;
-		}
-
-		/*
-		 * handle each type of fts_read() flag
-		 */
-		switch(ftent->fts_info) {
-		case FTS_D:
-		case FTS_DEFAULT:
-		case FTS_F:
-		case FTS_SL:
-		case FTS_SLNONE:
-			/*
-			 * these are all ok
-			 */
-			break;
-		case FTS_DP:
-			/*
-			 * already saw this directory. If the user wants file
-			 * access times reset, we use this to restore the
-			 * access time for this directory since this is the
-			 * last time we will see it in this file subtree
-			 * remember to force the time (this is -t on a read
-			 * directory, not a created directory).
-			 */
-#			ifdef NET2_FTS
-			if (!tflag || (get_atdir(ftent->fts_statb.st_dev,
-			    ftent->fts_statb.st_ino, &mtime, &atime) < 0))
-#			else
-			if (!tflag || (get_atdir(ftent->fts_statp->st_dev,
-			    ftent->fts_statp->st_ino, &mtime, &atime) < 0))
-#			endif
-				continue;
-			set_ftime(ftent->fts_path, mtime, atime, 1);
-			continue;
-		case FTS_DC:
-			/*
-			 * fts claims a file system cycle
-			 */
-			paxwarn(1,"File system cycle found at %s",ftent->fts_path);
-			continue;
-		case FTS_DNR:
-#			ifdef NET2_FTS
-			syswarn(1, errno,
-#			else
-			syswarn(1, ftent->fts_errno,
-#			endif
-			    "Unable to read directory %s", ftent->fts_path);
-			continue;
-		case FTS_ERR:
-#			ifdef NET2_FTS
-			syswarn(1, errno,
-#			else
-			syswarn(1, ftent->fts_errno,
-#			endif
-			    "File system traversal error");
-			continue;
-		case FTS_NS:
-		case FTS_NSOK:
-#			ifdef NET2_FTS
-			syswarn(1, errno,
-#			else
-			syswarn(1, ftent->fts_errno,
-#			endif
-			    "Unable to access %s", ftent->fts_path);
-			continue;
-		}
-
-		/*
-		 * ok got a file tree node to process. copy info into arcn
-		 * structure (initialize as required)
-		 */
-		arcn->skip = 0;
-		arcn->pad = 0;
-		arcn->ln_nlen = 0;
-		arcn->ln_name[0] = '\0';
-#		ifdef NET2_FTS
-		arcn->sb = ftent->fts_statb;
-#		else
-		arcn->sb = *(ftent->fts_statp);
-#		endif
-
-		/*
-		 * file type based set up and copy into the arcn struct
-		 * SIDE NOTE:
-		 * we try to reset the access time on all files and directories
-		 * we may read when the -t flag is specified. files are reset
-		 * when we close them after copying. we reset the directories
-		 * when we are done with their file tree (we also clean up at
-		 * end in case we cut short a file tree traversal). However
-		 * there is no way to reset access times on symlinks.
-		 */
-		switch(S_IFMT & arcn->sb.st_mode) {
-		case S_IFDIR:
-			arcn->type = PAX_DIR;
-			if (!tflag)
-				break;
-			add_atdir(ftent->fts_path, arcn->sb.st_dev,
-			    arcn->sb.st_ino, arcn->sb.st_mtime,
-			    arcn->sb.st_atime);
-			break;
-		case S_IFCHR:
-			arcn->type = PAX_CHR;
-			break;
-		case S_IFBLK:
-			arcn->type = PAX_BLK;
-			break;
-		case S_IFREG:
-			/*
-			 * only regular files with have data to store on the
-			 * archive. all others will store a zero length skip.
-			 * the skip field is used by pax for actual data it has
-			 * to read (or skip over).
-			 */
-			arcn->type = PAX_REG;
-			arcn->skip = arcn->sb.st_size;
-			break;
-		case S_IFLNK:
-			arcn->type = PAX_SLK;
-			/*
-			 * have to read the symlink path from the file
-			 */
-			if ((cnt = readlink(ftent->fts_path, arcn->ln_name,
-			    PAXPATHLEN - 1)) < 0) {
-				syswarn(1, errno, "Unable to read symlink %s",
-				    ftent->fts_path);
-				continue;
-			}
-			/*
-			 * set link name length, watch out readlink does not
-			 * always NUL terminate the link path
-			 */
-			arcn->ln_name[cnt] = '\0';
-			arcn->ln_nlen = cnt;
-			break;
-#if 0
-		case S_IFSOCK:
-			/*
-			 * under BSD storing a socket is senseless but we will
-			 * let the format specific write function make the
-			 * decision of what to do with it.
-			 */
-			arcn->type = PAX_SCK;
-			break;
-#endif
-		case S_IFIFO:
-			arcn->type = PAX_FIF;
-			break;
-		}
-		break;
-	}
-
-	/*
-	 * copy file name, set file name length
-	 */
-	arcn->nlen = l_strncpy(arcn->name, ftent->fts_path, sizeof(arcn->name) - 1);
-	arcn->name[arcn->nlen] = '\0';
-	arcn->org_name = ftent->fts_path;
-	return(0);
-}
Index: trunk/minix/commands/pax/ftree.h
===================================================================
--- trunk/minix/commands/pax/ftree.h	(revision 9)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *	@(#)ftree.h	8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/bin/pax/ftree.h,v 1.7 2004/04/06 20:06:48 markm Exp $
- */
-
-/*
- * Data structure used by the ftree.c routines to store the file args to be
- * handed to fts(). It keeps a reference count of which args generated a
- * "selected" member
- */
-
-typedef struct ftree {
-	char		*fname;		/* file tree name */
-	int		refcnt;		/* has tree had a selected file? */
-	int		chflg;		/* change directory flag */
-	struct ftree	*fow;		/* pointer to next entry on list */
-} FTREE;
Index: trunk/minix/commands/pax/gen_subs.c
===================================================================
--- trunk/minix/commands/pax/gen_subs.c	(revision 9)
+++ 	(revision )
@@ -1,414 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)gen_subs.c	8.1 (Berkeley) 5/31/93";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <utmp.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "pax.h"
-#include "extern.h"
-
-/*
- * a collection of general purpose subroutines used by pax
- */
-
-/*
- * constants used by ls_list() when printing out archive members
- */
-#define MODELEN 20
-#define DATELEN 64
-#define SIXMONTHS	 ((365 / 2) * 86400)
-#define CURFRMTM	"%b %e %H:%M"
-#define OLDFRMTM	"%b %e  %Y"
-#define CURFRMTD	"%e %b %H:%M"
-#define OLDFRMTD	"%e %b  %Y"
-#ifndef UT_NAMESIZE
-#define UT_NAMESIZE	8
-#endif
-#define UT_GRPSIZE	6
-
-static int d_first = -1;
-
-/*
- * ls_list()
- *	list the members of an archive in ls format
- */
-
-void
-ls_list(ARCHD *arcn, time_t now, FILE *fp)
-{
-	struct stat *sbp;
-	char f_mode[MODELEN];
-	char f_date[DATELEN];
-	const char *timefrmt;
-
-	/*
-	 * if not verbose, just print the file name
-	 */
-	if (!vflag) {
-		(void)fprintf(fp, "%s\n", arcn->name);
-		(void)fflush(fp);
-		return;
-	}
-
-	if (d_first < 0)
-		d_first = 0;
-	/*
-	 * user wants long mode
-	 */
-	sbp = &(arcn->sb);
-#if 0
-	strmode(sbp->st_mode, f_mode);
-#else
-	strcpy(f_mode, "");
-#endif
-
-	/*
-	 * time format based on age compared to the time pax was started.
-	 */
-	if ((sbp->st_mtime + SIXMONTHS) <= now)
-		timefrmt = d_first ? OLDFRMTD : OLDFRMTM;
-	else
-		timefrmt = d_first ? CURFRMTD : CURFRMTM;
-
-	/*
-	 * print file mode, link count, uid, gid and time
-	 */
-#if 0
-	if (strftime(f_date,DATELEN,timefrmt,localtime(&(sbp->st_mtime))) == 0)
-#endif
-		f_date[0] = '\0';
-	(void)fprintf(fp, "%s%2u %-*s %-*s ", f_mode, sbp->st_nlink,
-		UT_NAMESIZE, name_uid(sbp->st_uid, 1), UT_GRPSIZE,
-		name_gid(sbp->st_gid, 1));
-
-	/*
-	 * print device id's for devices, or sizes for other nodes
-	 */
-	if ((arcn->type == PAX_CHR) || (arcn->type == PAX_BLK))
-#		ifdef NET2_STAT
-		(void)fprintf(fp, "%4u,%4u ", major(sbp->st_rdev),
-		    minor(sbp->st_rdev));
-#		else
-		(void)fprintf(fp, "%4lu,%4lu ", (unsigned long)major(sbp->st_rdev),
-		    (unsigned long)minor(sbp->st_rdev));
-#		endif
-	else {
-#		ifdef NET2_STAT
-		(void)fprintf(fp, "%9lu ", sbp->st_size);
-#		else
-		(void)fprintf(fp, "%9ju ", (uintmax_t)sbp->st_size);
-#		endif
-	}
-
-	/*
-	 * print name and link info for hard and soft links
-	 */
-	(void)fprintf(fp, "%s %s", f_date, arcn->name);
-	if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))
-		(void)fprintf(fp, " == %s\n", arcn->ln_name);
-	else if (arcn->type == PAX_SLK)
-		(void)fprintf(fp, " => %s\n", arcn->ln_name);
-	else
-		(void)putc('\n', fp);
-	(void)fflush(fp);
-	return;
-}
-
-/*
- * tty_ls()
- * 	print a short summary of file to tty.
- */
-
-void
-ls_tty(ARCHD *arcn)
-{
-	char f_date[DATELEN];
-	char f_mode[MODELEN];
-	const char *timefrmt;
-
-	if (d_first < 0)
-		d_first = 0;
-
-	if ((arcn->sb.st_mtime + SIXMONTHS) <= time(NULL))
-		timefrmt = d_first ? OLDFRMTD : OLDFRMTM;
-	else
-		timefrmt = d_first ? CURFRMTD : CURFRMTM;
-
-	/*
-	 * convert time to string, and print
-	 */
-#if 0
-	if (strftime(f_date, DATELEN, timefrmt,
-	    localtime(&(arcn->sb.st_mtime))) == 0)
-#endif
-		f_date[0] = '\0';
-#if 0
-	strmode(arcn->sb.st_mode, f_mode);
-#else
-	strcpy(f_mode, "");
-#endif
-	tty_prnt("%s%s %s\n", f_mode, f_date, arcn->name);
-	return;
-}
-
-/*
- * l_strncpy()
- *	copy src to dest up to len chars (stopping at first '\0').
- *	when src is shorter than len, pads to len with '\0'. 
- * Return:
- *	number of chars copied. (Note this is a real performance win over
- *	doing a strncpy(), a strlen(), and then a possible memset())
- */
-
-int
-l_strncpy(char *dest, const char *src, int len)
-{
-	char *stop;
-	char *start;
-
-	stop = dest + len;
-	start = dest;
-	while ((dest < stop) && (*src != '\0'))
-		*dest++ = *src++;
-	len = dest - start;
-	while (dest < stop)
-		*dest++ = '\0';
-	return(len);
-}
-
-/*
- * asc_ul()
- *	convert hex/octal character string into a u_long. We do not have to
- *	check for overflow! (the headers in all supported formats are not large
- *	enough to create an overflow).
- *	NOTE: strings passed to us are NOT TERMINATED.
- * Return:
- *	unsigned long value
- */
-
-u_long
-asc_ul(char *str, int len, int base)
-{
-	char *stop;
-	u_long tval = 0;
-
-	stop = str + len;
-
-	/*
-	 * skip over leading blanks and zeros
-	 */
-	while ((str < stop) && ((*str == ' ') || (*str == '0')))
-		++str;
-
-	/*
-	 * for each valid digit, shift running value (tval) over to next digit
-	 * and add next digit
-	 */
-	if (base == HEX) {
-		while (str < stop) {
-			if ((*str >= '0') && (*str <= '9'))
-				tval = (tval << 4) + (*str++ - '0');
-			else if ((*str >= 'A') && (*str <= 'F'))
-				tval = (tval << 4) + 10 + (*str++ - 'A');
-			else if ((*str >= 'a') && (*str <= 'f'))
-				tval = (tval << 4) + 10 + (*str++ - 'a');
-			else
-				break;
-		}
-	} else {
- 		while ((str < stop) && (*str >= '0') && (*str <= '7'))
-			tval = (tval << 3) + (*str++ - '0');
-	}
-	return(tval);
-}
-
-/*
- * ul_asc()
- *	convert an unsigned long into an hex/oct ascii string. pads with LEADING
- *	ascii 0's to fill string completely
- *	NOTE: the string created is NOT TERMINATED.
- */
-
-int
-ul_asc(u_long val, char *str, int len, int base)
-{
-	char *pt;
-	u_long digit;
-
-	/*
-	 * WARNING str is not '\0' terminated by this routine
-	 */
-	pt = str + len - 1;
-
-	/*
-	 * do a tailwise conversion (start at right most end of string to place
-	 * least significant digit). Keep shifting until conversion value goes
-	 * to zero (all digits were converted)
-	 */
-	if (base == HEX) {
-		while (pt >= str) {
-			if ((digit = (val & 0xf)) < 10)
-				*pt-- = '0' + (char)digit;
-			else
-				*pt-- = 'a' + (char)(digit - 10);
-			if ((val = (val >> 4)) == (u_long)0)
-				break;
-		}
-	} else {
-		while (pt >= str) {
-			*pt-- = '0' + (char)(val & 0x7);
-			if ((val = (val >> 3)) == (u_long)0)
-				break;
-		}
-	}
-
-	/*
-	 * pad with leading ascii ZEROS. We return -1 if we ran out of space.
-	 */
-	while (pt >= str)
-		*pt-- = '0';
-	if (val != (u_long)0)
-		return(-1);
-	return(0);
-}
-
-#ifndef NET2_STAT
-/*
- * asc_uqd()
- *	convert hex/octal character string into a u_quad_t. We do not have to
- *	check for overflow! (the headers in all supported formats are not large
- *	enough to create an overflow).
- *	NOTE: strings passed to us are NOT TERMINATED.
- * Return:
- *	u_quad_t value
- */
-
-u_quad_t
-asc_uqd(char *str, int len, int base)
-{
-	char *stop;
-	u_quad_t tval = 0;
-
-	stop = str + len;
-
-	/*
-	 * skip over leading blanks and zeros
-	 */
-	while ((str < stop) && ((*str == ' ') || (*str == '0')))
-		++str;
-
-	/*
-	 * for each valid digit, shift running value (tval) over to next digit
-	 * and add next digit
-	 */
-	if (base == HEX) {
-		while (str < stop) {
-			if ((*str >= '0') && (*str <= '9'))
-				tval = (tval << 4) + (*str++ - '0');
-			else if ((*str >= 'A') && (*str <= 'F'))
-				tval = (tval << 4) + 10 + (*str++ - 'A');
-			else if ((*str >= 'a') && (*str <= 'f'))
-				tval = (tval << 4) + 10 + (*str++ - 'a');
-			else
-				break;
-		}
-	} else {
- 		while ((str < stop) && (*str >= '0') && (*str <= '7'))
-			tval = (tval << 3) + (*str++ - '0');
-	}
-	return(tval);
-}
-
-/*
- * uqd_asc()
- *	convert an u_quad_t into a hex/oct ascii string. pads with LEADING
- *	ascii 0's to fill string completely
- *	NOTE: the string created is NOT TERMINATED.
- */
-
-int
-uqd_asc(u_quad_t val, char *str, int len, int base)
-{
-	char *pt;
-	u_quad_t digit;
-
-	/*
-	 * WARNING str is not '\0' terminated by this routine
-	 */
-	pt = str + len - 1;
-
-	/*
-	 * do a tailwise conversion (start at right most end of string to place
-	 * least significant digit). Keep shifting until conversion value goes
-	 * to zero (all digits were converted)
-	 */
-	if (base == HEX) {
-		while (pt >= str) {
-			if ((digit = (val & 0xf)) < 10)
-				*pt-- = '0' + (char)digit;
-			else
-				*pt-- = 'a' + (char)(digit - 10);
-			if ((val = (val >> 4)) == (u_quad_t)0)
-				break;
-		}
-	} else {
-		while (pt >= str) {
-			*pt-- = '0' + (char)(val & 0x7);
-			if ((val = (val >> 3)) == (u_quad_t)0)
-				break;
-		}
-	}
-
-	/*
-	 * pad with leading ascii ZEROS. We return -1 if we ran out of space.
-	 */
-	while (pt >= str)
-		*pt-- = '0';
-	if (val != (u_quad_t)0)
-		return(-1);
-	return(0);
-}
-#endif
Index: trunk/minix/commands/pax/getoldopt.c
===================================================================
--- trunk/minix/commands/pax/getoldopt.c	(revision 9)
+++ 	(revision )
@@ -1,70 +1,0 @@
-/*	$OpenBSD: getoldopt.c,v 1.4 2000/01/22 20:24:51 deraadt Exp $	*/
-/*	$NetBSD: getoldopt.c,v 1.3 1995/03/21 09:07:28 cgd Exp $	*/
-
-/*-
- * Plug-compatible replacement for getopt() for parsing tar-like
- * arguments.  If the first argument begins with "-", it uses getopt;
- * otherwise, it uses the old rules used by tar, dump, and ps.
- *
- * Written 25 August 1985 by John Gilmore (ihnp4!hoptoad!gnu) and placed
- * in the Pubic Domain for your edification and enjoyment.
- */
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "pax.h"
-#include "extern.h"
-
-int
-getoldopt(int argc, char **argv, const char *optstring)
-{
-	static char	*key;		/* Points to next keyletter */
-	static char	use_getopt;	/* !=0 if argv[1][0] was '-' */
-	char		c;
-	char		*place;
-
-	optarg = NULL;
-
-	if (key == NULL) {		/* First time */
-		if (argc < 2) return EOF;
-		key = argv[1];
-		if (*key == '-')
-			use_getopt++;
-		else
-			optind = 2;
-	}
-
-	if (use_getopt)
-		return getopt(argc, argv, optstring);
-
-	c = *key++;
-	if (c == '\0') {
-		key--;
-		return EOF;
-	}
-	place = strchr(optstring, c);
-
-	if (place == NULL || c == ':') {
-		fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
-		return('?');
-	}
-
-	place++;
-	if (*place == ':') {
-		if (optind < argc) {
-			optarg = argv[optind];
-			optind++;
-		} else {
-			fprintf(stderr, "%s: %c argument missing\n",
-				argv[0], c);
-			return('?');
-		}
-	}
-
-	return(c);
-}
Index: trunk/minix/commands/pax/options.c
===================================================================
--- trunk/minix/commands/pax/options.c	(revision 9)
+++ 	(revision )
@@ -1,1591 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#define _POSIX_SOURCE 1
-#define _MINIX 1
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)options.c	8.2 (Berkeley) 4/18/94";
-#endif /* not lint */
-#endif
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mtio.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <minix/paths.h>
-
-#include <sys/types.h>
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-
-
-#include "pax.h"
-#include "options.h"
-#include "cpio.h"
-#include "tar.h"
-#include "extern.h"
-
-/*
- * Routines which handle command line options
- */
-
-static char flgch[] = FLGCH;	/* list of all possible flags */
-static OPLIST *ophead = NULL;	/* head for format specific options -x */
-static OPLIST *optail = NULL;	/* option tail */
-
-static int no_op(void);
-static void printflg(unsigned int);
-static int c_frmt(const void *, const void *);
-static off_t str_offt(char *);
-static char *getline(FILE *fp);
-static void pax_options(int, char **);
-static void pax_usage(void);
-static void tar_options(int, char **);
-static void tar_usage(void);
-static void cpio_options(int, char **);
-static void cpio_usage(void);
-
-/* errors from getline */
-#define GETLINE_FILE_CORRUPT 1
-#define GETLINE_OUT_OF_MEM 2
-static int getline_error;
-
-
-#define GZIP_CMD	"gzip"		/* command to run as gzip */
-#define COMPRESS_CMD	"compress"	/* command to run as compress */
-#define BZIP2_CMD	"bzip2"		/* command to run as gzip */
-
-/*
- *	Format specific routine table - MUST BE IN SORTED ORDER BY NAME
- *	(see pax.h for description of each function)
- *
- * 	name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
- *	read, end_read, st_write, write, end_write, trail,
- *	rd_data, wr_data, options
- */
-
-FSUB fsub[] = {
-/* 0: OLD BINARY CPIO */
-	{"bcpio", 5120, sizeof(HD_BCPIO), 1, 0, 0, 1, bcpio_id, cpio_strd,
-	bcpio_rd, bcpio_endrd, cpio_stwr, bcpio_wr, cpio_endwr, cpio_trail,
-	NULL, rd_wrfile, wr_rdfile, bad_opt},
-
-/* 1: OLD OCTAL CHARACTER CPIO */
-	{"cpio", 5120, sizeof(HD_CPIO), 1, 0, 0, 1, cpio_id, cpio_strd,
-	cpio_rd, cpio_endrd, cpio_stwr, cpio_wr, cpio_endwr, cpio_trail,
-	NULL, rd_wrfile, wr_rdfile, bad_opt},
-
-/* 2: SVR4 HEX CPIO */
-	{"sv4cpio", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, vcpio_id, cpio_strd,
-	vcpio_rd, vcpio_endrd, cpio_stwr, vcpio_wr, cpio_endwr, cpio_trail,
-	NULL, rd_wrfile, wr_rdfile, bad_opt},
-
-/* 3: SVR4 HEX CPIO WITH CRC */
-	{"sv4crc", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd,
-	vcpio_rd, vcpio_endrd, crc_stwr, vcpio_wr, cpio_endwr, cpio_trail,
-	NULL, rd_wrfile, wr_rdfile, bad_opt},
-
-/* 4: OLD TAR */
-	{"tar", 10240, BLKMULT, 0, 1, BLKMULT, 0, tar_id, no_op,
-	tar_rd, tar_endrd, no_op, tar_wr, tar_endwr, NULL, tar_trail,
-	rd_wrfile, wr_rdfile, tar_opt},
-
-/* 5: POSIX USTAR */
-	{"ustar", 10240, BLKMULT, 0, 1, BLKMULT, 0, ustar_id, ustar_strd,
-	ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, NULL, tar_trail,
-	rd_wrfile, wr_rdfile, bad_opt},
-};
-#define F_OCPIO	0	/* format when called as cpio -6 */
-#define F_ACPIO	1	/* format when called as cpio -c */
-#define F_CPIO	3	/* format when called as cpio */
-#define F_OTAR	4	/* format when called as tar -o */
-#define F_TAR	5	/* format when called as tar */
-#define DEFLT	5	/* default write format from list above */
-
-/*
- * ford is the archive search order used by get_arc() to determine what kind
- * of archive we are dealing with. This helps to properly id  archive formats
- * some formats may be subsets of others....
- */
-int ford[] = {5, 4, 3, 2, 1, 0, -1 };
-
-/*
- * options()
- *	figure out if we are pax, tar or cpio. Call the appropriate options
- *	parser
- */
-
-void
-options(int argc, char **argv)
-{
-
-	/*
-	 * Are we acting like pax, tar or cpio (based on argv[0])
-	 */
-	if ((argv0 = strrchr(argv[0], '/')) != NULL)
-		argv0++;
-	else
-		argv0 = argv[0];
-
-	if (strcmp(NM_TAR, argv0) == 0) {
-		tar_options(argc, argv);
-		return;
-	}
-	else if (strcmp(NM_CPIO, argv0) == 0) {
-		cpio_options(argc, argv);
-		return;
-	}
-	/*
-	 * assume pax as the default
-	 */
-	argv0 = NM_PAX;
-	pax_options(argc, argv);
-	return;
-}
-
-/*
- * pax_options()
- *	look at the user specified flags. set globals as required and check if
- *	the user specified a legal set of flags. If not, complain and exit
- */
-
-static void
-pax_options(int argc, char **argv)
-{
-	int c;
-	size_t i;
-	unsigned int flg = 0;
-	unsigned int bflg = 0;
-	char *pt;
-	FSUB tmp;
-
-	/*
-	 * process option flags
-	 */
-	while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLPT:U:XYZ"))
-	    != -1) {
-		switch (c) {
-		case 'a':
-			/*
-			 * append
-			 */
-			flg |= AF;
-			break;
-		case 'b':
-			/*
-			 * specify blocksize
-			 */
-			flg |= BF;
-			if ((wrblksz = (int)str_offt(optarg)) <= 0) {
-				paxwarn(1, "Invalid block size %s", optarg);
-				pax_usage();
-			}
-			break;
-		case 'c':
-			/*
-			 * inverse match on patterns
-			 */
-			cflag = 1;
-			flg |= CF;
-			break;
-		case 'd':
-			/*
-			 * match only dir on extract, not the subtree at dir
-			 */
-			dflag = 1;
-			flg |= DF;
-			break;
-		case 'f':
-			/*
-			 * filename where the archive is stored
-			 */
-			arcname = optarg;
-			flg |= FF;
-			break;
-		case 'i':
-			/*
-			 * interactive file rename
-			 */
-			iflag = 1;
-			flg |= IF;
-			break;
-		case 'k':
-			/*
-			 * do not clobber files that exist
-			 */
-			kflag = 1;
-			flg |= KF;
-			break;
-		case 'l':
-			/*
-			 * try to link src to dest with copy (-rw)
-			 */
-			lflag = 1;
-			flg |= LF;
-			break;
-		case 'n':
-			/*
-			 * select first match for a pattern only
-			 */
-			nflag = 1;
-			flg |= NF;
-			break;
-		case 'o':
-			/*
-			 * pass format specific options
-			 */
-			flg |= OF;
-			if (opt_add(optarg) < 0)
-				pax_usage();
-			break;
-		case 'p':
-			/*
-			 * specify file characteristic options
-			 */
-			for (pt = optarg; *pt != '\0'; ++pt) {
-				switch(*pt) {
-				case 'a':
-					/*
-					 * do not preserve access time
-					 */
-					patime = 0;
-					break;
-				case 'e':
-					/*
-					 * preserve user id, group id, file
-					 * mode, access/modification times
-					 */
-					pids = 1;
-					pmode = 1;
-					patime = 1;
-					pmtime = 1;
-					break;
-				case 'm':
-					/*
-					 * do not preserve modification time
-					 */
-					pmtime = 0;
-					break;
-				case 'o':
-					/*
-					 * preserve uid/gid
-					 */
-					pids = 1;
-					break;
-				case 'p':
-					/*
-					 * preserver file mode bits
-					 */
-					pmode = 1;
-					break;
-				default:
-					paxwarn(1, "Invalid -p string: %c", *pt);
-					pax_usage();
-					break;
-				}
-			}
-			flg |= PF;
-			break;
-		case 'r':
-			/*
-			 * read the archive
-			 */
-			flg |= RF;
-			break;
-		case 's':
-			/*
-			 * file name substitution name pattern
-			 */
-			if (rep_add(optarg) < 0) {
-				pax_usage();
-				break;
-			}
-			flg |= SF;
-			break;
-		case 't':
-			/*
-			 * preserve access time on file system nodes we read
-			 */
-			tflag = 1;
-			flg |= TF;
-			break;
-		case 'u':
-			/*
-			 * ignore those older files
-			 */
-			uflag = 1;
-			flg |= UF;
-			break;
-		case 'v':
-			/*
-			 * verbose operation mode
-			 */
-			vflag = 1;
-			flg |= VF;
-			break;
-		case 'w':
-			/*
-			 * write an archive
-			 */
-			flg |= WF;
-			break;
-		case 'x':
-			/*
-			 * specify an archive format on write
-			 */
-			tmp.name = optarg;
-			if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
-			    sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL) {
-				flg |= XF;
-				break;
-			}
-			paxwarn(1, "Unknown -x format: %s", optarg);
-			(void)fputs("pax: Known -x formats are:", stderr);
-			for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
-				(void)fprintf(stderr, " %s", fsub[i].name);
-			(void)fputs("\n\n", stderr);
-			pax_usage();
-			break;
-		case 'z':
-			/*
-			 * use gzip.  Non standard option.
-			 */
-			gzip_program = GZIP_CMD;
-			break;
-		case 'B':
-			/*
-			 * non-standard option on number of bytes written on a
-			 * single archive volume.
-			 */
-			if ((wrlimit = str_offt(optarg)) <= 0) {
-				paxwarn(1, "Invalid write limit %s", optarg);
-				pax_usage();
-			}
-			if (wrlimit % BLKMULT) {
-				paxwarn(1, "Write limit is not a %d byte multiple",
-				    BLKMULT);
-				pax_usage();
-			}
-			flg |= CBF;
-			break;
-		case 'D':
-			/*
-			 * On extraction check file inode change time before the
-			 * modification of the file name. Non standard option.
-			 */
-			Dflag = 1;
-			flg |= CDF;
-			break;
-		case 'E':
-			/*
-			 * non-standard limit on read faults
-			 * 0 indicates stop after first error, values
-			 * indicate a limit, "NONE" try forever
-			 */
-			flg |= CEF;
-			if (strcmp(NONE, optarg) == 0)
-				maxflt = -1;
-			else if ((maxflt = atoi(optarg)) < 0) {
-				paxwarn(1, "Error count value must be positive");
-				pax_usage();
-			}
-			break;
-		case 'G':
-			/*
-			 * non-standard option for selecting files within an
-			 * archive by group (gid or name)
-			 */
-			if (grp_add(optarg) < 0) {
-				pax_usage();
-				break;
-			}
-			flg |= CGF;
-			break;
-		case 'H':
-			/*
-			 * follow command line symlinks only
-			 */
-			Hflag = 1;
-			flg |= CHF;
-			break;
-		case 'L':
-			/*
-			 * follow symlinks
-			 */
-			Lflag = 1;
-			flg |= CLF;
-			break;
-		case 'P':
-			/*
-			 * do NOT follow symlinks (default)
-			 */
-			Lflag = 0;
-			flg |= CPF;
-			break;
-		case 'T':
-			/*
-			 * non-standard option for selecting files within an
-			 * archive by modification time range (lower,upper)
-			 */
-			if (trng_add(optarg) < 0) {
-				pax_usage();
-				break;
-			}
-			flg |= CTF;
-			break;
-		case 'U':
-			/*
-			 * non-standard option for selecting files within an
-			 * archive by user (uid or name)
-			 */
-			if (usr_add(optarg) < 0) {
-				pax_usage();
-				break;
-			}
-			flg |= CUF;
-			break;
-		case 'X':
-			/*
-			 * do not pass over mount points in the file system
-			 */
-			Xflag = 1;
-			flg |= CXF;
-			break;
-		case 'Y':
-			/*
-			 * On extraction check file inode change time after the
-			 * modification of the file name. Non standard option.
-			 */
-			Yflag = 1;
-			flg |= CYF;
-			break;
-		case 'Z':
-			/*
-			 * On extraction check modification time after the
-			 * modification of the file name. Non standard option.
-			 */
-			Zflag = 1;
-			flg |= CZF;
-			break;
-		default:
-			pax_usage();
-			break;
-		}
-	}
-
-	/*
-	 * figure out the operation mode of pax read,write,extract,copy,append
-	 * or list. check that we have not been given a bogus set of flags
-	 * for the operation mode.
-	 */
-	if (ISLIST(flg)) {
-		act = LIST;
-		listf = stdout;
-		bflg = flg & BDLIST;
-	} else if (ISEXTRACT(flg)) {
-		act = EXTRACT;
-		bflg = flg & BDEXTR;
-	} else if (ISARCHIVE(flg)) {
-		act = ARCHIVE;
-		bflg = flg & BDARCH;
-	} else if (ISAPPND(flg)) {
-		act = APPND;
-		bflg = flg & BDARCH;
-	} else if (ISCOPY(flg)) {
-		act = COPY;
-		bflg = flg & BDCOPY;
-	} else
-		pax_usage();
-	if (bflg) {
-		printflg(flg);
-		pax_usage();
-	}
-
-	/*
-	 * if we are writing (ARCHIVE) we use the default format if the user
-	 * did not specify a format. when we write during an APPEND, we will
-	 * adopt the format of the existing archive if none was supplied.
-	 */
-	if (!(flg & XF) && (act == ARCHIVE))
-		frmt = &(fsub[DEFLT]);
-
-	/*
-	 * process the args as they are interpreted by the operation mode
-	 */
-	switch (act) {
-	case LIST:
-	case EXTRACT:
-		for (; optind < argc; optind++)
-			if (pat_add(argv[optind], NULL) < 0)
-				pax_usage();
-		break;
-	case COPY:
-		if (optind >= argc) {
-			paxwarn(0, "Destination directory was not supplied");
-			pax_usage();
-		}
-		--argc;
-		dirptr = argv[argc];
-		/* FALLTHROUGH */
-	case ARCHIVE:
-	case APPND:
-		for (; optind < argc; optind++)
-			if (ftree_add(argv[optind], 0) < 0)
-				pax_usage();
-		/*
-		 * no read errors allowed on updates/append operation!
-		 */
-		maxflt = 0;
-		break;
-	}
-}
-
-
-/*
- * tar_options()
- *	look at the user specified flags. set globals as required and check if
- *	the user specified a legal set of flags. If not, complain and exit
- */
-
-static void
-tar_options(int argc, char **argv)
-{
-	int c;
-	int fstdin = 0;
-	int Oflag = 0;
-	int nincfiles = 0;
-	int incfiles_max = 0;
-	struct incfile {
-		char *file;
-		char *dir;
-	};
-	struct incfile *incfiles = NULL;
-
-	/*
-	 * Set default values.
-	 */
-	rmleadslash = 1;
-
-	/*
-	 * process option flags
-	 */
-	while ((c = getoldopt(argc, argv,
-	    "b:cef:hjmopqruts:vwxyzBC:HI:LOPXZ014578")) != -1) {
-		switch(c) {
-		case 'b':
-			/*
-			 * specify blocksize in 512-byte blocks
-			 */
-			if ((wrblksz = (int)str_offt(optarg)) <= 0) {
-				paxwarn(1, "Invalid block size %s", optarg);
-				tar_usage();
-			}
-			wrblksz *= 512;		/* XXX - check for int oflow */
-			break;
-		case 'c':
-			/*
-			 * create an archive
-			 */
-			act = ARCHIVE;
-			break;
-		case 'e':
-			/*
-			 * stop after first error
-			 */
-			maxflt = 0;
-			break;
-		case 'f':
-			/*
-			 * filename where the archive is stored
-			 */
-			if ((optarg[0] == '-') && (optarg[1]== '\0')) {
-				/*
-				 * treat a - as stdin
-				 */
-				fstdin = 1;
-				arcname = NULL;
-				break;
-			}
-			fstdin = 0;
-			arcname = optarg;
-			break;
-		case 'h':
-			/*
-			 * follow symlinks
-			 */
-			Lflag = 1;
-			break;
-		case 'j':
-		case 'y':
-			/*
-			 * use bzip2.  Non standard option.
-			 */
-			gzip_program = BZIP2_CMD;
-			break;
-		case 'm':
-			/*
-			 * do not preserve modification time
-			 */
-			pmtime = 0;
-			break;
-		case 'o':
-			if (opt_add("write_opt=nodir") < 0)
-				tar_usage();
-		case 'O':
-			Oflag = 1;
-			break;
-		case 'p':
-			/*
-			 * preserve uid/gid and file mode, regardless of umask
-			 */
-			pmode = 1;
-			pids = 1;
-			break;
-		case 'q':
-			/*
-			 * select first match for a pattern only
-			 */
-			nflag = 1;
-			break;
-		case 'r':
-		case 'u':
-			/*
-			 * append to the archive
-			 */
-			act = APPND;
-			break;
-		case 's':
-			/*
-			 * file name substitution name pattern
-			 */
-			if (rep_add(optarg) < 0) {
-				tar_usage();
-				break;
-			}
-			break;
-		case 't':
-			/*
-			 * list contents of the tape
-			 */
-			act = LIST;
-			break;
-		case 'v':
-			/*
-			 * verbose operation mode
-			 */
-			vflag++;
-			break;
-		case 'w':
-			/*
-			 * interactive file rename
-			 */
-			iflag = 1;
-			break;
-		case 'x':
-			/*
-			 * extract an archive, preserving mode,
-			 * and mtime if possible.
-			 */
-			act = EXTRACT;
-			pmtime = 1;
-			break;
-		case 'z':
-			/*
-			 * use gzip.  Non standard option.
-			 */
-			gzip_program = GZIP_CMD;
-			break;
-		case 'B':
-			/*
-			 * Nothing to do here, this is pax default
-			 */
-			break;
-		case 'C':
-			chdname = optarg;
-			break;
-		case 'H':
-			/*
-			 * follow command line symlinks only
-			 */
-			Hflag = 1;
-			break;
-		case 'I':
-			if (++nincfiles > incfiles_max) {
-				incfiles_max = nincfiles + 3;
-				incfiles = realloc(incfiles,
-				    sizeof(*incfiles) * incfiles_max);
-				if (incfiles == NULL) {
-					paxwarn(0, "Unable to allocate space "
-					    "for option list");
-					exit(1);
-				}
-			}
-			incfiles[nincfiles - 1].file = optarg;
-			incfiles[nincfiles - 1].dir = chdname;
-			break;
-		case 'L':
-			/*
-			 * follow symlinks
-			 */
-			Lflag = 1;
-			break;
-		case 'P':
-			/*
-			 * do not remove leading '/' from pathnames
-			 */
-			rmleadslash = 0;
-			break;
-		case 'X':
-			/*
-			 * do not pass over mount points in the file system
-			 */
-			Xflag = 1;
-			break;
-		case 'Z':
-			/*
-			 * use compress.
-			 */
-			gzip_program = COMPRESS_CMD;
-			break;
-		case '0':
-			arcname = DEV_0;
-			break;
-		case '1':
-			arcname = DEV_1;
-			break;
-		case '4':
-			arcname = DEV_4;
-			break;
-		case '5':
-			arcname = DEV_5;
-			break;
-		case '7':
-			arcname = DEV_7;
-			break;
-		case '8':
-			arcname = DEV_8;
-			break;
-		default:
-			tar_usage();
-			break;
-		}
-	}
-	argc -= optind;
-	argv += optind;
-
-	/* Traditional tar behaviour (pax uses stderr unless in list mode) */
-	if (fstdin == 1 && act == ARCHIVE)
-		listf = stderr;
-	else
-		listf = stdout;
-
-	/* Traditional tar behaviour (pax wants to read file list from stdin) */
-	if ((act == ARCHIVE || act == APPND) && argc == 0 && nincfiles == 0)
-		exit(0);
-
-	/*
-	 * if we are writing (ARCHIVE) specify tar, otherwise run like pax
-	 * (unless -o specified)
-	 */
-	if (act == ARCHIVE || act == APPND)
-		frmt = &(fsub[Oflag ? F_OTAR : F_TAR]);
-	else if (Oflag) {
-		paxwarn(1, "The -O/-o options are only valid when writing an archive");
-		tar_usage();		/* only valid when writing */
-	}
-
-	/*
-	 * process the args as they are interpreted by the operation mode
-	 */
-	switch (act) {
-	case LIST:
-	case EXTRACT:
-	default:
-		{
-			int sawpat = 0;
-			char *file, *dir = NULL;
-
-			while (nincfiles || *argv != NULL) {
-				/*
-				 * If we queued up any include files,
-				 * pull them in now.  Otherwise, check
-				 * for -I and -C positional flags.
-				 * Anything else must be a file to
-				 * extract.
-				 */
-				if (nincfiles) {
-					file = incfiles->file;
-					dir = incfiles->dir;
-					incfiles++;
-					nincfiles--;
-				} else if (strcmp(*argv, "-I") == 0) {
-					if (*++argv == NULL)
-						break;
-					file = *argv++;
-					dir = chdname;
-				} else
-					file = NULL;
-				if (file != NULL) {
-					FILE *fp;
-					char *str;
-
-					if (strcmp(file, "-") == 0)
-						fp = stdin;
-					else if ((fp = fopen(file, "r")) == NULL) {
-						paxwarn(1, "Unable to open file '%s' for read", file);
-						tar_usage();
-					}
-					while ((str = getline(fp)) != NULL) {
-						if (pat_add(str, dir) < 0)
-							tar_usage();
-						sawpat = 1;
-					}
-					if (strcmp(file, "-") != 0)
-						fclose(fp);
-					if (getline_error) {
-						paxwarn(1, "Problem with file '%s'", file);
-						tar_usage();
-					}
-				} else if (strcmp(*argv, "-C") == 0) {
-					if (*++argv == NULL)
-						break;
-					chdname = *argv++;
-				} else if (pat_add(*argv++, chdname) < 0)
-					tar_usage();
-				else
-					sawpat = 1;
-			}
-			/*
-			 * if patterns were added, we are doing	chdir()
-			 * on a file-by-file basis, else, just one
-			 * global chdir (if any) after opening input.
-			 */
-			if (sawpat > 0)
-				chdname = NULL;	
-		}
-		break;
-	case ARCHIVE:
-	case APPND:
-		if (chdname != NULL) {	/* initial chdir() */
-			if (ftree_add(chdname, 1) < 0)
-				tar_usage();
-		}
-
-		while (nincfiles || *argv != NULL) {
-			char *file, *dir = NULL;
-
-			/*
-			 * If we queued up any include files, pull them in
-			 * now.  Otherwise, check for -I and -C positional
-			 * flags.  Anything else must be a file to include
-			 * in the archive.
-			 */
-			if (nincfiles) {
-				file = incfiles->file;
-				dir = incfiles->dir;
-				incfiles++;
-				nincfiles--;
-			} else if (strcmp(*argv, "-I") == 0) {
-				if (*++argv == NULL)
-					break;
-				file = *argv++;
-				dir = NULL;
-			} else
-				file = NULL;
-			if (file != NULL) {
-				FILE *fp;
-				char *str;
-
-				/* Set directory if needed */
-				if (dir) {
-					if (ftree_add(dir, 1) < 0)
-						tar_usage();
-				}
-
-				if (strcmp(file, "-") == 0)
-					fp = stdin;
-				else if ((fp = fopen(file, "r")) == NULL) {
-					paxwarn(1, "Unable to open file '%s' for read", file);
-					tar_usage();
-				}
-				while ((str = getline(fp)) != NULL) {
-					if (ftree_add(str, 0) < 0)
-						tar_usage();
-				}
-				if (strcmp(file, "-") != 0)
-					fclose(fp);
-				if (getline_error) {
-					paxwarn(1, "Problem with file '%s'",
-					    file);
-					tar_usage();
-				}
-			} else if (strcmp(*argv, "-C") == 0) {
-				if (*++argv == NULL)
-					break;
-				if (ftree_add(*argv++, 1) < 0)
-					tar_usage();
-			} else if (ftree_add(*argv++, 0) < 0)
-				tar_usage();
-		}
-		/*
-		 * no read errors allowed on updates/append operation!
-		 */
-		maxflt = 0;
-		break;
-	}
-	if (!fstdin && ((arcname == NULL) || (*arcname == '\0'))) {
-		arcname = getenv("TAPE");
-		if ((arcname == NULL) || (*arcname == '\0'))
-			arcname = _PATH_DEFTAPE;
-	}
-}
-
-static int
-mkpath(char *path)
-{
-	struct stat sb;
-	char *slash;
-	int done = 0;
-
-	slash = path;
-
-	while (!done) {
-		slash += strspn(slash, "/");
-		slash += strcspn(slash, "/");
-
-		done = (*slash == '\0');
-		*slash = '\0';
-
-		if (stat(path, &sb)) {
-			if (errno != ENOENT || mkdir(path, 0777)) {
-				paxwarn(1, "%s", path);
-				return (-1);
-			}
-		} else if (!S_ISDIR(sb.st_mode)) {
-			syswarn(1, ENOTDIR, "%s", path);
-			return (-1);
-		}
-
-		if (!done)
-			*slash = '/';
-	}
-
-	return (0);
-}
-/*
- * cpio_options()
- *	look at the user specified flags. set globals as required and check if
- *	the user specified a legal set of flags. If not, complain and exit
- */
-
-static void
-cpio_options(int argc, char **argv)
-{
-	int c;
-	size_t i;
-	char *str;
-	FSUB tmp;
-	FILE *fp;
-
-	kflag = 1;
-	pids = 1;
-	pmode = 1;
-	pmtime = 0;
-	arcname = NULL;
-	dflag = 1;
-	act = -1;
-	nodirs = 1;
-	while ((c=getopt(argc,argv,"abcdfiklmoprstuvzABC:E:F:H:I:LO:SZ6")) != -1)
-		switch (c) {
-			case 'a':
-				/*
-				 * preserve access time on files read
-				 */
-				tflag = 1;
-				break;
-			case 'b':
-				/*
-				 * swap bytes and half-words when reading data
-				 */
-				break;
-			case 'c':
-				/*
-				 * ASCII cpio header
-				 */
-				frmt = &(fsub[F_ACPIO]);
-				break;
-			case 'd':
-				/*
-				 * create directories as needed
-				 */
-				nodirs = 0;
-				break;
-			case 'f':
-				/*
-				 * invert meaning of pattern list
-				 */
-				cflag = 1;
-				break;
-			case 'i':
-				/*
-				 * restore an archive
-				 */
-				act = EXTRACT;
-				break;
-			case 'k':
-				break;
-			case 'l':
-				/*
-				 * use links instead of copies when possible
-				 */
-				lflag = 1;
-				break;
-			case 'm':
-				/*
-				 * preserve modification time
-				 */
-				pmtime = 1;
-				break;
-			case 'o':
-				/*
-				 * create an archive
-				 */
-				act = ARCHIVE;
-				frmt = &(fsub[F_CPIO]);
-				break;
-			case 'p':
-				/*
-				 * copy-pass mode
-				 */
-				act = COPY;
-				break;
-			case 'r':
-				/*
-				 * interactively rename files
-				 */
-				iflag = 1;
-				break;
-			case 's':
-				/*
-				 * swap bytes after reading data
-				 */
-				break;
-			case 't':
-				/*
-				 * list contents of archive
-				 */
-				act = LIST;
-				listf = stdout;
-				break;
-			case 'u':
-				/*
-				 * replace newer files
-				 */
-				kflag = 0;
-				break;
-			case 'v':
-				/*
-				 * verbose operation mode
-				 */
-				vflag = 1;
-				break;
-			case 'z':
-				/*
-				 * use gzip.  Non standard option.
-				 */
-				gzip_program = GZIP_CMD;
-				break;
-			case 'A':
-				/*
-				 * append mode
-				 */
-				act = APPND;
-				break;
-			case 'B':
-				/*
-				 * Use 5120 byte block size
-				 */
-				wrblksz = 5120;
-				break;
-			case 'C':
-				/*
-				 * set block size in bytes
-				 */
-				wrblksz = atoi(optarg);
-				break;
-			case 'E':
-				/*
-				 * file with patterns to extract or list
-				 */
-				if ((fp = fopen(optarg, "r")) == NULL) {
-					paxwarn(1, "Unable to open file '%s' for read", optarg);
-					cpio_usage();
-				}
-				while ((str = getline(fp)) != NULL) {
-					pat_add(str, NULL);
-				}
-				fclose(fp);
-				if (getline_error) {
-					paxwarn(1, "Problem with file '%s'", optarg);
-					cpio_usage();
-				}
-				break;
-			case 'F':
-			case 'I':
-			case 'O':
-				/*
-				 * filename where the archive is stored
-				 */
-				if ((optarg[0] == '-') && (optarg[1]== '\0')) {
-					/*
-					 * treat a - as stdin
-					 */
-					arcname = NULL;
-					break;
-				}
-				arcname = optarg;
-				break;
-			case 'H':
-				/*
-				 * specify an archive format on write
-				 */
-				tmp.name = optarg;
-				if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
-				    sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL)
-					break;
-				paxwarn(1, "Unknown -H format: %s", optarg);
-				(void)fputs("cpio: Known -H formats are:", stderr);
-				for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
-					(void)fprintf(stderr, " %s", fsub[i].name);
-				(void)fputs("\n\n", stderr);
-				cpio_usage();
-				break;
-			case 'L':
-				/*
-				 * follow symbolic links
-				 */
-				Lflag = 1;
-				break;
-			case 'S':
-				/*
-				 * swap halfwords after reading data
-				 */
-				break;
-			case 'Z':
-				/*
-				 * use compress.  Non standard option.
-				 */
-				gzip_program = COMPRESS_CMD;
-				break;
-			case '6':
-				/*
-				 * process Version 6 cpio format
-				 */
-				frmt = &(fsub[F_OCPIO]);
-				break;
-			case '?':
-			default:
-				cpio_usage();
-				break;
-		}
-	argc -= optind;
-	argv += optind;
-
-	/*
-	 * process the args as they are interpreted by the operation mode
-	 */
-	switch (act) {
-		case LIST:
-		case EXTRACT:
-			while (*argv != NULL)
-				if (pat_add(*argv++, NULL) < 0)
-					cpio_usage();
-			break;
-		case COPY:
-			if (*argv == NULL) {
-				paxwarn(0, "Destination directory was not supplied");
-				cpio_usage();
-			}
-			dirptr = *argv;
-			if (mkpath(dirptr) < 0)
-				cpio_usage();
-			--argc;
-			++argv;
-			/* FALLTHROUGH */
-		case ARCHIVE:
-		case APPND:
-			if (*argv != NULL)
-				cpio_usage();
-			/*
-			 * no read errors allowed on updates/append operation!
-			 */
-			maxflt = 0;
-			while ((str = getline(stdin)) != NULL) {
-				ftree_add(str, 0);
-			}
-			if (getline_error) {
-				paxwarn(1, "Problem while reading stdin");
-				cpio_usage();
-			}
-			break;
-		default:
-			cpio_usage();
-			break;
-	}
-}
-
-/*
- * printflg()
- *	print out those invalid flag sets found to the user
- */
-
-static void
-printflg(unsigned int flg)
-{
-	int nxt;
-	int pos = 0;
-
-	(void)fprintf(stderr,"%s: Invalid combination of options:", argv0);
-	while ((nxt = ffs(flg)) != 0) {
-		flg = flg >> nxt;
-		pos += nxt;
-		(void)fprintf(stderr, " -%c", flgch[pos-1]);
-	}
-	(void)putc('\n', stderr);
-}
-
-/*
- * c_frmt()
- *	comparison routine used by bsearch to find the format specified
- *	by the user
- */
-
-static int
-c_frmt(const void *a, const void *b)
-{
-	return(strcmp(((const FSUB *)a)->name, ((const FSUB *)b)->name));
-}
-
-/*
- * opt_next()
- *	called by format specific options routines to get each format specific
- *	flag and value specified with -o
- * Return:
- *	pointer to next OPLIST entry or NULL (end of list).
- */
-
-OPLIST *
-opt_next(void)
-{
-	OPLIST *opt;
-
-	if ((opt = ophead) != NULL)
-		ophead = ophead->fow;
-	return(opt);
-}
-
-/*
- * bad_opt()
- *	generic routine used to complain about a format specific options
- *	when the format does not support options.
- */
-
-int
-bad_opt(void)
-{
-	OPLIST *opt;
-
-	if (ophead == NULL)
-		return(0);
-	/*
-	 * print all we were given
-	 */
-	paxwarn(1,"These format options are not supported");
-	while ((opt = opt_next()) != NULL)
-		(void)fprintf(stderr, "\t%s = %s\n", opt->name, opt->value);
-	pax_usage();
-	return(0);
-}
-
-/*
- * opt_add()
- *	breaks the value supplied to -o into an option name and value. Options
- *	are given to -o in the form -o name-value,name=value
- *	multiple -o may be specified.
- * Return:
- *	0 if format in name=value format, -1 if -o is passed junk.
- */
-
-int
-opt_add(const char *str)
-{
-	OPLIST *opt;
-	char *frpt;
-	char *pt;
-	char *endpt;
-	char *lstr;
-
-	if ((str == NULL) || (*str == '\0')) {
-		paxwarn(0, "Invalid option name");
-		return(-1);
-	}
-	if ((lstr = strdup(str)) == NULL) {
-		paxwarn(0, "Unable to allocate space for option list");
-		return(-1);
-	}
-	frpt = endpt = lstr;
-
-	/*
-	 * break into name and values pieces and stuff each one into a
-	 * OPLIST structure. When we know the format, the format specific
-	 * option function will go through this list
-	 */
-	while ((frpt != NULL) && (*frpt != '\0')) {
-		if ((endpt = strchr(frpt, ',')) != NULL)
-			*endpt = '\0';
-		if ((pt = strchr(frpt, '=')) == NULL) {
-			paxwarn(0, "Invalid options format");
-			free(lstr);
-			return(-1);
-		}
-		if ((opt = (OPLIST *)malloc(sizeof(OPLIST))) == NULL) {
-			paxwarn(0, "Unable to allocate space for option list");
-			free(lstr);
-			return(-1);
-		}
-		*pt++ = '\0';
-		opt->name = frpt;
-		opt->value = pt;
-		opt->fow = NULL;
-		if (endpt != NULL)
-			frpt = endpt + 1;
-		else
-			frpt = NULL;
-		if (ophead == NULL) {
-			optail = ophead = opt;
-			continue;
-		}
-		optail->fow = opt;
-		optail = opt;
-	}
-	return(0);
-}
-
-/*
- * str_offt()
- *	Convert an expression of the following forms to an off_t > 0.
- * 	1) A positive decimal number.
- *	2) A positive decimal number followed by a b (mult by 512).
- *	3) A positive decimal number followed by a k (mult by 1024).
- *	4) A positive decimal number followed by a m (mult by 512).
- *	5) A positive decimal number followed by a w (mult by sizeof int)
- *	6) Two or more positive decimal numbers (with/without k,b or w).
- *	   separated by x (also * for backwards compatibility), specifying
- *	   the product of the indicated values.
- * Return:
- *	0 for an error, a positive value o.w.
- */
-
-static off_t
-str_offt(char *val)
-{
-	char *expr;
-	off_t num, t;
-
-#	ifdef NET2_STAT
-	num = strtol(val, &expr, 0);
-	if ((num == LONG_MAX) || (num <= 0) || (expr == val))
-#	else
-	num = strtoq(val, &expr, 0);
-	if ((num == QUAD_MAX) || (num <= 0) || (expr == val))
-#	endif
-		return(0);
-
-	switch(*expr) {
-	case 'b':
-		t = num;
-		num *= 512;
-		if (t > num)
-			return(0);
-		++expr;
-		break;
-	case 'k':
-		t = num;
-		num *= 1024;
-		if (t > num)
-			return(0);
-		++expr;
-		break;
-	case 'm':
-		t = num;
-		num *= 1048576;
-		if (t > num)
-			return(0);
-		++expr;
-		break;
-	case 'w':
-		t = num;
-		num *= sizeof(int);
-		if (t > num)
-			return(0);
-		++expr;
-		break;
-	}
-
-	switch(*expr) {
-		case '\0':
-			break;
-		case '*':
-		case 'x':
-			t = num;
-			num *= str_offt(expr + 1);
-			if (t > num)
-				return(0);
-			break;
-		default:
-			return(0);
-	}
-	return(num);
-}
-
-char *fgetln(FILE *f, size_t *);
-
-static char *
-getline(FILE *f)
-{
-	char *name, *temp;
-	size_t len;
-
-	name = fgetln(f, &len);
-	if (!name) {
-		getline_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0;
-		return(0);
-	}
-	if (name[len-1] != '\n')
-		len++;
-	temp = malloc(len);
-	if (!temp) {
-		getline_error = GETLINE_OUT_OF_MEM;
-		return(0);
-	}
-	memcpy(temp, name, len-1);
-	temp[len-1] = 0;
-	return(temp);
-}
-			
-/*
- * no_op()
- *	for those option functions where the archive format has nothing to do.
- * Return:
- *	0
- */
-
-static int
-no_op(void)
-{
-	return(0);
-}
-
-/*
- * pax_usage()
- *	print the usage summary to the user
- */
-
-static void
-pax_usage(void)
-{
-	(void)fputs("usage: pax [-cdnvz] [-E limit] [-f archive] ", stderr);
-	(void)fputs("[-s replstr] ... [-U user] ...", stderr);
-	(void)fputs("\n	   [-G group] ... ", stderr);
-	(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
-	(void)fputs("[pattern ...]\n", stderr);
-	(void)fputs("       pax -r [-cdiknuvzDYZ] [-E limit] ", stderr);
-	(void)fputs("[-f archive] [-o options] ... \n", stderr);
-	(void)fputs("	   [-p string] ... [-s replstr] ... ", stderr);
-	(void)fputs("[-U user] ... [-G group] ...\n	   ", stderr);
-	(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
-	(void)fputs(" [pattern ...]\n", stderr);
-	(void)fputs("       pax -w [-dituvzHLPX] [-b blocksize] ", stderr);
-	(void)fputs("[ [-a] [-f archive] ] [-x format] \n", stderr);
-	(void)fputs("	   [-B bytes] [-s replstr] ... ", stderr);
-	(void)fputs("[-o options] ... [-U user] ...", stderr);
-	(void)fputs("\n	   [-G group] ... ", stderr);
-	(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);
-	(void)fputs("[file ...]\n", stderr);
-	(void)fputs("       pax -r -w [-diklntuvDHLPXYZ] ", stderr);
-	(void)fputs("[-p string] ... [-s replstr] ...", stderr);
-	(void)fputs("\n	   [-U user] ... [-G group] ... ", stderr);
-	(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);
-	(void)fputs("\n	   [file ...] directory\n", stderr);
-	exit(1);
-}
-
-/*
- * tar_usage()
- *	print the usage summary to the user
- */
-
-static void
-tar_usage(void)
-{
-	(void)fputs("usage: tar [-]{crtux}[-befhjmopqsvwyzHLOPXZ014578] [blocksize] ",
-		 stderr);
-	(void)fputs("[archive] [replstr] [-C directory] [-I file] [file ...]\n",
-	    stderr);
-	exit(1);
-}
-
-/*
- * cpio_usage()
- *	print the usage summary to the user
- */
-
-static void
-cpio_usage(void)
-{
-	(void)fputs("usage: cpio -o [-aABcLvVzZ] [-C bytes] [-H format] [-O archive]\n", stderr);
-	(void)fputs("               [-F archive] < name-list [> archive]\n", stderr);
-	(void)fputs("       cpio -i [-bBcdfmnrsStuvVzZ6] [-C bytes] [-E file] [-H format]\n", stderr);
-	(void)fputs("               [-I archive] [-F archive] [pattern...] [< archive]\n", stderr);
-	(void)fputs("       cpio -p [-adlLmuvV] destination-directory < name-list\n", stderr);
-	exit(1);
-}
Index: trunk/minix/commands/pax/options.h
===================================================================
--- trunk/minix/commands/pax/options.h	(revision 9)
+++ 	(revision )
@@ -1,110 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *	@(#)options.h	8.2 (Berkeley) 4/18/94
- * $FreeBSD: src/bin/pax/options.h,v 1.6 2004/04/06 20:06:48 markm Exp $
- */
-
-/*
- * argv[0] names. Used for tar and cpio emulation
- */
-
-#define NM_TAR  "tar"
-#define NM_CPIO "cpio"
-#define NM_PAX  "pax"
-
-/*
- * Constants used to specify the legal sets of flags in pax. For each major
- * operation mode of pax, a set of illegal flags is defined. If any one of
- * those illegal flags are found set, we scream and exit
- */
-#define NONE	"none"
-
-/*
- * flags (one for each option).
- */
-#define	AF	0x00000001
-#define	BF	0x00000002
-#define	CF	0x00000004
-#define	DF	0x00000008
-#define	FF	0x00000010
-#define	IF	0x00000020
-#define	KF	0x00000040
-#define	LF	0x00000080
-#define	NF	0x00000100
-#define	OF	0x00000200
-#define	PF	0x00000400
-#define	RF	0x00000800
-#define	SF	0x00001000
-#define	TF	0x00002000
-#define	UF	0x00004000
-#define	VF	0x00008000
-#define	WF	0x00010000
-#define	XF	0x00020000
-#define	CBF	0x00040000	/* nonstandard extension */
-#define	CDF	0x00080000	/* nonstandard extension */
-#define	CEF	0x00100000	/* nonstandard extension */
-#define	CGF	0x00200000	/* nonstandard extension */
-#define	CHF	0x00400000	/* nonstandard extension */
-#define	CLF	0x00800000	/* nonstandard extension */
-#define	CPF	0x01000000	/* nonstandard extension */
-#define	CTF	0x02000000	/* nonstandard extension */
-#define	CUF	0x04000000	/* nonstandard extension */
-#define	CXF	0x08000000
-#define	CYF	0x10000000	/* nonstandard extension */
-#define	CZF	0x20000000	/* nonstandard extension */
-
-/*
- * ascii string indexed by bit position above (alter the above and you must
- * alter this string) used to tell the user what flags caused us to complain
- */
-#define FLGCH	"abcdfiklnoprstuvwxBDEGHLPTUXYZ"
-
-/*
- * legal pax operation bit patterns
- */
-
-#define ISLIST(x)	(((x) & (RF|WF)) == 0)
-#define	ISEXTRACT(x)	(((x) & (RF|WF)) == RF)
-#define ISARCHIVE(x)	(((x) & (AF|RF|WF)) == WF)
-#define ISAPPND(x)	(((x) & (AF|RF|WF)) == (AF|WF))
-#define	ISCOPY(x)	(((x) & (RF|WF)) == (RF|WF))
-#define	ISWRITE(x)	(((x) & (RF|WF)) == WF)
-
-/*
- * Illegal option flag subsets based on pax operation
- */
-
-#define	BDEXTR	(AF|BF|LF|TF|WF|XF|CBF|CHF|CLF|CPF|CXF)
-#define	BDARCH	(CF|KF|LF|NF|PF|RF|CDF|CEF|CYF|CZF)
-#define	BDCOPY	(AF|BF|FF|OF|XF|CBF|CEF)
-#define	BDLIST (AF|BF|IF|KF|LF|OF|PF|RF|TF|UF|WF|XF|CBF|CDF|CHF|CLF|CPF|CXF|CYF|CZF)
Index: trunk/minix/commands/pax/pat_rep.c
===================================================================
--- trunk/minix/commands/pax/pat_rep.c	(revision 9)
+++ 	(revision )
@@ -1,1128 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)pat_rep.c	8.2 (Berkeley) 4/18/94";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#ifdef NET2_REGEX
-#include <regexp.h>
-#else
-#include <regex.h>
-#endif
-#include "pax.h"
-#include "pat_rep.h"
-#include "extern.h"
-
-/*
- * routines to handle pattern matching, name modification (regular expression
- * substitution and interactive renames), and destination name modification for
- * copy (-rw). Both file name and link names are adjusted as required in these
- * routines.
- */
-
-#define MAXSUBEXP	10		/* max subexpressions, DO NOT CHANGE */
-static PATTERN *pathead = NULL;		/* file pattern match list head */
-static PATTERN *pattail = NULL;		/* file pattern match list tail */
-static REPLACE *rephead = NULL;		/* replacement string list head */
-static REPLACE *reptail = NULL;		/* replacement string list tail */
-
-static int rep_name(char *, int *, int);
-static int tty_rename(ARCHD *);
-static int fix_path(char *, int *, char *, int);
-static int fn_match(char *, char *, char **);
-static char * range_match(char *, int);
-#ifdef NET2_REGEX
-static int resub(regexp *, char *, char *, char *);
-#else
-static int resub(regex_t *, regmatch_t *, char *, char *, char *);
-#endif
-
-/*
- * rep_add()
- *	parses the -s replacement string; compiles the regular expression
- *	and stores the compiled value and it's replacement string together in
- *	replacement string list. Input to this function is of the form:
- *		/old/new/pg
- *	The first char in the string specifies the delimiter used by this
- *	replacement string. "Old" is a regular expression in "ed" format which
- *	is compiled by regcomp() and is applied to filenames. "new" is the
- *	substitution string; p and g are options flags for printing and global
- *	replacement (over the single filename)
- * Return:
- *	0 if a proper replacement string and regular expression was added to
- *	the list of replacement patterns; -1 otherwise.
- */
-
-int
-rep_add(char *str)
-{
-	char *pt1;
-	char *pt2;
-	REPLACE *rep;
-#	ifndef NET2_REGEX
-	int res;
-	char rebuf[BUFSIZ];
-#	endif
-
-	/*
-	 * throw out the bad parameters
-	 */
-	if ((str == NULL) || (*str == '\0')) {
-		paxwarn(1, "Empty replacement string");
-		return(-1);
-	}
-
-	/*
-	 * first character in the string specifies what the delimiter is for
-	 * this expression
-	 */
-	if ((pt1 = strchr(str+1, *str)) == NULL) {
-		paxwarn(1, "Invalid replacement string %s", str);
-		return(-1);
-	}
-
-	/*
-	 * allocate space for the node that handles this replacement pattern
-	 * and split out the regular expression and try to compile it
-	 */
-	if ((rep = (REPLACE *)malloc(sizeof(REPLACE))) == NULL) {
-		paxwarn(1, "Unable to allocate memory for replacement string");
-		return(-1);
-	}
-
-	*pt1 = '\0';
-#	ifdef NET2_REGEX
-	if ((rep->rcmp = regcomp(str+1)) == NULL) {
-#	else
-	if ((res = regcomp(&(rep->rcmp), str+1, 0)) != 0) {
-		regerror(res, &(rep->rcmp), rebuf, sizeof(rebuf));
-		paxwarn(1, "%s while compiling regular expression %s", rebuf, str);
-#	endif
-		(void)free((char *)rep);
-		return(-1);
-	}
-
-	/*
-	 * put the delimiter back in case we need an error message and
-	 * locate the delimiter at the end of the replacement string
-	 * we then point the node at the new substitution string
-	 */
-	*pt1++ = *str;
-	if ((pt2 = strchr(pt1, *str)) == NULL) {
-#		ifdef NET2_REGEX
-		(void)free((char *)rep->rcmp);
-#		else
-		regfree(&(rep->rcmp));
-#		endif
-		(void)free((char *)rep);
-		paxwarn(1, "Invalid replacement string %s", str);
-		return(-1);
-	}
-
-	*pt2 = '\0';
-	rep->nstr = pt1;
-	pt1 = pt2++;
-	rep->flgs = 0;
-
-	/*
-	 * set the options if any
-	 */
-	while (*pt2 != '\0') {
-		switch(*pt2) {
-		case 'g':
-		case 'G':
-			rep->flgs  |= GLOB;
-			break;
-		case 'p':
-		case 'P':
-			rep->flgs  |= PRNT;
-			break;
-		default:
-#			ifdef NET2_REGEX
-			(void)free((char *)rep->rcmp);
-#			else
-			regfree(&(rep->rcmp));
-#			endif
-			(void)free((char *)rep);
-			*pt1 = *str;
-			paxwarn(1, "Invalid replacement string option %s", str);
-			return(-1);
-		}
-		++pt2;
-	}
-
-	/*
-	 * all done, link it in at the end
-	 */
-	rep->fow = NULL;
-	if (rephead == NULL) {
-		reptail = rephead = rep;
-		return(0);
-	}
-	reptail->fow = rep;
-	reptail = rep;
-	return(0);
-}
-
-/*
- * pat_add()
- *	add a pattern match to the pattern match list. Pattern matches are used
- *	to select which archive members are extracted. (They appear as
- *	arguments to pax in the list and read modes). If no patterns are
- *	supplied to pax, all members in the archive will be selected (and the
- *	pattern match list is empty).
- * Return:
- *	0 if the pattern was added to the list, -1 otherwise
- */
-
-int
-pat_add(char *str, char *chdnam)
-{
-	PATTERN *pt;
-
-	/*
-	 * throw out the junk
-	 */
-	if ((str == NULL) || (*str == '\0')) {
-		paxwarn(1, "Empty pattern string");
-		return(-1);
-	}
-
-	/*
-	 * allocate space for the pattern and store the pattern. the pattern is
-	 * part of argv so do not bother to copy it, just point at it. Add the
-	 * node to the end of the pattern list
-	 */
-	if ((pt = (PATTERN *)malloc(sizeof(PATTERN))) == NULL) {
-		paxwarn(1, "Unable to allocate memory for pattern string");
-		return(-1);
-	}
-
-	pt->pstr = str;
-	pt->pend = NULL;
-	pt->plen = strlen(str);
-	pt->fow = NULL;
-	pt->flgs = 0;
-	pt->chdname = chdnam;
-
-	if (pathead == NULL) {
-		pattail = pathead = pt;
-		return(0);
-	}
-	pattail->fow = pt;
-	pattail = pt;
-	return(0);
-}
-
-/*
- * pat_chk()
- *	complain if any the user supplied pattern did not result in a match to
- *	a selected archive member.
- */
-
-void
-pat_chk(void)
-{
-	PATTERN *pt;
-	int wban = 0;
-
-	/*
-	 * walk down the list checking the flags to make sure MTCH was set,
-	 * if not complain
-	 */
-	for (pt = pathead; pt != NULL; pt = pt->fow) {
-		if (pt->flgs & MTCH)
-			continue;
-		if (!wban) {
-			paxwarn(1, "WARNING! These patterns were not matched:");
-			++wban;
-		}
-		(void)fprintf(stderr, "%s\n", pt->pstr);
-	}
-}
-
-/*
- * pat_sel()
- *	the archive member which matches a pattern was selected. Mark the
- *	pattern as having selected an archive member. arcn->pat points at the
- *	pattern that was matched. arcn->pat is set in pat_match()
- *
- *	NOTE: When the -c option is used, we are called when there was no match
- *	by pat_match() (that means we did match before the inverted sense of
- *	the logic). Now this seems really strange at first, but with -c  we
- *	need to keep track of those patterns that cause an archive member to NOT
- *	be selected (it found an archive member with a specified pattern)
- * Return:
- *	0 if the pattern pointed at by arcn->pat was tagged as creating a
- *	match, -1 otherwise.
- */
-
-int
-pat_sel(ARCHD *arcn)
-{
-	PATTERN *pt;
-	PATTERN **ppt;
-	int len;
-
-	/*
-	 * if no patterns just return
-	 */
-	if ((pathead == NULL) || ((pt = arcn->pat) == NULL))
-		return(0);
-
-	/*
-	 * when we are NOT limited to a single match per pattern mark the
-	 * pattern and return
-	 */
-	if (!nflag) {
-		pt->flgs |= MTCH;
-		return(0);
-	}
-
-	/*
-	 * we reach this point only when we allow a single selected match per
-	 * pattern, if the pattern matches a directory and we do not have -d
-	 * (dflag) we are done with this pattern. We may also be handed a file
-	 * in the subtree of a directory. in that case when we are operating
-	 * with -d, this pattern was already selected and we are done
-	 */
-	if (pt->flgs & DIR_MTCH)
-		return(0);
-
-	if (!dflag && ((pt->pend != NULL) || (arcn->type == PAX_DIR))) {
-		/*
-		 * ok we matched a directory and we are allowing
-		 * subtree matches but because of the -n only its children will
-		 * match. This is tagged as a DIR_MTCH type.
-		 * WATCH IT, the code assumes that pt->pend points
-		 * into arcn->name and arcn->name has not been modified.
-		 * If not we will have a big mess. Yup this is another kludge
-		 */
-
-		/*
-		 * if this was a prefix match, remove trailing part of path
-		 * so we can copy it. Future matches will be exact prefix match
-		 */
-		if (pt->pend != NULL)
-			*pt->pend = '\0';
-
-		if ((pt->pstr = strdup(arcn->name)) == NULL) {
-			paxwarn(1, "Pattern select out of memory");
-			if (pt->pend != NULL)
-				*pt->pend = '/';
-			pt->pend = NULL;
-			return(-1);
-		}
-
-		/*
-		 * put the trailing / back in the source string
-		 */
-		if (pt->pend != NULL) {
-			*pt->pend = '/';
-			pt->pend = NULL;
-		}
-		pt->plen = strlen(pt->pstr);
-
-		/*
-		 * strip off any trailing /, this should really never happen
-		 */
-		len = pt->plen - 1;
-		if (*(pt->pstr + len) == '/') {
-			*(pt->pstr + len) = '\0';
-			pt->plen = len;
-		}
-		pt->flgs = DIR_MTCH | MTCH;
-		arcn->pat = pt;
-		return(0);
-	}
-
-	/*
-	 * we are then done with this pattern, so we delete it from the list
-	 * because it can never be used for another match.
-	 * Seems kind of strange to do for a -c, but the pax spec is really
-	 * vague on the interaction of -c -n and -d. We assume that when -c
-	 * and the pattern rejects a member (i.e. it matched it) it is done.
-	 * In effect we place the order of the flags as having -c last.
-	 */
-	pt = pathead;
-	ppt = &pathead;
-	while ((pt != NULL) && (pt != arcn->pat)) {
-		ppt = &(pt->fow);
-		pt = pt->fow;
-	}
-
-	if (pt == NULL) {
-		/*
-		 * should never happen....
-		 */
-		paxwarn(1, "Pattern list inconsistant");
-		return(-1);
-	}
-	*ppt = pt->fow;
-	(void)free((char *)pt);
-	arcn->pat = NULL;
-	return(0);
-}
-
-/*
- * pat_match()
- *	see if this archive member matches any supplied pattern, if a match
- *	is found, arcn->pat is set to point at the potential pattern. Later if
- *	this archive member is "selected" we process and mark the pattern as
- *	one which matched a selected archive member (see pat_sel())
- * Return:
- *	0 if this archive member should be processed, 1 if it should be
- *	skipped and -1 if we are done with all patterns (and pax should quit
- *	looking for more members)
- */
-
-int
-pat_match(ARCHD *arcn)
-{
-	PATTERN *pt;
-
-	arcn->pat = NULL;
-
-	/*
-	 * if there are no more patterns and we have -n (and not -c) we are
-	 * done. otherwise with no patterns to match, matches all
-	 */
-	if (pathead == NULL) {
-		if (nflag && !cflag)
-			return(-1);
-		return(0);
-	}
-
-	/*
-	 * have to search down the list one at a time looking for a match.
-	 */
-	pt = pathead;
-	while (pt != NULL) {
-		/*
-		 * check for a file name match unless we have DIR_MTCH set in
-		 * this pattern then we want a prefix match
-		 */
-		if (pt->flgs & DIR_MTCH) {
-			/*
-			 * this pattern was matched before to a directory
-			 * as we must have -n set for this (but not -d). We can
-			 * only match CHILDREN of that directory so we must use
-			 * an exact prefix match (no wildcards).
-			 */
-			if ((arcn->name[pt->plen] == '/') &&
-			    (strncmp(pt->pstr, arcn->name, pt->plen) == 0))
-				break;
-		} else if (fn_match(pt->pstr, arcn->name, &pt->pend) == 0)
-			break;
-		pt = pt->fow;
-	}
-
-	/*
-	 * return the result, remember that cflag (-c) inverts the sense of a
-	 * match
-	 */
-	if (pt == NULL)
-		return(cflag ? 0 : 1);
-
-	/*
-	 * We had a match, now when we invert the sense (-c) we reject this
-	 * member. However we have to tag the pattern a being successful, (in a
-	 * match, not in selecting an archive member) so we call pat_sel() here.
-	 */
-	arcn->pat = pt;
-	if (!cflag)
-		return(0);
-
-	if (pat_sel(arcn) < 0)
-		return(-1);
-	arcn->pat = NULL;
-	return(1);
-}
-
-/*
- * fn_match()
- * Return:
- *	0 if this archive member should be processed, 1 if it should be
- *	skipped and -1 if we are done with all patterns (and pax should quit
- *	looking for more members)
- *	Note: *pend may be changed to show where the prefix ends.
- */
-
-static int
-fn_match(char *pattern, char *string, char **pend)
-{
-	char c;
-	char test;
-
-	*pend = NULL;
-	for (;;) {
-		switch (c = *pattern++) {
-		case '\0':
-			/*
-			 * Ok we found an exact match
-			 */
-			if (*string == '\0')
-				return(0);
-
-			/*
-			 * Check if it is a prefix match
-			 */
-			if ((dflag == 1) || (*string != '/'))
-				return(-1);
-
-			/*
-			 * It is a prefix match, remember where the trailing
-			 * / is located
-			 */
-			*pend = string;
-			return(0);
-		case '?':
-			if ((test = *string++) == '\0')
-				return (-1);
-			break;
-		case '*':
-			c = *pattern;
-			/*
-			 * Collapse multiple *'s.
-			 */
-			while (c == '*')
-				c = *++pattern;
-
-			/*
-			 * Optimized hack for pattern with a * at the end
-			 */
-			if (c == '\0')
-				return (0);
-
-			/*
-			 * General case, use recursion.
-			 */
-			while ((test = *string) != '\0') {
-				if (!fn_match(pattern, string, pend))
-					return (0);
-				++string;
-			}
-			return (-1);
-		case '[':
-			/*
-			 * range match
-			 */
-			if (((test = *string++) == '\0') ||
-			    ((pattern = range_match(pattern, test)) == NULL))
-				return (-1);
-			break;
-		case '\\':
-		default:
-			if (c != *string++)
-				return (-1);
-			break;
-		}
-	}
-	/* NOTREACHED */
-}
-
-static char *
-range_match(char *pattern, int test)
-{
-	char c;
-	char c2;
-	int negate;
-	int ok = 0;
-
-	if ((negate = (*pattern == '!')) != 0)
-		++pattern;
-
-	while ((c = *pattern++) != ']') {
-		/*
-		 * Illegal pattern
-		 */
-		if (c == '\0')
-			return (NULL);
-
-		if ((*pattern == '-') && ((c2 = pattern[1]) != '\0') &&
-		    (c2 != ']')) {
-			if ((c <= test) && (test <= c2))
-				ok = 1;
-			pattern += 2;
-		} else if (c == test)
-			ok = 1;
-	}
-	return (ok == negate ? NULL : pattern);
-}
-
-/*
- * mod_name()
- *	modify a selected file name. first attempt to apply replacement string
- *	expressions, then apply interactive file rename. We apply replacement
- *	string expressions to both filenames and file links (if we didn't the
- *	links would point to the wrong place, and we could never be able to
- *	move an archive that has a file link in it). When we rename files
- *	interactively, we store that mapping (old name to user input name) so
- *	if we spot any file links to the old file name in the future, we will
- *	know exactly how to fix the file link.
- * Return:
- *	0 continue to  process file, 1 skip this file, -1 pax is finished
- */
-
-int
-mod_name(ARCHD *arcn)
-{
-	int res = 0;
-
-	/*
-	 * Strip off leading '/' if appropriate.
-	 * Currently, this option is only set for the tar format.
-	 */
-	if (rmleadslash && arcn->name[0] == '/') {
-		if (arcn->name[1] == '\0') {
-			arcn->name[0] = '.';
-		} else {
-			(void)memmove(arcn->name, &arcn->name[1],
-			    strlen(arcn->name));
-			arcn->nlen--;
-		}
-		if (rmleadslash < 2) {
-			rmleadslash = 2;
-			paxwarn(0, "Removing leading / from absolute path names in the archive");
-		}
-	}
-	if (rmleadslash && arcn->ln_name[0] == '/' &&
-	    (arcn->type == PAX_HLK || arcn->type == PAX_HRG)) {
-		if (arcn->ln_name[1] == '\0') {
-			arcn->ln_name[0] = '.';
-		} else {
-			(void)memmove(arcn->ln_name, &arcn->ln_name[1],
-			    strlen(arcn->ln_name));
-			arcn->ln_nlen--;
-		}
-		if (rmleadslash < 2) {
-			rmleadslash = 2;
-			paxwarn(0, "Removing leading / from absolute path names in the archive");
-		}
-	}
-
-	/*
-	 * IMPORTANT: We have a problem. what do we do with symlinks?
-	 * Modifying a hard link name makes sense, as we know the file it
-	 * points at should have been seen already in the archive (and if it
-	 * wasn't seen because of a read error or a bad archive, we lose
-	 * anyway). But there are no such requirements for symlinks. On one
-	 * hand the symlink that refers to a file in the archive will have to
-	 * be modified to so it will still work at its new location in the
-	 * file system. On the other hand a symlink that points elsewhere (and
-	 * should continue to do so) should not be modified. There is clearly
-	 * no perfect solution here. So we handle them like hardlinks. Clearly
-	 * a replacement made by the interactive rename mapping is very likely
-	 * to be correct since it applies to a single file and is an exact
-	 * match. The regular expression replacements are a little harder to
-	 * justify though. We claim that the symlink name is only likely
-	 * to be replaced when it points within the file tree being moved and
-	 * in that case it should be modified. what we really need to do is to
-	 * call an oracle here. :)
-	 */
-	if (rephead != NULL) {
-		/*
-		 * we have replacement strings, modify the name and the link
-		 * name if any.
-		 */
-		if ((res = rep_name(arcn->name, &(arcn->nlen), 1)) != 0)
-			return(res);
-
-		if (((arcn->type == PAX_SLK) || (arcn->type == PAX_HLK) ||
-		    (arcn->type == PAX_HRG)) &&
-		    ((res = rep_name(arcn->ln_name, &(arcn->ln_nlen), 0)) != 0))
-			return(res);
-	}
-
-	if (iflag) {
-		/*
-		 * perform interactive file rename, then map the link if any
-		 */
-		if ((res = tty_rename(arcn)) != 0)
-			return(res);
-		if ((arcn->type == PAX_SLK) || (arcn->type == PAX_HLK) ||
-		    (arcn->type == PAX_HRG))
-			sub_name(arcn->ln_name, &(arcn->ln_nlen), sizeof(arcn->ln_name));
-	}
-	return(res);
-}
-
-/*
- * tty_rename()
- *	Prompt the user for a replacement file name. A "." keeps the old name,
- *	a empty line skips the file, and an EOF on reading the tty, will cause
- *	pax to stop processing and exit. Otherwise the file name input, replaces
- *	the old one.
- * Return:
- *	0 process this file, 1 skip this file, -1 we need to exit pax
- */
-
-static int
-tty_rename(ARCHD *arcn)
-{
-	char tmpname[PAXPATHLEN+2];
-	int res;
-
-	/*
-	 * prompt user for the replacement name for a file, keep trying until
-	 * we get some reasonable input. Archives may have more than one file
-	 * on them with the same name (from updates etc). We print verbose info
-	 * on the file so the user knows what is up.
-	 */
-	tty_prnt("\nATTENTION: %s interactive file rename operation.\n", argv0);
-
-	for (;;) {
-		ls_tty(arcn);
-		tty_prnt("Input new name, or a \".\" to keep the old name, ");
-		tty_prnt("or a \"return\" to skip this file.\n");
-		tty_prnt("Input > ");
-		if (tty_read(tmpname, sizeof(tmpname)) < 0)
-			return(-1);
-		if (strcmp(tmpname, "..") == 0) {
-			tty_prnt("Try again, illegal file name: ..\n");
-			continue;
-		}
-		if (strlen(tmpname) > PAXPATHLEN) {
-			tty_prnt("Try again, file name too long\n");
-			continue;
-		}
-		break;
-	}
-
-	/*
-	 * empty file name, skips this file. a "." leaves it alone
-	 */
-	if (tmpname[0] == '\0') {
-		tty_prnt("Skipping file.\n");
-		return(1);
-	}
-	if ((tmpname[0] == '.') && (tmpname[1] == '\0')) {
-		tty_prnt("Processing continues, name unchanged.\n");
-		return(0);
-	}
-
-	/*
-	 * ok the name changed. We may run into links that point at this
-	 * file later. we have to remember where the user sent the file
-	 * in order to repair any links.
-	 */
-	tty_prnt("Processing continues, name changed to: %s\n", tmpname);
-	res = add_name(arcn->name, arcn->nlen, tmpname);
-	arcn->nlen = l_strncpy(arcn->name, tmpname, sizeof(arcn->name) - 1);
-	arcn->name[arcn->nlen] = '\0';
-	if (res < 0)
-		return(-1);
-	return(0);
-}
-
-/*
- * set_dest()
- *	fix up the file name and the link name (if any) so this file will land
- *	in the destination directory (used during copy() -rw).
- * Return:
- *	0 if ok, -1 if failure (name too long)
- */
-
-int
-set_dest(ARCHD *arcn, char *dest_dir, int dir_len)
-{
-	if (fix_path(arcn->name, &(arcn->nlen), dest_dir, dir_len) < 0)
-		return(-1);
-
-	/*
-	 * It is really hard to deal with symlinks here, we cannot be sure
-	 * if the name they point was moved (or will be moved). It is best to
-	 * leave them alone.
-	 */
-	if ((arcn->type != PAX_HLK) && (arcn->type != PAX_HRG))
-		return(0);
-
-	if (fix_path(arcn->ln_name, &(arcn->ln_nlen), dest_dir, dir_len) < 0)
-		return(-1);
-	return(0);
-}
-
-/*
- * fix_path
- *	concatenate dir_name and or_name and store the result in or_name (if
- *	it fits). This is one ugly function.
- * Return:
- *	0 if ok, -1 if the final name is too long
- */
-
-static int
-fix_path( char *or_name, int *or_len, char *dir_name, int dir_len)
-{
-	char *src;
-	char *dest;
-	char *start;
-	int len;
-
-	/*
-	 * we shift the or_name to the right enough to tack in the dir_name
-	 * at the front. We make sure we have enough space for it all before
-	 * we start. since dest always ends in a slash, we skip of or_name
-	 * if it also starts with one.
-	 */
-	start = or_name;
-	src = start + *or_len;
-	dest = src + dir_len;
-	if (*start == '/') {
-		++start;
-		--dest;
-	}
-	if ((len = dest - or_name) > PAXPATHLEN) {
-		paxwarn(1, "File name %s/%s, too long", dir_name, start);
-		return(-1);
-	}
-	*or_len = len;
-
-	/*
-	 * enough space, shift
-	 */
-	while (src >= start)
-		*dest-- = *src--;
-	src = dir_name + dir_len - 1;
-
-	/*
-	 * splice in the destination directory name
-	 */
-	while (src >= dir_name)
-		*dest-- = *src--;
-
-	*(or_name + len) = '\0';
-	return(0);
-}
-
-/*
- * rep_name()
- *	walk down the list of replacement strings applying each one in order.
- *	when we find one with a successful substitution, we modify the name
- *	as specified. if required, we print the results. if the resulting name
- *	is empty, we will skip this archive member. We use the regexp(3)
- *	routines (regexp() ought to win a prize as having the most cryptic
- *	library function manual page).
- *	--Parameters--
- *	name is the file name we are going to apply the regular expressions to
- *	(and may be modified)
- *	nlen is the length of this name (and is modified to hold the length of
- *	the final string).
- *	prnt is a flag that says whether to print the final result.
- * Return:
- *	0 if substitution was successful, 1 if we are to skip the file (the name
- *	ended up empty)
- */
-
-static int
-rep_name(char *name, int *nlen, int prnt)
-{
-	REPLACE *pt;
-	char *inpt;
-	char *outpt;
-	char *endpt;
-	char *rpt;
-	int found = 0;
-	int res;
-#	ifndef NET2_REGEX
-	regmatch_t pm[MAXSUBEXP];
-#	endif
-	char nname[PAXPATHLEN+1];	/* final result of all replacements */
-	char buf1[PAXPATHLEN+1];	/* where we work on the name */
-
-	/*
-	 * copy the name into buf1, where we will work on it. We need to keep
-	 * the orig string around so we can print out the result of the final
-	 * replacement. We build up the final result in nname. inpt points at
-	 * the string we apply the regular expression to. prnt is used to
-	 * suppress printing when we handle replacements on the link field
-	 * (the user already saw that substitution go by)
-	 */
-	pt = rephead;
-	(void)strcpy(buf1, name);
-	inpt = buf1;
-	outpt = nname;
-	endpt = outpt + PAXPATHLEN;
-
-	/*
-	 * try each replacement string in order
-	 */
-	while (pt != NULL) {
-		do {
-			/*
-			 * check for a successful substitution, if not go to
-			 * the next pattern, or cleanup if we were global
-			 */
-#			ifdef NET2_REGEX
-			if (regexec(pt->rcmp, inpt) == 0)
-#			else
-			if (regexec(&(pt->rcmp), inpt, MAXSUBEXP, pm, 0) != 0)
-#			endif
-				break;
-
-			/*
-			 * ok we found one. We have three parts, the prefix
-			 * which did not match, the section that did and the
-			 * tail (that also did not match). Copy the prefix to
-			 * the final output buffer (watching to make sure we
-			 * do not create a string too long).
-			 */
-			found = 1;
-#			ifdef NET2_REGEX
-			rpt = pt->rcmp->startp[0];
-#			else
-			rpt = inpt + pm[0].rm_so;
-#			endif
-
-			while ((inpt < rpt) && (outpt < endpt))
-				*outpt++ = *inpt++;
-			if (outpt == endpt)
-				break;
-
-			/*
-			 * for the second part (which matched the regular
-			 * expression) apply the substitution using the
-			 * replacement string and place it the prefix in the
-			 * final output. If we have problems, skip it.
-			 */
-#			ifdef NET2_REGEX
-			if ((res = resub(pt->rcmp,pt->nstr,outpt,endpt)) < 0) {
-#			else
-			if ((res = resub(&(pt->rcmp),pm,pt->nstr,outpt,endpt))
-			    < 0) {
-#			endif
-				if (prnt)
-					paxwarn(1, "Replacement name error %s",
-					    name);
-				return(1);
-			}
-			outpt += res;
-
-			/*
-			 * we set up to look again starting at the first
-			 * character in the tail (of the input string right
-			 * after the last character matched by the regular
-			 * expression (inpt always points at the first char in
-			 * the string to process). If we are not doing a global
-			 * substitution, we will use inpt to copy the tail to
-			 * the final result. Make sure we do not overrun the
-			 * output buffer
-			 */
-#			ifdef NET2_REGEX
-			inpt = pt->rcmp->endp[0];
-#			else
-			inpt += pm[0].rm_eo - pm[0].rm_so;
-#			endif
-
-			if ((outpt == endpt) || (*inpt == '\0'))
-				break;
-
-			/*
-			 * if the user wants global we keep trying to
-			 * substitute until it fails, then we are done.
-			 */
-		} while (pt->flgs & GLOB);
-
-		if (found)
-			break;
-
-		/*
-		 * a successful substitution did NOT occur, try the next one
-		 */
-		pt = pt->fow;
-	}
-
-	if (found) {
-		/*
-		 * we had a substitution, copy the last tail piece (if there is
-		 * room) to the final result
-		 */
-		while ((outpt < endpt) && (*inpt != '\0'))
-			*outpt++ = *inpt++;
-
-		*outpt = '\0';
-		if ((outpt == endpt) && (*inpt != '\0')) {
-			if (prnt)
-				paxwarn(1,"Replacement name too long %s >> %s",
-				    name, nname);
-			return(1);
-		}
-
-		/*
-		 * inform the user of the result if wanted
-		 */
-		if (prnt && (pt->flgs & PRNT)) {
-			if (*nname == '\0')
-				(void)fprintf(stderr,"%s >> <empty string>\n",
-				    name);
-			else
-				(void)fprintf(stderr,"%s >> %s\n", name, nname);
-		}
-
-		/*
-		 * if empty inform the caller this file is to be skipped
-		 * otherwise copy the new name over the orig name and return
-		 */
-		if (*nname == '\0')
-			return(1);
-		*nlen = l_strncpy(name, nname, PAXPATHLEN + 1);
-		name[PAXPATHLEN] = '\0';
-	}
-	return(0);
-}
-
-#ifdef NET2_REGEX
-/*
- * resub()
- *	apply the replacement to the matched expression. expand out the old
- * 	style ed(1) subexpression expansion.
- * Return:
- *	-1 if error, or the number of characters added to the destination.
- */
-
-static int
-resub(regexp *prog, char *src, char *dest, char *destend)
-{
-	char *spt;
-	char *dpt;
-	char c;
-	int no;
-	int len;
-
-	spt = src;
-	dpt = dest;
-	while ((dpt < destend) && ((c = *spt++) != '\0')) {
-		if (c == '&')
-			no = 0;
-		else if ((c == '\\') && (*spt >= '0') && (*spt <= '9'))
-			no = *spt++ - '0';
-		else {
- 			if ((c == '\\') && ((*spt == '\\') || (*spt == '&')))
- 				c = *spt++;
- 			*dpt++ = c;
-			continue;
-		}
- 		if ((prog->startp[no] == NULL) || (prog->endp[no] == NULL) ||
-		    ((len = prog->endp[no] - prog->startp[no]) <= 0))
-			continue;
-
-		/*
-		 * copy the subexpression to the destination.
-		 * fail if we run out of space or the match string is damaged
-		 */
-		if (len > (destend - dpt))
-			len = destend - dpt;
-		if (l_strncpy(dpt, prog->startp[no], len) != len)
-			return(-1);
-		dpt += len;
-	}
-	return(dpt - dest);
-}
-
-#else
-
-/*
- * resub()
- *	apply the replacement to the matched expression. expand out the old
- * 	style ed(1) subexpression expansion.
- * Return:
- *	-1 if error, or the number of characters added to the destination.
- */
-
-static int
-resub(regex_t *rp, regmatch_t *pm, char *src, char *dest,
-	char *destend)
-{
-	char *spt;
-	char *dpt;
-	char c;
-	regmatch_t *pmpt;
-	int len;
-	int subexcnt;
-
-	spt =  src;
-	dpt = dest;
-	subexcnt = rp->re_nsub;
-	while ((dpt < destend) && ((c = *spt++) != '\0')) {
-		/*
-		 * see if we just have an ordinary replacement character
-		 * or we refer to a subexpression.
-		 */
-		if (c == '&') {
-			pmpt = pm;
-		} else if ((c == '\\') && (*spt >= '0') && (*spt <= '9')) {
-			/*
-			 * make sure there is a subexpression as specified
-			 */
-			if ((len = *spt++ - '0') > subexcnt)
-				return(-1);
-			pmpt = pm + len;
-		} else {
- 			/*
-			 * Ordinary character, just copy it
-			 */
- 			if ((c == '\\') && ((*spt == '\\') || (*spt == '&')))
- 				c = *spt++;
- 			*dpt++ = c;
-			continue;
-		}
-
-		/*
-		 * continue if the subexpression is bogus
-		 */
-		if ((pmpt->rm_so < 0) || (pmpt->rm_eo < 0) ||
-		    ((len = pmpt->rm_eo - pmpt->rm_so) <= 0))
-			continue;
-
-		/*
-		 * copy the subexpression to the destination.
-		 * fail if we run out of space or the match string is damaged
-		 */
-		if (len > (destend - dpt))
-			len = destend - dpt;
-		if (l_strncpy(dpt, src + pmpt->rm_so, len) != len)
-			return(-1);
-		dpt += len;
-	}
-	return(dpt - dest);
-}
-#endif
Index: trunk/minix/commands/pax/pat_rep.h
===================================================================
--- trunk/minix/commands/pax/pat_rep.h	(revision 9)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *	@(#)pat_rep.h	8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/bin/pax/pat_rep.h,v 1.6 2004/04/06 20:06:48 markm Exp $
- */
-
-/*
- * data structure for storing user supplied replacement strings (-s)
- */
-typedef struct replace {
-	char		*nstr;	/* the new string we will substitute with */
-#	ifdef NET2_REGEX
-	regexp		*rcmp;	/* compiled regular expression used to match */
-#	else
-	regex_t		rcmp;	/* compiled regular expression used to match */
-#	endif
-	int		flgs;	/* print conversions? global in operation?  */
-#define	PRNT		0x1
-#define	GLOB		0x2
-	struct replace	*fow;	/* pointer to next pattern */
-} REPLACE;
Index: trunk/minix/commands/pax/pax.c
===================================================================
--- trunk/minix/commands/pax/pax.c	(revision 9)
+++ 	(revision )
@@ -1,439 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#if 0
-#ifndef lint
-static char const copyright[] =
-"@(#) Copyright (c) 1992, 1993\n\
-	The Regents of the University of California.  All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)pax.c	8.2 (Berkeley) 4/18/94";
-#endif /* not lint */
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <locale.h>
-#include <minix/paths.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "pax.h"
-#include "extern.h"
-static int gen_init(void);
-
-/*
- * PAX main routines, general globals and some simple start up routines
- */
-
-/*
- * Variables that can be accessed by any routine within pax
- */
-int	act = DEFOP;		/* read/write/append/copy */
-FSUB	*frmt = NULL;		/* archive format type */
-int	cflag;			/* match all EXCEPT pattern/file */
-int	cwdfd;			/* starting cwd */
-int	dflag;			/* directory member match only  */
-int	iflag;			/* interactive file/archive rename */
-int	kflag;			/* do not overwrite existing files */
-int	lflag;			/* use hard links when possible */
-int	nflag;			/* select first archive member match */
-int	tflag;			/* restore access time after read */
-int	uflag;			/* ignore older modification time files */
-int	vflag;			/* produce verbose output */
-int	Dflag;			/* same as uflag except inode change time */
-int	Hflag;			/* follow command line symlinks (write only) */
-int	Lflag;			/* follow symlinks when writing */
-int	Xflag;			/* archive files with same device id only */
-int	Yflag;			/* same as Dflg except after name mode */
-int	Zflag;			/* same as uflg except after name mode */
-int	vfpart;			/* is partial verbose output in progress */
-int	patime = 1;		/* preserve file access time */
-int	pmtime = 1;		/* preserve file modification times */
-int	nodirs;			/* do not create directories as needed */
-int	pmode;			/* preserve file mode bits */
-int	pids;			/* preserve file uid/gid */
-int	rmleadslash = 0;	/* remove leading '/' from pathnames */
-int	exit_val;		/* exit value */
-int	docrc;			/* check/create file crc */
-char	*dirptr;		/* destination dir in a copy */
-const	char *argv0;		/* root of argv[0] */
-sigset_t s_mask;		/* signal mask for cleanup critical sect */
-FILE	*listf;			/* file pointer to print file list to */
-char	*tempfile;		/* tempfile to use for mkstemp(3) */
-char	*tempbase;		/* basename of tempfile to use for mkstemp(3) */
-
-/*
- *	PAX - Portable Archive Interchange
- *
- * 	A utility to read, write, and write lists of the members of archive
- *	files and copy directory hierarchies. A variety of archive formats
- *	are supported (some are described in POSIX 1003.1 10.1):
- *
- *		ustar - 10.1.1 extended tar interchange format
- *		cpio  - 10.1.2 extended cpio interchange format
- *		tar - old BSD 4.3 tar format
- *		binary cpio - old cpio with binary header format
- *		sysVR4 cpio -  with and without CRC
- *
- * This version is a superset of IEEE Std 1003.2b-d3
- *
- * Summary of Extensions to the IEEE Standard:
- *
- * 1	READ ENHANCEMENTS
- * 1.1	Operations which read archives will continue to operate even when
- *	processing archives which may be damaged, truncated, or fail to meet
- *	format specs in several different ways. Damaged sections of archives
- *	are detected and avoided if possible. Attempts will be made to resync
- *	archive read operations even with badly damaged media.
- * 1.2	Blocksize requirements are not strictly enforced on archive read.
- *	Tapes which have variable sized records can be read without errors.
- * 1.3	The user can specify via the non-standard option flag -E if error
- *	resync operation should stop on a media error, try a specified number
- *	of times to correct, or try to correct forever.
- * 1.4	Sparse files (lseek holes) stored on the archive (but stored with blocks
- *	of all zeros will be restored with holes appropriate for the target
- *	file system
- * 1.5	The user is notified whenever something is found during archive
- *	read operations which violates spec (but the read will continue).
- * 1.6	Multiple archive volumes can be read and may span over different
- *	archive devices
- * 1.7	Rigidly restores all file attributes exactly as they are stored on the
- *	archive.
- * 1.8	Modification change time ranges can be specified via multiple -T
- *	options. These allow a user to select files whose modification time
- *	lies within a specific time range.
- * 1.9	Files can be selected based on owner (user name or uid) via one or more
- *	-U options.
- * 1.10	Files can be selected based on group (group name or gid) via one o
- *	more -G options.
- * 1.11	File modification time can be checked against existing file after
- *	name modification (-Z)
- *
- * 2	WRITE ENHANCEMENTS
- * 2.1	Write operation will stop instead of allowing a user to create a flawed
- *	flawed archive (due to any problem).
- * 2.2	Archives written by pax are forced to strictly conform to both the
- *	archive and pax the specific format specifications.
- * 2.3	Blocking size and format is rigidly enforced on writes.
- * 2.4	Formats which may exhibit header overflow problems (they have fields
- *	too small for large file systems, such as inode number storage), use
- *	routines designed to repair this problem. These techniques still
- *	conform to both pax and format specifications, but no longer truncate
- *	these fields. This removes any restrictions on using these archive
- *	formats on large file systems.
- * 2.5	Multiple archive volumes can be written and may span over different
- *	archive devices
- * 2.6	A archive volume record limit allows the user to specify the number
- *	of bytes stored on an archive volume. When reached the user is
- *	prompted for the next archive volume. This is specified with the
- *	non-standard -B flag. The limit is rounded up to the next blocksize.
- * 2.7	All archive padding during write use zero filled sections. This makes
- *	it much easier to pull data out of flawed archive during read
- *	operations.
- * 2.8	Access time reset with the -t applies to all file nodes (including
- *	directories).
- * 2.9	Symbolic links can be followed with -L (optional in the spec).
- * 2.10	Modification or inode change time ranges can be specified via
- *	multiple -T options. These allow a user to select files whose
- *	modification or inode change time lies within a specific time range.
- * 2.11	Files can be selected based on owner (user name or uid) via one or more
- *	-U options.
- * 2.12	Files can be selected based on group (group name or gid) via one o
- *	more -G options.
- * 2.13	Symlinks which appear on the command line can be followed (without
- *	following other symlinks; -H flag)
- *
- * 3	COPY ENHANCEMENTS
- * 3.1	Sparse files (lseek holes) can be copied without expanding the holes
- *	into zero filled blocks. The file copy is created with holes which are
- *	appropriate for the target file system
- * 3.2	Access time as well as modification time on copied file trees can be
- *	preserved with the appropriate -p options.
- * 3.3	Access time reset with the -t applies to all file nodes (including
- *	directories).
- * 3.4	Symbolic links can be followed with -L (optional in the spec).
- * 3.5	Modification or inode change time ranges can be specified via
- *	multiple -T options. These allow a user to select files whose
- *	modification or inode change time lies within a specific time range.
- * 3.6	Files can be selected based on owner (user name or uid) via one or more
- *	-U options.
- * 3.7	Files can be selected based on group (group name or gid) via one o
- *	more -G options.
- * 3.8	Symlinks which appear on the command line can be followed (without
- *	following other symlinks; -H flag)
- * 3.9  File inode change time can be checked against existing file before
- *	name modification (-D)
- * 3.10 File inode change time can be checked against existing file after
- *	name modification (-Y)
- * 3.11	File modification time can be checked against existing file after
- *	name modification (-Z)
- *
- * 4	GENERAL ENHANCEMENTS
- * 4.1	Internal structure is designed to isolate format dependent and
- *	independent functions. Formats are selected via a format driver table.
- *	This encourages the addition of new archive formats by only having to
- *	write those routines which id, read and write the archive header.
- */
-
-/*
- * main()
- *	parse options, set up and operate as specified by the user.
- *	any operational flaw will set exit_val to non-zero
- * Return: 0 if ok, 1 otherwise
- */
-
-int
-main(int argc, char *argv[])
-{
-	const char *tmpdir;
-	size_t tdlen;
-
-	(void) setlocale(LC_ALL, "");
-	listf = stderr;
-	/*
-	 * Keep a reference to cwd, so we can always come back home.
-	 */
-	cwdfd = open(".", O_RDONLY);
-	if (cwdfd < 0) {
-		syswarn(0, errno, "Can't open current working directory.");
-		return(exit_val);
-	}
-
-	/*
-	 * Where should we put temporary files?
-	 */
-	if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
-		tmpdir = _PATH_TMP;
-	tdlen = strlen(tmpdir);
-	while(tdlen > 0 && tmpdir[tdlen - 1] == '/')
-		tdlen--;
-	tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE));
-	if (tempfile == NULL) {
-		paxwarn(1, "Cannot allocate memory for temp file name.");
-		return(exit_val);
-	}
-	if (tdlen)
-		memcpy(tempfile, tmpdir, tdlen);
-	tempbase = tempfile + tdlen;
-	*tempbase++ = '/';
-
-	/*
-	 * parse options, determine operational mode, general init
-	 */
-	options(argc, argv);
-	if ((gen_init() < 0) || (tty_init() < 0))
-		return(exit_val);
-
-	/*
-	 * select a primary operation mode
-	 */
-	switch(act) {
-	case EXTRACT:
-		extract();
-		break;
-	case ARCHIVE:
-		archive();
-		break;
-	case APPND:
-		if (gzip_program != NULL)
-			err(1, "can not gzip while appending");
-		append();
-		break;
-	case COPY:
-		copy();
-		break;
-	default:
-	case LIST:
-		list();
-		break;
-	}
-	return(exit_val);
-}
-
-/*
- * sig_cleanup()
- *	when interrupted we try to do whatever delayed processing we can.
- *	This is not critical, but we really ought to limit our damage when we
- *	are aborted by the user.
- * Return:
- *	never....
- */
-
-void
-sig_cleanup(int which_sig)
-{
-	/*
-	 * restore modes and times for any dirs we may have created
-	 * or any dirs we may have read. Set vflag and vfpart so the user
-	 * will clearly see the message on a line by itself.
-	 */
-	vflag = vfpart = 1;
-#if 0
-	/* ignore this under minix */
-	if (which_sig == SIGXCPU)
-		paxwarn(0, "Cpu time limit reached, cleaning up.");
-	else
-#endif
-		paxwarn(0, "Signal caught, cleaning up.");
-
-	ar_close();
-	proc_dir();
-	if (tflag)
-		atdir_end();
-	exit(1);
-}
-
-/*
- * gen_init()
- *	general setup routines. Not all are required, but they really help
- *	when dealing with a medium to large sized archives.
- */
-
-static int
-gen_init(void)
-{
-#if 0
-	struct rlimit reslimit;
-#endif
-	struct sigaction n_hand;
-	struct sigaction o_hand;
-
-#if 0
-	/*
-	 * Really needed to handle large archives. We can run out of memory for
-	 * internal tables really fast when we have a whole lot of files...
-	 */
-	if (getrlimit(RLIMIT_DATA , &reslimit) == 0){
-		reslimit.rlim_cur = reslimit.rlim_max;
-		(void)setrlimit(RLIMIT_DATA , &reslimit);
-	}
-
-	/*
-	 * should file size limits be waived? if the os limits us, this is
-	 * needed if we want to write a large archive
-	 */
-	if (getrlimit(RLIMIT_FSIZE , &reslimit) == 0){
-		reslimit.rlim_cur = reslimit.rlim_max;
-		(void)setrlimit(RLIMIT_FSIZE , &reslimit);
-	}
-
-	/*
-	 * increase the size the stack can grow to
-	 */
-	if (getrlimit(RLIMIT_STACK , &reslimit) == 0){
-		reslimit.rlim_cur = reslimit.rlim_max;
-		(void)setrlimit(RLIMIT_STACK , &reslimit);
-	}
-
-	/*
-	 * not really needed, but doesn't hurt
-	 */
-	if (getrlimit(RLIMIT_RSS , &reslimit) == 0){
-		reslimit.rlim_cur = reslimit.rlim_max;
-		(void)setrlimit(RLIMIT_RSS , &reslimit);
-	}
-#endif
-
-	/*
-	 * signal handling to reset stored directory times and modes. Since
-	 * we deal with broken pipes via failed writes we ignore it. We also
-	 * deal with any file size limit thorugh failed writes. Cpu time
-	 * limits are caught and a cleanup is forced.
-	 */
-
-	if ((sigemptyset(&s_mask) < 0) || (sigaddset(&s_mask, SIGTERM) < 0) ||
-	    (sigaddset(&s_mask,SIGINT) < 0)||(sigaddset(&s_mask,SIGHUP) < 0) ||
-	    (sigaddset(&s_mask,SIGPIPE) < 0)||(sigaddset(&s_mask,SIGQUIT)<0) 
-#if 0
-	    || (sigaddset(&s_mask,SIGXCPU) < 0)||(sigaddset(&s_mask,SIGXFSZ)<0)
-#endif
-	    ) {
-		paxwarn(1, "Unable to set up signal mask");
-		return(-1);
-	}
-	memset(&n_hand, 0, sizeof n_hand);
-	n_hand.sa_mask = s_mask;
-	n_hand.sa_flags = 0;
-	n_hand.sa_handler = sig_cleanup;
-
-	if ((sigaction(SIGHUP, &n_hand, &o_hand) < 0) &&
-	    (o_hand.sa_handler == SIG_IGN) &&
-	    (sigaction(SIGHUP, &o_hand, &o_hand) < 0))
-		goto out;
-
-	if ((sigaction(SIGTERM, &n_hand, &o_hand) < 0) &&
-	    (o_hand.sa_handler == SIG_IGN) &&
-	    (sigaction(SIGTERM, &o_hand, &o_hand) < 0))
-		goto out;
-
-	if ((sigaction(SIGINT, &n_hand, &o_hand) < 0) &&
-	    (o_hand.sa_handler == SIG_IGN) &&
-	    (sigaction(SIGINT, &o_hand, &o_hand) < 0))
-		goto out;
-
-	if ((sigaction(SIGQUIT, &n_hand, &o_hand) < 0) &&
-	    (o_hand.sa_handler == SIG_IGN) &&
-	    (sigaction(SIGQUIT, &o_hand, &o_hand) < 0))
-		goto out;
-
-#if 0
-	if ((sigaction(SIGXCPU, &n_hand, &o_hand) < 0) &&
-	    (o_hand.sa_handler == SIG_IGN) &&
-	    (sigaction(SIGXCPU, &o_hand, &o_hand) < 0))
-		goto out;
-#endif
-
-	n_hand.sa_handler = SIG_IGN;
-	if ((sigaction(SIGPIPE, &n_hand, &o_hand) < 0)
-#if 0
-	 || (sigaction(SIGXFSZ, &n_hand, &o_hand) < 0)
-#endif
-	    )
-
-
-		goto out;
-	return(0);
-
-    out:
-	syswarn(1, errno, "Unable to set up signal handler");
-	return(-1);
-}
Index: trunk/minix/commands/pax/pax.h
===================================================================
--- trunk/minix/commands/pax/pax.h	(revision 9)
+++ 	(revision )
@@ -1,251 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *	@(#)pax.h	8.2 (Berkeley) 4/18/94
- * $FreeBSD: src/bin/pax/pax.h,v 1.18 2004/04/06 20:06:48 markm Exp $
- */
-
-
-#include <minix/config.h>
-#include <minix/const.h>
-
-/*
- * BSD PAX global data structures and constants.
- */
-
-#define	MAXBLK		64512	/* MAX blocksize supported (posix SPEC) */
-				/* WARNING: increasing MAXBLK past 32256 */
-				/* will violate posix spec. */
-#define	MAXBLK_POSIX	32256	/* MAX blocksize supported as per POSIX */
-#define BLKMULT		512	/* blocksize must be even mult of 512 bytes */
-				/* Don't even think of changing this */
-#define DEVBLK		8192	/* default read blksize for devices */
-#define FILEBLK		10240	/* default read blksize for files */
-#define PAXPATHLEN	3072	/* maximum path length for pax. MUST be */
-				/* longer than the system PATH_MAX */
-
-/*
- * Pax modes of operation
- */
-#define	LIST		0	/* List the file in an archive */
-#define	EXTRACT		1	/* extract the files in an archive */
-#define ARCHIVE		2	/* write a new archive */
-#define APPND		3	/* append to the end of an archive */
-#define	COPY		4	/* copy files to destination dir */
-#define DEFOP		LIST	/* if no flags default is to LIST */
-
-/*
- * Device type of the current archive volume
- */
-#define ISREG		0	/* regular file */
-#define ISCHR		1	/* character device */
-#define ISBLK		2	/* block device */
-#define ISTAPE		3	/* tape drive */
-#define ISPIPE		4	/* pipe/socket */
-
-typedef struct archd ARCHD;
-typedef struct fsub FSUB;
-typedef struct oplist OPLIST;
-typedef struct pattern PATTERN;
-
-/*
- * Format Specific Routine Table
- *
- * The format specific routine table allows new archive formats to be quickly
- * added. Overall pax operation is independent of the actual format used to
- * form the archive. Only those routines which deal directly with the archive
- * are tailored to the oddities of the specific format. All other routines are
- * independent of the archive format. Data flow in and out of the format
- * dependent routines pass pointers to ARCHD structure (described below).
- */
-struct fsub {
-	const char *name;	/* name of format, this is the name the user */
-				/* gives to -x option to select it. */
-	int bsz;		/* default block size. used when the user */
-				/* does not specify a blocksize for writing */
-				/* Appends continue to with the blocksize */
-				/* the archive is currently using. */
-	int hsz;		/* Header size in bytes. this is the size of */
-				/* the smallest header this format supports. */
-				/* Headers are assumed to fit in a BLKMULT. */
-				/* If they are bigger, get_head() and */
-				/* get_arc() must be adjusted */
-	int udev;		/* does append require unique dev/ino? some */
-				/* formats use the device and inode fields */
-				/* to specify hard links. when members in */
-				/* the archive have the same inode/dev they */
-				/* are assumed to be hard links. During */
-				/* append we may have to generate unique ids */
-				/* to avoid creating incorrect hard links */
-	int hlk;		/* does archive store hard links info? if */
-				/* not, we do not bother to look for them */
-				/* during archive write operations */
-	int blkalgn;		/* writes must be aligned to blkalgn boundary */
-	int inhead;		/* is the trailer encoded in a valid header? */
-				/* if not, trailers are assumed to be found */
-				/* in invalid headers (i.e like tar) */
-	int (*id)(char *, int);	/* checks if a buffer is a valid header */
-				/* returns 1 if it is, o.w. returns a 0 */
-	int (*st_rd)(void);	/* initialize routine for read. so format */
-				/* can set up tables etc before it starts */
-				/* reading an archive */
-	int (*rd)(ARCHD *, char *);
-				/* read header routine. passed a pointer to */
-				/* ARCHD. It must extract the info from the */
-				/* format and store it in the ARCHD struct. */
-				/* This routine is expected to fill all the */
-				/* fields in the ARCHD (including stat buf) */
-				/* 0 is returned when a valid header is */
-				/* found. -1 when not valid. This routine */
-				/* set the skip and pad fields so the format */
-				/* independent routines know the amount of */
-				/* padding and the number of bytes of data */
-				/* which follow the header. This info is */
-				/* used skip to the next file header */
-	off_t (*end_rd)(void);	/* read cleanup. Allows format to clean up */
-				/* and MUST RETURN THE LENGTH OF THE TRAILER */
-				/* RECORD (so append knows how many bytes */
-				/* to move back to rewrite the trailer) */
-	int (*st_wr)(void);	/* initialize routine for write operations */
-	int (*wr)(ARCHD *);	/* write archive header. Passed an ARCHD */
-				/* filled with the specs on the next file to */
-				/* archived. Returns a 1 if no file data is */
-				/* is to be stored; 0 if file data is to be */
-				/* added. A -1 is returned if a write */
-				/* operation to the archive failed. this */
-				/* function sets the skip and pad fields so */
-				/* the proper padding can be added after */
-				/* file data. This routine must NEVER write */
-				/* a flawed archive header. */
-	int (*end_wr)(void);	/* end write. write the trailer and do any */
-				/* other format specific functions needed */
-				/* at the end of an archive write */
-	int (*trail_cpio)(ARCHD *);
-	int (*trail_tar)(char *, int, int *);
-				/* returns 0 if a valid trailer, -1 if not */
-				/* For formats which encode the trailer */
-				/* outside of a valid header, a return value */
-				/* of 1 indicates that the block passed to */
-				/* it can never contain a valid header (skip */
-				/* this block, no point in looking at it)  */
-	int (*rd_data)(ARCHD *, int, off_t *);
-				/* read/process file data from the archive */
-	int (*wr_data)(ARCHD *, int, off_t *);
-				/* write/process file data to the archive */
-	int (*options)(void);	/* process format specific options (-o) */
-};
-
-/*
- * Pattern matching structure
- *
- * Used to store command line patterns
- */
-struct pattern {
-	char		*pstr;		/* pattern to match, user supplied */
-	char		*pend;		/* end of a prefix match */
-	char		*chdname;	/* the dir to change to if not NULL.  */
-	int		plen;		/* length of pstr */
-	int		flgs;		/* processing/state flags */
-#define MTCH		0x1		/* pattern has been matched */
-#define DIR_MTCH	0x2		/* pattern matched a directory */
-	struct pattern	*fow;		/* next pattern */
-};
-
-/*
- * General Archive Structure (used internal to pax)
- *
- * This structure is used to pass information about archive members between
- * the format independent routines and the format specific routines. When
- * new archive formats are added, they must accept requests and supply info
- * encoded in a structure of this type. The name fields are declared statically
- * here, as there is only ONE of these floating around, size is not a major
- * consideration. Eventually converting the name fields to a dynamic length
- * may be required if and when the supporting operating system removes all
- * restrictions on the length of pathnames it will resolve.
- */
-struct archd {
-	int nlen;			/* file name length */
-	char name[PAXPATHLEN+1];	/* file name */
-	int ln_nlen;			/* link name length */
-	char ln_name[PAXPATHLEN+1];	/* name to link to (if any) */
-	char *org_name;			/* orig name in file system */
-	PATTERN *pat;			/* ptr to pattern match (if any) */
-	struct stat sb;			/* stat buffer see stat(2) */
-	off_t pad;			/* bytes of padding after file xfer */
-	off_t skip;			/* bytes of real data after header */
-					/* IMPORTANT. The st_size field does */
-					/* not always indicate the amount of */
-					/* data following the header. */
-	u_long crc;			/* file crc */
-	int type;			/* type of file node */
-#define PAX_DIR		1		/* directory */
-#define PAX_CHR		2		/* character device */
-#define PAX_BLK		3		/* block device */
-#define PAX_REG		4		/* regular file */
-#define PAX_SLK		5		/* symbolic link */
-#define PAX_SCK		6		/* socket */
-#define PAX_FIF		7		/* fifo */
-#define PAX_HLK		8		/* hard link */
-#define PAX_HRG		9		/* hard link to a regular file */
-#define PAX_CTG		10		/* high performance file */
-};
-
-/*
- * Format Specific Options List
- *
- * Used to pass format options to the format options handler
- */
-struct oplist {
-	char		*name;		/* option variable name e.g. name= */
-	char		*value;		/* value for option variable */
-	struct oplist	*fow;		/* next option */
-};
-
-/*
- * General Macros
- */
-#ifndef MIN
-#define	       MIN(a,b) (((a)<(b))?(a):(b))
-#endif
-#define TODEV(x, y)	makedev((x), (y))
-
-/*
- * General Defines
- */
-#define HEX		16
-#define OCT		8
-#define _PAX_		1
-#define _TFILE_BASE	"paxXXXXXXXXXX"
-
-#define err(c, str) { perror(str); exit(c); }
-#define setpassent(a) setpwent()
-#define setgroupent(a) setgrent()
Index: trunk/minix/commands/pax/sel_subs.c
===================================================================
--- trunk/minix/commands/pax/sel_subs.c	(revision 9)
+++ 	(revision )
@@ -1,605 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)sel_subs.c	8.1 (Berkeley) 5/31/93";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <pwd.h>
-#include <time.h>
-#include <grp.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "pax.h"
-#include "sel_subs.h"
-#include "extern.h"
-
-static int str_sec(char *, time_t *);
-static int usr_match(ARCHD *);
-static int grp_match(ARCHD *);
-static int trng_match(ARCHD *);
-
-static TIME_RNG *trhead = NULL;		/* time range list head */
-static TIME_RNG *trtail = NULL;		/* time range list tail */
-static USRT **usrtb = NULL;		/* user selection table */
-static GRPT **grptb = NULL;		/* group selection table */
-
-/*
- * Routines for selection of archive members
- */
-
-/*
- * sel_chk()
- *	check if this file matches a specified uid, gid or time range
- * Return:
- *	0 if this archive member should be processed, 1 if it should be skipped
- */
-
-int
-sel_chk(ARCHD *arcn)
-{
-	if (((usrtb != NULL) && usr_match(arcn)) ||
-	    ((grptb != NULL) && grp_match(arcn)) ||
-	    ((trhead != NULL) && trng_match(arcn)))
-		return(1);
-	return(0);
-}
-
-/*
- * User/group selection routines
- *
- * Routines to handle user selection of files based on the file uid/gid. To
- * add an entry, the user supplies either then name or the uid/gid starting with
- * a # on the command line. A \# will escape the #.
- */
-
-/*
- * usr_add()
- *	add a user match to the user match hash table
- * Return:
- *	0 if added ok, -1 otherwise;
- */
-
-int
-usr_add(char *str)
-{
-	u_int indx;
-	USRT *pt;
-	struct passwd *pw;
-	uid_t uid;
-
-	/*
-	 * create the table if it doesn't exist
-	 */
-	if ((str == NULL) || (*str == '\0'))
-		return(-1);
-	if ((usrtb == NULL) &&
- 	    ((usrtb = (USRT **)calloc(USR_TB_SZ, sizeof(USRT *))) == NULL)) {
-		paxwarn(1, "Unable to allocate memory for user selection table");
-		return(-1);
-	}
-
-	/*
-	 * figure out user spec
-	 */
-	if (str[0] != '#') {
-		/*
-		 * it is a user name, \# escapes # as first char in user name
-		 */
-		if ((str[0] == '\\') && (str[1] == '#'))
-			++str;
-		if ((pw = getpwnam(str)) == NULL) {
-			paxwarn(1, "Unable to find uid for user: %s", str);
-			return(-1);
-		}
-		uid = (uid_t)pw->pw_uid;
-	} else
-#		ifdef NET2_STAT
-		uid = (uid_t)atoi(str+1);
-#		else
-		uid = (uid_t)strtoul(str+1, NULL, 10);
-#		endif
-	endpwent();
-
-	/*
-	 * hash it and go down the hash chain (if any) looking for it
-	 */
-	indx = ((unsigned)uid) % USR_TB_SZ;
-	if ((pt = usrtb[indx]) != NULL) {
-		while (pt != NULL) {
-			if (pt->uid == uid)
-				return(0);
-			pt = pt->fow;
-		}
-	}
-
-	/*
-	 * uid is not yet in the table, add it to the front of the chain
-	 */
-	if ((pt = (USRT *)malloc(sizeof(USRT))) != NULL) {
-		pt->uid = uid;
-		pt->fow = usrtb[indx];
-		usrtb[indx] = pt;
-		return(0);
-	}
-	paxwarn(1, "User selection table out of memory");
-	return(-1);
-}
-
-/*
- * usr_match()
- *	check if this files uid matches a selected uid.
- * Return:
- *	0 if this archive member should be processed, 1 if it should be skipped
- */
-
-static int
-usr_match(ARCHD *arcn)
-{
-	USRT *pt;
-
-	/*
-	 * hash and look for it in the table
-	 */
-	pt = usrtb[((unsigned)arcn->sb.st_uid) % USR_TB_SZ];
-	while (pt != NULL) {
-		if (pt->uid == arcn->sb.st_uid)
-			return(0);
-		pt = pt->fow;
-	}
-
-	/*
-	 * not found
-	 */
-	return(1);
-}
-
-/*
- * grp_add()
- *	add a group match to the group match hash table
- * Return:
- *	0 if added ok, -1 otherwise;
- */
-
-int
-grp_add(char *str)
-{
-	u_int indx;
-	GRPT *pt;
-	struct group *gr;
-	gid_t gid;
-
-	/*
-	 * create the table if it doesn't exist
-	 */
-	if ((str == NULL) || (*str == '\0'))
-		return(-1);
-	if ((grptb == NULL) &&
- 	    ((grptb = (GRPT **)calloc(GRP_TB_SZ, sizeof(GRPT *))) == NULL)) {
-		paxwarn(1, "Unable to allocate memory fo group selection table");
-		return(-1);
-	}
-
-	/*
-	 * figure out user spec
-	 */
-	if (str[0] != '#') {
-		/*
-		 * it is a group name, \# escapes # as first char in group name
-		 */
-		if ((str[0] == '\\') && (str[1] == '#'))
-			++str;
-		if ((gr = getgrnam(str)) == NULL) {
-			paxwarn(1,"Cannot determine gid for group name: %s", str);
-			return(-1);
-		}
-		gid = gr->gr_gid;
-	} else
-#		ifdef NET2_STAT
-		gid = (gid_t)atoi(str+1);
-#		else
-		gid = (gid_t)strtoul(str+1, NULL, 10);
-#		endif
-	endgrent();
-
-	/*
-	 * hash it and go down the hash chain (if any) looking for it
-	 */
-	indx = ((unsigned)gid) % GRP_TB_SZ;
-	if ((pt = grptb[indx]) != NULL) {
-		while (pt != NULL) {
-			if (pt->gid == gid)
-				return(0);
-			pt = pt->fow;
-		}
-	}
-
-	/*
-	 * gid not in the table, add it to the front of the chain
-	 */
-	if ((pt = (GRPT *)malloc(sizeof(GRPT))) != NULL) {
-		pt->gid = gid;
-		pt->fow = grptb[indx];
-		grptb[indx] = pt;
-		return(0);
-	}
-	paxwarn(1, "Group selection table out of memory");
-	return(-1);
-}
-
-/*
- * grp_match()
- *	check if this files gid matches a selected gid.
- * Return:
- *	0 if this archive member should be processed, 1 if it should be skipped
- */
-
-static int
-grp_match(ARCHD *arcn)
-{
-	GRPT *pt;
-
-	/*
-	 * hash and look for it in the table
-	 */
-	pt = grptb[((unsigned)arcn->sb.st_gid) % GRP_TB_SZ];
-	while (pt != NULL) {
-		if (pt->gid == arcn->sb.st_gid)
-			return(0);
-		pt = pt->fow;
-	}
-
-	/*
-	 * not found
-	 */
-	return(1);
-}
-
-/*
- * Time range selection routines
- *
- * Routines to handle user selection of files based on the modification and/or
- * inode change time falling within a specified time range (the non-standard
- * -T flag). The user may specify any number of different file time ranges.
- * Time ranges are checked one at a time until a match is found (if at all).
- * If the file has a mtime (and/or ctime) which lies within one of the time
- * ranges, the file is selected. Time ranges may have a lower and/or an upper
- * value. These ranges are inclusive. When no time ranges are supplied to pax
- * with the -T option, all members in the archive will be selected by the time
- * range routines. When only a lower range is supplied, only files with a
- * mtime (and/or ctime) equal to or younger are selected. When only an upper
- * range is supplied, only files with a mtime (and/or ctime) equal to or older
- * are selected. When the lower time range is equal to the upper time range,
- * only files with a mtime (or ctime) of exactly that time are selected.
- */
-
-/*
- * trng_add()
- *	add a time range match to the time range list.
- *	This is a non-standard pax option. Lower and upper ranges are in the
- *	format: [yy[mm[dd[hh]]]]mm[.ss] and are comma separated.
- *	Time ranges are based on current time, so 1234 would specify a time of
- *	12:34 today.
- * Return:
- *	0 if the time range was added to the list, -1 otherwise
- */
-
-int
-trng_add(char *str)
-{
-	TIME_RNG *pt;
-	char *up_pt = NULL;
-	char *stpt;
-	char *flgpt;
-	int dot = 0;
-
-	/*
-	 * throw out the badly formed time ranges
-	 */
-	if ((str == NULL) || (*str == '\0')) {
-		paxwarn(1, "Empty time range string");
-		return(-1);
-	}
-
-	/*
-	 * locate optional flags suffix /{cm}.
-	 */
-	if ((flgpt = strrchr(str, '/')) != NULL)
-		*flgpt++ = '\0';
-
-	for (stpt = str; *stpt != '\0'; ++stpt) {
-		if ((*stpt >= '0') && (*stpt <= '9'))
-			continue;
-		if ((*stpt == ',') && (up_pt == NULL)) {
-			*stpt = '\0';
-			up_pt = stpt + 1;
-			dot = 0;
-			continue;
-		}
-
-		/*
-		 * allow only one dot per range (secs)
-		 */
-		if ((*stpt == '.') && (!dot)) {
-			++dot;
-			continue;
-		}
-		paxwarn(1, "Improperly specified time range: %s", str);
-		goto out;
-	}
-
-	/*
-	 * allocate space for the time range and store the limits
-	 */
-	if ((pt = (TIME_RNG *)malloc(sizeof(TIME_RNG))) == NULL) {
-		paxwarn(1, "Unable to allocate memory for time range");
-		return(-1);
-	}
-
-	/*
-	 * by default we only will check file mtime, but usee can specify
-	 * mtime, ctime (inode change time) or both.
-	 */
-	if ((flgpt == NULL) || (*flgpt == '\0'))
-		pt->flgs = CMPMTME;
-	else {
-		pt->flgs = 0;
-		while (*flgpt != '\0') {
-			switch(*flgpt) {
-			case 'M':
-			case 'm':
-				pt->flgs |= CMPMTME;
-				break;
-			case 'C':
-			case 'c':
-				pt->flgs |= CMPCTME;
-				break;
-			default:
-				paxwarn(1, "Bad option %c with time range %s",
-				    *flgpt, str);
-				goto out;
-			}
-			++flgpt;
-		}
-	}
-
-	/*
-	 * start off with the current time
-	 */
-	pt->low_time = pt->high_time = time(NULL);
-	if (*str != '\0') {
-		/*
-		 * add lower limit
-		 */
-		if (str_sec(str, &(pt->low_time)) < 0) {
-			paxwarn(1, "Illegal lower time range %s", str);
-			(void)free((char *)pt);
-			goto out;
-		}
-		pt->flgs |= HASLOW;
-	}
-
-	if ((up_pt != NULL) && (*up_pt != '\0')) {
-		/*
-		 * add upper limit
-		 */
-		if (str_sec(up_pt, &(pt->high_time)) < 0) {
-			paxwarn(1, "Illegal upper time range %s", up_pt);
-			(void)free((char *)pt);
-			goto out;
-		}
-		pt->flgs |= HASHIGH;
-
-		/*
-		 * check that the upper and lower do not overlap
-		 */
-		if (pt->flgs & HASLOW) {
-			if (pt->low_time > pt->high_time) {
-				paxwarn(1, "Upper %s and lower %s time overlap",
-					up_pt, str);
-				(void)free((char *)pt);
-				return(-1);
-			}
-		}
-	}
-
-	pt->fow = NULL;
-	if (trhead == NULL) {
-		trtail = trhead = pt;
-		return(0);
-	}
-	trtail->fow = pt;
-	trtail = pt;
-	return(0);
-
-    out:
-	paxwarn(1, "Time range format is: [yy[mm[dd[hh]]]]mm[.ss][/[c][m]]");
-	return(-1);
-}
-
-/*
- * trng_match()
- *	check if this files mtime/ctime falls within any supplied time range.
- * Return:
- *	0 if this archive member should be processed, 1 if it should be skipped
- */
-
-static int
-trng_match(ARCHD *arcn)
-{
-	TIME_RNG *pt;
-
-	/*
-	 * have to search down the list one at a time looking for a match.
-	 * remember time range limits are inclusive.
-	 */
-	pt = trhead;
-	while (pt != NULL) {
-		switch(pt->flgs & CMPBOTH) {
-		case CMPBOTH:
-			/*
-			 * user wants both mtime and ctime checked for this
-			 * time range
-			 */
-			if (((pt->flgs & HASLOW) &&
-			    (arcn->sb.st_mtime < pt->low_time) &&
-			    (arcn->sb.st_ctime < pt->low_time)) ||
-			    ((pt->flgs & HASHIGH) &&
-			    (arcn->sb.st_mtime > pt->high_time) &&
-			    (arcn->sb.st_ctime > pt->high_time))) {
-				pt = pt->fow;
-				continue;
-			}
-			break;
-		case CMPCTME:
-			/*
-			 * user wants only ctime checked for this time range
-			 */
-			if (((pt->flgs & HASLOW) &&
-			    (arcn->sb.st_ctime < pt->low_time)) ||
-			    ((pt->flgs & HASHIGH) &&
-			    (arcn->sb.st_ctime > pt->high_time))) {
-				pt = pt->fow;
-				continue;
-			}
-			break;
-		case CMPMTME:
-		default:
-			/*
-			 * user wants only mtime checked for this time range
-			 */
-			if (((pt->flgs & HASLOW) &&
-			    (arcn->sb.st_mtime < pt->low_time)) ||
-			    ((pt->flgs & HASHIGH) &&
-			    (arcn->sb.st_mtime > pt->high_time))) {
-				pt = pt->fow;
-				continue;
-			}
-			break;
-		}
-		break;
-	}
-
-	if (pt == NULL)
-		return(1);
-	return(0);
-}
-
-/*
- * str_sec()
- *	Convert a time string in the format of [yy[mm[dd[hh]]]]mm[.ss] to gmt
- *	seconds. Tval already has current time loaded into it at entry.
- * Return:
- *	0 if converted ok, -1 otherwise
- */
-
-static int
-str_sec(char *str, time_t *tval)
-{
-	struct tm *lt;
-	char *dot = NULL;
-
-	lt = localtime(tval);
-	if ((dot = strchr(str, '.')) != NULL) {
-		/*
-		 * seconds (.ss)
-		 */
-		*dot++ = '\0';
-		if (strlen(dot) != 2)
-			return(-1);
-		if ((lt->tm_sec = ATOI2(dot)) > 61)
-			return(-1);
-	} else
-		lt->tm_sec = 0;
-
-	switch (strlen(str)) {
-	case 10:
-		/*
-		 * year (yy)
-		 * watch out for year 2000
-		 */
-		if ((lt->tm_year = ATOI2(str)) < 69)
-			lt->tm_year += 100;
-		str += 2;
-		/* FALLTHROUGH */
-	case 8:
-		/*
-		 * month (mm)
-		 * watch out months are from 0 - 11 internally
-		 */
-		if ((lt->tm_mon = ATOI2(str)) > 12)
-			return(-1);
-		--lt->tm_mon;
-		str += 2;
-		/* FALLTHROUGH */
-	case 6:
-		/*
-		 * day (dd)
-		 */
-		if ((lt->tm_mday = ATOI2(str)) > 31)
-			return(-1);
-		str += 2;
-		/* FALLTHROUGH */
-	case 4:
-		/*
-		 * hour (hh)
-		 */
-		if ((lt->tm_hour = ATOI2(str)) > 23)
-			return(-1);
-		str += 2;
-		/* FALLTHROUGH */
-	case 2:
-		/*
-		 * minute (mm)
-		 */
-		if ((lt->tm_min = ATOI2(str)) > 59)
-			return(-1);
-		break;
-	default:
-		return(-1);
-	}
-	/*
-	 * convert broken-down time to GMT clock time seconds
-	 */
-	if ((*tval = mktime(lt)) == -1)
-		return(-1);
-	return(0);
-}
Index: trunk/minix/commands/pax/sel_subs.h
===================================================================
--- trunk/minix/commands/pax/sel_subs.h	(revision 9)
+++ 	(revision )
@@ -1,70 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *	@(#)sel_subs.h	8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/bin/pax/sel_subs.h,v 1.6 2004/04/06 20:06:48 markm Exp $
- */
-
-/*
- * data structure for storing uid/grp selects (-U, -G non standard options)
- */
-
-#define USR_TB_SZ	317		/* user selection table size */
-#define GRP_TB_SZ	317		/* user selection table size */
-
-typedef struct usrt {
-	uid_t uid;
-	struct usrt *fow;		/* next uid */
-} USRT;
-
-typedef struct grpt {
-	gid_t gid;
-	struct grpt *fow;		/* next gid */
-} GRPT;
-
-/*
- * data structure for storing user supplied time ranges (-T option)
- */
-
-#define ATOI2(s)	((((s)[0] - '0') * 10) + ((s)[1] - '0'))
-
-typedef struct time_rng {
-	time_t		low_time;	/* lower inclusive time limit */
-	time_t		high_time;	/* higher inclusive time limit */
-	int		flgs;		/* option flags */
-#define	HASLOW		0x01		/* has lower time limit */
-#define HASHIGH		0x02		/* has higher time limit */
-#define CMPMTME		0x04		/* compare file modification time */
-#define CMPCTME		0x08		/* compare inode change time */
-#define CMPBOTH	(CMPMTME|CMPCTME)	/* compare inode and mod time */
-	struct time_rng	*fow;		/* next pattern */
-} TIME_RNG;
Index: trunk/minix/commands/pax/tables.c
===================================================================
--- trunk/minix/commands/pax/tables.c	(revision 9)
+++ 	(revision )
@@ -1,1284 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)tables.c	8.1 (Berkeley) 5/31/93";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "pax.h"
-#include "tables.h"
-#include "extern.h"
-
-/*
- * Routines for controlling the contents of all the different databases pax
- * keeps. Tables are dynamically created only when they are needed. The
- * goal was speed and the ability to work with HUGE archives. The databases
- * were kept simple, but do have complex rules for when the contents change.
- * As of this writing, the POSIX library functions were more complex than
- * needed for this application (pax databases have very short lifetimes and
- * do not survive after pax is finished). Pax is required to handle very
- * large archives. These database routines carefully combine memory usage and
- * temporary file storage in ways which will not significantly impact runtime
- * performance while allowing the largest possible archives to be handled.
- * Trying to force the fit to the POSIX databases routines was not considered
- * time well spent.
- */
-
-static HRDLNK **ltab = NULL;	/* hard link table for detecting hard links */
-static FTM **ftab = NULL;	/* file time table for updating arch */
-static NAMT **ntab = NULL;	/* interactive rename storage table */
-static DEVT **dtab = NULL;	/* device/inode mapping tables */
-static ATDIR **atab = NULL;	/* file tree directory time reset table */
-static int dirfd = -1;		/* storage for setting created dir time/mode */
-static u_long dircnt;		/* entries in dir time/mode storage */
-static int ffd = -1;		/* tmp file for file time table name storage */
-
-static DEVT *chk_dev(dev_t, int);
-
-/*
- * hard link table routines
- *
- * The hard link table tries to detect hard links to files using the device and
- * inode values. We do this when writing an archive, so we can tell the format
- * write routine that this file is a hard link to another file. The format
- * write routine then can store this file in whatever way it wants (as a hard
- * link if the format supports that like tar, or ignore this info like cpio).
- * (Actually a field in the format driver table tells us if the format wants
- * hard link info. if not, we do not waste time looking for them). We also use
- * the same table when reading an archive. In that situation, this table is
- * used by the format read routine to detect hard links from stored dev and
- * inode numbers (like cpio). This will allow pax to create a link when one
- * can be detected by the archive format.
- */
-
-/*
- * lnk_start
- *	Creates the hard link table.
- * Return:
- *	0 if created, -1 if failure
- */
-
-int
-lnk_start(void)
-{
-	if (ltab != NULL)
-		return(0);
- 	if ((ltab = (HRDLNK **)calloc(L_TAB_SZ, sizeof(HRDLNK *))) == NULL) {
-		paxwarn(1, "Cannot allocate memory for hard link table");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * chk_lnk()
- *	Looks up entry in hard link hash table. If found, it copies the name
- *	of the file it is linked to (we already saw that file) into ln_name.
- *	lnkcnt is decremented and if goes to 1 the node is deleted from the
- *	database. (We have seen all the links to this file). If not found,
- *	we add the file to the database if it has the potential for having
- *	hard links to other files we may process (it has a link count > 1)
- * Return:
- *	if found returns 1; if not found returns 0; -1 on error
- */
-
-int
-chk_lnk(ARCHD *arcn)
-{
-	HRDLNK *pt;
-	HRDLNK **ppt;
-	u_int indx;
-
-	if (ltab == NULL)
-		return(-1);
-	/*
-	 * ignore those nodes that cannot have hard links
-	 */
-	if ((arcn->type == PAX_DIR) || (arcn->sb.st_nlink <= 1))
-		return(0);
-
-	/*
-	 * hash inode number and look for this file
-	 */
-	indx = ((unsigned)arcn->sb.st_ino) % L_TAB_SZ;
-	if ((pt = ltab[indx]) != NULL) {
-		/*
-		 * it's hash chain in not empty, walk down looking for it
-		 */
-		ppt = &(ltab[indx]);
-		while (pt != NULL) {
-			if ((pt->ino == arcn->sb.st_ino) &&
-			    (pt->dev == arcn->sb.st_dev))
-				break;
-			ppt = &(pt->fow);
-			pt = pt->fow;
-		}
-
-		if (pt != NULL) {
-			/*
-			 * found a link. set the node type and copy in the
-			 * name of the file it is to link to. we need to
-			 * handle hardlinks to regular files differently than
-			 * other links.
-			 */
-			arcn->ln_nlen = l_strncpy(arcn->ln_name, pt->name,
-				sizeof(arcn->ln_name) - 1);
-			arcn->ln_name[arcn->ln_nlen] = '\0';
-			if (arcn->type == PAX_REG)
-				arcn->type = PAX_HRG;
-			else
-				arcn->type = PAX_HLK;
-
-			/*
-			 * if we have found all the links to this file, remove
-			 * it from the database
-			 */
-			if (--pt->nlink <= 1) {
-				*ppt = pt->fow;
-				(void)free((char *)pt->name);
-				(void)free((char *)pt);
-			}
-			return(1);
-		}
-	}
-
-	/*
-	 * we never saw this file before. It has links so we add it to the
-	 * front of this hash chain
-	 */
-	if ((pt = (HRDLNK *)malloc(sizeof(HRDLNK))) != NULL) {
-		if ((pt->name = strdup(arcn->name)) != NULL) {
-			pt->dev = arcn->sb.st_dev;
-			pt->ino = arcn->sb.st_ino;
-			pt->nlink = arcn->sb.st_nlink;
-			pt->fow = ltab[indx];
-			ltab[indx] = pt;
-			return(0);
-		}
-		(void)free((char *)pt);
-	}
-
-	paxwarn(1, "Hard link table out of memory");
-	return(-1);
-}
-
-/*
- * purg_lnk
- *	remove reference for a file that we may have added to the data base as
- *	a potential source for hard links. We ended up not using the file, so
- *	we do not want to accidently point another file at it later on.
- */
-
-void
-purg_lnk(ARCHD *arcn)
-{
-	HRDLNK *pt;
-	HRDLNK **ppt;
-	u_int indx;
-
-	if (ltab == NULL)
-		return;
-	/*
-	 * do not bother to look if it could not be in the database
-	 */
-	if ((arcn->sb.st_nlink <= 1) || (arcn->type == PAX_DIR) ||
-	    (arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))
-		return;
-
-	/*
-	 * find the hash chain for this inode value, if empty return
-	 */
-	indx = ((unsigned)arcn->sb.st_ino) % L_TAB_SZ;
-	if ((pt = ltab[indx]) == NULL)
-		return;
-
-	/*
-	 * walk down the list looking for the inode/dev pair, unlink and
-	 * free if found
-	 */
-	ppt = &(ltab[indx]);
-	while (pt != NULL) {
-		if ((pt->ino == arcn->sb.st_ino) &&
-		    (pt->dev == arcn->sb.st_dev))
-			break;
-		ppt = &(pt->fow);
-		pt = pt->fow;
-	}
-	if (pt == NULL)
-		return;
-
-	/*
-	 * remove and free it
-	 */
-	*ppt = pt->fow;
-	(void)free((char *)pt->name);
-	(void)free((char *)pt);
-}
-
-/*
- * lnk_end()
- *	Pull apart an existing link table so we can reuse it. We do this between
- *	read and write phases of append with update. (The format may have
- *	used the link table, and we need to start with a fresh table for the
- *	write phase).
- */
-
-void
-lnk_end(void)
-{
-	int i;
-	HRDLNK *pt;
-	HRDLNK *ppt;
-
-	if (ltab == NULL)
-		return;
-
-	for (i = 0; i < L_TAB_SZ; ++i) {
-		if (ltab[i] == NULL)
-			continue;
-		pt = ltab[i];
-		ltab[i] = NULL;
-
-		/*
-		 * free up each entry on this chain
-		 */
-		while (pt != NULL) {
-			ppt = pt;
-			pt = ppt->fow;
-			(void)free((char *)ppt->name);
-			(void)free((char *)ppt);
-		}
-	}
-	return;
-}
-
-/*
- * modification time table routines
- *
- * The modification time table keeps track of last modification times for all
- * files stored in an archive during a write phase when -u is set. We only
- * add a file to the archive if it is newer than a file with the same name
- * already stored on the archive (if there is no other file with the same
- * name on the archive it is added). This applies to writes and appends.
- * An append with an -u must read the archive and store the modification time
- * for every file on that archive before starting the write phase. It is clear
- * that this is one HUGE database. To save memory space, the actual file names
- * are stored in a scatch file and indexed by an in memory hash table. The
- * hash table is indexed by hashing the file path. The nodes in the table store
- * the length of the filename and the lseek offset within the scratch file
- * where the actual name is stored. Since there are never any deletions to this
- * table, fragmentation of the scratch file is never an issue. Lookups seem to
- * not exhibit any locality at all (files in the database are rarely
- * looked up more than once...). So caching is just a waste of memory. The
- * only limitation is the amount of scatch file space available to store the
- * path names.
- */
-
-/*
- * ftime_start()
- *	create the file time hash table and open for read/write the scratch
- *	file. (after created it is unlinked, so when we exit we leave
- *	no witnesses).
- * Return:
- *	0 if the table and file was created ok, -1 otherwise
- */
-
-int
-ftime_start(void)
-{
-
-	if (ftab != NULL)
-		return(0);
- 	if ((ftab = (FTM **)calloc(F_TAB_SZ, sizeof(FTM *))) == NULL) {
-		paxwarn(1, "Cannot allocate memory for file time table");
-		return(-1);
-	}
-
-	/*
-	 * get random name and create temporary scratch file, unlink name
-	 * so it will get removed on exit
-	 */
-	memcpy(tempbase, _TFILE_BASE, sizeof(_TFILE_BASE));
-	if ((ffd = mkstemp(tempfile)) < 0) {
-		syswarn(1, errno, "Unable to create temporary file: %s",
-		    tempfile);
-		return(-1);
-	}
-	(void)unlink(tempfile);
-
-	return(0);
-}
-
-/*
- * chk_ftime()
- *	looks up entry in file time hash table. If not found, the file is
- *	added to the hash table and the file named stored in the scratch file.
- *	If a file with the same name is found, the file times are compared and
- *	the most recent file time is retained. If the new file was younger (or
- *	was not in the database) the new file is selected for storage.
- * Return:
- *	0 if file should be added to the archive, 1 if it should be skipped,
- *	-1 on error
- */
-
-int
-chk_ftime(ARCHD *arcn)
-{
-	FTM *pt;
-	int namelen;
-	u_int indx;
-	char ckname[PAXPATHLEN+1];
-
-	/*
-	 * no info, go ahead and add to archive
-	 */
-	if (ftab == NULL)
-		return(0);
-
-	/*
-	 * hash the pathname and look up in table
-	 */
-	namelen = arcn->nlen;
-	indx = st_hash(arcn->name, namelen, F_TAB_SZ);
-	if ((pt = ftab[indx]) != NULL) {
-		/*
-		 * the hash chain is not empty, walk down looking for match
-		 * only read up the path names if the lengths match, speeds
-		 * up the search a lot
-		 */
-		while (pt != NULL) {
-			if (pt->namelen == namelen) {
-				/*
-				 * potential match, have to read the name
-				 * from the scratch file.
-				 */
-				if (lseek(ffd,pt->seek,SEEK_SET) != pt->seek) {
-					syswarn(1, errno,
-					    "Failed ftime table seek");
-					return(-1);
-				}
-				if (read(ffd, ckname, namelen) != namelen) {
-					syswarn(1, errno,
-					    "Failed ftime table read");
-					return(-1);
-				}
-
-				/*
-				 * if the names match, we are done
-				 */
-				if (!strncmp(ckname, arcn->name, namelen))
-					break;
-			}
-
-			/*
-			 * try the next entry on the chain
-			 */
-			pt = pt->fow;
-		}
-
-		if (pt != NULL) {
-			/*
-			 * found the file, compare the times, save the newer
-			 */
-			if (arcn->sb.st_mtime > pt->mtime) {
-				/*
-				 * file is newer
-				 */
-				pt->mtime = arcn->sb.st_mtime;
-				return(0);
-			}
-			/*
-			 * file is older
-			 */
-			return(1);
-		}
-	}
-
-	/*
-	 * not in table, add it
-	 */
-	if ((pt = (FTM *)malloc(sizeof(FTM))) != NULL) {
-		/*
-		 * add the name at the end of the scratch file, saving the
-		 * offset. add the file to the head of the hash chain
-		 */
-		if ((pt->seek = lseek(ffd, (off_t)0, SEEK_END)) >= 0) {
-			if (write(ffd, arcn->name, namelen) == namelen) {
-				pt->mtime = arcn->sb.st_mtime;
-				pt->namelen = namelen;
-				pt->fow = ftab[indx];
-				ftab[indx] = pt;
-				return(0);
-			}
-			syswarn(1, errno, "Failed write to file time table");
-		} else
-			syswarn(1, errno, "Failed seek on file time table");
-	} else
-		paxwarn(1, "File time table ran out of memory");
-
-	if (pt != NULL)
-		(void)free((char *)pt);
-	return(-1);
-}
-
-/*
- * Interactive rename table routines
- *
- * The interactive rename table keeps track of the new names that the user
- * assigns to files from tty input. Since this map is unique for each file
- * we must store it in case there is a reference to the file later in archive
- * (a link). Otherwise we will be unable to find the file we know was
- * extracted. The remapping of these files is stored in a memory based hash
- * table (it is assumed since input must come from /dev/tty, it is unlikely to
- * be a very large table).
- */
-
-/*
- * name_start()
- *	create the interactive rename table
- * Return:
- *	0 if successful, -1 otherwise
- */
-
-int
-name_start(void)
-{
-	if (ntab != NULL)
-		return(0);
- 	if ((ntab = (NAMT **)calloc(N_TAB_SZ, sizeof(NAMT *))) == NULL) {
-		paxwarn(1, "Cannot allocate memory for interactive rename table");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * add_name()
- *	add the new name to old name mapping just created by the user.
- *	If an old name mapping is found (there may be duplicate names on an
- *	archive) only the most recent is kept.
- * Return:
- *	0 if added, -1 otherwise
- */
-
-int
-add_name(char *oname, int onamelen, char *nname)
-{
-	NAMT *pt;
-	u_int indx;
-
-	if (ntab == NULL) {
-		/*
-		 * should never happen
-		 */
-		paxwarn(0, "No interactive rename table, links may fail\n");
-		return(0);
-	}
-
-	/*
-	 * look to see if we have already mapped this file, if so we
-	 * will update it
-	 */
-	indx = st_hash(oname, onamelen, N_TAB_SZ);
-	if ((pt = ntab[indx]) != NULL) {
-		/*
-		 * look down the has chain for the file
-		 */
-		while ((pt != NULL) && (strcmp(oname, pt->oname) != 0))
-			pt = pt->fow;
-
-		if (pt != NULL) {
-			/*
-			 * found an old mapping, replace it with the new one
-			 * the user just input (if it is different)
-			 */
-			if (strcmp(nname, pt->nname) == 0)
-				return(0);
-
-			(void)free((char *)pt->nname);
-			if ((pt->nname = strdup(nname)) == NULL) {
-				paxwarn(1, "Cannot update rename table");
-				return(-1);
-			}
-			return(0);
-		}
-	}
-
-	/*
-	 * this is a new mapping, add it to the table
-	 */
-	if ((pt = (NAMT *)malloc(sizeof(NAMT))) != NULL) {
-		if ((pt->oname = strdup(oname)) != NULL) {
-			if ((pt->nname = strdup(nname)) != NULL) {
-				pt->fow = ntab[indx];
-				ntab[indx] = pt;
-				return(0);
-			}
-			(void)free((char *)pt->oname);
-		}
-		(void)free((char *)pt);
-	}
-	paxwarn(1, "Interactive rename table out of memory");
-	return(-1);
-}
-
-/*
- * sub_name()
- *	look up a link name to see if it points at a file that has been
- *	remapped by the user. If found, the link is adjusted to contain the
- *	new name (oname is the link to name)
- */
-
-void
-sub_name(char *oname, int *onamelen, size_t onamesize)
-{
-	NAMT *pt;
-	u_int indx;
-
-	if (ntab == NULL)
-		return;
-	/*
-	 * look the name up in the hash table
-	 */
-	indx = st_hash(oname, *onamelen, N_TAB_SZ);
-	if ((pt = ntab[indx]) == NULL)
-		return;
-
-	while (pt != NULL) {
-		/*
-		 * walk down the hash chain looking for a match
-		 */
-		if (strcmp(oname, pt->oname) == 0) {
-			/*
-			 * found it, replace it with the new name
-			 * and return (we know that oname has enough space)
-			 */
-			*onamelen = l_strncpy(oname, pt->nname, onamesize - 1);
-			oname[*onamelen] = '\0';
-			return;
-		}
-		pt = pt->fow;
-	}
-
-	/*
-	 * no match, just return
-	 */
-	return;
-}
-
-/*
- * device/inode mapping table routines
- * (used with formats that store device and inodes fields)
- *
- * device/inode mapping tables remap the device field in an archive header. The
- * device/inode fields are used to determine when files are hard links to each
- * other. However these values have very little meaning outside of that. This
- * database is used to solve one of two different problems.
- *
- * 1) when files are appended to an archive, while the new files may have hard
- * links to each other, you cannot determine if they have hard links to any
- * file already stored on the archive from a prior run of pax. We must assume
- * that these inode/device pairs are unique only within a SINGLE run of pax
- * (which adds a set of files to an archive). So we have to make sure the
- * inode/dev pairs we add each time are always unique. We do this by observing
- * while the inode field is very dense, the use of the dev field is fairly
- * sparse. Within each run of pax, we remap any device number of a new archive
- * member that has a device number used in a prior run and already stored in a
- * file on the archive. During the read phase of the append, we store the
- * device numbers used and mark them to not be used by any file during the
- * write phase. If during write we go to use one of those old device numbers,
- * we remap it to a new value.
- *
- * 2) Often the fields in the archive header used to store these values are
- * too small to store the entire value. The result is an inode or device value
- * which can be truncated. This really can foul up an archive. With truncation
- * we end up creating links between files that are really not links (after
- * truncation the inodes are the same value). We address that by detecting
- * truncation and forcing a remap of the device field to split truncated
- * inodes away from each other. Each truncation creates a pattern of bits that
- * are removed. We use this pattern of truncated bits to partition the inodes
- * on a single device to many different devices (each one represented by the
- * truncated bit pattern). All inodes on the same device that have the same
- * truncation pattern are mapped to the same new device. Two inodes that
- * truncate to the same value clearly will always have different truncation
- * bit patterns, so they will be split from away each other. When we spot
- * device truncation we remap the device number to a non truncated value.
- * (for more info see table.h for the data structures involved).
- */
-
-/*
- * dev_start()
- *	create the device mapping table
- * Return:
- *	0 if successful, -1 otherwise
- */
-
-int
-dev_start(void)
-{
-	if (dtab != NULL)
-		return(0);
- 	if ((dtab = (DEVT **)calloc(D_TAB_SZ, sizeof(DEVT *))) == NULL) {
-		paxwarn(1, "Cannot allocate memory for device mapping table");
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * add_dev()
- *	add a device number to the table. this will force the device to be
- *	remapped to a new value if it be used during a write phase. This
- *	function is called during the read phase of an append to prohibit the
- *	use of any device number already in the archive.
- * Return:
- *	0 if added ok, -1 otherwise
- */
-
-int
-add_dev(ARCHD *arcn)
-{
-	if (chk_dev(arcn->sb.st_dev, 1) == NULL)
-		return(-1);
-	return(0);
-}
-
-/*
- * chk_dev()
- *	check for a device value in the device table. If not found and the add
- *	flag is set, it is added. This does NOT assign any mapping values, just
- *	adds the device number as one that need to be remapped. If this device
- *	is already mapped, just return with a pointer to that entry.
- * Return:
- *	pointer to the entry for this device in the device map table. Null
- *	if the add flag is not set and the device is not in the table (it is
- *	not been seen yet). If add is set and the device cannot be added, null
- *	is returned (indicates an error).
- */
-
-static DEVT *
-chk_dev(dev_t dev, int add)
-{
-	DEVT *pt;
-	u_int indx;
-
-	if (dtab == NULL)
-		return(NULL);
-	/*
-	 * look to see if this device is already in the table
-	 */
-	indx = ((unsigned)dev) % D_TAB_SZ;
-	if ((pt = dtab[indx]) != NULL) {
-		while ((pt != NULL) && (pt->dev != dev))
-			pt = pt->fow;
-
-		/*
-		 * found it, return a pointer to it
-		 */
-		if (pt != NULL)
-			return(pt);
-	}
-
-	/*
-	 * not in table, we add it only if told to as this may just be a check
-	 * to see if a device number is being used.
-	 */
-	if (add == 0)
-		return(NULL);
-
-	/*
-	 * allocate a node for this device and add it to the front of the hash
-	 * chain. Note we do not assign remaps values here, so the pt->list
-	 * list must be NULL.
-	 */
-	if ((pt = (DEVT *)malloc(sizeof(DEVT))) == NULL) {
-		paxwarn(1, "Device map table out of memory");
-		return(NULL);
-	}
-	pt->dev = dev;
-	pt->list = NULL;
-	pt->fow = dtab[indx];
-	dtab[indx] = pt;
-	return(pt);
-}
-/*
- * map_dev()
- *	given an inode and device storage mask (the mask has a 1 for each bit
- *	the archive format is able to store in a header), we check for inode
- *	and device truncation and remap the device as required. Device mapping
- *	can also occur when during the read phase of append a device number was
- *	seen (and was marked as do not use during the write phase). WE ASSUME
- *	that unsigned longs are the same size or bigger than the fields used
- *	for ino_t and dev_t. If not the types will have to be changed.
- * Return:
- *	0 if all ok, -1 otherwise.
- */
-
-int
-map_dev(ARCHD *arcn, u_long dev_mask, u_long ino_mask)
-{
-	DEVT *pt;
-	DLIST *dpt;
-	static dev_t lastdev = 0;	/* next device number to try */
-	int trc_ino = 0;
-	int trc_dev = 0;
-	ino_t trunc_bits = 0;
-	ino_t nino;
-
-	if (dtab == NULL)
-		return(0);
-	/*
-	 * check for device and inode truncation, and extract the truncated
-	 * bit pattern.
-	 */
-	if ((arcn->sb.st_dev & (dev_t)dev_mask) != arcn->sb.st_dev)
-		++trc_dev;
-	if ((nino = arcn->sb.st_ino & (ino_t)ino_mask) != arcn->sb.st_ino) {
-		++trc_ino;
-		trunc_bits = arcn->sb.st_ino & (ino_t)(~ino_mask);
-	}
-
-	/*
-	 * see if this device is already being mapped, look up the device
-	 * then find the truncation bit pattern which applies
-	 */
-	if ((pt = chk_dev(arcn->sb.st_dev, 0)) != NULL) {
-		/*
-		 * this device is already marked to be remapped
-		 */
-		for (dpt = pt->list; dpt != NULL; dpt = dpt->fow)
-			if (dpt->trunc_bits == trunc_bits)
-				break;
-
-		if (dpt != NULL) {
-			/*
-			 * we are being remapped for this device and pattern
-			 * change the device number to be stored and return
-			 */
-			arcn->sb.st_dev = dpt->dev;
-			arcn->sb.st_ino = nino;
-			return(0);
-		}
-	} else {
-		/*
-		 * this device is not being remapped YET. if we do not have any
-		 * form of truncation, we do not need a remap
-		 */
-		if (!trc_ino && !trc_dev)
-			return(0);
-
-		/*
-		 * we have truncation, have to add this as a device to remap
-		 */
-		if ((pt = chk_dev(arcn->sb.st_dev, 1)) == NULL)
-			goto bad;
-
-		/*
-		 * if we just have a truncated inode, we have to make sure that
-		 * all future inodes that do not truncate (they have the
-		 * truncation pattern of all 0's) continue to map to the same
-		 * device number. We probably have already written inodes with
-		 * this device number to the archive with the truncation
-		 * pattern of all 0's. So we add the mapping for all 0's to the
-		 * same device number.
-		 */
-		if (!trc_dev && (trunc_bits != 0)) {
-			if ((dpt = (DLIST *)malloc(sizeof(DLIST))) == NULL)
-				goto bad;
-			dpt->trunc_bits = 0;
-			dpt->dev = arcn->sb.st_dev;
-			dpt->fow = pt->list;
-			pt->list = dpt;
-		}
-	}
-
-	/*
-	 * look for a device number not being used. We must watch for wrap
-	 * around on lastdev (so we do not get stuck looking forever!)
-	 */
-	while (++lastdev > 0) {
-		if (chk_dev(lastdev, 0) != NULL)
-			continue;
-		/*
-		 * found an unused value. If we have reached truncation point
-		 * for this format we are hosed, so we give up. Otherwise we
-		 * mark it as being used.
-		 */
-		if (((lastdev & ((dev_t)dev_mask)) != lastdev) ||
-		    (chk_dev(lastdev, 1) == NULL))
-			goto bad;
-		break;
-	}
-
-	if ((lastdev <= 0) || ((dpt = (DLIST *)malloc(sizeof(DLIST))) == NULL))
-		goto bad;
-
-	/*
-	 * got a new device number, store it under this truncation pattern.
-	 * change the device number this file is being stored with.
-	 */
-	dpt->trunc_bits = trunc_bits;
-	dpt->dev = lastdev;
-	dpt->fow = pt->list;
-	pt->list = dpt;
-	arcn->sb.st_dev = lastdev;
-	arcn->sb.st_ino = nino;
-	return(0);
-
-    bad:
-	paxwarn(1, "Unable to fix truncated inode/device field when storing %s",
-	    arcn->name);
-	paxwarn(0, "Archive may create improper hard links when extracted");
-	return(0);
-}
-
-/*
- * directory access/mod time reset table routines (for directories READ by pax)
- *
- * The pax -t flag requires that access times of archive files to be the same
- * before being read by pax. For regular files, access time is restored after
- * the file has been copied. This database provides the same functionality for
- * directories read during file tree traversal. Restoring directory access time
- * is more complex than files since directories may be read several times until
- * all the descendants in their subtree are visited by fts. Directory access
- * and modification times are stored during the fts pre-order visit (done
- * before any descendants in the subtree is visited) and restored after the
- * fts post-order visit (after all the descendants have been visited). In the
- * case of premature exit from a subtree (like from the effects of -n), any
- * directory entries left in this database are reset during final cleanup
- * operations of pax. Entries are hashed by inode number for fast lookup.
- */
-
-/*
- * atdir_start()
- *	create the directory access time database for directories READ by pax.
- * Return:
- *	0 is created ok, -1 otherwise.
- */
-
-int
-atdir_start(void)
-{
-	if (atab != NULL)
-		return(0);
- 	if ((atab = (ATDIR **)calloc(A_TAB_SZ, sizeof(ATDIR *))) == NULL) {
-		paxwarn(1,"Cannot allocate space for directory access time table");
-		return(-1);
-	}
-	return(0);
-}
-
-
-/*
- * atdir_end()
- *	walk through the directory access time table and reset the access time
- *	of any directory who still has an entry left in the database. These
- *	entries are for directories READ by pax
- */
-
-void
-atdir_end(void)
-{
-	ATDIR *pt;
-	int i;
-
-	if (atab == NULL)
-		return;
-	/*
-	 * for each non-empty hash table entry reset all the directories
-	 * chained there.
-	 */
-	for (i = 0; i < A_TAB_SZ; ++i) {
-		if ((pt = atab[i]) == NULL)
-			continue;
-		/*
-		 * remember to force the times, set_ftime() looks at pmtime
-		 * and patime, which only applies to things CREATED by pax,
-		 * not read by pax. Read time reset is controlled by -t.
-		 */
-		for (; pt != NULL; pt = pt->fow)
-			set_ftime(pt->name, pt->mtime, pt->atime, 1);
-	}
-}
-
-/*
- * add_atdir()
- *	add a directory to the directory access time table. Table is hashed
- *	and chained by inode number. This is for directories READ by pax
- */
-
-void
-add_atdir(char *fname, dev_t dev, ino_t ino, time_t mtime, time_t atime)
-{
-	ATDIR *pt;
-	u_int indx;
-
-	if (atab == NULL)
-		return;
-
-	/*
-	 * make sure this directory is not already in the table, if so just
-	 * return (the older entry always has the correct time). The only
-	 * way this will happen is when the same subtree can be traversed by
-	 * different args to pax and the -n option is aborting fts out of a
-	 * subtree before all the post-order visits have been made).
-	 */
-	indx = ((unsigned)ino) % A_TAB_SZ;
-	if ((pt = atab[indx]) != NULL) {
-		while (pt != NULL) {
-			if ((pt->ino == ino) && (pt->dev == dev))
-				break;
-			pt = pt->fow;
-		}
-
-		/*
-		 * oops, already there. Leave it alone.
-		 */
-		if (pt != NULL)
-			return;
-	}
-
-	/*
-	 * add it to the front of the hash chain
-	 */
-	if ((pt = (ATDIR *)malloc(sizeof(ATDIR))) != NULL) {
-		if ((pt->name = strdup(fname)) != NULL) {
-			pt->dev = dev;
-			pt->ino = ino;
-			pt->mtime = mtime;
-			pt->atime = atime;
-			pt->fow = atab[indx];
-			atab[indx] = pt;
-			return;
-		}
-		(void)free((char *)pt);
-	}
-
-	paxwarn(1, "Directory access time reset table ran out of memory");
-	return;
-}
-
-/*
- * get_atdir()
- *	look up a directory by inode and device number to obtain the access
- *	and modification time you want to set to. If found, the modification
- *	and access time parameters are set and the entry is removed from the
- *	table (as it is no longer needed). These are for directories READ by
- *	pax
- * Return:
- *	0 if found, -1 if not found.
- */
-
-int
-get_atdir(dev_t dev, ino_t ino, time_t *mtime, time_t *atime)
-{
-	ATDIR *pt;
-	ATDIR **ppt;
-	u_int indx;
-
-	if (atab == NULL)
-		return(-1);
-	/*
-	 * hash by inode and search the chain for an inode and device match
-	 */
-	indx = ((unsigned)ino) % A_TAB_SZ;
-	if ((pt = atab[indx]) == NULL)
-		return(-1);
-
-	ppt = &(atab[indx]);
-	while (pt != NULL) {
-		if ((pt->ino == ino) && (pt->dev == dev))
-			break;
-		/*
-		 * no match, go to next one
-		 */
-		ppt = &(pt->fow);
-		pt = pt->fow;
-	}
-
-	/*
-	 * return if we did not find it.
-	 */
-	if (pt == NULL)
-		return(-1);
-
-	/*
-	 * found it. return the times and remove the entry from the table.
-	 */
-	*ppt = pt->fow;
-	*mtime = pt->mtime;
-	*atime = pt->atime;
-	(void)free((char *)pt->name);
-	(void)free((char *)pt);
-	return(0);
-}
-
-/*
- * directory access mode and time storage routines (for directories CREATED
- * by pax).
- *
- * Pax requires that extracted directories, by default, have their access/mod
- * times and permissions set to the values specified in the archive. During the
- * actions of extracting (and creating the destination subtree during -rw copy)
- * directories extracted may be modified after being created. Even worse is
- * that these directories may have been created with file permissions which
- * prohibits any descendants of these directories from being extracted. When
- * directories are created by pax, access rights may be added to permit the
- * creation of files in their subtree. Every time pax creates a directory, the
- * times and file permissions specified by the archive are stored. After all
- * files have been extracted (or copied), these directories have their times
- * and file modes reset to the stored values. The directory info is restored in
- * reverse order as entries were added to the data file from root to leaf. To
- * restore atime properly, we must go backwards. The data file consists of
- * records with two parts, the file name followed by a DIRDATA trailer. The
- * fixed sized trailer contains the size of the name plus the off_t location in
- * the file. To restore we work backwards through the file reading the trailer
- * then the file name.
- */
-
-/*
- * dir_start()
- *	set up the directory time and file mode storage for directories CREATED
- *	by pax.
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-dir_start(void)
-{
-
-	if (dirfd != -1)
-		return(0);
-
-	/*
-	 * unlink the file so it goes away at termination by itself
-	 */
-	memcpy(tempbase, _TFILE_BASE, sizeof(_TFILE_BASE));
-	if ((dirfd = mkstemp(tempfile)) >= 0) {
-		(void)unlink(tempfile);
-		return(0);
-	}
-	paxwarn(1, "Unable to create temporary file for directory times: %s",
-	    tempfile);
-	return(-1);
-}
-
-/*
- * add_dir()
- *	add the mode and times for a newly CREATED directory
- *	name is name of the directory, psb the stat buffer with the data in it,
- *	frc_mode is a flag that says whether to force the setting of the mode
- *	(ignoring the user set values for preserving file mode). Frc_mode is
- *	for the case where we created a file and found that the resulting
- *	directory was not writeable and the user asked for file modes to NOT
- *	be preserved. (we have to preserve what was created by default, so we
- *	have to force the setting at the end. this is stated explicitly in the
- *	pax spec)
- */
-
-void
-add_dir(char *name, int nlen, struct stat *psb, int frc_mode)
-{
-	DIRDATA dblk;
-
-	if (dirfd < 0)
-		return;
-
-	/*
-	 * get current position (where file name will start) so we can store it
-	 * in the trailer
-	 */
-	if ((dblk.npos = lseek(dirfd, 0L, SEEK_CUR)) < 0) {
-		paxwarn(1,"Unable to store mode and times for directory: %s",name);
-		return;
-	}
-
-	/*
-	 * write the file name followed by the trailer
-	 */
-	dblk.nlen = nlen + 1;
-	dblk.mode = psb->st_mode & 0xffff;
-	dblk.mtime = psb->st_mtime;
-	dblk.atime = psb->st_atime;
-	dblk.frc_mode = frc_mode;
-	if ((write(dirfd, name, dblk.nlen) == dblk.nlen) &&
-	    (write(dirfd, (char *)&dblk, sizeof(dblk)) == sizeof(dblk))) {
-		++dircnt;
-		return;
-	}
-
-	paxwarn(1,"Unable to store mode and times for created directory: %s",name);
-	return;
-}
-
-/*
- * proc_dir()
- *	process all file modes and times stored for directories CREATED
- *	by pax
- */
-
-void
-proc_dir(void)
-{
-	char name[PAXPATHLEN+1];
-	DIRDATA dblk;
-	u_long cnt;
-
-	if (dirfd < 0)
-		return;
-	/*
-	 * read backwards through the file and process each directory
-	 */
-	for (cnt = 0; cnt < dircnt; ++cnt) {
-		/*
-		 * read the trailer, then the file name, if this fails
-		 * just give up.
-		 */
-		if (lseek(dirfd, -((off_t)sizeof(dblk)), SEEK_CUR) < 0)
-			break;
-		if (read(dirfd,(char *)&dblk, sizeof(dblk)) != sizeof(dblk))
-			break;
-		if (lseek(dirfd, dblk.npos, SEEK_SET) < 0)
-			break;
-		if (read(dirfd, name, dblk.nlen) != dblk.nlen)
-			break;
-		if (lseek(dirfd, dblk.npos, SEEK_SET) < 0)
-			break;
-
-		/*
-		 * frc_mode set, make sure we set the file modes even if
-		 * the user didn't ask for it (see file_subs.c for more info)
-		 */
-		if (pmode || dblk.frc_mode)
-			set_pmode(name, dblk.mode);
-		if (patime || pmtime)
-			set_ftime(name, dblk.mtime, dblk.atime, 0);
-	}
-
-	(void)close(dirfd);
-	dirfd = -1;
-	if (cnt != dircnt)
-		paxwarn(1,"Unable to set mode and times for created directories");
-	return;
-}
-
-/*
- * database independent routines
- */
-
-/*
- * st_hash()
- *	hashes filenames to a u_int for hashing into a table. Looks at the tail
- *	end of file, as this provides far better distribution than any other
- *	part of the name. For performance reasons we only care about the last
- *	MAXKEYLEN chars (should be at LEAST large enough to pick off the file
- *	name). Was tested on 500,000 name file tree traversal from the root
- *	and gave almost a perfectly uniform distribution of keys when used with
- *	prime sized tables (MAXKEYLEN was 128 in test). Hashes (sizeof int)
- *	chars at a time and pads with 0 for last addition.
- * Return:
- *	the hash value of the string MOD (%) the table size.
- */
-
-u_int
-st_hash(char *name, int len, int tabsz)
-{
-	char *pt;
-	char *dest;
-	char *end;
-	int i;
-	u_int key = 0;
-	int steps;
-	int res;
-	u_int val;
-
-	/*
-	 * only look at the tail up to MAXKEYLEN, we do not need to waste
-	 * time here (remember these are pathnames, the tail is what will
-	 * spread out the keys)
-	 */
-	if (len > MAXKEYLEN) {
-		pt = &(name[len - MAXKEYLEN]);
-		len = MAXKEYLEN;
-	} else
-		pt = name;
-
-	/*
-	 * calculate the number of u_int size steps in the string and if
-	 * there is a runt to deal with
-	 */
-	steps = len/sizeof(u_int);
-	res = len % sizeof(u_int);
-
-	/*
-	 * add up the value of the string in unsigned integer sized pieces
-	 * too bad we cannot have unsigned int aligned strings, then we
-	 * could avoid the expensive copy.
-	 */
-	for (i = 0; i < steps; ++i) {
-		end = pt + sizeof(u_int);
-		dest = (char *)&val;
-		while (pt < end)
-			*dest++ = *pt++;
-		key += val;
-	}
-
-	/*
-	 * add in the runt padded with zero to the right
-	 */
-	if (res) {
-		val = 0;
-		end = pt + res;
-		dest = (char *)&val;
-		while (pt < end)
-			*dest++ = *pt++;
-		key += val;
-	}
-
-	/*
-	 * return the result mod the table size
-	 */
-	return(key % tabsz);
-}
Index: trunk/minix/commands/pax/tables.h
===================================================================
--- trunk/minix/commands/pax/tables.h	(revision 9)
+++ 	(revision )
@@ -1,169 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *	@(#)tables.h	8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/bin/pax/tables.h,v 1.10 2004/04/06 20:06:48 markm Exp $
- */
-
-/*
- * data structures and constants used by the different databases kept by pax
- */
-
-/*
- * Hash Table Sizes MUST BE PRIME, if set too small performance suffers.
- * Probably safe to expect 500000 inodes per tape. Assuming good key
- * distribution (inodes) chains of under 50 long (worse case) is ok.
- */
-#define L_TAB_SZ	2503		/* hard link hash table size */
-#define F_TAB_SZ	50503		/* file time hash table size */
-#define N_TAB_SZ	541		/* interactive rename hash table */
-#define D_TAB_SZ	317		/* unique device mapping table */
-#define A_TAB_SZ	317		/* ftree dir access time reset table */
-#define MAXKEYLEN	64		/* max number of chars for hash */
-
-/*
- * file hard link structure (hashed by dev/ino and chained) used to find the
- * hard links in a file system or with some archive formats (cpio)
- */
-typedef struct hrdlnk {
-	char		*name;	/* name of first file seen with this ino/dev */
-	dev_t		dev;	/* files device number */
-	ino_t		ino;	/* files inode number */
-	u_long		nlink;	/* expected link count */
-	struct hrdlnk	*fow;
-} HRDLNK;
-
-/*
- * Archive write update file time table (the -u, -C flag), hashed by filename.
- * Filenames are stored in a scratch file at seek offset into the file. The
- * file time (mod time) and the file name length (for a quick check) are
- * stored in a hash table node. We were forced to use a scratch file because
- * with -u, the mtime for every node in the archive must always be available
- * to compare against (and this data can get REALLY large with big archives).
- * By being careful to read only when we have a good chance of a match, the
- * performance loss is not measurable (and the size of the archive we can
- * handle is greatly increased).
- */
-typedef struct ftm {
-	int		namelen;	/* file name length */
-	time_t		mtime;		/* files last modification time */
-	off_t		seek;		/* location in scratch file */
-	struct ftm	*fow;
-} FTM;
-
-/*
- * Interactive rename table (-i flag), hashed by orig filename.
- * We assume this will not be a large table as this mapping data can only be
- * obtained through interactive input by the user. Nobody is going to type in
- * changes for 500000 files? We use chaining to resolve collisions.
- */
-
-typedef struct namt {
-	char		*oname;		/* old name */
-	char		*nname;		/* new name typed in by the user */
-	struct namt	*fow;
-} NAMT;
-
-/*
- * Unique device mapping tables. Some protocols (e.g. cpio) require that the
- * <c_dev,c_ino> pair will uniquely identify a file in an archive unless they
- * are links to the same file. Appending to archives can break this. For those
- * protocols that have this requirement we map c_dev to a unique value not seen
- * in the archive when we append. We also try to handle inode truncation with
- * this table. (When the inode field in the archive header are too small, we
- * remap the dev on writes to remove accidental collisions).
- *
- * The list is hashed by device number using chain collision resolution. Off of
- * each DEVT are linked the various remaps for this device based on those bits
- * in the inode which were truncated. For example if we are just remapping to
- * avoid a device number during an update append, off the DEVT we would have
- * only a single DLIST that has a truncation id of 0 (no inode bits were
- * stripped for this device so far). When we spot inode truncation we create
- * a new mapping based on the set of bits in the inode which were stripped off.
- * so if the top four bits of the inode are stripped and they have a pattern of
- * 0110...... (where . are those bits not truncated) we would have a mapping
- * assigned for all inodes that has the same 0110.... pattern (with this dev
- * number of course). This keeps the mapping sparse and should be able to store
- * close to the limit of files which can be represented by the optimal
- * combination of dev and inode bits, and without creating a fouled up archive.
- * Note we also remap truncated devs in the same way (an exercise for the
- * dedicated reader; always wanted to say that...:)
- */
-
-typedef struct devt {
-	dev_t		dev;	/* the orig device number we now have to map */
-	struct devt	*fow;	/* new device map list */
-	struct dlist	*list;	/* map list based on inode truncation bits */
-} DEVT;
-
-typedef struct dlist {
-	ino_t trunc_bits;	/* truncation pattern for a specific map */
-	dev_t dev;		/* the new device id we use */
-	struct dlist *fow;
-} DLIST;
-
-/*
- * ftree directory access time reset table. When we are done with with a
- * subtree we reset the access and mod time of the directory when the tflag is
- * set. Not really explicitly specified in the pax spec, but easy and fast to
- * do (and this may have even been intended in the spec, it is not clear).
- * table is hashed by inode with chaining.
- */
-
-typedef struct atdir {
-	char *name;	/* name of directory to reset */
-	dev_t dev;	/* dev and inode for fast lookup */
-	ino_t ino;
-	time_t mtime;	/* access and mod time to reset to */
-	time_t atime;
-	struct atdir *fow;
-} ATDIR;
-
-/*
- * created directory time and mode storage entry. After pax is finished during
- * extraction or copy, we must reset directory access modes and times that
- * may have been modified after creation (they no longer have the specified
- * times and/or modes). We must reset time in the reverse order of creation,
- * because entries are added  from the top of the file tree to the bottom.
- * We MUST reset times from leaf to root (it will not work the other
- * direction).  Entries are recorded into a spool file to make reverse
- * reading faster.
- */
-
-typedef struct dirdata {
-	int nlen;	/* length of the directory name (includes \0) */
-	off_t npos;	/* position in file where this dir name starts */
-	mode_t mode;	/* file mode to restore */
-	time_t mtime;	/* mtime to set */
-	time_t atime;	/* atime to set */
-	int frc_mode;	/* do we force mode settings? */
-} DIRDATA;
Index: trunk/minix/commands/pax/tar.c
===================================================================
--- trunk/minix/commands/pax/tar.c	(revision 9)
+++ 	(revision )
@@ -1,1121 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)tar.c	8.2 (Berkeley) 4/18/94";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "pax.h"
-#include "extern.h"
-#include "tar.h"
-
-/*
- * Routines for reading, writing and header identify of various versions of tar
- */
-
-static u_long tar_chksm(char *, int);
-static char *name_split(char *, int);
-static int ul_oct(u_long, char *, int, int);
-#ifndef NET2_STAT
-static int uqd_oct(u_quad_t, char *, int, int);
-#endif
-
-/*
- * Routines common to all versions of tar
- */
-
-static int tar_nodir;			/* do not write dirs under old tar */
-
-/*
- * tar_endwr()
- *	add the tar trailer of two null blocks
- * Return:
- *	0 if ok, -1 otherwise (what wr_skip returns)
- */
-
-int
-tar_endwr(void)
-{
-	return(wr_skip((off_t)(NULLCNT*BLKMULT)));
-}
-
-/*
- * tar_endrd()
- *	no cleanup needed here, just return size of trailer (for append)
- * Return:
- *	size of trailer (2 * BLKMULT)
- */
-
-off_t
-tar_endrd(void)
-{
-	return((off_t)(NULLCNT*BLKMULT));
-}
-
-/*
- * tar_trail()
- *	Called to determine if a header block is a valid trailer. We are passed
- *	the block, the in_sync flag (which tells us we are in resync mode;
- *	looking for a valid header), and cnt (which starts at zero) which is
- *	used to count the number of empty blocks we have seen so far.
- * Return:
- *	0 if a valid trailer, -1 if not a valid trailer, or 1 if the block
- *	could never contain a header.
- */
-
-int
-tar_trail(char *buf, int in_resync, int *cnt)
-{
-	int i;
-
-	/*
-	 * look for all zero, trailer is two consecutive blocks of zero
-	 */
-	for (i = 0; i < BLKMULT; ++i) {
-		if (buf[i] != '\0')
-			break;
-	}
-
-	/*
-	 * if not all zero it is not a trailer, but MIGHT be a header.
-	 */
-	if (i != BLKMULT)
-		return(-1);
-
-	/*
-	 * When given a zero block, we must be careful!
-	 * If we are not in resync mode, check for the trailer. Have to watch
-	 * out that we do not mis-identify file data as the trailer, so we do
-	 * NOT try to id a trailer during resync mode. During resync mode we
-	 * might as well throw this block out since a valid header can NEVER be
-	 * a block of all 0 (we must have a valid file name).
-	 */
-	if (!in_resync && (++*cnt >= NULLCNT))
-		return(0);
-	return(1);
-}
-
-/*
- * ul_oct()
- *	convert an unsigned long to an octal string. many oddball field
- *	termination characters are used by the various versions of tar in the
- *	different fields. term selects which kind to use. str is '0' padded
- *	at the front to len. we are unable to use only one format as many old
- *	tar readers are very cranky about this.
- * Return:
- *	0 if the number fit into the string, -1 otherwise
- */
-
-static int
-ul_oct(u_long val, char *str, int len, int term)
-{
-	char *pt;
-
-	/*
-	 * term selects the appropriate character(s) for the end of the string
-	 */
-	pt = str + len - 1;
-	switch(term) {
-	case 3:
-		*pt-- = '\0';
-		break;
-	case 2:
-		*pt-- = ' ';
-		*pt-- = '\0';
-		break;
-	case 1:
-		*pt-- = ' ';
-		break;
-	case 0:
-	default:
-		*pt-- = '\0';
-		*pt-- = ' ';
-		break;
-	}
-
-	/*
-	 * convert and blank pad if there is space
-	 */
-	while (pt >= str) {
-		*pt-- = '0' + (char)(val & 0x7);
-		if ((val = val >> 3) == (u_long)0)
-			break;
-	}
-
-	while (pt >= str)
-		*pt-- = '0';
-	if (val != (u_long)0)
-		return(-1);
-	return(0);
-}
-
-#ifndef NET2_STAT
-/*
- * uqd_oct()
- *	convert an u_quad_t to an octal string. one of many oddball field
- *	termination characters are used by the various versions of tar in the
- *	different fields. term selects which kind to use. str is '0' padded
- *	at the front to len. we are unable to use only one format as many old
- *	tar readers are very cranky about this.
- * Return:
- *	0 if the number fit into the string, -1 otherwise
- */
-
-static int
-uqd_oct(u_quad_t val, char *str, int len, int term)
-{
-	char *pt;
-
-	/*
-	 * term selects the appropriate character(s) for the end of the string
-	 */
-	pt = str + len - 1;
-	switch(term) {
-	case 3:
-		*pt-- = '\0';
-		break;
-	case 2:
-		*pt-- = ' ';
-		*pt-- = '\0';
-		break;
-	case 1:
-		*pt-- = ' ';
-		break;
-	case 0:
-	default:
-		*pt-- = '\0';
-		*pt-- = ' ';
-		break;
-	}
-
-	/*
-	 * convert and blank pad if there is space
-	 */
-	while (pt >= str) {
-		*pt-- = '0' + (char)(val & 0x7);
-		if ((val = val >> 3) == 0)
-			break;
-	}
-
-	while (pt >= str)
-		*pt-- = '0';
-	if (val != (u_quad_t)0)
-		return(-1);
-	return(0);
-}
-#endif
-
-/*
- * tar_chksm()
- *	calculate the checksum for a tar block counting the checksum field as
- *	all blanks (BLNKSUM is that value pre-calculated, the sum of 8 blanks).
- *	NOTE: we use len to short circuit summing 0's on write since we ALWAYS
- *	pad headers with 0.
- * Return:
- *	unsigned long checksum
- */
-
-static u_long
-tar_chksm(char *blk, int len)
-{
-	char *stop;
-	char *pt;
-	u_long chksm = BLNKSUM;	/* initial value is checksum field sum */
-
-	/*
-	 * add the part of the block before the checksum field
-	 */
-	pt = blk;
-	stop = blk + CHK_OFFSET;
-	while (pt < stop)
-		chksm += (u_long)(*pt++ & 0xff);
-	/*
-	 * move past the checksum field and keep going, spec counts the
-	 * checksum field as the sum of 8 blanks (which is pre-computed as
-	 * BLNKSUM).
-	 * ASSUMED: len is greater than CHK_OFFSET. (len is where our 0 padding
-	 * starts, no point in summing zero's)
-	 */
-	pt += CHK_LEN;
-	stop = blk + len;
-	while (pt < stop)
-		chksm += (u_long)(*pt++ & 0xff);
-	return(chksm);
-}
-
-/*
- * Routines for old BSD style tar (also made portable to sysV tar)
- */
-
-/*
- * tar_id()
- *	determine if a block given to us is a valid tar header (and not a USTAR
- *	header). We have to be on the lookout for those pesky blocks of	all
- *	zero's.
- * Return:
- *	0 if a tar header, -1 otherwise
- */
-
-int
-tar_id(char *blk, int size)
-{
-	HD_TAR *hd;
-	HD_USTAR *uhd;
-
-	if (size < BLKMULT)
-		return(-1);
-	hd = (HD_TAR *)blk;
-	uhd = (HD_USTAR *)blk;
-
-	/*
-	 * check for block of zero's first, a simple and fast test, then make
-	 * sure this is not a ustar header by looking for the ustar magic
-	 * cookie. We should use TMAGLEN, but some USTAR archive programs are
-	 * wrong and create archives missing the \0. Last we check the
-	 * checksum. If this is ok we have to assume it is a valid header.
-	 */
-	if (hd->name[0] == '\0')
-		return(-1);
-	if (strncmp(uhd->magic, TMAGIC, TMAGLEN - 1) == 0)
-		return(-1);
-	if (asc_ul(hd->chksum,sizeof(hd->chksum),OCT) != tar_chksm(blk,BLKMULT))
-		return(-1);
-	return(0);
-}
-
-/*
- * tar_opt()
- *	handle tar format specific -o options
- * Return:
- *	0 if ok -1 otherwise
- */
-
-int
-tar_opt(void)
-{
-	OPLIST *opt;
-
-	while ((opt = opt_next()) != NULL) {
-		if (strcmp(opt->name, TAR_OPTION) ||
-		    strcmp(opt->value, TAR_NODIR)) {
-			paxwarn(1, "Unknown tar format -o option/value pair %s=%s",
-			    opt->name, opt->value);
-			paxwarn(1,"%s=%s is the only supported tar format option",
-			    TAR_OPTION, TAR_NODIR);
-			return(-1);
-		}
-
-		/*
-		 * we only support one option, and only when writing
-		 */
-		if ((act != APPND) && (act != ARCHIVE)) {
-			paxwarn(1, "%s=%s is only supported when writing.",
-			    opt->name, opt->value);
-			return(-1);
-		}
-		tar_nodir = 1;
-	}
-	return(0);
-}
-
-
-/*
- * tar_rd()
- *	extract the values out of block already determined to be a tar header.
- *	store the values in the ARCHD parameter.
- * Return:
- *	0
- */
-
-int
-tar_rd(ARCHD *arcn, char *buf)
-{
-	HD_TAR *hd;
-	char *pt;
-
-	/*
-	 * we only get proper sized buffers passed to us
-	 */
-	if (tar_id(buf, BLKMULT) < 0)
-		return(-1);
-	arcn->org_name = arcn->name;
-	arcn->sb.st_nlink = 1;
-	arcn->pat = NULL;
-
-	/*
-	 * copy out the name and values in the stat buffer
-	 */
-	hd = (HD_TAR *)buf;
-	/*
-	 * old tar format specifies the name always be null-terminated,
-	 * but let's be robust to broken archives.
-	 * the same applies to handling links below.
-	 */
-	arcn->nlen = l_strncpy(arcn->name, hd->name,
-	    MIN(sizeof(hd->name), sizeof(arcn->name)) - 1);
-	arcn->name[arcn->nlen] = '\0';
-	arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode,sizeof(hd->mode),OCT) &
-	    0xfff);
-	arcn->sb.st_uid = (uid_t)asc_ul(hd->uid, sizeof(hd->uid), OCT);
-	arcn->sb.st_gid = (gid_t)asc_ul(hd->gid, sizeof(hd->gid), OCT);
-#ifdef NET2_STAT
-	arcn->sb.st_size = (off_t)asc_ul(hd->size, sizeof(hd->size), OCT);
-	arcn->sb.st_mtime = (time_t)asc_ul(hd->mtime, sizeof(hd->mtime), OCT);
-#else
-	arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT);
-	arcn->sb.st_mtime = (time_t)asc_uqd(hd->mtime, sizeof(hd->mtime), OCT);
-#endif
-	arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
-
-	/*
-	 * have to look at the last character, it may be a '/' and that is used
-	 * to encode this as a directory
-	 */
-	pt = &(arcn->name[arcn->nlen - 1]);
-	arcn->pad = 0;
-	arcn->skip = 0;
-	switch(hd->linkflag) {
-	case SYMTYPE:
-		/*
-		 * symbolic link, need to get the link name and set the type in
-		 * the st_mode so -v printing will look correct.
-		 */
-		arcn->type = PAX_SLK;
-		arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname,
-		    MIN(sizeof(hd->linkname), sizeof(arcn->ln_name)) - 1);
-		arcn->ln_name[arcn->ln_nlen] = '\0';
-		arcn->sb.st_mode |= S_IFLNK;
-		break;
-	case LNKTYPE:
-		/*
-		 * hard link, need to get the link name, set the type in the
-		 * st_mode and st_nlink so -v printing will look better.
-		 */
-		arcn->type = PAX_HLK;
-		arcn->sb.st_nlink = 2;
-		arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname,
-		    MIN(sizeof(hd->linkname), sizeof(arcn->ln_name)) - 1);
-		arcn->ln_name[arcn->ln_nlen] = '\0';
-
-		/*
-		 * no idea of what type this thing really points at, but
-		 * we set something for printing only.
-		 */
-		arcn->sb.st_mode |= S_IFREG;
-		break;
-	case DIRTYPE:
-		/*
-		 * It is a directory, set the mode for -v printing
-		 */
-		arcn->type = PAX_DIR;
-		arcn->sb.st_mode |= S_IFDIR;
-		arcn->sb.st_nlink = 2;
-		arcn->ln_name[0] = '\0';
-		arcn->ln_nlen = 0;
-		break;
-	case AREGTYPE:
-	case REGTYPE:
-	default:
-		/*
-		 * If we have a trailing / this is a directory and NOT a file.
-		 */
-		arcn->ln_name[0] = '\0';
-		arcn->ln_nlen = 0;
-		if (*pt == '/') {
-			/*
-			 * it is a directory, set the mode for -v printing
-			 */
-			arcn->type = PAX_DIR;
-			arcn->sb.st_mode |= S_IFDIR;
-			arcn->sb.st_nlink = 2;
-		} else {
-			/*
-			 * have a file that will be followed by data. Set the
-			 * skip value to the size field and calculate the size
-			 * of the padding.
-			 */
-			arcn->type = PAX_REG;
-			arcn->sb.st_mode |= S_IFREG;
-			arcn->pad = TAR_PAD(arcn->sb.st_size);
-			arcn->skip = arcn->sb.st_size;
-		}
-		break;
-	}
-
-	/*
-	 * strip off any trailing slash.
-	 */
-	if (*pt == '/') {
-		*pt = '\0';
-		--arcn->nlen;
-	}
-	return(0);
-}
-
-/*
- * tar_wr()
- *	write a tar header for the file specified in the ARCHD to the archive.
- *	Have to check for file types that cannot be stored and file names that
- *	are too long. Be careful of the term (last arg) to ul_oct, each field
- *	of tar has it own spec for the termination character(s).
- *	ASSUMED: space after header in header block is zero filled
- * Return:
- *	0 if file has data to be written after the header, 1 if file has NO
- *	data to write after the header, -1 if archive write failed
- */
-
-int
-tar_wr(ARCHD *arcn)
-{
-	HD_TAR *hd;
-	int len;
-	char hdblk[sizeof(HD_TAR)];
-
-	/*
-	 * check for those file system types which tar cannot store
-	 */
-	switch(arcn->type) {
-	case PAX_DIR:
-		/*
-		 * user asked that dirs not be written to the archive
-		 */
-		if (tar_nodir)
-			return(1);
-		break;
-	case PAX_CHR:
-		paxwarn(1, "Tar cannot archive a character device %s",
-		    arcn->org_name);
-		return(1);
-	case PAX_BLK:
-		paxwarn(1, "Tar cannot archive a block device %s", arcn->org_name);
-		return(1);
-	case PAX_SCK:
-		paxwarn(1, "Tar cannot archive a socket %s", arcn->org_name);
-		return(1);
-	case PAX_FIF:
-		paxwarn(1, "Tar cannot archive a fifo %s", arcn->org_name);
-		return(1);
-	case PAX_SLK:
-	case PAX_HLK:
-	case PAX_HRG:
-		if (arcn->ln_nlen >= (int)sizeof(hd->linkname)) {
-			paxwarn(1,"Link name too long for tar %s", arcn->ln_name);
-			return(1);
-		}
-		break;
-	case PAX_REG:
-	case PAX_CTG:
-	default:
-		break;
-	}
-
-	/*
-	 * check file name len, remember extra char for dirs (the / at the end)
-	 */
-	len = arcn->nlen;
-	if (arcn->type == PAX_DIR)
-		++len;
-	if (len >= (int)sizeof(hd->name)) {
-		paxwarn(1, "File name too long for tar %s", arcn->name);
-		return(1);
-	}
-
-	/*
-	 * copy the data out of the ARCHD into the tar header based on the type
-	 * of the file. Remember many tar readers want the unused fields to be
-	 * padded with zero. We set the linkflag field (type), the linkname
-	 * (or zero if not used),the size, and set the padding (if any) to be
-	 * added after the file data (0 for all other types, as they only have
-	 * a header)
-	 */
-	hd = (HD_TAR *)hdblk;
-	l_strncpy(hd->name, arcn->name, sizeof(hd->name) - 1);
-	hd->name[sizeof(hd->name) - 1] = '\0';
-	arcn->pad = 0;
-
-	if (arcn->type == PAX_DIR) {
-		/*
-		 * directories are the same as files, except have a filename
-		 * that ends with a /, we add the slash here. No data follows,
-		 * dirs, so no pad.
-		 */
-		hd->linkflag = AREGTYPE;
-		memset(hd->linkname, 0, sizeof(hd->linkname));
-		hd->name[len-1] = '/';
-		if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1))
-			goto out;
-	} else if (arcn->type == PAX_SLK) {
-		/*
-		 * no data follows this file, so no pad
-		 */
-		hd->linkflag = SYMTYPE;
-		l_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1);
-		hd->linkname[sizeof(hd->linkname) - 1] = '\0';
-		if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1))
-			goto out;
-	} else if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG)) {
-		/*
-		 * no data follows this file, so no pad
-		 */
-		hd->linkflag = LNKTYPE;
-		l_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1);
-		hd->linkname[sizeof(hd->linkname) - 1] = '\0';
-		if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1))
-			goto out;
-	} else {
-		/*
-		 * data follows this file, so set the pad
-		 */
-		hd->linkflag = AREGTYPE;
-		memset(hd->linkname, 0, sizeof(hd->linkname));
-#		ifdef NET2_STAT
-		if (ul_oct((u_long)arcn->sb.st_size, hd->size,
-		    sizeof(hd->size), 1)) {
-#		else
-		if (uqd_oct((u_quad_t)arcn->sb.st_size, hd->size,
-		    sizeof(hd->size), 1)) {
-#		endif
-			paxwarn(1,"File is too large for tar %s", arcn->org_name);
-			return(1);
-		}
-		arcn->pad = TAR_PAD(arcn->sb.st_size);
-	}
-
-	/*
-	 * copy those fields that are independent of the type
-	 */
-	if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 0) ||
-	    ul_oct((u_long)arcn->sb.st_uid, hd->uid, sizeof(hd->uid), 0) ||
-	    ul_oct((u_long)arcn->sb.st_gid, hd->gid, sizeof(hd->gid), 0) ||
-	    ul_oct((u_long)arcn->sb.st_mtime, hd->mtime, sizeof(hd->mtime), 1))
-		goto out;
-
-	/*
-	 * calculate and add the checksum, then write the header. A return of
-	 * 0 tells the caller to now write the file data, 1 says no data needs
-	 * to be written
-	 */
-	if (ul_oct(tar_chksm(hdblk, sizeof(HD_TAR)), hd->chksum,
-	    sizeof(hd->chksum), 3))
-		goto out;
-	if (wr_rdbuf(hdblk, sizeof(HD_TAR)) < 0)
-		return(-1);
-	if (wr_skip((off_t)(BLKMULT - sizeof(HD_TAR))) < 0)
-		return(-1);
-	if ((arcn->type == PAX_CTG) || (arcn->type == PAX_REG))
-		return(0);
-	return(1);
-
-    out:
-	/*
-	 * header field is out of range
-	 */
-	paxwarn(1, "Tar header field is too small for %s", arcn->org_name);
-	return(1);
-}
-
-/*
- * Routines for POSIX ustar
- */
-
-/*
- * ustar_strd()
- *	initialization for ustar read
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-ustar_strd(void)
-{
-	if ((usrtb_start() < 0) || (grptb_start() < 0))
-		return(-1);
-	return(0);
-}
-
-/*
- * ustar_stwr()
- *	initialization for ustar write
- * Return:
- *	0 if ok, -1 otherwise
- */
-
-int
-ustar_stwr(void)
-{
-	if ((uidtb_start() < 0) || (gidtb_start() < 0))
-		return(-1);
-	return(0);
-}
-
-/*
- * ustar_id()
- *	determine if a block given to us is a valid ustar header. We have to
- *	be on the lookout for those pesky blocks of all zero's
- * Return:
- *	0 if a ustar header, -1 otherwise
- */
-
-int
-ustar_id(char *blk, int size)
-{
-	HD_USTAR *hd;
-
-	if (size < BLKMULT)
-		return(-1);
-	hd = (HD_USTAR *)blk;
-
-	/*
-	 * check for block of zero's first, a simple and fast test then check
-	 * ustar magic cookie. We should use TMAGLEN, but some USTAR archive
-	 * programs are fouled up and create archives missing the \0. Last we
-	 * check the checksum. If ok we have to assume it is a valid header.
-	 */
-	if (hd->name[0] == '\0')
-		return(-1);
-	if (strncmp(hd->magic, TMAGIC, TMAGLEN - 1) != 0)
-		return(-1);
-	if (asc_ul(hd->chksum,sizeof(hd->chksum),OCT) != tar_chksm(blk,BLKMULT))
-		return(-1);
-	return(0);
-}
-
-/*
- * ustar_rd()
- *	extract the values out of block already determined to be a ustar header.
- *	store the values in the ARCHD parameter.
- * Return:
- *	0
- */
-
-int
-ustar_rd(ARCHD *arcn, char *buf)
-{
-	HD_USTAR *hd;
-	char *dest;
-	int cnt = 0;
-	dev_t devmajor;
-	dev_t devminor;
-
-	/*
-	 * we only get proper sized buffers
-	 */
-	if (ustar_id(buf, BLKMULT) < 0)
-		return(-1);
-	arcn->org_name = arcn->name;
-	arcn->sb.st_nlink = 1;
-	arcn->pat = NULL;
-	arcn->nlen = 0;
-	hd = (HD_USTAR *)buf;
-
-	/*
-	 * see if the filename is split into two parts. if, so joint the parts.
-	 * we copy the prefix first and add a / between the prefix and name.
-	 */
-	dest = arcn->name;
-	if (*(hd->prefix) != '\0') {
-		cnt = l_strncpy(dest, hd->prefix,
-		    MIN(sizeof(hd->prefix), sizeof(arcn->name) - 2));
-		dest += cnt;
-		*dest++ = '/';
-		cnt++;
-	}
-	/*
-	 * ustar format specifies the name may be unterminated
-	 * if it fills the entire field.  this also applies to
-	 * the prefix and the linkname.
-	 */
-	arcn->nlen = cnt + l_strncpy(dest, hd->name,
-	    MIN(sizeof(hd->name), sizeof(arcn->name) - cnt - 1));
-	arcn->name[arcn->nlen] = '\0';
-
-	/*
-	 * follow the spec to the letter. we should only have mode bits, strip
-	 * off all other crud we may be passed.
-	 */
-	arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode, sizeof(hd->mode), OCT) &
-	    0xfff);
-#ifdef NET2_STAT
-	arcn->sb.st_size = (off_t)asc_ul(hd->size, sizeof(hd->size), OCT);
-	arcn->sb.st_mtime = (time_t)asc_ul(hd->mtime, sizeof(hd->mtime), OCT);
-#else
-	arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT);
-	arcn->sb.st_mtime = (time_t)asc_uqd(hd->mtime, sizeof(hd->mtime), OCT);
-#endif
-	arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
-
-	/*
-	 * If we can find the ascii names for gname and uname in the password
-	 * and group files we will use the uid's and gid they bind. Otherwise
-	 * we use the uid and gid values stored in the header. (This is what
-	 * the POSIX spec wants).
-	 */
-	hd->gname[sizeof(hd->gname) - 1] = '\0';
-	if (gid_name((char *) hd->gname, (gid_t *) &(arcn->sb.st_gid)) < 0)
-		arcn->sb.st_gid = (gid_t)asc_ul(hd->gid, sizeof(hd->gid), OCT);
-	hd->uname[sizeof(hd->uname) - 1] = '\0';
-	if (uid_name(hd->uname, &(arcn->sb.st_uid)) < 0)
-		arcn->sb.st_uid = (uid_t)asc_ul(hd->uid, sizeof(hd->uid), OCT);
-
-	/*
-	 * set the defaults, these may be changed depending on the file type
-	 */
-	arcn->ln_name[0] = '\0';
-	arcn->ln_nlen = 0;
-	arcn->pad = 0;
-	arcn->skip = 0;
-	arcn->sb.st_rdev = (dev_t)0;
-
-	/*
-	 * set the mode and PAX type according to the typeflag in the header
-	 */
-	switch(hd->typeflag) {
-	case FIFOTYPE:
-		arcn->type = PAX_FIF;
-		arcn->sb.st_mode |= S_IFIFO;
-		break;
-	case DIRTYPE:
-		arcn->type = PAX_DIR;
-		arcn->sb.st_mode |= S_IFDIR;
-		arcn->sb.st_nlink = 2;
-
-		/*
-		 * Some programs that create ustar archives append a '/'
-		 * to the pathname for directories. This clearly violates
-		 * ustar specs, but we will silently strip it off anyway.
-		 */
-		if (arcn->name[arcn->nlen - 1] == '/')
-			arcn->name[--arcn->nlen] = '\0';
-		break;
-	case BLKTYPE:
-	case CHRTYPE:
-		/*
-		 * this type requires the rdev field to be set.
-		 */
-		if (hd->typeflag == BLKTYPE) {
-			arcn->type = PAX_BLK;
-			arcn->sb.st_mode |= S_IFBLK;
-		} else {
-			arcn->type = PAX_CHR;
-			arcn->sb.st_mode |= S_IFCHR;
-		}
-		devmajor = (dev_t)asc_ul(hd->devmajor,sizeof(hd->devmajor),OCT);
-		devminor = (dev_t)asc_ul(hd->devminor,sizeof(hd->devminor),OCT);
-		arcn->sb.st_rdev = TODEV(devmajor, devminor);
-		break;
-	case SYMTYPE:
-	case LNKTYPE:
-		if (hd->typeflag == SYMTYPE) {
-			arcn->type = PAX_SLK;
-			arcn->sb.st_mode |= S_IFLNK;
-		} else {
-			arcn->type = PAX_HLK;
-			/*
-			 * so printing looks better
-			 */
-			arcn->sb.st_mode |= S_IFREG;
-			arcn->sb.st_nlink = 2;
-		}
-		/*
-		 * copy the link name
-		 */
-		arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname,
-		    MIN(sizeof(hd->linkname), sizeof(arcn->ln_name) - 1));
-		arcn->ln_name[arcn->ln_nlen] = '\0';
-		break;
-	case CONTTYPE:
-	case AREGTYPE:
-	case REGTYPE:
-	default:
-		/*
-		 * these types have file data that follows. Set the skip and
-		 * pad fields.
-		 */
-		arcn->type = PAX_REG;
-		arcn->pad = TAR_PAD(arcn->sb.st_size);
-		arcn->skip = arcn->sb.st_size;
-		arcn->sb.st_mode |= S_IFREG;
-		break;
-	}
-	return(0);
-}
-
-/*
- * ustar_wr()
- *	write a ustar header for the file specified in the ARCHD to the archive
- *	Have to check for file types that cannot be stored and file names that
- *	are too long. Be careful of the term (last arg) to ul_oct, we only use
- *	'\0' for the termination character (this is different than picky tar)
- *	ASSUMED: space after header in header block is zero filled
- * Return:
- *	0 if file has data to be written after the header, 1 if file has NO
- *	data to write after the header, -1 if archive write failed
- */
-
-int
-ustar_wr(ARCHD *arcn)
-{
-	HD_USTAR *hd;
-	char *pt;
-	char hdblk[sizeof(HD_USTAR)];
-
-	/*
-	 * check for those file system types ustar cannot store
-	 */
-	if (arcn->type == PAX_SCK) {
-		paxwarn(1, "Ustar cannot archive a socket %s", arcn->org_name);
-		return(1);
-	}
-
-	/*
-	 * check the length of the linkname
-	 */
-	if (((arcn->type == PAX_SLK) || (arcn->type == PAX_HLK) ||
-	    (arcn->type == PAX_HRG)) &&
-	    (arcn->ln_nlen > (int)sizeof(hd->linkname))) {
-		paxwarn(1, "Link name too long for ustar %s", arcn->ln_name);
-		return(1);
-	}
-
-	/*
-	 * split the path name into prefix and name fields (if needed). if
-	 * pt != arcn->name, the name has to be split
-	 */
-	if ((pt = name_split(arcn->name, arcn->nlen)) == NULL) {
-		paxwarn(1, "File name too long for ustar %s", arcn->name);
-		return(1);
-	}
-	hd = (HD_USTAR *)hdblk;
-	arcn->pad = 0L;
-
-	/*
-	 * split the name, or zero out the prefix
-	 */
-	if (pt != arcn->name) {
-		/*
-		 * name was split, pt points at the / where the split is to
-		 * occur, we remove the / and copy the first part to the prefix
-		 */
-		*pt = '\0';
-		l_strncpy(hd->prefix, arcn->name, sizeof(hd->prefix));
-		*pt++ = '/';
-	} else
-		memset(hd->prefix, 0, sizeof(hd->prefix));
-
-	/*
-	 * copy the name part. this may be the whole path or the part after
-	 * the prefix.  both the name and prefix may fill the entire field.
-	 */
-	l_strncpy(hd->name, pt, sizeof(hd->name));
-
-	/*
-	 * set the fields in the header that are type dependent
-	 */
-	switch(arcn->type) {
-	case PAX_DIR:
-		hd->typeflag = DIRTYPE;
-		memset(hd->linkname, 0, sizeof(hd->linkname));
-		memset(hd->devmajor, 0, sizeof(hd->devmajor));
-		memset(hd->devminor, 0, sizeof(hd->devminor));
-		if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 3))
-			goto out;
-		break;
-	case PAX_CHR:
-	case PAX_BLK:
-		if (arcn->type == PAX_CHR)
-			hd->typeflag = CHRTYPE;
-		else
-			hd->typeflag = BLKTYPE;
-		memset(hd->linkname, 0, sizeof(hd->linkname));
-		if (ul_oct((u_long)major(arcn->sb.st_rdev), hd->devmajor,
-		   sizeof(hd->devmajor), 3) ||
-		   ul_oct((u_long)minor(arcn->sb.st_rdev), hd->devminor,
-		   sizeof(hd->devminor), 3) ||
-		   ul_oct((u_long)0L, hd->size, sizeof(hd->size), 3))
-			goto out;
-		break;
-	case PAX_FIF:
-		hd->typeflag = FIFOTYPE;
-		memset(hd->linkname, 0, sizeof(hd->linkname));
-		memset(hd->devmajor, 0, sizeof(hd->devmajor));
-		memset(hd->devminor, 0, sizeof(hd->devminor));
-		if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 3))
-			goto out;
-		break;
-	case PAX_SLK:
-	case PAX_HLK:
-	case PAX_HRG:
-		if (arcn->type == PAX_SLK)
-			hd->typeflag = SYMTYPE;
-		else
-			hd->typeflag = LNKTYPE;
-		/* the link name may occupy the entire field in ustar */
-		l_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname));
-		memset(hd->devmajor, 0, sizeof(hd->devmajor));
-		memset(hd->devminor, 0, sizeof(hd->devminor));
-		if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 3))
-			goto out;
-		break;
-	case PAX_REG:
-	case PAX_CTG:
-	default:
-		/*
-		 * file data with this type, set the padding
-		 */
-		if (arcn->type == PAX_CTG)
-			hd->typeflag = CONTTYPE;
-		else
-			hd->typeflag = REGTYPE;
-		memset(hd->linkname, 0, sizeof(hd->linkname));
-		memset(hd->devmajor, 0, sizeof(hd->devmajor));
-		memset(hd->devminor, 0, sizeof(hd->devminor));
-		arcn->pad = TAR_PAD(arcn->sb.st_size);
-#		ifdef NET2_STAT
-		if (ul_oct((u_long)arcn->sb.st_size, hd->size,
-		    sizeof(hd->size), 3)) {
-#		else
-		if (uqd_oct((u_quad_t)arcn->sb.st_size, hd->size,
-		    sizeof(hd->size), 3)) {
-#		endif
-			paxwarn(1,"File is too long for ustar %s",arcn->org_name);
-			return(1);
-		}
-		break;
-	}
-
-	l_strncpy(hd->magic, TMAGIC, TMAGLEN);
-	l_strncpy(hd->version, TVERSION, TVERSLEN);
-
-	/*
-	 * set the remaining fields. Some versions want all 16 bits of mode
-	 * we better humor them (they really do not meet spec though)....
-	 */
-	if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 3) ||
-	    ul_oct((u_long)arcn->sb.st_uid, hd->uid, sizeof(hd->uid), 3)  ||
-	    ul_oct((u_long)arcn->sb.st_gid, hd->gid, sizeof(hd->gid), 3) ||
-	    ul_oct((u_long)arcn->sb.st_mtime,hd->mtime,sizeof(hd->mtime),3))
-		goto out;
-	l_strncpy(hd->uname,name_uid(arcn->sb.st_uid, 0),sizeof(hd->uname));
-	l_strncpy(hd->gname,name_gid(arcn->sb.st_gid, 0),sizeof(hd->gname));
-
-	/*
-	 * calculate and store the checksum write the header to the archive
-	 * return 0 tells the caller to now write the file data, 1 says no data
-	 * needs to be written
-	 */
-	if (ul_oct(tar_chksm(hdblk, sizeof(HD_USTAR)), hd->chksum,
-	   sizeof(hd->chksum), 3))
-		goto out;
-	if (wr_rdbuf(hdblk, sizeof(HD_USTAR)) < 0)
-		return(-1);
-	if (wr_skip((off_t)(BLKMULT - sizeof(HD_USTAR))) < 0)
-		return(-1);
-	if ((arcn->type == PAX_CTG) || (arcn->type == PAX_REG))
-		return(0);
-	return(1);
-
-    out:
-    	/*
-	 * header field is out of range
-	 */
-	paxwarn(1, "Ustar header field is too small for %s", arcn->org_name);
-	return(1);
-}
-
-/*
- * name_split()
- *	see if the name has to be split for storage in a ustar header. We try
- *	to fit the entire name in the name field without splitting if we can.
- *	The split point is always at a /
- * Return
- *	character pointer to split point (always the / that is to be removed
- *	if the split is not needed, the points is set to the start of the file
- *	name (it would violate the spec to split there). A NULL is returned if
- *	the file name is too long
- */
-
-static char *
-name_split(char *name, int len)
-{
-	char *start;
-
-	/*
-	 * check to see if the file name is small enough to fit in the name
-	 * field. if so just return a pointer to the name.
-	 */
-	if (len <= TNMSZ)
-		return(name);
-	if (len > (TPFSZ + TNMSZ + 1))
-		return(NULL);
-
-	/*
-	 * we start looking at the biggest sized piece that fits in the name
-	 * field. We walk forward looking for a slash to split at. The idea is
-	 * to find the biggest piece to fit in the name field (or the smallest
-	 * prefix we can find)
-	 */
-	start = name + len - TNMSZ - 1;
-	while ((*start != '\0') && (*start != '/'))
-		++start;
-
-	/*
-	 * if we hit the end of the string, this name cannot be split, so we
-	 * cannot store this file.
-	 */
-	if (*start == '\0')
-		return(NULL);
-	len = start - name;
-
-	/*
-	 * NOTE: /str where the length of str == TNMSZ can not be stored under
-	 * the p1003.1-1990 spec for ustar. We could force a prefix of / and
-	 * the file would then expand on extract to //str. The len == 0 below
-	 * makes this special case follow the spec to the letter.
-	 */
-	if ((len > TPFSZ) || (len == 0))
-		return(NULL);
-
-	/*
-	 * ok have a split point, return it to the caller
-	 */
-	return(start);
-}
Index: trunk/minix/commands/pax/tar.h
===================================================================
--- trunk/minix/commands/pax/tar.h	(revision 9)
+++ 	(revision )
@@ -1,145 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- *
- *	@(#)tar.h	8.2 (Berkeley) 4/18/94
- * $FreeBSD: src/bin/pax/tar.h,v 1.7 2004/04/06 20:06:49 markm Exp $
- */
-
-/*
- * defines and data structures common to all tar formats
- */
-#define CHK_LEN		8		/* length of checksum field */
-#define TNMSZ		100		/* size of name field */
-#ifdef _PAX_
-#define NULLCNT		2		/* number of null blocks in trailer */
-#define CHK_OFFSET	148		/* start of checksum field */
-#define BLNKSUM		256L		/* sum of checksum field using ' ' */
-#endif /* _PAX_ */
-
-/*
- * Values used in typeflag field in all tar formats
- * (only REGTYPE, LNKTYPE and SYMTYPE are used in old BSD tar headers)
- */
-#define	REGTYPE		'0'		/* Regular File */
-#define	AREGTYPE	'\0'		/* Regular File */
-#define	LNKTYPE		'1'		/* Link */
-#define	SYMTYPE		'2'		/* Symlink */
-#define	CHRTYPE		'3'		/* Character Special File */
-#define	BLKTYPE		'4'		/* Block Special File */
-#define	DIRTYPE		'5'		/* Directory */
-#define	FIFOTYPE	'6'		/* FIFO */
-#define	CONTTYPE	'7'		/* high perf file */
-
-/*
- * Mode field encoding of the different file types - values in octal
- */
-#define TSUID		04000		/* Set UID on execution */
-#define TSGID		02000		/* Set GID on execution */
-#define TSVTX		01000		/* Reserved */
-#define TUREAD		00400		/* Read by owner */
-#define TUWRITE		00200		/* Write by owner */
-#define TUEXEC		00100		/* Execute/Search by owner */
-#define TGREAD		00040		/* Read by group */
-#define TGWRITE		00020		/* Write by group */
-#define TGEXEC		00010		/* Execute/Search by group */
-#define TOREAD		00004		/* Read by other */
-#define TOWRITE		00002		/* Write by other */
-#define TOEXEC		00001		/* Execute/Search by other */
-
-#ifdef _PAX_
-/*
- * Pad with a bit mask, much faster than doing a mod but only works on powers
- * of 2. Macro below is for block of 512 bytes.
- */
-#define TAR_PAD(x)	((512 - ((x) & 511)) & 511)
-#endif /* _PAX_ */
-
-/*
- * structure of an old tar header as it appeared in BSD releases
- */
-typedef struct {
-	char name[TNMSZ];		/* name of entry */
-	char mode[8]; 			/* mode */
-	char uid[8]; 			/* uid */
-	char gid[8];			/* gid */
-	char size[12];			/* size */
-	char mtime[12];			/* modification time */
-	char chksum[CHK_LEN];		/* checksum */
-	char linkflag;			/* norm, hard, or sym. */
-	char linkname[TNMSZ];		/* linked to name */
-} HD_TAR;
-
-#ifdef _PAX_
-/*
- * -o options for BSD tar to not write directories to the archive
- */
-#define TAR_NODIR	"nodir"
-#define TAR_OPTION	"write_opt"
-
-/*
- * default device names
- */
-#define	DEV_0		"/dev/rmt0"
-#define	DEV_1		"/dev/rmt1"
-#define	DEV_4		"/dev/rmt4"
-#define	DEV_5		"/dev/rmt5"
-#define	DEV_7		"/dev/rmt7"
-#define	DEV_8		"/dev/rmt8"
-#endif /* _PAX_ */
-
-/*
- * Data Interchange Format - Extended tar header format - POSIX 1003.1-1990
- */
-#define TPFSZ		155
-#define	TMAGIC		"ustar"		/* ustar and a null */
-#define	TMAGLEN		6
-#define	TVERSION	"00"		/* 00 and no null */
-#define	TVERSLEN	2
-
-typedef struct {
-	char name[TNMSZ];		/* name of entry */
-	char mode[8]; 			/* mode */
-	char uid[8]; 			/* uid */
-	char gid[8];			/* gid */
-	char size[12];			/* size */
-	char mtime[12];			/* modification time */
-	char chksum[CHK_LEN];		/* checksum */
-	char typeflag;			/* type of file. */
-	char linkname[TNMSZ];		/* linked to name */
-	char magic[TMAGLEN];		/* magic cookie */
-	char version[TVERSLEN];		/* version */
-	char uname[32];			/* ascii owner name */
-	char gname[32];			/* ascii group name */
-	char devmajor[8];		/* major device number */
-	char devminor[8];		/* minor device number */
-	char prefix[TPFSZ];		/* linked to name */
-} HD_USTAR;
Index: trunk/minix/commands/pax/tty_subs.c
===================================================================
--- trunk/minix/commands/pax/tty_subs.c	(revision 9)
+++ 	(revision )
@@ -1,189 +1,0 @@
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)tty_subs.c	8.2 (Berkeley) 4/18/94";
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include "pax.h"
-#include "extern.h"
-#include <stdarg.h>
-
-/*
- * routines that deal with I/O to and from the user
- */
-
-#define DEVTTY	  "/dev/tty"      /* device for interactive i/o */
-static FILE *ttyoutf = NULL;		/* output pointing at control tty */
-static FILE *ttyinf = NULL;		/* input pointing at control tty */
-
-/*
- * tty_init()
- *	try to open the controlling terminal (if any) for this process. if the
- *	open fails, future ops that require user input will get an EOF
- */
-
-int
-tty_init(void)
-{
-	int ttyfd;
-
-	if ((ttyfd = open(DEVTTY, O_RDWR)) >= 0) {
-		if ((ttyoutf = fdopen(ttyfd, "w")) != NULL) {
-			if ((ttyinf = fdopen(ttyfd, "r")) != NULL)
-				return(0);
-			(void)fclose(ttyoutf);
-		}
-		(void)close(ttyfd);
-	}
-
-	if (iflag) {
-		paxwarn(1, "Fatal error, cannot open %s", DEVTTY);
-		return(-1);
-	}
-	return(0);
-}
-
-/*
- * tty_prnt()
- *	print a message using the specified format to the controlling tty
- *	if there is no controlling terminal, just return.
- */
-
-void
-tty_prnt(const char *fmt, ...)
-{
-	va_list ap;
-	if (ttyoutf == NULL)
-		return;
-	va_start(ap, fmt);
-	(void)vfprintf(ttyoutf, fmt, ap);
-	va_end(ap);
-	(void)fflush(ttyoutf);
-}
-
-/*
- * tty_read()
- *	read a string from the controlling terminal if it is open into the
- *	supplied buffer
- * Return:
- *	0 if data was read, -1 otherwise.
- */
-
-int
-tty_read(char *str, int len)
-{
-	char *pt;
-
-	if ((--len <= 0) || (ttyinf == NULL) || (fgets(str,len,ttyinf) == NULL))
-		return(-1);
-	*(str + len) = '\0';
-
-	/*
-	 * strip off that trailing newline
-	 */
-	if ((pt = strchr(str, '\n')) != NULL)
-		*pt = '\0';
-	return(0);
-}
-
-/*
- * paxwarn()
- *	write a warning message to stderr. if "set" the exit value of pax
- *	will be non-zero.
- */
-
-void
-paxwarn(int set, const char *fmt, ...)
-{
-	va_list ap;
-	va_start(ap, fmt);
-	if (set)
-		exit_val = 1;
-	/*
-	 * when vflag we better ship out an extra \n to get this message on a
-	 * line by itself
-	 */
-	if (vflag && vfpart) {
-		(void)fflush(listf);
-		(void)fputc('\n', stderr);
-		vfpart = 0;
-	}
-	(void)fprintf(stderr, "%s: ", argv0);
-	(void)vfprintf(stderr, fmt, ap);
-	va_end(ap);
-	(void)fputc('\n', stderr);
-}
-
-/*
- * syswarn()
- *	write a warning message to stderr. if "set" the exit value of pax
- *	will be non-zero.
- */
-
-void
-syswarn(int set, int errnum, const char *fmt, ...)
-{
-	va_list ap;
-	va_start(ap, fmt);
-	if (set)
-		exit_val = 1;
-	/*
-	 * when vflag we better ship out an extra \n to get this message on a
-	 * line by itself
-	 */
-	if (vflag && vfpart) {
-		(void)fflush(listf);
-		(void)fputc('\n', stderr);
-		vfpart = 0;
-	}
-	(void)fprintf(stderr, "%s: ", argv0);
-	(void)vfprintf(stderr, fmt, ap);
-	va_end(ap);
-
-	/*
-	 * format and print the errno
-	 */
-	if (errnum > 0)
-		(void)fprintf(stderr, " <%s>", strerror(errnum));
-	(void)fputc('\n', stderr);
-}
Index: trunk/minix/commands/ps/Makefile
===================================================================
--- trunk/minix/commands/ps/Makefile	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-# Makefile for the process status utility.
-#
-u=/usr
-CC=	exec cc
-CFLAGS=	-O -D_MINIX -D_POSIX_SOURCE
-MAKE=	exec make -$(MAKEFLAGS)
-
-all: ps
-
-# process status utility
-ps:	ps.c /usr/include/minix/config.h /usr/include/minix/const.h \
-		../../kernel/const.h ../../kernel/type.h \
-		../../kernel/proc.h ../../servers/pm/mproc.h \
-		../../servers/fs/fproc.h ../../servers/fs/const.h
-	$(CC) -i $(CFLAGS) -o $@ ps.c
-	install -S 32kw $@
-install:	/usr/bin/ps
-/usr/bin/ps:	ps
-	install -cs -o bin -g kmem -m 2755 $? $@
-
-
-
-# clean up compile results
-clean:
-	rm -f *.bak ps 
Index: trunk/minix/commands/ps/build
===================================================================
--- trunk/minix/commands/ps/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/ps/ps.c
===================================================================
--- trunk/minix/commands/ps/ps.c	(revision 9)
+++ 	(revision )
@@ -1,605 +1,0 @@
-/* ps - print status			Author: Peter Valkenburg */
-
-/* Ps.c, Peter Valkenburg (valke@psy.vu.nl), january 1990.
- *
- * This is a V7 ps(1) look-alike for MINIX >= 1.5.0.
- * It does not support the 'k' option (i.e. cannot read memory from core file).
- * If you want to compile this for non-IBM PC architectures, the header files
- * require that you have your CHIP, MACHINE etc. defined.
- * Full syntax:
- *	ps [-][aeflx]
- * Option `a' gives all processes, `l' for detailed info, `x' includes even
- * processes without a terminal.
- * The `f' and `e' options were added by Kees Bot for the convenience of 
- * Solaris users accustomed to these options. The `e' option is equivalent to 
- * `a' and `f' is equivalent to  -l. These do not appear in the usage message.
- *
- * VERY IMPORTANT NOTE:
- *	To compile ps, the kernel/, fs/ and pm/ source directories must be in
- *	../../ relative to the directory where ps is compiled (normally the
- *	tools source directory).
- *
- *	If you want your ps to be useable by anyone, you can arrange the
- *	following access permissions (note the protected memory files and set
- *	*group* id on ps):
- *	-rwxr-sr-x  1 bin   kmem       11916 Jul  4 15:31 /bin/ps
- *	crw-r-----  1 bin   kmem      1,   1 Jan  1  1970 /dev/mem
- *	crw-r-----  1 bin   kmem      1,   2 Jan  1  1970 /dev/kmem
- */
-
-/* Some technical comments on this implementation:
- *
- * Most fields are similar to V7 ps(1), except for CPU, NICE, PRI which are
- * absent, RECV which replaces WCHAN, and PGRP that is an extra.
- * The info is obtained from the following fields of proc, mproc and fproc:
- * F	- kernel status field, p_rts_flags
- * S	- kernel status field, p_rts_flags; mm status field, mp_flags (R if p_rts_flags
- *	  is 0; Z if mp_flags == ZOMBIE; T if mp_flags == STOPPED; else W).
- * UID	- mm eff uid field, mp_effuid
- * PID	- mm pid field, mp_pid
- * PPID	- mm parent process index field, mp_parent (used as index in proc).
- * PGRP - mm process group field, mp_procgrp
- * SZ	- kernel text size + physical stack address - physical data address
- *			   + stack size
- *	  p_memmap[T].mem_len + p_memmap[S].mem_phys - p_memmap[D].mem_phys
- *			   + p_memmap[S].mem_len
- * RECV	- kernel process index field for message receiving, p_getfrom
- *	  If sleeping, mm's mp_flags, or fs's fp_task are used for more info.
- * TTY	- fs controlling tty device field, fp_tty.
- * TIME	- kernel user + system times fields, user_time + sys_time
- * CMD	- system process index (converted to mnemonic name by using the p_name
- *	  field), or user process argument list (obtained by reading the stack
- *	  frame; the resulting address is used to get the argument vector from
- *	  user space and converted into a concatenated argument list).
- */
-
-#include <minix/config.h>
-#include <minix/endpoint.h>
-#include <limits.h>
-#include <timers.h>
-#include <sys/types.h>
-
-#include <minix/const.h>
-#include <minix/type.h>
-#include <minix/ipc.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <minix/com.h>
-#include <fcntl.h>
-#include <a.out.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <signal.h>
-#include <stdio.h>
-#include <ttyent.h>
-
-#include "../../kernel/const.h"
-#include "../../kernel/type.h"
-#include "../../kernel/proc.h"
-
-#include "../../servers/pm/mproc.h"
-#include "../../servers/fs/fproc.h"
-#include "../../servers/fs/const.h"
-
-
-/*----- ps's local stuff below this line ------*/
-
-
-#define mindev(dev)	(((dev)>>MINOR) & 0377)	/* yield minor device */
-#define majdev(dev)	(((dev)>>MAJOR) & 0377)	/* yield major device */
-
-#define	TTY_MAJ		4	/* major device of console */
-
-/* Structure for tty name info. */
-typedef struct {
-  char tty_name[NAME_MAX + 1];	/* file name in /dev */
-  dev_t tty_dev;		/* major/minor pair */
-} ttyinfo_t;
-
-ttyinfo_t *ttyinfo;		/* ttyinfo holds actual tty info */
-size_t n_ttyinfo;		/* Number of tty info slots */
-
-/* Macro to convert memory offsets to rounded kilo-units */
-#define	off_to_k(off)	((unsigned) (((off) + 512) / 1024))
-
-
-/* Number of tasks and processes and addresses of the main process tables. */
-int nr_tasks, nr_procs;		
-vir_bytes proc_addr, mproc_addr, fproc_addr;	
-extern int errno;
-
-/* Process tables of the kernel, MM, and FS. */
-struct proc *ps_proc;
-struct mproc *ps_mproc;
-struct fproc *ps_fproc;
-
-/* Where is INIT? */
-int init_proc_nr;
-#define low_user init_proc_nr
-
-#define	KMEM_PATH	"/dev/kmem"	/* opened for kernel proc table */
-#define	MEM_PATH	"/dev/mem"	/* opened for pm/fs + user processes */
-
-int kmemfd, memfd;		/* file descriptors of [k]mem */
-
-/* Short and long listing formats:
- *
- *   PID TTY  TIME CMD
- * ppppp tttmmm:ss cccccccccc...
- *
- *   F S UID   PID  PPID  PGRP   SZ       RECV TTY  TIME CMD
- * fff s uuu ppppp ppppp ppppp ssss rrrrrrrrrr tttmmm:ss cccccccc...
- */
-#define S_HEADER "  PID TTY  TIME CMD\n"
-#define S_FORMAT "%5s %3s %s %s\n"
-#define L_HEADER "  F S UID   PID  PPID  PGRP     SZ         RECV TTY  TIME CMD\n"
-#define L_FORMAT "%3o %c %3d %5s %5d %5d %6d %12s %3s %s %s\n"
-
-
-struct pstat {			/* structure filled by pstat() */
-  dev_t ps_dev;			/* major/minor of controlling tty */
-  uid_t ps_ruid;		/* real uid */
-  uid_t ps_euid;		/* effective uid */
-  pid_t ps_pid;			/* process id */
-  pid_t ps_ppid;		/* parent process id */
-  int ps_pgrp;			/* process group id */
-  int ps_flags;			/* kernel flags */
-  int ps_mflags;		/* mm flags */
-  int ps_ftask;			/* (possibly pseudo) fs suspend task */
-  char ps_state;		/* process state */
-  vir_bytes ps_tsize;		/* text size (in bytes) */
-  vir_bytes ps_dsize;		/* data size (in bytes) */
-  vir_bytes ps_ssize;		/* stack size (in bytes) */
-  phys_bytes ps_vtext;		/* virtual text offset */
-  phys_bytes ps_vdata;		/* virtual data offset */
-  phys_bytes ps_vstack;		/* virtual stack offset */
-  phys_bytes ps_text;		/* physical text offset */
-  phys_bytes ps_data;		/* physical data offset */
-  phys_bytes ps_stack;		/* physical stack offset */
-  int ps_recv;			/* process number to receive from */
-  time_t ps_utime;		/* accumulated user time */
-  time_t ps_stime;		/* accumulated system time */
-  char *ps_args;		/* concatenated argument string */
-  vir_bytes ps_procargs;	/* initial stack frame from MM */
-};
-
-/* Ps_state field values in pstat struct above */
-#define	Z_STATE		'Z'	/* Zombie */
-#define	W_STATE		'W'	/* Waiting */
-#define	S_STATE		'S'	/* Sleeping */
-#define	R_STATE		'R'	/* Runnable */
-#define	T_STATE		'T'	/* stopped (Trace) */
-
-_PROTOTYPE(char *tname, (Dev_t dev_nr ));
-_PROTOTYPE(char *taskname, (int p_nr ));
-_PROTOTYPE(char *prrecv, (struct pstat *bufp ));
-_PROTOTYPE(void disaster, (int sig ));
-_PROTOTYPE(int main, (int argc, char *argv []));
-_PROTOTYPE(char *get_args, (struct pstat *bufp ));
-_PROTOTYPE(int pstat, (int p_nr, struct pstat *bufp ));
-_PROTOTYPE(int addrread, (int fd, phys_clicks base, vir_bytes addr, 
-						    char *buf, int nbytes ));
-_PROTOTYPE(void usage, (char *pname ));
-_PROTOTYPE(void err, (char *s ));
-_PROTOTYPE(int gettynames, (void));
-
-
-/*
- * Tname returns mnemonic string for dev_nr. This is "?" for maj/min pairs that
- * are not found.  It uses the ttyinfo array (prepared by gettynames).
- * Tname assumes that the first three letters of the tty's name can be omitted
- * and returns the rest (except for the console, which yields "co").
- */
-char *tname(dev_nr)
-Dev_t dev_nr;
-{
-  int i;
-
-  if (majdev(dev_nr) == TTY_MAJ && mindev(dev_nr) == 0) return "co";
-
-  for (i = 0; i < n_ttyinfo && ttyinfo[i].tty_name[0] != '\0'; i++)
-	if (ttyinfo[i].tty_dev == dev_nr)
-		return ttyinfo[i].tty_name + 3;
-
-  return "?";
-}
-
-/* Return canonical task name of task p_nr; overwritten on each call (yucch) */
-char *taskname(p_nr)
-int p_nr;
-{
-  return ps_proc[_ENDPOINT_P(p_nr) + nr_tasks].p_name;
-}
-
-/* Prrecv prints the RECV field for process with pstat buffer pointer bufp.
- * This is either "ANY", "taskname", or "(blockreason) taskname".
- */
-char *prrecv(bufp)
-struct pstat *bufp;
-{
-  char *blkstr, *task;		/* reason for blocking and task */
-  static char recvstr[20];
-
-  if (bufp->ps_recv == ANY) return "ANY";
-
-  task = taskname(bufp->ps_recv);
-  if (bufp->ps_state != S_STATE) return task;
-
-  blkstr = "?";
-  if (bufp->ps_recv == PM_PROC_NR) {
-	if (bufp->ps_mflags & PAUSED)
-		blkstr = "pause";
-	else if (bufp->ps_mflags & WAITING)
-		blkstr = "wait";
-	else if (bufp->ps_mflags & SIGSUSPENDED)
-		blkstr = "ssusp";
-  } else if (bufp->ps_recv == FS_PROC_NR) {
-	if (-bufp->ps_ftask == XPIPE)
-		blkstr = "pipe";
-	else if (-bufp->ps_ftask == XPOPEN)
-		blkstr = "popen";
-	else if (-bufp->ps_ftask == XLOCK)
-		blkstr = "flock";
-	else if(-bufp->ps_ftask == XSELECT)
-		blkstr = "select";
-	else if(-bufp->ps_ftask >= 0)
-		blkstr = taskname(-bufp->ps_ftask);
-	else
-		blkstr = "??";
-  }
-  (void) sprintf(recvstr, "(%s) %s", blkstr, task);
-  return recvstr;
-}
-
-/* If disaster is called some of the system parameters imported into ps are
- * probably wrong.  This tends to result in memory faults.
- */
-void disaster(sig)
-int sig;
-{
-  fprintf(stderr, "Ooops, got signal %d\n", sig);
-  fprintf(stderr, "Was ps recompiled since the last kernel change?\n");
-  exit(3);
-}
-
-/* Main interprets arguments, gets system addresses, opens [k]mem, reads in
- * process tables from kernel/pm/fs and calls pstat() for relevant entries.
- */
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int i;
-  struct pstat buf;
-  int db_fd;
-  int uid = getuid();		/* real uid of caller */
-  char *opt;
-  int opt_all = FALSE;		/* -a */
-  int opt_long = FALSE;		/* -l */
-  int opt_notty = FALSE;	/* -x */
-  char *ke_path;		/* paths of kernel, */
-  char *mm_path;		/* mm, */
-  char *fs_path;		/* and fs used in ps -U */
-  char pid[2 + sizeof(pid_t) * 3];
-  unsigned long ustime;
-  char cpu[sizeof(clock_t) * 3 + 1 + 2];
-  struct kinfo kinfo;
-  int s;
-
-  (void) signal(SIGSEGV, disaster);	/* catch a common crash */
-
-  /* Parse arguments; a '-' need not be present (V7/BSD compatability) */
-  for (i = 1; i < argc; i++) {
-	opt = argv[i];
-	if (opt[0] == '-') opt++;
-	while (*opt != 0) switch (*opt++) {
-		case 'a':	opt_all = TRUE;			break;
-		case 'e':	opt_all = opt_notty = TRUE;	break;
-		case 'f':
-		case 'l':	opt_long = TRUE;		break;
-		case 'x':	opt_notty = TRUE;		break;
-		default:	usage(argv[0]);
-	}
-  }
-
-  /* Open memory devices and get PS info from the kernel */
-  if ((kmemfd = open(KMEM_PATH, O_RDONLY)) == -1) err(KMEM_PATH);
-  if ((memfd = open(MEM_PATH, O_RDONLY)) == -1) err(MEM_PATH);
-  if (gettynames() == -1) err("Can't get tty names");
-
-  getsysinfo(PM_PROC_NR, SI_PROC_ADDR, &mproc_addr);
-  getsysinfo(FS_PROC_NR, SI_PROC_ADDR, &fproc_addr);
-  getsysinfo(PM_PROC_NR, SI_KINFO, &kinfo);
-  proc_addr = kinfo.proc_addr;
-  nr_tasks = kinfo.nr_tasks;	
-  nr_procs = kinfo.nr_procs;
-
-  /* Allocate memory for process tables */
-  ps_proc = (struct proc *) malloc((nr_tasks + nr_procs) * sizeof(ps_proc[0]));
-  ps_mproc = (struct mproc *) malloc(nr_procs * sizeof(ps_mproc[0]));
-  ps_fproc = (struct fproc *) malloc(nr_procs * sizeof(ps_fproc[0]));
-  if (ps_proc == NULL || ps_mproc == NULL || ps_fproc == NULL)
-	err("Out of memory");
-
-  /* Get kernel process table */
-  if (addrread(kmemfd, (phys_clicks) 0,
-		proc_addr, (char *) ps_proc,
-		(nr_tasks + nr_procs) * sizeof(ps_proc[0]))
-			!= (nr_tasks + nr_procs) * sizeof(ps_proc[0]))
-	err("Can't get kernel proc table from /dev/kmem");
-
-  /* Get mm/fs process tables */
-  if (addrread(memfd, ps_proc[nr_tasks + PM_PROC_NR].p_memmap[D].mem_phys,
-		mproc_addr, (char *) ps_mproc,
-		nr_procs * sizeof(ps_mproc[0]))
-			!= nr_procs * sizeof(ps_mproc[0]))
-	err("Can't get mm proc table from /dev/mem");
-  if (addrread(memfd, ps_proc[nr_tasks + FS_PROC_NR].p_memmap[D].mem_phys,
-		fproc_addr, (char *) ps_fproc,
-		nr_procs * sizeof(ps_fproc[0]))
-			!= nr_procs * sizeof(ps_fproc[0]))
-	err("Can't get fs proc table from /dev/mem");
-
-  /* We need to know where INIT hangs out. */
-  for (i = FS_PROC_NR; i < nr_procs; i++) {
-	if (strcmp(ps_proc[nr_tasks + i].p_name, "init") == 0) break;
-  }
-  init_proc_nr = i;
-
-  /* Now loop through process table and handle each entry */
-  printf("%s", opt_long ? L_HEADER : S_HEADER);
-  for (i = -nr_tasks; i < nr_procs; i++) {
-	if (pstat(i, &buf) != -1 &&
-	    (opt_all || buf.ps_euid == uid || buf.ps_ruid == uid) &&
-	    (opt_notty || majdev(buf.ps_dev) == TTY_MAJ)) {
-		if (buf.ps_pid == 0 && i != PM_PROC_NR) {
-			sprintf(pid, "(%d)", i);
-		} else {
-			sprintf(pid, "%d", buf.ps_pid);
-		}
-
-		ustime = (buf.ps_utime + buf.ps_stime) / HZ;
-		if (ustime < 60 * 60) {
-			sprintf(cpu, "%2lu:%02lu", ustime / 60, ustime % 60);
-		} else
-		if (ustime < 100L * 60 * 60) {
-			ustime /= 60;
-			sprintf(cpu, "%2luh%02lu", ustime / 60, ustime % 60);
-		} else {
-			sprintf(cpu, "%4luh", ustime / 3600);
-		}
-
-		if (opt_long) printf(L_FORMAT,
-			       buf.ps_flags, buf.ps_state,
-			       buf.ps_euid, pid, buf.ps_ppid, 
-			       buf.ps_pgrp,
-			       off_to_k((buf.ps_tsize
-					 + buf.ps_stack - buf.ps_data
-					 + buf.ps_ssize)),
-			       (buf.ps_flags & RECEIVING ?
-				prrecv(&buf) :
-				""),
-			       tname((Dev_t) buf.ps_dev),
-			       cpu,
-			       i <= init_proc_nr || buf.ps_args == NULL
-				       ? taskname(i) : buf.ps_args);
-		else
-			printf(S_FORMAT,
-			       pid, tname((Dev_t) buf.ps_dev),
-			       cpu,
-			       i <= init_proc_nr || buf.ps_args == NULL
-				       ? taskname(i) : buf.ps_args);
-	}
-  }
-  return(0);
-}
-
-char *get_args(bufp)
-struct pstat *bufp;
-{
-  int nargv;
-  int cnt;			/* # of bytes read from stack frame */
-  int neos;			/* # of '\0's seen in argv string space */
-  phys_bytes iframe;
-  long l;
-  char *cp, *args;
-  static union stack {
-	vir_bytes stk_i;
-	char *stk_cp;
-	char stk_c;
-  } stk[ARG_MAX / sizeof(char *)];
-  union stack *sp;
-
-  /* Phys address of the original stack frame. */
-  iframe = bufp->ps_procargs - bufp->ps_vstack + bufp->ps_stack;
-
-  /* Calculate the number of bytes to read from user stack */
-  l = (phys_bytes) bufp->ps_ssize - (iframe - bufp->ps_stack);
-  if (l > ARG_MAX) l = ARG_MAX;
-  cnt = l;
-
-  /* Get cnt bytes from user initial stack to local stack buffer */
-  if (lseek(memfd, (off_t) iframe, 0) < 0)
-	return NULL; 
-
-  if ( read(memfd, (char *)stk, cnt) != cnt ) 
-	return NULL;
-
-  sp = stk;
-  nargv = (int) sp[0].stk_i;  /* number of argv arguments */
-
-  /* See if argv[0] is with the bytes we read in */
-  l = (long) sp[1].stk_cp - (long) bufp->ps_procargs;
-
-  if ( ( l < 0 ) || ( l > cnt ) )  
-	return NULL;
-
-  /* l is the offset of the argv[0] argument */
-  /* change for concatenation the '\0' to space, for nargv elements */
-
-  args = &((char *) stk)[(int)l]; 
-  neos = 0;
-  for (cp = args; cp < &((char *) stk)[cnt]; cp++)
-	if (*cp == '\0')
-		if (++neos >= nargv)
-			break;
-		else
-			*cp = ' ';
-  if (cp == args) return NULL;
-  *cp = '\0';
-
-  return args;
-
-}
-
-/* Pstat collects info on process number p_nr and returns it in buf.
- * It is assumed that tasks do not have entries in fproc/mproc.
- */
-int pstat(p_nr, bufp)
-int p_nr;
-struct pstat *bufp;
-{
-  int p_ki = p_nr + nr_tasks;	/* kernel proc index */
-
-  if (p_nr < -nr_tasks || p_nr >= nr_procs) return -1;
-
-  if ((ps_proc[p_ki].p_rts_flags == SLOT_FREE)
-  				&& !(ps_mproc[p_nr].mp_flags & IN_USE))
-	return -1;
-
-  bufp->ps_flags = ps_proc[p_ki].p_rts_flags;
-
-  if (p_nr >= low_user) {
-	bufp->ps_dev = ps_fproc[p_nr].fp_tty;
-	bufp->ps_ftask = ps_fproc[p_nr].fp_task;
-  } else {
-	bufp->ps_dev = 0;
-	bufp->ps_ftask = 0;
-  }
-
-  if (p_nr >= 0) {
-	bufp->ps_ruid = ps_mproc[p_nr].mp_realuid;
-	bufp->ps_euid = ps_mproc[p_nr].mp_effuid;
-	bufp->ps_pid = ps_mproc[p_nr].mp_pid;
-	bufp->ps_ppid = ps_mproc[ps_mproc[p_nr].mp_parent].mp_pid;
-	bufp->ps_pgrp = ps_mproc[p_nr].mp_procgrp;
-	bufp->ps_mflags = ps_mproc[p_nr].mp_flags;
-  } else {
-	bufp->ps_pid = 0;
-	bufp->ps_ppid = 0;
-	bufp->ps_ruid = bufp->ps_euid = 0;
-	bufp->ps_pgrp = 0;
-	bufp->ps_mflags = 0;
-  }
-
-  /* State is interpretation of combined kernel/mm flags for non-tasks */
-  if (p_nr >= low_user) {		/* non-tasks */
-	if (ps_mproc[p_nr].mp_flags & ZOMBIE)
-		bufp->ps_state = Z_STATE;	/* zombie */
-	else if (ps_mproc[p_nr].mp_flags & STOPPED)
-		bufp->ps_state = T_STATE;	/* stopped (traced) */
-	else if (ps_proc[p_ki].p_rts_flags == 0)
-		bufp->ps_state = R_STATE;	/* in run-queue */
-	else if (ps_mproc[p_nr].mp_flags & (WAITING | PAUSED | SIGSUSPENDED) ||
-		 ps_fproc[p_nr].fp_suspended == SUSPENDED)
-		bufp->ps_state = S_STATE;	/* sleeping */
-	else
-		bufp->ps_state = W_STATE;	/* a short wait */
-  } else {			/* tasks are simple */
-	if (ps_proc[p_ki].p_rts_flags == 0)
-		bufp->ps_state = R_STATE;	/* in run-queue */
-	else
-		bufp->ps_state = W_STATE;	/* other i.e. waiting */
-  }
-
-  bufp->ps_tsize = (size_t) ps_proc[p_ki].p_memmap[T].mem_len << CLICK_SHIFT;
-  bufp->ps_dsize = (size_t) ps_proc[p_ki].p_memmap[D].mem_len << CLICK_SHIFT;
-  bufp->ps_ssize = (size_t) ps_proc[p_ki].p_memmap[S].mem_len << CLICK_SHIFT;
-  bufp->ps_vtext = (off_t) ps_proc[p_ki].p_memmap[T].mem_vir << CLICK_SHIFT;
-  bufp->ps_vdata = (off_t) ps_proc[p_ki].p_memmap[D].mem_vir << CLICK_SHIFT;
-  bufp->ps_vstack = (off_t) ps_proc[p_ki].p_memmap[S].mem_vir << CLICK_SHIFT;
-  bufp->ps_text = (off_t) ps_proc[p_ki].p_memmap[T].mem_phys << CLICK_SHIFT;
-  bufp->ps_data = (off_t) ps_proc[p_ki].p_memmap[D].mem_phys << CLICK_SHIFT;
-  bufp->ps_stack = (off_t) ps_proc[p_ki].p_memmap[S].mem_phys << CLICK_SHIFT;
-
-  bufp->ps_recv = _ENDPOINT_P(ps_proc[p_ki].p_getfrom_e);
-
-  bufp->ps_utime = ps_proc[p_ki].p_user_time;
-  bufp->ps_stime = ps_proc[p_ki].p_sys_time;
-
-  bufp->ps_procargs = ps_mproc[p_nr].mp_procargs;
-
-  if (bufp->ps_state == Z_STATE)
-	bufp->ps_args = "<defunct>";
-  else if (p_nr > init_proc_nr)
-	bufp->ps_args = get_args(bufp);
-
-  return 0;
-}
-
-/* Addrread reads nbytes from offset addr to click base of fd into buf. */
-int addrread(fd, base, addr, buf, nbytes)
-int fd;
-phys_clicks base;
-vir_bytes addr;
-char *buf;
-int nbytes;
-{
-  if (lseek(fd, ((off_t) base << CLICK_SHIFT) + addr, 0) < 0)
-	return -1;
-
-  return read(fd, buf, nbytes);
-}
-
-void usage(pname)
-char *pname;
-{
-  fprintf(stderr, "Usage: %s [-][aeflx]\n", pname);
-  exit(1);
-}
-
-void err(s)
-char *s;
-{
-  extern int errno;
-
-  if (errno == 0)
-	fprintf(stderr, "ps: %s\n", s);
-  else
-	fprintf(stderr, "ps: %s: %s\n", s, strerror(errno));
-
-  exit(2);
-}
-
-/* Fill ttyinfo by fstatting character specials in /dev. */
-int gettynames()
-{
-  static char dev_path[] = "/dev/";
-  struct stat statbuf;
-  static char path[sizeof(dev_path) + NAME_MAX];
-  int index;
-  struct ttyent *ttyp;
-
-  index = 0;
-  while ((ttyp = getttyent()) != NULL) {
-	strcpy(path, dev_path);
-	strcat(path, ttyp->ty_name);
-	if (stat(path, &statbuf) == -1 || !S_ISCHR(statbuf.st_mode))
-		continue;
-	if (index >= n_ttyinfo) {
-		n_ttyinfo= (index+16) * 2;
-		ttyinfo = realloc(ttyinfo, n_ttyinfo * sizeof(ttyinfo[0]));
-		if (ttyinfo == NULL) err("Out of memory");
-	}
-	ttyinfo[index].tty_dev = statbuf.st_rdev;
-	strcpy(ttyinfo[index].tty_name, ttyp->ty_name);
-	index++;
-  }
-  endttyent();
-  while (index < n_ttyinfo) ttyinfo[index++].tty_dev= 0;
-
-  return 0;
-}
Index: trunk/minix/commands/reboot/Makefile
===================================================================
--- trunk/minix/commands/reboot/Makefile	(revision 9)
+++ 	(revision )
@@ -1,43 +1,0 @@
-# Makefile for shutdown / halt / reboot.
-
-CFLAGS=$(OPT) -D_MINIX -D_POSIX_SOURCE
-LDFLAGS=-i
-CC=exec cc
-
-PROGRAMS=	shutdown halt tinyhalt
-MANUALS=	shutdown.8 halt.8 reboot.2 reboot.8
-
-all:	$(PROGRAMS)
-
-shutdown:	shutdown.o sh_wall.o log.o
-	$(CC) $(LDFLAGS) -o shutdown shutdown.o sh_wall.o log.o
-	install -S 4kw $@
-
-halt:	halt.o log.o
-	$(CC) $(LDFLAGS) -o halt halt.o log.o
-	install -S 4kw $@
-
-tinyhalt:	tinyhalt.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $?
-	install -S 4kw $@
-
-install:	/usr/bin/halt /usr/bin/reboot /usr/bin/shutdown \
-		/bin/halt /bin/reboot
-
-/usr/bin/halt:	halt
-	install -cs -o root -g operator -m 744 $? $@
-
-/usr/bin/reboot:	/usr/bin/halt
-	install -l $? $@
-
-/usr/bin/shutdown:	shutdown
-	install -cs -o root -g operator -m 4754 $? $@
-
-/bin/halt:	tinyhalt
-	install -cs -o root -g operator -m 744 $? $@
-
-/bin/reboot:	/bin/halt
-	install -l $? $@
-
-clean:
-	rm -f *.o a.out core $(PROGRAMS)
Index: trunk/minix/commands/reboot/README
===================================================================
--- trunk/minix/commands/reboot/README	(revision 9)
+++ 	(revision )
@@ -1,52 +1,0 @@
-This a new implementation of a shutdown procedure. It allows 
-the system to go down graciously with informing the
-users. This package contains 3 programs:
-
-- halt = Immediately stop the system, no info to users
-- shutdown = Inform users, close down the system properly
-- wall = Vincent Archer's implementation of wall (Write all)
-
-Installing
-
-Shutdown and halt use a new systemcall, which I've added to
-MM. Therefor there are several diff's which should be applied:
-
-callnr.hd - New callnr for reboot(2)
-	   Diff against /usr/include/minix/callnr.h.
-	   Those of you using a symlink package should
-	   change the number and mm/table.c into a free
-	   number. I used 54, LSTAT.
-param.hd - Defines reboot_flag as a part of the messages
-proto.hd - Add's prototype for do_reboot()
-table.cd - Interpretation of the systemcall to MM
-mm.cd -	   I have added the do_reboot code to mm/getset.c but
-	   I couldn't find a getset.c to create a useable diff :-(
-	   So you can add where you want it. It is pure code, no diff.
-
-Now edit log.c and search for ``host''. Change this into your
-systemname or make it empty.
-
-Shutdown and halt log their actions in /usr/adm/log, edit the
-makefile and undefine -DLOG if you don't want this (this at the end of
-the makefile). You can change SHUT_LOG in shutdown.c and log.c if you
-want it in another file.
-
-Then type a `make'. This will take a minute or so (13 sec. with bcc :-).
-Remember to build a new image and update the ps_database.
-
-Type `make install' to place the program's where I've got them.
-Use them, try them and let me now if you've got problems running
-something.
-
-I have tested to sources both on 16-bits and 32-bits MINIX. I have compiled
-it with gcc, bcc and ACK, so that shouldn't really give a problem. Maybe
-the standard MINIX-make chokes on the makefile, atleast mine did.
-
-NOTE:
-	Make install does not place the man-pages somewhere. You should
-	do this yourself.
-
---
-Edvard Tuinder        ed@pulstar.NL.mugnet.org    v892231@si.hhs.NL
-Student Computer Science
-Haagse Hogeschool, The Hague, The Netherlands
Index: trunk/minix/commands/reboot/build
===================================================================
--- trunk/minix/commands/reboot/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/reboot/halt.c
===================================================================
--- trunk/minix/commands/reboot/halt.c	(revision 9)
+++ 	(revision )
@@ -1,133 +1,0 @@
-/* halt / reboot - halt or reboot system (depends on name)
-
-   halt   - calling reboot() with RBT_HALT
-   reboot - calling reboot() with RBT_REBOOT
-
-   author: Edvard Tuinder   v892231@si.hhs.NL
-
-   This program calls the library function reboot(2) which performs
-   the system-call do_reboot. 
-
- */
-
-#define _POSIX_SOURCE	1
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-
-void write_log _ARGS(( void ));
-void usage _ARGS(( void ));
-int main _ARGS(( int argc, char *argv[] ));
-
-char *prog;
-char *reboot_code = "delay; boot";
-
-void
-usage()
-{
-  fprintf(stderr, "Usage: %s [-hrRf] [-x reboot-code]\n", prog);
-  exit(1);
-}
-
-int
-main(argc,argv)
-int argc;
-char **argv;
-{
-  int flag = -1;		/* default action unknown */
-  int fast = 0;			/* fast halt/reboot, don't bother being nice. */
-  int i;
-  struct stat dummy;
-  char *monitor_code = "";
-  pid_t pid;
-
-  if ((prog = strrchr(argv[0],'/')) == NULL) prog = argv[0]; else prog++;
-
-  if (strcmp(prog, "halt") == 0) flag = RBT_HALT;
-  if (strcmp(prog, "reboot") == 0) flag = RBT_REBOOT;
-
-  i = 1;
-  while (i < argc && argv[i][0] == '-') {
-    char *opt = argv[i++] + 1;
-
-    if (*opt == '-' && opt[1] == 0) break;	/* -- */
-
-    while (*opt != 0) switch (*opt++) {
-      case 'h': flag = RBT_HALT; 	break;
-      case 'r': flag = RBT_REBOOT; 	break;
-      case 'R': flag = RBT_RESET; 	break;
-      case 'f': fast = 1; break;
-      case 'x':
-	flag = RBT_MONITOR;
-	if (*opt == 0) {
-	  if (i == argc) usage();
-	  opt = argv[i++];
-	}
-	monitor_code = opt;
-	opt = "";
-	break;
-      default:
-	usage();
-    }
-  }
-
-  if (i != argc) usage();
-
-  if (flag == -1) {
-    fprintf(stderr, "Don't know what to do when named '%s'\n", prog);
-    exit(1);
-  }
-
-  if (flag == RBT_REBOOT) {
-	flag = RBT_MONITOR;		/* set monitor code for reboot */
-	monitor_code = reboot_code;
-  }
-
-  if (stat("/usr/bin", &dummy) < 0) {
-    /* It seems that /usr isn't present, let's assume "-f." */
-    fast = 1;
-  }
-
-  signal(SIGHUP, SIG_IGN);
-  signal(SIGTERM, SIG_IGN);
-
-  /* Skip this part for fast shut down. */
-  if (! fast) {
-    /* Run the shutdown scripts. */
-    switch ((pid = fork())) {
-      case -1:
-	fprintf(stderr, "%s: can't fork(): %s\n", prog, strerror(errno));
-	exit(1);
-      case 0:
-	execl("/bin/sh", "sh", "/etc/rc", "down", (char *) NULL);
-	fprintf(stderr, "%s: can't execute: /bin/sh: %s\n",
-	  prog, strerror(errno));
-	exit(1);
-      default:
-	while (waitpid(pid, NULL, 0) != pid) {}
-    }
-  }
-
-  /* Tell init to stop spawning getty's. */
-  kill(1, SIGTERM);
-
-  /* Give everybody a chance to die peacefully. */
-  printf("Sending SIGTERM to all processes ...\n");
-  kill(-1, SIGTERM);
-  sleep(1);
-
-  write_log();
-
-  sync();
-
-  reboot(flag, monitor_code, strlen(monitor_code));
-  fprintf(stderr, "%s: reboot(): %s\n", strerror(errno));
-  return 1;
-}
Index: trunk/minix/commands/reboot/log.c
===================================================================
--- trunk/minix/commands/reboot/log.c	(revision 9)
+++ 	(revision )
@@ -1,81 +1,0 @@
-/*
-  log - log the shutdown's and the halt's
-
-  Author: Edvard Tuinder  <v892231@si.hhs.NL>
-
-  shutdown is logged in /usr/adm/wtmp and in /usr/adm/log (if desired)
-  halt is logged only in /usr/adm/wtmp as `halt' to prevent last from
-       reporting halt's as crashes.
-
- */
-
-#define _POSIX_SOURCE	1
-#include <sys/types.h>
-#include <stdio.h>
-#include <utmp.h>
-#include <pwd.h>
-#include <fcntl.h>
-#include <time.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/utsname.h>
-#undef WTMP
-
-static char WTMP[] = "/usr/adm/wtmp";	/* Record of logins and logouts. */
-static char SHUT_LOG[] = "/usr/adm/log";
-
-char who[8];
-extern char *prog;
-static char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-			 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
-
-void write_log _ARGS(( void ));
-
-void write_log()
-{
-  int fd;
-  static struct utmp wtmp;
-  static struct passwd *pwd;
-  char mes[90];
-  struct tm *tm;
-  time_t now;
-  struct utsname utsname;
-  char *host = "localhost";
-
-  time(&now);
-  tm = localtime(&now);
-
-  if (uname(&utsname) >= 0) host = utsname.nodename;
-
-  pwd = getpwuid(getuid());
-  if (pwd == (struct passwd *)0)
-    strcpy (who,"root");
-  else
-    strcpy (who,pwd->pw_name);
-  fd = open(WTMP,O_APPEND|O_WRONLY,1);
-  if (fd) {
-    if (strcmp(prog,"reboot"))
-      strcpy (wtmp.ut_user, prog);
-    else
-      strcpy (wtmp.ut_user, "shutdown"); /* last ... */
-    strcpy (wtmp.ut_id, "~~");
-    strcpy (wtmp.ut_line, "~");
-    wtmp.ut_pid = 0;
-    wtmp.ut_type = BOOT_TIME;
-    wtmp.ut_time = now;
-    wtmp.ut_host[0]= '\0';
-    write (fd, (char *) &wtmp,sizeof(struct utmp));
-    close(fd);
-  }
-  fd = open(SHUT_LOG,O_APPEND|O_WRONLY,1);
-  if (!fd) 
-    perror ("open");
-  else {
-    sprintf (mes,"%s %02d %02d:%02d:%02d %s: system %s by %s@%s\n",
-	month[tm->tm_mon],tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-	prog,prog,who,host);
-    write (fd,mes,strlen(mes));
-    close(fd);
-  }
-  return;
-}
Index: trunk/minix/commands/reboot/sh_wall.c
===================================================================
--- trunk/minix/commands/reboot/sh_wall.c	(revision 9)
+++ 	(revision )
@@ -1,109 +1,0 @@
-/* wall - write to all logged in users			Author: V. Archer */
-/*
-   Edvard Tuinder    v892231@si.hhs.NL
-    Modified some things to include this with my shutdown/halt
-    package
- */
-
-#define _POSIX_SOURCE	1
-#include <sys/types.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <string.h>
-#include <stdio.h>
-#include <time.h>
-#include <utmp.h>
-#include <unistd.h>
-#include <sys/utsname.h>
-#include <sys/stat.h>
-#undef UTMP
-
-static char UTMP[] = "/etc/utmp";	/* Currently logged in users. */
-
-void wall _ARGS(( char *when, char *extra ));
-void crnlcat _ARGS(( char *message, char *more ));
-
-void
-wall(when, extra)
-char *when;			/* When is shutdown */
-char *extra;			/* If non-nil, why is the shutdown */
-{
-  struct utmp utmp;
-  char utmptty[5 + sizeof(utmp.ut_line) + 1];
-  char message[1024];
-  struct passwd *pw;
-  int utmpfd, ttyfd;
-  char *ourtty, *ourname;
-  time_t now;
-  struct utsname utsname;
-  struct stat con_st, tty_st;
-
-  if (ourtty = ttyname(1)) {
-	if (ourname = strrchr(ourtty, '/')) ourtty = ourname+1;
-  } else ourtty = "system task";
-  if (pw = getpwuid(getuid())) ourname = pw->pw_name;
-  else ourname = "unknown";
-
-  time(&now);
-  if (uname(&utsname) != 0) strcpy(utsname.nodename, "?");
-  sprintf(message, "\r\nBroadcast message from %s@%s (%s)\r\n%.24s...\r\n",
-		ourname, utsname.nodename, ourtty, ctime(&now));
-
-  crnlcat(message, when);
-  crnlcat(message, extra);
-
-/* Search the UTMP database for all logged-in users. */
-
-  if ((utmpfd = open(UTMP, O_RDONLY)) < 0) {
-	fprintf(stderr, "Cannot open utmp file\r\n");
-	return;
-  }
-
-  /* first the console */
-  strcpy(utmptty, "/dev/console");
-  if ((ttyfd = open(utmptty, O_WRONLY | O_NONBLOCK)) < 0) {
-	perror(utmptty);
-  } else {
-	fstat(ttyfd, &con_st);
-	write(ttyfd, message, strlen(message));
-	close(ttyfd);
-  }
-
-  while (read(utmpfd, (char *) &utmp, sizeof(utmp)) == sizeof(utmp)) {
-	/* is this the user we are looking for? */
-	if (utmp.ut_type != USER_PROCESS) continue;
-
-	strncpy(utmptty+5, utmp.ut_line, sizeof(utmp.ut_line));
-	utmptty[5 + sizeof(utmp.ut_line) + 1] = 0;
-	if ((ttyfd = open(utmptty, O_WRONLY | O_NONBLOCK)) < 0) {
-		perror(utmptty);
-		continue;
-	}
-	fstat(ttyfd, &tty_st);
-	if (tty_st.st_rdev != con_st.st_rdev)
-		write(ttyfd, message, strlen(message));
-	close(ttyfd);
-  }
-  close(utmpfd);
-  return;
-}
-
-void
-crnlcat(message, more)
-char *message, *more;
-{
-  char *p = message;
-  char *m = more;
-  char *end = message + 1024 - 1;
-
-  while (p < end && *p != 0) *p++;
-
-  while (p < end && *m != 0) {
-    if (*m == '\n' && (p == message || p[-1] != '\n')) {
-      *p++ = '\r';
-      if (p == end) p--;
-    }
-    *p++ = *m++;
-  }
-  *p = 0;
-}
Index: trunk/minix/commands/reboot/shutdown.c
===================================================================
--- trunk/minix/commands/reboot/shutdown.c	(revision 9)
+++ 	(revision )
@@ -1,409 +1,0 @@
-/*
-  shutdown - close down the system graciously
-
-  Author: Edvard Tuinder  <v892231@si.hhs.NL>
-
-  This program informs the users that the system is going
-  down, when and why. After that a shutdown notice is written in
-  both /usr/adm/wtmp and by syslog(3).  Then reboot(2) is called
-  to really close the system.
-
-  This actually is a ``nice'' halt(8).
-
-  Options are supposed to be as with BSD
-   -h: shutdown and halt the system
-   -r: shutdown and reboot
-   -k: stop an already running shutdown
-   -o: obsolete: not implemented
-
-  New Minix options:
-   -C: crash check, i.e. is the last wtmp entry a shutdown entry?
-   -x: let the monitor execute the given code
-   -R: reset the system
- */
-
-#define _POSIX_SOURCE	1
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <time.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include <utmp.h>
-#include <errno.h>
-#undef WTMP
-
-static char WTMP[] =		"/usr/adm/wtmp";
-static char SHUT_PID[] =	"/usr/run/shutdown.pid";
-static char NOLOGIN[] =		"/etc/nologin";
-
-#ifndef __STDC__
-#define inform_user_time inf_time
-#define inform_user      inf_user
-#endif
-
-void usage _ARGS(( void ));
-void write_pid _ARGS(( void ));
-int inform_user_time _ARGS(( void ));
-void inform_user _ARGS(( void ));
-void terminate _ARGS(( void ));
-void wall _ARGS(( char *when, char *extra ));
-int crash_check _ARGS(( void ));
-void parse_time _ARGS(( char *arg ));
-void get_message _ARGS(( void ));
-void main _ARGS(( int argc, char *argv[] ));
-char *itoa _ARGS(( int n ));
-
-long wait_time=0L;
-char message[1024];
-char info[80];
-int reboot_flag='h';			/* default is halt */
-char *reboot_code="";			/* optional monitor code */
-int info_min, info_hour;
-char *prog;
-
-void parse_time (arg)
-char *arg;
-{
-  char *p = arg;
-  int hours, minutes;
-  time_t now;
-  struct tm *tm;
-  int delta = 0;
-  int bad = 0;
-  
-  if (p[0] == '+') { delta = 1; p++; }
-
-  hours = strtoul(p, &p, 10);
-  if (*p == 0 && delta) {
-    minutes = hours;
-    hours = 0;
-  } else {
-    if (*p != ':' && *p != '.')
-      bad = 1;
-    else
-      p++;
-    minutes = strtoul(p, &p, 10);
-    if (*p != 0) bad = 1;
-  }
-  if (bad) {
-    fprintf(stderr,"Invalid time specification `%s'\n",arg);
-    usage();
-  }
-
-  time(&now);
-  tm = localtime(&now);
-
-  if (!delta) {
-    hours -= tm->tm_hour;
-    minutes -= tm->tm_min;
-  }
-
-  if (minutes < 0) {
-    minutes += 60;
-    hours--;
-  }
-  if (hours < 0) hours += 24;	/* Time after midnight. */
-
-  tm->tm_hour += hours;
-  tm->tm_min += minutes;
-  (void) mktime(tm);
-  info_hour = tm->tm_hour;
-  info_min  = tm->tm_min;
-
-  sprintf(info,
-    "The system will shutdown in %d hour%s and %d minute%s at %02d:%02d\n\n",
-    hours,hours==1?"":"s",minutes,minutes==1?"":"s",info_hour,info_min);
-
-  wait_time += hours * 3600 + minutes * 60;
-  return;
-}
-
-void main(argc,argv)
-int argc;
-char *argv[];
-{
-  int i, now = 0, nologin = 0, want_terminate = 0, want_message = 0, check = 0;
-  char *opt;
-  int tty;
-  static char HALT1[] = "-?";
-  static char *HALT[] = { "shutdown", HALT1, NULL, NULL };
-
-  /* Parse options. */
-  for (i = 1; i < argc && argv[i][0] == '-'; i++) {
-    if (argv[i][1] == '-' && argv[i][2] == 0) {
-      /* -- */
-      i++;
-      break;
-    }
-    for (opt = argv[i] + 1; *opt != 0; opt++) {
-      switch (*opt) {
-      case 'k':
-	want_terminate = 1;
-	break;
-      case 'h':
-      case 'r':
-      case 'x':
-	reboot_flag = *opt;
-	if (reboot_flag == 'x') {
-	  if (*++opt == 0) {
-	    if (++i == argc) {
-	      fprintf (stderr,"shutdown: option '-x' requires an argument\n");
-	      usage();
-	    }
-	    opt=argv[i];
-	  }
-	  reboot_code=opt;
-	  opt="";
-	}
-	break;
-      case 'R':
-	reboot_flag = 'R';
-	break;
-      case 'm':
-	want_message = 1;
-	break;
-      case 'C':
-	check = 1;
-	break;
-      default:
-	fprintf (stderr,"shutdown: invalid option '-%c'\n",*opt);
-	usage();
-	break;
-      }
-    }
-  }
-  if ((argc - i) > 2) usage();
-
-  if (check) exit(crash_check() ? 0 : 2);
-
-  if (i == argc) {
-    /* No timespec, assume "now". */
-    now = 1;
-  } else {
-    if (!strcmp(argv[i], "now"))
-      now++;
-    else
-      parse_time(argv[i]);
-  }
-
-  if ((argc - i) == 2) {
-    /* One line message */
-    strcat(message, argv[i+1]);
-    strcat(message, "\n");
-  }
-
-  if (want_terminate) terminate();
-  if (want_message) get_message();
-
-  puts(info);
-
-  prog = strrchr(*argv,'/');
-  if (prog == (char *)0)
-    prog = *argv;
-  else
-    prog++;
-    
-  if (!now) {
-    /* Daemonize. */
-    switch (fork()) {
-    case 0:
-      break;
-    case -1:
-      fprintf(stderr, "%s: can't fork\n", prog);
-      exit(1);
-    default:
-      exit(0);
-    }
-    /* Detach from the terminal (if any). */
-    if ((tty = open("/dev/tty", O_RDONLY)) != -1) {
-      close(tty);
-      setsid();
-    }
-    write_pid();
-  }
-
-  for (;;) {
-    if (wait_time <= 5 * 60 && !nologin && !now) {
-      close(creat(NOLOGIN,00644));
-      nologin = 1;
-    }
-    if (wait_time <= 60) break;
-    if(inform_user_time())
-      inform_user();
-    sleep (60);
-    wait_time -= 60;
-  }
-  
-  if (!now) {
-    inform_user();
-    sleep (30);				/* Last minute before shutdown */
-    wait_time -= 30;
-    inform_user();
-    sleep (30);				/* Last 30 seconds before shutdown */
-  }
-  wait_time = 0;
-  inform_user();
-
-  unlink(SHUT_PID);			/* No way of stopping anymore */
-  unlink(NOLOGIN);
-
-  HALT[1][1] = reboot_flag;
-  if (reboot_flag == 'x') HALT[2] = reboot_code;
-#if __minix_vmd
-  execv("/usr/sbin/halt", HALT);
-#else
-  execv("/usr/bin/halt", HALT);
-#endif
-  if (errno != ENOENT)
-    fprintf(stderr, "Can't execute 'halt': %s\n", strerror(errno));
-
-  sleep(2);
-  reboot(RBT_HALT);
-  fprintf(stderr, "Reboot call failed: %s\n", strerror(errno));
-  exit(1);
-}
-
-void usage()
-{
-  fputs("Usage: shutdown [-hrRmk] [-x code] [time [message]]\n", stderr);
-  fputs("       -h -> halt system after shutdown\n", stderr);
-  fputs("       -r -> reboot system after shutdown\n", stderr);
-  fputs("       -R -> reset system after shutdown\n", stderr);
-  fputs("       -x -> return to the monitor doing...\n", stderr);
-  fputs("       -m -> read a shutdown message from standard input\n", stderr);
-  fputs("       -k -> stop an already running shutdown\n", stderr);
-  fputs("       code -> boot monitor code to be executed\n", stderr);
-  fputs("       time -> keyword ``now'', minutes before shutdown ``+5'',\n", stderr);
-  fputs("               or absolute time specification ``11:20''\n", stderr);
-  fputs("       message -> short shutdown message\n", stderr);
-  exit(1);
-}
-
-void terminate()
-{
-  FILE *in;
-  pid_t pid;
-  char c_pid[5];
-  char buf[80];
-
-  in = fopen(SHUT_PID,"r");
-  if (in == (FILE *)0) {
-    fputs ("Can't get pid of shutdown process, probably not running shutdown\n", stderr);
-    exit(1);
-  }
-  fgets(c_pid,5,in);
-  fclose(in);
-  pid = atoi(c_pid);
-  if (kill(pid,9) == -1)
-    fputs("Can't kill the shutdown process, probably not running anymore\n",stderr);
-  else
-    puts("Shutdown process terminated");
-  unlink(SHUT_PID);
-  unlink(NOLOGIN);
-#ifdef not_very_useful
-  in = fopen (SHUT_LOG,"a");
-  if (in == (FILE *)0)
-    exit(0);
-  sprintf (buf, "Shutdown with pid %d terminated\n",pid);
-  fputs(buf,in);
-  fclose(in);
-#endif
-  exit(0);
-}
-
-void get_message()
-{
-  char line[80];
-  int max_lines=12;
-
-  puts ("Type your message. End with ^D at an empty line");
-  fputs ("shutdown> ",stdout);fflush(stdout);
-  while (fgets(line,80,stdin) != (char *)0) {
-    strcat (message,line);
-    bzero(line,strlen(line));
-    fputs ("shutdown> ",stdout);fflush(stdout);
-  }
-  putc('\n',stdout);fflush(stdout);
-}
-
-int inform_user_time()
-{
-  int min;
-
-  min = wait_time /60;
-
-  if (min == 60 || min == 30 || min == 15 || min == 10 || min <= 5)
-    return 1;
-  else
-    return 0;
-}
-
-void inform_user()
-{
-  int hour, minute;
-  char mes[80];
-
-  hour = 0;
-  minute = wait_time / 60;
-  while (minute >= 60) {
-    minute -= 60;
-    hour++;
-  }
-
-  if (hour)
-    sprintf(mes,
-    "\nThe system will shutdown in %d hour%s and %d minute%s at %.02d:%.02d\n\n",
-    hour,hour==1?"":"s",minute,minute==1?"":"s",info_hour,info_min);
-  else
-  if (minute > 1)
-    sprintf(mes,
-    "\nThe system will shutdown in %d minutes at %.02d:%.02d\n\n",
-    minute,info_hour,info_min);
-  else
-  if (wait_time > 1)
-    sprintf(mes,
-    "\nThe system will shutdown in %d seconds\n\n",
-    wait_time);
-  else
-    sprintf(mes,
-    "\nThe system will shutdown NOW\n\n");
-
-  wall(mes,message);
-}
-
-void write_pid()
-{
-  char pid[5];
-  int fd;
-
-  fd = creat(SHUT_PID,00600);
-  if (!fd)
-    return;
-  strncpy (pid,itoa(getpid()), sizeof(pid));
-  write (fd,pid,sizeof(pid));
-  close(fd);
-  return;
-}
-
-int crash_check()
-{
-  struct utmp last;
-  int fd, crashed;
-  struct stat st;
-
-  if (stat(WTMP, &st) < 0 || st.st_size == 0) return 0;
-  if ((fd = open(WTMP, O_RDONLY)) < 0) return 0;
-
-  crashed = (lseek(fd, - (off_t) sizeof(last), SEEK_END) == -1
-    || read(fd, (void *) &last, sizeof(last)) != sizeof(last)
-    || last.ut_line[0] != '~'
-    || (strncmp(last.ut_user, "shutdown", sizeof(last.ut_user))
-     && strncmp(last.ut_user, "halt", sizeof(last.ut_user))));
-  close(fd);
-  return crashed;
-}
Index: trunk/minix/commands/reboot/tinyhalt.c
===================================================================
--- trunk/minix/commands/reboot/tinyhalt.c	(revision 9)
+++ 	(revision )
@@ -1,43 +1,0 @@
-/*	tinyhalt 1.0 - small forerunner			Author: Kees J. Bot
- *
- * Disk space on the root file system is a scarce resource.  This little
- * program sits in /sbin.  It normally calls the real halt/reboot, but if
- * that isn't available then it simply calls reboot().  Can't do any logging
- * of the event anyhow.
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <signal.h>
-
-int main(int argc, char **argv)
-{
-	int flag;
-	char *prog;
-	char *reboot_code = "delay; boot";
-
-	/* Try to run the real McCoy. */
-#if __minix_vmd
-	execv("/usr/sbin/halt", argv);
-#else
-	execv("/usr/bin/halt", argv);
-#endif
-
-	if ((prog = strrchr(*argv,'/')) == nil) prog= argv[0]; else prog++;
-
-	sleep(1);	/* Not too fast. */
-  	signal(SIGHUP, SIG_IGN);
-  	signal(SIGTERM, SIG_IGN);
-	kill(1, SIGTERM);
-	kill(-1, SIGTERM);
-	sleep(1);
-
-	reboot(strcmp(prog, "reboot") == 0 ? RBT_MONITOR : RBT_HALT,
-		reboot_code, strlen(reboot_code));
-
-	write(2, "reboot call failed\n", 19);
-	return 1;
-}
Index: trunk/minix/commands/rlogind/Makefile
===================================================================
--- trunk/minix/commands/rlogind/Makefile	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-# Makefile for rlogind.
-
-CFLAGS	= $(OPT) -D_MINIX
-CC = exec cc
-LDFLAGS	=
-
-all:	rlogind
-
-OBJ=	rlogind.o setup.o
-
-rlogind:	$(OBJ)
-	$(CC) $(LDFLAGS) -o $@ $(OBJ)
-	install -S 8kw $@
-
-install:	/usr/bin/in.rlogind
-
-/usr/bin/in.rlogind:	rlogind
-	install -c $? $@
-
-clean:
-	rm -f *.o rlogind core a.out
-
-# Dependencies.
-$(OBJ):		rlogind.h
Index: trunk/minix/commands/rlogind/build
===================================================================
--- trunk/minix/commands/rlogind/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/rlogind/rlogind.c
===================================================================
--- trunk/minix/commands/rlogind/rlogind.c	(revision 9)
+++ 	(revision )
@@ -1,455 +1,0 @@
-/*
-rlogind.c
-
-Created:	by Philip Homburg <philip@cs.vu.nl>
-Log:		Utmp improvement by Kees Bot <kjb@cs.vu.nl>
-		Split to compile easier on i86 by kjb
-*/
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <time.h>
-#include <unistd.h>
-#include <utmp.h>
-#include <net/hton.h>
-#define EXTERN
-#include "rlogind.h"
-
-char pty_str[]= "/dev/ptyXX";
-char tty_str[]= "/dev/ttyXX";
-char hex_str[16]= "0123456789abcdef";
-
-char PATH_UTMP[] = "/etc/utmp";		/* current logins */
-char PATH_WTMP[] = "/usr/adm/wtmp";	/* login/logout history */
-
-char term[64]= "TERM=";
-#define ENVSIZE (sizeof("TERM=")-1)	/* skip null for concatenation. */
-int confirmed= 0;
-char *env[2];
-char *args[10];
-
-static void do_child(int tty_fd, char *tty_str);
-static void dealloc_term(int slot, char *tty_str, int pid);
-static void wtmp(char *user, char *id, char *line, int pid, int type, int slot);
-static void setup_term(int fd);
-static speed_t num2speed(int num);
-static int do_control(char *buf, int cnt);
-static void readall(char *buf, int cnt);
-
-int main(int argc, char *argv[])
-{
-	int error;
-	int i, j= 0;
-	int tty_fd, pty_fd;
-	int login_pid, write_pid;
-	int count, bytes, tmp_count;
-	char *lp= 0, *cp;
-	struct stat struct_stat;
-	int slot;
-
-	prog_name= argv[0];
-
-	/* Check if the remote user is allowed in. */
-	authenticate();
-
-	write(1, "", 1);	/* Send the '\0' */
-	confirmed= 1;
-
-	/* We try to convince the other side not the do ^S/^Q, the rlogin
-	 * protocol indicates the we only send this when XOFF is turned off
-	 * but we don't know when this happens so we tell the other side that
-	 * it is turned off.
-	 */
-	tcp_urg(1, 1);
-
-	write(1, "\220", 1);
-
-	tcp_urg(1, 0);
-
-	/* Let's look for a pty. */
-	pty_fd= -1;
-	for (i= 'p'; i <= 'z'; i++)
-	{
-		pty_str[sizeof(pty_str)-3]= i;
-		pty_str[sizeof(pty_str)-2]= '0';
-		error= stat(pty_str, &struct_stat);
-		if (error == -1)
-			continue;
-		for (j= 0; j < 16; j++)
-		{
-			pty_str[sizeof(pty_str)-2]= hex_str[j];
-			pty_fd= open(pty_str, O_RDWR);
-			if (pty_fd != -1)
-				break;
-		}
-		if (pty_fd != -1)
-			break;
-	}
-	if (pty_fd == -1)
-	{
-		printf("%s: out of ptys\r\n", prog_name);
-		exit(1);
-	}
-	tty_str[sizeof(pty_str)-3]= i;
-	tty_str[sizeof(pty_str)-2]= hex_str[j];
-
-	tty_fd= open(tty_str, O_RDWR);
-	if (tty_fd == -1)
-	{
-		printf("%s: unable to open '%s': %s\r\n", prog_name, tty_str,
-			strerror(errno));
-		exit(1);
-	}
-
-	slot= fttyslot(tty_fd);
-
-	login_pid= fork();
-	if (login_pid == -1)
-	{
-		printf("%s: unable to fork: %s\r\n", prog_name,
-			strerror(errno));
-		exit(1);
-	}
-	if (login_pid == 0)
-	{
-		close(pty_fd);
-		wtmp("", "", tty_str, login_pid, LOGIN_PROCESS, slot);
-		do_child(tty_fd, tty_str);
-	}
-	close(tty_fd);
-
-	write_pid= fork();
-	if (write_pid == -1)
-	{
-		printf("%s: unable to fork: %s\r\n", prog_name,
-			strerror(errno));
-		exit(1);
-	}
-	if (write_pid == 0)
-	{
-		dup2(pty_fd, 0);
-		count= 0;
-		for (;;)
-		{
-			if (!count)
-			{
-				count= read(0, line, sizeof(line));
-				if (count <= 0)
-					break;
-				lp= line;
-			}
-			bytes= write(1, lp, count);
-			if (bytes <= 0 || bytes > count)
-				break;
-			lp += bytes;
-			count -= bytes;
-		}
-		kill(getppid(), SIGKILL);
-		dealloc_term(slot, tty_str, login_pid);
-		_exit(1);
-	}
-
-	dup2(pty_fd, 1);
-	count= 0;
-	for (;;)
-	{
-		if (!count)
-		{
-			count= read(0, line, sizeof(line));
-			if (count <= 0)
-				break;
-			lp= line;
-		}
-		tmp_count= count;
-		cp= memchr(lp, 255, count);
-		if (cp)
-		{
-			tmp_count= cp-lp;
-			if (tmp_count == 0)
-			{
-				tmp_count= do_control(lp, count);
-				if (tmp_count)
-				{
-					lp += tmp_count;
-					count -= tmp_count;
-					continue;
-				}
-			}
-		}
-		bytes= write(1, lp, tmp_count);
-		if (bytes <= 0 || bytes > count)
-			break;
-		lp += bytes;
-		count -= bytes;
-	}
-	kill(write_pid, SIGKILL);
-	dealloc_term(slot, tty_str, login_pid);
-	return(0);
-}
-
-static void do_child(int tty_fd, char *tty_str)
-{
-	int ctty_fd, tst_fd;
-	FILE *tty_file;
-	int sav_errno;
-	char **argp;
-
-	/* Set up the terminal attributes. */
-	setup_term(tty_fd);
-
-	/* Let's start the new session. */
-	setsid();
-	ctty_fd= open(tty_str, O_RDWR);
-	if (ctty_fd == -1)
-	{
-		printf("%s(do_child): unable to open '%s': %s\r\n",
-			prog_name, tty_str, strerror(errno));
-		exit(1);
-	}
-	/* Test if we really got a controlling tty. */
-	tst_fd= open("/dev/tty", O_RDWR);
-	if (tst_fd == -1)
-	{
-		printf(
-	"%s(do_child): '%s' didn't result in a controlling tty (%s)\r\n",
-			prog_name, tty_str, strerror(errno));
-		exit(1);
-	}
-
-	argp= args;
-	*argp++= "login";
-	*argp++= "-p";
-	*argp++= "-h";
-	*argp++= hostname;
-	if (authenticated)
-		*argp++= "-f";
-	if (lusername[0] != '\0')
-		*argp++= lusername;
-
-	/* We reached the point of no return. */
-	close(tst_fd);
-	close(tty_fd);
-
-	if (ctty_fd != 0)
-	{
-		dup2(ctty_fd, 0);
-		close(ctty_fd);
-		ctty_fd= 0;
-	}
-	dup2(ctty_fd, 1);
-#if DEBUG
-	fprintf(stderr, "execing login\r\n"); 
-#endif
-	dup2(ctty_fd, 2);
-	execve("/bin/login", args, env);
-	if (errno == ENOENT) execve("/usr/bin/login", args, env);
-	sav_errno= errno;
-	tty_file= fdopen(2, "w");
-	if (tty_file)
-	{
-		fprintf(tty_file, "%s(do_child): unable to exec login: %s\r\n",
-			prog_name, strerror(sav_errno));
-		fflush(tty_file);
-	}
-	_exit(1);
-}
-
-static void dealloc_term(int slot, char *tty_str, int pid)
-{
-  wtmp("", "", tty_str, pid, DEAD_PROCESS, slot);
-
-  /* Finally we reset the owner and mode of the terminal. */
-  chown(tty_str, 0, 0);
-  chmod(tty_str, 0666);
-}
-
-static void wtmp(
-	char *user,		/* name of user */
-	char *id,		/* inittab ID */
-	char *line,		/* TTY name */
-	int pid,		/* PID of process */
-	int type,		/* TYPE of entry */
-	int slot)		/* slot number in UTMP */
-{
-/* Log an event into the UTMP and WTMP files. */
-
-  struct utmp utmp;		/* UTMP/WTMP User Accounting */
-  int fd= -1;
-  int log = 1;			/* log in wtmp */
-  char *p;
-
-  /* Strip the /dev part of the TTY name. */
-  p = strrchr(line, '/');
-  if (p != 0)
-	line= p+1;
-
-  if (type == DEAD_PROCESS) {
-	/* Don't add a logout entry for just a dying login. */
-	if ((fd = open(PATH_UTMP, O_RDONLY)) < 0) return;
-	if (lseek(fd, (off_t) slot * sizeof(utmp), SEEK_SET) != -1
-		&& read(fd, (void *) &utmp, sizeof(utmp)) == sizeof(utmp))
-	{
-		if (utmp.ut_type != INIT_PROCESS
-				&& utmp.ut_type != USER_PROCESS)
-			log= 0;
-	}
-	close(fd);
-  }
-  if (type == LOGIN_PROCESS) log= 0;	/* and don't log this one */
-
-  /* Clear the utmp record. */
-  memset((void *) &utmp, 0, sizeof(utmp));
-
-  /* Enter new values. */
-  strncpy(utmp.ut_name, user, sizeof(utmp.ut_name));
-  strncpy(utmp.ut_id, id, sizeof(utmp.ut_id));
-  strncpy(utmp.ut_line, line, sizeof(utmp.ut_line));
-  strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
-  utmp.ut_pid = pid;
-  utmp.ut_type = type;
-  utmp.ut_time = time((time_t *)0);
-
-  if (log) {
-	if ((fd = open(PATH_WTMP, O_WRONLY | O_APPEND)) < 0) return;
-	write(fd, (char *) &utmp, sizeof(struct utmp));
-	close(fd);
-  }
-
-  /* write entry to utmp */
-  if ((fd = open(PATH_UTMP, O_WRONLY)) < 0) return;
-  if (lseek(fd, (off_t) slot * sizeof(utmp), SEEK_SET) != -1)
-	write(fd, (char *) &utmp, sizeof(struct utmp));
-  close(fd);
-}
-
-void fatal(int fd, char *msg, int err)
-{
-	int len;
-	char buf[80], *bp;
-
-	bp= buf;
-	if (!confirmed)
-		*bp++= '\1';
-	if (err)
-		len= sprintf(bp, "rlogind: %s: %s.\r\n", msg, strerror(err));
-	else
-		len= sprintf(bp, "rlogind: %s.\r\n", msg);
-	write(fd, buf, bp+len-buf);
-	exit(1);
-}
-
-static void setup_term(int fd)
-{
-	char *cp, *speed;
-	struct termios tt;
-	speed_t spd;
-	int num;
-	char *check;
-
-	cp= strchr(term, '/');
-	if (cp)
-	{
-		tcgetattr(fd, &tt);
-		*cp++= '\0';
-		speed= cp;
-		cp= strchr(speed, '/');
-		if (cp)
-			*cp++= '\0';
-		num= strtol(speed, &check, 0);
-		spd= num2speed(num);
-		if (spd != B0 && check[0] == '\0')
-		{
-			cfsetospeed(&tt, spd);
-			cfsetispeed(&tt, spd);
-		}
-		tcsetattr(fd, TCSANOW, &tt);
-	}
-	env[0]= term;
-	env[1]= 0;
-}
-
-static speed_t num2speed(int num)
-{
-	static struct 
-	{
-		int num;
-		speed_t value;
-	} speed_table[]=
-	{
-		{ 0, B0, }, { 50, B50, }, { 75, B75, }, { 110, B110, },
-		{ 134, B134, }, { 150, B150, }, { 200, B200, }, { 300, B300, },
-		{ 600, B600, }, { 1200, B1200, }, { 1800, B1800, },
-		{ 2400, B2400, }, { 4800, B4800, }, { 9600, B9600, },
-		{ 19200, B19200, }, { 38400, B38400, },
-		{ -1, -1 },
-	};
-	int i;
-
-	for (i= 0; speed_table[i].num != -1; i++)
-	{
-		if (speed_table[i].num == num)
-			return (speed_table[i].value);
-	}
-	return B0;
-}
-
-static int do_control(char *cp, int cnt)
-{
-	char buf[20];
-	struct winsize winsize;
-
-	if (cnt > sizeof(buf))
-		cnt= sizeof(buf);
-
-	memcpy(buf, cp, cnt);
-
-	/* Let's fetch the first 2 bytes. */
-	if (cnt < 2)
-		readall(buf+cnt, 2-cnt);
-	if ((unsigned char)buf[1] != 255)
-		return 0;
-
-	/* Let's fetch the first 4 bytes. */
-	if (cnt < 4)
-		readall(buf+cnt, 4-cnt);
-	if (buf[2] != 's' || buf[3] != 's')
-		return 0;
-
-	/* Let's fetch a winsize structure. */
-	if (cnt < 4 + sizeof(winsize))
-		readall(buf+cnt, 4 + sizeof(winsize) - cnt);
-
-	memcpy(&winsize, buf+4, sizeof(winsize));
-	winsize.ws_row= ntohs(winsize.ws_row);
-	winsize.ws_col= ntohs(winsize.ws_col);
-	winsize.ws_xpixel= ntohs(winsize.ws_xpixel);
-	winsize.ws_ypixel= ntohs(winsize.ws_ypixel);
-#if DEBUG
-	fprintf(stderr, "setting window size to %d, %d\r\n", winsize.ws_row,
-		winsize.ws_col);
-#endif
-	ioctl(1, TIOCSWINSZ, &winsize);
-	return 4 + sizeof(winsize);
-}
-
-static void readall(char *buf, int cnt)
-{
-	int res;
-
-	while(cnt)
-	{
-		res= read(0, buf, cnt);
-		if (res <= 0)
-			return;
-		buf += cnt;
-		cnt -= res;
-	}
-}
Index: trunk/minix/commands/rlogind/rlogind.h
===================================================================
--- trunk/minix/commands/rlogind/rlogind.h	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-/*
-in.rld.h
-*/
-
-#define NMAX	30
-
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
-EXTERN char *prog_name;
-EXTERN char hostname[256+1];
-EXTERN char line[1024];
-EXTERN char lusername[NMAX+1], rusername[NMAX+1];
-EXTERN char term[64];
-EXTERN int authenticated;
-
-/* in.rld.c: */
-void fatal(int fd, char *msg, int err);
-
-/* setup.c: */
-void authenticate(void);
-int do_rlogin(void);
-void tcp_urg(int fd, int on);
Index: trunk/minix/commands/rlogind/setup.c
===================================================================
--- trunk/minix/commands/rlogind/setup.c	(revision 9)
+++ 	(revision )
@@ -1,92 +1,0 @@
-/*
-setup.c
-*/
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <net/netlib.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include <net/gen/netdb.h>
-#include <net/gen/socket.h>
-#include "rlogind.h"
-
-static void getstr(char *buf, int cnt, char *errmsg);
-
-void authenticate(void)
-{
-	int result;
-	struct nwio_tcpconf tcpconf;
-	struct hostent *hostent;
-	char c;
-
-	/* Let's lookup the hostname for the connection. */
-	result= ioctl (0, NWIOGTCPCONF, &tcpconf);
-	if (result<0)
-	{
-		fprintf(stderr, "%s: ioctl(NWIOTCPCONF): %s\r\n", 
-			prog_name, strerror(errno));
-		exit(1);
-	}
-	hostent= gethostbyaddr((char *)&tcpconf.nwtc_remaddr,
-		sizeof(tcpconf.nwtc_remaddr), AF_INET);
-	if (hostent)
-	{
-		strncpy(hostname, hostent->h_name, sizeof(hostname)-1);
-		hostname[sizeof(hostname)-1]= '\0';
-	}
-	else
-	{
-		strcpy(hostname, inet_ntoa(tcpconf.nwtc_remaddr));
-	}
-
-	authenticated = 0;
-
-	getstr(&c, 1, "protocol violation");
-	getstr(rusername, sizeof(rusername), "remuser too long");
-	getstr(lusername, sizeof(lusername), "locuser too long");
-	strcpy(term, "TERM=");
-	getstr(term+5, sizeof(term)-5, "Terminal type too long");
-
-#if DEBUG
-	fprintf(stderr, "got lu= %s, ru= %s, te= %s\r\n", lusername, rusername,
-		term);
-#endif
-	if (iruserok(tcpconf.nwtc_remaddr, 0, rusername, lusername) == 0)
-		authenticated = 1;
-}
-
-static void getstr(char *buf, int cnt, char *errmsg)
-{
-	char c;
-
-	errno= 0;
-	do
-	{
-		if (read(0, &c, 1) != 1)
-			fatal(1, "read failed", errno);
-		cnt--;
-		if (cnt < 0)
-			fatal(1, errmsg, 0);
-		*buf++= c;
-	} while(c != 0);
-}
-
-void tcp_urg(int fd, int on)
-{
-	struct nwio_tcpopt tcpopt;
-
-	tcpopt.nwto_flags= on ? (NWTO_BSD_URG | NWTO_SND_URG) : NWTO_SND_NOTURG;
-	if (ioctl(1, NWIOSTCPOPT, &tcpopt) == -1)
-	{
-		fprintf(stderr, "rlogind: NWIOSTCPOPT failed: %s\r\n",
-			strerror(errno));
-	}
-}
Index: trunk/minix/commands/scripts/DESCRIBE.sh
===================================================================
--- trunk/minix/commands/scripts/DESCRIBE.sh	(revision 9)
+++ 	(revision )
@@ -1,188 +1,0 @@
-#!/bin/sh
-#
-# DESCRIBE 2.2 - Describe the given devices.		Author: Kees J. Bot
-#
-# BUGS
-# - Arguments may not contain shell metacharacters.
-
-case $# in
-0)	flag=; set -$- /dev ;;
-*)	flag=d ;;
-esac
-
-ls -l$flag $* | \
-sed	-e '/^total/d' \
-	-e '/^[^bc]/s/.* /BAD BAD /' \
-	-e '/^[bc]/s/.* \([0-9][0-9]*\), *\([0-9][0-9]*\).* /\1 \2 /' \
-| {
-ex=0	# exit code
-
-while read major minor path
-do
-    case $path in
-    /*)	name=`expr $path : '.*/\\(.*\\)$'`
-	;;
-    *)	name=$path
-    esac
-    dev= des=
-
-    case $major in	# One of the controllers?  What is its controller nr?
-    3)	ctrlr=0	;;
-    8)	ctrlr=1	;;
-    10)	ctrlr=2	;;
-    12)	ctrlr=3	;;
-    esac
-
-    case $major,$minor in
-    1,0)	des="RAM disk" dev=ram
-	;;
-    1,1)	des="memory" dev=mem
-	;;
-    1,2)	des="kernel memory" dev=kmem
-	;;
-    1,3)	des="null device, data sink" dev=null
-	;;
-    2,*)	drive=`expr $minor % 4`
-	case `expr $minor - $drive` in
-	0)	des='auto density' dev="fd$drive"
-	    ;;
-	4)	des='360k, 5.25"' dev="pc$drive"
-	    ;;
-	8)	des='1.2M, 5.25"' dev="at$drive"
-	    ;;
-	12)	des='360k in 720k, 5.25"' dev="qd$drive"
-	    ;;
-	16)	des='720k, 3.5"' dev="ps$drive"
-	    ;;
-	20)	des='360k in 1.2M, 5.25"' dev="pat$drive"
-	    ;;
-	24)	des='720k in 1.2M, 5.25"' dev="qh$drive"
-	    ;;
-	28)	des='1.44M, 3.5"' dev="PS$drive"
-	    ;;
-	112)	des='auto partition 0' dev="fd${drive}p0"
-	    ;;
-	116)	des='auto partition 1' dev="fd${drive}p1"
-	    ;;
-	120)	des='auto partition 2' dev="fd${drive}p2"
-	    ;;
-	124)	des='auto partition 3' dev="fd${drive}p3"
-	    ;;
-	*)	dev=BAD
-	esac
-	des="floppy drive $drive ($des)"
-	;;
-    [38],[05]|[38],[123][05]|1[02],[05]|1[02],[123][05])
-	drive=`expr $minor / 5`
-	des="controller $ctrlr disk $drive" dev=c${ctrlr}d${drive}
-	;;
-    [38],?|[38],[123]?|1[02],?|1[02],[123]?)
-	drive=`expr $minor / 5`
-	par=`expr $minor % 5 - 1`
-	des="controller $ctrlr disk $drive partition $par"
-	dev=c${ctrlr}d${drive}p${par}
-	;;
-    [38],12[89]|[38],1[3-9]?|[38],2??|1[02],12[89]|1[02],1[3-9]?|1[02],2??)
-	drive=`expr \\( $minor - 128 \\) / 16`
-	par=`expr \\( \\( $minor - 128 \\) / 4 \\) % 4`
-	sub=`expr \\( $minor - 128 \\) % 4`
-	des="hard disk $drive, partition $par, subpartition $sub"
-	des="controller $ctrlr disk $drive partition $par slice $sub"
-	#par=`expr $drive '*' 5 + $par`
-	dev=c${ctrlr}d${drive}p${par}s${sub}
-	;;
-    [38],6[4-9]|[38],7?|1[02],6[4-9]|1[02],7?)
-	tape=`expr \\( $minor - 64 \\) / 2`
-	case $minor in
-	*[02468])
-	    des="controller $ctrlr tape $tape (non-rewinding)"
-	    dev=c${ctrlr}t${tape}n
-	    ;;
-	*[13579])
-	    des="controller $ctrlr tape $tape (rewinding)"
-	    dev=c${ctrlr}t${tape}
-	esac
-	;;
-    4,0)	des="console device" dev=console
-	;;
-    4,[1-7])des="virtual console $minor" dev=ttyc$minor
-	;;
-    4,15)	des="diagnostics device" dev=log
-	;;
-    4,1[6-9])
-	line=`expr $minor - 16`
-	des="serial line $line" dev=tty0$line
-	;;
-    4,12[89]|4,1[3-8]?|4,19[01])
-	p=`expr \\( $minor - 128 \\) / 16 | tr '0123' 'pqrs'`
-	n=`expr $minor % 16`
-	test $n -ge 10 && n=`expr $n - 10 | tr '012345' 'abcdef'`
-	des="pseudo tty `expr $minor - 128`" dev=tty$p$n
-	;;
-    4,???)
-	p=`expr \\( $minor - 192 \\) / 16 | tr '0123' 'pqrs'`
-	n=`expr $minor % 16`
-	test $n -ge 10 && n=`expr $n - 10 | tr '012345' 'abcdef'`
-	des="controller of tty$p$n" dev=pty$p$n
-	;;
-    5,0)	des="anonymous tty" dev=tty
-	;;
-    6,0)	des="line printer, parallel port" dev=lp
-	;;
-    7,*)
-	d=`expr $minor % 8`
-	n=`expr $minor / 8`
-	case $d in
-	0)  case $name in
-	    psip*)
-		des="Pseudo IP #$n" dev=psip
-		;;
-	    *)  des="raw ethernet #$n" dev=eth
-	    esac
-	    ;;
-	1)  des="raw IP #$n" dev=ip
-	    ;;
-	2)  des="TCP/IP #$n" dev=tcp
-	    ;;
-	3)  des="UDP #$n" dev=udp
-	esac
-	case $d in
-	[0123])
-	    if [ "$name" = "$dev" ]
-	    then
-		des="$des (default)"
-	    else
-		dev=$dev$n
-	    fi
-	esac
-	;;
-    13,0)
-	des="audio" dev=audio
-	;;
-    14,0)
-	des="audio mixer" dev=mixer
-	;;
-    BAD,BAD)
-	des= dev=
-	;;
-    *)	dev=BAD
-    esac
-
-    case $name:$dev in
-    *:)
-	echo "$path: not a device" >&2
-	ex=1
-	;;
-    *:*BAD*)
-	echo "$path: cannot describe: major=$major, minor=$minor" >&2
-	ex=1
-	;;
-    $dev:*)
-	echo "$path: $des"
-	;;
-    *:*)	echo "$path: nonstandard name for $dev: $des"
-    esac
-done
-
-exit $ex
-}
Index: trunk/minix/commands/scripts/M.sh
===================================================================
--- trunk/minix/commands/scripts/M.sh	(revision 9)
+++ 	(revision )
@@ -1,28 +1,0 @@
-#!/bin/sh
-#
-#	M, U - mount or unmount standard devices.
-
-case $#:$2 in
-1:|2:-r)	;;
-*)	echo "Usage: $0 <abbreviation> [-r]" >&2; exit 1
-esac
-
-. /etc/fstab
-
-dev=$1 dir=$1
-
-case $1 in
-0)	dev=/dev/fd0 dir=fd0 ;;
-1)	dev=/dev/fd1 dir=fd1 ;;
-PS0|at0|fd0|pat0|pc0|ps0)	dev=/dev/$dev dir=fd0 ;;
-PS1|at1|fd1|pat1|pc1|ps1)	dev=/dev/$dev dir=fd1 ;;
-root)	dev=$root ;;
-tmp)	dev=$tmp ;;
-usr)	dev=$usr ;;
-*)	dev=/dev/$dev dir=mnt
-esac
-
-case $0 in
-*M)	mount $dev /$dir $2 ;;
-*U)	umount $dev
-esac
Index: trunk/minix/commands/scripts/MAKEDEV.sh
===================================================================
--- trunk/minix/commands/scripts/MAKEDEV.sh	(revision 9)
+++ 	(revision )
@@ -1,267 +1,0 @@
-#!/bin/sh
-#
-# MAKEDEV 3.3 - Make special devices.			Author: Kees J. Bot
-
-case $1 in
--n)	e=echo; shift ;;	# Just echo when -n is given.
-*)	e=
-esac
-
-case $#:$1 in
-1:std)		# Standard devices.
-    set -$- mem fd0 fd1 fd0p0 fd1p0 \
-	c0d0 c0d0p0 c0d0p0s0 c0d1 c0d1p0 c0d1p0s0 \
-	c0d2 c0d2p0 c0d2p0s0 c0d3 c0d3p0 c0d3p0s0 \
-	c0d4 c0d4p0 c0d4p0s0 c0d5 c0d5p0 c0d5p0s0 \
-	c0d6 c0d6p0 c0d6p0s0 c0d7 c0d7p0 c0d7p0s0 \
-	tty ttyc1 ttyc2 ttyc3 tty00 tty01 tty02 tty03 \
-	ttyp0 ttyp1 ttyp2 ttyp3 ttyp4 ttyp5 ttyp6 ttyp7 ttyp8 ttyp9 \
-	ttypa ttypb ttypc ttypd ttype ttypf \
-	ttyq0 ttyq1 ttyq2 ttyq3 ttyq4 ttyq5 ttyq6 ttyq7 ttyq8 ttyq9 \
-	ttyqa ttyqb ttyqc ttyqd ttyqe ttyqf \
-	eth klog random cmos rescue
-    ;;
-0:|1:-\?)
-    cat >&2 <<EOF
-Usage:	$0 [-n] key ...
-Where key is one of the following:
-  ram mem kmem null boot zero	  # One of these makes all these memory devices
-  fd0 fd1 ...		  # Floppy devices for drive 0, 1, ...
-  fd0p0 fd1p0 ...	  # Make floppy partitions fd0p[0-3], fd1p[0-3], ...
-  c0d0 c0d1 ...		  # Make disks c0d0, c0d1, ...
-  c0d0p0 c0d1p0 ...	  # Make partitions c0d0p[0-3], c0d1p[0-3], ...
-  c0d0p0s0 c0d1p0s0 ...	  # Subparts c0d0p[0-3]s[0-3], c0d1p[0-3]s[0-3], ...
-  c1d0(p0)(s0)		  # Likewise for controller 1
-  c0t0 c0t1 c1t0 ...	  # Make tape devices c0t0, c0t0n, c0t1, ...
-  console lp tty log	  # One of these makes all four
-  ttyc1 ... ttyc7         # Virtual consoles
-  tty00 ... tty03         # Make serial lines
-  ttyp0 ... ttyq0 ...     # Make tty, pty pairs
-  eth ip tcp udp	  # One of these makes some TCP/IP devices
-  audio mixer		  # Make audio devices
-  klog                    # Make /dev/klog
-  random                  # Make /dev/random, /dev/urandom
-  cmos                    # Make /dev/cmos
-  kbd                     # Make /dev/kbd
-  kbdaux                  # Make /dev/kbdaux
-  rescue                  # Make /dev/rescue
-  video                   # Make /dev/video
-  std			  # All standard devices
-EOF
-    exit 1
-esac
-
-umask 077
-ex=0
-
-for dev
-do
-    case $dev in	# One of the controllers?  Precompute major device nr.
-    c0*) maj=3  ;;
-    c1*) maj=8  ;;
-    c2*) maj=10 ;;
-    c3*) maj=12 ;;
-    esac
-
-    case $dev in
-    ram|mem|kmem|null|boot|zero)
-	# Memory devices.
-	#
-	$e mknod ram b 1 0;	$e chmod 600 ram
-	$e mknod mem c 1 1;	$e chmod 640 mem
-	$e mknod kmem c 1 2;	$e chmod 640 kmem
-	$e mknod null c 1 3;	$e chmod 666 null
-	$e mknod boot b 1 4;	$e chmod 600 ram
-	$e mknod zero c 1 5;	$e chmod 644 zero
-	$e chgrp kmem ram mem kmem null boot zero
-	;;
-    fd[0-3])
-	# Floppy disk drive n.
-	#
-	d=`expr $dev : '.*\\(.\\)'`	# Drive number.
-	$e mknod $dev  b 2 $d
-	$e chmod 666 $dev
-	;;
-    pc[0-3]|at[0-3]|qd[0-3]|ps[0-3]|pat[0-3]|qh[0-3]|PS[0-3])
-	# Obsolete density locked floppy disk drive n.
-	#
-	d=`expr $dev : '.*\\(.\\)'`	# Drive number.
-	m=$d				# Minor device number.
-
-	$e mknod pc$d  b 2 $m;	m=`expr $m + 4`
-	$e mknod at$d  b 2 $m;	m=`expr $m + 4`
-	$e mknod qd$d  b 2 $m;	m=`expr $m + 4`
-	$e mknod ps$d  b 2 $m;	m=`expr $m + 4`
-	$e mknod pat$d b 2 $m;	m=`expr $m + 4`
-	$e mknod qh$d  b 2 $m;	m=`expr $m + 4`
-	$e mknod PS$d  b 2 $m;	m=`expr $m + 4`
-
-	$e chmod 666 pc$d at$d qd$d ps$d pat$d qh$d PS$d
-	;;
-    fd[0-3]p[0-3])
-	# Floppy disk partitions.
-	#
-	n=`expr $dev : '\\(.*\\)..'`	# Name prefix.
-	d=`expr $dev : '..\\(.\\)'`	# Drive number.
-	m=`expr 112 + $d`		# Minor of partition 0.
-	alldev=
-
-	for p in 0 1 2 3
-	do
-	    m=`expr 112 + $d + $p '*' 4` # Minor of partition $p.
-	    $e mknod ${n}p${p} b 2 $m	# Make e.g. fd0p0 - fd0p3
-	    alldev="$alldev ${n}p${p}"
-	done
-	$e chmod 666 $alldev
-	;;
-    c[0-3]d[0-7])
-	# Whole disk devices.
-	d=`expr $dev : '...\\(.\\)'`	# Disk number.
-	m=`expr $d '*' 5`		# Minor device number.
-	$e mknod $dev b $maj $m
-	$e chmod 600 $dev
-	;;
-    c[0-3]d[0-7]p[0-3])
-	# Disk primary partitions.
-	n=`expr $dev : '\\(.*\\).'`	# Name prefix.
-	d=`expr $dev : '...\\(.\\)'`	# Disk number.
-	alldev=
-
-	for p in 0 1 2 3
-	do
-	    m=`expr $d '*' 5 + 1 + $p`	# Minor device number.
-	    $e mknod $n$p b $maj $m
-	    alldev="$alldev $n$p"
-	done
-	$e chmod 600 $alldev
-	;;
-    c[0-3]d[0-7]p[0-3]s[0-3])
-	# Disk subpartition.
-	n=`expr $dev : '\\(.*\\)...'`	# Name prefix.
-	d=`expr $dev : '...\\(.\\)'`	# Disk number.
-	alldev=
-
-	for p in 0 1 2 3
-	do
-	    for s in 0 1 2 3
-	    do
-		m=`expr 128 + $d '*' 16 + $p '*' 4 + $s`  # Minor device nr.
-		$e mknod ${n}${p}s${s} b $maj $m
-		alldev="$alldev ${n}${p}s${s}"
-	    done
-	done
-	$e chmod 600 $alldev
-	;;
-    c[0-3]t[0-7]|c[0-3]t[0-7]n)
-	# Tape devices.
-	n=`expr $dev : '\\(....\\)'`	# Name prefix.
-	t=`expr $dev : '...\\(.\\)'`	# Tape number.
-	m=`expr 64 + $t '*' 2`		# Minor device number.
-	$e mknod ${n}n c $maj $m
-	$e mknod ${n} c $maj `expr $m + 1`
-	$e chmod 660 ${n}n ${n}
-	;;
-    console|lp|tty|log|kbd|kbdaux|video)
-	# Console, line printer, anonymous tty, diagnostics device,
-	# raw keyboard, ps/2 mouse, video.
-	$e mknod console c 4 0
-	$e chmod 600 console
-	$e chgrp tty console
-	$e mknod tty c 5 0
-	$e chmod 666 tty
-	$e mknod lp c 6 0
-	$e chown daemon lp
-	$e chgrp daemon lp
-	$e chmod 200 lp
-	$e mknod log c 4 15
-	$e chmod 222 log
-	$e mknod kbd c 4 127
-	$e mknod kbdaux c 4 126
-	$e chmod 660 kbd kbdaux
-	$e chgrp operator kbd kbdaux
-	$e mknod video c 4 125
-	$e chmod 600 video
-	$e chgrp operator video
-	;;
-    ttyc[1-7])
-	# Virtual consoles.
-	#
-	m=`expr $dev : '....\\(.*\\)'`	# Minor device number.
-	$e mknod $dev c 4 $m
-	$e chgrp tty $dev
-	$e chmod 600 $dev
-	;;
-    tty0[0-3])
-	# Serial lines.
-	#
-	n=`expr $dev : '.*\\(.\\)'`
-	$e mknod $dev c 4 `expr $n + 16`
-	$e chmod 666 $dev
-	$e chgrp tty $dev
-	;;
-    tty[p-s][0-9a-f]|pty[p-s][0-9a-f])
-	# Pseudo ttys.
-	#
-	dev=`expr $dev : '...\\(..\\)'`
-	g=`expr $dev : '\\(.\\)'`	# Which group.
-	g=`echo $g | tr 'pqrs' '0123'`
-	n=`expr $dev : '.\\(.\\)'`	# Which pty in the group.
-	case $n in
-	[a-f])	n=1`echo $n | tr 'abcdef' '012345'`
-	esac
-
-	$e mknod tty$dev c 4 `expr $g '*' 16 + $n + 128`
-	$e mknod pty$dev c 4 `expr $g '*' 16 + $n + 192`
-	$e chgrp tty tty$dev pty$dev
-	$e chmod 666 tty$dev pty$dev
-	;;
-    eth|ip|tcp|udp|eth0|ip0|tcp0|udp0)
-	# TCP/IP devices.
-	#
-	$e mknod eth0 c 7 0		# Network 0 (Ethernet)
-	$e mknod ip0 c 7 1
-	$e mknod tcp0 c 7 2
-	$e mknod udp0 c 7 3
-	$e chmod 600 eth0 ip0
-	$e chmod 666 tcp0 udp0
-	$e ln -f eth0 eth		# Default interface
-	$e ln -f ip0 ip
-	$e ln -f tcp0 tcp
-	$e ln -f udp0 udp
-	;;
-    audio|mixer)
-	# Audio devices.
-	#
-   $e mknod audio c 13 0
-   $e mknod rec c 13 1
-   $e mknod mixer c 13 2
-   $e chmod 666 audio rec mixer
-	;;
-    random|urandom)
-	# random data generator.
-	$e mknod random c 16 0;	$e chmod 644 random
-	$e mknod urandom c 16 0; $e chmod 644 urandom
-	$e chgrp operator random urandom
-	;;
-    cmos)
-    	# cmos device (set/get system time).
-    	$e mknod cmos c 17 0
-	$e chmod 600 cmos
-	;;
-    rescue)
-    	# rescue device
-    	$e mknod rescue b 9 0
-	$e chmod 644 rescue
-	;;
-    klog)
-    	# logging device.
-    	$e mknod klog c 15 0
-	$e chmod 600 klog
-	;;
-    *)
-	echo "$0: don't know about $dev" >&2
-	ex=1
-    esac
-done
-
-exit $ex
Index: trunk/minix/commands/scripts/Makefile
===================================================================
--- trunk/minix/commands/scripts/Makefile	(revision 9)
+++ 	(revision )
@@ -1,180 +1,0 @@
-# Makefile for cmd/scripts.
-
-CFLAGS	= -D_MINIX -D_POSIX_SOURCE
-CCLD	= $(CC) -i $(CFLAGS)
-MAKE	= exec make -$(MAKEFLAGS) install
-
-all:		# Does nothing
-
-install:	usr root
-
-# Commands on the /usr partition.
-usr:	\
-	/usr/bin/DESCRIBE \
-	/usr/bin/M \
-		/usr/bin/U \
-	/usr/bin/MAKEDEV \
-	/usr/bin/bigmake \
-	/usr/bin/adduser \
-	/usr/bin/binpackage \
-	/usr/bin/binpackages \
-	/usr/bin/cd \
-		/usr/bin/[ \
-		/usr/bin/command \
-		/usr/bin/easypack \
-		/usr/bin/echo \
-		/usr/bin/expr \
-		/usr/bin/false \
-		/usr/bin/getopts \
-		/usr/bin/getpack \
-		/usr/bin/read \
-		/usr/bin/test \
-		/usr/bin/true \
-		/usr/bin/umask \
-		/usr/bin/wait \
-	/usr/bin/checkhier \
-	/usr/bin/clear \
-		/usr/bin/clr \
-	/usr/bin/makewhatis \
-	/usr/bin/mkdep \
-	/usr/bin/mkdist \
-	/bin/setup \
-	/usr/bin/binsizes \
-	/usr/bin/rotate \
-	/usr/bin/floppysetup \
-	/usr/bin/packit \
-	/usr/bin/packman \
-	/usr/bin/spell \
-	/usr/bin/srccrc \
-	/usr/bin/svclog \
-	/usr/bin/version \
-	/usr/bin/whatis \
-		/usr/bin/apropos \
-	/usr/bin/whereis \
-
-# Commands on the root partition.
-root:	\
-	/bin/M \
-		/bin/U \
-	/bin/cd \
-		/bin/[ \
-		/bin/command \
-		/bin/echo \
-		/bin/expr \
-		/bin/false \
-		/bin/getopts \
-		/bin/read \
-		/bin/test \
-		/bin/true \
-		/bin/umask \
-		/bin/wait \
-
-clean:
-
-/usr/bin/DESCRIBE:	DESCRIBE.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/M:	M.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/U:	/usr/bin/M
-	install -m 755 -l $? $@
-
-/usr/bin/MAKEDEV:	MAKEDEV.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/bigmake:	bigmake.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/binpackage:	binpackage.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/binpackages:	binpackages.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/adduser:	adduser.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/cd:	cd.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/[ /usr/bin/command /usr/bin/echo /usr/bin/expr /usr/bin/false \
-/usr/bin/getopts /usr/bin/read /usr/bin/test /usr/bin/true /usr/bin/umask \
-/usr/bin/wait:	/usr/bin/cd
-	install -m 755 -l $? $@
-
-/usr/bin/easypack:	easypack.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/getpack:	getpack.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/checkhier:	checkhier.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/clear:	clear.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/clr:	/usr/bin/clear
-	install -m 755 -l $? $@
-
-/usr/bin/makewhatis:	makewhatis.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/mkdep:	mkdep.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/mkdist:	mkdist.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/floppysetup:	floppysetup.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/rotate:	rotate.sh
-	install -m 755 -c -o bin $? $@
-
-/bin/setup:	setup.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/binsizes:	binsizes.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/packit:	packit.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/packman:	packman.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/spell:	spell.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/srccrc:	srccrc.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/svclog:	svclog.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/version:	version.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/whatis:	whatis.sh
-	install -m 755 -c -o bin $? $@
-
-/usr/bin/apropos:	/usr/bin/whatis
-	install -m 755 -l $? $@
-
-/usr/bin/whereis:	whereis.sh
-	install -m 755 -c -o bin $? $@
-
-/bin/M:	/usr/bin/M
-	install -m 755 -c -o bin $? $@
-
-/bin/U:	/bin/M
-	install -m 755 -l $? $@
-
-/bin/cd:	/usr/bin/cd
-	install -m 755 -lc $? $@
-
-/bin/[ /bin/command /bin/echo /bin/expr /bin/false /bin/getopts \
-/bin/read /bin/test /bin/true /bin/umask /bin/wait:	/bin/cd
-	install -m 755 -l $? $@
Index: trunk/minix/commands/scripts/adduser.sh
===================================================================
--- trunk/minix/commands/scripts/adduser.sh	(revision 9)
+++ 	(revision )
@@ -1,121 +1,0 @@
-#!/bin/sh
-#
-#	adduser 1.0 - add a new user to the system	Author: Kees J. Bot
-#								16 Jan 1996
-
-# Check arguments.
-case "$#" in
-3)	user="$1"; group="$2"; home="$3"
-	;;
-*)	echo "Usage: adduser user group home-dir" >&2; exit 1
-esac
-
-# We need to be root.
-case "`id`" in
-'uid=0('*)
-	;;
-*)	echo "adduser: you must be root to add users" >&2; exit 1
-esac
-
-# User and group names must be alphanumeric and no longer than 8 characters.
-len=`expr "$user" : '[a-z][a-z0-9]*$'`
-if [ "$len" -eq 0 -o "$len" -gt 8 ]
-then
-	echo >&2 \
-"adduser: the user name must be alphanumeric and no longer than 8 characters"
-	exit 1
-fi
-
-len=`expr "$group" : '[a-z][a-z0-9]*$'`
-if [ "$len" -eq 0 -o "$len" -gt 8 ]
-then
-	echo >&2 \
-"adduser: the group name must be alphanumeric and no longer than 8 characters"
-	exit 1
-fi
-
-# The new user name must not exist, but the group must exist.
-if grep "^$user:" /etc/passwd >/dev/null
-then
-	echo "adduser: user $user already exists" >&2
-	exit 1
-fi
-
-gid=`sed -e "/^$group:/!d" -e 's/^[^:]*:[^:]*:\\([^:]*\\):.*/\\1/' /etc/group`
-if [ `expr "$gid" : '[0-9]*$'` -eq 0 ]
-then
-	echo "adduser: group $group does not exist" >&2
-	exit 1
-fi
-
-# Find the first free user-id of 10 or higher.
-uid=10
-while grep "^[^:]*:[^:]*:$uid:.*" /etc/passwd >/dev/null
-do
-	uid=`expr $uid + 1`
-done
-
-# No interruptions.
-trap '' 1 2 3 15
-
-# Lock the password file.
-ln /etc/passwd /etc/ptmp || {
-	echo "adduser: password file busy, try again later"
-	exit 1
-}
-
-# Make the new home directory, it should not exist already.
-mkdir "$home" || {
-	rm -rf /etc/ptmp
-	exit 1
-}
-
-# Make the new home directory by copying the honorary home directory of our
-# fearless leader.
-echo cpdir /usr/ast "$home"
-cpdir /usr/ast "$home" || {
-	rm -rf /etc/ptmp "$home"
-	exit 1
-}
-
-# Change the ownership to the new user.
-echo chown -R $uid:$gid "$home"
-chown -R $uid:$group "$home" || {
-	rm -rf /etc/ptmp "$home"
-	exit 1
-}
-
-# Is there a shadow password file?  If so add an entry.
-if [ -f /etc/shadow ]
-then
-	echo "echo $user::0:0::: >>/etc/shadow"
-	echo "$user::0:0:::" >>/etc/shadow || {
-		rm -rf /etc/ptmp "$home"
-		exit 1
-	}
-	pwd="##$user"
-else
-	pwd=
-fi
-
-# Finish up by adding a password file entry.
-echo "echo $user:$pwd:$uid:$gid:$user:$home: >>/etc/passwd"
-echo "$user:$pwd:$uid:$gid:$user:$home:" >>/etc/passwd || {
-	rm -rf /etc/ptmp "$home"
-	exit 1
-}
-
-# Remove the lock.
-rm /etc/ptmp || exit
-
-echo "
-The new user $user has been added to the system.  Note that the password,
-full name, and shell may be changed with the commands passwd(1), chfn(1),
-and chsh(1).  The password is now empty, so only console logins are possible."
-if [ $gid = 0 ]
-then
-	echo "\
-Also note that a new operator needs an executable search path (\$PATH) that
-does not contain the current directory (an empty field or "." in \$PATH)."
-fi
-exit 0
Index: trunk/minix/commands/scripts/bigmake.sh
===================================================================
--- trunk/minix/commands/scripts/bigmake.sh	(revision 9)
+++ 	(revision )
@@ -1,6 +1,0 @@
-#!/bin/sh
-binsizes big
-make $*
-c=$?
-binsizes normal
-exit $c
Index: trunk/minix/commands/scripts/binpackage.sh
===================================================================
--- trunk/minix/commands/scripts/binpackage.sh	(revision 9)
+++ 	(revision )
@@ -1,66 +1,0 @@
-#!/bin/sh 
-
-PI=.postinstall
-INFO=.minixpackage
-
-set -e
-
-# No trailing slashes in the directory, because we want to base the
-# package filename on it.
-dir=`echo "$1" | sed 's/\/*$//'`
-
-if [ $# -ne 2 ]
-then	echo "Usage: $0 sourcedir packagedir"
-	exit 1
-fi
-
-if [ ! -d "$dir" ]
-then	echo "Error: $dir isn't a directory."
-	exit 1
-fi
-
-here=`pwd`
-
-case "$dir" in
-/*) srcdir="$dir" ;;
-*) srcdir="$here/$dir" ;;
-esac
-
-case $2 in
-/*) pdir="$2" ;;
-*) pdir="$here/$2" ;;
-esac
-
-packagestart=$srcdir/now
-findlist=$srcdir/findlist
-tar=$srcdir/"`basename ${dir}`".tar
-tarbz=$tar.bz2
-
-mkdir $pdir 2>/dev/null || true
-binsizes=big
-rc=$dir/.binpackage
-if [ -f $rc ]
-then	 . $rc
-fi
-binsizes $binsizes
-touch $packagestart
-sleep 1
-cd $dir
-
-if [ ! -f build -a ! -f build.minix ]
-then	echo "Error: No build or build.minix script in $dir."
-	exit 1
-fi
-
-if [ -f build.minix ]
-then	sh -e build.minix
-else	sh -e build
-fi
-
-echo " * Building package"
-echo "Minix package $dir built `date`." >$INFO
-( echo $INFO ; if [ -f $PI ]; then echo $PI; fi; find / -cnewer $packagestart | egrep -v "^($srcdir|/(dev|tmp)|/usr/(tmp|log|adm|run)|/etc/utmp|/var/run)" ) | pax -w -d | bzip2 >$tarbz
-rm -f $packagestart $findlist $tarcmd
-binsizes normal
-mv $tarbz $pdir
-exit 0
Index: trunk/minix/commands/scripts/binpackages.sh
===================================================================
--- trunk/minix/commands/scripts/binpackages.sh	(revision 9)
+++ 	(revision )
@@ -1,13 +1,0 @@
-#!/bin/sh
-
-pdir=Packages
-
-for d in */build
-do
-	dir="`echo $d | sed 's/\/build$//'`"
-	if [ ! -f $pdir/$dir.tar.gz ]
-	then
-		echo " * $dir"
-		binpackage $dir $pdir
-	fi
-done
Index: trunk/minix/commands/scripts/binsizes.sh
===================================================================
--- trunk/minix/commands/scripts/binsizes.sh	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-#!/bin/sh
-
-t=/etc/binary_sizes
-
-if [ "$#" -ne 1 ]
-then	echo "Usage: $0 <big|normal>"
-	exit 1
-fi
-
-if [ "$1" != normal ]
-then	t=$t.$1
-fi
-
-chmem =250000 /usr/lib/* /usr/lib/i386/* >/dev/null 2>&1
-chmem =600000 /usr/lib/ego/*  >/dev/null 2>&1
-if [ -f $t ]
-then	cat "$t" | while read line
-	do	awk '{ print "chmem =" $2 " " $1 " 2>&1 | grep -v area.changed.from  || exit 1"}'
-	done | /bin/sh -e || exit 1
-else
-	echo "$0: $t does not exist" >&2
-	exit 1
-fi
-exit 0
Index: trunk/minix/commands/scripts/build
===================================================================
--- trunk/minix/commands/scripts/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/scripts/cd.sh
===================================================================
--- trunk/minix/commands/scripts/cd.sh	(revision 9)
+++ 	(revision )
@@ -1,11 +1,0 @@
-#!/bin/sh
-#
-# cd 1.3 - equivalents for normally builtin commands.	Author: Kees J. Bot
-
-case $0 in
-*/*)	command="`expr "$0" : '.*/\(.*\)'`"
-	;;
-*)	command="$0"
-esac
-
-"$command" "$@"
Index: trunk/minix/commands/scripts/checkhier.sh
===================================================================
--- trunk/minix/commands/scripts/checkhier.sh	(revision 9)
+++ 	(revision )
@@ -1,181 +1,0 @@
-#!/bin/sh
-#
-#	checkhier 2.7 - check the directory hierarchy	Author: Kees J. Bot
-#								7 May 1995
-
-case "`id`" in
-'uid=0('*)	;;
-*)	echo "$0: must be run by root" >&2
-	exit 1
-esac
-
-# List of all interesting top level files and directories, with mode,
-# owner and group.  Only the key files are listed, the rest is owned
-# by bin, has mode 755 or 644, and is not critical to the operation of
-# the system.
-{
-	cat <<'EOF'
-drwxr-xr-x	root	operator	/
-drwxr-xr-x	bin	operator	/bin
-drwxr-xr-x	root	operator	/dev
-drwxr-xr-x	root	operator	/etc
--rw-r--r--	root	operator	/etc/fstab
--rw-r--r--	root	operator	/etc/group
--rw-r--r--	root	operator	/etc/hostname.file
--rw-r--r--	root	operator	/etc/inet.conf
--rw-r--r--	root	operator	/etc/motd
--rw-r--r--	root	operator	/etc/mtab
--rw-r--r--	root	operator	/etc/passwd
--rw-r--r--	root	operator	/etc/profile
--rw-r--r--	root	operator	/etc/protocols
--rw-r--r--	root	operator	/etc/rc
--rw-r--r--	root	operator	/etc/services
--rw-------	root	operator	/etc/shadow
--rw-r--r--	root	operator	/etc/termcap
--rw-r--r--	root	operator	/etc/ttytab
--rw-r--r--	root	operator	/etc/utmp
-dr-xr-xr-x	root	operator	/mnt
-dr-xr-xr-x	root	operator	/root
-drwxrwxrwx	root	operator	/tmp
-drwxr-xr-x	root	operator	/usr
-drwxr-xr-x	root	operator	/usr/adm
--rw-r--r--	root	operator	/usr/adm/lastlog
--rw-r--r--	root	operator	/usr/adm/wtmp
-drwxr-xr-x	ast	other		/usr/ast
-drwxr-xr-x	bin	operator	/usr/bin
-drwxr-xr-x	root	operator	/usr/etc
-drwxr-xr-x	bin	operator	/usr/include
-drwxr-xr-x	bin	operator	/usr/lib
-drwxrwxr-x	root	operator	/usr/local
-drwxrwxr-x	bin	operator	/usr/local/bin
-drwxrwxr-x	bin	operator	/usr/local/include
-drwxrwxr-x	bin	operator	/usr/local/lib
-drwxrwxr-x	bin	operator	/usr/local/man
-drwxrwxr-x	bin	operator	/usr/local/src
-drwxr-xr-x	bin	operator	/usr/man
-drwxr-xr-x	bin	operator	/usr/mdec
-drwx------	root	operator	/usr/preserve
-drwxr-xr-x	root	operator	/usr/run
-drwxr-xr-x	root	operator	/usr/spool
-drwx--x--x	root	operator	/usr/spool/at
-drwx--x--x	root	operator	/usr/spool/at/past
-drwx------	root	operator	/usr/spool/crontabs
-drwxrwxr-x	root	uucp		/usr/spool/locks
-drwx------	daemon	daemon		/usr/spool/lpd
-drwxr-xr-x	bin	operator	/usr/src
-drwxrwxrwx	root	operator	/usr/tmp
--rwsr-xr-x	root	?		/usr/bin/at
--rwsr-xr-x	root	?		/usr/bin/chfn
--rwsr-xr-x	root	?		/usr/bin/chsh
--rwsr-xr-x	root	?		/usr/bin/df
--rwsr-xr-x	root	?		/usr/bin/elvprsv
--rwsr-xr-x	root	?		/usr/bin/elvrec
--rwsr-xr-x	root	?		/usr/bin/format
--rwsr-xr-x	root	?		/usr/bin/hostaddr
--rwsr-xr-x	root	?		/usr/bin/install
--rwsr-xr-x	daemon	?		/usr/bin/lpd
--rwsr-xr-x	root	?		/usr/bin/mail
--rwsr-xr-x	root	?		/usr/bin/mount
--rwsr-xr-x	root	?		/usr/bin/passwd
--rwsr-xr-x	root	?		/usr/bin/ping
--rwxr-sr-x	?	kmem		/usr/bin/ps
--rwsr-xr--	root	?		/usr/bin/shutdown
--rwsr-xr-x	root	?		/usr/bin/su
--rwxr-sr-x	?	uucp		/usr/bin/term
--rwsr-xr-x	root	?		/usr/bin/umount
--rwxr-sr-x	?	tty		/usr/bin/write
-EOF
-
-} | {
-	# Check if each file has the proper attributes.  Offer a correction
-	# if not.
-	banner="\
-# List of commands to fix the top level hierarchy.  Do not apply these
-# commands blindly, but check and repair by hand.
-"
-
-	while read mode owner group file
-	do
-	    ( # "fix" a memory leak in set...
-
-		set -$- `ls -ld $file 2>/dev/null` '' '' '' ''
-		curmode=$1 curowner=$3 curgroup=$4
-		test $owner = '?' && curowner=$owner
-		test $group = '?' && curgroup=$group
-
-		# File types?
-		if [ x`expr "$mode" : '\\(.\\)'` != \
-					x`expr "$curmode" : '\\(.\\)'` ]
-		then
-			case $curmode in
-			?*)	echo "${banner}rm -r $file"
-				banner=
-			esac
-			curmode= curowner= curgroup=
-			case $mode in
-			d*)	echo "${banner}mkdir $file"
-				;;
-			-*)	echo "${banner}> $file"
-				;;
-			*)	echo "$0: $mode $file: unknown filetype" >&2
-				exit 1
-			esac
-			banner=
-		fi
-
-		# Mode?
-		if [ x$mode != x$curmode ]
-		then
-			octmode=
-			m=$mode
-			for i in u g o
-			do
-				r=0 w=0 x=0
-				case $m in
-				?r??*)		r=4
-				esac
-				case $m in
-				??w?*)		w=2
-				esac
-				case $m in
-				???[xst]*)	x=1
-				esac
-				octmode=$octmode`expr $r + $w + $x`
-				m=`expr $m : '...\\(.*\\)'`
-			done
-			r=0 w=0 x=0
-			case $mode in
-			???[sS=]??????)	r=4
-			esac
-			case $mode in
-			??????[sS=]???)	w=2
-			esac
-			case $mode in
-			?????????[tT=])	x=1
-			esac
-			case $r$w$x in
-			000)	;;
-			*)	octmode=`expr $r + $w + $x`$octmode
-			esac
-
-			echo "${banner}chmod $octmode $file"
-			banner=
-		fi
-
-		# Ownership?
-		if [ x$owner != x$curowner -o x$group != x$curgroup ]
-		then
-			echo "${banner}chown $owner:$group $file"
-			banner=
-		fi
-
-		# The Minix shell forgets processes, so wait explicitly.
-		wait
-
-	    case "$banner" in '') exit 1;; *) exit 0;; esac) || banner=
-	done
-	case "$banner" in
-	'')	exit 1
-	esac
-	exit 0
-}
Index: trunk/minix/commands/scripts/clear.sh
===================================================================
--- trunk/minix/commands/scripts/clear.sh	(revision 9)
+++ 	(revision )
@@ -1,6 +1,0 @@
-#!/bin/sh
-#
-#	clear 1.0 - clear the screen			Author: Kees J. Bot
-#								30 Mar 1996
-export PATH=/bin:/usr/bin
-exec tget -str cl
Index: trunk/minix/commands/scripts/easypack.sh
===================================================================
--- trunk/minix/commands/scripts/easypack.sh	(revision 9)
+++ 	(revision )
@@ -1,118 +1,0 @@
-#!/bin/sh
-
-# This script gets and installs a package from the Website.
-# It is called by getpack package1 ...
-# A package must be in the form of pack.tar.bz2 and must
-# include a build script that makes and installs it.
-# The build script should succeed if installation works, else fail
-
-# Examples:
-#	easypack awk elle telnet	# fetch and install 3 packages
-#	easypack -o awk elle telnet	# fetch and replace existing packs
-
-SOURCE_DIR=/usr/src/commands		# where the source is deposited
-OVERWRITE=0				# can an installed package be overwritten?
-SOFTWARE_DIR="http://www.minix3.org/software"	# Tested and approved S/W
-BETA_DIR="http://www.minix3.org/beta_software"	# Untested software
-
-
-# Check for at least one parameter
-case $# in
-0)	echo Usage: $0 package ...
-	exit ;;
-esac
-
-# Change to source directory
-ORIG_DIR=`pwd`
-rm -f Log			# remove old debugging log
-cd $SOURCE_DIR || exit
-
-if [ "`id -u`" -ne 0 ]
-then
-	# Check for write permission here
-	if test ! -w . 
-	   then echo You do not have write permission for $SOURCE_DIR
-	   exit 1
-	fi
-fi
-
-# Check for -o flag; if found, set OVERWRITE
-if test $1 = "-o"
-   then OVERWRITE=1
-        shift
-fi
-
-# Loop on the packages
-for i
-do # Check to see if it exists. Don't overwrite unless -o given
-   echo " " ; echo Start fetching package $i 
-   echo " " >>$ORIG_DIR/Log
-   echo ------------- Start fetching $i ------------------ >>$ORIG_DIR/Log
-   if test -r $i
-      then # Directory already exists. May it be overwritten?
-	   if test $OVERWRITE = 0
-              then echo $i already exists. Skipping this package
-                   continue
-	      else # Remove the directory
-		   rm -rf $i
-		   echo Existing directory $i removed
-	   fi
-    fi
-
-   # Remove any junk from previous attempts
-   rm -f $i.tar.bz2 $i.tar
-
-   # Get the package
-   URL=$SOFTWARE_DIR/$i.tar.bz2
-   URL1=$URL
-   TARBZ=$i.tar.bz2
-   if urlget $URL >$TARBZ 2>/dev/null
-   then :
-   else # It is not in the directory of tested software. Try beta dir.
-	   URL=$BETA_DIR/$TARBZ
-	   if urlget $URL >$TARBZ 2>/dev/null
-	   then :
-	   else
-	   	   echo Cannot get $i.
-		   echo "   " Tried $URL1
-		   echo "   " Tried $URL
-		   echo "   " Skipping this package
-		   rm -f $TARBZ
-		   continue
-	   fi
-   fi
-
-   # We got it. Unpack it.
-   echo Package $i fetched
-   bunzip2 $TARBZ || smallbunzip2 $TARBZ
-   tar xf $i.tar
-   if test ! -d $i
-      then echo Unable to unpack $i
-	   continue
-      else echo Package $i unpacked
-   fi
-
-   # It is now unpacked. Build it
-   cd $i
-   binsizes big
-   if [ -f build.minix ]
-   then	sh build.minix >>$ORIG_DIR/Log 2>&1
-	r=$?
-   else	sh build >>$ORIG_DIR/Log 2>&1
-	r=$?
-   fi
-   if [ $r -eq 0 ] 
-      then echo Package $i installed
-      else echo Package $i failed to install, see Log
-   fi
-   if [ -f .postinstall ]
-   then	echo Running postinstall script.
-	sh -e .postinstall
-   fi
-   binsizes normal
-
-   # Clean up
-   cd ..
-   rm -f $i.tar $TARBZ # Remove whatever is still lying around
-done
-
Index: trunk/minix/commands/scripts/floppysetup.sh
===================================================================
--- trunk/minix/commands/scripts/floppysetup.sh	(revision 9)
+++ 	(revision )
@@ -1,408 +1,0 @@
-#!/bin/sh
-#
-#	setup 4.1 - install a Minix distribution	Author: Kees J. Bot
-#								20 Dec 1994
-
-PATH=/bin:/usr/bin
-export PATH
-
-usage()
-{
-    cat >&2 <<'EOF'
-Usage:	setup		# Install a skeleton system on the hard disk.
-	setup /usr	# Install the rest of the system (binaries or sources).
-
-	# To install from other things then floppies:
-
-	urlget http://... | setup /usr		# Read from a web site.
-	urlget ftp://... | setup /usr		# Read from an FTP site.
-	mtools copy c0d0p0:... - | setup /usr	# Read from the C: drive.
-	dosread c0d0p0 ... | setup /usr		# Likewise if no mtools.
-EOF
-    exit 1
-}
-
-# No options.
-while getopts '' opt; do usage; done
-shift `expr $OPTIND - 1`
-
-# Installing a floppy set?
-case $# in
-0)  # No, we're installing a skeleton system on the hard disk.
-    ;;
-1)
-    cd "$1" || exit
-
-    # Annoying message still there?
-    grep "'setup /usr'" /etc/issue >/dev/null 2>&1 && rm -f /etc/issue
-
-    if [ -t 0 ]
-    then
-	size=bad
-	while [ "$size" = bad ]
-	do
-	    echo -n "\
-What is the size of the images on the diskettes? [all] "; read size
-
-	    case $size in
-	    ''|360|720|1200|1440)
-		;;
-	    *)	echo "Sorry, I don't believe \"$size\", try again." >&2
-		size=bad
-	    esac
-	done
-
-	drive=
-	while [ -z "$drive" ]
-	do
-	    echo -n "What floppy drive to use? [0] "; read drive
-
-	    case $drive in
-	    '')	drive=0
-		;;
-	    [01])
-		;;
-	    *)	echo "It must be 0 or 1, not \"$drive\"."
-		drive=
-	    esac
-	done
-
-	vol -r $size /dev/fd$drive | uncompress | tar xvfp -
-    else
-	# Standard input is where we can get our files from.
-	uncompress | tar xvfp -
-    fi
-
-    echo Done.
-    exit
-    ;;
-*)
-    usage
-esac
-
-# Installing Minix on the hard disk.
-# Must be in / or we can't mount or umount.
-if [ ! -f /CD ]
-then
-	case "`pwd`" in
-	/?*)
-	    echo "Please type 'cd /' first, you are locking up `pwd`" >&2	
-	    exit 1
-	esac
-fi
-
-case "$0" in
-/tmp/*)
-    rm -f "$0"
-    ;;
-*)  cp -p "$0" /tmp/setup
-    exec /tmp/setup
-esac
-
-# Find out what we are running from.
-exec 9<&0 </etc/mtab			# Mounted file table.
-read thisroot rest			# Current root (/dev/ram or /dev/fd?)
-read fdusr rest				# USR (/dev/fd? or /dev/fd?p2)
-exec 0<&9 9<&-
-
-# What do we know about ROOT?
-case $thisroot:$fdusr in
-/dev/ram:/dev/fd0p2)	fdroot=/dev/fd0		# Combined ROOT+USR in drive 0
-			;;
-/dev/ram:/dev/fd1p2)	fdroot=/dev/fd1		# Combined ROOT+USR in drive 1
-			;;
-/dev/ram:/dev/fd*)	fdroot=unknown		# ROOT is some other floppy
-			;;
-/dev/fd*:/dev/fd*)	fdroot=$thisroot	# ROOT is mounted directly
-			;;
-*)			fdroot=$thisroot	# ?
-    if [ -f /CD ]
-    then
-    	:
-    else
-	    echo -n "\
-It looks like Minix has been installed on disk already.  Are you sure you
-know what you are doing? [n] "
-	    read yn
-	    case "$yn" in
-	    [yY]*|sure)	;;
-	    *)	exit
-	    esac
-     fi
-esac
-
-echo -n "\
-This is the Minix installation script.
-
-Note 1: If the screen blanks suddenly then hit CTRL+F3 to select \"software
-	scrolling\".
-
-Note 2: If things go wrong then hit DEL and start over.
-
-Note 3: The installation procedure is described in the manual page
-	usage(8).  It will be hard without it.
-
-Note 4: Some questions have default answers, like this: [y]
-	Simply hit RETURN (or ENTER) if you want to choose that answer.
-
-Note 5: If you see a colon (:) then you should hit RETURN to continue.
-:"
-read ret
-
-echo "
-What type of keyboard do you have?  You can choose one of:
-"
-ls -C /usr/lib/keymaps | sed -e 's/\.map//g' -e 's/^/    /'
-echo -n "
-Keyboard type? [us-std] "; read keymap
-test -n "$keymap" && loadkeys "/usr/lib/keymaps/$keymap.map"
-
-echo -n "
-Minix needs one primary partition of at about 210 MB for a full install
-with sources.  (The full install also fits in about 180 MB, but it
-needs more if fully recompiled.  Add more space to taste.)
-
-  * Minix currently only understands filesystems up to 4GB, so don't make
-    it bigger.
-
-If there is no free space on your disk then you have to back up one of the
-other partitions, shrink, and reinstall.  See the appropriate manuals of the
-the operating systems currently installed.  Restart your Minix installation
-after you have made space.
-
-To make this partition you will be put in the editor \"part\".  Follow the
-advice under the '!' key to make a new partition of type MINIX.  Do not
-touch an existing partition unless you know precisely what you are doing!
-Please note the name of the partition (e.g. c0d0p1, c0d1p3, c1d1p0) you
-make.  (See the devices section in usage(8) on Minix device names.)
-:"
-read ret
-
-primary=
-while [ -z "$primary" ]
-do
-    part || exit
-
-    echo -n "
-Please finish the name of the primary partition you have created:
-(Just type RETURN if you want to rerun \"part\")                   /dev/"
-    read primary
-done
-
-root=${primary}s0
-swap=${primary}s1
-usr=${primary}s2
-
-hex2int()
-{
-    # Translate hexadecimal to integer.
-    local h d i
-
-    h=$1
-    i=0
-    while [ -n "$h" ]
-    do
-	d=$(expr $h : '\(.\)')
-	h=$(expr $h : '.\(.*\)')
-	d=$(expr \( 0123456789ABCDEF : ".*$d" \) - 1)
-	i=$(expr $i \* 16 + $d)
-    done
-    echo $i
-}
-
-# Ask user about networking
-echo ""
-echo "Minix currently supports the Intel Pro/100 and RealTek 8139 "
-echo "Ethernet cards. Please choose: "
-echo ""
-echo "0. No Ethernet card (no networking)"
-echo "1. An Intel Pro/100 Ethernet card is installed"
-echo "2. A Realtek 8139 Ethernet card is installed"
-echo "3. A different Ethernet card is installed (no networking)"
-echo ""
-echo "You can always change your mind after the install."
-echo ""
-echo "Choice? "
-read eth
-driver=""
-inetparams=""
-case "$eth" in
-	1)	driver=FXP;	inetparams="servers=inet;" ;;
-	2)	driver=RTL8139;	inetparams="servers=inet;" ;;
-esac
-
-# Compute the amount of memory available to Minix.
-memsize=0
-ifs="$IFS"
-IFS=','
-set -- $(sysenv memory)
-IFS="$ifs"
-
-for mem
-do
-    mem=$(expr $mem : '.*:\(.*\)')
-    memsize=$(expr $memsize + $(hex2int $mem) / 1024)
-done
-
-# Compute an advised swap size.
-swapadv=0
-case `arch` in
-i86)
-    test $memsize -lt 4096 && swapadv=$(expr 4096 - $memsize)
-    ;;
-*)  test $memsize -lt 6144 && swapadv=$(expr 6144 - $memsize)
-esac
-
-echo -n "
-How much swap space would you like?  Swapspace is only needed if this
-system is memory starved, like a 16-bit system with less then 2M, or a
-32-bit system with less then 4M.  Minix swapping isn't very good yet, so
-there is no need for it otherwise.
-		    Size in kilobytes? [$swapadv] "
-swapsize=
-read swapsize
-test -z "$swapsize" && swapsize=$swapadv
-
-echo -n "
-You have created a partition named:	/dev/$primary
-The following subpartitions are about to be created on /dev/$primary:
-
-    Root subpartition:	/dev/$root	16 MB
-    Swap subpartition:	/dev/$swap	$swapsize kb
-    /usr subpartition:	/dev/$usr	rest of $primary
-
-Hit return if everything looks fine, or hit DEL to bail out if you want to
-think it over.  The next step will destroy /dev/$primary.
-:"
-read ret
-					# Secondary master bootstrap.
-installboot -m /dev/$primary /usr/mdec/masterboot >/dev/null || exit
-
-					# Partition the primary.
-p3=0:0
-test "$swapsize" -gt 0 && p3=81:`expr $swapsize \* 2`
-partition /dev/$primary 1 81:32768* $p3 81:0+ || exit
-
-if [ "$swapsize" -gt 0 ]
-then
-    # We must have that swap, now!
-    mkswap -f /dev/$swap || exit
-    mount -s /dev/$swap || exit
-else
-    # Forget about swap.
-    swap=
-fi
-
-echo "
-Migrating to disk...
-"
-
-mkfs /dev/$usr
-echo "\
-Scanning /dev/$usr for bad blocks.  (Hit DEL to stop the scan if you are
-absolutely sure that there can not be any bad blocks.  Otherwise just wait.)"
-trap ': nothing' 2
-readall -b /dev/$usr | sh
-sleep 2
-trap 2
-
-mount /dev/$usr /mnt || exit		# Mount the intended /usr.
-
-cpdir -v /usr /mnt || exit		# Copy the usr floppy.
-
-umount /dev/$usr || exit		# Unmount the intended /usr.
-
-umount $fdusr				# Unmount the /usr floppy.
-
-mount /dev/$usr /usr || exit		# A new /usr
-
-if [ $fdroot = unknown ]
-then
-    echo "
-By now the floppy USR has been copied to /dev/$usr, and it is now in use as
-/usr.  Please insert the installation ROOT floppy in a floppy drive."
-
-    drive=
-    while [ -z "$drive" ]
-    do
-	echo -n "What floppy drive is it in? [0] "; read drive
-
-	case $drive in
-	'')	drive=0
-	    ;;
-	[01])
-	    ;;
-	*)	echo "It must be 0 or 1, not \"$drive\"."
-	    drive=
-	esac
-    done
-    fdroot=/dev/fd$drive
-fi
-
-echo "
-Copying $fdroot to /dev/$root
-"
-
-mkfs /dev/$root || exit
-mount /dev/$root /mnt || exit
-if [ -d /boot ]
-then
-    # Running from the floppy itself (or installation CD).
-    cpdir -vx / /mnt || exit
-    chmod 555 /mnt/usr
-else
-    # Running from the RAM disk, root image is on a floppy.
-    mount $fdroot /root || exit
-    cpdir -v /root /mnt || exit
-    umount $fdroot || exit
-    cpdir -f /dev /mnt/dev		# Copy any extra MAKEDEV'd devices
-fi
-
-# CD remnants that aren't for the installed system
-rm /mnt/etc/issue /mnt/CD 2>/dev/null
-					# Change /etc/fstab.
-echo >/mnt/etc/fstab "\
-# Poor man's File System Table.
-
-root=/dev/$root
-${swap:+swap=/dev/$swap}
-usr=/dev/$usr"
-
-					# National keyboard map.
-test -n "$keymap" && cp -p "/usr/lib/keymaps/$keymap.map" /mnt/etc/keymap
-
-# Set inet.conf to correct driver
-if [ -n "$driver" ]
-then	echo "eth0 $driver 0 { default; };" >/mnt/etc/inet.conf
-fi
-
-umount /dev/$root || exit		# Unmount the new root.
-
-# Compute size of the second level file block cache.
-case `arch` in
-i86)
-    cache=`expr "0$memsize" - 1024`
-    test $cache -lt 32 && cache=0
-    test $cache -gt 512 && cache=512
-    ;;
-*)
-    cache=`expr "0$memsize" - 2560`
-    test $cache -lt 64 && cache=0
-    test $cache -gt 1024 && cache=1024
-esac
-echo "Second level file system block cache set to $cache kb."
-if [ $cache -eq 0 ]; then cache=; else cache="ramsize=$cache"; fi
-
-					# Make bootable.
-installboot -d /dev/$root /usr/mdec/bootblock /boot/boot >/dev/null || exit
-edparams /dev/$root "rootdev=$root; ramimagedev=$root; $cache; $inetparams; save" || exit
-pfile="/usr/src/tools/fdbootparams"
-echo "Remembering boot parameters in ${pfile}."
-echo "rootdev=$root; ramimagedev=$root; $cache; save" >$pfile || exit
-sync
-
-echo "
-Please type 'halt' to exit Minix.
-You can type 'boot $primary' to try the newly installed Minix system.  See
-\"TESTING\" in the usage manual."
-
Index: trunk/minix/commands/scripts/getpack.sh
===================================================================
--- trunk/minix/commands/scripts/getpack.sh	(revision 9)
+++ 	(revision )
@@ -1,30 +1,0 @@
-#!/bin/sh
-
-if [ $# -ne 1 ]
-then	echo "Usage: $0 <url>"
-	exit 1
-fi
-
-if [ -z "$HOME" ]
-then	echo "Where is your \$HOME? "
-	exit 1
-fi
-
-if [ ! -d "$HOME" ]
-then	echo "Where is your \$HOME ($HOME) ? "
-	exit 1
-fi
-
-tmpdir=$HOME/getpack$$
-tmpfile=package
-tmpfiletar=$tmpfile.tar
-tmpfiletargz=$tmpfile.tar.gz
-
-mkdir -m 700 $tmpdir || exit 1
-cd $tmpdir || exit 1
-
-urlget "$1" >$tmpfiletargz
-
-gzip -d $tmpfiletargz || exit 1
-tar xf $tmpfiletar || exit 1
-make && make install && echo "Ok."
Index: trunk/minix/commands/scripts/makewhatis.sh
===================================================================
--- trunk/minix/commands/scripts/makewhatis.sh	(revision 9)
+++ 	(revision )
@@ -1,85 +1,0 @@
-#!/bin/sh
-#
-# makewhatis 2.0 - make whatis(5) database.	Author: Kees J. Bot.
-#
-# Make the whatis database of a man directory from the manual pages.
-
-case $1 in
--*)	set -$- x x
-esac
-
-case $# in
-1)	;;
-*)	echo "Usage: $0 <mandir>" >&2
-	exit 1
-esac
-
-cd $1 || exit
-
-{
-	# First pass, gathering the .SH NAME lines in various forms.
-
-	# First the man[1-8] directories, the titles are under the .SH NAME
-	# section header.
-	for chap in 1 2 3 4 5 6 7 8
-	do
-		for page in man$chap/*.$chap
-		do
-		   if	test -f "$page"; then	# (Old sh barfs on 'continue')
-
-			sed -e 's/	/ /g
-				s/"NAME"/NAME/g
-				/^\.SH NAME/,/^\.SH /!d
-				/^\.SH /d
-				s/\\f.//g	# should not be needed
-				s/\\s[+-].//g
-				s/\\s.//g
-				s/\\//
-				'"s/ - / ($chap) - /" < "$page"
-		   fi
-		done
-	done
-
-	# The Minix "Book style" documents, look for .CD
-	for page in man9/*.9
-	do
-	   if	test -f "$page"; then
-
-		sed -e 's/	/ /g
-			/^\.CD /!d
-			s/^[^"]*"//
-			s/"[^"]*$//
-			s/\\(en/-/g
-			s/\\f.//g
-			s/\\s[+-].//g
-			s/\\s.//g
-			s/\\\*(M2/MINIX/g
-			s/\\//
-			'"s/ - / (9) - /" < "$page"
-	   fi
-	done
-
-	# Some people throw extra flat text files into the cat[1-9]
-	# directories.  It would be nice if man(1) can find them.
-	trap 'rm -f /tmp/mkw[cmn]$$; exit 1' 1 2 15
-	for chap in 1 2 3 4 5 6 7 8 9
-	do
-		ls cat$chap 2>/dev/null >/tmp/mkwc$$
-		ls man$chap 2>/dev/null >/tmp/mkwm$$
-		comm -23 /tmp/mkwc$$ /tmp/mkwm$$ >/tmp/mkwn$$
-		sed -e "/.*\\.$chap\$/!d
-			s/\\.$chap\$/ ($chap) - ???/" < /tmp/mkwn$$
-	done
-	rm -f /tmp/mkw[cmn]$$
-} | {
-	# Second pass, remove empty lines, leading and trailing spaces,
-	# multiple spaces to one space, remove lines without a dash.
-	sed -e 's/  */ /g
-		s/^ //
-		s/ $//
-		/^$/d
-		/-/!d'
-} | {
-	# Third pass, sort by section.
-	sort -t'(' +1 -o whatis
-}
Index: trunk/minix/commands/scripts/mkdep.sh
===================================================================
--- trunk/minix/commands/scripts/mkdep.sh	(revision 9)
+++ 	(revision )
@@ -1,55 +1,0 @@
-#!/bin/sh
-#
-#	mkdep 1.1 - Generate Makefile dependencies.	Author: Kees J. Bot
-#
-# Does what 'cc -M' should do, but no compiler gets it right, they all
-# strip the leading path of the '.o' file.)
-#
-# Added option to generate .depend files in subdirectories of given dir.
-# 							Jorrit N. Herder
-
-case $# in
-
-# Display help ...
-0)	
-	echo "Usage: mkdep 'cpp command' file ..." >&2
-	echo "       mkdep directory" >&2
-;;
-
-# Create .depend files ...
-1)
-	echo "Creating .depend files in $1"
-	for dir in `find $1 -type d ! -name CVS`
-	do
-		touch $dir/.depend
-	done
-
-;;
-
-
-# Get dependencies ... 
-*)
-	cpp="$1"; shift
-
-	for f
-	do
-		: < "$f" || exit
-
-		o=`expr "$f" : '\(.*\)\..*'`.o
-
-		echo
-
-		$cpp "$f" | \
-			sed -e '/^#/!d
-				s/.*"\(.*\)".*/\1/
-				s:^\./::' \
-			    -e "s:^:$o\:	:" | \
-			sort -u
-	done
-esac
-
-exit 0
-
-#
-# $PchId: mkdep.sh,v 1.3 1998/07/23 21:24:38 philip Exp $
-#
Index: trunk/minix/commands/scripts/mkdist.sh
===================================================================
--- trunk/minix/commands/scripts/mkdist.sh	(revision 9)
+++ 	(revision )
@@ -1,301 +1,0 @@
-#!/bin/sh
-#
-#	mkdist 3.6 - Make a Minix distribution		Author: Kees J. Bot
-#								20 Dec 1994
-
-system=`uname`
-
-usage()
-{
-    case $system in
-    Minix)	echo "Usage: $0" >&2
-	;;
-    Minix-vmd)	echo "Usage: $0 base-path root-device usr-device" >&2
-    esac
-    exit 1
-}
-
-# No options.
-while getopts '' opt; do usage; done
-shift `expr $OPTIND - 1`
-
-case $system:$# in
-Minix:0)
-    # Interactive.
-    case "$0" in
-    /tmp/*)
-	rm -f "$0"
-	;;
-    *)  # Move out of /usr.
-	cp -p "$0" /tmp/mkdist
-	exec /tmp/mkdist
-    esac
-    std=t
-    base=/
-    export PATH=/bin:/usr/bin
-    ;;
-Minix-vmd:3)
-    # Called by an external script from Minix-vmd to help make a distribution.
-    std=
-    base="$1" rootdev="$2" usrdev="$3"
-esac
-
-usrlist="
-bin
-bin/MAKEDEV
-bin/arch
-bin/badblocks
-bin/chmod
-bin/clone
-bin/compress
-bin/cp
-bin/cpdir
-bin/df
-`test -f $base/usr/bin/mtools || echo bin/dosdir bin/dosread bin/doswrite`
-`test -f $base/usr/bin/mtools && echo bin/mtools`
-bin/edparams
-bin/getty
-bin/grep
-bin/installboot
-bin/isodir
-bin/isoinfo
-bin/isoread
-bin/kill
-bin/ln
-bin/login
-bin/ls
-bin/mined
-bin/mkdir
-bin/mkfs
-bin/mknod
-bin/mkswap
-bin/mv
-bin/od
-bin/part
-bin/partition
-bin/readall
-bin/repartition
-bin/rm
-bin/rmdir
-bin/sed
-bin/setup
-bin/shutdown
-bin/sleep
-bin/sort
-bin/stty
-bin/sysenv
-bin/tar
-bin/uname
-bin/uncompress
-bin/update
-bin/vol
-bin/zcat
-etc
-etc/rc
-lib
-lib/keymaps
-`cd $base/usr && echo lib/keymaps/*`
-lib/pwdauth
-mdec
-mdec/boot
-mdec/bootblock
-mdec/jumpboot
-mdec/masterboot
-tmp
-"
-
-if [ "$std" ]
-then
-    # Find the root device, and the real root device.
-    . /etc/fstab
-    realroot=`printroot -r`
-    if [ $realroot = $root ]
-    then
-	rootdir=/
-    else
-	umount $root >/dev/null 2>&1
-	mount $root /root || exit
-	rootdir=/root
-    fi
-
-    echo -n "
-The installation root and /usr can be put on either one diskette of at least
-1.2 Mb, or on two diskettes of at least 720 kb.
-
-Do you want to use a single diskette of at least 1.2 Mb? [y] "; read single
-
-    case $single in
-    ''|[yY]*|sure)
-	single=t
-	;;
-    *)  single=
-    esac
-
-    echo -n "Which drive to use? [0] "; read drive
-
-    case $drive in
-    '') drive=0
-	;;
-    [01])	;;
-    *)  echo "Please type '0' or '1'" >&2; exit 1
-    esac
-
-    if [ "$single" ]
-    then
-	echo -n "Insert the root+usr diskette in drive $drive and hit RETURN"
-    else
-	echo -n "Insert the root diskette in drive $drive and hit RETURN"
-    fi
-    read ret
-
-    rootdev=/dev/fd$drive
-    v1=-1
-else
-    rootdir=$base
-    v1='-t 1'
-fi
-
-umount $rootdev 2>/dev/null
-if [ "$std" ]
-then
-    umount ${rootdev}p1 2>/dev/null
-    umount ${rootdev}p2 2>/dev/null
-else
-    umount $rootdir/minix 2>/dev/null
-    umount $rootdir/etc 2>/dev/null
-fi
-mkfs $v1 -i 272 $rootdev 480 || exit
-mount $rootdev /mnt || exit
-if [ "$std" ]
-then
-    partition -mf $rootdev 0 81:960 81:240 81:240 >/dev/null || exit
-    repartition $rootdev >/dev/null || exit
-    mkfs $v1 ${rootdev}p1 || exit
-    mkfs $v1 ${rootdev}p2 || exit
-    mount ${rootdev}p1 $rootdir/minix || exit	# Hide /minix and /etc
-    mount ${rootdev}p2 $rootdir/etc 2>/dev/null # (complains about /etc/mtab)
-else
-    install -d /tmp/.minix || exit
-    install -d /tmp/.etc || exit		# Hide /minix and /etc
-    mount -t lo /tmp/.minix $rootdir/minix || exit
-    mount -t lo /tmp/.etc $rootdir/etc || exit
-fi
-cpdir -vx $rootdir /mnt || exit
-install -d -o 0 -g 0 -m 755 /mnt || exit
-install -d -o 0 -g 0 -m 555 /mnt/root || exit
-install -d -o 0 -g 0 -m 555 /mnt/mnt || exit
-install -d -o 0 -g 0 -m 555 /mnt/usr || exit
-if [ "$std" ]
-then
-    umount ${rootdev}p2 2>/dev/null	# Unhide /etc
-    umount ${rootdev}p1 || exit		# Unhide /minix
-else
-    umount $rootdir/etc || exit		# Unhide /etc
-    umount $rootdir/minix || exit	# Unhide /minix
-fi
-install -d -o 2 -g 0 -m 755 /mnt/minix || exit
-install -d -o 2 -g 0 -m 755 /mnt/etc || exit
-set `ls -t $rootdir/minix`	# Install the latest kernel
-install -c $rootdir/minix/$1 /mnt/minix/`echo $1 | sed 's/r[0-9]*$//` || exit
-cpdir -v $base/usr/src/etc /mnt/etc || exit	# Install a fresh /etc
-chown -R 0:0 /mnt/etc				# Patch up owner and mode
-chmod 600 /mnt/etc/shadow
-
-# Change /etc/fstab.
-echo >/mnt/etc/fstab "\
-# Poor man's File System Table.
-
-root=unknown
-usr=unknown"
-
-# How to install?
-echo >/mnt/etc/issue "\
-
-Login as root and run 'setup' to install Minix."
-
-umount $rootdev || exit
-test "$std" && umount $root 2>/dev/null
-installboot -d $rootdev $base/usr/mdec/bootblock boot >/dev/null
-
-# Partition the root floppy whether necessary or not.  (Two images can be
-# concatenated, or a combined image can be split later.)
-partition -mf $rootdev 0 81:960 0:0 81:1440 81:480 >/dev/null || exit
-
-if [ "$std" ]
-then
-    if [ "$single" ]
-    then
-	repartition $rootdev >/dev/null
-	usrdev=${rootdev}p2
-    else
-	echo -n "Insert the usr diskette in drive $drive and hit RETURN"
-	read ret
-	usrdev=$rootdev
-    fi
-fi
-
-mkfs $v1 -i 96 $usrdev 720 || exit
-mount $usrdev /mnt || exit
-install -d -o 0 -g 0 -m 755 /mnt || exit
-(cd $base/usr && exec tar cfD - $usrlist) | (cd /mnt && exec tar xvfp -) || exit
-umount $usrdev || exit
-
-# Put a "boot the other drive" bootblock on the /usr floppy.
-installboot -m $usrdev /usr/mdec/masterboot >/dev/null
-
-# We're done for Minix-vmd here, it has its own ideas on how to package /usr.
-test "$std" || exit 0
-
-# Guess the size of /usr in compressed form.  Assume compression down to 60%
-# of the original size.  Use "disk megabytes" of 1000*1024 for a safe guess.
-set -$- `df | grep "^$usr"`
-size=`expr \\( $4 \\* 6 / 10 + 999 \\) / 1000`
-
-echo -n "
-You now need enough diskettes to hold /usr in compressed form, close to
-$size Mb total.  "
-
-size=
-while [ -z "$size" ]
-do
-    if [ "$single" ]; then defsize=1440; else defsize=720; fi
-
-    echo -n "What is the size of the diskettes? [$defsize] "; read size
-
-    case $size in
-    '')	size=$defsize
-	;;
-    360|720|1200|1440)
-	;;
-    *)	echo "Sorry, I don't believe \"$size\", try again." >&2
-	size=
-    esac
-done
-
-drive=
-while [ -z "$drive" ]
-do
-    echo -n "What floppy drive to use? [0] "; read drive
-
-    case $drive in
-    '')	drive=0
-	;;
-    [01])
-	;;
-    *)	echo "It must be 0 or 1, not \"$drive\"."
-	drive=
-    esac
-done
-
-echo "
-Enter the floppies in drive $drive when asked to.  Mark them with the volume
-numbers!
-"
-sleep 2
-
-if [ `arch` = i86 ]; then bits=13; else bits=16; fi
-
->/tmp/DONE
-cd /usr && tar cvf - . /tmp/DONE \
-    | compress -b$bits | vol -w $size /dev/fd$drive &&
-echo Done.
Index: trunk/minix/commands/scripts/packit.sh
===================================================================
--- trunk/minix/commands/scripts/packit.sh	(revision 9)
+++ 	(revision )
@@ -1,52 +1,0 @@
-#!/bin/sh
-
-PI=.postinstall
-TMP=/usr/tmp
-PATH=/bin:/usr/bin:/usr/local/bin
-
-if [ "$#" -ne 1  ]
-then
-	echo "Usage: $0 <package file>"
-	exit 1
-fi
-
-dir=`pwd`
-if [ "$1" = "-" ]
-then f=""
-else	case "$1" in
-	/*) f="$1" ;;
-	*) f="$dir/$1" ;;
-	esac
-fi
-
-cd $TMP
-rm -f $PI
-
-if [ -f $PI ]
-then	echo "$PI is in $TMP, please remove it first."
-	exit 1
-fi
-
-if [ ! -f $f ]
-then	echo "Couldn't find package $f."
-	exit 1
-fi
-
-# can we execute bunzip2?
-if bunzip2 --help 2>&1 | grep usage >/dev/null
-then	BUNZIP2=bunzip2
-else	BUNZIP2=smallbunzip2
-fi
-
-cat $f | $BUNZIP2 | pax -r -p e
-if [ -f $PI ]
-then
-	sh -e $PI
-	rm -f $PI
-fi
-
-for d in /usr/man /usr/local/man /usr/gnu/man /usr/X11R6/man
-do	if [ -d "$d" ]
-	then makewhatis $d
-	fi
-done
Index: trunk/minix/commands/scripts/packman.sh
===================================================================
--- trunk/minix/commands/scripts/packman.sh	(revision 9)
+++ 	(revision )
@@ -1,241 +1,0 @@
-#!/bin/sh
-
-RC=/usr/etc/rc.package
-CDDIR=PACKAGES
-CDMP=/mnt
-CDPACK=${CDMP}/install/packages
-CDSRC=${CDMP}/install/package-sources
-SRC=/usr/src/commands
-LISTFILE=/etc/packages
-LISTURL=http://www.minix3.org/packages/List
-TMPDIR=/usr/tmp/packages
-mkdir -p $TMPDIR
-URL1=http://www.minix3.org/packages
-URL2=http://www.minix3.org/beta_packages
-SRCURL1=http://www.minix3.org/software
-SRCURL2=http://www.minix3.org/beta_software
-
-# can we execute bunzip2?
-if bunzip2 --help 2>&1 | grep usage >/dev/null
-then    BUNZIP2=bunzip2 
-else    BUNZIP2=smallbunzip2
-fi
-
-if id | fgrep "uid=0(" >/dev/null
-then	:
-else	echo "Please run $0 as root."
-	exit 1
-fi
-
-chmod 700 $TMPDIR
-
-if [ -f "$RC" ]
-then	. "$RC"
-fi
-
-cd /
-
-cdpackages=""
-if [ -n "$cddrive" ]
-then	pack=${cddrive}p2
-	umount $pack >/dev/null 2>&1 || true
-	if mount -r $pack $CDMP
-	then	fn="$CDPACK/List"
-		cdpackages=$fn
-		if [ ! -f $cdpackages ]
-		then	cdpackages=""
-			echo "No package list found on CD in $fn."
-		fi
-	else	echo "CD mount failed."
-	fi
-else	echo "Don't know where the install CD is. You can set it in $RC."
-fi
-
-# For local testing
-#cdpackages=/usr/bigports/Packages/List
-#CDPACK=/usr/bigports/Packages
-#CDSRC=/usr/bigports/Sources
-
-if [ "$cdpackages" = "" ]
-then	echo "Skipping CD packages."
-else	cont=y
-	while [ $cont = y ]
-	do	n="`wc -l $cdpackages | awk '{ print $1 }'`"
-		sourcef=$CDSRC/SizeMB
-		binf=$CDPACK/SizeMB
-		if [ -f $binf -a -f $sourcef ]
-		then	sourcemb="`cat $sourcef`"
-			binmb="`cat $binf`"
-			sourcesize=" (`expr $binmb + $sourcemb` MB uncompressed)"
-		else	sourcesize=""
-		fi
-		if [ -f $binf ]
-		then	binmb="`cat $binf`"
-			binsize=" ($binmb MB uncompressed)"
-		else	binsize=""
-		fi
-
-		echo "There are $n CD packages."
-		echo "Please choose:"
-		echo " 1  Install all $n binary packages$binsize from CD"
-		echo " 2  Install all $n binary packages + sources from CD$sourcesize"
-		echo " 3  Display the list of packages on CD"
-		echo " 4  Let me select individual packages to install from CD or network."
-		echo " 5  Exit."
-		echo -n "Choice: [4] "
-		read in
-		case "$in" in
-		1|2)
-			cd $CDPACK || exit
-			echo " * Installing binaries .."
-			for f in *.tar.bz2
-			do	echo "Installing $f binaries .."
-				packit $f && echo Installed $f
-			done
-			if [ "$in" = 2 ]
-			then
-				cd $SRC || exit
-				echo " * Installing sources in $SRC .."
-				for f in $CDSRC/*.tar.bz2
-				do	echo "$f .."
-					$BUNZIP2 -dc $f | tar xf - 
-				done
-			fi
-			;;
-		3)
-			( echo "Displaying list; press q to leave it, space for more."
-			  cat "$CDPACK/List" | awk -F'|' '{ printf "%-20s %s\n", $1, $2 }'
-			) | more
-			;;
-		""|4)
-			echo "Ok, showing packages to install." ; echo
-			cont=n
-			;;
-		5)
-			exit 0
-			;;
-		esac
-	done
-	echo -n "Press RETURN to continue .. "
-	read xyzzy
-fi
-
-TMPF=$TMPDIR/.list.$$
-rm -f $TMPF
-rm -f $TMPDIR/.*	# Remove any remaining .postinstall script or .list*
-
-netpackages=""
-if ( : </dev/tcp ) 2>/dev/null
-then	if [ -f $LISTFILE ]
-	then	echo -n "Update package list from network? (y/N) "
-		read y
-	else	echo "No package list found - retrieving initial version."
-		y=y
-	fi
-	if [ "$y" = y -o "$y" = Y ]
-	then	echo "Fetching package list."
-		urlget $LISTURL >$TMPF && mv $TMPF $LISTFILE || echo "Update not successful."
-	fi
-	netpackages=$LISTFILE
-	if [ ! -f "$netpackages" -o ! `cat "$netpackages" 2>/dev/null | wc -l | awk '{ print $1 }'` -gt 1 ]
-	then	netpackages=""
-	fi
-else	echo "No working network detected."
-fi
-
-if [ "$netpackages" = "" ]
-then	echo "Skipping network packages."
-	if [ "$cdpackages" = "" ]
-	then	echo "No packages found."
-		exit 1
-	fi
-fi
-
-cont=y
-while [ "$cont" = y ]
-do	cd $TMPDIR
-	echo ""
-	echo "Showing you a list of packages using more. Press q when"
-	echo "you want to leave the list."
-	echo -n "Press RETURN to continue.."
-	read xyzzy
-	echo "Package list:"
-	(	echo "No.|Source|Package|Description"
-		(
-		if [ -f "$netpackages" ]
-		then	sed <$netpackages 's/^/net\|/'
-		fi
-		if [ -f "$cdpackages" ]
-		then	sed <$cdpackages 's/^/cdrom\|/'
-		fi
-		) | sort -t'|' +1 | awk '{ n++; printf "%d|%s\n", n, $0 }' 
-	) >$TMPF
-	awk -F'|' <$TMPF '{ printf "%3s %-6s %-15s %s\n", $1, $2, $3, $4 }' | more
-	echo -n "Package to install? [RETURN for none] "
-	read packno
-	ok=y
-	pat="^$packno|"
-	if [ "`grep $pat $TMPF | wc -l | awk '{ print $1 }'`" -ne 1 ]
-	then	if [ "$packno" ]
-		then	echo "Wrong package number."
-		fi
-		ok=n
-	fi
-	if [ $ok = y ]
-	then	source="`grep $pat $TMPF | awk -F'|' '{ print $2 }'`"
-		packagename="`grep $pat $TMPF | awk -F'|' '{ print $3 }'`"
-		file=$packagename.tar.bz2
-		case $source in
-		net*)	echo -n "Get source of $packagename? (y/N) "
-			read src
-			echo "Retrieving binary from primary location into $TMPDIR .."
-			srcurl=""
-			if urlget $URL1/$file >$file
-			then	echo "Retrieved ok. Installing .."
-				packit $file && echo Installed ok.
-				srcurl=$SRCURL1/$file
-			else	echo "Retrying from Beta binary location.."
-				if urlget $URL2/$file >$file
-				then	echo "Retrieved ok. Installing .."
-					packit $file  && echo Installed ok.
-					srcurl=$SRCURL2/$file
-				else echo "Retrieval failed."
-				fi
-			fi
-			if [ "$src" = y -o "$src" = Y ]
-			then	(	cd $SRC || exit
-					srcfile=${packagename}-src.tar.bz2
-					echo "Retrieving source from $srcurl .."
-					urlget $srcurl >$srcfile || exit
-					echo "Source retrieved in $SRC/$srcfile."
-					$BUNZIP2 -dc $srcfile | tar xf - >/dev/null || exit
-					echo "Source unpacked in $SRC."
-				)
-			fi
-			;;
-		cdrom*)
-			if [ -f $CDPACK/$file ]
-			then	echo "Installing from $CDPACK/$file .."
-				packit $CDPACK/$file
-			else	echo "$CDPACK/$file not found."
-			fi
-			srcfile=$CDSRC/${packagename}-src.tar.bz2
-			if [ -f $srcfile ]
-			then
-				echo -n "Get source of $packagename? (y/N) "
-				read src
-				if [ "$src" = y -o "$src" = Y ]
-				then	(	cd $SRC || exit
-						$BUNZIP2 -dc $srcfile | tar xf - || exit
-						echo "Source $srcfile unpacked in $SRC."
-					)
-				fi
-			else	echo "No source on CD for $packagename."
-			fi
-			;;
-		esac
-	else	cont=n
-	fi
-done
-
-rm -f $TMPDIR/.*	# Remove any remaining .postinstall script or .list*
Index: trunk/minix/commands/scripts/postinstall.sh
===================================================================
--- trunk/minix/commands/scripts/postinstall.sh	(revision 9)
+++ 	(revision )
@@ -1,11 +1,0 @@
-#!/bin/sh
-echo -n "Would you like to install binary packages from the CD? (y/N) "
-read y
-if [ "$y" = y -o "$y" = Y ]
-then	echo "Ok, showing you a list of packages, please type y"
-	echo "for every package you want installed."
-	/usr/bin/packme
-else	echo "Ok, not installing binary packages."
-fi
-echo "Use the 'packme' command after rebooting MINIX to get another chance"
-echo "to install binary packages."
Index: trunk/minix/commands/scripts/rotate.sh
===================================================================
--- trunk/minix/commands/scripts/rotate.sh	(revision 9)
+++ 	(revision )
@@ -1,31 +1,0 @@
-#!/bin/sh
-BZIP=/usr/local/bin/bzip2
-RM="rm -f"
-MV="mv -f"
-
-if [ $# -ne 2 ]
-then	echo "Usage: $0 <log> <keep>"
-	exit 1
-fi
-
-if [ ! -f "$1" ]
-then	 exit 1
-fi
-
-if [ ! -x "$BZIP" ]
-then	exit 1
-fi
-
-if [ "$2" -le 0 ]
-then	echo "Keep at least 1 copy please."
-	exit 1
-fi
-
-k="$2"
-$RM "$1.$k" 2>/dev/null || exit 1
-while [ "$k" -ge 2 ]
-do	prev="`expr $k - 1`"
-	$MV $1.$prev.bz2 $1.$k.bz2 2>/dev/null 
-	k=$prev
-done
-$BZIP -c $1 >$1.1.bz2 && : >$1
Index: trunk/minix/commands/scripts/setup.sh
===================================================================
--- trunk/minix/commands/scripts/setup.sh	(revision 9)
+++ 	(revision )
@@ -1,647 +1,0 @@
-#!/bin/sh
-#
-#	setup 4.1 - install a MINIX distribution	
-#
-# Changes:
-#    Aug     2005   robustness checks and beautifications  (Jorrit N. Herder)
-#    Jul     2005   extended with autopart and networking  (Ben Gras)
-#    Dec 20, 1994   created  (Kees J. Bot)
-#						
-
-LOCALRC=/usr/etc/rc.local
-MYLOCALRC=/mnt/etc/rc.local
-ROOTMB=16
-ROOTSECTS="`expr $ROOTMB '*' 1024 '*' 2`"
-USRKBFILE=/.usrkb
-if [ ! -f "$USRKBFILE" ]
-then	echo "Are you really running from CD?"
-	echo "No $USRKBFILE file."
-	exit 1
-fi
-USRKB="`cat /.usrkb`"
-TOTALMB="`expr 3 + $USRKB / 1024 + $ROOTMB`"
-ROOTFILES="`cat /.rootfiles`"
-USRFILES="`cat /.usrfiles`"
-EXTRASRCFILES="`cat /.extrasrcfiles`"
-EXTRASRCKB="`cat /.extrasrckb`"
-
-# Install size without extra sources (rounded up)
-NOSRCMB="`expr $TOTALMB - $EXTRASRCKB / 1024`"
-NOSRCUSRFILES="`expr $USRFILES - $EXTRASRCFILES`"
-
-if [ "$EXTRASRCKB" -lt 1 ]
-then	 
-	echo "Are you really running from CD?"
-	echo "Something wrong with the extra-source-kb on CD."
-	exit 1
-fi
-
-if [ "$EXTRASRCFILES" -lt 1 ]
-then	 
-	echo "Are you really running from CD?"
-	echo "Something wrong with the extra-source-files estimate on CD."
-	exit 1
-fi
-
-if [ "$TOTALMB" -lt 1 ]
-then	 
-	echo "Are you really running from CD?"
-	echo "Something wrong with size estimate on CD."
-	exit 1
-fi
-
-if [ "$ROOTFILES" -lt 1 ]
-then	 
-	echo "Are you really running from CD?"
-	echo "Something wrong with root files count on CD."
-	exit 1
-fi
-
-if [ "$USRFILES" -lt 1 ]
-then	 
-	echo "Are you really running from CD?"
-	echo "Something wrong with usr files count on CD."
-	exit 1
-fi
-
-PATH=/bin:/usr/bin
-export PATH
-
-
-usage()
-{
-    cat >&2 <<'EOF'
-Usage:	setup		# Install a skeleton system on the hard disk.
-	setup /usr	# Install the rest of the system (binaries or sources).
-
-	# To install from other things then floppies:
-
-	urlget http://... | setup /usr		# Read from a web site.
-	urlget ftp://... | setup /usr		# Read from an FTP site.
-	mtools copy c0d0p0:... - | setup /usr	# Read from the C: drive.
-	dosread c0d0p0 ... | setup /usr		# Likewise if no mtools.
-EOF
-    exit 1
-}
-
-warn() 
-{
-  echo -e "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ! $1"
-}
-
-# No options.
-while getopts '' opt; do usage; done
-shift `expr $OPTIND - 1`
-
-if [ "$USER" != root ]
-then	echo "Please run setup as root."
-	exit 1
-fi
-
-# Find out what we are running from.
-exec 9<&0 </etc/mtab			# Mounted file table.
-read thisroot rest			# Current root (/dev/ram or /dev/fd?)
-read fdusr rest				# USR (/dev/fd? or /dev/fd?p2)
-exec 0<&9 9<&-
-
-# What do we know about ROOT?
-case $thisroot:$fdusr in
-/dev/ram:/dev/fd0p2)	fdroot=/dev/fd0		# Combined ROOT+USR in drive 0
-			;;
-/dev/ram:/dev/fd1p2)	fdroot=/dev/fd1		# Combined ROOT+USR in drive 1
-			;;
-/dev/ram:/dev/fd*)	fdroot=unknown		# ROOT is some other floppy
-			;;
-/dev/fd*:/dev/fd*)	fdroot=$thisroot	# ROOT is mounted directly
-			;;
-*)			fdroot=$thisroot	# ?
-esac
-
-echo -n "
-Welcome to the MINIX 3 setup script.  This script will guide you in setting up
-MINIX on your machine.  Please consult the manual for detailed instructions.
-
-Note 1: If the screen blanks, hit CTRL+F3 to select \"software scrolling\".
-Note 2: If things go wrong then hit CTRL+C to abort and start over.
-Note 3: Default answers, like [y], can simply be chosen by hitting ENTER.
-Note 4: If you see a colon (:) then you should hit ENTER to continue.
-:"
-read ret
-
-# begin Step 1
-echo ""
-echo " --- Step 1: Select keyboard type --------------------------------------"
-echo ""
-
-    echo "What type of keyboard do you have?  You can choose one of:"
-    echo ""
-    ls -C /usr/lib/keymaps | sed -e 's/\.map//g' -e 's/^/    /'
-    echo ""
-step1=""
-while [ "$step1" != ok ]
-do
-    echo -n "Keyboard type? [us-std] "; read keymap
-    test -n "$keymap" || keymap=us-std
-    if loadkeys "/usr/lib/keymaps/$keymap.map" 2>/dev/null 
-    then step1=ok 
-    else warn "invalid keyboard"
-    fi
-done
-# end Step 1
-
-# begin Step 2
-echo ""
-echo " --- Step 2: Select your Ethernet chip ---------------------------------"
-echo ""
-
-# Ask user about networking
-echo "MINIX 3 currently supports the following Ethernet cards. Please choose: "
-    echo ""
-    echo "0. No Ethernet card (no networking)"
-    echo "1. Intel Pro/100"
-    echo "2. 3Com 501 or 3Com 509 based card"
-    echo "3. Realtek 8139 based card"
-    echo "4. Realtek 8029 based card (also emulated by Qemu)"
-    echo "   Note: If you want to use this in Qemu, set 'qemu_pci=1' in the boot monitor."
-    echo "5. NE2000, 3com 503 or WD based card (also emulated by Bochs)"
-    echo "6. AMD LANCE (also emulated by VMWare)"
-    echo "7. Different Ethernet card (no networking)"
-    echo ""
-    echo "You can always change your mind after the setup."
-    echo ""
-step2=""
-while [ "$step2" != ok ]
-do
-    eth=""
-    echo -n "Ethernet card? [0] "; read eth
-    test -z $eth && eth=0
-    driver=""
-    driverargs=""
-    case "$eth" in
-        0) step2="ok"; ;;    
-	1) step2="ok";	driver=fxp;      ;;
-	2) step2="ok";	driver=dpeth;    driverargs="#dpeth_arg='DPETH0=port:irq:memory'";
-	   echo ""
-           echo "Note: After installing, edit $LOCALRC to the right configuration."
-		;;
-	3) step2="ok";	driver=rtl8139;  ;;
-	4) step2="ok";	driver=dp8390;   driverargs="dp8390_arg='DPETH0=pci'";	;;
-	5) step2="ok";	driver=dp8390;   driverargs="dp8390_arg='DPETH0=240:9'"; 
-	   echo ""
-           echo "Note: After installing, edit $LOCALRC to the right configuration."
-           echo " chose option 4, the defaults for emulation by Bochs have been set."
-		;;
-        6) driver="lance"; driverargs="lance_arg='LANCE0=on'"; step2="ok"; ;;    
-        7) step2="ok"; ;;    
-        *) warn "choose a number"
-    esac
-done
-# end Step 2
-
-# begin Step 3
-step3=""
-while [ "$step3" != ok ]
-do
-	echo ""
-	echo " --- Step 3: Select minimal or full distribution -----------------------"
-	echo ""
-	echo "You can install MINIX as (M)inimal or (F)ull. (M)inimal"
-	echo "includes only the binary system and basic system sources."
-	echo "(F)ull also includes commands sources."
-	echo ""
-	echo "Please select:"
-	echo "  (M)inimal install (only basic sources) ($NOSRCMB MB required)"
-	echo "  (F)ull install (full install) ($TOTALMB MB required)"
-	echo " "
-	echo -n "Basic (M)inimal or (F)ull install? [F] "
-	read conf
-	case "$conf" in
-	"") 	step3="ok"; nobigsource="" ;;
-	[Ff]*)	step3="ok"; nobigsource="" ;;
-	[Mm]*)	step3="ok"; nobigsource="1"; TOTALMB=$NOSRCMB; USRFILES=$NOSRCUSRFILES ;;
-	esac
-done
-# end Step 3
-
-# begin Step 4
-step4=""
-while [ "$step4" != ok ]
-do
-	echo ""
-	echo " --- Step 4: Create or select a partition for MINIX 3 -------------------"
-	echo ""
-
-    echo "Now you need to create a MINIX 3 partition on your hard disk."
-    echo "It has to have $TOTALMB MB at the very least."
-    echo "You can also select one that's already there."
-    echo " "
-    echo "If you have an existing installation, reinstalling will let you"
-    echo "keep your current partitioning and subpartitioning, and overwrite"
-    echo "everything except your s1 subpartition (/home). If you want to"
-    echo "reinstall, select your existing minix partition."
-    echo " "
-    echo "Unless you are an expert, you are advised to use the automated"
-    echo "step-by-step help in setting up."
-    echo ""
-    ok=""
-    while [ "$ok" = "" ]
-    do
-	    echo -n "Press ENTER for automatic mode, or type 'expert': "
-	    read mode
-	    if [ -z "$mode" ]; then auto="1"; ok="yes"; fi 
-	    if [ "$mode" = expert ]; then auto=""; ok="yes"; fi
-	    if [ "$ok" != yes ]; then warn "try again"; fi 
-    done
-
-	primary=
-
-	if [ -z "$auto" ]
-	then
-		# Expert mode
-		echo -n "
-MINIX needs one primary partition of $TOTALMB MB for a full install,
-plus what you want for /home.
-The maximum file system currently supported is 4 GB.
-
-If there is no free space on your disk then you have to choose an option:
-   (1) Delete one or more partitions
-   (2) Allocate an existing partition to MINIX 3
-   (3) Exit setup and shrink a partition using a different OS
-
-To make this partition you will be put in the editor \"part\".  Follow the
-advice under the '!' key to make a new partition of type MINIX.  Do not
-touch an existing partition unless you know precisely what you are doing!
-Please note the name of the partition (e.g. c0d0p1, c0d1p3, c1d1p0) you
-make.  (See the devices section in usage(8) on MINIX device names.)
-:"
-		read ret
-
-		while [ -z "$primary" ]
-		do
-		    part || exit
-
-		    echo -n "
-Please finish the name of the primary partition you have created:
-(Just type ENTER if you want to rerun \"part\")                   /dev/"
-		    read primary
-		done
-		echo ""
-		echo "This is the point of no return.  You have selected to install MINIX"
-		echo "on partition /dev/$primary.  Please confirm that you want to use this"
-		echo "selection to install MINIX."
-		echo ""
-		confirmation=""
-		while [ -z "$confirmation" -o "$confirmation" != yes -a "$confirmation" != no ]
-		do
-			echo -n "Are you sure you want to continue? Please enter 'yes' or 'no': "
-			read confirmation
-			if [ "$confirmation" = yes ]; then step4=ok; fi
-		done
-		biosdrivename="Actual BIOS device name unknown, due to expert mode."
-	else
-		if [ "$auto" = "1" ]
-		then
-			# Automatic mode
-			PF="/tmp/pf"
-			if autopart -m$TOTALMB -f$PF
-			then	if [ -s "$PF" ]
-				then
-					set `cat $PF`
-					bd="$1"
-					bdn="$2"
-					biosdrivename="Probably, the right command is \"boot $bdn\"."
-					if [ -b "/dev/$bd" ]
-					then	primary="$bd"
-					else	echo "Funny device $bd from autopart."
-					fi
-				else
-					echo "Didn't find output from autopart."
-				fi 
-			else	echo "Autopart tool failed. Trying again."
-			fi
-
-			# Reset at retries and timeouts in case autopart left
-			# them messy.
-			atnormalize
-
-			if [ -n "$primary" ]; then step4=ok; fi
-		fi
-	fi
-
-	if [ ! -b "/dev/$primary" ]
-	then	echo "/dev/$primary is not a block device."
-		step4=""
-	else
-		devsize="`devsize /dev/$primary`"
-
-		if [ "$devsize" -lt 1 ]
-		then	echo "/dev/$primary is a 0-sized device."
-			step4=""
-		fi
-	fi
-done	# while step4 != ok
-# end Step 4
-
-root=${primary}s0
-home=${primary}s1
-usr=${primary}s2
-umount /dev/$root 2>/dev/null && echo "Unmounted $root for you."
-umount /dev/$home 2>/dev/null && echo "Unmounted $home for you."
-umount /dev/$usr 2>/dev/null && echo "Unmounted $usr for you."
-
-devsizemb="`expr $devsize / 1024 / 2`"
-maxhome="`expr $devsizemb - $TOTALMB - 1`"
-
-if [ "$devsizemb" -lt "$TOTALMB" ]
-then	echo "The selected partition ($devsizemb MB) is too small."
-	echo "You'll need $TOTALMB MB at least."
-	exit 1
-fi
-
-if [ "$maxhome" -lt 1 ]
-then	echo "Note: you can't have /home with that size partition."
-	maxhome=0
-fi
-
-TMPMP=/m
-mkdir $TMPMP >/dev/null 2>&1
-
-confirm=""
-
-while [ "$confirm" = "" ]
-do
-	auto=""
-	echo ""
-echo " --- Step 5: Reinstall choice ------------------------------------------"
-	if mount -r /dev/$home $TMPMP >/dev/null 2>&1
-	then	umount /dev/$home >/dev/null 2>&1
-		echo ""
-		echo "You have selected an existing MINIX 3 partition."
-		echo "Type F for full installation (to overwrite entire partition)"
-		echo "Type R for a reinstallation (existing /home will not be affected)"
-		echo ""
-		echo -n "(F)ull or (R)einstall? [R] "
-		read conf
-		case "$conf" in
-		"") 	confirm="ok"; auto="r"; ;;
-		[Rr]*)	confirm="ok"; auto="r"; ;;
-		[Ff]*)	confirm="ok"; auto="" ;;
-		esac
-
-	else	echo ""
-		echo "No old /home found. Doing full install."
-		echo ""
-		confirm="ok";
-	fi
-
-done
-
-rmdir $TMPMP
-
-nohome="0"
-
-homesize=""
-if [ ! "$auto" = r ]
-then	
-echo ""
-echo " --- Step 6: Select the size of /home ----------------------------------"
-	while [ -z "$homesize" ]
-	do
-
-		# 20% of what is left over after / and /usr
-		# are taken.
-		defmb="`expr $maxhome / 5`"
-		if [ "$defmb" -gt "$maxhome" ]
-		then
-			defmb=$maxhome
-		fi
-
-		echo ""
-		echo "MINIX will take up $TOTALMB MB, without /home."
-		echo -n "How big do you want your /home to be in MB (0-$maxhome) ? [$defmb] "
-		read homesize
-		if [ "$homesize" = "" ] ; then homesize=$defmb; fi
-		if [ "$homesize" -lt 1 ]
-		then	nohome=1
-			echo "Ok, not making a /home."
-			homesize=0
-		else
-			if [ "$homesize" -gt "$maxhome" ]
-			then	echo "That won't fit!"
-				homesize=""
-			else
-				echo ""
-				echo -n "$homesize MB Ok? [Y] "
-				read ok
-				[ "$ok" = Y -o "$ok" = y -o "$ok" = "" ] || homesize=""
-			fi
-		fi
-		echo ""
-	done
-	# Homesize in sectors
-	homemb="$homesize MB"
-	homesize="`expr $homesize '*' 1024 '*' 2`"
-else
-	homepart="`devsize /dev/$home`"
-	homesize="`expr $homepart / 2 / 1024`"
-	if [ "$homesize" -gt "$maxhome" ]
-	then
-		echo "Sorry, but your /home is too big ($homesize MB) to leave enough"
-		echo "space on the rest of the partition ($devsizemb MB) for your"
-		echo "selected installation size ($TOTALMB MB)."
-		exit 1
-	fi
-	# Homesize unchanged (reinstall)
-	homesize=exist
-	homemb="current size"
-fi
-
-blockdefault=4
-
-if [ ! "$auto" = "r" ]
-then
-	echo ""
-echo " --- Step 7: Select a block size ---------------------------------------"
-	echo ""
-	
-	echo "The maximum (and default) file system block size is $blockdefault KB."
-	echo "For a small disk or small RAM you may want 1 or 2 KB blocks."
-	echo ""
-	
-	while [ -z "$blocksize" ]
-	do	
-		echo -n "Block size in kilobytes? [$blockdefault] "; read blocksize
-		test -z "$blocksize" && blocksize=$blockdefault
-		if [ "$blocksize" -ne 1 -a "$blocksize" -ne 2 -a "$blocksize" -ne $blockdefault ]
-		then	
-			warn "1, 2 or 4 please"
-			blocksize=""
-		fi
-	done
-else
-	blocksize=$blockdefault
-fi
-
-blocksizebytes="`expr $blocksize '*' 1024`"
-
-echo "
-You have selected to (re)install MINIX 3 in the partition /dev/$primary.
-The following subpartitions are now being created on /dev/$primary:
-
-    Root subpartition:	/dev/$root	$ROOTMB MB
-    /home subpartition:	/dev/$home	$homemb
-    /usr subpartition:	/dev/$usr	rest of $primary
-"
-					# Secondary master bootstrap.
-installboot -m /dev/$primary /usr/mdec/masterboot >/dev/null || exit
-					# Partition the primary.
-partition /dev/$primary 1 81:${ROOTSECTS}* 81:$homesize 81:0+ > /dev/null || exit
-
-echo "Creating /dev/$root for / .."
-mkfs -B $blocksizebytes /dev/$root || exit
-
-if [ "$nohome" = 0 ]
-then
-	if [ ! "$auto" = r ]
-	then	echo "Creating /dev/$home for /home .."
-		mkfs -B $blocksizebytes /dev/$home || exit
-	fi
-else	echo "Skipping /home"
-fi
-
-echo "Creating /dev/$usr for /usr .."
-mkfs -B $blocksizebytes /dev/$usr || exit
-
-echo ""
-echo " --- Step 8: Wait for bad block detection ------------------------------"
-echo ""
-echo "Scanning disk for bad blocks.  Hit CTRL+C to stop the scan if you are"
-echo "sure that there can not be any bad blocks.  Otherwise just wait."
-
-trap ': nothing;echo' 2
-
-echo ""
-echo "Scanning /dev/$root for bad blocks:"
-readall -b /dev/$root | sh
-
-if [ "$nohome" = 0 ]
-then
-	echo ""
-	echo "Scanning /dev/$home for bad blocks:"
-	readall -b /dev/$home | sh
-	fshome="home=/dev/$home"
-else	fshome=""
-fi
-
-echo ""
-echo "Scanning /dev/$usr for bad blocks:"
-readall -b /dev/$usr | sh
-
-trap 2
-
-echo ""
-echo " --- Step 9: Wait for files to be copied -------------------------------"
-echo ""
-echo "This is the final step of the MINIX 3 setup.  All files will now be"
-echo "copied to your hard disk.  This may take a while."
-echo ""
-
-mount /dev/$usr /mnt >/dev/null || exit		# Mount the intended /usr.
-
-(cd /usr || exit 1
- if [ "$nobigsource" = 1 ]
- then	list="`ls | fgrep -v src. | fgrep -v install`"
- else	list="`ls | fgrep -v install`"
- fi
- for d in $list
- do	
- 	cpdir -v $d /mnt/$d
- done
-) | progressbar "$USRFILES" || exit	# Copy the usr floppy.
-
-if [ -d /mnt/src.commands ]
-then	mv /mnt/src.commands /mnt/src/commands
-fi
-
-if [ -d /mnt/src.contrib ]
-then	mv /mnt/src.contrib /mnt/src/contrib
-fi
-					# Set inet.conf to correct driver
-if [ -n "$driver" ]
-then	echo "$driverargs" >$MYLOCALRC
-fi
-
-umount /dev/$usr >/dev/null || exit		# Unmount the intended /usr.
-mount /dev/$root /mnt >/dev/null || exit
-
-# Running from the installation CD.
-cpdir -vx / /mnt | progressbar "$ROOTFILES" || exit	
-cp /mnt/etc/motd.install /mnt/etc/motd
-
-# Fix /var/log
-rm /mnt/var/log
-ln -s /usr/log /mnt/var/log
-
-if [ -n "$driver" ]
-then	echo "eth0 $driver 0 { default; };" >/mnt/etc/inet.conf
-fi
-
-# CD remnants that aren't for the installed system
-rm /mnt/etc/issue /mnt/CD /mnt/.* 2>/dev/null
-					# Change /etc/fstab. (No swap.)
-					# ${swap:+swap=/dev/$swap}
-echo >/mnt/etc/fstab "\
-# Poor man's File System Table.
-
-root=/dev/$root
-usr=/dev/$usr
-$fshome"
-
-					# National keyboard map.
-test -n "$keymap" && cp -p "/usr/lib/keymaps/$keymap.map" /mnt/etc/keymap
-
-umount /dev/$root >/dev/null || exit	# Unmount the new root.
-mount /dev/$usr /mnt >/dev/null || exit
-
-# Make bootable.
-installboot -d /dev/$root /usr/mdec/bootblock /boot/boot >/dev/null || exit
-
-edparams /dev/$root "rootdev=$root; ramimagedev=$root; minix(1,Start MINIX 3 (requires at least 16 MB RAM)) { image=/boot/image_big; boot; }; smallminix(2,Start Small MINIX 3 (intended for 8 MB RAM systems)) { image=/boot/image_small; boot; }; newminix(3,Start Custom MINIX 3) { unset image; boot }; main() { echo By default, MINIX 3 will automatically load in 3 seconds.; echo Press ESC to enter the monitor for special configuration.; trap 3000 boot; menu; }; save" || exit
-pfile="/mnt/src/tools/fdbootparams"
-echo "rootdev=$root; ramimagedev=$root; save" >$pfile
-# Save name of CD drive
-cddrive="`mount | grep usr | awk '{ print $1 }' | sed 's/p.*//'`" 
-echo "cddrive=$cddrive" >>/mnt/etc/rc.package
-
-bios="`echo $primary | sed -e 's/d./dX/g' -e 's/c.//g'`"
-
-if [ ! "$auto" = "r" ]
-then	if mount /dev/$home /home 2>/dev/null
-	then	for u in bin ast
-		do	if mkdir ~$u
-			then	echo " * Creating home directory for $u in ~$u"
-				cpdir /usr/ast ~$u
-				chown -R $u:operator ~$u
-			else	echo " * Couldn't create ~$u"
-			fi
-		done
-		umount /dev/$home
-	fi
-fi
-
-echo "Saving random data.."
-dd if=/dev/random of=/mnt/adm/random.dat bs=1024 count=1
-
-echo "
-Please type 'shutdown' to exit MINIX 3 and enter the boot monitor. At
-the boot monitor prompt, type 'boot $bios', where X is the bios drive
-number of the drive you installed on, to try your new MINIX system.
-$biosdrivename
-
-This ends the MINIX 3 setup script.  After booting your newly set up system,
-you can run the test suites as indicated in the setup manual.  You also 
-may want to take care of local configuration, such as securing your system
-with a password.  Please consult the usage manual for more information. 
-
-"
-
Index: trunk/minix/commands/scripts/spell.sh
===================================================================
--- trunk/minix/commands/scripts/spell.sh	(revision 9)
+++ 	(revision )
@@ -1,35 +1,0 @@
-#!/bin/sh
-#
-#	spell 1.1 - show unknown words			Author: Kees J. Bot
-#								28 Apr 1995
-
-dict=words
-
-while getopts 'd:' opt
-do
-	case $opt in
-	d)	dict="$OPTARG"
-		;;
-	?)	echo "Usage: spell [-d dict] [file ...]" >&2; exit 1
-	esac
-done
-shift `expr $OPTIND - 1`
-
-case "$dict" in
-*/*)	;;
-*)	dict="/usr/lib/dict/$dict"
-esac
-
-{
-	if [ $# = 0 ]
-	then
-		prep
-	else
-		for file
-		do
-			prep "$file"
-		done
-	fi
-} | {
-	sort -u | comm -23 - "$dict"
-}
Index: trunk/minix/commands/scripts/srccrc.sh
===================================================================
--- trunk/minix/commands/scripts/srccrc.sh	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-#!/bin/sh
-#
-#	srccrc 1.0 - compute CRC checksums of the entire source tree
-#							Author: Kees J. Bot
-cd /usr || exit
-
-{
-	# List the file names of all files in /usr/include and /usr/src.
-	find include src/* -type f
-} | {
-	# Sort the list to make them comparable.
-	sort
-} | {
-	# Remove files like *.o, *.bak, etc.
-	sed -e '/\.o$/d
-		/\.a$/d
-		/\.bak$/d
-		/\/a\.out$/d
-		/\/core$/d
-		/\/bin\/[^/]*$/d'
-} | {
-	# Compute checksums.
-	xargs crc
-}
Index: trunk/minix/commands/scripts/svclog.sh
===================================================================
--- trunk/minix/commands/scripts/svclog.sh	(revision 9)
+++ 	(revision )
@@ -1,6 +1,0 @@
-#!/bin/sh
-#
-svc=`basename $1 ,S`,S
-if test \( ! -r $svc \) -a -d "SVC" ; then svc=SVC/$svc ; fi
-grep '^#\*\*\*SVC' $svc
-
Index: trunk/minix/commands/scripts/version.sh
===================================================================
--- trunk/minix/commands/scripts/version.sh	(revision 9)
+++ 	(revision )
@@ -1,2 +1,0 @@
-#!/bin/sh
-cat /etc/version
Index: trunk/minix/commands/scripts/whatis.sh
===================================================================
--- trunk/minix/commands/scripts/whatis.sh	(revision 9)
+++ 	(revision )
@@ -1,53 +1,0 @@
-#!/bin/sh
-#
-# whatis/apropos 1.3 - search whatis(5) database for commands
-#							Author: Kees J. Bot
-# BUGS
-#	whatis file must be as if created by makewhatis(8).
-#
-# This version includes a fix by Michael Haardt originally posted to 
-# comp.os.minix in July 1999.  Fixes for grep provided by Michael in May
-# 1999 caused whatis to break, this is now fixed.   (ASW 2004-12-12)
-
-all='exit 0'
-
-case "$1" in
--a)	all="found='exit 0'"
-	shift
-esac
-
-case $#:$0 in
-1:*whatis)
-	;;
-1:*apropos)
-	all="found='exit 0'"
-	;;
-*)	echo "Usage: `basename $0` [-a] <keyword>" >&2
-	exit 1
-esac
-
-IFS=":$IFS"
-MANPATH="${MANPATH-/usr/local/man:/usr/man}"
-
-found=
-
-for m in $MANPATH
-do
-	for w in $m/whatis
-	do
-		test -f $w || continue
-
-		case $0 in
-		*whatis)
-			grep '^\('$1'\|[^(]* '$1'\)[ ,][^(]*(' $w && eval $all
-			;;
-		*apropos)
-			grep -i "$1" $w && eval $all
-		esac
-	done
-done
-
-$found
-
-echo "`basename $0`: $1: not found" >&2
-exit 1
Index: trunk/minix/commands/scripts/whereis.sh
===================================================================
--- trunk/minix/commands/scripts/whereis.sh	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-#!/bin/sh
-: List all system directories containing the argument
-: Author: Terrence W. Holm
-if test $# -ne 1; then
-  echo "Usage:  whereis  name"
-  exit 1
-fi
-
-path="/bin /lib /etc\
-      /usr/bin /usr/lib\
-      /usr/include /usr/include/sys"
-
-for dir in $path; do
-  for file in $dir/$1 $dir/$1.*; do
-    if test -f $file; then
-      echo $file 
-    elif test -d $file; then
-      echo $file/
-      fi
-    done
-  done
-
-exit 0
Index: trunk/minix/commands/sh/Makefile
===================================================================
--- trunk/minix/commands/sh/Makefile	(revision 9)
+++ 	(revision )
@@ -1,29 +1,0 @@
-# Makefile for sh
-
-CFLAGS	= -O -D_MINIX -D_POSIX_SOURCE -wa
-LDFLAGS	= -i
-CC = exec cc
-
-OBJ	= sh1.o sh2.o sh3.o sh4.o sh5.o sh6.o
-
-all:	sh
-
-sh:	$(OBJ)
-	cc $(LDFLAGS) -o $@ $(OBJ)
-	install -S 11kw sh
-
-install:	/usr/bin/msh
-
-/usr/bin/msh:	sh
-	install -cs -o bin $? $@
-
-#/usr/bin/sh:	/usr/bin/msh
-#	install -l $? $@
-#
-#/bin/sh:	/usr/bin/msh
-#	install -lcs $? $@
-
-$(OBJ):	sh.h
-
-clean:
-	rm -f sh *.o *.bak core
Index: trunk/minix/commands/sh/build
===================================================================
--- trunk/minix/commands/sh/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/sh/sh.h
===================================================================
--- trunk/minix/commands/sh/sh.h	(revision 9)
+++ 	(revision )
@@ -1,383 +1,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-/* Need a way to have void used for ANSI, nothing for K&R. */
-#ifndef _ANSI
-#undef _VOID
-#define _VOID
-#endif
-
-/* -------- sh.h -------- */
-/*
- * shell
- */
-
-#define	LINELIM	4096
-#define	NPUSH	8	/* limit to input nesting */
-
-#define	NOFILE	20	/* Number of open files */
-#define	NUFILE	10	/* Number of user-accessible files */
-#define	FDBASE	10	/* First file usable by Shell */
-
-/*
- * values returned by wait
- */
-#define	WAITSIG(s) ((s)&0177)
-#define	WAITVAL(s) (((s)>>8)&0377)
-#define	WAITCORE(s) (((s)&0200)!=0)
-
-/*
- * library and system defintions
- */
-#ifdef __STDC__
-typedef void xint;	/* base type of jmp_buf, for not broken compilers */
-#else
-typedef char * xint;	/* base type of jmp_buf, for broken compilers */
-#endif
-
-/*
- * shell components
- */
-/* #include "area.h" */
-/* #include "word.h" */
-/* #include "io.h" */
-/* #include "var.h" */
-
-#define	QUOTE	0200
-
-#define	NOBLOCK	((struct op *)NULL)
-#define	NOWORD	((char *)NULL)
-#define	NOWORDS	((char **)NULL)
-#define	NOPIPE	((int *)NULL)
-
-/*
- * Description of a command or an operation on commands.
- * Might eventually use a union.
- */
-struct op {
-	int	type;	/* operation type, see below */
-	char	**words;	/* arguments to a command */
-	struct	ioword	**ioact;	/* IO actions (eg, < > >>) */
-	struct op *left;
-	struct op *right;
-	char	*str;	/* identifier for case and for */
-};
-
-#define	TCOM	1	/* command */
-#define	TPAREN	2	/* (c-list) */
-#define	TPIPE	3	/* a | b */
-#define	TLIST	4	/* a [&;] b */
-#define	TOR	5	/* || */
-#define	TAND	6	/* && */
-#define	TFOR	7
-#define	TDO	8
-#define	TCASE	9
-#define	TIF	10
-#define	TWHILE	11
-#define	TUNTIL	12
-#define	TELIF	13
-#define	TPAT	14	/* pattern in case */
-#define	TBRACE	15	/* {c-list} */
-#define	TASYNC	16	/* c & */
-
-/*
- * actions determining the environment of a process
- */
-#define	BIT(i)	(1<<(i))
-#define	FEXEC	BIT(0)	/* execute without forking */
-
-/*
- * flags to control evaluation of words
- */
-#define	DOSUB	1	/* interpret $, `, and quotes */
-#define	DOBLANK	2	/* perform blank interpretation */
-#define	DOGLOB	4	/* interpret [?* */
-#define	DOKEY	8	/* move words with `=' to 2nd arg. list */
-#define	DOTRIM	16	/* trim resulting string */
-
-#define	DOALL	(DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM)
-
-Extern	char	**dolv;
-Extern	int	dolc;
-Extern	int	exstat;
-Extern  char	gflg;
-Extern  int	talking;	/* interactive (talking-type wireless) */
-Extern  int	execflg;
-Extern  int	multiline;	/* \n changed to ; */
-Extern  struct	op	*outtree;	/* result from parser */
-
-Extern	xint	*failpt;
-Extern	xint	*errpt;
-
-struct	brkcon {
-	jmp_buf	brkpt;
-	struct	brkcon	*nextlev;
-} ;
-Extern	struct brkcon	*brklist;
-Extern	int	isbreak;
-
-/*
- * redirection
- */
-struct ioword {
-	short	io_unit;	/* unit affected */
-	short	io_flag;	/* action (below) */
-	char	*io_name;	/* file name */
-};
-#define	IOREAD	1	/* < */
-#define	IOHERE	2	/* << (here file) */
-#define	IOWRITE	4	/* > */
-#define	IOCAT	8	/* >> */
-#define	IOXHERE	16	/* ${}, ` in << */
-#define	IODUP	32	/* >&digit */
-#define	IOCLOSE	64	/* >&- */
-
-#define	IODEFAULT (-1)	/* token for default IO unit */
-
-Extern	struct	wdblock	*wdlist;
-Extern	struct	wdblock	*iolist;
-
-/*
- * parsing & execution environment
- */
-extern struct	env {
-	char	*linep;
-	struct	io	*iobase;
-	struct	io	*iop;
-	xint	*errpt;
-	int	iofd;
-	struct	env	*oenv;
-} e;
-
-/*
- * flags:
- * -e: quit on error
- * -k: look for name=value everywhere on command line
- * -n: no execution
- * -t: exit after reading and executing one command
- * -v: echo as read
- * -x: trace
- * -u: unset variables net diagnostic
- */
-extern	char	*flag;
-
-extern	char	*null;	/* null value for variable */
-extern	int	intr;	/* interrupt pending */
-
-Extern	char	*trap[_NSIG+1];
-Extern	char	ourtrap[_NSIG+1];
-Extern	int	trapset;	/* trap pending */
-
-extern	int	heedint;	/* heed interrupt signals */
-
-Extern	int	yynerrs;	/* yacc */
-
-Extern	char	line[LINELIM];
-extern	char	*elinep;
-
-/*
- * other functions
- */
-#ifdef __STDC__
-int (*inbuilt(char *s ))(void);
-#else
-int (*inbuilt())();
-#endif
-_PROTOTYPE(char *rexecve , (char *c , char **v , char **envp ));
-_PROTOTYPE(char *space , (int n ));
-_PROTOTYPE(char *strsave , (char *s , int a ));
-_PROTOTYPE(char *evalstr , (char *cp , int f ));
-_PROTOTYPE(char *putn , (int n ));
-_PROTOTYPE(char *itoa , (unsigned u , int n ));
-_PROTOTYPE(char *unquote , (char *as ));
-_PROTOTYPE(struct var *lookup , (char *n ));
-_PROTOTYPE(int rlookup , (char *n ));
-_PROTOTYPE(struct wdblock *glob , (char *cp , struct wdblock *wb ));
-_PROTOTYPE(int subgetc , (int ec , int quoted ));
-_PROTOTYPE(char **makenv , (void));
-_PROTOTYPE(char **eval , (char **ap , int f ));
-_PROTOTYPE(int setstatus , (int s ));
-_PROTOTYPE(int waitfor , (int lastpid , int canintr ));
-
-_PROTOTYPE(void onintr , (int s )); /* SIGINT handler */
-
-_PROTOTYPE(int newenv , (int f ));
-_PROTOTYPE(void quitenv , (void));
-_PROTOTYPE(void err , (char *s ));
-_PROTOTYPE(int anys , (char *s1 , char *s2 ));
-_PROTOTYPE(int any , (int c , char *s ));
-_PROTOTYPE(void next , (int f ));
-_PROTOTYPE(void setdash , (void));
-_PROTOTYPE(void onecommand , (void));
-_PROTOTYPE(void runtrap , (int i ));
-_PROTOTYPE(void xfree , (char *s ));
-_PROTOTYPE(int letter , (int c ));
-_PROTOTYPE(int digit , (int c ));
-_PROTOTYPE(int letnum , (int c ));
-_PROTOTYPE(int gmatch , (char *s , char *p ));
-
-/*
- * error handling
- */
-_PROTOTYPE(void leave , (void)); /* abort shell (or fail in subshell) */
-_PROTOTYPE(void fail , (void));	 /* fail but return to process next command */
-_PROTOTYPE(void warn , (char *s ));
-_PROTOTYPE(void sig , (int i ));	 /* default signal handler */
-
-/* -------- var.h -------- */
-
-struct	var {
-	char	*value;
-	char	*name;
-	struct	var	*next;
-	char	status;
-};
-#define	COPYV	1	/* flag to setval, suggesting copy */
-#define	RONLY	01	/* variable is read-only */
-#define	EXPORT	02	/* variable is to be exported */
-#define	GETCELL	04	/* name & value space was got with getcell */
-
-Extern	struct	var	*vlist;		/* dictionary */
-
-Extern	struct	var	*homedir;	/* home directory */
-Extern	struct	var	*prompt;	/* main prompt */
-Extern	struct	var	*cprompt;	/* continuation prompt */
-Extern	struct	var	*path;		/* search path for commands */
-Extern	struct	var	*shell;		/* shell to interpret command files */
-Extern	struct	var	*ifs;		/* field separators */
-
-_PROTOTYPE(int yyparse , (void));
-_PROTOTYPE(struct var *lookup , (char *n ));
-_PROTOTYPE(void setval , (struct var *vp , char *val ));
-_PROTOTYPE(void nameval , (struct var *vp , char *val , char *name ));
-_PROTOTYPE(void export , (struct var *vp ));
-_PROTOTYPE(void ronly , (struct var *vp ));
-_PROTOTYPE(int isassign , (char *s ));
-_PROTOTYPE(int checkname , (char *cp ));
-_PROTOTYPE(int assign , (char *s , int cf ));
-_PROTOTYPE(void putvlist , (int f , int out ));
-_PROTOTYPE(int eqname , (char *n1 , char *n2 ));
-
-_PROTOTYPE(int execute , (struct op *t , int *pin , int *pout , int act ));
-
-/* -------- io.h -------- */
-/* io buffer */
-struct iobuf {
-  unsigned id;				/* buffer id */
-  char buf[512];			/* buffer */
-  char *bufp;				/* pointer into buffer */
-  char *ebufp;				/* pointer to end of buffer */
-};
-
-/* possible arguments to an IO function */
-struct ioarg {
-	char	*aword;
-	char	**awordlist;
-	int	afile;		/* file descriptor */
-	unsigned afid;		/* buffer id */
-	long	afpos;		/* file position */
-	struct iobuf *afbuf;	/* buffer for this file */
-};
-Extern struct ioarg ioargstack[NPUSH];
-#define AFID_NOBUF	(~0)
-#define AFID_ID		0
-
-/* an input generator's state */
-struct	io {
-	int	(*iofn)(_VOID);
-	struct	ioarg	*argp;
-	int	peekc;
-	char	prev;		/* previous character read by readc() */
-	char	nlcount;	/* for `'s */
-	char	xchar;		/* for `'s */
-	char	task;		/* reason for pushed IO */
-};
-Extern	struct	io	iostack[NPUSH];
-#define	XOTHER	0	/* none of the below */
-#define	XDOLL	1	/* expanding ${} */
-#define	XGRAVE	2	/* expanding `'s */
-#define	XIO	3	/* file IO */
-
-/* in substitution */
-#define	INSUB()	(e.iop->task == XGRAVE || e.iop->task == XDOLL)
-
-/*
- * input generators for IO structure
- */
-_PROTOTYPE(int nlchar , (struct ioarg *ap ));
-_PROTOTYPE(int strchar , (struct ioarg *ap ));
-_PROTOTYPE(int qstrchar , (struct ioarg *ap ));
-_PROTOTYPE(int filechar , (struct ioarg *ap ));
-_PROTOTYPE(int herechar , (struct ioarg *ap ));
-_PROTOTYPE(int linechar , (struct ioarg *ap ));
-_PROTOTYPE(int gravechar , (struct ioarg *ap , struct io *iop ));
-_PROTOTYPE(int qgravechar , (struct ioarg *ap , struct io *iop ));
-_PROTOTYPE(int dolchar , (struct ioarg *ap ));
-_PROTOTYPE(int wdchar , (struct ioarg *ap ));
-_PROTOTYPE(void scraphere , (void));
-_PROTOTYPE(void freehere , (int area ));
-_PROTOTYPE(void gethere , (void));
-_PROTOTYPE(void markhere , (char *s , struct ioword *iop ));
-_PROTOTYPE(int herein , (char *hname , int xdoll ));
-_PROTOTYPE(int run , (struct ioarg *argp , int (*f)(_VOID)));
-
-/*
- * IO functions
- */
-_PROTOTYPE(int eofc , (void));
-_PROTOTYPE(int getc , (int ec ));
-_PROTOTYPE(int readc , (void));
-_PROTOTYPE(void unget , (int c ));
-_PROTOTYPE(void ioecho , (int c ));
-_PROTOTYPE(void prs , (char *s ));
-_PROTOTYPE(void putc , (int c ));
-_PROTOTYPE(void prn , (unsigned u ));
-_PROTOTYPE(void closef , (int i ));
-_PROTOTYPE(void closeall , (void));
-
-/*
- * IO control
- */
-_PROTOTYPE(void pushio , (struct ioarg *argp , int (*fn)(_VOID)));
-_PROTOTYPE(int remap , (int fd ));
-_PROTOTYPE(int openpipe , (int *pv ));
-_PROTOTYPE(void closepipe , (int *pv ));
-_PROTOTYPE(struct io *setbase , (struct io *ip ));
-
-extern	struct	ioarg	temparg;	/* temporary for PUSHIO */
-#define	PUSHIO(what,arg,gen) ((temparg.what = (arg)),pushio(&temparg,(gen)))
-#define	RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
-
-/* -------- word.h -------- */
-#ifndef WORD_H
-#define	WORD_H	1
-struct	wdblock {
-	short	w_bsize;
-	short	w_nword;
-	/* bounds are arbitrary */
-	char	*w_words[1];
-};
-
-_PROTOTYPE(struct wdblock *addword , (char *wd , struct wdblock *wb ));
-_PROTOTYPE(struct wdblock *newword , (int nw ));
-_PROTOTYPE(char **getwords , (struct wdblock *wb ));
-#endif
-
-/* -------- area.h -------- */
-
-/*
- * storage allocation
- */
-_PROTOTYPE(char *getcell , (unsigned nbytes ));
-_PROTOTYPE(void garbage , (void));
-_PROTOTYPE(void setarea , (char *cp , int a ));
-_PROTOTYPE(int getarea , (char *cp ));
-_PROTOTYPE(void freearea , (int a ));
-_PROTOTYPE(void freecell , (char *cp ));
-
-Extern	int	areanum;	/* current allocation area */
-
-#define	NEW(type) (type *)getcell(sizeof(type))
-#define	DELETE(obj)	freecell((char *)obj)
Index: trunk/minix/commands/sh/sh1.c
===================================================================
--- trunk/minix/commands/sh/sh1.c	(revision 9)
+++ 	(revision )
@@ -1,952 +1,0 @@
-#define Extern extern
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <setjmp.h>
-#include "sh.h"
-/* -------- sh.c -------- */
-/*
- * shell
- */
-
-/* #include "sh.h" */
-
-int	intr;
-int	inparse;
-char	flags['z'-'a'+1];
-char	*flag = flags-'a';
-char	*elinep = line+sizeof(line)-5;
-char	*null	= "";
-int	heedint =1;
-struct	env	e ={line, iostack, iostack-1,
-		    (xint *)NULL, FDBASE, (struct env *)NULL};
-
-extern	char	**environ;	/* environment pointer */
-
-/*
- * default shell, search rules
- */
-char	shellname[] = "/bin/sh";
-char	search[] = ":/bin:/usr/bin";
-
-_PROTOTYPE(void (*qflag), (int)) = SIG_IGN;
-
-_PROTOTYPE(int main, (int argc, char **argv ));
-_PROTOTYPE(int newfile, (char *s ));
-_PROTOTYPE(static char *findeq, (char *cp ));
-_PROTOTYPE(static char *cclass, (char *p, int sub ));
-_PROTOTYPE(void initarea, (void));
-
-int main(argc, argv)
-int argc;
-register char **argv;
-{
-	register int f;
-	register char *s;
-	int cflag;
-	char *name, **ap;
-	int (*iof)();
-
-	initarea();
-	if ((ap = environ) != NULL) {
-		while (*ap)
-			assign(*ap++, !COPYV);
-		for (ap = environ; *ap;)
-			export(lookup(*ap++));
-	}
-	closeall();
-	areanum = 1;
-
-	shell = lookup("SHELL");
-	if (shell->value == null)
-		setval(shell, shellname);
-	export(shell);
-
-	homedir = lookup("HOME");
-	if (homedir->value == null)
-		setval(homedir, "/");
-	export(homedir);
-
-	setval(lookup("$"), itoa(getpid(), 5));
-
-	path = lookup("PATH");
-	if (path->value == null)
-		setval(path, search);
-	export(path);
-
-	ifs = lookup("IFS");
-	if (ifs->value == null)
-		setval(ifs, " \t\n");
-
-	prompt = lookup("PS1");
-	if (prompt->value == null)
-#ifndef UNIXSHELL
-		setval(prompt, "$ ");
-#else
-		setval(prompt, "% ");
-#endif
-
-	if (geteuid() == 0) {
-		setval(prompt, "# ");
-		prompt->status &= ~EXPORT;
-	}
-	cprompt = lookup("PS2");
-	if (cprompt->value == null)
-		setval(cprompt, "> ");
-
-	iof = filechar;
-	cflag = 0;
-	name = *argv++;
-	if (--argc >= 1) {
-		if(argv[0][0] == '-' && argv[0][1] != '\0') {
-			for (s = argv[0]+1; *s; s++)
-				switch (*s) {
-				case 'c':
-					prompt->status &= ~EXPORT;
-					cprompt->status &= ~EXPORT;
-					setval(prompt, "");
-					setval(cprompt, "");
-					cflag = 1;
-					if (--argc > 0)
-						PUSHIO(aword, *++argv, iof = nlchar);
-					break;
-	
-				case 'q':
-					qflag = SIG_DFL;
-					break;
-
-				case 's':
-					/* standard input */
-					break;
-
-				case 't':
-					prompt->status &= ~EXPORT;
-					setval(prompt, "");
-					iof = linechar;
-					break;
-	
-				case 'i':
-					talking++;
-				default:
-					if (*s>='a' && *s<='z')
-						flag[*s]++;
-				}
-		} else {
-			argv--;
-			argc++;
-		}
-		if (iof == filechar && --argc > 0) {
-			setval(prompt, "");
-			setval(cprompt, "");
-			prompt->status &= ~EXPORT;
-			cprompt->status &= ~EXPORT;
-			if (newfile(name = *++argv))
-				exit(1);
-		}
-	}
-	setdash();
-	if (e.iop < iostack) {
-		PUSHIO(afile, 0, iof);
-		if (isatty(0) && isatty(1) && !cflag)
-			talking++;
-	}
-	signal(SIGQUIT, qflag);
-	if (name && name[0] == '-') {
-		talking++;
-		if ((f = open(".profile", 0)) >= 0)
-			next(remap(f));
-		if ((f = open("/etc/profile", 0)) >= 0)
-			next(remap(f));
-	}
-	if (talking)
-		signal(SIGTERM, sig);
-	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
-		signal(SIGINT, onintr);
-	dolv = argv;
-	dolc = argc;
-	dolv[0] = name;
-	if (dolc > 1)
-		for (ap = ++argv; --argc > 0;)
-			if (assign(*ap = *argv++, !COPYV))
-				dolc--;	/* keyword */
-			else
-				ap++;
-	setval(lookup("#"), putn((--dolc < 0) ? (dolc = 0) : dolc));
-
-	for (;;) {
-		if (talking && e.iop <= iostack)
-			prs(prompt->value);
-		onecommand();
-	}
-}
-
-void
-setdash()
-{
-	register char *cp, c;
-	char m['z'-'a'+1];
-
-	cp = m;
-	for (c='a'; c<='z'; c++)
-		if (flag[c])
-			*cp++ = c;
-	*cp = 0;
-	setval(lookup("-"), m);
-}
-
-int
-newfile(s)
-register char *s;
-{
-	register f;
-
-	if (strcmp(s, "-") != 0) {
-		f = open(s, 0);
-		if (f < 0) {
-			prs(s);
-			err(": cannot open");
-			return(1);
-		}
-	} else
-		f = 0;
-	next(remap(f));
-	return(0);
-}
-
-void
-onecommand()
-{
-	register i;
-	jmp_buf m1;
-
-	while (e.oenv)
-		quitenv();
-	areanum = 1;
-	freehere(areanum);
-	freearea(areanum);
-	garbage();
-	wdlist = 0;
-	iolist = 0;
-	e.errpt = 0;
-	e.linep = line;
-	yynerrs = 0;
-	multiline = 0;
-	inparse = 1;
-	intr = 0;
-	execflg = 0;
-	setjmp(failpt = m1);	/* Bruce Evans' fix */
-	if (setjmp(failpt = m1) || yyparse() || intr) {
-		while (e.oenv)
-			quitenv();
-		scraphere();
-		if (!talking && intr)
-			leave();
-		inparse = 0;
-		intr = 0;
-		return;
-	}
-	inparse = 0;
-	brklist = 0;
-	intr = 0;
-	execflg = 0;
-	if (!flag['n'])
-		execute(outtree, NOPIPE, NOPIPE, 0);
-	if (!talking && intr) {
-		execflg = 0;
-		leave();
-	}
-	if ((i = trapset) != 0) {
-		trapset = 0;
-		runtrap(i);
-	}
-}
-
-void
-fail()
-{
-	longjmp(failpt, 1);
-	/* NOTREACHED */
-}
-
-void
-leave()
-{
-	if (execflg)
-		fail();
-	scraphere();
-	freehere(1);
-	runtrap(0);
-	exit(exstat);
-	/* NOTREACHED */
-}
-
-void
-warn(s)
-register char *s;
-{
-	if(*s) {
-		prs(s);
-		exstat = -1;
-	}
-	prs("\n");
-	if (flag['e'])
-		leave();
-}
-
-void
-err(s)
-char *s;
-{
-	warn(s);
-	if (flag['n'])
-		return;
-	if (!talking)
-		leave();
-	if (e.errpt)
-		longjmp(e.errpt, 1);
-	closeall();
-	e.iop = e.iobase = iostack;
-}
-
-int
-newenv(f)
-int f;
-{
-	register struct env *ep;
-
-	if (f) {
-		quitenv();
-		return(1);
-	}
-	ep = (struct env *) space(sizeof(*ep));
-	if (ep == NULL) {
-		while (e.oenv)
-			quitenv();
-		fail();
-	}
-	*ep = e;
-	e.oenv = ep;
-	e.errpt = errpt;
-	return(0);
-}
-
-void
-quitenv()
-{
-	register struct env *ep;
-	register fd;
-
-	if ((ep = e.oenv) != NULL) {
-		fd = e.iofd;
-		e = *ep;
-		/* should close `'d files */
-		DELETE(ep);
-		while (--fd >= e.iofd)
-			close(fd);
-	}
-}
-
-/*
- * Is any character from s1 in s2?
- */
-int
-anys(s1, s2)
-register char *s1, *s2;
-{
-	while (*s1)
-		if (any(*s1++, s2))
-			return(1);
-	return(0);
-}
-
-/*
- * Is character c in s?
- */
-int
-any(c, s)
-register int c;
-register char *s;
-{
-	while (*s)
-		if (*s++ == c)
-			return(1);
-	return(0);
-}
-
-char *
-putn(n)
-register int n;
-{
-	return(itoa(n, -1));
-}
-
-char *
-itoa(u, n)
-register unsigned u;
-int n;
-{
-	register char *cp;
-	static char s[20];
-	int m;
-
-	m = 0;
-	if (n < 0 && (int) u < 0) {
-		m++;
-		u = -u;
-	}
-	cp = s+sizeof(s);
-	*--cp = 0;
-	do {
-		*--cp = u%10 + '0';
-		u /= 10;
-	} while (--n > 0 || u);
-	if (m)
-		*--cp = '-';
-	return(cp);
-}
-
-void
-next(f)
-int f;
-{
-	PUSHIO(afile, f, filechar);
-}
-
-void
-onintr(s)
-int s;				/* ANSI C requires a parameter */
-{
-	signal(SIGINT, onintr);
-	intr = 1;
-	if (talking) {
-		if (inparse) {
-			prs("\n");
-			fail();
-		}
-	}
-	else if (heedint) {
-		execflg = 0;
-		leave();
-	}
-}
-
-int
-letter(c)
-register c;
-{
-	return((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_');
-}
-
-int
-digit(c)
-register c;
-{
-	return(c >= '0' && c <= '9');
-}
-
-int
-letnum(c)
-register c;
-{
-	return(letter(c) || digit(c));
-}
-
-char *
-space(n)
-int n;
-{
-	register char *cp;
-
-	if ((cp = getcell(n)) == 0)
-		err("out of string space");
-	return(cp);
-}
-
-char *
-strsave(s, a)
-register char *s;
-int a;
-{
-	register char *cp, *xp;
-
-	if ((cp = space(strlen(s)+1)) != NULL) {
-		setarea((char *)cp, a);
-		for (xp = cp; (*xp++ = *s++) != '\0';)
-			;
-		return(cp);
-	}
-	return("");
-}
-
-void
-xfree(s)
-register char *s;
-{
-	DELETE(s);
-}
-
-/*
- * trap handling
- */
-void
-sig(i)
-register int i;
-{
-	trapset = i;
-	signal(i, sig);
-}
-
-void runtrap(i)
-int i;
-{
-	char *trapstr;
-
-	if ((trapstr = trap[i]) == NULL)
-		return;
-	if (i == 0)
-		trap[i] = 0;
-	RUN(aword, trapstr, nlchar);
-}
-
-/* -------- var.c -------- */
-/* #include "sh.h" */
-
-/*
- * Find the given name in the dictionary
- * and return its value.  If the name was
- * not previously there, enter it now and
- * return a null value.
- */
-struct var *
-lookup(n)
-register char *n;
-{
-	register struct var *vp;
-	register char *cp;
-	register int c;
-	static struct var dummy;
-
-	if (digit(*n)) {
-		dummy.name = n;
-		for (c = 0; digit(*n) && c < 1000; n++)
-			c = c*10 + *n-'0';
-		dummy.status = RONLY;
-		dummy.value = c <= dolc? dolv[c]: null;
-		return(&dummy);
-	}
-	for (vp = vlist; vp; vp = vp->next)
-		if (eqname(vp->name, n))
-			return(vp);
-	cp = findeq(n);
-	vp = (struct var *)space(sizeof(*vp));
-	if (vp == 0 || (vp->name = space((int)(cp-n)+2)) == 0) {
-		dummy.name = dummy.value = "";
-		return(&dummy);
-	}
-	for (cp = vp->name; (*cp = *n++) && *cp != '='; cp++)
-		;
-	if (*cp == 0)
-		*cp = '=';
-	*++cp = 0;
-	setarea((char *)vp, 0);
-	setarea((char *)vp->name, 0);
-	vp->value = null;
-	vp->next = vlist;
-	vp->status = GETCELL;
-	vlist = vp;
-	return(vp);
-}
-
-/*
- * give variable at `vp' the value `val'.
- */
-void
-setval(vp, val)
-struct var *vp;
-char *val;
-{
-	nameval(vp, val, (char *)NULL);
-}
-
-/*
- * if name is not NULL, it must be
- * a prefix of the space `val',
- * and end with `='.
- * this is all so that exporting
- * values is reasonably painless.
- */
-void
-nameval(vp, val, name)
-register struct var *vp;
-char *val, *name;
-{
-	register char *cp, *xp;
-	char *nv;
-	int fl;
-
-	if (vp->status & RONLY) {
-		for (xp = vp->name; *xp && *xp != '=';)
-			putc(*xp++);
-		err(" is read-only");
-		return;
-	}
-	fl = 0;
-	if (name == NULL) {
-		xp = space(strlen(vp->name)+strlen(val)+2);
-		if (xp == 0)
-			return;
-		/* make string:  name=value */
-		setarea((char *)xp, 0);
-		name = xp;
-		for (cp = vp->name; (*xp = *cp++) && *xp!='='; xp++)
-			;
-		if (*xp++ == 0)
-			xp[-1] = '=';
-		nv = xp;
-		for (cp = val; (*xp++ = *cp++) != '\0';)
-			;
-		val = nv;
-		fl = GETCELL;
-	}
-	if (vp->status & GETCELL)
-		xfree(vp->name);	/* form new string `name=value' */
-	vp->name = name;
-	vp->value = val;
-	vp->status |= fl;
-}
-
-void
-export(vp)
-struct var *vp;
-{
-	vp->status |= EXPORT;
-}
-
-void
-ronly(vp)
-struct var *vp;
-{
-	if (letter(vp->name[0]))	/* not an internal symbol ($# etc) */
-		vp->status |= RONLY;
-}
-
-int
-isassign(s)
-register char *s;
-{
-	if (!letter((int)*s))
-		return(0);
-	for (; *s != '='; s++)
-		if (*s == 0 || !letnum(*s))
-			return(0);
-	return(1);
-}
-
-int
-assign(s, cf)
-register char *s;
-int cf;
-{
-	register char *cp;
-	struct var *vp;
-
-	if (!letter(*s))
-		return(0);
-	for (cp = s; *cp != '='; cp++)
-		if (*cp == 0 || !letnum(*cp))
-			return(0);
-	vp = lookup(s);
-	nameval(vp, ++cp, cf == COPYV? (char *)NULL: s);
-	if (cf != COPYV)
-		vp->status &= ~GETCELL;
-	return(1);
-}
-
-int
-checkname(cp)
-register char *cp;
-{
-	if (!letter(*cp++))
-		return(0);
-	while (*cp)
-		if (!letnum(*cp++))
-			return(0);
-	return(1);
-}
-
-void
-putvlist(f, out)
-register int f, out;
-{
-	register struct var *vp;
-
-	for (vp = vlist; vp; vp = vp->next)
-		if (vp->status & f && letter(*vp->name)) {
-			if (vp->status & EXPORT)
-				write(out, "export ", 7);
-			if (vp->status & RONLY)
-				write(out, "readonly ", 9);
-			write(out, vp->name, (int)(findeq(vp->name) - vp->name));
-			write(out, "\n", 1);
-		}
-}
-
-int
-eqname(n1, n2)
-register char *n1, *n2;
-{
-	for (; *n1 != '=' && *n1 != 0; n1++)
-		if (*n2++ != *n1)
-			return(0);
-	return(*n2 == 0 || *n2 == '=');
-}
-
-static char *
-findeq(cp)
-register char *cp;
-{
-	while (*cp != '\0' && *cp != '=')
-		cp++;
-	return(cp);
-}
-
-/* -------- gmatch.c -------- */
-/*
- * int gmatch(string, pattern)
- * char *string, *pattern;
- *
- * Match a pattern as in sh(1).
- */
-
-#define	CMASK	0377
-#define	QUOTE	0200
-#define	QMASK	(CMASK&~QUOTE)
-#define	NOT	'!'	/* might use ^ */
-
-int
-gmatch(s, p)
-register char *s, *p;
-{
-	register int sc, pc;
-
-	if (s == NULL || p == NULL)
-		return(0);
-	while ((pc = *p++ & CMASK) != '\0') {
-		sc = *s++ & QMASK;
-		switch (pc) {
-		case '[':
-			if ((p = cclass(p, sc)) == NULL)
-				return(0);
-			break;
-
-		case '?':
-			if (sc == 0)
-				return(0);
-			break;
-
-		case '*':
-			s--;
-			do {
-				if (*p == '\0' || gmatch(s, p))
-					return(1);
-			} while (*s++ != '\0');
-			return(0);
-
-		default:
-			if (sc != (pc&~QUOTE))
-				return(0);
-		}
-	}
-	return(*s == 0);
-}
-
-static char *
-cclass(p, sub)
-register char *p;
-register int sub;
-{
-	register int c, d, not, found;
-
-	if ((not = *p == NOT) != 0)
-		p++;
-	found = not;
-	do {
-		if (*p == '\0')
-			return((char *)NULL);
-		c = *p & CMASK;
-		if (p[1] == '-' && p[2] != ']') {
-			d = p[2] & CMASK;
-			p++;
-		} else
-			d = c;
-		if (c == sub || (c <= sub && sub <= d))
-			found = !not;
-	} while (*++p != ']');
-	return(found? p+1: (char *)NULL);
-}
-
-/* -------- area.c -------- */
-#define	REGSIZE		sizeof(struct region)
-#define GROWBY		256
-#undef	SHRINKBY	64
-#define FREE 32767
-#define BUSY 0
-#define	ALIGN (sizeof(int)-1)
-
-/* #include "area.h" */
-
-struct region {
-	struct	region *next;
-	int	area;
-};
-
-/*
- * All memory between (char *)areabot and (char *)(areatop+1) is
- * exclusively administered by the area management routines.
- * It is assumed that sbrk() and brk() manipulate the high end.
- */
-static	struct region *areabot;		/* bottom of area */
-static	struct region *areatop;		/* top of area */
-static	struct region *areanxt;		/* starting point of scan */
-
-void
-initarea()
-{
-	while ((int)sbrk(0) & ALIGN)
-		sbrk(1);
-	areabot = (struct region *)sbrk(REGSIZE);
-	areabot->next = areabot;
-	areabot->area = BUSY;
-	areatop = areabot;
-	areanxt = areabot;
-}
-
-char *
-getcell(nbytes)
-unsigned nbytes;
-{
-	register int nregio;
-	register struct region *p, *q;
-	register i;
-
-	if (nbytes == 0)
-		abort();	/* silly and defeats the algorithm */
-	/*
-	 * round upwards and add administration area
-	 */
-	nregio = (nbytes+(REGSIZE-1))/REGSIZE + 1;
-	for (p = areanxt;;) {
-		if (p->area > areanum) {
-			/*
-			 * merge free cells
-			 */
-			while ((q = p->next)->area > areanum && q != areanxt)
-				p->next = q->next;
-			/*
-			 * exit loop if cell big enough
-			 */
-			if (q >= p + nregio)
-				goto found;
-		}
-		p = p->next;
-		if (p == areanxt)
-			break;
-	}
-	i = nregio >= GROWBY ? nregio : GROWBY;
-	p = (struct region *)sbrk(i * REGSIZE);
-	if (p == (struct region *)-1)
-		return((char *)NULL);
-	p--;
-	if (p != areatop)
-		abort();	/* allocated areas are contiguous */
-	q = p + i;
-	p->next = q;
-	p->area = FREE;
-	q->next = areabot;
-	q->area = BUSY;
-	areatop = q;
-found:
-	/*
-	 * we found a FREE area big enough, pointed to by 'p', and up to 'q'
-	 */
-	areanxt = p + nregio;
-	if (areanxt < q) {
-		/*
-		 * split into requested area and rest
-		 */
-		if (areanxt+1 > q)
-			abort();	/* insufficient space left for admin */
-		areanxt->next = q;
-		areanxt->area = FREE;
-		p->next = areanxt;
-	}
-	p->area = areanum;
-	return((char *)(p+1));
-}
-
-void
-freecell(cp)
-char *cp;
-{
-	register struct region *p;
-
-	if ((p = (struct region *)cp) != NULL) {
-		p--;
-		if (p < areanxt)
-			areanxt = p;
-		p->area = FREE;
-	}
-}
-
-void
-freearea(a)
-register int a;
-{
-	register struct region *p, *top;
-
-	top = areatop;
-	for (p = areabot; p != top; p = p->next)
-		if (p->area >= a)
-			p->area = FREE;
-}
-
-void
-setarea(cp,a)
-char *cp;
-int a;
-{
-	register struct region *p;
-
-	if ((p = (struct region *)cp) != NULL)
-		(p-1)->area = a;
-}
-
-int
-getarea(cp)
-char *cp;
-{
-	return ((struct region*)cp-1)->area;
-}
-
-void
-garbage()
-{
-	register struct region *p, *q, *top;
-
-	top = areatop;
-	for (p = areabot; p != top; p = p->next) {
-		if (p->area > areanum) {
-			while ((q = p->next)->area > areanum)
-				p->next = q->next;
-			areanxt = p;
-		}
-	}
-#ifdef SHRINKBY
-	if (areatop >= q + SHRINKBY && q->area > areanum) {
-		brk((char *)(q+1));
-		q->next = areabot;
-		q->area = BUSY;
-		areatop = q;
-	}
-#endif
-}
Index: trunk/minix/commands/sh/sh2.c
===================================================================
--- trunk/minix/commands/sh/sh2.c	(revision 9)
+++ 	(revision )
@@ -1,800 +1,0 @@
-#define Extern extern
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <setjmp.h>
-#include "sh.h"
-
-/* -------- csyn.c -------- */
-/*
- * shell: syntax (C version)
- */
-
-typedef union {
-	char	*cp;
-	char	**wp;
-	int	i;
-	struct	op *o;
-} YYSTYPE;
-#define	WORD	256
-#define	LOGAND	257
-#define	LOGOR	258
-#define	BREAK	259
-#define	IF	260
-#define	THEN	261
-#define	ELSE	262
-#define	ELIF	263
-#define	FI	264
-#define	CASE	265
-#define	ESAC	266
-#define	FOR	267
-#define	WHILE	268
-#define	UNTIL	269
-#define	DO	270
-#define	DONE	271
-#define	IN	272
-#define	YYERRCODE 300
-
-/* flags to yylex */
-#define	CONTIN	01	/* skip new lines to complete command */
-
-/* #include "sh.h" */
-#define	SYNTAXERR	zzerr()
-static	int	startl;
-static	int	peeksym;
-static	int	nlseen;
-static	int	iounit = IODEFAULT;
-
-static	YYSTYPE	yylval;
-
-_PROTOTYPE(static struct op *pipeline, (int cf ));
-_PROTOTYPE(static struct op *andor, (void));
-_PROTOTYPE(static struct op *c_list, (void));
-_PROTOTYPE(static int synio, (int cf ));
-_PROTOTYPE(static void musthave, (int c, int cf ));
-_PROTOTYPE(static struct op *simple, (void));
-_PROTOTYPE(static struct op *nested, (int type, int mark ));
-_PROTOTYPE(static struct op *command, (int cf ));
-_PROTOTYPE(static struct op *dogroup, (int onlydone ));
-_PROTOTYPE(static struct op *thenpart, (void));
-_PROTOTYPE(static struct op *elsepart, (void));
-_PROTOTYPE(static struct op *caselist, (void));
-_PROTOTYPE(static struct op *casepart, (void));
-_PROTOTYPE(static char **pattern, (void));
-_PROTOTYPE(static char **wordlist, (void));
-_PROTOTYPE(static struct op *list, (struct op *t1, struct op *t2 ));
-_PROTOTYPE(static struct op *block, (int type, struct op *t1, struct op *t2, char **wp ));
-_PROTOTYPE(static struct op *newtp, (void));
-_PROTOTYPE(static struct op *namelist, (struct op *t ));
-_PROTOTYPE(static char **copyw, (void));
-_PROTOTYPE(static void word, (char *cp ));
-_PROTOTYPE(static struct ioword **copyio, (void));
-_PROTOTYPE(static struct ioword *io, (int u, int f, char *cp ));
-_PROTOTYPE(static void zzerr, (void));
-_PROTOTYPE(void yyerror, (char *s ));
-_PROTOTYPE(static int yylex, (int cf ));
-_PROTOTYPE(int collect, (int c, int c1 ));
-_PROTOTYPE(int dual, (int c ));
-_PROTOTYPE(static void diag, (int ec ));
-_PROTOTYPE(static char *tree, (unsigned size ));
-_PROTOTYPE(void printf, (char *s ));
-
-int
-yyparse()
-{
-	startl  = 1;
-	peeksym = 0;
-	yynerrs = 0;
-	outtree = c_list();
-	musthave('\n', 0);
-	return(yynerrs!=0);
-}
-
-static struct op *
-pipeline(cf)
-int cf;
-{
-	register struct op *t, *p;
-	register int c;
-
-	t = command(cf);
-	if (t != NULL) {
-		while ((c = yylex(0)) == '|') {
-			if ((p = command(CONTIN)) == NULL)
-				SYNTAXERR;
-			if (t->type != TPAREN && t->type != TCOM) {
-				/* shell statement */
-				t = block(TPAREN, t, NOBLOCK, NOWORDS);
-			}
-			t = block(TPIPE, t, p, NOWORDS);
-		}
-		peeksym = c;
-	}
-	return(t);
-}
-
-static struct op *
-andor()
-{
-	register struct op *t, *p;
-	register int c;
-
-	t = pipeline(0);
-	if (t != NULL) {
-		while ((c = yylex(0)) == LOGAND || c == LOGOR) {
-			if ((p = pipeline(CONTIN)) == NULL)
-				SYNTAXERR;
-			t = block(c == LOGAND? TAND: TOR, t, p, NOWORDS);
-		}
-		peeksym = c;
-	}
-	return(t);
-}
-
-static struct op *
-c_list()
-{
-	register struct op *t, *p;
-	register int c;
-
-	t = andor();
-	if (t != NULL) {
-		if((peeksym = yylex(0)) == '&')
-			t = block(TASYNC, t, NOBLOCK, NOWORDS);
-		while ((c = yylex(0)) == ';' || c == '&' || (multiline && c == '\n')) {
-			if ((p = andor()) == NULL)
-				return(t);
-			if((peeksym = yylex(0)) == '&')
-				p = block(TASYNC, p, NOBLOCK, NOWORDS);
-			t = list(t, p);
-		}
-		peeksym = c;
-	}
-	return(t);
-}
-
-
-static int
-synio(cf)
-int cf;
-{
-	register struct ioword *iop;
-	register int i;
-	register int c;
-
-	if ((c = yylex(cf)) != '<' && c != '>') {
-		peeksym = c;
-		return(0);
-	}
-	i = yylval.i;
-	musthave(WORD, 0);
-	iop = io(iounit, i, yylval.cp);
-	iounit = IODEFAULT;
-	if (i & IOHERE)
-		markhere(yylval.cp, iop);
-	return(1);
-}
-
-static void
-musthave(c, cf)
-int c, cf;
-{
-	if ((peeksym = yylex(cf)) != c)
-		SYNTAXERR;
-	peeksym = 0;
-}
-
-static struct op *
-simple()
-{
-	register struct op *t;
-
-	t = NULL;
-	for (;;) {
-		switch (peeksym = yylex(0)) {
-		case '<':
-		case '>':
-			(void) synio(0);
-			break;
-
-		case WORD:
-			if (t == NULL) {
-				t = newtp();
-				t->type = TCOM;
-			}
-			peeksym = 0;
-			word(yylval.cp);
-			break;
-
-		default:
-			return(t);
-		}
-	}
-}
-
-static struct op *
-nested(type, mark)
-int type, mark;
-{
-	register struct op *t;
-
-	multiline++;
-	t = c_list();
-	musthave(mark, 0);
-	multiline--;
-	return(block(type, t, NOBLOCK, NOWORDS));
-}
-
-static struct op *
-command(cf)
-int cf;
-{
-	register struct op *t;
-	struct wdblock *iosave;
-	register int c;
-
-	iosave = iolist;
-	iolist = NULL;
-	if (multiline)
-		cf |= CONTIN;
-	while (synio(cf))
-		cf = 0;
-	switch (c = yylex(cf)) {
-	default:
-		peeksym = c;
-		if ((t = simple()) == NULL) {
-			if (iolist == NULL)
-				return((struct op *)NULL);
-			t = newtp();
-			t->type = TCOM;
-		}
-		break;
-
-	case '(':
-		t = nested(TPAREN, ')');
-		break;
-
-	case '{':
-		t = nested(TBRACE, '}');
-		break;
-
-	case FOR:
-		t = newtp();
-		t->type = TFOR;
-		musthave(WORD, 0);
-		startl = 1;
-		t->str = yylval.cp;
-		multiline++;
-		t->words = wordlist();
-		if ((c = yylex(0)) != '\n' && c != ';')
-			peeksym = c;
-		t->left = dogroup(0);
-		multiline--;
-		break;
-
-	case WHILE:
-	case UNTIL:
-		multiline++;
-		t = newtp();
-		t->type = c == WHILE? TWHILE: TUNTIL;
-		t->left = c_list();
-		t->right = dogroup(1);
-		t->words = NULL;
-		multiline--;
-		break;
-
-	case CASE:
-		t = newtp();
-		t->type = TCASE;
-		musthave(WORD, 0);
-		t->str = yylval.cp;
-		startl++;
-		multiline++;
-		musthave(IN, CONTIN);
-		startl++;
-		t->left = caselist();
-		musthave(ESAC, 0);
-		multiline--;
-		break;
-
-	case IF:
-		multiline++;
-		t = newtp();
-		t->type = TIF;
-		t->left = c_list();
-		t->right = thenpart();
-		musthave(FI, 0);
-		multiline--;
-		break;
-	}
-	while (synio(0))
-		;
-	t = namelist(t);
-	iolist = iosave;
-	return(t);
-}
-
-static struct op *
-dogroup(onlydone)
-int onlydone;
-{
-	register int c;
-	register struct op *list;
-
-	c = yylex(CONTIN);
-	if (c == DONE && onlydone)
-		return((struct op *)NULL);
-	if (c != DO)
-		SYNTAXERR;
-	list = c_list();
-	musthave(DONE, 0);
-	return(list);
-}
-
-static struct op *
-thenpart()
-{
-	register int c;
-	register struct op *t;
-
-	if ((c = yylex(0)) != THEN) {
-		peeksym = c;
-		return((struct op *)NULL);
-	}
-	t = newtp();
-	t->type = 0;
-	t->left = c_list();
-	if (t->left == NULL)
-		SYNTAXERR;
-	t->right = elsepart();
-	return(t);
-}
-
-static struct op *
-elsepart()
-{
-	register int c;
-	register struct op *t;
-
-	switch (c = yylex(0)) {
-	case ELSE:
-		if ((t = c_list()) == NULL)
-			SYNTAXERR;
-		return(t);
-
-	case ELIF:
-		t = newtp();
-		t->type = TELIF;
-		t->left = c_list();
-		t->right = thenpart();
-		return(t);
-
-	default:
-		peeksym = c;
-		return((struct op *)NULL);
-	}
-}
-
-static struct op *
-caselist()
-{
-	register struct op *t;
-
-	t = NULL;
-	while ((peeksym = yylex(CONTIN)) != ESAC)
-		t = list(t, casepart());
-	return(t);
-}
-
-static struct op *
-casepart()
-{
-	register struct op *t;
-
-	t = newtp();
-	t->type = TPAT;
-	t->words = pattern();
-	musthave(')', 0);
-	t->left = c_list();
-	if ((peeksym = yylex(CONTIN)) != ESAC)
-		musthave(BREAK, CONTIN);
-	return(t);
-}
-
-static char **
-pattern()
-{
-	register int c, cf;
-
-	cf = CONTIN;
-	do {
-		musthave(WORD, cf);
-		word(yylval.cp);
-		cf = 0;
-	} while ((c = yylex(0)) == '|');
-	peeksym = c;
-	word(NOWORD);
-	return(copyw());
-}
-
-static char **
-wordlist()
-{
-	register int c;
-
-	if ((c = yylex(0)) != IN) {
-		peeksym = c;
-		return((char **)NULL);
-	}
-	startl = 0;
-	while ((c = yylex(0)) == WORD)
-		word(yylval.cp);
-	word(NOWORD);
-	peeksym = c;
-	return(copyw());
-}
-
-/*
- * supporting functions
- */
-static struct op *
-list(t1, t2)
-register struct op *t1, *t2;
-{
-	if (t1 == NULL)
-		return(t2);
-	if (t2 == NULL)
-		return(t1);
-	return(block(TLIST, t1, t2, NOWORDS));
-}
-
-static struct op *
-block(type, t1, t2, wp)
-int type;
-struct op *t1, *t2;
-char **wp;
-{
-	register struct op *t;
-
-	t = newtp();
-	t->type = type;
-	t->left = t1;
-	t->right = t2;
-	t->words = wp;
-	return(t);
-}
-
-struct res {
-	char	*r_name;
-	int	r_val;
-} restab[] = {
-	"for",		FOR,
-	"case",		CASE,
-	"esac",		ESAC,
-	"while",	WHILE,
-	"do",		DO,
-	"done",		DONE,
-	"if",		IF,
-	"in",		IN,
-	"then",		THEN,
-	"else",		ELSE,
-	"elif",		ELIF,
-	"until",	UNTIL,
-	"fi",		FI,
-
-	";;",		BREAK,
-	"||",		LOGOR,
-	"&&",		LOGAND,
-	"{",		'{',
-	"}",		'}',
-
-	0,
-};
-
-int
-rlookup(n)
-register char *n;
-{
-	register struct res *rp;
-
-	for (rp = restab; rp->r_name; rp++)
-		if (strcmp(rp->r_name, n) == 0)
-			return(rp->r_val);
-	return(0);
-}
-
-static struct op *
-newtp()
-{
-	register struct op *t;
-
-	t = (struct op *)tree(sizeof(*t));
-	t->type = 0;
-	t->words = NULL;
-	t->ioact = NULL;
-	t->left = NULL;
-	t->right = NULL;
-	t->str = NULL;
-	return(t);
-}
-
-static struct op *
-namelist(t)
-register struct op *t;
-{
-	if (iolist) {
-		iolist = addword((char *)NULL, iolist);
-		t->ioact = copyio();
-	} else
-		t->ioact = NULL;
-	if (t->type != TCOM) {
-		if (t->type != TPAREN && t->ioact != NULL) {
-			t = block(TPAREN, t, NOBLOCK, NOWORDS);
-			t->ioact = t->left->ioact;
-			t->left->ioact = NULL;
-		}
-		return(t);
-	}
-	word(NOWORD);
-	t->words = copyw();
-	return(t);
-}
-
-static char **
-copyw()
-{
-	register char **wd;
-
-	wd = getwords(wdlist);
-	wdlist = 0;
-	return(wd);
-}
-
-static void
-word(cp)
-char *cp;
-{
-	wdlist = addword(cp, wdlist);
-}
-
-static struct ioword **
-copyio()
-{
-	register struct ioword **iop;
-
-	iop = (struct ioword **) getwords(iolist);
-	iolist = 0;
-	return(iop);
-}
-
-static struct ioword *
-io(u, f, cp)
-int u;
-int f;
-char *cp;
-{
-	register struct ioword *iop;
-
-	iop = (struct ioword *) tree(sizeof(*iop));
-	iop->io_unit = u;
-	iop->io_flag = f;
-	iop->io_name = cp;
-	iolist = addword((char *)iop, iolist);
-	return(iop);
-}
-
-static void
-zzerr()
-{
-	yyerror("syntax error");
-}
-
-void
-yyerror(s)
-char *s;
-{
-	yynerrs++;
-	if (talking && e.iop <= iostack) {
-		multiline = 0;
-		while (eofc() == 0 && yylex(0) != '\n')
-			;
-	}
-	err(s);
-	fail();
-}
-
-static int
-yylex(cf)
-int cf;
-{
-	register int c, c1;
-	int atstart;
-
-	if ((c = peeksym) > 0) {
-		peeksym = 0;
-		if (c == '\n')
-			startl = 1;
-		return(c);
-	}
-	nlseen = 0;
-	e.linep = line;
-	atstart = startl;
-	startl = 0;
-	yylval.i = 0;
-
-loop:
-	while ((c = getc(0)) == ' ' || c == '\t')
-		;
-	switch (c) {
-	default:
-		if (any(c, "0123456789")) {
-			unget(c1 = getc(0));
-			if (c1 == '<' || c1 == '>') {
-				iounit = c - '0';
-				goto loop;
-			}
-			*e.linep++ = c;
-			c = c1;
-		}
-		break;
-
-	case '#':
-		while ((c = getc(0)) != 0 && c != '\n')
-			;
-		unget(c);
-		goto loop;
-
-	case 0:
-		return(c);
-
-	case '$':
-		*e.linep++ = c;
-		if ((c = getc(0)) == '{') {
-			if ((c = collect(c, '}')) != '\0')
-				return(c);
-			goto pack;
-		}
-		break;
-
-	case '`':
-	case '\'':
-	case '"':
-		if ((c = collect(c, c)) != '\0')
-			return(c);
-		goto pack;
-
-	case '|':
-	case '&':
-	case ';':
-		if ((c1 = dual(c)) != '\0') {
-			startl = 1;
-			return(c1);
-		}
-		startl = 1;
-		return(c);
-	case '^':
-		startl = 1;
-		return('|');
-	case '>':
-	case '<':
-		diag(c);
-		return(c);
-
-	case '\n':
-		nlseen++;
-		gethere();
-		startl = 1;
-		if (multiline || cf & CONTIN) {
-			if (talking && e.iop <= iostack)
-				prs(cprompt->value);
-			if (cf & CONTIN)
-				goto loop;
-		}
-		return(c);
-
-	case '(':
-	case ')':
-		startl = 1;
-		return(c);
-	}
-
-	unget(c);
-
-pack:
-	while ((c = getc(0)) != 0 && !any(c, "`$ '\"\t;&<>()|^\n"))
-		if (e.linep >= elinep)
-			err("word too long");
-		else
-			*e.linep++ = c;
-	unget(c);
-	if(any(c, "\"'`$"))
-		goto loop;
-	*e.linep++ = '\0';
-	if (atstart && (c = rlookup(line))!=0) {
-		startl = 1;
-		return(c);
-	}
-	yylval.cp = strsave(line, areanum);
-	return(WORD);
-}
-
-int
-collect(c, c1)
-register c, c1;
-{
-	char s[2];
-
-	*e.linep++ = c;
-	while ((c = getc(c1)) != c1) {
-		if (c == 0) {
-			unget(c);
-			s[0] = c1;
-			s[1] = 0;
-			prs("no closing "); yyerror(s);
-			return(YYERRCODE);
-		}
-		if (talking && c == '\n' && e.iop <= iostack)
-			prs(cprompt->value);
-		*e.linep++ = c;
-	}
-	*e.linep++ = c;
-	return(0);
-}
-
-int
-dual(c)
-register c;
-{
-	char s[3];
-	register char *cp = s;
-
-	*cp++ = c;
-	*cp++ = getc(0);
-	*cp = 0;
-	if ((c = rlookup(s)) == 0)
-		unget(*--cp);
-	return(c);
-}
-
-static void
-diag(ec)
-register int ec;
-{
-	register int c;
-
-	c = getc(0);
-	if (c == '>' || c == '<') {
-		if (c != ec)
-			zzerr();
-		yylval.i = ec == '>'? IOWRITE|IOCAT: IOHERE;
-		c = getc(0);
-	} else
-		yylval.i = ec == '>'? IOWRITE: IOREAD;
-	if (c != '&' || yylval.i == IOHERE)
-		unget(c);
-	else
-		yylval.i |= IODUP;
-}
-
-static char *
-tree(size)
-unsigned size;
-{
-	register char *t;
-
-	if ((t = getcell(size)) == NULL) {
-		prs("command line too complicated\n");
-		fail();
-		/* NOTREACHED */
-	}
-	return(t);
-}
-
-/* VARARGS1 */
-/* ARGSUSED */
-void 
-printf(s)	/* yyparse calls it */
-char *s;
-{
-}
-
Index: trunk/minix/commands/sh/sh3.c
===================================================================
--- trunk/minix/commands/sh/sh3.c	(revision 9)
+++ 	(revision )
@@ -1,1147 +1,0 @@
-#define Extern extern
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <setjmp.h>
-#include <stddef.h>
-#include <time.h>
-#include <sys/times.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#undef NULL
-#include "sh.h"
-
-/* -------- exec.c -------- */
-/* #include "sh.h" */
-
-/*
- * execute tree
- */
-
-static	char	*signame[] = {
-	"Signal 0",
-	"Hangup",
-	(char *)NULL,	/* interrupt */
-	"Quit",
-	"Illegal instruction",
-	"Trace/BPT trap",
-	"Abort",
-	"EMT trap",
-	"Floating exception",
-	"Killed",
-	"Bus error",
-	"Memory fault",
-	"Bad system call",
-	(char *)NULL,	/* broken pipe */
-	"Alarm clock",
-	"Terminated",
-};
-#define	NSIGNAL (sizeof(signame)/sizeof(signame[0]))
-
-
-_PROTOTYPE(static int forkexec, (struct op *t, int *pin, int *pout, int act, char **wp, int *pforked ));
-_PROTOTYPE(static int parent, (void));
-_PROTOTYPE(int iosetup, (struct ioword *iop, int pipein, int pipeout ));
-_PROTOTYPE(static void echo, (char **wp ));
-_PROTOTYPE(static struct op **find1case, (struct op *t, char *w ));
-_PROTOTYPE(static struct op *findcase, (struct op *t, char *w ));
-_PROTOTYPE(static void brkset, (struct brkcon *bc ));
-_PROTOTYPE(int dolabel, (void));
-_PROTOTYPE(int dochdir, (struct op *t ));
-_PROTOTYPE(int doshift, (struct op *t ));
-_PROTOTYPE(int dologin, (struct op *t ));
-_PROTOTYPE(int doumask, (struct op *t ));
-_PROTOTYPE(int doexec, (struct op *t ));
-_PROTOTYPE(int dodot, (struct op *t ));
-_PROTOTYPE(int dowait, (struct op *t ));
-_PROTOTYPE(int doread, (struct op *t ));
-_PROTOTYPE(int doeval, (struct op *t ));
-_PROTOTYPE(int dotrap, (struct op *t ));
-_PROTOTYPE(int getsig, (char *s ));
-_PROTOTYPE(void setsig, (int n, void (*f)()));
-_PROTOTYPE(int getn, (char *as ));
-_PROTOTYPE(int dobreak, (struct op *t ));
-_PROTOTYPE(int docontinue, (struct op *t ));
-_PROTOTYPE(static int brkcontin, (char *cp, int val ));
-_PROTOTYPE(int doexit, (struct op *t ));
-_PROTOTYPE(int doexport, (struct op *t ));
-_PROTOTYPE(int doreadonly, (struct op *t ));
-_PROTOTYPE(static void rdexp, (char **wp, void (*f)(), int key));
-_PROTOTYPE(static void badid, (char *s ));
-_PROTOTYPE(int doset, (struct op *t ));
-_PROTOTYPE(void varput, (char *s, int out ));
-_PROTOTYPE(int dotimes, (void));
-
-int
-execute(t, pin, pout, act)
-register struct op *t;
-int *pin, *pout;
-int act;
-{
-	register struct op *t1;
-	int i, pv[2], rv, child, a;
-	char *cp, **wp, **wp2;
-	struct var *vp;
-	struct brkcon bc;
-
-	if (t == NULL)
-		return(0);
-	rv = 0;
-	a = areanum++;
-	wp = (wp2 = t->words) != NULL
-	     ? eval(wp2, t->type == TCOM ? DOALL : DOALL & ~DOKEY)
-	     : NULL;
-
-	switch(t->type) {
-	case TPAREN:
-	case TCOM:
-		rv = forkexec(t, pin, pout, act, wp, &child);
-		if (child) {
-			exstat = rv;
-			leave();
-		}
-		break;
-
-	case TPIPE:
-		if ((rv = openpipe(pv)) < 0)
-			break;
-		pv[0] = remap(pv[0]);
-		pv[1] = remap(pv[1]);
-		(void) execute(t->left, pin, pv, 0);
-		rv = execute(t->right, pv, pout, 0);
-		break;
-
-	case TLIST:
-		(void) execute(t->left, pin, pout, 0);
-		rv = execute(t->right, pin, pout, 0);
-		break;
-
-	case TASYNC:
-		i = parent();
-		if (i != 0) {
-			if (i != -1) {
-				setval(lookup("!"), putn(i));
-				if (pin != NULL)
-					closepipe(pin);
-				if (talking) {
-					prs(putn(i));
-					prs("\n");
-				}
-			} else
-				rv = -1;
-			setstatus(rv);
-		} else {
-			signal(SIGINT, SIG_IGN);
-			signal(SIGQUIT, SIG_IGN);
-			if (talking)
-				signal(SIGTERM, SIG_DFL);
-			talking = 0;
-			if (pin == NULL) {
-				close(0);
-				open("/dev/null", 0);
-			}
-			exit(execute(t->left, pin, pout, FEXEC));
-		}
-		break;
-
-	case TOR:
-	case TAND:
-		rv = execute(t->left, pin, pout, 0);
-		if ((t1 = t->right)!=NULL && (rv == 0) == (t->type == TAND))
-			rv = execute(t1, pin, pout, 0);
-		break;
-
-	case TFOR:
-		if (wp == NULL) {
-			wp = dolv+1;
-			if ((i = dolc) < 0)
-				i = 0;
-		} else {
-			i = -1;
-			while (*wp++ != NULL)
-				;			
-		}
-		vp = lookup(t->str);
-		while (setjmp(bc.brkpt))
-			if (isbreak)
-				goto broken;
-		brkset(&bc);
-		for (t1 = t->left; i-- && *wp != NULL;) {
-			setval(vp, *wp++);
-			rv = execute(t1, pin, pout, 0);
-		}
-		brklist = brklist->nextlev;
-		break;
-
-	case TWHILE:
-	case TUNTIL:
-		while (setjmp(bc.brkpt))
-			if (isbreak)
-				goto broken;
-		brkset(&bc);
-		t1 = t->left;
-		while ((execute(t1, pin, pout, 0) == 0) == (t->type == TWHILE))
-			rv = execute(t->right, pin, pout, 0);
-		brklist = brklist->nextlev;
-		break;
-
-	case TIF:
-	case TELIF:
-	 	if (t->right != NULL) {
-		rv = !execute(t->left, pin, pout, 0) ?
-			execute(t->right->left, pin, pout, 0):
-			execute(t->right->right, pin, pout, 0);
-		}
-		break;
-
-	case TCASE:
-		if ((cp = evalstr(t->str, DOSUB|DOTRIM)) == 0)
-			cp = "";
-		if ((t1 = findcase(t->left, cp)) != NULL)
-			rv = execute(t1, pin, pout, 0);
-		break;
-
-	case TBRACE:
-/*
-		if (iopp = t->ioact)
-			while (*iopp)
-				if (iosetup(*iopp++, pin!=NULL, pout!=NULL)) {
-					rv = -1;
-					break;
-				}
-*/
-		if (rv >= 0 && (t1 = t->left))
-			rv = execute(t1, pin, pout, 0);
-		break;
-	}
-
-broken:
-	t->words = wp2;
-	isbreak = 0;
-	freehere(areanum);
-	freearea(areanum);
-	areanum = a;
-	if (talking && intr) {
-		closeall();
-		fail();
-	}
-	if ((i = trapset) != 0) {
-		trapset = 0;
-		runtrap(i);
-	}
-	return(rv);
-}
-
-static int
-forkexec(t, pin, pout, act, wp, pforked)
-register struct op *t;
-int *pin, *pout;
-int act;
-char **wp;
-int *pforked;
-{
-	int i, rv, (*shcom)();
-	register int f;
-	char *cp;
-	struct ioword **iopp;
-	int resetsig;
-	char **owp;
-
-	owp = wp;
-	resetsig = 0;
-	*pforked = 0;
-	shcom = NULL;
-	rv = -1;	/* system-detected error */
-	if (t->type == TCOM) {
-		while ((cp = *wp++) != NULL)
-			;
-		cp = *wp;
-
-		/* strip all initial assignments */
-		/* not correct wrt PATH=yyy command  etc */
-		if (flag['x'])
-			echo (cp ? wp: owp);
-		if (cp == NULL && t->ioact == NULL) {
-			while ((cp = *owp++) != NULL && assign(cp, COPYV))
-				;
-			return(setstatus(0));
-		}
-		else if (cp != NULL)
-			shcom = inbuilt(cp);
-	}
-	t->words = wp;
-	f = act;
-	if (shcom == NULL && (f & FEXEC) == 0) {
-		i = parent();
-		if (i != 0) {
-			if (i == -1)
-				return(rv);
-			if (pin != NULL)
-				closepipe(pin);
-			return(pout==NULL? setstatus(waitfor(i,0)): 0);
-		}
-		if (talking) {
-			signal(SIGINT, SIG_IGN);
-			signal(SIGQUIT, SIG_IGN);
-			resetsig = 1;
-		}
-		talking = 0;
-		intr = 0;
-		(*pforked)++;
-		brklist = 0;
-		execflg = 0;
-	}
-	if (owp != NULL)
-		while ((cp = *owp++) != NULL && assign(cp, COPYV))
-			if (shcom == NULL)
-				export(lookup(cp));
-#ifdef COMPIPE
-	if ((pin != NULL || pout != NULL) && shcom != NULL && shcom != doexec) {
-		err("piping to/from shell builtins not yet done");
-		return(-1);
-	}
-#endif
-	if (pin != NULL) {
-		dup2(pin[0], 0);
-		closepipe(pin);
-	}
-	if (pout != NULL) {
-		dup2(pout[1], 1);
-		closepipe(pout);
-	}
-	if ((iopp = t->ioact) != NULL) {
-		if (shcom != NULL && shcom != doexec) {
-			prs(cp);
-			err(": cannot redirect shell command");
-			return(-1);
-		}
-		while (*iopp)
-			if (iosetup(*iopp++, pin!=NULL, pout!=NULL))
-				return(rv);
-	}
-	if (shcom)
-		return(setstatus((*shcom)(t)));
-	/* should use FIOCEXCL */
-	for (i=FDBASE; i<NOFILE; i++)
-		close(i);
-	if (resetsig) {
-		signal(SIGINT, SIG_DFL);
-		signal(SIGQUIT, SIG_DFL);
-	}
-	if (t->type == TPAREN)
-		exit(execute(t->left, NOPIPE, NOPIPE, FEXEC));
-	if (wp[0] == NULL)
-		exit(0);
-	cp = rexecve(wp[0], wp, makenv());
-	prs(wp[0]); prs(": "); warn(cp);
-	if (!execflg)
-		trap[0] = NULL;
-	leave();
-	/* NOTREACHED */
-}
-
-/*
- * common actions when creating a new child
- */
-static int
-parent()
-{
-	register int i;
-
-	i = fork();
-	if (i != 0) {
-		if (i == -1)
-			warn("try again");
-	}
-	return(i);
-}
-
-/*
- * 0< 1> are ignored as required
- * within pipelines.
- */
-int
-iosetup(iop, pipein, pipeout)
-register struct ioword *iop;
-int pipein, pipeout;
-{
-	register u;
-	char *cp, *msg;
-
-	if (iop->io_unit == IODEFAULT)	/* take default */
-		iop->io_unit = iop->io_flag&(IOREAD|IOHERE)? 0: 1;
-	if (pipein && iop->io_unit == 0)
-		return(0);
-	if (pipeout && iop->io_unit == 1)
-		return(0);
-	msg = iop->io_flag&(IOREAD|IOHERE)? "open": "create";
-	if ((iop->io_flag & IOHERE) == 0) {
-		cp = iop->io_name;
-		if ((cp = evalstr(cp, DOSUB|DOTRIM)) == NULL)
-			return(1);
-	}
-	if (iop->io_flag & IODUP) {
-		if (cp[1] || (!digit(*cp) && *cp != '-')) {
-			prs(cp);
-			err(": illegal >& argument");
-			return(1);
-		}
-		if (*cp == '-')
-			iop->io_flag = IOCLOSE;
-		iop->io_flag &= ~(IOREAD|IOWRITE);
-	}
-	switch (iop->io_flag) {
-	case IOREAD:
-		u = open(cp, 0);
-		break;
-
-	case IOHERE:
-	case IOHERE|IOXHERE:
-		u = herein(iop->io_name, iop->io_flag&IOXHERE);
-		cp = "here file ";
-		break;
-
-	case IOWRITE|IOCAT:
-		if ((u = open(cp, 1)) >= 0) {
-			lseek(u, (long)0, 2);
-			break;
-		}
-	case IOWRITE:
-		u = creat(cp, 0666);
-		break;
-
-	case IODUP:
-		u = dup2(*cp-'0', iop->io_unit);
-		break;
-
-	case IOCLOSE:
-		close(iop->io_unit);
-		return(0);
-	}
-	if (u < 0) {
-		int e=errno;
-		prs(cp);
-                if (iop->io_flag&IOHERE) prs(iop->io_name);
-		prs(": cannot ");
-	        prs(msg);
-	        prs(" (");
-	        prs(strerror(e));
-		warn(")");
-		return(1);
-	} else {
-		if (u != iop->io_unit) {
-			dup2(u, iop->io_unit);
-			close(u);
-		}
-	}
-	return(0);
-}
-
-static void
-echo(wp)
-register char **wp;
-{
-	register i;
-
-	prs("+");
-	for (i=0; wp[i]; i++) {
-		if (i)
-			prs(" ");
-		prs(wp[i]);
-	}
-	prs("\n");
-}
-
-static struct op **
-find1case(t, w)
-struct op *t;
-char *w;
-{
-	register struct op *t1;
-	struct op **tp;
-	register char **wp, *cp;
-
-	if (t == NULL)
-		return((struct op **)NULL);
-	if (t->type == TLIST) {
-		if ((tp = find1case(t->left, w)) != NULL)
-			return(tp);
-		t1 = t->right;	/* TPAT */
-	} else
-		t1 = t;
-	for (wp = t1->words; *wp;)
-		if ((cp = evalstr(*wp++, DOSUB)) && gmatch(w, cp))
-			return(&t1->left);
-	return((struct op **)NULL);
-}
-
-static struct op *
-findcase(t, w)
-struct op *t;
-char *w;
-{
-	register struct op **tp;
-
-	return((tp = find1case(t, w)) != NULL? *tp: (struct op *)NULL);
-}
-
-/*
- * Enter a new loop level (marked for break/continue).
- */
-static void
-brkset(bc)
-struct brkcon *bc;
-{
-	bc->nextlev = brklist;
-	brklist = bc;
-}
-
-/*
- * Wait for the last process created.
- * Print a message for each process found
- * that was killed by a signal.
- * Ignore interrupt signals while waiting
- * unless `canintr' is true.
- */
-int
-waitfor(lastpid, canintr)
-register int lastpid;
-int canintr;
-{
-	register int pid, rv;
-	int s;
-	int oheedint = heedint;
-
-	heedint = 0;
-	rv = 0;
-	do {
-		pid = wait(&s);
-		if (pid == -1) {
-			if (errno != EINTR || canintr)
-				break;
-		} else {
-			if ((rv = WAITSIG(s)) != 0) {
-				if (rv < NSIGNAL) {
-					if (signame[rv] != NULL) {
-						if (pid != lastpid) {
-							prn(pid);
-							prs(": ");
-						}
-						prs(signame[rv]);
-					}
-				} else {
-					if (pid != lastpid) {
-						prn(pid);
-						prs(": ");
-					}
-					prs("Signal "); prn(rv); prs(" ");
-				}
-				if (WAITCORE(s))
-					prs(" - core dumped");
-				if (rv >= NSIGNAL || signame[rv])
-					prs("\n");
-				rv = -1;
-			} else
-				rv = WAITVAL(s);
-		}
-	} while (pid != lastpid);
-	heedint = oheedint;
-	if (intr)
-		if (talking) {
-			if (canintr)
-				intr = 0;
-		} else {
-			if (exstat == 0) exstat = rv;
-			onintr(0);
-		}
-	return(rv);
-}
-
-int
-setstatus(s)
-register int s;
-{
-	exstat = s;
-	setval(lookup("?"), putn(s));
-	return(s);
-}
-
-/*
- * PATH-searching interface to execve.
- * If getenv("PATH") were kept up-to-date,
- * execvp might be used.
- */
-char *
-rexecve(c, v, envp)
-char *c, **v, **envp;
-{
-	register int i;
-	register char *sp, *tp;
-	int eacces = 0, asis = 0;
-
-	sp = any('/', c)? "": path->value;
-	asis = *sp == '\0';
-	while (asis || *sp != '\0') {
-		asis = 0;
-		tp = e.linep;
-		for (; *sp != '\0'; tp++)
-			if ((*tp = *sp++) == ':') {
-				asis = *sp == '\0';
-				break;
-			}
-		if (tp != e.linep)
-			*tp++ = '/';
-		for (i = 0; (*tp++ = c[i++]) != '\0';)
-			;
-		execve(e.linep, v, envp);
-		switch (errno) {
-		case ENOEXEC:
-			*v = e.linep;
-			tp = *--v;
-			*v = e.linep;
-			execve("/bin/sh", v, envp);
-			*v = tp;
-			return("no Shell");
-
-		case ENOMEM:
-			return("program too big");
-
-		case E2BIG:
-			return("argument list too long");
-
-		case EACCES:
-			eacces++;
-			break;
-		}
-	}
-	return(errno==ENOENT ? "not found" : "cannot execute");
-}
-
-/*
- * Run the command produced by generator `f'
- * applied to stream `arg'.
- */
-int
-run(argp, f)
-struct ioarg *argp;
-int (*f)();
-{
-	struct op *otree;
-	struct wdblock *swdlist;
-	struct wdblock *siolist;
-	jmp_buf ev, rt;
-	xint *ofail;
-	int rv;
-
-	areanum++;
-	swdlist = wdlist;
-	siolist = iolist;
-	otree = outtree;
-	ofail = failpt;
-	rv = -1;
-	if (newenv(setjmp(errpt = ev)) == 0) {
-		wdlist = 0;
-		iolist = 0;
-		pushio(argp, f);
-		e.iobase = e.iop;
-		yynerrs = 0;
-		if (setjmp(failpt = rt) == 0 && yyparse() == 0)
-			rv = execute(outtree, NOPIPE, NOPIPE, 0);
-		quitenv();
-	}
-	wdlist = swdlist;
-	iolist = siolist;
-	failpt = ofail;
-	outtree = otree;
-	freearea(areanum--);
-	return(rv);
-}
-
-/* -------- do.c -------- */
-/* #include "sh.h" */
-
-/*
- * built-in commands: doX
- */
-
-int
-dolabel()
-{
-	return(0);
-}
-
-int
-dochdir(t)
-register struct op *t;
-{
-	register char *cp, *er;
-
-	if ((cp = t->words[1]) == NULL && (cp = homedir->value) == NULL)
-		er = ": no home directory";
-	else if(chdir(cp) < 0)
-		er = ": bad directory";
-	else
-		return(0);
-	prs(cp != NULL? cp: "cd");
-	err(er);
-	return(1);
-}
-
-int
-doshift(t)
-register struct op *t;
-{
-	register n;
-
-	n = t->words[1]? getn(t->words[1]): 1;
-	if(dolc < n) {
-		err("nothing to shift");
-		return(1);
-	}
-	dolv[n] = dolv[0];
-	dolv += n;
-	dolc -= n;
-	setval(lookup("#"), putn(dolc));
-	return(0);
-}
-
-/*
- * execute login and newgrp directly
- */
-int
-dologin(t)
-struct op *t;
-{
-	register char *cp;
-
-	if (talking) {
-		signal(SIGINT, SIG_DFL);
-		signal(SIGQUIT, SIG_DFL);
-	}
-	cp = rexecve(t->words[0], t->words, makenv());
-	prs(t->words[0]); prs(": "); err(cp);
-	return(1);
-}
-
-int
-doumask(t)
-register struct op *t;
-{
-	register int i, n;
-	register char *cp;
-
-	if ((cp = t->words[1]) == NULL) {
-		i = umask(0);
-		umask(i);
-		for (n=3*4; (n-=3) >= 0;)
-			putc('0'+((i>>n)&07));
-		putc('\n');
-	} else {
-		for (n=0; *cp>='0' && *cp<='9'; cp++)
-			n = n*8 + (*cp-'0');
-		umask(n);
-	}
-	return(0);
-}
-
-int
-doexec(t)
-register struct op *t;
-{
-	register i;
-	jmp_buf ex;
-	xint *ofail;
-
-	t->ioact = NULL;
-	for(i = 0; (t->words[i]=t->words[i+1]) != NULL; i++)
-		;
-	if (i == 0)
-		return(1);
-	execflg = 1;
-	ofail = failpt;
-	if (setjmp(failpt = ex) == 0)
-		execute(t, NOPIPE, NOPIPE, FEXEC);
-	failpt = ofail;
-	execflg = 0;
-	return(1);
-}
-
-int
-dodot(t)
-struct op *t;
-{
-	register i;
-	register char *sp, *tp;
-	char *cp;
-
-	if ((cp = t->words[1]) == NULL)
-		return(0);
-	sp = any('/', cp)? ":": path->value;
-	while (*sp) {
-		tp = e.linep;
-		while (*sp && (*tp = *sp++) != ':')
-			tp++;
-		if (tp != e.linep)
-			*tp++ = '/';
-		for (i = 0; (*tp++ = cp[i++]) != '\0';)
-			;
-		if ((i = open(e.linep, 0)) >= 0) {
-			exstat = 0;
-			next(remap(i));
-			return(exstat);
-		}
-	}
-	prs(cp);
-	err(": not found");
-	return(-1);
-}
-
-int
-dowait(t)
-struct op *t;
-{
-	register i;
-	register char *cp;
-
-	if ((cp = t->words[1]) != NULL) {
-		i = getn(cp);
-		if (i == 0)
-			return(0);
-	} else
-		i = -1;
-	setstatus(waitfor(i, 1));
-	return(0);
-}
-
-int
-doread(t)
-struct op *t;
-{
-	register char *cp, **wp;
-	register nb;
-	register int  nl = 0;
-
-	if (t->words[1] == NULL) {
-		err("Usage: read name ...");
-		return(1);
-	}
-	for (wp = t->words+1; *wp; wp++) {
-		for (cp = e.linep; !nl && cp < elinep-1; cp++)
-			if ((nb = read(0, cp, sizeof(*cp))) != sizeof(*cp) ||
-			    (nl = (*cp == '\n')) ||
-			    (wp[1] && any(*cp, ifs->value)))
-				break;
-		*cp = 0;
-		if (nb <= 0)
-			break;
-		setval(lookup(*wp), e.linep);
-	}
-	return(nb <= 0);
-}
-
-int
-doeval(t)
-register struct op *t;
-{
-	return(RUN(awordlist, t->words+1, wdchar));
-}
-
-int
-dotrap(t)
-register struct op *t;
-{
-	register int  n, i;
-	register int  resetsig;
-
-	if (t->words[1] == NULL) {
-		for (i=0; i<=_NSIG; i++)
-			if (trap[i]) {
-				prn(i);
-				prs(": ");
-				prs(trap[i]);
-				prs("\n");
-			}
-		return(0);
-	}
-	resetsig = digit(*t->words[1]);
-	for (i = resetsig ? 1 : 2; t->words[i] != NULL; ++i) {
-		n = getsig(t->words[i]);
-		xfree(trap[n]);
-		trap[n] = 0;
-		if (!resetsig) {
-			if (*t->words[1] != '\0') {
-				trap[n] = strsave(t->words[1], 0);
-				setsig(n, sig);
-			} else
-				setsig(n, SIG_IGN);
-		} else {
-			if (talking)
-				if (n == SIGINT)
-					setsig(n, onintr);
-				else
-					setsig(n, n == SIGQUIT ? SIG_IGN 
-							       : SIG_DFL);
-			else
-				setsig(n, SIG_DFL);
-		}
-	}
-	return(0);
-}
-
-int
-getsig(s)
-char *s;
-{
-	register int n;
-
-	if ((n = getn(s)) < 0 || n > _NSIG) {
-		err("trap: bad signal number");
-		n = 0;
-	}
-	return(n);
-}
-
-void
-setsig(n, f)
-register n;
-_PROTOTYPE(void (*f), (int));
-{
-	if (n == 0)
-		return;
-	if (signal(n, SIG_IGN) != SIG_IGN || ourtrap[n]) {
-		ourtrap[n] = 1;
-		signal(n, f);
-	}
-}
-
-int
-getn(as)
-char *as;
-{
-	register char *s;
-	register n, m;
-
-	s = as;
-	m = 1;
-	if (*s == '-') {
-		m = -1;
-		s++;
-	}
-	for (n = 0; digit(*s); s++)
-		n = (n*10) + (*s-'0');
-	if (*s) {
-		prs(as);
-		err(": bad number");
-	}
-	return(n*m);
-}
-
-int
-dobreak(t)
-struct op *t;
-{
-	return(brkcontin(t->words[1], 1));
-}
-
-int
-docontinue(t)
-struct op *t;
-{
-	return(brkcontin(t->words[1], 0));
-}
-
-static int
-brkcontin(cp, val)
-register char *cp;
-int val;
-{
-	register struct brkcon *bc;
-	register nl;
-
-	nl = cp == NULL? 1: getn(cp);
-	if (nl <= 0)
-		nl = 999;
-	do {
-		if ((bc = brklist) == NULL)
-			break;
-		brklist = bc->nextlev;
-	} while (--nl);
-	if (nl) {
-		err("bad break/continue level");
-		return(1);
-	}
-	isbreak = val;
-	longjmp(bc->brkpt, 1);
-	/* NOTREACHED */
-}
-
-int
-doexit(t)
-struct op *t;
-{
-	register char *cp;
-
-	execflg = 0;
-	if ((cp = t->words[1]) != NULL)
-		setstatus(getn(cp));
-	leave();
-	/* NOTREACHED */
-}
-
-int
-doexport(t)
-struct op *t;
-{
-	rdexp(t->words+1, export, EXPORT);
-	return(0);
-}
-
-int
-doreadonly(t)
-struct op *t;
-{
-	rdexp(t->words+1, ronly, RONLY);
-	return(0);
-}
-
-static void
-rdexp(wp, f, key)
-register char **wp;
-void (*f)();
-int key;
-{
-	if (*wp != NULL) {
-		for (; *wp != NULL; wp++)
-			if (checkname(*wp))
-				(*f)(lookup(*wp));
-			else
-				badid(*wp);
-	} else
-		putvlist(key, 1);
-}
-
-static void
-badid(s)
-register char *s;
-{
-	prs(s);
-	err(": bad identifier");
-}
-
-int
-doset(t)
-register struct op *t;
-{
-	register struct var *vp;
-	register char *cp;
-	register n;
-
-	if ((cp = t->words[1]) == NULL) {
-		for (vp = vlist; vp; vp = vp->next)
-			varput(vp->name, 1);
-		return(0);
-	}
-	if (*cp == '-') {
-		/* bad: t->words++; */
-		for(n = 0; (t->words[n]=t->words[n+1]) != NULL; n++)
-			;
-		if (*++cp == 0)
-			flag['x'] = flag['v'] = 0;
-		else
-			for (; *cp; cp++)
-				switch (*cp) {
-				case 'e':
-					if (!talking)
-						flag['e']++;
-					break;
-
-				default:
-					if (*cp>='a' && *cp<='z')
-						flag[*cp]++;
-					break;
-				}
-		setdash();
-	}
-	if (t->words[1]) {
-		t->words[0] = dolv[0];
-		for (n=1; t->words[n]; n++)
-			setarea((char *)t->words[n], 0);
-		dolc = n-1;
-		dolv = t->words;
-		setval(lookup("#"), putn(dolc));
-		setarea((char *)(dolv-1), 0);
-	}
-	return(0);
-}
-
-void
-varput(s, out)
-register char *s;
-int out;
-{
-	if (letnum(*s)) {
-		write(out, s, strlen(s));
-		write(out, "\n", 1);
-	}
-}
-
-
-#define	SECS	60L
-#define	MINS	3600L
-
-int
-dotimes()
-{
-	struct tms tbuf;
-
-	times(&tbuf);
-
-	prn((int)(tbuf.tms_cutime / MINS));
-	prs("m");
-	prn((int)((tbuf.tms_cutime % MINS) / SECS));
-	prs("s ");
-	prn((int)(tbuf.tms_cstime / MINS));
-	prs("m");
-	prn((int)((tbuf.tms_cstime % MINS) / SECS));
-	prs("s\n");
-	return(0);
-}
-
-struct	builtin {
-	char	*command;
-	int	(*fn)();
-};
-static struct	builtin	builtin[] = {
-	":",		dolabel,
-	"cd",		dochdir,
-	"shift",	doshift,
-	"exec",		doexec,
-	"wait",		dowait,
-	"read",		doread,
-	"eval",		doeval,
-	"trap",		dotrap,
-	"break",	dobreak,
-	"continue",	docontinue,
-	"exit",		doexit,
-	"export",	doexport,
-	"readonly",	doreadonly,
-	"set",		doset,
-	".",		dodot,
-	"umask",	doumask,
-	"login",	dologin,
-	"newgrp",	dologin,
-	"times",	dotimes,
-	0,
-};
-
-int (*inbuilt(s))()
-register char *s;
-{
-	register struct builtin *bp;
-
-	for (bp = builtin; bp->command != NULL; bp++)
-		if (strcmp(bp->command, s) == 0)
-			return(bp->fn);
-	return((int(*)())NULL);
-}
-
Index: trunk/minix/commands/sh/sh4.c
===================================================================
--- trunk/minix/commands/sh/sh4.c	(revision 9)
+++ 	(revision )
@@ -1,779 +1,0 @@
-#define Extern extern
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/dir.h>
-#include <limits.h>
-#include <signal.h>
-#include <errno.h>
-#include <setjmp.h>
-#include "sh.h"
-
-/* -------- eval.c -------- */
-/* #include "sh.h" */
-/* #include "word.h" */
-
-/*
- * ${}
- * `command`
- * blank interpretation
- * quoting
- * glob
- */
-
-_PROTOTYPE(static int expand, (char *cp, struct wdblock **wbp, int f ));
-_PROTOTYPE(static char *blank, (int f ));
-_PROTOTYPE(static int dollar, (int quoted ));
-_PROTOTYPE(static int grave, (int quoted ));
-_PROTOTYPE(void globname, (char *we, char *pp ));
-_PROTOTYPE(static char *generate, (char *start1, char *end1, char *middle, char *end ));
-_PROTOTYPE(static int anyspcl, (struct wdblock *wb ));
-_PROTOTYPE(static int xstrcmp, (char *p1, char *p2 ));
-_PROTOTYPE(void glob0, (char *a0, unsigned int a1, int a2, int (*a3)(char *, char *)));
-_PROTOTYPE(void glob1, (char *base, char *lim ));
-_PROTOTYPE(void glob2, (char *i, char *j ));
-_PROTOTYPE(void glob3, (char *i, char *j, char *k ));
-_PROTOTYPE(char *memcopy, (char *ato, char *from, int nb ));
-
-char **
-eval(ap, f)
-register char **ap;
-int f;
-{
-	struct wdblock *wb;
-	char **wp;
-	char **wf;
-	jmp_buf ev;
-
-	wp = NULL;
-	wb = NULL;
-	wf = NULL;
-	if (newenv(setjmp(errpt = ev)) == 0) {
-		while (*ap && isassign(*ap))
-			expand(*ap++, &wb, f & ~DOGLOB);
-		if (flag['k']) {
-			for (wf = ap; *wf; wf++) {
-				if (isassign(*wf))
-					expand(*wf, &wb, f & ~DOGLOB);
-			}
-		}
-		for (wb = addword((char *)0, wb); *ap; ap++) {
-			if (!flag['k'] || !isassign(*ap))
-				expand(*ap, &wb, f & ~DOKEY);
-		}
-		wb = addword((char *)0, wb);
-		wp = getwords(wb);
-		quitenv();
-	} else
-		gflg = 1;
-	return(gflg? (char **)NULL: wp);
-}
-
-/*
- * Make the exported environment from the exported
- * names in the dictionary. Keyword assignments
- * will already have been done.
- */
-char **
-makenv()
-
-{
-	register struct wdblock *wb;
-	register struct var *vp;
-
-	wb = NULL;
-	for (vp = vlist; vp; vp = vp->next)
-		if (vp->status & EXPORT)
-			wb = addword(vp->name, wb);
-	wb = addword((char *)0, wb);
-	return(getwords(wb));
-}
-
-char *
-evalstr(cp, f)
-register char *cp;
-int f;
-{
-	struct wdblock *wb;
-
-	wb = NULL;
-	if (expand(cp, &wb, f)) {
-		if (wb == NULL || wb->w_nword == 0 || (cp = wb->w_words[0]) == NULL)
-			cp = "";
-		DELETE(wb);
-	} else
-		cp = NULL;
-	return(cp);
-}
-
-static int
-expand(cp, wbp, f)
-register char *cp;
-register struct wdblock **wbp;
-int f;
-{
-	jmp_buf ev;
-
-	gflg = 0;
-	if (cp == NULL)
-		return(0);
-	if (!anys("$`'\"", cp) &&
-	    !anys(ifs->value, cp) &&
-	    ((f&DOGLOB)==0 || !anys("[*?", cp))) {
-		cp = strsave(cp, areanum);
-		if (f & DOTRIM)
-			unquote(cp);
-		*wbp = addword(cp, *wbp);
-		return(1);
-	}
-	if (newenv(setjmp(errpt = ev)) == 0) {
-		PUSHIO(aword, cp, strchar);
-		e.iobase = e.iop;
-		while ((cp = blank(f)) && gflg == 0) {
-			e.linep = cp;
-			cp = strsave(cp, areanum);
-			if ((f&DOGLOB) == 0) {
-				if (f & DOTRIM)
-					unquote(cp);
-				*wbp = addword(cp, *wbp);
-			} else
-				*wbp = glob(cp, *wbp);
-		}
-		quitenv();
-	} else
-		gflg = 1;
-	return(gflg == 0);
-}
-
-/*
- * Blank interpretation and quoting
- */
-static char *
-blank(f)
-int f;
-{
-	register c, c1;
-	register char *sp;
-	int scanequals, foundequals;
-
-	sp = e.linep;
-	scanequals = f & DOKEY;
-	foundequals = 0;
-
-loop:
-	switch (c = subgetc('"', foundequals)) {
-	case 0:
-		if (sp == e.linep)
-			return(0);
-		*e.linep++ = 0;
-		return(sp);
-
-	default:
-		if (f & DOBLANK && any(c, ifs->value))
-			goto loop;
-		break;
-
-	case '"':
-	case '\'':
-		scanequals = 0;
-		if (INSUB())
-			break;
-		for (c1 = c; (c = subgetc(c1, 1)) != c1;) {
-			if (c == 0)
-				break;
-			if (c == '\'' || !any(c, "$`\""))
-				c |= QUOTE;
-			*e.linep++ = c;
-		}
-		c = 0;
-	}
-	unget(c);
-	if (!letter(c))
-		scanequals = 0;
-	for (;;) {
-		c = subgetc('"', foundequals);
-		if (c == 0 ||
-		    (f & DOBLANK && any(c, ifs->value)) ||
-		    (!INSUB() && any(c, "\"'"))) {
-		        scanequals = 0;
-			unget(c);
-			if (any(c, "\"'"))
-				goto loop;
-			break;
-		}
-		if (scanequals)
-			if (c == '=') {
-				foundequals = 1;
-				scanequals  = 0;
-			}
-			else if (!letnum(c))
-				scanequals = 0;
-		*e.linep++ = c;
-	}
-	*e.linep++ = 0;
-	return(sp);
-}
-
-/*
- * Get characters, substituting for ` and $
- */
-int
-subgetc(ec, quoted)
-register char ec;
-int quoted;
-{
-	register char c;
-
-again:
-	c = getc(ec);
-	if (!INSUB() && ec != '\'') {
-		if (c == '`') {
-			if (grave(quoted) == 0)
-				return(0);
-			e.iop->task = XGRAVE;
-			goto again;
-		}
-		if (c == '$' && (c = dollar(quoted)) == 0) {
-			e.iop->task = XDOLL;
-			goto again;
-		}
-	}
-	return(c);
-}
-
-/*
- * Prepare to generate the string returned by ${} substitution.
- */
-static int
-dollar(quoted)
-int quoted;
-{
-	int otask;
-	struct io *oiop;
-	char *dolp;
-	register char *s, c, *cp;
-	struct var *vp;
-
-	c = readc();
-	s = e.linep;
-	if (c != '{') {
-		*e.linep++ = c;
-		if (letter(c)) {
-			while ((c = readc())!=0 && letnum(c))
-				if (e.linep < elinep)
-					*e.linep++ = c;
-			unget(c);
-		}
-		c = 0;
-	} else {
-		oiop = e.iop;
-		otask = e.iop->task;
-		e.iop->task = XOTHER;
-		while ((c = subgetc('"', 0))!=0 && c!='}' && c!='\n')
-			if (e.linep < elinep)
-				*e.linep++ = c;
-		if (oiop == e.iop)
-			e.iop->task = otask;
-		if (c != '}') {
-			err("unclosed ${");
-			gflg++;
-			return(c);
-		}
-	}
-	if (e.linep >= elinep) {
-		err("string in ${} too long");
-		gflg++;
-		e.linep -= 10;
-	}
-	*e.linep = 0;
-	if (*s)
-		for (cp = s+1; *cp; cp++)
-			if (any(*cp, "=-+?")) {
-				c = *cp;
-				*cp++ = 0;
-				break;
-			}
-	if (s[1] == 0 && (*s == '*' || *s == '@')) {
-		if (dolc > 1) {
-			/* currently this does not distinguish $* and $@ */
-			/* should check dollar */
-			e.linep = s;
-			PUSHIO(awordlist, dolv+1, dolchar);
-			return(0);
-		} else {	/* trap the nasty ${=} */
-			s[0] = '1';
-			s[1] = 0;
-		}
-	}
-	e.linep = s;
-	vp = lookup(s);
-	if ((dolp = vp->value) == null) {
-		switch (c) {
-		case '=':
-			if (digit(*s)) {
-				err("cannot use ${...=...} with $n");
-				gflg++;
-				break;
-			}
-			cp = evalstr(strsave(cp, areanum),DOSUB);
-			setval(vp, cp);
-			dolp = vp->value;
-			break;
-
-		case '-':
-			dolp = evalstr(strsave(cp, areanum),DOSUB);
-			break;
-
-		case '?':
-			if (*cp == 0) {
-				prs("missing value for ");
-				err(s);
-			} else
-			        err(evalstr(strsave(cp, areanum),DOSUB));
-			gflg++;
-			break;
-		}
-	} else if (c == '+') {
-		dolp = evalstr(strsave(cp, areanum),DOSUB);
-	}
-	if (flag['u'] && dolp == null) {
-		prs("unset variable: ");
-		err(s);
-		gflg++;
-	}
-	PUSHIO(aword, dolp, quoted ? qstrchar : strchar);
-	return(0);
-}
-
-/*
- * Run the command in `...` and read its output.
- */
-static int
-grave(quoted)
-int quoted;
-{
-        int otask;
-        struct io *oiop;
-	register char *cp,*s;
-	register int i,c;
-	int pf[2];
-
-	c = readc();
-        s = e.linep;
-        *e.linep++ = c;
-	oiop = e.iop;
-	otask = e.iop->task;
-	e.iop->task = XOTHER;
-	while ((c = subgetc('\'', 0))!=0 && c!='`')
-		if (e.linep < elinep)
-			*e.linep++ = c;
-	if (oiop == e.iop)
-		e.iop->task = otask;
-	if (c != '`') {
-		err("no closing `");
-		return(0);
-	}
-	if (openpipe(pf) < 0)
-		return(0);
-	if ((i = fork()) == -1) {
-		closepipe(pf);
-		err("try again");
-		return(0);
-	}
-	if (i != 0) {
-		e.linep = s;
-		close(pf[1]);
-		PUSHIO(afile, remap(pf[0]), quoted? qgravechar: gravechar);
-		return(1);
-	}
-	*e.linep = 0;
-	/* allow trapped signals */
-	for (i=0; i<=_NSIG; i++)
-		if (ourtrap[i] && signal(i, SIG_IGN) != SIG_IGN)
-			signal(i, SIG_DFL);
-	dup2(pf[1], 1);
-	closepipe(pf);
-	flag['e'] = 0;
-	flag['v'] = 0;
-	flag['n'] = 0;
-	cp = strsave(e.linep = s, 0);
-	areanum = 1;
-	inithere();
-	freearea(areanum);	/* free old space */
-	e.oenv = NULL;
-	e.iop = (e.iobase = iostack) - 1;
-	unquote(cp);
-	talking = 0;
-	PUSHIO(aword, cp, nlchar);
-	onecommand();
-	exit(1);
-}
-
-char *
-unquote(as)
-register char *as;
-{
-	register char *s;
-
-	if ((s = as) != NULL)
-		while (*s)
-			*s++ &= ~QUOTE;
-	return(as);
-}
-
-/* -------- glob.c -------- */
-/* #include "sh.h" */
-
-/*
- * glob
- */
-
-#define	scopy(x) strsave((x), areanum)
-#define	BLKSIZ	512
-#define	NDENT	((BLKSIZ+sizeof(struct direct)-1)/sizeof(struct direct))
-
-static	struct wdblock	*cl, *nl;
-static	char	spcl[] = "[?*";
-
-struct wdblock *
-glob(cp, wb)
-char *cp;
-struct wdblock *wb;
-{
-	register i;
-	register char *pp;
-
-	if (cp == 0)
-		return(wb);
-	i = 0;
-	for (pp = cp; *pp; pp++)
-		if (any(*pp, spcl))
-			i++;
-		else if (!any(*pp & ~QUOTE, spcl))
-			*pp &= ~QUOTE;
-	if (i != 0) {
-		for (cl = addword(scopy(cp), (struct wdblock *)0); anyspcl(cl); cl = nl) {
-			nl = newword(cl->w_nword*2);
-			for(i=0; i<cl->w_nword; i++) { /* for each argument */
-				for (pp = cl->w_words[i]; *pp; pp++)
-					if (any(*pp, spcl)) {
-						globname(cl->w_words[i], pp);
-						break;
-					}
-				if (*pp == '\0')
-					nl = addword(scopy(cl->w_words[i]), nl);
-			}
-			for(i=0; i<cl->w_nword; i++)
-				DELETE(cl->w_words[i]);
-			DELETE(cl);
-		}
-		for(i=0; i<cl->w_nword; i++)
-			unquote(cl->w_words[i]);
-		glob0((char *)cl->w_words, cl->w_nword, sizeof(char *), xstrcmp);
-		if (cl->w_nword) {
-			for (i=0; i<cl->w_nword; i++)
-				wb = addword(cl->w_words[i], wb);
-			DELETE(cl);
-			return(wb);
-		}
-	}
-	wb = addword(unquote(cp), wb);
-	return(wb);
-}
-
-void
-globname(we, pp)
-char *we;
-register char *pp;
-{
-	register char *np, *cp;
-	char *name, *gp, *dp;
-	int dn, j, n, k;
-	struct direct ent[NDENT];
-	char dname[NAME_MAX+1];
-	struct stat dbuf;
-
-	for (np = we; np != pp; pp--)
-		if (pp[-1] == '/')
-			break;
-	for (dp = cp = space((int)(pp-np)+3); np < pp;)
-		*cp++ = *np++;
-	*cp++ = '.';
-	*cp = '\0';
-	for (gp = cp = space(strlen(pp)+1); *np && *np != '/';)
-		*cp++ = *np++;
-	*cp = '\0';
-	dn = open(dp, 0);
-	if (dn < 0) {
-		DELETE(dp);
-		DELETE(gp);
-		return;
-	}
-	dname[NAME_MAX] = '\0';
-	while ((n = read(dn, (char *)ent, sizeof(ent))) >= sizeof(*ent)) {
-		n /= sizeof(*ent);
-		for (j=0; j<n; j++) {
-			if (ent[j].d_ino == 0)
-				continue;
-			strncpy(dname, ent[j].d_name, NAME_MAX);
-			if (dname[0] == '.')
-				if (*gp != '.')
-					continue;
-			for(k=0; k<NAME_MAX; k++)
-				if (any(dname[k], spcl))
-					dname[k] |= QUOTE;
-			if (gmatch(dname, gp)) {
-				name = generate(we, pp, dname, np);
-				if (*np && !anys(np, spcl)) {
-					if (stat(name,&dbuf)) {
-						DELETE(name);
-						continue;
-					}
-				}
-				nl = addword(name, nl);
-			}
-		}
-	}
-	close(dn);
-	DELETE(dp);
-	DELETE(gp);
-}
-
-/*
- * generate a pathname as below.
- * start..end1 / middle end
- * the slashes come for free
- */
-static char *
-generate(start1, end1, middle, end)
-char *start1;
-register char *end1;
-char *middle, *end;
-{
-	char *p;
-	register char *op, *xp;
-
-	p = op = space((int)(end1-start1)+strlen(middle)+strlen(end)+2);
-	for (xp = start1; xp != end1;)
-		*op++ = *xp++;
-	for (xp = middle; (*op++ = *xp++) != '\0';)
-		;
-	op--;
-	for (xp = end; (*op++ = *xp++) != '\0';)
-		;
-	return(p);
-}
-
-static int
-anyspcl(wb)
-register struct wdblock *wb;
-{
-	register i;
-	register char **wd;
-
-	wd = wb->w_words;
-	for (i=0; i<wb->w_nword; i++)
-		if (anys(spcl, *wd++))
-			return(1);
-	return(0);
-}
-
-static int
-xstrcmp(p1, p2)
-char *p1, *p2;
-{
-	return(strcmp(*(char **)p1, *(char **)p2));
-}
-
-/* -------- word.c -------- */
-/* #include "sh.h" */
-/* #include "word.h" */
-
-#define	NSTART	16	/* default number of words to allow for initially */
-
-struct wdblock *
-newword(nw)
-register int nw;
-{
-	register struct wdblock *wb;
-
-	wb = (struct wdblock *) space(sizeof(*wb) + nw*sizeof(char *));
-	wb->w_bsize = nw;
-	wb->w_nword = 0;
-	return(wb);
-}
-
-struct wdblock *
-addword(wd, wb)
-char *wd;
-register struct wdblock *wb;
-{
-	register struct wdblock *wb2;
-	register nw;
-
-	if (wb == NULL)
-		wb = newword(NSTART);
-	if ((nw = wb->w_nword) >= wb->w_bsize) {
-		wb2 = newword(nw * 2);
-		memcopy((char *)wb2->w_words, (char *)wb->w_words, nw*sizeof(char *));
-		wb2->w_nword = nw;
-		DELETE(wb);
-		wb = wb2;
-	}
-	wb->w_words[wb->w_nword++] = wd;
-	return(wb);
-}
-
-char **
-getwords(wb)
-register struct wdblock *wb;
-{
-	register char **wd;
-	register nb;
-
-	if (wb == NULL)
-		return((char **)NULL);
-	if (wb->w_nword == 0) {
-		DELETE(wb);
-		return((char **)NULL);
-	}
-	wd = (char **) space(nb = sizeof(*wd) * wb->w_nword);
-	memcopy((char *)wd, (char *)wb->w_words, nb);
-	DELETE(wb);	/* perhaps should done by caller */
-	return(wd);
-}
-
-_PROTOTYPE(int (*func), (char *, char *));
-int	globv;
-
-void
-glob0(a0, a1, a2, a3)
-char *a0;
-unsigned a1;
-int a2;
-_PROTOTYPE(int (*a3), (char *, char *));
-{
-	func = a3;
-	globv = a2;
-	glob1(a0, a0 + a1 * a2);
-}
-
-void
-glob1(base, lim)
-char *base, *lim;
-{
-	register char *i, *j;
-	int v2;
-	char *lptr, *hptr;
-	int c;
-	unsigned n;
-
-
-	v2 = globv;
-
-top:
-	if ((n=(int)(lim-base)) <= v2)
-		return;
-	n = v2 * (n / (2*v2));
-	hptr = lptr = base+n;
-	i = base;
-	j = lim-v2;
-	for(;;) {
-		if (i < lptr) {
-			if ((c = (*func)(i, lptr)) == 0) {
-				glob2(i, lptr -= v2);
-				continue;
-			}
-			if (c < 0) {
-				i += v2;
-				continue;
-			}
-		}
-
-begin:
-		if (j > hptr) {
-			if ((c = (*func)(hptr, j)) == 0) {
-				glob2(hptr += v2, j);
-				goto begin;
-			}
-			if (c > 0) {
-				if (i == lptr) {
-					glob3(i, hptr += v2, j);
-					i = lptr += v2;
-					goto begin;
-				}
-				glob2(i, j);
-				j -= v2;
-				i += v2;
-				continue;
-			}
-			j -= v2;
-			goto begin;
-		}
-
-
-		if (i == lptr) {
-			if (lptr-base >= lim-hptr) {
-				glob1(hptr+v2, lim);
-				lim = lptr;
-			} else {
-				glob1(base, lptr);
-				base = hptr+v2;
-			}
-			goto top;
-		}
-
-
-		glob3(j, lptr -= v2, i);
-		j = hptr -= v2;
-	}
-}
-
-void
-glob2(i, j)
-char *i, *j;
-{
-	register char *index1, *index2, c;
-	int m;
-
-	m = globv;
-	index1 = i;
-	index2 = j;
-	do {
-		c = *index1;
-		*index1++ = *index2;
-		*index2++ = c;
-	} while(--m);
-}
-
-void
-glob3(i, j, k)
-char *i, *j, *k;
-{
-	register char *index1, *index2, *index3;
-	int c;
-	int m;
-
-	m = globv;
-	index1 = i;
-	index2 = j;
-	index3 = k;
-	do {
-		c = *index1;
-		*index1++ = *index3;
-		*index3++ = *index2;
-		*index2++ = c;
-	} while(--m);
-}
-
-char *
-memcopy(ato, from, nb)
-register char *ato, *from;
-register int nb;
-{
-	register char *to;
-
-	to = ato;
-	while (--nb >= 0)
-		*to++ = *from++;
-	return(ato);
-}
Index: trunk/minix/commands/sh/sh5.c
===================================================================
--- trunk/minix/commands/sh/sh5.c	(revision 9)
+++ 	(revision )
@@ -1,681 +1,0 @@
-#define Extern extern
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <setjmp.h>
-#include "sh.h"
-
-/* -------- io.c -------- */
-/* #include "sh.h" */
-
-/*
- * shell IO
- */
-
-static struct iobuf sharedbuf = {AFID_NOBUF};
-static struct iobuf mainbuf = {AFID_NOBUF};
-static unsigned bufid = AFID_ID;	/* buffer id counter */
-
-struct ioarg temparg = {0, 0, 0, AFID_NOBUF, 0};
-
-_PROTOTYPE(static void readhere, (char **name, char *s, int ec ));
-_PROTOTYPE(void pushio, (struct ioarg *argp, int (*fn)()));
-_PROTOTYPE(static int xxchar, (struct ioarg *ap ));
-_PROTOTYPE(void tempname, (char *tname ));
-
-int
-getc(ec)
-register int ec;
-{
-	register int c;
-
-	if(e.linep > elinep) {
-		while((c=readc()) != '\n' && c)
-			;
-		err("input line too long");
-		gflg++;
-		return(c);
-	}
-	c = readc();
- 	if (ec != '\'' && e.iop->task != XGRAVE) {
-		if(c == '\\') {
-			c = readc();
-			if (c == '\n' && ec != '\"')
-				return(getc(ec));
-			c |= QUOTE;
-		}
-	}
-	return(c);
-}
-
-void
-unget(c)
-int c;
-{
-	if (e.iop >= e.iobase)
-		e.iop->peekc = c;
-}
-
-int
-eofc()
-
-{
-  return e.iop < e.iobase || (e.iop->peekc == 0 && e.iop->prev == 0);
-}
-
-int
-readc()
-{
-	register c;
-
-	for (; e.iop >= e.iobase; e.iop--)
-		if ((c = e.iop->peekc) != '\0') {
-			e.iop->peekc = 0;
-			return(c);
-		}
-		else {
-		    if (e.iop->prev != 0) {
-		        if ((c = (*e.iop->iofn)(e.iop->argp, e.iop)) != '\0') {
-			        if (c == -1) {
-				        e.iop++;
-				        continue;
-			        }
-			        if (e.iop == iostack)
-				        ioecho(c);
-			        return(e.iop->prev = c);
-		        }
-		        else if (e.iop->task == XIO && e.iop->prev != '\n') {
-			        e.iop->prev = 0;
-				if (e.iop == iostack)
-					ioecho('\n');
-			        return '\n';
-		        }
-		    }
-		    if (e.iop->task == XIO) {
-			if (multiline)
-			    return e.iop->prev = 0;
-			if (talking && e.iop == iostack+1)
-			    prs(prompt->value);
-		    }
-		}
-	if (e.iop >= iostack)
-		return(0);
-	leave();
-	/* NOTREACHED */
-}
-
-void
-ioecho(c)
-char c;
-{
-	if (flag['v'])
-		write(2, &c, sizeof c);
-}
-
-void
-pushio(argp, fn)
-struct ioarg *argp;
-int (*fn)();
-{
-	if (++e.iop >= &iostack[NPUSH]) {
-		e.iop--;
-		err("Shell input nested too deeply");
-		gflg++;
-		return;
-	}
-	e.iop->iofn = fn;
-
-	if (argp->afid != AFID_NOBUF)
-	  e.iop->argp = argp;
-	else {
-	  e.iop->argp  = ioargstack + (e.iop - iostack);
-	  *e.iop->argp = *argp;
-	  e.iop->argp->afbuf = e.iop == &iostack[0] ? &mainbuf : &sharedbuf;
-	  if (isatty(e.iop->argp->afile) == 0 &&
-	      (e.iop == &iostack[0] ||
-	       lseek(e.iop->argp->afile, 0L, 1) != -1)) {
-	    if (++bufid == AFID_NOBUF)
-	      bufid = AFID_ID;
-	    e.iop->argp->afid  = bufid;
-	  }
-	}
-
-	e.iop->prev  = ~'\n';
-	e.iop->peekc = 0;
-	e.iop->xchar = 0;
-	e.iop->nlcount = 0;
-	if (fn == filechar || fn == linechar)
-		e.iop->task = XIO;
-	else if (fn == gravechar || fn == qgravechar)
-		e.iop->task = XGRAVE;
-	else
-		e.iop->task = XOTHER;
-}
-
-struct io *
-setbase(ip)
-struct io *ip;
-{
-	register struct io *xp;
-
-	xp = e.iobase;
-	e.iobase = ip;
-	return(xp);
-}
-
-/*
- * Input generating functions
- */
-
-/*
- * Produce the characters of a string, then a newline, then EOF.
- */
-int
-nlchar(ap)
-register struct ioarg *ap;
-{
-	register int c;
-
-	if (ap->aword == NULL)
-		return(0);
-	if ((c = *ap->aword++) == 0) {
-		ap->aword = NULL;
-		return('\n');
-	}
-	return(c);
-}
-
-/*
- * Given a list of words, produce the characters
- * in them, with a space after each word.
- */
-int
-wdchar(ap)
-register struct ioarg *ap;
-{
-	register char c;
-	register char **wl;
-
-	if ((wl = ap->awordlist) == NULL)
-		return(0);
-	if (*wl != NULL) {
-		if ((c = *(*wl)++) != 0)
-			return(c & 0177);
-		ap->awordlist++;
-		return(' ');
-	}
-	ap->awordlist = NULL;
-	return('\n');
-}
-
-/*
- * Return the characters of a list of words,
- * producing a space between them.
- */
-int
-dolchar(ap)
-register struct ioarg *ap;
-{
-	register char *wp;
-
-	if ((wp = *ap->awordlist++) != NULL) {
-		PUSHIO(aword, wp, *ap->awordlist == NULL? strchar: xxchar);
-		return(-1);
-	}
-	return(0);
-}
-
-static int
-xxchar(ap)
-register struct ioarg *ap;
-{
-	register int c;
-
-	if (ap->aword == NULL)
-		return(0);
-	if ((c = *ap->aword++) == '\0') {
-		ap->aword = NULL;
-		return(' ');
-	}
-	return(c);
-}
-
-/*
- * Produce the characters from a single word (string).
- */
-int
-strchar(ap)
-register struct ioarg *ap;
-{
-	register int c;
-
-	if (ap->aword == NULL || (c = *ap->aword++) == 0)
-		return(0);
-	return(c);
-}
-
-/*
- * Produce quoted characters from a single word (string).
- */
-int
-qstrchar(ap)
-register struct ioarg *ap;
-{
-	register int c;
-
-	if (ap->aword == NULL || (c = *ap->aword++) == 0)
-		return(0);
-	return(c|QUOTE);
-}
-
-/*
- * Return the characters from a file.
- */
-int
-filechar(ap)
-register struct ioarg *ap;
-{
-	register int i;
-	char c;
-	struct iobuf *bp = ap->afbuf;
-
-	if (ap->afid != AFID_NOBUF) {
-	  if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) {
-	    if (i)
-	      lseek(ap->afile, ap->afpos, 0);
-	    do {
-	      i = read(ap->afile, bp->buf, sizeof(bp->buf));
-	    } while (i < 0 && errno == EINTR);
-	    if (i <= 0) {
-	      closef(ap->afile);
-	      return 0;
-	    }
-	    bp->id = ap->afid;
-	    bp->ebufp = (bp->bufp  = bp->buf) + i;
-	  }
-	  ap->afpos++;
-	  return *bp->bufp++ & 0177;
-	}
-
-	do {
-		i = read(ap->afile, &c, sizeof(c));
-	} while (i < 0 && errno == EINTR);
-	return(i == sizeof(c)? c&0177: (closef(ap->afile), 0));
-}
-
-/*
- * Return the characters from a here temp file.
- */
-int
-herechar(ap)
-register struct ioarg *ap;
-{
-	char c;
-
-
-	if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) {
-		close(ap->afile);
-		c = 0;
-	}
-	return (c);
-
-}
-
-/*
- * Return the characters produced by a process (`...`).
- * Quote them if required, and remove any trailing newline characters.
- */
-int
-gravechar(ap, iop)
-struct ioarg *ap;
-struct io *iop;
-{
-	register int c;
-
-	if ((c = qgravechar(ap, iop)&~QUOTE) == '\n')
-		c = ' ';
-	return(c);
-}
-
-int
-qgravechar(ap, iop)
-register struct ioarg *ap;
-struct io *iop;
-{
-	register int c;
-
-	if (iop->xchar) {
-		if (iop->nlcount) {
-			iop->nlcount--;
-			return('\n'|QUOTE);
-		}
-		c = iop->xchar;
-		iop->xchar = 0;
-	} else if ((c = filechar(ap)) == '\n') {
-		iop->nlcount = 1;
-		while ((c = filechar(ap)) == '\n')
-			iop->nlcount++;
-		iop->xchar = c;
-		if (c == 0)
-			return(c);
-		iop->nlcount--;
-		c = '\n';
-	}
-	return(c!=0? c|QUOTE: 0);
-}
-
-/*
- * Return a single command (usually the first line) from a file.
- */
-int
-linechar(ap)
-register struct ioarg *ap;
-{
-	register int c;
-
-	if ((c = filechar(ap)) == '\n') {
-		if (!multiline) {
-			closef(ap->afile);
-			ap->afile = -1;	/* illegal value */
-		}
-	}
-	return(c);
-}
-
-void
-prs(s)
-register char *s;
-{
-	if (*s)
-		write(2, s, strlen(s));
-}
-
-void
-putc(c)
-char c;
-{
-	write(2, &c, sizeof c);
-}
-
-void
-prn(u)
-unsigned u;
-{
-	prs(itoa(u, 0));
-}
-
-void
-closef(i)
-register int i;
-{
-	if (i > 2)
-		close(i);
-}
-
-void
-closeall()
-{
-	register u;
-
-	for (u=NUFILE; u<NOFILE;)
-		close(u++);
-}
-
-/*
- * remap fd into Shell's fd space
- */
-int
-remap(fd)
-register int fd;
-{
-	register int i;
-	int map[NOFILE];
-
-	if (fd < e.iofd) {
-		for (i=0; i<NOFILE; i++)
-			map[i] = 0;
-		do {
-			map[fd] = 1;
-			fd = dup(fd);
-		} while (fd >= 0 && fd < e.iofd);
-		for (i=0; i<NOFILE; i++)
-			if (map[i])
-				close(i);
-		if (fd < 0)
-			err("too many files open in shell");
-	}
-	return(fd);
-}
-
-int
-openpipe(pv)
-register int *pv;
-{
-	register int i;
-
-	if ((i = pipe(pv)) < 0)
-		err("can't create pipe - try again");
-	return(i);
-}
-
-void
-closepipe(pv)
-register int *pv;
-{
-	if (pv != NULL) {
-		close(*pv++);
-		close(*pv);
-	}
-}
-
-/* -------- here.c -------- */
-/* #include "sh.h" */
-
-/*
- * here documents
- */
-
-struct	here {
-	char	*h_tag;
-	int	h_dosub;
-	struct	ioword *h_iop;
-	struct	here	*h_next;
-};
-
-static	struct here *inhere;		/* list of hear docs while parsing */
-static	struct here *acthere;		/* list of active here documents */
-
-void
-inithere()
-{
-	inhere=acthere=(struct here*)0;
-}
-
-void
-markhere(s, iop)
-register char *s;
-struct ioword *iop;
-{
-	register struct here *h, *lh;
-
-	h = (struct here *) space(sizeof(struct here));
-	if (h == 0)
-		return;
-	h->h_tag = evalstr(s, DOSUB);
-	if (h->h_tag == 0)
-		return;
-	h->h_iop = iop;
-	iop->io_name = 0;
-	h->h_next = NULL;
-	if (inhere == 0)
-		inhere = h;
-	else
-		for (lh = inhere; lh!=NULL; lh = lh->h_next)
-			if (lh->h_next == 0) {
-				lh->h_next = h;
-				break;
-			}
-	iop->io_flag |= IOHERE|IOXHERE;
-	for (s = h->h_tag; *s; s++)
-		if (*s & QUOTE) {
-			iop->io_flag &= ~ IOXHERE;
-			*s &= ~ QUOTE;
-		}
-	h->h_dosub = iop->io_flag & IOXHERE;
-}
-
-void
-gethere()
-{
-	register struct here *h, *hp;
-
-	/* Scan here files first leaving inhere list in place */
-	for (hp = h = inhere; h != NULL; hp = h, h = h->h_next)
-	  readhere(&h->h_iop->io_name, h->h_tag, h->h_dosub? 0: '\'');
-
-	/* Make inhere list active - keep list intact for scraphere */
-	if (hp != NULL) {
-	  hp->h_next = acthere;
-	  acthere    = inhere;
-	  inhere     = NULL;
-	}
-}
-
-static void
-readhere(name, s, ec)
-char **name;
-register char *s;
-int ec;
-{
-	int tf;
-	char tname[30];
-	register c;
-	jmp_buf ev;
-	char line [LINELIM+1];
-	char *next;
-
-	tempname(tname);
-	*name = strsave(tname, areanum);
-	tf = creat(tname, 0600);
-	if (tf < 0)
-		return;
-	if (newenv(setjmp(errpt = ev)) != 0)
-		unlink(tname);
-	else {
-		pushio(e.iop->argp, e.iop->iofn);
-		e.iobase = e.iop;
-		for (;;) {
-			if (talking && e.iop <= iostack)
-				prs(cprompt->value);
-			next = line;
-			while ((c = readc()) != '\n' && c) {
-				if (next >= &line[LINELIM]) {
-					c = 0;
-					break;
-				}
-				*next++ = c;
-			}
-			*next = 0;
-			if (strcmp(s, line) == 0 || c == 0)
-				break;
-			*next++ = '\n';
-			write (tf, line, (int)(next-line));
-		}
-		if (c == 0) {
-			prs("here document `"); prs(s); err("' unclosed");
-		}
-		quitenv();
-	}
-	close(tf);
-}
-
-/*
- * open here temp file.
- * if unquoted here, expand here temp file into second temp file.
- */
-int
-herein(hname, xdoll)
-char *hname;
-int xdoll;
-{
-	register hf, tf;
-
-	if (hname == 0)
-		return(-1);
-	hf = open(hname, 0);
-	if (hf < 0)
-		return (-1);
-	if (xdoll) {
-		char c;
-		char tname[30];
-		jmp_buf ev;
-
-		tempname(tname);
-		if ((tf = creat(tname, 0600)) < 0)
-			return (-1);
-		if (newenv(setjmp(errpt = ev)) == 0) {
-			PUSHIO(afile, hf, herechar);
-			setbase(e.iop);
-			while ((c = subgetc(0, 0)) != 0) {
-				char c1 = c&~QUOTE;
-
-				if (c&QUOTE && !any(c1,"`$\\"))
-					write(tf,"\\",1);
-				write(tf, &c1, 1);
-			}
-			quitenv();
-		} else
-			unlink(tname);
-		close(tf);
-		tf = open(tname, 0);
-		unlink(tname);
-		return (tf);
-	} else
-		return (hf);
-}
-
-void
-scraphere()
-{
-	register struct here *h;
-
-	for (h = inhere; h != NULL; h = h->h_next) {
-		if (h->h_iop && h->h_iop->io_name)
-		  unlink(h->h_iop->io_name);
-	}
-	inhere = NULL;
-}
-
-/* unlink here temp files before a freearea(area) */
-void
-freehere(area)
-int area;
-{
-	register struct here *h, *hl;
-
-	hl = NULL;
-	for (h = acthere; h != NULL; h = h->h_next)
-		if (getarea((char *) h) >= area) {
-			if (h->h_iop->io_name != NULL)
-				unlink(h->h_iop->io_name);
-			if (hl == NULL)
-				acthere = h->h_next;
-			else
-				hl->h_next = h->h_next;
-		} else
-			hl = h;
-}
-
-void
-tempname(tname)
-char *tname;
-{
-	static int inc;
-	register char *cp, *lp;
-
-	for (cp = tname, lp = "/tmp/shtm"; (*cp = *lp++) != '\0'; cp++)
-		;
-	lp = putn(getpid()*1000 + inc++);
-	for (; (*cp = *lp++) != '\0'; cp++)
-		;
-}
Index: trunk/minix/commands/sh/sh6.c
===================================================================
--- trunk/minix/commands/sh/sh6.c	(revision 9)
+++ 	(revision )
@@ -1,8 +1,0 @@
-#define Extern
-
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <setjmp.h>
-#include "sh.h"
-
Index: trunk/minix/commands/simple/Makefile
===================================================================
--- trunk/minix/commands/simple/Makefile	(revision 9)
+++ 	(revision )
@@ -1,1732 +1,0 @@
-# Makefile for commands/simple.
-
-CFLAGS	= -D_MINIX -D_POSIX_SOURCE
-SYS	= ../..
-SERVERS = ../../servers
-CCLD	= $(CC) -i $(CFLAGS)
-CC	= exec cc
-
-# This Makefile is large, but that is because it lists all actions that must
-# be taken to compile and install all the simple commands.  If there were only
-# one command then it would look like this:
-#
-# ALL	= \
-#	cat \			need the 'cat' executable
-#
-# all:	$(ALL)			default rule, make all binaries
-#
-# cat:	cat.c			'cat' is made from 'cat.c'
-#	$(CCLD) -o $@ $?	compile 'cat.c' ($?) to 'cat' ($@)
-#	install -S 4kw $@	stack size is 8k (8086) or 16k (others)
-#
-# install:	\		rule to install all binaries
-#	/usr/bin/cat \		one can find 'cat' in /usr/bin
-#	/bin/cat \		important binaries are also in /bin
-#
-# /usr/bin/cat:	cat
-#	install -cs -o bin $? $@	copy 'cat' to '/usr/bin/cat' (-c),
-#					strip symbol table (-s)
-#
-# /bin/cat:	/usr/bin/cat
-#	install -lcs $? $@	install '/bin/cat' by linking (if possible)
-#				or copying (otherwise)
-#
-# Some of the binaries are installed under more than one name.  The extra
-# names are indented by one extra tab in the install rule.
-# If you want to add a command then insert it at the appropriate position
-# in sorted order.  Search around for the command just above or below the
-# the new command and add new rules for the new command near those places.
-# Observe four key things:
-#	What to make, how to make, what to install, how to install.
-
-ALL	= \
-	add_route \
-	arp \
-	at \
-	backup \
-	badblocks \
-	banner \
-	basename \
-	cal \
-	calendar \
-	cat \
-	cdiff \
-	cdprobe \
-	cgrep \
-	chmem \
-	chmod \
-	chown \
-	chroot \
-	ci \
-	cksum \
-	cleantmp \
-	cmp \
-	co \
-	comm \
-	compress \
-	cp \
-	crc \
-	cut \
-	date \
-	dd \
-	decomp16 \
-	dev2name \
-	devsize \
-	df \
-	dhrystone \
-	diff \
-	dirname \
-	du \
-	ed \
-	eject \
-	env \
-	expand \
-	factor \
-	fgrep \
-	file \
-	find \
-	finger \
-	fix \
-	fold \
-	fortune \
-	fsck \
-	fsck1 \
-	getty \
-	gomoku \
-	grep \
-	head \
-	host \
-	hostaddr \
-	id \
-	ifconfig \
-	ifdef \
-	in.fingerd \
-	in.rshd \
-	installx \
-	intr \
-	irdpd \
-	isoread \
-	join \
-	kill \
-	last \
-	leave \
-	life \
-	loadramdisk \
-	login \
-	look \
-	lp \
-	lpd \
-	ls \
-	mail \
-	man \
-	mesg \
-	mkdir \
-	mkfifo \
-	mkfs \
-	mknod \
-	mkproto \
-	mkswap \
-	modem \
-	mount \
-	mt \
-	nm \
-	newroot \
-	nonamed \
-	nice \
-	od \
-	passwd \
-	paste \
-	ping \
-	pr \
-	pr_routes \
-	progressbar \
-	prep \
-	printf \
-	printroot \
-	printenv \
-	proto \
-	pwd \
-	pwdauth \
-	ramdisk \
-	rarpd \
-	rcp \
-	rawspeed \
-	rdate \
-	readall \
-	rev \
-	readfs \
-	remsync \
-	rget \
-	rlogin \
-	rmdir \
-	rsh \
-	sed \
-	shar \
-	size \
-	sleep \
-	slip \
-	sort \
-	split \
-	stat \
-	strings \
-	strip \
-	stty \
-	su \
-	sum \
-	swapfs \
-	sync \
-	synctree \
-	sysenv \
-	tail \
-	tar \
-	tcpd \
-	tcpdp \
-	tcpstat \
-	tee \
-	term \
-	termcap \
-	tget \
-	time \
-	touch \
-	top \
-	tr \
-	truncate \
-	treecmp \
-	tsort \
-	ttt \
-	tty \
-	udpstat \
-	umount \
-	uname \
-	unexpand \
-	uniq \
-	update \
-	uud \
-	uue \
-	vol \
-	wc \
-	which \
-	who \
-	whoami \
-	write \
-	writeisofs \
-	xargs \
-	yes \
-	#
-
-all:	$(ALL)
-
-add_route:	add_route.c
-	$(CCLD) -o $@ add_route.c
-	@install -S 4kw $@
-
-arp:	arp.c
-	$(CCLD) -o $@ arp.c
-	@install -S 4kw $@
-
-at:	at.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-backup:	backup.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-badblocks:	badblocks.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-banner:	banner.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-basename:	basename.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-cal:	cal.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-calendar:	calendar.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-cat:	cat.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-cdiff:	cdiff.c
-	$(CCLD) -o $@ $?
-	@install -S 28kw $@
-
-cdprobe: cdprobe.c
-	$(CCLD) -o $@ $?
-	@install -S 28kw $@
-
-cgrep:	cgrep.c
-	$(CCLD) -o $@ $?
-	@install -S 5kw $@
-
-chmem:	chmem.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-chmod:	chmod.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-chown:	chown.c
-	$(CCLD) -o $@ $?
-	@install -S 16kw $@
-
-chroot:	chroot.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-ci:	ci.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-cksum:	cksum.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-cleantmp:	cleantmp.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-cmp:	cmp.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-co:	co.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-comm:	comm.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-compress:	compress.c
-	$(CCLD) -o $@ $?
-	@install -S 450k $@
-
-cp:    cp.c
-	$(CCLD) -o $@ $?
-	@install -S 32kw $@
-
-crc:	crc.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-cut:	cut.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-date:	date.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-dd:	dd.c
-	$(CCLD) -o $@ $?
-	@install -S 20kw $@
-
-decomp16:	decomp16.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-dev2name:	dev2name.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-devsize:	devsize.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-df:	df.c
-	$(CCLD) -I$(SYS) -o $@ $?
-	@install -S 4kw $@
-
-dhrystone:	dhrystone.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-diff:	diff.c
-	$(CCLD) -o $@ $?
-	@install -S 40kw $@
-
-dirname:	dirname.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-du:	du.c
-	$(CCLD) -o $@ $?
-	@install -S 256kw $@
-
-ed:	ed.c
-	$(CCLD) -o $@ $?
-	@install -S 32kw $@
-
-eject:	eject.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-env:	env.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-expand:	expand.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-factor:	factor.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-fgrep:	fgrep.c
-	$(CCLD) -o $@ $?
-	@install -S 10kw $@
-
-file:	file.c
-	$(CCLD) -o $@ $?
-	@install -S 25kw $@
-
-find:	find.c
-	$(CCLD) -o $@ $?
-	@install -S 25kw $@
-
-finger:	finger.c
-	$(CCLD) -o $@ finger.c
-	@install -S 8kw $@
-
-fix:	fix.c
-	$(CCLD) -o $@ fix.c
-	@install -S 32kw $@
-
-fold:	fold.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-fortune:	fortune.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-fsck:	fsck.c
-	$(CCLD) -o $@ $?
-	@install -S 4096k $@
-
-fsck1:	fsck1.c
-	$(CCLD) -o $@ $?
-	@install -S 32kw $@
-
-getty:	getty.c /usr/include/minix/config.h
-	$(CCLD) -o $@ getty.c
-	@install -S 4kw $@
-
-gomoku:	gomoku.c
-	$(CCLD) -o $@ $? -lcurses
-	@install -S 8kw $@
-
-grep:	grep.c
-	$(CCLD) -o $@ $?
-	@install -S 32kw $@
-
-head:	head.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-host:	host.c
-	$(CCLD) -wo -o $@ host.c
-	@install -S 4kw $@
-
-hostaddr:	hostaddr.c
-	$(CCLD) -o $@ hostaddr.c
-	@install -S 8kw $@
-
-id:	id.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-ifconfig:	ifconfig.c
-	$(CCLD) -o $@ ifconfig.c
-	@install -S 4kw $@
-
-ifdef:	ifdef.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-in.fingerd:	in.fingerd.c
-	$(CCLD) -o $@ in.fingerd.c
-	@install -S 4kw $@
-
-in.rshd:	in.rshd.c
-	$(CCLD) -o $@ in.rshd.c
-	@install -S 4kw $@
-
-installx:	install.c	# Note: avoided confict with 'install' rule.
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-intr:	intr.c
-	$(CCLD) -o $@ intr.c
-	@install -S 4kw $@
-
-irdpd:	irdpd.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-isoread:	isoread.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-join:	join.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-kill:	kill.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-last:	last.c
-	$(CCLD) -o $@ $?
-	@install -S 5kw $@
-
-leave:	leave.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-life:	life.c
-	$(CCLD) -o $@ $? -lcurses
-	@install -S 15kw $@
-
-loadramdisk:	loadramdisk.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-login:	login.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-look:	look.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-lp:	lp.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-lpd:	lpd.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-ls:	ls.c
-	$(CCLD) -o $@ $?
-	@install -S 20kw $@
-
-mail:	mail.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-man:	man.c
-	$(CCLD) -o $@ $?
-	@install -S 10kw $@
-
-mesg:	mesg.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-mkdir:	mkdir.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-mkfifo:	mkfifo.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-mkfs:	mkfs.c
-	$(CCLD) -o $@ $?
-	@install -S 20kw $@
-
-mknod:	mknod.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-mkproto:	mkproto.c
-	$(CCLD) -o $@ $?
-	@install -S 20kw $@
-
-mkswap:	mkswap.c
-	$(CCLD) -I$(SYS) -o $@ $?
-	@install -S 4kw $@
-
-modem:	modem.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-mount:	mount.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-mt:	mt.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-newroot:	newroot.c
-	$(CCLD) -o $@ $?
-	@install -S 32kw $@
-
-nm:	nm.c
-	$(CCLD) -o $@ $?
-	@install -S 32kw $@
-
-nice:	nice.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-nonamed:	nonamed.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-od:	od.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-passwd:	passwd.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-paste:	paste.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-ping:	ping.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-pr:	pr.c
-	$(CCLD) -o $@ $?
-	@install -S 16kw $@
-
-pr_routes:	pr_routes.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-progressbar:	progressbar.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-prep:	prep.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-printf:	printf.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-printenv:	printenv.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-printroot:	printroot.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-proto:	proto.c
-	$(CCLD) -o $@ $?
-	@install -S 15kw $@
-
-pwd:	pwd.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-pwdauth:	pwdauth.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-ramdisk:	ramdisk.c
-	$(CCLD) -o $@ ramdisk.c
-	@install -S 4kw $@
-
-rarpd:	rarpd.c
-	$(CCLD) -o $@ rarpd.c
-	@install -S 4kw $@
-
-rcp:	rcp.c
-	$(CCLD) -o $@ rcp.c
-	@install -S 8kw $@
-
-rawspeed:	rawspeed.c
-	$(CCLD) -o $@ rawspeed.c
-	@install -S 512k $@
-
-rdate:	rdate.c
-	$(CCLD) -o $@ rdate.c
-	@install -S 8kw $@
-
-rev:	rev.c
-	$(CCLD) -o $@ rev.c
-	@install -S 8kw $@
-
-readall:	readall.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-readfs:	readfs.c
-	$(CCLD) -o $@ $?
-	@install -S 25kw $@
-
-remsync:	remsync.c
-	$(CCLD) -o $@ $?
-	@install -S 256k $@
-
-rget:	rget.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-rlogin:	rlogin.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-rmdir:	rmdir.c
-	$(CCLD) -o $@ $?
-	@install -S 15kw $@
-
-rsh:	rsh.c
-	$(CCLD) -o $@ rsh.c
-	@install -S 8kw $@
-
-sed:	sed.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-shar:	shar.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-size:	size.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-sleep:	sleep.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-slip:	slip.c
-	$(CCLD) -o $@ $?
-	@install -S 20k $@
-
-sort:	sort.c
-	$(CCLD) -o $@ $?
-	@install -S 30kw $@
-
-split:	split.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-stat:	stat.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-strings:	strings.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-strip:	strip.c
-	$(CCLD) -o $@ $?
-	@install -S 8kw $@
-
-stty:	stty.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-su:	su.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-sum:	sum.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-swapfs:	swapfs.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-sync:	sync.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-synctree:	synctree.c
-	$(CCLD) -o $@ -wo $?
-	install -S 256kw $@
-
-sysenv:	sysenv.c
-	$(CCLD) -o $@ -wo $?
-	@install -S 4kw $@
-
-tail:	tail.c
-	$(CCLD) -o $@ $?
-	@install -S 16kw $@
-
-tar:	tar.c
-	$(CCLD) -o $@ $?
-	@install -S 256kw $@
-
-tcpd:	tcpd.c
-	$(CCLD) -o $@ -DPARANOID=0 tcpd.c
-	@install -S 4kw $@
-
-tcpdp:	tcpd.c
-	$(CCLD) -o $@ -DPARANOID=1 tcpd.c
-	@install -S 8kw $@
-
-tcpstat:	tcpstat.c
-	$(CCLD) -o $@ -I$(SERVERS) tcpstat.c
-	@install -S 8kw $@
-
-tee:	tee.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-term:	term.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-termcap:	termcap.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-tget:	tget.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-time:	time.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-touch:	touch.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-top:	top.c
-	$(CCLD) -o $@ $? -lcurses
-
-tr:	tr.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-tsort:	tsort.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-treecmp:	treecmp.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-truncate:	truncate.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-ttt:	ttt.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-tty:	tty.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-udpstat:	udpstat.c
-	$(CCLD) -o $@ -I$(SERVERS) $?
-	@install -S 32k $@
-
-umount:	umount.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-uname:	uname.c /usr/include/minix/config.h
-	$(CCLD) -o $@ uname.c
-	@install -S 4kw $@
-
-unexpand:	unexpand.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-uniq:	uniq.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-update:	update.c
-	$(CCLD) -o $@ $?
-	@install -S 2kw $@
-
-uud:	uud.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-uue:	uue.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-vol:	vol.c
-	$(CCLD) -o $@ $?
-	@install -S 80k $@	# note: '-S' is upper limit to 'vol -m'
-
-wc:	wc.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-which:	which.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-who:	who.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-whoami:	whoami.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-write:	write.c
-	$(CCLD) -o $@ $?
-
-writeisofs:	writeisofs.c
-	$(CCLD) -o $@ $?
-
-xargs:	xargs.c
-	$(CCLD) -o $@ $?
-	@install -S 16kw $@
-
-yes:	yes.c
-	$(CCLD) -o $@ $?
-	@install -S 4kw $@
-
-install:	\
-	/usr/bin/add_route \
-		/usr/bin/del_route \
-	/usr/bin/arp \
-	/usr/bin/at \
-	/usr/bin/backup \
-	/usr/bin/restore \
-	/usr/bin/rev \
-	/usr/bin/badblocks \
-	/usr/bin/banner \
-	/usr/bin/basename \
-	/usr/bin/cal \
-	/usr/bin/calendar \
-	/usr/bin/cat \
-	/usr/bin/cdiff \
-	/usr/bin/cdprobe \
-	/usr/bin/cgrep \
-	/usr/bin/chmem \
-	/usr/bin/chmod \
-	/usr/bin/chown \
-	/bin/chroot \
-		/usr/bin/chgrp \
-	/usr/bin/ci \
-	/usr/bin/cksum \
-	/usr/bin/cleantmp \
-	/usr/bin/cmp \
-	/usr/bin/co \
-	/usr/bin/comm \
-	/usr/bin/compress \
-		/usr/bin/uncompress \
-		/usr/bin/zcat \
-	/bin/cp \
-	/bin/rm \
-	/bin/mv \
-	/bin/ln \
-	/usr/bin/cp \
-		/usr/bin/clone \
-		/usr/bin/cpdir \
-		/usr/bin/ln \
-		/usr/bin/mv \
-		/usr/bin/rm \
-		/bin/rm \
-	/usr/bin/crc \
-	/usr/bin/cut \
-	/usr/bin/date \
-	/usr/bin/dd \
-	/usr/bin/decomp16 \
-	/bin/dev2name \
-	/usr/bin/devsize \
-	/usr/bin/df \
-	/usr/bin/dhrystone \
-	/usr/bin/diff \
-	/usr/bin/dirname \
-	/usr/bin/du \
-	/usr/bin/ed \
-	/usr/bin/eject \
-	/usr/bin/env \
-	/usr/bin/expand \
-	/usr/bin/factor \
-	/usr/bin/fgrep \
-	/usr/bin/file \
-	/usr/bin/find \
-	/usr/bin/finger \
-	/usr/bin/fix \
-	/usr/bin/fold \
-	/usr/bin/fortune \
-	/usr/bin/fsck \
-	/usr/bin/fsck1 \
-	/bin/getty \
-	/usr/bin/getty \
-	/usr/bin/gomoku \
-	/usr/bin/grep \
-		/usr/bin/egrep \
-	/usr/bin/head \
-	/usr/bin/host \
-	/usr/bin/hostaddr \
-	/usr/bin/id \
-	/usr/bin/ifconfig \
-	/usr/bin/ifdef \
-	/usr/bin/in.fingerd \
-	/usr/bin/in.rshd \
-	/bin/install \
-	/usr/bin/install \
-	/usr/bin/intr \
-	/usr/bin/irdpd \
-	/usr/bin/isoread \
-		/usr/bin/isodir \
-		/usr/bin/isoinfo \
-	/usr/bin/join \
-	/usr/bin/kill \
-	/usr/bin/last \
-		/usr/bin/uptime \
-	/usr/bin/leave \
-	/usr/bin/life \
-	/usr/bin/loadramdisk \
-	/usr/bin/login \
-	/usr/bin/look \
-	/usr/bin/lp \
-	/usr/bin/lpd \
-	/usr/bin/ls \
-	/bin/ls \
-	/usr/bin/mail \
-	/usr/bin/man \
-	/usr/bin/mesg \
-	/usr/bin/mkdir \
-	/usr/bin/mkfifo \
-	/usr/bin/mkfs \
-	/usr/bin/mknod \
-	/usr/bin/mkproto \
-	/usr/bin/mkswap \
-	/usr/bin/modem \
-	/usr/bin/mount \
-	/usr/bin/mt \
-	/usr/bin/newroot \
-	/usr/bin/nm \
-	/usr/bin/nice \
-	/usr/bin/nonamed \
-	/usr/bin/od \
-	/usr/bin/passwd \
-		/usr/bin/chfn \
-		/usr/bin/chsh \
-	/usr/bin/paste \
-	/usr/bin/ping \
-	/usr/bin/pr \
-	/usr/bin/pr_routes \
-	/usr/bin/progressbar \
-	/usr/bin/prep \
-	/usr/bin/printf \
-	/usr/bin/printenv \
-	/usr/bin/printroot \
-	/usr/bin/proto \
-	/usr/bin/pwd \
-	/usr/lib/pwdauth \
-	/usr/bin/ramdisk \
-	/usr/bin/rarpd \
-	/usr/bin/rcp \
-	/usr/bin/rawspeed \
-	/usr/bin/rdate \
-	/usr/bin/readall \
-	/usr/bin/readlink \
-	/usr/bin/readfs \
-	/usr/bin/remsync \
-	/usr/bin/rget \
-		/usr/bin/rput \
-	/usr/bin/rlogin \
-	/usr/bin/rmdir \
-	/usr/bin/rsh \
-	/usr/bin/sed \
-	/bin/sed \
-	/usr/bin/shar \
-	/usr/bin/size \
-	/usr/bin/sleep \
-	/usr/bin/slip \
-	/usr/bin/sort \
-	/usr/bin/split \
-	/usr/bin/stat \
-		/usr/bin/fstat \
-	/usr/bin/strings \
-	/usr/bin/strip \
-	/usr/bin/stty \
-	/usr/bin/su \
-	/usr/bin/sum \
-	/usr/bin/swapfs \
-	/usr/bin/sync \
-	/usr/bin/synctree \
-	/usr/bin/sysenv \
-	/bin/sysenv \
-	/usr/bin/tail \
-	/usr/bin/tar \
-	/usr/bin/tcpd \
-	/usr/bin/tcpdp \
-	/usr/bin/tcpstat \
-	/usr/bin/tee \
-	/usr/bin/term \
-	/usr/bin/termcap \
-	/usr/bin/tget \
-	/usr/bin/time \
-	/usr/bin/top \
-	/usr/bin/touch \
-	/usr/bin/tr \
-	/usr/bin/treecmp \
-	/usr/bin/truncate \
-	/usr/bin/tsort \
-	/usr/bin/ttt \
-	/usr/bin/tty \
-	/usr/bin/udpstat \
-	/usr/bin/umount \
-	/usr/bin/uname \
-		/usr/bin/arch \
-	/usr/bin/unexpand \
-	/usr/bin/uniq \
-	/usr/bin/update \
-	/usr/bin/uud \
-		/usr/bin/uudecode \
-	/usr/bin/uue \
-		/usr/bin/uuencode \
-	/usr/bin/vol \
-	/usr/bin/wc \
-	/usr/bin/which \
-	/usr/bin/who \
-	/usr/bin/whoami \
-	/usr/bin/write \
-	/usr/bin/writeisofs \
-	/usr/bin/xargs \
-	/usr/bin/yes \
-	/usr/bin/udpstat \
-	/bin/cat \
-	/bin/date \
-	/bin/fsck \
-	/bin/intr \
-	/bin/mount \
-	/bin/printroot \
-	/bin/pwd \
-	/bin/sync \
-	/bin/umount \
-	#
-
-/usr/bin/add_route:	add_route
-	install -cs -o bin $? $@
-
-/usr/bin/del_route:	/usr/bin/add_route
-	install -l $? $@
-
-/usr/bin/arp:	arp
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/at:	at
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/backup:	backup
-	install -cs -o bin $? $@
-
-/usr/bin/restore:	/usr/bin/backup
-	install -l $? $@
-
-/usr/bin/badblocks:	badblocks
-	install -cs -o bin $? $@
-
-/usr/bin/banner:	banner
-	install -cs -o bin $? $@
-
-/usr/bin/basename:	basename
-	install -cs -o bin $? $@
-
-/usr/bin/cal:	cal
-	install -cs -o bin $? $@
-
-/usr/bin/calendar:	calendar
-	install -cs -o bin $? $@
-
-/usr/bin/cat:	cat
-	install -cs -o bin $? $@
-
-/usr/bin/cdiff:	cdiff
-	install -cs -o bin $? $@
-
-/usr/bin/cdprobe: cdprobe
-	install -cs -o bin $? $@
-
-/usr/bin/cgrep:	cgrep
-	install -cs -o bin $? $@
-
-/usr/bin/chmem:	chmem
-	install -cs -o bin $? $@
-
-/usr/bin/chmod:	chmod
-	install -cs -o bin $? $@
-
-/usr/bin/chown:	chown
-	install -cs -o bin $? $@
-
-/bin/chroot:	chroot
-	install -cs -o bin $? $@
-
-/usr/bin/chgrp:	/usr/bin/chown
-	install -l $? $@
-
-/usr/bin/ci:	ci
-	install -cs -o bin $? $@
-
-/usr/bin/cksum:	cksum
-	install -cs -o bin $? $@
-
-/usr/bin/cleantmp:	cleantmp
-	install -cs -o bin $? $@
-
-/usr/bin/cmp:	cmp
-	install -cs -o bin $? $@
-
-/usr/bin/co:	co
-	install -cs -o bin $? $@
-
-/usr/bin/comm:	comm
-	install -cs -o bin $? $@
-
-/usr/bin/compress:	compress
-	install -cs -o bin $? $@
-
-/usr/bin/uncompress /usr/bin/zcat:	/usr/bin/compress
-	install -l $? $@
-
-/bin/cp:	cp
-	install -cs -o bin $? $@
-
-/usr/bin/cp:	cp
-	install -cs -o bin $? $@
-
-/usr/bin/clone /usr/bin/cpdir \
-/usr/bin/ln /usr/bin/mv /usr/bin/rm:	/usr/bin/cp
-	install -l $? $@
-
-/bin/ln /bin/mv /bin/rm:	/bin/cp
-	install -l $? $@
-
-/usr/bin/crc:	crc
-	install -cs -o bin $? $@
-
-/usr/bin/cut:	cut
-	install -cs -o bin $? $@
-
-/usr/bin/date:	date
-	install -cs -o bin $? $@
-
-/usr/bin/dd:	dd
-	install -cs -o bin $? $@
-
-/bin/dev2name:	dev2name
-	install -cs -o bin $? $@
-
-/usr/bin/devsize:	devsize
-	install -cs -o bin $? $@
-
-/usr/bin/decomp16:	decomp16
-	install -cs -o bin $? $@
-
-/usr/bin/df:	df
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/dhrystone:	dhrystone
-	install -cs -o bin $? $@
-
-/usr/bin/diff:	diff
-	install -cs -o bin $? $@
-
-/usr/bin/dirname:	dirname
-	install -cs -o bin $? $@
-
-/usr/bin/du:	du
-	install -cs -o bin $? $@
-
-/usr/bin/ed:	ed
-	install -cs -o bin $? $@
-
-/usr/bin/eject:	eject
-	install -cs -o bin $? $@
-
-/usr/bin/env:	env
-	install -cs -o bin $? $@
-
-/usr/bin/expand:	expand
-	install -cs -o bin $? $@
-
-/usr/bin/factor:	factor
-	install -cs -o bin $? $@
-
-/usr/bin/fgrep:	fgrep
-	install -cs -o bin $? $@
-
-/usr/bin/file:	file
-	install -cs -o bin $? $@
-
-/usr/bin/find:	find
-	install -cs -o bin $? $@
-
-/usr/bin/finger:	finger
-	install -cs -o bin $? $@
-
-/usr/bin/fix:	fix
-	install -cs -o bin $? $@
-
-/usr/bin/fold:	fold
-	install -cs -o bin $? $@
-
-/usr/bin/fortune:	fortune
-	install -cs -o bin $? $@
-
-/usr/bin/fsck:	fsck
-	install -cs -o bin $? $@
-
-/usr/bin/fsck1:	fsck1
-	install -cs -o bin $? $@
-
-/bin/getty:	getty
-	install -cs -o bin $? $@
-
-/usr/bin/getty:	getty
-	install -cs -o bin $? $@
-
-/usr/bin/gomoku:	gomoku
-	install -cs -o bin $? $@
-
-/usr/bin/grep:	grep
-	install -cs -o bin $? $@
-
-/usr/bin/egrep:	/usr/bin/grep
-	install -l $? $@
-
-/usr/bin/head:	head
-	install -cs -o bin $? $@
-
-/usr/bin/host:	host
-	install -cs -o bin $? $@
-
-/usr/bin/hostaddr:	hostaddr
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/id:	id
-	install -cs -o bin $? $@
-
-/usr/bin/ifconfig:	ifconfig
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/ifdef:	ifdef
-	install -cs -o bin $? $@
-
-/usr/bin/in.fingerd:	in.fingerd
-	install -cs -o bin $? $@
-
-/usr/bin/in.rshd:	in.rshd
-	install -cs -o bin $? $@
-
-/bin/install:	installx
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/install:	installx
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/intr:	intr
-	install -cs -o bin $? $@
-
-/usr/bin/irdpd:	irdpd
-	install -cs -o bin $? $@
-
-/usr/bin/isoread:	isoread
-	install -cs -o bin $? $@
-
-/usr/bin/isodir /usr/bin/isoinfo:	/usr/bin/isoread
-	install -l $? $@
-
-/usr/bin/join:	join
-	install -cs -o bin $? $@
-
-/usr/bin/kill:	kill
-	install -cs -o bin $? $@
-
-/usr/bin/last:	last
-	install -cs -o bin $? $@
-
-/usr/bin/uptime:	/usr/bin/last
-	install -l $? $@
-
-/usr/bin/leave:	leave
-	install -cs -o bin $? $@
-
-/usr/bin/life:	life
-	install -cs -o bin $? $@
-
-/usr/bin/loadramdisk:	loadramdisk
-	install -cs -o bin $? $@
-
-/usr/bin/login:	login
-	install -cs -o bin $? $@
-
-/usr/bin/look:	look
-	install -cs -o bin $? $@
-
-/usr/bin/lp:	lp
-	install -cs -o bin $? $@
-
-/usr/bin/lpd:	lpd
-	install -cs -o daemon -m 4755 $? $@
-
-/usr/bin/ls:	ls
-	install -cs -o bin $? $@
-
-/bin/ls:	ls
-	install -cs -o bin $? $@
-
-/usr/bin/mail:	mail
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/man:	man
-	install -cs -o bin $? $@
-
-/usr/bin/mesg:	mesg
-	install -cs -o bin $? $@
-
-/usr/bin/mkdir:	mkdir
-	install -cs -o bin $? $@
-
-/usr/bin/mkfifo:	mkfifo
-	install -cs -o bin $? $@
-
-/usr/bin/mkfs:	mkfs
-	install -cs -o bin $? $@
-
-/usr/bin/mknod:	mknod
-	install -cs -o bin $? $@
-
-/usr/bin/mkproto:	mkproto
-	install -cs -o bin $? $@
-
-/usr/bin/mkswap:	mkswap
-	install -cs -o bin $? $@
-
-/usr/bin/modem:	modem
-	install -cs -o bin $? $@
-
-/usr/bin/mount:	mount
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/mt:	mt
-	install -cs -o bin $? $@
-
-/usr/bin/newroot:	newroot
-	install -cs -o bin $? $@
-
-/usr/bin/nm:	nm
-	install -cs -o bin $? $@
-
-/usr/bin/nice:	nice
-	install -cs -o bin $? $@
-
-/usr/bin/nonamed:	nonamed
-	install -cs -o bin $? $@
-
-/usr/bin/od:	od
-	install -cs -o bin $? $@
-
-/usr/bin/passwd:	passwd
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/chfn /usr/bin/chsh:	/usr/bin/passwd
-	install -l $? $@
-
-/usr/bin/paste:	paste
-	install -cs -o bin $? $@
-
-/usr/bin/ping:	ping
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/pr:	pr
-	install -cs -o bin $? $@
-
-/usr/bin/pr_routes:	pr_routes
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/progressbar:	progressbar
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/prep:	prep
-	install -cs -o bin $? $@
-
-/usr/bin/printf:	printf
-	install -cs -o bin $? $@
-
-/usr/bin/printenv:	printenv
-	install -cs -o bin $? $@
-
-/usr/bin/printroot:	printroot
-	install -cs -o bin $? $@
-
-/usr/bin/proto:	proto
-	install -cs -o bin $? $@
-
-/usr/bin/pwd:	pwd
-	install -cs -o bin $? $@
-
-/usr/lib/pwdauth:	pwdauth
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/ramdisk:	ramdisk
-	install -cs -o bin $? $@
-
-/usr/bin/rarpd:	rarpd
-	install -cs -o bin $? $@
-
-/usr/bin/rcp:	rcp
-	install -cs -o bin $? $@
-
-/usr/bin/rawspeed:	rawspeed
-	install -cs -o bin $? $@
-
-/usr/bin/rdate:	rdate
-	install -cs -o bin $? $@
-
-/usr/bin/readall:	readall
-	install -cs -o bin $? $@
-
-/usr/bin/readlink:	/usr/bin/stat
-	install -l $? $@
-
-/usr/bin/readfs:	readfs
-	install -cs -o bin $? $@
-
-/usr/bin/remsync:	remsync
-	install -cs -o bin $? $@
-
-/usr/bin/rev:	rev
-	install -cs -o bin $? $@
-
-/usr/bin/rget:	rget
-	install -cs -o bin $? $@
-
-/usr/bin/rput:	/usr/bin/rget
-	install -l $? $@
-
-/usr/bin/rlogin:	rlogin
-	install -cs -o bin $? $@
-
-/usr/bin/rmdir:	rmdir
-	install -cs -o bin $? $@
-
-/usr/bin/rsh:	rsh
-	install -cs -o bin $? $@
-
-/usr/bin/sed:	sed
-	install -cs -o bin $? $@
-
-/bin/sed:	sed
-	install -cs -o bin $? $@
-
-/usr/bin/shar:	shar
-	install -cs -o bin $? $@
-
-/usr/bin/size:	size
-	install -cs -o bin $? $@
-
-/usr/bin/sleep:	sleep
-	install -cs -o bin $? $@
-
-/usr/bin/slip:	slip
-	install -cs -o bin $? $@
-
-/usr/bin/sort:	sort
-	install -cs -o bin $? $@
-
-/usr/bin/split:	split
-	install -cs -o bin $? $@
-
-/usr/bin/stat:	stat
-	install -cs -o bin $? $@
-
-/usr/bin/fstat:	/usr/bin/stat
-	install -l $? $@
-
-/usr/bin/strings:	strings
-	install -cs -o bin $? $@
-
-/usr/bin/strip:	strip
-	install -cs -o bin $? $@
-
-/usr/bin/stty:	stty
-	install -cs -o bin $? $@
-
-/usr/bin/su:	su
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/sum:	sum
-	install -cs -o bin $? $@
-
-/usr/bin/swapfs:	swapfs
-	install -cs -o bin $? $@
-
-/usr/bin/sync:	sync
-	install -cs -o bin $? $@
-
-/usr/bin/synctree:	synctree
-	install -cs -o bin $? $@
-
-/bin/sysenv:	sysenv
-	install -cs -o bin $? $@
-
-/usr/bin/sysenv:	sysenv
-	install -cs -o bin $? $@
-
-/usr/bin/tail:	tail
-	install -cs -o bin $? $@
-
-/usr/bin/tar:	tar
-	install -cs -o bin $? $@
-
-/usr/bin/tcpd:	tcpd
-	install -cs -o bin $? $@
-
-/usr/bin/tcpdp:	tcpdp
-	install -cs -o bin $? $@
-
-/usr/bin/tcpstat:	tcpstat
-	install -cs -o bin $? $@
-
-/usr/bin/tee:	tee
-	install -cs -o bin $? $@
-
-/usr/bin/term:	term
-	install -cs -o bin -g uucp -m 2755 $? $@
-
-/usr/bin/termcap:	termcap
-	install -cs -o bin $? $@
-
-/usr/bin/tget:	tget
-	install -cs -o bin $? $@
-
-/usr/bin/time:	time
-	install -cs -o bin $? $@
-
-/usr/bin/top:	top
-	install -cs -o bin $? $@
-
-/usr/bin/touch:	touch
-	install -cs -o bin $? $@
-
-/usr/bin/tr:	tr
-	install -cs -o bin $? $@
-
-/usr/bin/treecmp:	treecmp
-	install -cs -o bin $? $@
-
-/usr/bin/truncate:	truncate
-	install -cs -o bin $? $@
-
-/usr/bin/tsort:	tsort
-	install -cs -o bin $? $@
-
-/usr/bin/ttt:	ttt
-	install -cs -o bin $? $@
-
-/usr/bin/tty:	tty
-	install -cs -o bin $? $@
-
-/usr/bin/udpstat:	udpstat
-	install -cs -o bin $? $@
-
-/usr/bin/umount:	umount
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/uname:	uname
-	install -cs -o bin $? $@
-
-/usr/bin/arch:	/usr/bin/uname
-	install -l $? $@
-
-/usr/bin/unexpand:	unexpand
-	install -cs -o bin $? $@
-
-/usr/bin/uniq:	uniq
-	install -cs -o bin $? $@
-
-/usr/bin/update:	update
-	install -cs -o bin $? $@
-
-/usr/bin/uud:	uud
-	install -cs -o bin $? $@
-
-/usr/bin/uudecode:	/usr/bin/uud
-	install -l $? $@
-
-/usr/bin/uue:	uue
-	install -cs -o bin $? $@
-
-/usr/bin/uuencode:	/usr/bin/uue
-	install -l $? $@
-
-/usr/bin/vol:	vol
-	install -cs -o bin $? $@
-
-/usr/bin/wc:	wc
-	install -cs -o bin $? $@
-
-/usr/bin/which:	which
-	install -cs -o bin $? $@
-
-/usr/bin/who:	who
-	install -cs -o bin $? $@
-
-/usr/bin/whoami:	whoami
-	install -cs -o bin $? $@
-
-/usr/bin/write:	write
-	install -cs -o bin -g tty -m 2755 $? $@
-
-/usr/bin/writeisofs:	writeisofs
-	install -cs -S 2M -o bin $? $@
-
-/usr/bin/xargs:	xargs
-	install -cs -o bin $? $@
-
-/usr/bin/yes:	yes
-	install -cs -o bin $? $@
-
-/bin/cat:	/usr/bin/cat
-	install -lcs $? $@
-
-/bin/date:	/usr/bin/date
-	install -lcs $? $@
-
-/bin/fsck:	/usr/bin/fsck
-	install -lcs $? $@
-
-/bin/intr:	/usr/bin/intr
-	install -lcs $? $@
-
-/bin/mount:	/usr/bin/mount
-	install -lcs $? $@
-
-/bin/printroot:	/usr/bin/printroot
-	install -lcs $? $@
-
-/bin/pwd:	/usr/bin/pwd
-	install -lcs $? $@
-
-/bin/sync:	/usr/bin/sync
-	install -lcs $? $@
-
-/bin/umount:	/usr/bin/umount
-	install -lcs $? $@
-
-clean:
-	rm -rf $(ALL) a.out core
Index: trunk/minix/commands/simple/add_route.c
===================================================================
--- trunk/minix/commands/simple/add_route.c	(revision 9)
+++ 	(revision )
@@ -1,347 +1,0 @@
-/*
-add_route.c
-
-Created August 7, 1991 by Philip Homburg
-*/
-
-#define _POSIX_C_SOURCE	2
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <net/hton.h>
-#include <net/netlib.h>
-#include <net/gen/netdb.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/route.h>
-#include <net/gen/socket.h>
-#include <net/gen/ip_io.h>
-
-static char *prog_name;
-static enum { ADD, DEL } action;
-
-static void usage(void);
-static int name_to_ip(char *name, ipaddr_t *addr);
-static int parse_cidr(char *cidr, ipaddr_t *addr, ipaddr_t *mask);
-
-int main(int argc, char *argv[])
-{
-	struct netent *netent;
-	ipaddr_t gateway, destination, netmask, defaultmask=0;
-	u8_t high_byte;
-	nwio_route_t route;
-	int ip_fd, itab;
-	int r;
-	int metric;
-	char *check;
-	char *ip_device;
-	char *netmask_str, *metric_str, *destination_str, *gateway_str;
-	int c;
-	char *d_arg, *g_arg, *m_arg, *n_arg, *I_arg;
-	int i_flag, o_flag, D_flag, v_flag;
-	int cidr;
-
-	prog_name= strrchr(argv[0], '/');
-	if (prog_name == NULL) prog_name= argv[0]; else prog_name++;
-
-	if (strcmp(prog_name, "add_route") == 0)
-		action= ADD;
-	else if (strcmp(prog_name, "del_route") == 0)
-		action= DEL;
-	else
-	{
-		fprintf(stderr, "Don't know what to do when named '%s'\n",
-			prog_name);
-		exit(1);
-	}
-
-	i_flag= 0;
-	o_flag= 0;
-	D_flag= 0;
-	v_flag= 0;
-	g_arg= NULL;
-	d_arg= NULL;
-	m_arg= NULL;
-	n_arg= NULL;
-	I_arg= NULL;
-	while ((c= getopt(argc, argv, "iovDg:d:m:n:I:?")) != -1)
-	{
-		switch(c)
-		{
-		case 'i':
-			if (i_flag)
-				usage();
-			i_flag= 1;
-			break;
-		case 'o':
-			if (o_flag)
-				usage();
-			o_flag= 1;
-			break;
-		case 'v':
-			if (v_flag)
-				usage();
-			v_flag= 1;
-			break;
-		case 'D':
-			if (D_flag)
-				usage();
-			D_flag= 1;
-			break;
-		case 'g':
-			if (g_arg)
-				usage();
-			g_arg= optarg;
-			break;
-		case 'd':
-			if (d_arg)
-				usage();
-			d_arg= optarg;
-			break;
-		case 'm':
-			if (m_arg)
-				usage();
-			m_arg= optarg;
-			break;
-		case 'n':
-			if (n_arg)
-				usage();
-			n_arg= optarg;
-			break;
-		case 'I':
-			if (I_arg)
-				usage();
-			I_arg= optarg;
-			break;
-		case '?':
-			usage();
-		default:
-			fprintf(stderr, "%s: getopt failed\n", prog_name);
-			exit(1);
-		}
-	}
-	if (optind != argc)
-		usage();
-	if (i_flag && o_flag)
-		usage();
-	itab= i_flag;
-
-	if (i_flag)
-	{
-		if (g_arg == NULL || d_arg == NULL || m_arg == NULL)
-			usage();
-	}
-	else
-	{
-		if (g_arg == NULL || (d_arg == NULL && n_arg != NULL))
-		{
-			usage();
-		}
-	}
-		
-	gateway_str= g_arg;
-	destination_str= d_arg;
-	metric_str= m_arg;
-	netmask_str= n_arg;
-	ip_device= I_arg;
-
-	if (!name_to_ip(gateway_str, &gateway))
-	{
-		fprintf(stderr, "%s: unknown host '%s'\n", prog_name,
-								gateway_str);
-		exit(1);
-	}
-
-	destination= 0;
-	netmask= 0;
-	cidr= 0;
-
-	if (destination_str)
-	{
-		if (parse_cidr(destination_str, &destination, &netmask))
-			cidr= 1;
-		else if (inet_aton(destination_str, &destination))
-			;
-		else if ((netent= getnetbyname(destination_str)) != NULL)
-			destination= netent->n_net;
-		else if (!name_to_ip(destination_str, &destination))
-		{
-			fprintf(stderr, "%s: unknown network/host '%s'\n",
-				prog_name, destination_str);
-			exit(1);
-		}
-		high_byte= *(u8_t *)&destination;
-		if (!(high_byte & 0x80))	/* class A or 0 */
-		{
-			if (destination)
-				defaultmask= HTONL(0xff000000);
-		}
-		else if (!(high_byte & 0x40))	/* class B */
-		{
-			defaultmask= HTONL(0xffff0000);
-		}
-		else if (!(high_byte & 0x20))	/* class C */
-		{
-			defaultmask= HTONL(0xffffff00);
-		}
-		else				/* class D is multicast ... */
-		{
-			fprintf(stderr, "%s: Warning: Martian address '%s'\n",
-				prog_name, inet_ntoa(destination));
-			defaultmask= HTONL(0xffffffff);
-		}
-		if (destination & ~defaultmask)
-		{
-			/* host route */
-			defaultmask= HTONL(0xffffffff);
-		}
-		if (!cidr)
-			netmask= defaultmask;
-	}
-
-	if (netmask_str)
-	{
-		if (cidr)
-			usage();
-		if (inet_aton(netmask_str, &netmask) == 0)
-		{
-			fprintf(stderr, "%s: illegal netmask'%s'\n", prog_name,
-				netmask_str);
-			exit(1);
-		}
-	}
-
-	if (metric_str)
-	{
-		metric= strtol(metric_str, &check, 0);
-		if (check[0] != '\0' || metric < 1)
-		{
-			fprintf(stderr, "%s: illegal metric %s\n",
-				prog_name, metric_str);
-		}
-	}
-	else
-		metric= 1;
-		
-	if (!ip_device)
-		ip_device= getenv("IP_DEVICE");
-	if (!ip_device)
-		ip_device= IP_DEVICE;
-
-	ip_fd= open(ip_device, O_RDWR);
-	if (ip_fd == -1)
-	{
-		fprintf(stderr, "%s: unable to open('%s'): %s\n",
-			prog_name, ip_device, strerror(errno));
-		exit(1);
-	}
-
-	if (v_flag)
-	{
-		printf("%s %s route to %s ",
-			action == ADD ? "adding" : "deleting",
-			itab ? "input" : "output",
-			inet_ntoa(destination));
-		printf("with netmask %s ", inet_ntoa(netmask));
-		printf("using gateway %s", inet_ntoa(gateway));
-		if (itab && action == ADD)
-			printf(" at distance %d", metric);
-		printf("\n");
-	}
-
-	route.nwr_ent_no= 0;
-	route.nwr_dest= destination;
-	route.nwr_netmask= netmask;
-	route.nwr_gateway= gateway;
-	route.nwr_dist= action == ADD ? metric : 0;
-	route.nwr_flags= (action == DEL && D_flag) ? 0 : NWRF_STATIC;
-	route.nwr_pref= 0;
-	route.nwr_mtu= 0;
-
-	if (action == ADD)
-		r= ioctl(ip_fd, itab ? NWIOSIPIROUTE : NWIOSIPOROUTE, &route);
-	else
-		r= ioctl(ip_fd, itab ? NWIODIPIROUTE : NWIODIPOROUTE, &route);
-	if (r == -1)
-	{
-		fprintf(stderr, "%s: NWIO%cIP%cROUTE: %s\n",
-			prog_name,
-			action == ADD ? 'S' : 'D',
-			itab ? 'I' : 'O',
-			strerror(errno));
-		exit(1);
-	}
-	return(0);
-}
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Usage: %s\n"
-		"\t[-o] %s-g gw [-d dst [-n netmask]] %s[-I ipdev] [-v]\n"
-		"\t-i %s-g gw -d dst [-n netmask] %s[-I ipdev] [-v]\n"
-		"Note: <dst> may be in CIDR notation\n",
-		prog_name,
-		action == DEL ? "[-D] " : "",
-		action == ADD ? "[-m metric] " : "",
-		action == DEL ? "[-D] " : "",
-		action == ADD ? "-m metric " : ""
-	);
-	exit(1);
-}
-
-static int name_to_ip(char *name, ipaddr_t *addr)
-{
-	/* Translate a name to an IP address.  Try first with inet_aton(), then
-	 * with gethostbyname().  (The latter can also recognize an IP address,
-	 * but only decimals with at least one dot).)
-	 */
-	struct hostent *hostent;
-
-	if (!inet_aton(name, addr)) {
-		if ((hostent= gethostbyname(name)) == NULL) return 0;
-		if (hostent->h_addrtype != AF_INET) return 0;
-		if (hostent->h_length != sizeof(*addr)) return 0;
-		memcpy(addr, hostent->h_addr, sizeof(*addr));
-	}
-	return 1;
-}
-
-static int parse_cidr(char *cidr, ipaddr_t *addr, ipaddr_t *mask)
-{
-	char *slash, *check;
-	ipaddr_t a;
-	int ok;
-	unsigned long len;
-
-	if ((slash= strchr(cidr, '/')) == NULL)
-		return 0;
-
-	*slash++= 0;
-	ok= 1;
-
-	if (!inet_aton(cidr, &a))
-		ok= 0;
-
-	len= strtoul(slash, &check, 10);
-	if (check == slash || *check != 0 || len > 32)
-		ok= 0;
-
-	*--slash= '/';
-	if (!ok)
-		return 0;
-	*addr= a;
-	*mask= htonl(len == 0 ? 0 : (0xFFFFFFFF << (32-len)) & 0xFFFFFFFF);
-	return 1;
-}
-
-/*
- * $PchId: add_route.c,v 1.6 2001/04/20 10:45:07 philip Exp $
- */
Index: trunk/minix/commands/simple/arp.c
===================================================================
--- trunk/minix/commands/simple/arp.c	(revision 9)
+++ 	(revision )
@@ -1,473 +1,0 @@
-/*
-arp.c
-
-Created:	Jan 2001 by Philip Homburg <philip@f-mnx.phicoh.com>
-
-Manipulate ARP table
-*/
-
-#define _POSIX_C_SOURCE 2
-#define _MINIX_SOURCE
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sys/ioctl.h>
-
-#include <net/netlib.h>
-#include <net/gen/ether.h>
-#include <net/gen/if_ether.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/ip_io.h>
-#include <net/gen/netdb.h>
-#include <net/gen/socket.h>
-
-#include <net/gen/arp_io.h>
-
-char *progname;
-static int ipfd= -1;
-static int do_setuid= 0;
-
-static void do_open(char *devname);
-static void show_one(char *hostname, int do_num);
-static void show_all(int do_num);
-static void print_one(ipaddr_t ipaddr, nwio_arp_t *arpp, int do_num);
-static void delete_all(void);
-static void delete(char *hostname);
-static void do_set(char *hostname, char *ethername, int temp, int pub,
-	int optdelete);
-static ipaddr_t nametoipaddr(char *hostname);
-static void fatal(char *fmt, ...);
-static void usage(void);
-
-int main(int argc, char *argv[])
-{
-	int c;
-	char *hostname, *ethername;
-	int do_temp, do_pub;
-	int a_flag, d_flag, n_flag, s_flag, S_flag;
-	char *I_arg;
-
-	(progname=strrchr(argv[0],'/')) ? progname++ : (progname=argv[0]);
-
-	a_flag= d_flag= n_flag= s_flag= S_flag= 0;
-	I_arg= NULL;
-	while(c= getopt(argc, argv, "adnsS?I:"), c != -1)
-	{
-		switch(c)
-		{
-		case '?':	usage();
-		case 'a':	a_flag= 1; break;
-		case 'd':	d_flag= 1; break;
-		case 'n':	n_flag= 1; break;
-		case 's':	s_flag= 1; break;
-		case 'S':	S_flag= 1; break;
-		case 'I':	I_arg= optarg; break;
-		default:	fatal("getopt failed: '%c'", c);
-		}
-	}
-
-	hostname= NULL;		/* lint */
-	ethername= NULL;	/* lint */
-	do_temp= do_pub= 0;	/* lint */
-
-	if (n_flag + d_flag + s_flag + S_flag > 1)
-		usage();
-	if (s_flag || S_flag)
-	{
-		if (optind >= argc) usage();
-		hostname= argv[optind++];
-
-		if (optind >= argc) usage();
-		ethername= argv[optind++];
-
-		do_temp= do_pub= 0;
-		while (optind < argc) 
-		{
-			if (strcasecmp(argv[optind], "temp") == 0)
-			{
-				do_temp= 1;
-				optind++;
-				continue;
-			}
-			if (strcasecmp(argv[optind], "pub") == 0)
-			{
-				do_pub= 1;
-				optind++;
-				continue;
-			}
-			usage();
-		}
-	}
-	else if (d_flag)
-	{
-		if (!a_flag)
-		{
-			if (optind >= argc)
-				usage();
-			hostname= argv[optind++];
-			if (optind != argc)
-				usage();
-		}
-	}
-	else if (a_flag)
-	{
-		if (optind != argc)
-			usage();
-		do_setuid= 1;
-	}
-	else
-	{
-		if (optind >= argc)
-			usage();
-		hostname= argv[optind++];
-		if (optind != argc)
-			usage();
-		do_setuid= 1;
-	}
-
-	do_open(I_arg);
-	if (d_flag)
-	{
-		if (a_flag)
-			delete_all();
-		else
-			delete(hostname);
-	}
-	else if (s_flag || S_flag)
-		do_set(hostname, ethername, do_temp, do_pub, S_flag);
-	else if (a_flag)
-		show_all(n_flag);
-	else
-		show_one(hostname, n_flag);
-	exit(0);
-}
-
-static void do_open(char *devname)
-{
-	size_t l;
-	char *check;
-
-	if (do_setuid && devname)
-	{
-		/* Only strings that consist of IP_DEVICE optionally 
-		 * followed by a number are allowed.
-		 */
-		l= strlen(IP_DEVICE);
-		if (strncmp(devname, IP_DEVICE, l) != 0)
-			do_setuid= 0;
-		else if (strlen(devname) == l)
-			; /* OK */
-		else
-		{
-			strtoul(devname+l, &check, 10);
-			if (check[0] != '\0')
-				do_setuid= 0;
-		}
-	}
-	if (!devname)
-		devname= IP_DEVICE;
-	if (!do_setuid)
-	{
-		setuid(getuid());
-		setgid(getgid());
-	}
-	ipfd= open(devname, O_RDWR);
-	if (ipfd == -1)
-		fatal("unable to open '%s': %s", devname, strerror(errno));
-}
-
-static void show_one(char *hostname, int do_num)
-{
-	int r;
-	ipaddr_t ipaddr;
-	nwio_arp_t arp;
-
-	ipaddr= nametoipaddr(hostname);
-
-	arp.nwa_ipaddr= ipaddr;
-	r= ioctl(ipfd, NWIOARPGIP, &arp);
-	if (r == -1 && errno == ENOENT)
-	{
-		print_one(ipaddr, NULL, do_num);
-		exit(1);
-	}
-	if (r == -1)
-		fatal("NWIOARPGIP failed: %s", strerror(errno));
-	print_one(ipaddr, &arp, do_num);
-}
-
-static void show_all(int do_num)
-{
-	int ind, max, i, r;
-	nwio_arp_t *arptab;
-	nwio_arp_t arp;
-
-	/* First get all entries */
-	max= 10;
-	ind= 0;
-	arptab= malloc(max * sizeof(*arptab));
-	if (arptab == NULL)
-	{
-		fatal("out of memory, can't get %d bytes",
-			max*sizeof(*arptab));
-	}
-	arp.nwa_entno= 0;
-	for (;;)
-	{
-		if (ind == max)
-		{
-			max *= 2;
-			arptab= realloc(arptab, max * sizeof(*arptab));
-			if (!arptab)
-			{
-				fatal("out of memory, can't get %d bytes",
-					max*sizeof(*arptab));
-			}
-		}
-		r= ioctl(ipfd, NWIOARPGNEXT, &arp);
-		if (r == -1 && errno == ENOENT)
-			break;
-		if (r == -1)
-			fatal("NWIOARPGNEXT failed: %s", strerror(errno));
-		arptab[ind]= arp;
-		ind++;
-	}
-
-	for (i= 0; i<ind; i++)
-		print_one(0, &arptab[i], do_num);
-}
-
-static void print_one(ipaddr_t ipaddr, nwio_arp_t *arpp, int do_num)
-{
-	u32_t flags;
-	struct hostent *he;
-
-	if (arpp)
-		ipaddr= arpp->nwa_ipaddr;
-	if (!do_num)
-		he= gethostbyaddr((char *)&ipaddr, sizeof(ipaddr), AF_INET);
-	else
-		he= NULL;
-	if (he)
-		printf("%s (%s)", he->h_name, inet_ntoa(ipaddr));
-	else
-		printf("%s", inet_ntoa(ipaddr));
-	if (!arpp)
-	{
-		printf(" -- no entry\n");
-		return;
-	}
-	flags= arpp->nwa_flags;
-	if (flags & NWAF_INCOMPLETE)
-		printf(" is incomplete");
-	else if (flags & NWAF_DEAD)
-		printf(" is dead");
-	else
-	{
-		printf(" is at %s", ether_ntoa(&arpp->nwa_ethaddr));
-		if (flags & NWAF_PERM)
-			printf(" permanent");
-		if (flags & NWAF_PUB)
-			printf(" published");
-	}
-	printf("\n");
-}
-
-static void delete_all(void)
-{
-	int ind, max, i, r;
-	nwio_arp_t *arptab;
-	nwio_arp_t arp;
-
-	/* First get all entries */
-	max= 10;
-	ind= 0;
-	arptab= malloc(max * sizeof(*arptab));
-	if (arptab == NULL)
-	{
-		fatal("out of memory, can't get %d bytes",
-			max*sizeof(*arptab));
-	}
-	arp.nwa_entno= 0;
-	for (;;)
-	{
-		if (ind == max)
-		{
-			max *= 2;
-			arptab= realloc(arptab, max * sizeof(*arptab));
-			if (arptab == NULL)
-			{
-				fatal("out of memory, can't get %d bytes",
-					max*sizeof(*arptab));
-			}
-		}
-		r= ioctl(ipfd, NWIOARPGNEXT, &arp);
-		if (r == -1 && errno == ENOENT)
-			break;
-		if (r == -1)
-			fatal("NWIOARPGNEXT failed: %s", strerror(errno));
-		arptab[ind]= arp;
-		ind++;
-	}
-
-	for (i= 0; i<ind; i++)
-	{
-		r= ioctl(ipfd, NWIOARPDIP, &arptab[i]);
-		if (r == 0)
-			continue;
-		if (errno == EINVAL || errno == ENOENT)
-		{
-			/* Entry is incomplete of entry is already deleted */
-			continue;
-		}
-		fatal("unable to delete host %s: %s",
-			inet_ntoa(arptab[i].nwa_ipaddr), strerror(errno));
-	}
-}
-
-static void delete(char *hostname)
-{
-	int r;
-	ipaddr_t ipaddr;
-	nwio_arp_t arp;
-
-	ipaddr= nametoipaddr(hostname);
-	arp.nwa_ipaddr= ipaddr;
-	r= ioctl(ipfd, NWIOARPDIP, &arp);
-	if (r == 0)
-		return;
-	if (errno == ENOENT)
-	{
-		print_one(ipaddr, NULL, 0);
-		exit(1);
-	}
-	fatal("unable to delete host %s: %s", inet_ntoa(ipaddr),
-		errno == EINVAL ? "entry is incomplete" : strerror(errno));
-}
-
-static void do_set(char *hostname, char *ethername, int temp, int pub,
-	int optdelete)
-{
-	int r;
-	ipaddr_t ipaddr;
-	ether_addr_t *eap;
-	ether_addr_t ethaddr;
-	nwio_arp_t arp;
-	nwio_ipconf_t ipconf;
-
-	ipaddr= nametoipaddr(hostname);
-	if (pub && strcasecmp(ethername, "auto") == 0)
-	{
-		r= ioctl(ipfd, NWIOGIPCONF, &ipconf);
-		if (r == -1)
-			fatal("NWIOGIPCONF failed: %s", strerror(errno));
-		arp.nwa_ipaddr= ipconf.nwic_ipaddr;
-		r= ioctl(ipfd, NWIOARPGIP, &arp);
-		if (r == -1)
-			fatal("NWIOARPGIP failed: %s", strerror(errno));
-		ethaddr= arp.nwa_ethaddr;
-	}
-	else if (eap= ether_aton(ethername), eap != NULL)
-		ethaddr= *eap;
-	else if (ether_hostton(ethername, &ethaddr) != 0)
-	{
-		fatal("unable to parse ethernet address '%s'",
-			ethername);
-	}
-
-	if (optdelete)
-	{
-		arp.nwa_ipaddr= ipaddr;
-		r= ioctl(ipfd, NWIOARPDIP, &arp);
-		if (r == -1 && errno != ENOENT)
-		{
-			fatal("unable to delete entry for host %s: %s",
-				inet_ntoa(ipaddr),
-				errno == EINVAL ? "incomplete entry" :
-				strerror(errno));
-		}
-	}
-
-	arp.nwa_ipaddr= ipaddr;
-	arp.nwa_ethaddr= ethaddr;
-	arp.nwa_flags= 0;
-	if (pub)
-		arp.nwa_flags |= NWAF_PUB;
-	if (!temp)
-		arp.nwa_flags |= NWAF_PERM;
-	r= ioctl(ipfd, NWIOARPSIP, &arp);
-	if (r == -1)
-	{
-		fatal("unable to set arp entry: %s",
-			errno == EEXIST ? "entry exists" : strerror(errno));
-	}
-}
-
-static ipaddr_t nametoipaddr(char *hostname)
-{
-	ipaddr_t ipaddr;
-	struct hostent *he;
-
-	if (inet_aton(hostname, &ipaddr) == 0)
-	{
-		he= gethostbyname(hostname);
-		if (!he)
-			fatal("unknown hostname '%s'", hostname);
-		if (he->h_addrtype != AF_INET ||
-			he->h_length != sizeof(ipaddr))
-		{
-			fatal("strange host '%s': addrtype %d, length %d",
-				he->h_addrtype, he->h_length);
-		}
-		memcpy(&ipaddr, he->h_addr, sizeof(ipaddr));
-	}
-	return ipaddr;
-}
-
-#if 0
-static char *ether_ntoa(struct ether_addr *eap)
-{
-	static char buf[]= "xx:xx:xx:xx:xx:xx";
-
-	sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
-		eap->ea_addr[0], eap->ea_addr[1],
-		eap->ea_addr[2], eap->ea_addr[3],
-		eap->ea_addr[4], eap->ea_addr[5]);
-	return buf;
-}
-#endif
-
-static void fatal(char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	fprintf(stderr, "%s: ", progname);
-	vfprintf(stderr, fmt, ap);
-	fprintf(stderr, "\n");
-	va_end(ap);
-
-	exit(1);
-}
-
-static void usage(void)
-{
-	fprintf(stderr, "Usage:\tarp [-I ip-dev] [-n] hostname\n"
-		"\tarp [-I ip-dev] [-n] -a\n"
-		"\tarp [-I ip-dev] -d hostname\n"
-		"\tarp [-I ip-dev] -d -a\n"
-		"\tarp [-I ip-dev] -s hostname ether-addr [temp] [pub]\n"
-		"\tarp [-I ip-dev] -S hostname ether-addr [temp] [pub]\n");
-	exit(1);
-}
-
-/*
- * $PchId: arp.c,v 1.3 2005/01/31 22:31:45 philip Exp $
- */
Index: trunk/minix/commands/simple/at.c
===================================================================
--- trunk/minix/commands/simple/at.c	(revision 9)
+++ 	(revision )
@@ -1,223 +1,0 @@
-/* at - run a command at a specified time	Author: Jan Looyen */
-
-#include <sys/types.h>
-#include <time.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <limits.h>
-#include <signal.h>
-#include <errno.h>
-
-#define	STARTDAY	0	/* see ctime(3)	 */
-#define	LEAPDAY		STARTDAY+59
-#define	MAXDAYNR	STARTDAY+365
-#define	NODAY		-2
-char CRONPID[]	=	"/usr/run/cron.pid";
-
-_PROTOTYPE(int main, (int argc, char **argv, char **envp));
-_PROTOTYPE(int getltim, (char *t));
-_PROTOTYPE(int getlday, (char *m, char *d));
-_PROTOTYPE(int digitstring, (char *s));
-
-int main(argc, argv, envp)
-int argc;
-char **argv, **envp;
-{
-  int i, c, mask, ltim, year, lday = NODAY;
-  char buf[64], job[30], pastjob[35], *dp, *sp;
-  struct tm *p;
-  long clk;
-  FILE *fp;
-  char pwd[PATH_MAX+1];
-
-/*-------------------------------------------------------------------------*
- *	check arguments	& pipe to "pwd"				           *
- *-------------------------------------------------------------------------*/
-  if (argc < 2 || argc > 5) {
-	fprintf(stderr, "Usage: %s time [month day] [file]\n", argv[0]);
-	exit(1);
-  }
-  if ((ltim = getltim(argv[1])) == -1) {
-	fprintf(stderr, "%s: wrong time specification\n", argv[0]);
-	exit(1);
-  }
-  if ((argc == 4 || argc == 5) && (lday = getlday(argv[2], argv[3])) == -1) {
-	fprintf(stderr, "%s: wrong date specification\n", argv[0]);
-	exit(1);
-  }
-  if ((argc == 3 || argc == 5) && open(argv[argc - 1], O_RDONLY) == -1) {
-	fprintf(stderr, "%s: cannot find: %s\n", argv[0], argv[argc - 1]);
-	exit(1);
-  }
-  if (getcwd(pwd, sizeof(pwd)) == NULL) {
-	fprintf(stderr, "%s: cannot determine current directory: %s\n",
-		argv[0], strerror(errno));
-	exit(1);
-  }
-
-/*-------------------------------------------------------------------------*
- *	determine execution time and create 'at' job file		   *
- *-------------------------------------------------------------------------*/
-  time(&clk);
-  p = localtime(&clk);
-  year = p->tm_year;
-  if (lday == NODAY) {		/* no [month day] given */
-	lday = p->tm_yday;
-	if (ltim <= (p->tm_hour * 100 + p->tm_min)) {
-		lday++;
-		if ((lday == MAXDAYNR && (year % 4)) || lday == MAXDAYNR + 1) {
-			lday = STARTDAY;
-			year++;
-		}
-	}
-  } else
-	switch (year % 4) {
-	    case 0:
-		if (lday < p->tm_yday ||
-		    (lday == p->tm_yday &&
-		    ltim <= (p->tm_hour * 100 + p->tm_min))) {
-			year++;
-			if (lday > LEAPDAY) lday--;
-		}
-		break;
-	    case 1:
-	    case 2:
-		if (lday > LEAPDAY) lday--;
-		if (lday < p->tm_yday ||
-		    (lday == p->tm_yday &&
-		     ltim <= (p->tm_hour * 100 + p->tm_min)))
-			year++;
-		break;
-	    case 3:
-		if (lday < ((lday > LEAPDAY) ? p->tm_yday + 1 : p->tm_yday) ||
-		    (lday ==((lday > LEAPDAY) ? p->tm_yday + 1 : p->tm_yday) &&
-		     ltim <= (p->tm_hour * 100 + p->tm_min)))
-			year++;
-		else if (lday > LEAPDAY)
-			lday--;
-		break;
-	}
-  sprintf(job, "/usr/spool/at/%02d.%03d.%04d.%02d",
-	year % 100, lday, ltim, getpid() % 100);
-  sprintf(pastjob, "/usr/spool/at/past/%02d.%03d.%04d.%02d",
-	year % 100, lday, ltim, getpid() % 100);
-  mask= umask(0077);
-  if ((fp = fopen(pastjob, "w")) == NULL) {
-	fprintf(stderr, "%s: cannot create %s: %s\n",
-		argv[0], pastjob, strerror(errno));
-	exit(1);
-  }
-
-/*-------------------------------------------------------------------------*
- *	write environment and command(s) to 'at'job file		   *
- *-------------------------------------------------------------------------*/
-  i = 0;
-  while ((sp= envp[i++]) != NULL) {
-	dp = buf;
-	while ((c= *sp++) != '\0' && c != '=' && dp < buf+sizeof(buf)-1)
-		*dp++ = c;
-	if (c != '=') continue;
-	*dp = '\0';
-	fprintf(fp, "%s='", buf);
-	while (*sp != 0) {
-		if (*sp == '\'')
-			fprintf(fp, "'\\''");
-		else
-			fputc(*sp, fp);
-		sp++;
-	}
-	fprintf(fp, "'; export %s\n", buf);
-  }
-  fprintf(fp, "cd '%s'\n", pwd);
-  fprintf(fp, "umask %o\n", mask);
-  if (argc == 3 || argc == 5)
-	fprintf(fp, "%s\n", argv[argc - 1]);
-  else				/* read from stdinput */
-	while ((c = getchar()) != EOF) putc(c, fp);
-  fclose(fp);
-
-  if (chown(pastjob, getuid(), getgid()) == -1) {
-	fprintf(stderr, "%s: cannot set ownership of %s: %s\n",
-		argv[0], pastjob, strerror(errno));
-	unlink(pastjob);
-	exit(1);
-  }
-  /* "Arm" the job. */
-  if (rename(pastjob, job) == -1) {
-	fprintf(stderr, "%s: cannot move %s to %s: %s\n",
-		argv[0], pastjob, job, strerror(errno));
-	unlink(pastjob);
-	exit(1);
-  }
-  printf("%s: %s created\n", argv[0], job);
-
-  /* Alert cron to the new situation. */
-  if ((fp= fopen(CRONPID, "r")) != NULL) {
-	unsigned long pid;
-
-	pid= 0;
-	while ((c= fgetc(fp)) != EOF && c != '\n') {
-		if ((unsigned) (c - '0') >= 10) { pid= 0; break; }
-		pid= 10*pid + (c - '0');
-		if (pid >= 30000) { pid= 0; break; }
-	}
-	if (pid > 1) kill((pid_t) pid, SIGHUP);
-  }
-  return(0);
-}
-
-/*-------------------------------------------------------------------------*
- *	getltim()		return((time OK) ? daytime : -1)	   *
- *-------------------------------------------------------------------------*/
-int getltim(t)
-char *t;
-{
-  if (t[4] == '\0' && t[3] >= '0' && t[3] <= '9' &&
-      t[2] >= '0' && t[2] <= '5' && t[1] >= '0' && t[1] <= '9' &&
-      (t[0] == '0' || t[0] == '1' || (t[1] <= '3' && t[0] == '2')))
-	return(atoi(t));
-  else
-	return(-1);
-}
-
-/*-------------------------------------------------------------------------*
- *	getlday()		return ((date OK) ? yearday : -1)	   *
- *-------------------------------------------------------------------------*/
-int getlday(m, d)
-char *m, *d;
-{
-  int i, day, im;
-  static int cumday[] = {0, 0, 31, 60, 91, 121, 152,
-		       182, 213, 244, 274, 305, 335};
-  static struct date {
-	char *mon;
-	int dcnt;
-  } *pc, kal[] = {
-	{ "Jan", 31 }, { "Feb", 29 }, { "Mar", 31 }, { "Apr", 30 },
-	{ "May", 31 }, { "Jun", 30 }, { "Jul", 31 }, { "Aug", 31 },
-	{ "Sep", 30 }, { "Oct", 31 }, { "Nov", 30 }, { "Dec", 31 },
-  };
-
-  pc = kal;
-  im = (digitstring(m)) ? atoi(m) : 0;
-  m[0] &= 0337;
-  for (i = 1; i < 13 && strcmp(m, pc->mon) && im != i; i++, pc++);
-  if (i < 13 && (day = (digitstring(d)) ? atoi(d) : 0) && day <= pc->dcnt) {
-	if (!STARTDAY) day--;
-	return(day + cumday[i]);
-  } else
-	return(-1);
-}
-
-
-
-int digitstring(s)
-char *s;
-{
-  while (*s >= '0' && *s <= '9') s++;
-  return((*s == '\0') ? 1 : 0);
-}
Index: trunk/minix/commands/simple/backup.c
===================================================================
--- trunk/minix/commands/simple/backup.c	(revision 9)
+++ 	(revision )
@@ -1,589 +1,0 @@
-/* backup - backup a directory		Author: Andy Tanenbaum */
-
-/* This program recursively backs up a directory.  It has two typical uses:
- *
- * 1. Backing up a directory to 1 or more diskettes
- * 2. Backing up RAM disk to a shadow directory on hard disk
- *
- * The backup directory or medium may be empty, in which case, the entire
- * source directory is copied, or it may contain an old backup, in which
- * case only those files that are new or out of date are copied.  In this
- * respect, 'backup' resembles 'make', except that no 'makefile' is needed.
- * The backed up copy may optionally be compressed to save space.
- *
- * The following flags exist:
- *
- *	-d  At the top level, only back up directories (not loose files)
- *	-j  Don't copy junk: *.Z, *.bak, *.log, a.out, and core
- *	-m  If ENOSPC encountered, ask for another diskette
- *	-n  No directories, only loose files are backed up
- *	-o  Don't copy *.o files
- *	-r  Restore files (ie. uncompress if necessary)
- *	-s  Don't copy *.s files
- *	-t  Set creation date of target-file equal to cdate of source-file
- *	-v  Verbose (announce what is being done)
- *	-z  Compress on backup/uncompress on restore
- *
- * Patches:
- *	30 Mar 91.	Added restore option.  cwr. 
- *	 9 Sep 91.	Changed user interface.  cwr.
- *	21 Jan 93.	Revised error messages.  cwr.
- *	29 Mar 95.	Added -o, NARROW define.  cwr.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <utime.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <dirent.h>
-
-#define NAME_SIZE _DIRENT_NAME_LEN
-
-#undef NARROW			/* Width of verbose output */
-#define COPY_SIZE 4096
-#define MAX_ENTRIES 512
-#define MAX_PATH 256
-#define NONFATAL 0
-#define FATAL 1
-#define NO_SAVINGS 512		/* compress can return code 2 */
-#define OUT_OF_SPACE 2
-
-struct dirent dir_ent[MAX_ENTRIES];
-int entries = 0;
-
-struct sorted {
-  int mode;			/* file mode */
-  char *namep;			/* pointer to name in dir_buf */
-  long acctime;			/* time of last access */
-  long modtime;			/* time of last modification */
-} sorted[MAX_ENTRIES];
-
-char copybuf[COPY_SIZE];
-char *pname;
-int dflag, jflag, mflag, nflag, oflag, rflag, sflag, tflag, vflag, zflag;
-
-extern int errno;
-extern char **environ;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void maketarget, (char *dir2));
-_PROTOTYPE(int make_dir, (char *dir));
-_PROTOTYPE(int stat_all, (char *dir1, int n));
-_PROTOTYPE(void sort_dir, (int m));
-_PROTOTYPE(void process, (int m, char *dir1, char *dir2));
-_PROTOTYPE(void swap, (struct sorted *sp1, struct sorted *sp2));
-_PROTOTYPE(int copy, (char *dir1, struct sorted *sp, char *cbuf2));
-_PROTOTYPE(int zcopy, (char *src, char *targ));
-_PROTOTYPE(void copydir, (char *dir1, char *dir2, char *namep));
-_PROTOTYPE(void newdisk, (char *dir));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void error, (int type, char *s1, char *s2, char *s3));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int ct, n, m, fd;
-  char *dir1, *dir2, *cp, c;
-  struct stat s;
-  struct dirent *e;
-  DIR *DIR1, *DIR2;
-
-  (void) sync();
-
-  /* Get the flags */
-  if ((pname = strrchr(argv[0], '/')) == (char *)NULL)
-	pname = argv[0];
-  else
-	pname++;
-  if (argc < 3 || argc > 4) usage();
-  if (argc == 4) {
-	cp = argv[1];
-	if (*cp++ != '-') usage();
-	while ((c = *cp++) != '\0') {
-		switch (c) {
-		    case 'd':	dflag++;	break;
-		    case 'j':	jflag++;	break;
-		    case 'm':	mflag++;	break;
-		    case 'n':	nflag++;	break;
-		    case 'o':	oflag++;	break;
-		    case 's':	sflag++;	break;
-		    case 'r':	rflag++;	break;
-		    case 't':	tflag++;	break;
-		    case 'v':	vflag++;	break;
-		    case 'z':	zflag++;	break;
-		    default:	usage();
-		}
-	}
-	dir1 = argv[2];
-	dir2 = argv[3];
-  } else {
-	dir1 = argv[1];
-	dir2 = argv[2];
-  }
-  if (!strcmp(pname, "restore") && !rflag) rflag++;
-
-  /* Check for a valid source */
-  if (stat(dir1, &s) < 0) error(FATAL, "cannot stat ", dir1, "");
-  if ((s.st_mode & S_IFMT) != S_IFDIR) error(FATAL, "non-directory ", dir1, "");
-
-  /* Read in the source directory */
-  if(!(DIR1 = opendir(dir1))) {
-  	perror(dir1);
-  	return 1;
-  }
-  while(entries < MAX_ENTRIES && (e=readdir(DIR1)))
-  	memcpy(&dir_ent[entries++], e, sizeof(*e));
-  closedir(DIR1);
-  if (entries == MAX_ENTRIES)
-	error(FATAL, "directory ", dir1, " is too large");
-
-  /* Create the target directory. */
-  maketarget(dir2);
-
-  /* Stat all the entries. */
-  n = entries;
-  m = stat_all(dir1, n);
-
-  /* Remove non-entries and sort what's left. */
-  sort_dir(m);
-
-  /* Process each of the m entries one at a time. */
-  process(m, dir1, dir2);
-  return(0);
-}
-
-
-void maketarget(dir2)
-char *dir2;
-{
-/* The target directory is created if it does not already exist. */
-
-  char *p, c, dbuf[MAX_PATH];
-
-  if (access(dir2, 6) == 0)
-	return;			/* if target exists, we're done */
-  if (make_dir(dir2) == 0) return;	/* we just made it */
-
-  /* We have to try creating all the higher level directories. */
-  strcpy(dbuf, dir2);
-  p = dbuf + 1;
-  while (1) {
-	while (*p != '/' && *p != '\0') p++;
-	c = *p;			/* either / or \0 */
-	*p = 0;
-	make_dir(dbuf);
-	if (c == '\0') return;
-	*p = c;
-	p++;
-  }
-}
-
-int make_dir(dir)
-char *dir;
-{
-/* Create a directory. */
-  int pid, status;
-
-  if ((pid = fork()) < 0)
-	error(FATAL, "cannot fork off mkdir to create ", dir, "");
-  if (pid > 0) {
-	/* Parent process waits for child (mkdir). */
-	wait(&status);
-	return(status);
-  } else {
-	/* Child process executes mkdir */
-	close(2);		/* don't want mkdir's error messages */
-	execle("/bin/mkdir", "mkdir", dir, (char *) 0, environ);
-	execle("/usr/bin/mkdir", "mkdir", dir, (char *) 0, environ);
-	error(FATAL, "cannot execute mkdir", "", "");
-  }
-  return(0);
-}
-
-
-int stat_all(dir1, n)
-char *dir1;
-int n;
-{
-/* Stat all the directory entries.  By doing this all at once, the disk
- * head can stay in the inode area.
- */
-
-  int i, j;
-  char cbuf[MAX_PATH];
-  struct stat s;
-
-  for (i = 0; i < n; i++) {
-	/* Mark "." and ".." as null entries, as well as unstatable ones. */
-	if (strcmp(dir_ent[i].d_name, ".") == 0) dir_ent[i].d_ino = 0;
-	if (strcmp(dir_ent[i].d_name, "..") == 0) dir_ent[i].d_ino = 0;
-	if (dir_ent[i].d_ino == 0) continue;
-
-	/* Stat the file. */
-	snprintf(cbuf, sizeof(cbuf), "%s/%s", dir1, dir_ent[i].d_name);
-	if (stat(cbuf, &s) < 0) {
-		error(NONFATAL, "cannot stat ", cbuf, "");
-		dir_ent[i].d_ino = 0;	/* mark as unusable */
-		continue;
-	}
-	sorted[i].mode = s.st_mode;
-	sorted[i].acctime = s.st_atime;
-	sorted[i].modtime = s.st_mtime;
-	sorted[i].namep = dir_ent[i].d_name;
-	sorted[i].namep[NAME_SIZE-1] = '\0';
-  }
-
-  /* Squeeze out all the entries whose ino field is 0. */
-  j = 0;
-  for (i = 0; i < n; i++) {
-	if (dir_ent[i].d_ino != 0) {
-		sorted[j] = sorted[i];
-		j++;
-	}
-  }
-  return(j);
-}
-
-
-void sort_dir(m)
-int m;
-{
-/* Sort the directory using bubble sort. */
-
-  struct sorted *sp1, *sp2;
-
-  for (sp1 = &sorted[0]; sp1 < &sorted[m - 1]; sp1++) {
-	for (sp2 = sp1 + 1; sp2 < &sorted[m]; sp2++) {
-		if (strcmp(sp1->namep, sp2->namep) > 0)
-			swap(sp1, sp2);
-	}
-  }
-}
-
-
-void process(m, dir1, dir2)
-int m;
-char *dir1, *dir2;
-{
-/* Process each entry in sorted[].  If it is a regular file, stat the target
- * file.  The the source is newer, copy it.  If the entry is a directory,
- * recursively call the entire program to process the directory.
- */
-
-  int er, fmode, res;
-  struct sorted *sp;
-  struct stat s;
-  char cbuf[MAX_PATH];
-
-  for (sp = &sorted[0]; sp < &sorted[m]; sp++) {
-  	int namlen;
-	fmode = sp->mode & S_IFMT;
-	if (fmode == S_IFREG) {
-		/* Regular file.  Construct target name and stat it. */
-		snprintf(cbuf, sizeof(cbuf), "%s/%s", dir2, sp->namep);
-		namlen = strlen(sp->namep);
-		/* Switch between compressed and uncompressed file names */
-		if (zflag && !rflag && strncmp((sp->namep + namlen - 2), ".Z", (size_t)2)
-				&& (namlen <= (NAME_SIZE - 2)))
-			strncat(cbuf, ".Z", (size_t)2);
-		if (zflag && rflag && !strncmp((sp->namep + namlen - 2), ".Z", (size_t)2))
-			cbuf[strlen(cbuf) - 2] = '\0';
-		er = stat(cbuf, &s);
-		if (er < 0 || sp->modtime > s.st_mtime) {
-			res = copy(dir1, sp, cbuf);
-		} else {
-			res = NONFATAL;
-		}
-
-		/* Check status of the copy. */
-		if (res == OUT_OF_SPACE) {
-			printf("Out of space while copying to %s\n", cbuf);
-			/* We ran out of space copying a regular file. */
-			if (mflag == 0)
-				error(FATAL, "Quitting, disk full", "", "");
-
-			/* If -m, ask for new diskette and continue. */
-			newdisk(dir2);
-			sp--;
-			continue;
-		}
-	} else if (fmode == S_IFDIR) {
-		/* Directory.  Execute this program recursively. */
-		copydir(dir1, dir2, sp->namep);
-	} else if (fmode == S_IFBLK || fmode == S_IFCHR) {
-		/* Special file. */
-		strncpy(cbuf, sp->namep, sizeof(cbuf));
-		printf("%s is special file.  Not backed up.\n", cbuf);
-	}
-  }
-}
-
-
-
-
-void swap(sp1, sp2)
-struct sorted *sp1, *sp2;
-{
-/* Swap two directory entries. */
-
-  struct sorted d;
-
-  d = *sp1;
-  *sp1 = *sp2;
-  *sp2 = d;
-}
-
-
-int copy(dir1, sp, cbuf2)
-struct sorted *sp;
-char *dir1, *cbuf2;
-{
-/* Copy a regular file. */
-
-  int fd1, fd2, nr, nw, res, n;
-  char cbuf1[MAX_PATH], *p;
-#ifdef NARROW
-  char *msg = (rflag || strcmp(pname, "backup")) ? "Restored" : "Backing up";
-#endif
-
-  /* If the -j or -o or -s flags were given, suppress certain files. */
-  p = sp->namep;
-  n = strlen(p);
-  if (n > NAME_SIZE) n = NAME_SIZE;
-  if (jflag) {
-	if (strcmp(p, "a.out") == 0) return(0);
-	if (strcmp(p, "core") == 0) return (0);
-	if (strcmp(p + n - 2, ".Z") == 0) return (0);
-	if (strcmp(p + n - 4, ".bak") == 0) return (0);
-	if (strcmp(p + n - 4, ".log") == 0) return (0);
-  }
-  if (oflag) {
-	if (strcmp(p + n - 2, ".o") == 0) return(0);
-  }
-  if (sflag) {
-	if (strcmp(p + n - 2, ".s") == 0) return(0);
-  }
-  res = 0;
-  if (dflag) return(0);		/* backup -d means only directories */
-  strcpy(cbuf1, dir1);
-  strncat(cbuf1, "/", (size_t)1);
-  strncat(cbuf1, sp->namep, (size_t)NAME_SIZE);	/* cbuf1 = source file name */
-
-  /* At this point, cbuf1 contains the source file name, cbuf2 the target. */
-  fd1 = open(cbuf1, O_RDONLY);
-  if (fd1 < 0) {
-	error(NONFATAL, "cannot open ", cbuf1, "");
-	return(res);
-  }
-  fd2 = creat(cbuf2, (sp->mode | S_IWUSR) & 07777);
-  if (fd2 < 0) {
-	if (errno == ENFILE) {
-		close(fd1);
-		return(OUT_OF_SPACE);
-	}
-	error(NONFATAL, "cannot create ", cbuf2, "");
-	close(fd1);
-	return(res);
-  }
-
-  /* Both files are now open.  Do the copying. */
-  if (!rflag && strncmp((sp->namep + n - 2), ".Z", (size_t)2) ||
-		rflag && !strncmp((sp->namep + n - 2), ".Z", (size_t)2)) {
-	if (zflag && (rflag || (n <= (NAME_SIZE - 2)))) {
-		close(fd1);
-		close(fd2);
-		res = zcopy(cbuf1, cbuf2);
-		if (tflag) utime(cbuf2, (struct utimbuf *) & (sp->acctime));
-		if (res != 0) unlink(cbuf2); /* if error, get rid of the corpse */
-#ifdef NARROW
-		if (vflag && res == 0) printf("%s %s\n", msg, cbuf1);
-#else
-		if (vflag && res == 0) {
-			printf("%-37.37s -> %-37.37s\n", cbuf1, cbuf2);
-			if (strlen(cbuf1) > 37 || strlen(cbuf2) > 37)
-				printf("%37.37s    %37.37s\n",
-				(strlen(cbuf1) > 37) ? (cbuf1 + 37) : "",
-				(strlen(cbuf2) > 37) ? (cbuf2 + 37) : "");
-		}
-#endif
-		return(res);
-	}
-  }
-  while (1) {
-	nr = read(fd1, copybuf, COPY_SIZE);
-	if (nr == 0) break;
-	if (nr < 0) {
-		error(NONFATAL, "read error on ", cbuf1, "");
-		res = EIO;
-		break;
-	}
-	nw = write(fd2, copybuf, nr);
-	if (nw < 0) {
-		if (errno == ENOSPC) {
-			/* Device is full. */
-			res = OUT_OF_SPACE;
-			break;
-		}
-
-		/* True write error. */
-		error(NONFATAL, "write error on ", cbuf2, "");
-		res = EIO;
-		break;
-	}
-  }
-  if (res == 0) {
-#ifdef NARROW
- 	if (vflag) printf("%s %s\n", msg, cbuf1);
-#else
-	if (vflag) {
-		printf("%-37.37s -> %-37.37s\n", cbuf1, cbuf2);
-		if (strlen(cbuf1) > 37 || strlen(cbuf2) > 37)
-			printf("%37.37s    %37.37s\n",
-			(strlen(cbuf1) > 37) ? (cbuf1 + 37) : "",
-			(strlen(cbuf2) > 37) ? (cbuf2 + 37) : "");
-	}
-#endif
-  } else {
-	unlink(cbuf2);
-  }
-  close(fd1);
-  close(fd2);
-  if (tflag) utime(cbuf2, (struct utimbuf *) & (sp->acctime));
-  return(res);
-}
-
-
-int zcopy(src, targ)
-char *src, *targ;
-{
-
-  int pid, status, res, s;
-  char fbuf[20];
-
-  /* These flags go for compress and gzip. */
-  strcpy(fbuf, "-c");
-  if (rflag)
-	strcat(fbuf, "d");
-  else
-	strcat(fbuf, "f");
-
-  if ((pid = fork()) < 0) error(FATAL, "cannot fork", "", "");
-  if (pid > 0) {
-	wait(&status);
-
-	/* Error codes 0 and 2 are ok, assume others mean disk is full. */
-	res = (status == 0 || status == NO_SAVINGS ? 0 : OUT_OF_SPACE);
-	return(res);
-  } else {
-	/* Child must execute compress. */
-	close(1);
-	s = open(targ, O_RDWR);
-	if (s < 0) error(FATAL, "cannot write on ", "targ", "");
-	execle("/usr/bin/gzip", "gzip", fbuf, src, (char *)0, environ);
-	execle("/usr/local/bin/gzip", "gzip", fbuf, src, (char *)0, environ);
-	execle("/bin/compress", "compress", fbuf, src, (char *)0, environ);
-	execle("/usr/bin/compress", "compress", fbuf, src, (char *)0, environ);
-	error(FATAL, "cannot exec gzip or compress", "", "");
-  }
-  return(0);
-}
-
-
-void copydir(dir1, dir2, namep)
-char *dir1, *dir2, *namep;
-{
-/* Copy a directory. */
-
-  int pid, status;
-  char fbuf[20], d1buf[MAX_PATH], d2buf[MAX_PATH];
-
-  if (nflag) return;	/* backup -n means no directories */
-
-  fbuf[0] = '\0';
-
-  /* Handle directory copy by forking off 'backup' ! */
-  if (jflag || mflag || oflag || rflag || sflag || tflag || vflag || zflag)
-	strcpy(fbuf, "-");
-  if (jflag) strcat(fbuf, "j");
-  if (mflag) strcat(fbuf, "m");
-  if (oflag) strcat(fbuf, "o");
-  if (rflag) strcat(fbuf, "r");
-  if (sflag) strcat(fbuf, "s");
-  if (tflag) strcat(fbuf, "t");
-  if (vflag) strcat(fbuf, "v");
-  if (zflag) strcat(fbuf, "z");
-  snprintf(d1buf, sizeof(d1buf), "%s/%s", dir1, namep);
-  snprintf(d2buf, sizeof(d2buf), "%s/%s", dir2, namep);
-
-  if ((pid = fork()) < 0) error(FATAL, "cannot fork", "", "");
-  if (pid > 0) {
-	/* Parent waits for child, then returns. */
-	wait(&status);
-	return;
-  }
-
-  if (fbuf[0] == '-') {
-	execle(pname, pname, fbuf, d1buf, d2buf, (char *) 0, environ);
-	execle("/bin/backup", "backup", fbuf, d1buf, d2buf, (char *)0,environ);
-	execle("/usr/bin/backup","backup",fbuf,d1buf,d2buf,(char *)0,environ);
-	error(FATAL, "cannot recursively exec backup", "", "");
-  } else {
-	execle(pname, pname, d1buf, d2buf, (char *) 0, environ);
-	execle("/bin/backup", "backup", d1buf, d2buf, (char *)0,environ);
-	execle("/usr/bin/backup","backup", d1buf, d2buf, (char *)0,environ);
-	error(FATAL, "cannot recursively exec backup", "", "");
-  }
-}
-
-void newdisk(dir)
-char *dir;
-{
-/* Ask for a new diskette. A big problem is that this program does not
- * know which device is being used and where it is mounted on.  As an
- * emergency solution, fork off a shell and ask the user to do the work.
- */
-
-  int pid, status;
-
-  printf("\nDiskette full. Please do the following:\n");
-  printf("   1. Unmount the diskette using /etc/umount\n");
-  printf("   2. Physically replace the diskette by the next one.\n");
-  printf("   3. Mount the new diskette using /etc/mount\n");
-  printf("   4. Type CTRL-D to return to the backup/restore program\n");
-
-  if ((pid = fork()) < 0) error(FATAL, "cannot fork", "", "");
-  if (pid > 0) {
-	wait(&status);
-	maketarget(dir);	/* make the directory */
-  } else {
-	execle("/bin/sh", "sh", "-i", (char *) 0, environ);
-	execle("/usr/bin/sh", "sh", "-i", (char *) 0, environ);
-	error(FATAL, "cannot execute shell to ask for new diskette", "", "");
-  }
-}
-
-void usage()
-{
-  fprintf(stderr, "Usage: %s [-djmnorstvz] dir1 dir2\n", pname);
-  exit(2);
-}
-
-
-void error(type, s1, s2, s3)
-int type;
-char *s1, *s2, *s3;
-{
-  fprintf(stderr, "%s: %s%s%s\n", pname, s1, s2, s3);
-
-  if (type == NONFATAL)
-	return;
-  else
-	exit(type);
-}
Index: trunk/minix/commands/simple/badblocks.c
===================================================================
--- trunk/minix/commands/simple/badblocks.c	(revision 9)
+++ 	(revision )
@@ -1,657 +1,0 @@
-/* badblocks - collect bad blocks in a file	Author: Jacob Bunschoten */
-
-/* Usage "badblocks block_special [Up_to_7_blocks]" */
-
-/* This program is written to handle BADBLOCKS on a hard or floppy disk.
- * The program asks for block_numbers. These numbers can be obtained with
- * the program readall, written by A. Tanenbaum.  It then creates a
- * file on the disk containing up to 7 bad blocks.
- *
- * BUG:
- *
- *	When the zone_size > block_size it can happen that
- *	the zone is already allocated. This means some
- *	file is using this zone and may use all the blocks including
- *	the bad one. This can be cured by inspecting the zone_bitmap
- *	(is already done) and change the file if this zone is used.
- *	This means that another zone must be allocated and
- *	the inode wich claims this zone must be found and changed.
- *
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <minix/config.h>
-#include <minix/type.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <stdlib.h>
-
-#include "../../servers/fs/const.h"	/* must be included before stdio.h */
-#undef printf			/* so its define of printf can be undone */
-#include "../../servers/fs/type.h"
-
-#include <string.h>
-#include <stdio.h>
-
-#define EXTERN extern
-#include "../../servers/fs/super.h"
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void rw_super, (int flag));
-_PROTOTYPE(void get_super, (void));
-_PROTOTYPE(void put_super, (void));
-_PROTOTYPE(void rw_inode, (struct stat * stat_ptr, int rw_mode));
-_PROTOTYPE(void get_inode, (struct stat * stat_ptr));
-_PROTOTYPE(void put_inode, (struct stat * stat_ptr));
-_PROTOTYPE(long rd_cmdline, (int argc, char *argv[]));
-_PROTOTYPE(void modify, (int nr_blocks));
-_PROTOTYPE(void save_blk, (block_t blk_num));
-_PROTOTYPE(void reset_blks, (void));
-_PROTOTYPE(void show_blks, (void));
-_PROTOTYPE(int blk_is_used, (block_t blk_num));
-_PROTOTYPE(int blk_ok, (block_t num));
-_PROTOTYPE(void set_bit, (zone_t num));
-_PROTOTYPE(long rd_num, (void));
-_PROTOTYPE(int ok, (char *str));
-_PROTOTYPE(void done, (int nr));
-
-/* 		Super block table.
- *
- * 	The disk layout is:
- *
- *      Item        # block
- *    boot block      1
- *    super block     1
- *    inode map     s_imap_blocks
- *    zone map      s_zmap_blocks
- *    inodes        (s_ninodes + 1 + inodes_per_block - 1)/inodes_per_block
- *    unused
- *    data zones    (s_nzones - s_firstdatazone) << s_log_zone_size
- *
- */
-
-#define OK	0
-#define NOT_OK	1
-#define QUIT	2
-
-#define READ 	0
-#define WRITE	1
-
-#define HARMLESS	0
-#define DIR_CREATED	1
-#define DEV_MOUNTED	2
-#define FILE_EXISTS	3
-#define SUCCESS		4
-
-#define BYTE         0377
-#define BLOCK_SIZE   1024
-#define SIZE_OF_INT   (sizeof (int) )
-
-/* Define V_NR_DZONES as the larger of V1_NR_DZONES and V2_NR_DZONES. */
-#if (V1_NR_DZONES > V2_NR_DZONES)
-#define V_NR_DZONES V1_NR_DZONES
-#define V_SMALLER   V2_NR_DZONES
-#else
-#define V_NR_DZONES V2_NR_DZONES
-#define V_SMALLER   V1_NR_DZONES
-#endif
-
-#if 0
-struct super_block {
-  ino_t s_ninodes;		/* # usable inodes on the minor device */
-  zone1_t s_nzones;		/* total device size, including bit maps etc */
-  short s_imap_blocks;		/* # of blocks used by inode bit map */
-  short s_zmap_blocks;		/* # of blocks used by zone bit map */
-  zone1_t s_firstdatazone;	/* number of first data zone */
-  short s_log_zone_size;	/* log2 of blocks/zone */
-  off_t s_max_size;		/* maximum file size on this device */
-  short s_magic;		/* magic number to recognize super-blocks */
-  short s_pad;			/* try to avoid compiler-dependent padding */
-  zone_t s_zones;		/* number of zones (replaces s_nzones in V2) */
-} super_block;
-#endif
-
- /* ====== globals ======= */
-
-char *dev_name;
-char f_name[] = ".Bad_XXXXXX";
-char file_name[50];
-char dir_name[] = "/tmpXXXXXX";
-
-block_t block[V_NR_DZONES + 1];	/* last block contains zero */
-int interactive;		/* 1 if interactive (argc == 2) */
-int position = 2;		/* next block # is argv[position] */
-
-FILE *f;
-int fd;
-int eofseen;			/* set if '\n' seen */
-struct stat stat_buf;
-struct super_block *sp, sbs;
-int inodes_per_block;
-size_t inode_size;
-int v1fs = 0, v2fs = 0;			/* TRUE for V1 file system, FALSE for V2 */
-
-d1_inode d1inode;		/* declare a V1 disk inode */
-d1_inode *ip1;
-d2_inode d2inode;		/* declare a V2 disk inode */
-d2_inode *ip2;
-
-
- /* ====== super block routines ======= */
-
-void rw_super(flag)
-int flag;
-{				/* read or write a superblock */
-  int rwd;
-
-  lseek(fd, 0L, SEEK_SET);	/* rewind */
-  lseek(fd, (long) BLOCK_SIZE, SEEK_SET);	/* seek */
-
-  if (flag == READ)
-	rwd = read(fd, (char *) sp, SUPER_SIZE);
-  else
-	rwd = write(fd, (char *) sp, SUPER_SIZE);
-  if (rwd != SUPER_SIZE) {	/* ok ? */
-	printf("Bad %s in get_super() (should be %u is %d)\n",
-	       flag == READ ? "read" : "write",
-	       (unsigned) SUPER_SIZE, rwd);
-	done(DIR_CREATED);
-  }
-}
-
-void get_super()
- /* Get super_block. global pointer sp is used */
-{
-  rw_super(READ);
-
-  if (sp->s_magic == SUPER_MAGIC) {
-	/* This is a V1 file system. */
-	v1fs = 1;		/* file system is not V2 */
-  } else if (sp->s_magic == SUPER_V2) {
-	/* This is a V2 file system. */
-	v2fs = 1;		/* this is a V2 file system */
-  } else if (sp->s_magic == SUPER_V3) {
-	v1fs = v2fs = 0;		/* this is a V3 file system */
-  } else {
-	/* Neither V1 nor V2 nor V3. */
-	printf("Bad magic number in super_block (0x%x)\n",
-	       (unsigned) sp->s_magic);
-	done(DIR_CREATED);
-  }
-}
-
-
-void put_super()
-{
-  rw_super(WRITE);
-}
-
- /* ========== inode routines =========== */
-
-void rw_inode(stat_ptr, rw_mode)
-struct stat *stat_ptr;
-int rw_mode;
-{
-  int rwd;
-  ino_t i_num;
-  block_t blk, offset;
-
-
-  i_num = stat_ptr->st_ino;
-
-  blk = (block_t) (2 + sp->s_imap_blocks + sp->s_zmap_blocks);
-  blk += (block_t) ((i_num - 1) / inodes_per_block);
-  blk *= (block_t) (BLOCK_SIZE);/* this block */
-
-  offset = (block_t) ((i_num - 1) % inodes_per_block);
-  offset *= (block_t) (inode_size);	/* and this offset */
-
-  lseek(fd, (off_t) 0, SEEK_SET);	/* rewind */
-  lseek(fd, (off_t) (blk + offset), SEEK_SET);	/* seek */
-
-  /* Pointer is at the inode */
-  if (v1fs) {
-	/* This is a V1 file system. */
-	if (rw_mode == READ) {	/* read it */
-		rwd = read(fd, (char *) ip1, inode_size);
-	} else {		/* write it */
-		rwd = write(fd, (char *) ip1, inode_size);
-	}
-  } else {
-	/* This is a V2 file system. */
-	if (rw_mode == READ) {	/* read it */
-		rwd = read(fd, (char *) ip2, inode_size);
-	} else {		/* write it */
-		rwd = write(fd, (char *) ip2, inode_size);
-	}
-  }
-
-  if (rwd != inode_size) {	/* ok ? */
-	printf("Bad %s in get_inode()\n", (rw_mode == READ) ? "read" :
-	       "write");
-	done(DIR_CREATED);
-  }
-}
-
-void get_inode(stat_ptr)
-struct stat *stat_ptr;
-{
-
-  int cnt;
-
-  rw_inode(stat_ptr, READ);
-
-  if (v1fs) {
-	for (cnt = 0; cnt < V1_NR_TZONES; cnt++)
-		ip1->d1_zone[cnt] = 0;	/* Just to be safe */
-  } else {
-	for (cnt = 0; cnt < V2_NR_TZONES; cnt++)
-		ip2->d2_zone[cnt] = 0;	/* Just to be safe */
-  }
-}
-
-void put_inode(stat_ptr)
-struct stat *stat_ptr;
-{
-  rw_inode(stat_ptr, WRITE);
-}
-
-
- /* ==============  main program ================= */
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int cnt, finished;
-  block_t blk_nr;
-  struct stat dev_stat;
-  FILE *fp;
-  int block_size;
-
-  sp = &sbs;
-  ip1 = &d1inode;
-  ip2 = &d2inode;
-
-  if (argc < 2 || argc > 9) {
-	fprintf(stderr, "Usage: %s block_special [up_to_7_blocks]\n", argv[0]);
-	done(HARMLESS);
-  }
-  interactive = (argc == 2 ? 1 : 0);
-
-  /* Do some test. */
-  if (geteuid()) {
-	printf("Sorry, not in superuser mode \n");
-	printf("Set_uid bit must be on or you must become super_user\n");
-	done(HARMLESS);
-  }
-  dev_name = argv[1];
-  mktemp(dir_name);
-  if (mkdir(dir_name, 0777) == -1) {
-	fprintf(stderr, "%s is already used in system\n", dir_name);
-	done(HARMLESS);
-  }
-
-  /* Mount device. This call may fail. */
-  mount(dev_name, dir_name, 0);
-  /* Succes. dev was mounted, try to umount */
-
-  /* Umount device. Playing with the file system while other processes
-   * have access to this device is asking for trouble */
-  if (umount(dev_name) == -1) {
-	printf("Could not umount device %s.\n", dev_name);
-	done(HARMLESS);
-  }
-  mktemp(f_name);
-  /* Create "/tmpXXXXpid/.BadXXpid" */
-  strcat(file_name, dir_name);
-  strcat(file_name, "/");
-  strcat(file_name, f_name);
-
-  if (mount(dev_name, dir_name, 0) == -1) {	/* this call should work */
-	fprintf(stderr, "Could not mount device anymore\n");
-	done(HARMLESS);
-  }
-  if (stat(file_name, &stat_buf) != -1) {
-	printf("File %s already exists\n", file_name);
-	done(DEV_MOUNTED);
-  }
-  if ((fp = fopen(file_name, "w")) == NULL) {
-	printf("Cannot create file %s\n", file_name);
-	done(DEV_MOUNTED);
-  }
-  chmod(file_name, 0);		/* "useless" file */
-  if (stat(file_name, &stat_buf) == -1) {
-	printf("What? Second call from stat failed\n");
-	done(FILE_EXISTS);
-  }
-
-  /* Stat buf must be safed. We can now calculate the inode on disk */
-  fclose(fp);
-
-  /* ===== the badblock file is created ===== */
-
-  if (umount(dev_name) == -1) {
-	printf("Can not umount device anymore??? \n");
-	done(DIR_CREATED);
-  }
-  if ((fd = open(dev_name, O_RDWR)) == -1) {
-	printf("Can not open device %s\n", dev_name);
-	done(DEV_MOUNTED);
-  }
-  if (fstat(fd, &dev_stat) == -1) {
-	printf("fstat on device %s failed\n", dev_name);
-	done(DEV_MOUNTED);
-  }
-  if ((dev_stat.st_mode & S_IFMT) != S_IFBLK) {
-	printf("Device \"%s\" is not a block_special.\n", dev_name);
-	done(DEV_MOUNTED);
-  }
-  get_super();
-  if (sp->s_log_zone_size) {
-	printf("Block_size != zone_size.");
-	printf("This program can not handle it\n");
-	done(DIR_CREATED);
-  }
-  if(v1fs || v2fs) block_size = 1024;
-  else block_size = sp->s_block_size;
-
-  /* The number of inodes in a block differs in V1 and V2. */
-  if (v1fs) {
-	inodes_per_block = V1_INODES_PER_BLOCK;
-	inode_size = V1_INODE_SIZE;
-  } else {
-	inodes_per_block = V2_INODES_PER_BLOCK(block_size);
-	inode_size = V2_INODE_SIZE;
-  }
-
-  get_inode(&stat_buf);
-
-  for (finished = 0; !finished;) {
-	if (interactive)
-		printf("Give up to %d bad block numbers separated by spaces\n",
-		       V_SMALLER);
-	reset_blks();
-	cnt = 0;		/* cnt keep track of the zone's */
-	while (cnt < V_SMALLER) {
-		int tst;
-
-		if (interactive)
-			blk_nr = rd_num();
-		else
-			blk_nr = rd_cmdline(argc, argv);
-		if (blk_nr == -1) break;
-		tst = blk_ok(blk_nr);
-
-		/* Test if this block is free */
-		if (tst == OK) {
-			cnt++;
-			save_blk(blk_nr);
-		} else if (tst == QUIT)
-			break;
-	}
-	if (interactive) show_blks();
-	if (!cnt) done(FILE_EXISTS);
-	if (interactive) {
-		switch (ok("All these blocks ok <y/n/q> (y:Device will change) ")) {
-		    case OK:	finished = 1;	break;
-		    case NOT_OK:
-			break;
-		    case QUIT:	done(FILE_EXISTS);
-		}
-	} else {
-		finished = 1;
-	}
-  }
-
-  modify(cnt);
-  close(fd);			/* free device */
-  done(SUCCESS);
-  return(0);
-}
-
-long rd_cmdline(argc, argv)
-int argc;
-char *argv[];
-{
-  if (position == argc) return(-1);
-  return(atol(argv[position++]));
-}
-
-
-void modify(nr_blocks)
-int nr_blocks;
-{
-  int i;
-
-  if (nr_blocks == 0) return;
-  if (v1fs) {
-	/* This is a V1 file system. */
-	for (i = 0; i < nr_blocks; i++) {
-		set_bit(block[i]);
-		ip1->d1_zone[i] = block[i];
-	}
-  } else {
-	/* This is a V2 file system. */
-	for (i = 0; i < nr_blocks; i++) {
-		set_bit(block[i]);
-		ip2->d2_zone[i] = block[i];
-	}
-  }
-  if (v1fs) {
-	ip1->d1_size = (long) (BLOCK_SIZE * nr_blocks);	/* give file size */
-	ip1->d1_mtime = 0;	/* Who wants a file from 1970? */
-  } else {
-	ip2->d2_size = (long) (BLOCK_SIZE * nr_blocks);	/* give file size */
-	ip2->d2_atime = ip2->d2_mtime = ip2->d2_ctime = 0;
-  }
-
-  put_inode(&stat_buf);		/* save the inode on disk */
-  put_super();			/* bit_maps too */
-}
-
-
-static blk_cnt = 0;
-
-void save_blk(blk_num)
-block_t blk_num;
-{
-  block[blk_cnt++] = blk_num;
-}
-
-void reset_blks()
-{
-  int i;
-
-  for (i = 0; i <= V_NR_DZONES; i++)
-	block[i] = 0;		/* Note: Last block_number is set to zero */
-  blk_cnt = 0;
-}
-
-void show_blks()
-{
-  int i;
-
-  for (i = 0; i < blk_cnt; i++)
-	printf("Block[%d] = %lu\n", i, (unsigned long) block[i]);
-}
-
-int blk_is_used(blk_num)
-block_t blk_num;
-{				/* return TRUE(1) if used */
-  int i;
-
-  for (i = 0; block[i] && block[i] != blk_num; i++);
-  return(block[i] != 0) ? 1 : 0;
-}
-
-
- /* ===== bitmap handling ======	 */
-
-#define BIT_MAP_SHIFT	13
-#define INT_BITS	(SIZE_OF_INT << 3)
-
-int blk_ok(num)			/* is this zone free (y/n) */
-block_t num;
-{
-  block_t blk_offset;
-  int rd;
-  int blk, offset, words, bit, tst_word;
-  zone_t z_num;
-
-  if (blk_is_used(num)) {
-	printf("Duplicate block (%lu) given\n", (unsigned long) num);
-	return NOT_OK;
-  }
-
-  /* Assumption zone_size == block_size */
-
-  z_num = num - (sp->s_firstdatazone - 1);	/* account offset */
-
-  /* Calculate the word in the bitmap. */
-  blk = z_num >> BIT_MAP_SHIFT;	/* which block */
-  offset = z_num - (blk << BIT_MAP_SHIFT);	/* offset */
-  words = z_num / INT_BITS;	/* which word */
-
-  blk_offset = (block_t) (2 + sp->s_imap_blocks);	/* zone map */
-  blk_offset *= (block_t) BLOCK_SIZE;	/* of course in block */
-  blk_offset += (block_t) (words * SIZE_OF_INT);	/* offset */
-
-
-  lseek(fd, (off_t) 0, SEEK_SET);	/* rewind */
-  lseek(fd, (off_t) blk_offset, SEEK_SET);	/* set pointer at word */
-
-  rd = read(fd, (char *) &tst_word, SIZE_OF_INT);
-  if (rd != SIZE_OF_INT) {
-	printf("Read error in bitmap\n");
-	done(DIR_CREATED);
-  }
-
-  /* We have the tst_word, check if bit was off */
-  bit = offset % INT_BITS;
-
-  if (((tst_word >> bit) & 01) == 0)	/* free */
-	return OK;
-  else {
-	printf("Bad number %lu. ", (unsigned long) num);
-	printf("This zone (block) is marked in bitmap\n");
-	return NOT_OK;
-  }
-}
-
-void set_bit(num)		/* write in the bitmap */
-zone_t num;
-{
-  int rwd;
-  long blk_offset;
-  int blk, offset, words, tst_word, bit;
-  unsigned z_num;
-
-  z_num = num - (sp->s_firstdatazone - 1);
-
-  blk = z_num >> BIT_MAP_SHIFT;	/* which block */
-  offset = z_num - (blk << BIT_MAP_SHIFT);	/* offset in block */
-  words = z_num / INT_BITS;	/* which word */
-
-  blk_offset = (long) (2 + sp->s_imap_blocks);
-  blk_offset *= (long) BLOCK_SIZE;
-  blk_offset += (long) (words * SIZE_OF_INT);
-
-
-  lseek(fd, (off_t) 0, SEEK_SET);	/* rewind */
-  lseek(fd, (off_t) blk_offset, SEEK_SET);
-
-  rwd = read(fd, (char *) &tst_word, SIZE_OF_INT);
-  if (rwd != SIZE_OF_INT) {
-	printf("Read error in bitmap\n");
-	done(DEV_MOUNTED);
-  }
-  bit = offset % INT_BITS;
-  if (((tst_word >> bit) & 01) == 0) {	/* free */
-	lseek(fd, 0L, SEEK_SET);/* rewind */
-	lseek(fd, (off_t) blk_offset, SEEK_SET);
-	tst_word |= (1 << bit);	/* not free anymore */
-	rwd = write(fd, (char *) &tst_word, SIZE_OF_INT);
-	if (rwd != SIZE_OF_INT) {
-		printf("Bad write in zone map\n");
-		printf("Check file system \n");
-		done(DIR_CREATED);
-	}
-	return;
-  }
-  printf("Bit map indicates that block %lu is in use. Not marked.\n",
-	 (unsigned long) num);
-/*  done(DIR_CREATED); */
-  return;
-}
-
- /* ======= interactive interface ======= */
-
-long rd_num()
-{				/* read a number from stdin */
-  long num;
-  int c;
-
-  if (eofseen) return(-1);
-  do {
-	c = getchar();
-	if (c == EOF || c == '\n') return(-1);
-  } while (c != '-' && (c < '0' || c > '9'));
-
-  if (c == '-') {
-	printf("Block numbers must be positive\n");
-	exit(1);
-  }
-  num = 0;
-  while (c >= '0' && c <= '9') {
-	num *= 10;
-	num += c - '0';
-	c = getchar();
-	if (c == '\n') eofseen = 1;
-  }
-  return num;
-}
-
-
-
-int ok(str)
-char *str;
-{
-  int c;
-
-  for (;;) {
-	printf("%s", str);
-	while ((c = getchar()) != EOF &&
-	       c != 'y' && c != 'n' && c != 'q')
-		if (c != '\n') printf(" Bad character %c\n", (char) c);
-	switch (c) {
-	    case EOF:
-		return QUIT;
-	    case 'y':
-		return OK;
-	    case 'n':
-		return NOT_OK;
-	    case 'q':	return QUIT;
-	}
-	printf("\n");
-  }
-}
-
-
-void done(nr)
-int nr;
-{
-  switch (nr) {
-      case SUCCESS:
-      case FILE_EXISTS:
-	unlink(file_name);
-      case DEV_MOUNTED:
-	umount(dev_name);
-      case DIR_CREATED:
-	rmdir(dir_name);
-      case HARMLESS:;
-  }
-  sync();
-  exit(nr == SUCCESS ? 0 : 1);
-}
Index: trunk/minix/commands/simple/banner.c
===================================================================
--- trunk/minix/commands/simple/banner.c	(revision 9)
+++ 	(revision )
@@ -1,153 +1,0 @@
-/* banner - print a banner		Author: Brian Wallis */
-
-/*****************************************************************
- *
- * SYSVbanner.c
- *
- * This is a PD version of the SYS V banner program (at least I think
- * it is compatible to SYS V) which I wrote to use with the clock
- * program written by:
- **     DCF, Inc.
- **     14623 North 49th Place
- **     Scottsdale, AZ 85254
- * and published in the net comp.sources.misc newsgroup in early July
- * since the BSD banner program works quite differently.
- *
- * There is no copyright or responsibility accepted for the use
- * of this software.
- *
- * Brian Wallis, brw@jim.odr.oz, 4 July 1988
- *
- *****************************************************************/
-
-#include <string.h>
-#include <stdio.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-
-char *glyphs[] = {
-	  "         @@@  @@   @@  @ @   @@@@@          @@     @@@  ",
-	  "         @@@  @@   @@  @ @  @  @  @@@   @  @  @    @@@  ",
-	  "         @@@   @   @ @@@@@@@@  @   @@  @    @@      @   ",
-	  "          @            @ @   @@@@@    @    @@@     @    ",
-	  "                     @@@@@@@   @  @  @    @   @ @       ",
-	  "         @@@           @ @  @  @  @ @  @@ @    @        ",
-	  "         @@@           @ @   @@@@@ @   @@  @@@@ @       ",
-
-	  "   @@    @@                                            @",
-	  "  @        @   @   @    @                             @ ",
-	  " @          @   @ @     @                            @  ",
-	  " @          @ @@@@@@@ @@@@@   @@@   @@@@@           @   ",
-	  " @          @   @ @     @     @@@                  @    ",
-	  "  @        @   @   @    @      @            @@@   @     ",
-	  "   @@    @@                   @             @@@  @      ",
-
-	  "  @@@     @    @@@@@  @@@@@ @      @@@@@@@ @@@@@ @@@@@@@",
-	  " @   @   @@   @     @@     @@    @ @      @     @@    @ ",
-	  "@   @ @ @ @         @      @@    @ @      @          @  ",
-	  "@  @  @   @    @@@@@  @@@@@ @@@@@@@ @@@@@ @@@@@@    @   ",
-	  "@ @   @   @   @            @     @       @@     @  @    ",
-	  " @   @    @   @      @     @     @ @     @@     @  @    ",
-	  "  @@@   @@@@@ @@@@@@@ @@@@@      @  @@@@@  @@@@@   @    ",
-
-	  " @@@@@  @@@@@          @@@      @           @     @@@@@ ",
-	  "@     @@     @  @@@    @@@     @             @   @     @",
-	  "@     @@     @  @@@           @     @@@@@     @        @",
-	  " @@@@@  @@@@@@         @@@   @                 @     @@ ",
-	  "@     @      @         @@@    @     @@@@@     @     @   ",
-	  "@     @@     @  @@@     @      @             @          ",
-	  " @@@@@  @@@@@   @@@    @        @           @       @   ",
-
-	  " @@@@@    @   @@@@@@  @@@@@ @@@@@@ @@@@@@@@@@@@@@ @@@@@ ",
-	  "@     @  @ @  @     @@     @@     @@      @      @     @",
-	  "@ @@@ @ @   @ @     @@      @     @@      @      @      ",
-	  "@ @ @ @@     @@@@@@@ @      @     @@@@@@  @@@@@  @  @@@@",
-	  "@ @@@@ @@@@@@@@     @@      @     @@      @      @     @",
-	  "@     @@     @@     @@     @@     @@      @      @     @",
-	  " @@@@@ @     @@@@@@@  @@@@@ @@@@@@ @@@@@@@@       @@@@@ ",
-
-	  "@     @  @*@        @@    @ @      @     @@     @@@@@@@@",
-	  "@     @   @         @@   @  @      @@   @@@@    @@     @",
-	  "@     @   @         @@  @   @      @ @ @ @@ @   @@     @",
-	  "@@@@@@@   @         @@@@    @      @  @  @@  @  @@     @",
-	  "@     @   @   @     @@  @   @      @     @@   @ @@     @",
-	  "@     @   @   @     @@   @  @      @     @@    @@@     @",
-	  "@     @  @@@   @@@@@ @    @ @@@@@@@@     @@     @@@@@@@@",
-
-	  "@@@@@@  @@@@@ @@@@@@  @@@@@ @@@@@@@@     @@     @@     @",
-	  "@     @@     @@     @@     @   @   @     @@     @@  @  @",
-	  "@     @@     @@     @@         @   @     @@     @@  @  @",
-	  "@@@@@@ @     @@@@@@@  @@@@@    @   @     @@     @@  @  @",
-	  "@      @   @ @@   @        @   @   @     @ @   @ @  @  @",
-	  "@      @    @ @    @ @     @   @   @     @  @ @  @  @  @",
-	  "@       @@@@ @@     @ @@@@@    @    @@@@@    @    @@ @@ ",
-
-	  "@     @@     @@@@@@@@ @@@@@ @       @@@@@    @          ",
-	  " @   @  @   @      @  @      @          @   @ @         ",
-	  "  @ @    @ @      @   @       @         @  @   @        ",
-	  "   @      @      @    @        @        @               ",
-	  "  @ @     @     @     @         @       @               ",
-	  " @   @    @    @      @          @      @               ",
-	  "@     @   @   @@@@@@@ @@@@@       @ @@@@@        @@@@@@@",
-
-	  "  @@@                                                   ",
-	  "  @@@     @@   @@@@@   @@@@  @@@@@  @@@@@@ @@@@@@  @@@@ ",
-	  "   @     @  @  @    @ @    @ @    @ @      @      @    @",
-	  "    @   @    @ @@@@@  @      @    @ @@@@@  @@@@@  @     ",
-	  "        @@@@@@ @    @ @      @    @ @      @      @  @@@",
-	  "        @    @ @    @ @    @ @    @ @      @      @    @",
-	  "        @    @ @@@@@   @@@@  @@@@@  @@@@@@ @       @@@@ ",
-
-	  "                                                        ",
-	  " @    @    @        @ @    @ @      @    @ @    @  @@@@ ",
-	  " @    @    @        @ @   @  @      @@  @@ @@   @ @    @",
-	  " @@@@@@    @        @ @@@@   @      @ @@ @ @ @  @ @    @",
-	  " @    @    @        @ @  @   @      @    @ @  @ @ @    @",
-	  " @    @    @   @    @ @   @  @      @    @ @   @@ @    @",
-	  " @    @    @    @@@@  @    @ @@@@@@ @    @ @    @  @@@@ ",
-
-	  "                                                        ",
-	  " @@@@@   @@@@  @@@@@   @@@@   @@@@@ @    @ @    @ @    @",
-	  " @    @ @    @ @    @ @         @   @    @ @    @ @    @",
-	  " @    @ @    @ @    @  @@@@     @   @    @ @    @ @    @",
-	  " @@@@@  @  @ @ @@@@@       @    @   @    @ @    @ @ @@ @",
-	  " @      @   @  @   @  @    @    @   @    @  @  @  @@  @@",
-	  " @       @@@ @ @    @  @@@@     @    @@@@    @@   @    @",
-
-	  "                       @@@     @     @@@   @@    @ @ @ @",
-	  " @    @  @   @ @@@@@@ @        @        @ @  @  @ @ @ @ ",
-	  "  @  @    @ @      @  @        @        @     @@ @ @ @ @",
-	  "   @@      @      @  @@                 @@        @ @ @ ",
-	  "   @@      @     @    @        @        @        @ @ @ @",
-	  "  @  @     @    @     @        @        @         @ @ @ ",
-	  " @    @    @   @@@@@@  @@@     @     @@@         @ @ @ @"
-};
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int a, b, c, len, ind;
-  char line[80];
-
-  for (argv++; --argc; argv++) {
-	len = strlen(*argv);
-	if (len > 10) len = 10;
-	for (a = 0; a < 7; a++) {
-		for (b = 0; b < len; b++) {
-			if ((ind = (*argv)[b] - ' ') < 0) ind = 0;
-			for (c = 0; c < 7; c++) {
-				line[b * 8 + c] = glyphs[(ind / 8 * 7) + a][(ind % 8 * 7) + c] == '@' ? ind + ' ' : ' ';
-			}
-			line[b * 8 + 7] = ' ';
-		}
-		for (b = len * 8 - 1; b >= 0; b--) {
-			if (line[b] != ' ') break;
-			line[b] = '\0';
-		}
-		printf("%s\n", line);
-	}
-	printf("\n");
-  }
-  return(0);
-}
Index: trunk/minix/commands/simple/basename.c
===================================================================
--- trunk/minix/commands/simple/basename.c	(revision 9)
+++ 	(revision )
@@ -1,76 +1,0 @@
-/* basename - print last part of a path      Authors: B. Garfolo & P. Nelson */
-
-/* Basename - print the last part of a path.
- *
- *    For MINIX  --  Conforms to POSIX - P1003.2/D10
- *      Exception -- it ignores the LC environment variables.
- *
- *    Original MINIX author:  Blaine Garfolo
- *    POSIX rewrite author:   Philip A. Nelson
- *
- *    POSIX version - October 20, 1990
- *      Feb 14, 1991: changed rindex to strrchr. (PAN)
- *
- */
-
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define EOS '\0'
-
-_PROTOTYPE(int main, (int argc, char **argv));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char *result_string;		/* The pointer into argv[1]. */
-  char *temp;			/* Used to move around in argv[1]. */
-  int suffix_len;		/* Length of the suffix. */
-  int suffix_start;		/* Where the suffix should start. */
-
-
-  /* Check for the correct number of arguments. */
-  if ((argc < 2) || (argc > 3)) {
-	fprintf(stderr, "Usage: basename string [suffix] \n");
-	exit(1);
-  }
-
-  /* Check for all /'s */
-  for (temp = argv[1]; *temp == '/'; temp++)	/* Move to next char. */
-	;
-  if (*temp == EOS) {
-	printf("/\n");
-	exit(0);
-  }
-
-  /* Build the basename. */
-  result_string = argv[1];
-
-  /* Find the last /'s */
-  temp = strrchr(result_string, '/');
-
-  if (temp != NULL) {
-	/* Remove trailing /'s. */
-	while ((*(temp + 1) == EOS) && (*temp == '/')) *temp-- = EOS;
-
-	/* Set result_string to last part of path. */
-	if (*temp != '/') temp = strrchr(result_string, '/');
-	if (temp != NULL && *temp == '/') result_string = temp + 1;
-  }
-
-  /* Remove the suffix, if any. */
-  if (argc > 2) {
-	suffix_len = strlen(argv[2]);
-	suffix_start = strlen(result_string) - suffix_len;
-	if (suffix_start > 0)
-		if (strcmp(result_string + suffix_start, argv[2]) == EOS)
-			*(result_string + suffix_start) = EOS;
-  }
-
-  /* Print the resultant string. */
-  printf("%s\n", result_string);
-  return(0);
-}
Index: trunk/minix/commands/simple/build
===================================================================
--- trunk/minix/commands/simple/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/simple/cal.c
===================================================================
--- trunk/minix/commands/simple/cal.c	(revision 9)
+++ 	(revision )
@@ -1,315 +1,0 @@
-/* cal - print a calendar		Author: Maritn Minow */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#define do3months	domonth
-#define	IO_SUCCESS	0	/* Unix definitions		 */
-#define	IO_ERROR	1
-#define	EOS	0
-
-#define	ENTRY_SIZE	3	/* 3 bytes per value		 */
-#define DAYS_PER_WEEK	7	/* Sunday, etc.			 */
-#define	WEEKS_PER_MONTH	6	/* Max. weeks in a month	 */
-#define	MONTHS_PER_LINE	3	/* Three months across		 */
-#define	MONTH_SPACE	3	/* Between each month		 */
-
-char *badarg = {"Bad argument\n"};
-char *how = {"Usage: cal [month] year\n"};
-
-/* Calendar() stuffs data into layout[],
- * output() copies from layout[] to outline[], (then trims blanks).
- */
-char layout[MONTHS_PER_LINE][WEEKS_PER_MONTH][DAYS_PER_WEEK][ENTRY_SIZE];
-char outline[(MONTHS_PER_LINE * DAYS_PER_WEEK * ENTRY_SIZE)
-       + (MONTHS_PER_LINE * MONTH_SPACE)
-       + 1];
-
-char *weekday = " S  M Tu  W Th  F  S";
-char *monthname[] = {
-	     "???",		/* No month 0	 */
-	     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-	     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void doyear, (int year));
-_PROTOTYPE(void domonth, (int year, int month));
-_PROTOTYPE(void output, (int nmonths));
-_PROTOTYPE(void calendar, (int year, int month, int indx));
-_PROTOTYPE(void usage, (char *s));
-_PROTOTYPE(int date, (int year, int month, int week, int wday));
-_PROTOTYPE(void setmonth, (int year, int month));
-_PROTOTYPE(int getdate, (int week, int wday));
-_PROTOTYPE(static int Jan1, (int year));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  register int year;
-
-  register int arg1val;
-  int arg1len;
-  int arg2val;
-
-  if (argc <= 1) {
-	usage(how);
-  } else {
-	arg1val = atoi(argv[1]);
-	arg1len = strlen(argv[1]);
-	if (argc == 2) {
-		/* Only one argument, if small, it's a month.  If
-		 * large, it's a year.  Note: cal		0082	Year
-		 * 0082 cal		82	Year 0082 */
-		if (arg1len <= 2 && arg1val <= 12)
-			do3months(year, arg1val);
-		else
-			doyear(arg1val);
-	} else {
-		/* Two arguments, allow 1980 12 or 12 1980 */
-		arg2val = atoi(argv[2]);
-		if (arg1len > 2)
-			do3months(arg1val, arg2val);
-		else
-			do3months(arg2val, arg1val);
-	}
-  }
-  return(IO_SUCCESS);
-}
-
-void doyear(year)
-int year;
-/* Print the calendar for an entire year. */
-{
-  register int month;
-
-  if (year < 1 || year > 9999) usage(badarg);
-  if (year < 100)
-	printf("\n\n\n                                 00%2d\n\n", year);
-  else
-	printf("\n\n\n%35d\n\n", year);
-  for (month = 1; month <= 12; month += MONTHS_PER_LINE) {
-	printf("%12s%23s%23s\n",
-	       monthname[month],
-	       monthname[month + 1],
-	       monthname[month + 2]);
-	printf("%s   %s   %s\n", weekday, weekday, weekday);
-	calendar(year, month + 0, 0);
-	calendar(year, month + 1, 1);
-	calendar(year, month + 2, 2);
-	output(3);
-#if MONTHS_PER_LINE != 3
-#error  "the above will not work"
-#endif
-  }
-  printf("\n\n\n");
-}
-
-void domonth(year, month)
-int year;
-int month;
-/* Do one specific month -- note: no longer used */
-{
-  if (year < 1 || year > 9999) usage(badarg);
-  if (month <= 0 || month > 12) usage(badarg);
-  printf("%9s%5d\n\n%s\n", monthname[month], year, weekday);
-  calendar(year, month, 0);
-  output(1);
-  printf("\n\n");
-}
-
-void output(nmonths)
-int nmonths;			/* Number of months to do	 */
-/* Clean up and output the text. */
-{
-  register int week;
-  register int month;
-  register char *outp;
-  int i;
-  char tmpbuf[21], *p;
-
-  for (week = 0; week < WEEKS_PER_MONTH; week++) {
-	outp = outline;
-	for (month = 0; month < nmonths; month++) {
-		/* The -1 in the following removes the unwanted
-		 * leading blank from the entry for Sunday. */
-		p = &layout[month][week][0][1];
-		for (i = 0; i < 20; i++) tmpbuf[i] = *p++;
-		tmpbuf[20] = 0;
-		sprintf(outp, "%s   ", tmpbuf);
-		outp += (DAYS_PER_WEEK * ENTRY_SIZE) + MONTH_SPACE - 1;
-	}
-	while (outp > outline && outp[-1] == ' ') outp--;
-	*outp = EOS;
-	printf("%s\n", outline);
-  }
-}
-
-void calendar(year, month, indx)
-int year;
-int month;
-int indx;			/* Which of the three months		 */
-/* Actually build the calendar for this month. */
-{
-  register char *tp;
-  int week;
-  register int wday;
-  register int today;
-
-  setmonth(year, month);
-  for (week = 0; week < WEEKS_PER_MONTH; week++) {
-	for (wday = 0; wday < DAYS_PER_WEEK; wday++) {
-		tp = &layout[indx][week][wday][0];
-		*tp++ = ' ';
-		today = getdate(week, wday);
-		if (today <= 0) {
-			*tp++ = ' ';
-			*tp++ = ' ';
-		} else if (today < 10) {
-			*tp++ = ' ';
-			*tp = (today + '0');
-		} else {
-			*tp++ = (today / 10) + '0';
-			*tp = (today % 10) + '0';
-		}
-	}
-  }
-}
-
-void usage(s)
-char *s;
-{
-/* Fatal parameter error. */
-
-  fprintf(stderr, "%s", s);
-  exit(IO_ERROR);
-}
-
-/* Calendar routines, intended for eventual porting to TeX
- *
- * date(year, month, week, wday)
- *	Returns the date on this week (0 is first, 5 last possible)
- *	and day of the week (Sunday == 0)
- *	Note: January is month 1.
- *
- * setmonth(year, month)
- *	Parameters are as above, sets getdate() for this month.
- *
- * int
- * getdate(week, wday)
- *	Parameters are as above, uses the data set by setmonth()
- */
-
-/* This structure is used to pass data between setmonth() and getdate().
- * It needs considerable expansion if the Julian->Gregorian change is
- * to be extended to other countries.
- */
-
-static struct {
-  int this_month;		/* month number used in 1752 checking	 */
-  int feb;			/* Days in February for this month	 */
-  int sept;			/* Days in September for this month	 */
-  int days_in_month;		/* Number of days in this month		 */
-  int dow_first;		/* Day of week of the 1st day in month	 */
-} info;
-
-static int day_month[] = {	/* 30 days hath September...		 */
-		  0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
-int date(year, month, week, wday)
-int year;			/* Calendar date being computed		 */
-int month;			/* January == 1				 */
-int week;			/* Week in the month 0..5 inclusive	 */
-int wday;			/* Weekday, Sunday == 0			 */
-/* Return the date of the month that fell on this week and weekday.
- * Return zero if it's out of range.
- */
-{
-  setmonth(year, month);
-  return(getdate(week, wday));
-}
-
-void setmonth(year, month)
-int year;			/* Year to compute		 */
-int month;			/* Month, January is month 1	 */
-/* Setup the parameters needed to compute this month
- * (stored in the info structure).
- */
-{
-  register int i;
-
-  if (month < 1 || month > 12) {/* Verify caller's parameters	 */
-	info.days_in_month = 0;	/* Garbage flag			 */
-	return;
-  }
-  info.this_month = month;	/* used in 1752	checking	 */
-  info.dow_first = Jan1(year);	/* Day of January 1st for now	 */
-  info.feb = 29;		/* Assume leap year		 */
-  info.sept = 30;		/* Assume normal year		 */
-  /* Determine whether it's an ordinary year, a leap year or the
-   * magical calendar switch year of 1752. */
-  switch ((Jan1(year + 1) + 7 - info.dow_first) % 7) {
-      case 1:			/* Not a leap year		 */
-	info.feb = 28;
-      case 2:			/* Ordinary leap year		 */
-	break;
-
-      default:			/* The magical moment arrives	 */
-	info.sept = 19;		/* 19 days hath September	 */
-	break;
-  }
-  info.days_in_month =
-	(month == 2) ? info.feb
-	: (month == 9) ? info.sept
-	: day_month[month];
-  for (i = 1; i < month; i++) {
-	switch (i) {		/* Special months?		 */
-	    case 2:		/* February			 */
-		info.dow_first += info.feb;
-		break;
-
-	    case 9:	info.dow_first += info.sept;	break;
-
-	    default:
-		info.dow_first += day_month[i];
-		break;
-	}
-  }
-  info.dow_first %= 7;		/* Now it's Sunday to Saturday	 */
-}
-
-int getdate(week, wday)
-int week;
-int wday;
-{
-  register int today;
-
-  /* Get a first guess at today's date and make sure it's in range. */
-  today = (week * 7) + wday - info.dow_first + 1;
-  if (today <= 0 || today > info.days_in_month)
-	return(0);
-  else if (info.sept == 19 && info.this_month == 9
-	 && today >= 3)		/* The magical month?	 */
-	return(today + 11);	/* If so, some dates changed	 */
-  else				/* Otherwise,			 */
-	return(today);		/* Return the date		 */
-}
-
-static int Jan1(year)
-int year;
-/* Return day of the week for Jan 1 of the specified year. */
-{
-  register int day;
-
-  day = year + 4 + ((year + 3) / 4);	/* Julian Calendar	 */
-  if (year > 1800) {		/* If it's recent, do	 */
-	day -= ((year - 1701) / 100);	/* Clavian correction	 */
-	day += ((year - 1601) / 400);	/* Gregorian correction	 */
-  }
-  if (year > 1752)		/* Adjust for Gregorian	 */
-	day += 3;		/* calendar		 */
-  return(day % 7);
-}
Index: trunk/minix/commands/simple/calendar.c
===================================================================
--- trunk/minix/commands/simple/calendar.c	(revision 9)
+++ 	(revision )
@@ -1,232 +1,0 @@
-/* calendar - reminder service		Authors: S. & K. Hirabayashi */
-
-/* Permission is hereby granted for nonprofit use. */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <regexp.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termcap.h>
-#include <unistd.h>
-#include <utime.h>
-#include <stdio.h>
-
-/* Change these two lines for your system needs. */
-#define MAIL1	"/usr/bin/mail"
-#define MAIL2	"/bin/mail"
-#define PASSWD	"/etc/passwd"	/* system password file */
-#define MAX_EXP		4	/* see date_exp() function */
-
-char *mail;			/* mail command path ("/bin/mail" etc) */
-regexp *exp[MAX_EXP];		/* date expressions */
-int nexp;			/* # of the date expressions */
-char calfile[PATH_MAX];		/* calendar file for the user */
-
-int rflg;			/* consult aged 'calendar' file and touch */
-int mflg;			/* mail (multi user) service */
-char *cmd;			/* the name of this command */
-char buf[BUFSIZ];
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void calendar, (void));
-_PROTOTYPE(char *getstr, (char *s, int n));
-_PROTOTYPE(int newaccess, (char *file));
-_PROTOTYPE(void grep, (char *file, char *user));
-_PROTOTYPE(int date_exp, (void));
-_PROTOTYPE(char *date_pat, (time_t t));
-/*
-_PROTOTYPE(void regerror, (char *s));
-*/
-_PROTOTYPE(void error, (char *s, char *t));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  char *s;
-
-  cmd = *argv;
-  while (--argc > 0 && (*++argv)[0] == '-') {
-	s = argv[0] + 1;
-	if (*s == '\0')
-		mflg++;		/* mail service */
-	else if (strcmp(s, "r") == 0)
-		rflg++, mflg++;
-  }
-
-  if (mflg) {			/* check mailing agent */
-	if (access(MAIL1, X_OK) == 0)
-		mail = MAIL1;
-	else if (access(MAIL2, X_OK) == 0)
-		mail = MAIL2;
-	else
-		error("cannot find %s", MAIL1);
-  }
-  nexp = date_exp();
-  calendar();
-  exit(0);
-}
-
-void calendar()
-{
-  int i;
-  char *s;
-  FILE *fp;
-
-  if (!mflg) {
-	grep("calendar", "");
-	return;
-  }
-
-  /* Mail sevice */
-  if ((fp = fopen(PASSWD, "r")) == (FILE *) NULL)
-	error("cannot open %s", PASSWD);
-
-  while (fgets(buf, BUFSIZ, fp) != (char *) NULL) {
-	for (i = 0, s = buf; *s && *s != '\n'; s++)
-		if (*s == ':') i++;
-	*s = '\0';
-	if (i != 6) error("illegal '/etc/passwd' format: %s", buf);
-
-	/* Calendar file = ${HOME}/calendar */
-	sprintf(calfile, "%s/%s", getstr(buf, 5), "calendar");
-
-	if ((access(calfile, R_OK) != 0) || (rflg && !newaccess(calfile)))
-		continue;
-
-	grep(calfile, getstr(buf, 0));
-  }
-
-  fclose(fp);
-}
-
-char *getstr(s, n)
-char *s;
-int n;
-{
-/* Returns the string value of the n-th field in the record (s) */
-  int i;
-  char *t;
-  static char str[512];
-
-  for (i = 0; i < n && *s; s++)
-	if (*s == ':') i++;		/* field separator */
-  for (i = 0, t = str; *s && *s != ':' && i < 511; i++) *t++ = *s++;
-  *t = '\0';
-  return str;
-}
-
-int newaccess(file)
-char *file;			/* file name */
-{
-/* Check whether the file has been touched today. */
-
-  int r = 0;
-  struct tm *tm;
-  struct stat stbuf;
-  time_t clk;
-  char newdate[8], olddate[8];
-
-  time(&clk);
-  tm = localtime(&clk);
-  sprintf(newdate, "%02d%02d%02d", tm->tm_year, tm->tm_mon + 1, tm->tm_mday);
-
-  if (stat(file, &stbuf) == -1) error("cannot stat %s", file);
-  tm = localtime(&stbuf.st_mtime);
-  sprintf(olddate, "%02d%02d%02d", tm->tm_year, tm->tm_mon + 1, tm->tm_mday);
-
-  if (strcmp(newdate, olddate) != 0) {
-	utime(file, NULL);	/* touch */
-	r++;
-  }
-  return r;
-}
-
-void grep(file, user)
-char *file, *user;
-{				/* grep 'exp[]' [| mail user] */
-  int i;
-  char command[128];		/* mail command */
-  FILE *ifp, *ofp;
-
-  if ((ifp = fopen(file, "r")) == (FILE *) NULL)
-	error("cannot open %s", file);
-  if (*user != '\0') {
-	sprintf(command, "%s %s", mail, user);
-	ofp = (FILE *) NULL;
-  } else {
-	ofp = stdout;
-  }
-
-  while (fgets(buf, BUFSIZ, ifp) != (char *) NULL) {
-	for (i = 0; i < nexp; i++) {
-		if (regexec(exp[i], buf, 1)) {
-			if ((ofp == (FILE *) NULL) &&
-				  (ofp = popen(command, "w")) == (FILE *) NULL)
-				error("cannot popen %s", mail);
-			fputs(buf, ofp);
-			break;
-		}
-	}
-  }
-
-  fclose(ifp);
-  if (ofp == stdout)
-	fflush(ofp);
-  else if (ofp != (FILE *) NULL)
-	pclose(ofp);
-}
-
-int date_exp()
-{
-/* Set compiled regular expressions into the exp[] array. */
-  static int n[] = {2, 2, 2, 2, 2, 4, 3};
-  int i, r, wday;
-  time_t clk;
-
-  time(&clk);
-  wday = localtime(&clk)->tm_wday;
-  r = n[wday];
-  if (r > MAX_EXP) error("too many date expressions", "");
-  for (i = 0; i < r; i++) {
-	exp[i] = regcomp(date_pat(clk));
-	clk += 60 * 60 * 24L;	/* 24 hours */
-  }
-  return(r);
-}
-
-char *date_pat(t)
-time_t t;
-{				/* returns date expression for the time (t) */
-  static char *month[] = {
-	 "[Jj]an", "[Ff]eb", "[Mm]ar", "[Aa]pr", "[Mm]ay", "[Jj]un",
-	  "[Jj]ul", "[Aa]ug", "[Ss]ep", "[Oo]ct", "[Nn]ov", "[Dd]ec"
-  };
-  static char str[512];
-  struct tm *tm;
-
-  tm = localtime(&t);
-  sprintf(str,
-	"(^|[ \t(,;])(((%s[^ \t]*[ \t])|0*%d/|\\*/)(0*%d|\\*))([^0123456789]|$)",
-	month[tm->tm_mon], tm->tm_mon + 1, tm->tm_mday);
-
-  return str;
-}
-
-void regerror(s)
-const char *s;
-{				/* regcomp() needs this */
-  error("REGULAR EXPRESSION ERROR (%s)", (char *) s);
-}
-
-void error(s, t)
-char *s, *t;
-{
-  fprintf(stderr, "%s: ", cmd);
-  fprintf(stderr, s, t);
-  fprintf(stderr, "\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/cat.c
===================================================================
--- trunk/minix/commands/simple/cat.c	(revision 9)
+++ 	(revision )
@@ -1,138 +1,0 @@
-/* cat - concatenates files  		Author: Andy Tanenbaum */
-
-/* 30 March 1990 - Slightly modified for efficiency by Norbert Schlenker. */
-/* 23 March 2002 - Proper error messages by Kees J. Bot. */
-
-
-#include <errno.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <minix/minlib.h>
-#include <stdio.h>
-
-#define CHUNK_SIZE	(2048 * sizeof(char *))
-
-static int unbuffered;
-static char ibuf[CHUNK_SIZE];
-static char obuf[CHUNK_SIZE];
-static char *op = obuf;
-
-int main(int argc, char **argv);
-static void copyout(char *file, int fd);
-static void output(char *buf, size_t count);
-static void report(char *label);
-static void fatal(char *label);
-
-static char STDIN[] = "standard input";
-static char STDOUT[] = "standard output";
-
-static int excode = 0;
-
-int main(int argc, char *argv[])
-{
-  int i, fd;
-
-  i = 1;
-  while (i < argc && argv[i][0] == '-') {
-	char *opt = argv[i] + 1;
-
-	if (opt[0] == 0) break;				/* - */
-	i++;
-	if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-	while (*opt != 0) switch (*opt++) {
-	case 'u':
-		unbuffered = 1;
-		break;
-	default:
-		std_err("Usage: cat [-u] [file ...]\n");
-		exit(1);
-	}
-  }
-
-  if (i >= argc) {
-	copyout(STDIN, STDIN_FILENO);
-  } else {
-	while (i < argc) {
-		char *file = argv[i++];
-
-		if (file[0] == '-' && file[1] == 0) {
-			copyout(STDIN, STDIN_FILENO);
-		} else {
-			fd = open(file, O_RDONLY);
-			if (fd < 0) {
-				report(file);
-			} else {
-				copyout(file, fd);
-				close(fd);
-			}
-		}
-	}
-  }
-  output(obuf, (op - obuf));
-  return(excode);
-}
-
-static void copyout(char *file, int fd)
-{
-  int n;
-
-  while (1) {
-	n = read(fd, ibuf, CHUNK_SIZE);
-	if (n < 0) fatal(file);
-	if (n == 0) return;
-	if (unbuffered || (op == obuf && n == CHUNK_SIZE)) {
-		output(ibuf, n);
-	} else {
-		int bytes_left;
-
-		bytes_left = &obuf[CHUNK_SIZE] - op;
-		if (n <= bytes_left) {
-			memcpy(op, ibuf, (size_t)n);
-			op += n;
-		} else {
-			memcpy(op, ibuf, (size_t)bytes_left);
-			output(obuf, CHUNK_SIZE);
-			n -= bytes_left;
-			memcpy(obuf, ibuf + bytes_left, (size_t)n);
-			op = obuf + n;
-		}
-	}
-  }
-}
-
-static void output(char *buf, size_t count)
-{
-  ssize_t n;
-
-  while (count > 0) {
-	n = write(STDOUT_FILENO, buf, count);
-	if (n <= 0) {
-		if (n < 0) fatal(STDOUT);
-		std_err("cat: standard output: EOF\n");
-		exit(1);
-	}
-	buf += n;
-	count -= n;
-  }
-}
-
-static void report(char *label)
-{
-  int e = errno;
-  std_err("cat: ");
-  std_err(label);
-  std_err(": ");
-  std_err(strerror(e));
-  std_err("\n");
-  excode = 1;
-}
-
-static void fatal(char *label)
-{
-  report(label);
-  exit(1);
-}
Index: trunk/minix/commands/simple/cdiff.c
===================================================================
--- trunk/minix/commands/simple/cdiff.c	(revision 9)
+++ 	(revision )
@@ -1,365 +1,0 @@
-/* cdiff - context diff			Author: Larry Wall */
-
-/* Cdiff - turns a regular diff into a new-style context diff
- *
- * Usage: cdiff file1 file2
- */
-
-#define PATCHLEVEL 2
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <limits.h>
-#include <stdio.h>
-
-char buff[512];
-
-FILE *inputfp, *oldfp, *newfp;
-
-int oldmin, oldmax, newmin, newmax;
-int oldbeg, oldend, newbeg, newend;
-int preoldmax, prenewmax;
-int preoldbeg, preoldend, prenewbeg, prenewend;
-int oldwanted, newwanted;
-
-char *oldhunk, *newhunk;
-char *progname;
-size_t oldsize, oldalloc, newsize, newalloc;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void dumphunk, (void));
-_PROTOTYPE(char *getold, (int targ));
-_PROTOTYPE(char *getnew, (int targ));
-_PROTOTYPE(void *xmalloc, (size_t size));
-_PROTOTYPE(void *xrealloc, (void *ptr, size_t size));
-
-#define Nullfp (FILE*)0
-#define Nullch (char*)0
-#define ENOUGH (NAME_MAX + PATH_MAX + 1)
-#define CRC_END 12
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  FILE *crcfp;
-  char *old, *new;
-  int context = 3;
-  struct stat statbuf;
-  register char *s;
-  char op;
-  char *newmark, *oldmark;
-  char sysbuf1[ENOUGH], sysbuf2[ENOUGH];
-  int len;
-  char *line;
-  int i;
-  int status;
-
-  progname = argv[0];
-  oldalloc = 512;
-  oldhunk = (char *) xmalloc(oldalloc);
-  newalloc = 512;
-  newhunk = (char *) xmalloc(newalloc);
-
-  for (argc--, argv++; argc; argc--, argv++) {
-	if (argv[0][0] != '-') break;
-
-	if (argv[0][1] == 'c') context = atoi(argv[0] + 2);
-  }
-
-  if (argc != 2) {
-	fprintf(stderr, "Usage: cdiff old new\n");
-	exit(2);
-  }
-  old = argv[0];
-  new = argv[1];
-
-  oldfp = fopen(old, "r");
-  if (!oldfp) {
-	fprintf(stderr, "Can't open %s\n", old);
-	exit(2);
-  }
-  newfp = fopen(new, "r");
-  if (!newfp) {
-	fprintf(stderr, "Can't open %s\n", new);
-	exit(2);
-  }
-
-  /* Compute crcs by popen()ing crc and reading the output.  Do this before
-   * popen()ing diff to do the work.  popen() attempts to support multiple
-   * clients, but the 1.3-1.6.24b versions don't succeed.
-   */
-  sprintf(sysbuf1, "crc %s", old);
-  crcfp = popen(sysbuf1, "r");
-  if (!crcfp) {
-	/* The only advantage of cdiff over diff is that it prints crcs, so
-	 * give up easily if crc fails.
-	 */
-	fprintf(stderr, "Can't execute crc %s\n", old);
-	exit(2);
-  }
-  fgets(sysbuf1, sizeof(sysbuf1), crcfp);
-  sysbuf1[CRC_END] = '\0';
-  status = pclose(crcfp);
-  if (status != 0) {
-	fprintf(stderr, "crc %s returned bad status %d\n", old, status);
-	exit(2);
-  }
-  sprintf(sysbuf2, "crc %s", new);
-  crcfp = popen(sysbuf2, "r");
-  if (!crcfp) {
-	fprintf(stderr, "Can't execute crc %s\n", new);
-	exit(2);
-  }
-  fgets(sysbuf2, sizeof(sysbuf2), crcfp);
-  sysbuf2[CRC_END] = '\0';
-  status = pclose(crcfp);
-  if (status != 0) {
-	fprintf(stderr, "crc %s returned bad status %d\n", new, status);
-	exit(2);
-  }
-
-  sprintf(buff, "diff %s %s 2>/dev/null", old, new);
-  inputfp = popen(buff, "r");
-  if (!inputfp) {
-	fprintf(stderr, "Can't execute diff %s %s\n", old, new);
-	exit(2);
-  }
-
-  fstat(fileno(oldfp), &statbuf);
-  printf("*** %s  crc=%s\t%s", old, sysbuf1, ctime(&statbuf.st_mtime));
-  fstat(fileno(newfp), &statbuf);
-  printf("--- %s  crc=%s\t%s", new, sysbuf2, ctime(&statbuf.st_mtime));
-
-  preoldend = -1000;
-
-  while (fgets(buff, sizeof buff, inputfp) != Nullch) {
-	if (isdigit(*buff)) {
-		oldmin = atoi(buff);
-		for (s = buff; isdigit(*s); s++);
-		if (*s == ',') {
-			s++;
-			oldmax = atoi(s);
-			for (; isdigit(*s); s++);
-		} else {
-			oldmax = oldmin;
-		}
-		if (*s != 'a' && *s != 'd' && *s != 'c') {
-			fprintf(stderr, "Unparseable input: %s\n", s);
-			exit(2);
-		}
-		op = *s;
-		s++;
-		newmin = atoi(s);
-		for (; isdigit(*s); s++);
-		if (*s == ',') {
-			s++;
-			newmax = atoi(s);
-			for (; isdigit(*s); s++);
-		} else {
-			newmax = newmin;
-		}
-		if (*s != '\n' && *s != ' ') {
-			fprintf(stderr, "Unparseable input: %s\n", s);
-			exit(2);
-		}
-		newmark = oldmark = "! ";
-		if (op == 'a') {
-			oldmin++;
-			newmark = "+ ";
-		}
-		if (op == 'd') {
-			newmin++;
-			oldmark = "- ";
-		}
-		oldbeg = oldmin - context;
-		oldend = oldmax + context;
-		if (oldbeg < 1) oldbeg = 1;
-		newbeg = newmin - context;
-		newend = newmax + context;
-		if (newbeg < 1) newbeg = 1;
-
-		if (preoldend < oldbeg - 1) {
-			if (preoldend >= 0) {
-				dumphunk();
-			}
-			preoldbeg = oldbeg;
-			prenewbeg = newbeg;
-			oldwanted = newwanted = 0;
-			oldsize = newsize = 0;
-		} else {	/* we want to append to previous hunk */
-			oldbeg = preoldmax + 1;
-			newbeg = prenewmax + 1;
-		}
-
-		for (i = oldbeg; i <= oldmax; i++) {
-			line = getold(i);
-			if (!line) {
-				oldend = oldmax = i - 1;
-				break;
-			}
-			len = strlen(line) + 2;
-			if (oldsize + len + 1 >= oldalloc) {
-				oldalloc *= 2;
-				oldhunk = (char *) xrealloc(oldhunk, oldalloc);
-			}
-			if (i >= oldmin) {
-				strcpy(oldhunk + oldsize, oldmark);
-				oldwanted++;
-			} else {
-				strcpy(oldhunk + oldsize, "  ");
-			}
-			strcpy(oldhunk + oldsize + 2, line);
-			oldsize += len;
-		}
-		preoldmax = oldmax;
-		preoldend = oldend;
-
-		for (i = newbeg; i <= newmax; i++) {
-			line = getnew(i);
-			if (!line) {
-				newend = newmax = i - 1;
-				break;
-			}
-			len = strlen(line) + 2;
-			if (newsize + len + 1 >= newalloc) {
-				newalloc *= 2;
-				newhunk = (char *) xrealloc(newhunk, newalloc);
-			}
-			if (i >= newmin) {
-				strcpy(newhunk + newsize, newmark);
-				newwanted++;
-			} else {
-				strcpy(newhunk + newsize, "  ");
-			}
-			strcpy(newhunk + newsize + 2, line);
-			newsize += len;
-		}
-		prenewmax = newmax;
-		prenewend = newend;
-	}
-  }
-
-  if (preoldend >= 0) {
-	dumphunk();
-  }
-  status = pclose(inputfp);
-  if (!WIFEXITED(status)) exit(2);
-  status = WEXITSTATUS(status);
-  return(status == 0 || status == 1 ? status : 2);
-}
-
-void dumphunk()
-{
-  int i;
-  char *line;
-  int len;
-
-  for (i = preoldmax + 1; i <= preoldend; i++) {
-	line = getold(i);
-	if (!line) {
-		preoldend = i - 1;
-		break;
-	}
-	len = strlen(line) + 2;
-	if (oldsize + len + 1 >= oldalloc) {
-		oldalloc *= 2;
-		oldhunk = (char *) xrealloc(oldhunk, oldalloc);
-	}
-	strcpy(oldhunk + oldsize, "  ");
-	strcpy(oldhunk + oldsize + 2, line);
-	oldsize += len;
-  }
-  for (i = prenewmax + 1; i <= prenewend; i++) {
-	line = getnew(i);
-	if (!line) {
-		prenewend = i - 1;
-		break;
-	}
-	len = strlen(line) + 2;
-	if (newsize + len + 1 >= newalloc) {
-		newalloc *= 2;
-		newhunk = (char *) xrealloc(newhunk, newalloc);
-	}
-	strcpy(newhunk + newsize, "  ");
-	strcpy(newhunk + newsize + 2, line);
-	newsize += len;
-  }
-  printf("***************\n");
-  if (preoldbeg >= preoldend) {
-	printf("*** %d ****\n", preoldend);
-  } else {
-	printf("*** %d,%d ****\n", preoldbeg, preoldend);
-  }
-  if (oldwanted) {
-	printf("%s", oldhunk);
-  }
-  oldsize = 0;
-  *oldhunk = '\0';
-  if (prenewbeg >= prenewend) {
-	printf("--- %d ----\n", prenewend);
-  } else {
-	printf("--- %d,%d ----\n", prenewbeg, prenewend);
-  }
-  if (newwanted) {
-	printf("%s", newhunk);
-  }
-  newsize = 0;
-  *newhunk = '\0';
-}
-
-char *getold(targ)
-int targ;
-{
-  static int oldline = 0;
-
-  while (fgets(buff, sizeof buff, oldfp) != Nullch) {
-	oldline++;
-	if (oldline == targ) return buff;
-  }
-  return Nullch;
-}
-
-char *getnew(targ)
-int targ;
-{
-  static int newline = 0;
-
-  while (fgets(buff, sizeof buff, newfp) != Nullch) {
-	newline++;
-	if (newline == targ) return buff;
-  }
-  return Nullch;
-}
-
-void *xmalloc(size)
-size_t size;
-{
-  void *ptr;
-
-  ptr = malloc(size);
-  if (ptr == NULL) {
-	fprintf(stderr, "%s: out of memory\n", progname);
-	exit(2);
-  }
-  return(ptr);
-}
-
-void *xrealloc(ptr, size)
-void *ptr;
-size_t size;
-{
-  ptr = realloc(ptr, size);
-  if (ptr == NULL) {
-	fprintf(stderr, "%s: out of memory\n", progname);
-	exit(2);
-  }
-  return(ptr);
-}
Index: trunk/minix/commands/simple/cdprobe.c
===================================================================
--- trunk/minix/commands/simple/cdprobe.c	(revision 9)
+++ 	(revision )
@@ -1,130 +1,0 @@
-/* This file contains some code to guess where we have to load the
- * RAM image device from, if started from CD. (In this case it's hard
- * to tell where this is without diving into BIOS heuristics.)
- *
- * There is some nasty hard-codery in here ( MINIX cd label) that can be
- * improved on.
- *
- * Changes:
- *   Jul 14, 2005   Created (Ben Gras)
- *   Feb 10, 2006   Changed into a standalone program (Philip Homburg)
- */
-
-#define CD_SECTOR	2048
-#define SUPER_OFF	1024
-#define AT_MINORS	8
-#define MAGIC_OFF	24
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "../../servers/fs/const.h"
-
-char pvd[CD_SECTOR];
-
-/*===========================================================================*
- *				cdprobe					     *
- *===========================================================================*/
-int main(void)
-{
-	int i, r, fd, minor, found;
-	off_t pos;
-	u16_t *magicp;
-	char name1[]= "/dev/c0dX";
-	char name2[]= "/dev/c0dXpY";
-
-	found= 0;
-	for(i = 0; i < AT_MINORS; i++) {
-		name1[8]= '0' + i;
-
-		fd = open(name1, O_RDONLY);
-		if (fd < 0)
-		{
-			if (errno != ENXIO)
-			{
-				fprintf(stderr, "open '%s' failed: %s\n",
-					name1, strerror(errno));
-			}
-			continue;
-		}
-
-		pos= lseek(fd, 16*CD_SECTOR, SEEK_SET);
-		if (pos != 16*CD_SECTOR)
-		{
-			/* Strange, do we need to issue a warning? */
-			close(fd);
-			continue;
-		}
-		r = read(fd, pvd, sizeof(pvd));
-		if (r != sizeof(pvd))
-		{
-			fprintf(stderr,
-				"error reading CD label from '%s': %s\n",
-				name1, strerror(errno));
-			close(fd);
-			continue;
-		}
-		close(fd);
-
-		/* Check PVD ID. */
-		if (pvd[0] !=  1  || pvd[1] != 'C' || pvd[2] != 'D' ||
-		   pvd[3] != '0' || pvd[4] != '0' || pvd[5] != '1' ||
-		   pvd[6] != 1 ||
-		   strncmp(pvd + 40, "MINIX", 5) != 0) {
-		   	continue;
-		}
-
-		/* 3. Both c0dXp1 and p2 should have a superblock. */
-		found= 1;	/* Assume everything is okay */
-		for (minor = 1; minor <= 2; minor++) {
-			name2[8]= '0' + i;
-			name2[10]= '0' + minor;
-
-			fd = open(name2, O_RDONLY);
-			if (fd < 0)
-			{
-				if (errno != ENXIO)
-				{
-					fprintf(stderr,
-						"open '%s' failed: %s\n",
-						name2, strerror(errno));
-				}
-				found= 0;
-				break;
-			}
-			r = read(fd, pvd, sizeof(pvd));
-			if (r != sizeof(pvd))
-			{
-				fprintf(stderr,
-				"error reading super block from '%s': %s\n",
-					name2, strerror(errno));
-				close(fd);
-				found= 0;
-				break;
-			}
-			close(fd);
-
-			magicp= (u16_t *)&pvd[SUPER_OFF+MAGIC_OFF];
-			if (*magicp != SUPER_V3)
-			{
-				fprintf(stderr, "bad super block on %s\n",
-					name2);
-				found= 0;
-				break;
-			}
-		}
-
-		if (found)
-		{
-			printf("%s\n", name1);
-			exit(0);
-		}
-	}
-
-	return 1;
-}
-
Index: trunk/minix/commands/simple/cgrep.c
===================================================================
--- trunk/minix/commands/simple/cgrep.c	(revision 9)
+++ 	(revision )
@@ -1,379 +1,0 @@
-/* cgrep - grep and display context	Author: Mark Mallet */
-
-/*
-        Nov 19 1984     Mark Mallett   (mem@zinn.MV.COM)
-
-mem	860224	Modified to do r/e (regular expression) parsing on unix
-mem	860324	Added -f, -n; added code to number lines correctly on output.
-mem	870325	Added support for regcmp()/regex() style regular expression
-  library; redid some conditionals to provide better mix'n'match.
-mem	870326	Don't try to print the filename if reading from stdin.
-  Add -w option.  Fix a small problem which occasionally allowed
-  the separator to come out between adjacent lines of the file.
-mem	871119	Fix semantics of call to regcmp(): the NULL terminating the
-  argument list was missing.  It worked, but probably only
-  due to some bizarre coincidence.
-dro	890109  Minor mods to compile under Minix
-
-*/
-
-#define  OS_UNIX		/* Define this for unix systems */
- /* #define	REGEX *//* Define this for re_comp/re_exec library */
-#define  REGCMP			/* Define this to use regcmp/regex */
- /* #define	OS_CPM *//* Define this for CP/M-80 */
-
-
-/* Don't touch these */
-#define	NOREGEXP		/* Set this for no regular expression */
-#ifdef	REGEX
-#undef	NOREGEXP
-#endif	/* REGEX */
-
-#ifdef	REGCMP
-#undef	NOREGEXP
-#endif	/* REGCMP */
-
-
-#ifdef OS_CPM
-#include "stdio.h"
-#include "ctype.h"
-#endif /* OS_CPM */
-
-#ifdef OS_UNIX
-#include <sys/types.h>
-#include <sys/dir.h>		/* Either here or in sys directory - dro */
-#include <ctype.h>
-#include <limits.h>		/* should have this                - dro */
-#include <regexp.h>		/* should have this                - dro */
-#include <stdlib.h>
-#include <stdio.h>
-#endif /* OS_UNIX */
-
-
-/* Local definitions */
-
-#ifndef	NULL
-#define	NULL	((char *)0)
-#endif	/* NULL */
-
-#ifndef NUL
-#define NUL     '\000'
-#endif
-
-#ifndef TRUE
-#define TRUE    1
-#define FALSE   0
-#endif
-
-
-/* Internal data declared global */
-
-
-/* Internal routines */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void dosrch, (char *ifnm));
-_PROTOTYPE(void shwlin, (char *fnm, int linnum, char *line));
-_PROTOTYPE(int matlin, (char *line));
-_PROTOTYPE(void regerror, (const char *s));
-
-/* External data */
-
-
-/* Local data */
-
-static int Debug = {FALSE};	/* Debug enabled flag */
-static int Lcur = {0};		/* Current line (in Lines array) */
-static char **Lines = {NULL};	/* Lines pointer array */
-static int Linlen = {100};	/* Line length */
-static int Lone = {0};		/* Line one (in Lines array) */
-static int Nmr = {0};		/* Number of matched regions */
-static char *Pat = {NULL};	/* Pattern */
-static char Shwfile = {TRUE};	/* Show file name... */
-static char Shwline = {TRUE};	/* Show line number */
-static int Waft = {0};		/* Window after */
-static int Wbef = {0};		/* Window before */
-static int Wsiz = {0};		/* Window size */
-
-regexp *Re;			/* Result from reg compilation */
-
-int main(argc, argv)
-int argc;			/* Argument count */
-char **argv;			/* Argument values */
-
-{
-  int i;			/* Scratch */
-  int n;			/* Scratch again */
-  int c;			/* A character */
-  char *aptr;			/* Argument pointer */
-  int nf;			/* number of files on command line */
-
-  nf = 0;			/* No files on line */
-
-  for (i = 1; i < argc; i++) {	/* Look at args */
-	if (argv[i][0] != '-') {/* If option */
-		if (Pat == NULL) {	/* If no pattern yet given */
-			Pat = argv[i];	/* point here */
-#ifdef	REGEX
-			if ((Re = re_comp(Pat)) != NULL) {
-				fprintf(stderr, "cgrep: %s\n", re);
-				exit(1);
-			}
-#endif	/* REGEX */
-
-#ifdef	REGCMP
-			if ((Re = regcomp(Pat)) == NULL) {
-				fprintf(stderr, "cgrep: error in regular expression.\n");
-				exit(1);
-			}
-#endif	/* REGCMP */
-
-		} else {	/* This must be a file to search */
-			nf++;	/* Count it */
-			dosrch(argv[i]);	/* Search */
-		}
-	} else {		/* Option char */
-		c = argv[i][1];	/* Get option char */
-		if (isupper(c))	/* Trap idiot definition of tolower */
-			c = tolower(c);	/* Don't care about case */
-		n = i;
-		aptr = NULL;	/* Find arg, if any */
-		if (argv[i][2] != NUL) {
-			aptr = &argv[i][2];
-			n = i;	/* Where to set i if we use this arg */
-		} else if (i < argc - 1) {	/* use next.. */
-			n = i + 1;
-			aptr = argv[n];
-		}
-		switch (c) {	/* Process the option */
-		    case 'a':	/* Lines after */
-			Waft = atoi(aptr);
-			Lines = NULL;
-			i = n;
-			break;
-
-		    case 'b':	/* Lines before */
-			Wbef = atoi(aptr);
-			Lines = NULL;
-			i = n;
-			break;
-
-/* Disable debug output
-                    case 'd':	Debug = TRUE;	                 break;
-*/
-
-		    case 'f':	/* Suppress filename on output */
-			Shwfile = FALSE;
-			break;
-
-		    case 'l':	/* Line length */
-			Linlen = atoi(aptr);
-			Lines = NULL;
-			i = n;
-			break;
-
-		    case 'n':	/* Suppress line number on output */
-			Shwline = FALSE;
-			break;
-
-		    case 'w':	/* Window: lines before and after */
-			Waft = Wbef = atoi(aptr);
-			Lines = NULL;
-			i = n;
-			break;
-
-		    default:
-			fprintf(stderr, "Invalid option %s\n", argv[i]);
-			exit(1);
-		}
-	}
-  }
-
-  if (Pat == NULL) {		/* If no pattern given */
-	fprintf(stderr,
-		"Usage: cgrep [-a n] [-b n] [-f] [-l n] [-n] [-w n] pattern [filename... ]\n");
-	exit(1);
-  }
-  if (nf == 0)			/* No files processed ? */
-	dosrch((char *)NULL);		/* Do standard input */
-  return(0);
-}
-
- /* Dosrch (ifnm) Perform the search 
-  * Accepts :
-  * 
-  * ifn             Input file name
-  * 
-  * 
-  * Returns :
-  * 
-  * 
-  */
-
-void dosrch(ifnm)
-char *ifnm;			/* Input filelname */
-
-{
-  FILE *ifp;			/* Input fp */
-  char *lptr;			/* Line pointer */
-  int i;			/* Scratch */
-  int prtaft;			/* Print-after count */
-  int linnum;			/* Line number */
-  int nlb;			/* Number of lines buffered */
-
-  if (ifnm != NULL) {		/* If file name given */
-	ifp = fopen(ifnm, "r");	/* Open it for read access */
-	if (ifp == NULL) {
-		fprintf(stderr, "Can not open file %s\n", ifnm);
-		return;
-	}
-  } else
-	ifp = stdin;
-
-  if (Lines == NULL) {		/* If no line table allocated.. */
-	Wsiz = Wbef + 2;	/* Determine total window size */
-	Lines = (char **) calloc((size_t)Wsiz, sizeof(char *));
-	/* Allocate pointer table */
-	for (i = 0; i < Wsiz; i++)	/* Allocate line buffers */
-		Lines[i] = (char *) calloc((size_t)Linlen, sizeof(char));
-  }
-  Lcur = Lone = 0;		/* Setup line pointers */
-  nlb = 0;			/* No lines buffered */
-  linnum = 0;			/* Line number is zero */
-  prtaft = -(Wbef + 1);		/* Make sure separator given first time */
-
-  for (;;) {			/* Loop through the file */
-	lptr = Lines[Lcur];	/* Get pointer to current line */
-	if (++Lcur == Wsiz)	/* Bump curr pointer and wrap */
-		Lcur = 0;	/* if hit end */
-	if (Lone == Lcur)	/* If wrapped to beginning of window */
-		if (++Lone == Wsiz)	/* Bump beginning */
-			Lone = 0;	/* and wrap if hit end */
-
-	if (fgets(lptr, Linlen, ifp) != lptr) break;	/* if end of file */
-
-	linnum++;		/* Count line number */
-	if (matlin(lptr)) {	/* If matching line */
-		if (prtaft < (-Wbef))	/* Check for separator needed */
-			if ((Nmr++ > 0) && ((Wbef > 0) || (Waft > 0)))
-				printf("----------------------------------------------------------------------------\n");
-		while (Lone != Lcur) {	/* Until we close the window */
-			shwlin(ifnm, linnum - nlb, Lines[Lone]);
-			/* Show the line */
-			if (++Lone == Wsiz) Lone = 0;
-			nlb--;
-		}
-		nlb = 0;	/* No lines buffered */
-		prtaft = Waft;	/* Print n lines after */
-	} else {		/* Didn't match */
-		if (prtaft-- > 0) {	/* If must print lines after */
-			shwlin(ifnm, linnum, lptr);
-			/* Show the line */
-			Lone = Lcur;	/* Match pointers */
-		} else if (nlb < Wbef)	/* Count lines buffered */
-			nlb++;
-	}
-  }
-
-  if (ifnm != NULL) fclose(ifp);
-}
-
- /* Shwlin (fnm, linnum, line) Show a matching line 
-  * 
-  * Accepts :
-  * 
-  * fnm             File name
-  * 
-  * linnum          Line number
-  * 
-  * line            Line to show
-  * 
-  * 
-  * Returns :
-  * 
-  * 
-  */
-
-void shwlin(fnm, linnum, line)
-char *fnm;			/* File name */
-int linnum;			/* Line number */
-char *line;			/* Line (with newline at end) to print */
-
-{
-  if (Shwfile && (fnm != NULL)) printf("%s%s", fnm, Shwline ? " " : ":");
-  if (Shwline) printf("@%05d:", linnum);
-  printf("%s", line);
-}
-
- /* Matlin (line) Perform match against pattern and line 
-  * 
-  * Accepts :
-  * 
-  * line            Address of line to match
-  * 
-  * 
-  * Returns :
-  * 
-  * <value>         TRUE if match FALSE if not
-  * 
-  * 
-  */
-
-
-int matlin(line)
-char *line;			/* Line to match */
-
-{
-  int rtncode;			/* Return value from this routine */
-
-
-#ifdef	NOREGEXP
-  char *pptr, *lptr, *tlptr;
-  int c1, c2;
-#endif /* NOREGEXP */
-
-  if (Debug) printf("Matching %s against %s", Pat, line);
-
-#ifdef	REGEX
-  rtncode = re_exec(line);	/* Hand off to r/e evaluator */
-#endif	/* REGEX */
-
-#ifdef	REGCMP
-  rtncode = (regexec(Re, line, TRUE) != 0);
-#endif /* REGCMP */
-
-#ifdef	NOREGEX			/* Have to do menial comparison.. */
-  lptr = line;			/* Init line pointer */
-
-  for (rtncode = -1; rtncode < 0;) {
-	tlptr = lptr++;		/* Get temp ptr to line */
-	pptr = Pat;		/* Get ptr to pattern */
-	while (TRUE) {
-		if ((c1 = *pptr++) == NUL) {
-			rtncode = 1;	/* GOOD return value */
-			break;
-		}
-		if ((c2 = *tlptr++) == NUL) {
-			rtncode = 0;	/* BAD return value */
-			break;
-		}
-		if (isupper(c1)) c1 = tolower(c1);
-		if (isupper(c2)) c2 = tolower(c2);
-		if (c1 != c2) break;
-	}
-  }
-#endif	/* NOREGEX */
-
-
-  if (Debug) printf("matlin returned %s\n", rtncode ? "TRUE" : "FALSE");
-  return(rtncode);
-}
-
-
-
-void regerror(s)
-const char *s;
-{
-  printf("%s\n", (char *) s);
-  exit(1);
-}
Index: trunk/minix/commands/simple/chmem.c
===================================================================
--- trunk/minix/commands/simple/chmem.c	(revision 9)
+++ 	(revision )
@@ -1,148 +1,0 @@
-/* chmem - set total memory size for execution	Author: Andy Tanenbaum */
-
-#include <minix/config.h>
-#include <sys/types.h>
-#include <a.out.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#define MAX_8086     0x10000L	/* maximum allocation size for 8086 */
-#define MAX_386	  0x7FFFFFFFL	/* etc */
-#define MAX_68K   0x7FFFFFFFL
-#define MAX_SPARC 0x20000000L	/* No more than 512MB on a SparcStation! */
-
-char *progname;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void error, (char *s1, char *s2));
-_PROTOTYPE(void usage, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-/* The 8088 architecture does not make it possible to catch stacks that grow
- * big.  The only way to deal with this problem is to let the stack grow down
- * towards the data segment and the data segment grow up towards the stack.
- * Normally, a total of 64K is allocated for the two of them, but if the
- * programmer knows that a smaller amount is sufficient, he can change it
- * using chmem.
- *
- * chmem =4096 prog  sets the total space for stack + data growth to 4096
- * chmem +200  prog  increments the total space for stack + data growth by 200
- */
-
-  char *p;
-  int fd = -1, separate;
-  size_t s;
-  long lsize, olddynam, newdynam, newtot, overflow;
-  struct exec exec;
-  char cpu;
-  long max;
-  int last_failed = 0, any_failed = 0;
-
-  progname = argv[0];
-  if (argc < 3) usage();
-  p = argv[1];
-  if (*p != '=' && *p != '+' && *p != '-') usage();
-  lsize = atol(p + 1);
-  s = sizeof(struct exec);
-
-  if (lsize < 0) {
-	error(p + 1, "is negative");
-	exit(1);
-  }
-  argc -= 1;
-  argv += 1;
-
-  while (--argc) {
-	if(last_failed) any_failed = 1;
-
-	/* Unless we reach the end of this loop, this one failed. */
-	last_failed = 1;
-	++argv;
-	if(fd != -1) close(fd);
-	fd = open(*argv, O_RDWR);
-	if (fd < 0) {
-		error("can't open", *argv);
-		continue;
-	}
-	if (read(fd, (char *) &exec, s) != s) {
-		error("can't read header in", *argv);
-		continue;
-	}
-	if (BADMAG(exec)) {
-		error(*argv, "is not executable");
-		continue;
-	}
-	separate = (exec.a_flags & A_SEP ? 1 : 0);
-	cpu = exec.a_cpu;
-
-#if (CHIP == M68000)
-	if (cpu == A_I8086) cpu = A_M68K;
-#endif
-
-	switch (cpu) {
-	    case A_I8086:	max = MAX_8086;	break;
-	    case A_I80386:	max = MAX_386;	break;
-	    case A_M68K:	max = MAX_68K;	break;
-	    case A_SPARC:	max = MAX_SPARC;	break;
-	    default:
-		error("bad CPU type in", *argv);
-		continue;
-	}
-
-	if (lsize > max) {
-		error("size is too large for", *argv);
-		continue;
-	}
-	olddynam = exec.a_total - exec.a_data - exec.a_bss;
-	if (separate == 0) olddynam -= exec.a_text;
-
-	if (*p == '=')
-		newdynam = lsize;
-	else if (*p == '+')
-		newdynam = olddynam + lsize;
-	else if (*p == '-')
-		newdynam = olddynam - lsize;
-
-	newtot = exec.a_data + exec.a_bss + newdynam;
-	if (separate == 0) newtot += exec.a_text;
-	overflow = (newtot > max ? newtot - max : 0);
-	newdynam -= overflow;
-	newtot -= overflow;
-	exec.a_total = newtot;
-	lseek(fd, (long) 0, SEEK_SET);
-	if (write(fd, (char *) &exec, s) != s) {
-		error("can't modify", *argv);
-		continue;
-	}
-	printf("%s: Stack+malloc area changed from %ld to %ld bytes.\n",
-	       *argv, olddynam, newdynam);
-
-	/* This one didn't fail. */
-	last_failed = 0;
-  }
-  return(any_failed || last_failed ? 1 : 0);
-}
-
-void error(s1, s2)
-char *s1;
-char *s2;
-{
-  fprintf(stderr, "%s: %s ", progname, s1);
-  if (errno != 0)
-	perror(s2);
-  else
-	fprintf(stderr, "%s\n", s2);
-  errno = 0;
-}
-
-void usage()
-{
-  fprintf(stderr, "Usage: %s {=+-} amount file\n", progname);
-  exit(1);
-}
Index: trunk/minix/commands/simple/chmod.c
===================================================================
--- trunk/minix/commands/simple/chmod.c	(revision 9)
+++ 	(revision )
@@ -1,254 +1,0 @@
-/* chmod - Change file modes				Author: V. Archer */
-
-/* Copyright 1991 by Vincent Archer
- *	You may freely redistribute this software, in source or binary
- *	form, provided that you do not alter this copyright mention in any
- *	way.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <minix/minlib.h>
-#include <stdio.h>
-
-#ifndef S_ISLNK
-#define S_ISLNK(mode)	0
-#define lstat		stat
-#endif
-
-#define USR_MODES (S_ISUID|S_IRWXU)
-#define GRP_MODES (S_ISGID|S_IRWXG)
-#define EXE_MODES (S_IXUSR|S_IXGRP|S_IXOTH)
-#ifdef S_ISVTX
-#define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO|S_ISVTX)
-#else
-#define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO)
-#endif
-
-
-/* Common variables */
-char *symbolic;
-mode_t new_mode, u_mask;
-int rflag, errors;
-struct stat st;
-char path[PATH_MAX + 1];
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(mode_t parsemode, (char *symbolic, mode_t oldmode));
-_PROTOTYPE(int do_change, (char *name));
-_PROTOTYPE(void usage, (void));
-
-/* Parse a P1003.2 4.7.7-conformant symbolic mode. */
-mode_t parsemode(char *symbolic, mode_t oldmode)
-{
-  mode_t who, mask, newmode, tmpmask;
-  char action;
-
-  newmode = oldmode & ALL_MODES;
-  while (*symbolic) {
-	who = 0;
-	for (; *symbolic; symbolic++) {
-		if (*symbolic == 'a') {
-			who |= ALL_MODES;
-			continue;
-		}
-		if (*symbolic == 'u') {
-			who |= USR_MODES;
-			continue;
-		}
-		if (*symbolic == 'g') {
-			who |= GRP_MODES;
-			continue;
-		}
-		if (*symbolic == 'o') {
-			who |= S_IRWXO;
-			continue;
-		}
-		break;
-	}
-	if (!*symbolic || *symbolic == ',') usage();
-	while (*symbolic) {
-		if (*symbolic == ',') break;
-		switch (*symbolic) {
-		    default:
-			usage();
-		    case '+':
-		    case '-':
-		    case '=':	action = *symbolic++;
-		}
-		mask = 0;
-		for (; *symbolic; symbolic++) {
-			if (*symbolic == 'u') {
-				tmpmask = newmode & S_IRWXU;
-				mask |= tmpmask | (tmpmask << 3) | (tmpmask << 6);
-				symbolic++;
-				break;
-			}
-			if (*symbolic == 'g') {
-				tmpmask = newmode & S_IRWXG;
-				mask |= tmpmask | (tmpmask >> 3) | (tmpmask << 3);
-				symbolic++;
-				break;
-			}
-			if (*symbolic == 'o') {
-				tmpmask = newmode & S_IRWXO;
-				mask |= tmpmask | (tmpmask >> 3) | (tmpmask >> 6);
-				symbolic++;
-				break;
-			}
-			if (*symbolic == 'r') {
-				mask |= S_IRUSR | S_IRGRP | S_IROTH;
-				continue;
-			}
-			if (*symbolic == 'w') {
-				mask |= S_IWUSR | S_IWGRP | S_IWOTH;
-				continue;
-			}
-			if (*symbolic == 'x') {
-				mask |= EXE_MODES;
-				continue;
-			}
-			if (*symbolic == 's') {
-				mask |= S_ISUID | S_ISGID;
-				continue;
-			}
-			if (*symbolic == 'X') {
-				if (S_ISDIR(oldmode) || (oldmode & EXE_MODES))
-					mask |= EXE_MODES;
-				continue;
-			}
-#ifdef S_ISVTX
-			if (*symbolic == 't') {
-				mask |= S_ISVTX;
-				who |= S_ISVTX;
-				continue;
-			}
-#endif
-			break;
-		}
-		switch (action) {
-		    case '=':
-			if (who)
-				newmode &= ~who;
-			else
-				newmode = 0;
-		    case '+':
-			if (who)
-				newmode |= who & mask;
-			else
-				newmode |= mask & (~u_mask);
-			break;
-		    case '-':
-			if (who)
-				newmode &= ~(who & mask);
-			else
-				newmode &= ~mask | u_mask;
-		}
-	}
-	if (*symbolic) symbolic++;
-  }
-  return(newmode);
-}
-
-
-/* Main module. The single option possible (-R) does not warrant a call to
- * the getopt() stuff.
- */
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int ex_code = 0;
-
-  argc--;
-  argv++;
-
-  if (argc && strcmp(*argv, "-R") == 0) {
-	argc--;
-	argv++;
-	rflag = 1;
-  } else
-	rflag = 0;
-
-  if (!argc--) usage();
-  if (!strcmp(argv[0], "--")) {	/* Allow chmod -- -r, as in Draft11 example */
-	if (!argc--) usage();
-	argv++;
-  }
-  symbolic = *argv++;
-  if (!argc) usage();
-
-  if (*symbolic >= '0' && *symbolic <= '7') {
-	new_mode = 0;
-	while (*symbolic >= '0' && *symbolic <= '7')
-		new_mode = (new_mode << 3) | (*symbolic++ & 07);
-	if (*symbolic) usage();
-	new_mode &= ALL_MODES;
-	symbolic = (char *) 0;
-  } else
-	u_mask = umask(0);
-
-  while (argc--)
-	if (do_change(*argv++)) ex_code = 1;
-  return(ex_code);
-}
-
-
-/* Apply a mode change to a given file system element. */
-int do_change(name)
-char *name;
-{
-  mode_t m;
-  DIR *dirp;
-  struct dirent *entp;
-  char *namp;
-
-  if (lstat(name, &st)) {
-	perror(name);
-	return(1);
-  }
-  if (S_ISLNK(st.st_mode) && rflag) return(0);	/* Note: violates POSIX. */
-  if (!symbolic)
-	m = new_mode;
-  else
-	m = parsemode(symbolic, st.st_mode);
-  if (chmod(name, m)) {
-	perror(name);
-	errors = 1;
-  } else
-	errors = 0;
-
-  if (S_ISDIR(st.st_mode) && rflag) {
-	if (!(dirp = opendir(name))) {
-		perror(name);
-		return(1);
-	}
-	if (name != path) strcpy(path, name);
-	namp = path + strlen(path);
-	*namp++ = '/';
-	while (entp = readdir(dirp))
-		if (entp->d_name[0] != '.' ||
-		    (entp->d_name[1] &&
-		     (entp->d_name[1] != '.' || entp->d_name[2]))) {
-			strcpy(namp, entp->d_name);
-			errors |= do_change(path);
-		}
-	closedir(dirp);
-	*--namp = '\0';
-  }
-  return(errors);
-}
-
-
-/* Display Posix prototype */
-void usage()
-{
-  std_err("Usage: chmod [-R] mode file...\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/chown.c
===================================================================
--- trunk/minix/commands/simple/chown.c	(revision 9)
+++ 	(revision )
@@ -1,168 +1,0 @@
-/* chown/chgrp - Change file ownership			Author: V. Archer */
-
-/* Copyright 1991 by Vincent Archer
- *	You may freely redistribute this software, in source or binary
- *	form, provided that you do not alter this copyright mention in any
- *	way.
- */
-
-/* Changed  3 Feb 93 by Kees J. Bot:  setuid execution nonsense removed.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <pwd.h>
-#include <grp.h>
-#include <string.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <minix/minlib.h>
-#include <stdio.h>
-
-#ifndef S_ISLNK
-#define S_ISLNK(mode)	0
-#define lstat		stat
-#endif
-
-#define S_IUGID (S_ISUID|S_ISGID)
-
-/* Global variables, such as flags and path names */
-int gflag, oflag, rflag, error;
-char *pgmname, path[PATH_MAX + 1];
-uid_t nuid;
-gid_t ngid;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void do_chown, (char *file));
-_PROTOTYPE(void usage, (void));
-
-/* Main module. If chown(1) is invoked as chgrp(1), the behaviour is nearly
- * identical, except that the default when a single name is given as an
- * argument is to take a group id rather than an user id. This allow the
- * non-Posix "chgrp user:group file".
- * The single option switch used by chown/chgrp (-R) does not warrant a
- * call to the getopt stuff. The two others flags (-g, -u) are set from
- * the program name and arguments.
- */
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char *id, *id2;
-  struct group *grp;
-  struct passwd *pwp;
-
-  if (pgmname = strrchr(*argv, '/'))
-	pgmname++;
-  else
-	pgmname = *argv;
-  argc--;
-  argv++;
-  gflag = strcmp(pgmname, "chgrp");
-
-  if (argc && **argv == '-' && argv[0][1] == 'R') {
-	argc--;
-	argv++;
-	rflag = 1;
-  }
-  if (argc < 2) usage();
-
-  id = *argv++;
-  argc--;
-  if (id2 = strchr(id, ':')) *id2++ = '\0';
-  if (!id2 && !gflag) {
-	id2 = id;
-	id = 0;
-  }
-  if (id) {
-	if (isdigit(*id))
-		nuid = atoi(id);
-	else {
-		if (!(pwp = getpwnam(id))) {
-			std_err(id);
-			std_err(": unknown user name\n");
-			exit(1);
-		}
-		nuid = pwp->pw_uid;
-	}
-	oflag = 1;
-  } else
-	oflag = 0;
-
-  if (id2) {
-	if (isdigit(*id2))
-		ngid = atoi(id2);
-	else {
-		if (!(grp = getgrnam(id2))) {
-			std_err(id2);
-			std_err(": unknown group name\n");
-			exit(1);
-		}
-		ngid = grp->gr_gid;
-	}
-	gflag = 1;
-  } else
-	gflag = 0;
-
-  error = 0;
-  while (argc--) do_chown(*argv++);
-  return(error);
-}
-
-/* Apply the user/group modification here.
- */
-void do_chown(file)
-char *file;
-{
-  DIR *dirp;
-  struct dirent *entp;
-  char *namp;
-  struct stat st;
-
-  if (lstat(file, &st)) {
-	perror(file);
-	error = 1;
-	return;
-  }
-
-  if (S_ISLNK(st.st_mode) && rflag) return;	/* Note: violates POSIX. */
-
-  if (chown(file, oflag ? nuid : st.st_uid, gflag ? ngid : st.st_gid)) {
-	perror(file);
-	error = 1;
-  }
-
-  if (S_ISDIR(st.st_mode) && rflag) {
-	if (!(dirp = opendir(file))) {
-		perror(file);
-		error = 1;
-		return;
-	}
-	if (path != file) strcpy(path, file);
-	namp = path + strlen(path);
-	*namp++ = '/';
-	while (entp = readdir(dirp))
-		if (entp->d_name[0] != '.' ||
-		    (entp->d_name[1] &&
-		     (entp->d_name[1] != '.' || entp->d_name[2]))) {
-			strcpy(namp, entp->d_name);
-			do_chown(path);
-		}
-	closedir(dirp);
-	*--namp = '\0';
-  }
-}
-
-/* Posix prototype of the chown/chgrp function */
-void usage()
-{
-  std_err("Usage: ");
-  std_err(pgmname);
-  std_err(gflag ? " owner[:group]" : " [owner:]group");
-  std_err(" file...\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/chroot.c
===================================================================
--- trunk/minix/commands/simple/chroot.c	(revision 9)
+++ 	(revision )
@@ -1,28 +1,0 @@
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <sys/wait.h>
-
-int
-main(int argc, char *argv[])
-{
-	int status;
-
-	if(argc != 3) {
-		fprintf(stderr, "usage: %s <root> <command>\n", argv[0]);
-		return 1;
-	}
-
-	if(chroot(argv[1]) < 0) {
-		perror("chroot");
-		return 1;
-	}
-
-	status = system(argv[2]);
-	if(WIFEXITED(status))
-		return WEXITSTATUS(status);
-	return 1;
-}
-
Index: trunk/minix/commands/simple/ci.c
===================================================================
--- trunk/minix/commands/simple/ci.c	(revision 9)
+++ 	(revision )
@@ -1,343 +1,0 @@
-/* ci - check in 			Author: Peter S. Housel 12/17/87 */
-
-#include <sys/types.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <fcntl.h>
-#include <sys/wait.h>
-#include <stdio.h>
-
-#define SUFFIX		",S"	/* svc indicator */
-#define SVCDIR		"SVC"	/* svc postfix indicator */
-
-#define LINELEN		256	/* maximum line length */
-
-#ifndef PATCH
-#define FIX		"fix $1 Fix.$1 > New.$1; mv New.$1 $1\n"
-#else
-#define FIX		"patch -n -s $1 < Fix.$1; rm -f $1.orig\n"
-#endif /* !PATCH */
-
-#ifdef MAXPATHLEN
-#define PATHLEN MAXPATHLEN
-#else
-#define PATHLEN 128		/* buffer length for filenames */
-#endif
-
-int unlocked = 0;		/* leave unlocked after checkin */
-int relock = 0;			/* lock next revision after checkin */
-char file[PATHLEN];		/* file to be checked in */
-char svc[PATHLEN];		/* filename for svc file */
-char newsvc[PATHLEN];		/* new copy of SVC file */
-char line[LINELEN];		/* temporary line buffer */
-char *p;			/* scratch character pointer */
-
-FILE *svcfp;			/* svc file */
-FILE *origfp, *newfp;		/* "orig" and "new" temp files */
-FILE *srcfp;			/* source file */
-int rev;			/* new revision number */
-int status;			/* wait() buffer */
-struct stat stb1, stb2;		/* stat buffers for size compare */
-char original[] = "/tmp/cioXXXXXX";	/* previous revision */
-char diffout[] = "/tmp/cidXXXXXX";	/* diffs */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void rundiff, (void));
-_PROTOTYPE(void logmsg, (FILE *fp));
-_PROTOTYPE(void fname, (char *src, char *dst));
-_PROTOTYPE(void svcname, (char *src, char *dst));
-_PROTOTYPE(int lockcheck, (FILE *fp, int rev));
-_PROTOTYPE(void onintr, (int dummy));
-_PROTOTYPE(void clean, (void));
-_PROTOTYPE(char *whoami, (void));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-#ifdef perprintf
-  char errbuf[BUFSIZ];
-  setbuf(stderr, errbuf);
-  perprintf(stderr);
-#endif
-
-  while (++argv, --argc) {
-	if ('-' == (*argv)[0]) {
-		if ('u' == (*argv)[1])
-			++unlocked;
-		else if ('l' == (*argv)[1])
-			++relock;
-		else {
-			fprintf(stderr, "ci: illegal option -%c\n", (*argv)[1]);
-			exit(1);
-		}
-	} else
-		break;
-  }
-
-  if (1 != argc) {
-	fprintf(stderr, "ci: bad number of files arguments\n");
-	exit(1);
-  }
-  fname(*argv, file);
-  svcname(file, svc);
-
-  fprintf(stderr, "%s -> %s\n", file, svc);
-
-  signal(SIGHUP, onintr);
-  signal(SIGINT, onintr);
-  signal(SIGTERM, onintr);
-
-#ifndef BSD
-  if (NULL == (p = strrchr(file, '/')))
-	p = file;
-  else
-	++p;
-
-  if (strlen(p) > 13) {
-	fprintf(stderr, "ci: filename %s is too long\n", p);
-	exit(1);
-  }
-#endif /* !BSD */
-
-  strcpy(newsvc, svc);
-  *(strrchr(newsvc, ',')) = ';';	/* temporary file will be "file;S" */
-
-  if (NULL == (newfp = fopen(newsvc, "w"))) {
-	perror("ci: can't create SVC temporary");
-	exit(1);
-  }
-  (void) mktemp(original);
-  (void) mktemp(diffout);
-
-  if (NULL != (svcfp = fopen(svc, "r"))) {	/* does svc-file exist? */
-	fgets(line, LINELEN, svcfp);
-	if (1 != sscanf(line, "# %d", &rev)) {
-		fprintf(stderr, "ci: %s: illegal SVC file header\n", svc);
-		exit(1);
-	}
-	++rev;
-
-	if (!lockcheck(svcfp, rev)) {
-		fprintf(stderr, "Revision %d not locked\n", rev);
-		clean();
-		exit(1);
-	}
-	if (NULL == (origfp = fopen(original, "w"))) {
-		fprintf(stderr, "ci: can't create %s", original);
-		perror(" ");
-	}
-	fgets(line, LINELEN, svcfp);	/* skip "cat <<***MAIN-eof***" line */
-
-	while (NULL != fgets(line, LINELEN, svcfp)
-	       && strcmp(line, "***MAIN-eof***\n")) {
-		fputs(line, origfp);
-		if (ferror(origfp)) {
-			perror("ci: origfile");
-			exit(1);
-		}
-	}
-	fclose(origfp);
-
-	rundiff();
-
-	if (0 != stat(original, &stb1) || 0 != stat(diffout, &stb2)) {
-		perror("ci: can't stat original or diffout");
-		clean();
-		exit(1);
-	}
-  } else {			/* no - create one */
-	rev = 1;
-  }
-
-  fprintf(newfp, "# %d\n", rev);
-  fprintf(newfp, "cat <<***MAIN-eof*** >$1\n");
-  if (NULL == (srcfp = fopen(file, "r"))) {
-	perror("ci: can't read source file");
-	clean();
-	exit(1);
-  }
-  while (NULL != fgets(line, LINELEN, srcfp)) fputs(line, newfp);
-  fclose(srcfp);
-  fputs("***MAIN-eof***\n", newfp);
-
-  if (rev > 1) {
-	fprintf(newfp, "if test $2 -ge %d ; then rm -f Fix.$1 ; exit 0 ; fi ; cat <<***%d-eof*** >Fix.$1\n", rev, rev);
-	p = (stb1.st_size <= stb2.st_size) ? original : diffout;
-	if (NULL == (origfp = fopen(p, "r"))) {
-		perror("can't open diff output file");
-		clean();
-		exit(1);
-	}
-	while (NULL != fgets(line, LINELEN, origfp)) fputs(line, newfp);
-	fclose(origfp);
-	fprintf(newfp, "***%d-eof***\n", rev);
-	fputs((original == p) ? "mv Fix.$1 $1\n" : FIX, newfp);
-	logmsg(newfp);
-	while (NULL != fgets(line, LINELEN, svcfp) && strncmp(line, "#***SVCLOCK***", (size_t)14))
-		fputs(line, newfp);
-  } else {
-	logmsg(newfp);
-	fputs("rm -f Fix.$1\n", newfp);
-  }
-
-  if (relock) {
-	fprintf(stderr, "(relocking into revision %d)\n", rev + 1);
-	fprintf(newfp, "#***SVCLOCK*** %s %d\n", whoami(), rev + 1);
-  }
-  signal(SIGHUP, SIG_IGN);	/* disable during critical section */
-  signal(SIGINT, SIG_IGN);
-
-  if (ferror(newfp) || fclose(newfp) || ((rev > 1) && unlink(svc))
-      || link(newsvc, svc)) {
-	fprintf(stderr, "SVC file write/link error - Checkin aborted\n");
-	clean();
-	exit(1);
-  } else
-	fprintf(stderr, "Checkin complete.\n");
-
-  if (stat(svc, &stb1) < 0 || chmod(svc, stb1.st_mode & 0555) < 0)
-	perror("ci: can't chmod SVC file");
-
-  if (unlocked) {
-	if (stat(file, &stb1) < 0 || chmod(file, stb1.st_mode & 0555) < 0)
-		perror("ci: can't chmod source file");
-  } else if (relock) {
-	if (stat(file, &stb1) < 0 || chmod(file, stb1.st_mode | 0200) < 0)
-		perror("ci: can't chmod source file");
-  } else
-	unlink(file);
-
-  clean();
-  return(0);
-}
-
-void rundiff()
-{				/* do "diff file original > diffout" */
-  int fd;			/* redirected output file */
-
-  switch (fork()) {
-      case -1:
-	perror("ci: fork");	/* error */
-	clean();
-	exit(1);
-
-      case 0:			/* child */
-	if ((fd = creat(diffout, 0600)) < 0 || -1 == dup2(fd, 1)) {
-		perror("ci: diffout");
-		clean();
-		exit(1);
-	}
-	close(fd);
-	execlp("diff", "diff", file, original, (char *) 0);
-	perror("ci: exec diff failed");
-	exit(1);
-
-      default:	break;		/* parent */
-}
-  wait(&status);
-  if (0 != status && 1 << 8 != status) {
-	fprintf(stderr, "ci: bad return status (0x%x) from diff\n", status);
-	clean();
-	exit(1);
-  }
-}
-
-void logmsg(fp)
-FILE *fp;
-{
-  long now;
-
-  time(&now);
-  fprintf(stderr, "Enter log message for revision %d (end with ^D or '.'):\n", rev);
-  fprintf(fp, "#***SVC*** revision %d %s %s", rev, file, ctime(&now));
-  while (NULL != gets(line) && strcmp(line, "."))
-	fprintf(fp, "#***SVC*** %s\n", line);
-}
-
-void fname(src, dst)
-char *src, *dst;
-{
-  char *p;
-  strcpy(dst, src);
-  p = &dst[strlen(src) - strlen(SUFFIX)];
-  if (!strcmp(p, SUFFIX)) *p = '\0';
-}
-
-void svcname(src, dst)
-char *src, *dst;
-{
-  char *p;
-
-  strcpy(dst, src);
-  strcat(dst, SUFFIX);
-
-  if (0 != access(dst, 4)) {
-	char dirname[PATHLEN];
-	if (NULL != (p = strrchr(src, '/')))
-		strncpy(dirname, src, (size_t)(p - src + 1));
-	else
-		dirname[0] = '\0';
-	strcat(dirname, SVCDIR);
-
-	if (0 == access(dirname, 1)) {
-		strcpy(dst, dirname);
-		if (NULL == p) {
-			strcat(dst, "/");
-			strcat(dst, src);
-		} else
-			strcat(dst, p);
-		strcat(dst, SUFFIX);
-	}
-  }
-}
-
-int lockcheck(fp, rev)
-FILE *fp;
-int rev;
-{
-  char lock[40], check[40];
-  long pos;
-  int ret;
-
-  sprintf(lock, "#***SVCLOCK*** %s %d\n", whoami(), rev);
-
-  pos = ftell(fp);
-  fseek(fp, -((long) strlen(lock)), 2);
-  fgets(check, 40, fp);
-  ret = (0 == strcmp(lock, check));
-  fseek(fp, pos, 0);
-
-  return ret;
-}
-
-void onintr(dummy)
-int dummy; /* to keep the compiler happy */
-{
-  fprintf(stderr, "Interrupt - Aborting checkin, cleaning up\n");
-  clean();
-  exit(1);
-}
-
-void clean()
-{
-  if (strlen(original))		/* if only more programs made this check! */
-	unlink(original);
-  if (strlen(diffout)) unlink(diffout);
-  if (strlen(newsvc)) unlink(newsvc);
-}
-
-char *whoami()
-{
-  struct passwd *pw;
-
-  if (NULL != (pw = getpwuid(getuid())))
-	return pw->pw_name;
-  else
-	return "nobody";
-}
Index: trunk/minix/commands/simple/cksum.c
===================================================================
--- trunk/minix/commands/simple/cksum.c	(revision 9)
+++ 	(revision )
@@ -1,155 +1,0 @@
-/* cksum.c - Display file checksums and block counts	Author: V. Archer */
-
-/* Copyright 1991 by Vincent Archer
- *	You may freely redistribute this software, in source or binary
- *	form, provided that you do not alter this copyright mention in any
- *	way.
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-
-int error;
-
-/* Table from P1003.2 (4.9/Fig 4.1). In fact, this table was taken from zmodem
- * and rewritten to look like the Draft 11 example.
- */
-unsigned long crctab[] = {
-		  0x7fffffff,
-	 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
-	 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e,
-	 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
-	 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d,
-	 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0,
-	 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63,
-	 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
-	 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa,
-	 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75,
-	 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180,
-	 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
-	 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87,
-	 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
-	 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5,
-	 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
-	 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4,
-	 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b,
-	 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea,
-	 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
-	 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541,
-	 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc,
-	 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f,
-	 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
-	 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e,
-	 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
-	 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c,
-	 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
-	 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b,
-	 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2,
-	 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671,
-	 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
-	 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8,
-	 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767,
-	 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6,
-	 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
-	 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795,
-	 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
-	 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b,
-	 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
-	 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82,
-	 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d,
-	 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8,
-	 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
-	 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff,
-	 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee,
-	 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d,
-	 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
-	 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c,
-	 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
-	 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02,
-	  0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
-};
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void crc, (int fd, char *name));
-_PROTOTYPE(unsigned long strncrc, (unsigned char *b, int n, unsigned long s));
-
-static int aux;
-
-/* Routine straight out of 4.9.10 */
-unsigned long strncrc(b, n, s)
-register unsigned char *b;	/* byte sequence to checksum */
-register int n;			/* length of sequence */
-register unsigned long s;	/* initial checksum value */
-{
-  register int i;
-
-  while (n-- > 0) {
-	/* Compute the index to the crc table */
-	i = (s >> 24) ^ ((unsigned int) (*b++));
-
-	if (i == 0) {
-		/* Replace an intermediate zero with the next value
-		 * from the sequence */
-		i = aux++;
-		if (aux >= sizeof(crctab) / sizeof(crctab[0])) aux = 0;
-	}
-
-	/* New checksum value */
-	s = (s << 8) ^ crctab[i];
-  }
-  return(s);
-}
-
-/* Main module. No options switches allowed, none parsed. */
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  argc--;
-  error = 0;
-  if (!argc)
-	crc(0, (char *) 0);
-  else
-	for (argv++; argc--; argv++) crc(open(*argv, O_RDONLY), *argv);
-  return(error);
-}
-
-/* Compute crc and size of input file descriptor. */
-void crc(fd, name)
-int fd;
-char *name;
-{
-  off_t f_size;
-  unsigned long crc;
-  int nb;
-  unsigned char buffer[1024];
-
-  if (fd < 0) {
-	perror(name);
-	error = 1;
-	return;
-  }
-  crc = 0;
-  f_size = 0;
-  aux = 0;
-  for (;;) {
-	nb = read(fd, (char *) buffer, sizeof(buffer));
-	if (nb < 0) {
-		close(fd);
-		perror(name ? name : "stdin");
-		error = 1;
-		return;
-	}
-	if (!nb) break;
-	f_size += nb;
-	crc = strncrc(buffer, nb, crc);
-  }
-  close(fd);
-  printf("%lu %ld", crc, f_size);
-  if (name)
-	printf(" %s\n", name);
-  else
-	putchar('\n');
-}
Index: trunk/minix/commands/simple/cleantmp.c
===================================================================
--- trunk/minix/commands/simple/cleantmp.c	(revision 9)
+++ 	(revision )
@@ -1,361 +1,0 @@
-/*	cleantmp 1.6 - clean out a tmp dir.		Author: Kees J. Bot
- *								11 Apr 1991
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <time.h>
-#include <dirent.h>
-#include <errno.h>
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-#ifndef S_ISLNK
-/* There were no symlinks in medieval times. */
-#define lstat stat
-#endif
-
-#ifndef DEBUG
-#define NDEBUG
-#endif
-#include <assert.h>
-
-#define SEC_DAY	(24 * 3600L)	/* A full day in seconds */
-#define DOTDAYS	14		/* Don't remove tmp/.* in at least 14 days. */
-
-void report(const char *label)
-{
-	fprintf(stderr, "cleantmp: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-void *alloc(size_t s)
-{
-	void *mem;
-
-	if ((mem= (void *) malloc(s)) == nil) fatal("");
-	return mem;
-}
-
-int force= 0;			/* Force remove all. */
-int debug= 0;			/* Debug level. */
-
-void days2time(unsigned long days, time_t *retired, time_t *dotretired)
-{
-	struct tm *tm;
-	time_t t;
-
-	time(&t);
-
-	tm= localtime(&t);
-	tm->tm_hour= 0;
-	tm->tm_min= 0;
-	tm->tm_sec= 0;	/* Step back to midnight of this day. */
-	t= mktime(tm);
-
-	if (t < (days - 1) * SEC_DAY) {
-		*retired= *dotretired= 0;
-	} else {
-		*retired= t - (days - 1) * SEC_DAY;
-		*dotretired= t - (DOTDAYS - 1) * SEC_DAY;
-		if (*dotretired > *retired) *dotretired= *retired;
-	}
-	if (debug >= 2) fprintf(stderr, "Retired:    %s", ctime(retired));
-	if (debug >= 2) fprintf(stderr, "Dotretired: %s", ctime(dotretired));
-}
-
-/* Path name construction, addpath adds a component, delpath removes it.
- * The string 'path' is used throughout the program as the file under
- * examination.
- */
-
-char *path;	/* Path name constructed in path[]. */
-int plen= 0, pidx= 0;	/* Lenght/index for path[]. */
-
-void addpath(int *didx, char *name)
-/* Add a component to path. (name may also be a full path at the first call)
- * The index where the current path ends is stored in *pdi.
- */
-{
-	if (plen == 0) path= (char *) alloc((plen= 32) * sizeof(path[0]));
-
-	*didx= pidx;	/* Record point to go back to for delpath. */
-
-	if (pidx > 0 && path[pidx-1] != '/') path[pidx++]= '/';
-
-	do {
-		if (*name != '/' || pidx == 0 || path[pidx-1] != '/') {
-			if (pidx == plen &&
-				(path= (char *) realloc((void *) path,
-					(plen*= 2) * sizeof(path[0]))) == nil
-			) fatal("");
-			path[pidx++]= *name;
-		}
-	} while (*name++ != 0);
-
-	--pidx;		/* Put pidx back at the null.  The path[pidx++]= '/'
-			 * statement will overwrite it at the next call.
-			 */
-	assert(pidx < plen);
-}
-
-void delpath(int didx)
-{
-	assert(0 <= didx);
-	assert(didx <= pidx);
-	path[pidx= didx]= 0;
-}
-
-struct file {
-	struct file	*next;
-	char		*name;
-};
-
-struct file *listdir(void)
-{
-	DIR *dp;
-	struct dirent *entry;
-	struct file *first, **last= &first;
-
-	if ((dp= opendir(path)) == nil) {
-		report(path);
-		return nil;
-	}
-
-	while ((entry= readdir(dp)) != nil) {
-		struct file *new;
-
-		if (strcmp(entry->d_name, ".") == 0
-			|| strcmp(entry->d_name, "..") == 0) continue;
-
-		new= (struct file *) alloc(sizeof(*new));
-		new->name= (char *) alloc((size_t) strlen(entry->d_name) + 1);
-		strcpy(new->name, entry->d_name);
-
-		*last= new;
-		last= &new->next;
-	}
-	closedir(dp);
-	*last= nil;
-
-	return first;
-}
-
-struct file *shorten(struct file *list)
-{
-	struct file *junk;
-
-	assert(list != nil);
-
-	junk= list;
-	list= list->next;
-
-	free((void *) junk->name);
-	free((void *) junk);
-
-	return list;
-}
-
-/* Hash list of files to ignore. */
-struct file *ignore_list[1024];
-size_t n_ignored= 0;
-
-unsigned ihash(char *name)
-/* A simple hashing function on a file name. */
-{
-	unsigned h= 0;
-
-	while (*name != 0) h= (h * 0x1111) + *name++;
-
-	return h & (arraysize(ignore_list) - 1);
-}
-
-void do_ignore(int add, char *name)
-/* Add or remove a file to/from the list of files to ignore. */
-{
-	struct file **ipp, *ip;
-
-	ipp= &ignore_list[ihash(name)];
-	while ((ip= *ipp) != nil) {
-		if (strcmp(name, ip->name) <= 0) break;
-		ipp= &ip->next;
-	}
-
-	if (add) {
-		ip= alloc(sizeof(*ip));
-		ip->name= alloc((strlen(name) + 1) * sizeof(ip->name[0]));
-		strcpy(ip->name, name);
-		ip->next= *ipp;
-		*ipp= ip;
-		n_ignored++;
-	} else {
-		assert(ip != nil);
-		*ipp= ip->next;
-		free(ip->name);
-		free(ip);
-		n_ignored--;
-	}
-}
-
-int is_ignored(char *name)
-/* Is a file in the list of ignored files? */
-{
-	struct file *ip;
-	int r;
-
-	ip= ignore_list[ihash(name)];
-	while (ip != nil) {
-		if ((r = strcmp(name, ip->name)) <= 0) return (r == 0);
-		ip= ip->next;
-	}
-	return 0;
-}
-
-#define is_ignored(name) (n_ignored > 0 && (is_ignored)(name))
-
-time_t retired, dotretired;
-
-enum level { TOP, DOWN };
-
-void cleandir(enum level level, time_t retired)
-{
-	struct file *list;
-	struct stat st;
-	time_t ret;
-
-	if (debug >= 2) fprintf(stderr, "Cleaning %s\n", path);
-
-	list= listdir();
-
-	while (list != nil) {
-		int didx;
-
-		ret= (level == TOP && list->name[0] == '.') ?
-			dotretired : retired;
-			/* don't rm tmp/.* too soon. */
-
-		addpath(&didx, list->name);
-
-		if (is_ignored(path)) {
-			if (debug >= 1) fprintf(stderr, "ignoring %s\n", path);
-			do_ignore(0, path);
-		} else
-		if (is_ignored(list->name)) {
-			if (debug >= 1) fprintf(stderr, "ignoring %s\n", path);
-		} else
-		if (lstat(path, &st) < 0) {
-			report(path);
-		} else
-		if (S_ISDIR(st.st_mode)) {
-			cleandir(DOWN, ret);
-			if (force || st.st_mtime < ret) {
-				if (debug < 3 && rmdir(path) < 0) {
-					if (errno != ENOTEMPTY
-							&& errno != EEXIST) {
-						report(path);
-					}
-				} else {
-					if (debug >= 1) {
-						fprintf(stderr,
-							"rmdir %s\n", path);
-					}
-				}
-			}
-		} else {
-			if (force || (st.st_atime < ret
-					&& st.st_mtime < ret
-					&& st.st_ctime < ret)
-			) {
-				if (debug < 3 && unlink(path) < 0) {
-					if (errno != ENOENT) {
-						report(path);
-					}
-				} else {
-					if (debug >= 1) {
-						fprintf(stderr,
-							"rm %s\n", path);
-					}
-				}
-			}
-		}
-		delpath(didx);
-		list= shorten(list);
-	}
-}
-
-void usage(void)
-{
-	fprintf(stderr,
-	"Usage: cleantmp [-d[level]] [-i file ] ... -days|-f directory ...\n");
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	int i;
-	unsigned long days;
-
-	i= 1;
-	while (i < argc && argv[i][0] == '-') {
-		char *opt= argv[i++] + 1;
-
-		if (opt[0] == '-' && opt[1] == 0) break;
-
-		if (opt[0] == 'd') {
-			debug= 1;
-			if (opt[1] != 0) debug= atoi(opt + 1);
-		} else
-		if (opt[0] == 'i') {
-			if (*++opt == 0) {
-				if (i == argc) usage();
-				opt= argv[i++];
-			}
-			do_ignore(1, opt);
-		} else
-		if (opt[0] == 'f' && opt[1] == 0) {
-			force= 1;
-			days= 1;
-		} else {
-			char *end;
-			days= strtoul(opt, &end, 10);
-			if (*opt == 0 || *end != 0
-				|| days == 0
-				|| ((time_t) (days * SEC_DAY)) / SEC_DAY != days
-			) {
-				fprintf(stderr,
-				"cleantmp: %s is not a valid number of days\n",
-					opt);
-				exit(1);
-			}
-		}
-	}
-	if (days == 0) usage();
-
-	days2time(days, &retired, &dotretired);
-
-	while (i < argc) {
-		int didx;
-
-		if (argv[i][0] == 0) {
-			fprintf(stderr, "cleantmp: empty pathname!\n");
-			exit(1);
-		}
-		addpath(&didx, argv[i]);
-		cleandir(TOP, retired);
-		delpath(didx);
-		assert(path[0] == 0);
-		i++;
-	}
-	exit(0);
-}
Index: trunk/minix/commands/simple/cmp.c
===================================================================
--- trunk/minix/commands/simple/cmp.c	(revision 9)
+++ 	(revision )
@@ -1,129 +1,0 @@
-/* cmp - compare two files		Author: Kees J. Bot.  */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-_PROTOTYPE(void fatal, (char *label));
-_PROTOTYPE(int cmp, (int fd1, int fd2));
-_PROTOTYPE(void Usage, (void));
-_PROTOTYPE(int main, (int argc, char **argv));
-
-#define BLOCK	4096
-
-static int loud = 0, silent = 0;
-static char *name1, *name2;
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  int fd1, fd2;
-
-  /* Process the '-l' or '-s' option. */
-  while (argc > 1 && argv[1][0] == '-' && argv[1][1] != 0) {
-  	if (argv[1][2] != 0) Usage();
-
-  	switch (argv[1][1]) {
-  	case '-':
-  		/* '--': no-op option. */
-  		break;
-  	case 'l':
-		loud = 1;
-		break;
-	case 's':
-		silent = 1;
-		break;
-	default:
-		Usage();
-	}
-	argc--;
-	argv++;
-  }
-  if (argc != 3) Usage();
-
-  /* Open the first file, '-' means standard input. */
-  if (argv[1][0] == '-' && argv[1][1] == 0) {
-	name1 = "stdin";
-	fd1 = 0;
-  } else {
-	name1 = argv[1];
-	if ((fd1 = open(name1, 0)) < 0) fatal(name1);
-  }
-
-  /* Second file likewise. */
-  if (argv[2][0] == '-' && argv[2][1] == 0) {
-	name2 = "stdin";
-	fd2 = 0;
-  } else {
-	name2 = argv[2];
-	if ((fd2 = open(name2, 0)) < 0) fatal(name2);
-  }
-
-  exit(cmp(fd1, fd2));
-}
-
-int cmp(fd1, fd2)
-int fd1, fd2;
-{
-  static char buf1[BLOCK], buf2[BLOCK];
-  int n1 = 0, n2 = 0, i1 = 0, i2 = 0, c1, c2;
-  off_t pos = 0, line = 1;
-  int eof = 0, differ = 0;
-
-  for (;;) {
-	if (i1 == n1) {
-		pos += n1;
-
-		if ((n1 = read(fd1, buf1, sizeof(buf1))) <= 0) {
-			if (n1 < 0) fatal(name1);
-			eof |= 1;
-		}
-		i1 = 0;
-	}
-	if (i2 == n2) {
-		if ((n2 = read(fd2, buf2, sizeof(buf2))) <= 0) {
-			if (n2 < 0) fatal(name2);
-			eof |= 2;
-		}
-		i2 = 0;
-	}
-	if (eof != 0) break;
-
-	c1 = buf1[i1++];
-	c2 = buf2[i2++];
-
-	if (c1 != c2) {
-		if (!loud) {
-			if (!silent) {
-				printf("%s %s differ: char %ld, line %ld\n",
-				       name1, name2, pos + i1, line);
-			}
-			return(1);
-		}
-		printf("%10ld %3o %3o\n", pos + i1, c1 & 0xFF, c2 & 0xFF);
-		differ = 1;
-	}
-	if (c1 == '\n') line++;
-  }
-  if (eof == (1 | 2)) return(differ);
-  if (!silent) fprintf(stderr, "cmp: EOF on %s\n", eof == 1 ? name1 : name2);
-  return(1);
-}
-
-void fatal(label)
-char *label;
-{
-  if (!silent) fprintf(stderr, "cmp: %s: %s\n", label, strerror(errno));
-  exit(2);
-}
-
-void Usage()
-{
-  fprintf(stderr, "Usage: cmp [-l | -s] file1 file2\n");
-  exit(2);
-}
Index: trunk/minix/commands/simple/co.c
===================================================================
--- trunk/minix/commands/simple/co.c	(revision 9)
+++ 	(revision )
@@ -1,252 +1,0 @@
-/* co - check out			Author: Peter S. Housel 12/24/87 */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#define SUFFIX		",S"	/* svc indicator */
-#define SVCDIR		"SVC"	/* svc postfix indicator */
-
-#define LINELEN		256	/* maximum line length */
-
-#ifdef MAXPATHLEN
-#define PATHLEN MAXPATHLEN
-#else
-#define PATHLEN 128		/* buffer length for filenames */
-#endif
-
-char file[PATHLEN];		/* file to be checked in */
-char svc[PATHLEN];		/* filename for svc file */
-char newsvc[PATHLEN];		/* new copy of SVC file */
-char line[LINELEN];		/* temporary line buffer */
-char *p;			/* scratch character pointer */
-
-FILE *svcfp;			/* svc file */
-int rev;			/* old revision number */
-int lastrev, lockrev;		/* latest file revision, lock into */
-int status;			/* wait() buffer */
-int svclock;			/* lock the SVC file */
-struct stat stb;		/* stat() buffer */
-char *base;			/* basename of file */
-
-char difftemp[PATHLEN];		/* extract() fix/patch input */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void fname, (char *src, char *dst));
-_PROTOTYPE(void svcname, (char *src, char *dst));
-_PROTOTYPE(void extract, (char *script, char *out, int rev));
-_PROTOTYPE(char *basename, (char *name));
-_PROTOTYPE(char *whoami, (void));
-_PROTOTYPE(int getyn, (void));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-#ifdef perprintf
-  char errbuf[BUFSIZ];
-  setbuf(stderr, errbuf);
-  perprintf(stderr);
-#endif
-
-  while (++argv, --argc) {
-	if ('-' == (*argv)[0]) {
-		if ('r' == (*argv)[1]) {
-			--argc;
-			rev = atoi(*++argv);
-			if (rev < 1) {
-				fprintf(stderr, "Illegal revision number\n");
-				exit(1);
-			}
-		} else if ('l' == (*argv)[1])
-			++svclock;
-		else {
-			fprintf(stderr, "co: illegal option -%c\n", (*argv)[1]);
-			exit(1);
-		}
-	} else
-		break;
-  }
-
-  if (1 != argc) {
-	fprintf(stderr, "co: bad number of files arguments\n");
-	exit(1);
-  }
-  fname(*argv, file);
-  svcname(file, svc);
-
-  fprintf(stderr, "%s -> %s\n", svc, base = basename(file));
-
-  if (NULL == (svcfp = fopen(svc, "r"))) {
-	perror("co: can't read SVC file");
-	exit(1);
-  }
-  if (1 != fscanf(svcfp, "# %d", &lastrev) || lastrev < 1) {
-	fprintf(stderr, "co: illegal SVC file format\n");
-	exit(1);
-  }
-  fclose(svcfp);
-
-  if (stat(base, &stb) >= 0 && (stb.st_mode & 0222)) {
-	fprintf(stderr, "Writable %s exists - overwrite (n/y)? ", base);
-	if (!getyn()) {
-		fprintf(stderr, "Checkout aborted\n");
-		exit(1);
-	}
-  }
-  if (strlen(base)) unlink(base);
-  if (0 == rev) rev = lastrev;
-  fprintf(stderr, "Checking out revision %d", rev);
-  extract(svc, base, rev);
-
-  if (svclock) {
-	lockrev = lastrev + 1;
-	fprintf(stderr, "; Locking into revision %d\n", lockrev);
-	if (stat(svc, &stb) < 0 || chmod(svc, stb.st_mode | 0200) < 0)
-		perror("co: can't chmod SVC file");
-
-	if (stat(base, &stb) < 0 || chmod(base, stb.st_mode | 0200) < 0)
-		perror("co: can't chmod source file");
-
-	if (NULL == (svcfp = fopen(svc, "a"))
-	    || (fprintf(svcfp, "#***SVCLOCK*** %s %d\n", whoami(), lockrev), ferror(svcfp))) {
-		fprintf(stderr, "co: can't lock %s\n", svc);
-		exit(1);
-	}
-	if (stat(svc, &stb) < 0 || chmod(svc, stb.st_mode & 0555))
-		perror("co: can't chmod SVC file");
-  } else {
-	putchar('\n');
-	if (stat(base, &stb) < 0 || chmod(base, stb.st_mode & 0555))
-		perror("co: can't chmod source file");
-  }
-
-  return(0);
-}
-
-
-void fname(src, dst)
-char *src, *dst;
-{
-  char *p;
-  strcpy(dst, src);
-  p = &dst[strlen(src) - strlen(SUFFIX)];
-  if (!strcmp(p, SUFFIX)) *p = '\0';
-}
-
-void svcname(src, dst)
-char *src, *dst;
-{
-  char *p;
-
-  strcpy(dst, src);
-  strcat(dst, SUFFIX);
-
-  if (0 != access(dst, 4)) {
-	char dirname[PATHLEN];
-	if (NULL != (p = strrchr(src, '/')))
-		strncpy(dirname, src, (size_t)(p - src) + 1);
-	else
-		dirname[0] = '\0';
-	strcat(dirname, SVCDIR);
-
-	if (0 == access(dirname, 1)) {
-		strcpy(dst, dirname);
-		if (NULL == p) {
-			strcat(dst, "/");
-			strcat(dst, src);
-		} else
-			strcat(dst, p);
-		strcat(dst, SUFFIX);
-	}
-  }
-}
-
-void extract(script, out, rev)
-char *script, *out;
-int rev;
-{
-  FILE *outfp;
-  int testrev;
-  char buf[80];
-
-  sprintf(difftemp, "Fix.%s", out);
-
-  svcfp = fopen(script, "r");
-  fgets(line, LINELEN, svcfp);	/* skip '# rev' line */
-  fgets(line, LINELEN, svcfp);	/* skip 'cat <***MAIN-eof***' line */
-
-  if (NULL == (outfp = fopen(out, "w"))) {
-	perror("co: can't create output file");
-	return;
-  }
-  while (NULL != fgets(line, LINELEN, svcfp) &&
-	  strcmp(line, "***MAIN-eof***\n"))
-	fputs(line, outfp);
-
-  fclose(outfp);
-
-  while (NULL != fgets(line, LINELEN, svcfp)) {
-	if (!strncmp(line, "if ", (size_t)3)) {
-		sscanf(line, "if test $2 -ge %d", &testrev);
-		if (rev >= testrev) {
-			unlink(difftemp);
-			return;
-		}
-		if (NULL == (outfp = fopen(difftemp, "w"))) {
-			perror("co: can't create output file");
-			return;
-		}
-		sprintf(buf, "***%d-eof***\n", testrev);
-		while (NULL != fgets(line, LINELEN, svcfp) &&
-							strcmp(line, buf))
-			fputs(line, outfp);
-		fclose(outfp);
-	} else if (!strncmp(line, "mv ", (size_t)3)) {
-		sprintf(buf, "mv Fix.%s %s", out, out);
-		system(buf);
-	} else if (!strncmp(line, "fix ", (size_t)4)) {
-		sprintf(buf, "fix %s Fix.%s > New.%s; mv New.%s %s", out, out, out, out, out);
-		system(buf);
-	} else if (!strncmp(line, "patch ", (size_t)6)) {
-		sprintf(buf, "patch -n -s %s < Fix.%s; rm -f %s.orig", out, out, out);
-		system(buf);
-	} else {		/* ignore */
-	}
-  }
-
-  unlink(difftemp);
-  return;
-}
-
-char *basename(name)
-char *name;
-{
-  char *p;
-
-  if (NULL == (p = strrchr(name, '/')))
-	return name;
-  else
-	return p + 1;
-}
-
-char *whoami()
-{
-  struct passwd *pw;
-
-  if (NULL != (pw = getpwuid(getuid())))
-	return pw->pw_name;
-  else
-	return "nobody";
-}
-
-int getyn()
-{
-  char ans[10];
-
-  return(NULL != fgets(ans, 10, stdin)) && ('y' == ans[0] || 'Y' == ans[0]);
-}
Index: trunk/minix/commands/simple/comm.c
===================================================================
--- trunk/minix/commands/simple/comm.c	(revision 9)
+++ 	(revision )
@@ -1,206 +1,0 @@
-/* comm - select lines from two sorted files	Author: Martin C. Atkins */
-
-/*
- *	This program was written by:
- *		Martin C. Atkins,
- *		University of York,
- *		Heslington,
- *		York. Y01 5DD
- *		England
- *	and is released into the public domain, on the condition
- *	that this comment is always included without alteration.
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <minix/minlib.h>
-#include <stdio.h>
-
-#define BUFFER_SIZE (512)
-#define LINMAX (600)
-
-struct file {
-  char *name;			/* the file's name */
-  int fd;			/* the file descripter */
-  char buf[BUFFER_SIZE];		/* buffer storage */
-  char *next;			/* the next character to read */
-  char *endp;			/* the first invalid character */
-  int seeneof;			/* an end of file has been seen */
-} files[2];
-
-char lines[2][LINMAX];
-
-int colflgs[3] = {1, 2, 3};	/* number of tabs + 1: 0 => no column */
-
-static char *umsg = "Usage: comm [-[123]] file1 file2\n";
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void error, (char *s, char *f));
-_PROTOTYPE(void eopen, (char *fn, struct file *file));
-_PROTOTYPE(int getbuf, (struct file *file));
-_PROTOTYPE(int readline, (int fno));
-_PROTOTYPE(void comm, (void));
-_PROTOTYPE(void putcol, (int col, char *buf));
-_PROTOTYPE(void cpycol, (int col));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int cnt;
-  if (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {
-	char *ap;
-	for (ap = &argv[1][1]; *ap; ap++) switch (*ap) {
-		    case '1':
-		    case '2':
-		    case '3':
-			cnt = *ap - '1';
-			if (colflgs[cnt] == 0) break;
-			colflgs[cnt] = 0;
-			for (cnt++; cnt < 3; cnt++) colflgs[cnt]--;
-			break;
-		    default:	usage();
-		}
-	argc--;
-	argv++;
-  }
-  if (argc != 3) usage();
-  eopen(argv[1], &files[0]);
-  eopen(argv[2], &files[1]);
-  comm();
-  return(0);
-}
-
-void usage()
-{
-
-  std_err(umsg);
-  exit(1);
-}
-
-void error(s, f)
-char *s, *f;
-{
-  std_err("comm: ");
-  std_err(s);
-  if (f) std_err(f);
-  std_err("\n");
-  exit(1);
-}
-
-void eopen(fn, file)
-char *fn;
-struct file *file;
-{
-  file->name = fn;
-  file->next = file->endp = &file->buf[0];
-  file->seeneof = 0;
-  if (fn[0] == '-' && fn[1] == '\0')
-	file->fd = 0;
-  else if ((file->fd = open(fn, O_RDONLY)) < 0)
-	error("can't open ", fn);
-}
-
-
-int getbuf(file)
-struct file *file;
-{
-/* Get a buffer-full from the file.  Return true if no characters
- * were obtained because we are at end of file.
- */
-  int n;
-
-  if (file->seeneof) return(1);
-  if ((n = read(file->fd, &file->buf[0], BUFFER_SIZE)) < 0)
-	error("read error on ", file->name);
-  if (n == 0) {
-	file->seeneof++;
-	return 1;
-  }
-  file->next = &file->buf[0];
-  file->endp = &file->buf[n];
-  return(0);
-}
-
-
-int readline(fno)
-int fno;
-{
-/* Read up to the next '\n' character to buf.
- * Return a complete line, even if end of file occurs within a line.
- * Return false at end of file/
- */
-  register struct file *file = &files[fno];
-  char *buf = lines[fno];
-
-  if (file->next == file->endp && getbuf(file)) return(0);
-  while ((*buf++ = *file->next++) != '\n')
-	if (file->next == file->endp && getbuf(file)) {
-		*buf++ = '\n';
-		*buf = '\0';
-		return(1);
-	}
-  *buf = '\0';
-  return(1);
-}
-
-void comm()
-{
-  register int res;
-
-  if (!readline(0)) {
-	cpycol(1);
-	return;
-  }
-  if (!readline(1)) {
-	putcol(0, lines[0]);
-	cpycol(0);
-	return;
-  }
-  for (;;) {
-	if ((res = strcmp(lines[0], lines[1])) != 0) {
-		res = res > 0;
-		putcol(res, lines[res]);
-		if (!readline(res)) {
-			putcol(!res, lines[!res]);
-			cpycol(!res);
-			return;
-		}
-	} else {
-		putcol(2, lines[0]);	/* files[1]lin == f2lin */
-		if (!readline(0)) {
-			cpycol(1);
-			return;
-		}
-		if (!readline(1)) {
-			putcol(0, lines[0]);
-			cpycol(0);
-			return;
-		}
-	}
-  }
-
-  /* NOTREACHED */
-}
-
-void putcol(col, buf)
-int col;
-char *buf;
-{
-  int cnt;
-
-  if (colflgs[col] == 0) return;
-  for (cnt = 0; cnt < colflgs[col] - 1; cnt++) printf("\t");
-  printf("%s", buf);
-}
-
-void cpycol(col)
-int col;
-{
-  if (colflgs[col]) while (readline(col))
-		putcol(col, lines[col]);
-}
Index: trunk/minix/commands/simple/compress.c
===================================================================
--- trunk/minix/commands/simple/compress.c	(revision 9)
+++ 	(revision )
@@ -1,1617 +1,0 @@
-/* compress - Reduce file size using Modified Lempel-Ziv encoding */
-
-/*
- * compress.c - File compression ala IEEE Computer, June 1984.
- *
- * Authors:	Spencer W. Thomas	(decvax!harpo!utah-cs!utah-gr!thomas)
- *		Jim McKie		(decvax!mcvax!jim)
- *		Steve Davies		(decvax!vax135!petsd!peora!srd)
- *		Ken Turkowski		(decvax!decwrl!turtlevax!ken)
- *		James A. Woods		(decvax!ihnp4!ames!jaw)
- *		Joe Orost		(decvax!vax135!petsd!joe)
- *
- *		Richard Todd		Port to MINIX
- *		Andy Tanenbaum		Cleanup
- *
- *
- * Algorithm from "A Technique for High Performance Data Compression",
- * Terry A. Welch, IEEE Computer Vol 17, No 6 (June 1984), pp 8-19.
- *
- * Usage: compress [-dfvc] [-b bits] [file ...]
- * Inputs:
- *	-d:	    If given, decompression is done instead.
- *
- *      -c:         Write output on stdout.
- *
- *      -b:         Parameter limits the max number of bits/code.
- *
- *	-f:	    Forces output file to be generated, even if one already
- *		    exists, and even if no space is saved by compressing.
- *		    If -f is not used, the user will be prompted if stdin is
- *		    a tty, otherwise, the output file will not be overwritten.
- *
- *      -v:	    Write compression statistics
- *
- * 	file ...:   Files to be compressed.  If none specified, stdin
- *		    is used.
- * Outputs:
- *	file.Z:	    Compressed form of file with same mode, owner, and utimes
- * 	or stdout   (if stdin used as input)
- *
- * Assumptions:
- *	When filenames are given, replaces with the compressed version
- *	(.Z suffix) only if the file decreases in size.
- * Algorithm:
- * 	Modified Lempel-Ziv method (LZW).  Basically finds common
- * substrings and replaces them with a variable size code.  This is
- * deterministic, and can be done on the fly.  Thus, the decompression
- * procedure needs no input table, but tracks the way the table was built.
- */
-
-
-#define AZTEC86 1
-
-#define	min(a,b)	((a>b) ? b : a)
-
-/*
- * Set USERMEM to the maximum amount of physical user memory available
- * in bytes.  USERMEM is used to determine the maximum BITS that can be used
- * for compression.
- *
- * SACREDMEM is the amount of physical memory saved for others; compress
- * will hog the rest.
- */
-#ifndef SACREDMEM
-#define SACREDMEM	0
-#endif
-
-#ifndef USERMEM
-# define USERMEM 	450000	/* default user memory */
-#endif
-
-#define REGISTER register
-#define DOTZ ".Z"
-
-#include <limits.h>
-#include <dirent.h>
-
-/* The default for Minix is -b13, but we can do -b16 if the machine can. */
-#define DEFAULTBITS 13
-#if INT_MAX == 32767
-# define BITS 13
-#else
-# define BITS 16
-#endif
-
-#ifdef USERMEM
-# if USERMEM >= (433484+SACREDMEM)
-#  define PBITS	16
-# else
-#  if USERMEM >= (229600+SACREDMEM)
-#   define PBITS	15
-#  else
-#   if USERMEM >= (127536+SACREDMEM)
-#    define PBITS	14
-#   else
-#    if USERMEM >= (73464+SACREDMEM)
-#     define PBITS	13
-#    else
-#     define PBITS	12
-#    endif
-#   endif
-#  endif
-# endif
-# undef USERMEM
-#endif /* USERMEM */
-
-#ifdef PBITS		/* Preferred BITS for this memory size */
-# ifndef BITS
-#  define BITS PBITS
-# endif
-#endif /* PBITS */
-
-#if BITS == 16
-# define HSIZE	69001		/* 95% occupancy */
-#endif
-#if BITS == 15
-# define HSIZE	35023		/* 94% occupancy */
-#endif
-#if BITS == 14
-# define HSIZE	18013		/* 91% occupancy */
-#endif
-#if BITS == 13
-# define HSIZE	9001		/* 91% occupancy */
-#endif
-#if BITS <= 12
-# define HSIZE	5003		/* 80% occupancy */
-#endif
-
-
-/*
- * a code_int must be able to hold 2**BITS values of type int, and also -1
- */
-#if BITS > 15
-typedef long int	code_int;
-#else
-typedef int		code_int;
-#endif
-
-#ifdef SIGNED_COMPARE_SLOW
-typedef unsigned long int count_int;
-typedef unsigned short int count_short;
-#else
-typedef long int	  count_int;
-#endif
-
-#ifdef NO_UCHAR
- typedef char	char_type;
-#else
- typedef	unsigned char	char_type;
-#endif /* UCHAR */
-char_type magic_header[] = "\037\235";	/* 1F 9D */
-
-/* Defines for third byte of header */
-#define BIT_MASK	0x1f
-#define BLOCK_MASK	0x80
-/* Masks 0x40 and 0x20 are free.  I think 0x20 should mean that there is
-   a fourth header byte (for expansion).
-*/
-#define INIT_BITS 9			/* initial number of bits/code */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <utime.h>
-#include <stdio.h>
-
-#define ARGVAL() (*++(*argv) || (--argc && *++argv))
-
-int n_bits;				/* number of bits/code */
-int maxbits = DEFAULTBITS;		/* user settable max # bits/code */
-code_int maxcode;			/* maximum code, given n_bits */
-code_int maxmaxcode = 1 << BITS;	/* should NEVER generate this code */
-#ifdef COMPATIBLE		/* But wrong! */
-# define MAXCODE(n_bits)	(1 << (n_bits) - 1)
-#else
-# define MAXCODE(n_bits)	((1 << (n_bits)) - 1)
-#endif /* COMPATIBLE */
-
-#ifndef AZTEC86
-	count_int htab [HSIZE];
-	unsigned short codetab [HSIZE];
-#else
-	count_int *htab;
-	unsigned short *codetab;
-#	define HTABSIZE ((size_t)(HSIZE*sizeof(count_int)))
-#	define CODETABSIZE ((size_t)(HSIZE*sizeof(unsigned short)))
-
-
-#define htabof(i)	htab[i]
-#define codetabof(i)	codetab[i]
-#endif	/* XENIX_16 */
-code_int hsize = HSIZE;			/* for dynamic table sizing */
-count_int fsize;
-
-/*
- * To save much memory, we overlay the table used by compress() with those
- * used by decompress().  The tab_prefix table is the same size and type
- * as the codetab.  The tab_suffix table needs 2**BITS characters.  We
- * get this from the beginning of htab.  The output stack uses the rest
- * of htab, and contains characters.  There is plenty of room for any
- * possible stack (stack used to be 8000 characters).
- */
-
-#define tab_prefixof(i)	codetabof(i)
-#ifdef XENIX_16
-# define tab_suffixof(i)	((char_type *)htab[(i)>>15])[(i) & 0x7fff]
-# define de_stack		((char_type *)(htab2))
-#else	/* Normal machine */
-# define tab_suffixof(i)	((char_type *)(htab))[i]
-# define de_stack		((char_type *)&tab_suffixof(1<<BITS))
-#endif	/* XENIX_16 */
-
-code_int free_ent = 0;			/* first unused entry */
-int exit_stat = 0;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void Usage, (void));
-_PROTOTYPE(void compress, (void));
-_PROTOTYPE(void onintr, (int dummy));
-_PROTOTYPE(void oops, (int dummy));
-_PROTOTYPE(void output, (code_int code));
-_PROTOTYPE(int foreground, (void));
-_PROTOTYPE(void decompress, (void));
-_PROTOTYPE(code_int getcode, (void)); 
-_PROTOTYPE(void writeerr, (void));
-_PROTOTYPE(void copystat, (char *ifname, char *ofname));
-_PROTOTYPE(int foreground, (void));
-_PROTOTYPE(void cl_block , (void));
-_PROTOTYPE(void cl_hash, (count_int hsize));
-_PROTOTYPE(void prratio, (FILE *stream, long int num, long int den));
-_PROTOTYPE(void version, (void));
-
-void Usage() {
-#ifdef DEBUG
-fprintf(stderr,"Usage: compress [-dDVfc] [-b maxbits] [file ...]\n");
-}
-int debug = 0;
-#else
-fprintf(stderr,"Usage: compress [-dfvcV] [-b maxbits] [file ...]\n");
-}
-#endif /* DEBUG */
-int nomagic = 0;	/* Use a 3-byte magic number header, unless old file */
-int zcat_flg = 0;	/* Write output on stdout, suppress messages */
-int quiet = 0;		/* don't tell me about compression */
-
-/*
- * block compression parameters -- after all codes are used up,
- * and compression rate changes, start over.
- */
-int block_compress = BLOCK_MASK;
-int clear_flg = 0;
-long int ratio = 0;
-#define CHECK_GAP 10000	/* ratio check interval */
-count_int checkpoint = CHECK_GAP;
-/*
- * the next two codes should not be changed lightly, as they must not
- * lie within the contiguous general code space.
- */ 
-#define FIRST	257	/* first free entry */
-#define	CLEAR	256	/* table clear output code */
-
-int force = 0;
-char ofname [100];
-#ifdef DEBUG
-int verbose = 0;
-#endif /* DEBUG */
-
-#ifndef METAWARE
-#ifdef AZTEC86
-void
-#else
-int
-#endif
-#ifndef __STDC__
-(*bgnd_flag)();
-#else
-(*bgnd_flag)(int);
-#endif
-#endif
-
-int do_decomp = 0;
-
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-    int overwrite = 0;	/* Do not overwrite unless given -f flag */
-    char tempname[100];
-    char **filelist, **fileptr;
-    char *cp;
-    struct stat statbuf;
-#ifndef METAWARE
-    if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN ) {
-	signal ( SIGINT, onintr );
-	signal ( SIGSEGV, oops );
-    }
-#endif
-#ifdef AZTEC86
-#ifdef METAWARE
-	_setmode(NULL,_ALL_FILES_BINARY);
-	_setmode(stdin,_BINARY);
-	_setmode(stdout,_BINARY);
-	_setmode(stderr,_TEXT);
-#endif
-	if (NULL == (htab = (count_int *)malloc(HTABSIZE)))
-	{
-		fprintf(stderr,"Can't allocate htab\n");
-		exit(1);
-	}
-	if (NULL == (codetab = (unsigned short *)malloc(CODETABSIZE)))
-	{
-		fprintf(stderr,"Can't allocate codetab\n");
-		exit(1);
-	}
-#endif
-#ifdef COMPATIBLE
-    nomagic = 1;	/* Original didn't have a magic number */
-#endif /* COMPATIBLE */
-
-    filelist = fileptr = (char **)(malloc((size_t)(argc * sizeof(*argv))));
-    *filelist = NULL;
-
-    if((cp = strrchr(argv[0], '/')) != 0) {
-	cp++;
-    } else {
-	cp = argv[0];
-    }
-    if(strcmp(cp, "uncompress") == 0) {
-	do_decomp = 1;
-    } else if(strcmp(cp, "zcat") == 0) {
-	do_decomp = 1;
-	zcat_flg = 1;
-    }
-
-#ifdef BSD4_2
-    /* 4.2BSD dependent - take it out if not */
-    setlinebuf( stderr );
-#endif /* BSD4_2 */
-
-    /* Argument Processing
-     * All flags are optional.
-     * -D => debug
-     * -V => print Version; debug verbose
-     * -d => do_decomp
-     * -v => unquiet
-     * -f => force overwrite of output file
-     * -n => no header: useful to uncompress old files
-     * -b maxbits => maxbits.  If -b is specified, then maxbits MUST be
-     *	    given also.
-     * -c => cat all output to stdout
-     * -C => generate output compatible with compress 2.0.
-     * if a string is left, must be an input filename.
-     */
-    for (argc--, argv++; argc > 0; argc--, argv++) 
-	{
-		if (**argv == '-') 
-		{	/* A flag argument */
-		    while (*++(*argv)) 
-			{	/* Process all flags in this arg */
-				switch (**argv) 
-				{
-#ifdef DEBUG
-			    case 'D':
-					debug = 1;
-					break;
-			    case 'V':
-					verbose = 1;
-					version();
-					break;
-#else
-			    case 'V':
-					version();
-					break;
-#endif /* DEBUG */
-			    case 'v':
-					quiet = 0;
-					break;
-			    case 'd':
-					do_decomp = 1;
-					break;
-			    case 'f':
-			    case 'F':
-					overwrite = 1;
-					force = 1;
-					break;
-			    case 'n':
-					nomagic = 1;
-					break;
-			    case 'C':
-					block_compress = 0;
-					break;
-			    case 'b':
-					if (!ARGVAL()) 
-					{
-					    fprintf(stderr, "Missing maxbits\n");
-					    Usage();
-					    exit(1);
-					}
-					maxbits = atoi(*argv);
-					goto nextarg;
-			    case 'c':
-					zcat_flg = 1;
-					break;
-			    case 'q':
-					quiet = 1;
-					break;
-			    default:
-					fprintf(stderr, "Unknown flag: '%c'; ", **argv);
-					Usage();
-					exit(1);
-				}
-		    }
-		}
-		else 
-		{		/* Input file name */
-		    *fileptr++ = *argv;	/* Build input file list */
-		    *fileptr = NULL;
-		    /* process nextarg; */
-		}
-		nextarg: continue;
-    }
-
-    if(maxbits < INIT_BITS) maxbits = INIT_BITS;
-    if (maxbits > BITS) maxbits = BITS;
-    maxmaxcode = 1 << maxbits;
-
-    if (*filelist != NULL) 
-	{
-		for (fileptr = filelist; *fileptr; fileptr++) 
-		{
-		    exit_stat = 0;
-		    if (do_decomp != 0) 
-			{			/* DECOMPRESSION */
-				/* Check for .Z suffix */
-#ifndef PCDOS
-				if (strcmp(*fileptr + strlen(*fileptr) - 2, DOTZ) != 0) 
-#else
-				if (strcmp(*fileptr + strlen(*fileptr) - 1, DOTZ) != 0) 
-#endif
-				{
-				    /* No .Z: tack one on */
-				    strcpy(tempname, *fileptr);
-#ifndef PCDOS
-				    strcat(tempname, DOTZ);
-#else
-					/* either tack one on or replace last character */
-					{
-						char *dot;
-						if (NULL == (dot = strchr(tempname,'.')))
-						{
-							strcat(tempname,".Z");
-						}
-						else
-						/* if there is a dot then either tack a z on
-						   or replace last character */
-						{
-							if (strlen(dot) < 4)
-								strcat(tempname,DOTZ);
-							else
-								dot[3] = 'Z';
-						}
-					}
-#endif
-				    *fileptr = tempname;
-				}
-				/* Open input file */
-				if ((freopen(*fileptr, "r", stdin)) == NULL) 
-				{
-					perror(*fileptr); continue;
-				}
-				/* Check the magic number */
-				if (nomagic == 0) 
-				{
-					unsigned magic1, magic2;
-				    if (((magic1 = getc(stdin)) != (magic_header[0] & 0xFF))
-				     || ((magic2 = getc(stdin)) != (magic_header[1] & 0xFF))) 
-					{
-						fprintf(stderr, 
-						"%s: not in compressed format %x %x\n",
-					    *fileptr,magic1,magic2);
-					    continue;
-				    }
-				    maxbits = getc(stdin);	/* set -b from file */
-				    block_compress = maxbits & BLOCK_MASK;
-				    maxbits &= BIT_MASK;
-				    maxmaxcode = 1 << maxbits;
-				    if(maxbits > BITS) 
-					{
-						fprintf(stderr,
-					"%s: compressed with %d bits, can only handle %d bits\n",
-						*fileptr, maxbits, BITS);
-						continue;
-				    }
-				}
-				/* Generate output filename */
-				strcpy(ofname, *fileptr);
-#ifndef PCDOS
-				ofname[strlen(*fileptr) - 2] = '\0';  /* Strip off .Z */
-#else
-				/* kludge to handle various common three character extension */
-				{
-					char *dot; 
-					char fixup = '\0';
-					/* first off, map name to upper case */
-					for (dot = ofname; *dot; dot++)
-						*dot = toupper(*dot);
-					if (NULL == (dot = strchr(ofname,'.')))
-					{
-						fprintf(stderr,"Bad filename %s\n",ofname);
-						exit(1);
-					}
-					if (strlen(dot) == 4)
-					/* we got three letter extensions */
-					{
-						if (strcmp(dot,".EXZ") == 0)
-							fixup = 'E';
-						else if (strcmp(dot,".COZ") == 0)
-							fixup = 'M';
-						else if (strcmp(dot,".BAZ") == 0)
-							fixup = 'S';
-						else if (strcmp(dot,".OBZ") == 0)
-							fixup = 'J';
-						else if (strcmp(dot,".SYZ") == 0)
-							fixup = 'S';
-						else if (strcmp(dot,".DOZ") == 0)
-							fixup = 'C';
-
-					} 
-					/* replace the Z */
-					ofname[strlen(*fileptr) - 1] = fixup;
-				}
-#endif
-		    } else 
-			{					/* COMPRESSION */
-				if (strcmp(*fileptr + strlen(*fileptr) - 2, DOTZ) == 0) 
-				{
-			    	fprintf(stderr, "%s: already has .Z suffix -- no change\n",
-				    *fileptr);
-				    continue;
-				}
-				/* Open input file */
-				if ((freopen(*fileptr, "r", stdin)) == NULL) 
-				{
-				    perror(*fileptr); continue;
-				}
-				(void)stat( *fileptr, &statbuf );
-				fsize = (long) statbuf.st_size;
-				/*
-				 * tune hash table size for small files -- ad hoc,
-				 * but the sizes match earlier #defines, which
-				 * serve as upper bounds on the number of output codes. 
-				 */
-				hsize = HSIZE; /*lint -e506 -e712 */
-				if ( fsize < (1 << 12) )
-				    hsize = min ( 5003, HSIZE );
-				else if ( fsize < (1 << 13) )
-				    hsize = min ( 9001, HSIZE );
-				else if ( fsize < (1 << 14) )
-				    hsize = min ( 18013, HSIZE );
-				else if ( fsize < (1 << 15) )
-				    hsize = min ( 35023, HSIZE );
-				else if ( fsize < 47000 )
-				    hsize = min ( 50021, HSIZE ); /*lint +e506 +e712 */
-
-				/* Generate output filename */
-				strcpy(ofname, *fileptr);
-#ifndef BSD4_2		/* Short filenames */
-				if ((cp=strrchr(ofname,'/')) != NULL)
-					cp++;
-				else
-					cp = ofname;
-				if (strlen(cp) >= _DIRENT_NAME_LEN-3) 
-				{
-				    fprintf(stderr,"%s: filename too long to tack on .Z\n",cp);
-				    continue;
-				}
-#ifdef PCDOS
-				else
-				{
-					/* either tack one on or replace last character */
-					char *dot;
-					if (NULL == (dot = strchr(cp,'.')))
-					{
-						strcat(cp,".Z");
-					}
-					else
-					/* if there is a dot then either tack a z on
-					   or replace last character */
-					{
-						if (strlen(dot) < 4)
-							strcat(cp,DOTZ);
-						else
-							dot[3] = 'Z';
-					}
-				}
-#endif
-#endif  /* BSD4_2		Long filenames allowed */
-#ifndef PCDOS
-			/* PCDOS takes care of this above */
-				strcat(ofname, DOTZ);
-#endif
-		    }
-		    /* Check for overwrite of existing file */
-		    if (overwrite == 0 && zcat_flg == 0) 
-			{
-				if (stat(ofname, &statbuf) == 0) 
-				{
-				    char response[2]; int fd;
-				    response[0] = 'n';
-				    fprintf(stderr, "%s already exists;", ofname);
-				    if (foreground()) 
-					{
-						fd = open("/dev/tty", O_RDONLY);
-						fprintf(stderr, 
-						" do you wish to overwrite %s (y or n)? ", ofname);
-						fflush(stderr);
-						(void)read(fd, response, 2);
-						while (response[1] != '\n') 
-						{
-						    if (read(fd, response+1, 1) < 0) 
-							{	/* Ack! */
-								perror("stderr"); 
-								break;
-						    }
-						}
-						close(fd);
-				    }
-				    if (response[0] != 'y') 
-					{
-						fprintf(stderr, "\tnot overwritten\n");
-						continue;
-				    }
-				}
-		    }
-		    if(zcat_flg == 0) 
-			{		/* Open output file */
-				if (freopen(ofname, "w", stdout) == NULL) 
-				{
-				    perror(ofname);
-				    continue;
-				}
-				if(!quiet)
-					fprintf(stderr, "%s: ", *fileptr);
-		    }
-
-		    /* Actually do the compression/decompression */
-		    if (do_decomp == 0)	
-				compress();
-#ifndef DEBUG
-		    else			
-				decompress();
-#else
-		    else if (debug == 0)	
-				decompress();
-		    else			
-				printcodes();
-		    if (verbose)		
-				dump_tab();
-#endif /* DEBUG */
-		    if(zcat_flg == 0) 
-			{
-				copystat(*fileptr, ofname);	/* Copy stats */
-				if((exit_stat == 1) || (!quiet))
-					putc('\n', stderr);
-		    }
-		}
-    } else 
-	{		/* Standard input */
-		if (do_decomp == 0) 
-		{
-			compress();
-#ifdef DEBUG
-			if(verbose)		dump_tab();
-#endif /* DEBUG */
-			if(!quiet)
-				putc('\n', stderr);
-		} else 
-		{
-		    /* Check the magic number */
-		    if (nomagic == 0) 
-			{
-				if ((getc(stdin)!=(magic_header[0] & 0xFF))
-				 || (getc(stdin)!=(magic_header[1] & 0xFF))) 
-				{
-				    fprintf(stderr, "stdin: not in compressed format\n");
-				    exit(1);
-				}
-				maxbits = getc(stdin);	/* set -b from file */
-				block_compress = maxbits & BLOCK_MASK;
-				maxbits &= BIT_MASK;
-				maxmaxcode = 1 << maxbits;
-				fsize = 100000;		/* assume stdin large for USERMEM */
-				if(maxbits > BITS) 
-				{
-					fprintf(stderr,
-					"stdin: compressed with %d bits, can only handle %d bits\n",
-					maxbits, BITS);
-					exit(1);
-				}
-		    }
-#ifndef DEBUG
-		    decompress();
-#else
-		    if (debug == 0)	decompress();
-		    else		printcodes();
-		    if (verbose)	dump_tab();
-#endif /* DEBUG */
-		}
-    }
-    return(exit_stat);
-}
-
-static int offset;
-long int in_count = 1;			/* length of input */
-long int bytes_out;			/* length of compressed output */
-long int out_count = 0;			/* # of codes output (for debugging) */
-
-/*
- * compress stdin to stdout
- *
- * Algorithm:  use open addressing double hashing (no chaining) on the 
- * prefix code / next character combination.  We do a variant of Knuth's
- * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
- * secondary probe.  Here, the modular division first probe is gives way
- * to a faster exclusive-or manipulation.  Also do block compression with
- * an adaptive reset, whereby the code table is cleared when the compression
- * ratio decreases, but after the table fills.  The variable-length output
- * codes are re-sized at this point, and a special CLEAR code is generated
- * for the decompressor.  Late addition:  construct the table according to
- * file size for noticeable speed improvement on small files.  Please direct
- * questions about this implementation to ames!jaw.
- */
-
-void compress() 
-{
-    REGISTER long fcode;
-    REGISTER code_int i = 0;
-    REGISTER int c;
-    REGISTER code_int ent;
-#ifdef XENIX_16
-    REGISTER code_int disp;
-#else	/* Normal machine */
-    REGISTER int disp;
-#endif
-    REGISTER code_int hsize_reg;
-    REGISTER int hshift;
-
-#ifndef COMPATIBLE
-    if (nomagic == 0) 
-	{
-		putc(magic_header[0],stdout); 
-		putc(magic_header[1],stdout);
-		putc((char)(maxbits | block_compress),stdout);
-		if(ferror(stdout))
-			writeerr();
-    }
-#endif /* COMPATIBLE */
-
-    offset = 0;
-    bytes_out = 3;		/* includes 3-byte header mojo */
-    out_count = 0;
-    clear_flg = 0;
-    ratio = 0;
-    in_count = 1;
-    checkpoint = CHECK_GAP;
-    maxcode = MAXCODE(n_bits = INIT_BITS);
-    free_ent = ((block_compress) ? FIRST : 256 );
-
-    ent = getc(stdin);
-
-    hshift = 0;
-    for ( fcode = (long) hsize;  fcode < 65536L; fcode *= 2L )
-    	hshift++;
-    hshift = 8 - hshift;		/* set hash code range bound */
-
-    hsize_reg = hsize;
-    cl_hash( (count_int) hsize_reg);		/* clear hash table */
-
-#ifdef SIGNED_COMPARE_SLOW
-    while ( (c = getc(stdin)) != (unsigned) EOF )
-#else
-    while ( (c = getc(stdin)) != EOF )
-#endif
-	{
-		in_count++;
-		fcode = (long) (((long) c << maxbits) + ent);
-	 	i = ((c << hshift) ^ ent);	/* xor hashing */
-
-		if ( htabof (i) == fcode ) 
-		{
-		    ent = codetabof (i);
-		    continue;
-		} else if ( (long)htabof (i) < 0 )	/* empty slot */
-		    goto nomatch;
-	 	disp = hsize_reg - i;		/* secondary hash (after G. Knott) */
-		if ( i == 0 )
-		    disp = 1;
-probe:
-		if ( (i -= disp) < 0 )
-		    i += hsize_reg;
-
-		if ( htabof (i) == fcode ) 
-		{
-		    ent = codetabof (i);
-		    continue;
-		}
-		if ( (long)htabof (i) > 0 ) 
-		    goto probe;
-nomatch:
-		output ( (code_int) ent );
-		out_count++;
-	 	ent = c;
-#ifdef SIGNED_COMPARE_SLOW
-		if ( (unsigned) free_ent < (unsigned) maxmaxcode)
-#else
-		if ( free_ent < maxmaxcode )
-#endif
-		{
-	 	    codetabof (i) = free_ent++;	/* code -> hashtable */
-		    htabof (i) = fcode;
-		}
-		else if ( (count_int)in_count >= checkpoint && block_compress )
-		    cl_block ();
-    }
-    /*
-     * Put out the final code.
-     */
-    output( (code_int)ent );
-    out_count++;
-    output( (code_int)-1 );
-
-    /*
-     * Print out stats on stderr
-     */
-    if(zcat_flg == 0 && !quiet) 
-	{
-#ifdef DEBUG
-		fprintf( stderr,
-		"%ld chars in, %ld codes (%ld bytes) out, compression factor: ",
-		in_count, out_count, bytes_out );
-		prratio( stderr, in_count, bytes_out );
-		fprintf( stderr, "\n");
-		fprintf( stderr, "\tCompression as in compact: " );
-		prratio( stderr, in_count-bytes_out, in_count );
-		fprintf( stderr, "\n");
-		fprintf( stderr, "\tLargest code (of last block) was %d (%d bits)\n",
-		free_ent - 1, n_bits );
-#else /* !DEBUG */
-		fprintf( stderr, "Compression: " );
-		prratio( stderr, in_count-bytes_out, in_count );
-#endif /* DEBUG */
-    }
-    if(bytes_out > in_count)	/* exit(2) if no savings */
-		exit_stat = 2;
-    return;
-}
-
-/*****************************************************************
- * TAG( output )
- *
- * Output the given code.
- * Inputs:
- * 	code:	A n_bits-bit integer.  If == -1, then EOF.  This assumes
- *		that n_bits =< (long)wordsize - 1.
- * Outputs:
- * 	Outputs code to the file.
- * Assumptions:
- *	Chars are 8 bits long.
- * Algorithm:
- * 	Maintain a BITS character long buffer (so that 8 codes will
- * fit in it exactly).  Use the VAX insv instruction to insert each
- * code in turn.  When the buffer fills up empty it and start over.
- */
-
-static char buf[BITS];
-
-#ifndef vax
-char_type lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
-char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
-#endif /* vax */
-void output( code )
-code_int  code;
-{
-#ifdef DEBUG
-    static int col = 0;
-#endif /* DEBUG */
-
-    /*
-     * On the VAX, it is important to have the REGISTER declarations
-     * in exactly the order given, or the asm will break.
-     */
-    REGISTER int r_off = offset, bits= n_bits;
-    REGISTER char * bp = buf;
-#ifndef BREAKHIGHC
-#ifdef METAWARE
-	int temp;
-#endif
-#endif
-#ifdef DEBUG
-	if ( verbose )
-	    fprintf( stderr, "%5d%c", code,
-		    (col+=6) >= 74 ? (col = 0, '\n') : ' ' );
-#endif /* DEBUG */
-    if ( code >= 0 ) 
-	{
-#ifdef vax
-	/* VAX DEPENDENT!! Implementation on other machines is below.
-	 *
-	 * Translation: Insert BITS bits from the argument starting at
-	 * offset bits from the beginning of buf.
-	 */
-	0;	/* Work around for pcc -O bug with asm and if stmt */
-	asm( "insv	4(ap),r11,r10,(r9)" );
-#else /* not a vax */
-/* 
- * byte/bit numbering on the VAX is simulated by the following code
- */
-	/*
-	 * Get to the first byte.
-	 */
-	bp += (r_off >> 3);
-	r_off &= 7;
-	/*
-	 * Since code is always >= 8 bits, only need to mask the first
-	 * hunk on the left.
-	 */
-#ifndef BREAKHIGHC
-#ifdef METAWARE
-	*bp &= rmask[r_off];
-	temp = (code << r_off) & lmask[r_off];
-	*bp |= temp;
-#else
-	*bp = (*bp & rmask[r_off]) | ((code << r_off) & lmask[r_off]);
-#endif
-#else
-	*bp = (*bp & rmask[r_off]) | ((code << r_off) & lmask[r_off]);
-#endif
-	bp++;
-	bits -= (8 - r_off);
-	code >>= (8 - r_off);
-	/* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
-	if ( bits >= 8 ) 
-	{
-	    *bp++ = code;
-	    code >>= 8;
-	    bits -= 8;
-	}
-	/* Last bits. */
-	if(bits)
-	    *bp = code;
-#endif /* vax */
-	offset += n_bits;
-	if ( offset == (n_bits << 3) ) 
-	{
-	    bp = buf;
-	    bits = n_bits;
-	    bytes_out += bits;
-	    do
-		putc(*bp++,stdout);
-	    while(--bits);
-	    offset = 0;
-	}
-
-	/*
-	 * If the next entry is going to be too big for the code size,
-	 * then increase it, if possible.
-	 */
-	if ( free_ent > maxcode || (clear_flg > 0))
-	{
-	    /*
-	     * Write the whole buffer, because the input side won't
-	     * discover the size increase until after it has read it.
-	     */
-	    if ( offset > 0 ) 
-		{
-			if( fwrite( buf, (size_t)1, (size_t)n_bits, stdout ) != n_bits)
-				writeerr();
-			bytes_out += n_bits;
-	    }
-	    offset = 0;
-
-	    if ( clear_flg ) 
-		{
-    	        maxcode = MAXCODE (n_bits = INIT_BITS);
-		        clear_flg = 0;
-	    }
-	    else 
-		{
-	    	n_bits++;
-	    	if ( n_bits == maxbits )
-			    maxcode = maxmaxcode;
-	    	else
-			    maxcode = MAXCODE(n_bits);
-	    }
-#ifdef DEBUG
-	    if ( debug ) 
-		{
-			fprintf( stderr, "\nChange to %d bits\n", n_bits );
-			col = 0;
-	    }
-#endif /* DEBUG */
-	}
-    } else 
-	{
-	/*
-	 * At EOF, write the rest of the buffer.
-	 */
-	if ( offset > 0 )
-	    fwrite( buf, (size_t)1, (size_t)(offset + 7) / 8, stdout );
-	bytes_out += (offset + 7) / 8;
-	offset = 0;
-	fflush( stdout );
-#ifdef DEBUG
-	if ( verbose )
-	    fprintf( stderr, "\n" );
-#endif /* DEBUG */
-	if( ferror( stdout ) )
-		writeerr();
-    }
-}
-/*
- * Decompress stdin to stdout.  This routine adapts to the codes in the
- * file building the "string" table on-the-fly; requiring no table to
- * be stored in the compressed file.  The tables used herein are shared
- * with those of the compress() routine.  See the definitions above.
- */
-
-void decompress() {
-    REGISTER char_type *stackp;
-    REGISTER int finchar;
-    REGISTER code_int code, oldcode, incode;
-
-    /*
-     * As above, initialize the first 256 entries in the table.
-     */
-    maxcode = MAXCODE(n_bits = INIT_BITS);
-    for ( code = 255; code >= 0; code-- ) {
-	tab_prefixof(code) = 0;
-	tab_suffixof(code) = (char_type)code;
-    }
-    free_ent = ((block_compress) ? FIRST : 256 );
-
-    finchar = oldcode = getcode();
-    if(oldcode == -1)	/* EOF already? */
-	return;			/* Get out of here */
-    putc( (char)finchar,stdout );		/* first code must be 8 bits = char */
-    if(ferror(stdout))		/* Crash if can't write */
-	writeerr();
-    stackp = de_stack;
-
-    while ( (code = getcode()) > -1 ) {
-
-	if ( (code == CLEAR) && block_compress ) {
-	    for ( code = 255; code >= 0; code-- )
-		tab_prefixof(code) = 0;
-	    clear_flg = 1;
-	    free_ent = FIRST - 1;
-	    if ( (code = getcode ()) == -1 )	/* O, untimely death! */
-		break;
-	}
-	incode = code;
-	/*
-	 * Special case for KwKwK string.
-	 */
-	if ( code >= free_ent ) {
-            *stackp++ = finchar;
-	    code = oldcode;
-	}
-
-	/*
-	 * Generate output characters in reverse order
-	 */
-#ifdef SIGNED_COMPARE_SLOW
-	while ( ((unsigned long)code) >= ((unsigned long)256) ) {
-#else
-	while ( code >= 256 ) {
-#endif
-	    *stackp++ = tab_suffixof(code);
-	    code = tab_prefixof(code);
-	}
-	*stackp++ = finchar = tab_suffixof(code);
-
-	/*
-	 * And put them out in forward order
-	 */
-	do
-	    putc ( *--stackp ,stdout);
-	while ( stackp > de_stack );
-
-	/*
-	 * Generate the new entry.
-	 */
-	if ( (code=free_ent) < maxmaxcode ) 
-	{
-	    tab_prefixof(code) = (unsigned short)oldcode;
-	    tab_suffixof(code) = finchar;
-	    free_ent = code+1;
-	} 
-	/*
-	 * Remember previous code.
-	 */
-	oldcode = incode;
-    }
-    fflush( stdout );
-    if(ferror(stdout))
-	writeerr();
-}
-
-/*****************************************************************
- * TAG( getcode )
- *
- * Read one code from the standard input.  If EOF, return -1.
- * Inputs:
- * 	stdin
- * Outputs:
- * 	code or -1 is returned.
- */
-
-code_int
-getcode() 
-{
-    /*
-     * On the VAX, it is important to have the REGISTER declarations
-     * in exactly the order given, or the asm will break.
-     */
-    REGISTER code_int code;
-    static int offset = 0, size = 0;
-    static char_type buf[BITS];
-    REGISTER int r_off, bits;
-    REGISTER char_type *bp = buf;
-
-    if ( clear_flg > 0 || offset >= size || free_ent > maxcode ) 
-	{
-		/*
-		 * If the next entry will be too big for the current code
-		 * size, then we must increase the size.  This implies reading
-		 * a new buffer full, too.
-		 */
-		if ( free_ent > maxcode ) 
-		{
-		    n_bits++;
-		    if ( n_bits == maxbits )
-				maxcode = maxmaxcode;	/* won't get any bigger now */
-		    else
-				maxcode = MAXCODE(n_bits);
-		}
-		if ( clear_flg > 0) 
-		{
-    	    maxcode = MAXCODE (n_bits = INIT_BITS);
-		    clear_flg = 0;
-		}
-		size = fread( buf, (size_t)1, (size_t)n_bits, stdin );
-		if ( size <= 0 )
-		    return -1;			/* end of file */
-		offset = 0;
-		/* Round size down to integral number of codes */
-		size = (size << 3) - (n_bits - 1);
-    }
-    r_off = offset;
-    bits = n_bits;
-#ifdef vax
-    asm( "extzv   r10,r9,(r8),r11" );
-#else /* not a vax */
-	/*
-	 * Get to the first byte.
-	 */
-	bp += (r_off >> 3);
-	r_off &= 7;
-	/* Get first part (low order bits) */
-#ifdef NO_UCHAR
-	code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff;
-#else
-	code = (*bp++ >> r_off);
-#endif /* NO_UCHAR */
-	bits -= (8 - r_off);
-	r_off = 8 - r_off;		/* now, offset into code word */
-	/* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
-	if ( bits >= 8 ) 
-	{
-#ifdef NO_UCHAR
-	    code |= (*bp++ & 0xff) << r_off;
-#else
-	    code |= *bp++ << r_off;
-#endif /* NO_UCHAR */
-	    r_off += 8;
-	    bits -= 8;
-	}
-	/* high order bits. */
-	code |= (*bp & rmask[bits]) << r_off;
-#endif /* vax */
-    offset += n_bits;
-
-    return code;
-}
-
-#ifndef AZTEC86
-char *
-strrchr(s, c)		/* For those who don't have it in libc.a */
-REGISTER char *s, c;
-{
-	char *p;
-	for (p = NULL; *s; s++)
-	    if (*s == c)
-		p = s;
-	return(p);
-}
-#endif
-
-
-#ifndef METAWARE
-#ifdef DEBUG
-printcodes()
-{
-    /*
-     * Just print out codes from input file.  For debugging.
-     */
-    code_int code;
-    int col = 0, bits;
-
-    bits = n_bits = INIT_BITS;
-    maxcode = MAXCODE(n_bits);
-    free_ent = ((block_compress) ? FIRST : 256 );
-    while ( ( code = getcode() ) >= 0 ) {
-	if ( (code == CLEAR) && block_compress ) {
-   	    free_ent = FIRST - 1;
-   	    clear_flg = 1;
-	}
-	else if ( free_ent < maxmaxcode )
-	    free_ent++;
-	if ( bits != n_bits ) {
-	    fprintf(stderr, "\nChange to %d bits\n", n_bits );
-	    bits = n_bits;
-	    col = 0;
-	}
-	fprintf(stderr, "%5d%c", code, (col+=6) >= 74 ? (col = 0, '\n') : ' ' );
-    }
-    putc( '\n', stderr );
-    exit( 0 );
-}
-#ifdef DEBUG2
-code_int sorttab[1<<BITS];	/* sorted pointers into htab */
-#define STACK_SIZE	500
-static char stack[STACK_SIZE];
-/* dumptab doesn't use main stack now -prevents distressing crashes */
-dump_tab()	/* dump string table */
-{
-    REGISTER int i, first;
-    REGISTER ent;
-    int stack_top = STACK_SIZE;
-    REGISTER c;
-
-    if(do_decomp == 0) {	/* compressing */
-	REGISTER int flag = 1;
-
-	for(i=0; i<hsize; i++) {	/* build sort pointers */
-		if((long)htabof(i) >= 0) {
-			sorttab[codetabof(i)] = i;
-		}
-	}
-	first = block_compress ? FIRST : 256;
-	for(i = first; i < free_ent; i++) {
-		fprintf(stderr, "%5d: \"", i);
-		stack[--stack_top] = '\n';
-		stack[--stack_top] = '"'; /* " */
-		stack_top = in_stack((int)(htabof(sorttab[i])>>maxbits)&0xff, 
-                                     stack_top);
-		for(ent=htabof(sorttab[i]) & ((1<<maxbits)-1);
-		    ent > 256;
-		    ent=htabof(sorttab[ent]) & ((1<<maxbits)-1)) {
-			stack_top = in_stack((int)(htabof(sorttab[ent]) >> maxbits),
-						stack_top);
-		}
-		stack_top = in_stack(ent, stack_top);
-		fwrite( &stack[stack_top], (size_t)1, (size_t)(STACK_SIZE-stack_top), stderr);
-	   	stack_top = STACK_SIZE;
-	}
-   } else if(!debug) {	/* decompressing */
-
-       for ( i = 0; i < free_ent; i++ ) {
-	   ent = i;
-	   c = tab_suffixof(ent);
-	   if ( isascii(c) && isprint(c) )
-	       fprintf( stderr, "%5d: %5d/'%c'  \"",
-			   ent, tab_prefixof(ent), c );
-	   else
-	       fprintf( stderr, "%5d: %5d/\\%03o \"",
-			   ent, tab_prefixof(ent), c );
-	   stack[--stack_top] = '\n';
-	   stack[--stack_top] = '"'; /* " */
-	   for ( ; ent != NULL;
-		   ent = (ent >= FIRST ? tab_prefixof(ent) : NULL) ) {
-	       stack_top = in_stack(tab_suffixof(ent), stack_top);
-	   }
-	   fwrite( &stack[stack_top], (size_t)1, (size_t)(STACK_SIZE - stack_top), stderr );
-	   stack_top = STACK_SIZE;
-       }
-    }
-}
-
-int
-in_stack(c, stack_top)
-	REGISTER int c, stack_top;
-{
-	if ( (isascii(c) && isprint(c) && c != '\\') || c == ' ' ) {
-	    stack[--stack_top] = c;
-	} else {
-	    switch( c ) {
-	    case '\n': stack[--stack_top] = 'n'; break;
-	    case '\t': stack[--stack_top] = 't'; break;
-	    case '\b': stack[--stack_top] = 'b'; break;
-	    case '\f': stack[--stack_top] = 'f'; break;
-	    case '\r': stack[--stack_top] = 'r'; break;
-	    case '\\': stack[--stack_top] = '\\'; break;
-	    default:
-	 	stack[--stack_top] = '0' + c % 8;
-	 	stack[--stack_top] = '0' + (c / 8) % 8;
-	 	stack[--stack_top] = '0' + c / 64;
-	 	break;
-	    }
-	    stack[--stack_top] = '\\';
-	}
-	if (stack_top<0) {
-	    fprintf(stderr,"dump_tab stack overflow!!!\n");
-	    exit(1);
-	}
-	return stack_top;
-}
-#else
-dump_tab() {}
-#endif /* DEBUG2 */
-#endif /* DEBUG */
-#endif /* METAWARE */
-
-void writeerr()
-{
-    perror ( ofname );
-    unlink ( ofname );
-    exit ( 1 );
-}
-
-void copystat(ifname, ofname)
-char *ifname, *ofname;
-{
-    struct stat statbuf;
-    int mode;
-#ifndef AZTEC86
-    time_t timep[2];
-#else
-	unsigned long timep[2];
-#endif
-    fflush(stdout);
-    close(fileno(stdout));
-    if (stat(ifname, &statbuf)) 
-	{		/* Get stat on input file */
-		perror(ifname);
-		return;
-    }
-#ifndef PCDOS
-    /* meddling with UNIX-style file modes */
-    if ((statbuf.st_mode & S_IFMT/*0170000*/) != S_IFREG/*0100000*/) 
-	{
-		if(quiet)
-	    	fprintf(stderr, "%s: ", ifname);
-		fprintf(stderr, " -- not a regular file: unchanged");
-		exit_stat = 1;
-    } else if (statbuf.st_nlink > 1) 
-	{
-		if(quiet)
-	    	fprintf(stderr, "%s: ", ifname);
-		fprintf(stderr, " -- has %d other links: unchanged",
-		statbuf.st_nlink - 1);
-		exit_stat = 1;
-    } else 
-#endif
-	if (exit_stat == 2 && (!force)) 
-	{ /* No compression: remove file.Z */
-		if(!quiet)
-			fprintf(stderr, " -- file unchanged");
-    } else 
-	{			/* ***** Successful Compression ***** */
-		exit_stat = 0;
-#ifndef PCDOS
-		mode = statbuf.st_mode & 07777;
-#else
-		mode = statbuf.st_attr & 07777;
-#endif
-		if (chmod(ofname, mode))		/* Copy modes */
-		    perror(ofname);
-#ifndef PCDOS
-		chown(ofname, statbuf.st_uid, statbuf.st_gid);	/* Copy ownership */
-		timep[0] = statbuf.st_atime;
-		timep[1] = statbuf.st_mtime;
-#else
-		timep[0] = statbuf.st_mtime;
-		timep[1] = statbuf.st_mtime;
-#endif
-		utime(ofname, (struct utimbuf *)timep);	/* Update last accessed and modified times */
-/*
-		if (unlink(ifname))
-		    perror(ifname);
-*/
-		if(!quiet)
-		    if(do_decomp == 0)
-			fprintf(stderr, " -- compressed to %s", ofname);
-		    else
-			fprintf(stderr, " -- decompressed to %s", ofname);
-		return;		/* Successful return */
-    }
-
-    /* Unsuccessful return -- one of the tests failed */
-    if (unlink(ofname))
-		perror(ofname);
-}
-/*
- * This routine returns 1 if we are running in the foreground and stderr
- * is a tty.
- */
-int foreground()
-{
-#ifndef METAWARE
-	if(bgnd_flag) {	/* background? */
-		return(0);
-	} else {			/* foreground */
-#endif
-		if(isatty(2)) {		/* and stderr is a tty */
-			return(1);
-		} else {
-			return(0);
-		}
-#ifndef METAWARE
-	}
-#endif
-}
-#ifndef METAWARE
-void onintr (dummy)
-int dummy; /* to keep the compiler happy */
-{
-	(void)signal(SIGINT,SIG_IGN);
-    unlink ( ofname );
-    exit ( 1 );
-}
-
-void oops (dummy)	/* wild pointer -- assume bad input */
-int dummy; /* to keep the compiler happy */
-{
-	(void)signal(SIGSEGV,SIG_IGN);
-    if ( do_decomp == 1 ) 
-    	fprintf ( stderr, "uncompress: corrupt input\n" );
-    unlink ( ofname );
-    exit ( 1 );
-}
-#endif
-void cl_block ()		/* table clear for block compress */
-{
-    REGISTER long int rat;
-
-    checkpoint = in_count + CHECK_GAP;
-#ifdef DEBUG
-	if ( debug ) {
-    		fprintf ( stderr, "count: %ld, ratio: ", in_count );
-     		prratio ( stderr, in_count, bytes_out );
-		fprintf ( stderr, "\n");
-	}
-#endif /* DEBUG */
-
-    if(in_count > 0x007fffff) {	/* shift will overflow */
-	rat = bytes_out >> 8;
-	if(rat == 0) {		/* Don't divide by zero */
-	    rat = 0x7fffffff;
-	} else {
-	    rat = in_count / rat;
-	}
-    } else {
-	rat = (in_count << 8) / bytes_out;	/* 8 fractional bits */
-    }
-    if ( rat > ratio ) {
-	ratio = rat;
-    } else {
-	ratio = 0;
-#ifdef DEBUG
-	if(verbose)
-		dump_tab();	/* dump string table */
-#endif
- 	cl_hash ( (count_int) hsize );
-	free_ent = FIRST;
-	clear_flg = 1;
-	output ( (code_int) CLEAR );
-#ifdef DEBUG
-	if(debug)
-    		fprintf ( stderr, "clear\n" );
-#endif /* DEBUG */
-    }
-}
-
-void cl_hash(hsize)		/* reset code table */
-	REGISTER count_int hsize;
-{
-#ifdef AZTEC86
-#ifdef PCDOS
-	/* This function only in PC-DOS lib, not in MINIX lib */
-	memset(htab,-1, hsize * sizeof(count_int));
-#else
-/* MINIX and all non-PC machines do it this way */	
-#ifndef XENIX_16	/* Normal machine */
-	REGISTER count_int *htab_p = htab+hsize;
-#else
-	REGISTER j;
-	REGISTER long k = hsize;
-	REGISTER count_int *htab_p;
-#endif
-	REGISTER long i;
-	REGISTER long m1 = -1;
-
-#ifdef XENIX_16
-    for(j=0; j<=8 && k>=0; j++,k-=8192) 
-	{
-		i = 8192;
-		if(k < 8192) 
-		{
-			i = k;
-		}
-		htab_p = &(htab[j][i]);
-		i -= 16;
-		if(i > 0) 
-		{
-#else
-	i = hsize - 16;
-#endif
-	 	do 
-		{				/* might use Sys V memset(3) here */
-			*(htab_p-16) = m1;
-			*(htab_p-15) = m1;
-			*(htab_p-14) = m1;
-			*(htab_p-13) = m1;
-			*(htab_p-12) = m1;
-			*(htab_p-11) = m1;
-			*(htab_p-10) = m1;
-			*(htab_p-9) = m1;
-			*(htab_p-8) = m1;
-			*(htab_p-7) = m1;
-			*(htab_p-6) = m1;
-			*(htab_p-5) = m1;
-			*(htab_p-4) = m1;
-			*(htab_p-3) = m1;
-			*(htab_p-2) = m1;
-			*(htab_p-1) = m1;
-			htab_p -= 16;
-		} while ((i -= 16) >= 0);
-#ifdef XENIX_16
-		}
-    }
-#endif
-	for ( i += 16; i > 0; i-- )
-		*--htab_p = m1;
-#endif
-#endif
-}
-
-void prratio(stream, num, den)
-FILE *stream;
-long int num;
-long int den;
-{
-	REGISTER int q;			/* Doesn't need to be long */
-	if(num > 214748L) 
-	{		/* 2147483647/10000 */
-		q = (int)(num / (den / 10000L));
-	} else 
-	{
-		q = (int)(10000L * num / den);		/* Long calculations, though */
-	}
-	if (q < 0) 
-	{
-		putc('-', stream);
-		q = -q;
-	}
-	fprintf(stream, "%d.%02d%c", q / 100, q % 100, '%');
-}
-
-void version()
-{
-	fprintf(stderr, "compress 4.1\n");
-	fprintf(stderr, "Options: ");
-#ifdef vax
-	fprintf(stderr, "vax, ");
-#endif
-#ifdef _MINIX
-	fprintf(stderr, "MINIX, ");
-#endif
-#ifdef NO_UCHAR
-	fprintf(stderr, "NO_UCHAR, ");
-#endif
-#ifdef SIGNED_COMPARE_SLOW
-	fprintf(stderr, "SIGNED_COMPARE_SLOW, ");
-#endif
-#ifdef XENIX_16
-	fprintf(stderr, "XENIX_16, ");
-#endif
-#ifdef COMPATIBLE
-	fprintf(stderr, "COMPATIBLE, ");
-#endif
-#ifdef DEBUG
-	fprintf(stderr, "DEBUG, ");
-#endif
-#ifdef BSD4_2
-	fprintf(stderr, "BSD4_2, ");
-#endif
-	fprintf(stderr, "BITS = %d\n", BITS);
-}
-/* End of text from uok.UUCP:net.sources */
-
Index: trunk/minix/commands/simple/cp.c
===================================================================
--- trunk/minix/commands/simple/cp.c	(revision 9)
+++ 	(revision )
@@ -1,1380 +1,0 @@
-/*	cp 1.12 - copy files				Author: Kees J. Bot
- *	mv      - move files					20 Jul 1993
- *	rm      - remove files
- *	ln      - make a link
- *	cpdir   - copy a directory tree (cp -psmr)
- *	clone   - make a link farm (ln -fmr)
- */
-#define nil 0
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stddef.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <time.h>
-#include <sys/stat.h>
-#include <utime.h>
-#include <dirent.h>
-#include <errno.h>
-#ifndef DEBUG
-#define DEBUG	0
-#define NDEBUG	1
-#endif
-#include <assert.h>
-
-#include <sys/dir.h>
-
-/* Copy files in this size chunks: */
-#if __minix && !__minix_vmd
-#define CHUNK	(8192 * sizeof(char *))
-#else
-#define CHUNK	(1024 << (sizeof(int) + sizeof(char *)))
-#endif
-
-
-#ifndef CONFORMING
-#define CONFORMING	1	/* Precisely POSIX conforming. */
-#endif
-
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-char *prog_name;		/* Call name of this program. */
-int ex_code= 0;			/* Final exit code. */
-
-typedef enum identity { CP, MV, RM, LN, CPDIR, CLONE } identity_t;
-typedef enum action { COPY, MOVE, REMOVE, LINK } action_t;
-
-identity_t identity;		/* How did the user call me? */
-action_t action;		/* Copying, moving, or linking. */
-int pflag= 0;			/* -p/-s: Make orginal and copy the same. */
-int iflag= 0;			/* -i: Interactive overwriting/deleting. */
-int fflag= 0;			/* -f: Force. */
-int sflag= 0;			/* -s: Make a symbolic link (ln/clone). */
-int Sflag= 0;			/* -S: Make a symlink if across devices. */
-int mflag= 0;			/* -m: Merge trees, no target dir trickery. */
-int rflag= 0;			/* -r/-R: Recursively copy a tree. */
-int vflag= 0;			/* -v: Verbose. */
-int xflag= 0;			/* -x: Don't traverse past mount points. */
-int xdev= 0;			/* Set when moving or linking cross-device. */
-int expand= 0;			/* Expand symlinks, ignore links. */
-int conforming= CONFORMING;	/* Sometimes standards are a pain. */
-
-int fc_mask;			/* File creation mask. */
-int uid, gid;			/* Effective uid & gid. */
-int istty;			/* Can have terminal input. */
-
-#ifndef S_ISLNK
-/* There were no symlinks in medieval times. */
-#define S_ISLNK(mode)			(0)
-#define lstat				stat
-#define symlink(path1, path2)		(errno= ENOSYS, -1)
-#define readlink(path, buf, len)	(errno= ENOSYS, -1)
-#endif
-
-void report(const char *label)
-{
-    if (action == REMOVE && fflag) return;
-    fprintf(stderr, "%s: %s: %s\n", prog_name, label, strerror(errno));
-    ex_code= 1;
-}
-
-void fatal(const char *label)
-{
-    report(label);
-    exit(1);
-}
-
-void report2(const char *src, const char *dst)
-{
-    fprintf(stderr, "%s %s %s: %s\n", prog_name, src, dst, strerror(errno));
-    ex_code= 1;
-}
-
-#if DEBUG
-size_t nchunks= 0;	/* Number of allocated cells. */
-#endif
-
-void *allocate(void *mem, size_t size)
-/* Like realloc, but with checking of the return value. */
-{
-#if DEBUG
-    if (mem == nil) nchunks++;
-#endif
-    if ((mem= mem == nil ? malloc(size) : realloc(mem, size)) == nil)
-	fatal("malloc()");
-    return mem;
-}
-
-void deallocate(void *mem)
-/* Release a chunk of memory. */
-{
-    if (mem != nil) {
-#if DEBUG
-	nchunks--;
-#endif
-	free(mem);
-    }
-}
-
-typedef struct pathname {
-    char		*path;	/* The actual pathname. */
-    size_t		idx;	/* Index for the terminating null byte. */
-    size_t		lim;	/* Actual length of the path array. */
-} pathname_t;
-
-void path_init(pathname_t *pp)
-/* Initialize a pathname to the null string. */
-{
-    pp->path= allocate(nil, pp->lim= DIRSIZ + 2);
-    pp->path[pp->idx= 0]= 0;
-}
-
-void path_add(pathname_t *pp, const char *name)
-/* Add a component to a pathname. */
-{
-    size_t lim;
-    char *p;
-
-    lim= pp->idx + strlen(name) + 2;
-
-    if (lim > pp->lim) {
-	pp->lim= lim += lim/2;	/* add an extra 50% growing space. */
-
-	pp->path= allocate(pp->path, lim);
-    }
-
-    p= pp->path + pp->idx;
-    if (p > pp->path && p[-1] != '/') *p++ = '/';
-
-    while (*name != 0) {
-	if (*name != '/' || p == pp->path || p[-1] != '/') *p++ = *name;
-	name++;
-    }
-    *p = 0;
-    pp->idx= p - pp->path;
-}
-
-void path_trunc(pathname_t *pp, size_t didx)
-/* Delete part of a pathname to a remembered length. */
-{
-    pp->path[pp->idx= didx]= 0;
-}
-
-#if DEBUG
-const char *path_name(const pathname_t *pp)
-/* Return the actual name as a C string. */
-{
-    return pp->path;
-}
-
-size_t path_length(const pathname_t *pp)
-/* The length of the pathname. */
-{
-    return pp->idx;
-}
-
-void path_drop(pathname_t *pp)
-/* Release the storage occupied by the pathname. */
-{
-    deallocate(pp->path);
-}
-
-#else /* !DEBUG */
-#define path_name(pp)		((const char *) (pp)->path)
-#define path_length(pp)		((pp)->idx)
-#define path_drop(pp)		deallocate((void *) (pp)->path)
-#endif /* !DEBUG */
-
-char *basename(const char *path)
-/* Return the last component of a pathname.  (Note: declassifies a const
- * char * just like strchr.
- */
-{
-    const char *p= path;
-
-    for (;;) {
-	while (*p == '/') p++;			/* Trailing slashes? */
-
-	if (*p == 0) break;
-
-	path= p;
-	while (*p != 0 && *p != '/') p++;	/* Skip component. */
-    }
-    return (char *) path;
-}
-
-int affirmative(void)
-/* Get a yes/no answer from the suspecting user. */
-{
-    int c;
-    int ok;
-
-    fflush(stdout);
-    fflush(stderr);
-
-    while ((c= getchar()) == ' ') {}
-    ok= (c == 'y' || c == 'Y');
-    while (c != EOF && c != '\n') c= getchar();
-
-    return ok;
-}
-
-int writable(const struct stat *stp)
-/* True iff the file with the given attributes allows writing.  (And we have
- * a terminal to ask if ok to overwrite.)
- */
-{
-    if (!istty || uid == 0) return 1;
-    if (stp->st_uid == uid) return stp->st_mode & S_IWUSR;
-    if (stp->st_gid == gid) return stp->st_mode & S_IWGRP;
-    return stp->st_mode & S_IWOTH;
-}
-
-#ifndef PATH_MAX
-#define PATH_MAX	1024
-#endif
-
-static char *link_islink(struct stat *stp, const char *file)
-{
-    /* Tell if a file, which stat(2) information in '*stp', has been seen
-     * earlier by this function under a different name.  If not return a
-     * null pointer with errno set to ENOENT, otherwise return the name of
-     * the link.  Return a null pointer with an error code in errno for any
-     * error, using E2BIG for a too long file name.
-     *
-     * Use link_islink(nil, nil) to reset all bookkeeping.
-     *
-     * Call for a file twice to delete it from the store.
-     */
-
-    typedef struct link {	/* In-memory link store. */
-	struct link	*next;		/* Hash chain on inode number. */
-	ino_t		ino;		/* File's inode number. */
-	off_t		off;		/* Offset to more info in temp file. */
-    } link_t;
-    typedef struct dlink {	/* On-disk link store. */
-	dev_t		dev;		/* Device number. */
-	char		file[PATH_MAX];	/* Name of earlier seen link. */
-    } dlink_t;
-    static link_t *links[256];		/* Hash list of known links. */
-    static int tfd= -1;			/* Temp file for file name storage. */
-    static dlink_t dlink;
-    link_t *lp, **plp;
-    size_t len;
-    off_t off;
-
-    if (file == nil) {
-	/* Reset everything. */
-	for (plp= links; plp < arraylimit(links); plp++) {
-	    while ((lp= *plp) != nil) {
-		*plp= lp->next;
-		free(lp);
-	    }
-	}
-	if (tfd != -1) close(tfd);
-	tfd= -1;
-	return nil;
-    }
-
-    /* The file must be a non-directory with more than one link. */
-    if (S_ISDIR(stp->st_mode) || stp->st_nlink <= 1) {
-	errno= ENOENT;
-	return nil;
-    }
-
-    plp= &links[stp->st_ino % arraysize(links)];
-
-    while ((lp= *plp) != nil) {
-	if (lp->ino == stp->st_ino) {
-	    /* May have seen this link before.  Get it and check. */
-	    if (lseek(tfd, lp->off, SEEK_SET) == -1) return nil;
-	    if (read(tfd, &dlink, sizeof(dlink)) < 0) return nil;
-
-	    /* Only need to check the device number. */
-	    if (dlink.dev == stp->st_dev) {
-		if (strcmp(file, dlink.file) == 0) {
-		    /* Called twice.  Forget about this link. */
-		    *plp= lp->next;
-		    free(lp);
-		    errno= ENOENT;
-		    return nil;
-		}
-
-		/* Return the name of the earlier link. */
-		return dlink.file;
-	    }
-	}
-	plp= &lp->next;
-    }
-
-    /* First time I see this link.  Add it to the store. */
-    if (tfd == -1) {
-	for (;;) {
-	    char *tmp;
-
-	    tmp= tmpnam(nil);
-	    tfd= open(tmp, O_RDWR|O_CREAT|O_EXCL, 0600);
-	    if (tfd < 0) {
-		if (errno != EEXIST) return nil;
-	    } else {
-		(void) unlink(tmp);
-		break;
-	    }
-	}
-    }
-    if ((len= strlen(file)) >= PATH_MAX) {
-	errno= E2BIG;
-	return nil;
-    }
-
-    dlink.dev= stp->st_dev;
-    strcpy(dlink.file, file);
-    len += offsetof(dlink_t, file) + 1;
-    if ((off= lseek(tfd, 0, SEEK_END)) == -1) return nil;
-    if (write(tfd, &dlink, len) != len) return nil;
-
-    if ((lp= malloc(sizeof(*lp))) == nil) return nil;
-    lp->next= nil;
-    lp->ino= stp->st_ino;
-    lp->off= off;
-    *plp= lp;
-    errno= ENOENT;
-    return nil;
-}
-
-int trylink(const char *src, const char *dst, struct stat *srcst,
-			struct stat *dstst)
-/* Keep the link structure intact if src has been seen before. */
-{
-    char *olddst;
-    int linked;
-
-    if (action == COPY && expand) return 0;
-
-    if ((olddst= link_islink(srcst, dst)) == nil) {
-	/* if (errno != ENOENT) ... */
-	return 0;
-    }
-
-    /* Try to link the file copied earlier to the new file. */
-    if (dstst->st_ino != 0) (void) unlink(dst);
-
-    if ((linked= (link(olddst, dst) == 0)) && vflag)
-	printf("ln %s ..\n", olddst);
-
-    return linked;
-}
-
-int copy(const char *src, const char *dst, struct stat *srcst,
-			struct stat *dstst)
-/* Copy one file to another and copy (some of) the attributes. */
-{
-    char buf[CHUNK];
-    int srcfd, dstfd;
-    ssize_t n;
-
-    assert(srcst->st_ino != 0);
-
-    if (dstst->st_ino == 0) {
-	/* The file doesn't exist yet. */
-
-	if (!S_ISREG(srcst->st_mode)) {
-	    /* Making a new mode 666 regular file. */
-	    srcst->st_mode= (S_IFREG | 0666) & fc_mask;
-	} else
-	if (!pflag && conforming) {
-	    /* Making a new file copying mode with umask applied. */
-	    srcst->st_mode &= fc_mask;
-	}
-    } else {
-	/* File exists, ask if ok to overwrite if '-i'. */
-
-	if (iflag || (action == MOVE && !fflag && !writable(dstst))) {
-	    fprintf(stderr, "Overwrite %s? (mode = %03o) ",
-			dst, dstst->st_mode & 07777);
-	    if (!affirmative()) return 0;
-	}
-
-	if (action == MOVE) {
-	    /* Don't overwrite, remove first. */
-	    if (unlink(dst) < 0 && errno != ENOENT) {
-		report(dst);
-		return 0;
-	    }
-	} else {
-	    /* Overwrite. */
-	    if (!pflag) {
-		/* Keep the existing mode and ownership. */
-		srcst->st_mode= dstst->st_mode;
-		srcst->st_uid= dstst->st_uid;
-		srcst->st_gid= dstst->st_gid;
-	    }
-	}
-    }
-
-    /* Keep the link structure if possible. */
-    if (trylink(src, dst, srcst, dstst)) return 1;
-
-    if ((srcfd= open(src, O_RDONLY)) < 0) {
-	report(src);
-	return 0;
-    }
-
-    dstfd= open(dst, O_WRONLY|O_CREAT|O_TRUNC, srcst->st_mode & 0777);
-    if (dstfd < 0 && fflag && errno == EACCES) {
-	/* Retry adding a "w" bit. */
-	(void) chmod(dst, dstst->st_mode | S_IWUSR);
-	dstfd= open(dst, O_WRONLY|O_CREAT|O_TRUNC, 0);
-    }
-    if (dstfd < 0 && fflag && errno == EACCES) {
-	/* Retry after trying to delete. */
-	(void) unlink(dst);
-	dstfd= open(dst, O_WRONLY|O_CREAT|O_TRUNC, 0);
-    }
-    if (dstfd < 0) {
-	report(dst);
-	close(srcfd);
-	return 0;
-    }
-
-    /* Get current parameters. */
-    if (fstat(dstfd, dstst) < 0) {
-	report(dst);
-	close(srcfd);
-	close(dstfd);
-	return 0;
-    }
-
-    /* Copy the little bytes themselves. */
-    while ((n= read(srcfd, buf, sizeof(buf))) > 0) {
-	char *bp = buf;
-	ssize_t r;
-
-	while (n > 0 && (r= write(dstfd, bp, n)) > 0) {
-	    bp += r;
-	    n -= r;
-	}
-	if (r <= 0) {
-	    if (r == 0) {
-		fprintf(stderr,
-		    "%s: Warning: EOF writing to %s\n",
-		    prog_name, dst);
-		break;
-	    }
-	    fatal(dst);
-	}
-    }
-
-    if (n < 0) {
-	report(src);
-	close(srcfd);
-	close(dstfd);
-	return 0;
-    }
-
-    close(srcfd);
-    close(dstfd);
-
-    /* Copy the ownership. */
-    if ((pflag || !conforming)
-	&& S_ISREG(dstst->st_mode)
-	&& (dstst->st_uid != srcst->st_uid
-		|| dstst->st_gid != srcst->st_gid)
-    ) {
-	if (chmod(dst, 0) == 0) dstst->st_mode&= ~07777;
-	if (chown(dst, srcst->st_uid, srcst->st_gid) < 0) {
-	    if (errno != EPERM) {
-		report(dst);
-		return 0;
-	    }
-	} else {
-	    dstst->st_uid= srcst->st_uid;
-	    dstst->st_gid= srcst->st_gid;
-	}
-    }
-
-    if (conforming && S_ISREG(dstst->st_mode)
-	&& (dstst->st_uid != srcst->st_uid
-		|| dstst->st_gid != srcst->st_gid)
-    ) {
-	/* Suid bits must be cleared in the holy name of
-	 * security (and the assumed user stupidity).
-	 */
-	srcst->st_mode&= ~06000;
-    }
-
-    /* Copy the mode. */
-    if (S_ISREG(dstst->st_mode) && dstst->st_mode != srcst->st_mode) {
-	if (chmod(dst, srcst->st_mode) < 0) {
-	    if (errno != EPERM) {
-		report(dst);
-		return 0;
-	    }
-	    fprintf(stderr, "%s: Can't change the mode of %s\n",
-		prog_name, dst);
-	}
-    }
-
-    /* Copy the file modification time. */
-    if ((pflag || !conforming) && S_ISREG(dstst->st_mode)) {
-	struct utimbuf ut;
-
-	ut.actime= action == MOVE ? srcst->st_atime : time(nil);
-	ut.modtime= srcst->st_mtime;
-	if (utime(dst, &ut) < 0) {
-	    if (errno != EPERM) {
-		report(dst);
-		return 0;
-	    }
-	    if (pflag) {
-		fprintf(stderr,
-		    "%s: Can't set the time of %s\n",
-		    prog_name, dst);
-	    }
-	}
-    }
-    if (vflag) {
-	printf(action == COPY ? "cp %s ..\n" : "mv %s ..\n", src);
-    }
-    return 1;
-}
-
-void copy1(const char *src, const char *dst, struct stat *srcst,
-			    struct stat *dstst)
-/* Inspect the source file and then copy it.  Treatment of symlinks and
- * special files is a bit complicated.  The filetype and link-structure are
- * ignored if (expand && !rflag), symlinks and link-structure are ignored
- * if (expand && rflag), everything is copied precisely if !expand.
- */
-{
-    int r, linked;
-
-    assert(srcst->st_ino != 0);
-
-    if (srcst->st_ino == dstst->st_ino && srcst->st_dev == dstst->st_dev) {
-	fprintf(stderr, "%s: can't copy %s onto itself\n",
-	    prog_name, src);
-	ex_code= 1;
-	return;
-    }
-
-    /* You can forget it if the destination is a directory. */
-    if (dstst->st_ino != 0 && S_ISDIR(dstst->st_mode)) {
-	errno= EISDIR;
-	report(dst);
-	return;
-    }
-
-    if (S_ISREG(srcst->st_mode) || (expand && !rflag)) {
-	if (!copy(src, dst, srcst, dstst)) return;
-
-	if (action == MOVE && unlink(src) < 0) {
-	    report(src);
-	    return;
-	}
-	return;
-    }
-
-    if (dstst->st_ino != 0) {
-	if (iflag || (action == MOVE && !fflag && !writable(dstst))) {
-	    fprintf(stderr, "Replace %s? (mode = %03o) ",
-		dst, dstst->st_mode & 07777);
-	    if (!affirmative()) return;
-	}
-	if (unlink(dst) < 0) {
-	    report(dst);
-	    return;
-	}
-	dstst->st_ino= 0;
-    }
-
-    /* Apply the file creation mask if so required. */
-    if (!pflag && conforming) srcst->st_mode &= fc_mask;
-
-    linked= 0;
-
-    if (S_ISLNK(srcst->st_mode)) {
-	char buf[1024+1];
-
-	if ((r= readlink(src, buf, sizeof(buf)-1)) < 0) {
-	    report(src);
-	    return;
-	}
-	buf[r]= 0;
-	r= symlink(buf, dst);
-	if (vflag && r == 0)
-	    printf("ln -s %s %s\n", buf, dst);
-    } else
-    if (trylink(src, dst, srcst, dstst)) {
-	linked= 1;
-	r= 0;
-    } else
-    if (S_ISFIFO(srcst->st_mode)) {
-	r= mkfifo(dst, srcst->st_mode);
-	if (vflag && r == 0)
-	    printf("mkfifo %s\n", dst);
-    } else
-    if (S_ISBLK(srcst->st_mode) || S_ISCHR(srcst->st_mode)) {
-	r= mknod(dst, srcst->st_mode, srcst->st_rdev);
-	if (vflag && r == 0) {
-	    printf("mknod %s %c %d %d\n",
-		dst,
-		S_ISBLK(srcst->st_mode) ? 'b' : 'c',
-		(srcst->st_rdev >> 8) & 0xFF,
-		(srcst->st_rdev >> 0) & 0xFF);
-	}
-    } else {
-	fprintf(stderr, "%s: %s: odd filetype %5o (not copied)\n",
-	    prog_name, src, srcst->st_mode);
-	ex_code= 1;
-	return;
-    }
-
-    if (r < 0 || lstat(dst, dstst) < 0) {
-	report(dst);
-	return;
-    }
-
-    if (action == MOVE && unlink(src) < 0) {
-	report(src);
-	(void) unlink(dst);	/* Don't want it twice. */
-	return;
-    }
-
-    if (linked) return;
-
-    if (S_ISLNK(srcst->st_mode)) return;
-
-    /* Copy the ownership. */
-    if ((pflag || !conforming)
-	&& (dstst->st_uid != srcst->st_uid
-		|| dstst->st_gid != srcst->st_gid)
-    ) {
-	if (chown(dst, srcst->st_uid, srcst->st_gid) < 0) {
-	    if (errno != EPERM) {
-		report(dst);
-		return;
-	    }
-	}
-    }
-
-    /* Copy the file modification time. */
-    if (pflag || !conforming) {
-	struct utimbuf ut;
-
-	ut.actime= action == MOVE ? srcst->st_atime : time(nil);
-	ut.modtime= srcst->st_mtime;
-	if (utime(dst, &ut) < 0) {
-	    if (errno != EPERM) {
-		report(dst);
-		return;
-	    }
-	    fprintf(stderr, "%s: Can't set the time of %s\n",
-		prog_name, dst);
-	}
-    }
-}
-
-void remove1(const char *src, struct stat *srcst)
-{
-    if (iflag || (!fflag && !writable(srcst))) {
-	fprintf(stderr, "Remove %s? (mode = %03o) ", src,
-			srcst->st_mode & 07777);
-	if (!affirmative()) return;
-    }
-    if (unlink(src) < 0) {
-	report(src);
-    } else {
-	if (vflag) printf("rm %s\n", src);
-    }
-}
-
-void link1(const char *src, const char *dst, struct stat *srcst,
-			    struct stat *dstst)
-{
-    pathname_t sym;
-    const char *p;
-
-    if (dstst->st_ino != 0 && (iflag || fflag)) {
-	if (srcst->st_ino == dstst->st_ino) {
-	    if (fflag) return;
-	    fprintf(stderr, "%s: Can't link %s onto itself\n",
-		prog_name, src);
-	    ex_code= 1;
-	    return;
-	}
-	if (iflag) {
-	    fprintf(stderr, "Remove %s? ", dst);
-	    if (!affirmative()) return;
-	}
-	errno= EISDIR;
-	if (S_ISDIR(dstst->st_mode) || unlink(dst) < 0) {
-	    report(dst);
-	    return;
-	}
-    }
-
-    if (!sflag && !(rflag && S_ISLNK(srcst->st_mode)) && !(Sflag && xdev)) {
-	/* A normal link. */
-	if (link(src, dst) < 0) {
-	    if (!Sflag || errno != EXDEV) {
-		report2(src, dst);
-		return;
-	    }
-	    /* Can't do a cross-device link, we have to symlink. */
-	    xdev= 1;
-	} else {
-	    if (vflag) printf("ln %s..\n", src);
-	    return;
-	}
-    }
-
-    /* Do a symlink. */
-    if (!rflag && !Sflag) {
-	/* We can get away with a "don't care if it works" symlink. */
-	if (symlink(src, dst) < 0) {
-	    report(dst);
-	    return;
-	}
-	if (vflag) printf("ln -s %s %s\n", src, dst);
-	return;
-    }
-
-    /* If the source is a symlink then it is simply copied. */
-    if (S_ISLNK(srcst->st_mode)) {
-	int r;
-	char buf[1024+1];
-
-	if ((r= readlink(src, buf, sizeof(buf)-1)) < 0) {
-	    report(src);
-	    return;
-	}
-	buf[r]= 0;
-	if (symlink(buf, dst) < 0) {
-	    report(dst);
-	    return;
-	}
-	if (vflag) printf("ln -s %s %s\n", buf, dst);
-	return;
-    }
-
-    /* Make a symlink that has to work, i.e. we must be able to access the
-     * source now, and the link must work.
-     */
-    if (dst[0] == '/' && src[0] != '/') {
-	/* ln -[rsS] relative/path /full/path. */
-	fprintf(stderr,
-	    "%s: Symlinking %s to %s is too difficult for me to figure out\n",
-	    prog_name, src, dst);
-	exit(1);
-    }
-
-    /* Count the number of subdirectories in the destination file and
-     * add one '..' for each.
-     */
-    path_init(&sym);
-    if (src[0] != '/') {
-	p= dst;
-	while (*p != 0) {
-	    if (p[0] == '.') {
-		if (p[1] == '/' || p[1] == 0) {
-		    /* A "." component; skip. */
-		    do p++; while (*p == '/');
-		    continue;
-		} else
-		if (p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
-		    /* A ".." component; oops. */
-		    switch (path_length(&sym)) {
-		    case 0:
-			fprintf(stderr,
-	    "%s: Symlinking %s to %s is too difficult for me to figure out\n",
-			    prog_name, src, dst);
-			exit(1);
-		    case 2:
-			path_trunc(&sym, 0);
-			break;
-		    default:
-			path_trunc(&sym, path_length(&sym) - 3);
-		    }
-		    p++;
-		    do p++; while (*p == '/');
-		    continue;
-		}
-	    }
-	    while (*p != 0 && *p != '/') p++;
-	    while (*p == '/') p++;
-	    if (*p == 0) break;
-	    path_add(&sym, "..");
-	}
-    }
-    path_add(&sym, src);
-
-    if (symlink(path_name(&sym), dst) < 0) {
-	report(dst);
-    } else {
-	if (vflag) printf("ln -s %s %s\n", path_name(&sym), dst);
-    }
-    path_drop(&sym);
-}
-
-typedef struct entrylist {
-    struct entrylist	*next;
-    char			*name;
-} entrylist_t;
-
-int eat_dir(const char *dir, entrylist_t **dlist)
-/* Make a linked list of all the names in a directory. */
-{
-    DIR *dp;
-    struct dirent *entry;
-
-    if ((dp= opendir(dir)) == nil) return 0;
-
-    while ((entry= readdir(dp)) != nil) {
-	if (strcmp(entry->d_name, ".") == 0) continue;
-	if (strcmp(entry->d_name, "..") == 0) continue;
-
-	*dlist= allocate(nil, sizeof(**dlist));
-	(*dlist)->name= allocate(nil, strlen(entry->d_name)+1);
-	strcpy((*dlist)->name, entry->d_name);
-	dlist= &(*dlist)->next;
-    }
-    closedir(dp);
-    *dlist= nil;
-    return 1;
-}
-
-void chop_dlist(entrylist_t **dlist)
-/* Chop an entry of a name list. */
-{
-    entrylist_t *junk= *dlist;
-
-    *dlist= junk->next;
-    deallocate(junk->name);
-    deallocate(junk);
-}
-
-void drop_dlist(entrylist_t *dlist)
-/* Get rid of a whole list. */
-{
-    while (dlist != nil) chop_dlist(&dlist);
-}
-
-void do1(pathname_t *src, pathname_t *dst, int depth)
-/* Perform the appropriate action on a source and destination file. */
-{
-    size_t slashsrc, slashdst;
-    struct stat srcst, dstst;
-    entrylist_t *dlist;
-    static ino_t topdst_ino;
-    static dev_t topdst_dev;
-    static dev_t topsrc_dev;
-
-#if DEBUG
-    if (vflag && depth == 0) {
-	char flags[100], *pf= flags;
-
-	if (pflag) *pf++= 'p';
-	if (iflag) *pf++= 'i';
-	if (fflag) *pf++= 'f';
-	if (sflag) *pf++= 's';
-	if (Sflag) *pf++= 'S';
-	if (mflag) *pf++= 'm';
-	if (rflag) *pf++= 'r';
-	if (vflag) *pf++= 'v';
-	if (xflag) *pf++= 'x';
-	if (expand) *pf++= 'L';
-	if (conforming) *pf++= 'C';
-	*pf= 0;
-	printf(": %s -%s %s %s\n", prog_name, flags,
-		    path_name(src), path_name(dst));
-    }
-#endif
-
-    /* st_ino == 0 if not stat()'ed yet, or nonexistent. */
-    srcst.st_ino= 0;
-    dstst.st_ino= 0;
-
-    if (action != LINK || !sflag || rflag) {
-	/* Source must exist unless symlinking. */
-	if ((expand ? stat : lstat)(path_name(src), &srcst) < 0) {
-	    report(path_name(src));
-	    return;
-	}
-    }
-
-    if (depth == 0) {
-	/* First call: Not cross-device yet, first dst not seen yet,
-	 * remember top device number.
-	 */
-	xdev= 0;
-	topdst_ino= 0;
-	topsrc_dev= srcst.st_dev;
-    }
-
-    /* Inspect the intended destination unless removing. */
-    if (action != REMOVE) {
-	if ((expand ? stat : lstat)(path_name(dst), &dstst) < 0) {
-	    if (errno != ENOENT) {
-		report(path_name(dst));
-		return;
-	    }
-	}
-    }
-
-    if (action == MOVE && !xdev) {
-	if (dstst.st_ino != 0 && srcst.st_dev != dstst.st_dev) {
-	    /* It's a cross-device rename, i.e. copy and remove. */
-	    xdev= 1;
-	} else
-	if (!mflag || dstst.st_ino == 0 || !S_ISDIR(dstst.st_mode)) {
-	    /* Try to simply rename the file (not merging trees). */
-
-	    if (srcst.st_ino == dstst.st_ino) {
-		fprintf(stderr,
-		    "%s: Can't move %s onto itself\n",
-		    prog_name, path_name(src));
-		ex_code= 1;
-		return;
-	    }
-
-	    if (dstst.st_ino != 0) {
-		if (iflag || (!fflag && !writable(&dstst))) {
-		    fprintf(stderr,
-			"Replace %s? (mode = %03o) ",
-			path_name(dst),
-			dstst.st_mode & 07777);
-		    if (!affirmative()) return;
-		}
-		if (!S_ISDIR(dstst.st_mode))
-		    (void) unlink(path_name(dst));
-	    }
-
-	    if (rename(path_name(src), path_name(dst)) == 0) {
-		/* Success. */
-		if (vflag) {
-		    printf("mv %s %s\n", path_name(src),
-			    path_name(dst));
-		}
-		return;
-	    }
-	    if (errno == EXDEV) {
-		xdev= 1;
-	    } else {
-		report2(path_name(src), path_name(dst));
-		return;
-	    }
-	}
-    }
-
-    if (srcst.st_ino == 0 || !S_ISDIR(srcst.st_mode)) {
-	/* Copy/move/remove/link a single file. */
-	switch (action) {
-	case COPY:
-	case MOVE:
-	    copy1(path_name(src), path_name(dst), &srcst, &dstst);
-	    break;
-	case REMOVE:
-	    remove1(path_name(src), &srcst);
-	    break;
-	case LINK:
-	    link1(path_name(src), path_name(dst), &srcst, &dstst);
-	    break;
-	}
-	return;
-    }
-
-    /* Recursively copy/move/remove/link a directory if -r or -R. */
-    if (!rflag) {
-	errno= EISDIR;
-	report(path_name(src));
-	return;
-    }
-
-    /* Ok to remove contents of dir? */
-    if (action == REMOVE) {
-	if (xflag && topsrc_dev != srcst.st_dev) {
-	    /* Don't recurse past a mount point. */
-	    return;
-	}
-	if (iflag) {
-	    fprintf(stderr, "Remove contents of %s? ", path_name(src));
-	    if (!affirmative()) return;
-	}
-    }
-
-    /* Gather the names in the source directory. */
-    if (!eat_dir(path_name(src), &dlist)) {
-	report(path_name(src));
-	return;
-    }
-
-    /* Check/create the target directory. */
-    if (action != REMOVE && dstst.st_ino != 0 && !S_ISDIR(dstst.st_mode)) {
-	if (action != MOVE && !fflag) {
-	    errno= ENOTDIR;
-	    report(path_name(dst));
-	    return;
-	}
-	if (iflag) {
-	    fprintf(stderr, "Replace %s? ", path_name(dst));
-	    if (!affirmative()) {
-		drop_dlist(dlist);
-		return;
-	    }
-	}
-	if (unlink(path_name(dst)) < 0) {
-	    report(path_name(dst));
-	    drop_dlist(dlist);
-	    return;
-	}
-	dstst.st_ino= 0;
-    }
-
-    if (action != REMOVE) {
-	if (dstst.st_ino == 0) {
-	    /* Create a new target directory. */
-	    if (!pflag && conforming) srcst.st_mode&= fc_mask;
-
-	    if (mkdir(path_name(dst), srcst.st_mode | S_IRWXU) < 0
-		    || stat(path_name(dst), &dstst) < 0) {
-		report(path_name(dst));
-		drop_dlist(dlist);
-		return;
-	    }
-	    if (vflag) printf("mkdir %s\n", path_name(dst));
-	} else {
-	    /* Target directory already exists. */
-	    if (action == MOVE && !mflag) {
-		errno= EEXIST;
-		report(path_name(dst));
-		drop_dlist(dlist);
-		return;
-	    }
-	    if (!pflag) {
-		/* Keep the existing attributes. */
-		srcst.st_mode= dstst.st_mode;
-		srcst.st_uid= dstst.st_uid;
-		srcst.st_gid= dstst.st_gid;
-		srcst.st_mtime= dstst.st_mtime;
-	    }
-	}
-
-	if (topdst_ino == 0) {
-	    /* Remember the top destination. */
-	    topdst_dev= dstst.st_dev;
-	    topdst_ino= dstst.st_ino;
-	}
-
-	if (srcst.st_ino == topdst_ino && srcst.st_dev == topdst_dev) {
-	    /* E.g. cp -r /shallow /shallow/deep. */
-	    fprintf(stderr,
-		"%s%s %s/ %s/: infinite recursion avoided\n",
-		prog_name, action != MOVE ? " -r" : "",
-		path_name(src), path_name(dst));
-	    drop_dlist(dlist);
-	    return;
-	}
-
-	if (xflag && topsrc_dev != srcst.st_dev) {
-	    /* Don't recurse past a mount point. */
-	    drop_dlist(dlist);
-	    return;
-	}
-    }
-
-    /* Go down. */
-    slashsrc= path_length(src);
-    slashdst= path_length(dst);
-
-    while (dlist != nil) {
-	path_add(src, dlist->name);
-	if (action != REMOVE) path_add(dst, dlist->name);
-
-	do1(src, dst, depth+1);
-
-	path_trunc(src, slashsrc);
-	path_trunc(dst, slashdst);
-	chop_dlist(&dlist);
-    }
-
-    if (action == MOVE || action == REMOVE) {
-	/* The contents of the source directory should have
-	 * been (re)moved above.  Get rid of the empty dir.
-	 */
-	if (action == REMOVE && iflag) {
-	    fprintf(stderr, "Remove directory %s? ",
-			    path_name(src));
-	    if (!affirmative()) return;
-	}
-	if (rmdir(path_name(src)) < 0) {
-	    if (errno != ENOTEMPTY) report(path_name(src));
-	    return;
-	}
-	if (vflag) printf("rmdir %s\n", path_name(src));
-    }
-
-    if (action != REMOVE) {
-	/* Set the attributes of a new directory. */
-	struct utimbuf ut;
-
-	/* Copy the ownership. */
-	if ((pflag || !conforming)
-	    && (dstst.st_uid != srcst.st_uid
-		|| dstst.st_gid != srcst.st_gid)
-	) {
-	    if (chown(path_name(dst), srcst.st_uid,
-			    srcst.st_gid) < 0) {
-		if (errno != EPERM) {
-		    report(path_name(dst));
-		    return;
-		}
-	    }
-	}
-
-	/* Copy the mode. */
-	if (dstst.st_mode != srcst.st_mode) {
-	    if (chmod(path_name(dst), srcst.st_mode) < 0) {
-		report(path_name(dst));
-		return;
-	    }
-	}
-
-	/* Copy the file modification time. */
-	if (dstst.st_mtime != srcst.st_mtime) {
-	    ut.actime= action == MOVE ? srcst.st_atime : time(nil);
-	    ut.modtime= srcst.st_mtime;
-	    if (utime(path_name(dst), &ut) < 0) {
-		if (errno != EPERM) {
-		    report(path_name(dst));
-		    return;
-		}
-		fprintf(stderr,
-		    "%s: Can't set the time of %s\n",
-		    prog_name, path_name(dst));
-	    }
-	}
-    }
-}
-
-void usage(void)
-{
-    char *flags1, *flags2;
-
-    switch (identity) {
-    case CP:
-	flags1= "pifsmrRvx";
-	flags2= "pifsrRvx";
-	break;
-    case MV:
-	flags1= "ifsmvx";
-	flags2= "ifsvx";
-	break;
-    case RM:
-	fprintf(stderr, "Usage: rm [-ifrRvx] file ...\n");
-	exit(1);
-    case LN:
-	flags1= "ifsSmrRvx";
-	flags2= "ifsSrRvx";
-	break;
-    case CPDIR:
-	flags1= "ifvx";
-	flags2= nil;
-	break;
-    case CLONE:
-	flags1= "ifsSvx";
-	flags2= nil;
-	break;
-    }
-    fprintf(stderr, "Usage: %s [-%s] file1 file2\n", prog_name, flags1);
-  if (flags2 != nil)
-    fprintf(stderr, "       %s [-%s] file ... dir\n", prog_name, flags2);
-    exit(1);
-}
-
-void main(int argc, char **argv)
-{
-    int i;
-    char *flags;
-    struct stat st;
-    pathname_t src, dst;
-    size_t slash;
-
-#if DEBUG >= 3
-    /* The first argument is the call name while debugging. */
-    if (argc < 2) exit(-1);
-    argv++;
-    argc--;
-#endif
-#if DEBUG
-    vflag= isatty(1);
-#endif
-
-    /* Call name of this program. */
-    prog_name= basename(argv[0]);
-
-    /* Required action. */
-    if (strcmp(prog_name, "cp") == 0) {
-	identity= CP;
-	action= COPY;
-	flags= "pifsmrRvx";
-	expand= 1;
-    } else
-    if (strcmp(prog_name, "mv") == 0) {
-	identity= MV;
-	action= MOVE;
-	flags= "ifsmvx";
-	rflag= pflag= 1;
-    } else
-    if (strcmp(prog_name, "rm") == 0) {
-	identity= RM;
-	action= REMOVE;
-	flags= "ifrRvx";
-    } else
-    if (strcmp(prog_name, "ln") == 0) {
-	identity= LN;
-	action= LINK;
-	flags= "ifsSmrRvx";
-    } else
-    if (strcmp(prog_name, "cpdir") == 0) {
-	identity= CPDIR;
-	action= COPY;
-	flags= "pifsmrRvx";
-	rflag= mflag= pflag= 1;
-	conforming= 0;
-    } else
-    if (strcmp(prog_name, "clone") == 0) {
-	identity= CLONE;
-	action= LINK;
-	flags= "ifsSmrRvx";
-	rflag= mflag= fflag= 1;
-    } else {
-	fprintf(stderr,
-	    "%s: Identity crisis, not called cp, mv, rm, ln, cpdir, or clone\n",
-	    prog_name);
-	exit(1);
-    }
-
-    /* Who am I?, where am I?, how protective am I? */
-    uid= geteuid();
-    gid= getegid();
-    istty= isatty(0);
-    fc_mask= ~umask(0);
-
-    /* Gather flags. */
-    i= 1;
-    while (i < argc && argv[i][0] == '-') {
-	char *opt= argv[i++] + 1;
-
-	if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-	while (*opt != 0) {
-	    /* Flag supported? */
-	    if (strchr(flags, *opt) == nil) usage();
-
-	    switch (*opt++) {
-	    case 'p':
-		pflag= 1;
-		break;
-	    case 'i':
-		iflag= 1;
-		if (action == MOVE) fflag= 0;
-		break;
-	    case 'f':
-		fflag= 1;
-		if (action == MOVE) iflag= 0;
-		break;
-	    case 's':
-		if (action == LINK) {
-		    sflag= 1;
-		} else {
-		    /* Forget about POSIX, do it right. */
-		    conforming= 0;
-		}
-		break;
-	    case 'S':
-		Sflag= 1;
-		break;
-	    case 'm':
-		mflag= 1;
-		break;
-	    case 'r':
-		expand= 0;
-		/*FALL THROUGH*/
-	    case 'R':
-		rflag= 1;
-		break;
-	    case 'v':
-		vflag= 1;
-		break;
-	    case 'x':
-		xflag= 1;
-		break;
-	    default:
-		assert(0);
-	    }
-	}
-    }
-
-    switch (action) {
-    case REMOVE:
-	if (i == argc) usage();
-	break;
-    case LINK:
-	/* 'ln dir/file' is to be read as 'ln dir/file .'. */
-	if ((argc - i) == 1 && action == LINK) argv[argc++]= ".";
-	/*FALL THROUGH*/
-    default:
-	if ((argc - i) < 2) usage();
-    }
-
-    path_init(&src);
-    path_init(&dst);
-
-    if (action != REMOVE && !mflag
-	&& stat(argv[argc-1], &st) >= 0 && S_ISDIR(st.st_mode)
-    ) {
-	/* The last argument is a directory, this means we have to
-	 * throw the whole lot into this directory.  This is the
-	 * Right Thing unless you use -r.
-	 */
-	path_add(&dst, argv[argc-1]);
-	slash= path_length(&dst);
-
-	do {
-	    path_add(&src, argv[i]);
-	    path_add(&dst, basename(argv[i]));
-
-	    do1(&src, &dst, 0);
-
-	    path_trunc(&src, 0);
-	    path_trunc(&dst, slash);
-	} while (++i < argc-1);
-    } else
-    if (action == REMOVE || (argc - i) == 2) {
-	/* Just two files (or many files for rm). */
-	do {
-	    path_add(&src, argv[i]);
-	    if (action != REMOVE) path_add(&dst, argv[i+1]);
-
-	    do1(&src, &dst, 0);
-	    path_trunc(&src, 0);
-	} while (action == REMOVE && ++i < argc);
-    } else {
-	usage();
-    }
-    path_drop(&src);
-    path_drop(&dst);
-
-#if DEBUG
-    if (nchunks != 0) {
-	fprintf(stderr, "(%ld chunks of memory not freed)\n",
-	    (long) nchunks);
-    }
-#endif
-    exit(ex_code);
-}
Index: trunk/minix/commands/simple/crc.c
===================================================================
--- trunk/minix/commands/simple/crc.c	(revision 9)
+++ 	(revision )
@@ -1,117 +1,0 @@
-/* Compute checksum			Author: Johan W. Stevenson */
-
-/* Copyright 1988 by Johan W. Stevenson */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-int errs;
-
-#if __STDC__
-int main(int argc, char **argv);
-void crc(char *fname);
-#else
-void crc();
-#endif
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  char line[256];
-
-  if (argc <= 1)
-	crc((char *) 0);
-  else if (argc == 2 && strcmp(argv[1], "-") == 0)
-	while (fgets(line, sizeof line, stdin) != NULL) {
-		if (line[strlen(line) - 1] == '\n')
-			line[strlen(line) - 1] = '\0';
-		crc(line);
-	}
-  else
-	do {
-		crc(argv[1]);
-		argv++;
-		argc--;
-	} while (argc > 1);
-  return(errs != 0);
-}
-
-/* Crctab calculated by Mark G. Mendel, Network Systems Corporation */
-static unsigned short crctab[256] = {
-       0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
-       0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
-       0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
-       0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
-       0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
-       0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
-       0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
-       0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
-       0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
-       0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
-       0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
-       0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
-       0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
-       0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
-       0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
-       0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
-       0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
-       0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
-       0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
-       0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
-       0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
-       0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
-       0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
-       0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
-       0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
-       0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
-       0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
-       0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
-       0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
-       0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
-       0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
-        0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
-};
-
-/* Updcrc macro derived from article Copyright (C) 1986 Stephen Satchell.
- *  NOTE: First argument must be in range 0 to 255.
- *        Second argument is referenced twice.
- *
- * Programmers may incorporate any or all code into their programs,
- * giving proper credit within the source. Publication of the
- * source routines is permitted so long as proper credit is given
- * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
- * Omen Technology.
- */
-
-#define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
-
-void crc(fname)
-char *fname;
-{
-  register int c;
-  register long len = 0;
-  register unsigned short crc = 0;
-  register FILE *fp;
-
-  if (fname == NULL)
-	fp = stdin;
-  else if ((fp = fopen(fname, "r")) == NULL) {
-	fprintf(stderr, "crc: Can't open %s: %s\n", fname, strerror(errno));
-	errs++;
-	return;
-  }
-  while ((c = getc(fp)) != EOF) {
-	len++;
-	crc = updcrc(c, crc);
-  }
-  printf("%05u %6ld", crc, len);
-  if (fname) {
-	printf(" %s", fname);
-	fclose(fp);
-  }
-  printf("\n");
-}
Index: trunk/minix/commands/simple/cut.c
===================================================================
--- trunk/minix/commands/simple/cut.c	(revision 9)
+++ 	(revision )
@@ -1,310 +1,0 @@
-/* cut - extract columns from a file or stdin. 	Author: Michael J. Holme
- *
- *	Copyright 1989, Michael John Holme, All rights reserved.
- *	This code may be freely distributed, provided that this notice
- *	remains intact.
- *
- *	V1.1: 6th September 1989
- *
- *	Bugs, criticisms, etc,
- *      c/o Mark Powell
- *          JANET sq79@uk.ac.liv
- *          ARPA  sq79%liv.ac.uk@nsfnet-relay.ac.uk
- *          UUCP  ...!mcvax!ukc!liv.ac.uk!sq79
- *-------------------------------------------------------------------------
- *	Changed for POSIX1003.2/Draft10 conformance
- *	Thomas Brupbacher (tobr@mw.lpc.ethz.ch), September 1990.
- *	Changes:
- *	    - separation of error messages ( stderr) and output (stdout).
- *	    - support for -b and -n (no effect, -b acts as -c)
- *	    - support for -s
- *-------------------------------------------------------------------------
- */
-
-#include <sys/types.h>
-#include <ctype.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define MAX_FIELD	80	/* Pointers to the beginning of each field
-			 * are stored in columns[], if a line holds
-			 * more than MAX_FIELD columns the array
-			 * boundary is exceed. But unlikely at 80 */
-
-#define MAX_ARGS	32	/* Maximum number of fields following -f or
-			 * -c switches												  	  */
-int args[MAX_ARGS * 2];
-int num_args;
-
-/* Lots of new defines, should easen maintainance...			*/
-#define DUMP_STDIN	0	/* define for mode: no options	 */
-#define OPTIONF		1	/* define for mode: option -f 	 */
-#define OPTIONC		2	/* define for mode: option -c	 */
-#define OPTIONB		3	/* define for mode: option -b	 */
-#define NOTSET		0	/* option not selected		 */
-#define SET		1	/* option selected		 */
-
-/* Defines for the warnings						*/
-#define DELIMITER_NOT_APPLICABLE	0
-#define OVERRIDING_PREVIOUS_MODE	1
-#define OPTION_NOT_APPLICABLE		2
-#define UNKNOWN_OPTION			3
-#define FILE_NOT_READABLE		4
-
-/* Defines for the fatal errors						*/
-#define SYNTAX_ERROR			101
-#define POSITION_ERROR			102
-#define USAGE				103
-#define LINE_TO_LONG_ERROR		104
-#define RANGE_ERROR			105
-#define MAX_FIELDS_EXEEDED_ERROR	106
-#define MAX_ARGS_EXEEDED_ERROR		107
-
-
-int mode;			/* 0 = dump stdin to stdout, 1=-f, 2=-c   */
-int flag_i;			/* SET = -i set on command line	 */
-int flag_s;			/* SET = -s set on command line	 */
-char delim = '\t';		/* default delimiting character	  */
-FILE *fd;
-char *name;
-char line[BUFSIZ];
-int exit_status;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void warn, (int warn_number, char *option));
-_PROTOTYPE(void cuterror, (int err));
-_PROTOTYPE(void get_args, (void));
-_PROTOTYPE(void cut, (void));
-
-void warn(warn_number, option)
-int warn_number;
-char *option;
-{
-  static char *warn_msg[] = {
-			   "%s: Option -d allowed only with -f\n",
-			   "%s: -%s overrides earlier option\n",
-			   "%s: -%s not allowed in current mode\n",
-			   "%s: Cannot open %s\n"
-  };
-
-  fprintf(stderr, warn_msg[warn_number], name, option);
-  exit_status = warn_number + 1;
-
-}
-
-void cuterror(err)
-int err;
-{
-  static char *err_mes[] = {
-			  "%s: syntax error\n",
-			  "%s: position must be >0\n",
-  "%s: usage: cut [-f args [-i] [-d x]]|[-c args] [filename [...]]\n",
-			  "%s: line longer than BUFSIZ\n",
-		 "%s: range must not decrease from left to right\n",
-			  "%s: MAX_FIELD exceeded\n",
-			  "%s: MAX_ARGS exceeded\n"
-  };
-
-  fprintf(stderr, err_mes[err - 101], name);
-  exit(err);
-}
-
-
-void get_args()
-{
-  int i = 0;
-  int arg_ptr = 0;
-  int flag;
-
-  num_args = 0;
-  do {
-	if (num_args == MAX_ARGS) cuterror(MAX_ARGS_EXEEDED_ERROR);
-	if (!isdigit(line[i]) && line[i] != '-') cuterror(SYNTAX_ERROR);
-
-	args[arg_ptr] = 1;
-	args[arg_ptr + 1] = BUFSIZ;
-	flag = 1;
-
-	while (line[i] != ',' && line[i] != 0) {
-		if (isdigit(line[i])) {
-			args[arg_ptr] = 0;
-			while (isdigit(line[i]))
-				args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0';
-			if (!args[arg_ptr]) cuterror(POSITION_ERROR);
-			arg_ptr++;
-		}
-		if (line[i] == '-') {
-			arg_ptr |= 1;
-			i++;
-			flag = 0;
-		}
-	}
-	if (flag && arg_ptr & 1) args[arg_ptr] = args[arg_ptr - 1];
-	if (args[num_args * 2] > args[num_args * 2 + 1])
-		cuterror(RANGE_ERROR);
-	num_args++;
-	arg_ptr = num_args * 2;
-  }
-  while (line[i++]);
-}
-
-
-void cut()
-{
-  int i, j, length, maxcol;
-  char *columns[MAX_FIELD];
-
-  while (fgets(line, BUFSIZ, fd)) {
-	length = strlen(line) - 1;
-	*(line + length) = 0;
-	switch (mode) {
-	    case DUMP_STDIN:	printf("%s", line);	break;
-	    case OPTIONF:
-		maxcol = 0;
-		columns[maxcol++] = line;
-		for (i = 0; i < length; i++) {
-			if (*(line + i) == delim) {
-				*(line + i) = 0;
-				if (maxcol == MAX_FIELD)
-					cuterror(MAX_FIELDS_EXEEDED_ERROR);
-				columns[maxcol] = line + i + 1;
-				while (*(line + i + 1) == delim && flag_i) {
-					columns[maxcol]++;
-					i++;
-				}
-				maxcol++;
-			}
-		}
-		if (maxcol == 1) {
-			if (flag_s != SET) printf("%s", line);
-		} else {
-			for (i = 0; i < num_args; i++) {
-				for (j = args[i * 2]; j <= args[i * 2 + 1]; j++)
-					if (j <= maxcol) {
-						printf("%s", columns[j - 1]);
-						if (i != num_args - 1 || j != args[i * 2 + 1])
-							putchar(delim);
-					}
-			}
-		}
-		break;
-	    case OPTIONC:
-		for (i = 0; i < num_args; i++) {
-			for (j = args[i * 2]; j <= (args[i * 2 + 1] > length ? length :
-					      args[i * 2 + 1]); j++)
-				putchar(*(line + j - 1));
-		}
-	}
-	if (maxcol == 1 && flag_s == SET);
-	else
-		putchar('\n');
-  }
-}
-
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int i = 1;
-  int numberFilenames = 0;
-  name = argv[0];
-
-  if (argc == 1) cuterror(USAGE);
-
-  while (i < argc) {
-	if (argv[i][0] == '-') {
-		switch (argv[i++][1]) {
-		    case 'd':
-			if (mode == OPTIONC || mode == OPTIONB)
-				warn(DELIMITER_NOT_APPLICABLE, "d");
-			delim = argv[i++][0];
-			break;
-		    case 'f':
-			sprintf(line, "%s", argv[i++]);
-			if (mode == OPTIONC || mode == OPTIONB)
-				warn(OVERRIDING_PREVIOUS_MODE, "f");
-			mode = OPTIONF;
-			break;
-		    case 'b':
-			sprintf(line, "%s", argv[i++]);
-			if (mode == OPTIONF || mode == OPTIONC)
-				warn(OVERRIDING_PREVIOUS_MODE, "b");
-			mode = OPTIONB;
-			break;
-		    case 'c':
-			sprintf(line, "%s", argv[i++]);
-			if (mode == OPTIONF || mode == OPTIONB)
-				warn(OVERRIDING_PREVIOUS_MODE, "c");
-			mode = OPTIONC;
-			break;
-		    case 'i':	flag_i = SET;	break;
-		    case 's':	flag_s = SET;	break;
-		    case '\0':	/* - means: read from stdin		 */
-			numberFilenames++;
-			break;
-		    case 'n':	/* needed for Posix, but no effect here	 */
-			if (mode != OPTIONB)
-				warn(OPTION_NOT_APPLICABLE, "n");
-			break;
-		    default:
-			warn(UNKNOWN_OPTION, &(argv[i - 1][1]));
-		}
-	} else {
-		i++;
-		numberFilenames++;
-	}
-  }
-
-/* Here follow the checks, if the selected options are reasonable.	*/
-  if (mode == OPTIONB)		/* since in Minix char := byte		 */
-	mode = OPTIONC;
-/* Flag -s is only allowed with -f, otherwise warn and reset flag_s	*/
-  if (flag_s == SET && (mode == OPTIONB || mode == OPTIONC)) {
-	warn(OPTION_NOT_APPLICABLE, "s");
-	flag_s = NOTSET;
-  }
-
-/* Flag -i is only allowed with -f, otherwise warn and reset flag_i	*/
-  if (flag_i == SET && mode == OPTIONF) {
-	warn(OPTION_NOT_APPLICABLE, "s");
-	flag_i = NOTSET;
-  }
-  get_args();
-  if (numberFilenames != 0) {
-	i = 1;
-	while (i < argc) {
-		if (argv[i][0] == '-') {
-			switch (argv[i][1]) {
-			    case 'f':
-			    case 'c':
-			    case 'b':
-			    case 'd':	i += 2;	break;
-			    case 'n':
-			    case 'i':
-			    case 's':	i++;	break;
-			    case '\0':
-				fd = stdin;
-				i++;
-				cut();
-				break;
-			    default:	i++;
-			}
-		} else {
-			if ((fd = fopen(argv[i++], "r")) == NULL) {
-				warn(FILE_NOT_READABLE, argv[i - 1]);
-			} else {
-				cut();
-				fclose(fd);
-			}
-		}
-	}
-  } else {
-	fd = stdin;
-	cut();
-  }
-
-  return(exit_status);
-}
Index: trunk/minix/commands/simple/date.c
===================================================================
--- trunk/minix/commands/simple/date.c	(revision 9)
+++ 	(revision )
@@ -1,443 +1,0 @@
-/* date - Display (or set) the date and time		Author: V. Archer */
-
-#include <sys/types.h>
-#include <ctype.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <time.h>
-#include <string.h>
-#include <unistd.h>
-
-#define	MIN	60L		/* # seconds in a minute */
-#define	HOUR	(60 * MIN)	/* # seconds in an hour */
-#define	DAY	(24 * HOUR)	/* # seconds in a day */
-#define	YEAR	(365 * DAY)	/* # seconds in a (non-leap) year */
-
-int qflag, uflag, sflag, Sflag;
-
-/* Default output file descriptor.
- */
-int outfd = 1;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void putchar, (int c));
-_PROTOTYPE(void pstring, (char *s, int len));
-_PROTOTYPE(void pldecimal, (unsigned long d, int digits));
-_PROTOTYPE(void pdecimal, (int d, int digits));
-_PROTOTYPE(void fmtdate, (char *format, time_t t, struct tm *p));
-_PROTOTYPE(time_t make_time, (char *t));
-_PROTOTYPE(struct tm *september, (time_t *tp));
-_PROTOTYPE(void usage, (void));
-
-/* Main module. Handles P1003.2 date and system administrator's date. The
- * date entered should be given GMT, regardless of the system's TZ!
- */
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  time_t t;
-  struct tm *tm;
-  char *format;
-  char time_buf[40];
-  int n;
-  int i;
-
-  time(&t);
-
-  i = 1;
-  while (i < argc && argv[i][0] == '-') {
-	char *opt = argv[i++] + 1, *end;
-
-	if (opt[0] == '-' && opt[1] == 0) break;
-
-	while (*opt != 0) switch (*opt++) {
-	case 'q':
-		qflag = 1;
-		break;
-	case 's':
-		sflag = 1;
-		break;
-	case 'u':
-		uflag = 1;
-		break;
-	case 'S':
-		Sflag = 1;
-		break;
-	case 't':
-		/* (obsolete, now -r) */
-	case 'r':
-		if (*opt == 0) {
-			if (i == argc) usage();
-			opt = argv[i++];
-		}
-		t = strtoul(opt, &end, 10);
-		if (*end != 0) usage();
-		opt = "";
-		break;
-	default:
-		usage();
-	}
-  }
-
-  if (!qflag && i < argc && ('0' <= argv[i][0] && argv[i][0] <= '9')) {
-	t = make_time(argv[i++]);
-	sflag = 1;
-  }
-
-  format = "%c";
-  if (i < argc && argv[i][0] == '+') format = argv[i++] + 1;
-
-  if (i != argc) usage();
-
-  if (qflag) {
-	pstring("\nPlease enter date: MMDDYYhhmmss. Then hit the RETURN key.\n", -1);
-	n = read(0, time_buf, sizeof(time_buf));
-	if (n > 0 && time_buf[n-1] == '\n') n--;
-	if (n >= 0) time_buf[n] = 0;
-	t = make_time(time_buf);
-	sflag = 1;
-  }
-
-  if (sflag && stime(&t) != 0) {
-	outfd = 2;
-	pstring("No permission to set time\n", -1);
-	return(1);
-  }
-
-  tm = Sflag ? september(&t) : uflag ? gmtime(&t) : localtime(&t);
-
-  fmtdate(format, t, tm);
-  putchar('\n');
-  return(0);
-}
-
-/* Replacement for stdio putchar().
- */
-void putchar(c)
-int c;
-{
-  static char buf[1024];
-  static char *bp = buf;
-
-  if (c != 0) *bp++ = c;
-  if (c == 0 || c == '\n' || bp == buf + sizeof(buf)) {
-	write(outfd, buf, bp - buf);
-	bp = buf;
-  }
-}
-
-/* Internal function that prints a n-digits number. Replaces stdio in our
- * specific case.
- */
-void pldecimal(d, digits)
-unsigned long d;
-int digits;
-{
-  digits--;
-  if (d > 9 || digits > 0) pldecimal(d / 10, digits);
-  putchar('0' + (d % 10));
-}
-
-void pdecimal(d, digits)
-int d, digits;
-{
-  pldecimal((unsigned long) d, digits);
-}
-
-/* Internal function that prints a fixed-size string. Replaces stdio in our
- * specific case.
- */
-void pstring(s, len)
-char *s;
-int len;
-{
-  while (*s)
-	if (len--)
-		putchar(*s++);
-	else
-		break;
-}
-
-/* Format the date, using the given locale string. A special case is the
- * TZ which might be a sign followed by four digits (New format time zone).
- */
-void fmtdate(format, t, p)
-char *format;
-time_t t;
-struct tm *p;
-{
-  int i;
-  char *s;
-  static char *wday[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
-		       "Thursday", "Friday", "Saturday"};
-  static char *month[] = {"January", "February", "March", "April",
-			"May", "June", "July", "August",
-		    "September", "October", "November", "December"};
-
-  while (*format)
-	if (*format == '%') {
-		switch (*++format) {
-		    case 'A':
-			pstring(wday[p->tm_wday], -1);
-			break;
-		    case 'B':
-			pstring(month[p->tm_mon], -1);
-			break;
-		    case 'D':
-			pdecimal(p->tm_mon + 1, 2);
-			putchar('/');
-			pdecimal(p->tm_mday, 2);
-			putchar('/');
-		    case 'y':
-			pdecimal(p->tm_year % 100, 2);
-			break;
-		    case 'H':
-			pdecimal(p->tm_hour, 2);
-			break;
-		    case 'I':
-			i = p->tm_hour % 12;
-			pdecimal(i ? i : 12, 2);
-			break;
-		    case 'M':
-			pdecimal(p->tm_min, 2);
-			break;
-		    case 'X':
-		    case 'T':
-			pdecimal(p->tm_hour, 2);
-			putchar(':');
-			pdecimal(p->tm_min, 2);
-			putchar(':');
-		    case 'S':
-			pdecimal(p->tm_sec, 2);
-			break;
-		    case 'U':
-			pdecimal((p->tm_yday - p->tm_wday + 13) / 7, 2);
-			break;
-		    case 'W':
-			if (--(p->tm_wday) < 0) p->tm_wday = 6;
-			pdecimal((p->tm_yday - p->tm_wday + 13) / 7, 2);
-			if (++(p->tm_wday) > 6) p->tm_wday = 0;
-			break;
-		    case 'Y':
-			pdecimal(p->tm_year + 1900, 4);
-			break;
-		    case 'Z':
-			if (uflag) {
-				s = "GMT";
-			} else {
-				s = (p->tm_isdst == 1) ? tzname[1] : tzname[0];
-			}
-			pstring(s, strlen(s));
-			break;
-		    case 'a':
-			pstring(wday[p->tm_wday], 3);
-			break;
-		    case 'b':
-		    case 'h':
-			pstring(month[p->tm_mon], 3);
-			break;
-		    case 'c':
-			if (!(s = getenv("LC_TIME")))
-				s = "%a %b %e %T %Z %Y";
-			fmtdate(s, t, p);
-			break;
-		    case 'd':
-			pdecimal(p->tm_mday, 2);
-			break;
-		    case 'e':
-			if (p->tm_mday < 10) putchar(' ');
-			pdecimal(p->tm_mday, 1);
-			break;
-		    case 'j':
-			pdecimal(p->tm_yday + 1, 3);
-			break;
-		    case 'm':
-			pdecimal(p->tm_mon + 1, 2);
-			break;
-		    case 'n':	putchar('\n');	break;
-		    case 'p':
-			if (p->tm_hour < 12)
-				putchar('A');
-			else
-				putchar('P');
-			putchar('M');
-			break;
-		    case 'r':
-			fmtdate("%I:%M:%S %p", t, p);
-			break;
-		    case 's':
-			pldecimal((unsigned long) t, 0);
-			break;
-		    case 't':	putchar('\t');	break;
-		    case 'w':
-			putchar('0' + p->tm_wday);
-			break;
-		    case 'x':
-			fmtdate("%B %e %Y", t, p);
-			break;
-		    case '%':	putchar('%');	break;
-		    case '\0':	format--;
-		}
-		format++;
-	} else
-		putchar(*format++);
-}
-
-/* Convert a local date string into GMT time in seconds. */
-time_t make_time(t)
-char *t;
-{
-  struct tm tm;				/* user specified time */
-  time_t now;				/* current time */
-  int leap;				/* current year is leap year */
-  int i;				/* general index */
-  int fld;				/* number of fields */
-  int f[6];				/* time fields */
-  static int days_per_month[2][12] = {
-  { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
-  { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }};
-
-/* Get current time just in case */
-  now = time((time_t *) 0);
-  tm  = *localtime(&now);
-  tm.tm_sec   = 0;
-  tm.tm_mon++;
-  tm.tm_year %= 100;
-
-/* Parse the time */
-#if '0'+1 != '1' || '1'+1 != '2' || '2'+1 != '3' || '3'+1 != '4' || \
-    '4'+1 != '5' || '5'+1 != '6' || '6'+1 != '7' || '7'+1 != '8' || '8'+1 != '9'
-  << Code unsuitable for character collating sequence >>
-#endif
-
-  for (fld = 0; fld < sizeof(f)/sizeof(f[0]); fld++) {
-	if (*t == 0) break;
-	f[fld] = 0;
-	for (i = 0; i < 2; i++, t++) {
-		if (*t < '0' || *t > '9') usage();
-		f[fld] = f[fld] * 10 + *t - '0';
-	}
-  }
-
-  switch (fld) {
-  case 2:
-	tm.tm_hour = f[0]; tm.tm_min  = f[1]; break;
-
-  case 3:
-	tm.tm_hour = f[0]; tm.tm_min  = f[1]; tm.tm_sec  = f[2];
-	break;
-
-  case 5:
-  	tm.tm_mon  = f[0]; tm.tm_mday = f[1]; tm.tm_year = f[2];
-	tm.tm_hour = f[3]; tm.tm_min  = f[4];
-	break;
-
-  case 6:
-	tm.tm_mon  = f[0]; tm.tm_mday = f[1]; tm.tm_year = f[2];
-	tm.tm_hour = f[3]; tm.tm_min  = f[4]; tm.tm_sec  = f[5];
-	break;
-
-  default:
-	usage();
-  }
-
-/* Convert the time into seconds since 1 January 1970 */
-  if (tm.tm_year < 70)
-    tm.tm_year += 100;
-  leap = (tm.tm_year % 4 == 0 && tm.tm_year % 400 != 0);
-  if (tm.tm_mon  < 1  || tm.tm_mon  > 12 ||
-      tm.tm_mday < 1  || tm.tm_mday > days_per_month[leap][tm.tm_mon-1] ||
-      tm.tm_hour > 23 || tm.tm_min  > 59) {
-    outfd = 2;
-    pstring("Illegal date format\n", -1);
-    exit(1);
-  }
-
-/* Convert the time into Minix time - zone independent code */
-  {
-    time_t utctime;			/* guess at unix time */
-    time_t nextbit;			/* next bit to try */
-    int rv;				/* result of try */
-    struct tm *tmp;			/* local time conversion */
-
-#define COMPARE(a,b)	((a) != (b)) ? ((a) - (b)) :
-
-    utctime = 1;
-    do {
-      nextbit = utctime;
-      utctime = nextbit << 1;
-    } while (utctime >= 1);
-
-    for (utctime = 0; ; nextbit >>= 1) {
-
-      utctime |= nextbit;
-      tmp = localtime(&utctime);
-      if (tmp == 0) continue;
-
-      rv = COMPARE(tmp->tm_year,    tm.tm_year)
-           COMPARE(tmp->tm_mon + 1, tm.tm_mon)
-	   COMPARE(tmp->tm_mday,    tm.tm_mday)
-	   COMPARE(tmp->tm_hour,    tm.tm_hour)
-	   COMPARE(tmp->tm_min,     tm.tm_min)
-	   COMPARE(tmp->tm_sec,     tm.tm_sec)
-	   0;
-
-      if (rv > 0)
-        utctime &= ~nextbit;
-      else if (rv == 0)
-        break;
-
-      if (nextbit == 0) {
-	uflag = 1;
-        outfd = 2;
-        pstring("Inexact conversion to UTC from ", -1);
-        fmtdate("%c\n", utctime, localtime(&utctime) );
-	exit(1);
-      }
-    }
-    return utctime;
-  }
-}
-
-/* Correct the time to the reckoning of Eternal September. */
-struct tm *september(tp)
-time_t *tp;
-{
-  time_t t;
-  int days;
-  struct tm *tm;
-
-  tm = localtime(tp);
-
-  t = *tp - (tm->tm_hour - 12) * 3600L;  /* No zone troubles around noon. */
-  days = 0;
-
-  while (tm->tm_year > 93 || (tm->tm_year == 93 && tm->tm_mon >= 8)) {
-	/* Step back a year or a month. */
-	days += tm->tm_year > 93 ? tm->tm_yday+1 : tm->tm_mday;
-	t = *tp - days * (24 * 3600L);
-
-	tm = localtime(&t);
-  }
-
-  if (days > 0) {
-	tm = localtime(tp);
-	tm->tm_mday = days;
-	tm->tm_year = 93;
-	tm->tm_mon = 8;
-#if SANITY
-	t = mktime(tm);
-	tm = localtime(&t);
-#endif
-  }
-  return tm;
-}
-
-/* (Extended) Posix prototype of date. */
-void usage()
-{
-  outfd = 2;
-  pstring("Usage: date [-qsuS] [-r seconds] [[MMDDYY]hhmm[ss]] [+format]\n", -1);
-  exit(1);
-}
Index: trunk/minix/commands/simple/dd.c
===================================================================
--- trunk/minix/commands/simple/dd.c	(revision 9)
+++ 	(revision )
@@ -1,394 +1,0 @@
-/* dd - disk dumper */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#define EOS '\0'
-#define BOOLEAN int
-#define TRUE 1
-#define FALSE 0
-
-char *pch, *errorp;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(BOOLEAN is, (char *pc));
-_PROTOTYPE(int num, (void));
-_PROTOTYPE(void puto, (void));
-_PROTOTYPE(void statistics, (void));
-_PROTOTYPE(int ulcase, (int c));
-_PROTOTYPE(void cnull, (int c));
-_PROTOTYPE(void null, (int c));
-_PROTOTYPE(void extra, (void));
-_PROTOTYPE(void over, (int dummy));
-
-BOOLEAN is(pc)
-char *pc;
-{
-  register char *ps = pch;
-
-  while (*ps++ == *pc++)
-	if (*pc == EOS) {
-		pch = ps;
-		return(TRUE);
-	}
-  return(FALSE);
-}
-
-#define BIGNUM  2147483647
-
-int num()
-{
-  long ans;
-  register char *pc;
-
-  pc = pch;
-  ans = 0L;
-  while ((*pc >= '0') && (*pc <= '9'))
-	ans = (long) ((*pc++ - '0') + (ans * 10));
-  while (TRUE) switch (*pc++) {
-	    case 'w':
-		ans *= 2L;
-		continue;
-	    case 'b':
-		ans *= 512L;
-		continue;
-	    case 'k':
-		ans *= 1024L;
-		continue;
-	    case 'x':
-		pch = pc;
-		ans *= (long) num();
-	    case EOS:
-		if ((ans >= BIGNUM) || (ans < 0)) {
-			fprintf(stderr, "dd: argument %s out of range\n",
-				errorp);
-			exit(1);
-		}
-		return((int) ans);
-	}
-}
-
-#define SWAB 0x0001
-#define LCASE 0x0002
-#define UCASE 0x0004
-#define NOERROR 0x0008
-#define SYNC 0x0010
-#define SILENT 0x0020
-#define BLANK ' '
-#define DEFAULT 512
-
-unsigned cbs, bs, skip, nseek, count;
-int seekseen = FALSE;
-unsigned ibs = DEFAULT;
-unsigned obs = DEFAULT;
-unsigned files = 1;
-char *ifilename = NULL;
-char *ofilename = NULL;
-
-int convflag = 0;
-int flag = 0;
-int ifd, ofd, ibc;
-char *ibuf, *obuf, *op;
-unsigned nifull, nipartial, nofull, nopartial;
-int cbc;
-unsigned ntr, obc;
-int ns;
-char mlen[] = {64, 45, 82, 45, 83, 96, 109, 100, 109, 97, 96, 116, 108, 9};
-
-void puto()
-{
-  int n;
-
-  if (obc == 0) return;
-  if (obc == obs)
-	nofull++;
-  else
-	nopartial++;
-  if ((n = write(ofd, obuf, obc)) != obc) {
-	if (n == -1) {
-		fprintf(stderr, "dd: Write error: %s\n", strerror(errno));
-	} else {
-		fprintf(stderr, "dd: Short write, %d instead of %d\n", n, obc);
-	}
-	exit(1);
-  }
-  obc = 0;
-}
-
-void statistics()
-{
-  if (convflag & SILENT) return;
-  fprintf(stderr, "%u+%u records in\n", nifull, nipartial);
-  fprintf(stderr, "%u+%u records out\n", nofull, nopartial);
-  if (ntr) fprintf(stderr, "%d truncated records\n", ntr);
-}
-
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-#ifdef __STDC__
-  void (*convert) (int);
-#else
-  void (*convert) ();
-#endif
-  char *iptr;
-  int i, j;
-
-  convert = null;
-  argc--;
-  argv++;
-  while (argc-- > 0) {
-	pch = *(argv++);
-	if (is("ibs=")) {
-		errorp = pch;
-		ibs = num();
-		continue;
-	}
-	if (is("obs=")) {
-		errorp = pch;
-		obs = num();
-		continue;
-	}
-	if (is("bs=")) {
-		errorp = pch;
-		bs = num();
-		continue;
-	}
-	if (is("if=")) {
-		ifilename = pch;
-		continue;
-	}
-	if (is("of=")) {
-		ofilename = pch;
-		continue;
-	}
-	if (is("skip=")) {
-		errorp = pch;
-		skip = num();
-		continue;
-	}
-	if (is("seek=")) {
-		errorp = pch;
-		nseek = num();
-		seekseen = TRUE;
-		continue;
-	}
-	if (is("count=")) {
-		errorp = pch;
-		count = num();
-		continue;
-	}
-	if (is("files=")) {
-		errorp = pch;
-		files = num();
-		continue;
-	}
-	if (is("length=")) {
-		errorp = pch;
-		for (j = 0; j < 13; j++) mlen[j]++;
-		write(2, mlen, 14);
-		continue;
-	}
-	if (is("conv=")) {
-		while (*pch != EOS) {
-			if (is("lcase")) {
-				convflag |= LCASE;
-				continue;
-			}
-			if (is("ucase")) {
-				convflag |= UCASE;
-				continue;
-			}
-			if (is("noerror")) {
-				convflag |= NOERROR;
-				continue;
-			}
-			if (is("sync")) {
-				convflag |= SYNC;
-				continue;
-			}
-			if (is("swab")) {
-				convflag |= SWAB;
-				continue;
-			}
-			if (is("silent")) {
-				convflag |= SILENT;
-				continue;
-			}
-			if (is(",")) continue;
-			fprintf(stderr, "dd: bad argument: %s\n",
-				pch);
-			exit(1);
-		}
-		if (*pch == EOS) continue;
-	}
-	fprintf(stderr, "dd: bad argument: %s\n", pch);
-	exit(1);
-  }
-  if ((convert == null) && (convflag & (UCASE | LCASE))) convert = cnull;
-  if ((ifd = ((ifilename) ? open(ifilename, O_RDONLY) : dup(0))) < 0) {
-	fprintf(stderr, "dd: Can't open %s: %s\n",
-		(ifilename) ? ifilename : "stdin", strerror(errno));
-	exit(1);
-  }
-  if ((ofd = ((ofilename) ? open(ofilename, seekseen ? O_WRONLY | O_CREAT
-					: O_WRONLY | O_CREAT | O_TRUNC, 0666)
-			: dup(1))) < 0) {
-	fprintf(stderr, "dd: Can't open %s: %s\n",
-		(ofilename) ? ofilename : "stdout", strerror(errno));
-	exit(1);
-  }
-  if (bs) {
-	ibs = obs = bs;
-	if (convert == null) flag++;
-  }
-  if (ibs == 0) {
-	fprintf(stderr, "dd: ibs cannot be zero\n");
-	exit(1);
-  }
-  if (obs == 0) {
-	fprintf(stderr, "dd: obs cannot be zero\n");
-	exit(1);
-  }
-  if ((ibuf = sbrk(ibs)) == (char *) -1) {
-	fprintf(stderr, "dd: not enough memory\n");
-	exit(1);
-  }
-  if ((obuf = (flag) ? ibuf : sbrk(obs)) == (char *) -1) {
-	fprintf(stderr, "dd: not enough memory\n");
-	exit(1);
-  }
-  ibc = obc = cbc = 0;
-  op = obuf;
-  if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, over);
-  if (skip != 0) {
-	struct stat st;
-	if (fstat(ifd,&st) < 0 || !(S_ISREG(st.st_mode) || S_ISBLK(st.st_mode))
-	   || lseek(ifd, (off_t) ibs * (off_t) skip, SEEK_SET) == (off_t) -1) {
-		do {
-			if (read(ifd, ibuf, ibs) == -1) {
-				fprintf(stderr,
-					"dd: Error skipping input: %s\n",
-					strerror(errno));
-				exit(1);
-			}
-		} while (--skip != 0);
-	}
-  }
-  if (nseek != 0) {
-	if (lseek(ofd, (off_t) obs * (off_t) nseek, SEEK_SET) == (off_t) -1) {
-		fprintf(stderr, "dd: Seeking on output failed: %s\n",
-			strerror(errno));
-		exit(1);
-	}
-  }
-
-outputall:
-  if (ibc-- == 0) {
-	ibc = 0;
-	if ((count == 0) || ((nifull + nipartial) != count)) {
-		if (convflag & (NOERROR | SYNC))
-			for (iptr = ibuf + ibs; iptr > ibuf;) *--iptr = 0;
-		ibc = read(ifd, ibuf, ibs);
-	}
-	if (ibc == -1) {
-		fprintf(stderr, "dd: Read error: %s\n", strerror(errno));
-		if ((convflag & NOERROR) == 0) {
-			puto();
-			over(0);
-		}
-		ibc = 0;
-		for (i = 0; i < ibs; i++)
-			if (ibuf[i] != 0) ibc = i;
-		statistics();
-	}
-	if ((ibc == 0) && (--files <= 0)) {
-		puto();
-		over(0);
-	}
-	if (ibc != ibs) {
-		nipartial++;
-		if (convflag & SYNC) ibc = ibs;
-	} else
-		nifull++;
-	iptr = ibuf;
-	i = ibc >> 1;
-	if ((convflag & SWAB) && i) do {
-			int temp;
-			temp = *iptr++;
-			iptr[-1] = *iptr;
-			*iptr++ = temp;
-		} while (--i);
-	iptr = ibuf;
-	if (flag) {
-		obc = ibc;
-		puto();
-		ibc = 0;
-	}
-	goto outputall;
-  }
-  i = *iptr++ & 0377;
-  (*convert) (i);
-  goto outputall;
-}
-
-int ulcase(c)
-int c;
-{
-  int ans = c;
-
-  if ((convflag & UCASE) && (c >= 'a') &&
-      (c <= 'z'))
-	ans += 'A' - 'a';
-  if ((convflag & LCASE) && (c >= 'A') &&
-      (c <= 'Z'))
-	ans += 'a' - 'A';
-  return(ans);
-}
-
-void cnull(c)
-int c;
-{
-  c = ulcase(c);
-  null(c);
-}
-
-void null(c)
-int c;
-{
-  *op++ = c;
-  if (++obc >= obs) {
-	puto();
-	op = obuf;
-  }
-}
-
-void extra()
-{
-  if (++cbc >= cbs) {
-	null('\n');
-	cbc = 0;
-	ns = 0;
-  }
-}
-
-void over(sig)
-int sig;
-{
-  statistics();
-  if (sig != 0) {
-	signal(sig, SIG_DFL);
-	raise(sig);
-  }
-  exit(0);
-}
Index: trunk/minix/commands/simple/decomp16.c
===================================================================
--- trunk/minix/commands/simple/decomp16.c	(revision 9)
+++ 	(revision )
@@ -1,444 +1,0 @@
-/* decomp16: decompress 16bit compressed files on a 16bit Intel processor
- *
- * Version 1.3 of 25 Mar 92.
- *
- * This was written by John N. White on 6/30/91 and is Public Domain.
- * Patched to run under news by Will Rose, Feb 92.
- * J N White's (earlier) patches added by Will Rose, 20 Feb 92.
- * Unsigned int increment/wrap bug fixed by Will Rose, 24 Mar 92.
- * Argument bug fixed, stdio generalised by Will Rose, 25 Mar 92.
- *
- * decomp16 can use as as little as 512 bytes of stack; since it forks
- * four additional copies, it's probably worth using minimum stack rather
- * than the 8192 byte Minix default.  To reduce memory still further,
- * change BUFSZ below to 256; it is currently set to 1024 for speed.  The
- * minimal decomp16 needs about 280k to run in pipe mode (56k per copy).
- *
- * This program acts as a filter:
- *    decomp16 < compressed_file > decompressed_file
- * The arguments -0 to -4 run only the corresponding pass.
- * Thus:
- *    decomp16 -4 < compressed_file > 3;
- *    decomp16 -3 < 3 > 2;
- *    decomp16 -2 < 2 > 1;
- *    decomp16 -1 < 1 > 0;
- *    decomp16 -0 < 0 > decompressed_file
- * will also work, as will connecting the passes by explicit pipes if
- * there is enough memory to do so.  File name arguments can also be
- * given directly on the command line.
- *
- * Compress uses a modified LZW compression algorithm. A compressed file
- * is a set of indices into a dictionary of strings. The number of bits
- * used to store each index depends on the number of entries currently
- * in the dictionary. If there are between 257 and 512 entries, 9 bits
- * are used. With 513 entries, 10 bits are used, etc. The initial dictionary
- * consists of 0-255 (which are the corresponding chars) and 256 (which
- * is a special CLEAR code). As each index in the compressed file is read,
- * a new entry is added to the dictionary consisting of the current string
- * with the first char of the next string appended. When the dictionary
- * is full, no further entries are added. If a CLEAR code is received,
- * the dictionary will be completely reset. The first two bytes of the
- * compressed file are a magic number, and the third byte indicates the
- * maximum number of bits, and whether the CLEAR code is used (older versions
- * of compress didn't have CLEAR).
- *
- * This program works by forking four more copies of itself. The five
- * programs form a pipeline. Copy 0 writes to stdout, and forks copy 1
- * to supply its input, which in turn forks and reads from copy 2, etc.
- * This sequence is used so that when the program exits, all writes
- * are completed and a program that has exec'd uncompress (such as news)
- * can immediately use the uncompressed data when the wait() call returns.
- *
- * If given a switch -#, where # is a digit from 0 to 4 (example: -2), the
- * program will run as that copy, reading from stdin and writing to stdout.
- * This allows decompressing with very limited RAM because only one of the
- * five passes is in memory at a time.
- *
- * The compressed data is a series of string indices (and a header at
- * the beginning and an occasional CLEAR code). As these indices flow
- * through the pipes, each program decodes the ones it can. The result
- * of each decoding will be indices that the following programs can handle.
- *
- * Each of the 65536 strings in the dictionary is an earlier string with
- * some character added to the end (except for the the 256 predefined
- * single char strings). When new entries are made to the dictionary,
- * the string index part will just be the last index to pass through.
- * But the char part is the first char of the next string, which isn't
- * known yet. So the string can be stored as a pair of indices. When
- * this string is specified, it is converted to this pair of indices,
- * which are flagged so that the first will be decoded in full while
- * the second will be decoded to its first char. The dictionary takes
- * 256k to store (64k strings of 2 indices of 2 bytes each). This is
- * too big for a 64k data segment, so it is divided into 5 equal parts.
- * Copy 4 of the program maintains the high part and copy 0 holds the
- * low part.
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#define BUFSZ		1024	/* size of i/o buffers */
-#define BUFSZ_2		(BUFSZ/2)	/* # of unsigned shorts in i/o bufs */
-#define DICTSZ		(unsigned)13056	/* # of local dictionary entries */
-#define EOF_INDEX	(unsigned short)0xFFFF	/* EOF flag for pipeline */
-#define FALSE		0
-#define TRUE		~FALSE
-
-int fdin, fdout, fderr;		/* input, output, and error file descriptors */
-int ibufstart, obufind, ibufend;/* i/o buffer indices */
-int ipbufind = BUFSZ_2;		/* pipe buffer indices */
-int opbufind = 0;
-int pnum = -1;			/* ID of this copy */
-unsigned short ipbuf[BUFSZ_2];	/* for buffering input */
-unsigned short opbuf[BUFSZ_2];	/* for buffering output */
-unsigned char *ibuf = (unsigned char *) ipbuf;
-unsigned char *obuf = (unsigned char *) opbuf;
-
-unsigned short dindex[DICTSZ];	/* dictionary: index to substring */
-unsigned short dchar[DICTSZ];	/* dictionary: last char of string */
-unsigned iindex, tindex, tindex2;	/* holds index being processed */
-unsigned base;			/* where in global dict local dict starts */
-unsigned tbase;
-unsigned locend;		/* where in global dict local dict ends */
-unsigned curend = 256;		/* current end of global dict */
-unsigned maxend;		/* max end of global dict */
-int dcharp;			/* ptr to dchar that needs next index entry */
-int curbits;			/* number of bits for getbits() to read */
-int maxbits;			/* limit on number of bits */
-int clearflg;			/* if set, allow CLEAR */
-int inmod;			/* mod 8 for getbits() */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void ffork, (void));
-_PROTOTYPE(void die, (char *s));
-_PROTOTYPE(void myputc, (unsigned c));
-_PROTOTYPE(unsigned mygetc, (void));
-_PROTOTYPE(void getbits, (void));
-_PROTOTYPE(void getpipe, (void));
-_PROTOTYPE(void putpipe, (unsigned u, int flag));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  char c, *cp;
-  int j, k, fdtmp;
-  unsigned int len;
-
-  /* Find the program name */
-  j = 0;
-  while (argv[0][j] != '\0') j++;
-  len = (unsigned int) j;
-  while (j--)
-	if (argv[0][j] == '/') break;
-  if (argv[0][j] == '/') j++;
-  cp = argv[0] + j;
-  len -= j;
-
-  /* Sort out the flags */
-  for (k = 1; k < argc; k++) {
-	if (argv[k][0] == '-') {
-		c = argv[k][1];
-		switch (c) {
-		    case '0':	/* pass numbers */
-		    case '1':
-		    case '2':
-		    case '3':
-		    case '4':	pnum = c - '0';	break;
-		    case 'd':	/* used by news */
-			break;
-		    default:
-			(void) write(1, "Usage: ", 7);
-			(void) write(1, cp, len);
-			(void) write(1, " [-#] [in] [out]\n", 17);
-			exit(0);
-			break;
-		}
-
-		/* Once it's checked, lose it anyway */
-		for (j = k; j < argc; j++) argv[j] = argv[j + 1];
-		argc--;
-		k--;
-	}
-  }
-
-  /* Default i/o settings */
-  fdin = 0;
-  fdout = 1;
-  fderr = 2;
-
-  /* Try to open specific files and connect them to stdin/stdout */
-  if (argc > 1) {
-	if ((fdtmp = open(argv[1], 0)) == -1) die("input open failed");
-	(void) close(0);
-	if ((fdin = dup(fdtmp)) == -1) die("input dup failed\n");
-	(void) close(fdtmp);
-  }
-  if (argc > 2) {
-	(void) unlink(argv[2]);
-	if ((fdtmp = creat(argv[2], 0666)) == -1) die("output creat failed");
-	(void) close(1);
-	if ((fdout = dup(fdtmp)) == -1) die("output dup failed\n");
-	(void) close(fdtmp);
-  }
-
-  /* Sort out type of compression */
-  if (pnum == -1 || pnum == 4) {/* if this is pass 4 */
-	/* Check header of compressed file */
-	if (mygetc() != 0x1F || mygetc() != 0x9D)      /* check magic number */
-		die("not a compressed file\n");
-	iindex = mygetc();	/* get compression style */
-  } else
-	getpipe();		/* get compression style */
-
-  maxbits = iindex & 0x1F;
-  clearflg = ((iindex & 0x80) != 0) ? TRUE : FALSE;
-  if (maxbits < 9 || maxbits > 16)	/* check for valid maxbits */
-	die("can't decompress\n");
-  if (pnum != -1 && pnum != 0)
-	putpipe(iindex, 0);	/* pass style to next copy */
-
-  /* Fork off an ancestor if necessary - ffork() increments pnum */
-  if (pnum == -1) {
-	pnum = 0;
-	if (pnum == 0) ffork();
-	if (pnum == 1) ffork();
-	if (pnum == 2) ffork();
-	if (pnum == 3) ffork();
-  }
-
-  /* Preliminary inits. Note: end/maxend/curend are highest, not
-   * highest + 1 */
-  base = DICTSZ * pnum + 256;
-  locend = base + DICTSZ - 1;
-  maxend = (1 << maxbits) - 1;
-  if (maxend > locend) maxend = locend;
-
-  while (TRUE) {
-	curend = 255 + (clearflg ? 1 : 0);	/* init dictionary */
-	dcharp = DICTSZ;	/* flag for none needed */
-	curbits = 9;		/* init curbits (for copy 0) */
-	while (TRUE) {		/* for each index in input */
-		if (pnum == 4) {/* get index using getbits() */
-			if (curbits < maxbits && (1 << curbits) <= curend) {
-				/* Curbits needs to be increased */
-				/* Due to uglyness in compress, these
-				 * indices in the compressed file are
-				 * wasted */
-				while (inmod) getbits();
-				curbits++;
-			}
-			getbits();
-		} else
-			getpipe();	/* get next index */
-
-		if (iindex == 256 && clearflg) {
-			if (pnum > 0) putpipe(iindex, 0);
-			/* Due to uglyness in compress, these indices
-			 * in the compressed file are wasted */
-			while (inmod) getbits();
-			break;
-		}
-		tindex = iindex;
-		/* Convert the index part, ignoring spawned chars */
-		while (tindex >= base) tindex = dindex[tindex - base];
-		/* Pass on the index */
-		putpipe(tindex, 0);
-		/* Save the char of the last added entry, if any */
-		if (dcharp < DICTSZ) dchar[dcharp++] = tindex;
-		if (curend < maxend && ++curend > (base - 1))
-			dindex[dcharp = (curend - base)] = iindex;
-
-		/* Do spawned chars. They are naturally produced in
-		 * the wrong order. To get them in the right order
-		 * without using memory, a series of passes,
-		 * progressively less deep, are used */
-		tbase = base;
-		while ((tindex = iindex) >= tbase) {/* for each char to spawn*/
-			while ((tindex2 = dindex[tindex - base]) >= tbase)
-				tindex = tindex2;    /* scan to desired char */
-			putpipe(dchar[tindex-base], 1); /* put it to the pipe*/
-			tbase = tindex + 1;
-			if (tbase == 0) break;	/* it's a wrap */
-		}
-	}
-  }
-}
-
-
-/* F f o r k
- *
- * Fork off the previous pass - the parent reads from the child.
- */
-void ffork()
-{
-  int j, pfd[2];
-
-  if (pipe(pfd) == -1) die("pipe() error\n");
-  if ((j = fork()) == -1) die("fork() error\n");
-  if (j == 0) {			/* this is the child */
-	if (close(1) == -1) die("close(1) error\n");
-	if (dup(pfd[1]) != 1) die("dup(1) error\n");
-	(void) close(pfd[0]);
-	pnum++;
-  } else {			/* this is the parent */
-	if (close(0) == -1) die("close(0) error\n");
-	if (dup(pfd[0]) != 0) die("dup(0) error\n");
-	(void) close(pfd[1]);
-  }
-}
-
-
-/* D i e
- *
- * If s is a message, write it to stderr. Flush buffers if needed. Then exit.
- */
-void die(s)
-char *s;
-{
-  /* Flush stdout buffer if needed */
-  if (obufind != 0) {
-	if (write(fdout, (char *) obuf, (unsigned) obufind) != obufind)
-		s = "bad stdout write\n";
-	obufind = 0;
-  }
-
-  /* Flush pipe if needed */
-  do
-	putpipe(EOF_INDEX, 0);
-  while (opbufind);
-  /* Write any error message */
-  if (s != (char *) NULL) {
-	while (*s) (void) write(fderr, s++, 1);
-  }
-  exit((s == (char *) NULL) ? 0 : 1);
-}
-
-
-/* M p u t c
- *
- * Put a char to stdout.
- */
-void myputc(c)
-unsigned c;
-{
-  obuf[obufind++] = c;
-  if (obufind >= BUFSZ) {	/* if stdout buffer full */
-	if (write(fdout, (char *) obuf, BUFSZ) != BUFSZ)	/* flush to stdout */
-		die("bad stdout write\n");
-	obufind = 0;
-  }
-}
-
-
-/* M y g e t c
- *
- * Get a char from stdin. If EOF, then die() and exit.
- */
-unsigned mygetc()
-{
-  if (ibufstart >= ibufend) {	/* if stdin buffer empty */
-	if ((ibufend = read(fdin, (char *) ibuf, BUFSZ)) <= 0)
-		die((char *) NULL);	/* if EOF, do normal exit */
-	ibufstart = 0;
-  }
-  return(ibuf[ibufstart++] & 0xff);
-}
-
-
-/* G e t b i t s
- *
- * Put curbits bits into index from stdin. Note: only copy 4 uses this.
- * The bits within a byte are in the correct order. But when the bits
- * cross a byte boundry, the lowest bits will be in the higher part of
- * the current byte, and the higher bits will be in the lower part of
- * the next byte.
- */
-void getbits()
-{
-  int have;
-  static unsigned curbyte;	/* byte having bits extracted from it */
-  static int left;		/* how many bits are left in curbyte */
-
-  inmod = (inmod + 1) & 7;	/* count input mod 8 */
-  iindex = curbyte;
-  have = left;
-  if (curbits - have > 8) {
-	iindex |= mygetc() << have;
-	have += 8;
-  }
-  iindex |= ((curbyte = mygetc()) << have) & ~((unsigned) 0xFFFF << curbits);
-  curbyte >>= curbits - have;
-  left = 8 - (curbits - have);
-}
-
-
-/* G e t p i p e
- *
- * Get an index from the pipeline. If flagged firstonly, handle it here.
- */
-void getpipe()
-{
-  static short flags;
-  static int n = 0;		/* number of flags in flags */
-
-  while (TRUE) {		/* while index with firstonly flag set */
-	if (n <= 0) {
-		if (ipbufind >= BUFSZ_2) {	/* if pipe input buffer
-						 * empty */
-			if (read(fdin, (char *) ipbuf, BUFSZ) != BUFSZ)
-				die("bad pipe read\n");
-			ipbufind = 0;
-		}
-		flags = ipbuf[ipbufind++];
-		n = 15;
-	}
-	iindex = ipbuf[ipbufind++];
-	if (iindex > curend)
-		die((iindex == EOF_INDEX) ? (char *) NULL : "invalid data\n");
-	flags <<= 1;
-	n--;
-	/* Assume flags < 0 if highest remaining flag is set */
-	if (flags < 0) {	/* if firstonly flag for index is not set */
-		while (iindex >= base) iindex = dindex[iindex - base];
-		putpipe(iindex, 1);
-	} else
-		return;		/* return with valid non-firstonly index */
-  }
-}
-
-
-/* P u t p i p e
- *
- * put an index into the pipeline.
- */
-void putpipe(u, flag)
-unsigned u;
-int flag;
-{
-  static unsigned short flags, *flagp;
-  static int n = 0;		/* number of flags in flags */
-
-  if (pnum == 0) {		/* if we should write to stdout */
-	myputc(u);		/* index will be the char value */
-	return;
-  }
-  if (n == 0) {			/* if we need to reserve a flag entry */
-	flags = 0;
-	flagp = opbuf + opbufind;
-	opbufind++;
-  }
-  opbuf[opbufind++] = u;	/* add index to buffer */
-  flags = (flags << 1) | flag;	/* add firstonly flag */
-  if (++n >= 15) {		/* if block of 15 indices */
-	n = 0;
-	*flagp = flags;		/* insert flags entry */
-	if (opbufind >= BUFSZ_2) {	/* if pipe out buffer full */
-		opbufind = 0;
-		if (write(fdout, (char *) opbuf, BUFSZ) != BUFSZ)
-			die("bad pipe write\n");
-	}
-  }
-}
Index: trunk/minix/commands/simple/dev2name.c
===================================================================
--- trunk/minix/commands/simple/dev2name.c	(revision 9)
+++ 	(revision )
@@ -1,54 +1,0 @@
-
-/* Translate internal FS device number to a /dev/ name. */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <unistd.h>
-
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <minix/config.h>
-#include <minix/const.h>
-
-#define PATH_DEV "/dev"
-
-int
-main(int argc, char *argv[])
-{
-	DIR *dev;
-	struct dirent *e;
-	int dev_n;
-	if(argc <= 1 || argc > 3) {
-		fprintf(stderr, "Usage: \n"
-			"%s <major> <minor>\n"
-			"%s <devicenumber>\n", argv[0], argv[0]);
-		return 1;
-	} else if(argc == 2) dev_n = atoi(argv[1]);
-	else if(argc == 3) dev_n = (atoi(argv[1]) << MAJOR) | atoi(argv[2]);
-
-	if(chdir(PATH_DEV) < 0) {
-		perror(PATH_DEV " chdir");
-		return 1;
-	}
-
-	if(!(dev=opendir("."))) {
-		perror(". in " PATH_DEV);
-		return 1;
-	}
-
-	while((e=readdir(dev))) {
-		struct stat st;
-		if(stat(e->d_name, &st) < 0) {
-			continue;
-		}
-		if((st.st_mode & (S_IFBLK | S_IFCHR)) && dev_n == st.st_rdev) {
-			printf("%s/%s\n", PATH_DEV, e->d_name);
-			return 0;
-		}
-	}
-
-	return 1;
-}
-
Index: trunk/minix/commands/simple/devsize.c
===================================================================
--- trunk/minix/commands/simple/devsize.c	(revision 9)
+++ 	(revision )
@@ -1,57 +1,0 @@
-/* Ben Gras
- *
- * Based on sizeup() in mkfs.c.
- */
-
-#include <sys/types.h>
-#include <sys/dir.h>
-#include <sys/stat.h>
-#include <ibm/partition.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <sys/ioc_disk.h>
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-unsigned long sizeup(char *);
-
-int main(int argc, char *argv[])
-{
-  int sec;
-
-  if(argc != 2) {
-	fprintf(stderr, "Usage: %s <device>\n", argv[0]);
-	return 1;
-  }
-
-  printf("%lu\n", sizeup(argv[1]));
-  return 0;
-}	
-
-
-unsigned long sizeup(device)
-char *device;
-{
-  int fd;
-  struct partition entry;
-  unsigned long d;
-  struct stat st;
-
-  if ((fd = open(device, O_RDONLY)) == -1) {
-  	perror("sizeup open");
-  	exit(1);
-  }
-  if (ioctl(fd, DIOCGETP, &entry) == -1) {
-  	perror("sizeup ioctl");
-  	exit(1);
-  }
-  close(fd);
-  d = div64u(entry.size, 512);
-  return d;
-}
Index: trunk/minix/commands/simple/df.c
===================================================================
--- trunk/minix/commands/simple/df.c	(revision 9)
+++ 	(revision )
@@ -1,442 +1,0 @@
-/* df - disk free block printout	Author: Andy Tanenbaum
- *
- * 91/04/30 Kees J. Bot (kjb@cs.vu.nl)
- *	Map filename arguments to the devices they live on.
- *	Changed output to show percentages.
- *
- * 92/12/12 Kees J. Bot
- *	Posixized.  (Almost, the normal output is in kilobytes, it should
- *	be 512-byte units.  'df -P' and 'df -kP' are as it should be.)
- *
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <limits.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#if __minix_vmd
-#include <sys/mnttab.h>
-#else
-#include <minix/minlib.h>
-#endif
-
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include <servers/fs/const.h>
-#include <servers/fs/type.h>
-#include <servers/fs/super.h>
-#undef printf
-
-#if !__minix_vmd
-/* Map Minix-vmd names to Minix names. */
-#define v12_super_block		super_block
-#define SUPER_V1		SUPER_MAGIC
-
-#endif
-
-#define ISDISK(mode)	S_ISBLK(mode)	/* || S_ISCHR for raw device??? */
-
-extern int errno;
-char MTAB[] = "/etc/mtab";
-
-struct mtab {	/* List of mounted devices from /etc/mtab. */
-	struct mtab	*next;
-	dev_t		device;
-	char		*devname;
-	char		*mountpoint;
-} *mtab= NULL;
-
-struct mtab *searchtab(char *name);
-void readmtab(char *type);
-int df(const struct mtab *mt);
-bit_t bit_count(unsigned blocks, bit_t bits, int fd, int bs);
-
-int iflag= 0;	/* Focus on inodes instead of blocks. */
-int Pflag= 0;	/* Posix standard output. */
-int kflag= 0;	/* Output in kilobytes instead of 512 byte units for -P. */
-int istty;	/* isatty(1) */
-uid_t ruid, euid;	/* To sometimes change identities. */
-gid_t rgid, egid;
-
-void usage(void)
-{
-	fprintf(stderr, "Usage: df [-ikP] [-t type] [device]...\n");
-	exit(1);
-}
-
-int unitsize;
-
-int main(int argc, char *argv[])
-{
-  int i;
-  struct mtab *mt;
-  char *type= "dev";
-  int ex= 0;
-
-  while (argc > 1 && argv[1][0] == '-') {
-  	char *opt= argv[1]+1;
-
-  	while (*opt != 0) {
-  		switch (*opt++) {
-  		case 'i':	iflag= 1;	break;
-  		case 'k':	kflag= 1;	break;
-  		case 'P':	Pflag= 1;	break;
-  		case 't':
-			if (argc < 3) usage();
-			type= argv[2];
-			argv++;
-			argc--;
-			break;
-		default:
-			usage();
-		}
-	}
-	argc--;
-	argv++;
-  }
-
-  istty= isatty(1);
-  ruid= getuid(); euid= geteuid();
-  rgid= getgid(); egid= getegid();
-
-  readmtab(type);
- 
-  if(!Pflag || (Pflag && kflag)) unitsize = 1024;
-  else unitsize = 512;
-
-  if (Pflag) {
-	printf(!iflag ? "\
-Filesystem    %4d-blocks      Used    Available  Capacity  Mounted on\n" : "\
-Filesystem         Inodes       IUsed      IFree    %%IUsed    Mounted on\n",
-		unitsize);
-  } else {
-	printf("%s\n", !iflag ? "\
-Filesystem      Size (kB)       Free       Used    % Files%   Mounted on" : "\
-Filesystem          Files       Free       Used    % BUsed%   Mounted on"
-	);
-  }
-
-  if (argc == 1) {
-	for (mt= mtab; mt != NULL; mt= mt->next) ex |= df(mt);
-  } else {
-	for (i = 1; i < argc; i++) ex |= df(searchtab(argv[i]));
-  }
-  exit(ex);
-}
-
-void readmtab(char *type)
-/* Turn the mounted file table into a list. */
-{
-  struct mtab **amt= &mtab, *new;
-  struct stat st;
-
-#if __minix_vmd
-  char *devname, *mountpoint;
-  FILE *mtf;
-  struct mnttab mte, look;
-
-  if ((mtf= fopen(MTAB, "r")) == NULL) {
-	fprintf(stderr, "df: can't open %s\n", MTAB);
-	return;
-  }
-
-  look.mnt_special= NULL;
-  look.mnt_mountp= NULL;
-  look.mnt_fstype= type;
-  look.mnt_mntopts= NULL;
-
-  while (getmntany(mtf, &mte, &look) >= 0) {
-  	devname= mte.mnt_special;
-  	mountpoint= mte.mnt_mountp;
-
-		/* Skip bad entries, can't complain about everything. */
-	if (stat(devname, &st) < 0 || !ISDISK(st.st_mode)) continue;
-
-		/* Make new list cell. */
-	if ((new= (struct mtab *) malloc(sizeof(*new))) == NULL
-	  || (new->devname= (char *) malloc(strlen(devname) + 1)) == NULL
-	  || (new->mountpoint= (char *) malloc(strlen(mountpoint) + 1)) == NULL
-	) break;
-
-	new->device= st.st_rdev;
-	strcpy(new->devname, devname);
-	strcpy(new->mountpoint, mountpoint);
-
-	*amt= new;		/* Add the cell to the end. */
-	amt= &new->next;
-	*amt= NULL;
-  }
-  fclose(mtf);
-
-#else /* __minix */
-  char devname[128], mountpoint[128], version[10], rw_flag[10];
-
-  if (load_mtab("df") < 0) exit(1);
-
-  while (get_mtab_entry(devname, mountpoint, version, rw_flag),
-							  devname[0] != 0) {
-	if (strcmp(type, "dev") == 0) {
-		if (strcmp(version, "1") != 0 && strcmp(version, "2") != 0 &&
-		 	strcmp(version, "3"))
-			continue;
-	} else {
-		if (strcmp(type, version) != 0) continue;
-	}
-
-		/* Skip bad entries, can't complain about everything. */
-	if (stat(devname, &st) < 0 || !ISDISK(st.st_mode)) continue;
-
-		/* Make new list cell. */
-	if ((new= (struct mtab *) malloc(sizeof(*new))) == NULL
-	  || (new->devname= (char *) malloc(strlen(devname) + 1)) == NULL
-	  || (new->mountpoint= (char *) malloc(strlen(mountpoint) + 1)) == NULL
-	) break;
-
-	new->device= st.st_rdev;
-	strcpy(new->devname, devname);
-	strcpy(new->mountpoint, mountpoint);
-
-	*amt= new;		/* Add the cell to the end. */
-	amt= &new->next;
-	*amt= NULL;
-  }
-#endif
-}
-
-struct mtab *searchtab(char *name)
-/* See what we can do with a user supplied name, there are five possibilities:
- * 1. It's a device and it is in the mtab: Return mtab entry.
- * 2. It's a device and it is not in the mtab: Return device mounted on "".
- * 3. It's a file and lives on a device in the mtab: Return mtab entry.
- * 4. It's a file and it's not on an mtab device: Search /dev for the device
- *    and return this device as mounted on "???".
- * 5. It's junk: Return something df() will choke on.
- */
-{
-  static struct mtab unknown;
-  static char devname[5 + NAME_MAX + 1]= "/dev/";
-  struct mtab *mt;
-  struct stat st;
-  DIR *dp;
-  struct dirent *ent;
-
-  unknown.devname= name;
-  unknown.mountpoint= "";
-
-  if (stat(name, &st) < 0) return &unknown;	/* Case 5. */
-
-  unknown.device= ISDISK(st.st_mode) ? st.st_rdev : st.st_dev;
-
-  for (mt= mtab; mt != NULL; mt= mt->next) {
-	if (unknown.device == mt->device)
-		return mt;			/* Case 1 & 3. */
-  }
-
-  if (ISDISK(st.st_mode)) {
-	return &unknown;			/* Case 2. */
-  }
-
-  if ((dp= opendir("/dev")) == NULL) return &unknown;	/* Disaster. */
-
-  while ((ent= readdir(dp)) != NULL) {
-	if (ent->d_name[0] == '.') continue;
-	strcpy(devname + 5, ent->d_name);
-	if (stat(devname, &st) >= 0 && ISDISK(st.st_mode)
-		&& unknown.device == st.st_rdev
-	) {
-		unknown.devname= devname;
-		unknown.mountpoint= "???";
-		break;
-	}
-  }
-  closedir(dp);
-  return &unknown;				/* Case 4. */
-}
-
-/* (num / tot) in percentages rounded up. */
-#define percent(num, tot)  ((int) ((100L * (num) + ((tot) - 1)) / (tot)))
-
-/* One must be careful printing all these _t types. */
-#define L(n)	((long) (n))
-
-int df(const struct mtab *mt)
-{
-  int fd;
-  bit_t i_count, z_count;
-  block_t totblocks, busyblocks;
-  int n, block_size;
-  struct v12_super_block super, *sp;
-
-  /* Don't allow Joe User to df just any device. */
-  seteuid(*mt->mountpoint == 0 ? ruid : euid);
-  setegid(*mt->mountpoint == 0 ? rgid : egid);
-
-  if ((fd = open(mt->devname, O_RDONLY)) < 0) {
-	fprintf(stderr, "df: %s: %s\n", mt->devname, strerror(errno));
-	return(1);
-  }
-  lseek(fd, (off_t) SUPER_BLOCK_BYTES, SEEK_SET);	/* skip boot block */
-
-  if (read(fd, (char *) &super, sizeof(super)) != (int) sizeof(super)) {
-	fprintf(stderr, "df: Can't read super block of %s\n", mt->devname);
-	close(fd);
-	return(1);
-  }
-
-  sp = &super;
-  if (sp->s_magic != SUPER_V1 && sp->s_magic != SUPER_V2
-      && sp->s_magic != SUPER_V3) {
-	fprintf(stderr, "df: %s: Not a valid file system\n", mt->devname);
-	close(fd);
-	return(1);
-  }
-
-  if(sp->s_magic != SUPER_V3) block_size = _STATIC_BLOCK_SIZE;
-  else block_size = super.s_block_size;
-
-  if(block_size < _MIN_BLOCK_SIZE || block_size > _MAX_BLOCK_SIZE) {
-	fprintf(stderr, "df: %s: funny block size (%d)\n",
-		mt->devname, block_size);
-	close(fd);
-	return(1);
-  }
-
-  if (sp->s_magic == SUPER_V1) sp->s_zones= sp->s_nzones;
-
-  lseek(fd, (off_t) block_size * 2L, SEEK_SET);	/* skip rest of super block */
-
-  i_count = bit_count(sp->s_imap_blocks, (bit_t) (sp->s_ninodes+1),
-  	fd, block_size);
-
-  if (i_count == -1) {
-	fprintf(stderr, "df: Can't find bit maps of %s\n", mt->devname);
-	close(fd);
-	return(1);
-  }
-  i_count--;	/* There is no inode 0. */
-
-  /* The first bit in the zone map corresponds with zone s_firstdatazone - 1
-   * This means that there are s_zones - (s_firstdatazone - 1) bits in the map
-   */
-  z_count = bit_count(sp->s_zmap_blocks,
-	(bit_t) (sp->s_zones - (sp->s_firstdatazone - 1)), fd, block_size);
-
-  if (z_count == -1) {
-	fprintf(stderr, "df: Can't find bit maps of %s\n", mt->devname);
-	close(fd);
-	return(1);
-  }
-  /* Don't forget those zones before sp->s_firstdatazone - 1 */
-  z_count += sp->s_firstdatazone - 1;
-
-#ifdef __minix_vmd
-  totblocks = sp->s_zones;
-  busyblocks = z_count;
-#else
-  totblocks = (block_t) sp->s_zones << sp->s_log_zone_size;
-  busyblocks = (block_t) z_count << sp->s_log_zone_size;
-#endif
-
-  busyblocks = busyblocks * (block_size/512) / (unitsize/512);
-  totblocks = totblocks * (block_size/512) / (unitsize/512);
-
-  /* Print results. */
-  printf("%s", mt->devname);
-  n= strlen(mt->devname);
-  if (n > 15 && istty) { putchar('\n'); n= 0; }
-  while (n < 15) { putchar(' '); n++; }
-
-  if (!Pflag && !iflag) {
-	printf(" %9ld  %9ld  %9ld %3d%%   %3d%%   %s\n",
-		L(totblocks),				/* Blocks */
-		L(totblocks - busyblocks),		/* free */
-		L(busyblocks),				/* used */
-		percent(busyblocks, totblocks),		/* % */
-		percent(i_count, sp->s_ninodes),	/* FUsed% */
-		mt->mountpoint				/* Mounted on */
-	);
-  }
-  if (!Pflag && iflag) {
-	printf(" %9ld  %9ld  %9ld %3d%%   %3d%%   %s\n",
-		L(sp->s_ninodes),			/* Files */
-		L(sp->s_ninodes - i_count),		/* free */
-		L(i_count),				/* used */
-		percent(i_count, sp->s_ninodes),	/* % */
-		percent(busyblocks, totblocks),		/* BUsed% */
-		mt->mountpoint				/* Mounted on */
-	);
-  }
-  if (Pflag && !iflag) {
-	printf(" %9ld   %9ld  %9ld     %4d%%    %s\n",
-		L(totblocks),				/* Blocks */
-		L(busyblocks),				/* Used */
-		totblocks - busyblocks,			/* Available */
-		percent(busyblocks, totblocks),		/* Capacity */
-		mt->mountpoint				/* Mounted on */
-	);
-  }
-  if (Pflag && iflag) {
-	printf(" %9ld   %9ld  %9ld     %4d%%    %s\n",
-		L(sp->s_ninodes),			/* Inodes */
-		L(i_count),				/* IUsed */
-		L(sp->s_ninodes - i_count),		/* IAvail */
-		percent(i_count, sp->s_ninodes),	/* Capacity */
-		mt->mountpoint				/* Mounted on */
-	);
-  }
-  close(fd);
-  return(0);
-}
-
-bit_t bit_count(unsigned blocks, bit_t bits, int fd, int block_size)
-{
-  char *wptr;
-  int i, b;
-  bit_t busy;
-  char *wlim;
-  static char buf[_MAX_BLOCK_SIZE];
-  static char bits_in_char[1 << CHAR_BIT];
-
-  /* Precalculate bitcount for each char. */
-  if (bits_in_char[1] != 1) {
-	for (b = (1 << 0); b < (1 << CHAR_BIT); b <<= 1)
-		for (i = 0; i < (1 << CHAR_BIT); i++)
-			if (i & b) bits_in_char[i]++;
-  }
-
-  /* Loop on blocks, reading one at a time and counting bits. */
-  busy = 0;
-  for (i = 0; i < blocks && bits != 0; i++) {
-	if (read(fd, buf, block_size) != block_size) return(-1);
-
-	wptr = &buf[0];
-	if (bits >= CHAR_BIT * block_size) {
-		wlim = &buf[block_size];
-		bits -= CHAR_BIT * block_size;
-	} else {
-		b = bits / CHAR_BIT;	/* whole chars in map */
-		wlim = &buf[b];
-		bits -= b * CHAR_BIT;	/* bits in last char, if any */
-		b = *wlim & ((1 << bits) - 1);	/* bit pattern from last ch */
-		busy += bits_in_char[b];
-		bits = 0;
-	}
-
-	/* Loop on the chars of a block. */
-	while (wptr != wlim)
-		busy += bits_in_char[*wptr++ & ((1 << CHAR_BIT) - 1)];
-  }
-  return(busy);
-}
-
-/*
- * $PchId: df.c,v 1.7 1998/07/27 18:42:17 philip Exp $
- */
Index: trunk/minix/commands/simple/dhrystone.c
===================================================================
--- trunk/minix/commands/simple/dhrystone.c	(revision 9)
+++ 	(revision )
@@ -1,585 +1,0 @@
-/* dhrystone - benchmark program */
-
-#define REGISTER
-/*
- *
- *	"DHRYSTONE" Benchmark Program
- *
- *	Version:	C/1.1, 12/01/84
- *
- *	Date:		PROGRAM updated 01/06/86, COMMENTS changed 01/31/87
- *
- *	Author:		Reinhold P. Weicker,  CACM Vol 27, No 10, 10/84 pg.1013
- *			Translated from ADA by Rick Richardson
- *			Every method to preserve ADA-likeness has been used,
- *			at the expense of C-ness.
- *
- *	Compile:	cc -O dry.c -o drynr			: No registers
- *			cc -O -DREG=register dry.c -o dryr	: Registers
- *
- *	Defines:	Defines are provided for old C compiler's
- *			which don't have enums, and can't assign structures.
- *			The time(2) function is library dependant; Most
- *			return the time in seconds, but beware of some, like
- *			Aztec C, which return other units.
- *			The LOOPS define is initially set for 50000 loops.
- *			If you have a machine with large integers and is
- *			very fast, please change this number to 500000 to
- *			get better accuracy.  Please select the way to
- *			measure the execution time using the TIME define.
- *			For single user machines, time(2) is adequate. For
- *			multi-user machines where you cannot get single-user
- *			access, use the times(2) function.  Be careful to
- *			adjust the HZ parameter below for the units which
- *			are returned by your times(2) function.  You can
- *			sometimes find this in <sys/param.h>.  If you have
- *			neither time(2) nor times(2), use a stopwatch in
- *			the dead of the night.
- *			Use a "printf" at the point marked "start timer"
- *			to begin your timings. DO NOT use the UNIX "time(1)"
- *			command, as this will measure the total time to
- *			run this program, which will (erroneously) include
- *			the time to malloc(3) storage and to compute the
- *			time it takes to do nothing.
- *
- *	Run:		drynr; dryr
- *
- *	Results:	If you get any new machine/OS results, please send to:
- *
- *				ihnp4!castor!pcrat!rick
- *
- *			and thanks to all that do.
- *
- *	Note:		I order the list in increasing performance of the
- *			"with registers" benchmark.  If the compiler doesn't
- *			provide register variables, then the benchmark
- *			is the same for both REG and NOREG.
- *
- *	PLEASE:		Send complete information about the machine type,
- *			clock speed, OS and C manufacturer/version.  If
- *			the machine is modified, tell me what was done.
- *			On UNIX, execute uname -a and cc -V to get this info.
- *
- *	80x8x NOTE:	80x8x benchers: please try to do all memory models
- *			for a particular compiler.
- *
- *
- *	The following program contains statements of a high-level programming
- *	language (C) in a distribution considered representative:
- *
- *	assignments			53%
- *	control statements		32%
- *	procedure, function calls	15%
- *
- *	100 statements are dynamically executed.  The program is balanced with
- *	respect to the three aspects:
- *		- statement type
- *		- operand type (for simple data types)
- *		- operand access
- *			operand global, local, parameter, or constant.
- *
- *	The combination of these three aspects is balanced only approximately.
- *
- *	The program does not compute anything meaningfull, but it is
- *	syntactically and semantically correct.
- *
- */
-
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <stdio.h>
-#include <signal.h>
-#include <unistd.h>
-
-/* Accuracy of timings and human fatigue controlled by next two lines */
-/*#define LOOPS	50000	*/	/* Use this for slow or 16 bit machines */
-/*#define LOOPS	500000 */	/* Use this for faster machines */
-/*#define LOOPS	(sizeof(int) == 2 ? 50000 : 1000000)*/
-
-/* Seconds to run */
-#define SECONDS	15
-
-/* Compiler dependent options */
-#define	NOENUM			/* Define if compiler has no enum's */
-/* #define NOSTRUCTASSIGN */	/* Define if compiler can't assign structures*/
-
-
-/* Define only one of the next two defines */
-#define TIMES			/* Use times(2) time function */
-/*#define TIME	*/		/* Use time(2) time function */
-
-
-#ifdef TIME
-/* Ganularity of time(2) is of course 1 second */
-#define HZ	1
-#endif
-
-#ifdef TIMES
-/* Define the granularity of your times(2) function */
-/*#define HZ	50	*/	/* times(2) returns 1/50 second (europe?) */
-/*#define HZ	60	*/	/* times(2) returns 1/60 second (most) */
-/*#define HZ	100 	*/	/* times(2) returns 1/100 second (WECo) */
-#endif
-
-/* For compatibility with goofed up version */
-/*#undef GOOF		*/	/* Define if you want the goofed up version */
-
-
-#ifdef GOOF
-char Version[] = "1.0";
-#else
-char Version[] = "1.1";
-#endif
-
-
-#ifdef	NOSTRUCTASSIGN
-#define	structassign(d, s)	memcpy(&(d), &(s), sizeof(d))
-#else
-#define	structassign(d, s)	d = s
-#endif
-
-
-#ifdef	NOENUM
-#define	Ident1	1
-#define	Ident2	2
-#define	Ident3	3
-#define	Ident4	4
-#define	Ident5	5
-typedef int Enumeration;
-#else
-typedef enum {
-  Ident1, Ident2, Ident3, Ident4, Ident5
-} Enumeration;
-#endif
-
-typedef int OneToThirty;
-typedef int OneToFifty;
-typedef char CapitalLetter;
-typedef char String30[31];
-typedef int Array1Dim[51];
-typedef int Array2Dim[51][51];
-
-struct Record {
-  struct Record *PtrComp;
-  Enumeration Discr;
-  Enumeration EnumComp;
-  OneToFifty IntComp;
-  String30 StringComp;
-};
-
-typedef struct Record RecordType;
-typedef RecordType *RecordPtr;
-typedef int boolean;
-
-#ifdef NULL
-#undef NULL
-#endif
-
-#define	NULL		0
-#define	TRUE		1
-#define	FALSE		0
-
-#ifndef REG
-#define	REG
-#endif
-
-
-#ifdef TIMES
-#include <sys/times.h>
-#endif
-
-#ifndef _PROTOTYPE
-#define _PROTOTYPE(fun, args)	fun args
-#endif
-
-_PROTOTYPE(int main, (void));
-_PROTOTYPE(void prep_timer, (void));
-_PROTOTYPE(void timeout, (int sig));
-_PROTOTYPE(void Proc0, (void));
-_PROTOTYPE(void Proc1, (RecordPtr PtrParIn));
-_PROTOTYPE(void Proc2, (OneToFifty *IntParIO));
-_PROTOTYPE(void Proc3, (RecordPtr *PtrParOut));
-_PROTOTYPE(void Proc4, (void));
-_PROTOTYPE(void Proc5, (void));
-_PROTOTYPE(void Proc6, (Enumeration EnumParIn, Enumeration *EnumParOut));
-_PROTOTYPE(void Proc7, (OneToFifty IntParI1, OneToFifty IntParI2, 
-						OneToFifty *IntParOut));
-_PROTOTYPE(void Proc8, (Array1Dim Array1Par, Array2Dim Array2Par, 
-				OneToFifty IntParI1, OneToFifty IntParI2));
-/*_PROTOTYPE(Enumeration Func1,(CapitalLetter CharPar1, CapitalLetter CharPar2));*/
-_PROTOTYPE(boolean Func2, (String30 StrParI1, String30 StrParI2));
-_PROTOTYPE(boolean Func3, (Enumeration EnumParIn));
-
-_PROTOTYPE(Enumeration Func1, (int CharPar1, int CharPar2));
-
-
-int main()
-{
-  Proc0();
-  return(0);
-}
-
-
-#if __STDC__
-volatile int done;
-#else
-int done;
-#endif
-
-void prep_timer()
-{
-  signal(SIGALRM, timeout);
-  done = 0;
-}
-
-void timeout(sig)
-int sig;
-{
-  done = 1;
-}
-
-/* Package 1  */
-int IntGlob;
-boolean BoolGlob;
-char Char1Glob;
-char Char2Glob;
-Array1Dim Array1Glob;
-Array2Dim Array2Glob;
-RecordPtr PtrGlb;
-RecordPtr PtrGlbNext;
-
-
-void Proc0()
-{
-  OneToFifty IntLoc1;
-  REG OneToFifty IntLoc2;
-  OneToFifty IntLoc3;
-  REG char CharIndex;
-  Enumeration EnumLoc;
-  String30 String1Loc;
-  String30 String2Loc;
-  register unsigned long i;
-  unsigned long starttime;
-  unsigned long benchtime;
-  unsigned long nulltime;
-  unsigned long nullloops;
-  unsigned long benchloops;
-  unsigned long ticks_per_sec;
-#ifdef TIMES
-  struct tms tms;
-#endif
-
-#ifdef HZ
-#define ticks_per_sec	HZ
-#else
-  ticks_per_sec = sysconf(_SC_CLK_TCK);
-#endif
-
-  i = 0;
-  prep_timer();
-
-#ifdef TIME
-  starttime = time((long *) 0);
-#endif
-
-#ifdef TIMES
-  times(&tms);
-  starttime = tms.tms_utime;
-#endif
-
-  alarm(1);
-  while (!done) i++;
-
-#ifdef TIME
-  nulltime = time((long *) 0) - starttime;	/* Computes o'head of loop */
-#endif
-
-#ifdef TIMES
-  times(&tms);
-  nulltime = tms.tms_utime - starttime;	/* Computes overhead of looping */
-#endif
-
-  nullloops = i;
-
-
-  PtrGlbNext = (RecordPtr) malloc(sizeof(RecordType));
-  PtrGlb = (RecordPtr) malloc(sizeof(RecordType));
-  PtrGlb->PtrComp = PtrGlbNext;
-  PtrGlb->Discr = Ident1;
-  PtrGlb->EnumComp = Ident3;
-  PtrGlb->IntComp = 40;
-  strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
-#ifndef	GOOF
-  strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING");	/* GOOF */
-#endif
-
-  Array2Glob[8][7] = 10;	/* Was missing in published program */
-
-
-/*****************
--- Start Timer --
-*****************/
-  i = 0;
-  prep_timer();
-
-#ifdef TIME
-  starttime = time((long *) 0);
-#endif
-
-#ifdef TIMES
-  times(&tms);
-  starttime = tms.tms_utime;
-#endif
-
-  alarm(SECONDS);
-  while (!done) {
-	i++;
-	Proc5();
-	Proc4();
-	IntLoc1 = 2;
-	IntLoc2 = 3;
-	strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
-	EnumLoc = Ident2;
-	BoolGlob = !Func2(String1Loc, String2Loc);
-	while (IntLoc1 < IntLoc2) {
-		IntLoc3 = 5 * IntLoc1 - IntLoc2;
-		Proc7(IntLoc1, IntLoc2, &IntLoc3);
-		++IntLoc1;
-	}
-	Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
-	Proc1(PtrGlb);
-	for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
-		if (EnumLoc == Func1(CharIndex, 'C'))
-			Proc6(Ident1, &EnumLoc);
-	IntLoc3 = IntLoc2 * IntLoc1;
-	IntLoc2 = IntLoc3 / IntLoc1;
-	IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
-	Proc2(&IntLoc1);
-  }
-
-
-/*****************
--- Stop Timer --
-*****************/
-
-
-#ifdef TIME
-  benchtime = time((long *) 0) - starttime;
-#endif
-
-#ifdef TIMES
-  times(&tms);
-  benchtime = tms.tms_utime - starttime;
-#endif
-  benchloops = i;
-
-  /* Approximately correct benchtime to the nulltime. */
-  benchtime -= nulltime / (nullloops / benchloops);
-
-  printf("Dhrystone(%s) time for %lu passes = %lu.%02lu\n",
-	Version,
-	benchloops, benchtime / ticks_per_sec,
-	benchtime % ticks_per_sec * 100 / ticks_per_sec);
-  printf("This machine benchmarks at %lu dhrystones/second\n",
-	benchloops * ticks_per_sec / benchtime);
-}
-
-
-void Proc1(PtrParIn)
-REG RecordPtr PtrParIn;
-{
-#define	NextRecord	(*(PtrParIn->PtrComp))
-
-
-  structassign(NextRecord, *PtrGlb);
-  PtrParIn->IntComp = 5;
-  NextRecord.IntComp = PtrParIn->IntComp;
-  NextRecord.PtrComp = PtrParIn->PtrComp;
-  Proc3((RecordPtr *)NextRecord.PtrComp);
-  if (NextRecord.Discr == Ident1) {
-	NextRecord.IntComp = 6;
-	Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
-	NextRecord.PtrComp = PtrGlb->PtrComp;
-	Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp);
-  } else
-	structassign(*PtrParIn, NextRecord);
-
-
-#undef	NextRecord
-}
-
-
-void Proc2(IntParIO)
-OneToFifty *IntParIO;
-{
-  REG OneToFifty IntLoc;
-  REG Enumeration EnumLoc;
-
-
-  IntLoc = *IntParIO + 10;
-  for (;;) {
-	if (Char1Glob == 'A') {
-		--IntLoc;
-		*IntParIO = IntLoc - IntGlob;
-		EnumLoc = Ident1;
-	}
-	if (EnumLoc == Ident1) break;
-  }
-}
-
-
-void Proc3(PtrParOut)
-RecordPtr *PtrParOut;
-{
-  if (PtrGlb != NULL)
-	*PtrParOut = PtrGlb->PtrComp;
-  else
-	IntGlob = 100;
-  Proc7(10, IntGlob, &PtrGlb->IntComp);
-}
-
-
-void Proc4()
-{
-  REG boolean BoolLoc;
-
-
-  BoolLoc = Char1Glob == 'A';
-  BoolLoc |= BoolGlob;
-  Char2Glob = 'B';
-}
-
-
-void Proc5()
-{
-  Char1Glob = 'A';
-  BoolGlob = FALSE;
-}
-
-
-void Proc6(EnumParIn, EnumParOut)
-REG Enumeration EnumParIn;
-REG Enumeration *EnumParOut;
-{
-  *EnumParOut = EnumParIn;
-  if (!Func3(EnumParIn)) *EnumParOut = Ident4;
-  switch (EnumParIn) {
-      case Ident1:	*EnumParOut = Ident1;	break;
-      case Ident2:
-	if (IntGlob > 100)
-		*EnumParOut = Ident1;
-	else
-		*EnumParOut = Ident4;
-	break;
-      case Ident3:	*EnumParOut = Ident2;	break;
-      case Ident4:
-	break;
-      case Ident5:	*EnumParOut = Ident3;
-}
-}
-
-
-void Proc7(IntParI1, IntParI2, IntParOut)
-OneToFifty IntParI1;
-OneToFifty IntParI2;
-OneToFifty *IntParOut;
-{
-  REG OneToFifty IntLoc;
-
-
-  IntLoc = IntParI1 + 2;
-  *IntParOut = IntParI2 + IntLoc;
-}
-
-
-void Proc8(Array1Par, Array2Par, IntParI1, IntParI2)
-Array1Dim Array1Par;
-Array2Dim Array2Par;
-OneToFifty IntParI1;
-OneToFifty IntParI2;
-{
-  REG OneToFifty IntLoc;
-  REG OneToFifty IntIndex;
-
-
-  IntLoc = IntParI1 + 5;
-  Array1Par[IntLoc] = IntParI2;
-  Array1Par[IntLoc + 1] = Array1Par[IntLoc];
-  Array1Par[IntLoc + 30] = IntLoc;
-  for (IntIndex = IntLoc; IntIndex <= (IntLoc + 1); ++IntIndex)
-	Array2Par[IntLoc][IntIndex] = IntLoc;
-  ++Array2Par[IntLoc][IntLoc - 1];
-  Array2Par[IntLoc + 20][IntLoc] = Array1Par[IntLoc];
-  IntGlob = 5;
-}
-
-
-Enumeration Func1(CharPar1, CharPar2)
-CapitalLetter CharPar1;
-CapitalLetter CharPar2;
-{
-  REG CapitalLetter CharLoc1;
-  REG CapitalLetter CharLoc2;
-
-
-  CharLoc1 = CharPar1;
-  CharLoc2 = CharLoc1;
-  if (CharLoc2 != CharPar2)
-	return(Ident1);
-  else
-	return(Ident2);
-}
-
-
-boolean Func2(StrParI1, StrParI2)
-String30 StrParI1;
-String30 StrParI2;
-{
-  REG OneToThirty IntLoc;
-  REG CapitalLetter CharLoc;
-
-
-  IntLoc = 1;
-  while (IntLoc <= 1)
-	if (Func1(StrParI1[IntLoc], StrParI2[IntLoc + 1]) == Ident1) {
-		CharLoc = 'A';
-		++IntLoc;
-	}
-  if (CharLoc >= 'W' && CharLoc <= 'Z') IntLoc = 7;
-  if (CharLoc == 'X')
-	return(TRUE);
-  else {
-	if (strcmp(StrParI1, StrParI2) > 0) {
-		IntLoc += 7;
-		return(TRUE);
-	} else
-		return(FALSE);
-  }
-}
-
-
-boolean Func3(EnumParIn)
-REG Enumeration EnumParIn;
-{
-  REG Enumeration EnumLoc;
-
-
-  EnumLoc = EnumParIn;
-  if (EnumLoc == Ident3) return(TRUE);
-  return(FALSE);
-}
-
-
-#ifdef	NOSTRUCTASSIGN
-memcpy(d, s, l)
-register char *d;
-register char *s;
-register int l;
-{
-  while (l--) *d++ = *s++;
-}
-
-#endif
Index: trunk/minix/commands/simple/diff.c
===================================================================
--- trunk/minix/commands/simple/diff.c	(revision 9)
+++ 	(revision )
@@ -1,1254 +1,0 @@
-/* diff  - print differences between 2 files	  Author: Erik Baalbergen */
-
-/* Poor man's implementation of diff(1) 	- no options available
-* 	- may give more output than other diffs,
-*	  due to the straight-forward algorithm
-* 	- runs out of memory if the differing chunks become too large
-* 	- input line length should not exceed LINELEN; longer lines are
-*	  truncated, while only the first LINELEN characters are compared
-*
-* 	- Bug fixes by Rick Thomas Sept. 1989
-*
-* Please report bugs and suggestions to erikb@cs.vu.nl
-*------------------------------------------------------------------------------
-* Changed diff to conform to POSIX 1003.2 ( Draft 11) by Thomas Brupbacher
-* ( tobr@mw.lpc.ethz.ch).
-*
-* To incorporate the context diff option -c in the program, the source code
-* for the program cdiff has been copied to the end of this program. Only
-* slight modifications for the cdiff code to work within the program diff
-* were made( e.g. main() -> context_diff()).
-*
-* New options:
-* -c, -C n where n=0,1,...:
-*  	produces a context diff as the program cdiff. The default is to
-*  	print 3 lines of context, this value can be changed with -C
-*	( e.g. -C 5 prints five lines of context.)
-* -e :	Prints an ed script, so you can convert <file1> to <file2> with
-*  	the command ed <file1> < `diff -e <file1> <file2>`.
-* -b :	Causes trailing blanks to be ignored and spaces of multiple blanks
-*  	to be reduced to one blank before comparison.
-*-----------------------------------------------------------------------------
-*/
-
-#include <errno.h>
-#include <stdlib.h>
-#include <limits.h>		/* NAME_MAX for maximal filename length	 */
-#include <string.h>		/* string manipulation			 */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <ctype.h>
-#include <time.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <stdio.h>
-
-/* These definitions are needed only to suppress warning messages. */
-#define Nullfp 		((FILE*)0)
-#define Nullch 		((char*)0)
-#define NullStructLine	((struct line *)0)
-
-#define LINELEN 128		/* max line length included in diff	 */
-
-
-#define NOT_SET 0		/* Defines to characterise if a flag 	 */
-#define SET	1		/* is set				 */
-
- /* Indexes of the warning-message array	 */
-#define EXCLUSIVE_OPTIONS	0
-#define CANNOT_OPEN_FILE	1
-
- /* Used to define the mode 		 */
-typedef enum {
-  undefined, context, ed_mode
-} MODE;
-
- /* Global variables for the 'normal' diff part	 */
-char *progname;			/* program name	(on command line)	 */
-int diffs = 0;			/* number of differences		 */
-MODE mode;			/* which mode is used			 */
-int severe_error;		/* nonzero after severe, non-fatal error */
-
-/* The following global variables are used with the -r option:
- * for every pair of files that are different, a "command line" of the
- * form "diff <options> <oldfile> <newfile>" is printed before the real
- * output starts.							 */
-int firstoutput = 1;		/* flag to print one time		 */
-char options_string[10];	/* string to hold command line options 	 */
-char oldfile[PATH_MAX];		/* first file				 */
-char newfile[PATH_MAX];		/* second file				 */
-
-
- /* Global variables for the command-line options */
-int trim_blanks = NOT_SET;	/* SET if -b specified	 		 */
-int recursive_dir = NOT_SET;	/* SET if -r specified	 		 */
-int context_lines = 3;		/* numbers of lines in a context	 */
-static int offset;		/* offset of the actual line number for -e */
-
- /* Function prototypes for the functions in this file	 */
-struct f;
-_PROTOTYPE(int main, (int argc, char **argv ));
-_PROTOTYPE(void process_command_line, (int argc, char **argv ));
-_PROTOTYPE(void analyse_input_files, (char *arg1, char *arg2, char *input1, 
-							char *input2 ));
-_PROTOTYPE(void diff, (char *filename1, char *filename2 ));
-_PROTOTYPE(FILE *check_file, (char *name ));
-_PROTOTYPE(void build_option_string, (void ));
-_PROTOTYPE(void fatal_error, (char *fmt, char *s ));
-_PROTOTYPE(void warn, (int number, char *string ));
-_PROTOTYPE(void trimming_blanks, (char *l_text ));
-_PROTOTYPE(char *filename, (char *path_string));
-_PROTOTYPE(struct line *new_line, (int size ));
-_PROTOTYPE(void free_line, (struct line *l ));
-_PROTOTYPE(int equal_line, (struct line *l1, struct line *l2 ));
-_PROTOTYPE(int equal_3, (struct line *l1, struct line *l2 ));
-_PROTOTYPE(struct line *read_line, (FILE *fp ));
-_PROTOTYPE(void advance, (struct f *f ));
-_PROTOTYPE(void aside, (struct f *f, struct line *l ));
-_PROTOTYPE(struct line *next, (struct f *f ));
-_PROTOTYPE(void init_f, (struct f *f, FILE *fp ));
-_PROTOTYPE(void update, (struct f *f, char *s ));
-_PROTOTYPE(void __diff, (FILE *fp1, FILE *fp2 ));
-_PROTOTYPE(void differ, (struct f *f1, struct f *f2 ));
-_PROTOTYPE(int wlen, (struct f *f ));
-_PROTOTYPE(void range, (int a, int b ));
-_PROTOTYPE(void cdiff, (char *old, char *new, FILE *file1, FILE *file2 ));
-_PROTOTYPE(void dumphunk, (void ));
-_PROTOTYPE(char *getold, (int targ ));
-_PROTOTYPE(char *getnew, (int targ ));
-_PROTOTYPE(int isdir, (char *path ));
-_PROTOTYPE(void diff_recursive, (char *dir1, char *dir2 ));
-_PROTOTYPE(void file_type_error, (char *filename1, char *filename2, 
-			struct stat *statbuf1, struct stat *statbuf2 ));
-_PROTOTYPE(void *xmalloc, (size_t size));
-_PROTOTYPE(void *xrealloc, (void *ptr, size_t size));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  char file1[PATH_MAX], file2[PATH_MAX];
-  extern int optind;		/* index of the current string in argv	 */
-
-  progname = argv[0];
-  process_command_line(argc, argv);
-
-  analyse_input_files(argv[optind], argv[optind + 1], file1, file2);
-  optind++;
-
-  if (recursive_dir == SET) {
-	build_option_string();
-	diff_recursive(file1, file2);
-  } else {
-	diff(file1, file2);
-  }
-
-  return(severe_error ? 2 : diffs > 0 ? 1 : 0);
-}
-
-/* Process the command line and set the flags for the different
- * options. the processing of the command line is done with the
- * getopt() library function. a minimal error processing is done
- * for the number of command line arguments.				 */
-void process_command_line(argc, argv)
-int argc;			/* number of arguments on command line	 */
-char **argv;			/* ** to arguments on command line	 */
-{
-  int c;
-  extern char *optarg;		/* points to string with options	 */
-  extern int optind;		/* index of the current string in argv	 */
-
-  /* Are there enough arguments?		 */
-  if (argc < 3) {
-	fatal_error("Usage: %s [-c|-e|-C n][-br] file1 file2\n", progname);
-  }
-
-  /* Process all options using getopt()	 */
-  while ((c = getopt(argc, argv, "ceC:br")) != -1) {
-	switch (c) {
-	    case 'c':
-		if (mode != undefined) warn(EXCLUSIVE_OPTIONS, "c");
-		mode = context;
-		context_lines = 3;
-		break;
-	    case 'e':
-		if (mode != undefined) warn(EXCLUSIVE_OPTIONS, "e");
-		mode = ed_mode;
-		break;
-	    case 'C':
-		if (mode != undefined) warn(EXCLUSIVE_OPTIONS, "C");
-		mode = context;
-		context_lines = atoi(optarg);
-		break;
-	    case 'b':	trim_blanks = SET;	break;
-	    case 'r':	recursive_dir = SET;	break;
-	    case '?':
-		exit(2);
-	}
-  }
-
-  /* We should have two arguments left	 */
-  if ((argc - optind) != 2)
-	fatal_error("Need exactly two input file-names!\n", "");
-}
-
-/* Analyse_input_files takes the two input files on the command line
- * and decides what to do. returns the (corrected) filenames that
- * can be used to call diff().
- * if two directories are given, then a recursive diff is done.
- * one directory and one filename compares the file with <filename>
- * in the directory <directory> with <filename>.
- * if two filenames are specified, no special action takes place.
- */
-void analyse_input_files(arg1, arg2, input1, input2)
-char *arg1, *arg2;		/* filenames on the command line	 */
-char *input1, *input2;		/* filenames to be used with diff()	 */
-{
-  int stat1 = 0, stat2 = 0;
-
-  if (strcmp(arg1, "-") != 0)
-	stat1 = isdir(arg1);	/* != 0 <-> arg1 is directory		 */
-  if (strcmp(arg2, "-") != 0) stat2 = isdir(arg2);
-#ifdef DEBUG
-  fprintf(stderr, "%s, stat = %d\n", arg1, stat1);
-  fprintf(stderr, "%s, stat = %d\n", arg2, stat2);
-#endif
-  if (stat1 && stat2) {		/* both arg1 and arg2 are directories */
-	recursive_dir = SET;
-	strcpy(input1, arg1);
-	strcpy(input2, arg2);
-	return;
-  }
-  if (stat1 != 0) {		/* arg1 is a dir, arg2 not		 */
-	if (strcmp(arg2, "-") != 0) {	/* arg2 != stdin	 */
-		strcpy(input1, arg1);
-		strcat(input1, "/");
-		strcat(input1, arg2);
-		strcpy(input2, arg2);
-		return;
-	} else {
-		fatal_error("cannot compare stdin (-) with a directory!", "");
-	}
-  }
-  if (stat2 != 0) {		/* arg2 is a dir, arg1 not		 */
-	if (strcmp(arg1, "-") != 0) {	/* arg1 != stdin	 */
-		strcpy(input1, arg1);
-		strcpy(input2, arg2);
-		strcat(input2, "/");
-		strcat(input2, arg1);
-		return;
-	} else {		/* arg1 == stdin			 */
-		fatal_error("cannot compare stdin (-) with a directory!", "");
-	}
-  }
-
-  /* Both arg1 and arg2 are normal  files	 */
-  strcpy(input1, arg1);
-  strcpy(input2, arg2);
-}
-
-/* Diff() is the front end for all modes of the program diff, execpt
- * the recursive_dir option.
- * diff() expects the filenames of the two files to be compared as
- * arguments. the mode is determined from the global variable mode.
- */
-void diff(filename1, filename2)
-char *filename1, *filename2;
-{
-  FILE *file1 = check_file(filename1);
-  FILE *file2 = check_file(filename2);
-  struct stat statbuf1, statbuf2;
-
-  if ((file1 != Nullfp) && (file2 != Nullfp)) {
-	/* If we do a recursive diff, then we don't compare block
-	 * special, character special or FIFO special files to any
-	 * file.			  */
-	fstat(fileno(file1), &statbuf1);
-	fstat(fileno(file2), &statbuf2);
-	if ((((statbuf1.st_mode & S_IFREG) != S_IFREG) ||
-	     ((statbuf2.st_mode & S_IFREG) != S_IFREG)) &&
-	    (recursive_dir == SET)) {
-		file_type_error(filename1, filename2, &statbuf1, &statbuf2);
-	} else {
-		switch (mode) {
-		    case context:
-			cdiff(filename1, filename2, file1, file2);
-			break;
-		    case ed_mode:
-		    case undefined:
-			__diff(file1, file2);
-			if (mode == ed_mode) printf("w\n");
-			break;
-		}
-	}
-  } else
-	severe_error = 1;
-  if (file1 != Nullfp) fclose(file1);
-  if (file2 != Nullfp) fclose(file2);
-}
-
-/* Check_file() opens the fileptr with name <filename>. if <filename>
- * equals "-" stdin is associated with the return value.
- */
-FILE *check_file(name)
-char *name;
-{
-  FILE *temp;
-
-  if (strcmp(name, "-") == 0) {
-	return(stdin);
-  } else {
-	temp = fopen(name, "r");
-	if (temp == Nullfp) warn(CANNOT_OPEN_FILE, name);
-	return(temp);
-  }
-}
-
-/* Build_option_string() is called before recursive_dir() is called
- * from the main() function. its purpose is to build the string that
- * is used on the command line to get the current operation mode.
- * e.g. "-C 6 -b".
- */
-void build_option_string()
-{
-  switch (mode) {
-	    case ed_mode:sprintf(options_string, "-e");
-	break;
-      case context:
-	if (context_lines == 3)
-		sprintf(options_string, "-c");
-	else
-		sprintf(options_string, "-C %d", context_lines);
-	break;
-  }
-
-}
-
-
-/* The fatal error handler.
- * Expects a format string and a string as arguments. The arguments
- * are printed to stderr and the program exits with an error code 2.
- */
-void fatal_error(fmt, s)
-char *fmt;			/* the format sttring to be printed	 */
-char *s;			/* string to be inserted into the format
-				 * string				 */
-{
-  fprintf(stderr, "%s: ", progname);
-  fprintf(stderr, fmt, s);
-  fprintf(stderr, "\n");
-  exit(2);
-}
-
-/* This function prints non fatal error messages to stderr.
- * Expects the index of the message to be printed and a pointer
- * to the (optional) string to be printed.
- * Returns no value.
- */
-void warn(number, string)
-int number;			/* index of the warning			 */
-char *string;			/* string to be inserted to the warning	 */
-{
-  static char *warning[] = {
-    "%s: The options -c, -e, -C n are mutually exclusive! Assuming -%c\n",
-    "%s: cannot open file %s for reading\n",
-  };
-  fprintf(stderr, warning[number], progname, string);
-}
-
-/* Function used with the optione -b, trims the blanks in a input line:
- * - blanks between words are reduced to one
- * - trailing blanks are eliminated.
- */
-void trimming_blanks(l_text)
-char *l_text;			/* begin of the char array		 */
-{
-  char *line = l_text;
-  char *copy_to, *copy_from;
-
-  do {
-	if (*line == ' ') {
-		copy_from = line;
-		copy_to = line;
-		while (*(++copy_from) == ' ');
-		if (*copy_from != '\n') copy_to++;
-		while (*copy_from != '\0') *(copy_to++) = *(copy_from++);
-		*copy_to = '\0';
-	}
-  } while (*(++line) != '\0');
-}
-
-
-/* Filename separates the filename and the relative path in path_string.
- * Returns the filename with a leading /
- */
-char *filename(path_string)
-char *path_string;
-{
-  char name[NAME_MAX + 2];	/* filename plus /		 	 */
-  char *ptr;
-
-  name[0] = '/';
-  ptr = strrchr(path_string, '/');
-
-  if (ptr == 0) {		/* no / in path_string, only a filename	 */
-	strcat(name, path_string);
-  } else {
-	strcat(name, ptr);
-  }
-
-  return(name);
-}
-
-/* The line module: one member in a linked list of lines. */
-struct line {
-  struct line *l_next;		/* pointer to the next line	 */
-  char l_eof;			/* == 0 if last line in file	 */
-  char *l_text;			/* array with the text		 */
-};
-
-struct line *freelist = 0;
-#define stepup(ll) ( ((ll) && ((ll)->l_eof==0)) ? (ll)->l_next : (ll) )
-
-/* Function to allocate space for a new line containing SIZE chars	*/
-struct line *new_line(size)
-int size;
-{
-  register struct line *l;
-
-  if ((l = freelist) != NullStructLine)
-	freelist = freelist->l_next;
-  else {
-	l = (struct line *) xmalloc(3 * sizeof(void *));
-	l->l_text = (char *) xmalloc((size + 2) * sizeof(char));
-	if ((l == 0) || (l->l_text == 0)) fatal_error("Out of memory", "");
-  }
-  return l;
-}
-
-
-/* Free_line() releases storage allocated for <l>. */
-void free_line(l)
-register struct line *l;
-{
-  l->l_next = freelist;
-  freelist = l;
-}
-
-/* Equal_line() compares two lines, <l1> and <l2>.
- * the returned value is the result of the strcmp() function.
- */
-int equal_line(l1, l2)
-struct line *l1, *l2;
-{
-  if (l1 == 0 || l2 == 0)
-	return(0);
-  else if (l1->l_eof || l2->l_eof)
-	return(l1->l_eof == l2->l_eof);
-  else
-	return(strcmp(l1->l_text, l2->l_text) == 0);
-}
-
-int equal_3(l1, l2)
-struct line *l1, *l2;
-{
-  register int i, ansr;
-
-  ansr = 1;
-#ifdef DEBUG
-  if (l1 == 0)
-	fprintf(stderr, "\t(null)\n");
-  else if (l1->l_eof)
-	fprintf(stderr, "\t(eof)\n");
-  else
-	fprintf(stderr, "\t%s", l1->l_text);
-  if (l2 == 0)
-	fprintf(stderr, "\t(null)\n");
-  else if (l2->l_eof)
-	fprintf(stderr, "\t(eof)\n");
-  else
-	fprintf(stderr, "\t%s", l2->l_text);
-#endif
-  for (i = 0; i < 3; ++i) {
-	if (!equal_line(l1, l2)) {
-		ansr = 0;
-		break;
-	}
-	l1 = stepup(l1);
-	l2 = stepup(l2);
-  }
-#ifdef DEBUG
-  fprintf(stderr, "\t%d\n", ansr);
-#endif
-  return(ansr);
-}
-
-struct line *
- read_line(fp)
-FILE *fp;
-{
-  register struct line *l = new_line(LINELEN);
-  register char *p;
-  register int c;
-
-  (p = &(l->l_text[LINELEN]))[1] = '\377';
-  l->l_eof = 0;
-  if (fgets(l->l_text, LINELEN + 2, fp) == 0) {
-	l->l_eof = 1;
-	l->l_text[0] = 0;
-  } else if ((p[1] & 0377) != 0377 && *p != '\n') {
-	while ((c = fgetc(fp)) != '\n' && c != EOF) {
-	}
-	*p++ = '\n';
-	*p = '\0';
-  }
-  l->l_next = 0;
-  if (trim_blanks == SET) {
-#ifdef DEBUG
-	printf("xxx %s xxx\n", l->l_text);
-#endif
-	trimming_blanks(l->l_text);
-#ifdef DEBUG
-	printf("xxx %s xxx\n", l->l_text);
-#endif
-  }
-  return l;
-}
-
-/* File window handler */
-struct f {
-  struct line *f_bwin, *f_ewin;
-  struct line *f_aside;
-  int f_linecnt;		/* line number in file of last advanced line */
-  FILE *f_fp;
-};
-
-void advance(f)
-register struct f *f;
-{
-  register struct line *l;
-
-  if ((l = f->f_bwin) != NullStructLine) {
-	if (f->f_ewin == l)
-		f->f_bwin = f->f_ewin = 0;
-	else
-		f->f_bwin = l->l_next;
-	free_line(l);
-	(f->f_linecnt)++;
-  }
-}
-
-void aside(f, l)
-struct f *f;
-struct line *l;
-{
-  register struct line *ll;
-
-  if (l == 0) return;
-  if ((ll = l->l_next) != NullStructLine) {
-	while (ll->l_next) ll = ll->l_next;
-	ll->l_next = f->f_aside;
-	f->f_aside = l->l_next;
-	l->l_next = 0;
-	f->f_ewin = l;
-  }
-}
-
-
-struct line *next(f)
-register struct f *f;
-{
-  register struct line *l;
-
-  if ((l = f->f_aside) != NullStructLine) {
-	f->f_aside = l->l_next;
-	l->l_next = 0;
-  } else
-	l = read_line(f->f_fp);
-  if (l) {
-	if (f->f_bwin == 0)
-		f->f_bwin = f->f_ewin = l;
-	else {
-		if (f->f_ewin->l_eof && l->l_eof) {
-			free_line(l);
-			return(f->f_ewin);
-		}
-		f->f_ewin->l_next = l;
-		f->f_ewin = l;
-	}
-  }
-  return l;
-}
-
-
-/* Init_f() initialises a window structure (struct f). <fp> is the
- * file associated with <f>.
- */
-void init_f(f, fp)
-register struct f *f;
-FILE *fp;
-{
-  f->f_bwin = f->f_ewin = f->f_aside = 0;
-  f->f_linecnt = 0;
-  f->f_fp = fp;
-}
-
-
-/* Update() prints a window. <f> is a pointer to the window, <s> is the
- * string containing the "prefix" to the printout( either "<" or ">").
- * after completion of update(), the window is empty.
- */
-void update(f, s)
-register struct f *f;
-char *s;
-{
-  char *help;
-  int only_dot = 0;
-
-  if (firstoutput && (recursive_dir == SET)) {
-	printf("diff %s %s %s\n", options_string, oldfile, newfile);
-	firstoutput = 0;
-  }
-  while (f->f_bwin && f->f_bwin != f->f_ewin) {
-	if (mode != ed_mode) {
-		printf("%s%s", s, f->f_bwin->l_text);
-	} else {
-#ifdef DEBUG
-		printf("ed_mode: test for only dot");
-		printf("%s", f->f_bwin->l_text);
-#endif
-		help = f->f_bwin->l_text;
-		while ((*help == ' ') ||
-		       (*help == '.') ||
-		       (*help == '\t')) {
-			if (*(help++) == '.') only_dot++;
-			if (only_dot > 1) break;
-		}
-
-		/* If only_dot is equal 1, there is only one dot on
-		 * the line, so we have to take special actions.
-		 * f the line with only one dot is found, we output
-		 * two dots (".."), terminate the append modus and
-		 * substitute "." for "..". Afterwards we restart
-		 * with the append command.			 */
-		if (*help == '\n' && only_dot == 1) {
-			help = f->f_bwin->l_text;
-			while (*help != '\0') {
-				if (*help == '.') printf(".");
-				putchar((int) *(help++));
-			}
-			printf(".\n");
-			printf(".s/\\.\\././\n");
-			printf("a\n");
-		} else {
-			printf("%s%s", s, f->f_bwin->l_text);
-		}
-	}
-	advance(f);
-  }
-}
-
-/* __Diff(), performs the "core operation" of the program.
- * Expects two file-pointers as arguments. This functions does
- * *not* check if the file-pointers are valid.
- */
-
-void __diff(fp1, fp2)
-FILE *fp1, *fp2;
-{
-  struct f f1, f2;
-  struct line *l1, *s1, *b1, *l2, *s2, *b2;
-  register struct line *ll;
-
-  init_f(&f1, fp1);
-  init_f(&f2, fp2);
-  l1 = next(&f1);
-  l2 = next(&f2);
-  while ((l1->l_eof == 0) || (l2->l_eof == 0)) {
-	if (equal_line(l1, l2)) {
-  equal:
-		advance(&f1);
-		advance(&f2);
-		l1 = next(&f1);
-		l2 = next(&f2);
-		continue;
-	}
-	s1 = b1 = l1;
-	s2 = b2 = l2;
-	/* Read several more lines */
-	next(&f1);
-	next(&f1);
-	next(&f2);
-	next(&f2);
-	/* Start searching */
-search:
-	next(&f2);
-	ll = s1;
-	do {
-		if (equal_3(ll, b2)) {
-			l1 = ll;
-			l2 = b2;
-			aside(&f1, ll);
-			aside(&f2, b2);
-			differ(&f1, &f2);
-			goto equal;
-		}
-		if (ll->l_eof) break;
-		ll = stepup(ll);
-	} while (ll);
-	b2 = stepup(b2);
-
-	next(&f1);
-	ll = s2;
-	do {
-		if (equal_3(b1, ll)) {
-			l1 = b1;
-			l2 = ll;
-			aside(&f2, ll);
-			aside(&f1, b1);
-			differ(&f1, &f2);
-			goto equal;
-		}
-		if (ll->l_eof != 0) break;
-		ll = stepup(ll);
-	} while (ll);
-	b1 = stepup(b1);
-
-	goto search;
-  }
-
-  /* Both of the files reached EOF */
-}
-
-/* Differ() prints the differences between files. the arguments <f1> and
- * <f2> are pointers to the two windows, where the differences are.
- */
-void differ(f1, f2)
-register struct f *f1, *f2;
-{
-  int cnt1 = f1->f_linecnt, len1 = wlen(f1);
-  int cnt2 = f2->f_linecnt, len2 = wlen(f2);
-  if ((len1 != 0) || (len2 != 0)) {
-	if (len1 == 0) {
-		if (mode == ed_mode) {
-			cnt1 += offset;
-			printf("%d a\n", cnt1);
-			update(f2, "");
-			printf(".\n");
-			offset += len2;
-		} else {
-			printf("%da", cnt1);
-			range(cnt2 + 1, cnt2 + len2);
-		}
-	} else if (len2 == 0) {
-		if (mode == ed_mode) {
-			cnt1 += offset;
-			range(cnt1 + 1, cnt1 + len1);
-			printf("d\n");
-			offset -= len1;
-			while (f1->f_bwin && f1->f_bwin != f1->f_ewin)
-				advance(f1);
-		} else {
-			range(cnt1 + 1, cnt1 + len1);
-			printf("d%d", cnt2);
-		}
-	} else {
-		if (mode != ed_mode) {
-			range(cnt1 + 1, cnt1 + len1);
-			putchar('c');
-			range(cnt2 + 1, cnt2 + len2);
-		} else {
-			cnt1 += offset;
-			if (len1 == len2) {
-				range(cnt1 + 1, cnt1 + len1);
-				printf("c\n");
-				update(f2, "");
-				printf(".\n");
-			} else {
-				range(cnt1 + 1, cnt1 + len1);
-				printf("d\n");
-				printf("%d a\n", cnt1);
-				update(f2, "");
-				printf(".\n");
-				offset -= len1 - len2;
-			}
-			while (f1->f_bwin && f1->f_bwin != f1->f_ewin)
-				advance(f1);
-		}
-	}
-	if (mode != ed_mode) {
-		putchar('\n');
-		if (len1 != 0) update(f1, "< ");
-		if ((len1 != 0) && (len2 != 0)) printf("---\n");
-		if (len2 != 0) update(f2, "> ");
-	}
-	diffs++;
-  }
-}
-
-
-/* Function wlen() calculates the number of lines in a window. */
-int wlen(f)
-struct f *f;
-{
-  register cnt = 0;
-  register struct line *l = f->f_bwin, *e = f->f_ewin;
-
-  while (l && l != e) {
-	cnt++;
-	l = l->l_next;
-  }
-  return cnt;
-}
-
-
-/* Range() prints the line numbers of a range. the arguments <a> and <b>
- * are the beginning and the ending line number of the range. if
- * <a> == <b>, only one line number is printed. otherwise <a> and <b> are
- * separated by a ",".
- */
-void range(a, b)
-int a, b;
-{
-  printf(((a == b) ? "%d" : "%d,%d"), a, b);
-}
-
-/* Here follows the code for option -c.
- * This code is from the cdiff program by Larry Wall. I changed it only
- * slightly to reflect the POSIX standard and to call the main routine
- * as function context_diff().
- */
-
-/* Cdiff - context diff			Author: Larry Wall */
-
-/* These global variables are still here from the original cdiff program...
- * I was to lazy just to sort them out...
- */
-char buff[512];
-FILE *oldfp, *newfp;
-
-int oldmin, oldmax, newmin, newmax;
-int oldbeg, oldend, newbeg, newend;
-int preoldmax, prenewmax;
-int preoldbeg, preoldend, prenewbeg, prenewend;
-int oldwanted, newwanted;
-
-char *oldhunk, *newhunk;
-size_t oldsize, oldalloc, newsize, newalloc;
-
-int oldline, newline; /* Jose */
-
-void cdiff(old, new, file1, file2)
-char *old, *new;		/* The names of the two files to be compared */
-FILE *file1, *file2;		/* The corresponding file-pointers	 */
-{
-  FILE *inputfp;
-  struct stat statbuf;
-  register char *s;
-  char op;
-  char *newmark, *oldmark;
-  int len;
-  char *line;
-  int i, status;
-
-  oldfp = file1;
-  newfp = file2;
-
-  oldalloc = 512;
-  oldhunk = (char *) xmalloc(oldalloc);
-  newalloc = 512;
-  newhunk = (char *) xmalloc(newalloc);
-
-
-/* The context diff spawns a new process that executes a normal diff
- * and parses the output.
- */
-  if (trim_blanks == SET)
-	sprintf(buff, "diff -b %s %s", old, new);
-  else
-	sprintf(buff, "diff %s %s", old, new);
-
-  inputfp = popen(buff, "r");
-  if (!inputfp) {
-	fprintf(stderr, "Can't execute diff %s %s, popen failed with %s\n",
-		old, new, strerror(errno));
-	exit(2);
-  }
-  preoldend = -1000;
-  firstoutput = 1;
-  oldline = newline = 0;
-  while (fgets(buff, sizeof buff, inputfp) != Nullch) {
-	if (firstoutput) {
-		if (recursive_dir == SET) {
-			printf("diff %s %s %s\n", options_string,
-			       oldfile, newfile);
-		}
-		fstat(fileno(oldfp), &statbuf);
-		printf("*** %s %s", old, ctime(&statbuf.st_mtime));
-		fstat(fileno(newfp), &statbuf);
-		printf("--- %s %s", new, ctime(&statbuf.st_mtime));
-		firstoutput = 0;
-	}
-	if (isdigit(*buff)) {
-		oldmin = atoi(buff);
-		for (s = buff; isdigit(*s); s++);
-		if (*s == ',') {
-			s++;
-			oldmax = atoi(s);
-			for (; isdigit(*s); s++);
-		} else {
-			oldmax = oldmin;
-		}
-		if (*s != 'a' && *s != 'd' && *s != 'c') {
-			fprintf(stderr, "Unparseable input: %s", s);
-			exit(2);
-		}
-		op = *s;
-		s++;
-		newmin = atoi(s);
-		for (; isdigit(*s); s++);
-		if (*s == ',') {
-			s++;
-			newmax = atoi(s);
-			for (; isdigit(*s); s++);
-		} else {
-			newmax = newmin;
-		}
-		if (*s != '\n' && *s != ' ') {
-			fprintf(stderr, "Unparseable input: %s", s);
-			exit(2);
-		}
-		newmark = oldmark = "! ";
-		if (op == 'a') {
-			oldmin++;
-			newmark = "+ ";
-		}
-		if (op == 'd') {
-			newmin++;
-			oldmark = "- ";
-		}
-		oldbeg = oldmin - context_lines;
-		oldend = oldmax + context_lines;
-		if (oldbeg < 1) oldbeg = 1;
-		newbeg = newmin - context_lines;
-		newend = newmax + context_lines;
-		if (newbeg < 1) newbeg = 1;
-
-		if (preoldend < oldbeg - 1) {
-			if (preoldend >= 0) {
-				dumphunk();
-			}
-			preoldbeg = oldbeg;
-			prenewbeg = newbeg;
-			oldwanted = newwanted = 0;
-			oldsize = newsize = 0;
-		} else {	/* we want to append to previous hunk */
-			oldbeg = preoldmax + 1;
-			newbeg = prenewmax + 1;
-		}
-
-		for (i = oldbeg; i <= oldmax; i++) {
-			line = getold(i);
-			if (!line) {
-				oldend = oldmax = i - 1;
-				break;
-			}
-			len = strlen(line) + 2;
-			if (oldsize + len + 1 >= oldalloc) {
-				oldalloc *= 2;
-				oldhunk = (char *) xrealloc(oldhunk, oldalloc);
-			}
-			if (i >= oldmin) {
-				strcpy(oldhunk + oldsize, oldmark);
-				oldwanted++;
-			} else {
-				strcpy(oldhunk + oldsize, "  ");
-			}
-			strcpy(oldhunk + oldsize + 2, line);
-			oldsize += len;
-		}
-		preoldmax = oldmax;
-		preoldend = oldend;
-
-		for (i = newbeg; i <= newmax; i++) {
-			line = getnew(i);
-			if (!line) {
-				newend = newmax = i - 1;
-				break;
-			}
-			len = strlen(line) + 2;
-			if (newsize + len + 1 >= newalloc) {
-				newalloc *= 2;
-				newhunk = (char *) xrealloc(newhunk, newalloc);
-			}
-			if (i >= newmin) {
-				strcpy(newhunk + newsize, newmark);
-				newwanted++;
-			} else {
-				strcpy(newhunk + newsize, "  ");
-			}
-			strcpy(newhunk + newsize + 2, line);
-			newsize += len;
-		}
-		prenewmax = newmax;
-		prenewend = newend;
-	}
-  }
-  status = pclose(inputfp);
-  if (status != 0) diffs++;
-  if (!WIFEXITED(status) || WEXITSTATUS(status) > 1) severe_error = 1;
-
-  if (preoldend >= 0) {
-	dumphunk();
-  }
-}
-
-void dumphunk()
-{
-  int i;
-  char *line;
-  int len;
-
-  for (i = preoldmax + 1; i <= preoldend; i++) {
-	line = getold(i);
-	if (!line) {
-		preoldend = i - 1;
-		break;
-	}
-	len = strlen(line) + 2;
-	if (oldsize + len + 1 >= oldalloc) {
-		oldalloc *= 2;
-		oldhunk = (char *) xrealloc(oldhunk, oldalloc);
-	}
-	strcpy(oldhunk + oldsize, "  ");
-	strcpy(oldhunk + oldsize + 2, line);
-	oldsize += len;
-  }
-  for (i = prenewmax + 1; i <= prenewend; i++) {
-	line = getnew(i);
-	if (!line) {
-		prenewend = i - 1;
-		break;
-	}
-	len = strlen(line) + 2;
-	if (newsize + len + 1 >= newalloc) {
-		newalloc *= 2;
-		newhunk = (char *) xrealloc(newhunk, newalloc);
-	}
-	strcpy(newhunk + newsize, "  ");
-	strcpy(newhunk + newsize + 2, line);
-	newsize += len;
-  }
-  fputs("***************\n", stdout);
-  if (preoldbeg >= preoldend) {
-	printf("*** %d ****\n", preoldend);
-  } else {
-	printf("*** %d,%d ****\n", preoldbeg, preoldend);
-  }
-  if (oldwanted) {
-	fputs(oldhunk, stdout);
-  }
-  oldsize = 0;
-  *oldhunk = '\0';
-  if (prenewbeg >= prenewend) {
-	printf("--- %d ----\n", prenewend);
-  } else {
-	printf("--- %d,%d ----\n", prenewbeg, prenewend);
-  }
-  if (newwanted) {
-	fputs(newhunk, stdout);
-  }
-  newsize = 0;
-  *newhunk = '\0';
-}
-
-char *getold(targ)
-int targ;
-{
-  while (fgets(buff, sizeof buff, oldfp) != Nullch) {
-	oldline++;
-	if (oldline == targ) return buff;
-  }
-  return Nullch;
-}
-
-char *getnew(targ)
-int targ;
-{
-  while (fgets(buff, sizeof buff, newfp) != Nullch) {
-	newline++;
-	if (newline == targ) return buff;
-  }
-  return Nullch;
-}
-
-
-/* Isdir() checks, if <path> is the name of a directory. a return value
- * is 0, <path> is a normal file. otherwise the <path> is a directory.
- */
-int isdir(path)
-char *path;
-{
-  struct stat buf;
-  stat(path, &buf);
-  if (buf.st_mode & S_IFDIR) {	/* path is a directory		 */
-	return(~0);
-  } else {
-	return(0);
-  }
-}
-
-
-
-/* This is the "main" function if a diff of two directories has to be
- * done. diff_recursive() expects the names of the two directories to
- * be compared. 							 */
-void diff_recursive(dir1, dir2)
-char *dir1, *dir2;
-{
-  FILE *ls1, *ls2;
-  char file1[PATH_MAX], file2[PATH_MAX];
-  char jointfile1[PATH_MAX], jointfile2[PATH_MAX];
-  char command[PATH_MAX];
-  int difference, eof1, eof2;
-
-  sprintf(command, "ls %s", dir1);
-  ls1 = popen(command, "r");
-  sprintf(command, "ls %s", dir2);
-  ls2 = popen(command, "r");
-
-  if ((ls1 == NULL) || (ls2 == NULL))
-	fatal_error("cannot execute ls!", "");
-
-  file1[0] = '\0';
-  eof1 = fscanf(ls1, "%s\n", file1);
-  file2[0] = '\0';
-  eof2 = fscanf(ls2, "%s\n", file2);
-
-  while ((file1[0] != '\0') && (file2[0] != '\0')) {
-	difference = strcmp(file1, file2);
-	while (difference != 0) {
-		if (difference < 0) {
-			printf("Only in %s: %s\n", dir1, file1);
-			file1[0] = '\0';
-			eof1 = fscanf(ls1, "%s\n", file1);
-			if (file1[0] == '\0') break;
-		} else {
-			printf("Only in %s: %s\n", dir2, file2);
-			file2[0] = '\0';
-			eof2 = fscanf(ls2, "%s\n", file2);
-			if (file2[0] == '\0') break;
-		}
-		difference = strcmp(file1, file2);
-	}
-	if (eof1 != EOF && eof2 != EOF) {
-		strcpy(jointfile1, dir1);
-		strcat(jointfile1, "/");
-		strcat(jointfile1, file1);
-		strcpy(jointfile2, dir2);
-		strcat(jointfile2, "/");
-		strcat(jointfile2, file2);
-
-		if ((isdir(jointfile1) != 0) && (isdir(jointfile2) != 0)) {
-			printf("Common subdirectories: %s and %s\n",
-			       jointfile1, jointfile2);
-			diff_recursive(jointfile1, jointfile2);
-		} else {
-			firstoutput = 1;
-			strcpy(oldfile, jointfile1);
-			strcpy(newfile, jointfile2);
-			diff(jointfile1, jointfile2);
-		}
-		file1[0] = '\0';
-		eof1 = fscanf(ls1, "%s\n", file1);
-		file2[0] = '\0';
-		eof2 = fscanf(ls2, "%s\n", file2);
-	}
-  }
-
-  if (file1[0] != '\0') {	/* first arg still has files 		 */
-	do {
-		printf("Only in %s: %s\n", dir1, file1);
-		eof1 = fscanf(ls1, " %s\n", file1);
-	} while (eof1 != EOF);
-  }
-  if (file2[0] != '\0') {
-	do {
-		printf("Only in %s: %s\n", dir2, file2);
-		eof2 = fscanf(ls2, " %s\n", file2);
-	} while (eof2 != EOF);
-  }
-  if (pclose(ls1) != 0) severe_error = 1;
-  if (pclose(ls2) != 0) severe_error = 1;
-}
-
-
-/* File_type_error is called, if in a recursive diff ( -r) one of the two
- * files a block special, a character special or a FIFO special file is.
- * The corresponding error message is printed here.			  */
-void file_type_error(filename1, filename2, statbuf1, statbuf2)
-char *filename1, *filename2;
-struct stat *statbuf1, *statbuf2;
-{
-  char type1[25], type2[25];
-
-  switch (statbuf1->st_mode & S_IFMT) {	/* select only file mode */
-      case S_IFREG:
-	sprintf(type1, "regular file ");
-	break;
-      case S_IFBLK:
-	sprintf(type1, "block special file ");
-	break;
-      case S_IFDIR:	sprintf(type1, "directory ");	break;
-      case S_IFCHR:
-	sprintf(type1, "character special file ");
-	break;
-      case S_IFIFO:
-	sprintf(type1, "FIFO special file ");
-	break;
-  }
-
-  switch (statbuf2->st_mode & S_IFMT) {	/* select only file mode */
-      case S_IFREG:
-	sprintf(type2, "regular file ");
-	break;
-      case S_IFBLK:
-	sprintf(type2, "block special file ");
-	break;
-      case S_IFDIR:	sprintf(type2, "directory ");	break;
-      case S_IFCHR:
-	sprintf(type2, "character special file ");
-	break;
-      case S_IFIFO:
-	sprintf(type2, "FIFO special file ");
-	break;
-  }
-  printf("File %s is a %s while file %s is a %s\n",
-         filename1, type1, filename2, type2);
-}
-
-void *xmalloc(size)
-size_t size;
-{
-  void *ptr;
-
-  ptr = malloc(size);
-  if (ptr == NULL) {
-	fprintf(stderr, "%s: out of memory\n", progname);
-	exit(2);
-  }
-  return(ptr);
-}
-
-void *xrealloc(ptr, size)
-void *ptr;
-size_t size;
-{
-  ptr = realloc(ptr, size);
-  if (ptr == NULL) {
-	fprintf(stderr, "%s: out of memory\n", progname);
-	exit(2);
-  }
-  return(ptr);
-}
Index: trunk/minix/commands/simple/dirname.c
===================================================================
--- trunk/minix/commands/simple/dirname.c	(revision 9)
+++ 	(revision )
@@ -1,42 +1,0 @@
-/* dirname - extract the directory name from a path	Author: Peter Holzer */
-
-/* Dirname -- extract directory part from a path name
- *
- * Peter Holzer (hp@vmars.tuwien.ac.at)
- *
- * $Log: dirname.c,v $
- * Revision 1.1.1.1  2005/04/21 14:55:21  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:30  beng
- * Initial import of minix 2.0.4
- *
- * Revision 1.1  1994/02/12  16:15:02  hjp
- * Initial revision
- *
- */
-
-#include <string.h>
-#include <stdio.h>
-
-int main(int argc, char **argv)
-{
-  char *p;
-  char *path;
-
-  if (argc != 2) {
-	fprintf(stderr, "Usage: %s path\n", argv[0]);
-	return(1);
-  }
-  path = argv[1];
-  p = path + strlen(path);
-  while (p > path && p[-1] == '/') p--;	/* trailing slashes */
-  while (p > path && p[-1] != '/') p--;	/* last component */
-  while (p > path && p[-1] == '/') p--;	/* trailing slashes */
-  if (p == path) {
-	printf(path[0] == '/' ? "/\n" : ".\n");
-  } else {
-	printf("%.*s\n", (int) (p - path), path);
-  }
-  return(0);
-}
Index: trunk/minix/commands/simple/du.c
===================================================================
--- trunk/minix/commands/simple/du.c	(revision 9)
+++ 	(revision )
@@ -1,254 +1,0 @@
-/* du - report on disk usage		Author: Alistair G. Crooks */
-
-/*
- *	du.c		1.1	27/5/87		agc	Joypace Ltd.
- *			1.2	24 Mar 89	nick@nswitgould.oz
- *			1.3	31 Mar 89	nick@nswitgould.oz
- *			1.4	22 Feb 90	meulenbr@cst.prl.philips.nl
- *			1.5	09 Jul 91	hp@vmars.tuwien.ac.at
- *			1.6	01 Oct 92	kjb@cs.vu.nl
- *			1.7	04 Jan 93	bde
- *			1.8	19 Sep 94	kjb
- *			1.9	28 Oct 99	kjb
- *
- *	Copyright 1987, Joypace Ltd., London UK. All rights reserved.
- *	This code may be freely distributed, provided that this notice
- *	remains attached.
- *
- *	du - a public domain interpretation of du(1).
- *
- *  1.2: 	Fixed bug involving 14 character long filenames
- *  1.3:	Add [-l levels] option to restrict printing.
- *  1.4:	Added processing of multiple arguments
- *  1.5:	Fixed processing of multiple arguments. General cleanup.
- *  1.6:	Use readdir
- *  1.7:	Merged 1.5 and 1.6.
- *		Print totals even for non-dirs at top level.
- *		Count blocks for each dir before printing total for the dir.
- *		Count blocks for all non-special files.
- *		Don't clutter link buffer with directories.
- *  1.8:	Remember all links.
- *  1.9:	Added -x flag to not cross device boundaries.  Type fixes.
- */
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/statfs.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <minix/config.h>
-#include <minix/const.h>
-
-extern char *optarg;
-extern int optind;
-
-#define	LINELEN		256
-#define	NR_ALREADY	512
-
-#ifdef S_IFLNK
-#define	LSTAT lstat
-#else
-#define	LSTAT stat
-#endif
-
-typedef struct already {
-  struct already *al_next;
-  int al_dev;
-  ino_t al_inum;
-  nlink_t al_nlink;
-} ALREADY;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(int makedname, (char *d, char *f, char *out, int outlen));
-_PROTOTYPE(int done, (Dev_t dev, Ino_t inum, Nlink_t nlink));
-_PROTOTYPE(long dodir, (char *d, int thislev, Dev_t dev));
-
-char *prog;			/* program name */
-char *optstr = "asxdl:";	/* options */
-int silent = 0;			/* silent mode */
-int all = 0;			/* all directory entries mode */
-int crosschk = 0;		/* do not cross device boundaries mode */
-char *startdir = ".";		/* starting from here */
-int levels = 20000;		/* # of directory levels to print */
-ALREADY *already[NR_ALREADY];
-int alc;
-
-
-/*
- *	makedname - make the pathname from the directory name, and the
- *	directory entry, placing it in out. If this would overflow,
- *	return 0, otherwise 1.
- */
-int makedname(d, f, out, outlen)
-char *d;
-char *f;
-char *out;
-int outlen;
-{
-  char *cp;
-  int length;
-
-  length = strlen(f);
-  if (strlen(d) + length + 2 > outlen) return(0);
-  for (cp = out; *d; *cp++ = *d++);
-  if (*(cp - 1) != '/') *cp++ = '/';
-  while (length--) *cp++ = *f++;
-  *cp = '\0';
-  return(1);
-}
-
-/*
- *	done - have we encountered (dev, inum) before? Returns 1 for yes,
- *	0 for no, and remembers (dev, inum, nlink).
- */
-int done(dev, inum, nlink)
-dev_t dev;
-ino_t inum;
-nlink_t nlink;
-{
-  register ALREADY **pap, *ap;
-
-  pap = &already[(unsigned) inum % NR_ALREADY];
-  while ((ap = *pap) != NULL) {
-	if (ap->al_inum == inum && ap->al_dev == dev) {
-		if (--ap->al_nlink == 0) {
-			*pap = ap->al_next;
-			free(ap);
-		}
-		return(1);
-	}
-	pap = &ap->al_next;
-  }
-  if ((ap = malloc(sizeof(*ap))) == NULL) {
-	fprintf(stderr, "du: Out of memory\n");
-	exit(1);
-  }
-  ap->al_next = NULL;
-  ap->al_inum = inum;
-  ap->al_dev = dev;
-  ap->al_nlink = nlink - 1;
-  *pap = ap;
-  return(0);
-}
-
-int get_block_size(char *dir, struct stat *st)
-{
-  struct statfs stfs;
-  static int fs_block_size = -1, fs_dev = -1;
-  int d;
-
-  if(st->st_dev == fs_dev)
-  	return fs_block_size;
-
-  if((d = open(dir, O_RDONLY)) < 0) {
-  	perror(dir);
-  	return 0;
-  }
-
-  if(fstatfs(d, &stfs) < 0) {
-  	perror(dir);
-  	return 0;
-  }
-
-  fs_block_size = stfs.f_bsize;
-  fs_dev = st->st_dev;
-
-  return fs_block_size;
-}
-
-
-/*
- *	dodir - process the directory d. Return the long size (in blocks)
- *	of d and its descendants.
- */
-long dodir(d, thislev, dev)
-char *d;
-int thislev;
-dev_t dev;
-{
-  int maybe_print;
-  struct stat s;
-  long total_kb;
-  char dent[LINELEN];
-  DIR *dp;
-  struct dirent *entry;
-  int block_size;
-
-  if (LSTAT(d, &s) < 0) {
-	fprintf(stderr,
-		"%s: %s: %s\n", prog, d, strerror(errno));
-    	return 0L;
-  }
-  if (s.st_dev != dev && dev != 0 && crosschk) return 0;
-  block_size = get_block_size(d, &s);
-  if(block_size < 1) {
-	fprintf(stderr,
-		"%s: %s: funny block size found (%d)\n", 
-			prog, d, block_size);
-    	return 0L;
-  }
-  total_kb = ((s.st_size + (block_size - 1)) / block_size) * block_size / 1024;
-  switch (s.st_mode & S_IFMT) {
-    case S_IFDIR:
-	/* Directories should not be linked except to "." and "..", so this
-	 * directory should not already have been done.
-	 */
-	maybe_print = !silent;
-	if ((dp = opendir(d)) == NULL) break;
-	while ((entry = readdir(dp)) != NULL) {
-		if (strcmp(entry->d_name, ".") == 0 ||
-		    strcmp(entry->d_name, "..") == 0)
-			continue;
-		if (!makedname(d, entry->d_name, dent, sizeof(dent))) continue;
-		total_kb += dodir(dent, thislev - 1, s.st_dev);
-	}
-	closedir(dp);
-	break;
-    case S_IFBLK:
-    case S_IFCHR:
-	/* st_size for special files is not related to blocks used. */
-	total_kb = 0;
-	/* Fall through. */
-    default:
-	if (s.st_nlink > 1 && done(s.st_dev, s.st_ino, s.st_nlink)) return 0L;
-	maybe_print = all;
-	break;
-  }
-  if (thislev >= levels || (maybe_print && thislev >= 0)) {
-	printf("%ld\t%s\n", total_kb, d);
-  }
-  return(total_kb);
-}
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  int c;
-
-  prog = argv[0];
-  while ((c = getopt(argc, argv, optstr)) != EOF) switch (c) {
-	    case 'a':	all = 1;	break;
-	    case 's':	silent = 1;	break;
-	    case 'x':
-	    case 'd':	crosschk = 1;	break;
-	    case 'l':	levels = atoi(optarg);	break;
-	    default:
-		fprintf(stderr,
-			"Usage: %s [-asx] [-l levels] [startdir]\n", prog);
-		exit(1);
-	}
-  do {
-	if (optind < argc) startdir = argv[optind++];
-	alc = 0;
-	(void) dodir(startdir, levels, 0);
-  } while (optind < argc);
-  return(0);
-}
Index: trunk/minix/commands/simple/ed.c
===================================================================
--- trunk/minix/commands/simple/ed.c	(revision 9)
+++ 	(revision )
@@ -1,2198 +1,0 @@
-/* Copyright 1987 Brian Beattie Rights Reserved.
- *
- * Permission to copy and/or distribute granted under the
- * following conditions:
- *
- * 1). No charge may be made other than resonable charges
- *	for reproduction.
- *
- * 2). This notice must remain intact.
- *
- * 3). No further restrictions may be added.
- *
- */
-
-/*	This program used to be in many little pieces, with this makefile:
-.SUFFIXES:	.c .s
-
-CFLAGS = -F
-
-OBJS =	append.s catsub.s ckglob.s deflt.s del.s docmd.s doglob.s\
-  doprnt.s doread.s dowrite.s ed.s egets.s find.s getfn.s getlst.s\
-  getnum.s getone.s getptr.s getrhs.s gettxt.s ins.s join.s maksub.s\
-  move.s optpat.s set.s setbuf.s subst.s getpat.s matchs.s amatch.s\
-  unmkpat.s omatch.s makepat.s bitmap.s dodash.s esc.s System.s
-
-ed:	$(OBJS)
-  cc -T. -i -o ed $(OBJS)
-*/
-
-#include <sys/types.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <stdio.h>
-
-/****************************/
-
-/*	tools.h	*/
-/*
- *	#defines for non-printing ASCII characters
- */
-
-#define NUL	0x00		/* ^@ */
-#define EOS	0x00		/* end of string */
-#define SOH	0x01		/* ^A */
-#define STX	0x02		/* ^B */
-#define ETX	0x03		/* ^C */
-#define EOT	0x04		/* ^D */
-#define ENQ	0x05		/* ^E */
-#define ACK	0x06		/* ^F */
-#define BEL	0x07		/* ^G */
-#define BS	0x08		/* ^H */
-#define HT	0x09		/* ^I */
-#define LF	0x0a		/* ^J */
-#define NL	'\n'
-#define VT	0x0b		/* ^K */
-#define FF	0x0c		/* ^L */
-#define CR	0x0d		/* ^M */
-#define SO	0x0e		/* ^N */
-#define SI	0x0f		/* ^O */
-#define DLE	0x10		/* ^P */
-#define DC1	0x11		/* ^Q */
-#define DC2	0x12		/* ^R */
-#define DC3	0x13		/* ^S */
-#define DC4	0x14		/* ^T */
-#define NAK	0x15		/* ^U */
-#define SYN	0x16		/* ^V */
-#define ETB	0x17		/* ^W */
-#define CAN	0x18		/* ^X */
-#define EM	0x19		/* ^Y */
-#define SUB	0x1a		/* ^Z */
-#define ESC	0x1b		/* ^[ */
-#define FS	0x1c		/* ^\ */
-#define GS	0x1d		/* ^] */
-#define RS	0x1e		/* ^^ */
-#define US	0x1f		/* ^_ */
-#define SP	0x20		/* space */
-#define DEL	0x7f		/* DEL */
-
-
-#define TRUE	1
-#define FALSE	0
-#define ERR	-2
-
-
-/*	Definitions of meta-characters used in pattern matching
- *	routines.  LITCHAR & NCCL are only used as token identifiers;
- *	all the others are also both token identifier and actual symbol
- *	used in the regular expression.
- */
-
-
-#define BOL	'^'
-#define EOL	'$'
-#define ANY	'.'
-#define LITCHAR	'L'
-#define	ESCAPE	'\\'
-#define CCL	'['		/* Character class: [...] */
-#define CCLEND	']'
-#define NEGATE	'^'
-#define NCCL	'!'		/* Negative character class [^...] */
-#define CLOSURE	'*'
-#define OR_SYM	'|'
-#define DITTO	'&'
-#define OPEN	'('
-#define CLOSE	')'
-
-/* Largest permitted size for an expanded character class.  (i.e. the class
- * [a-z] will expand into 26 symbols; [a-z0-9] will expand into 36.)
- */
-#define CLS_SIZE	128
-
-/*
- *	Tokens are used to hold pattern templates. (see makepat())
- */
-typedef char BITMAP;
-
-typedef struct token {
-  char tok;
-  char lchar;
-  BITMAP *bitmap;
-  struct token *next;
-} TOKEN;
-
-#define TOKSIZE sizeof (TOKEN)
-
-/*
- *	An absolute maximun for strings.
- */
-
-#define MAXSTR	132		/* Maximum numbers of characters in a line */
-
-
-/* Macros */
-#define max(a,b)	((a>b)?a:b)
-#define min(a,b)	((a<b)?a:b)
-#define toupper(c)	(c>='a'&&c<='z'?c-32:c)
-
-/*	ed.h	*/
-#define FATAL	(ERR-1)
-struct line {
-  int l_stat;			/* empty, mark */
-  struct line *l_prev;
-  struct line *l_next;
-  char l_buff[1];
-};
-
-typedef struct line LINE;
-
-#define LINFREE	1		/* entry not in use */
-#define LGLOB	2		/* line marked global */
-
-				/* max number of chars per line */
-#define MAXLINE	(sizeof(int) == 2 ? 256 : 8192)
-#define MAXPAT	256		/* max number of chars per replacement
-				 * pattern */
-				/* max file name size */
-#define MAXFNAME (sizeof(int) == 2 ? 256 : 1024)
-
-extern LINE line0;
-extern int curln, lastln, line1, line2, nlines;
-extern int nflg;		/* print line number flag */
-extern int lflg;		/* print line in verbose mode */
-extern char *inptr;		/* tty input buffer */
-extern char linbuf[], *linptr;	/* current line */
-extern int truncflg;		/* truncate long line flag */
-extern int eightbit;		/* save eighth bit */
-extern int nonascii;		/* count of non-ascii chars read */
-extern int nullchar;		/* count of null chars read */
-extern int truncated;		/* count of lines truncated */
-extern int fchanged;		/* file changed */
-
-#define nextln(l)	((l)+1 > lastln ? 0 : (l)+1)
-#define prevln(l)	((l)-1 < 0 ? lastln : (l)-1)
-
-/*	amatch.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(static char *match, (char *lin, TOKEN *pat, char *boln));
-_PROTOTYPE(char *amatch, (char *lin, TOKEN *pat, char *boln));
-_PROTOTYPE(int append, (int line, int glob));
-_PROTOTYPE(BITMAP *makebitmap, (unsigned size));
-_PROTOTYPE(int setbit, (unsigned c, char *map, unsigned val));
-_PROTOTYPE(int testbit, (unsigned c, char *map));
-_PROTOTYPE(char *catsub, (char *from, char *to, char *sub, char *new, char *newend));
-_PROTOTYPE(int ckglob, (void));
-_PROTOTYPE(int deflt, (int def1, int def2));
-_PROTOTYPE(int del, (int from, int to));
-_PROTOTYPE(int docmd, (int glob));
-_PROTOTYPE(int dolst, (int line1, int line2));
-_PROTOTYPE(char *dodash, (int delim, char *src, char *map));
-_PROTOTYPE(int doglob, (void));
-_PROTOTYPE(int doprnt, (int from, int to));
-_PROTOTYPE(void prntln, (char *str, int vflg, int lin));
-_PROTOTYPE(void putcntl, (int c, FILE *stream));
-_PROTOTYPE(int doread, (int lin, char *fname));
-_PROTOTYPE(int dowrite, (int from, int to, char *fname, int apflg));
-_PROTOTYPE(void intr, (int sig));
-_PROTOTYPE(int egets, (char *str, int size, FILE *stream));
-_PROTOTYPE(int esc, (char **s));
-_PROTOTYPE(int find, (TOKEN *pat, int dir));
-_PROTOTYPE(char *getfn, (void));
-_PROTOTYPE(int getlst, (void));
-_PROTOTYPE(int getnum, (int first));
-_PROTOTYPE(int getone, (void));
-_PROTOTYPE(TOKEN *getpat, (char *arg));
-_PROTOTYPE(LINE *getptr, (int num));
-_PROTOTYPE(int getrhs, (char *sub));
-_PROTOTYPE(char *gettxt, (int num));
-_PROTOTYPE(int ins, (char *str));
-_PROTOTYPE(int System, (char *c));
-_PROTOTYPE(int join, (int first, int last));
-_PROTOTYPE(TOKEN *makepat, (char *arg, int delim));
-_PROTOTYPE(char *maksub, (char *sub, int subsz));
-_PROTOTYPE(char *matchs, (char *line, TOKEN *pat, int ret_endp));
-_PROTOTYPE(int move, (int num));
-_PROTOTYPE(int transfer, (int num));
-_PROTOTYPE(int omatch, (char **linp, TOKEN *pat, char *boln));
-_PROTOTYPE(TOKEN *optpat, (void));
-_PROTOTYPE(int set, (void));
-_PROTOTYPE(int show, (void));
-_PROTOTYPE(void relink, (LINE *a, LINE *x, LINE *y, LINE *b));
-_PROTOTYPE(void clrbuf, (void));
-_PROTOTYPE(void set_buf, (void));
-_PROTOTYPE(int subst, (TOKEN *pat, char *sub, int gflg, int pflag));
-_PROTOTYPE(void unmakepat, (TOKEN *head));
-
-/*     Scans throught the pattern template looking for a match
- * with lin.  Each element of lin is compared with the template
- * until either a mis-match is found or the end of the template
- * is reached.  In the former case a 0 is returned; in the latter,
- * a pointer into lin (pointing to the character following the
- * matched pattern) is returned.
- *
- *	"lin"	is a pointer to the line being searched.
- *	"pat"	is a pointer to a template made by makepat().
- *	"boln"	is a pointer into "lin" which points at the
- *			character at the beginning of the line.
- */
-
-char *paropen[9], *parclose[9];
-int between, parnum;
-
-char *amatch(lin, pat, boln)
-char *lin;
-TOKEN *pat;
-char *boln;
-{
-  between = 0;
-  parnum = 0;
-
-  lin = match(lin, pat, boln);
-
-  if (between) return 0;
-
-  while (parnum < 9) {
-	paropen[parnum] = parclose[parnum] = "";
-	parnum++;
-  }
-  return lin;
-}
-
-static char *match(lin, pat, boln)
-char *lin;
-TOKEN *pat;
-char *boln;
-{
-  register char *bocl, *rval, *strstart;
-
-  if (pat == 0) return 0;
-
-  strstart = lin;
-
-  while (pat) {
-	if (pat->tok == CLOSURE && pat->next) {
-		/* Process a closure: first skip over the closure
-		 * token to the object to be repeated.  This object
-		 * can be a character class. */
-
-		pat = pat->next;
-
-		/* Now match as many occurrences of the closure
-		 * pattern as possible. */
-		bocl = lin;
-
-		while (*lin && omatch(&lin, pat, boln));
-
-		/* 'Lin' now points to the character that made made
-		 * us fail.  Now go on to process the rest of the
-		 * string.  A problem here is a character following
-		 * the closure which could have been in the closure.
-		 * For example, in the pattern "[a-z]*t" (which
-		 * matches any lower-case word ending in a t), the
-		 * final 't' will be sucked up in the while loop.
-		 * So, if the match fails, we back up a notch and try
-		 * to match the rest of the string again, repeating
-		 * this process recursively until we get back to the
-		 * beginning of the closure.  The recursion goes, at
-		 * most two levels deep. */
-
-		if (pat = pat->next) {
-			int savbtwn = between;
-			int savprnm = parnum;
-
-			while (bocl <= lin) {
-				if (rval = match(lin, pat, boln)) {
-					/* Success */
-					return(rval);
-				} else {
-					--lin;
-					between = savbtwn;
-					parnum = savprnm;
-				}
-			}
-			return(0);	/* match failed */
-		}
-	} else if (pat->tok == OPEN) {
-		if (between || parnum >= 9) return 0;
-		paropen[parnum] = lin;
-		between = 1;
-		pat = pat->next;
-	} else if (pat->tok == CLOSE) {
-		if (!between) return 0;
-		parclose[parnum++] = lin;
-		between = 0;
-		pat = pat->next;
-	} else if (omatch(&lin, pat, boln)) {
-		pat = pat->next;
-	} else {
-		return(0);
-	}
-  }
-
-  /* Note that omatch() advances lin to point at the next character to
-   * be matched.  Consequently, when we reach the end of the template,
-   * lin will be pointing at the character following the last character
-   * matched.  The exceptions are templates containing only a BOLN or
-   * EOLN token.  In these cases omatch doesn't advance.
-   * 
-   * A philosophical point should be mentioned here.  Is $ a position or a
-   * character? (i.e. does $ mean the EOL character itself or does it
-   * mean the character at the end of the line.)  I decided here to
-   * make it mean the former, in order to make the behavior of match()
-   * consistent.  If you give match the pattern ^$ (match all lines
-   * consisting only of an end of line) then, since something has to be
-   * returned, a pointer to the end of line character itself is
-   * returned. */
-
-  return((char *) max(strstart, lin));
-}
-
-/*	append.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int append(line, glob)
-int line, glob;
-{
-  int stat;
-  char lin[MAXLINE];
-
-  if (glob) return(ERR);
-  curln = line;
-  while (1) {
-	if (nflg) printf("%6d. ", curln + 1);
-
-	if (fgets(lin, MAXLINE, stdin) == NULL) return(EOF);
-	if (lin[0] == '.' && lin[1] == '\n') return (0);
-	stat = ins(lin);
-	if (stat < 0) return(ERR);
-
-  }
-}
-
-/*	bitmap.c	*/
-/*
- *	BITMAP.C -	makebitmap, setbit, testbit
- *			bit-map manipulation routines.
- *
- *	Copyright (c) Allen I. Holub, all rights reserved.  This program may
- *		for copied for personal, non-profit use only.
- *
- */
-
-#ifdef DEBUG
-/* #include <stdio.h> */
-#endif
-
-/* #include "tools.h" */
-
-
-BITMAP *makebitmap(size)
-unsigned size;
-{
-  /* Make a bit map with "size" bits.  The first entry in the map is an
-   * "unsigned int" representing the maximum bit.  The map itself is
-   * concatenated to this integer. Return a pointer to a map on
-   * success, 0 if there's not enough memory. */
-
-  unsigned *map, numbytes;
-
-  numbytes = (size >> 3) + ((size & 0x07) ? 1 : 0);
-
-#ifdef DEBUG
-  printf("Making a %d bit map (%d bytes required)\n", size, numbytes);
-#endif
-
-  if (map = (unsigned *) malloc(numbytes + sizeof(unsigned))) {
-	*map = size;
-	memset(map + 1, 0, numbytes);
-  }
-
-  return((BITMAP *) map);
-}
-
-int setbit(c, map, val)
-unsigned c, val;
-char *map;
-{
-  /* Set bit c in the map to val. If c > map-size, 0 is returned, else
-   * 1 is returned. */
-
-  if (c >= *(unsigned *) map)	/* if c >= map size */
-	return 0;
-
-  map += sizeof(unsigned);	/* skip past size */
-
-  if (val)
-	map[c >> 3] |= 1 << (c & 0x07);
-  else
-	map[c >> 3] &= ~(1 << (c & 0x07));
-
-  return 1;
-}
-
-int testbit(c, map)
-unsigned c;
-char *map;
-{
-  /* Return 1 if the bit corresponding to c in map is set. 0 if it is not. */
-
-  if (c >= *(unsigned *) map) return 0;
-
-  map += sizeof(unsigned);
-
-  return(map[c >> 3] & (1 << (c & 0x07)));
-}
-
-/*	catsub.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-extern char *paropen[9], *parclose[9];
-
-char *catsub(from, to, sub, new, newend)
-char *from, *to, *sub, *new, *newend;
-{
-  char *cp, *cp2;
-
-  for (cp = new; *sub != EOS && cp < newend;) {
-	if (*sub == DITTO) for (cp2 = from; cp2 < to;) {
-			*cp++ = *cp2++;
-			if (cp >= newend) break;
-		}
-	else if (*sub == ESCAPE) {
-		sub++;
-		if ('1' <= *sub && *sub <= '9') {
-			char *parcl = parclose[*sub - '1'];
-
-			for (cp2 = paropen[*sub - '1']; cp2 < parcl;) {
-				*cp++ = *cp2++;
-				if (cp >= newend) break;
-			}
-		} else
-			*cp++ = *sub;
-	} else
-		*cp++ = *sub;
-
-	sub++;
-  }
-
-  return(cp);
-}
-
-/*	ckglob.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int ckglob()
-{
-  TOKEN *glbpat;
-  char c, delim;
-  char lin[MAXLINE];
-  int num;
-  LINE *ptr;
-
-  c = *inptr;
-
-  if (c != 'g' && c != 'v') return(0);
-
-  if (deflt(1, lastln) < 0) return(ERR);
-
-  delim = *++inptr;
-  if (delim <= ' ') return(ERR);
-
-  glbpat = optpat();
-
-  if (*inptr == delim) inptr++;
-
-  ptr = getptr(1);
-  for (num = 1; num <= lastln; num++) {
-	ptr->l_stat &= ~LGLOB;
-	if (line1 <= num && num <= line2) {
-		strcpy(lin, ptr->l_buff);
-		strcat(lin, "\n");
-		if (matchs(lin, glbpat, 0)) {
-			if (c == 'g') ptr->l_stat |= LGLOB;
-		} else {
-			if (c == 'v') ptr->l_stat |= LGLOB;
-		}
-	}
-	ptr = ptr->l_next;
-  }
-  return(1);
-}
-
-/*	deflt.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int deflt(def1, def2)
-int def1, def2;
-{
-  if (nlines == 0) {
-	line1 = def1;
-	line2 = def2;
-  }
-  if (line1 > line2 || line1 <= 0) return(ERR);
-  return(0);
-}
-
-/*	del.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int del(from, to)
-int from, to;
-{
-  LINE *first, *last, *next, *tmp;
-
-  if (from < 1) from = 1;
-  first = getptr(prevln(from));
-  last = getptr(nextln(to));
-  next = first->l_next;
-  while (next != last && next != &line0) {
-	tmp = next->l_next;
-	free((char *) next);
-	next = tmp;
-  }
-  relink(first, last, first, last);
-  lastln -= (to - from) + 1;
-  curln = prevln(from);
-  return(0);
-}
-
-/*	docmd.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-char fname[MAXFNAME];
-int fchanged;
-extern int nofname;
-
-extern int mark[];
-
-int docmd(glob)
-int glob;
-{
-  static char rhs[MAXPAT];
-  TOKEN *subpat;
-  int c, err, line3;
-  int apflg, pflag, gflag;
-  int nchng;
-  char *fptr;
-
-  pflag = FALSE;
-  while (*inptr == SP && *inptr == HT) inptr++;
-
-  c = *inptr++;
-
-  switch (c) {
-      case NL:
-	if (nlines == 0) {
-		if ((line2 = nextln(curln)) == 0) return(ERR);
-	}
-	curln = line2;
-	return(1);
-	break;
-
-      case '=':	printf("%d\n", line2);	break;
-
-      case 'a':
-	if (*inptr != NL || nlines > 1) return(ERR);
-
-	if (append(line1, glob) < 0) return(ERR);;
-	fchanged = TRUE;
-	break;
-
-      case 'c':
-	if (*inptr != NL) return(ERR);
-
-	if (deflt(curln, curln) < 0) return(ERR);
-
-	if (del(line1, line2) < 0) return(ERR);
-	if (append(curln, glob) < 0) return (ERR);
-	fchanged = TRUE;
-	break;
-
-      case 'd':
-	if (*inptr != NL) return(ERR);
-
-	if (deflt(curln, curln) < 0) return(ERR);
-
-	if (del(line1, line2) < 0) return(ERR);
-	if (nextln(curln) != 0) curln = nextln(curln);
-	fchanged = TRUE;
-	break;
-
-      case 'e':
-	if (nlines > 0) return(ERR);
-	if (fchanged) {
-		fchanged = FALSE;
-		return(ERR);
-	}
-
-	/* FALL THROUGH */
-      case 'E':
-	if (nlines > 0) return(ERR);
-
-	if (*inptr != ' ' && *inptr != HT && *inptr != NL) return(ERR);
-
-	if ((fptr = getfn()) == NULL) return(ERR);
-
-	clrbuf();
-	if ((err = doread(0, fptr)) < 0) return(err);
-
-	strcpy(fname, fptr);
-	fchanged = FALSE;
-	break;
-
-      case 'f':
-	if (nlines > 0) return(ERR);
-
-	if (*inptr != ' ' && *inptr != HT && *inptr != NL) return(ERR);
-
-	if ((fptr = getfn()) == NULL) return(ERR);
-
-	if (nofname)
-		printf("%s\n", fname);
-	else
-		strcpy(fname, fptr);
-	break;
-
-      case 'i':
-	if (*inptr != NL || nlines > 1) return(ERR);
-
-	if (append(prevln(line1), glob) < 0) return(ERR);
-	fchanged = TRUE;
-	break;
-
-      case 'j':
-	if (*inptr != NL || deflt(curln, curln + 1) < 0) return(ERR);
-
-	if (join(line1, line2) < 0) return(ERR);
-	break;
-
-      case 'k':
-	while (*inptr == ' ' || *inptr == HT) inptr++;
-
-	if (*inptr < 'a' || *inptr > 'z') return ERR;
-	c = *inptr++;
-
-	if (*inptr != ' ' && *inptr != HT && *inptr != NL) return(ERR);
-
-	mark[c - 'a'] = line1;
-	break;
-
-      case 'l':
-	if (*inptr != NL) return(ERR);
-	if (deflt(curln, curln) < 0) return (ERR);
-	if (dolst(line1, line2) < 0) return (ERR);
-	break;
-
-      case 'm':
-	if ((line3 = getone()) < 0) return(ERR);
-	if (deflt(curln, curln) < 0) return (ERR);
-	if (move(line3) < 0) return (ERR);
-	fchanged = TRUE;
-	break;
-
-      case 'P':
-      case 'p':
-	if (*inptr != NL) return(ERR);
-	if (deflt(curln, curln) < 0) return (ERR);
-	if (doprnt(line1, line2) < 0) return (ERR);
-	break;
-
-      case 'q':
-	if (fchanged) {
-		fchanged = FALSE;
-		return(ERR);
-	}
-
-	/* FALL THROUGH */
-      case 'Q':
-	if (*inptr == NL && nlines == 0 && !glob)
-		return(EOF);
-	else
-		return(ERR);
-
-      case 'r':
-	if (nlines > 1) return(ERR);
-
-	if (nlines == 0) line2 = lastln;
-
-	if (*inptr != ' ' && *inptr != HT && *inptr != NL) return(ERR);
-
-	if ((fptr = getfn()) == NULL) return(ERR);
-
-	if ((err = doread(line2, fptr)) < 0) return(err);
-	fchanged = TRUE;
-	break;
-
-      case 's':
-	if (*inptr == 'e') return(set());
-	while (*inptr == SP || *inptr == HT) inptr++;
-	if ((subpat = optpat()) == NULL) return (ERR);
-	if ((gflag = getrhs(rhs)) < 0) return (ERR);
-	if (*inptr == 'p') pflag++;
-	if (deflt(curln, curln) < 0) return (ERR);
-	if ((nchng = subst(subpat, rhs, gflag, pflag)) < 0) return (ERR);
-	if (nchng) fchanged = TRUE;
-	break;
-
-      case 't':
-	if ((line3 = getone()) < 0) return(ERR);
-	if (deflt(curln, curln) < 0) return (ERR);
-	if (transfer(line3) < 0) return (ERR);
-	fchanged = TRUE;
-	break;
-
-      case 'W':
-      case 'w':
-	apflg = (c == 'W');
-
-	if (*inptr != ' ' && *inptr != HT && *inptr != NL) return(ERR);
-
-	if ((fptr = getfn()) == NULL) return(ERR);
-
-	if (deflt(1, lastln) < 0) return(ERR);
-	if (dowrite(line1, line2, fptr, apflg) < 0) return (ERR);
-	fchanged = FALSE;
-	break;
-
-      case 'x':
-	if (*inptr == NL && nlines == 0 && !glob) {
-		if ((fptr = getfn()) == NULL) return(ERR);
-		if (dowrite(1, lastln, fptr, 0) >= 0) return (EOF);
-	}
-	return(ERR);
-
-      case 'z':
-	if (deflt(curln, curln) < 0) return(ERR);
-
-	switch (*inptr) {
-	    case '-':
-		if (doprnt(line1 - 21, line1) < 0) return(ERR);
-		break;
-
-	    case '.':
-		if (doprnt(line1 - 11, line1 + 10) < 0) return(ERR);
-		break;
-
-	    case '+':
-	    case '\n':
-		if (doprnt(line1, line1 + 21) < 0) return(ERR);
-		break;
-	}
-	break;
-
-      default:	return(ERR);
-}
-  return(0);
-}
-
-int dolst(line1, line2)
-int line1, line2;
-{
-  int oldlflg = lflg, p;
-
-  lflg = 1;
-  p = doprnt(line1, line2);
-  lflg = oldlflg;
-
-  return p;
-}
-
-/*	dodash.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-
-/*	Expand the set pointed to by *src into dest.
- *	Stop at delim.  Return 0 on error or size of
- *	character class on success.  Update *src to
- *	point at delim.  A set can have one element
- *	{x} or several elements ( {abcdefghijklmnopqrstuvwxyz}
- *	and {a-z} are equivalent ).  Note that the dash
- *	notation is expanded as sequential numbers.
- *	This means (since we are using the ASCII character
- *	set) that a-Z will contain the entire alphabet
- *	plus the symbols: [\]^_`.  The maximum number of
- *	characters in a character class is defined by maxccl.
- */
-char *dodash(delim, src, map)
-int delim;
-char *src, *map;
-{
-
-  register int first, last;
-  char *start;
-
-  start = src;
-
-  while (*src && *src != delim) {
-	if (*src != '-') setbit(esc(&src), map, 1);
-
-	else if (src == start || *(src + 1) == delim)
-		setbit('-', map, 1);
-	else {
-		src++;
-
-		if (*src < *(src - 2)) {
-			first = *src;
-			last = *(src - 2);
-		} else {
-			first = *(src - 2);
-			last = *src;
-		}
-
-		while (++first <= last) setbit(first, map, 1);
-
-	}
-	src++;
-  }
-  return(src);
-}
-
-/*	doglob.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int doglob()
-{
-  int lin, stat;
-  char *cmd;
-  LINE *ptr;
-
-  cmd = inptr;
-
-  while (1) {
-	ptr = getptr(1);
-	for (lin = 1; lin <= lastln; lin++) {
-		if (ptr->l_stat & LGLOB) break;
-		ptr = ptr->l_next;
-	}
-	if (lin > lastln) break;
-
-	ptr->l_stat &= ~LGLOB;
-	curln = lin;
-	inptr = cmd;
-	if ((stat = getlst()) < 0) return(stat);
-	if ((stat = docmd(1)) < 0) return (stat);
-  }
-  return(curln);
-}
-
-/*	doprnt.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int doprnt(from, to)
-int from, to;
-{
-  int i;
-  LINE *lptr;
-
-  from = from < 1 ? 1 : from;
-  to = to > lastln ? lastln : to;
-
-  if (to != 0) {
-	lptr = getptr(from);
-	for (i = from; i <= to; i++) {
-		prntln(lptr->l_buff, lflg, (nflg ? i : 0));
-		lptr = lptr->l_next;
-	}
-	curln = to;
-  }
-  return(0);
-}
-
-void prntln(str, vflg, lin)
-char *str;
-int vflg, lin;
-{
-  if (lin) printf("%7d ", lin);
-  while (*str && *str != NL) {
-	if (*str < ' ' || *str >= 0x7f) {
-		switch (*str) {
-		    case '\t':
-			if (vflg)
-				putcntl(*str, stdout);
-			else
-				putc(*str, stdout);
-			break;
-
-		    case DEL:
-			putc('^', stdout);
-			putc('?', stdout);
-			break;
-
-		    default:
-			putcntl(*str, stdout);
-			break;
-		}
-	} else
-		putc(*str, stdout);
-	str++;
-  }
-  if (vflg) putc('$', stdout);
-  putc('\n', stdout);
-}
-
-void putcntl(c, stream)
-char c;
-FILE *stream;
-{
-  putc('^', stream);
-  putc((c & 31) | '@', stream);
-}
-
-/*	doread.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-extern int diag;
-
-int doread(lin, fname)
-int lin;
-char *fname;
-{
-  FILE *fp;
-  int err;
-  long bytes;
-  int lines;
-  static char str[MAXLINE];
-
-  err = 0;
-  nonascii = nullchar = truncated = 0;
-
-  if (diag) printf("\"%s\" ", fname);
-  if ((fp = fopen(fname, "r")) == NULL) {
-	printf("file open err\n");
-	return(ERR);
-  }
-  curln = lin;
-  for (lines = 0, bytes = 0; (err = egets(str, MAXLINE, fp)) > 0;) {
-	bytes += strlen(str);
-	if (ins(str) < 0) {
-		printf("file insert error\n");
-		err++;
-		break;
-	}
-	lines++;
-  }
-  fclose(fp);
-  if (err < 0) return(err);
-  if (diag) {
-	printf("%d lines %ld bytes", lines, bytes);
-	if (nonascii) printf(" [%d non-ascii]", nonascii);
-	if (nullchar) printf(" [%d nul]", nullchar);
-	if (truncated) printf(" [%d lines truncated]", truncated);
-	printf("\n");
-  }
-  return(err);
-}
-
-/*	dowrite.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int dowrite(from, to, fname, apflg)
-int from, to;
-char *fname;
-int apflg;
-{
-  FILE *fp;
-  int lin, err;
-  int lines;
-  long bytes;
-  char *str;
-  LINE *lptr;
-
-  err = 0;
-
-  lines = bytes = 0;
-  if (diag) printf("\"%s\" ", fname);
-  if ((fp = fopen(fname, (apflg ? "a" : "w"))) == NULL) {
-	printf("file open error\n");
-	return(ERR);
-  }
-  lptr = getptr(from);
-  for (lin = from; lin <= to; lin++) {
-	str = lptr->l_buff;
-	lines++;
-	bytes += strlen(str) + 1;
-	if (fputs(str, fp) == EOF) {
-		printf("file write error\n");
-		err++;
-		break;
-	}
-	fputc('\n', fp);
-	lptr = lptr->l_next;
-  }
-  if (diag) printf("%d lines %ld bytes\n", lines, bytes);
-  fclose(fp);
-  return(err);
-}
-
-/*	ed.c	*/
-/* Copyright 1987 Brian Beattie Rights Reserved.
- *
- * Permission to copy and/or distribute granted under the
- * following conditions:
- *
- * 1). No charge may be made other than resonable charges
- *	for reproduction.
- *
- * 2). This notice must remain intact.
- *
- * 3). No further restrictions may be added.
- *
- */
-/* #include <stdio.h> */
-/* #include <signal.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-#include <setjmp.h>
-jmp_buf env;
-
-LINE line0;
-int curln = 0;
-int lastln = 0;
-char *inptr;
-static char inlin[MAXLINE];
-int nflg, lflg;
-int line1, line2, nlines;
-extern char fname[];
-int version = 1;
-int diag = 1;
-
-void intr(sig)
-int sig;
-{
-  printf("?\n");
-  longjmp(env, 1);
-}
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  int stat, i, doflush;
-
-  set_buf();
-  doflush = isatty(1);
-
-  if (argc > 1 && (strcmp(argv[1], "-") == 0 || strcmp(argv[1], "-s") == 0)) {
-	diag = 0;
-	argc--;
-	argv++;
-  }
-  if (argc > 1) {
-	for (i = 1; i < argc; i++) {
-		if (doread(0, argv[i]) == 0) {
-			curln = 1;
-			strcpy(fname, argv[i]);
-			break;
-		}
-	}
-  }
-  while (1) {
-	setjmp(env);
-	if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, intr);
-
-	if (doflush) fflush(stdout);
-
-	if (fgets(inlin, sizeof(inlin), stdin) == NULL) {
-		break;
-	}
-	for (;;) {
-		inptr = strchr(inlin, EOS);
-		if (inptr >= inlin+2 && inptr[-2] == '\\' && inptr[-1] == NL) {
-			inptr[-1] = 'n';
-			if (fgets(inptr, sizeof(inlin) - (inptr - inlin),
-						stdin) == NULL) break;
-		} else {
-			break;
-		}
-	}
-	if (*inlin == '!') {
-		if ((inptr = strchr(inlin, NL)) != NULL) *inptr = EOS;
-		System(inlin + 1);
-		continue;
-	}
-	inptr = inlin;
-	if (getlst() >= 0)
-		if ((stat = ckglob()) != 0) {
-			if (stat >= 0 && (stat = doglob()) >= 0) {
-				curln = stat;
-				continue;
-			}
-		} else {
-			if ((stat = docmd(0)) >= 0) {
-				if (stat == 1) doprnt(curln, curln);
-				continue;
-			}
-		}
-	if (stat == EOF) {
-		exit(0);
-	}
-	if (stat == FATAL) {
-		fputs("FATAL ERROR\n", stderr);
-		exit(1);
-	}
-	printf("?\n");
-  }
-  return(0);
-}
-
-/*	egets.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int eightbit = 1;		/* save eight bit */
-int nonascii, nullchar, truncated;
-int egets(str, size, stream)
-char *str;
-int size;
-FILE *stream;
-{
-  int c, count;
-  char *cp;
-
-  for (count = 0, cp = str; size > count;) {
-	c = getc(stream);
-	if (c == EOF) {
-		*cp++ = '\n';
-		*cp = EOS;
-		if (count) {
-			printf("[Incomplete last line]\n");
-		}
-		return(count);
-	}
-	if (c == NL) {
-		*cp++ = c;
-		*cp = EOS;
-		return(++count);
-	}
-	if (c > 127) {
-		if (!eightbit)	/* if not saving eighth bit */
-			c = c & 127;	/* strip eigth bit */
-		nonascii++;	/* count it */
-	}
-	if (c) {
-		*cp++ = c;	/* not null, keep it */
-		count++;
-	} else
-		nullchar++;	/* count nulls */
-  }
-  str[count - 1] = EOS;
-  if (c != NL) {
-	printf("truncating line\n");
-	truncated++;
-	while ((c = getc(stream)) != EOF)
-		if (c == NL) break;
-  }
-  return(count);
-}
-
-/*	esc.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-
-/* Map escape sequences into their equivalent symbols.  Returns the
- * correct ASCII character.  If no escape prefix is present then s
- * is untouched and *s is returned, otherwise **s is advanced to point
- * at the escaped character and the translated character is returned.
- */
-int esc(s)
-char **s;
-{
-  register int rval;
-
-
-  if (**s != ESCAPE) {
-	rval = **s;
-  } else {
-	(*s)++;
-
-	switch (toupper(**s)) {
-	    case '\000':	rval = ESCAPE;	break;
-	    case 'S':	rval = ' ';	break;
-	    case 'N':	rval = '\n';	break;
-	    case 'T':	rval = '\t';	break;
-	    case 'B':	rval = '\b';	break;
-	    case 'R':	rval = '\r';	break;
-	    default:	rval = **s;	break;
-	}
-  }
-
-  return(rval);
-}
-
-/*	find.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int find(pat, dir)
-TOKEN *pat;
-int dir;
-{
-  int i, num;
-  char lin[MAXLINE];
-  LINE *ptr;
-
-  num = curln;
-  ptr = getptr(curln);
-  num = (dir ? nextln(num) : prevln(num));
-  ptr = (dir ? ptr->l_next : ptr->l_prev);
-  for (i = 0; i < lastln; i++) {
-	if (num == 0) {
-		num = (dir ? nextln(num) : prevln(num));
-		ptr = (dir ? ptr->l_next : ptr->l_prev);
-	}
-	strcpy(lin, ptr->l_buff);
-	strcat(lin, "\n");
-	if (matchs(lin, pat, 0)) {
-		return(num);
-	}
-	num = (dir ? nextln(num) : prevln(num));
-	ptr = (dir ? ptr->l_next : ptr->l_prev);
-  }
-  return(ERR);
-}
-
-/*	getfn.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-extern char fname[MAXFNAME];
-int nofname;
-
-char *getfn()
-{
-  static char file[256];
-  char *cp;
-
-  if (*inptr == NL) {
-	nofname = TRUE;
-	strcpy(file, fname);
-  } else {
-	nofname = FALSE;
-	while (*inptr == SP || *inptr == HT) inptr++;
-
-	cp = file;
-	while (*inptr && *inptr != NL && *inptr != SP && *inptr != HT) {
-		*cp++ = *inptr++;
-	}
-	*cp = '\0';
-
-	if (strlen(file) == 0) {
-		printf("bad file name\n");
-		return(NULL);
-	}
-  }
-
-  if (strlen(file) == 0) {
-	printf("no file name\n");
-	return(NULL);
-  }
-  return(file);
-}
-
-/*	getlst.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int getlst()
-{
-  int num;
-
-  line2 = 0;
-  for (nlines = 0; (num = getone()) >= 0;) {
-	line1 = line2;
-	line2 = num;
-	nlines++;
-	if (*inptr != ',' && *inptr != ';') break;
-	if (*inptr == ';') curln = num;
-	inptr++;
-  }
-  nlines = min(nlines, 2);
-  if (nlines == 0) line2 = curln;
-  if (nlines <= 1) line1 = line2;
-
-  if (num == ERR)
-	return(num);
-  else
-	return(nlines);
-}
-
-/*	getnum.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int mark['z' - 'a' + 1];
-
-int getnum(first)
-int first;
-{
-  TOKEN *srchpat;
-  int num;
-  char c;
-
-  while (*inptr == SP || *inptr == HT) inptr++;
-
-  if (*inptr >= '0' && *inptr <= '9') {	/* line number */
-	for (num = 0; *inptr >= '0' && *inptr <= '9';) {
-		num = (num * 10) + *inptr - '0';
-		inptr++;
-	}
-	return num;
-  }
-  switch (c = *inptr) {
-      case '.':
-	inptr++;
-	return(curln);
-
-      case '$':
-	inptr++;
-	return(lastln);
-
-      case '/':
-      case '?':
-	srchpat = optpat();
-	if (*inptr == c) inptr++;
-	return(find(srchpat, c == '/' ? 1 : 0));
-
-      case '-':
-      case '+':
-	return(first ? curln : 1);
-
-      case '\'':
-	inptr++;
-	if (*inptr < 'a' || *inptr > 'z') return(EOF);
-
-	return mark[*inptr++ - 'a'];
-
-      default:
-	return(first ? EOF : 1);/* unknown address */
-  }
-}
-
-/*	getone.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-#define FIRST 1
-#define NOTFIRST 0
-
-int getone()
-{
-  int c, i, num;
-
-  if ((num = getnum(FIRST)) >= 0) {
-	while (1) {
-		while (*inptr == SP || *inptr == HT) inptr++;
-
-		if (*inptr != '+' && *inptr != '-') break;
-		c = *inptr++;
-
-		if ((i = getnum(NOTFIRST)) < 0) return(i);
-
-		if (c == '+') {
-			num += i;
-		} else {
-			num -= i;
-		}
-	}
-  }
-  return(num > lastln ? ERR : num);
-}
-
-/*	getpat.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-
-/* Translate arg into a TOKEN string */
-TOKEN *
- getpat(arg)
-char *arg;
-{
-
-  return(makepat(arg, '\000'));
-}
-
-/*	getptr.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-LINE *
- getptr(num)
-int num;
-{
-  LINE *ptr;
-  int j;
-
-  if (2 * num > lastln && num <= lastln) {	/* high line numbers */
-	ptr = line0.l_prev;
-	for (j = lastln; j > num; j--) ptr = ptr->l_prev;
-  } else {			/* low line numbers */
-	ptr = &line0;
-	for (j = 0; j < num; j++) ptr = ptr->l_next;
-  }
-  return(ptr);
-}
-
-/*	getrhs.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int getrhs(sub)
-char *sub;
-{
-  if (inptr[0] == NL || inptr[1] == NL)	/* check for eol */
-	return(ERR);
-
-  if (maksub(sub, MAXPAT) == NULL) return(ERR);
-
-  inptr++;			/* skip over delimter */
-  while (*inptr == SP || *inptr == HT) inptr++;
-  if (*inptr == 'g') {
-	inptr++;
-	return(1);
-  }
-  return(0);
-}
-
-/*	gettxt.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-char *
- gettxt(num)
-int num;
-{
-  LINE *lin;
-  static char txtbuf[MAXLINE];
-
-  lin = getptr(num);
-  strcpy(txtbuf, lin->l_buff);
-  strcat(txtbuf, "\n");
-  return(txtbuf);
-}
-
-/*	ins.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int ins(str)
-char *str;
-{
-  char buf[MAXLINE], *cp;
-  LINE *new, *cur, *nxt;
-
-  cp = buf;
-  while (1) {
-	if ((*cp = *str++) == NL) *cp = EOS;
-	if (*cp) {
-		cp++;
-		continue;
-	}
-	if ((new = (LINE *) malloc(sizeof(LINE) + strlen(buf))) == NULL)
-		return(ERR);	/* no memory */
-
-	new->l_stat = 0;
-	strcpy(new->l_buff, buf);	/* build new line */
-	cur = getptr(curln);	/* get current line */
-	nxt = cur->l_next;	/* get next line */
-	relink(cur, new, new, nxt);	/* add to linked list */
-	relink(new, nxt, cur, new);
-	lastln++;
-	curln++;
-
-	if (*str == EOS)	/* end of line ? */
-		return(1);
-
-	cp = buf;
-  }
-}
-
-/*	join.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-extern int fchanged;
-
-int join(first, last)
-int first, last;
-{
-  char buf[MAXLINE];
-  char *cp = buf, *str;
-  int num;
-
-  if (first <= 0 || first > last || last > lastln) return(ERR);
-  if (first == last) {
-	curln = first;
-	return 0;
-  }
-  for (num = first; num <= last; num++) {
-	str = gettxt(num);
-
-	while (*str != NL && cp < buf + MAXLINE - 1) *cp++ = *str++;
-
-	if (cp == buf + MAXLINE - 1) {
-		printf("line too long\n");
-		return(ERR);
-	}
-  }
-  *cp++ = NL;
-  *cp = EOS;
-  del(first, last);
-  curln = first - 1;
-  ins(buf);
-  fchanged = TRUE;
-  return 0;
-}
-
-/*	makepat.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-
-/* Make a pattern template from the strinng pointed to by arg.  Stop
- * when delim or '\000' or '\n' is found in arg.  Return a pointer to
- * the pattern template.
- *
- * The pattern template used here are somewhat different than those
- * used in the "Software Tools" book; each token is a structure of
- * the form TOKEN (see tools.h).  A token consists of an identifier,
- * a pointer to a string, a literal character and a pointer to another
- * token.  This last is 0 if there is no subsequent token.
- *
- * The one strangeness here is caused (again) by CLOSURE which has
- * to be put in front of the previous token.  To make this insertion a
- * little easier, the 'next' field of the last to point at the chain
- * (the one pointed to by 'tail) is made to point at the previous node.
- * When we are finished, tail->next is set to 0.
- */
-TOKEN *
- makepat(arg, delim)
-char *arg;
-int delim;
-{
-  TOKEN *head, *tail, *ntok;
-  int error;
-
-  /* Check for characters that aren't legal at the beginning of a template. */
-
-  if (*arg == '\0' || *arg == delim || *arg == '\n' || *arg == CLOSURE)
-	return(0);
-
-  error = 0;
-  tail = head = NULL;
-
-  while (*arg && *arg != delim && *arg != '\n' && !error) {
-	ntok = (TOKEN *) malloc(TOKSIZE);
-	ntok->lchar = '\000';
-	ntok->next = 0;
-
-	switch (*arg) {
-	    case ANY:	ntok->tok = ANY;	break;
-
-	    case BOL:
-		if (head == 0)	/* then this is the first symbol */
-			ntok->tok = BOL;
-		else
-			ntok->tok = LITCHAR;
-		ntok->lchar = BOL;
-		break;
-
-	    case EOL:
-		if (*(arg + 1) == delim || *(arg + 1) == '\000' ||
-		    *(arg + 1) == '\n') {
-			ntok->tok = EOL;
-		} else {
-			ntok->tok = LITCHAR;
-			ntok->lchar = EOL;
-		}
-		break;
-
-	    case CLOSURE:
-		if (head != 0) {
-			switch (tail->tok) {
-			    case BOL:
-			    case EOL:
-			    case CLOSURE:
-				return(0);
-
-			    default:
-				ntok->tok = CLOSURE;
-			}
-		}
-		break;
-
-	    case CCL:
-
-		if (*(arg + 1) == NEGATE) {
-			ntok->tok = NCCL;
-			arg += 2;
-		} else {
-			ntok->tok = CCL;
-			arg++;
-		}
-
-		if (ntok->bitmap = makebitmap(CLS_SIZE))
-			arg = dodash(CCLEND, arg, ntok->bitmap);
-		else {
-			fprintf(stderr, "Not enough memory for pat\n");
-			error = 1;
-		}
-		break;
-
-	    default:
-		if (*arg == ESCAPE && *(arg + 1) == OPEN) {
-			ntok->tok = OPEN;
-			arg++;
-		} else if (*arg == ESCAPE && *(arg + 1) == CLOSE) {
-			ntok->tok = CLOSE;
-			arg++;
-		} else {
-			ntok->tok = LITCHAR;
-			ntok->lchar = esc(&arg);
-		}
-	}
-
-	if (error || ntok == 0) {
-		unmakepat(head);
-		return(0);
-	} else if (head == 0) {
-		/* This is the first node in the chain. */
-
-		ntok->next = 0;
-		head = tail = ntok;
-	} else if (ntok->tok != CLOSURE) {
-		/* Insert at end of list (after tail) */
-
-		tail->next = ntok;
-		ntok->next = tail;
-		tail = ntok;
-	} else if (head != tail) {
-		/* More than one node in the chain.  Insert the
-		 * CLOSURE node immediately in front of tail. */
-
-		(tail->next)->next = ntok;
-		ntok->next = tail;
-	} else {
-		/* Only one node in the chain,  Insert the CLOSURE
-		 * node at the head of the linked list. */
-
-		ntok->next = head;
-		tail->next = ntok;
-		head = ntok;
-	}
-	arg++;
-  }
-
-  tail->next = 0;
-  return(head);
-}
-
-/*	maksub.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-char *
- maksub(sub, subsz)
-char *sub;
-int subsz;
-{
-  int size;
-  char delim, *cp;
-
-  size = 0;
-  cp = sub;
-
-  delim = *inptr++;
-  for (size = 0; *inptr != delim && *inptr != NL && size < subsz; size++) {
-	if (*inptr == '&') {
-		*cp++ = DITTO;
-		inptr++;
-	} else if ((*cp++ = *inptr++) == ESCAPE) {
-		if (size >= subsz) return(NULL);
-
-		switch (toupper(*inptr)) {
-		    case NL:	*cp++ = ESCAPE;		break;
-			break;
-		    case 'S':
-			*cp++ = SP;
-			inptr++;
-			break;
-		    case 'N':
-			*cp++ = NL;
-			inptr++;
-			break;
-		    case 'T':
-			*cp++ = HT;
-			inptr++;
-			break;
-		    case 'B':
-			*cp++ = BS;
-			inptr++;
-			break;
-		    case 'R':
-			*cp++ = CR;
-			inptr++;
-			break;
-		    case '0':{
-				int i = 3;
-				*cp = 0;
-				do {
-					if (*++inptr < '0' || *inptr > '7')
-						break;
-
-					*cp = (*cp << 3) | (*inptr - '0');
-				} while (--i != 0);
-				cp++;
-			} break;
-		    default:	*cp++ = *inptr++;	break;
-		}
-	}
-  }
-  if (size >= subsz) return(NULL);
-
-  *cp = EOS;
-  return(sub);
-}
-
-/*	matchs.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-
-/* Compares line and pattern.  Line is a character string while pat
- * is a pattern template made by getpat().
- * Returns:
- *	1. A zero if no match was found.
- *
- *	2. A pointer to the last character satisfing the match
- *	   if ret_endp is non-zero.
- *
- *	3. A pointer to the beginning of the matched string if
- *	   ret_endp is zero.
- *
- * e.g.:
- *
- *	matchs ("1234567890", getpat("4[0-9]*7), 0);
- * will return a pointer to the '4', while:
- *
- *	matchs ("1234567890", getpat("4[0-9]*7), 1);
- * will return a pointer to the '7'.
- */
-char *
- matchs(line, pat, ret_endp)
-char *line;
-TOKEN *pat;
-int ret_endp;
-{
-
-  char *rval, *bptr;
-  char *line2;
-  TOKEN *pat2;
-  char c;
-  short ok;
-
-  bptr = line;
-
-  while (*line) {
-
-	if (pat && pat->tok == LITCHAR) {
-		while (*line) {
-			pat2 = pat;
-			line2 = line;
-			if (*line2 != pat2->lchar) {
-				c = pat2->lchar;
-				while (*line2 && *line2 != c) ++line2;
-				line = line2;
-				if (*line2 == '\0') break;
-			}
-			ok = 1;
-			++line2;
-			pat2 = pat2->next;
-			while (pat2 && pat2->tok == LITCHAR) {
-				if (*line2 != pat2->lchar) {
-					ok = 0;
-					break;
-				}
-				++line2;
-				pat2 = pat2->next;
-			}
-			if (!pat2) {
-				if (ret_endp)
-					return(--line2);
-				else
-					return(line);
-			} else if (ok)
-				break;
-			++line;
-		}
-		if (*line == '\0') return(0);
-	} else {
-		line2 = line;
-		pat2 = pat;
-	}
-	if ((rval = amatch(line2, pat2, bptr)) == 0) {
-		if (pat && pat->tok == BOL) break;
-		line++;
-	} else {
-		if (rval > bptr && rval > line)
-			rval--;	/* point to last char matched */
-		rval = ret_endp ? rval : line;
-		break;
-	}
-  }
-  return(rval);
-}
-
-/*	move.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int move(num)
-int num;
-{
-  LINE *k0, *k1, *k2, *k3;
-
-  if (line1 <= 0 || line2 < line1 || (line1 <= num && num <= line2))
-	return(ERR);
-  k0 = getptr(prevln(line1));
-  k1 = getptr(line1);
-  k2 = getptr(line2);
-  k3 = getptr(nextln(line2));
-
-  relink(k0, k3, k0, k3);
-  lastln -= line2 - line1 + 1;
-
-  if (num > line1) num -= line2 - line1 + 1;
-
-  curln = num + (line2 - line1 + 1);
-
-  k0 = getptr(num);
-  k3 = getptr(nextln(num));
-
-  relink(k0, k1, k2, k3);
-  relink(k2, k3, k0, k1);
-  lastln += line2 - line1 + 1;
-
-  return(1);
-}
-
-int transfer(num)
-int num;
-{
-  int mid, lin, ntrans;
-
-  if (line1 <= 0 || line1 > line2) return(ERR);
-
-  mid = num < line2 ? num : line2;
-
-  curln = num;
-  ntrans = 0;
-
-  for (lin = line1; lin <= mid; lin++) {
-	ins(gettxt(lin));
-	ntrans++;
-  }
-  lin += ntrans;
-  line2 += ntrans;
-
-  for (; lin <= line2; lin += 2) {
-	ins(gettxt(lin));
-	line2++;
-  }
-  return(1);
-}
-
-/*	omatch.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-
-/* Match one pattern element, pointed at by pat, with the character at
- * **linp.  Return non-zero on match.  Otherwise, return 0.  *Linp is
- * advanced to skip over the matched character; it is not advanced on
- * failure.  The amount of advance is 0 for patterns that match null
- * strings, 1 otherwise.  "boln" should point at the position that will
- * match a BOL token.
- */
-int omatch(linp, pat, boln)
-char **linp;
-TOKEN *pat;
-char *boln;
-{
-
-  register int advance;
-
-  advance = -1;
-
-  if (**linp) {
-	switch (pat->tok) {
-	    case LITCHAR:
-		if (**linp == pat->lchar) advance = 1;
-		break;
-
-	    case BOL:
-		if (*linp == boln) advance = 0;
-		break;
-
-	    case ANY:
-		if (**linp != '\n') advance = 1;
-		break;
-
-	    case EOL:
-		if (**linp == '\n') advance = 0;
-		break;
-
-	    case CCL:
-		if (testbit(**linp, pat->bitmap)) advance = 1;
-		break;
-
-	    case NCCL:
-		if (!testbit(**linp, pat->bitmap)) advance = 1;
-		break;
-	}
-  }
-  if (advance >= 0) *linp += advance;
-
-  return(++advance);
-}
-
-/*	optpat.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-TOKEN *oldpat;
-
-TOKEN *
- optpat()
-{
-  char delim, str[MAXPAT], *cp;
-
-  delim = *inptr++;
-  cp = str;
-  while (*inptr != delim && *inptr != NL) {
-	if (*inptr == ESCAPE && inptr[1] != NL) *cp++ = *inptr++;
-	*cp++ = *inptr++;
-  }
-
-  *cp = EOS;
-  if (*str == EOS) return(oldpat);
-  if (oldpat) unmakepat(oldpat);
-  oldpat = getpat(str);
-  return(oldpat);
-}
-
-/*	set.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-struct tbl {
-  char *t_str;
-  int *t_ptr;
-  int t_val;
-} *t, tbl[] = {
-
-  "number", &nflg, TRUE,
-  "nonumber", &nflg, FALSE,
-  "list", &lflg, TRUE,
-  "nolist", &lflg, FALSE,
-  "eightbit", &eightbit, TRUE,
-  "noeightbit", &eightbit, FALSE,
-  0
-};
-
-int set()
-{
-  char word[16];
-  int i;
-
-  inptr++;
-  if (*inptr != 't') {
-	if (*inptr != SP && *inptr != HT && *inptr != NL) return(ERR);
-  } else
-	inptr++;
-
-  if (*inptr == NL) return(show());
-  /* Skip white space */
-  while (*inptr == SP || *inptr == HT) inptr++;
-
-  for (i = 0; *inptr != SP && *inptr != HT && *inptr != NL;)
-	word[i++] = *inptr++;
-  word[i] = EOS;
-  for (t = tbl; t->t_str; t++) {
-	if (strcmp(word, t->t_str) == 0) {
-		*t->t_ptr = t->t_val;
-		return(0);
-	}
-  }
-  return(0);
-}
-
-int show()
-{
-  extern int version;
-
-  printf("ed version %d.%d\n", version / 100, version % 100);
-  printf("number %s, list %s\n", nflg ? "ON" : "OFF", lflg ? "ON" : "OFF");
-  return(0);
-}
-
-/*	setbuf.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-void relink(a, x, y, b)
-LINE *a, *x, *y, *b;
-{
-  x->l_prev = a;
-  y->l_next = b;
-}
-
-void clrbuf()
-{
-  del(1, lastln);
-}
-
-void set_buf()
-{
-  relink(&line0, &line0, &line0, &line0);
-  curln = lastln = 0;
-}
-
-/*	subst.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-/* #include "ed.h" */
-
-int subst(pat, sub, gflg, pflag)
-TOKEN *pat;
-char *sub;
-int gflg, pflag;
-{
-  int lin, chngd, nchngd;
-  char *txtptr, *txt;
-  char *lastm, *m, *new, buf[MAXLINE];
-
-  if (line1 <= 0) return(ERR);
-  nchngd = 0;			/* reset count of lines changed */
-  for (lin = line1; lin <= line2; lin++) {
-	txt = txtptr = gettxt(lin);
-	new = buf;
-	chngd = 0;
-	lastm = NULL;
-	while (*txtptr) {
-		if (gflg || !chngd)
-			m = amatch(txtptr, pat, txt);
-		else
-			m = NULL;
-		if (m != NULL && lastm != m) {
-			chngd++;
-			new = catsub(txtptr, m, sub, new,
-				     buf + MAXLINE);
-			lastm = m;
-		}
-		if (m == NULL || m == txtptr) {
-			*new++ = *txtptr++;
-		} else {
-			txtptr = m;
-		}
-	}
-	if (chngd) {
-		if (new >= buf + MAXLINE) return(ERR);
-		*new++ = EOS;
-		del(lin, lin);
-		ins(buf);
-		nchngd++;
-		if (pflag) doprnt(curln, curln);
-	}
-  }
-  if (nchngd == 0 && !gflg) {
-	return(ERR);
-  }
-  return(nchngd);
-}
-
-/*	System.c	*/
-#define SHELL	"/bin/sh"
-#define SHELL2	"/usr/bin/sh"
-
-int System(c)
-char *c;
-{
-  int pid, status;
-
-  switch (pid = fork()) {
-      case -1:
-	return -1;
-      case 0:
-	execl(SHELL, "sh", "-c", c, (char *) 0);
-	execl(SHELL2, "sh", "-c", c, (char *) 0);
-	exit(-1);
-      default:	while (wait(&status) != pid);
-}
-  return status;
-}
-
-/*	unmkpat.c	*/
-/* #include <stdio.h> */
-/* #include "tools.h" */
-
-/* Free up the memory usde for token string */
-void unmakepat(head)
-TOKEN *head;
-{
-
-  register TOKEN *old_head;
-
-  while (head) {
-	switch (head->tok) {
-	    case CCL:
-	    case NCCL:
-		free(head->bitmap);
-		/* Fall through to default */
-
-	    default:
-		old_head = head;
-		head = head->next;
-		free((char *) old_head);
-		break;
-	}
-  }
-}
Index: trunk/minix/commands/simple/eject.c
===================================================================
--- trunk/minix/commands/simple/eject.c	(revision 9)
+++ 	(revision )
@@ -1,39 +1,0 @@
-/*	eject 1.3 - Eject removable media		Author: Kees J. Bot
- *								11 Dec 1993
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/ioctl.h>
-
-void fatal(char *label)
-{
-	fprintf(stderr, "eject: %s: %s\n", label, strerror(errno));
-	exit(1);
-}
-
-void main(int argc, char **argv)
-{
-	char *device;
-	int fd;
-
-	if (argc != 2) {
-		fprintf(stderr, "Usage: eject <device>\n");
-		exit(1);
-	}
-
-	device= argv[1];
-
-	/* Try to open it in whatever mode. */
-	fd= open(device, O_RDONLY);
-	if (fd < 0 && errno == EACCES) fd= open(device, O_WRONLY);
-	if (fd < 0) fatal(device);
-
-	/* Tell it to eject. */
-	if (ioctl(fd, DIOCEJECT, nil) < 0) fatal(device);
-	exit(0);
-}
Index: trunk/minix/commands/simple/env.c
===================================================================
--- trunk/minix/commands/simple/env.c	(revision 9)
+++ 	(revision )
@@ -1,83 +1,0 @@
-/*	env 1.1 - Set environment for command		Author: Kees J. Bot
- *								17 Dec 1997
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-int main(int argc, char **argv)
-{
-	int i;
-	int iflag= 0;
-	int aflag= 0;
-	extern char **environ;
-
-	i= 1;
-	while (i < argc && argv[i][0] == '-') {
-		char *opt= argv[i++] + 1;
-
-		if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-		if (opt[0] == 0) iflag= 1;			/* - */
-
-		while (*opt != 0) switch (*opt++) {
-		case 'i':
-			iflag= 1;	/* Clear environment. */
-			break;
-		case 'a':		/* Specify arg 0 separately. */
-			aflag= 1;
-			break;
-		default:
-			fprintf(stderr,
-		"Usage: env [-ia] [name=value] ... [utility [argument ...]]\n");
-			exit(1);
-		}
-	}
-
-	/* Clear the environment if -i. */
-	if (iflag) *environ= nil;
-
-	/* Set the new environment strings. */
-	while (i < argc && strchr(argv[i], '=') != nil) {
-		if (putenv(argv[i]) != 0) {
-			fprintf(stderr, "env: Setting '%s' failed: %s\n",
-				argv[i], strerror(errno));
-			exit(1);
-		}
-		i++;
-	}
-
-	/* Environment settings and command may be separated with '--'.
-	 * This is for compatibility with other envs, we don't advertise it.
-	 */
-	if (i < argc && strcmp(argv[i], "--") == 0) i++;
-
-	if (i >= argc) {
-		/* No utility given; print environment. */
-		char **ep;
-
-		for (ep= environ; *ep != nil; ep++) {
-			if (puts(*ep) == EOF) {
-				fprintf(stderr, "env: %s\n", strerror(errno));
-				exit(1);
-			}
-		}
-		return 0;
-	} else {
-		char *util, **args;
-		int err;
-
-		util= argv[i];
-		args= argv + i;
-		if (aflag) args++;
-		(void) execvp(util, args);
-		err= errno;
-		fprintf(stderr, "env: Can't execute %s: %s\n",
-			util, strerror(err));
-		return err == ENOENT ? 127 : 126;
-	}
-}
Index: trunk/minix/commands/simple/expand.c
===================================================================
--- trunk/minix/commands/simple/expand.c	(revision 9)
+++ 	(revision )
@@ -1,99 +1,0 @@
-/*  expand - expand tabs to spaces	Author: Terrence W. Holm */
-
-/*  Usage:  expand  [ -tab1,tab2,tab3,... ]  [ file ... ]  */
-
-#include <stddef.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define MAX_TABS 32
-
-int column = 0;			/* Current column, retained between files  */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void Expand, (FILE *f, int tab_index, int tabs []));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int tabs[MAX_TABS];
-  int tab_index = 0;		/* Default one tab   */
-  int i;
-  FILE *f;
-
-  tabs[0] = 8;			/* Default tab stop  */
-
-  if (argc > 1 && argv[1][0] == '-') {
-	char *p = argv[1];
-	int last_tab_stop = 0;
-
-	for (tab_index = 0; tab_index < MAX_TABS; ++tab_index) {
-		if ((tabs[tab_index] = atoi(p + 1)) <= last_tab_stop) {
-			fprintf(stderr, "Bad tab stop spec\n");
-			exit(1);
-		}
-		last_tab_stop = tabs[tab_index];
-
-		if ((p = strchr(p + 1, ',')) == NULL) break;
-	}
-
-	--argc;
-	++argv;
-  }
-  if (argc == 1)
-	Expand(stdin, tab_index, tabs);
-  else
-	for (i = 1; i < argc; ++i) {
-		if ((f = fopen(argv[i], "r")) == NULL) {
-			perror(argv[i]);
-			exit(1);
-		}
-		Expand(f, tab_index, tabs);
-		fclose(f);
-	}
-
-  return(0);
-}
-
-
-void Expand(f, tab_index, tabs)
-FILE *f;
-int tab_index;
-int tabs[];
-{
-  int next;
-  int c;
-  int i;
-
-  while ((c = getc(f)) != EOF) {
-	if (c == '\t') {
-		if (tab_index == 0)
-			next = (column / tabs[0] + 1) * tabs[0];
-		else {
-			for (i = 0; i <= tab_index && tabs[i] <= column; ++i);
-
-			if (i > tab_index)
-				next = column + 1;
-			else
-				next = tabs[i];
-		}
-
-		do {
-			++column;
-			putchar(' ');
-		} while (column < next);
-
-		continue;
-	}
-	if (c == '\b')
-		column = column > 0 ? column - 1 : 0;
-	else if (c == '\n' || c == '\r')
-		column = 0;
-	else
-		++column;
-
-	putchar(c);
-  }
-}
Index: trunk/minix/commands/simple/factor.c
===================================================================
--- trunk/minix/commands/simple/factor.c	(revision 9)
+++ 	(revision )
@@ -1,53 +1,0 @@
-/* factor - print the prime factors of a number      Author: Andy Tanenbaum */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(long first, (long k));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-/* Factor a number */
-
-  long i, n, flag = 0;
-
-  if (argc != 2 || (n = atol(argv[1])) < 2) {
-	printf("Usage: factor n   (2 <= n < 2**31)\n");
-	exit(1);
-  }
-  if (n == 2) {
-	printf("2 is a prime\n");
-	exit(0);
-  }
-  while (1) {
-	i = first(n);
-	if (i == 0) {
-		if (flag == 0)
-			printf("%ld is a prime\n", n);
-		else
-			printf("%ld\n", n);
-		exit(0);
-	}
-	printf("%ld ", i);
-	n = n / i;
-	flag = 1;
-  }
-}
-
-
-long first(k)
-long k;
-{
-/* Return the first factor of k.  If it is a prime, return 0; */
-
-  long i;
-
-  if (k == 2) return(0);
-  if (k % 2 == 0) return (2);
-  for (i = 3; i <= k / 3; i += 2)
-	if (k % i == 0) return(i);
-  return(0);
-}
Index: trunk/minix/commands/simple/fgrep.c
===================================================================
--- trunk/minix/commands/simple/fgrep.c	(revision 9)
+++ 	(revision )
@@ -1,354 +1,0 @@
-/* fgrep - fast grep			Author: Bert Gijsbers */
-
-/* Copyright (c) 1991 by Bert Gijsbers.  All rights reserved.
- * Permission to use and redistribute this software is hereby granted provided
- * that this copyright notice remains intact and that any modifications are
- * clearly marked as such.
- *
- * syntax:
- *	fgrep -chlnsv <[-e string] ... [-f file] ... | string> [file] ...
- * options:
- *	-c : print the number of matching lines
- *	-h : don't print file name headers if more than one file
- *	-l : print only the file names of the files containing a match
- *	-n : print line numbers
- *	-s : don't print, return status only
- *	-v : reverse, lines not containing one of the strings match
- *	-e string : search for this string
- *	-f file : file contains strings to search for
- * notes:
- *	Options are processed by getopt(3).
- *	Multiple strings per command line are supported, eg.
- *		fgrep -e str1 -e str2 *.c
- *	Instead of a filename - is allowed, meaning standard input.
- */
-
-/* #include <ansi.h> */
-#include <sys/types.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#define MAX_STR_LEN	 256	/* maximum length of strings to search for */
-#define BYTE		0xFF	/* convert from char to int */
-#define READ_SIZE	4096	/* read() request size */
-#define BUF_SIZE (2*READ_SIZE)	/* size of buffer */
-
-typedef struct test_str {
-  struct test_str *next;	/* linked list */
-  char *str;			/* string to be found */
-  char *str_end;		/* points to last character */
-  int len;			/* string length */
-  char *bufp;			/* pointer into input buffer */
-  unsigned char table[256];	/* table for Boyer-Moore algorithm */
-} test_str;
-
-test_str *strings;
-char *prog_name;
-int cflag, hflag, lflag, nflag, sflag, vflag;
-unsigned line_num;		/* line number in current file */
-
-int fd_in, eof_seen;		/* file descriptor for input and eof status */
-char input_buffer[BUF_SIZE + 2];/* buffer + sentinel margin */
-#define buffer	(&input_buffer[2])
-
-/* Pointers into the input buffer */
-char *input;			/* points to current input char */
-char *max_input;		/* points to first invalid char */
-char *buf_end;			/* points to first char not read */
-
-/* Error messages */
-char no_mem[] = "not enough memory";
-char no_arg[] = "argument missing";
-
-extern char *optarg;
-extern int optind;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(char *search_str, (test_str * ts));
-_PROTOTYPE(int fill_buffer, (void));
-_PROTOTYPE(void failure, (char *mesg));
-_PROTOTYPE(void file_open, (void));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(char *get_line, (void));
-_PROTOTYPE(void string_file, (void));
-_PROTOTYPE(void add_string, (char *str));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  char *line;
-  int c;
-  unsigned count;		/* number of matching lines in current file */
-  unsigned found_one = 0;	/* was there any match in any file at all ? */
-
-#ifdef noperprintf
-  noperprintf(stdout);
-#else
-  static char outbuf[BUFSIZ];
-
-  setvbuf(stdout, outbuf, _IOFBF, sizeof outbuf);
-#endif
-
-  prog_name = argv[0];
-  if (argc == 1) usage();
-  while ((c = getopt(argc, argv, "ce:f:hlnsv")) != EOF) {
-	switch (c) {
-	    case 'c':	cflag++;	break;
-	    case 'e':	add_string(optarg);	break;
-	    case 'f':	string_file();	break;
-	    case 'h':	hflag++;	break;
-	    case 'l':	lflag++;	break;
-	    case 'n':	nflag++;	break;
-	    case 's':	sflag++;	break;
-	    case 'v':	vflag++;	break;
-	    default:	usage();	break;
-	}
-  }
-
-  /* If no -e or -f option is used take a string from the command line. */
-  if (strings == (test_str *) NULL) {
-	if (optind == argc) failure(no_arg);
-	add_string(argv[optind++]);
-  }
-  if (argc - optind < 2)
-	hflag++;		/* don't print filenames if less than two
-			 * files */
-
-  /* Handle every matching line according to the flags. */
-  do {
-	optarg = argv[optind];
-	file_open();
-	count = 0;
-	while ((line = get_line()) != (char *) NULL) {
-		count++;
-		if (sflag) return 0;
-		if (lflag) {
-			printf("%s\n", optarg);
-			fflush(stdout);
-			break;
-		}
-		if (cflag) continue;
-		if (hflag == 0) printf("%s:", optarg);
-		if (nflag) printf("%u:", line_num);
-		do {
-			putchar(*line);
-		} while (++line < input);
-		fflush(stdout);
-	}
-	found_one |= count;
-	if (cflag) {
-		if (hflag == 0) printf("%s: ", optarg);
-		printf("%u\n", count);
-		fflush(stdout);
-	}
-	close(fd_in);
-  } while (++optind < argc);
-
-  /* Exit nonzero if no match is found. */
-  return found_one ? 0 : 1;
-}
-
-void usage()
-{
-  fprintf(stderr,
-	"Usage: %s -chlnsv <[-e string] ... [-f file] ... | string> [file] ...\n",
-	prog_name);
-  exit(2);
-}
-
-void failure(mesg)
-char *mesg;
-{
-  fprintf(stderr, "%s: %s\n", prog_name, mesg);
-  exit(1);
-}
-
-/* Add a string to search for to the global linked list `strings'. */
-void add_string(str)
-char *str;
-{
-  test_str *ts;
-  int len;
-
-  if (str == (char *) NULL || (len = strlen(str)) == 0) return;
-  if (len > MAX_STR_LEN) failure("string too long");
-  if ((ts = (test_str *) malloc(sizeof(*ts))) == (test_str *) NULL)
-	failure(no_mem);
-
-  /* Initialize Boyer-Moore table. */
-  memset(ts->table, len, sizeof(ts->table));
-  ts->len = len;
-  ts->str = str;
-  ts->str_end = str + len - 1;
-  for (; --len >= 0; str++) ts->table[*str & BYTE] = len;
-
-  /* Put it on the list */
-  ts->next = strings;
-  strings = ts;
-}
-
-/* Open a file for reading.  Initialize input buffer pointers. */
-void file_open()
-{
-  /* Use stdin if no file arguments are given on the command line. */
-  if (optarg == (char *) NULL || strcmp(optarg, "-") == 0) {
-	fd_in = 0;
-	optarg = "stdin";
-  } else if ((fd_in = open(optarg, O_RDONLY)) == -1) {
-	fprintf(stderr, "%s: can't open %s\n", prog_name, optarg);
-	exit(1);
-  }
-  input = max_input = buf_end = buffer;
-  buffer[-1] = '\n';		/* sentinel */
-  eof_seen = 0;
-  line_num = 0;
-}
-
-/* Move any leftover characters to the head of the buffer.
- * Read characters into the rest of the buffer.
- * Round off the available input to whole lines.
- * Return the number of valid input characters.
- */
-int fill_buffer()
-{
-  char *bufp;
-  int size;
-
-  if (eof_seen) return 0;
-
-  size = buf_end - max_input;
-  memmove(buffer, max_input, size);
-  bufp = &buffer[size];
-
-  do {
-	if ((size = read(fd_in, bufp, READ_SIZE)) <= 0) {
-		if (size != 0) failure("read error");
-		eof_seen++;
-		if (bufp == buffer)	/* no input left */
-			return 0;
-		/* Make sure the last char of a file is '\n'. */
-		*bufp++ = '\n';
-		break;
-	}
-	bufp += size;
-  } while (bufp - buffer < READ_SIZE && bufp[-1] != '\n');
-
-  buf_end = bufp;
-  while (*--bufp != '\n');
-  if (++bufp == buffer) {
-	/* Line too long. */
-	*buf_end++ = '\n';
-	bufp = buf_end;
-  }
-  max_input = bufp;
-  input = buffer;
-
-  return max_input - buffer;
-}
-
-/* Read strings from a file.  Give duplicates to add_string(). */
-void string_file()
-{
-  char *str, *p;
-
-  file_open();
-  while (input < max_input || fill_buffer() > 0) {
-	p = (char *) memchr(input, '\n', BUF_SIZE);
-	*p++ = '\0';
-	if ((str = (char *) malloc(p - input)) == (char *) NULL)
-		failure(no_mem);
-	memcpy(str, input, p - input);
-	add_string(str);
-	input = p;
-  }
-  close(fd_in);
-}
-
-/* Scan the rest of the available input for a string using Boyer-Moore.
- * Return a pointer to the match or a pointer beyond end of input if no match.
- * Record how far the input is scanned.
- */
-char *search_str(ts)
-test_str *ts;
-{
-  char *bufp, *prevbufp, *s;
-
-  bufp = input + ts->len - 1;
-  while (bufp < max_input) {
-	prevbufp = bufp;
-	bufp += ts->table[*bufp & BYTE];
-	if (bufp > prevbufp) continue;
-	s = ts->str_end;
-	do {
-		if (s == ts->str) {	/* match found */
-			ts->bufp = bufp;
-			return bufp;
-		}
-	} while (*--bufp == *--s);
-	bufp = prevbufp + 1;
-  }
-  ts->bufp = bufp;
-
-  return bufp;
-}
-
-/* Return the next line in which one of the strings occurs.
- * Or, if the -v option is used, the next line without a match.
- * Or NULL on EOF.
- */
-char *get_line()
-{
-  test_str *ts;
-  char *match, *line;
-
-  /* Loop until a line is found. */
-  while (1) {
-	if (input >= max_input && fill_buffer() == 0) {	/* EOF */
-		line = (char *) NULL;
-		break;
-	}
-
-	/* If match is still equal to max_input after the next loop
-	 * then no match is found. */
-	match = max_input;
-	ts = strings;
-	do {
-		if (input == buffer) {
-			if (search_str(ts) < match) match = ts->bufp;
-		} else if (ts->bufp < match) {
-			if (ts->bufp >= input || search_str(ts) < match)
-				match = ts->bufp;
-		}
-	} while ((ts = ts->next) != (test_str *) NULL);
-
-	/* Determine if and in what line a match is found. Only do
-	 * line number counting if it is necessary or very easy. */
-	if (vflag) {
-		line_num++;
-		line = input;
-		input = 1 + (char *) memchr(line, '\n', BUF_SIZE);
-		if (input <= match) break;	/* no match in current line */
-	} else if (nflag) {
-		do {
-			line_num++;
-			line = input;
-			input = 1 + (char *) memchr(line, '\n', BUF_SIZE);
-		} while (input < match ||
-			 (input == match && match < max_input));
-		if (match < max_input) break;	/* match found */
-	} else if (match < max_input) {
-		/* Match found. */
-		for (line = match; *--line != '\n';);
-		line++;
-		input = 1 + (char *) memchr(match, '\n', BUF_SIZE);
-		break;
-	} else
-		input = max_input;
-  }
-
-  return line;
-}
Index: trunk/minix/commands/simple/file.c
===================================================================
--- trunk/minix/commands/simple/file.c	(revision 9)
+++ 	(revision )
@@ -1,278 +1,0 @@
-/* file - report on file type.		Author: Andy Tanenbaum */
-/* Magic number detection changed to look-up table 08-Jan-91 - ajm */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#define BLOCK_SIZE	1024
-
-#define XBITS 00111		/* rwXrwXrwX (x bits in the mode) */
-#define ENGLISH 25		/* cutoff for determining if text is Eng. */
-unsigned char buf[BLOCK_SIZE];
-
-struct info {
-  int execflag;			/* 1 == ack executable, 2 == gnu executable,
-				 * 3 == core */
-  unsigned char magic[4];	/* First four bytes of the magic number */
-  unsigned char mask[4];	/* Mask to apply when matching */
-  char *description;		/* What it means */
-} table[] = {
-  0x00, 0x1f, 0x9d, 0x8d, 0x00,		0xff, 0xff, 0xff, 0x00,
-	"13-bit compressed file",
-  0x00, 0x1f, 0x9d, 0x90, 0x00,		0xff, 0xff, 0xff, 0x00,
-	"16-bit compressed file",
-  0x00, 0x65, 0xff, 0x00, 0x00,		0xff, 0xff, 0x00, 0x00,
-	"MINIX-PC bcc archive",
-  0x00, 0x2c, 0xff, 0x00, 0x00,		0xff, 0xff, 0x00, 0x00,
-	"ACK object archive",
-  0x00, 0x65, 0xff, 0x00, 0x00,		0xff, 0xff, 0x00, 0x00,
-	"MINIX-PC ack archive",
-  0x00, 0x47, 0x6e, 0x75, 0x20,		0xff, 0xff, 0xff, 0xff,
-	"MINIX-68k gnu archive",
-  0x00, 0x21, 0x3c, 0x61, 0x72,		0xff, 0xff, 0xff, 0xff,
-	"MINIX-PC gnu archive",
-  0x00, 0x01, 0x02, 0x00, 0x00,		0xff, 0xff, 0x00, 0x00,
-	"ACK object file",
-  0x00, 0xa3, 0x86, 0x00, 0x00, 	0xff, 0xff, 0x00, 0x00,
-	"MINIX-PC bcc object file",
-  0x00, 0x00, 0x00, 0x01, 0x07, 	0xff, 0xff, 0xff, 0xff,
-	"MINIX-68k gnu object file",
-  0x00, 0x07, 0x01, 0x00, 0x00, 	0xff, 0xff, 0xff, 0xff,
-	"MINIX-PC gnu object file",
-  0x01, 0x01, 0x03, 0x00, 0x04, 	0xff, 0xff, 0x00, 0xff,
-	"MINIX-PC 16-bit executable",
-  0x01, 0x01, 0x03, 0x00, 0x10, 	0xff, 0xff, 0x00, 0xff,
-	"MINIX-PC 32-bit executable",
-  0x01, 0x04, 0x10, 0x03, 0x01, 	0xff, 0xff, 0xff, 0xff,
-	"MINIX-68k old style executable",
-  0x01, 0x01, 0x03, 0x10, 0x0b, 	0xff, 0xff, 0xff, 0xff,
-	"MINIX-68k new style executable",
-  0x02, 0x0b, 0x01, 0x00, 0x00, 	0xff, 0xff, 0xff, 0xff,
-	"MINIX-PC 32-bit gnu executable combined I & D space",
-  0x02, 0x00, 0x00, 0x0b, 0x01, 	0xff, 0xff, 0xff, 0xff,
-	"MINIX-68k gnu executable",
-  0x03, 0x82, 0x12, 0xC4, 0xC0,		0xff, 0xff, 0xff, 0xff,
-	"core file",
-};
-
-int tabsize = sizeof(table) / sizeof(struct info);
-int L_flag;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void file, (char *name));
-_PROTOTYPE(void do_strip, (int type));
-_PROTOTYPE(void usage, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-/* This program uses some heuristics to try to guess about a file type by
- * looking at its contents.
- */
-  int c, i;
-
-  L_flag= 0;
-  while ((c= getopt(argc, argv, "L?")) != -1)
-  {
-	switch(c)
-	{
-	case 'L':
-		L_flag= 1;
-		break;
-	case '?':
-		usage();
-	default:
-		fprintf(stderr, "file: panic getopt failed\n");
-		exit(1);
-	}
-  }
-  if (optind >= argc) usage();
-  for (i = optind; i < argc; i++) file(argv[i]);
-  return(0);
-}
-
-void file(name)
-char *name;
-{
-  int i, fd, n, mode, nonascii, special, funnypct, etaoins;
-  int j;
-  long engpct;
-  int c;
-  struct stat st_buf;
-
-  printf("%s: ", name);
-
-#ifdef S_IFLNK
-  if (!L_flag)
-	n = lstat(name, &st_buf);
-  else
-	n = stat(name, &st_buf);
-#else
-  n = stat(name, &st_buf);
-#endif
-  if (n < 0) {
-	printf("cannot stat\n");
-	return;
-  }
-  mode = st_buf.st_mode;
-
-  /* Check for directories and special files. */
-  if (S_ISDIR(mode)) {
-	printf("directory\n");
-	return;
-  }
-  if (S_ISCHR(mode)) {
-	printf("character special file\n");
-	return;
-  }
-  if (S_ISBLK(mode)) {
-	printf("block special file\n");
-	return;
-  }
-  if (S_ISFIFO(mode)) {
-	printf("named pipe\n");
-	return;
-  }
-#ifdef S_IFLNK
-  if (S_ISLNK(mode)) {
-	n= readlink(name, (char *)buf, BLOCK_SIZE);
-	if (n == -1)
-		printf("cannot readlink\n");
-	else
-		printf("symbolic link to %.*s\n", n, buf);
-	return;
-  }
-#endif
-  if (!S_ISREG(mode)) {
-	printf("strange file type %5o\n", mode);
-	return;
-  }
-
-  /* Open the file, stat it, and read in 1 block. */
-  fd = open(name, O_RDONLY);
-  if (fd < 0) {
-	printf("cannot open\n");
-	return;
-  }
-  n = read(fd, (char *)buf, BLOCK_SIZE);
-  if (n < 0) {
-	printf("cannot read\n");
-	close(fd);
-	return;
-  }
-  if (n == 0) {       /* must check this, for loop will fail otherwise !! */
-      printf("empty file\n");
-      close(fd);
-      return;
-  }
-
-  for (i = 0; i < tabsize; i++) {
-	for (j = 0; j < 4; j++)
-		if ((buf[j] & table[i].mask[j]) != table[i].magic[j])
-			break;
-	if (j == 4) {
-		printf("%s", table[i].description);
-		do_strip(table[i].execflag);
-		close(fd);
-		return;
-	}
-  }
-
-
-  /* Check to see if file is a shell script. */
-  if (mode & XBITS) {
-	/* Not a binary, but executable.  Probably a shell script. */
-	printf("shell script\n");
-	close(fd);
-	return;
-  }
-
-  /* Check for ASCII data and certain punctuation. */
-  nonascii = 0;
-  special = 0;
-  etaoins = 0;
-  for (i = 0; i < n; i++) {
-	c = buf[i];
-	if (c & 0200) nonascii++;
-	if (c == ';' || c == '{' || c == '}' || c == '#') special++;
-	if (c == '*' || c == '<' || c == '>' || c == '/') special++;
-	if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a';
-	if (c == 'e' || c == 't' || c == 'a' || c == 'o') etaoins++;
-	if (c == 'i' || c == 'n' || c == 's') etaoins++;
-  }
-
-  if (nonascii == 0) {
-	/* File only contains ASCII characters.  Continue processing. */
-	funnypct = 100 * special / n;
-	engpct = 100L * (long) etaoins / n;
-	if (funnypct > 1) {
-		printf("C program\n");
-	} else {
-		if (engpct > (long) ENGLISH)
-			printf("English text\n");
-		else
-			printf("ASCII text\n");
-	}
-	close(fd);
-	return;
-  }
-
-  /* Give up.  Call it data. */
-  printf("data\n");
-  close(fd);
-  return;
-}
-
-void do_strip(type)
-int type;
-{
-  if (type == 1) {	/* Non-GNU executable */
-	if (buf[2] & 1)
-		printf(", UZP");
-	if (buf[2] & 2)
-		printf(", PAL");
-	if (buf[2] & 4)
-		printf(", NSYM");
-	if (buf[2] & 0x20)
-		printf(", sep I&D");
-	else
-		printf(", comm I&D");
-	if (( buf[28] | buf[29] | buf[30] | buf[31]) != 0)
-		printf(" not stripped\n");
-	else
-		printf(" stripped\n");
-	return;
-  }
-
-  if (type == 2) {	/* GNU format executable */
-     if ((buf[16] | buf[17] | buf[18] | buf[19]) != 0)
-	 printf(" not stripped\n");
-     else
-	 printf(" stripped\n");
-     return;
-  }
-
-  if (type == 3) {	/* Core file in <sys/core.h> format */
-	switch(buf[36] & 0xff)
-	{
-		case 1:	printf(" of i86 executable"); break;
-		case 2:	printf(" of i386 executable"); break;
-		default:printf(" of unknown executable"); break;
-	}
-	printf(" '%.32s'\n", buf+4);
-	return;
-  }
-
-  printf("\n");		/* Not an executable file */
- }
-
-void usage()
-{
-  printf("Usage: file [-L] name ...\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/find.c
===================================================================
--- trunk/minix/commands/simple/find.c	(revision 9)
+++ 	(revision )
@@ -1,927 +1,0 @@
-/* find - look for files satisfying a predicate       Author: E. Baalbergen */
-
-/* Original author: Erik Baalbergen; POSIX compliant version: Bert Laverman */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <time.h>
-#include <pwd.h>
-#include <grp.h>
-#include <dirent.h>
-#include <limits.h>
-#include <stdio.h>
-
-/*######################## DEFINITIONS ##############################*/
-
-#ifdef S_IFLNK
-#define LSTAT lstat
-#else
-#define LSTAT stat
-#endif
-
-#define SHELL "/bin/sh"
-#define MAXARG          256	/* maximum length for an argv for -exec  */
-#define BSIZE           512	/* POSIX wants 512 byte blocks           */
-#define SECS_PER_DAY    (24L*60L*60L)	/* check your planet             */
-
-#define OP_NAME          1	/* match name                            */
-#define OP_PERM          2	/* check file permission bits            */
-#define OP_TYPE          3	/* check file type bits                  */
-#define OP_LINKS         4	/* check link count                      */
-#define OP_USER          5	/* check owner                           */
-#define OP_GROUP         6	/* check group ownership                 */
-#define OP_SIZE          7	/* check size, blocks or bytes           */
-#define OP_SIZEC         8	/* this is a fake for -size with 'c'     */
-#define OP_INUM          9	/* compare inode number                  */
-#define OP_ATIME        10	/* check last access time                */
-#define OP_CTIME        11	/* check creation time                   */
-#define OP_MTIME        12	/* check last modification time          */
-#define OP_EXEC         13	/* execute command                       */
-#define OP_OK           14	/* execute with confirmation             */
-#define OP_PRINT        15	/* print name                            */
-#define OP_PRINT0       16	/* print name null terminated            */
-#define OP_NEWER        17	/* compare modification times            */
-#define OP_CNEWER       18	/* compare modification times            */
-#define OP_AND          19	/* logical and (short circuit)           */
-#define OP_OR           20	/* logical or (short circuit)            */
-#define OP_XDEV         21	/* do not cross file-system boundaries   */
-#define OP_DEPTH        22	/* descend directory before testing      */
-#define OP_PRUNE        23	/* don't descend into current directory  */
-#define OP_NOUSER       24	/* check validity of user id             */
-#define OP_NOGROUP      25	/* check validity of group id            */
-#define LPAR            26	/* left parenthesis                      */
-#define RPAR            27	/* right parenthesis                     */
-#define NOT             28	/* logical not                           */
-
-/* Some return values: */
-#define EOI             -1	/* end of expression                     */
-#define NONE             0	/* not a valid predicate                 */
-
-/* For -perm with symbolic modes: */
-#define ISWHO(c)        ((c == 'u') || (c == 'g') || (c == 'o') || (c == 'a'))
-#define ISOPER(c)       ((c == '-') || (c == '=') || (c == '+'))
-#define ISMODE(c)       ((c == 'r') || (c == 'w') || (c == 'x') || \
-			 (c == 's') || (c == 't'))
-#define MUSER           1
-#define MGROUP          2
-#define MOTHERS         4
-
-
-struct exec {
-  int e_cnt;
-  char *e_vec[MAXARG];
-};
-
-struct node {
-  int n_type;			/* any OP_ or NOT */
-  union {
-	char *n_str;
-	struct {
-		long n_val;
-		int n_sign;
-	} n_int;
-	struct exec *n_exec;
-	struct {
-		struct node *n_left, *n_right;
-	} n_opnd;
-  } n_info;
-};
-
-struct oper {
-  char *op_str;
-  int op_val;
-} ops[] = {
-
-  {
-	"name", OP_NAME
-  },
-  {
-	"perm", OP_PERM
-  },
-  {
-	"type", OP_TYPE
-  },
-  {
-	"links", OP_LINKS
-  },
-  {
-	"user", OP_USER
-  },
-  {
-	"group", OP_GROUP
-  },
-  {
-	"size", OP_SIZE
-  },
-  {
-	"inum", OP_INUM
-  },
-  {
-	"atime", OP_ATIME
-  },
-  {
-	"ctime", OP_CTIME
-  },
-  {
-	"mtime", OP_MTIME
-  },
-  {
-	"exec", OP_EXEC
-  },
-  {
-	"ok", OP_OK
-  },
-  {
-	"print", OP_PRINT
-  },
-  {
-	"print0", OP_PRINT0
-  },
-  {
-	"newer", OP_NEWER
-  },
-  {
-	"cnewer", OP_CNEWER
-  },
-  {
-	"a", OP_AND
-  },
-  {
-	"o", OP_OR
-  },
-  {
-	"xdev", OP_XDEV
-  },
-  {
-	"depth", OP_DEPTH
-  },
-  {
-	"prune", OP_PRUNE
-  },
-  {
-	"nouser", OP_NOUSER
-  },
-  {
-	"nogroup", OP_NOGROUP
-  },
-  {
-	0, 0
-  }
-};
-
-
-char **ipp;			/* pointer to next argument during parsing       */
-char *prog;			/* program name (== argv [0])                    */
-char *epath;			/* value of PATH environment string              */
-long current_time;		/* for computing age                             */
-int tty;			/* fd for /dev/tty when using -ok                */
-int xdev_flag = 0;		/* cross device boundaries?                      */
-int devnr;			/* device nr of first inode                      */
-int depth_flag = 0;		/* descend before check?                         */
-int prune_here;			/* This is Baaaad! Don't ever do this again!     */
-int um;				/* current umask()                               */
-int needprint = 1;		/* implicit -print needed?                       */
-
-
-/* The prototypes: */
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(char *Malloc, (int n));
-_PROTOTYPE(char *Salloc, (char *s));
-_PROTOTYPE(void find, (char *path, struct node * pred, char *last));
-_PROTOTYPE(int check, (char *path, struct stat * st, struct node * n, char *last));
-_PROTOTYPE(int ichk, (long val, struct node * n));
-_PROTOTYPE(int lex, (char *str));
-_PROTOTYPE(struct node * newnode, (int t));
-_PROTOTYPE(int isnumber, (char *str, int base, int sign));
-_PROTOTYPE(void number, (char *str, int base, long *pl, int *ps));
-_PROTOTYPE(void fmode, (char *str, long *pl, int *ps));
-_PROTOTYPE(struct node * expr, (int t));
-_PROTOTYPE(struct node * primary, (int t));
-_PROTOTYPE(struct node * secondary, (int t));
-_PROTOTYPE(void checkarg, (char *arg));
-_PROTOTYPE(struct node * simple, (int t));
-_PROTOTYPE(void nonfatal, (char *s1, char *s2));
-_PROTOTYPE(void fatal, (char *s1, char *s2));
-_PROTOTYPE(int smatch, (char *s, char *t));
-_PROTOTYPE(char *find_bin, (char *s));
-_PROTOTYPE(int execute, (int op, struct exec * e, char *path));
-_PROTOTYPE(void domode, (int op, int *mode, int bits));
-
-
-/* Malloc: a certified malloc */
-char *Malloc(n)
-int n;
-{
-  char *m;
-
-  if ((m = (char *) malloc(n)) == (char *) NULL) fatal("out of memory", "");
-  return m;
-}
-
-/* Salloc: allocate space for a string */
-char *Salloc(s)
-char *s;
-{
-  return strcpy(Malloc(strlen(s) + 1), s);
-}
-
-
-/* Main: the main body */
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char **pathlist, *path, *last;
-  int pathcnt = 0, i;
-  struct node *pred;
-
-  prog = *argv++;		/* set program name (for diagnostics)    */
-  if ((epath = getenv("PATH")) == (char *) NULL)
-	fatal("Can't get path from environment", "");
-  (void) umask(um = umask(0));	/* non-destructive get-umask :-)         */
-  time(&current_time);		/* get current time                      */
-
-  pathlist= argv;
-  while (--argc > 0 && lex(*argv) == NONE) {	/* find paths            */
-	pathcnt++;
-	argv++;
-  }
-  if (pathcnt == 0)		/* there must be at least one path       */
-	fatal("Usage: path-list [predicate-list]", "");
-
-  ipp = argv;			/* prepare for parsing                   */
-  if (argc != 0) {		/* If there is anything to parse,        */
-	pred = expr(lex(*ipp));	/* then do so                            */
-	if (lex(*++ipp) != EOI)	/* Make sure there's nothing left        */
-		fatal("syntax error: garbage at end of predicate", "");
-  } else			/* No predicate list                     */
-	pred = (struct node *) NULL;
-
-  for (i = 0; i < pathcnt; i++) {
-	if (xdev_flag) xdev_flag = 2;
-	path = pathlist[i];
-	if ((last = strrchr(path, '/')) == NULL) last = path; else last++;
-	find(path, pred, last);
-  }
-  return 0;
-}
-
-void find(path, pred, last)
-char *path, *last;
-struct node *pred;
-{
-  char spath[PATH_MAX];
-  register char *send = spath, *p;
-  struct stat st;
-  DIR *dp;
-  struct dirent *de;
-
-  if (path[1] == '\0' && *path == '/') {
-	*send++ = '/';
-	*send = '\0';
-  } else
-	while (*send++ = *path++) {
-	}
-
-  if (LSTAT(spath, &st) == -1)
-	nonfatal("can't get status of ", spath);
-  else {
-	switch (xdev_flag) {
-	  case 0:
-		break;
-	  case 1:
-		if (st.st_dev != devnr) return;
-		break;
-	  case 2:		/* set current device number */
-		xdev_flag = 1;
-		devnr = st.st_dev;
-		break;
-	}
-
-	prune_here = 0;
-	if (!depth_flag && check(spath, &st, pred, last) && needprint)
-		printf("%s\n", spath);
-	if (!prune_here && (st.st_mode & S_IFMT) == S_IFDIR) {
-		if ((dp = opendir(spath)) == NULL) {
-			nonfatal("can't read directory ", spath);
-			perror( "Error" );
-			return;
-		}
-		send[-1] = '/';
-		while ((de = readdir(dp)) != NULL) {
-			p = de->d_name;
-			if ((de->d_name[0] != '.') || ((de->d_name[1])
-					  && ((de->d_name[1] != '.')
-					      || (de->d_name[2])))) {
-				strcpy(send, de->d_name);
-				find(spath, pred, send);
-			}
-		}
-		closedir(dp);
-	}
-	if (depth_flag) {
-		send[-1] = '\0';
-		if (check(spath, &st, pred, last) && needprint)
-			printf("%s\n", spath);
-	}
-  }
-}
-
-int check(path, st, n, last)
-char *path, *last;
-register struct stat *st;
-register struct node *n;
-{
-  if (n == (struct node *) NULL) return 1;
-  switch (n->n_type) {
-    case OP_AND:
-	return check(path, st, n->n_info.n_opnd.n_left, last) &&
-		check(path, st, n->n_info.n_opnd.n_right, last);
-    case OP_OR:
-	return check(path, st, n->n_info.n_opnd.n_left, last) ||
-		check(path, st, n->n_info.n_opnd.n_right, last);
-    case NOT:
-	return !check(path, st, n->n_info.n_opnd.n_left, last);
-    case OP_NAME:
-	return smatch(last, n->n_info.n_str);
-    case OP_PERM:
-	if (n->n_info.n_int.n_sign < 0)
-		return(st->st_mode & (int) n->n_info.n_int.n_val) ==
-			(int) n->n_info.n_int.n_val;
-	return(st->st_mode & 07777) == (int) n->n_info.n_int.n_val;
-    case OP_NEWER:
-	return st->st_mtime > n->n_info.n_int.n_val;
-    case OP_CNEWER:
-	return st->st_ctime > n->n_info.n_int.n_val;
-    case OP_TYPE:
-	return(st->st_mode & S_IFMT) == (mode_t) n->n_info.n_int.n_val;
-    case OP_LINKS:
-	return ichk((long) (st->st_nlink), n);
-    case OP_USER:
-	return st->st_uid == n->n_info.n_int.n_val;
-    case OP_GROUP:
-	return st->st_gid == n->n_info.n_int.n_val;
-    case OP_SIZE:
-	return ichk((st->st_size == 0) ? 0L :
-		    (long) ((st->st_size - 1) / BSIZE + 1), n);
-    case OP_SIZEC:
-	return ichk((long) st->st_size, n);
-    case OP_INUM:
-	return ichk((long) (st->st_ino), n);
-    case OP_ATIME:
-	return ichk(st->st_atime, n);
-    case OP_CTIME:
-	return ichk(st->st_ctime, n);
-    case OP_MTIME:
-	return ichk(st->st_mtime, n);
-    case OP_EXEC:
-    case OP_OK:
-	return execute(n->n_type, n->n_info.n_exec, path);
-    case OP_PRINT:
-	printf("%s\n", path);
-	return 1;
-    case OP_PRINT0:
-	printf("%s", path); putchar(0);
-	return 1;
-    case OP_XDEV:
-    case OP_DEPTH:
-	return 1;
-    case OP_PRUNE:
-	prune_here = 1;
-	return 1;
-    case OP_NOUSER:
-	return(getpwuid(st->st_uid) == (struct passwd *) NULL);
-    case OP_NOGROUP:
-	return(getgrgid(st->st_gid) == (struct group *) NULL);
-  }
-  fatal("ILLEGAL NODE", "");
-  return 0;			/* Never reached */
-}
-
-int ichk(val, n)
-long val;
-struct node *n;
-{
-  switch (n->n_info.n_int.n_sign) {
-    case 0:
-	return val == n->n_info.n_int.n_val;
-    case 1:
-	return val > n->n_info.n_int.n_val;
-    case -1:	return val < n->n_info.n_int.n_val;
-}
-  fatal("internal: bad n_sign", "");
-  return 0;			/* Never reached */
-}
-
-int lex(str)
-char *str;
-{
-  if (str == (char *) NULL) return EOI;
-  if (*str == '-') {
-	register struct oper *op;
-
-	str++;
-	for (op = ops; op->op_str; op++)
-		if (strcmp(str, op->op_str) == 0) break;
-	return op->op_val;
-  }
-  if (str[1] == 0) {
-	switch (*str) {
-	  case '(':
-		return LPAR;
-	  case ')':
-		return RPAR;
-	  case '!':	return NOT;
-	}
-  }
-  return NONE;
-}
-
-struct node *
- newnode(t)
-int t;
-{
-  struct node *n = (struct node *) Malloc(sizeof(struct node));
-
-  n->n_type = t;
-  return n;
-}
-
-/*########################### PARSER ###################################*/
-/* Grammar:
- * expr        : primary | primary OR expr;
- * primary     : secondary | secondary AND primary | secondary primary;
- * secondary   : NOT secondary | LPAR expr RPAR | simple;
- * simple      : -OP args...
- */
-
-/* Isnumber checks correct number syntax. A sign is allowed, but the '+'
- * only if the number is to be in decimal.
- */
-int isnumber(str, base, sign)
-register char *str;
-int base;
-int sign;
-{
-  if (sign && ((*str == '-') || ((base == 8) && (*str == '+')))) str++;
-  while ((*str >= '0') && (*str < ('0' + base))) str++;
-  return(*str == '\0' ? 1 : 0);
-}
-
-/* Convert a string to an integer, storing sign info in *ps. */
-void number(str, base, pl, ps)
-char *str;
-int base;
-long *pl;
-int *ps;
-{
-  int up = '0' + base - 1;
-  long val = 0;
-
-  *ps = ((*str == '-' || *str == '+') ? ((*str++ == '-') ? -1 : 1) : 0);
-  while (*str >= '0' && *str <= up) val = base * val + *str++ - '0';
-  if (*str) fatal("syntax error: illegal numeric value", "");
-  *pl = val;
-}
-
-
-void domode(op, mode, bits)
-int op;
-int *mode;
-int bits;
-{
-  switch (op) {
-    case '-':
-	*mode &= ~bits;
-	break;			/* clear bits */
-    case '=':
-	*mode |= bits;
-	break;			/* set bits */
-    case '+':
-	*mode |= (bits & ~um);	/* set, but take umask in account */
-  }
-}
-
-void fmode(str, pl, ps)
-char *str;
-long *pl;
-int *ps;
-{
-  int m = 0, w, op;
-  char *p = str;
-
-  if (*p == '-') {
-	*ps = -1;
-	p++;
-  } else
-	*ps = 0;
-
-  while (*p) {
-	w = 0;
-	if (ISOPER(*p))
-		w = MUSER | MGROUP | MOTHERS;
-	else if (!ISWHO(*p))
-		fatal("u, g, o, or a expected: ", p);
-	else {
-		while (ISWHO(*p)) {
-			switch (*p) {
-			  case 'u':
-				w |= MUSER;
-				break;
-			  case 'g':
-				w |= MGROUP;
-				break;
-			  case 'o':
-				w |= MOTHERS;
-				break;
-			  case 'a':
-				w = MUSER | MGROUP | MOTHERS;
-			}
-			p++;
-		}
-		if (!ISOPER(*p)) fatal("-, + or = expected: ", p);
-	}
-	op = *p++;
-	while (ISMODE(*p)) {
-		switch (*p) {
-		  case 'r':
-			if (w & MUSER) domode(op, &m, S_IRUSR);
-			if (w & MGROUP) domode(op, &m, S_IRGRP);
-			if (w & MOTHERS) domode(op, &m, S_IROTH);
-			break;
-		  case 'w':
-			if (w & MUSER) domode(op, &m, S_IWUSR);
-			if (w & MGROUP) domode(op, &m, S_IWGRP);
-			if (w & MOTHERS) domode(op, &m, S_IWOTH);
-			break;
-		  case 'x':
-			if (w & MUSER) domode(op, &m, S_IXUSR);
-			if (w & MGROUP) domode(op, &m, S_IXGRP);
-			if (w & MOTHERS) domode(op, &m, S_IXOTH);
-			break;
-		  case 's':
-			if (w & MUSER) domode(op, &m, S_ISUID);
-			if (w & MGROUP) domode(op, &m, S_ISGID);
-			break;
-		  case 't':
-			domode(op, &m, S_ISVTX);
-		}
-		p++;
-	}
-	if (*p) {
-		if (*p == ',')
-			p++;
-		else
-			fatal("garbage at end of mode string: ", p);
-	}
-  }
-  *pl = m;
-}
-
-struct node *
- expr(t)
-int t;
-{
-  struct node *nd, *p, *nd2;
-
-  nd = primary(t);
-  if ((t = lex(*++ipp)) == OP_OR) {
-	nd2 = expr(lex(*++ipp));
-	p = newnode(OP_OR);
-	p->n_info.n_opnd.n_left = nd;
-	p->n_info.n_opnd.n_right = nd2;
-	return p;
-  }
-  ipp--;
-  return nd;
-}
-
-struct node *
- primary(t)
-int t;
-{
-  struct node *nd, *p, *nd2;
-
-  nd = secondary(t);
-  if ((t = lex(*++ipp)) != OP_AND) {
-	ipp--;
-	if (t == EOI || t == RPAR || t == OP_OR) return nd;
-  }
-  nd2 = primary(lex(*++ipp));
-  p = newnode(OP_AND);
-  p->n_info.n_opnd.n_left = nd;
-  p->n_info.n_opnd.n_right = nd2;
-  return p;
-}
-
-struct node *
- secondary(t)
-int t;
-{
-  struct node *n, *p;
-
-  if (t == LPAR) {
-	n = expr(lex(*++ipp));
-	if (lex(*++ipp) != RPAR) fatal("syntax error, ) expected", "");
-	return n;
-  }
-  if (t == NOT) {
-	n = secondary(lex(*++ipp));
-	p = newnode(NOT);
-	p->n_info.n_opnd.n_left = n;
-	return p;
-  }
-  return simple(t);
-}
-
-void checkarg(arg)
-char *arg;
-{
-  if (arg == 0) fatal("syntax error, argument expected", "");
-}
-
-struct node *
- simple(t)
-int t;
-{
-  struct node *p = newnode(t);
-  struct exec *e;
-  struct stat est;
-  struct passwd *pw;
-  struct group *gr;
-  long l;
-  int i;
-
-  switch (t) {
-    case OP_TYPE:
-	checkarg(*++ipp);
-	switch (**ipp) {
-	  case 'b':
-		p->n_info.n_int.n_val = S_IFBLK;
-		break;
-	  case 'c':
-		p->n_info.n_int.n_val = S_IFCHR;
-		break;
-	  case 'd':
-		p->n_info.n_int.n_val = S_IFDIR;
-		break;
-	  case 'f':
-		p->n_info.n_int.n_val = S_IFREG;
-		break;
-	  case 'p':
-		p->n_info.n_int.n_val = S_IFIFO;
-		break;
-	  case 's':
-		p->n_info.n_int.n_val = ~0;
-		break;
-	  case 'l':
-#ifdef S_IFLNK
-		p->n_info.n_int.n_val = S_IFLNK;
-#else
-		p->n_info.n_int.n_val = ~0;	/* Always unequal. */
-#endif
-		break;
-	  default:
-		fatal("-type needs b, c, d, f, p, s or l", "");
-	}
-	break;
-    case OP_USER:
-	checkarg(*++ipp);
-	if (((pw = getpwnam(*ipp)) == NULL)
-	    && isnumber(*ipp, 10, 0))
-		number(*ipp, 10, &(p->n_info.n_int.n_val),
-		       &(p->n_info.n_int.n_sign));
-	else {
-		if (pw == NULL)
-			fatal("unknown user: ", *ipp);
-		p->n_info.n_int.n_val = pw->pw_uid;
-		p->n_info.n_int.n_sign = 0;
-	}
-	break;
-    case OP_GROUP:
-	checkarg(*++ipp);
-	if (((gr = getgrnam(*ipp)) == NULL)
-	    && isnumber(*ipp, 10, 0))
-		number(*ipp, 10, &(p->n_info.n_int.n_val),
-		       &(p->n_info.n_int.n_sign));
-	else {
-		if (gr == NULL)
-			fatal("unknown group: ", *ipp);
-		p->n_info.n_int.n_val = gr->gr_gid;
-		p->n_info.n_int.n_sign = 0;
-	}
-	break;
-    case OP_SIZE:
-	checkarg(*++ipp);
-	i = strlen(*ipp) - 1;
-	if ((*ipp)[i] == 'c') {
-		p->n_type = OP_SIZEC;	/* Count in bytes i.s.o. blocks */
-		(*ipp)[i] = '\0';
-	}
-	number(*ipp, 10, &(p->n_info.n_int.n_val),
-	       &(p->n_info.n_int.n_sign));
-	break;
-    case OP_LINKS:
-    case OP_INUM:
-	checkarg(*++ipp);
-	number(*ipp, 10, &(p->n_info.n_int.n_val),
-	       &(p->n_info.n_int.n_sign));
-	break;
-    case OP_PERM:
-	checkarg(*++ipp);
-	if (isnumber(*ipp, 8, 1)) number(*ipp, 8, &(p->n_info.n_int.n_val),
-		       &(p->n_info.n_int.n_sign));
-	else
-		fmode(*ipp, &(p->n_info.n_int.n_val),
-		      &(p->n_info.n_int.n_sign));
-	break;
-    case OP_ATIME:
-    case OP_CTIME:
-    case OP_MTIME:
-	checkarg(*++ipp);
-	number(*ipp, 10, &l, &(p->n_info.n_int.n_sign));
-	p->n_info.n_int.n_val = current_time - l * SECS_PER_DAY;
-	/* More than n days old means less than the absolute time */
-	p->n_info.n_int.n_sign *= -1;
-	break;
-    case OP_EXEC:
-    case OP_OK:
-	checkarg(*++ipp);
-	e = (struct exec *) Malloc(sizeof(struct exec));
-	e->e_cnt = 2;
-	e->e_vec[0] = SHELL;
-	p->n_info.n_exec = e;
-	while (*ipp) {
-		if (**ipp == ';' && (*ipp)[1] == '\0') {
-			e->e_vec[e->e_cnt] = 0;
-			break;
-		}
-		e->e_vec[(e->e_cnt)++] =
-			(**ipp == '{' && (*ipp)[1] == '}'
-		       && (*ipp)[2] == '\0') ? (char *) (-1) : *ipp;
-		ipp++;
-	}
-	if (*ipp == 0) fatal("-exec/-ok: ; missing", "");
-	if ((e->e_vec[1] = find_bin(e->e_vec[2])) == 0)
-		fatal("can't find program ", e->e_vec[2]);
-	if (t == OP_OK)
-		if ((tty = open("/dev/tty", O_RDWR)) < 0)
-			fatal("can't open /dev/tty", "");
-	break;
-    case OP_CNEWER:
-    case OP_NEWER:
-	checkarg(*++ipp);
-	if (LSTAT(*ipp, &est) == -1)
-		fatal("-newer: can't get status of ", *ipp);
-	p->n_info.n_int.n_val = est.st_mtime;
-	break;
-    case OP_NAME:
-	checkarg(*++ipp);
-	p->n_info.n_str = *ipp;
-	break;
-    case OP_XDEV:	xdev_flag = 1;	break;
-    case OP_DEPTH:	depth_flag = 1;	break;
-    case OP_PRUNE:
-    case OP_PRINT:
-    case OP_PRINT0:
-    case OP_NOUSER:	case OP_NOGROUP:	break;
-          default:
-	fatal("syntax error, operator expected", "");
-  }
-  if ((t == OP_PRINT) || (t == OP_PRINT0) || (t == OP_EXEC) || (t == OP_OK))
-	needprint = 0;
-
-  return p;
-}
-
-/*######################## DIAGNOSTICS ##############################*/
-
-void nonfatal(s1, s2)
-char *s1, *s2;
-{
-  fprintf(stderr, "%s: %s%s\n", prog, s1, s2);
-}
-
-void fatal(s1, s2)
-char *s1, *s2;
-{
-  nonfatal(s1, s2);
-  exit(1);
-}
-
-/*################### SMATCH #########################*/
-/* Don't try to understand the following one... */
-int smatch(s, t)		/* shell-like matching */
-char *s, *t;
-{
-  register n;
-
-  if (*t == '\0') return *s == '\0';
-  if (*t == '*') {
-	++t;
-	do
-		if (smatch(s, t)) return 1;
-	while (*s++ != '\0');
-	return 0;
-  }
-  if (*s == '\0') return 0;
-  if (*t == '\\') return (*s == *++t) ? smatch(++s, ++t) : 0;
-  if (*t == '?') return smatch(++s, ++t);
-  if (*t == '[') {
-	while (*++t != ']') {
-		if (*t == '\\') ++t;
-		if (*(t + 1) != '-')
-			if (*t == *s) {
-				while (*++t != ']')
-					if (*t == '\\') ++t;
-				return smatch(++s, ++t);
-			} else
-				continue;
-		if (*(t + 2) == ']') return(*s == *t || *s == '-');
-		n = (*(t + 2) == '\\') ? 3 : 2;
-		if (*s >= *t && *s <= *(t + n)) {
-			while (*++t != ']')
-				if (*t == '\\') ++t;
-			return smatch(++s, ++t);
-		}
-		t += n;
-	}
-	return 0;
-  }
-  return(*s == *t) ? smatch(++s, ++t) : 0;
-}
-
-/*####################### EXECUTE ###########################*/
-/* Do -exec or -ok */
-
-char *
- find_bin(s)
-char *s;
-{
-  char *f, *l, buf[PATH_MAX];
-
-  if (*s == '/')		/* absolute path name */
-	return(access(s, 1) == 0) ? s : 0;
-  l = f = epath;
-  for (;;) {
-	if (*l == ':' || *l == 0) {
-		if (l == f) {
-			if (access(s, 1) == 0) return Salloc(s);
-			f++;
-		} else {
-			register char *p = buf, *q = s;
-
-			while (f != l) *p++ = *f++;
-			f++;
-			*p++ = '/';
-			while (*p++ = *q++) {
-			}
-			if (access(buf, 1) == 0) return Salloc(buf);
-		}
-		if (*l == 0) break;
-	}
-	l++;
-  }
-  return 0;
-}
-
-int execute(op, e, path)
-int op;
-struct exec *e;
-char *path;
-{
-  int s, pid;
-  char *argv[MAXARG];
-  register char **p, **q;
-
-  for (p = e->e_vec, q = argv; *p;)	/* replace the {}s */
-	if ((*q++ = *p++) == (char *) -1) q[-1] = path;
-  *q = '\0';
-  if (op == OP_OK) {
-	char answer[10];
-
-	for (p = &argv[2]; *p; p++) {
-		write(tty, *p, strlen(*p));
-		write(tty, " ", 1);
-	}
-	write(tty, "? ", 2);
-	if (read(tty, answer, 10) < 2 || *answer != 'y') return 0;
-  }
-  if ((pid = fork()) == -1) fatal("can't fork", "");
-  if (pid == 0) {
-	register i = 3;
-
-	while (close(i++) == 0) {
-	}			/* wow!!! */
-	execv(argv[1], &argv[2]);	/* binary itself? */
-	execv(argv[0], &argv[1]);	/* shell command? */
-	fatal("exec failure: ", argv[1]);	/* none of them! */
-	exit(127);
-  }
-  return wait(&s) == pid && s == 0;
-}
Index: trunk/minix/commands/simple/finger.c
===================================================================
--- trunk/minix/commands/simple/finger.c	(revision 9)
+++ 	(revision )
@@ -1,1093 +1,0 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)finger.c 1.1 87/12/21 SMI"; /* from 5.8 3/13/86 */
-#endif /* not lint */
-
-/*
- * This is a finger program.  It prints out useful information about users
- * by digging it up from various system files.
- *
- * There are three output formats, all of which give login name, teletype
- * line number, and login time.  The short output format is reminiscent
- * of finger on ITS, and gives one line of information per user containing
- * in addition to the minimum basic requirements (MBR), the full name of
- * the user, his idle time and location.  The
- * quick style output is UNIX who-like, giving only name, teletype and
- * login time.  Finally, the long style output give the same information
- * as the short (in more legible format), the home directory and shell
- * of the user, and, if it exits, a copy of the file .plan in the users
- * home directory.  Finger may be called with or without a list of people
- * to finger -- if no list is given, all the people currently logged in
- * are fingered.
- *
- * The program is validly called by one of the following:
- *
- *	finger			{short form list of users}
- *	finger -l		{long form list of users}
- *	finger -b		{briefer long form list of users}
- *	finger -q		{quick list of users}
- *	finger -i		{quick list of users with idle times}
- *	finger namelist		{long format list of specified users}
- *	finger -s namelist	{short format list of specified users}
- *	finger -w namelist	{narrow short format list of specified users}
- *
- * where 'namelist' is a list of users login names.
- * The other options can all be given after one '-', or each can have its
- * own '-'.  The -f option disables the printing of headers for short and
- * quick outputs.  The -b option briefens long format outputs.  The -p
- * option turns off plans for long format outputs.
- */
-
-#include <sys/types.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <utmp.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/netdb.h>
-#include <net/gen/socket.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_hdr.h>
-#include <net/gen/tcp_io.h>
-#include <net/hton.h>
-#include <net/netlib.h>
-
-#define NONOTHING	1		/* don't say "No plan", or "No mail" */
-
-#define NONET	0
-
-#define ASTERISK	'*'		/* ignore this in real name */
-#define COMMA		','		/* separator in pw_gecos field */
-#define COMMAND		'-'		/* command line flag char */
-#define SAMENAME	'&'		/* repeat login name in real name */
-#define TALKABLE	0220		/* tty is writable if this mode */
-
-struct utmp user;
-#define NMAX sizeof(user.ut_name)
-#define LMAX sizeof(user.ut_line)
-#define HMAX sizeof(user.ut_host)
-
-struct person {			/* one for each person fingered */
-	char *name;			/* name */
-	char tty[LMAX+1];		/* null terminated tty line */
-	char host[HMAX+1];		/* null terminated remote host name */
-	long loginat;			/* time of (last) login */
-	long idletime;			/* how long idle (if logged in) */
-	char *realname;			/* pointer to full name */
-	struct passwd *pwd;		/* structure of /etc/passwd stuff */
-	char loggedin;			/* person is logged in */
-	char writable;			/* tty is writable */
-	char original;			/* this is not a duplicate entry */
-	struct person *link;		/* link to next person */
-	char *where;			/* terminal location */
-	char hostt[HMAX+1];		/* login host */
-};
-
-#include <minix/paths.h>
-
-char LASTLOG[] = _PATH_LASTLOG;	/* last login info */
-char USERLOG[] = _PATH_UTMP;		/* who is logged in */
-char PLAN[] = "/.plan";			/* what plan file is */
-char PROJ[] = "/.project";		/* what project file */
-	
-int unbrief = 1;			/* -b option default */
-int header = 1;				/* -f option default */
-int hack = 1;				/* -h option default */
-int idle = 0;				/* -i option default */
-int large = 0;				/* -l option default */
-int match = 1;				/* -m option default */
-int plan = 1;				/* -p option default */
-int unquick = 1;			/* -q option default */
-int small = 0;				/* -s option default */
-int wide = 1;				/* -w option default */
-
-int unshort;
-int lf;					/* LASTLOG file descriptor */
-struct person *person1;			/* list of people */
-long tloc;				/* current time */
-
-#if !_MINIX
-char *strcpy();
-char *ctime();
-#endif
-
-char *prog_name;
-
-int main (int argc, char *argv[]);
-static void doall(void);
-static void donames(char **args);
-static void print(void);
-static void fwopen(void);
-static void decode(struct person *pers);
-static void fwclose(void);
-static int netfinger (char *name);
-static int matchcmp (char *gname, char *login, char *given);
-static void quickprint (struct person *pers);
-static void shortprint (struct person *pers);
-static void personprint (struct person *pers);
-static int AlreadyPrinted(int uid);
-static int AnyMail (char *name);
-static struct passwd *pwdcopy(struct passwd *pfrom);
-static void findidle (struct person *pers);
-static int ltimeprint (char *dt, long *before, char *after);
-static void stimeprint (long *dt);
-static void findwhen (struct person *pers);
-static int namecmp (char *name1, char *name2);
-
-main(argc, argv)
-	int argc;
-	register char **argv;
-{
-	FILE *fp;
-	register char *s;
-
-	prog_name= argv[0];
-
-	/* parse command line for (optional) arguments */
-	while (*++argv && **argv == COMMAND)
-		for (s = *argv + 1; *s; s++)
-			switch (*s) {
-			case 'b':
-				unbrief = 0;
-				break;
-			case 'f':
-				header = 0;
-				break;
-			case 'h':
-				hack = 0;
-				break;
-			case 'i':
-				idle = 1;
-				unquick = 0;
-				break;
-			case 'l':
-				large = 1;
-				break;
-			case 'm':
-				match = 0;
-				break;
-			case 'p':
-				plan = 0;
-				break;
-			case 'q':
-				unquick = 0;
-				break;
-			case 's':
-				small = 1;
-				break;
-			case 'w':
-				wide = 0;
-				break;
-			default:
-				fprintf(stderr, "Usage: finger [-bfhilmpqsw] [login1 [login2 ...] ]\n");
-				exit(1);
-			}
-	if (unquick || idle)
-		time(&tloc);
-	/*
-	 * *argv == 0 means no names given
-	 */
-	if (*argv == 0)
-		doall();
-	else
-		donames(argv);
-	if (person1)
-		print();
-	exit(0);
-}
-
-static void doall()
-{
-	register struct person *p;
-	register struct passwd *pw;
-	int uf;
-	char name[NMAX + 1];
-
-	unshort = large;
-	if ((uf = open(USERLOG, 0)) < 0) {
-		fprintf(stderr, "finger: error opening %s\n", USERLOG);
-		exit(2);
-	}
-	if (unquick) {
-		setpwent();
-		fwopen();
-	}
-	while (read(uf, (char *)&user, sizeof user) == sizeof user) {
-		if (user.ut_name[0] == 0)
-			continue;
-		if (person1 == 0)
-			p = person1 = (struct person *) malloc(sizeof *p);
-		else {
-			p->link = (struct person *) malloc(sizeof *p);
-			p = p->link;
-		}
-		bcopy(user.ut_name, name, NMAX);
-		name[NMAX] = 0;
-		bcopy(user.ut_line, p->tty, LMAX);
-		p->tty[LMAX] = 0;
-		bcopy(user.ut_host, p->host, HMAX);
-		p->host[HMAX] = 0;
-		p->loginat = user.ut_time;
-		p->pwd = 0;
-		p->loggedin = 1;
-		p->where = NULL;
-		if (unquick && (pw = getpwnam(name))) {
-			p->pwd = pwdcopy(pw);
-			decode(p);
-			p->name = p->pwd->pw_name;
-		} else
-			p->name = strcpy(malloc(strlen(name) + 1), name);
-	}
-	if (unquick) {
-		fwclose();
-		endpwent();
-	}
-	close(uf);
-	if (person1 == 0) {
-		printf("No one logged on\n");
-		return;
-	}
-	p->link = 0;
-}
-
-static void donames(argv)
-	char **argv;
-{
-	register struct person *p;
-	register struct passwd *pw;
-	int uf;
-
-	/*
-	 * get names from command line and check to see if they're
-	 * logged in
-	 */
-	unshort = !small;
-	for (; *argv != 0; argv++) {
-		if (netfinger(*argv))
-			continue;
-		if (person1 == 0)
-			p = person1 = (struct person *) malloc(sizeof *p);
-		else {
-			p->link = (struct person *) malloc(sizeof *p);
-			p = p->link;
-		}
-		p->name = *argv;
-		p->loggedin = 0;
-		p->original = 1;
-		p->pwd = 0;
-	}
-	if (person1 == 0)
-		return;
-	p->link = 0;
-	/*
-	 * if we are doing it, read /etc/passwd for the useful info
-	 */
-	if (unquick) {
-		setpwent();
-		if (!match) {
-			for (p = person1; p != 0; p = p->link)
-				if (pw = getpwnam(p->name))
-					p->pwd = pwdcopy(pw);
-		} else while ((pw = getpwent()) != 0) {
-			for (p = person1; p != 0; p = p->link) {
-				if (!p->original)
-					continue;
-				if (strcmp(p->name, pw->pw_name) != 0 &&
-				    !matchcmp(pw->pw_gecos, pw->pw_name, p->name))
-					continue;
-				if (p->pwd == 0)
-					p->pwd = pwdcopy(pw);
-				else {
-					struct person *new;
-					/*
-					 * handle multiple login names, insert
-					 * new "duplicate" entry behind
-					 */
-					new = (struct person *)
-						malloc(sizeof *new);
-					new->pwd = pwdcopy(pw);
-					new->name = p->name;
-					new->original = 1;
-					new->loggedin = 0;
-					new->link = p->link;
-					p->original = 0;
-					p->link = new;
-					p = new;
-				}
-			}
-		}
-		endpwent();
-	}
-	/* Now get login information */
-	if ((uf = open(USERLOG, 0)) < 0) {
-		fprintf(stderr, "finger: error opening %s\n", USERLOG);
-		exit(2);
-	}
-	while (read(uf, (char *)&user, sizeof user) == sizeof user) {
-		if (*user.ut_name == 0)
-			continue;
-		for (p = person1; p != 0; p = p->link) {
-			if (p->loggedin == 2)
-				continue;
-			if (strncmp(p->pwd ? p->pwd->pw_name : p->name,
-				    user.ut_name, NMAX) != 0)
-				continue;
-			if (p->loggedin == 0) {
-				bcopy(user.ut_line, p->tty, LMAX);
-				p->tty[LMAX] = 0;
-				bcopy(user.ut_host, p->host, HMAX);
-				p->host[HMAX] = 0;
-				p->loginat = user.ut_time;
-				p->loggedin = 1;
-			} else {	/* p->loggedin == 1 */
-				struct person *new;
-				new = (struct person *) malloc(sizeof *new);
-				new->name = p->name;
-				bcopy(user.ut_line, new->tty, LMAX);
-				new->tty[LMAX] = 0;
-				bcopy(user.ut_host, new->host, HMAX);
-				new->host[HMAX] = 0;
-				new->loginat = user.ut_time;
-				new->pwd = p->pwd;
-				new->loggedin = 1;
-				new->original = 0;
-				new->link = p->link;
-				p->loggedin = 2;
-				p->link = new;
-				p = new;
-			}
-		}
-	}
-	close(uf);
-	if (unquick) {
-		fwopen();
-		for (p = person1; p != 0; p = p->link)
-			decode(p);
-		fwclose();
-	}
-}
-
-static void print()
-{
-	register FILE *fp;
-	register struct person *p;
-	register char *s;
-	register c;
-
-	/*
-	 * print out what we got
-	 */
-	if (header) {
-		if (unquick) {
-			if (!unshort)
-				if (wide)
-					printf("Login       Name              TTY Idle    When            Where\n");
-				else
-					printf("Login    TTY Idle    When            Where\n");
-		} else {
-			printf("Login      TTY            When");
-			if (idle)
-				printf("             Idle");
-			putchar('\n');
-		}
-	}
-	for (p = person1; p != 0; p = p->link) {
-		if (!unquick) {
-			quickprint(p);
-			continue;
-		}
-		if (!unshort) {
-			shortprint(p);
-			continue;
-		}
-		personprint(p);
-		if (p->pwd != 0 && !AlreadyPrinted(p->pwd->pw_uid)) {
-			AnyMail(p->pwd->pw_name);
-			if (hack) {
-				s = malloc(strlen(p->pwd->pw_dir) +
-					sizeof PROJ);
-				strcpy(s, p->pwd->pw_dir);
-				strcat(s, PROJ);
-				if ((fp = fopen(s, "r")) != 0) {
-					printf("Project: ");
-					while ((c = getc(fp)) != EOF) {
-						if (c == '\n')
-							break;
-						if (isprint(c) || isspace(c))
-							putchar(c);
-						else
-							putchar(c ^ 100);
-					}
-					fclose(fp);
-					putchar('\n');
-				}
-				free(s);
-			}
-			if (plan) {
-				s = malloc(strlen(p->pwd->pw_dir) +
-					sizeof PLAN);
-				strcpy(s, p->pwd->pw_dir);
-				strcat(s, PLAN);
-				if ((fp = fopen(s, "r")) == 0) {
-					if (!NONOTHING) printf("No Plan.\n");
-				} else {
-					printf("Plan:\n");
-					while ((c = getc(fp)) != EOF)
-						if (isprint(c) || isspace(c))
-							putchar(c);
-						else
-							putchar(c ^ 100);
-					fclose(fp);
-				}
-				free(s);
-			}
-		}
-		if (p->link != 0)
-			putchar('\n');
-	}
-}
-
-/*
- * Duplicate a pwd entry.
- * Note: Only the useful things (what the program currently uses) are copied.
- */
-static struct passwd *
-pwdcopy(pfrom)
-	register struct passwd *pfrom;
-{
-	register struct passwd *pto;
-
-	pto = (struct passwd *) malloc(sizeof *pto);
-#define savestr(s) strcpy(malloc(strlen(s) + 1), s)
-	pto->pw_name = savestr(pfrom->pw_name);
-	pto->pw_uid = pfrom->pw_uid;
-	pto->pw_gecos = savestr(pfrom->pw_gecos);
-	pto->pw_dir = savestr(pfrom->pw_dir);
-	pto->pw_shell = savestr(pfrom->pw_shell);
-#undef savestr
-	return pto;
-}
-
-/*
- * print out information on quick format giving just name, tty, login time
- * and idle time if idle is set.
- */
-static void quickprint(pers)
-	register struct person *pers;
-{
-	printf("%-*.*s  ", NMAX, NMAX, pers->name);
-	if (pers->loggedin) {
-		if (idle) {
-			findidle(pers);
-			printf("%c%-*s %-16.16s", pers->writable ? ' ' : '*',
-				LMAX, pers->tty, ctime(&pers->loginat));
-			ltimeprint("   ", &pers->idletime, "");
-		} else
-			printf(" %-*s %-16.16s", LMAX,
-				pers->tty, ctime(&pers->loginat));
-		putchar('\n');
-	} else
-		printf("          Not Logged In\n");
-}
-
-/*
- * print out information in short format, giving login name, full name,
- * tty, idle time, login time, and host.
- */
-static void shortprint(pers)
-	register struct person *pers;
-{
-	char *p;
-	char dialup;
-
-	if (pers->pwd == 0) {
-		printf("%-15s       ???\n", pers->name);
-		return;
-	}
-	printf("%-*s", NMAX, pers->pwd->pw_name);
-	dialup = 0;
-	if (wide) {
-		if (pers->realname)
-			printf(" %-20.20s", pers->realname);
-		else
-			printf("        ???          ");
-	}
-	putchar(' ');
-	if (pers->loggedin && !pers->writable)
-		putchar('*');
-	else
-		putchar(' ');
-	if (*pers->tty) {
-		if (pers->tty[0] == 't' && pers->tty[1] == 't' &&
-		    pers->tty[2] == 'y') {
-			if (pers->tty[3] == 'd' && pers->loggedin)
-				dialup = 1;
-			printf("%-2.2s ", pers->tty + 3);
-		} else
-			printf("%-2.2s ", pers->tty);
-	} else
-		printf("   ");
-	p = ctime(&pers->loginat);
-	if (pers->loggedin) {
-		stimeprint(&pers->idletime);
-		printf(" %3.3s %-5.5s ", p, p + 11);
-	} else if (pers->loginat == 0)
-		printf(" < .  .  .  . >");
-	else if (tloc - pers->loginat >= 180L * 24 * 60 * 60)
-		printf(" <%-6.6s, %-4.4s>", p + 4, p + 20);
-	else
-		printf(" <%-12.12s>", p + 4);
-	if (pers->host[0])
-		printf(" %-20.20s", pers->host);
-	putchar('\n');
-}
-
-
-/*
- * print out a person in long format giving all possible information.
- * directory and shell are inhibited if unbrief is clear.
- */
-static void
-personprint(pers)
-	register struct person *pers;
-{
-	if (pers->pwd == 0) {
-		printf("Login name: %-10s\t\t\tIn real life: ???\n",
-			pers->name);
-		return;
-	}
-	printf("Login name: %-10s", pers->pwd->pw_name);
-	if (pers->loggedin && !pers->writable)
-		printf("	(messages off)	");
-	else
-		printf("			");
-	if (pers->realname)
-		printf("In real life: %s", pers->realname);
-	if (unbrief) {
-		printf("\nDirectory: %-25s", pers->pwd->pw_dir);
-		if (*pers->pwd->pw_shell)
-			printf("\tShell: %-s", pers->pwd->pw_shell);
-	}
-	if (pers->loggedin) {
-		register char *ep = ctime(&pers->loginat);
-		if (*pers->host) {
-			printf("\nOn since %15.15s on %s from %s",
-				&ep[4], pers->tty, pers->host);
-			ltimeprint("\n", &pers->idletime, " Idle Time");
-		} else {
-			printf("\nOn since %15.15s on %-*s",
-				&ep[4], LMAX, pers->tty);
-			ltimeprint("\t", &pers->idletime, " Idle Time");
-		}
-	} else if (pers->loginat == 0) {
-		if (lf >= 0) printf("\nNever logged in.");
-	} else if (tloc - pers->loginat > 180L * 24 * 60 * 60) {
-		register char *ep = ctime(&pers->loginat);
-		printf("\nLast login %10.10s, %4.4s on %s",
-			ep, ep+20, pers->tty);
-		if (*pers->host)
-			printf(" from %s", pers->host);
-	} else {
-		register char *ep = ctime(&pers->loginat);
-		printf("\nLast login %16.16s on %s", ep, pers->tty);
-		if (*pers->host)
-			printf(" from %s", pers->host);
-	}
-	putchar('\n');
-}
-
-
-/*
- * decode the information in the gecos field of /etc/passwd
- */
-static void
-decode(pers)
-	register struct person *pers;
-{
-	char buffer[256];
-	register char *bp, *gp, *lp;
-	int alldigits;
-	int hasspace;
-	int len;
-
-	pers->realname = 0;
-	if (pers->pwd == 0)
-		return;
-	gp = pers->pwd->pw_gecos;
-	bp = buffer;
-	if (*gp == ASTERISK)
-		gp++;
-	while (*gp && *gp != COMMA) 			/* name */
-		if (*gp == SAMENAME) {
-			lp = pers->pwd->pw_name;
-			if (islower(*lp))
-				*bp++ = toupper(*lp++);
-			while (*bp++ = *lp++)
-				;
-			bp--;
-			gp++;
-		} else
-			*bp++ = *gp++;
-	*bp++ = 0;
-	if ((len = bp - buffer) > 1)
-		pers->realname = strcpy(malloc(len), buffer);
-	if (pers->loggedin)
-		findidle(pers);
-	else
-		findwhen(pers);
-}
-
-/*
- * find the last log in of a user by checking the LASTLOG file.
- * the entry is indexed by the uid, so this can only be done if
- * the uid is known (which it isn't in quick mode)
- */
-
-static void
-fwopen()
-{
-	if ((lf = open(LASTLOG, 0)) < 0) {
-		if (errno == ENOENT) return;
-		fprintf(stderr, "finger: %s open error\n", LASTLOG);
-	}
-}
-
-static void
-findwhen(pers)
-	register struct person *pers;
-{
-	struct utmp ll;
-#define ll_line ut_line
-#define ll_host ut_host
-#define ll_time ut_time
-
-	int i;
-
-	if (lf >= 0) {
-		lseek(lf, (long)pers->pwd->pw_uid * sizeof ll, 0);
-		if ((i = read(lf, (char *)&ll, sizeof ll)) == sizeof ll) {
-			bcopy(ll.ll_line, pers->tty, LMAX);
-			pers->tty[LMAX] = 0;
-			bcopy(ll.ll_host, pers->host, HMAX);
-			pers->host[HMAX] = 0;
-			pers->loginat = ll.ll_time;
-		} else {
-			if (i != 0)
-				fprintf(stderr, "finger: %s read error\n",
-					LASTLOG);
-			pers->tty[0] = 0;
-			pers->host[0] = 0;
-			pers->loginat = 0L;
-		}
-	} else {
-		pers->tty[0] = 0;
-		pers->host[0] = 0;
-		pers->loginat = 0L;
-	}
-}
-
-static void fwclose()
-{
-	if (lf >= 0)
-		close(lf);
-}
-
-/*
- * find the idle time of a user by doing a stat on /dev/tty??,
- * where tty?? has been gotten from USERLOG, supposedly.
- */
-static void
-findidle(pers)
-	register struct person *pers;
-{
-	struct stat ttystatus;
-	static char buffer[20] = "/dev/";
-	long t;
-#define TTYLEN 5
-
-	strcpy(buffer + TTYLEN, pers->tty);
-	buffer[TTYLEN+LMAX] = 0;
-	if (stat(buffer, &ttystatus) < 0) {
-		fprintf(stderr, "finger: Can't stat %s\n", buffer);
-		exit(4);
-	}
-	time(&t);
-	if (t < ttystatus.st_atime)
-		pers->idletime = 0L;
-	else
-		pers->idletime = t - ttystatus.st_atime;
-	pers->writable = (ttystatus.st_mode & TALKABLE) == TALKABLE;
-}
-
-/*
- * print idle time in short format; this program always prints 4 characters;
- * if the idle time is zero, it prints 4 blanks.
- */
-static void
-stimeprint(dt)
-	long *dt;
-{
-	register struct tm *delta;
-
-	delta = gmtime(dt);
-	if (delta->tm_yday == 0)
-		if (delta->tm_hour == 0)
-			if (delta->tm_min == 0)
-				printf("    ");
-			else
-				printf("  %2d", delta->tm_min);
-		else
-			if (delta->tm_hour >= 10)
-				printf("%3d:", delta->tm_hour);
-			else
-				printf("%1d:%02d",
-					delta->tm_hour, delta->tm_min);
-	else
-		printf("%3dd", delta->tm_yday);
-}
-
-/*
- * print idle time in long format with care being taken not to pluralize
- * 1 minutes or 1 hours or 1 days.
- * print "prefix" first.
- */
-static int
-ltimeprint(before, dt, after)
-	long *dt;
-	char *before, *after;
-{
-	register struct tm *delta;
-
-	delta = gmtime(dt);
-	if (delta->tm_yday == 0 && delta->tm_hour == 0 && delta->tm_min == 0 &&
-	    delta->tm_sec <= 10)
-		return (0);
-	printf("%s", before);
-	if (delta->tm_yday >= 10)
-		printf("%d days", delta->tm_yday);
-	else if (delta->tm_yday > 0)
-		printf("%d day%s %d hour%s",
-			delta->tm_yday, delta->tm_yday == 1 ? "" : "s",
-			delta->tm_hour, delta->tm_hour == 1 ? "" : "s");
-	else
-		if (delta->tm_hour >= 10)
-			printf("%d hours", delta->tm_hour);
-		else if (delta->tm_hour > 0)
-			printf("%d hour%s %d minute%s",
-				delta->tm_hour, delta->tm_hour == 1 ? "" : "s",
-				delta->tm_min, delta->tm_min == 1 ? "" : "s");
-		else
-			if (delta->tm_min >= 10)
-				printf("%2d minutes", delta->tm_min);
-			else if (delta->tm_min == 0)
-				printf("%2d seconds", delta->tm_sec);
-			else
-				printf("%d minute%s %d second%s",
-					delta->tm_min,
-					delta->tm_min == 1 ? "" : "s",
-					delta->tm_sec,
-					delta->tm_sec == 1 ? "" : "s");
-	printf("%s", after);
-}
-
-static int
-matchcmp(gname, login, given)
-	register char *gname;
-	char *login;
-	char *given;
-{
-	char buffer[100];
-	register char *bp, *lp;
-	register c;
-
-	if (*gname == ASTERISK)
-		gname++;
-	lp = 0;
-	bp = buffer;
-	for (;;)
-		switch (c = *gname++) {
-		case SAMENAME:
-			for (lp = login; bp < buffer + sizeof buffer
-					 && (*bp++ = *lp++);)
-				;
-			bp--;
-			break;
-		case ' ':
-		case COMMA:
-		case '\0':
-			*bp = 0;
-			if (namecmp(buffer, given))
-				return (1);
-			if (c == COMMA || c == 0)
-				return (0);
-			bp = buffer;
-			break;
-		default:
-			if (bp < buffer + sizeof buffer)
-				*bp++ = c;
-		}
-	/*NOTREACHED*/
-}
-
-static int
-namecmp(name1, name2)
-	register char *name1, *name2;
-{
-	register c1, c2;
-
-	for (;;) {
-		c1 = *name1++;
-		if (islower(c1))
-			c1 = toupper(c1);
-		c2 = *name2++;
-		if (islower(c2))
-			c2 = toupper(c2);
-		if (c1 != c2)
-			break;
-		if (c1 == 0)
-			return (1);
-	}
-	if (!c1) {
-		for (name2--; isdigit(*name2); name2++)
-			;
-		if (*name2 == 0)
-			return (1);
-	} else if (!c2) {
-		for (name1--; isdigit(*name1); name1++)
-			;
-		if (*name2 == 0)
-			return (1);
-	}
-	return (0);
-}
-
-#if NONET
-static int
-netfinger(name)
-char *name;
-{
-	return 0;
-}
-#else
-static int
-netfinger(name)
-	char *name;
-{
-	char *host;
-	char fname[100];
-	struct hostent *hp;
-	struct servent *sp;
-	int s, result;
-#if !_MINIX
-	char *rindex();
-#endif
-	register FILE *f;
-	register int c;
-	register int lastc;
-	nwio_tcpconf_t tcpconf;
-	nwio_tcpcl_t tcpconnopt;
-	char *tcp_device;
-
-	if (name == NULL)
-		return (0);
-	host = rindex(name, '@');
-	if (host == NULL)
-		return (0);
-	*host++ = 0;
-	hp = gethostbyname(host);
-	if (hp == NULL) {
-		static struct hostent def;
-		static ipaddr_t defaddr;
-		static char namebuf[128];
-
-		defaddr = inet_addr(host);
-		if (defaddr == -1) {
-			printf("unknown host: %s\n", host);
-			return (1);
-		}
-		strcpy(namebuf, host);
-		def.h_name = namebuf;
-		def.h_addr = (char *)&defaddr;
-		def.h_length = sizeof (ipaddr_t);
-		def.h_addrtype = AF_INET;
-		def.h_aliases = 0;
-		hp = &def;
-	}
-	printf("[%s] ", hp->h_name);
-	fflush(stdout);
-
-	tcp_device= getenv("TCP_DEVICE");
-	if (tcp_device == NULL)
-		tcp_device= TCP_DEVICE;
-	s= open (tcp_device, O_RDWR);
-	if (s == -1)
-	{
-		fprintf(stderr, "%s: unable to open %s (%s)\n",
-			prog_name, tcp_device, strerror(errno));
-		exit(1);
-	}
-	tcpconf.nwtc_flags= NWTC_LP_SEL | NWTC_SET_RA | NWTC_SET_RP;
-	tcpconf.nwtc_remaddr= *(ipaddr_t *)hp->h_addr;
-	tcpconf.nwtc_remport= htons(TCPPORT_FINGER);
-
-	result= ioctl (s, NWIOSTCPCONF, &tcpconf);
-	if (result<0)
-	{
-		fprintf(stderr, "%s\n", strerror(errno));
-		exit(1);
-	}
-
-	tcpconnopt.nwtcl_flags= 0;
-
-	do
-	{
-		result= ioctl (s, NWIOTCPCONN, &tcpconnopt);
-		if (result<0 && errno== EAGAIN)
-		{
-			fprintf(stderr, "got EAGAIN error, sleeping 2s\n");
-			sleep(2);
-		}
-	} while (result<0 && errno == EAGAIN);
-	if (result<0)
-	{
-		fprintf(stderr, "%s\n", strerror(errno));
-		exit(1);
-	}
-	printf("\r\n");
-	if (large) write(s, "/W ", 3);
-	write(s, name, strlen(name));
-	write(s, "\r\n", 2);
-	f = fdopen(s, "r");
-	while ((c = getc(f)) != EOF) {
-/*
-		switch(c) {
-		case 0210:
-		case 0211:
-		case 0212:
-		case 0214:
-			c -= 0200;
-			break;
-		case 0215:
-			c = '\n';
-			break;
-		}
-*/
-		c &= ~0200;
-		if (c == '\r')
-		{
-			c= getc(f) & ~0200;
-			if (c == '\012')
-			{
-				lastc= c;
-				putchar('\n');
-				continue;
-			}
-			else
-				putchar('\r');
-		}
-		lastc = c;
-		if (isprint(c) || isspace(c))
-			putchar(c);
-		else
-			putchar(c ^ 100);
-	}
-	if (lastc != '\n')
-		putchar('\n');
-	(void)fclose(f);
-	return (1);
-}
-#endif
-
-/*
- *	AnyMail - takes a username (string pointer thereto), and
- *	prints on standard output whether there is any unread mail,
- *	and if so, how old it is.	(JCM@Shasta 15 March 80)
- */
-#define preamble "/usr/spool/mail/"	/* mailboxes are there */
-static int
-AnyMail(name)
-char *name;
-{
-	struct stat buf;		/* space for file status buffer */
-	char *mbxdir = preamble; 	/* string with path preamble */
-	char *mbxpath;			/* space for entire pathname */
-
-#if !_MINIX
-	char *ctime();			/* convert longword time to ascii */
-#endif
-	char *timestr;
-
-	mbxpath = malloc(strlen(name) + strlen(preamble) + 1);
-
-	strcpy(mbxpath, mbxdir);	/* copy preamble into path name */
-	strcat(mbxpath, name);		/* concatenate user name to path */
-
-	if (stat(mbxpath, &buf) == -1 || buf.st_size == 0) {
-	    /* Mailbox is empty or nonexistent */
-	    if (!NONOTHING) printf("No unread mail\n");
-        } else {
-	    if (buf.st_mtime == buf.st_atime) {
-		/* There is something in the mailbox, but we can't really
-		 *   be sure whether it is mail held there by the user
-		 *   or a (single) new message that was placed in a newly
-		 *   recreated mailbox, so we punt and call it "unread mail."
-		 */
-		printf("Unread mail since ");
-	        printf(ctime(&buf.st_mtime));
-	    } else {
-		/* New mail has definitely arrived since the last time
-		 *   mail was read.  mtime is the time the most recent
-		 *   message arrived; atime is either the time the oldest
-		 *   unread message arrived, or the last time the mail
-		 *   was read.
-		 */
-		printf("New mail received ");
-		timestr = ctime(&buf.st_mtime);	/* time last modified */
-		timestr[24] = '\0';		/* suppress newline (ugh) */
-		printf(timestr);
-		printf(";\n  unread since ");
-	        printf(ctime(&buf.st_atime));	/* time last accessed */
-	    }
-	}
-	
-	free(mbxpath);
-}
-
-/*
- * return true iff we've already printed project/plan for this uid;
- * if not, enter this uid into table (so this function has a side-effect.)
- */
-#define	PPMAX	200		/* assume no more than 200 logged-in users */
-int	PlanPrinted[PPMAX+1];
-int	PPIndex = 0;		/* index of next unused table entry */
-
-static int
-AlreadyPrinted(uid)
-int uid;
-{
-	int i = 0;
-	
-	while (i++ < PPIndex) {
-	    if (PlanPrinted[i] == uid)
-		return(1);
-	}
-	if (i < PPMAX) {
-	    PlanPrinted[i] = uid;
-	    PPIndex++;
-	}
-	return(0);
-}
Index: trunk/minix/commands/simple/fix.c
===================================================================
--- trunk/minix/commands/simple/fix.c	(revision 9)
+++ 	(revision )
@@ -1,224 +1,0 @@
-/* fix file difflist - update file from difflist     Author: Erik Baalbergen */
-
-
-/* Notes: files old and old.patch are equal after the following commands
-     diff old new > difflist
-     patch old difflist > old.patch
-   * the diff output is assumed to be produced by my diff program.
-   * the difflist has the following form:
-     difflist ::= chunk*
-     chunk ::= append | delete | change ;
-     append ::= n1 'a' n2 [',' n3]? '\n' ['> ' line '\n'](n3 - n2 + 1)
-     delete ::= n1 [',' n2]? 'd' n3 '\n' ['< ' line '\n'](n2 - n1 + 1)
-     change ::= n1 [',' n2]? 'c' n3 [',' n4]? '\n'
-	      ['< ' line '\n'](n2 - n1 + 1)
-	      '---\n'
-	      ['> ' line '\n'](n4 - n3 + 1)
-     where
-     - n[1234] is an unsigned integer
-     - "[pat](expr)" means "(expr) occurences of pat"
-     - "[pat]?" means "either pat or nothing"
-   * the information in the diff listing is checked against the file to which
-     it is applied; an error is printed if there is a conflict
-*/
-
-#include <ctype.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#define IGNORE_WHITE_SPACE	/* This makes it white space insensitive */
-
-#ifdef IGNORE_WHITE_SPACE
-#define strcmp strwcmp
-#endif
-
-#define LINELEN	1024
-
-char *prog = 0, *processing = 0;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(char *getline, (FILE *fp, char *b));
-_PROTOTYPE(char *range, (char *s, int *p1, int *p2));
-_PROTOTYPE(int getcommand, (FILE *fp, int *o1, int *o2, char *pcmd, int *n1, int *n2));
-_PROTOTYPE(void fatal, (char *s, ...));
-_PROTOTYPE(int strwcmp, (char *s1, char *s2));
-_PROTOTYPE(int whitespace, (int ch));
-
-char *
- getline(fp, b)
-FILE *fp;
-char *b;
-{
-  if (fgets(b, LINELEN, fp) == NULL) fatal("unexpected eof");
-
-  return b;
-}
-
-#define copy(str) printf("%s", str)
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  char cmd, *fl, *fd, obuf[LINELEN], nbuf[LINELEN];
-  int o1, o2, n1, n2, here;
-  FILE *fpf, *fpd;
-
-  prog = argv[0];
-  processing = argv[1];
-  if (argc != 3) fatal("use: %s original-file diff-list-file", prog);
-  if ((fpf = fopen(argv[1], "r")) == NULL) fatal("can't read %s", argv[1]);
-  if ((fpd = fopen(argv[2], "r")) == NULL) fatal("can't read %s", argv[2]);
-  here = 0;
-  while (getcommand(fpd, &o1, &o2, &cmd, &n1, &n2)) {
-	while (here < o1 - 1) {
-		here++;
-		copy(getline(fpf, obuf));
-	}
-	switch (cmd) {
-	    case 'c':
-	    case 'd':
-		if (cmd == 'd' && n1 != n2) fatal("delete count conflict");
-		while (o1 <= o2) {
-			fl = getline(fpf, obuf);
-			here++;
-			fd = getline(fpd, nbuf);
-			if (strncmp(fd, "<", (size_t)1))
-				fatal("illegal delete line");
-			if (strcmp(fl, fd + 2))
-				fatal("delete line conflict");
-			o1++;
-		}
-		if (cmd == 'd') break;
-		if (strcmp(getline(fpd, nbuf), "---\n"))
-			fatal("illegal separator in chunk");
-		/* FALLTHROUGH */
-	    case 'a':
-		if (cmd == 'a') {
-			if (o1 != o2) fatal("append count conflict");
-			copy(getline(fpf, obuf));
-			here++;
-		}
-		while (n1 <= n2) {
-			if (strncmp(getline(fpd, nbuf), ">", (size_t)1))
-				fatal("illegal append line");
-			copy(nbuf + 2);
-			n1++;
-		}
-		break;
-	}
-  }
-  while (fgets(obuf, LINELEN, fpf) != NULL) copy(obuf);
-  return(0);
-}
-
-char *
- range(s, p1, p2)
-char *s;
-int *p1, *p2;
-{
-  register int v1 = 0, v2;
-
-  while (isdigit(*s)) v1 = 10 * v1 + *s++ - '0';
-  v2 = v1;
-  if (*s == ',') {
-	s++;
-	v2 = 0;
-	while (isdigit(*s)) v2 = 10 * v2 + *s++ - '0';
-  }
-  if (v1 > v2) fatal("illegal range");
-  *p1 = v1;
-  *p2 = v2;
-  return s;
-}
-
-int getcommand(fp, o1, o2, pcmd, n1, n2)
-FILE *fp;
-int *o1, *o2, *n1, *n2;
-char *pcmd;
-{
-  char buf[LINELEN];
-  register char *s;
-  char cmd;
-
-  if ((s = fgets(buf, LINELEN, fp)) == NULL) return 0;
-  s = range(s, o1, o2);
-  if ((cmd = *s++) != 'a' && cmd != 'c' && cmd != 'd')
-	fatal("illegal command");
-  s = range(s, n1, n2);
-  if (*s != '\n' && s[1] != '\0')
-	fatal("extra characters at end of command: %s", s);
-  *pcmd = cmd;
-  return 1;
-}
-
-#ifdef __STDC__
-void fatal(char *s, ...)
-{
-  va_list args;
-
-  va_start (args, s);
-  fprintf(stderr, "%s: processing: %s fatal: ", prog, processing);
-  vfprintf(stderr, s, args);
-  fprintf(stderr, "\n");
-  va_end(args);
-  exit(1);
-}
-#else
-/* the K&R lib does not have vfprintf */
-void fatal(s, a)
-char *s, *a;
-{
-  fprintf(stderr, "%s: processing: %s fatal: ", prog, processing);
-  fprintf(stderr, s, a);
-  fprintf(stderr, "\n");
-  exit(1);
-}
-#endif
-
-#ifdef IGNORE_WHITE_SPACE
-
-/* This routine is a white space insensitive version of strcmp.
-   It is needed for testing things which might have undergone
-   tab conversion or trailing space removal
-   Bret Mckee June, 1988 */
-
-int strwcmp(s1, s2)
-char *s1, *s2;
-{
-  char *x1 = s1, *x2 = s2;
-
-  /* Remove leading white space */
-  while (whitespace(*s1)) s1++;
-  while (whitespace(*s2)) s2++;
-  do {
-	while ((*s1 == *s2) && *s1 && *s2) {
-		s1++;
-		s2++;
-	}
-	;			/* consume identical characters */
-	while (whitespace(*s1)) s1++;
-	while (whitespace(*s2)) s2++;
-  } while (*s1 && *s2 && (*s1 == *s2));
-  if (*s1 - *s2)
-	fprintf(stderr, "Failing for (%x)[%s]\n            (%x)[%s]\n",
-		(int) *s1, x1, (int) *s2, x2);
-  return(*s1 - *s2);
-}
-
-int whitespace(ch)
-char ch;
-{
-  switch (ch) {
-      case ' ':
-      case '\n':
-      case 0x0D:
-      case '\t':
-	return(1);
-      default:	return(0);
-}
-}
-
-#endif
Index: trunk/minix/commands/simple/fold.c
===================================================================
--- trunk/minix/commands/simple/fold.c	(revision 9)
+++ 	(revision )
@@ -1,70 +1,0 @@
-/* fold - folds long lines		Author: Terrence W. Holm */
-
-/*  Usage:  fold  [ -width ]  [ file ... ]  */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#define  TAB		8
-#define  DEFAULT_WIDTH  80
-
-int column = 0;			/* Current column, retained between files  */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void Fold, (FILE *f, int width));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int width = DEFAULT_WIDTH;
-  int i;
-  FILE *f;
-
-  if (argc > 1 && argv[1][0] == '-') {
-	if ((width = atoi(&argv[1][1])) <= 0) {
-		fprintf(stderr, "Bad number for fold\n");
-		exit(1);
-	}
-	--argc;
-	++argv;
-  }
-  if (argc == 1)
-	Fold(stdin, width);
-  else {
-	for (i = 1; i < argc; ++i) {
-		if ((f = fopen(argv[i], "r")) == NULL) {
-			perror(argv[i]);
-			exit(1);
-		}
-		Fold(f, width);
-		fclose(f);
-	}
-  }
-  return(0);
-}
-
-
-void Fold(f, width)
-FILE *f;
-int width;
-{
-  int c;
-
-  while ((c = getc(f)) != EOF) {
-	if (c == '\t')
-		column = (column / TAB + 1) * TAB;
-	else if (c == '\b')
-		column = column > 0 ? column - 1 : 0;
-	else if (c == '\n' || c == '\r')
-		column = 0;
-	else
-		++column;
-
-	if (column > width) {
-		putchar('\n');
-		column = c == '\t' ? TAB : 1;
-	}
-	putchar(c);
-  }
-}
Index: trunk/minix/commands/simple/fortune.c
===================================================================
--- trunk/minix/commands/simple/fortune.c	(revision 9)
+++ 	(revision )
@@ -1,75 +1,0 @@
-/*  fortune  -  hand out Chinese fortune cookies	Author: Bert Reuling */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#define COOKIEJAR "/usr/lib/fortune.dat"
-
-static char *Copyright = "\0Copyright (c) 1990 Bert Reuling";
-static unsigned long seed;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(unsigned long magic, (unsigned long range));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int c1, c2, c3;
-  struct stat cookie_stat;
-  FILE *cookie;
-
-  if ((cookie = fopen(COOKIEJAR, "r")) == NULL) {
-	printf("\nSome things better stay closed.\n  - %s\n", argv[0]);
-	exit (-1);
-  }
-
-  /* Create seed from : date, time, user-id and process-id. we can't get
-   * the position of the moon, unfortunately.
-   */
-  seed = time( (time_t *) 0) ^ (long) getuid() ^ (long) getpid();
-
-  if (stat(COOKIEJAR, &cookie_stat) != 0) {
-	printf("\nIt furthers one to see the super guru.\n  - %s\n", argv[0]);
-	exit (-1);
-  }
-  fseek(cookie, magic((unsigned long) cookie_stat.st_size), 0); /* m ove bu magic... */
-
-  c2 = c3 = '\n';
-  while (((c1 = getc(cookie)) != EOF) && ((c1 != '%') || (c2 != '%') || (c3 != '\n'))) {
-	c3 = c2;
-	c2 = c1;
-  }
-
-  if (c1 == EOF) {
-	printf("\nSomething unexpected has happened.\n  - %s", argv[0]);
-	exit (-1);
-  }
-
-  c2 = c3 = '\n';
-  while (((c1 = getc(cookie)) != '%') || (c2 != '%') || (c3 != '\n')) {
-	if (c1 == EOF) {
-		rewind(cookie);
-		continue;
-	}
-	putc(c2, stdout);
-	c3 = c2;
-	c2 = c1;
-  }
-  putc('\n', stdout);
-  fclose(cookie);
-  return (0);
-}
-
-/*  magic  -  please study carefull: there is more than meets the eye */
-unsigned long magic(range)
-unsigned long range;
-{
-
-  seed = 9065531L * (seed % 9065533L) - 2 * (seed / 9065531L) + 1L;
-  return (seed % range);
-}
Index: trunk/minix/commands/simple/fsck.c
===================================================================
--- trunk/minix/commands/simple/fsck.c	(revision 9)
+++ 	(revision )
@@ -1,1592 +1,0 @@
-/* Hacks for version 1.6 */					
-
-#define INODES_PER_BLOCK V2_INODES_PER_BLOCK(block_size)
-#define INODE_SIZE ((int) V2_INODE_SIZE)
-#define WORDS_PER_BLOCK (block_size / (int) sizeof(bitchunk_t))
-#define MAX_ZONES (V2_NR_DZONES+V2_INDIRECTS(block_size)+(long)V2_INDIRECTS(block_size)*V2_INDIRECTS(block_size))
-#define NR_DZONE_NUM V2_NR_DZONES
-#define NR_INDIRECTS V2_INDIRECTS(block_size)
-#define NR_ZONE_NUMS V2_NR_TZONES
-#define ZONE_NUM_SIZE V2_ZONE_NUM_SIZE
-#define bit_nr bit_t
-#define block_nr block_t
-#define d_inode d2_inode
-#define d_inum d_ino
-#define dir_struct struct direct
-#define i_mode d2_mode
-#define i_nlinks d2_nlinks
-#define i_size d2_size
-#define i_zone d2_zone
-#define zone_nr zone_t
-
-/* fsck - file system checker		Author: Robbert van Renesse */
-
-/* Modified by Norbert Schlenker
-*   Removed vestiges of standalone/DOS versions:
-*     - various unused variables and buffers removed
-*     - now uses library functions rather than private internal routines
-*     - bytewise structure copies replaced by structure assignment
-*     - fixed one bug with 14 character file names
-*     - other small tweaks for speed
-*
-* Modified by Lars Fredriksen at the request of Andy Tanenbaum, 90-03-10.
-*   Removed -m option, by which fsck could be told to make a file
-*   system on a 360K floppy.  The code had limited utility, was buggy,
-*   and failed due to a bug in the ACK C compiler.  Use mkfs instead!
-*/
-
-#include <sys/types.h>
-#include <sys/dir.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include "../../servers/fs/const.h"
-#include "../../servers/fs/inode.h"
-#include "../../servers/fs/type.h"
-#include <minix/fslib.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <a.out.h>
-#include <tools.h>
-#include <dirent.h>
-
-#undef N_DATA
-
-unsigned int fs_version = 2, block_size = 0;
-
-#define BITSHIFT	  4	/* = log2(#bits(int)) */
-
-#define MAXPRINT	  80	/* max. number of error lines in chkmap */
-#define CINDIR		128	/* number of indirect zno's read at a time */
-#define CDIRECT		  1	/* number of dir entries read at a time */
-
-/* Macros for handling bitmaps.  Now bit_t is long, these are bulky and the
- * type demotions produce a lot of lint.  The explicit demotion in POWEROFBIT
- * is for efficiency and assumes 2's complement ints.  Lint should be clever
- * enough not to warn about it since BITMASK is small, but isn't.  (It would
- * be easier to get right if bit_t was was unsigned (long) since then there
- * would be no danger from wierd sign representations.  Lint doesn't know
- * we only use non-negative bit numbers.) There will usually be an implicit
- * demotion when WORDOFBIT is used as an array index.  This should be safe
- * since memory for bitmaps will run out first.
- */
-#define BITMASK		((1 << BITSHIFT) - 1)
-#define WORDOFBIT(b)	((b) >> BITSHIFT)
-#define POWEROFBIT(b)	(1 << ((int) (b) & BITMASK))
-#define setbit(w, b)	(w[WORDOFBIT(b)] |= POWEROFBIT(b))
-#define clrbit(w, b)	(w[WORDOFBIT(b)] &= ~POWEROFBIT(b))
-#define bitset(w, b)	(w[WORDOFBIT(b)] & POWEROFBIT(b))
-
-#define ZONE_CT 	360	/* default zones  (when making file system) */
-#define INODE_CT	 95	/* default inodes (when making file system) */
-
-#include "../../servers/fs/super.h"
-static struct super_block sb;
-
-#define STICKY_BIT	01000	/* not defined anywhere else */
-
-/* Ztob gives the block address of a zone
- * btoa gives the byte address of a block
- */
-#define ztob(z)		((block_nr) (z) << sb.s_log_zone_size)
-#define btoa(b)		((long) (b) * block_size)
-#define SCALE		((int) ztob(1))	/* # blocks in a zone */
-#define FIRST		((zone_nr) sb.s_firstdatazone)	/* as the name says */
-
-/* # blocks of each type */
-#define N_IMAP		(sb.s_imap_blocks)
-#define N_ZMAP		(sb.s_zmap_blocks)
-#define N_ILIST		((sb.s_ninodes+INODES_PER_BLOCK-1) / INODES_PER_BLOCK)
-#define N_DATA		(sb.s_zones - FIRST)
-
-/* Block address of each type */
-#define OFFSET_SUPER_BLOCK	SUPER_BLOCK_BYTES
-#define BLK_IMAP	2
-#define BLK_ZMAP	(BLK_IMAP  + N_IMAP)
-#define BLK_ILIST	(BLK_ZMAP  + N_ZMAP)
-#define BLK_FIRST	ztob(FIRST)
-#define ZONE_SIZE	((int) ztob(block_size))
-#define NLEVEL		(NR_ZONE_NUMS - NR_DZONE_NUM + 1)
-
-/* Byte address of a zone/of an inode */
-#define zaddr(z)	btoa(ztob(z))
-#define cinoaddr(i)	((long) (i - 1) * INODE_SIZE + (long) btoa(BLK_ILIST))
-#define INDCHUNK	((int) (CINDIR * ZONE_NUM_SIZE))
-#define DIRCHUNK	((int) (CDIRECT * DIR_ENTRY_SIZE))
-
-char *prog, *fsck_device;		/* program name (fsck), device name */
-int firstcnterr;		/* is this the first inode ref cnt error? */
-bitchunk_t *imap, *spec_imap;	/* inode bit maps */
-bitchunk_t *zmap, *spec_zmap;	/* zone bit maps */
-bitchunk_t *dirmap;		/* directory (inode) bit map */
-char *rwbuf;			/* one block buffer cache */
-block_nr thisblk;		/* block in buffer cache */
-char *nullbuf;	/* null buffer */
-nlink_t *count;			/* inode count */
-int changed;			/* has the diskette been written to? */
-struct stack {
-  dir_struct *st_dir;
-  struct stack *st_next;
-  char st_presence;
-} *ftop;
-
-int dev;			/* file descriptor of the device */
-
-#define DOT	1
-#define DOTDOT	2
-
-/* Counters for each type of inode/zone. */
-int nfreeinode, nregular, ndirectory, nblkspec, ncharspec, nbadinode;
-int npipe, nsyml, ztype[NLEVEL];
-long nfreezone;
-
-int repair, automatic, listing, listsuper;	/* flags */
-int firstlist;			/* has the listing header been printed? */
-unsigned part_offset;		/* sector offset for this partition */
-char answer[] = "Answer questions with y or n.  Then hit RETURN";
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void initvars, (void));
-_PROTOTYPE(void fatal, (char *s));
-_PROTOTYPE(int eoln, (int c));
-_PROTOTYPE(int yes, (char *question));
-_PROTOTYPE(int atoo, (char *s));
-_PROTOTYPE(int input, (char *buf, int size));
-_PROTOTYPE(char *alloc, (unsigned nelem, unsigned elsize));
-_PROTOTYPE(void printname, (char *s));
-_PROTOTYPE(void printrec, (struct stack *sp));
-_PROTOTYPE(void printpath, (int mode, int nlcr));
-_PROTOTYPE(void devopen, (void));
-_PROTOTYPE(void devclose, (void));
-_PROTOTYPE(void devio, (block_nr bno, int dir));
-_PROTOTYPE(void devread, (long offset, char *buf, int size));
-_PROTOTYPE(void devwrite, (long offset, char *buf, int size));
-_PROTOTYPE(void pr, (char *fmt, int cnt, char *s, char *p));
-_PROTOTYPE(void lpr, (char *fmt, long cnt, char *s, char *p));
-_PROTOTYPE(bit_nr getnumber, (char *s));
-_PROTOTYPE(char **getlist, (char ***argv, char *type));
-_PROTOTYPE(void lsuper, (void));
-_PROTOTYPE(void getsuper, (void));
-_PROTOTYPE(void chksuper, (void));
-_PROTOTYPE(void lsi, (char **clist));
-_PROTOTYPE(bitchunk_t *allocbitmap, (int nblk));
-_PROTOTYPE(void loadbitmap, (bitchunk_t *bitmap, block_nr bno, int nblk));
-_PROTOTYPE(void dumpbitmap, (bitchunk_t *bitmap, block_nr bno, int nblk));
-_PROTOTYPE(void fillbitmap, (bitchunk_t *bitmap, bit_nr lwb, bit_nr upb, char **list));
-_PROTOTYPE(void freebitmap, (bitchunk_t *p));
-_PROTOTYPE(void getbitmaps, (void));
-_PROTOTYPE(void putbitmaps, (void));
-_PROTOTYPE(void chkword, (unsigned w1, unsigned w2, bit_nr bit, char *type, int *n, int *report, bit_t));
-_PROTOTYPE(void chkmap, (bitchunk_t *cmap, bitchunk_t *dmap, bit_nr bit, block_nr blkno, int nblk, char *type));
-_PROTOTYPE(void chkilist, (void));
-_PROTOTYPE(void getcount, (void));
-_PROTOTYPE(void counterror, (Ino_t ino));
-_PROTOTYPE(void chkcount, (void));
-_PROTOTYPE(void freecount, (void));
-_PROTOTYPE(void printperm, (mode_t mode, int shift, int special, int overlay));
-_PROTOTYPE(void list, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int Remove, (dir_struct *dp));
-_PROTOTYPE(void make_printable_name, (char *dst, char *src, int n));
-_PROTOTYPE(int chkdots, (Ino_t ino, off_t pos, dir_struct *dp, Ino_t exp));
-_PROTOTYPE(int chkname, (Ino_t ino, dir_struct *dp));
-_PROTOTYPE(int chkentry, (Ino_t ino, off_t pos, dir_struct *dp));
-_PROTOTYPE(int chkdirzone, (Ino_t ino, d_inode *ip, off_t pos, zone_nr zno));
-_PROTOTYPE(int chksymlinkzone, (Ino_t ino, d_inode *ip, off_t pos,
-								zone_nr zno));
-_PROTOTYPE(void errzone, (char *mess, zone_nr zno, int level, off_t pos));
-_PROTOTYPE(int markzone, (zone_nr zno, int level, off_t pos));
-_PROTOTYPE(int chkindzone, (Ino_t ino, d_inode *ip, off_t *pos, zone_nr zno, int level));
-_PROTOTYPE(off_t jump, (int level));
-_PROTOTYPE(int zonechk, (Ino_t ino, d_inode *ip, off_t *pos, zone_nr zno, int level));
-_PROTOTYPE(int chkzones, (Ino_t ino, d_inode *ip, off_t *pos, zone_nr *zlist, int len, int level));
-_PROTOTYPE(int chkfile, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chkdirectory, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chklink, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chkspecial, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chkmode, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chkinode, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int descendtree, (dir_struct *dp));
-_PROTOTYPE(void chktree, (void));
-_PROTOTYPE(void printtotal, (void));
-_PROTOTYPE(void chkdev, (char *f, char **clist, char **ilist, char **zlist));
-
-/* Initialize the variables used by this program. */
-void initvars()
-{
-  register level;
-
-  nregular = ndirectory = nblkspec = ncharspec = nbadinode = npipe = nsyml = 0;
-  for (level = 0; level < NLEVEL; level++) ztype[level] = 0;
-  changed = 0;
-  thisblk = NO_BLOCK;
-  firstlist = 1;
-  firstcnterr = 1;
-}
-
-/* Print the string `s' and exit. */
-void fatal(s)
-char *s;
-{
-  printf("%s\nfatal\n", s);
-  exit(-1);
-}
-
-/* Test for end of line. */
-int eoln(c)
-int c;
-{
-  return(c == EOF || c == '\n' || c == '\r');
-}
-
-/* Ask a question and get the answer unless automatic is set. */
-int yes(question)
-char *question;
-{
-  register int c, answerchar;
-  static int note = 0;
-
-  if (!repair) {
-	printf("\n");
-	return(0);
-  }
-  printf("%s? ", question);
-  if(!note) { printf("(y=yes, n=no, q=quit, A=for yes to all) "); note = 1; }
-  if (automatic) {
-	printf("yes\n");
-	return(1);
-  }
-  fflush(stdout);
-  if ((c = answerchar = getchar()) == 'q' || c == 'Q') exit(1);
-  if(c == 'A') { automatic = 1; c = 'y'; }
-  while (!eoln(c)) c = getchar();
-  return !(answerchar == 'n' || answerchar == 'N');
-}
-
-/* Convert string to integer.  Representation is octal. */
-int atoo(s)
-register char *s;
-{
-  register int n = 0;
-
-  while ('0' <= *s && *s < '8') {
-	n <<= 3;
-	n += *s++ - '0';
-  }
-  return n;
-}
-
-/* If repairing the file system, print a prompt and get a string from user. */
-int input(buf, size)
-char *buf;
-int size;
-{
-  register char *p = buf;
-
-  printf("\n");
-  if (repair) {
-	printf("--> ");
-	fflush(stdout);
-	while (--size) {
-		*p = getchar();
-		if (eoln(*p)) {
-			*p = 0;
-			return(p > buf);
-		}
-		p++;
-	}
-	*p = 0;
-	while (!eoln(getchar()));
-	return(1);
-  }
-  return(0);
-}
-
-/* Allocate some memory and zero it. */
-char *alloc(nelem, elsize)
-unsigned nelem, elsize;
-{
-  char *p;
-
-  if ((p = (char *)malloc((size_t)nelem * elsize)) == 0) {
-  	fprintf(stderr, "Tried to allocate %dkB\n",
-  		nelem*elsize/1024);
-  	fatal("out of memory");
-  }
-  memset((void *) p, 0, (size_t)nelem * elsize);
-  return(p);
-}
-
-/* Print the name in a directory entry. */
-void printname(s)
-char *s;
-{
-  register n = NAME_MAX;
-  int c;
-
-  do {
-	if ((c = *s) == 0) break;
-	if (!isprint(c)) c = '?';
-	putchar(c);
-	s++;
-  } while (--n);
-}
-
-/* Print the pathname given by a linked list pointed to by `sp'.  The
- * names are in reverse order.
- */
-void printrec(sp)
-struct stack *sp;
-{
-  if (sp->st_next != 0) {
-	printrec(sp->st_next);
-	putchar('/');
-	printname(sp->st_dir->d_name);
-  }
-}
-
-/* Print the current pathname.  */
-void printpath(mode, nlcr)
-int mode;
-int nlcr;
-{
-  if (ftop->st_next == 0)
-	putchar('/');
-  else
-	printrec(ftop);
-  switch (mode) {
-      case 1:
-	printf(" (ino = %u, ", ftop->st_dir->d_inum);
-	break;
-      case 2:
-	printf(" (ino = %u)", ftop->st_dir->d_inum);
-	break;
-  }
-  if (nlcr) printf("\n");
-}
-
-/* Open the device.  */
-void devopen()
-{
-  if ((dev = open(fsck_device, repair ? O_RDWR : O_RDONLY)) < 0) {
-	perror(fsck_device);
-	fatal("couldn't open device to fsck");
-  }
-}
-
-/* Close the device. */
-void devclose()
-{
-  if (close(dev) != 0) {
-	perror("close");
-	fatal("");
-  }
-}
-
-/* Read or write a block. */
-void devio(bno, dir)
-block_nr bno;
-int dir;
-{
-  if(!block_size) fatal("devio() with unknown block size");
-  if (dir == READING && bno == thisblk) return;
-  thisblk = bno;
-
-#if 0
-printf("%s at block %5d\n", dir == READING ? "reading " : "writing", bno);
-#endif
-  lseek(dev, (off_t) btoa(bno), SEEK_SET);
-  if (dir == READING) {
-	if (read(dev, rwbuf, block_size) == block_size)
-		return;
-  } else {
-	if (write(dev, rwbuf, block_size) == block_size)
-		return;
-  }
-
-  printf("%s: can't %s block %ld (error = 0x%x)\n", prog,
-         dir == READING ? "read" : "write", (long) bno, errno);
-  if (dir == READING) {
-	printf("Continuing with a zero-filled block.\n");
-	memset(rwbuf, 0, block_size);
-	return;
-  }
-  fatal("");
-}
-
-/* Read `size' bytes from the disk starting at byte `offset'. */
-void devread(offset, buf, size)
-long offset;
-char *buf;
-int size;
-{
-  if(!block_size) fatal("devread() with unknown block size");
-  devio((block_nr) (offset / block_size), READING);
-  memmove(buf, &rwbuf[(int) (offset % block_size)], (size_t)size);  /* lint but OK */
-}
-
-/* Write `size' bytes to the disk starting at byte `offset'. */
-void devwrite(offset, buf, size)
-long offset;
-char *buf;
-int size;
-{
-  if(!block_size) fatal("devwrite() with unknown block size");
-  if (!repair) fatal("internal error (devwrite)");
-  if (size != block_size) devio((block_nr) (offset / block_size), READING);
-  memmove(&rwbuf[(int) (offset % block_size)], buf, (size_t)size);  /* lint but OK */
-  devio((block_nr) (offset / block_size), WRITING);
-  changed = 1;
-}
-
-/* Print a string with either a singular or a plural pronoun. */
-void pr(fmt, cnt, s, p)
-char *fmt, *s, *p;
-int cnt;
-{
-  printf(fmt, cnt, cnt == 1 ? s : p);
-}
-
-/* Same as above, but with a long argument */
-void lpr(fmt, cnt, s, p)
-char *fmt, *s, *p;
-long cnt;
-{
-  printf(fmt, cnt, cnt == 1 ? s : p);
-}
-
-/* Convert string to number. */
-bit_nr getnumber(s)
-register char *s;
-{
-  register bit_nr n = 0;
-
-  if (s == NULL)
-	return NO_BIT;
-  while (isdigit(*s))
-	n = (n << 1) + (n << 3) + *s++ - '0';
-  return (*s == '\0') ? n : NO_BIT;
-}
-
-/* See if the list pointed to by `argv' contains numbers. */
-char **getlist(argv, type)
-char ***argv, *type;
-{
-  register char **list = *argv;
-  register empty = 1;
-
-  while (getnumber(**argv) != NO_BIT) {
-	(*argv)++;
-	empty = 0;
-  }
-  if (empty) {
-	printf("warning: no %s numbers given\n", type);
-	return(NULL);
-  }
-  return(list);
-}
-
-/* Make a listing of the super block.  If `repair' is set, ask the user
- * for changes.
- */
-void lsuper()
-{
-  char buf[80];
-
-  do {
-	/* Most of the following atol's enrage lint, for good reason. */  
-	printf("ninodes       = %u", sb.s_ninodes);
-	if (input(buf, 80)) sb.s_ninodes = atol(buf);
-	printf("nzones        = %ld", sb.s_zones);
-	if (input(buf, 80)) sb.s_zones = atol(buf);
-	printf("imap_blocks   = %u", sb.s_imap_blocks);
-	if (input(buf, 80)) sb.s_imap_blocks = atol(buf);
-	printf("zmap_blocks   = %u", sb.s_zmap_blocks);
-	if (input(buf, 80)) sb.s_zmap_blocks = atol(buf);
-	printf("firstdatazone = %u", sb.s_firstdatazone);
-	if (input(buf, 80)) sb.s_firstdatazone = atol(buf);
-	printf("log_zone_size = %u", sb.s_log_zone_size);
-	if (input(buf, 80)) sb.s_log_zone_size = atol(buf);
-	printf("maxsize       = %ld", sb.s_max_size);
-	if (input(buf, 80)) sb.s_max_size = atol(buf);
-	printf("block size    = %ld", sb.s_block_size);
-	if (input(buf, 80)) sb.s_block_size = atol(buf);
-	if (yes("ok now")) {
-		devwrite(OFFSET_SUPER_BLOCK, (char *) &sb, sizeof(sb));
-		return;
-	}
-  } while (yes("Do you want to try again"));
-  if (repair) exit(0);
-}
-
-/* Get the super block from either disk or user.  Do some initial checks. */
-void getsuper()
-{
-  if(lseek(dev, OFFSET_SUPER_BLOCK, SEEK_SET) < 0) {
-  	perror("lseek");
-  	fatal("couldn't seek to super block.");
-  }
-  if(read(dev, &sb, sizeof(sb)) != sizeof(sb)) {
-  	fatal("couldn't read super block.");
-  }
-  if (listsuper) lsuper();
-  if (sb.s_magic == SUPER_MAGIC) fatal("Cannot handle V1 file systems");
-  if (sb.s_magic == SUPER_V2) {
-  	fs_version = 2;
-  	block_size = /* STATIC_BLOCK_SIZE */ 8192;
-  } else if(sb.s_magic == SUPER_V3) {
-  	fs_version = 3;
-  	block_size = sb.s_block_size;
-  } else {
-  	fatal("bad magic number in super block");
-  }
-  if (sb.s_ninodes <= 0) fatal("no inodes");
-  if (sb.s_zones <= 0) fatal("no zones");
-  if (sb.s_imap_blocks <= 0) fatal("no imap");
-  if (sb.s_zmap_blocks <= 0) fatal("no zmap");
-  if (sb.s_firstdatazone <= 4) fatal("first data zone too small");
-  if (sb.s_log_zone_size < 0) fatal("zone size < block size");
-  if (sb.s_max_size <= 0) fatal("max. file size <= 0");
-
-}
-
-/* Check the super block for reasonable contents. */
-void chksuper()
-{
-  register n;
-  register off_t maxsize;
-
-  n = bitmapsize((bit_t) sb.s_ninodes + 1, block_size);
-  if (sb.s_magic != SUPER_V2 && sb.s_magic != SUPER_V3)
-  	fatal("bad magic number in super block");
-  if (sb.s_imap_blocks < n) {
-  	printf("need %d bocks for inode bitmap; only have %d\n",
-  		n, sb.s_imap_blocks);
-  	fatal("too few imap blocks");
-  }
-  if (sb.s_imap_blocks != n) {
-	pr("warning: expected %d imap_block%s", n, "", "s");
-	printf(" instead of %d\n", sb.s_imap_blocks);
-  }
-  n = bitmapsize((bit_t) sb.s_zones, block_size);
-  if (sb.s_zmap_blocks < n) fatal("too few zmap blocks");
-  if (sb.s_zmap_blocks != n) {
-	pr("warning: expected %d zmap_block%s", n, "", "s");
-	printf(" instead of %d\n", sb.s_zmap_blocks);
-  }
-  if (sb.s_firstdatazone >= sb.s_zones)
-	fatal("first data zone too large");
-  if (sb.s_log_zone_size >= 8 * sizeof(block_nr))
-	fatal("log_zone_size too large");
-  if (sb.s_log_zone_size > 8) printf("warning: large log_zone_size (%d)\n",
-	       sb.s_log_zone_size);
-  n = (BLK_ILIST + N_ILIST + SCALE - 1) >> sb.s_log_zone_size;
-  if (sb.s_firstdatazone < n) fatal("first data zone too small");
-  if (sb.s_firstdatazone != n) {
-	printf("warning: expected first data zone to be %d ", n);
-	printf("instead of %u\n", sb.s_firstdatazone);
-  }
-  maxsize = MAX_FILE_POS;
-  if (((maxsize - 1) >> sb.s_log_zone_size) / block_size >= MAX_ZONES)
-	maxsize = ((long) MAX_ZONES * block_size) << sb.s_log_zone_size;
-  if (sb.s_max_size != maxsize) {
-	printf("warning: expected max size to be %ld ", maxsize);
-	printf("instead of %ld\n", sb.s_max_size);
-  }
-}
-
-int inoaddr(int inn)
-{
-	int a;
-	a = cinoaddr(inn);
-	return a;
-}
-
-/* Make a listing of the inodes given by `clist'.  If `repair' is set, ask
- * the user for changes.
- */
-void lsi(clist)
-char **clist;
-{
-  register bit_nr bit;
-  register ino_t ino;
-  d_inode inode, *ip = &inode;
-  char buf[80];
-
-  if (clist == 0) return;
-  while ((bit = getnumber(*clist++)) != NO_BIT) {
-	setbit(spec_imap, bit);
-	ino = bit;
-	do {
-		devread(inoaddr(ino), (char *) ip, INODE_SIZE);
-		printf("inode %u:\n", ino);
-		printf("    mode   = %6o", ip->i_mode);
-		if (input(buf, 80)) ip->i_mode = atoo(buf);
-		printf("    nlinks = %6u", ip->i_nlinks);
-		if (input(buf, 80)) ip->i_nlinks = atol(buf);
-		printf("    size   = %6ld", ip->i_size);
-		if (input(buf, 80)) ip->i_size = atol(buf);
-		if (yes("Write this back")) {
-			devwrite(inoaddr(ino), (char *) ip, INODE_SIZE);
-			break;
-		}
-	} while (yes("Do you want to change it again"));
-  }
-}
-
-/* Allocate `nblk' blocks worth of bitmap. */
-bitchunk_t *allocbitmap(nblk)
-int nblk;
-{
-  register bitchunk_t *bitmap;
-
-  bitmap = (bitchunk_t *) alloc((unsigned) nblk, block_size);
-  *bitmap |= 1;
-  return(bitmap);
-}
-
-/* Load the bitmap starting at block `bno' from disk. */
-void loadbitmap(bitmap, bno, nblk)
-bitchunk_t *bitmap;
-block_nr bno;
-int nblk;
-{
-  register i;
-  register bitchunk_t *p;
-
-  p = bitmap;
-  for (i = 0; i < nblk; i++, bno++, p += WORDS_PER_BLOCK)
-	devread(btoa(bno), (char *) p, block_size);
-  *bitmap |= 1;
-}
-
-/* Write the bitmap starting at block `bno' to disk. */
-void dumpbitmap(bitmap, bno, nblk)
-bitchunk_t *bitmap;
-block_nr bno;
-int nblk;
-{
-  register i;
-  register bitchunk_t *p = bitmap;
-
-  for (i = 0; i < nblk; i++, bno++, p += WORDS_PER_BLOCK)
-	devwrite(btoa(bno), (char *) p, block_size);
-}
-
-/* Set the bits given by `list' in the bitmap. */
-void fillbitmap(bitmap, lwb, upb, list)
-bitchunk_t *bitmap;
-bit_nr lwb, upb;
-char **list;
-{
-  register bit_nr bit;
-
-  if (list == 0) return;
-  while ((bit = getnumber(*list++)) != NO_BIT)
-	if (bit < lwb || bit >= upb) {
-		if (bitmap == spec_imap)
-			printf("inode number %ld ", bit);
-		else
-			printf("zone number %ld ", bit);
-		printf("out of range (ignored)\n");
-	} else
-		setbit(bitmap, bit - lwb + 1);
-}
-
-/* Deallocate the bitmap `p'. */
-void freebitmap(p)
-bitchunk_t *p;
-{
-  free((char *) p);
-}
-
-/* Get all the bitmaps used by this program. */
-void getbitmaps()
-{
-  imap = allocbitmap(N_IMAP);
-  zmap = allocbitmap(N_ZMAP);
-  spec_imap = allocbitmap(N_IMAP);
-  spec_zmap = allocbitmap(N_ZMAP);
-  dirmap = allocbitmap(N_IMAP);
-}
-
-/* Release all the space taken by the bitmaps. */
-void putbitmaps()
-{
-  freebitmap(imap);
-  freebitmap(zmap);
-  freebitmap(spec_imap);
-  freebitmap(spec_zmap);
-  freebitmap(dirmap);
-}
-
-/* `w1' and `w2' are differing words from two bitmaps that should be
- * identical.  Print what's the matter with them.
- */
-void chkword(w1, w2, bit, type, n, report, phys)
-unsigned w1, w2;
-char *type;
-bit_nr bit;
-int *n, *report;
-bit_nr phys;
-{
-  for (; (w1 | w2); w1 >>= 1, w2 >>= 1, bit++, phys++)
-	if ((w1 ^ w2) & 1 && ++(*n) % MAXPRINT == 0 && *report &&
-	    (!repair || automatic || yes("stop this listing")))
-		*report = 0;
-	else if (*report)
-		if ((w1 & 1) && !(w2 & 1))
-			printf("%s %ld (%ld) is missing\n", type, bit, phys);
-		else if (!(w1 & 1) && (w2 & 1))
-			printf("%s %ld (%ld) is not free\n", type, bit, phys);
-}
-
-/* Check if the given (correct) bitmap is identical with the one that is
- * on the disk.  If not, ask if the disk should be repaired.
- */
-void chkmap(cmap, dmap, bit, blkno, nblk, type)
-bitchunk_t *cmap, *dmap;
-bit_nr bit;
-block_nr blkno;
-int nblk;
-char *type;
-{
-  register bitchunk_t *p = dmap, *q = cmap;
-  int report = 1, nerr = 0;
-  int w = nblk * WORDS_PER_BLOCK;
-  bit_nr phys = 0;
-
-  printf("Checking %s map\n", type);
-  loadbitmap(dmap, blkno, nblk);
-  do {
-	if (*p != *q) chkword(*p, *q, bit, type, &nerr, &report, phys);
-	p++;
-	q++;
-	bit += 8 * sizeof(bitchunk_t);
-	phys += 8 * sizeof(bitchunk_t);
-  } while (--w > 0);
-
-  if ((!repair || automatic) && !report) printf("etc. ");
-  if (nerr > MAXPRINT || nerr > 10) printf("%d errors found. ", nerr);
-  if (nerr != 0 && yes("install a new map")) dumpbitmap(cmap, blkno, nblk);
-  if (nerr > 0) printf("\n");
-}
-
-/* See if the inodes that aren't allocated are cleared. */
-void chkilist()
-{
-  register ino_t ino = 1;
-  mode_t mode;
-
-  printf("Checking inode list\n");
-  do
-	if (!bitset(imap, (bit_nr) ino)) {
-		devread(inoaddr(ino), (char *) &mode, sizeof(mode));
-		if (mode != I_NOT_ALLOC) {
-			printf("mode inode %u not cleared", ino);
-			if (yes(". clear")) devwrite(inoaddr(ino), nullbuf,
-					 INODE_SIZE);
-		}
-	}
-  while (++ino <= sb.s_ninodes && ino != 0);
-  printf("\n");
-}
-
-/* Allocate an array to maintain the inode reference counts in. */
-void getcount()
-{
-  count = (nlink_t *) alloc((unsigned) (sb.s_ninodes + 1), sizeof(nlink_t));
-}
-
-/* The reference count for inode `ino' is wrong.  Ask if it should be adjusted. */
-void counterror(ino)
-ino_t ino;
-{
-  d_inode inode;
-
-  if (firstcnterr) {
-	printf("INODE NLINK COUNT\n");
-	firstcnterr = 0;
-  }
-  devread(inoaddr(ino), (char *) &inode, INODE_SIZE);
-  count[ino] += inode.i_nlinks;	/* it was already subtracted; add it back */
-  printf("%5u %5u %5u", ino, (unsigned) inode.i_nlinks, count[ino]);
-  if (yes(" adjust")) {
-	if ((inode.i_nlinks = count[ino]) == 0) {
-		fatal("internal error (counterror)");
-		inode.i_mode = I_NOT_ALLOC;
-		clrbit(imap, (bit_nr) ino);
-	}
-	devwrite(inoaddr(ino), (char *) &inode, INODE_SIZE);
-  }
-}
-
-/* Check if the reference count of the inodes are correct.  The array `count'
- * is maintained as follows:  an entry indexed by the inode number is
- * incremented each time a link is found; when the inode is read the link
- * count in there is substracted from the corresponding entry in `count'.
- * Thus, when the whole file system has been traversed, all the entries
- * should be zero.
- */
-void chkcount()
-{
-  register ino_t ino;
-
-  for (ino = 1; ino <= sb.s_ninodes && ino != 0; ino++)
-	if (count[ino] != 0) counterror(ino);
-  if (!firstcnterr) printf("\n");
-}
-
-/* Deallocate the `count' array. */
-void freecount()
-{
-  free((char *) count);
-}
-
-/* Print the inode permission bits given by mode and shift. */
-void printperm(mode_t mode, int shift, int special, int overlay)
-{
-  if (mode >> shift & R_BIT)
-	putchar('r');
-  else
-	putchar('-');
-  if (mode >> shift & W_BIT)
-	putchar('w');
-  else
-	putchar('-');
-  if (mode & special)
-	putchar(overlay);
-  else
-	if (mode >> shift & X_BIT)
-		putchar('x');
-	else
-		putchar('-');
-}
-
-/* List the given inode. */
-void list(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  if (firstlist) {
-	firstlist = 0;
-	printf(" inode permission link   size name\n");
-  }
-  printf("%6u ", ino);
-  switch (ip->i_mode & I_TYPE) {
-      case I_REGULAR:		putchar('-');	break;
-      case I_DIRECTORY:		putchar('d');	break;
-      case I_CHAR_SPECIAL:	putchar('c');	break;
-      case I_BLOCK_SPECIAL:	putchar('b');	break;
-      case I_NAMED_PIPE:	putchar('p');	break;
-#ifdef I_SYMBOLIC_LINK
-      case I_SYMBOLIC_LINK:	putchar('l');	break;
-#endif
-      default:			putchar('?');
-}
-  printperm(ip->i_mode, 6, I_SET_UID_BIT, 's');
-  printperm(ip->i_mode, 3, I_SET_GID_BIT, 's');
-  printperm(ip->i_mode, 0, STICKY_BIT, 't');
-  printf(" %3u ", ip->i_nlinks);
-  switch (ip->i_mode & I_TYPE) {
-      case I_CHAR_SPECIAL:
-      case I_BLOCK_SPECIAL:
-	printf("  %2x,%2x ", (dev_t) ip->i_zone[0] >> MAJOR & 0xFF,
-	       (dev_t) ip->i_zone[0] >> MINOR & 0xFF);
-	break;
-      default:	printf("%7ld ", ip->i_size);
-  }
-  printpath(0, 1);
-}
-
-/* Remove an entry from a directory if ok with the user.
- * Don't name the function remove() - that is owned by ANSI, and chaos results
- * when it is a macro.
- */
-int Remove(dp)
-dir_struct *dp;
-{
-  setbit(spec_imap, (bit_nr) dp->d_inum);
-  if (yes(". remove entry")) {
-	count[dp->d_inum]--;
-	memset((void *) dp, 0, sizeof(dir_struct));
-	return(1);
-  }
-  return(0);
-}
-
-/* Convert string so that embedded control characters are printable. */
-void make_printable_name(dst, src, n)
-register char *dst;
-register char *src;
-register int n;
-{
-  register int c;
-
-  while (--n >= 0 && (c = *src++) != '\0') {
-	if (isprint(c) && c != '\\')
-		*dst++ = c;
-	else {
-		*dst++ = '\\';
-		switch (c) {
-		      case '\\':
-			*dst++ = '\\'; break;
-		      case '\b':
-			*dst++ = 'b'; break;
-		      case '\f':
-			*dst++ = 'f'; break;
-		      case '\n':
-			*dst++ = 'n'; break;
-		      case '\r':
-			*dst++ = 'r'; break;
-		      case '\t':
-			*dst++ = 't'; break;
-		      default:
-			*dst++ = '0' + ((c >> 6) & 03);
-			*dst++ = '0' + ((c >> 3) & 07);
-			*dst++ = '0' + (c & 07);
-		}
-	}
-  }
-  *dst = '\0';
-}
-
-/* See if the `.' or `..' entry is as expected. */
-int chkdots(ino, pos, dp, exp)
-ino_t ino, exp;
-off_t pos;
-dir_struct *dp;
-{
-  char printable_name[4 * NAME_MAX + 1];
-
-  if (dp->d_inum != exp) {
-	make_printable_name(printable_name, dp->d_name, sizeof(dp->d_name));
-	printf("bad %s in ", printable_name);
-	printpath(1, 0);
-	printf("%s is linked to %u ", printable_name, dp->d_inum);
-	printf("instead of %u)", exp);
-	setbit(spec_imap, (bit_nr) ino);
-	setbit(spec_imap, (bit_nr) dp->d_inum);
-	setbit(spec_imap, (bit_nr) exp);
-	if (yes(". repair")) {
-		count[dp->d_inum]--;
-		dp->d_inum = exp;
-		count[exp]++;
-		return(0);
-	}
-  } else if (pos != (dp->d_name[1] ? DIR_ENTRY_SIZE : 0)) {
-	make_printable_name(printable_name, dp->d_name, sizeof(dp->d_name));
-	printf("warning: %s has offset %ld in ", printable_name, pos);
-	printpath(1, 0);
-	printf("%s is linked to %u)\n", printable_name, dp->d_inum);
-	setbit(spec_imap, (bit_nr) ino);
-	setbit(spec_imap, (bit_nr) dp->d_inum);
-	setbit(spec_imap, (bit_nr) exp);
-  }
-  return(1);
-}
-
-/* Check the name in a directory entry. */
-int chkname(ino, dp)
-ino_t ino;
-dir_struct *dp;
-{
-  register n = NAME_MAX + 1;
-  register char *p = dp->d_name;
-
-  if (*p == '\0') {
-	printf("null name found in ");
-	printpath(0, 0);
-	setbit(spec_imap, (bit_nr) ino);
-	if (Remove(dp)) return(0);
-  }
-  while (*p != '\0' && --n != 0)
-	if (*p++ == '/') {
-		printf("found a '/' in entry of directory ");
-		printpath(1, 0);
-		setbit(spec_imap, (bit_nr) ino);
-		printf("entry = '");
-		printname(dp->d_name);
-		printf("')");
-		if (Remove(dp)) return(0);
-		break;
-	}
-  return(1);
-}
-
-/* Check a directory entry.  Here the routine `descendtree' is called
- * recursively to check the file or directory pointed to by the entry.
- */
-int chkentry(ino, pos, dp)
-ino_t ino;
-off_t pos;
-dir_struct *dp;
-{
-  if (dp->d_inum < ROOT_INODE || dp->d_inum > sb.s_ninodes) {
-	printf("bad inode found in directory ");
-	printpath(1, 0);
-	printf("ino found = %u, ", dp->d_inum);
-	printf("name = '");
-	printname(dp->d_name);
-	printf("')");
-	if (yes(". remove entry")) {
-		memset((void *) dp, 0, sizeof(dir_struct));
-		return(0);
-	}
-	return(1);
-  }
-  if ((unsigned) count[dp->d_inum] == SHRT_MAX) {
-	printf("too many links to ino %u\n", dp->d_inum);
-	printf("discovered at entry '");
-	printname(dp->d_name);
-	printf("' in directory ");
-	printpath(0, 1);
-	if (Remove(dp)) return(0);
-  }
-  count[dp->d_inum]++;
-  if (strcmp(dp->d_name, ".") == 0) {
-	ftop->st_presence |= DOT;
-	return(chkdots(ino, pos, dp, ino));
-  }
-  if (strcmp(dp->d_name, "..") == 0) {
-	ftop->st_presence |= DOTDOT;
-	return(chkdots(ino, pos, dp, ino == ROOT_INODE ? ino :
-			ftop->st_next->st_dir->d_inum));
-  }
-  if (!chkname(ino, dp)) return(0);
-  if (bitset(dirmap, (bit_nr) dp->d_inum)) {
-	printf("link to directory discovered in ");
-	printpath(1, 0);
-	printf("name = '");
-	printname(dp->d_name);
-	printf("', dir ino = %u)", dp->d_inum);
-	return !Remove(dp);
-  }
-  return(descendtree(dp));
-}
-
-/* Check a zone of a directory by checking all the entries in the zone.
- * The zone is split up into chunks to not allocate too much stack.
- */
-int chkdirzone(ino, ip, pos, zno)
-ino_t ino;
-d_inode *ip;
-off_t pos;
-zone_nr zno;
-{
-  dir_struct dirblk[CDIRECT];
-  register dir_struct *dp;
-  register n, dirty;
-  register long offset = zaddr(zno);
-  register off_t size = 0;
-  n = SCALE * (NR_DIR_ENTRIES(block_size) / CDIRECT);
-
-  do {
-	devread(offset, (char *) dirblk, DIRCHUNK);
-	dirty = 0;
-	for (dp = dirblk; dp < &dirblk[CDIRECT]; dp++) {
-		if (dp->d_inum != NO_ENTRY && !chkentry(ino, pos, dp))
-			dirty = 1;
-		pos += DIR_ENTRY_SIZE;
-		if (dp->d_inum != NO_ENTRY) size = pos;
-	}
-	if (dirty) devwrite(offset, (char *) dirblk, DIRCHUNK);
-	offset += DIRCHUNK;
-	n--;
-  } while (n > 0);
-
-  if (size > ip->i_size) {
-	printf("size not updated of directory ");
-	printpath(2, 0);
-	if (yes(". extend")) {
-		setbit(spec_imap, (bit_nr) ino);
-		ip->i_size = size;
-		devwrite(inoaddr(ino), (char *) ip, INODE_SIZE);
-	}
-  }
-  return(1);
-}
-
-
-int chksymlinkzone(ino, ip, pos, zno)
-ino_t ino;
-d_inode *ip;
-off_t pos;
-zone_nr zno;
-{
-	long offset;
-	size_t len;
-	char target[PATH_MAX+1];
-
-	if (ip->i_size > PATH_MAX)
-		fatal("chksymlinkzone: fsck program inconsistency\n");
-	offset = zaddr(zno);
-	devread(offset, target, ip->i_size);
-	target[ip->i_size]= '\0';
-	len= strlen(target);
-	if (len != ip->i_size)
-	{
-		printf("bad size in symbolic link (%d instead of %d) ",
-			ip->i_size, len);
-		printpath(2, 0);
-		if (yes(". update")) {
-			setbit(spec_imap, (bit_nr) ino);
-			ip->i_size = len;
-			devwrite(inoaddr(ino), (char *) ip, INODE_SIZE);
-		}
-	}
-	return 1;
-}
-
-/* There is something wrong with the given zone.  Print some details. */
-void errzone(mess, zno, level, pos)
-char *mess;
-zone_nr zno;
-int level;
-off_t pos;
-{
-  printf("%s zone in ", mess);
-  printpath(1, 0);
-  printf("zno = %ld, type = ", zno);
-  switch (level) {
-      case 0:	printf("DATA");	break;
-      case 1:	printf("SINGLE INDIRECT");	break;
-      case 2:	printf("DOUBLE INDIRECT");	break;
-      default:	printf("VERY INDIRECT");
-  }
-  printf(", pos = %ld)\n", pos);
-}
-
-/* Found the given zone in the given inode.  Check it, and if ok, mark it
- * in the zone bitmap.
- */
-int markzone(zno, level, pos)
-zone_nr zno;
-int level;
-off_t pos;
-{
-  register bit_nr bit = (bit_nr) zno - FIRST + 1;
-
-  ztype[level]++;
-  if (zno < FIRST || zno >= sb.s_zones) {
-	errzone("out-of-range", zno, level, pos);
-	return(0);
-  }
-  if (bitset(zmap, bit)) {
-	setbit(spec_zmap, bit);
-	errzone("duplicate", zno, level, pos);
-	return(0);
-  }
-  nfreezone--;
-  if (bitset(spec_zmap, bit)) errzone("found", zno, level, pos);
-  setbit(zmap, bit);
-  return(1);
-}
-
-/* Check an indirect zone by checking all of its entries.
- * The zone is split up into chunks to not allocate too much stack.
- */
-int chkindzone(ino, ip, pos, zno, level)
-ino_t ino;
-d_inode *ip;
-off_t *pos;
-zone_nr zno;
-int level;
-{
-  zone_nr indirect[CINDIR];
-  register n = NR_INDIRECTS / CINDIR;
-  register long offset = zaddr(zno);
-
-  do {
-	devread(offset, (char *) indirect, INDCHUNK);
-	if (!chkzones(ino, ip, pos, indirect, CINDIR, level - 1)) return(0);
-	offset += INDCHUNK;
-  } while (--n && *pos < ip->i_size);
-  return(1);
-}
-
-/* Return the size of a gap in the file, represented by a null zone number
- * at some level of indirection.
- */
-off_t jump(level)
-int level;
-{
-  off_t power = ZONE_SIZE;
-
-  if (level != 0) do
-		power *= NR_INDIRECTS;
-	while (--level);
-  return(power);
-}
-
-/* Check a zone, which may be either a normal data zone, a directory zone,
- * or an indirect zone.
- */
-int zonechk(ino, ip, pos, zno, level)
-ino_t ino;
-d_inode *ip;
-off_t *pos;
-zone_nr zno;
-int level;
-{
-  if (level == 0) {
-	if ((ip->i_mode & I_TYPE) == I_DIRECTORY &&
-	    !chkdirzone(ino, ip, *pos, zno))
-		return(0);
-	if ((ip->i_mode & I_TYPE) == I_SYMBOLIC_LINK &&
-	    !chksymlinkzone(ino, ip, *pos, zno))
-		return(0);
-	*pos += ZONE_SIZE;
-	return(1);
-  } else
-	return chkindzone(ino, ip, pos, zno, level);
-}
-
-/* Check a list of zones given by `zlist'. */
-int chkzones(ino, ip, pos, zlist, len, level)
-ino_t ino;
-d_inode *ip;
-off_t *pos;
-zone_nr *zlist;
-int len;
-int level;
-{
-  register ok = 1, i;
-
-  /* The check on the position in the next loop is commented out, since FS
-   * now requires valid zone numbers in each level that is necessary and FS
-   * always deleted all the zones in the double indirect block.
-   */
-  for (i = 0; i < len /* && *pos < ip->i_size */ ; i++)
-	if (zlist[i] == NO_ZONE)
-		*pos += jump(level);
-	else if (!markzone(zlist[i], level, *pos)) {
-		*pos += jump(level);
-		ok = 0;
-	} else if (!zonechk(ino, ip, pos, zlist[i], level))
-		ok = 0;
-  return(ok);
-}
-
-/* Check a file or a directory. */
-int chkfile(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  register ok, i, level;
-  off_t pos = 0;
-
-  ok = chkzones(ino, ip, &pos, &ip->i_zone[0], NR_DZONE_NUM, 0);
-  for (i = NR_DZONE_NUM, level = 1; i < NR_ZONE_NUMS; i++, level++)
-	ok &= chkzones(ino, ip, &pos, &ip->i_zone[i], 1, level);
-  return(ok);
-}
-
-/* Check a directory by checking the contents.  Check if . and .. are present. */
-int chkdirectory(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  register ok;
-
-  setbit(dirmap, (bit_nr) ino);
-  ok = chkfile(ino, ip);
-  if (!(ftop->st_presence & DOT)) {
-	printf(". missing in ");
-	printpath(2, 1);
-	ok = 0;
-  }
-  if (!(ftop->st_presence & DOTDOT)) {
-	printf(".. missing in ");
-	printpath(2, 1);
-	ok = 0;
-  }
-  return(ok);
-}
-
-#ifdef I_SYMBOLIC_LINK
-
-/* Check the validity of a symbolic link. */
-int chklink(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  int ok;
-
-  ok = chkfile(ino, ip);
-  if (ip->i_size <= 0 || ip->i_size > block_size) {
-	if (ip->i_size == 0)
-		printf("empty symbolic link ");
-	else
-		printf("symbolic link too large (size %ld) ", ip->i_size);
-	printpath(2, 1);
-	ok = 0;
-  }
-  return(ok);
-}
-
-#endif
-
-/* Check the validity of a special file. */
-int chkspecial(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  int i, ok;
-
-  ok = 1;
-  if ((dev_t) ip->i_zone[0] == NO_DEV) {
-	printf("illegal device number %ld for special file ", ip->i_zone[0]);
-	printpath(2, 1);
-	ok = 0;
-  }
-
-  /* FS will not use the remaining "zone numbers" but 1.6.11++ will panic if
-   * they are nonzero, since this should not happen.
-   */
-  for (i = 1; i < NR_ZONE_NUMS; i++)
-	if (ip->i_zone[i] != NO_ZONE) {
-		printf("nonzero zone number %ld for special file ",
-		       ip->i_zone[i]);
-		printpath(2, 1);
-		ok = 0;
-	}
-  return(ok);
-}
-
-/* Check the mode and contents of an inode. */
-int chkmode(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  switch (ip->i_mode & I_TYPE) {
-      case I_REGULAR:
-	nregular++;
-	return chkfile(ino, ip);
-      case I_DIRECTORY:
-	ndirectory++;
-	return chkdirectory(ino, ip);
-      case I_BLOCK_SPECIAL:
-	nblkspec++;
-	return chkspecial(ino, ip);
-      case I_CHAR_SPECIAL:
-	ncharspec++;
-	return chkspecial(ino, ip);
-      case I_NAMED_PIPE:
-	npipe++;
-	return chkfile(ino, ip);
-#ifdef I_SYMBOLIC_LINK
-      case I_SYMBOLIC_LINK:
-	nsyml++;
-	return chklink(ino, ip);
-#endif
-      default:
-	nbadinode++;
-	printf("bad mode of ");
-	printpath(1, 0);
-	printf("mode = %o)", ip->i_mode);
-	return(0);
-  }
-}
-
-/* Check an inode. */
-int chkinode(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  if (ino == ROOT_INODE && (ip->i_mode & I_TYPE) != I_DIRECTORY) {
-	printf("root inode is not a directory ");
-	printf("(ino = %u, mode = %o)\n", ino, ip->i_mode);
-	fatal("");
-  }
-  if (ip->i_nlinks == 0) {
-	printf("link count zero of ");
-	printpath(2, 0);
-	return(0);
-  }
-  nfreeinode--;
-  setbit(imap, (bit_nr) ino);
-  if ((unsigned) ip->i_nlinks > SHRT_MAX) {
-	printf("link count too big in ");
-	printpath(1, 0);
-	printf("cnt = %u)\n", (unsigned) ip->i_nlinks);
-	count[ino] -= SHRT_MAX;
-	setbit(spec_imap, (bit_nr) ino);
-  } else {
-	count[ino] -= (unsigned) ip->i_nlinks;
-  }
-  return chkmode(ino, ip);
-}
-
-/* Check the directory entry pointed to by dp, by checking the inode. */
-int descendtree(dp)
-dir_struct *dp;
-{
-  d_inode inode;
-  register ino_t ino = dp->d_inum;
-  register visited;
-  struct stack stk;
-
-  stk.st_dir = dp;
-  stk.st_next = ftop;
-  ftop = &stk;
-  if (bitset(spec_imap, (bit_nr) ino)) {
-	printf("found inode %u: ", ino);
-	printpath(0, 1);
-  }
-  visited = bitset(imap, (bit_nr) ino);
-  if (!visited || listing) {
-	devread(inoaddr(ino), (char *) &inode, INODE_SIZE);
-	if (listing) list(ino, &inode);
-	if (!visited && !chkinode(ino, &inode)) {
-		setbit(spec_imap, (bit_nr) ino);
-		if (yes("remove")) {
-			count[ino] += inode.i_nlinks - 1;
-			clrbit(imap, (bit_nr) ino);
-			devwrite(inoaddr(ino), nullbuf, INODE_SIZE);
-			memset((void *) dp, 0, sizeof(dir_struct));
-			ftop = ftop->st_next;
-			return(0);
-		}
-	}
-  }
-  ftop = ftop->st_next;
-  return(1);
-}
-
-/* Check the file system tree. */
-void chktree()
-{
-  dir_struct dir;
-
-  nfreeinode = sb.s_ninodes;
-  nfreezone = N_DATA;
-  dir.d_inum = ROOT_INODE;
-  dir.d_name[0] = 0;
-  if (!descendtree(&dir)) fatal("bad root inode");
-  putchar('\n');
-}
-
-/* Print the totals of all the objects found. */
-void printtotal()
-{
-  printf("blocksize = %5d        ", block_size);
-  printf("zonesize  = %5d\n", ZONE_SIZE);
-  printf("\n");
-  pr("%8u    Regular file%s\n", nregular, "", "s");
-  pr("%8u    Director%s\n", ndirectory, "y", "ies");
-  pr("%8u    Block special file%s\n", nblkspec, "", "s");
-  pr("%8u    Character special file%s\n", ncharspec, "", "s");
-  if (nbadinode != 0) pr("%6u    Bad inode%s\n", nbadinode, "", "s");
-  pr("%8u    Free inode%s\n", nfreeinode, "", "s");
-  pr("%8u    Named pipe%s\n", npipe, "", "s");
-  pr("%8u    Symbolic link%s\n", nsyml, "", "s");
-/* Don't print some fields.
-  printf("\n");
-  pr("%8u    Data zone%s\n",		  ztype[0],	 "",   "s");
-  pr("%8u    Single indirect zone%s\n",	  ztype[1],	 "",   "s");
-  pr("%8u    Double indirect zone%s\n",	  ztype[2],	 "",   "s");
-*/
-  lpr("%8ld    Free zone%s\n", nfreezone, "", "s");
-}
-
-/* Check the device which name is given by `f'.  The inodes listed by `clist'
- * should be listed separately, and the inodes listed by `ilist' and the zones
- * listed by `zlist' should be watched for while checking the file system.
- */
-
-void chkdev(f, clist, ilist, zlist)
-char *f, **clist, **ilist, **zlist;
-{
-  if (automatic) repair = 1;
-  fsck_device = f;
-  initvars();
-
-  devopen();
-
-  getsuper();
-
-  if(block_size < _MIN_BLOCK_SIZE || block_size > _MAX_BLOCK_SIZE)
-  	fatal("funny block size");
-
-  if(!(rwbuf = malloc(block_size))) fatal("couldn't allocate fs buf (1)");
-  if(!(nullbuf = malloc(block_size))) fatal("couldn't allocate fs buf (2)");
-  memset(nullbuf, 0, block_size);
-
-  chksuper();
-
-  lsi(clist);
-
-  getbitmaps();
-
-  fillbitmap(spec_imap, (bit_nr) 1, (bit_nr) sb.s_ninodes + 1, ilist);
-  fillbitmap(spec_zmap, (bit_nr) FIRST, (bit_nr) sb.s_zones, zlist);
-
-  getcount();
-  chktree();
-  chkmap(zmap, spec_zmap, (bit_nr) FIRST - 1, BLK_ZMAP, N_ZMAP, "zone");
-  chkcount();
-  chkmap(imap, spec_imap, (bit_nr) 0, BLK_IMAP, N_IMAP, "inode");
-  chkilist();
-  printtotal();
-
-  putbitmaps();
-  freecount();
-  devclose();
-
-  if (changed) printf("----- FILE SYSTEM HAS BEEN MODIFIED -----\n\n");
-}
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  register char **clist = 0, **ilist = 0, **zlist = 0;
-
-  register devgiven = 0;
-  register char *arg;
-
-  if ((1 << BITSHIFT) != 8 * sizeof(bitchunk_t)) {
-	printf("Fsck was compiled with the wrong BITSHIFT!\n");
-	exit(1);
-  }
-
-  sync();
-  prog = *argv++;
-  while ((arg = *argv++) != 0)
-	if (arg[0] == '-' && arg[1] != 0 && arg[2] == 0) switch (arg[1]) {
-		    case 'a':	automatic ^= 1;	break;
-		    case 'c':
-			clist = getlist(&argv, "inode");
-			break;
-		    case 'i':
-			ilist = getlist(&argv, "inode");
-			break;
-		    case 'z':
-			zlist = getlist(&argv, "zone");
-			break;
-		    case 'r':	repair ^= 1;	break;
-		    case 'l':	listing ^= 1;	break;
-		    case 's':	listsuper ^= 1;	break;
-		    default:
-			printf("%s: unknown flag '%s'\n", prog, arg);
-		}
-	else {
-		chkdev(arg, clist, ilist, zlist);
-		clist = 0;
-		ilist = 0;
-		zlist = 0;
-		devgiven = 1;
-	}
-  if (!devgiven) {
-	printf("Usage: fsck [-acilrsz] file\n");
-	exit(1);
-  }
-  return(0);
-}
Index: trunk/minix/commands/simple/fsck1.c
===================================================================
--- trunk/minix/commands/simple/fsck1.c	(revision 9)
+++ 	(revision )
@@ -1,1477 +1,0 @@
-/* Hacks for version 1.6 */					
-
-#define INODES_PER_BLOCK V1_INODES_PER_BLOCK
-#define INODE_SIZE V1_INODE_SIZE
-#define WORDS_PER_BLOCK (BLOCK_SIZE / (int) sizeof(bitchunk_t))
-#define MAX_ZONES (V1_NR_DZONES+V1_INDIRECTS+(long)V1_INDIRECTS*V1_INDIRECTS)
-#define NR_DZONE_NUM V1_NR_DZONES
-#define NR_INDIRECTS V1_INDIRECTS
-#define NR_ZONE_NUMS V1_NR_TZONES
-#define ZONE_NUM_SIZE V1_ZONE_NUM_SIZE
-#define bit_nr u16_t	/* perhaps bit_t should be used, although slower */
-#define Bit_nr U16_t
-#define block_nr block_t
-#define d_inode d1_inode
-#define d_inum d_ino
-#define dir_struct struct direct
-#define i_mode d1_mode
-#define i_nlinks d1_nlinks
-#define i_size d1_size
-#define i_zone d1_zone
-#define zone_nr zone1_t
-#define Zone_nr Zone1_t
-
-/* fsck - file system checker		Author: Robbert van Renesse */
-
-/* Modified by Norbert Schlenker
-*   Removed vestiges of standalone/DOS versions:
-*     - various unused variables and buffers removed
-*     - now uses library functions rather than private internal routines
-*     - bytewise structure copies replaced by structure assignment
-*     - fixed one bug with 14 character file names
-*     - other small tweaks for speed
-*
-* Modified by Lars Fredriksen at the request of Andy Tanenbaum, 90-03-10.
-*   Removed -m option, by which fsck could be told to make a file
-*   system on a 360K floppy.  The code had limited utility, was buggy,
-*   and failed due to a bug in the ACK C compiler.  Use mkfs instead!
-*/
-
-#include <sys/types.h>
-#include <sys/dir.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include "../../servers/fs/const.h"
-#include "../../servers/fs/inode.h"
-#include "../../servers/fs/type.h"
-#include <minix/fslib.h>
-#include <stdio.h>
-#include <dirent.h>
-
-#define BLOCK_SIZE _STATIC_BLOCK_SIZE
-
-#define BITSHIFT	  4	/* = log2(#bits(int)) */
-
-#define MAXPRINT	  8	/* max. number of error lines in chkmap */
-#define CINDIR		128	/* number of indirect zno's read at a time */
-#define CDIRECT		 16	/* number of dir entries read at a time */
-#define BITMASK		((1 << BITSHIFT) - 1)
-#define setbit(w, b)	(w[(b) >> BITSHIFT] |= 1 << ((b) & BITMASK))
-#define clrbit(w, b)	(w[(b) >> BITSHIFT] &= ~(1 << ((b) & BITMASK)))
-#define bitset(w, b)	(w[(b) >> BITSHIFT] & (1 << ((b) & BITMASK)))
-
-#define ZONE_CT 	360	/* default zones  (when making file system) */
-#define INODE_CT	 95	/* default inodes (when making file system) */
-
-#include "../../servers/fs/super.h"
-struct super_block sb;
-
-#define STICKY_BIT	01000	/* not defined anywhere else */
-
-/* Ztob gives the block address of a zone
- * btoa gives the byte address of a block
- */
-#define ztob(z)		((block_nr) (z) << sb.s_log_zone_size)
-#define btoa(b)		((long) (b) * BLOCK_SIZE)
-#define SCALE		((int) ztob(1))	/* # blocks in a zone */
-#define FIRST		((zone_nr) sb.s_firstdatazone)	/* as the name says */
-
-/* # blocks of each type */
-#define N_SUPER		1
-#define N_IMAP		(sb.s_imap_blocks)
-#define N_ZMAP		(sb.s_zmap_blocks)
-#define N_ILIST		((sb.s_ninodes+INODES_PER_BLOCK-1) / INODES_PER_BLOCK)
-#define N_DATA		(sb.s_nzones - FIRST)
-
-/* Block address of each type */
-#define BLK_SUPER	(1)
-#define BLK_IMAP	(BLK_SUPER + N_SUPER)
-#define BLK_ZMAP	(BLK_IMAP  + N_IMAP)
-#define BLK_ILIST	(BLK_ZMAP  + N_ZMAP)
-#define BLK_FIRST	ztob(FIRST)
-#define ZONE_SIZE	((int) ztob(BLOCK_SIZE))
-#define NLEVEL		(NR_ZONE_NUMS - NR_DZONE_NUM + 1)
-
-/* Byte address of a zone/of an inode */
-#define zaddr(z)	btoa(ztob(z))
-#define inoaddr(i)	((long) (i - 1) * INODE_SIZE + btoa(BLK_ILIST))
-#define INDCHUNK	(CINDIR * ZONE_NUM_SIZE)
-#define DIRCHUNK	(CDIRECT * DIR_ENTRY_SIZE)
-
-char *prog, *device;		/* program name (fsck), device name */
-int firstcnterr;		/* is this the first inode ref cnt error? */
-bitchunk_t *imap, *spec_imap;	/* inode bit maps */
-bitchunk_t *zmap, *spec_zmap;	/* zone bit maps */
-bitchunk_t *dirmap;		/* directory (inode) bit map */
-char rwbuf[BLOCK_SIZE];		/* one block buffer cache */
-block_nr thisblk;		/* block in buffer cache */
-char nullbuf[BLOCK_SIZE];	/* null buffer */
-nlink_t *count;			/* inode count */
-int changed;			/* has the diskette been written to? */
-struct stack {
-  dir_struct *st_dir;
-  struct stack *st_next;
-  char st_presence;
-} *ftop;
-
-int dev;			/* file descriptor of the device */
-
-#define DOT	1
-#define DOTDOT	2
-
-/* Counters for each type of inode/zone. */
-int nfreeinode, nregular, ndirectory, nblkspec, ncharspec, nbadinode;
-int npipe, nsyml, nfreezone, ztype[NLEVEL];
-
-int repair, automatic, listing, listsuper;	/* flags */
-int firstlist;			/* has the listing header been printed? */
-unsigned part_offset;		/* sector offset for this partition */
-char answer[] = "Answer questions with y or n.  Then hit RETURN";
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void initvars, (void));
-_PROTOTYPE(void fatal, (char *s));
-_PROTOTYPE(int eoln, (int c));
-_PROTOTYPE(int yes, (char *question));
-_PROTOTYPE(int atoo, (char *s));
-_PROTOTYPE(int input, (char *buf, int size));
-_PROTOTYPE(char *alloc, (unsigned nelem, unsigned elsize));
-_PROTOTYPE(void printname, (char *s));
-_PROTOTYPE(void printrec, (struct stack *sp));
-_PROTOTYPE(void printpath, (int mode, int nlcr));
-_PROTOTYPE(void devopen, (void));
-_PROTOTYPE(void devclose, (void));
-_PROTOTYPE(void devio, (block_nr bno, int dir));
-_PROTOTYPE(void devread, (long offset, char *buf, int size));
-_PROTOTYPE(void devwrite, (long offset, char *buf, int size));
-_PROTOTYPE(void pr, (char *fmt, int cnt, char *s, char *p));
-_PROTOTYPE(bit_nr getnumber, (char *s));
-_PROTOTYPE(char **getlist, (char ***argv, char *type));
-_PROTOTYPE(void lsuper, (void));
-_PROTOTYPE(void getsuper, (void));
-_PROTOTYPE(void chksuper, (void));
-_PROTOTYPE(void lsi, (char **clist));
-_PROTOTYPE(bitchunk_t *allocbitmap, (int nblk));
-_PROTOTYPE(void loadbitmap, (bitchunk_t *bitmap, block_nr bno, int nblk));
-_PROTOTYPE(void dumpbitmap, (bitchunk_t *bitmap, block_nr bno, int nblk));
-_PROTOTYPE(void fillbitmap, (bitchunk_t *bitmap, Bit_nr lwb, Bit_nr upb, char **list));
-_PROTOTYPE(void freebitmap, (bitchunk_t *p));
-_PROTOTYPE(void getbitmaps, (void));
-_PROTOTYPE(void putbitmaps, (void));
-_PROTOTYPE(void chkword, (unsigned w1, unsigned w2, Bit_nr bit, char *type, int *n, int *report));
-_PROTOTYPE(void chkmap, (bitchunk_t *cmap, bitchunk_t *dmap, Bit_nr bit, block_nr blkno, int nblk, char *type));
-_PROTOTYPE(void chkilist, (void));
-_PROTOTYPE(void getcount, (void));
-_PROTOTYPE(void counterror, (Ino_t ino));
-_PROTOTYPE(void chkcount, (void));
-_PROTOTYPE(void freecount, (void));
-_PROTOTYPE(void printperm, (mode_t mode, int shift, int special, int overlay));
-_PROTOTYPE(void list, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int Remove, (dir_struct *dp));
-_PROTOTYPE(void make_printable_name, (char *dst, char *src, int n));
-_PROTOTYPE(int chkdots, (Ino_t ino, off_t pos, dir_struct *dp, Ino_t exp));
-_PROTOTYPE(int chkname, (Ino_t ino, dir_struct *dp));
-_PROTOTYPE(int chkentry, (Ino_t ino, off_t pos, dir_struct *dp));
-_PROTOTYPE(int chkdirzone, (Ino_t ino, d_inode *ip, off_t pos, Zone_nr zno));
-_PROTOTYPE(void errzone, (char *mess, Zone_nr zno, int level, off_t pos));
-_PROTOTYPE(int markzone, (Ino_t ino, Zone_nr zno, int level, off_t pos));
-_PROTOTYPE(int chkindzone, (Ino_t ino, d_inode *ip, off_t *pos, Zone_nr zno, int level));
-_PROTOTYPE(off_t jump, (int level));
-_PROTOTYPE(int zonechk, (Ino_t ino, d_inode *ip, off_t *pos, Zone_nr zno, int level));
-_PROTOTYPE(int chkzones, (Ino_t ino, d_inode *ip, off_t *pos, zone_nr *zlist, int len, int level));
-_PROTOTYPE(int chkfile, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chkdirectory, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chklink, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chkmode, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chkinode, (Ino_t ino, d_inode *ip));
-_PROTOTYPE(int chkspecial, (Ino_t ino, d_inode *ip) );
-_PROTOTYPE(int descendtree, (dir_struct *dp));
-_PROTOTYPE(void chktree, (void));
-_PROTOTYPE(void printtotal, (void));
-_PROTOTYPE(void chkdev, (char *f, char **clist, char **ilist, char **zlist));
-
-/* Initialize the variables used by this program. */
-void initvars()
-{
-  register level;
-
-  nregular = ndirectory = nblkspec = ncharspec = nbadinode = npipe = nsyml = 0;
-  for (level = 0; level < NLEVEL; level++) ztype[level] = 0;
-  changed = 0;
-  thisblk = NO_BLOCK;
-  firstlist = 1;
-  firstcnterr = 1;
-}
-
-/* Print the string `s' and exit. */
-void fatal(s)
-char *s;
-{
-  printf("%s\nfatal\n", s);
-  exit(-1);
-}
-
-/* Test for end of line. */
-int eoln(c)
-int c;
-{
-  return(c == EOF || c == '\n' || c == '\r');
-}
-
-/* Ask a question and get the answer unless automatic is set. */
-int yes(question)
-char *question;
-{
-  register c, answer;
-
-  if (!repair) {
-	printf("\n");
-	return(0);
-  }
-  printf("%s? ", question);
-  if (automatic) {
-	printf("yes\n");
-	return(1);
-  }
-  fflush(stdout);
-  if ((c = answer = getchar()) == 'q' || c == 'Q') exit(1);
-  while (!eoln(c)) c = getchar();
-  return !(answer == 'n' || answer == 'N');
-}
-
-/* Convert string to integer.  Representation is octal. */
-int atoo(s)
-register char *s;
-{
-  register int n = 0;
-
-  while ('0' <= *s && *s < '8') {
-	n <<= 3;
-	n += *s++ - '0';
-  }
-  return n;
-}
-
-/* If repairing the file system, print a prompt and get a string from user. */
-int input(buf, size)
-char *buf;
-int size;
-{
-  register char *p = buf;
-
-  printf("\n");
-  if (repair) {
-	printf("--> ");
-	fflush(stdout);
-	while (--size) {
-		*p = getchar();
-		if (eoln(*p)) {
-			*p = 0;
-			return(p > buf);
-		}
-		p++;
-	}
-	*p = 0;
-	while (!eoln(getchar()));
-	return(1);
-  }
-  return(0);
-}
-
-/* Allocate some memory and zero it. */
-char *alloc(nelem, elsize)
-unsigned nelem, elsize;
-{
-  char *p;
-
-  if ((p = (char *) malloc((size_t)nelem * elsize)) == 0) fatal("out of memory");
-  memset(p, 0, (size_t)nelem * elsize);
-  return(p);
-}
-
-/* Print the name in a directory entry. */
-void printname(s)
-char *s;
-{
-  register n = NAME_MAX;
-  int c;
-
-  do {
-	if ((c = *s) == 0) break;
-	if (!isprint(c)) c = '?';
-	putchar(c);
-	s++;
-  } while (--n);
-}
-
-/* Print the pathname given by a linked list pointed to by `sp'.  The
- * names are in reverse order.
- */
-void printrec(sp)
-struct stack *sp;
-{
-  if (sp->st_next != 0) {
-	printrec(sp->st_next);
-	putchar('/');
-	printname(sp->st_dir->d_name);
-  }
-}
-
-/* Print the current pathname.  */
-void printpath(mode, nlcr)
-int mode;
-int nlcr;
-{
-  if (ftop->st_next == 0)
-	putchar('/');
-  else
-	printrec(ftop);
-  switch (mode) {
-      case 1:
-	printf(" (ino = %u, ", ftop->st_dir->d_inum);
-	break;
-      case 2:
-	printf(" (ino = %u)", ftop->st_dir->d_inum);
-	break;
-  }
-  if (nlcr) printf("\n");
-}
-
-/* Open the device.  */
-void devopen()
-{
-  if ((dev = open(device, repair ? O_RDWR : O_RDONLY)) < 0) {
-	perror(device);
-	fatal("");
-  }
-}
-
-/* Close the device. */
-void devclose()
-{
-  if (close(dev) != 0) {
-	perror("close");
-	fatal("");
-  }
-}
-
-/* Read or write a block. */
-void devio(bno, dir)
-block_nr bno;
-int dir;
-{
-  if (dir == READING && bno == thisblk) return;
-  thisblk = bno;
-
-  lseek(dev, (off_t) btoa(bno), SEEK_SET);
-  if (dir == READING) {
-	if (read(dev, rwbuf, BLOCK_SIZE) == BLOCK_SIZE)
-		return;
-  } else {
-	if (write(dev, rwbuf, BLOCK_SIZE) == BLOCK_SIZE)
-		return;
-  }
-
-  printf("%s: can't %s block %ld (error = 0x%x)\n", prog,
-         dir == READING ? "read" : "write", (long) bno, errno);
-  if (dir == READING) {
-	printf("Continuing with a zero-filled block.\n");
-	memset(rwbuf, 0, BLOCK_SIZE);
-	return;
-  }
-  fatal("");
-}
-
-/* Read `size' bytes from the disk starting at byte `offset'. */
-void devread(offset, buf, size)
-long offset;
-char *buf;
-int size;
-{
-  devio((block_nr) (offset / BLOCK_SIZE), READING);
-  memmove(buf, &rwbuf[(int) (offset % BLOCK_SIZE)], (size_t)size);
-}
-
-/* Write `size' bytes to the disk starting at byte `offset'. */
-void devwrite(offset, buf, size)
-long offset;
-char *buf;
-int size;
-{
-  if (!repair) fatal("internal error (devwrite)");
-  if (size != BLOCK_SIZE) devio((block_nr) (offset / BLOCK_SIZE), READING);
-  memmove(&rwbuf[(int) (offset % BLOCK_SIZE)], buf, (size_t)size);
-  devio((block_nr) (offset / BLOCK_SIZE), WRITING);
-  changed = 1;
-}
-
-/* Print a string with either a singular or a plural pronoun. */
-void pr(fmt, cnt, s, p)
-char *fmt, *s, *p;
-int cnt;
-{
-  printf(fmt, cnt, cnt == 1 ? s : p);
-}
-
-/* Convert string to number. */
-bit_nr getnumber(s)
-register char *s;
-{
-  register bit_nr n = 0;
-
-  if (s == NULL)
-	return NO_BIT;
-  while (isdigit(*s))
-	n = (n << 1) + (n << 3) + *s++ - '0';
-  return (*s == '\0') ? n : NO_BIT;
-}
-
-/* See if the list pointed to by `argv' contains numbers. */
-char **getlist(argv, type)
-char ***argv, *type;
-{
-  register char **list = *argv;
-  register empty = 1;
-
-  while (getnumber(**argv) != NO_BIT) {
-	(*argv)++;
-	empty = 0;
-  }
-  if (empty) {
-	printf("warning: no %s numbers given\n", type);
-	return(NULL);
-  }
-  return(list);
-}
-
-/* Make a listing of the super block.  If `repair' is set, ask the user
- * for changes.
- */
-void lsuper()
-{
-  char buf[80];
-
-  do {
-	printf("ninodes       = %u", sb.s_ninodes);
-	if (input(buf, 80)) sb.s_ninodes = atol(buf);
-	printf("nzones        = %u", sb.s_nzones);
-	if (input(buf, 80)) sb.s_nzones = atol(buf);
-	printf("imap_blocks   = %u", sb.s_imap_blocks);
-	if (input(buf, 80)) sb.s_imap_blocks = atol(buf);
-	printf("zmap_blocks   = %u", sb.s_zmap_blocks);
-	if (input(buf, 80)) sb.s_zmap_blocks = atol(buf);
-	printf("firstdatazone = %u", sb.s_firstdatazone);
-	if (input(buf, 80)) sb.s_firstdatazone = atol(buf);
-	printf("log_zone_size = %u", sb.s_log_zone_size);
-	if (input(buf, 80)) sb.s_log_zone_size = atol(buf);
-	printf("maxsize       = %lu", sb.s_max_size);
-	if (input(buf, 80)) sb.s_max_size = atol(buf);
-	if (yes("ok now")) {
-		devwrite(btoa(BLK_SUPER), (char *) &sb, sizeof(sb));
-		return;
-	}
-  } while (yes("Do you want to try again"));
-  if (repair) exit(0);
-}
-
-/* Get the super block from either disk or user.  Do some initial checks. */
-void getsuper()
-{
-  devread(btoa(BLK_SUPER), (char *) &sb, sizeof(sb));
-  if (listsuper) lsuper();
-  if (sb.s_magic == SUPER_V2) fatal("Cannot handle V2 file systems");
-  if (sb.s_magic != SUPER_MAGIC) fatal("bad magic number in super block");
-  if ((short) sb.s_ninodes <= 0) fatal("no inodes");
-  if (sb.s_nzones <= 2) fatal("no zones");
-  if ((short) sb.s_imap_blocks <= 0) fatal("no imap");
-  if ((short) sb.s_zmap_blocks <= 0) fatal("no zmap");
-  if ((short) sb.s_firstdatazone <= 1) fatal("first data zone too small");
-  if ((short) sb.s_log_zone_size < 0) fatal("zone size < block size");
-  if (sb.s_max_size <= 0) fatal("max. file size <= 0");
-}
-
-/* Check the super block for reasonable contents. */
-void chksuper()
-{
-  register n;
-  register off_t maxsize;
-
-  n = bitmapsize((bit_t) sb.s_ninodes + 1, BLOCK_SIZE);
-  if (sb.s_magic != SUPER_MAGIC) fatal("bad magic number in super block");
-  if ((short) sb.s_imap_blocks < n) fatal("too few imap blocks");
-  if (sb.s_imap_blocks != n) {
-	pr("warning: expected %d imap_block%s", n, "", "s");
-	printf(" instead of %d\n", sb.s_imap_blocks);
-  }
-  n = bitmapsize((bit_t) sb.s_nzones, BLOCK_SIZE);
-  if ((short) sb.s_zmap_blocks < n) fatal("too few zmap blocks");
-  if (sb.s_zmap_blocks != n) {
-	pr("warning: expected %d zmap_block%s", n, "", "s");
-	printf(" instead of %d\n", sb.s_zmap_blocks);
-  }
-  if (sb.s_firstdatazone >= sb.s_nzones)
-	fatal("first data zone too large");
-  if ((unsigned short) sb.s_log_zone_size >= 8 * sizeof(block_nr))
-	fatal("log_zone_size too large");
-  if (sb.s_log_zone_size > 8) printf("warning: large log_zone_size (%d)\n",
-	       sb.s_log_zone_size);
-  n = (BLK_ILIST + N_ILIST + SCALE - 1) >> sb.s_log_zone_size;
-  if ((short) sb.s_firstdatazone < n) fatal("first data zone too small");
-  if (sb.s_firstdatazone != n) {
-	printf("warning: expected first data zone to be %d ", n);
-	printf("instead of %u\n", sb.s_firstdatazone);
-  }
-  maxsize = MAX_FILE_POS;
-  if (((maxsize - 1) >> sb.s_log_zone_size) / BLOCK_SIZE >= MAX_ZONES)
-	maxsize = ((long) MAX_ZONES * BLOCK_SIZE) << sb.s_log_zone_size;
-  if (sb.s_max_size != maxsize) {
-	printf("warning: expected max size to be %ld ", maxsize);
-	printf("instead of %ld\n", sb.s_max_size);
-  }
-}
-
-/* Make a listing of the inodes given by `clist'.  If `repair' is set, ask
- * the user for changes.
- */
-void lsi(clist)
-char **clist;
-{
-  register bit_nr bit;
-  register ino_t ino;
-  d_inode inode, *ip = &inode;
-  char buf[80];
-
-  if (clist == 0) return;
-  while ((bit = getnumber(*clist++)) != NO_BIT) {
-	setbit(spec_imap, bit);
-	ino = bit;
-	do {
-		devread(inoaddr(ino), (char *) ip, INODE_SIZE);
-		printf("inode %u:\n", ino);
-		printf("    mode   = %06o", ip->i_mode);
-		if (input(buf, 80)) ip->i_mode = atoo(buf);
-		printf("    nlinks = %6u", ip->i_nlinks);
-		if (input(buf, 80)) ip->i_nlinks = atol(buf);
-		printf("    size   = %6ld", ip->i_size);
-		if (input(buf, 80)) ip->i_size = atol(buf);
-		if (yes("Write this back")) {
-			devwrite(inoaddr(ino), (char *) ip, INODE_SIZE);
-			break;
-		}
-	} while (yes("Do you want to change it again"));
-  }
-}
-
-/* Allocate `nblk' blocks worth of bitmap. */
-bitchunk_t *allocbitmap(nblk)
-int nblk;
-{
-  register bitchunk_t *bitmap;
-
-  bitmap = (bitchunk_t *) alloc(nblk, BLOCK_SIZE);
-  *bitmap |= 1;
-  return(bitmap);
-}
-
-/* Load the bitmap starting at block `bno' from disk. */
-void loadbitmap(bitmap, bno, nblk)
-bitchunk_t *bitmap;
-block_nr bno;
-int nblk;
-{
-  register i;
-  register bitchunk_t *p;
-
-  p = bitmap;
-  for (i = 0; i < nblk; i++, bno++, p += WORDS_PER_BLOCK)
-	devread(btoa(bno), (char *) p, BLOCK_SIZE);
-  *bitmap |= 1;
-}
-
-/* Write the bitmap starting at block `bno' to disk. */
-void dumpbitmap(bitmap, bno, nblk)
-bitchunk_t *bitmap;
-block_nr bno;
-int nblk;
-{
-  register i;
-  register bitchunk_t *p = bitmap;
-
-  for (i = 0; i < nblk; i++, bno++, p += WORDS_PER_BLOCK)
-	devwrite(btoa(bno), (char *) p, BLOCK_SIZE);
-}
-
-/* Set the bits given by `list' in the bitmap. */
-void fillbitmap(bitmap, lwb, upb, list)
-bitchunk_t *bitmap;
-bit_nr lwb, upb;
-char **list;
-{
-  register bit_nr bit;
-
-  if (list == 0) return;
-  while ((bit = getnumber(*list++)) != NO_BIT)
-	if (bit < lwb || bit >= upb) {
-		if (bitmap == spec_imap)
-			printf("inode number %u ", bit);
-		else
-			printf("zone number %u ", bit);
-		printf("out of range (ignored)\n");
-	} else
-		setbit(bitmap, bit - lwb + 1);
-}
-
-/* Deallocate the bitmap `p'. */
-void freebitmap(p)
-bitchunk_t *p;
-{
-  free((char *) p);
-}
-
-/* Get all the bitmaps used by this program. */
-void getbitmaps()
-{
-  imap = allocbitmap(N_IMAP);
-  zmap = allocbitmap(N_ZMAP);
-  spec_imap = allocbitmap(N_IMAP);
-  spec_zmap = allocbitmap(N_ZMAP);
-  dirmap = allocbitmap(N_IMAP);
-}
-
-/* Release all the space taken by the bitmaps. */
-void putbitmaps()
-{
-  freebitmap(imap);
-  freebitmap(zmap);
-  freebitmap(spec_imap);
-  freebitmap(spec_zmap);
-  freebitmap(dirmap);
-}
-
-/* `w1' and `w2' are differing words from two bitmaps that should be
- * identical.  Print what's the matter with them.
- */
-void chkword(w1, w2, bit, type, n, report)
-unsigned w1, w2;
-char *type;
-bit_nr bit;
-int *n, *report;
-{
-  for (; (w1 | w2); w1 >>= 1, w2 >>= 1, bit++)
-	if ((w1 ^ w2) & 1 && ++(*n) % MAXPRINT == 0 && *report &&
-	    (!repair || automatic || yes("stop this listing")))
-		*report = 0;
-	else if (*report)
-		if ((w1 & 1) && !(w2 & 1))
-			printf("%s %u is missing\n", type, bit);
-		else if (!(w1 & 1) && (w2 & 1))
-			printf("%s %u is not free\n", type, bit);
-}
-
-/* Check if the given (correct) bitmap is identical with the one that is
- * on the disk.  If not, ask if the disk should be repaired.
- */
-void chkmap(cmap, dmap, bit, blkno, nblk, type)
-bitchunk_t *cmap, *dmap;
-bit_nr bit;
-block_nr blkno;
-int nblk;
-char *type;
-{
-  register bitchunk_t *p = dmap, *q = cmap;
-  int report = 1, nerr = 0;
-  int w = nblk * WORDS_PER_BLOCK;
-
-  printf("Checking %s map\n", type);
-  loadbitmap(dmap, blkno, nblk);
-  do {
-	if (*p != *q) chkword(*p, *q, bit, type, &nerr, &report);
-	p++;
-	q++;
-	bit += 8 * sizeof(bitchunk_t);
-  } while (--w > 0);
-
-  if ((!repair || automatic) && !report) printf("etc. ");
-  if (nerr > MAXPRINT || nerr > 10) printf("%d errors found. ", nerr);
-  if (nerr != 0 && yes("install a new map")) dumpbitmap(cmap, blkno, nblk);
-  if (nerr > 0) printf("\n");
-}
-
-/* See if the inodes that aren't allocated are cleared. */
-void chkilist()
-{
-  register ino_t ino = 1;
-  mode_t mode;
-
-  printf("Checking inode list\n");
-  do
-	if (!bitset(imap, (bit_nr) ino)) {
-		devread(inoaddr(ino), (char *) &mode, sizeof(mode));
-		if (mode != I_NOT_ALLOC) {
-			printf("mode inode %u not cleared", ino);
-			if (yes(". clear")) devwrite(inoaddr(ino), nullbuf,
-					 INODE_SIZE);
-		}
-	}
-  while (++ino <= sb.s_ninodes);
-  printf("\n");
-}
-
-/* Allocate an array to maintain the inode reference counts in. */
-void getcount()
-{
-  count = (nlink_t *) alloc(sb.s_ninodes + 1, sizeof(nlink_t));
-}
-
-/* The reference count for inode `ino' is wrong.  Ask if it should be adjusted. */
-void counterror(ino)
-ino_t ino;
-{
-  d_inode inode;
-
-  if (firstcnterr) {
-	printf("INODE NLINK COUNT\n");
-	firstcnterr = 0;
-  }
-  devread(inoaddr(ino), (char *) &inode, INODE_SIZE);
-  count[ino] += inode.i_nlinks;
-  printf("%5u %5u %5u", ino, (unsigned) inode.i_nlinks, count[ino]);
-  if (yes(" adjust")) {
-	if ((inode.i_nlinks = count[ino]) == 0) {
-		fatal("internal error (counterror)");
-/* This would be a patch
-		inode.i_mode = I_NOT_ALLOC;
-		clrbit(imap, (bit_nr) ino);
-*/
-	}
-	devwrite(inoaddr(ino), (char *) &inode, INODE_SIZE);
-  }
-}
-
-/* Check if the reference count of the inodes are correct.  The array `count'
- * is maintained as follows:  an entry indexed by the inode number is
- * incremented each time a link is found; when the inode is read the link
- * count in there is substracted from the corresponding entry in `count'.
- * Thus, when the whole file system has been traversed, all the entries
- * should be zero.
- */
-void chkcount()
-{
-  register ino_t ino;
-
-  for (ino = 1; ino <= sb.s_ninodes; ino++)
-	if (count[ino] != 0) counterror(ino);
-  if (!firstcnterr) printf("\n");
-}
-
-/* Deallocate the `count' array. */
-void freecount()
-{
-  free((char *) count);
-}
-
-/* Print the inode permission bits given by mode and shift. */
-void printperm(mode_t mode, int shift, int special, int overlay)
-{
-  if (mode >> shift & R_BIT)
-	putchar('r');
-  else
-	putchar('-');
-  if (mode >> shift & W_BIT)
-	putchar('w');
-  else
-	putchar('-');
-  if (mode & special)
-	putchar(overlay);
-  else
-	if (mode >> shift & X_BIT)
-		putchar('x');
-	else
-		putchar('-');
-}
-
-/* List the given inode. */
-void list(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  if (firstlist) {
-	firstlist = 0;
-	printf(" inode permission link   size name\n");
-  }
-  printf("%6u ", ino);
-  switch (ip->i_mode & I_TYPE) {
-      case I_REGULAR:		putchar('-');	break;
-      case I_DIRECTORY:		putchar('d');	break;
-      case I_CHAR_SPECIAL:	putchar('c');	break;
-      case I_BLOCK_SPECIAL:	putchar('b');	break;
-      case I_NAMED_PIPE:	putchar('p');	break;
-#ifdef I_SYMBOLIC_LINK
-      case I_SYMBOLIC_LINK:	putchar('l');	break;
-#endif
-      default:			putchar('?');
-}
-  printperm(ip->i_mode, 6, I_SET_UID_BIT, 's');
-  printperm(ip->i_mode, 3, I_SET_GID_BIT, 's');
-  printperm(ip->i_mode, 0, STICKY_BIT, 't');
-  printf(" %3u ", ip->i_nlinks);
-  switch (ip->i_mode & I_TYPE) {
-      case I_CHAR_SPECIAL:
-      case I_BLOCK_SPECIAL:
-	printf("  %2x,%2x ", (dev_t) ip->i_zone[0] >> MAJOR & 0xFF,
-	       (dev_t) ip->i_zone[0] >> MINOR & 0xFF);
-	break;
-      default:	printf("%7ld ", ip->i_size);
-  }
-  printpath(0, 1);
-}
-
-/* Remove an entry from a directory if ok with the user.
- * Don't name the function remove() - that is owned by ANSI, and chaos results
- * when it is a macro.
- */
-int Remove(dp)
-dir_struct *dp;
-{
-  setbit(spec_imap, (bit_nr) dp->d_inum);
-  if (yes(". remove entry")) {
-	count[dp->d_inum]--;
-	memset((void *) dp, 0, sizeof(dir_struct));
-	return(1);
-  }
-  return(0);
-}
-
-/* Convert string so that embedded control characters are printable. */
-void make_printable_name(dst, src, n)
-register char *dst;
-register char *src;
-register int n;
-{
-  register int c;
-
-  while (--n >= 0 && (c = *src++) != '\0') {
-	if (isprint(c) && c != '\\')
-		*dst++ = c;
-	else {
-		*dst++ = '\\';
-		switch (c) {
-		      case '\\':
-			*dst++ = '\\'; break;
-		      case '\b':
-			*dst++ = 'b'; break;
-		      case '\f':
-			*dst++ = 'f'; break;
-		      case '\n':
-			*dst++ = 'n'; break;
-		      case '\r':
-			*dst++ = 'r'; break;
-		      case '\t':
-			*dst++ = 't'; break;
-		      default:
-			*dst++ = '0' + ((c >> 6) & 03);
-			*dst++ = '0' + ((c >> 3) & 07);
-			*dst++ = '0' + (c & 07);
-		}
-	}
-  }
-  *dst = '\0';
-}
-
-/* See if the `.' or `..' entry is as expected. */
-int chkdots(ino, pos, dp, exp)
-ino_t ino, exp;
-off_t pos;
-dir_struct *dp;
-{
-  char printable_name[4 * NAME_MAX + 1];
-
-  if (dp->d_inum != exp) {
-	make_printable_name(printable_name, dp->d_name, sizeof(dp->d_name));
-	printf("bad %s in ", printable_name);
-	printpath(1, 0);
-	printf("%s is linked to %u ", printable_name, dp->d_inum);
-	printf("instead of %u)", exp);
-	setbit(spec_imap, (bit_nr) ino);
-	setbit(spec_imap, (bit_nr) dp->d_inum);
-	setbit(spec_imap, (bit_nr) exp);
-	if (yes(". repair")) {
-		count[dp->d_inum]--;
-		dp->d_inum = exp;
-		count[exp]++;
-		return(0);
-	}
-  } else if (pos != (dp->d_name[1] ? DIR_ENTRY_SIZE : 0)) {
-	make_printable_name(printable_name, dp->d_name, sizeof(dp->d_name));
-	printf("warning: %s has offset %ld in ", printable_name, pos);
-	printpath(1, 0);
-	printf("%s is linked to %u)\n", printable_name, dp->d_inum);
-	setbit(spec_imap, (bit_nr) ino);
-	setbit(spec_imap, (bit_nr) dp->d_inum);
-	setbit(spec_imap, (bit_nr) exp);
-  }
-  return(1);
-}
-
-/* Check the name in a directory entry. */
-int chkname(ino, dp)
-ino_t ino;
-dir_struct *dp;
-{
-  register n = NAME_MAX + 1;
-  register char *p = dp->d_name;
-
-  if (*p == '\0') {
-	printf("null name found in ");
-	printpath(0, 0);
-	setbit(spec_imap, (bit_nr) ino);
-	if (Remove(dp)) return(0);
-  }
-  while (*p != '\0' && --n != 0)
-	if (*p++ == '/') {
-		printf("found a '/' in entry of directory ");
-		printpath(1, 0);
-		setbit(spec_imap, (bit_nr) ino);
-		printf("entry = '");
-		printname(dp->d_name);
-		printf("')");
-		if (Remove(dp)) return(0);
-		break;
-	}
-  return(1);
-}
-
-/* Check a directory entry.  Here the routine `descendtree' is called
- * recursively to check the file or directory pointed to by the entry.
- */
-int chkentry(ino, pos, dp)
-ino_t ino;
-off_t pos;
-dir_struct *dp;
-{
-  if (dp->d_inum < ROOT_INODE || dp->d_inum > sb.s_ninodes) {
-	printf("bad inode found in directory ");
-	printpath(1, 0);
-	printf("ino found = %u, ", dp->d_inum);
-	printf("name = '");
-	printname(dp->d_name);
-	printf("')");
-	if (yes(". remove entry")) {
-		memset((void *) dp, 0, sizeof(dir_struct));
-		return(0);
-	}
-	return(1);
-  }
-  if ((unsigned) count[dp->d_inum] == CHAR_MAX) {
-	printf("too many links to ino %u\n", dp->d_inum);
-	printf("discovered at entry '");
-	printname(dp->d_name);
-	printf("' in directory ");
-	printpath(0, 1);
-	if (Remove(dp)) return(0);
-  }
-  count[dp->d_inum]++;
-  if (strcmp(dp->d_name, ".") == 0) {
-	ftop->st_presence |= DOT;
-	return(chkdots(ino, pos, dp, ino));
-  }
-  if (strcmp(dp->d_name, "..") == 0) {
-	ftop->st_presence |= DOTDOT;
-	return(chkdots(ino, pos, dp, ino == ROOT_INODE ? ino :
-			ftop->st_next->st_dir->d_inum));
-  }
-  if (!chkname(ino, dp)) return(0);
-  if (bitset(dirmap, (bit_nr) dp->d_inum)) {
-	printf("link to directory discovered in ");
-	printpath(1, 0);
-	printf("name = '");
-	printname(dp->d_name);
-	printf("', dir ino = %u)", dp->d_inum);
-	return !Remove(dp);
-  }
-  return(descendtree(dp));
-}
-
-/* Check a zone of a directory by checking all the entries in the zone.
- * The zone is split up into chunks to not allocate too much stack.
- */
-int chkdirzone(ino, ip, pos, zno)
-ino_t ino;
-d_inode *ip;
-off_t pos;
-zone_nr zno;
-{
-  dir_struct dirblk[CDIRECT];
-  register dir_struct *dp;
-  register n = SCALE * (NR_DIR_ENTRIES(BLOCK_SIZE) / CDIRECT), dirty;
-  register long offset = zaddr(zno);
-  register off_t size = 0;
-
-  do {
-	devread(offset, (char *) dirblk, DIRCHUNK);
-	dirty = 0;
-	for (dp = dirblk; dp < &dirblk[CDIRECT]; dp++) {
-		if (dp->d_inum != NO_ENTRY && !chkentry(ino, pos, dp))
-			dirty = 1;
-		pos += DIR_ENTRY_SIZE;
-		if (dp->d_inum != NO_ENTRY) size = pos;
-	}
-	if (dirty) devwrite(offset, (char *) dirblk, DIRCHUNK);
-	offset += DIRCHUNK;
-  } while (--n);
-
-  if (size > ip->i_size) {
-	printf("size not updated of directory ");
-	printpath(2, 0);
-	if (yes(". extend")) {
-		setbit(spec_imap, (bit_nr) ino);
-		ip->i_size = size;
-		devwrite(inoaddr(ino), (char *) ip, INODE_SIZE);
-	}
-  }
-  return(1);
-}
-
-/* There is something wrong with the given zone.  Print some details. */
-void errzone(mess, zno, level, pos)
-char *mess;
-zone_nr zno;
-int level;
-off_t pos;
-{
-  printf("%s zone in ", mess);
-  printpath(1, 0);
-  printf("zno = %u, type = ", zno);
-  switch (level) {
-      case 0:	printf("DATA");	break;
-      case 1:	printf("SINGLE INDIRECT");	break;
-      case 2:	printf("DOUBLE INDIRECT");	break;
-      default:	printf("VERY INDIRECT");
-  }
-  printf(", pos = %ld)\n", pos);
-}
-
-/* Found the given zone in the given inode.  Check it, and if ok, mark it
- * in the zone bitmap.
- */
-int markzone(ino, zno, level, pos)
-ino_t ino;
-zone_nr zno;
-int level;
-off_t pos;
-{
-  register bit_nr bit = (bit_nr) zno - FIRST + 1;
-
-  ztype[level]++;
-  if (zno < FIRST || zno >= sb.s_nzones) {
-	errzone("out-of-range", zno, level, pos);
-	return(0);
-  }
-  if (bitset(zmap, bit)) {
-	setbit(spec_zmap, bit);
-	errzone("duplicate", zno, level, pos);
-	return(0);
-  }
-  nfreezone--;
-  if (bitset(spec_zmap, bit)) errzone("found", zno, level, pos);
-  setbit(zmap, bit);
-  return(1);
-}
-
-/* Check an indirect zone by checking all of its entries.
- * The zone is split up into chunks to not allocate too much stack.
- */
-int chkindzone(ino, ip, pos, zno, level)
-ino_t ino;
-d_inode *ip;
-off_t *pos;
-zone_nr zno;
-int level;
-{
-  zone_nr indirect[CINDIR];
-  register n = NR_INDIRECTS / CINDIR;
-  register long offset = zaddr(zno);
-
-  do {
-	devread(offset, (char *) indirect, INDCHUNK);
-	if (!chkzones(ino, ip, pos, indirect, CINDIR, level - 1)) return(0);
-	offset += INDCHUNK;
-  } while (--n && *pos < ip->i_size);
-  return(1);
-}
-
-/* Return the size of a gap in the file, represented by a null zone number
- * at some level of indirection.
- */
-off_t jump(level)
-int level;
-{
-  off_t power = ZONE_SIZE;
-
-  if (level != 0) do
-		power *= NR_INDIRECTS;
-	while (--level);
-  return(power);
-}
-
-/* Check a zone, which may be either a normal data zone, a directory zone,
- * or an indirect zone.
- */
-int zonechk(ino, ip, pos, zno, level)
-ino_t ino;
-d_inode *ip;
-off_t *pos;
-zone_nr zno;
-int level;
-{
-  if (level == 0) {
-	if ((ip->i_mode & I_TYPE) == I_DIRECTORY &&
-	    !chkdirzone(ino, ip, *pos, zno))
-		return(0);
-	*pos += ZONE_SIZE;
-	return(1);
-  } else
-	return chkindzone(ino, ip, pos, zno, level);
-}
-
-/* Check a list of zones given by `zlist'. */
-int chkzones(ino, ip, pos, zlist, len, level)
-ino_t ino;
-d_inode *ip;
-off_t *pos;
-zone_nr *zlist;
-int len;
-int level;
-{
-  register ok = 1, i;
-
-  /* The check on the position in the next loop is commented out, since FS
-   * now requires valid zone numbers in each level that is necessary and FS
-   * always deleted all the zones in the double indirect block.
-   */
-  for (i = 0; i < len /* && *pos < ip->i_size */ ; i++)
-	if (zlist[i] == NO_ZONE)
-		*pos += jump(level);
-	else if (!markzone(ino, zlist[i], level, *pos)) {
-		*pos += jump(level);
-		ok = 0;
-	} else if (!zonechk(ino, ip, pos, zlist[i], level))
-		ok = 0;
-  return(ok);
-}
-
-/* Check a file or a directory. */
-int chkfile(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  register ok, i, level;
-  off_t pos = 0;
-
-  ok = chkzones(ino, ip, &pos, (zone_nr *)&ip->i_zone[0], NR_DZONE_NUM, 0);
-  for (i = NR_DZONE_NUM, level = 1; i < NR_ZONE_NUMS; i++, level++)
-	ok &= chkzones(ino, ip, &pos, (zone_nr *)&ip->i_zone[i], 1, level);
-  return(ok);
-}
-
-/* Check a directory by checking the contents.  Check if . and .. are present. */
-int chkdirectory(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  register ok;
-
-  setbit(dirmap, (bit_nr) ino);
-  ok = chkfile(ino, ip);
-  if (!(ftop->st_presence & DOT)) {
-	printf(". missing in ");
-	printpath(2, 1);
-	ok = 0;
-  }
-  if (!(ftop->st_presence & DOTDOT)) {
-	printf(".. missing in ");
-	printpath(2, 1);
-	ok = 0;
-  }
-  return(ok);
-}
-
-#ifdef I_SYMBOLIC_LINK
-
-/* Check the validity of a symbolic link. */
-int chklink(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  int ok;
-
-  ok = chkfile(ino, ip);
-  if (ip->i_size <= 0 || ip->i_size > BLOCK_SIZE) {
-	if (ip->i_size == 0)
-		printf("empty symbolic link ");
-	else
-		printf("symbolic link too large (size %ld) ", ip->i_size);
-	printpath(2, 1);
-	ok = 0;
-  }
-  return(ok);
-}
-
-#endif
-
-/* Check the validity of a special file. */
-int chkspecial(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  int i, ok;
-
-  ok = 1;
-  if ((dev_t) ip->i_zone[0] == NO_DEV) {
-	printf("illegal device number %u for special file ", ip->i_zone[0]);
-	printpath(2, 1);
-	ok = 0;
-  }
-
-  /* FS will not use the remaining "zone numbers" but 1.6.11++ will panic if
-   * they are nonzero, since this should not happen.
-   */
-  for (i = 1; i < NR_ZONE_NUMS; i++)
-	if (ip->i_zone[i] != NO_ZONE) {
-		printf("nonzero zone number %u for special file ",
-		       ip->i_zone[i]);
-		printpath(2, 1);
-		ok = 0;
-	}
-  return(ok);
-}
-
-/* Check the mode and contents of an inode. */
-int chkmode(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  switch (ip->i_mode & I_TYPE) {
-      case I_REGULAR:
-	nregular++;
-	return chkfile(ino, ip);
-      case I_DIRECTORY:
-	ndirectory++;
-	return chkdirectory(ino, ip);
-      case I_BLOCK_SPECIAL:
-	nblkspec++;
-	return chkspecial(ino, ip);
-      case I_CHAR_SPECIAL:
-	ncharspec++;
-	return chkspecial(ino, ip);
-      case I_NAMED_PIPE:
-	npipe++;
-	return chkfile(ino, ip);
-#ifdef I_SYMBOLIC_LINK
-      case I_SYMBOLIC_LINK:
-	nsyml++;
-	return chklink(ino, ip);
-#endif
-      default:
-	nbadinode++;
-	printf("bad mode of ");
-	printpath(1, 0);
-	printf("mode = %o)", ip->i_mode);
-	return(0);
-  }
-}
-
-/* Check an inode. */
-int chkinode(ino, ip)
-ino_t ino;
-d_inode *ip;
-{
-  if (ino == ROOT_INODE && (ip->i_mode & I_TYPE) != I_DIRECTORY) {
-	printf("root inode is not a directory ");
-	printf("(ino = %u, mode = %o)\n", ino, ip->i_mode);
-	fatal("");
-  }
-  if (ip->i_nlinks == 0) {
-	printf("link count zero of ");
-	printpath(2, 0);
-	return(0);
-  }
-  nfreeinode--;
-  setbit(imap, (bit_nr) ino);
-  if ((unsigned) ip->i_nlinks > CHAR_MAX) {
-	printf("link count too big in ");
-	printpath(1, 0);
-	printf("cnt = %u)\n", (unsigned) ip->i_nlinks);
-	count[ino] -= CHAR_MAX;
-	setbit(spec_imap, (bit_nr) ino);
-  } else
-	count[ino] -= (unsigned) ip->i_nlinks;
-  return chkmode(ino, ip);
-}
-
-/* Check the directory entry pointed to by dp, by checking the inode. */
-int descendtree(dp)
-dir_struct *dp;
-{
-  d_inode inode;
-  register ino_t ino = dp->d_inum;
-  register visited;
-  struct stack stk;
-
-  stk.st_dir = dp;
-  stk.st_next = ftop;
-  ftop = &stk;
-  if (bitset(spec_imap, (bit_nr) ino)) {
-	printf("found inode %u: ", ino);
-	printpath(0, 1);
-  }
-  visited = bitset(imap, (bit_nr) ino);
-  if (!visited || listing) {
-	devread(inoaddr(ino), (char *) &inode, INODE_SIZE);
-	if (listing) list(ino, &inode);
-	if (!visited && !chkinode(ino, &inode)) {
-		setbit(spec_imap, (bit_nr) ino);
-		if (yes("remove")) {
-			count[ino] += inode.i_nlinks - 1;
-			clrbit(imap, (bit_nr) ino);
-			devwrite(inoaddr(ino), nullbuf, INODE_SIZE);
-			memset((void *) dp, 0, sizeof(dir_struct));
-			ftop = ftop->st_next;
-			return(0);
-		}
-	}
-  }
-  ftop = ftop->st_next;
-  return(1);
-}
-
-/* Check the file system tree. */
-void chktree()
-{
-  dir_struct dir;
-
-  nfreeinode = sb.s_ninodes;
-  nfreezone = N_DATA;
-  dir.d_inum = ROOT_INODE;
-  dir.d_name[0] = 0;
-  if (!descendtree(&dir)) fatal("bad root inode");
-  putchar('\n');
-}
-
-/* Print the totals of all the objects found. */
-void printtotal()
-{
-  printf("blocksize = %5d        ", BLOCK_SIZE);
-  printf("zonesize  = %5d\n", ZONE_SIZE);
-  printf("\n");
-  pr("%6u    Regular file%s\n", nregular, "", "s");
-  pr("%6u    Director%s\n", ndirectory, "y", "ies");
-  pr("%6u    Block special file%s\n", nblkspec, "", "s");
-  pr("%6u    Character special file%s\n", ncharspec, "", "s");
-  if (nbadinode != 0) pr("%6u    Bad inode%s\n", nbadinode, "", "s");
-  pr("%6u    Free inode%s\n", nfreeinode, "", "s");
-  pr("%6u    Named pipe%s\n", npipe, "", "s");
-  pr("%6u    Symbolic link%s\n", nsyml, "", "s");
-/* Don't print some fields.
-  printf("\n");
-  pr("%6u    Data zone%s\n",		  ztype[0],	 "",   "s");
-  pr("%6u    Single indirect zone%s\n",	  ztype[1],	 "",   "s");
-  pr("%6u    Double indirect zone%s\n",	  ztype[2],	 "",   "s");
-*/
-  pr("%6u    Free zone%s\n", nfreezone, "", "s");
-}
-
-/* Check the device which name is given by `f'.  The inodes listed by `clist'
- * should be listed separately, and the inodes listed by `ilist' and the zones
- * listed by `zlist' should be watched for while checking the file system.
- */
-
-void chkdev(f, clist, ilist, zlist)
-char *f, **clist, **ilist, **zlist;
-{
-  if (automatic) repair = 1;
-  device = f;
-  initvars();
-
-  devopen();
-
-  getsuper();
-  chksuper();
-
-  lsi(clist);
-
-  getbitmaps();
-
-  fillbitmap(spec_imap, (bit_nr) 1, (bit_nr) sb.s_ninodes + 1, ilist);
-  fillbitmap(spec_zmap, (bit_nr) FIRST, (bit_nr) sb.s_nzones, zlist);
-
-  getcount();
-  chktree();
-  chkmap(zmap, spec_zmap, (bit_nr) FIRST - 1, BLK_ZMAP, N_ZMAP, "zone");
-  chkcount();
-  chkmap(imap, spec_imap, (bit_nr) 0, BLK_IMAP, N_IMAP, "inode");
-  chkilist();
-  printtotal();
-
-  putbitmaps();
-  freecount();
-  devclose();
-
-  if (changed) printf("----- FILE SYSTEM HAS BEEN MODIFIED -----\n\n");
-}
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  register char **clist = 0, **ilist = 0, **zlist = 0;
-
-  register devgiven = 0;
-  register char *arg;
-
-  if ((1 << BITSHIFT) != 8 * sizeof(bitchunk_t)) {
-	printf("Fsck was compiled with the wrong BITSHIFT!\n");
-	exit(1);
-  }
-
-  sync();
-  prog = *argv++;
-  while ((arg = *argv++) != 0)
-	if (arg[0] == '-' && arg[1] != 0 && arg[2] == 0) switch (arg[1]) {
-		    case 'a':	automatic ^= 1;	break;
-		    case 'c':
-			clist = getlist(&argv, "inode");
-			break;
-		    case 'i':
-			ilist = getlist(&argv, "inode");
-			break;
-		    case 'z':
-			zlist = getlist(&argv, "zone");
-			break;
-		    case 'r':	repair ^= 1;	break;
-		    case 'l':	listing ^= 1;	break;
-		    case 's':	listsuper ^= 1;	break;
-		    default:
-			printf("%s: unknown flag '%s'\n", prog, arg);
-		}
-	else {
-		chkdev(arg, clist, ilist, zlist);
-		clist = 0;
-		ilist = 0;
-		zlist = 0;
-		devgiven = 1;
-	}
-  if (!devgiven) {
-	printf("Usage: fsck1 [-acilrsz] file\n");
-	exit(1);
-  }
-  return(0);
-}
Index: trunk/minix/commands/simple/getty.c
===================================================================
--- trunk/minix/commands/simple/getty.c	(revision 9)
+++ 	(revision )
@@ -1,201 +1,0 @@
-/* getty - get tty speed			Author: Fred van Kempen */
-
-/*
- * GETTY  -     Initialize and serve a login-terminal for INIT.
- *		Also, select the correct speed. The STTY() code
- *		was taken from stty(1).c; which was written by
- *		Andrew S. Tanenbaum.
- *
- * Usage:	getty [-c filename] [-h] [-k] [-t] line [speed]
- *
- * Version:	3.4	02/17/90
- *
- * Author:	F. van Kempen, MicroWalt Corporation
- *
- * Modifications:
- *		All the good stuff removed to get a minimal getty, because
- *		many modems don't like all that fancy speed detection stuff.
- *		03/03/91	Kees J. Bot (kjb@cs.vu.nl)
- *
- *		Uname(), termios.  More nonsense removed.  (The result has
- *		only 10% of the original functionality, but a 10x chance of
- *		working.)
- *		12/12/92	Kees J. Bot
- *
- *		Customizable login banner.
- *		11/13/95	Kees J. Bot
- *
- *		Suspend/resume signals removed.
- *		2001-04-04	Kees J. Bot
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/utsname.h>
-
-char LOGIN[] =		"/usr/bin/login";
-char SHELL[] =		"/bin/sh";
-
-char *tty_name;			/* name of the line */
-
-/* Crude indication of a tty being physically secure: */
-#define securetty(dev)		((unsigned) ((dev) - 0x0400) < (unsigned) 8)
-
-void std_out(char *s)
-{
-  write(1, s, strlen(s));
-}
-
-/* Read one character from stdin.
- */
-int readch(void)
-{
-  int st;
-  char ch1;
-
-  /* read character from TTY */
-  st = read(0, &ch1, 1);
-  if (st == 0) {
-	std_out("\n");
-	exit(0);
-  }
-  if (st < 0) {
-	std_out("getty: ");
-	std_out(tty_name);
-	std_out(": read error\n");
-	exit(1);
-  }
-  return(ch1 & 0xFF);
-}
-
-
-/* Handle the process of a GETTY.
- */
-void do_getty(char *name, size_t len, char **args, char *ttyname)
-{
-  register char *np, *s, *s0;
-  int ch;
-  struct utsname utsname;
-  char **banner, *t;
-  static char *def_banner[] = { "%s  Release %r Version %v  (%t)\n\n%n login: ", 0 };
-
-  /* Clean up tty name. */
-  if((t = strrchr(ttyname, '/'))) ttyname = t + 1;
-
-  /* Default banner? */
-  if (args[0] == NULL) args = def_banner;
-
-  /* Display prompt. */
-  ch = ' ';
-  *name = '\0';
-  while (ch != '\n') {
-	/* Get data about this machine. */
-	uname(&utsname);
-
-	/* Print the banner. */
-	for (banner = args; *banner != NULL; banner++) {
-		std_out(banner == args ? "\n" : " ");
-		s0 = *banner;
-		for (s = *banner; *s != 0; s++) {
-			if (*s == '\\') {
-				write(1, s0, s-s0);
-				s0 = s+2;
-				switch (*++s) {
-				case 'n':  std_out("\n"); break;
-				case 's':  std_out(" "); break;
-				case 't':  std_out("\t"); break;
-				case 0:	   goto leave;
-				default:   s0 = s;
-				}
-			} else
-			if (*s == '%') {
-				write(1, s0, s-s0);
-				s0 = s+2;
-				switch (*++s) {
-				case 's':  std_out(utsname.sysname); break;
-				case 'n':  std_out(utsname.nodename); break;
-				case 'r':  std_out(utsname.release); break;
-				case 'v':  std_out(utsname.version); break;
-				case 'm':  std_out(utsname.machine); break;
-				case 'p':  std_out(utsname.arch); break;
-				case 't':  std_out(ttyname); break;
-#if __minix_vmd
-				case 'k':  std_out(utsname.kernel); break;
-				case 'h':  std_out(utsname.hostname); break;
-				case 'b':  std_out(utsname.bus); break;
-#endif
-				case 0:	   goto leave;
-				default:   s0 = s-1;
-				}
-			}
-		}
-	    leave:
-		write(1, s0, s-s0);
-	}
-
-	np = name;
-	while ((ch = readch()) != '\n') {
-		if (np < name + len) *np++ = ch;
-	}
-	*np = '\0';
-	if (*name == '\0') ch = ' ';	/* blank line typed! */
-  }
-}
-
-
-/* Execute the login(1) command with the current
- * username as its argument. It will reply to the
- * calling user by typing "Password: "...
- */
-void do_login(char *name)
-{ 
-  struct stat st;
-
-  execl(LOGIN, LOGIN, name, (char *) NULL);
-  /* Failed to exec login.  Impossible, but true.  Try a shell, but only if
-   * the terminal is more or less secure, because it will be a root shell.
-   */
-  std_out("getty: can't exec ");
-  std_out(LOGIN);
-  std_out("\n");
-  if (fstat(0, &st) == 0 && S_ISCHR(st.st_mode) && securetty(st.st_rdev)) {
-	execl(SHELL, SHELL, (char *) NULL);
-  }
-}
-
-
-int main(int argc, char **argv)
-{
-  register char *s;
-  char name[30];
-  struct sigaction sa;
-
-  /* Don't let QUIT dump core. */
-  sigemptyset(&sa.sa_mask);
-  sa.sa_flags = 0;
-  sa.sa_handler = exit;
-  sigaction(SIGQUIT, &sa, NULL);
-
-  tty_name = ttyname(0);
-  if (tty_name == NULL) {
-	std_out("getty: tty name unknown\n");
-	pause();
-	return(1);
-  }
-
-  chown(tty_name, 0, 0);	/* set owner of TTY to root */
-  chmod(tty_name, 0600);	/* mode to max secure */
-
-  do_getty(name, sizeof(name), argv+1, tty_name);	/* handle getty() */
-  name[29] = '\0';		/* make sure the name fits! */
-
-  do_login(name);		/* and call login(1) if OK */
-
-  return(1);			/* never executed */
-}
Index: trunk/minix/commands/simple/gomoku.c
===================================================================
--- trunk/minix/commands/simple/gomoku.c	(revision 9)
+++ 	(revision )
@@ -1,739 +1,0 @@
-/* gomoku - 5 in a row game		Author: ? */
-
-/* This program plays a very old Japanese game called GO-MOKU,
-   perhaps better known as  5-in-line.   The game is played on
-   a board with 19 x 19 squares, and the object of the game is
-   to get 5 stones in a row.
-*/
-
-#include <sys/types.h>
-#include <curses.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-/* Size of the board */
-#define SIZE 19
-
-/* Importance of attack (1..16) */
-#define AttackFactor 4
-
-/* Value of having 0, 1,2,3,4 or 5 pieces in line */
-int Weight[7] = {0, 0, 4, 20, 100, 500, 0};
-
-#define Null 0
-#define Horiz 1
-#define DownLeft 2
-#define DownRight 3
-#define Vert 4
-
-/* The two players */
-#define Empty 0
-#define Cross 1
-#define Nought 2
-
-char PieceChar[Nought + 1] = {' ', 'X', '0'};
-
-int Board[SIZE + 1][SIZE + 1];/* The board */
-int Player;			/* The player whose move is next */
-int TotalLines;			/* The number of Empty lines left */
-int GameWon;			/* Set if one of the players has won */
-
-int Line[4][SIZE + 1][SIZE + 1][Nought + 1];
-
-/* Value of each square for each player */
-int Value[SIZE + 1][SIZE + 1][Nought + 1];
-
-int X, Y;			/* Move coordinates */
-char Command;			/* Command from keyboard */
-int AutoPlay = FALSE;		/* The program plays against itself */
-
-_PROTOTYPE(void Initialize, (void));
-_PROTOTYPE(int Abort, (char *s));
-_PROTOTYPE(void WriteLetters, (void));
-_PROTOTYPE(void WriteLine, (int j, int *s));
-_PROTOTYPE(void WriteBoard, (int N, int *Top, int *Middle, int *Bottom));
-_PROTOTYPE(void SetUpScreen, (void));
-_PROTOTYPE(void GotoSquare, (int x, int y));
-_PROTOTYPE(void PrintMove, (int Piece, int X, int Y));
-_PROTOTYPE(void ClearMove, (void));
-_PROTOTYPE(void PrintMsg, (char *Str));
-_PROTOTYPE(void ClearMsg, (void));
-_PROTOTYPE(void WriteCommand, (char *S));
-_PROTOTYPE(void ResetGame, (int FirstGame));
-_PROTOTYPE(int OpponentColor, (int Player));
-_PROTOTYPE(void BlinkRow, (int X, int Y, int Dx, int Dy, int Piece));
-_PROTOTYPE(void BlinkWinner, (int Piece, int X, int Y, int WinningLine));
-_PROTOTYPE(int Random, (int x));
-_PROTOTYPE(void Add, (int *Num));
-_PROTOTYPE(void Update, (int Lin[], int Valu[], int Opponent));
-_PROTOTYPE(void MakeMove, (int X, int Y));
-_PROTOTYPE(int GameOver, (void));
-_PROTOTYPE(void FindMove, (int *X, int *Y));
-_PROTOTYPE(char GetChar, (void));
-_PROTOTYPE(void ReadCommand, (int X, int Y, char *Command));
-_PROTOTYPE(void InterpretCommand, (int Command));
-_PROTOTYPE(void PlayerMove, (void));
-_PROTOTYPE(void ProgramMove, (void));
-_PROTOTYPE(int main, (void));
-
-/* Set terminal to raw mode. */
-void Initialize()
-{
-  srand(getpid() + 13);		/* Initialize the random seed with our pid */
-  initscr();
-  raw();
-  noecho();
-  clear();
-}
-
-/* Reset terminal and exit from the program. */
-int Abort(s)
-char *s;
-{
-  move(LINES - 1, 0);
-  refresh();
-  endwin();
-  exit(0);
-}
-
-/* Set up the screen ----------------------------------------------- */
-
-/* Write the letters */
-void WriteLetters()
-{
-  int i;
-
-  addch(' ');
-  addch(' ');
-  for (i = 1; i <= SIZE; i++) printw(" %c", 'A' + i - 1);
-  addch('\n');
-}
-
-/* Write one line of the board */
-void WriteLine(j, s)
-int j;
-int *s;
-{
-  int i;
-
-  printw("%2d ", j);
-  addch(s[0]);
-  for (i = 2; i <= SIZE - 1; i++) {
-	addch(s[1]);
-	addch(s[2]);
-  }
-  addch(s[1]);
-  addch(s[3]);
-  printw(" %-2d\n", j);
-}
-
-/* Print the Empty board and the border */
-void WriteBoard(N, Top, Middle, Bottom)
-int N;
-int *Top, *Middle, *Bottom;
-{
-  int j;
-
-  move(1, 0);
-  WriteLetters();
-  WriteLine(N, Top);
-  for (j = N - 1; j >= 2; j--) WriteLine(j, Middle);
-  WriteLine(1, Bottom);
-  WriteLetters();
-}
-
-/* Sets up the screen with an Empty board */
-void SetUpScreen()
-{
-  int top[4], middle[4], bottom[4];
-
-  top[0] = ACS_ULCORNER;
-  top[1] = ACS_HLINE;
-  top[2] = ACS_TTEE;
-  top[3] = ACS_URCORNER;
-
-  middle[0] = ACS_LTEE;
-  middle[1] = ACS_HLINE;
-  middle[2] = ACS_PLUS;
-  middle[3] = ACS_RTEE;
-
-  bottom[0] = ACS_LLCORNER;
-  bottom[1] = ACS_HLINE;
-  bottom[2] = ACS_BTEE;
-  bottom[3] = ACS_LRCORNER;
-
-  WriteBoard(SIZE, top, middle, bottom);
-}
-
-/* Show moves ----------------------------------------------- */
-
-void GotoSquare(x, y)
-int x, y;
-{
-  move(SIZE + 2 - y, 1 + x * 2);
-}
-
-/* Prints a move */
-void PrintMove(Piece, X, Y)
-int Piece;
-int X, Y;
-{
-  move(22, 49);
-  printw("%c %c %d", PieceChar[Piece], 'A' + X - 1, Y);
-  clrtoeol();
-  GotoSquare(X, Y);
-  addch(PieceChar[Piece]);
-  GotoSquare(X, Y);
-  refresh();
-}
-
-/* Clears the line where a move is displayed */
-void ClearMove()
-{
-  move(22, 49);
-  clrtoeol();
-}
-
-/* Message handling ---------------------------------------------- */
-
-/* Prints a message */
-void PrintMsg(Str)
-char *Str;
-{
-  mvprintw(23, 1, "%s", Str);
-}
-
-/* Clears the message about the winner */
-void ClearMsg()
-{
-  move(23, 1);
-  clrtoeol();
-}
-
-/* Highlights the first letter of S */
-void WriteCommand(S)
-char *S;
-{
-  standout();
-  addch(*S);
-  standend();
-  printw("%s", S + 1);
-}
-
-/* Display the board ----------------------------------------------- */
-
-/* Resets global variables to start a new game */
-void ResetGame(FirstGame)
-int FirstGame;
-{
-  int I, J;
-  int C, D;
-
-  SetUpScreen();
-  if (FirstGame) {
-	move(1, 49);
-	addstr("G O M O K U");
-	move(3, 49);
-	WriteCommand("Newgame    ");
-	WriteCommand("Quit ");
-	move(5, 49);
-	WriteCommand("Auto");
-	move(7, 49);
-	WriteCommand("Play");
-	move(9, 49);
-	WriteCommand("Hint");
-	move(14, 60);
-	WriteCommand("Left, ");
-	WriteCommand("Right, ");
-	move(16, 60);
-	WriteCommand("Up, ");
-	WriteCommand("Down");
-	move(18, 60);
-	standout();
-	addstr("SPACE");
-	move(20, 49);
-	WriteCommand(" NOTE: Use Num Lock & arrows");
-	standend();
-	mvaddstr(14, 49, "7  8  9");
-	mvaddch(15, 52, ACS_UARROW);
-	mvaddch(16, 49, '4');
-	addch(ACS_LARROW);
-	mvaddch(16, 54, ACS_RARROW);
-	addch('6');
-	mvaddch(17, 52, ACS_DARROW);
-	mvaddstr(18, 49, "1  2  3");
-	FirstGame = FALSE;
-  } else {
-	ClearMsg();
-	ClearMove();
-  }
-
-  /* Clear tables */
-  for (I = 1; I <= SIZE; I++) for (J = 1; J <= SIZE; J++) {
-		Board[I][J] = Empty;
-		for (C = Cross; C <= Nought; C++) {
-			Value[I][J][C] = 0;
-			for (D = 0; D <= 3; D++) Line[D][I][J][C] = 0;
-		}
-	}
-
-  /* Cross starts */
-  Player = Cross;
-  /* Total number of lines */
-  TotalLines = 2 * 2 * (SIZE * (SIZE - 4) + (SIZE - 4) * (SIZE - 4));
-  GameWon = FALSE;
-}
-
-int OpponentColor(Player)
-int Player;
-{
-  if (Player == Cross)
-	return Nought;
-  else
-	return Cross;
-}
-
-/* Blink the row of 5 stones */
-void BlinkRow(X, Y, Dx, Dy, Piece)
-int X, Y, Dx, Dy, Piece;
-{
-  int I;
-
-  attron(A_BLINK);
-  for (I = 1; I <= 5; I++) {
-	GotoSquare(X, Y);
-	addch(PieceChar[Piece]);
-	X = X - Dx;
-	Y = Y - Dy;
-  }
-  attroff(A_BLINK);
-}
-
-/* Prints the 5 winning stones in blinking color */
-void BlinkWinner(Piece, X, Y, WinningLine)
-int Piece, X, Y, WinningLine;
-{
-  /* Used to store the position of the winning move */
-  int XHold, YHold;
-  /* Change in X and Y */
-  int Dx, Dy;
-
-  /* Display winning move */
-  PrintMove(Piece, X, Y);
-  /* Preserve winning position */
-  XHold = X;
-  YHold = Y;
-  switch (WinningLine) {
-      case Horiz:
-	{
-		Dx = 1;
-		Dy = 0;
-		break;
-	}
-
-      case DownLeft:
-	{
-		Dx = 1;
-		Dy = 1;
-		break;
-	}
-
-      case Vert:
-	{
-		Dx = 0;
-		Dy = 1;
-		break;
-	}
-
-      case DownRight:
-	{
-		Dx = -1;
-		Dy = 1;
-		break;
-	}
-  }
-
-  /* Go to topmost, leftmost */
-  while (Board[X + Dx][Y + Dy] != Empty && Board[X + Dx][Y + Dy] == Piece) {
-	X = X + Dx;
-	Y = Y + Dy;
-  }
-  BlinkRow(X, Y, Dx, Dy, Piece);
-  /* Restore winning position */
-  X = XHold;
-  Y = YHold;
-  /* Go back to winning square */
-  GotoSquare(X, Y);
-}
-
-/* Functions for playing a game -------------------------------- */
-
-int Random(x)
-int x;
-{
-  return((rand() / 19) % x);
-}
-
-/* Adds one to the number of pieces in a line */
-void Add(Num)
-int *Num;
-{
-  /* Adds one to the number.     */
-  *Num = *Num + 1;
-  /* If it is the first piece in the line, then the opponent cannot use
-   * it any more.  */
-  if (*Num == 1) TotalLines = TotalLines - 1;
-  /* The game is won if there are 5 in line. */
-  if (*Num == 5) GameWon = TRUE;
-}
-
-/* Updates the value of a square for each player, taking into
-   account that player has placed an extra piece in the square.
-   The value of a square in a usable line is Weight[Lin[Player]+1]
-   where Lin[Player] is the number of pieces already placed
-in the line */
-void Update(Lin, Valu, Opponent)
-int Lin[];
-int Valu[];
-int Opponent;
-{
-  /* If the opponent has no pieces in the line, then simply update the
-   * value for player */
-  if (Lin[Opponent] == 0)
-	Valu[Player] += Weight[Lin[Player] + 1] - Weight[Lin[Player]];
-  else
-	/* If it is the first piece in the line, then the line is
-	 * spoiled for the opponent */
-  if (Lin[Player] == 1) Valu[Opponent] -= Weight[Lin[Opponent] + 1];
-}
-
-/* Performs the move X,Y for player, and updates the global variables
-(Board, Line, Value, Player, GameWon, TotalLines and the screen) */
-void MakeMove(X, Y)
-int X, Y;
-{
-  int Opponent;
-  int X1, Y1;
-  int K, L, WinningLine;
-
-  WinningLine = Null;
-  Opponent = OpponentColor(Player);
-  GameWon = FALSE;
-
-  /* Each square of the board is part of 20 different lines. The adds
-   * one to the number of pieces in each of these lines. Then it
-   * updates the value for each of the 5 squares in each of the 20
-   * lines. Finally Board is updated, and the move is printed on the
-   * screen. */
-
-  /* Horizontal lines, from left to right */
-  for (K = 0; K <= 4; K++) {
-	X1 = X - K;		/* Calculate starting point */
-	Y1 = Y;
-	if ((1 <= X1) && (X1 <= SIZE - 4)) {	/* Check starting point */
-		Add(&Line[0][X1][Y1][Player]);	/* Add one to line */
-		if (GameWon && (WinningLine == Null))	/* Save winning line */
-			WinningLine = Horiz;
-		for (L = 0; L <= 4; L++)	/* Update value for the
-						 * 5 squares in the line */
-			Update(Line[0][X1][Y1], Value[X1 + L][Y1], Opponent);
-	}
-  }
-
-  for (K = 0; K <= 4; K++) {	/* Diagonal lines, from lower left to
-				 * upper right */
-	X1 = X - K;
-	Y1 = Y - K;
-	if ((1 <= X1) && (X1 <= SIZE - 4) &&
-	    (1 <= Y1) && (Y1 <= SIZE - 4)) {
-		Add(&Line[1][X1][Y1][Player]);
-		if (GameWon && (WinningLine == Null))	/* Save winning line */
-			WinningLine = DownLeft;
-		for (L = 0; L <= 4; L++)
-			Update(Line[1][X1][Y1], Value[X1 + L][Y1 + L], Opponent);
-	}
-  }				/* for */
-
-  for (K = 0; K <= 4; K++) {	/* Diagonal lines, down right to upper left */
-	X1 = X + K;
-	Y1 = Y - K;
-	if ((5 <= X1) && (X1 <= SIZE) &&
-	    (1 <= Y1) && (Y1 <= SIZE - 4)) {
-		Add(&Line[3][X1][Y1][Player]);
-		if (GameWon && (WinningLine == Null))	/* Save winning line */
-			WinningLine = DownRight;
-		for (L = 0; L <= 4; L++)
-			Update(Line[3][X1][Y1], Value[X1 - L][Y1 + L], Opponent);
-	}
-  }				/* for */
-
-  for (K = 0; K <= 4; K++) {	/* Vertical lines, from down to up */
-	X1 = X;
-	Y1 = Y - K;
-	if ((1 <= Y1) && (Y1 <= SIZE - 4)) {
-		Add(&Line[2][X1][Y1][Player]);
-		if (GameWon && (WinningLine == Null))	/* Save winning line */
-			WinningLine = Vert;
-		for (L = 0; L <= 4; L++)
-			Update(Line[2][X1][Y1], Value[X1][Y1 + L], Opponent);
-	}
-  }
-
-  Board[X][Y] = Player;		/* Place piece in board */
-  if (GameWon)
-	BlinkWinner(Player, X, Y, WinningLine);
-  else
-	PrintMove(Player, X, Y);/* Print move on screen */
-  Player = Opponent;		/* The opponent is next to move */
-}
-
-int GameOver()
-/* A game is over if one of the players have
-won, or if there are no more Empty lines */
-{
-  return(GameWon || (TotalLines <= 0));
-}
-
-/* Finds a move X,Y for player, simply by picking the one with the
-highest value */
-void FindMove(X, Y)
-int *X, *Y;
-{
-  int Opponent;
-  int I, J;
-  int Max, Valu;
-
-  Opponent = OpponentColor(Player);
-  Max = -10000;
-  /* If no square has a high value then pick the one in the middle */
-  *X = (SIZE + 1) / 2;
-  *Y = (SIZE + 1) / 2;
-  if (Board[*X][*Y] == Empty) Max = 4;
-  /* The evaluation for a square is simply the value of the square for
-   * the player (attack points) plus the value for the opponent
-   * (defense points). Attack is more important than defense, since it
-   * is better to get 5 in line yourself than to prevent the op- ponent
-   * from getting it. */
-
-  /* For all Empty squares */
-  for (I = 1; I <= SIZE; I++) for (J = 1; J <= SIZE; J++)
-		if (Board[I][J] == Empty) {
-			/* Calculate evaluation */
-			Valu = Value[I][J][Player] * (16 + AttackFactor) / 16 + Value[I][J][Opponent] + Random(4);
-			/* Pick move with highest value */
-			if (Valu > Max) {
-				*X = I;
-				*Y = J;
-				Max = Valu;
-			}
-		}
-}
-
-char GetChar()
-/* Get a character from the keyboard */
-{
-  int c;
-
-  c = getch();
-  if (c < 0) abort();
-  if (c == '\033') {	/* arrow key */
-	if ((c = getch()) == '[') {
-		c = getch();
-		switch (c) {
-		case 'A': c = 'U'; break;
-		case 'B': c = 'D'; break;
-		case 'C': c = 'R'; break;
-		case 'D': c = 'L'; break;
-		default:
-			c = '?';
-			break;
-		}
-	}
-	else
-		c = '?';
-  }
-  if (islower(c))
-	return toupper(c);
-  else
-	return c;
-}
-
-/* Reads in a valid command character */
-void ReadCommand(X, Y, Command)
-int X, Y;
-char *Command;
-{
-  int ValidCommand;
-
-  do {
-	ValidCommand = TRUE;
-	GotoSquare(X, Y);	/* Goto square */
-	refresh();
-	*Command = GetChar();	/* Read from keyboard */
-	switch (*Command) {
-	    case '\n':		/* '\n', '\r' or space means place a */
-	    case '\r':
-	    case ' ':
-		*Command = 'E';
-		break;		/* stone at the cursor position  */
-
-	    case 'L':
-	    case 'R':
-	    case 'U':
-	    case 'D':
-	    case '7':
-	    case '9':
-	    case '1':
-	    case '3':
-	    case 'N':
-	    case 'Q':
-	    case 'A':
-	    case 'P':
-	    case 'H':
-		break;
-
-	    case '8':	*Command = 'U';	break;
-	    case '2':	*Command = 'D';	break;
-	    case '4':	*Command = 'L';	break;
-	    case '6':	*Command = 'R';	break;
-	    default:
-		{
-			if (GameOver())
-				*Command = 'P';
-			else
-				ValidCommand = FALSE;
-			break;
-		}
-	}
-  } while (!ValidCommand);
-}
-
-void InterpretCommand(Command)
-char Command;
-{
-  int Temp;
-
-  switch (Command) {
-      case 'N':{		/* Start new game */
-		ResetGame(FALSE);	/* ResetGame but only redraw
-					 * the board */
-		X = (SIZE + 1) / 2;
-		Y = X;
-		break;
-	}
-      case 'H':
-	FindMove(&X, &Y);
-	break;			/* Give the user a hint */
-      case 'L':
-	X = (X + SIZE - 2) % SIZE + 1;
-	break;			/* Left  */
-      case 'R':
-	X = X % SIZE + 1;
-	break;			/* Right */
-      case 'D':
-	Y = (Y + SIZE - 2) % SIZE + 1;
-	break;			/* Down  */
-      case 'U':
-	Y = Y % SIZE + 1;
-	break;			/* Up    */
-      case '7':{
-		if ((X == 1) || (Y == SIZE)) {	/* Move diagonally    *//* t
-						 * owards upper left */
-			Temp = X;
-			X = Y;
-			Y = Temp;
-		} else {
-			X = X - 1;
-			Y = Y + 1;
-		}
-		break;
-	}
-      case '9':{		/* Move diagonally    */
-		if (X == SIZE) {/* toward upper right */
-			X = (SIZE - Y) + 1;
-			Y = 1;
-		} else if (Y == SIZE) {
-			Y = (SIZE - X) + 1;
-			X = 1;
-		} else {
-			X = X + 1;
-			Y = Y + 1;
-		}
-		break;
-	}
-      case '1':{		/* Move diagonally   */
-		if (Y == 1) {	/* toward lower left */
-			Y = (SIZE - X) + 1;
-			X = SIZE;
-		} else if (X == 1) {
-			X = (SIZE - Y) + 1;
-			Y = SIZE;
-		} else {
-			X = X - 1;
-			Y = Y - 1;
-		}
-		break;
-	}
-      case '3':{		/* Move diagonally    */
-		if ((X == SIZE) || (Y == 1)) {	/* toward lower right */
-			Temp = X;
-			X = Y;
-			Y = Temp;
-		} else {
-			X = X + 1;
-			Y = Y - 1;
-		}
-		break;
-	}
-      case 'A':
-	AutoPlay = TRUE;
-	break;			/* Auto play mode */
-  }				/* case */
-}				/* InterpretCommand */
-
-void PlayerMove()
-/* Enter and make a move */
-{
-  if (Board[X][Y] == Empty) {
-	MakeMove(X, Y);
-	if (GameWon) PrintMsg("Congratulations, You won!");
-	Command = 'P';
-  }
-  refresh();
-}				/* PlayerMove */
-
-void ProgramMove()
-/* Find and perform programs move */
-{
-  do {
-	if (GameOver()) {
-		AutoPlay = FALSE;
-		if ((Command != 'Q') && (!GameWon)) PrintMsg("Tie game!");
-	} else {
-		FindMove(&X, &Y);
-		MakeMove(X, Y);
-		if (GameWon) PrintMsg("I won!");
-	}
-	refresh();
-  } while (AutoPlay);
-}
-
-int main()
-{
-  Initialize();
-  ResetGame(TRUE);		/* ResetGame and draw the entire screen */
-  refresh();
-  X = (SIZE + 1) / 2;		/* Set starting position to */
-  Y = X;			/* the middle of the board  */
-  do {
-	ReadCommand(X, Y, &Command);
-	if (GameOver())
-		if (Command != 'Q') Command = 'N';
-	InterpretCommand(Command);
-	if (Command == 'E') PlayerMove();
-	if (Command == 'P' || Command == 'A') ProgramMove();
-  } while (Command != 'Q');
-  Abort("Good bye!");
-  return(0);
-}
Index: trunk/minix/commands/simple/grep.c
===================================================================
--- trunk/minix/commands/simple/grep.c	(revision 9)
+++ 	(revision )
@@ -1,379 +1,0 @@
-/* grep - search a file for a pattern	Author: Norbert Schlenker */
-
-/* Norbert Schlenker (nfs@princeton.edu)  1990-02-08
- * Released into the public domain.
- *
- * Grep searches files for lines containing a pattern, as specified by
- * a regular expression, and prints those lines.  It is invoked by:
- *	grep [flags] [pattern] [file ...]
- *
- * Flags:
- *	-e pattern	useful when pattern begins with '-'
- *	-c		print a count of lines matched
- *	-i		ignore case
- *	-l		prints just file names, no lines (quietly overrides -n)
- *	-n		printed lines are preceded by relative line numbers
- *	-s		prints errors only (quietly overrides -l and -n)
- *	-v		prints lines which don't contain the pattern
- *
- * Semantic note:
- * 	If both -l and -v are specified, grep prints the names of those
- *	files which do not contain the pattern *anywhere*.
- *
- * Exit:
- *	Grep sets an exit status which can be tested by the caller.
- *	Note that these settings are not necessarily compatible with
- *	any other version of grep, especially when -v is specified.
- *	Possible status values are:
- *	  0	if any matches are found
- *	  1	if no matches are found
- *	  2	if syntax errors are detected or any file cannot be opened
- */
-
-
-/* External interfaces */
-#include <sys/types.h>
-#include <regexp.h>		/* Thanks to Henry Spencer */
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <unistd.h>
-
-/* Internal constants */
-#define MATCH		0	/* exit code: some match somewhere */
-#define NO_MATCH	1	/* exit code: no match on any line */
-#define FAILURE		2	/* exit code: syntax error or bad file name */
-
-/* Macros */
-#define SET_FLAG(c)	(flags[(c)-'a'] = 1)
-#define FLAG(c)		(flags[(c)-'a'] != 0)
-
-#define uppercase(c)	(((unsigned) ((c) - 'A')) <= ('Z' - 'A'))
-#define downcase(c)	((c) - 'A' + 'a')
-
-/* Private storage */
-static char *program;		/* program name */
-static char flags[26];		/* invocation flags */
-static regexp *expression;	/* compiled search pattern */
-static const char *rerr;              /* error message */
-
-/* External variables. */
-extern int optind;
-extern char *optarg;
-
-/* Internal interfaces */
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(static int match, (FILE *input, char *label, char *filename));
-_PROTOTYPE(static char *get_line, (FILE *input));
-_PROTOTYPE(static char *map_nocase, (char *line));
-_PROTOTYPE(void regerror , (const char *s ) );
-_PROTOTYPE(static void tov8, (char *v8pattern, char *pattern));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int opt;			/* option letter from getopt() */
-  int egrep=0;			/* using extended regexp operators */
-  char *pattern;		/* search pattern */
-  char *v8pattern;		/* v8 regexp search pattern */
-  int exit_status = NO_MATCH;	/* exit status for our caller */
-  int file_status;		/* status of search in one file */
-  FILE *input;			/* input file (if not stdin) */
-
-  program = argv[0];
-  if (strlen(program)>=5 && strcmp(program+strlen(program)-5,"egrep")==0) egrep=1;
-  memset(flags, 0, sizeof(flags));
-  pattern = NULL;
-
-/* Process any command line flags. */
-  while ((opt = getopt(argc, argv, "e:cilnsv")) != EOF) {
-	if (opt == '?')
-		exit_status = FAILURE;
-	else
-	if (opt == 'e')
-		pattern = optarg;
-	else
-		SET_FLAG(opt);
-  }
-
-/* Detect a few problems. */
-  if ((exit_status == FAILURE) || (optind == argc && pattern == NULL)) {
-	fprintf(stderr,"Usage: %s [-cilnsv] [-e] expression [file ...]\n",program);
-	exit(FAILURE);
-  }
-
-/* Ensure we have a usable pattern. */
-  if (pattern == NULL)
-	pattern = argv[optind++];
-
-/* Map pattern to lowercase if -i given. */
-  if (FLAG('i')) {
-	char *p;
-	for (p = pattern; *p != '\0'; p++) {
-		if (uppercase(*p))
-			*p = downcase(*p);
-	}
-  }
-
-  if (!egrep) {
-	  if ((v8pattern=malloc(2*strlen(pattern)))==(char*)0) {
-		fprintf(stderr,"%s: out of memory\n");
-		exit(FAILURE);
-	  }
-	  tov8(v8pattern,pattern);
-  } else v8pattern=pattern;
-
-  rerr=(char*)0;
-  if ((expression = regcomp(v8pattern)) == NULL) {
-	fprintf(stderr,"%s: bad regular expression",program);
-	if (rerr) fprintf(stderr," (%s)",rerr);
-	fprintf(stderr,"\n");
-	exit(FAILURE);
-  }
-
-/* Process the files appropriately. */
-  if (optind == argc) {		/* no file names - find pattern in stdin */
-	exit_status = match(stdin, (char *) NULL, "<stdin>");
-  }
-  else 
-  if (optind + 1 == argc) {	/* one file name - find pattern in it */
-	if (strcmp(argv[optind], "-") == 0) {
-		exit_status = match(stdin, (char *) NULL, "-");
-	} else {
-		if ((input = fopen(argv[optind], "r")) == NULL) {
-			fprintf(stderr, "%s: couldn't open %s\n",
-							program, argv[optind]);
-			exit_status = FAILURE;
-		}
-		else {
-			exit_status = match(input, (char *) NULL, argv[optind]);
-		}
-	}
-  }
-  else
-  while (optind < argc) {	/* lots of file names - find pattern in all */
-	if (strcmp(argv[optind], "-") == 0) {
-		file_status = match(stdin, "-", "-");
-	} else {
-		if ((input = fopen(argv[optind], "r")) == NULL) {
-			fprintf(stderr, "%s: couldn't open %s\n",
-							program, argv[optind]);
-			exit_status = FAILURE;
-		} else {
-			file_status = match(input, argv[optind], argv[optind]);
-			fclose(input);
-		}
-	}
-	if (exit_status != FAILURE)
-		exit_status &= file_status;
-	++optind;
-  }
-  return(exit_status);
-}
-
-
-/* match - matches the lines of a file with the regular expression.
- * To improve performance when either -s or -l is specified, this
- * function handles those cases specially.
- */
-
-static int match(input, label, filename)
-FILE *input;
-char *label;
-char *filename;
-{
-  char *line, *testline;	/* pointers to input line */
-  long int lineno = 0;		/* line number */
-  long int matchcount = 0;	/* lines matched */
-  int status = NO_MATCH;	/* summary of what was found in this file */
-
-  if (FLAG('s') || FLAG('l')) {
-	while ((line = get_line(input)) != NULL) {
-		testline = FLAG('i') ? map_nocase(line) : line;
-		if (regexec(expression, testline, 1)) {
-			status = MATCH;
-			break;
-		}
-	}
-	if (FLAG('l'))
-		if ((!FLAG('v') && status == MATCH) ||
-		    ( FLAG('v') && status == NO_MATCH))
-			puts(filename);
-	return status;
-  }
-
-  while ((line = get_line(input)) != NULL) {
-	++lineno;
-	testline = FLAG('i') ? map_nocase(line) : line;
-	if (regexec(expression, testline, 1)) {
-		status = MATCH;
-		if (!FLAG('v')) {
-			if (label != NULL)
-				printf("%s:", label);
-			if (FLAG('n'))
-				printf("%ld:", lineno);
-			if (!FLAG('c')) puts(line);
-			matchcount++;
-		}
-	} else {
-		if (FLAG('v')) {
-			if (label != NULL)
-				printf("%s:", label);
-			if (FLAG('n'))
-				printf("%ld:", lineno);
-			if (!FLAG('c')) puts(line);
-			matchcount++;
-		}
-	}
-  }
-  if (FLAG('c')) printf("%ld\n", matchcount);
-  return status;
-}
-
-
-/* get_line - fetch a line from the input file
- * This function reads a line from the input file into a dynamically
- * allocated buffer.  If the line is too long for the current buffer,
- * attempts will be made to increase its size to accomodate the line.
- * The trailing newline is stripped before returning to the caller.
- */
-
-#define FIRST_BUFFER (size_t)256		/* first buffer size */
-
-static char *buf = NULL;	/* input buffer */
-static size_t buf_size = 0;		/* input buffer size */
-
-static char *get_line(input)
-FILE *input;
-{
-  int n;
-  register char *bp;
-  register int c;
-  char *new_buf;
-  size_t new_size;
-
-  if (buf_size == 0) {
-	if ((buf = (char *) malloc(FIRST_BUFFER)) == NULL) {
-		fprintf(stderr,"%s: not enough memory\n",program);
-		exit(FAILURE);
-	}
-	buf_size = FIRST_BUFFER;
-  }
-
-  bp = buf;
-  n = buf_size;
-  while (1) {
-	while (--n > 0 && (c = getc(input)) != EOF) {
-		if (c == '\n') {
-			*bp = '\0';
-			return buf;
-		}
-		*bp++ = c;
-	}
-	if (c == EOF)
-		return (ferror(input) || bp == buf) ? NULL : buf;
-	new_size = buf_size << 1;
-	if ((new_buf = (char *) realloc(buf, new_size)) == NULL) {
-		fprintf(stderr, "%s: line too long - truncated\n", program);
-		while ((c = getc(input)) != EOF && c != '\n') ;
-		*bp = '\0';
-		return buf;
-	} else {
-		bp = new_buf + (buf_size - 1);
-		n = buf_size + 1;
-		buf = new_buf;
-		buf_size = new_size;
-	}
-  }
-}
-
-
-/* map_nocase - map a line down to lowercase letters only.
- * bad points:	assumes line gotten from get_line.
- *		there is more than A-Z you say?
- */
-
-static char *map_nocase(line)
-char *line;
-{
-  static char *mapped=(char*)0;
-  static size_t map_size = 0;
-  char *mp;
-
-  if (map_size < buf_size) {
-	if ((mapped=realloc(mapped,map_size=buf_size)) == NULL) {
-		fprintf(stderr,"%s: not enough memory\n",program);
-		exit(FAILURE);
-	}
-  }
-
-  mp = mapped;
-  do {
-	*mp++ = uppercase(*line) ? downcase(*line) : *line;
-  } while (*line++ != '\0');
-
-  return mapped;
-}
-
-/* In basic regular expressions, the characters ?, +, |, (, and )
-   are taken literally; use the backslashed versions for RE operators.
-   In v8 regular expressions, things are the other way round, so
-   we have to swap those characters and their backslashed versions.
-*/
-static void tov8(char *v8, char *basic)
-{
-  while (*basic) switch (*basic)
-  {
-    case '?':
-    case '+':
-    case '|':
-    case '(':
-    case ')':        
-    {        
-      *v8++='\\';
-      *v8++=*basic++;
-      break;
-    }                    
-    case '\\':
-    {
-      switch (*(basic+1))
-      {
-        case '?':
-        case '+':
-        case '|':
-        case '(': 
-        case ')':
-        {
-          *v8++=*++basic;
-          ++basic;
-          break;
-        }
-        case '\0':
-        {
-          *v8++=*basic++;
-          break;
-        }
-        default:
-        {       
-          *v8++=*basic++;
-          *v8++=*basic++;
-        }                
-      }     
-      break;
-    }       
-    default:
-    {
-      *v8++=*basic++;
-    }                
-  }   
-  *v8++='\0';
-}
-
-/* Regular expression code calls this routine to print errors. */
-
-void regerror(s)
-const char *s;
-{
-  rerr=s;
-}
Index: trunk/minix/commands/simple/head.c
===================================================================
--- trunk/minix/commands/simple/head.c	(revision 9)
+++ 	(revision )
@@ -1,78 +1,0 @@
-/* head - print the first few lines of a file	Author: Andy Tanenbaum */
-
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#define DEFAULT 10
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void do_file, (int n, FILE *f));
-_PROTOTYPE(void usage, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  FILE *f;
-  int n, k, nfiles;
-  char *ptr;
-
-  /* Check for flag.  Only flag is -n, to say how many lines to print. */
-  k = 1;
-  ptr = argv[1];
-  n = DEFAULT;
-  if (argc > 1 && *ptr++ == '-') {
-	k++;
-	n = atoi(ptr);
-	if (n <= 0) usage();
-  }
-  nfiles = argc - k;
-
-  if (nfiles == 0) {
-	/* Print standard input only. */
-	do_file(n, stdin);
-	exit(0);
-  }
-
-  /* One or more files have been listed explicitly. */
-  while (k < argc) {
-	if (nfiles > 1) printf("==> %s <==\n", argv[k]);
-	if ((f = fopen(argv[k], "r")) == NULL)
-		fprintf(stderr, "%s: cannot open %s: %s\n",
-			argv[0], argv[k], strerror(errno));
-	else {
-		do_file(n, f);
-		fclose(f);
-	}
-	k++;
-	if (k < argc) printf("\n");
-  }
-  return(0);
-}
-
-
-
-void do_file(n, f)
-int n;
-FILE *f;
-{
-  int c;
-
-  /* Print the first 'n' lines of a file. */
-  while (n) switch (c = getc(f)) {
-	    case EOF:
-		return;
-	    case '\n':
-		--n;
-	    default:	putc((char) c, stdout);
-	}
-}
-
-
-void usage()
-{
-  fprintf(stderr, "Usage: head [-n] [file ...]\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/host.c
===================================================================
--- trunk/minix/commands/simple/host.c	(revision 9)
+++ 	(revision )
@@ -1,1410 +1,0 @@
-/*
- * Copyright (c) 1986 Regents of the University of California
- * All Rights Reserved
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that this notice is preserved and that due credit is given
- * to the University of California at Berkeley. The name of the University
- * may not be used to endorse or promote products derived from this
- * software without specific prior written permission. This software
- * is provided ``as is'' without express or implied warranty.
- */
-
-/*
- * Actually, this program is from Rutgers University, however it is 
- * based on nslookup and other pieces of named tools, so it needs
- * that copyright notice.
- */
-
-#if _MINIX
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <net/hton.h>
-#include <net/netlib.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/netdb.h>
-#include <net/gen/nameser.h>
-#include <net/gen/resolv.h>
-#include <net/gen/socket.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-
-#undef ERROR
-#else
-#include <stdio.h>
-#include <sys/types.h>
-#include <arpa/nameser.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <resolv.h>
-#include <sys/param.h>
-#include <strings.h>
-#include <ctype.h>
-#endif
-
-extern int h_errno;
-
-#define NUMMX 50
-
-#define  SUCCESS		0
-#define  TIME_OUT		-1
-#define  NO_INFO 		-2
-#define  ERROR 			-3
-#define  NONAUTH 		-4
-
-#define NAME_LEN 256
-
-#ifndef T_TXT
-#define T_TXT 16
-#endif
-#ifndef NO_DATA
-#define NO_DATA NO_ADDRESS
-#endif
-#ifndef C_HS
-#define C_HS 4
-#endif
-
-FILE *filePtr;
-
-struct state orig;
-extern struct state _res;
-static u8_t *cname = NULL;
-int getclass = C_IN;
-int gettype, getdeftype = T_A;
-int verbose = 0;
-int list = 0;
-int server_specified = 0;
-
-union querybuf;
-
-int main _ARGS(( int c, char *v[] ));
-
-static int parsetype _ARGS(( char *s ));
-static int parseclass _ARGS(( char *s ));
-static void hperror _ARGS(( int errno ));
-static void printanswer _ARGS(( struct hostent *hp ));
-static int ListHosts _ARGS(( char *namePtr, int queryType ));
-static int gethostinfo _ARGS(( char *name ));
-static int getdomaininfo _ARGS(( char *name, char *domain ));
-static int getinfo _ARGS(( char *name, char *domain, int type ));
-static int printinfo _ARGS(( union querybuf *answer, u8_t *eom, int filter, 
-								int isls ));
-static char *DecodeError _ARGS(( int result ));
-static u8_t *pr_rr _ARGS(( u8_t *cp, u8_t *msg, FILE *file, int filter ));
-static u8_t * pr_cdname _ARGS(( u8_t *cp, u8_t *msg, u8_t *name, int namelen ));
-static char *pr_class _ARGS(( int class ));
-static char *pr_type _ARGS(( int type ));
-static int tcpip_writeall _ARGS(( int fd, char *buf, unsigned siz ));
-
-int
-main(c, v)
-	char **v;
-{
-	char *domain;
-	ipaddr_t addr;
-	register struct hostent *hp;
-	register char *s, *p;
-	register inverse = 0;
-	register waitmode = 0;
-	u8_t *oldcname;
-	int ncnames;
-	int isaddr;
-
-	res_init();
-	_res.retrans = 5;
-
-	if (c < 2) {
-		fprintf(stderr, "Usage: host [-w] [-v] [-r] [-d] [-V] [-t querytype] [-c class] [-a] host [server]\n  -w to wait forever until reply\n  -v for verbose output\n  -r to disable recursive processing\n  -d to turn on debugging output\n  -t querytype to look for a specific type of information\n  -c class to look for non-Internet data\n  -a is equivalent to '-v -t *'\n  -V to always use a virtual circuit\n");
-		exit(1);
-	}
-	while (c > 2 && v[1][0] == '-') {
-		if (strcmp (v[1], "-w") == 0) {
-			_res.retry = 1;
-			_res.retrans = 15;
-			waitmode = 1;
-			v++;
-			c--;
-		}
-		else if (strcmp (v[1], "-r") == 0) {
-			_res.options &= ~RES_RECURSE;
-			v++;
-			c--;
-		}
-		else if (strcmp (v[1], "-d") == 0) {
-			_res.options |= RES_DEBUG;
-			v++;
-			c--;
-		}
-		else if (strcmp (v[1], "-v") == 0) {
-			verbose = 1;
-			v++;
-			c--;
-		}
-		else if (strcmp (v[1], "-l") == 0) {
-			list = 1;
-			v++;
-			c--;
-		}
-		else if (strncmp (v[1], "-t", 2) == 0) {
-			v++;
-			c--;
-			gettype = parsetype(v[1]);
-			v++;
-			c--;
-		}
-		else if (strncmp (v[1], "-c", 2) == 0) {
-			v++;
-			c--;
-			getclass = parseclass(v[1]);
-			v++;
-			c--;
-		}
-		else if (strcmp (v[1], "-a") == 0) {
-			verbose = 1;
-			gettype = T_ANY;
-			v++;
-			c--;
-		}		
-		else if (strcmp (v[1], "-V") == 0) {
-			_res.options |= RES_USEVC;
-			v++;
-			c--;
-		}
-        }
-	if (c > 2) {
-		s = v[2];
-		server_specified++;
-		
-		if ((p = strchr(s, ':')) != NULL) *p++ = 0;
-		isaddr = inet_aton(s, &addr);
-		if (p != NULL) p[-1] = ':';
-		if (!isaddr) {
-		  hp = gethostbyname(s);
-		  if (hp == NULL) {
-		    fprintf(stderr,"Error in looking up server name:\n");
-		    hperror(h_errno);
-		    exit(1);
-		  }
-		  _res.nsaddr= *(ipaddr_t *)hp->h_addr;
-		  printf("Using domain server:\n");
-		  printanswer(hp);
-		}
-		else {
-		  _res.nsaddr_list[0]= addr;
-		  _res.nsport_list[0]= htons(NAMESERVER_PORT);
-		  printf("Using domain server %s",
-			 inet_ntoa(_res.nsaddr));
-		  if (p != NULL) {
-		    printf(" on port %d", atoi(p));
-		    _res.nsport_list[0]= htons(atoi(p));
-		  }
-		  printf(":\n");
-		}
-	      }
-	domain = v[1];
-	if (strcmp (domain, ".") != 0 && inet_aton(domain, &addr)) {
-	  static char ipname[sizeof("255.255.255.255.in-addr.arpa.")];
-	  sprintf(ipname, "%d.%d.%d.%d.in-addr.arpa.",
-	    ((unsigned char *) &addr)[3],
-	    ((unsigned char *) &addr)[2],
-	    ((unsigned char *) &addr)[1],
-	    ((unsigned char *) &addr)[0]);
-	  domain = ipname;
-	  getdeftype = T_PTR;
-	}
-
-	hp = NULL;
-	h_errno = TRY_AGAIN;
-/*
- * we handle default domains ourselves, thank you
- */
-	_res.options &= ~RES_DEFNAMES;
-
-        if (list)
-	  exit(ListHosts(domain, gettype ? gettype : getdeftype));
-	oldcname = NULL;
-	ncnames = 5;
-	while (hp == NULL && h_errno == TRY_AGAIN) {
-	  cname = NULL;
-	  if (oldcname == NULL)
-	    hp = (struct hostent *)gethostinfo(domain);
-	  else
-	    hp = (struct hostent *)gethostinfo((char *)oldcname);
-	  if (cname) {
-	    if (ncnames-- == 0) {
-	      printf("Too many cnames.  Possible loop.\n");
-	      exit(1);
-	    }
-	    oldcname = cname;
-	    hp = NULL;
-	    h_errno = TRY_AGAIN;
-	    continue;
-	  }
-	  if (!waitmode)
-	    break;
-	}
-
-	if (hp == NULL) {
-	  hperror(h_errno);
-	  exit(1);
-	}
-
-	exit(0);
-
-}
-
-static int
-parsetype(s)
-	char *s;
-{
-if (strcmp(s,"a") == 0)
-  return(1);
-if (strcmp(s,"ns") == 0)
-  return(2);
-if (strcmp(s,"md") == 0)
-  return(3);
-if (strcmp(s,"mf") == 0)
-  return(4);
-if (strcmp(s,"cname") == 0)
-  return(5);
-if (strcmp(s,"soa") == 0)
-  return(6);
-if (strcmp(s,"mb") == 0)
-  return(7);
-if (strcmp(s,"mg") == 0)
-  return(8);
-if (strcmp(s,"mr") == 0)
-  return(9);
-if (strcmp(s,"null") == 0)
-  return(10);
-if (strcmp(s,"wks") == 0)
-  return(11);
-if (strcmp(s,"ptr") == 0)
-  return(12);
-if (strcmp(s,"hinfo") == 0)
-  return(13);
-if (strcmp(s,"minfo") == 0)
-  return(14);
-if (strcmp(s,"mx") == 0)
-  return(15);
-if (strcmp(s,"txt") == 0)	/* Roy */
-  return(T_TXT);		/* Roy */
-if (strcmp(s,"uinfo") == 0)
-  return(100);
-if (strcmp(s,"uid") == 0)
-  return(101);
-if (strcmp(s,"gid") == 0)
-  return(102);
-if (strcmp(s,"unspec") == 0)
-  return(103);
-if (strcmp(s,"any") == 0)
-  return(255);
-if (strcmp(s,"*") == 0)
-  return(255);
-if (atoi(s))
-  return(atoi(s));
-fprintf(stderr, "Invalid query type: %s\n", s);
-exit(2);
-}
-
-static int
-parseclass(s)
-	char *s;
-{
-if (strcmp(s,"in") == 0)
-  return(C_IN);
-if (strcmp(s,"chaos") == 0)
-  return(C_CHAOS);
-if (strcmp(s,"hs") == 0)
-  return(C_HS);
-if (strcmp(s,"any") == 0)
-  return(C_ANY);
-if (atoi(s))
-  return(atoi(s));
-fprintf(stderr, "Invalid query class: %s\n", s);
-exit(2);
-}
-
-static void
-printanswer(hp)
-	register struct hostent *hp;
-{
-	register char **cp;
-	register ipaddr_t **hptr;
-
-	printf("Name: %s\n", hp->h_name);
-	printf("Address:");
-	for (hptr = (ipaddr_t **)hp->h_addr_list; *hptr; hptr++)
-	  printf(" %s", inet_ntoa(*(ipaddr_t *)*hptr));
-	printf("\nAliases:");
-	for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
-		printf(" %s", *cp);
-	printf("\n\n");
-}
-
-static void
-hperror(errno) 
-int errno;
-{
-switch(errno) {
-	case HOST_NOT_FOUND:
-		fprintf(stderr,"Host not found.\n");
-		break;
-	case TRY_AGAIN:
-		fprintf(stderr,"Host not found, try again.\n");
-		break;
-	case NO_RECOVERY:
-		fprintf(stderr,"No recovery, Host not found.\n");
-		break;
-	case NO_ADDRESS:
-		fprintf(stderr,"There is an entry for this host, but it doesn't have what you requested.\n");
-		break;
-	}
-}
-
-
-typedef union querybuf {
-	dns_hdr_t qb1;
-	u8_t qb2[PACKETSZ];
-} querybuf_t;
-
-static u8_t hostbuf[BUFSIZ+1];
-
-
-static int
-gethostinfo(name)
-	char *name;
-{
-	register char *cp, **domain;
-	int n;
-	int hp;
-	int nDomain;
-
-	if (strcmp(name, ".") == 0)
-		return(getdomaininfo(name, NULL));
-	for (cp = name, n = 0; *cp; cp++)
-		if (*cp == '.')
-			n++;
-	if (n && cp[-1] == '.') {
-		if (cp[-1] == '.')
-			cp[-1] = 0;
-		hp = getdomaininfo(name, (char *)NULL);
-		if (cp[-1] == 0)
-			cp[-1] = '.';
-		return (hp);
-	}
-	if (n == 0 && (cp = __hostalias(name))) {
-	        if (verbose)
-		    printf("Aliased to \"%s\"\n", cp);
-		_res.options |= RES_DEFNAMES;	  
-		return (getdomaininfo(cp, (char *)NULL));
-	}
-#ifdef MAXDS
-	for (nDomain = 0;
-	     _res.defdname_list[nDomain][0] != 0;
-	     nDomain++) {
-	    for (domain = _res.dnsrch_list[nDomain]; *domain; domain++) {
-	        if (verbose)
-		    printf("Trying domain \"%s\"\n", *domain);
-		hp = getdomaininfo(name, *domain);
-		if (hp)
-			return (hp);
-	    }
-	}
-#else
-	for (domain = _res.dnsrch; *domain; domain++) {
-	  if (verbose)
-	    printf("Trying domain \"%s\"\n", *domain);
-	  hp = getdomaininfo(name, *domain);
-	  if (hp)
-	    return (hp);
-	}
-#endif
-	if (h_errno != HOST_NOT_FOUND ||
-	   (_res.options & RES_DNSRCH) == 0)
-		return (0);
-	if (verbose)
-	    printf("Trying null domain\n");
-	return (getdomaininfo(name, (char *)NULL));
-}
-
-static int
-getdomaininfo(name, domain)
-	char *name, *domain;
-{
-  return getinfo(name, domain, gettype ? gettype : getdeftype);
-}
-
-static int
-getinfo(name, domain, type)
-	char *name, *domain;
-{
-
-	dns_hdr_t *hp;
-	u8_t *eom, *bp, *cp;
-	querybuf_t buf, answer;
-	int n, n1, i, j, nmx, ancount, nscount, arcount, qdcount, buflen;
-	u_short pref, class;
-	char host[2*MAXDNAME+2];
-
-	if (domain == NULL)
-		(void)sprintf(host, "%.*s", MAXDNAME, name);
-	else
-		(void)sprintf(host, "%.*s.%.*s", MAXDNAME, name, MAXDNAME, domain);
-
-	n = res_mkquery(QUERY, host, getclass, type, (char *)NULL, 0, NULL,
-		(char *)&buf, sizeof(buf));
-	if (n < 0) {
-		if (_res.options & RES_DEBUG)
-			printf("res_mkquery failed\n");
-		h_errno = NO_RECOVERY;
-		return(0);
-	}
-	n = res_send((char *)&buf, n, (char *)&answer, sizeof(answer));
-	if (n < 0) {
-		if (_res.options & RES_DEBUG)
-			printf("res_send failed\n");
-		h_errno = TRY_AGAIN;
-		return (0);
-	}
-	eom = (u8_t *)&answer + n;
-	return(printinfo(&answer, eom, T_ANY, 0));
-}
-
-static int
-printinfo(answer, eom, filter, isls)
-	querybuf_t *answer;
-	u8_t *eom;
-        int filter;
-        int isls;
-{
-	dns_hdr_t *hp;
-	u8_t *bp, *cp;
-	int n, n1, i, j, nmx, ancount, nscount, arcount, qdcount, buflen;
-	u_short pref, class;
-
-	/*
-	 * find first satisfactory answer
-	 */
-	hp = (dns_hdr_t *) answer;
-	ancount = ntohs(hp->dh_ancount);
-	qdcount = ntohs(hp->dh_qdcount);
-	nscount = ntohs(hp->dh_nscount);
-	arcount = ntohs(hp->dh_arcount);
-	if (_res.options & RES_DEBUG || (verbose && isls == 0))
-		printf("rcode = %d (%s), ancount=%d\n", 
-		       hp->dh_flag2 & DHF_RCODE,
-		       DecodeError(hp->dh_flag2 & DHF_RCODE), ancount);
-	if (hp->dh_flag2 & DHF_RCODE != NOERROR || 
-		(ancount+nscount+arcount) == 0) {
-		switch (hp->dh_flag2 & DHF_RCODE) {
-			case NXDOMAIN:
-				/* Check if it's an authoritive answer */
-				if (hp->dh_flag1 & DHF_AA) {
-					h_errno = HOST_NOT_FOUND;
-					return(0);
-				} else {
-					h_errno = TRY_AGAIN;
-					return(0);
-				}
-			case SERVFAIL:
-				h_errno = TRY_AGAIN;
-				return(0);
-#ifdef OLDJEEVES
-			/*
-			 * Jeeves (TOPS-20 server) still does not
-			 * support MX records.  For the time being,
-			 * we must accept FORMERRs as the same as
-			 * NOERROR.
-			 */
-			case FORMERR:
-#endif /* OLDJEEVES */
-			case NOERROR:
-/* TpB - set a return error for this case. NO_DATA */
-				h_errno = NO_DATA;
-				return(0); /* was 1,but now indicates exception */
-#ifndef OLDJEEVES
-			case FORMERR:
-#endif /* OLDJEEVES */
-			case NOTIMP:
-			case REFUSED:
-				h_errno = NO_RECOVERY;
-				return(0);
-		}
-		return (0);
-	}
-	bp = hostbuf;
-	nmx = 0;
-	buflen = sizeof(hostbuf);
-	cp = (u8_t *)answer + sizeof(dns_hdr_t);
-	if (qdcount) {
-		cp += dn_skipname((u8_t *)cp,(u8_t *)eom) + QFIXEDSZ;
-		while (--qdcount > 0)
-			cp += dn_skipname((u8_t *)cp,(u8_t *)eom) + QFIXEDSZ;
-	}
-	if (ancount) {
-	  if (!(hp->dh_flag1 & DHF_AA))
-	    if (verbose && isls == 0)
-	      printf("The following answer is not authoritative:\n");
-	  while (--ancount >= 0 && cp && cp < eom) {
-	    cp = pr_rr(cp, (u8_t *)answer, stdout, filter);
-/*
- * When we ask for address and there is a CNAME, it seems to return
- * both the CNAME and the address.  Since we trace down the CNAME
- * chain ourselves, we don't really want to print the address at
- * this point.
- */
-	    if (cname && ! verbose)
-	      return (1);
-	  }
-	}
-	if (! verbose)
-	  return (1);
-	if (nscount) {
-	  printf("For authoritative answers, see:\n");
-	  while (--nscount >= 0 && cp && cp < eom) {
-	    cp = pr_rr(cp, (u8_t *)answer, stdout, filter);
-	  }
-	}
-	if (arcount) {
-	  printf("Additional information:\n");
-	  while (--arcount >= 0 && cp && cp < eom) {
-	    cp = pr_rr(cp, (u8_t *)answer, stdout, filter);
-	  }
-	}
-	return(1);
- }
-
-static u8_t cnamebuf[MAXDNAME];
-
-/*
- * Print resource record fields in human readable form.
- */
-static u8_t *
-pr_rr(cp, msg, file, filter)
-	u8_t *cp, *msg;
-	FILE *file;
-        int filter;
-{
-	int type, class, dlen, n, c, proto, ttl;
-	ipaddr_t inaddr;
-	u8_t *cp1;
-	struct protoent *protop;
-	struct servent *servp;
-	char punc;
-	int doprint;
-	u8_t name[MAXDNAME];
-
-	if ((cp = pr_cdname(cp, msg, name, sizeof(name))) == NULL)
-		return (NULL);			/* compression error */
-
-	type = _getshort(cp);
-	cp += sizeof(u_short);
-
-	class = _getshort(cp);
-	cp += sizeof(u_short);
-
-	ttl = _getlong(cp);
-	cp += sizeof(u_long);
-
-	if (filter == type || filter == T_ANY ||
-	    (filter == T_A && (type == T_PTR || type == T_NS)))
-	  doprint = 1;
-	else
-	  doprint = 0;
-
-	if (doprint)
-	  if (verbose)
-	    fprintf(file,"%s\t%d%s\t%s",
-		    name, ttl, pr_class(class), pr_type(type));
-	  else
-	    fprintf(file,"%s%s %s",name, pr_class(class), pr_type(type));
-	if (verbose)
-	  punc = '\t';
-	else
-	  punc = ' ';
-
-	dlen = _getshort(cp);
-	cp += sizeof(u_short);
-	cp1 = cp;
-	/*
-	 * Print type specific data, if appropriate
-	 */
-	switch (type) {
-	case T_A:
-		switch (class) {
-		case C_IN:
-			bcopy((char *)cp, (char *)&inaddr, sizeof(inaddr));
-			if (dlen == 4) {
-			        if (doprint)
-				  fprintf(file,"%c%s", punc,
-					inet_ntoa(inaddr));
-				cp += dlen;
-			} else if (dlen == 7) {
-			        if (doprint) {
-				  fprintf(file,"%c%s", punc,
-					  inet_ntoa(inaddr));
-				  fprintf(file,", protocol = %d", cp[4]);
-				  fprintf(file,", port = %d",
-					  (cp[5] << 8) + cp[6]);
-				}
-				cp += dlen;
-			}
-			break;
-		}
-		break;
-	case T_CNAME:
-		if (dn_expand(msg, msg + 512, cp, cnamebuf, 
-			      sizeof(cnamebuf)-1) >= 0) {
-			strcat((char *) cnamebuf, ".");
-			if (gettype != T_CNAME && gettype != T_ANY)
-				cname = cnamebuf;				
-		}
-	case T_MB:
-#ifdef OLDRR
-	case T_MD:
-	case T_MF:
-#endif /* OLDRR */
-	case T_MG:
-	case T_MR:
-	case T_NS:
-	case T_PTR:
-		cp = pr_cdname(cp, msg, name, sizeof(name));
-		if (doprint)
-		  fprintf(file,"%c%s",punc, name);
-		break;
-
-	case T_HINFO:
-		if (n = *cp++) {
-			if (doprint)
-			  fprintf(file,"%c%.*s", punc, n, cp);
-			cp += n;
-		}
-		if (n = *cp++) {
-			if (doprint)
-			  fprintf(file,"%c%.*s", punc, n, cp);
-			cp += n;
-		}
-		break;
-
-	case T_SOA:
-		cp = pr_cdname(cp, msg, name, sizeof(name));
-		if (doprint)
-		  fprintf(file,"\t%s", name);
-		cp = pr_cdname(cp, msg, name, sizeof(name));
-		if (doprint)
-		  fprintf(file," %s", name);
-		if (doprint)
-		  fprintf(file,"(\n\t\t\t%ld\t;serial (version)", _getlong(cp));
-		cp += sizeof(u_long);
-		if (doprint)
-		  fprintf(file,"\n\t\t\t%ld\t;refresh period", _getlong(cp));
-		cp += sizeof(u_long);
-		if (doprint)
-		  fprintf(file,"\n\t\t\t%ld\t;retry refresh this often", _getlong(cp));
-		cp += sizeof(u_long);
-		if (doprint)
-		  fprintf(file,"\n\t\t\t%ld\t;expiration period", _getlong(cp));
-		cp += sizeof(u_long);
-		if (doprint)
-		  fprintf(file,"\n\t\t\t%ld\t;minimum TTL\n\t\t\t)", _getlong(cp));
-		cp += sizeof(u_long);
-		break;
-
-	case T_MX:
-		if (doprint)
-		  if (verbose)
-		    fprintf(file,"\t%d ",_getshort(cp));
-		  else
-		    fprintf(file," (pri=%d) by ",_getshort(cp));
-		cp += sizeof(u_short);
-		cp = pr_cdname(cp, msg, name, sizeof(name));
-		if (doprint)
-		  fprintf(file, "%s", name);
-		break;
-
-	case T_MINFO:
-		cp = pr_cdname(cp, msg, name, sizeof(name));
-		if (doprint)
-		  fprintf(file,"%c%s",punc, name);
-		cp = pr_cdname(cp, msg, name, sizeof(name));
-		if (doprint)
-		  fprintf(file," %s", name);
-		break;
-
-		/* Roy start */
-	case T_TXT:
-		if (n = *cp++) {
-			if (doprint)
-			  fprintf(file,"%c%.*s", punc, n, cp);
-			cp += n;
-		}
-		break;
-		/* Roy end */
-
-	case T_UINFO:
-		if (doprint)
-		  fprintf(file,"%c%s", punc, cp);
-		cp += dlen;
-		break;
-
-	case T_UID:
-	case T_GID:
-		if (dlen == 4) {
-			if (doprint)
-			  fprintf(file,"%c%ld", punc, _getlong(cp));
-			cp += sizeof(int);
-		}
-		break;
-
-	case T_WKS:
-		if (dlen < sizeof(u_long) + 1)
-			break;
-		bcopy((char *)cp, (char *)&inaddr, sizeof(inaddr));
-		cp += sizeof(u_long);
-		proto = *cp++;
-		protop = getprotobynumber(proto);
-		if (doprint)
-		  if (protop)
-		    fprintf(file,"%c%s %s", punc,
-			    inet_ntoa(inaddr), protop->p_name);
-		  else
-		    fprintf(file,"%c%s %d", punc,
-			    inet_ntoa(inaddr), proto);
-
-		n = 0;
-		while (cp < cp1 + dlen) {
-			c = *cp++;
-			do {
- 				if (c & 0200) {
-				  servp = NULL;
-				  if (protop)
-				    servp = getservbyport (htons(n),
-							   protop->p_name);
-				  if (doprint)
-				    if (servp)
-				      fprintf(file, " %s", servp->s_name);
-				    else
-				      fprintf(file, " %d", n);
-				}
- 				c <<= 1;
-			} while (++n & 07);
-		}
-		break;
-
-	default:
-		if (doprint)
-		  fprintf(file,"%c???", punc);
-		cp += dlen;
-	}
-	if (cp != cp1 + dlen)
-		fprintf(file,"packet size error (%#x != %#x)\n", cp, cp1+dlen);
-	if (doprint)
-	  fprintf(file,"\n");
-	return (cp);
-}
-
-static	char nbuf[20];
-
-/*
- * Return a string for the type
- */
-static char *
-pr_type(type)
-	int type;
-{
-	switch (type) {
-	case T_A:
-		return(verbose? "A" : "has address");
-	case T_NS:		/* authoritative server */
-		return("NS");
-#ifdef OLDRR
-	case T_MD:		/* mail destination */
-		return("MD");
-	case T_MF:		/* mail forwarder */
-		return("MF");
-#endif /* OLDRR */
-	case T_CNAME:		/* connonical name */
-		return(verbose? "CNAME" : "is a nickname for");
-	case T_SOA:		/* start of authority zone */
-		return("SOA");
-	case T_MB:		/* mailbox domain name */
-		return("MB");
-	case T_MG:		/* mail group member */
-		return("MG");
-	case T_MX:		/* mail routing info */
-		return(verbose? "MX" : "mail is handled");
-	/* Roy start */
-	case T_TXT:		/* TXT - descriptive info */
-		return(verbose? "TXT" : "descriptive text");
-	/* Roy end */
-	case T_MR:		/* mail rename name */
-		return("MR");
-	case T_NULL:		/* null resource record */
-		return("NULL");
-	case T_WKS:		/* well known service */
-		return("WKS");
-	case T_PTR:		/* domain name pointer */
-		return("PTR");
-	case T_HINFO:		/* host information */
-		return("HINFO");
-	case T_MINFO:		/* mailbox information */
-		return("MINFO");
-	case T_AXFR:		/* zone transfer */
-		return("AXFR");
-	case T_MAILB:		/* mail box */
-		return("MAILB");
-	case T_MAILA:		/* mail address */
-		return("MAILA");
-	case T_ANY:		/* matches any type */
-		return("ANY");
-	case T_UINFO:
-		return("UINFO");
-	case T_UID:
-		return("UID");
-	case T_GID:
-		return("GID");
-	default:
-		return (sprintf(nbuf, "%d", type) == EOF ? NULL : nbuf);
-	}
-}
-
-/*
- * Return a mnemonic for class
- */
-static char *
-pr_class(class)
-	int class;
-{
-
-	switch (class) {
-	case C_IN:		/* internet class */
-		return(verbose? " IN" : "");
-	case C_CHAOS:		/* chaos class */
-		return(verbose? " CHAOS" : "");
-	case C_HS:		/* Hesiod class */
-		return(verbose? " HS" : "");
-	case C_ANY:		/* matches any class */
-		return(" ANY");
-	default:
-		return (sprintf(nbuf," %d", class) == EOF ? NULL : nbuf);
-	}
-}
-
-static u8_t *
-pr_cdname(cp, msg, name, namelen)
-	u8_t *cp, *msg;
-        u8_t *name;
-        int namelen;
-{
-	int n;
-
-	if ((n = dn_expand(msg, msg + 512, cp, name, namelen - 2)) < 0)
-		return (NULL);
-	if (name[0] == '\0') {
-		name[0] = '.';
-		name[1] = '\0';
-	}
-	return (cp + n);
-}
-
-char *resultcodes[] = {
-	"NOERROR",
-	"FORMERR",
-	"SERVFAIL",
-	"NXDOMAIN",
-	"NOTIMP",
-	"REFUSED",
-	"6",
-	"7",
-	"8",
-	"9",
-	"10",
-	"11",
-	"12",
-	"13",
-	"14",
-	"NOCHANGE",
-};
-
-
-
-
-/*
- ******************************************************************************
- *
- *  ListHosts --
- *
- *	Requests the name server to do a zone transfer so we
- *	find out what hosts it knows about.
- *
- *  Results:
- *	SUCCESS		the listing was successful.
- *	ERROR		the server could not be contacted because 
- *			a socket could not be obtained or an error
- *			occured while receiving, or the output file
- *			could not be opened.
- *
- ******************************************************************************
- */
-
-static int
-ListHosts(namePtr, queryType)
-    char *namePtr;
-    int  queryType;  /* e.g. T_A */
-{
-	querybuf_t 		buf, answer;
-	dns_hdr_t		*headerPtr;
-
-	int 			msglen;
-	int 			amtToRead;
-	int 			numRead;
-	int 			i;
-	int 			numAnswers = 0;
-	int 			result;
-	int 			soacnt = 0;
-	u_short 		len;
-	int			dlen;
-	int			type;
-	int			nscount;
-	u8_t 			*cp, *nmp;
-	u8_t 			name[NAME_LEN];
-	char 			dname[2][NAME_LEN];
-	u8_t 			domain[NAME_LEN];
-/* names and addresses of name servers to try */
-#define NUMNS 8
-	char			nsname[NUMNS][NAME_LEN];
-	int			nshaveaddr[NUMNS];
-#define IPADDRSIZE 4
-#define NUMNSADDR 16
-	char	 		nsipaddr[NUMNSADDR][IPADDRSIZE];
-	int			numns;
-	int			numnsaddr;
-	int			thisns;
-	struct hostent		*hp;
-	enum {
-	    NO_ERRORS, 
-	    ERR_READING_LEN, 
-	    ERR_READING_MSG,
-	    ERR_PRINTING
-	} error = NO_ERRORS;
-	char *tcp_serv_name;
-	int tcp_fd;
-	nwio_tcpconf_t tcpconf;
-	nwio_tcpcl_t clopt;
-	int terrno;
-
-/*
- * normalize to not have trailing dot.  We do string compares below
- * of info from name server, and it won't have trailing dots.
- */
-	i = strlen(namePtr);
-	if (namePtr[i-1] == '.')
-	  namePtr[i-1] = 0;
-
-	if (server_specified) {
-	  bcopy((char *)&_res.nsaddr, nsipaddr[0], IPADDRSIZE);
-	  numnsaddr = 1;
-	}
-	else {
-
-/*
- * First we have to find out where to look.  This needs a NS query,
- * possibly followed by looking up addresses for some of the names.
- */
-
-	msglen = res_mkquery(QUERY, namePtr, C_IN, T_NS,
-				(char *)0, 0, (struct rrec *)0, 
-				(char *)&buf, sizeof(buf));
-
-	if (msglen < 0) {
-		printf("res_mkquery failed\n");
-		return (ERROR);
-	}
-
-	msglen = res_send((char *)&buf,msglen,(char *)&answer, sizeof(answer));
-	
-	if (msglen < 0) {
-		printf("Unable to get to nameserver -- try again later\n");
-		return (ERROR);
-	}
-	if (_res.options & RES_DEBUG || verbose)
-		printf("rcode = %d (%s), ancount=%d\n", 
-		       answer.qb1.dh_flag2 & DHF_RCODE,
-		       DecodeError(answer.qb1.dh_flag2 & DHF_RCODE),
-		       ntohs(answer.qb1.dh_ancount));
-
-/*
- * Analyze response to our NS lookup
- */
-
-	nscount = ntohs(answer.qb1.dh_ancount) + ntohs(answer.qb1.dh_nscount) +
-		  ntohs(answer.qb1.dh_arcount);
-
-	if (answer.qb1.dh_flag2 & DHF_RCODE != NOERROR || nscount == 0) {
-		switch (answer.qb1.dh_flag2 & DHF_RCODE) {
-			case NXDOMAIN:
-				/* Check if it's an authoritive answer */
-				if (answer.qb1.dh_flag1 & DHF_AA) {
-					printf("No such domain\n");
-				} else {
-					printf("Unable to get information about domain -- try again later.\n");
-				}
-				break;
-			case SERVFAIL:
-				printf("Unable to get information about that domain -- try again later.\n");
-				break;
-			case NOERROR:
-				printf("That domain exists, but seems to be a leaf node.\n");
-				break;
-			case FORMERR:
-			case NOTIMP:
-			case REFUSED:
-				printf("Unrecoverable error looking up domain name.\n");
-				break;
-		}
-		return (0);
-	}
-
-	cp = answer.qb2 + sizeof(dns_hdr_t);
-	if (ntohs(answer.qb1.dh_qdcount) > 0)
-	  cp += dn_skipname(cp, answer.qb2 + msglen) + QFIXEDSZ;
-
-	numns = 0;
-	numnsaddr = 0;
-
-/*
- * Look at response from NS lookup for NS and A records.
- */
-
-	for (;nscount; nscount--) {
-	  cp += dn_expand(answer.qb2, answer.qb2 + msglen, cp,
-			  domain, sizeof(domain));
-	  type = _getshort(cp);
-	  cp += sizeof(u_short) + sizeof(u_short) + sizeof(u_long);
-	  dlen = _getshort(cp);
-	  cp += sizeof(u_short);
-	  if (type == T_NS) {
-	    if (dn_expand(answer.qb2, answer.qb2 + msglen, cp, 
-			  name, sizeof(name)) >= 0) {
-	      if (numns < NUMNS && strcasecmp((char *)domain, namePtr) == 0) {
-		for (i = 0; i < numns; i++)
-		  if (strcasecmp(nsname[i], (char *)name) == 0)
-		    break;  /* duplicate */
-		if (i >= numns) {
-		  strncpy(nsname[numns], (char *)name, sizeof(name));
-		  nshaveaddr[numns] = 0;
-		  numns++;
-		}
-	      }
-	    }
-	  }
-	  else if (type == T_A) {
-	    if (numnsaddr < NUMNSADDR)
-	      for (i = 0; i < numns; i++) {
-		if (strcasecmp(nsname[i], (char *)domain) == 0) {
-		  nshaveaddr[i]++;
-		  bcopy((char *)cp, nsipaddr[numnsaddr],IPADDRSIZE);
-		  numnsaddr++;
-		  break;
-		}
-	      }
-	  }
-	  cp += dlen;
-	}
-
-/*
- * Usually we'll get addresses for all the servers in the additional
- * info section.  But in case we don't, look up their addresses.
- */
-
-	for (i = 0; i < numns; i++) {
-	  if (! nshaveaddr[i]) {
-	    register long **hptr;
-	    int numaddrs = 0;
-
-	    hp = gethostbyname(nsname[i]);
-	    if (hp) {
-	      for (hptr = (long **)hp->h_addr_list; *hptr; hptr++)
-		if (numnsaddr < NUMNSADDR) {
-		  bcopy((char *)*hptr, nsipaddr[numnsaddr],IPADDRSIZE);
-		  numnsaddr++;
-		  numaddrs++;
-		}
-	    }
-	    if (_res.options & RES_DEBUG || verbose)
-	      printf("Found %d addresses for %s by extra query\n",
-		     numaddrs, nsname[i]);
-	  }
-	  else
-	    if (_res.options & RES_DEBUG || verbose)
-	      printf("Found %d addresses for %s\n",
-		     nshaveaddr[i], nsname[i]);
-	}
-        }
-/*
- * Now nsipaddr has numnsaddr addresses for name servers that
- * serve the requested domain.  Now try to find one that will
- * accept a zone transfer.
- */
-
-	thisns = 0;
-
-again:
-
-	numAnswers = 0;
-	soacnt = 0;
-
-	/*
-	 *  Create a query packet for the requested domain name.
-	 *
-	 */
-	msglen = res_mkquery(QUERY, namePtr, getclass, T_AXFR,
-				(char *)0, 0, (struct rrec *)0, 
-				(char *) &buf, sizeof(buf));
-	if (msglen < 0) {
-	    if (_res.options & RES_DEBUG) {
-		fprintf(stderr, "ListHosts: Res_mkquery failed\n");
-	    }
-	    return (ERROR);
-	}
-
-	/*
-	 *  Set up a virtual circuit to the server.
-	 */
-
-	tcp_serv_name= getenv("TCP_DEVICE");
-	if (!tcp_serv_name)
-		tcp_serv_name= TCP_DEVICE;
-	for (;thisns < numnsaddr; thisns++) 
-	{
-		tcp_fd= open(tcp_serv_name, O_RDWR);
-		if (tcp_fd == -1)
-		{
-			fprintf(stderr, "unable to open '%s': %s\n", tcp_serv_name,
-				strerror(errno));
-			return ERROR;
-		}
-
-		tcpconf.nwtc_flags= NWTC_EXCL | NWTC_LP_SEL | NWTC_SET_RA | 
-								NWTC_SET_RP;
-		tcpconf.nwtc_remaddr= *(ipaddr_t *)nsipaddr[thisns];
-		tcpconf.nwtc_remport= _res.nsport_list[0];
-		result= ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf);
-		if (result == -1)
-		{
-			fprintf(stderr, "tcp_ioc_setconf failed: %s\n", 
-				strerror(errno));
-			close(tcp_fd);
-			return ERROR;
-		}
-		if (_res.options & RES_DEBUG || verbose)
-			printf("Trying %s\n", inet_ntoa(tcpconf.nwtc_remaddr));
-		clopt.nwtcl_flags= 0;
-		result= ioctl(tcp_fd, NWIOTCPCONN, &clopt);
-		if (result == 0)
-			break;
-		terrno= errno;
-		if (verbose)
-			fprintf(stderr, 
-				"Connection failed, trying next server: %s\n",
-				strerror(errno));
-		close(tcp_fd);
-	}	
-	if (thisns >= numnsaddr) {
-	  printf("No server for that domain responded\n");
-	  if (!verbose)
-	    fprintf(stderr, "Error from the last server was: %s\n", 
-						strerror(terrno));
-	  return(ERROR);
-	}
-
-	/*
-	 * Send length & message for zone transfer 
-	 */
-
-        len = htons(msglen);
-
-	result= tcpip_writeall(tcp_fd, (char *)&len, sizeof(len));
-	if (result != sizeof(len))
-	{
-		fprintf(stderr, "write failed: %s\n", strerror(errno));
-		close(tcp_fd);
-		return ERROR;
-	}
-	result= tcpip_writeall(tcp_fd, (char *)&buf, msglen);
-	if (result != msglen)
-	{
-		fprintf(stderr, "write failed: %s\n",
-			strerror(errno));
-		close(tcp_fd);
-		return ERROR;
-	}
-	filePtr = stdout;
-
-	while (1) {
-
-	    /*
-	     * Read the length of the response.
-	     */
-
-	    cp = (u8_t *) &buf;
-	    amtToRead = sizeof(u_short);
-	    while(amtToRead > 0)
-	    {
-		result = read(tcp_fd, (char *)cp, amtToRead);
-		if (result <= 0)
-			break;
-		cp 	  += result;
-		amtToRead -= result;
-	    }
-	    if (amtToRead) {
-		error = ERR_READING_LEN;
-		break;
-	    }	
-
-	    if ((len = htons(*(u_short *)&buf)) == 0) {
-		break;	/* nothing left to read */
-	    }
-
-	    /*
-	     * Read the response.
-	     */
-
-	    amtToRead = len;
-	    cp = (u8_t *) &buf;
-	    while(amtToRead > 0)
-	    {
-		result = read(tcp_fd, (char *)cp, amtToRead);
-		if (result<= 0)
-			break;
-		cp 	  += result;
-		amtToRead -= result;
-	    }
-	    if (amtToRead) {
-		error = ERR_READING_MSG;
-		break;
-	    }
-
-	    i = buf.qb1.dh_flag2 & DHF_RCODE;
-	    if (i != NOERROR || ntohs(buf.qb1.dh_ancount) == 0) {
-	      if ((thisns+1) < numnsaddr &&
-		  (i == SERVFAIL || i == NOTIMP || i == REFUSED)) {
-		if (_res.options & RES_DEBUG || verbose)
-		  printf("Server failed, trying next server: %s\n",
-			 i != NOERROR ? 
-			 DecodeError(i) : "Premature end of data");
-		close(tcp_fd);
-		thisns++;
-		goto again;
-	      }
-	      printf("Server failed: %s\n",
-		     i != NOERROR ? DecodeError(i) : "Premature end of data");
-	      break;
-	    }
-
-
-	    result = printinfo(&buf, cp, queryType, 1);
-	    if (! result) {
-		error = ERR_PRINTING;
-		break;
-	    }
-	    numAnswers++;
-	    cp = buf.qb2 + sizeof(dns_hdr_t);
-	    if (ntohs(buf.qb1.dh_qdcount) > 0)
-		cp += dn_skipname(cp, buf.qb2 + len) + QFIXEDSZ;
-
-	    nmp = cp;
-	    cp += dn_skipname(cp, (u_char *)&buf + len);
-	    if ((_getshort(cp) == T_SOA)) {
-		dn_expand(buf.qb2, buf.qb2 + len, nmp, (u8_t *)dname[soacnt],
-			sizeof(dname[0]));
-	        if (soacnt) {
-		    if (strcmp(dname[0], dname[1]) == 0)
-			break;
-		} else
-		    soacnt++;
-	    }
-        }
-
-	close(tcp_fd);
-
-	switch (error) {
-	    case NO_ERRORS:
-		return (SUCCESS);
-
-	    case ERR_READING_LEN:
-		return(ERROR);
-
-	    case ERR_PRINTING:
-		fprintf(stderr,"*** Error during listing of %s: %s\n", 
-				namePtr, DecodeError(result));
-		return(result);
-
-	    case ERR_READING_MSG:
-		headerPtr = (dns_hdr_t *) &buf;
-		fprintf(stderr,"ListHosts: error receiving zone transfer:\n");
-		fprintf(stderr,
-	       "  result: %s, answers = %d, authority = %d, additional = %d\n", 
-		    	resultcodes[headerPtr->dh_flag2 & DHF_RCODE], 
-		    	ntohs(headerPtr->dh_ancount), 
-			ntohs(headerPtr->dh_nscount), 
-			ntohs(headerPtr->dh_arcount));
-		return(ERROR);
-	    default:
-		return(ERROR);
-	}
-}
-
-static char *
-DecodeError(result)
-    int result;
-{
-	switch(result) {
-	    case NOERROR: 	return("Success"); break;
-	    case FORMERR:	return("Format error"); break;
-	    case SERVFAIL:	return("Server failed"); break;
-	    case NXDOMAIN:	return("Non-existent domain"); break;
-	    case NOTIMP:	return("Not implemented"); break;
-	    case REFUSED:	return("Query refused"); break;
-	    case NOCHANGE:	return("No change"); break;
-	    case NO_INFO: 	return("No information"); break;
-	    case ERROR: 	return("Unspecified error"); break;
-	    case TIME_OUT: 	return("Timed out"); break;
-	    case NONAUTH: 	return("Non-authoritative answer"); break;
-	    default: 		break;
-	}
-	return("BAD ERROR VALUE"); 
-}
-
-static int tcpip_writeall(fd, buf, siz)
-int fd;
-char *buf;
-unsigned siz;
-{
-	unsigned siz_org;
-	int nbytes;
-
-	siz_org= siz;
-
-	while (siz)
-	{
-		nbytes= write(fd, buf, siz);
-		if (nbytes == -1)
-			return nbytes;
-		assert(siz >= nbytes);
-		buf += nbytes;
-		siz -= nbytes;
-	}
-	return siz_org;
-}
Index: trunk/minix/commands/simple/hostaddr.c
===================================================================
--- trunk/minix/commands/simple/hostaddr.c	(revision 9)
+++ 	(revision )
@@ -1,313 +1,0 @@
-/*
-hostaddr.c
-
-Fetch an ip and/or ethernet address and print it on one line.
-
-Created:	Jan 27, 1992 by Philip Homburg
-*/
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/utsname.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/ether.h>
-#include <net/gen/eth_io.h>
-#include <net/gen/if_ether.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/ip_io.h>
-#include <net/gen/netdb.h>
-#include <net/gen/socket.h>
-#include <net/gen/nameser.h>
-#include <net/gen/resolv.h>
-#include <net/gen/dhcp.h>
-
-#include <minix/paths.h>
-
-char *prog_name;
-
-char DHCPCACHE[]=_PATH_DHCPCACHE;
-
-void main _ARGS(( int argc, char *argv[] ));
-void usage _ARGS(( void ));
-
-void main(argc, argv)
-int argc;
-char *argv[];
-{
-	int c;
-	int first_print;
-	int a_flag, e_flag, i_flag, h_flag;
-	char *E_arg, *I_arg;
-	int do_ether, do_ip, do_asc_ip, do_hostname;
-	char *eth_device, *ip_device;
-	int eth_fd, ip_fd;
-	int result;
-	nwio_ethstat_t nwio_ethstat;
-	nwio_ipconf_t nwio_ipconf;
-	struct hostent *hostent;
-	char *hostname, *domain;
-	char nodename[2*256];
-	dhcp_t dhcp;
-
-	first_print= 1;
-	prog_name= argv[0];
-
-	a_flag= e_flag= h_flag = i_flag= 0;
-	E_arg= I_arg= NULL;
-
-	while((c= getopt(argc, argv, "?aheE:iI:")) != -1)
-	{
-		switch(c)
-		{
-		case '?':
-			usage();
-		case 'a':
-			if (a_flag)
-				usage();
-			a_flag= 1;
-			break;
-		case 'h':
-			if (h_flag)
-				usage();
-			h_flag= 1;
-			break;
-		case 'e':
-			if (e_flag)
-				usage();
-			e_flag= 1;
-			break;
-		case 'E':
-			if (E_arg)
-				usage();
-			E_arg= optarg;
-			break;
-		case 'i':
-			if (i_flag)
-				usage();
-			i_flag= 1;
-			break;
-		case 'I':
-			if (I_arg)
-				usage();
-			I_arg= optarg;
-			break;
-		default:
-			usage();
-		}
-	}
-	if(optind != argc)
-		usage();
-
-	do_ether= e_flag;
-	if (E_arg)
-		eth_device= E_arg;
-	else
-	{
-		eth_device= getenv("ETH_DEVICE");
-		if (!eth_device)
-			eth_device= ETH_DEVICE;
-	}
-
-	do_ip= i_flag;
-	do_asc_ip= a_flag;
-	do_hostname= h_flag;
-	if (I_arg)
-		ip_device= I_arg;
-	else
-	{
-		ip_device= getenv("IP_DEVICE");
-		if (!ip_device)
-			ip_device= IP_DEVICE;
-	}
-
-	if (!do_ether && !do_ip && !do_asc_ip && !do_hostname)
-		do_ether= do_ip= do_asc_ip= 1;
-
-	if (do_ether)
-	{
-		eth_fd= open(eth_device, O_RDWR);
-		if (eth_fd == -1)
-		{
-			fprintf(stderr, "%s: Unable to open '%s': %s\n",
-				prog_name, eth_device, strerror(errno));
-			exit(1);
-		}
-		result= ioctl(eth_fd, NWIOGETHSTAT, &nwio_ethstat);
-		if (result == -1)
-		{
-			fprintf(stderr, 
-			"%s: Unable to fetch ethernet address: %s\n",
-				prog_name, strerror(errno));
-			exit(1);
-		}
-		printf("%s%s", first_print ? "" : " ",
-					ether_ntoa(&nwio_ethstat.nwes_addr));
-		first_print= 0;
-	}
-	if (do_ip || do_asc_ip || do_hostname)
-	{
-		ip_fd= open(ip_device, O_RDWR);
-		if (ip_fd == -1)
-		{
-			fprintf(stderr, "%s: Unable to open '%s': %s\n",
-				prog_name, ip_device, strerror(errno));
-			exit(1);
-		}
-		result= ioctl(ip_fd, NWIOGIPCONF, &nwio_ipconf);
-		if (result == -1)
-		{
-			fprintf(stderr, 
-				"%s: Unable to fetch IP address: %s\n",
-				prog_name,
-				strerror(errno));
-			exit(1);
-		}
-	}
-
-	setuid(getuid());
-
-	if (do_ip)
-	{
-		printf("%s%s", first_print ? "" : " ",
-					inet_ntoa(nwio_ipconf.nwic_ipaddr));
-		first_print= 0;
-	}
-	if (do_asc_ip || do_hostname)
-	{
-		int fd;
-		int r;
-		dhcp_t d;
-		u8_t *data;
-		size_t hlen, dlen;
-
-		hostname= NULL;
-		domain= NULL;
-
-		/* Use a reverse DNS lookup to get the host name.  This is
-		 * the preferred method, but often fails due to lazy admins.
-		 */
-		hostent= gethostbyaddr((char *)&nwio_ipconf.nwic_ipaddr,
-			sizeof(nwio_ipconf.nwic_ipaddr), AF_INET);
-		if (hostent != NULL) hostname= hostent->h_name;
-
-		if (hostname != NULL)
-		{
-			/* Reverse DNS works.  */
-		}
-		else if ((fd= open(DHCPCACHE, O_RDONLY)) == -1)
-		{
-			if (errno != ENOENT)
-			{
-				fprintf(stderr, "%s: %s: %s\n",
-					prog_name, DHCPCACHE, strerror(errno));
-				exit(1);
-			}
-		}
-		else
-		{
-			/* Try to get the hostname from the DHCP data. */
-			while ((r= read(fd, &d, sizeof(d))) == sizeof(d))
-			{
-				if (d.yiaddr == nwio_ipconf.nwic_ipaddr) break;
-			}
-			if (r < 0)
-			{
-				fprintf(stderr, "%s: %s: %s\n",
-					prog_name, DHCPCACHE, strerror(errno));
-				exit(1);
-			}
-			close(fd);
-
-			if (r == sizeof(d))
-			{
-				if (dhcp_gettag(&d, DHCP_TAG_HOSTNAME,
-							&data, &hlen))
-					hostname= (char *) data;
-
-				if (dhcp_gettag(&d, DHCP_TAG_DOMAIN,
-							&data, &dlen))
-					domain= (char *) data;
-
-				if (hostname != NULL) hostname[hlen] = 0;
-				if (domain != NULL) domain[dlen] = 0;
-			}
-		}
-
-		if (hostname != NULL)
-		{
-			if (strchr(hostname, '.') != NULL)
-			{
-				domain= strchr(hostname, '.');
-				*domain++ = 0;
-			}
-		}
-		else
-		{
-			/* No host name anywhere.  Use the IP address. */
-			hostname= inet_ntoa(nwio_ipconf.nwic_ipaddr);
-			domain= NULL;
-		}
-
-		strcpy(nodename, hostname);
-		if (domain != NULL)
-		{
-			strcat(nodename, ".");
-			strcat(nodename, domain);
-		}
-	}
-	if (do_asc_ip)
-	{
-		printf("%s%s", first_print ? "" : " ", nodename);
-		first_print= 0;
-	}
-	if (do_hostname)
-	{
-#if __minix_vmd
-		if (sysuname(_UTS_SET, _UTS_NODENAME,
-					nodename, strlen(nodename)+1) == -1)
-		{
-			fprintf(stderr, "%s: Unable to set nodename: %s\n",
-				prog_name, strerror(errno));
-			exit(1);
-		}
-
-		if (sysuname(_UTS_SET, _UTS_HOSTNAME,
-					hostname, strlen(hostname)+1) == -1)
-		{
-			fprintf(stderr, "%s: Unable to set hostname: %s\n",
-				prog_name, strerror(errno));
-			exit(1);
-		}
-#else
-		FILE *fp;
-
-		if ((fp= fopen("/etc/hostname.file", "w")) == NULL
-		    || fprintf(fp, "%s\n", nodename) == EOF
-		    || fclose(fp) == EOF)
-		{
-			fprintf(stderr, "%s: /etc/hostname.file: %s\n",
-				prog_name, strerror(errno));
-			exit(1);
-		}
-#endif
-	}
-	if (!first_print) printf("\n");
-	exit(0);
-}
-
-void usage()
-{
-	fprintf(stderr,
-		"Usage: %s -[eiah] [-E <eth-device>] [-I <ip-device>]\n", 
-								prog_name);
-	exit(1);
-}
Index: trunk/minix/commands/simple/id.c
===================================================================
--- trunk/minix/commands/simple/id.c	(revision 9)
+++ 	(revision )
@@ -1,122 +1,0 @@
-/* id - return uid and gid		Author: John J. Marco */
-
-/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
-/* 		----- id.c -----					*/
-/* Id - get real and effective user id and group id			*/
-/* Author: John J. Marco						*/
-/*	   pa1343@sdcc15.ucsd.edu					*/
-/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <limits.h>
-
-int main(int argc, char *argv[])
-{
-  struct passwd *pwd;
-  struct group *grp;
-  uid_t ruid, euid;
-  gid_t rgid, egid;
-#if __minix_vmd
-  uid_t suid;
-  gid_t sgid;
-#else
-# define suid ruid
-# define sgid rgid
-#endif
-#if NGROUPS_MAX > 0
-  gid_t groups[NGROUPS_MAX];
-  int ngroups;
-#else
-# define groups (&rgid)
-# define ngroups 0
-#endif
-  int g;
-  int isug;
-  int c, uopt = 0;
-
-#if __minix_vmd
-  get6id(&ruid, &euid, &suid, &rgid, &egid, &sgid);
-  isug = issetugid();
-#else
-  ruid = getuid();
-  euid = geteuid();
-  rgid = getgid();
-  egid = getegid();
-  isug = 0;
-#endif
-#if NGROUPS_MAX > 0
-  ngroups = getgroups(NGROUPS_MAX, groups);
-#endif
-
-  while((c = getopt(argc, argv, "u")) != EOF) {
-	switch(c) {
-		case 'u':
-			uopt = 1;
-			break;
-		default:
-			fprintf(stderr, "%s: unrecognized option\n", argv[0]);
-			return(1);
-	}
-  }
-
-  if(uopt) {
-	printf("%d\n", euid);
-	return 0;
-  }
-
-  if ((pwd = getpwuid(ruid)) == NULL)
-	printf("uid=%d", ruid);
-  else
-	printf("uid=%d(%s)", ruid, pwd->pw_name);
-
-  if ((grp = getgrgid(rgid)) == NULL)
-	printf(" gid=%d", rgid);
-  else
-	printf(" gid=%d(%s)", rgid, grp->gr_name);
-
-  if (euid != ruid)
-	if ((pwd = getpwuid(euid)) != NULL)
-		printf(" euid=%d(%s)", euid, pwd->pw_name);
-	else
-		printf(" euid=%d", euid);
-
-  if (egid != rgid)
-	if ((grp = getgrgid(egid)) != NULL)
-		printf(" egid=%d(%s)", egid, grp->gr_name);
-	else
-		printf(" egid=%d", egid);
-
-  if (suid != euid)
-	if ((pwd = getpwuid(suid)) != NULL)
-		printf(" suid=%d(%s)", suid, pwd->pw_name);
-	else
-		printf(" suid=%d", suid);
-
-  if (sgid != egid)
-	if ((grp = getgrgid(sgid)) != NULL)
-		printf(" sgid=%d(%s)", sgid, grp->gr_name);
-	else
-		printf(" sgid=%d", sgid);
-
-  if (isug) {
-	printf(" issetugid");
-  }
-
-  if (ngroups > 0) {
-	printf(" groups=");
-	for (g = 0; g < ngroups; g++) {
-		if (g > 0) fputc(',', stdout);
-		if ((grp = getgrgid(groups[g])) == NULL)
-			printf("%d", groups[g]);
-		else
-			printf("%d(%s)", groups[g], grp->gr_name);
-	}
-  }
-
-  printf("\n");
-  return(0);
-}
Index: trunk/minix/commands/simple/ifconfig.c
===================================================================
--- trunk/minix/commands/simple/ifconfig.c	(revision 9)
+++ 	(revision )
@@ -1,352 +1,0 @@
-/*
-ifconfig.c
-*/
-
-#define _POSIX_C_SOURCE	2
-
-#include <sys/types.h>
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <net/netlib.h>
-#include <net/gen/in.h>
-#include <net/gen/ip_io.h>
-#include <net/gen/inet.h>
-
-#if __STDC__
-#define PROTO(x,y) x y
-#else
-#define PROTO(x,y) x()
-#endif
-
-static PROTO (void usage, (void) );
-static PROTO (void set_hostaddr, (int ip_fd, char *host_s, int ins) );
-static PROTO (void set_netmask, (int ip_fd, char *net_s, int ins) );
-static PROTO (void set_mtu, (int ip_fd, char *mtu_s) );
-static PROTO (int check_ipaddrset, (int ip_fd) );
-static PROTO (int check_netmaskset, (int ip_fd) );
-static PROTO (int get_ipconf, (int ip_fd,
-	struct nwio_ipconf *ref_ipconf) );
-PROTO (int main, (int argc, char *argv[]) );
-
-char *prog_name;
-
-main(argc, argv)
-int argc;
-char *argv[];
-{
-	char *device_s, *hostaddr_s, *mtu_s, *netmask_s, **arg_s;
-	int ins;
-	int c, ip_fd, ifno;
-	struct nwio_ipconf ipconf;
-	int i_flag, v_flag, a_flag, modify;
-	char *d_arg, *h_arg, *m_arg, *n_arg;
-
-	prog_name= argv[0];
-
-	d_arg= NULL;
-	h_arg= NULL;
-	m_arg= NULL;
-	n_arg= NULL;
-	i_flag= 0;
-	v_flag= 0;
-	a_flag= 0;
-	while ((c= getopt(argc, argv, "?I:h:m:n:iva")) != -1)
-	{
-		switch(c)
-		{
-		case '?':
-			usage();
-		case 'I':
-			if (d_arg)
-				usage();
-			d_arg= optarg;
-			break;
-		case 'h':
-			if (h_arg)
-				usage();
-			h_arg= optarg;
-			break;
-		case 'm':
-			if (m_arg)
-				usage();
-			m_arg= optarg;
-			break;
-		case 'n':
-			if (n_arg)
-				usage();
-			n_arg= optarg;
-			break;
-		case 'i':
-			if (i_flag)
-				usage();
-			i_flag= 1;
-			break;
-		case 'v':
-			if (v_flag)
-				usage();
-			v_flag= 1;
-			break;
-		case 'a':
-			if (a_flag)
-				usage();
-			a_flag= 1;
-			break;
-		default:
-			fprintf(stderr, "%s: getopt failed: '%c'\n", 
-				prog_name, c);
-			exit(1);
-		}
-	}
-	modify = (h_arg != NULL || n_arg != NULL || m_arg != NULL);
-	if (a_flag && modify) usage();
-	if (!modify) v_flag= 1;
-
-	if (modify) setuid(getuid());
-
-	if (optind != argc)
-		usage();
-
-	hostaddr_s= h_arg;
-	mtu_s= m_arg;
-	netmask_s= n_arg;
-	ins= i_flag;
-
-	ifno= 0;
-	do
-	{
-		if (!a_flag) {
-			device_s= d_arg;
-			if (device_s == NULL)
-				device_s= getenv("IP_DEVICE");
-			if (device_s == NULL)
-				device_s= IP_DEVICE;
-		} else {
-			static char device[sizeof("/dev/ip99")];
-
-			sprintf(device, "/dev/ip%d", ifno);
-			device_s= device;
-		}
-
-		ip_fd= open (device_s, O_RDWR);
-		if (ip_fd<0)
-		{
-			if (a_flag && (errno == ENOENT || errno == ENXIO))
-				continue;
-
-			fprintf(stderr, "%s: Unable to open '%s': %s\n", 
-				prog_name, device_s, strerror(errno));
-			exit(1);
-		}
-
-		if (hostaddr_s)
-			set_hostaddr(ip_fd, hostaddr_s, ins);
-
-		if (netmask_s)
-			set_netmask(ip_fd, netmask_s, ins);
-
-		if (mtu_s)
-			set_mtu(ip_fd, mtu_s);
-
-		if (v_flag) {
-			if (!get_ipconf(ip_fd, &ipconf))
-			{
-				if (!a_flag)
-				{
-					fprintf(stderr,
-					"%s: %s: Host address not set\n",
-						prog_name, device_s);
-					exit(1);
-				}
-			}
-			else
-			{
-				printf("%s: address %s", device_s,
-					inet_ntoa(ipconf.nwic_ipaddr));
-
-				if (ipconf.nwic_flags & NWIC_NETMASK_SET)
-				{
-					printf(" netmask %s",
-						inet_ntoa(ipconf.nwic_netmask));
-				}
-#ifdef NWIC_MTU_SET
-				if (ipconf.nwic_mtu)
-					printf(" mtu %u", ipconf.nwic_mtu);
-#endif
-				fputc('\n', stdout);
-			}
-		}
-		close(ip_fd);
-	} while (a_flag && ++ifno < 32);
-	exit(0);
-}
-
-static void set_hostaddr (ip_fd, hostaddr_s, ins)
-int ip_fd;
-char *hostaddr_s;
-int ins;
-{
-	ipaddr_t ipaddr;
-	struct nwio_ipconf ipconf;
-	int result;
-
-	ipaddr= inet_addr (hostaddr_s);
-	if (ipaddr == (ipaddr_t)(-1))
-	{
-		fprintf(stderr, "%s: Invalid host address (%s)\n",
-			prog_name, hostaddr_s);
-		exit(1);
-	}
-	if (ins && check_ipaddrset(ip_fd))
-		return;
-
-	ipconf.nwic_flags= NWIC_IPADDR_SET;
-	ipconf.nwic_ipaddr= ipaddr;
-
-	result= ioctl(ip_fd, NWIOSIPCONF, &ipconf);
-	if (result<0)
-	{
-		fprintf(stderr, "%s: Unable to set IP configuration: %s\n",
-			prog_name, strerror(errno));
-		exit(1);
-	}
-}
-
-static int check_ipaddrset (ip_fd)
-int ip_fd;
-{
-	struct nwio_ipconf ipconf;
-
-	if (!get_ipconf(ip_fd, &ipconf))
-		return 0;
-
-	assert (ipconf.nwic_flags & NWIC_IPADDR_SET);
-
-	return 1;
-}
-
-static int get_ipconf (ip_fd, ref_ipaddr)
-int ip_fd;
-struct nwio_ipconf *ref_ipaddr;
-{
-	int flags;
-	int error, result;
-	nwio_ipconf_t ipconf;
-
-	flags= fcntl(ip_fd, F_GETFL);
-	fcntl(ip_fd, F_SETFL, flags | O_NONBLOCK);
-
-	result= ioctl (ip_fd, NWIOGIPCONF, &ipconf);
-	error= errno;
-
-	fcntl(ip_fd, F_SETFL, flags);
-
-	if (result <0 && error != EAGAIN)
-	{
-		errno= error;
-		fprintf(stderr, "%s: Unable to get IP configuration: %s\n",
-			prog_name, strerror(errno));
-		exit(1);
-	}
-	if (result == 0)
-	{
-		*ref_ipaddr = ipconf;
-	}
-	return result>=0;
-}
-
-static void usage()
-{
-	fprintf(stderr,
-	"Usage: %s [-I ip-device] [-h ipaddr] [-n netmask] [-m mtu] [-iva]\n",
-		prog_name);
-	exit(1);
-}
-
-static void set_netmask (ip_fd, netmask_s, ins)
-int ip_fd;
-char *netmask_s;
-int ins;
-{
-	ipaddr_t netmask;
-	struct nwio_ipconf ipconf;
-	int result;
-
-	netmask= inet_addr (netmask_s);
-	if (netmask == (ipaddr_t)(-1))
-	{
-		fprintf(stderr, "%s: Invalid netmask (%s)\n",
-			prog_name, netmask_s);
-		exit(1);
-	}
-	if (ins && check_netmaskset(ip_fd))
-		return;
-
-	ipconf.nwic_flags= NWIC_NETMASK_SET;
-	ipconf.nwic_netmask= netmask;
-
-	result= ioctl(ip_fd, NWIOSIPCONF, &ipconf);
-	if (result<0)
-	{
-		fprintf(stderr, "%s: Unable to set IP configuration: %s\n",
-			prog_name, strerror(errno));
-		exit(1);
-	}
-}
-
-static void set_mtu (ip_fd, mtu_s)
-int ip_fd;
-char *mtu_s;
-{
-	ipaddr_t netmask;
-	int result;
-	long mtu;
-	char *check;
-	struct nwio_ipconf ipconf;
-
-	mtu= strtol (mtu_s, &check, 0);
-	if (check[0] != '\0')
-	{
-		fprintf(stderr, "%s: Invalid mtu (%s)\n",
-			prog_name, mtu_s);
-		exit(1);
-	}
-
-#ifdef NWIC_MTU_SET
-	ipconf.nwic_flags= NWIC_MTU_SET;
-	ipconf.nwic_mtu= mtu;
-
-	result= ioctl(ip_fd, NWIOSIPCONF, &ipconf);
-	if (result<0)
-	{
-		fprintf(stderr, "%s: Unable to set IP configuration: %s\n",
-			prog_name, strerror(errno));
-		exit(1);
-	}
-#endif
-}
-
-static int check_netmaskset (ip_fd)
-int ip_fd;
-{
-	struct nwio_ipconf ipconf;
-
-	if (!get_ipconf(ip_fd, &ipconf))
-	{
-		fprintf(stderr,
-"%s: Unable to determine if netmask is set, please set IP address first\n",
-			prog_name);
-		exit(1);
-	}
-
-	return (ipconf.nwic_flags & NWIC_NETMASK_SET);
-}
-
-/*
- * $PchId: ifconfig.c,v 1.7 2001/02/21 09:19:52 philip Exp $
- */
Index: trunk/minix/commands/simple/ifdef.c
===================================================================
--- trunk/minix/commands/simple/ifdef.c	(revision 9)
+++ 	(revision )
@@ -1,504 +1,0 @@
-/* ifdef - remove #ifdefs		Author: Warren Toomey */
-
-/* Copyright 1989 by Warren Toomey	wkt@cs.adfa.oz.au[@uunet.uu.net]
- *
- * You may freely copy or distribute this code as long as this notice
- * remains intact.
- *
- * You may modify this code, as long as this notice remains intact, and
- * you add another notice indicating that the code has been modified.
- *
- * You may NOT sell this code or in any way profit from this code without
- * prior agreement from the author.
- */
-
-#include <sys/types.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-
-/* Definition of structures and constants used in ifdef.c  */
-
-/* Types of symbols */
-#define DEF	  1		/* Symbol is defined    */
-#define UNDEF	  2		/* Symbol isn't defined */
-#define IGN	  3		/* Ignore this symbol unless defined */
-
-/* Redef mode values */
-#define MUTABLE   1		/* Symbol can change defined <-> undefined */
-#define IMMUTABLE 2		/* Symbol can't change as above            */
-
-/* Processing modes */
-#define NO	0		/* Don't process */
-#define YES	1		/* Process */
-
-/* Ignore (IGN), ignore but process */
-struct DEFINE {
-  char *symbol;			/* SLL of defined symbols. The redef  */
-  char type;			/* field indicates if this symbol can */
-  char redef;			/* change from defined <-> undefined. */
-  struct DEFINE *next;		/* Type is DEF or UNDEF.	      */
-};
-
-/* Global variables & structures */
-FILE *zin;			/* Input file for processing  */
-struct DEFINE *defptr;		/* Defined symbols SLL        */
-struct DEFINE *defend;		/* Ptr to last node in defptr */
-struct DEFINE *deftemp;		/* Ptr to last found node     */
-int line = 1;			/* Current line number        */
-int table = 0;			/* Don't normally want a table */
-
-extern int optind;
-extern char *optarg;
-
-/* Prototypes. */
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(char fgetarg, (FILE *stream, char *cbuf));
-_PROTOTYPE(int find, (char *symd));
-_PROTOTYPE(void defit, (char *sym, int redef, int typed));
-_PROTOTYPE(void stop, (void));
-_PROTOTYPE(void gotoeoln, (void));
-_PROTOTYPE(void prteoln, (void));
-_PROTOTYPE(void printtable, (void));
-_PROTOTYPE(char getendif, (void));
-_PROTOTYPE(void gettable, (void));
-_PROTOTYPE(void parse, (void));
-_PROTOTYPE(void usage, (void));
-
-#ifdef __STDC__
-char fgetarg ( FILE *stream , char *cbuf )
-#else
-char fgetarg(stream, cbuf)	/* Get next arg from file into cbuf, */
-FILE *stream;			/* returning the character that      */
-char *cbuf;			/* terminated it. Cbuf returns 0     */
-#endif
-{				/* if no arg. EOF is returned if no  */
-  int ch;			/* args left in file.                */
-  int i;
-
-  i = 0;
-  cbuf[i] = 0;
-
-  while (((ch = fgetc(stream)) == ' ') || (ch == '\t') || (ch == '\n'))
-	if (ch == '\n') return(ch);	/* Bypass leading */
-					/* Whitespace     */
-  if (feof(stream)) return(EOF);
-
-  cbuf[i++] = ch;
-
-  while (((ch = fgetc(stream)) != ' ') && (ch != '\t') && (ch != '\n'))
-	cbuf[i++] = ch;			/* Get the argument */
-
-  cbuf[i] = 0;
-  return(ch);
-}
-
-
-#ifdef __STDC__
-int find ( char *sym )
-#else
-int find(sym)
-char *sym;
-#endif
-{				/* Return DEF if defined else UNDEF */
-
-  deftemp = defptr;
-  while (deftemp) {			/* Search for the symbol */
-	if (!strcmp(deftemp->symbol, sym))
-		return(deftemp->type);	/* Setting up the type */
-	deftemp = deftemp->next;
-  }
-  return(0);
-}
-
-
-
-#define Define(x,y)	defit(x,y,DEF)
-#define Undefine(x,y)	defit(x,y,UNDEF)
-#define Ignore(x,y)	defit(x,y,IGN)
-
-#ifdef __STDC__
-void defit ( char *sym , int redef , int type )
-#else
-void defit(sym, redef, type)	/* Add symbol to the define list */
-char *sym;
-char redef;			/* Mode: MUTABLE etc      */
-char type;			/* Type: DEF, UNDEF, IGN  */
-#endif
-{
-  struct DEFINE *temp;
-  char c;
-
-  c = find(sym);		/* First try finding the symbol */
-  if (type == c) return;	/* Return if already declared */
-  if (c) {			/* We have to move if from DEF <-> UNDEF */
-	if (deftemp->redef == IMMUTABLE)
-		return;
-	else {
-		deftemp->type = type;
-		deftemp->redef = redef;
-	}
-  } else {			/* We must create a struct & add it */
-				/* Malloc room for the struct */
-	if ((temp = (struct DEFINE *)malloc(sizeof(struct DEFINE))) == NULL) {
-		(void)fprintf(stderr, "ifdef: could not malloc\n");
-		exit(1);
-	}
-
-					/* Malloc room for symbol */
-	if ((temp->symbol = (char *)malloc(strlen(sym) + 1)) == NULL) {
-		(void)fprintf(stderr, "ifdef: could not malloc\n");
-		exit(1);
-	}
-	(void)strcpy(temp->symbol, sym); /* Copy symbol into struct      */
-	temp->redef = redef;		/* and set its redef mode too   */
-	temp->type = type;		/* as well as making it defined */
-
-
-					/* Now add to the SLL */
-	if (defptr == NULL)		/* If first node set  */
-		defptr = temp;		/* the pointers to it */
-	else
-		defend->next = temp;	/* else add it to the */
-	defend = temp;			/* end of the list.   */
-  }
-}
-
-
-
-#ifdef __STDC__
-void stop ( void )
-#else
-void stop()
-#endif
-{				/* Stop: Tidy up at EOF */
-  if (table) printtable();
-  (void)fclose(zin);
-  exit(0);
-}
-
-#define Goto	{ line++; if (ch!='\n') gotoeoln(); }
-#define Print	{ line++; if (ch!='\n') prteoln();  }
-
-#ifdef __STDC__
-void gotoeoln ( void )
-#else
-void gotoeoln()			/* Go to the end of the line */
-#endif
-{
-  int ch;
-  while ((ch = fgetc(zin)) != '\n')
-	if (ch == EOF) stop();
-}
-
-
-#ifdef __STDC__
-void prteoln ( void )
-#else
-void prteoln()			/* Print to the end of the line */
-#endif
-{
-  int ch;
-  while ((ch = fgetc(zin)) != '\n')
-	if (ch == EOF)
-		stop();
-	else
-		(void)putchar(ch);
-  (void)putchar('\n');
-}
-
-
-#ifdef __STDC__
-void printtable ( void )
-#else
-void printtable()		/* Print the defines in the SLL */
-#endif
-{
-  struct DEFINE *temp;
-
-  (void)printf("Defined\n\n");
-
-  temp = defptr;
-  while (temp) {
-	if (temp->type == DEF) (void)printf("%s\n", temp->symbol);
-	temp = temp->next;
-  }
-
-  (void)printf("\n\nUndefined\n\n");
-
-  temp = defptr;
-  while (temp) {
-	if (temp->type == UNDEF) (void)printf("%s\n", temp->symbol);
-	temp = temp->next;
-  }
-}
-
-#ifdef __STDC__
-char getendif ( void )
-#else
-char getendif()
-#endif
-{				/* Find matching endif when ignoring */
-  char word[80];		/* Buffer for symbols */
-  int ch;
-  int skip;			/* Number of skipped #ifdefs */
-
-  skip = 1;
-
-  while (1) {
-			/* Scan through the file looking for starting lines */
-	if ((ch = fgetc(zin)) == EOF)
-		stop();		/* Get first char on the line */
-	if (ch != '#') {	/* If not a # ignore line     */
-		(void)putchar(ch);
-		Print;
-		continue;
-	}
-	ch = fgetarg(zin, word);	/* Get the word after the # */
-
-	if (!strcmp(word, "ifdef") || !strcmp(word, "ifndef")) skip++;
-						/* Keep track of ifdefs & */
-	if (!strcmp(word, "endif")) skip--;	/* endifs		  */
-
-	(void)printf("#%s%c", word, ch);	/* Print the line out 	  */
-	Print;
-	if (!skip) return('\n');	/* If matching endif, return */
-  }
-}
-
-
-#ifdef __STDC__
-void gettable ( void )
-#else
-void gettable()			/* Get & print a table of defines etc.  */
-#endif
-{
-
-  char word[80];		/* Buffer for symbols */
-  int ch;
-
-  while (1) {
-			/* Scan through the file looking for starting lines */
-	if ((ch = fgetc(zin)) == EOF)
-		stop();		/* Get first char on the line */
-	if (ch != '#') {	/* If not a # ignore line     */
-		Goto;
-		continue;
-	}
-	ch = fgetarg(zin, word);	/* Get the word after the # */
-
-	if (!strcmp(word, "define")) {		/* Define: Define the */
-		ch = fgetarg(zin, word);	/* symbol, and goto   */
-		Define(word, MUTABLE);		/* the end of line    */
-		Goto;
-		continue;
-	}
-	if (!strcmp(word, "undef")) {		/* Undef: Undefine the */
-		ch = fgetarg(zin, word);	/* symbol, and goto    */
-		Undefine(word, MUTABLE);	/* the end of line     */
-		Goto;
-		continue;
-	}					/* Ifdef:            */
-	if (!strcmp(word, "ifdef") || !strcmp(word, "ifndef")) {
-		ch = fgetarg(zin, word);	/* Get the symbol */
-		if (find(word) != DEF)
-			Undefine(word, MUTABLE);	/* undefine it */
-		Goto;
-		continue;
-	}
-	Goto;				/* else ignore the line */
-  }
-}
-
-
-
-#ifdef __STDC__
-void parse ( void )
-#else
-void parse()
-#endif
-{				/* Parse & remove ifdefs from C source */
-  char word[80];		/* Buffer for symbols */
-  int ch;
-  int proc;			/* Should we be processing this bit?    */
-  int skip;			/* Number of skipped #ifdefs		 */
-
-  proc = 1;
-  skip = 0;
-
-  while (1) {
-			/* Scan through the file looking for starting lines */
-	if ((ch = fgetc(zin)) == EOF)
-		stop();		/* Get first char on the line */
-	if (ch != '#')
-		if (proc) {	/* If not # and  we're processing */
-			(void)putchar(ch); /* then print the line */
-			Print;
-			continue;
-		} else {
-			Goto;	/* else just skip the line  */
-			continue;
-		}
-
-	ch = fgetarg(zin, word);	/* Get the word after the # */
-
-	if (!strcmp(word, "define") && proc) {	/* Define: Define the */
-		ch = fgetarg(zin, word);	/* symbol, and goto   */
-		Define(word, MUTABLE);		/* the end of line    */
-		(void)printf("#define %s%c", word, ch);
-		Print;
-		continue;
-	}
-	if (!strcmp(word, "undef") && proc) {	/* Undef: Undefine the */
-		ch = fgetarg(zin, word);	/* symbol, and goto    */
-		Undefine(word, MUTABLE);	/* the end of line     */
-		(void)printf("#undef %s%c", word, ch);
-		Print;
-		continue;
-	}
-	if (!strcmp(word, "if")) {	/* If: we cannot handle these */
-		if (!proc)		/* at the moment, so just */
-			skip++;		/* treat them as an ignored */
-		else {			/* definition */
-			(void)printf("#%s%c",word,ch);
-			Print;
-			ch = getendif();	/* Get matching endif */
-			continue;
-		     	}
-	}
-	if (!strcmp(word, "ifdef")) {	/* Ifdef:	     */
-		if (!proc)		/* If not processing */
-			skip++;		/* skip it           */
-		else {
-			ch = fgetarg(zin, word); /* Get the symbol */
-			switch (find(word)) {
-			    case DEF:
-				break;
-			    case IGN:
-				(void)printf("#ifdef %s%c", word, ch);
-				Print;
-				ch = getendif(); /* Get matching endif */
-				break;
-						/* If symbol undefined */
-			    default:
-				Undefine(word, MUTABLE); /* undefine it */
-				proc = 0;	/* & stop processing */
-			}
-		}
-		Goto;
-		continue;
-	}
-	if (!strcmp(word, "ifndef")) {
-		/* Ifndef: */
-		if (!proc)	/* If not processing */
-			skip++;	/* skip the line     */
-		else {
-			ch = fgetarg(zin, word); /* Get the symbol */
-			switch (find(word)) {	/* If defined, stop */
-			    case DEF:
-				proc = 0;	/* processing       */
-				break;
-			    case IGN:
-				(void)printf("#ifdef %s%c", word, ch);
-				Print;
-				ch = getendif(); /* Get matching endif */
-				break;
-			}
-		}
-		Goto;
-		continue;
-	}
-	if (!strcmp(word, "else") && !skip) {	/* Else: Flip processing */
-		proc = !proc;
-		Goto;
-		continue;
-	}
-	if (!strcmp(word, "endif")) {	/* Endif: If no skipped   */
-					/* ifdefs turn processing */
-		if (!skip)		/* on, else decrement the */
-			proc = 1;	/* number of skips        */
-		else
-			skip--;
-		Goto;
-		continue;
-	}
-		/* The word fails all of the above tests, so if we're */
-		/* processing, print the line. */
-	if (proc) {
-		(void)printf("#%s%c", word, ch);
-		Print;
-	} else
-		Goto;
-  }
-}
-
-
-#ifdef __STDC__
-void usage ( void )
-#else
-void usage()
-#endif
-{
-  (void)fprintf(stderr, "Usage: ifdef [-t] [-Dsymbol] [-dsymbol] [-Usymbol] [-Isymbol] <file>\n");
-  exit(0);
-}
-
-
-#ifdef __STDC__
-int main(int argc , char *argv [])
-#else
-int main(argc, argv)
-int argc;
-char *argv[];
-#endif
-{
-  char sym[80];			/* Temp symbol storage */
-  int c;
-
-  if (argc == 1) usage();	/* Catch the curious user	 */
-  while ((c = getopt(argc, argv, "tD:d:U:I:")) != EOF) {
-	switch (c) {
-	    case 't':
-		table = 1;	/* Get the various options */
-		break;
-
-	    case 'd':
-		(void)strcpy(sym, optarg);
-		Define(sym, MUTABLE);
-		break;
-
-	    case 'D':
-		(void)strcpy(sym, optarg);
-		Define(sym, IMMUTABLE);
-		break;
-
-	    case 'U':
-		(void)strcpy(sym, optarg);
-		Undefine(sym, IMMUTABLE);
-		break;
-
-	    case 'I':
-		(void)strcpy(sym, optarg);
-		Ignore(sym, IMMUTABLE);
-		break;
-
-	    default:	usage();
-	}
-  }
-
-  zin = stdin;		/* If a C file is named */
-			/* Open stdin with it */
-  if (*argv[argc - 1] != '-') {
-	(void)fclose(zin);
-	if ((zin = fopen(argv[argc - 1], "r")) == NULL) {
-		perror("ifdef");
-		exit(1);
-	}
-  }
-  if (table)
-	gettable();		/* Either generate a table or    */
-  else
-	parse();		/* parse & replace with the file */
-  return(0);
-}
Index: trunk/minix/commands/simple/in.fingerd.c
===================================================================
--- trunk/minix/commands/simple/in.fingerd.c	(revision 9)
+++ 	(revision )
@@ -1,94 +1,0 @@
-/*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)in.fingerd.c 1.1 87/12/21 SMI"; /* from UCB 5.1 6/6/85 */
-#endif /* not lint */
-
-/*
- * Finger server.
- */
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
-int main _ARGS(( int argc, char *argv[] ));
-void fatal _ARGS(( char *prog, char *s ));
-
-int main(argc, argv)
-	char *argv[];
-{
-	register char *sp;
-	char line[512];
-	int i, p[2], pid, status;
-	FILE *fp;
-	char *av[4];
-
-	line[0] = '\0';
-	fgets(line, sizeof(line), stdin);
-	sp = line + strlen(line);
-	if (sp > line && *--sp == '\n') *sp = '\0';
-	sp = line;
-	av[0] = "finger";
-	i = 1;
-	while (1) {
-		while (isspace(*sp))
-			sp++;
-		if (!*sp)
-			break;
-		if (*sp == '/' && (sp[1] == 'W' || sp[1] == 'w')) {
-			sp += 2;
-			av[i++] = "-l";
-		}
-		if (*sp && !isspace(*sp)) {
-			av[i++] = sp;
-			while (*sp && !isspace(*sp))
-				sp++;
-			*sp = '\0';
-		}
-	}
-	av[i] = 0;
-	if (pipe(p) < 0)
-		fatal(argv[0], "pipe");
-	if ((pid = fork()) == 0) {
-		close(p[0]);
-		if (p[1] != 1) {
-			dup2(p[1], 1);
-			close(p[1]);
-		}
-		execv("/usr/bin/finger", av);
-		printf("No finger program found\n");
-		fflush(stdout);
-		_exit(1);
-	}
-	if (pid == -1)
-		fatal(argv[0], "fork");
-	close(p[1]);
-	if ((fp = fdopen(p[0], "r")) == NULL)
-		fatal(argv[0], "fdopen");
-	while ((i = getc(fp)) != EOF) {
-		if (i == '\n')
-			putchar('\r');
-		putchar(i);
-	}
-	fclose(fp);
-	while ((i = wait(&status)) != pid && i != -1)
-		;
-	return(0);
-}
-
-void fatal(prog, s)
-	char *prog, *s;
-{
-
-	fprintf(stderr, "%s: ", prog);
-	perror(s);
-	exit(1);
-}
Index: trunk/minix/commands/simple/in.rshd.c
===================================================================
--- trunk/minix/commands/simple/in.rshd.c	(revision 9)
+++ 	(revision )
@@ -1,445 +1,0 @@
-/*
-in.rshd.c
-*/
-
-/*
-	main channel:
-
-	back channel\0
-	remuser\0
-	locuser\0
-	command\0
-	data
-
-	back channel:
-	signal\0
-
-*/
-
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <pwd.h>
-#include <grp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/netdb.h>
-#include <net/gen/socket.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include <net/hton.h>
-#include <net/netlib.h>
-
-#define DEBUG 0
-
-#if DEBUG
-#define where() fprintf(stderr, "%s, %d: ", __FILE__, __LINE__)
-#endif
-
-char cmdbuf[_POSIX_ARG_MAX+1], locuser[16], remuser[16];
-extern char **environ;
-char username[20]="USER=";
-char homedir[64]="HOME=";
-char shell[64]="SHELL=";
-char tz[1024]="TZ=";
-char *envinit[]= {homedir, shell, username, tz, "PATH=:/bin:/usr/bin", 0};
-char *prog_name;
-char buffer[PIPE_BUF];
-
-#if __STDC__
-#define PROTO(func, args) func args
-#else
-#define PROTO(func, args) func ()
-#endif
-
-PROTO (int main, (int argc, char *argv[]));
-PROTO (void getstr, (char*buf, int cnt, char *err));
-PROTO (void close_on_exec, (int fd));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-	int result, result1;
-	nwio_tcpconf_t tcpconf, err_tcpconf;
-	nwio_tcpcl_t tcpconnopt;
-	nwio_tcpatt_t tcpattachopt;
-	tcpport_t tcpport;
-	tcpport_t err_port;
-	int err_fd, pds[2];
-	pid_t pid, pid1, new_pg;
-#if USEATTACH
-	int err2_fd;
-#endif
-	struct passwd *pwent;
-	char *cp, *buff_ptr, *TZ;
-	char sig;
-
-	prog_name= argv[0];
-	if (argc != 1)
-	{
-		fprintf(stderr, "%s: wrong number of arguments (%d)\n",
-			prog_name, argc);
-		exit(1);
-	}
-
-	signal(SIGINT, SIG_DFL);
-	signal(SIGQUIT, SIG_DFL);
-	signal(SIGTERM, SIG_DFL);
-
-#if DEBUG
- { where(); fprintf(stderr, "\n"); }
-#endif
-	result= ioctl (0, NWIOGTCPCONF, &tcpconf);
-	if (result<0)
-	{
-		fprintf(stderr, "%s: ioctl(NWIOGTCPCONF)= %d : %s\n", 
-			prog_name, errno, strerror(errno));
-		exit(1);
-	}
-#if DEBUG
- { where(); fprintf(stderr, "\n"); }
-#endif
-
-	tcpport= ntohs(tcpconf.nwtc_remport);
-	if (tcpport >= TCPPORT_RESERVED || tcpport < TCPPORT_RESERVED/2)
-	{
-		printf("\1%s: unprotected port (%d)\n", prog_name, tcpport);
-		exit(1);
-	}
-	alarm(60);
-	err_port= 0;
-	for (;;)
-	{
-		char c;
-		result= read(0, &c, 1);
-		if (result <0)
-		{
-			fprintf(stderr, "%s: read= %d : %s\n", prog_name, 
-				errno, strerror(errno));
-		}
-		if (result<1)
-			exit(1);
-		if (c == 0)
-			break;
-		err_port= err_port*10 + c - '0';
-	}
-	alarm(0);
-	if (err_port != 0)
-	{
-		int n, pid, lport;
-
-		pid= getpid();
-		lport= 1;
-		do {
-			lport= (lport << 1) | (pid & 1);
-			pid >>= 1;
-		} while (lport < TCPPORT_RESERVED/2);
-
-		n= TCPPORT_RESERVED/2;
-		do
-		{
-			if (--lport < TCPPORT_RESERVED/2)
-				lport= TCPPORT_RESERVED-1;
-			err_fd= open ("/dev/tcp", O_RDWR);
-			if (err_fd<0)
-			{
-				fprintf(stderr, "%s: open= %d : %s\n", 
-					prog_name, errno, strerror(errno));
-				exit(1);
-			}
-			close_on_exec(err_fd);
-			err_tcpconf.nwtc_flags= NWTC_LP_SET | NWTC_SET_RA |
-				NWTC_SET_RP | NWTC_EXCL;
-			err_tcpconf.nwtc_locport= htons(lport);
-			err_tcpconf.nwtc_remport= htons(err_port);
-			err_tcpconf.nwtc_remaddr= tcpconf.nwtc_remaddr;
-
-#if DEBUG
- { where(); fprintf(stderr, "\n"); }
-#endif
-			result= ioctl (err_fd, NWIOSTCPCONF, &err_tcpconf);
-			if (result == 0) break;
-			if (errno != EADDRINUSE)
-			{
-				fprintf(stderr, 
-					"%s: ioctl(NWIOSTCPCONF)= %d : %s\n",
-					prog_name, errno, strerror(errno));
-				exit(1);
-			}
-			close(err_fd);
-		} while (--n > 0);
-		if (n == 0)
-		{
-			printf("\1can't get stderr port\n");
-			exit(1);
-		}
-
-		err_tcpconf.nwtc_flags= NWTC_SHARED;
-#if DEBUG
-{ where(); fprintf(stderr, "\n"); }
-#endif
-		result= ioctl (err_fd, NWIOSTCPCONF, &err_tcpconf);
-		if (result<0)
-		{
-			fprintf(stderr, 
-				"%s: ioctl(NWIOSTCPCONF)= %d : %s\n",
-				prog_name, errno, strerror(errno));
-			exit(1);
-		}
-#if DEBUG
-{ where(); fprintf(stderr, "\n"); }
-#endif
-		tcpconnopt.nwtcl_flags= 0;
-
-		n= 20;
-		for (;;)
-		{
-#if DEBUG
-{ where(); fprintf(stderr, "\n"); }
-#endif
-			result= ioctl (err_fd, NWIOTCPCONN, &tcpconnopt);
-			if (result == 0) break;
-			if (errno != EAGAIN && errno != ECONNREFUSED)
-			{
-				fprintf(stderr,
-					"%s: ioctl(NWIOTCPCONN)= %d : %s\n",
-					prog_name, errno, strerror(errno));
-				exit(1);
-			}
-			if (--n == 0) break;
-			sleep(1);
-#if DEBUG
-{ where(); fprintf(stderr, "\n"); }
-#endif
-		}
-#if USEATTACH
-		err2_fd= open ("/dev/tcp", O_RDWR);
-		close_on_exec(err2_fd);
-		if (err2_fd<0)
-		{
-			fprintf(stderr, "%s: open= %d : %s\n", errno,
-				prog_name, strerror(errno));
-			exit(1);
-		}
-#if DEBUG
- { where(); fprintf(stderr, "\n"); }
-#endif
-		result= ioctl (err2_fd, NWIOSTCPCONF, &err_tcpconf);
-		if (result<0)
-		{
-			fprintf(stderr, "%s: ioctl(NWIOSTCPCONF)= %d : %s\n",
-				prog_name, errno, strerror(errno));
-			exit(1);
-		}
-#if DEBUG
- { where(); fprintf(stderr, "\n"); }
-#endif
-		tcpattachopt.nwta_flags= 0;
-#if DEBUG
- { where(); fprintf(stderr, "\n"); }
-#endif
-		result= ioctl (err2_fd, NWIOTCPATTACH, &tcpattachopt);
-		if (result<0)
-		{
-			fprintf(stderr, "%s: ioctl(NWIOTCPATTACH)= %d : %s\n",
-				prog_name, errno, strerror(errno));
-			exit(1);
-		}
-#if DEBUG
- { where(); fprintf(stderr, "\n"); }
-#endif
-#endif
-	}
-	getstr(remuser, sizeof(remuser), "remuser");
-	getstr(locuser, sizeof(locuser), "locuser");
-	getstr(cmdbuf, sizeof(cmdbuf), "cmdbuf");
-	setpwent();
-	pwent= getpwnam(locuser);
-	if (!pwent)
-	{
-		printf("\1Login incorrect.\n");
-		exit(1);
-	}
-	endpwent();
-	if (chdir(pwent->pw_dir) < 0)
-	{
-		chdir("/");
-	}
-#if DEBUG
- { where(); fprintf(stderr, "calling iruserok(%s, %d, %s, %s)\n", 
-	inet_ntoa(tcpconf.nwtc_remaddr), 0, remuser, locuser); }
-#endif
-	if (iruserok(tcpconf.nwtc_remaddr, 0, remuser, locuser) < 0)
-	{
-		printf("\1Permission denied.\n");
-		exit(1);
-	}
-	if (err_port)
-	{
-		/* Let's go to a different process group. */
-		new_pg= setsid();
-		pid= fork();
-		if (pid<0)
-		{
-			if (errno != EAGAIN)
-			{
-				fprintf(stderr, "%s: fork()= %d : %s\n",
-					prog_name, errno, strerror(errno));
-			}
-			printf("\1Try again.\n");
-			exit(1);
-		}
-		if (pid)
-		{
-			close(0);	/* stdin */
-			close(1);	/* stdout */
-#if USEATTACH
-			close(err_fd);	/* stderr for shell */
-#endif
-			dup2(2,0);
-			dup2(2,1);
-			for (;;)
-			{
-#if !USEATTACH
-				if (read(err_fd, &sig, 1) <= 0)
-#else
-				if (read(err2_fd, &sig, 1) <= 0)
-#endif
-				{
-#if 0
-					printf("read failed: %d\n", errno);
-#endif
-					exit(0);
-				}
-				pid= 0;
-#if 0
-				printf("killing %d with %d\n", -new_pg, sig);
-#endif
-				kill(-new_pg, sig);
-			}
-		}
-#if USEATTACH
-		close(err2_fd);	/* signal channel for parent */
-#endif
-		result= pipe(pds);
-		if (result<0)
-		{
-			printf("\1Can't make pipe\n");
-			kill(getppid(), SIGTERM);
-			exit(1);
-		}
-		pid1= fork();
-		if (pid1<0)
-		{
-			if (errno != EAGAIN)
-			{
-				fprintf(stderr, "%s: fork()= %d : %s\n",
-					prog_name, errno, strerror(errno));
-			}
-			printf("\1Try again.\n");
-			kill(-new_pg, SIGTERM);
-			exit(1);
-		}
-		if (pid1)
-		{
-			close(pds[1]);	/* write side of pipe */
-			for (;;)
-			{
-				result= read(pds[0], buffer, sizeof(buffer));
-				if (result<=0)
-				{
-					kill(pid, SIGTERM);
-					exit(0);
-				}
-				buff_ptr= buffer;
-				while (result>0)
-				{
-					result1= write (err_fd, buff_ptr,
-						result);
-					if (result1 <= 0)
-					{
-						fprintf(stderr, 
-						"%s: write()= %d : %s\n",
-							prog_name, errno,
-							strerror(errno));
-						kill(-new_pg, SIGTERM);
-						exit(1);
-					}
-					result -= result1;
-				}
-			}
-		}
-		close(err_fd);	/* file descriptor for error channel */
-		close (pds[0]);	/* read side of pipe */
-		dup2(pds[1], 2);
-		close (pds[1]);	/* write side of pipe */
-	}
-	if (*pwent->pw_shell == '\0')
-		pwent->pw_shell= "/bin/sh";
-#if __minix_vmd
-	initgroups(pwent->pw_name, pwent->pw_gid);
-#endif
-	setgid(pwent->pw_gid);
-	setuid(pwent->pw_uid);
-	TZ=getenv("TZ");
-	environ= envinit;
-	strncat(homedir, pwent->pw_dir, sizeof(homedir)-6);
-	strncat(shell, pwent->pw_shell, sizeof(shell)-7);
-	strncat(username, pwent->pw_name, sizeof(username)-6);
-	if (TZ)
-		strncat(tz, TZ, sizeof(tz)-4);
-	else
-		envinit[3]= NULL;
-
-	cp= strrchr(pwent->pw_shell, '/');
-	if (cp)
-		cp++;
-	else
-		cp= pwent->pw_shell;
-
-	if (!err_port)
-		dup2(1, 2);
-	write(1, "\0", 1);
-
-	execl(pwent->pw_shell, cp, "-c", cmdbuf, 0);
-	close(2);
-	open("/dev/tty", O_RDWR);
-	fprintf(stderr, "%s: execl(%s, %s, .., %s)= %d : %s\n", prog_name,
-		pwent->pw_shell, cp, cmdbuf, errno, strerror(errno));
-	kill(getppid(), SIGTERM);
-	exit(1);
-}
-
-void getstr(buf, cnt, err)
-char *buf;
-int cnt;
-char *err;
-{
-	char c;
-
-	do
-	{
-		if (read(0, &c, 1) != 1)
-			exit(1);
-		*buf++ = c;
-		if (--cnt == 0)
-		{
-			printf("\1%s too long", err);
-			exit(1);
-		}
-	} while (c != 0);
-}
-
-void close_on_exec(fd)
-int fd;
-{
-	(void) fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
-}
Index: trunk/minix/commands/simple/install.c
===================================================================
--- trunk/minix/commands/simple/install.c	(revision 9)
+++ 	(revision )
@@ -1,599 +1,0 @@
-/*	install 1.11 - install files.			Author: Kees J. Bot
- *								21 Feb 1993
- */
-#define nil 0
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <a.out.h>
-#include <limits.h>
-#include <pwd.h>
-#include <grp.h>
-#include <utime.h>
-#include <signal.h>
-
-/* First line used on a self-decompressing executable. */
-char ZCAT[]=	"#!/usr/bin/zexec /usr/bin/zcat\n";
-char GZCAT[]=	"#!/usr/bin/zexec /usr/bin/gzcat\n";
-
-/* Compression filters. */
-char *COMPRESS[]=	{ "compress", nil };
-char *GZIP[]=		{ "gzip", "-#", nil };
-
-int excode= 0;		/* Exit code. */
-
-void report(char *label)
-{
-	if (label == nil || label[0] == 0)
-		fprintf(stderr, "install: %s\n", strerror(errno));
-	else
-		fprintf(stderr, "install: %s: %s\n", label, strerror(errno));
-	excode= 1;
-}
-
-void fatal(char *label)
-{
-	report(label);
-	exit(1);
-}
-
-void *allocate(void *mem, size_t size)
-/* Safe malloc/realloc. */
-{
-	mem= mem == nil ? malloc(size) : realloc(mem, size);
-
-	if (mem == nil) fatal(nil);
-	return mem;
-}
-
-void deallocate(void *mem)
-{
-	if (mem != nil) free(mem);
-}
-
-int lflag= 0;		/* Make a hard link if possible. */
-int cflag= 0;		/* Copy if you can't link, otherwise symlink. */
-int dflag= 0;		/* Create a directory. */
-int strip= 0;		/* Strip the copy. */
-char **compress= nil;	/* Compress utility to make a compressed executable. */
-char *zcat= nil;	/* Line one to decompress. */
-
-long stack= -1;		/* Amount of heap + stack. */
-int wordpow= 1;		/* Must be multiplied with wordsize ** wordpow */
-			/* So 8kb for an 8086 and 16kb for the rest. */
-
-pid_t filter(int fd, char **command)
-/* Let a command filter the output to fd. */
-{
-	pid_t pid;
-	int pfd[2];
-
-	if (pipe(pfd) < 0) {
-		report("pipe()");
-		return -1;
-	}
-
-	switch ((pid= fork())) {
-	case -1:
-		report("fork()");
-		return -1;
-	case 0:
-		/* Run the filter. */
-		dup2(pfd[0], 0);
-		dup2(fd, 1);
-		close(pfd[0]);
-		close(pfd[1]);
-		close(fd);
-		signal(SIGPIPE, SIG_DFL);
-		execvp(command[0], command);
-		fatal(command[0]);
-	}
-	/* Connect fd to the pipe. */
-	dup2(pfd[1], fd);
-	close(pfd[0]);
-	close(pfd[1]);
-	return pid;
-}
-
-int mkdirp(char *dir, int mode, int owner, int group)
-/* mkdir -p dir */
-{
-	int keep;
-	char *sep, *pref;
-
-	sep= dir;
-	while (*sep == '/') sep++;
-	
-	if (*sep == 0) {
-		errno= EINVAL;
-		return -1;
-	}
-
-	do {
-		while (*sep != '/' && *sep != 0) sep++;
-		pref= sep;
-		while (*sep == '/') sep++;
-
-		keep= *pref; *pref= 0;
-
-		if (strcmp(dir, ".") == 0 || strcmp(dir, "..") == 0) continue;
-
-		if (mkdir(dir, mode) < 0) {
-			if (errno != EEXIST || *sep == 0) {
-				/* On purpose not doing: *pref= keep; */
-				return -1;
-			}
-		} else {
-			if (chown(dir, owner, group) < 0 && errno != EPERM)
-				return -1;
-		}
-	} while (*pref= keep, *sep != 0);
-	return 0;
-}
-
-void makedir(char *dir, int mode, int owner, int group)
-/* Install a directory, and set it's modes. */
-{
-	struct stat st;
-
-	if (stat(dir, &st) < 0) {
-		if (errno != ENOENT) { report(dir); return; }
-
-		/* The target doesn't exist, make it. */
-		if (mode == -1) mode= 0755;
-		if (owner == -1) owner= getuid();
-		if (group == -1) group= getgid();
-
-		if (mkdirp(dir, mode, owner, group) < 0) {
-			report(dir); return;
-		}
-	} else {
-		/* The target does exist, change mode and ownership. */
-		if (mode == -1) mode= (st.st_mode & 07777) | 0555;
-
-		if ((st.st_mode & 07777) != mode) {
-			if (chmod(dir, mode) < 0) { report(dir); return; }
-		}
-		if (owner == -1) owner= st.st_uid;
-		if (group == -1) group= st.st_gid;
-		if (st.st_uid != owner || st.st_gid != group) {
-			if (chown(dir, owner, group) < 0 && errno != EPERM) {
-				report(dir); return;
-			}
-			/* Set the mode again, chown may have wrecked it. */
-			(void) chmod(dir, mode);
-		}
-	}
-}
-
-int setstack(struct exec *hdr)
-/* Set the stack size in a header.  Return true if something changed. */
-{
-	long total;
-
-	total= stack;
-	while (wordpow > 0) {
-		total *= hdr->a_cpu == A_I8086 ? 2 : 4;
-		wordpow--;
-	}
-	total+= hdr->a_data + hdr->a_bss;
-
-	if (!(hdr->a_flags & A_SEP)) {
-		total+= hdr->a_text;
-#ifdef A_PAL
-		if (hdr->a_flags & A_PAL) total+= hdr->a_hdrlen;
-#endif
-	}
-	if (hdr->a_cpu == A_I8086 && total > 0x10000L)
-		total= 0x10000L;
-
-	if (hdr->a_total != total) {
-		/* Need to change stack allocation. */
-		hdr->a_total= total;
-
-		return 1;
-	}
-	return 0;
-}
-
-void copylink(char *source, char *dest, int mode, int owner, int group)
-{
-	struct stat sst, dst;
-	int sfd, dfd, n;
-	int r, same= 0, change= 0, docopy= 1;
-	char buf[4096];
-#	define hdr ((struct exec *) buf)
-	pid_t pid = 0;
-	int status = 0;
-
-	/* Source must exist as a plain file, dest may exist as a plain file. */
-
-	if (stat(source, &sst) < 0) { report(source); return; }
-
-	if (mode == -1) {
-		mode= sst.st_mode & 07777;
-		if (!lflag || cflag) {
-			mode|= 0444;
-			if (mode & 0111) mode|= 0111;
-		}
-	}
-	if (owner == -1) owner= sst.st_uid;
-	if (group == -1) group= sst.st_gid;
-
-	if (!S_ISREG(sst.st_mode)) {
-		fprintf(stderr, "install: %s is not a regular file\n", source);
-		excode= 1;
-		return;
-	}
-	r= stat(dest, &dst);
-	if (r < 0) {
-		if (errno != ENOENT) { report(dest); return; }
-	} else {
-		if (!S_ISREG(dst.st_mode)) {
-			fprintf(stderr, "install: %s is not a regular file\n",
-									dest);
-			excode= 1;
-			return;
-		}
-
-		/* Are the files the same? */
-		if (sst.st_dev == dst.st_dev && sst.st_ino == dst.st_ino) {
-			if (!lflag && cflag) {
-				fprintf(stderr,
-				"install: %s and %s are the same, can't copy\n",
-					source, dest);
-				excode= 1;
-				return;
-			}
-			same= 1;
-		}
-	}
-
-	if (lflag && !same) {
-		/* Try to link the files. */
-
-		if (r >= 0 && unlink(dest) < 0) {
-			report(dest); return;
-		}
-
-		if (link(source, dest) >= 0) {
-			docopy= 0;
-		} else {
-			if (!cflag || errno != EXDEV) {
-				fprintf(stderr,
-					"install: can't link %s to %s: %s\n",
-					source, dest, strerror(errno));
-				excode= 1;
-				return;
-			}
-		}
-	}
-
-	if (docopy && !same) {
-		/* Copy the files, stripping if necessary. */
-		long count= LONG_MAX;
-		int first= 1;
-
-		if ((sfd= open(source, O_RDONLY)) < 0) {
-			report(source); return;
-		}
-
-		/* Open for write is less simple, its mode may be 444. */
-		dfd= open(dest, O_WRONLY|O_CREAT|O_TRUNC, mode | 0600);
-		if (dfd < 0 && errno == EACCES) {
-			(void) chmod(dest, mode | 0600);
-			dfd= open(dest, O_WRONLY|O_TRUNC);
-		}
-		if (dfd < 0) {
-			report(dest);
-			close(sfd);
-			return;
-		}
-
-		pid= 0;
-		while (count > 0 && (n= read(sfd, buf, sizeof(buf))) > 0) {
-			if (first && n >= A_MINHDR && !BADMAG(*hdr)) {
-				if (strip) {
-					count= hdr->a_hdrlen
-						+ hdr->a_text + hdr->a_data;
-#ifdef A_NSYM
-					hdr->a_flags &= ~A_NSYM;
-#endif
-					hdr->a_syms= 0;
-				}
-				if (stack != -1 && setstack(hdr)) change= 1;
-
-				if (compress != nil) {
-					/* Write first #! line. */
-					(void) write(dfd, zcat, strlen(zcat));
-
-					/* Put a compressor in between. */
-					if ((pid= filter(dfd, compress)) < 0) {
-						close(sfd);
-						close(dfd);
-						return;
-					}
-					change= 1;
-				}
-			}
-			if (count < n) n= count;
-
-			if (write(dfd, buf, n) < 0) {
-				report(dest);
-				close(sfd);
-				close(dfd);
-				if (pid != 0) (void) waitpid(pid, nil, 0);
-				return;
-			}
-			count-= n;
-			first= 0;
-		}
-		if (n < 0) report(source);
-		close(sfd);
-		close(dfd);
-		if (pid != 0 && waitpid(pid, &status, 0) < 0 || status != 0) {
-			excode= 1;
-			return;
-		}
-		if (n < 0) return;
-	} else {
-		if (stack != -1) {
-			/* The file has been linked into place.  Set the
-			 * stack size.
-			 */
-			if ((dfd= open(dest, O_RDWR)) < 0) {
-				report(dest);
-				return;
-			}
-
-			if ((n= read(dfd, buf, sizeof(*hdr))) < 0) {
-				report(dest); return;
-			}
-
-			if (n >= A_MINHDR && !BADMAG(*hdr) && setstack(hdr)) {
-				if (lseek(dfd, (off_t) 0, SEEK_SET) == -1
-					|| write(dfd, buf, n) < 0
-				) {
-					report(dest);
-					close(dfd);
-					return;
-				}
-				change= 1;
-			}
-			close(dfd);
-		}
-	}
-
-	if (stat(dest, &dst) < 0) { report(dest); return; }
-
-	if ((dst.st_mode & 07777) != mode) {
-		if (chmod(dest, mode) < 0) { report(dest); return; }
-	}
-	if (dst.st_uid != owner || dst.st_gid != group) {
-		if (chown(dest, owner, group) < 0 && errno != EPERM) {
-			report(dest); return;
-		}
-		/* Set the mode again, chown may have wrecked it. */
-		(void) chmod(dest, mode);
-	}
-	if (!change) {
-		struct utimbuf ubuf;
-
-		ubuf.actime= dst.st_atime;
-		ubuf.modtime= sst.st_mtime;
-
-		if (utime(dest, &ubuf) < 0 && errno != EPERM) {
-			report(dest); return;
-		}
-	}
-}
-
-void usage(void)
-{
-	fprintf(stderr, "\
-Usage:\n\
-  install [-lcsz#] [-o owner] [-g group] [-m mode] [-S stack] [file1] file2\n\
-  install [-lcsz#] [-o owner] [-g group] [-m mode] [-S stack] file ... dir\n\
-  install -d [-o owner] [-g group] [-m mode] directory\n");
-	exit(1);
-}
-
-void main(int argc, char **argv)
-{
-	int i= 1;
-	int mode= -1;		/* Mode of target. */
-	int owner= -1;		/* Owner. */
-	int group= -1;		/* Group. */
-	int super = 0;
-#if NGROUPS_MAX > 0
-	gid_t groups[NGROUPS_MAX];
-	int ngroups;
-	int g;
-#endif
-
-	/* Only those in group 0 are allowed to set owner and group. */
-	if (getgid() == 0) super = 1;
-#if NGROUPS_MAX > 0
-	ngroups= getgroups(NGROUPS_MAX, groups);
-	for (g= 0; g < ngroups; g++) if (groups[g] == 0) super= 1;
-#endif
-	if (!super) {
-		setgid(getgid());
-		setuid(getuid());
-	}
-
-	/* May use a filter. */
-	signal(SIGPIPE, SIG_IGN);
-
-	while (i < argc && argv[i][0] == '-') {
-		char *p= argv[i++]+1;
-		char *end;
-		unsigned long num;
-		int wp;
-		struct passwd *pw;
-		struct group *gr;
-
-		if (strcmp(p, "-") == 0) break;
-
-		while (*p != 0) {
-			switch (*p++) {
-			case 'l':	lflag= 1;	break;
-			case 'c':	cflag= 1;	break;
-			case 's':	strip= 1;	break;
-			case 'd':	dflag= 1;	break;
-			case 'z':
-				if (compress == nil) {
-					compress= COMPRESS;
-					zcat= ZCAT;
-				}
-				break;
-			case 'o':
-				if (*p == 0) {
-					if (i == argc) usage();
-					p= argv[i++];
-					if (*p == 0) usage();
-				}
-				num= strtoul(p, &end, 10);
-				if (*end == 0) {
-					if ((uid_t) num != num) usage();
-					owner= num;
-				} else {
-					if ((pw= getpwnam(p)) == nil) {
-						fprintf(stderr,
-						"install: %s: unknown user\n",
-							p);
-						exit(1);
-					}
-					owner= pw->pw_uid;
-				}
-				p= "";
-				break;
-			case 'g':
-				if (*p == 0) {
-					if (i == argc) usage();
-					p= argv[i++];
-					if (*p == 0) usage();
-				}
-				num= strtoul(p, &end, 10);
-				if (*end == 0) {
-					if ((gid_t) num != num) usage();
-					group= num;
-				} else {
-					if ((gr= getgrnam(p)) == nil) {
-						fprintf(stderr,
-						"install: %s: unknown user\n",
-							p);
-						exit(1);
-					}
-					group= gr->gr_gid;
-				}
-				p= "";
-				break;
-			case 'm':
-				if (*p == 0) {
-					if (i == argc) usage();
-					p= argv[i++];
-					if (*p == 0) usage();
-				}
-				num= strtoul(p, &end, 010);
-				if (*end != 0 || (num & 07777) != num) usage();
-				mode= num;
-				if ((mode & S_ISUID) && super && owner == -1) {
-					/* Setuid what?  Root most likely. */
-					owner= 0;
-				}
-				if ((mode & S_ISGID) && super && group == -1) {
-					group= 0;
-				}
-				p= "";
-				break;
-			case 'S':
-				if (*p == 0) {
-					if (i == argc) usage();
-					p= argv[i++];
-					if (*p == 0) usage();
-				}
-				stack= strtol(p, &end, 0);
-				wp= 0;
-				if (end == p || stack < 0) usage();
-				p= end;
-				while (*p != 0) {
-					switch (*p++) {
-					case 'm':
-					case 'M': num= 1024 * 1024L; break;
-					case 'k':
-					case 'K': num= 1024; break;
-					case 'w':
-					case 'W': num= 4; wp++; break;
-					case 'b':
-					case 'B': num= 1; break;
-					default: usage();
-					}
-					if (stack > LONG_MAX / num) usage();
-					stack*= num;
-				}
-				wordpow= 0;
-				while (wp > 0) { stack /= 4; wordpow++; wp--; }
-				break;
-			default:
-				if ((unsigned) (p[-1] - '1') <= ('9' - '1')) {
-					compress= GZIP;
-					GZIP[1][1]= p[-1];
-					zcat= GZCAT;
-					break;
-				}
-				usage();
-			}
-		}
-	}
-	/* Some options don't mix. */
-	if (dflag && (cflag || lflag || strip)) usage();
-
-	/* Don't let the user umask interfere. */
-	umask(000);
-
-	if (dflag) {
-		/* install directory */
-		if ((argc - i) != 1) usage();
-
-		makedir(argv[i], mode, owner, group);
-	} else {
-		struct stat st;
-
-		if ((argc - i) < 1) usage();
-		if ((lflag || cflag) && (argc - i) == 1) usage();
-
-		if (stat(argv[argc-1], &st) >= 0 && S_ISDIR(st.st_mode)) {
-			/* install file ... dir */
-			char *target= nil;
-			char *base;
-
-			if ((argc - i) == 1) usage();
-
-			while (i < argc-1) {
-				if ((base= strrchr(argv[i], '/')) == nil)
-					base= argv[i];
-				else
-					base++;
-				target= allocate(target, strlen(argv[argc-1])
-						+ 1 + strlen(base) + 1);
-				strcpy(target, argv[argc-1]);
-				strcat(target, "/");
-				strcat(target, base);
-
-				copylink(argv[i++], target, mode, owner, group);
-			}
-		} else {
-			/* install [file1] file2 */
-
-			copylink(argv[i], argv[argc-1], mode, owner, group);
-		}
-	}
-	exit(excode);
-}
Index: trunk/minix/commands/simple/intr.c
===================================================================
--- trunk/minix/commands/simple/intr.c	(revision 9)
+++ 	(revision )
@@ -1,148 +1,0 @@
-/*	intr 1.4 - run a command with interrupts enabled
- *							Author: Kees J. Bot
- *								17 Dec 1992
- */
-#define nil 0
-#ifndef _POSIX_SOURCE
-#define _POSIX_SOURCE 1
-#endif
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#if __minix
-static char DEV_LOG[]= "/dev/log";
-#else
-static char DEV_LOG[]= "/dev/console";
-#endif
-
-static void say(const char *s)
-{
-	write(2, s, strlen(s));
-}
-
-static void fatal(const char *label)
-{
-	int err= errno;
-
-	say("intr: ");
-	say(label);
-	say(": ");
-	say(strerror(err));
-	say("\n");
-	exit(1);
-}
-
-static void usage(void)
-{
-	say("Usage: intr [-d] [-t seconds] command [arg ...]\n");
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	int fd;
-	unsigned n= 0;
-	int daemonize= 0;
-	int i;
-
-	i= 1;
-	while (i < argc && argv[i][0] == '-') {
-		char *opt= argv[i++]+1, *end;
-		unsigned long sec;
-
-		if (opt[0] == '-' && opt[1] == 0) break;
-
-		while (*opt != 0) switch (*opt++) {
-		case 'd':
-			/* -d */
-			daemonize= 1;
-			break;
-		case 't':
-			/* -t n: alarm in n seconds. */
-			if (*opt == 0) {
-				if (i == argc) usage();
-				opt= argv[i++];
-			}
-			sec= strtoul(opt, &end, 10);
-			if (end == opt || *end != 0 || (n= sec) != sec)
-				usage();
-			opt= "";
-			break;
-		default:
-			usage();
-		}
-	}
-
-	if ((argc - i) < 1) usage();
-
-	/* Try to open the controlling tty. */
-	if ((fd= open("/dev/tty", O_RDWR)) < 0) {
-		if (errno != ENXIO) fatal("/dev/tty");
-	}
-
-	if (!daemonize) {
-		/* Bring to the foreground.  If we already have a controlling
-		 * tty then use it.  Otherwise try to allocate the console as
-		 * controlling tty and begin a process group.
-		 */
-		if (fd < 0) {
-			if (setsid() < 0) fatal("setsid()");
-
-			fd= open("/dev/console", O_RDWR);
-		}
-
-		if (fd >= 0) {
-			if (fd != 0) {
-				dup2(fd, 0);
-				close(fd);
-			}
-			dup2(0, 1);
-			dup2(0, 2);
-		}
-
-		/* Set the usual signals back to the default. */
-		signal(SIGHUP, SIG_DFL);
-		signal(SIGINT, SIG_DFL);
-		signal(SIGQUIT, SIG_DFL);
-		signal(SIGTERM, SIG_DFL);
-	} else {
-		/* Send to the background.  Redirect input to /dev/null, and
-		 * output to the log device.  Detach from the process group.
-		 */
-		if (fd >= 0) {
-			close(fd);
-
-			if (setsid() < 0) fatal("setsid()");
-		}
-		if ((fd= open("/dev/null", O_RDWR)) < 0) fatal("/dev/null");
-		if (fd != 0) {
-			dup2(fd, 0);
-			close(fd);
-		}
-		if ((fd= open(DEV_LOG, O_WRONLY)) < 0) fatal(DEV_LOG);
-		if (fd != 1) {
-			dup2(fd, 1);
-			close(fd);
-		}
-		dup2(1, 2);
-
-		/* Move to the root directory. */
-		(void) chdir("/");
-	}
-
-	/* Schedule the alarm.  (It is inherited over execve.) */
-	if (n != 0) alarm(n);
-
-	/* Call program. */
-	execvp(argv[i], argv + i);
-
-	/* Complain. */
-	fatal(argv[i]);
-	return 0;
-}
Index: trunk/minix/commands/simple/irdpd.c
===================================================================
--- trunk/minix/commands/simple/irdpd.c	(revision 9)
+++ 	(revision )
@@ -1,624 +1,0 @@
-/*	irdpd 1.10 - Internet router discovery protocol daemon.
- *							Author: Kees J. Bot
- *								28 May 1994
- * Activily solicitate or passively look for routers.
- * Based heavily on its forerunners, the irdp_sol and rip2icmp daemons by
- * Philip Homburg.
- */
-#define nil 0
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <limits.h>
-#include <unistd.h>
-#include <signal.h>
-#include <sys/ioctl.h>
-#include <sys/asynchio.h>
-#include <net/hton.h>
-#include <net/netlib.h>
-#include <net/gen/in.h>
-#include <net/gen/ip_hdr.h>
-#include <net/gen/icmp.h>
-#include <net/gen/icmp_hdr.h>
-#include <net/gen/ip_io.h>
-#include <net/gen/inet.h>
-#include <net/gen/netdb.h>
-#include <net/gen/oneCsum.h>
-#include <net/gen/socket.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_hdr.h>
-#include <net/gen/udp_io.h>
-
-#define MAX_SOLICITATIONS	    3	/* # router solicitations. */
-#define SOLICITATION_INTERVAL	    3	/* Secs between solicitate retries. */
-#define DEST_TO 	      (10*60)	/* 10 minutes */
-#define NEW_ROUTE	       (5*60)	/* 5 minutes */
-#define DANGER		       (2*60)	/* Nearing a advert timeout? */
-#define DEAD_TO		    (24L*60*60)	/* 24 hours */
-#define DEAD_PREF	    0x80000000L	/* From RFC 1256 */
-#define MaxAdvertisementInterval (DEST_TO/2)	/* Chosen to jive with RIP */
-#define AdvertisementLifetime	 DEST_TO
-#define PRIO_OFF_DEF		-1024
-#define RIP_REPLY		    2
-
-/* It's now or never. */
-#define IMMEDIATELY	((time_t) ((time_t) -1 < 0 ? LONG_MIN : 0))
-#define NEVER		((time_t) ((time_t) -1 < 0 ? LONG_MAX : ULONG_MAX))
-
-#if !__minix_vmd
-/* Standard Minix needs to choose between router discovery and RIP info. */
-int do_rdisc= 1;
-int do_rip= 0;
-#else
-/* VMD Minix can do both at once. */
-#define do_rdisc 1
-#define do_rip 1
-#endif
-
-int rip_fd;			/* For incoming RIP packet. */
-int irdp_fd;			/* Receive or transmit IRDP packets. */
-
-char *udp_device;		/* UDP device to use. */
-char *ip_device;		/* IP device to use. */
-
-int priority_offset;		/* Offset to make my routes less preferred. */
-
-int bcast= 0;			/* Broadcast adverts to all. */
-int debug= 0;
-
-char rip_buf[8192];		/* Incoming RIP packet buffer. */
-char irdp_buf[1024];		/* IRDP buffer. */
-
-typedef struct routeinfo
-{
-	u8_t		command;
-	u8_t		version;
-	u16_t		zero1;
-	struct routedata {
-		u16_t	family;
-		u16_t	zero2;
-		u32_t	ip_addr;
-		u32_t	zero3, zero4;
-		u32_t	metric;
-	} data[1];
-} routeinfo_t;
-
-typedef struct table
-{
-	ipaddr_t	tab_gw;
-	i32_t		tab_pref;
-	time_t		tab_time;
-} table_t;
-
-table_t *table;			/* Collected table of routing info. */
-size_t table_size;
-
-int sol_retries= MAX_SOLICITATIONS;
-time_t next_sol= IMMEDIATELY;
-time_t next_advert= NEVER;
-time_t router_advert_valid= IMMEDIATELY;
-time_t now;
-
-void report(const char *label)
-/* irdpd: /dev/hd0: Device went up in flames */
-{
-	fprintf(stderr, "irdpd: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-/* irdpd: /dev/house: Taking this with it */
-{
-	report(label);
-	exit(1);
-}
-
-#if DEBUG
-char *addr2name(ipaddr_t host)
-/* Translate an IP address to a printable name. */
-{
-	struct hostent *hostent;
-
-	hostent= gethostbyaddr((char *) &host, sizeof(host), AF_INET);
-	return hostent == nil ? inet_ntoa(host) : hostent->h_name;
-}
-#else
-#define addr2name(host)	inet_ntoa(host)
-#endif
-
-void print_table(void)
-/* Show the collected routing table. */
-{
-	int i;
-	table_t *ptab;
-	struct tm *tm;
-
-	for (i= 0, ptab= table; i < table_size; i++, ptab++) {
-		if (ptab->tab_time < now - DEAD_TO) continue;
-
-		tm= localtime(&ptab->tab_time);
-		printf("%-40s %6ld %02d:%02d:%02d\n",
-			addr2name(ptab->tab_gw),
-			(long) ptab->tab_pref,
-			tm->tm_hour, tm->tm_min, tm->tm_sec);
-	}
-}
-
-void advertize(ipaddr_t host)
-/* Send a router advert to a host. */
-{
-	char *buf, *data;
-	ip_hdr_t *ip_hdr;
-	icmp_hdr_t *icmp_hdr;
-	int i;
-	table_t *ptab;
-
-	buf= malloc(sizeof(*ip_hdr) + offsetof(icmp_hdr_t, ih_dun.uhd_data)
-			+ table_size * (sizeof(ipaddr_t) + sizeof(u32_t)));
-	if (buf == nil) fatal("heap error");
-
-	ip_hdr= (ip_hdr_t *) buf;
-	icmp_hdr= (icmp_hdr_t *) (ip_hdr + 1);
-
-	ip_hdr->ih_vers_ihl= 0x45;
-	ip_hdr->ih_dst= host;
-
-	icmp_hdr->ih_type= ICMP_TYPE_ROUTER_ADVER;
-	icmp_hdr->ih_code= 0;
-	icmp_hdr->ih_hun.ihh_ram.iram_na= 0;
-	icmp_hdr->ih_hun.ihh_ram.iram_aes= 2;
-	icmp_hdr->ih_hun.ihh_ram.iram_lt= htons(AdvertisementLifetime);
-	data= (char *) icmp_hdr->ih_dun.uhd_data;
-
-	/* Collect gateway entries from the table. */
-	for (i= 0, ptab= table; i < table_size; i++, ptab++) {
-		if (ptab->tab_time < now - DEAD_TO) continue;
-
-		icmp_hdr->ih_hun.ihh_ram.iram_na++;
-		if (ptab->tab_time < now - DEST_TO) ptab->tab_pref= DEAD_PREF;
-		* (ipaddr_t *) data= ptab->tab_gw;
-		data+= sizeof(ipaddr_t);
-		* (i32_t *) data= htonl(ptab->tab_pref);
-		data+= sizeof(i32_t);
-	}
-	icmp_hdr->ih_chksum= 0;
-	icmp_hdr->ih_chksum= ~oneC_sum(0, icmp_hdr, data - (char *) icmp_hdr);
-
-	if (icmp_hdr->ih_hun.ihh_ram.iram_na > 0) {
-		/* Send routing info. */
-
-		if (debug) {
-			printf("Routing table send to %s:\n", addr2name(host));
-			print_table();
-		}
-
-		if (write(irdp_fd, buf, data - buf) < 0) {
-			(errno == EIO ? fatal : report)(ip_device);
-		}
-	}
-	free(buf);
-}
-
-void time_functions(void)
-/* Perform time dependend functions: router solicitation, router advert. */
-{
-	if (now >= next_sol) {
-		char buf[sizeof(ip_hdr_t) + 8];
-		ip_hdr_t *ip_hdr;
-		icmp_hdr_t *icmp_hdr;
-
-		if (sol_retries == 0) {
-			/* Stop soliciting. */
-			next_sol= NEVER;
-#if !__minix_vmd
-			/* Switch to RIP if no router responded. */
-			if (table_size == 0) {
-				do_rip= 1;
-				do_rdisc= 0;
-			}
-#endif
-			return;
-		}
-
-		/* Broadcast a router solicitation to find a router. */
-		ip_hdr= (ip_hdr_t *) buf;
-		icmp_hdr= (icmp_hdr_t *) (ip_hdr + 1);
-
-		ip_hdr->ih_vers_ihl= 0x45;
-		ip_hdr->ih_dst= HTONL(0xFFFFFFFFL);
-
-		icmp_hdr->ih_type= ICMP_TYPE_ROUTE_SOL;
-		icmp_hdr->ih_code= 0;
-		icmp_hdr->ih_chksum= 0;
-		icmp_hdr->ih_hun.ihh_unused= 0;
-		icmp_hdr->ih_chksum= ~oneC_sum(0, icmp_hdr, 8);
-
-		if (debug) printf("Broadcasting router solicitation\n");
-
-		if (write(irdp_fd, buf, sizeof(buf)) < 0)
-			fatal("sending router solicitation failed");
-
-		/* Schedule the next packet. */
-		next_sol= now + SOLICITATION_INTERVAL;
-
-		sol_retries--;
-	}
-
-	if (now >= next_advert) {
-		/* Advertize routes to the local host (normally), or
-		 * broadcast them (to keep bad hosts up.)
-		 */
-
-		advertize(bcast ? HTONL(0xFFFFFFFFL) : HTONL(0x7F000001L));
-		next_advert= now + MaxAdvertisementInterval;
-#if !__minix_vmd
-		/* Make sure we are listening to RIP now. */
-		do_rip= 1;
-		do_rdisc= 0;
-#endif
-	}
-}
-
-void add_gateway(ipaddr_t host, i32_t pref)
-/* Add a router with given address and preference to the routing table. */
-{
-	table_t *oldest, *ptab;
-	int i;
-
-	/* Look for the host, or select the oldest entry. */
-	oldest= nil;
-	for (i= 0, ptab= table; i < table_size; i++, ptab++) {
-		if (ptab->tab_gw == host) break;
-
-		if (oldest == nil || ptab->tab_time < oldest->tab_time)
-			oldest= ptab;
-	}
-
-	/* Don't evict the oldest if it is still valid. */
-	if (oldest != nil && oldest->tab_time >= now - DEST_TO) oldest= nil;
-
-	/* Expand the table? */
-	if (i == table_size && oldest == nil) {
-		table_size++;
-		table= realloc(table, table_size * sizeof(*table));
-		if (table == nil) fatal("heap error");
-		oldest= &table[table_size - 1];
-	}
-
-	if (oldest != nil) {
-		ptab= oldest;
-		ptab->tab_gw= host;
-		ptab->tab_pref= DEAD_PREF;
-	}
-
-	/* Replace an entry if the new one looks more promising. */
-	if (pref >= ptab->tab_pref || ptab->tab_time <= now - NEW_ROUTE) {
-		ptab->tab_pref= pref;
-		ptab->tab_time= now;
-	}
-}
-
-void rip_incoming(ssize_t n)
-/* Use a RIP packet to add to the router table.  (RIP packets are really for
- * between routers, but often it is the only information around.)
- */
-{
-	udp_io_hdr_t *udp_io_hdr;
-	u32_t default_dist;
-	i32_t pref;
-	routeinfo_t *routeinfo;
-	struct routedata *data, *end;
-
-	/* We don't care about RIP packets when there are router adverts. */
-	if (now + MaxAdvertisementInterval < router_advert_valid) return;
-
-	udp_io_hdr= (udp_io_hdr_t *) rip_buf;
-	if (udp_io_hdr->uih_data_len != n - sizeof(*udp_io_hdr)) {
-		if (debug) printf("Bad sized route packet (discarded)\n");
-		return;
-	}
-	routeinfo= (routeinfo_t *) (rip_buf + sizeof(*udp_io_hdr)
-			+ udp_io_hdr->uih_ip_opt_len);
-
-	if (routeinfo->command != RIP_REPLY) {
-		if (debug) {
-			printf("RIP-%d packet command %d ignored\n",
-				routeinfo->version, routeinfo->command);
-		}
-		return;
-	}
-
-	/* Look for a default route, the route to the gateway. */
-	end= (struct routedata *) (rip_buf + n);
-	default_dist= (u32_t) -1;
-	for (data= routeinfo->data; data < end; data++) {
-		if (ntohs(data->family) != AF_INET || data->ip_addr != 0)
-			continue;
-		default_dist= ntohl(data->metric);
-		if (default_dist >= 256) {
-			if (debug) {
-				printf("Strange metric %lu\n",
-					(unsigned long) default_dist);
-			}
-		}
-	}
-	pref= default_dist >= 256 ? 1 : 512 - default_dist;
-	pref+= priority_offset;
-
-	/* Add the gateway to the table with the calculated preference. */
-	add_gateway(udp_io_hdr->uih_src_addr, pref);
-
-	if (debug) {
-		printf("Routing table after RIP-%d packet from %s:\n",
-			routeinfo->version,
-			addr2name(udp_io_hdr->uih_src_addr));
-		print_table();
-	}
-
-	/* Start advertizing. */
-	if (next_advert == NEVER) next_advert= IMMEDIATELY;
-}
-
-void irdp_incoming(ssize_t n)
-/* Look for router solicitations and router advertisements.  The solicitations
- * are probably from other irdpd daemons, we answer them if we do not expect
- * a real router to answer.  The advertisements cause this daemon to shut up.
- */
-{
-	ip_hdr_t *ip_hdr;
-	icmp_hdr_t *icmp_hdr;
-	int ip_hdr_len;
-	char *data;
-	int i;
-	int router;
-	ipaddr_t addr;
-	i32_t pref;
-	time_t valid;
-
-	ip_hdr= (ip_hdr_t *) irdp_buf;
-	ip_hdr_len= (ip_hdr->ih_vers_ihl & IH_IHL_MASK) << 2;
-	if (n < ip_hdr_len + 8) {
-		if (debug) printf("Bad sized ICMP (discarded)\n");
-		return;
-	}
-
-	icmp_hdr= (icmp_hdr_t *)(irdp_buf + ip_hdr_len);
-
-	/* Did I send this myself? */
-	if (ip_hdr->ih_src == ip_hdr->ih_dst) return;
-	if ((htonl(ip_hdr->ih_src) & 0xFF000000L) == 0x7F000000L) return;
-
-	if (icmp_hdr->ih_type != ICMP_TYPE_ROUTER_ADVER) return;
-
-	/* Incoming router advertisement, the kind of packet the TCP/IP task
-	 * is very happy with.  No need to solicit further.
-	 */
-	sol_retries= 0;
-
-	/* Add router info to our table.  Also see if the packet really came
-	 * from a router.  If so then we can go dormant for the lifetime of
-	 * the ICMP.
-	 */
-	router= 0;
-	data= (char *) icmp_hdr->ih_dun.uhd_data;
-	for (i= 0; i < icmp_hdr->ih_hun.ihh_ram.iram_na; i++) {
-		addr= * (ipaddr_t *) data;
-		data+= sizeof(ipaddr_t);
-		pref= htonl(* (i32_t *) data);
-		data+= sizeof(i32_t);
-
-		if (addr == ip_hdr->ih_src) {
-			/* The sender is in the routing table! */
-			router= 1;
-		}
-		add_gateway(addr, pref);
-	}
-
-	valid= now + ntohs(icmp_hdr->ih_hun.ihh_ram.iram_lt);
-	if (router) router_advert_valid= valid;
-
-	/* Restart advertizing close to the timeout of the advert.  (No more
-	 * irdpd adverts if the router stays alive.)
-	 */
-	if (router || next_advert > valid - DANGER)
-		next_advert= valid - DANGER;
-
-	if (debug) {
-		printf("Routing table after advert received from %s:\n",
-			addr2name(ip_hdr->ih_src));
-		print_table();
-		if (router) {
-			struct tm *tm= localtime(&router_advert_valid);
-			printf(
-			"This router advert is valid until %02d:%02d:%02d\n",
-				tm->tm_hour, tm->tm_min, tm->tm_sec);
-		}
-	}
-}
-
-void sig_handler(int sig)
-/* A signal changes the debug level. */
-{
-	switch (sig) {
-	case SIGUSR1:	debug++;		break;
-	case SIGUSR2:	debug= 0;		break;
-	}
-}
-
-void usage(void)
-{
-	fprintf(stderr,
-"Usage: irdpd [-bd] [-U udp-device] [-I ip-device] [-o priority-offset]\n");
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	int i;
-	struct servent *service;
-	udpport_t route_port;
-	nwio_udpopt_t udpopt;
-	nwio_ipopt_t ipopt;
-	asynchio_t asyn;
-	time_t timeout;
-	struct timeval tv;
-	struct sigaction sa;
-	char *offset_arg, *offset_end;
-	long arg;
-
-	udp_device= ip_device= nil;
-	offset_arg= nil;
-
-	for (i = 1; i < argc && argv[i][0] == '-'; i++) {
-		char *p= argv[i] + 1;
-
-		if (p[0] == '-' && p[1] == 0) { i++; break; }
-
-		while (*p != 0) {
-			switch (*p++) {
-			case 'U':
-				if (udp_device != nil) usage();
-				if (*p == 0) {
-					if (++i == argc) usage();
-					p= argv[i];
-				}
-				udp_device= p;
-				p= "";
-				break;
-			case 'I':
-				if (ip_device != nil) usage();
-				if (*p == 0) {
-					if (++i == argc) usage();
-					p= argv[i];
-				}
-				ip_device= p;
-				p= "";
-				break;
-			case 'o':
-				if (offset_arg != nil) usage();
-				if (*p == 0) {
-					if (++i == argc) usage();
-					p= argv[i];
-				}
-				offset_arg= p;
-				p= "";
-				break;
-			case 'b':
-				bcast= 1;
-				break;
-			case 's':
-				/*obsolete*/
-				break;
-			case 'd':
-				debug= 1;
-				break;
-			default:
-				usage();
-			}
-		}
-	}
-	if (i != argc) usage();
-
-	/* Debug level signals. */
-	sa.sa_handler= sig_handler;
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags= 0;
-	sigaction(SIGUSR1, &sa, nil);
-	sigaction(SIGUSR2, &sa, nil);
-
-	if (udp_device == nil && (udp_device= getenv("UDP_DEVICE")) == nil)
-		udp_device= UDP_DEVICE;
-
-	if (ip_device == nil && (ip_device= getenv("IP_DEVICE")) == nil)
-		ip_device= IP_DEVICE;
-
-	if (offset_arg == nil) {
-		priority_offset= PRIO_OFF_DEF;
-	} else {
-		arg= strtol(offset_arg, &offset_end, 0);
-		if (*offset_end != 0 || (priority_offset= arg) != arg) usage();
-	}
-
-	if ((service= getservbyname("route", "udp")) == nil) {
-		fprintf(stderr,
-	"irdpd: unable to look up the port number for the 'route' service\n");
-		exit(1);
-	}
-
-	route_port= (udpport_t) service->s_port;
-
-	if ((rip_fd= open(udp_device, O_RDWR)) < 0) fatal(udp_device);
-
-	udpopt.nwuo_flags= NWUO_COPY | NWUO_LP_SET | NWUO_DI_LOC
-		| NWUO_EN_BROAD | NWUO_RP_SET | NWUO_RA_ANY | NWUO_RWDATALL
-		| NWUO_DI_IPOPT;
-	udpopt.nwuo_locport= route_port;
-	udpopt.nwuo_remport= route_port;
-	if (ioctl(rip_fd, NWIOSUDPOPT, &udpopt) < 0)
-		fatal("setting UDP options failed");
-
-	if ((irdp_fd= open(ip_device, O_RDWR)) < 0) fatal(ip_device);
-
-	ipopt.nwio_flags= NWIO_COPY | NWIO_EN_LOC | NWIO_EN_BROAD
-			| NWIO_REMANY | NWIO_PROTOSPEC
-			| NWIO_HDR_O_SPEC | NWIO_RWDATALL;
-	ipopt.nwio_tos= 0;
-	ipopt.nwio_ttl= 1;
-	ipopt.nwio_df= 0;
-	ipopt.nwio_hdropt.iho_opt_siz= 0;
-	ipopt.nwio_rem= HTONL(0xFFFFFFFFL);
-	ipopt.nwio_proto= IPPROTO_ICMP;
-
-	if (ioctl(irdp_fd, NWIOSIPOPT, &ipopt) < 0)
-		fatal("can't configure ICMP channel");
-
-	asyn_init(&asyn);
-
-	while (1) {
-		ssize_t r;
-
-		if (do_rip) {
-			/* Try a RIP read. */
-			r= asyn_read(&asyn, rip_fd, rip_buf, sizeof(rip_buf));
-			if (r < 0) {
-				if (errno == EIO) fatal(udp_device);
-				if (errno != EINPROGRESS) report(udp_device);
-			} else {
-				now= time(nil);
-				rip_incoming(r);
-			}
-		}
-
-		if (do_rdisc) {
-			/* Try an IRDP read. */
-			r= asyn_read(&asyn, irdp_fd, irdp_buf,
-							sizeof(irdp_buf));
-			if (r < 0) {
-				if (errno == EIO) fatal(ip_device);
-				if (errno != EINPROGRESS) report(ip_device);
-			} else {
-				now= time(nil);
-				irdp_incoming(r);
-			}
-		}
-		fflush(stdout);
-
-		/* Compute the next wakeup call. */
-		timeout= next_sol < next_advert ? next_sol : next_advert;
-
-		/* Wait for a RIP or IRDP packet or a timeout. */
-		tv.tv_sec= timeout;
-		tv.tv_usec= 0;
-		if (asyn_wait(&asyn, 0, timeout == NEVER ? nil : &tv) < 0) {
-			/* Timeout? */
-			if (errno != EINTR && errno != EAGAIN)
-				fatal("asyn_wait()");
-			now= time(nil);
-			time_functions();
-		}
-	}
-}
Index: trunk/minix/commands/simple/isoread.c
===================================================================
--- trunk/minix/commands/simple/isoread.c	(revision 9)
+++ 	(revision )
@@ -1,865 +1,0 @@
-/*
- * isoread.c
- *
- * isoread reads a file system in ISO9660 or HIGH SIERRA format from
- * a given device.
- *
- * Apr  5 1995    Michel R. Prevenier 
- * Nov 16 1996    Kees J. Bot        -- bug fix: isoread filename matching 
- * Dec  7 1997    Albert S. Woodhull -- bug fix: return values
- *                                       "   " : isodir filename handling
- *                                   -- added  : isoread -a option  
- * Mar 21 2000    Michael A. Temari  -- bug fix: look_up only searched first
- *                                             : block of directory
- *                                             : stack overflow in recurse_dir
- *                                             : and various other bugs
- * Apr 14 2002    Michael A. Temari  -- bug fix: fixed recursing directories
- *                                             : and printing dates 2000 and 
- *                                             : later
- * May 14 2002    Kees J. Bot        -- bug fix: fixed error messages
- * Mar 14 2003    Kees J. Bot        -- added  : iso{dir,read} -B option
- * Jul 24 2003    Michael A. Temari  -- bug fix: bytes to blocks roundup fix
- */
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <sys/times.h>
-#include <unistd.h>
-
-/*             
- *  definitions used by the ISO9660 and HIGH SIERRA file system
- */
-
-#define ISO9660_ID	"CD001"
-#define HIGH_SIERRA_ID	"CDROM"
-#define BLOCK_SIZE	2048
-#define BLOCK_SHIFT	11
-
-
-/* Fields in a ISO9660 volume descriptor */
-struct iso9660_descriptor
-{
-  char type[1];		
-  char id[5];			
-  char version[1];		
-  char reserved1[1];		
-  char system_id[32];		
-  char volume_id[32];		
-  char reserved2[8];		
-  char volume_size[8];	
-  char reserved3[32];		
-  char volume_set_size[4];	
-  char volume_seq_nr[4];
-  char block_size[4];	
-  char path_table_size[8];	
-  char type_l_path_table[4];	
-  char opt_type_l_path_table[4];	
-  char type_m_path_table[4];	
-  char opt_type_m_path_table[4];	
-  char root_dir_entry[34];
-  char vol_set_id[128];	
-  char publ_id[128];
-  char prep_id[128];	
-  char appl_id[128];	
-  char copyright_file_id[37];	
-  char abstract_file_id[37];	
-  char bibl_file_id[37];
-  char creation_date[17];	
-  char mod_date[17];	
-  char exp_date[17];	
-  char eff_date[17];	
-  char file_struc_version[1];
-  char reserved4[1];		
-  char appl_data[512];	
-  char reserved5[653];			
-};
-
-
-/* Fields in a High Sierra volume descriptor */
-struct high_sierra_descriptor
-{
-  char reserved1[8];
-  char type[1];	
-  char id[5];		
-  char version[1];	
-  char reserved2[1];	
-  char system_id[32];
-  char volume_id[32];
-  char reserved3[8];	
-  char volume_size[8];	
-  char reserved4[32];
-  char vol_set_size[4];
-  char volume_seq_nr[4];	
-  char block_size[4];	
-  char path_table_size[8];
-  char type_l_path_table[4];
-  char reserved5[28];		
-  char root_dir_entry[34];
-};
-
-
-/* Fields in a directory entry */
-struct dir_entry 
-{
-  char length[1];	
-  char ext_attr_length[1];
-  char first_block[8];
-  char size[8];	
-  char date[7];
-  char flags[1];	
-  char file_unit_size[1];
-  char interleave[1];
-  char volume_seq_nr[4];	
-  char name_length[1];
-  char name[1];
-};
-
-
-#define STDOUT		stdout
-#define STDERR		stderr
-#define NULL_DIR	(struct dir_entry *) 0
-#define MAX_NAME_LENGTH	255
-#define MAX_PATH_LENGTH	1024
-
-#define NR_OF_CHARS	13 
-#define NR_OF_BLANKS	2
-#define NR_OF_COLS	(80 / (NR_OF_CHARS + NR_OF_BLANKS))
-
-/* This macro always returns a lower case character */
-#define LOWER_CASE(CHR) (CHR >= 'A' && CHR <= 'Z' ? CHR | 0x20 : CHR) 
-
-/* Macro's for determining . , .. and normal directory entries */
-#define IS_DOT(PTR) (PTR->name_length[0] == 1 && PTR->name[0] == 0 ? 1 : 0)
-#define IS_DOT_DOT(PTR) (PTR->name_length[0] == 1 && PTR->name[0] == 1 ? 1 : 0)
-#define IS_DIR(PTR) (PTR->flags[-High_Sierra] & 2 ? 1 : 0)
-
-
-_PROTOTYPE (int main, (int argc, char **argv));
-_PROTOTYPE (int iso_cmp, (char *name, struct dir_entry *dir_ptr, int dir_flag));
-_PROTOTYPE (void list_dir, (struct dir_entry *dir_ptr));
-_PROTOTYPE (void list_file, (struct dir_entry *dir_ptr));
-_PROTOTYPE (struct dir_entry *look_up, (char *name));
-_PROTOTYPE (void recurse_dir, (char *path, struct dir_entry *dir_ptr));
-_PROTOTYPE (void read_device, (long offset, int nr_of_bytes, char *buffer));
-_PROTOTYPE (int valid_fs, (void) );               
-_PROTOTYPE (void usage, (void) );               
-_PROTOTYPE (void print_date, (char *date));
-_PROTOTYPE (void print_dir_date, (char *date));
-_PROTOTYPE (void iso_info, (struct iso9660_descriptor *vol_desc));
-_PROTOTYPE (void hs_info, (struct high_sierra_descriptor *vol_desc));
-_PROTOTYPE (int iso_711, (char *c));
-_PROTOTYPE (int iso_712, (char *c));
-_PROTOTYPE (int iso_721, (char *c));
-_PROTOTYPE (int iso_722, (char *c));
-_PROTOTYPE (int iso_723, (char *c));
-_PROTOTYPE (long iso_731, (char *c));
-_PROTOTYPE (long iso_732, (char *c));
-_PROTOTYPE (long iso_733, (char *c));
-
-
-char Buffer[BLOCK_SIZE];	            /* buffer to hold read data */
-int Device;				    /* global file descriptor */
-struct iso9660_descriptor *Iso_Vol_Desc;    /* iso9660 volume descriptor */
-struct high_sierra_descriptor *Hs_Vol_Desc; /* high sierra volume descriptor */
-int High_Sierra = 0;                        /* 1 = high sierra format */
-int Iso9660 = 0;                            /* 1 = iso9660 format */
-
-/* This comes in handy when printing the date */
-char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
-
-/* Flags displaying what to do  */
-int Read_File = 0;      /* 1 = Read file */
-int Read_Dir = 0;	/* 1 = Read directory entry */
-int Read_Info = 0;      /* 1 = Read volume descriptor */
-int Recurse = 0;        /* 1 = Recursively descend directories */
-int Verbose = 0;        /* 1 = Print all info on directories */
-int ByteOffset = 0;     /* 1 = Print byte offset and length of files */
-int Aflag = 0;          /* 1 = Suppress output of \r  */
-
-int iso_cmp(name, dir_ptr, dir_flag)
-char *name;
-struct dir_entry *dir_ptr;
-int dir_flag;
-{
-/* Compare name with directory entries, looking for match with a dirname.
- * An iso9660 filename is terminated by ";n", where n will probably 
- * be 1. A directory name is not terminated by anything special, it may be
- * followed by a \0 if padding is needed to put the following directory 
- * entry on an even address.
- */
-  int i;
-  int len;
-
-  /* First match the filename */
-  len = strlen(name);
-  if (len > iso_711(dir_ptr->name_length)) return 1;
-  for (i = 0; i < len; i++)
-  {
-    if (dir_ptr->name[i] == ';') return 1;	/* found end of a filename */ 
-    if (name[i] != LOWER_CASE(dir_ptr->name[i])) return 1; /* match failed */
-  }
-  if (dir_ptr->name[i] != ';' && i != len) return 1; /* incomplete match */
-
-  /* The filename is ok, now look at the file type */
-  if (dir_flag && !IS_DIR(dir_ptr)) return 1;  /* File type not correct */
-
-  return 0; 
-}
-
-
-void usage()
-{
-  if (Read_Dir)
-   fprintf (STDERR, "Usage: isodir [-lrB] inputfile [dir]\n");
-  else if (Read_Info)
-   fprintf (STDERR, "Usage: isoinfo inputfile\n");
-  else
-   fprintf (STDERR, "Usage: isoread [-a] inputfile file\n");
-  exit(1);
-}
-
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  struct dir_entry *entry;
-  char path[MAX_PATH_LENGTH];
-  char *input_file;
-  char *basename;
-  char *file_name;
-  int i,j;
-
-  /* Read arguments */
-  basename = argv[0];
-  while (*argv[0] != '\0') 
-    if (*argv[0]++ == '/') basename = argv[0];
-
-  if (strcmp(basename,"isodir") == 0) Read_Dir = 1;
-  else if (strcmp(basename,"isoinfo") == 0) Read_Info = 1;
-  else Read_File = 1;
-
-  if ((argc > 5 && Read_Dir) || (argc != 2 && Read_Info) ||
-     (argc > 4 && Read_File)) usage();
-
-  i = 1;
-
-  while (i < argc && argv[i][0] == '-')
-  {
-    char *opt = argv[i++] + 1;
-
-    if (opt[0] == '-' && opt[1] == '\0') break;
-
-    while (*opt != '\0')
-    {
-      if (Read_Info) usage();
-      if (Read_Dir)
-      switch (*opt++)
-      {
-	case 'r':	Recurse = 1; break;  
-	case 'l':	Verbose = 1; break;
-	case 'B':	ByteOffset = 1; break;
-	default:	usage();
-      }
-      if (Read_File)
-      switch (*opt++)
-      {
-	case 'a':	Aflag = 1; break;    
-	case 'B':	ByteOffset = 1; break;
-	default:	usage();
-      }
-    }
-  }
-
-  if (i >= argc) usage();
-  input_file = argv[i++];
-
-  if (Read_File)
-  {
-    if (i >= argc) usage();
-    file_name = argv[i++];
-  }
-
-  if (Read_Dir)
-  {
-    file_name = "/";
-    if (i < argc)
-    {
-      file_name = argv[i++];
-    }
-  }
-
-  if (i < argc) usage();
-  
-  if (Read_File || Read_Dir)
-  {
-    for (i=0; file_name[i] != '\0'; i++) 
-      path[i] = LOWER_CASE(file_name[i]);
-    path[i] = '\0';
-  }
- 
-  /* Open file system (file or device) */
-  if ((Device = open(input_file, O_RDONLY)) < 0) 
-  {
-    fprintf (STDERR, "cannot open %s: %s\n", input_file, strerror(errno));
-    exit(-1);
-  }
-
-  
-  if (!valid_fs())
-  {
-    fprintf (STDERR, "File system not in ISO9660 or HIGH SIERRA format \n");
-    exit(-1);
-  }
-
-  
-  if (Read_Info)
-  {
-    if (Iso9660) 
-      iso_info(Iso_Vol_Desc);
-    else 
-      hs_info(Hs_Vol_Desc);
-    exit(0);
-  }
-
-  /* Lookup file */
-  if ((entry = look_up(path)) != NULL_DIR)
-  {
-    if (Read_Dir)
-      if (Recurse) recurse_dir(path,entry);
-      else list_dir(entry);
-    else
-      list_file(entry);
-  }
-  else
-  {
-    if (Read_Dir)
-      fprintf (STDERR, "Directory");
-    else
-      fprintf (STDERR, "File");
-    fprintf (STDERR, " %s not found\n", path);
-    exit(-1);
-  }
-  return 0;
-}
-
-
-struct dir_entry *look_up(path)
-char *path;
-{
-  /* Lookup a file name */
-
-  struct dir_entry *dir_ptr;
-  long block;
-  int nr_of_blocks;
-  int offset;
-  char name[MAX_NAME_LENGTH + 1];
-  int name_index = 0;
-  int last_in_path = 0;
-  int found;
-  int i,j;
-
-  /* Get the right dir entry structure */
-  if (Iso9660)
-    dir_ptr = (struct dir_entry *) Iso_Vol_Desc->root_dir_entry;  
-  else
-    dir_ptr = (struct dir_entry *) Hs_Vol_Desc->root_dir_entry;  
-
-  /* If we look for the root we already have the right entry */
-  if (path[0] == '/')
-    if (strlen(path) == 1) return dir_ptr;
-    else name_index = 1; /* first name in path */
-
-  /* Keep searching for the path elements until all are found */
-  while (!last_in_path)
-  {
-    /* Get next name in path */ 
-    for (i = name_index; i < strlen(path); i++)
-    {
-      if (path[i] == '/') break;
-      name[i - name_index] = path[i];
-    }
-    last_in_path = 
-           (i == strlen(path) || (i == strlen(path) - 1 && path[i] == '/'));
-    name[i-name_index] = '\0';
-    name_index = i + 1;
-   
-    /* Get block of next directory */
-    block = iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length);
-    nr_of_blocks = (iso_733(dir_ptr->size) + (BLOCK_SIZE-1)) >> BLOCK_SHIFT;
-
-    /* Search for file in dir entry */
-    found = 0;
-    for (j=0; j < nr_of_blocks && !found; j++) 
-    {
-      /* Read a directory block */
-      read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
-      block++;
-
-      dir_ptr = (struct dir_entry *) Buffer;
-
-      offset = 0;
-      /* Compare with all entries in this block */
-      while (iso_711(dir_ptr->length) > 0 && offset < BLOCK_SIZE)
-      {
-        if (iso_cmp(name, dir_ptr,
-            (Read_Dir || (!Read_Dir && !last_in_path))) == 0) 
-        {
-          found = 1;
-          break;
-        }
-        /* Next entry */
-        offset += iso_711(dir_ptr->length);
-        dir_ptr = (struct dir_entry *) (Buffer + offset);
-      }
-    }
-    if (!found) return NULL_DIR;   /* path element not found */ 
-  }
-  return dir_ptr;
-}
-  
-
-void recurse_dir(path, dir_ptr)
-char *path;
-struct dir_entry *dir_ptr;
-{
-  /* Recursively descend all directories starting with dir_ptr */
-
-  char tmp_path[MAX_PATH_LENGTH];
-  int i,j, path_length;
-  long block, saveblock, dblock;
-  int nr_of_blocks;
-  int offset = 0; 
-
-  
-  /* Save block number and nr of blocks of current dir entry because 
-   * list_dir changes dir_ptr 
-   */
-  block = iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length);
-  nr_of_blocks = (iso_733(dir_ptr->size) + (BLOCK_SIZE-1)) >> BLOCK_SHIFT;
-
-  /* Add a trailing / to path if necessary */
-  path_length = strlen(path);
-  if (path[path_length-1] != '/')
-  {
-    path[path_length++] = '/';
-    path[path_length] = '\0';
-  }
-
-  /* Print current path of directory, and list contents of directory */
-  fprintf(STDOUT,"directory %s:\n\n", path);
-  list_dir(dir_ptr);
-  fprintf(STDOUT,"\n\n");
-  
-  for (j=0; j < nr_of_blocks; j++) 
-  {
-    read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
-    saveblock = block++;
-
-    /* Save buffer, because the next recursive call destroys 
-     * the global Buffer 
-     */
-    dir_ptr = (struct dir_entry *) Buffer;
-
-    /* Search this dir entry for directories */
-    offset = 0;
-    while (iso_711(dir_ptr->length) != 0 && offset < BLOCK_SIZE)
-    {
-      /* Is current file a directory and not the . or .. entries */
-      if (IS_DIR(dir_ptr)  && !IS_DOT(dir_ptr) && !IS_DOT_DOT(dir_ptr))
-      {
-        /* setup path for next recursive call */
-        for (i=0; i<path_length; i++) tmp_path[i] = path[i]; 
-        for (i=0;i<iso_711(dir_ptr->name_length) && dir_ptr->name[i] != ';';i++)
-          tmp_path[i+path_length] = LOWER_CASE(dir_ptr->name[i]);
-        tmp_path[i+path_length] = '/';
-        tmp_path[i+1+path_length] = '\0';
-  
-        /* Read block of directory we found */
-        dblock = iso_733(dir_ptr->first_block);
-        read_device(dblock*BLOCK_SIZE, BLOCK_SIZE, Buffer);
-  
-        /* And start all over again with this entry */
-        recurse_dir(tmp_path, (struct dir_entry *) Buffer);
-
-        /* get the block we were looking at */
-        read_device(saveblock*BLOCK_SIZE, BLOCK_SIZE, Buffer);
-      }
-
-      /* Go to the next file in this directory */
-      offset += iso_711(dir_ptr->length);
-      dir_ptr = (struct dir_entry *) (Buffer + offset);
-    }
-  }
-}
-    
-
-void list_dir(dir_ptr)
-struct dir_entry *dir_ptr;
-{
-  /* List all entries in a directory */
-  int tty;
-  long block;
-  int nr_of_blocks;
-  int i,j;
-  int offset = 0;
-  char name[NR_OF_CHARS+NR_OF_BLANKS+1];
-  int name_len;
-  int column = 0;
-  int skip = 0;
-
-  tty = isatty(STDOUT_FILENO);
-  /* Get first block of directory */
-  block = iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length);
-  nr_of_blocks = (iso_733(dir_ptr->size) + (BLOCK_SIZE-1)) >> BLOCK_SHIFT;
-
-  /* Read all directory blocks and display their contents */
-  for (j=0; j < nr_of_blocks; j++) 
-  {
-    read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
-    block++;
-
-    dir_ptr = (struct dir_entry *) (Buffer);
-    offset = 0;
-    while (iso_711(dir_ptr->length) != 0 && offset < BLOCK_SIZE)
-    {
-      name_len = 0;
-      if (IS_DOT(dir_ptr))
-      {
-        name[name_len++] =  '.';
-        if (!Verbose) skip = 1;
-      }
-      else
-      {
-        if (IS_DOT_DOT(dir_ptr))
-        { 
-          name[name_len++] =  '.';
-          name[name_len++] =  '.';
-          if (!Verbose) skip = 1;
-        }
-        else
-        {
-          for (i=0; i<iso_711(dir_ptr->name_length) &&
-                    i<NR_OF_CHARS; i++) 
-          {
-            if (dir_ptr->name[i] == ';') break;
-            name[name_len++] = LOWER_CASE(dir_ptr->name[i]);
-          }
-          if (IS_DIR(dir_ptr) && tty) name[name_len++] = '/';
-        }
-      }
-      if (!skip)
-      {
-        if (ByteOffset)
-        {
-          fprintf (STDOUT, "%10ld ",
-            (iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length))
-              * BLOCK_SIZE);
-        }
-        if (Verbose || ByteOffset)
-        {
-          fprintf (STDOUT, "%10ld ",  iso_733(dir_ptr->size));
-        }
-        if (Verbose)
-        {
-          print_dir_date(dir_ptr->date);
-          fprintf (STDOUT, " ");
-        }
-	if(!tty)
-		name[name_len] = '\0';
-	else {
-	        for(i=name_len; i<(NR_OF_CHARS+NR_OF_BLANKS); i++) name[i] = ' ';
-	        name[NR_OF_CHARS+NR_OF_BLANKS] = '\0';
-	}
-        fprintf(STDOUT, "%s", name);
-        if (!(Verbose || ByteOffset))
-        {
-          column++;
-          if (column >= NR_OF_COLS || !tty) 
-          {
-            column = 0;
-            fprintf(STDOUT,"\n");
-          }
-        }
-        else fprintf(STDOUT,"\n");
-      }
-      skip = 0;
-      offset += iso_711(dir_ptr->length);
-      dir_ptr = (struct dir_entry *) (Buffer+offset);
-    }
-  }
-  if (!Verbose && column) fprintf(STDOUT,"\n");
-}
-
-
-void print_dir_date(date)
-char *date;
-{
-  /* Print date in a directory entry */
-
-  int m;
-
-  m = iso_711(&date[1]) - 1;
-  if(m < 0 || m > 11)
-  	fprintf(STDOUT, "   ");
-  else
-	fprintf(STDOUT,"%.3s",&months[m*3]);
-
-  fprintf (STDOUT, " %02d %04d %02d:%02d:%02d",
-           date[2],
-           1900+date[0],
-           date[3],
-           date[4],
-           date[5]);
-}
-
-
-void list_file(dir_ptr)
-struct dir_entry *dir_ptr;
-{
-  /* List contents of a file */
-
-  int i;
-  long block;
-  long size;
-  char c;
-
-  block = iso_733(dir_ptr->first_block);
-  size = iso_733(dir_ptr->size);
-
-  if (ByteOffset) {
-    fprintf(STDOUT, "%ld %ld\n", block*BLOCK_SIZE, size);
-    return;
-  }
-
-  while (size > 0)
-  if (Aflag == 1) {
-    read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
-      for (i=0; ((i < size) && (i < BLOCK_SIZE)); i++)
-        if (Buffer[i] != '\r') fprintf(STDOUT, "%c", Buffer[i]);
-    size-= BLOCK_SIZE;
-    block++;
-  } else {
-    read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
-      for (i=0; ((i < size) && (i < BLOCK_SIZE)); i++)
-        fprintf(STDOUT, "%c", Buffer[i]);
-    size-= BLOCK_SIZE;
-    block++;
-  }
-}
-
-
-void print_date(date)
-char *date;
-{
-  /* Print the date in a volume descriptor */
-
-  fprintf (STDOUT, "%c%c-%c%c-%c%c%c%c %c%c:%c%c:%c%c",
-           date[4],
-           date[5],
-           date[6],
-           date[7],
-           date[0],
-           date[1],
-           date[2],
-           date[3],
-           date[8],
-           date[9],
-           date[10],
-           date[11],
-           date[12],
-           date[13]);
-}
-
-void iso_info(vol_desc)
-struct iso9660_descriptor *vol_desc;
-{
-  int i;
-
-  fprintf (STDOUT, "Format: ISO9660 \n");
-  fprintf (STDOUT, "System id: ");
-  for (i=0; i< sizeof(vol_desc->system_id); i++) 
-    fprintf(STDOUT, "%c", vol_desc->system_id[i]);
-  fprintf (STDOUT, "\n");
-  fprintf (STDOUT, "Volume id: ");
-  for (i=0; i< sizeof(vol_desc->volume_id); i++) 
-    fprintf(STDOUT, "%c", vol_desc->volume_id[i]);
-  fprintf (STDOUT, "\n");
-  fprintf (STDOUT, "Volume size: %ld Kb\n", iso_733(vol_desc->volume_size)*2);
-  fprintf (STDOUT, "Block size: %d bytes \n", iso_723(vol_desc->block_size));
-  fprintf (STDOUT, "Creation date: ");
-  print_date(vol_desc->creation_date); 
-  fprintf(STDOUT, "\n");
-  fprintf (STDOUT, "Modification date: ");
-  print_date(vol_desc->mod_date); 
-  fprintf (STDOUT, "\n");
-  fprintf (STDOUT, "Expiration date: ");
-  print_date(vol_desc->exp_date); 
-  fprintf (STDOUT, "\n");
-  fprintf (STDOUT, "Effective date: ");
-  print_date(vol_desc->eff_date); 
-  fprintf (STDOUT, "\n");
-}
-
-
-void hs_info(vol_desc)
-struct high_sierra_descriptor *vol_desc;
-{
-  int i;
-
-  fprintf (STDOUT, "Format: HIGH SIERRA \n");
-  fprintf (STDOUT, "System id: ");
-  for (i=0; i< sizeof(vol_desc->system_id); i++) 
-    fprintf(STDOUT, "%c", vol_desc->system_id[i]);
-  fprintf (STDOUT, "\n");
-  fprintf (STDOUT, "Volume id: ");
-  for (i=0; i< sizeof(vol_desc->volume_id); i++) 
-    fprintf(STDOUT, "%c", vol_desc->volume_id[i]);
-  fprintf (STDOUT, "\n");
-  fprintf (STDOUT, "Volume size: %ld Kb\n", (iso_733(vol_desc->volume_size)*2));
-  fprintf (STDOUT, "Block size: %d bytes \n", iso_723(vol_desc->block_size));
-}
-  
-
-int valid_fs()               
-{
-
-  int i;
-
-  /* search for a volume descriptor */
-  for (i=16; i<100; i++)
-  {
-  
-    read_device((long)(i)*BLOCK_SIZE, BLOCK_SIZE, Buffer);
-
-    Iso_Vol_Desc = (struct iso9660_descriptor *) Buffer; 
-    Hs_Vol_Desc = (struct high_sierra_descriptor *) Buffer; 
-    
-    if (strncmp(Iso_Vol_Desc->id, ISO9660_ID, sizeof Iso_Vol_Desc->id) == 0)
-    {
-      /* iso_info(Iso_Vol_Desc); */
-      Iso9660 = 1;
-      break;  
-    }
-
-    if (strncmp(Hs_Vol_Desc->id, HIGH_SIERRA_ID, sizeof Hs_Vol_Desc->id) == 0)
-    {
-      /* hs_info(Hs_Vol_Desc); */
-      High_Sierra = 1; 
-      break;  
-    }
-  }
-
-  if (i >= 100) return 0;
-  return 1;
-}
-
-
-void read_device(offset, nr_of_bytes, buffer)
-long offset;
-int nr_of_bytes;
-char *buffer;
-{
-  int bytes_read;
-
-  if (lseek(Device, offset, SEEK_SET) == -1) 
-  {
-	fflush (stdout);
-	fprintf (STDERR, "seek error: %s\n", strerror(errno));
-	exit(1);
-  }
-
-  bytes_read = read(Device, buffer, nr_of_bytes);
-  if (bytes_read != nr_of_bytes) 
-  {
-  	fprintf (STDERR, "read error: %s\n",
-	    bytes_read >= 0 ? "Short read" : strerror(errno));
-  	exit (1);
-  }
-}
-
-
-/* The ISO9660 functions */
-
-int iso_711 (c)
-char *c;
-{
-  return (*c & 0xff);
-}
-
-
-int iso_712 (c)
-char *c;
-{
-  int n;
-	
-  n = *c;
-  if (n & 0x80) n |= 0xffffff00;
-  return n;
-}
-
-int iso_721 (c)
-char *c;
-{
-  return ((c[0] & 0xff) | ((c[1] & 0xff) << 8));
-}
-
-int iso_722 (c)
-char *c;
-{
-  return (((c[0] & 0xff) << 8) | (c[1] & 0xff));
-}
-
-int iso_723 (c)
-char *c;
-{
-  if (c[0] != c[3] || c[1] != c[2]) 
-  {
-    fprintf (STDERR, "Invalid ISO 7.2.3 number\n");
-    exit (1);
-  }
-  return (iso_721 (c));
-}
-
-long iso_731 (c)
-char *c;
-{
-  return ((long)(c[0] & 0xff)
-       | ((long)(c[1] & 0xff) << 8)
-       | ((long)(c[2] & 0xff) << 16)
-       | ((long)(c[3] & 0xff) << 24));
-}
-
-
-long iso_732 (c)
-char *c;
-{
-  return (((long)(c[0] & 0xff) << 24)
-        | (((long)c[1] & 0xff) << 16)
-        | (((long)c[2] & 0xff) << 8)
-        | ((long)c[3] & 0xff));
-}
-
-long iso_733 (c)
-char *c;
-{
-int i;
-
-  for (i = 0; i < 4; i++) 
-  {
-    if (c[i] != c[7-i]) 
-    {
-      fprintf (STDERR, "Invalid ISO 7.3.3 number\n");
-      exit (1);
-    }
-  }
-  return (iso_731(c));
-}
Index: trunk/minix/commands/simple/join.c
===================================================================
--- trunk/minix/commands/simple/join.c	(revision 9)
+++ 	(revision )
@@ -1,360 +1,0 @@
-/* join - relation data base operator	Author:  Saeko Hirabayashi */
-
-/* Written by Saeko Hirabayashi, 1989.
- * 1992-01-28 Modified by Kouichi Hirabayashi to add some POSIX1003.2 options.
- *
- * This a free program.
- */
-
-#include <string.h>
-#include <stdio.h>
-
-#define MAXFLD	200		/* maximum # of fields to accept */
-
-_PROTOTYPE(void main, (int argc, char **argv));
-_PROTOTYPE(void error, (char *s, char *t));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void match, (void));
-_PROTOTYPE(void f1_only, (void));
-_PROTOTYPE(void f2_only, (void));
-_PROTOTYPE(void output, (int flag));
-_PROTOTYPE(void outfld, (int file));
-_PROTOTYPE(void outputf, (int flag));
-_PROTOTYPE(int compare, (void));
-_PROTOTYPE(int get1, (void));
-_PROTOTYPE(int get2, (int back));
-_PROTOTYPE(int getrec, (int file));
-_PROTOTYPE(int split, (int file));
-_PROTOTYPE(int atoi, (char *str));
-_PROTOTYPE(int exit, (int val));
-_PROTOTYPE(FILE * efopen, (char *file, char *mode));
-_PROTOTYPE(void (*outfun), (int file));	/* output func: output() or outputf()*/
-
-#define F1	1
-#define F2	2
-#define SEP	(sep ? sep : ' ')
-
-FILE *fp[2];			/* file pointer for file1 and file2 */
-long head;			/* head of the current (same)key group of the
-				 * file2 */
-
-char buf[2][BUFSIZ];		/* input buffer for file1 and file2 */
-char *fld[2][MAXFLD];		/* field vector for file1 and file2 */
-int nfld[2];			/* # of fields for file1 and file2 */
-
-int kpos[2];			/* key field position for file1 and file2
-				 * (from 0) */
-char oldkey[BUFSIZ];		/* previous key of the file1 */
-
-struct {			/* output list by -o option */
-  int o_file;			/* file #: 0 or 1 */
-  int o_field;			/* field #: 0, 1, 2, .. */
-} olist[MAXFLD];
-int nout;			/* # of output filed */
-
-int aflag;			/* n for '-an': F1 or F2 or both */
-int vflag;			/* n for '-vn': F1 or F2 or both */
-char *es;			/* s for '-e s' */
-char sep;			/* c for -tc: filed separator */
-char *cmd;			/* name of this program */
-
-void main(argc, argv)
-int argc;
-char **argv;
-{
-  register char *s;
-  int c, i, j;
-
-  cmd = argv[0];
-  outfun = output;		/* default output form */
-
-  while (--argc > 0 && (*++argv)[0] == '-' && (*argv)[1]) {
-	/* "-" is a file name (stdin) */
-	s = argv[0] + 1;
-	if ((c = *s) == '-' && !s[1]) {
-		++argv;
-		--argc;
-		break;		/* -- */
-	}
-	if (*++s == '\0') {
-		s = *++argv;
-		--argc;
-	}
-	switch (c) {
-	    case 'a':		/* add unpairable line to output */
-		vflag = 0;
-		switch (*s) {
-		    case '1':	aflag |= F1;	break;
-		    case '2':	aflag |= F2;	break;
-		    default:	aflag |= (F1 | F2);	break;
-		}
-		break;
-
-	    case 'e':		/* replace empty field by es */
-		es = s;
-		break;
-
-	    case 'j':		/* key field (obsolute) */
-		c = *s++;
-		if (*s == '\0') {
-			s = *++argv;
-			--argc;
-		}
-
-	    case '1':		/* key field of file1 */
-	    case '2':		/* key field of file2 */
-		i = atoi(s) - 1;
-
-		switch (c) {
-		    case '1':	kpos[0] = i;	break;
-		    case '2':	kpos[1] = i;	break;
-	            default:	kpos[0] = kpos[1] = i;
-				break;
-		}
-		break;
-
-	    case 'o':		/* specify output format */
-		do {
-			i = j = 0;
-			sscanf(s, "%d.%d", &i, &j);
-			if (i < 1 || j < 1 || i > 2) usage();
-			olist[nout].o_file = i - 1;
-			olist[nout].o_field = j - 1;
-			nout++;
-			if ((s = strchr(s, ',')) != (char *) 0)
-				s++;
-			else {
-				s = *++argv;
-				--argc;
-			}
-		} while (argc > 2 && *s != '-');
-		++argc;
-		--argv;		/* compensation */
-		outfun = outputf;
-		break;
-
-	    case 't':		/* tab char */
-		sep = *s;
-		break;
-
-	    case 'v':		/* output unpairable line only */
-		aflag = 0;
-		switch (*s) {
-		    case '1':	vflag |= F1;	break;
-		    case '2':	vflag |= F2;	break;
-		    default:	vflag |= (F1 | F2);	break;
-		}
-		break;
-
-	    default:	usage();
-	}
-  }
-  if (argc != 2) usage();
-
-  fp[0] = strcmp(argv[0], "-") ? efopen(argv[0], "r") : stdin;
-  fp[1] = efopen(argv[1], "r");
-
-  nfld[0] = get1();		/* read file1 */
-  nfld[1] = get2(0);		/* read file2 */
-
-  while (nfld[0] || nfld[1]) {
-	if ((i = compare()) == 0)
-		match();
-	else if (i < 0)
-		f1_only();
-	else
-		f2_only();
-  }
-  fflush(stdout);
-
-  exit(0);
-}
-
-void usage()
-{
-  fprintf(stderr,
-    "Usage: %s [-an|-vn] [-e str] [-o list] [-tc] [-1 f] [-2 f] file1 file2\n",
-    cmd);
-  exit(1);
-}
-
-int compare()
-{				/* compare key field */
-  register int r;
-
-  if (nfld[1] == 0)		/* file2 EOF */
-	r = -1;
-  else if (nfld[0] == 0)	/* file1 EOF */
-	r = 1;
-  else {
-	if (nfld[0] <= kpos[0])
-		error("missing key field in file1", (char *) 0);
-	if (nfld[1] <= kpos[1])
-		error("missing key field in file2", (char *) 0);
-
-	r = strcmp(fld[0][kpos[0]], fld[1][kpos[1]]);
-  }
-  return r;
-}
-
-void match()
-{
-  long p;
-
-  if (!vflag) (*outfun) (F1 | F2);
-
-  p = ftell(fp[1]);
-  nfld[1] = get2(0);		/* check key order */
-  if (nfld[1] == 0 || strcmp(fld[0][kpos[0]], fld[1][kpos[1]])) {
-	nfld[0] = get1();
-	if (strcmp(fld[0][kpos[0]], oldkey) == 0) {
-		fseek(fp[1], head, 0);	/* re-do from head */
-		nfld[1] = get2(1);	/* don't check key order */
-	} else
-		head = p;	/* mark here */
-  }
-}
-
-void f1_only()
-{
-  if ((aflag & F1) || (vflag & F1)) (*outfun) (F1);
-  nfld[0] = get1();
-}
-
-void f2_only()
-{
-  if ((aflag & F2) || (vflag & F2)) (*outfun) (F2);
-  head = ftell(fp[1]);		/* mark */
-  nfld[1] = get2(0);		/* check key order */
-}
-
-void output(f)
-{				/* default output form */
-  if (f & F1)
-	fputs(fld[0][kpos[0]], stdout);
-  else
-	fputs(fld[1][kpos[1]], stdout);
-  if (f & F1) outfld(0);
-  if (f & F2) outfld(1);
-  fputc('\n', stdout);
-}
-
-void outfld(file)
-{				/* output all fields except key_field */
-  register int i;
-  int k, n;
-
-  k = kpos[file];
-  n = nfld[file];
-  for (i = 0; i < n; i++)
-	if (i != k) {
-		fputc(SEP, stdout);
-		fputs(fld[file][i], stdout);
-	}
-}
-
-void outputf(f)
-{				/* output by '-o list' */
-  int i, j, k;
-  register char *s;
-
-  for (i = k = 0; i < nout; i++) {
-	j = olist[i].o_file;
-	if ((f & (j + 1)) && (olist[i].o_field < nfld[j]))
-		s = fld[j][olist[i].o_field];
-	else
-		s = es;
-	if (s) {
-		if (k++) fputc(SEP, stdout);
-		fputs(s, stdout);
-	}
-  }
-  fputc('\n', stdout);
-}
-
-int get1()
-{				/* read file1 */
-  int r;
-  static char oldkey1[BUFSIZ];
-
-  if (fld[0][kpos[0]]) {
-        strcpy(oldkey, fld[0][kpos[0]]);  /* save previous key for control */
-  }
-  r = getrec(0);
-
-  if (r) {
-        if (strcmp(oldkey1, fld[0][kpos[0]]) > 0)
-	      error("file1 is not sorted", (char *) 0);
-        strcpy(oldkey1, fld[0][kpos[0]]);  /* save prev key for sort check */
-  }
-  return r;
-}
-
-int get2(back)
-{				/* read file2 */
-  static char oldkey2[BUFSIZ];
-  int r;
-
-  r = getrec(1);
-
-  if (r) {
-        if (!back && strcmp(oldkey2, fld[1][kpos[1]]) > 0)
-	      error("file2 is not sorted", (char *) 0);
-        strcpy(oldkey2, fld[1][kpos[1]]);  /* save prev key for sort check */
-  }
-  return r;
-}
-
-int getrec(file)
-{				/* read one line to split it */
-  if (fgets(buf[file], BUFSIZ, fp[file]) == (char *) 0)
-	*buf[file] = '\0';
-  else if (*buf[file] == '\n' || *buf[file] == '\r')
-	error("null line in file%s", file ? "1" : "0");
-
-  return split(file);
-}
-
-int split(file)
-{				/* setup fields */
-  register int n;
-  register char *s, *t;
-
-  for (n = 0, s = buf[file]; *s && *s != '\n' && *s != '\r';) {
-	if (sep) {
-		for (t = s; *s && *s != sep && *s != '\n' && *s != '\r'; s++);
-	} else {
-		while (*s == ' ' || *s == '\t')
-			s++;	/* skip leading white space */
-		for (t = s; *s && *s != ' ' && *s != '\t'
-		     && *s != '\n' && *s != '\r'; s++);
-		/* We will treat trailing white space as NULL field */
-	}
-	if (*s) *s++ = '\0';
-	fld[file][n++] = t;
-	if (n == MAXFLD) error("too many filed in file%s", file ? "1" : "0");
-  }
-  fld[file][n] = (char *) 0;
-
-  return n;
-}
-
-FILE *efopen(file, mode)
-char *file, *mode;
-{
-  FILE *fp;
-
-  if ((fp = fopen(file, mode)) == (FILE *) 0) error("can't open %s", file);
-
-  return fp;
-}
-
-void error(s, t)
-char *s, *t;
-{
-  fprintf(stderr, "%s: ", cmd);
-  fprintf(stderr, s, t);
-  fprintf(stderr, "\n");
-
-  exit(1);
-}
Index: trunk/minix/commands/simple/kill.c
===================================================================
--- trunk/minix/commands/simple/kill.c	(revision 9)
+++ 	(revision )
@@ -1,100 +1,0 @@
-/* kill - send a signal to a process	Author: Adri Koppes  */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void usage, (void));
-
-/* Table of signal names. */
-struct signames {
-	char *name;
-	int sig;
-} signames[] = {
-	{ "HUP",	SIGHUP		},
-	{ "INT",	SIGINT		},
-	{ "QUIT",	SIGQUIT		},
-	{ "ILL",	SIGILL		},
-	{ "TRAP",	SIGTRAP		},
-	{ "ABRT",	SIGABRT		},
-	{ "IOT",	SIGIOT		},
-	{ "FPE",	SIGFPE		},
-	{ "KILL",	SIGKILL		},
-	{ "USR1",	SIGUSR1		},
-	{ "SEGV",	SIGSEGV		},
-	{ "USR2",	SIGUSR2		},
-	{ "PIPE",	SIGPIPE		},
-	{ "ALRM",	SIGALRM		},
-	{ "TERM",	SIGTERM		},
-	{ "EMT",	SIGEMT		},
-	{ "BUS",	SIGBUS		},
-	{ "CHLD",	SIGCHLD		},
-	{ "CONT",	SIGCONT		},
-	{ "STOP",	SIGSTOP		},
-	{ "TSTP",	SIGTSTP		},
-	{ "TTIN",	SIGTTIN		},
-	{ "TTOU",	SIGTTOU		},
-#ifdef SIGWINCH
-	{ "WINCH",	SIGWINCH	},
-#endif
-	{ NULL,		0		}
-};
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  pid_t proc;
-  int ex = 0, sig = SIGTERM;
-  char *end;
-  long l;
-  unsigned long ul;
-  struct sigaction sa;
-  int i, doit;
-  struct signames *snp;
-
-  if (argc > 1 && argv[1][0] == '-') {
-	sig = -1;
-	for (snp = signames; snp->name != NULL; snp++) {	/* symbolic? */
-		if (strcmp(snp->name, argv[1] + 1) == 0) {
-			sig = snp->sig;
-			break;
-		}
-	}
-	if (sig < 0) {						/* numeric? */
-		ul = strtoul(argv[1] + 1, &end, 10);
-		if (end == argv[1] + 1 || *end != 0 || ul > _NSIG) usage();
-		sig = ul;
-	}
-	argv++;
-	argc--;
-  }
-  sa.sa_flags = 0;
-  sigemptyset(&sa.sa_mask);
-  sa.sa_handler = SIG_IGN;		/* try not to kill yourself */
-  (void) sigaction(sig, &sa, (struct sigaction *) NULL);
-
-  for (doit = 0; doit <= 1; doit++) {
-	for (i = 1; i < argc; i++) {
-		l = strtoul(argv[i], &end, 10);
-		if (end == argv[i] || *end != 0 || (pid_t) l != l) usage();
-		proc = l;
-		if (doit && kill(proc, sig) < 0) {
-			fprintf(stderr, "kill: %d: %s\n",
-				proc, strerror(errno));
-			ex = 1;
-		}
-	}
-  }
-  return(ex);
-}
-
-void usage()
-{
-  fprintf(stderr, "Usage: kill [-sig] pid\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/last.c
===================================================================
--- trunk/minix/commands/simple/last.c	(revision 9)
+++ 	(revision )
@@ -1,481 +1,0 @@
-/* last - display login history			Author: Terrence W. Holm */
-
-/* last-	Display the user log-in history.
- *		Last(1) searches backwards through the file of log-in
- *		records (/usr/adm/wtmp), displaying the length of
- *		log-in sessions as requested by the options:
- *
- * Usage:	last [-r] [-count] [-f file] [name] [tty] ...
- *
- *		-r	Search backwards only until the last reboot
- *			record.
- *
- *		-count	Only print out <count> records. Last(1) stops
- *			when either -r or -count is satisfied, or at
- *			the end of the file if neither is given.
- *
- *		-f file	Use "file" instead of "/usr/adm/wtmp".
- *
- *		name	Print records for the user "name".
- *
- *		tty	Print records for the terminal "tty". Actually,
- *			a list of names may be given and all records
- *			that match either the user or tty name are
- *			printed. If no names are given then all records
- *			are displayed.
- *
- *		A sigquit (^\) causes last(1) to display how far it
- *		has gone back in the log-in record file, it then
- *		continues. This is used to check on the progress of
- *		long running searches. A sigint will stop last(1).
- *
- * Author:	Terrence W. Holm	May 1988
- *
- * Revision:
- *		Fred van Kempen, October 1989
- *		 -Adapted to MSS.
- *		 -Adapted to new utmp database.
- *
- *		Fred van Kempen, December 1989
- *		 -Adapted to POSIX (MINIX 1.5)
- *
- *		Fred van Kempen, January 1990
- *		 -Final edit for 1.5
- *
- *		Philip Homburg, March 1992
- *		 -Include host in output
- *
- *		Kees J. Bot, July 1997
- *		 -Approximate system uptime from last reboot record
- */
-#include <sys/types.h>
-#include <signal.h>
-#include <string.h>
-#include <utmp.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include <minix/paths.h>
-
-#define  FALSE	0
-#define  TRUE	1
-#define  RLOGIN	1
-
-#define  BUFFER_SIZE     4096	/* Room for wtmp records */
-#define  MAX_WTMP_COUNT  ( BUFFER_SIZE / sizeof(struct utmp) )
-
-#define  min( a, b )     ( (a < b) ? a : b )
-#define  max( a, b )	 ( (a > b) ? a : b )
-
-
-typedef struct logout {		/* A logout time record */
-  char line[12];		/* The terminal name */
-  long time;			/* The logout time */
-  struct logout *next;		/* Next in linked list */
-} logout;
-
-
-static char *Version = "@(#) LAST 1.7 (10/24/92)";
-
-
-/* command-line option flags */
-char boot_limit = FALSE;	/* stop on latest reboot */
-char count_limit = FALSE;	/* stop after print_count */
-char tell_uptime = FALSE;	/* tell uptime since last reboot */
-int print_count;
-char *prog;			/* name of this program */
-int arg_count;			/* used to select specific */
-char **args;			/* users and ttys */
-
-/* global variables */
-long boot_time = 0;		/* Zero means no reboot yet */
-char *boot_down;		/* "crash" or "down " flag */
-logout *first_link = NULL;	/* List of logout times */
-int interrupt = FALSE;		/* If sigint or sigquit occurs */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void Sigint, (int sig));
-_PROTOTYPE(void Sigquit, (int sig));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void Process, (struct utmp *wtmp));
-_PROTOTYPE(int Print_Record, (struct utmp *wtmp));
-_PROTOTYPE(void Print_Duration, (long from, long to));
-_PROTOTYPE(void Print_Uptime, (void));
-_PROTOTYPE(void Record_Logout_Time, (struct utmp *wtmp));
-
-/* Sigint() and Sigquit() Flag occurrence of an interrupt. */
-void Sigint(sig)
-int sig;
-{
-  interrupt = SIGINT;
-}
-
-
-void Sigquit(sig)
-int sig;
-{
-  interrupt = SIGQUIT;
-}
-
-
-void usage()
-{
-  fprintf(stderr,
-	"Usage: last [-r] [-u] [-count] [-f file] [name] [tty] ...\n");
-  exit(-1);
-}
-
-
-/* A log-in record format file contains four types of records.
- *
- *  [1] generated on a system reboot:
- *
- *	line="~", name="reboot", host="", time=date()
- *
- *
- *  [2] generated after a shutdown:
- *
- *	line="~", name="shutdown", host="", time=date()
- *
- *
- *  [3] generated on a successful login(1)
- *
- *	line=ttyname(), name=cuserid(), host=, time=date()
- *
- *
- *  [4] generated by init(8) on a logout
- *
- *	line=ttyname(), name="", host="", time=date()
- *
- *
- * Note: This version of last(1) does not recognize the '|' and '}' time
- *	 change records. Last(1) pairs up line login's and logout's to
- *	 generate four types of output lines:
- *
- *	  [1] a system reboot or shutdown
- *
- *	   reboot    ~       Mon May 16 14:16
- *	   shutdown  ~       Mon May 16 14:15
- *
- *	  [2] a login with a matching logout
- *
- *	   edwin     tty1    Thu May 26 20:05 - 20:32  (00:27)
- *
- *	  [3] a login followed by a reboot or shutdown
- *
- *	   root      tty0    Mon May 16 13:57 - crash  (00:19)
- *	   root      tty1    Mon May 16 13:45 - down   (00:30)
- *
- *	  [4] a login not followed by a logout or reboot
- *
- *	   terry     tty0    Thu May 26 21:19   still logged in
- */
-void Process(wtmp)
-struct utmp *wtmp;
-{
-  logout *link;
-  logout *next_link;
-  char is_reboot;
-
-  /* suppress the job number on an "ftp" line */
-  if (!strncmp(wtmp->ut_line, "ftp", (size_t)3)) strncpy(wtmp->ut_line, "ftp", (size_t)8);
-
-  if (!strcmp(wtmp->ut_line, "~")) {
-	/* A reboot or shutdown record  */
-	if (boot_limit) exit(0);
-
-	if (Print_Record(wtmp)) putchar('\n');
-	boot_time = wtmp->ut_time;
-
-	is_reboot = !strcmp(wtmp->ut_name, "reboot");
-	if (is_reboot)
-		boot_down = "crash";
-	else
-		boot_down = "down ";
-
-	if (tell_uptime) {
-		if (!is_reboot) {
-			fprintf(stderr,
-		"%s: no reboot record added to wtmp file on system boot!\n",
-				prog);
-			exit(1);
-		}
-		Print_Uptime();
-		exit(0);
-	}
-
-	/* remove any logout records */
-	for (link = first_link; link != NULL; link = next_link) {
-		next_link = link->next;
-		free(link);
-	}
-	first_link = NULL;
-  } else if (wtmp->ut_name[0] == '\0') {
-	/* A logout record */
-	Record_Logout_Time(wtmp);
-  } else {
-	/* A login record */
-	for (link = first_link; link != NULL; link = link->next)
-		if (!strncmp(link->line, wtmp->ut_line, (size_t)8)) {
-			/* found corresponding logout record */
-			if (Print_Record(wtmp)) {
-				printf("- %.5s ", ctime(&link->time) + 11);
-				Print_Duration(wtmp->ut_time, link->time);
-			}
-			/* record login time */
-			link->time = wtmp->ut_time;
-			return;
-		}
-	/* could not find a logout record for this login tty */
-	if (Print_Record(wtmp))
-		if (boot_time == 0)	/* still on */
-			printf("  still logged in\n");
-		else {		/* system crashed while on */
-			printf("- %s ", boot_down);
-			Print_Duration(wtmp->ut_time, boot_time);
-		}
-	Record_Logout_Time(wtmp);	/* Needed in case of 2
-					 * consecutive logins  */
-  }
-}
-
-
-/* Print_Record(wtmp) If the record was requested, then print out
- * the user name, terminal, host and time.
- */
-int Print_Record(wtmp)
-struct utmp *wtmp;
-{
-  int i;
-  char print_flag = FALSE;
-
-  /* just interested in the uptime? */
-  if (tell_uptime) return(FALSE);
-
-  /* check if we have already printed the requested number of records */
-  if (count_limit && print_count == 0) exit(0);
-
-  for (i = 0; i < arg_count; ++i)
-	if (!strncmp(args[i], wtmp->ut_name, sizeof(wtmp->ut_name)) ||
-	    !strncmp(args[i], wtmp->ut_line, sizeof(wtmp->ut_line)))
-		print_flag = TRUE;
-
-  if (arg_count == 0 || print_flag) {
-#ifdef RLOGIN
-	printf("%-8.8s  %-8.8s %-16.16s %.16s ",
-	       wtmp->ut_name, wtmp->ut_line, wtmp->ut_host,
-	       ctime(&wtmp->ut_time));
-#else
-	printf("%-8.8s  %-8.8s  %.16s ",
-	       wtmp->ut_name, wtmp->ut_line, ctime(&wtmp->ut_time));
-#endif
-	--print_count;
-	return(TRUE);
-  }
-  return(FALSE);
-}
-
-
-/* Print_Duration(from, to) Calculate and print the days and hh:mm between
- * the log-in and the log-out.
- */
-void Print_Duration(from, to)
-long from;
-long to;
-{
-  long delta, days, hours, minutes;
-
-  delta = max(to - from, 0);
-  days = delta / (24L * 60L * 60L);
-  delta = delta % (24L * 60L * 60L);
-  hours = delta / (60L * 60L);
-  delta = delta % (60L * 60L);
-  minutes = delta / 60L;
-
-  if (days > 0)
-	printf("(%ld+", days);
-  else
-	printf(" (");
-
-  printf("%02ld:%02ld)\n", hours, minutes);
-}
-
-
-/* Print_Uptime() Calculate and print the "uptime" between the last recorded
- * boot and the current time.
- */
-void Print_Uptime()
-{
-#define NLOADS 3
-  int nloads;
-  double loads[NLOADS];
-  char *utmp_file = _PATH_UTMP;
-  unsigned nusers;
-  struct utmp ut;
-  FILE *uf;
-  time_t now;
-  struct tm *tm;
-  unsigned long up;
-
-  /* Count the number of active users in the utmp file. */
-  if ((uf = fopen(utmp_file, "r")) == NULL) {
-	fprintf(stderr, "%s: %s: %s\n", prog, utmp_file, strerror(errno));
-	exit(1);
-  }
-
-  nusers = 0;
-  while (fread(&ut, sizeof(ut), 1, uf) == 1) {
-#ifdef USER_PROCESS
-	if (ut.ut_type == USER_PROCESS) nusers++;
-#else
-	if (ut.ut_name[0] != 0 && ut.ut_line[0] != 0) nusers++;
-#endif
-  }
-  fclose(uf);
-
-  /* Current time. */
-  now = time((time_t *) NULL);
-  tm = localtime(&now);
-
-  /* Uptime. */
-  up = now - boot_time;
-
-  printf(" %d:%02d  up", tm->tm_hour, tm->tm_min);
-  if (up >= 24 * 3600L) {
-	unsigned long days = up / (24 * 3600L);
-	printf(" %lu day%s,", days, days == 1 ? "" : "s");
-  }
-  printf(" %lu:%02lu,", (up % (24 * 3600L)) / 3600, (up % 3600) / 60);
-  printf("  %u user%s", nusers, nusers == 1 ? "" : "s");
-  if((nloads = getloadavg(loads, NLOADS)) > 0) {
-	int i;
-	printf(", load averages:");
-	for(i = 0; i < nloads; i++)
-		printf("%s %.2f", (i > 0) ? "," : "", loads[i]);
-  }
-  printf("\n");
-}
-
-
-/* Record_Logout_Time(wtmp) A linked list of "last logout time" is kept.
- * Each element of the list is for one terminal.
- */
-void Record_Logout_Time(wtmp)
-struct utmp *wtmp;
-{
-  logout *link;
-
-  /* see if the terminal is already in the list */
-  for (link = first_link; link != NULL; link = link->next)
-	if (!strncmp(link->line, wtmp->ut_line, (size_t)8)) {
-		link->time = wtmp->ut_time;
-		return;
-	}
-  /* allocate a new logout record, for a tty not previously encountered */
-  link = (logout *) malloc(sizeof(logout));
-  if (link == NULL) {
-	fprintf(stderr, "%s: malloc failure\n", prog);
-	exit(1);
-  }
-  strncpy(link->line, wtmp->ut_line, (size_t)8);
-  link->time = wtmp->ut_time;
-  link->next = first_link;
-
-  first_link = link;
-}
-
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char *wtmp_file = _PATH_WTMP;
-  FILE *f;
-  long size;			/* Number of wtmp records in the file	 */
-  int wtmp_count;		/* How many to read into wtmp_buffer	 */
-  struct utmp wtmp_buffer[MAX_WTMP_COUNT];
-
-  if ((prog = strrchr(argv[0], '/')) == NULL) prog = argv[0]; else prog++;
-
-  --argc;
-  ++argv;
-
-  while (argc > 0 && *argv[0] == '-') {
-	if (!strcmp(argv[0], "-r"))
-		boot_limit = TRUE;
-	else
-	if (!strcmp(argv[0], "-u"))
-		tell_uptime = TRUE;
-	else if (argc > 1 && !strcmp(argv[0], "-f")) {
-		wtmp_file = argv[1];
-		--argc;
-		++argv;
-	} else if ((print_count = atoi(argv[0] + 1)) > 0)
-		count_limit = TRUE;
-	else
-		usage();
-
-	--argc;
-	++argv;
-  }
-
-  arg_count = argc;
-  args = argv;
-
-  if (!strcmp(prog, "uptime")) tell_uptime = TRUE;
-
-  if ((f = fopen(wtmp_file, "r")) == NULL) {
-	perror(wtmp_file);
-	exit(1);
-  }
-  if (fseek(f, 0L, 2) != 0 || (size = ftell(f)) % sizeof(struct utmp) != 0) {
-	fprintf(stderr, "%s: invalid wtmp file\n", prog);
-	exit(1);
-  }
-  if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
-	signal(SIGINT, Sigint);
-	signal(SIGQUIT, Sigquit);
-  }
-  size /= sizeof(struct utmp);	/* Number of records in wtmp	 */
-
-  if (size == 0) wtmp_buffer[0].ut_time = time((time_t *)0);
-
-  while (size > 0) {
-	wtmp_count = (int) min(size, MAX_WTMP_COUNT);
-	size -= (long) wtmp_count;
-
-	fseek(f, size * sizeof(struct utmp), 0);
-
-
-	if (fread(&wtmp_buffer[0], sizeof(struct utmp), (size_t)wtmp_count, f)
-	    != wtmp_count) {
-		fprintf(stderr, "%s: read error on wtmp file\n", prog);
-		exit(1);
-	}
-	while (--wtmp_count >= 0) {
-		Process(&wtmp_buffer[wtmp_count]);
-		if (interrupt) {
-			printf("\ninterrupted %.16s \n",
-			   ctime(&wtmp_buffer[wtmp_count].ut_time));
-
-			if (interrupt == SIGINT) exit(2);
-
-			interrupt = FALSE;
-			signal(SIGQUIT, Sigquit);
-		}
-	}
-
-  }				/* end while(size > 0) */
-
-  if (tell_uptime) {
-	fprintf(stderr,
-		"%s: no reboot record in wtmp file to compute uptime from\n",
-		prog);
-	return(1);
-  }
-
-  printf("\nwtmp begins %.16s \n", ctime(&wtmp_buffer[0].ut_time));
-  return(0);
-}
Index: trunk/minix/commands/simple/leave.c
===================================================================
--- trunk/minix/commands/simple/leave.c	(revision 9)
+++ 	(revision )
@@ -1,210 +1,0 @@
-/* Usage:	leave [ [+] hh[:]mm ]
- *
- * Author:	Terrence W. Holm
- *
- * Revision:
- *		Fred van Kempen, MINIX User Group Holland
- *		 -adapted to MSS
- *		 -adapted to new utmp database
- *		 -adapted to POSIX (MINIX 1.5)
- *		Michael Temari, <temari@ix.netcom.com>
- *		 -use localtime/mktime to fix bug with DST
- */
-
-#include <sys/types.h>
-#include <signal.h>
-#include <time.h>
-#include <utmp.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-
-#define Min(a,b)  ((a<b) ? a : b)
-
-#define STRING	   80		/* lots of room for an argument */
-#define MIN	   60L		/* seconds per minute */
-#define HOUR      (60L*60L)	/* seconds per hour */
-
-/* Set the following to your personal preferences for the
- * time and contents of warnings.
- */
-#define INTERVALS 13		/* size of intervals[] */
-#define WARNINGS  4		/* size of warnings[] */
-
-
-static char *Version = "@(#) LEAVE 1.4 (01/09/90)";
-static int intervals[INTERVALS] = {
-  -5 * MIN,
-  -1 * MIN,
-  0,
-  MIN,
-  2 * MIN,
-  3 * MIN,
-  4 * MIN,
-  5 * MIN,
-  6 * MIN,
-  7 * MIN,
-  8 * MIN,
-  9 * MIN,
-  10 * MIN
-};
-static char *warnings[WARNINGS] = {
-  "You have to leave within 5 minutes",
-  "Just one more minute!",
-  "Time to leave!",
-  "You're going to be late!"	/* for all subsequent warnings */
-};
-
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void Usage, (void));
-_PROTOTYPE(void Get_Hour_Min, (char *when, int *hour, int *min));
-_PROTOTYPE(int Still_Logged_On, (char *user, char *tty));
-
-void Usage()
-{
-   fprintf(stderr, "Usage: leave [[+]hh[:]mm]\n");
-  exit(1);
-}
-
-
-void Get_Hour_Min(when, hour, min)
-char *when;
-int *hour;
-int *min;
-{
-  int hour_min;
-  int just_min = 0;
-
-  switch (sscanf(when, "%d:%d", &hour_min, &just_min)) {
-      case 1:
-	*hour = hour_min / 100;
-	*min = hour_min % 100;
-	break;
-      case 2:
-	*hour = hour_min;
-	*min = just_min;
-	break;
-      default:
-	Usage();
-  }
-
-  if (hour_min < 0 || just_min < 0 || *min > 59) Usage();
-}
-
-
-int Still_Logged_On(user, tty)
-char *user;
-char *tty;
-{
-  FILE *f;
-  struct utmp login;
-
-  if ((f = fopen(UTMP, "r")) == NULL)
-	/* no login/logout records kept */
-	return(1);
-
-  while (fread(&login, sizeof(struct utmp), (size_t)1, f) == 1) {
-	if (!strncmp(login.ut_line, tty, (size_t)8))
-		if (!strncmp(login.ut_name, user, (size_t)8)) {
-			fclose(f);
-			return(1);
-		} else {
-			fclose(f);
-			return(0);
-		}
-  }
-  fclose(f);
-  return(0);
-}
-
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char when[STRING];
-  time_t now = time((time_t *)0);
-  time_t leave, delta;
-  struct tm *tm;
-  int hour, min;
-  int pid, i;
-  char *user = cuserid( (char *)NULL);
-  char *tty = ttyname(0) + 5;
-
-  /* get the argument string "when" either from stdin, or argv */
-  if (argc <= 1) {
-	printf("When do you have to leave? ");
-	fflush(stdout);
-	if (fgets(when, STRING, stdin) == NULL || when[0] == '\n') exit(0);
-  } else {
-	strcpy(when, argv[1]);
-	if (argc > 2) strcat(when, argv[2]);
-  }
-
-  /* determine the leave time from the current time and "when" */
-  tm = localtime(&now);
-  if (when[0] == '+') {
-	Get_Hour_Min(&when[1], &hour, &min);
-	tm->tm_hour += hour;
-	tm->tm_min += min;
-	leave = mktime(tm);
-  } else {
-	/* user entered an absolute time */
-	Get_Hour_Min(&when[0], &hour, &min);
-	tm->tm_hour = hour;
-	tm->tm_min = min;
-	leave = mktime(tm);
-	if (leave < now) {
-		printf("That time has already passed!\n");
-		exit(1);
-	}
-  }
-
-  printf("Alarm set for %s", ctime(&leave));
-
-  if ((pid = fork()) == -1) {
-	fprintf(stderr, "leave: can not fork\n");
-	exit(1);
-  }
-  if (pid != 0) exit(0);
-
-  /* only the child continues on */
-  if (user == NULL || tty == NULL) {
-	fprintf(stderr, "leave: Can not determine user and terminal name\n");
-	exit(1);
-  }
-  signal(SIGINT, SIG_IGN);
-  signal(SIGQUIT, SIG_IGN);
-  signal(SIGTERM, SIG_IGN);
-
-  for (;;) {
-	if (!Still_Logged_On(user, tty)) exit(0);
-
-	/* how much longer until the leave time? */
-	/* XXX - use difftime all over. */
-	delta = leave - time((time_t *)0);
-
-	/* which interval are we currently in? */
-	for (i = 0; i < INTERVALS; ++i)
-		if (delta + intervals[i] > 0) break;
-
-	/* if we are within intervals[0] then print a warning If
-	 * there are more intervals than messages, then use/
-	 * warnings[WARNINGS-1] for all subsequent messages. */
-	if (i > 0)
-		printf("\007\r%s\r\n",
-			warnings[i > WARNINGS ? WARNINGS - 1 : i - 1]);
-
-	if (i == INTERVALS) {
-		printf("That was the last time I'll tell you. Bye.\r\n");
-		exit(0);
-	}
-	/* Sleep until the next interval. For long periods, wake up
-	 * every hour to check if the user is still on (also required
-	 * because 16 bit ints don't allow long waits). */
-	sleep((unsigned) Min(delta + intervals[i], HOUR));
-  }
-}
Index: trunk/minix/commands/simple/life.c
===================================================================
--- trunk/minix/commands/simple/life.c	(revision 9)
+++ 	(revision )
@@ -1,241 +1,0 @@
-/* life - Conway's game of life		Author: Jim King */
-
-/* clife.c - curses life simulator.  Translated from Pascal to C implementing
- *           curses Oct 1988 by pulsar@lsrhs, not jek5036@ritvax.isc.rit.edu
- *           life needs about 18kb stack space on MINIX.
- *
- * Flags:	-d  draw your own screen using arrows and space bar
- *		-p  print statistics on the bottom line during the game
- */
-
-#include <sys/types.h>
-#include <signal.h>
-#include <time.h>
-#include <curses.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#if __minix_vmd		/* Use a more random rand(). */
-#define srand(seed)	srandom(seed)
-#define rand()		random()
-#endif
-
-/* A value of -1 will make it go forever */
-/* A value of 0 will make it exit immediately */
-#define	REPSTOP		-1	/* number of repetitions before stop */
-
-int present[23][80];		/* screen 1 cycle ago */
-int past[23][80];		/* screen this cycle */
-int total;			/* total # of changes */
-int icnt;			/* counter to check for repetition */
-int maxrow = 22;		/* some defines to represent the screen */
-int maxcol = 79;
-int minrow = 0;
-int mincol = 0; 
-int pri = 0;			/* flag for printing stats on bottom line */
-int draw = 0;			/* flag for drawing your own screen */
-int i, j, k;			/* loop counters */
-int cycle;			/* current cycle # */
-int changes;			/* # of changes this cycle (live + die) */
-int die;			/* number of deaths this cycle */
-int live;			/* number of births this cycle */
-
-WINDOW *mns;			/* Main Screen */
-WINDOW *info;			/* Bottom line */
-
-_PROTOTYPE(void cleanup, (int s));
-_PROTOTYPE(void initialize, (void));
-_PROTOTYPE(void makscr, (void));
-_PROTOTYPE(void update, (void));
-_PROTOTYPE(void print, (void));
-_PROTOTYPE(int main, (int ac, char *av[]));
-
-/* Cleanup - cleanup then exit */
-void cleanup(s)
-int s;
-{
-  move(23, 0);			/* go to bottom of screen */
-  refresh();			/* update cursor */
-
-  endwin();			/* shutdown curses */
-  exit(1);			/* exit */
-}
-
-/* Initialize - init windows, variables, and signals */
-
-void initialize()
-{
-  srand(getpid());		/* init random seed */
-  initscr();			/* init curses */
-  noecho();
-  curs_set(0);
-  signal(SIGINT, cleanup);	/* catch ^C */
-  mns = newwin(maxrow, maxcol, 0, 0);	/* new window */
-  scrollok(mns, FALSE);
-  info = newwin(1, 80, 23, 0);
-  scrollok(info, FALSE);
-  wclear(mns);
-  wclear(info);
-  wmove(info, 0, 0);
-  wrefresh(info);
-  if (!draw) {			/* if no draw, make random pattern */
-	for (j = 0; j < maxrow; j++) {
-		for (k = 0; k < maxcol; k++) {
-			present[j][k] = rand() % 2;
-			if (present[j][k] == 1) changes++, live++;
-		}
-	}
-  }
-}
-
-/* Makscr - make your own screen using arrow keys and space bar */
-void makscr()
-{
-  int curx, cury;		/* current point on screen */
-  char c;			/* input char */
-
-  wclear(info);
-  wmove(info, 0, 0);
-  wprintw(info, "Use arrow keys to move, space to place / erase, ^D to start", NULL);
-  wrefresh(info);
-  curx = cury = 1;
-  wmove(mns, cury - 1, curx - 1);
-  wrefresh(mns);
-  noecho();
-  for (;;) {
-	c = wgetch(mns);
-	if (c == '\004')
-		break;
-	else if (c == ' ') {
-		if (present[cury][curx]) {
-			--present[cury][curx];
-			changes++;
-			die++;
-			mvwaddch(mns, cury, curx, ' ');
-		} else {
-			++present[cury][curx];
-			changes++;
-			live++;
-			mvwaddch(mns, cury, curx, '*');
-		}
-	} else if (c == '\033') {
-		wgetch(mns);
-		switch (wgetch(mns)) {
-		    case 'A':	--cury;	break;
-		    case 'B':	++cury;	break;
-		    case 'C':	++curx;	break;
-		    case 'D':	--curx;	break;
-		    default:	break;
-		}
-	}
-	if (cury > maxrow) cury = minrow;
-	if (cury < minrow) cury = maxrow;
-	if (curx > maxcol) curx = mincol;
-	if (curx < mincol) curx = maxcol;
-	wmove(mns, cury, curx);
-	wrefresh(mns);
-  }
-  wclear(info);
-}
-
-/* Update rules:  2 or 3 adjacent alive --- stay alive
- *                3 adjacent alive -- dead to live
- *                all else die or stay dead
- */
-void update()
-{				/* Does all mathmatical calculations */
-  int howmany, w, x, y, z;
-  changes = die = live = 0;
-  for (j = 0; j < maxrow; j++) {
-	for (k = 0; k < maxcol; k++) {
-		w = j - 1;
-		x = j + 1;
-		y = k - 1;
-		z = k + 1;
-
-		howmany = (past[w][y] + past[w][k] + past[w][z] +
-			   past[j][y] + past[j][z] + past[x][y] +
-			   past[x][k] + past[x][z]);
-
-		switch (howmany) {
-		    case 0:
-		    case 1:
-		    case 4:
-		    case 5:
-		    case 6:
-		    case 7:
-		    case 8:
-			present[j][k] = 0;
-			if (past[j][k]) changes++, die++;
-			break;
-		    case 3:
-			present[j][k] = 1;
-			if (!past[j][k]) changes++, live++;
-			break;
-		    default:	break;
-		}
-	}
-  }
-  if (live == die)
-	++icnt;
-  else
-	icnt = 0;
-
-  if (icnt == REPSTOP) cleanup(0);
-}
-
-/* Print - updates the screen according to changes from past to present */
-void print()
-{	
-/* Updates the screen, greatly improved using curses */
-  if (pri) {
-	wmove(info, 0, 0);
-	total += changes;
-	cycle++;
-	wprintw(info, "Cycle %5d | %5d changes: %5d died + %5d born = %5u total changes", (char *) cycle, changes, die, live, total);
-	wclrtoeol(info);
-  }
-  for (j = 1; j < maxrow; j++) {
-	for (k = 1; k < maxcol; k++) {
-		if (present[j][k] != past[j][k] && present[j][k] == 1) {
-			wmove(mns, j, k);
-			wprintw(mns, "*", NULL);
-		} else if (present[j][k] != past[j][k] && present[j][k] == 0) {
-			wmove(mns, j, k);
-			wprintw(mns, " ", NULL);
-		}
-	}
-  }
-  if (pri) wrefresh(info);
-  wrefresh(mns);
-}
-
-/* Main - main procedure */
-int main(ac, av)
-int ac;
-char *av[];
-{
-  if (ac > 1) {
-	for (j = 1; j < ac; j++) {
-		switch (av[j][1]) {
-		    case 'd':	++draw;	break;
-		    case 'p':	++pri;	break;
-		    default:
-			fprintf(stderr, "%s: usage: %s [-d] [-p]\n", av[0], av[0]);
-			exit(1);
-		}
-	}
-  }
-
-  initialize();
-  if (draw) makscr();
-
-  for (;;) {
-	print();
-	for (j = 0; j < maxrow; j++) {
-		for (k = 0; k < maxcol; k++) past[j][k] = present[j][k];
-	}
-	update();
-  }
-}
Index: trunk/minix/commands/simple/loadramdisk.c
===================================================================
--- trunk/minix/commands/simple/loadramdisk.c	(revision 9)
+++ 	(revision )
@@ -1,126 +1,0 @@
-/*
-loadramdisk.c
-
-Copy a device or file specified as argument to /dev/ram
-*/
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-
-#define RAM	"/dev/ram"
-
-char buf[10240];
-
-static unsigned long size_device(int fd);
-
-int main(int argc, char *argv[])
-{
-	unsigned long off, size;
-	int r, s, fd, ramfd;
-	char *src;
-
-	if (argc != 2)
-	{
-		fprintf(stderr, "Usage: loadramdisk <file>\n");
-		exit(1);
-	}
-	src= argv[1];
-	fd= open(src, O_RDONLY);
-	if (fd < 0)
-	{
-		fprintf(stderr, "Unable to open '%s': %s\n",
-			src, strerror(errno));
-		exit(1);
-	}
-
-	/* Get the size of the device */
-	errno= 0;
-	size= size_device(fd);
-	if (errno != 0)
-	{
-		fprintf(stderr, "Lseek(end) failed on '%s': %s\n",
-			src, strerror(errno));
-		exit(1);
-	}
-	if (lseek(fd, 0, SEEK_SET) != 0)
-	{
-		fprintf(stderr, "Lseek(0) failed on '%s': %s\n",
-			src, strerror(errno));
-		exit(1);
-	}
-
-	ramfd= open(RAM, O_RDWR);
-	if (ramfd < 0)
-	{
-		fprintf(stderr, "Unable to open '%s': %s\n",
-			RAM, strerror(errno));
-		exit(1);
-	}
-	r= ioctl(ramfd, MIOCRAMSIZE, &size);
-	if (r != 0)
-	{
-		fprintf(stderr, "MIOCRAMSIZE %lu failed on '%s': %s\n",
-			size, RAM, strerror(errno));
-		exit(1);
-	}
-
-	off= 0;
-	while (off < size)
-	{
-		r= read(fd, buf, sizeof(buf));
-		if (r <= 0)
-		{
-			fprintf(stderr, "error reading '%s': %s\n",
-				src, r == 0 ? "unexpected EOF" :
-				strerror(errno));
-			exit(1);
-		}
-		s= write(ramfd, buf, r);
-		if (s != r)
-		{
-			fprintf(stderr, "error writing to '%s': %s\n",
-				s >= 0 ? "short write" : strerror(errno));
-			exit(1);
-		}
-		off += r;
-	}
-	exit(0);
-}
-
-static unsigned long size_device(int fd)
-{
-	char b;
-	int r;
-	unsigned long low, mid, high;
-
-	/* Try to find the size of a device using binary search */
-	low= 0;
-	high= -1;
-
-	while (mid= low+(high-low)/2, mid > low)
-	{
-		if (lseek(fd, mid, SEEK_SET) != mid)
-		{
-			fprintf(stderr, "lseek to %lu failed: %s\n",
-				mid, strerror(errno));
-			exit(1);
-		}
-		r= read(fd, &b, 1);
-		if (r < 0)
-		{
-			fprintf(stderr, "read failed at position %lu: %s\n",
-				mid, strerror(errno));
-			exit(1);
-		}
-		if (r > 0)
-			low= mid;
-		else
-			high= mid;
-	}
-	return high;
-}
Index: trunk/minix/commands/simple/login.c
===================================================================
--- trunk/minix/commands/simple/login.c	(revision 9)
+++ 	(revision )
@@ -1,508 +1,0 @@
-/* login - log into the system			Author: Patrick van Kleef */
-
-/* Original version by Patrick van Kleef.  History of modifications:
- *
- * Peter S. Housel   Jan. 1988
- *  - Set up $USER, $HOME and $TERM.
- *  - Set signals to SIG_DFL.
- *
- * Terrence W. Holm   June 1988
- *  - Allow a username as an optional argument.
- *  - Time out if a password is not typed within 60 seconds.
- *  - Perform a dummy delay after a bad username is entered.
- *  - Don't allow a login if "/etc/nologin" exists.
- *  - Cause a failure on bad "pw_shell" fields.
- *  - Record the login in "/usr/adm/wtmp".
- *
- * Peter S. Housel   Dec. 1988
- *  - Record the login in "/etc/utmp" also.
- *
- * F. van Kempen     June 1989
- *  - various patches for Minix V1.4a.
- *
- * F. van Kempen     September 1989
- *  - added login-failure administration (new utmp.h needed!).
- *  - support arguments in pw_shell field
- *  - adapted source text to MINIX Style Sheet
- *
- * F. van Kempen     October 1989
- *  - adapted to new utmp database.
- * F. van Kempen,    December 1989
- *  - fixed 'slot' assumption in wtmp()
- *  - fixed all MSS-stuff
- *  - adapted to POSIX (MINIX 1.5)
- * F. van Kempen,    January 1990
- *  - made all 'bad login accounting' optional by "#ifdef BADLOG".
- * F. van Kempen,    Februari 1990
- *  - fixed 'first argument' bug and added some casts.
- *
- * Andy Tanenbaum April 1990
- * - if /bin/sh cannot be located, try /usr/bin/sh
- *
- * Michael A. Temari	October 1990
- *  - handle more than single digit tty devices
- *
- * Philip Homburg - Feb 28 1992
- *  - use ttyname to get the name of a tty.
- *
- * Kees J. Bot - Feb 13 1993
- *  - putting out garbage.
- *  - added lastlog.
- *
- * Kees J. Bot - Feb 13 1993
- *  - supplementary groups.
- *
- * Kees J. Bot - Jan 3 1996
- *  - ported back to standard Minix.
- */
-
-#define _MINIX_SOURCE
-#define _POSIX_C_SOURCE	2
-
-#include <sys/types.h>
-#include <ttyent.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <grp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <utmp.h>
-#include <time.h>
-#include <sys/utsname.h>
-#include <minix/minlib.h>
-#include <minix/paths.h>
-
-char PATH_UTMP[] = _PATH_UTMP;			/* current logins */
-char PATH_WTMP[] = _PATH_WTMP;		/* login/logout history */
-char PATH_LASTLOG[] = _PATH_LASTLOG;	/* last login history */
-char PATH_MOTD[] = _PATH_MOTD;			/* message of the day */
-
-#define TTY_GID		4			/* group ID of ttys */
-
-#define EXTRA_ENV	6
-
-/* Crude indication of a tty being physically secure: */
-#define securetty(dev)		((unsigned) ((dev) - 0x0400) < (unsigned) 8)
-
-int time_out;
-char *hostname;
-char user[32];
-char logname[35];
-char home[128];
-char shell[128];
-char term[128];
-char **env;
-extern char **environ;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void wtmp, (char *user, int uid));
-_PROTOTYPE(void show_file, (char *nam));
-_PROTOTYPE(void Time_out, (int dummy));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void add2env, (char **env, char *entry, int replace));
-
-void wtmp(user, uid)
-char *user;			/* user name */
-int uid;			/* user id */
-{
-  /* Make entries in /usr/adm/wtmp and /etc/utmp. */
-  struct utmp entry;
-  register int fd= -1;
-  int lineno;
-  int err = 0;
-  char *what;
-
-  /* First, read the current UTMP entry. we need some of its
-   * parameters! (like PID, ID etc...).
-   */
-  what= "ttyslot()";
-  lineno= ttyslot();
-  if (lineno == 0) err= errno;	/* ttyslot failed */
-
-  if (err == 0 && (fd = open(what = PATH_UTMP, O_RDONLY)) < 0) {
-  	if (errno == ENOENT) return;
-  	err= errno;
-  }
-  if (err == 0 && lseek(fd, (off_t) lineno * sizeof(entry), SEEK_SET) < 0)
-  	err= errno;
-  if (err == 0 && read(fd, (char *) &entry, sizeof(entry)) != sizeof(entry))
-  	err= errno;
-  if (fd >= 0) close(fd);
-
-  /* Enter new fields. */
-  strncpy(entry.ut_user, user, sizeof(entry.ut_user));
-  if (hostname) strncpy(entry.ut_host, hostname, sizeof(entry.ut_host));
-
-  if (entry.ut_pid == 0) entry.ut_pid = getpid();
-
-  entry.ut_type = USER_PROCESS;		/* we are past login... */
-  time(&entry.ut_time);
-
-  /* Write a WTMP record. */
-  if (err == 0) {
-  	if ((fd = open(what = PATH_WTMP, O_WRONLY|O_APPEND)) < 0) {
-  		if (errno != ENOENT) err= errno;
-	} else {
-		if (write(fd, (char *) &entry, sizeof(entry)) < 0) err= errno;
-		close(fd);
-	}
-  }
-
-  /* Rewrite the UTMP entry. */
-  if (err == 0 && (fd = open(what = PATH_UTMP, O_WRONLY)) < 0)
-	err= errno;
-  if (err == 0 && lseek(fd, (off_t) lineno * sizeof(entry), SEEK_SET) < 0)
-	err= errno;
-  if (err == 0 && write(fd, (char *) &entry, sizeof(entry)) < 0)
-	err= errno;
-  if (fd >= 0) close(fd);
-
-  /* Write the LASTLOG entry. */
-  if (err == 0 && (fd = open(what = PATH_LASTLOG, O_WRONLY)) < 0) {
-	if (errno == ENOENT) return;
-	err= errno;
-  }
-  if (err == 0 && lseek(fd, (off_t) uid * sizeof(entry), SEEK_SET) < 0)
-	err= errno;
-  if (err == 0 && write(fd, (char *) &entry, sizeof(entry)) < 0)
-	err= errno;
-  if (fd >= 0) close(fd);
-
-  if (err != 0) {
-  	fprintf(stderr, "login: %s: %s\n", what, strerror(err));
-  	return;
-  }
-}
-
-
-void show_file(nam)
-char *nam;
-{
-/* Read a textfile and show it on the desired terminal. */
-  register int fd, len;
-  char buf[80];
-
-  if ((fd = open(nam, O_RDONLY)) > 0) {
-	len = 1;
-	while (len > 0) {
-		len = read(fd, buf, 80);
-		write(1, buf, len);
-	}
-	close(fd);
-  }
-}
-
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char name[30];
-  char *password, *cryptedpwd;
-  char *tty_name, *p;
-  int n, ap, check_pw, bad, secure, i, envsiz, do_banner;
-  struct passwd *pwd;
-  char *bp, *argx[8], **ep;	/* pw_shell arguments */
-  char argx0[64];		/* argv[0] of the shell */
-  char *sh = "/bin/sh";		/* sh/pw_shell field value */
-  char *initialname;
-  int c, b_flag, f_flag, p_flag;
-  char *h_arg;
-  int authorized, preserv_env;
-  struct ttyent *ttyp;
-  struct stat ttystat;
-  struct sigaction sa;
-  struct utsname uts;
-
-  /* Don't let QUIT dump core. */
-  sigemptyset(&sa.sa_mask);
-  sa.sa_flags = 0;
-  sa.sa_handler = exit;
-  sigaction(SIGQUIT, &sa, NULL);
-
-  /* Parse options.  */
-  b_flag= 0;
-  f_flag= 0;
-  p_flag= 0;
-  h_arg= NULL;
-  while ((c= getopt(argc, argv, "?bfh:p")) != -1)
-  {
-	switch(c)
-	{
-	case 'b': b_flag= 1;	break;
-	case 'f': f_flag= 1;	break;
-	case 'h':
-		if (h_arg)
-			usage();
-		if (getuid() == 0)
-			h_arg= optarg;
-		break;
-	case 'p': p_flag= 1;	break;
-	case '?':
-		usage();
-	default:
-		fprintf(stderr, "login: getopt failed: '%c'\n", c);
-		exit(1);
-	}
-  }
-  if (optind < argc)
-	initialname= argv[optind++];
-  else
-	initialname= NULL;
-  if (optind != argc)
-	usage();
-
-  authorized= f_flag;
-  hostname= h_arg;
-  preserv_env= p_flag;
-  do_banner= b_flag;
-
-  /* Look up /dev/tty number. */
-  tty_name= ttyname(0);
-  if (tty_name == NULL)
-  {
-	write(1, "Unable to lookup tty name\n", 26);
-	exit(1);
-  }
-
-  if (do_banner)
-  {
-	uname(&uts);
-	write(1, "\n", 1);
-	write(1, uts.sysname, strlen(uts.sysname));
-	write(1, "/", 1);
-	write(1, uts.machine, strlen(uts.machine));
-	write(1, " Release ", 9);
-	write(1, uts.release, strlen(uts.release));
-	write(1, " Version ", 9);
-	write(1, uts.version, strlen(uts.version));
-	write(1, " (", 2);
-	p= strrchr(tty_name, '/');
-	if (!p)
-		p= tty_name;
-	else
-		p++;
-	write(1, p, strlen(p));
-	write(1, ")\n\n", 3);
-	write(1, uts.nodename, strlen(uts.nodename));
-	write(1, " ", 1);
-  }
-
-  /* Get login name and passwd. */
-  for (;;initialname= NULL) {
-	if (initialname)
-		strcpy(name, initialname);
-	else {
-		do {
-			write(1, "login: ", 7);
-			n = read(0, name, 30);
-			if (n == 0) exit(1);
-			if (n < 0)
-			{
-				if (errno != EINTR)
-					fprintf(stderr,
-						"login: read failed: %s\n",
-							strerror(errno));
-				exit(1);
-			}
-		} while (n < 2);
-		name[n - 1] = 0;
-	}
-
-	/* Start timer running. */
-	time_out = 0;
-	sa.sa_handler = Time_out;
-	sigaction(SIGALRM, &sa, NULL);
-	alarm(60);
-
-
-	/* Look up login/passwd. */
-	pwd = getpwnam(name);
-
-	check_pw = 1;			/* default is check password. */
-
-	/* For now, only console is secure. */
-	secure = fstat(0, &ttystat) == 0 && securetty(ttystat.st_rdev);
-
-	if (pwd && authorized && initialname
-			&& (pwd->pw_uid == getuid() || getuid() == 0)) {
-		check_pw= 0;		/* Don't ask a password for
-					 * pre-authorized users.
-					 */
-	} else
-	if (pwd && secure && strcmp(crypt("", pwd->pw_passwd),
-						pwd->pw_passwd) == 0) {
-		check_pw= 0;		/* empty password */
-	}
-
-	if (check_pw) {
-		password = getpass("Password:");
-
-		if (time_out) exit(1);
-
-		bad = 0;
-		if (!pwd) bad = 1;
-		if (!password) { password = ""; bad = 1; }
-		if (!secure && pwd && strcmp(crypt("", pwd->pw_passwd),
-					pwd->pw_passwd) == 0) bad = 1;
-
-		cryptedpwd = bad ? "*" : pwd->pw_passwd;
-
-		if (strcmp(crypt(password, cryptedpwd), cryptedpwd) != 0) {
-			write(1, "Login incorrect\n", 16);
-			continue;
-		}
-	}
-	/* Check if the system is going down  */
-	if (access("/etc/nologin", 0) == 0 && strcmp(name, "root") != 0) {
-		write(1, "System going down\n\n", 19);
-		continue;
-	}
-
-	/* Stop timer. */
-	alarm(0);
-
-	/* Write login record to /usr/adm/wtmp and /etc/utmp */
-	wtmp(name, pwd->pw_uid);
-
-	/* Create the argv[] array from the pw_shell field. */
-	ap = 0;
-	argx[ap++] = argx0;	/* "-sh" most likely */
-	if (pwd->pw_shell[0]) {
-		sh = pwd->pw_shell;
-		bp = sh;
-		while (*bp) {
-			while (*bp && *bp != ' ' && *bp != '\t') bp++;
-			if (*bp == ' ' || *bp == '\t') {
-				*bp++ = '\0';	/* mark end of string */
-				argx[ap++] = bp;
-			}
-		}
-	} else
-	argx[ap] = NULL;
-	strcpy(argx0, "-");	/* most shells need it for their .profile */
-	if ((bp= strrchr(sh, '/')) == NULL) bp = sh; else bp++;
-	strncat(argx0, bp, sizeof(argx0) - 2);
-
-	/* Set the environment */
-	if (p_flag)
-	{
-		for (ep= environ; *ep; ep++)
-			;
-	}
-	else
-		ep= environ;
-
-	envsiz= ep-environ;
-	env= calloc(envsiz + EXTRA_ENV, sizeof(*env));
-	if (env == NULL)
-	{
-		fprintf(stderr, "login: out of memory\n");
-		exit(1);
-	}
-	for (i= 0; i<envsiz; i++)
-		env[i]= environ[i];
-
-	strcpy(user, "USER=");
-	strcat(user, name);
-	add2env(env, user, 1);
-	strcpy(logname, "LOGNAME=");
-	strcat(logname, name);
-	add2env(env, logname, 1);
-	strcpy(home, "HOME=");
-	strcat(home, pwd->pw_dir);
-	add2env(env, home, 1);
-	strcpy(shell, "SHELL=");
-	strcat(shell, sh);
-	add2env(env, shell, 1);
-	if ((ttyp = getttynam(tty_name + 5)) != NULL) {
-		strcpy(term, "TERM=");
-		strcat(term, ttyp->ty_type);
-		add2env(env, term, 0);
-	}
-
-	/* Show the message-of-the-day. */
-	show_file(PATH_MOTD);
-
-	/* Assign the terminal to this user. */
-	chown(tty_name, pwd->pw_uid, TTY_GID);
-	chmod(tty_name, 0620);
-
-	/* Change id. */
-#if __minix_vmd
-	initgroups(pwd->pw_name, pwd->pw_gid);
-#endif
-	setgid(pwd->pw_gid);
-	setuid(pwd->pw_uid);
-
-	/* cd $HOME */
-	chdir(pwd->pw_dir);
-
-	/* Reset signals to default values. */
-	sa.sa_handler = SIG_DFL;
-	for (n = 1; n <= _NSIG; ++n) sigaction(n, &sa, NULL);
-
-	/* Execute the user's shell. */
-	execve(sh, argx, env);
-
-	if (pwd->pw_gid == 0) {
-		/* Privileged user gets /bin/sh in times of crisis. */
-		sh= "/bin/sh";
-		argx[0]= "-sh";
-		strcpy(shell, "SHELL=");
-		strcat(shell, sh);
-		execve(sh, argx, env);
-	}
-	fprintf(stderr, "login: can't execute %s: %s\n", sh, strerror(errno));
-	exit(1);
-  }
-  return(0);
-}
-
-
-void Time_out(dummy)
-int dummy; /* to keep the compiler happy */
-{
-   write(2, "\r\nLogin timed out after 60 seconds\r\n", 36);
-   time_out = 1;
-}
-
-void usage()
-{
-	fprintf(stderr,
-		"Usage: login [-h hostname] [-b] [-f] [-p] [username]\n");
-	exit(1);
-}
-
-void add2env(env, entry, replace)
-char **env;
-char *entry;
-int replace;
-{
-/* Replace an environment variable with entry or add entry if the environment
- * variable doesn't exit yet. 
- */
-	char *cp;
-	int keylen;
-
-	cp= strchr(entry, '=');
-	keylen= cp-entry+1;
-
-	for(; *env; env++)
-	{
-		if (strncmp(*env, entry, keylen) == 0) {
-			if (!replace) return;		/* Don't replace */
-			break;
-		}
-	}
-	*env= entry;
-}
-
-/*
- * $PchId: login.c,v 1.6 2001/07/31 14:23:28 philip Exp $
- */
Index: trunk/minix/commands/simple/look.c
===================================================================
--- trunk/minix/commands/simple/look.c	(revision 9)
+++ 	(revision )
@@ -1,158 +1,0 @@
-/*	look 1.3 - Find lines in a sorted list.		Author: Kees J. Bot
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-
-char DEFAULT[] = "/usr/lib/dict/words";
-
-char *string, *wordlist= DEFAULT;
-
-#define MAXLEN	1024	/* Maximum word length. */
-
-int dflg= 0, fflg= 0;
-
-void nonascii(char *what)
-{
-	fprintf(stderr, "look: %s contains non-ASCII characters.\n", what);
-	exit(1);
-}
-
-int compare(char *prefix, char *word)
-{
-	char *p= prefix, *w= word;
-	int cp, cw;
-
-	do {
-		do {
-			if ((cp= *p++) == 0) return 0;
-			if (!isascii(cp)) nonascii("prefix string");
-		} while (dflg && !isspace(cp) && !isalnum(cp));
-
-		if (dflg) {
-			if (isspace(cp)) {
-				while (isspace(*p)) p++;
-				cp= ' ';
-			}
-		}
-		if (fflg && isupper(cp)) cp= tolower(cp);
-
-		do {
-			if ((cw= *w++) == 0) return 1;
-			if (!isascii(cw)) nonascii(wordlist);
-		} while (dflg && !isspace(cw) && !isalnum(cw));
-
-		if (dflg) {
-			if (isspace(cw)) {
-				while (isspace(*w)) w++;
-				cw= ' ';
-			}
-		}
-		if (fflg && isupper(cw)) cw= tolower(cw);
-	} while (cp == cw);
-
-	return cp - cw;
-}
-
-char *readword(FILE *f)
-{
-	static char word[MAXLEN + 2];
-	int n;
-
-	if (fgets(word, sizeof(word), f) == nil) {
-		if (ferror(f)) {
-			fprintf(stderr, "look: read error on %s",
-				wordlist);
-			exit(1);
-		}
-		return nil;
-	}
-
-	n= strlen(word);
-
-	if (word[n-1] != '\n') {
-		fprintf(stderr, "look: word from %s is too long\n", wordlist);
-		exit(1);
-	}
-	word[n-1] = 0;
-
-	return word;
-}
-
-void look(void)
-{
-	off_t low, mid, high;
-	FILE *f;
-	char *word;
-	int c;
-
-	if ((f= fopen(wordlist, "r")) == nil) {
-		fprintf(stderr, "look: Can't open %s\n", wordlist);
-		exit(1);
-	}
-
-	low= 0;
-
-	fseek(f, (off_t) 0, 2);
-
-	high= ftell(f);
-
-	while (low <= high) {
-		mid= (low + high) / 2;
-
-		fseek(f, mid, 0);
-
-		if (mid != 0) readword(f);
-
-		if ((word= readword(f)) == nil)
-			c= -1;
-		else
-			c= compare(string, word);
-
-		if (c <= 0) high= mid - 1; else low= mid + 1;
-	}
-	fseek(f, low, 0);
-	if (low != 0) readword(f);
-
-	c=0;
-	while (c >= 0 && (word= readword(f)) != nil) {
-		c= compare(string, word);
-
-		if (c == 0) puts(word);
-	}
-}
-
-int main(int argc, char **argv)
-{
-	if (argc == 2) dflg= fflg= 1;
-
-	while (argc > 1 && argv[1][0] == '-') {
-		char *p= argv[1] + 1;
-
-		while (*p != 0) {
-			switch (*p++) {
-			case 'd':	dflg= 1; break;
-			case 'f':	fflg= 1; break;
-			default:
-				fprintf(stderr, "look: Bad flag: %c\n", p[-1]);
-				exit(1);
-			}
-		}
-		argc--;
-		argv++;
-	}
-	if (argc == 3)
-		wordlist= argv[2];
-	else
-	if (argc != 2) {
-		fprintf(stderr, "Usage: look [-df] string [file]\n");
-		exit(1);
-	}
-	string= argv[1];
-	look();
-	exit(0);
-}
-/* Kees J. Bot 24-5-89. */
Index: trunk/minix/commands/simple/lp.c
===================================================================
--- trunk/minix/commands/simple/lp.c	(revision 9)
+++ 	(revision )
@@ -1,91 +1,0 @@
-/*	lp 1.4 - Send file to the lineprinter		Author: Kees J. Bot
- *								3 Dec 1989
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/wait.h>
-
-char LPD1[] = "/usr/sbin/lpd";		/* Proper place of lpd */
-char LPD2[] = "/usr/bin/lpd";		/* Minix has no sbin directories. */
-
-void report(char *mess)
-{
-	fprintf(stderr, "lp: %s: %s\n", mess, strerror(errno));
-}
-
-void fatal(char *mess)
-{
-	report(mess);
-	exit(1);
-}
-
-void lp(char *file)
-/* Start the lpd daemon giving it the file to spool and print. */
-{
-	int pid, status;
-
-	if (file[0] != '/' || (pid= fork()) == 0) {
-		execl(LPD1, LPD1, file, (char *) nil);
-		if (errno != ENOENT) fatal(LPD1);
-		execl(LPD2, LPD2, file, (char *) nil);
-		fatal(LPD2);
-	}
-
-	if (pid < 0) fatal("can't fork");
-
-	if (waitpid(pid, &status, 0) < 0) fatal("wait");
-
-	if (status != 0) exit(1);
-}
-
-char path[PATH_MAX+1];
-int cwdsize;
-
-int main(int argc, char **argp)
-{
-	int e=0;
-	char *file;
-
-	if (argc <= 1) lp("stdin");
-
-	/* Lpd requires full path names, so find out where we are. */
-	if (getcwd(path, sizeof(path)) == nil)
-		fatal("Can't determine current directory");
-
-	cwdsize= strlen(path);
-
-	/* Hand each file to lpd. */
-	while ((file= *++argp) != nil) {
-
-		close(0);
-
-		if (open(file, O_RDONLY) != 0) {
-			report(file);
-			e=1;
-			continue;
-		}
-		if (file[0] == '/') {
-			lp(file);
-			continue;
-		}
-		if (cwdsize + 1 + strlen(file) + 1 > sizeof(path)) {
-			fprintf(stderr,
-				"lp: full pathname of %s is too long\n",
-				file);
-			e=1;
-			continue;
-		}
-		path[cwdsize] = '/';
-		strcpy(path + cwdsize + 1, file);
-
-		lp(path);
-	}
-	exit(e);
-}
Index: trunk/minix/commands/simple/lpd.c
===================================================================
--- trunk/minix/commands/simple/lpd.c	(revision 9)
+++ 	(revision )
@@ -1,368 +1,0 @@
-/*	lpd 1.6 - Printer daemon			Author: Kees J. Bot
- *								3 Dec 1989
- */
-#define nil 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <termcap.h>
-
-char PRINTER[] =	"/dev/lp";
-char SPOOL[] =		"/usr/spool/lpd";
-char LOG[] =		"/dev/log";
-
-void report(char *mess)
-{
-	fprintf(stderr, "lpd: %s: %s\n", mess, strerror(errno));
-}
-
-void fatal(char *mess)
-{
-	report(mess);
-	exit(1);
-}
-
-char jobX[] = "jobXXXXXX";
-char tmpX[] = "tmpXXXXXX";
-
-void spoolerr(char *file)
-{
-	int e= errno;
-
-	unlink(jobX);
-	unlink(tmpX);
-	fatal(file);
-}
-
-void spool(char *path)
-/* Place a file into the spool directory, either by copying it, or by leaving
- * a reference.
- */
-{
-	char *file;
-	int j, u;
-
-	mktemp(jobX);
-	file= mktemp(tmpX);
-
-	if (path[0] == '/') {
-		int f;
-
-		if ((f= open(path, O_RDONLY)) >= 0) {
-			close(f);
-			file= path;
-		}
-	}
-	if (file != path) {
-		int c;
-		FILE *t;
-
-		if ((t= fopen(tmpX, "w")) == nil) spoolerr(tmpX);
-
-		while ((c= getchar()) != EOF && putc(c, t) != EOF) {}
-
-		if (ferror(stdin)) spoolerr(path);
-
-		if (ferror(t) || fclose(t) == EOF) spoolerr(tmpX);
-
-		fclose(stdin);
-	}
-
-	if ((j= open(jobX, O_WRONLY|O_CREAT|O_EXCL, 0000)) < 0) spoolerr(jobX);
-
-	u= getuid();
-	if (write(j, file, strlen(file)+1) < 0
-		|| write(j, &u, sizeof(u)) < 0
-		|| write(j, path, strlen(path)+1) < 0
-		|| close(j) < 0
-		|| chmod(jobX, 0600) < 0
-	) spoolerr(jobX);
-}
-
-struct job {
-	struct job *next;
-	time_t age;
-	char name[sizeof(jobX)];
-} *jobs = nil;
-
-int job(void)
-/* Look for print jobs in the spool directory.  Make a list of them sorted
- * by age.  Return true iff the list is nonempty.
- */
-{
-	DIR *spool;
-	struct dirent *entry;
-	struct job *newjob, **ajob;
-	struct stat st;
-
-	if (jobs != nil) return 1;
-
-	if ((spool= opendir(".")) == nil) fatal(SPOOL);
-
-	while ((entry= readdir(spool)) != nil) {
-		if (strncmp(entry->d_name, "job", 3) != 0) continue;
-
-		if (stat(entry->d_name, &st) < 0
-			|| (st.st_mode & 0777) == 0000) continue;
-
-		if ((newjob= malloc(sizeof(*newjob))) == nil) fatal("malloc()");
-		newjob->age = st.st_mtime;
-		strcpy(newjob->name, entry->d_name);
-
-		ajob= &jobs;
-		while (*ajob != nil && (*ajob)->age < newjob->age)
-			ajob= &(*ajob)->next;
-
-		newjob->next= *ajob;
-		*ajob= newjob;
-	}
-	closedir(spool);
-
-	return jobs != nil;
-}
-
-/* What to do with control-X:
- * 0 ignore,
- * 1 give up on controlling the printer, assume user knows how printer works,
- * 2 print.
- */
-char control[] = {
-	0, 1, 1, 1, 1, 1, 1, 0,		/* \0, \a  don't show.	*/
-	2, 2, 2, 1, 2, 2, 1, 1,		/* \b, \t, \n, \f, \r	*/
-	1, 1, 1, 1, 1, 1, 1, 1,
-	1, 1, 1, 1, 1, 1, 1, 1
-};
-
-int lp;
-char buf[BUFSIZ];
-int count, column, line, ncols = 80, nlines = 66;
-
-int flush(void)
-/* Copy the characters in the output buffer to the printer, with retries if
- * out of paper.
- */
-{
-	char *bp= buf;
-
-	while (count > 0) {
-		int retry = 0, complain = 0;
-		int r;
-
-		while ((r= write(lp, bp, count)) < 0) {
-			if (errno != EAGAIN) fatal(PRINTER);
-			if (retry == complain) {
-				fprintf(stderr,
-					"lpd: %s: Printer out of paper\n",
-					PRINTER);
-				complain= retry + 60;
-			}
-			sleep(1);
-			retry++;
-		}
-		bp+= r;
-		count-= r;
-	}
-	count = 0;
-}
-
-int put(int c)
-/* Send characters to the output buffer to be printed and do so if the buffer
- * is full.  Track the position of the write-head in `column' and `line'.
- */
-{
-	buf[count++] = c;
-
-	switch (c) {
-	case '\f':
-		column = 0;
-		line = 0;
-		break;
-	case '\r':
-		column = 0;
-		break;
-	case '\n':
-		line++;
-		break;
-	case '\b':
-		column--;
-		break;
-	default:
-		if (++column > ncols) { line++; column= 1; }
-	}
-	if (line == nlines) line= 0;
-
-	if (count == BUFSIZ) flush();
-}
-
-void print(FILE *f)
-/* Send the contents of an open file to the printer.  Expand tabs and change
- * linefeed to a carriage-return linefeed sequence.  Print a formfeed at the
- * end if needed to reach the top of the next page.  If a control character
- * is printed that we do not know about, then the user is assumed to know
- * what they are doing, so output processing is disabled.
- */
-{
-	int c;
-
-	count= column= line= 0;
-
-	while ((c= getc(f)) != EOF) {
-		if (c < ' ') {
-			switch (control[c]) {
-			case 0:	continue;	/* Ignore this one. */
-			case 1:
-				/* Can't handle this junk, assume smart user. */
-				do {
-					buf[count++] = c;
-					if (count == BUFSIZ) flush();
-				} while ((c= getc(f)) != EOF);
-
-				flush();
-				return;
-			case 2: /* fine */;
-			}
-		}
-
-		switch (c) {
-		case '\n':
-			put('\r');
-			put('\n');
-			break;
-		case '\t':
-			do {
-				put(' ');
-			} while (column & 07);
-			break;
-		case '\b':
-			if (column > 0) put(c);
-			break;
-		default:
-			put(c);
-		}
-	}
-	if (column > 0) { put('\r'); put('\n'); }
-	if (line > 0) put('\f');
-	flush();
-	return;
-}
-
-void joberr(char *job)
-{
-	fprintf(stderr, "lpd: something is wrong with %s\n", job);
-
-	if (unlink(job) < 0) fatal("can't remove it");
-}
-
-void work(void)
-/* Print all the jobs in the job list. */
-{
-	FILE *j, *f;
-	char file[PATH_MAX+1], *pf=file;
-	int c;
-	struct job *job;
-
-	job= jobs;
-	jobs= jobs->next;
-
-	if ((j= fopen(job->name, "r")) == nil) {
-		joberr(job->name);
-		return;
-	}
-
-	do {
-		if (pf == file + sizeof(file) || (c= getc(j)) == EOF) {
-			fclose(j);
-			joberr(job->name);
-			return;
-		}
-		*pf++ = c;
-	} while (c != 0);
-
-	fclose(j);
-
-	if ((f= fopen(file, "r")) == nil)
-		fprintf(stderr, "lpd: can't read %s\n", file);
-	else {
-		print(f);
-		fclose(f);
-	}
-	if (file[0] != '/' && unlink(file) < 0) report(file);
-
-	if (unlink(job->name) < 0) fatal(job->name);
-	free(job);
-}
-
-void getcap(void)
-/* Find the line printer dimensions in the termcap database under "lp". */
-{
-	char printcap[1024];
-	int n;
-
-	if (tgetent(printcap, "lp") == 1) {
-		if ((n= tgetnum("co")) > 0) ncols= n;
-		if ((n= tgetnum("li")) > 0) nlines= n;
-	}
-}
-
-void haunt(void)
-/* Become a daemon, print jobs while there are any, exit. */
-{
-	int fd;
-
-	if ((fd= open("/dev/tty", O_RDONLY)) != -1) {
-		/* We have a controlling tty!  Disconnect. */
-		close(fd);
-
-		switch(fork()) {
-		case -1:	fatal("can't fork");
-		case  0:	break;
-		default:	exit(0);
-		}
-
-		if ((fd= open("/dev/null", O_RDONLY)) < 0) fatal("/dev/null");
-		dup2(fd, 0);
-		close(fd);
-		if ((fd= open(LOG, O_WRONLY)) < 0) fatal(LOG);
-		dup2(fd, 1);
-		dup2(fd, 2);
-		close(fd);
-		setsid();
-	}
-
-	getcap();
-
-	do {
-		if ((lp= open(PRINTER, O_WRONLY)) < 0) {
-			/* Another lpd? */
-			if (errno == EBUSY) exit(0);
-			fatal(PRINTER);
-		}
-
-		while (job()) work();
-
-		close(lp);
-	} while (job());
-}
-
-int main(int argc, char **argv)
-{
-	if (argc > 2) {
-		fprintf(stderr, "Usage: %s [path | stdin < path]\n", argv[0]);
-		exit(1);
-	}
-
-	umask(0077);
-
-	if (chdir(SPOOL) < 0) fatal(SPOOL);
-
-	if (argc == 2) spool(argv[1]);
-
-	haunt();
-}
Index: trunk/minix/commands/simple/ls.c
===================================================================
--- trunk/minix/commands/simple/ls.c	(revision 9)
+++ 	(revision )
@@ -1,1150 +1,0 @@
-/*	ls 5.4 - List files.				Author: Kees J. Bot
- *								25 Apr 1989
- *
- * About the amount of bytes for heap + stack under Minix:
- * Ls needs a average amount of 42 bytes per unserviced directory entry, so
- * scanning 10 directory levels deep in an ls -R with 100 entries per directory
- * takes 42000 bytes of heap.  So giving ls 10000 bytes is tight, 20000 is
- * usually enough, 40000 is pessimistic.
- */
-
-/* The array l_ifmt[] is used in an 'ls -l' to map the type of a file to a
- * letter.  This is done so that ls can list any future file or device type
- * other than symlinks, without recompilation.  (Yes it's dirty.)
- */
-char l_ifmt[] = "0pcCd?bB-?l?s???";
-
-#define ifmt(mode)	l_ifmt[((mode) >> 12) & 0xF]
-
-#define nil 0
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <time.h>
-#include <pwd.h>
-#include <grp.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-#ifndef major
-#define major(dev)	((int) (((dev) >> 8) & 0xFF))
-#define minor(dev)	((int) (((dev) >> 0) & 0xFF))
-#endif
-
-#if !__minix
-#define SUPER_ID	uid	/* Let -A flag be default for SUPER_ID == 0. */
-#else
-#define SUPER_ID	gid
-#endif
-
-#ifdef S_IFLNK
-int (*status)(const char *file, struct stat *stp);
-#else
-#define status	stat
-#endif
-
-/* Basic disk block size is 512 except for one niche O.S. */
-#if __minix
-#define BLOCK	1024
-#else
-#define BLOCK	 512
-#endif
-
-/* Assume other systems have st_blocks. */
-#if !__minix
-#define ST_BLOCKS 1
-#endif
-
-/* Some terminals ignore more than 80 characters on a line.  Dumb ones wrap
- * when the cursor hits the side.  Nice terminals don't wrap until they have
- * to print the 81st character.  Whether we like it or not, no column 80.
- */
-int ncols= 79;
-
-#define NSEP	3	/* # spaces between columns. */
-
-#define MAXCOLS	128	/* Max # of files per line. */
-
-char *arg0;	/* Last component of argv[0]. */
-int uid, gid;	/* callers id. */
-int ex= 0;	/* Exit status to be. */
-int istty;	/* Output is on a terminal. */
-
-/* Safer versions of malloc and realloc: */
-
-void heaperr(void)
-{
-	fprintf(stderr, "%s: Out of memory\n", arg0);
-	exit(-1);
-}
-
-void *allocate(size_t n)
-/* Deliver or die. */
-{
-	void *a;
-
-	if ((a= malloc(n)) == nil) heaperr();
-	return a;
-}
-
-void *reallocate(void *a, size_t n)
-{
-	if ((a= realloc(a, n)) == nil) heaperr();
-	return a;
-}
-
-char allowed[] = "acdfghilnpqrstu1ACDFLMRTX";
-char flags[sizeof(allowed)];
-
-char arg0flag[] = "cdfmrtx";	/* These in argv[0] go to upper case. */
-
-void setflags(char *flgs)
-{
-	int c;
-
-	while ((c= *flgs++) != 0) {
-		if (strchr(allowed, c) == nil) {
-			fprintf(stderr, "Usage: %s [-%s] [file ...]\n",
-				arg0, allowed);
-			exit(1);
-		} else
-		if (strchr(flags, c) == nil) {
-			flags[strlen(flags)] = c;
-		}
-	}
-}
-
-int present(int f)
-{
-	return f == 0 || strchr(flags, f) != nil;
-}
-
-void report(char *f)
-/* Like perror(3), but in the style: "ls: junk: No such file or directory. */
-{
-	fprintf(stderr, "%s: %s: %s\n", arg0, f, strerror(errno));
-	ex= 1;
-}
-
-/* Two functions, uidname and gidname, translate id's to readable names.
- * All names are remembered to avoid searching the password file.
- */
-#define NNAMES	(1 << (sizeof(int) + sizeof(char *)))
-enum whatmap { PASSWD, GROUP };
-
-struct idname {		/* Hash list of names. */
-	struct idname	*next;
-	char		*name;
-	uid_t		id;
-} *uids[NNAMES], *gids[NNAMES];
-
-char *idname(unsigned id, enum whatmap map)
-/* Return name for a given user/group id. */
-{
-	struct idname *i;
-	struct idname **ids= &(map == PASSWD ? uids : gids)[id % NNAMES];
-
-	while ((i= *ids) != nil && id < i->id) ids= &i->next;
-
-	if (i == nil || id != i->id) {
-		/* Not found, go look in the password or group map. */
-		char *name= nil;
-		char noname[3 * sizeof(uid_t)];
-
-		if (!present('n')) {
-			if (map == PASSWD) {
-				struct passwd *pw= getpwuid(id);
-
-				if (pw != nil) name= pw->pw_name;
-			} else {
-				struct group *gr= getgrgid(id);
-
-				if (gr != nil) name= gr->gr_name;
-			}
-		}
-		if (name == nil) {
-			/* Can't find it, weird.  Use numerical "name." */
-			sprintf(noname, "%u", id);
-			name= noname;
-		}
-
-		/* Add a new id-to-name cell. */
-		i= allocate(sizeof(*i));
-		i->id= id;
-		i->name= allocate(strlen(name) + 1);
-		strcpy(i->name, name);
-		i->next= *ids;
-		*ids= i;
-	}
-	return i->name;
-}
-
-#define uidname(uid)	idname((uid), PASSWD)
-#define gidname(gid)	idname((gid), GROUP)
-
-/* Path name construction, addpath adds a component, delpath removes it.
- * The string path is used throughout the program as the file under examination.
- */
-
-char *path;	/* Path name constructed in path[]. */
-int plen= 0, pidx= 0;	/* Lenght/index for path[]. */
-
-void addpath(int *didx, char *name)
-/* Add a component to path. (name may also be a full path at the first call)
- * The index where the current path ends is stored in *pdi.
- */
-{
-	if (plen == 0) path= (char *) allocate((plen= 32) * sizeof(path[0]));
-
-	if (pidx == 1 && path[0] == '.') pidx= 0;	/* Remove "." */
-
-	*didx= pidx;	/* Record point to go back to for delpath. */
-
-	if (pidx > 0 && path[pidx-1] != '/') path[pidx++]= '/';
-
-	do {
-		if (*name != '/' || pidx == 0 || path[pidx-1] != '/') {
-			if (pidx == plen) {
-				path= (char *) reallocate((void *) path,
-						(plen*= 2) * sizeof(path[0]));
-			}
-			path[pidx++]= *name;
-		}
-	} while (*name++ != 0);
-
-	--pidx;		/* Put pidx back at the null.  The path[pidx++]= '/'
-			 * statement will overwrite it at the next call.
-			 */
-}
-
-#define delpath(didx)	(path[pidx= didx]= 0)	/* Remove component. */
-
-int field = 0;	/* (used to be) Fields that must be printed. */
-		/* (now) Effects triggered by certain flags. */
-
-#define L_INODE		0x0001	/* -i */
-#define L_BLOCKS	0x0002	/* -s */
-#define L_EXTRA		0x0004	/* -X */
-#define L_MODE		0x0008	/* -lMX */
-#define L_LONG		0x0010	/* -l */
-#define L_GROUP		0x0020	/* -g */
-#define L_BYTIME	0x0040	/* -tuc */
-#define L_ATIME		0x0080	/* -u */
-#define L_CTIME		0x0100	/* -c */
-#define L_MARK		0x0200	/* -F */
-#define L_MARKDIR	0x0400	/* -p */
-#define L_TYPE		0x0800	/* -D */
-#define L_LONGTIME	0x1000	/* -T */
-#define L_DIR		0x2000	/* -d */
-#define L_KMG		0x4000	/* -h */
-
-struct file {		/* A file plus stat(2) information. */
-	struct file	*next;	/* Lists are made of them. */
-	char		*name;	/* Null terminated name. */
-	ino_t		ino;
-	mode_t		mode;
-	uid_t		uid;
-	gid_t		gid;
-	nlink_t		nlink;
-	dev_t		rdev;
-	off_t		size;
-	time_t		mtime;
-	time_t		atime;
-	time_t		ctime;
-#if ST_BLOCKS
-	long		blocks;
-#endif
-};
-
-void setstat(struct file *f, struct stat *stp)
-{
-	f->ino=		stp->st_ino;
-	f->mode=	stp->st_mode;
-	f->nlink=	stp->st_nlink;
-	f->uid=		stp->st_uid;
-	f->gid=		stp->st_gid;
-	f->rdev=	stp->st_rdev;
-	f->size=	stp->st_size;
-	f->mtime=	stp->st_mtime;
-	f->atime=	stp->st_atime;
-	f->ctime=	stp->st_ctime;
-#if ST_BLOCKS
-	f->blocks=	stp->st_blocks;
-#endif
-}
-
-#define	PAST	(26*7*24*3600L)	/* Half a year ago. */
-/* Between PAST and FUTURE from now a time is printed, otherwise a year. */
-#define FUTURE	( 1*7*24*3600L)	/* One week. */
-
-static char *timestamp(struct file *f)
-/* Transform the right time field into something readable. */
-{
-	struct tm *tm;
-	time_t t;
-	static time_t now;
-	static int drift= 0;
-	static char date[] = "Jan 19 03:14:07 2038";
-	static char month[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
-
-	t= f->mtime;
-	if (field & L_ATIME) t= f->atime;
-	if (field & L_CTIME) t= f->ctime;
-
-	tm= localtime(&t);
-	if (--drift < 0) { time(&now); drift= 50; }	/* limit time() calls */
-
-	if (field & L_LONGTIME) {
-		sprintf(date, "%.3s %2d %02d:%02d:%02d %d",
-			month + 3*tm->tm_mon,
-			tm->tm_mday,
-			tm->tm_hour, tm->tm_min, tm->tm_sec,
-			1900 + tm->tm_year);
-	} else
-	if (t < now - PAST || t > now + FUTURE) {
-		sprintf(date, "%.3s %2d  %d",
-			month + 3*tm->tm_mon,
-			tm->tm_mday,
-			1900 + tm->tm_year);
-	} else {
-		sprintf(date, "%.3s %2d %02d:%02d",
-			month + 3*tm->tm_mon,
-			tm->tm_mday,
-			tm->tm_hour, tm->tm_min);
-	}
-	return date;
-}
-
-char *permissions(struct file *f)
-/* Compute long or short rwx bits. */
-{
-	static char rwx[] = "drwxr-x--x";
-
-	rwx[0] = ifmt(f->mode);
-	/* Note that rwx[0] is a guess for the more alien file types.  It is
-	 * correct for BSD4.3 and derived systems.  I just don't know how
-	 * "standardized" these numbers are.
-	 */
-
-	if (field & L_EXTRA) {		/* Short style */
-		int mode = f->mode, ucase= 0;
-
-		if (uid == f->uid) {	/* What group of bits to use. */
-			/* mode<<= 0, */
-			ucase= (mode<<3) | (mode<<6);
-			/* Remember if group or others have permissions. */
-		} else
-		if (gid == f->gid) {
-			mode<<= 3;
-		} else {
-			mode<<= 6;
-		}
-		rwx[1]= mode&S_IRUSR ? (ucase&S_IRUSR ? 'R' : 'r') : '-';
-		rwx[2]= mode&S_IWUSR ? (ucase&S_IWUSR ? 'W' : 'w') : '-';
-
-		if (mode&S_IXUSR) {
-			static char sbit[]= { 'x', 'g', 'u', 's' };
-
-			rwx[3]= sbit[(f->mode&(S_ISUID|S_ISGID))>>10];
-			if (ucase&S_IXUSR) rwx[3] += 'A'-'a';
-		} else {
-			rwx[3]= f->mode&(S_ISUID|S_ISGID) ? '=' : '-';
-		}
-		rwx[4]= 0;
-	} else {		/* Long form. */
-		char *p= rwx+1;
-		int mode= f->mode;
-
-		do {
-			p[0] = (mode & S_IRUSR) ? 'r' : '-';
-			p[1] = (mode & S_IWUSR) ? 'w' : '-';
-			p[2] = (mode & S_IXUSR) ? 'x' : '-';
-			mode<<= 3;
-		} while ((p+=3) <= rwx+7);
-
-		if (f->mode&S_ISUID) rwx[3]= f->mode&(S_IXUSR>>0) ? 's' : '=';
-		if (f->mode&S_ISGID) rwx[6]= f->mode&(S_IXUSR>>3) ? 's' : '=';
-		if (f->mode&S_ISVTX) rwx[9]= f->mode&(S_IXUSR>>6) ? 't' : '=';
-	}
-	return rwx;
-}
-
-void numeral(int i, char **pp)
-{
-	char itoa[3*sizeof(int)], *a=itoa;
-
-	do *a++ = i%10 + '0'; while ((i/=10) > 0);
-
-	do *(*pp)++ = *--a; while (a>itoa);
-}
-
-#define K	1024L		/* A kilobyte counts in multiples of K */
-#define T	1000L		/* A megabyte in T*K, a gigabyte in T*T*K */
-
-char *cxsize(struct file *f)
-/* Try and fail to turn a 32 bit size into 4 readable characters. */
-{
-	static char siz[] = "1.2m";
-	char *p= siz;
-	off_t z;
-
-	siz[1]= siz[2]= siz[3]= 0;
-
-	if (f->size <= 5*K) {	/* <= 5K prints as is. */
-		numeral((int) f->size, &p);
-		return siz;
-	}
-	z= (f->size + K-1) / K;
-
-	if (z <= 999) {		/* Print as 123k. */
-		numeral((int) z, &p);
-		*p = 'k';	/* Can't use 'K', looks bad */
-	} else
-	if (z*10 <= 99*T) {	/* 1.2m (Try ls -X /dev/at0) */
-		z= (z*10 + T-1) / T;	/* Force roundup */
-		numeral((int) z / 10, &p);
-		*p++ = '.';
-		numeral((int) z % 10, &p);
-		*p = 'm';
-	} else
-	if (z <= 999*T) {	/* 123m */
-		numeral((int) ((z + T-1) / T), &p);
-		*p = 'm';
-	} else {		/* 1.2g */
-		z= (z*10 + T*T-1) / (T*T);
-		numeral((int) z / 10, &p);
-		*p++ = '.';
-		numeral((int) z % 10, &p);
-		*p = 'g';
-	}
-	return siz;
-}
-
-/* Transform size of file to number of blocks.  This was once a function that
- * guessed the number of indirect blocks, but that nonsense has been removed.
- */
-#if ST_BLOCKS
-#define nblocks(f)	((f)->blocks)
-#else
-#define nblocks(f)	(((f)->size + BLOCK-1) / BLOCK)
-#endif
-
-/* From number of blocks to kilobytes. */
-#if BLOCK < 1024
-#define nblk2k(nb)	(((nb) + (1024 / BLOCK - 1)) / (1024 / BLOCK))
-#else
-#define nblk2k(nb)	((nb) * (BLOCK / 1024))
-#endif
-
-static int (*CMP)(struct file *f1, struct file *f2);
-static int (*rCMP)(struct file *f1, struct file *f2);
-
-static void mergesort(struct file **al)
-/* This is either a stable mergesort, or thermal noise, I'm no longer sure.
- * It must be called like this: if (L != nil && L->next != nil) mergesort(&L);
- */
-{
-	/* static */ struct file *l1, **mid;  /* Need not be local */
-	struct file *l2;
-
-	l1= *(mid= &(*al)->next);
-	do {
-		if ((l1= l1->next) == nil) break;
-		mid= &(*mid)->next;
-	} while ((l1= l1->next) != nil);
-
-	l2= *mid;
-	*mid= nil;
-
-	if ((*al)->next != nil) mergesort(al);
-	if (l2->next != nil) mergesort(&l2);
-
-	l1= *al;
-	for (;;) {
-		if ((*CMP)(l1, l2) <= 0) {
-			if ((l1= *(al= &l1->next)) == nil) {
-				*al= l2;
-				break;
-			}
-		} else {
-			*al= l2;
-			l2= *(al= &l2->next);
-			*al= l1;
-			if (l2 == nil) break;
-		}
-	}
-}
-
-int namecmp(struct file *f1, struct file *f2)
-{
-	return strcmp(f1->name, f2->name);
-}
-
-int mtimecmp(struct file *f1, struct file *f2)
-{
-	return f1->mtime == f2->mtime ? 0 : f1->mtime > f2->mtime ? -1 : 1;
-}
-
-int atimecmp(struct file *f1, struct file *f2)
-{
-	return f1->atime == f2->atime ? 0 : f1->atime > f2->atime ? -1 : 1;
-}
-
-int ctimecmp(struct file *f1, struct file *f2)
-{
-	return f1->ctime == f2->ctime ? 0 : f1->ctime > f2->ctime ? -1 : 1;
-}
-
-int typecmp(struct file *f1, struct file *f2)
-{
-	return ifmt(f1->mode) - ifmt(f2->mode);
-}
-
-int revcmp(struct file *f1, struct file *f2) { return (*rCMP)(f2, f1); }
-
-static void sort(struct file **al)
-/* Sort the files according to the flags. */
-{
-	if (!present('f') && *al != nil && (*al)->next != nil) {
-		CMP= namecmp;
-
-		if (!(field & L_BYTIME)) {
-			/* Sort on name */
-
-			if (present('r')) { rCMP= CMP; CMP= revcmp; }
-			mergesort(al);
-		} else {
-			/* Sort on name first, then sort on time. */
-
-			mergesort(al);
-			if (field & L_CTIME) {
-				CMP= ctimecmp;
-			} else
-			if (field & L_ATIME) {
-				CMP= atimecmp;
-			} else {
-				CMP= mtimecmp;
-			}
-
-			if (present('r')) { rCMP= CMP; CMP= revcmp; }
-			mergesort(al);
-		}
-		/* Separate by file type if so desired. */
-
-		if (field & L_TYPE) {
-			CMP= typecmp;
-			mergesort(al);
-		}
-	}
-}
-
-struct file *newfile(char *name)
-/* Create file structure for given name. */
-{
-	struct file *new;
-
-	new= (struct file *) allocate(sizeof(*new));
-	new->name= strcpy((char *) allocate(strlen(name)+1), name);
-	return new;
-}
-
-void pushfile(struct file **flist, struct file *new)
-/* Add file to the head of a list. */
-{
-	new->next= *flist;
-	*flist= new;
-}
-
-void delfile(struct file *old)
-/* Release old file structure. */
-{
-	free((void *) old->name);
-	free((void *) old);
-}
-
-struct file *popfile(struct file **flist)
-/* Pop file off top of file list. */
-{
-	struct file *f;
-
-	f= *flist;
-	*flist= f->next;
-	return f;
-}
-
-int dotflag(char *name)
-/* Return flag that would make ls list this name: -a or -A. */
-{
-	if (*name++ != '.') return 0;
-
-	switch (*name++) {
-	case 0:		return 'a';			/* "." */
-	case '.':	if (*name == 0) return 'a';	/* ".." */
-	default:	return 'A';			/* ".*" */
-	}
-}
-
-int adddir(struct file **aflist, char *name)
-/* Add directory entries of directory name to a file list. */
-{
-	DIR *d;
-	struct dirent *e;
-
-	if (access(name, 0) < 0) {
-		report(name);
-		return 0;
-	}
-
-	if ((d= opendir(name)) == nil) {
-		report(name);
-		return 0;
-	}
-	while ((e= readdir(d)) != nil) {
-		if (e->d_ino != 0 && present(dotflag(e->d_name))) {
-			pushfile(aflist, newfile(e->d_name));
-			aflist= &(*aflist)->next;
-		}
-	}
-	closedir(d);
-	return 1;
-}
-
-off_t countblocks(struct file *flist)
-/* Compute total block count for a list of files. */
-{
-	off_t cb = 0;
-
-	while (flist != nil) {
-		switch (flist->mode & S_IFMT) {
-		case S_IFDIR:
-		case S_IFREG:
-#ifdef S_IFLNK
-		case S_IFLNK:
-#endif
-			cb += nblocks(flist);
-		}
-		flist= flist->next;
-	}
-	return cb;
-}
-
-void printname(char *name)
-/* Print a name with control characters as '?' (unless -q).  The terminal is
- * assumed to be eight bit clean.
- */
-{
-	int c, q= present('q');
-
-	while ((c= (unsigned char) *name++) != 0) {
-		if (q && (c < ' ' || c == 0177)) c= '?';
-		putchar(c);
-	}
-}
-
-int mark(struct file *f, int doit)
-{
-	int c;
-
-	c= 0;
-
-	if (field & L_MARK) {
-		switch (f->mode & S_IFMT) {
-		case S_IFDIR:	c= '/'; break;
-#ifdef S_IFIFO
-		case S_IFIFO:	c= '|'; break;
-#endif
-#ifdef S_IFLNK
-		case S_IFLNK:	c= '@'; break;
-#endif
-#ifdef S_IFSOCK
-		case S_IFSOCK:	c= '='; break;
-#endif
-		case S_IFREG:
-			if (f->mode & (S_IXUSR | S_IXGRP | S_IXOTH)) c= '*';
-			break;
-		}
-	} else
-	if (field & L_MARKDIR) {
-		if (S_ISDIR(f->mode)) c= '/';
-	}
-
-	if (doit && c != 0) putchar(c);
-	return c;
-}
-
-/* Width of entire column, and of several fields. */
-enum { W_COL, W_INO, W_BLK, W_NLINK, W_UID, W_GID, W_SIZE, W_NAME, MAXFLDS };
-
-unsigned char fieldwidth[MAXCOLS][MAXFLDS];
-
-void maxise(unsigned char *aw, int w)
-/* Set *aw to the larger of it and w. */
-{
-	if (w > *aw) {
-		if (w > UCHAR_MAX) w= UCHAR_MAX;
-		*aw= w;
-	}
-}
-
-int numwidth(unsigned long n)
-/* Compute width of 'n' when printed. */
-{
-	int width= 0;
-
-	do { width++; } while ((n /= 10) > 0);
-	return width;
-}
-
-#if !__minix
-int numxwidth(unsigned long n)
-/* Compute width of 'n' when printed in hex. */
-{
-	int width= 0;
-
-	do { width++; } while ((n /= 16) > 0);
-	return width;
-}
-#endif
-
-static int nsp= 0;	/* This many spaces have not been printed yet. */
-#define spaces(n)	(nsp= (n))
-#define terpri()	(nsp= 0, putchar('\n'))		/* No trailing spaces */
-
-void print1(struct file *f, int col, int doit)
-/* Either compute the number of spaces needed to print file f (doit == 0) or
- * really print it (doit == 1).
- */
-{
-	int width= 0, n;
-	char *p;
-	unsigned char *f1width = fieldwidth[col];
-
-	while (nsp>0) { putchar(' '); nsp--; }/* Fill gap between two columns */
-
-	if (field & L_INODE) {
-		if (doit) {
-			printf("%*d ", f1width[W_INO], f->ino);
-		} else {
-			maxise(&f1width[W_INO], numwidth(f->ino));
-			width++;
-		}
-	}
-	if (field & L_BLOCKS) {
-		unsigned long nb= nblk2k(nblocks(f));
-		if (doit) {
-			printf("%*lu ", f1width[W_BLK], nb);
-		} else {
-			maxise(&f1width[W_BLK], numwidth(nb));
-			width++;
-		}
-	}
-	if (field & L_MODE) {
-		if (doit) {
-			printf("%s ", permissions(f));
-		} else {
-			width+= (field & L_EXTRA) ? 5 : 11;
-		}
-	}
-	if (field & L_EXTRA) {
-		p= cxsize(f);
-		n= strlen(p)+1;
-
-		if (doit) {
-			n= f1width[W_SIZE] - n;
-			while (n > 0) { putchar(' '); --n; }
-			printf("%s ", p);
-		} else {
-			maxise(&f1width[W_SIZE], n);
-		}
-	}
-	if (field & L_LONG) {
-		if (doit) {
-			printf("%*u ", f1width[W_NLINK], (unsigned) f->nlink);
-		} else {
-			maxise(&f1width[W_NLINK], numwidth(f->nlink));
-			width++;
-		}
-		if (!(field & L_GROUP)) {
-			if (doit) {
-				printf("%-*s  ", f1width[W_UID],
-							uidname(f->uid));
-			} else {
-				maxise(&f1width[W_UID],
-						strlen(uidname(f->uid)));
-				width+= 2;
-			}
-		}
-		if (doit) {
-			printf("%-*s  ", f1width[W_GID], gidname(f->gid));
-		} else {
-			maxise(&f1width[W_GID], strlen(gidname(f->gid)));
-			width+= 2;
-		}
-
-		switch (f->mode & S_IFMT) {
-		case S_IFBLK:
-		case S_IFCHR:
-#ifdef S_IFMPB
-		case S_IFMPB:
-#endif
-#ifdef S_IFMPC
-		case S_IFMPC:
-#endif
-#if __minix
-			if (doit) {
-				printf("%*d, %3d ", f1width[W_SIZE] - 5,
-					major(f->rdev), minor(f->rdev));
-			} else {
-				maxise(&f1width[W_SIZE],
-						numwidth(major(f->rdev)) + 5);
-				width++;
-			}
-#else /* !__minix */
-			if (doit) {
-				printf("%*lX ", f1width[W_SIZE],
-					(unsigned long) f->rdev);
-			} else {
-				maxise(&f1width[W_SIZE], numwidth(f->rdev));
-				width++;
-			}
-#endif /* !__minix */
-			break;
-		default:
-			if (field & L_KMG) {
-				p= cxsize(f);
-				n= strlen(p)+1;
-
-				if (doit) {
-					n= f1width[W_SIZE] - n;
-					while (n > 0) { putchar(' '); --n; }
-					printf("%s ", p);
-				} else {
-					maxise(&f1width[W_SIZE], n);
-				}
-			} else {
-				if (doit) {
-					printf("%*lu ", f1width[W_SIZE],
-						(unsigned long) f->size);
-				} else {
-					maxise(&f1width[W_SIZE],
-						numwidth(f->size));
-					width++;
-				}
-			}
-		}
-
-		if (doit) {
-			printf("%s ", timestamp(f));
-		} else {
-			width+= (field & L_LONGTIME) ? 21 : 13;
-		}
-	}
-
-	n= strlen(f->name);
-	if (doit) {
-		printname(f->name);
-		if (mark(f, 1) != 0) n++;
-#ifdef S_IFLNK
-		if ((field & L_LONG) && (f->mode & S_IFMT) == S_IFLNK) {
-			char *buf;
-			int r, didx;
-
-			buf= (char *) allocate(((size_t) f->size + 1)
-							* sizeof(buf[0]));
-			addpath(&didx, f->name);
-			r= readlink(path, buf, (int) f->size);
-			delpath(didx);
-			if (r > 0) buf[r] = 0; else r=1, strcpy(buf, "?");
-			printf(" -> ");
-			printname(buf);
-			free((void *) buf);
-			n+= 4 + r;
-		}
-#endif
-		spaces(f1width[W_NAME] - n);
-	} else {
-		if (mark(f, 0) != 0) n++;
-#ifdef S_IFLNK
-		if ((field & L_LONG) && (f->mode & S_IFMT) == S_IFLNK) {
-			n+= 4 + (int) f->size;
-		}
-#endif
-		maxise(&f1width[W_NAME], n + NSEP);
-
-		for (n= 1; n < MAXFLDS; n++) width+= f1width[n];
-		maxise(&f1width[W_COL], width);
-	}
-}
-
-int countfiles(struct file *flist)
-/* Return number of files in the list. */
-{
-	int n= 0;
-
-	while (flist != nil) { n++; flist= flist->next; }
-
-	return n;
-}
-
-struct file *filecol[MAXCOLS];	/* filecol[i] is list of files for column i. */
-int nfiles, nlines;	/* # files to print, # of lines needed. */
-
-void columnise(struct file *flist, int nplin)
-/* Chop list of files up in columns.  Note that 3 columns are used for 5 files
- * even though nplin may be 4, filecol[3] will simply be nil.
- */
-{
-	int i, j;
-
-	nlines= (nfiles + nplin - 1) / nplin;	/* nlines needed for nfiles */
-
-	filecol[0]= flist;
-
-	for (i=1; i<nplin; i++) {	/* Give nlines files to each column. */
-		for (j=0; j<nlines && flist != nil; j++) flist= flist->next;
-
-		filecol[i]= flist;
-	}
-}
-
-int print(struct file *flist, int nplin, int doit)
-/* Try (doit == 0), or really print the list of files over nplin columns.
- * Return true if it can be done in nplin columns or if nplin == 1.
- */
-{
-	register struct file *f;
-	register int col, fld, totlen;
-
-	columnise(flist, nplin);
-
-	if (!doit) {
-		for (col= 0; col < nplin; col++) {
-			for (fld= 0; fld < MAXFLDS; fld++) {
-				fieldwidth[col][fld]= 0;
-			}
-		}
-	}
-
-	while (--nlines >= 0) {
-		totlen= 0;
-
-		for (col= 0; col < nplin; col++) {
-			if ((f= filecol[col]) != nil) {
-				filecol[col]= f->next;
-				print1(f, col, doit);
-			}
-			if (!doit && nplin > 1) {
-				/* See if this line is not too long. */
-				if (fieldwidth[col][W_COL] == UCHAR_MAX) {
-					return 0;
-				}
-				totlen+= fieldwidth[col][W_COL];
-				if (totlen > ncols+NSEP) return 0;
-			}
-		}
-		if (doit) terpri();
-	}
-	return 1;
-}
-
-enum depth { SURFACE, SURFACE1, SUBMERGED };
-enum state { BOTTOM, SINKING, FLOATING };
-
-void listfiles(struct file *flist, enum depth depth, enum state state)
-/* Main workhorse of ls, it sorts and prints the list of files.  Flags:
- * depth: working with the command line / just one file / listing dir.
- * state: How "recursive" do we have to be.
- */
-{
-	struct file *dlist= nil, **afl= &flist, **adl= &dlist;
-	int nplin;
-	static int white = 1;	/* Nothing printed yet. */
-
-	/* Flush everything previously printed, so new error output will
-	 * not intermix with files listed earlier.
-	 */
-	fflush(stdout);
-
-	if (field != 0 || state != BOTTOM) {	/* Need stat(2) info. */
-		while (*afl != nil) {
-			static struct stat st;
-			int r, didx;
-
-			addpath(&didx, (*afl)->name);
-
-			if ((r= status(path, &st)) < 0
-#ifdef S_IFLNK
-				&& (status == lstat || lstat(path, &st) < 0)
-#endif
-			) {
-				if (depth != SUBMERGED || errno != ENOENT)
-					report((*afl)->name);
-				delfile(popfile(afl));
-			} else {
-				setstat(*afl, &st);
-				afl= &(*afl)->next;
-			}
-			delpath(didx);
-		}
-	}
-	sort(&flist);
-
-	if (depth == SUBMERGED && (field & (L_BLOCKS | L_LONG))) {
-		printf("total %ld\n", nblk2k(countblocks(flist)));
-	}
-
-	if (state == SINKING || depth == SURFACE1) {
-	/* Don't list directories themselves, list their contents later. */
-		afl= &flist;
-		while (*afl != nil) {
-			if (((*afl)->mode & S_IFMT) == S_IFDIR) {
-				pushfile(adl, popfile(afl));
-				adl= &(*adl)->next;
-			} else {
-				afl= &(*afl)->next;
-			}
-		}
-	}
-
-	if ((nfiles= countfiles(flist)) > 0) {
-		/* Print files in how many columns? */
-		nplin= !present('C') ? 1 : nfiles < MAXCOLS ? nfiles : MAXCOLS;
-
-		while (!print(flist, nplin, 0)) nplin--;	/* Try first */
-
-		print(flist, nplin, 1);		/* Then do it! */
-		white = 0;
-	}
-
-	while (flist != nil) {	/* Destroy file list */
-		if (state == FLOATING && (flist->mode & S_IFMT) == S_IFDIR) {
-			/* But keep these directories for ls -R. */
-			pushfile(adl, popfile(&flist));
-			adl= &(*adl)->next;
-		} else {
-			delfile(popfile(&flist));
-		}
-	}
-
-	while (dlist != nil) {	/* List directories */
-		if (dotflag(dlist->name) != 'a' || depth != SUBMERGED) {
-			int didx;
-
-			addpath(&didx, dlist->name);
-
-			flist= nil;
-			if (adddir(&flist, path)) {
-				if (depth != SURFACE1) {
-					if (!white) putchar('\n');
-					printf("%s:\n", path);
-					white = 0;
-				}
-				listfiles(flist, SUBMERGED,
-					state == FLOATING ? FLOATING : BOTTOM);
-			}
-			delpath(didx);
-		}
-		delfile(popfile(&dlist));
-	}
-}
-
-int main(int argc, char **argv)
-{
-	struct file *flist= nil, **aflist= &flist;
-	enum depth depth;
-	char *lsflags;
-	struct winsize ws;
-
-	uid= geteuid();
-	gid= getegid();
-
-	if ((arg0= strrchr(argv[0], '/')) == nil) arg0= argv[0]; else arg0++;
-	argv++;
-
-	if (strcmp(arg0, "ls") != 0) {
-		char *p= arg0+1;
-
-		while (*p != 0) {
-			if (strchr(arg0flag, *p) != nil) *p += 'A' - 'a';
-			p++;
-		}
-		setflags(arg0+1);
-	}
-	while (*argv != nil && (*argv)[0] == '-') {
-		if ((*argv)[1] == '-' && (*argv)[2] == 0) {
-			argv++;
-			break;
-		}
-		setflags(*argv++ + 1);
-	}
-
-	istty= isatty(1);
-
-	if (istty && (lsflags= getenv("LSOPTS")) != nil) {
-		if (*lsflags == '-') lsflags++;
-		setflags(lsflags);
-	}
-
-	if (!present('1') && !present('C') && !present('l')
-		&& (istty || present('M') || present('X') || present('F'))
-	) setflags("C");
-
-	if (istty) setflags("q");
-
-	if (SUPER_ID == 0 || present('a')) setflags("A");
-
-	if (present('i')) field|= L_INODE;
-	if (present('s')) field|= L_BLOCKS;
-	if (present('M')) field|= L_MODE;
-	if (present('X')) field|= L_EXTRA | L_MODE;
-	if (present('t')) field|= L_BYTIME;
-	if (present('u')) field|= L_ATIME;
-	if (present('c')) field|= L_CTIME;
-	if (present('l')) field|= L_MODE | L_LONG;
-	if (present('g')) field|= L_MODE | L_LONG | L_GROUP;
-	if (present('F')) field|= L_MARK;
-	if (present('p')) field|= L_MARKDIR;
-	if (present('D')) field|= L_TYPE;
-	if (present('T')) field|= L_MODE | L_LONG | L_LONGTIME;
-	if (present('d')) field|= L_DIR;
-	if (present('h')) field|= L_KMG;
-	if (field & L_LONG) field&= ~L_EXTRA;
-
-#ifdef S_IFLNK
-	status= present('L') ? stat : lstat;
-#endif
-
-	if (present('C')) {
-		int t= istty ? 1 : open("/dev/tty", O_WRONLY);
-
-		if (t >= 0 && ioctl(t, TIOCGWINSZ, &ws) == 0 && ws.ws_col > 0)
-			ncols= ws.ws_col - 1;
-
-		if (t != 1 && t != -1) close(t);
-	}
-
-	depth= SURFACE;
-
-	if (*argv == nil) {
-		if (!(field & L_DIR)) depth= SURFACE1;
-		pushfile(aflist, newfile("."));
-	} else {
-		if (argv[1] == nil && !(field & L_DIR)) depth= SURFACE1;
-
-		do {
-			pushfile(aflist, newfile(*argv++));
-			aflist= &(*aflist)->next;
-		} while (*argv!=nil);
-	}
-	listfiles(flist, depth,
-		(field & L_DIR) ? BOTTOM : present('R') ? FLOATING : SINKING);
-	return ex;
-}
Index: trunk/minix/commands/simple/mail.c
===================================================================
--- trunk/minix/commands/simple/mail.c	(revision 9)
+++ 	(revision )
@@ -1,776 +1,0 @@
-/*  mail - send/receive mail 		 Author: Peter S. Housel */
-/* Version 0.2 of September 1990: added -e, -t, * options - cwr */
-
-/* 2003-07-18: added -s option - ASW */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#undef EOF			/* temporary hack */
-#include <signal.h>
-#include <pwd.h>
-#include <time.h>
-#include <setjmp.h>
-#include <string.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <stdio.h>
-
-#ifdef DEBUG
-#define D(Q) (Q)
-#else
-#define D(Q)
-#endif
-
-#define SHELL		"/bin/sh"
-
-#define DROPNAME 	"/usr/spool/mail/%s"
-#define LOCKNAME	"/usr/spool/mail/%s.lock"
-#define LOCKWAIT	5	/* seconds to wait after collision */
-#define LOCKTRIES	4	/* maximum number of collisions */
-
-#define MBOX		"mbox"
-
-#define HELPFILE	"/usr/lib/mail.help"
-#define PROMPT		"? "
-#define PATHLEN		80
-#define MAXRCPT		100	/* maximum number of recipients */
-#define LINELEN		512
-
-/* #define MAILER		"/usr/bin/smail"	*/ /* smart mailer */
-#define MAILERARGS		/* (unused) */
-
-#define UNREAD		1	/* 'not read yet' status */
-#define DELETED		2	/* 'deleted' status */
-#define READ		3	/* 'has been read' status */
-
-struct letter {
-  struct letter *prev, *next;	/* linked letter list */
-  int status;			/* letter status */
-  off_t location;		/* location within mailbox file */
-};
-
-struct letter *firstlet, *lastlet;
-
-int usemailer = 1;		/* use MAILER to deliver (if any) */
-int printmode = 0;		/* print-and-exit mode */
-int quitmode = 0;		/* take interrupts */
-int reversemode = 0;		/* print mailbox in reverse order */
-int usedrop = 1;		/* read the maildrop (no -f given) */
-int verbose = 0;		/* pass "-v" flag on to mailer */
-int needupdate = 0;		/* need to update mailbox */
-int msgstatus = 0;		/* return the mail status */
-int distlist = 0;		/* include distribution list */
-char mailbox[PATHLEN];		/* user's mailbox/maildrop */
-char tempname[PATHLEN] = "/tmp/mailXXXXXX";	/* temporary file */
-char *subject = NULL;
-FILE *boxfp = NULL;		/* mailbox file */
-jmp_buf printjump;		/* for quitting out of letters */
-unsigned oldmask;		/* saved umask() */
-
-extern int optind;
-extern char *optarg;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(int deliver, (int count, char *vec []));
-_PROTOTYPE(FILE *makerewindable, (void));
-_PROTOTYPE(int copy, (FILE *fromfp, FILE *tofp));
-_PROTOTYPE(void readbox, (void));
-_PROTOTYPE(void printall, (void));
-_PROTOTYPE(void interact, (void));
-_PROTOTYPE(void onint, (int dummy));
-_PROTOTYPE(void savelet, (struct letter *let, char *savefile));
-_PROTOTYPE(void updatebox, (void));
-_PROTOTYPE(void printlet, (struct letter *let, FILE *tofp));
-_PROTOTYPE(void doshell, (char *command));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(char *basename, (char *name));
-_PROTOTYPE(char *whoami, (void));
-_PROTOTYPE(void dohelp, (void));
-_PROTOTYPE(int filesize, (char *name));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int c;
-
-  if ('l' == (basename(argv[0]))[0])	/* 'lmail' link? */
-	usemailer = 0;		/* yes, let's deliver it */
-
-  (void) mktemp(tempname);	/* name the temp file */
-
-  oldmask = umask(022);		/* change umask for security */
-
-  while (EOF != (c = getopt(argc, argv, "epqrf:tdvs:"))) switch (c) {
-	    case 'e':	++msgstatus;	break;	
-
-	    case 't':	++distlist;	break;
-
-	    case 'p':	++printmode;	break;
-
-	    case 'q':	++quitmode;	break;
-
-	    case 'r':	++reversemode;	break;
-
-	    case 'f':
-		setuid(getuid());	/* won't need to lock */
-		usedrop = 0;
-		strncpy(mailbox, optarg, (size_t)(PATHLEN - 1));
-		break;
-
-	    case 'd':	usemailer = 0;	break;
-
-	    case 'v':	++verbose;	break;
-
-	    case 's':	subject = optarg; break;
-
-	    default:
-		usage();
-		exit(1);
-	}
-
-  if (optind < argc) {
-	if (deliver(argc - optind, argv + optind) < 0)
-		exit(1);
-	else
-		exit(0);
-  }
-  if (usedrop) sprintf(mailbox, DROPNAME, whoami());
-
-  D(printf("mailbox=%s\n", mailbox));
-
-  if (msgstatus) {
-	if (filesize(mailbox))
-		exit(0);
-	else
-		exit(1);
-  }
-
-  readbox();
-
-  if (printmode)
-	printall();
-  else
-	interact();
-
-  if (needupdate) updatebox();
-
-  return(0);
-}
-
-int deliver(count, vec)
-int count;
-char *vec[];
-{
-  int i, j;
-  int errs = 0;			/* count of errors */
-  int dropfd;			/* file descriptor for user's drop */
-  int created = 0;		/* true if we created the maildrop */
-  FILE *mailfp;			/* fp for mail */
-  struct stat stb;		/* for checking drop modes, owners */
-#ifdef __STDC__
-  void (*sigint)(int), (*sighup)(int), (*sigquit)(int);/* saving signal state */
-#else
-  void (*sigint) (), (*sighup) (), (*sigquit) ();      /* saving signal state */
-#endif
-  time_t now;			/* for datestamping the postmark */
-  char sender[32];		/* sender's login name */
-  char lockname[PATHLEN];	/* maildrop lock */
-  int locktries;		/* tries when box is locked */
-  struct passwd *pw;		/* sender and recipent */
-  int to_console;		/* deliver to console if everything fails */
-
-  if (count > MAXRCPT) {
-	fprintf(stderr, "mail: too many recipients\n");
-	return -1;
-  }
-#ifdef MAILER
-  if (usemailer) {
-	char *argvec[MAXRCPT + 3];
-	char **argp;
-
-	setuid(getuid());
-
-	argp = argvec;
-	*argp++ = "send-mail";
-	if (verbose) *argp++ = "-v";
-
-	for (i = 0; i < count; ++i) *argp++ = vec[i];
-
-	*argp = NULL;
-	execv(MAILER, argvec);
-	fprintf(stderr, "mail: couldn't exec %s\n", MAILER);
-	return -1;
-  }
-#endif /* MAILER */
-
-  if (NULL == (pw = getpwuid(getuid()))) {
-	fprintf(stderr, "mail: unknown sender\n");
-	return -1;
-  }
-  strcpy(sender, pw->pw_name);
-
-  /* If we need to rewind stdin and it isn't rewindable, make a copy */
-  if (isatty(0) || (count > 1 && lseek(0, 0L, 0) == (off_t) -1)) {
-	mailfp = makerewindable();
-  } else
-	mailfp = stdin;
-
-  /* Shut off signals during the delivery */
-  sigint = signal(SIGINT, SIG_IGN);
-  sighup = signal(SIGHUP, SIG_IGN);
-  sigquit = signal(SIGQUIT, SIG_IGN);
-
-  for (i = 0; i < count; ++i) {
-	if (count > 1) rewind(mailfp);
-
-	D(printf("deliver to %s\n", vec[i]));
-
-	if (NULL == (pw = getpwnam(vec[i]))) {
-		fprintf(stderr, "mail: user %s not known\n", vec[i]);
-		++errs;
-		continue;
-	}
-	sprintf(mailbox, DROPNAME, pw->pw_name);
-	sprintf(lockname, LOCKNAME, pw->pw_name);
-
-	D(printf("maildrop='%s', lock='%s'\n", mailbox, lockname));
-
-	/* Lock the maildrop while we're messing with it. Races are
-	 * possible (though not very likely) when we have to create
-	 * the maildrop, but not otherwise. If the box is already
-	 * locked, wait awhile and try again. */
-	locktries = created = to_console = 0;
-trylock:
-	if (link(mailbox, lockname) != 0) {
-		if (ENOENT == errno) {	/* user doesn't have a drop yet */
-			dropfd = creat(mailbox, 0600);
-			if (dropfd < 0 && errno == ENOENT) {
-				/* Probably missing spool dir; to console. */
-				boxfp = fopen("/dev/console", "w");
-				if (boxfp != NULL) {
-					to_console = 1;
-					goto nobox;
-				}
-			}
-			if (dropfd < 0) {
-				fprintf(stderr, "mail: couln't create a maildrop for user %s\n",
-					vec[i]);
-				++errs;
-				continue;
-			}
-			++created;
-			goto trylock;
-		} else {	/* somebody else has it locked, it seems -
-			 * wait */
-			if (++locktries >= LOCKTRIES) {
-				fprintf(stderr, "mail: couldn't lock maildrop for user %s\n",
-					vec[i]);
-				++errs;
-				continue;
-			}
-			sleep(LOCKWAIT);
-			goto trylock;
-		}
-	}
-	if (created) {
-		(void) chown(mailbox, pw->pw_uid, pw->pw_gid);
-		boxfp = fdopen(dropfd, "a");
-	} else
-		boxfp = fopen(mailbox, "a");
-
-	if (NULL == boxfp || stat(mailbox, &stb) < 0) {
-		fprintf(stderr, "mail: serious maildrop problems for %s\n", vec[i]);
-		unlink(lockname);
-		++errs;
-		continue;
-	}
-	if (stb.st_uid != pw->pw_uid || (stb.st_mode & S_IFMT) != S_IFREG) {
-		fprintf(stderr, "mail: mailbox for user %s is illegal\n", vec[i]);
-		unlink(lockname);
-		++errs;
-		continue;
-	}
-nobox:
-	if (to_console) {
-		fprintf(boxfp,
-			"-------------\n| Mail from %s to %s\n-------------\n",
-			sender, vec[i]);
-	} else {
-		(void) time(&now);
-		fprintf(boxfp, "From %s %24.24s\n", sender, ctime(&now));
-	}
-
-	/* Add the To: header line */
-	fprintf(boxfp, "To: %s\n", vec[i]);
-
-	if (distlist) {
-		fprintf(boxfp, "Dist: ");
-		for (j = 0; j < count; ++j)
-			if (getpwnam(vec[j]) != NULL && j != i)
-				fprintf(boxfp, "%s ", vec[j]) ;
-		fprintf(boxfp, "\n");
-	}
-
-	/* Add the Subject: header line */
-	if (subject != NULL) fprintf(boxfp, "Subject: %s\n", subject);
-
-	fprintf(boxfp, "\n");
- 
-	if ((copy(mailfp, boxfp) < 0) || (fclose(boxfp) != 0)) {
-		fprintf(stderr, "mail: error delivering to user %s", vec[i]);
-		perror(" ");
-		++errs;
-	}
-	unlink(lockname);
-  }
-
-  fclose(mailfp);
-
-  /* Put signals back the way they were */
-  signal(SIGINT, sigint);
-  signal(SIGHUP, sighup);
-  signal(SIGQUIT, sigquit);
-
-  return(0 == errs) ? 0 : -1;
-}
-
-/* 'stdin' isn't rewindable. Make a temp file that is.
- * Note that if one wanted to catch SIGINT and write a '~/dead.letter'
- * for interactive mails, this might be the place to do it (though the
- * case where a MAILER is being used would also need to be handled).
- */
-FILE *makerewindable()
-{
-  FILE *tempfp;			/* temp file used for copy */
-  int c;			/* character being copied */
-  int state;			/* ".\n" detection state */
-
-  if (NULL == (tempfp = fopen(tempname, "w"))) {
-	fprintf(stderr, "mail: can't create temporary file\n");
-	return NULL;
-  }
-
-  /* Here we copy until we reach the end of the letter (end of file or
-   * a line containing only a '.'), painstakingly avoiding setting a
-   * line length limit. */
-  state = '\n';
-  while (EOF != (c = getc(stdin))) switch (state) {
-	    case '\n':
-		if ('.' == c)
-			state = '.';
-		else {
-			if ('\n' != c) state = '\0';
-			putc(c, tempfp);
-		}
-		break;
-	    case '.':
-		if ('\n' == c) goto done;
-		state = '\0';
-		putc('.', tempfp);
-		putc(c, tempfp);
-		break;
-	    default:
-		state = ('\n' == c) ? '\n' : '\0';
-		putc(c, tempfp);
-	}
-done:
-  if (ferror(tempfp) || fclose(tempfp)) {
-	fprintf(stderr, "mail: couldn't copy letter to temporary file\n");
-	return NULL;
-  }
-  tempfp = freopen(tempname, "r", stdin);
-  unlink(tempname);		/* unlink name; file lingers on in limbo */
-  return tempfp;
-}
-
-int copy(fromfp, tofp)
-FILE *fromfp, *tofp;
-{
-  int c;			/* character being copied */
-  int state;			/* ".\n" and postmark detection state */
-  int blankline = 0;		/* was most recent line completely blank? */
-  static char postmark[] = "From ";
-  char *p, *q;
-
-  /* Here we copy until we reach the end of the letter (end of file or
-   * a line containing only a '.'). Postmarks (lines beginning with
-   * "From ") are copied with a ">" prepended. Here we also complicate
-   * things by not setting a line limit. */
-  state = '\n';
-  p = postmark;
-  while (EOF != (c = getc(fromfp))) {
-	switch (state) {
-	    case '\n':
-		if ('.' == c)	/* '.' at BOL */
-			state = '.';
-		else if (*p == c) {	/* start of postmark */
-			++p;
-			state = 'P';
-		} else {	/* anything else */
-			if ('\n' == c)
-				blankline = 1;
-			else {
-				state = '\0';
-				blankline = 0;
-			}
-			putc(c, tofp);
-		}
-		break;
-	    case '.':
-		if ('\n' == c) goto done;
-		state = '\0';
-		putc('.', tofp);
-		putc(c, tofp);
-		break;
-	    case 'P':
-		if (*p == c) {
-			if (*++p == '\0') {	/* successfully reached end */
-				p = postmark;
-				putc('>', tofp);
-				fputs(postmark, tofp);
-				state = '\0';
-				break;
-			}
-			break;	/* not there yet */
-		}
-		state = ('\n' == c) ? '\n' : '\0';
-		for (q = postmark; q < p; ++q) putc(*q, tofp);
-		putc(c, tofp);
-		blankline = 0;
-		p = postmark;
-		break;
-	    default:
-		state = ('\n' == c) ? '\n' : '\0';
-		putc(c, tofp);
-	}
-  }
-  if ('\n' != state) putc('\n', tofp);
-done:
-  if (!blankline) putc('\n', tofp);
-  if (ferror(tofp)) return -1;
-  return 0;
-}
-
-void readbox()
-{
-  char linebuf[512];
-  struct letter *let;
-  off_t current;
-
-  firstlet = lastlet = NULL;
-
-  if (access(mailbox, 4) < 0 || NULL == (boxfp = fopen(mailbox, "r"))) {
-	if (usedrop && ENOENT == errno) return;
-	fprintf(stderr, "can't access mailbox ");
-	perror(mailbox);
-	exit(1);
-  }
-  current = 0L;
-  while (1) {
-	if (NULL == fgets(linebuf, sizeof linebuf, boxfp)) break;
-
-	if (!strncmp(linebuf, "From ", (size_t)5)) {
-		if (NULL == (let = (struct letter *) malloc(sizeof(struct letter)))) {
-			fprintf(stderr, "Out of memory.\n");
-			exit(1);
-		}
-		if (NULL == lastlet) {
-			firstlet = let;
-			let->prev = NULL;
-		} else {
-			let->prev = lastlet;
-			lastlet->next = let;
-		}
-		lastlet = let;
-		let->next = NULL;
-
-		let->status = UNREAD;
-		let->location = current;
-		D(printf("letter at %ld\n", current));
-	}
-	current += strlen(linebuf);
-  }
-}
-
-void printall()
-{
-  struct letter *let;
-
-  let = reversemode ? firstlet : lastlet;
-
-  if (NULL == let) {
-	printf("No mail.\n");
-	return;
-  }
-  while (NULL != let) {
-	printlet(let, stdout);
-	let = reversemode ? let->next : let->prev;
-  }
-}
-
-void interact()
-{
-  char linebuf[512];		/* user input line */
-  struct letter *let, *next;	/* current and next letter */
-  int interrupted = 0;		/* SIGINT hit during letter print */
-  int needprint = 1;		/* need to print this letter */
-  char *savefile;		/* filename to save into */
-
-  if (NULL == firstlet) {
-	printf("No mail.\n");
-	return;
-  }
-  let = reversemode ? firstlet : lastlet;
-
-  while (1) {
-	next = reversemode ? let->next : let->prev;
-	if (NULL == next) next = let;
-
-	if (!quitmode) {
-		interrupted = setjmp(printjump);
-		signal(SIGINT, onint);
-	}
-	if (!interrupted && needprint) {
-		if (DELETED != let->status) let->status = READ;
-		printlet(let, stdout);
-	}
-	if (interrupted) putchar('\n');
-	needprint = 0;
-	fputs(PROMPT, stdout);
-	fflush(stdout);
-
-	if (fgets(linebuf, sizeof linebuf, stdin) == NULL) break;
-
-	if (!quitmode) signal(SIGINT, SIG_IGN);
-
-	switch (linebuf[0]) {
-	    case '\n':
-		let = next;
-		needprint = 1;
-		continue;
-	    case 'd':
-		let->status = DELETED;
-		if (next != let)/* look into this */
-			needprint = 1;
-		needupdate = 1;
-		let = next;
-		continue;
-	    case 'p':
-		needprint = 1;
-		continue;
-	    case '-':
-		next = reversemode ? let->prev : let->next;
-		if (NULL == next) next = let;
-		let = next;
-		needprint = 1;
-		continue;
-	    case 's':
-		for (savefile = strtok(linebuf + 1, " \t\n");
-		     savefile != NULL;
-		     savefile = strtok((char *) NULL, " \t\n")) {
-			savelet(let, savefile);
-		}
-		continue;
-	    case '!':
-		doshell(linebuf + 1);
-		continue;
-	    case '*':
-		dohelp();
-		continue;
-	    case 'q':
-		return;
-	    case 'x':
-		exit(0);
-	    default:
-		fprintf(stderr, "Illegal command\n");
-		continue;
-	}
-  }
-}
-
-void onint(dummy)
-int dummy;	/* to satisfy ANSI compilers */
-{
-  longjmp(printjump, 1);
-}
-
-void savelet(let, savefile)
-struct letter *let;
-char *savefile;
-{
-  int waitstat, pid;
-  FILE *savefp;
-
-  if ((pid = fork()) < 0) {
-	perror("mail: couldn't fork");
-	return;
-  } else if (pid != 0) {	/* parent */
-	wait(&waitstat);
-	return;
-  }
-
-  /* Child */
-  setgid(getgid());
-  setuid(getuid());
-  if ((savefp = fopen(savefile, "a")) == NULL) {
-	perror(savefile);
-	exit(0);
-  }
-  printlet(let, savefp);
-  if ((ferror(savefp) != 0) | (fclose(savefp) != 0)) {
-	fprintf(stderr, "savefile write error:");
-	perror(savefile);
-  }
-  exit(0);
-}
-
-void updatebox()
-{
-  FILE *tempfp;			/* fp for tempfile */
-  char lockname[PATHLEN];	/* maildrop lock */
-  int locktries = 0;		/* tries when box is locked */
-  struct letter *let;		/* current letter */
-  int c;
-
-  sprintf(lockname, LOCKNAME, whoami());
-
-  if (NULL == (tempfp = fopen(tempname, "w"))) {
-	perror("mail: can't create temporary file");
-	return;
-  }
-  for (let = firstlet; let != NULL; let = let->next) {
-	if (let->status != DELETED) {
-		printlet(let, tempfp);
-		D(printf("printed letter at %ld\n", let->location));
-	}
-  }
-
-  if (ferror(tempfp) || NULL == (tempfp = freopen(tempname, "r", tempfp))) {
-	perror("mail: temporary file write error");
-	unlink(tempname);
-	return;
-  }
-
-  /* Shut off signals during the update */
-  signal(SIGINT, SIG_IGN);
-  signal(SIGHUP, SIG_IGN);
-  signal(SIGQUIT, SIG_IGN);
-
-  if (usedrop) while (link(mailbox, lockname) != 0) {
-		if (++locktries >= LOCKTRIES) {
-			fprintf(stderr, "mail: couldn't lock maildrop for update\n");
-			return;
-		}
-		sleep(LOCKWAIT);
-	}
-
-  if (NULL == (boxfp = freopen(mailbox, "w", boxfp))) {
-	perror("mail: couldn't reopen maildrop");
-	fprintf(stderr, "mail may have been lost; look in %s\n", tempname);
-	if (usedrop) unlink(lockname);
-	return;
-  }
-  unlink(tempname);
-
-  while ((c = getc(tempfp)) != EOF) putc(c, boxfp);
-
-  fclose(boxfp);
-
-  if (usedrop) unlink(lockname);
-}
-
-void printlet(let, tofp)
-struct letter *let;
-FILE *tofp;
-{
-  off_t current, limit;
-  int c;
-
-  fseek(boxfp, (current = let->location), 0);
-  limit = (NULL != let->next) ? let->next->location : -1;
-
-  while (current != limit && (c = getc(boxfp)) != EOF) {
-	putc(c, tofp);
-	++current;
-  }
-}
-
-void doshell(command)
-char *command;
-{
-  int waitstat, pid;
-  char *shell;
-
-  if (NULL == (shell = getenv("SHELL"))) shell = SHELL;
-
-  if ((pid = fork()) < 0) {
-	perror("mail: couldn't fork");
-	return;
-  } else if (pid != 0) {	/* parent */
-	wait(&waitstat);
-	return;
-  }
-
-  /* Child */
-  setgid(getgid());
-  setuid(getuid());
-  umask(oldmask);
-
-  execl(shell, shell, "-c", command, (char *) NULL);
-  fprintf(stderr, "can't exec shell\n");
-  exit(127);
-}
-
-void usage()
-{
-  fprintf(stderr, "usage: mail [-epqr] [-f file]\n");
-  fprintf(stderr, "       mail [-dtv] [-s subject] user [...]\n");
-}
-
-char *basename(name)
-char *name;
-{
-  char *p;
-
-  if (NULL == (p = rindex(name, '/')))
-	return name;
-  else
-	return p + 1;
-}
-
-char *whoami()
-{
-  struct passwd *pw;
-
-  if (NULL != (pw = getpwuid(getuid())))
-	return pw->pw_name;
-  else
-	return "nobody";
-}
-
-void dohelp()
-{
-  FILE *fp;
-  char buffer[80];
-
-  if ( (fp = fopen(HELPFILE, "r")) == NULL)
-	fprintf(stdout, "can't open helpfile %s\n", HELPFILE);
-  else
-	while (fgets(buffer, 80, fp))
-		fputs(buffer, stdout);
-}
-
-int filesize(name)
-char *name ;
-{
-  struct stat buf;
- 
-  if (stat(name, &buf) == -1)
-	buf.st_size = 0L;
-
-  return (buf.st_size ? 1 : 0);
-}
Index: trunk/minix/commands/simple/man.c
===================================================================
--- trunk/minix/commands/simple/man.c	(revision 9)
+++ 	(revision )
@@ -1,695 +1,0 @@
-/*	man 2.4 - display online manual pages		Author: Kees J. Bot
- *								17 Mar 1993
- */
-#define nil NULL
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-
-/* Defaults: */
-char MANPATH[]=	"/usr/local/man:/usr/man:/usr/gnu/man";
-char PAGER[]=	"more";
-
-/* Comment at the start to let tbl(1) be run before n/troff. */
-char TBL_MAGIC[] = ".\\\"t\n";
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-#define between(a, c, z) ((unsigned) ((c) - (a)) <= (unsigned) ((z) - (a)))
-
-/* Section 9 uses special macros under Minix. */
-#if __minix
-#define SEC9SPECIAL	1
-#else
-#define SEC9SPECIAL	0
-#endif
-
-int searchwhatis(FILE *wf, char *title, char **ppage, char **psection)
-/* Search a whatis file for the next occurence of "title".  Return the basename
- * of the page to read and the section it is in.  Return 0 on failure, 1 on
- * success, -1 on EOF or error.
- */
-{
-    static char page[256], section[32];
-    char alias[256];
-    int found= 0;
-    int c;
-
-    /* Each whatis line should have the format:
-     *	page, title, title (section) - descriptive text
-     */
-
-    /* Search the file for a line with the title. */
-    do {
-	int first= 1;
-	char *pc= section;
-
-	c= fgetc(wf);
-
-	/* Search the line for the title. */
-	do {
-	    char *pa= alias;
-
-	    while (c == ' ' || c == '\t' || c == ',') c= fgetc(wf);
-
-	    while (c != ' ' && c != '\t' && c != ','
-		    && c != '(' && c != '\n' && c != EOF
-	    ) {
-		if (pa < arraylimit(alias)-1) *pa++= c;
-		c= getc(wf);
-	    }
-	    *pa= 0;
-	    if (first) { strcpy(page, alias); first= 0; }
-
-	    if (strcmp(alias, title) == 0) found= 1;
-	} while (c != '(' && c != '\n' && c != EOF);
-
-	if (c != '(') {
-	    found= 0;
-	} else {
-	    while ((c= fgetc(wf)) != ')' && c != '\n' && c != EOF) {
-		if ('A' <= c && c <= 'Z') c= c - 'A' + 'a';
-		if (pc < arraylimit(section)-1) *pc++= c;
-	    }
-	    *pc= 0;
-	    if (c != ')' || pc == section) found= 0;
-	}
-	while (c != EOF && c != '\n') c= getc(wf);
-    } while (!found && c != EOF);
-
-    if (found) {
-	*ppage= page;
-	*psection= section;
-    }
-    return c == EOF ? -1 : found;
-}
-
-int searchwindex(FILE *wf, char *title, char **ppage, char **psection)
-/* Search a windex file for the next occurence of "title".  Return the basename
- * of the page to read and the section it is in.  Return 0 on failure, 1 on
- * success, -1 on EOF or error.
- */
-{
-    static char page[256], section[32];
-    static long low, high;
-    long mid0, mid1;
-    int c;
-    unsigned char *pt;
-    char *pc;
-
-    /* Each windex line should have the format:
-     *	title page (section) - descriptive text
-     * The file is sorted.
-     */
-
-    if (ftell(wf) == 0) {
-	/* First read of this file, initialize. */
-	low= 0;
-	fseek(wf, (off_t) 0, SEEK_END);
-	high= ftell(wf);
-    }
-
-    /* Binary search for the title. */
-    while (low <= high) {
-	pt= (unsigned char *) title;
-
-	mid0= mid1= (low + high) >> 1;
-	if (mid0 == 0) {
-	    if (fseek(wf, (off_t) 0, SEEK_SET) != 0)
-		return -1;
-	} else {
-	    if (fseek(wf, (off_t) mid0 - 1, SEEK_SET) != 0)
-		return -1;
-
-	    /* Find the start of a line. */
-	    while ((c= getc(wf)) != EOF && c != '\n')
-		mid1++;
-	    if (ferror(wf)) return -1;
-	}
-
-	/* See if the line has the title we seek. */
-	for (;;) {
-	    if ((c= getc(wf)) == ' ' || c == '\t') c= 0;
-	    if (c == 0 || c != *pt) break;
-	    pt++;
-	}
-
-	/* Halve the search range. */
-	if (c == EOF || *pt <= c) {
-	    high= mid0 - 1;
-	} else {
-	    low= mid1 + 1;
-	}
-    }
-
-    /* Look for the title from 'low' onwards. */
-    if (fseek(wf, (off_t) low, SEEK_SET) != 0)
-	return -1;
-
-    do {
-	if (low != 0) {
-	    /* Find the start of a line. */
-	    while ((c= getc(wf)) != EOF && c != '\n')
-		low++;
-	    if (ferror(wf)) return -1;
-	}
-
-	/* See if the line has the title we seek. */
-	pt= (unsigned char *) title;
-
-	for (;;) {
-	    if ((c= getc(wf)) == EOF) return 0;
-	    low++;
-	    if (c == ' ' || c == '\t') c= 0;
-	    if (c == 0 || c != *pt) break;
-	    pt++;
-	}
-    } while (c < *pt);
-
-    if (*pt != c) return 0;		/* Not found. */
-
-    /* Get page and section. */
-    while ((c= fgetc(wf)) == ' ' || c == '\t') {}
-
-    pc= page;
-    while (c != ' ' && c != '\t' && c != '(' && c != '\n' && c != EOF) {
-	if (pc < arraylimit(page)-1) *pc++= c;
-	c= getc(wf);
-    }
-    if (pc == page) return 0;
-    *pc= 0;
-
-    while (c == ' ' || c == '\t') c= fgetc(wf);
-
-    if (c != '(') return 0;
-
-    pc= section;
-    while ((c= fgetc(wf)) != ')' && c != '\n' && c != EOF) {
-	if ('A' <= c && c <= 'Z') c= c - 'A' + 'a';
-	if (pc < arraylimit(section)-1) *pc++= c;
-    }
-    *pc= 0;
-    if (c != ')' || pc == section) return 0;
-
-    while (c != EOF && c != '\n') c= getc(wf);
-    if (c != '\n') return 0;
-
-    *ppage= page;
-    *psection= section;
-    return 1;
-}
-
-char ALL[]= "";		/* Magic sequence of all sections. */
-
-int all= 0;		/* Show all pages with a given title. */
-int whatis= 0;		/* man -f word == whatis word. */
-int apropos= 0;		/* man -k word == apropos word. */
-int quiet= 0;		/* man -q == quietly check. */
-enum ROFF { NROFF, TROFF } rofftype= NROFF;
-char *roff[] = { "nroff", "troff" };
-
-int shown;		/* True if something has been shown. */
-int tty;		/* True if displaying on a terminal. */
-char *manpath;		/* The manual directory path. */
-char *pager;		/* The pager to use. */
-
-char *pipeline[8][8];	/* An 8 command pipeline of 7 arguments each. */
-char *(*plast)[8] = pipeline;
-
-void putinline(char *arg1, ...)
-/* Add a command to the pipeline. */
-{
-    va_list ap;
-    char **argv;
-
-    argv= *plast++;
-    *argv++= arg1;
-
-    va_start(ap, arg1);
-    while ((*argv++= va_arg(ap, char *)) != nil) {}
-    va_end(ap);
-}
-
-void execute(int set_mp, char *file)
-/* Execute the pipeline build with putinline().  (This is a lot of work to
- * avoid a call to system(), but it so much fun to do it right!)
- */
-{
-    char *(*plp)[8], **argv;
-    char *mp;
-    int fd0, pfd[2], err[2];
-    pid_t pid;
-    int r, status;
-    int last;
-    void (*isav)(int sig), (*qsav)(int sig), (*tsav)(int sig);
-
-    if (tty) {
-	/* Must run this through a pager. */
-	putinline(pager, (char *) nil);
-    }
-    if (plast == pipeline) {
-	/* No commands at all? */
-	putinline("cat", (char *) nil);
-    }
-
-    /* Add the file as argument to the first command. */
-    argv= pipeline[0];
-    while (*argv != nil) argv++;
-    *argv++= file;
-    *argv= nil;
-
-    /* Start the commands. */
-    fd0= 0;
-    for (plp= pipeline; plp < plast; plp++) {
-	argv= *plp;
-	last= (plp+1 == plast);
-
-	/* Create an error pipe and pipe between this command and the next. */
-	if (pipe(err) < 0 || (!last && pipe(pfd) < 0)) {
-	    fprintf(stderr, "man: can't create a pipe: %s\n", strerror(errno));
-	    exit(1);
-	}
-
-	(void) fcntl(err[1], F_SETFD, fcntl(err[1], F_GETFD) | FD_CLOEXEC);
-
-	if ((pid = fork()) < 0) {
-	    fprintf(stderr, "man: cannot fork: %s\n", strerror(errno));
-	    exit(1);
-	}
-	if (pid == 0) {
-	    /* Child. */
-	    if (set_mp) {
-		mp= malloc((8 + strlen(manpath) + 1) * sizeof(*mp));
-		if (mp != nil) {
-		    strcpy(mp, "MANPATH=");
-		    strcat(mp, manpath);
-		    (void) putenv(mp);
-		}
-	    }
-
-	    if (fd0 != 0) {
-		dup2(fd0, 0);
-		close(fd0);
-	    }
-	    if (!last) {
-		close(pfd[0]);
-		if (pfd[1] != 1) {
-		    dup2(pfd[1], 1);
-		    close(pfd[1]);
-		}
-	    }
-	    close(err[0]);
-	    execvp(argv[0], argv);
-	    (void) write(err[1], &errno, sizeof(errno));
-	    _exit(1);
-	}
-
-	close(err[1]);
-	if (read(err[0], &errno, sizeof(errno)) != 0) {
-	    fprintf(stderr, "man: %s: %s\n", argv[0],
-			    strerror(errno));
-	    exit(1);
-	}
-	close(err[0]);
-
-	if (!last) {
-	    close(pfd[1]);
-	    fd0= pfd[0];
-	}
-	set_mp= 0;
-    }
-
-    /* Wait for the last command to finish. */
-    isav= signal(SIGINT, SIG_IGN);
-    qsav= signal(SIGQUIT, SIG_IGN);
-    tsav= signal(SIGTERM, SIG_IGN);
-    while ((r= wait(&status)) != pid) {
-	if (r < 0) {
-	    fprintf(stderr, "man: wait(): %s\n", strerror(errno));
-	    exit(1);
-	}
-    }
-    (void) signal(SIGINT, isav);
-    (void) signal(SIGQUIT, qsav);
-    (void) signal(SIGTERM, tsav);
-    if (status != 0) exit(1);
-    plast= pipeline;
-}
-
-void keyword(char *keyword)
-/* Make an apropos(1) or whatis(1) call. */
-{
-    putinline(apropos ? "apropos" : "whatis",
-		all ? "-a" : (char *) nil,
-		(char *) nil);
-
-    if (tty) {
-	printf("Looking for keyword '%s'\n", keyword);
-	fflush(stdout);
-    }
-
-    execute(1, keyword);
-}
-
-enum pagetype { CAT, CATZ, MAN, MANZ, SMAN, SMANZ };
-
-int showpage(char *page, enum pagetype ptype, char *macros)
-/* Show a manual page if it exists using the proper decompression and
- * formatting tools.
- */
-{
-    struct stat st;
-
-    /* We want a normal file without X bits if not a full path. */
-    if (stat(page, &st) < 0) return 0;
-
-    if (!S_ISREG(st.st_mode)) return 0;
-    if ((st.st_mode & 0111) && page[0] != '/') return 0;
-
-    /* Do we only care if it exists? */
-    if (quiet) { shown= 1; return 1; }
-
-    if (ptype == CATZ || ptype == MANZ || ptype == SMANZ) {
-	putinline("zcat", (char *) nil);
-    }
-
-    if (ptype == SMAN || ptype == SMANZ) {
-	/* Change SGML into regular *roff. */
-	putinline("/usr/lib/sgml/sgml2roff", (char *) nil);
-	putinline("tbl", (char *) nil);
-	putinline("eqn", (char *) nil);
-    }
-
-    if (ptype == MAN) {
-	/* Do we need tbl? */
-	FILE *fp;
-	int c;
-	char *tp = TBL_MAGIC;
-
-	if ((fp = fopen(page, "r")) == nil) {
-	    fprintf(stderr, "man: %s: %s\n", page, strerror(errno));
-	    exit(1);
-	}
-	c= fgetc(fp);
-	for (;;) {
-	    if (c == *tp || (c == '\'' && *tp == '.')) {
-		if (*++tp == 0) {
-		    /* A match, add tbl. */
-		    putinline("tbl", (char *) nil);
-		    break;
-		}
-	    } else {
-		/* No match. */
-		break;
-	    }
-	    while ((c = fgetc(fp)) == ' ' || c == '\t') {}
-	}
-	fclose(fp);
-    }
-
-    if (ptype == MAN || ptype == MANZ || ptype == SMAN || ptype == SMANZ) {
-	putinline(roff[rofftype], macros, (char *) nil);
-    }
-
-    if (tty) {
-	printf("%s %s\n",
-	    ptype == CAT || ptype == CATZ ? "Showing" : "Formatting", page);
-	fflush(stdout);
-    }
-    execute(0, page);
-
-    shown= 1;
-    return 1;
-}
-
-int member(char *word, char *list)
-/* True if word is a member of a comma separated list. */
-{
-    size_t len= strlen(word);
-
-    if (list == ALL) return 1;
-
-    while (*list != 0) {
-	if (strncmp(word, list, len) == 0
-		&& (list[len] == 0 || list[len] == ','))
-	    return 1;
-	while (*list != 0 && *list != ',') list++;
-	if (*list == ',') list++;
-    }
-    return 0;
-}
-
-int trymandir(char *mandir, char *title, char *section)
-/* Search the whatis file of the manual directory for a page of the given
- * section and display it.
- */
-{
-    FILE *wf;
-    char whatis[1024], pagename[1024], *wpage, *wsection;
-    int rsw, rsp;
-    int ntries;
-    int (*searchidx)(FILE *, char *, char **, char **);
-    struct searchnames {
-	enum pagetype	ptype;
-	char		*pathfmt;
-    } *sp;
-    static struct searchnames searchN[] = {
-	{ CAT,	"%s/cat%s/%s.%s"	},	/* SysV */
-	{ CATZ,	"%s/cat%s/%s.%s.Z"	},
-	{ MAN,	"%s/man%s/%s.%s"	},
-	{ MANZ,	"%s/man%s/%s.%s.Z"	},
-	{ SMAN,	"%s/sman%s/%s.%s"	},	/* Solaris */
-	{ SMANZ,"%s/sman%s/%s.%s.Z"	},
-	{ CAT,	"%s/cat%.1s/%s.%s"	},	/* BSD */
-	{ CATZ,	"%s/cat%.1s/%s.%s.Z"	},
-	{ MAN,	"%s/man%.1s/%s.%s"	},
-	{ MANZ,	"%s/man%.1s/%s.%s.Z"	},
-    };
-
-    if (strlen(mandir) + 1 + 6 + 1 > arraysize(whatis)) return 0;
-
-    /* Prefer a fast windex database if available. */
-    sprintf(whatis, "%s/windex", mandir);
-
-    if ((wf= fopen(whatis, "r")) != nil) {
-	searchidx= searchwindex;
-    } else {
-	/* Use a classic whatis database. */
-	sprintf(whatis, "%s/whatis", mandir);
-
-	if ((wf= fopen(whatis, "r")) == nil) return 0;
-	searchidx= searchwhatis;
-    }
-
-    rsp= 0;
-    while (!rsp && (rsw= (*searchidx)(wf, title, &wpage, &wsection)) == 1) {
-	if (!member(wsection, section)) continue;
-
-	/* When looking for getc(1S) we try:
-	 *	cat1s/getc.1s
-	 *	cat1s/getc.1s.Z
-	 *	man1s/getc.1s
-	 *	man1s/getc.1s.Z
-	 *	sman1s/getc.1s
-	 *	sman1s/getc.1s.Z
-	 *	cat1/getc.1s
-	 *	cat1/getc.1s.Z
-	 *	man1/getc.1s
-	 *	man1/getc.1s.Z
-	 */
-
-	if (strlen(mandir) + 2 * strlen(wsection) + strlen(wpage)
-		    + 10 > arraysize(pagename))
-	    continue;
-
-	sp= searchN;
-	ntries= arraysize(searchN);
-	do {
-	    if (sp->ptype <= CATZ && rofftype != NROFF)
-		continue;
-
-	    sprintf(pagename, sp->pathfmt,
-		mandir, wsection, wpage, wsection);
-
-	    rsp= showpage(pagename, sp->ptype,
-		(SEC9SPECIAL && strcmp(wsection, "9") == 0) ? "-mnx" : "-man");
-	} while (sp++, !rsp && --ntries != 0);
-
-	if (all) rsp= 0;
-    }
-    if (rsw < 0 && ferror(wf)) {
-	fprintf(stderr, "man: %s: %s\n", whatis, strerror(errno));
-	exit(1);
-    }
-    fclose(wf);
-    return rsp;
-}
-
-int trysubmandir(char *mandir, char *title, char *section)
-/* Search the subdirectories of this manual directory for whatis files, they
- * may have manual pages that override the ones in the major directory.
- */
-{
-    char submandir[1024];
-    DIR *md;
-    struct dirent *entry;
-
-    if ((md= opendir(mandir)) == nil) return 0;
-
-    while ((entry= readdir(md)) != nil) {
-	if (strcmp(entry->d_name, ".") == 0
-	    || strcmp(entry->d_name, "..") == 0) continue;
-	if ((strncmp(entry->d_name, "man", 3) == 0
-	    || strncmp(entry->d_name, "cat", 3) == 0)
-	    && between('0', entry->d_name[3], '9')) continue;
-
-	if (strlen(mandir) + 1 + strlen(entry->d_name) + 1
-		    > arraysize(submandir)) continue;
-
-	sprintf(submandir, "%s/%s", mandir, entry->d_name);
-
-	if (trymandir(submandir, title, section) && !all) {
-	    closedir(md);
-	    return 1;
-	}
-    }
-    closedir(md);
-
-    return 0;
-}
-
-void searchmanpath(char *title, char *section)
-/* Search the manual path for a manual page describing "title." */
-{
-    char mandir[1024];
-    char *pp= manpath, *pd;
-
-    for (;;) {
-	while (*pp != 0 && *pp == ':') pp++;
-
-	if (*pp == 0) break;
-
-	pd= mandir;
-	while (*pp != 0 && *pp != ':') {
-	    if (pd < arraylimit(mandir)) *pd++= *pp;
-	    pp++;
-	}
-	if (pd == arraylimit(mandir)) continue;		/* forget it */
-
-	*pd= 0;
-	if (trysubmandir(mandir, title, section) && !all) break;
-	if (trymandir(mandir, title, section) && !all) break;
-    }
-}
-
-void usage(void)
-{
-    fprintf(stderr, "Usage: man -[antfkq] [-M path] [-s section] title ...\n");
-    exit(1);
-}
-
-int main(int argc, char **argv)
-{
-    char *title, *section= ALL;
-    int i;
-    int nomoreopt= 0;
-    char *opt;
-
-    if ((pager= getenv("PAGER")) == nil) pager= PAGER;
-    if ((manpath= getenv("MANPATH")) == nil) manpath= MANPATH;
-    tty= isatty(1);
-
-    i= 1;
-    do {
-	while (i < argc && argv[i][0] == '-' && !nomoreopt) {
-	    opt= argv[i++]+1;
-	    if (opt[0] == '-' && opt[1] == 0) {
-		nomoreopt= 1;
-		break;
-	    }
-	    while (*opt != 0) {
-		switch (*opt++) {
-		case 'a':
-		    all= 1;
-		    break;
-		case 'f':
-		    whatis= 1;
-		    break;
-		case 'k':
-		    apropos= 1;
-		    break;
-		case 'q':
-		    quiet= 1;
-		    break;
-		case 'n':
-		    rofftype= NROFF;
-		    apropos= whatis= 0;
-		    break;
-		case 't':
-		    rofftype= TROFF;
-		    apropos= whatis= 0;
-		    break;
-		case 's':
-		    if (*opt == 0) {
-			if (i == argc) usage();
-			section= argv[i++];
-		    } else {
-			section= opt;
-			opt= "";
-		    }
-		    break;
-		case 'M':
-		    if (*opt == 0) {
-			if (i == argc) usage();
-			manpath= argv[i++];
-		    } else {
-			manpath= opt;
-			opt= "";
-		    }
-		    break;
-		default:
-		    usage();
-		}
-	    }
-	}
-
-	if (i >= argc) usage();
-
-	if (between('0', argv[i][0], '9') && argv[i][1] == 0) {
-	    /* Allow single digit section designations. */
-	    section= argv[i++];
-	}
-	if (i == argc) usage();
-
-	title= argv[i++];
-
-	if (whatis || apropos) {
-	    keyword(title);
-	} else {
-	    shown= 0;
-	    searchmanpath(title, section);
-
-	    if (!shown) (void) showpage(title, MAN, "-man");
-
-	    if (!shown) {
-		if (!quiet) {
-		    fprintf(stderr,
-			"man: no manual on %s\n",
-			title);
-		}
-		exit(1);
-	    }
-	}
-    } while (i < argc);
-
-    return 0;
-}
Index: trunk/minix/commands/simple/mesg.c
===================================================================
--- trunk/minix/commands/simple/mesg.c	(revision 9)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/* mesg - enable or disable communications. Author: John J. Ribera */
-
-/*
- * mesg -	enable or disable communications.
- *
- * Usage:	mesg [ y | n ]
- *
- *		'mesg n' will turn off group and world permissions of the
- *			 user's terminal.
- *		'mesg y' will enable group and world to write to the user's
- *			 tty.
- *		mesg	 with no parameters will put the writeable status
- *			 onto stdout.
- *
- * Author:	John J. Ribera, Jr. 09/09/90
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-_PROTOTYPE( int main, (int argc, char *argv []) );
-
-int main(argc, argv)
-int  argc;
-char *argv[];
-{
-  struct stat statb;
-  char *tty_name;
-
-  if ((tty_name = ttyname(0)) == NULL) exit(2);
-  if (stat(tty_name, &statb) == -1) exit(2);
-  if (--argc) {
-	if (*argv[1] == 'n') statb.st_mode = 0600;
-	  else if (*argv[1] == 'y') statb.st_mode = 0620;
-	  else {
-		fprintf(stderr, "mesg: usage: mesg [n|y]\n");
-		exit(2);
-	}
-	if (chmod(tty_name, statb.st_mode) == -1) exit(2);
-  } else printf((statb.st_mode & 020) ? "is y\n" : "is n\n");
-
-  if (statb.st_mode & 020) exit(0);
-
-  exit(1);
-}
-
Index: trunk/minix/commands/simple/mkdir.c
===================================================================
--- trunk/minix/commands/simple/mkdir.c	(revision 9)
+++ 	(revision )
@@ -1,265 +1,0 @@
-/* mkdir - Make directories		Author: V. Archer */
-
-/* Copyright 1991 by Vincent Archer
- *	You may freely redistribute this software, in source or binary
- *	form, provided that you do not alter this copyright mention in any
- *	way.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <minix/minlib.h>
-#include <limits.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-
-extern int optind, opterr;
-extern char *optarg;
-
-#define USR_MODES (S_ISUID|S_IRWXU)
-#define GRP_MODES (S_ISGID|S_IRWXG)
-#define EXE_MODES (S_IXUSR|S_IXGRP|S_IXOTH)
-#ifdef S_ISVTX
-#define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO|S_ISVTX)
-#else
-#define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO)
-#endif
-#define DEFAULT_MODE (S_IRWXU|S_IRWXG|S_IRWXO)
-#define USER_WX (S_IWUSR|S_IXUSR)
-
-
-/* Global variables */
-int pflag;
-char *symbolic;
-mode_t u_mask;
-struct stat st;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(mode_t parsemode, (char *symbolic, mode_t oldmode));
-_PROTOTYPE(int makepath, (char *fordir));
-_PROTOTYPE(int makedir, (char *dirname));
-_PROTOTYPE(void usage, (void));
-
-/* Parse a P1003.2 4.7.7-conformant symbolic mode. */
-mode_t parsemode(char *symbolic, mode_t oldmode)
-{
-  mode_t who, mask, newmode, tmpmask;
-  char action;
-  char *end;
-  unsigned long octalmode;
-
-  octalmode = strtoul(symbolic, &end, 010);
-  if (octalmode < ALL_MODES && *end == 0 && end != symbolic) return octalmode;
-
-  newmode = oldmode & ALL_MODES;
-  while (*symbolic) {
-	who = 0;
-	for (; *symbolic; symbolic++) {
-		if (*symbolic == 'a') {
-			who |= ALL_MODES;
-			continue;
-		}
-		if (*symbolic == 'u') {
-			who |= USR_MODES;
-			continue;
-		}
-		if (*symbolic == 'g') {
-			who |= GRP_MODES;
-			continue;
-		}
-		if (*symbolic == 'o') {
-			who |= S_IRWXO;
-			continue;
-		}
-		break;
-	}
-	if (!*symbolic || *symbolic == ',') usage();
-	while (*symbolic) {
-		if (*symbolic == ',') break;
-		switch (*symbolic) {
-		    default:
-			usage();
-		    case '+':
-		    case '-':
-		    case '=':	action = *symbolic++;
-		}
-		mask = 0;
-		for (; *symbolic; symbolic++) {
-			if (*symbolic == 'u') {
-				tmpmask = newmode & S_IRWXU;
-				mask |= tmpmask | (tmpmask << 3) | (tmpmask << 6);
-				symbolic++;
-				break;
-			}
-			if (*symbolic == 'g') {
-				tmpmask = newmode & S_IRWXG;
-				mask |= tmpmask | (tmpmask >> 3) | (tmpmask << 3);
-				symbolic++;
-				break;
-			}
-			if (*symbolic == 'o') {
-				tmpmask = newmode & S_IRWXO;
-				mask |= tmpmask | (tmpmask >> 3) | (tmpmask >> 6);
-				symbolic++;
-				break;
-			}
-			if (*symbolic == 'r') {
-				mask |= S_IRUSR | S_IRGRP | S_IROTH;
-				continue;
-			}
-			if (*symbolic == 'w') {
-				mask |= S_IWUSR | S_IWGRP | S_IWOTH;
-				continue;
-			}
-			if (*symbolic == 'x') {
-				mask |= EXE_MODES;
-				continue;
-			}
-			if (*symbolic == 's') {
-				mask |= S_ISUID | S_ISGID;
-				continue;
-			}
-			if (*symbolic == 'X') {
-				if (S_ISDIR(oldmode) || (oldmode & EXE_MODES))
-					mask |= EXE_MODES;
-				continue;
-			}
-#ifdef S_ISVTX
-			if (*symbolic == 't') {
-				mask |= S_ISVTX;
-				who |= S_ISVTX;
-				continue;
-			}
-#endif
-			break;
-		}
-		switch (action) {
-		    case '=':
-			if (who)
-				newmode &= ~who;
-			else
-				newmode = 0;
-		    case '+':
-			if (who)
-				newmode |= who & mask;
-			else
-				newmode |= mask & (~u_mask);
-			break;
-		    case '-':
-			if (who)
-				newmode &= ~(who & mask);
-			else
-				newmode &= ~mask | u_mask;
-		}
-	}
-	if (*symbolic) symbolic++;
-  }
-  return(newmode);
-}
-
-
-/* Main module. */
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  int error, c;
-
-  opterr = 0;
-  pflag = 0;
-  symbolic = (char *) 0;
-  u_mask = umask(0);
-  umask(u_mask);
-  while ((c = getopt(argc, argv, "m:p")) != EOF) switch (c) {
-	    case 'm':	symbolic = optarg;	break;
-	    case 'p':	pflag = 1;	break;
-	    default:	usage();
-	}
-  if (optind >= argc) usage();
-
-  error = 0;
-  while (optind < argc) error |= makedir(argv[optind++]);
-  return(error);
-}
-
-
-/* P1003.2 requires that missing intermediate pathname components should be
- *	created if the -p option is specified (4.40.3).
- */
-int makepath(fordir)
-char *fordir;
-{
-  char parent[PATH_MAX + 1], *end, *last;
-
-  strcpy(parent, fordir);
-  do {
-	  if (!(end = strrchr(parent, '/'))) return(0);
-	  *end = '\0';
-	  if (!parent[0] || !strcmp(parent, ".")) return(0);
-  } while((last = strrchr(parent, '/')) && !strcmp(last+1, "."));
-
-  if (!stat(parent, &st)) {
-	if (S_ISDIR(st.st_mode)) return(0);
-	errno = ENOTDIR;
-	perror(parent);
-	return(1);
-  }
-  if (mkdir(parent, DEFAULT_MODE)) {
-	if (makepath(parent)) return(1);
-	if (mkdir(parent, DEFAULT_MODE)) {
-		perror(parent);
-		return(1);
-	}
-  }
-
-/* P1003.2 states that, regardless of umask() value, intermediate paths
- *	should have at least write and search (x) permissions (4.40.10).
- */
-  if ((u_mask & USER_WX) &&
-      chmod(parent, ((~u_mask) | USER_WX)) & DEFAULT_MODE) {
-	perror(parent);
-	return(1);
-  }
-  return(0);
-}
-
-
-/* Actual directory creation, using a mkdir() system call. */
-int makedir(dirname)
-char *dirname;
-{
-  if (mkdir(dirname, DEFAULT_MODE)) {
-	if (!pflag) {
-		perror(dirname);
-		return(1);
-	}
-	if (!stat(dirname, &st)) {
-		if (S_ISDIR(st.st_mode)) return(0);
-		errno = ENOTDIR;
-		perror(dirname);
-		return(1);
-	}
-	if (makepath(dirname)) return(1);
-	if (mkdir(dirname, DEFAULT_MODE)) {
-		perror(dirname);
-		return(1);
-	}
-  }
-  if (symbolic && (stat(dirname, &st) ||
-		 chmod(dirname, parsemode(symbolic, st.st_mode)))) {
-	perror(dirname);
-	return(1);
-  }
-  return(0);
-}
-
-
-/* Posix command prototype. */
-void usage()
-{
-  std_err("Usage: mkdir [-p] [-m mode] dir...\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/mkfifo.c
===================================================================
--- trunk/minix/commands/simple/mkfifo.c	(revision 9)
+++ 	(revision )
@@ -1,194 +1,0 @@
-/* mkfifo - Make FIFO special files		Author: V. Archer */
-
-/* Copyright 1991 by Vincent Archer
- *	You may freely redistribute this software, in source or binary
- *	form, provided that you do not alter this copyright mention in any
- *	way.
- */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <unistd.h>
-#include <minix/minlib.h>
-#include <stdio.h>
-
-#define USR_MODES (S_ISUID|S_IRWXU)
-#define GRP_MODES (S_ISGID|S_IRWXG)
-#define EXE_MODES (S_IXUSR|S_IXGRP|S_IXOTH)
-#ifdef S_ISVTX
-#define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO|S_ISVTX)
-#else
-#define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO)
-#endif
-#define DEFAULT_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
-
-
-/* Global u_mask needed in changemode.h */
-mode_t u_mask;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(mode_t parsemode, (char *symbolic, mode_t oldmode));
-_PROTOTYPE(void usage, (void));
-
-/* Parse a P1003.2 4.7.7-conformant symbolic mode. */
-mode_t parsemode(char *symbolic, mode_t oldmode)
-{
-  mode_t who, mask, newmode, tmpmask;
-  char action;
-
-  newmode = oldmode & ALL_MODES;
-  while (*symbolic) {
-	who = 0;
-	for (; *symbolic; symbolic++) {
-		if (*symbolic == 'a') {
-			who |= ALL_MODES;
-			continue;
-		}
-		if (*symbolic == 'u') {
-			who |= USR_MODES;
-			continue;
-		}
-		if (*symbolic == 'g') {
-			who |= GRP_MODES;
-			continue;
-		}
-		if (*symbolic == 'o') {
-			who |= S_IRWXO;
-			continue;
-		}
-		break;
-	}
-	if (!*symbolic || *symbolic == ',') usage();
-	while (*symbolic) {
-		if (*symbolic == ',') break;
-		switch (*symbolic) {
-		    default:
-			usage();
-		    case '+':
-		    case '-':
-		    case '=':	action = *symbolic++;
-		}
-		mask = 0;
-		for (; *symbolic; symbolic++) {
-			if (*symbolic == 'u') {
-				tmpmask = newmode & S_IRWXU;
-				mask |= tmpmask | (tmpmask << 3) | (tmpmask << 6);
-				symbolic++;
-				break;
-			}
-			if (*symbolic == 'g') {
-				tmpmask = newmode & S_IRWXG;
-				mask |= tmpmask | (tmpmask >> 3) | (tmpmask << 3);
-				symbolic++;
-				break;
-			}
-			if (*symbolic == 'o') {
-				tmpmask = newmode & S_IRWXO;
-				mask |= tmpmask | (tmpmask >> 3) | (tmpmask >> 6);
-				symbolic++;
-				break;
-			}
-			if (*symbolic == 'r') {
-				mask |= S_IRUSR | S_IRGRP | S_IROTH;
-				continue;
-			}
-			if (*symbolic == 'w') {
-				mask |= S_IWUSR | S_IWGRP | S_IWOTH;
-				continue;
-			}
-			if (*symbolic == 'x') {
-				mask |= EXE_MODES;
-				continue;
-			}
-			if (*symbolic == 's') {
-				mask |= S_ISUID | S_ISGID;
-				continue;
-			}
-			if (*symbolic == 'X') {
-				if (S_ISDIR(oldmode) || (oldmode & EXE_MODES))
-					mask |= EXE_MODES;
-				continue;
-			}
-#ifdef S_ISVTX
-			if (*symbolic == 't') {
-				mask |= S_ISVTX;
-				who |= S_ISVTX;
-				continue;
-			}
-#endif
-			break;
-		}
-		switch (action) {
-		    case '=':
-			if (who)
-				newmode &= ~who;
-			else
-				newmode = 0;
-		    case '+':
-			if (who)
-				newmode |= who & mask;
-			else
-				newmode |= mask & (~u_mask);
-			break;
-		    case '-':
-			if (who)
-				newmode &= ~(who & mask);
-			else
-				newmode &= ~mask | u_mask;
-		}
-	}
-	if (*symbolic) symbolic++;
-  }
-  return(newmode);
-}
-
-
-/* Main module. Since only one option (-m mode) is allowed, there's no need
- * to include the whole getopt() stuff.
- */
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int errors = 0;
-  char *symbolic;
-
-  if (argc > 2 && *argv[1] == '-' && strcmp(argv[1], "-m") != 0) usage();
-  argc--;
-  argv++;
-  if (argc && strncmp(*argv, "-m", (size_t) 2) == 0) {
-	argc--;
-	if ((argv[0])[2])
-		symbolic = (*argv++) + 2;
-	else {
-		if (!argc--) usage();
-		argv++;
-		symbolic = *argv++;
-	}
-	u_mask = umask(0);
-	umask(u_mask);
-  } else
-	symbolic = (char *) 0;
-
-  if (!argc) usage();
-  for (; argc--; argv++)
-	if (mkfifo(*argv, DEFAULT_MODE)) {
-		perror(*argv);
-		errors = 1;
-	} else if (symbolic && chmod(*argv, parsemode(symbolic, DEFAULT_MODE))) {
-		unlink(*argv);
-		perror(*argv);
-		errors = 1;
-	}
-  return(errors);
-}
-
-
-/* Posix command prototype. */
-void usage()
-{
-  std_err("Usage: mkfifo [-m mode] file...\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/mkfs.c
===================================================================
--- trunk/minix/commands/simple/mkfs.c	(revision 9)
+++ 	(revision )
@@ -1,1593 +1,0 @@
-/* mkfs  -  make the MINIX filesystem	Authors: Tanenbaum et al. */
-
-/*	Authors: Andy Tanenbaum, Paul Ogilvie, Frans Meulenbroeks, Bruce Evans
- *
- * This program can make both version 1 and version 2 file systems, as follows:
- *	mkfs /dev/fd0 1200	# Version 2 (default)
- *	mkfs -1 /dev/fd0 360	# Version 1
- *
- */
-
-#include <sys/types.h>
-#include <sys/dir.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include <minix/minlib.h>
-#include "../../servers/fs/const.h"
-#if (MACHINE == IBM_PC)
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <sys/ioctl.h>
-#endif
-#include <a.out.h>
-#include <tools.h>
-#include <dirent.h>
-
-#undef EXTERN
-#define EXTERN			/* get rid of EXTERN by making it null */
-#include "../../servers/fs/type.h"
-#include "../../servers/fs/super.h"
-#include <minix/fslib.h>
-
-#ifndef max
-#define max(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-#ifndef DOS
-#ifndef UNIX
-#define UNIX
-#endif
-#endif
-
-#define INODE_MAP            2
-#define MAX_TOKENS          10
-#define LINE_LEN           200
-#define BIN                  2
-#define BINGRP               2
-#define BIT_MAP_SHIFT       13
-#define N_BLOCKS         MAX_BLOCK_NR
-#define N_BLOCKS16	  (128L * 1024)
-#define INODE_MAX       ((unsigned) 65535)
-
-/* You can make a really large file system on a 16-bit system, but the array
- * of bits that get_block()/putblock() needs gets a bit big, so we can only
- * prefill MAX_INIT blocks.  (16-bit fsck can't check a file system larger
- * than N_BLOCKS16 anyway.)
- */
-#define MAX_INIT	 (sizeof(char *) == 2 ? N_BLOCKS16 : N_BLOCKS)
-
-
-#ifdef DOS
-maybedefine O_RDONLY 4		/* O_RDONLY | BINARY_BIT */
- maybedefine BWRITE 5		/* O_WRONLY | BINARY_BIT */
-#endif
-
-#if (MACHINE == ATARI)
-int isdev;
-#endif
-
-extern char *optarg;
-extern int optind;
-
-int next_zone, next_inode, zone_size, zone_shift = 0, zoff;
-block_t nrblocks;
-int inode_offset, lct = 0, disk, fd, print = 0, file = 0;
-unsigned int nrinodes;
-int override = 0, simple = 0, dflag;
-int donttest;			/* skip test if it fits on medium */
-char *progname;
-
-long current_time, bin_time;
-char *zero, *lastp;
-char umap[MAX_INIT / 8];	/* bit map tells if block read yet */
-block_t zone_map;		/* where is zone map? (depends on # inodes) */
-int inodes_per_block;
-int fs_version;
-unsigned int block_size;
-block_t max_nrblocks;
-
-FILE *proto;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(block_t sizeup, (char *device));
-_PROTOTYPE(void super, (zone_t zones, Ino_t inodes));
-_PROTOTYPE(void rootdir, (Ino_t inode));
-_PROTOTYPE(void eat_dir, (Ino_t parent));
-_PROTOTYPE(void eat_file, (Ino_t inode, int f));
-_PROTOTYPE(void enter_dir, (Ino_t parent, char *name, Ino_t child));
-_PROTOTYPE(void incr_size, (Ino_t n, long count));
-_PROTOTYPE(PRIVATE ino_t alloc_inode, (int mode, int usrid, int grpid));
-_PROTOTYPE(PRIVATE zone_t alloc_zone, (void));
-_PROTOTYPE(void add_zone, (Ino_t n, zone_t z, long bytes, long cur_time));
-_PROTOTYPE(void add_z_1, (Ino_t n, zone_t z, long bytes, long cur_time));
-_PROTOTYPE(void add_z_2, (Ino_t n, zone_t z, long bytes, long cur_time));
-_PROTOTYPE(void incr_link, (Ino_t n));
-_PROTOTYPE(void insert_bit, (block_t block, int bit));
-_PROTOTYPE(int mode_con, (char *p));
-_PROTOTYPE(void getline, (char line[LINE_LEN], char *parse[MAX_TOKENS]));
-_PROTOTYPE(void check_mtab, (char *devname));
-_PROTOTYPE(long file_time, (int f));
-_PROTOTYPE(void pexit, (char *s));
-_PROTOTYPE(void copy, (char *from, char *to, int count));
-_PROTOTYPE(void print_fs, (void));
-_PROTOTYPE(int read_and_set, (block_t n));
-_PROTOTYPE(void special, (char *string));
-_PROTOTYPE(void get_block, (block_t n, char *buf));
-_PROTOTYPE(void get_super_block, (char *buf));
-_PROTOTYPE(void put_block, (block_t n, char *buf));
-_PROTOTYPE(void cache_init, (void));
-_PROTOTYPE(void flush, (void));
-_PROTOTYPE(void mx_read, (int blocknr, char *buf));
-_PROTOTYPE(void mx_write, (int blocknr, char *buf));
-_PROTOTYPE(void dexit, (char *s, int sectnum, int err));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(char *alloc_block, (void));
-
-/*================================================================
- *                    mkfs  -  make filesystem
- *===============================================================*/
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int nread, mode, usrid, grpid, ch;
-  block_t blocks, maxblocks;
-  block_t i;
-  ino_t root_inum;
-  ino_t inodes;
-  zone_t zones;
-  char *token[MAX_TOKENS], line[LINE_LEN];
-  struct stat statbuf;
-
-  /* Get two times, the current time and the mod time of the binary of
-   * mkfs itself.  When the -d flag is used, the later time is put into
-   * the i_mtimes of all the files.  This feature is useful when
-   * producing a set of file systems, and one wants all the times to be
-   * identical. First you set the time of the mkfs binary to what you
-   * want, then go.
-   */
-  current_time = time((time_t *) 0);	/* time mkfs is being run */
-  stat(argv[0], &statbuf);
-  bin_time = statbuf.st_mtime;	/* time when mkfs binary was last modified */
-
-  /* Process switches. */
-  progname = argv[0];
-  blocks = 0;
-  i = 0;
-  fs_version = 3;
-  inodes_per_block = 0;
-  max_nrblocks = N_BLOCKS;
-  block_size = 0;
-  while ((ch = getopt(argc, argv, "12b:di:lotB:")) != EOF)
-	switch (ch) {
-	    case '1':
-		fs_version = 1;
-		inodes_per_block = V1_INODES_PER_BLOCK;
-		max_nrblocks = 0xFFFF;
-		break;
-	    case '2':
-	    	fs_version = 2;
-	    	break;
-	    case 'b':
-		blocks = strtoul(optarg, (char **) NULL, 0);
-		break;
-	    case 'd':
-		dflag = 1;
-		current_time = bin_time;
-		break;
-	    case 'i':
-		i = strtoul(optarg, (char **) NULL, 0);
-		break;
-	    case 'l':	print = 1;	break;
-	    case 'o':	override = 1;	break;
-	    case 't':	donttest = 1;	break;
-	    case 'B':	block_size = atoi(optarg);	break;
-	    default:	usage();
-	}
-
-  if(fs_version == 3) {
-  	if(!block_size) block_size = _MAX_BLOCK_SIZE; /* V3 default block size */
-  	if(block_size%SECTOR_SIZE || block_size < _MIN_BLOCK_SIZE) {
-  		fprintf(stderr, "block size must be multiple of sector (%d) "
-  			"and at least %d bytes\n",
-  			SECTOR_SIZE, _MIN_BLOCK_SIZE);
-  		pexit("specified block size illegal");
-  	}
-  	if(block_size%V2_INODE_SIZE) {
-  		fprintf(stderr, "block size must be a multiple of inode size (%d bytes)\n",
-  			V2_INODE_SIZE);
-  		pexit("specified block size illegal");
-  	}
-  } else {
-  	if(block_size) {
-	  	pexit("Can't specify a block size if FS version is <3");
-  	}
- 	block_size = _STATIC_BLOCK_SIZE;	/* V1/V2 block size */
-  }
-
-  if(!inodes_per_block)
-  	inodes_per_block = V2_INODES_PER_BLOCK(block_size);
-
-  /* now that the block size is known, do buffer allocations where
-   * possible.
-   */
-  zero = alloc_block();
-  bzero(zero, block_size);
-
-  /* Determine the size of the device if not specified as -b or proto. */
-  maxblocks = sizeup(argv[optind]);
-  if (argc - optind == 1 && blocks == 0) {
-  	blocks = maxblocks;
-  	/* blocks == 0 is checked later, but leads to a funny way of
-  	 * reporting a 0-sized device (displays usage).
-  	 */
-  	if(blocks < 1) {
-  		fprintf(stderr, "%s: this device can't hold a filesystem.\n",
-  			progname);
-  		return 1;
-  	}
-  }
-
-  /* The remaining args must be 'special proto', or just 'special' if the
-   * no. of blocks has already been specified.
-   */
-  if (argc - optind != 2 && (argc - optind != 1 || blocks == 0)) usage();
-
-  if (blocks > maxblocks) {
- 	fprintf(stderr, "%s: %s: number of blocks too large for device.\n",
-  		progname, argv[optind]);
-  	return 1;
-  }
-
-  /* Check special. */
-  check_mtab(argv[optind]);
-
-  /* Check and start processing proto. */
-  optarg = argv[++optind];
-  if (optind < argc && (proto = fopen(optarg, "r")) != NULL) {
-	/* Prototype file is readable. */
-	lct = 1;
-	getline(line, token);	/* skip boot block info */
-
-	/* Read the line with the block and inode counts. */
-	getline(line, token);
-	blocks = atol(token[0]);
-	if (blocks > max_nrblocks) pexit("Block count too large");
-	if (sizeof(char *) == 2 && blocks > N_BLOCKS16) {
-		fprintf(stderr,
-		"%s: warning: FS is larger than the %dM that fsck can check!\n",
-			progname, (int) (N_BLOCKS16 / (1024L * 1024)));
-	}
-	inodes = atoi(token[1]);
-
-	/* Process mode line for root directory. */
-	getline(line, token);
-	mode = mode_con(token[0]);
-	usrid = atoi(token[1]);
-	grpid = atoi(token[2]);
-  } else {
-	lct = 0;
-	if (optind < argc) {
-		/* Maybe the prototype file is just a size.  Check. */
-		blocks = strtoul(optarg, (char **) NULL, 0);
-		if (blocks == 0) pexit("Can't open prototype file");
-	}
-	if (i == 0) {
-		int kb;
-		kb = blocks * (max(block_size,1024) / 1024);
-		/* The default for inodes is 2 blocks per kb, rounded up
-		 * to fill an inode block.  Above 20M, the average files are
-		 * sure to be larger because it is hard to fill up 20M with
-		 * tiny files, so reduce the default number of inodes.  This
-		 * default can always be overridden by using the '-i option.
-		 */
-		i = kb / 2;
-		if (kb >= 20000) i = kb / 3;
-		if (kb >= 40000) i = kb / 4;
-		if (kb >= 60000) i = kb / 5;
-		if (kb >= 80000) i = kb / 6;
-		if (kb >= 100000) i = kb / 7;
-
-		/* round up to fill inode block */
-		i += inodes_per_block - 1;
-		i = i / inodes_per_block * inodes_per_block;
-		if (i > INODE_MAX && fs_version < 3) i = INODE_MAX;
-
-	}
-	if (blocks < 5) pexit("Block count too small");
-	if (blocks > max_nrblocks) pexit("Block count too large");
-	if (i < 1) pexit("Inode count too small");
-	if (i > INODE_MAX && fs_version < 3) pexit("Inode count too large");
-	inodes = (ino_t) i;
-
-	/* Make simple file system of the given size, using defaults. */
-	mode = 040777;
-	usrid = BIN;
-	grpid = BINGRP;
-	simple = 1;
-  }
-
-  if(ULONG_MAX / block_size <= blocks-1) {
-  	fprintf(stderr, "Warning: too big for filesystem to currently\n");
-  	fprintf(stderr, "run on (max 4GB), truncating.\n");
-  	blocks = ULONG_MAX / block_size;
-  }
-
-  nrblocks = blocks;
-  nrinodes = inodes;
-
-  /* Open special. */
-  special(argv[--optind]);
-
-#ifdef UNIX
-  if (!donttest) {
-	short *testb;
-	ssize_t w;
-
-	testb = (short *) alloc_block();
-
-	/* Try writing the last block of partition or diskette. */
-	if(lseek(fd, (off_t) (blocks - 1) * block_size, SEEK_SET) < 0) {
-		pexit("couldn't seek to last block to test size (1)");
-	}
-	testb[0] = 0x3245;
-	testb[1] = 0x11FF;
-	testb[block_size-1] = 0x1F2F;
-	if ((w=write(fd, (char *) testb, block_size)) != block_size) {
-		if(w < 0) perror("write");
-		printf("%d/%d\n", w, block_size);
-		pexit("File system is too big for minor device (write)");
-	}
-	sync();			/* flush write, so if error next read fails */
-	if(lseek(fd, (off_t) (blocks - 1) * block_size, SEEK_SET) < 0) {
-		pexit("couldn't seek to last block to test size (2)");
-	}
-	testb[0] = 0;
-	testb[1] = 0;
-	nread = read(fd, (char *) testb, block_size);
-	if (nread != block_size || testb[0] != 0x3245 || testb[1] != 0x11FF ||
-		testb[block_size-1] != 0x1F2F) {
-		if(nread < 0) perror("read");
-		pexit("File system is too big for minor device (read)");
-	}
-	lseek(fd, (off_t) (blocks - 1) * block_size, SEEK_SET);
-	testb[0] = 0;
-	testb[1] = 0;
-	if (write(fd, (char *) testb, block_size) != block_size)
-		pexit("File system is too big for minor device (write2)");
-	lseek(fd, 0L, SEEK_SET);
-	free(testb);
-  }
-#endif
-
-  /* Make the file-system */
-
-  cache_init();
-
-#if (MACHINE == ATARI)
-  if (isdev) {
-	char block0[BLOCK_SIZE];
-	get_block((block_t) 0, block0);
-	/* Need to read twice; first time gets an empty block */
-	get_block((block_t) 0, block0);
-	/* Zero parts of the boot block so the disk won't be
-	 * recognized as a tos disk any more. */
-	block0[0] = block0[1] = 0;	/* branch code to boot code    */
-	strncpy(&block0[2], "MINIX ", (size_t) 6);
-	block0[16] = 0;		/* number of FATS              */
-	block0[17] = block0[18] = 0;	/* number of dir entries       */
-	block0[22] = block0[23] = 0;	/* sectors/FAT                 */
-	bzero(&block0[30], 480);/* boot code                   */
-	put_block((block_t) 0, block0);
-  } else
-#endif
-
-	put_block((block_t) 0, zero);	/* Write a null boot block. */
-
-  zone_shift = 0;		/* for future use */
-  zones = nrblocks >> zone_shift;
-
-  super(zones, inodes);
-
-  root_inum = alloc_inode(mode, usrid, grpid);
-  rootdir(root_inum);
-  if (simple == 0) eat_dir(root_inum);
-
-  if (print) print_fs();
-  flush();
-  return(0);
-
-  /* NOTREACHED */
-}				/* end main */
-
-
-/*================================================================
- *                    sizeup  -  determine device size
- *===============================================================*/
-block_t sizeup(device)
-char *device;
-{
-  int fd;
-  struct partition entry;
-  block_t d;
-  struct stat st;
-
-  if ((fd = open(device, O_RDONLY)) == -1) {
-	if (errno != ENOENT)
-		perror("sizeup open");
-  	return 0;
-  }
-  if (ioctl(fd, DIOCGETP, &entry) == -1) {
-  	perror("sizeup ioctl");
-  	if(fstat(fd, &st) < 0) {
-  		perror("fstat");
-	  	entry.size = cvu64(0);
-  	} else {
-  		fprintf(stderr, "used fstat instead\n");
-	  	entry.size = cvu64(st.st_size);
-  	}
-  }
-  close(fd);
-  d = div64u(entry.size, block_size);
-  return d;
-}
-
-
-/*================================================================
- *                 super  -  construct a superblock
- *===============================================================*/
-
-void super(zones, inodes)
-zone_t zones;
-ino_t inodes;
-{
-  unsigned int i;
-  int inodeblks;
-  int initblks;
-
-  zone_t initzones, nrzones, v1sq, v2sq;
-  zone_t zo;
-  struct super_block *sup;
-  char *buf, *cp;
-
-  buf = alloc_block();
-
-  for (cp = buf; cp < &buf[block_size]; cp++) *cp = 0;
-  sup = (struct super_block *) buf;	/* lint - might use a union */
-
-  sup->s_ninodes = inodes;
-  if (fs_version == 1) {
-	sup->s_nzones = zones;
-  } else {
-	sup->s_nzones = 0;	/* not used in V2 - 0 forces errors early */
-	sup->s_zones = zones;
-  }
-  sup->s_imap_blocks = bitmapsize((bit_t) (1 + inodes), block_size);
-  sup->s_zmap_blocks = bitmapsize((bit_t) zones, block_size);
-  inode_offset = sup->s_imap_blocks + sup->s_zmap_blocks + 2;
-  inodeblks = (inodes + inodes_per_block - 1) / inodes_per_block;
-  initblks = inode_offset + inodeblks;
-  initzones = (initblks + (1 << zone_shift) - 1) >> zone_shift;
-  nrzones = nrblocks >> zone_shift;
-  sup->s_firstdatazone = (initblks + (1 << zone_shift) - 1) >> zone_shift;
-  zoff = sup->s_firstdatazone - 1;
-  sup->s_log_zone_size = zone_shift;
-  if (fs_version == 1) {
-	sup->s_magic = SUPER_MAGIC;	/* identify super blocks */
-	v1sq = (zone_t) V1_INDIRECTS * V1_INDIRECTS;
-	zo = V1_NR_DZONES + (long) V1_INDIRECTS + v1sq;
-  	sup->s_max_size = zo * block_size;
-  } else {
-	v2sq = (zone_t) V2_INDIRECTS(block_size) * V2_INDIRECTS(block_size);
-	zo = V2_NR_DZONES + (zone_t) V2_INDIRECTS(block_size) + v2sq;
-  	if(fs_version == 2) {
-		sup->s_magic = SUPER_V2;/* identify super blocks */
-  		sup->s_max_size = zo * block_size;
-	} else {
-		sup->s_magic = SUPER_V3;
-  		sup->s_block_size = block_size;
-  		sup->s_disk_version = 0;
-#define MAX_MAX_SIZE 	((unsigned long) 0xffffffff)
-  		if(MAX_MAX_SIZE/block_size < zo) {
-	  		sup->s_max_size = MAX_MAX_SIZE;
-  		}
-	  	else {
-	  		sup->s_max_size = zo * block_size;
-	  	}
-	}
-  }
-
-  zone_size = 1 << zone_shift;	/* nr of blocks per zone */
-
-  if (lseek(fd, (off_t) _STATIC_BLOCK_SIZE, SEEK_SET) == (off_t) -1) {
-	pexit("super() couldn't seek");
-  }
-  if (write(fd, buf, _STATIC_BLOCK_SIZE) != _STATIC_BLOCK_SIZE) {
-	pexit("super() couldn't write");
-  }
-
-  /* Clear maps and inodes. */
-  for (i = 2; i < initblks; i++) put_block((block_t) i, zero);
-
-  next_zone = sup->s_firstdatazone;
-  next_inode = 1;
-
-  zone_map = INODE_MAP + sup->s_imap_blocks;
-
-  insert_bit(zone_map, 0);	/* bit zero must always be allocated */
-  insert_bit((block_t) INODE_MAP, 0);	/* inode zero not used but
-					 * must be allocated */
-
-  free(buf);
-}
-
-
-/*================================================================
- *              rootdir  -  install the root directory
- *===============================================================*/
-void rootdir(inode)
-ino_t inode;
-{
-  zone_t z;
-
-  z = alloc_zone();
-  add_zone(inode, z, 2 * sizeof(struct direct), current_time);
-  enter_dir(inode, ".", inode);
-  enter_dir(inode, "..", inode);
-  incr_link(inode);
-  incr_link(inode);
-}
-
-
-/*================================================================
- *	    eat_dir  -  recursively install directory
- *===============================================================*/
-void eat_dir(parent)
-ino_t parent;
-{
-  /* Read prototype lines and set up directory. Recurse if need be. */
-  char *token[MAX_TOKENS], *p;
-  char line[LINE_LEN];
-  int mode, usrid, grpid, maj, min, f;
-  ino_t n;
-  zone_t z;
-  long size;
-
-  while (1) {
-	getline(line, token);
-	p = token[0];
-	if (*p == '$') return;
-	p = token[1];
-	mode = mode_con(p);
-	usrid = atoi(token[2]);
-	grpid = atoi(token[3]);
-	if (grpid & 0200) fprintf(stderr, "A.S.Tanenbaum\n");
-	n = alloc_inode(mode, usrid, grpid);
-
-	/* Enter name in directory and update directory's size. */
-	enter_dir(parent, token[0], n);
-	incr_size(parent, sizeof(struct direct));
-
-	/* Check to see if file is directory or special. */
-	incr_link(n);
-	if (*p == 'd') {
-		/* This is a directory. */
-		z = alloc_zone();	/* zone for new directory */
-		add_zone(n, z, 2 * sizeof(struct direct), current_time);
-		enter_dir(n, ".", n);
-		enter_dir(n, "..", parent);
-		incr_link(parent);
-		incr_link(n);
-		eat_dir(n);
-	} else if (*p == 'b' || *p == 'c') {
-		/* Special file. */
-		maj = atoi(token[4]);
-		min = atoi(token[5]);
-		size = 0;
-		if (token[6]) size = atoi(token[6]);
-		size = block_size * size;
-		add_zone(n, (zone_t) ((maj << 8) | min), size, current_time);
-	} else {
-		/* Regular file. Go read it. */
-		if ((f = open(token[4], O_RDONLY)) < 0) {
-			fprintf(stderr, "%s: Can't open %s: %s\n",
-				progname, token[4], strerror(errno));
-		} else {
-			eat_file(n, f);
-		}
-	}
-  }
-
-}
-
-/*================================================================
- * 		eat_file  -  copy file to MINIX
- *===============================================================*/
-/* Zonesize >= blocksize */
-void eat_file(inode, f)
-ino_t inode;
-int f;
-{
-  int ct, i, j, k;
-  zone_t z;
-  char *buf;
-  long timeval;
-
-  buf = alloc_block();
-
-  do {
-	for (i = 0, j = 0; i < zone_size; i++, j += ct) {
-		for (k = 0; k < block_size; k++) buf[k] = 0;
-		if ((ct = read(f, buf, block_size)) > 0) {
-			if (i == 0) z = alloc_zone();
-			put_block((z << zone_shift) + i, buf);
-		}
-	}
-	timeval = (dflag ? current_time : file_time(f));
-	if (ct) add_zone(inode, z, (long) j, timeval);
-  } while (ct == block_size);
-  close(f);
-}
-
-
-
-/*================================================================
- *	    directory & inode management assist group
- *===============================================================*/
-void enter_dir(parent, name, child)
-ino_t parent, child;
-char *name;
-{
-  /* Enter child in parent directory */
-  /* Works for dir > 1 block and zone > block */
-  int i, j, k, l, off;
-  block_t b;
-  zone_t z;
-  char *p1, *p2;
-  struct direct *dir_entry;
-  d1_inode ino1[V1_INODES_PER_BLOCK];
-  d2_inode *ino2;
-  int nr_dzones;
-
-  b = ((parent - 1) / inodes_per_block) + inode_offset;
-  off = (parent - 1) % inodes_per_block;
-
-  if(!(dir_entry = malloc(NR_DIR_ENTRIES(block_size) * sizeof(*dir_entry))))
-  	pexit("couldn't allocate directory entry");
-
-  if(!(ino2 = malloc(V2_INODES_PER_BLOCK(block_size) * sizeof(*ino2))))
-  	pexit("couldn't allocate block of inodes entry");
-
-  if (fs_version == 1) {
-	get_block(b, (char *) ino1);
-	nr_dzones = V1_NR_DZONES;
-  } else {
-	get_block(b, (char *) ino2);
-	nr_dzones = V2_NR_DZONES;
-  }
-  for (k = 0; k < nr_dzones; k++) {
-	if (fs_version == 1) {
-		z = ino1[off].d1_zone[k];
-		if (z == 0) {
-			z = alloc_zone();
-			ino1[off].d1_zone[k] = z;
-		}
-	} else {
-		z = ino2[off].d2_zone[k];
-		if (z == 0) {
-			z = alloc_zone();
-			ino2[off].d2_zone[k] = z;
-		}
-	}
-	for (l = 0; l < zone_size; l++) {
-		get_block((z << zone_shift) + l, (char *) dir_entry);
-		for (i = 0; i < NR_DIR_ENTRIES(block_size); i++) {
-			if (dir_entry[i].d_ino == 0) {
-				dir_entry[i].d_ino = child;
-				p1 = name;
-				p2 = dir_entry[i].d_name;
-				j = sizeof(dir_entry[i].d_name);
-				while (j--) {
-					*p2++ = *p1;
-					if (*p1 != 0) p1++;
-				}
-				put_block((z << zone_shift) + l, (char *) dir_entry);
-				if (fs_version == 1) {
-					put_block(b, (char *) ino1);
-				} else {
-					put_block(b, (char *) ino2);
-				}
-				free(dir_entry);
-				free(ino2);
-				return;
-			}
-		}
-	}
-  }
-
-  printf("Directory-inode %d beyond direct blocks.  Could not enter %s\n",
-         parent, name);
-  pexit("Halt");
-}
-
-
-void add_zone(n, z, bytes, cur_time)
-ino_t n;
-zone_t z;
-long bytes, cur_time;
-{
-  if (fs_version == 1) {
-	add_z_1(n, z, bytes, cur_time);
-  } else {
-	add_z_2(n, z, bytes, cur_time);
-  }
-}
-
-void add_z_1(n, z, bytes, cur_time)
-ino_t n;
-zone_t z;
-long bytes, cur_time;
-{
-  /* Add zone z to inode n. The file has grown by 'bytes' bytes. */
-
-  int off, i;
-  block_t b;
-  zone_t indir;
-  zone1_t blk[V1_INDIRECTS];
-  d1_inode *p;
-  d1_inode inode[V1_INODES_PER_BLOCK];
-
-  b = ((n - 1) / V1_INODES_PER_BLOCK) + inode_offset;
-  off = (n - 1) % V1_INODES_PER_BLOCK;
-  get_block(b, (char *) inode);
-  p = &inode[off];
-  p->d1_size += bytes;
-  p->d1_mtime = cur_time;
-  for (i = 0; i < V1_NR_DZONES; i++)
-	if (p->d1_zone[i] == 0) {
-		p->d1_zone[i] = (zone1_t) z;
-		put_block(b, (char *) inode);
-		return;
-	}
-  put_block(b, (char *) inode);
-
-  /* File has grown beyond a small file. */
-  if (p->d1_zone[V1_NR_DZONES] == 0)
-	p->d1_zone[V1_NR_DZONES] = (zone1_t) alloc_zone();
-  indir = p->d1_zone[V1_NR_DZONES];
-  put_block(b, (char *) inode);
-  b = indir << zone_shift;
-  get_block(b, (char *) blk);
-  for (i = 0; i < V1_INDIRECTS; i++)
-	if (blk[i] == 0) {
-		blk[i] = (zone1_t) z;
-		put_block(b, (char *) blk);
-		return;
-	}
-  pexit("File has grown beyond single indirect");
-}
-
-void add_z_2(n, z, bytes, cur_time)
-ino_t n;
-zone_t z;
-long bytes, cur_time;
-{
-  /* Add zone z to inode n. The file has grown by 'bytes' bytes. */
-
-  int off, i;
-  block_t b;
-  zone_t indir;
-  zone_t *blk;
-  d2_inode *p;
-  d2_inode *inode;
-
-  if(!(blk = malloc(V2_INDIRECTS(block_size)*sizeof(*blk))))
-  	pexit("Couldn't allocate indirect block");
-
-  if(!(inode = malloc(V2_INODES_PER_BLOCK(block_size)*sizeof(*inode))))
-  	pexit("Couldn't allocate block of inodes");
-
-  b = ((n - 1) / V2_INODES_PER_BLOCK(block_size)) + inode_offset;
-  off = (n - 1) % V2_INODES_PER_BLOCK(block_size);
-  get_block(b, (char *) inode);
-  p = &inode[off];
-  p->d2_size += bytes;
-  p->d2_mtime = cur_time;
-  for (i = 0; i < V2_NR_DZONES; i++)
-	if (p->d2_zone[i] == 0) {
-		p->d2_zone[i] = z;
-		put_block(b, (char *) inode);
-  		free(blk);
-  		free(inode);
-		return;
-	}
-  put_block(b, (char *) inode);
-
-  /* File has grown beyond a small file. */
-  if (p->d2_zone[V2_NR_DZONES] == 0) p->d2_zone[V2_NR_DZONES] = alloc_zone();
-  indir = p->d2_zone[V2_NR_DZONES];
-  put_block(b, (char *) inode);
-  b = indir << zone_shift;
-  get_block(b, (char *) blk);
-  for (i = 0; i < V2_INDIRECTS(block_size); i++)
-	if (blk[i] == 0) {
-		blk[i] = z;
-		put_block(b, (char *) blk);
-  		free(blk);
-  		free(inode);
-		return;
-	}
-  pexit("File has grown beyond single indirect");
-}
-
-
-void incr_link(n)
-ino_t n;
-{
-  /* Increment the link count to inode n */
-  int off;
-  static int enter = 0;
-  block_t b;
-
-  if(enter) exit(1);
-
-  b = ((n - 1) / inodes_per_block) + inode_offset;
-  off = (n - 1) % inodes_per_block;
-  if (fs_version == 1) {
-	d1_inode inode1[V1_INODES_PER_BLOCK];
-
-	get_block(b, (char *) inode1);
-	inode1[off].d1_nlinks++;
-	put_block(b, (char *) inode1);
-  } else {
-	static d2_inode *inode2 = NULL;
-	int n;
-
-	n = sizeof(*inode2) * V2_INODES_PER_BLOCK(block_size);
-	if(!inode2 && !(inode2 = malloc(n)))
-		pexit("couldn't allocate a block of inodes");
-
-	get_block(b, (char *) inode2);
-	inode2[off].d2_nlinks++;
-	put_block(b, (char *) inode2);
-  }
-  enter = 0;
-}
-
-
-void incr_size(n, count)
-ino_t n;
-long count;
-{
-  /* Increment the file-size in inode n */
-  block_t b;
-  int off;
-
-  b = ((n - 1) / inodes_per_block) + inode_offset;
-  off = (n - 1) % inodes_per_block;
-  if (fs_version == 1) {
-	d1_inode inode1[V1_INODES_PER_BLOCK];
-
-	get_block(b, (char *) inode1);
-	inode1[off].d1_size += count;
-	put_block(b, (char *) inode1);
-  } else {
-	d2_inode *inode2;
-	if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size) * sizeof(*inode2))))
-		pexit("couldn't allocate a block of inodes");
-
-	get_block(b, (char *) inode2);
-	inode2[off].d2_size += count;
-	put_block(b, (char *) inode2);
-	free(inode2);
-  }
-}
-
-
-/*================================================================
- * 	 	     allocation assist group
- *===============================================================*/
-PRIVATE ino_t alloc_inode(mode, usrid, grpid)
-int mode, usrid, grpid;
-{
-  ino_t num;
-  int off;
-  block_t b;
-
-  num = next_inode++;
-  if (num > nrinodes) {
-  	fprintf(stderr, "have %d inodoes\n", nrinodes);
-  	pexit("File system does not have enough inodes");
-  }
-  b = ((num - 1) / inodes_per_block) + inode_offset;
-  off = (num - 1) % inodes_per_block;
-  if (fs_version == 1) {
-	d1_inode inode1[V1_INODES_PER_BLOCK];
-
-	get_block(b, (char *) inode1);
-	inode1[off].d1_mode = mode;
-	inode1[off].d1_uid = usrid;
-	inode1[off].d1_gid = grpid;
-	put_block(b, (char *) inode1);
-  } else {
-	d2_inode *inode2;
-
-	if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size) * sizeof(*inode2))))
-		pexit("couldn't allocate a block of inodes");
-
-	get_block(b, (char *) inode2);
-	inode2[off].d2_mode = mode;
-	inode2[off].d2_uid = usrid;
-	inode2[off].d2_gid = grpid;
-	put_block(b, (char *) inode2);
-
-	free(inode2);
-  }
-
-  /* Set the bit in the bit map. */
-  /* DEBUG FIXME.  This assumes the bit is in the first inode map block. */
-  insert_bit((block_t) INODE_MAP, (int) num);
-  return(num);
-}
-
-
-PRIVATE zone_t alloc_zone()
-{
-  /* Allocate a new zone */
-  /* Works for zone > block */
-  block_t b;
-  int i;
-  zone_t z;
-
-  z = next_zone++;
-  b = z << zone_shift;
-  if ((b + zone_size) > nrblocks)
-	pexit("File system not big enough for all the files");
-  for (i = 0; i < zone_size; i++)
-	put_block(b + i, zero);	/* give an empty zone */
-  /* DEBUG FIXME.  This assumes the bit is in the first zone map block. */
-  insert_bit(zone_map, (int) (z - zoff));	/* lint, NOT OK because
-						 * z hasn't been broken
-						 * up into block +
-						 * offset yet. */
-  return(z);
-}
-
-
-void insert_bit(block, bit)
-block_t block;
-int bit;
-{
-  /* Insert 'count' bits in the bitmap */
-  int w, s;
-  short *buf;
-
-  buf = (short *) alloc_block();
-
-  if (block < 0) pexit("insert_bit called with negative argument");
-  get_block(block, (char *) buf);
-  w = bit / (8 * sizeof(short));
-  s = bit % (8 * sizeof(short));
-  buf[w] |= (1 << s);
-  put_block(block, (char *) buf);
-
-  free(buf);
-}
-
-
-/*================================================================
- * 		proto-file processing assist group
- *===============================================================*/
-int mode_con(p)
-char *p;
-{
-  /* Convert string to mode */
-  int o1, o2, o3, mode;
-  char c1, c2, c3;
-
-  c1 = *p++;
-  c2 = *p++;
-  c3 = *p++;
-  o1 = *p++ - '0';
-  o2 = *p++ - '0';
-  o3 = *p++ - '0';
-  mode = (o1 << 6) | (o2 << 3) | o3;
-  if (c1 == 'd') mode += I_DIRECTORY;
-  if (c1 == 'b') mode += I_BLOCK_SPECIAL;
-  if (c1 == 'c') mode += I_CHAR_SPECIAL;
-  if (c1 == '-') mode += I_REGULAR;
-  if (c2 == 'u') mode += I_SET_UID_BIT;
-  if (c3 == 'g') mode += I_SET_GID_BIT;
-  return(mode);
-}
-
-void getline(line, parse)
-char *parse[MAX_TOKENS];
-char line[LINE_LEN];
-{
-  /* Read a line and break it up in tokens */
-  int k;
-  char c, *p;
-  int d;
-
-  for (k = 0; k < MAX_TOKENS; k++) parse[k] = 0;
-  for (k = 0; k < LINE_LEN; k++) line[k] = 0;
-  k = 0;
-  parse[0] = 0;
-  p = line;
-  while (1) {
-	if (++k > LINE_LEN) pexit("Line too long");
-	d = fgetc(proto);
-	if (d == EOF) pexit("Unexpected end-of-file");
-	*p = d;
-	if (*p == '\n') lct++;
-	if (*p == ' ' || *p == '\t') *p = 0;
-	if (*p == '\n') {
-		*p++ = 0;
-		*p = '\n';
-		break;
-	}
-	p++;
-  }
-
-  k = 0;
-  p = line;
-  lastp = line;
-  while (1) {
-	c = *p++;
-	if (c == '\n') return;
-	if (c == 0) continue;
-	parse[k++] = p - 1;
-	do {
-		c = *p++;
-	} while (c != 0 && c != '\n');
-  }
-}
-
-
-/*================================================================
- *			other stuff
- *===============================================================*/
-void check_mtab(devname)
-char *devname;			/* /dev/hd1 or whatever */
-{
-/* Check to see if the special file named in s is mounted. */
-
-  int n, r;
-  struct stat sb;
-  char special[PATH_MAX + 1], mounted_on[PATH_MAX + 1], version[10], rw_flag[10];
-
-  r= stat(devname, &sb);
-  if (r == -1)
-  {
-	if (errno == ENOENT)
-		return;	/* Does not exist, and therefore not mounted. */
-	fprintf(stderr, "%s: stat %s failed: %s\n",
-		progname, devname, strerror(errno));
-	exit(1);
-  }
-  if (!S_ISBLK(sb.st_mode))
-  {
-	/* Not a block device and therefore not mounted. */
-	return;
-  }
-
-  if (load_mtab("mkfs") < 0) return;
-  while (1) {
-	n = get_mtab_entry(special, mounted_on, version, rw_flag);
-	if (n < 0) return;
-	if (strcmp(devname, special) == 0) {
-		/* Can't mkfs on top of a mounted file system. */
-		fprintf(stderr, "%s: %s is mounted on %s\n",
-			progname, devname, mounted_on);
-		exit(1);
-	}
-  }
-}
-
-
-long file_time(f)
-int f;
-{
-#ifdef UNIX
-  struct stat statbuf;
-  fstat(f, &statbuf);
-  return(statbuf.st_mtime);
-#else				/* fstat not supported by DOS */
-  return(0L);
-#endif
-}
-
-
-void pexit(s)
-char *s;
-{
-  fprintf(stderr, "%s: %s\n", progname, s);
-  if (lct != 0)
-	fprintf(stderr, "Line %d being processed when error detected.\n", lct);
-  flush();
-  exit(2);
-}
-
-
-void copy(from, to, count)
-char *from, *to;
-int count;
-{
-  while (count--) *to++ = *from++;
-}
-
-char *alloc_block()
-{
-	char *buf;
-
-	if(!(buf = malloc(block_size))) {
-		pexit("couldn't allocate filesystem buffer");
-	}
-  	bzero(buf, block_size);
-
-	return buf;
-}
-
-void print_fs()
-{
-  int i, j;
-  ino_t k;
-  d1_inode inode1[V1_INODES_PER_BLOCK];
-  d2_inode *inode2;
-  unsigned short *usbuf;
-  block_t b, inode_limit;
-  struct direct *dir;
-
-  if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size) * sizeof(*inode2))))
-	pexit("couldn't allocate a block of inodes");
-
-  if(!(dir = malloc(NR_DIR_ENTRIES(block_size)*sizeof(*dir))))
-  	pexit("malloc of directory entry failed");
-
-  usbuf = (unsigned short *) alloc_block();
-
-  get_super_block((char *) usbuf);
-  printf("\nSuperblock: ");
-  for (i = 0; i < 8; i++) printf("%06o ", usbuf[i]);
-  get_block((block_t) 2, (char *) usbuf);
-  printf("...\nInode map:  ");
-  for (i = 0; i < 9; i++) printf("%06o ", usbuf[i]);
-  get_block((block_t) 3, (char *) usbuf);
-  printf("...\nZone  map:  ");
-  for (i = 0; i < 9; i++) printf("%06o ", usbuf[i]);
-  printf("...\n");
-
-  free(usbuf);
-  usbuf = NULL;
-
-  k = 0;
-  for (b = inode_offset; k < nrinodes; b++) {
-	if (fs_version == 1) {
-		get_block(b, (char *) inode1);
-	} else {
-		get_block(b, (char *) inode2);
-	}
-	for (i = 0; i < inodes_per_block; i++) {
-		k = inodes_per_block * (int) (b - inode_offset) + i + 1;
-		/* Lint but OK */
-		if (k > nrinodes) break;
-		if (fs_version == 1) {
-			if (inode1[i].d1_mode != 0) {
-				printf("Inode %2d:  mode=", k);
-				printf("%06o", inode1[i].d1_mode);
-				printf("  uid=%2d  gid=%2d  size=",
-				inode1[i].d1_uid, inode1[i].d1_gid);
-				printf("%6ld", inode1[i].d1_size);
-				printf("  zone[0]=%d\n", inode1[i].d1_zone[0]);
-			}
-			if ((inode1[i].d1_mode & I_TYPE) == I_DIRECTORY) {
-				/* This is a directory */
-				get_block(inode1[i].d1_zone[0], (char *) dir);
-				for (j = 0; j < NR_DIR_ENTRIES(block_size); j++)
-					if (dir[j].d_ino)
-						printf("\tInode %2d: %s\n", dir[j].d_ino, dir[j].d_name);
-			}
-		} else {
-			if (inode2[i].d2_mode != 0) {
-				printf("Inode %2d:  mode=", k);
-				printf("%06o", inode2[i].d2_mode);
-				printf("  uid=%2d  gid=%2d  size=",
-				inode2[i].d2_uid, inode2[i].d2_gid);
-				printf("%6ld", inode2[i].d2_size);
-				printf("  zone[0]=%ld\n", inode2[i].d2_zone[0]);
-			}
-			if ((inode2[i].d2_mode & I_TYPE) == I_DIRECTORY) {
-				/* This is a directory */
-				get_block(inode2[i].d2_zone[0], (char *) dir);
-				for (j = 0; j < NR_DIR_ENTRIES(block_size); j++)
-					if (dir[j].d_ino)
-						printf("\tInode %2d: %s\n", dir[j].d_ino, dir[j].d_name);
-			}
-		}
-	}
-  }
-
-  printf("%d inodes used.     %d zones used.\n", next_inode - 1, next_zone);
-  free(dir);
-  free(inode2);
-}
-
-
-int read_and_set(n)
-block_t n;
-{
-/* The first time a block is read, it returns all 0s, unless there has
- * been a write.  This routine checks to see if a block has been accessed.
- */
-
-  int w, s, mask, r;
-
-  if (sizeof(char *) == 2 && n >= MAX_INIT) pexit("can't initialize past 128M");
-  w = n / 8;
-  s = n % 8;
-  mask = 1 << s;
-  r = (umap[w] & mask ? 1 : 0);
-  umap[w] |= mask;
-  return(r);
-}
-
-void usage()
-{
-  fprintf(stderr,
-	  "Usage: %s [-12dlot] [-b blocks] [-i inodes] [-B blocksize] special [proto]\n",
-	  progname);
-  exit(1);
-}
-
-/*================================================================
- *		      get_block & put_block for MS-DOS
- *===============================================================*/
-#ifdef DOS
-
-/*
- *	These are the get_block and put_block routines
- *	when compiling & running mkfs.c under MS-DOS.
- *
- *	It requires the (asembler) routines absread & abswrite
- *	from the file diskio.asm. Since these routines just do
- *	as they are told (read & write the sector specified),
- *	a local cache is used to minimize the i/o-overhead for
- *	frequently used blocks.
- *
- *	The global variable "file" determines whether the output
- *	is to a disk-device or to a binary file.
- */
-
-
-#define PH_SECTSIZE	   512	/* size of a physical disk-sector */
-
-
-char *derrtab[14] = {
-	     "no error",
-	     "disk is read-only",
-	     "unknown unit",
-	     "device not ready",
-	     "bad command",
-	     "data error",
-	     "internal error: bad request structure length",
-	     "seek error",
-	     "unknown media type",
-	     "sector not found",
-	     "printer out of paper (?)",
-	     "write fault",
-	     "read error",
-	     "general error"
-};
-
-#define	CACHE_SIZE	20	/* 20 block-buffers */
-
-
-struct cache {
-  char blockbuf[BLOCK_SIZE];
-  block_t blocknum;
-  int dirty;
-  int usecnt;
-} cache[CACHE_SIZE];
-
-
-void special(string)
-char *string;
-{
-
-  if (string[1] == ':' && string[2] == 0) {
-	/* Format: d: or d:fname */
-	disk = (string[0] & ~32) - 'A';
-	if (disk > 1 && !override)	/* safety precaution */
-		pexit("Bad drive specifier for special");
-  } else {
-	file = 1;
-	if ((fd = creat(string, BWRITE)) == 0)
-		pexit("Can't open special file");
-  }
-}
-
-void get_block(n, buf)
-block_t n;
-char *buf;
-{
-  /* Get a block to the user */
-  struct cache *bp, *fp;
-
-  /* First access returns a zero block */
-  if (read_and_set(n) == 0) {
-	copy(zero, buf, block_size);
-	return;
-  }
-
-  /* Look for block in cache */
-  fp = 0;
-  for (bp = cache; bp < &cache[CACHE_SIZE]; bp++) {
-	if (bp->blocknum == n) {
-		copy(bp, buf, block_size);
-		bp->usecnt++;
-		return;
-	}
-
-	/* Remember clean block */
-	if (bp->dirty == 0)
-		if (fp) {
-			if (fp->usecnt > bp->usecnt) fp = bp;
-		} else
-			fp = bp;
-  }
-
-  /* Block not in cache, get it */
-  if (!fp) {
-	/* No clean buf, flush one */
-	for (bp = cache, fp = cache; bp < &cache[CACHE_SIZE]; bp++)
-		if (fp->usecnt > bp->usecnt) fp = bp;
-	mx_write(fp->blocknum, fp);
-  }
-  mx_read(n, fp);
-  fp->dirty = 0;
-  fp->usecnt = 0;
-  fp->blocknum = n;
-  copy(fp, buf, block_size);
-}
-
-void put_block(n, buf)
-block_t n;
-char *buf;
-{   
-  /* Accept block from user */
-  struct cache *fp, *bp;
-
-  (void) read_and_set(n);
-
-  /* Look for block in cache */
-  fp = 0;
-  for (bp = cache; bp < &cache[CACHE_SIZE]; bp++) {
-	if (bp->blocknum == n) {
-		copy(buf, bp, block_size);
-		bp->dirty = 1;
-		return;
-	}
-
-	/* Remember clean block */
-	if (bp->dirty == 0)
-		if (fp) {
-			if (fp->usecnt > bp->usecnt) fp = bp;
-		} else
-			fp = bp;
-  }
-
-  /* Block not in cache */
-  if (!fp) {
-	/* No clean buf, flush one */
-	for (bp = cache, fp = cache; bp < &cache[CACHE_SIZE]; bp++)
-		if (fp->usecnt > bp->usecnt) fp = bp;
-	mx_write(fp->blocknum, fp);
-  }
-  fp->dirty = 1;
-  fp->usecnt = 1;
-  fp->blocknum = n;
-  copy(buf, fp, block_size);
-}
-
-void cache_init()
-{
-  struct cache *bp;
-  for (bp = cache; bp < &cache[CACHE_SIZE]; bp++) bp->blocknum = -1;
-}
-
-void flush()
-{
-  /* Flush all dirty blocks to disk */
-  struct cache *bp;
-
-  for (bp = cache; bp < &cache[CACHE_SIZE]; bp++)
-	if (bp->dirty) {
-		mx_write(bp->blocknum, bp);
-		bp->dirty = 0;
-	}
-}
-
-/*==================================================================
- *			hard read & write etc.
- *=================================================================*/
-#define MAX_RETRIES	5
-
-
-void mx_read(blocknr, buf)
-int blocknr;
-char *buf;
-{
-
-  /* Read the requested MINIX-block in core */
-  char (*bp)[PH_SECTSIZE];
-  int sectnum, retries, err;
-
-  if (file) {
-	lseek(fd, (off_t) blocknr * block_size, 0);
-	if (read(fd, buf, block_size) != block_size)
-		pexit("mx_read: error reading file");
-  } else {
-	sectnum = blocknr * (block_size / PH_SECTSIZE);
-	for (bp = buf; bp < &buf[block_size]; bp++) {
-		retries = MAX_RETRIES;
-		do
-			err = absread(disk, sectnum, bp);
-		while (err && --retries);
-
-		if (retries) {
-			sectnum++;
-		} else {
-			dexit("mx_read", sectnum, err);
-		}
-	}
-  }
-}
-
-void mx_write(blocknr, buf)
-int blocknr;
-char *buf;
-{
-  /* Write the MINIX-block to disk */
-  char (*bp)[PH_SECTSIZE];
-  int retries, sectnum, err;
-
-  if (file) {
-	lseek(fd, blocknr * block_size, 0);
-	if (write(fd, buf, block_size) != block_size) {
-		pexit("mx_write: error writing file");
-	}
-  } else {
-	sectnum = blocknr * (block_size / PH_SECTSIZE);
-	for (bp = buf; bp < &buf[block_size]; bp++) {
-		retries = MAX_RETRIES;
-		do {
-			err = abswrite(disk, sectnum, bp);
-		} while (err && --retries);
-
-		if (retries) {
-			sectnum++;
-		} else {
-			dexit("mx_write", sectnum, err);
-		}
-	}
-  }
-}
-
-
-void dexit(s, sectnum, err)
-int sectnum, err;
-char *s;
-{
-  printf("Error: %s, sector: %d, code: %d, meaning: %s\n",
-         s, sectnum, err, derrtab[err]);
-  exit(2);
-}
-
-#endif
-
-/*================================================================
- *		      get_block & put_block for UNIX
- *===============================================================*/
-#ifdef UNIX
-
-void special(string)
-char *string;
-{
-  fd = creat(string, 0777);
-  close(fd);
-  fd = open(string, O_RDWR);
-  if (fd < 0) pexit("Can't open special file");
-#if (MACHINE == ATARI)
-  {
-	struct stat statbuf;
-
-	if (fstat(fd, &statbuf) < 0) return;
-	isdev = (statbuf.st_mode & S_IFMT) == S_IFCHR
-		||
-		(statbuf.st_mode & S_IFMT) == S_IFBLK
-		;
-  }
-#endif
-}
-
-
-
-void get_block(n, buf)
-block_t n;
-char *buf;
-{
-/* Read a block. */
-
-  int k;
-
-  /* First access returns a zero block */
-  if (read_and_set(n) == 0) {
-	copy(zero, buf, block_size);
-	return;
-  }
-  lseek(fd, (off_t) n * block_size, SEEK_SET);
-  k = read(fd, buf, block_size);
-  if (k != block_size) {
-	pexit("get_block couldn't read");
-  }
-}
-
-void get_super_block(buf)
-char *buf;
-{
-/* Read a block. */
-
-  int k;
-
-  if(lseek(fd, (off_t) SUPER_BLOCK_BYTES, SEEK_SET) < 0) {
-  	perror("lseek");
-  	pexit("seek failed");
-  }
-  k = read(fd, buf, _STATIC_BLOCK_SIZE);
-  if (k != _STATIC_BLOCK_SIZE) {
-	pexit("get_super_block couldn't read");
-  }
-}
-
-void put_block(n, buf)
-block_t n;
-char *buf;
-{
-/* Write a block. */
-
-  (void) read_and_set(n);
-
-  /* XXX - check other lseeks too. */
-  if (lseek(fd, (off_t) n * block_size, SEEK_SET) == (off_t) -1) {
-	pexit("put_block couldn't seek");
-  }
-  if (write(fd, buf, block_size) != block_size) {
-	pexit("put_block couldn't write");
-  }
-}
-
-
-/* Dummy routines to keep source file clean from #ifdefs */
-
-void flush()
-{
-  return;
-}
-
-void cache_init()
-{
-  return;
-}
-
-#endif
Index: trunk/minix/commands/simple/mknod.c
===================================================================
--- trunk/minix/commands/simple/mknod.c	(revision 9)
+++ 	(revision )
@@ -1,70 +1,0 @@
-/* mknod - build a special file		Author: Andy Tanenbaum */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <minix/minlib.h>
-#include <errno.h>
-#include <stdio.h>
-
-_PROTOTYPE(int main, (int argc, char *argv []));
-_PROTOTYPE(void badcomm, (void));
-_PROTOTYPE(void badfifo, (void));
-_PROTOTYPE(void badchar, (void));
-_PROTOTYPE(void badblock, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-/* Mknod name b/c major minor makes a node. */
-
-  int mode, major, minor, dev;
-
-  if (argc < 3) badcomm();
-  if (*argv[2] != 'b' && *argv[2] != 'c' && *argv[2] != 'p') badcomm();
-  if (*argv[2] == 'p' && argc != 3) badfifo();
-  if (*argv[2] == 'c' && argc != 5) badchar();
-  if (*argv[2] == 'b' && argc != 5) badblock();
-  if (*argv[2] == 'p') {
-	mode = 010666;
-	dev = 0;
-  } else {
-	mode = (*argv[2] == 'b' ? 060666 : 020666);
-	major = atoi(argv[3]);
-	minor = atoi(argv[4]);
-	if (major - 1 > 0xFE || minor > 0xFF) badcomm();
-	dev = (major << 8) | minor;
-  }
-  if (mknod(argv[1], mode, dev) < 0) {
-	int err = errno;
-	std_err("mknod: ");
-	errno = err;
-	perror(argv[1]);
-  }
-  return(0);
-}
-
-void badcomm()
-{
-  std_err("Usage: mknod name b/c/p [major minor]\n");
-  exit(1);
-}
-
-void badfifo()
-{
-  std_err("Usage: mknod name p\n");
-  exit(1);
-}
-
-void badchar()
-{
-  std_err("Usage: mknod name c major minor\n");
-  exit(1);
-}
-
-void badblock()
-{
-  std_err("Usage: mknod name b major minor\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/mkproto.c
===================================================================
--- trunk/minix/commands/simple/mkproto.c	(revision 9)
+++ 	(revision )
@@ -1,250 +1,0 @@
-/* mkproto - make an mkfs prototype	Author: Andrew Cagney */
-
-/* Submitted by: cagney@chook.ua.oz (Andrew Cagney - aka Noid) */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <limits.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <unistd.h>
-
-/* The default values for the prototype file */
-#define DEF_UID		2	/* bin */
-#define DEF_GID		1	/* daemon group */
-#define DEF_PROT	0555	/* a=re */
-#define DEF_BLOCKS	360
-#define DEF_INODES	63
-#define DEF_INDENTSTR	"\t"
-
-#ifndef major
-#define major(x) ( (x>>8) & 0377)
-#define minor(x) (x & 0377)
-#endif
-
-/* Globals. */
-int count, origlen, tabs;
-int gid, uid, prot, same_uid, same_gid, same_prot, blocks, inodes;
-int block_given, inode_given, dprot;
-char *indentstr;
-char *proto_file, *top;
-FILE *outfile;
-
-extern int optind;
-extern char *optarg;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void descend, (char *dirname));
-_PROTOTYPE(void display_attrib, (char *name, struct stat *st));
-_PROTOTYPE(void usage, (char *binname));
-_PROTOTYPE(void open_outfile, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char *dir;
-  struct stat st;
-  int op;
-
-  gid = DEF_GID;
-  uid = DEF_UID;
-  prot = DEF_PROT;
-  blocks = DEF_BLOCKS;
-  inodes = DEF_INODES;
-  indentstr = DEF_INDENTSTR;
-  inode_given = 0;
-  block_given = 0;
-  top = 0;
-  same_uid = 0;
-  same_gid = 0;
-  same_prot = 0;
-  while ((op = getopt(argc, argv, "b:g:i:p:t:u:d:s")) != EOF) {
-	switch (op) {
-	    case 'b':
-		blocks = atoi(optarg);
-		block_given = 1;
-		break;
-	    case 'g':
-		gid = atoi(optarg);
-		if (gid == 0) usage(argv[0]);
-		same_gid = 0;
-		break;
-	    case 'i':
-		inodes = atoi(optarg);
-		inode_given = 1;
-		break;
-	    case 'p':
-		sscanf(optarg, "%o", &prot);
-		if (prot == 0) usage(argv[0]);
-		same_prot = 0;
-		break;
-	    case 's':
-		same_prot = 1;
-		same_uid = 1;
-		same_gid = 1;
-		break;
-	    case 't':	top = optarg;	break;
-	    case 'u':
-		uid = atoi(optarg);
-		if (uid == 0) usage(argv[0]);
-		same_uid = 0;
-		break;
-	    case 'd':	indentstr = optarg;	break;
-	    default:		/* Illegal options */
-		usage(argv[0]);
-	}
-  }
-
-  if (optind >= argc) {
-	usage(argv[0]);
-  } else {
-	dir = argv[optind];
-	optind++;
-	proto_file = argv[optind];
-  }
-  if (!top) top = dir;
-  open_outfile();
-  if (block_given && !inode_given) inodes = (blocks / 3) + 8;
-  if (!block_given && inode_given) usage(argv[0]);
-  count = 1;
-  tabs = 0;
-  origlen = strlen(dir);
-
-  /* Check that it really is a directory */
-  stat(dir, &st);
-  if ((st.st_mode & S_IFMT) != S_IFDIR) {
-	fprintf(stderr, "mkproto: %s must be a directory\n", dir);
-	usage(argv[0]);
-  }
-  fprintf(outfile, "boot\n%d %d\n", blocks, inodes);
-  display_attrib("", &st);
-  fprintf(outfile, "\n");
-  descend(dir);
-  fprintf(outfile, "$\n");
-  return(0);
-}
-
-/* Output the prototype spec for this directory. */
-void descend(dirname)
-char *dirname;
-{
-  struct dirent *dp;
-  DIR *dirp;
-  char *name, *temp, *tempend;
-  int i;
-  struct stat st;
-  mode_t mode;
-
-  dirp = opendir(dirname);
-  if (dirp == NULL) {
-	fprintf(stderr, "unable to open directory %s\n", dirname);
-	return;
-  }
-  tabs++;
-  temp = (char *) malloc(sizeof(char) * strlen(dirname) +1 + PATH_MAX);
-  strcpy(temp, dirname);
-  strcat(temp, "/");
-  tempend = &temp[strlen(temp)];
-
-  for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
-	name = dp->d_name;
-
-	count++;
-	strcpy(tempend, name);
-
-	if (stat(temp, &st) == -1) {
-		fprintf(stderr, "cant get status of '%s' \n", temp);
-		continue;
-	}
-	if (name[0] == '.' && (name[1] == 0 ||
-	    (name[1] == '.' && name[2] == 0)))
-		continue;
-
-	display_attrib(name, &st);
-
-	mode = st.st_mode & S_IFMT;
-	if (mode == S_IFDIR) {
-		fprintf(outfile, "\n");
-		descend(temp);
-		for (i = 0; i < tabs; i++) {
-			fprintf(outfile, indentstr);
-		}
-		fprintf(outfile, "$\n");
-		continue;
-	}
-	if (mode == S_IFBLK || mode == S_IFCHR) {
-		fprintf(outfile, " %d %d\n", major(st.st_rdev), minor(st.st_rdev));
-		continue;
-	}
-	if (mode == S_IFREG) {
-		i = origlen;
-		fprintf(outfile, "%s%s", indentstr, top);
-		while (temp[i] != '\0') {
-			fputc(temp[i], outfile);
-			i++;
-		}
-		fprintf(outfile, "\n");
-		continue;
-	}
-	fprintf(outfile, " /dev/null");
-	fprintf(stderr,"File\n\t%s\n has an invalid mode, made empty.\n",temp);
-  }
-  closedir(dirp);
-  free(temp);
-  tabs--;
-}
-
-
-void display_attrib(name, st)
-char *name;
-struct stat *st;
-{
-/* Output the specification for a single file */
-
-  int i;
-
-  if (same_uid) uid = st->st_uid;
-  if (same_gid) gid = st->st_gid;
-  if (same_prot)
-	prot = st->st_mode & 0777;	/***** This one is a bit shady *****/
-  for (i = 0; i < tabs; i++) fprintf(outfile, indentstr);
-  fprintf(outfile, "%s%s%c%c%c%3o %d %d",
-	name,
-	*name == '\0' ? "" : indentstr,	/* stop the tab for a null name */
-	(st->st_mode & S_IFMT) == S_IFDIR ? 'd' :
-	(st->st_mode & S_IFMT) == S_IFCHR ? 'c' :
-	(st->st_mode & S_IFMT) == S_IFBLK ? 'b' :
-	'-',			/* file type */
-	(st->st_mode & S_ISUID) ? 'u' : '-',	/* set uid */
-	(st->st_mode & S_ISGID) ? 'g' : '-',	/* set gid */
-	prot,
-	uid,
-	gid);
-}
-
-void usage(binname)
-char *binname;
-{
-  fprintf(stderr, "Usage: %s [options] source_directory [prototype_file]\n", binname);
-  fprintf(stderr, "options:\n");
-  fprintf(stderr, "   -b n\t\t file system size is n blocks (default %d)\n", DEF_BLOCKS);
-  fprintf(stderr, "   -d STRING\t define the indentation characters (default %s)\n", "(none)");
-  fprintf(stderr, "   -g n\t\t use n as the gid on all files (default %d)\n", DEF_GID);
-  fprintf(stderr, "   -i n\t\t file system gets n i-nodes (default %d)\n", DEF_INODES);
-  fprintf(stderr, "   -p nnn\t use nnn (octal) as mode on all files (default %o)\n", DEF_PROT);
-  fprintf(stderr, "   -s  \t\t use the same uid, gid and mode as originals have\n");
-  fprintf(stderr, "   -t ROOT\t inital path prefix for each entry\n");
-  fprintf(stderr, "   -u n\t\t use nnn as the uid on all files (default %d)\n", DEF_UID);
-  exit(1);
-}
-
-void open_outfile()
-{
-  if (proto_file == NULL)
-	outfile = stdout;
-  else if ((outfile = fopen(proto_file, "w")) == NULL)
-	fprintf(stderr, "Cannot create %s\n ", proto_file);
-}
Index: trunk/minix/commands/simple/mkswap.c
===================================================================
--- trunk/minix/commands/simple/mkswap.c	(revision 9)
+++ 	(revision )
@@ -1,197 +1,0 @@
-/*	mkswap 1.0 - Initialize a swap partition or file
- *							Author: Kees J. Bot
- *								6 Jan 2001
- */
-#define nil ((void*)0)
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include <minix/u64.h>
-#include <minix/partition.h>
-#include <minix/swap.h>
-#include <servers/fs/const.h>
-#include <servers/fs/type.h>
-#include <servers/fs/super.h>
-
-static void usage(void)
-{
-    fprintf(stderr, "Usage: mkswap [-f] device-or-file [size[km]]\n");
-    exit(1);
-}
-
-int main(int argc, char **argv)
-{
-    int first;
-    int i;
-    char *file;
-    unsigned long offset, size, devsize;
-    int fd;
-    struct stat st;
-    ssize_t r;
-    struct super_block super;
-    swap_hdr_t swap_hdr;
-    static u8_t block[_MAX_BLOCK_SIZE];
-
-    first= 0;
-    i= 1;
-    while (i < argc && argv[i][0] == '-') {
-	char *opt= argv[i++]+1;
-
-	if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-	while (*opt != 0) switch (*opt++) {
-	case 'f':	first= 1;	break;
-	default:	usage();
-	}
-    }
-    if (i == argc) usage();
-    file= argv[i++];
-
-    size= 0;
-    if (i < argc) {
-	char *end;
-	unsigned long m;
-
-	size= strtoul(argv[i], &end, 10);
-	if (end == argv[i]) usage();
-	m= 1024;
-	if (*end != 0) {
-	    switch (*end) {
-	    case 'm':	case 'M':	m *= 1024;	/*FALL THROUGH*/
-	    case 'k':	case 'K':	end++;		break;
-	    }
-	}
-	if (*end != 0 || size == -1
-	    || (size * m) / m != size || (size *= m) <= SWAP_OFFSET
-	) {
-	    fprintf(stderr, "mkswap: %s: Bad size\n", argv[i]);
-	    exit(1);
-	}
-	i++;
-    }
-    if (i != argc) usage();
-
-    /* Open the device or file. */
-    if ((fd= open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) {
-	fprintf(stderr, "mkswap: Can't open %s: %s\n", file, strerror(errno));
-	exit(1);
-    }
-
-    /* File or device? */
-    (void) fstat(fd, &st);
-    if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode)) {
-	struct partition part;
-
-	/* How big is the partition? */
-	if (ioctl(fd, DIOCGETP, &part) < 0) {
-	    fprintf(stderr, "mkswap: Can't determine the size of %s: %s\n",
-		file, strerror(errno));
-	    exit(1);
-	}
-	devsize= cv64ul(part.size);
-	offset= 0;
-
-	if (!first) {
-	    /* Is there a file system? */
-	    r= -1;
-	    if (lseek(fd, SUPER_BLOCK_BYTES, SEEK_SET) == -1
-		|| (r= read(fd, block, _STATIC_BLOCK_SIZE)) < _STATIC_BLOCK_SIZE
-	    ) {
-		fprintf(stderr, "mkswap: %s: %s\n",
-		    file, r >= 0 ? "End of file" : strerror(errno));
-		exit(1);
-	    }
-	    memcpy(&super, block, sizeof(super));
-	    if (super.s_magic == SUPER_MAGIC) {
-		offset= (unsigned long) super.s_nzones * _STATIC_BLOCK_SIZE;
-	    } else
-	    if (super.s_magic == SUPER_V2) {
-		offset= (unsigned long) super.s_zones * _STATIC_BLOCK_SIZE;
-	    } else if (super.s_magic == SUPER_V3) {
-		offset= (unsigned long) super.s_zones * super.s_block_size;
-	    } else {
-		first= 1;
-	    }
-	}
-	if (size == 0) size= devsize - offset;
-	if (size == 0 || offset + size > devsize) {
-	    fprintf(stderr, "mkswap: There is no room on %s for ", file);
-	    if (size > 0) fprintf(stderr, "%lu kilobytes of ", size/1024);
-	    fprintf(stderr, "swapspace\n");
-	    if (offset > 0) {
-		fprintf(stderr, "(Use the -f flag to wipe the file system)\n");
-	    }
-	    exit(1);
-	}
-    } else
-    if (S_ISREG(st.st_mode)) {
-	/* Write to the swap file to guarantee space for MM. */
-	unsigned long n;
-
-	if (size == 0) {
-	    fprintf(stderr, "mkswap: No size specified for %s\n", file);
-	    usage();
-	}
-
-	memset(block, 0, sizeof(block));
-	for (n= 0; n < size; n += r) {
-	    r= size > sizeof(block) ? sizeof(block) : size;
-	    if ((r= write(fd, block, r)) <= 0) {
-		fprintf(stderr, "mkswap: %s: %s\n",
-		    file, r == 0 ? "End of file" : strerror(errno));
-		exit(1);
-	    }
-	}
-	first= 1;
-    } else {
-	fprintf(stderr, "mkswap: %s is not a device or a file\n", file);
-	exit(1);
-    }
-
-    if (offset < SWAP_OFFSET) {
-	offset += SWAP_OFFSET;
-	if (size < SWAP_OFFSET) size= 0; else size -= SWAP_OFFSET;
-    }
-    swap_hdr.sh_magic[0]= SWAP_MAGIC0;
-    swap_hdr.sh_magic[1]= SWAP_MAGIC1;
-    swap_hdr.sh_magic[2]= SWAP_MAGIC2;
-    swap_hdr.sh_magic[3]= SWAP_MAGIC3;
-    swap_hdr.sh_version= SH_VERSION;
-    swap_hdr.sh_priority= 0;
-    swap_hdr.sh_offset= offset;
-    swap_hdr.sh_swapsize= size;
-
-    r= -1;
-    if (lseek(fd, SWAP_BOOTOFF, SEEK_SET) == -1
-	|| (r= read(fd, block, sizeof(block))) < sizeof(block)
-    ) {
-	fprintf(stderr, "mkswap: %s: %s\n", file,
-	    file, r >= 0 ? "End of file" : strerror(errno));
-	exit(1);
-    }
-
-    r= (first ? SWAP_BOOTOFF : OPTSWAP_BOOTOFF) - SWAP_BOOTOFF;
-    memcpy(block + r, &swap_hdr, sizeof(swap_hdr));
-
-    r= -1;
-    if (lseek(fd, SWAP_BOOTOFF, SEEK_SET) == -1
-	|| (r= write(fd, block, sizeof(block))) < sizeof(block)
-    ) {
-	fprintf(stderr, "mkswap: %s: %s\n", file,
-	    file, r >= 0 ? "End of file" : strerror(errno));
-	exit(1);
-    }
-    printf("%s: swapspace at offset %lu, size %lu kilobytes\n",
-	file, offset / 1024, size / 1024);
-    return 0;
-}
Index: trunk/minix/commands/simple/modem.c
===================================================================
--- trunk/minix/commands/simple/modem.c	(revision 9)
+++ 	(revision )
@@ -1,253 +1,0 @@
-/* modem - Put modem into DIALIN or DIALOUT mode.	Author: F. van Kempen */
-
-/* Exit:	0	OK, suspended/restarted GETTY
- *		1	UNIX error
- *		2	Process busy
- * Version:	1.3 	12/30/89
- *
- * Author:	F. van Kempen, MicroWalt Corporation
- *
- * All fancy stuff removed, see getty.c.	Kees J. Bot.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include <utmp.h>
-#include <errno.h>
-
-#include <minix/paths.h>
-
-char PATH_UTMP[] = _PATH_UTMP;			/* current logins */
-
-_PROTOTYPE(void usage , (void));
-_PROTOTYPE(int main , (int argc , char *argv []));
-_PROTOTYPE(void sendcodes , (char *tty, char *codes));
-
-
-void usage()
-{
-  fprintf(stderr,
-"Usage: modem [-sio] [-I in-codes] [-O out-codes] line [command args ...]\n");
-  exit(1);
-}
-
-
-main(argc, argv)
-int argc;
-char *argv[];
-{
-  struct utmp entry;
-  char devtty[1024], *tty;
-  char **command;
-  int ex_code = 0;
-  int fd, i, slot, getty;
-  struct stat st;
-  enum { TOGGLE, DIALIN, DIALOUT } mode= TOGGLE;
-  int silent = 0;
-  _PROTOTYPE(void (*hsig), (int));
-  _PROTOTYPE(void (*isig), (int));
-  _PROTOTYPE(void (*qsig), (int));
-  _PROTOTYPE(void (*tsig), (int));
-  pid_t pid;
-  int r, status;
-  uid_t uid = getuid();
-  gid_t gid = getgid();
-  char *in_codes, *out_codes;
-
-  i = 1;
-  while (i < argc && argv[i][0] == '-') {
-	char *opt = argv[i++] + 1;
-
-	if (opt[0] == '-' && opt[1] == 0) break;
-
-	while (*opt != 0) {
-		switch (*opt++) {
-		    case 's':	/* silent mode */
-			silent = 1;
-			break;
-		    case 'i':	/* DIAL-IN mode: suspend GETTY */
-			mode = DIALIN;
-			break;
-		    case 'o':	/* DIAL-OUT mode: restart GETTY */
-			mode = DIALOUT;
-			break;
-		    case 'I':	/* code to switch modem to dial-in */
-			if (*opt == 0) {
-				if (i == argc) usage();
-				opt = argv[i++];
-			}
-			in_codes = opt;
-			opt = "";
-			break;
-		    case 'O':	/* code to switch modem to dial-out */
-			if (*opt == 0) {
-				if (i == argc) usage();
-				opt = argv[i++];
-			}
-			out_codes = opt;
-			opt = "";
-			break;
-		    default:
-			usage();
-		}
-	}
-  }
-
-  if (i == argc) usage();
-  tty = argv[i++];		/* Modem line */
-
-  if (mode != TOGGLE && i != argc) usage();
-  command = argv + i;		/* Command to execute (if any). */
-
-  if (strchr(tty, '/') == NULL) {
-	strcpy(devtty, "/dev/");
-	strncat(devtty, tty, 1024 - 6);
-	tty = devtty;
-  }
-
-  if (stat(tty, &st) < 0) {
-	fprintf(stderr, "modem: %s: %s\n", tty, strerror(errno));
-	exit(1);
-  }
-
-  if (!S_ISCHR(st.st_mode)) {
-	fprintf(stderr, "%s is not a tty\n", tty);
-	exit(1);
-  }
-
-  /* Find the utmp slot number for the line. */
-  if ((fd= open(tty, O_RDONLY)) < 0 || (slot= fttyslot(fd)) == 0) {
-	fprintf(stderr, "modem: %s: %s\n", tty, strerror(errno));
-	exit(1);
-  }
-  close(fd);
-
-  /* Read the UTMP file to find out the PID and STATUS of the GETTY. */
-  entry.ut_type= 0;
-  if ((fd = open(PATH_UTMP, O_RDONLY)) < 0
-	|| lseek(fd, (off_t) slot * sizeof(entry), SEEK_SET) < 0
-	|| read(fd, &entry, sizeof(entry)) < 0
-  ) {
-	fprintf(stderr, "modem: cannot read UTMP !\n");
-	exit(1);
-  }
-  close(fd);
-
-  hsig= signal(SIGHUP, SIG_IGN);
-  isig= signal(SIGINT, SIG_IGN);
-  qsig= signal(SIGQUIT, SIG_IGN);
-  tsig= signal(SIGTERM, SIG_IGN);
-
-  /* Process the terminal entry if we got one. */
-  switch (entry.ut_type) {
-  case LOGIN_PROCESS:		/* getty waiting for a call */
-	getty = 1;
-	break;
-  case USER_PROCESS:		/* login or user-shell */
-	if (!silent) fprintf(stderr, "modem: line is busy.\n");
-	exit(2);
-	break;
-  default:
-	getty = 0;
-  }
-
-  for (i = (mode == TOGGLE) ? 0 : 1; i < 2; i++) {
-	/* Now perform the desired action (DIALIN or DIALOUT). */
-	switch (mode) {
-	case DIALOUT:
-	case TOGGLE:
-		if (getty) kill(entry.ut_pid, SIGUSR1);  /* suspend getty */
-		chown(tty, uid, st.st_gid);	/* give line to user */
-		chmod(tty, 0600);
-		if (out_codes != NULL) sendcodes(tty, out_codes);
-		if (!silent) printf("modem on %s set for dialout.\n", tty);
-		break;
-	case DIALIN:
-		if (in_codes != NULL) sendcodes(tty, in_codes);
-		chown(tty, 0, st.st_gid);		/* revoke access */
-		chmod(tty, 0600);
-		if (getty) kill(entry.ut_pid, SIGUSR2);	/* restart getty */
-		if (!silent) printf("modem on %s set for dialin.\n", tty);
-	}
-	if (mode == TOGGLE) {
-		/* Start the command to run */
-		pid_t pid;
-		int status;
-
-		switch ((pid = fork())) {
-		case -1:
-			fprintf(stderr, "modem: fork(): %s\n", strerror(errno));
-			ex_code= 1;
-			break;
-		case 0:
-			setgid(gid);
-			setuid(uid);
-			(void) signal(SIGHUP, hsig);
-			(void) signal(SIGINT, isig);
-			(void) signal(SIGQUIT, qsig);
-			(void) signal(SIGTERM, tsig);
-			execvp(command[0], command);
-			fprintf(stderr, "modem: %s: %s\n",
-					command[0], strerror(errno));
-			_exit(127);
-		default:
-			while ((r= wait(&status)) != pid) {
-				if (r == -1 && errno != EINTR) break;
-			}
-			if (r == -1 || status != 0) ex_code = 1;
-		}
-		mode = DIALIN;
-	}
-  }
-  exit(ex_code);
-}
-
-void sendcodes(tty, codes)
-char *tty, *codes;
-{
-	int fd;
-	int c;
-	char buf[1024], *bp = buf;
-
-	if ((fd = open(tty, O_RDWR|O_NONBLOCK)) < 0) {
-		fprintf(stderr, "modem: can't send codes to %s: %s\n",
-			tty, strerror(errno));
-		return;
-	}
-	while ((c = *codes++) != 0) {
-fprintf(stderr, "%d\n", __LINE__);
-		if (c == '\\') {
-			if ((c = *codes++) == 0) break;
-			if (c == 'r') c= '\r';
-			if (c == 'n') c= '\n';
-		}
-		*bp++ = c;
-		if (bp == buf + sizeof(buf) || c == '\r' || c == '\n') {
-fprintf(stderr, "%d\n", __LINE__);
-			write(fd, buf, bp - buf);
-fprintf(stderr, "%d\n", __LINE__);
-			do {sleep(1);
-fprintf(stderr, "%d\n", __LINE__);
-			fprintf(stderr, "%d\n", read(fd, buf, sizeof(buf)));
-			}while (read(fd, buf, sizeof(buf)) > 0);
-fprintf(stderr, "%d\n", __LINE__);
-			bp = buf;
-		}
-	}
-	if (bp > buf) {
-fprintf(stderr, "%d\n", __LINE__);
-		write(fd, buf, bp - buf);
-fprintf(stderr, "%d\n", __LINE__);
-		do sleep(1); while (read(fd, buf, sizeof(buf)) > 0);
-fprintf(stderr, "%d\n", __LINE__);
-	}
-	close(fd);
-}
Index: trunk/minix/commands/simple/mount.c
===================================================================
--- trunk/minix/commands/simple/mount.c	(revision 9)
+++ 	(revision )
@@ -1,206 +1,0 @@
-/* mount - mount a file system		Author: Andy Tanenbaum */
-
-#include <errno.h>
-#include <sys/types.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/minlib.h>
-#include <minix/swap.h>
-#include <sys/svrctl.h>
-#include <stdio.h>
-#include "../../servers/fs/const.h"
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void list, (void));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void tell, (char *this));
-_PROTOTYPE(void swapon, (char *file));
-
-static u8_t MAGIC[] = { SWAP_MAGIC0, SWAP_MAGIC1, SWAP_MAGIC2, SWAP_MAGIC3 };
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int i, ro, swap, n, v;
-  char **ap, *vs, *opt, *err;
-  char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
-
-  if (argc == 1) list();	/* just list /etc/mtab */
-  ro = 0;
-  swap = 0;
-  ap = argv+1;
-  for (i = 1; i < argc; i++) {
-	if (argv[i][0] == '-') {
-		opt = argv[i]+1;
-		while (*opt != 0) switch (*opt++) {
-		case 'r':	ro = 1;		break;
-		case 's':	swap = 1;	break;
-		default:	usage();
-		}
-	} else {
-		*ap++ = argv[i];
-	}
-  }
-  *ap = NULL;
-  argc = (ap - argv);
-
-  if (ro && swap) usage();
-
-  if (swap) {
-	if (argc != 2) usage();
-	swapon(argv[1]);
-	tell(argv[1]);
-	tell(" is swapspace\n");
-  } else {
-	if (argc != 3) usage();
-	if (mount(argv[1], argv[2], ro) < 0) {
-		err = strerror(errno);
-		std_err("mount: Can't mount ");
-		std_err(argv[1]);
-		std_err(" on ");
-		std_err(argv[2]);
-		std_err(": ");
-		std_err(err);
-		std_err("\n");
-		exit(1);
-	}
-	/* The mount has completed successfully. Tell the user. */
-	tell(argv[1]);
-	tell(" is read-");
-	tell(ro ? "only" : "write");
-	tell(" mounted on ");
-	tell(argv[2]);
-	tell("\n");
-  }
-
-  /* Update /etc/mtab. */
-  n = load_mtab("mount");
-  if (n < 0) exit(1);		/* something is wrong. */
-
-  /* Loop on all the /etc/mtab entries, copying each one to the output buf. */
-  while (1) {
-	n = get_mtab_entry(special, mounted_on, version, rw_flag);
-	if (n < 0) break;
-	n = put_mtab_entry(special, mounted_on, version, rw_flag);
-	if (n < 0) {
-		std_err("mount: /etc/mtab has grown too large\n");
-		exit(1);
-	}
-  }
-  if (swap) {
-	vs = "swap";
-  } else {
-	v = fsversion(argv[1], "mount");
-	if (v == 1)
-		vs = "1";
-	else if (v == 2)
-		vs = "2";
-	else if (v == 3)
-		vs = "3";
-	else
-		vs = "0";
-  }
-  n = put_mtab_entry(argv[1], swap ? "swap" : argv[2], vs, (ro ? "ro" : "rw") );
-  if (n < 0) {
-	std_err("mount: /etc/mtab has grown too large\n");
-	exit(1);
-  }
-
-  n = rewrite_mtab("mount");
-  return(0);
-}
-
-
-void list()
-{
-  int n;
-  char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
-
-  /* Read and print /etc/mtab. */
-  n = load_mtab("mount");
-  if (n < 0) exit(1);
-
-  while (1) {
-	n = get_mtab_entry(special, mounted_on, version, rw_flag);
-	if  (n < 0) break;
-	write(1, special, strlen(special));
-	if (strcmp(version, "swap") == 0) {
-		tell(" is swapspace\n");
-	} else {
-		tell(" is read-");
-		tell(strcmp(rw_flag, "rw") == 0 ? "write" : "only");
-		tell(" mounted on ");
-		tell(mounted_on);
-		tell("\n");
-	}
-  }
-  exit(0);
-}
-
-
-void usage()
-{
-  std_err("Usage: mount [-r] special name\n       mount -s special\n");
-  exit(1);
-}
-
-
-void tell(this)
-char *this;
-{
-  write(1, this, strlen(this));
-}
-
-void swapon(file)
-char *file;
-{
-  u32_t super[2][_MAX_BLOCK_SIZE / 2 / sizeof(u32_t)];
-  swap_hdr_t *sp;
-  struct mmswapon mmswapon;
-  int fd, r;
-  char *err;
-  
-  if ((fd = open(file, O_RDWR)) < 0
-	|| lseek(fd, SUPER_BLOCK_BYTES, SEEK_SET) == -1
-	|| (r = read(fd, super, _STATIC_BLOCK_SIZE)) < 0
-  ) {
-	err = strerror(errno);
-	std_err("mount: ");
-	std_err(file);
-	std_err(": ");
-	std_err(err);
-	std_err("\n");
-	exit(1);
-  }
-  sp = (swap_hdr_t *) &super[0];
-  if (memcmp(sp->sh_magic, MAGIC, sizeof(MAGIC)) != 0)
-	sp = (swap_hdr_t *) &super[1];
-  if (r == _STATIC_BLOCK_SIZE && memcmp(sp->sh_magic, MAGIC, sizeof(MAGIC)) != 0
-			|| sp->sh_version > SH_VERSION) {
-	std_err("mount: ");
-	std_err(file);
-	std_err(" is not swapspace\n");
-	exit(1);
-  }
-  close(fd);
-  mmswapon.offset = sp->sh_offset;
-  mmswapon.size = sp->sh_swapsize;
-  strncpy(mmswapon.file, file, sizeof(mmswapon.file));
-  mmswapon.file[sizeof(mmswapon.file)-1] = 0;
-  if (svrctl(MMSWAPON, &mmswapon) < 0) {
-	err = strerror(errno);
-	std_err("mount: ");
-	std_err(file);
-	std_err(": ");
-	std_err(err);
-	std_err("\n");
-	exit(1);
-  }
-}
Index: trunk/minix/commands/simple/mt.c
===================================================================
--- trunk/minix/commands/simple/mt.c	(revision 9)
+++ 	(revision )
@@ -1,216 +1,0 @@
-/*	mt 1.3 - magnetic tape control			Author: Kees J. Bot
- *								4 Apr 1993
- */
-#define nil	NULL
-#ifndef _POSIX_SOURCE
-#define _POSIX_SOURCE	1
-#endif
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/mtio.h>
-
-/* Device status. */
-#define DS_OK		0
-#define DS_ERR		1
-#define DS_EOF		2
-
-/* SCSI Sense key bits. */
-#define SENSE_KEY	0x0F	/* The key part. */
-#define SENSE_ILI	0x20	/* Illegal block size. */
-#define SENSE_EOM	0x40	/* End-of-media. */
-#define SENSE_EOF	0x80	/* Filemark reached. */
-
-/* Supported operations: */
-
-typedef struct tape_operation {
-	int	op;		/* Opcode for MTIOCTOP ioctl (if any). */
-	char	*cmd;		/* Command name. */
-	int	lim;		/* Limits on count. */
-} tape_operation_t;
-
-#define SELF	-1	/* Not a simple command, have to interpret. */
-#define IGN	-1	/* Ignore count field (or accept anything.) */
-#define NNG	 0	/* Nonnegative count field. */
-#define POS	 1	/* Positive count field. */
-
-tape_operation_t tapeops[] = {
-	{ MTWEOF,  "eof",      POS },	/* Write EOF mark */
-	{ MTWEOF,  "weof",     POS },	/* Same */
-	{ MTFSF,   "fsf",      POS },	/* Forward Space File */
-	{ MTFSR,   "fsr",      POS },	/* Forward Space Record */
-	{ MTBSF,   "bsf",      NNG },	/* Backward Space File */
-	{ MTBSR,   "bsr",      POS },	/* Backward Space Record */
-	{ MTEOM,   "eom",      IGN },	/* To End-Of-Media */
-	{ MTREW,   "rewind",   IGN },	/* Rewind */
-	{ MTOFFL,  "offline",  IGN },	/* Rewind and take offline */
-	{ MTOFFL,  "rewoffl",  IGN },	/* Same */
-	{ SELF,	   "status",   IGN },	/* Tape Status */
-	{ MTRETEN, "retension",IGN },	/* Retension the tape */
-	{ MTERASE, "erase",    IGN },	/* Erase the tape */
-	{ MTMODE,  "density",  NNG },	/* Select density */
-	{ MTBLKZ,  "blksize",  NNG },	/* Select block size */
-	{ MTBLKZ,  "blocksize",NNG },	/* Same */
-};
-
-#define arraysize(a)	(sizeof(a)/sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-/* From aha_scsi.c: */
-char *dev_state[] = {
-	"OK", "ERR", "EOF"
-};
-
-char *scsi_sense[] = {
-	"NO SENSE INFO", "RECOVERED ERROR", "NOT READY", "MEDIUM ERROR",
-	"HARDWARE ERROR", "ILLEGAL REQUEST", "UNIT ATTENTION", "DATA PROTECT",
-	"BLANK CHECK", "VENDOR UNIQUE ERROR", "COPY ABORTED", "ABORTED COMMAND",
-	"EQUAL", "VOLUME OVERFLOW", "MISCOMPARE", "SENSE RESERVED"
-};
-
-void usage(void)
-{
-	fprintf(stderr, "Usage: mt [-f device] command [count]\n");
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	char *tape;
-	char *cmd;
-	int count= 1;
-	int fd, r;
-	tape_operation_t *op, *found;
-	struct mtop mtop;
-	struct mtget mtget;
-
-	tape= getenv("TAPE");
-
-	/* -f tape? */
-	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'f') {
-		tape= argv[1] + 2;
-
-		if (*tape == 0) {
-			if (--argc < 2) usage();
-			argv++;
-			tape= argv[1];
-		}
-		argc--;
-		argv++;
-	}
-
-	if (argc != 2 && argc != 3) usage();
-
-	if (argc == 3) {
-		/* Check and convert the 'count' argument. */
-		char *end;
-
-		errno= 0;
-		count= strtol(argv[2], &end, 0);
-		if (*end != 0) usage();
-		if (errno == ERANGE || (mtop.mt_count= count) != count) {
-			fprintf(stderr, "mt: %s: count too large, overflow\n",
-				argv[2]);
-			exit(1);
-		}
-	}
-
-	if (tape == nil) {
-		fprintf(stderr,
-			"mt: tape device not specified by -f or $TAPE\n");
-		exit(1);
-	}
-
-	cmd= argv[1];
-	if (strcmp(cmd, "rew") == 0) cmd= "rewind";	/* aha! */
-	found= nil;
-
-	/* Search for an operation that is unambiguously named. */
-	for (op= tapeops; op < arraylimit(tapeops); op++) {
-		if (strncmp(op->cmd, cmd, strlen(cmd)) == 0) {
-			if (found != nil) {
-				fprintf(stderr, "mt: %s: ambiguous\n", cmd);
-				exit(1);
-			}
-			found= op;
-		}
-	}
-
-	if ((op= found) == nil) {
-		fprintf(stderr, "mt: unknown command '%s'\n", cmd);
-		exit(1);
-	}
-
-	/* Check count. */
-	switch (op->lim) {
-	case NNG:
-		if (count < 0) {
-			fprintf(stderr, "mt %s: count may not be negative\n",
-				op->cmd);
-			exit(1);
-		}
-		break;
-	case POS:
-		if (count <= 0) {
-			fprintf(stderr,
-				"mt %s: count must be greater than zero\n",
-				op->cmd);
-			exit(1);
-		}
-		break;
-	}
-
-	if (strcmp(tape, "-") == 0) {
-		fd= 0;
-	} else
-	if ((fd= open(tape, O_RDONLY)) < 0) {
-		fprintf(stderr, "mt: %s: %s\n", tape, strerror(errno));
-		exit(1);
-	}
-
-	if (op->op != SELF) {
-		/* A simple tape operation. */
-
-		mtop.mt_op= op->op;
-		mtop.mt_count= count;
-		r= ioctl(fd, MTIOCTOP, &mtop);
-	} else
-	if (strcmp(op->cmd, "status") == 0) {
-		/* Get status information. */
-
-		if ((r= ioctl(fd, MTIOCGET, &mtget)) == 0) {
-			printf("\
-SCSI tape drive %s:\n\
-   drive status = 0x%02x (%s), sense key = 0x%02x (%s%s%s%s)\n\
-   file no = %ld, block no = %ld, residual = %ld, block size = ",
-   				tape, mtget.mt_dsreg,
-   				mtget.mt_dsreg > 2 ? "?" :
-   						dev_state[mtget.mt_dsreg],
-				mtget.mt_erreg,
-				mtget.mt_erreg & SENSE_EOF ? "EOF + " : "",
-				mtget.mt_erreg & SENSE_EOM ? "EOM + " : "",
-				mtget.mt_erreg & SENSE_ILI ? "ILI + " : "",
-				scsi_sense[mtget.mt_erreg & SENSE_KEY],
-				(long) mtget.mt_fileno,
-				(long) mtget.mt_blkno,
-				(long) mtget.mt_resid);
-			printf(mtget.mt_blksize == 0 ? "variable\n" : "%ld\n",
-				mtget.mt_blksize);
-		}
-	}
-	if (r < 0) {
-		if (errno == ENOTTY) {
-			fprintf(stderr, "mt: %s: command '%s' not supported\n",
-				tape, op->cmd);
-			exit(2);
-		}
-		fprintf(stderr, "mt: %s: %s\n", tape, strerror(errno));
-		exit(1);
-	}
-	exit(0);
-}
Index: trunk/minix/commands/simple/newroot.c
===================================================================
--- trunk/minix/commands/simple/newroot.c	(revision 9)
+++ 	(revision )
@@ -1,31 +1,0 @@
-/*
-newroot.c
-
-Replace the current root with a new one
-*/
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-int main(int argc, char *argv[])
-{
-	int r;
-	char *dev;
-
-	if (argc != 2)
-	{
-		fprintf(stderr, "Usage: newroot <block-special>\n");
-		exit(1);
-	}
-	dev= argv[1];
-	r= mount(dev, "/", 0 /* !ro */);
-	if (r != 0)
-	{
-		fprintf(stderr, "newroot: mount failed: %s\n", strerror(errno));
-		exit(1);
-	}
-	return 0;
-}
Index: trunk/minix/commands/simple/nice.c
===================================================================
--- trunk/minix/commands/simple/nice.c	(revision 9)
+++ 	(revision )
@@ -1,108 +1,0 @@
-/*
- * Copyright (c) 1989, 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. 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.
- */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#define	DEFNICE	10
-
-void usage(void);
-
-int
-main(int argc, char *argv[])
-{
-	long niceness = DEFNICE;
-	int ch;
-	char *ep;
-	char arg1[10];
-
-	/* Obsolescent syntax: -number, --number */
-	if (argc >= 2 && argv[1][0] == '-' && (argv[1][1] == '-' ||
-	    isdigit((unsigned char)argv[1][1])) && strcmp(argv[1], "--") != 0) {
-		snprintf(arg1, sizeof(arg1), "-n%s", argv[1] + 1);
-		argv[1] = arg1;
-	}
-
-	while ((ch = getopt(argc, argv, "n:")) != -1) {
-		switch (ch) {
-		case 'n':
-			errno = 0;
-			niceness = strtol(optarg, &ep, 10);
-			if (ep == optarg || *ep != '\0' || errno ||
-			    niceness < INT_MIN || niceness > INT_MAX) {
-				fprintf(stderr, "%s: invalid nice value", optarg);
-				return 1;
-			}
-			break;
-		default:
-			usage();
-		}
-	}
-	argc -= optind;
-	argv += optind;
-
-	if (argc == 0)
-		usage();
-
-	errno = 0;
-	niceness += getpriority(PRIO_PROCESS, 0);
-	if (errno) {
-		perror("getpriority");
-		return 1;
-	}
-	if (setpriority(PRIO_PROCESS, 0, (int)niceness)) {
-		perror("setpriority");
-		return 1;
-	}
-	errno = 0;
-	execvp(*argv, argv);
-	perror("execvp");
-	return 1;
-}
-
-void
-usage(void)
-{
-
-	(void)fprintf(stderr, "usage: nice [-n incr] utility [arguments]\n");
-	exit(1);
-}
Index: trunk/minix/commands/simple/nm.c
===================================================================
--- trunk/minix/commands/simple/nm.c	(revision 9)
+++ 	(revision )
@@ -1,226 +1,0 @@
-/* nm - print name list.		Author: Dick van Veen */
-
-/* Dick van Veen: veench@cs.vu.nl */
-
-#include <sys/types.h>
-#include <a.out.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-/* Read the name list in memory, sort it, and print it.  */
-
-/* Nm [-gnopru] [file] ...
- *
- * flags:
- *	-d	address in decimal
- *	-g	print only external symbols.
- *	-n	sort numerically rather than alphabetically.
- *	-o	prepend file name to each line rather than only once.
- *	-p	don't sort, pint n symbol-table order.
- *	-r	sort in reverse order.
- *	-u	print only undefined symbols.
- *
- *	-	when no file name is present, a.out is assumed.
- *
- *	NOTE:	no archives are supported because assembly files don't
- *		have symbol tables.
- *
- */
-
-#define A_OUT		"a.out"
-
-int d_flag;
-int g_flag;
-int n_flag;
-int o_flag;
-int p_flag;
-int r_flag;
-int u_flag;
-
-char io_buf[BUFSIZ];		/* io buffer */
-struct exec header;		/* header of a.out file */
-int stbl_elems;			/* #elements in symbol table */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(int nm_sort, (const void *tmp_stbl1, const void *tmp_stbl2));
-_PROTOTYPE(void nm, (char *file));
-_PROTOTYPE(int read_header, (int fd));
-_PROTOTYPE(void nm_print, (char *file, struct nlist *stbl));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  argv++;
-  while (*argv != 0 && **argv == '-') {
-	*argv += 1;
-	while (**argv != '\0') {
-		switch (**argv) {
-		    case 'd':	d_flag = 1;	break;
-		    case 'g':	g_flag = 1;	break;
-		    case 'n':	n_flag = 1;	break;
-		    case 'o':	o_flag = 1;	break;
-		    case 'p':	p_flag = 1;	break;
-		    case 'r':	r_flag = 1;	break;
-		    case 'u':	u_flag = 1;	break;
-		    default:
-			fprintf(stderr, "illegal flag: -%c\n", **argv);
-			exit(-1);
-		}
-		*argv += 1;
-	}
-	argv++;
-  }
-  setbuf(stdin, io_buf);
-  if (*argv == 0)
-	nm(A_OUT);
-  else
-	while (*argv != 0) {
-		nm(*argv);
-		argv++;
-	}
-  return(0);
-}
-
-int nm_sort(tmp_stbl1, tmp_stbl2)
-_CONST void *tmp_stbl1, *tmp_stbl2;
-{
-
-  struct nlist *stbl1 = (struct nlist *)tmp_stbl1;
-  struct nlist *stbl2 = (struct nlist *)tmp_stbl2;
-  int cmp;
-
-  if (n_flag) {			/* sort numerically */
-	if ((stbl1->n_sclass & N_SECT) <
-	    (stbl2->n_sclass & N_SECT))
-		cmp = -1;
-	else if ((stbl1->n_sclass & N_SECT) >
-		 (stbl2->n_sclass & N_SECT))
-		cmp = 1;
-	else if (stbl1->n_value < stbl2->n_value)
-		cmp = -1;
-	else if (stbl1->n_value > stbl2->n_value)
-		cmp = 1;
-	else
-		cmp = strncmp(stbl1->n_name, stbl2->n_name, (size_t)8);
-  } else {
-	cmp = strncmp(stbl1->n_name, stbl2->n_name, (size_t)8);
-	if (cmp == 0) {
-		if (stbl1->n_value < stbl2->n_value)
-			cmp = -1;
-		else if (stbl1->n_value > stbl2->n_value)
-			cmp = 1;
-	}
-  }
-
-  if (r_flag) cmp = -cmp;	/* reverse sort */
-  return(cmp);
-}
-
-void nm(file)
-char *file;
-{
-  struct nlist *stbl;
-  int fd;
-
-  fd = open(file, O_RDONLY);
-  if (fd == -1) {
-	fprintf(stderr, "can't open %s\n", file);
-	return;
-  }
-  if (read_header(fd)) {
-	fprintf(stderr, "%s: no executable file\n", file);
-	close(fd);
-	return;
-  }
-  if (header.a_syms == 0) {
-	close(fd);
-	return;
-  }
-  if ((size_t) header.a_syms != header.a_syms) {
-	fprintf(stderr, "%s: symbol table too large to allocate\n", file);
-	close(fd);
-	return;
-  }
-  if ((int) header.a_syms != header.a_syms) {
-	/* This is necessary because we are too lazy to iterate the read. */
-	fprintf(stderr, "%s: symbol table too large to read\n", file);
-	close(fd);
-	return;
-  }
-  stbl = (struct nlist *) malloc((size_t) header.a_syms);
-  if (stbl == NULL) {
-	fprintf(stderr, "%s: can't allocate symbol table\n", file);
-	close(fd);
-	return;
-  }
-  if (read(fd, (char *) stbl, (unsigned) header.a_syms) != header.a_syms) {
-	fprintf(stderr, "%s: can't read symbol table\n", file);
-	free(stbl);
-	close(fd);
-	return;
-  }
-  stbl_elems = (int) header.a_syms / sizeof(struct nlist);
-  if (!p_flag) qsort(stbl, (size_t)stbl_elems, sizeof(struct nlist), nm_sort);
-  nm_print(file, stbl);
-  free(stbl);
-  close(fd);
-}
-
-int read_header(fd)
-int fd;
-{
-  if (read(fd, (char *) &header, sizeof(struct exec)) != sizeof(struct exec))
-	return(1);
-  if (BADMAG(header)) return(1);
-  lseek(fd, A_SYMPOS(header), SEEK_SET);
-
-  return(0);
-}
-
-void nm_print(file, stbl)
-char *file;
-register struct nlist *stbl;
-{
-  struct nlist *last;
-  char name[9];
-  int n_sclass;
-  char type;
-
-  name[8] = '\0';
-  if (!o_flag) printf("%s:\n", file);
-  for (last = &stbl[stbl_elems]; stbl != last; stbl++) {
-	if (g_flag && (stbl->n_sclass & N_CLASS) != C_EXT) continue;
-	if (u_flag && (stbl->n_sclass & N_SECT) != N_UNDF) continue;
-
-	n_sclass = stbl->n_sclass & N_SECT;
-	if (n_sclass == N_ABS)
-		type = 'a';
-	else if (n_sclass == N_TEXT)
-		type = 't';
-	else if (n_sclass == N_DATA)
-		type = 'd';
-	else if (n_sclass == N_BSS)
-		type = 'b';
-	else
-		type = 'u';
-	if ((stbl->n_sclass & N_CLASS) == C_EXT) type += 'A' - 'a';
-	strncpy(name, stbl->n_name, (size_t)8);
-	if (d_flag) {
-		/* Offsets in decimal. */
-		if (o_flag) 
-		       printf("%s:%08ld %c %s\n",file,stbl->n_value,type,name);
-		else
-		       printf("%08ld %c %s\n", stbl->n_value, type, name);
-	} else {
-		/* Offsets in hex. */
-		if (o_flag) 
-		       printf("%s:%08lx %c %s\n",file,stbl->n_value,type,name);
-		else
-		       printf("%08lx %c %s\n", stbl->n_value, type, name);
-	}
-  }
-}
Index: trunk/minix/commands/simple/nonamed.c
===================================================================
--- trunk/minix/commands/simple/nonamed.c	(revision 9)
+++ 	(revision )
@@ -1,2173 +1,0 @@
-/*	nonamed - Not a name daemon, but plays one on TV.
- *							Author: Kees J. Bot
- *								29 Nov 1994
- */
-static const char version[] = "2.7";
-
-/* Use the file reading gethostent() family of functions. */
-#define sethostent	_sethostent
-#define gethostent	_gethostent
-#define endhostent	_endhostent
-
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <stdio.h>
-#include <syslog.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <time.h>
-#include <limits.h>
-#include <signal.h>
-#include <assert.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/asynchio.h>
-#include <net/hton.h>
-#include <net/netlib.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/nameser.h>
-#include <net/gen/resolv.h>
-#include <net/gen/netdb.h>
-#include <net/gen/socket.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_hdr.h>
-#include <net/gen/udp_io.h>
-#include <net/gen/dhcp.h>
-
-#include <minix/paths.h>
-
-#define HTTL	  	3600L	/* Default time to live for /etc/hosts data. */
-#define SHORT_TIMEOUT	   2	/* If you expect an answer soon. */
-#define MEDIUM_TIMEOUT	   4	/* Soon, but not that soon. */
-#define LONG_TIMEOUT	 300	/* For stream connections to a real named. */
-#define N_IDS		 256	/* Keep track of this many queries. */
-#define N_DATAMAX (4096*sizeof(char *))	/* Default response cache size. */
-#define N_NAMEDS	   8	/* Max # name daemons we can keep track of. */
-#define NO_FD		(-1)	/* No name daemon channel here. */
-#define T_NXD	((u16_t) -1)	/* A "type" signalling a nonexistent domain. */
-
-/* Can't do async I/O under standard Minix, so forget about TCP. */
-#define DO_TCP (__minix_vmd || !__minix)
-
-/* Host data, file to store our process id in, our cache, DHCP's cache. */
-static char HOSTS[]=	_PATH_HOSTS;
-static char PIDFILE[]=	"/usr/run/nonamed.pid";
-static char NNCACHE[]=	"/usr/adm/nonamed.cache";
-static char DHCPCACHE[]= _PATH_DHCPCACHE;
-
-/* Magic string to head the cache file. */
-static char MAGIC[4]=	"NND\2";
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-#define between(a, c, z) ((unsigned) ((c) - (a)) <= (unsigned) ((z) - (a)))
-
-/* The start of time and the far future. */
-#define IMMEDIATE	((time_t) 0)
-#define NEVER		((time_t) ((time_t) -1 < 0 ? LONG_MAX : ULONG_MAX))
-
-static unsigned debug;		/* Debug level. */
-static time_t now;		/* Current time. */
-static u32_t stale;		/* Extension time for stale data. */
-static u32_t httl;		/* TTL for /etc/hosts data. */
-static int reinit, done;	/* Reinit config / program is done. */
-static int single;		/* Run single on a nondefault interface. */
-static int localonly;		/* Only accept local queries. */
-#define LOCALHOST	0x7F000001
-
-static void report(const char *label)
-{
-    fprintf(stderr, "nonamed: %s: %s\n", label, strerror(errno));
-}
-
-static void fatal(const char *label)
-{
-    report(label);
-    if (debug >= 3) { fflush(nil); abort(); }
-    exit(1);
-}
-
-static void *allocate(void *mem, size_t size)
-{
-    if ((mem= realloc(mem, size)) == nil) fatal("malloc()");
-    return mem;
-}
-
-static void deallocate(void *mem)
-{
-    free(mem);
-}
-
-static char *timegmt(time_t t)
-/* Simple "time in seconds to GMT time today" converter. */
-{
-    unsigned h, m, s;
-    static char asctime[sizeof("00:00:00")];
-
-    s= t % 60;
-    t /= 60;
-    m= t % 60;
-    t /= 60;
-    h= t % 24;
-    sprintf(asctime, "%02u:%02u:%02u", h, m, s);
-    return asctime;
-}
-
-static char *nowgmt(void)
-{
-    return timegmt(now);
-}
-
-#define PC(n)	((void) sizeof(char [sizeof(*(n)) == 1]), (char *) (n))
-#define namecpy(n1, n2)		strcpy(PC(n1), PC(n2))
-#define namecat(n1, n2)		strcat(PC(n1), PC(n2))
-#define namechr(n, c)		((u8_t *) strchr(PC(n), (c)))
-#define namecmp(n1, n2)		strcasecmp(PC(n1), PC(n2))
-#define namencmp(n1, n2, len)	strncasecmp(PC(n1), PC(n2), len)
-
-typedef struct dns {		/* A DNS packet. */
-	dns_hdr_t	hdr;		/* DNS header. */
-	u8_t		data[PACKETSZ - sizeof(dns_hdr_t)];	/* DNS data. */
-} dns_t;
-
-/* Addres of DNS packet to octet address, or vv. */
-#define dns2oct(dp)		((u8_t *) (dp))
-#define oct2dns(dp)		((dns_t *) (dp))
-
-typedef struct query {		/* One cached answer to a query. */
-	struct query	*less;		/* Less recently used. */
-	struct query	*more;		/* More recently used. */
-	time_t		age;		/* Time it was added. */
-	time_t		stale;		/* Time it goes stale by TTL. */
-	u16_t		usage;		/* Counts of queries answered. */
-	u8_t		flags;		/* QF_REFRESH. */
-	size_t		size;		/* Size of DNS packet. */
-	dns_t		dns;		/* Answer to query as a DNS packet. */
-} query_t;
-
-#define QF_REFRESH	0x01		/* This stale data must be refreshed. */
-#define QU_SHIFT	1		/* To shift usage by when evicting. */
-
-/* Size of new query_t or existing query_t. */
-#define query_allocsize(dnssize)	(offsetof(query_t, dns) + (dnssize))
-#define query_size(qp)			query_allocsize((qp)->size)
-
-static query_t *mru, *lru;	/* Most and least recently used answers. */
-static int q_refresh;		/* Set when an entry needs refreshing. */
-
-static void pack16(u8_t *buf, u16_t s)
-/* Pack a 16 bit value into a byte array. */
-{
-    buf[0]= ((u8_t *) &s)[0];
-    buf[1]= ((u8_t *) &s)[1];
-}
-
-static void pack32(u8_t *buf, u32_t l)
-/* Pack a 32 bit value into a byte array. */
-{
-    buf[0]= ((u8_t *) &l)[0];
-    buf[1]= ((u8_t *) &l)[1];
-    buf[2]= ((u8_t *) &l)[2];
-    buf[3]= ((u8_t *) &l)[3];
-}
-
-static u16_t upack16(u8_t *buf)
-/* Unpack a 16 bit value from a byte array. */
-{
-    u16_t s;
-
-    ((u8_t *) &s)[0]= buf[0];
-    ((u8_t *) &s)[1]= buf[1];
-    return s;
-}
-
-static u32_t upack32(u8_t *buf)
-/* Unpack a 32 bit value from a byte array. */
-{
-    u32_t l;
-
-    ((u8_t *) &l)[0]= buf[0];
-    ((u8_t *) &l)[1]= buf[1];
-    ((u8_t *) &l)[2]= buf[2];
-    ((u8_t *) &l)[3]= buf[3];
-    return l;
-}
-
-/* Encoding of RRs: i(paddr), d(omain), l(ong), c(har), s(tring), (s)h(ort). */
-static char *encoding[] = {
-	"c*",		/* anything unknown is c* */
-	"i",		/* A */
-	"d",		/* NS */
-	"d",		/* MD */
-	"d",		/* MF */
-	"d",		/* CNAME */
-	"ddlllll",	/* SOA */
-	"d",		/* MB */
-	"d",		/* MG */
-	"d",		/* MR */
-	"c*",		/* NULL */
-	"icc*",		/* WKS */
-	"d",		/* PTR */
-	"ss",		/* HINFO */
-	"dd",		/* MINFO */
-	"hd",		/* MX */
-	"s*",		/* TXT */
-};
-
-static char *itoa(char *fmt, u32_t i)
-{
-    static char output[32 + 3 * sizeof(i)];
-
-    sprintf(output, fmt, (unsigned long) i);
-    return output;
-}
-
-static char *classname(unsigned class)
-/* Class name of a resource record, for debug purposes. */
-{
-    static char *classes[] = { "IN", "CS", "CHAOS", "HS" };
-
-    if ((class - C_IN) < arraysize(classes)) return classes[class - C_IN];
-    return itoa("C_%u", class);
-}
-
-static char *typename(unsigned type)
-/* Type name of a resource record, for debug purposes. */
-{
-    static char type_A[][6] = {
-	"A", "NS", "MD", "MF", "CNAME", "SOA", "MB", "MG", "MR", "NULL",
-	"WKS", "PTR", "HINFO", "MINFO", "MX", "TXT",
-    };
-    static char type_AXFR[][6] = {
-	"AXFR", "MAILB", "MAILA", "ANY",
-    };
-    if ((type - T_A) < arraysize(type_A)) return type_A[type - T_A];
-    if ((type - T_AXFR) < arraysize(type_AXFR)) return type_AXFR[type - T_AXFR];
-    return itoa("T_%u", type);
-}
-
-static int print_qrr(dns_t *dp, size_t size, u8_t *cp0, int q)
-/* Print a query (q) or resource record (!q) from 'cp0' in a DNS packet for
- * debug purposes.  Return number of bytes skipped or -1 on error.
- */
-{
-    u8_t name[MAXDNAME+1];
-    u8_t *cp;
-    char *ep;
-    u8_t *dlim, *rlim;
-    u16_t type, class, rdlength;
-    u32_t ttl;
-    int r;
-
-    cp= cp0;
-    dlim= dns2oct(dp) + size;
-    r= dn_expand(dns2oct(dp), dlim, cp, name, MAXDNAME);
-    if (r == -1) return -1;
-    cp += r;
-    if (cp + 2 * sizeof(u16_t) > dlim) return -1;
-    type= ntohs(upack16(cp));
-    cp += sizeof(u16_t);
-    class= ntohs(upack16(cp));
-    cp += sizeof(u16_t);
-    printf("%-25s", (char *) name);
-    if (q) {
-	/* We're just printing a query segment, stop right here. */
-	printf(" %8s", classname(class));
-	printf(" %-5s", typename(type));
-	return cp - cp0;
-    }
-    if (cp + sizeof(u32_t) + sizeof(u16_t) > dlim) return -1;
-    ttl= ntohl(upack32(cp));
-    cp += sizeof(u32_t);
-    rdlength= ntohs(upack16(cp));
-    cp += sizeof(u16_t);
-    if (cp + rdlength > dlim) return -1;
-    rlim = cp + rdlength;
-    printf(" %5lu", (unsigned long) ttl);
-    printf(" %s", classname(class));
-    printf(" %-5s", typename(type));
-    ep= type < arraysize(encoding) ? encoding[type] : encoding[0];
-    while (*ep != 0) {
-	switch (*ep++) {
-	case 'i':
-	    if (cp + sizeof(u32_t) > rlim) return -1;
-	    printf(" %s", inet_ntoa(upack32(cp)));
-	    cp += sizeof(u32_t);
-	    break;
-	case 'l':
-	    if (cp + sizeof(u32_t) > rlim) return -1;
-	    printf(" %ld", (long)(i32_t) ntohl(upack32(cp)));
-	    cp += sizeof(u32_t);
-	    break;
-	case 'd':
-	    r= dn_expand(dns2oct(dp), dlim, cp, name, MAXDNAME);
-	    if (r == -1) return -1;
-	    printf(" %s", (char *) name);
-	    cp += r;
-	    break;
-	case 'c':
-	    if (cp >= rlim) return -1;
-	    printf(" %02X", *cp++);
-	    break;
-	case 's':
-	    r= *cp + 1;
-	    if (cp + r > rlim) return -1;
-	    printf(" \"%.*s\"", *cp, (char *) (cp + 1));
-	    cp += r;
-	    break;
-	case 'h':
-	    if (cp + sizeof(u16_t) > rlim) return -1;
-	    printf(" %u", ntohs(upack16(cp)));
-	    cp += sizeof(u16_t);
-	    break;
-	}
-	if (*ep == '*') ep= cp < rlim ? ep-1 : ep+1;
-    }
-    return cp - cp0;
-}
-
-static void dns_tell(int indent, dns_t *dp, size_t size)
-/* Explain a DNS packet, for debug purposes. */
-{
-    u8_t *cp;
-    int r, i;
-    unsigned count[4];
-    static char label[4][4]= { "QD:", "AN:", "NS:", "AR:" };
-    static char rcodes[][9] = {
-	"NOERROR", "FORMERR", "SERVFAIL", "NXDOMAIN", "NOTIMP", "REFUSED"
-    };
-
-    if (size < sizeof(dns_hdr_t)) return;
-
-    printf("%*s", indent, "");
-    printf("DNS %s:", (dp->hdr.dh_flag1 & DHF_QR) ? "reply" : "query");
-    r= dp->hdr.dh_flag2 & DHF_RCODE;
-    printf(" %s", r < arraysize(rcodes) ? rcodes[r] : itoa("ERR_%lu", r));
-    if (dp->hdr.dh_flag1 & DHF_AA) printf(" AA");
-    if (dp->hdr.dh_flag1 & DHF_TC) printf(" TC");
-    if (dp->hdr.dh_flag1 & DHF_RD) printf(" RD");
-    if (dp->hdr.dh_flag2 & DHF_RA) printf(" RA");
-#ifdef DHF_AD
-    if (dp->hdr.dh_flag2 & DHF_AD) printf(" AD");
-    if (dp->hdr.dh_flag2 & DHF_CD) printf(" CD");
-#endif
-    fputc('\n', stdout);
-
-    count[0]= ntohs(dp->hdr.dh_qdcount);
-    count[1]= ntohs(dp->hdr.dh_ancount);
-    count[2]= ntohs(dp->hdr.dh_nscount);
-    count[3]= ntohs(dp->hdr.dh_arcount);
-    cp = dp->data;
-    for (i= 0; i < 4; i++) {
-	while (count[i] > 0) {
-	    printf("%*s", indent, "");
-	    printf(" %s ", label[i]);
-	    r= print_qrr(dp, size, cp, (i == 0));
-	    fputc('\n', stdout);
-	    if (r == -1) return;
-	    cp += r;
-	    count[i]--;
-	}
-    }
-}
-
-static u32_t dns_ttl(dns_t *dp, size_t size, u32_t delta)
-/* Compute the minimum TTL of all RRs in a DNS packet and subtract delta from
- * all TTLs.  (We are actually only interested in the minimum (delta = 0) or
- * the subtraction (delta > 0).  It was easier to roll this into one routine.)
- */
-{
-    u8_t *cp, *rdp, *dlim;
-    int r, i, hasttl, hassoa;
-    unsigned type, count[4];
-    u32_t ttl, minimum, minttl;
-    unsigned rcode;
-    u8_t name[MAXDNAME+1];
-
-    hasttl= hassoa= 0;
-    minttl= 365*24*3600L;
-    dlim= dns2oct(dp) + size;
-    if (size < sizeof(dns_hdr_t)) return 0;
-
-    rcode= dp->hdr.dh_flag2 & DHF_RCODE;
-    count[0]= ntohs(dp->hdr.dh_qdcount);
-    count[1]= ntohs(dp->hdr.dh_ancount);
-    count[2]= ntohs(dp->hdr.dh_nscount);
-    count[3]= ntohs(dp->hdr.dh_arcount);
-    cp = dp->data;
-    for (i= 0; i < 4 && cp < dlim; i++) {
-	while (count[i] > 0) {
-	    r= dn_expand(dns2oct(dp), dlim, cp, name, MAXDNAME);
-	    if (r == -1) break;
-	    cp += r + 2 * sizeof(u16_t);
-	    if (i != 0) {
-		if (cp + sizeof(u32_t) + sizeof(u16_t) > dlim) break;
-		type= upack16(cp - 2 * sizeof(u16_t));
-		ttl= ntohl(upack32(cp));
-		ttl= ttl < delta ? 0 : ttl - delta;
-		if (rcode == NXDOMAIN && i == 2 && type == HTONS(T_SOA)) {
-		    rdp= cp + sizeof(u32_t) + sizeof(u16_t);
-		    r= dn_expand(dns2oct(dp), dlim, rdp, name, MAXDNAME);
-		    if (r == -1) break;
-		    rdp += r;
-		    r= dn_expand(dns2oct(dp), dlim, rdp, name, MAXDNAME);
-		    if (r == -1) break;
-		    rdp += r + 4 * sizeof(u32_t);
-		    if (rdp + sizeof(u32_t) > dlim) break;
-		    minimum= ntohl(upack32(rdp));
-		    if (ttl > minimum) ttl= minimum;
-		    hassoa= 1;
-		}
-		if (delta != 0) pack32(cp, htonl(ttl));
-		if (ttl < minttl) minttl= ttl;
-		hasttl= 1;
-		cp += sizeof(u32_t);
-		cp += sizeof(u16_t) + ntohs(upack16(cp));
-	    }
-	    count[i]--;
-	}
-    }
-    return ((rcode == NOERROR && hasttl) || (rcode == NXDOMAIN && hassoa))
-		? minttl : 0;
-}
-
-/* Total cached query data. */
-static size_t n_datamax= N_DATAMAX;
-static size_t n_data;
-
-static query_t *extract_query(query_t *qp)
-/* Take a query out of the query cache. */
-{
-    assert(qp != nil);
-    *(qp->less != nil ? &qp->less->more : &lru) = qp->more;
-    *(qp->more != nil ? &qp->more->less : &mru) = qp->less;
-    n_data -= query_size(qp);
-    return qp;
-}
-
-static query_t *get_query(u8_t *name, unsigned type)
-/* Find a query and if so remove it from the cache and return it. */
-{
-    query_t *qp, *less;
-    u8_t qname[MAXDNAME+1];
-    int r;
-
-    for (qp= mru; qp != nil; qp= less) {
-	less= qp->less;
-	if (qp->stale <= now - stale) {
-	    /* This answer has expired. */
-	    deallocate(extract_query(qp));
-	} else {
-	    r= dn_expand(dns2oct(&qp->dns), dns2oct(&qp->dns) + qp->size,
-		qp->dns.data, qname, MAXDNAME);
-	    if (r == -1) continue;
-	    if (namecmp(qname, name) == 0 && upack16(qp->dns.data+r) == type) {
-		/* Found an answer to the query. */
-		return extract_query(qp);
-	    }
-	}
-    }
-    return nil;
-}
-
-static void insert_query(query_t *qp)
-/* (Re)insert a query into the cache. */
-{
-    *(qp->less != nil ? &qp->less->more : &lru) = qp;
-    *(qp->more != nil ? &qp->more->less : &mru) = qp;
-    n_data += query_size(qp);
-
-    /* Try to delete the LRU while there is too much memory in use.  If
-     * its usage count is too high then it gets a second chance.
-     */
-    while (n_data > n_datamax && lru != nil) {
-	if ((lru->usage >>= QU_SHIFT) == 0 || lru->stale <= now - stale) {
-	    deallocate(extract_query(lru));
-	} else {
-	    lru->less= mru;	/* Make list circular. */
-	    mru->more= lru;
-	    mru= lru;		/* Move one over, making LRU the MRU. */
-	    lru= lru->more;
-	    lru->less= nil;	/* Break the circle. */
-	    mru->more= nil;
-	}
-    }
-
-    if (debug >= 2) {
-	unsigned n= 0;
-	for (qp= mru; qp != nil; qp= qp->less) n++;
-	printf("%u cached repl%s, %u bytes, sbrk(0) = %u\n",
-	    n, n == 1 ? "y" : "ies",
-	    (unsigned) n_data,
-	    (unsigned) sbrk(0));
-    }
-}
-
-static void put_query(query_t *qp)
-/* Add a new query to the cache as the MRU. */
-{
-    qp->less= mru;
-    qp->more= nil;
-    insert_query(qp);
-}
-
-static void cache2file(void)
-/* Store the cached data into the cache file. */
-{
-    FILE *fp;
-    query_t *qp;
-    u8_t data[4+1+2+2];
-    u16_t usage;
-    char newcache[sizeof(NNCACHE) + sizeof(".new")];
-
-    if (single) return;
-
-    strcpy(newcache, NNCACHE);
-    strcat(newcache, ".new");
-
-    if ((fp= fopen(newcache, "w")) == nil) {
-	if ((errno != ENOENT && errno != EROFS) || debug >= 2) report(newcache);
-	return;
-    }
-    if (debug >= 2) printf("Writing %s:\n", newcache);
-
-    /* Magic number: */
-    fwrite(MAGIC, 1, sizeof(MAGIC), fp);
-
-    for (qp= lru; qp != nil; qp= qp->more) {
-	if (qp->stale <= now - stale) continue;
-	if (debug >= 2) {
-	    printf("Usage = %u, Age = %ld, Flags = %02X:\n",
-		qp->usage, (long) (now - qp->age), qp->flags);
-	    dns_tell(2, &qp->dns, qp->size);
-	}
-	pack32(data+0, htonl(qp->age));
-	data[4]= qp->flags;
-	pack16(data+5, htons(qp->size));
-	pack16(data+7, htons(qp->usage));
-	fwrite(data, 1, sizeof(data), fp);
-	fwrite(&qp->dns, 1, qp->size, fp);
-	if (ferror(fp)) break;
-    }
-
-    if (ferror(fp) || fclose(fp) == EOF) {
-	report(newcache);
-	(void) unlink(newcache);
-	return;
-    }
-
-    if (debug >= 2) printf("mv %s %s\n", newcache, NNCACHE);
-    if (rename(newcache, NNCACHE) < 0) {
-	fprintf(stderr, "nonamed: mv %s %s: %s\n",
-	    newcache, NNCACHE, strerror(errno));
-	(void) unlink(newcache);
-    }
-}
-
-static void file2cache(void)
-/* Read cached data from the cache file. */
-{
-    query_t *qp;
-    FILE *fp;
-    u8_t data[4+1+2+2];
-    size_t dlen;
-
-    if (single) return;
-
-    if ((fp= fopen(NNCACHE, "r")) == nil) {
-	if (errno != ENOENT || debug >= 2) report(NNCACHE);
-	return;
-    }
-    if (debug >= 2) printf("Reading %s:\n", NNCACHE);
-
-    /* Magic number? */
-    fread(data, 1, sizeof(MAGIC), fp);
-    if (ferror(fp) || memcmp(MAGIC, data, sizeof(MAGIC)) != 0) goto err;
-
-    for (;;) {
-	fread(data, 1, sizeof(data), fp);
-	if (feof(fp) || ferror(fp)) break;
-	dlen= ntohs(upack16(data+5));
-	qp= allocate(nil, query_allocsize(dlen));
-	qp->age= htonl(upack32(data+0));
-	qp->flags= data[4];
-	if (qp->flags & QF_REFRESH) q_refresh= 1;
-	qp->size= dlen;
-	qp->usage= htons(upack16(data+7));
-	fread(&qp->dns, 1, qp->size, fp);
-	if (feof(fp) || ferror(fp)) {
-	    deallocate(qp);
-	    goto err;
-	}
-	qp->stale= qp->age + dns_ttl(&qp->dns, dlen, 0);
-	if (debug >= 2) {
-	    printf("Usage = %u, Age = %ld, Flags = %02X:\n",
-		qp->usage, (long) (now - qp->age), qp->flags);
-	    dns_tell(2, &qp->dns, dlen);
-	}
-	put_query(qp);
-    }
-    if (ferror(fp)) {
-    err:
-	/* The cache file did not end at EOF or is otherwise a mess. */
-	fprintf(stderr, "nonamed: %s: %s\n", NNCACHE,
-		ferror(fp) ? strerror(errno) : "Corrupt");
-	while (lru != nil) deallocate(extract_query(lru));
-    }
-    fclose(fp);
-}
-
-typedef int handler_t(void *data, int expired);
-
-/* All actions are in the form of "jobs". */
-typedef struct job {
-	struct job	*next, **prev;	/* To make a job queue. */
-	handler_t	*handler;	/* Function to handle this job. */
-	time_t		timeout;	/* Moment it times out. */
-	void		*data;		/* Data associated with the job. */
-} job_t;
-
-static job_t *queue;		/* Main job queue. */
-
-static void newjob(handler_t *handler, time_t timeout, void *data)
-/* Create a new job with the given handler, timeout time and data. */
-{
-    job_t *job, **prev;
-
-    job= allocate(nil, sizeof(*job));
-    job->handler= handler;
-    job->timeout= timeout;
-    job->data= data;
-
-    for (prev= &queue; *prev != nil; prev= &(*prev)->next) {
-	if (job->timeout < (*prev)->timeout) break;
-    }
-    job->next= *prev;
-    job->prev= prev;
-    *prev= job;
-    if (job->next != nil) job->next->prev= &job->next;
-}
-
-static int execjob(job_t *job, int expired)
-/* Execute a job by calling the handler.  Remove the job if it returns true,
- * indicating that it is done.  Expired is set if the job timed out.  It is
- * otherwise called to check for I/O.
- */
-{
-    if ((*job->handler)(job->data, expired)) {
-	*job->prev= job->next;
-	if (job->next != nil) job->next->prev= job->prev;
-	deallocate(job);
-	return 1;
-    }
-    return 0;
-}
-
-static void force_expire(handler_t *handler)
-/* Force jobs to expire immediately, the named searcher for instance. */
-{
-    job_t *job, **prev= &queue;
-
-    while ((job= *prev) != nil) {
-	if (job->handler == handler && job->timeout != IMMEDIATE) {
-	    *prev= job->next;
-	    if (job->next != nil) job->next->prev= prev;
-	    newjob(job->handler, IMMEDIATE, job->data);
-	    deallocate(job);
-	} else {
-	    prev= &job->next;
-	}
-    }
-}
-
-static int nxdomain(u8_t *name)
-/* True iff the two top level components in a name are repeated in the name,
- * or if in-addr.arpa is found within a name.  Such things happen often in a
- * search for an already fully qualified local name.  For instance:
- * flotsam.cs.vu.nl.cs.vu.nl.  (We don't want this at boot time.)
- */
-{
-    u8_t *end, *top, *p;
-    size_t n;
-
-    end= namechr(name, 0);
-    top= end;
-    while (top > name && *--top != '.') {}
-    while (top > name && *--top != '.') {}
-    n= end - top;
-    p= top;
-    for (;;) {
-	if (p == name) return 0;
-	if (*--p == '.') {
-	    if (namencmp(p, top, n) == 0 && p[n] == '.') return 1;
-	    if (namencmp(p, ".in-addr.arpa.", 14) == 0) return 1;
-	}
-    }
-}
-
-typedef struct id2id {
-	u16_t		id;		/* ID of old query. */
-	u16_t		port;		/* Reply port. */
-	ipaddr_t	ip;		/* Reply address. */
-} id2id_t;
-
-static id2id_t id2id[N_IDS];
-static u16_t id_counter;
-
-static u16_t new_id(u16_t in_id, u16_t in_port, ipaddr_t in_ip)
-/* An incoming UDP query must be relabeled with a new ID before it can be
- * send on to a real name daemon.
- */
-{
-    id2id_t *idp;
-    u16_t id;
-
-    id= id_counter++;
-    idp= &id2id[id % N_IDS];
-    idp->id= in_id;
-    idp->port= in_port;
-    idp->ip= in_ip;
-    return htons(id);
-}
-
-static int old_id(u16_t id, u16_t *out_id, u16_t *out_port, ipaddr_t *out_ip)
-/* Translate a reply id back to the id, port, and address used in the query.
- * Return true if the translation is possible.
- */
-{
-    id= ntohs(id);
-    if ((u16_t) (id_counter - id) > N_IDS) {
-	/* Too old. */
-	return 0;
-    } else {
-	/* We know this one. */
-	id2id_t *idp= &id2id[id % N_IDS];
-
-	if (idp->port == 0) return 0;	/* Named is trying to fool us? */
-	*out_id= idp->id;
-	*out_port= idp->port;
-	*out_ip= idp->ip;
-	idp->port= 0;
-	return 1;
-    }
-}
-
-/* IDs used to mark my own queries to name servers, must be new_id translated
- * to make them unique "on the wire".
- */
-#define ID_IPSELF	HTONL(0)	/* "I did it myself" address. */
-#define ID_PROBE	HTONS(0)	/* Name server probe. */
-#define ID_REFRESH	HTONS(1)	/* Query to refresh a cache entry. */
-
-static char *tcp_device, *udp_device;	/* TCP and UDP device names. */
-static int udp_fd;			/* To send or receive UDP packets. */
-static asynchio_t asyn;			/* For I/O in progress. */
-static ipaddr_t my_ip;			/* My IP address. */
-static u16_t my_port, named_port;	/* Port numbers, normally "domain". */
-
-static ipaddr_t named[N_NAMEDS];	/* Addresses of all name servers. */
-static unsigned n_nameds;		/* Number of configured name daemons. */
-static unsigned i_named;		/* Index to current name server. */
-static int expect;			/* Set when we expect an answer. */
-static int search_ct= -1;		/* Named search count and state. */
-static int dirty;			/* True when new entry put in cache. */
-
-#define current_named()		(+named[i_named])
-#define searching()		(search_ct > 0)
-#define start_searching()	((void) (search_ct= -1))
-#define stop_searching()	((void) (search_ct= 0))
-#define expecting()		(+expect)
-#define start_expecting()	((void) (expect= 1))
-#define stop_expecting()	((void) (expect= 0))
-
-static time_t filetime(const char *file)
-/* Get the modified time of a file. */
-{
-    struct stat st;
-
-    return stat(file, &st) == 0 ? st.st_mtime : 0;
-}
-
-static void init_config(ipaddr_t ifip)
-/* Read name daemon list and other special stuff from the hosts file. */
-{
-    struct hostent *he;
-    u32_t nip, hip;
-    static time_t hosts_time, dhcp_time;
-    time_t ht, dt;
-
-    /* See if anything really changed. */
-    if (((ifip ^ HTONL(LOCALHOST)) & HTONL(0xFF000000)) == 0) ifip= my_ip;
-    ht= filetime(HOSTS);
-    dt= filetime(DHCPCACHE);
-    if (ifip == my_ip && ht == hosts_time && dt == dhcp_time) return;
-    my_ip= ifip;
-    hosts_time= ht;
-    dhcp_time= dt;
-
-    if (debug >= 2) {
-	printf("%s: I am nonamed %s at %s:%u\n",
-	    nowgmt(), version, inet_ntoa(my_ip), ntohs(my_port));
-    }
-
-    httl= HTONL(HTTL);
-    stale= 0;
-    n_nameds= 0;
-
-    if (!single) {
-	sethostent(0);
-	while ((he= gethostent()) != nil) {
-	    memcpy(&nip, he->h_addr, sizeof(u32_t));
-	    hip= ntohl(nip);
-	    if (namecmp(he->h_name, "%ttl") == 0) httl= nip;
-	    if (namecmp(he->h_name, "%stale") == 0) stale= hip;
-	    if (namecmp(he->h_name, "%memory") == 0) n_datamax= hip;
-	    if (namecmp(he->h_name, "%nameserver") == 0) {
-		if (nip != my_ip || named_port != my_port) {
-		    if (n_nameds < N_NAMEDS) named[n_nameds++]= nip;
-		}
-	    }
-	}
-	endhostent();
-    }
-
-    if (n_nameds == 0) {
-	/* No name daemons found in the host file.  What about DHCP? */
-	int fd;
-	dhcp_t d;
-	ssize_t r;
-	u8_t *data;
-	size_t len;
-
-	if ((fd= open(DHCPCACHE, O_RDONLY)) < 0) {
-	    if (errno != ENOENT) fatal(DHCPCACHE);
-	} else {
-	    while ((r= read(fd, &d, sizeof(d))) == sizeof(d)) {
-		if (d.yiaddr == my_ip) break;
-	    }
-	    if (r < 0) fatal(DHCPCACHE);
-	    close(fd);
-
-	    if (r == sizeof(d) && dhcp_gettag(&d, DHCP_TAG_DNS, &data, &len)) {
-		while (len >= sizeof(nip)) {
-		    memcpy(&nip, data, sizeof(nip));
-		    data += sizeof(nip);
-		    len -= sizeof(nip);
-		    if (nip != my_ip || named_port != my_port) {
-			if (n_nameds < N_NAMEDS) named[n_nameds++]= nip;
-		    }
-		}
-	    }
-	}
-    }
-    i_named= 0;
-}
-
-static handler_t job_save_cache, job_read_udp, job_find_named, job_expect_named;
-#if DO_TCP
-static handler_t job_setup_listen, job_listen, job_setup_connect, job_connect;
-static handler_t job_read_query, job_write_query;
-static handler_t job_read_reply, job_write_reply;
-#endif
-
-static int query_hosts(u8_t *qname, unsigned type, dns_t *dp, size_t *pdlen)
-/* Read the /etc/hosts file to try and answer an A or PTR query.  Return
- * true iff an answer can be found, with the answer copied to *dp.
- */
-{
-    struct hostent *he;
-    int i, r;
-    dns_t dns;
-    u8_t *domain;
-    u8_t *cp;
-    u8_t name[MAXDNAME+1];
-    u8_t *dnvec[40];
-    unsigned ancount;
-    struct hostent localhost;
-    static char *noaliases[]= { nil };
-    static ipaddr_t localaddr= HTONL(LOCALHOST);
-    static char *localaddrlist[]= { (char *) &localaddr, nil };
-
-    if (single) return 0;
-
-    /* Assume we can answer. */
-    dns.hdr.dh_flag1= DHF_QR | DHF_AA;
-    dns.hdr.dh_flag2= DHF_RA;
-    dns.hdr.dh_qdcount= HTONS(1);
-    ancount= 0;
-    dns.hdr.dh_nscount= HTONS(0);
-    dns.hdr.dh_arcount= HTONS(0);
-
-    dnvec[0]= dns2oct(&dns);
-    dnvec[1]= nil;
-    cp= dns.data;
-    r= dn_comp(qname, cp, arraysize(dns.data), dnvec, arraylimit(dnvec));
-    if (r == -1) return 0;
-    cp += r;
-    pack16(cp, type);
-    cp += sizeof(u16_t);
-    pack16(cp, HTONS(C_IN));
-    cp += sizeof(u16_t);
-
-    /* Localhost is fixed to 127.0.0.1. */
-    localhost.h_name=
-	namencmp(qname, "localhost.", 10) == 0 ? (char *) qname : "localhost";
-    localhost.h_aliases= noaliases;
-    localhost.h_addr_list= localaddrlist;
-    he= &localhost;
-
-    sethostent(0);
-    do {
-	switch (type) {
-	case HTONS(T_A):
-	    if (namecmp(qname, he->h_name) == 0) {
-	      addA:
-		r= dn_comp((u8_t *) he->h_name, cp, arraylimit(dns.data) - cp,
-		    dnvec, arraylimit(dnvec));
-		if (r == -1) return 0;
-		cp += r;
-		if (cp + 3 * sizeof(u16_t) + 2 * sizeof(u32_t)
-		    > arraylimit(dns.data)) { r= -1; break; }
-		pack16(cp, HTONS(T_A));
-		cp += sizeof(u16_t);
-		pack16(cp, HTONS(C_IN));
-		cp += sizeof(u16_t);
-		pack32(cp, httl);
-		cp += sizeof(u32_t);
-		pack16(cp, HTONS(sizeof(u32_t)));
-		cp += sizeof(u16_t);
-		memcpy(cp, he->h_addr, sizeof(u32_t));
-		cp += sizeof(u32_t);
-		ancount++;
-		break;
-	    }
-	    /*FALL THROUGH*/
-	case HTONS(T_CNAME):
-	    domain= namechr(he->h_name, '.');
-	    for (i= 0; he->h_aliases[i] != nil; i++) {
-		namecpy(name, he->h_aliases[i]);
-		if (domain != nil && namechr(name, '.') == nil) {
-		    namecat(name, domain);
-		}
-		if (namecmp(qname, name) == 0) {
-		    r= dn_comp(name, cp, arraylimit(dns.data) - cp,
-			dnvec, arraylimit(dnvec));
-		    if (r == -1) break;
-		    cp += r;
-		    if (cp + 3 * sizeof(u16_t)
-			+ 1 * sizeof(u32_t) > arraylimit(dns.data)) return 0;
-		    pack16(cp, HTONS(T_CNAME));
-		    cp += sizeof(u16_t);
-		    pack16(cp, HTONS(C_IN));
-		    cp += sizeof(u16_t);
-		    pack32(cp, httl);
-		    cp += sizeof(u32_t);
-		    /* pack16(cp, htonl(RDLENGTH)) */
-		    cp += sizeof(u16_t);
-		    r= dn_comp((u8_t *) he->h_name, cp,
-			arraylimit(dns.data) - cp,
-			dnvec, arraylimit(dnvec));
-		    if (r == -1) break;
-		    pack16(cp - sizeof(u16_t), htons(r));
-		    cp += r;
-		    ancount++;
-		    if (type == HTONS(T_A)) goto addA;	/* really wants A */
-		    break;
-		}
-	    }
-	    break;
-	case HTONS(T_PTR):
-	    if (ancount > 0) break;
-	    if (he->h_name[0] == '%') break;
-	    sprintf((char *) name, "%d.%d.%d.%d.in-addr.arpa",
-		    ((u8_t *) he->h_addr)[3],
-		    ((u8_t *) he->h_addr)[2],
-		    ((u8_t *) he->h_addr)[1],
-		    ((u8_t *) he->h_addr)[0]);
-	    if (namecmp(qname, name) == 0) {
-		r= dn_comp(name, cp, arraylimit(dns.data) - cp,
-		    dnvec, arraylimit(dnvec));
-		if (r == -1) break;
-		cp += r;
-		if (cp + 3 * sizeof(u16_t) + 1 * sizeof(u32_t)
-		    > arraylimit(dns.data)) { r= -1; break; }
-		pack16(cp, HTONS(T_PTR));
-		cp += sizeof(u16_t);
-		pack16(cp, HTONS(C_IN));
-		cp += sizeof(u16_t);
-		pack32(cp, httl);
-		cp += sizeof(u32_t);
-		/* pack16(cp, htonl(RDLENGTH)) */
-		cp += sizeof(u16_t);
-		r= dn_comp((u8_t *) he->h_name, cp,
-		    arraylimit(dns.data) - cp, dnvec, arraylimit(dnvec));
-		if (r == -1) return 0;
-		pack16(cp - sizeof(u16_t), htons(r));
-		cp += r;
-		ancount++;
-	    }
-	    break;
-	}
-    } while (r != -1 && (he= gethostent()) != nil);
-    endhostent();
-
-    if (r == -1 || ancount == 0) return 0;
-
-    dns.hdr.dh_ancount= htons(ancount);
-    memcpy(dp, &dns, *pdlen= cp - dns2oct(&dns));
-    return 1;
-}
-
-static int query_chaos(u8_t *qname, unsigned type, dns_t *dp, size_t *pdlen)
-/* Report my version.  Can't let BIND take all the credit. :-) */
-{
-    int i, n, r;
-    dns_t dns;
-    u8_t *cp;
-    u8_t *dnvec[40];
-
-    if (type != HTONS(T_TXT) || namecmp(qname, "version.bind") != 0) return 0;
-
-    dns.hdr.dh_flag1= DHF_QR | DHF_AA;
-    dns.hdr.dh_flag2= DHF_RA;
-    dns.hdr.dh_qdcount= HTONS(1);
-    dns.hdr.dh_ancount= HTONS(1);
-    dns.hdr.dh_nscount= HTONS(0);
-    dns.hdr.dh_arcount= htons(n_nameds);
-
-    dnvec[0]= dns2oct(&dns);
-    dnvec[1]= nil;
-    cp= dns.data;
-    r= dn_comp(qname, cp, arraysize(dns.data), dnvec, arraylimit(dnvec));
-    if (r == -1) return 0;
-    cp += r;
-    pack16(cp, type);
-    cp += sizeof(u16_t);
-    pack16(cp, HTONS(C_CHAOS));
-    cp += sizeof(u16_t);
-
-    r= dn_comp(qname, cp, arraylimit(dns.data) - cp, dnvec, arraylimit(dnvec));
-    if (r == -1) return 0;
-    cp += r;
-    pack16(cp, HTONS(T_TXT));
-    cp += sizeof(u16_t);
-    pack16(cp, HTONS(C_CHAOS));
-    cp += sizeof(u16_t);
-    pack32(cp, HTONL(0));
-    cp += sizeof(u32_t);
-    /* pack16(cp, htonl(RDLENGTH)) */
-    cp += sizeof(u16_t);
-    sprintf((char *) cp + 1, "nonamed %s at %s:%u",
-	    version, inet_ntoa(my_ip), ntohs(my_port));
-    r= strlen((char *) cp + 1) + 1;
-    pack16(cp - sizeof(u16_t), htons(r));
-    *cp= r-1;
-    cp += r;
-    for (n= 0, i= i_named; n < n_nameds; n++, i= (i+1) % n_nameds) {
-	r= dn_comp((u8_t *) "%nameserver", cp, arraylimit(dns.data) - cp,
-	    dnvec, arraylimit(dnvec));
-	if (r == -1) return 0;
-	cp += r;
-	if (cp + 3 * sizeof(u16_t)
-	    + 2 * sizeof(u32_t) > arraylimit(dns.data)) return 0;
-	pack16(cp, HTONS(T_A));
-	cp += sizeof(u16_t);
-	pack16(cp, HTONS(C_IN));
-	cp += sizeof(u16_t);
-	pack32(cp, HTONL(0));
-	cp += sizeof(u32_t);
-	pack16(cp, HTONS(sizeof(u32_t)));
-	cp += sizeof(u16_t);
-	memcpy(cp, &named[i], sizeof(u32_t));
-	cp += sizeof(u32_t);
-    }
-
-    memcpy(dp, &dns, *pdlen= cp - dns2oct(&dns));
-    return 1;
-}
-
-static void cache_reply(dns_t *dp, size_t dlen)
-/* Store a DNS packet in the cache. */
-{
-    int r;
-    query_t *qp, *less, *more;
-    unsigned usage;
-    u16_t type;
-    u8_t *cp;
-    u8_t name[MAXDNAME];
-    u32_t minttl;
-
-    if ((dp->hdr.dh_flag1 & (DHF_RD | DHF_TC)) != DHF_RD) return;
-    if (dp->hdr.dh_qdcount != HTONS(1)) return;
-    cp= dp->data;
-    r= dn_expand(dns2oct(dp), dns2oct(dp) + dlen, cp, name, MAXDNAME);
-    if (r == -1) return;
-    cp += r;
-    type= upack16(cp);
-    cp += sizeof(u16_t);
-    if (upack16(cp) != HTONS(C_IN)) return;
-
-    /* Delete old cached data, if any.  Note where it is in the LRU. */
-    if ((qp= get_query(name, type)) != nil) {
-	less= qp->less;
-	more= qp->more;
-	usage= qp->usage;
-	deallocate(qp);
-    } else {
-	/* Not yet in the cache. */
-	less= mru;
-	more= nil;
-	usage= 1;
-    }
-
-    /* Determine minimum TTL.  Discard if zero, never cache zero TTLs. */
-    if ((minttl= dns_ttl(dp, dlen, 0)) == 0) return;
-
-    /* Enter new reply in cache. */
-    qp= allocate(nil, query_allocsize(dlen));
-    qp->less= less;
-    qp->more= more;
-    qp->age= now;
-    qp->flags= 0;
-    qp->usage= usage;
-    qp->size= dlen;
-    memcpy(&qp->dns, dp, dlen);
-    qp->stale= qp->age + minttl;
-    insert_query(qp);
-    if (debug >= 1) printf("Answer cached\n");
-
-    /* Save the cache soon. */
-    if (!dirty) {
-	dirty= 1;
-	newjob(job_save_cache, now + LONG_TIMEOUT, nil);
-    }
-}
-
-static int job_save_cache(void *data, int expired)
-/* Some time after the cache is changed it is written back to disk. */
-{
-    if (!expired) return 0;
-    cache2file();
-    dirty= 0;
-}
-
-static int compose_reply(dns_t *dp, size_t *pdlen)
-/* Try to compose a reply to a request in *dp using the hosts file or
- * cached data.  Return answer in *dp with its size in *pdlen.  Return true
- * iff an answer is given.
- */
-{
-    size_t dlen= *pdlen;
-    int r, rd;
-    query_t *qp;
-    unsigned id, type, class;
-    u8_t *cp;
-    u8_t name[MAXDNAME];
-
-    cp= dp->data;
-    r= dn_expand(dns2oct(dp), dns2oct(dp) + dlen, cp, name, MAXDNAME);
-    if (r != -1) {
-	cp += r;
-	if (cp + 2 * sizeof(u16_t) > dns2oct(dp) + dlen) {
-	    r= -1;
-	} else {
-	    type= upack16(cp);
-	    cp += sizeof(u16_t);
-	    class= upack16(cp);
-	    cp += sizeof(u16_t);
-	}
-    }
-
-    /* Remember ID and RD. */
-    id= dp->hdr.dh_id;
-    rd= dp->hdr.dh_flag1 & DHF_RD;
-
-    if (r == -1) {
-	/* Malformed query, reply "FORMERR". */
-	dp->hdr.dh_flag1 &= ~(DHF_TC);
-	dp->hdr.dh_flag1 |= DHF_QR | DHF_AA;
-	dp->hdr.dh_flag2 &= ~(DHF_UNUSED | DHF_RCODE);
-	dp->hdr.dh_flag2 |= DHF_RA | FORMERR;
-    } else
-    if (class == HTONS(C_IN) && query_hosts(name, type, dp, pdlen)) {
-	/* Answer to this query is in the hosts file. */
-	dlen= *pdlen;
-    } else
-    if (class == HTONS(C_IN) && (qp= get_query(name, type)) != nil) {
-	/* Answer to this query is present in the cache. */
-	memcpy(dp, &qp->dns, dlen= qp->size);
-	dp->hdr.dh_flag1 &= ~DHF_AA;
-	(void) dns_ttl(dp, dlen, now - qp->age);
-	if (rd) {
-	    if (qp->stale <= now) {
-		qp->flags |= QF_REFRESH;
-		q_refresh= 1;
-	    }
-	    qp->usage++;
-	}
-	put_query(qp);
-    } else
-    if (class == HTONS(C_CHAOS) && query_chaos(name, type, dp, pdlen)) {
-	/* Return our version numbers. */
-	dlen= *pdlen;
-    } else
-    if (n_nameds == 0 || nxdomain(name)) {
-	/* No real name daemon present, or this name has a repeated top level
-	 * domain sequence.  Reply "no such domain".
-	 */
-	dp->hdr.dh_flag1 &= ~(DHF_TC);
-	dp->hdr.dh_flag1 |= DHF_QR | DHF_AA;
-	dp->hdr.dh_flag2 &= ~(DHF_UNUSED | DHF_RCODE);
-	dp->hdr.dh_flag2 |= DHF_RA | NXDOMAIN;
-    } else
-    if (!rd) {
-	/* "Recursion Desired" is off, so don't bother to relay. */
-	dp->hdr.dh_flag1 &= ~(DHF_TC);
-	dp->hdr.dh_flag1 |= DHF_QR;
-	dp->hdr.dh_flag2 &= ~(DHF_UNUSED | DHF_RCODE);
-	dp->hdr.dh_flag2 |= DHF_RA | NOERROR;
-    } else {
-	/* Caller needs to consult with a real name daemon. */
-	return 0;
-    }
-
-    /* Copy ID and RD back to answer. */
-    dp->hdr.dh_id= id;
-    dp->hdr.dh_flag1 &= ~DHF_RD;
-    dp->hdr.dh_flag1 |= rd;
-    *pdlen= dlen;
-    return 1;
-}
-
-typedef struct udp_dns {	/* One DNS packet over UDP. */
-	udp_io_hdr_t	hdr;		/* UDP header (source/destination). */
-	dns_t		dns;		/* DNS packet. */
-} udp_dns_t;
-
-static void refresh_cache(void)
-/* Find a stale entry in the cache that was used to answer a query, and send
- * a request to a name server that should refresh this entry.
- */
-{
-    query_t *qp;
-    unsigned type;
-    int r;
-    u8_t *cp;
-    size_t dlen, ulen;
-    u8_t qname[MAXDNAME+1];
-    u8_t *dnvec[40];
-    udp_dns_t udp;
-
-    if (!q_refresh) return;
-    for (qp= lru; qp != nil; qp= qp->more) {
-	if ((qp->flags & QF_REFRESH) && qp->stale > now - stale) break;
-    }
-    if (qp == nil) {
-	q_refresh= 0;
-	return;
-    }
-
-    /* Found one to refresh. */
-    qp->flags &= ~QF_REFRESH;
-    r= dn_expand(dns2oct(&qp->dns), dns2oct(&qp->dns) + qp->size,
-	qp->dns.data, qname, MAXDNAME);
-    if (r == -1) return;
-    type= upack16(qp->dns.data+r);
-
-    dnvec[0]= dns2oct(&udp.dns);
-    dnvec[1]= nil;
-    cp= udp.dns.data;
-    r= dn_comp(qname, cp, arraysize(udp.dns.data), dnvec, arraylimit(dnvec));
-    if (r == -1) return;
-    cp += r;
-    pack16(cp, type);
-    cp += sizeof(u16_t);
-    pack16(cp, HTONS(C_IN));
-    cp += sizeof(u16_t);
-    dlen= cp - dns2oct(&udp.dns);
-
-    udp.dns.hdr.dh_id= new_id(ID_REFRESH, my_port, ID_IPSELF);
-    udp.dns.hdr.dh_flag1= DHF_RD;
-    udp.dns.hdr.dh_flag2= 0;
-    udp.dns.hdr.dh_qdcount= HTONS(1);
-    udp.dns.hdr.dh_ancount= HTONS(0);
-    udp.dns.hdr.dh_nscount= HTONS(0);
-    udp.dns.hdr.dh_arcount= HTONS(0);
-
-    udp.hdr.uih_dst_addr= current_named();
-    udp.hdr.uih_dst_port= named_port;
-    udp.hdr.uih_ip_opt_len= 0;
-    udp.hdr.uih_data_len= dlen;
-
-    if (debug >= 1) {
-	printf("Refresh to %s:%u:\n",
-	    inet_ntoa(current_named()), ntohs(named_port));
-	dns_tell(0, &udp.dns, dlen);
-    }
-    ulen= offsetof(udp_dns_t, dns) + dlen;
-    if (write(udp_fd, &udp, ulen) < 0) fatal(udp_device);
-}
-
-static int job_read_udp(void *data, int expired)
-/* Read UDP queries and replies. */
-{
-    size_t ulen, dlen;
-    static udp_dns_t udp;
-    u16_t id, port;
-    ipaddr_t ip;
-    time_t dtime;
-
-    assert(!expired);
-
-    /* Try to read a packet. */
-    ulen= asyn_read(&asyn, udp_fd, &udp, sizeof(udp));
-    dlen= ulen - offsetof(udp_dns_t, dns);
-
-    if (ulen == -1) {
-	if (errno == EINPROGRESS && !expired) return 0;
-	if (errno == EIO) fatal(udp_device);
-
-	if (debug >= 2) {
-	    printf("%s: UDP read: %s\n", nowgmt(), strerror(errno));
-	}
-    } else {
-	if (debug >= 2) {
-	    printf("%s: UDP read, %d bytes\n", nowgmt(), (int) ulen);
-	}
-    }
-
-    /* Restart this job no matter what. */
-    newjob(job_read_udp, NEVER, nil);
-
-    if (ulen < (ssize_t) (sizeof(udp_io_hdr_t) + sizeof(dns_hdr_t))) return 1;
-
-    if (debug >= 1) {
-	printf("%s:%u UDP ", inet_ntoa(udp.hdr.uih_src_addr),
-				ntohs(udp.hdr.uih_src_port));
-	dns_tell(0, &udp.dns, dlen);
-    }
-
-    /* Check, and if necessary reinitialize my configuration. */
-    init_config(udp.hdr.uih_dst_addr);
-
-    if (udp.dns.hdr.dh_flag1 & DHF_QR) {
-	/* This is a remote named reply, not a query. */
-
-	/* Response to a query previously relayed? */
-	if (!old_id(udp.dns.hdr.dh_id, &id, &port, &ip)) return 1;
-
-	if (ip == ID_IPSELF && id == ID_PROBE) {
-	    if (searching()) {
-		/* We have found a name server! */
-		int i;
-
-		/* In my list? */
-		for (i= 0; i < n_nameds; i++) {
-		    if (named[i] == udp.hdr.uih_src_addr) {
-			i_named= i;
-			if (debug >= 1) {
-			    printf("Current named = %s\n",
-				inet_ntoa(current_named()));
-			}
-			stop_searching();
-			force_expire(job_find_named);
-		    }
-		}
-	    }
-	}
-
-	/* We got an answer, so stop worrying. */
-	if (expecting()) {
-	    stop_expecting();
-	    force_expire(job_expect_named);
-	}
-
-	/* Put the information in the cache. */
-	cache_reply(&udp.dns, dlen);
-
-	/* Refresh a cached entry that was used when stale. */
-	refresh_cache();
-
-	/* Discard reply to myself. */
-	if (ip == ID_IPSELF) return 1;
-
-	/* Send the reply to the process that asked for it. */
-	udp.dns.hdr.dh_id= id;
-	udp.hdr.uih_dst_addr= ip;
-	udp.hdr.uih_dst_port= port;
-	if (debug >= 1) printf("To client %s:%u\n", inet_ntoa(ip), ntohs(port));
-    } else {
-	/* A query. */
-	if (udp.dns.hdr.dh_qdcount != HTONS(1)) return 1;
-
-	if(localonly) {
-		/* Check if it's a local query. */
-		if(ntohl(udp.hdr.uih_src_addr) != LOCALHOST) {
-		   	syslog(LOG_WARNING, "nonamed: dropped query from %s",
-		   		inet_ntoa(udp.hdr.uih_src_addr));
-		   	return 1;
-		}
-	}
-
-	/* Try to compose a reply from local data. */
-	if (compose_reply(&udp.dns, &dlen)) {
-	    udp.hdr.uih_dst_addr= udp.hdr.uih_src_addr;
-	    udp.hdr.uih_dst_port= udp.hdr.uih_src_port;
-	    udp.hdr.uih_ip_opt_len= 0;
-	    udp.hdr.uih_data_len= dlen;
-	    ulen= offsetof(udp_dns_t, dns) + dlen;
-
-	    /* Send an UDP DNS reply. */
-	    if (debug >= 1) {
-		printf("%s:%u UDP ", inet_ntoa(udp.hdr.uih_dst_addr),
-					    ntohs(udp.hdr.uih_dst_port));
-		dns_tell(0, &udp.dns, dlen);
-	    }
-	} else {
-	    /* Let a real name daemon handle the query. */
-	    udp.dns.hdr.dh_id= new_id(udp.dns.hdr.dh_id,
-				udp.hdr.uih_src_port, udp.hdr.uih_src_addr);
-	    udp.hdr.uih_dst_addr= current_named();
-	    udp.hdr.uih_dst_port= named_port;
-	    if (!expecting()) {
-		start_expecting();
-		newjob(job_expect_named, now + MEDIUM_TIMEOUT, nil);
-	    }
-	    if (debug >= 1) {
-		printf("To named %s:%u\n",
-		    inet_ntoa(current_named()), ntohs(named_port));
-	    }
-	}
-    }
-    if (write(udp_fd, &udp, ulen) < 0) fatal(udp_device);
-    return 1;
-}
-
-#if DO_TCP
-
-typedef struct data_cl {	/* Data for connect or listen jobs. */
-	int		fd;		/* Open TCP channel. */
-	int		dn_fd;		/* TCP channel to the name daemon. */
-	int		retry;		/* Retrying a connect? */
-	nwio_tcpcl_t	tcpcl;		/* Flags. */
-} data_cl_t;
-
-typedef struct data_rw {	/* Data for TCP read or write jobs. */
-	int		r_fd;		/* Read from this TCP channel. */
-	int		w_fd;		/* And write to this TCP channel. */
-	struct data_rw	*rev;		/* Optional reverse TCP channel. */
-	u8_t		*buf;		/* Buffer for bytes to transfer. */
-	ssize_t		offset;		/* Offset in buf to r/w at. */
-	size_t		size;		/* Size of buf. */
-} data_rw_t;
-
-static int job_setup_listen(void *data, int expired)
-/* Set up a listening channel for TCP DNS queries. */
-{
-    data_cl_t *data_cl= data;
-    nwio_tcpconf_t tcpconf;
-    nwio_tcpopt_t tcpopt;
-    int fd;
-
-    if (!expired) return 0;
-    if (debug >= 2) printf("%s: Setup listen\n", nowgmt());
-
-    if (data_cl == nil) {
-	if ((fd= open(tcp_device, O_RDWR)) < 0) {
-	    if (errno != EMFILE) report(tcp_device);
-	    newjob(job_setup_listen, now + SHORT_TIMEOUT, nil);
-	    return 1;
-	}
-
-	tcpconf.nwtc_flags= NWTC_SHARED | NWTC_LP_SET | NWTC_UNSET_RA
-							| NWTC_UNSET_RP;
-	tcpconf.nwtc_locport= my_port;
-	if (ioctl(fd, NWIOSTCPCONF, &tcpconf) == -1) fatal(tcp_device);
-
-	tcpopt.nwto_flags= NWTO_DEL_RST;
-	if (ioctl(fd, NWIOSTCPOPT, &tcpopt) == -1) fatal(tcp_device);
-
-	data_cl= allocate(nil, sizeof(*data_cl));
-	data_cl->fd= fd;
-	data_cl->tcpcl.nwtcl_flags= 0;
-    }
-    /* And listen. */
-    newjob(job_listen, NEVER, data_cl);
-    return 1;
-}
-
-static int job_listen(void *data, int expired)
-/* A connection on the TCP DNS query channel. */
-{
-    data_cl_t *data_cl= data;
-
-    /* Wait for a client. */
-    if (asyn_ioctl(&asyn, data_cl->fd, NWIOTCPLISTEN, &data_cl->tcpcl) < 0) {
-	if (errno == EINPROGRESS) return 0;
-	report(tcp_device);
-
-	/* Try again after a short time. */
-	newjob(job_setup_listen, now + SHORT_TIMEOUT, data_cl);
-	return 1;
-    }
-    if (debug >= 2) printf("%s: Listen\n", nowgmt());
-
-    /* Immediately resume listening. */
-    newjob(job_setup_listen, IMMEDIATE, nil);
-
-    /* Set up a connect to the real name daemon. */
-    data_cl->retry= 0;
-    newjob(job_setup_connect, IMMEDIATE, data_cl);
-    return 1;
-}
-
-static void start_relay(int fd, int dn_fd)
-/* Start one or two read jobs after job_setup_connect() or job_connect(). */
-{
-    data_rw_t *query;	/* Client to DNS daemon relay. */
-    data_rw_t *reply;	/* DNS daemon to client relay. */
-
-    query= allocate(nil, sizeof(*query));
-    query->r_fd= fd;
-    query->buf= allocate(nil, sizeof(u16_t));
-    query->offset= 0;
-    query->size= sizeof(u16_t);
-    if (dn_fd == NO_FD) {
-	/* Answer mode. */
-	query->w_fd= fd;
-	query->rev= nil;
-    } else {
-	/* Relay mode. */
-	reply= allocate(nil, sizeof(*reply));
-	reply->r_fd= dn_fd;
-	reply->w_fd= fd;
-	reply->buf= allocate(nil, sizeof(u16_t));
-	reply->offset= 0;
-	reply->size= sizeof(u16_t);
-	reply->rev= query;
-	query->w_fd= dn_fd;
-	query->rev= reply;
-	newjob(job_read_reply, now + LONG_TIMEOUT, reply);
-    }
-    newjob(job_read_query, now + LONG_TIMEOUT, query);
-}
-
-static void close_relay(data_rw_t *data_rw)
-/* Close a relay channel. */
-{
-    if (data_rw->rev != nil) {
-	/* Other end still active, signal EOF. */
-	(void) ioctl(data_rw->w_fd, NWIOTCPSHUTDOWN, nil);
-	data_rw->rev->rev= nil;
-    } else {
-	/* Close both ends down. */
-	asyn_close(&asyn, data_rw->r_fd);
-	close(data_rw->r_fd);
-	if (data_rw->w_fd != data_rw->r_fd) {
-	    asyn_close(&asyn, data_rw->w_fd);
-	    close(data_rw->w_fd);
-	}
-    }
-    deallocate(data_rw->buf);
-    deallocate(data_rw);
-}
-
-static int job_setup_connect(void *data, int expired)
-/* Set up a connect for a TCP channel to the real name daemon. */
-{
-    nwio_tcpconf_t tcpconf;
-    int dn_fd;
-    data_cl_t *data_cl= data;
-
-    if (!expired) return 0;
-    if (debug >= 2) printf("%s: Setup connect\n", nowgmt());
-
-    if (n_nameds == 0) {
-	/* No name daemons to relay to, answer myself. */
-	start_relay(data_cl->fd, NO_FD);
-	deallocate(data_cl);
-	return 1;
-    }
-
-    if ((dn_fd= open(tcp_device, O_RDWR)) < 0) {
-	if (errno != EMFILE) report(tcp_device);
-	if (++data_cl->retry < 5) {
-	    /* Retry. */
-	    newjob(job_setup_connect, now + SHORT_TIMEOUT, data_cl);
-	} else {
-	    /* Reply myself (bound to fail). */
-	    start_relay(data_cl->fd, NO_FD);
-	    deallocate(data_cl);
-	}
-	return 1;
-    }
-
-    tcpconf.nwtc_flags= NWTC_LP_SEL | NWTC_SET_RA | NWTC_SET_RP;
-    tcpconf.nwtc_remaddr= current_named();
-    tcpconf.nwtc_remport= named_port;
-    if (ioctl(dn_fd, NWIOSTCPCONF, &tcpconf) == -1) fatal(tcp_device);
-
-    /* And connect. */
-    data_cl->dn_fd= dn_fd;
-    data_cl->tcpcl.nwtcl_flags= 0;
-    newjob(job_connect, NEVER, data_cl);
-    return 1;
-}
-
-static int job_connect(void *data, int expired)
-/* Connect to a TCP DNS query channel. */
-{
-    data_cl_t *data_cl= data;
-
-    /* Try to connect. */
-    if (asyn_ioctl(&asyn, data_cl->dn_fd, NWIOTCPCONN, &data_cl->tcpcl) < 0) {
-	if (errno == EINPROGRESS) return 0;
-	if (errno == EIO) fatal(tcp_device);
-
-	/* Connection refused. */
-	if (debug >= 2) printf("%s: Connect: %s\n", nowgmt(), strerror(errno));
-	asyn_close(&asyn, data_cl->dn_fd);
-	close(data_cl->dn_fd);
-	data_cl->dn_fd= NO_FD;
-	if (++data_cl->retry < 5) {
-	    /* Search a new name daemon. */
-	    if (!searching()) {
-		start_searching();
-		force_expire(job_find_named);
-	    }
-	    newjob(job_setup_connect, NEVER, data_cl);
-	    return 1;
-	}
-	/* Reply with a failure eventually. */
-    }
-    if (debug >= 2) printf("%s: Connect\n", nowgmt());
-
-    /* Read the query from the user, send on to the name daemon, etc. */
-    start_relay(data_cl->fd, data_cl->dn_fd);
-    deallocate(data_cl);
-    return 1;
-}
-
-static void tcp_dns_tell(int fd, u8_t *buf)
-/* Tell about a DNS packet on a TCP channel. */
-{
-    nwio_tcpconf_t tcpconf;
-
-    if (ioctl(fd, NWIOGTCPCONF, &tcpconf) < 0) {
-	printf("??\?:?? TCP ");
-    } else {
-	printf("%s:%u TCP ", inet_ntoa(tcpconf.nwtc_remaddr),
-				ntohs(tcpconf.nwtc_remport));
-    }
-    dns_tell(0, oct2dns(buf + sizeof(u16_t)), ntohs(upack16(buf)));
-}
-
-static int job_read_query(void *data, int expired)
-/* Read TCP queries from the client. */
-{
-    data_rw_t *data_rw= data;
-    ssize_t count;
-
-    /* Try to read count bytes. */
-    count= asyn_read(&asyn, data_rw->r_fd,
-				data_rw->buf + data_rw->offset,
-				data_rw->size - data_rw->offset);
-
-    if (count < 0) {
-	if (errno == EINPROGRESS && !expired) return 0;
-	if (errno == EIO) fatal(tcp_device);
-
-	/* Remote end is late, or an error occurred. */
-	if (debug >= 2) {
-	    printf("%s: TCP read query: %s\n", nowgmt(), strerror(errno));
-	}
-	close_relay(data_rw);
-	return 1;
-    }
-
-    if (debug >= 2) {
-	printf("%s: TCP read query, %d/%u bytes\n",
-	    nowgmt(), data_rw->offset + count, data_rw->size);
-    }
-    if (count == 0) {
-	/* EOF. */
-	close_relay(data_rw);
-	return 1;
-    }
-    data_rw->offset += count;
-    if (data_rw->offset == data_rw->size) {
-	data_rw->size= sizeof(u16_t) + ntohs(upack16(data_rw->buf));
-	if (data_rw->size < sizeof(u16_t)) {
-	    /* Malformed. */
-	    close_relay(data_rw);
-	    return 1;
-	}
-	if (data_rw->offset < data_rw->size) {
-	    /* Query not complete, read more. */
-	    data_rw->buf= allocate(data_rw->buf, data_rw->size);
-	    newjob(job_read_query, now + LONG_TIMEOUT, data_rw);
-	    return 1;
-	}
-    }
-
-    if (data_rw->size < sizeof(u16_t) + sizeof(dns_hdr_t)) {
-	close_relay(data_rw);
-	return 1;
-    }
-    if (debug >= 1) tcp_dns_tell(data_rw->r_fd, data_rw->buf);
-
-    /* Relay or reply. */
-    if (data_rw->w_fd != data_rw->r_fd) {
-	/* We have a real name daemon to do the work. */
-	data_rw->offset= 0;
-	newjob(job_write_query, now + LONG_TIMEOUT, data_rw);
-    } else {
-	/* No real name daemons or none reachable, so use the hosts file. */
-	dns_t *dp;
-	size_t dlen;
-
-	if (data_rw->size < sizeof(u16_t) + PACKETSZ) {
-	    data_rw->buf= allocate(data_rw->buf, sizeof(u16_t) + PACKETSZ);
-	}
-
-	/* Build a reply packet. */
-	dp= oct2dns(data_rw->buf + sizeof(u16_t));
-	dlen= data_rw->size - sizeof(u16_t);
-	if (!compose_reply(dp, &dlen)) {
-	    /* We're told to ask a name daemon, but that won't work. */
-	    close_relay(data_rw);
-	    return 1;
-	}
-
-	/* Start a reply write. */
-	pack16(data_rw->buf, htons(dlen));
-	data_rw->size= sizeof(u16_t) + dlen;
-	data_rw->buf= allocate(data_rw->buf, data_rw->size);
-	data_rw->offset= 0;
-	newjob(job_write_reply, now + LONG_TIMEOUT, data_rw);
-    }
-    return 1;
-}
-
-static int job_write_query(void *data, int expired)
-/* Relay a TCP query to the name daemon. */
-{
-    data_rw_t *data_rw= data;
-    ssize_t count;
-
-    /* Try to write count bytes to the name daemon. */
-    count= asyn_write(&asyn, data_rw->w_fd,
-				data_rw->buf + data_rw->offset,
-				data_rw->size - data_rw->offset);
-
-    if (count <= 0) {
-	if (errno == EINPROGRESS && !expired) return 0;
-	if (errno == EIO) fatal(tcp_device);
-
-	/* A write expired or failed (usually a broken connection.) */
-	if (debug >= 2) {
-	    printf("%s: TCP write query: %s\n", nowgmt(), strerror(errno));
-	}
-	close_relay(data_rw);
-	return 1;
-    }
-
-    if (debug >= 2) {
-	printf("%s: TCP write query, %d/%u bytes\n",
-	    nowgmt(), data_rw->offset + count, data_rw->size);
-    }
-    data_rw->offset += count;
-    if (data_rw->offset < data_rw->size) {
-	/* Partial write, continue. */
-	newjob(job_write_query, now + LONG_TIMEOUT, data_rw);
-	return 1;
-    }
-    if (debug >= 1) tcp_dns_tell(data_rw->w_fd, data_rw->buf);
-
-    /* Query fully send on, go read more queries. */
-    data_rw->offset= 0;
-    data_rw->size= sizeof(u16_t);
-    newjob(job_read_query, now + LONG_TIMEOUT, data_rw);
-    return 1;
-}
-
-static int job_read_reply(void *data, int expired)
-/* Read a TCP reply from the real name daemon. */
-{
-    data_rw_t *data_rw= data;
-    ssize_t count;
-
-    /* Try to read count bytes. */
-    count= asyn_read(&asyn, data_rw->r_fd,
-				data_rw->buf + data_rw->offset,
-				data_rw->size - data_rw->offset);
-
-    if (count < 0) {
-	if (errno == EINPROGRESS && !expired) return 0;
-	if (errno == EIO) fatal(tcp_device);
-
-	/* Remote end is late, or an error occurred. */
-	if (debug >= 2) {
-	    printf("%s: TCP read reply: %s\n", nowgmt(), strerror(errno));
-	}
-	close_relay(data_rw);
-	return 1;
-    }
-
-    if (debug >= 2) {
-	printf("%s: TCP read reply, %d/%u bytes\n",
-	    nowgmt(), data_rw->offset + count, data_rw->size);
-    }
-    if (count == 0) {
-	/* EOF. */
-	close_relay(data_rw);
-	return 1;
-    }
-    data_rw->offset += count;
-    if (data_rw->offset == data_rw->size) {
-	data_rw->size= sizeof(u16_t) + ntohs(upack16(data_rw->buf));
-	if (data_rw->size < sizeof(u16_t)) {
-	    /* Malformed. */
-	    close_relay(data_rw);
-	    return 1;
-	}
-	if (data_rw->offset < data_rw->size) {
-	    /* Reply not complete, read more. */
-	    data_rw->buf= allocate(data_rw->buf, data_rw->size);
-	    newjob(job_read_reply, now + LONG_TIMEOUT, data_rw);
-	    return 1;
-	}
-    }
-    if (debug >= 1) tcp_dns_tell(data_rw->r_fd, data_rw->buf);
-
-    /* Reply fully read, send it on. */
-    data_rw->offset= 0;
-    newjob(job_write_reply, now + LONG_TIMEOUT, data_rw);
-    return 1;
-}
-
-static int job_write_reply(void *data, int expired)
-/* Send a TCP reply to the client. */
-{
-    data_rw_t *data_rw= data;
-    ssize_t count;
-
-    /* Try to write count bytes to the client. */
-    count= asyn_write(&asyn, data_rw->w_fd,
-				data_rw->buf + data_rw->offset,
-				data_rw->size - data_rw->offset);
-
-    if (count <= 0) {
-	if (errno == EINPROGRESS && !expired) return 0;
-	if (errno == EIO) fatal(tcp_device);
-
-	/* A write expired or failed (usually a broken connection.) */
-	if (debug >= 2) {
-	    printf("%s: TCP write reply: %s\n", nowgmt(), strerror(errno));
-	}
-	close_relay(data_rw);
-	return 1;
-    }
-
-    if (debug >= 2) {
-	printf("%s: TCP write reply, %d/%u bytes\n",
-	    nowgmt(), data_rw->offset + count, data_rw->size);
-    }
-    data_rw->offset += count;
-    if (data_rw->offset < data_rw->size) {
-	/* Partial write, continue. */
-	newjob(job_write_reply, now + LONG_TIMEOUT, data_rw);
-	return 1;
-    }
-    if (debug >= 1) tcp_dns_tell(data_rw->w_fd, data_rw->buf);
-
-    /* Reply fully send on, go read more replies (or queries). */
-    data_rw->offset= 0;
-    data_rw->size= sizeof(u16_t);
-    newjob(data_rw->w_fd != data_rw->r_fd ? job_read_reply : job_read_query,
-		now + LONG_TIMEOUT, data_rw);
-    return 1;
-}
-#else /* !DO_TCP */
-
-static int job_dummy(void *data, int expired)
-{
-    return 1;
-}
-#define job_setup_listen	job_dummy
-#define job_setup_connect	job_dummy
-#endif /* !DO_TCP */
-
-static void named_probe(ipaddr_t ip)
-/* Send a probe to a name daemon, like 'host -r -t ns . <ip>'. */
-{
-    udp_dns_t udp;
-#   define dlen (offsetof(dns_t, data) + 5)
-#   define ulen (offsetof(udp_dns_t, dns) + dlen)
-
-    /* Send a simple DNS query that all name servers can answer easily:
-     * "What are the name servers for the root domain?"
-     */
-    udp.dns.hdr.dh_id= new_id(ID_PROBE, my_port, ID_IPSELF);
-    udp.dns.hdr.dh_flag1= 0;
-    udp.dns.hdr.dh_flag2= 0;
-    udp.dns.hdr.dh_qdcount= HTONS(1);
-    udp.dns.hdr.dh_ancount= HTONS(0);
-    udp.dns.hdr.dh_nscount= HTONS(0);
-    udp.dns.hdr.dh_arcount= HTONS(0);
-
-    udp.dns.data[0] = 0;	/* Null name. */
-    pack16(udp.dns.data+1, HTONS(T_NS));
-    pack16(udp.dns.data+3, HTONS(C_IN));
-    if (debug >= 1) {
-	printf("PROBE %s ", inet_ntoa(ip));
-	dns_tell(0, &udp.dns, dlen);
-    }
-
-    udp.hdr.uih_dst_addr= ip;
-    udp.hdr.uih_dst_port= named_port;
-    udp.hdr.uih_ip_opt_len= 0;
-    udp.hdr.uih_data_len= dlen;
-
-    if (write(udp_fd, &udp, ulen) < 0) fatal(udp_device);
-#undef dlen
-#undef ulen
-}
-
-static int job_find_named(void *data, int expired)
-/* Look for a real name daemon to answer real DNS queries. */
-{
-    if (!expired) return 0;
-    if (debug >= 2) printf("%s: Find named\n", nowgmt());
-
-    /* New search? */
-    if (search_ct < 0) {
-	search_ct= n_nameds;
-	i_named= -1;
-    }
-
-    if (--search_ct < 0) {
-	/* Forced end of search (named response!), or end of search with
-	 * nothing found.  Search again after a long time.
-	 */
-	newjob(job_find_named,
-	    (stale > 0 || i_named > 0) ? now + LONG_TIMEOUT : NEVER, nil);
-	force_expire(job_setup_connect);
-	return 1;
-    }
-
-    /* Send a named probe. */
-    i_named= (i_named+1) % n_nameds;
-    named_probe(current_named());
-
-    /* Schedule the next call. */
-    newjob(job_find_named, now + SHORT_TIMEOUT, nil);
-    return 1;
-}
-
-static int job_expect_named(void *data, int expired)
-/* The real name server is expected to answer by now. */
-{
-    if (!expired) return 0;
-    if (debug >= 2) printf("%s: Expect named\n", nowgmt());
-
-    if (expecting() && !searching()) {
-	/* No answer yet, start searching. */
-	start_searching();
-	force_expire(job_find_named);
-    }
-    return 1;
-}
-
-static void sig_handler(int sig)
-/* A signal forces a search for a real name daemon, etc. */
-{
-    switch (sig) {
-    case SIGINT:
-    case SIGTERM:	done= 1;		break;
-    case SIGHUP:	reinit= 1;		break;
-    case SIGUSR1:	debug++;		break;
-    case SIGUSR2:	debug= 0;		break;
-    }
-}
-
-static void usage(void)
-{
-    fprintf(stderr, "Usage: nonamed [-qs] [-d[level]] [-p port]\n");
-    exit(1);
-}
-
-int main(int argc, char **argv)
-{
-    job_t *job;
-    nwio_udpopt_t udpopt;
-    int i;
-    struct servent *servent;
-    struct sigaction sa;
-    FILE *fp;
-    int quit= 0;
-
-    /* Debug output must be line buffered. */
-    setvbuf(stdout, nil, _IOLBF, 0);
-
-    /* DNS service port number? */
-    if ((servent= getservbyname("domain", nil)) == nil) {
-	fprintf(stderr, "nonamed: \"domain\": unknown service\n");
-	exit(1);
-    }
-    my_port= servent->s_port;
-    named_port= servent->s_port;
-
-    i= 1;
-    while (i < argc && argv[i][0] == '-') {
-	char *opt= argv[i++] + 1, *end;
-
-	if (opt[0] == '-' && opt[1] == 0) break;
-
-	switch (*opt++) {
-	case 'd':		/* Debug level. */
-	    debug= 1;
-	    if (between('0', *opt, '9')) debug= strtoul(opt, &opt, 10);
-	    break;
-	case 'p':		/* Port to listen to (for testing.) */
-	    if (*opt == 0) {
-		if (i == argc) usage();
-		opt= argv[i++];
-	    }
-	    my_port= htons(strtoul(opt, &end, 0));
-	    if (opt == end || *end != 0) usage();
-	    opt= end;
-	    break;
-	case 's':
-	    single= 1;
-	    break;
-	case 'q':		/* Quit after printing cache contents. */
-	    quit= 1;
-	    break;
-	case 'L':
-	    localonly= 1;
-	    break;
-	default:
-	    usage();
-	}
-    }
-    if (i != argc) usage();
-
-    if (quit) {
-	/* Oops, just having a look at the cache. */
-	debug= 2;
-	now= time(nil);
-	n_datamax= -1;
-	file2cache();
-	return 0;
-    }
-
-    /* Don't die on broken pipes, reinitialize on hangup, etc. */
-    sa.sa_handler= SIG_IGN;
-    sigemptyset(&sa.sa_mask);
-    sa.sa_flags= 0;
-    sigaction(SIGPIPE, &sa, nil);
-    sa.sa_handler= sig_handler;
-    sigaction(SIGINT, &sa, nil);
-    sigaction(SIGHUP, &sa, nil);
-    sigaction(SIGUSR1, &sa, nil);
-    sigaction(SIGUSR2, &sa, nil);
-    sigaction(SIGTERM, &sa, nil);
-
-    /* TCP and UDP device names. */
-    if ((tcp_device= getenv("TCP_DEVICE")) == nil) tcp_device= TCP_DEVICE;
-    if ((udp_device= getenv("UDP_DEVICE")) == nil) udp_device= UDP_DEVICE;
-
-    /* Open an UDP channel for incoming DNS queries. */
-    if ((udp_fd= open(udp_device, O_RDWR)) < 0) fatal(udp_device);
-
-    udpopt.nwuo_flags= NWUO_EXCL | NWUO_LP_SET | NWUO_EN_LOC | NWUO_DI_BROAD
-		| NWUO_RP_ANY | NWUO_RA_ANY | NWUO_RWDATALL | NWUO_DI_IPOPT;
-    udpopt.nwuo_locport= my_port;
-    if (ioctl(udp_fd, NWIOSUDPOPT, &udpopt) == -1
-	|| ioctl(udp_fd, NWIOGUDPOPT, &udpopt) == -1
-    ) {
-	fatal(udp_device);
-    }
-
-    /* The current time is... */
-    now= time(nil);
-
-    /* Read configuration and data cached by the previous nonamed. */
-    init_config(udpopt.nwuo_locaddr);
-    file2cache();
-
-    if (!single) {
-	/* Save process id. */
-	if ((fp= fopen(PIDFILE, "w")) != nil) {
-	    fprintf(fp, "%u\n", (unsigned) getpid());
-	    fclose(fp);
-	}
-    }
-
-    /* Jobs that start the ball rolling. */
-    newjob(job_read_udp, NEVER, nil);
-    newjob(job_setup_listen, IMMEDIATE, nil);
-    newjob(job_find_named, IMMEDIATE, nil);
-
-    /* Open syslog. */
-    openlog("nonamed", LOG_PID, LOG_DAEMON);
-
-    while (!done) {
-	/* There is always something in the queue. */
-	assert(queue != nil);
-
-	/* Any expired jobs? */
-	while (queue->timeout <= now) {
-	    (void) execjob(queue, 1);
-	    assert(queue != nil);
-	}
-
-	/* Check I/O jobs. */
-	for (job= queue; job != nil; job= job->next) {
-	    if (execjob(job, 0)) break;
-	}
-
-	if (queue->timeout != IMMEDIATE) {
-	    struct timeval tv, *tvp;
-
-	    if (debug >= 2) printf("%s: I/O wait", nowgmt());
-
-	    if (queue->timeout != NEVER) {
-		tv.tv_sec= queue->timeout;
-		tv.tv_usec= 0;
-		tvp= &tv;
-		if (debug >= 2) printf(" (expires %s)\n", timegmt(tv.tv_sec));
-	    } else {
-		tvp= nil;
-		if (debug >= 2) fputc('\n', stdout);
-	    }
-	    fflush(stdout);
-
-	    if (asyn_wait(&asyn, 0, tvp) < 0) {
-		if (errno != EINTR && errno != EAGAIN) fatal("fwait()");
-	    }
-	    now= time(nil);
-	}
-
-	if (reinit) {
-	    /* A hangup makes us go back to square one. */
-	    reinit= 0;
-	    if (ioctl(udp_fd, NWIOGUDPOPT, &udpopt) == -1) fatal(udp_device);
-	    init_config(udpopt.nwuo_locaddr);
-	    start_searching();
-	    force_expire(job_find_named);
-	}
-    }
-    cache2file();
-    (void) unlink(PIDFILE);
-    if (debug >= 2) printf("sbrk(0) = %u\n", (unsigned) sbrk(0));
-    return 0;
-}
Index: trunk/minix/commands/simple/od.c
===================================================================
--- trunk/minix/commands/simple/od.c	(revision 9)
+++ 	(revision )
@@ -1,314 +1,0 @@
-/* od - octal dump		   Author: Andy Tanenbaum */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-
-int bflag, cflag, dflag, oflag, xflag, hflag, vflag;
-int linenr, width, state, ever;
-int prevwds[8];
-long off;
-char buf[512], buffer[BUFSIZ];
-int next;
-int bytespresent;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(long offset, (int argc, char *argv [], int k));
-_PROTOTYPE(void dumpfile, (void));
-_PROTOTYPE(void wdump, (short *words, int k, int radix));
-_PROTOTYPE(void bdump, (char bytes [16 ], int k, int c));
-_PROTOTYPE(void byte, (int val, int c));
-_PROTOTYPE(int getwords, (short **words));
-_PROTOTYPE(int same, (short *w1, int *w2));
-_PROTOTYPE(void outword, (int val, int radix));
-_PROTOTYPE(void outnum, (int num, int radix));
-_PROTOTYPE(void addrout, (long l));
-_PROTOTYPE(char hexit, (int k));
-_PROTOTYPE(void usage, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int k, flags;
-  char *p;
-
-  /* Process flags */
-  setbuf(stdout, buffer);
-  flags = 0;
-  p = argv[1];
-  if (argc > 1 && *p == '-') {
-	/* Flags present. */
-	flags++;
-	p++;
-	while (*p) {
-		switch (*p) {
-		    case 'b':	bflag++;	break;
-		    case 'c':	cflag++;	break;
-		    case 'd':	dflag++;	break;
-		    case 'h':	hflag++;	break;
-		    case 'o':	oflag++;	break;
-		    case 'v':	vflag++;	break;	
-		    case 'x':	xflag++;	break;
-		    default:	usage();
-		}
-		p++;
-	}
-  } else {
-	oflag = 1;
-  }
-  if ((bflag | cflag | dflag | oflag | xflag) == 0) oflag = 1;
-  k = (flags ? 2 : 1);
-  if (bflag | cflag) {
-	width = 8;
-  } else if (oflag) {
-	width = 7;
-  } else if (dflag) {
-	width = 6;
-  } else {
-	width = 5;
-  }
-
-  /* Process file name, if any. */
-  p = argv[k];
-  if (k < argc && *p != '+') {
-	/* Explicit file name given. */
-	close(0);
-	if (open(argv[k], O_RDONLY) != 0) {
-		fprintf(stderr, "od: cannot open %s\n", argv[k]);
-		exit(1);
-	}
-	k++;
-  }
-
-  /* Process offset, if any. */
-  if (k < argc) {
-	/* Offset present. */
-	off = offset(argc, argv, k);
-	off = (off / 16L) * 16L;
-	lseek(0, off, SEEK_SET);
-  }
-  dumpfile();
-  addrout(off);
-  printf("\n");
-  return(0);
-}
-
-
-long offset(argc, argv, k)
-int argc;
-char *argv[];
-int k;
-{
-  int dot, radix;
-  char *p, c;
-  long val;
-
-  /* See if the offset is decimal. */
-  dot = 0;
-  p = argv[k];
-  while (*p)
-	if (*p++ == '.') dot = 1;
-
-  /* Convert offset to binary. */
-  radix = (dot ? 10 : 8);
-  val = 0;
-  p = argv[k];
-  if (*p == '+') p++;
-  while (*p != 0 && *p != '.') {
-	c = *p++;
-	if (c < '0' || c > '9') {
-		printf("Bad character in offset: %c\n", c);
-		exit(1);
-	}
-	val = radix * val + c - '0';
-  }
-
-  p = argv[k + 1];
-  if (k + 1 == argc - 1 && *p == 'b') val = 512L * val;
-  return(val);
-}
-
-
-void dumpfile()
-{
-  int k;
-  short *words;
-
-  while ((k = getwords(&words))) {	/* 'k' is # bytes read */
-	if (!vflag) {		/* ensure 'lazy' evaluation */
-		if (k == 16 && ever == 1 && same(words, prevwds)) {
-			if (state == 0) {
-				printf("*\n");
-				state = 1;
-				off += 16;
-				continue;
-			} else if (state == 1) {
-				off += 16;
-				continue;
-			}
-		}
-	}
-	addrout(off);
-	off += k;
-	state = 0;
-	ever = 1;
-	linenr = 1;
-	if (oflag) wdump(words, k, 8);
-	if (dflag) wdump(words, k, 10);
-	if (xflag) wdump(words, k, 16);
-	if (cflag) bdump((char *)words, k, (int)'c');
-	if (bflag) bdump((char *)words, k, (int)'b');
-	for (k = 0; k < 8; k++) prevwds[k] = words[k];
-	for (k = 0; k < 8; k++) words[k] = 0;
-  }
-}
-
-
-void wdump(words, k, radix)
-short *words;
-int k, radix;
-{
-  int i;
-
-  if (linenr++ != 1) printf("       ");
-  for (i = 0; i < (k + 1) / 2; i++) outword(words[i] & 0xFFFF, radix);
-  printf("\n");
-}
-
-
-void bdump(bytes, k, c)
-char bytes[16];
-int k;
-char c;
-{
-  int i;
-
-  if (linenr++ != 1) printf("       ");
-  for (i = 0; i < k; i++) byte(bytes[i] & 0377, c);
-  printf("\n");
-}
-
-void byte(val, c)
-int val;
-char c;
-{
-  if (c == 'b') {
-	printf(" ");
-	outnum(val, 7);
-	return;
-  }
-  if (val == 0)
-	printf("  \\0");
-  else if (val == '\b')
-	printf("  \\b");
-  else if (val == '\f')
-	printf("  \\f");
-  else if (val == '\n')
-	printf("  \\n");
-  else if (val == '\r')
-	printf("  \\r");
-  else if (val == '\t')
-	printf("  \\t");
-  else if (val >= ' ' && val < 0177)
-	printf("   %c", val);
-  else {
-	printf(" ");
-	outnum(val, 7);
-  }
-}
-
-
-int getwords(words)
-short **words;
-{
-  int count;
-
-  if (next >= bytespresent) {
-	bytespresent = read(0, buf, 512);
-	next = 0;
-  }
-  if (next >= bytespresent) return(0);
-  *words = (short *) &buf[next];
-  if (next + 16 <= bytespresent)
-	count = 16;
-  else
-	count = bytespresent - next;
-
-  next += count;
-  return(count);
-}
-
-int same(w1, w2)
-short *w1;
-int *w2;
-{
-  int i;
-  i = 8;
-  while (i--)
-	if (*w1++ != *w2++) return(0);
-  return(1);
-}
-
-void outword(val, radix)
-int val, radix;
-{
-/* Output 'val' in 'radix' in a field of total size 'width'. */
-
-  int i;
-
-  if (radix == 16) i = width - 4;
-  if (radix == 10) i = width - 5;
-  if (radix == 8) i = width - 6;
-  if (i == 1)
-	printf(" ");
-  else if (i == 2)
-	printf("  ");
-  else if (i == 3)
-	printf("   ");
-  else if (i == 4)
-	printf("    ");
-  outnum(val, radix);
-}
-
-
-void outnum(num, radix)
-int num, radix;
-{
-/* Output a number with all leading 0s present.  Octal is 6 places,
- * decimal is 5 places, hex is 4 places.
- */
-  unsigned val;
-
-  val = (unsigned) num;
-  if (radix == 8)
-	printf ("%06o", val);
-  else if (radix == 10)
-	printf ("%05u", val);
-  else if (radix == 16)
-	printf ("%04x", val);
-  else if (radix == 7) {
-  	/* special case */
-	printf ("%03o", val);
-  }
-}
-
-
-void addrout(l)
-long l;
-{
-  if (hflag == 0) {
-	printf("%07lo", l);
-  } else {
-	printf("%07lx", l);
-  }
-}
-
-
-void usage()
-{
-  fprintf(stderr, "Usage: od [-bcdhovx] [file] [ [+] offset [.] [b] ]\n");
-}
Index: trunk/minix/commands/simple/origmkfs.c
===================================================================
--- trunk/minix/commands/simple/origmkfs.c	(revision 9)
+++ 	(revision )
@@ -1,1374 +1,0 @@
-/* mkfs  -  make the MINIX filesystem	Authors: Tanenbaum et al. */
-
-/*	Authors: Andy Tanenbaum, Paul Ogilvie, Frans Meulenbroeks, Bruce Evans
- *
- * This program can make both version 1 and version 2 file systems, as follows:
- *	mkfs /dev/fd0 1200	# Version 2 (default)
- *	mkfs -1 /dev/fd0 360	# Version 1
- *
- */
-
-#include <sys/types.h>
-#include <sys/dir.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include <minix/minlib.h>
-#include "../../servers/fs/const.h"
-#if (MACHINE == IBM_PC)
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <sys/ioctl.h>
-#endif
-
-#undef EXTERN
-#define EXTERN			/* get rid of EXTERN by making it null */
-#include "../../servers/fs/type.h"
-#include "../../servers/fs/super.h"
-#include <minix/fslib.h>
-
-#ifndef DOS
-#ifndef UNIX
-#define UNIX
-#endif
-#endif
-
-#undef BLOCK_SIZE
-#define BLOCK_SIZE 1024
-
-#define INODE_MAP            2
-#define MAX_TOKENS          10
-#define LINE_LEN           200
-#define BIN                  2
-#define BINGRP               2
-#define BIT_MAP_SHIFT       13
-#define N_BLOCKS         (1024L * 1024)
-#define N_BLOCKS16	  (128L * 1024)
-#define INODE_MAX       ((unsigned) 65535)
-
-/* You can make a really large file system on a 16-bit system, but the array
- * of bits that get_block()/putblock() needs gets a bit big, so we can only
- * prefill MAX_INIT blocks.  (16-bit fsck can't check a file system larger
- * than N_BLOCKS16 anyway.)
- */
-#define MAX_INIT	 (sizeof(char *) == 2 ? N_BLOCKS16 : N_BLOCKS)
-
-
-#ifdef DOS
-maybedefine O_RDONLY 4		/* O_RDONLY | BINARY_BIT */
- maybedefine BWRITE 5		/* O_WRONLY | BINARY_BIT */
-#endif
-
-#if (MACHINE == ATARI)
-int isdev;
-#endif
-
-extern char *optarg;
-extern int optind;
-
-int next_zone, next_inode, zone_size, zone_shift = 0, zoff;
-block_t nrblocks;
-int inode_offset, lct = 0, disk, fd, print = 0, file = 0;
-unsigned int nrinodes;
-int override = 0, simple = 0, dflag;
-int donttest;			/* skip test if it fits on medium */
-char *progname;
-
-long current_time, bin_time;
-char zero[BLOCK_SIZE], *lastp;
-char umap[MAX_INIT / 8];	/* bit map tells if block read yet */
-block_t zone_map;		/* where is zone map? (depends on # inodes) */
-int inodes_per_block;
-int fs_version;
-block_t max_nrblocks;
-
-FILE *proto;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(block_t sizeup, (char *device));
-_PROTOTYPE(void super, (zone_t zones, Ino_t inodes));
-_PROTOTYPE(void rootdir, (Ino_t inode));
-_PROTOTYPE(void eat_dir, (Ino_t parent));
-_PROTOTYPE(void eat_file, (Ino_t inode, int f));
-_PROTOTYPE(void enter_dir, (Ino_t parent, char *name, Ino_t child));
-_PROTOTYPE(void incr_size, (Ino_t n, long count));
-_PROTOTYPE(PRIVATE ino_t alloc_inode, (int mode, int usrid, int grpid));
-_PROTOTYPE(PRIVATE zone_t alloc_zone, (void));
-_PROTOTYPE(void add_zone, (Ino_t n, zone_t z, long bytes, long cur_time));
-_PROTOTYPE(void add_z_1, (Ino_t n, zone_t z, long bytes, long cur_time));
-_PROTOTYPE(void add_z_2, (Ino_t n, zone_t z, long bytes, long cur_time));
-_PROTOTYPE(void incr_link, (Ino_t n));
-_PROTOTYPE(void insert_bit, (block_t block, int bit));
-_PROTOTYPE(int mode_con, (char *p));
-_PROTOTYPE(void getline, (char line[LINE_LEN], char *parse[MAX_TOKENS]));
-_PROTOTYPE(void check_mtab, (char *devname));
-_PROTOTYPE(long file_time, (int f));
-_PROTOTYPE(void pexit, (char *s));
-_PROTOTYPE(void copy, (char *from, char *to, int count));
-_PROTOTYPE(void print_fs, (void));
-_PROTOTYPE(int read_and_set, (block_t n));
-_PROTOTYPE(void special, (char *string));
-_PROTOTYPE(void get_block, (block_t n, char buf[BLOCK_SIZE]));
-_PROTOTYPE(void put_block, (block_t n, char buf[BLOCK_SIZE]));
-_PROTOTYPE(void cache_init, (void));
-_PROTOTYPE(void flush, (void));
-_PROTOTYPE(void mx_read, (int blocknr, char buf[BLOCK_SIZE]));
-_PROTOTYPE(void mx_write, (int blocknr, char buf[BLOCK_SIZE]));
-_PROTOTYPE(void dexit, (char *s, int sectnum, int err));
-_PROTOTYPE(void usage, (void));
-
-/*================================================================
- *                    mkfs  -  make filesystem
- *===============================================================*/
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int nread, mode, usrid, grpid, ch;
-  block_t blocks;
-  block_t i;
-  ino_t root_inum;
-  ino_t inodes;
-  zone_t zones;
-  char *token[MAX_TOKENS], line[LINE_LEN];
-  struct stat statbuf;
-
-  /* Get two times, the current time and the mod time of the binary of
-   * mkfs itself.  When the -d flag is used, the later time is put into
-   * the i_mtimes of all the files.  This feature is useful when
-   * producing a set of file systems, and one wants all the times to be
-   * identical. First you set the time of the mkfs binary to what you
-   * want, then go.
-   */
-  current_time = time((time_t *) 0);	/* time mkfs is being run */
-  stat(argv[0], &statbuf);
-  bin_time = statbuf.st_mtime;	/* time when mkfs binary was last modified */
-
-  /* Process switches. */
-  progname = argv[0];
-  blocks = 0;
-  i = 0;
-  fs_version = 2;
-  inodes_per_block = V2_INODES_PER_BLOCK(BLOCK_SIZE);
-  max_nrblocks = N_BLOCKS;
-  while ((ch = getopt(argc, argv, "1b:di:lot")) != EOF)
-	switch (ch) {
-	    case '1':
-		fs_version = 1;
-		inodes_per_block = V1_INODES_PER_BLOCK;
-		max_nrblocks = 0xFFFF;
-		break;
-	    case 'b':
-		blocks = strtoul(optarg, (char **) NULL, 0);
-		break;
-	    case 'd':
-		dflag = 1;
-		current_time = bin_time;
-		break;
-	    case 'i':
-		i = strtoul(optarg, (char **) NULL, 0);
-		break;
-	    case 'l':	print = 1;	break;
-	    case 'o':	override = 1;	break;
-	    case 't':	donttest = 1;	break;
-	    default:	usage();
-	}
-
-  /* Determine the size of the device if not specified as -b or proto. */
-  if (argc - optind == 1 && blocks == 0) blocks = sizeup(argv[optind]);
-  printf("%lu blocks\n", blocks);
-
-  /* The remaining args must be 'special proto', or just 'special' if the
-   * block size has already been specified.
-   */
-  if (argc - optind != 2 && (argc - optind != 1 || blocks == 0)) usage();
-
-  /* Check special. */
-  check_mtab(argv[optind]);
-
-  /* Check and start processing proto. */
-  optarg = argv[++optind];
-  if (optind < argc && (proto = fopen(optarg, "r")) != NULL) {
-	/* Prototype file is readable. */
-	lct = 1;
-	getline(line, token);	/* skip boot block info */
-
-	/* Read the line with the block and inode counts. */
-	getline(line, token);
-	blocks = atol(token[0]);
-	if (blocks > max_nrblocks) {
-		printf("%d > %d\n",  blocks, max_nrblocks);
-		pexit("Block count too large");
-	}
-	if (sizeof(char *) == 2 && blocks > N_BLOCKS16) {
-		fprintf(stderr,
-		"%s: warning: FS is larger than the %dM that fsck can check!\n",
-			progname, (int) (N_BLOCKS16 / (1024L * 1024)));
-	}
-	inodes = atoi(token[1]);
-
-	/* Process mode line for root directory. */
-	getline(line, token);
-	mode = mode_con(token[0]);
-	usrid = atoi(token[1]);
-	grpid = atoi(token[2]);
-  } else {
-	lct = 0;
-	if (optind < argc) {
-		/* Maybe the prototype file is just a size.  Check. */
-		blocks = strtoul(optarg, (char **) NULL, 0);
-		if (blocks == 0) pexit("Can't open prototype file");
-	}
-	if (i == 0) {
-		/* The default for inodes is 3 blocks per inode, rounded up
-		 * to fill an inode block.  Above 20M, the average files are
-		 * sure to be larger because it is hard to fill up 20M with
-		 * tiny files, so reduce the default number of inodes.  This
-		 * default can always be overridden by using the -i option.
-		 */
-		i = blocks / 3;
-		if (blocks >= 20000) i = blocks / 4;
-		if (blocks >= 40000) i = blocks / 5;
-		if (blocks >= 60000) i = blocks / 6;
-		if (blocks >= 80000) i = blocks / 7;
-		if (blocks >= 100000) i = blocks / 8;
-		i += inodes_per_block - 1;
-		i = i / inodes_per_block * inodes_per_block;
-		if (i > INODE_MAX) i = INODE_MAX;
-	}
-	if (blocks < 5) pexit("Block count too small");
-	if (blocks > max_nrblocks)  {
-		printf("%d > %d\n",  blocks, max_nrblocks);
-		pexit("Block count too large");
-	}
-	if (i < 1) pexit("Inode count too small");
-	if (i > INODE_MAX) pexit("Inode count too large");
-	inodes = (ino_t) i;
-
-	/* Make simple file system of the given size, using defaults. */
-	mode = 040777;
-	usrid = BIN;
-	grpid = BINGRP;
-	simple = 1;
-  }
-  nrblocks = blocks;
-  nrinodes = inodes;
-
-  /* Open special. */
-  special(argv[--optind]);
-
-#ifdef UNIX
-  if (!donttest) {
-	static short testb[BLOCK_SIZE / sizeof(short)];
-
-	/* Try writing the last block of partition or diskette. */
-	lseek(fd, (off_t) (blocks - 1) * BLOCK_SIZE, SEEK_SET);
-	testb[0] = 0x3245;
-	testb[1] = 0x11FF;
-	if (write(fd, (char *) testb, BLOCK_SIZE) != BLOCK_SIZE)
-		pexit("File system is too big for minor device");
-	sync();			/* flush write, so if error next read fails */
-	lseek(fd, (off_t) (blocks - 1) * BLOCK_SIZE, SEEK_SET);
-	testb[0] = 0;
-	testb[1] = 0;
-	nread = read(fd, (char *) testb, BLOCK_SIZE);
-	if (nread != BLOCK_SIZE || testb[0] != 0x3245 || testb[1] != 0x11FF)
-		pexit("File system is too big for minor device");
-	lseek(fd, (off_t) (blocks - 1) * BLOCK_SIZE, SEEK_SET);
-	testb[0] = 0;
-	testb[1] = 0;
-	if (write(fd, (char *) testb, BLOCK_SIZE) != BLOCK_SIZE)
-		pexit("File system is too big for minor device");
-	lseek(fd, 0L, SEEK_SET);
-  }
-#endif
-
-  /* Make the file-system */
-
-  cache_init();
-
-#if (MACHINE == ATARI)
-  if (isdev) {
-	char block0[BLOCK_SIZE];
-	get_block((block_t) 0, block0);
-	/* Need to read twice; first time gets an empty block */
-	get_block((block_t) 0, block0);
-	/* Zero parts of the boot block so the disk won't be
-	 * recognized as a tos disk any more. */
-	block0[0] = block0[1] = 0;	/* branch code to boot code    */
-	strncpy(&block0[2], "MINIX ", (size_t) 6);
-	block0[16] = 0;		/* number of FATS              */
-	block0[17] = block0[18] = 0;	/* number of dir entries       */
-	block0[22] = block0[23] = 0;	/* sectors/FAT                 */
-	bzero(&block0[30], 480);/* boot code                   */
-	put_block((block_t) 0, block0);
-  } else
-#endif
-
-	put_block((block_t) 0, zero);	/* Write a null boot block. */
-
-  zone_shift = 0;		/* for future use */
-  zones = nrblocks >> zone_shift;
-
-  super(zones, inodes);
-
-  root_inum = alloc_inode(mode, usrid, grpid);
-  rootdir(root_inum);
-  if (simple == 0) eat_dir(root_inum);
-
-  if (print) print_fs();
-  flush();
-  return(0);
-
-  /* NOTREACHED */
-}				/* end main */
-
-
-/*================================================================
- *                    sizeup  -  determine device size
- *===============================================================*/
-block_t sizeup(device)
-char *device;
-{
-  int fd;
-  struct partition entry;
-
-  if ((fd = open(device, O_RDONLY)) == -1) return 0;
-  if (ioctl(fd, DIOCGETP, &entry) == -1) entry.size = cvu64(0);
-  close(fd);
-  return div64u(entry.size, BLOCK_SIZE);
-}
-
-
-/*================================================================
- *                 super  -  construct a superblock
- *===============================================================*/
-
-void super(zones, inodes)
-zone_t zones;
-ino_t inodes;
-{
-  unsigned int i;
-  int inodeblks;
-  int initblks;
-
-  zone_t initzones, nrzones, v1sq, v2sq;
-  zone_t zo;
-  struct super_block *sup;
-  char buf[BLOCK_SIZE], *cp;
-
-  for (cp = buf; cp < &buf[BLOCK_SIZE]; cp++) *cp = 0;
-  sup = (struct super_block *) buf;	/* lint - might use a union */
-
-  sup->s_ninodes = inodes;
-  if (fs_version == 1) {
-	sup->s_nzones = zones;
-  } else {
-	sup->s_nzones = 0;	/* not used in V2 - 0 forces errors early */
-	sup->s_zones = zones;
-  }
-  sup->s_imap_blocks = bitmapsize((bit_t) (1 + inodes), BLOCK_SIZE);
-  sup->s_zmap_blocks = bitmapsize((bit_t) zones, BLOCK_SIZE);
-  inode_offset = sup->s_imap_blocks + sup->s_zmap_blocks + 2;
-  inodeblks = (inodes + inodes_per_block - 1) / inodes_per_block;
-  initblks = inode_offset + inodeblks;
-  initzones = (initblks + (1 << zone_shift) - 1) >> zone_shift;
-  nrzones = nrblocks >> zone_shift;
-  sup->s_firstdatazone = (initblks + (1 << zone_shift) - 1) >> zone_shift;
-  zoff = sup->s_firstdatazone - 1;
-  sup->s_log_zone_size = zone_shift;
-  if (fs_version == 1) {
-	sup->s_magic = SUPER_MAGIC;	/* identify super blocks */
-	v1sq = (zone_t) V1_INDIRECTS * V1_INDIRECTS;
-	zo = V1_NR_DZONES + (long) V1_INDIRECTS + v1sq;
-  } else {
-	sup->s_magic = SUPER_V2;/* identify super blocks */
-	v2sq = (zone_t) V2_INDIRECTS(BLOCK_SIZE) * V2_INDIRECTS(BLOCK_SIZE);
-	zo = V2_NR_DZONES + (zone_t) V2_INDIRECTS(BLOCK_SIZE) + v2sq;
-  }
-  sup->s_max_size = zo * BLOCK_SIZE;
-  zone_size = 1 << zone_shift;	/* nr of blocks per zone */
-
-  put_block((block_t) 1, buf);
-
-  /* Clear maps and inodes. */
-  for (i = 2; i < initblks; i++) put_block((block_t) i, zero);
-
-  next_zone = sup->s_firstdatazone;
-  next_inode = 1;
-
-  zone_map = INODE_MAP + sup->s_imap_blocks;
-
-  insert_bit(zone_map, 0);	/* bit zero must always be allocated */
-  insert_bit((block_t) INODE_MAP, 0);	/* inode zero not used but
-					 * must be allocated */
-}
-
-
-/*================================================================
- *              rootdir  -  install the root directory
- *===============================================================*/
-void rootdir(inode)
-ino_t inode;
-{
-  zone_t z;
-
-  z = alloc_zone();
-  add_zone(inode, z, 32L, current_time);
-  enter_dir(inode, ".", inode);
-  enter_dir(inode, "..", inode);
-  incr_link(inode);
-  incr_link(inode);
-}
-
-
-/*================================================================
- *	    eat_dir  -  recursively install directory
- *===============================================================*/
-void eat_dir(parent)
-ino_t parent;
-{
-  /* Read prototype lines and set up directory. Recurse if need be. */
-  char *token[MAX_TOKENS], *p;
-  char line[LINE_LEN];
-  int mode, usrid, grpid, maj, min, f;
-  ino_t n;
-  zone_t z;
-  long size;
-
-  while (1) {
-	getline(line, token);
-	p = token[0];
-	if (*p == '$') return;
-	p = token[1];
-	mode = mode_con(p);
-	usrid = atoi(token[2]);
-	grpid = atoi(token[3]);
-	if (grpid & 0200) fprintf(stderr, "A.S.Tanenbaum\n");
-	n = alloc_inode(mode, usrid, grpid);
-
-	/* Enter name in directory and update directory's size. */
-	enter_dir(parent, token[0], n);
-	incr_size(parent, 16L);
-
-	/* Check to see if file is directory or special. */
-	incr_link(n);
-	if (*p == 'd') {
-		/* This is a directory. */
-		z = alloc_zone();	/* zone for new directory */
-		add_zone(n, z, 32L, current_time);
-		enter_dir(n, ".", n);
-		enter_dir(n, "..", parent);
-		incr_link(parent);
-		incr_link(n);
-		eat_dir(n);
-	} else if (*p == 'b' || *p == 'c') {
-		/* Special file. */
-		maj = atoi(token[4]);
-		min = atoi(token[5]);
-		size = 0;
-		if (token[6]) size = atoi(token[6]);
-		size = BLOCK_SIZE * size;
-		add_zone(n, (zone_t) ((maj << 8) | min), size, current_time);
-	} else {
-		/* Regular file. Go read it. */
-		if ((f = open(token[4], O_RDONLY)) < 0) {
-			fprintf(stderr, "%s: Can't open %s: %s\n",
-				progname, token[4], strerror(errno));
-		} else
-			eat_file(n, f);
-	}
-  }
-
-}
-
-/*================================================================
- * 		eat_file  -  copy file to MINIX
- *===============================================================*/
-/* Zonesize >= blocksize */
-void eat_file(inode, f)
-ino_t inode;
-int f;
-{
-  int ct, i, j, k;
-  zone_t z;
-  char buf[BLOCK_SIZE];
-  long timeval;
-
-  do {
-	for (i = 0, j = 0; i < zone_size; i++, j += ct) {
-		for (k = 0; k < BLOCK_SIZE; k++) buf[k] = 0;
-		if ((ct = read(f, buf, BLOCK_SIZE)) > 0) {
-			if (i == 0) z = alloc_zone();
-			put_block((z << zone_shift) + i, buf);
-		}
-	}
-	timeval = (dflag ? current_time : file_time(f));
-	if (ct) add_zone(inode, z, (long) j, timeval);
-  } while (ct == BLOCK_SIZE);
-  close(f);
-}
-
-
-
-/*================================================================
- *	    directory & inode management assist group
- *===============================================================*/
-void enter_dir(parent, name, child)
-ino_t parent, child;
-char *name;
-{
-  /* Enter child in parent directory */
-  /* Works for dir > 1 block and zone > block */
-  int i, j, k, l, off;
-  block_t b;
-  zone_t z;
-  char *p1, *p2;
-  struct direct dir_entry[NR_DIR_ENTRIES(BLOCK_SIZE)];
-  d1_inode ino1[V1_INODES_PER_BLOCK];
-  d2_inode ino2[V2_INODES_PER_BLOCK(BLOCK_SIZE)];
-  int nr_dzones;
-
-  b = ((parent - 1) / inodes_per_block) + inode_offset;
-  off = (parent - 1) % inodes_per_block;
-
-  if (fs_version == 1) {
-	get_block(b, (char *) ino1);
-	nr_dzones = V1_NR_DZONES;
-  } else {
-	get_block(b, (char *) ino2);
-	nr_dzones = V2_NR_DZONES;
-  }
-  for (k = 0; k < nr_dzones; k++) {
-	if (fs_version == 1) {
-		z = ino1[off].d1_zone[k];
-		if (z == 0) {
-			z = alloc_zone();
-			ino1[off].d1_zone[k] = z;
-		}
-	} else {
-		z = ino2[off].d2_zone[k];
-		if (z == 0) {
-			z = alloc_zone();
-			ino2[off].d2_zone[k] = z;
-		}
-	}
-	for (l = 0; l < zone_size; l++) {
-		get_block((z << zone_shift) + l, (char *) dir_entry);
-		for (i = 0; i < NR_DIR_ENTRIES(BLOCK_SIZE); i++) {
-			if (dir_entry[i].d_ino == 0) {
-				dir_entry[i].d_ino = child;
-				p1 = name;
-				p2 = dir_entry[i].d_name;
-				j = 14;
-				while (j--) {
-					*p2++ = *p1;
-					if (*p1 != 0) p1++;
-				}
-				put_block((z << zone_shift) + l, (char *) dir_entry);
-				if (fs_version == 1) {
-					put_block(b, (char *) ino1);
-				} else {
-					put_block(b, (char *) ino2);
-				}
-				return;
-			}
-		}
-	}
-  }
-
-  printf("Directory-inode %d beyond direct blocks.  Could not enter %s\n",
-         parent, name);
-  pexit("Halt");
-}
-
-
-void add_zone(n, z, bytes, cur_time)
-ino_t n;
-zone_t z;
-long bytes, cur_time;
-{
-  if (fs_version == 1) {
-	add_z_1(n, z, bytes, cur_time);
-  } else {
-	add_z_2(n, z, bytes, cur_time);
-  }
-}
-
-void add_z_1(n, z, bytes, cur_time)
-ino_t n;
-zone_t z;
-long bytes, cur_time;
-{
-  /* Add zone z to inode n. The file has grown by 'bytes' bytes. */
-
-  int off, i;
-  block_t b;
-  zone_t indir;
-  zone1_t blk[V1_INDIRECTS];
-  d1_inode *p;
-  d1_inode inode[V1_INODES_PER_BLOCK];
-
-  b = ((n - 1) / V1_INODES_PER_BLOCK) + inode_offset;
-  off = (n - 1) % V1_INODES_PER_BLOCK;
-  get_block(b, (char *) inode);
-  p = &inode[off];
-  p->d1_size += bytes;
-  p->d1_mtime = cur_time;
-  for (i = 0; i < V1_NR_DZONES; i++)
-	if (p->d1_zone[i] == 0) {
-		p->d1_zone[i] = (zone1_t) z;
-		put_block(b, (char *) inode);
-		return;
-	}
-  put_block(b, (char *) inode);
-
-  /* File has grown beyond a small file. */
-  if (p->d1_zone[V1_NR_DZONES] == 0)
-	p->d1_zone[V1_NR_DZONES] = (zone1_t) alloc_zone();
-  indir = p->d1_zone[V1_NR_DZONES];
-  put_block(b, (char *) inode);
-  b = indir << zone_shift;
-  get_block(b, (char *) blk);
-  for (i = 0; i < V1_INDIRECTS; i++)
-	if (blk[i] == 0) {
-		blk[i] = (zone1_t) z;
-		put_block(b, (char *) blk);
-		return;
-	}
-  pexit("File has grown beyond single indirect");
-}
-
-void add_z_2(n, z, bytes, cur_time)
-ino_t n;
-zone_t z;
-long bytes, cur_time;
-{
-  /* Add zone z to inode n. The file has grown by 'bytes' bytes. */
-
-  int off, i;
-  block_t b;
-  zone_t indir;
-  zone_t blk[V2_INDIRECTS(BLOCK_SIZE)];
-  d2_inode *p;
-  d2_inode inode[V2_INODES_PER_BLOCK(BLOCK_SIZE)];
-
-  b = ((n - 1) / V2_INODES_PER_BLOCK(BLOCK_SIZE)) + inode_offset;
-  off = (n - 1) % V2_INODES_PER_BLOCK(BLOCK_SIZE);
-  get_block(b, (char *) inode);
-  p = &inode[off];
-  p->d2_size += bytes;
-  p->d2_mtime = cur_time;
-  for (i = 0; i < V2_NR_DZONES; i++)
-	if (p->d2_zone[i] == 0) {
-		p->d2_zone[i] = z;
-		put_block(b, (char *) inode);
-		return;
-	}
-  put_block(b, (char *) inode);
-
-  /* File has grown beyond a small file. */
-  if (p->d2_zone[V2_NR_DZONES] == 0) p->d2_zone[V2_NR_DZONES] = alloc_zone();
-  indir = p->d2_zone[V2_NR_DZONES];
-  put_block(b, (char *) inode);
-  b = indir << zone_shift;
-  get_block(b, (char *) blk);
-  for (i = 0; i < V2_INDIRECTS(BLOCK_SIZE); i++)
-	if (blk[i] == 0) {
-		blk[i] = z;
-		put_block(b, (char *) blk);
-		return;
-	}
-  pexit("File has grown beyond single indirect");
-}
-
-
-void incr_link(n)
-ino_t n;
-{
-  /* Increment the link count to inode n */
-  int off;
-  block_t b;
-
-  b = ((n - 1) / inodes_per_block) + inode_offset;
-  off = (n - 1) % inodes_per_block;
-  if (fs_version == 1) {
-	d1_inode inode1[V1_INODES_PER_BLOCK];
-
-	get_block(b, (char *) inode1);
-	inode1[off].d1_nlinks++;
-	put_block(b, (char *) inode1);
-  } else {
-	d2_inode inode2[V2_INODES_PER_BLOCK(BLOCK_SIZE)];
-
-	get_block(b, (char *) inode2);
-	inode2[off].d2_nlinks++;
-	put_block(b, (char *) inode2);
-  }
-}
-
-
-void incr_size(n, count)
-ino_t n;
-long count;
-{
-  /* Increment the file-size in inode n */
-  block_t b;
-  int off;
-
-  b = ((n - 1) / inodes_per_block) + inode_offset;
-  off = (n - 1) % inodes_per_block;
-  if (fs_version == 1) {
-	d1_inode inode1[V1_INODES_PER_BLOCK];
-
-	get_block(b, (char *) inode1);
-	inode1[off].d1_size += count;
-	put_block(b, (char *) inode1);
-  } else {
-	d2_inode inode2[V2_INODES_PER_BLOCK(BLOCK_SIZE)];
-
-	get_block(b, (char *) inode2);
-	inode2[off].d2_size += count;
-	put_block(b, (char *) inode2);
-  }
-}
-
-
-/*================================================================
- * 	 	     allocation assist group
- *===============================================================*/
-PRIVATE ino_t alloc_inode(mode, usrid, grpid)
-int mode, usrid, grpid;
-{
-  ino_t num;
-  int off;
-  block_t b;
-
-  num = next_inode++;
-  if (num > nrinodes) pexit("File system does not have enough inodes");
-  b = ((num - 1) / inodes_per_block) + inode_offset;
-  off = (num - 1) % inodes_per_block;
-  if (fs_version == 1) {
-	d1_inode inode1[V1_INODES_PER_BLOCK];
-
-	get_block(b, (char *) inode1);
-	inode1[off].d1_mode = mode;
-	inode1[off].d1_uid = usrid;
-	inode1[off].d1_gid = grpid;
-	put_block(b, (char *) inode1);
-  } else {
-	d2_inode inode2[V2_INODES_PER_BLOCK(BLOCK_SIZE)];
-
-	get_block(b, (char *) inode2);
-	inode2[off].d2_mode = mode;
-	inode2[off].d2_uid = usrid;
-	inode2[off].d2_gid = grpid;
-	put_block(b, (char *) inode2);
-  }
-
-  /* Set the bit in the bit map. */
-  /* DEBUG FIXME.  This assumes the bit is in the first inode map block. */
-  insert_bit((block_t) INODE_MAP, (int) num);
-  return(num);
-}
-
-
-PRIVATE zone_t alloc_zone()
-{
-  /* Allocate a new zone */
-  /* Works for zone > block */
-  block_t b;
-  int i;
-  zone_t z;
-
-  z = next_zone++;
-  b = z << zone_shift;
-  if ((b + zone_size) > nrblocks)
-	pexit("File system not big enough for all the files");
-  for (i = 0; i < zone_size; i++)
-	put_block(b + i, zero);	/* give an empty zone */
-  /* DEBUG FIXME.  This assumes the bit is in the first zone map block. */
-  insert_bit(zone_map, (int) (z - zoff));	/* lint, NOT OK because
-						 * z hasn't been broken
-						 * up into block +
-						 * offset yet. */
-  return(z);
-}
-
-
-void insert_bit(block, bit)
-block_t block;
-int bit;
-{
-  /* Insert 'count' bits in the bitmap */
-  int w, s;
-  short buf[BLOCK_SIZE / sizeof(short)];
-
-  if (block < 0) pexit("insert_bit called with negative argument");
-  get_block(block, (char *) buf);
-  w = bit / (8 * sizeof(short));
-  s = bit % (8 * sizeof(short));
-  buf[w] |= (1 << s);
-  put_block(block, (char *) buf);
-}
-
-
-/*================================================================
- * 		proto-file processing assist group
- *===============================================================*/
-int mode_con(p)
-char *p;
-{
-  /* Convert string to mode */
-  int o1, o2, o3, mode;
-  char c1, c2, c3;
-
-  c1 = *p++;
-  c2 = *p++;
-  c3 = *p++;
-  o1 = *p++ - '0';
-  o2 = *p++ - '0';
-  o3 = *p++ - '0';
-  mode = (o1 << 6) | (o2 << 3) | o3;
-  if (c1 == 'd') mode += I_DIRECTORY;
-  if (c1 == 'b') mode += I_BLOCK_SPECIAL;
-  if (c1 == 'c') mode += I_CHAR_SPECIAL;
-  if (c1 == '-') mode += I_REGULAR;
-  if (c2 == 'u') mode += I_SET_UID_BIT;
-  if (c3 == 'g') mode += I_SET_GID_BIT;
-  return(mode);
-}
-
-void getline(line, parse)
-char *parse[MAX_TOKENS];
-char line[LINE_LEN];
-{
-  /* Read a line and break it up in tokens */
-  int k;
-  char c, *p;
-  int d;
-
-  for (k = 0; k < MAX_TOKENS; k++) parse[k] = 0;
-  for (k = 0; k < LINE_LEN; k++) line[k] = 0;
-  k = 0;
-  parse[0] = 0;
-  p = line;
-  while (1) {
-	if (++k > LINE_LEN) pexit("Line too long");
-	d = fgetc(proto);
-	if (d == EOF) pexit("Unexpected end-of-file");
-	*p = d;
-	if (*p == '\n') lct++;
-	if (*p == ' ' || *p == '\t') *p = 0;
-	if (*p == '\n') {
-		*p++ = 0;
-		*p = '\n';
-		break;
-	}
-	p++;
-  }
-
-  k = 0;
-  p = line;
-  lastp = line;
-  while (1) {
-	c = *p++;
-	if (c == '\n') return;
-	if (c == 0) continue;
-	parse[k++] = p - 1;
-	do {
-		c = *p++;
-	} while (c != 0 && c != '\n');
-  }
-}
-
-
-/*================================================================
- *			other stuff
- *===============================================================*/
-void check_mtab(devname)
-char *devname;			/* /dev/hd1 or whatever */
-{
-/* Check to see if the special file named in s is mounted. */
-
-  int n;
-  char special[PATH_MAX + 1], mounted_on[PATH_MAX + 1], version[10], rw_flag[10];
-
-  if (load_mtab("mkfs") < 0) return;
-  while (1) {
-	n = get_mtab_entry(special, mounted_on, version, rw_flag);
-	if (n < 0) return;
-	if (strcmp(devname, special) == 0) {
-		/* Can't mkfs on top of a mounted file system. */
-		fprintf(stderr, "%s: %s is mounted on %s\n",
-			progname, devname, mounted_on);
-		exit(1);
-	}
-  }
-}
-
-
-long file_time(f)
-int f;
-{
-#ifdef UNIX
-  struct stat statbuf;
-  fstat(f, &statbuf);
-  return(statbuf.st_mtime);
-#else				/* fstat not supported by DOS */
-  return(0L);
-#endif
-}
-
-
-void pexit(s)
-char *s;
-{
-  fprintf(stderr, "%s: %s\n", progname, s);
-  if (lct != 0)
-	fprintf(stderr, "Line %d being processed when error detected.\n", lct);
-  flush();
-  exit(2);
-}
-
-
-void copy(from, to, count)
-char *from, *to;
-int count;
-{
-  while (count--) *to++ = *from++;
-}
-
-
-void print_fs()
-{
-  int i, j;
-  ino_t k;
-  d1_inode inode1[V1_INODES_PER_BLOCK];
-  d2_inode inode2[V2_INODES_PER_BLOCK(BLOCK_SIZE)];
-  unsigned short usbuf[BLOCK_SIZE / sizeof(unsigned short)];
-  block_t b, inode_limit;
-  struct direct dir[NR_DIR_ENTRIES(BLOCK_SIZE)];
-
-  get_block((block_t) 1, (char *) usbuf);
-  printf("\nSuperblock: ");
-  for (i = 0; i < 8; i++) printf("%06o ", usbuf[i]);
-  get_block((block_t) 2, (char *) usbuf);
-  printf("...\nInode map:  ");
-  for (i = 0; i < 9; i++) printf("%06o ", usbuf[i]);
-  get_block((block_t) 3, (char *) usbuf);
-  printf("...\nZone  map:  ");
-  for (i = 0; i < 9; i++) printf("%06o ", usbuf[i]);
-  printf("...\n");
-
-  k = 0;
-  for (b = inode_offset; k < nrinodes; b++) {
-	if (fs_version == 1) {
-		get_block(b, (char *) inode1);
-	} else {
-		get_block(b, (char *) inode2);
-	}
-	for (i = 0; i < inodes_per_block; i++) {
-		k = inodes_per_block * (int) (b - inode_offset) + i + 1;
-		/* Lint but OK */
-		if (k > nrinodes) break;
-		if (fs_version == 1) {
-			if (inode1[i].d1_mode != 0) {
-				printf("Inode %2d:  mode=", k);
-				printf("%06o", inode1[i].d1_mode);
-				printf("  uid=%2d  gid=%2d  size=",
-				inode1[i].d1_uid, inode1[i].d1_gid);
-				printf("%6ld", inode1[i].d1_size);
-				printf("  zone[0]=%d\n", inode1[i].d1_zone[0]);
-			}
-			if ((inode1[i].d1_mode & I_TYPE) == I_DIRECTORY) {
-				/* This is a directory */
-				get_block(inode1[i].d1_zone[0], (char *) dir);
-				for (j = 0; j < NR_DIR_ENTRIES(BLOCK_SIZE); j++)
-					if (dir[j].d_ino)
-						printf("\tInode %2d: %s\n", dir[j].d_ino, dir[j].d_name);
-			}
-		} else {
-			if (inode2[i].d2_mode != 0) {
-				printf("Inode %2d:  mode=", k);
-				printf("%06o", inode2[i].d2_mode);
-				printf("  uid=%2d  gid=%2d  size=",
-				inode2[i].d2_uid, inode2[i].d2_gid);
-				printf("%6ld", inode2[i].d2_size);
-				printf("  zone[0]=%ld\n", inode2[i].d2_zone[0]);
-			}
-			if ((inode2[i].d2_mode & I_TYPE) == I_DIRECTORY) {
-				/* This is a directory */
-				get_block(inode2[i].d2_zone[0], (char *) dir);
-				for (j = 0; j < NR_DIR_ENTRIES(BLOCK_SIZE); j++)
-					if (dir[j].d_ino)
-						printf("\tInode %2d: %s\n", dir[j].d_ino, dir[j].d_name);
-			}
-		}
-	}
-  }
-
-  printf("%d inodes used.     %d zones used.\n", next_inode - 1, next_zone);
-}
-
-
-int read_and_set(n)
-block_t n;
-{
-/* The first time a block is read, it returns all 0s, unless there has
- * been a write.  This routine checks to see if a block has been accessed.
- */
-
-  int w, s, mask, r;
-
-  if (sizeof(char *) == 2 && n >= MAX_INIT) pexit("can't initialize past 128M");
-  w = n / 8;
-  s = n % 8;
-  mask = 1 << s;
-  r = (umap[w] & mask ? 1 : 0);
-  umap[w] |= mask;
-  return(r);
-}
-
-void usage()
-{
-  fprintf(stderr,
-	  "Usage: %s [-1dlot] [-b blocks] [-i inodes] special [proto]\n",
-	  progname);
-  exit(1);
-}
-
-/*================================================================
- *		      get_block & put_block for MS-DOS
- *===============================================================*/
-#ifdef DOS
-
-/*
- *	These are the get_block and put_block routines
- *	when compiling & running mkfs.c under MS-DOS.
- *
- *	It requires the (asembler) routines absread & abswrite
- *	from the file diskio.asm. Since these routines just do
- *	as they are told (read & write the sector specified),
- *	a local cache is used to minimize the i/o-overhead for
- *	frequently used blocks.
- *
- *	The global variable "file" determines whether the output
- *	is to a disk-device or to a binary file.
- */
-
-
-#define PH_SECTSIZE	   512	/* size of a physical disk-sector */
-
-
-char *derrtab[14] = {
-	     "no error",
-	     "disk is read-only",
-	     "unknown unit",
-	     "device not ready",
-	     "bad command",
-	     "data error",
-	     "internal error: bad request structure length",
-	     "seek error",
-	     "unknown media type",
-	     "sector not found",
-	     "printer out of paper (?)",
-	     "write fault",
-	     "read error",
-	     "general error"
-};
-
-#define	CACHE_SIZE	20	/* 20 block-buffers */
-
-
-struct cache {
-  char blockbuf[BLOCK_SIZE];
-  block_t blocknum;
-  int dirty;
-  int usecnt;
-} cache[CACHE_SIZE];
-
-
-void special(string)
-char *string;
-{
-
-  if (string[1] == ':' && string[2] == 0) {
-	/* Format: d: or d:fname */
-	disk = (string[0] & ~32) - 'A';
-	if (disk > 1 && !override)	/* safety precaution */
-		pexit("Bad drive specifier for special");
-  } else {
-	file = 1;
-	if ((fd = creat(string, BWRITE)) == 0)
-		pexit("Can't open special file");
-  }
-}
-
-void get_block(n, buf)
-block_t n;
-char buf[BLOCK_SIZE];
-{
-  /* Get a block to the user */
-  struct cache *bp, *fp;
-
-  /* First access returns a zero block */
-  if (read_and_set(n) == 0) {
-	copy(zero, buf, BLOCK_SIZE);
-	return;
-  }
-
-  /* Look for block in cache */
-  fp = 0;
-  for (bp = cache; bp < &cache[CACHE_SIZE]; bp++) {
-	if (bp->blocknum == n) {
-		copy(bp, buf, BLOCK_SIZE);
-		bp->usecnt++;
-		return;
-	}
-
-	/* Remember clean block */
-	if (bp->dirty == 0)
-		if (fp) {
-			if (fp->usecnt > bp->usecnt) fp = bp;
-		} else
-			fp = bp;
-  }
-
-  /* Block not in cache, get it */
-  if (!fp) {
-	/* No clean buf, flush one */
-	for (bp = cache, fp = cache; bp < &cache[CACHE_SIZE]; bp++)
-		if (fp->usecnt > bp->usecnt) fp = bp;
-	mx_write(fp->blocknum, fp);
-  }
-  mx_read(n, fp);
-  fp->dirty = 0;
-  fp->usecnt = 0;
-  fp->blocknum = n;
-  copy(fp, buf, BLOCK_SIZE);
-}
-
-void put_block(n, buf)
-block_t n;
-char buf[BLOCK_SIZE];
-{
-  /* Accept block from user */
-  struct cache *fp, *bp;
-
-  (void) read_and_set(n);
-
-  /* Look for block in cache */
-  fp = 0;
-  for (bp = cache; bp < &cache[CACHE_SIZE]; bp++) {
-	if (bp->blocknum == n) {
-		copy(buf, bp, BLOCK_SIZE);
-		bp->dirty = 1;
-		return;
-	}
-
-	/* Remember clean block */
-	if (bp->dirty == 0)
-		if (fp) {
-			if (fp->usecnt > bp->usecnt) fp = bp;
-		} else
-			fp = bp;
-  }
-
-  /* Block not in cache */
-  if (!fp) {
-	/* No clean buf, flush one */
-	for (bp = cache, fp = cache; bp < &cache[CACHE_SIZE]; bp++)
-		if (fp->usecnt > bp->usecnt) fp = bp;
-	mx_write(fp->blocknum, fp);
-  }
-  fp->dirty = 1;
-  fp->usecnt = 1;
-  fp->blocknum = n;
-  copy(buf, fp, BLOCK_SIZE);
-}
-
-void cache_init()
-{
-  struct cache *bp;
-  for (bp = cache; bp < &cache[CACHE_SIZE]; bp++) bp->blocknum = -1;
-}
-
-void flush()
-{
-  /* Flush all dirty blocks to disk */
-  struct cache *bp;
-
-  for (bp = cache; bp < &cache[CACHE_SIZE]; bp++)
-	if (bp->dirty) {
-		mx_write(bp->blocknum, bp);
-		bp->dirty = 0;
-	}
-}
-
-/*==================================================================
- *			hard read & write etc.
- *=================================================================*/
-#define MAX_RETRIES	5
-
-
-void mx_read(blocknr, buf)
-int blocknr;
-char buf[BLOCK_SIZE];
-{
-
-  /* Read the requested MINIX-block in core */
-  char (*bp)[PH_SECTSIZE];
-  int sectnum, retries, err;
-
-  if (file) {
-	lseek(fd, (off_t) blocknr * BLOCK_SIZE, 0);
-	if (read(fd, buf, BLOCK_SIZE) != BLOCK_SIZE)
-		pexit("mx_read: error reading file");
-  } else {
-	sectnum = blocknr * (BLOCK_SIZE / PH_SECTSIZE);
-	for (bp = buf; bp < &buf[BLOCK_SIZE]; bp++) {
-		retries = MAX_RETRIES;
-		do
-			err = absread(disk, sectnum, bp);
-		while (err && --retries);
-
-		if (retries) {
-			sectnum++;
-		} else {
-			dexit("mx_read", sectnum, err);
-		}
-	}
-  }
-}
-
-void mx_write(blocknr, buf)
-int blocknr;
-char buf[BLOCK_SIZE];
-{
-  /* Write the MINIX-block to disk */
-  char (*bp)[PH_SECTSIZE];
-  int retries, sectnum, err;
-
-  if (file) {
-	lseek(fd, blocknr * BLOCK_SIZE, 0);
-	if (write(fd, buf, BLOCK_SIZE) != BLOCK_SIZE) {
-		pexit("mx_write: error writing file");
-	}
-  } else {
-	sectnum = blocknr * (BLOCK_SIZE / PH_SECTSIZE);
-	for (bp = buf; bp < &buf[BLOCK_SIZE]; bp++) {
-		retries = MAX_RETRIES;
-		do {
-			err = abswrite(disk, sectnum, bp);
-		} while (err && --retries);
-
-		if (retries) {
-			sectnum++;
-		} else {
-			dexit("mx_write", sectnum, err);
-		}
-	}
-  }
-}
-
-
-void dexit(s, sectnum, err)
-int sectnum, err;
-char *s;
-{
-  printf("Error: %s, sector: %d, code: %d, meaning: %s\n",
-         s, sectnum, err, derrtab[err]);
-  exit(2);
-}
-
-#endif
-
-/*================================================================
- *		      get_block & put_block for UNIX
- *===============================================================*/
-#ifdef UNIX
-
-void special(string)
-char *string;
-{
-  fd = creat(string, 0777);
-  close(fd);
-  fd = open(string, O_RDWR);
-  if (fd < 0) pexit("Can't open special file");
-#if (MACHINE == ATARI)
-  {
-	struct stat statbuf;
-
-	if (fstat(fd, &statbuf) < 0) return;
-	isdev = (statbuf.st_mode & S_IFMT) == S_IFCHR
-		||
-		(statbuf.st_mode & S_IFMT) == S_IFBLK
-		;
-  }
-#endif
-}
-
-
-
-void get_block(n, buf)
-block_t n;
-char buf[BLOCK_SIZE];
-{
-/* Read a block. */
-
-  int k;
-
-  /* First access returns a zero block */
-  if (read_and_set(n) == 0) {
-	copy(zero, buf, BLOCK_SIZE);
-	return;
-  }
-  lseek(fd, (off_t) n * BLOCK_SIZE, SEEK_SET);
-  k = read(fd, buf, BLOCK_SIZE);
-  if (k != BLOCK_SIZE) {
-	pexit("get_block couldn't read");
-  }
-}
-
-void put_block(n, buf)
-block_t n;
-char buf[BLOCK_SIZE];
-{
-/* Write a block. */
-
-  (void) read_and_set(n);
-
-  /* XXX - check other lseeks too. */
-  if (lseek(fd, (off_t) n * BLOCK_SIZE, SEEK_SET) == (off_t) -1) {
-	pexit("put_block couldn't seek");
-  }
-  if (write(fd, buf, BLOCK_SIZE) != BLOCK_SIZE) {
-	pexit("put_block couldn't write");
-  }
-}
-
-
-/* Dummy routines to keep source file clean from #ifdefs */
-
-void flush()
-{
-  return;
-}
-
-void cache_init()
-{
-  return;
-}
-
-#endif
Index: trunk/minix/commands/simple/passwd.c
===================================================================
--- trunk/minix/commands/simple/passwd.c	(revision 9)
+++ 	(revision )
@@ -1,260 +1,0 @@
-/* passwd - change a passwd			Author: Adri Koppes */
-
-/* chfn, chsh - change full name, shell		Added by: Kees J. Bot */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <string.h>
-#include <signal.h>
-#include <pwd.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <sys/stat.h>
-#include <minix/minlib.h>
-#include <stdio.h>
-
-_PROTOTYPE(void report, (char *label));
-_PROTOTYPE(void quit, (int ex_stat));
-_PROTOTYPE(void fatal, (char *label));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(int goodchars, (char *s));
-_PROTOTYPE(int main, (int argc, char **argv));
-
-char pw_file[] = "/etc/passwd";
-char sh_file[] = "/etc/shadow";
-char pw_tmp[] = "/etc/ptmp";
-char bad[] = "Permission denied\n";
-char buf[1024];
-
-enum action {
-  PASSWD, CHFN, CHSH
-} action = PASSWD;
-
-char *arg0;
-
-void report(label)
-char *label;
-{
-  int e = errno;
-  fprintf(stderr, "%s: ", arg0);
-  fflush(stderr);
-  errno = e;
-  perror(label);
-}
-
-void quit(ex_stat)
-int ex_stat;
-{
-  if (unlink(pw_tmp) < 0 && errno != ENOENT) {
-	report(pw_tmp);
-	ex_stat = 1;
-  }
-  exit(ex_stat);
-}
-
-void fatal(label)
-char *label;
-{
-  report(label);
-  quit(1);
-}
-
-void usage()
-{
-  static char *usages[] = {
-	"passwd [user]\n",
-	"chfn [user] fullname\n",
-	"chsh [user] shell\n"
-  };
-  std_err(usages[(int) action]);
-  exit(1);
-}
-
-int goodchars(s)
-char *s;
-{
-  int c;
-
-  while ((c = *s++) != 0) {
-	if (c == ':' || c < ' ' || c >= 127) return(0);
-  }
-  return(1);
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int uid, cn, n;
-  int fd_pwd, fd_tmp;
-  FILE *fp_tmp;
-  time_t salt;
-  struct passwd *pwd;
-  char *name, pwname[9], oldpwd[9], newpwd[9], newcrypted[14], sl[2];
-  char *argn;
-  int shadow = 0;
-
-  if ((arg0 = strrchr(argv[0], '/')) != 0)
-	arg0++;
-  else
-	arg0 = argv[0];
-
-  if (strcmp(arg0, "chfn") == 0)
-	action = CHFN;
-  else if (strcmp(arg0, "chsh") == 0)
-	action = CHSH;
-
-  uid = getuid();
-
-  n = action == PASSWD ? 1 : 2;
-
-  if (argc != n && argc != n + 1) usage();
-
-  if (argc == n) {
-	pwd = getpwuid(uid);
-	strcpy(pwname, pwd->pw_name);
-	name = pwname;
-  } else {
-	name = argv[1];
-	pwd = getpwnam(name);
-  }
-  if (pwd == NULL || ((uid != pwd->pw_uid) && uid != 0)) {
-	std_err(bad);
-	exit(1);
-  }
-
-  switch (action) {
-      case PASSWD:
-	if (pwd->pw_passwd[0] == '#' && pwd->pw_passwd[1] == '#') {
-		/* The password is found in the shadow password file. */
-		shadow = 1;
-		strncpy(pwname, pwd->pw_passwd + 2, 8);
-		pwname[8] = 0;
-		name = pwname;
-		setpwfile(sh_file);
-		if ((pwd= getpwnam(name)) == NULL) {
-			std_err(bad);
-			exit(1);
-		}
-		printf("Changing the shadow password of %s\n", name);
-	} else {
-		printf("Changing the password of %s\n", name);
-	}
-
-	oldpwd[0] = 0;
-	if (pwd->pw_passwd[0] != '\0' && uid != 0) {
-		strcpy(oldpwd, getpass("Old password:"));
-		if (strcmp(pwd->pw_passwd, crypt(oldpwd, pwd->pw_passwd)) != 0)
-		{
-			std_err(bad);
-			exit(1);
-		}
-	}
-	for (;;) {
-		strcpy(newpwd, getpass("New password:"));
-
-		if (newpwd[0] == '\0')
-			std_err("Password cannot be null");
-		else if (strcmp(newpwd, getpass("Retype password:")) != 0)
-			std_err("Passwords don't match");
-		else
-			break;
-
-		std_err(", try again\n");
-	}
-	time(&salt);
-	sl[0] = (salt & 077) + '.';
-	sl[1] = ((salt >> 6) & 077) + '.';
-	for (cn = 0; cn < 2; cn++) {
-		if (sl[cn] > '9') sl[cn] += 7;
-		if (sl[cn] > 'Z') sl[cn] += 6;
-	}
-	strcpy(newcrypted, crypt(newpwd, sl));
-	break;
-
-      case CHFN:
-      case CHSH:
-	argn = argv[argc - 1];
-
-	if (strlen(argn) > (action == CHFN ? 80 : 60) || !goodchars(argn)) {
-		std_err(bad);
-		exit(1);
-	}
-  }
-
-  signal(SIGHUP, SIG_IGN);
-  signal(SIGINT, SIG_IGN);
-  signal(SIGQUIT, SIG_IGN);
-  signal(SIGTERM, SIG_IGN);
-
-  umask(0);
-  n = 10;
-  while ((fd_tmp = open(pw_tmp, O_RDWR | O_CREAT | O_EXCL, 0400)) < 0) {
-	if (errno != EEXIST) fatal("Can't create temporary file");
-
-	if (n-- > 0) {
-		sleep(2);
-	} else {
-		fprintf(stderr, "Password file busy, try again later.\n");
-		exit(1);
-	}
-  }
-
-  if ((fp_tmp = fdopen(fd_tmp, "w+")) == NULL) fatal(pw_tmp);
-
-  setpwent();
-  while ((pwd = getpwent()) != 0) {
-	if (strcmp(name, pwd->pw_name) == 0) {
-		switch (action) {
-		    case PASSWD:
-			pwd->pw_passwd = newcrypted;
-			break;
-		    case CHFN:
-			pwd->pw_gecos = argn;
-			break;
-		    case CHSH:
-		    	pwd->pw_shell = argn;
-		    	break;
-		}
-	}
-	if (strcmp(pwd->pw_shell, "/bin/sh") == 0
-		|| strcmp(pwd->pw_shell, "/usr/bin/sh") == 0
-	)
-		pwd->pw_shell = "";
-
-	fprintf(fp_tmp, "%s:%s:%s:",
-		pwd->pw_name,
-		pwd->pw_passwd,
-		itoa(pwd->pw_uid)
-	);
-	if (ferror(fp_tmp)) fatal(pw_tmp);
-
-	fprintf(fp_tmp, "%s:%s:%s:%s\n",
-		itoa(pwd->pw_gid),
-		pwd->pw_gecos,
-		pwd->pw_dir,
-		pwd->pw_shell
-	);
-	if (ferror(fp_tmp)) fatal(pw_tmp);
-  }
-  endpwent();
-  if (fflush(fp_tmp) == EOF) fatal(pw_tmp);
-
-  if (lseek(fd_tmp, (off_t) 0, SEEK_SET) != 0)
-	fatal("Can't reread temp file");
-
-  if ((fd_pwd = open(shadow ? sh_file : pw_file, O_WRONLY | O_TRUNC)) < 0)
-	fatal("Can't recreate password file");
-
-  while ((n = read(fd_tmp, buf, sizeof(buf))) != 0) {
-	if (n < 0 || write(fd_pwd, buf, n) != n) {
-		report("Error rewriting password file, tell root!");
-		exit(1);
-	}
-  }
-  close(fd_tmp);
-  close(fd_pwd);
-  quit(0);
-}
Index: trunk/minix/commands/simple/paste.c
===================================================================
--- trunk/minix/commands/simple/paste.c	(revision 9)
+++ 	(revision )
@@ -1,456 +1,0 @@
-/* paste - laminate files		Author: David Ihnat */
-
-/* Paste - a recreation of the Unix(Tm) paste(1) command.
- *
- * syntax: paste file1 file2 ... paste -dLIST file1 file2 ... paste -s [-dLIST]
- * file1 file2 ...
- *
- * Copyright (C) 1984 by David M. Ihnat
- *
- * This program is a total rewrite of the Bell Laboratories Unix(Tm) command of
- * the same name, as of System V.  It contains no proprietary code, and
- * therefore may be used without violation of any proprietary agreements
- * whatsoever.  However, you will notice that the program is copyrighted by
- * me.  This is to assure the program does *not* fall into the public domain.
- * Thus, I may specify just what I am now: This program may be freely copied
- * and distributed, provided this notice remains; it may not be sold for
- * profit without express written consent of the author. Please note that I
- * recreated the behavior of the Unix(Tm) 'paste' command as faithfully as
- * possible, with minor exceptions (noted below); however, I haven't run a
- * full set of regression * tests.  Thus, the user of this program accepts
- * full responsibility for any effects or loss; in particular, the author is
- * not responsible for any losses, explicit or incidental, that may be
- * incurred through use of this program.
- *
- * The changes to the program, with one exception, are transparent to a user
- * familiar with the Unix command of the same name.  These changes are:
- *
- * 1) The '-s' option had a bug in the Unix version when used with multiple
- *    files.  (It would repeat each file in a list, i.e., for 
- *
- *		paste -s file1 file2 file3
- *
- * it would list
- *
- *	 <file1\n><file1\n><file2\n><file1\n><file2\n><file3\n>
- *
- * I fixed this, and reported the bug to the providers of the command in Unix.
- *
- * 2) The list of valid escape sequences has been expanded to include \b,\f, 
- *    and \r.  (Just because *I* can't imagine why you'd want to use them 
- *    doesn't mean I should keep them from you.)
- *
- * 3) There is no longer any restriction on line length.
- *
- * I ask that any bugs (and, if possible, fixes) be reported to me when
- * possible.  -David Ihnat (312) 784-4544 ihuxx!ignatz
- */
-
-/* Modified to run under MINIX 1.1 by David O. Tinker  (416) 978-3636
- * (utgpu!dtinker) Sept. 19, 1987
- */
-
-/* Modified to conform to POSIX 1003.2/Draft10 standard 23rd Sept. 1990
- * Changes:
- * 	- the arguments can be in any order
- *	- removed the ToUpper function
- * by Thomas Brupbacher (tobr@mw.lpc.ethz.ch)
- */
-
-#include <errno.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-/* I'd love to use enums, but not everyone has them.  Portability, y'know. */
-#define NODELIM		1
-#define USAGE		2
-#define BADFILE		3
-#define TOOMANY		4
-
-#define	TAB		'\t'
-#define	NL		'\n'
-#define	BS		'\b'
-#define	FF		'\f'
-#define	CR		'\r'
-#define DEL             '\177'
-#define SPACE		' '
-#define BACKSLASH	'\\'
-
-#define	_MAXSZ		512
-#define _MAXFILES	12
-#define	CLOSED		((FILE *)-1)
-#define ENDLIST		((FILE *)-2)
-
-char *cmdnam;
-
-short int sflag;
-static char default_delims[] = {TAB};	/* default delimiter string	 */
-char *delims;			/* the pointer to the delimiters        */
-int number_of_delims = 1;	/* number of delimiters to use	 	 */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void docol, (int nfiles, char **fnamptr));
-_PROTOTYPE(void doserial, (int nfiles, char **fnamptr));
-_PROTOTYPE(void delimbuild, (char *strptr));
-_PROTOTYPE(void prerr, (int etype, char *estring));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  char **arg_ptr;		/* used to save argv, needed for docol() etc */
-  int num_files = 0;		/* Number of filenames specified on cmd line */
-  sflag = 0;
-  delims = default_delims;	/* use default delimiters */
-
-  cmdnam = *argv;
-
-  if (argc >= 2) {
-
-	/* Skip invocation name */
-	argv++;
-	argc--;
-
-	/* Save argv */
-	arg_ptr = argv;
-	/* First, parse input options */
-
-	while (argc-- > 0) {
-		if (argv[0][0] == '-' && argv[0][1] != '\0') {
-			switch (argv[0][1]) {
-			    case 'd':
-				/* Delimiter character(s) */
-				if (*(++argv) == '\0')
-					prerr(NODELIM, "");
-				else
-					delimbuild(*(argv));
-				argc--;
-				break;
-
-			    case 's':	sflag++;	break;
-
-			    default:	prerr(USAGE, "");
-			}
-			argv++;
-		} else {
-			num_files++;
-			argv++;
-		}
-	}
-
-	/* If there are more than MAX_FILES files on the command
-	 * line, exit with error message.						 */
-	if (num_files > _MAXFILES) prerr(TOOMANY, "");
-
-	/* If no files specified, simply exit.  Otherwise, if not the
-	 * old '-s' option, process all files. If '-s', then process
-	 * files one-at-a-time. */
-
-	if (!sflag)
-		docol(num_files, arg_ptr);	/* Column paste */
-	else
-		doserial(num_files, arg_ptr);	/* Serial paste */
-
-	exit(0);
-  } else
-	prerr(USAGE, "");
-  return(0);
-}
-
-void docol(nfiles, fnamptr)
-int nfiles;
-char **fnamptr;
-{
-  char iobuff[_MAXSZ];		/* i/o buffer for the fgets */
-  short int somedone;		/* flag for blank field handling */
-
-  /* There is a strange case where all files are just ready to be
-   * closed, or will on this round.  In that case, the string of
-   * delimiters must be preserved.  delbuf[1] ->delbuf[MAXFILES+1]
-   * provides intermediate storage for closed files, if needed;
-   * delbuf[0] is the current index.
-   */
-  char delbuf[_MAXFILES + 2];
-
-  FILE *fileptr[_MAXFILES + 1];
-
-  int filecnt;			/* Set to number of files to process */
-  register char *delimptr;	/* Cycling delimiter pointer */
-  int index;			/* Working variable */
-  int strend;			/* End of string in buffer */
-
-  /* Perform column paste.  First, attempt to open all files. (This
-   * could be expanded to an infinite number of files, but at the
-   * (considerable) expense of remembering the file and its current
-   * offset, then opening/reading/closing.  The commands' utility
-   * doesn't warrant the effort; at least, to me...) 
-   */
-
-  for (filecnt = 0; (nfiles > 0); fnamptr++) {
-	if ((fnamptr[0][0] == '-') && (fnamptr[0][1] != '\0')) {
-		if (fnamptr[0][1] == 'd') fnamptr++;
-	} else {
-		nfiles--;
-		if (fnamptr[0][0] == '-') {
-			fileptr[filecnt++] = stdin;
-		} else {
-			fileptr[filecnt] = fopen(fnamptr[0], "r");
-			if (fileptr[filecnt++] == NULL)
-				prerr(BADFILE, *fnamptr);
-		}
-	}
-  }
-
-  fileptr[filecnt] = ENDLIST;	/* End of list. */
-
-  /* Have all files.  Now, read a line from each file, and output to
-   * stdout.  Notice that the old 511 character limitation on the line
-   * length no longer applies, since this program doesn't do the
-   * buffering.  Do this until you go through the loop and don't
-   * successfully read from any of the files.
-   */
-  for (; filecnt;) {
-	somedone = 0;		/* Blank field handling flag */
-	delimptr = delims;	/* Start at beginning of delim list */
-	delbuf[0] = 0;		/* No squirreled delims */
-
-	for (index = 0; (fileptr[index] != ENDLIST) && filecnt; index++) {
-		/* Read a line and immediately output. If it's too
-		 * big for the buffer, then dump what was read and go
-		 * back for more.
-		 * 
-		 * Otherwise, if it is from the last file, then leave
-		 * the carriage return in place; if not, replace with
-		 * a delimiter (if any) 
- 		 */
-
-		strend = 0;	/* Set so can easily detect EOF */
-
-		if (fileptr[index] != CLOSED)
-			while (fgets(iobuff, (_MAXSZ - 1), 
-					fileptr[index]) != NULL) {
-				strend = strlen(iobuff);/* Did the buf fill? */
-
-				if (strend == (_MAXSZ - 1)) {
-					/* Gosh, what a long line. */
-					fputs(iobuff, stdout);
-					strend = 0;
-					continue;
-				}
-
-				/* Ok got whole line in buffer. */
-				break;	/* Out of loop for this file */
-			}
-
-		/* Ended either on an EOF (well, actually NULL
-		 * return-- it *could* be some sort of file error,
-		 * but but if the file was opened successfully, this
-		 * is unlikely. Besides, error checking on streams
-		 * doesn't allow us to decide exactly what went
-		 * wrong, so I'm going to be very Unix-like and
-		 * ignore it!), or a closed file, or a received line.
-		 * If an EOF, close the file and mark it in the list.
-		 * In any case, output the delimiter of choice. 
-		 */
-
-		if (!strend) {
-			if (fileptr[index] != CLOSED) {
-				fclose(fileptr[index]);
-				fileptr[index] = CLOSED;
-				filecnt--;
-			}
-
-			/* Is this the end of the whole thing? */
-			if ((fileptr[index + 1] == ENDLIST) && !somedone)
-				continue;	/* EXITS */
-
-			/* Ok, some files not closed this line. Last file? */
-			if (fileptr[index + 1] == ENDLIST) {
-				if (delbuf[0]) {
-					fputs(&delbuf[1], stdout);
-					delbuf[0] = 0;
-				}
-				putc((int) NL, stdout);
-				continue;	/* Next read of files */
-			} else {
-				/* Closed file; setup delim */
-				if (*delimptr != DEL) {
-					delbuf[0]++;
-					delbuf[delbuf[0]] = *delimptr++;
-					delbuf[delbuf[0] + 1] = '\0';
-				} else
-					delimptr++;
-			}
-
-			/* Reset end of delimiter string if necessary */
-			if (*delimptr == '\0') delimptr = delims;
-		} else {
-			/* Some data read. */
-			somedone++;
-
-			/* Any saved delims? */
-			if (delbuf[0]) {
-				fputs(&delbuf[1], stdout);
-				delbuf[0] = 0;
-			}
-
-			/* If last file, last char will be NL. */
-			if (fileptr[index + 1] != ENDLIST) {
-				if (*delimptr == DEL) {
-					delimptr++;
-					iobuff[strend - 1] = '\0';/* No delim*/
-				} else
-					iobuff[strend - 1] = *delimptr++;
-			}
-			if (*delimptr == '\0') delimptr = delims;
-
-			/* Now dump the buffer */
-			fputs(iobuff, stdout);
-			fflush(stdout);
-		}
-	}
-  }
-}
-
-void doserial(nfiles, fnamptr)
-int nfiles;
-char **fnamptr;
-{
-  /* Do serial paste.  Simply scarf characters, performing
-   * one-character buffering to facilitate delim processing. 
-   */
-
-  register int charnew, charold;
-  register char *delimptr;
-
-  register FILE *fileptr;
-
-  for (; nfiles != 0; fnamptr++) {
-	if ((fnamptr[0][0] == '-') && (fnamptr[0][1] != '\0')) {
-		if (fnamptr[0][1] == 'd') fnamptr++;
-	} else {
-		if (fnamptr[0][0] == '-') {
-			fileptr = stdin;
-		} else {
-			fileptr = fopen(*fnamptr, "r");
-
-			if (fileptr == NULL) prerr(BADFILE, *fnamptr);
-		}
-
-		/* The file is open; just keep taking characters,
-		 * stashing them in charnew; output charold,
-		 * converting to the appropriate delimiter character
-		 * if needful.  After the EOF, simply output
-		 * 'charold' if it's a newline; otherwise, output it
-		 * and then a newline. 
-		 */
-
-		delimptr = delims;	/* Set up for delimiter string */
-
-		if ((charold = getc(fileptr)) == EOF) {
-			/* Empty file! */
-			putc(NL, stdout);
-			fflush(stdout);
-			continue;	/* Go on to the next file */
-		}
-
-		/* Ok, 'charold' is set up.  Hit it! */
-
-		while ((charnew = getc(fileptr)) != EOF) {
-			/* Ok, process the old character */
-			if (charold == NL) {
-				if (*delimptr != DEL)
-					putc((int) *delimptr++, stdout);
-
-				/* Reset pointer at end of delimiter string */
-				if (*delimptr == '\0') delimptr = delims;
-			} else
-				putc(charold, stdout);
-
-			charold = charnew;
-		}
-
-		/* Ok, hit EOF.  Process that last character */
-
-		putc(charold, stdout);
-		if ((char) charold != NL) putc(NL, stdout);
-		fflush(stdout);
-		nfiles--;
-	}
-  }
-}
-
-void delimbuild(strptr)
-char *strptr;
-{
-  /* Process the delimiter string into something that can be used by
-   * the routines.  This involves, primarily, collapsing the backslash
-   * representations of special characters into their actual values,
-   * and terminating the string in a manner that the routines can
-   * recognize.  The set of possible backslash characters has been
-   * expanded beyond that recognized by the vanilla Unix(Tm) version. 
-   */
-
-  register char *strout;
-
-  delims = strptr;		/* delims now points to argv[...]	 */
-  strout = strptr;		/* Start at the same place, anyway */
-
-  while (*strptr) {
-	if (*strptr != '\\')	/* Is it an escape character? */
-		*strout++ = *strptr++;	/* No, just transfer it */
-	else {
-		strptr++;	/* Get past escape character */
-
-		switch (*strptr) {
-		    case '0':	*strout++ = DEL;	break;
-
-		    case 't':	*strout++ = TAB;	break;
-
-		    case 'n':	*strout++ = NL;	break;
-
-		    case 'b':	*strout++ = BS;	break;
-
-		    case 'f':	*strout++ = FF;	break;
-
-		    case 'r':	*strout++ = CR;	break;
-
-		    case '\\':
-			*strout++ = BACKSLASH;
-			break;
-
-		    default:	*strout++ = *strptr;
-		}
-
-		strptr++;
-	}
-
-  }
-  *strout = '\0';		/* Heaven forfend that we forget this! */
-}
-
-void prerr(etype, estring)
-int etype;
-char *estring;
-{
-  switch (etype) {
-      case USAGE:
-	fprintf(stderr, "%s : Usage: %s [-s] [-d <delimiters>] file1 file2 ...\n", cmdnam, cmdnam);
-	break;
-
-      case NODELIM:
-	fprintf(stderr, "%s : no delimiters\n", cmdnam);
-	break;
-
-      case BADFILE:
-	fprintf(stderr, "%s : %s : cannot open\n", cmdnam, estring);
-	break;
-
-      case TOOMANY:
-	fprintf(stderr, "%s : too many files\n", cmdnam);
-	break;
-  }
-  exit(1);
-}
Index: trunk/minix/commands/simple/ping.c
===================================================================
--- trunk/minix/commands/simple/ping.c	(revision 9)
+++ 	(revision )
@@ -1,151 +1,0 @@
-/*
-ping.c
-*/
-
-#define DEBUG	1
-
-#include <sys/types.h>
-#include <errno.h>
-#include <signal.h>
-#include <net/gen/netdb.h>
-#include <sys/ioctl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <net/gen/oneCsum.h>
-#include <fcntl.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/ip_hdr.h>
-#include <net/gen/icmp_hdr.h>
-#include <net/gen/ip_io.h>
-
-#define WRITE_SIZE 30
-char buffer[16*1024];
-
-int main(int argc, char *argv[]);
-
-#if DEBUG
-#define where() fprintf(stderr, "%s %d:", __FILE__, __LINE__);
-#endif
-
-#if __STDC__
-#define PROTO(x,y) x y
-#else
-#define PROTO(x,y) X ()
-#endif
-
-PROTO (int main, (int argc, char *argv[]) );
-static PROTO (void sig_hand, (int signal) );
-
-main(argc, argv)
-int argc;
-char *argv[];
-{
-	int fd, i;
-	int result, result1;
-	nwio_ipopt_t ipopt;
-	ip_hdr_t *ip_hdr;
-	int ihl;
-	icmp_hdr_t *icmp_hdr;
-	ipaddr_t dst_addr;
-	struct hostent *hostent;
-	int length;
-
-	if (argc<2 || argc>3)
-	{
-		fprintf(stderr, "Usage: %s hostname [-l length] [-t timeout]\n",
-			argv[0]);
-		exit(1);
-	}
-	hostent= gethostbyname(argv[1]);
-	if (!hostent)
-	{
-		dst_addr= inet_addr(argv[1]);
-		if (dst_addr == -1)
-		{
-			fprintf(stderr, "%s: unknown host (%s)\n",
-				argv[0], argv[1]);
-			exit(1);
-		}
-	}
-	else
-		dst_addr= *(ipaddr_t *)(hostent->h_addr);
-	if (argc == 3)
-	{
-		length= strtol (argv[2], (char **)0, 0);
-		if (length< sizeof(icmp_hdr_t) + IP_MIN_HDR_SIZE)
-		{
-			fprintf(stderr, "%s: length too small (%s)\n",
-				argv[0], argv[2]);
-			exit(1);
-		}
-	}
-	else
-		length= WRITE_SIZE;
-
-	fd= open ("/dev/ip", O_RDWR);
-	if (fd<0)
-		perror("open"), exit(1);
-
-	ipopt.nwio_flags= NWIO_COPY | NWIO_PROTOSPEC;
-	ipopt.nwio_proto= 1;
-
-	result= ioctl (fd, NWIOSIPOPT, &ipopt);
-	if (result<0)
-		perror("ioctl (NWIOSIPOPT)"), exit(1);
-
-	result= ioctl (fd, NWIOGIPOPT, &ipopt);
-	if (result<0)
-		perror("ioctl (NWIOGIPOPT)"), exit(1);
-
-	for (i= 0; i< 20; i++)
-	{
-		ip_hdr= (ip_hdr_t *)buffer;
-		ip_hdr->ih_dst= dst_addr;
-
-		icmp_hdr= (icmp_hdr_t *)(buffer+20);
-		icmp_hdr->ih_type= 8;
-		icmp_hdr->ih_code= 0;
-		icmp_hdr->ih_chksum= 0;
-		icmp_hdr->ih_chksum= ~oneC_sum(0, (u16_t *)icmp_hdr,
-			WRITE_SIZE-20);
-		result= write(fd, buffer, length);
-		if (result<0)
-		{
-			perror("write");
-			exit(1);
-		}
-		if (result != length)
-		{
-			where();
-			fprintf(stderr, "result= %d\n", result);
-			exit(1);
-		}
-
-		alarm(0);
-		signal (SIGALRM, sig_hand);
-		alarm(1);
-
-		result= read(fd, buffer, sizeof(buffer));
-		if (result>= 0 || errno != EINTR)
-			break;
-	}
-	if (i >= 20)
-	{
-		printf("no answer from %s\n", argv[1]);
-		exit(1);
-	}
-	if (result<0)
-	{
-		perror ("read");
-		exit(1);
-	}
-	printf("%s is alive\n", argv[1]);
-	exit(0);
-}
-
-static void sig_hand(signal)
-int signal;
-{
-}
Index: trunk/minix/commands/simple/pr.c
===================================================================
--- trunk/minix/commands/simple/pr.c	(revision 9)
+++ 	(revision )
@@ -1,504 +1,0 @@
-/* pr - print files			Author: Michiel Huisjes */
-
-/* Pr - print files
- *
- * Author: Michiel Huisjes.
- * Modified: Jacob P. Bunschoten.	(30 nov 87)
- *	When "columns" is not given and numbering is on:
- *		line numbers are correlated with input lines.
- *	(try pr [-1] -n file )
- *	tabs are accounted for.
- *	When numbering is turned on, width know this.
- *	automatic line-folding. -f to get the original program.
- *	backspaces are accounted for. -b to disable this.
- *	multi-column mode changed.
- *	header can be given and used.
- *	format changed may occur between printing of several files:
- *		pr -l30 file1 -w75 file2
- *
- * Modified: Rick Thomas.		(Sept 12, 1988)
- *	added "-M" option to cover functionality of old "-n" option,
- *	and made "-n" option behavior compatible with system V.
- *
- * Usage: pr [+page] [-columns] [-h header] [-wwidth] [-llength] [-ntm] [files]
- *        -t : Do not print the 5 line header and trailer at the page.
- *        -n : Turn on line numbering.
- *        -M : Use "Minix" style line numbering -- Each page begins at
- *             a line number that is an even multiple of the page length.
- *             Like the listings in Appendix E of the book.
- *        +page    : Start printing at page n.
- *        -columns : Print files in n-columns.
- *        -l length: Take the length of the page to be n instead of 66
- *        -h header: Take next argument as page header.
- *        -w width  : Take the width of the page to be n instead of default 79
- *	  -f : do not fold lines.
- *
- * Modified: Lars Fredriksen		(Jan 19, 1990)
- *	fixed the program so that
- *		pr -n *.c
- *	would work. The clobal variable 'width' was decremented
- *	by NUM_WIDTH, for each file, resulting in width finally
- *	being so small that nothing was printed. Used the local
- *	variable 'w' for the width adjustment (in print())
- *
- * Modified: Kenneth J. Hendrickson	(10 April 1991)
- *	date in header should be last modification date for files,
- *	and the current time for stdin.
- *
- * Modified: Kees J. Bot		(5 October 1992)
- *	Use localtime(3) to get the date, it knows TZ.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-
-#define DEF_LENGTH	66
-#define DEF_WIDTH	79
-#define NUM_WIDTH	8
-#define TAB_WIDTH	8	/* fixed tab_width */
-
-/* Used to compute next (fixed) tabstop */
-#define TO_TAB(x)	(( (x) + TAB_WIDTH ) & ~07 )
-
-typedef char BOOL;
-
-#define FALSE		0
-#define TRUE		1
-
-/* EAT:	eat rest of input line */
-#define EAT(fp)		while((c=getc(fp))!='\n' && c!=EOF)
-
-/* L_BUF: calculate address of pointer to char (string) used in format */
-#define L_BUF(i,j)	* (char **) (line_buf + (i + j*length)*sizeof(char *))
-
-char *header;
-BOOL no_header;
-BOOL number = FALSE;
-BOOL minix_number = FALSE;
-BOOL ext_header_set = FALSE;	/* external header given */
-BOOL back_space = TRUE;		/* back space correction in line width */
-BOOL dont_fold = FALSE;		/* original. If the line does not fit eat it. */
-short columns;
-short cwidth;
-short start_page = 1;
-short width = DEF_WIDTH;
-short length = DEF_LENGTH;
-short linenr;
-char *line_buf;			/* used in format for multi-column output */
-
-char output[1024];
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(static char *myalloc, (size_t size));
-_PROTOTYPE(char skip_page, (int lines, int width, FILE * filep));
-_PROTOTYPE(void format, (FILE * filep));
-_PROTOTYPE(void print_page, (int pagenr, int maxcol));
-_PROTOTYPE(void print, (FILE * filep));
-_PROTOTYPE(void out_header, (int page));
-_PROTOTYPE(void print_time, (time_t t));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  FILE *file;
-  char *ptr;
-  int index = 1;		/* index is one ahead of argc */
-  int line, col;
-
-  setbuf(stdout, output);
-  do {
-	if (argc == index)	/* No arguments (left) */
-		goto pr_files;
-
-	ptr = argv[index++];
-	if (*ptr == '+') {
-		start_page = atoi(++ptr);
-		continue;
-	}
-	if (*ptr != '-') {	/* no flags */
-		index--;
-		goto pr_files;
-	}
-	if (*++ptr >= '0' && *ptr <= '9') {
-		columns = atoi(ptr);
-		if (columns <= 0) columns = 1;
-		continue;	/* Fetch next flag */
-	}
-	while (*ptr) switch (*ptr++) {
-		    case 't':	no_header = TRUE;	break;
-		    case 'n':
-			number = TRUE;
-			minix_number = FALSE;
-			break;
-		    case 'M':
-			number = TRUE;
-			minix_number = TRUE;
-			break;
-		    case 'h':
-			header = argv[index++];
-			ext_header_set = TRUE;
-			break;
-		    case 'w':
-			if ((width = atoi(ptr)) <= 0) width = DEF_WIDTH;
-			*ptr = '\0';
-			break;
-		    case 'l':
-			if ((length = atoi(ptr)) <= 0) length = DEF_LENGTH;
-			*ptr = '\0';
-			break;
-		    case 'b':	/* back_space correction off */
-			back_space = FALSE;
-			break;
-		    case 'f':	/* do not fold lines */
-			dont_fold = TRUE;
-			break;
-		    default:
-			fprintf(stderr, "Usage: %s [+page] [-columns] [-h header] [-w<width>] [-l<length>] [-nMt] [files]\n", argv[0]);
-			exit(1);
-		}
-	continue;		/* Scan for next flags */
-
-
-	/* ==============  flags are read. Print the file(s) ========= */
-
-pr_files:
-
-	if (!no_header) length -= 10;
-
-	if (columns) {
-		cwidth = width / columns + 1;
-		if (columns > width) {
-			fprintf(stderr, "Too many columns for page width.\n");
-			exit(1);
-		}
-
-		/* Allocate piece of mem to hold some pointers */
-		line_buf = myalloc(length * columns * sizeof(char *));
-	}
-	for (line = 0; line < length; line++)
-		for (col = 0; col < columns; col++)
-			L_BUF(line, col) = NULL;
-
-	if (length <= 0) {
-		fprintf(stderr, "Minimal length should be %d\n", no_header ?
-			1 : 11);
-		exit(1);
-	}
-	while (index <= argc) {	/* print all files, including stdin */
-		if (index < argc && (*argv[index] == '-' || *argv[index] == '+'))
-			break;	/* Format change */
-
-		if (argc == index) {	/* no file specified, so stdin */
-			if (!ext_header_set) header = "";
-			file = stdin;
-		} else {
-			if ((file = fopen(argv[index], "r")) == (FILE *) 0) {
-				fprintf(stderr, "Cannot open %s\n", argv[index++]);
-				continue;
-			}
-			if (!ext_header_set) header = argv[index];
-		}
-		if (columns)
-			format(file);
-		else
-			print(file);
-		fclose(file);
-		if (++index >= argc)
-			break;	/* all files (including stdin) done */
-	}
-	if (index >= argc) break;
-	/* When control comes here. format changes are to be done.
-	 * reinitialize some variables */
-	if (!no_header) length += 10;
-
-	start_page = 1;
-	ext_header_set = FALSE;
-	if (columns) free(line_buf);
-  } while (index <= argc);	/* "pr -l60" should work too */
-
-  (void) fflush(stdout);
-  return(0);
-}
-
-char skip_page(lines, width, filep)
-int lines, width;
-FILE *filep;
-{
-  short c;
-  int char_cnt;
-  int w;
-
-  do {
-	w = width;
-	if (number)		/* first lines are shorter */
-		if (!columns ||	/* called from print(file)  */
-		    !(lines % columns))	/* called from format(file) */
-			w -= NUM_WIDTH;
-
-	char_cnt = 0;
-	while ((c = getc(filep)) != '\n' && c != EOF && char_cnt < w) {
-		/* Calculate if this line is longer than "width (w)"
-		 * characters */
-		if (c == '\b' && back_space) {
-			if (--char_cnt < 0) char_cnt = 0;
-		} else if (c == '\t')
-			char_cnt = TO_TAB(char_cnt);
-		else
-			char_cnt++;
-	}
-	if (dont_fold && c != '\n' && c != EOF) EAT(filep);
-	lines--;
-	if (c == '\n') linenr++;
-  } while (lines > 0 && c != EOF);
-
-  return c;			/* last char read */
-}
-
-void format(filep)
-FILE *filep;
-{
-  char buf[512];
-  short c = '\0';
-  short index, lines, i;
-  short page_number = 0;
-  short maxcol = columns;
-  short wdth;
-  short line, col;
-
-  do {
-	/* Check printing of page */
-	page_number++;
-
-	if (page_number < start_page && c != EOF) {
-		c = (char) skip_page(columns * length, cwidth, filep);
-		continue;
-	}
-	if (c == EOF) return;
-
-	lines = columns * length;
-	for (line = 0; line < length; line++)
-		for (col = 0; col < columns; col++) {
-			if (L_BUF(line, col) != NULL)
-				free(L_BUF(line, col));
-			L_BUF(line, col) = (char *) NULL;
-		}
-	line = 0;
-	col = 0;
-	do {
-		index = 0;
-		wdth = cwidth - 1;
-		if (number && !col)	/* need room for numbers */
-			wdth -= NUM_WIDTH;
-
-		/* Intermidiate colums are shortened by 1 char */
-		/* Last column not */
-		if (col + 1 == columns) wdth++;
-		for (i = 0; i < wdth - 1; i++) {
-			c = getc(filep);
-			if (c == '\n' || c == EOF) break;
-
-			if (c == '\b' && back_space) {
-				buf[index++] = '\b';
-				if (--i < 0) {	/* just in case ... */
-					i = 0;
-					index = 0;
-				}
-			} else if (c == '\t') {
-				int cnt, max;
-
-				max = TO_TAB(i);
-				for (cnt = i; cnt < max; cnt++)
-					buf[index++] = ' ';
-				i = max - 1;
-			} else
-				buf[index++] = (char) c;
-		}
-		buf[index++] = '\0';
-		/* Collected enough chars (or eoln, or EOF) */
-
-		/* First char is EOF */
-		if (i == 0 && lines == columns * length && c == EOF) return;
-
-		/* Alloc mem to hold this (sub) string */
-		L_BUF(line, col) = myalloc(index * sizeof(char));
-		strcpy(L_BUF(line, col), buf);
-
-		line++;
-		line %= length;
-		if (line == 0) {
-			col++;
-			col %= columns;
-		}
-		if (dont_fold && c != '\n' && c != EOF) EAT(filep);
-		lines--;	/* line ready for output */
-		if (c == EOF) {
-			maxcol = columns - lines / length;
-		}
-	} while (c != EOF && lines);
-	print_page(page_number, maxcol);
-  } while (c != EOF);
-}
-
-void print_page(pagenr, maxcol)
-short pagenr, maxcol;
-{
-  short pad, i, j;
-  short width;
-  char *p;
-
-  if (minix_number)
-	linenr = (pagenr - 1) * length + 1;
-  else
-	linenr = 1;
-
-  if (!no_header) out_header(pagenr);
-
-  for (i = 0; i < length; i++) {
-	for (j = 0; j < maxcol; j++) {
-		width = cwidth;
-		if (number && j == 0) {	/* first columns */
-			printf("%7.7d ", linenr++);	/* 7 == NUM_WIDTH-1 */
-			width -= NUM_WIDTH;
-		}
-		pad = 0;
-		if (p = (char *) L_BUF(i, j))
-			for (; pad < width - 1 && *p; pad++) putchar(*p++);
-		if (j < maxcol - 1) while (pad++ < width - 1)
-				putchar(' ');
-	}
-	putchar('\n');
-  }
-  if (!no_header) printf("\n\n\n\n\n");
-}
-
-void print(filep)
-FILE *filep;
-{
-  short c = '\0';
-  short page_number = 0;
-  short lines;
-  short cnt;
-  short w = width;
-  BOOL pr_number = TRUE;	/* only real lines are numbered, not folded
-			 * parts */
-
-  linenr = 1;
-  if (number) w -= NUM_WIDTH;
-
-  do {
-	/* Check printing of page */
-	page_number++;
-
-	if (page_number < start_page && c != EOF) {
-		pr_number = FALSE;
-		c = skip_page(length, w, filep);
-		if (c == '\n') pr_number = TRUE;
-		continue;
-	}
-	if (c == EOF) return;
-
-	if (minix_number) linenr = (page_number - 1) * length + 1;
-
-	if (page_number == start_page) c = getc(filep);
-
-	/* Print the page */
-	lines = length;
-	while (lines && c != EOF) {
-		if (lines == length && !no_header) out_header(page_number);
-		if (number)
-			if (pr_number)
-				printf("%7.7d ", linenr++);	/* 7 == NUM_WIDTH-1 */
-			else
-				printf("%7c ", ' ');	/* 7 == NUM_WIDTH-1 */
-		pr_number = FALSE;
-		cnt = 0;
-		while (c != '\n' && c != EOF && cnt < w) {
-			if (c == '\t') {
-				int i, max;
-				max = TO_TAB(cnt);
-				for (i = cnt; i < max; i++) putchar(' ');
-				cnt = max - 1;
-			} else if (c == '\b' && back_space) {
-				putchar('\b');
-				cnt--;
-			} else
-				putchar(c);
-			c = getc(filep);
-			cnt++;
-		}
-		putchar('\n');
-		if (dont_fold && c != '\n' && c != EOF) EAT(filep);
-		lines--;
-		if (c == '\n') {
-			c = getc(filep);
-			pr_number = TRUE;
-		}
-	}
-	if (lines == length)	/* We never printed anything on this
-				 * page --  */
-		return;		/* even the header, so dont try to fill it up */
-	if (!no_header)		/* print the trailer -- 5 blank lines */
-		printf("\n\n\n\n\n");
-  } while (c != EOF);
-
-  /* Fill last page */
-  if (page_number >= start_page) {
-	while (lines--) putchar('\n');
-  }
-}
-
-static char *myalloc(size)
-size_t size;			/* How many bytes */
-{
-  void *ptr;
-
-  ptr = malloc(size);
-  if (ptr == NULL) {
-	fprintf(stderr, "malloc returned NULL\n");
-	exit(1);
-  }
-  return(char *) ptr;
-}
-
-void out_header(page)
-short page;
-{
-  time_t t;
-  struct stat buf;
-
-  if (strlen(header)) {
-	stat(header, &buf);	/* use last modify time for file */
-	t = buf.st_mtime;
-  } else
-	(void) time(&t);	/* use current time for stdin */
-  print_time(t);
-  printf("  %s   Page %d\n\n\n", header, page);
-}
-
-char *moname[] = {
-	  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-	  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-/* Print the date. */
-void print_time(t)
-time_t t;
-{
-  struct tm *tm;
-
-  tm = localtime(&t);
-
-  printf("\n\n%s %2d %2d:%02d %d",
-         moname[tm->tm_mon],
-         tm->tm_mday,
-         tm->tm_hour,
-         tm->tm_min,
-         1900 + tm->tm_year
-	);
-}
Index: trunk/minix/commands/simple/pr_routes.c
===================================================================
--- trunk/minix/commands/simple/pr_routes.c	(revision 9)
+++ 	(revision )
@@ -1,307 +1,0 @@
-/*
-vmd/cmd/simple/pr_routes.c
-*/
-
-#define _POSIX_C_SOURCE 2
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/ip_io.h>
-#include <net/gen/route.h>
-#include <net/gen/netdb.h>
-#include <net/gen/inet.h>
-
-#define N_IF	64	/* More than enough? */
-
-char *prog_name;
-int all_devices;
-char *ifname;
-ipaddr_t iftab[N_IF];
-
-static void print_header(void);
-static void print_route(nwio_route_t *route);
-static void fill_iftab(void);
-static char *get_ifname(ipaddr_t addr);
-static void fatal(char *fmt, ...);
-static void usage(void);
-
-int main(int argc, char *argv[])
-{
-	int nr_routes, i;
-	nwio_route_t route;
-	nwio_ipconf_t ip_conf;
-	unsigned long ioctl_cmd;
-	int ip_fd;
-	int result;
-	int c;
-	char *ip_device, *cp;
-	int a_flag, i_flag, o_flag;
-	char *I_arg;
-
-	prog_name= argv[0];
-
-	a_flag= 0;
-	i_flag= 0;
-	o_flag= 0;
-	I_arg= NULL;
-	while ((c =getopt(argc, argv, "?aI:io")) != -1)
-	{
-		switch(c)
-		{
-		case '?':
-			usage();
-		case 'a':
-			if (a_flag)
-				usage();
-			a_flag= 1;
-			break;
-		case 'I':
-			if (I_arg)
-				usage();
-			I_arg= optarg;
-			break;
-		case 'i':
-			if (i_flag || o_flag)
-				usage();
-			i_flag= 1;
-			break;
-		case 'o':
-			if (i_flag || o_flag)
-				usage();
-			o_flag= 1;
-			break;
-		default:
-			fprintf(stderr, "%s: getopt failed: '%c'\n",
-				prog_name, c);
-			exit(1);
-		}
-	}
-	if (optind != argc)
-		usage();
-
-	ip_device= I_arg;
-	all_devices= a_flag;
-
-	if (i_flag)
-		ioctl_cmd= NWIOGIPIROUTE;
-	else
-		ioctl_cmd= NWIOGIPOROUTE;
-
-	if (ip_device == NULL)
-		ip_device= getenv("IP_DEVICE");
-	ifname= ip_device;
-	if (ip_device == NULL)
-		ip_device= IP_DEVICE;
-		
-	ip_fd= open(ip_device, O_RDONLY);
-	if (ip_fd == -1)
-	{
-		fprintf(stderr, "%s: unable to open %s: %s\n", prog_name,
-			ip_device, strerror(errno));
-		exit(1);
-	}
-
-	if (!all_devices && ifname)
-	{
-		cp= strrchr(ip_device, '/');
-		if (cp)
-			ifname= cp+1;
-	}
-	else
-	{
-		ifname= NULL;
-		fill_iftab();
-	}
-
-	result= ioctl(ip_fd, NWIOGIPCONF, &ip_conf);
-	if (result == -1)
-	{
-		fprintf(stderr, "%s: unable to NWIOIPGCONF: %s\n",
-			prog_name, strerror(errno));
-		exit(1);
-	}
-
-	route.nwr_ent_no= 0;
-	result= ioctl(ip_fd, ioctl_cmd, &route);
-	if (result == -1)
-	{
-		fprintf(stderr, "%s: unable to NWIOGIPxROUTE: %s\n",
-			prog_name, strerror(errno));
-		exit(1);
-	}
-	print_header();
-	nr_routes= route.nwr_ent_count;
-	for (i= 0; i<nr_routes; i++)
-	{
-		route.nwr_ent_no= i;
-		result= ioctl(ip_fd, ioctl_cmd, &route);
-		if (result == -1)
-		{
-			fprintf(stderr, "%s: unable to NWIOGIPxROUTE: %s\n",
-				prog_name, strerror(errno));
-			exit(1);
-		}
-		if (all_devices || route.nwr_ifaddr == ip_conf.nwic_ipaddr)
-			print_route(&route);
-	}
-	exit(0);
-}
-
-int ent_width= 5;
-int if_width= 4;
-int dest_width= 18;
-int gateway_width= 15;
-int dist_width= 4;
-int pref_width= 5;
-int mtu_width= 4;
-
-static void print_header(void)
-{
-	printf("%*s ", ent_width, "ent #");
-	printf("%*s ", if_width, "if");
-	printf("%*s ", dest_width, "dest");
-	printf("%*s ", gateway_width, "gateway");
-	printf("%*s ", dist_width, "dist");
-	printf("%*s ", pref_width, "pref");
-	printf("%*s ", mtu_width, "mtu");
-	printf("%s", "flags");
-	printf("\n");
-}
-
-static char *cidr2a(ipaddr_t addr, ipaddr_t mask)
-{
-	ipaddr_t testmask= 0xFFFFFFFF;
-	int n;
-	static char result[sizeof("255.255.255.255/255.255.255.255")];
-
-	for (n= 32; n >= 0; n--)
-	{
-		if (mask == htonl(testmask))
-			break;
-		testmask= (testmask << 1) & 0xFFFFFFFF;
-	}
-
-	sprintf(result, "%s/%-2d", inet_ntoa(addr), n);
-	if (n == -1)
-		strcpy(strchr(result, '/')+1, inet_ntoa(mask));
-	return result;
-}
-
-static void print_route(nwio_route_t *route)
-{
-	if (!(route->nwr_flags & NWRF_INUSE))
-		return;
-
-	printf("%*lu ", ent_width, (unsigned long) route->nwr_ent_no);
-	printf("%*s ", if_width,
-		ifname ?  ifname : get_ifname(route->nwr_ifaddr));
-	printf("%*s ", dest_width, cidr2a(route->nwr_dest, route->nwr_netmask));
-	printf("%*s ", gateway_width, inet_ntoa(route->nwr_gateway));
-	printf("%*lu ", dist_width, (unsigned long) route->nwr_dist);
-	printf("%*ld ", pref_width, (long) route->nwr_pref);
-	printf("%*lu", mtu_width, (long) route->nwr_mtu);
-	if (route->nwr_flags & NWRF_STATIC)
-		printf(" static");
-	if (route->nwr_flags & NWRF_UNREACHABLE)
-		printf(" dead");
-	printf("\n");
-}
-
-static void fill_iftab(void)
-{
-	int i, j, r, fd;
-	nwio_ipconf_t ip_conf;
-	char dev_name[12];	/* /dev/ipXXXX */
-
-	for (i= 0; i<N_IF; i++)
-	{
-		iftab[i]= 0;
-
-		sprintf(dev_name, "/dev/ip%d", i);
-		fd= open(dev_name, O_RDWR);
-		if (fd == -1)
-		{
-			if (errno == EACCES || errno == ENOENT || errno == ENXIO)
-				continue;
-			fatal("unable to open '%s': %s",
-				dev_name, strerror(errno));
-		}
-		fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
-		r= ioctl(fd, NWIOGIPCONF, &ip_conf);
-		if (r == -1 && errno == EAGAIN)
-		{
-			/* interface is down */
-			close(fd);
-			continue;
-		}
-		if (r == -1)
-		{
-			fatal("NWIOGIPCONF failed on %s: %s",
-				dev_name, strerror(errno));
-		}
-
-		iftab[i]= ip_conf.nwic_ipaddr;
-		close(fd);
-
-		for (j= 0; j<i; j++)
-		{
-			if (iftab[j] == iftab[i])
-			{
-				fatal("duplicate address in ip%d and ip%d: %s",
-					i, j, inet_ntoa(iftab[i]));
-			}
-		}
-
-	}
-}
-
-static char *get_ifname(ipaddr_t addr)
-{
-	static char name[7];	/* ipXXXX */
-
-	int i;
-
-	for (i= 0; i<N_IF; i++)
-	{
-		if (iftab[i] != addr)
-			continue;
-		sprintf(name, "ip%d", i);
-		return name;
-	}
-
-	return inet_ntoa(addr);
-}
-
-static void fatal(char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	fprintf(stderr, "%s: ", prog_name);
-	vfprintf(stderr, fmt, ap);
-	fprintf(stderr, "\n");
-	va_end(ap);
-	exit(1);
-}
-
-static void usage(void)
-{
-	fprintf(stderr, "Usage: %s [-i|-o] [ -a ] [ -I <ip-device> ]\n",
-		prog_name);
-	exit(1);
-}
-
-/*
- * $PchId: pr_routes.c,v 1.8 2002/04/11 10:58:58 philip Exp $
- */
Index: trunk/minix/commands/simple/prep.c
===================================================================
--- trunk/minix/commands/simple/prep.c	(revision 9)
+++ 	(revision )
@@ -1,136 +1,0 @@
-/* prep - prepare file for statistics 	Author: Andy Tanenbaum */
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define TROFF_CHAR	'.'	/* troff commands begin with this char */
-#define EOL		'\n'	/* end of line char */
-#define APOSTROPHE	047	/* single quote */
-#define BACKSLASH       '\\'	/* troff code */
-
-int lfread;			/* set when last char read was lf */
-int lfwritten = 1;		/* set when last char written was lf */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void skipline, (void));
-_PROTOTYPE(int backslash, (void));
-_PROTOTYPE(void usage, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-
-  int c;
-
-  if (argc > 2) usage();
-  if (argc == 2) {
-	if (freopen(argv[1], "r", stdin) == NULL) {
-		printf("prep: cannot open %s\n", argv[1]);
-		exit(1);
-	}
-  }
-  while ((c = getchar()) != EOF) {
-	/* Lines beginning with "." are troff commands -- skip them. */
-	if (lfread && c == TROFF_CHAR) {
-		skipline();
-		continue;
-	}
-	while (c == BACKSLASH) c = backslash();	/* eat troff stuff */
-
-	if (isupper(c)) {
-		putchar(tolower(c));
-		lfwritten = 0;
-		lfread = 0;
-		continue;
-	}
-	if (islower(c)) {
-		putchar(c);
-		lfwritten = 0;
-		lfread = 0;
-		continue;
-	}
-	if (c == APOSTROPHE) {
-		putchar(c);
-		lfwritten = 0;
-		lfread = 0;
-		continue;
-	}
-	lfread = (c == EOL ? 1 : 0);
-	if (lfwritten) continue;
-	putchar(EOL);
-	lfwritten = 1;
-  }
-  return(0);
-}
-
-
-void skipline()
-{
-  char c;
-
-  while ((c = getchar()) != EOL);
-}
-
-
-int backslash()
-{
-/* A backslash has been seen.  Eat troff stuff. */
-
-  int c, c1, c2;
-
-  c = getchar();
-  switch (c) {
-      case 'f':
-	c = getchar();
-	c = getchar();
-	return(c);
-
-      case 's':			/* \s7  or \s14 */
-	c = getchar();
-	c = getchar();
-	if (isdigit(c)) c = getchar();
-	return(c);
-
-      case 'n':			/* \na or \n(xx  */
-	c = getchar();
-	if (c == '(') {
-		c = getchar();
-		c = getchar();
-	}
-	c = getchar();
-	return(c);
-
-      case '*':			/* / * (XX */
-	c = getchar();
-	if (c == '(') {
-		c = getchar();
-		c = getchar();
-		c = getchar();
-		return(c);
-	}
-
-      case '(':			/* troff 4-character escape sequence */
-	c1 = getchar();
-	c2 = getchar();
-	if (c1 == 'e' && c2 == 'm') return(' ');
-	if (c1 == 'e' && c2 == 'n') return(' ');
-	c = getchar();
-	return(c);
-
-      case '%':			/* soft hyphen: \% */
-	c = getchar();
-	return(c);
-
-      default:
-	return(c);
-
-  }
-}
-
-void usage()
-{
-  printf("Usage: prep [file]\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/printenv.c
===================================================================
--- trunk/minix/commands/simple/printenv.c	(revision 9)
+++ 	(revision )
@@ -1,12 +1,0 @@
-
-#include <stdio.h>
-
-int main(int argc, char *argv[], char *envp[])
-{
-	int p;
-	for(p = 0; envp[p] && *envp[p]; p++) {
-		printf("%s\n", envp[p]);
-	}
-	return 0;
-}
-
Index: trunk/minix/commands/simple/printf.c
===================================================================
--- trunk/minix/commands/simple/printf.c	(revision 9)
+++ 	(revision )
@@ -1,471 +1,0 @@
-#if ever
-static char sccsid[] = "@(#)printf.c	(U of Maryland) FLB 6-Jan-1987";
-static char RCSid[] = "@(#)$Header: /cvsup/minix/src/commands/simple/printf.c,v 1.1.1.1 2005/04/21 14:55:31 beng Exp $";
-#endif
-
-/*
- * Printf - Duplicate the C library routine of the same name, but from
- *	    the shell command level.
- *
- * Fred Blonder <fred@Mimsy.umd.edu>
- *
- * To Compile:
- %	cc -s -O printf.c -o printf
- *
- * $Log: printf.c,v $
- * Revision 1.1.1.1  2005/04/21 14:55:31  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:30  beng
- * Initial import of minix 2.0.4
- *
- * Revision 1.4  87/01/29  20:52:30  fred
- * Re-installed backslash-notation conversion for string & char arguments.
- * 
- * Revision 1.3  87/01/29  20:44:23  fred
- * Converted to portable algorithm.
- * Added Roman format for integers.
- * 	29-Jan-87  FLB
- * 
- * Revision 1.2  87/01/09  19:10:57  fred
- * Fixed bug in argument-count error-checking.
- * Changed backslash escapes within strings to correspond to ANSII C
- * 	draft standard.  (9-Jan-87 FLB)
- * 
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#define EX_OK		0
-#define EX_USAGE	1
-
-int ctrl(char *s);
-
-#define atoi(a)		strtoul((a), NULL, 0)
-
-/****************************************************************************/
-
-int main(int argc, char *argv[])
-{
-register char *cp, *conv_spec, **argp, **ep;
-char *ctor(int x);
-
-if (argc < 2) {
-	fprintf(stderr,
-		"printf: Usage: printf <format-string> [ arg1 . . . ]\n");
-	exit(EX_USAGE);
-	}
-
-argp = &argv[2];	/* Point at first arg (if any) beyond format string. */
-ep = &argv[argc];	/* Point beyond last arg. */
-
-ctrl(argv[1]);	/* Change backslash notation to control chars in fmt string. */
-
-/* Scan format string for conversion specifications, and do appropriate
-   conversion on the corresponding argument. */
-for (cp = argv[1]; *cp; cp++) {
-register int dynamic_count;
-
-	/* Look for next conversion spec. */
-	while (*cp && *cp != '%') {
-		putchar(*cp++);
-		}
-
-	if (!*cp)	/* End of format string */
-		break;
-		
-	dynamic_count = 0;	/* Begin counting dynamic field width specs. */
-	conv_spec = cp++;	/* Remember where this conversion begins. */
-
-	for (;*cp; cp++) {	/* Scan until conversion character. */
-		char conv_buf[BUFSIZ];	/* Save conversion string here. */
-		register int conv_len;	/* Length of ``conv_buf''. */
-
-		switch (*cp) {	/* Field-width spec.: Keep scanning. */
-			case '.': case '0': case '1': case '2': case '3':
-			case '4': case '5': case '6': case '7': case '8':
-			case '9':
-				continue;
-
-			case '*':	/* Dynamic field-width spec */
-				dynamic_count++;
-				continue;
-
-			case 's':	/* String */
-				if (&argp[dynamic_count] >= ep) {
-					fprintf(stderr,
-					"printf: Not enough args for format.\n"
-						);
-					exit(EX_USAGE);
-					}
-
-				(void) strncpy(conv_buf, conv_spec,
-					conv_len = cp - conv_spec + 1);
-				conv_buf[conv_len] = '\0';
-
-				switch (dynamic_count) {
-					case 0:
-						ctrl(*argp);
-						printf(conv_buf, *argp++);
-						break;
-
-					case 1:
-						{
-						register int a1;
-
-						a1 = atoi(*argp++);
-						ctrl(*argp);
-						printf(conv_buf, a1, *argp++);
-						}
-						break;
-
-					case 2:
-						{
-						register int a1, a2;
-
-						a1 = atoi(*argp++);
-						a2 = atoi(*argp++);
-						ctrl(*argp);
-						printf(conv_buf, a1, a2, *argp++);
-						}
-						break;
-
-					}
-				goto out;
-
-			case 'c':	/* Char */
-				if (&argp[dynamic_count] >= ep) {
-					fprintf(stderr,
-					"printf: Not enough args for format.\n"
-						);
-					exit(EX_USAGE);
-					}
-
-				(void) strncpy(conv_buf, conv_spec,
-					conv_len = cp - conv_spec + 1);
-				conv_buf[conv_len] = '\0';
-
-				switch (dynamic_count) {
-					case 0:
-						ctrl(*argp);
-						printf(conv_buf, **argp++);
-						break;
-
-					case 1:
-						{
-						register int a1;
-
-						a1 = atoi(*argp++);
-						ctrl(*argp);
-						printf(conv_buf, a1, **argp++);
-						}
-						break;
-
-					case 2:
-						{
-						register int a1, a2;
-
-						a1 = atoi(*argp++);
-						a2 = atoi(*argp++);
-						ctrl(*argp);
-						printf(conv_buf, a1, a2, **argp++);
-						}
-						break;
-					}
-				goto out;
-
-			case 'd':	/* Integer */
-			case 'o':
-			case 'x':
-			case 'X':
-			case 'u':
-				if (&argp[dynamic_count] >= ep) {
-					fprintf(stderr,
-					"printf: Not enough args for format.\n"
-						);
-					exit(EX_USAGE);
-					}
-
-				(void) strncpy(conv_buf, conv_spec,
-					conv_len = cp - conv_spec + 1);
-				conv_buf[conv_len] = '\0';
-
-				switch (dynamic_count) {
-					case 0:
-						printf(conv_buf, atoi(*argp++));
-						break;
-
-					case 1:
-						{
-						register int a1;
-
-						a1 = atoi(*argp++);
-						printf(conv_buf, a1, atoi(*argp++));
-						}
-						break;
-
-					case 2:
-						{
-						register int a1, a2;
-
-						a1 = atoi(*argp++);
-						a2 = atoi(*argp++);
-						printf(conv_buf, a1, a2, atoi(*argp++));
-						}
-						break;
-
-					}
-				goto out;
-
-			case 'f':	/* Real */
-			case 'e':
-			case 'g':
-				if (&argp[dynamic_count] >= ep) {
-					fprintf(stderr,
-					"printf: Not enough args for format.\n"
-						);
-					exit(EX_USAGE);
-					}
-
-				(void) strncpy(conv_buf, conv_spec,
-					conv_len = cp - conv_spec + 1);
-				conv_buf[conv_len] = '\0';
-
-				switch (dynamic_count) {
-					case 0:
-						printf(conv_buf, atof(*argp++));
-						break;
-
-					case 1:
-						{
-						register int a1;
-
-						a1 = atoi(*argp++);
-						printf(conv_buf, a1, atof(*argp++));
-						}
-						break;
-
-					case 2:
-						{
-						register int a1, a2;
-
-						a1 = atoi(*argp++);
-						a2 = atoi(*argp++);
-						printf(conv_buf, a1, a2, atof(*argp++));
-						}
-						break;
-
-					}
-				goto out;
-
-			case 'r':	/* Roman (Well, why not?) */
-				if (&argp[dynamic_count] >= ep) {
-					fprintf(stderr,
-					"printf: Not enough args for format.\n"
-						);
-					exit(EX_USAGE);
-					}
-
-				(void) strncpy(conv_buf, conv_spec,
-					conv_len = cp - conv_spec + 1);
-				conv_buf[conv_len] = '\0';
-				conv_buf[conv_len - 1] = 's';
-
-				switch (dynamic_count) {
-					case 0:
-						printf(conv_buf,
-							ctor(atoi(*argp++)));
-						break;
-
-					case 1:
-						{
-						register int a1;
-
-						a1 = atoi(*argp++);
-						printf(conv_buf, a1,
-							ctor(atoi(*argp++)));
-						}
-						break;
-
-					case 2:
-						{
-						register int a1, a2;
-
-						a1 = atoi(*argp++);
-						a2 = atoi(*argp++);
-						printf(conv_buf, a1, a2,
-							ctor(atoi(*argp++)));
-						}
-						break;
-
-					}
-				goto out;
-
-			case '%':	/* Boring */
-				putchar('%');
-				break;
-
-			default:	/* Probably an error, but let user
-					   have his way. */
-				continue;
-			}
-		}
-	out: ;
-	}
-
-exit(EX_OK);
-}
-
-/****************************************************************************/
-
-/* Convert backslash notation to control characters, in place. */
-
-int ctrl(char *s)
-{
-register char *op;
-static int val;
-
-for (op = s; *s; s++)
-	if (*s == '\\')
-		switch (*++s) {
-			case '\0':	/* End-of-string: user goofed */
-				goto out;
-
-			case '\\':	/* Backslash */
-				*op++ = '\\';
-				break;
-
-			case 'n':	/* newline */
-				*op++ = '\n';
-				break;
-
-			case 't':	/* horizontal tab */
-				*op++ = '\t';
-				break;
-
-			case 'r':	/* carriage-return */
-				*op++ = '\r';
-				break;
-
-			case 'f':	/* form-feed */
-				*op++ = '\f';
-				break;
-
-			case 'b':	/* backspace */
-				*op++ = '\b';
-				break;
-
-			case 'v':	/* vertical tab */
-				*op++ = '\13';
-				break;
-
-			case 'a':	/* WARNING! DANGER! DANGER! DANGER! */
-				*op++ = '\7';
-				break;
-
-			case '0': case '1': case '2': case '3':
-			case '4': case '5': case '6': case '7':
-				{	/* octal constant */
-				register int digits;
-
-				val = 0;
-				(void) sscanf(s, "%3o", &val);
-				*op++ = val;
-				for (digits = 3; s[1] &&
-					strchr("01234567", s[1])
-					&& --digits > 0;
-						s++);
-				}
-				break;
-
-			case 'x':	/* hex constant */
-			case 'X':
-				s++;
-				{
-				register int digits;
-
-				val = 0;
-				(void) sscanf(s, "%3x", &val);
-				*op++ = val;
-				for (digits = 3; *s && s[1] &&
-					strchr("0123456789abcdefABCDEF",
-									s[1])
-					&& --digits > 0;
-						s++);
-				}
-				break;
-
-			}
-	else
-		*op++ = *s;
-
-out:
-
-*op = '\0';
-}
-
-/****************************************************************************/
-
-/* Convert integer to Roman Numerals. (Have have you survived without it?) */
-
-struct roman {
-	unsigned r_mag;
-	char r_units, r_fives;
-	} roman[] = {
-		{ 1000, 'M', '\0', },
-		{  100, 'C', 'D',  },
-		{   10, 'X', 'L',  },
-		{    1, 'I', 'V',  },
-		};
-
-char *ctor(int x)
-{
-register struct roman *mp;
-static char buf[BUFSIZ];
-register char *cp = buf;
-
-/* I've never actually seen a roman numeral with a minus-sign.
-   Probably ought to print out some appropriate latin phrase instead. */
-if (x < 0) {
-	*cp++ = '-';
-	x = -x;
-	}
-
-for (mp = roman; x; mp++) {
-	register unsigned units;
-
-	units = x / mp->r_mag;
-	x = x % mp->r_mag;
-
-	if (cp > &buf[BUFSIZ-2])
-		return "???";
-
-	if (units == 9 && mp > roman) {	/* Do inverse notation: Eg: ``IX''. */
-		*cp++ = mp->r_units;
-		*cp++ = mp[-1].r_units;
-		}
-	else if (units == 4 && mp->r_fives) {
-		/* Inverse notation for half-decades: Eg: ``IV'' */
-		*cp++ = mp->r_units;
-		*cp++ = mp->r_fives;
-		}
-	else {	/* Additive notation */
-		if (units >= 5 && mp->r_fives) {
-			*cp++ = mp->r_fives;
-			units -= 5;
-			}
-		while (units--) {
-			*cp++ = mp->r_units;
-			if (cp > &buf[BUFSIZ-5])
-				return "???";
-			}
-		}
-	}
-
-*cp = '\0';
-
-return buf;
-}
-
-/****************************************************************************/
Index: trunk/minix/commands/simple/printroot.c
===================================================================
--- trunk/minix/commands/simple/printroot.c	(revision 9)
+++ 	(revision )
@@ -1,85 +1,0 @@
-/* printroot - print root device on stdout	Author: Bruce Evans */
-
-/* This program figures out what the root device is by doing a stat on it, and
- * then searching /dev until it finds an entry with the same device number.
- * A typical use (probably the only use) is in /etc/rc for initializing
- * /etc/mtab, as follows:
- *
- *	/usr/bin/printroot >/etc/mtab
- *
- *  9 Dec 1989	- clean up for 1.5 - full prototypes (BDE)
- * 15 Oct 1989	- avoid ACK cc bugs (BDE):
- *		- sizeof "foo" is 2 (from wrong type char *) instead of 4
- *		- char foo[10] = "bar"; allocates 4 bytes instead of 10
- *  1 Oct 1989	- Minor changes by Andy Tanenbaum
- *  5 Oct 1992	- Use readdir (kjb)
- * 26 Nov 1994	- Flag -r: print just the root device (kjb)
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <minix/minlib.h>
-#include <dirent.h>
-
-static char DEV_PATH[] = "/dev/";	/* #define would step on sizeof bug */
-static char MESSAGE[] = " / ";	/* ditto */
-#define UNKNOWN_DEV	"/dev/unknown"
-#define ROOT		"/"
-int rflag;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void done, (char *name, int status));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  DIR *dp;
-  struct dirent *entry;
-  struct stat filestat, rootstat;
-  static char namebuf[sizeof DEV_PATH + NAME_MAX];
-
-  rflag = (argc > 1 && strcmp(argv[1], "-r") == 0);
-
-  if (stat(ROOT, &rootstat) == 0 && (dp = opendir(DEV_PATH)) != (DIR *) NULL) {
-	while ((entry = readdir(dp)) != (struct dirent *) NULL) {
-		strcpy(namebuf, DEV_PATH);
-		strcat(namebuf, entry->d_name);
-		if (stat(namebuf, &filestat) != 0) continue;
-		if ((filestat.st_mode & S_IFMT) != S_IFBLK) continue;
-		if (filestat.st_rdev != rootstat.st_dev) continue;
-		done(namebuf, 0);
-	}
-  }
-  done(UNKNOWN_DEV, 1);
-  return(0);			/* not reached */
-}
-
-void done(name, status)
-char *name;
-int status;
-{
-  int v;
-
-  write(1, name, strlen(name));
-  if (rflag) {
-	write(1, "\n", 1);
-	exit(status);
-  }
-  write(1, MESSAGE, sizeof MESSAGE - 1);
-  v = fsversion(name, "printroot");	/* determine file system version */
-  if (v == 1)
-	write(1, "1 rw\n", 5);
-  else if (v == 2)
-	write(1, "2 rw\n", 5);
-  else if (v == 3)
-	write(1, "3 rw\n", 5);
-  else
-	write(1, "0 rw\n", 5);
-  exit(status);
-}
Index: trunk/minix/commands/simple/progressbar.c
===================================================================
--- trunk/minix/commands/simple/progressbar.c	(revision 9)
+++ 	(revision )
@@ -1,79 +1,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <unistd.h>
-#include <string.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-
-void
-prettyprogress(long b, long maxb, time_t starttime)
-{
-  /* print progress indication */
-  time_t spent, now;
-  double bpsec;
-  time(&now);
-  spent = now - starttime;
-  printf("\r");	/* Make sure progress bar starts at beginning of line */
-  if(spent > 0 && (bpsec = (double)b / spent) > 0) {
-  	int len, i;
-  	long secremain, minremain, hremain;
-	  secremain = (maxb - b) / bpsec;
-	  minremain = (secremain / 60) % 60;
-	  hremain = secremain / 3600;
-  	len = printf("Remaining: %ld files. ", maxb-b);
-
-#if 0
-  	len += printf("ETA: %d:%02d:%02d ",
-  		hremain, minremain, secremain % 60);
-#endif
-
-	len += printf(" [");
-
-#define WIDTH 77
-  	len = WIDTH - len;
-  	for(i = 0; i < (b * (len-1) / maxb); i++) 
-  		printf("=");
- 	printf("|");
-  	for(; i < len-2; i++) 
-  		printf("-");
-  	printf("][K\n");
-  } else printf("\n");
-
-  return;
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-	long i = 0, count = 0;
-	int l;
-	char line[2000];
-	time_t start;
-	if(argc < 2) return 1;
-	count = atol(argv[1]);
-	if(count < 0) return 1;
-	time(&start);
-	printf("\n");
-#define LINES 5
-	for(l = 1; l <= LINES+1; l++) printf("\n");
-	printf("[A");
-	while(fgets(line, sizeof(line), stdin)) {
-		char *nl;
-		i++;
-		for(l = 0; l <= LINES; l++)  printf("[A");
-		if(i <= count) prettyprogress(i, count, start);
-		else printf("\n");
-		printf("[M");
-		for(l = 0; l < LINES; l++)  printf("[B");
-		if((nl = strchr(line, '\n'))) *nl = '\0';
-		line[78] = '\0';
-		printf("\r%s\r", line);
-	}
-
-  	printf("\nDone.[K\n");
-
-	return 0;
-}
Index: trunk/minix/commands/simple/proto.c
===================================================================
--- trunk/minix/commands/simple/proto.c	(revision 9)
+++ 	(revision )
@@ -1,688 +1,0 @@
-/* proto - Generate ANSI C prototypes.	Author:	Eric R. Smith */
-
-/* Program to extract function declarations from C source code
- * Written by Eric R. Smith and placed in the public domain
- * Thanks are due to Jwahar R. Bammi for fixing several bugs
- * And providing the Unix makefiles.
- */
-#define EXIT_SUCCESS  0
-#define EXIT_FAILURE  1
-
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define ISCSYM(x) ((x) > 0 && (isalnum(x) || (x) == '_' ))
-#define ABORTED ( (Word *) -1 )
-#define MAXPARAM 20		/* max. number of parameters to a function */
-
-typedef struct word {
-  struct word *next;
-  char string[1];
-} Word;
-
-int inquote = 0;		/* in a quote? */
-int newline_seen = 1;		/* are we at the start of a line */
-long linenum = 1L;		/* line number in current file */
-long endline = 0L;		/* the last line before the { of a f'n */
-long symline = 0L;		/* Line that symbol was on, set by getsym() */
-int dostatic = 0;		/* do static functions? */
-int donum = 0;			/* print line numbers? */
-int dohead = 1;			/* do file headers? */
-int docond = 1;			/* conditionalize for non-ANSI compilers? */
-int dodiff = 0;			/* Output a diff file to prototype original */
-int doold = 0;			/* do old style: P() */
-int glastc = ' ';		/* last char. seen by getsym() */
-Word *endlist;			/* Parentheses after the parameters */
-char *progname;			/* name of program (for error messages) */
-
-
-_PROTOTYPE(Word * word_alloc, (char *s));
-_PROTOTYPE(void word_free, (Word * w));
-_PROTOTYPE(int List_len, (Word * w));
-_PROTOTYPE(Word * word_append, (Word * w1, Word * w2));
-_PROTOTYPE(int foundin, (Word * w1, Word * w2));
-_PROTOTYPE(void addword, (Word * w, char *s));
-_PROTOTYPE(void printlist, (Word * p));
-_PROTOTYPE(Word * typelist, (Word * p));
-_PROTOTYPE(void typefixhack, (Word * w));
-_PROTOTYPE(int ngetc, (FILE * f));
-_PROTOTYPE(int fnextch, (FILE * f));
-_PROTOTYPE(int nextch, (FILE * f));
-_PROTOTYPE(int getsym, (char *buf, FILE * f));
-_PROTOTYPE(int skipit, (char *buf, FILE * f));
-_PROTOTYPE(Word * getparamlist, (FILE * f));
-_PROTOTYPE(void emit, (Word * wlist, Word * plist, long startline));
-_PROTOTYPE(void getdecl, (FILE * f));
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void Usage, (void));
-
-/* Routines for manipulating lists of words. */
-
-Word *word_alloc(s)
-char *s;
-{
-  Word *w;
-
-  w = (Word *) malloc(sizeof(Word) + strlen(s) + 1);
-  if (w == NULL) {
-	fprintf(stderr, "%s: out of memory\n", progname);
-	exit(1);
-  }
-  (void) strcpy(w->string, s);
-  w->next = NULL;
-  return w;
-}
-
-void word_free(w)
-Word *w;
-{
-  Word *oldw;
-  while (w) {
-	oldw = w;
-	w = w->next;
-	free((char *) oldw);
-  }
-}
-
-/* Return the length of a list; empty words are not counted */
-int List_len(w)
-Word *w;
-{
-  int count = 0;
-
-  while (w) {
-	if (*w->string) count++;
-	w = w->next;
-  }
-  return count;
-}
-
-/* Append two lists, and return the result */
-Word *word_append(w1, w2)
-Word *w1, *w2;
-{
-  Word *r, *w;
-
-  r = w = word_alloc("");
-
-  while (w1) {
-	w->next = word_alloc(w1->string);
-	w = w->next;
-	w1 = w1->next;
-  }
-  while (w2) {
-	w->next = word_alloc(w2->string);
-	w = w->next;
-	w2 = w2->next;
-  }
-
-  return r;
-}
-
-/* See if the last entry in w2 is in w1 */
-int foundin(w1, w2)
-Word *w1, *w2;
-{
-  while (w2->next) w2 = w2->next;
-
-  while (w1) {
-	if (!strcmp(w1->string, w2->string)) return 1;
-	w1 = w1->next;
-  }
-  return 0;
-}
-
-/* Add the string s to the given list of words */
-void addword(w, s)
-Word *w;
-char *s;
-{
-  while (w->next) w = w->next;
-  w->next = word_alloc(s);
-}
-
-/* Printlist: print out a list */
-void printlist(p)
-Word *p;
-{
-  Word *w;
-  int i = 0;
-
-  for (w = p; w; w = w->next) {
-	printf("%s", w->string);
-	if (ISCSYM(w->string[0]) && i > 0
-			&& w->next && w->next->string[0] != ',') printf(" ");
-	i++;
-  }
-}
-
-/* Given a list representing a type and a variable name, extract just
- * the base type, e.g. "struct word *x" would yield "struct word".
- * Similarly, "unsigned char x[]" would yield "unsigned char".
- */
-Word *typelist(p)
-Word *p;
-{
-  Word *w, *r, *last;
-
-  last = r = w = word_alloc("");
-  while (p && p->next) {
-	if (p->string[0] == '[') {
-		word_free(w);
-		last->next = NULL;
-		break;
-	}
-	if (p->string[0] && !ISCSYM(p->string[0])) break;
-	w->next = word_alloc(p->string);
-	last = w;
-	w = w->next;
-	p = p->next;
-  }
-  return r;
-}
-
-/* Typefixhack: promote formal parameters of type "char", "unsigned char",
- * "short", or "unsigned short" to "int".
- */
-void typefixhack(w)
-Word *w;
-{
-  Word *oldw = 0;
-
-  while (w) {
-	if (*w->string) {
-		if ((!strcmp(w->string, "char") ||
-		     !strcmp(w->string, "short"))
-		    && (List_len(w->next) < 2)) {
-			if (oldw && !strcmp(oldw->string, "unsigned")) {
-				oldw->next = w->next;
-				free((char *) w);
-				w = oldw;
-			}
-			(void) strcpy(w->string, "int");
-		}
-	}
-	w = w->next;
-  }
-}
-
-/* Read a character: if it's a newline, increment the line count */
-int ngetc(f)
-FILE *f;
-{
-  int c;
-
-  c = getc(f);
-  if (c == '\n') linenum++;
-
-  return c;
-}
-
-/* Read the next character from the file. If the character is '\' then
- * read and skip the next character. Any comment sequence is converted
- * to a blank.
- */
-int fnextch(f)
-FILE *f;
-{
-  int c, lastc, incomment;
-
-  c = ngetc(f);
-  while (c == '\\') {
-	c = ngetc(f);		/* skip a character */
-	c = ngetc(f);
-  }
-  if (c == '/' && !inquote) {
-	c = ngetc(f);
-	if (c == '*') {
-		incomment = 1;
-		c = ' ';
-		while (incomment) {
-			lastc = c;
-			c = ngetc(f);
-			if (lastc == '*' && c == '/')
-				incomment = 0;
-			else if (c < 0)
-				return c;
-		}
-		return fnextch(f);
-	} else {
-		if (c == '\n') linenum--;
-		(void) ungetc(c, f);
-		return '/';
-	}
-  }
-  return c;
-}
-
-
-/* Get the next "interesting" character. Comments are skipped, and strings
- * are converted to "0". Also, if a line starts with "#" it is skipped.
- */
-int nextch(f)
-FILE *f;
-{
-  int c;
-
-  c = fnextch(f);
-  if (newline_seen && c == '#') {
-	do {
-		c = fnextch(f);
-	} while (c >= 0 && c != '\n');
-	if (c < 0) return c;
-  }
-  newline_seen = (c == '\n');
-
-  if (c == '\'' || c == '\"') {
-	inquote = c;
-	while ((c = fnextch(f)) >= 0) {
-		if (c == inquote) {
-			inquote = 0;
-			return '0';
-		}
-	}
-  }
-  return c;
-}
-
-/* Get the next symbol from the file, skipping blanks.
- * Return 0 if OK, -1 for EOF.
- * Also collapses everything between { and }
- */
-int getsym(buf, f)
-char *buf;
-FILE *f;
-{
-  register int c;
-  int inbrack = 0;
-
-  c = glastc;
-  while ((c > 0) && isspace(c)) c = nextch(f);
-  if (c < 0) return -1;
-  if (c == '{') {
-	inbrack = 1;
-	endline = linenum;
-	while (inbrack) {
-		c = nextch(f);
-		if (c < 0) {
-			glastc = c;
-			return c;
-		}
-		if (c == '{')
-			inbrack++;
-		else if (c == '}')
-			inbrack--;
-	}
-	(void) strcpy(buf, "{}");
-	glastc = nextch(f);
-	return 0;
-  }
-  if (!ISCSYM(c)) {
-	*buf++ = c;
-	glastc = nextch(f);
-	if (c == '(' && glastc == '*') {	/* Look for a 'f'n pointer */
-		*buf++ = glastc;
-		glastc = nextch(f);
-	}
-	*buf = 0;
-	return 0;
-  }
-  symline = linenum;
-  while (ISCSYM(c)) {
-	*buf++ = c;
-	c = nextch(f);
-  }
-  *buf = 0;
-  glastc = c;
-  return 0;
-}
-
-
-/* Skipit: skip until a ";" or the end of a function declaration is seen */
-int skipit(buf, f)
-char *buf;
-FILE *f;
-{
-  int i;
-
-  do {
-	i = getsym(buf, f);
-	if (i < 0) return i;
-  } while (*buf != ';' && *buf != '{');
-
-  return 0;
-}
-
-/* Get a parameter list; when this is called the next symbol in line
- * should be the first thing in the list.
- */
-Word *getparamlist(f)
-FILE *f;
-{
-  static Word *pname[MAXPARAM];	/* parameter names */
-  Word *tlist,			/* type name */
-  *plist;			/* temporary */
-  int np = 0;			/* number of parameters */
-  int typed[MAXPARAM];		/* parameter has been given a type */
-  int tlistdone;		/* finished finding the type name */
-  int sawsomething;
-  int i;
-  int inparen = 0;
-  char buf[80];
-
-  for (i = 0; i < MAXPARAM; i++) typed[i] = 0;
-
-  plist = word_alloc("");
-  endlist = word_alloc("");
-
-  /* First, get the stuff inside brackets (if anything) */
-
-  sawsomething = 0;		/* gets set nonzero when we see an arg */
-  for (;;) {
-	if (getsym(buf, f) < 0) return(NULL);
-	if (*buf == ')' && (--inparen < 0)) {
-		if (sawsomething) {	/* if we've seen an arg */
-			pname[np] = plist;
-			plist = word_alloc("");
-			np++;
-		}
-		break;
-	}
-	if (*buf == ';') {	/* something weird */
-		return ABORTED;
-	}
-	sawsomething = 1;	/* there's something in the arg. list */
-	if (*buf == ',' && inparen == 0) {
-		pname[np] = plist;
-		plist = word_alloc("");
-		np++;
-	} else {
-		addword(plist, buf);
-		if (*buf == '(') inparen++;
-	}
-  }
-
-  /* Next, get the declarations after the function header */
-  inparen = 0;
-  tlist = word_alloc("");
-  plist = word_alloc("");
-  tlistdone = 0;
-  sawsomething = 0;
-  for (;;) {
-	if (getsym(buf, f) < 0) return(NULL);
-
-	/* Handle parentheses, which should indicate func pointer rtn values */
-	if (*buf == '(') {
-		addword(endlist, buf);
-		addword(endlist, " void ");
-		inparen++;
-	} else if (*buf == ')') {
-		if (symline == linenum) {
-			addword(endlist, buf);
-			addword(endlist, buf);
-		}
-		inparen--;
-	} else if (*buf == ',' && !inparen) {
-		/* Handle a list like "int x,y,z" */
-		if (!sawsomething) return(NULL);
-		for (i = 0; i < np; i++) {
-			if (!typed[i] && foundin(plist, pname[i])) {
-				typed[i] = 1;
-				word_free(pname[i]);
-				pname[i] = word_append(tlist, plist);
-				/* Promote types */
-				typefixhack(pname[i]);
-				break;
-			}
-		}
-		if (!tlistdone) {
-			tlist = typelist(plist);
-			tlistdone = 1;
-		}
-		word_free(plist);
-		plist = word_alloc("");
-	} else if (*buf == ';') {
-		/* Handle the end of a list */
-		if (!sawsomething) return ABORTED;
-		for (i = 0; i < np; i++) {
-			if (!typed[i] && foundin(plist, pname[i])) {
-				typed[i] = 1;
-				word_free(pname[i]);
-				pname[i] = word_append(tlist, plist);
-				typefixhack(pname[i]);
-				break;
-			}
-		}
-		tlistdone = 0;
-		word_free(tlist);
-		word_free(plist);
-		tlist = word_alloc("");
-		plist = word_alloc("");
-	} else if (!strcmp(buf, "{}"))
-		break;	/* Handle the  beginning of the function */
-		/* Otherwise, throw word into list (except for "register") */
-	else if (strcmp(buf, "register")) {
-		sawsomething = 1;
-		addword(plist, buf);
-		if (*buf == '(') inparen++;
-		if (*buf == ')') inparen--;
-	}
-  }
-
-  /* Now take the info we have and build a prototype list */
-
-  /* Empty parameter list means "void" */
-  if (np == 0) return word_alloc("void");
-
-  plist = tlist = word_alloc("");
-  for (i = 0; i < np; i++) {
-
-  /* If no type provided, make it an "int" */
-	if (!(pname[i]->next) ||
-	    (!(pname[i]->next->next)&&strcmp(pname[i]->next->string,"void"))) {
-		addword(tlist, "int");
-	}
-	while (tlist->next) tlist = tlist->next;
-	tlist->next = pname[i];
-	if (i < np - 1) addword(tlist, ", ");
-  }
-  return plist;
-}
-
-/* Emit a function declaration. The attributes and name of the function
- * are in wlist; the parameters are in plist.
- */
-void emit(wlist, plist, startline)
-Word *wlist, *plist;
-long startline;
-{
-  Word *w;
-  int count = 0;
-
-  if (doold == 0) printf("_PROTOTYPE( ");
-  if (dodiff) {
-	printf("%lda%ld,%ld\n", startline - 1, startline, startline +2);
-	printf("> #ifdef __STDC__\n> ");
-  }
-  if (donum) printf("/*%8ld */ ", startline);
-  for (w = wlist; w; w = w->next) {
-	if (w->string[0]) count++;
-  }
-  if (count < 2) printf("int ");
-  printlist(wlist);
-  if (docond) {
-	if (doold)
-		printf(" P((");
-	else
-		printf(", (");
-  } else {
-	printf("(");
-  }
-
-  printlist(plist);
-  printlist(endlist);
-
-  if (docond) {
-	if (doold)
-		printf("))");
-	else
-		printf(") )");
-  } else {
-	printf(")");
-  }
-
-  if (!dodiff)
-	printf(";\n");
-  else
-	printf("\n");
-
-  if (dodiff) {
-	printf("> #else\n");
-	printf("%lda%ld\n", endline - 1, endline);
-	printf("> #endif\n");
-  }
-}
-
-/* Get all the function declarations */
-void getdecl(f)
-FILE *f;
-{
-  Word *plist, *wlist = NULL;
-  char buf[80];
-  int sawsomething;
-  long startline = 0L;		/* line where declaration started */
-  int oktoprint;
-
-again:				/* SHAME SHAME */
-  word_free(wlist);
-  wlist = word_alloc("");
-  sawsomething = 0;
-  oktoprint = 1;
-
-  for (;;) {
-	if (getsym(buf, f) < 0) return;
-
-	/* Guess when a declaration is not an external function definition */
-	if (!strcmp(buf, ",") || !strcmp(buf, "{}") ||
-	    !strcmp(buf, "=") || !strcmp(buf, "typedef") ||
-	    !strcmp(buf, "extern")) {
-		(void) skipit(buf, f);
-		goto again;
-	}
-	if (!dostatic && !strcmp(buf, "static")) oktoprint = 0;
-
-	/* For the benefit of compilers that allow "inline" declarations */
-	if (!strcmp(buf, "inline") && !sawsomething) continue;
-	if (!strcmp(buf, ";")) goto again;
-
-	/* A left parenthesis *might* indicate a function definition */
-	if (!strcmp(buf, "(")) {
-		if (!sawsomething || !(plist = getparamlist(f))) {
-			(void) skipit(buf, f);
-			goto again;
-		}
-		if (plist == ABORTED) goto again;
-
-		/* It seems to have been what we wanted */
-		if (oktoprint) emit(wlist, plist, startline);
-		word_free(plist);
-		goto again;
-	}
-	addword(wlist, buf);
-	if (!sawsomething) startline = symline;
-	sawsomething = 1;
-  }
-}
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  FILE *f, *g;
-  char *t;
-  char newname[40];
-
-  progname = argv[0];
-  argv++;
-  argc--;
-  g = stdout;
-
-  while (*argv && **argv == '-') {
-	t = *argv++;
-	--argc;
-	t++;
-	while (*t) {
-		if (*t == 's')
-			dostatic = 1;
-		else if (*t == 'n')
-			donum = 1;
-		else if (*t == 'p')
-			docond = 0;
-		else if (*t == 'P')
-			doold =1;
-		else if (*t == 'd') {
-			dodiff = 1;
-			doold = 1;
-			docond = 0;
-			donum = 0;
-			dostatic = 1;
-		} else
-			Usage();
-		t++;
-	}
-  }
-
-  if (docond && doold) {
-	printf("#ifdef __STDC__\n");
-	printf("# define P(args)\targs\n");
-	printf("#else\n");
-	printf("# define P(args)\t()\n");
-	printf("#endif\n\n");
-  }
-  if (argc == 0)
-	getdecl(stdin);
-  else
-	while (argc > 0 && *argv) {
-		if (!(f = fopen(*argv, "r"))) {
-			perror(*argv);
-			exit(EXIT_FAILURE);
-		}
-#if 0
-		if (dodiff) {
-			(void) sprintf(newname, "%sdif", *argv);
-			(void) fclose(g);
-			if (!(g = fopen(newname, "w"))) {
-				perror(newname);
-				exit(EXIT_FAILURE);
-			}
-		}
-#endif
-		if (doold && dohead && !dodiff) printf("\n/* %s */\n", *argv);
-		linenum = 1;
-		newline_seen = 1;
-		glastc = ' ';
-		getdecl(f);
-		argc--;
-		argv++;
-		(void) fclose(f);
-	}
-  if (docond && doold) printf("\n#undef P\n");	/* clean up namespace */
-  (void) fclose(g);
-  return(EXIT_SUCCESS);
-}
-
-
-void Usage()
-{
-  fputs("Usage: ", stderr);
-  fputs(progname, stderr);
-  fputs(" [-d][-n][-p][-s] [files ...]\n", stderr);
-  fputs("   -P: use P() style instead of _PROTOTYPE\n", stderr);
-  fputs("   -d: produce a diff file to prototype original source\n", stderr);
-  fputs("   -n: put line numbers of declarations as comments\n", stderr);
-  fputs("   -p: don't make header files readable by K&R compilers\n", stderr);
-  fputs("   -s: include declarations for static functions\n", stderr);
-  exit(EXIT_FAILURE);
-}
Index: trunk/minix/commands/simple/pwd.c
===================================================================
--- trunk/minix/commands/simple/pwd.c	(revision 9)
+++ 	(revision )
@@ -1,49 +1,0 @@
-/* pwd - print working directory	Author: Norbert Schlenker */
-
-/*
- * pwd - print working directory
- *   Syntax:	pwd
- *   Flags:	None.
- *   Author:	Norbert Schlenker
- *   Copyright:	None.  Released to the public domain.
- *   Reference:	IEEE P1003.2 Section 4.50 (draft 10)
- *   Bugs:	No internationalization support; all messages are in English.
- */
-
-/* Force visible Posix names */
-#ifndef _POSIX_SOURCE
-#define _POSIX_SOURCE 1
-#endif
-
-/* External interfaces */
-#include <sys/types.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-/* Magic numbers suggested or required by Posix specification */
-#define SUCCESS	0		/* exit code in case of success */
-#define FAILURE 1		/*                   or failure */
-
-_PROTOTYPE(int main, (void));
-
-static char dir[PATH_MAX + 1];
-static char *errmsg = "pwd: cannot search some directory on the path\n";
-
-int main()
-{
-  char *p;
-  size_t n;
-
-  p = getcwd(dir, PATH_MAX);
-  if (p == NULL) {
-	write(STDERR_FILENO, errmsg, strlen(errmsg));
-	exit(FAILURE);
-  }
-  n = strlen(p);
-  p[n] = '\n';
-  if (write(STDOUT_FILENO, p, n + 1) != n + 1) 	exit(FAILURE);
-  return(SUCCESS);
-}
Index: trunk/minix/commands/simple/pwdauth.c
===================================================================
--- trunk/minix/commands/simple/pwdauth.c	(revision 9)
+++ 	(revision )
@@ -1,357 +1,0 @@
-/*	pwdauth 2.0 - check a shadow password		Author: Kees J. Bot
- *								7 Feb 1994
- *
- * This program gets as input the key and salt arguments of the crypt(3)
- * function as two null terminated strings.  The crypt result is output as
- * one null terminated string.  Input and output must be <= 1024 characters.
- * The exit code will be 1 on any error.
- *
- * If the key has the form '##name' then the key will be encrypted and the
- * result checked to be equal to the encrypted password in the shadow password
- * file.  If equal than '##name' will be returned, otherwise exit code 2.
- *
- * Otherwise the key will be encrypted normally and the result returned.
- *
- * As a special case, anything matches a null encrypted password to allow
- * a no-password login.
- */
-#define nil 0
-#define crypt	CRYPT	/* The true crypt is included here. */
-#include <sys/types.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#define LEN	1024
-char SHADOW[] = "/etc/shadow";
-
-int main(int argc, char **argv)
-{
-	char key[LEN];
-	char *salt;
-	struct passwd *pw;
-	int n;
-
-	/* Read input data.  Check if there are exactly two null terminated
-	 * strings.
-	 */
-	n= read(0, key, LEN);
-	if (n < 0) return 1;
-	salt = key + n;
-	n = 0;
-	while (salt > key) if (*--salt == 0) n++;
-	if (n != 2) return 1;
-	salt = key + strlen(key) + 1;
-
-	if (salt[0] == '#' && salt[1] == '#') {
-		/* Get the encrypted password from the shadow password file,
-		 * encrypt key and compare.
-		 */
-		setpwfile(SHADOW);
-
-		if ((pw= getpwnam(salt + 2)) == nil) return 2;
-
-		/* A null encrypted password matches a null key, otherwise
-		 * do the normal crypt(3) authentication check.
-		 */
-		if (*pw->pw_passwd == 0 && *key == 0) {
-			/* fine */
-		} else
-		if (strcmp(crypt(key, pw->pw_passwd), pw->pw_passwd) != 0) {
-			return 2;
-		}
-	} else {
-		/* Normal encryption. */
-		if (*salt == 0 && *key == 0) {
-			/* fine */
-		} else {
-			salt= crypt(key, salt);
-		}
-	}
-
-	/* Return the (possibly new) salt to the caller. */
-	if (write(1, salt, strlen(salt) + 1) < 0) return 1;
-	return 0;
-}
-
-/* The one and only crypt(3) function. */
-
-/*	From Andy Tanenbaum's book "Computer Networks",
-	rewritten in C
-*/
-
-struct block {
-	unsigned char b_data[64];
-};
-
-struct ordering {
-	unsigned char o_data[64];
-};
-
-static struct block key;
-
-static struct ordering InitialTr = {
-	58,50,42,34,26,18,10, 2,60,52,44,36,28,20,12, 4,
-	62,54,46,38,30,22,14, 6,64,56,48,40,32,24,16, 8,
-	57,49,41,33,25,17, 9, 1,59,51,43,35,27,19,11, 3,
-	61,53,45,37,29,21,13, 5,63,55,47,39,31,23,15, 7,
-};
-
-static struct ordering FinalTr = {
-	40, 8,48,16,56,24,64,32,39, 7,47,15,55,23,63,31,
-	38, 6,46,14,54,22,62,30,37, 5,45,13,53,21,61,29,
-	36, 4,44,12,52,20,60,28,35, 3,43,11,51,19,59,27,
-	34, 2,42,10,50,18,58,26,33, 1,41, 9,49,17,57,25,
-};
-
-static struct ordering swap = {
-	33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
-	49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,
-	 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,
-	17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
-};
-
-static struct ordering KeyTr1 = {
-	57,49,41,33,25,17, 9, 1,58,50,42,34,26,18,
-	10, 2,59,51,43,35,27,19,11, 3,60,52,44,36,
-	63,55,47,39,31,23,15, 7,62,54,46,38,30,22,
-	14, 6,61,53,45,37,29,21,13, 5,28,20,12, 4,
-};
-
-static struct ordering KeyTr2 = {
-	14,17,11,24, 1, 5, 3,28,15, 6,21,10,
-	23,19,12, 4,26, 8,16, 7,27,20,13, 2,
-	41,52,31,37,47,55,30,40,51,45,33,48,
-	44,49,39,56,34,53,46,42,50,36,29,32,
-};
-
-static struct ordering etr = {
-	32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9,
-	 8, 9,10,11,12,13,12,13,14,15,16,17,
-	16,17,18,19,20,21,20,21,22,23,24,25,
-	24,25,26,27,28,29,28,29,30,31,32, 1,
-};
-
-static struct ordering ptr = {
-	16, 7,20,21,29,12,28,17, 1,15,23,26, 5,18,31,10,
-	 2, 8,24,14,32,27, 3, 9,19,13,30, 6,22,11, 4,25,
-};
-
-static unsigned char s_boxes[8][64] = {
-{	14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7,
-	 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8,
-	 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0,
-	15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13,
-},
-
-{	15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10,
-	 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5,
-	 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15,
-	13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9,
-},
-
-{	10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8,
-	13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1,
-	13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7,
-	 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12,
-},
-
-{	 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15,
-	13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9,
-	10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4,
-	 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14,
-},
-
-{	 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9,
-	14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6,
-	 4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14,
-	11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3,
-},
-
-{	12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11,
-	10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8,
-	 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6,
-	 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13,
-},
-
-{	 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1,
-	13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6,
-	 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2,
-	 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12,
-},
-
-{	13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7,
-	 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2,
-	 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8,
-	 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11,
-},
-};
-
-static int rots[] = {
-	1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1,
-};
-
-static void transpose(struct block *data, struct ordering *t, int n)
-{
-	struct block x;
-
-	x = *data;
-
-	while (n-- > 0) {
-		data->b_data[n] = x.b_data[t->o_data[n] - 1];
-	}
-}
-
-static void rotate(struct block *key)
-{
-	unsigned char *p = key->b_data;
-	unsigned char *ep = &(key->b_data[55]);
-	int data0 = key->b_data[0], data28 = key->b_data[28];
-
-	while (p++ < ep) *(p-1) = *p;
-	key->b_data[27] = data0;
-	key->b_data[55] = data28;
-}
-
-static struct ordering *EP = &etr;
-
-static void f(int i, struct block *key, struct block *a, struct block *x)
-{
-	struct block e, ikey, y;
-	int k;
-	unsigned char *p, *q, *r;
-
-	e = *a;
-	transpose(&e, EP, 48);
-	for (k = rots[i]; k; k--) rotate(key);
-	ikey = *key;
-	transpose(&ikey, &KeyTr2, 48);
-	p = &(y.b_data[48]);
-	q = &(e.b_data[48]);
-	r = &(ikey.b_data[48]);
-	while (p > y.b_data) {
-		*--p = *--q ^ *--r;
-	}
-	q = x->b_data;
-	for (k = 0; k < 8; k++) {
-		int xb, r;
-
-		r = *p++ << 5;
-		r += *p++ << 3;
-		r += *p++ << 2;
-		r += *p++ << 1;
-		r += *p++;
-		r += *p++ << 4;
-
-		xb = s_boxes[k][r];
-
-		*q++ = (xb >> 3) & 1;
-		*q++ = (xb>>2) & 1;
-		*q++ = (xb>>1) & 1;
-		*q++ = (xb & 1);
-	}
-	transpose(x, &ptr, 32);
-}
-
-static void setkey(char *k)
-{
-
-	key = *((struct block *) k);
-	transpose(&key, &KeyTr1, 56);
-}
-
-static void encrypt(char *blck, int edflag)
-{
-	struct block *p = (struct block *) blck;
-	int i;
-
-	transpose(p, &InitialTr, 64);
-	for (i = 15; i>= 0; i--) {
-		int j = edflag ? i : 15 - i;
-		int k;
-		struct block b, x;
-
-		b = *p;
-		for (k = 31; k >= 0; k--) {
-			p->b_data[k] = b.b_data[k + 32];
-		}
-		f(j, &key, p, &x);
-		for (k = 31; k >= 0; k--) {
-			p->b_data[k+32] = b.b_data[k] ^ x.b_data[k];
-		}
-	}
-	transpose(p, &swap, 64);
-	transpose(p, &FinalTr, 64);
-}
-
-char *crypt(const char *pw, const char *salt)
-{
-	char pwb[66];
-	char *cp;
-	static char result[16];
-	char *p = pwb;
-	struct ordering new_etr;
-	int i;
-
-	while (*pw && p < &pwb[64]) {
-		int j = 7;
-
-		while (j--) {
-			*p++ = (*pw >> j) & 01;
-		}
-		pw++;
-		*p++ = 0;
-	}
-	while (p < &pwb[64]) *p++ = 0;
-
-	setkey(p = pwb);
-
-	while (p < &pwb[66]) *p++ = 0;
-
-	new_etr = etr;
-	EP = &new_etr;
-	if (salt[0] == 0 || salt[1] == 0) salt = "**";
-	for (i = 0; i < 2; i++) {
-		char c = *salt++;
-		int j;
-
-		result[i] = c;
-		if ( c > 'Z') c -= 6 + 7 + '.';	/* c was a lower case letter */
-		else if ( c > '9') c -= 7 + '.';/* c was upper case letter */
-		else c -= '.';			/* c was digit, '.' or '/'. */
-						/* now, 0 <= c <= 63 */
-		for (j = 0; j < 6; j++) {
-			if ((c >> j) & 01) {
-				int t = 6*i + j;
-				int temp = new_etr.o_data[t];
-				new_etr.o_data[t] = new_etr.o_data[t+24];
-				new_etr.o_data[t+24] = temp;
-			}
-		}
-	}
-
-	if (result[1] == 0) result[1] = result[0];
-
-	for (i = 0; i < 25; i++) encrypt(pwb,0);
-	EP = &etr;
-
-	p = pwb;
-	cp = result+2;
-	while (p < &pwb[66]) {
-		int c = 0;
-		int j = 6;
-
-		while (j--) {
-			c <<= 1;
-			c |= *p++;
-		}
-		c += '.';		/* becomes >= '.' */
-		if (c > '9') c += 7;	/* not in [./0-9], becomes upper */
-		if (c > 'Z') c += 6;	/* not in [A-Z], becomes lower */
-		*cp++ = c;
-	}
-	*cp = 0;
-	return result;
-}
Index: trunk/minix/commands/simple/ramdisk.c
===================================================================
--- trunk/minix/commands/simple/ramdisk.c	(revision 9)
+++ 	(revision )
@@ -1,38 +1,0 @@
-
-#include <minix/paths.h>
-
-#include <sys/ioc_memory.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <stdlib.h>
-
-int
-main(int argc, char *argv[])
-{
-	int fd;
-	signed long size;
-	if((fd=open(_PATH_RAMDISK, O_RDONLY)) < 0) {
-		perror(_PATH_RAMDISK);
-		return 1;
-	}
-
-	if(argc != 2) {
-		fprintf(stderr, "usage: %s <size in bytes>\n", argv[0]);
-		return 1;
-	}
-
-	size = atol(argv[1]);
-
-	if(size <= 0) {
-		fprintf(stderr, "size should be positive.\n");
-		return 1;
-	}
-
-	if(ioctl(fd, MIOCRAMSIZE, &size) < 0) {
-		perror("MIOCRAMSIZE");
-		return 1;
-	}
-
-	return 0;
-}
-
Index: trunk/minix/commands/simple/rarpd.c
===================================================================
--- trunk/minix/commands/simple/rarpd.c	(revision 9)
+++ 	(revision )
@@ -1,365 +1,0 @@
-/*
-rarpd.c
-
-Created:	Nov 12, 1992 by Philip Homburg
-
-Changed:	May 13, 1995 by Kees J. Bot
-		Rewrite to handle multiple ethernets.
-
-Changed:	Jul 18, 1995 by Kees J. Bot
-		Do RARP requests (formerly inet's job)
-
-Changed:	Dec 14, 1996 by Kees J. Bot
-		Query the netmask
-
-Changed:	Dec 11, 2000 by Kees J. Bot
-		Dressed down to be only a RARP server, giving the floor to DHCP
-*/
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/asynchio.h>
-#include <net/hton.h>
-#include <net/gen/socket.h>
-#include <net/gen/netdb.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/ether.h>
-#include <net/gen/eth_io.h>
-#include <net/gen/if_ether.h>
-#include <net/gen/ip_io.h>
-#include <net/gen/nameser.h>
-
-#define MAX_RARP_RETRIES	5
-#define RARP_TIMEOUT		5
-
-typedef struct rarp46
-{
-	ether_addr_t a46_dstaddr;
-	ether_addr_t a46_srcaddr;
-	ether_type_t a46_ethtype;
-	u16_t a46_hdr, a46_pro;
-	u8_t a46_hln, a46_pln;
-	u16_t a46_op;
-	ether_addr_t a46_sha;
-	u8_t a46_spa[4];
-	ether_addr_t a46_tha;
-	u8_t a46_tpa[4];
-	char a46_padding[ETH_MIN_PACK_SIZE - (4*6 + 2*4 + 4*2 + 2*1)];
-} rarp46_t;
-
-#define ETH_RARP_PROTO	0x8035
-
-#define RARP_ETHERNET	1
-
-#define RARP_REQUEST	3
-#define RARP_REPLY	4
-
-static char *program;
-static unsigned debug;
-
-#define between(a, c, z)	((unsigned) (c) - (a) <= (unsigned) (z) - (a))
-
-static void report(const char *label)
-{
-    fprintf(stderr, "%s: %s: %s\n", program, label, strerror(errno));
-}
-
-static void fatal(const char *label)
-{
-    report(label);
-    exit(1);
-}
-
-static void *allocate(size_t size)
-{
-    void *mem;
-
-    if ((mem= malloc(size)) == NULL) fatal("Can't allocate memory");
-    return mem;
-}
-
-static char *ethdev(int n)
-{
-    static char an_ethdev[]= "/dev/ethNNN";
-
-    sprintf(an_ethdev + sizeof(an_ethdev)-4, "%d", n);
-    return an_ethdev;
-}
-
-static char *ipdev(int n)
-{
-    static char an_ipdev[]= "/dev/ipNNN";
-
-    sprintf(an_ipdev + sizeof(an_ipdev)-4, "%d", n);
-    return an_ipdev;
-}
-
-typedef struct ethernet {
-	int		n;		/* Network number. */
-	int		eth_fd;		/* Open low level ethernet device. */
-	ether_addr_t	eth_addr;	/* Ethernet address of this net. */
-	char		packet[ETH_MAX_PACK_SIZE];	/* Incoming packet. */
-	ipaddr_t	ip_addr;	/* IP address of this net. */
-	ipaddr_t	ip_mask;	/* Associated netmask. */
-} ethernet_t;
-
-static ethernet_t *ethernets;
-
-static void onsig(int sig)
-{
-    switch (sig) {
-    case SIGUSR1:	debug++;	break;
-    case SIGUSR2:	debug= 0;	break;
-    }
-}
-
-static void rarp_reply(ethernet_t *ep, char *hostname, ipaddr_t ip_addr,
-						ether_addr_t eth_addr)
-{
-    rarp46_t rarp46;
-
-    /* Construct a RARP reply packet and send it. */
-    rarp46.a46_dstaddr= eth_addr;
-    rarp46.a46_hdr= HTONS(RARP_ETHERNET);
-    rarp46.a46_pro= HTONS(ETH_IP_PROTO);
-    rarp46.a46_hln= 6;
-    rarp46.a46_pln= 4;
-    rarp46.a46_op= HTONS(RARP_REPLY);
-    rarp46.a46_sha= ep->eth_addr;
-    memcpy(rarp46.a46_spa, &ep->ip_addr, sizeof(ipaddr_t));
-    rarp46.a46_tha= eth_addr;
-    memcpy(rarp46.a46_tpa, &ip_addr, sizeof(ipaddr_t));
-
-    if (debug >= 1) {
-	printf("%s: Replying %s (%s) to %s\n",
-	    ethdev(ep->n), inet_ntoa(ip_addr), hostname, ether_ntoa(&eth_addr));
-    }
-    (void) write(ep->eth_fd, &rarp46, sizeof(rarp46));
-}
-
-static int addhostname(char *addname, char *hostname, int n)
-{
-    /* Create an additional hostname for a given hostname by adding "-n" to
-     * the first part.  E.g. given "wombat.cs.vu.nl" and n=2 return
-     * "wombat-2.cs.vu.nl".  This is useful for VU practical work where
-     * people get a few extra ethernet addresses on a machine and are asked
-     * to build a TCP/IP stack on it.
-     */
-    char *dot;
-
-    if (strlen(hostname) + 4 >= 1024) return 0;
-    if ((dot= strchr(hostname, '.')) == NULL) dot= strchr(hostname, 0);
-    sprintf(addname, "%.*s-%d%s", (dot - hostname), hostname, n, dot);
-    return 1;
-}
-
-static void usage(void)
-{
-    fprintf(stderr, "Usage: %s [-d[level]] network-name ...\n", program);
-    exit(1);
-}
-
-static int ifname2n(const char *name)
-{
-    /* Translate an interface name, ip0, ip1, etc, to a number. */
-    const char *np;
-    char *end;
-    unsigned long n;
-
-    np= name;
-    if (*np++ != 'i' || *np++ != 'p') usage();
-    n= strtoul(np, &end, 10);
-    if (end == np || *end != 0) usage();
-    if (n >= 1000) {
-	fprintf(stderr, "%s: Network number of \"%s\" is a bit large\n",
-	    program, name);
-	exit(1);
-    }
-    return n;
-}
-
-int main(int argc, char **argv)
-{
-    int i;
-    ethernet_t *ep;
-    nwio_ethopt_t ethopt;
-    nwio_ethstat_t ethstat;
-    char hostname[1024];
-    struct hostent *hostent;
-    struct sigaction sa;
-    nwio_ipconf_t ipconf;
-    asynchio_t asyn;
-    ssize_t n;
-    ipaddr_t ip_addr;
-    rarp46_t rarp46;
-    int fd;
-    int n_eths;
-
-    program= argv[0];
-    asyn_init(&asyn);
-
-    debug= 0;
-    i= 1;
-    while (i < argc && argv[i][0] == '-') {
-	char *opt= argv[i++]+1;
-
-	if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-	while (*opt != 0) switch (*opt++) {
-	case 'd':
-	    debug= 1;
-	    if (between('0', *opt, '9')) debug= strtoul(opt, &opt, 10);
-	    break;
-	default:
-	    usage();
-	}
-    }
-
-    if ((n_eths= (argc - i)) == 0) usage();
-
-#if __minix_vmd
-    /* Minix-vmd can handle all nets at once using async I/O. */
-    ethernets= allocate(n_eths * sizeof(ethernets[0]));
-    for (i= 0; i < n_eths; i++) {
-	ethernets[i].n= ifname2n(argv[argc - n_eths + i]);
-    }
-#else
-    /* Minix forks n-1 times to handle each net in a process each. */
-    for (i= 0; i < n_eths; i++) {
-	if (i+1 < n_eths) {
-	    switch (fork()) {
-	    case -1:	fatal("fork()");
-	    case 0:		break;
-	    default:	continue;
-	    }
-	}
-	ethernets= allocate(1 * sizeof(ethernets[0]));
-	ethernets[0].n= ifname2n(argv[argc - n_eths + i]);
-    }
-    n_eths= 1;
-#endif
-
-    sa.sa_handler= onsig;
-    sigemptyset(&sa.sa_mask);
-    sa.sa_flags= 0;
-    sigaction(SIGUSR1, &sa, NULL);
-    sigaction(SIGUSR2, &sa, NULL);
-
-    for (i= 0; i < n_eths; i++) {
-	ep= &ethernets[i];
-	if ((ep->eth_fd= open(ethdev(ep->n), O_RDWR)) < 0) fatal(ethdev(ep->n));
-
-	if (ioctl(ep->eth_fd, NWIOGETHSTAT, &ethstat) < 0) {
-	    fprintf(stderr, "%s: %s: Unable to get eth statistics: %s\n",
-		program, ethdev(ep->n), strerror(errno));
-	    exit(1);
-	}
-	ep->eth_addr= ethstat.nwes_addr;
-	if (debug >= 1) {
-	    printf("%s: Ethernet address is %s\n",
-		ethdev(ep->n), ether_ntoa(&ep->eth_addr));
-	}
-
-	ethopt.nweo_flags= NWEO_COPY | NWEO_EN_LOC | NWEO_EN_BROAD |
-		NWEO_TYPESPEC;
-	ethopt.nweo_type= HTONS(ETH_RARP_PROTO);
-
-	if (ioctl(ep->eth_fd, NWIOSETHOPT, &ethopt) < 0) {
-	    fprintf(stderr, "%s: %s: Unable to set eth options: %s\n",
-		program, ethdev(ep->n), strerror(errno));
-	    exit(1);
-	}
-
-	/* What are my address and netmask? */
-	if ((fd= open(ipdev(ep->n), O_RDWR)) < 0) fatal(ipdev(ep->n));
-	if (ioctl(fd, NWIOGIPCONF, &ipconf) < 0) fatal(ipdev(ep->n));
-
-	ep->ip_addr= ipconf.nwic_ipaddr;
-	ep->ip_mask= ipconf.nwic_netmask;
-	close(fd);
-	if (debug >= 1) {
-	    printf("%s: IP address is %s / ",
-		ipdev(ep->n), inet_ntoa(ep->ip_addr));
-	    printf("%s\n", inet_ntoa(ep->ip_mask));
-	}
-    }
-
-    /* Wait for RARP requests, reply, repeat. */
-    for(;;) {
-	fflush(NULL);
-
-	/* Wait for a RARP request. */
-	for (i= 0; i < n_eths; i++) {
-	    ep= &ethernets[i];
-
-	    n= asyn_read(&asyn, ep->eth_fd, ep->packet, sizeof(ep->packet));
-	    if (n != -1) break;
-	    if (errno != EINPROGRESS) {
-		report(ethdev(ep->n));
-		sleep(10);
-	    }
-	}
-
-	/* RARP request? */
-	if (i < n_eths
-	    && n >= sizeof(rarp46)
-	    && (memcpy(&rarp46, ep->packet, sizeof(rarp46)), 1)
-	    && rarp46.a46_hdr == HTONS(RARP_ETHERNET)
-	    && rarp46.a46_pro == HTONS(ETH_IP_PROTO)
-	    && rarp46.a46_hln == 6
-	    && rarp46.a46_pln == 4
-	    && rarp46.a46_op == HTONS(RARP_REQUEST)
-	) {
-	    if ((ether_ntohost(hostname, &rarp46.a46_tha) == 0
-		  || (rarp46.a46_tha.ea_addr[0] == 'v'
-		    && (memcpy(&ip_addr, rarp46.a46_tha.ea_addr+2, 4), 1)
-		    && (hostent= gethostbyaddr((char*) &ip_addr,
-						4, AF_INET)) != NULL
-		    && addhostname(hostname, hostent->h_name,
-						rarp46.a46_tha.ea_addr[1])))
-		&& (hostent= gethostbyname(hostname)) != NULL
-		&& hostent->h_addrtype == AF_INET
-	    ) {
-		/* Host is found in the ethers file and the DNS, or the
-		 * ethernet address denotes a special additional address
-		 * used for implementing a TCP/IP stack in user space.
-		 */
-		for (i= 0; hostent->h_addr_list[i] != NULL; i++) {
-		    memcpy(&ip_addr, hostent->h_addr_list[i], sizeof(ipaddr_t));
-
-		    /* Check if the address is on this network. */
-		    if (((ip_addr ^ ep->ip_addr) & ep->ip_mask) == 0) break;
-		}
-
-		if (hostent->h_addr_list[i] != NULL) {
-		    rarp_reply(ep, hostname, ip_addr, rarp46.a46_tha);
-		} else {
-		    if (debug >= 2) {
-			printf("%s: Host '%s' (%s) is on the wrong net\n",
-			    ethdev(ep->n),
-			    hostname, ether_ntoa(&rarp46.a46_tha));
-		    }
-		}
-	    } else {
-		if (debug >= 2) {
-		    printf("%s: RARP request from unknown host '%s'\n",
-			ethdev(ep->n), ether_ntoa(&rarp46.a46_tha));
-		}
-	    }
-	}
-
-	/* Wait for another request. */
-	if (asyn_wait(&asyn, 0, NULL) < 0) {
-	    report("asyn_wait()");
-	    sleep(10);
-	}
-    }
-}
Index: trunk/minix/commands/simple/rawspeed.c
===================================================================
--- trunk/minix/commands/simple/rawspeed.c	(revision 9)
+++ 	(revision )
@@ -1,273 +1,0 @@
-/*	rawspeed 1.15 - Measure speed of a device.	Author: Kees J. Bot
- *								26 Apr 1992
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <signal.h>
-#include <string.h>
-#include <time.h>
-#if !__minix
-#include <sys/time.h>
-#endif
-#include <fcntl.h>
-#include <limits.h>
-#include <sys/stat.h>
-
-#define SECTOR_SIZE		512
-#define BLK_MAX_SECTORS		(sizeof(int) == 2 ? 32 : 64)
-#define CHR_MAX_SECTORS		(sizeof(int) == 2 ? 63 : 512)
-#define ABS_MAX_SECTORS		(INT_MAX / SECTOR_SIZE)
-
-#define USEC	(!__minix || __minix_vmd)
-
-/* Any good random number generator around? */
-#if __minix_vmd || __linux
-#define	rand	random
-#define srand	srandom
-#endif
-
-#if __sun && __svr4__
-#define rand	lrand48
-#define srand	srand48
-#endif
-
-void report(const char *label)
-{
-	fprintf(stderr, "rawspeed: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-void usage(void)
-{
-	fprintf(stderr,
-"Usage: rawspeed [-u unit] [-m max] [-t seconds] [-c] [-r limit] device\n");
-	fprintf(stderr,
-"       -u unit = best sector multiple (default 2)\n");
-	fprintf(stderr,
-"       -m max = read multiples of unit upto 'max' (default %d raw, %d file)\n",
-					CHR_MAX_SECTORS, BLK_MAX_SECTORS);
-	fprintf(stderr,
-"       -t seconds = time to run test (default 10)\n");
-	fprintf(stderr,
-"       -c = cache test: rewind after each read or write of max size\n");
-	fprintf(stderr,
-"       -r limit = random seeks upto sector 'limit' before reading or writing\n");
-	exit(1);
-}
-
-int done= 0;
-
-void timeout(int sig)
-{
-	done= 1;
-}
-
-int main(int argc, char **argv)
-{
-	int i, fd, n= 0, unit= -1, max= -1, cache= 0;
-	int size, seconds= 10;
-	long tenthsec;
-#if USEC
-	struct timeval start_time, end_time;
-	struct timezone dummy;
-#else
-	time_t start_time;
-#endif
-	off_t nbytes= 0, wbytes= 0, randlimit= 0;
-	char *device, *chunk;
-	struct stat st;
-	off_t nseeks= 0;
-
-	for (i= 1; i < argc && argv[i][0] == '-' && argv[i][1] != 0; i++) {
-		char *opt;
-
-		if (argv[i][1] == '-' && argv[i][2] == 0) { i++; break; }
-
-		for (opt= argv[i]+1; *opt != 0; opt++) {
-			switch (*opt) {
-			case 'w':
-				if (i == argc) usage();
-				wbytes= atol(argv[++i]) * 1024;
-				if (wbytes <= 0) usage();
-				break;
-			case 'm':
-				if (i == argc) usage();
-				max= atoi(argv[++i]);
-				if (max <= 0 || max > ABS_MAX_SECTORS)
-					usage();
-				break;
-			case 'u':
-				if (i == argc) usage();
-				unit= atoi(argv[++i]);
-				if (unit <= 0 || unit > ABS_MAX_SECTORS)
-					usage();
-				break;
-			case 't':
-				if (i == argc) usage();
-				seconds= atoi(argv[++i]);
-				if (seconds <= 0) usage();
-				break;
-			case 'c':
-				cache= 1;
-				break;
-			case 'r':
-				if (i == argc) usage();
-				randlimit= atol(argv[++i]);
-				if (randlimit <= 0) usage();
-				break;
-			default:
-				usage();
-			}
-		}
-	}
-
-	if (i != argc - 1) usage();
-
-	if (strcmp(argv[i], "-") == 0) {
-		fd= wbytes == 0 ? 0 : 1;
-		device= "";
-	} else {
-		device= argv[i];
-		if ((fd= open(device,
-			wbytes == 0 ? O_RDONLY : O_WRONLY | O_CREAT, 0666)) < 0)
-				fatal(device);
-	}
-	if (max < 0) {
-		if (fstat(fd, &st) >= 0 && S_ISCHR(st.st_mode))
-			max= CHR_MAX_SECTORS;
-		else
-			max= BLK_MAX_SECTORS;
-	}
-
-	if (unit < 0) unit= max > 1 ? 2 : 1;
-	unit*= max / unit;
-	if (unit == 0) usage();
-	size= unit * SECTOR_SIZE;
-	randlimit/= unit;
-
-	if ((chunk= malloc((size_t) size)) == nil) {
-		fprintf(stderr, "rawspeed: can't grab %d bytes: %s\n",
-			size, strerror(errno));
-		exit(1);
-	}
-
-	/* Touch the pages to get real memory sending other processes to swap.
-	 */
-	memset((void *) chunk, 0, (size_t) size);
-
-	/* Clean the cache. */
-	sync();
-
-	signal(SIGALRM, timeout);
-	signal(SIGINT, timeout);
-#if USEC
-	gettimeofday(&start_time, &dummy);
-	if (randlimit != 0) srand((int) (start_time.tv_sec & INT_MAX));
-#else
-	start_time= time((time_t *) nil);
-	if (randlimit != 0) srand((int) (start_time & INT_MAX));
-#endif
-	alarm(seconds);
-
-	if (wbytes > 0) {
-		while (!done && (n= write(fd, chunk, size)) > 0
-						&& (nbytes+= n) < wbytes) {
-			if (cache && lseek(fd, (off_t) 0, SEEK_SET) == -1)
-				fatal(device);
-			if (randlimit != 0) {
-				if (lseek(fd, (off_t)
-					(rand() % randlimit * size),
-							SEEK_SET) == -1)
-					fatal(device);
-				nseeks++;
-			}
-		}
-		sync();
-	} else {
-		while (!done && (n= read(fd, chunk, size)) > 0) {
-			nbytes+= n;
-			if (cache && lseek(fd, (off_t) 0, SEEK_SET) == -1)
-				fatal(device);
-			if (randlimit != 0) {
-				if (lseek(fd, (off_t)
-					(rand() % randlimit * size),
-							SEEK_SET) == -1)
-					fatal(device);
-				nseeks++;
-			}
-		}
-	}
-
-#if USEC
-	gettimeofday(&end_time, &dummy);
-	tenthsec= (end_time.tv_sec - start_time.tv_sec) * 10
-		+ (end_time.tv_usec - start_time.tv_usec) / 100000;
-#else
-	tenthsec= (time((time_t *) 0) - start_time) * 10;
-#endif
-	if (n < 0 && errno == EINTR) n= 0;
-	if (n < 0) report(device);
-
-	if (nbytes > 0) {
-		off_t kBpts;
-
-		fprintf(stderr, "%ld kB / %d.%d s = ",
-			(nbytes + 512) / 1024,
-			tenthsec / 10, tenthsec % 10);
-		if (tenthsec < 5)
-			fprintf(stderr, "infinite\n");
-		else {
-			if (nbytes > LONG_MAX / 100) {
-				seconds = (tenthsec + 5) / 10;
-				kBpts= (nbytes + 512L * seconds)
-							/ (1024L * seconds);
-				fprintf(stderr, "%ld kB/s\n", kBpts);
-			} else {
-				kBpts= (100 * nbytes + 512L * tenthsec)
-							/ (1024L * tenthsec);
-				fprintf(stderr, "%ld.%ld kB/s\n",
-					kBpts/10, kBpts%10);
-			}
-		}
-	}
-	if (randlimit != 0 && tenthsec >= 5) {
-		int rpm, disc= 0;
-		off_t tenthms;
-
-		tenthms= (tenthsec * 1000 + nseeks/2) / nseeks;
-
-		fprintf(stderr,
-			"%ld seeks / %d.%d s = %ld seeks/s = %ld.%ld ms/seek\n",
-			nseeks, tenthsec / 10, tenthsec % 10,
-			(nseeks * 10 + tenthsec/2) / tenthsec,
-			tenthms / 10, tenthms % 10);
-
-		for (rpm= 3600; rpm <= 7200; rpm+= 1800) {
-			int rotms = (10000L / 2 * 60 + rpm/2) / rpm;
-
-			if (tenthms <= rotms) continue;
-
-			if (!disc) {
-				fprintf(stderr,
-					"discarding av. rotational delay:\n  ");
-				disc= 1;
-			} else {
-				fprintf(stderr, ", ");
-			}
-			fprintf(stderr, "%ld.%ld ms (%d rpm)",
-				(tenthms - rotms) / 10, (tenthms - rotms) % 10,
-				rpm);
-		}
-		if (disc) fputc('\n', stdout);
-	}
-	return n < 0 ? 1 : 0;
-}
Index: trunk/minix/commands/simple/rcp.c
===================================================================
--- trunk/minix/commands/simple/rcp.c	(revision 9)
+++ 	(revision )
@@ -1,848 +1,0 @@
-/*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1983 Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)rcp.c 1.1 87/12/21 SMI"; /* from UCB 5.3 6/8/85"*/
-#endif /* not lint */
-
-/*
- * rcp
- */
-
-#undef _MINIX
-#define NAMESERVER
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <utime.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-
-#include <dirent.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <signal.h>
-#include <unistd.h>
-
-#include <net/gen/netdb.h>
-#include <net/netlib.h>
-
-#if __STDC__
-#define PROTO(func, args)	func args
-#else
-#define PROTO(func, args)	func ()
-#endif /* __STDC__ */
-
-PROTO (int main, (int argc, char *argv[]));
-PROTO (void lostconn, (int sig));
-PROTO (void error, (char *fmt, ...) );
-PROTO (int response, (void) );
-PROTO (void source, (int argc, char *argv[]) );
-PROTO (void sink, (int argc, char *argv[]) );
-PROTO (void usage, (void) );
-PROTO (char *colon, (char *cp) );
-PROTO (int okname, (char *cp0) );
-PROTO (int susystem, (char *s) );
-PROTO (void verifydir, (char *cp) );
-PROTO (void rsource, (char *name, struct stat *statp) );
-PROTO (struct buffer *allocbuf, (struct buffer *bp, int fd, int blksize) );
-
-#define vfork	fork
-
-int	rem;
-int	errs;
-int	errno;
-int	iamremote, targetshouldbedirectory;
-int	iamrecursive;
-int	myuid;		/* uid of invoker */
-int	pflag;
-struct	passwd *pwd;
-int	userid;
-int	port;
-
-struct buffer {
-	int	cnt;
-	char	*buf;
-};
-
-
-#define	ga()	 	(void) write(rem, "", 1)
-
-main(argc, argv)
-	int argc;
-	char **argv;
-{
-	char *targ, *host, *src;
-#ifndef NAMESERVER
-	char *suser, *tuser;
-#else /* NAMESERVER */
-	char *suser, *tuser, *thost;
-#endif /* NAMESERVER */
-	int i;
-	char buf[BUFSIZ], cmd[16];
-	struct servent *sp;
-
-	sp = getservbyname("shell", "tcp");
-	if (sp == NULL) {
-		fprintf(stderr, "rcp: shell/tcp: unknown service\n");
-		exit(1);
-	}
-	port = sp->s_port;
-	pwd = getpwuid(userid = getuid());
-	if (pwd == 0) {
-		fprintf(stderr, "who are you?\n");
-		exit(1);
-	}
-
-#ifdef NOT_DEF
-	/*
-	 * This is a kludge to allow seteuid to user before touching
-	 * files and seteuid root before doing rcmd so we can open
-	 * the socket.
-	 */
-	myuid = getuid();
-	if (setruid(0) < 0) {
-		perror("setruid root");
-		exit(1);
-	}
-	seteuid(myuid);
-#endif
-
-	for (argc--, argv++; argc > 0 && **argv == '-'; argc--, argv++) {
-		(*argv)++;
-		while (**argv) switch (*(*argv)++) {
-
-		    case 'r':
-			iamrecursive++;
-			break;
-
-		    case 'p':		/* preserve mtimes and atimes */
-			pflag++;
-			break;
-
-		    /* The rest of these are not for users. */
-		    case 'd':
-			targetshouldbedirectory = 1;
-			break;
-
-		    case 'f':		/* "from" */
-			iamremote = 1;
-			(void) response();
-			source(--argc, ++argv);
-			exit(errs);
-
-		    case 't':		/* "to" */
-			iamremote = 1;
-			sink(--argc, ++argv);
-			exit(errs);
-
-		    default:
-			usage();
-			exit(1);
-		}
-	}
-if (iamremote)
-{
-	close(2);
-	open("/dev/tty", 2);
-}
-
-	if (argc < 2) {
-		usage();
-		exit(1);
-	}
-	rem = -1;
-	if (argc > 2)
-		targetshouldbedirectory = 1;
-	(void) sprintf(cmd, "rcp%s%s%s",
-	    iamrecursive ? " -r" : "", pflag ? " -p" : "", 
-	    targetshouldbedirectory ? " -d" : "");
-	(void) signal(SIGPIPE, lostconn);
-	targ = colon(argv[argc - 1]);
-	if (targ) {				/* ... to remote */
-		*targ++ = 0;
-		if (*targ == 0)
-			targ = ".";
-#ifndef NAMESERVER
-		tuser = strrchr(argv[argc - 1], '.');
-		if (tuser) {
-			*tuser++ = 0;
-			if (!okname(tuser))
-				exit(1);
-		} else
-			tuser = pwd->pw_name;
-#else /* NAMESERVER */
-		thost = strchr(argv[argc - 1], '@');
-		if (thost) {
-			*thost++ = 0;
-			tuser = argv[argc - 1];
-			if (*tuser == '\0')
-				tuser = pwd->pw_name;
-			else if (!okname(tuser))
-				exit(1);
-		} else {
-			thost = argv[argc - 1];
-			tuser = pwd->pw_name;
-		}
-#endif /* NAMESERVER */
-		for (i = 0; i < argc - 1; i++) {
-			src = colon(argv[i]);
-			if (src) {		/* remote to remote */
-				*src++ = 0;
-				if (*src == 0)
-					src = ".";
-#ifndef NAMESERVER
-				suser = strrchr(argv[i], '.');
-				if (suser) {
-					*suser++ = 0;
-					if (!okname(suser))
-#else /* NAMESERVER */
-				host = strchr(argv[i], '@');
-				if (host) {
-					*host++ = 0;
-					suser = argv[i];
-					if (*suser == '\0')
-						suser = pwd->pw_name;
-					else if (!okname(suser))
-#endif /* NAMESERVER */
-						continue;
-#ifndef NAMESERVER
-		(void) sprintf(buf, "rsh %s -l %s -n %s %s '%s.%s:%s'",
-					    argv[i], suser, cmd, src,
-					    argv[argc - 1], tuser, targ);
-				} else
-		(void) sprintf(buf, "rsh %s -n %s %s '%s.%s:%s'",
-					    argv[i], cmd, src,
-					    argv[argc - 1], tuser, targ);
-#else /* NAMESERVER */
-		(void) sprintf(buf, "rsh %s -l %s -n %s %s '%s@%s:%s'",
-					    host, suser, cmd, src,
-					    tuser, thost, targ);
-				} else
-		(void) sprintf(buf, "rsh %s -n %s %s '%s@%s:%s'",
-					    argv[i], cmd, src,
-					    tuser, thost, targ);
-#endif /* NAMESERVER */
-				(void) susystem(buf);
-			} else {		/* local to remote */
-				if (rem == -1) {
-					(void) sprintf(buf, "%s -t %s",
-					    cmd, targ);
-#ifndef NAMESERVER
-					host = argv[argc - 1];
-#else /* NAMESERVER */
-					host = thost;
-#endif /* NAMESERVER */
-#ifdef NOT_DEF
-					if (seteuid(0) < 0) {
-						perror("seteuid root");
-						exit(1);
-					}
-#endif
-					rem = rcmd(&host, port, pwd->pw_name,
-					    tuser, buf, 0);
-#ifdef NO_DEF
-					seteuid(myuid);
-#endif
-					if (rem < 0)
-						exit(1);
-					if (response() < 0)
-						exit(1);
-				}
-				source(1, argv+i);
-			}
-		}
-	} else {				/* ... to local */
-		if (targetshouldbedirectory)
-			verifydir(argv[argc - 1]);
-		for (i = 0; i < argc - 1; i++) {
-			src = colon(argv[i]);
-			if (src == 0) {		/* local to local */
-				(void) sprintf(buf, "cp%s%s %s %s",
-				    iamrecursive ? " -r" : "",
-				    pflag ? " -p" : "",
-				    argv[i], argv[argc - 1]);
-				(void) susystem(buf);
-			} else {		/* remote to local */
-				*src++ = 0;
-				if (*src == 0)
-					src = ".";
-#ifndef NAMESERVER
-				suser = strrchr(argv[i], '.');
-				if (suser) {
-					*suser++ = 0;
-					if (!okname(suser))
-#else /* NAMESERVER */
-				host = strchr(argv[i], '@');
-				if (host) {
-					*host++ = 0;
-					suser = argv[i];
-					if (*suser == '\0')
-						suser = pwd->pw_name;
-					else if (!okname(suser))
-#endif /* NAMESERVER */
-						continue;
-#ifndef NAMESERVER
-				} else
-#else /* NAMESERVER */
-				} else {
-					host = argv[i];
-#endif /* NAMESERVER */
-					suser = pwd->pw_name;
-#ifdef NAMESERVER
-				}
-#endif /* NAMESERVER */
-				(void) sprintf(buf, "%s -f %s", cmd, src);
-#ifndef NAMESERVER
-				host = argv[i];
-#endif /* NAMESERVER */
-#ifdef NOT_DEF
-				if (seteuid(0) < 0) {
-					perror("seteuid root");
-					exit(1);
-				}
-#endif
-				rem = rcmd(&host, port, pwd->pw_name, suser,
-				    buf, 0);
-#ifdef NOT_DEF
-				seteuid(myuid);
-#endif
-				if (rem < 0) {
-					errs++;
-					continue;
-				}
-				sink(1, argv+argc-1);
-				(void) close(rem);
-				rem = -1;
-			}
-		}
-	}
-	exit(errs);
-}
-
-void
-verifydir(cp)
-	char *cp;
-{
-	struct stat stb;
-
-	if (stat(cp, &stb) >= 0) {
-		if ((stb.st_mode & S_IFMT) == S_IFDIR)
-			return;
-		errno = ENOTDIR;
-	}
-	error("rcp: %s: %s.\n", cp, strerror(errno));
-	exit(1);
-}
-
-char *
-colon(cp)
-	char *cp;
-{
-
-	while (*cp) {
-		if (*cp == ':')
-			return (cp);
-		if (*cp == '/')
-			return (0);
-		cp++;
-	}
-	return (0);
-}
-
-
-int
-okname(cp0)
-	char *cp0;
-{
-	register char *cp = cp0;
-	register int c;
-
-	do {
-		c = *cp;
-		if (c & 0200)
-			goto bad;
-		if (!isalpha(c) && !isdigit(c) && c != '_' && c != '-')
-			goto bad;
-		cp++;
-	} while (*cp);
-	return (1);
-bad:
-	fprintf(stderr, "rcp: invalid user name %s\n", cp0);
-	return (0);
-}
-
-int
-susystem(s)
-	char *s;
-{
-	int status, pid, w;
-	register void PROTO ((*istat), (int) ), PROTO ((*qstat), (int) );
-
-	if ((pid = vfork()) == 0) {
-#ifdef NOT_DEF
-		(void) setruid(myuid);
-#endif
-		execl("/bin/sh", "sh", "-c", s, (char *)0);
-		_exit(127);
-	}
-	istat = signal(SIGINT, SIG_IGN);
-	qstat = signal(SIGQUIT, SIG_IGN);
-	while ((w = wait(&status)) != pid && w != -1)
-		;
-	if (w == -1)
-		status = -1;
-	(void) signal(SIGINT, istat);
-	(void) signal(SIGQUIT, qstat);
-	return (status);
-}
-
-void
-source(argc, argv)
-	int argc;
-	char **argv;
-{
-	char *last, *name;
-	struct stat stb;
-	static struct buffer buffer;
-	struct buffer *bp;
-	int x, sizerr, f, amt;
-	off_t i;
-	char buf[BUFSIZ];
-
-	for (x = 0; x < argc; x++) {
-		name = argv[x];
-		if ((f = open(name, 0)) < 0) {
-			error("rcp: %s: %s\n", name, strerror(errno));
-			continue;
-		}
-		if (fstat(f, &stb) < 0)
-			goto notreg;
-		switch (stb.st_mode&S_IFMT) {
-
-		case S_IFREG:
-			break;
-
-		case S_IFDIR:
-			if (iamrecursive) {
-				(void) close(f);
-				rsource(name, &stb);
-				continue;
-			}
-			/* fall into ... */
-		default:
-notreg:
-			(void) close(f);
-			error("rcp: %s: not a plain file\n", name);
-			continue;
-		}
-		last = strrchr(name, '/');
-		if (last == 0)
-			last = name;
-		else
-			last++;
-		if (pflag) {
-			/*
-			 * Make it compatible with possible future
-			 * versions expecting microseconds.
-			 */
-			(void) sprintf(buf, "T%ld 0 %ld 0\n",
-			    stb.st_mtime, stb.st_atime);
-			(void) write(rem, buf, strlen(buf));
-			if (response() < 0) {
-				(void) close(f);
-				continue;
-			}
-		}
-		(void) sprintf(buf, "C%04o %ld %s\n",
-		    stb.st_mode&07777, stb.st_size, last);
-		(void) write(rem, buf, strlen(buf));
-		if (response() < 0) {
-			(void) close(f);
-			continue;
-		}
-		if ((bp = allocbuf(&buffer, f, BUFSIZ)) == 0) {
-			(void) close(f);
-			continue;
-		}
-		sizerr = 0;
-		for (i = 0; i < stb.st_size; i += bp->cnt) {
-			amt = bp->cnt;
-			if (i + amt > stb.st_size)
-				amt = stb.st_size - i;
-			if (sizerr == 0 && read(f, bp->buf, amt) != amt)
-				sizerr = 1;
-			(void) write(rem, bp->buf, amt);
-		}
-		(void) close(f);
-		if (sizerr == 0)
-			ga();
-		else
-			error("rcp: %s: file changed size\n", name);
-		(void) response();
-	}
-}
-
-
-void
-rsource(name, statp)
-	char *name;
-	struct stat *statp;
-{
-	DIR *d = opendir(name);
-	char *last;
-	struct dirent *dp;
-	char buf[BUFSIZ];
-	char *bufv[1];
-
-	if (d == 0) {
-		error("rcp: %s: %s\n", name, strerror(errno));
-		return;
-	}
-	last = strrchr(name, '/');
-	if (last == 0)
-		last = name;
-	else
-		last++;
-	if (pflag) {
-		(void) sprintf(buf, "T%ld 0 %ld 0\n",
-		    statp->st_mtime, statp->st_atime);
-		(void) write(rem, buf, strlen(buf));
-		if (response() < 0) {
-			closedir(d);
-			return;
-		}
-	}
-	(void) sprintf(buf, "D%04o %d %s\n", statp->st_mode&07777, 0, last);
-	(void) write(rem, buf, strlen(buf));
-	if (response() < 0) {
-		closedir(d);
-		return;
-	}
-	while (dp = readdir(d)) {
-		if (dp->d_ino == 0)
-			continue;
-		if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
-			continue;
-		if (strlen(name) + 1 + strlen(dp->d_name) >= BUFSIZ - 1) {
-			error("%s/%s: Name too long.\n", name, dp->d_name);
-			continue;
-		}
-		(void) sprintf(buf, "%s/%s", name, dp->d_name);
-		bufv[0] = buf;
-		source(1, bufv);
-	}
-	closedir(d);
-	(void) write(rem, "E\n", 2);
-	(void) response();
-}
-
-int
-response()
-{
-	char resp, c, rbuf[BUFSIZ], *cp = rbuf;
-
-	if (read(rem, &resp, 1) != 1)
-		lostconn(0);
-	switch (resp) {
-
-	case 0:				/* ok */
-		return (0);
-
-	default:
-		*cp++ = resp;
-		/* fall into... */
-	case 1:				/* error, followed by err msg */
-	case 2:				/* fatal error, "" */
-		do {
-			if (read(rem, &c, 1) != 1)
-				lostconn(0);
-			*cp++ = c;
-		} while (cp < &rbuf[BUFSIZ] && c != '\n');
-		if (iamremote == 0)
-			(void) write(2, rbuf, cp - rbuf);
-		errs++;
-		if (resp == 1)
-			return (-1);
-		exit(1);
-	}
-	/*NOTREACHED*/
-}
-
-void
-lostconn(sig)
-int sig;
-{
-
-	if (iamremote == 0)
-		fprintf(stderr, "rcp: lost connection\n");
-	exit(1);
-}
-
-void
-sink(argc, argv)
-	int argc;
-	char **argv;
-{
-	off_t i, j, size;
-	char *targ, *whopp, *cp;
-	int of, mode, wrerr, exists, first, count, amt;
-	struct buffer *bp;
-	static struct buffer buffer;
-	struct stat stb;
-	int targisdir = 0;
-	int mask = umask(0);
-	char *myargv[1];
-	char cmdbuf[BUFSIZ], nambuf[BUFSIZ];
-	int setimes = 0;
-	struct utimbuf utimbuf;
-#define atime	utimbuf.actime
-#define mtime	utimbuf.modtime
-	time_t dummy;
-#define	SCREWUP(str)	{ whopp = str; goto screwup; }
-
-#ifdef NOT_DEF
-	seteuid(pwd->pw_uid);
-#endif
-	if (!pflag)
-		(void) umask(mask);
-	if (argc != 1) {
-		error("rcp: ambiguous target\n");
-		exit(1);
-	}
-	targ = *argv;
-	if (targetshouldbedirectory)
-		verifydir(targ);
-	ga();
-	if (stat(targ, &stb) == 0 && (stb.st_mode & S_IFMT) == S_IFDIR)
-		targisdir = 1;
-	for (first = 1; ; first = 0) {
-		cp = cmdbuf;
-		if (read(rem, cp, 1) <= 0)
-			return;
-		if (*cp++ == '\n')
-			SCREWUP("unexpected '\\n'");
-		do {
-			if (read(rem, cp, 1) != 1)
-				SCREWUP("lost connection");
-		} while (*cp++ != '\n');
-		*cp = 0;
-		if (cmdbuf[0] == '\01' || cmdbuf[0] == '\02') {
-			if (iamremote == 0)
-				(void) write(2, cmdbuf+1, strlen(cmdbuf+1));
-			if (cmdbuf[0] == '\02')
-				exit(1);
-			errs++;
-			continue;
-		}
-		*--cp = 0;
-		cp = cmdbuf;
-		if (*cp == 'E') {
-			ga();
-			return;
-		}
-
-#define getnum(t) (t) = 0; while (isdigit(*cp)) (t) = (t) * 10 + (*cp++ - '0');
-		if (*cp == 'T') {
-			setimes++;
-			cp++;
-			getnum(mtime);
-			if (*cp++ != ' ')
-				SCREWUP("mtime.sec not delimited");
-			getnum(dummy);
-			if (*cp++ != ' ')
-				SCREWUP("mtime.usec not delimited");
-			getnum(atime);
-			if (*cp++ != ' ')
-				SCREWUP("atime.sec not delimited");
-			getnum(dummy);
-			if (*cp++ != '\0')
-				SCREWUP("atime.usec not delimited");
-			ga();
-			continue;
-		}
-		if (*cp != 'C' && *cp != 'D') {
-			/*
-			 * Check for the case "rcp remote:foo\* local:bar".
-			 * In this case, the line "No match." can be returned
-			 * by the shell before the rcp command on the remote is
-			 * executed so the ^Aerror_message convention isn't
-			 * followed.
-			 */
-			if (first) {
-				error("%s\n", cp);
-				exit(1);
-			}
-			SCREWUP("expected control record");
-		}
-		cp++;
-		mode = 0;
-		for (; cp < cmdbuf+5; cp++) {
-			if (*cp < '0' || *cp > '7')
-				SCREWUP("bad mode");
-			mode = (mode << 3) | (*cp - '0');
-		}
-		if (*cp++ != ' ')
-			SCREWUP("mode not delimited");
-		size = 0;
-		while (isdigit(*cp))
-			size = size * 10 + (*cp++ - '0');
-		if (*cp++ != ' ')
-			SCREWUP("size not delimited");
-		if (targisdir)
-			(void) sprintf(nambuf, "%s%s%s", targ,
-			    *targ ? "/" : "", cp);
-		else
-			(void) strcpy(nambuf, targ);
-		exists = stat(nambuf, &stb) == 0;
-		if (cmdbuf[0] == 'D') {
-			if (exists) {
-				if ((stb.st_mode&S_IFMT) != S_IFDIR) {
-					errno = ENOTDIR;
-					goto bad;
-				}
-				if (pflag)
-					(void) chmod(nambuf, mode);
-			} else if (mkdir(nambuf, mode) < 0)
-				goto bad;
-			myargv[0] = nambuf;
-			sink(1, myargv);
-			if (setimes) {
-				setimes = 0;
-				if (utime(nambuf, &utimbuf) < 0)
-					error("rcp: can't set times on %s: %s\n",
-					    nambuf, strerror(errno));
-			}
-			continue;
-		}
-		if ((of = creat(nambuf, mode)) < 0) {
-	bad:
-			error("rcp: %s: %s\n", nambuf, strerror(errno));
-			continue;
-		}
-		if (exists && pflag)
-			(void) chmod(nambuf, mode);
-		ga();
-		if ((bp = allocbuf(&buffer, of, BUFSIZ)) == 0) {
-			(void) close(of);
-			continue;
-		}
-		cp = bp->buf;
-		count = 0;
-		wrerr = 0;
-		for (i = 0; i < size; i += BUFSIZ) {
-			amt = BUFSIZ;
-			if (i + amt > size)
-				amt = size - i;
-			count += amt;
-			do {
-				j = read(rem, cp, amt);
-				if (j <= 0)
-					exit(1);
-				amt -= j;
-				cp += j;
-			} while (amt > 0);
-			if (count == bp->cnt) {
-				if (wrerr == 0 &&
-				    write(of, bp->buf, count) != count)
-					wrerr++;
-				count = 0;
-				cp = bp->buf;
-			}
-		}
-		if (count != 0 && wrerr == 0 &&
-		    write(of, bp->buf, count) != count)
-			wrerr++;
-		(void) close(of);
-		(void) response();
-		if (setimes) {
-			setimes = 0;
-			if (utime(nambuf, &utimbuf) < 0)
-				error("rcp: can't set times on %s: %s\n",
-				    nambuf, strerror(errno));
-		}				   
-		if (wrerr)
-			error("rcp: %s: %s\n", nambuf, strerror(errno));
-		else
-			ga();
-	}
-screwup:
-	error("rcp: protocol screwup: %s\n", whopp);
-	exit(1);
-}
-
-struct buffer *
-allocbuf(bp, fd, blksize)
-	struct buffer *bp;
-	int fd, blksize;
-{
-	struct stat stb;
-	int size;
-
-	if (fstat(fd, &stb) < 0) {
-		error("rcp: fstat: %s\n", strerror(errno));
-		return ((struct buffer *)0);
-	}
-	size= 0;
-#if NOT_DEF
-	size = roundup(stb.st_blksize, blksize);
-#endif
-	if (size == 0)
-		size = blksize;
-	if (bp->cnt < size) {
-		if (bp->buf != 0)
-			free(bp->buf);
-		bp->buf = (char *)malloc((unsigned) size);
-		if (bp->buf == 0) {
-			error("rcp: malloc: out of memory\n");
-			return ((struct buffer *)0);
-		}
-	}
-	bp->cnt = size;
-	return (bp);
-}
-
-/*VARARGS1*/
-#if __STDC__
-void
-error (char *fmt, ...)
-#else
-error(fmt)
-char *fmt;
-#endif
-{
-	char buf[BUFSIZ], *cp = buf;
-	va_list ap;
-
-	va_start(ap, fmt);
-
-	errs++;
-	*cp++ = 1;
-	(void) vsprintf(cp, fmt, ap);
-	va_end(ap);
-	(void) write(rem, buf, strlen(buf));
-	if (iamremote == 0)
-		(void) write(2, buf+1, strlen(buf+1));
-}
-
-void
-usage()
-{
-	fprintf(stderr, "Usage: rcp [-p] f1 f2; or: rcp [-rp] f1 ... fn d2\n");
-}
Index: trunk/minix/commands/simple/rdate.c
===================================================================
--- trunk/minix/commands/simple/rdate.c	(revision 9)
+++ 	(revision )
@@ -1,109 +1,0 @@
-/*	rdate 1.0 - Set time&date from remote host	Author: Kees J. Bot
- *								12 Oct 1995
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <time.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <net/hton.h>
-#include <net/netlib.h>
-#include <net/gen/in.h>
-#include <net/gen/netdb.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-
-void report(const char *label)
-{
-	fprintf(stderr, "rdate: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	char *tcp_device;
-	int fd;
-	int i;
-	struct servent *servent;
-	struct hostent *hostent;
-	u16_t time_port;
-	nwio_tcpconf_t tcpconf;
-	nwio_tcpcl_t tcpcl;
-	u32_t net_time;
-	time_t unix_time;
-
-	if (argc <= 1) {
-		fprintf(stderr, "Usage: rdate host ...\n");
-		exit(1);
-	}
-
-	/* Look up the port number of the TCP service "time". */
-	if ((servent= getservbyname("time", "tcp")) == nil) {
-		fprintf(stderr, "rdate: \"time\": unknown service\n");
-		exit(1);
-	}
-	time_port= servent->s_port;
-
-	if ((tcp_device= getenv("TCP_DEVICE")) == nil) tcp_device= TCP_DEVICE;
-
-	if ((fd= open(tcp_device, O_RDWR)) < 0) fatal(tcp_device);
-
-	/* Try each host on the command line. */
-	for (i= 1; i < argc; i++) {
-		if ((hostent= gethostbyname(argv[i])) == nil) {
-			fprintf(stderr, "rdate: %s: unknown host\n", argv[i]);
-			continue;
-		}
-
-		/* Configure a TCP channel and connect to the remote host. */
-
-		tcpconf.nwtc_flags= NWTC_LP_SEL | NWTC_SET_RA | NWTC_SET_RP;
-		memcpy(&tcpconf.nwtc_remaddr, hostent->h_addr, 4);
-		tcpconf.nwtc_remport= time_port;
-		if (ioctl(fd, NWIOSTCPCONF, &tcpconf) == -1) fatal(tcp_device);
-
-		tcpcl.nwtcl_flags= 0;
-		if (ioctl(fd, NWIOTCPCONN, &tcpcl) < 0) {
-			report(argv[i]);
-			continue;
-		}
-
-		/* Read four bytes to obtain the time. */
-		switch (read(fd, &net_time, sizeof(net_time))) {
-		case -1:
-			report(argv[i]);
-			continue;
-		default:
-			fprintf(stderr, "rdate: %s: short read\n", argv[i]);
-			continue;
-		case sizeof(net_time):
-			break;
-		}
-		break;
-	}
-	if (i == argc) exit(1);
-
-	/* Internet time is in seconds since 1900, UNIX time is in seconds
-	 * since 1970.
-	 */
-	unix_time= ntohl(net_time) - 2208988800;
-
-	/* Try to set the time and tell us about it. */
-	if (stime(&unix_time) < 0) {
-		printf("time on ");
-	} else {
-		printf("time set to ");
-	}
-	printf("%s: %s", argv[i], ctime(&unix_time));
-	exit(0);
-}
Index: trunk/minix/commands/simple/readall.c
===================================================================
--- trunk/minix/commands/simple/readall.c	(revision 9)
+++ 	(revision )
@@ -1,194 +1,0 @@
-/* readall - read a whole device fast		Author: Andy Tanenbaum */
-
-/* Readall reads all the blocks on a device as fast as it can.  If it hits
- * an error, it stops reading in large units and reads one block at a time.
- * It reports on all errors it finds.
- *
- * If the -b flag is given, the output is a shell script that can be run
- * to mark all the bad blocks.
- *
- * If the -t flag is given, only the total numbers of blocks is reported.
- *
- * Examples of usage:
- *	readall /dev/hd1		# read /dev/hd1
- *	readall -b /dev/hd2		# prepare bad block list on stdout
- *	readall -t /dev/ram		# report size of ram disk
- */
-
-#include <sys/types.h>
-#include <sys/ioc_disk.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <time.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define CHUNK    25		/* max number of blocks read at once */
-#define BLOCK_SIZE	1024	/* size of a block */
-#define RESUME  200		/* # good reads before going back to CHUNK */
-#define DIVISOR	 1000		/* how often to print statistics */
-#define STORE  4096		/* save this many bad blocks for summary */
-
-int chunk = CHUNK;		/* current number of blocks being read */
-long goodies;			/* incremented on good reads */
-long errors;			/* number of errors so far */
-int normal = 1;			/* set unless -b flag is given */
-int total = 0;			/* unset unless -t flag is given */
-char *name;			/* name of special file being read */
-
-char a[CHUNK * BLOCK_SIZE];	/* read buffer */
-long rotten[STORE];		/* list of bad blocks */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-static _PROTOTYPE(void output, (long blocks_read));
-
-/* print pretty progress meter with remaining no. of blocks and ETA on
- * stderr
- */
-void
-prettyprogress(long b, long nblocks, time_t starttime)
-{
-  /* print progress indication */
-  time_t spent, now;
-  long bpsec;
-  time(&now);
-  spent = now - starttime;
-  if(spent > 0 && (bpsec = b / spent) > 0) {
-  	int len, i;
-  	long secremain, minremain, hremain;
-	  secremain = (nblocks - b) / bpsec;
-	  minremain = (secremain / 60) % 60;
-	  hremain = secremain / 3600;
-  	len = fprintf(stderr, "Remain %ld blocks. ETA: %d:%02d:%02d  [",
-  		nblocks - b,
-  		hremain, minremain, secremain % 60);
-#define WIDTH 77
-  	len = WIDTH - len;
-  	for(i = 0; i < (b * (len-1) / nblocks); i++) 
-  		fprintf(stderr, "=");
- 	fprintf(stderr, "|");
-  	for(; i < len-2; i++) 
-  		fprintf(stderr, "-");
-  	fprintf(stderr, "]\r");
-  	fflush(stderr);
-  }
-
-  return;
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  struct partition entry;
-  int fd, s, i, badprinted;
-  long b = 0, nblocks;
-  char *p;
-  time_t starttime;
-
-  if (argc != 2 && argc != 3) {
-	fprintf(stderr, "Usage: readall [-b | -t] file\n");
-	exit(1);
-  }
-  i = 1;
-
-  p = argv[1];
-  if (*p == '-' && *(p + 1) == 'b' && *(p + 2) == '\0') {
-	normal = 0;
-	i++;
-	name = argv[i];
-  }
-  if (*p == '-' && *(p + 1) == 't' && *(p + 2) == '\0') {
-	normal = 0;
-	total = 1;
-	i++;
-	name = argv[i];
-  }
-  fd = open(argv[i], O_RDONLY);
-  if (fd < 0) {
-  	perror(argv[i]);
-	fprintf(stderr, "%s is not readable\n", argv[i]);
-	exit(1);
-  }
-
-  /* Get size of file */
-  if(ioctl(fd, DIOCGETP, &entry) < 0) {
-  	perror("ioctl DIOCGETP");
-  	return 1;
-  }
-  nblocks = div64u(entry.size, BLOCK_SIZE);
-
-  time(&starttime);
-  /* Read the entire file. Try it in large chunks, but if an error
-   * occurs, go to single reads for a while. */
-  while (1) {
-	if(lseek(fd, BLOCK_SIZE * b, SEEK_SET) < 0) {
-		perror("lseek");
-		return 1;
-	}
-	s = read(fd, a, BLOCK_SIZE * chunk);
-	if (s == BLOCK_SIZE * chunk) {
-		/* Normal read, no errors. */
-		b += chunk;
-		goodies++;
-		if (chunk == 1) {
-			if (goodies >= RESUME && b % DIVISOR == 0)
-				chunk = CHUNK;
-		}
-  		if(b % DIVISOR == 0 && !normal) {
-  			prettyprogress(b, nblocks, starttime);
-  		}
-	} else if (s < 0) {
-		/* I/O error. */
-		if (chunk != 1) {
-			chunk = 1;	/* regress to single block mode */
-			continue;
-		}
-		if (errors == STORE) {
-			fprintf(stderr,
-			 "\n%ld Bad blocks is too many.  Exiting\n",
-				errors);
-			exit(1);
-		}
-		rotten[(int) errors] = b;	/* log the error */
-		b += chunk;
-		errors++;
-	} else {
-		/* End of file. */
-		b += s / BLOCK_SIZE;
-		if (normal) {
-			output(b);
-			fprintf(stderr, "\n");
-		} else fprintf(stderr, "\r%*s\n", -WIDTH, "Done scanning.");
-		if (total) printf("%8ld\n", b);
-		if ((errors == 0) || total) exit(0);
-		badprinted = 0;
-		if (normal) printf("Summary of bad blocks\n");
-
-		/* Print summary of bad blocks, possibly as shell script. */
-		for (i = 0; i < errors; i++) {
-			if (normal == 0 && badprinted == 0) {
-				printf("badblocks %s ", name);
-				badprinted = 1;
-			}
-			printf("%6ld ", rotten[i]);
-			if ((i + 1) % 7 == 0) {
-				printf("\n");
-				badprinted = 0;
-			}
-		}
-		printf("\n");
-		exit(0);
-	}
-	if (normal && b % DIVISOR == 0) output(b);
-  }
-}
-
-static void output(blocks_read)
-long blocks_read;
-{
-  fprintf(stderr, "%8ld blocks read, %5ld errors\r", blocks_read, errors);
-  fflush(stderr);
-}
Index: trunk/minix/commands/simple/readfs.c
===================================================================
--- trunk/minix/commands/simple/readfs.c	(revision 9)
+++ 	(revision )
@@ -1,601 +1,0 @@
-/* readfs - read a MINIX file system	Author: Paul Polderman */
-
-/* Command: readfs - read and extract a MINIX filesystem.
- *
- * Syntax:  readfs [-li] block-special [directory]
- *
- * Flags: -l:	Extract files and dirs and produce a mkfs-listing on stdout
- * 	  -i:	Information only: give the listing, but do not extract files.
- *	  -d:	Don't extract regular files, just the skeleton please.
- *
- * Examples: readfs /dev/fd1		# extract all files from /dev/fd1.
- * 	     readfs -i /dev/hd2		# see what's on /dev/hd2.
- * 	     readfs -l /dev/at0 rootfs	# extract and list the filesystem
- * 					# of /dev/at0 and put the tree
- * 					# in the directory `rootfs'.
- *
- *   Readfs reads a MINIX filesystem and extracts recursively all directories
- * and files, and (optionally) produces a mkfs-listing of them on stdout.
- * The root directory contents are placed in the current directory, unless
- * a directory is given as argument, in which case the contents are put there.
- * Readfs tries to restore the attributes (mode/uid/gid/time) of the files
- * extracted to those of the original files.
- * Special files are created as ordinary files, but the mkfs-listing
- * enables mkfs to restore them to original.
- */
-
-#include <sys/types.h>
-#include <sys/dir.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <utime.h>
-#include <dirent.h>
-
-#define BLOCK_SIZE _STATIC_BLOCK_SIZE
-
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include "../../servers/fs/const.h"
-#include "../../servers/fs/type.h"
-#include "../../servers/fs/buf.h"
-#include "../../servers/fs/super.h"
-
-#undef printf			/* Definition used only in the kernel */
-#include <stdio.h>
-
-/* Compile with -I/user0/ast/minix
- * (i.e. the directory containing the MINIX system sources)
- *
- *	Author: Paul Polderman (polder@cs.vu.nl) April 1987
- */
-
-char verbose = 0;		/* give a mkfs-listing of the filesystem */
- /* And extracts its contents. */
-char noaction = 0;		/* just give a mkfs-listing, do not extract
-			 * files. */
-char nofiles = 0;		/* only extract the skeleton FS structure */
-
-struct super_block sb;
-char pathname[1024];
-int inodes_per_block;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void get_flags, (char *flags));
-_PROTOTYPE(void readfs, (char *special_file, char *directory));
-_PROTOTYPE(int get_inode, (int fd, Ino_t inum, d1_inode * ip));
-_PROTOTYPE(void dump_dir, (int special, d1_inode * ip, char *directory));
-_PROTOTYPE(int dump_file, (int special, d1_inode * ip, char *filename));
-_PROTOTYPE(int get_fileblock, (int special, d1_inode * ip, block_t b, struct buf * bp));
-_PROTOTYPE(int get_block, (int fd, block_t block, struct buf * bp, int type));
-_PROTOTYPE(int get_rawblock, (int special, block_t blockno, char *bufp));
-_PROTOTYPE(void restore, (char *name, d1_inode * ip));
-_PROTOTYPE(void show_info, (char *name, d1_inode * ip, char *path));
-_PROTOTYPE(void do_indent, (int i));
-_PROTOTYPE(int Mkdir, (char *directory));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  switch (argc) {
-      case 2:
-	pathname[0] = '\0';
-	readfs(argv[1], pathname);
-	break;
-      case 3:
-	if (argv[1][0] == '-') {
-		get_flags(&argv[1][1]);
-		pathname[0] = '\0';
-		readfs(argv[2], pathname);
-	} else {
-		strcpy(pathname, argv[2]);
-		readfs(argv[1], pathname);
-	}
-	break;
-      case 4:
-	if (argv[1][0] == '-') {
-		get_flags(&argv[1][1]);
-		strcpy(pathname, argv[3]);
-		readfs(argv[2], pathname);
-		break;
-	}			/* else fall through .. */
-      default:
-	fprintf(stderr, "Usage: %s [-li] <special> [dirname]\n", argv[0]);
-	exit(1);
-  }
-  return(0);
-}
-
-void get_flags(flags)
-register char *flags;
-{
-  while (*flags) {
-	switch (*flags) {
-	    case 'L':
-	    case 'l':	verbose = 1;	break;
-	    case 'I':
-	    case 'i':
-		noaction = 1;
-		verbose = 1;
-		break;
-	    case 'D':
-	    case 'd':	nofiles = 1;	break;
-	    default:
-		fprintf(stderr, "Bad flag: %c\n", *flags);
-		break;
-	}
-	flags++;
-  }
-}
-
-#define	zone_shift	(sb.s_log_zone_size)	/* zone to block ratio */
-
-void readfs(special_file, directory)
-char *special_file, *directory;
-/* Readfs: opens the given special file (with MINIX filesystem),
- * and extracts its contents into the given directory.
- */
-{
-  d1_inode root_inode;
-  int special, magic;
-  off_t super_b;
-
-  umask(0);
-
-  /* Open the special file */
-  if ((special = open(special_file, O_RDONLY)) < 0) {
-	fprintf(stderr, "cannot open %s\n", special_file);
-	return;
-  }
-
-  /* Read the superblock */
-  super_b = (off_t) 1 *(off_t) BLOCK_SIZE;
-  if (lseek(special, super_b, SEEK_SET) != super_b) {
-	fprintf(stderr, "cannot seek to superblock\n");
-	return;
-  }
-  if (read(special, (char *) &sb, sizeof(struct super_block))
-      != sizeof(struct super_block)) {
-	fprintf(stderr, "cannot read superblock\n");
-	return;
-  }
-
-  /* The number of inodes in a block differs in V1 and V2. */
-  magic = sb.s_magic;
-  if (magic == SUPER_MAGIC || magic == SUPER_REV) {
-	inodes_per_block = V1_INODES_PER_BLOCK;
-  } else {
-	inodes_per_block = V2_INODES_PER_BLOCK(BLOCK_SIZE);
-  }
-
-  /* Is it really a MINIX filesystem ? */
-  if (magic != SUPER_MAGIC && magic != SUPER_V2) {
-	fprintf(stderr, "%s is not a valid MINIX filesystem\n", special_file);
-	return;
-  }
-
-  /* Fetch the inode of the root directory */
-  if (get_inode(special, (ino_t) ROOT_INODE, &root_inode) < 0) {
-	fprintf(stderr, "cannot get inode of root directory\n");
-	return;
-  }
-
-  /* Print number of blocks and inodes */
-  if (verbose) printf("boot\n%ld %d\n",
-	       (block_t) sb.s_nzones << zone_shift, sb.s_ninodes);
-
-  /* Extract (recursively) the root directory */
-  dump_dir(special, &root_inode, directory);
-}
-
-/* Different type of blocks:	(used in routine get_block for caching) */
-
-#define	B_INODE		0	/* Cache #0 is the inode cache */
-#define	B_INDIRECT	1	/* Cache #1 is the (dbl) indirect block cache */
-#define	B_DATA		2	/* No cache for data blocks (only read once) */
-
-int get_inode(fd, inum, ip)
-int fd;
-ino_t inum;
-d1_inode *ip;
-
-/* Get inode `inum' from the MINIX filesystem. (Uses the inode-cache) */
-{
-  struct buf bp;
-  block_t block;
-  block_t ino_block;
-  unsigned short ino_offset;
-
-  /* Calculate start of i-list */
-  block = 1 + 1 + sb.s_imap_blocks + sb.s_zmap_blocks;
-
-  /* Calculate block with inode inum */
-  ino_block = ((inum - 1) / inodes_per_block);
-  ino_offset = ((inum - 1) % inodes_per_block);
-  block += ino_block;
-
-  /* Fetch the block */
-  if (get_block(fd, block, &bp, B_INODE) == 0) {
-	memcpy((void *) ip, (void *) &bp.b_v1_ino[ino_offset], sizeof(d1_inode));
-	return(0);
-  }
-
-  /* Oeps, foutje .. */
-  fprintf(stderr, "cannot find inode %d\n", inum);
-  return(-1);
-}
-
-static int indent = 0;		/* current indent (used for mkfs-listing) */
-
-void dump_dir(special, ip, directory)
-int special;
-d1_inode *ip;
-char *directory;
-/* Make the given directory (if non-NULL),
- * and recursively extract its contents.
- */
-{
-  register struct direct *dp;
-  register int n_entries;
-  register char *name;
-  block_t b = 0;
-  d1_inode dip;
-  struct buf bp;
-
-  if (verbose) {
-	show_info(directory, ip, "");
-	indent++;
-  }
-  if (!noaction && *directory) {
-	/* Try to make the directory if not already there */
-	if (Mkdir(directory) != 0 || chdir(directory) < 0) {
-		fprintf(stderr, "Mkdir %s failed\n", directory);
-		return;
-	}
-  }
-  for (name = directory; *name; name++)	/* Find end of pathname */
-	;
-  *name++ = '/';		/* Add trailing slash */
-
-  n_entries = (int) (ip->d1_size / (off_t) sizeof(struct direct));
-  while (n_entries > 0) {
-
-	/* Read next block of the directory */
-	if (get_fileblock(special, ip, b, &bp) < 0) return;
-	dp = &bp.b_dir[0];
-	if (b++ == (block_t) 0) {
-		dp += 2;	/* Skip "." and ".." */
-		n_entries -= 2;
-	}
-
-	/* Extract the files/directories listed in the block */
-	while (n_entries-- > 0 && dp < &bp.b_dir[NR_DIR_ENTRIES(BLOCK_SIZE)]) {
-		if (dp->d_ino != (ino_t) 0) {
-			if (get_inode(special, dp->d_ino, &dip) < 0) {
-				/* Bad luck */
-				dp++;
-				continue;
-			}
-
-			/* Add new pathname-component to `pathname'. */
-			strncpy(name, dp->d_name, (size_t) NAME_MAX);
-			name[NAME_MAX] = '\0';
-
-			/* Call the right routine */
-			if ((dip.d1_mode & I_TYPE) == I_DIRECTORY)
-				dump_dir(special, &dip, name);
-			else
-				dump_file(special, &dip, name);
-		}
-		dp++;		/* Next entry, please. */
-	}
-  }
-  *--name = '\0';		/* Restore `pathname' to what it was. */
-  if (!noaction && *directory) {
-	chdir("..");		/* Go back up. */
-	restore(directory, ip);	/* Restore mode/owner/accesstime */
-  }
-  if (verbose) {
-	do_indent(--indent);	/* Let mkfs know we are done */
-	printf("$\n");		/* with this directory. */
-  }
-}
-
-int dump_file(special, ip, filename)
-int special;
-d1_inode *ip;
-char *filename;
-/* Extract given filename from the MINIX-filesystem,
- * and store it on the local filesystem.
- */
-{
-  int file;
-  block_t b = 0;
-  struct buf bp;
-  off_t size;
-
-  if (nofiles && (ip->d1_mode & I_TYPE) == I_REGULAR) return(0);
-
-  if (verbose) show_info(filename, ip, pathname);
-
-  if (noaction) return(0);
-
-  if (access(filename, 0) == 0) {
-	/* Should not happen, but just in case .. */
-	fprintf(stderr, "Will not create %s: file exists\n", filename);
-	return(-1);
-  }
-  if ((file = creat(filename, (ip->d1_mode & ALL_MODES))) < 0) {
-	fprintf(stderr, "cannot create %s\n", filename);
-	return(-1);
-  }
-
-  /* Don't try to extract /dev/hd0 */
-  if ((ip->d1_mode & I_TYPE) == I_REGULAR) {
-	size = ip->d1_size;
-	while (size > (off_t) 0) {
-		/* Get next block of file */
-		if (get_fileblock(special, ip, b++, &bp) < 0) {
-			close(file);
-			return(-1);
-		}
-
-		/* Write it to the file */
-		if (size > (off_t) BLOCK_SIZE)
-			write(file, bp.b_data, BLOCK_SIZE);
-		else
-			write(file, bp.b_data, (int) size);
-
-		size -= (off_t) BLOCK_SIZE;
-	}
-  }
-  close(file);
-  restore(filename, ip);	/* Restore mode/owner/filetimes */
-  return(0);
-}
-
-int get_fileblock(special, ip, b, bp)
-int special;
-d1_inode *ip;
-block_t b;
-struct buf *bp;
-/* Read the `b'-th block from the file whose inode is `ip'. */
-{
-  zone_t zone, ind_zone;
-  block_t z, zone_index;
-  int r;
-
-  /* Calculate zone in which the datablock number is contained */
-  zone = (zone_t) (b >> zone_shift);
-
-  /* Calculate index of the block number in the zone */
-  zone_index = b - ((block_t) zone << zone_shift);
-
-  /* Go get the zone */
-  if (zone < (zone_t) V1_NR_DZONES) {	/* direct block */
-	zone = ip->d1_zone[(int) zone];
-	z = ((block_t) zone << zone_shift) + zone_index;
-	r = get_block(special, z, bp, B_DATA);
-	return(r);
-  }
-
-  /* The zone is not a direct one */
-  zone -= (zone_t) V1_NR_DZONES;
-
-  /* Is it single indirect ? */
-  if (zone < (zone_t) V1_INDIRECTS) {	/* single indirect block */
-	ind_zone = ip->d1_zone[V1_NR_DZONES];
-  } else {			/* double indirect block */
-	/* Fetch the double indirect block */
-	ind_zone = ip->d1_zone[V1_NR_DZONES + 1];
-	z = (block_t) ind_zone << zone_shift;
-	r = get_block(special, z, bp, B_INDIRECT);
-	if (r < 0) return(r);
-
-	/* Extract the indirect zone number from it */
-	zone -= (zone_t) V1_INDIRECTS;
-
-	/* The next line assumes a V1 file system only! */
-	ind_zone = bp->b_v1_ind[(int) (zone / V1_INDIRECTS)];
-	zone %= (zone_t) V1_INDIRECTS;
-  }
-
-  /* Extract the datablock number from the indirect zone */
-  z = (block_t) ind_zone << zone_shift;
-  r = get_block(special, z, bp, B_INDIRECT);
-  if (r < 0) return(r);
-
-  /* The next line assumes a V1 file system only! */
-  zone = bp->b_v1_ind[(int) zone];
-
-  /* Calculate datablock number to be fetched */
-  z = ((block_t) zone << zone_shift) + zone_index;
-  r = get_block(special, z, bp, B_DATA);
-  return(r);
-}
-
-/* The following routines simulate a LRU block cache.
- *
- * Definition of a cache block:
- */
-
-struct cache_block {
-  block_t b_block;		/* block number of block */
-  long b_access;		/* counter value of last access */
-  char b_buf[BLOCK_SIZE];	/* buffer for block */
-};
-
-#define	NR_CACHES	2	/* total number of caches */
-#define	NR_CBLOCKS	5	/* number of blocks in a cache */
-
-static struct cache_block cache[NR_CACHES][NR_CBLOCKS];
-static long counter = 0L;	/* Counter used as a sense of time. */
- /* Incremented after each cache operation. */
-
-int get_block(fd, block, bp, type)
-int fd;
-block_t block;
-struct buf *bp;
-int type;
-/* Get the requested block from the device with filedescriptor fd.
- * If it is in the cache, no (floppy-) disk access is needed,
- * if not, allocate a cache block and read the block into it.
- */
-{
-  register int i;
-  register struct cache_block *cache_p, *cp;
-
-  if (block == (block_t) NO_ZONE) {
-	/* Should never happen in a good filesystem. */
-	fprintf(stderr, "get_block: NO_ZONE requested !\n");
-	return(-1);
-  }
-  if (type < 0 || type >= NR_CACHES)	/* No cache for this type */
-	return(get_rawblock(fd, block, (char *) bp));
-
-  cache_p = cache[type];
-  cp = (struct cache_block *) 0;
-
-  /* First find out if block requested is in the cache */
-  for (i = 0; i < NR_CBLOCKS; i++) {
-	if (cache_p[i].b_block == block) {	/* found right block */
-		cp = &cache_p[i];
-		break;
-	}
-  }
-
-  if (cp == (struct cache_block *) 0) {	/* block is not in cache */
-	cp = cache_p;		/* go find oldest buffer */
-	for (i = 0; i < NR_CBLOCKS; i++) {
-		if (cache_p[i].b_access < cp->b_access) cp = &cache_p[i];
-	}
-
-	/* Fill the buffer with the right block */
-	if (get_rawblock(fd, block, cp->b_buf) < 0) return(-1);
-  }
-
-  /* Update/store last access counter */
-  cp->b_access = ++counter;
-  cp->b_block = block;
-  memcpy((void *) bp, (void *) cp->b_buf, BLOCK_SIZE);
-  return(0);
-}
-
-int get_rawblock(special, blockno, bufp)
-int special;
-block_t blockno;
-char *bufp;
-/* Read a block from the disk. */
-{
-  off_t pos;
-
-  /* Calculate the position of the block on the disk */
-  pos = (off_t) blockno *(off_t) BLOCK_SIZE;
-
-  /* Read the block from the disk */
-  if (lseek(special, pos, SEEK_SET) == pos
-      && read(special, bufp, BLOCK_SIZE) == BLOCK_SIZE)
-	return(0);
-
-  /* Should never get here .. */
-  fprintf(stderr, "read block %d failed\n", blockno);
-  return(-1);
-}
-
-void restore(name, ip)
-char *name;
-d1_inode *ip;
-/* Restores given file's attributes.
- * `ip' contains the attributes of the file on the MINIX filesystem,
- * `name' is the filename of the extracted file on the local filesystem.
- */
-{
-  long ttime[2];
-
-  chown(name, ip->d1_uid, ip->d1_gid);	/* Fails if not superuser */
-  chmod(name, (ip->d1_mode & ALL_MODES));
-  ttime[0] = ttime[1] = ip->d1_mtime;
-  utime(name, (struct utimbuf *) ttime);
-}
-
-/* Characters to use as prefix to `mkfs' mode field */
-
-static char special_chars[] = {
-		       '-',	/* I_REGULAR */
-		       'c',	/* I_CHAR_SPECIAL */
-		       'd',	/* I_DIRECTORY */
-		       'b'	/* I_BLOCK_SPECIAL */
-};
-
-void show_info(name, ip, path)
-char *name;
-d1_inode *ip;
-char *path;
-/* Show information about the given file/dir in `mkfs'-format */
-{
-  char c1, c2, c3;
-
-  c1 = special_chars[(ip->d1_mode >> 13) & 03];
-  c2 = ((ip->d1_mode & ALL_MODES & ~RWX_MODES) == I_SET_UID_BIT) ? 'u' : '-';
-  c3 = ((ip->d1_mode & ALL_MODES & ~RWX_MODES) == I_SET_GID_BIT) ? 'g' : '-';
-
-  if (*name) {
-	do_indent(indent);
-	printf("%-14s ", name);
-  }
-  printf("%c%c%c%03o %d %d", c1, c2, c3,
-         (ip->d1_mode & RWX_MODES), ip->d1_uid, ip->d1_gid);
-
-  switch (ip->d1_mode & I_TYPE) {
-      case I_DIRECTORY:
-	break;
-      case I_CHAR_SPECIAL:	/* Print major and minor dev numbers */
-	printf(" %d %d", (ip->d1_zone[0] >> MAJOR) & 0377,
-	       (ip->d1_zone[0] >> MINOR) & 0377);
-	break;
-      case I_BLOCK_SPECIAL:	/* Print major and minor dev numbers */
-	printf(" %d %d", (ip->d1_zone[0] >> MAJOR) & 0377,
-	       (ip->d1_zone[0] >> MINOR) & 0377);
-	/* Also print the number of blocks on the device */
-	printf(" %ld", (ip->d1_size / (off_t) BLOCK_SIZE));
-	break;
-      default:			/* Just print the pathname */
-	printf(" %s", path);
-	break;
-  }
-  putchar('\n');
-}
-
-#define	INDENT_SIZE	4
-
-void do_indent(i)
-int i;
-{
-  i *= INDENT_SIZE;
-  while (i-- > 0) putchar(' ');
-}
-
-int Mkdir(directory)
-char *directory;
-/* Make a directory, return exit status.
- * This routine is not necessary on systems that
- * have a system call to make directories.
- */
-{
-  int pid, status;
-
-  if ((pid = fork()) == 0) {
-	execl("/bin/Mkdir", "Mkdir", directory, (char *) 0);
-	execl("/usr/bin/Mkdir", "Mkdir", directory, (char *) 0);
-	exit(1);
-  } else if (pid < 0)
-	return(-1);
-  while (wait(&status) != pid);
-  return(status);
-}
Index: trunk/minix/commands/simple/remsync.c
===================================================================
--- trunk/minix/commands/simple/remsync.c	(revision 9)
+++ 	(revision )
@@ -1,1551 +1,0 @@
-/*	remsync 1.5 - remotely synchronize file trees	Author: Kees J. Bot
- *								10 Jun 1994
- */
-#define nil 0
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <limits.h>
-#include <time.h>
-#include <utime.h>
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-#ifndef major
-#define major(dev)	((int) ((dev) >> 8))
-#define minor(dev)	((int) ((dev) & 0xFF))
-#endif
-
-#ifndef S_ISLNK
-/* There were no symlinks in medieval times. */
-#define S_ISLNK(mode)			(0)
-#define lstat				stat
-#define symlink(path1, path2)		(errno= ENOSYS, -1)
-#define readlink(path, buf, len)	(errno= ENOSYS, -1)
-#endif
-
-int sflag;		/* Make state file. */
-int dflag;		/* Make list of differences. */
-int uflag;		/* Only update files with newer versions. */
-int xflag;		/* Do not cross device boundaries. */
-int Dflag;		/* Debug: Readable differences, no file contents. */
-int vflag;		/* Verbose. */
-
-#define NO_DEVICE	(-1)
-dev_t xdev= NO_DEVICE;	/* The device that you should stay within. */
-
-int excode= 0;		/* Exit(excode); */
-
-#define BASE_INDENT	2	/* State file basic indent. */
-
-void report(const char *label)
-{
-	fprintf(stderr, "remsync: %s: %s\n", label, strerror(errno));
-	excode= 1;
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-void *allocate(void *mem, size_t size)
-{
-	if ((mem= mem == nil ? malloc(size) : realloc(mem, size)) == nil) {
-		fprintf(stderr, "remsync: Out of memory: %s\n",
-			strerror(errno));
-		exit(1);
-	}
-	return mem;
-}
-
-void deallocate(void *mem)
-{
-	if (mem != nil) free(mem);
-}
-
-/* One needs to slowly forget two sets of objects: for the code that reads
- * the state file, and for the code that traverses trees.
- */
-int keep;
-#define KEEP_STATE	0
-#define KEEP_TRAVERSE	1
-
-void forget(void *mem)
-/* Some objects must be deleted in time, but not just yet. */
-{
-	static void *death_row[2][50];
-	static void **dp[2]= { death_row[0], death_row[1] };
-
-	deallocate(*dp[keep]);
-	*dp[keep]++= mem;
-	if (dp[keep] == arraylimit(death_row[keep])) dp[keep]= death_row[keep];
-}
-
-char *copystr(const char *s)
-{
-	char *c= allocate(nil, (strlen(s) + 1) * sizeof(c[0]));
-	strcpy(c, s);
-	return c;
-}
-
-typedef struct pathname {
-	char		*path;	/* The actual pathname. */
-	size_t		idx;	/* Index for the terminating null byte. */
-	size_t		lim;	/* Actual length of the path array. */
-} pathname_t;
-
-void path_init(pathname_t *pp)
-/* Initialize a pathname to the null string. */
-{
-	pp->path= allocate(nil, (pp->lim= 16) * sizeof(pp->path[0]));
-	pp->path[pp->idx= 0]= 0;
-}
-
-void path_add(pathname_t *pp, const char *name)
-/* Add a component to a pathname. */
-{
-	size_t lim;
-	char *p;
-	int slash;
-
-	lim= pp->idx + strlen(name) + 2;
-
-	if (lim > pp->lim) {
-		pp->lim= lim + lim/2;	/* add an extra 50% growing space. */
-		pp->path= allocate(pp->path, pp->lim * sizeof(pp->path[0]));
-	}
-
-	p= pp->path + pp->idx;
-	slash= (pp->idx > 0);
-	if (pp->idx == 1 && p[-1] == '/') p--;
-
-	while (*name != 0) {
-		if (*name == '/') {
-			slash= 1;
-		} else {
-			if (slash) { *p++ = '/'; slash= 0; }
-			*p++= *name;
-		}
-		name++;
-	}
-	if (slash && p == pp->path) *p++= '/';
-	*p = 0;
-	pp->idx= p - pp->path;
-}
-
-void path_trunc(pathname_t *pp, size_t didx)
-/* Delete part of a pathname to a remembered length. */
-{
-	pp->path[pp->idx= didx]= 0;
-}
-
-#if kept_for_comments_only
-
-const char *path_name(const pathname_t *pp)
-/* Return the actual name as a char array. */
-{
-	return pp->path;
-}
-
-size_t path_length(const pathname_t *pp)
-/* The length of the pathname. */
-{
-	return pp->idx;
-}
-
-void path_drop(pathname_t *pp)
-/* Release the storage occupied by the pathname. */
-{
-	free(pp->path);
-}
-#endif
-
-#define path_name(pp)		((const char *) (pp)->path)
-#define path_length(pp)		((pp)->idx)
-#define path_drop(pp)		free((void *) (pp)->path)
-
-typedef struct namelist {	/* Obviously a list of names. */
-	struct namelist	*next;
-	char		*name;
-} namelist_t;
-
-char *rdlink(const char *link, off_t size)
-/* Look where "link" points. */
-{
-	static char *path= nil;
-	static size_t len= 0;
-	size_t n;
-
-	if (len <= size) {
-		path= allocate(path, (len= size * 2) * sizeof(path[0]));
-	}
-	if ((n= readlink(link, path, len)) == -1) return nil;
-	path[n]= 0;
-	return path;
-}
-
-void sort(namelist_t **anl)
-/* A stable mergesort disguised as line noise.  Must be called like this:
- *	if (L!=nil && L->next!=nil) sort(&L);
- */
-{
-	/* static */ namelist_t *nl1, **mid;  /* Need not be local */
-	namelist_t *nl2;
-
-	nl1= *(mid= &(*anl)->next);
-	do {
-		if ((nl1= nl1->next) == nil) break;
-		mid= &(*mid)->next;
-	} while ((nl1= nl1->next) != nil);
-
-	nl2= *mid;
-	*mid= nil;
-
-	if ((*anl)->next != nil) sort(anl);
-	if (nl2->next != nil) sort(&nl2);
-
-	nl1= *anl;
-	for (;;) {
-		if (strcmp(nl1->name, nl2->name)<=0) {
-			if ((nl1= *(anl= &nl1->next)) == nil) {
-				*anl= nl2;
-				break;
-			}
-		} else {
-			*anl= nl2;
-			nl2= *(anl= &nl2->next);
-			*anl= nl1;
-			if (nl2 == nil) break;
-		}
-	}
-}
-
-namelist_t *collect(const char *dir)
-/* Return a sorted list of directory entries.  Returns null with errno != 0
- * on error.
- */
-{
-	namelist_t *names, **pn= &names;
-	DIR *dp;
-	struct dirent *entry;
-
-	if ((dp= opendir(dir)) == nil) return nil;
-
-	while ((entry= readdir(dp)) != nil) {
-		if (entry->d_name[0] == '.'
-			&& (entry->d_name[1] == 0
-				|| (entry->d_name[1] == '.'
-					&& entry->d_name[2] == 0))) {
-			continue;
-		}
-		*pn= allocate(nil, sizeof(**pn));
-		(*pn)->name= copystr(entry->d_name);
-		pn= &(*pn)->next;
-	}
-	closedir(dp);
-	*pn= nil;
-	errno= 0;
-	if (names != nil && names->next != nil) sort(&names);
-	return names;
-}
-
-char *pop_name(namelist_t **names)
-/* Return one name of a name list. */
-{
-	char *name;
-	namelist_t *junk;
-
-	junk= *names;
-	*names= junk->next;
-	name= junk->name;
-	deallocate(junk);
-	forget(name);
-	return name;
-}
-
-typedef enum filetype {		/* The files we know about. */
-	F_DIR,
-	F_FILE,
-	F_BLK,
-	F_CHR,
-	F_PIPE,
-	F_LINK
-} filetype_t;
-
-typedef struct entry {		/* One file. */
-	int		depth;		/* Depth in directory tree. */
-	const char	*name;		/* Name of entry. */
-	const char	*path;		/* Path name. */
-	int		ignore;		/* Ignore this entry (errno number.) */
-	unsigned long	fake_ino;	/* Fake inode number for hard links. */
-	int		linked;		/* Is the file hard linked? */
-	int		lastlink;	/* Is it the last link? */
-	char		*link;		/* Where a (sym)link points to. */
-	filetype_t	type;
-	mode_t		mode;		/* Not unlike those in struct stat. */
-	uid_t		uid;
-	gid_t		gid;
-	off_t		size;
-	time_t		mtime;
-	dev_t		rdev;
-} entry_t;
-
-void linked(entry_t *entry, struct stat *stp)
-/* Return an "inode number" if a file could have links (link count > 1).
- * Also return a path to the first link if you see the file again.
- */
-{
-	static unsigned long new_fake_ino= 0;
-	static struct links {
-		struct links	*next;
-		char		*path;
-		ino_t		ino;
-		dev_t		dev;
-		nlink_t		nlink;
-		unsigned long	fake_ino;
-	} *links[1024];
-	struct links **plp, *lp;
-
-	entry->linked= entry->lastlink= 0;
-	entry->fake_ino= 0;
-	entry->link= nil;
-
-	if (S_ISDIR(stp->st_mode) || stp->st_nlink < 2) return;
-
-	plp= &links[stp->st_ino % arraysize(links)];
-	while ((lp= *plp) != nil && (lp->ino != stp->st_ino
-				|| lp->dev != stp->st_dev)) plp= &lp->next;
-
-	if (lp == nil) {
-		/* New file, store it with a new fake inode number. */
-		*plp= lp= allocate(nil, sizeof(*lp));
-		lp->next= nil;
-		lp->path= copystr(entry->path);
-		lp->ino= stp->st_ino;
-		lp->dev= stp->st_dev;
-		lp->nlink= stp->st_nlink;
-		lp->fake_ino= ++new_fake_ino;
-	} else {
-		entry->link= lp->path;
-		entry->linked= 1;
-	}
-	entry->fake_ino= lp->fake_ino;
-
-	if (--lp->nlink == 0) {
-		/* No need to remember this one, no more links coming. */
-		*plp= lp->next;
-		forget(lp->path);
-		deallocate(lp);
-		entry->lastlink= 1;
-	}
-}
-
-char *tree;		/* Tree to work on. */
-FILE *statefp;		/* State file. */
-char *state_file;
-FILE *difffp;		/* File of differences. */
-char *diff_file;
-
-entry_t *traverse(void)
-/* Get one name from the directory tree. */
-{
-	static int depth;
-	static pathname_t path;
-	static entry_t entry;
-	static namelist_t **entries;
-	static size_t *trunc;
-	static size_t deep;
-	static namelist_t *newentries;
-	struct stat st;
-
-recurse:
-	keep= KEEP_TRAVERSE;
-
-	if (deep == 0) {
-		/* Initialize for the root of the tree. */
-		path_init(&path);
-		path_add(&path, tree);
-		entries= allocate(nil, 1 * sizeof(entries[0]));
-		entries[0]= allocate(nil, sizeof(*entries[0]));
-		entries[0]->next= nil;
-		entries[0]->name= copystr("/");
-		trunc= allocate(nil, 1 * sizeof(trunc[0]));
-		trunc[0]= path_length(&path);
-		deep= 1;
-	} else
-	if (newentries != nil) {
-		/* Last entry was a directory, need to go down. */
-		if (entry.ignore) {
-			/* Ouch, it is to be ignored! */
-			while (newentries != nil) (void) pop_name(&newentries);
-			goto recurse;
-		}
-		if (++depth == deep) {
-			deep++;
-			entries= allocate(entries, deep * sizeof(entries[0]));
-			trunc= allocate(trunc, deep * sizeof(trunc[0]));
-		}
-		entries[depth]= newentries;
-		newentries= nil;
-		trunc[depth]= path_length(&path);
-	} else {
-		/* Pop up out of emptied directories. */
-		while (entries[depth] == nil) {
-			if (depth == 0) return nil;	/* Back at the root. */
-
-			/* Go up one level. */
-			depth--;
-		}
-	}
-	entry.name= pop_name(&entries[depth]);
-	path_trunc(&path, trunc[depth]);
-	path_add(&path, entry.name);
-	if (depth == 0) {
-		entry.path= "/";
-	} else {
-		entry.path= path_name(&path) + trunc[0];
-		if (entry.path[0] == '/') entry.path++;
-	}
-	entry.depth= depth;
-	entry.ignore= 0;
-
-	if (lstat(path_name(&path), &st) < 0) {
-		if (depth == 0 || errno != ENOENT) {
-			/* Something wrong with this entry, complain about
-			 * it and ignore it further.
-			 */
-			entry.ignore= errno;
-			report(path_name(&path));
-			return &entry;
-		} else {
-			/* Entry strangely nonexistent; simply continue. */
-			goto recurse;
-		}
-	}
-
-	/* Don't cross mountpoints if -x is set. */
-	if (xflag) {
-		if (xdev == NO_DEVICE) xdev= st.st_dev;
-		if (st.st_dev != xdev) {
-			/* Ignore the mountpoint. */
-			entry.ignore= EXDEV;
-			return &entry;
-		}
-	}
-
-	entry.mode= st.st_mode & 07777;
-	entry.uid= st.st_uid;
-	entry.gid= st.st_gid;
-	entry.size= st.st_size;
-	entry.mtime= st.st_mtime;
-	entry.rdev= st.st_rdev;
-
-	linked(&entry, &st);
-
-	if (S_ISDIR(st.st_mode)) {
-		/* A directory. */
-		entry.type= F_DIR;
-
-		/* Gather directory entries for the next traverse. */
-		if ((newentries= collect(path_name(&path))) == nil
-							&& errno != 0) {
-			entry.ignore= errno;
-			report(path_name(&path));
-		}
-	} else
-	if (S_ISREG(st.st_mode)) {
-		/* A plain file. */
-		entry.type= F_FILE;
-	} else
-	if (S_ISBLK(st.st_mode)) {
-		/* A block special file. */
-		entry.type= F_BLK;
-	} else
-	if (S_ISCHR(st.st_mode)) {
-		/* A character special file. */
-		entry.type= F_CHR;
-	} else
-	if (S_ISFIFO(st.st_mode)) {
-		/* A named pipe. */
-		entry.type= F_PIPE;
-	} else
-	if (S_ISLNK(st.st_mode)) {
-		/* A symbolic link. */
-		entry.type= F_LINK;
-		if ((entry.link= rdlink(path_name(&path), st.st_size)) == nil) {
-			entry.ignore= errno;
-			report(path_name(&path));
-		}
-	} else {
-		/* Unknown type of file. */
-		entry.ignore= EINVAL;
-	}
-	return &entry;
-}
-
-void checkstate(void)
-{
-	if (ferror(statefp)) fatal(state_file);
-}
-
-void indent(int depth)
-/* Provide indentation to show directory depth. */
-{
-	int n= BASE_INDENT * (depth - 1);
-
-	while (n >= 8) {
-		if (putc('\t', statefp) == EOF) checkstate();
-		n-= 8;
-	}
-	while (n > 0) {
-		if (putc(' ', statefp) == EOF) checkstate();
-		n--;
-	}
-}
-
-int print_name(FILE *fp, const char *name)
-/* Encode a name. */
-{
-	const char *p;
-	int c;
-
-	for (p= name; (c= (unsigned char) *p) != 0; p++) {
-		if (c <= ' ' || c == '\\') {
-			fprintf(fp, "\\%03o", c);
-			if (ferror(fp)) return 0;
-		} else {
-			if (putc(c, fp) == EOF) return 0;
-		}
-	}
-	return 1;
-}
-
-void mkstatefile(void)
-/* Make a state file out of the directory tree. */
-{
-	entry_t *entry;
-
-	while ((entry= traverse()) != nil) {
-		indent(entry->depth);
-		if (!print_name(statefp, entry->name)) checkstate();
-
-		if (entry->ignore) {
-			fprintf(statefp, "\tignore (%s)\n",
-				strerror(entry->ignore));
-			checkstate();
-			continue;
-		}
-
-		switch (entry->type) {
-		case F_DIR:
-			fprintf(statefp, "\td%03o %u %u",
-				(unsigned) entry->mode,
-				(unsigned) entry->uid, (unsigned) entry->gid);
-			break;
-		case F_FILE:
-			fprintf(statefp, "\t%03o %u %u %lu %lu",
-				(unsigned) entry->mode,
-				(unsigned) entry->uid, (unsigned) entry->gid,
-				(unsigned long) entry->size,
-				(unsigned long) entry->mtime);
-			break;
-		case F_BLK:
-		case F_CHR:
-			fprintf(statefp, "\t%c%03o %u %u %x",
-				entry->type == F_BLK ? 'b' : 'c',
-				(unsigned) entry->mode,
-				(unsigned) entry->uid, (unsigned) entry->gid,
-				(unsigned) entry->rdev);
-			break;
-		case F_PIPE:
-			fprintf(statefp, "\tp%03o %u %u",
-				(unsigned) entry->mode,
-				(unsigned) entry->uid, (unsigned) entry->gid);
-			break;
-		case F_LINK:
-			fprintf(statefp, "\t-> ");
-			checkstate();
-			(void) print_name(statefp, entry->link);
-			break;
-		}
-		checkstate();
-		if (entry->fake_ino != 0)
-			fprintf(statefp, " %lu", entry->fake_ino);
-		if (entry->lastlink)
-			fprintf(statefp, " last");
-		if (fputc('\n', statefp) == EOF) checkstate();
-	}
-	fflush(statefp);
-	checkstate();
-}
-
-char *read1line(FILE *fp)
-/* Read one line from a file.  Return null on EOF or error. */
-{
-	static char *line;
-	static size_t len;
-	size_t idx;
-	int c;
-
-	if (len == 0) line= allocate(nil, (len= 16) * sizeof(line[0]));
-
-	idx= 0;
-	while ((c= getc(fp)) != EOF && c != '\n') {
-		if (c < '\t') {
-			/* Control characters are not possible. */
-			fprintf(stderr,
-				"remsync: control character in data file!\n");
-			exit(1);
-		}
-		line[idx++]= c;
-		if (idx == len) {
-			line= allocate(line, (len*= 2) * sizeof(line[0]));
-		}
-	}
-	if (c == EOF) {
-		if (ferror(fp)) return nil;
-		if (idx == 0) return nil;
-	}
-	line[idx]= 0;
-	return line;
-}
-
-void getword(char **pline, char **parg, size_t *plen)
-/* Get one word from a line, interpret octal escapes. */
-{
-	char *line= *pline;
-	char *arg= *parg;
-	size_t len= *plen;
-	int i;
-	int c;
-	size_t idx;
-
-	idx= 0;
-	while ((c= *line) != 0 && c != ' ' && c != '\t') {
-		line++;
-		if (c == '\\') {
-			c= 0;
-			for (i= 0; i < 3; i++) {
-				if ((unsigned) (*line - '0') >= 010) break;
-				c= (c << 3) | (*line - '0');
-				line++;
-			}
-		}
-		arg[idx++]= c;
-		if (idx == len) arg= allocate(arg, (len*= 2) * sizeof(arg[0]));
-	}
-	arg[idx]= 0;
-	*pline= line;
-	*parg= arg;
-	*plen= len;
-}
-
-void splitline(char *line, char ***pargv, size_t *pargc)
-/* Split a line into an array of words. */
-{
-	static char **argv;
-	static size_t *lenv;
-	static size_t len;
-	size_t idx;
-
-	idx= 0;
-	for (;;) {
-		while (*line == ' ' || *line == '\t') line++;
-
-		if (*line == 0) break;
-
-		if (idx == len) {
-			len++;
-			argv= allocate(argv, len * sizeof(argv[0]));
-			lenv= allocate(lenv, len * sizeof(lenv[0]));
-			argv[idx]= allocate(nil, 16 * sizeof(argv[idx][0]));
-			lenv[idx]= 16;
-		}
-		getword(&line, &argv[idx], &lenv[idx]);
-		idx++;
-	}
-	*pargv= argv;
-	*pargc= idx;
-}
-
-int getattributes(entry_t *entry, int argc, char **argv)
-/* Convert state or difference file info into file attributes. */
-{
-	int i;
-	int attr;
-#define A_MODE1		0x01	/* Some of these attributes follow the name */
-#define A_MODE		0x02
-#define	A_OWNER		0x04
-#define A_SIZETIME	0x08
-#define A_DEV		0x10
-#define A_LINK		0x20
-
-	switch (argv[0][0]) {
-	case 'd':
-		/* Directory. */
-		entry->type= F_DIR;
-		attr= A_MODE1 | A_OWNER;
-		break;
-	case 'b':
-		/* Block device. */
-		entry->type= F_BLK;
-		attr= A_MODE1 | A_OWNER | A_DEV;
-		break;
-	case 'c':
-		/* Character device. */
-		entry->type= F_CHR;
-		attr= A_MODE1 | A_OWNER | A_DEV;
-		break;
-	case 'p':
-		/* Named pipe. */
-		entry->type= F_PIPE;
-		attr= A_MODE1 | A_OWNER;
-		break;
-	case '-':
-		/* Symlink. */
-		entry->type= F_LINK;
-		attr= A_LINK;
-		break;
-	default:
-		/* Normal file. */
-		entry->type= F_FILE;
-		attr= A_MODE | A_OWNER | A_SIZETIME;
-	}
-
-	if (attr & (A_MODE | A_MODE1)) {
-		entry->mode= strtoul(argv[0] + (attr & A_MODE1), nil, 010);
-	}
-	i= 1;
-	if (attr & A_OWNER) {
-		if (i + 2 > argc) return 0;
-		entry->uid= strtoul(argv[i++], nil, 10);
-		entry->gid= strtoul(argv[i++], nil, 10);
-	}
-	if (attr & A_SIZETIME) {
-		if (i + 2 > argc) return 0;
-		entry->size= strtoul(argv[i++], nil, 10);
-		entry->mtime= strtoul(argv[i++], nil, 10);
-	}
-	if (attr & A_DEV) {
-		if (i + 1 > argc) return 0;
-		entry->rdev= strtoul(argv[i++], nil, 0x10);
-	}
-	if (attr & A_LINK) {
-		if (i + 1 > argc) return 0;
-		entry->link= argv[i++];
-	}
-	entry->linked= entry->lastlink= 0;
-	if (i < argc) {
-		/* It has a fake inode number, so it is a hard link. */
-		static struct links {	/* List of hard links. */
-			struct links	*next;
-			unsigned long	fake_ino;
-			char		*path;
-		} *links[1024];
-		struct links **plp, *lp;
-		unsigned long fake_ino;
-
-		fake_ino= strtoul(argv[i++], nil, 10);
-
-		plp= &links[fake_ino % arraysize(links)];
-		while ((lp= *plp) != nil && lp->fake_ino != fake_ino)
-			plp= &lp->next;
-
-		if (lp == nil) {
-			/* New link. */
-			*plp= lp= allocate(nil, sizeof(*lp));
-			lp->next= nil;
-			lp->fake_ino= fake_ino;
-			lp->path= copystr(entry->path);
-		} else {
-			/* Linked to. */
-			entry->link= lp->path;
-			entry->linked= 1;
-		}
-
-		if (i < argc) {
-			if (strcmp(argv[i++], "last") != 0) return 0;
-
-			/* Last hard link of a file. */
-			forget(lp->path);
-			*plp= lp->next;
-			deallocate(lp);
-			entry->lastlink= 1;
-		}
-	}
-	if (i != argc) return 0;
-	return 1;
-}
-
-void state_syntax(off_t line)
-{
-	fprintf(stderr, "remsync: %s: syntax error on line %lu\n",
-		state_file, (unsigned long) line);
-	exit(1);
-}
-
-entry_t *readstate(void)
-/* Read one entry from the state file. */
-{
-	static entry_t entry;
-	static pathname_t path;
-	static size_t *trunc;
-	static size_t trunc_len;
-	static base_indent;
-	char *line;
-	char **argv;
-	size_t argc;
-	static off_t lineno;
-	int indent, depth;
-
-recurse:
-	keep= KEEP_STATE;
-
-	if (feof(statefp) || (line= read1line(statefp)) == nil) {
-		checkstate();
-		return nil;
-	}
-	lineno++;
-
-	/* How far is this entry indented? */
-	indent= 0;
-	while (*line != 0) {
-		if (*line == ' ') indent++;
-		else
-		if (*line == '\t') indent= (indent + 8) & ~7;
-		else
-			break;
-		line++;
-	}
-	if (indent > 0 && base_indent == 0) base_indent= indent;
-	depth= (base_indent == 0 ? 0 : indent / base_indent) + 1;
-
-	if (entry.ignore && depth > entry.depth) {
-		/* If the old directory is ignored, then so are its entries. */
-		goto recurse;
-	}
-	entry.depth= depth;
-
-	splitline(line, &argv, &argc);
-	if (argc < 2) state_syntax(lineno);
-
-	if (trunc == nil) {
-		/* The root of the tree, initialize path. */
-		if (argv[0][0] != '/') state_syntax(lineno);
-		path_init(&path);
-		path_add(&path, "/");
-		trunc= allocate(nil, (trunc_len= 16) * sizeof(trunc[0]));
-
-		/* The root has depth 0. */
-		entry.depth= 0;
-		trunc[0]= 0;
-	} else {
-		if (entry.depth > trunc_len) {
-			trunc= allocate(trunc,
-					(trunc_len*= 2) * sizeof(trunc[0]));
-		}
-		path_trunc(&path, trunc[entry.depth - 1]);
-		path_add(&path, argv[0]);
-		trunc[entry.depth]= path_length(&path);
-	}
-
-	entry.path= path_name(&path);
-	entry.name= argv[0];
-	entry.link= nil;
-	if ((entry.ignore= strcmp(argv[1], "ignore") == 0)) {
-		return &entry;
-	}
-	if (!getattributes(&entry, argc - 1, argv + 1)) state_syntax(lineno);
-	return &entry;
-}
-
-void checkdiff(void)
-{
-	if (ferror(difffp)) fatal(diff_file);
-}
-
-enum { DELETE, REPLACE, COPY, SIMILAR, EQUAL, ADD }
-compare(entry_t *remote, entry_t *local)
-/* Compare the local and remote entries and tell what need to be done. */
-{
-	int cmp;
-
-	/* Surplus entries? */
-	if (local == nil) return DELETE;
-	if (remote == nil) return ADD;
-
-	/* Extra directory entries? */
-	if (remote->depth > local->depth) return DELETE;
-	if (local->depth > remote->depth) return ADD;
-
-	/* Compare names. */
-	cmp= strcmp(remote->name, local->name);
-	if (cmp < 0) return DELETE;
-	if (cmp > 0) return ADD;
-
-	/* The files have the same name.  Ignore one, ignore the other. */
-	if (remote->ignore || local->ignore) {
-		remote->ignore= local->ignore= 1;
-		return EQUAL;
-	}
-
-	/* Reasons for replacement? */
-	if (remote->type != local->type) return REPLACE;
-
-	/* Should be hard linked to the same file. */
-	if (remote->linked || local->linked) {
-		if (!remote->linked || !local->linked) return REPLACE;
-		if (strcmp(remote->link, local->link) != 0) return REPLACE;
-	}
-
-	switch (remote->type) {
-	case F_FILE:
-		if (uflag) {
-			if (remote->mtime < local->mtime) return COPY;
-		} else {
-			if (remote->size != local->size
-					|| remote->mtime != local->mtime)
-				return COPY;
-		}
-		goto check_modes;
-	case F_BLK:
-	case F_CHR:
-		if (remote->rdev != local->rdev) return REPLACE;
-		goto check_modes;
-	case F_DIR:
-	case F_PIPE:
-	check_modes:
-		if (remote->mode != local->mode
-			|| remote->uid != local->uid
-			|| remote->gid != local->gid) return SIMILAR;
-		break;
-	case F_LINK:
-		if (strcmp(remote->link, local->link) != 0) return REPLACE;
-		break;
-	}
-	return EQUAL;
-}
-
-void delete(entry_t *old)
-/* Emit an instruction to remove an entry. */
-{
-	if (old->ignore) return;
-	if (uflag) return;
-
-	fprintf(difffp, "rm ");
-	checkdiff();
-	if (!print_name(difffp, old->path)) checkdiff();
-	if (putc('\n', difffp) == EOF) checkdiff();
-	if (vflag) fprintf(stderr, "rm %s\n", old->path);
-}
-
-void change_modes(entry_t *old, entry_t *new)
-/* Emit an instruction to change the attributes of an entry. */
-{
-	if (new->ignore) return;
-
-	fprintf(difffp, "chmod ");
-	checkdiff();
-	if (!print_name(difffp, new->path)) checkdiff();
-	fprintf(difffp, " %03o %u %u\n",
-		(unsigned) new->mode,
-		(unsigned) new->uid, (unsigned) new->gid);
-	checkdiff();
-	if (vflag && old->mode != new->mode) {
-		fprintf(stderr, "chmod %s %03o %u %u\n",
-			new->path,
-			(unsigned) new->mode,
-			(unsigned) new->uid, (unsigned) new->gid);
-	}
-}
-
-int cat(int f, off_t size)
-/* Include the contents of a file in the differences file. */
-{
-	ssize_t n;
-	unsigned char buf[1024 << sizeof(int)];
-	unsigned char *p;
-	int c;
-
-	if (Dflag) return 1;	/* Debug: Don't need the file contents. */
-
-	while ((n= read(f, buf, sizeof(buf))) > 0) {
-		p= buf;
-		do {
-			if (size == 0) {
-				/* File suddenly larger. */
-				errno= EINVAL;
-				return 0;
-			}
-			c= *p++;
-			if (putc(c, difffp) == EOF) checkdiff();
-			size--;
-		} while (--n != 0);
-	}
-	if (size > 0) {
-		int err= errno;
-
-		/* File somehow shrunk, pad it out. */
-		do {
-			if (putc(0, difffp) == EOF) checkdiff();
-		} while (--size != 0);
-		errno= n == 0 ? EINVAL : err;
-		n= -1;
-	}
-	return n == 0;
-}
-
-void add(entry_t *old, entry_t *new)
-/* Emit an instruction to add an entry. */
-{
-	pathname_t file;
-	int f;
-
-	if (new->ignore) return;
-
-	if (new->linked) {
-		/* This file is to be a hard link to an existing file. */
-		fprintf(difffp, "ln ");
-		checkdiff();
-		if (!print_name(difffp, new->link)) checkdiff();
-		if (fputc(' ', difffp) == EOF) checkdiff();
-		if (!print_name(difffp, new->path)) checkdiff();
-		if (fputc('\n', difffp) == EOF) checkdiff();
-		if (vflag) {
-			fprintf(stderr, "ln %s %s\n", new->link, new->path);
-		}
-		return;
-	}
-
-	/* Add some other type of file. */
-	fprintf(difffp, "add ");
-	checkdiff();
-	if (!print_name(difffp, new->path)) checkdiff();
-
-	switch (new->type) {
-	case F_DIR:
-		fprintf(difffp, " d%03o %u %u\n",
-			(unsigned) new->mode,
-			(unsigned) new->uid, (unsigned) new->gid);
-		if (vflag) fprintf(stderr, "mkdir %s\n", new->path);
-		break;
-	case F_FILE:
-		path_init(&file);
-		path_add(&file, tree);
-		path_add(&file, new->path);
-		if ((f= open(path_name(&file), O_RDONLY)) < 0) {
-			report(path_name(&file));
-			path_drop(&file);
-			fprintf(difffp, " ignore\n");
-			break;
-		}
-		fprintf(difffp, " %03o %u %u %lu %lu\n",
-			(unsigned) new->mode,
-			(unsigned) new->uid, (unsigned) new->gid,
-			(unsigned long) new->size,
-			(unsigned long) new->mtime);
-		checkdiff();
-		if (!cat(f, new->size)) {
-			int err= errno;
-			report(path_name(&file));
-			fprintf(difffp, "old ");
-			checkdiff();
-			print_name(difffp, err == EINVAL
-				? "File changed when copied" : strerror(err));
-			fputc('\n', difffp);
-			checkdiff();
-		} else {
-			if (vflag) {
-				fprintf(stderr, "%s %s\n",
-					old == nil ? "add" :
-						old->mtime > new->mtime ?
-							"restore" : "update",
-					new->path);
-			}
-		}
-		close(f);
-		path_drop(&file);
-		break;
-	case F_BLK:
-	case F_CHR:
-		fprintf(difffp, " %c%03o %u %u %lx\n",
-			new->type == F_BLK ? 'b' : 'c',
-			(unsigned) new->mode,
-			(unsigned) new->uid, (unsigned) new->gid,
-			(unsigned long) new->rdev);
-		if (vflag) fprintf(stderr, "mknod %s\n", new->path);
-		break;
-	case F_PIPE:
-		fprintf(difffp, " p%03o %u %u\n",
-			(unsigned) new->mode,
-			(unsigned) new->uid, (unsigned) new->gid);
-		if (vflag) fprintf(stderr, "mkfifo %s\n", new->path);
-		break;
-	case F_LINK:
-		fprintf(difffp, " -> ");
-		checkdiff();
-		(void) print_name(difffp, new->link);
-		checkdiff();
-		fputc('\n', difffp);
-		if (vflag) {
-			fprintf(stderr, "ln -s %s %s\n", new->link, new->path);
-		}
-		break;
-	}
-	checkdiff();
-}
-
-void mkdifferences(void)
-{
-	entry_t *remote;
-	entry_t *local;
-
-	remote= readstate();
-	local= traverse();
-
-	while (remote != nil || local != nil) {
-		switch (compare(remote, local)) {
-		case DELETE:
-			/* Remove the remote file. */
-			delete(remote);
-			remote->ignore= 1;
-			remote= readstate();
-			break;
-		case REPLACE:
-			/* Replace the remote file with the local one. */
-			if (remote->type == F_FILE && local->type == F_FILE
-							&& !local->linked) {
-				/* Don't overwrite, remove first. */
-				delete(remote);
-			}
-			/*FALL THROUGH*/
-		case COPY:
-			/* Overwrite the remote file with the local one. */
-			add(remote, local);
-			remote->ignore= 1;
-			goto skip2;
-		case SIMILAR:
-			/* About the same, but the attributes need changing. */
-			change_modes(remote, local);
-			goto skip2;
-		case EQUAL:
-		skip2:
-			/* Skip two files. */
-			remote= readstate();
-			local= traverse();
-			break;
-		case ADD:
-			/* Add the local file. */
-			add(nil, local);
-			local= traverse();
-			break;
-		}
-	}
-	fprintf(difffp, "end\n");
-	fflush(difffp);
-	checkdiff();
-}
-
-void apply_remove(pathname_t *pp)
-/* Remove an obsolete file. */
-{
-	struct stat st;
-
-	if (lstat(path_name(pp), &st) < 0) {
-		if (errno != ENOENT) report(path_name(pp));
-		return;
-	}
-
-	if (S_ISDIR(st.st_mode)) {
-		/* Recursively delete directories. */
-		size_t len;
-		namelist_t *entries;
-
-		if ((entries= collect(path_name(pp))) == nil && errno != 0) {
-			report(path_name(pp));
-			return;
-		}
-		len= path_length(pp);
-
-		while (entries != nil) {
-			path_add(pp, pop_name(&entries));
-			apply_remove(pp);
-			path_trunc(pp, len);
-		}
-		if (rmdir(path_name(pp)) < 0) {
-			report(path_name(pp));
-			return;
-		}
-		if (vflag) fprintf(stderr, "rmdir %s\n", path_name(pp));
-	} else {
-		/* Some other type of file. */
-		if (unlink(path_name(pp)) < 0) {
-			report(path_name(pp));
-			return;
-		}
-		if (vflag) fprintf(stderr, "rm %s\n", path_name(pp));
-	}
-}
-
-void apply_mkold(const char *file, const char *err)
-/* Make a file very old.  (An error occurred when it was added.) */
-{
-	struct utimbuf utb;
-
-	utb.actime= utb.modtime= 0;
-	if (utime(file, &utb) < 0) {
-		report(file);
-		return;
-	}
-	fprintf(stderr, "made %s look old", file);
-	fprintf(stderr, err == nil ? "\n" : " due to a remote problem: %s\n",
-								err);
-}
-
-void apply_chmod(const char *file, mode_t mode, uid_t uid, gid_t gid, int talk)
-/* Change mode and ownership. */
-{
-	struct stat st;
-
-	if (lstat(file, &st) < 0) {
-		report(file);
-		return;
-	}
-	if ((st.st_mode & 07777) != mode) {
-		if (chmod(file, mode) < 0) {
-			report(file);
-			return;
-		}
-		if (vflag && talk) {
-			fprintf(stderr, "chmod %03o %s\n",
-						(unsigned) mode, file);
-		}
-	}
-	if (st.st_uid != uid || st.st_gid != gid) {
-		if (chown(file, uid, gid) < 0) {
-			if (errno != EPERM) report(file);
-			return;
-		}
-		if (vflag && talk) {
-			fprintf(stderr, "chown %u:%u %s\n",
-				(unsigned) uid, (unsigned) gid, file);
-		}
-	}
-}
-
-void apply_add(pathname_t *pp, entry_t *entry)
-/* Add or replace a file. */
-{
-	const char *file;
-	off_t size;
-	int f;
-	unsigned char buf[1024 << sizeof(int)];
-	unsigned char *p;
-	int c;
-	int dirty;
-	struct stat st;
-	struct utimbuf utb;
-
-	if (entry->ignore) return;
-
-	if (lstat(path_name(pp), &st) >= 0 && (entry->type != F_FILE
-					|| !S_ISREG(st.st_mode))) {
-		apply_remove(pp);
-	}
-
-	file= path_name(pp);
-
-	switch (entry->type) {
-	case F_DIR:
-		if (mkdir(file, entry->mode) < 0) {
-			report(file);
-			return;
-		}
-		if (vflag) fprintf(stderr, "mkdir %s\n", file);
-		break;
-	case F_FILE:
-		size= entry->size;
-
-		f= -1;
-		st.st_mode= 0;
-		if (lstat(file, &st) < 0 || S_ISREG(st.st_mode)) {
-			f= open(file, O_WRONLY | O_CREAT | O_TRUNC,
-						entry->mode);
-			if (f < 0) {
-				(void) chmod(file, entry->mode | 0200);
-				f= open(file, O_WRONLY | O_CREAT | O_TRUNC,
-						entry->mode);
-			}
-			if (f < 0) {
-				(void) unlink(file);
-				f= open(file, O_WRONLY | O_CREAT | O_TRUNC,
-						entry->mode);
-			}
-			if (f < 0) report(file);
-		}
-		dirty= (f >= 0);
-		p= buf;
-		while (size > 0 && (c= getc(difffp)) != EOF) {
-			size--;
-			*p++= c;
-			if (p == arraylimit(buf) || size == 0) {
-				if (f >= 0 && write(f, buf, p - buf) < 0) {
-					report(file);
-					close(f);
-					f= -1;
-				}
-				p= buf;
-			}
-		}
-		if (size > 0) {
-			if (ferror(difffp)) report(diff_file);
-			if (feof(difffp)) {
-				fprintf(stderr, "remspec: %s: premature EOF\n",
-					diff_file);
-			}
-			if (dirty) apply_mkold(file, nil);
-			exit(1);
-		}
-		if (f < 0) {
-			if (dirty) apply_mkold(file, nil);
-			return;
-		}
-		close(f);
-		if (vflag) {
-			fprintf(stderr, st.st_mode == 0 ? "add %s\n"
-				: entry->mtime >= st.st_mtime
-					? "update %s\n" : "restore %s\n", file);
-		}
-		utb.actime= time(nil);
-		utb.modtime= entry->mtime;
-		if (utime(file, &utb) < 0) report(file);
-		break;
-	case F_BLK:
-		if (mknod(file, S_IFBLK | entry->mode, entry->rdev) < 0) {
-			report(file);
-			return;
-		}
-		if (vflag) {
-			fprintf(stderr, "mknod %s b %d %d\n", file,
-				major(entry->rdev), minor(entry->rdev));
-		}
-		break;
-	case F_CHR:
-		if (mknod(file, S_IFCHR | entry->mode, entry->rdev) < 0) {
-			report(file);
-			return;
-		}
-		if (vflag) {
-			fprintf(stderr, "mknod %s c %d %d\n", file,
-				major(entry->rdev), minor(entry->rdev));
-		}
-		break;
-	case F_PIPE:
-		if (mknod(file, S_IFIFO | entry->mode, 0) < 0) {
-			report(file);
-			return;
-		}
-		if (vflag) fprintf(stderr, "mknod %s p\n", file);
-		break;
-	case F_LINK:
-		if (symlink(entry->link, file) < 0) {
-			report(file);
-			return;
-		}
-		if (vflag) fprintf(stderr, "ln -s %s %s\n", entry->link, file);
-		return;
-	}
-	apply_chmod(file, entry->mode, entry->uid, entry->gid, 0);
-}
-
-void apply_link(const char *file, pathname_t *pp)
-/* Hard link *pp to file. */
-{
-	struct stat st1, st2;
-
-	if (lstat(file, &st1) < 0) {
-		report(file);
-		return;
-	}
-	if (lstat(path_name(pp), &st2) >= 0) {
-		if (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev)
-			return;
-		apply_remove(pp);
-		if (lstat(path_name(pp), &st2) >= 0) return;
-	}
-	if (link(file, path_name(pp)) < 0) {
-		fprintf(stderr, "remsync: ln %s %s: %s\n", file, path_name(pp),
-			strerror(errno));
-		excode= 1;
-		return;
-	}
-	if (vflag) fprintf(stderr, "ln %s %s\n", file, path_name(pp));
-}
-
-void diff_syntax(const char *line)
-{
-	fprintf(stderr, "remsync: %s: syntax error on this line: %s\n",
-		diff_file, line);
-	exit(1);
-}
-
-void apply_differences(void)
-/* Update a tree to a list of differences derived from a remote tree. */
-{
-	char *line;
-	char **argv;
-	size_t argc;
-	pathname_t path, link;
-	size_t trunc;
-
-	path_init(&path);
-	path_init(&link);
-	path_add(&path, tree);
-	path_add(&link, tree);
-	trunc= path_length(&path);
-
-	while (!feof(difffp) && (line= read1line(difffp)) != nil) {
-		splitline(line, &argv, &argc);
-		if (argc == 0) diff_syntax(line);
-
-		path_trunc(&path, trunc);
-
-		if (strcmp(argv[0], "add") == 0) {
-			entry_t entry;
-
-			if (argc < 3) diff_syntax(line);
-			path_add(&path, argv[1]);
-			entry.ignore= (strcmp(argv[2], "ignore") == 0);
-			if (!entry.ignore && !getattributes(&entry,
-							argc - 2, argv + 2))
-				diff_syntax(line);
-			apply_add(&path, &entry);
-		} else
-		if (strcmp(argv[0], "rm") == 0) {
-			if (argc != 2) diff_syntax(line);
-			path_add(&path, argv[1]);
-			apply_remove(&path);
-		} else
-		if (strcmp(argv[0], "ln") == 0) {
-			if (argc != 3) diff_syntax(line);
-			path_trunc(&link, trunc);
-			path_add(&link, argv[1]);
-			path_add(&path, argv[2]);
-			apply_link(path_name(&link), &path);
-		} else
-		if (strcmp(argv[0], "chmod") == 0) {
-			if (argc != 5) diff_syntax(line);
-			path_add(&path, argv[1]);
-			apply_chmod(path_name(&path),
-				strtoul(argv[2], nil, 010),
-				strtoul(argv[3], nil, 10),
-				strtoul(argv[4], nil, 10),
-				1);
-		} else
-		if (strcmp(argv[0], "old") == 0) {
-			if (argc != 3) diff_syntax(line);
-			path_add(&path, argv[1]);
-			apply_mkold(path_name(&path), argv[2]);
-		} else
-		if (strcmp(argv[0], "end") == 0) {
-			if (argc != 1) diff_syntax(line);
-			break;
-		} else {
-			diff_syntax(line);
-		}
-	}
-	checkdiff();
-}
-
-void usage(void)
-{
-    fprintf(stderr, "Usage: remsync -sxv tree [state-file]\n");
-    fprintf(stderr, "       remsync -duxvD tree [state-file [diff-file]]\n");
-    fprintf(stderr, "       remsync [-xv] tree [diff-file]\n");
-    exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	int i;
-
-	for (i= 1; i < argc && argv[i][0] == '-'; i++) {
-		char *p= argv[i] + 1;
-
-		if (p[0] == '-' && p[1] == 0) { i++; break; }
-
-		while (*p != 0) {
-			switch (*p++) {
-			case 's':	sflag= 1; break;
-			case 'd':	dflag= 1; break;
-			case 'u':	uflag= 1; break;
-			case 'x':	xflag= 1; break;
-			case 'D':	Dflag= 1; break;
-			case 'v':	vflag= 1; break;
-			default:	usage();
-			}
-		}
-	}
-	if (sflag && dflag) usage();
-	if (sflag && uflag) usage();
-	if (!sflag && !dflag && uflag) usage();
-	if (!dflag && Dflag) usage();
-
-	if (i == argc) usage();
-	tree= argv[i++];
-
-	if (sflag) {
-		/* Make a state file. */
-		state_file= i < argc ? argv[i++] : "-";
-		if (i != argc) usage();
-
-		statefp= stdout;
-		if (strcmp(state_file, "-") != 0) {
-			if ((statefp= fopen(state_file, "w")) == nil)
-				fatal(state_file);
-		}
-		mkstatefile();
-	} else
-	if (dflag) {
-		/* Make a file of differences. */
-		state_file= i < argc ? argv[i++] : "-";
-
-		diff_file= i < argc ? argv[i++] : "-";
-		if (i != argc) usage();
-
-		statefp= stdin;
-		if (strcmp(state_file, "-") != 0) {
-			if ((statefp= fopen(state_file, "r")) == nil)
-				fatal(state_file);
-		}
-
-		difffp= stdout;
-		if (strcmp(diff_file, "-") != 0) {
-			if ((difffp= fopen(diff_file, "w")) == nil)
-				fatal(diff_file);
-		}
-		mkdifferences();
-	} else {
-		/* Apply a file of differences. */
-		diff_file= i < argc ? argv[i++] : "-";
-		if (i != argc) usage();
-
-		difffp= stdin;
-		if (strcmp(diff_file, "-") != 0) {
-			if ((difffp= fopen(diff_file, "r")) == nil)
-				fatal(diff_file);
-		}
-		apply_differences();
-	}
-	exit(excode);
-}
Index: trunk/minix/commands/simple/rev.c
===================================================================
--- trunk/minix/commands/simple/rev.c	(revision 9)
+++ 	(revision )
@@ -1,108 +1,0 @@
-/*-
- * Copyright (c) 1987, 1992, 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. 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.
- */
-
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1987, 1992, 1993\n\
-	The Regents of the University of California.  All rights reserved.\n";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <locale.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-void usage(void);
-
-int
-main(int argc, char *argv[])
-{
-	const char *filename;
-	char p[2000], *t;
-	FILE *fp;
-	size_t len;
-	int ch, rval;
-
-	setlocale(LC_ALL, "");
-
-	while ((ch = getopt(argc, argv, "")) != -1)
-		switch(ch) {
-		case '?':
-		default:
-			usage();
-		}
-
-	argc -= optind;
-	argv += optind;
-
-	fp = stdin;
-	filename = "stdin";
-	rval = 0;
-	do {
-		if (*argv) {
-			if ((fp = fopen(*argv, "r")) == NULL) {
-				perror(*argv);
-				rval = 1;
-				++argv;
-				continue;
-			}
-			filename = *argv++;
-		}
-		while ((fgets(p, sizeof(p)-1, fp)) != NULL) {
-			len = strlen(p);
-			if (p[len - 1] == '\n')
-				--len;
-			t = p + len - 1;
-			for (t = p + len - 1; t >= p; --t)
-				putchar(*t);
-			putchar('\n');
-		}
-		if (ferror(fp)) {
-			perror(filename);
-			rval = 1;
-		}
-		(void)fclose(fp);
-	} while(*argv);
-	exit(rval);
-}
-
-void
-usage(void)
-{
-	(void)fprintf(stderr, "usage: rev [file ...]\n");
-	exit(1);
-}
Index: trunk/minix/commands/simple/rget.c
===================================================================
--- trunk/minix/commands/simple/rget.c	(revision 9)
+++ 	(revision )
@@ -1,290 +1,0 @@
-/*	rget 2.6 - remote pipe				Author: Kees J. Bot
- *								20 Mar 1989
- *
- * here$ ... | rput key			there$ rget -h here key | ...
- * here$ rput key command ...		there$ rget -h here key command ...
- *
- * (Once my first try at network programming, completely reworked by now.)
- */
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#if __minix
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/netdb.h>
-#include <net/gen/socket.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_hdr.h>
-#include <net/gen/tcp_io.h>
-#include <net/hton.h>
-#include <net/netlib.h>
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#endif
-
-static char *name;
-static int iflag, oflag, hflag, lflag, cflag;	/* -iolch? */
-static char *host;				/* Argument to -h. */
-static struct hostent *hent;			/* gethostbyname(host) */
-static char *key;				/* key (port) */
-static char **cmdv;				/* command [arg ...] */
-
-static void fatal(const char *label)
-{
-    int err= errno;
-
-    fprintf(stderr, "%s: %s: %s\n", name, label, strerror(err));
-    exit(1);
-}
-
-static unsigned name2port(char *n)
-{
-    char *end;
-    unsigned port;
-
-    port= strtoul(n, &end, 0);
-    if (end == n || *end != 0) {
-	port= 1;
-	while (*n != 0) port *= (*n++ & 0xFF);
-	port |= 0x8000;
-    }
-    return htons(port & 0xFFFF);
-}
-
-static void usage(void)
-{
-    fprintf(stderr,
-	"Usage: %s [-lcio] [-h host] key [command [arg ...]]\n"
-	"\t-l: Open TCP socket and listen (default for rput)\n"
-	"\t-c: Connect to a remote TCP socket (default for rget)\n"
-	"\t-i: Tie standard input to the TCP stream (default for rget)\n"
-	"\t-o: Tie standard output to the TCP stream (default for rput)\n"
-	"\t-io: Bidirectional!\n"
-	"\tkey: A word to hash into a port number, or simply a port number\n",
-	name);
-    exit(1);
-}
-
-int main(int argc, char **argv)
-{
-    int i, s;
-
-    if ((name= strrchr(argv[0], '/')) == nil) name= argv[0]; else name++;
-
-    if (strcmp(name, "rget") != 0 && strcmp(name, "rput") != 0) {
-	fprintf(stderr, "Don't know what to do if you call me '%s'\n", name);
-	exit(1);
-    }
-
-    i= 1;
-    while (i < argc && argv[i][0] == '-') {
-	char *opt= argv[i++]+1;
-
-	if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-	while (*opt != 0) switch (*opt++) {
-	case 'l':	lflag= 1;	break;
-	case 'c':	cflag= 1;	break;
-	case 'i':	iflag= 1;	break;
-	case 'o':	oflag= 1;	break;
-	case 'h':
-	    hflag= 1;
-	    if (*opt == 0) {
-		if (i == argc) usage();
-		opt= argv[i++];
-	    }
-	    host= opt;
-	    opt= "";
-	    break;
-	default:	usage();	break;
-	}
-    }
-
-    if (i == argc) usage();
-    key= argv[i++];
-    cmdv= argv + i;
-
-    /* Defaults. */
-    if (!lflag && !cflag) {
-	if (name[1] == 'p') lflag= 1;
-	if (name[1] == 'g') cflag= 1;
-    }
-    if (!iflag && !oflag) {
-	if (name[1] == 'g') iflag= 1;
-	if (name[1] == 'p') oflag= 1;
-    }
-
-    /* Constraints. */
-    if (lflag && cflag) {
-	fprintf(stderr, "%s: -c and -l don't mix\n", name);
-	usage();
-    }
-    if (cflag && !hflag) {
-	fprintf(stderr, "%s: -c requires a host name given with -h\n", name);
-	usage();
-    }
-    if (lflag && hflag) {
-	fprintf(stderr, "%s: -l does not require a host name given with -h\n",
-	    name);
-	usage();
-    }
-    if (iflag && oflag && cmdv[0] == nil) {
-	fprintf(stderr, "%s: -io requires that a command is given\n", name);
-	usage();
-    }
-
-    if (hflag) {
-	if ((hent= gethostbyname(host)) == nil) {
-	    fprintf(stderr, "%s: %s: Name lookup failed\n", name, host);
-	    exit(1);
-	}
-    }
-
-    s= -1;
-    if (lflag) {
-	/* We need to listen and wait.  (We're "rput", most likely.) */
-#if __minix
-	char *tcp_device;
-	struct nwio_tcpconf tcpconf;
-	struct nwio_tcpcl tcplistenopt;
-
-	if ((tcp_device= getenv("TCP_DEVICE")) == nil) tcp_device= "/dev/tcp";
-	if ((s= open(tcp_device, O_RDWR)) < 0) fatal(tcp_device);
-
-	tcpconf.nwtc_flags=
-	    NWTC_EXCL | NWTC_LP_SET | NWTC_UNSET_RA | NWTC_UNSET_RP;
-	tcpconf.nwtc_locport= name2port(key);
-	if (ioctl(s, NWIOSTCPCONF, &tcpconf) < 0) fatal("NWIOSTCPCONF");
-
-	tcplistenopt.nwtcl_flags= 0;
-	if (ioctl(s, NWIOTCPLISTEN, &tcplistenopt) < 0) fatal("NWIOTCPLISTEN");
-#else
-	int sa;
-	struct sockaddr_in channel;
-	static int on= 1;
-
-	if ((s= socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))<0) fatal("socket()");
-
-	(void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
-								sizeof(on));
-	memset(&channel, 0, sizeof(channel));
-	channel.sin_family= AF_INET;
-	channel.sin_addr.s_addr= htonl(INADDR_ANY);
-	channel.sin_port= name2port(key);
-	if (bind(s, (struct sockaddr *) &channel, sizeof(channel)) < 0)
-	    fatal("bind()");
-
-	if (listen(s, 0) < 0) fatal("listen()");
-
-	if ((sa= accept(s, nil, nil)) < 0) fatal("accept()");
-	close(s);
-	s= sa;
-#endif
-    }
-
-    if (cflag) {
-	/* Connect to the remote end.  (We're "rget", most likely.) */
-#if __minix
-	int n;
-	char *tcp_device;
-	nwio_tcpconf_t tcpconf;
-	nwio_tcpcl_t tcpconnopt;
-
-	if ((tcp_device= getenv("TCP_DEVICE")) == nil) tcp_device= "/dev/tcp";
-
-	n=60;
-	for (;;) {
-	    if ((s= open(tcp_device, O_RDWR)) < 0) fatal(tcp_device);
-
-	    tcpconf.nwtc_flags= NWTC_LP_SEL | NWTC_SET_RA | NWTC_SET_RP;
-	    memcpy(&tcpconf.nwtc_remaddr, hent->h_addr,
-		sizeof(tcpconf.nwtc_remaddr));
-	    tcpconf.nwtc_remport= name2port(key);
-	    if (ioctl(s, NWIOSTCPCONF, &tcpconf) < 0) fatal("NWIOSTCPCONF");
-
-	    tcpconnopt.nwtcl_flags= 0;
-	    if (ioctl(s, NWIOTCPCONN, &tcpconnopt) == 0) break;
-
-	    if (--n > 0) sleep(2); else fatal("NWIOTCPCONN");
-	    close(s);
-	}
-#else
-	int n;
-	struct sockaddr_in channel;
-
-	n=60;
-	for (;;) {
-	    if ((s= socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
-		fatal("socket()");
-
-	    memset(&channel, 0, sizeof(channel));
-	    channel.sin_family= AF_INET;
-	    memcpy(&channel.sin_addr.s_addr, hent->h_addr,
-		sizeof(channel.sin_addr.s_addr));
-	    channel.sin_port= name2port(key);
-	    if (connect(s, (struct sockaddr *) &channel,
-			    sizeof(channel)) >= 0) break;
-
-	    if (--n > 0) sleep(2); else fatal("connect()");
-	    close(s);
-	}
-#endif
-    }
-
-    if (cmdv[0] != nil) {
-	/* A command is given, so execute it with standard input (rget),
-	 * standard output (rput) or both (-io) tied to the TCP stream.
-	 */
-	if (iflag) dup2(s, 0);
-	if (oflag) dup2(s, 1);
-	close(s);
-
-	execvp(cmdv[0], cmdv);
-	fatal(cmdv[0]);
-    } else {
-	/* Without a command we have to copy bytes ourselves, probably to or
-	 * from a command that is connected to us with a pipe.  (The original
-	 * function of rput/rget, a remote pipe.)
-	 */
-	int fi, fo;
-	int n;
-	char buf[8192];
-
-	if (iflag) {
-	    fi= s;
-	    fo= 1;
-	} else {
-	    fi= 0;
-	    fo= s;
-	}
-
-	while ((n= read(fi, buf, sizeof(buf))) > 0) {
-	    char *bp= buf;
-
-	    while (n > 0) {
-		int r;
-
-		if ((r= write(fo, bp, n)) <= 0) {
-		    if (r == 0) {
-			fprintf(stderr, "%s: write(): Unexpected EOF\n", name);
-			exit(1);
-		    }
-		    fatal("write()");
-		}
-		bp+= r;
-		n-= r;
-	    }
-	}
-	if (n < 0) fatal("read()");
-    }
-    return 0;
-}
Index: trunk/minix/commands/simple/rlogin.c
===================================================================
--- trunk/minix/commands/simple/rlogin.c	(revision 9)
+++ 	(revision )
@@ -1,1775 +1,0 @@
-/*
- * Copyright (c) 1983, 1990 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. 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1983, 1990 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-#ifdef ID
-static char sccsid[] = "@(#)rlogin.c	5.33 (Berkeley) 3/1/91";
-#endif
-#endif /* not lint */
-
-/*
- * $Source: /cvsup/minix/src/commands/simple/rlogin.c,v $
- * $Header: mit/rlogin/RCS/rlogin.c,v 5.2 89/07/26 12:11:21 kfall
- *	Exp Locker: kfall $
- */
-
-/*
- * rlogin - remote login
- */
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/netdb.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-
-#include <termios.h>
-#include <setjmp.h>
-#include <errno.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <assert.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdlib.h>
-
-#ifdef KERBEROS
-#include <kerberosIV/des.h>
-#include <kerberosIV/krb.h>
-
-CREDENTIALS cred;
-Key_schedule schedule;
-int use_kerberos = 1, doencrypt;
-char dst_realm_buf[REALM_SZ], *dest_realm = NULL;
-extern char *krb_realmofhost();
-#endif
-
-#ifndef TIOCPKT_WINDOW
-#define	TIOCPKT_WINDOW	0x80
-#endif
-
-/* concession to Sun */
-#ifndef SIGUSR1
-#define	SIGUSR1	30
-#endif
-
-extern int errno;
-int eight, litout, rem;
-
-int noescape;
-u_char escapechar = '~';
-
-struct speed
-{
-	speed_t speed;
-	char *name;
-} speeds[] = {
-	{ B0, "0" }, { B50, "50" }, { B75, "75" }, { B110, "110" }, 
-	{ B134, "134" }, { B150, "150" }, { B200, "200" }, { B300, "300" }, 
-	{ B600, "600" }, { B1200, "1200" }, { B1800, "1800" }, 
-	{ B2400, "2400" }, { B4800, "4800" }, { B9600, "9600" }, 
-	{ B19200, "19200" }, { B38400, "38400" }, { B57600, "57600" },
-	{ B115200, "115200" },
-	{ -1, NULL },
-};
-
-#if __minix_vmd
-/* flow control variables */
-int more2read_0;
-int inprogress_0;
-int more2write_1;
-int inprogress_1;
-int more2read_rem;
-int inprogress_rd_rem;
-int more2write_rem;
-int inprogress_wr_rem;
-
-/* write to remote */
-size_t wr_rem_size;
-size_t wr_rem_offset;
-size_t extra_wr_rem_size;
-size_t extra_wr_rem_offset;
-char *extra_wr_rem;
-size_t extra_wr_rem_new_size;
-char *extra_wr_rem_new;
-
-#endif /* __minix_vmd */
-
-struct	winsize winsize;
-
-#define	get_window_size(fd, wp)	ioctl(fd, TIOCGWINSZ, wp)
-
-extern int main _ARGS(( int argc, char **argv ));
-static void usage _ARGS(( void ));
-static u_char getescape _ARGS(( char *p ));
-static char *speeds2str _ARGS(( speed_t speed ));
-static void lostpeer _ARGS(( int sig ));
-static void doit _ARGS(( void ));
-static void setsignal _ARGS(( int sig, void (*act)(int sig) ));
-static void msg _ARGS(( char *str ));
-static void done _ARGS(( int status ));
-#if !__minix_vmd
-static int reader _ARGS(( void ));
-#endif
-static void mode _ARGS(( int f ));
-#if __minix_vmd
-static void mark_async _ARGS(( int fd ));
-static void init_0 _ARGS(( void ));
-static void init_1 _ARGS(( void ));
-static void init_rd_rem _ARGS(( void ));
-static void init_wr_rem _ARGS(( void ));
-static void restart_0 _ARGS(( void ));
-static void restart_1 _ARGS(( void ));
-static void restart_rd_rem _ARGS(( void ));
-static void restart_wr_rem _ARGS(( void ));
-static void completed_0 _ARGS(( int result, int error ));
-static void completed_1 _ARGS(( int result, int error ));
-static void completed_rd_rem _ARGS(( int result, int error ));
-static void completed_wr_rem _ARGS(( int result, int error ));
-static void do_urg _ARGS(( int urg_byte ));
-#endif
-#if !__minix_vmd
-static void catch_child _ARGS(( int sig ));
-static void writer _ARGS(( void ));
-#endif
-static void echo _ARGS(( int c ));
-#if __minix_vmd
-static void finish _ARGS(( void ));
-static void sendwindow _ARGS(( void ));
-static void sigwinch _ARGS(( int sig ));
-static void subshell _ARGS(( void ));
-#endif
-
-int main(argc, argv)
-	int argc;
-	char **argv;
-{
-	extern char *optarg;
-	extern int optind;
-	struct passwd *pw;
-	struct servent *sp;
-	struct termios ttyb;
-	nwio_tcpopt_t tcpopt;
-	int error;
-	int argoff, ch, dflag, one, uid;
-	char *host, *p, *user, term[1024];
-
-	argoff = dflag = 0;
-	one = 1;
-	host = user = NULL;
-
-	if (p = rindex(argv[0], '/'))
-		++p;
-	else
-		p = argv[0];
-
-	if (strcmp(p, "rlogin"))
-		host = p;
-
-	/* handle "rlogin host flags" */
-	if (!host && argc > 2 && argv[1][0] != '-') {
-		host = argv[1];
-		argoff = 1;
-	}
-
-#ifdef KERBEROS
-#define	OPTIONS	"8EKLde:k:l:x"
-#else
-#define	OPTIONS	"8EKLde:l:"
-#endif
-	while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != EOF)
-		switch(ch) {
-		case '8':
-			eight = 1;
-			break;
-		case 'E':
-			noescape = 1;
-			break;
-		case 'K':
-#ifdef KERBEROS
-			use_kerberos = 0;
-#endif
-			break;
-		case 'L':
-			litout = 1;
-			break;
-		case 'd':
-			dflag = 1;
-			break;
-		case 'e':
-			escapechar = getescape(optarg);
-			break;
-#ifdef KERBEROS
-		case 'k':
-			dest_realm = dst_realm_buf;
-			(void)strncpy(dest_realm, optarg, REALM_SZ);
-			break;
-#endif
-		case 'l':
-			user = optarg;
-			break;
-#ifdef CRYPT
-#ifdef KERBEROS
-		case 'x':
-			doencrypt = 1;
-			des_set_key(cred.session, schedule);
-			break;
-#endif
-#endif
-		case '?':
-		default:
-			usage();
-		}
-	optind += argoff;
-	argc -= optind;
-	argv += optind;
-
-	/* if haven't gotten a host yet, do so */
-	if (!host && !(host = *argv++))
-		usage();
-
-	if (*argv)
-		usage();
-
-	if (!(pw = getpwuid(uid = getuid()))) {
-		(void)fprintf(stderr, "rlogin: unknown user id.\n");
-		exit(1);
-	}
-	if (!user)
-		user = pw->pw_name;
-
-	sp = NULL;
-#ifdef KERBEROS
-	if (use_kerberos) {
-		sp = getservbyname((doencrypt ? "eklogin" : "klogin"), "tcp");
-		if (sp == NULL) {
-			use_kerberos = 0;
-			warning("can't get entry for %s/tcp service",
-			    doencrypt ? "eklogin" : "klogin");
-		}
-	}
-#endif
-	if (sp == NULL)
-		sp = getservbyname("login", "tcp");
-	if (sp == NULL) {
-		(void)fprintf(stderr, "rlogin: login/tcp: unknown service.\n");
-		exit(1);
-	}
-
-	(void)strncpy(term, (p = getenv("TERM")) ? p : "network", sizeof(term));
-	term[sizeof(term)-1]= 0;
-
-	if (tcgetattr(0, &ttyb) == 0) {
-		(void)strcat(term, "/");
-		(void)strcat(term, speeds2str(cfgetospeed(&ttyb)));
-	}
-
-	(void)get_window_size(0, &winsize);
-
-	(void)signal(SIGPIPE, lostpeer);
-
-#ifdef KERBEROS
-try_connect:
-	if (use_kerberos) {
-		rem = KSUCCESS;
-		errno = 0;
-		if (dest_realm == NULL)
-			dest_realm = krb_realmofhost(host);
-
-#ifdef CRYPT
-		if (doencrypt)
-			rem = krcmd_mutual(&host, sp->s_port, user, term, 0,
-			    dest_realm, &cred, schedule);
-		else
-#endif /* CRYPT */
-			rem = krcmd(&host, sp->s_port, user, term, 0,
-			    dest_realm);
-		if (rem < 0) {
-			use_kerberos = 0;
-			sp = getservbyname("login", "tcp");
-			if (sp == NULL) {
-				(void)fprintf(stderr,
-				    "rlogin: unknown service login/tcp.\n");
-				exit(1);
-			}
-			if (errno == ECONNREFUSED)
-				warning("remote host doesn't support Kerberos");
-			if (errno == ENOENT)
-				warning("can't provide Kerberos auth data");
-			goto try_connect;
-		}
-	} else {
-#ifdef CRYPT
-		if (doencrypt) {
-			(void)fprintf(stderr,
-			    "rlogin: the -x flag requires Kerberos authentication.\n");
-			exit(1);
-		}
-#endif /* CRYPT */
-		rem = rcmd(&host, sp->s_port, pw->pw_name, user, term, 0);
-	}
-#else
-	rem = rcmd(&host, sp->s_port, pw->pw_name, user, term, 0);
-#endif /* KERBEROS */
-
-	if (rem < 0)
-		exit(1);
-
-	/* Enable BSD compatibility for urgent data. */
-	tcpopt.nwto_flags= NWTO_BSD_URG;
-	error= ioctl(rem, NWIOSTCPOPT, &tcpopt);
-	if (error == -1)
-	{
-		fprintf(stderr, "rlogin: NWIOSTCPOPT failed: %s\n",
-			strerror(errno));
-	}
-
-	(void)setuid(uid);
-	doit();
-	/*NOTREACHED*/
-}
-
-struct termios defattr, rawattr;
-#if __minix_vmd
-int mustsendwindow;
-#else
-int child;
-#endif
-
-static void
-doit()
-{
-	struct termios sb;
-#if !__minix_vmd
-	int r;
-#else
-	asio_fd_set_t fd_set;
-	struct fwait fw;
-	int result;
-#endif
-
-	(void)tcgetattr(0, &sb);
-	defattr = sb;
-	rawattr = sb;
-
-	rawattr.c_iflag &= ~(ICRNL | IGNCR | INLCR | ISTRIP | IXOFF | IXON | 
-							PARMRK | IXANY);
-	rawattr.c_oflag &= ~(OPOST);
-	rawattr.c_lflag &= ~(ECHONL | ECHO | ICANON | IEXTEN | ISIG);
-
-	(void)signal(SIGINT, SIG_IGN);
-	setsignal(SIGHUP, exit);
-	setsignal(SIGQUIT, exit);
-
-#if !__minix_vmd
-	child = fork();
-	if (child == -1) {
-		(void)fprintf(stderr, "rlogin: fork: %s.\n", strerror(errno));
-		done(1);
-	}
-	if (child == 0) {
-		mode(1);
-		r = reader();
-		if (r == 0) {
-			msg("connection closed.");
-			exit(0);
-		}
-		sleep(1);
-		msg("\007connection closed.");
-		exit(1);
-	}
-
-	(void)signal(SIGCHLD, catch_child);
-	writer();
-
-#else /* __minix_vmd */
-
-	mode(1);
-	/* mark the file descriptors 0, 1, and rem as asynchronous. */
-	mark_async(0);
-	mark_async(1);
-	mark_async(rem);
-	init_0();
-	init_1();
-	init_rd_rem();
-	init_wr_rem();
-
-	for (;;)
-	{
-		ASIO_FD_ZERO(&fd_set);
-		fw.fw_flags= 0;
-		fw.fw_bits= fd_set.afds_bits;
-		fw.fw_maxfd= ASIO_FD_SETSIZE;
-
-		if (more2read_0 && !inprogress_0)
-		{
-			restart_0();
-			fw.fw_flags |= FWF_NONBLOCK;
-		}
-
-		if (more2write_1 && !inprogress_1)
-		{
-			restart_1();
-			fw.fw_flags |= FWF_NONBLOCK;
-		}
-
-		if (more2read_rem && !inprogress_rd_rem)
-		{
-			restart_rd_rem();
-			fw.fw_flags |= FWF_NONBLOCK;
-		}
-
-		if (more2write_rem && !inprogress_wr_rem)
-		{
-			restart_wr_rem();
-			fw.fw_flags |= FWF_NONBLOCK;
-		}
-
-		if (more2read_0 && inprogress_0)
-			ASIO_FD_SET(0, ASIO_READ, &fd_set);
-		if (more2write_1 && inprogress_1)
-			ASIO_FD_SET(1, ASIO_WRITE, &fd_set);
-		if (more2read_rem && inprogress_rd_rem)
-			ASIO_FD_SET(rem, ASIO_READ, &fd_set);
-		if (more2write_rem && inprogress_wr_rem)
-			ASIO_FD_SET(rem, ASIO_WRITE, &fd_set);
-
-		for (;;)
-		{
-			result= fwait(&fw);
-			if (result == -1 && (errno == EAGAIN || 
-							errno == EINTR))
-			{
-				break;
-			}
-			if (result == -1)
-			{
-				fprintf(stderr, "fwait failed (%s)\n", 
-							strerror(errno));
-				exit(1);
-			}
-			assert(result == 0);
-#if 0
-printf("fwait: fw_fw= %d, fw_operation= %d, fw_result= %d, fw.fw_errno= %d\n",
-	fw.fw_fd, fw.fw_operation, fw.fw_result, fw.fw_errno);
-#endif
-			if (fw.fw_fd == 0 && fw.fw_operation == ASIO_READ)
-			{
-				completed_0(fw.fw_result, fw.fw_errno);
-			}
-			else if (fw.fw_fd == 1 && 
-					fw.fw_operation == ASIO_WRITE)
-			{
-				completed_1(fw.fw_result, fw.fw_errno);
-			}
-			else if (fw.fw_fd == rem && 
-					fw.fw_operation == ASIO_READ)
-			{
-				completed_rd_rem(fw.fw_result, fw.fw_errno);
-			}
-			else if (fw.fw_fd == rem && 
-					fw.fw_operation == ASIO_WRITE)
-			{
-				completed_wr_rem(fw.fw_result, fw.fw_errno);
-			}
-			else
-			{
-				fprintf(stderr,
-			"strange result from fwait: fd= %d, operation= %d\n",
-					fw.fw_fd, fw.fw_operation);
-				exit(1);
-			}
-			if (!(fw.fw_flags & FWF_MORE))
-				break;
-		}
-		if (mustsendwindow)
-		{
-			mustsendwindow= 0;
-			sendwindow();
-		}
-	}
-#endif /* __minix_vmd */
-	msg("connection closed.");
-	done(0);
-}
-
-/* trap a signal, unless it is being ignored. */
-static void
-setsignal(sig, act)
-	int sig;
-	void (*act) _ARGS(( int sig ));
-{
-	if (signal(sig, act) == SIG_IGN)
-		(void)signal(sig, SIG_IGN);
-}
-
-static void
-done(status)
-	int status;
-{
-	int w, wstatus;
-
-	mode(0);
-#if !__minix_vmd
-	if (child > 0) {
-		/* make sure catch_child does not snap it up */
-		(void)signal(SIGCHLD, SIG_DFL);
-		if (kill(child, SIGKILL) >= 0)
-			while ((w = wait(&wstatus)) > 0 && w != child);
-	}
-#endif
-	exit(status);
-}
-
-int dosigwinch;
-#if !__minix
-void sigwinch();
-#endif
-
-#if !__minix_vmd
-static void
-catch_child(sig)
-	int sig;
-{
-	int status;
-	int pid;
-
-	for (;;) {
-		pid = waitpid(-1, &status, WNOHANG|WUNTRACED);
-		if (pid == 0)
-			return;
-		/* if the child (reader) dies, just quit */
-		if (pid < 0 || pid == child && !WIFSTOPPED(status))
-			done(WTERMSIG(status) | WEXITSTATUS(status));
-	}
-	/* NOTREACHED */
-}
-#endif
-
-#if !__minix_vmd
-/*
- * writer: write to remote: 0 -> line.
- * ~.				terminate
- * ~^Z				suspend rlogin process.
- * ~<delayed-suspend char>	suspend rlogin process, but leave reader alone.
- */
-static void
-writer()
-{
-	register int bol, local, n;
-	u_char ch;
-	int c;
-
-	bol = 1;			/* beginning of line */
-	local = 0;
-	for (;;) {
-		n = read(STDIN_FILENO, &ch, 1);
-		if (n <= 0) {
-			if (n < 0 && errno == EINTR)
-				continue;
-			break;
-		}
-		c = ch;
-		/*
-		 * If we're at the beginning of the line and recognize a
-		 * command character, then we echo locally.  Otherwise,
-		 * characters are echo'd remotely.  If the command character
-		 * is doubled, this acts as a force and local echo is
-		 * suppressed.
-		 */
-		if (bol) {
-			bol = 0;
-			if (!noescape && c == escapechar) {
-				local = 1;
-				continue;
-			}
-		} else if (local) {
-			local = 0;
-			if (c == '.' || c == defattr.c_cc[VEOF]) {
-				echo(c);
-				break;
-			}
-#if !__minix
-			if (c == defattr.c_cc[VSUSP]) {
-				bol = 1;
-				echo(c);
-				stop(c);
-				continue;
-			}
-#endif
-			if (c != escapechar)
-#ifdef CRYPT
-#ifdef KERBEROS
-				if (doencrypt)
-					(void)des_write(rem, &escapechar, 1);
-				else
-#endif
-#endif
-					(void)write(rem, &escapechar, 1);
-		}
-
-		ch = c;
-#ifdef CRYPT
-#ifdef KERBEROS
-		if (doencrypt) {
-			if (des_write(rem, &ch, 1) == 0) {
-				msg("line gone");
-				break;
-			}
-		} else
-#endif
-#endif
-			if (write(rem, &ch, 1) == 0) {
-				msg("line gone");
-				break;
-			}
-		bol = c == defattr.c_cc[VKILL] ||
-		    c == defattr.c_cc[VEOF] ||
-		    c == defattr.c_cc[VINTR] ||
-		    c == defattr.c_cc[VSUSP] ||
-		    c == '\r' || c == '\n';
-	}
-}
-#endif
-
-#if !__minix_vmd
-static void
-echo(c)
-int c;
-{
-	register char *p;
-	char buf[8];
-
-	p = buf;
-	c &= 0177;
-	*p++ = escapechar;
-	if (c < ' ') {
-		*p++ = '^';
-		*p++ = c + '@';
-	} else if (c == 0177) {
-		*p++ = '^';
-		*p++ = '?';
-	} else
-		*p++ = c;
-	*p++ = '\r';
-	*p++ = '\n';
-	(void)write(STDOUT_FILENO, buf, p - buf);
-}
-#endif
-
-#if !__minix
-stop(cmdc)
-	char cmdc;
-{
-	mode(0);
-	(void)signal(SIGCHLD, SIG_IGN);
-	(void)kill(cmdc == defltc.t_suspc ? 0 : getpid(), SIGTSTP);
-	(void)signal(SIGCHLD, catch_child);
-	mode(1);
-	sigwinch();			/* check for size changes */
-}
-#endif
-
-#if __minix_vmd
-#ifdef SIGWINCH
-static void
-sigwinch(sig)
-	int sig;
-{
-	struct winsize ws;
-
-#if __minix
-	signal(SIGWINCH, sigwinch);
-#endif
-
-	if (dosigwinch && get_window_size(0, &ws) == 0 &&
-	    memcmp(&ws, &winsize, sizeof(ws))) {
-		winsize = ws;
-		mustsendwindow= 1;
-	}
-}
-
-/*
- * Send the window size to the server via the magic escape
- */
-static void
-sendwindow()
-{
-	struct winsize *wp;
-	char *obuf, *new_buf;
-
-	new_buf= realloc(extra_wr_rem_new, 
-					extra_wr_rem_new_size+4+sizeof(*wp));
-	if (new_buf == 0)
-		return;
-	extra_wr_rem_new= new_buf;
-	obuf= new_buf+extra_wr_rem_new_size;
-	extra_wr_rem_new_size += 4+sizeof(*wp);
-
-	more2read_0= 0;
-	more2write_rem= 1;
-
-	wp = (struct winsize *)(obuf+4);
-	obuf[0] = 0377;
-	obuf[1] = 0377;
-	obuf[2] = 's';
-	obuf[3] = 's';
-	wp->ws_row = htons(winsize.ws_row);
-	wp->ws_col = htons(winsize.ws_col);
-	wp->ws_xpixel = htons(winsize.ws_xpixel);
-	wp->ws_ypixel = htons(winsize.ws_ypixel);
-}
-#endif /* SIGWINCH */
-#endif
-
-#if !__minix_vmd
-/*
- * reader: read from remote: line -> 1
- */
-#define	READING	1
-#define	WRITING	2
-
-int rcvcnt, rcvstate;
-char rcvbuf[8 * 1024];
-
-static int
-reader()
-{
-	int pid = -getpid();
-	int n, remaining;
-	char *bufp = rcvbuf;
-
-	for (;;) {
-		while ((remaining = rcvcnt - (bufp - rcvbuf)) > 0) {
-			rcvstate = WRITING;
-			n = write(STDOUT_FILENO, bufp, remaining);
-			if (n < 0) {
-				if (errno != EINTR)
-					return(-1);
-				continue;
-			}
-			bufp += n;
-		}
-		bufp = rcvbuf;
-		rcvcnt = 0;
-		rcvstate = READING;
-
-#ifdef CRYPT
-#ifdef KERBEROS
-		if (doencrypt)
-			rcvcnt = des_read(rem, rcvbuf, sizeof(rcvbuf));
-		else
-#endif
-#endif
-			rcvcnt = read(rem, rcvbuf, sizeof (rcvbuf));
-		if (rcvcnt == 0)
-			return (0);
-		if (rcvcnt < 0) {
-			if (errno == EINTR)
-				continue;
-			if (errno == EURG) {
-				nwio_tcpopt_t tcpopt;
-#if DEBUG
-fprintf(stderr, "\n\rEURG\n\r");
-#endif
-				tcpopt.nwto_flags= NWTO_RCV_URG;
-				if (ioctl(rem, NWIOSTCPOPT, &tcpopt) == -1) {
-					fprintf(stderr,
-				"rlogin: trouble with urgent data: %s\n",
-						strerror(errno));
-					return(-1);
-				}
-				continue;
-			}
-			if (errno == ENOURG) {
-				nwio_tcpopt_t tcpopt;
-#if DEBUG
-fprintf(stderr, "\n\rENOURG\n\r");
-#endif
-				tcpopt.nwto_flags= NWTO_RCV_NOTURG;
-				if (ioctl(rem, NWIOSTCPOPT, &tcpopt) == -1) {
-					fprintf(stderr,
-				"rlogin: trouble with not-urgent data: %s\n",
-						strerror(errno));
-					return(-1);
-				}
-				continue;
-			}
-			(void)fprintf(stderr, "rlogin: read: %s\n",
-				strerror(errno));
-			return(-1);
-		}
-	}
-}
-#endif  /* !__minix_vmd */
-
-static void
-mode(f)
-	int f;
-{
-	struct termios *sb;
-
-	switch(f) {
-	case 0:
-		sb= &defattr;
-		break;
-	case 1:
-		sb= &rawattr;
-		break;
-	default:
-		return;
-	}
-	(void)tcsetattr(0, TCSAFLUSH, sb);
-}
-
-static void
-lostpeer(sig)
-int sig;
-{
-	(void)signal(SIGPIPE, SIG_IGN);
-	msg("\007connection closed.");
-	done(1);
-}
-
-static void
-msg(str)
-	char *str;
-{
-	(void)fprintf(stderr, "rlogin: %s\r\n", str);
-}
-
-#ifdef KERBEROS
-/* VARARGS */
-warning(va_alist)
-va_dcl
-{
-	va_list ap;
-	char *fmt;
-
-	(void)fprintf(stderr, "rlogin: warning, using standard rlogin: ");
-	va_start(ap);
-	fmt = va_arg(ap, char *);
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
-	(void)fprintf(stderr, ".\n");
-}
-#endif
-
-static void
-usage()
-{
-	(void)fprintf(stderr,
-	    "Usage: rlogin [-%s]%s[-e char] [-l username] host\n",
-#ifdef KERBEROS
-#ifdef CRYPT
-	    "8ELx", " [-k realm] ");
-#else
-	    "8EL", " [-k realm] ");
-#endif
-#else
-	    "8EL", " ");
-#endif
-	exit(1);
-}
-
-/*
- * The following routine provides compatibility (such as it is) between 4.2BSD
- * Suns and others.  Suns have only a `ttysize', so we convert it to a winsize.
- */
-#ifdef sun
-get_window_size(fd, wp)
-	int fd;
-	struct winsize *wp;
-{
-	struct ttysize ts;
-	int error;
-
-	if ((error = ioctl(0, TIOCGSIZE, &ts)) != 0)
-		return(error);
-	wp->ws_row = ts.ts_lines;
-	wp->ws_col = ts.ts_cols;
-	wp->ws_xpixel = 0;
-	wp->ws_ypixel = 0;
-	return(0);
-}
-#endif
-
-static u_char
-getescape(p)
-	register char *p;
-{
-	long val;
-	int len;
-
-	if ((len = strlen(p)) == 1)	/* use any single char, including '\' */
-		return((u_char)*p);
-					/* otherwise, \nnn */
-	if (*p == '\\' && len >= 2 && len <= 4) {
-		val = strtol(++p, (char **)NULL, 8);
-		for (;;) {
-			if (!*++p)
-				return((u_char)val);
-			if (*p < '0' || *p > '8')
-				break;
-		}
-	}
-	msg("illegal option value -- e");
-	usage();
-	/* NOTREACHED */
-}
-
-static char *
-speeds2str(speed)
-	speed_t speed;
-{
-	int i;
-	for (i= 0; speeds[i].name != NULL && speeds[i].speed != speed; i++) {
-		if (speeds[i].speed == speed) return speeds[i].name;
-	}
-	return "unknown";
-}
-
-#if __minix_vmd
-static void 
-mark_async(fd)
-	int fd;
-{
-	int result;
-	int v;
-
-	result= fcntl(fd, F_GETFD);
-	if (result == -1)
-	{
-		fprintf(stderr,
-			"rlogin: mark_async: fcntl(%d, GETFD) failed (%s)\n",
-			fd, strerror(errno));
-		exit(1);
-	}
-	v= result | FD_ASYNCHIO;
-	result= fcntl(fd, F_SETFD, v);
-	if (result == -1)
-	{
-		fprintf(stderr, 
-		"rlogin: mark_async: fcntl(%d, SETFD, %d) failed (%s)\n",
-			fd, v, strerror(errno));
-		exit(1);
-	}
-}
-
-#define RD_0_BUFSIZE	256
-char rd_0_buf[RD_0_BUFSIZE];
-size_t rd_0_offset;
-
-static void
-init_0()
-{
-	more2read_0= 1;
-	inprogress_0= 0;
-	rd_0_offset= 0;
-}
-
-size_t wr_1_size;
-size_t wr_1_offset;
-char *urg_1;
-size_t urg_1_size;
-char *extra_1;
-size_t extra_1_size;
-size_t extra_1_offset;
-char *extra_1_new;
-size_t extra_1_new_size;
-#define MAX_EXTRA_1_NEW_SIZE	(16*1024)
-
-static void
-init_1()
-{
-	more2write_1= 0;
-	inprogress_1= 0;
-	wr_1_size= 0;
-	wr_1_offset= 0;
-	urg_1= NULL;
-	urg_1_size= 0;
-	extra_1= NULL;
-	extra_1_size= 0;
-	extra_1_offset= 0;
-	extra_1_new= NULL;
-	extra_1_new_size= 0;
-}
-
-#define RD_REM_BUFSIZE	(8*1024)
-char rd_rem_buf[RD_REM_BUFSIZE];
-size_t rd_rem_offset;
-int rd_rem_urg;
-
-static void 
-init_rd_rem()
-{
-	more2read_rem= 1;
-	inprogress_rd_rem= 0;
-	rd_rem_offset= 0;
-	rd_rem_urg= 0;
-}
-
-static void 
-init_wr_rem()
-{
-	more2write_rem= 0;
-	inprogress_wr_rem= 0;
-	wr_rem_size= 0;
-	wr_rem_offset= 0;
-	extra_wr_rem_size= 0;
-	extra_wr_rem_offset= 0;
-	extra_wr_rem= NULL;
-	extra_wr_rem_new_size= 0;
-	extra_wr_rem_new= NULL;
-}
-
-static void
-restart_0()
-{
-	size_t offset;
-	int result, error;
-
-	assert(!inprogress_0);
-	rd_0_offset= 1;
-	offset= 0;
-	while (offset < RD_0_BUFSIZE)
-	{
-		result= read(0, rd_0_buf+rd_0_offset+offset,
-					RD_0_BUFSIZE-rd_0_offset-offset);
-		if (result > 0)
-		{
-			offset += result;
-			assert(rd_0_offset+offset <= RD_0_BUFSIZE);
-			continue;
-		}
-		error= errno;
-
-		if (offset != 0)
-			completed_0(offset, 0);
-		rd_0_offset += offset;
-		if (result == -1 && error == EINPROGRESS)
-		{
-			inprogress_0= 1;
-			return;
-		}
-		completed_0(result, error);
-		return;
-	}
-	completed_0(offset, 0);
-}
-
-static void 
-restart_1()
-{
-	size_t offset;
-	int result, error;
-
-	assert(!inprogress_1);
-
-	while (extra_1 != NULL || extra_1_new != NULL)
-	{
-		if (extra_1 == NULL)
-		{
-			extra_1= extra_1_new;
-			extra_1_new= NULL;
-			extra_1_size= extra_1_new_size;
-			extra_1_new_size= 0;
-			extra_1_offset= 0;
-		}
-		offset= 0;
-#if DEBUG
-		if (extra_1_size == 0)
-			fprintf(stderr, "restart_1: extra_1_size= 0\n");
-#endif
-		while (offset < extra_1_size)
-		{
-			result= write(1, extra_1+extra_1_offset+offset, 
-							extra_1_size-offset);
-			if (result > 0)
-			{
-				assert (result <= extra_1_size-offset);
-				offset += result;
-				continue;
-			}
-			error= errno;
-			if (offset != 0)
-				completed_1(offset, 0);
-
-			if (result == -1 && errno == EINPROGRESS)
-			{
-				inprogress_1= 1;
-				return;
-			}
-			completed_1(result, errno);
-			return;
-		}
-		completed_1(offset, 0);
-	}
-
-	offset= 0;
-
-	if (wr_1_size == 0)
-	{
-		more2write_1= 0;
-		more2read_rem= 1;
-		return;
-	}
-
-	while (offset < wr_1_size)
-	{
-		result= write(1, rd_rem_buf+wr_1_offset+offset, 
-							wr_1_size-offset);
-		if (result > 0)
-		{
-			assert (result <= wr_1_size-offset);
-			offset += result;
-			continue;
-		}
-		error= errno;
-		if (offset != 0)
-			completed_1(offset, 0);
-
-		if (result == -1 && errno == EINPROGRESS)
-		{
-			inprogress_1= 1;
-			return;
-		}
-		completed_1(result, errno);
-		return;
-	}
-	completed_1(offset, 0);
-}
-
-static void
-restart_rd_rem()
-{
-	size_t offset;
-	int result, error;
-
-	assert(!inprogress_rd_rem);
-	rd_rem_offset= 0;
-	offset= 0;
-	while (offset < RD_REM_BUFSIZE)
-	{
-		result= read(rem, rd_rem_buf+offset, RD_REM_BUFSIZE-offset);
-		if (result > 0)
-		{
-			offset += result;
-			assert(offset <= RD_REM_BUFSIZE);
-			continue;
-		}
-		error= errno;
-
-		if (offset != 0)
-			completed_rd_rem(offset, 0);
-		rd_rem_offset= offset;
-		if (result == -1 && error == EINPROGRESS)
-		{
-			inprogress_rd_rem= 1;
-			return;
-		}
-		completed_rd_rem(result, error);
-		return;
-	}
-	completed_rd_rem(offset, 0);
-}
-
-static void
-restart_wr_rem()
-{
-	size_t offset;
-	int result, error;
-
-	assert(!inprogress_wr_rem);
-
-	if (extra_wr_rem_new != NULL && extra_wr_rem == NULL)
-	{
-		extra_wr_rem= extra_wr_rem_new;
-		extra_wr_rem_size= extra_wr_rem_new_size;
-		extra_wr_rem_offset= 0;
-		extra_wr_rem_new= NULL;
-		extra_wr_rem_new_size= 0;
-	}
-	if (extra_wr_rem != NULL)
-	{
-		offset= 0;
-		while (offset < extra_wr_rem_size)
-		{
-			result= write(rem, 
-				extra_wr_rem+extra_wr_rem_offset+offset, 
-						extra_wr_rem_size-offset);
-			if (result > 0)
-			{
-				assert (result <= extra_wr_rem_size-offset);
-				offset += result;
-				continue;
-			}
-			error= errno;
-			if (offset != 0)
-				completed_wr_rem(offset, 0);
-
-			if (result == -1 && errno == EINPROGRESS)
-			{
-				inprogress_wr_rem= 1;
-				return;
-			}
-			completed_wr_rem(result, errno);
-			return;
-		}
-		completed_wr_rem(offset, 0);
-	}
-	if (wr_rem_size == 0)
-		return;
-
-	offset= 0;
-	while (offset < wr_rem_size)
-	{
-		result= write(rem, rd_0_buf+wr_rem_offset+offset, 
-							wr_rem_size-offset);
-		if (result > 0)
-		{
-			assert (result <= wr_rem_size-offset);
-			offset += result;
-			continue;
-		}
-		error= errno;
-		if (offset != 0)
-			completed_wr_rem(offset, 0);
-
-		if (result == -1 && errno == EINPROGRESS)
-		{
-			inprogress_wr_rem= 1;
-			return;
-		}
-		completed_wr_rem(result, errno);
-		return;
-	}
-	completed_wr_rem(offset, 0);
-}
-
-static void
-completed_0(result, error)
-	int result;
-	int error;
-{
-	static int bol= 0, local= 0;
-
-	char *iptr, *optr;
-	int i;
-	u_char c;
-
-	inprogress_0= 0;
-
-	if (result > 0)
-	{
-		assert(rd_0_offset > 0);
-		wr_rem_offset= 1;
-
-		iptr= rd_0_buf+rd_0_offset;
-		optr= rd_0_buf+wr_rem_offset;
-		for (i= 0; i<result; iptr++, i++)
-		{
-			c= *iptr;
-			if (bol)
-			{
-				bol= 0;
-				if (!noescape && c == escapechar)
-				{
-					local= 1;
-					continue;
-				}
-			}
-			else if (local)
-			{
-				local= 0;
-				if (c == '.' || (c != _POSIX_VDISABLE &&
-					c == defattr.c_cc[VEOF]))
-				{
-					echo(c);
-					finish();
-					/* NOTREACHED */
-				}
-				if (c == '!')
-				{
-					subshell();
-					continue;
-				}
-				if (c != escapechar)
-				{
-					if (optr < iptr)
-					{
-						*(optr++)= escapechar;
-					}
-					else
-					{
-						assert(optr == iptr);
-						assert(iptr == rd_0_buf+
-								rd_0_offset);
-						assert(rd_0_offset > 0);
-						wr_rem_offset--;
-						optr[-1]= escapechar;
-					}
-				}
-			}
-			*(optr++)= c;
-			bol= (c != _POSIX_VDISABLE) && 
-				(c == defattr.c_cc[VKILL] ||
-				c == defattr.c_cc[VEOF] ||
-				c == defattr.c_cc[VINTR] ||
-				c == defattr.c_cc[VSUSP] ||
-				c == '\r' || c == '\n');
-		}
-		wr_rem_size += optr-rd_0_buf-wr_rem_offset;
-		if (wr_rem_size != 0)
-		{
-			more2read_0= 0;
-			more2write_rem= 1;
-		}
-		return;
-	} else
-	if (result < 0) {
-		fprintf(stderr, "rlogin: %s\n", strerror(error));
-	}
-	done(1);
-}
-
-static void
-completed_1(result, error)
-	int result;
-	int error;
-{
-	inprogress_1= 0;
-
-	if (result > 0)
-	{
-		if (extra_1 != NULL)
-		{
-			assert (result <= extra_1_size);
-			extra_1_size -= result;
-			extra_1_offset += result;
-			if (extra_1_size == 0)
-			{
-				more2write_1= 0;
-				more2read_rem= 1;
-				free(extra_1);
-				extra_1= NULL;
-			}
-			return;
-		}
-		assert (result <= wr_1_size);
-		wr_1_size -= result;
-		wr_1_offset += result;
-		if (wr_1_size == 0)
-		{
-			more2write_1= 0;
-			more2read_rem= 1;
-		}
-		return;
-	} else
-	if (result < 0) {
-		fprintf(stderr, "rlogin: %s\n", strerror(error));
-	}
-	done(1);
-}
-
-static void
-completed_rd_rem(result, error)
-	int result;
-	int error;
-{
-	nwio_tcpopt_t tcpopt;
-	char *new_buf;
-	size_t keep_size;
-	u_char urg_byte;
-	int i;
-
-	inprogress_rd_rem= 0;
-
-	if (result > 0)
-	{
-		if (rd_rem_urg)
-		{
-#if DEBUG
-fprintf(stderr, "\n\r%d urg bytes\n\r", result);
-#endif
-			if (urg_1_size > MAX_EXTRA_1_NEW_SIZE)
-			{
-				keep_size= MAX_EXTRA_1_NEW_SIZE/2;
-				memmove(urg_1, urg_1+urg_1_size-keep_size, 
-					keep_size);
-				urg_1_size= keep_size;
-			}
-			new_buf= realloc(urg_1, urg_1_size+result);
-			if (new_buf == NULL)
-			{
-				fprintf(stderr, 
-					"rlogin: warning realloc %d failed\n",
-					urg_1_size+result);
-				return;
-			}
-			memcpy(new_buf+urg_1_size, 
-				rd_rem_buf+rd_rem_offset, result);
-			urg_1= new_buf;
-			urg_1_size += result;
-			return;
-		}
-		more2read_rem= 0;
-		more2write_1= 1;
-		wr_1_size= result;
-		wr_1_offset= rd_rem_offset;
-		return;
-	}
-	if (result == -1 && error == EURG)
-	{
-#if DEBUG
-fprintf(stderr, "\n\rEURG\n\r");
-#endif
-		rd_rem_urg= 1;
-		tcpopt.nwto_flags= NWTO_RCV_URG;
-		result= ioctl(rem, NWIOSTCPOPT, &tcpopt);
-		if (result == -1)
-		{
-			fprintf(stderr, 
-				"rlogin: NWIOSTCPOPT on %d failed (%s)\n",
-				rem, strerror(errno));
-			exit(1);
-		}
-		return;
-	}
-	if (result == -1 && error == ENOURG)
-	{
-#if DEBUG
-fprintf(stderr, "\n\rENOURG\n\r");
-#endif
-		rd_rem_urg= 0;
-		tcpopt.nwto_flags= NWTO_RCV_NOTURG;
-		result= ioctl(rem, NWIOSTCPOPT, &tcpopt);
-		if (result == -1)
-		{
-			fprintf(stderr, 
-				"rlogin: NWIOSTCPOPT on %d failed (%s)\n",
-				rem, strerror(errno));
-			exit(1);
-		}
-		if (urg_1_size != 0)
-		{
-			urg_byte= urg_1[urg_1_size-1];
-			urg_1_size--;
-			do_urg(urg_byte);
-			if (urg_1_size == 0)
-				return;
-			if (extra_1_new_size + urg_1_size > MAX_EXTRA_1_NEW_SIZE)
-			{
-				extra_1_new_size= 0;
-				free(extra_1_new);
-				extra_1_new= NULL;
-			}
-			if (extra_1_new_size != 0)
-			{
-				new_buf= realloc(extra_1_new, 
-					extra_1_new_size+urg_1_size);
-				if (new_buf == 0)
-				{
-					extra_1_new_size= 0;
-					free(extra_1_new);
-					extra_1_new= NULL;
-				}
-				else
-				{
-					extra_1_new= new_buf;
-					memcpy(extra_1_new+extra_1_new_size,
-						urg_1, urg_1_size);
-					extra_1_new_size += urg_1_size;
-					urg_1_size= 0;
-					free(urg_1);
-					urg_1= NULL;
-				}
-			}
-			if (extra_1_new_size == 0)
-			{
-				extra_1_new_size= urg_1_size;
-				extra_1_new= urg_1;
-				urg_1_size= 0;
-				urg_1= NULL;
-			}
-			more2read_rem= 0;
-			more2write_1= 1;
-		}
-		return;
-	}
-	if (result == -1 && error == EINTR)
-	{
-		/* Never mind. */
-		return;
-	}
-	if (result == 0)
-	{
-		msg("connection closed.");
-		done(0);
-	}
-	if (result < 0) {
-		fprintf(stderr, "rlogin: %s\n", strerror(error));
-	}
-	done(1);
-}
-
-static void
-completed_wr_rem(result, error)
-	int result;
-	int error;
-{
-	inprogress_wr_rem= 0;
-
-	if (result > 0)
-	{
-		if (extra_wr_rem != NULL)
-		{
-			assert (result <= extra_wr_rem_size);
-			extra_wr_rem_size -= result;
-			extra_wr_rem_offset += result;
-			if (extra_wr_rem_size == 0)
-			{
-				free(extra_wr_rem);
-				extra_wr_rem= NULL;
-				if (wr_rem_size == 0)
-				{
-					more2write_rem= 0;
-					more2read_0= 1;
-				}
-			}
-			return;
-		}
-
-		assert (result <= wr_rem_size);
-		wr_rem_size -= result;
-		wr_rem_offset += result;
-		if (wr_rem_size == 0)
-		{
-			more2write_rem= 0;
-			more2read_0= 1;
-		}
-		return;
-	}
-	if (result < 0) {
-		fprintf(stderr, "rlogin: %s\n", strerror(error));
-	}
-	done(1);
-}
-
-static void
-do_urg(urg_byte)
-	int urg_byte;
-{
-#if DEBUG
-	fprintf(stderr, "rlogin: warning got urg_byte 0x%x\r\n", urg_byte);
-#endif
-	if (urg_byte & TIOCPKT_WINDOW)
-	{
-		if (dosigwinch == 0)
-		{
-			sendwindow();
-			signal(SIGWINCH, sigwinch);
-		}
-		dosigwinch= 1;
-	}
-}
-
-static void
-echo(c)
-	int c;
-{
-	u_char c1;
-	char *new_buf;
-
-	new_buf= realloc(extra_1_new, extra_1_new_size+6);
-	if (new_buf == NULL)
-		return;
-	extra_1_new= new_buf;
-	new_buf= extra_1_new+extra_1_new_size;
-
-	c1= escapechar;
-	if (c1 < ' ')
-	{
-		*new_buf++= '^';
-		*new_buf++= c1 + '@';
-	}
-	else if (c1 == 0x7f)
-	{
-		*new_buf++= '^';
-		*new_buf++= '?';
-	}
-	else
-		*new_buf++= c1;
-
-	if (c < ' ')
-	{
-		*new_buf++= '^';
-		*new_buf++= c + '@';
-	}
-	else if (c == 0x7f)
-	{
-		*new_buf++= '^';
-		*new_buf++= '?';
-	}
-	else
-		*new_buf++= c;
-
-	*new_buf++= '\r';
-	*new_buf++= '\n';
-	extra_1_new_size= new_buf-extra_1_new;
-	more2write_1= 1;
-}
-
-static void
-finish()
-{
-	done(0);
-}
-
-static char cmdbuf[256];
-
-static void
-subshell()
-{
-	/* Start a subshell. Based on the first character of the command,
-	 * the tcp connection will be present at fd 3 ('+'), or at
-	 * fd 0 and fd 1 ('=')
-	 */
-	int r, pid, stat, len;
-	char *shell, *cmd;
-
-	/* cancel the reads and writes that are in progress. */
-	if (inprogress_0)
-	{
-		r= fcancel(0, ASIO_READ);
-		if (r != 0) abort();
-	}
-	if (inprogress_1)
-	{
-		r= fcancel(1, ASIO_WRITE);
-		if (r != 0) abort();
-	}
-	if (inprogress_rd_rem)
-	{
-		r= fcancel(rem, ASIO_READ);
-		if (r != 0) abort();
-	}
-	if (inprogress_wr_rem)
-	{
-		r= fcancel(rem, ASIO_WRITE);
-		if (r != 0) abort();
-	}
-
-	mode(0);
-
-	pid= fork();
-	if (pid == -1) abort();
-	if (pid != 0)
-	{
-		r= waitpid(pid, &stat, 0);
-		if (r != pid) abort();
-
-#if DEBUG
-		fprintf(stderr, "stat: 0x%x\n", stat);
-#endif
-		mode(1);
-		return;
-	}
-
-	(void)signal(SIGINT, SIG_DFL);
-
-	shell= getenv("SHELL");
-	if (shell == NULL)
-		shell= "/bin/sh";
-	printf("~!\ncommand [%s]: ", shell);
-	cmd= fgets(cmdbuf, sizeof(cmdbuf), stdin);
-	if (cmd == NULL)
-		exit(0);
-#if DEBUG
-	printf("got command '%s'\n", cmd);
-#endif
-
-	/* Strip the trailing newline */
-	len= strlen(cmd);
-	if (len > 0 && cmd[len-1] == '\n')
-		cmd[len-1]= '\0';
-	else
-		printf("\n");
-
-	/* Skip leading white space */
-	while (*cmd != '\0' && isspace(*cmd))
-		cmd++;
-
-	if (*cmd == '+')
-	{
-		if (rem != 3)
-		{
-			dup2(rem, 3);
-			close(rem);
-		}
-		cmd++;
-	}
-	else if (*cmd == '=')
-	{
-		dup2(rem, 0);
-		dup2(rem, 1);
-		close(rem);
-		cmd++;
-	}
-	else
-		close(rem);
-	if (*cmd == '\0')
-	{
-		r= execl(shell, shell, NULL);
-	}
-	else
-	{
-		r= execl("/bin/sh", "sh", "-c", cmd, NULL);
-	}
-	printf("exec failed: %d, %d\n", r, errno);
-	exit(0);
-}
-#endif /* __minix_vmd */
Index: trunk/minix/commands/simple/rmdir.c
===================================================================
--- trunk/minix/commands/simple/rmdir.c	(revision 9)
+++ 	(revision )
@@ -1,46 +1,0 @@
-/*	rmdir - remove directory.		Author:  Kees J. Bot
- */
-#define nil 0
-#include <sys/types.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-void tell(char *what)
-{
-	write(2, what, strlen(what));
-}
-
-void report(char *label)
-{
-	char *err= strerror(errno);
-
-	tell("rmdir: ");
-	tell(label);
-	tell(": ");
-	tell(err);
-	tell("\n");
-}
-
-int main(int argc, char **argv)
-{
-	int i, ex= 0;
-
-	if (argc < 2) {
-		tell("Usage: rmdir directory ...\n");
-		exit(1);
-	}
-
-	i=1;
-	do {
-		if (rmdir(argv[i]) < 0) {
-			report(argv[i]);
-			ex= 1;
-		}
-	} while (++i < argc);
-
-	exit(ex);
-}
-/* Kees J. Bot  27-12-90. */
Index: trunk/minix/commands/simple/rsh.c
===================================================================
--- trunk/minix/commands/simple/rsh.c	(revision 9)
+++ 	(revision )
@@ -1,567 +1,0 @@
-/*-
- * Copyright (c) 1983, 1990 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. 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1983, 1990 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)rsh.c	5.24 (Berkeley) 7/1/91";
-#endif /* not lint */
-
-/*
- * $Source: /cvsup/minix/src/commands/simple/rsh.c,v $
- * $Header: /cvsup/minix/src/commands/simple/rsh.c,v 1.2 2005/06/17 13:42:53 beng Exp $
- */
-
-#if _MINIX
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <net/netlib.h>
-#include <net/gen/netdb.h>
-void main _ARGS(( int argc, char *argv[] ));
-void usage _ARGS(( void ));
-char *copyargs _ARGS(( char **argv ));
-void sendsig _ARGS(( int signo ));
-void talk _ARGS(( int nflag, long omask, int pid, int rem ));
-
-#define _PATH_RLOGIN1	"/bin/rlogin"
-#define _PATH_RLOGIN2	"/usr/bin/rlogin"
-
-#else
-#include <sys/types.h>
-#include <sys/signal.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <sys/file.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-
-#include <pwd.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <varargs.h>
-#include "pathnames.h"
-#endif
-
-#ifdef KERBEROS
-#include <kerberosIV/des.h>
-#include <kerberosIV/krb.h>
-
-CREDENTIALS cred;
-Key_schedule schedule;
-int use_kerberos = 1, doencrypt;
-char dst_realm_buf[REALM_SZ], *dest_realm;
-extern char *krb_realmofhost();
-#endif
-
-/*
- * rsh - remote shell
- */
-extern int errno;
-int rfd2;
-
-void
-main(argc, argv)
-	int argc;
-	char **argv;
-{
-	extern char *optarg;
-	extern int optind;
-	struct passwd *pw;
-	struct servent *sp;
-	long omask;
-	int argoff, asrsh, ch, dflag, nflag, one, pid, rem, uid;
-	register char *p;
-	char *args, *host, *user;
-#if !_MINIX
-	char *copyargs();
-	void sendsig();
-#endif
-
-	argoff = asrsh = dflag = nflag = 0;
-	one = 1;
-	host = user = NULL;
-
-	/* if called as something other than "rsh", use it as the host name */
-	if (p = rindex(argv[0], '/'))
-		++p;
-	else
-		p = argv[0];
-	if (strcmp(p, "rsh"))
-		host = p;
-	else
-		asrsh = 1;
-
-	/* handle "rsh host flags" */
-	if (!host && argc > 2 && argv[1][0] != '-') {
-		host = argv[1];
-		argoff = 1;
-	}
-
-#ifdef KERBEROS
-#ifdef CRYPT
-#define	OPTIONS	"8KLdek:l:nwx"
-#else
-#define	OPTIONS	"8KLdek:l:nw"
-#endif
-#else
-#define	OPTIONS	"8KLdel:nw"
-#endif
-	while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != EOF)
-		switch(ch) {
-		case 'K':
-#ifdef KERBEROS
-			use_kerberos = 0;
-#endif
-			break;
-		case 'L':	/* -8Lew are ignored to allow rlogin aliases */
-		case 'e':
-		case 'w':
-		case '8':
-			break;
-		case 'd':
-			dflag = 1;
-			break;
-		case 'l':
-			user = optarg;
-			break;
-#ifdef KERBEROS
-		case 'k':
-			dest_realm = dst_realm_buf;
-			strncpy(dest_realm, optarg, REALM_SZ);
-			break;
-#endif
-		case 'n':
-			nflag = 1;
-			break;
-#ifdef KERBEROS
-#ifdef CRYPT
-		case 'x':
-			doencrypt = 1;
-			des_set_key(cred.session, schedule);
-			break;
-#endif
-#endif
-		case '?':
-		default:
-			usage();
-		}
-	optind += argoff;
-
-	/* if haven't gotten a host yet, do so */
-	if (!host && !(host = argv[optind++]))
-		usage();
-
-	/* if no further arguments, must have been called as rlogin. */
-	if (!argv[optind]) {
-		if (asrsh)
-			*argv = "rlogin";
-		execv(_PATH_RLOGIN1, argv);
-		execv(_PATH_RLOGIN2, argv);
-		(void)fprintf(stderr, "rsh: can't exec rlogin\n");
-		exit(1);
-	}
-
-	argc -= optind;
-	argv += optind;
-
-	if (!(pw = getpwuid(uid = getuid()))) {
-		(void)fprintf(stderr, "rsh: unknown user id.\n");
-		exit(1);
-	}
-	if (!user)
-		user = pw->pw_name;
-
-#ifdef KERBEROS
-#ifdef CRYPT
-	/* -x turns off -n */
-	if (doencrypt)
-		nflag = 0;
-#endif
-#endif
-
-	args = copyargs(argv);
-
-	sp = NULL;
-#ifdef KERBEROS
-	if (use_kerberos) {
-		sp = getservbyname((doencrypt ? "ekshell" : "kshell"), "tcp");
-		if (sp == NULL) {
-			use_kerberos = 0;
-			warning("can't get entry for %s/tcp service",
-			    doencrypt ? "ekshell" : "kshell");
-		}
-	}
-#endif
-	if (sp == NULL)
-		sp = getservbyname("shell", "tcp");
-	if (sp == NULL) {
-		(void)fprintf(stderr, "rsh: shell/tcp: unknown service.\n");
-		exit(1);
-	}
-
-#ifdef KERBEROS
-try_connect:
-	if (use_kerberos) {
-		rem = KSUCCESS;
-		errno = 0;
-		if (dest_realm == NULL)
-			dest_realm = krb_realmofhost(host);
-
-#ifdef CRYPT
-		if (doencrypt)
-			rem = krcmd_mutual(&host, sp->s_port, user, args,
-			    &rfd2, dest_realm, &cred, schedule);
-		else
-#endif
-			rem = krcmd(&host, sp->s_port, user, args, &rfd2,
-			    dest_realm);
-		if (rem < 0) {
-			use_kerberos = 0;
-			sp = getservbyname("shell", "tcp");
-			if (sp == NULL) {
-				(void)fprintf(stderr,
-				    "rsh: unknown service shell/tcp.\n");
-				exit(1);
-			}
-			if (errno == ECONNREFUSED)
-				warning("remote host doesn't support Kerberos");
-			if (errno == ENOENT)
-				warning("can't provide Kerberos auth data");
-			goto try_connect;
-		}
-	} else {
-		if (doencrypt) {
-			(void)fprintf(stderr,
-			    "rsh: the -x flag requires Kerberos authentication.\n");
-			exit(1);
-		}
-		rem = rcmd(&host, sp->s_port, pw->pw_name, user, args, &rfd2);
-	}
-#else
-	rem = rcmd(&host, sp->s_port, pw->pw_name, user, args, &rfd2);
-#endif
-
-	if (rem < 0)
-		exit(1);
-
-	if (rfd2 < 0) {
-		(void)fprintf(stderr, "rsh: can't establish stderr.\n");
-		exit(1);
-	}
-#if !_MINIX
-	if (dflag) {
-		if (setsockopt(rem, SOL_SOCKET, SO_DEBUG, &one,
-		    sizeof(one)) < 0)
-			(void)fprintf(stderr, "rsh: setsockopt: %s.\n",
-			    strerror(errno));
-		if (setsockopt(rfd2, SOL_SOCKET, SO_DEBUG, &one,
-		    sizeof(one)) < 0)
-			(void)fprintf(stderr, "rsh: setsockopt: %s.\n",
-			    strerror(errno));
-	}
-#endif
-
-	(void)setuid(uid);
-#if !_MINIX
-	omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGTERM));
-#endif
-	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
-		(void)signal(SIGINT, sendsig);
-	if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
-		(void)signal(SIGQUIT, sendsig);
-	if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
-		(void)signal(SIGTERM, sendsig);
-
-	if (!nflag) {
-		pid = fork();
-		if (pid < 0) {
-			(void)fprintf(stderr,
-			    "rsh: fork: %s.\n", strerror(errno));
-			exit(1);
-		}
-	}
-
-#ifdef KERBEROS
-#ifdef CRYPT
-	if (!doencrypt)
-#endif
-#endif
-	{
-#if _MINIX
-		;
-#else
-		(void)ioctl(rfd2, FIONBIO, &one);
-		(void)ioctl(rem, FIONBIO, &one);
-#endif
-	}
-
-	talk(nflag, omask, pid, rem);
-
-	if (!nflag && pid)
-	{
-#if DEBUG
-		printf("killing %d with %d\n", pid, SIGKILL);
-#endif
-		(void)kill(pid, SIGKILL);
-	}
-	exit(0);
-}
-
-void
-talk(nflag, omask, pid, rem)
-	int nflag, pid;
-	long omask;
-	register int rem;
-{
-	register int cc, wc;
-	register char *bp;
-	int readfrom, ready, rembits;
-	char buf[BUFSIZ];
-#if _MINIX
-	int pid1;
-#endif
-
-	if (!nflag && pid == 0) {
-		(void)close(rfd2);
-
-reread:		errno = 0;
-		if ((cc = read(0, buf, sizeof buf)) <= 0)
-			goto done;
-		bp = buf;
-
-rewrite:
-#if !_MINIX
-		rembits = 1 << rem;
-		if (select(16, 0, &rembits, 0, 0) < 0) {
-			if (errno != EINTR) {
-				(void)fprintf(stderr,
-				    "rsh: select: %s.\n", strerror(errno));
-				exit(1);
-			}
-			goto rewrite;
-		}
-		if ((rembits & (1 << rem)) == 0)
-			goto rewrite;
-#endif
-#ifdef KERBEROS
-#ifdef CRYPT
-		if (doencrypt)
-			wc = des_write(rem, bp, cc);
-		else
-#endif
-#endif
-			wc = write(rem, bp, cc);
-		if (wc < 0) {
-#if !_MINIX
-			if (errno == EWOULDBLOCK)
-				goto rewrite;
-#endif
-			goto done;
-		}
-		bp += wc;
-		cc -= wc;
-		if (cc == 0)
-			goto reread;
-		goto rewrite;
-done:
-#if _MINIX
-		ioctl(rem, NWIOTCPSHUTDOWN, NULL);
-#else
-		(void)shutdown(rem, 1);
-#endif
-		exit(0);
-	}
-
-#if _MINIX
-	pid1= fork();
-	if (pid1 == -1)
-	{
-		(void)fprintf(stderr, "rsh: fork: %s.\n", strerror(errno));
-		exit(1);
-	}
-	close (pid1 ? rfd2 : rem);
-	for(;;)
-	{
-		errno = 0;
-		cc = read(pid1 ? rem : rfd2, buf, sizeof buf);
-		if (cc <= 0)
-		{
-			if (pid1)
-			{
-#if DEBUG
-				printf("killing %d with %d\n", pid1, SIGKILL);
-#endif
-				kill(pid1, SIGKILL);
-				return;
-			}
-			exit(0);
-		}
-		(void)write(pid1 ? 1 : 2, buf, cc);
-	}
-#else
-	(void)sigsetmask(omask);
-	readfrom = (1 << rfd2) | (1 << rem);
-	do {
-		ready = readfrom;
-		if (select(16, &ready, 0, 0, 0) < 0) {
-			if (errno != EINTR) {
-				(void)fprintf(stderr,
-				    "rsh: select: %s.\n", strerror(errno));
-				exit(1);
-			}
-			continue;
-		}
-		if (ready & (1 << rfd2)) {
-			errno = 0;
-#ifdef KERBEROS
-#ifdef CRYPT
-			if (doencrypt)
-				cc = des_read(rfd2, buf, sizeof buf);
-			else
-#endif
-#endif
-				cc = read(rfd2, buf, sizeof buf);
-			if (cc <= 0) {
-				if (errno != EWOULDBLOCK)
-					readfrom &= ~(1 << rfd2);
-			} else
-				(void)write(2, buf, cc);
-		}
-		if (ready & (1 << rem)) {
-			errno = 0;
-#ifdef KERBEROS
-#ifdef CRYPT
-			if (doencrypt)
-				cc = des_read(rem, buf, sizeof buf);
-			else
-#endif
-#endif
-				cc = read(rem, buf, sizeof buf);
-			if (cc <= 0) {
-				if (errno != EWOULDBLOCK)
-					readfrom &= ~(1 << rem);
-			} else
-				(void)write(1, buf, cc);
-		}
-	} while (readfrom);
-#endif
-}
-
-void
-sendsig(signo)
-	char signo;
-{
-#ifdef KERBEROS
-#ifdef CRYPT
-	if (doencrypt)
-		(void)des_write(rfd2, &signo, 1);
-	else
-#endif
-#endif
-		(void)write(rfd2, &signo, 1);
-}
-
-#ifdef KERBEROS
-/* VARARGS */
-warning(va_alist)
-va_dcl
-{
-	va_list ap;
-	char *fmt;
-
-	(void)fprintf(stderr, "rsh: warning, using standard rsh: ");
-	va_start(ap);
-	fmt = va_arg(ap, char *);
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
-	(void)fprintf(stderr, ".\n");
-}
-#endif
-
-char *
-copyargs(argv)
-	char **argv;
-{
-	register int cc;
-	register char **ap, *p;
-	char *args;
-#if !_MINIX
-	char *malloc();
-#endif
-
-	cc = 0;
-	for (ap = argv; *ap; ++ap)
-		cc += strlen(*ap) + 1;
-	if (!(args = malloc((u_int)cc))) {
-		(void)fprintf(stderr, "rsh: %s.\n", strerror(ENOMEM));
-		exit(1);
-	}
-	for (p = args, ap = argv; *ap; ++ap) {
-		(void)strcpy(p, *ap);
-		for (p = strcpy(p, *ap); *p; ++p);
-		if (ap[1])
-			*p++ = ' ';
-	}
-	return(args);
-}
-
-void
-usage()
-{
-	(void)fprintf(stderr,
-	    "usage: rsh [-nd%s]%s[-l login] host [command]\n",
-#ifdef KERBEROS
-#ifdef CRYPT
-	    "x", " [-k realm] ");
-#else
-	    "", " [-k realm] ");
-#endif
-#else
-	    "", " ");
-#endif
-	exit(1);
-}
Index: trunk/minix/commands/simple/sed.c
===================================================================
--- trunk/minix/commands/simple/sed.c	(revision 9)
+++ 	(revision )
@@ -1,1613 +1,0 @@
-/* sed - stream editor		Author: Eric S. Raymond */
-
-/* This used to be three different files with the following makefile:
- * (Note the chmem).
-
-CFLAGS=	-F -T.
-
-OBJS=   sedcomp.s sedexec.s
-
-sed: 	$(OBJS)
-        cc -T. -o sed $(OBJS)
-  @chmem =13312 sed
-
-$(OBJS):	sed.h
-
- * If you want longer lines: increase MAXBUF.
- * If you want scripts with more text: increase POOLSIZE.
- * If you want more commands per script: increase MAXCMDS.
- */
-
-#include <ctype.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-/*+++++++++++++++*/
-
-/* Sed.h -- types and constants for the stream editor */
-
-/* Data area sizes used by both modules */
-#define MAXBUF		4000	/* current line buffer size */
-#define MAXAPPENDS	20	/* maximum number of appends */
-#define MAXTAGS		9	/* tagged patterns are \1 to \9 */
-
-/* Constants for compiled-command representation */
-#define EQCMD	0x01		/* = -- print current line number	 */
-#define ACMD	0x02		/* a -- append text after current line	 */
-#define BCMD	0x03		/* b -- branch to label			 */
-#define CCMD	0x04		/* c -- change current line		 */
-#define DCMD	0x05		/* d -- delete all of pattern space */
-#define CDCMD	0x06		/* D -- delete first line of pattern space */
-#define GCMD	0x07		/* g -- copy hold space to pattern space */
-#define CGCMD	0x08		/* G -- append hold space to pattern space */
-#define HCMD	0x09		/* h -- copy pattern space to hold space */
-#define CHCMD	0x0A		/* H -- append pattern space to hold space */
-#define ICMD	0x0B		/* i -- insert text before current line	 */
-#define LCMD	0x0C		/* l -- print pattern space in escaped form */
-#define NCMD	0x0D		/* n -- get next line into pattern space */
-#define CNCMD	0x0E		/* N -- append next line to pattern space */
-#define PCMD	0x0F		/* p -- print pattern space to output	 */
-#define CPCMD	0x10		/* P -- print first line of pattern space */
-#define QCMD	0x11		/* q -- exit the stream editor		 */
-#define RCMD	0x12		/* r -- read in a file after current line */
-#define SCMD	0x13		/* s -- regular-expression substitute	 */
-#define TCMD	0x14		/* t -- branch on any substitute successful */
-#define CTCMD	0x15		/* T -- branch on any substitute failed	 */
-#define WCMD	0x16		/* w -- write pattern space to file	 */
-#define CWCMD	0x17		/* W -- write first line of pattern space */
-#define XCMD	0x18		/* x -- exhange pattern and hold spaces	 */
-#define YCMD	0x19		/* y -- transliterate text		 */
-
-struct cmd_t {			/* compiled-command representation */
-  char *addr1;			/* first address for command */
-  char *addr2;			/* second address for command */
-  union {
-	char *lhs;		/* s command lhs */
-	struct cmd_t *link;	/* label link */
-  } u;
-  char command;			/* command code */
-  char *rhs;			/* s command replacement string */
-  FILE *fout;			/* associated output file descriptor */
-  struct {
-	char allbut;		/* was negation specified? */
-	char global;		/* was g postfix specified? */
-	char print;		/* was p postfix specified? */
-	char inrange;		/* in an address range? */
-  } flags;
-};
-typedef struct cmd_t sedcmd;	/* use this name for declarations */
-
-#define BAD	((char *) -1)	/* guaranteed not a string ptr */
-
-
-
-/* Address and regular expression compiled-form markers */
-#define STAR	1		/* marker for Kleene star */
-#define CCHR	2		/* non-newline character to be matched
-			 * follows */
-#define CDOT	4		/* dot wild-card marker */
-#define CCL	6		/* character class follows */
-#define CNL	8		/* match line start */
-#define CDOL	10		/* match line end */
-#define CBRA	12		/* tagged pattern start marker */
-#define CKET	14		/* tagged pattern end marker */
-#define CBACK	16		/* backslash-digit pair marker */
-#define CLNUM	18		/* numeric-address index follows */
-#define CEND	20		/* symbol for end-of-source */
-#define CEOF	22		/* end-of-field mark */
-
-/* Sed.h ends here */
-
-#ifndef CMASK
-#define CMASK  0xFF		/* some char type should have been unsigned
-			 * char? */
-#endif
-
-/*+++++++++++++++*/
-
-/* Sed - stream editor		Author: Eric S. Raymond */
-
-/*
-   The stream editor compiles its command input	 (from files or -e options)
-   into an internal form using compile() then executes the compiled form using
-   execute(). Main() just initializes data structures, interprets command line
-   options, and calls compile() and execute() in appropriate sequence.
-
-   The data structure produced by compile() is an array of compiled-command
-   structures (type sedcmd).  These contain several pointers into pool[], the
-   regular-expression and text-data pool, plus a command code and g & p flags.
-   In the special case that the command is a label the struct  will hold a ptr
-   into the labels array labels[] during most of the compile,  until resolve()
-   resolves references at the end.
-
-   The operation of execute() is described in its source module.
-*/
-
-/* #include <stdio.h> */
-/* #include "sed.h"   */
-
-/* Imported functions */
-
-/***** public stuff ******/
-
-#define MAXCMDS		500	/* maximum number of compiled commands */
-#define MAXLINES	256	/* max # numeric addresses to compile */
-
-/* Main data areas */
-char linebuf[MAXBUF + 1];	/* current-line buffer */
-sedcmd cmds[MAXCMDS + 1];	/* hold compiled commands */
-long linenum[MAXLINES];		/* numeric-addresses table */
-
-/* Miscellaneous shared variables */
-int nflag;			/* -n option flag */
-int eargc;			/* scratch copy of argument count */
-char **eargv;			/* scratch copy of argument list */
-char bits[] = {1, 2, 4, 8, 16, 32, 64, 128};
-
-/***** module common stuff *****/
-
-#define POOLSIZE	20000	/* size of string-pool space */
-#define WFILES		10	/* max # w output files that can be compiled */
-#define RELIMIT		256	/* max chars in compiled RE */
-#define MAXDEPTH	20	/* maximum {}-nesting level */
-#define MAXLABS		50	/* max # of labels that can be handled */
-
-#define SKIPWS(pc)	while ((*pc==' ') || (*pc=='\t')) pc++
-#define ABORT(msg)	(fprintf(stderr, msg, linebuf), quit(2))
-#define IFEQ(x, v)	if (*x == v) x++ ,	/* do expression */
-
-/* Error messages */
-static char AGMSG[] = "sed: garbled address %s\n";
-static char CGMSG[] = "sed: garbled command %s\n";
-static char TMTXT[] = "sed: too much text: %s\n";
-static char AD1NG[] = "sed: no addresses allowed for %s\n";
-static char AD2NG[] = "sed: only one address allowed for %s\n";
-static char TMCDS[] = "sed: too many commands, last was %s\n";
-static char COCFI[] = "sed: cannot open command-file %s\n";
-static char UFLAG[] = "sed: unknown flag %c\n";
-static char CCOFI[] = "sed: cannot create %s\n";
-static char ULABL[] = "sed: undefined label %s\n";
-static char TMLBR[] = "sed: too many {'s\n";
-static char FRENL[] = "sed: first RE must be non-null\n";
-static char NSCAX[] = "sed: no such command as %s\n";
-static char TMRBR[] = "sed: too many }'s\n";
-static char DLABL[] = "sed: duplicate label %s\n";
-static char TMLAB[] = "sed: too many labels: %s\n";
-static char TMWFI[] = "sed: too many w files\n";
-static char REITL[] = "sed: RE too long: %s\n";
-static char TMLNR[] = "sed: too many line numbers\n";
-static char TRAIL[] = "sed: command \"%s\" has trailing garbage\n";
-
-typedef struct {		/* represent a command label */
-  char *name;			/* the label name */
-  sedcmd *last;			/* it's on the label search list */
-  sedcmd *address;		/* pointer to the cmd it labels */
-}
-
- label;
-
-/* Label handling */
-static label labels[MAXLABS];	/* here's the label table */
-static label *lab = labels + 1;	/* pointer to current label */
-static label *lablst = labels;	/* header for search list */
-
-/* String pool for regular expressions, append text, etc. etc. */
-static char pool[POOLSIZE];	/* the pool */
-static char *fp = pool;		/* current pool pointer */
-static char *poolend = pool + POOLSIZE;	/* pointer past pool end */
-
-/* Compilation state */
-static FILE *cmdf = NULL;	/* current command source */
-static char *cp = linebuf;	/* compile pointer */
-static sedcmd *cmdp = cmds;	/* current compiled-cmd ptr */
-static char *lastre = NULL;	/* old RE pointer */
-static int bdepth = 0;		/* current {}-nesting level */
-static int bcount = 0;		/* # tagged patterns in current RE */
-
-/* Compilation flags */
-static int eflag;		/* -e option flag */
-static int gflag;		/* -g option flag */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(static void compile, (void));
-_PROTOTYPE(static int cmdcomp, (int cchar));
-_PROTOTYPE(static char *rhscomp, (char *rhsp, int delim));
-_PROTOTYPE(static char *recomp, (char *expbuf, int redelim));
-_PROTOTYPE(static int cmdline, (char *cbuf));
-_PROTOTYPE(static char *address, (char *expbuf));
-_PROTOTYPE(static char *gettext, (char *txp));
-_PROTOTYPE(static label *search, (label *ptr));
-_PROTOTYPE(static void resolve, (void));
-_PROTOTYPE(static char *ycomp, (char *ep, int delim));
-_PROTOTYPE(void quit, (int n));
-_PROTOTYPE(void execute, (void));
-_PROTOTYPE(static int selected, (sedcmd *ipc));
-_PROTOTYPE(static int match, (char *expbuf, int gf));
-_PROTOTYPE(static int advance, (char *lp, char *ep));
-_PROTOTYPE(static int substitute, (sedcmd *ipc));
-_PROTOTYPE(static void dosub, (char *rhsbuf));
-_PROTOTYPE(static char *place, (char *asp, char *al1, char *al2));
-_PROTOTYPE(static void listto, (char *p1, FILE *fp));
-_PROTOTYPE(static void truncated, (int h));
-_PROTOTYPE(static void command, (sedcmd *ipc));
-_PROTOTYPE(static void openfile, (char *file));
-_PROTOTYPE(static void get, (void));
-_PROTOTYPE(static void initget, (void));
-_PROTOTYPE(static char *getline, (char *buf));
-_PROTOTYPE(static int Memcmp, (char *a, char *b, int count));
-_PROTOTYPE(static void readout, (void));
-
-int main(argc, argv)
-/* Main sequence of the stream editor */
-int argc;
-char *argv[];
-{
-  eargc = argc;			/* set local copy of argument count */
-  eargv = argv;			/* set local copy of argument list */
-  cmdp->addr1 = pool;		/* 1st addr expand will be at pool start */
-  if (eargc == 1) quit(0);	/* exit immediately if no arguments */
-  /* Scan through the arguments, interpreting each one */
-  while ((--eargc > 0) && (**++eargv == '-')) switch (eargv[0][1]) {
-	    case 'e':
-		eflag++;
-		compile();	/* compile with e flag on */
-		eflag = 0;
-		continue;	/* get another argument */
-	    case 'f':
-		if (eargc-- <= 0)	/* barf if no -f file */
-			quit(2);
-		if ((cmdf = fopen(*++eargv, "r")) == NULL) {
-			fprintf(stderr, COCFI, *eargv);
-			quit(2);
-		}
-		compile();	/* file is O.K., compile it */
-		fclose(cmdf);
-		continue;	/* go back for another argument */
-	    case 'g':
-		gflag++;	/* set global flag on all s cmds */
-		continue;
-	    case 'n':
-		nflag++;	/* no print except on p flag or w */
-		continue;
-	    default:
-		fprintf(stdout, UFLAG, eargv[0][1]);
-		continue;
-	}
-
-
-  if (cmdp == cmds) {		/* no commands have been compiled */
-	eargv--;
-	eargc++;
-	eflag++;
-	compile();
-	eflag = 0;
-	eargv++;
-	eargc--;
-  }
-  if (bdepth)			/* we have unbalanced squigglies */
-	ABORT(TMLBR);
-
-  lablst->address = cmdp;	/* set up header of label linked list */
-  resolve();			/* resolve label table indirections */
-  execute();			/* execute commands */
-  quit(0);			/* everything was O.K. if we got here */
-  return(0);
-}
-
-
-#define H	0x80		/* 128 bit, on if there's really code for
-			 * command */
-#define LOWCMD	56		/* = '8', lowest char indexed in cmdmask */
-
-/* Indirect through this to get command internal code, if it exists */
-static char cmdmask[] =
-{
- 0, 0, H, 0, 0, H + EQCMD, 0, 0,
- 0, 0, 0, 0, H + CDCMD, 0, 0, CGCMD,
- CHCMD, 0, 0, 0, 0, 0, CNCMD, 0,
- CPCMD, 0, 0, 0, H + CTCMD, 0, 0, H + CWCMD,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, H + ACMD, H + BCMD, H + CCMD, DCMD, 0, 0, GCMD,
- HCMD, H + ICMD, 0, 0, H + LCMD, 0, NCMD, 0,
- PCMD, H + QCMD, H + RCMD, H + SCMD, H + TCMD, 0, 0, H + WCMD,
- XCMD, H + YCMD, 0, H + BCMD, 0, H, 0, 0,
-};
-
-static void compile()
-/* Precompile sed commands out of a file */
-{
-  char ccode;
-
-
-  for (;;) {			/* main compilation loop */
-	if (*cp == '\0') {	/* get a new command line */
-		*linebuf = '\0';	/* K.H */
-		if (cmdline(cp = linebuf) < 0) break;
-	}
-	SKIPWS(cp);
-	if (*cp == '\0')	/* empty */
-		continue;
-	if (*cp == '#') {	/* comment */
-		while (*cp) ++cp;
-		continue;
-	}
-	if (*cp == ';') {	/* ; separates cmds */
-		cp++;
-		continue;
-	}
-
-	/* Compile first address */
-	if (fp > poolend)
-		ABORT(TMTXT);
-	else if ((fp = address(cmdp->addr1 = fp)) == BAD)
-		ABORT(AGMSG);
-
-	if (fp == cmdp->addr1) {/* if empty RE was found */
-		if (lastre)	/* if there was previous RE */
-			cmdp->addr1 = lastre;	/* use it */
-		else
-			ABORT(FRENL);
-	} else if (fp == NULL) {/* if fp was NULL */
-		fp = cmdp->addr1;	/* use current pool location */
-		cmdp->addr1 = NULL;
-	} else {
-		lastre = cmdp->addr1;
-		if (*cp == ',' || *cp == ';') {	/* there's 2nd addr */
-			cp++;
-			if (fp > poolend) ABORT(TMTXT);
-			fp = address(cmdp->addr2 = fp);
-			if (fp == BAD || fp == NULL) ABORT(AGMSG);
-			if (fp == cmdp->addr2)
-				cmdp->addr2 = lastre;
-			else
-				lastre = cmdp->addr2;
-		} else
-			cmdp->addr2 = NULL;	/* no 2nd address */
-	}
-	if (fp > poolend) ABORT(TMTXT);
-
-	SKIPWS(cp);		/* discard whitespace after address */
-	IFEQ(cp, '!') cmdp->flags.allbut = 1;
-
-	SKIPWS(cp);		/* get cmd char, range-check it */
-	if ((*cp < LOWCMD) || (*cp > '~')
-	    || ((ccode = cmdmask[*cp - LOWCMD]) == 0))
-		ABORT(NSCAX);
-
-	cmdp->command = ccode & ~H;	/* fill in command value */
-	if ((ccode & H) == 0)	/* if no compile-time code */
-		cp++;		/* discard command char */
-	else if (cmdcomp(*cp++))/* execute it; if ret = 1 */
-		continue;	/* skip next line read */
-
-	if (++cmdp >= cmds + MAXCMDS) ABORT(TMCDS);
-
-	SKIPWS(cp);		/* look for trailing stuff */
-	if (*cp != '\0' && *cp != ';' && *cp != '#') ABORT(TRAIL);
-  }
-}
-
-static int cmdcomp(cchar)
-/* Compile a single command */
-register char cchar;		/* character name of command */
-{
-  static sedcmd **cmpstk[MAXDEPTH];	/* current cmd stack for {} */
-  static char *fname[WFILES];	/* w file name pointers */
-  static FILE *fout[WFILES];	/* w file file ptrs */
-  static int nwfiles = 1;	/* count of open w files */
-  int i;			/* indexing dummy used in w */
-  sedcmd *sp1, *sp2;		/* temps for label searches */
-  label *lpt;
-  char redelim;			/* current RE delimiter */
-
-  fout[0] = stdout;
-  switch (cchar) {
-      case '{':			/* start command group */
-	cmdp->flags.allbut = !cmdp->flags.allbut;
-	cmpstk[bdepth++] = &(cmdp->u.link);
-	if (++cmdp >= cmds + MAXCMDS) ABORT(TMCDS);
-	return(1);
-
-      case '}':			/* end command group */
-	if (cmdp->addr1) ABORT(AD1NG);	/* no addresses allowed */
-	if (--bdepth < 0) ABORT(TMRBR);	/* too many right braces */
-	*cmpstk[bdepth] = cmdp;	/* set the jump address */
-	return(1);
-
-      case '=':			/* print current source line number */
-      case 'q':			/* exit the stream editor */
-	if (cmdp->addr2) ABORT(AD2NG);
-	break;
-
-      case ':':			/* label declaration */
-	if (cmdp->addr1) ABORT(AD1NG);	/* no addresses allowed */
-	fp = gettext(lab->name = fp);	/* get the label name */
-	if (lpt = search(lab)) {/* does it have a double? */
-		if (lpt->address) ABORT(DLABL);	/* yes, abort */
-	} else {		/* check that it doesn't overflow label table */
-		lab->last = NULL;
-		lpt = lab;
-		if (++lab >= labels + MAXLABS) ABORT(TMLAB);
-	}
-	lpt->address = cmdp;
-	return(1);
-
-      case 'b':			/* branch command */
-      case 't':			/* branch-on-succeed command */
-      case 'T':			/* branch-on-fail command */
-	SKIPWS(cp);
-	if (*cp == '\0') {	/* if branch is to start of cmds... */
-		/* Add current command to end of label last */
-		if (sp1 = lablst->last) {
-			while (sp2 = sp1->u.link) sp1 = sp2;
-			sp1->u.link = cmdp;
-		} else		/* lablst->last == NULL */
-			lablst->last = cmdp;
-		break;
-	}
-	fp = gettext(lab->name = fp);	/* else get label into pool */
-	if (lpt = search(lab)) {/* enter branch to it */
-		if (lpt->address)
-			cmdp->u.link = lpt->address;
-		else {
-			sp1 = lpt->last;
-			while (sp2 = sp1->u.link) sp1 = sp2;
-			sp1->u.link = cmdp;
-		}
-	} else {		/* matching named label not found */
-		lab->last = cmdp;	/* add the new label */
-		lab->address = NULL;	/* it's forward of here */
-		if (++lab >= labels + MAXLABS)	/* overflow if last */
-			ABORT(TMLAB);
-	}
-	break;
-
-      case 'a':			/* append text */
-      case 'i':			/* insert text */
-      case 'r':			/* read file into stream */
-	if (cmdp->addr2) ABORT(AD2NG);
-      case 'c':			/* change text */
-	if ((*cp == '\\') && (*++cp == '\n')) cp++;
-	fp = gettext(cmdp->u.lhs = fp);
-	break;
-
-      case 'D':			/* delete current line in hold space */
-	cmdp->u.link = cmds;
-	break;
-
-      case 's':			/* substitute regular expression */
-	redelim = *cp++;	/* get delimiter from 1st ch */
-	if ((fp = recomp(cmdp->u.lhs = fp, redelim)) == BAD) ABORT(CGMSG);
-	if (fp == cmdp->u.lhs)	/* if compiled RE zero len */
-		cmdp->u.lhs = lastre;	/* use the previous one */
-	else			/* otherwise */
-		lastre = cmdp->u.lhs;	/* save the one just found */
-	if ((cmdp->rhs = fp) > poolend) ABORT(TMTXT);
-	if ((fp = rhscomp(cmdp->rhs, redelim)) == BAD) ABORT(CGMSG);
-	if (gflag) cmdp->flags.global ++;
-	while (*cp == 'g' || *cp == 'p' || *cp == 'P') {
-		IFEQ(cp, 'g') cmdp->flags.global ++;
-		IFEQ(cp, 'p') cmdp->flags.print = 1;
-		IFEQ(cp, 'P') cmdp->flags.print = 2;
-	}
-
-      case 'l':			/* list pattern space */
-	if (*cp == 'w')
-		cp++;		/* and execute a w command! */
-	else
-		break;		/* s or l is done */
-
-      case 'w':			/* write-pattern-space command */
-      case 'W':			/* write-first-line command */
-	if (nwfiles >= WFILES) ABORT(TMWFI);
-	fp = gettext(fname[nwfiles] = fp);	/* filename will be in pool */
-	for (i = nwfiles - 1; i >= 0; i--)	/* match it in table */
-		if ((fname[i] != NULL) &&
-		    (strcmp(fname[nwfiles], fname[i]) == 0)) {
-			cmdp->fout = fout[i];
-			return(0);
-		}
-
-	/* If didn't find one, open new out file */
-	if ((cmdp->fout = fopen(fname[nwfiles], "w")) == NULL) {
-		fprintf(stderr, CCOFI, fname[nwfiles]);
-		quit(2);
-	}
-	fout[nwfiles++] = cmdp->fout;
-	break;
-
-      case 'y':			/* transliterate text */
-	fp = ycomp(cmdp->u.lhs = fp, *cp++);	/* compile translit */
-	if (fp == BAD) ABORT(CGMSG);	/* fail on bad form */
-	if (fp > poolend) ABORT(TMTXT);	/* fail on overflow */
-	break;
-  }
-  return(0);			/* succeeded in interpreting one command */
-}
-
-static char *rhscomp(rhsp, delim)	/* uses bcount */
- /* Generate replacement string for substitute command right hand side */
-register char *rhsp;		/* place to compile expression to */
-register char delim;		/* regular-expression end-mark to look for */
-{
-  register char *p = cp;	/* strictly for speed */
-
-  for (;;)
-	if ((*rhsp = *p++) == '\\') {	/* copy; if it's a \, */
-		*rhsp = *p++;	/* copy escaped char */
-		/* Check validity of pattern tag */
-		if (*rhsp > bcount + '0' && *rhsp <= '9') return(BAD);
-		*rhsp++ |= 0x80;/* mark the good ones */
-		continue;
-	} else if (*rhsp == delim) {	/* found RE end, hooray... */
-		*rhsp++ = '\0';	/* cap the expression string */
-		cp = p;
-		return(rhsp);	/* pt at 1 past the RE */
-	} else if (*rhsp++ == '\0')	/* last ch not RE end, help! */
-		return(BAD);
-}
-
-static char *recomp(expbuf, redelim)	/* uses cp, bcount */
- /* Compile a regular expression to internal form */
-char *expbuf;			/* place to compile it to */
-char redelim;			/* RE end-marker to look for */
-{
-  register char *ep = expbuf;	/* current-compiled-char pointer */
-  register char *sp = cp;	/* source-character ptr */
-  register int c;		/* current-character pointer */
-  char negclass;		/* all-but flag */
-  char *lastep;			/* ptr to last expr compiled */
-  char *svclass;		/* start of current char class */
-  char brnest[MAXTAGS];		/* bracket-nesting array */
-  char *brnestp;		/* ptr to current bracket-nest */
-  int classct;			/* class element count */
-  int tags;			/* # of closed tags */
-
-  if (*cp == redelim)		/* if first char is RE endmarker */
-	return(cp++, expbuf);	/* leave existing RE unchanged */
-
-  lastep = NULL;		/* there's no previous RE */
-  brnestp = brnest;		/* initialize ptr to brnest array */
-  tags = bcount = 0;		/* initialize counters */
-
-  if (*ep++ = (*sp == '^'))	/* check for start-of-line syntax */
-	sp++;
-
-  for (;;) {
-	if (ep >= expbuf + RELIMIT)	/* match is too large */
-		return(cp = sp, BAD);
-	if ((c = *sp++) == redelim) {	/* found the end of the RE */
-		cp = sp;
-		if (brnestp != brnest)	/* \(, \) unbalanced */
-			return(BAD);
-		*ep++ = CEOF;	/* write end-of-pattern mark */
-		return(ep);	/* return ptr to compiled RE */
-	}
-	if (c != '*')		/* if we're a postfix op */
-		lastep = ep;	/* get ready to match last */
-
-	switch (c) {
-	    case '\\':
-		if ((c = *sp++) == '(') {	/* start tagged section */
-			if (bcount >= MAXTAGS) return(cp = sp, BAD);
-			*brnestp++ = bcount;	/* update tag stack */
-			*ep++ = CBRA;	/* enter tag-start */
-			*ep++ = bcount++;	/* bump tag count */
-			continue;
-		} else if (c == ')') {	/* end tagged section */
-			if (brnestp <= brnest)	/* extra \) */
-				return(cp = sp, BAD);
-			*ep++ = CKET;	/* enter end-of-tag */
-			*ep++ = *--brnestp;	/* pop tag stack */
-			tags++;	/* count closed tags */
-			continue;
-		} else if (c >= '1' && c <= '9') {	/* tag use */
-			if ((c -= '1') >= tags)	/* too few */
-				return(BAD);
-			*ep++ = CBACK;	/* enter tag mark */
-			*ep++ = c;	/* and the number */
-			continue;
-		} else if (c == '\n')	/* escaped newline no good */
-			return(cp = sp, BAD);
-		else if (c == 'n')	/* match a newline */
-			c = '\n';
-		else if (c == 't')	/* match a tab */
-			c = '\t';
-		else if (c == 'r')	/* match a return */
-			c = '\r';
-		goto defchar;
-
-	    case '\0':		/* ignore nuls */
-		continue;
-
-	    case '\n':		/* trailing pattern delimiter is missing */
-		return(cp = sp, BAD);
-
-	    case '.':		/* match any char except newline */
-		*ep++ = CDOT;
-		continue;
-	    case '*':		/* 0..n repeats of previous pattern */
-		if (lastep == NULL)	/* if * isn't first on line */
-			goto defchar;	/* match a literal * */
-		if (*lastep == CKET)	/* can't iterate a tag */
-			return(cp = sp, BAD);
-		*lastep |= STAR;/* flag previous pattern */
-		continue;
-
-	    case '$':		/* match only end-of-line */
-		if (*sp != redelim)	/* if we're not at end of RE */
-			goto defchar;	/* match a literal $ */
-		*ep++ = CDOL;	/* insert end-symbol mark */
-		continue;
-
-	    case '[':		/* begin character set pattern */
-		if (ep + 17 >= expbuf + RELIMIT) ABORT(REITL);
-		*ep++ = CCL;	/* insert class mark */
-		if (negclass = ((c = *sp++) == '^')) c = *sp++;
-		svclass = sp;	/* save ptr to class start */
-		do {
-			if (c == '\0') ABORT(CGMSG);
-
-			/* Handle character ranges */
-			if (c == '-' && sp > svclass && *sp != ']')
-				for (c = sp[-2]; c < *sp; c++)
-					ep[c >> 3] |= bits[c & 7];
-
-			/* Handle escape sequences in sets */
-			if (c == '\\')
-				if ((c = *sp++) == 'n')
-					c = '\n';
-				else if (c == 't')
-					c = '\t';
-				else if (c == 'r')
-					c = '\r';
-
-			/* Enter (possibly translated) char in set */
-			ep[c >> 3] |= bits[c & 7];
-		} while
-			((c = *sp++) != ']');
-
-		/* Invert the bitmask if all-but was specified */
-		if (negclass) for (classct = 0; classct < 16; classct++)
-				ep[classct] ^= 0xFF;
-		ep[0] &= 0xFE;	/* never match ASCII 0 */
-		ep += 16;	/* advance ep past set mask */
-		continue;
-
-  defchar:			/* match literal character */
-	    default:		/* which is what we'd do by default */
-		*ep++ = CCHR;	/* insert character mark */
-		*ep++ = c;
-	}
-  }
-}
-
-static int cmdline(cbuf)	/* uses eflag, eargc, cmdf */
- /* Read next command from -e argument or command file */
-register char *cbuf;
-{
-  register int inc;		/* not char because must hold EOF */
-
-  *cbuf-- = 0;			/* so pre-increment points us at cbuf */
-
-  /* E command flag is on */
-  if (eflag) {
-	register char *p;	/* ptr to current -e argument */
-	static char *savep;	/* saves previous value of p */
-
-	if (eflag > 0) {	/* there are pending -e arguments */
-		eflag = -1;
-		if (eargc-- <= 0) quit(2);	/* if no arguments, barf */
-
-		/* Else transcribe next e argument into cbuf */
-		p = *++eargv;
-		while (*++cbuf = *p++)
-			if (*cbuf == '\\') {
-				if ((*++cbuf = *p++) == '\0')
-					return(savep = NULL, -1);
-				else
-					continue;
-			} else if (*cbuf == '\n') {	/* end of 1 cmd line */
-				*cbuf = '\0';
-				return(savep = p, 1);
-				/* We'll be back for the rest... */
-			}
-
-		/* Found end-of-string; can advance to next argument */
-		return(savep = NULL, 1);
-	}
-	if ((p = savep) == NULL) return(-1);
-
-	while (*++cbuf = *p++)
-		if (*cbuf == '\\') {
-			if ((*++cbuf = *p++) == '0')
-				return(savep = NULL, -1);
-			else
-				continue;
-		} else if (*cbuf == '\n') {
-			*cbuf = '\0';
-			return(savep = p, 1);
-		}
-	return(savep = NULL, 1);
-  }
-
-  /* If no -e flag read from command file descriptor */
-  while ((inc = getc(cmdf)) != EOF)	/* get next char */
-	if ((*++cbuf = inc) == '\\')	/* if it's escape */
-		*++cbuf = inc = getc(cmdf);	/* get next char */
-	else if (*cbuf == '\n')	/* end on newline */
-		return(*cbuf = '\0', 1);	/* cap the string */
-
-  return(*++cbuf = '\0', -1);	/* end-of-file, no more chars */
-}
-
-static char *address(expbuf)	/* uses cp, linenum */
- /* Expand an address at *cp... into expbuf, return ptr at following char */
-register char *expbuf;
-{
-  static int numl = 0;		/* current ind in addr-number table */
-  register char *rcp;		/* temp compile ptr for forwd look */
-  long lno;			/* computed value of numeric address */
-
-  if (*cp == '$') {		/* end-of-source address */
-	*expbuf++ = CEND;	/* write symbolic end address */
-	*expbuf++ = CEOF;	/* and the end-of-address mark (!) */
-	cp++;			/* go to next source character */
-	return(expbuf);	/* we're done */
-  }
-  if (*cp == '/' || *cp == '\\') { /* start of regular-expression match */
-	if (*cp == '\\') cp++;
-	return(recomp(expbuf, *cp++));	/* compile the RE */
-  }
-
-  rcp = cp;
-  lno = 0;			/* now handle a numeric address */
-  while (*rcp >= '0' && *rcp <= '9')	/* collect digits */
-	lno = lno * 10 + *rcp++ - '0';	/* compute their value */
-
-  if (rcp > cp) {		/* if we caught a number... */
-	*expbuf++ = CLNUM;	/* put a numeric-address marker */
-	*expbuf++ = numl;	/* and the address table index */
-	linenum[numl++] = lno;	/* and set the table entry */
-	if (numl >= MAXLINES)	/* oh-oh, address table overflow */
-		ABORT(TMLNR);	/* abort with error message */
-	*expbuf++ = CEOF;	/* write the end-of-address marker */
-	cp = rcp;		/* point compile past the address */
-	return(expbuf);	/* we're done */
-  }
-  return(NULL);			/* no legal address was found */
-}
-
-static char *gettext(txp)	/* uses global cp */
- /* Accept multiline input from *cp..., discarding leading whitespace */
-register char *txp;		/* where to put the text */
-{
-  register char *p = cp;	/* this is for speed */
-
-  SKIPWS(p);			/* discard whitespace */
-  do {
-	if ((*txp = *p++) == '\\')	/* handle escapes */
-		*txp = *p++;
-	if (*txp == '\0')	/* we're at end of input */
-		return(cp = --p, ++txp);
-	else if (*txp == '\n')	/* also SKIPWS after newline */
-		SKIPWS(p);
-  } while
-	(txp++);		/* keep going till we find that nul */
-  return(txp);
-}
-
-static label *search(ptr)	/* uses global lablst */
- /* Find the label matching *ptr, return NULL if none */
-register label *ptr;
-{
-  register label *rp;
-  for (rp = lablst; rp < ptr; rp++)
-	if ((rp->name != NULL) && (strcmp(rp->name, ptr->name) == 0))
-		return(rp);
-  return(NULL);
-}
-
-static void resolve()
-{				/* uses global lablst */
-  /* Write label links into the compiled-command space */
-  register label *lptr;
-  register sedcmd *rptr, *trptr;
-
-  /* Loop through the label table */
-  for (lptr = lablst; lptr < lab; lptr++)
-	if (lptr->address == NULL) {	/* barf if not defined */
-		fprintf(stderr, ULABL, lptr->name);
-		quit(2);
-	} else if (lptr->last) {/* if last is non-null */
-		rptr = lptr->last;	/* chase it */
-		while (trptr = rptr->u.link) {	/* resolve refs */
-			rptr->u.link = lptr->address;
-			rptr = trptr;
-		}
-		rptr->u.link = lptr->address;
-	}
-}
-
-static char *ycomp(ep, delim)
-/* Compile a y (transliterate) command */
-register char *ep;		/* where to compile to */
-char delim;			/* end delimiter to look for */
-{
-  register char *tp, *sp;
-  register int c;
-
-  /* Scan the 'from' section for invalid chars */
-  for (sp = tp = cp; *tp != delim; tp++) {
-	if (*tp == '\\') tp++;
-	if ((*tp == '\n') || (*tp == '\0')) return (BAD);
-  }
-  tp++;				/* tp now points at first char of 'to'
-			 * section */
-
-  /* Now rescan the 'from' section */
-  while ((c = *sp++ & 0x7F) != delim) {
-	if (c == '\\' && *sp == 'n') {
-		sp++;
-		c = '\n';
-	}
-	if ((ep[c] = *tp++) == '\\' && *tp == 'n') {
-		ep[c] = '\n';
-		tp++;
-	}
-	if ((ep[c] == delim) || (ep[c] == '\0')) return(BAD);
-  }
-
-  if (*tp != delim)		/* 'to', 'from' parts have unequal lengths */
-	return(BAD);
-
-  cp = ++tp;			/* point compile ptr past translit */
-
-  for (c = 0; c < 128; c++)	/* fill in self-map entries in table */
-	if (ep[c] == 0) ep[c] = c;
-
-  return(ep + 0x80);		/* return first free location past table end */
-}
-
-void quit(n)
-int n;
-{
-/* Flush buffers and exit.  Now a historical relic.  Rely on exit to flush
- * the buffers.
- */
-  exit(n);
-}
-
-/*+++++++++++++++*/
-
-/*
-   sedexec.c -- execute compiled form of stream editor commands
-
-   The single entry point of this module is the function execute(). It
-   may take a string argument (the name of a file to be used as text)  or
-   the argument NULL which tells it to filter standard input. It executes
-   the compiled commands in cmds[] on each line in turn.
-
-   The function command() does most of the work. Match() and advance()
-   are used for matching text against precompiled regular expressions and
-   dosub() does right-hand-side substitution.  Getline() does text input;
-   readout() and Memcmp() are output and string-comparison utilities.
-*/
-
-/* #include <stdio.h>	*/
-/* #include <ctype.h>	*/
-/* #include "sed.h"	*/
-
-/***** shared variables imported from the main ******/
-
-/* Main data areas */
-extern char linebuf[];		/* current-line buffer */
-extern sedcmd cmds[];		/* hold compiled commands */
-extern long linenum[];		/* numeric-addresses table */
-
-/* Miscellaneous shared variables */
-extern int nflag;		/* -n option flag */
-extern int eargc;		/* scratch copy of argument count */
-extern char **eargv;		/* scratch copy of argument list */
-extern char bits[];		/* the bits table */
-
-/***** end of imported stuff *****/
-
-#define MAXHOLD	 MAXBUF		/* size of the hold space */
-#define GENSIZ	 MAXBUF		/* maximum genbuf size */
-
-#define TRUE	 1
-#define FALSE	 0
-
-static char LTLMSG[] = "sed: line too long\n";
-
-static char *spend;		/* current end-of-line-buffer pointer */
-static long lnum = 0L;		/* current source line number */
-
-/* Append buffer maintenance */
-static sedcmd *appends[MAXAPPENDS];	/* array of ptrs to a,i,c commands */
-static sedcmd **aptr = appends;	/* ptr to current append */
-
-/* Genbuf and its pointers */
-static char genbuf[GENSIZ];
-static char *loc1;
-static char *loc2;
-static char *locs;
-
-/* Command-logic flags */
-static int lastline;		/* do-line flag */
-static int jump;		/* jump to cmd's link address if set */
-static int delete;		/* delete command flag */
-
-/* Tagged-pattern tracking */
-static char *bracend[MAXTAGS];	/* tagged pattern start pointers */
-static char *brastart[MAXTAGS];	/* tagged pattern end pointers */
-
-static int anysub;		/* true if any s on current line succeeded */
-
-
-void execute()
-/* Execute the compiled commands in cmds[] */
-{
-  register char *p1;		/* dummy copy ptrs */
-  register sedcmd *ipc;		/* ptr to current command */
-  char *execp;			/* ptr to source */
-
-
-  initget();
-
-  /* Here's the main command-execution loop */
-  for (;;) {
-
-	/* Get next line to filter */
-	if ((execp = getline(linebuf)) == BAD) return;
-	spend = execp;
-	anysub = FALSE;
-
-	/* Loop through compiled commands, executing them */
-	for (ipc = cmds; ipc->command;) {
-		if (!selected(ipc)) {
-			ipc++;
-			continue;
-		}
-		command(ipc);	/* execute the command pointed at */
-
-		if (delete)	/* if delete flag is set */
-			break;	/* don't exec rest of compiled cmds */
-
-		if (jump) {	/* if jump set, follow cmd's link */
-			jump = FALSE;
-			if ((ipc = ipc->u.link) == 0) {
-				ipc = cmds;
-				break;
-			}
-		} else		/* normal goto next command */
-			ipc++;
-	}
-
-	/* We've now done all modification commands on the line */
-
-	/* Here's where the transformed line is output */
-	if (!nflag && !delete) {
-		for (p1 = linebuf; p1 < spend; p1++) putc(*p1, stdout);
-		putc('\n', stdout);
-	}
-
-	/* If we've been set up for append, emit the text from it */
-	if (aptr > appends) readout();
-
-	delete = FALSE;		/* clear delete flag; about to get next cmd */
-  }
-}
-
-static int selected(ipc)
-/* Is current command selected */
-sedcmd *ipc;
-{
-  register char *p1 = ipc->addr1;	/* point p1 at first address */
-  register char *p2 = ipc->addr2;	/* and p2 at second */
-  int c;
-  int sel = TRUE;		/* select by default */
-
-  if (!p1)			/* No addresses: always selected */
-	;
-  else if (ipc->flags.inrange) {
-	if (*p2 == CEND);
-	else if (*p2 == CLNUM) {
-		c = p2[1] & CMASK;
-		if (lnum >= linenum[c]) {
-			ipc->flags.inrange = FALSE;
-			if (lnum > linenum[c]) sel = FALSE;
-		}
-	} else if (match(p2, 0))
-		ipc->flags.inrange = FALSE;
-  } else if (*p1 == CEND) {
-	if (!lastline) sel = FALSE;
-  } else if (*p1 == CLNUM) {
-	c = p1[1] & CMASK;
-	if (lnum != linenum[c])
-		sel = FALSE;
-	else if (p2)
-		ipc->flags.inrange = TRUE;
-  } else if (match(p1, 0)) {
-	if (p2) ipc->flags.inrange = TRUE;
-  } else
-	sel = FALSE;
-
-  return ipc->flags.allbut ? !sel : sel;
-}
-
-static int match(expbuf, gf)	/* uses genbuf */
- /* Match RE at expbuf against linebuf; if gf set, copy linebuf from genbuf */
-char *expbuf;
-int gf;
-{
-  register char *p1, *p2, c;
-
-  if (gf) {
-	if (*expbuf) return(FALSE);
-	p1 = linebuf;
-	p2 = genbuf;
-	while (*p1++ = *p2++);
-	locs = p1 = loc2;
-  } else {
-	p1 = linebuf;
-	locs = FALSE;
-  }
-
-  p2 = expbuf;
-  if (*p2++) {
-	loc1 = p1;
-	if (*p2 == CCHR && p2[1] != *p1)	/* 1st char is wrong */
-		return(FALSE);	/* so fail */
-	return(advance(p1, p2));/* else try to match rest */
-  }
-
-  /* Quick check for 1st character if it's literal */
-  if (*p2 == CCHR) {
-	c = p2[1];		/* pull out character to search for */
-	do {
-		if (*p1 != c) continue;	/* scan the source string */
-		if (advance(p1, p2))	/* found it, match the rest */
-			return(loc1 = p1, 1);
-	} while
-		(*p1++);
-	return(FALSE);		/* didn't find that first char */
-  }
-
-  /* Else try for unanchored match of the pattern */
-  do {
-	if (advance(p1, p2)) return(loc1 = p1, 1);
-  } while
-	(*p1++);
-
-  /* If got here, didn't match either way */
-  return(FALSE);
-}
-
-static int advance(lp, ep)
-/* Attempt to advance match pointer by one pattern element */
-register char *lp;		/* source (linebuf) ptr */
-register char *ep;		/* regular expression element ptr */
-{
-  register char *curlp;		/* save ptr for closures */
-  char c;			/* scratch character holder */
-  char *bbeg;
-  int ct;
-
-  for (;;) switch (*ep++) {
-	    case CCHR:		/* literal character */
-		if (*ep++ == *lp++)	/* if chars are equal */
-			continue;	/* matched */
-		return(FALSE);	/* else return false */
-
-	    case CDOT:		/* anything but newline */
-		if (*lp++)	/* first NUL is at EOL */
-			continue;	/* keep going if didn't find */
-		return(FALSE);	/* else return false */
-
-	    case CNL:		/* start-of-line */
-	    case CDOL:		/* end-of-line */
-		if (*lp == 0)	/* found that first NUL? */
-			continue;	/* yes, keep going */
-		return(FALSE);	/* else return false */
-
-	    case CEOF:		/* end-of-address mark */
-		loc2 = lp;	/* set second loc */
-		return(TRUE);	/* return true */
-
-	    case CCL:		/* a closure */
-		c = *lp++ & 0177;
-		if (ep[c >> 3] & bits[c & 07]) {	/* is char in set? */
-			ep += 16;	/* then skip rest of bitmask */
-			continue;	/* and keep going */
-		}
-		return(FALSE);	/* else return false */
-
-	    case CBRA:		/* start of tagged pattern */
-		brastart[*ep++] = lp;	/* mark it */
-		continue;	/* and go */
-
-	    case CKET:		/* end of tagged pattern */
-		bracend[*ep++] = lp;	/* mark it */
-		continue;	/* and go */
-
-	    case CBACK:
-		bbeg = brastart[*ep];
-		ct = bracend[*ep++] - bbeg;
-
-		if (Memcmp(bbeg, lp, ct)) {
-			lp += ct;
-			continue;
-		}
-		return(FALSE);
-
-	    case CBACK | STAR:
-		bbeg = brastart[*ep];
-		ct = bracend[*ep++] - bbeg;
-		curlp = lp;
-		while (Memcmp(bbeg, lp, ct)) lp += ct;
-
-		while (lp >= curlp) {
-			if (advance(lp, ep)) return(TRUE);
-			lp -= ct;
-		}
-		return(FALSE);
-
-
-	    case CDOT | STAR:	/* match .* */
-		curlp = lp;	/* save closure start loc */
-		while (*lp++);	/* match anything */
-		goto star;	/* now look for followers */
-
-	    case CCHR | STAR:	/* match <literal char>* */
-		curlp = lp;	/* save closure start loc */
-		while (*lp++ == *ep);	/* match many of that char */
-		ep++;		/* to start of next element */
-		goto star;	/* match it and followers */
-
-	    case CCL | STAR:	/* match [...]* */
-		curlp = lp;	/* save closure start loc */
-		do {
-			c = *lp++ & 0x7F;	/* match any in set */
-		} while
-			(ep[c >> 3] & bits[c & 07]);
-		ep += 16;	/* skip past the set */
-		goto star;	/* match followers */
-
-  star:				/* the recursion part of a * or + match */
-		if (--lp == curlp)	/* 0 matches */
-			continue;
-
-		if (*ep == CCHR) {
-			c = ep[1];
-			do {
-				if (*lp != c) continue;
-				if (advance(lp, ep)) return (TRUE);
-			} while
-				(lp-- > curlp);
-			return(FALSE);
-		}
-		if (*ep == CBACK) {
-			c = *(brastart[ep[1]]);
-			do {
-				if (*lp != c) continue;
-				if (advance(lp, ep)) return (TRUE);
-			} while
-				(lp-- > curlp);
-			return(FALSE);
-		}
-		do {
-			if (lp == locs) break;
-			if (advance(lp, ep)) return (TRUE);
-		} while
-			(lp-- > curlp);
-		return(FALSE);
-
-	    default:
-		fprintf(stderr, "sed: RE error, %o\n", *--ep);
-		quit(2);
-	}
-}
-
-static int substitute(ipc)
-/* Perform s command */
-sedcmd *ipc;			/* ptr to s command struct */
-{
-  int nullmatch;
-
-  if (match(ipc->u.lhs, 0)) {	/* if no match */
-	nullmatch = (loc1 == loc2);
-	dosub(ipc->rhs);	/* perform it once */
-  } else
-	return(FALSE);		/* command fails */
-
-  if (ipc->flags.global)	/* if global flag enabled */
-	while (*loc2) {		/* cycle through possibles */
-		if (nullmatch) loc2++;
-		if (match(ipc->u.lhs, 1)) {	/* found another */
-			nullmatch = (loc1 == loc2);
-			dosub(ipc->rhs);	/* so substitute */
-		} else		/* otherwise, */
-			break;	/* we're done */
-	}
-  return(TRUE);			/* we succeeded */
-}
-
-static void dosub(rhsbuf)	/* uses linebuf, genbuf, spend */
- /* Generate substituted right-hand side (of s command) */
-char *rhsbuf;			/* where to put the result */
-{
-  register char *lp, *sp, *rp;
-  int c;
-
-  /* Copy linebuf to genbuf up to location  1 */
-  lp = linebuf;
-  sp = genbuf;
-  while (lp < loc1) *sp++ = *lp++;
-
-  for (rp = rhsbuf; c = *rp++;) {
-	if (c == '&') {
-		sp = place(sp, loc1, loc2);
-		continue;
-	} else if (c & 0200 && (c &= 0177) >= '1' && c < MAXTAGS + '1') {
-		sp = place(sp, brastart[c - '1'], bracend[c - '1']);
-		continue;
-	}
-	*sp++ = c & 0177;
-	if (sp >= genbuf + MAXBUF) fprintf(stderr, LTLMSG);
-  }
-  lp = loc2;
-  loc2 = sp - genbuf + linebuf;
-  while (*sp++ = *lp++)
-	if (sp >= genbuf + MAXBUF) fprintf(stderr, LTLMSG);
-  lp = linebuf;
-  sp = genbuf;
-  while (*lp++ = *sp++);
-  spend = lp - 1;
-}
-
-static char *place(asp, al1, al2)	/* uses genbuf */
- /* Place chars at *al1...*(al1 - 1) at asp... in genbuf[] */
-register char *asp, *al1, *al2;
-{
-  while (al1 < al2) {
-	*asp++ = *al1++;
-	if (asp >= genbuf + MAXBUF) fprintf(stderr, LTLMSG);
-  }
-  return(asp);
-}
-
-static void listto(p1, fp)
-/* Write a hex dump expansion of *p1... to fp */
-register char *p1;		/* the source */
-FILE *fp;			/* output stream to write to */
-{
-  p1--;
-  while (*p1++)
-	if (isprint(*p1))
-		putc(*p1, fp);	/* pass it through */
-	else {
-		putc('\\', fp);	/* emit a backslash */
-		switch (*p1) {
-		    case '\b':
-			putc('b', fp);
-			break;	/* BS */
-		    case '\t':
-			putc('t', fp);
-			break;	/* TAB */
-		    case '\n':
-			putc('n', fp);
-			break;	/* NL */
-		    case '\r':
-			putc('r', fp);
-			break;	/* CR */
-		    case '\33':
-			putc('e', fp);
-			break;	/* ESC */
-		    default:
-			fprintf(fp, "%02x", *p1 & 0xFF);
-		}
-	}
-  putc('\n', fp);
-}
-
-static void truncated(h)
-int h;
-{
-  static long last = 0L;
-
-  if (lnum == last) return;
-  last = lnum;
-
-  fprintf(stderr, "sed: ");
-  fprintf(stderr, h ? "hold space" : "line %ld", lnum);
-  fprintf(stderr, " truncated to %d characters\n", MAXBUF);
-}
-
-static void command(ipc)
-/* Execute compiled command pointed at by ipc */
-sedcmd *ipc;
-{
-  static char holdsp[MAXHOLD + 1];	/* the hold space */
-  static char *hspend = holdsp;	/* hold space end pointer */
-  register char *p1, *p2;
-  char *execp;
-  int didsub;			/* true if last s succeeded */
-
-  switch (ipc->command) {
-      case ACMD:		/* append */
-	*aptr++ = ipc;
-	if (aptr >= appends + MAXAPPENDS) fprintf(stderr,
-			"sed: too many appends after line %ld\n",
-			lnum);
-	*aptr = 0;
-	break;
-
-      case CCMD:		/* change pattern space */
-	delete = TRUE;
-	if (!ipc->flags.inrange || lastline) printf("%s\n", ipc->u.lhs);
-	break;
-
-      case DCMD:		/* delete pattern space */
-	delete++;
-	break;
-
-      case CDCMD:		/* delete a line in hold space */
-	p1 = p2 = linebuf;
-	while (*p1 != '\n')
-		if (delete = (*p1++ == 0)) return;
-	p1++;
-	while (*p2++ = *p1++) continue;
-	spend = p2 - 1;
-	jump++;
-	break;
-
-      case EQCMD:		/* show current line number */
-	fprintf(stdout, "%ld\n", lnum);
-	break;
-
-      case GCMD:		/* copy hold space to pattern space */
-	p1 = linebuf;
-	p2 = holdsp;
-	while (*p1++ = *p2++);
-	spend = p1 - 1;
-	break;
-
-      case CGCMD:		/* append hold space to pattern space */
-	*spend++ = '\n';
-	p1 = spend;
-	p2 = holdsp;
-	do
-		if (p1 > linebuf + MAXBUF) {
-			truncated(0);
-			p1[-1] = 0;
-			break;
-		}
-	while (*p1++ = *p2++);
-
-	spend = p1 - 1;
-	break;
-
-      case HCMD:		/* copy pattern space to hold space */
-	p1 = holdsp;
-	p2 = linebuf;
-	while (*p1++ = *p2++);
-	hspend = p1 - 1;
-	break;
-
-      case CHCMD:		/* append pattern space to hold space */
-	*hspend++ = '\n';
-	p1 = hspend;
-	p2 = linebuf;
-	do
-		if (p1 > holdsp + MAXBUF) {
-			truncated(1);
-			p1[-1] = 0;
-			break;
-		}
-	while (*p1++ = *p2++);
-
-	hspend = p1 - 1;
-	break;
-
-      case ICMD:		/* insert text */
-	printf("%s\n", ipc->u.lhs);
-	break;
-
-      case BCMD:		/* branch to label */
-	jump = TRUE;
-	break;
-
-      case LCMD:		/* list text */
-	listto(linebuf, (ipc->fout != NULL) ? ipc->fout : stdout);
-	break;
-
-      case NCMD:		/* read next line into pattern space */
-	if (!nflag) puts(linebuf);	/* flush out the current line */
-	if (aptr > appends) readout();	/* do pending a, r commands */
-	if ((execp = getline(linebuf)) == BAD) {
-		delete = TRUE;
-		break;
-	}
-	spend = execp;
-	anysub = FALSE;
-	break;
-
-      case CNCMD:		/* append next line to pattern space */
-	if (aptr > appends) readout();
-	*spend++ = '\n';
-	if ((execp = getline(spend)) == BAD) {
-		*--spend = 0;
-		break;
-	}
-	spend = execp;
-	anysub = FALSE;
-	break;
-
-      case PCMD:		/* print pattern space */
-	puts(linebuf);
-	break;
-
-      case CPCMD:		/* print one line from pattern space */
-cpcom:				/* so s command can jump here */
-	for (p1 = linebuf; *p1 != '\n' && *p1 != '\0';) putc(*p1++, stdout);
-	putc('\n', stdout);
-	break;
-
-      case QCMD:		/* quit the stream editor */
-	if (!nflag) puts(linebuf);	/* flush out the current line */
-	if (aptr > appends)
-		readout();	/* do any pending a and r commands */
-	quit(0);
-
-      case RCMD:		/* read a file into the stream */
-	*aptr++ = ipc;
-	if (aptr >= appends + MAXAPPENDS) fprintf(stderr,
-			"sed: too many reads after line %ld\n",
-			lnum);
-	*aptr = 0;
-	break;
-
-      case SCMD:		/* substitute RE */
-	didsub = substitute(ipc);
-	if (didsub) anysub = TRUE;
-	if (ipc->flags.print && didsub)
-		if (ipc->flags.print == TRUE)
-			puts(linebuf);
-		else
-			goto cpcom;
-	if (didsub && ipc->fout) fprintf(ipc->fout, "%s\n", linebuf);
-	break;
-
-      case TCMD:		/* branch on any s successful */
-      case CTCMD:		/* branch on any s failed */
-	if (anysub == (ipc->command == CTCMD))
-		break;		/* no branch if any s failed, else */
-	anysub = FALSE;
-	jump = TRUE;		/* set up to jump to assoc'd label */
-	break;
-
-      case CWCMD:		/* write one line from pattern space */
-	for (p1 = linebuf; *p1 != '\n' && *p1 != '\0';)
-		putc(*p1++, ipc->fout);
-	putc('\n', ipc->fout);
-	break;
-
-      case WCMD:		/* write pattern space to file */
-	fprintf(ipc->fout, "%s\n", linebuf);
-	break;
-
-      case XCMD:		/* exchange pattern and hold spaces */
-	p1 = linebuf;
-	p2 = genbuf;
-	while (*p2++ = *p1++) continue;
-	p1 = holdsp;
-	p2 = linebuf;
-	while (*p2++ = *p1++) continue;
-	spend = p2 - 1;
-	p1 = genbuf;
-	p2 = holdsp;
-	while (*p2++ = *p1++) continue;
-	hspend = p2 - 1;
-	break;
-
-      case YCMD:
-	p1 = linebuf;
-	p2 = ipc->u.lhs;
-	while (*p1 = p2[*p1]) p1++;
-	break;
-  }
-}
-
-static void openfile(file)
-char *file;
-/* Replace stdin by given file */
-{
-  if (freopen(file, "r", stdin) == NULL) {
-	fprintf(stderr, "sed: can't open %s\n", file);
-	quit(1);
-  }
-}
-
-static int c;			/* Will be the next char to read, a kind of
-			 * lookahead */
-
-static void get()
-/* Read next character into c treating all argument files as run through cat */
-{
-  while ((c = getchar()) == EOF && --eargc >= 0) openfile(*eargv++);
-}
-
-static void initget()
-/* Initialise character input */
-{
-  if (--eargc >= 0) openfile(*eargv++);	/* else input == stdin */
-  get();
-}
-
-static char *getline(buf)
-/* Get next line of text to be edited, return pointer to end */
-register char *buf;		/* where to send the input */
-{
-  if (c == EOF) return BAD;
-
-  lnum++;			/* we can read a new line */
-
-  do {
-	if (c == '\n') {
-		get();
-		break;
-	}
-	if (buf <= linebuf + MAXBUF) *buf++ = c;
-	get();
-  } while (c != EOF);
-
-  if (c == EOF) lastline = TRUE;
-
-  if (buf > linebuf + MAXBUF) {
-	truncated(0);
-	--buf;
-  }
-  *buf = 0;
-  return buf;
-}
-
-static int Memcmp(a, b, count)
-/* Return TRUE if *a... == *b... for count chars, FALSE otherwise */
-register char *a, *b;
-int count;
-{
-  while (count--)		/* look at count characters */
-	if (*a++ != *b++)	/* if any are nonequal	 */
-		return(FALSE);	/* return FALSE for false */
-  return(TRUE);			/* compare succeeded */
-}
-
-static void readout()
-/* Write file indicated by r command to output */
-{
-  register int t;		/* hold input char or EOF */
-  FILE *fi;			/* ptr to file to be read */
-
-  aptr = appends - 1;		/* arrange for pre-increment to work right */
-  while (*++aptr)
-	if ((*aptr)->command == ACMD)	/* process "a" cmd */
-		printf("%s\n", (*aptr)->u.lhs);
-	else {			/* process "r" cmd */
-		if ((fi = fopen((*aptr)->u.lhs, "r")) == NULL) {
-			fprintf(stderr, "sed: can't open %s\n",
-				(*aptr)->u.lhs);
-			continue;
-		}
-		while ((t = getc(fi)) != EOF) putc((char) t, stdout);
-		fclose(fi);
-	}
-  aptr = appends;		/* reset the append ptr */
-  *aptr = 0;
-}
-
-/* Sedexec.c ends here */
Index: trunk/minix/commands/simple/shar.c
===================================================================
--- trunk/minix/commands/simple/shar.c	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-/* shar - make a shell archive		Author: Michiel Husijes */
-
-#include <stdlib.h>		/* for the nonstd :-( _PROTOTYPE */
-#include <stdio.h>
-
-static _PROTOTYPE( void error, (char *progname, char *operation,
-				char *filename) );
-_PROTOTYPE( int main, (int argc, char **argv) );
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int argn;
-  register int ch;
-  register FILE *fp;
-  int exitstatus;
-  char *filename;
-
-  exitstatus = 0;
-  for (argn = 1; argn < argc; argn++) {
-	filename = argv[argn];
-	if ((fp = fopen(filename, "r")) == NULL) {
-		error(argv[0], "opening ", filename);
-		exitstatus = 1;
-	} else {
-		fputs("echo x - ", stdout);
-		fputs(filename, stdout);
-		fputs("\nsed '/^X/s///' > ", stdout);
-		fputs(filename, stdout);
-		fputs(" << '/'\n", stdout);
-		while ((ch = getc(fp)) != EOF) {
-			putchar('X');
-			putchar(ch);
-			while (ch != '\n') {
-				ch = getc(fp);
-				if (ch == EOF) break;
-				putchar(ch);
-			}
-			if (ch == EOF) break;
-		}
-		fputs("/\n", stdout);
-		if (ferror(fp)) {
-			error(argv[0], "reading ", filename);
-			exitstatus = 1;
-		}
-		if (fclose(fp) != 0) {
-			error(argv[0], "closing ", filename);
-			exitstatus = 1;
-		}
-		if (ferror(stdout)) break;	/* lost already */
-	}
-  }
-  fflush(stdout);
-  if (ferror(stdout)) {
-	error(argv[0], "writing ", "stdout");
-	exitstatus = 1;
-  }
-  return(exitstatus);
-}
-
-static void error(progname, operation, filename)
-char *progname;
-char *operation;
-char *filename;
-{
-  fputs(progname, stderr);
-  fputs(": error ", stderr);
-  fputs(operation, stderr);
-  perror(filename);
-}
Index: trunk/minix/commands/simple/size.c
===================================================================
--- trunk/minix/commands/simple/size.c	(revision 9)
+++ 	(revision )
@@ -1,64 +1,0 @@
-/* size - tell size of an object file		Author: Andy Tanenbaum */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <a.out.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-
-int heading;			/* set when heading printed */
-int error;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void size, (char *name));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int i;
-
-  if (argc == 1) {
-	size("a.out");
-	exit(error);
-  }
-  for (i = 1; i < argc; i++) size(argv[i]);
-  return(error);
-}
-
-
-
-void size(name)
-char *name;
-{
-  int fd, separate;
-  long dynam, allmem;
-  struct exec exec;
-
-  if ((fd = open(name, O_RDONLY)) < 0) {
-	fprintf(stderr, "size: can't open %s\n", name);
-	error = 1;
-	return;
-  }
-  if (read(fd, (char *)&exec, sizeof(struct exec)) != sizeof(struct exec)) {
-	fprintf(stderr, "size: %s: header too short\n", name);
-	error = 1;
-	close(fd);
-	return;
-  }
-  if (BADMAG(exec)) {
-	fprintf(stderr, "size: %s not an object file\n", name);
-	error = 1;
-	close(fd);
-	return;
-  }
-  separate = (exec.a_flags & A_SEP ? 1 : 0);
-  dynam = exec.a_total - exec.a_text - exec.a_data - exec.a_bss;
-  if (separate) dynam += exec.a_text;
-  allmem = (separate ? exec.a_total + exec.a_text : exec.a_total);
-  if (heading++ == 0) printf("   text    data     bss    stack   memory\n");
-  printf("%7ld %7ld %7ld %8ld %8ld  %s\n",
-         exec.a_text, exec.a_data, exec.a_bss, dynam, allmem, name);
-  close(fd);
-}
Index: trunk/minix/commands/simple/sleep.c
===================================================================
--- trunk/minix/commands/simple/sleep.c	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-/* sleep - suspend a process for x sec		Author: Andy Tanenbaum */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <minix/minlib.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  register seconds;
-  register char c;
-
-  seconds = 0;
-
-  if (argc != 2) {
-	std_err("Usage: sleep time\n");
-	exit(1);
-  }
-  while (c = *(argv[1])++) {
-	if (c < '0' || c > '9') {
-		std_err("sleep: bad arg\n");
-		exit(1);
-	}
-	seconds = 10 * seconds + (c - '0');
-  }
-
-  /* Now sleep. */
-  sleep(seconds);
-  return(0);
-}
Index: trunk/minix/commands/simple/slip.c
===================================================================
--- trunk/minix/commands/simple/slip.c	(revision 9)
+++ 	(revision )
@@ -1,323 +1,0 @@
-/*	slip 1.1 - Serial line IP			Author: Kees J. Bot
- *								19 Jul 1997
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/asynchio.h>
-
-#if __minix && !__minix_vmd
-#define HAS_ASYN	0	/* Standard Minix doesn't have async I/O. */
-#else
-#define HAS_ASYN	1	/* Everyone else does in some way. */
-#endif
-
-#if !HAS_ASYN
-#include <signal.h>
-#endif
-
-#define END		0300		/* End of packet. */
-#define ESC		0333		/* Byte stuffing escape. */
-#define ESC_END		0334		/* END -> ESC ESC_END -> END. */
-#define ESC_ESC		0335		/* ESC -> ESC ESC_ESC -> ESC. */
-
-#define PACKLEN		2048		/* Max datagram size. */
-#define SLIPLEN   (1 + 2*PACKLEN + 1)	/* Max serial size when all escaped. */
-
-/* Pathetic fprintf() clone to avoid dragging in the stdio library. */
-static int fprintf(int fd, const char *format, ...);
-#define stderr	2
-
-int main(int argc, char **argv)
-{
-    char *ps_device;
-    int ps_fd;
-    int doing[2], discard;
-    ssize_t r;
-#if !HAS_ASYN
-    pid_t other_pid;
-#endif
-    size_t ps_len[2], sl_len[2];
-    unsigned char *sl_end;
-    unsigned char ps_buf[2][PACKLEN];
-    unsigned char sl_buf[2][SLIPLEN];
-    asynchio_t asyn;
-
-    if (argc != 2) {
-	fprintf(stderr, "Usage: slip psip-device\n");
-	exit(1);
-    }
-    ps_device= argv[1];
-
-    if ((ps_fd= open(ps_device, O_RDWR)) < 0) {
-	fprintf(stderr, "slip: can't open %s: %s\n",
-	    ps_device, strerror(errno));
-	exit(1);
-    }
-
-    doing[0]= 1;	/* We're doing serial -> psip. */
-    discard= 0;		/* No input error. */
-    sl_len[0]= 0;	/* Nothing read from serial line yet. */
-    sl_end= nil;	/* No END marker seen. */
-    ps_len[0]= 0;	/* Nothing to write to pseudo IP device. */
-
-    doing[1]= 1;	/* We're doing psip -> serial. */
-    sl_len[1]= 0;	/* Nothing read from pseudo IP device yet. */
-    ps_len[1]= 0;	/* Nothing to write to serial line. */
-
-#if !HAS_ASYN
-    /* Oops, standard Minix can't do asynchronous I/O.  Fork and let the parent
-     * do serial -> psip, and the child do psip -> serial.  (Note that we have
-     * to make sure that we're not reading and writing at the same time even
-     * for standard Minix.  For Minix-vmd we do fill an input buffer while an
-     * output buffer is waiting to be drained to improve performance a bit.)
-     */
-    switch ((other_pid= fork())) {
-    case -1:
-	fprintf(stderr, "slip: can't fork: %s\n", strerror(errno));
-	exit(1);
-    case 0:
-	/* Child. */
-	doing[0]= 0;	/* *Not* doing serial -> psip. */
-	other_pid= getppid();
-	break;
-    default:
-	/* Parent. */
-	doing[1]= 0;	/* *Not* doing psip -> serial. */
-    }
-#endif
-
-    asyn_init(&asyn);
-
-    for (;;) {
-	if (doing[0]) {
-	    /* If there is an END marker in the serial input then create
-	     * an IP packet to be send to the TCP/IP task.
-	     */
-	    while (sl_end != nil && ps_len[0] == 0) {
-		unsigned char *sp= sl_buf[0];
-		unsigned char *pp= ps_buf[0];
-
-		while (sp < sl_end) {
-		    int c= *sp++;
-
-		    if (c == ESC) {
-			switch (*sp++) {
-			case ESC_ESC:	/* ESC ESC_ESC -> ESC. */
-			    c= ESC;
-			    break;
-			case ESC_END:	/* ESC ESC_END -> END. */
-			    c= END;
-			    break;
-			default:
-			    /* Protocol error. */
-			    discard= 1;
-			}
-		    }
-		    if (pp < ps_buf[0] + PACKLEN) {
-			*pp++ = c;
-		    } else {
-			/* Packet too big, discard. */
-			discard= 1;
-		    }
-		}
-		if (discard) {
-		    discard= 0;
-		} else {
-		    /* A new packet can be send to the TCP/IP server. */
-		    ps_len[0]= (pp - ps_buf[0]);
-		}
-		/* Move what's beyond END to the front. */
-		sl_end++;
-		sl_len[0] -= (sl_end - sl_buf[0]);
-		memmove(sl_buf[0], sl_end, sl_len[0]);
-		sl_end= memchr(sl_buf[0], END, sl_len[0]);
-	    }
-
-	    /* Reading from serial input. */
-	    if (sl_end == nil && (HAS_ASYN || ps_len[0] == 0)) {
-		r= asyn_read(&asyn, 0, sl_buf[0] + sl_len[0],
-							SLIPLEN - sl_len[0]);
-		if (r > 0) {
-		    sl_end= memchr(sl_buf[0] + sl_len[0], END, r);
-		    sl_len[0]+= r;
-		    if (sl_end == nil && sl_len[0] == SLIPLEN) {
-			/* Packet is idiotically big and no END in sight. */
-			sl_len[0]= 0;
-			discard= 1;
-		    }
-		} else
-		if (r == 0) {
-		    fprintf(stderr, "slip: EOF on serial input\n");
-		    break;
-		} else
-		if (errno != ASYN_INPROGRESS) {
-		    fprintf(stderr, "slip: serial input error: %s\n",
-			strerror(errno));
-		    break;
-		}
-	    }
-
-	    /* Writing to the psip device. */
-	    if (ps_len[0] > 0) {
-		r= asyn_write(&asyn, ps_fd, ps_buf[0], ps_len[0]);
-		if (r == ps_len[0]) {
-		    /* Packet written. */
-		    ps_len[0]= 0;
-		} else
-		if (r >= 0) {
-		    fprintf(stderr,
-			"slip: odd write to %s, tried %u, wrote %d\n",
-			ps_device, (unsigned) ps_len[0], (int) r);
-		    break;
-		} else
-		if (errno != ASYN_INPROGRESS) {
-		    fprintf(stderr, "slip: error writing %s: %s\n",
-			ps_device, strerror(errno));
-		    break;
-		}
-	    }
-	}
-
-	if (doing[1]) {
-	    /* Transform an IP packet to a "byte stuffed" serial packet. */
-	    if (ps_len[1] > 0 && sl_len[1] == 0) {
-		unsigned char *pp= ps_buf[1];
-		unsigned char *sp= sl_buf[1];
-
-		*sp++ = END;
-		while (ps_len[1] > 0) {
-		    int c= *pp++;
-		    ps_len[1]--;
-		    switch (c) {
-		    case ESC:		/* ESC -> ESC ESC_ESC. */
-			*sp++ = ESC;
-			c= ESC_ESC;
-			break;
-		    case END:		/* END -> ESC ESC_END. */
-			*sp++ = ESC;
-			c= ESC_END;
-			break;
-		    }
-		    *sp++ = c;
-		}
-		*sp++ = END;
-		sl_len[1]= (sp - sl_buf[1]);
-	    }
-
-	    /* Reading from the psip device. */
-	    if (ps_len[1] == 0 && (HAS_ASYN || sl_len[1] == 0)) {
-		r= asyn_read(&asyn, ps_fd, ps_buf[1], PACKLEN);
-		if (r > 0) {
-		    /* One packet read. */
-		    ps_len[1]= r;
-		} else
-		if (r == 0) {
-		    fprintf(stderr, "slip: EOF on %s\n", ps_device);
-		    break;
-		} else
-		if (errno != ASYN_INPROGRESS) {
-		    fprintf(stderr, "slip: error reading %s: %s\n",
-			ps_device, strerror(errno));
-		    break;
-		}
-	    }
-
-	    /* Writing to serial output. */
-	    if (sl_len[1] > 0) {
-		r= asyn_write(&asyn, 1, sl_buf[1], sl_len[1]);
-		if (r > 0) {
-		    if ((sl_len[1]-= r) > 0) {
-			memmove(sl_buf[1], sl_buf[1] + r, sl_len[1]);
-		    }
-		} else
-		if (r == 0) {
-		    fprintf(stderr, "slip: EOF on serial output\n");
-		    break;
-		} else
-		if (errno != ASYN_INPROGRESS) {
-		    fprintf(stderr, "slip: serial output error: %s\n",
-			strerror(errno));
-		    break;
-		}
-	    }
-	}
-
-	/* Wait for something to happen. */
-	if (asyn_wait(&asyn, 0, nil) < 0) {
-	    fprintf(stderr,
-		"slip: error while waiting for I/O to happen: %s\n",
-		strerror(errno));
-	    break;
-	}
-    }
-#if !HAS_ASYN
-    /* Tell my alter ego that the game is over. */
-    kill(other_pid, SIGKILL);
-#endif
-    return 1;
-}
-
-static int fprintf(int fd, const char *format, ...)
-/* Simple fprintf() to save a few bytes by not using the stdio library. */
-{
-    int len;
-    ssize_t r;
-    const char *fp0, *fp;
-    va_list ap;
-
-    len= 0;
-    fp= fp0= format;
-    va_start(ap, format);
-
-    while (*fp != 0) {
-	if (*fp == '%' && memchr("sdu", fp[1], 3) != nil) {
-	    if (fp > fp0) {
-		if ((r= write(fd, fp0, (fp - fp0))) < 0) return -1;
-		len+= r;
-	    }
-	    fp++;
-	    fp0= fp+1;
-
-	    if (*fp == 's') {
-		char *s= va_arg(ap, char *);
-
-		if ((r= write(fd, s, strlen(s))) < 0) return -1;
-		len+= r;
-	    } else {
-		int d;
-		unsigned u;
-		char a[3 * sizeof(u) + 2];
-		char *p;
-
-		if (*fp == 'd') {
-		    u= d= va_arg(ap, int);
-		    if (d < 0) u= -u;
-		} else {
-		    u= va_arg(ap, unsigned);
-		    d= 0;
-		}
-
-		p= a + sizeof(a);
-		*--p= 0;
-		do *--p= '0' + (u % 10); while ((u /= 10) > 0);
-
-		if (d < 0) *--p= '-';
-		if ((r= write(fd, p, (a + sizeof(a)) - p)) < 0) return -1;
-		len+= r;
-	    }
-	}
-	fp++;
-    }
-    if (fp > fp0) {
-	if ((r= write(fd, fp0, (fp - fp0))) < 0) return -1;
-	len+= r;
-    }
-    va_end(ap);
-    return len;
-}
Index: trunk/minix/commands/simple/sort.c
===================================================================
--- trunk/minix/commands/simple/sort.c	(revision 9)
+++ 	(revision )
@@ -1,1193 +1,0 @@
-/* sort - sort a file of lines		Author: Michiel Huisjes */
-
-/* SYNOPSIS:
- * 	sort [-funbirdcmt'x'] [+beg_pos[opts] [-end_pos]] [-o outfile] [file]..
- *
- * 	[opts] can be any of
- * 	-f : Fold upper case to lower.
- * 	-n : Sort to numeric value (optional decimal point) implies -b
- * 	-b : Skip leading blanks
- * 	-i : Ignore chars outside ASCII range (040 - 0176)
- * 	-r : Reverse the sense of comparisons.
- * 	-d : Sort to dictionary order. Only letters, digits, comma's and points
- * 	     are compared.
- * 	If any of these flags are used in [opts], then they override all global
- * 	ordering for this field.
- *
- * 	I/O control flags are:
- * 	-u : Print uniq lines only once.
- * 	-c : Check if files are sorted in order.
- * 	-m : Merge already sorted files.
- * 	-o outfile : Name of output file. (Can be one of the input files).
- * 		     Default is stdout.
- * 	- : Take stdin as input.
- *
- * 	Fields:
- * 	-t'x' : Field separating character is 'x'
- * 	+a.b : Start comparing at field 'a' with offset 'b'. A missing 'b' is
- * 	       taken to be 0.
- * 	-a.b : Stop comparing at field 'a' with offset 'b'. A missing 'b' is
- * 	       taken to be 0.
- * 	A missing -a.b means the rest of the line.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <limits.h>
-
-#define OPEN_FILES	(OPEN_MAX-4)	/* Nr of open files per process */
-#if __minix_vmd
-#define MEMORY_SIZE	(1024 * 1024)
-#else
-#define MEMORY_SIZE	((10 * sizeof(int)) * 1024)
-#endif
-					/* Total mem_size */
-#define LINE_SIZE	(1024 >> 1)	/* Max length of a line */
-#define IO_SIZE		(2 * 1024)	/* Size of buffered output */
-#define STD_OUT		 1	/* Fd of terminal */
-
-/* Return status of functions */
-#define OK		 0
-#define ERROR		-1
-#define NIL_PTR		((char *) 0)
-
-/* Compare return values */
-#define LOWER		-1
-#define SAME		 0
-#define HIGHER		 1
-
-/* Table definitions. */
-#define DICT		0x001	/* Alpha, numeric, letters and . */
-#define ASCII		0x002	/* All between ' ' and '~' */
-#define BLANK		0x004	/* ' ' and '\t' */
-#define DIGIT		0x008	/* 0-9 */
-#define UPPER		0x010	/* A-Z */
-
-typedef int BOOL;
-
-#define	FALSE	0
-#define	TRUE	1
-
-typedef struct {
-  int fd;			/* Fd of file */
-  char *buffer;			/* Buffer for reads */
-  int read_chars;		/* Nr of chars actually read in buffer */
-  int cnt;			/* Nr of chars taken out of buffer */
-  char *line;			/* Contains line currently used */
-} MERGE;
-
-#define NIL_MERGE	((MERGE *) 0)
-MERGE merge_f[OPEN_FILES];	/* Merge structs */
-int buf_size;			/* Size of core available for each struct */
-
-#define FIELDS_LIMIT	10	/* 1 global + 9 user */
-#define GLOBAL		 0
-
-typedef struct {
-  int beg_field, beg_pos;	/* Begin field + offset */
-  int end_field, end_pos;	/* End field + offset. ERROR == EOLN */
-  BOOL reverse;			/* TRUE if rev. flag set on this field */
-  BOOL blanks;
-  BOOL dictionary;
-  BOOL fold_case;
-  BOOL ascii;
-  BOOL numeric;
-} FIELD;
-
-/* Field declarations. A total of FILEDS_LIMIT is allowed */
-FIELD fields[FIELDS_LIMIT];
-int field_cnt;			/* Nr of field actually assigned */
-
-/* Various output control flags */
-BOOL check = FALSE;
-BOOL only_merge = FALSE;
-BOOL uniq = FALSE;
-
-char *mem_top;			/* Mem_top points to lowest pos of memory. */
-char *cur_pos;			/* First free position in mem */
-char **line_table;		/* Pointer to the internal line table */
-BOOL in_core = TRUE;		/* Set if input cannot all be sorted in core */
-
- /* Place where temp_files should be made */
-char temp_files[] = "/tmp/sort.XXXXX.XX";
-char *output_file;		/* Name of output file */
-int out_fd;			/* Fd to output file (could be STD_OUT) */
-char out_buffer[IO_SIZE];	/* For buffered output */
-
-char **argptr;			/* Pointer to argv structure */
-int args_offset;		/* Nr of args spilled on options */
-int args_limit;			/* Nr of args given */
-
-char separator;			/* Char that separates fields */
-int nr_of_files = 0;		/* Nr_of_files to be merged */
-int disabled;			/* Nr of files done */
-
-char USAGE[] = "Usage: sort [-funbirdcmt'x'] [+beg_pos [-end_pos]] [-o outfile] [file] ..";
-
-/* Forward declarations */
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void get_opts, (char *ptr, FIELD * field));
-_PROTOTYPE(void new_field, (FIELD * field, int *offset, BOOL beg_fl));
-_PROTOTYPE(void adjust_options, (FIELD * field));
-_PROTOTYPE(void error, (BOOL quit, char *message, char *arg));
-_PROTOTYPE(void open_outfile, (void));
-_PROTOTYPE(void get_file, (int fd, off_t size));
-_PROTOTYPE(int last_line, (void));
-_PROTOTYPE(void print_table, (int fd));
-_PROTOTYPE(char *file_name, (int nr));
-_PROTOTYPE(void mread, (int fd, char *address, int bytes));
-_PROTOTYPE(void mwrite, (int fd, char *address, int bytes));
-_PROTOTYPE(void sort, (void));
-_PROTOTYPE(void sort_table, (int nel));
-_PROTOTYPE(void incr, (int si, int ei));
-_PROTOTYPE(int cmp_fields, (char *el1, char *el2));
-_PROTOTYPE(void build_field, (char *dest, FIELD * field, char *src));
-_PROTOTYPE(char *skip_fields, (char *str, int nf));
-_PROTOTYPE(int compare, (char *el1, char *el2));
-_PROTOTYPE(int cmp, (unsigned char *el1, unsigned char *el2, FIELD * field));
-_PROTOTYPE(int digits, (char *str1, char *str2, BOOL check_sign));
-_PROTOTYPE(void files_merge, (int file_cnt));
-_PROTOTYPE(void merge, (int start_file, int limit_file));
-_PROTOTYPE(void put_line, (char *line));
-_PROTOTYPE(MERGE * print, (MERGE * merg, int file_cnt));
-_PROTOTYPE(int read_line, (MERGE * merg));
-_PROTOTYPE(MERGE * skip_lines, (MERGE * smallest, int file_cnt));
-_PROTOTYPE(void uniq_lines, (MERGE * merg));
-_PROTOTYPE(void check_file, (int fd, char *file));
-_PROTOTYPE(int length, (char *line));
-_PROTOTYPE(void copy, (char *dest, char *src));
-_PROTOTYPE(char *msbrk, (int size));
-_PROTOTYPE(void mbrk, (char *address));
-_PROTOTYPE(void catch, (int dummy));
-
-/* Table of all chars. 0 means no special meaning. */
-char table[256] = {
-/* '^@' to space */
-	   0, 0, 0, 0, 0, 0, 0, 0,
-	   0, BLANK | DICT, 0, 0, 0, 0, 0, 0,
-	   0, 0, 0, 0, 0, 0, 0, 0,
-	   0, 0, 0, 0, 0, 0, 0, 0,
-
-/* Space to '0' */
-       BLANK | DICT | ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII,
-	   ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII,
-	   ASCII, ASCII,
-
-/* '0' until '9' */
-     DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII,
-     DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII,
-     DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII,
-	   DIGIT | DICT | ASCII,
-
-/* ASCII from ':' to '@' */
-	   ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII,
-
-/* Upper case letters 'A' to 'Z' */
-     UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII,
-     UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII,
-     UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII,
-     UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII,
-     UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII,
-     UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII,
-     UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII,
-     UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII,
-	   UPPER | DICT | ASCII, UPPER | DICT | ASCII,
-
-/* ASCII from '[' to '`' */
-	   ASCII, ASCII, ASCII, ASCII, ASCII, ASCII,
-
-/* Lower case letters from 'a' to 'z' */
-	   DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII,
-	   DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII,
-	   DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII,
-	   DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII,
-	   DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII,
-	   DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII,
-	   DICT | ASCII, DICT | ASCII,
-
-/* ASCII from '{' to '~' */
-	   ASCII, ASCII, ASCII, ASCII,
-
-/* Stuff from -1 to -177 */
-	   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
-};
-
-
-/*
- * Get_opts () assigns the options into the field structure as described in ptr.
- * This field structure could be the GLOBAL one.
- */
-void get_opts(ptr, field)
-register char *ptr;
-register FIELD *field;
-{
-  switch (*ptr) {
-      case 'b':			/* Skip leading blanks */
-	field->blanks = TRUE;
-	break;
-      case 'd':			/* Dictionary order */
-	field->dictionary = TRUE;
-	break;
-      case 'f':			/* Fold upper case to lower */
-	field->fold_case = TRUE;
-	break;
-      case 'i':			/* Skip chars outside ' ' '~' */
-	field->ascii = TRUE;
-	break;
-      case 'n':			/* Sort on numeric */
-	field->numeric = TRUE;
-	field->blanks = TRUE;
-	break;
-      case 'r':			/* Reverse comparisons */
-	field->reverse = TRUE;
-	break;
-      default:			/* Illegal options */
-	error(TRUE, USAGE, NIL_PTR);
-  }
-}
-
-/* New_field () assigns a new field as described by the arguments.
- * A field description is of the form: +a.b[opts] -c.d, where b and d, as well
- * as -c.d and [opts] are optional. Nr before digit is field nr. Nr after digit
- * is offset from field.
- */
-void new_field(field, offset, beg_fl)
-register FIELD *field;		/* Field to assign */
-int *offset;			/* Offset in argv structure */
-BOOL beg_fl;			/* Assign beg or end of field */
-{
-  register char *ptr;
-
-  ptr = argptr[*offset];
-  *offset += 1;			/* Incr offset to next arg */
-  ptr++;
-
-  if (beg_fl)
-	field->beg_field = atoi(ptr);	/* Assign int of first field */
-  else
-	field->end_field = atoi(ptr);
-
-  while (table[*ptr] & DIGIT)	/* Skip all digits */
-	ptr++;
-
-  if (*ptr == '.') {		/* Check for offset */
-	ptr++;
-	if (beg_fl)
-		field->beg_pos = atoi(ptr);
-	else
-		field->end_pos = atoi(ptr);
-	while (table[*ptr] & DIGIT)	/* Skip digits */
-		ptr++;
-  }
-  if (beg_fl) {
-	while (*ptr != '\0')	/* Check options after field */
-		get_opts(ptr++, field);
-  }
-  if (beg_fl) {			/* Check for end pos */
-	ptr = argptr[*offset];
-	if (ptr && *ptr == '-' && ((table[*(ptr + 1)] & DIGIT) || *(ptr + 1) == '.')) {
-		new_field(field, offset, FALSE);
-		if (field->beg_field > field->end_field)
-			error(TRUE, "End field is before start field!", NIL_PTR);
-	} else			/* No end pos. */
-		field->end_field = ERROR;
-  }
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int arg_count = 1;		/* Offset in argv */
-  struct stat st;
-  register char *ptr;		/* Ptr to *argv in use */
-  register int fd;
-  int pid, pow;
-
-  argptr = argv;
-  cur_pos = mem_top = msbrk(MEMORY_SIZE);	/* Find lowest mem. location */
-
-  while (arg_count < argc && ((ptr = argv[arg_count])[0] == '-' || *ptr == '+')) {
-	if (*ptr == '-' && *(ptr + 1) == '\0')	/* "-" means stdin */
-		break;
-	if (*ptr == '+') {	/* Assign field. */
-		if (++field_cnt == FIELDS_LIMIT)
-			error(TRUE, "Too many fields", NIL_PTR);
-		new_field(&fields[field_cnt], &arg_count, TRUE);
-	} else {		/* Get output options */
-		while (*++ptr) {
-			switch (*ptr) {
-			    case 'c':	/* Only check file */
-				check = TRUE;
-				break;
-			    case 'm':	/* Merge (sorted) files */
-				only_merge = TRUE;
-				break;
-			    case 'u':	/* Only give uniq lines */
-				uniq = TRUE;
-				break;
-			    case 'o':	/* Name of output file */
-				output_file = argv[++arg_count];
-				break;
-			    case 't':	/* Field separator */
-				ptr++;
-				separator = *ptr;
-				break;
-			    default:	/* Sort options */
-				get_opts(ptr, &fields[GLOBAL]);
-			}
-		}
-		arg_count++;
-	}
-  }
-
-  for (fd = 1; fd <= field_cnt; fd++) adjust_options(&fields[fd]);
-
-/* Create name of tem_files 'sort.pid.aa' */
-  ptr = &temp_files[10];
-  pid = getpid();
-  pow = 10000;
-  while (pow != 0) {
-	*ptr++ = pid / pow + '0';
-	pid %= pow;
-	pow /= 10;
-  }
-
-  signal(SIGINT, catch);
-
-/* Only merge files. Set up */
-  if (only_merge) {
-	args_limit = args_offset = arg_count;
-	while (argv[args_limit] != NIL_PTR)
-		args_limit++;	/* Find nr of args */
-	files_merge(args_limit - arg_count);
-	exit(0);
-  }
-  if (arg_count == argc) {	/* No args left. Use stdin */
-	if (check)
-		check_file(0, NIL_PTR);
-	else
-		get_file(0, (off_t) 0);
-  } else
-	while (arg_count < argc) {	/* Sort or check args */
-		if (strcmp(argv[arg_count], "-") == 0)
-			fd = 0;
-		else if (stat(argv[arg_count], &st) < 0) {
-			error(FALSE, "Cannot find ", argv[arg_count++]);
-			continue;
-		}
-
-		/* Open files */
-		else if ((fd = open(argv[arg_count], O_RDONLY)) < 0) {
-			error(FALSE, "Cannot open ", argv[arg_count++]);
-			continue;
-		}
-		if (check)
-			check_file(fd, argv[arg_count]);
-		else		/* Get_file reads whole file */
-			get_file(fd, st.st_size);
-		arg_count++;
-	}
-
-  if (check) exit(0);
-
-  sort();			/* Sort whatever is left */
-
-  if (nr_of_files == 1)		/* Only one file sorted -> don't merge */
-	exit(0);
-
-  files_merge(nr_of_files);
-  return(0);
-}
-
-/* Adjust_options() assigns all global variables set also in the fields
- * assigned.
- */
-void adjust_options(field)
-register FIELD *field;
-{
-  register FIELD *gfield = &fields[GLOBAL];
-
-  if (gfield->reverse) field->reverse = TRUE;
-  if (gfield->blanks) field->blanks = TRUE;
-  if (gfield->dictionary) field->dictionary = TRUE;
-  if (gfield->fold_case) field->fold_case = TRUE;
-  if (gfield->ascii) field->ascii = TRUE;
-  if (gfield->numeric) field->numeric = TRUE;
-}
-
-/* Error () prints the error message on stderr and exits if quit == TRUE. */
-void error(quit, message, arg)
-register BOOL quit;
-register char *message, *arg;
-{
-  write(2, message, strlen(message));
-  if (arg != NIL_PTR) write(2, arg, strlen(arg));
-  perror(" ");
-  if (quit) exit(1);
-}
-
-/* Open_outfile () assigns to out_fd the fd where the output must go when all
- * the sorting is done.
- */
-void open_outfile()
-{
-  if (output_file == NIL_PTR)
-	out_fd = STD_OUT;
-  else if ((out_fd = creat(output_file, 0644)) < 0)
-	error(TRUE, "Cannot creat ", output_file);
-}
-
-/* Get_file reads the whole file of filedescriptor fd. If the file is too big
- * to keep in core, a partial sort is done, and the output is stashed somewhere.
- */
-void get_file(fd, size)
-int fd;				/* Fd of file to read */
-register off_t size;		/* Size of file */
-{
-  register int i;
-  int rest;			/* Rest in memory */
-  char save_ch;			/* Used in stdin readings */
-
-  rest = MEMORY_SIZE - (cur_pos - mem_top);
-  if (fd == 0) {		/* We're reding stdin */
-	while ((i = read(0, cur_pos, rest)) > 0) {
-		if ((cur_pos - mem_top) + i == MEMORY_SIZE) {
-			in_core = FALSE;
-			i = last_line();	/* End of last line */
-			save_ch = mem_top[i];
-			mem_top[i] = '\0';
-			sort();	/* Sort core */
-			mem_top[i] = save_ch;	/* Restore erased char */
-			/* Restore last (half read) line */
-			for (rest = 0; i + rest != MEMORY_SIZE; rest++)
-				mem_top[rest] = mem_top[i + rest];
-			/* Assign current pos. in memory */
-			cur_pos = &mem_top[rest];
-		} else {	/* Fits, just assign position in mem. */
-			cur_pos = cur_pos + i;
-			*cur_pos = '\0';
-		}
-
-		/* Calculate rest of mem */
-		rest = MEMORY_SIZE - (cur_pos - mem_top);
-	}
-  }
-
-  /* Reading file. Check size */
-  else if (size > rest) {	/* Won't fit */
-	mread(fd, cur_pos, rest);
-	in_core = FALSE;
-	i = last_line();	/* Get pos. of last line */
-	mem_top[i] = '\0';	/* Truncate */
-	(void) lseek(fd, (off_t) (i - MEMORY_SIZE), SEEK_CUR);	/* Do this next time */
-	size = size - rest - i + MEMORY_SIZE;	/* Calculate rest */
-	cur_pos = mem_top;	/* Reset mem */
-	sort();			/* Sort core */
-	get_file(fd, size);	/* Get rest of file */
-  } else {			/* Fits. Just read in */
-	rest = size;
-	mread(fd, cur_pos, rest);
-	cur_pos = cur_pos + rest;	/* Reassign cur_pos */
-	*cur_pos = '\0';
-	(void) close(fd);	/* File completed */
-  }
-}
-
-/* Last_line () find the last line in core and retuns the offset from the top
- * of the memory.
- */
-int last_line()
-{
-  register int i;
-
-  for (i = MEMORY_SIZE - 2; i > 0; i--)
-	if (mem_top[i] == '\n') break;
-  return i + 1;
-}
-
-/* Print_table prints the line table in the given file_descriptor. If the fd
- * equals ERROR, it opens a temp_file itself.
- */
-void print_table(fd)
-int fd;
-{
-  register char **line_ptr;	/* Ptr in line_table */
-  register char *ptr;		/* Ptr to line */
-  int index = 0;		/* Index in output buffer */
-
-  if (fd == ERROR) {
-	if ((fd = creat(file_name(nr_of_files), 0644)) < 0)
-		error(TRUE, "Cannot creat ", file_name(nr_of_files));
-  }
-  for (line_ptr = line_table; *line_ptr != NIL_PTR; line_ptr++) {
-	ptr = *line_ptr;
-	/* Skip all same lines if uniq is set */
-	if (uniq && *(line_ptr + 1) != NIL_PTR) {
-		if (compare(ptr, *(line_ptr + 1)) == SAME) continue;
-	}
-	do {			/* Print line in a buffered way */
-		out_buffer[index++] = *ptr;
-		if (index == IO_SIZE) {
-			mwrite(fd, out_buffer, IO_SIZE);
-			index = 0;
-		}
-	} while (*ptr++ != '\n');
-  }
-  mwrite(fd, out_buffer, index);/* Flush buffer */
-  (void) close(fd);		/* Close file */
-  nr_of_files++;		/* Increment nr_of_files to merge */
-}
-
-/* File_name () returns the nr argument from the argument list, or a uniq
- * filename if the nr is too high, or the arguments were not merge files.
- */
-char *file_name(nr)
-register int nr;
-{
-  if (only_merge) {
-	if (args_offset + nr < args_limit) return argptr[args_offset + nr];
-  }
-  temp_files[16] = nr / 26 + 'a';
-  temp_files[17] = nr % 26 + 'a';
-
-  return temp_files;
-}
-
-/* Mread () performs a normal read (), but checks the return value. */
-void mread(fd, address, bytes)
-int fd;
-char *address;
-register int bytes;
-{
-  if (read(fd, address, bytes) < 0 && bytes != 0)
-	error(TRUE, "Read error", NIL_PTR);
-}
-
-/* Mwrite () performs a normal write (), but checks the return value. */
-void mwrite(fd, address, bytes)
-int fd;
-char *address;
-register int bytes;
-{
-  if (write(fd, address, bytes) != bytes && bytes != 0)
-	error(TRUE, "Write error", NIL_PTR);
-}
-
-/* Sort () sorts the input in memory starting at mem_top. */
-void sort()
-{
-  register char *ptr = mem_top;
-  register int count = 0;
-
-/* Count number of lines in memory */
-  while (*ptr) {
-	if (*ptr++ == '\n') count++;
-  }
-
-/* Set up the line table */
-  line_table = (char **) msbrk(count * sizeof(char *) + sizeof(char *));
-
-  count = 1;
-  ptr = line_table[0] = mem_top;
-  while (*ptr) {
-	if (*ptr++ == '\n') line_table[count++] = ptr;
-  }
-
-  line_table[count - 1] = NIL_PTR;
-
-/* Sort the line table */
-  sort_table(count - 1);
-
-/* Stash output somewhere */
-  if (in_core) {
-	open_outfile();
-	print_table(out_fd);
-  } else
-	print_table(ERROR);
-
-/* Free line table */
-  mbrk((char *) line_table);
-}
-
-/* Sort_table () sorts the line table consisting of nel elements. */
-void sort_table(nel)
-register int nel;
-{
-  char *tmp;
-  register int i;
-
-  /* Make heap */
-  for (i = (nel >> 1); i >= 1; i--) incr(i, nel);
-
-  /* Sort from heap */
-  for (i = nel; i > 1; i--) {
-	tmp = line_table[0];
-	line_table[0] = line_table[i - 1];
-	line_table[i - 1] = tmp;
-	incr(1, i - 1);
-  }
-}
-
-/* Incr () increments the heap. */
-void incr(si, ei)
-register int si, ei;
-{
-  char *tmp;
-
-  while (si <= (ei >> 1)) {
-	si <<= 1;
-	if (si + 1 <= ei && compare(line_table[si - 1], line_table[si]) <= 0)
-		si++;
-	if (compare(line_table[(si >> 1) - 1], line_table[si - 1]) >= 0)
-		return;
-	tmp = line_table[(si >> 1) - 1];
-	line_table[(si >> 1) - 1] = line_table[si - 1];
-	line_table[si - 1] = tmp;
-  }
-}
-
-/* Cmp_fields builds new lines out of the lines pointed to by el1 and el2 and
- * puts it into the line1 and line2 arrays. It then calls the cmp () routine
- * with the field describing the arguments.
- */
-int cmp_fields(el1, el2)
-register char *el1, *el2;
-{
-  int i, ret;
-  char line1[LINE_SIZE], line2[LINE_SIZE];
-
-  for (i = 0; i < field_cnt; i++) {	/* Setup line parts */
-	build_field(line1, &fields[i + 1], el1);
-	build_field(line2, &fields[i + 1], el2);
-	if ((ret = cmp((unsigned char *) line1, (unsigned char *) line2,
-		       &fields[i + 1])) != SAME)
-		break;		/* If equal, try next field */
-  }
-
-/* Check for reverse flag */
-  if (i != field_cnt && fields[i + 1].reverse) return -ret;
-
-/* Else return the last return value of cmp () */
-  return ret;
-}
-
-/* Build_field builds a new line from the src as described by the field.
- * The result is put in dest.
- */
-void build_field(dest, field, src)
-char *dest;			/* Holds result */
-register FIELD *field;		/* Field description */
-register char *src;		/* Source line */
-{
-  char *begin = src;		/* Remember start location */
-  char *last;			/* Pointer to end location */
-  int i;
-
-/* Skip begin fields */
-  src = skip_fields(src, field->beg_field);
-
-/* Skip begin positions */
-  for (i = 0; i < field->beg_pos && *src != '\n'; i++) src++;
-
-/* Copy whatever is left */
-  copy(dest, src);
-
-/* If end field is assigned truncate (perhaps) the part copied */
-  if (field->end_field != ERROR) {	/* Find last field */
-	last = skip_fields(begin, field->end_field);
-/* Skip positions as given by end fields description */
-	for (i = 0; i < field->end_pos && *last != '\n'; i++) last++;
-	dest[last - src] = '\n';/* Truncate line */
-  }
-}
-
-/* Skip_fields () skips nf fields of the line pointed to by str. */
-char *skip_fields(str, nf)
-register char *str;
-int nf;
-{
-  while (nf-- > 0) {
-	if (separator == '\0') {/* Means ' ' or '\t' */
-		while (*str != ' ' && *str != '\t' && *str != '\n') str++;
-		while (table[*str] & BLANK) str++;
-	} else {
-		while (*str != separator && *str != '\n') str++;
-		if (*str == separator) str++;
-	}
-  }
-  return str;			/* Return pointer to indicated field */
-}
-
-/* Compare is called by all sorting routines. It checks if fields assignments
- * has been made. if so, it calls cmp_fields (). If not, it calls cmp () and
- * reversed the return value if the (global) reverse flag is set.
- */
-int compare(el1, el2)
-register char *el1, *el2;
-{
-  int ret;
-
-  if (field_cnt > GLOBAL) return cmp_fields(el1, el2);
-
-  ret = cmp((unsigned char *) el1, (unsigned char *) el2, &fields[GLOBAL]);
-  return(fields[GLOBAL].reverse) ? -ret : ret;
-}
-
-/* Cmp () is the actual compare routine. It compares according to the
- * description given in the field pointer.
- */
-int cmp(el1, el2, field)
-register unsigned char *el1, *el2;
-FIELD *field;
-{
-  int c1, c2;
-
-  if (field->blanks) {		/* Skip leading blanks */
-	while (table[*el1] & BLANK) el1++;
-	while (table[*el2] & BLANK) el2++;
-  }
-  if (field->numeric)		/* Compare numeric */
-	return digits((char *) el1, (char *) el2, TRUE);
-
-  for (;;) {
-	while (*el1 == *el2) {
-		if (*el1++ == '\n')	/* EOLN on both strings */
-			return SAME;
-		el2++;
-	}
-	if (*el1 == '\n')	/* EOLN on string one */
-		return LOWER;
-	if (*el2 == '\n') return HIGHER;
-	if (field->ascii) {	/* Skip chars outside 040 - 0177 */
-		if ((table[*el1] & ASCII) == 0) {
-			do {
-				el1++;
-			} while ((table[*el1] & ASCII) == 0);
-			continue;
-		}
-		if ((table[*el2] & ASCII) == 0) {
-			do {
-				el2++;
-			} while ((table[*el2] & ASCII) == 0);
-			continue;
-		}
-	}
-	if (field->dictionary) {/* Skip non-dict chars */
-		if ((table[*el1] & DICT) == 0) {
-			do {
-				el1++;
-			} while ((table[*el1] & DICT) == 0);
-			continue;
-		}
-		if ((table[*el2] & DICT) == 0) {
-			do {
-				el2++;
-			} while ((table[*el2] & DICT) == 0);
-			continue;
-		}
-	}
-	if (field->fold_case) {	/* Fold upper case to lower */
-		if (table[c1 = *el1++] & UPPER) c1 += 'a' - 'A';
-		if (table[c2 = *el2++] & UPPER) c2 += 'a' - 'A';
-		if (c1 == c2) continue;
-		return c1 - c2;
-	}
-	return *el1 - *el2;
-  }
-
-  /* NOTREACHED */
-}
-
-/*
- * Digits compares () the two strings that point to a number of digits followed
- * by an optional decimal point.
- */
-int digits(str1, str2, check_sign)
-register char *str1, *str2;
-BOOL check_sign;		/* True if sign must be checked */
-{
-  BOOL negative = FALSE;	/* True if negative numbers */
-  int diff, pow, ret;
-
-/* Check for optional minus or plus sign */
-  if (check_sign) {
-	if (*str1 == '-') {
-		negative = TRUE;
-		str1++;
-	} else if (*str1 == '+')
-		str1++;
-
-	if (*str2 == '-') {
-		if (negative == FALSE) return HIGHER;
-		str2++;
-	} else if (negative)
-		return LOWER;
-	else if (*str2 == '+')
-		str2++;
-  }
-
-/* Keep incrementing as long as digits are available and equal */
-  while ((table[*str1] & DIGIT) && table[*str2] & DIGIT) {
-	if (*str1 != *str2) break;
-	str1++;
-	str2++;
-  }
-
-/* First check for the decimal point. */
-  if (*str1 == '.' || *str2 == '.') {
-	if (*str1 == '.') {
-		if (*str2 == '.')	/* Both. Check decimal part */
-			ret = digits(str1 + 1, str2 + 1, FALSE);
-		else
-			ret = (table[*str2] & DIGIT) ? LOWER : HIGHER;
-	} else
-		ret = (table[*str1] & DIGIT) ? HIGHER : LOWER;
-  }
-
-/* Now either two digits differ, or unknown char is seen (e.g. end of string) */
-  else if ((table[*str1] & DIGIT) && (table[*str2] & DIGIT)) {
-	diff = *str1 - *str2;	/* Basic difference */
-	pow = 0;		/* Check power of numbers */
-	while (table[*str1++] & DIGIT) pow++;
-	while (table[*str2++] & DIGIT) pow--;
-	ret = (pow == 0) ? diff : pow;
-  }
-
-/* Unknown char. Check on which string it occurred */
-  else {
-	if ((table[*str1] & DIGIT) == 0)
-		ret = (table[*str2] & DIGIT) ? LOWER : SAME;
-	else
-		ret = HIGHER;
-  }
-
-/* Reverse sense of comparisons if negative is true. (-1000 < -1) */
-  return(negative) ? -ret : ret;
-}
-
-/* Files_merge () merges all files as indicated by nr_of_files. Merging goes
- * in numbers of files that can be opened at the same time. (OPEN_FILES)
- */
-void files_merge(file_cnt)
-register int file_cnt;		/* Nr_of_files to merge */
-{
-  register int i;
-  int limit;
-
-  for (i = 0; i < file_cnt; i += OPEN_FILES) {
-	/* Merge last files and store in output file */
-	if ((limit = i + OPEN_FILES) >= file_cnt) {
-		open_outfile();
-		limit = file_cnt;
-	} else {		/* Merge OPEN_FILES files and store in temp
-			 * file */
-		temp_files[16] = file_cnt / 26 + 'a';
-		temp_files[17] = file_cnt % 26 + 'a';
-		if ((out_fd = creat(temp_files, 0644)) < 0)
-			error(TRUE, "Cannot creat ", temp_files);
-		file_cnt++;
-	}
-	merge(i, limit);
-  }
-
-/* Cleanup mess */
-  i = (only_merge) ? args_limit - args_offset : 0;
-  while (i < file_cnt) (void) unlink(file_name(i++));
-}
-
-/* Merge () merges the files between start_file and limit_file. */
-void merge(start_file, limit_file)
-int start_file, limit_file;
-{
-  register MERGE *smallest;	/* Keeps track of smallest line */
-  register int i;
-  int file_cnt = limit_file - start_file;	/* Nr of files to merge */
-
-/* Calculate size in core available for file_cnt merge structs */
-  buf_size = MEMORY_SIZE / file_cnt - LINE_SIZE;
-
-  mbrk(mem_top);		/* First reset mem to lowest loc. */
-  disabled = 0;			/* All files not done yet */
-
-/* Set up merge structures. */
-  for (i = start_file; i < limit_file; i++) {
-	smallest = &merge_f[i - start_file];
-	if (!strcmp(file_name(i), "-"))	/* File is stdin */
-		smallest->fd = 0;
-	else if ((smallest->fd = open(file_name(i), O_RDONLY)) < 0) {
-		smallest->fd = ERROR;
-		error(FALSE, "Cannot open ", file_name(i));
-		disabled++;	/* Done this file */
-		continue;
-	}
-	smallest->buffer = msbrk(buf_size);
-	smallest->line = msbrk(LINE_SIZE);
-	smallest->cnt = smallest->read_chars = 0;
-	(void) read_line(smallest);	/* Read first line */
-  }
-
-  if (disabled == file_cnt) {	/* Couldn't open files */
-	(void) close(out_fd);
-	return;
-  }
-
-/* Find a merg struct to assign smallest. */
-  for (i = 0; i < file_cnt; i++) {
-	if (merge_f[i].fd != ERROR) {
-		smallest = &merge_f[i];
-		break;
-	}
-  }
-
-/* Loop until all files minus one are done */
-  while (disabled < file_cnt - 1) {
-	if (uniq)		/* Skip all same lines */
-		smallest = skip_lines(smallest, file_cnt);
-	else {			/* Find smallest line */
-		for (i = 0; i < file_cnt; i++) {
-			if (merge_f[i].fd == ERROR)
-				continue;	/* We've had this one */
-			if (compare(merge_f[i].line, smallest->line) < 0)
-				smallest = &merge_f[i];
-		}
-	}			/* Print line and read next */
-	smallest = print(smallest, file_cnt);
-  }
-
-  if (only_merge && uniq)
-	uniq_lines(smallest);	/* Print only uniq lines */
-  else				/* Print rest of file */
-	while (print(smallest, file_cnt) != NIL_MERGE);
-
-  put_line(NIL_PTR);		/* Flush output buffer */
-}
-
-/* Put_line () prints the line into the out_fd filedescriptor. If line equals
- * NIL_PTR, the out_fd is flushed and closed.
- */
-void put_line(line)
-register char *line;
-{
-  static int index = 0;		/* Index in out_buffer */
-
-  if (line == NIL_PTR) {	/* Flush and close */
-	mwrite(out_fd, out_buffer, index);
-	index = 0;
-	(void) close(out_fd);
-	return;
-  }
-  do {				/* Fill out_buffer with line */
-	out_buffer[index++] = *line;
-	if (index == IO_SIZE) {
-		mwrite(out_fd, out_buffer, IO_SIZE);
-		index = 0;
-	}
-  } while (*line++ != '\n');
-}
-
-/*
- * Print () prints the line of the merg structure and tries to read another one.
- * If this fails, it returns the next merg structure which file_descriptor is
- * still open. If none could be found, a NIL structure is returned.
- */
-MERGE *print(merg, file_cnt)
-register MERGE *merg;
-int file_cnt;			/* Nr of files that are being merged */
-{
-  register int i;
-
-  put_line(merg->line);		/* Print the line */
-
-  if (read_line(merg) == ERROR) {	/* Read next line */
-	for (i = 0; i < file_cnt; i++) {
-		if (merge_f[i].fd != ERROR) {
-			merg = &merge_f[i];
-			break;
-		}
-	}
-	if (i == file_cnt)	/* No more files left */
-		return NIL_MERGE;
-  }
-  return merg;
-}
-
-/* Read_line () reads a line from the fd from the merg struct. If the read
- * failed, disabled is incremented and the file is closed. Readings are
- * done in buf_size bytes.
- * Lines longer than LINE_SIZE are silently truncated.
- */
-int read_line(merg)
-register MERGE *merg;
-{
-  register char *ptr = merg->line - 1;	/* Ptr buf that will hold line */
-
-  do {
-	ptr++;
-	if (merg->cnt == merg->read_chars) {	/* Read new buffer */
-		if ((merg->read_chars =
-		     read(merg->fd, merg->buffer, buf_size)) <= 0) {
-			(void) close(merg->fd);	/* OOPS */
-			merg->fd = ERROR;
-			disabled++;
-			return ERROR;
-		}
-		merg->cnt = 0;
-	}
-	*ptr = merg->buffer[merg->cnt++];	/* Assign next char of line */
-	if (ptr - merg->line == LINE_SIZE - 1)
-		*ptr = '\n';	/* Truncate very long lines */
-  } while (*ptr != '\n' && *ptr != '\0');
-
-  if (*ptr == '\0')		/* Add '\n' to last line */
-	*ptr = '\n';
-  *++ptr = '\0';		/* Add '\0' */
-  return OK;
-}
-
-/* Skip_lines () skips all same lines in all the files currently being merged.
- * It returns a pointer to the merge struct containing the smallest line.
- */
-MERGE *skip_lines(smallest, file_cnt)
-register MERGE *smallest;
-int file_cnt;
-{
-  register int i;
-  int ret;
-
-  if (disabled == file_cnt - 1)	/* We've had all */
-	return smallest;
-
-  for (i = 0; i < file_cnt; i++) {
-	if (merge_f[i].fd == ERROR || smallest == &merge_f[i])
-		continue;	/* Don't check same file */
-	while ((ret = compare(merge_f[i].line, smallest->line)) == 0) {
-		if (read_line(&merge_f[i]) == ERROR) break;	/* EOF */
-	}
-	if (ret < 0)		/* Line wasn't smallest. Try again */
-		return skip_lines(&merge_f[i], file_cnt);
-  }
-  return smallest;
-}
-
-/* Uniq_lines () prints only the uniq lines out of the fd of the merg struct. */
-void uniq_lines(merg)
-register MERGE *merg;
-{
-  char lastline[LINE_SIZE];	/* Buffer to hold last line */
-
-  for (;;) {
-	put_line(merg->line);	/* Print this line */
-	copy(lastline, merg->line);	/* and save it */
-	if (read_line(merg) == ERROR)	/* Read the next */
-		return;
-	/* Keep reading until lines duffer */
-	while (compare(lastline, merg->line) == SAME)
-		if (read_line(merg) == ERROR) return;
-  }
-
-  /* NOTREACHED */
-}
-
-/*
- * Check_file () checks if a file is sorted in order according to the arguments
- * given in main ().
- */
-void check_file(fd, file)
-int fd;
-char *file;
-{
-  register MERGE *merg;		/* 1 file only */
-  char lastline[LINE_SIZE];	/* Save last line */
-  register int ret;		/* ret status of compare */
-
-  if (fd == 0) file = "stdin";
-  merg = (MERGE *) mem_top;	/* Assign MERGE structure */
-  merg->buffer = mem_top + sizeof(MERGE);
-  merg->line = msbrk(LINE_SIZE);
-  merg->cnt = merg->read_chars = 0;
-  merg->fd = fd;
-  buf_size = MEMORY_SIZE - sizeof(MERGE);
-
-  if (read_line(merg) == ERROR)	/* Read first line */
-	return;
-  copy(lastline, merg->line);	/* and save it */
-
-  for (;;) {
-	if (read_line(merg) == ERROR)	/* EOF reached */
-		break;
-	if ((ret = compare(lastline, merg->line)) > 0) {
-		error(FALSE, "Disorder in file ", file);
-		write(2, merg->line, length(merg->line));
-		break;
-	} else if (ret < 0)	/* Copy if lines not equal */
-		copy(lastline, merg->line);
-	else if (uniq) {
-		error(FALSE, "Non uniq line in file ", file);
-		write(2, merg->line, length(merg->line));
-		break;
-	}
-  }
-
-  mbrk(mem_top);		/* Reset mem */
-}
-
-/* Length () returns the length of the argument line including the linefeed. */
-int length(line)
-register char *line;
-{
-  register int i = 1;		/* Add linefeed */
-
-  while (*line++ != '\n') i++;
-  return i;
-}
-
-/* Copy () copies the src line into the dest line including linefeed. */
-void copy(dest, src)
-register char *dest, *src;
-{
-  while ((*dest++ = *src++) != '\n');
-}
-
-/* Msbrk() does a sbrk() and checks the return value. */
-char *msbrk(size)
-register int size;
-{
-  register char *address;
-
-  if ((address = sbrk(size)) == (char *) -1)
-	error(TRUE, "Not enough memory. Use chmem to allocate more", NIL_PTR);
-  return address;
-}
-
-/* Mbrk() does a brk() and checks the return value. */
-void mbrk(address)
-char *address;
-{
-  if (brk(address) == -1) error(TRUE, "Cannot reset memory", NIL_PTR);
-}
-
-void catch(dummy)
-int dummy;			/* to satisfy the prototype */
-{
-  register int i;
-
-  signal(SIGINT, SIG_IGN);
-  only_merge = FALSE;
-  for (i = 0; i < 26; i++) (void) unlink(file_name(i));
-  exit(2);
-}
Index: trunk/minix/commands/simple/split.c
===================================================================
--- trunk/minix/commands/simple/split.c	(revision 9)
+++ 	(revision )
@@ -1,117 +1,0 @@
-/* split - split a file			Author: Michiel Huisjes */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <minix/minlib.h>
-
-#define CHUNK_SIZE	1024
-
-int cut_line = 1000;
-int infile;
-char out_file[100];
-char *suffix;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void split, (void));
-_PROTOTYPE(int newfile, (void));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void quit, (void));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  unsigned short i;
-
-  out_file[0] = 'x';
-  infile = -1;
-
-  if (argc > 4) usage();
-  for (i = 1; i < argc; i++) {
-	if (argv[i][0] == '-') {
-		if (argv[i][1] >= '0' && argv[i][1] <= '9'
-		    && cut_line == 1000)
-			cut_line = atoi(argv[i]);
-		else if (argv[i][1] == '\0' && infile == -1)
-			infile = 0;
-		else
-			usage();
-	} else if (infile == -1) {
-		if ((infile = open(argv[i], O_RDONLY)) < 0) {
-			std_err("Cannot open input file.\n");
-			exit(1);
-		}
-	} else
-		strcpy(out_file, argv[i]);
-  }
-  if (infile == -1) infile = 0;
-  strcat(out_file, "aa");
-  for (suffix = out_file; *suffix; suffix++);
-  suffix--;
-
-/* Appendix now points to last `a' of "aa". We have to decrement it by one */
-  *suffix = 'a' - 1;
-  split();
-  return(0);
-}
-
-void split()
-{
-  char buf[CHUNK_SIZE];
-  register char *index, *base;
-  register int n;
-  int fd;
-  long lines = 0L;
-
-  fd = -1;
-  while ((n = read(infile, buf, CHUNK_SIZE)) > 0) {
-	base = index = buf;
-	while (--n >= 0) {
-		if (*index++ == '\n')
-			if (++lines % cut_line == 0) {
-				if (fd == -1) fd = newfile();
-				if (write(fd, base, (int) (index - base)) != (int) (index - base))
-					quit();
-				base = index;
-				close(fd);
-				fd = -1;
-			}
-	}
-	if (index == base) continue;
-	if (fd == -1) fd = newfile();
-	if (write(fd, base, (int) (index - base)) != (int) (index - base))
-		quit();
-  }
-}
-
-int newfile()
-{
-  int fd;
-
-  if (++*suffix > 'z') {	/* Increment letter */
-	*suffix = 'a';		/* Reset last letter */
-	++*(suffix - 1);	/* Previous letter must be incremented */
-	/* E.g. was `filename.az' */
-	/* Now `filename.ba' */
-  }
-  if ((fd = creat(out_file, 0644)) < 0) {
-	std_err("Cannot create new file.\n");
-	exit(2);
-  }
-  return fd;
-}
-
-void usage()
-{
-  std_err("Usage: split [-n] [file [name]].\n");
-  exit(1);
-}
-
-void quit()
-{
-  std_err("split: write error\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/stat.c
===================================================================
--- trunk/minix/commands/simple/stat.c	(revision 9)
+++ 	(revision )
@@ -1,391 +1,0 @@
-/* stat.c Feb 1987 - main, printit, statit
- *
- * stat - a program to perform what the stat(2) call does.  
- *
- * usage: stat [-] [-all] -<field> [-<field> ...] [file1 file2 file3 ...]
- *
- * where   <field> is one of the struct stat fields without the leading "st_".
- *	   The three times can be printed out as human times by requesting
- *	   -Ctime instead of -ctime (upper case 1st letter).
- *	   - means take the file names from stdin.
- *	   -0.. means fd0..
- *	   no files means all fds.
- *
- * output: if only one field is specified, that fields' contents are printed.
- *         if more than one field is specified, the output is
- *	   file	filed1: f1val, field2: f2val, etc
- *
- * written: Larry McVoy, (mcvoy@rsch.wisc.edu)  
- */
-
-# define	ALLDEF		/* Make -all default. (kjb) */
-
-# include	<sys/types.h>
-# include	<errno.h>
-# include	<limits.h>
-# include	<stdio.h>
-# include	<stdlib.h>
-# include	<unistd.h>
-# include 	<string.h>
-# include	<time.h>
-# include	<sys/stat.h>
-# define	addr(x)		((void*) &sbuf.x)
-# define	size(x)		sizeof(sbuf.x)
-# define	equal(s, t)	(strcmp(s, t) == 0)
-# ifndef PATH_MAX
-#  define	PATH_MAX	1024
-# endif
-# undef		LS_ADDS_SPACE	/* AT&T Unix PC, ls prints "file[* /]" */
-				/* This makes stat fail. */
-
-# ifndef _MINIX			/* All but Minix have u_* and st_blocks */
-#  define BSD
-# endif
-
-# ifndef S_IREAD
-#  define S_IREAD	S_IRUSR
-#  define S_IWRITE	S_IWUSR
-#  define S_IEXEC	S_IXUSR
-# endif
-
-char *      arg0;
-struct stat sbuf;
-extern int  errno;
-int	    first_file= 1;
-#ifndef S_IFLNK
-#define lstat	stat
-#endif
-
-struct field {
-    char* f_name;	/* field name in stat */
-    u_char* f_addr;	/* address of the field in sbuf */
-    u_short f_size;	/* size of the object, needed for pointer arith */
-    u_short f_print;	/* show this field? */
-} fields[] = {
-    { "dev",		addr(st_dev),		size(st_dev),		0 },
-    { "ino",		addr(st_ino),		size(st_ino),		0 },
-    { "mode",		addr(st_mode),		size(st_mode),		0 },
-    { "nlink",		addr(st_nlink),		size(st_nlink),		0 },
-    { "uid",		addr(st_uid),		size(st_uid),		0 },
-    { "gid",		addr(st_gid),		size(st_gid),		0 },
-    { "rdev",		addr(st_rdev),		size(st_rdev),		0 },
-    { "size",		addr(st_size),		size(st_size),		0 },
-    { "Atime",		addr(st_atime),		size(st_atime),		0 },
-    { "atime",		addr(st_atime),		size(st_atime),		0 },
-    { "Mtime",		addr(st_mtime),		size(st_mtime),		0 },
-    { "mtime",		addr(st_mtime),		size(st_mtime),		0 },
-    { "Ctime",		addr(st_ctime),		size(st_ctime),		0 },
-    { "ctime",		addr(st_ctime),		size(st_ctime),		0 },
-# ifdef BSD
-    { "blksize", 	addr(st_blksize),	size(st_blksize),	0 },
-    { "blocks",		addr(st_blocks),	size(st_blocks),	0 },
-# endif
-    { NULL,		0,			0,			0 },
-};
-    
-void printstat(struct stat *sbuf, int nprint);
-void printit(struct stat* sb, struct field* f, int n);
-void rwx(mode_t mode, char *bit);
-void usage(void);
-
-int do_readlink=0;
-
-int main(int ac, char** av)
-{
-    int      i, j, nprint = 0, files = 0;
-    char     buf[PATH_MAX], *check;
-    int      sym=0, ret=0, from_stdin = 0;
-    int      err;
-    u_long   fd;
-
-    if ((arg0 = strrchr(av[0], '/')) == NULL) arg0 = av[0]; else arg0++;
-#ifdef S_IFLNK
-    if (equal(arg0, "lstat")) sym = 1;
-    if (equal(arg0, "readlink")) do_readlink = 1;
-#endif
-
-    if (ac > 1 && equal(av[i = 1], "-"))
-	i++, from_stdin++;
-
-    for (i= 1; i<ac; i++)  {
-	if (av[i][0] == '-')  {
-	    if (equal(av[i], "-")) {
-		from_stdin= 1;
-		files++;
-		continue;
-	    }
-	    if (equal("-all", av[i])) {
-		for (j=0; fields[j].f_name; j++)
-		    nprint++, fields[j].f_print++;
-		continue;
-	    }
-	    if (equal("-s", av[i])) {
-#ifdef S_IFLNK
-		sym=1;
-#endif
-		continue;
-	    }
-	    fd = strtoul(av[i]+1, &check, 0);
-	    if (check != av[i]+1 && *check == '\0')
-	    {
-		files++;
-		continue;
-	    }
-	    for (j=0; fields[j].f_name; j++) 
-		if (equal(fields[j].f_name, &av[i][1])) {
-		    nprint++, fields[j].f_print++;
-		    break;
-		}
-	    if (!fields[j].f_name) {
-		if (!equal("-?", av[i])) {
-		    fprintf(stderr, "stat: %s: bad field\n", av[i]);
-		}
-		usage();
-	    }
-	}
-	else 
-	    files++;
-    }
-    if (!nprint) {
-# ifndef ALLDEF
-	usage();
-# else
-	for (j=0; fields[j].f_name; j++)
-	    nprint++, fields[j].f_print++;
-# endif
-    }
-
-    if (from_stdin)
-	files++;	/* We don't know how many files come from stdin. */
-
-    if (files == 0) {	/* Stat all file descriptors. */
-	if(do_readlink) return 0;
-	for (i= 0; i<OPEN_MAX; i++) {
-	    err= fstat(i, &sbuf);
-	    if (err == -1 && errno == EBADF)
-		continue;
-	    if (err == 0) {
-		if (!first_file) fputc('\n', stdout);
-		printf("fd %d:\n", i);
-		printstat(&sbuf, nprint);
-	    }
-	    else {
-		fprintf(stderr, "%s: fd %d: %s\n", arg0, i, strerror(errno));
-		ret= 1;
-	    }
-	}
-	exit(ret);
-    }
-		
-    for (i=1; i<ac; i++) {
-	if (equal(av[i], "-")) {
-	    while (fgets(buf, sizeof(buf), stdin)) {
-	    	char *p= strchr(buf, '\n');
-	    	if (p) *p= 0;
-#ifdef S_IFLNK
-		if(do_readlink) {
-			char sbuf[300];
-			int n;
-			if((n=readlink(buf, sbuf, sizeof(sbuf)-1)) < 0) {
-				perror(buf);
-				continue;
-			}
-			sbuf[n] = '\0';
-			printf("%s: %s\n", buf, sbuf);
-			continue;
-		}
-#endif
-		if (!sym) err= stat(av[i], &sbuf);
-		if (sym || (err != 0 && errno == ENOENT)) {
-		    err= lstat(av[i], &sbuf);
-		}
-		if (err == -1) {
-		    fprintf(stderr, "%s: %s: %s\n",
-			arg0, av[i], strerror(errno));
-		    ret= 1;
-		}
-		else {
-		    if (!first_file) fputc('\n', stdout);
-		    printf("%s:\n", buf);
-		    printstat(&sbuf, nprint);
-		}
-	    }
-	    continue;
-	}
-	if (av[i][0] == '-') {
-	    fd= strtoul(av[i]+1, &check, 10);
-	    if (check == av[i]+1 || *check != '\0') continue;
-	    if (fd >= INT_MAX) {
-		err= -1;
-		errno= EBADF;
-	    }
-	    else {
-		err= fstat((int) fd, &sbuf);
-	    }
-	    if (err != -1) {
-		if (!first_file) fputc('\n', stdout);
-		if (files != 1) printf("fd %lu:\n", fd);
-		printstat(&sbuf, nprint);
-	    }
-	    else {
-		fprintf(stderr, "fd %lu: %s\n", fd, strerror(errno));
-		ret= 1;
-	    }
-	    continue;
-	}
-	if(do_readlink) {
-		char sbuf[300];
-		int n;
-		if((n=err=readlink(av[i], sbuf, sizeof(sbuf)-1)) < 0) {
-			perror(av[i]);
-			continue;
-		}
-		sbuf[n] = '\0';
-		printf("%s: %s\n", av[i], sbuf);
-		continue;
-	}
-	if (!sym) err= stat(av[i], &sbuf);
-	if (sym || (err != 0 && errno == ENOENT)) err= lstat(av[i], &sbuf);
-	if (err != -1) {
-	    if (!first_file) fputc('\n', stdout);
-	    if (files != 1) printf("%s:\n", av[i]);
-	    printstat(&sbuf, nprint);
-	}
-	else {
-	    fprintf(stderr, "%s: %s: %s\n", arg0, av[i], strerror(errno));
-	    ret= 1;
-	}
-    }
-    exit(ret);
-}
-
-/*------------------------------------------------------------------30/Jan/87-*
- * printstat(file, nprint) - do the work
- *----------------------------------------------------------------larry mcvoy-*/
-void printstat(struct stat *sbuf, int nprint)
-{
-    int      j;
-    int      first_field= 1;
-
-    for (j=0; fields[j].f_name; j++) {
-	if (fields[j].f_print) {
-	    if (!first_field) fputc('\n', stdout);
-	    printit(sbuf, &fields[j], nprint);
-	    first_field= 0;
-	}
-    }
-    fputc('\n', stdout);
-    first_file= 0;
-}
-
-/*------------------------------------------------------------------30/Jan/87-*
- * printit(sb, f, n) - print the field
- *
- * Inputs    -> (struct stat*), (struct field*), (int)
- *
- * Results   -> Displays the field, with special handling of weird fields like
- *		mode and mtime.  The mode field is dumped in octal, followed
- *		by one or more of the S_IF<X> and/or S_I<X> values.
- *----------------------------------------------------------------larry mcvoy-*/
-void printit(struct stat* sb, struct field* f, int n)
-{
-    if (n > 1)
-	printf("%s: ", f->f_name);
-    if (equal(f->f_name, "mode")) {
-		/* This lot changed to my personal liking. (kjb) */
-	char bit[11];
-
-	printf("%07lo, ", (u_long) sb->st_mode);
-
-	strcpy(bit, "----------");
-
-	switch (sb->st_mode&S_IFMT) {
-	case S_IFDIR:	bit[0]='d';	break;
-# ifdef S_IFFIFO
-	case S_IFFIFO:	bit[0]='p';	break;
-# endif
-	case S_IFCHR:	bit[0]='c';	break;
-	case S_IFBLK:	bit[0]='b';	break;
-# ifdef S_IFSOCK
-	case S_IFSOCK:	bit[0]='S';	break;
-# endif
-# ifdef S_IFMPC
-	case S_IFMPC:	bit[0]='C';	break;
-# endif
-# ifdef S_IFMPB
-	case S_IFMPB:	bit[0]='B';	break;
-# endif
-# ifdef S_IFLNK
-	case S_IFLNK:	bit[0]='l';	break;
-# endif
-	}
-	rwx(sb->st_mode, bit+1);
-	rwx(sb->st_mode<<3, bit+4);
-	rwx(sb->st_mode<<6, bit+7);
-	if (sb->st_mode&S_ISUID)	bit[3]='s';
-	if (sb->st_mode&S_ISGID)	bit[6]='s';
-	if (sb->st_mode&S_ISVTX)	bit[9]='t';
-	printf("\"%s\"", bit);
-    }
-    /* times in human form, uppercase first letter */
-    else if (equal("Ctime", f->f_name)) {
-	printf("%.24s (%lu)", ctime(&sb->st_ctime), (u_long) sb->st_ctime);
-	f[1].f_print= 0;
-    }
-    else if (equal("Mtime", f->f_name)) {
-	printf("%.24s (%lu)", ctime(&sb->st_mtime), (u_long) sb->st_mtime);
-	f[1].f_print= 0;
-    }
-    else if (equal("Atime", f->f_name)) {
-	printf("%.24s (%lu)", ctime(&sb->st_atime), (u_long) sb->st_atime);
-	f[1].f_print= 0;
-    }
-    else if (equal("ctime", f->f_name)) {
-	printf("%lu", (u_long) sb->st_ctime);
-    }
-    else if (equal("mtime", f->f_name)) {
-	printf("%lu", (u_long) sb->st_mtime);
-    }
-    else if (equal("atime", f->f_name)) {
-	printf("%lu", (u_long) sb->st_atime);
-    }
-    else {
-	switch (f->f_size) {
-	case sizeof(char):
-	    printf("%d", * (u_char *) f->f_addr);
-	    break;
-	case sizeof(short):
-	    printf("%u", (u_int) * (u_short *) f->f_addr);
-	    break;
-#if INT_MAX != SHRT_MAX
-	case sizeof(int):
-	    printf("%u", * (u_int *) f->f_addr);
-	    break;
-#endif
-#if LONG_MAX != INT_MAX && LONG_MAX != SHRT_MAX
-	case sizeof(long):
-	    printf("%lu", * (u_long *) f->f_addr);
-	    break;
-#endif
-	default:
-	    fprintf(stderr, "\nProgram error: bad '%s' field size %d\n", 
-			    f->f_name, f->f_size);
-	    break;
-	}
-    }
-}
-
-void rwx(mode_t mode, char *bit)
-{
-	if (mode&S_IREAD)	bit[0]='r';
-	if (mode&S_IWRITE)	bit[1]='w';
-	if (mode&S_IEXEC)	bit[2]='x';
-}
-
-void usage(void)
-{
-    fprintf(stderr,
-	"Usage: %s [-] [-fd] [-all] [-s] [-field ...] [file1 ...]\n", 
-	arg0);
-    exit(1);
-}
Index: trunk/minix/commands/simple/strings.c
===================================================================
--- trunk/minix/commands/simple/strings.c	(revision 9)
+++ 	(revision )
@@ -1,139 +1,0 @@
-/* strings - print ASCII strings in a file	Author: Peter S. Housel */
-
-/*
-  This is a version of the BSD "strings" program for Minix. It is used
-  to search a file for printable strings. To install,
-
-  cc -o strings strings.c
-  chmem =8000 strings
-
-Command:  strings - search file for printable strings
-Syntax:	  strings [-] [-o] [-len] file ...
-Flags:	  -	Search the entire file. If this option is not given, only
-	 	the initialized data segment of files that appear to be
-		"a.out" format is searched.
-    	  -o	Print the offset (in octal) with each string.
-          -len	Use "len" as the minimum string length. The default is 4.
-
-Examples: strings core
-	  strings -o a.out > str
-
-Strings searches the specified file(s) for printable ASCII strings (four
-or more printable characters followed by a newline or a null) and writes
-them to the standard output. This can be used to find out, for example, to
-find out what program a "core" file came from, what kinds of error messages
-are in an executable, or to see ASCII data hidden in a "binary" data file.
-
-P.S. The program doesn't use the "a.out.h" file posted last week by
-Dick van Veen, both because it was written before then, and because
-not everybody has a.out.h yet. Future revisions probably ought to, though.
-
-*/
-
-
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-/* Minix (8086 version) dependant definitions */
-#define SMALLMAGIC	0x04100301L	/* small model a.out magic number */
-#define SEPARATEMAGIC	0x04200301L	/* separate instruction/data a.out */
-
-#define HDR_MAGIC	0	/* 0'th long  magic number */
-#define HDR_HSIZE	1	/* 1'st long  size of header */
-#define HDR_TSIZE	2	/* 2'nd long  size of text */
-#define HDR_DSIZE	3	/* 3'rd long  size of init'ed data */
-#define HDR_BSIZE	4	/* 4'th long  size of bss */
-#define HDR_TOTMEM	6	/* 6'th long  total memory */
-
-#define HDR_LEN		8	/* total length of header */
-
-/* Miscellaneous definitions */
-#define	STRLEN		4	/* default minimum string length */
-#define STRBUF		512	/* buffer length for strings */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void strings, (char *filename));
-_PROTOTYPE(void usage, (void));
-
-int strmin = STRLEN;		/* minimum string length */
-int printoff = 0;		/* print octal offset of each str */
-int objall = 0;			/* search entire a.out file, not */
-
-/* Just initialized data segment */
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  while ((++argv, --argc) && '-' == (*argv)[0]) {
-	if (!strcmp(*argv, "-"))
-		++objall;
-	else if (!strcmp(*argv, "-o"))
-		++printoff;
-	else if (isdigit((*argv)[1]))
-		strmin = atoi(&(*argv)[1]);
-	else
-		usage();
-  }
-
-  if (0 == argc) usage();
-  while (argc--) strings(*argv++);
-  return(0);
-}
-
-void strings(filename)
-char *filename;
-{
-  char buf[STRBUF];		/* the strings buffer */
-  char *bufptr;			/* pointer into the strings buffer */
-  FILE *input;			/* input file */
-  long header[HDR_LEN];		/* buffer for reading the header */
-  long offset;			/* file offset */
-  long limit;			/* limit, if doing data segment only */
-  int c;			/* input character */
-
-  if (NULL == (input = fopen(filename, "r"))) {
-	fprintf(stderr, "strings: ");
-	perror(filename);
-	exit(1);
-  }
-  if (HDR_LEN == fread(header, sizeof(long), (size_t)HDR_LEN, input)
-      && (SMALLMAGIC == header[HDR_MAGIC]
-	||SEPARATEMAGIC == header[HDR_MAGIC]) && !objall) {
-	offset = header[HDR_HSIZE] + header[HDR_TSIZE];	/* object file */
-	limit = offset + header[HDR_DSIZE];
-  } else {
-	offset = 0L;
-	limit = 0L;
-  }
-
-  fseek(input, offset, 0);
-  bufptr = buf;
-
-  while (!limit || offset < limit) {
-	if (EOF == (c = getc(input))) break;
-	if ((('\0' == c || '\n' == c) && bufptr - buf >= strmin)
-	    || (bufptr - buf == STRBUF - 1)) {
-		*bufptr = '\0';
-		if (printoff) printf("%lo:", offset - (bufptr - buf));
-		puts(buf);
-		bufptr = buf;
-	} else if ((' ' <= c && c < 0177) || '\t' == c)
-		*bufptr++ = c;
-	else
-		bufptr = buf;
-
-	++offset;
-  }
-
-  fclose(input);
-}
-
-void usage()
-{
-  fprintf(stderr, "usage: strings [-] [-o] [-num] file ...\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/strip.c
===================================================================
--- trunk/minix/commands/simple/strip.c	(revision 9)
+++ 	(revision )
@@ -1,169 +1,0 @@
-/* strip - remove symbols.		Author: Dick van Veen */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <a.out.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-/* Strip [file] ...
- *
- *	-	when no file is present, a.out is assumed.
- *
- */
-
-#define A_OUT		"a.out"
-#define NAME_LENGTH	128	/* max file path name */
-
-char buffer[BUFSIZ];		/* used to copy executable */
-char new_file[NAME_LENGTH];	/* contains name of temporary */
-struct exec header;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void strip, (char *file));
-_PROTOTYPE(int read_header, (int fd));
-_PROTOTYPE(int write_header, (int fd));
-_PROTOTYPE(int make_tmp, (char *new_name, char *name));
-_PROTOTYPE(int copy_file, (int fd1, int fd2, long size));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  argv++;
-  if (*argv == NULL)
-	strip(A_OUT);
-  else
-	while (*argv != NULL) {
-		strip(*argv);
-		argv++;
-	}
-  return(0);
-}
-
-void strip(file)
-char *file;
-{
-  int fd, new_fd;
-  struct stat buf;
-  long symb_size, relo_size;
-
-  fd = open(file, O_RDONLY);
-  if (fd == -1) {
-	fprintf(stderr, "can't open %s\n", file);
-	close(fd);
-	return;
-  }
-  if (read_header(fd)) {
-	fprintf(stderr, "%s: not an executable file\n", file);
-	close(fd);
-	return;
-  }
-  if (header.a_syms == 0L) {
-	close(fd);		/* no symbol table present */
-	return;
-  }
-  symb_size = header.a_syms;
-  header.a_syms = 0L;		/* remove table size */
-  fstat(fd, &buf);
-  relo_size = buf.st_size - (A_MINHDR + header.a_text + header.a_data + symb_size);
-  new_fd = make_tmp(new_file, file);
-  if (new_fd == -1) {
-	fprintf(stderr, "can't create temporary file\n");
-	close(fd);
-	return;
-  }
-  if (write_header(new_fd)) {
-	fprintf(stderr, "can't write temporary file\n");
-	unlink(new_file);
-	close(fd);
-	close(new_fd);
-	return;
-  }
-  if (copy_file(fd, new_fd, header.a_text + header.a_data)) {
-	fprintf(stderr, "can't copy %s\n", file);
-	unlink(new_file);
-	close(fd);
-	close(new_fd);
-	return;
-  }
-  if (relo_size != 0) {
-	lseek(fd, symb_size, 1);
-	if (copy_file(fd, new_fd, relo_size)) {
-	    fprintf(stderr, "can't copy %s\n", file);
-	    unlink(new_file);
-	    close(fd);
-	    close(new_fd);
-	    return;
-	}
-  }
-  close(fd);
-  close(new_fd);
-  if (unlink(file) == -1) {
-	fprintf(stderr, "can't unlink %s\n", file);
-	unlink(new_file);
-	return;
-  }
-  link(new_file, file);
-  unlink(new_file);
-  chmod(file, buf.st_mode);
-}
-
-int read_header(fd)
-int fd;
-{
-  if (read(fd, (char *) &header, A_MINHDR) != A_MINHDR) return(1);
-  if (BADMAG(header)) return (1);
-  if (header.a_hdrlen > sizeof(struct exec)) return (1);
-  lseek(fd, 0L, SEEK_SET);	/* variable size header */
-  if (read(fd, (char *)&header, (int)header.a_hdrlen) != (int) header.a_hdrlen)
-	return(1);
-  return(0);
-}
-
-int write_header(fd)
-int fd;
-{
-  lseek(fd, 0L, SEEK_SET);
-  if (write(fd, (char *)&header, (int)header.a_hdrlen) != (int)header.a_hdrlen)
-	return(1);
-  return(0);
-}
-
-int make_tmp(new_name, name)
-char *new_name, *name;
-{
-  int len;
-  char *nameptr;
-
-  len = strlen(name);
-  if (len + 1 > NAME_LENGTH) return(-1);
-  strcpy(new_name, name);
-  nameptr = strrchr(new_name, '/');
-  if (nameptr == NULL) nameptr = new_name - 1;
-  if (nameptr - new_name + 6 + 1 > NAME_LENGTH) return (-1);
-  strcpy(nameptr + 1, "XXXXXX");
-  mktemp(new_name);
-  return(creat(new_name, 0777));
-}
-
-int copy_file(fd1, fd2, size)
-int fd1, fd2;
-long size;
-{
-  int length;
-
-  while (size > 0) {
-	if (size < sizeof(buffer))
-		length = size;
-	else
-		length = sizeof(buffer);
-	if (read(fd1, buffer, length) != length) return(1);
-	if (write(fd2, buffer, length) != length) return (1);
-	size -= length;
-  }
-  return(0);
-}
Index: trunk/minix/commands/simple/stty.c
===================================================================
--- trunk/minix/commands/simple/stty.c	(revision 9)
+++ 	(revision )
@@ -1,1277 +1,0 @@
-/* stty - set terminal mode	  	Author: Andy Tanenbaum */
-
-/*
-	Adapted to POSIX 1003.2 by Philip Homburg.
- */
-
-#ifdef __minix_vmd
-#define _MINIX_SOURCE
-#endif
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#ifdef __minix
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#endif
-
-/* Default settings, the Minix ones are defined in <termios.h> */
-
-#ifndef TCTRL_DEF
-#define TCTRL_DEF	(PARENB | CREAD | CS7)
-#endif
-
-#ifndef TSPEED_DEF
-#define TSPEED_DEF	B1200
-#endif
-
-#ifndef TINPUT_DEF
-#define TINPUT_DEF	(BRKINT | IGNPAR | ISTRIP | ICRNL)
-#endif
-
-#ifndef TOUTPUT_DEF
-#define TOUTPUT_DEF	OPOST
-#endif
-
-#ifndef TLOCAL_DEF
-#define TLOCAL_DEF	(ISIG | IEXTEN | ICANON | ECHO | ECHOE)
-#endif
-
-#ifndef TEOF_DEF
-#define TEOF_DEF	'\4'	/* ^D */
-#endif
-#ifndef TEOL_DEF
-#ifdef _POSIX_VDISABLE
-#define TEOL_DEF	_POSIX_VDISABLE
-#else
-#define TEOL_DEF	'\n'
-#endif
-#endif
-#ifndef TERASE_DEF
-#define TERASE_DEF	'\10'	/* ^H */
-#endif
-#ifndef TINTR_DEF
-#define TINTR_DEF	'\177'	/* ^? */
-#endif
-#ifndef TKILL_DEF
-#define TKILL_DEF	'\25'	/* ^U */
-#endif
-#ifndef TQUIT_DEF
-#define TQUIT_DEF	'\34'	/* ^\ */
-#endif
-#ifndef TSUSP_DEF
-#define TSUSP_DEF	'\32'	/* ^Z */
-#endif
-#ifndef TSTART_DEF
-#define TSTART_DEF	'\21'	/* ^Q */
-#endif
-#ifndef TSTOP_DEF
-#define TSTOP_DEF	'\23'	/* ^S */
-#endif
-#ifndef TMIN_DEF
-#define TMIN_DEF	1
-#endif
-#ifndef TTIME_DEF
-#define TTIME_DEF	0
-#endif
-
-
-
-char *prog_name;
-struct termios termios;
-int column= 0, max_column=80;		/* Assume 80 character terminals. */
-#ifdef __minix
-struct winsize winsize;
-#endif
-
-#if __minix
-#define PROTO(a) _ARGS(a)
-#else
-#define PROTO(a) ()
-#endif
-
-void main PROTO(( int argc, char **argv ));
-void report PROTO(( int flags ));
-int option PROTO(( char *opt, char *next ));
-int match PROTO(( char *s1, char *s2 ));
-void prctl PROTO(( int c ));
-speed_t long2speed PROTO(( long num ));
-long speed2long PROTO(( unsigned long speed ));
-void print_flags PROTO(( unsigned long flags, unsigned long flag,
-				unsigned long def, char *string, int all ));
-void output PROTO(( char *s ));
-void do_print_char PROTO(( unsigned chr, unsigned def, char *name, int all ));
-void do_print_num PROTO(( unsigned num, unsigned def, char *name, int all ));
-void set_saved_settings PROTO(( char *opt ));
-void set_control PROTO(( int option, char *value ));
-void set_min_tim PROTO(( int option, char *value ));
-
-#define print_char(c,d,n,a) (do_print_char((unsigned)(c),(unsigned)(d),(n),(a)))
-#define print_num(m,d,n,a) (do_print_num((unsigned)(m),(unsigned)(d),(n),(a)))
-
-void main(argc, argv)
-int argc;
-char *argv[];
-{
-  int flags, k;
-
-  prog_name= argv[0];
-  flags= 0;
-
-  /* Stty with no arguments just reports on current status. */
-  if (tcgetattr(0, &termios) == -1)
-  {
-	fprintf(stderr, "%s: can't read ioctl parameters from stdin: %s\n",
-		prog_name, strerror(errno));
-	exit(1);
-  }
-#ifdef __minix
-  if (ioctl(0, TIOCGWINSZ, &winsize) == -1)
-  {
-	fprintf(stderr, "%s: can't get screen size from stdin: %s\n",
-		prog_name, strerror(errno));
-	exit(1);
-  }
-  if (winsize.ws_col != 0)
-	max_column= winsize.ws_col;
-#endif
-
-  if (argc == 2)
-  {
-	if (!strcmp(argv[1], "-a"))
-		flags |= 1;
-	else if (!strcmp(argv[1], "-g"))
-		flags |= 2;
-  }
-  if (argc == 1 || flags) {
-	report(flags);
-	exit(0);
-  }
-
-  /* Process the options specified. */
-  for (k= 1; k < argc; k++)
-	k += option(argv[k], k+1 < argc ? argv[k+1] : "");
-
-#ifdef __minix
-  if (ioctl(0, TIOCSWINSZ, &winsize) == -1)
-  {
-	fprintf(stderr, "%s: can't set screen size to stdin: %s\n",
-		prog_name, strerror(errno));
-	exit(1);
-  }
-#endif
-  if (tcsetattr(0, TCSANOW, &termios) == -1)
-  {
-	fprintf(stderr, "%s: can't set terminal parameters to stdin: %s\n",
-		prog_name, strerror(errno));
-	exit(1);
-  }
-  exit(0);
-}
-
-
-
-void report(flags)
-int flags;
-{
-	int i, all;
-	tcflag_t c_cflag, c_iflag, c_oflag, c_lflag;
-	char line[80];
-	speed_t ispeed, ospeed;
-
-	if (flags & 2)
-	{	/* We have to write the termios structure in a encoded form
-		 * to stdout.
-		 */
-		printf(":%x:%x:%x:%x:%x:%x", termios.c_iflag, termios.c_oflag,
-			termios.c_cflag, termios.c_lflag, cfgetispeed(&termios),
-			cfgetospeed(&termios));
-		for (i= 0; i<NCCS; i++)
-			printf(":%x", termios.c_cc[i]);
-		printf(":\n");
-		return;
-	}
-
-	all= !!flags;
-
-	/* Start with the baud rate. */
-	ispeed= cfgetispeed(&termios);
-	ospeed= cfgetospeed(&termios);
-	if (ispeed != ospeed)
-	{
-		sprintf(line, "ispeed %lu baud; ospeed %lu baud;", 
-			speed2long(ispeed), speed2long(ospeed));
-		output(line);
-	}
-	else if (all || ospeed != TSPEED_DEF)
-	{
-		sprintf(line, "speed %lu baud;", speed2long(ospeed));
-		output(line);
-	}
-
-	/* The control modes. */
-
-	c_cflag= termios.c_cflag;
-	if (all || (c_cflag & CSIZE) != (TCTRL_DEF & CSIZE))
-	{
-		switch (c_cflag & CSIZE)
-		{
-		case CS5: output("cs5"); break;
-		case CS6: output("cs6"); break;
-		case CS7: output("cs7"); break;
-		case CS8: output("cs8"); break;
-		default: output("cs??"); break;
-		}
-	}
-	print_flags(c_cflag, PARENB, TCTRL_DEF, "-parenb", all);
-	print_flags(c_cflag, PARODD, TCTRL_DEF, "-parodd", all);
-	print_flags(c_cflag, HUPCL, TCTRL_DEF, "-hupcl", all);
-	print_flags(c_cflag, CSTOPB, TCTRL_DEF, "-cstopb", all);
-	print_flags(c_cflag, CREAD, TCTRL_DEF, "-cread", all);
-	print_flags(c_cflag, CLOCAL, TCTRL_DEF, "-clocal", all);
-		
-	if (all)
-	{
-		printf("\n");
-		column= 0;
-	}
-
-	/* The input flags. */
-
-	c_iflag= termios.c_iflag;
-
-	print_flags(c_iflag, IGNBRK, TINPUT_DEF, "-ignbrk", all);
-	print_flags(c_iflag, BRKINT, TINPUT_DEF, "-brkint", all);
-	print_flags(c_iflag, IGNPAR, TINPUT_DEF, "-ignpar", all);
-	print_flags(c_iflag, PARMRK, TINPUT_DEF, "-parmrk", all);
-	print_flags(c_iflag, INPCK, TINPUT_DEF, "-inpck", all);
-	print_flags(c_iflag, ISTRIP, TINPUT_DEF, "-istrip", all);
-	print_flags(c_iflag, INLCR, TINPUT_DEF, "-inlcr", all);
-	print_flags(c_iflag, IGNCR, TINPUT_DEF, "-igncr", all);
-	print_flags(c_iflag, ICRNL, TINPUT_DEF, "-icrnl", all);
-	print_flags(c_iflag, IXON, TINPUT_DEF, "-ixon", all);
-	print_flags(c_iflag, IXOFF, TINPUT_DEF, "-ixoff", all);
-	print_flags(c_iflag, IXANY, TINPUT_DEF, "-ixany", all);
-	
-	if (all)
-	{
-		printf("\n");
-		column= 0;
-	}
-
-	/* The output flags. */
-
-	c_oflag= termios.c_oflag;
-
-	print_flags(c_oflag, OPOST, TOUTPUT_DEF, "-opost", all);
-#ifdef __minix
-	print_flags(c_oflag, ONLCR, TOUTPUT_DEF, "-onlcr", all);
-	print_flags(c_oflag, XTABS, TOUTPUT_DEF, "-xtabs", all);
-	print_flags(c_oflag, ONOEOT, TOUTPUT_DEF, "-onoeot", all);
-#endif
-	if (all)
-	{
-		printf("\n");
-		column= 0;
-	}
-
-	/* The local flags. */
-
-	c_lflag= termios.c_lflag;
-
-	print_flags(c_lflag, ISIG, TLOCAL_DEF, "-isig", all);
-	print_flags(c_lflag, ICANON, TLOCAL_DEF, "-icanon", all);
-	print_flags(c_lflag, IEXTEN, TLOCAL_DEF, "-iexten", all);
-	print_flags(c_lflag, ECHO, TLOCAL_DEF, "-echo", all);
-	print_flags(c_lflag, ECHOE, TLOCAL_DEF, "-echoe", all);
-	print_flags(c_lflag, ECHOK, TLOCAL_DEF, "-echok", all);
-	print_flags(c_lflag, ECHONL, TLOCAL_DEF, "-echonl", all);
-	print_flags(c_lflag, NOFLSH, TLOCAL_DEF, "-noflsh", all);
-#ifdef TOSTOP
-	print_flags(c_lflag, TOSTOP, TLOCAL_DEF, "-tostop", all);
-#endif
-#ifdef __minix
-	print_flags(c_lflag, LFLUSHO, TLOCAL_DEF, "-lflusho", all);
-#endif
-
-	if (all)
-	{
-		printf("\n");
-		column= 0;
-	}
-
-	/* The special control characters. */
-
-	print_char(termios.c_cc[VEOF], TEOF_DEF, "eof", all);
-	print_char(termios.c_cc[VEOL], TEOL_DEF, "eol", all);
-	print_char(termios.c_cc[VERASE], TERASE_DEF, "erase", all);
-	print_char(termios.c_cc[VINTR], TINTR_DEF, "intr", all);
-	print_char(termios.c_cc[VKILL], TKILL_DEF, "kill", all);
-	print_char(termios.c_cc[VQUIT], TQUIT_DEF, "quit", all);
-	print_char(termios.c_cc[VSUSP], TSUSP_DEF, "susp", all);
-	print_char(termios.c_cc[VSTART], TSTART_DEF, "start", all);
-	print_char(termios.c_cc[VSTOP], TSTOP_DEF, "stop", all);
-#ifdef __minix
-	print_char(termios.c_cc[VREPRINT], TREPRINT_DEF, "rprnt", all);
-	print_char(termios.c_cc[VLNEXT], TLNEXT_DEF, "lnext", all);
-	print_char(termios.c_cc[VDISCARD], TDISCARD_DEF, "flush", all);
-#endif
-	print_num(termios.c_cc[VMIN], TMIN_DEF, "min", all);
-	print_num(termios.c_cc[VTIME], TTIME_DEF, "time", all);
-	if (all)
-	{
-		printf("\n");
-		column= 0;
-	}
-
-#ifdef __minix
-	/* Screen size */
-	if (all || winsize.ws_row != 0 || winsize.ws_col != 0)
-	{
-		sprintf(line, "%d rows %d columns", winsize.ws_row, 
-			winsize.ws_col);
-		output(line);
-	}
-
-	if (all || winsize.ws_ypixel != 0 || winsize.ws_xpixel != 0)
-	{
-		sprintf(line, "%d ypixels %d xpixels", winsize.ws_ypixel, 
-			winsize.ws_xpixel);
-		output(line);
-	}
-
-	if (all)
-	{
-		printf("\n");
-		column= 0;
-	}
-#endif
-
-	if (column != 0)
-	{
-		printf("\n");
-		column= 0;
-	}
-}
-
-int option(opt, next)
-char *opt, *next;
-{
-  char *check;
-  speed_t speed;
-  long num;
-
-  /* The control options. */
-
-  if (match(opt, "clocal")) {
-	termios.c_cflag |= CLOCAL;
-	return 0;
-  }
-  if (match(opt, "-clocal")) {
-	termios.c_cflag &= ~CLOCAL;
-	return 0;
-  }
-
-  if (match(opt, "cread")) {
-	termios.c_cflag |= CREAD;
-	return 0;
-  }
-  if (match(opt, "-cread")) {
-	termios.c_cflag &= ~CREAD;
-	return 0;
-  }
-
-  if (match(opt, "cs5")) {
-	termios.c_cflag &= ~CSIZE;
-	termios.c_cflag |= CS5;
-	return 0;
-  }
-  if (match(opt, "cs6")) {
-	termios.c_cflag &= ~CSIZE;
-	termios.c_cflag |= CS6;
-	return 0;
-  }
-  if (match(opt, "cs7")) {
-	termios.c_cflag &= ~CSIZE;
-	termios.c_cflag |= CS7;
-	return 0;
-  }
-  if (match(opt, "cs8")) {
-	termios.c_cflag &= ~CSIZE;
-	termios.c_cflag |= CS8;
-	return 0;
-  }
-
-  if (match(opt, "cstopb")) {
-	termios.c_cflag |= CSTOPB;
-	return 0;
-  }
-  if (match(opt, "-cstopb")) {
-	termios.c_cflag &= ~CSTOPB;
-	return 0;
-  }
-
-  if (match(opt, "hupcl") || match(opt, "hup")) {
-	termios.c_cflag |= HUPCL;
-	return 0;
-  }
-  if (match(opt, "-hupcl") || match(opt, "-hup")) {
-	termios.c_cflag &= ~HUPCL;
-	return 0;
-  }
-
-  if (match(opt, "parenb")) {
-	termios.c_cflag |= PARENB;
-	return 0;
-  }
-  if (match(opt, "-parenb")) {
-	termios.c_cflag &= ~PARENB;
-	return 0;
-  }
-
-  if (match(opt, "parodd")) {
-	termios.c_cflag |= PARODD;
-	return 0;
-  }
-  if (match(opt, "-parodd")) {
-	termios.c_cflag &= ~PARODD;
-	return 0;
-  }
-
-  num= strtol(opt, &check, 10);
-  if (check[0] == '\0')
-  {
-	speed= long2speed(num);
-	if (speed == (speed_t)-1)
-	{
-		fprintf(stderr, "%s: illegal speed: '%s'\n", prog_name, opt);
-		return 0;
-	}
-	/* Speed OK */
-	cfsetispeed(&termios, speed);
-	cfsetospeed(&termios, speed);
-	return 0;
-  }
-
-  if (match(opt, "ispeed")) {
-	num= strtol(next, &check, 10);
-	if (check != '\0')
-	{
-		speed= long2speed(num);
-		if (speed == (speed_t)-1)
-		{
-			fprintf(stderr, "%s: illegal speed: '%s'\n", prog_name, 
-									opt);
-			return 1;
-		}
-		cfsetispeed(&termios, speed);
-		return 1;
-	}
-	else
-	{
-		fprintf(stderr, "%s: invalid argument to ispeed: '%s'\n", 
-			prog_name, next);
-		return 1;
-	}
-  }
-
-  if (match(opt, "ospeed")) {
-	num= strtol(next, &check, 10);
-	if (check != '\0')
-	{
-		speed= long2speed(num);
-		if (speed == (speed_t)-1)
-		{
-			fprintf(stderr, "%s: illegal speed: '%s'\n", prog_name, 
-									opt);
-			return 1;
-		}
-		cfsetospeed(&termios, speed);
-		return 1;
-	}
-	else
-	{
-		fprintf(stderr, "%s: invalid argument to ospeed: %s\n", 
-			prog_name, next);
-		return 1;
-	}
-  }
-
-  /* Input modes. */
-
-  if (match(opt, "brkint")) {
-	termios.c_iflag |= BRKINT;
-	return 0;
-  }
-  if (match(opt, "-brkint")) {
-	termios.c_iflag &= ~BRKINT;
-	return 0;
-  }
-
-  if (match(opt, "icrnl")) {
-	termios.c_iflag |= ICRNL;
-	return 0;
-  }
-  if (match(opt, "-icrnl")) {
-	termios.c_iflag &= ~ICRNL;
-	return 0;
-  }
-
-  if (match(opt, "ignbrk")) {
-	termios.c_iflag |= IGNBRK;
-	return 0;
-  }
-  if (match(opt, "-ignbrk")) {
-	termios.c_iflag &= ~IGNBRK;
-	return 0;
-  }
-
-  if (match(opt, "igncr")) {
-	termios.c_iflag |= IGNCR;
-	return 0;
-  }
-  if (match(opt, "-igncr")) {
-	termios.c_iflag &= ~IGNCR;
-	return 0;
-  }
-
-  if (match(opt, "ignpar")) {
-	termios.c_iflag |= IGNPAR;
-	return 0;
-  }
-  if (match(opt, "-ignpar")) {
-	termios.c_iflag &= ~IGNPAR;
-	return 0;
-  }
-
-  if (match(opt, "inlcr")) {
-	termios.c_iflag |= INLCR;
-	return 0;
-  }
-  if (match(opt, "-inlcr")) {
-	termios.c_iflag &= ~INLCR;
-	return 0;
-  }
-
-  if (match(opt, "inpck")) {
-	termios.c_iflag |= INPCK;
-	return 0;
-  }
-  if (match(opt, "-inpck")) {
-	termios.c_iflag &= ~INPCK;
-	return 0;
-  }
-
-  if (match(opt, "istrip")) {
-	termios.c_iflag |= ISTRIP;
-	return 0;
-  }
-  if (match(opt, "-istrip")) {
-	termios.c_iflag &= ~ISTRIP;
-	return 0;
-  }
-
-  if (match(opt, "ixoff")) {
-	termios.c_iflag |= IXOFF;
-	return 0;
-  }
-  if (match(opt, "-ixoff")) {
-	termios.c_iflag &= ~IXOFF;
-	return 0;
-  }
-
-  if (match(opt, "ixon")) {
-	termios.c_iflag |= IXON;
-	return 0;
-  }
-  if (match(opt, "-ixon")) {
-	termios.c_iflag &= ~IXON;
-	return 0;
-  }
-
-  if (match(opt, "parmrk")) {
-	termios.c_iflag |= PARMRK;
-	return 0;
-  }
-  if (match(opt, "-parmrk")) {
-	termios.c_iflag &= ~PARMRK;
-	return 0;
-  }
-
-  if (match(opt, "ixany")) {
-	termios.c_iflag |= IXANY;
-	return 0;
-  }
-  if (match(opt, "-ixany")) {
-	termios.c_iflag &= ~IXANY;
-	return 0;
-  }
-
-  /* Output modes. */
-
-  if (match(opt, "opost")) {
-	termios.c_oflag |= OPOST;
-	return 0;
-  }
-  if (match(opt, "-opost")) {
-	termios.c_oflag &= ~OPOST;
-	return 0;
-  }
-#ifdef __minix
-  if (match(opt, "onlcr")) {
-	termios.c_oflag |= ONLCR;
-	return 0;
-  }
-  if (match(opt, "-onlcr")) {
-	termios.c_oflag &= ~ONLCR;
-	return 0;
-  }
-
-  if (match(opt, "xtabs")) {
-	termios.c_oflag |= XTABS;
-	return 0;
-  }
-  if (match(opt, "-xtabs")) {
-	termios.c_oflag &= ~XTABS;
-	return 0;
-  }
-
-  if (match(opt, "onoeot")) {
-	termios.c_oflag |= ONOEOT;
-	return 0;
-  }
-  if (match(opt, "-onoeot")) {
-	termios.c_oflag &= ~ONOEOT;
-	return 0;
-  }
-#endif
-
-  /* Local modes. */
-
-  if (match(opt, "echo")) {
-	termios.c_lflag |= ECHO;
-	return 0;
-  }
-  if (match(opt, "-echo")) {
-	termios.c_lflag &= ~ECHO;
-	return 0;
-  }
-
-  if (match(opt, "echoe")) {
-	termios.c_lflag |= ECHOE;
-	return 0;
-  }
-  if (match(opt, "-echoe")) {
-	termios.c_lflag &= ~ECHOE;
-	return 0;
-  }
-
-  if (match(opt, "echok")) {
-	termios.c_lflag |= ECHOK;
-	return 0;
-  }
-  if (match(opt, "-echok")) {
-	termios.c_lflag &= ~ECHOK;
-	return 0;
-  }
-
-  if (match(opt, "echonl")) {
-	termios.c_lflag |= ECHONL;
-	return 0;
-  }
-  if (match(opt, "-echonl")) {
-	termios.c_lflag &= ~ECHONL;
-	return 0;
-  }
-
-  if (match(opt, "icanon")) {
-	termios.c_lflag |= ICANON;
-	return 0;
-  }
-  if (match(opt, "-icanon")) {
-	termios.c_lflag &= ~ICANON;
-	return 0;
-  }
-
-  if (match(opt, "iexten")) {
-	termios.c_lflag |= IEXTEN;
-	return 0;
-  }
-  if (match(opt, "-iexten")) {
-	termios.c_lflag &= ~IEXTEN;
-	return 0;
-  }
-
-  if (match(opt, "isig")) {
-	termios.c_lflag |= ISIG;
-	return 0;
-  }
-  if (match(opt, "-isig")) {
-	termios.c_lflag &= ~ISIG;
-	return 0;
-  }
-
-  if (match(opt, "noflsh")) {
-	termios.c_lflag |= NOFLSH;
-	return 0;
-  }
-  if (match(opt, "-noflsh")) {
-	termios.c_lflag &= ~NOFLSH;
-	return 0;
-  }
-
-  if (match(opt, "tostop")) {
-	termios.c_lflag |= TOSTOP;
-	return 0;
-  }
-  if (match(opt, "-tostop")) {
-	termios.c_lflag &= ~TOSTOP;
-	return 0;
-  }
-
-#ifdef __minix
-  if (match(opt, "lflusho")) {
-	termios.c_lflag |= LFLUSHO;
-	return 0;
-  }
-  if (match(opt, "-lflusho")) {
-	termios.c_lflag &= ~LFLUSHO;
-	return 0;
-  }
-#endif
-
-  /* The special control characters. */
-  if (match(opt, "eof")) {
-	set_control(VEOF, next);
-	return 1;
-  }
-
-  if (match(opt, "eol")) {
-	set_control(VEOL, next);
-	return 1;
-  }
-
-  if (match(opt, "erase")) {
-	set_control(VERASE, next);
-	return 1;
-  }
-
-  if (match(opt, "intr")) {
-	set_control(VINTR, next);
-	return 1;
-  }
-
-  if (match(opt, "kill")) {
-	set_control(VKILL, next);
-	return 1;
-  }
-
-  if (match(opt, "quit")) {
-	set_control(VQUIT, next);
-	return 1;
-  }
-
-  if (match(opt, "susp")) {
-	set_control(VSUSP, next);
-	return 1;
-  }
-
-  if (match(opt, "start")) {
-	set_control(VSTART, next);
-	return 1;
-  }
-
-  if (match(opt, "stop")) {
-	set_control(VSTOP, next);
-	return 1;
-  }
-#ifdef __minix
-  if (match(opt, "rprnt")) {
-	set_control(VREPRINT, next);
-	return 1;
-  }
-
-  if (match(opt, "lnext")) {
-	set_control(VLNEXT, next);
-	return 1;
-  }
-
-  if (match(opt, "flush")) {
-	set_control(VDISCARD, next);
-	return 1;
-  }
-#endif
- 
-  if (match(opt, "min")) {
-	set_min_tim(VMIN, next);
-	return 1;
-  }
-
-  if (match(opt, "time")) {
-	set_min_tim(VTIME, next);
-	return 1;
-  }
-
-  /* Special modes. */
-  if (opt[0] == ':')
-  {
-	set_saved_settings(opt);
-	return 0;
-  }
-
-  if (match(opt, "cooked") || match(opt, "raw")) {
-	int x = opt[0] == 'c' ? 1 : 0;
-
-	option(x + "-icrnl", "");	/* off in raw mode, on in cooked mode */
-	option(x + "-ixon", "");
-	option(x + "-opost", "");
-	option(x + "-onlcr", "");
-	option(x + "-isig", "");
-	option(x + "-icanon", "");
-	option(x + "-iexten", "");
-	option(x + "-echo", "");
-	return 0;
-  }
-
-  if (match(opt, "evenp") || match(opt, "parity")) {
-	option("parenb", "");
-	option("cs7", "");
-	option("-parodd", "");
-	return 0;
-  }
-
-  if (match(opt, "oddp")) {
-	option("parenb", "");
-	option("cs7", "");
-	option("parodd", "");
-	return 0;
-  }
-
-  if (match(opt, "-parity") || match(opt, "-evenp") || match(opt, "-oddp")) {
-	option("-parenb", "");
-	option("cs8", "");
-	return 0;
-  }
-
-  if (match(opt, "nl")) {
-	option("icrnl", "");
-	return 0;
-  }
-
-  if (match(opt, "-nl")) {
-	option("-icrnl", "");
-	option("-inlcr", "");
-	option("-igncr", "");
-	return 0;
-  }
-
-  if (match(opt, "ek")) {
-	termios.c_cc[VERASE]= TERASE_DEF;;
-	termios.c_cc[VKILL]= TKILL_DEF;;
-	return 0;
-  }
-
-  if (match(opt, "sane"))
-  {
-	/* Reset all terminal attributes to a sane state, except things like
-	 * line speed and parity, because it can't be known what their sane
-	 * values are.
-	 */
-	termios.c_iflag= (TINPUT_DEF & ~(IGNPAR|ISTRIP|INPCK))
-		| (termios.c_iflag & (IGNPAR|ISTRIP|INPCK));
-	termios.c_oflag= (TOUTPUT_DEF & ~(XTABS))
-		| (termios.c_oflag & (XTABS));
-	termios.c_cflag= (TCTRL_DEF & ~(CLOCAL|CSIZE|CSTOPB|PARENB|PARODD))
-		| (termios.c_cflag & (CLOCAL|CSIZE|CSTOPB|PARENB|PARODD));
-	termios.c_lflag= (TLOCAL_DEF & ~(ECHOE|ECHOK))
-		| (termios.c_lflag & (ECHOE|ECHOK));
-	if (termios.c_lflag & ICANON) {
-		termios.c_cc[VMIN]= TMIN_DEF;
-		termios.c_cc[VTIME]= TTIME_DEF;
-	}
-	termios.c_cc[VEOF]= TEOF_DEF;
-	termios.c_cc[VEOL]= TEOL_DEF;
-	termios.c_cc[VERASE]= TERASE_DEF;
-	termios.c_cc[VINTR]= TINTR_DEF;
-	termios.c_cc[VKILL]= TKILL_DEF;
-	termios.c_cc[VQUIT]= TQUIT_DEF;
-	termios.c_cc[VSUSP]= TSUSP_DEF;
-#ifdef __minix
-	termios.c_cc[VREPRINT]= TREPRINT_DEF;
-	termios.c_cc[VLNEXT]= TLNEXT_DEF;
-	termios.c_cc[VDISCARD]= TDISCARD_DEF;
-#endif
-	termios.c_cc[VSTART]= TSTART_DEF;
-	termios.c_cc[VSTOP]= TSTOP_DEF;
-	if (!(termios.c_lflag & ICANON)) {
-		termios.c_cc[VMIN]= TMIN_DEF;
-		termios.c_cc[VTIME]= TTIME_DEF;
-	}
-	return 0;
-  }
-
-#ifdef __minix
-  if (match(opt, "cols"))
-  {
-  	num= strtol(next, &check, 0);
-  	if (check[0] != '\0')
-  	{
-  		fprintf(stderr, "%s: illegal parameter to cols: '%s'\n", 
-  							prog_name, next);
-  		return 1;
-  	}
-  	winsize.ws_col= num;
-	return 1;
-  }
-
-  if (match(opt, "rows"))
-  {
-  	num= strtol(next, &check, 0);
-  	if (check[0] != '\0')
-  	{
-  		fprintf(stderr, "%s: illegal parameter to rows: '%s'\n", 
-  							prog_name, next);
-  		return 1;
-  	}
-  	winsize.ws_row= num;
-	return 1;
-  }
-
-  if (match(opt, "xpixels"))
-  {
-  	num= strtol(next, &check, 0);
-  	if (check[0] != '\0')
-  	{
-  		fprintf(stderr, "%s: illegal parameter to xpixels: '%s'\n", 
-  							prog_name, next);
-  		return 1;
-  	}
-  	winsize.ws_xpixel= num;
-	return 1;
-  }
-
-  if (match(opt, "ypixels"))
-  {
-  	num= strtol(next, &check, 0);
-  	if (check[0] != '\0')
-  	{
-  		fprintf(stderr, "%s: illegal parameter to ypixels: '%s'\n", 
-  							prog_name, next);
-  		return 1;
-  	}
-  	winsize.ws_ypixel= num;
-	return 1;
-  }
-#endif /* __minix */
-
-  fprintf(stderr, "%s: unknown mode: %s\n", prog_name, opt);
-  return 0;
-}
-
-int match(s1, s2)
-char *s1, *s2;
-{
-
-  while (1) {
-	if (*s1 == 0 && *s2 == 0) return(1);
-	if (*s1 == 0 || *s2 == 0) return (0);
-	if (*s1 != *s2) return (0);
-	s1++;
-	s2++;
-  }
-}
-
-void prctl(c)
-char c;
-{
-  if (c < ' ')
-	printf("^%c", 'A' + c - 1);
-  else if (c == 0177)
-	printf("^?");
-  else
-	printf("%c", c);
-}
-
-struct s2s {
-	speed_t ts;
-	long ns;
-} s2s[] = {
-	{ B0,		     0 },
-	{ B50,		    50 },
-	{ B75,		    75 },
-	{ B110,		   110 },
-	{ B134,		   134 },
-	{ B150,		   150 },
-	{ B200,		   200 },
-	{ B300,		   300 },
-	{ B600,		   600 },
-	{ B1200,	  1200 },
-	{ B1800,	  1800 },
-	{ B2400,	  2400 },
-	{ B4800,	  4800 },
-	{ B9600,	  9600 },
-	{ B19200,	 19200 },
-	{ B38400,	 38400 },
-#ifdef __minix
-	{ B57600,	 57600 },
-	{ B115200,	115200 },
-#ifdef B230400
-	{ B230400,	230400 },
-#endif
-#ifdef B460800
-	{ B460800,	460800 },
-#endif
-#ifdef B921600
-	{ B921600,	921600 },
-#endif
-#endif
-};
-
-speed_t long2speed(num)
-long num;
-{
-	struct s2s *sp;
-
-	for (sp = s2s; sp < s2s + (sizeof(s2s) / sizeof(s2s[0])); sp++) {
-		if (sp->ns == num) return sp->ts;
-	}
-	return -1;
-}
-
-long speed2long(speed)
-unsigned long speed;
-{
-	struct s2s *sp;
-
-	for (sp = s2s; sp < s2s + (sizeof(s2s) / sizeof(s2s[0])); sp++) {
-		if (sp->ts == speed) return sp->ns;
-	}
-	return -1;
-}
-		
-void print_flags(flags, flag, def, string, all)
-unsigned long flags;
-unsigned long flag;
-unsigned long def;
-char *string;
-int all;
-{
-	if (!(flags & flag))
-	{
-		if (all || (def & flag))
-			output(string);
-		return;
-	}
-	string++;
-	if (all || !(def & flag))
-		output(string);
-}
-
-void output(s)
-char *s;
-{
-	int len;
-
-	len= strlen(s);
-	if (column + len + 3 >= max_column)
-	{
-		printf("\n");
-		column= 0;
-	}
-	if (column)
-	{
-		putchar(' ');
-		column++;
-	}
-	fputs(s, stdout);
-	column += len;
-}
-
-void do_print_char(chr, def, name, all)
-unsigned chr;
-unsigned def;
-char *name;
-int all;
-{
-	char line[20];
-
-	if (!all && chr == def)
-		return;
-	
-#ifdef _POSIX_VDISABLE
-	if (chr == _POSIX_VDISABLE)
-		sprintf(line, "%s = <undef>", name);
-	else
-#endif
-	if (chr < ' ')
-		sprintf(line, "%s = ^%c", name, chr + '@');
-	else if (chr == 127)
-		sprintf(line, "%s = ^?", name);
-	else
-		sprintf(line, "%s = %c", name, chr);
-	output(line);
-}
-
-void do_print_num(num, def, name, all)
-unsigned num;
-unsigned def;
-char *name;
-int all;
-{
-	char line[20];
-		
-	if (!all && num == def)
-		return;
-	sprintf(line, "%s = %u", name, num);
-	output(line);
-}
-
-void set_saved_settings(opt)
-char *opt;
-{
-	long num;
-	char *check;
-	tcflag_t c_oflag, c_cflag, c_lflag, c_iflag;
-	cc_t c_cc[NCCS];
-	speed_t ispeed, ospeed;
-	int i;
-
-	check= opt;
-	num= strtol(check+1, &check, 16);
-	if (check[0] != ':')
-	{
-		fprintf(stderr, "error in saved settings '%s'\n", opt);
-		return;
-	}
-	c_iflag= num;
-
-	num= strtol(check+1, &check, 16);
-	if (check[0] != ':')
-	{
-		fprintf(stderr, "error in saved settings '%s'\n", opt);
-		return;
-	}
-	c_oflag= num;
-
-	num= strtol(check+1, &check, 16);
-	if (check[0] != ':')
-	{
-		fprintf(stderr, "error in saved settings '%s'\n", opt);
-		return;
-	}
-	c_cflag= num;
-
-	num= strtol(check+1, &check, 16);
-	if (check[0] != ':')
-	{
-		fprintf(stderr, "error in saved settings '%s'\n", opt);
-		return;
-	}
-	c_lflag= num;
-
-	num= strtol(check+1, &check, 16);
-	if (check[0] != ':')
-	{
-		fprintf(stderr, "error in saved settings '%s'\n", opt);
-		return;
-	}
-	ispeed= num;
-
-	num= strtol(check+1, &check, 16);
-	if (check[0] != ':')
-	{
-		fprintf(stderr, "error in saved settings '%s'\n", opt);
-		return;
-	}
-	ospeed= num;
-
-	for(i=0; i<NCCS; i++)
-	{
-		num= strtol(check+1, &check, 16);
-		if (check[0] != ':')
-		{
-			fprintf(stderr, "error in saved settings '%s'\n", opt);
-			return;
-		}
-		c_cc[i]= num;
-	}
-	if (check[1] != '\0')
-	{
-		fprintf(stderr, "error in saved settings '%s'\n", opt);
-		return;
-	}
-	termios.c_iflag= c_iflag;
-	termios.c_oflag= c_oflag;
-	termios.c_cflag= c_cflag;
-	termios.c_lflag= c_lflag;
-
-	cfsetispeed(&termios, ispeed);
-	cfsetospeed(&termios, ospeed);
-
-	for(i=0; i<NCCS; i++)
-		termios.c_cc[i]= c_cc[i];
-}
-
-void set_control(option, value)
-int option;
-char *value;
-{
-	int chr;
-
-	if (match(value, "undef") || match(value, "^-")) {
-#ifdef _POSIX_VDISABLE
-		chr= _POSIX_VDISABLE;
-#else
-		fprintf(stderr, 
-			"stty: unable to set option to _POSIX_VDISABLE\n");
-		return;
-#endif
-	} else if (match(value, "^?"))
-		chr= '\177';
-	else if (strlen(value) == 2 && value[0] == '^') {
-		chr= toupper(value[1]) - '@';
-		if (chr < 0 || chr >= 32) {
-			fprintf(stderr, "stty: illegal option value: '%s'\n",
-				value);
-			return;
-		}
-	} else if (strlen(value) == 1)
-		chr= value[0];
-	else {
-		fprintf(stderr, "stty: illegal option value: '%s'\n", value);
-		return;
-	}
-
-	assert(option >= 0 && option < NCCS);
-	termios.c_cc[option]= chr;
-}
-		
-void set_min_tim(option, value)
-int option;
-char *value;
-{
-	long num;
-	char *check;
-
-	num= strtol(value, &check, 0);
-	if (check[0] != '\0') {
-		fprintf(stderr, "stty: illegal option value: '%s'\n", value);
-		return;
-	}
-
-	if ((cc_t)num != num) {
-		fprintf(stderr, "stty: illegal option value: '%s'\n", value);
-		return;
-	}
-	assert(option >= 0 && option < NCCS);
-	termios.c_cc[option]= num;
-}
-
-/*
- * $PchId: stty.c,v 1.7 2001/05/02 15:04:42 philip Exp $
- */
Index: trunk/minix/commands/simple/su.c
===================================================================
--- trunk/minix/commands/simple/su.c	(revision 9)
+++ 	(revision )
@@ -1,155 +1,0 @@
-/* su - become super-user		Author: Patrick van Kleef */
-
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <limits.h>
-#include <fcntl.h>
-#include <time.h>
-#if __minix_vmd
-#include <sys/syslog.h>
-#endif
-#include <minix/minlib.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  register char *name, *password;
-  char *shell, sh0[100];
-  char from_user[8+1], from_shell[100];
-  register struct passwd *pwd;
-  char USER[20], LOGNAME[25], HOME[100], SHELL[100];
-  char *envv[20], **envp;
-  int smallenv;
-  char *p;
-  int super;
-  int loginshell;
-#if __minix_vmd
-  gid_t groups[NGROUPS_MAX];
-  int ngroups;
-  int g;
-#endif
-
-  smallenv = 0;
-  loginshell = 0;
-  if (argc > 1 && (strcmp(argv[1], "-") == 0 || strcmp(argv[1], "-e") == 0)) {
-	if (argv[1][1] == 0)
-		loginshell= 1;		/* 'su -' reads .profile */
-	argv[1] = argv[0];
-	argv++;
-	argc--;
-	smallenv = 1;	/* Use small environment. */
-  }
-  if (argc > 1) {
-	if (argv[1][0] == '-') {
-		fprintf(stderr,
-			"Usage: su [-[e]] [user [shell-arguments ...]]\n");
-		exit(1);
-	}
-	name = argv[1];
-	argv[1] = argv[0];
-	argv++;
-  } else {
-	name = "root";
-  }
-
-  if ((pwd = getpwuid(getuid())) == 0) {
-	fprintf(stderr, "You do not exist\n");
-	exit(1);
-  }
-  strncpy(from_user, pwd->pw_name, 8);
-  from_user[8]= 0;
-  strncpy(from_shell, pwd->pw_shell[0] == '\0' ? "/bin/sh" : pwd->pw_shell,
-						sizeof(from_shell)-1);
-  from_shell[sizeof(from_shell)-1]= 0;
-
-  if ((pwd = getpwnam(name)) == 0) {
-	fprintf(stderr, "Unknown id: %s\n", name);
-	exit(1);
-  }
-  super = 0;
-  if (getgid() == 0) super = 1;
-#if __minix_vmd
-  ngroups = getgroups(NGROUPS_MAX, groups);
-  for (g = 0; g < ngroups; g++) if (groups[g] == 0) super = 1;
-#endif
-
-  if (!super && strcmp(pwd->pw_passwd, crypt("", pwd->pw_passwd)) != 0) {
-#if __minix_vmd
-	openlog("su", 0, LOG_AUTH);
-#endif
-	password = getpass("Password:");
-	if (password == 0
-	  || strcmp(pwd->pw_passwd, crypt(password, pwd->pw_passwd)) != 0) {
-		if (password != 0 && *password != 0) {
-#if __minix_vmd
-			syslog(LOG_WARNING, "su %s failed for %s",
-							name, from_user);
-#endif
-		}
-		fprintf(stderr, "Sorry\n");
-		exit(2);
-	}
-#if __minix_vmd
-	syslog(LOG_NOTICE, "su %s succeeded for %s", name, from_user);
-	closelog();
-#endif
-  }
-
-#if __minix_vmd
-  initgroups(pwd->pw_name, pwd->pw_gid);
-#endif
-  setgid(pwd->pw_gid);
-  setuid(pwd->pw_uid);
-  if (loginshell) {
-	shell = pwd->pw_shell[0] == '\0' ? "/bin/sh" : pwd->pw_shell;
-  } else {
-	if ((shell = getenv("SHELL")) == NULL) shell = from_shell;
-  }
-  if ((p= strrchr(shell, '/')) == 0) p= shell; else p++;
-  sh0[0]= '-';
-  strcpy(loginshell ? sh0+1 : sh0, p);
-  argv[0]= sh0;
-
-  if (smallenv) {
-	envp = envv;
-	*envp++ = "PATH=:/bin:/usr/bin",
-	strcpy(USER, "USER=");
-	strcpy(USER + 5, name);
-	*envp++ = USER;
-	strcpy(LOGNAME, "LOGNAME=");
-	strcpy(LOGNAME + 8, name);
-	*envp++ = LOGNAME;
-	strcpy(SHELL, "SHELL=");
-	strcpy(SHELL + 6, shell);
-	*envp++ = SHELL;
-	strcpy(HOME, "HOME=");
-	strcpy(HOME + 5, pwd->pw_dir);
-	*envp++ = HOME;
-	if ((p = getenv("TERM")) != NULL) {
-		*envp++ = p - 5;
-	}
-	if ((p = getenv("TERMCAP")) != NULL) {
-		*envp++ = p - 8;
-	}
-	if ((p = getenv("TZ")) != NULL) {
-		*envp++ = p - 3;
-	}
-	*envp = NULL;
-	(void) chdir(pwd->pw_dir);
-	execve(shell, argv, envv);
-	perror(shell);
-  } else {
-	execv(shell, argv);
-	perror(shell);
-  }
-  fprintf(stderr, "No shell\n");
-  return(3);
-}
Index: trunk/minix/commands/simple/sum.c
===================================================================
--- trunk/minix/commands/simple/sum.c	(revision 9)
+++ 	(revision )
@@ -1,121 +1,0 @@
-/* sum - checksum a file		Author: Martin C. Atkins */
-
-/*
- *	This program was written by:
- *		Martin C. Atkins,
- *		University of York,
- *		Heslington,
- *		York. Y01 5DD
- *		England
- *	and is released into the public domain, on the condition
- *	that this comment is always included without alteration.
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <minix/minlib.h>
-#include <stdio.h>
-
-#define BUFFER_SIZE (512)
-
-int rc = 0;
-
-char *defargv[] = {"-", 0};
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void error, (char *s, char *f));
-_PROTOTYPE(void sum, (int fd, char *fname));
-_PROTOTYPE(void putd, (int number, int fw, int zeros));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  register int fd;
-
-  if (*++argv == 0) argv = defargv;
-  for (; *argv; argv++) {
-	if (argv[0][0] == '-' && argv[0][1] == '\0')
-		fd = 0;
-	else
-		fd = open(*argv, O_RDONLY);
-
-	if (fd == -1) {
-		error("can't open ", *argv);
-		rc = 1;
-		continue;
-	}
-	sum(fd, (argc > 2) ? *argv : (char *) 0);
-	if (fd != 0) close(fd);
-  }
-  return(rc);
-}
-
-void error(s, f)
-char *s, *f;
-{
-
-  std_err("sum: ");
-  std_err(s);
-
-  if (f) std_err(f);
-  std_err("\n");
-}
-
-void sum(fd, fname)
-int fd;
-char *fname;
-{
-  char buf[BUFFER_SIZE];
-  register int i, n;
-  long size = 0;
-  unsigned crc = 0;
-  unsigned tmp, blks;
-
-  while ((n = read(fd, buf, BUFFER_SIZE)) > 0) {
-	for (i = 0; i < n; i++) {
-		crc = (crc >> 1) + ((crc & 1) ? 0x8000 : 0);
-		tmp = buf[i] & 0377;
-		crc += tmp;
-		crc &= 0xffff;
-		size++;
-	}
-  }
-
-  if (n < 0) {
-	if (fname)
-		error("read error on ", fname);
-	else
-		error("read error", (char *) 0);
-	rc = 1;
-	return;
-  }
-  putd(crc, 5, 1);
-  blks = (size + (long) BUFFER_SIZE - 1L) / (long) BUFFER_SIZE;
-  putd(blks, 6, 0);
-  if (fname) printf(" %s", fname);
-  printf("\n");
-}
-
-void putd(number, fw, zeros)
-int number, fw, zeros;
-{
-/* Put a decimal number, in a field width, to stdout. */
-
-  char buf[10];
-  int n;
-  unsigned num;
-
-  num = (unsigned) number;
-  for (n = 0; n < fw; n++) {
-	if (num || n == 0) {
-		buf[fw - n - 1] = '0' + num % 10;
-		num /= 10;
-	} else
-		buf[fw - n - 1] = zeros ? '0' : ' ';
-  }
-  buf[fw] = 0;
-  printf("%s", buf);
-}
Index: trunk/minix/commands/simple/swapfs.c
===================================================================
--- trunk/minix/commands/simple/swapfs.c	(revision 9)
+++ 	(revision )
@@ -1,1048 +1,0 @@
-/* swapfs - swap a Minix file system	    Author: Niels C. Willems */
-
-
-/* $Id: swapfs.c,v 1.1.1.1 2005/04/21 14:55:33 beng Exp $ */
-
-/* Swapfs, a program to convert V1 or V2 Minix file systems from big endian
-   byte order to little endian and vv.
-
-   Some examples:
-   swapfs -v disk.01			! only show verbose information.
-   swapfs /dev/fd0 | compress > fd0r.Z	! convert and compress filesystem.
-   swapfs -v fileA fileA	! read, convert and write the same filesystem.
-
-  This program uses one byte of heap memory for each data block (1Kbytes)
-  in the file system, so with Minix-PC 16-bit you can't swap file systems
-  bigger than about 32 Mbytes
-
-  Be careful with 'swapfs fileA fileA'. If the program aborts e.g. by
-  user interrupt, power failure or an inconsistent file system, you
-  better have a backup of fileA
-
-  This program only converts directories and indirect blocks of files
-  that are in use. Converting indirect blocks or directories of deleted
-  files is hard and not yet done.
-
-  If you have a (1.6.xx, xx < 18) version of Minix that supports the
-  mounting of reversed file systems always mount them read-only and
-  avoid any attemp to modify them (mkdir, open, creat) too!
-  These problems have been fixed in Minix 1.6.18.
-
-  In this version you can get some more information about the
-  file system with the -d (debug) flag.
-
-      Please send your bug reports or ideas to ncwille@cs.vu.nl
- */
-
-
-#define _POSIX_SOURCE	1
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#include <assert.h>
-
-#if __STDC__ == 1
-#define	_PROTOTYPE(function, params)	function params
-#else
-#define	_PROTOTYPE(function, params)	function()
-#endif
-
-#define BLOCK_SIZE	1024
-
-#define BOOT_BLOCK_OFF	   (blockn_t) 0
-#define SUPER_BLOCK_OFF    (blockn_t) 1
-
-#define V1_MAGIC		0x137F
-#define V2_MAGIC		0x2468
-#define NINODES_OFFSET		     0
-#define V1_ZONES_OFFSET		     2
-#define IMAP_BLOCKS_OFFSET	     4
-#define ZMAP_BLOCKS_OFFSET	     6
-#define FIRSTDATAZONE_OFFSET	     8
-#define LOG_ZONE_SIZE_OFFSET        10
-#define MAGIC_OFFSET		    16
-#define V2_ZONES_OFFSET		    20
-
-
-#define NR_DIRECT_ZONES	 7
-#define V1_NR_TZONES	 9
-#define V2_NR_TZONES	10
-#define V1_INODE_SIZE	32
-#define V2_INODE_SIZE	64
-
-#define INODE1_MODE_OFF		 0
-#define INODE1_SIZE_OFF		 4
-#define INODE1_DIRECT_OFF	14
-#define INODE1_IND1_OFF		28
-#define INODE1_IND2_OFF		30
-
-#define INODE2_MODE_OFF		 0
-#define INODE2_SIZE_OFF		 8
-#define INODE2_DIRECT_OFF	24
-#define INODE2_IND1_OFF		52
-#define INODE2_IND2_OFF		56
-#define INODE2_IND3_OFF		60
-
-#define INODE_MODE_MASK		0xf000	/* file type mask    */
-#define INODE_DIR_MODE		0x4000	/* directory         */
-#define INODE_BLK_SPECIAL_MODE	0x6000	/* block special     */
-#define INODE_CHR_SPECIAL_MODE  0x2000	/* character special */
-
-#define T_MASK		0x1c
-#define T_UNKNOWN	0x00
-#define T_MAYBE_OLD_DIR	0x04
-#define T_OLD_NON_DIR	0x08
-#define T_DIR		0x0c
-#define T_NON_DIR	0x10
-
-#define INDIRECT_MASK	0x03
-
-#define IND_PROCESSED_BIT 0x20	/* set when all blocks in ind block are
-			 * marked */
-#define IND_CONFLICT_BIT  0x40
-#define TYPE_CONFLICT_BIT 0x80
-
-#define DIR_ENTRY_SIZE    16
-
-typedef enum {
-  Unused_zone, Old_zone, In_use_zone
-} class_t;
-
-typedef unsigned long blockn_t;
-typedef unsigned int inodesn_t;
-
-typedef struct {
-  inodesn_t ninodes;		/* # usable inodes on the minor device */
-  blockn_t imap_blocks;		/* # of blocks used by inode bit map */
-  blockn_t zmap_blocks;		/* # of blocks used by zone bit map */
-  blockn_t firstdatazone;	/* number of first data zone */
-  int log_zone_size;		/* log2 of blocks/zone */
-  blockn_t zones;		/* number of zones */
-
-  int version;			/* file system version */
-  inodesn_t inodes_per_block;
-  blockn_t first_imap_block;
-  blockn_t first_zmap_block;
-  blockn_t first_inode_block;	/* number of first block with inodes */
-  size_t dzmap_size;		/* # of data zone blocks */
-} super_t;
-
-
-typedef struct {		/* summary of inode */
-  long size;			/* current file size in bytes */
-  blockn_t direct[NR_DIRECT_ZONES];	/* block numbers for direct,
-					 * ind, ... */
-  blockn_t ind1;		/* single indirect block number */
-  blockn_t ind2;		/* double indirect block number */
-  blockn_t ind3;		/* triple indirect block number */
-  int ztype;			/* type of zones that belong to this inode */
-} inode_t;
-
-static char rcsid[] = "$Id: swapfs.c,v 1.1.1.1 2005/04/21 14:55:33 beng Exp $";
-
-static int super_format[] = {2, 2, 2, 2, 2, 2, 4, 2, 2, 4, 0};
-static int inode1_format[] = {2, 2, 4, 4, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0};
-static int inode2_format[] = {2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
-		      4, 4, 0};
-
-static char *ind_str[4] = {"direct", "single indirect",
-		   "double indirect", "triple indirect"};
-
-static int big_endian_fs;	/* set in init_super(), 1 iff file system has
-			 * big endian byte order */
-static int verbose_flag;
-static int debug_flag;
-static int test_flag;
-
-typedef unsigned char *dzmap_t;
-
-
-int _PROTOTYPE(main, (int argc, char *argv[]));
-static void _PROTOTYPE(parse_args_init_io, (int argc, char *argv[]));
-static void _PROTOTYPE(rw_boot, (void));
-static void _PROTOTYPE(rw_init_super, (super_t * sp));
-static void _PROTOTYPE(init_dzmap, (dzmap_t * dzmap_ptr, size_t dzmap_size));
-static void _PROTOTYPE(rw_ibmap, (super_t super));
-static void _PROTOTYPE(rw_zbmap, (super_t super));
-static void _PROTOTYPE(print_stat, (dzmap_t dzmap, super_t super));
-static void _PROTOTYPE(p1_rw_inodes, (dzmap_t dzmap, super_t super));
-static void _PROTOTYPE(rd_indirects, (dzmap_t dzmap, super_t super, int ind,
-			       class_t required_class));
-static void _PROTOTYPE(rw_data_zones, (dzmap_t dzmap, super_t super));
-
-static int _PROTOTYPE(read_block, (char *buf, blockn_t offset));
-static void _PROTOTYPE(write_block, (char *buf));
-static int _PROTOTYPE(convcpy, (char *dst, char *src, int *format));
-static void _PROTOTYPE(conv2_blkcpy, (char *dst, char *src));
-static void _PROTOTYPE(conv4_blkcpy, (char *dst, char *src));
-static void _PROTOTYPE(conv2cpy, (char *dst, char *src));
-static int _PROTOTYPE(inode_size, (int version));
-
-static void _PROTOTYPE(init_super, (super_t * sp, char *buf));
-static void _PROTOTYPE(get_inode, (inode_t * ip, char *buf, int version));
-static int _PROTOTYPE(check_inode, (inode_t inode, super_t super));
-static int _PROTOTYPE(was_blk_special, (inode_t inode));
-static int _PROTOTYPE(check_blk_number, (blockn_t num, super_t super));
-static void _PROTOTYPE(cw_inode_block, (char *buf, inodesn_t ninodes,
-				 int version));
-static void _PROTOTYPE(proc_ind, (dzmap_t dzmap, size_t curr_ind,
-			   char *buf, super_t super));
-static void _PROTOTYPE(cw_dir_block, (char *buf));
-static void _PROTOTYPE(dzmap_add_inode, (dzmap_t dzmap, inode_t inode,
-				  super_t super));
-static void _PROTOTYPE(dz_update, (dzmap_t dzmap, blockn_t blknum,
-		     int new_indnum, int new_ztype, super_t super));
-static class_t _PROTOTYPE(ztype_class, (int ztype));
-
-static unsigned int _PROTOTYPE(two_bytes, (char buf[2]));
-static long _PROTOTYPE(four_bytes, (char buf[4]));
-
-static void _PROTOTYPE(fail, (char *string));
-static void _PROTOTYPE(usage, (char *arg0));
-
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  super_t super;
-  dzmap_t dzmap;
-
-  parse_args_init_io(argc, argv);
-  rw_boot();
-  rw_init_super(&super);
-  init_dzmap(&dzmap, super.dzmap_size);
-  rw_ibmap(super);
-  rw_zbmap(super);
-  p1_rw_inodes(dzmap, super);
-
-  rd_indirects(dzmap, super, 3, In_use_zone);
-  rd_indirects(dzmap, super, 2, In_use_zone);
-  rd_indirects(dzmap, super, 1, In_use_zone);
-  if (verbose_flag) putc('\n', stderr);
-
-  print_stat(dzmap, super);
-  rw_data_zones(dzmap, super);
-  return 0;
-}
-
-
-static void parse_args_init_io(argc, argv)
-int argc;
-char *argv[];
-{
-  char *str;
-  struct stat buf;
-  ino_t src_ino;
-  int i;
-
-  debug_flag = 0;
-  verbose_flag = 0;
-  test_flag = 0;
-
-  for (i = 1; i < argc; i++) {
-	str = argv[i];
-	if (*str != '-') break;
-	switch (*++str) {
-	    case 'v':	verbose_flag = 1;	break;
-	    case 'd':
-		debug_flag = 1;
-		verbose_flag = 1;
-		break;
-	    case 't':	test_flag = 1;	break;
-	    default:	usage(argv[0]);
-	}
-  }
-  if ((argc - i == 0 && isatty(0)) || (argc - i) > 2) usage(argv[0]);
-
-  if (argc - i > 0) {
-	(void) close(0);
-	if (open(argv[i], O_RDONLY) != 0) {
-		fprintf(stderr, "Can't open input file %s", argv[i]);
-		fail("");
-	}
-  }
-  if (isatty(1) || argc - i == 2) {
-	if (argc - i < 2)
-		test_flag = 1;
-	else {
-		i++;
-		(void) close(1);
-		(void) fstat(0, &buf);
-		src_ino = buf.st_ino;
-		if (stat(argv[i], &buf) == 0 && src_ino == buf.st_ino) {
-			/* Src and dest are the same */
-			if (open(argv[i], O_WRONLY) != 1) {
-				fprintf(stderr, "Can't open output file %s", argv[i]);
-				fail("");
-			}
-		} else if (creat(argv[i], 0644) != 1) {
-			fprintf(stderr, "Can't creat output file %s", argv[i]);
-			fail("");
-		}
-	}
-  }
-}
-
-
-static void rw_boot()
-{
-  char buf[BLOCK_SIZE];
-
-  if (read_block(buf, BOOT_BLOCK_OFF) != BLOCK_SIZE)
-	fail("Can't read bootblock");
-  write_block(buf);
-}
-
-
-static void rw_init_super(sp)
-super_t *sp;
-{
-  char ibuf[BLOCK_SIZE], obuf[BLOCK_SIZE];
-
-  if (read_block(ibuf, SUPER_BLOCK_OFF) != BLOCK_SIZE)
-	fail("Can't read superblock");
-
-  init_super(sp, ibuf);
-
-  memcpy(obuf, ibuf, (size_t) BLOCK_SIZE);	/* preserve 'unused' data */
-  (void) convcpy(obuf, ibuf, super_format);
-
-  write_block(obuf);
-}
-
-
-static void init_dzmap(dzmap_ptr, dzmap_size)
-dzmap_t *dzmap_ptr;
-size_t dzmap_size;
-{
-  if ((*dzmap_ptr = (dzmap_t) malloc(dzmap_size)) == (dzmap_t) NULL)
-	fail("Not enough space for data zone map");
-  memset(*dzmap_ptr, '\0', (size_t) dzmap_size);
-}
-
-
-static void rw_ibmap(super)
-super_t super;
-{
-  char ibuf[BLOCK_SIZE], obuf[BLOCK_SIZE];
-  blockn_t i;
-
-  for (i = 0; i < super.imap_blocks; i++) {
-	if (read_block(ibuf, super.first_imap_block + i) != BLOCK_SIZE)
-		fail("Can't read inode bit map");
-	conv2_blkcpy(obuf, ibuf);
-	write_block(obuf);
-  }
-}
-
-
-static void rw_zbmap(super)
-super_t super;
-{
-  char ibuf[BLOCK_SIZE], obuf[BLOCK_SIZE];
-  blockn_t i;
-
-  for (i = 0; i < super.zmap_blocks; i++) {
-	if (read_block(ibuf, super.first_zmap_block + i) != BLOCK_SIZE)
-		fail("Can't read zone bit map");
-	conv2_blkcpy(obuf, ibuf);
-	write_block(obuf);
-  }
-}
-
-
-static void p1_rw_inodes(dzmap, super)
-dzmap_t dzmap;
-super_t super;
-{
-  char buf[BLOCK_SIZE], *buf_ptr;
-  inodesn_t i, num_inodes;
-  blockn_t next_block;
-  inode_t inode;
-
-
-  next_block = super.first_inode_block;
-
-  for (i = 1; i <= super.ninodes; i++) {
-	if ((i - 1) % super.inodes_per_block == 0) {
-		if (read_block(buf, next_block) != BLOCK_SIZE)
-			fail("read failed in inode block");
-		buf_ptr = buf;
-		next_block++;
-		num_inodes = super.ninodes + 1 - i;
-		if (num_inodes > super.inodes_per_block)
-			num_inodes = super.inodes_per_block;
-		cw_inode_block(buf, num_inodes, super.version);
-	}
-	get_inode(&inode, buf_ptr, super.version);
-	dzmap_add_inode(dzmap, inode, super);
-	buf_ptr += inode_size(super.version);
-  }
-}
-
-
-static void print_stat(dzmap, super)
-dzmap_t dzmap;
-super_t super;
-{
-  size_t i;
-  register unsigned char dz;
-  int both_conflict = 0, ind_conflict = 0, type_conflict = 0, unreferenced = 0;
-  int not_in_use = 0;
-
-  if (!verbose_flag) return;
-
-  for (i = 0; i < super.dzmap_size; i++) {
-	dz = dzmap[i];
-	if (dz & IND_CONFLICT_BIT && dz & TYPE_CONFLICT_BIT)
-		both_conflict++;
-	else if (dz & IND_CONFLICT_BIT)
-		ind_conflict++;
-	else if (dz & TYPE_CONFLICT_BIT)
-		type_conflict++;
-
-	if (dz == 0) unreferenced++;
-	if (ztype_class(dz & T_MASK) < In_use_zone) not_in_use++;
-
-  }
-  if (debug_flag) {
-	fprintf(stderr, "%5d zone blocks with conflicting indir.\n",
-		ind_conflict);
-	fprintf(stderr, "%5d zone blocks with conflicting types.\n",
-		type_conflict);
-	fprintf(stderr, "%5d zone blocks with conflicting types and indir.\n",
-		both_conflict);
-	fprintf(stderr, "%5d zone blocks never referenced.\n", unreferenced);
-  }
-  fprintf(stderr, "%5d zone blocks not in use.\n", not_in_use);
-  putc('\n', stderr);
-}
-
-
-static void rd_indirects(dzmap, super, ind, required_class)
-dzmap_t dzmap;
-super_t super;
-int ind;
-class_t required_class;
-{
-  size_t i;
-  int ind_cnt;
-  off_t dz_offset;
-  char buf[BLOCK_SIZE];
-
-  dz_offset = super.firstdatazone;
-  ind_cnt = 0;
-  for (i = 0; i < super.dzmap_size; i++) {
-	if (ztype_class(dzmap[i] & T_MASK) != required_class ||
-	    (dzmap[i] & INDIRECT_MASK) != ind ||
-	    (dzmap[i] & IND_PROCESSED_BIT))
-		continue;
-
-	ind_cnt++;
-	if (read_block(buf, dz_offset + i) != BLOCK_SIZE) {
-		fprintf(stderr, "Can't read %s block", ind_str[ind]);
-		fail("");
-	}
-	proc_ind(dzmap, i, buf, super);
-  }
-  if ((verbose_flag && ind_cnt > 0) || debug_flag)
-	fprintf(stderr, "%5d %s zone blocks.\n", ind_cnt, ind_str[ind]);
-}
-
-
-static void rw_data_zones(dzmap, super)
-dzmap_t dzmap;
-super_t super;
-{
-  char ibuf[BLOCK_SIZE], obuf[BLOCK_SIZE];
-  size_t i;
-  int ztype, ind, last_read;
-  off_t dz_offset;
-
-  dz_offset = super.firstdatazone;
-  for (i = 0; i < super.dzmap_size; i++) {
-	last_read = read_block(ibuf, dz_offset + i);
-	if (last_read != BLOCK_SIZE) break;
-
-	ind = dzmap[i] & INDIRECT_MASK;
-	if (ind == 0) {
-		ztype = dzmap[i] & T_MASK;
-		if (ztype == T_DIR)
-			cw_dir_block(ibuf);
-		else
-			write_block(ibuf);
-	} else {
-		if (super.version == 1)
-			conv2_blkcpy(obuf, ibuf);
-		else
-			conv4_blkcpy(obuf, ibuf);
-		write_block(obuf);
-	}
-	if (verbose_flag && i && i % 1024 == 0) {
-		fprintf(stderr, ".");
-		fflush(stderr);
-	}
-  }
-  if (verbose_flag && i > 1024) putc('\n', stderr);
-
-  if (last_read != BLOCK_SIZE) for (; i < super.dzmap_size; i++)
-		if (ztype_class(dzmap[i] & T_MASK) == In_use_zone)
-			fail("Can't read data zone");
-}
-
-
-static int read_block(buf, offset)
-char *buf;
-blockn_t offset;
-{
-  static blockn_t curr_offset = 0;
-  int bytes;
-
-  if (offset != curr_offset) {
-	if (lseek(0, (off_t) offset * BLOCK_SIZE, 0) == -1)
-		fail("lseek failed on input file");
-	curr_offset = offset;
-  }
-  bytes = read(0, buf, BLOCK_SIZE);
-  if (bytes < 0) fail("read failed on input file");
-
-  curr_offset += bytes;
-
-  return bytes;
-}
-
-
-static void write_block(buf)
-char *buf;
-{
-  if (test_flag) return;
-
-  if (write(1, buf, BLOCK_SIZE) != BLOCK_SIZE)
-	fail("write failed on output file");
-}
-
-
-static int convcpy(dst, src, format)
-char *dst;
-char *src;
-int *format;
-{
-  char *old_src = src;
-  register char tmp;
-  int i;
-
-  for (i = 0; format[i] > 0; i++) {
-	switch (format[i]) {
-	    case 1:	*dst++ = *src++;	break;
-	    case 2:
-		tmp = *src++;
-		*dst++ = *src++;
-		*dst++ = tmp;
-		break;
-	    case 4:
-		tmp = src[0];
-		dst[0] = src[3];
-		dst[3] = tmp;
-		tmp = src[1];
-		dst[1] = src[2];
-		dst[2] = tmp;
-		src += 4;
-		dst += 4;
-		break;
-	    default:
-		fail("wrong format array for convcpy");
-	}
-  }
-  return(src - old_src);
-}
-
-
-static void conv2_blkcpy(dst, src)
-char *dst;
-char *src;
-{
-  int i;
-  register char tmp;
-
-  for (i = 0; i < BLOCK_SIZE; i += 2) {
-	tmp = *src++;
-	*dst++ = *src++;
-	*dst++ = tmp;
-  }
-}
-
-
-static void conv4_blkcpy(dst, src)
-char *dst;
-char *src;
-{
-  int i;
-  register char tmp;
-
-  for (i = 0; i < BLOCK_SIZE; i += 4) {
-	tmp = src[0];
-	dst[0] = src[3];
-	dst[3] = tmp;
-
-	tmp = src[1];
-	dst[1] = src[2];
-	dst[2] = tmp;
-
-	src += 4;
-	dst += 4;
-  }
-}
-
-
-static void conv2cpy(dst, src)
-char *dst;
-char *src;
-{
-  register char tmp;
-  tmp = *src++;
-  *dst++ = *src++;
-  *dst++ = tmp;
-}
-
-
-static int inode_size(version)
-int version;
-{
-  return(version == 1) ? V1_INODE_SIZE : V2_INODE_SIZE;
-}
-
-
-static void init_super(sp, buf)
-super_t *sp;
-char *buf;
-{
-  int magic;
-  long imapblks, zmapblks;
-
-  big_endian_fs = 0;		/* guess the file system is little endian */
-  magic = two_bytes(buf + MAGIC_OFFSET);
-
-  if (magic != V1_MAGIC && magic != V2_MAGIC) {
-	big_endian_fs = 1;
-	magic = two_bytes(buf + MAGIC_OFFSET);
-  }
-  switch (magic) {
-      case V1_MAGIC:	sp->version = 1;	break;
-      case V2_MAGIC:	sp->version = 2;	break;
-      default:	fail("Not a Minix file system");
-}
-
-  if (verbose_flag) fprintf(stderr, "\nVersion = V%d, %s endian.\n",
-		sp->version, big_endian_fs ? "big" : "little");
-
-  sp->ninodes = two_bytes(buf + NINODES_OFFSET);
-  imapblks = two_bytes(buf + IMAP_BLOCKS_OFFSET);
-  sp->imap_blocks = imapblks;
-  zmapblks = two_bytes(buf + ZMAP_BLOCKS_OFFSET);
-  sp->zmap_blocks = zmapblks;
-  sp->firstdatazone = two_bytes(buf + FIRSTDATAZONE_OFFSET);
-  sp->log_zone_size = two_bytes(buf + LOG_ZONE_SIZE_OFFSET);
-
-  if (sp->version == 1)
-	sp->zones = two_bytes(buf + V1_ZONES_OFFSET);
-  else
-	sp->zones = four_bytes(buf + V2_ZONES_OFFSET);
-
-  sp->inodes_per_block = BLOCK_SIZE / inode_size(sp->version);
-
-  if (imapblks < 0 || zmapblks < 0 || sp->ninodes < 1 || sp->zones < 1)
-	fail("Bad superblock");
-
-
-  if (sp->log_zone_size != 0)
-	fail("Can't swap file systems with different zone and block sizes");
-
-  sp->first_imap_block = SUPER_BLOCK_OFF + 1;
-  sp->first_zmap_block = sp->first_imap_block + sp->imap_blocks;
-  sp->first_inode_block = sp->first_zmap_block + sp->zmap_blocks;
-
-  sp->dzmap_size = sp->zones - sp->firstdatazone;
-  if (verbose_flag) {
-	fprintf(stderr, "nzones = %ld, ", sp->zones);
-	fprintf(stderr, "ninodes = %u, ", sp->ninodes);
-	fprintf(stderr, "first data zone = %ld.\n\n", sp->firstdatazone);
-  }
-}
-
-
-static void get_inode(ip, buf, version)
-inode_t *ip;
-char *buf;
-int version;
-{
-  int i;
-  int mode;
-
-  if (version == 1) {
-	mode = two_bytes(buf + INODE1_MODE_OFF);
-	ip->size = four_bytes(buf + INODE1_SIZE_OFF);
-	ip->ind1 = two_bytes(buf + INODE1_IND1_OFF);
-	ip->ind2 = two_bytes(buf + INODE1_IND2_OFF);
-	ip->ind3 = 0;
-	for (i = 0; i < NR_DIRECT_ZONES; i++)
-		ip->direct[i] = two_bytes(buf + INODE1_DIRECT_OFF + 2 * i);
-  } else {
-	mode = two_bytes(buf + INODE2_MODE_OFF);
-	ip->size = four_bytes(buf + INODE2_SIZE_OFF);
-	ip->ind1 = four_bytes(buf + INODE2_IND1_OFF);
-	ip->ind2 = four_bytes(buf + INODE2_IND2_OFF);
-	ip->ind3 = four_bytes(buf + INODE2_IND3_OFF);
-	for (i = 0; i < NR_DIRECT_ZONES; i++)
-		ip->direct[i] = four_bytes(buf + INODE2_DIRECT_OFF + 4 * i);
-  }
-
-  if (mode == 0) {
-	if (ip->size % DIR_ENTRY_SIZE == 0)
-		ip->ztype = T_MAYBE_OLD_DIR;
-	else
-		ip->ztype = T_OLD_NON_DIR;
-	if (was_blk_special(*ip)) ip->size = 0;
-  } else {
-	mode = mode & INODE_MODE_MASK;
-	if (mode == INODE_BLK_SPECIAL_MODE || mode == INODE_CHR_SPECIAL_MODE)
-		ip->size = 0;	/* prevent the use of the block numbers. */
-	ip->ztype = (mode == INODE_DIR_MODE) ? T_DIR : T_NON_DIR;
-  }
-}
-
-
-static int check_inode(inode, super)
-inode_t inode;
-super_t super;
-{
-  int i;
-
-  for (i = 0; i < NR_DIRECT_ZONES; i++)
-	if (!check_blk_number(inode.direct[i], super)) return 0;
-
-  return(check_blk_number(inode.ind1, super) &&
-	check_blk_number(inode.ind2, super) &&
-	check_blk_number(inode.ind3, super));
-}
-
-
-static int check_blk_number(num, super)
-blockn_t num;
-super_t super;
-{
-  if (num == 0 || (num >= super.firstdatazone && num < super.zones))
-	return 1;
-
-  fprintf(stderr, "warning bad block number %ld in inode.\n", num);
-  return 0;
-}
-
-
-static int was_blk_special(inode)
-inode_t inode;
-{
-  int i, result;
-  blockn_t block_size;
-
-  if (inode.size % BLOCK_SIZE || inode.ind1) return 0;
-  block_size = inode.size / BLOCK_SIZE;
-
-  for (i = NR_DIRECT_ZONES - 1; i >= 0; i--)
-	if (inode.direct[i] != 0) break;
-
-  result = (i < 1 && block_size > i + 1);
-
-  if (debug_flag && result) {
-	fprintf(stderr, "old block special file detected (slot = %d).\n", i);
-  }
-  return result;
-}
-
-
-static void cw_inode_block(buf, ninodes, version)
-char *buf;
-inodesn_t ninodes;
-int version;
-{
-  char output_buf[BLOCK_SIZE];
-  char *src, *dst;
-  inodesn_t i;
-  int cnt, free_bytes;
-  int *format;
-
-  src = buf;
-  dst = output_buf;
-
-  format = (version == 1) ? inode1_format : inode2_format;
-  for (i = 0; i < ninodes; i++) {
-	cnt = convcpy(dst, src, format);
-	src += cnt;
-	dst += cnt;
-  }
-
-  assert(cnt == inode_size(version));
-
-  free_bytes = BLOCK_SIZE - (src - buf);
-  assert(free_bytes >= 0);
-  if (verbose_flag && free_bytes > 0) {
-	/* There is a small change that the last free inode has no
-	 * matching bit in the last inode bit map block: e.g. if
-	 * sp->ninodes == 8191. */
-	fprintf(stderr, "%5d bytes (%d inodes) free in last inode block.\n",
-		free_bytes, free_bytes / inode_size(version));
-	memcpy(dst, src, (size_t) free_bytes);
-  }
-  write_block(output_buf);
-}
-
-
-static void proc_ind(dzmap, curr_ind, buf, super)
-dzmap_t dzmap;
-size_t curr_ind;
-char *buf;
-super_t super;
-{
-  int indnum, i, ztype;
-  int word_size;		/* size of zone block number in ind. block in
-			 * bytes */
-  unsigned char dz, tmp_dz;
-  blockn_t blk, ind_blk;
-  int bad_range = 0, hidden_zero = 0, zero_flag = 0, expired = 0;
-  size_t blk_index;
-
-  dz = dzmap[curr_ind];
-  indnum = dz & INDIRECT_MASK;
-  ztype = dz & T_MASK;
-  ind_blk = curr_ind + super.firstdatazone;
-
-  word_size = (super.version == 1) ? 2 : 4;
-  assert(indnum > 0);
-
-  for (i = 0; i < BLOCK_SIZE; i += word_size) {
-	if (word_size == 2)
-		blk = two_bytes(buf + i);
-	else
-		blk = four_bytes(buf + i);
-
-	if (blk == 0)
-		zero_flag = 1;
-	else if (blk < super.firstdatazone || blk >= super.zones)
-		bad_range = 1;
-	else {
-		if (zero_flag) hidden_zero = 1;
-		blk_index = blk - super.firstdatazone;
-		tmp_dz = dzmap[blk_index];
-		if (ztype_class(tmp_dz & T_MASK) == In_use_zone) expired = 1;
-	}
-
-  }
-
-  if (ztype_class(ztype) == In_use_zone) {
-	if (bad_range) {
-		fprintf(stderr, "%s zone block contains ", ind_str[indnum]);
-		fail("illegal value");
-	}
-	if ((ztype == T_DIR || indnum > 1) && hidden_zero) {
-		fprintf(stderr, "WARNING: %s zone block %ld contains ",
-			ind_str[indnum], ind_blk);
-		fprintf(stderr, "unexpected zero block numbers\n");
-	}
-  } else {
-	if (expired) {
-		dzmap[curr_ind] &= ~(INDIRECT_MASK & IND_CONFLICT_BIT);
-		return;
-	}
-
-	/* Not yet implemented. :-( if (bad_range || (indnum > 1 &&
-	 * hidden_zero) || equal_values(buf, super.version ) { } */
-  }
-
-  for (i = 0; i < BLOCK_SIZE; i += word_size) {
-	if (word_size == 2)
-		blk = two_bytes(buf + i);
-	else
-		blk = four_bytes(buf + i);
-
-	if (blk == 0) continue;
-	blk_index = blk - super.firstdatazone;
-	tmp_dz = dzmap[blk_index];
-	if (ztype_class(tmp_dz & T_MASK) == In_use_zone) {	/* trouble */
-		if ((tmp_dz & INDIRECT_MASK) == indnum - 1 &&
-		    (tmp_dz & T_MASK) == ztype)
-			fprintf(stderr, "WARNING: %s zone block %ld used more \
-than once\n", ind_str[indnum - 1], blk);
-		else {
-			fprintf(stderr, "Block %ld used more than ", blk);
-			fail("once with different types");
-		}
-	}
-	dzmap[blk_index] = (dz & ~INDIRECT_MASK) | (indnum - 1);
-  }
-  dzmap[curr_ind] |= IND_PROCESSED_BIT;
-}
-
-
-static void cw_dir_block(buf)
-char *buf;
-{
-  char output_buf[BLOCK_SIZE];
-  int ino, i, old_ino_offset;
-
-  memcpy(output_buf, buf, BLOCK_SIZE);
-
-  for (i = 0; i < BLOCK_SIZE; i += DIR_ENTRY_SIZE) {
-	ino = two_bytes(buf + i);
-	if (ino == 0) {
-		old_ino_offset = i + DIR_ENTRY_SIZE - 2;
-		conv2cpy(output_buf + old_ino_offset, buf + old_ino_offset);
-	} else
-		conv2cpy(output_buf + i, buf + i);
-  }
-  write_block(output_buf);
-}
-
-
-static void dzmap_add_inode(dzmap, inode, super)
-dzmap_t dzmap;
-inode_t inode;
-super_t super;
-{
-  int i;
-
-  if (inode.size == 0 || !check_inode(inode, super)) return;
-
-  for (i = 0; i < NR_DIRECT_ZONES; i++)
-	dz_update(dzmap, inode.direct[i], 0, inode.ztype, super);
-
-  dz_update(dzmap, inode.ind1, 1, inode.ztype, super);
-  dz_update(dzmap, inode.ind2, 2, inode.ztype, super);
-  dz_update(dzmap, inode.ind3, 3, inode.ztype, super);
-}
-
-
-static void dz_update(dzmap, blknum, new_indnum, new_ztype, super)
-dzmap_t dzmap;
-blockn_t blknum;
-int new_indnum;
-int new_ztype;
-super_t super;
-{
-  size_t dznum;
-  int old_indnum;
-  int old_ztype;
-  unsigned char *dz;
-  char new_dz;
-
-
-  if (blknum == 0) return;
-
-  dznum = (size_t) (blknum - super.firstdatazone);
-
-  dz = &dzmap[dznum];
-  old_indnum = *dz & INDIRECT_MASK;
-  old_ztype = *dz & T_MASK;
-
-  new_dz = new_ztype | new_indnum;
-
-  if (ztype_class(new_ztype) > ztype_class(old_ztype)) {
-	*dz = new_dz;
-	return;
-  } else if (ztype_class(new_ztype) < ztype_class(old_ztype))
-	return;
-
-  /* Collision: old and new have the same class */
-
-  if (ztype_class(old_ztype) == In_use_zone) {	/* trouble */
-	if (new_indnum == old_indnum && new_ztype == old_ztype) {
-		fprintf(stderr, "WARNING: file system corrupt, zone block %ld \
-is used more than once.\n", blknum);
-		return;
-	}
-	fprintf(stderr, "ERROR: file system corrupt, zone block %ld is used \
-more than once.\n", blknum);
-	fail("Can't determine its type");
-  }
-  assert(ztype_class(old_ztype) == Old_zone);
-
-
-  if (new_indnum != old_indnum) {
-	*dz |= IND_CONFLICT_BIT;
-	if (new_indnum > old_indnum) {
-		*dz &= ~INDIRECT_MASK;
-		*dz |= new_indnum;
-	}
-  }
-  if (new_ztype == T_MAYBE_OLD_DIR || old_ztype == T_MAYBE_OLD_DIR) {
-	*dz |= TYPE_CONFLICT_BIT;
-	*dz &= ~T_MASK;
-	*dz |= T_MAYBE_OLD_DIR;
-  }
-}
-
-
-static class_t ztype_class(ztype)
-int ztype;
-{
-  class_t class;
-
-  if (ztype == T_MAYBE_OLD_DIR || ztype == T_OLD_NON_DIR)
-	class = Old_zone;
-  else if (ztype == T_DIR || ztype == T_NON_DIR)
-	class = In_use_zone;
-  else
-	class = Unused_zone;
-
-  return class;
-}
-
-
-static void fail(str)
-char *str;
-{
-  fprintf(stderr, "%s\n", str);
-  exit(1);
-}
-
-
-static unsigned int two_bytes(buf)
-char buf[2];
-{
-  unsigned char *ubuf = (unsigned char *) buf;
-
-  if (big_endian_fs)
-	return(ubuf[0] << 8) | ubuf[1];
-  else
-	return(ubuf[1] << 8) | ubuf[0];
-}
-
-
-static long four_bytes(buf)
-char buf[4];
-{
-  unsigned char *ubuf = (unsigned char *) buf;
-  register int r1, r2;
-
-  if (big_endian_fs) {
-	r1 = (ubuf[0] << 8) | ubuf[1];
-	r2 = (ubuf[2] << 8) | ubuf[3];
-  } else {
-	r2 = (ubuf[1] << 8) | ubuf[0];
-	r1 = (ubuf[3] << 8) | ubuf[2];
-  }
-  return((long) r1 << 16) | r2;
-}
-
-
-static void usage(arg0)
-char *arg0;
-{
-  fprintf(stderr, "usage: %s [-v] srcfs [destfs]\n", arg0);
-  exit(2);
-}
Index: trunk/minix/commands/simple/sync.c
===================================================================
--- trunk/minix/commands/simple/sync.c	(revision 9)
+++ 	(revision )
@@ -1,14 +1,0 @@
-/* sync - flush the file system buffers.  Author: Andy Tanenbaum */
-
-#include <sys/types.h>
-#include <unistd.h>
-
-_PROTOTYPE(int main, (void));
-
-int main()
-{
-/* First prize in shortest useful program contest. */
-/* Highest comment/code ratio */
-  sync();
-  return(0);
-}
Index: trunk/minix/commands/simple/synctree.c
===================================================================
--- trunk/minix/commands/simple/synctree.c	(revision 9)
+++ 	(revision )
@@ -1,1481 +1,0 @@
-/*	synctree 4.16 - Synchronise file tree.		Author: Kees J. Bot
- *								5 Apr 1989
- * SYNOPSYS
- *	synctree [-iuf] [[user1@machine1:]dir1 [[user2@]machine2:]dir2
- *
- * Dir2 will then be synchronized to dir1 with respect to the flags.
- * The flags mean:
- *	-i  Be interactive on files other than directories too.
- *	-u  Only install files that are newer, i.e. that need an update.
- *	-f  Force.  Don't ask for confirmation, all answers are 'yes'.
- *
- * Hitting return lets synctree use its proposed answer.  Hitting CTRL-D is
- * like typing return to all questions that follow.
- *
- * If either of the directories to be synchronized contains the file ".backup"
- * then it is a backup directory.  The file ".backup" in this directory is
- * an array of mode information indexed on inode number.
- *
- * 89/04/05, Kees J. Bot - Birth of tree synchronizing program.
- * 92/02/02		 - General overhaul, rcp(1) like syntax.
- */
-
-#define nil 0
-#include <sys/types.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <utime.h>
-#include <string.h>
-#include <signal.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <sys/wait.h>
-
-#if _MINIX
-#include "limits.h"
-#include "minix/config.h"
-
-/*#define BLOCK_SIZE	1024*/
-#define LITTLE_ENDIAN	(CHIP == INTEL)
-#define USE_SHADOWING	(CHIP == M68000)
-#else
-#define LITTLE_ENDIAN	0
-#define USE_SHADOWING	0
-#endif
-
-#ifndef PATH_MAX
-#define PATH_MAX	1024
-#endif
-
-#ifndef S_ISLNK
-/* There were no symlinks in medieval times. */
-#define S_ISLNK(mode)			(0)
-#define lstat				stat
-#define symlink(path1, path2)		(errno= ENOSYS, -1)
-#define readlink(path, buf, len)	(errno= ENOSYS, -1)
-#endif
-
-#define NUMBYTES     4	/* Any number fits in this many bytes. */
-#define CHUNK     4096	/* Transfer files in this size chunks. */
-
-static int install= 0;	/* Install files, do not delete, update if newer. */
-static int interact= 0;	/* Ask permission to install too. */
-static int force= 0;	/* Force trees to be completely equal. */
-static int backup= 0;	/* This tree is for backup. */
-
-static char SYNCNAME[]	= "synctree";
-static char SLAVENAME[]	= "==SLAVE==";
-static char MASTERNAME[]= "==MASTER==";
-
-
-static char BACKUP[] = ".backup";	/* Backup filemodes. */
-static int filemodes;			/* Filemodes fildes. */
-
-static int chan[2]= { 0, 1 };	/* In and output channel to opposite side. */
-
-#define BUCKSIZE (1+NUMBYTES+CHUNK)
-static char bucket[BUCKSIZE];	/* Put a lot of things here before sending. */
-static char *buckp= bucket;	/* Fill pointer. */
-static int buckn= 0;		/* # bytes in bucket. */
-
-enum orders {	/* What back breaking labour should the slave perform? */
-	ENTER= 128,	/* Make ready to process contents of directory. */
-	ADVANCE,	/* Determine next pathname and report it back. */
-	CAT,		/* Send contents of file. */
-	MORE,		/* Send more file contents. */
-	CANCEL,		/* Current pathname is not installed, remove as link. */
-	DIE,		/* Die with exit(0); */
-	DIE_BAD,	/* exit(1); */
-	POSITIVE,	/* Ask a yes/no question expecting yes. */
-	NEGATIVE,	/* Same expecting no. */
-	PASS_YES,	/* Pass this to the master will you. */
-	PASS_NO		/* Same here. */
-};
-
-#ifdef DEBUG
-char *ORDERS[]= {
-	"ENTER", "ADVANCE", "CAT", "MORE", "CANCEL", "DIE", "DIE_BAD",
-	"POSITIVE", "NEGATIVE", "PASS_YES", "PASS_NO"
-};
-#endif
-
-enum answers {
-	PATH= 128,	/* Report pathname, and stat(2) info. */
-	LINK,		/* Report linkname, pathname, and stat(2) info. */
-	DATA,		/* Contents of file follow. */
-	NODATA,		/* Can't read file. */
-	DONE,		/* Nothing more to advance to. */
-	SYMLINK,	/* Report symlinkname, pathname, and stat(2) info. */
-	YES, NO		/* Result of an ASK. */
-};
-
-#ifdef DEBUG
-char *ANSWERS[]= {
-	"PATH", "LINK", "DATA", "NODATA", "DONE", "SYMLINK", "YES", "NO"
-};
-
-#define DPRINTF(format, arg)	fprintf(stderr, format, arg0, arg)
-#else
-#define DPRINTF(format, arg)
-#endif
-
-struct mode {
-	unsigned short	md_mode;
-	unsigned short	md_uid;
-	unsigned short	md_gid;
-	unsigned short	md_rdev;
-	unsigned short	md_devsiz;
-};
-
-static char *arg0;	/* basename(argv[0]) */
-static int ex= 0;	/* exit status. */
-
-static void because()
-{
-	fprintf(stderr, ": %s\n", strerror(errno));
-	ex= 1;
-}
-
-static void perr(label) char *label;
-{
-	fprintf(stderr, "%s: %s: %s\n", arg0, label, strerror(errno));
-	ex= 1;
-}
-
-static void perrx(label) char *label;
-{
-	perr(label);
-	exit(1);
-}
-
-#if S_HIDDEN
-/* Support for per achitecture hidden files. */
-static int transparent= 0;
-
-static void isvisible(name) char *name;
-{
-	char *p= name + strlen(name);
-
-	while (p > name && *--p == '/') {}
-
-	if (p > name && *p == '@' && p[-1] != '/') transparent= 1;
-}
-#else
-#define transparent	0
-#define isvisible(name)	((void) 0)
-#endif
-
-static void isbackup(slave) int slave;
-{
-	if ((filemodes= open(BACKUP, slave ? O_RDONLY : O_RDWR)) >= 0)
-		backup= 1;
-	else {
-		if (errno != ENOENT) perrx(BACKUP);
-	}
-}
-
-static char path[PATH_MAX+1];	/* Holds pathname of file being worked on. */
-static char lnkpth[PATH_MAX+1];	/* (Sym)link to path. */
-static char *linkpath;		/* What path is, or should be linked to. */
-static struct stat st;		/* Corresponding stat(2) info. */
-static char Spath[PATH_MAX+1];	/* Slave is looking at this. */
-static char Slnkpth[PATH_MAX+1];/* (Sym)link to Spath. */
-static char *Slinkpath=nil;	/* Either nil or Slnkpth. */
-static struct stat Sst;		/* Slave's stat(2). */
-
-static char *addpath(p, n) char *p, *n;
-/* Add a name to the path, return pointer to end. */
-{
-	if (p - path + 1 + strlen(n) > PATH_MAX) {
-		*p= 0;
-		fprintf(stderr, "%s: %s/%s is too long.\n", arg0, path, n);
-		fprintf(stderr, "%s: Unable to continue.\n", arg0);
-		exit(1);
-	}
-	if (p == path+1 && path[0] == '.') p= path;
-
-	if (p > path) *p++ = '/';
-
-	while (*n != 0) *p++ = *n++;
-	*p= 0;
-	return p;
-}
-
-struct entry {	/* A directory entry. */
-	struct entry	*next;	/* Next entry in same directory */
-	struct entry	*dir;	/* It is part of this directory */
-	struct entry	*con;	/* If a dir, its contents */
-	char		*name;	/* Name of this dir entry */
-};
-
-static struct entry *E= nil;		/* File being processed. */
-
-static void setpath(e) struct entry *e;
-/* Set path leading to e. */
-{
-	static char *pend;
-
-	if (e == nil)
-		pend= path;
-	else {
-		setpath(e->dir);
-		pend= addpath(pend, e->name);
-	}
-}
-
-static void sort(ae) struct entry **ae;
-/* This is either a stable mergesort, or thermal noise, I'm no longer sure.
- * It must be called like this: if (L!=nil && L->next!=nil) sort(&L);
- */
-{
-	/* static */ struct entry *e1, **mid;  /* Need not be local */
-	struct entry *e2;
-
-	e1= *(mid= &(*ae)->next);
-	do {
-		if ((e1= e1->next) == nil) break;
-		mid= &(*mid)->next;
-	} while ((e1= e1->next) != nil);
-
-	e2= *mid;
-	*mid= nil;
-
-	if ((*ae)->next != nil) sort(ae);
-	if (e2->next != nil) sort(&e2);
-
-	e1= *ae;
-	for (;;) {
-		if (strcmp(e1->name, e2->name)<=0) {
-			if ((e1= *(ae= &e1->next)) == nil) {
-				*ae= e2;
-				break;
-			}
-		} else {
-			*ae= e2;
-			e2= *(ae= &e2->next);
-			*ae= e1;
-			if (e2 == nil) break;
-		}
-	}
-}
-
-static void enter()
-/* Collect directory entries of E. */
-{
-	struct entry **last= &E->con, *new;
-	struct dirent *e;
-	DIR *d;
-
-	if ((d= opendir(path)) == nil) {
-		fprintf(stderr, "%s: Can't read dir %s\n", arg0, path);
-		return;
-	}
-
-	while ((e= readdir(d)) != nil) {
-		if (e->d_name[0] == '.' && (e->d_name[1] == 0
-			|| (e->d_name[1] == '.' && e->d_name[2] == 0)
-		)) continue;
-
-		new= (struct entry *) malloc(sizeof(*new));
-
-		new->next= nil;
-		new->dir= E;
-		new->con= nil;
-		new->name= (char *) malloc(strlen(e->d_name) + 1);
-		strcpy(new->name, e->d_name);
-		*last= new;
-		last= &new->next;
-	}
-	closedir(d);
-	if (E->con != nil && E->con->next != nil) sort(&E->con);
-}
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-static char *link_islink(struct stat *stp, const char *file)
-{
-    /* Tell if a file, which stat(2) information in '*stp', has been seen
-     * earlier by this function under a different name.  If not return a
-     * null pointer with errno set to ENOENT, otherwise return the name of
-     * the link.  Return a null pointer with an error code in errno for any
-     * error, using E2BIG for a too long file name.
-     *
-     * Use link_islink(nil, nil) to reset all bookkeeping.
-     *
-     * Call for a file twice to delete it from the store.
-     */
-
-    typedef struct link {	/* In-memory link store. */
-	struct link	*next;		/* Hash chain on inode number. */
-	ino_t		ino;		/* File's inode number. */
-	off_t		off;		/* Offset to more info in temp file. */
-    } link_t;
-    typedef struct dlink {	/* On-disk link store. */
-	dev_t		dev;		/* Device number. */
-	char		file[PATH_MAX];	/* Name of earlier seen link. */
-    } dlink_t;
-    static link_t *links[256];		/* Hash list of known links. */
-    static int tfd= -1;			/* Temp file for file name storage. */
-    static dlink_t dlink;
-    link_t *lp, **plp;
-    size_t len;
-    off_t off;
-
-    if (file == nil) {
-	/* Reset everything. */
-	for (plp= links; plp < arraylimit(links); plp++) {
-	    while ((lp= *plp) != nil) {
-		*plp= lp->next;
-		free(lp);
-	    }
-	}
-	if (tfd != -1) close(tfd);
-	tfd= -1;
-	return nil;
-    }
-
-    /* The file must be a non-directory with more than one link. */
-    if (S_ISDIR(stp->st_mode) || stp->st_nlink <= 1) {
-	errno= ENOENT;
-	return nil;
-    }
-
-    plp= &links[stp->st_ino % arraysize(links)];
-
-    while ((lp= *plp) != nil) {
-	if (lp->ino == stp->st_ino) {
-	    /* May have seen this link before.  Get it and check. */
-	    if (lseek(tfd, lp->off, SEEK_SET) == -1) return nil;
-	    if (read(tfd, &dlink, sizeof(dlink)) < 0) return nil;
-
-	    /* Only need to check the device number. */
-	    if (dlink.dev == stp->st_dev) {
-		if (strcmp(file, dlink.file) == 0) {
-		    /* Called twice.  Forget about this link. */
-		    *plp= lp->next;
-		    free(lp);
-		    errno= ENOENT;
-		    return nil;
-		}
-
-		/* Return the name of the earlier link. */
-		return dlink.file;
-	    }
-	}
-	plp= &lp->next;
-    }
-
-    /* First time I see this link.  Add it to the store. */
-    if (tfd == -1) {
-	for (;;) {
-	    char *tmp;
-
-	    tmp= tmpnam(nil);
-	    tfd= open(tmp, O_RDWR|O_CREAT|O_EXCL, 0600);
-	    if (tfd < 0) {
-		if (errno != EEXIST) return nil;
-	    } else {
-		(void) unlink(tmp);
-		break;
-	    }
-	}
-    }
-    if ((len= strlen(file)) >= PATH_MAX) {
-	errno= E2BIG;
-	return nil;
-    }
-
-    dlink.dev= stp->st_dev;
-    strcpy(dlink.file, file);
-    len += offsetof(dlink_t, file) + 1;
-    if ((off= lseek(tfd, 0, SEEK_END)) == -1) return nil;
-    if (write(tfd, &dlink, len) != len) return nil;
-
-    if ((lp= malloc(sizeof(*lp))) == nil) return nil;
-    lp->next= nil;
-    lp->ino= stp->st_ino;
-    lp->off= off;
-    *plp= lp;
-    errno= ENOENT;
-    return nil;
-}
-
-#define cancellink()	((void) islink())
-
-static char *islink()
-/* Returns the name of the file path is linked to.  If no such link can be
- * found, then path is added to the list and nil is returned.  If all the
- * links of a file have been seen, then it is removed from the list.
- * Directories are not seen as linkable.
- */
-{
-	char *name;
-
-	name= link_islink(&st, path);
-	if (name == nil && errno != ENOENT) perrx(path);
-	return name;
-}
-
-static void setstat(ino, stp) ino_t ino; struct stat *stp;
-/* Set backup status info, we know that backup is true. */
-{
-	struct mode md;
-
-	md.md_mode = stp->st_mode;
-	md.md_uid = stp->st_uid;
-	md.md_gid = stp->st_gid;
-	md.md_rdev = stp->st_rdev;
-	md.md_devsiz = stp->st_size / 1024;
-
-	if (lseek(filemodes, (off_t) sizeof(md) * (off_t) ino, 0) == -1
-		|| write(filemodes, (char *) &md, sizeof(md)) != sizeof(md)
-	) perrx(BACKUP);
-}
-
-static int getstat(name, stp) char *name; struct stat *stp;
-/* Get status information of file name, skipping some files.  Backup info
- * is inserted as needed.
- */
-{
-	errno= 0;
-
-	if (strcmp(name, BACKUP) == 0) return -1;
-
-	if (lstat(name, stp) < 0) return -1;
-
-	if (stp->st_mode == S_IFREG && stp->st_mtime == 0) return -1;
-
-	if (backup) {
-		struct mode md;
-
-		if (lseek(filemodes,
-			(off_t) sizeof(md) * (off_t) stp->st_ino, 0) == -1
-		    || read(filemodes, (char *) &md, sizeof(md)) != sizeof(md)
-		    || md.md_mode == 0
-		) {
-			errno= 0;
-			setstat(stp->st_ino, stp);
-		} else {
-			stp->st_mode = md.md_mode;
-			stp->st_uid = md.md_uid;
-			stp->st_gid = md.md_gid;
-			stp->st_rdev = md.md_rdev;
-			if (S_ISBLK(stp->st_mode))
-				stp->st_size= (off_t) md.md_devsiz * 1024;
-		}
-	}
-	return 0;
-}
-
-static int advance()
-/* Determine next pathname, return true on success. */
-{
-	for (;;) {
-		if (E==nil) {	/* First call, enter root dir. */
-			E= (struct entry *) malloc(sizeof(*E));
-			E->dir= nil;
-			E->con= nil;
-			E->next= nil;
-			E->name= (char *) malloc(3);
-			strcpy(E->name, transparent ? ".@" : ".");
-		} else
-		if (E->con != nil)	/* Dir's files must be processed. */
-			E= E->con;
-		else {
-			for (;;) {
-				/* Remove E from it's parents list, then
-				 * try next entry, if none, go to parent dir.
-				 */
-				struct entry *junk= E, *parent= E->dir;
-
-				if (parent != nil) parent->con= E->next;
-				E= E->next;
-				free(junk->name);
-				free(junk);
-
-				if (E != nil) break;
-
-				if ((E= parent) == nil) return 0;
-			}
-		}
-		setpath(E);
-		if (getstat(path, &st) == 0) {
-			if (S_ISLNK(st.st_mode)) {
-				int n;
-
-				if ((n= readlink(path, lnkpth, PATH_MAX)) >= 0)
-				{
-					lnkpth[n]= 0;
-					break;
-				}
-			} else {
-				break;
-			}
-		}
-		if (errno != 0 && errno != ENOENT) perr(path);
-	}
-
-	linkpath= islink();
-	DPRINTF("%s: path = %s\n", path);
-	return 1;
-}
-
-static enum orders request()
-/* Slave reads command sent by master. */
-{
-	static char buf[64], *bp;
-	static int n= 0;
-	int req;
-
-	for (;;) {
-		if (n == 0) {
-			if ((n= read(chan[0], buf, (int) sizeof(buf))) <= 0) {
-				if (n < 0) perrx("request()");
-				/* Master died, try to report it then follow. */
-				fprintf(stderr,
-					"%s: Master died prematurely.\n", arg0);
-				exit(1);
-			}
-			bp= buf;
-		}
-		req= *bp++ & 0xFF;
-		n--;
-		if (req >= (int) ENTER) break;
-
-		/* Master using slave to print to stdout: */
-		putchar(req);
-	}
-	DPRINTF("%s: request() == %s\n", ORDERS[req - (int) ENTER]);
-
-	return (enum orders) req;
-}
-
-static void report()
-{
-	int r;
-
-	DPRINTF("%s: reporting now!\n", 0);
-
-	buckp= bucket;
-
-	while (buckn > 0) {
-		r = buckn;
-		if (r > (512 << sizeof(char*))) r= (512 << sizeof(char*));
-
-		if ((r= write(chan[1], buckp, r)) < 0) perrx("report()");
-
-		buckp += r;
-		buckn -= r;
-	}
-	buckp= bucket;
-	buckn= 0;
-}
-
-static void inform(a) enum answers a;
-/* Slave replies to master. */
-{
-	DPRINTF("%s: inform(%s)\n", ANSWERS[(int) a - (int) PATH]);
-
-	*buckp++ = (int) a;
-	buckn++;
-}
-
-#define wwrite(buf, n)	(memcpy(buckp, (buf), (n)), buckp+= (n), buckn+= (n))
-
-static void sendnum(n) long n;
-/* Send number from least to most significant byte. */
-{
-#if LITTLE_ENDIAN
-	wwrite((char *) &n, sizeof(n));
-#else
-	char buf[NUMBYTES];
-
-	buf[0]= (char) (n >>  0);
-	buf[1]= (char) (n >>  8);
-	buf[2]= (char) (n >> 16);
-	buf[3]= (char) (n >> 24);
-	wwrite(buf, sizeof(buf));
-#endif
-}
-
-static void send(buf, n) char *buf; int n;
-/* Slave sends size and contents of buf. */
-{
-	sendnum((long) n);
-	if (n > 0) wwrite(buf, (size_t) n);
-}
-
-static void sendstat(stp) struct stat *stp;
-{
-	sendnum((long) stp->st_mode);
-	sendnum((long) stp->st_uid);
-	sendnum((long) stp->st_gid);
-	sendnum((long) stp->st_rdev);
-	sendnum((long) stp->st_size);
-	sendnum((long) stp->st_mtime);
-}
-
-static int ask();
-
-static void slave()
-/* Carry out orders from the master, such as transmitting path names.
- * Note that the slave uses path, not Spath, the master uses Spath.
- */
-{
-	int f, n;
-	char buf[CHUNK];
-	enum { run, done, die } state= run;
-
-	do {
-		switch (request()) {
-		case ENTER:
-			enter();
-			break;
-		case ADVANCE:
-			if (!advance() || state == done) {
-				inform(DONE);
-				state= done;
-			} else {
-				if (linkpath!=nil) {
-					inform(LINK);
-					send(linkpath, strlen(linkpath) + 1);
-				} else
-				if (S_ISLNK(st.st_mode)) {
-					inform(SYMLINK);
-					send(lnkpth, strlen(lnkpth) + 1);
-				} else {
-					inform(PATH);
-				}
-				send(path, strlen(path) + 1);
-				sendstat(&st);
-			}
-			break;
-		case CAT:
-			if ((f= open(path, O_RDONLY))<0) {
-				fprintf(stderr, "%s: Can't open %s",
-					arg0, path);
-				because();
-				inform(NODATA);
-				break;
-			}
-			inform(DATA);
-			do {
-				n= read(f, buf, sizeof(buf));
-				if (n < 0) perr(path);
-				send(buf, n);
-				if (n > 0) report();
-			} while (n > 0);
-			close(f);
-			break;
-		case CANCEL:
-			cancellink();
-			break;
-		case DIE_BAD:
-			ex= 1;
-			/*FALL THROUGH*/
-		case DIE:
-			state= die;
-			break;
-		case POSITIVE:
-			inform(ask('y') ? YES : NO);
-			break;
-		case NEGATIVE:
-			inform(ask('n') ? YES : NO);
-			break;
-		case PASS_YES:
-			inform(YES);
-			break;
-		case PASS_NO:
-			inform(NO);
-			break;
-		default:
-			fprintf(stderr, "%s: strange request\n", arg0);
-			exit(1);
-		}
-		report();
-	} while (state != die);
-}
-
-static int execute(argv) char **argv;
-/* Execute a command and return its success or failure. */
-{
-	int pid, r, status;
-
-	if ((pid= fork())<0) {
-		perr("fork()");
-		return 0;
-	}
-	if (pid == 0) {
-		execvp(argv[0], argv);
-		perrx(argv[0]);
-	}
-	while ((r= wait(&status)) != pid) {
-		if (r < 0) {
-			perr(argv[0]);
-			return 0;
-		}
-	}
-	return status == 0;
-}
-
-static int removedir(dir) char *dir;
-/* Remove a directory and its contents. */
-{
-	static char *argv[] = { "rm", "-r", nil, nil };
-
-	printf("(rm -r %s)\n", dir);
-
-	argv[2]= dir;
-	return execute(argv);
-}
-
-static void order(o) enum orders o;
-/* Master tells slave what to do. */
-{
-	char c= (char) o;
-
-	DPRINTF("%s: order(%s)\n", ORDERS[o - (int) ENTER]);
-
-	if (write(chan[1], &c, 1) != 1) perrx("order()");
-}
-
-static void rread(buf, n) char *buf; int n;
-/* Master gets buf of size n from slave, doing multiple reads if needed. */
-{
-	int r;
-
-	while (n > 0) {
-		if (buckn == 0) {
-			switch (buckn= read(chan[0], bucket, BUCKSIZE)) {
-			case -1:
-				perrx("reply channel from slave");
-			case  0:
-				fprintf(stderr,
-					"%s: slave died prematurely.\n",
-					arg0);
-				exit(1);
-			}
-			buckp= bucket;
-		}
-		r= n < buckn ? n : buckn;
-		memcpy(buf, buckp, r);
-		buckp+= r;
-		buckn-= r;
-		buf+= r;
-		n-= r;
-	}
-}
-
-static enum answers answer()
-/* Master reads slave's reply. */
-{
-	char c;
-	int a;
-
-	rread(&c, 1);
-	a= c & 0xFF;
-
-	DPRINTF("%s: answer() == %s\n", ANSWERS[a - (int) PATH]);
-
-	return (enum answers) a;
-}
-
-static long recnum()
-/* Read number as pack of bytes from least to most significant.  The data
- * is on the wire in little-endian format.  (Mostly run on PC's).
- */
-{
-#if LITTLE_ENDIAN
-	long n;
-
-	rread((char *) &n, (int) sizeof(n));
-	return n;
-#else
-	unsigned char buf[NUMBYTES];
-
-	rread(buf, sizeof(buf));
-	return	buf[0]
-		| ((unsigned) buf[1] << 8)
-		| ((unsigned long) buf[2] << 16)
-		| ((unsigned long) buf[3] << 24);
-#endif
-}
-
-static int receive(buf, max) char *buf; int max;
-/* Master get's data from slave, by first reading size, then data. */
-{
-	int n;
-
-	n= recnum();
-	if (n > max) {
-		fprintf(stderr, "%s: panic: Can't read %d bytes\n", arg0, n);
-		exit(1);
-	}
-	if (n > 0) rread(buf, n);
-	return n;
-}
-
-static void recstat(stp) struct stat *stp;
-{
-	stp->st_mode= recnum();
-	stp->st_uid= recnum();
-	stp->st_gid= recnum();
-	stp->st_rdev= recnum();
-	stp->st_size= recnum();
-	stp->st_mtime= recnum();
-}
-
-static int key()
-{
-	int c;
-	static int tty= -1;
-
-	if (tty < 0) tty= isatty(0);
-
-	if (feof(stdin) || (c= getchar()) == EOF) {
-		c= '\n';
-		if (tty) putchar('\n');
-	}
-
-	if (!tty) putchar(c);
-
-	return c;
-}
-
-static int ask(def) int def;
-/* Ask for a yes or no, anything else means choose def. */
-{
-	int y, c;
-
-	if (chan[0] == 0) {
-		/* I'm running remote, tell the slave to ask. */
-		fflush(stdout);
-		order(def == 'y' ? POSITIVE : NEGATIVE);
-		return answer() == YES;
-	}
-
-	printf("? (%c) ", def);
-	fflush(stdout);
-
-	do c= key(); while (c == ' ' || c == '\t');
-
-	y= c;
-
-	while (c != '\n') c= key();
-
-	if (y != 'y' && y != 'Y' && y != 'n' && y != 'N') y= def;
-
-	return y == 'y' || y == 'Y';
-}
-
-static void setmodes(silent) int silent;
-{
-	struct stat st;
-	int change= 0;
-	struct utimbuf tms;
-
-	errno= 0;
-	getstat(Spath, &st);
-	if (backup && silent) {
-		setstat(st.st_ino, &Sst);
-		getstat(Spath, &st);
-	}
-
-	if (S_ISLNK(st.st_mode)) return;
-
-	if (errno == 0 && st.st_mode != Sst.st_mode) {
-		if (!backup) chmod(Spath, Sst.st_mode & 07777);
-		change= 1;
-	}
-	if (errno == 0
-		&& (st.st_uid != Sst.st_uid || st.st_gid != Sst.st_gid)
-		&& (backup || geteuid() == 0)
-	) {
-		errno= 0;
-		if (!backup) chown(Spath, Sst.st_uid, Sst.st_gid);
-		change= 1;
-	}
-
-	if (backup && !silent) setstat(st.st_ino, &Sst);
-
-	if (errno == 0 && S_ISREG(Sst.st_mode) && st.st_mtime != Sst.st_mtime) {
-		time(&tms.actime);
-		tms.modtime= Sst.st_mtime;
-		errno= 0;
-		utime(Spath, &tms);
-		change= 1;
-	}
-	if (errno != 0) {
-		fprintf(stderr, "%s: Can't set modes of %s", arg0, Spath);
-		because();
-	} else
-	if (change && !silent) {
-		printf("Mode changed of %s\n", Spath);
-	}
-}
-
-static void makeold()
-{
-	static struct utimbuf tms= { 0, 0 };
-
-	if (utime(Spath, &tms) < 0) {
-		if (errno != ENOENT) {
-			fprintf(stderr,
-				"%s: can't make %s look old", arg0, Spath);
-			because();
-		}
-	} else {
-		fprintf(stderr, "%s: made %s look old.\n", arg0, Spath);
-	}
-}
-
-static int busy= 0;
-
-static void bail_out(sig) int sig;
-{
-	signal(sig, SIG_IGN);
-
-	fprintf(stderr, "%s: Exiting after signal %d\n", arg0, sig);
-
-	if (busy) {
-		fprintf(stderr, "%s: was installing %s\n", arg0, Spath);
-		makeold();
-	}
-	order(DIE_BAD);
-
-	exit(sig);
-}
-
-static int makenode(name, mode, addr, size)
-	char *name; int mode; dev_t addr; off_t size;
-{
-	int r;
-
-	if (!backup) {
-		r= mknod(name, mode, addr);
-	} else {
-		if ((r= creat(name, 0644)) >= 0) close(r);
-	}
-	return r;
-}
-
-static void add(update) int update;
-/* Add Spath to the filesystem. */
-{
-	int f, n;
-	char buf[CHUNK];
-	int forced_update= force && update;
-
-	if (Slinkpath != nil && !S_ISLNK(Sst.st_mode)) {
-		if (interact && !update) {
-			printf("Link %s to %s", Spath, Slinkpath);
-			if (!ask('n')) return;
-		}
-		if (link(Slinkpath, Spath) >= 0) {
-			printf("Linked %s to %s\n", Spath, Slinkpath);
-			return;
-		} else {
-			fprintf(stderr,
-				"%s: Can't link %s to %s",
-				arg0, Slinkpath, Spath);
-			because();
-			/* Try to install instead. */
-		}
-	}
-	switch (Sst.st_mode & S_IFMT) {
-	case S_IFDIR:
-		if (!force) {
-			printf("Add dir %s", Spath);
-			if (!ask('n')) return;
-		}
-		if (mkdir(Spath, backup ? 0755 : Sst.st_mode) < 0) {
-			perr(Spath);
-			return;
-		}
-		printf("Directory %s created.\n", Spath);
-		order(ENTER);
-		break;
-	case S_IFBLK:
-	case S_IFCHR:
-	case S_IFIFO:
-		if (interact && !update) {
-			printf("Create special file %s", Spath);
-			if (!ask('n')) { order(CANCEL); return; }
-		}
-		if (makenode(Spath, Sst.st_mode, Sst.st_rdev, Sst.st_size)<0) {
-			fprintf(stderr,
-				"%s: Can't create special file %s",
-				arg0, Spath);
-			because();
-			return;
-		}
-		printf("Special file %s created\n", Spath);
-		break;
-#ifdef S_IFLNK
-	case S_IFLNK:
-		if (interact && !update) {
-			printf("Install %s -> %s", Spath, Slnkpth);
-			if (!ask('n')) { order(CANCEL); return; }
-		}
-		if (symlink(Slnkpth, Spath) < 0) {
-			fprintf(stderr, "%s: Can't create symlink %s",
-				arg0, Spath);
-			because();
-			return;
-		}
-		printf("%s %s -> %s\n",
-			forced_update ? "Updated:  " : "Installed:",
-			Spath, Slnkpth);
-		break;
-#endif
-	case S_IFREG:
-		if (interact && !update) {
-			printf("Install %s", Spath);
-			if (!ask('n')) { order(CANCEL); return; }
-		}
-		order(CAT);
-		if (answer() != DATA) return;
-
-		busy= 1;
-		if ((f= creat(Spath, backup ? 0644 : Sst.st_mode&07777)) < 0) {
-			busy= 0;
-			fprintf(stderr, "%s: Can't create %s", arg0, Spath);
-			because();
-		}
-
-		while ((n= receive(buf, sizeof(buf)))>0) {
-			if (f >= 0 && write(f, buf, n) != n) {
-				fprintf(stderr, "%s: Write error on %s",
-					arg0, Spath);
-				because();
-				close(f); f= -1;
-			}
-		}
-		if (n < 0) {
-			fprintf(stderr, "%s: Slave read err on %s\n",
-				arg0, Spath);
-		}
-		if (f >= 0) close(f);
-		if (n < 0 || f < 0) { makeold(); busy= 0; return; }
-		busy= 0;
-		printf("%s %s\n",
-			forced_update ?
-				Sst.st_mtime < st.st_mtime ? "Restored: " :
-					"Updated:  " :
-				"Installed:",
-			Spath
-		);
-		break;
-	default:
-		fprintf(stderr,
-			"%s: Won't add file with strange mode %05o: %s\n",
-			arg0, Sst.st_mode, Spath);
-		order(CANCEL);
-		return;
-	}
-	setmodes(1);
-}
-
-static int delete(update) int update;
-/* Delete path. */
-{
-	int forced_update= force && update;
-
-	if (S_ISDIR(st.st_mode)) {
-		if (install) return 0;
-		if (!force) {
-			printf("Delete dir %s", path);
-			if (!ask('n')) return 0;
-		}
-		if (!removedir(path)) { ex= 1; return 0; }
-		if (!forced_update) printf("Directory %s deleted.\n", path);
-		return 1;
-	}
-
-	if (install && !update) return 0;
-
-	if (!force) {
-		printf("Delete %s", path);
-		if (!ask((interact && !update) ? 'n' : 'y')) return 0;
-	}
-
-	if (unlink(path)<0) {
-		fprintf(stderr, "Can't delete %s", path);
-		because();
-		return 0;
-	}
-	cancellink();
-	if (!forced_update) printf("Deleted:   %s\n", path);
-	return 1;
-}
-
-static int different()
-/* Return true iff path and Spath are different. */
-{
-	if (! ( (linkpath == nil && Slinkpath == nil)
-		|| (linkpath != nil && Slinkpath != nil
-			&& strcmp(linkpath, Slinkpath) == 0)
-	)) {
-		linkpath= Slinkpath;
-		return 1;
-	}
-
-	if ((st.st_mode & S_IFMT) != (Sst.st_mode & S_IFMT)) return 1;
-
-	switch (st.st_mode & S_IFMT) {
-	case S_IFDIR:
-		return 0;
-	case S_IFBLK:
-	case S_IFCHR:
-		return st.st_rdev != Sst.st_rdev;
-	case S_IFREG:
-		if (install) return Sst.st_mtime > st.st_mtime;
-		return st.st_size != Sst.st_size
-			|| st.st_mtime != Sst.st_mtime;
-	case S_IFIFO:	return 0;
-#ifdef S_IFLNK
-	case S_IFLNK:	return strcmp(lnkpth, Slnkpth) != 0;
-#endif
-	default:	return 1;
-	}
-}
-
-static void compare()
-/* See if path and Spath are same. */
-{
-	if (different()) {
-		if (!force) {
-			printf("%sing %s (delete + add)\n",
-				Sst.st_mtime < st.st_mtime ? "Restor" : "Updat",
-				path);
-		}
-		if (delete(1)) add(1);
-	} else {
-		if (!install) setmodes(0);
-
-		if (S_ISDIR(st.st_mode)) {
-			order(ENTER);
-			enter();
-		}
-	}
-}
-
-static int done= 0, Sdone= 0;
-
-static enum action { ADD, COMPARE, DELETE } action()
-/* Look at path's of master and slave, compare them alphabetically to see
- * who is ahead of who, then tell what is to be done.
- */
-{
-	int c;
-	char *Sp, *p;
-
-	if (done) return ADD;		/* Slave still has names. */
-	if (Sdone) return DELETE;	/* Master has too many names. */
-
-	/* Compare paths.  Let "a/a" come before "a.a". */
-	Sp= Spath;
-	p= path;
-	while (*Sp == *p && *Sp != 0) { Sp++; p++; }
-	if (*Sp == '/') return ADD;
-	if (*p == '/') return DELETE;
-	return (c= strcmp(Sp, p)) == 0 ? COMPARE : c < 0 ? ADD : DELETE;
-}
-
-static void master()
-/* Synchronise file tree to that of its slave. */
-{
-	enum action a= COMPARE;	/* Trick first advances. */
-
-	umask(backup ? 0022 : 0000);
-
-	signal(SIGPIPE, SIG_IGN);
-	signal(SIGHUP, bail_out);
-	signal(SIGINT, bail_out);
-	signal(SIGTERM, bail_out);
-
-	while (!done || !Sdone) {
-		if (!Sdone && (a == ADD || a == COMPARE)) {
-			/* Slave advances. */
-			order(ADVANCE);
-			switch (answer()) {
-			case PATH:
-				Slinkpath= nil;
-				receive(Spath, sizeof(Spath));
-				recstat(&Sst);
-				break;
-			case LINK:
-				receive(Slnkpth, sizeof(Slnkpth));
-				Slinkpath= Slnkpth;
-				receive(Spath, sizeof(Spath));
-				recstat(&Sst);
-				break;
-			case SYMLINK:
-				Slinkpath= nil;
-				receive(Slnkpth, sizeof(Slnkpth));
-				receive(Spath, sizeof(Spath));
-				recstat(&Sst);
-				break;
-			case DONE:
-				Sdone= 1;
-				break;
-			default:
-				fprintf(stderr,
-					"%s: Strange answer from slave.\n",
-					arg0);
-				exit(1);
-			}
-		}
-		if (!done && (a == COMPARE || a == DELETE)) {
-			/* Master advances. */
-			if (!advance()) done= 1;
-		}
-
-		if (done && Sdone) break;
-
-		switch (a= action()) {
-		case ADD:	/* Spath exists, path doesn't, add? */
-			add(0);
-			break;
-		case COMPARE:	/* They both exist, are they the same? */
-			compare();
-			break;
-		case DELETE:	/* path exists, Spath doesn't, delete? */
-			delete(0);
-		}
-		fflush(stdout);	/* Don't keep user in suspense. */
-	}
-	order(ex == 0 ? DIE : DIE_BAD);
-}
-
-static void mediator()
-/* Sits at the local machine and passes orders from master to slave, both
- * on remote machines.  Only diagnostics and questions are handled.
- */
-{
-	enum orders req;
-
-	for (;;) {
-		switch (req= request()) {
-		case DIE_BAD:
-			ex= 1;
-			/*FALL THROUGH*/
-		case DIE:
-			order(DIE);
-			return;
-		case POSITIVE:
-			order(ask('y') ? PASS_YES : PASS_NO);
-			break;
-		case NEGATIVE:
-			order(ask('n') ? PASS_YES : PASS_NO);
-			break;
-		default:
-			order(req);
-		}
-	}
-}
-
-#define P_EXIT		1	/* Make sure process doesn't return. */
-#define P_SHADOW	2	/* Always use exec on 68000. */
-
-static void startprocess(proc, machine, path, p_flags)
-	void (*proc)(); char *machine, *path; int p_flags;
-{
-	char *argv[10], **argp= argv;
-	char flags[10], *pfl= flags;
-
-	if (machine != nil) {
-		char *u= machine, *m;
-
-		*argp++ = "rsh";
-		if ((m= strchr(machine, '@')) != nil) {
-			*m++ = 0;
-			*argp++ = "-l";
-			*argp++ = u;
-			machine= m;
-		}
-		*argp++ = machine;
-	} else
-	/* Without this check it would run like a pig on an non MMU 68000: */
-	if (!(USE_SHADOWING && p_flags & P_SHADOW)) {
-		if (chdir(path) < 0) {
-			if (proc != master || errno != ENOENT
-						|| mkdir(path, 0700) < 0)
-				perrx(path);
-			if (chdir(path) < 0) perrx(path);
-			printf("Destination directory %s created\n", path);
-		}
-		isvisible(path);
-		isbackup(proc == slave);
-		(*proc)();
-		if (p_flags & P_EXIT) exit(ex);
-		return;
-	}
-	*argp++ = SYNCNAME;
-	*pfl++ = '-';
-	if (interact) *pfl++ = 'i';
-	if (install) *pfl++ = 'u';
-	if (force) *pfl++ = 'f';
-	*pfl= 0;
-	*argp++ = flags;
-	*argp++ = proc == slave ? SLAVENAME : MASTERNAME;
-	*argp++ = path;
-	*argp++ = nil;
-#ifdef DEBUG
-	fprintf(stderr, "execlp(");
-	for (argp= argv; *argp != nil; argp++) fprintf(stderr, "%s, ", *argp);
-	fprintf(stderr, "nil);\n");
-#endif
-	execvp(argv[0], argv);
-	perrx(argv[0]);
-}
-
-void splitcolon(path, amach, adir) char *path, **amach, **adir;
-{
-	char *dir= path;
-
-	for (;;) {
-		if (*dir == ':') {
-			*dir++ = 0;
-			*amach= path;
-			*adir= dir;
-			break;
-		}
-		if (*dir == 0 || *dir == '/') {
-			*amach= nil;
-			*adir= path;
-			break;
-		}
-		dir++;
-	}
-}
-
-static void Usage()
-{
-	fprintf(stderr,
-	    "Usage: %s [-iuf] [[user@]machine:]dir1 [[user@]machine:]dir2\n",
-		arg0);
-	exit(1);
-}
-
-main(argc, argv) int argc; char **argv;
-{
-	char *s_mach, *s_dir;
-	char *m_mach, *m_dir;
-	int m2s[2], s2m[2], m2m[2];
-	int s_pid= 0, m_pid= 0;
-	int r;
-
-	if ((arg0= strrchr(argv[0], '/')) == nil) arg0= argv[0]; else arg0++;
-
-	while (argc>1 && argv[1][0] == '-') {
-		char *f= argv[1]+1;
-
-		while (*f != 0) {
-			switch (*f++) {
-			case 'i':	interact= 1; break;
-			case 'u':	install= 1; break;
-			case 'f':	force= 1; break;
-			default:	Usage();
-			}
-		}
-		argc--;
-		argv++;
-	}
-
-	if (argc != 3) Usage();
-
-	if (strcmp(argv[1], SLAVENAME) == 0) {
-		arg0= "Slave";
-		splitcolon(argv[2], &s_mach, &s_dir);
-		startprocess(slave, s_mach, s_dir, P_EXIT);
-	} else
-	if (strcmp(argv[1], MASTERNAME) == 0) {
-		arg0= "Master";
-		splitcolon(argv[2], &m_mach, &m_dir);
-		startprocess(master, m_mach, m_dir, P_EXIT);
-	}
-
-	splitcolon(argv[1], &s_mach, &s_dir);
-	splitcolon(argv[2], &m_mach, &m_dir);
-
-	/* How difficult can plumbing be? */
-	if (pipe(m2s) < 0 || pipe(s2m) < 0) perrx("pipe()");
-
-	if (m_mach == nil) {
-		/* synctree [machine:]dir1 dir2 */
-		switch (s_pid= fork()) {
-		case -1:
-			perrx("fork()");
-		case 0:
-			dup2(m2s[0], 0); close(m2s[0]); close(m2s[1]);
-			dup2(s2m[1], 1); close(s2m[0]); close(s2m[1]);
-			arg0= "Slave";
-			startprocess(slave, s_mach, s_dir, P_EXIT|P_SHADOW);
-		}
-		chan[0]= s2m[0]; close(s2m[1]);
-		chan[1]= m2s[1]; close(m2s[0]);
-		startprocess(master, m_mach, m_dir, 0);
-	} else
-	if (s_mach == nil) {
-		/* synctree dir1 machine:dir2 */
-		switch (m_pid= fork()) {
-		case -1:
-			perrx("fork()");
-		case 0:
-			dup2(s2m[0], 0); close(s2m[0]); close(s2m[1]);
-			dup2(m2s[1], 1); close(m2s[0]); close(m2s[1]);
-			arg0= "Master";
-			startprocess(master, m_mach, m_dir, P_EXIT|P_SHADOW);
-		}
-		chan[0]= m2s[0]; close(m2s[1]);
-		chan[1]= s2m[1]; close(s2m[0]);
-		startprocess(slave, s_mach, s_dir, 0);
-	} else {
-		/* synctree machine1:dir1 machine2:dir2 */
-		if (pipe(m2m) < 0) perrx(pipe);
-
-		switch (s_pid= fork()) {
-		case -1:
-			perrx("fork()");
-		case 0:
-			dup2(m2s[0], 0); close(m2s[0]); close(m2s[1]);
-			dup2(s2m[1], 1); close(s2m[0]); close(s2m[1]);
-			close(m2m[0]); close(m2m[1]);
-			arg0= "Slave";
-			startprocess(slave, s_mach, s_dir, P_EXIT|P_SHADOW);
-		}
-
-		switch (m_pid= fork()) {
-		case -1:
-			perrx("fork()");
-		case 0:
-			dup2(s2m[0], 0); close(s2m[0]); close(s2m[1]);
-			close(m2s[0]); close(m2s[1]);
-			dup2(m2m[1], 1); close(m2m[0]); close(m2m[1]);
-			arg0= "Master";
-			startprocess(master, m_mach, m_dir, P_EXIT|P_SHADOW);
-		}
-		close(s2m[0]); close(s2m[1]);
-		chan[0]= m2m[0]; close(m2m[1]);
-		chan[1]= m2s[1]; close(m2s[0]);
-		mediator();
-	}
-	close(chan[0]);
-	close(chan[1]);
-
-	alarm(15); /* Don't wait(2) forever. */
-
-	while (s_pid != 0 || m_pid != 0) {
-		if ((r= wait((int *) nil)) < 0) perrx("wait()");
-		if (r == s_pid) s_pid= 0;
-		if (r == m_pid) m_pid= 0;
-	}
-	exit(ex);
-}
Index: trunk/minix/commands/simple/sysenv.c
===================================================================
--- trunk/minix/commands/simple/sysenv.c	(revision 9)
+++ 	(revision )
@@ -1,80 +1,0 @@
-/*	sysenv 1.0 - request system boot parameter	Author: Kees J. Bot
- *								23 Dec 2000
- */
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <sys/svrctl.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-
-#define NIL ((char*)0)
-
-static void tell(int fd, ...)
-{
-    va_list ap;
-    char *s;
-
-    va_start(ap, fd);
-    while ((s= va_arg(ap, char *)) != NIL) {
-	(void) write(fd, s, strlen(s));
-    }
-    va_end(ap);
-}
-
-int main(int argc, char **argv)
-{
-    struct sysgetenv sysgetenv;
-    int i;
-    int ex= 0;
-    char *e;
-    char val[1024];
-
-    i= 1;
-    while (i < argc && argv[i][0] == '-') {
-	char *opt= argv[i++]+1;
-
-	if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-	if (*opt != 0) {
-	    tell(2, "Usage: sysenv [name ...]\n", NIL);
-	    exit(1);
-	}
-    }
-
-    do {
-	if (i < argc) {
-	    sysgetenv.key= argv[i];
-	    sysgetenv.keylen= strlen(sysgetenv.key) + 1;
-	} else {
-	    sysgetenv.key= nil;
-	    sysgetenv.keylen= 0;
-	}
-	sysgetenv.val= val;
-	sysgetenv.vallen= sizeof(val);
-
-	if (svrctl(MMGETPARAM, &sysgetenv) == -1) {
-	    if (errno == ESRCH) {
-		ex |= 2;
-	    } else {
-		ex |= 1;
-		tell(2, "sysenv: ", strerror(errno), "\n", NIL);
-	    }
-	    continue;
-	}
-
-	e= sysgetenv.val;
-	do {
-	    e += strlen(e);
-	    *e++ = '\n';
-	} while (i == argc && *e != 0);
-
-	if (write(1, sysgetenv.val, e - sysgetenv.val) < 0) {
-	    ex |= 1;
-	    tell(2, "sysenv: ", strerror(errno), "\n", NIL);
-	}
-    } while (++i < argc);
-    return ex;
-}
Index: trunk/minix/commands/simple/tail.c
===================================================================
--- trunk/minix/commands/simple/tail.c	(revision 9)
+++ 	(revision )
@@ -1,359 +1,0 @@
-/* tail - copy the end of a file	Author: Norbert Schlenker */
-
-/*   Syntax:	tail [-f] [-c number | -n number] [file]
- *		tail -[number][c|l][f] [file]		(obsolescent)
- *		tail +[number][c|l][f] [file]		(obsolescent)
- *   Flags:
- *	-c number	Measure starting point in bytes.  If number begins
- *			with '+', the starting point is relative to the
- *			the file's beginning.  If number begins with '-'
- *			or has no sign, the starting point is relative to
- *			the end of the file.
- *	-f		Keep trying to read after EOF on files and FIFOs.
- *	-n number	Measure starting point in lines.  The number
- *			following the flag has significance similar to
- *			that described for the -c flag.
- *
- *   If neither -c nor -n are specified, the default is tail -n 10.
- *
- *   In the obsolescent syntax, an argument with a 'c' following the
- *   (optional) number is equivalent to "-c number" in the standard
- *   syntax, with number including the leading sign ('+' or '-') of the
- *   argument.  An argument with 'l' following the number is equivalent
- *   to "-n number" in the standard syntax.  If the number is not
- *   specified, 10 is used as the default.  If neither 'c' nor 'l' are
- *   specified, 'l' is assumed.  The character 'f' may be suffixed to
- *   the argument and is equivalent to specifying "-f" in the standard
- *   syntax.  Look for lines marked "OBSOLESCENT".
- *
- *   If no file is specified, standard input is assumed. 
- *
- *   P1003.2 does not specify tail's behavior when a count of 0 is given.
- *   It also does not specify clearly whether the first byte (line) of a
- *   file should be numbered 0 or 1.  Historical behavior is that the
- *   first byte is actually number 1 (contrary to all Unix standards).
- *   Historically, a count of 0 (or -0) results in no output whatsoever,
- *   while a count of +0 results in the entire file being copied (just like
- *   +1).  The implementor does not agree with these behaviors, but has
- *   copied them slavishly.  Look for lines marked "HISTORICAL".
- *   
- *   Author:    Norbert Schlenker
- *   Copyright: None.  Released to the public domain.
- *   Reference: P1003.2 section 4.59 (draft 10)
- *   Notes:	Under Minix, this program requires chmem =30000.
- *   Bugs:	No internationalization support; all messages are in English.
- */
-
-/* Force visible Posix names */
-#ifndef _POSIX_SOURCE
-#define _POSIX_SOURCE 1
-#endif
-
-/* External interfaces */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-/* External interfaces that should have been standardized into <getopt.h> */
-extern char *optarg;
-extern int optind;
-
-/* We expect this constant to be defined in <limits.h> in a Posix program,
- * but we'll specify it here just in case it's been left out.
- */
-#ifndef LINE_MAX
-#define LINE_MAX 2048		/* minimum acceptable lower bound */
-#endif
-
-/* Magic numbers suggested or required by Posix specification */
-#define SUCCESS	0		/* exit code in case of success */
-#define FAILURE 1		/*                   or failure */
-#define DEFAULT_COUNT 10	/* default number of lines or bytes */
-#define MIN_BUFSIZE (LINE_MAX * DEFAULT_COUNT)
-#define SLEEP_INTERVAL	1	/* sleep for one second intervals with -f */
-
-#define FALSE 0
-#define TRUE 1
-
-/* Internal functions - prototyped under Minix */
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(int tail, (int count, int bytes, int read_until_killed));
-_PROTOTYPE(int keep_reading, (void));
-_PROTOTYPE(void usage, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int cflag = FALSE;
-  int nflag = FALSE;
-  int fflag = FALSE;
-  int number = -DEFAULT_COUNT;
-  char *suffix;
-  int opt;
-  struct stat stat_buf;
-
-/* Determining whether this invocation is via the standard syntax or
- * via an obsolescent one is a nasty kludge.  Here it is, but there is
- * no pretense at elegance.
- */
-  if (argc == 1) {		/* simple:  default read of a pipe */
-	exit(tail(-DEFAULT_COUNT, 0, fflag));
-  }
-  if ((argv[1][0] == '+') ||	/* OBSOLESCENT */
-      (argv[1][0] == '-' && ((isdigit(argv[1][1])) ||
-			     (argv[1][1] == 'l') ||
-			     (argv[1][1] == 'c' && argv[1][2] == 'f')))) {
-	--argc; ++argv;
-	if (isdigit(argv[0][1])) {
-		number = (int)strtol(argv[0], &suffix, 10);
-		if (number == 0) {		/* HISTORICAL */
-			if (argv[0][0] == '+')
-				number = 1;
-			else
-				exit(SUCCESS);
-		}
-	} else {
-		number = (argv[0][0] == '+') ? DEFAULT_COUNT : -DEFAULT_COUNT;
-		suffix = &(argv[0][1]);
-	}
-	if (*suffix != '\0') {
-		if (*suffix == 'c') {
-			cflag = TRUE;
-			++suffix;
-		}
-		else
-		if (*suffix == 'l') {
-			nflag = TRUE;
-			++suffix;
-		}
-	}
-	if (*suffix != '\0') {
-		if (*suffix == 'f') {
-			fflag = TRUE;
-			++suffix;
-		}
-	}
-	if (*suffix != '\0') {	/* bad form: assume to be a file name */
-		number = -DEFAULT_COUNT;
-		cflag = nflag = FALSE;
-		fflag = FALSE;
-	} else {
-		--argc; ++argv;
-	}
-  } else {			/* new standard syntax */
-	while ((opt = getopt(argc, argv, "c:fn:")) != EOF) {
-		switch (opt) {
-		      case 'c':
-			cflag = TRUE;
-			if (*optarg == '+' || *optarg == '-')
-				number = atoi(optarg);
-			else
-			if (isdigit(*optarg))
-				number = -atoi(optarg);
-			else
-				usage();
-			if (number == 0) {		/* HISTORICAL */
-				if (*optarg == '+')
-					number = 1;
-				else
-					exit(SUCCESS);
-			}
-			break;
-		      case 'f':
-			fflag = TRUE;
-			break;
-		      case 'n':
-			nflag = TRUE;
-			if (*optarg == '+' || *optarg == '-')
-				number = atoi(optarg);
-			else
-			if (isdigit(*optarg))
-				number = -atoi(optarg);
-			else
-				usage();
-			if (number == 0) {		/* HISTORICAL */
-				if (*optarg == '+')
-					number = 1;
-				else
-					exit(SUCCESS);
-			}
-			break;
-		      default:
-			usage();
-			/* NOTREACHED */
-		}
-	}
-	argc -= optind;
-	argv += optind;
-  }
-
-  if (argc > 1 ||		/* too many arguments */
-      (cflag && nflag)) {	/* both bytes and lines specified */
-	usage();
-  }
-
-  if (argc > 0) {		/* an actual file */
-	if (freopen(argv[0], "r", stdin) != stdin) {
-		fputs("tail: could not open ", stderr);
-		fputs(argv[0], stderr);
-		fputs("\n", stderr);
-		exit(FAILURE);
-	}
-	/* There is an optimization possibility here.  If a file is being
-	 * read, we need not look at the front of it.  If we seek backwards
-         * from the end, we can (potentially) avoid looking at most of the
-	 * file.  Some systems fail when asked to seek backwards to a point
-	 * before the start of the file, so we avoid that possibility.
-	 */
-	if (number < 0 && fstat(fileno(stdin), &stat_buf) == 0) {
-		long offset = cflag ? (long)number : (long)number * LINE_MAX;
-
-		if (-offset < stat_buf.st_size)
-			fseek(stdin, offset, SEEK_END);
-	}
-  } else {
-	fflag = FALSE;		/* force -f off when reading a pipe */
-  }
-  exit(tail(number, cflag, fflag));
-  /* NOTREACHED */
-}
-
-int tail(count, bytes, read_until_killed)
-int count;			/* lines or bytes desired */
-int bytes;			/* TRUE if we want bytes */
-int read_until_killed;		/* keep reading at EOF */
-{
-  int c;
-  char *buf;			/* pointer to input buffer */
-  char *buf_end;		/* and one past its end */
-  char *start;			/* pointer to first desired character in buf */
-  char *finish;			/* pointer past last desired character */
-  int wrapped_once = FALSE;	/* TRUE after buf has been filled once */
-
-/* This is magic.  If count is positive, it means start at the count'th
- * line or byte, with the first line or byte considered number 1.  Thus,
- * we want to SKIP one less line or byte than the number specified.  In
- * the negative case, we look backward from the end of the file for the
- * (count + 1)'th newline or byte, so we really want the count to be one
- * LARGER than was specified (in absolute value).  In either case, the
- * right thing to do is:
- */
-  --count;
-
-/* Count is positive:  skip the desired lines or bytes and then copy. */
-  if (count >= 0) {
-	while (count > 0 && (c = getchar()) != EOF) {
-		if (bytes || c == '\n')
-			--count;
-	}
-	while ((c = getchar()) != EOF) {
-		if (putchar(c) == EOF)
-			return FAILURE;
-	}
-	if (read_until_killed)
-		return keep_reading();
-	return ferror(stdin) ? FAILURE : SUCCESS;
-  }
-
-/* Count is negative:  allocate a reasonably large buffer. */
-  if ((buf = (char *)malloc(MIN_BUFSIZE + 1)) == (char *)NULL) {
-	fputs("tail: out of memory\n", stderr);
-	return FAILURE;
-  }
-  buf_end = buf + (MIN_BUFSIZE + 1);
-
-/* Read the entire file into the buffer. */
-  finish = buf;
-  while ((c = getchar()) != EOF) {
-	*finish++ = c;
-	if (finish == buf_end) {
-		finish = buf;
-		wrapped_once = TRUE;
-	}
-  }
-  if (ferror(stdin))
-	return FAILURE;
-
-/* Back up inside the buffer.  The count has already been adjusted to
- * back up exactly one character too far, so we will bump the buffer
- * pointer once after we're done.
- * 
- * BUG: For large line counts, the buffer may not be large enough to
- *	hold all the lines.  The specification allows the program to
- *	fail in such a case - this program will simply dump the entire
- *	buffer's contents as its best attempt at the desired behavior.
- */
-  if (finish != buf || wrapped_once) {		/* file was not empty */
-	start = (finish == buf) ? buf_end - 1 : finish - 1;
-	while (start != finish) {
-		if ((bytes || *start == '\n') && ++count == 0)
-			break;
-		if (start == buf) {
-			start = buf_end - 1;
-			if (!wrapped_once)	/* never wrapped: stop now */
-				break;
-		} else {
-			--start;
-		}
-	}
-	if (++start == buf_end) {		/* bump after going too far */
-		start = buf;
-	}
-	if (finish > start) {
-		fwrite(start, 1, finish - start, stdout);
-	} else {
-		fwrite(start, 1, buf_end - start, stdout);
-		fwrite(buf, 1, finish - buf, stdout);
-	}
-  }
-  if (read_until_killed)
-	return keep_reading();
-  return ferror(stdout) ? FAILURE : SUCCESS;
-}
-
-/* Wake at intervals to reread standard input.  Copy anything read to
- * standard output and then go to sleep again.
- */
-int keep_reading()
-{
-  char buf[1024];
-  int n;
-  int i;
-  off_t pos;
-  struct stat st;
-
-  pos = lseek(0, (off_t) 0, SEEK_CUR);
-  for (;;) {
-  	for (i = 0; i < 60; i++) {
-  		while ((n = read(0, buf, sizeof(buf))) > 0) {
-  			if (write(1, buf, n) < 0) return FAILURE;
-  		}
-  		if (n < 0) return FAILURE;
-
-		sleep(SLEEP_INTERVAL);
-	}
-
-	/* Rewind if suddenly truncated. */
-	if (pos != -1) {
-		if (fstat(0, &st) == -1) {
-			pos = -1;
-		} else
-		if (st.st_size < pos) {
-			pos = lseek(0, (off_t) 0, SEEK_SET);
-		} else {
-			pos = st.st_size;
-		}
-	}
-  }
-}
-
-/* Tell the user the standard syntax. */
-void usage()
-{
-  fputs("Usage: tail [-f] [-c number | -n number] [file]\n", stderr);
-  exit(FAILURE);
-}
Index: trunk/minix/commands/simple/tar.c
===================================================================
--- trunk/minix/commands/simple/tar.c	(revision 9)
+++ 	(revision )
@@ -1,1108 +1,0 @@
-/* tar - tape archiver			Author: Michiel Huisjes */
-
-/* Usage: tar [cxt][vo][F][f] tapefile [files]
- *
- * attempt to make tar to conform to POSIX 1003.1
- * disclaimer: based on an old (1986) POSIX draft.
- * Klamer Schutte, 20/9/89
- *
- * Changes:
- *  Changed to handle the original minix-tar format.	KS 22/9/89
- *  Changed to handle BSD4.3 tar format.		KS 22/9/89
- *  Conform to current umask if not super-user.		KS 22/9/89
- *  Update usage message to show f option		KS 22/9/89
- *
- *
- * 1)	tar will back itself up, should check archive inode num(&dev) and
-  then check the target inode number. In verbose mode, issue
-  warning, in all cases ignore target.
-  marks@mgse		Mon Sep 25 10:38:58 CDT 1989
-  	added global varaibles, made changes to main() and add_file();
-  maks@mgse Mon Sep 25 12:09:20 CDT 1989
-
-   2)	tar will not notice that a file has changed size while it was being
-  backed up. should issue warning.
-  marks@mgse		Mon Sep 25 10:38:58 CDT 1989
-
-   3)	the 'f' option was not documented in usage[].
-  marks@mgse		Mon Sep 25 12:03:20 CDT 1989
-  	changed both usage[] defines. Why are there two (one is commented out)?
-  	( deleted by me (was done twice) -- KS, 2/10/89 )
- *
- *  changed stat on tar_fd to an fstat				KS 2/10/89
- *  deleted mkfifo() code -- belongs in libc.a			KS 2/10/89
- *  made ar_dev default to -1 : an illegal device		KS 2/10/89
- *  made impossible to chown if normal user			KS 2/10/89
- *  if names in owner fields not known use numirical values	KS 2/10/89
- *  creat with mask 666 -- use umask if to liberal		KS 2/10/89
- *  allow to make directories as ../directory			KS 2/10/89
- *  allow tmagic field to end with a space (instead of \0)	KS 2/10/89
- *  correct usage of tmagic field 				KS 3/10/89
- *  made mkdir() to return a value if directory == "."  	KS 3/10/89
- *  made lint complains less (On a BSD 4.3 system)		KS 3/10/89
- *  use of directory(3) routines				KS 3/10/89
- *  deleted use of d_namlen selector of struct dirent		KS 18/10/89
- *  support mknod4(2)						EC 7/7/90
- *  forget inodes when link count expires			EC 6/4/91
- *  don't remember directories *twice*!
- *  added 'p' flag to ignore umask for normal user		KJB 6/10/92
- *  mknod4(2) out						KJB 30/10/94
- *  added 'D' flag to not recurse into directories		KJB 19/12/94
- *  status output to stdout unless 'tar cvf -'			KJB 3/5/97
- *
- * Bugs:
- *  verbose mode is not reporting consistent
- *  code needs cleanup
- *  prefix field is not used
- *  timestamp of a directory will not be correct if there are files to be
- *  unpacked in the directory
- *	(add you favorite bug here (or two (or three (or ...))))
-*/
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <grp.h>
-#include <tar.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <utime.h>
-#include <sys/wait.h>
-#include <stdio.h>		/* need NULL */
-#include <errno.h>
-
-#define	POSIX_COMP		/* POSIX compatible */
-#define DIRECT_3		/* use directory(3) routines */
-
-#ifdef DIRECT_3
-#ifndef BSD
-/* To all minix users: i am sorry, developed this piece of code on a
- * BSD system. KS 18/10/89 */
-#include <dirent.h>
-#define	direct	dirent		/* stupid BSD non-POSIX compatible name! */
-#else				/* BSD */
-#include <sys/dir.h>
-#include <dir.h>
-#endif				/* BSD */
-#endif				/* DIRECT_3 */
-
-#ifdef S_IFIFO
-#define	HAVE_FIFO		/* have incorporated Simon Pooles' changes */
-#endif
-#ifdef S_IFLNK
-#define HAVE_SYMLINK
-#endif
-
-typedef char BOOL;
-#define TRUE	1
-#define FALSE	0
-
-#define STRING_SIZE	256	/* string buffer size */
-#define HEADER_SIZE	TBLOCK
-#define NAME_SIZE	NAMSIZ
-/* #define BLOCK_BOUNDARY	 20 -- not in POSIX ! */
-
-typedef union hblock HEADER;
-
-/* Make the MINIX member names overlap to the POSIX names */
-#define	m_name		name
-#define m_mode		mode
-#define m_uid		uid
-#define m_gid		gid
-#define m_size		size
-#define	m_time		mtime
-#define	m_checksum	chksum
-#define	m_linked	typeflag
-#define	m_link		linkname
-#define	hdr_block	dummy
-#define	m		header
-#define	member		dbuf
-
-#if 0				/* original structure -- see tar.h for new
-			 * structure */
-typedef union {
-  char hdr_block[HEADER_SIZE];
-  struct m {
-	char m_name[NAME_SIZE];
-	char m_mode[8];
-	char m_uid[8];
-	char m_gid[8];
-	char m_size[12];
-	char m_time[12];
-	char m_checksum[8];
-	char m_linked;
-	char m_link[NAME_SIZE];
-  } member;
-} HEADER;
-
-#endif
-
-/* Structure used to note links */
-struct link {
-  ino_t ino;
-  dev_t dev;
-  nlink_t nlink;
-  struct link *next;
-  char name[1];
-} *link_top = NULL;
-
-HEADER header;
-
-#define INT_TYPE	(sizeof(header.member.m_uid))
-#define LONG_TYPE	(sizeof(header.member.m_size))
-
-#define NIL_HEADER	((HEADER *) 0)
-#define NIL_PTR		((char *) 0)
-#define TBLOCK_SIZE	TBLOCK
-
-#define flush()		print(NIL_PTR)
-
-BOOL show_fl, creat_fl, ext_fl;
-
-int tar_fd;
-/* Char usage[] = "Usage: tar [cxt] tarfile [files]."; */
-char usage[] = "Usage: tar [cxt][vo][F][f] tarfile [files].";
-char io_buffer[TBLOCK_SIZE];
-char path[NAME_SIZE];
-char pathname[NAME_SIZE];
-int force_flag = 0;
-#ifdef ORIGINAL_DEFAULTS
-int chown_flag = 1;
-int verbose_flag = 1;
-#else
-int chown_flag = 0;
-int verbose_flag = 0;
-#endif
-int norec_flag = 0;
-
-/* Make sure we don't tar ourselves. marks@mgse Mon Sep 25 12:06:28 CDT 1989 */
-ino_t ar_inode;			/* archive inode number	 */
-dev_t ar_dev;			/* archive device number */
-
-int total_blocks;
-int u_mask;			/* one's complement of current umask */
-
-#define block_size()	(int) ((convert(header.member.m_size, LONG_TYPE) \
-  + (long) TBLOCK_SIZE - 1) / (long) TBLOCK_SIZE)
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void error, (char *s1, char *s2));
-_PROTOTYPE(BOOL get_header, (void));
-_PROTOTYPE(void tarfile, (void));
-_PROTOTYPE(void skip_entry, (void));
-_PROTOTYPE(void extract, (char *file));
-_PROTOTYPE(void delete, (char *file));
-_PROTOTYPE(void do_chown, (char *file));
-_PROTOTYPE(void timestamp, (char *file));
-_PROTOTYPE(void copy, (char *file, int from, int to, long bytes));
-_PROTOTYPE(long convert, (char str[], int type));
-_PROTOTYPE(int checksum, (void));
-_PROTOTYPE(int is_dir, (char *file));
-_PROTOTYPE(char *path_name, (char *file));
-_PROTOTYPE(void add_path, (char *name));
-_PROTOTYPE(void add_file, (char *file));
-_PROTOTYPE(void verb_print, (char *s1, char *s2));
-_PROTOTYPE(void add_close, (int fd));
-_PROTOTYPE(int add_open, (char *file, struct stat * st));
-_PROTOTYPE(void make_header, (char *file, struct stat * st));
-_PROTOTYPE(void is_added, (struct stat * st, char *file));
-_PROTOTYPE(void is_deleted, (struct stat * st));
-_PROTOTYPE(char *is_linked, (struct stat * st));
-_PROTOTYPE(void clear_header, (void));
-_PROTOTYPE(void adjust_boundary, (void));
-_PROTOTYPE(void mread, (int fd, char *address, int bytes));
-_PROTOTYPE(void mwrite, (int fd, char *address, int bytes));
-_PROTOTYPE(int bread, (int fd, char *address, int bytes));
-_PROTOTYPE(int bwrite, (int fd, char *address, int bytes));
-_PROTOTYPE(void print, (char *str));
-_PROTOTYPE(char *num_out, (long number));
-_PROTOTYPE(void string_print, (char *buffer, char *fmt,...));
-
-void error(s1, s2)
-char *s1, *s2;
-{
-  string_print(NIL_PTR, "%s %s\n", s1, s2 ? s2 : "");
-  flush();
-  exit(1);
-}
-
-int main(argc, argv)
-int argc;
-register char *argv[];
-{
-  register char *mem_name;
-  register char *ptr;
-  struct stat st;
-  int i;
-
-  if (argc < 3) error(usage, NIL_PTR);
-
-  for (ptr = argv[1]; *ptr; ptr++) {
-  	/* Ignore - as first char */
-  	if(*ptr == '-' && ptr == argv[1]) continue;
-	switch (*ptr) {
-	    case 'c':	creat_fl = TRUE;	break;
-	    case 'x':	ext_fl = TRUE;	break;
-	    case 't':	show_fl = TRUE;	break;
-	    case 'v':		/* verbose output  -Dal */
-		verbose_flag = !verbose_flag;
-		break;
-	    case 'o':		/* chown/chgrp files  -Dal */
-		chown_flag = TRUE;
-		break;
-	    case 'F':		/* IGNORE ERRORS  -Dal */
-		force_flag = TRUE;
-		break;
-	    case 'f':		/* standard U*IX usage -KS */
-		break;
-	    case 'p':		/* restore file modes right, ignore umask. */
-		(void) umask(0);
-		break;
-	    case 'D':		/* do not recursively add directories. */
-		norec_flag = TRUE;
-		break;
-	    default:	error(usage, NIL_PTR);
-	}
-  }
-
-  if (creat_fl + ext_fl + show_fl != 1) error(usage, NIL_PTR);
-
-  if (strcmp(argv[2], "-") == 0)/* only - means stdin/stdout - KS */
-	tar_fd = creat_fl ? 1 : 0;	/* '-' means used
-					 * stdin/stdout  -Dal */
-  else
-	tar_fd = creat_fl ? creat(argv[2], 0666) : open(argv[2], O_RDONLY);
-
-  if (tar_fd < 0) error("Cannot open ", argv[2]);
-
-  if (geteuid()) {		/* check if super-user */
-	int save_umask;
-	save_umask = umask(0);
-	u_mask = ~save_umask;
-	umask(save_umask);
-	chown_flag = TRUE;	/* normal user can't chown */
-  } else
-	u_mask = ~0;		/* don't restrict if 'privileged utility' */
-
-  ar_dev = -1;			/* impossible device nr */
-  if (creat_fl) {
-	if (tar_fd > 1 && fstat(tar_fd, &st) < 0)
-		error("Can't stat ", argv[2]);	/* will never be here,
-						 * right? */
-	else {			/* get archive inode & device	 */
-		ar_inode = st.st_ino;	/* save files inode	 */
-		ar_dev = st.st_dev;	/* save files device	 */
-	}			/* marks@mgse Mon Sep 25 11:30:45 CDT 1989 */
-
-	for (i = 3; i < argc; i++) {
-		add_file(argv[i]);
-		path[0] = '\0';
-	}
-	adjust_boundary();
-  } else if (ext_fl) {
-	/* Extraction code moved here from tarfile() MSP */
-	while (get_header()) {
-		mem_name = header.member.m_name;
-		if (is_dir(mem_name)) {
-			for (ptr = mem_name; *ptr; ptr++);
-			*(ptr - 1) = '\0';
-			header.dbuf.typeflag = '5';
-		}
-		for (i = 3; i < argc; i++)
-			if (!strncmp(argv[i], mem_name, strlen(argv[i])))
-				break;
-		if (argc == 3 || (i < argc)) {
-			extract(mem_name);
-		} else if (header.dbuf.typeflag == '0' ||
-			   header.dbuf.typeflag == 0 ||
-			   header.dbuf.typeflag == ' ')
-			skip_entry();
-		flush();
-	}
-  } else
-	tarfile();		/* tarfile() justs prints info. now MSP */
-
-  flush();
-  return(0);
-}
-
-BOOL get_header()
-{
-  register int check;
-
-  mread(tar_fd, (char *) &header, sizeof(header));
-  if (header.member.m_name[0] == '\0') return FALSE;
-
-  if (force_flag)		/* skip checksum verification  -Dal */
-	return TRUE;
-
-  check = (int) convert(header.member.m_checksum, INT_TYPE);
-
-  if (check != checksum()) error("Tar: header checksum error.", NIL_PTR);
-
-  return TRUE;
-}
-
-/* Tarfile() just lists info about archive now; as of the t flag. */
-/* Extraction has been moved into main() as that needs access to argv[] */
-
-void tarfile()
-{
-  register char *mem_name;
-
-  while (get_header()) {
-	mem_name = header.member.m_name;
-	string_print(NIL_PTR, "%s%s", mem_name,
-		     (verbose_flag ? " " : "\n"));
-	switch (header.dbuf.typeflag) {
-	    case '1':
-		verb_print("linked to", header.dbuf.linkname);
-		break;
-	    case '2':
-		verb_print("symbolic link to", header.dbuf.linkname);
-		break;
-	    case '6':	verb_print("", "fifo");	break;
-	    case '3':
-	    case '4':
-		if (verbose_flag) {
-			char sizebuf[TSIZLEN + 1];
-
-			strncpy(sizebuf, header.dbuf.size, (size_t) TSIZLEN);
-			sizebuf[TSIZLEN] = 0;
-			string_print(NIL_PTR,
-			      "%s special file major %s minor %s\n",
-				     (header.dbuf.typeflag == '3' ?
-				      "character" : "block"),
-				     header.dbuf.devmajor,
-				     header.dbuf.devminor,
-				     sizebuf);
-		}
-		break;
-	    case '0':		/* official POSIX */
-	    case 0:		/* also mentioned in POSIX */
-	    case ' ':		/* ofetn used */
-		if (!is_dir(mem_name)) {
-			if (verbose_flag)
-				string_print(NIL_PTR, "%d tape blocks\n",
-					     block_size());
-			skip_entry();
-			break;
-		} else		/* FALL TROUGH */
-	    case '5':
-			verb_print("", "directory");
-		break;
-	    default:
-		string_print(NIL_PTR, "not recogised item %d\n",
-			     header.dbuf.typeflag);
-	}
-	flush();
-  }
-}
-
-void skip_entry()
-{
-  register int blocks = block_size();
-
-  while (blocks--) (void) bread(tar_fd, io_buffer, TBLOCK_SIZE);
-}
-
-void extract(file)
-register char *file;
-{
-  register int fd, r;
-  char *pd1, *pd2;		/* walk thru failed directory path */
-
-  switch (header.dbuf.typeflag) {
-      case '1':			/* Link */
-	delete(file);
-	if (link(header.member.m_link, file) < 0)
-		string_print(NIL_PTR, "Cannot link %s to %s: %s\n",
-			     header.member.m_link, file, strerror(errno));
-	else if (verbose_flag)
-		string_print(NIL_PTR, "Linked %s to %s\n",
-			     header.member.m_link, file);
-	return;
-      case '5':			/* directory */
-	if (!(file[0] == '.' && file[1] == '\0')) delete(file);
-	if ((file[0] == '.' && file[1] == '\0') || mkdir(file, 0700) == 0) {
-		do_chown(file);
-		verb_print("created directory", file);
-	} else {
-		string_print(NIL_PTR, "Can't make directory %s: %s\n",
-				file, strerror(errno));
-	}
-	return;
-      case '3':			/* character special */
-      case '4':			/* block special */
-	{
-		int dmajor, dminor, mode;
-
-		dmajor = (int) convert(header.dbuf.devmajor, INT_TYPE);
-		dminor = (int) convert(header.dbuf.devminor, INT_TYPE);
-		mode = (header.dbuf.typeflag == '3' ? S_IFCHR : S_IFBLK);
-		delete(file);
-		if (mknod(file, mode, (dmajor << 8 | dminor)) == 0) {
-			if (verbose_flag) string_print(NIL_PTR,
-				     "made %s special file major %s minor %s\n",
-				      (header.dbuf.typeflag == '3' ?
-				       "character" : "block"),
-					     header.dbuf.devmajor,
-					     header.dbuf.devminor);
-			do_chown(file);
-		}
-		else 
-		{
-			string_print(NIL_PTR,
-				     "cannot make %s special file major %s minor %s: %s\n",
-				      (header.dbuf.typeflag == '3' ?
-				       "character" : "block"),
-					     header.dbuf.devmajor,
-					     header.dbuf.devminor,
-					     strerror(errno));
-		}
-		return;
-	}
-      case '2':			/* symbolic link */
-#ifdef HAVE_SYMLINK
-	delete(file);
-	if (symlink(header.member.m_link, file) < 0)
-		string_print(NIL_PTR, "Cannot make symbolic link %s to %s: %s\n",
-			     header.member.m_link, file, strerror(errno));
-	else if (verbose_flag)
-		string_print(NIL_PTR, "Symbolic link %s to %s\n",
-			     header.member.m_link, file);
-	return;
-#endif
-      case '7':			/* contiguous file -- what is this (KS) */
-	print("Not implemented file type\n");
-	return;			/* not implemented, but break out */
-#ifdef HAVE_FIFO
-      case '6':			/* fifo */
-	delete(file);
-	if (mkfifo(file, 0) == 0) {	/* is chmod'ed in do_chown */
-		do_chown(file);
-		verb_print("made fifo", file);
-	} else
-		string_print(NIL_PTR, "Can't make fifo %s: %s\n",
-			file, strerror(errno));
-	return;
-#endif
-  }
-
-  /* Create regular file.  If failure, try to make missing directories. */
-  if ((fd = creat(file, 0600)) < 0) {
-	pd1 = file;
-	while ((pd2 = index(pd1, '/')) > (char *) 0) {
-		*pd2 = '\0';
-		if (access(file, 1) < 0)
-			if (mkdir(file, 0777) < 0) {
-				string_print(NIL_PTR, "Cannot mkdir %s: %s\n",
-					file, strerror(errno));
-				return;
-			} else
-				string_print(NIL_PTR, "Made directory %s\n", file);
-		*pd2 = '/';
-		pd1 = ++pd2;
-	}
-	if ((fd = creat(file, 0600)) < 0) {
-		string_print(NIL_PTR, "Cannot create %s: %s\n",
-			file, strerror(errno));
-		return;
-	}
-  }
-  copy(file, tar_fd, fd, convert(header.member.m_size, LONG_TYPE));
-  (void) close(fd);
-
-  do_chown(file);
-}
-
-void delete(file)
-char *file;
-{
-  /* remove a file or an empty directory */
-  struct stat stbuf;
-
-  if (stat(file, &stbuf) < 0) return;
-
-  if (S_ISDIR(stbuf.st_mode)) (void) rmdir(file); else (void) unlink(file);
-  /* leave error reporting to the create following soon. */
-}
-
-void do_chown(file)
-char *file;
-{
-  int uid = -1, gid = -1;	/* these are illegal ??? -- KS */
-
-  if (!chown_flag) {		/* set correct owner and group  -Dal */
-	if (header.dbuf.magic[TMAGLEN] == ' ')
-		header.dbuf.magic[TMAGLEN] = '\0';	/* some tars out there
-							 * ... */
-	if (strncmp(TMAGIC, header.dbuf.magic, (size_t) TMAGLEN)) {
-		struct passwd *pwd;
-		struct group *grp;
-
-		pwd = getpwnam(header.dbuf.uname);
-		if (pwd != NULL) uid = pwd->pw_uid;
-		grp = getgrnam(header.dbuf.gname);
-		if (grp != NULL) gid = grp->gr_gid;
-	}
-	if (uid == -1) uid = (int) convert(header.member.m_uid, INT_TYPE);
-	if (gid == -1) gid = (int) convert(header.member.m_gid, INT_TYPE);
-	chown(file, uid, gid);
-  }
-  chmod(file, u_mask & (int) convert(header.member.m_mode, INT_TYPE));
-
-  /* Should there be a timestamp if the chown failes? -- KS */
-  timestamp(file);
-
-}
-
-void timestamp(file)
-char *file;
-{
-  struct utimbuf buf;
-
-  buf.modtime = buf.actime = convert(header.dbuf.mtime, LONG_TYPE);
-  utime(file, &buf);
-}
-
-void copy(file, from, to, bytes)
-char *file;
-int from, to;
-register long bytes;
-{
-  register int rest;
-  int blocks = (int) ((bytes + (long) TBLOCK_SIZE - 1) / (long) TBLOCK_SIZE);
-
-  if (verbose_flag)
-	string_print(NIL_PTR, "%s, %d tape blocks\n", file, blocks);
-
-  while (blocks--) {
-	(void) bread(from, io_buffer, TBLOCK_SIZE);
-	rest = (bytes > (long) TBLOCK_SIZE) ? TBLOCK_SIZE : (int) bytes;
-	mwrite(to, io_buffer, (to == tar_fd) ? TBLOCK_SIZE : rest);
-	bytes -= (long) rest;
-  }
-}
-
-long convert(str, type)
-char str[];
-int type;
-{
-  register long ac = 0L;
-  register int i;
-
-  for (i = 0; i < type; i++) {
-	if (str[i] >= '0' && str[i] <= '7') {
-		ac <<= 3;
-		ac += (long) (str[i] - '0');
-	}
-  }
-
-  return ac;
-}
-
-int checksum()
-{
-  register char *ptr = header.member.m_checksum;
-  register int ac = 0;
-
-  while (ptr < &header.member.m_checksum[INT_TYPE]) *ptr++ = ' ';
-
-  ptr = header.hdr_block;
-  while (ptr < &header.hdr_block[TBLOCK_SIZE]) ac += *ptr++;
-
-  return ac;
-}
-
-int is_dir(file)
-register char *file;
-{
-  while (*file++ != '\0');
-
-  return(*(file - 2) == '/');
-}
-
-
-char *path_name(file)
-register char *file;
-{
-
-  string_print(pathname, "%s%s", path, file);
-  return pathname;
-}
-
-void add_path(name)
-register char *name;
-{
-  register char *path_ptr = path;
-
-  while (*path_ptr) path_ptr++;
-
-  if (name == NIL_PTR) {
-	while (*path_ptr-- != '/');
-	while (*path_ptr != '/' && path_ptr != path) path_ptr--;
-	if (*path_ptr == '/') path_ptr++;
-	*path_ptr = '\0';
-  } else {
-	while (*name) {
-		if (path_ptr == &path[NAME_SIZE])
-			error("Pathname too long", NIL_PTR);
-		*path_ptr++ = *name++;
-	}
-	*path_ptr++ = '/';
-	*path_ptr = '\0';
-  }
-}
-
-/*
- *	add a file to the archive
-*/
-void add_file(file)
-register char *file;
-{
-  struct stat st;
-  char *linkname;
-  register int fd = -1;
-  char namebuf[16];		/* -Dal */
-  char cwd[129];		/* -KS */
-
-#ifdef HAVE_SYMLINK
-  if (lstat(file, &st) < 0) {
-#else
-  if (stat(file, &st) < 0) {
-#endif
-	string_print(NIL_PTR, "%s: %s\n", file, strerror(errno));
-	return;
-  }
-  if (st.st_dev == ar_dev && st.st_ino == ar_inode) {
-	string_print(NIL_PTR, "Cannot tar current archive file (%s)\n", file);
-	return;
-  }				/* marks@mgse Mon Sep 25 12:06:28 CDT 1989 */
-  if ((fd = add_open(file, &st)) < 0) {
-	string_print(NIL_PTR, "Cannot open %s\n", file);
-	return;
-  }
-  make_header(path_name(file), &st);
-  if ((linkname = is_linked(&st)) != NULL) {
-	strncpy(header.dbuf.linkname, linkname, (size_t) NAMSIZ);
-	header.dbuf.typeflag = '1';
-	if (verbose_flag) string_print(NIL_PTR, "linked %s to %s\n",
-			     header.dbuf.linkname, file);
-	string_print(header.member.m_checksum, "%I ", checksum());
-	mwrite(tar_fd, (char *) &header, sizeof(header));
-  } else {
-	is_added(&st, file);
-	switch (st.st_mode & S_IFMT) {
-	    case S_IFREG:
-		header.dbuf.typeflag = '0';
-		string_print(header.member.m_checksum, "%I ", checksum());
-		mwrite(tar_fd, (char *) &header, sizeof(header));
-		copy(path_name(file), fd, tar_fd, (long) st.st_size);
-		break;
-	    case S_IFDIR:
-		header.dbuf.typeflag = '5';
-		string_print(header.member.m_checksum, "%I ", checksum());
-		mwrite(tar_fd, (char *) &header, sizeof(header));
-		verb_print("read directory", file);
-		if (norec_flag) break;
-		if (NULL == getcwd(cwd, (int) sizeof cwd))
-			string_print(NIL_PTR, "Error: cannot getcwd()\n");
-		else if (chdir(file) < 0)
-			string_print(NIL_PTR, "Cannot chdir to %s: %s\n",
-				file, strerror(errno));
-		else {
-			add_path(file);
-#ifdef	DIRECT_3
-			{
-				DIR *dirp;
-				struct direct *dp;
-				struct stat dst;
-
-				add_close(fd);
-				fd= 0;
-				dirp = opendir(".");
-				while (NULL != (dp = readdir(dirp)))
-					if (strcmp(dp->d_name, ".") == 0)
-						is_linked(&st);
-					else if (strcmp(dp->d_name, "..") == 0) {
-						if (stat("..", &dst) == 0)
-							is_linked(&dst);
-					} else {
-						strcpy(namebuf, dp->d_name);
-						add_file(namebuf);
-					}
-				closedir(dirp);
-			}
-#else
-			{
-				int i;
-				struct direct dir;
-				struct stat dst;
-
-				for (i = 0; i < 2; i++) {	/* . and .. */
-					mread(fd, &dir, sizeof(dir));
-					if (strcmp(dir.d_name, ".") == 0)
-						is_linked(&st);
-					else if (strcmp(dir.d_name, "..") == 0) {
-						if (stat("..", &dst) == 0)
-							is_linked(&dst);
-					} else
-						break;
-				}
-				while (bread(fd, &dir, sizeof(dir)) == sizeof(dir))
-					if (dir.d_ino) {
-						strncpy(namebuf, dir.d_name,
-						   (size_t) DIRSIZ);
-						namebuf[DIRSIZ] = '\0';
-						add_file(namebuf);
-					}
-			}
-#endif
-			chdir(cwd);
-			add_path(NIL_PTR);
-			*file = 0;
-		}
-		break;
-#ifdef HAVE_SYMLINK
-	    case S_IFLNK:
-		{
-			int i;
-
-			header.dbuf.typeflag = '2';
-			verb_print("read symlink", file);
-			i = readlink(file,
-				     header.dbuf.linkname,
-				  sizeof(header.dbuf.linkname) - 1);
-			if (i < 0) {
-				string_print(NIL_PTR,
-					"Cannot read symbolic link %s: %s\n",
-					file, strerror(errno));
-				return;
-			}
-			header.dbuf.linkname[i] = 0;
-			string_print(header.member.m_checksum, "%I ", checksum());
-			mwrite(tar_fd, (char *) &header, sizeof(header));
-			break;
-		}
-#endif
-#ifdef HAVE_FIFO
-	    case S_IFIFO:
-		header.dbuf.typeflag = '6';
-		verb_print("read fifo", file);
-		string_print(header.member.m_checksum, "%I ", checksum());
-		mwrite(tar_fd, (char *) &header, sizeof(header));
-		break;
-#endif
-	    case S_IFBLK:
-		header.dbuf.typeflag = '4';
-		if (verbose_flag) {
-			char sizebuf[TSIZLEN + 1];
-
-			strncpy(sizebuf, header.dbuf.size, (size_t) TSIZLEN);
-			sizebuf[TSIZLEN] = 0;
-			string_print(NIL_PTR,
-			 "read block device %s major %s minor %s\n",
-				     file, header.dbuf.devmajor, header.dbuf.devminor, sizebuf);
-		}
-		string_print(header.member.m_checksum, "%I ", checksum());
-		mwrite(tar_fd, (char *) &header, sizeof(header));
-		break;
-	    case S_IFCHR:
-		header.dbuf.typeflag = '3';
-		if (verbose_flag) string_print(NIL_PTR,
-				     "read character device %s major %s minor %s\n",
-				     file, header.dbuf.devmajor, header.dbuf.devminor);
-		string_print(header.member.m_checksum, "%I ", checksum());
-		mwrite(tar_fd, (char *) &header, sizeof(header));
-		break;
-	    default:
-		is_deleted(&st);
-		string_print(NIL_PTR, "Tar: %s unknown file type. Not added.\n", file);
-		*file = 0;
-	}
-  }
-
-  flush();
-  add_close(fd);
-}
-
-void verb_print(s1, s2)
-char *s1, *s2;
-{
-  if (verbose_flag) string_print(NIL_PTR, "%s: %s\n", s1, s2);
-}
-
-void add_close(fd)
-int fd;
-{
-  if (fd != 0) close(fd);
-}
-
-/*
- *	open file 'file' to be added to archive, return file descriptor
-*/
-int add_open(file, st)
-char *file;
-struct stat *st;
-{
-  int fd;
-  if (((st->st_mode & S_IFMT) != S_IFREG) &&
-      ((st->st_mode & S_IFMT) != S_IFDIR))
-	return 0;
-  fd = open(file, O_RDONLY);
-  if (fd == -1)
-  	fprintf(stderr, "open failed: %s\n", strerror(errno));
-  return fd;
-}
-
-void make_header(file, st)
-char *file;
-register struct stat *st;
-{
-  register char *ptr = header.member.m_name;
-  struct passwd *pwd;
-  struct group *grp;
-
-  clear_header();
-
-  while (*ptr++ = *file++);
-
-  if ((st->st_mode & S_IFMT) == S_IFDIR) {	/* fixed test  -Dal */
-	*(ptr - 1) = '/';
-  }
-  string_print(header.member.m_mode, "%I ", st->st_mode & 07777);
-  string_print(header.member.m_uid, "%I ", st->st_uid);
-  string_print(header.member.m_gid, "%I ", st->st_gid);
-  if ((st->st_mode & S_IFMT) == S_IFREG)
-	string_print(header.member.m_size, "%L ", st->st_size);
-  else
-	strncpy(header.dbuf.size, "0", (size_t) TSIZLEN);
-  string_print(header.member.m_time, "%L ", st->st_mtime);
-  strncpy(header.dbuf.magic, TMAGIC, (size_t) TMAGLEN);
-  header.dbuf.version[0] = 0;
-  header.dbuf.version[1] = 0;
-  pwd = getpwuid(st->st_uid);
-  strncpy(header.dbuf.uname,
-	(pwd != NULL ? pwd->pw_name : "nobody"), TUNMLEN);
-  grp = getgrgid(st->st_gid);
-  strncpy(header.dbuf.gname,
-	(grp != NULL ? grp->gr_name : "nobody"), TGNMLEN);
-  if (st->st_mode & (S_IFBLK | S_IFCHR)) {
-	string_print(header.dbuf.devmajor, "%I ", (st->st_rdev >> 8));
-	string_print(header.dbuf.devminor, "%I ", (st->st_rdev & 0xFF));
-  }
-  header.dbuf.prefix[0] = 0;
-}
-
-void is_added(st, file)
-struct stat *st;
-char *file;
-{
-  struct link *new;
-  char *name;
-
-  if ((*file == 0) || (st->st_nlink == 1)) return;
-  name = path_name(file);
-  new = (struct link *) malloc(sizeof(struct link) + strlen(name));
-  if (new == NULL) {
-	print("Out of memory\n");
-	return;
-  }
-  new->next = link_top;
-  new->dev = st->st_dev;
-  new->ino = st->st_ino;
-  new->nlink = st->st_nlink - 1;
-  strcpy(new->name, name);
-  link_top = new;
-}
-
-void is_deleted(st)
-struct stat *st;
-{
-  struct link *old;
-
-  if ((old = link_top) != NULL) {
-	link_top = old->next;
-	free(old);
-  }
-}
-
-char *is_linked(st)
-struct stat *st;
-{
-  struct link *cur = link_top;
-  struct link **pre = &link_top;
-  static char name[NAMSIZ];
-
-  while (cur != NULL)
-	if ((cur->dev != st->st_dev) || (cur->ino != st->st_ino)) {
-		pre = &cur->next;
-		cur = cur->next;
-	} else {
-		if (--cur->nlink == 0) {
-			*pre = cur->next;
-			strncpy(name, cur->name, NAMSIZ);
-			return name;
-		}
-		return cur->name;
-	}
-  return NULL;
-}
-
-void clear_header()
-{
-  register char *ptr = header.hdr_block;
-
-  while (ptr < &header.hdr_block[TBLOCK_SIZE]) *ptr++ = '\0';
-}
-
-void adjust_boundary()
-{
-  clear_header();
-  mwrite(tar_fd, (char *) &header, sizeof(header));
-#ifndef POSIX_COMP
-  while (total_blocks++ < BLOCK_BOUNDARY)
-	mwrite(tar_fd, (char *) &header, sizeof(header));
-#else
-  mwrite(tar_fd, (char *) &header, sizeof(header));
-#endif
-  (void) close(tar_fd);
-}
-
-void mread(fd, address, bytes)
-int fd, bytes;
-char *address;
-{
-  if (bread(fd, address, bytes) != bytes) error("Tar: read error.", NIL_PTR);
-}
-
-void mwrite(fd, address, bytes)
-int fd, bytes;
-char *address;
-{
-  if (bwrite(fd, address, bytes) != bytes) error("Tar: write error.", NIL_PTR);
-
-  total_blocks++;
-}
-
-int bread(fd, address, bytes)
-int fd, bytes;
-char *address;
-{
-  int n = 0, r;
-
-  while (n < bytes) {
-	if ((r = read(fd, address + n, bytes - n)) <= 0) {
-		if (r < 0) return r;
-		break;
-	}
-	n += r;
-  }
-  return n;
-}
-
-int bwrite(fd, address, bytes)
-int fd, bytes;
-char *address;
-{
-  int n = 0, r;
-
-  while (n < bytes) {
-	if ((r = write(fd, address + n, bytes - n)) <= 0) {
-		if (r < 0) return r;
-		break;
-	}
-	n += r;
-  }
-  return n;
-}
-
-char output[TBLOCK_SIZE];
-void print(str)
-register char *str;
-{
-  int fd = (tar_fd == 1 ? 2 : 1);
-  static int indx = 0;
-
-  if (str == NIL_PTR) {
-	write(fd, output, indx);
-	indx = 0;
-	return;
-  }
-  while (*str) {
-	output[indx++] = *str++;
-	if (indx == TBLOCK_SIZE) {
-		write(fd, output, TBLOCK_SIZE);
-		indx = 0;
-	}
-  }
-}
-
-char *num_out(number)
-register long number;
-{
-  static char num_buf[12];
-  register int i;
-
-  for (i = 11; i--;) {
-	num_buf[i] = (number & 07) + '0';
-	number >>= 3;
-  }
-
-  return num_buf;
-}
-
-/*VARARGS2*/
-#if __STDC__
-void string_print(char *buffer, char *fmt,...)
-#else
-void string_print(buffer, fmt)
-char *buffer;
-char *fmt;
-#endif
-{
-  va_list args;
-  register char *buf_ptr;
-  char *scan_ptr;
-  char buf[STRING_SIZE];
-  BOOL pr_fl, i;
-
-  if (pr_fl = (buffer == NIL_PTR)) buffer = buf;
-
-  va_start(args, fmt);
-  buf_ptr = buffer;
-  while (*fmt) {
-	if (*fmt == '%') {
-		fmt++;
-		switch (*fmt++) {
-		    case 's':
-			scan_ptr = (char *) (va_arg(args, char *));
-			break;
-		    case 'I':
-			scan_ptr = num_out((long) (va_arg(args, int)));
-			for (i = 0; i < 5; i++) scan_ptr++;
-			break;
-		    case 'L':
-			scan_ptr = num_out((long) va_arg(args, long));
-			break;
-		    case 'd':
-			scan_ptr = num_out((long) va_arg(args, int));
-			while (*scan_ptr == '0') scan_ptr++;
-			scan_ptr--;
-			break;
-		    default:	scan_ptr = "";
-		}
-		while (*buf_ptr++ = *scan_ptr++);
-		buf_ptr--;
-	} else
-		*buf_ptr++ = *fmt++;
-  }
-  *buf_ptr = '\0';
-
-  if (pr_fl) print(buffer);
-  va_end(args);
-}
Index: trunk/minix/commands/simple/tcpd.c
===================================================================
--- trunk/minix/commands/simple/tcpd.c	(revision 9)
+++ 	(revision )
@@ -1,311 +1,0 @@
-/*
-tcpd.c
-*/
-
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <signal.h>
-#include <minix/config.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <net/hton.h>
-#include <net/netlib.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/netdb.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-
-/* This program can be compiled to be paranoid, i.e. check incoming connection
- * according to an access file, or to trust anyone.  The much smaller "trust
- * 'em" binary will call the paranoid version if the access file exists.
- */
-
-static char *arg0, *service;
-static unsigned nchildren;
-
-static void report(const char *label)
-{
-    int err= errno;
-
-    fprintf(stderr, "%s %s: %s: %s\n", arg0, service, label, strerror(err));
-    errno= err;
-}
-
-static void sigchld(int sig)
-{
-    while (waitpid(0, NULL, WNOHANG) > 0) {
-	if (nchildren > 0) nchildren--;
-    }
-}
-
-static void release(int *fd)
-{
-    if (*fd != -1) {
-	close(*fd);
-	*fd= -1;
-    }
-}
-
-static void usage(void)
-{
-    fprintf(stderr,
-	"Usage: %s [-d] [-m maxclients] service program [arg ...]\n",
-	arg0);
-    exit(1);
-}
-
-int main(int argc, char **argv)
-{
-    tcpport_t port;
-    int last_failed = 0;
-    struct nwio_tcpcl tcplistenopt;
-    struct nwio_tcpconf tcpconf;
-    struct nwio_tcpopt tcpopt;
-    char *tcp_device;
-    struct servent *servent;
-    int tcp_fd, client_fd, count, r;
-    int pfd[2];
-    unsigned stall= 0;
-    struct sigaction sa;
-    sigset_t chldmask, chldunmask, oldmask;
-    char **progv;
-
-#if !PARANOID
-#   define debug 0
-#   define max_children ((unsigned) -1)
-    arg0= argv[0];
-
-    /* Switch to the paranoid version of me if there are flags, or if
-     * there is an access file.
-     */
-    if (argv[1][0] == '-' || access(_PATH_SERVACCES, F_OK) == 0) {
-	execv("/usr/bin/tcpdp", argv);
-	report("tcpdp");
-	exit(1);
-    }
-    if (argc < 3) usage();
-    service= argv[1];
-    progv= argv+2;
-
-#else /* PARANOID */
-    int debug, i;
-    unsigned max_children;
-
-    arg0= argv[0];
-    debug= 0;
-    max_children= -1;
-    i= 1;
-    while (i < argc && argv[i][0] == '-') {
-	char *opt= argv[i++] + 1;
-	unsigned long m;
-	char *end;
-
-	if (*opt == '-' && opt[1] == 0) break;	/* -- */
-
-	while (*opt != 0) switch (*opt++) {
-	case 'd':
-	    debug= 1;
-	    break;
-	case 'm':
-	    if (*opt == 0) {
-		if (i == argc) usage();
-		opt= argv[i++];
-	    }
-	    m= strtoul(opt, &end, 10);
-	    if (m <= 0 || m > UINT_MAX || *end != 0) usage();
-	    max_children= m;
-	    opt= "";
-	    break;
-	default:
-	    usage();
-	}
-    }
-    service= argv[i++];
-    progv= argv+i;
-    if (i >= argc) usage();
-#endif
-
-    /* The interface to start the service on. */
-    if ((tcp_device= getenv("TCP_DEVICE")) == NULL) tcp_device= TCP_DEVICE;
-
-    /* Let SIGCHLD interrupt whatever I'm doing. */
-    sigemptyset(&chldmask);
-    sigaddset(&chldmask, SIGCHLD);
-    sigprocmask(SIG_BLOCK, &chldmask, &oldmask);
-    chldunmask= oldmask;
-    sigdelset(&chldunmask, SIGCHLD);
-    sigemptyset(&sa.sa_mask);
-    sa.sa_flags = 0;
-    sa.sa_handler = sigchld;
-    sigaction(SIGCHLD, &sa, NULL);
-
-    /* Open a socket to the service I'm to serve. */
-    if ((servent= getservbyname(service, "tcp")) == NULL) {
-	unsigned long p;
-	char *end;
-
-	p= strtoul(service, &end, 0);
-	if (p <= 0 || p > 0xFFFF || *end != 0) {
-	    fprintf(stderr, "%s: %s: Unknown service\n",
-		arg0, service);
-	    exit(1);
-	}
-	port= htons((tcpport_t) p);
-    } else {
-	port= servent->s_port;
-
-	if (debug)
-	{
-	    fprintf(stderr, "%s %s: listening to port %u\n",
-		arg0, service, ntohs(port));
-	}
-    }
-
-    /* No client yet. */
-    client_fd= -1;
-
-    while (1) {
-	if ((tcp_fd= open(tcp_device, O_RDWR)) < 0) {
-	    report(tcp_device);
-#if 0
-	    if (errno == ENOENT || errno == ENODEV
-			    || errno == ENXIO) {
-		exit(1);
-	    }
-#endif
-	    last_failed = 1;
-	    goto bad;
-	}
-	if(last_failed)
-		fprintf(stderr, "%s %s: %s: Ok\n",
-			arg0, service, tcp_device);
-	last_failed = 0;
-
-	tcpconf.nwtc_flags= NWTC_LP_SET | NWTC_UNSET_RA | NWTC_UNSET_RP;
-	tcpconf.nwtc_locport= port;
-
-	if (ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf) < 0) {
-	    report("Can't configure TCP channel");
-	    exit(1);
-	}
-
-	tcpopt.nwto_flags= NWTO_DEL_RST;
-
-	if (ioctl(tcp_fd, NWIOSTCPOPT, &tcpopt) < 0) {
-	    report("Can't set TCP options");
-	    exit(1);
-	}
-
-	if (client_fd != -1) {
-	    /* We have a client, so start a server for it. */
-
-	    tcpopt.nwto_flags= 0;
-	    (void) ioctl(client_fd, NWIOSTCPOPT, &tcpopt);
-
-	    fflush(NULL);
-
-	    /* Create a pipe to serve as an error indicator. */
-	    if (pipe(pfd) < 0) {
-		report("pipe");
-		goto bad;
-	    }
-	    (void) fcntl(pfd[1], F_SETFD,
-		    fcntl(pfd[1], F_GETFD) | FD_CLOEXEC);
-
-	    /* Fork and exec. */
-	    switch (fork()) {
-	    case -1:
-		report("fork");
-		close(pfd[0]);
-		close(pfd[1]);
-		goto bad;
-	    case 0:
-		close(tcp_fd);
-		close(pfd[0]);
-#if PARANOID
-		/* Check if access to this service allowed. */
-		if (ioctl(client_fd, NWIOGTCPCONF, &tcpconf) == 0
-		    && tcpconf.nwtc_remaddr != tcpconf.nwtc_locaddr
-		    && !servxcheck(tcpconf.nwtc_remaddr, argv[1], NULL)
-		) {
-		    exit(1);
-		}
-#endif
-		sigprocmask(SIG_SETMASK, &oldmask, NULL);
-		dup2(client_fd, 0);
-		dup2(client_fd, 1);
-		close(client_fd);
-		execvp(progv[0], progv);
-		report(progv[0]);
-		write(pfd[1], &errno, sizeof(errno));
-		exit(1);
-	    default:
-		nchildren++;
-		release(&client_fd);
-		close(pfd[1]);
-		r= read(pfd[0], &errno, sizeof(errno));
-		close(pfd[0]);
-		if (r != 0) goto bad;
-		break;
-	    }
-	}
-
-	while (nchildren >= max_children) {
-	    /* Too many clients, wait for one to die off. */
-	    sigsuspend(&chldunmask);
-	}
-
-	/* Wait for a new connection. */
-	sigprocmask(SIG_UNBLOCK, &chldmask, NULL);
-
-	tcplistenopt.nwtcl_flags= 0;
-	while (ioctl(tcp_fd, NWIOTCPLISTEN, &tcplistenopt) < 0) {
-	    if (errno != EINTR) {
-		if (errno != EAGAIN || debug) {
-		    report("Unable to listen");
-		}
-		goto bad;
-	    }
-	}
-	sigprocmask(SIG_BLOCK, &chldmask, NULL);
-
-	/* We got a connection. */
-	client_fd= tcp_fd;
-	tcp_fd= -1;
-
-	if (debug && ioctl(client_fd, NWIOGTCPCONF, &tcpconf) == 0) {
-	    fprintf(stderr, "%s %s: Connection from %s:%u\n",
-		arg0, service,
-		inet_ntoa(tcpconf.nwtc_remaddr),
-		ntohs(tcpconf.nwtc_remport));
-	}
-	/* All is well, no need to stall. */
-	stall= 0;
-	continue;
-
-    bad:
-	/* All is not well, release resources. */
-	release(&tcp_fd);
-	release(&client_fd);
-
-	/* Wait a bit if this happens more than once. */
-	if (stall != 0) {
-	    if (debug) {
-		fprintf(stderr, "%s %s: stalling %u second%s\n",
-		    arg0, service,
-		    stall, stall == 1 ? "" : "s");
-	    }
-	    sleep(stall);
-	    stall <<= 1;
-	} else {
-	    stall= 1;
-	}
-    }
-}
Index: trunk/minix/commands/simple/tcpstat.c
===================================================================
--- trunk/minix/commands/simple/tcpstat.c	(revision 9)
+++ 	(revision )
@@ -1,327 +1,0 @@
-/*
-tcpstat.c
-
-Created:	June 1995 by Philip Homburg <philip@f-mnx.phicoh.com>
-*/
-
-#define _MINIX_SOURCE
-#define _POSIX_C_SOURCE 2
-
-#include <inet/inet.h>
-#undef printf
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/svrctl.h>
-#ifndef __minix_vmd
-#include <sys/times.h>
-#endif
-#include <net/netlib.h>
-#include <net/gen/inet.h>
-#include <net/gen/netdb.h>
-#include <net/gen/socket.h>
-#include <minix/queryparam.h>
-
-#include <inet/generic/buf.h>
-#include <inet/generic/clock.h>
-#include <inet/generic/event.h>
-#include <inet/generic/type.h>
-#include <inet/generic/tcp.h>
-#include <inet/generic/tcp_int.h>
-
-char *prog_name;
-tcp_conn_t tcp_conn_table[TCP_CONN_NR];
-char values[2 * sizeof(tcp_conn_table) + 1];
-int inclListen, numerical, verbose;
-
-void print_conn(int i, clock_t now);
-void usage(void);
-
-int main(int argc, char*argv[])
-{
-	char *tcp_device;
-	int fd, i;
-	struct svrqueryparam qpar;
-	char *pval;
-	struct timeval uptime;
-	clock_t now;
-	int fl;
-	int a_flag, n_flag, v_flag;
-
-	(prog_name=strrchr(argv[0], '/')) ? prog_name++ : (prog_name=argv[0]);
-
-	a_flag= 0;
-	n_flag= 0;
-	v_flag= 0;
-	while ((fl= getopt(argc, argv, "?anv")) != -1)
-	{
-		switch(fl)
-		{
-		case '?':
-			usage();
-		case 'a':
-			a_flag= 1;
-			break;
-		case 'n':
-			n_flag= 1;
-			break;
-		case 'v':
-			v_flag= 1;
-			break;
-		default:
-			fprintf(stderr, "%s: getopt failed: '%c'\n", 
-				prog_name, fl);
-			exit(1);
-		}
-	}
-	inclListen= !!a_flag;
-	numerical= !!n_flag;
-	verbose= !!v_flag;
-
-	tcp_device= TCP_DEVICE;
-	if ((fd= open(tcp_device, O_RDWR)) == -1)
-	{
-		fprintf(stderr, "%s: unable to open '%s': %s\n", prog_name,
-			tcp_device, strerror(errno));
-		exit(1);
-	}
-
-	qpar.param = "tcp_conn_table";
-	qpar.psize = strlen(qpar.param);
-	qpar.value = values;
-	qpar.vsize = sizeof(values);
-	if (ioctl(fd, NWIOQUERYPARAM, &qpar) == -1)
-	{
-		fprintf(stderr, "%s: queryparam failed: %s\n", prog_name,
-			strerror(errno));
-		exit(1);
-	}
-	pval= values;
-	if (paramvalue(&pval, tcp_conn_table, sizeof(tcp_conn_table)) !=
-		sizeof(tcp_conn_table))
-	{
-		fprintf(stderr,
-			"%s: unable to decode the results from queryparam\n",
-			prog_name);
-		exit(1);
-	}
-
-#ifdef __minix_vmd
-	/* Get the uptime in clock ticks. */
-	if (sysutime(UTIME_UPTIME, &uptime) == -1)
-	{
-		fprintf(stderr, "%s: sysutime failed: %s\n", prog_name,
-			strerror(errno));
-		exit(1);
-	}
-	now= uptime.tv_sec * HZ + (uptime.tv_usec*HZ/1000000);
-#else	/* Minix 3 */
-	now= times(NULL);
-#endif
-
-	for (i= 0; i<TCP_CONN_NR; i++)
-		print_conn(i, now);
-	exit(0);
-}
-
-void print_conn(int i, clock_t now)
-{
-	tcp_conn_t *tcp_conn;
-	char *addr_str;
-	struct hostent *hostent;
-	struct servent *servent;
-	ipaddr_t a1, a2;
-	tcpport_t p1, p2;
-	unsigned flags;
-	int no_verbose;
-	clock_t rtt, artt, drtt;
-
-	tcp_conn= &tcp_conn_table[i];
-	if (!(tcp_conn->tc_flags & TCF_INUSE))
-		return;
-	if (tcp_conn->tc_state == TCS_LISTEN && !inclListen)
-		return;
-	if (tcp_conn->tc_state == TCS_CLOSED && tcp_conn->tc_fd == NULL &&
-		tcp_conn->tc_senddis < now)
-	{
-		return;
-	}
-	
-	printf("%3d", i);
-
-	a1= tcp_conn->tc_locaddr;
-	p1= tcp_conn->tc_locport;
-	a2= tcp_conn->tc_remaddr;
-	p2= tcp_conn->tc_remport;
-
-	if (a1 == 0)
-		addr_str= "*";
-	else if (!numerical &&
-		(hostent= gethostbyaddr((char *)&a1,
-		sizeof(a1), AF_INET)) != NULL)
-	{
-		addr_str= hostent->h_name;
-	}
-	else
-		addr_str= inet_ntoa(a1);
-	printf(" %s:", addr_str);
-
-	if (p1 == 0)
-		printf("*");
-	else if ((servent= getservbyport(p1, "tcp")) != NULL)
-	{
-		printf("%s", servent->s_name);
-	}
-	else
-		printf("%u", ntohs(p1));
-
-	if (tcp_conn->tc_orglisten)
-		printf(" <- ");
-	else
-		printf(" -> ");
-
-	if (a2 == 0)
-		addr_str= "*";
-	else if (!numerical &&
-		(hostent= gethostbyaddr((char *)&a2,
-		sizeof(a2), AF_INET)) != NULL)
-	{
-		addr_str= hostent->h_name;
-	}
-	else
-		addr_str= inet_ntoa(a2);
-	printf("%s:", addr_str);
-
-	if (p2 == 0)
-		printf("*");
-	else if ((servent= getservbyport(p2, "tcp")) !=
-		NULL)
-	{
-		printf("%s", servent->s_name);
-	}
-	else
-		printf("%u", ntohs(p2));
-
-	printf(" ");
-	no_verbose= 0;
-	switch(tcp_conn->tc_state)
-	{
-	case TCS_CLOSED:	printf("CLOSED");
-				if (tcp_conn->tc_senddis >= now)
-				{
-					printf("(time wait %ld s)",
-						(tcp_conn->tc_senddis-now)/HZ);
-				}
-				no_verbose= 1;
-				break;
-	case TCS_LISTEN:	printf("LISTEN"); no_verbose= 1; break;
-	case TCS_SYN_RECEIVED:	printf("SYN_RECEIVED"); break;
-	case TCS_SYN_SENT:	printf("SYN_SENT"); break;
-	case TCS_ESTABLISHED:	printf("ESTABLISHED"); break;
-	case TCS_CLOSING:	printf("CLOSING"); break;
-	default:		printf("state(%d)", tcp_conn->tc_state);
-				break;
-	}
-
-	if (tcp_conn->tc_flags & TCF_FIN_RECV)
-		printf(" F<");
-	if (tcp_conn->tc_flags & TCF_FIN_SENT)
-	{
-		printf(" F>");
-		if (tcp_conn->tc_SND_UNA == tcp_conn->tc_SND_NXT)
-			printf("+");
-	}
-	if (tcp_conn->tc_state != TCS_CLOSED &&
-		tcp_conn->tc_state != TCS_LISTEN)
-	{
-		printf("\n\t");
-		printf("RQ: %lu, SQ: %lu, RWnd: %u, SWnd: %lu, SWThresh: %lu",
-			tcp_conn->tc_RCV_NXT - tcp_conn->tc_RCV_LO,
-			tcp_conn->tc_SND_NXT - tcp_conn->tc_SND_UNA,
-			tcp_conn->tc_rcv_wnd,
-			tcp_conn->tc_snd_cwnd - tcp_conn->tc_SND_UNA,
-			tcp_conn->tc_snd_cthresh);
-	}
-
-	printf("\n");
-
-	if (!verbose || no_verbose)
-		return;
-	rtt= tcp_conn->tc_rtt;
-	artt= tcp_conn->tc_artt;
-	drtt= tcp_conn->tc_drtt;
-	printf("\tmss %u, mtu %u%s, rtt %.3f (%.3f+%d*%.3f) s\n",
-		tcp_conn->tc_max_mtu-IP_TCP_MIN_HDR_SIZE,
-		tcp_conn->tc_mtu,
-		(tcp_conn->tc_flags & TCF_PMTU) ? "" : " (no PMTU)",
-		rtt/(HZ+0.0),
-		artt/(HZ+0.0)/TCP_RTT_SCALE, TCP_DRTT_MULT,
-		drtt/(HZ+0.0)/TCP_RTT_SCALE);
-	flags= tcp_conn->tc_flags;
-	printf("\tflags:");
-	if (!flags)
-		printf(" TCF_EMPTY");
-	if (flags & TCF_INUSE)
-		flags &= ~TCF_INUSE;
-	if (flags & TCF_FIN_RECV)
-	{
-		printf(" TCF_FIN_RECV");
-		flags &= ~TCF_FIN_RECV;
-	}
-	if (flags & TCF_RCV_PUSH)
-	{
-		printf(" TCF_RCV_PUSH");
-		flags &= ~TCF_RCV_PUSH;
-	}
-	if (flags & TCF_MORE2WRITE)
-	{
-		printf(" TCF_MORE2WRITE");
-		flags &= ~TCF_MORE2WRITE;
-	}
-	if (flags & TCF_SEND_ACK)
-	{
-		printf(" TCF_SEND_ACK");
-		flags &= ~TCF_SEND_ACK;
-	}
-	if (flags & TCF_FIN_SENT)
-	{
-		printf(" TCF_FIN_SENT");
-		flags &= ~TCF_FIN_SENT;
-	}
-	if (flags & TCF_BSD_URG)
-	{
-		printf(" TCF_BSD_URG");
-		flags &= ~TCF_BSD_URG;
-	}
-	if (flags & TCF_NO_PUSH)
-	{
-		printf(" TCF_NO_PUSH");
-		flags &= ~TCF_NO_PUSH;
-	}
-	if (flags & TCF_PUSH_NOW)
-	{
-		printf(" TCF_PUSH_NOW");
-		flags &= ~TCF_PUSH_NOW;
-	}
-	if (flags & TCF_PMTU)
-		flags &= ~TCF_PMTU;
-	if (flags)
-		printf(" 0x%x", flags);
-	printf("\n");
-	printf("\ttimer: ref %d, time %f, active %d\n",
-		tcp_conn->tc_transmit_timer.tim_ref,
-		(0.0+tcp_conn->tc_transmit_timer.tim_time-now)/HZ,
-		tcp_conn->tc_transmit_timer.tim_active);
-}
-
-void usage(void)
-{
-	fprintf(stderr, "Usage: %s [-anv]\n", prog_name);
-	exit(1);
-}
-
-/*
- * $PchId: tcpstat.c,v 1.8 2005/01/30 01:04:38 philip Exp $
- */
Index: trunk/minix/commands/simple/tee.c
===================================================================
--- trunk/minix/commands/simple/tee.c	(revision 9)
+++ 	(revision )
@@ -1,66 +1,0 @@
-/* tee - pipe fitting			Author: Paul Polderman */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <minix/minlib.h>
-
-#define	MAXFD	18
-#define CHUNK_SIZE	4096
-
-int fd[MAXFD];
-
-_PROTOTYPE(int main, (int argc, char **argv));
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  char iflag = 0, aflag = 0;
-  char buf[CHUNK_SIZE];
-  int i, s, n;
-
-  argv++;
-  --argc;
-  while (argc > 0 && argv[0][0] == '-') {
-	switch (argv[0][1]) {
-	    case 'i':		/* Interrupt turned off. */
-		iflag++;
-		break;
-	    case 'a':		/* Append to outputfile(s), instead of
-			 * overwriting them. */
-		aflag++;
-		break;
-	    default:
-		std_err("Usage: tee [-i] [-a] [files].\n");
-		exit(1);
-	}
-	argv++;
-	--argc;
-  }
-  fd[0] = 1;			/* Always output to stdout. */
-  for (s = 1; s < MAXFD && argc > 0; --argc, argv++, s++) {
-	if (aflag && (fd[s] = open(*argv, O_RDWR)) >= 0) {
-		lseek(fd[s], 0L, SEEK_END);
-		continue;
-	} else {
-		if ((fd[s] = creat(*argv, 0666)) >= 0) continue;
-	}
-	std_err("Cannot open output file: ");
-	std_err(*argv);
-	std_err("\n");
-	exit(2);
-  }
-
-  if (iflag) signal(SIGINT, SIG_IGN);
-
-  while ((n = read(0, buf, CHUNK_SIZE)) > 0) {
-	for (i = 0; i < s; i++) write(fd[i], buf, n);
-  }
-
-  for (i = 0; i < s; i++)	/* Close all fd's */
-	close(fd[i]);
-  return(0);
-}
Index: trunk/minix/commands/simple/term.c
===================================================================
--- trunk/minix/commands/simple/term.c	(revision 9)
+++ 	(revision )
@@ -1,539 +1,0 @@
-/* term - terminal simulator		Author: Andy Tanenbaum */
-
-/* This program allows the user to turn a MINIX system into a dumb
- * terminal to communicate with a remote computer through one of the ttys.
- * It forks into two processes.  The parent sits in a tight loop copying
- * from stdin to the tty.  The child sits in a tight loop copying from
- * the tty to stdout.
- *
- * 2 Sept 88 BDE (Bruce D. Evans): Massive changes to make current settings the
- * default, allow any file as the "tty", support fancy baud rates and remove
- * references to and dependencies on modems and keyboards, so (e.g.)
- * a local login on /dev/tty1 can do an external login on /dev/tty2.
- *
- * 3 Sept 88 BDE: Split parent again to main process copies from stdin to a
- * pipe which is copied to the tty.  This stops a blocked write to the
- * tty from hanging the program.
- *
- * 11 Oct 88 BDE: Cleaned up baud rates and parity stripping.
- *
- * 09 Oct 90 MAT (Michael A. Temari): Fixed bug where terminal isn't reset
- * if an error occurs.
- *
- * Nov 90 BDE: Don't broadcast kill(0, SIGINT) since two or more of these
- * in a row will kill the parent shell.
- *
- * 19 Oct 89 RW (Ralf Wenk): Adapted to MINIX ST 1.1 + RS232 driver. Split
- * error into error_n and error. Added resetting of the terminal settings
- * in error.
- *
- * 24 Nov 90 RW: Adapted to MINIX ST 1.5.10.2. Forked processes are now
- * doing an exec to get a better performance. This idea is stolen from
- * a terminal program written by Felix Croes.
- *
- * 01 May 91 RW: Merged the MINIX ST patches with Andys current version.
- * Most of the 19 Oct 89 patches are deleted because they are already there.
- *
- * 10 Mar 96 KJB: Termios adaption, cleanup, command key interface.
- *
- * 27 Nov 96 KJB: Add -c flag that binds commands to keys.
- *
- * Example usage:
- *	term			: baud, bits/char, parity from /dev/tty1
- *	term 9600 7 even	: 9600 baud, 7 bits/char, even parity
- *	term odd 300 7		:  300 baud, 7 bits/char, odd parity
- *	term /dev/tty2		: use /dev/tty2 rather than /dev/tty1
- *				: Any argument starting with "/" is
- *				: taken as the communication device.
- *	term 8 57600 /dev/tty2 -atdt4441234	: if an argument begins with
- *						: - , the rest of that arg is
- *						: sent to the modem as a
- *						: dial string
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <termios.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-
-#define CHUNK 1024		/* how much to read at once */
-
-char TERM_LINE[] = "/dev/modem";/* default serial port to use */
-
-				/* device lock file */
-char lockfile[] = "/usr/spool/locks/LK.iii.jjj.kkk";
-
-char *commdev;			/* communications device a.k.a. "modem". */
-int commfd;			/* open file no. for comm device */
-struct termios tccomm;		/* terminal parameters for commfd */
-struct termios tcstdin;		/* terminal parameters for stdin */
-struct termios tcsavestdin;	/* saved terminal parameters for stdin */
-
-/* Special key to get term's attention. */
-#define HOTKEY	'\035'		/* CTRL-] */
-
-struct param_s {
-  char *pattern;
-  unsigned value;
-  enum { BAD, BITS, PARITY, SPEED } type;
-} params[] = {
-  { "5",	CS5,		BITS	},
-  { "6",	CS6,		BITS	},
-  { "7",	CS7,		BITS	},
-  { "8",	CS8,		BITS	},
-
-  { "even",	PARENB,		PARITY	},
-  { "odd",	PARENB|PARODD,	PARITY	},
-
-  { "50",	B50,		SPEED	},
-  { "75",	B75,		SPEED	},
-  { "110",	B110,		SPEED	},
-  { "134",	B134,		SPEED	},
-  { "200",	B200,		SPEED	},
-  { "300",	B300,		SPEED	},
-  { "600",	B600,		SPEED	},
-  { "1200",	B1200,		SPEED	},
-  { "1800",	B1800,		SPEED	},
-  { "2400",	B2400,		SPEED	},
-  { "4800",	B4800,		SPEED	},
-  { "9600",	B9600,		SPEED	},
-  { "19200",	B19200,		SPEED	},
-  { "38400",	B38400,		SPEED	},
-  { "57600",	B57600,		SPEED	},
-  { "115200",	B115200,	SPEED	},
-  { "",		0,		BAD	},	/* BAD type to end list */
-};
-
-#define NIL ((char *) NULL)		/* tell(fd, ..., NIL) */
-
-_PROTOTYPE(int main, (int argc, char *argv[]));
-_PROTOTYPE(int isdialstr, (char *arg));
-_PROTOTYPE(void tell, (int fd, ...));
-_PROTOTYPE(void reader, (int on));
-_PROTOTYPE(void shell, (char *cmd));
-_PROTOTYPE(void lock_device, (char *device));
-_PROTOTYPE(void fatal, (char *label));
-_PROTOTYPE(void setnum, (char *s, int n));
-_PROTOTYPE(void set_uart, (int argc, char *argv[], struct termios *tcp));
-_PROTOTYPE(void set_raw, (struct termios *tcp));
-_PROTOTYPE(void quit, (int code));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int i;
-  unsigned char key;
-  int candial;
-
-  for (i = 1; i < argc; ++i) {
-	if (argv[i][0] == '/') {
-		if (commdev != NULL) {
-			tell(2, "term: too many communication devices\n", NIL);
-			exit(1);
-		}
-		commdev = argv[i];
-	}
-  }
-  if (commdev == NULL) commdev = TERM_LINE;
-
-  /* Save tty attributes of the terminal. */
-  if (tcgetattr(0, &tcsavestdin) < 0) {
-	tell(2, "term: standard input is not a terminal\n", NIL);
-	exit(1);
-  }
-
-  lock_device(commdev);
-
-  commfd = open(commdev, O_RDWR);
-  if (commfd < 0) {
-	tell(2, "term: can't open ", commdev, ": ", strerror(errno), "\n", NIL);
-	quit(1);
-  }
-
-  /* Compute RAW modes of terminal and modem. */
-  if (tcgetattr(commfd, &tccomm) < 0) {
-	tell(2, "term: ", commdev, " is not a terminal\n", NIL);
-	quit(1);
-  }
-  signal(SIGINT, quit);
-  signal(SIGTERM, quit);
-  tcstdin = tcsavestdin;
-  set_raw(&tcstdin);
-  set_raw(&tccomm);
-  set_uart(argc, argv, &tccomm);
-  tcsetattr(0, TCSANOW, &tcstdin);
-  tcsetattr(commfd, TCSANOW, &tccomm);
-
-  /* Start a reader process to copy modem output to the screen. */
-  reader(1);
-
-  /* Welcome message. */
-  tell(1, "Connected to ", commdev,
-			", command key is CTRL-], type ^]? for help\r\n", NIL);
-
-  /* Dial. */
-  candial = 0;
-  for (i = 1; i < argc; ++i) {
-	if (!isdialstr(argv[i])) continue;
-	tell(commfd, argv[i] + 1, "\r", NIL);
-	candial = 1;
-  }
-
-  /* Main loop of the terminal simulator. */
-  while (read(0, &key, 1) == 1) {
-	if (key == HOTKEY) {
-		/* Command key typed. */
-		if (read(0, &key, 1) != 1) continue;
-
-		switch (key) {
-		default:
-			/* Added command? */
-			for (i = 1; i < argc; ++i) {
-				char *arg = argv[i];
-
-				if (arg[0] == '-' && arg[1] == 'c'
-							&& arg[2] == key) {
-					reader(0);
-					tcsetattr(0, TCSANOW, &tcsavestdin);
-					shell(arg+3);
-					tcsetattr(0, TCSANOW, &tcstdin);
-					reader(1);
-					break;
-				}
-			}
-			if (i < argc) break;
-
-			/* Unrecognized command, print list. */
-			tell(1, "\r\nTerm commands:\r\n",
-				" ? - this help\r\n",
-				candial ? " d - redial\r\n" : "",
-				" s - subshell (e.g. for file transfer)\r\n",
-				" h - hangup (+++ ATH)\r\n",
-				" b - send a break\r\n",
-				" q - exit term\r\n",
-				NIL);
-			for (i = 1; i < argc; ++i) {
-				char *arg = argv[i];
-				static char cmd[] = " x - ";
-
-				if (arg[0] == '-' && arg[1] == 'c'
-							&& arg[2] != 0) {
-					cmd[1] = arg[2];
-					tell(1, cmd, arg+3, "\r\n", NIL);
-				}
-			}
-			tell(1, "^] - send a CTRL-]\r\n\n",
-				NIL);
-			break;
-		case 'd':
-			/* Redial by sending the dial commands again. */
-			for (i = 1; i < argc; ++i) {
-				if (!isdialstr(argv[i])) continue;
-				tell(commfd, argv[i] + 1, "\r", NIL);
-			}
-			break;
-		case 's':
-			/* Subshell. */
-			reader(0);
-			tcsetattr(0, TCSANOW, &tcsavestdin);
-			shell(NULL);
-			tcsetattr(0, TCSANOW, &tcstdin);
-			reader(1);
-			break;
-		case 'h':
-			/* Hangup by using the +++ escape and ATH command. */
-			sleep(2);
-			tell(commfd, "+++", NIL);
-			sleep(2);
-			tell(commfd, "ATH\r", NIL);
-			break;
-		case 'b':
-			/* Send a break. */
-			tcsendbreak(commfd, 0);
-			break;
-		case 'q':
-			/* Exit term. */
-			quit(0);
-		case HOTKEY:
-			(void) write(commfd, &key, 1);
-			break;
-		}
-	} else {
-		/* Send keyboard input down the serial line. */
-		if (write(commfd, &key, 1) != 1) break;
-	}
-  }
-  tell(2, "term: nothing to copy from input to ", commdev, "?\r\n", NIL);
-  quit(1);
-}
-
-
-int isdialstr(char *arg)
-{
-/* True iff arg is the start of a dial string, i.e. "-at...". */
-
-  return (arg[0] == '-'
-  	&& (arg[1] == 'a' || arg[1] == 'A')
-  	&& (arg[2] == 't' || arg[2] == 'T'));
-}
-
-
-void tell(int fd, ...)
-{
-/* Write strings to file descriptor 'fd'. */
-  va_list ap;
-  char *s;
-
-  va_start(ap, fd);
-  while ((s = va_arg(ap, char *)) != NIL) write(fd, s, strlen(s));
-  va_end(ap);
-}
-
-
-void reader(on)
-int on;
-{
-/* Start or end a process that copies from the modem to the screen. */
-
-  static pid_t pid;
-  char buf[CHUNK];
-  ssize_t n, m, r;
-
-  if (!on) {
-	/* End the reader process (if any). */
-	if (pid == 0) return;
-	kill(pid, SIGKILL);
-	(void) waitpid(pid, (int *) NULL, 0);
-	pid = 0;
-	return;
-  }
-
-  /* Start a reader */
-  pid = fork();
-  if (pid < 0) {
-	tell(2, "term: fork() failed: ", strerror(errno), "\r\n", NIL);
-	quit(1);
-  }
-  if (pid == 0) {
-	/* Child: Copy from the modem to the screen. */
-
-	while ((n = read(commfd, buf, sizeof(buf))) > 0) {
-		m = 0;
-		while (m < n && (r = write(1, buf + m, n - m)) > 0) m += r;
-	}
-	tell(2, "term: nothing to copy from ", commdev, " to output?\r\n", NIL);
-	kill(getppid(), SIGTERM);
-	_exit(1);
-  }
-  /* One reader on the loose. */
-}
-
-
-void shell(char *cmd)
-{
-/* Invoke a subshell to allow one to run zmodem for instance.  Run sh -c 'cmd'
- * instead if 'cmd' non-null.
- */
-
-  pid_t pid;
-  char *shell, *sh0;
-  _PROTOTYPE(void (*isav), (int));
-  _PROTOTYPE(void (*qsav), (int));
-  _PROTOTYPE(void (*tsav), (int));
-
-  if (cmd == NULL) {
-	tell(1, "\nExit the shell to return to term, ",
-		commdev, " is open on file descriptor 9.\n", NIL);
-  }
-
-  if (cmd != NULL || (shell = getenv("SHELL")) == NULL) shell = "/bin/sh";
-  if ((sh0 = strrchr(shell, '/')) == NULL) sh0 = shell; else sh0++;
-
-  /* Start a shell */
-  pid = fork();
-  if (pid < 0) {
-	tell(2, "term: fork() failed: ", strerror(errno), "\n", NIL);
-	return;
-  }
-  if (pid == 0) {
-	/* Child: Exec the shell. */
-	setgid(getgid());
-	setuid(getuid());
-
-	if (commfd != 9) { dup2(commfd, 9); close(commfd); }
-
-	if (cmd == NULL) {
-		execl(shell, sh0, (char *) NULL);
-	} else {
-		execl(shell, sh0, "-c", cmd, (char *) NULL);
-	}
-	tell(2, "term: can't execute ", shell, ": ", strerror(errno), "\n",NIL);
-	_exit(1);
-  }
-  /* Wait for the shell to exit. */
-  isav = signal(SIGINT, SIG_IGN);
-  qsav = signal(SIGQUIT, SIG_IGN);
-  tsav = signal(SIGTERM, SIG_IGN);
-  (void) waitpid(pid, (int *) 0, 0);
-  (void) signal(SIGINT, isav);
-  (void) signal(SIGQUIT, qsav);
-  (void) signal(SIGTERM, tsav);
-  tell(1, "\n[back to term]\n", NIL);
-}
-
-
-void lock_device(device)
-char *device;
-{
-/* Lock a device by creating a lock file using SYSV style locking. */
-
-  struct stat stbuf;
-  unsigned int pid;
-  int fd;
-  int n;
-  int u;
-
-  if (stat(device, &stbuf) < 0) fatal(device);
-
-  if (!S_ISCHR(stbuf.st_mode)) {
-	tell(2, "term: ", device, " is not a character device\n", NIL);
-	exit(1);
-  }
-
-  /* Compute the lock file name. */
-  setnum(lockfile + 23, (stbuf.st_dev >> 8) & 0xFF);	/* FS major (why?) */
-  setnum(lockfile + 27, (stbuf.st_rdev >> 8) & 0xFF);	/* device major */
-  setnum(lockfile + 31, (stbuf.st_rdev >> 0) & 0xFF);	/* device minor */
-
-  /* Try to make a lock file and put my pid in it. */
-  u = umask(0);
-  for (;;) {
-	if ((fd = open(lockfile, O_RDONLY)) < 0) {
-		/* No lock file, try to lock it myself. */
-		if (errno != ENOENT) fatal(device);
-		if ((fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL, 0444)) < 0) {
-			if (errno == EEXIST) continue;
-			fatal(lockfile);
-		}
-		pid = getpid();
-		n = write(fd, &pid, sizeof(pid));
-		if (n < 0) {
-			n = errno;
-			(void) unlink(lockfile);
-			errno = n;
-			fatal(lockfile);
-		}
-		close(fd);
-		break;
-	} else {
-		/* Already there, but who owns it? */
-		n = read(fd, &pid, sizeof(pid));
-		if (n < 0) fatal(device);
-		close(fd);
-		if (n == sizeof(pid) && !(kill(pid, 0) < 0 && errno == ESRCH)) {
-			/* It is locked by a running process. */
-			tell(2, "term: ", device,
-				" is in use by another program\n", NIL);
-			if (getpgrp() == getpid()) sleep(3);
-			exit(1);
-		}
-		/* Stale lock. */
-		tell(1, "Removing stale lock ", lockfile, "\n", NIL);
-		if (unlink(lockfile) < 0 && errno != ENOENT) fatal(lockfile);
-	}
-  }
-  /* Lock achieved, but what if two terms encounters a stale lock at the same
-   * time?
-   */
-  umask(u);
-}
-
-
-void fatal(char *label)
-{
-  tell(2, "term: ", label, ": ", strerror(errno), "\n", NIL);
-  exit(1);
-}
-
-
-void setnum(char *s, int n)
-{
-/* Poke 'n' into string 's' backwards as three decimal digits. */
-  int i;
-
-  for (i = 0; i < 3; i++) { *--s = '0' + (n % 10); n /= 10; }
-}
-
-
-void set_uart(argc, argv, tcp)
-int argc;
-char *argv[];
-struct termios *tcp;
-{
-/* Set up the UART parameters. */
-
-  int i;
-  char *arg;
-  struct param_s *param;
-
-  /* Examine all the parameters and check for validity. */
-  for (i = 1; i < argc; ++i) {
-	arg = argv[i];
-	if (arg[0] == '/' || arg[0] == '-') continue;
-
-	/* Check parameter for legality. */
-	for (param = &params[0];
-	     param->type != BAD && strcmp(arg, param->pattern) != 0;
-	     ++param);
-	switch (param->type) {
-	    case BAD:
-		tell(2, "Invalid parameter: ", arg, "\n", NIL);
-		quit(1);
-		break;
-	    case BITS:
-		tcp->c_cflag &= ~CSIZE;
-		tcp->c_cflag |= param->value;
-		break;
-	    case PARITY:
-		tcp->c_cflag &= PARENB | PARODD;
-		tcp->c_cflag |= param->value;
-		break;
-	    case SPEED:
-		cfsetispeed(tcp, (speed_t) param->value);
-		cfsetospeed(tcp, (speed_t) param->value);
-		break;
-	}
-  }
-}
-
-
-void set_raw(tcp)
-struct termios *tcp;
-{
-  /* Set termios attributes for RAW mode. */
-
-  tcp->c_iflag &= ~(ICRNL|IGNCR|INLCR|IXON|IXOFF);
-  tcp->c_lflag &= ~(ICANON|IEXTEN|ISIG|ECHO|ECHONL);
-  tcp->c_oflag &= ~(OPOST);
-  tcp->c_cc[VMIN] = 1;
-  tcp->c_cc[VTIME] = 0;
-}
-
-
-void quit(code)
-int code;
-{
-/* Stop the reader process, reset the terminal, and exit. */
-  reader(0);
-  tcsetattr(0, TCSANOW, &tcsavestdin);
-  (void) unlink(lockfile);
-  exit(code);
-}
Index: trunk/minix/commands/simple/termcap.c
===================================================================
--- trunk/minix/commands/simple/termcap.c	(revision 9)
+++ 	(revision )
@@ -1,163 +1,0 @@
-/* termcap - print termcap settings	Author: Terrence Holm */
-
-#include <stdlib.h>
-#include <termcap.h>
-#include <stdio.h>
-
-#define  TC_BUFFER  1024	/* Size of termcap(3) buffer	*/
-
-/****************************************************************/
-/*								*/
-/*    termcap  [ type ]						*/
-/*								*/
-/*    Prints out all of the termcap capabilities as described	*/
-/*    in termcap(4). If "type" is not supplied then $TERM is	*/
-/*    used.							*/
-/*								*/
-/****************************************************************/
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void Print, (char *comment, char *name));
-_PROTOTYPE(void Error, (char *message, char *arg));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-
-  {
-  char *term;
-  char  buffer[ TC_BUFFER ];
-
-
-  /*  Check for an argument  */
-
-  if ( argc > 2 )
-    Error( "Usage:  %s  [ type ]\n", argv[0] );
-
-  if ( argc == 2 )
-    term = argv[1];
-  else
-    term = getenv( "TERM" );
-
-  if ( term == NULL )
-    Error( "termcap:  $TERM is not defined\n", "" );
-
-
-  /*  Read in the termcap entry  */
-
-  if ( tgetent( buffer, term ) != 1 )
-    Error( "termcap:  No termcap entry for %s\n", term );
-
-
-  /*  Print out the entry's contents  */
-
-  printf( "TERM = %s\n\n", term );
-
-  if ( tgetflag( "am" ) == 1 )
-    printf( "End of line wraps to next line   (am)\n" );
-
-  if ( tgetflag( "bs" ) == 1 )
-    printf( "Ctrl/H performs a backspace      (bs)\n" );
-
-  printf( "Number of columns                (co) = %d\n", tgetnum( "co" ) );
-  printf( "Number of lines                  (li) = %d\n", tgetnum( "li" ) );
-
-  Print( "Clear to end of line", 	  "ce" );
-  Print( "Clear to end of screen", 	  "cd" );
-  Print( "Clear the whole screen",	  "cl" );
-
-  Print( "Start \"stand out\" mode",	  "so" );
-  Print( "End \"stand out\" mode",	  "se" );
-  Print( "Start underscore mode",	  "us" );
-  Print( "End underscore mode",		  "ue" );
-  Print( "Start blinking mode",		  "mb" );
-  Print( "Start bold mode",		  "md" );
-  Print( "Start reverse mode",		  "mr" );
-  Print( "Return to normal mode",	  "me" );
-
-  Print( "Scroll backwards",		  "sr" );
-  Print( "Cursor motion",		  "cm" );
-
-  Print( "Up one line",			  "up" );
-  Print( "Down one line",		  "do" );
-  Print( "Left one space",		  "le" );
-  Print( "Right one space",		  "nd" );
-  Print( "Move to top left corner",	  "ho" );
-
-  Print( "Generated by \"UP\"",		  "ku" );
-  Print( "Generated by \"DOWN\"",	  "kd" );
-  Print( "Generated by \"LEFT\"",	  "kl" );
-  Print( "Generated by \"RIGHT\"",	  "kr" );
-  Print( "Generated by \"HOME\"",	  "kh" );
-  Print( "Generated by \"END\"",	  "k0" );
-  Print( "Generated by \"PGUP\"",	  "k1" );
-  Print( "Generated by \"PGDN\"",	  "k2" );
-  Print( "Generated by numeric \"+\"",	  "k3" );
-  Print( "Generated by numeric \"-\"",	  "k4" );
-  Print( "Generated by numeric \"5\"",	  "k5" );
-
-  return( 0 );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*    	Print( comment, name )					*/
-/*								*/
-/*    		If a termcap entry exists for "name", then	*/
-/*		print out "comment" and the entry. Control	*/
-/*		characters are printed as ^x.			*/
-/*								*/
-/****************************************************************/
-
-
-void Print( comment, name )
-  char *comment;
-  char *name;
-
-  {
-  char  entry[ 50 ];
-  char *p = entry;
-
-  if ( tgetstr( name, &p ) == NULL )
-    return;
-    
-  printf( "%-32s (%s) = ", comment, name );
-
-  for ( p = entry;  *p != '\0';  ++p )
-    if ( *p < ' ' )
-      printf( "^%c", *p + '@' );
-    else if ( *p == '\177' )
-      printf( "^?" );
-    else
-      putchar( *p );
-
-  putchar( '\n' );
-  }
-
-
-
-
-
-
-/****************************************************************/
-/*								*/
-/*    	Error( message, arg )					*/
-/*								*/
-/*    		Printf the "message" and abort.			*/
-/*								*/
-/****************************************************************/
-
-
-void Error( message, arg )
-  char *message;
-  char *arg;
-
-  {
-  fprintf( stderr, message, arg );
-  exit( 1 );
-  }
Index: trunk/minix/commands/simple/tget.c
===================================================================
--- trunk/minix/commands/simple/tget.c	(revision 9)
+++ 	(revision )
@@ -1,98 +1,0 @@
-/*	tget 1.0 - get termcap values			Author: Kees J. Bot
- *								6 Mar 1994
- */
-#define nil 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termcap.h>
-
-void fputchar(int c)
-{
-	putchar(c);
-}
-
-void usage(void)
-{
-	fprintf(stderr,
-"Usage: tget [-flag id] [-num id] [-str id] [-goto col line] [[-echo] string]\n"
-		);
-	exit(-1);
-}
-
-void main(int argc, char **argv)
-{
-	char termbuf[1024];
-	char string[256], *pstr;
-	char *term;
-	int i;
-	int excode= 0;
-
-	if ((term= getenv("TERM")) == nil) {
-		fprintf(stderr, "tget: $TERM is not set\n");
-		exit(-1);
-	}
-
-	if (tgetent(termbuf, term) != 1) {
-		fprintf(stderr, "tget: no termcap entry for '%s'\n", term);
-		exit(-1);
-	}
-
-	for (i= 1; i < argc; i++) {
-		char *option= argv[i];
-		char *id;
-
-		if (option[0] != '-') {
-			fputs(option, stdout);
-			continue;
-		}
-
-		if (++i == argc) usage();
-		id= argv[i];
-
-		if (strcmp(option, "-flag") == 0) {
-			excode= tgetflag(id) ? 0 : 1;
-		} else
-		if (strcmp(option, "-num") == 0) {
-			int num;
-
-			if ((num= tgetnum(id)) == -1) {
-				excode= 1;
-			} else {
-				excode= 0;
-				printf("%d", num);
-			}
-		} else
-		if (strcmp(option, "-str") == 0) {
-			char *str;
-
-			if ((str= tgetstr(id, (pstr= string, &pstr))) == nil) {
-				excode= 1;
-			} else {
-				excode= 0;
-				tputs(str, 0, fputchar);
-			}
-		} else
-		if (strcmp(option, "-goto") == 0) {
-			char *cm;
-			int col, line;
-
-			col= atoi(id);
-			if (++i == argc) usage();
-			line= atoi(argv[i]);
-
-			if ((cm= tgetstr("cm", (pstr= string, &pstr))) == nil) {
-				excode= 1;
-			} else {
-				excode= 0;
-				tputs(tgoto(cm, col, line), 0, fputchar);
-			}
-		} else
-		if (strcmp(option, "-echo") == 0) {
-			fputs(id, stdout);
-		} else {
-			usage();
-		}
-	}
-	exit(excode);
-}
Index: trunk/minix/commands/simple/time.c
===================================================================
--- trunk/minix/commands/simple/time.c	(revision 9)
+++ 	(revision )
@@ -1,161 +1,0 @@
-/* time - time a command	Authors: Andy Tanenbaum & Michiel Huisjes */
-
-#define NEW	1
-
-#include <sys/types.h>
-#include <sys/times.h>
-#include <limits.h>
-#include <time.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <minix/minlib.h>
-#include <stdio.h>
-
-/* -DNEW prints time to 0.01 sec. */
-#ifdef NEW		
-#define HUNDREDTHS 1
-#endif
-
-char **args;
-char *name;
-
-int digit_seen;
-char a[] = "        . \0";
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void print_time, (clock_t t));
-_PROTOTYPE(void twin, (int n, char *p));
-_PROTOTYPE(void execute, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-
-  struct tms pre_buf, post_buf;
-  int status, pid;
-#if _VMD_EXT
-  struct timeval start_time, end_time;
-#else
-  struct tms dummy;
-  int start_time, end_time;
-#endif
-  clock_t real_time;
-
-  if (argc == 1) exit(0);
-
-  args = &argv[1];
-  name = argv[1];
-
-  /* Get real time at start of run. */
-#if _VMD_EXT
-  (void) sysutime(UTIME_TIMEOFDAY, &start_time);
-#else
-  start_time = times(&dummy);
-#endif
-
-  /* Fork off child. */
-  if ((pid = fork()) < 0) {
-	std_err("Cannot fork\n");
-	exit(1);
-  }
-  if (pid == 0) execute();
-
-  /* Parent is the time program.  Disable interrupts and wait. */
-  signal(SIGINT, SIG_IGN);
-  signal(SIGQUIT, SIG_IGN);
-
-  do {
-	times(&pre_buf);
-  } while (wait(&status) != pid);
-#if _VMD_EXT
-  (void) sysutime(UTIME_TIMEOFDAY, &end_time);
-  real_time = (end_time.tv_sec - start_time.tv_sec) * CLOCKS_PER_SEC
-	+ (end_time.tv_usec - start_time.tv_usec) * CLOCKS_PER_SEC / 1000000;
-#else
-  end_time = times(&dummy);
-  real_time = (end_time - start_time);
-#endif
-
-  if ((status & 0377) != 0) std_err("Command terminated abnormally.\n");
-  times(&post_buf);
-
-  /* Print results. -DNEW enables time on one line to 0.01 sec */
-#ifndef NEW
-  std_err("real ");
-  print_time(real_time);
-  std_err("\nuser ");
-  print_time(post_buf.tms_cutime - pre_buf.tms_cutime);
-  std_err("\nsys  ");
-  print_time(post_buf.tms_cstime - pre_buf.tms_cstime);
-  std_err("\n");
-#else
-  print_time(real_time);
-  std_err(" real");
-  print_time(post_buf.tms_cutime - pre_buf.tms_cutime);
-  std_err(" user");
-  print_time(post_buf.tms_cstime - pre_buf.tms_cstime);
-  std_err(" sys\n");
-#endif
-  return((status & 0377) ? -1 : (status >> 8));
-}
-
-void print_time(t)
-register clock_t t;
-{
-/* Print the time 't' in hours: minutes: seconds.  't' is in ticks. */
-
-  int hours, minutes, seconds, hundredths, i;
-
-  digit_seen = 0;
-  for (i = 0; i < 8; i++) a[i] = ' ';
-  hours = (int) (t / ((clock_t) 3600 * CLOCKS_PER_SEC));
-  t -= (clock_t) hours * 3600 * CLOCKS_PER_SEC;
-  minutes = (int) (t / ((clock_t) 60 * CLOCKS_PER_SEC));
-  t -= (clock_t) minutes * 60 * CLOCKS_PER_SEC;
-  seconds = (int) (t / CLOCKS_PER_SEC);
-  t -= (clock_t) seconds * CLOCKS_PER_SEC;
-  hundredths = (int) (t * 100 / CLOCKS_PER_SEC);
-
-  if (hours) {
-	twin(hours, &a[0]);
-	a[2] = ':';
-  }
-  if (minutes || digit_seen) {
-	twin(minutes, &a[3]);
-	a[5] = ':';
-  }
-  if (seconds || digit_seen)
-	twin(seconds, &a[6]);
-  else
-	a[7] = '0';
-  a[9] = hundredths / 10 + '0';
-#ifdef HUNDREDTHS		/* tenths used to be enough */
-  a[10] = hundredths % 10 + '0';
-#endif
-  std_err(a);
-}
-
-void twin(n, p)
-int n;
-char *p;
-{
-  char c1, c2;
-  c1 = (n / 10) + '0';
-  c2 = (n % 10) + '0';
-  if (digit_seen == 0 && c1 == '0') c1 = ' ';
-  *p++ = c1;
-  *p++ = c2;
-  if (n > 0) digit_seen = 1;
-}
-
-void execute()
-{
-  execvp(name, args);
-  std_err("Cannot execute ");
-  std_err(name);
-  std_err("\n");
-  exit(-1);
-}
Index: trunk/minix/commands/simple/top.c
===================================================================
--- trunk/minix/commands/simple/top.c	(revision 9)
+++ 	(revision )
@@ -1,348 +1,0 @@
-
-/* Author: Ben Gras <beng@few.vu.nl>  17 march 2006 */
-
-#define _MINIX 1
-#define _POSIX_SOURCE 1
-
-#include <stdio.h>
-#include <pwd.h>
-#include <curses.h>
-#include <timers.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <termcap.h>
-#include <termios.h>
-#include <time.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <sys/ioc_tty.h>
-#include <sys/times.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/select.h>
-
-#include <minix/ipc.h>
-#include <minix/config.h>
-#include <minix/type.h>
-#include <minix/const.h>
-
-#include "../../servers/pm/mproc.h"
-#include "../../kernel/const.h"
-#include "../../kernel/proc.h"
-
-#define  TC_BUFFER  1024        /* Size of termcap(3) buffer    */
-#define  TC_STRINGS  200        /* Enough room for cm,cl,so,se  */
-
-char *Tclr_all;
-
-int print_memory(struct pm_mem_info *pmi)
-{
-        int h;
-        int largest_bytes = 0, total_bytes = 0; 
-        for(h = 0; h < _NR_HOLES; h++) {
-                if(pmi->pmi_holes[h].h_base && pmi->pmi_holes[h].h_len) {
-                        int bytes;
-                        bytes = pmi->pmi_holes[h].h_len << CLICK_SHIFT;
-                        if(bytes > largest_bytes) largest_bytes = bytes;
-                        total_bytes += bytes;
-                }
-        }
-
-	printf("Mem: %dK Free, %dK Contiguous Free\n",
-		total_bytes/1024, largest_bytes/1024);
-
-	return 1;
-}
-
-int print_load(double *loads, int nloads)
-{
-	int i;
-	printf("load averages: ");
-	for(i = 0; i < nloads; i++)
-		printf("%s %.2f", (i > 0) ? "," : "", loads[i]);
-	printf("\n");
-	return 1;
-}
-
-#define PROCS (NR_PROCS+NR_TASKS)
-
-int print_proc_summary(struct proc *proc)
-{
-	int p, alive, running, sleeping;
-
-	alive = running = sleeping = 0;
-
-	for(p = 0; p < PROCS; p++) {
-		if(p - NR_TASKS == IDLE)
-			continue;
-		if(proc[p].p_rts_flags & SLOT_FREE)
-			continue;
-		alive++;
-		if(proc[p].p_rts_flags & ~SLOT_FREE)
-			sleeping++;
-		else
-			running++;
-	}
-	printf("%d processes: %d running, %d sleeping\n",
-		alive, running, sleeping);
-	return 1;
-}
-
-static struct tp {
-	struct proc *p;
-	int ticks;
-} tick_procs[PROCS];
-
-int cmp_ticks(const void *v1, const void *v2)
-{
-	struct tp *p1 = (struct tp *) v1, *p2 = (struct tp *) v2;
-	if(p1->ticks < p2->ticks)
-		return 1;
-	if(p1->ticks > p2->ticks)
-		return -1;
-	if(p1->p->p_nr < p2->p->p_nr)
-		return -1;
-	if(p1->p->p_nr > p2->p->p_nr)
-		return 1;
-	return 0;
-}
-
-void print_procs(int maxlines,
-	struct proc *proc1, struct proc *proc2, int dt,
-	struct mproc *mproc)
-{
-	int p, nprocs, tot=0;
-	int idleticks = 0, kernelticks = 0, systemticks = 0;
-
-	if(dt < 1) return;
-
-	for(p = nprocs = 0; p < PROCS; p++) {
-		if(proc2[p].p_rts_flags & SLOT_FREE)
-			continue;
-		tick_procs[nprocs].p = proc2 + p;
-		if(proc1[p].p_endpoint == proc2[p].p_endpoint) {
-			tick_procs[nprocs].ticks =
-				proc2[p].p_user_time-proc1[p].p_user_time;
-		} else {
-			tick_procs[nprocs].ticks =
-				proc2[p].p_user_time;
-		}
-		if(p-NR_TASKS == IDLE) {
-			idleticks = tick_procs[nprocs].ticks;
-			continue;
-		}
-
-		/* Kernel task time, not counting IDLE */
-		if(proc2[p].p_nr < 0)
-			kernelticks += tick_procs[nprocs].ticks;
-		else if(mproc[proc2[p].p_nr].mp_procgrp == 0)
-			systemticks += tick_procs[nprocs].ticks;
-		nprocs++;
-	}
-
-	qsort(tick_procs, nprocs, sizeof(tick_procs[0]), cmp_ticks);
-
-	printf("CPU states: %6.2f%% user, %6.2f%% system, %6.2f%% kernel, %6.2f%% idle",
-		100.0*(dt-systemticks-kernelticks-idleticks)/dt,
-		100.0*systemticks/dt,
-		100.0*kernelticks/dt,
-		100.0*idleticks/dt);
-	printf("\n\n");
-	maxlines -= 2;
-
-	printf("  PID USERNAME PRI NICE   SIZE STATE   TIME     CPU COMMAND\n");
-	maxlines--;
-	for(p = 0; p < nprocs; p++) {
-		int euid = 0;
-		struct proc *pr;
-		int pnr, ticks;
-		char *name = "";
-		static struct passwd *who = NULL;
-		static int last_who = -1;
-
-		if(maxlines-- <= 0) break;
-
-		pnr = tick_procs[p].p->p_nr;
-		pr = tick_procs[p].p;
-		ticks = pr->p_user_time;
-		if(pnr >= 0) {
-			printf("%5d ", mproc[pnr].mp_pid);
-			euid = mproc[pnr].mp_effuid;
-			name = mproc[pnr].mp_name;
-		} else	{
-			printf("[%3d] ", pnr);
-			name = pr->p_name;
-		}
-		if(last_who != euid || !who) {
-			who = getpwuid(euid);
-			last_who = euid;
-		}
-
-		if(who && who->pw_name) printf("%-8s ", who->pw_name);
-		else if(pnr >= 0) printf("%8d ", mproc[pnr].mp_effuid);
-		else printf("         ");
-
-		printf(" %2d ", pr->p_priority);
-		if(pnr >= 0) {
-			printf(" %3d ", mproc[pnr].mp_nice);
-		} else printf("     ");
-		printf("%5dK",
-			((pr->p_memmap[T].mem_len + 
-			pr->p_memmap[D].mem_len) << CLICK_SHIFT)/1024);
-		printf("%6s", pr->p_rts_flags ? "" : "RUN");
-		printf(" %3d:%02d ", (ticks/HZ/60), (ticks/HZ)%60);
-
-		printf("%6.2f%% %s\n",
-			100.0*tick_procs[p].ticks/dt, name);
-	}
-}
-
-void showtop(int r)
-{
-#define NLOADS 3
-	double loads[NLOADS];
-	int nloads, i, p, lines = 0;
-	static struct proc prev_proc[PROCS], proc[PROCS];
-	struct winsize winsize;
-        static struct pm_mem_info pmi;
-	static int prev_uptime, uptime;
-	static struct mproc mproc[NR_PROCS];
-	struct tms tms;
-
-	uptime = times(&tms);
-
-	if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) {
-		perror("TIOCGWINSZ");
-		fprintf(stderr, "TIOCGWINSZ failed\n");
-		exit(1);
-	}
-
-        if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, &pmi) < 0) {
-		fprintf(stderr, "getsysinfo() for SI_MEM_ALLOC failed.\n");
-		exit(1);;
-	}
-
-	if(getsysinfo(PM_PROC_NR, SI_KPROC_TAB, proc) < 0) {
-		fprintf(stderr, "getsysinfo() for SI_KPROC_TAB failed.\n");
-		exit(1);
-	}
-
-	if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc) < 0) {
-		fprintf(stderr, "getsysinfo() for SI_PROC_TAB failed.\n");
-		exit(1);
-	}
-
-	if((nloads = getloadavg(loads, NLOADS)) != NLOADS) {
-		fprintf(stderr, "getloadavg() failed - %d loads\n", nloads);
-		exit(1);
-	}
-
-
-	printf("%s", Tclr_all);
-
-	lines += print_load(loads, NLOADS);
-	lines += print_proc_summary(proc);
-	lines += print_memory(&pmi);
-
-	if(winsize.ws_row > 0) r = winsize.ws_row;
-
-	print_procs(r - lines - 2, prev_proc,
-		proc, uptime-prev_uptime, mproc);
-
-	memcpy(prev_proc, proc, sizeof(prev_proc));
-	prev_uptime = uptime;
-}
-
-void init(int *rows)
-{
-	char  *term;
-	static char   buffer[TC_BUFFER], strings[TC_STRINGS];
-	char *s = strings, *v;
-
-	*rows = 0;
-
-	if(!(term = getenv("TERM"))) {
-		fprintf(stderr, "No TERM set\n");
-		exit(1);
-	}
-
-	if ( tgetent( buffer, term ) != 1 ) {
-		fprintf(stderr, "tgetent failed for term %s\n", term);
-		exit(1);
-	}
-
-	if ( (Tclr_all = tgetstr( "cl", &s )) == NULL )
-		Tclr_all = "\f";
-
-	if((v = tgetstr ("li", &s)) != NULL)
-		sscanf(v, "%d", rows);
-	if(*rows < 1) *rows = 24;
-	if(!initscr()) {
-		fprintf(stderr, "initscr() failed\n");
-		exit(1);
-	}
-	cbreak();
-	nl();
-}
-
-void sigwinch(int sig) { }
-
-int main(int argc, char *argv[])
-{
-	int r, c, s = 0, orig;
-
-	init(&r);
-
-	while((c=getopt(argc, argv, "s:")) != EOF) {
-		switch(c) {
-			case 's':
-				s = atoi(optarg);
-				break;
-			default:
-				fprintf(stderr,
-					"Usage: %s [-s<secdelay>]\n", argv[0]);
-				return 1;
-		}
-	}
-
-	if(s < 1) 
-		s = 2;
-
-	/* Catch window size changes so display is updated properly right away. */
-	signal(SIGWINCH, sigwinch);
-
-	while(1) {
-		fd_set fds;
-		int ns;
-		struct timeval tv;
-		showtop(r);
-		tv.tv_sec = s;
-		tv.tv_usec = 0;
-
-		FD_ZERO(&fds);
-		FD_SET(STDIN_FILENO, &fds);
-		if((ns=select(STDIN_FILENO+1, &fds, NULL, NULL, &tv)) < 0
-			&& errno != EINTR) {
-			perror("select");
-			sleep(1);
-		}
-
-		if(ns > 0 && FD_ISSET(STDIN_FILENO, &fds)) {
-			char c;
-			if(read(STDIN_FILENO, &c, 1) == 1) {
-				switch(c) {
-					case 'q':
-						return 0;
-						break;
-				}
-			}
-		}
-	}
-
-	return 0;
-}
-
Index: trunk/minix/commands/simple/touch.c
===================================================================
--- trunk/minix/commands/simple/touch.c	(revision 9)
+++ 	(revision )
@@ -1,248 +1,0 @@
-/* Touch - change file access and modification times.
- *
- * Usage: see end of file
- *
- * Conforms to P1003.2 draft 10, sec. 4.62, except that time values
- * are not checked for validity, but passed on to mktime, so that
- * 9301990000 will refer to Apr. 9th 1993. As a side effect, leap
- * seconds are not handled correctly.
- *
- * Authors: Original author unknown. Rewritten for POSIX by 
- *	Peter Holzer (hp@vmars.tuwien.ac.at).
- *
- * $Id: touch.c,v 1.1.1.1 2005/04/21 14:55:35 beng Exp $
- * $Log: touch.c,v $
- * Revision 1.1.1.1  2005/04/21 14:55:35  beng
- * Initial import of pre-3.0.1
- *
- * Revision 1.1.1.1  2005/04/20 13:33:47  beng
- * Initial import of minix 2.0.4
- *
- * Revision 1.8  1994/03/17  21:39:19  hjp
- * fixed bug with 4-digit years
- *
- * Revision 1.7  1994/03/15  00:43:27  hjp
- * Changes from kjb (vmd 1.6.25.1):
- * fixed exit code
- * nonstandard flag 0 to make file very old
- *
- * Revision 1.6  1994/02/12  17:26:33  hjp
- * fixed -a and -m flags
- *
- * Revision 1.5  1994/02/12  16:04:13  hjp
- * fixed bug when -t argument was not given
- * removed debugging code
- * run through pretty to get Minix layout
- *
- * Revision 1.4  1994/02/07  21:23:11  hjp
- * POSIXified.
- *
- */
-
-#define _POSIX_C_SOURCE 2	/* getopt */
-#include <assert.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <utime.h>
-
-#define val2(string) ((string)[0] * 10 + (string)[1] - '0' * 11)
-#define val4(string) (val2(string) * 100 + val2(string + 2))
-
-typedef enum {
-  OLD, NEW
-} formatT;
-
-char *cmnd;
-int no_creat = 0;
-unsigned int to_change = 0;
-#	define ATIME	1
-#	define MTIME	2
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(int doit, (char *name, struct utimbuf tvp));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(time_t parsetime, (const char *string, formatT format));
-
-time_t parsetime(string, format)
-const char *string;
-formatT format;
-{
-  struct tm tm;
-  time_t touchtime;
-  size_t l;
-
-  l = strspn(string, "0123456789");
-  if (l % 2 == 1) return -1;
-  if (string[l] != '\0' && (string[l] != '.' || format == OLD)) {
-	return -1;
-  }
-  if (format == OLD) {
-	if (l == 10) {
-		/* Last two digits are year */
-		tm.tm_year = val2(string + 8);
-		if (tm.tm_year <= 68) tm.tm_year += 100;
-	} else if (l == 8) {
-		time(&touchtime);
-		tm = *localtime(&touchtime);
-	} else {
-		return -1;
-	}
-  } else {
-	if (l == 12) {
-		/* First four digits are year */
-		tm.tm_year = val4(string) - 1900;
-		string += 4;
-	} else if (l == 10) {
-		/* First two digits are year */
-		tm.tm_year = val2(string);
-		if (tm.tm_year <= 68) tm.tm_year += 100;
-		string += 2;
-	} else if (l == 8) {
-		time(&touchtime);
-		tm = *localtime(&touchtime);
-	} else {
-		return -1;
-	}
-  }
-  tm.tm_mon = val2(string) - 1;
-  string += 2;
-  tm.tm_mday = val2(string);
-  string += 2;
-  tm.tm_hour = val2(string);
-  string += 2;
-  tm.tm_min = val2(string);
-  string += 2;
-  if (format == NEW && string[0] == '.') {
-	if (isdigit(string[1]) && isdigit(string[2]) &&
-	    string[3] == '\0') {
-		tm.tm_sec = val2(string + 1);
-	} else {
-		return -1;
-	}
-  } else {
-	tm.tm_sec = 0;
-  }
-  tm.tm_isdst = -1;
-  touchtime = mktime(&tm);
-  return touchtime;
-}
-
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  time_t auxtime;
-  struct stat sb;
-  int c;
-  struct utimbuf touchtimes;
-  int fail = 0;
-
-  cmnd = argv[0];
-  auxtime = time((time_t *) NULL);
-  touchtimes.modtime = auxtime;
-  touchtimes.actime = auxtime;
-
-  while ((c = getopt(argc, argv, "r:t:acm0")) != EOF) {
-	switch (c) {
-	    case 'r':
-		if (stat(optarg, &sb) == -1) {
-			fprintf(stderr, "%s: cannot stat %s: %s\n",
-				cmnd, optarg, strerror(errno));
-			exit(1);
-		}
-		touchtimes.modtime = sb.st_mtime;
-		touchtimes.actime = sb.st_atime;
-		break;
-	    case 't':
-		auxtime = parsetime(optarg, NEW);
-		if (auxtime == (time_t) - 1) usage();
-		touchtimes.modtime = auxtime;
-		touchtimes.actime = auxtime;
-		break;
-	    case 'a':	to_change |= ATIME;	break;
-	    case 'm':	to_change |= MTIME;	break;
-	    case 'c':	no_creat = 1;	break;
-	    case '0':
-		touchtimes.modtime = touchtimes.actime = 0;
-		break;
-	    case '?':	usage();	break;
-	    default:	assert(0);
-	}
-  }
-  if (to_change == 0) {
-	to_change = ATIME | MTIME;
-  }
-  if (optind == argc) usage();
-
-  /* Now check for old style time argument */
-  if (strcmp(argv[optind - 1], "--") != 0 &&
-      (auxtime = parsetime(argv[optind], OLD)) != (time_t) - 1) {
-	touchtimes.modtime = auxtime;
-	touchtimes.actime = auxtime;
-	optind++;
-	if (optind == argc) usage();
-  }
-  while (optind < argc) {
-	if (doit(argv[optind], touchtimes) > 0) {
-		fprintf(stderr, "%s: cannot touch %s: %s\n",
-			cmnd, argv[optind], strerror(errno));
-		fail = 1;
-	}
-	optind++;
-  }
-  return fail ? 1 : 0;
-}
-
-
-int doit(name, tvp)
-char *name;
-struct utimbuf tvp;
-{
-  int fd;
-  struct stat sb;
-
-  if (to_change != (ATIME | MTIME)) {
-
-	if (stat(name, &sb) != -1) {
-		if (!(to_change & ATIME)) {
-			tvp.actime = sb.st_atime;
-		} else {
-			tvp.modtime = sb.st_mtime;
-		}
-	}
-  }
-  if (utime(name, &tvp) == 0) return 0;
-  if (errno != ENOENT) return 1;
-  if (no_creat == 1) return 0;
-  if ((fd = creat(name, 0666)) >= 0) {
-	if (fstat(fd, &sb) != -1) {
-		if (!(to_change & ATIME)) {
-			tvp.actime = sb.st_atime;
-		} else {
-			tvp.modtime = sb.st_mtime;
-		}
-	} else {
-		assert(0);
-	}
-	close(fd);
-	if (utime(name, &tvp) == 0) return 0;
-  }
-  return 1;
-}
-
-
-void usage()
-{
-  fprintf(stderr, "Usage: %s [-c] [-a] [-m] [-r file] [-t [CC[YY]]MMDDhhmm[.ss]] "
-	"[MMDDhhmm[YY]] file...\n", cmnd);
-  exit(1);
-}
Index: trunk/minix/commands/simple/tr.c
===================================================================
--- trunk/minix/commands/simple/tr.c	(revision 9)
+++ 	(revision )
@@ -1,169 +1,0 @@
-/* tr - translate characters		Author: Michiel Huisjes */
-/* Usage: tr [-cds] [string1 [string2]]
- *	c: take complement of string1
- *	d: delete input characters coded string1
- *	s: squeeze multiple output characters of string2 into one character
- */
-
-#define BUFFER_SIZE	1024
-#define ASCII		0377
-
-typedef char BOOL;
-#define TRUE	1
-#define FALSE	0
-
-#define NIL_PTR		((char *) 0)
-
-BOOL com_fl, del_fl, sq_fl;
-
-unsigned char output[BUFFER_SIZE], input[BUFFER_SIZE];
-unsigned char vector[ASCII + 1];
-BOOL invec[ASCII + 1], outvec[ASCII + 1];
-
-short in_index, out_index;
-
-#include <sys/types.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void convert, (void));
-_PROTOTYPE(void map, (unsigned char *string1, unsigned char *string2));
-_PROTOTYPE(void expand, (char *arg, unsigned char *buffer));
-_PROTOTYPE(void complement, (unsigned char *buffer));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  register unsigned char *ptr;
-  int index = 1;
-  short i;
-
-  if (argc > 1 && argv[index][0] == '-') {
-	for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) {
-		switch (*ptr) {
-		    case 'c':	com_fl = TRUE;	break;
-		    case 'd':	del_fl = TRUE;	break;
-		    case 's':	sq_fl = TRUE;	break;
-		    default:
-			write(2,"Usage: tr [-cds] [string1 [string2]].\n", 38);
-			exit(1);
-		}
-	}
-	index++;
-  }
-  for (i = 0; i <= ASCII; i++) {
-	vector[i] = i;
-	invec[i] = outvec[i] = FALSE;
-  }
-
-  if (argv[index] != NIL_PTR) {
-	expand(argv[index++], input);
-	if (com_fl) complement(input);
-	if (argv[index] != NIL_PTR) expand(argv[index], output);
-	if (argv[index] != NIL_PTR) map(input, output);
-	for (ptr = input; *ptr; ptr++) invec[*ptr] = TRUE;
-	for (ptr = output; *ptr; ptr++) outvec[*ptr] = TRUE;
-  }
-  convert();
-  return(0);
-}
-
-void convert()
-{
-  short read_chars = 0;
-  short c, coded;
-  short last = -1;
-
-  for (;;) {
-	if (in_index == read_chars) {
-		if ((read_chars = read(0, (char *)input, BUFFER_SIZE)) <= 0) {
-			if (write(1, (char *)output, out_index) != out_index)
-				write(2, "Bad write\n", 10);
-			exit(0);
-		}
-		in_index = 0;
-	}
-	c = input[in_index++];
-	coded = vector[c];
-	if (del_fl && invec[c]) continue;
-	if (sq_fl && last == coded && outvec[coded]) continue;
-	output[out_index++] = last = coded;
-	if (out_index == BUFFER_SIZE) {
-		if (write(1, (char *)output, out_index) != out_index) {
-			write(2, "Bad write\n", 10);
-			exit(1);
-		}
-		out_index = 0;
-	}
-  }
-
-  /* NOTREACHED */
-}
-
-void map(string1, string2)
-register unsigned char *string1, *string2;
-{
-  unsigned char last;
-
-  while (*string1) {
-	if (*string2 == '\0')
-		vector[*string1] = last;
-	else
-		vector[*string1] = last = *string2++;
-	string1++;
-  }
-}
-
-void expand(arg, buffer)
-register char *arg;
-register unsigned char *buffer;
-{
-  int i, ac;
-
-  while (*arg) {
-	if (*arg == '\\') {
-		arg++;
-		i = ac = 0;
-		if (*arg >= '0' && *arg <= '7') {
-			do {
-				ac = (ac << 3) + *arg++ - '0';
-				i++;
-			} while (i < 4 && *arg >= '0' && *arg <= '7');
-			*buffer++ = ac;
-		} else if (*arg != '\0')
-			*buffer++ = *arg++;
-	} else if (*arg == '[') {
-		arg++;
-		i = *arg++;
-		if (*arg++ != '-') {
-			*buffer++ = '[';
-			arg -= 2;
-			continue;
-		}
-		ac = *arg++;
-		while (i <= ac) *buffer++ = i++;
-		arg++;		/* Skip ']' */
-	} else
-		*buffer++ = *arg++;
-  }
-}
-
-void complement(buffer)
-unsigned char *buffer;
-{
-  register unsigned char *ptr;
-  register short i, index;
-  unsigned char conv[ASCII + 2];
-
-  index = 0;
-  for (i = 1; i <= ASCII; i++) {
-	for (ptr = buffer; *ptr; ptr++)
-		if (*ptr == i) break;
-	if (*ptr == '\0') conv[index++] = i & ASCII;
-  }
-  conv[index] = '\0';
-  strcpy((char *)buffer, (char *)conv);
-}
Index: trunk/minix/commands/simple/treecmp.c
===================================================================
--- trunk/minix/commands/simple/treecmp.c	(revision 9)
+++ 	(revision )
@@ -1,327 +1,0 @@
-/* treecmp - compare two trees		Author: Andy Tanenbaum */
-
-/* This program recursively compares two trees and reports on differences.
- * It can be used, for example, when a project consists of a large number
- * of files and directories.  When a new release (i.e., a new tree) has been
- * prepared, the old and new tree can be compared to give a list of what has
- * changed.  The algorithm used is that the second tree is recursively
- * descended and for each file or directory found, the corresponding one in
- * the other tree checked.  The two arguments are not completely symmetric
- * because the second tree is descended, not the first one, but reversing
- * the arguments will still detect all the differences, only they will be
- * printed in a different order.  The program needs lots of stack space
- * because routines with local arrays are called recursively. The call is
- *    treecmp [-cv] old_dir new_dir
- * The -v flag (verbose) prints the directory names as they are processed.
- * The -c flag (changes) just prints the names of changed and new files.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define BUFSIZE 4096		/* size of file buffers */
-#define MAXPATH 128		/* longest acceptable path */
-#define DIRENTLEN 14		/* number of characters in a file name */
-
-struct dirstruct {		/* layout of a directory entry */
-  ino_t inum;
-  char fname[DIRENTLEN];
-};
-
-struct stat stat1, stat2;	/* stat buffers */
-
-char buf1[BUFSIZE];		/* used for comparing bufs */
-char buf2[BUFSIZE];		/* used for comparing bufs */
-
-int changes;			/* set on -c flag */
-int verbose;			/* set on -v flag */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void compare, (char *old, char *new));
-_PROTOTYPE(void regular, (char *old, char *new));
-_PROTOTYPE(void directory, (char *old, char *new));
-_PROTOTYPE(void check, (char *s, struct dirstruct *dp1, int ent1, char *new));
-_PROTOTYPE(void usage, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char *p;
-
-  if (argc < 3 || argc > 4) usage();
-  p = argv[1];
-  if (argc == 4) {
-	if (*p != '-') usage();
-	p++;
-	if (*p == '\0') usage();
-	while (*p) {
-		if (*p == 'c') changes++;
-		if (*p == 'v') verbose++;
-		if (*p != 'c' && *p != 'v') usage();
-		p++;
-	}
-  }
-  if (argc == 3)
-	compare(argv[1], argv[2]);
-  else
-	compare(argv[2], argv[3]);
-
-  return(0);
-}
-
-void compare(old, new)
-char *old, *new;
-{
-/* This is the main comparision routine.  It gets two path names as arguments
- * and stats them both.  Depending on the results, it calls other routines
- * to compare directories or files.
- */
-
-  int type1, type2;
-
-  if (stat(new, &stat1) < 0) {
-	/* The new file does not exist. */
-	if (changes == 0)
-		fprintf(stderr, "Cannot stat: %s\n", new);
-	else
-		printf("%s\n", new);
-	return;
-  }
-  if (stat(old, &stat2) < 0) {
-	/* The old file does not exist. */
-	if (changes == 0) 
-		fprintf(stderr, "Missing file: %s\n", old);
-	else
-		printf("%s\n", new);
-	return;
-  }
-
-  /* Examine the types of the files. */
-  type1 = stat1.st_mode & S_IFMT;
-  type2 = stat2.st_mode & S_IFMT;
-  if (type1 != type2) {
-	fprintf(stderr, "Type diff: %s and %s\n", new, old);
-	return;
-  }
-
-  /* The types are the same. */
-  switch (type1) {
-      case S_IFREG:	regular(old, new);	break;
-      case S_IFDIR:	directory(old, new);	break;
-      case S_IFCHR:	break;
-      case S_IFBLK:	break;
-      default:		fprintf(stderr, "Unknown file type %o\n", type1);
-  }
-  return;
-}
-
-void regular(old, new)
-char *old, *new;
-{
-/* Compare to regular files.  If they are different, complain. */
-
-  int fd1, fd2, n1, n2;
-  unsigned bytes;
-  long count;
-
-  if (stat1.st_size != stat2.st_size) {
-	if (changes == 0)
-		printf("Size diff: %s and %s\n", new, old);
-	else
-		printf("%s\n", new);
-	return;
-  }
-
-  /* The sizes are the same.  We actually have to read the files now. */
-  fd1 = open(new, O_RDONLY);
-  if (fd1 < 0) {
-	fprintf(stderr, "Cannot open %s for reading\n", new);
-	return;
-  }
-  fd2 = open(old, O_RDONLY);
-  if (fd2 < 0) {
-	fprintf(stderr, "Cannot open %s for reading\n", old);
-	return;
-  }
-  count = stat1.st_size;
-  while (count > 0L) {
-	bytes = (unsigned) (count > BUFSIZE ? BUFSIZE : count);	/* rd count */
-	n1 = read(fd1, buf1, bytes);
-	n2 = read(fd2, buf2, bytes);
-	if (n1 != n2) {
-		if (changes == 0)
-			printf("Length diff: %s and %s\n", new, old);
-		else
-			printf("%s\n", new);
-		close(fd1);
-		close(fd2);
-		return;
-	}
-
-	/* Compare the buffers. */
-	if (memcmp((void *) buf1, (void *) buf2, (size_t) n1) != 0) {
-		if (changes == 0)
-			printf("File diff: %s and %s\n", new, old);
-		else
-			printf("%s\n", new);
-		close(fd1);
-		close(fd2);
-		return;
-	}
-	count -= n1;
-  }
-  close(fd1);
-  close(fd2);
-}
-
-void directory(old, new)
-char *old, *new;
-{
-/* Recursively compare two directories by reading them and comparing their
- * contents.  The order of the entries need not be the same.
- */
-
-  int fd1, fd2, n1, n2, ent1, ent2, i, used1 = 0, used2 = 0;
-  char *dir1buf, *dir2buf;
-  char name1buf[MAXPATH], name2buf[MAXPATH];
-  struct dirstruct *dp1, *dp2;
-  unsigned dir1bytes, dir2bytes;
-
-  /* Allocate space to read in the directories */
-  dir1bytes = (unsigned) stat1.st_size;
-  dir1buf = (char *)malloc((size_t)dir1bytes);
-  if (dir1buf == 0) {
-	fprintf(stderr, "Cannot process directory %s: out of memory\n", new);
-	return;
-  }
-  dir2bytes = (unsigned) stat2.st_size;
-  dir2buf = (char *)malloc((size_t)dir2bytes);
-  if (dir2buf == 0) {
-	fprintf(stderr, "Cannot process directory %s: out of memory\n", old);
-	free(dir1buf);
-	return;
-  }
-
-  /* Read in the directories. */
-  fd1 = open(new, O_RDONLY);
-  if (fd1 > 0) n1 = read(fd1, dir1buf, dir1bytes);
-  if (fd1 < 0 || n1 != dir1bytes) {
-	fprintf(stderr, "Cannot read directory %s\n", new);
-	free(dir1buf);
-	free(dir2buf);
-	if (fd1 > 0) close(fd1);
-	return;
-  }
-  close(fd1);
-
-  fd2 = open(old, O_RDONLY);
-  if (fd2 > 0) n2 = read(fd2, dir2buf, dir2bytes);
-  if (fd2 < 0 || n2 != dir2bytes) {
-	fprintf(stderr, "Cannot read directory %s\n", old);
-	free(dir1buf);
-	free(dir2buf);
-	close(fd1);
-	if (fd2 > 0) close(fd2);
-	return;
-  }
-  close(fd2);
-
-  /* Linearly search directories */
-  ent1 = dir1bytes / sizeof(struct dirstruct);
-  dp1 = (struct dirstruct *) dir1buf;
-  for (i = 0; i < ent1; i++) {
-	if (dp1->inum != 0) used1++;
-	dp1++;
-  }
-
-  ent2 = dir2bytes / sizeof(struct dirstruct);
-  dp2 = (struct dirstruct *) dir2buf;
-  for (i = 0; i < ent2; i++) {
-	if (dp2->inum != 0) used2++;
-	dp2++;
-  }
-
-  if (verbose) printf("Directory %s: %d entries\n", new, used1);
-
-  /* Check to see if any entries in dir2 are missing from dir1. */
-  dp1 = (struct dirstruct *) dir1buf;
-  dp2 = (struct dirstruct *) dir2buf;
-  for (i = 0; i < ent2; i++) {
-	if (dp2->inum == 0 || strcmp(dp2->fname, ".") == 0 ||
-					    strcmp(dp2->fname, "..") == 0) {
-		dp2++;
-		continue;
-	}
-	check(dp2->fname, dp1, ent1, new);
-	dp2++;
-  }
-
-  /* Recursively process all the entries in dir1. */
-  dp1 = (struct dirstruct *) dir1buf;
-  for (i = 0; i < ent1; i++) {
-	if (dp1->inum == 0 || strcmp(dp1->fname, ".") == 0 ||
-	    strcmp(dp1->fname, "..") == 0) {
-		dp1++;
-		continue;
-	}
-	if (strlen(new) + DIRENTLEN >= MAXPATH) {
-		fprintf(stderr, "Path too long: %s\n", new);
-		free(dir1buf);
-		free(dir2buf);
-		return;
-	}
-	if (strlen(old) + DIRENTLEN >= MAXPATH) {
-		fprintf(stderr, "Path too long: %s\n", old);
-		free(dir1buf);
-		free(dir2buf);
-		return;
-	}
-	strcpy(name1buf, old);
-	strcat(name1buf, "/");
-	strncat(name1buf, dp1->fname, (size_t)DIRENTLEN);
-	strcpy(name2buf, new);
-	strcat(name2buf, "/");
-	strncat(name2buf, dp1->fname, (size_t)DIRENTLEN);
-
-	/* Here is the recursive call to process an entry. */
-	compare(name1buf, name2buf);	/* recursive call */
-	dp1++;
-  }
-
-  free(dir1buf);
-  free(dir2buf);
-}
-
-void check(s, dp1, ent1, new)
-char *s;
-struct dirstruct *dp1;
-int ent1;
-char *new;
-{
-/* See if the file name 's' is present in the directory 'dirbuf'. */
-  int i;
-  char file[DIRENTLEN+1];
-
-  for (i = 0; i < ent1; i++) {
-	if (strncmp(dp1->fname, s, (size_t)DIRENTLEN) == 0) return;
-	dp1++;
-  }
-  if (changes == 0) {
-	strncpy(file, s, DIRENTLEN);
-	file[DIRENTLEN] = '\0';
-	printf("Missing file: %s/%s\n", new, file);
-  }
-	
-}
-
-void usage()
-{
-  printf("Usage: treecmp [-cv] old_dir new_dir\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/truncate.c
===================================================================
--- trunk/minix/commands/simple/truncate.c	(revision 9)
+++ 	(revision )
@@ -1,208 +1,0 @@
-/*
- * Copyright (c) 2000 Sheldon Hearn <sheldonh@FreeBSD.org>.
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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/stat.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-static off_t	parselength(char *, off_t *);
-static void	usage(void);
-
-static int	no_create;
-static int	do_relative;
-static int	do_refer;
-static int	got_size;
-
-int
-main(int argc, char **argv)
-{
-	struct stat	sb;
-	mode_t	omode;
-	off_t	oflow, rsize, sz, tsize;
-	int	ch, error, fd, oflags;
-	char   *fname, *rname;
-
-	rsize = tsize = 0;
-	error = 0;
-	rname = NULL;
-	while ((ch = getopt(argc, argv, "cr:s:")) != -1)
-		switch (ch) {
-		case 'c':
-			no_create = 1;
-			break;
-		case 'r':
-			do_refer = 1;
-			rname = optarg;
-			break;
-		case 's':
-			if (parselength(optarg, &sz) == -1) {
-				fprintf(stderr,
-				    "invalid size argument `%s'", optarg);
-				   exit(EXIT_FAILURE);
-				  }
-			if (*optarg == '+' || *optarg == '-')
-				do_relative = 1;
-			got_size = 1;
-			break;
-		default:
-			usage();
-			/* NOTREACHED */
-		}
-
-	argv += optind;
-	argc -= optind;
-
-	/*
-	 * Exactly one of do_refer or got_size must be specified.  Since
-	 * do_relative implies got_size, do_relative and do_refer are
-	 * also mutually exclusive.  See usage() for allowed invocations.
-	 */
-	if (do_refer + got_size != 1 || argc < 1)
-		usage();
-	if (do_refer) {
-		if (stat(rname, &sb) == -1) {
-			fprintf(stderr, "%s", rname);
-			exit(EXIT_FAILURE);
-		}
-		tsize = sb.st_size;
-	} else if (do_relative)
-		rsize = sz;
-	else
-		tsize = sz;
-
-	if (no_create)
-		oflags = O_WRONLY;
-	else
-		oflags = O_WRONLY | O_CREAT;
-	omode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
-
-	while ((fname = *argv++) != NULL) {
-		if ((fd = open(fname, oflags, omode)) == -1) {
-			if (errno != ENOENT) {
-				perror(fname);
-				error++;
-			}
-			continue;
-		}
-		if (do_relative) {
-			if (fstat(fd, &sb) == -1) {
-				perror(fname);
-				error++;
-				continue;
-			}
-			oflow = sb.st_size + rsize;
-			if (oflow < (sb.st_size + rsize)) {
-				errno = EFBIG;
-				perror(fname);
-				error++;
-				continue;
-			}
-			tsize = oflow;
-		}
-		if (tsize < 0)
-			tsize = 0;
-
-		if (ftruncate(fd, tsize) == -1) {
-			perror(fname);
-			error++;
-			continue;
-		}
-
-		close(fd);
-	}
-
-	return error ? EXIT_FAILURE : EXIT_SUCCESS;
-}
-
-/*
- * Return the numeric value of a string given in the form [+-][0-9]+[GMK]
- * or -1 on format error or overflow.
- */
-static off_t
-parselength(char *ls, off_t *sz)
-{
-	off_t	length, oflow;
-	int	lsign;
-
-	length = 0;
-	lsign = 1;
-
-	switch (*ls) {
-	case '-':
-		lsign = -1;
-	case '+':
-		ls++;
-	}
-
-#define	ASSIGN_CHK_OFLOW(x, y)	if (x < y) return -1; y = x
-	/*
-	 * Calculate the value of the decimal digit string, failing
-	 * on overflow.
-	 */
-	while (isdigit(*ls)) {
-		oflow = length * 10 + *ls++ - '0';
-		ASSIGN_CHK_OFLOW(oflow, length);
-	}
-
-	switch (*ls) {
-	case 'G':
-	case 'g':
-		oflow = length * 1024;
-		ASSIGN_CHK_OFLOW(oflow, length);
-	case 'M':
-	case 'm':
-		oflow = length * 1024;
-		ASSIGN_CHK_OFLOW(oflow, length);
-	case 'K':
-	case 'k':
-		if (ls[1] != '\0')
-			return -1;
-		oflow = length * 1024;
-		ASSIGN_CHK_OFLOW(oflow, length);
-	case '\0':
-		break;
-	default:
-		return -1;
-	}
-
-	*sz = length * lsign;
-	return 0;
-}
-
-static void
-usage(void)
-{
-	fprintf(stderr, "%s\n%s\n",
-	    "usage: truncate [-c] -s [+|-]size[K|k|M|m|G|g] file ...",
-	    "       truncate [-c] -r rfile file ...");
-	exit(EXIT_FAILURE);
-}
Index: trunk/minix/commands/simple/tsort.c
===================================================================
--- trunk/minix/commands/simple/tsort.c	(revision 9)
+++ 	(revision )
@@ -1,356 +1,0 @@
-/* topo - topological sort		Author: Kent Williams */
-
-/*
-** topo - perform a topological sort of the output of lorder.
-**
-** Usage : topo [infile] [outfile]
-**
-** Author: Kent Williams (williams@umaxc.weeg.uiowa.edu)
-*/
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-typedef struct __v {
-    struct __v *next;   /* link list node                   */
-    int indegree,       /* number of edges into this vertex */
-        visited,        /* depth-first search visited flag  */
-        on_the_path,    /* used to find cycles              */
-        has_a_cycle;    /* true if a cycle at this vertex   */
-    struct __e *out;    /* outgoing edges from this vertex  */
-    char key[1];        /* name of this vertex              */
-} vertex;
-
-typedef struct __e {
-    struct __e *next;   /* link list node                   */
-    vertex *v;          /* vertex to which this edge goes   */
-} edge;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void *xmalloc, (size_t siz));
-_PROTOTYPE(edge *new_edge, (vertex *v));
-_PROTOTYPE(char *copyupto, (char *name, char *buf, int stop));
-_PROTOTYPE(int child_of, (vertex *parent, vertex *child));
-_PROTOTYPE(vertex *add_v, (char *s));
-_PROTOTYPE(void readin, (void));
-_PROTOTYPE(void pushname, (char *s));
-_PROTOTYPE(char *popname, (void));
-_PROTOTYPE(void topo, (void));
-_PROTOTYPE(void print_cycle, (vertex *parent, vertex *child));
-_PROTOTYPE(void dfs, (vertex *v));
-_PROTOTYPE(void check_cycles, (void));
-
-/*
-** xmalloc -- standard do or die malloc front end.
-*/
-void *
-xmalloc(siz)
-size_t siz;
-{
-    void *rval = (void *)malloc(siz);
-    if(rval == NULL) {
-        fputs("Out of memory.\n",stderr);
-        exit(1);
-    }
-    return rval;
-}
-
-/*
-** edge allocater.
-*/
-edge *
-new_edge(v)
-vertex *v;
-{
-    edge *rval;
-    rval = (edge *)xmalloc(sizeof(edge));
-    rval->v = v; return rval;
-}
-
-/*
-** copyupto - copy until you see the stop character.
-*/
-char *
-copyupto(name,buf,stop)
-char *name,*buf,stop;
-{
-    while(*buf != '\0' && *buf != stop)
-        *name++ = *buf++;
-    *name = '\0';
-    while(*buf != '\0' && isspace(*buf))
-        buf++;
-    return buf;
-}
-
-/*
-** find out if the vertex child is a child of the vertex parent.
-*/
-int
-child_of(parent,child)
-vertex *parent,*child;
-{
-    edge *e;
-    for(e = parent->out; e != NULL && e->v != child; e = e->next)
-        ;
-    return e == NULL ? 0 : 1;
-}
-
-/*
-** the vertex set.
-**
-** add_v adds a vertex to the set if it's not already there.
-*/
-vertex *vset = NULL;
-
-vertex *
-add_v(s)
-char *s;
-{
-    vertex *v,*last;
-    /*
-    ** go looking for this key in the vertex set.
-    */
-    for(last = v = vset; v != NULL && strcmp(v->key,s) != 0;
-        last = v, v = v->next)
-        ;
-    if(v != NULL) {
-        /*
-        ** use the move-to-front heuristic to keep this from being
-        ** an O(N^2) algorithm.
-        */
-        if(last != vset) {
-            last->next = v->next;
-            v->next = vset;
-            vset = v;
-        }
-        return v;
-    }
-
-    v = (vertex *)xmalloc(sizeof(vertex) + strlen(s));
-
-    v->out = NULL;
-    strcpy(v->key,s);
-    v->indegree =
-    v->on_the_path =
-    v->has_a_cycle =
-    v->visited = 0;
-    v->next = vset;
-    vset = v;
-    return v;
-}
-
-/*
-** readin -- read in the dependency pairs.
-*/
-void
-readin()
-{
-    static char buf[128];
-    static char name[64];
-    char *bp;
-    vertex *child,*parent;
-    edge *e;
-    while(fgets(buf,sizeof(buf),stdin) != NULL) {
-	bp = buf + strlen(buf);
-	if (bp > buf && bp[-1] == '\n') *--bp = 0;
-        bp = copyupto(name,buf,' ');
-        child = add_v(name);
-        parent = add_v(bp);
-        if(child != parent && !child_of(parent,child)) {
-            e = new_edge(child);
-            e->next = parent->out;
-            parent->out = e;
-            child->indegree++;
-        }
-    }
-}
-
-/*
-** the topological sort produces names of modules in reverse of
-** the order we want them in, so use a stack to hold the names
-** until we get them all, then pop them off to print them.
-*/
-struct name { struct name *next; char *s; }
-*namelist = NULL;
-
-void
-pushname(s)
-char *s;
-{
-    struct name *x = (struct name *)xmalloc(sizeof(struct name));
-    x->s = s;
-    x->next = namelist;
-    namelist = x;
-}
-
-char *
-popname() {
-    char *rval;
-    struct name *tmp;
-    if(namelist == NULL)
-        return NULL;
-    tmp = namelist;
-    rval = namelist->s;
-    namelist = namelist->next;
-    free(tmp);
-    return rval;
-}
-
-/*
-** topo - do a topological sort of the dependency graph.
-*/
-void topo() {
-    vertex *x = vset,*n;
-    edge *e;
-    vertex *outq = NULL,*tmp;
-#define insq(x) ((x->next = outq),(outq = x))
-#define deq() ((tmp = outq),(outq = outq->next),tmp)
-
-    /*
-    ** find all vertices that don't depend on any other vertices
-    ** Since it breaks the "next" links to insert x into the queue,
-    ** x->next is saved before insq, to resume the list traversal.
-    */
-    while (x != NULL) {
-	n = x->next;
-        if(x->indegree == 0) {
-            insq(x);
-            pushname(x->key);       
-        }
-	x = n;
-    }
-
-    /*
-    ** for each vertex V with indegree of zero,
-    **     for each edge E from vertex V
-    **        subtract one from the indegree of the vertex V'
-    **        pointed to by E.  If V' now has an indegree of zero,
-    **        add it to the set of vertices with indegree zero, and
-    **        push its name on the output stack.
-    */
-    while(outq != NULL) {
-        x = deq();
-        e = x->out;
-        while(e != NULL) {
-            if(--(e->v->indegree) == 0) {
-                insq(e->v);
-                pushname(e->v->key);
-            }
-            e = e->next;
-        }
-    }
-    
-    /*
-    ** print the vertex names in opposite of the order they were
-    ** encountered.
-    */
-    while(namelist != NULL)
-        puts(popname());
-}
-
-/*
-** print_cycle --
-** A cycle has been detected between parent and child.
-** Start with the child, and look at each of its edges for
-** the parent.
-**
-** We know a vertex is on the path from the child to the parent
-** because the depth-first search sets on_the_path true for each
-** vertex it visits.
-*/
-void
-print_cycle(parent,child)
-vertex *parent, *child;
-{
-    char *s;
-    vertex *x;
-    edge *e;
-    for(x = child; x != parent; ) {
-        pushname(x->key);
-        for(e = x->out; e != NULL; e = e->next) {
-            /*
-            ** stop looking for the path at the first node found
-            ** that's on the path.  Watch out for cycles already
-            ** detected, because if you follow an edge into a cycle,
-            ** you're stuck in an infinite loop!
-            */
-            if(e->v->on_the_path && !e->v->has_a_cycle) {
-                x = e->v;
-                break;
-            }
-        }
-    }
-    /*
-    ** print the name of the parent, and then names of each of the
-    ** vertices on the path from the child to the parent.
-    */
-    fprintf(stderr,"%s\n",x->key);
-    while((s = popname()) != NULL)
-        fprintf(stderr,"%s\n",s);
-}
-
-/*
-** depth first search for cycles in the dependency graph.
-** See "Introduction to Algorithms" by Udi Manber Addison-Wesley 1989
-*/
-void
-dfs(v)
-vertex *v;
-{
-    edge *e;
-
-    if(v->visited)      /* If you've been here before, don't go again! */
-        return;
-    v->visited++;
-    v->on_the_path++;   /* this node is on the path from the root. */
-
-    /*
-    ** depth-first search all outgoing edges.
-    */
-    for(e = v->out; e != NULL; e = e->next) {
-        if(!e->v->visited)
-            dfs(e->v);
-        if(e->v->on_the_path) {
-            fprintf(stderr,"cycle found between %s and %s\n",
-                v->key,e->v->key);
-            print_cycle(v,e->v);
-            v->has_a_cycle++;
-        }
-    }
-    v->on_the_path = 0;
-}
-
-/*
-** check cycles starts the recursive depth-first search from
-** each vertex in vset.
-*/
-void
-check_cycles()
-{
-    vertex *v;
-    for(v = vset; v != NULL; v = v->next)
-        dfs(v);
-}
-
-/*
-** main program.
-*/
-int main(argc,argv)
-int argc;
-char **argv;
-{
-    if(argc > 1 && freopen(argv[1],"r",stdin) == NULL) {
-        perror(argv[1]);
-        exit(0);
-    }
-    if(argc > 2 && freopen(argv[2],"w",stdout) == NULL) {
-        perror(argv[2]);
-        exit(0);
-    }
-    readin();
-    check_cycles();
-    topo();
-    return(0);
-}
Index: trunk/minix/commands/simple/ttt.c
===================================================================
--- trunk/minix/commands/simple/ttt.c	(revision 9)
+++ 	(revision )
@@ -1,299 +1,0 @@
-/* tic tac toe (noughts and crosses)		Author: Warren Toomey */
-
-/* Copyright 1988 by Warren Toomey	wkt@cs.adfa.oz.au[@uunet.uu.net]
- *
- * You may freely copy or distribute this code as long as this notice
- * remains intact.
- *
- * You may modify this code, as long as this notice remains intact, and
- * you add another notice indicating that the code has been modified.
- *
- * You may NOT sell this code or in any way profit from this code without
- * prior agreement from the author.
- */
-
-/* Compile with cc -o tic tic.c -lcurses -ltermcap */
-
-#include <stdlib.h>
-#include <time.h>
-
-#ifdef CURSES
-#include <curses.h>
-#endif
-
-#include <stdio.h>
-
-#ifndef CURSES
-#define printw printf
-#endif
-
-
-typedef struct {
-  int value;			/* The move returned by the    */
-  int path;			/* alphabeta consists of a value */
-} MOVE;				/* and an actual move (path)   */
-
-_PROTOTYPE(int main, (void));
-_PROTOTYPE(int stateval, (int board [], int whosemove));
-_PROTOTYPE(MOVE alphabeta, (int board [], int whosemove, int alpha, int beta));
-_PROTOTYPE(void draw, (int board []));
-_PROTOTYPE(void getmove, (int board []));
-_PROTOTYPE(int endofgame, (int board []));
-_PROTOTYPE(int randommove, (void));
-
- /* Static evaluator. Returns 100 if we have 3 in a row -100 if they have 3
-  * in a row
-  * 
-  * Board is array of 9 ints, where 0=empty square 1=our move 4= their move
-  * 
-  * and board is indices	0 1 2 3 4 5 6 7 8 */
-
-
-int stateval(board, whosemove)
-int board[];
-int whosemove;
-{
-  static int row[8][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8},	/* Indices of 3in-a-rows */
-			{0, 3, 6}, {1, 4, 7}, {2, 5, 8},
-			{0, 4, 8}, {2, 4, 6}};
-
-  int temp;			/* Temp row results */
-  int i, j;			/* Loop counters */
-  int side;			/* Depth multiplier */
-  int win, lose;
-
-  if (whosemove == 1) {
-	win = 100;
-	lose = -100;
-	side = 1;
-  } else {
-	/* Multiply by -1 if */
-	win = -100;
-	lose = 100;
-	side = -1;
-  }				/* not out move */
-  for (i = 0; i < 8; i++) {	/* For every 3-in-a-row */
-	temp = 0;
-	for (j = 0; j < 3; j++)	/* Add up the board values */
-		temp += board[row[i][j]];
-
-	if (temp == 3) return(win);	/* We've got 3 in a row */
-	if (temp == 12) return (lose);	/* They've got 3 in a row */
-  }
-  return(0);			/* Finally return sum */
-}
-
-
-MOVE alphabeta(board, whosemove, alpha, beta)	/* Alphabeta: takes a board, */
-int board[];			/* whose move, alpha & beta cutoffs, */
-int whosemove;			/* and returns a move to make and */
-int alpha;			/* the value that the move has */
-int beta;
-{
-  MOVE result, successor;
-  int best_score, i, best_path, mademove;
-
-  result.value = stateval(board, whosemove);	/* Work out the board's */
-  /* Static value */
-  if ((result.value == 100) ||	/* If a win or loss already */
-      (result.value == -100))
-	return(result);	/* return the result */
-
-  best_score = beta;		/* Ok, set worst score */
-  mademove = 0;			/* to the beta cutoff */
-  for (i = 0; i < 9; i++) {
-	if (board[i] == 0) {	/* For all valid moves */
-		mademove = 1;
-		board[i] = whosemove;	/* make the move on board */
-		successor = alphabeta(board, 5 - whosemove, -best_score - 1, -alpha - 1);
-		/* Get value of the move */
-		board[i] = 0;	/* Take move back */
-		if (-successor.value > best_score) {	/* If a better score */
-			best_score = -successor.value;	/* update our score */
-			best_path = i;	/* and move */
-			if (best_score > alpha)
-				break;	/* If we've beaten alpha */
-		}		/* return immediately */
-	}
-  }
-  if (mademove) {
-	result.value = best_score;	/* Finally return best score */
-	result.path = best_path;/* and best move */
-  }
-  return(result);		/* If no move, return static result */
-}
-
-
-void draw(board)			/* Draw the board */
-int board[];
-{
-  int i, j, row;
-  static char out[] = " X  O";	/* Lookup table for character */
-
-  row = 6;
-#ifdef CURSES
-  move(row, 0);
-#endif
-  for (j = 0; j < 9; j += 3) {
-	printw(" %d | %d | %d     ", j, j + 1, j + 2);
-	for (i = 0; i < 3; i++) {
-		printw("%c ", out[board[j + i]]);
-		if (i < 2) printw("| ");
-	}
-	if (j < 4) {
-#ifdef CURSES
-		move(++row, 0);
-#else
-		printw("\n");
-#endif
-		printw("---+---+---   ---+---+---");
-	}
-#ifdef CURSES
-	move(++row, 0);
-#else
-	printw("\n");
-#endif
-  }
-#ifdef CURSES
-  refresh();
-#else
-  printw("\n");
-#endif
-}
-
-
-void getmove(board)			/* Get a player's move */
-int board[];
-{
-  int Move;
-  int ItemsRead;
-  char dumc;
-
-  do {
-	do {
-#ifdef CURSES
-		move(9, 40);
-		printw("Your move: ");	/* Prompt for move */
-		refresh();
-#else
-		printw("Your move: ");	/* Prompt for move */
-#endif
-		ItemsRead = scanf("%d", &Move);	/* Input the move */
-		if (ItemsRead == 0) scanf("%c", &dumc);	/* Remove the offending character */
-	}
-	while (ItemsRead != 1);
-  }
-  while (board[Move]);
-  board[Move] = 4;		/* If legal, add to board */
-  draw(board);			/* Draw the board */
-}
-
-
-int endofgame(board)		/* Determine end of the game */
-int board[];
-{
-  int eval;
-  int count;
-
-  eval = stateval(board, 1);
-#ifdef CURSES
-  move(20, 25);
-#endif
-  if (eval == 100) {
-	printw("I have beaten you.\n");
-	return(1);
-  }
-  if (eval == -100) {
-	printw("Bus error (core dumped)\n");
-	return(1);
-  }
-  count = 0;
-  for (eval = 0; eval < 9; eval++)
-	if (board[eval] != 0) count++;
-  if (count == 9) {
-	printw("A draw!\n");
-	return(1);
-  }
-#ifdef CURSES
-  refresh();
-#endif
-  return(0);
-}
-
-
-int randommove()
-{				/* Make an initial random move */
-  int i;
-
-  i = abs((int) time((long *) 0));
-  return(i % 9);
-}
-
-
-int main()
-{				/* The actual game */
-  int i, board[9];
-  char ch;
-  MOVE ourmove;
-
-  for (i = 0; i < 9; i++) board[i] = 0;	/* Initialise the board */
-#ifdef CURSES
-  initscr();
-  clear();
-  refresh();
-#endif
-  printw("                           TIC TAC TOE   \n\n");
-  printw("                        Your moves are 'O'\n");
-  printw("                         My moves are 'X'\n\n");
-#ifdef CURSES
-  move(5, 0);
-  printw("Do you wish to move first: ");
-  refresh();
-  while (scanf("%c", &ch) != 1);
-  move(5, 0);
-  printw("                         .......");	/* Kludge to get rid */
-  refresh();
-  move(5, 0);
-  printw("                                ");	/* of input letter */
-  refresh();
-#else
-  do
-	printw("Do you wish to move first: ");
-  while (scanf("%c", &ch) != 1);
-#endif
-  if ((ch != 'y') && (ch != 'Y')) {
-	i = randommove();	/* If we move first */
-	board[i] = 1;		/* make it random */
-#ifdef CURSES
-	move(7, 42);
-	printw("My move: %d\n", i);
-	refresh();
-#else
-	printw("My move: %d\n", i);
-#endif
-  }
-  draw(board);
-  getmove(board);
-
-  while (1) {
-	ourmove = alphabeta(board, 1, 99, -99);	/* Get a move for us;
-						 * return wins */
-	/* Immediately & ignore losses */
-	board[ourmove.path] = 1;/* and make it */
-#ifdef CURSES
-	move(7, 42);
-	printw("My move: %d\n", ourmove.path);
-	refresh();
-#else
-	printw("My move: %d\n", ourmove.path);
-#endif
-	draw(board);
-	if (endofgame(board)) break;	/* If end of game, exit */
-	getmove(board);		/* Get opponent's move */
-	if (endofgame(board)) break;	/* If end of game, exit */
-  }
-#ifdef CURSES
-  endwin();
-#endif
-  return(0);
-}
Index: trunk/minix/commands/simple/tty.c
===================================================================
--- trunk/minix/commands/simple/tty.c	(revision 9)
+++ 	(revision )
@@ -1,30 +1,0 @@
-/* tty.c - Return tty name		Author: Freeman P. Pascal IV */
-
-/* Minor changes to make tty conform to POSIX1003.2 Draft10
-   Thomas Brupbacher (tobr@mw.lpc.ethz.ch)			*/
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char *tty_name;
-
-  tty_name = ttyname(STDIN_FILENO);
-  if ((argc == 2) && (!strcmp(argv[1], "-s")))
-	 /* Do nothing - shhh! we're in silent mode */ ;
-  else
-	puts((tty_name != NULL) ? tty_name : "not a tty");
-
-  if (isatty(STDIN_FILENO) == 0)
-	return(1);
-  else
-	return(0);
-}
Index: trunk/minix/commands/simple/udpstat.c
===================================================================
--- trunk/minix/commands/simple/udpstat.c	(revision 9)
+++ 	(revision )
@@ -1,300 +1,0 @@
-/*
-udpstat.c
-
-Created:	March 2001 by Philip Homburg <philip@f-mnx.phicoh.com>
-*/
-
-#define _MINIX_SOURCE
-#define _POSIX_C_SOURCE 2
-
-#include <inet/inet.h>
-#undef printf
-
-#include <assert.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/svrctl.h>
-#ifndef __minix_vmd
-#include <sys/times.h>
-#endif
-#include <net/netlib.h>
-#include <net/gen/inet.h>
-#include <net/gen/netdb.h>
-#include <net/gen/socket.h>
-#include <minix/queryparam.h>
-
-#include <inet/generic/buf.h>
-#include <inet/generic/clock.h>
-#include <inet/generic/event.h>
-#include <inet/generic/type.h>
-#include <inet/generic/udp_int.h>
-
-char *prog_name;
-udp_fd_t udp_fd_table[UDP_FD_NR];
-udp_port_t *udp_port_table;
-udp_port_t *udp_port_tablep;
-size_t udp_port_table_s;
-size_t udp_port_table_rs;
-int udp_port_nr;
-char values[6 * sizeof(void *) + 3];
-char *valuesl= NULL;
-size_t v_size;
-int inclSel, numerical;
-
-void print_fd(int i, clock_t now);
-void usage(void);
-
-int main(int argc, char*argv[])
-{
-	char *udp_device;
-	int fd, i;
-	struct svrqueryparam qpar;
-	char *pval;
-	struct timeval uptime;
-	clock_t now;
-	int fl;
-	int a_flag, n_flag;
-
-	(prog_name=strrchr(argv[0], '/')) ? prog_name++ : (prog_name=argv[0]);
-
-	a_flag= 0;
-	n_flag= 0;
-	while ((fl= getopt(argc, argv, "?an")) != -1)
-	{
-		switch(fl)
-		{
-		case '?':
-			usage();
-		case 'a':
-			a_flag= 1;
-			break;
-		case 'n':
-			n_flag= 1;
-			break;
-		default:
-			fprintf(stderr, "%s: getopt failed: '%c'\n", 
-				prog_name, fl);
-			exit(1);
-		}
-	}
-	inclSel= !!a_flag;
-	numerical= !!n_flag;
-
-	udp_device= UDP_DEVICE;
-	if ((fd= open(udp_device, O_RDWR)) == -1)
-	{
-		fprintf(stderr, "%s: unable to open '%s': %s\n", prog_name,
-			udp_device, strerror(errno));
-		exit(1);
-	}
-
-	v_size= 2*sizeof(udp_fd_table)+1;
-	valuesl= realloc(valuesl, v_size);
-	if (!valuesl)
-	{
-		fprintf(stderr, "%s: unable to malloc %u bytes for valuesl\n",
-			prog_name, v_size);
-		exit(1);
-	}
-
-	qpar.param = "udp_fd_table";
-	qpar.psize = strlen(qpar.param);
-	qpar.value = valuesl;
-	qpar.vsize = v_size;
-	if (ioctl(fd, NWIOQUERYPARAM, &qpar) == -1)
-	{
-		fprintf(stderr, "%s: queryparam failed: %s\n", prog_name,
-			strerror(errno));
-		exit(1);
-	}
-	pval= valuesl;
-	if (paramvalue(&pval, udp_fd_table, sizeof(udp_fd_table)) !=
-		sizeof(udp_fd_table))
-	{
-		fprintf(stderr,
-	"%s: unable to decode the results from queryparam (udp_fd_table)\n",
-			prog_name);
-		exit(1);
-	}
-
-	/* Get address, size, and element size of the UDP port table */
-	qpar.param = "&udp_port_table,$udp_port_table,$udp_port_table[0]";
-	qpar.psize = strlen(qpar.param);
-	qpar.value = values;
-	qpar.vsize = sizeof(values);
-	if (ioctl(fd, NWIOQUERYPARAM, &qpar) == -1)
-	{
-		fprintf(stderr, "%s: queryparam failed: %s\n", prog_name,
-			strerror(errno));
-		exit(1);
-	}
-	pval= values;
-	if (paramvalue(&pval, &udp_port_tablep, sizeof(udp_port_tablep)) !=
-		sizeof(udp_port_tablep) ||
-		paramvalue(&pval, &udp_port_table_s, sizeof(udp_port_table_s))
-			!= sizeof(udp_port_table_s) ||
-		paramvalue(&pval, &udp_port_table_rs, sizeof(udp_port_table_rs))
-			!= sizeof(udp_port_table_rs))
-	{
-		fprintf(stderr,
-"%s: unable to decode the results from queryparam (&udp_port_table, ...)\n",
-			prog_name);
-		exit(1);
-	}
-
-	if (udp_port_table_rs != sizeof(udp_port_table[0]))
-	{
-		fprintf(stderr,
-	"%s: size mismatch in udp_port_table (different version of inet?)\n",
-			prog_name);
-		exit(1);
-	}
-	udp_port_nr= udp_port_table_s/udp_port_table_rs;
-	assert(udp_port_table_s == udp_port_nr*udp_port_table_rs);
-	udp_port_table= malloc(udp_port_table_s);
-	if (!udp_port_table)
-	{
-		fprintf(stderr,
-	"%s: unable to malloc %u bytes for udp_port_table\n",
-			prog_name, udp_port_table_s);
-		exit(1);
-	}
-	v_size= 2*udp_port_table_s+1;
-	valuesl= realloc(valuesl, v_size);
-	if (!valuesl)
-	{
-		fprintf(stderr, "%s: unable to malloc %u bytes for valuesl\n",
-			prog_name, v_size);
-		exit(1);
-	}
-
-	qpar.param = "udp_port_table";
-	qpar.psize = strlen(qpar.param);
-	qpar.value = valuesl;
-	qpar.vsize = v_size;
-	if (ioctl(fd, NWIOQUERYPARAM, &qpar) == -1)
-	{
-		fprintf(stderr, "%s: queryparam failed: %s\n", prog_name,
-			strerror(errno));
-		exit(1);
-	}
-	pval= valuesl;
-	if (paramvalue(&pval, udp_port_table, udp_port_table_s) !=
-		udp_port_table_s)
-	{
-		fprintf(stderr,
-	"%s: unable to decode the results from queryparam (udp_port_table)\n",
-			prog_name);
-		exit(1);
-	}
-
-	/* Get the uptime in clock ticks. */
-#ifdef __minix_vmd
-	if (sysutime(UTIME_UPTIME, &uptime) == -1)
-	{
-		fprintf(stderr, "%s: sysutime failed: %s\n", prog_name,
-			strerror(errno));
-		exit(1);
-	}
-	now= uptime.tv_sec * HZ + (uptime.tv_usec*HZ/1000000);
-#else	/* Minix 3 */
-	now= times(NULL);
-#endif
-
-	for (i= 0; i<UDP_FD_NR; i++)
-		print_fd(i, now);
-	exit(0);
-}
-
-void print_fd(int i, clock_t now)
-{
-	unsigned long nwuo_flags;
-	int port_nr;
-	udp_fd_t *udp_fd;
-	udp_port_t *udp_port;
-	char *locaddr_str, *remaddr_str;
-	struct hostent *hostent;
-	struct servent *servent;
-	nwio_udpopt_t uf_udpopt;
-
-	udp_fd= &udp_fd_table[i];
-	if (!(udp_fd->uf_flags & UFF_INUSE))
-		return;
-	uf_udpopt= udp_fd->uf_udpopt;
-	nwuo_flags= uf_udpopt.nwuo_flags;
-	if (((nwuo_flags & NWUO_LOCPORT_MASK) != NWUO_LP_SET) && !inclSel)
-		return;
-
-	port_nr= udp_fd->uf_port-udp_port_tablep;
-	udp_port= &udp_port_table[port_nr];
-	
-	printf("%3d", i);
-
-	if (nwuo_flags & NWUO_EN_LOC)
-	{
-		if (!numerical && (hostent=
-			gethostbyaddr((char *)&udp_port->up_ipaddr,
-			sizeof(ipaddr_t), AF_INET)) != NULL)
-		{
-			locaddr_str= hostent->h_name;
-		}
-		else
-			locaddr_str= inet_ntoa(udp_port->up_ipaddr);
-	}
-	else if (nwuo_flags & NWUO_EN_BROAD)
-		locaddr_str= "255.255.255.255";
-	else
-		locaddr_str= "0.0.0.0";
-
-	printf(" %s:", locaddr_str);
-
-	if ((nwuo_flags & NWUO_LOCPORT_MASK) != NWUO_LP_SEL &&
-		(nwuo_flags & NWUO_LOCPORT_MASK) != NWUO_LP_SET)
-	{
-		printf("*");
-	}
-	else if ((servent= getservbyport(uf_udpopt.nwuo_locport, "udp")) !=
-		NULL)
-	{
-		printf("%s", servent->s_name);
-	}
-	else
-		printf("%u", ntohs(uf_udpopt.nwuo_locport));
-
-	printf(" -> ");
-
-	if (!(nwuo_flags & NWUO_RA_SET))
-		remaddr_str= "*";
-	else if (!numerical &&
-		(hostent= gethostbyaddr((char *)&uf_udpopt.nwuo_remaddr,
-		sizeof(ipaddr_t), AF_INET)) != NULL)
-	{
-		remaddr_str= hostent->h_name;
-	}
-	else
-		remaddr_str= inet_ntoa(uf_udpopt.nwuo_remaddr);
-	printf("%s:", remaddr_str);
-
-	if (!(nwuo_flags & NWUO_RP_SET))
-		printf("*");
-	else if ((servent= getservbyport(uf_udpopt.nwuo_remport, "udp")) !=
-		NULL)
-	{
-		printf("%s", servent->s_name);
-	}
-	else
-		printf("%u", ntohs(uf_udpopt.nwuo_remport));
-	printf("\n");
-}
-
-void usage(void)
-{
-	fprintf(stderr, "Usage: %s [-a] [-n]\n", prog_name);
-	exit(1);
-}
-
-/*
- * $PchId: udpstat.c,v 1.4 2005/01/30 01:04:57 philip Exp $
- */
Index: trunk/minix/commands/simple/umount.c
===================================================================
--- trunk/minix/commands/simple/umount.c	(revision 9)
+++ 	(revision )
@@ -1,92 +1,0 @@
-/* umount - unmount a file system		Author: Andy Tanenbaum */
-
-#define _MINIX 1		/* for proto of the non-POSIX umount() */
-#define _POSIX_SOURCE 1		/* for PATH_MAX from limits.h */
-
-#include <sys/types.h>
-#include <sys/svrctl.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <limits.h>
-#include <minix/minlib.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void update_mtab, (char *devname));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void tell, (char *this));
-
-static char mountpoint[PATH_MAX+1];
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int sflag = 0;
-
-  while (argc > 1 && argv[1][0] == '-') {
-	char *opt = argv[1]+1;
-	while (*opt) if (*opt++ == 's') sflag = 1; else usage();
-	argc--;
-	argv++;
-  }
-  if (argc != 2) usage();
-  if ((sflag ? svrctl(MMSWAPOFF, NULL) : umount(argv[1])) < 0) {
-	if (errno == EINVAL)
-		std_err("Device not mounted\n");
-	else
-		perror("umount");
-	exit(1);
-  }
-  update_mtab(argv[1]);
-  tell(argv[1]);
-  tell(" unmounted");
-  if (*mountpoint != '\0') {
-	tell(" from ");
-	tell(mountpoint);
-  }
-  tell("\n");
-  return(0);
-}
-
-void update_mtab(devname)
-char *devname;
-{
-/* Remove an entry from /etc/mtab. */
-  int n;
-  char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
-
-  if (load_mtab("umount") < 0) {
-	std_err("/etc/mtab not updated.\n");
-	exit(1);
-  }
-  while (1) {
-	n = get_mtab_entry(special, mounted_on, version, rw_flag);
-	if (n < 0) break;
-	if (strcmp(devname, special) == 0) {
-		strcpy(mountpoint, mounted_on);
-		continue;
-	}
-	(void) put_mtab_entry(special, mounted_on, version, rw_flag);
-  }
-  n = rewrite_mtab("umount");
-  if (n < 0) {
-	std_err("/etc/mtab not updated.\n");
-	exit(1);
-  }
-}
-
-void usage()
-{
-  std_err("Usage: umount [-s] special\n");
-  exit(1);
-}
-
-void tell(this)
-char *this;
-{
-  write(1, this, strlen(this));
-}
Index: trunk/minix/commands/simple/uname.c
===================================================================
--- trunk/minix/commands/simple/uname.c	(revision 9)
+++ 	(revision )
@@ -1,128 +1,0 @@
-/*  uname - print system name			Author: Earl Chew */
-
-/* Print the following system information as returned by the uname()
- * function:
- *
- *	system name		Minix
- *	node name		waddles
- *	release name		1.5
- *	version			10
- *	machine name		i86
- *	arch			i86	(Minix specific)
- */
-
-#include <sys/types.h>
-#include <sys/utsname.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-/* Define the uname components. */
-#define ALL	 ((unsigned) 0x1F)
-#define SYSNAME  ((unsigned) 0x01)
-#define NODENAME ((unsigned) 0x02)
-#define RELEASE  ((unsigned) 0x04)
-#define VERSION  ((unsigned) 0x08)
-#define U_MACHINE  ((unsigned) 0x10)
-#define ARCH     ((unsigned) 0x20)
-
-_PROTOTYPE(int main, (int argc, char **argv ));
-_PROTOTYPE(void print, (int fd, ... ));
-_PROTOTYPE(void usage, (void ));
-
-#ifdef __STDC__
-void print(int fd, ...)
-#else
-void print(fd)
-int fd;
-#endif
-{
-/* Print a sequence of strings onto the named channel. */
-  va_list argp;
-  char *p;
-
-  va_start(argp, fd);
-  while (1) {
-	p = va_arg(argp, char *);
-	if (p == (char *) NULL) break;
-	write(fd, p, strlen(p));
-  }
-  va_end(argp);
-}
-
-char *name;
-
-void usage()
-{
-  print(STDERR_FILENO, "Usage: ", name, " -snrvmpa\n", (char *) NULL);
-  exit(EXIT_FAILURE);
-}
-
-int main(argc, argv)
-int argc;
-char **argv;
-{
-  int info;
-  char *p;
-  struct utsname un;
-
-  name = strrchr(argv[0], '/');
-  if (name == NULL) name = argv[0]; else name++;
-
-  for (info = 0; argc > 1; argc--, argv++) {
-  	if (argv[1][0] == '-') {
-  		for (p = &argv[1][1]; *p; p++) {
-  			switch (*p) {
-				case 'a': info |= ALL;      break;
-				case 'm': info |= U_MACHINE;  break;
-				case 'n': info |= NODENAME; break;
-				case 'r': info |= RELEASE;  break;
-				case 's': info |= SYSNAME;  break;
-				case 'v': info |= VERSION;  break;
-				case 'p': info |= ARCH;     break;
-				default: usage();
-  			}
-		}
-	} else {
-		usage();
-	}
-  }
-
-  if (info == 0) info = strcmp(name, "arch") == 0 ? ARCH : SYSNAME;
-
-  if (uname(&un) != 0) {
-	print(STDERR_FILENO, "unable to determine uname values\n", (char *) NULL);
-	exit(EXIT_FAILURE);
-  }
-
-  if ((info & SYSNAME) != 0)
-	print(STDOUT_FILENO, un.sysname, (char *) NULL);
-  if ((info & NODENAME) != 0) {
-	if ((info & (SYSNAME)) != 0)
-		print(STDOUT_FILENO, " ", (char *) NULL);
-	print(STDOUT_FILENO, un.nodename, (char *) NULL);
-  }
-  if ((info & RELEASE) != 0) {
-	if ((info & (SYSNAME|NODENAME)) != 0)
-		print(STDOUT_FILENO, " ", (char *) NULL);
-	print(STDOUT_FILENO, un.release, (char *) NULL);
-  }
-  if ((info & VERSION) != 0) {
-	if ((info & (SYSNAME|NODENAME|RELEASE)) != 0)
-		print(STDOUT_FILENO, " ", (char *) NULL);
-	print(STDOUT_FILENO, un.version, (char *) NULL);
-  }
-  if ((info & U_MACHINE) != 0) {
-	if ((info & (SYSNAME|NODENAME|RELEASE|VERSION)) != 0)
-		print(STDOUT_FILENO, " ", (char *) NULL);
-	print(STDOUT_FILENO, un.machine, (char *) NULL);
-  }
-  if ((info & ARCH) != 0) {
-	if ((info & (SYSNAME|NODENAME|RELEASE|VERSION|U_MACHINE)) != 0)
-		print(STDOUT_FILENO, " ", (char *) NULL);
-	print(STDOUT_FILENO, un.arch, (char *) NULL);
-  }
-  print(STDOUT_FILENO, "\n", (char *) NULL);
-  return EXIT_SUCCESS;
-}
Index: trunk/minix/commands/simple/unexpand.c
===================================================================
--- trunk/minix/commands/simple/unexpand.c	(revision 9)
+++ 	(revision )
@@ -1,121 +1,0 @@
-/*  unexpand - convert spaces to tabs	Author: Terrence W. Holm */
-
-/*  Usage:  unexpand  [ -a ]  [ file ... ]  */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#define  TAB   8
-
-
-int column = 0;			/* Current column, retained between files  */
-int spaces = 0;			/* Spaces since last tab stop  	    */
-int leading_blank = 1;		/* Only unexpand leading blanks,	    */
-/* Overruled by -a option	            */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void Unexpand, (FILE *f, int all));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-
-{
-  int all = 0;			/* -a flag means unexpand all spaces  */
-  int i;
-  FILE *f;
-
-  if (argc > 1 && argv[1][0] == '-') {
-	if (strcmp(argv[1], "-a") == 0)
-		all = 1;
-	else {
-		fprintf(stderr, "Usage:  unexpand  [ -a ]  [ file ... ]\n");
-		exit(1);
-	}
-
-	--argc;
-	++argv;
-  }
-  if (argc == 1)
-	Unexpand(stdin, all);
-  else
-	for (i = 1; i < argc; ++i) {
-		if ((f = fopen(argv[i], "r")) == NULL) {
-			perror(argv[i]);
-			exit(1);
-		}
-		Unexpand(f, all);
-		fclose(f);
-	}
-
-
-  /* If there are pending spaces print them.  */
-
-  while (spaces > 0) {
-	putchar(' ');
-	--spaces;
-  }
-
-  return(0);
-}
-
-void Unexpand(f, all)
-FILE *f;
-int all;
-
-{
-  int c;
-
-  while ((c = getc(f)) != EOF) {
-	if (c == ' ' && (all || leading_blank)) {
-		++column;
-		++spaces;
-
-		/* If we have white space up to a tab stop, then output	 */
-		/* A tab. If only one space is required, use a ' '.	 */
-
-		if (column % TAB == 0) {
-			if (spaces == 1)
-				putchar(' ');
-			else
-				putchar('\t');
-
-			spaces = 0;
-		}
-		continue;
-	}
-
-	/* If a tab character is encountered in the input then		*/
-	/* Simply echo it. Any accumulated spaces can only be 		*/
-	/* Since the last tab stop, so ignore them.			*/
-	if (c == '\t') {
-		column = (column / TAB + 1) * TAB;
-		spaces = 0;
-		putchar('\t');
-		continue;
-	}
-
-	/* A non-space character is to be printed. If there   */
-	/* Are pending spaces, then print them. There will be */
-	/* At most TAB-1 spaces to print.		      */
-	while (spaces > 0) {
-		putchar(' ');
-		--spaces;
-	}
-
-	if (c == '\n' || c == '\r') {
-		column = 0;
-		leading_blank = 1;
-		putchar(c);
-		continue;
-	}
-	if (c == '\b')
-		column = column > 0 ? column - 1 : 0;
-	else
-		++column;
-
-	leading_blank = 0;
-	putchar(c);
-  }
-}
Index: trunk/minix/commands/simple/uniq.c
===================================================================
--- trunk/minix/commands/simple/uniq.c	(revision 9)
+++ 	(revision )
@@ -1,195 +1,0 @@
-/* uniq - compact repeated lines		Author: John Woods */
-/* Uniq [-udc] [-n] [+n] [infile [outfile]]
- *
- *	Written 02/08/86 by John Woods, placed into public domain.  Enjoy.
- *
- */
-
-/* If the symbol WRITE_ERROR is defined, uniq will exit(1) if it gets a
- * write error on the output.  This is not (of course) how V7 uniq does it,
- * so undefine the symbol if you want to lose your output to a full disk
- */
-
-#define WRITE_ERROR 1
-#include <ctype.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-char buffer[BUFSIZ];
-int uflag = 1;			/* default is union of -d and -u outputs */
-int dflag = 1;			/* flags are mutually exclusive */
-int cflag = 0;
-int fields = 0;
-int chars = 0;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(FILE *xfopen, (char *fn, char *mode));
-_PROTOTYPE(char *skip, (char *s));
-_PROTOTYPE(int equal, (char *s1, char *s2));
-_PROTOTYPE(void show, (char *line, int count));
-_PROTOTYPE(int uniq, (void));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(int getline, (char *buf, int count));
-
-FILE *xfopen(fn, mode)
-char *fn, *mode;
-{
-  FILE *p;
-
-  if ((p = fopen(fn, mode)) == NULL) {
-	perror("uniq");
-	fflush(stdout);
-	exit(1);
-  }
-  return(p);
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char *p;
-  int inf = -1, outf;
-
-  setbuf(stdout, buffer);
-  for (--argc, ++argv; argc > 0 && (**argv == '-' || **argv == '+');
-       --argc, ++argv) {
-	if (**argv == '+')
-		chars = atoi(*argv + 1);
-	else if (isdigit(argv[0][1]))
-		fields = atoi(*argv + 1);
-	else if (argv[0][1] == '\0')
-		inf = 0;	/* - is stdin */
-	else
-		for (p = *argv + 1; *p; p++) {
-			switch (*p) {
-			    case 'd':
-				dflag = 1;
-				uflag = 0;
-				break;
-			    case 'u':
-				uflag = 1;
-				dflag = 0;
-				break;
-			    case 'c':	cflag = 1;	break;
-			    default:	usage();
-			}
-		}
-  }
-
-  /* Input file */
-  if (argc == 0)
-	inf = 0;
-  else if (inf == -1) {		/* if - was not given */
-	fclose(stdin);
-	xfopen(*argv++, "r");
-	argc--;
-  }
-  if (argc == 0)
-	outf = 1;
-  else {
-	fclose(stdout);
-	xfopen(*argv++, "w");
-	argc--;
-  }
-
-  uniq();
-  fflush(stdout);
-  return(0);
-}
-
-char *skip(s)
-char *s;
-{
-  int n;
-
-  /* Skip fields */
-  for (n = fields; n > 0; --n) {
-	/* Skip blanks */
-	while (*s && (*s == ' ' || *s == '\t')) s++;
-	if (!*s) return s;
-	while (*s && (*s != ' ' && *s != '\t')) s++;
-	if (!*s) return s;
-  }
-
-  /* Skip characters */
-  for (n = chars; n > 0; --n) {
-	if (!*s) return s;
-	s++;
-  }
-  return s;
-}
-
-int equal(s1, s2)
-char *s1, *s2;
-{
-  return !strcmp(skip(s1), skip(s2));
-}
-
-void show(line, count)
-char *line;
-int count;
-{
-  if (cflag)
-	printf("%4d %s", count, line);
-  else {
-	if ((uflag && count == 1) || (dflag && count != 1))
-		printf("%s", line);
-  }
-}
-
-/* The meat of the whole affair */
-char *nowline, *prevline, buf1[1024], buf2[1024];
-
-int uniq()
-{
-  char *p;
-  int seen;
-
-  /* Setup */
-  prevline = buf1;
-  if (getline(prevline, 1024) < 0) return(0);
-  seen = 1;
-  nowline = buf2;
-
-  /* Get nowline and compare if not equal, dump prevline and swap
-   * pointers else continue, bumping seen count */
-  while (getline(nowline, 1024) > 0) {
-	if (!equal(prevline, nowline)) {
-		show(prevline, seen);
-		seen = 1;
-		p = nowline;
-		nowline = prevline;
-		prevline = p;
-	} else
-		seen += 1;
-  }
-  show(prevline, seen);
-  return 0;
-}
-
-void usage()
-{
-  fprintf(stderr, "Usage: uniq [-udc] [+n] [-n] [input [output]]\n");
-}
-
-int getline(buf, count)
-char *buf;
-int count;
-{
-  int c;
-  int ct = 0;
-
-  while (ct++ < count) {
-	c = getc(stdin);
-	if (c < 0) return(-1);
-	*buf++ = c;
-	if (c == '\n') {
-		*buf++ = 0;
-		return(ct);
-	}
-  }
-  return(ct);
-}
Index: trunk/minix/commands/simple/update.c
===================================================================
--- trunk/minix/commands/simple/update.c	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-/* update - do sync periodically		Author: Andy Tanenbaum */
-
-#include <sys/types.h>
-#include <signal.h>
-#include <unistd.h>
-
-_PROTOTYPE(int main, (void));
-
-int main()
-{
-  /* Release all (?) open file descriptors. */
-  close(0);
-  close(1);
-  close(2);
-
-  /* Release current directory to avoid locking current device. */
-  chdir("/");
-
-  /* Flush the cache every 30 seconds. */
-  while (1) {
-	sync();
-	sleep(30);
-  }
-}
Index: trunk/minix/commands/simple/uud.c
===================================================================
--- trunk/minix/commands/simple/uud.c	(revision 9)
+++ 	(revision )
@@ -1,562 +1,0 @@
-/* uud - bulletproof version of uudecode */
-
-/*
- * Uud -- decode a uuencoded file back to binary form.
- *
- * From the Berkeley original, modified by MSD, RDR, JPHD & WLS.
- * The Atari GEMDOS version compiled with MWC 2.x.
- * The MSDOS version with TurboC.
- * The Unix version with cc.
- * this version is made: 25 Nov 1988.
- * Jan 2 1990: Change system definition and change MSDOS to open the output
- *             file for write binary do cr/lf replacement.
- */
-
-#define UNIX  1		/* define one of: UNIX (Minix too!), MSDOS, or GEMDOS */ 
-
-#ifdef GEMDOS
-#define SYSNAME "gemdos"
-#define SMALL 1
-#endif
-#ifdef MSDOS
-#define SYSNAME "msdos"
-#define SMALL 1
-#endif
-#ifdef UNIX
-#define SYSNAME "unix"
-#endif
-
-#include <sys/types.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <stdio.h>
-
-#ifdef GEMDOS
-#include <osbind.h>
-#define Error(n)  { Bconin(2); exit(n); }
-#else
-#define Error(n)  exit(n)
-#endif
-#ifdef UNIX
-#define WRITE	  "w"
-#else
-#define WRITE	  "wb"		/* for both MSDOS and GEMDOS!	*/
-#endif
-
-#define loop	while (1)
-
-#define NCHARS  256
-#define LINELEN 256
-#define FILELEN 64
-#define NORMLEN 60	/* allows for 80 encoded chars per line */
-
-#define SEQMAX 'z'
-#define SEQMIN 'a'
-char seqc;
-int first, secnd, check, numl;
-
-FILE *in, *out;
-char *pos;
-char ifname[FILELEN], ofname[FILELEN];
-char *source = NULL, *target = NULL;
-char blank, part = '\0';
-int partn, lens;
-int debug = 0, nochk = 0, onedone = 0;
-int chtbl[NCHARS], cdlen[NORMLEN + 3];
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(char *getnword, (char *str, int n));
-_PROTOTYPE(void gettable, (void));
-_PROTOTYPE(void decode, (void));
-_PROTOTYPE(void getfile, (char *buf));
-_PROTOTYPE(void format, (char *fp, ...));
-_PROTOTYPE(void doprnt, (char *fp, char *ap));
-_PROTOTYPE(void puti, (unsigned int i, unsigned int r));
-_PROTOTYPE(void outc, (int c));
-
-int main(argc, argv) int argc; char *argv[];
-{
-	int mode;
-	register int i, j;
-	char *curarg;
-	char dest[FILELEN], buf[LINELEN];
-
-	while ((curarg = argv[1]) != NULL && curarg[0] == '-') {
-		if (((curarg[1] == 'd') || (curarg[1] == 'D')) &&
-		    (curarg[2] == '\0')) {
-			debug = 1;
-		} else if (((curarg[1] == 'n') || (curarg[1] == 'N')) &&
-			   (curarg[2] == '\0')) {
-			nochk = 1;
-		} else if (((curarg[1] == 't') || (curarg[1] == 'T')) &&
-			   (curarg[2] == '\0')) {
-			argv++;
-			argc--;
-			if (argc < 2) {
-				format("uud: Missing target directory.\n");
-				Error(15);
-			}
-			target = argv[1];
-			if (debug)
-				format("Target dir = %s\n",target);
-		} else if (((curarg[1] == 's') || (curarg[1] == 'S')) &&
-			   (curarg[2] == '\0')) {
-			argv++;
-			argc--;
-			if (argc < 2) {
-				format("uud: Missing source directory.\n");
-				Error(15);
-			}
-			source = argv[1];
-			if (debug)
-				format("Source dir = %s\n",source);
-		} else if (curarg[1] != '\0') {
-			format("Usage: uud [-n] [-d] [-s dir] [-t dir] [input-file]\n");
-			Error(1);
-		} else
-			break;
-		argv++;
-		argc--;
-	}
-
-	if (curarg == NULL || ((curarg[0] == '-') && (curarg[1] == '\0'))) {
-		in = stdin;
-		strcpy(ifname, "<stdin>");
-	} else {
-		if (source != NULL) {
-			strcpy(ifname, source);
-			strcat(ifname, curarg);
-		} else
-			strcpy(ifname, curarg);
-		if ((in = fopen(ifname, "r")) == NULL) {
-			format("uud: Can't open %s\n", ifname);
-			Error(2);
-		}
-		numl = 0;
-	}
-
-/*
- * Set up the default translation table.
- */
-	for (i = 0; i < ' '; i++) chtbl[i] = -1;
-	for (i = ' ', j = 0; i < ' ' + 64; i++, j++) chtbl[i] = j;
-	for (i = ' ' + 64; i < NCHARS; i++) chtbl[i] = -1;
-	chtbl['`'] = chtbl[' '];	/* common mutation */
-	chtbl['~'] = chtbl['^'];	/* an other common mutation */
-	blank = ' ';
-/*
- * set up the line length table, to avoid computing lotsa * and / ...
- */
-	cdlen[0] = 1;
-	for (i = 1, j = 5; i <= NORMLEN; i += 3, j += 4)
-		cdlen[i] = (cdlen[i + 1] = (cdlen[i + 2] = j));
-/*
- * search for header or translation table line.
- */
-	loop {	/* master loop for multiple decodes in one file */
-		partn = 'a';
-		loop {
-			if (fgets(buf, sizeof buf, in) == NULL) {
-				if (onedone) {
-					if (debug) format("End of file.\n");
-					exit(0);
-				} else {
-					format("uud: No begin line.\n");
-					Error(3);
-				}
-			}
-			numl++;
-			if (strncmp(buf, "table", (size_t)5) == 0) {
-				gettable();
-				continue;
-			}
-			if (strncmp(buf, "begin", (size_t)5) == 0) {
-				break;
-			}
-		}
-		lens = strlen(buf);
-		if (lens) buf[--lens] = '\0';
-#ifdef SMALL
-		if ((pos = getnword(buf, 3))) {
-			strcpy(dest, pos);
-		} else
-#else
-		if(sscanf(buf,"begin%o%s", &mode, dest) != 2)
-#endif
-		{
-			format("uud: Missing filename in begin line.\n");
-			Error(10);
-		}
-
-		if (target != NULL) {
-			strcpy(ofname, target);
-			strcat(ofname, dest);
-		} else
-			strcpy(ofname, dest);
-
-		if((out = fopen(ofname, WRITE)) == NULL) {
-			format("uud: Cannot open output file: %s\n", ofname);
-			Error(4);
-		}
-		if (debug) format("Begin uudecoding: %s\n", ofname);
-		seqc = SEQMAX;
-		check = nochk ? 0 : 1;
-		first = 1;
-		secnd = 0;
-		decode();
-		fclose(out);
-#ifdef UNIX
-		chmod(ofname, mode);
-#endif
-		onedone = 1;
-		if (debug) format("End uudecoding: %s\n", ofname);
-	}	/* master loop for multiple decodes in one file */
-}
-
-/*
- * Bring back a pointer to the start of the nth word.
- */
-char *getnword(str, n) register char *str; register int n;
-{
-	while((*str == '\t') || (*str == ' ')) str++;
-	if (! *str) return NULL;
-	while(--n) {
-		while ((*str != '\t') && (*str != ' ') && (*str)) str++;
-		if (! *str) return NULL;
-		while((*str == '\t') || (*str == ' ')) str++;
-		if (! *str) return NULL;
-	}
-	return str;
-}
-
-/*
- * Install the table in memory for later use.
- */
-void gettable()
-{
-	char buf[LINELEN];
-	register int c, n = 0;
-	register char *cpt;
-
-	for (c = 0; c < NCHARS; c++) chtbl[c] = -1;
-
-again:	if (fgets(buf, sizeof buf, in) == NULL) {
-		format("uud: EOF while in translation table.\n");
-		Error(5);
-	}
-	numl++;
-	if (strncmp(buf, "begin", (size_t)5) == 0) {
-		format("uud: Incomplete translation table.\n");
-		Error(6);
-	}
-	cpt = buf + strlen(buf) - 1;
-	*cpt = ' ';
-	while (*(cpt) == ' ') {
-		*cpt = 0;
-		cpt--;
-	}
-	cpt = buf;
-	while (c = *cpt) {
-		if (chtbl[c] != -1) {
-			format("uud: Duplicate char in translation table.\n");
-			Error(7);
-		}
-		if (n == 0) blank = c;
-		chtbl[c] = n++;
-		if (n >= 64) return;
-		cpt++;
-	}
-	goto again;
-}
-
-/*
- * copy from in to out, decoding as you go along.
- */
-
-void decode()
-{
-	char buf[LINELEN], outl[LINELEN];
-	register char *bp, *ut;
-	register int *trtbl = chtbl;
-	register int n, c, rlen;
-	register unsigned int len;
-
-	loop {
-		if (fgets(buf, sizeof buf, in) == NULL) {
-			format("uud: EOF before end.\n");
-			fclose(out);
-			Error(8);
-		}
-		numl++;
-		len = strlen(buf);
-		if (len) buf[--len] = '\0';
-/*
- * Is it an unprotected empty line before the end line ?
- */
-		if (len == 0) continue;
-/*
- * Get the binary line length.
- */
-		n = trtbl[*buf];
-		if (n >= 0) goto decod;
-/*
- * end of uuencoded file ?
- */
-		if (strncmp(buf, "end", (size_t)3) == 0) return;
-/*
- * end of current file ? : get next one.
- */
-		if (strncmp(buf, "include", (size_t)7) == 0) {
-			getfile(buf);
-			continue;
-		}
-		format("uud: Bad prefix line %d in file: %s\n",numl, ifname);
-		if (debug) format("Bad line =%s\n",buf);
-		Error(11);
-/*
- * Sequence checking ?
- */
-decod:		rlen = cdlen[n];
-/*
- * Is it the empty line before the end line ?
- */
-		if (n == 0) continue;
-/*
- * Pad with blanks.
- */
-		for (bp = &buf[c = len];
-			c < rlen; c++, bp++) *bp = blank;
-/*
- * Verify if asked for.
- */
-		if (debug) {
-			for (len = 0, bp = buf; len < rlen; len++) {
-				if (trtbl[*bp] < 0) {
-					format(
-	"Non uuencoded char <%c>, line %d in file: %s\n", *bp, numl, ifname);
-					format("Bad line =%s\n",buf);
-					Error(16);
-				}
-				bp++;
-			}
-		}
-/*
- * All this just to check for uuencodes that append a 'z' to each line....
- */
-		if (secnd && check) {
-			secnd = 0;
-			if (buf[rlen] == SEQMAX) {
-				check = 0;
-				if (debug) format("Sequence check turned off (2).\n");
-			} else
-				if (debug) format("Sequence check on (2).\n");
-		} else if (first && check) {
-			first = 0;
-			secnd = 1;
-			if (buf[rlen] != SEQMAX) {
-				check = 0;
-				if (debug) format("No sequence check (1).\n");
-			} else
-				if (debug) format("Sequence check on (1).\n");
-		}
-/*
- * There we check.
- */
-		if (check) {
-			if (buf[rlen] != seqc) {
-				format("uud: Wrong sequence line %d in %s\n",
-					numl, ifname);
-				if (debug)
-					format(
-	"Sequence char is <%c> instead of <%c>.\n", buf[rlen], seqc);
-				Error(18);
-			}
-			seqc--;
-			if (seqc < SEQMIN) seqc = SEQMAX;
-		}
-/*
- * output a group of 3 bytes (4 input characters).
- * the input chars are pointed to by p, they are to
- * be output to file f.n is used to tell us not to
- * output all of them at the end of the file.
- */
-		ut = outl;
-		len = n;
-		bp = &buf[1];
-		while (n > 0) {
-			*(ut++) = trtbl[*bp] << 2 | trtbl[bp[1]] >> 4;
-			n--;
-			if (n) {
-				*(ut++) = (trtbl[bp[1]] << 4) |
-					  (trtbl[bp[2]] >> 2);
-				n--;
-			}
-			if (n) {
-				*(ut++) = trtbl[bp[2]] << 6 | trtbl[bp[3]];
-				n--;
-			}
-			bp += 4;
-		}
-		if ((n = fwrite(outl, (size_t)1, (size_t)len, out)) <= 0) {
-			format("uud: Error on writing decoded file.\n");
-			Error(18);
-		}
-	}
-}
-
-/*
- * Find the next needed file, if existing, otherwise try further
- * on next file.
- */
-void getfile(buf) register char *buf;
-{
-	if ((pos = getnword(buf, 2)) == NULL) {
-		format("uud: Missing include file name.\n");
-		Error(17);
-	} else
-		if (source != NULL) {
-			strcpy(ifname, source);
-			strcat(ifname, pos);
-		} else
-			strcpy(ifname, pos);
-#ifdef GEMDOS
-	if (Fattrib(ifname, 0, 0) < 0)
-#else
-	if (access(ifname, 04))
-#endif
-	{
-		if (debug) {
-			format("Cant find: %s\n", ifname);
-			format("Continuing to read same file.\n");
-		}
-	}
-	else {
-		if (freopen(ifname, "r", in) == in) {
-			numl = 0;
-			if (debug) 
-				format("Reading next section from: %s\n", ifname);
-		} else {
-			format("uud: Freopen abort: %s\n", ifname);
-			Error(9);
-		}
-	}
-	loop {
-		if (fgets(buf, LINELEN, in) == NULL) {
-			format("uud: No begin line after include: %s\n", ifname);
-			Error(12);
-		}
-		numl++;
-		if (strncmp(buf, "table", (size_t)5) == 0) {
-			gettable();
-			continue;
-		}
-		if (strncmp(buf, "begin", (size_t)5) == 0) break;
-	}
-	lens = strlen(buf);
-	if (lens) buf[--lens] = '\0';
-/*
- * Check the part suffix.
- */
-	if ((pos = getnword(buf, 3)) == NULL ) {
-		format("uud: Missing part name, in included file: %s\n", ifname);
-		Error(13);
-	} else {
-		part = *pos;
-		partn++;
-		if (partn > 'z') partn = 'a';
-		if (part != partn) {
-			format("uud: Part suffix mismatch: <%c> instead of <%c>.\n",
-				part, partn);
-			Error(14);
-		}
-		if (debug) format("Reading part %c\n", *pos);
-	}
-}
-
-/*
- * Printf style formatting. (Borrowed from MicroEmacs by Dave Conroy.) 
- * A lot smaller than the full fledged printf.
- */
-#ifdef __STDC__
-void format(char *fp, ...)
-{
-  va_list args;
-
-  va_start (args, fp);
-  doprnt(fp, (char *)&args);
-  va_end(args);
-}
-#else
-/* VARARGS1 */
-void format(fp, args) char *fp;
-{
-	doprnt(fp, (char *)&args);
-}
-#endif
-
-void doprnt(fp, ap)
-register char	*fp;
-register char	*ap;
-{
-	register int	c, k;
-	register char	*s;
-
-	while ((c = *fp++) != '\0') {
-		if (c != '%')
-			outc(c);
-		else {
-			c = *fp++;
-			switch (c) {
-			case 'd':
-				puti(*(int *)ap, 10);
-				ap += sizeof(int);
-				break;
-
-			case 's':
-				s = *(char **)ap;
-				while ((k = *s++) != '\0')
-					outc(k);
-				ap += sizeof(char *);
-				break;
-
-			case 'c':
-				outc(*(int *)ap);
-				ap += sizeof(int);
-				break;
-
-			default:
-				outc(c);
-			}
-		}
-	}
-}
-
-/*
- * Put integer, in radix "r".
- */
-void puti(i, r)
-register unsigned int	i;
-register unsigned int	r;
-{
-	register unsigned int	q, s;
-
-	if ((q = i / r) != 0)
-		puti(q, r);
-	s = i % r;
-	if (s <= 9)
-		outc(s + '0');
-	else
-		outc(s - 10 + 'A');
-}
-void outc(c) register char c;
-{
-#ifdef GEMDOS
-	if (c == '\n') Bconout(2, '\r');
-	Bconout(2, c);
-#else
-	putchar(c);
-#endif
-}
Index: trunk/minix/commands/simple/uue.c
===================================================================
--- trunk/minix/commands/simple/uue.c	(revision 9)
+++ 	(revision )
@@ -1,217 +1,0 @@
-/* uue - bulletproof version of uuencode */
-
-/* Uue -- encode a file so that it's printable ascii, short lines
- *
- * Slightly modified from a version posted to net.sources a while back,
- * and suitable for compilation on the IBM PC
- *
- * modified for Lattice C on the ST - 11.05.85 by MSD
- * modified for ALCYON on the ST -    10-24-86 by RDR
- * modified a little more for MWC...  02/09/87 by JPHD
- * (An optional first argument of the form: -nnumber (e.g. -500), will
- * produce a serie of files that long, linked by the include statement,
- * such files are automatically uudecoded by the companion program.)
- * More mods, - ...		   05/06/87 by jphd
- * Mods for TOPS 20, and more.     08/06/87 by jphd
- *     (remove freopen and rindex...change filename generation...)
- * (A lot more to do about I/O speed, avoiding completely the stdio.h...)
- * May be called as uuencode.       Oct 2 1993 by Kees J. Bot
- *
- */
-
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#define USAGE
-#define FILE_NAME 10		/* affects how long names are truncated */
-
-/* ENC is the basic 1 character encoding function to make a char printing */
-#define ENC(c) (((c) & 077) + ' ')
-
-FILE *fp, *outp;
-char ofname[80];
-int lenofname;
-int stdo = 0;
-
-#ifdef ST
-#define READ "rb"
-#else
-#define READ "r"
-#endif
-
-int part = 'a', chap = 'a';
-#define SEQMAX 'z'
-#define SEQMIN 'a'
-char seqc = SEQMAX;
-
-int split = 0;
-int fileln = 32000;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void maketable, (void));
-_PROTOTYPE(void makename, (void));
-_PROTOTYPE(void encode, (void));
-_PROTOTYPE(void outdec, (char *p));
-_PROTOTYPE(int fr, (char *buf, int cnt));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  char *prog_name;
-  char *fname;
-  int filter;
-
-  prog_name = argv[0] + strlen(argv[0]);
-  while (prog_name > argv[0] && prog_name[-1] != '/') prog_name--;
-  filter = strcmp(prog_name, "uuencode") == 0;
-
-  if (argc < 2) {
-	fprintf(stderr, "Usage: %s [-n] inputfile [-]\n", prog_name);
-	exit(2);
-  }
-  if (argv[1][0] == '-') {
-	fileln = -atoi(argv[1]);
-	if (fileln <= 0) {
-		fprintf(stderr, "Wrong file length arg.\n");
-		exit(3);
-	}
-	split = 1;
-	argv++;
-	argc--;
-  }
-  if (filter) {		/* old uuencode reads from standard input */
-	fp = stdin;
-  } else {
-	if ((fp = fopen(argv[1], READ)) == NULL) {	/* binary input !!! */
-		fprintf(stderr, "Cannot open %s\n", argv[1]);
-		exit(1);
-	}
-  }
-  fname = argv[1] + strlen(argv[1]);
-  while (fname > argv[1] && fname[-1] != '/') fname--;
-  strcpy(ofname, fname);
-  fname = ofname;
-  do {
-	if (*fname == '.') *fname = '\0';
-  } while (*fname++);
-  /* 10 char prefix + .uue -> 14 chars MAX */
-  lenofname = strlen(ofname);
-  if (lenofname > FILE_NAME) ofname[FILE_NAME] = '\0';
-  strcat(ofname, ".uue");
-  lenofname = strlen(ofname);
-  if (!split && (filter || (argc > 2) && (argv[2][0] == '-'))) {
-	stdo = 1;
-	outp = stdout;
-  } else {
-	makename();
-	if ((outp = fopen(ofname, "w")) == NULL) {
-		fprintf(stderr, "Cannot open %s\n", ofname);
-		exit(1);
-	}
-  }
-  maketable();
-  fprintf(outp, "begin %o %s\n", 0644, argv[1]);
-  encode();
-  fprintf(outp, "end\n");
-  fclose(outp);
-  return(0);
-}
-
-/* Create ASCII table so a mailer can screw it up and the decode
- * program can restore the error.
- */
-void maketable()
-{
-  register int i, j;
-
-  fputs("table\n", outp);
-  for (i = ' ', j = 0; i < '`'; j++) {
-	if (j == 32) putc('\n', outp);
-	fputc(i++, outp);
-  }
-  putc('\n', outp);
-}
-
-/* Generate the names needed for single and multiple part encoding.  */
-void makename()
-{
-  if (split) {
-	ofname[lenofname - 1] = part;
-	ofname[lenofname - 2] = chap;
-  }
-}
-
-/* Copy from in to out, encoding as you go along.  */
-void encode()
-{
-  char buf[80];
-  register int i, n;
-  register int lines;
-  lines = 6;
-
-  for (;;) {
-	n = fr(buf, 45);
-	putc(ENC(n), outp);
-	for (i = 0; i < n; i += 3) outdec(&buf[i]);
-	putc(seqc, outp);
-	seqc--;
-	if (seqc < SEQMIN) seqc = SEQMAX;
-	putc('\n', outp);
-	++lines;
-	if (split && (lines > fileln)) {
-		part++;
-		if (part > 'z') {
-			part = 'a';
-			if (chap == 'z')
-				chap = 'a';	/* loop ... */
-			else
-				chap++;
-		}
-		makename();
-		fprintf(outp, "include %s\n", ofname);
-		fclose(outp);
-		if ((outp = fopen(ofname, "w")) == NULL) {
-			fprintf(stderr, "Cannot open %s\n", ofname);
-			exit(1);
-		}
-		maketable();
-		fprintf(outp, "begin part %c %s\n", part, ofname);
-		lines = 6;
-	}
-	if (n <= 0) break;
-  }
-}
-
-/* Output one group of 3 bytes, pointed at by p, on file f.  */
-void outdec(p)
-register char *p;
-{
-  register int c1, c2, c3, c4;
-
-  c1 = *p >> 2;
-  c2 = ((*p << 4) & 060) | ((p[1] >> 4) & 017);
-  c3 = ((p[1] << 2) & 074) | ((p[2] >> 6) & 03);
-  c4 = p[2] & 077;
-  putc(ENC(c1), outp);
-  putc(ENC(c2), outp);
-  putc(ENC(c3), outp);
-  putc(ENC(c4), outp);
-}
-
-/* Fr: like read but stdio */
-int fr(buf, cnt)
-register char *buf;
-register int cnt;
-{
-  register int c, i;
-  for (i = 0; i < cnt; i++) {
-	c = fgetc(fp);
-	if (feof(fp)) return(i);
-	buf[i] = c;
-  }
-  return(cnt);
-}
Index: trunk/minix/commands/simple/vol.c
===================================================================
--- trunk/minix/commands/simple/vol.c	(revision 9)
+++ 	(revision )
@@ -1,371 +1,0 @@
-/* vol - break stdin into volumes	Author: Andy Tanenbaum */
-
-/* This program reads standard input and writes it onto diskettes, pausing
- * at the start of each one.  It's main use is for saving files that are
- * larger than a single diskette.  Vol just writes its standard input onto
- * a diskette, and prompts for a new one when it is full.  This mechanism
- * is transparent to the process producing vol's standard input. For example,
- *	tar cf - . | vol -w 360 /dev/fd0
- * puts the tar output as as many diskettes as needed.  To read them back in,
- * use
- *	vol -r 360 /dev/fd0 | tar xf -
- *
- * Changed 17 Nov 1993 by Kees J. Bot to handle buffering to slow devices.
- * Changed 27 Jul 1994 by Kees J. Bot to auto discover data direction + -rw.
- * Changed 19 Sep 1995 by Kees J. Bot to do better buffering to tapes.
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <limits.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/mtio.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-
-/* Preferred block size to variable block length tapes, block devices or files.
- */
-#define VAR_BLKSIZ	   8192
-
-/* Required block size multiple of fixed block size tapes (usually updated by
- * 'mt status' data) and character devices.
- */
-#define FIX_BLKSIZ	    512
-
-/* Maximum multiple block size. */
-#if __minix_vmd
-#define MULT_MAX	1048576
-#else
-#define MULT_MAX	((ssize_t) (SSIZE_MAX < 65536L ? SSIZE_MAX : 65536L))
-#endif
-
-char *buffer = NULL;
-size_t block_size = 0, mult_max = 0;
-size_t buffer_size;
-long volume_size;
-char *str_vol_size;
-int rflag = 0, wflag = 0, oneflag = 0, variable = 0;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(long str2size, (char *name, char *str, long min, long max,
-							int assume_kb));
-_PROTOTYPE(void tape_inquire, (char *name, int fd));
-_PROTOTYPE(void allocate_buffer, (void));
-_PROTOTYPE(void diskio, (int fd1, int fd2, char *file1, char *file2));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int volume = 1, fd, tty, i, init, autovolsize;
-  char *p, *name;
-  struct stat stb;
-  struct partition part;
-  char key;
-
-  /* Fetch and verify the arguments. */
-  i = 1;
-  while (i < argc && argv[i][0] == '-') {
-	p = argv[i++] + 1;
-	if (p[0] == '-' && p[1] == 0) {
-		/* -- */
-		i++;
-		break;
-	}
-	while (*p != '\0') {
-		switch (*p++) {
-		case 'r':
-		case 'u':
-			rflag = 1;
-			break;
-		case 'w':
-			wflag = 1;
-			break;
-		case '1':
-			oneflag = 1;
-			break;
-		case 'b':
-			if (*p == 0) {
-				if (i == argc) usage();
-				p = argv[i++];
-			}
-			block_size = str2size("block", p,
-						1L, (long) SSIZE_MAX, 0);
-			p= "";
-			break;
-		case 'm':
-			if (*p == 0) {
-				if (i == argc) usage();
-				p = argv[i++];
-			}
-			mult_max = str2size("maximum", p,
-						1L, (long) SSIZE_MAX, 0);
-			p= "";
-			break;
-		default:
-			usage();
-		}
-	}
-  }
-  if (i < argc - 1) {
-	str_vol_size = argv[i++];
-	volume_size = str2size("volume", str_vol_size, 1L, LONG_MAX, 1);
-	autovolsize = 0;
-  } else {
-	volume_size = 0;	/* unlimited (long tape) or use DIOCGETP */
-	autovolsize = 1;
-  }
-
-  if (i >= argc) usage();
-  name = argv[i];
-
-  if (!rflag && !wflag) {
-	/* Auto direction.  If there is a terminal at one side then data is
-	 * to go out at the other side.
-	 */
-	if (isatty(0)) rflag = 1;
-	if (isatty(1)) wflag = 1;
-  }
-
-  if (rflag == wflag) {
-	fprintf(stderr, "vol: should %s be read or written?\n", name);
-	usage();
-  }
-
-  if (stat(name, &stb) < 0) {
-	fprintf(stderr, "vol: %s: %s\n", name, strerror(errno));
-	exit(1);
-  }
-  if (!S_ISBLK(stb.st_mode) && !S_ISCHR(stb.st_mode)) {
-	fprintf(stderr, "vol: %s is not a device\n", name);
-	exit(1);
-  }
-  variable = !S_ISCHR(stb.st_mode);
-
-  if (!oneflag) {
-	tty = open("/dev/tty", O_RDONLY);
-	if (tty < 0) {
-		fprintf(stderr, "vol: cannot open /dev/tty\n");
-		exit(1);
-	}
-  }
-
-  /* Buffer initializations are yet to be done. */
-  init = 0;
-
-  while (1) {
-	sleep(1);
-	if (oneflag) {
-		if (volume != 1) {
-			if (rflag) exit(0);
-			fprintf(stderr,
-				"vol: can't continue, volume is full\n");
-			exit(1);
-		}
-	} else {
-		fprintf(stderr,
-			"\007Please insert %sput volume %d and hit return\n",
-			rflag ? "in" : "out", volume);
-		while (read(tty, &key, sizeof(key)) == 1 && key != '\n') {}
-	}
-
-	/* Open the special file. */
-	fd = open(name, rflag ? O_RDONLY : O_WRONLY);
-	if (fd < 0) {
-		fprintf(stderr, "vol: %s: %s\n", name, strerror(errno));
-		exit(1);
-	}
-
-	if (!init) {
-		/* Ask for the tape block size and allocate a buffer. */
-		if (S_ISCHR(stb.st_mode)) tape_inquire(name, fd);
-		allocate_buffer();
-		init = 1;
-	}
-
-	if (autovolsize) {
-		/* Ask the driver how big the volume is. */
-		if (ioctl(fd, DIOCGETP, &part) < 0) {
-			autovolsize = 0;
-		} else {
-			volume_size = cv64ul(part.size);
-		}
-	}
-
-	/* Read or write the requisite number of blocks. */
-	if (rflag) {
-		diskio(fd, 1, name, "stdout");	/* vol -r | tar xf - */
-	} else {
-		diskio(0, fd, "stdin", name);	/* tar cf - | vol -w */
-	}
-	close(fd);
-	volume++;
-  }
-}
-
-void usage()
-{
-  fprintf(stderr,
-	"Usage: vol [-rw1] [-b blocksize] [-m max] [size] block-special\n");
-  exit(1);
-}
-
-long str2size(name, str, min, max, assume_kb)
-char *name;
-char *str;
-long min, max;
-int assume_kb;
-{
-  /* Convert a string to a size.  The number may be followed by 'm', 'k', 'b'
-   * or 'w' to multiply the size as shown below.  If 'assume_kb' is set then
-   * kilobytes is the default.
-   */
-  long size, factor;
-  char *ptr;
-  int bad;
-
-  errno = 0;
-  size = strtol(str, &ptr, 10);
-  bad = (errno != 0 || ptr == str || size < min || size > max);
-  if (*ptr == 0 && assume_kb) ptr = "k";
-  while (!bad && *ptr != 0) {
-	switch (*ptr++) {
-	case 'm':
-	case 'M':
-		factor = 1024*1024L; break;
-	case 'k':
-	case 'K':
-		factor = 1024; break;
-	case 'b':
-	case 'B':
-		factor = 512; break;
-	case 'w':
-	case 'W':
-		factor = 2; break;
-	default:
-		factor = 1; bad = 1;
-	}
-	if (size <= max / factor) size *= factor; else bad = 1;
-  }
-  if (bad) {
-	fprintf(stderr, "vol: bad %s size '%s'\n", name, str);
-	exit(1);
-  }
-  return size;
-}
-
-void tape_inquire(name, fd)
-char *name;
-int fd;
-{
-  /* If the device happens to be a tape, then what is its block size? */
-  struct mtget mtget;
-
-  if (ioctl(fd, MTIOCGET, &mtget) < 0) {
-	if (errno != ENOTTY) {
-		fprintf(stderr, "vol: %s: %s\n", name,
-					strerror(errno));
-		exit(1);
-	}
-  } else {
-	if (mtget.mt_blksize > SSIZE_MAX) {
-		fprintf(stderr,
-		"vol: %s: tape block size (%lu) is too large to handle\n",
-			name, (unsigned long) mtget.mt_blksize);
-		exit(1);
-	}
-	if (mtget.mt_blksize == 0) {
-		variable = 1;
-	} else {
-		/* fixed */
-		block_size = mtget.mt_blksize;
-	}
-  }
-}
-
-void allocate_buffer()
-{
-  /* Set block size and maximum multiple. */
-  if (block_size == 0) block_size = variable ? 1 : FIX_BLKSIZ;
-  if (mult_max == 0) mult_max = variable ? VAR_BLKSIZ : MULT_MAX;
-
-  /* Stretch the buffer size to the max. */
-  buffer_size = mult_max / block_size * block_size;
-  if (buffer_size == 0) buffer_size = block_size;
-
-  if (volume_size % block_size != 0) {
-	fprintf(stderr,
-	"vol: volume size (%s) is not a multiple of the block size (%lu)\n",
-		str_vol_size, (unsigned long) block_size);
-	exit(1);
-  }
-
-  buffer = (char *) malloc(buffer_size);
-  if (buffer == NULL) {
-	fprintf(stderr, "vol: cannot allocate a %luk buffer\n",
-		(unsigned long) buffer_size / 1024);
-	exit(1);
-  }
-}
-
-void diskio(fd1, fd2, file1, file2)
-int fd1, fd2;
-char *file1, *file2;
-{
-/* Read 'volume_size' bytes from 'fd1' and write them on 'fd2'.  Watch out for
- * the fact that reads on pipes can return less than the desired data.
- */
-
-  ssize_t n, in_needed, in_count, out_count;
-  long needed = volume_size;
-  int eof = 0;
-
-  for (;;) {
-	if (volume_size == 0) needed = buffer_size;
-
-	if (needed == 0) break;
-
-	in_count = 0;
-	in_needed = needed > buffer_size ? buffer_size : needed;
-	while (in_count < in_needed) {
-		n = in_needed - in_count;
-		n = eof ? 0 : read(fd1, buffer + in_count, n);
-		if (n == 0) {
-			eof = 1;
-			if ((n = in_count % block_size) > 0) {
-				n = block_size - n;
-				memset(buffer + in_count, '\0', n);
-				if ((in_count += n) > in_needed)
-					in_count = in_needed;
-			}
-			break;
-		}
-		if (n < 0) {
-			fprintf(stderr, "vol: %s: %s\n",
-						file1, strerror(errno));
-			exit(1);
-		}
-		in_count += n;
-	}
-	if (in_count == 0) exit(0);	/* EOF */
-	out_count = 0;
-	while (out_count < in_count) {
-		n = in_count - out_count;
-		n = write(fd2, buffer + out_count, n);
-		if (n < 0) {
-			fprintf(stderr, "vol: %s: %s\n",
-						file2, strerror(errno));
-			exit(1);
-		}
-		out_count += n;
-	}
-	needed -= in_count;
-  }
-}
Index: trunk/minix/commands/simple/wc.c
===================================================================
--- trunk/minix/commands/simple/wc.c	(revision 9)
+++ 	(revision )
@@ -1,151 +1,0 @@
-/* wc - count lines, words and characters	Author: David Messer */
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-/*
- *
- *	Usage:  wc [-lwc] [names]
- *
- *		Flags:
- *			l - count lines.
- *			w - count words.
- *			c - count characters.
- *
- *		Flags l, w, and c are default.
- *		Words are delimited by any non-alphabetic character.
- *
- *  Released into the PUBLIC-DOMAIN 02/10/86
- *
- *	If you find this program to be of use to you, a donation of
- *	whatever you think it is worth will be cheerfully accepted.
- *
- *	Written by: David L. Messer
- *				P.O. Box 19130, Mpls, MN,  55119
- *      Program (heavily) modified by Andy Tanenbaum
- */
-
-
-int lflag;			/* Count lines */
-int wflag;			/* Count words */
-int cflag;			/* Count characters */
-
-long lcount;			/* Count of lines */
-long wcount;			/* Count of words */
-long ccount;			/* Count of characters */
-
-long ltotal;			/* Total count of lines */
-long wtotal;			/* Total count of words */
-long ctotal;			/* Total count of characters */
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void count, (FILE *f));
-_PROTOTYPE(void usage, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int k;
-  char *cp;
-  int tflag, files;
-
-  /* Get flags. */
-  files = argc - 1;
-  k = 1;
-  cp = argv[1];
-  if (argc > 1 && *cp++ == '-') {
-	files--;
-	k++;			/* points to first file */
-	while (*cp != 0) {
-		switch (*cp) {
-		    case 'l':	lflag++;	break;
-		    case 'w':	wflag++;	break;
-		    case 'c':	cflag++;	break;
-		    default:	usage();
-		}
-		cp++;
-	}
-  }
-
-  /* If no flags are set, treat as wc -lwc. */
-  if (!lflag && !wflag && !cflag) {
-	lflag = 1;
-	wflag = 1;
-	cflag = 1;
-  }
-
-  /* Process files. */
-  tflag = files >= 2;		/* set if # files > 1 */
-
-  /* Check to see if input comes from std input. */
-  if (k >= argc) {
-	count(stdin);
-	if (lflag) printf(" %6ld", lcount);
-	if (wflag) printf(" %6ld", wcount);
-	if (cflag) printf(" %6ld", ccount);
-	printf(" \n");
-	fflush(stdout);
-	exit(0);
-  }
-
-  /* There is an explicit list of files.  Loop on files. */
-  while (k < argc) {
-	FILE *f;
-
-	if ((f = fopen(argv[k], "r")) == NULL) {
-		fprintf(stderr, "wc: cannot open %s\n", argv[k]);
-	} else {
-		count(f);
-		if (lflag) printf(" %6ld", lcount);
-		if (wflag) printf(" %6ld", wcount);
-		if (cflag) printf(" %6ld", ccount);
-		printf(" %s\n", argv[k]);
-		fclose(f);
-	}
-	k++;
-  }
-
-  if (tflag) {
-	if (lflag) printf(" %6ld", ltotal);
-	if (wflag) printf(" %6ld", wtotal);
-	if (cflag) printf(" %6ld", ctotal);
-	printf(" total\n");
-  }
-  fflush(stdout);
-  return(0);
-}
-
-void count(f)
-FILE *f;
-{
-  register int c;
-  register int word = 0;
-
-  lcount = 0;
-  wcount = 0;
-  ccount = 0L;
-
-  while ((c = getc(f)) != EOF) {
-	ccount++;
-
-	if (isspace(c)) {
-		if (word) wcount++;
-		word = 0;
-	} else {
-		word = 1;
-	}
-
-	if (c == '\n' || c == '\f') lcount++;
-  }
-  ltotal += lcount;
-  wtotal += wcount;
-  ctotal += ccount;
-}
-
-void usage()
-{
-  fprintf(stderr, "Usage: wc [-lwc] [name ...]\n");
-  exit(1);
-}
Index: trunk/minix/commands/simple/which.c
===================================================================
--- trunk/minix/commands/simple/which.c	(revision 9)
+++ 	(revision )
@@ -1,86 +1,0 @@
-/* which - search paths for executable */
-
-#define DELIMITER ':'
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-_PROTOTYPE(int main, (int argc, char **argv));
-
-int main(ac, av)
-int ac;
-char **av;
-{
-  char *path, *cp;
-  char buf[400];
-  char prog[400];
-  char patbuf[512];
-  int quit, none;
-  int excode = 0;
-
-  if (ac < 2) {
-	fprintf(stderr, "Usage: %s cmd [cmd, ..]\n", *av);
-	exit(1);
-  }
-  av[ac] = 0;
-  for (av++; *av; av++) {
-
-	quit = 0;
-	none = 1;
-	if ((path = getenv("PATH")) == NULL) {
-		fprintf(stderr, "Null path.\n");
-		exit(0);
-	}
-	strcpy(patbuf, path);
-	path = patbuf;
-	cp = path;
-
-	while (1) {
-		cp = strchr(path, DELIMITER);
-		if (cp == NULL)
-			quit++;
-		else
-			*cp = '\0';
-
-		if (strcmp(path, "") == 0 && quit == 0) {
-			sprintf(buf, "%s./%s", path, *av);
-		} else
-			sprintf(buf, "%s/%s", path, *av);
-
-		/* Fprintf(stderr,"Trying %s, path %s\n",buf,path); */
-
-		path = ++cp;
-
-		if (access(buf, 1) == 0) {
-			printf("%s\n", buf);
-			none = 0;
-		}
-		sprintf(prog, "%s.%s", buf, "prg");
-		if (access(prog, 1) == 0) {
-			printf("%s\n", prog);
-			none = 0;
-		}
-		sprintf(prog, "%s.%s", buf, "ttp");
-		if (access(prog, 1) == 0) {
-			printf("%s\n", prog);
-			none = 0;
-		}
-		sprintf(prog, "%s.%s", buf, "tos");
-		if (access(prog, 1) == 0) {
-			printf("%s\n", prog);
-			none = 0;
-		}
-		if (quit) {
-			if (none) {
-				fprintf(stderr, "No %s in %s\n", *av, getenv("PATH"));
-				excode = 1;
-			}
-			break;
-		}
-	}
-  }
-  return(excode);
-}
Index: trunk/minix/commands/simple/who.c
===================================================================
--- trunk/minix/commands/simple/who.c	(revision 9)
+++ 	(revision )
@@ -1,72 +1,0 @@
-/*	who 1.5 - tell who is currently logged in	Author: Kees J. Bot
- *								9 Jul 1989
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <utmp.h>
-#include <time.h>
-#include <string.h>
-#include <minix/paths.h>
-
-char PATH_UTMP[] = _PATH_UTMP;
-
-char day[] = "SunMonTueWedThuFriSat";
-char month[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
-
-int main(int argc, char **argv)
-{
-	char *tmp= PATH_UTMP;
-	FILE *f;
-	struct utmp ut;
-	struct tm *tm;
-	int slot, wtmp= 0, once= 0;
-
-	if (argc > 3) {
-		fprintf(stderr, "Usage: who <account-file>  |  who am i\n");
-		exit(1);
-	}
-	if (argc == 2) {
-		tmp= argv[1];
-		wtmp= 1;
-	}
-
-	if ((f= fopen(tmp, "r")) == nil) {
-		fprintf(stderr, "who: can't open %s\n", tmp);
-		exit(1);
-	}
-	if (argc == 3) {
-		if ((slot= ttyslot()) < 0) {
-			fprintf(stderr, "who: no access to terminal.\n");
-			exit(1);
-		}
-		fseek(f, (off_t) sizeof(ut) * slot, 0);
-		once= 1;
-	}
-
-	while (fread((char *) &ut, sizeof(ut), 1, f) == 1) {
-		if (!wtmp && ut.ut_name[0] == 0) continue;
-
-		tm= localtime(&ut.ut_time);
-
-		printf("%-9.8s %-9.8s %.3s %.3s %2d %02d:%02d",
-			ut.ut_name,
-			ut.ut_line,
-			day + (3 * tm->tm_wday),
-			month + (3 * tm->tm_mon),
-			tm->tm_mday,
-			tm->tm_hour,
-			tm->tm_min
-		);
-
-		if (ut.ut_host[0] != 0) printf("  (%.*s)",
-				(int) sizeof(ut.ut_host), ut.ut_host);
-
-		printf("\n");
-		if (once) break;
-	}
-	exit(0);
-}
Index: trunk/minix/commands/simple/whoami.c
===================================================================
--- trunk/minix/commands/simple/whoami.c	(revision 9)
+++ 	(revision )
@@ -1,19 +1,0 @@
-/* whoami - print the current user name 	Author: Terrence W. Holm */
-
-#include <sys/types.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-
-_PROTOTYPE(int main, (void));
-
-int main()
-{
-  struct passwd *pw_entry;
-
-  pw_entry = getpwuid(geteuid());
-  if (pw_entry == NULL) exit(1);
-  puts(pw_entry->pw_name);
-  return(0);
-}
Index: trunk/minix/commands/simple/write.c
===================================================================
--- trunk/minix/commands/simple/write.c	(revision 9)
+++ 	(revision )
@@ -1,269 +1,0 @@
-/* write - write to a logged in user	Authors: N. Andrew and F. van Kempen */
-
-/*
- * Usage:	write [-c] [-v] user [tty]
- *  			-c Read & write one character at a time (cbreak mode)
- *			-v Verbose
- *
- * Version:	1.6	10/24/92
- *
- * NOTES:	Write requires 1.4a (or higher) libraries,
- *		for getopt(), strchr().
- *
- * Authors:	Nick Andrew  (nick@nswitgould.oz)  - Public Domain
- *		Fred van Kempen (minixug!waltje@kyber.uucp)
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <termios.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <utmp.h>
-#include <time.h>
-#include <stdio.h>
-#include <minix/paths.h>
-
-static char *Version = "@(#) WRITE 1.6 (10/24/92)";
-
-int otty;			/* file desc of callee's terminal */
-short int cbreak = 0;		/* are we in CBREAK (-c) mode? */
-short int verbose = 0;		/* are we in VERBOSE (-v) mode? */
-short int writing = 0;		/* is there a connection? */
-char *user = NULL;	/* callee's user name */
-char *tty = NULL;	/* callee's terminal if given */
-char *ourtty = NULL;	/* our terminal name */
-struct termios ttyold, ttynew;	/* our tty controlling structs */
-
-extern int optind;
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(char *finduser, (void));
-_PROTOTYPE(void settty, (char *utty));
-_PROTOTYPE(void sayhello, (void));
-_PROTOTYPE(void escape, (char *cmd));
-_PROTOTYPE(void writetty, (void));
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(void intr, (int dummy));
-
-char *finduser()
-{
-/* Search the UTMP database for the user we want. */
-
-  static char utmptty[16];
-  struct utmp utmp;
-  struct passwd *userptr;
-  int utmpfd;
-
-  ourtty = ttyname(0);
-  if (ourtty == NULL) ourtty = "/dev/console";
-
-  if (user == NULL) exit(-1);
-  if ((userptr = getpwnam(user)) == NULL) {
-	fprintf(stderr, "No such user: %s\n", user);
-	return(NULL);
-  }
-  if (verbose) fprintf(stderr, "Trying to write to %s\n",
-		userptr->pw_gecos);
-
-  if ((utmpfd = open(_PATH_UTMP, O_RDONLY)) < 0) {
-	fprintf(stderr, "Cannot open utmp file\n");
-	return(NULL);
-  }
-  utmptty[0] = '\0';
-
-  /* We want to find if 'user' is logged on, and return in utmptty[]
-   * 'user' `s terminal, and if 'user' is logged onto the tty the
-   * caller specified, return that tty name. */
-  while (read(utmpfd, (char *) &utmp, sizeof(utmp)) == sizeof(utmp)) {
-	/* is this the user we are looking for? */
-	if (strncmp(utmp.ut_name, user, sizeof(utmp.ut_name))) continue;
-
-	strcpy(utmptty, utmp.ut_line);
-	/* is he on the terminal we want to write to? */
-	if (tty == NULL || !strcmp(utmptty, tty)) {
-		break;
-	}
-  }
-
-  if (utmptty[0] == '\0') {
-	fprintf(stderr, "%s is not logged on\n", user);
-	return( NULL);
-  }
-  if (tty != NULL && strcmp(utmptty, tty)) {
-	fprintf(stderr, "%s is logged onto %s, not %s\n", user, utmptty, tty);
-	return( NULL);
-  }
-  close(utmpfd);
-
-  if (verbose) fprintf(stderr, "Writing to %s on %s\n", user, utmptty);
-  return(utmptty);
-}
-
-
-void settty(utty)
-char *utty;			/* name of terminal found in utmp */
-{
-/* Open other person's terminal and setup our own terminal. */
-
-  char buff[48];
-
-  sprintf(buff, "/dev/%s", utty);
-  if ((otty = open(buff, O_WRONLY)) < 0) {
-	fprintf(stderr, "Cannot open %s to write to %s\n", utty, user);
-	fprintf(stderr, "It may have write permission turned off\n");
-	exit(-1);
-  }
-  tcgetattr(0, &ttyold);
-  tcgetattr(0, &ttynew);
-  ttynew.c_lflag &= ~(ICANON|ECHO);
-  signal(SIGINT, intr);
-  if (cbreak) tcsetattr(0, TCSANOW, &ttynew);
-}
-
-
-void sayhello()
-{
-  struct passwd *pw;
-  char buff[128];
-  long now;
-  char *sp;
-
-  time(&now);
-
-  pw = getpwuid(getuid());
-  if (pw == NULL) {
-	fprintf(stderr, "unknown user\n");
-	exit(-1);
-  }
-  if ((sp = strrchr(ourtty, '/')) != NULL)
-	++sp;
-  else
-	sp = ourtty;
-
-  sprintf(buff, "\nMessage from %s (%s) %-24.24s...\n",
-	pw->pw_name, sp, ctime(&now));
-
-  write(otty, buff, strlen(buff));
-  printf("\007\007");
-  fflush(stdout);
-}
-
-
-void escape(cmd)
-char *cmd;
-{
-/* Shell escape. */
-
-  register char *x;
-
-  write(1, "!\n", 2);
-  for (x = cmd; *x; ++x)
-	if (*x == '\n') *x = '\0';
-
-  system(cmd);
-  write(1, "!\n", 2);
-}
-
-
-void writetty()
-{
-/* The write loop. */
-
-  char line[80];
-  int n, cb_esc;
-
-  writing = 1;
-  cb_esc = 0;
-
-  while ((n = read(0, line, 79)) > 0) {
-	if (line[0] == '\004') break;	/* EOT */
-
-	if (cbreak && line[0] == '\n') cb_esc = 1;
-
-	if (cbreak) write(1, line, n);
-
-	if (line[0] == '!') {
-		if (cbreak && cb_esc) {
-			cb_esc = 0;
-			tcsetattr(0, TCSANOW, &ttyold);
-			read(0, line, 79);
-			escape(line);
-			tcsetattr(0, TCSANOW, &ttynew);
-		} else if (cbreak)
-			write(otty, line, n);
-		else
-			escape(&line[1]);
-		continue;
-	}
-	write(otty, line, n);
-  }
-  write(1, "\nEOT\n", 5);
-  write(otty, "\nEOT\n", 5);
-}
-
-
-void usage()
-{
-  fprintf(stderr, "usage: write [-c] [-v] user [tty]\n");
-  fprintf(stderr, "\t-c : cbreak mode\n\t-v : verbose\n");
-  exit(-1);
-}
-
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  register int c;
-  char *sp;
-
-  setbuf(stdout, (char *) NULL);
-
-  /* Parse options. */
-  while ((c = getopt(argc, argv, "cv")) != EOF) switch (c) {
-	        case 'c':	cbreak = 1;	break;
-	        case 'v':	verbose = 1;	break;
-	    default:
-		usage();
-	}
-
-  /* Parse user and tty arguments */
-  if (optind < argc) {
-	user = argv[optind++];
-
-	/* WTMP usernames are 1-8 chars */
-	if (strlen(user) > 8) *(user + 8) = '\0';
-
-	if (optind < argc) {
-		tty = argv[optind++];
-		if (optind < argc) usage();
-	}
-  } else
-	usage();
-
-  sp = finduser();		/* find which tty to write onto */
-  if (sp != NULL) {	/* did we find one? */
-	settty(sp);		/* setup our terminal */
-	sayhello();		/* print the initial message */
-	writetty();		/* the write loop */
-	tcsetattr(0, TCSANOW, &ttyold);
-	exit(0);
-  }
-  return(-1);
-}
-
-void intr(dummy)
-int dummy;			/* to satisfy the prototype */
-{
-/* The interrupt key has been hit. exit cleanly. */
-
-  signal(SIGINT, SIG_IGN);
-  fprintf(stderr, "\nInterrupt. Exiting write\n");
-  tcsetattr(0, TCSANOW, &ttyold);
-  if (writing) write(otty, "\nEOT\n", 5);
-  exit(0);
-}
Index: trunk/minix/commands/simple/writeisofs.c
===================================================================
--- trunk/minix/commands/simple/writeisofs.c	(revision 9)
+++ 	(revision )
@@ -1,1111 +1,0 @@
-
-/* writeisofs - simple ISO9660-format-image writing utility */
-
-#include <errno.h>
-#include <stdio.h>
-#include <time.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <ctype.h>
-#include <ibm/partition.h>
-
-#include <sys/stat.h>
-
-#define Writefield(fd, f) Write(fd, &(f), sizeof(f))
-
-extern char *optarg;
-extern int optind;
-
-typedef unsigned char u_int8_t;
-typedef unsigned short int u_int16_t;
-typedef unsigned long int u_int32_t;
-
-#ifndef min
-#define min(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
-#define FLAG_DIR	2
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#define NAMELEN		(DIRSIZ+5)
-#define ISONAMELEN	12
-#define PLATFORM_80X86	0
-
-#define ISO_SECTOR 2048
-#define VIRTUAL_SECTOR	512
-
-#define CURRENTDIR	"."
-#define PARENTDIR	".."
-
-/*  *** CD (disk) data structures ********************* */
-
-/* primary volume descriptor */
-
-struct pvd {
-	u_int8_t one;
-	char set[6];
-	u_int8_t zero;
-	char system[32];
-	char volume[32];
-	u_int8_t zeroes1[8];
-	u_int32_t sectors[2];
-	u_int8_t zeroes2[32];
-	u_int16_t setsize[2];
-	u_int16_t seq[2];
-	u_int16_t sectorsize[2];
-	u_int32_t pathtable[2];
-	u_int32_t first_little_pathtable_start;
-	u_int32_t second_little_pathtable_start;
-	u_int32_t first_big_pathtable_start;
-	u_int32_t second_big_pathtable_start;
-	u_int8_t rootrecord[34];
-	u_int8_t volumeset[128];
-	u_int8_t publisher[128];
-	u_int8_t preparer[128];
-	u_int8_t application[128];
-	u_int8_t copyrightfile[37];
-	u_int8_t abstractfile[37];
-	u_int8_t bibliofile[37];
-	u_int8_t create[17];
-	u_int8_t modified[17];
-	char expiry[17];
-	u_int8_t effective[17];
-	u_int8_t one2;
-	u_int8_t zero2;
-	u_int8_t zeroes3[512];
-	u_int8_t zeroes4[653];
-};
-
-/* boot record volume descriptor */
-
-struct bootrecord {
-	u_int8_t	indicator;	/* 0 */
-	char		set[5];		/* "CD001" */
-	u_int8_t	version;	/* 1 */
-	char		ident[32];	/* "EL TORITO SPECIFICATION" */
-	u_int8_t	zero[32];	/* unused, must be 0 */
-	u_int32_t	bootcatalog;	/* starting sector of boot catalog */
-	u_int8_t	zero2[1973];	/* unused, must be 0 */
-};
-
-/* boot catalog validation entry */
-
-struct bc_validation {
-	u_int8_t	headerid;	/* 1 */
-	u_int8_t	platform;	/* 0: 80x86; 1: powerpc; 2: mac */
-	u_int8_t	zero[2];	/* unused, must be 0 */
-	char		idstring[24];	/* id string */
-	u_int16_t	checksum;
-	u_int8_t	keys[2];	/* 0x55AA */
-};
-
-/* boot catalog initial/default entry */
-
-#define INDICATE_BOOTABLE	0x88
-
-#define BOOTMEDIA_NONE		0
-#define BOOTMEDIA_120M		1
-#define BOOTMEDIA_144M		2
-#define BOOTMEDIA_288M		3
-#define BOOTMEDIA_HARDDISK	4
-
-struct bc_initial {
-	u_int8_t	indicator;	/* INDICATE_BOOTABLE */
-	u_int8_t	media;		/* BOOTMEDIA_* */
-	u_int16_t	seg;		/* load segment or 0 for default */
-	u_int8_t	type;		/* system type (from part. table) */
-	u_int8_t	zero;
-	u_int16_t	sectors;
-	u_int32_t	startsector;
-	u_int8_t	zero2[20];
-};
-
-/* directory entry */
-
-struct dir {
-	u_int8_t	recordsize;
-	u_int8_t	extended;
-	u_int32_t	datasector[2];
-	u_int32_t	filesize[2];
-	u_int8_t	year;
-	u_int8_t	month;
-	u_int8_t	day;
-	u_int8_t	hour;
-	u_int8_t	minute;
-	u_int8_t	second;
-	u_int8_t	offset;
-	u_int8_t	flags;
-	u_int8_t	interleaved;
-	u_int8_t	interleavegap;
-	u_int16_t	sequence[2];
-	u_int8_t	namelen;
-	char		name[NAMELEN];
-};
-
-/*  *** program (memory) data structures ********************* */
-
-struct node {
-	char name[NAMELEN];
-	int isdir;
-	int pathtablerecord;
-	struct node *firstchild, *nextchild;
-
-	/* filled out at i/o time */
-	u_int32_t startsector, bytesize;
-};
-
-int n_reserved_pathtableentries = 0, n_used_pathtableentries = 0;
-int harddisk_emulation = 0;
-int system_type = 0;
-
-int get_system_type(int fd);
-
-ssize_t
-Write(int fd, void *buf, ssize_t len)
-{
-	ssize_t r;
-	if((r=write(fd, buf, len)) != len) {
-		if(r < 0) { perror("write"); }
-		fprintf(stderr, "failed or short write - aborting.\n");
-		exit(1);
-	}
-	return len;
-}
-
-off_t
-Lseek(int fd, off_t pos, int rel)
-{
-	off_t r;
-
-	if((r=lseek(fd, pos, rel)) < 0) {
-		perror("lseek");
-		fprintf(stderr, "lseek failed - aborting.\n");
-		exit(1);
-	}
-
-	return r;
-}
-
-void
-writesector(int fd, char *block, int *currentsector)
-{
-	Write(fd, block, ISO_SECTOR);
-	(*currentsector)++;
-	return;
-}
-
-void
-seeksector(int fd, int sector, int *currentsector)
-{
-	Lseek(fd, sector*ISO_SECTOR, SEEK_SET);
-	*currentsector = sector;
-}
-
-void
-seekwritesector(int fd, int sector, char *block, int *currentsector)
-{
-	seeksector(fd, sector, currentsector);
-	writesector(fd, block, currentsector);
-}
-
-ssize_t
-Read(int fd, void *buf, ssize_t len)
-{
-	ssize_t r;
-	if((r=read(fd, buf, len)) != len) {
-		if(r < 0) { perror("read"); }
-		fprintf(stderr, "failed or short read.\n");
-		exit(1);
-	}
-
-	return len;
-}
-
-void both16(unsigned char *both, unsigned short i16)
-{
-	unsigned char *little, *big;
-
-	little = both;
-	big = both + 2;
-
-	little[0] = big[1] = i16        & 0xFF;
-	little[1] = big[0] = (i16 >> 8) & 0xFF;
-}
-
-void both32(unsigned char *both, unsigned long i32)
-{
-	unsigned char *little, *big;
-
-	little = both;
-	big = both + 4;
-
-	little[0] = big[3] = i32         & 0xFF;
-	little[1] = big[2] = (i32 >>  8) & 0xFF;
-	little[2] = big[1] = (i32 >> 16) & 0xFF;
-	little[3] = big[0] = (i32 >> 24) & 0xFF;
-}
-
-#define MINDIRLEN	 1
-#define MAXDIRLEN	31
-
-#define MAXLEVEL 8
-
-static int cmpf(const void *v1, const void *v2)
-{
-	struct node *n1, *n2;
-	int i;
-	char f1[NAMELEN], f2[NAMELEN];
-
-	n1 = (struct node *) v1;
-	n2 = (struct node *) v2;
-	strcpy(f1, n1->name);
-	strcpy(f2, n2->name);
-	for(i = 0; i < strlen(f1); i++) f1[i] = toupper(f1[i]);
-	for(i = 0; i < strlen(f2); i++) f2[i] = toupper(f2[i]);
-
-
-	return -strcmp(f1, f2);
-}
-
-void
-maketree(struct node *thisdir, char *name, int level)
-{
-	DIR *dir;
-	struct dirent *e;
-	struct node *dirnodes = NULL;
-	int reserved_dirnodes = 0, used_dirnodes = 0;
-	struct node *child;
-
-	thisdir->firstchild = NULL;
-	thisdir->isdir = 1;
-	thisdir->startsector = 0xdeadbeef;
-
-	if(level >= MAXLEVEL) {
-		fprintf(stderr, "ignoring entries in %s (too deep for iso9660)\n",
-			name);
-		return;
-	}
-
-	if(!(dir = opendir(CURRENTDIR))) {
-		perror("opendir");
-		return;
-	}
-
-	/* how many entries do we need to allocate? */
-	while(readdir(dir)) reserved_dirnodes++;
-	if(!reserved_dirnodes) {
-		closedir(dir);
-		return;
-	}
-
-	if(!(dirnodes = malloc(sizeof(*dirnodes)*reserved_dirnodes))) {
-		fprintf(stderr, "couldn't allocate dirnodes (%d bytes)\n",
-			sizeof(*dirnodes)*reserved_dirnodes);
-		exit(1);
-	}
-
-
-	/* remember all entries in this dir */
-	rewinddir(dir);
-
-	child = dirnodes;
-	while((e=readdir(dir))) {
-		struct stat st;
-		mode_t type;
-		if(!strcmp(e->d_name, CURRENTDIR) || !strcmp(e->d_name, PARENTDIR))
-			continue;
-		if(stat(e->d_name, &st) < 0) {
-			perror(e->d_name);
-			fprintf(stderr, "failed to stat file/dir\n");
-			exit(1);
-		}
-
-		type = st.st_mode & S_IFMT;
-
-/*
-		printf("%s type: %x dir: %x file: %x\n",
-			e->d_name, type, S_IFDIR, S_IFREG);
-			*/
-		if(type != S_IFDIR && type != S_IFREG)
-			continue;
-
-		used_dirnodes++;
-		if(used_dirnodes > reserved_dirnodes) {
-			fprintf(stderr, "huh, directory entries appeared "
-	"(not enough pre-allocated nodes; this can't happen) ?\n");
-			exit(1);
-		}
-
-		if(type == S_IFDIR) {
-			child->isdir = 1;
-		} else {
-			child->isdir = 0;
-			child->firstchild = NULL;
-		}
-		strncpy(child->name, e->d_name, sizeof(child->name));
-
-		child++;
-	}
-
-	closedir(dir);
-
-	if(!used_dirnodes)
-		return;
-
-	if(!(dirnodes=realloc(dirnodes, used_dirnodes*sizeof(*dirnodes)))) {
-		fprintf(stderr, "realloc() of dirnodes failed - aborting\n");
-		exit(1);
-	}
-
-	qsort(dirnodes, used_dirnodes, sizeof(*dirnodes), cmpf);
-
-	child = dirnodes;
-
-	while(used_dirnodes--) {
-		child->nextchild = thisdir->firstchild;
-		thisdir->firstchild = child;
-		if(child->isdir) {
-			if(chdir(child->name) < 0) {
-				perror(child->name);
-			} else {
-				maketree(child, child->name, level+1);
-				if(chdir(PARENTDIR) < 0) {
-					perror("chdir() failed");
-					fprintf(stderr, "couldn't chdir() to parent, aborting\n");
-					exit(1);
-				}
-			}
-		}
-
-		child++;
-	}
-
-}
-
-void
-little32(unsigned char *dest, u_int32_t src)
-{
-	dest[0] = ((src >>  0) & 0xFF);
-	dest[1] = ((src >>  8) & 0xFF);
-	dest[2] = ((src >> 16) & 0xFF);
-	dest[3] = ((src >> 24) & 0xFF);
-
-	return;
-}
-
-void
-little16(unsigned char *dest, u_int16_t src)
-{
-	dest[0] = ((src >>  0) & 0xFF);
-	dest[1] = ((src >>  8) & 0xFF);
-
-	return;
-}
-
-void
-big32(unsigned char *dest, u_int32_t src)
-{
-	dest[3] = ((src >>  0) & 0xFF);
-	dest[2] = ((src >>  8) & 0xFF);
-	dest[1] = ((src >> 16) & 0xFF);
-	dest[0] = ((src >> 24) & 0xFF);
-	return;
-}
-
-void
-big16(unsigned char *dest, u_int16_t src)
-{
-	dest[1] = ((src >>  0) & 0xFF);
-	dest[0] = ((src >>  8) & 0xFF);
-	return;
-}
-
-
-void
-traversetree(struct node *root, int level, int littleendian,
-	int maxlevel, int *bytes, int fd, int parentrecord, int *recordno)
-{
-	struct node *child;
-	struct pte {
-		u_int8_t len;
-		u_int8_t zero;
-		u_int32_t startsector;
-		u_int16_t parent;
-	} pte;
-
-	if(level == maxlevel) {
-		int i;
-		char newname[NAMELEN];
-		if(!root->isdir)
-			return;
-		pte.zero = 0;
-		if(level == 1) {
-			/* root */
-			pte.len = 1;
-			pte.parent = 1;
-			root->name[0] = root->name[1] = '\0';
-		} else {
-			pte.len = strlen(root->name);
-			pte.parent = parentrecord;
-		}
-		pte.startsector = root->startsector;
-		root->pathtablerecord = (*recordno)++;
-
-		if(littleendian) {
-			little32((unsigned char *) &pte.startsector, pte.startsector);
-			little16((unsigned char *) &pte.parent, pte.parent);
-		} else {
-			big32((unsigned char *) &pte.startsector, pte.startsector);
-			big16((unsigned char *) &pte.parent, pte.parent);
-		}
-
-		*bytes += Write(fd, &pte.len, sizeof(pte.len));
-		*bytes += Write(fd, &pte.zero, sizeof(pte.zero));
-		*bytes += Write(fd, &pte.startsector, sizeof(pte.startsector));
-		*bytes += Write(fd, &pte.parent, sizeof(pte.parent));
-		if(!(pte.len%2))
-			root->name[pte.len++] = '\0';
-		for(i = 0; i < pte.len; i++)
-			newname[i] = toupper(root->name[i]);
-		*bytes += Write(fd, newname, pte.len);
-		return;
-	}
-
-	for(child = root->firstchild; child; child = child->nextchild)
-		if(child->isdir)
-			traversetree(child, level+1, littleendian,
-				maxlevel, bytes, fd, root->pathtablerecord,
-					recordno);
-
-	return;
-}
-
-int
-makepathtables(struct node *root, int littleendian, int *bytes, int fd)
-{
-	int level;
-	static char block[ISO_SECTOR];
-	int recordno;
-
-	recordno = 1;
-
-	*bytes = 0;
-
-	for(level = 1; level <= MAXLEVEL; level++)
-		traversetree(root, 1, littleendian, level, bytes, fd, 1, &recordno);
-
-	if(*bytes % ISO_SECTOR) {
-		ssize_t x;
-		x = ISO_SECTOR-(*bytes % ISO_SECTOR);
-		write(fd, block, x);
-		*bytes += x;
-	}
-
-	return *bytes/ISO_SECTOR;
-}
-
-ssize_t
-write_direntry(char *origname, u_int32_t sector, u_int32_t size, int isdir,
-	int fd)
-{
-	int namelen, total = 0;
-	struct dir entry;
-	char copyname[NAMELEN];
-
-	memset(&entry, 0, sizeof(entry));
-
-	if(!strcmp(origname, CURRENTDIR)) {
-		namelen = 1;
-	} else if(!strcmp(origname, PARENTDIR)) {
-		entry.name[0] = '\001';
-		namelen = 1;
-	} else {
-		int i;
-		strcpy(copyname, origname);
-		namelen = strlen(copyname);
-
-		if(namelen > ISONAMELEN) {
-			fprintf(stderr, "%s: truncated, too long for iso9660\n", copyname);
-			namelen = ISONAMELEN;
-			copyname[namelen] = '\0';
-		}
-
-		strcpy(entry.name, copyname);
-		for(i = 0; i < namelen; i++)
-			entry.name[i] = toupper(entry.name[i]);
-
-		/* padding byte + system field */
-		entry.name[namelen]   = '\0';
-		entry.name[namelen+1] = '\0';
-		entry.name[namelen+2] = '\0';
-	}
-	entry.namelen = namelen;	/* original length */
-	if(!(namelen%2)) namelen++;	/* length with padding byte */
-
-
-	/* XXX 2 extra bytes for 'system use'.. */
-	entry.recordsize = 33 + namelen;
-	both32((unsigned char *) entry.datasector, sector);
-	both32((unsigned char *) entry.filesize, size);
-
-	if(isdir) entry.flags = FLAG_DIR;
-
-	/* XXX node date */
-
-	both16((unsigned char *) entry.sequence, 1);
-	
-	 total = Write(fd, &entry.recordsize, sizeof(entry.recordsize));
-	 total += Write(fd, &entry.extended, sizeof(entry.extended));
-	 total += Write(fd, entry.datasector, sizeof(entry.datasector));
-	 total += Write(fd, entry.filesize, sizeof(entry.filesize));
-	 total += Write(fd, &entry.year, sizeof(entry.year));
-	 total += Write(fd, &entry.month, sizeof(entry.month));
-	 total += Write(fd, &entry.day, sizeof(entry.day));
-	 total += Write(fd, &entry.hour, sizeof(entry.hour));
-	 total += Write(fd, &entry.minute, sizeof(entry.minute));
-	 total += Write(fd, &entry.second, sizeof(entry.second));
-	 total += Write(fd, &entry.offset, sizeof(entry.offset));
-	 total += Write(fd, &entry.flags, sizeof(entry.flags));
-	 total += Write(fd, &entry.interleaved, sizeof(entry.interleaved));
-	 total += Write(fd, &entry.interleavegap, sizeof(entry.interleavegap));
-	 total += Write(fd, entry.sequence, sizeof(entry.sequence));
-	 total += Write(fd, &entry.namelen, sizeof(entry.namelen));
-	 total += Write(fd, entry.name, namelen);
-
-	if(total != entry.recordsize || (total % 2) != 0) {
-		printf("%2d, %2d!  ", total, entry.recordsize);
-		printf("%3d = %3d - %2d + %2d\n",
-		entry.recordsize, sizeof(entry), sizeof(entry.name), namelen);
-	}
-
-	return entry.recordsize;
-}
-
-void
-writedata(struct node *parent, struct node *root,
-	int fd, int *currentsector, int dirs, struct dir *rootentry,
-	int rootsize, int remove_after)
-{
-	static char buf[1024*1024];
-	struct node *c;
-	ssize_t written = 0, rest;
-
-	for(c = root->firstchild; c; c = c->nextchild) {
-		if(c->isdir && chdir(c->name) < 0) {
-			perror(c->name);
-			fprintf(stderr, "couldn't chdir to %s - aborting\n",
-				c->name);
-			exit(1);
-		}
-		writedata(root, c, fd, currentsector, dirs, rootentry, rootsize, remove_after);
-		if(c->isdir && chdir(PARENTDIR) < 0) {
-			perror("chdir to ..");
-			fprintf(stderr, "couldn't chdir to parent - "
-				"aborting\n");
-			exit(1);
-		}
-	}
-
-	/* write nodes depth-first, down-top */
-
-	if(root->isdir && dirs) {
-		/* dir */
-		written = 0;
-		root->startsector = *currentsector;
-		written += write_direntry(CURRENTDIR, root->startsector,
-			root->bytesize, root->isdir, fd);
-		if(parent) {
-			written += write_direntry(PARENTDIR, parent->startsector,
-				root->bytesize, root->isdir, fd);
-		} else {
-			written += write_direntry(PARENTDIR, root->startsector,
-				root->bytesize, root->isdir, fd);
-		}
-		for(c = root->firstchild; c; c = c->nextchild) {
-			off_t cur1, cur2;
-			ssize_t written_before;
-			cur1 = Lseek(fd, 0, SEEK_CUR);
-			written_before = written;
-			written += write_direntry(c->name,
-				c->startsector, c->bytesize, c->isdir, fd);
-			cur2 = Lseek(fd, 0, SEEK_CUR);
-			if(cur1/ISO_SECTOR != (cur2-1)/ISO_SECTOR) {
-				/* passed a sector boundary, argh! */
-				Lseek(fd, cur1, SEEK_SET);
-				written = written_before;
-				rest=(ISO_SECTOR-(written % ISO_SECTOR));
-				memset(buf, 0, rest);
-				Write(fd, buf, rest);
-				written += rest;
-				written += write_direntry(c->name,
-				  c->startsector, c->bytesize, c->isdir, fd);
-			}
-		}
-		root->bytesize = written;
-	} else if(!root->isdir && !dirs) {
-		/* file */
-		struct stat st;
-		ssize_t rem;
-		int filefd;
-		
-		if(stat(root->name, &st) < 0) {
-			perror(root->name);
-			fprintf(stderr, "couldn't stat %s - aborting\n", root->name);
-			exit(1);
-		}
-
-		if((filefd = open(root->name, O_RDONLY)) < 0) {
-			perror(root->name);
-			fprintf(stderr, "couldn't open %s - aborting\n", root->name);
-			exit(1);
-		}
-
-		rem = st.st_size;
-
-		root->startsector = *currentsector;
-
-		while(rem > 0) {
-			ssize_t chunk;
-			chunk = min(sizeof(buf), rem);
-			Read(filefd, buf, chunk);
-			Write(fd, buf, chunk);
-			rem -= chunk;
-		}
-
-		close(filefd);
-
-		root->bytesize = written = st.st_size;
-		if(remove_after && unlink(root->name) < 0) {
-			perror("unlink");
-			fprintf(stderr, "couldn't remove %s\n", root->name);
-		}
-	} else { 
-		/* nothing to be done */
-		return;
-	}
-
-	/* fill out sector with zero bytes */
-
-	if((rest=(ISO_SECTOR-(written % ISO_SECTOR)))) {
-		memset(buf, 0, rest);
-		Write(fd, buf, rest);
-		written += rest;
-	}
-
-	/* update dir size with padded size */
-
-	if(root->isdir) { root->bytesize = written; }
-
-	*currentsector += written/ISO_SECTOR;
-}
-
-void
-writebootcatalog(int fd, int  *currentsector, int imagesector, int imagesectors)
-{
-	static char buf[ISO_SECTOR];
-	struct bc_validation validate;
-	struct bc_initial initial;
-
-	ssize_t written, rest;
-	u_int16_t *v, sum = 0;
-	int i;
-
-	/* write validation entry */
-	
-	memset(&validate, 0, sizeof(validate));
-	validate.headerid = 1;
-	validate.platform = PLATFORM_80X86;
-	strcpy(validate.idstring, "");
-	validate.keys[0] = 0x55;
-	validate.keys[1] = 0xaa;
-
-	v = (u_int16_t *) &validate; 
-	for(i = 0; i < sizeof(validate)/2; i++)
-		sum += v[i];
-	validate.checksum = 65535 - sum + 1; /* sum must be 0 */
-
-	written = Write(fd, &validate, sizeof(validate));
-
-	/* write initial/default entry */
-
-	memset(&initial, 0, sizeof(initial));
-
-	initial.indicator = INDICATE_BOOTABLE;
-	if (harddisk_emulation)
-	{
-		initial.media = BOOTMEDIA_HARDDISK;
-		initial.type = system_type;
-	}
-	else
-		initial.media = BOOTMEDIA_144M;
-	/* initial.sectors = imagesectors; */
-	initial.sectors = 1;
-	initial.startsector = imagesector;
-
-	written += Write(fd, &initial, sizeof(initial));
-
-	/* fill out the rest of the sector with 0's */
-
-	if((rest = ISO_SECTOR - (written % 2048))) {
-		memset(buf, 0, sizeof(buf));
-		written += Write(fd, buf, rest);
-	}
-
-	(*currentsector) += written / ISO_SECTOR;
-
-	return;
-}
-
-int
-writebootimage(char *bootimage, int bootfd, int fd, int *currentsector)
-{
-	static char buf[1024*64];
-	ssize_t chunk, written = 0, rest;
-	int virtuals;
-
-	while((chunk=read(bootfd, buf, sizeof(buf))) > 0)
-		written += Write(fd, buf, chunk);
-
-	if(chunk < 0) {
-		perror("read boot image");
-		exit(1);
-	}
-
-	virtuals = written / VIRTUAL_SECTOR;
-
-	if((rest = ISO_SECTOR - (written % 2048))) {
-		memset(buf, 0, sizeof(buf));
-		written += Write(fd, buf, rest);
-	}
-
-	(*currentsector) += written/ISO_SECTOR;
-
-	return virtuals;
-}
-
-void
-writebootrecord(int fd, int *currentsector, int bootcatalogsector)
-{
-	int i;
-	static struct bootrecord bootrecord;
-	ssize_t w = 0;
-	/* boot record volume descriptor */
-
-	memset(&bootrecord, 0, sizeof(bootrecord));
-	bootrecord.set[0] = 'C';
-	bootrecord.set[1] = 'D';
-	bootrecord.set[2] = '0';
-	bootrecord.set[3] = '0';
-	bootrecord.set[4] = '1';
-	bootrecord.version = 1;
-	bootrecord.bootcatalog = bootcatalogsector;
-	strcpy(bootrecord.ident, "EL TORITO SPECIFICATION");
-	for(i = strlen(bootrecord.ident);
-		i < sizeof(bootrecord.ident); i++)
-		bootrecord.ident[i] = '\0';
-
-	w  = Writefield(fd, bootrecord.indicator);
-	w += Writefield(fd, bootrecord.set);
-	w += Writefield(fd, bootrecord.version);
-	w += Writefield(fd, bootrecord.ident);
-	w += Writefield(fd, bootrecord.zero);
-	w += Writefield(fd, bootrecord.bootcatalog);
-	w += Writefield(fd, bootrecord.zero2);
-
-	if(w != ISO_SECTOR) {
-		fprintf(stderr, "WARNING: something went wrong - boot record (%d) isn't a sector size (%d)\n",
-			w, ISO_SECTOR);
-	}
-
-	(*currentsector)++;
-}
-
-int
-main(int argc, char *argv[])
-{
-	int currentsector = 0;
-	int imagesector, imagesectors;
-	int bootfd, fd, i, ch, nsectors;
-	int remove_after = 0;
-	static char block[ISO_SECTOR];
-	static struct pvd pvd;
-	char *label = "ISO9660";
-	struct tm *now;
-	time_t nowtime;
-	char timestr[20], *prog;
-	char *bootimage = NULL;
-	struct node root;
-	int pvdsector;
-	int bigpath, littlepath, pathbytes = 0, dirsector, filesector, enddir;
-	int bootvolumesector, bootcatalogsector;
-
-	prog = argv[0];
-
-	/* This check is to prevent compiler padding screwing up
-	 * our format.
-	 */
-
-	if(sizeof(struct pvd) != ISO_SECTOR) {
-		fprintf(stderr, "Something confusing happened at\n"
-			"compile-time; pvd should be a sector size. %d != %d\n",
-			sizeof(struct pvd), ISO_SECTOR);
-		return 1;
-	}
-
-	while ((ch = getopt(argc, argv, "Rb:hl:")) != -1) {
-		switch(ch) {
-			case 'h':
-				harddisk_emulation= 1;
-				break;
-			case 'l':
-				label = optarg;
-				break;
-			case 'r':
-				remove_after = 1;
-				break;
-			case 'b':
-				bootimage = optarg;
-				if((bootfd = open(bootimage, O_RDONLY)) < 0) {
-					perror(bootimage);
-					return 1;
-				}
-				break;
-		}
-	}
-
-	argc -= optind;
-	argv += optind;
-
-	if(argc != 2) {
-		fprintf(stderr, "usage: %s [-l <label>] [-b <bootfloppyimage>] <dir> <isofile>\n",
-			prog);
-		return 1;
-	}
-
-	/* create .iso file */
-
-	if((fd=open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0) {
-		perror(argv[1]);
-		return 1;
-	}
-
-	/* go to where the iso has to be made from */
-
-	if(chdir(argv[0]) < 0) {
-		perror(argv[0]);
-		return 1;
-	}
-
-	/* collect dirs and files */
-
-	fprintf(stderr, " * traversing input tree\n");
-
-	maketree(&root, "", 1);
-
-	fprintf(stderr, " * writing initial zeroes and pvd\n");
-
-	/* first sixteen sectors are zero */
-
-	memset(block, 0, sizeof(block));
-
-	for(i = 0; i < 16; i++)
-		writesector(fd, block, &currentsector);
-
-	/* Primary Volume Descriptor */
-	memset(&pvd, 0, sizeof(pvd));
-	pvd.one = 1;
-	pvd.set[0] = 67;
-	pvd.set[1] = 68;
-	pvd.set[2] = 48;
-	pvd.set[3] = 48;
-	pvd.set[4] = 49;
-	pvd.set[5] =  1;
-	pvd.set[5] =  1;
-
-	strncpy(pvd.volume, label, sizeof(pvd.volume)-1);
-	for(i = strlen(pvd.volume); i < sizeof(pvd.volume); i++)
-		pvd.volume[i] = ' ';
-	for(i = 0; i < sizeof(pvd.system); i++)
-		pvd.system[i] = ' ';
-
-	both16((unsigned char *) pvd.setsize, 1);
-	both16((unsigned char *) pvd.seq, 1);
-	both16((unsigned char *) pvd.sectorsize, ISO_SECTOR);
-
-	/* fill time fields */
-	time(&nowtime);
-	now = gmtime(&nowtime);
-	strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S000", now);
-	memcpy(pvd.create, timestr, strlen(timestr));
-	memcpy(pvd.modified, timestr, strlen(timestr));
-	memcpy(pvd.effective, timestr, strlen(timestr));
-	strcpy(pvd.expiry, "0000000000000000");	/* not specified */
-	pvdsector = currentsector;
-
-	writesector(fd, (char *) &pvd, &currentsector);
-
-	if(bootimage) {
-		fprintf(stderr, " * writing boot record volume descriptor\n");
-		bootvolumesector = currentsector;
-		writebootrecord(fd, &currentsector, 0);
-	}
-
-	/* volume descriptor set terminator */
-	memset(block, 0, sizeof(block));
-	block[0] = 255;
-	block[1] =  67;
-	block[2] =  68;
-	block[3] =  48;
-	block[4] =  48;
-	block[5] =  49;
-	block[6] =   1;
-
-	writesector(fd, block, &currentsector);
-
-	if(bootimage) {
-		/* write the boot catalog */
-		fprintf(stderr, " * writing the boot catalog\n");
-		bootcatalogsector = currentsector;
-		if (harddisk_emulation)
-			system_type = get_system_type(bootfd);
-		writebootcatalog(fd, &currentsector, imagesector, imagesectors);
-
-		/* write boot image */
-		fprintf(stderr, " * writing the boot image\n");
-		imagesector = currentsector;
-		imagesectors = writebootimage(bootimage, bootfd,
-			fd, &currentsector);
-		fprintf(stderr, " * image: %d virtual sectors @ sector 0x%x\n",
-			imagesectors, imagesector);
-
-		close(bootfd);
-	}
-
-	/* write out all the file data */
-
-	filesector = currentsector;
-	fprintf(stderr, " * writing file data\n");
-	writedata(NULL, &root, fd, &currentsector, 0,
-		(struct dir *) &pvd.rootrecord, sizeof(pvd.rootrecord),
-		remove_after);
-
-	/* write out all the dir data */
-
-	dirsector = currentsector;
-	fprintf(stderr, " * writing dir data\n");
-	writedata(NULL, &root, fd, &currentsector, 1,
-		(struct dir *) &pvd.rootrecord, sizeof(pvd.rootrecord),
-			remove_after);
-	enddir = currentsector;
-	seeksector(fd, dirsector, &currentsector);
-	fprintf(stderr, " * rewriting dir data\n");
-	fflush(NULL);
-	writedata(NULL, &root, fd, &currentsector, 1,
-		(struct dir *) &pvd.rootrecord, sizeof(pvd.rootrecord),
-			remove_after);
-	if(currentsector != enddir) {
-		fprintf(stderr, "warning: inconsistent directories - "
-			"I have a bug! iso may be broken.\n");
-	}
-
-	/* now write the path table in both formats */
-
-	fprintf(stderr, " * writing big-endian path table\n");
-	bigpath = currentsector;
-	currentsector += makepathtables(&root, 0, &pathbytes, fd);
-
-	fprintf(stderr, " * writing little-endian path table\n");
-	littlepath = currentsector;
-	currentsector += makepathtables(&root, 1, &pathbytes, fd);
-
-	/* this is the size of the iso filesystem for use in the pvd later */
-
-	nsectors = currentsector;
-	both32((unsigned char *) pvd.sectors, nsectors);
-
-	/* *********** Filesystem writing done ************************* */
-
-	/* finish and rewrite the pvd. */
-	fprintf(stderr, " * rewriting pvd\n");
-	seekwritesector(fd, pvdsector, (char *) &pvd, &currentsector);
-
-	both32((unsigned char *) pvd.pathtable, pathbytes);
-	little32((unsigned char *) &pvd.first_little_pathtable_start, littlepath);
-	little32((unsigned char *) &pvd.first_big_pathtable_start, bigpath);
-
-	/* write root dir entry in pvd */
-	seeksector(fd, pvdsector, &currentsector);
-	Lseek(fd, (int)((char *) &pvd.rootrecord - (char *) &pvd), SEEK_CUR);
-	if(write_direntry(CURRENTDIR, root.startsector, root.bytesize,
-		root.isdir, fd) > sizeof(pvd.rootrecord)) {
-		fprintf(stderr, "warning: unexpectedly large root record\n");
-	}
-
-	if(bootimage) {
-		fprintf(stderr, " * rewriting boot catalog\n");
-		seeksector(fd, bootcatalogsector, &currentsector);
-		writebootcatalog(fd, &currentsector, imagesector, imagesectors);
-
-		/* finish and rewrite the boot record volume descriptor */
-		fprintf(stderr, " * rewriting the boot rvd\n");
-		seeksector(fd, bootvolumesector, &currentsector);
-		writebootrecord(fd, &currentsector, bootcatalogsector);
-	}
-
-	fprintf(stderr, " * all ok\n");
-
-	return 0;
-}
-
-int get_system_type(int fd)
-{
-	off_t old_pos;
-	size_t size;
-	ssize_t r;
-	int type;
-	struct part_entry *partp;
-	unsigned char bootsector[512];
-
-	errno= 0;
-	old_pos= lseek(fd, SEEK_SET, 0);
-	if (old_pos == -1 && errno != 0)
-	{
-		fprintf(stderr, "bootimage file is not seekable: %s\n",
-			strerror(errno));
-		exit(1);
-	}
-	size= sizeof(bootsector);
-	r= read(fd, bootsector, size);
-	if (r != size)
-	{
-		fprintf(stderr, "error reading bootimage file: %s\n",
-			r < 0 ? strerror(errno) : "unexpected EOF");
-		exit(1);
-	}
-	if (bootsector[size-2] != 0x55 && bootsector[size-1] != 0xAA)
-	{
-		fprintf(stderr, "bad magic in bootimage file\n");
-		exit(1);
-	}
-
-	partp= (struct part_entry *)&bootsector[PART_TABLE_OFF];
-	type= partp->sysind;
-	if (type == NO_PART)
-	{
-		fprintf(stderr, "first partition table entry is unused\n");
-		exit(1);
-	}
-	if (!(partp->bootind & ACTIVE_FLAG))
-	{
-		fprintf(stderr, "first partition table entry is not active\n");
-		exit(1);
-	}
-
-	lseek(fd, SEEK_SET, old_pos);
-	return type;
-}
Index: trunk/minix/commands/simple/xargs.c
===================================================================
--- trunk/minix/commands/simple/xargs.c	(revision 9)
+++ 	(revision )
@@ -1,424 +1,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * John B. Roll Jr.
- *
- * 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)xargs.c	5.11 (Berkeley) 6/19/91";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <limits.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#if __minix
-#define _PATH_ECHO	"/bin/echo"
-#else
-#include "pathnames.h"
-#endif
-
-#ifndef ARG_MAX
-#define ARG_MAX		(sizeof(int) == 2 ? 4096 : 128 * 1024)
-#endif
-
-int exit_status = 0;
-int tflag;
-void err(const char *, ...);
-void run(char **argv);
-void usage(void);
-
-int main(int argc, char **argv)
-{
-	extern int optind;
-	extern char *optarg;
-	register int ch;
-	register char *p, *bbp, *ebp, **bxp, **exp, **xp;
-	int cnt, indouble, insingle, nargs, nflag, nline, xflag, zflag;
-	char **av, *argp;
-
-	/*
-	 * POSIX.2 limits the exec line length to ARG_MAX - 2K.  Running that
-	 * caused some E2BIG errors, so it was changed to ARG_MAX - 4K.  Given
-	 * that the smallest argument is 2 bytes in length, this means that
-	 * the number of arguments is limited to:
-	 *
-	 *	 (ARG_MAX - 4K - LENGTH(utility + arguments)) / 2.
-	 *
-	 * We arbitrarily limit the number of arguments to 5000.  This is
-	 * allowed by POSIX.2 as long as the resulting minimum exec line is
-	 * at least LINE_MAX.  Realloc'ing as necessary is possible, but
-	 * probably not worthwhile.
-	 */
-#if !__minix || __minix_vmd
-	nargs = 5000;
-	nline = ARG_MAX - 4 * 1024;
-#else
-	/* Things are more cramped under standard Minix. */
-	nargs = 80 * sizeof(int);
-	nline = ARG_MAX - 512 * sizeof(int);
-#endif
-	nflag = xflag = zflag = 0;
-	while ((ch = getopt(argc, argv, "n:s:tx0")) != EOF)
-		switch(ch) {
-		case 'n':
-			nflag = 1;
-			if ((nargs = atoi(optarg)) <= 0)
-				err("illegal argument count");
-			break;
-		case 's':
-			nline = atoi(optarg);
-			break;
-		case 't':
-			tflag = 1;
-			break;
-		case 'x':
-			xflag = 1;
-			break;
-		case '0':
-			zflag = 1;
-			break;
-		case '?':
-		default:
-			usage();
-	}
-	argc -= optind;
-	argv += optind;
-
-	if (xflag && !nflag)
-		usage();
-
-	/*
-	 * Allocate pointers for the utility name, the utility arguments,
-	 * the maximum arguments to be read from stdin and the trailing
-	 * NULL.
-	 */
-	if (!(av = bxp =
-	    malloc((u_int)(1 + argc + nargs + 1) * sizeof(char **))))
-		err("%s", strerror(errno));
-
-	/*
-	 * Use the user's name for the utility as argv[0], just like the
-	 * shell.  Echo is the default.  Set up pointers for the user's
-	 * arguments.
-	 */
-	if (!*argv)
-		cnt = strlen(*bxp++ = _PATH_ECHO);
-	else {
-		cnt = 0;
-		do {
-			cnt += strlen(*bxp++ = *argv) + 1;
-		} while (*++argv);
-	}
-
-	/*
-	 * Set up begin/end/traversing pointers into the array.  The -n
-	 * count doesn't include the trailing NULL pointer, so the malloc
-	 * added in an extra slot.
-	 */
-	exp = (xp = bxp) + nargs;
-
-	/*
-	 * Allocate buffer space for the arguments read from stdin and the
-	 * trailing NULL.  Buffer space is defined as the default or specified
-	 * space, minus the length of the utility name and arguments.  Set up
-	 * begin/end/traversing pointers into the array.  The -s count does
-	 * include the trailing NULL, so the malloc didn't add in an extra
-	 * slot.
-	 */
-	nline -= cnt;
-	if (nline <= 0)
-		err("insufficient space for command");
-
-	if (!(bbp = malloc((u_int)nline + 1)))
-		err("%s", strerror(errno));
-	ebp = (argp = p = bbp) + nline - 1;
-
-	if (zflag) {
-		/* Read pathnames terminated by null bytes as produced by
-		 * find ... -print0.  No comments in this code, see further
-		 * below.
-		 */
-		for (;;)
-			switch(ch = getchar()) {
-			case EOF:
-				if (p == bbp)
-					exit(exit_status);
-
-				if (argp == p) {
-					*xp = NULL;
-					run(av);
-					exit(exit_status);
-				}
-				/*FALL THROUGH*/
-			case '\0':
-				if (argp == p)
-					continue;
-
-				*p = '\0';
-				*xp++ = argp;
-
-				if (xp == exp || p == ebp || ch == EOF) {
-					if (xflag && xp != exp && p == ebp)
-						err(
-					   "insufficient space for arguments");
-					*xp = NULL;
-					run(av);
-					if (ch == EOF)
-						exit(exit_status);
-					p = bbp;
-					xp = bxp;
-				} else
-					++p;
-				argp = p;
-				break;
-			default:
-				if (p < ebp) {
-					*p++ = ch;
-					break;
-				}
-
-				if (bxp == xp)
-					err("insufficient space for argument");
-				if (xflag)
-					err("insufficient space for arguments");
-
-				*xp = NULL;
-				run(av);
-				xp = bxp;
-				cnt = ebp - argp;
-				bcopy(argp, bbp, cnt);
-				p = (argp = bbp) + cnt;
-				*p++ = ch;
-				break;
-			}
-		/* NOTREACHED */
-	}
-
-	for (insingle = indouble = 0;;)
-		switch(ch = getchar()) {
-		case EOF:
-			/* No arguments since last exec. */
-			if (p == bbp)
-				exit(exit_status);
-
-			/* Nothing since end of last argument. */
-			if (argp == p) {
-				*xp = NULL;
-				run(av);
-				exit(exit_status);
-			}
-			goto arg1;
-		case ' ':
-		case '\t':
-			/* Quotes escape tabs and spaces. */
-			if (insingle || indouble)
-				goto addch;
-			goto arg2;
-		case '\n':
-			/* Empty lines are skipped. */
-			if (argp == p)
-				continue;
-
-			/* Quotes do not escape newlines. */
-arg1:			if (insingle || indouble)
-				 err("unterminated quote");
-
-arg2:			*p = '\0';
-			*xp++ = argp;
-
-			/*
-			 * If max'd out on args or buffer, or reached EOF,
-			 * run the command.  If xflag and max'd out on buffer
-			 * but not on args, object.
-			 */
-			if (xp == exp || p == ebp || ch == EOF) {
-				if (xflag && xp != exp && p == ebp)
-					err("insufficient space for arguments");
-				*xp = NULL;
-				run(av);
-				if (ch == EOF)
-					exit(exit_status);
-				p = bbp;
-				xp = bxp;
-			} else
-				++p;
-			argp = p;
-			break;
-		case '\'':
-			if (indouble)
-				goto addch;
-			insingle = !insingle;
-			break;
-		case '"':
-			if (insingle)
-				goto addch;
-			indouble = !indouble;
-			break;
-		case '\\':
-			/* Backslash escapes anything, is escaped by quotes. */
-			if (!insingle && !indouble && (ch = getchar()) == EOF)
-				err("backslash at EOF");
-			/* FALLTHROUGH */
-		default:
-addch:			if (p < ebp) {
-				*p++ = ch;
-				break;
-			}
-
-			/* If only one argument, not enough buffer space. */
-			if (bxp == xp)
-				err("insufficient space for argument");
-			/* Didn't hit argument limit, so if xflag object. */
-			if (xflag)
-				err("insufficient space for arguments");
-
-			*xp = NULL;
-			run(av);
-			xp = bxp;
-			cnt = ebp - argp;
-			bcopy(argp, bbp, cnt);
-			p = (argp = bbp) + cnt;
-			*p++ = ch;
-			break;
-		}
-	/* NOTREACHED */
-}
-
-void run(char **argv)
-{
-	register char **p;
-	pid_t pid;
-	int noinvoke;
-	int status;
-	int pfd[2];
-
-	if (tflag) {
-		(void)fprintf(stderr, "%s", *argv);
-		for (p = argv + 1; *p; ++p)
-			(void)fprintf(stderr, " %s", *p);
-		(void)fprintf(stderr, "\n");
-		(void)fflush(stderr);
-	}
-	if (pipe(pfd) < 0) err("pipe: %s", strerror(errno));
-
-	switch(pid = fork()) {
-	case -1:
-		err("fork: %s", strerror(errno));
-	case 0:
-		close(pfd[0]);
-		fcntl(pfd[1], F_SETFD, fcntl(pfd[1], F_GETFD) | FD_CLOEXEC);
-
-		execvp(argv[0], argv);
-		noinvoke = (errno == ENOENT) ? 127 : 126;
-		(void)fprintf(stderr,
-		    "xargs: %s exec failed: %s.\n", argv[0], strerror(errno));
-
-		/* Modern way of returning noinvoke instead of a dirty vfork()
-		 * trick:					(kjb)
-		 */
-		write(pfd[1], &noinvoke, sizeof(noinvoke));
-		_exit(-1);
-	}
-	close(pfd[1]);
-	if (read(pfd[0], &noinvoke, sizeof(noinvoke)) < sizeof(noinvoke))
-		noinvoke = 0;
-	close(pfd[0]);
-
-	pid = waitpid(pid, &status, 0);
-	if (pid == -1)
-		err("waitpid: %s", strerror(errno));
-
-	/*
-	 * If we couldn't invoke the utility or the utility didn't exit
-	 * properly, quit with 127 or 126 respectively.
-	 */
-	if (noinvoke)
-		exit(noinvoke);
-
-	/*
-	 * According to POSIX, we have to exit if the utility exits with
-	 * a 255 status, or is interrupted by a signal.   xargs is allowed
-	 * to return any exit status between 1 and 125 in these cases, but
-	 * we'll use 124 and 125, the same values used by GNU xargs.
-	 */
-	if (WIFEXITED(status)) {
-		if (WEXITSTATUS (status) == 255) {
-			fprintf (stderr, "xargs: %s exited with status 255\n",
-				 argv[0]);
-			exit(124);
-		} else if (WEXITSTATUS (status) != 0) {
-			exit_status = 123;
-		}
-	} else if (WIFSTOPPED (status)) {
-		fprintf (stderr, "xargs: %s terminated by signal %d\n",
-			 argv[0], WSTOPSIG (status));
-		exit(125);
-	} else if (WIFSIGNALED (status)) {
-		fprintf (stderr, "xargs: %s terminated by signal %d\n",
-			 argv[0], WTERMSIG (status));
-		exit(125);
-	}
-}
-
-void usage(void)
-{
-	(void)fprintf(stderr,
-"usage: xargs [-t0] [[-x] -n number] [-s size] [utility [argument ...]]\n");
-	exit(1);
-}
-
-void err(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	(void)fprintf(stderr, "xargs: ");
-	(void)vfprintf(stderr, fmt, ap);
-	va_end(ap);
-	(void)fprintf(stderr, "\n");
-	exit(1);
-	/* NOTREACHED */
-}
Index: trunk/minix/commands/simple/yes.c
===================================================================
--- trunk/minix/commands/simple/yes.c	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-/*	yes 1.4 - print 'y' or argv[1] continuously.	Author: Kees J. Bot
- *								15 Apr 1989
- */
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-int main(int argc, char **argv)
-{
-	char *yes;
-	static char y[] = "y";
-	int n;
-
-	yes= argc == 1 ? y : argv[1];
-
-	n= strlen(yes);
-		
-	yes[n++]= '\n';
-
-	while (write(1, yes, n) != -1) {}
-	exit(1);
-}
Index: trunk/minix/commands/syslogd/.depend
===================================================================
--- trunk/minix/commands/syslogd/.depend	(revision 9)
+++ 	(revision )
@@ -1,94 +1,0 @@
-
-logger.o:	/usr/include/ansi.h
-logger.o:	/usr/include/ctype.h
-logger.o:	/usr/include/errno.h
-logger.o:	/usr/include/minix/sys_config.h
-logger.o:	/usr/include/minix/type.h
-logger.o:	/usr/include/stdio.h
-logger.o:	/usr/include/stdlib.h
-logger.o:	/usr/include/string.h
-logger.o:	/usr/include/sys/dir.h
-logger.o:	/usr/include/sys/types.h
-logger.o:	/usr/include/syslog.h
-logger.o:	/usr/include/unistd.h
-logger.o:	logger.c
-
-syslog.o:	/usr/include/ansi.h
-syslog.o:	/usr/include/errno.h
-syslog.o:	/usr/include/fcntl.h
-syslog.o:	/usr/include/minix/ioctl.h
-syslog.o:	/usr/include/minix/sys_config.h
-syslog.o:	/usr/include/minix/type.h
-syslog.o:	/usr/include/net/gen/in.h
-syslog.o:	/usr/include/net/gen/inet.h
-syslog.o:	/usr/include/net/gen/netdb.h
-syslog.o:	/usr/include/net/gen/udp.h
-syslog.o:	/usr/include/net/gen/udp_io.h
-syslog.o:	/usr/include/net/hton.h
-syslog.o:	/usr/include/net/ioctl.h
-syslog.o:	/usr/include/net/netlib.h
-syslog.o:	/usr/include/stdarg.h
-syslog.o:	/usr/include/stdio.h
-syslog.o:	/usr/include/stdlib.h
-syslog.o:	/usr/include/string.h
-syslog.o:	/usr/include/sys/dir.h
-syslog.o:	/usr/include/sys/ioc_cmos.h
-syslog.o:	/usr/include/sys/ioc_disk.h
-syslog.o:	/usr/include/sys/ioc_file.h
-syslog.o:	/usr/include/sys/ioc_memory.h
-syslog.o:	/usr/include/sys/ioc_scsi.h
-syslog.o:	/usr/include/sys/ioc_sound.h
-syslog.o:	/usr/include/sys/ioc_tape.h
-syslog.o:	/usr/include/sys/ioc_tty.h
-syslog.o:	/usr/include/sys/ioctl.h
-syslog.o:	/usr/include/sys/types.h
-syslog.o:	/usr/include/syslog.h
-syslog.o:	/usr/include/time.h
-syslog.o:	/usr/include/unistd.h
-syslog.o:	syslog.c
-
-syslog_test.o:	/usr/include/ansi.h
-syslog_test.o:	/usr/include/minix/sys_config.h
-syslog_test.o:	/usr/include/minix/type.h
-syslog_test.o:	/usr/include/sys/types.h
-syslog_test.o:	/usr/include/syslog.h
-syslog_test.o:	/usr/include/unistd.h
-syslog_test.o:	syslog_test.c
-
-syslogd.o:	/usr/include/ansi.h
-syslogd.o:	/usr/include/ctype.h
-syslogd.o:	/usr/include/errno.h
-syslogd.o:	/usr/include/fcntl.h
-syslogd.o:	/usr/include/limits.h
-syslogd.o:	/usr/include/minix/ioctl.h
-syslogd.o:	/usr/include/minix/sys_config.h
-syslogd.o:	/usr/include/minix/type.h
-syslogd.o:	/usr/include/net/gen/in.h
-syslogd.o:	/usr/include/net/gen/netdb.h
-syslogd.o:	/usr/include/net/gen/udp.h
-syslogd.o:	/usr/include/net/gen/udp_io.h
-syslogd.o:	/usr/include/net/hton.h
-syslogd.o:	/usr/include/net/ioctl.h
-syslogd.o:	/usr/include/net/netlib.h
-syslogd.o:	/usr/include/signal.h
-syslogd.o:	/usr/include/stdio.h
-syslogd.o:	/usr/include/stdlib.h
-syslogd.o:	/usr/include/string.h
-syslogd.o:	/usr/include/sys/dir.h
-syslogd.o:	/usr/include/sys/ioc_cmos.h
-syslogd.o:	/usr/include/sys/ioc_disk.h
-syslogd.o:	/usr/include/sys/ioc_file.h
-syslogd.o:	/usr/include/sys/ioc_memory.h
-syslogd.o:	/usr/include/sys/ioc_scsi.h
-syslogd.o:	/usr/include/sys/ioc_sound.h
-syslogd.o:	/usr/include/sys/ioc_tape.h
-syslogd.o:	/usr/include/sys/ioc_tty.h
-syslogd.o:	/usr/include/sys/ioctl.h
-syslogd.o:	/usr/include/sys/select.h
-syslogd.o:	/usr/include/sys/time.h
-syslogd.o:	/usr/include/sys/types.h
-syslogd.o:	/usr/include/sys/wait.h
-syslogd.o:	/usr/include/syslog.h
-syslogd.o:	/usr/include/time.h
-syslogd.o:	/usr/include/unistd.h
-syslogd.o:	syslogd.c
Index: trunk/minix/commands/syslogd/CHANGELOG
===================================================================
--- trunk/minix/commands/syslogd/CHANGELOG	(revision 9)
+++ 	(revision )
@@ -1,17 +1,0 @@
-Version 1.1	Oct. 28, 2000
-  -	first release for testing.
-
-Version 1.2	Jan. 23, 2001
-  -	Changed pidfile directory to '/usr/spool/locks'
-	so at boot old file is deleted.
-  -	Changed the 'debug' variable to 'DbgOpt' so 'debug'
-	can be a preprocessor define from Makefile.
-
-Version 1.3
-  -	Changes for Minix 3.0
-  -	Changed pidfile to /var/run/syslogd.pid and added code
-	for setting pathname from Makefile
-  -	Merged code from usyslogd.c to handle kernel messages.
-  -	Reworked Makefile to make a correct installation
-
-$Id: CHANGELOG,v 1.1 2006/04/03 13:07:42 beng Exp $
Index: trunk/minix/commands/syslogd/Makefile
===================================================================
--- trunk/minix/commands/syslogd/Makefile	(revision 9)
+++ 	(revision )
@@ -1,44 +1,0 @@
-##
-##  @(#)Makefile	1.00	Jan. 11, 2000
-##
-##  Makefile for syslogd/klogd
-##  $Id: Makefile,v 1.2 2006/04/04 12:52:22 beng Exp $
-
-BINDIR	= /usr/bin
-
-CC	= exec cc
-RM	= rm -f
-EXTRA	= -DPIDFILE=\"/var/run/syslogd.pid\"
-CPPFLAGS= -D_MINIX -D_POSIX_SOURCE -Ddebug=0 $(EXTRA) -I.
-CFLAGS	= -m -O $(CPPFLAGS)
-MKDEP	= mkdep "$(CC) -E $(CPPFLAGS)"
-LDFLAGS = -i -o $@
-TARGETS = logger syslogd
-
-SRCS =	logger.c syslog.c syslog_test.c syslogd.c
-OBJS =	logger.o syslog.o syslog_test.o syslogd.o
-
-all: $(TARGETS)	
-
-syslogd:	syslogd.o
-	$(CC) $? $(LDFLAGS)
-	@install -S 8kw $@
-
-syslog_test: syslog_test.o syslog.o
-	$(CC) syslog_test.o syslog.o $(LDFLAGS)
-	@install -S 2kw $@
-
-logger: logger.o syslog.o
-	$(CC) logger.o syslog.o $(LDFLAGS)
-	@install -S 2kw $@
-
-clean:
-	$(RM) $(OBJS) $(TARGETS) syslog_test *.BAK core
-
-install:	$(BINDIR)/logger $(BINDIR)/syslog_test $(BINDIR)/syslogd
-$(BINDIR)/logger:	logger
-	install -cs -m 755 -o bin -g operator $? $@
-$(BINDIR)/syslog_test:	syslog_test
-	install -cs -m 755 -o bin -g operator $? $@
-$(BINDIR)/syslogd:	syslogd
-	install -cs -m 700 -o root -g operator $? $@
Index: trunk/minix/commands/syslogd/README
===================================================================
--- trunk/minix/commands/syslogd/README	(revision 9)
+++ 	(revision )
@@ -1,69 +1,0 @@
-This is just syslogd and the test programs now. syslog() is in libc 4.2
-syslogd has been changed to use /proc/kmsg for kernel messages. It also
-avoids making any terminal it opens its controlling terminal. Otherwise
-we have a dodgy race condition between processes connecting to terminals
-which can result in the terminal having the wrong group at the wrong time.
-The syslog() in libc 4.2 needs changing to use O_NOCTTY on its opens as
-well.
-
-Mike Jagdis	Internet: jaggy@purplet.demon.co.uk
-		FidoNet:  Mike Jagdis, 2:252/305
-
----------------------------------------------------------------------------
-
-                           Syslogd and Syslog.o
-
-These are the syslogd and syslog ported from 4.3BSD (that's the new one with
-the *very* flexible config file).  
-
-Syslogd is essentially unchanged from the 4.3BSD, with the exception that
-*nothing* is ever logged to the console (BAD thing to do on a UNIXpc).  You
-can configure it (via /etc/syslog.conf) to log messages in different
-logfiles (depending upon the sender's facility code and the priority), log
-to users' terminals (same dependancies), and if things get real bad, it can
-do a wall (write-all; same dependancies).
-
-Syslog is really only modified in that it uses UDP datagrams because I had
-no luck at all using UNIX domain sockets on the 3B1.  See syslog.h for
-facility codes and priorities that can be used.
-
-
-BUGS:
-Messages from facilities LOG_KERN, LOG_USER, and LOG_PRT never can be
-wall-ed, no matter how high the priority.  I'm still trying to decide if
-this is a bug or a feature. :-)
-
-
-ALSO INCLUDED:
-
-Syslog_test, sendlog (to use from shell scripts) and logger (for use in
-shell script also).
-
-NEEDED:
-
-The resolver routines in libresolv.a are not needed, but allow you to log to
-hosts not present in /etc/hosts and to accept logging from same.
-
------------------------------------------------------------------------
-
-Fixed up UNIX domain socket code, added Linux specific code to read messages
-from the kernel.
-
-The #ifdefs are now :-
-
-SYSLOG_INET	listen on a UDP socket (syslogd)
-		log via UDP (syslog library call)
-
-SYSLOG_UNIXAF	listen on a UNIX domain socker (syslogd)
-		log via UNIX domain (syslogd library)
-
-SYSLOG_KERNEL	fork a second copy to read kernel messages using
-		syslog system call.
-
-syslogd should be built with one or more of these flags, libsyslog.a should
-be built with SYSLOG_INET or SYSLOG_UNIXAF, SYSLOG_INET is used in preference
-to SYSLOG_UNIXAF.
-
-readlog is a program which reads from the kernel and records the messages
-it finds in syslogd via the normal library call interface, it can be run
-instead of building syslogd with SYSLOG_KERNEL.
Index: trunk/minix/commands/syslogd/README.minix
===================================================================
--- trunk/minix/commands/syslogd/README.minix	(revision 9)
+++ 	(revision )
@@ -1,28 +1,0 @@
-
-
-   This is the porting to Minix of the "syslogd" facility
-   available on many other *nix systems.
-
-   Since I' m still using an old 286 machine for my Minix
-   environment, I choosed to start from an old implementation
-   which has only the basic features. The result is a smaller
-   program, more suitable for 16 bits machines.
-
-   The file syslog.c should be included in C compiler library
-   (libc.a) or directly linked with prorams requiring syslog.
-
-   If you choose the former solution, you must recreate the 
-   library.  After having copied the file syslog.c to the 
-   directory '/usr/src/libs/other' you have to modify the 
-   Makefile in this directory adding syslog.c.
-
-   Then issue a 'make' command in the '/usr/src/libs' and wait 
-   a while.  Then issue 'make install' to install the new object.
-
-   NOTE:   The network must be configured, up and running for
-	   the package to work
-
-   Giovanni Falzoni <gfalzoni@inwind.it>
-
-   $Id: README.minix,v 1.1 2006/04/03 13:07:42 beng Exp $
-
Index: trunk/minix/commands/syslogd/logger.c
===================================================================
--- trunk/minix/commands/syslogd/logger.c	(revision 9)
+++ 	(revision )
@@ -1,188 +1,0 @@
-/* Copyright (c) 1983, 1988, 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. 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.
- *
- * #ifndef lint
- * char copyright[] =
- * "@(#) Copyright (c) 1983 Regents of the University of California.\n\
- *  All rights reserved.\n";
- * #endif
- *
- * #ifndef lint
- * static char sccsid[] = "@(#)logger.c	6.8 (Berkeley) 6/29/88";
- * #endif
- *
- * Porting to Minix by G. Falzoni <gfalzoni@inwind.it>
- * $Id: logger.c,v 1.1 2006/04/03 13:07:42 beng Exp $
- */
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-
-/*
-** 	LOGGER -- read and log utility
-**
-**	This program reads from an input and arranges to write the
-**	result on the system log, along with a useful tag.
-*/
-
-#define  SYSLOG_NAMES
-#include <syslog.h>
-
-/*
-**	Name:		void bailout(char *msg, char *arg);
-**	Function:	Handles error exit.
-*/
-void bailout(const char *msg, const char *arg)
-{
-
-  fprintf(stderr, "logger: %s %s\n", msg, arg);
-  exit(EXIT_FAILURE);
-}
-
-/*
-**	Name:		int decode(char *name, struct code * codetab);
-**	Function:	Decodes a name to the equivalent priority/facility.
-*/
-int decode(char *name, const struct _code * codetab)
-{
-  const struct _code *c;
-
-  if (isdigit(*name)) return(atoi(name));
-
-  for (c = codetab; c->c_name; c++)
-	if (!strcasecmp(name, c->c_name)) return(c->c_val);
-
-  return(-1);
-}
-
-/*
-**	Name:		int pencode(char *s);
-**	Function:	Decode a symbolic name (facility/priority)
-**			to a numeric value.
-*/
-int pencode(char *s)
-{
-  char *save;
-  int fac, lev;
-
-  for (save = s; *s && *s != '.'; ++s);
-  if (*s) {
-	*s = '\0';
-	fac = decode(save, FacNames);
-	if (fac < 0) bailout("unknown facility name:", save);
-	*s++ = '.';
-  } else {
-	fac = 0;
-	s = save;
-  }
-  lev = decode(s, PriNames);
-  if (lev < 0) bailout("unknown priority name:", save);
-  return((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
-}
-
-/*
-**	Name:		int main(int argc, char **argv);
-**	Function:	Main entry for logger.
-*/
-int main(int argc, char **argv)
-{
-  int pri = LOG_NOTICE;
-  int ch, logflags = 0;
-  char *tag, buf[200];
-  static const char usage[] =
-  "[-i] [-f file] [-p pri] [-t tag] [ message ... ]";
-
-  tag = NULL;
-  while ((ch = getopt(argc, argv, "f:ip:t:")) != EOF) {
-	switch ((char) ch) {
-	    case 'f':		/* file to log */
-		if (freopen(optarg, "r", stdin) == NULL) {
-			bailout(strerror(errno), optarg);
-		}
-		break;
-	    case 'i':		/* log process id also */
-		logflags |= LOG_PID;
-		break;
-	    case 'p':		/* priority */
-		pri = pencode(optarg);
-		break;
-	    case 't':		/* tag */
-		tag = optarg;
-		break;
-	    case '?':
-	    default:	bailout(usage, "");	break;
-	}
-  }
-  argc -= optind;
-  argv += optind;
-
-  /* Setup for logging */
-  openlog(tag ? tag : getlogin(), logflags, 0);
-  fclose(stdout);
-
-  if (argc > 0) {		/* Log input line if appropriate */
-	char *p, *endp;
-	int len;
-
-	for (p = buf, endp = buf + sizeof(buf) - 1;;) {
-		len = strlen(*argv);
-		if (p + len < endp && p > buf) {
-			*--p = '\0';
-			syslog(pri, buf);
-			p = buf;
-		}
-		if (len > sizeof(buf) - 1) {
-			syslog(pri, *argv++);
-			if (!--argc) break;
-		} else {
-			memcpy(p, *argv++, len);
-			p += len;
-			if (!--argc) break;
-			*p++ = ' ';
-			*--p = '\0';
-		}
-	}
-	if (p != buf) {
-		*p = '\0';
-		syslog(pri, buf);
-	}
-  } else			/* Main loop */
-	while (fgets(buf, sizeof(buf), stdin) != NULL) syslog(pri, buf);
-
-  return EXIT_SUCCESS;
-}
-
-/** logger.c **/
Index: trunk/minix/commands/syslogd/syslog.c
===================================================================
--- trunk/minix/commands/syslogd/syslog.c	(revision 9)
+++ 	(revision )
@@ -1,167 +1,0 @@
-/* Copyright (c) 1983, 1988, 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. 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.
- *
- * #if defined(LIBC_SCCS) && !defined(lint)
- * static char sccsid[] = "@(#)syslog.c    8.4 (Berkeley) 3/18/94";
- * #endif
- *
- * Author: Eric Allman
- * Modified to use UNIX domain IPC by Ralph Campbell
- * Patched March 12, 1996 by A. Ian Vogelesang <vogelesang@hdshq.com>
- * Rewritten by Martin Mares <mj@atrey.karlin.mff.cuni.cz> on May 14, 1997
- * Rewritten by G. Falzoni <gfalzoni@inwind.it> for porting to Minix
- *
- * $Id: syslog.c,v 1.1 2006/04/03 13:07:42 beng Exp $
- */
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <time.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <sys/ioctl.h>
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_io.h>
-#include <net/gen/netdb.h>
-#include <errno.h>
-#include <net/gen/inet.h>
-
-static int LogPid = (-1);
-static int nfd = (-1);
-static int LogFacility = LOG_USER;
-static int LogFlags = 0;
-static char TagBuffer[40] = "syslog";
-
-/*
-** OPENLOG -- open system log
-** 	- establishes a channel to syslogd using UDP device
-**	  (port 514 is used _ syslog/udp)
-**	- stores program tag (if not NULL) and other options
-**	  for use by syslog
-*/
-void openlog(const char *ident, int option, int facility)
-{
-  struct nwio_udpopt udpopt;
-
-  /* Stores logging flags */
-  LogFlags = option & (LOG_PID | LOG_PERROR | LOG_CONS);
-  /* Stores process id. if LOG_PID was specified */
-  if (option & LOG_PID) LogPid = getpid();
-  /* Stores the requested facility */
-  LogFacility = facility;
-  /* Stores log tag if supplied */
-  if (ident != NULL && *ident != '0' && ident != TagBuffer) {
-	strncpy(TagBuffer, ident, sizeof(TagBuffer));
-	TagBuffer[sizeof(TagBuffer) - 1] = '0';
-  }
-
-  /* Opens channel to syslog daemon via UDP device */
-  /* Static values used to minimize code */
-  if (option & LOG_NDELAY) {
-	/* Opens UDP device */
-	if ((nfd = open(UDP_DEVICE, O_RDWR)) < 0) {
-		 /* Report error */ ;
-	}
-	/* Sets options for UDP device */
-	udpopt.nwuo_flags = NWUO_SHARED | NWUO_LP_SET | NWUO_DI_LOC |
-		NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET |
-		NWUO_RWDATONLY | NWUO_DI_IPOPT;
-	udpopt.nwuo_locaddr = udpopt.nwuo_remaddr = htonl(0x7F000001L);
-	udpopt.nwuo_locport = udpopt.nwuo_remport = htons(514);
-	if (ioctl(nfd, NWIOSUDPOPT, &udpopt) < 0 ||
-	    ioctl(nfd, NWIOGUDPOPT, &udpopt) < 0) {
-		 /* Report error */ ;
-	}
-  }
-  return;
-}
-
-/*
-**  SYSLOG -- print message on log file
-**
-**  This routine looks a lot like printf, except that it outputs to the
-**  log file instead of the standard output.  Also:
-**	- adds a timestamp,
-**	- prints the module name in front of the message,
-**	- has some other formatting types (or will sometime),
-**	- adds a newline on the end of the message.
-**
-** The output of this routine is intended to be read by syslogd(8).
-*/
-void syslog(int lprty, const char *msg,...)
-{
-  time_t now;
-  char buff[512];
-  int len, rc;
-  va_list ap;
-
-  /* First log message open chnnel to syslog */
-  if (nfd < 0) openlog(TagBuffer, LogFlags | LOG_NDELAY, LogFacility);
-  time(&now);
-  len = sprintf(buff, "<%d>%.15s %s: ",
-		LogFacility | lprty, ctime(&now) + 4, TagBuffer);
-  if (LogFlags & LOG_PID) {
-	len -= 2;
-	len += sprintf(buff + len, "[%d]: ", LogPid);
-  }
-  va_start(ap, msg);
-  len += vsprintf(buff + len, msg, ap);
-  va_end(ap);
-  rc = write(nfd, buff, len);
-  if ((rc != len && LogFlags & LOG_CONS) || LogFlags & LOG_PERROR) {
-	write(STDERR_FILENO, buff, len);
-	write(STDERR_FILENO, "\n", 1);
-  }
-  return;
-}
-
-/*
-**  CLOSELOG -- close access to syslogd
-**	- closes UDP channel
-**	- restores default values
-*/
-void closelog(void)
-{
-
-  close(nfd);
-  LogPid = nfd = -1;
-  LogFacility = LOG_USER;
-  LogFlags = 0;
-  return;
-}
-
-/** syslog.c **/
Index: trunk/minix/commands/syslogd/syslog_test.c
===================================================================
--- trunk/minix/commands/syslogd/syslog_test.c	(revision 9)
+++ 	(revision )
@@ -1,30 +1,0 @@
-/*
-**	syslog_test
-**
-**	Author:		Giovanni Falzoni <gfalzoni@inwind.it>
-**	$Id: syslog_test.c,v 1.1 2006/04/03 13:07:42 beng Exp $
-*/
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <syslog.h>
-
-/*
-**	SYSLOG TEST
-**	Very simple utility to test syslog facility.
-*/
-void main(void)
-{
-  int ix;
-
-  openlog("syslog_test", LOG_PID | LOG_NDELAY | LOG_PERROR | LOG_CONS, LOG_DAEMON);
-
-  for (ix = LOG_EMERG; ix <= LOG_DEBUG; ix += 1) {
-	sleep(2);
-	syslog(ix, "message from test program - log level %d", ix);
-  }
-  closelog();
-  return;
-}
-
-/** syslog_test.c **/
Index: trunk/minix/commands/syslogd/syslogd.c
===================================================================
--- trunk/minix/commands/syslogd/syslogd.c	(revision 9)
+++ 	(revision )
@@ -1,932 +1,0 @@
-/*
-**  Copyright (c) 1983, 1988
-**  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. 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.
-**
-**  #ifndef lint
-**  char copyright2[] =
-**  "@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\
-**   All rights reserved.\n";
-**  #endif
-**
-**  #ifndef lint
-**  static char sccsid[] = "@(#)syslogd.c	5.27 (Berkeley) 10/10/88";
-**  #endif
-**
-**  -----------------------------------------------------------------------
-**
-**  SYSLOGD -- log system messages
-**	This program implements a system log.
-**	It takes a series of lines and outputs them according to the setup
-**	defined in the configuration file.
-**	Each line may have a priority, signified as "<n>" as
-**	the first characters of the line.  If this is
-**	not present, a default priority is used.
-**
-**	To kill syslogd, send a signal 15 (terminate).
-**	A signal 1 (hup) will cause it to reread its configuration file.
-**
-**  Defined Constants:
-**	MAXLINE   -- the maximimum line length that can be handled.
-**	MAXSVLINE -- the length of saved messages (for filtering)
-**	DEFUPRI   -- the default priority for user messages
-**	DEFSPRI   -- the default priority for kernel messages
-**
-**  Author: Eric Allman
-**  extensive changes by Ralph Campbell
-**  more extensive changes by Eric Allman (again)
-**  changes by Steve Lord
-**
-**  Extensive rewriting by G. Falzoni <gfalzoni@inwind.it> for porting to Minix
-** 
-**  $Log: syslogd.c,v $
-**  Revision 1.3  2006/04/04 14:22:40  beng
-**  Fix
-**
-**  Revision 1.2  2006/04/04 14:18:16  beng
-**  Make syslogd work, even if it can only open klog and not udp or vice versa
-**  (but not neither)
-**
-**  Revision 1.1  2006/04/03 13:07:42  beng
-**  Kick out usyslogd in favour of syslogd Giovanni's syslogd port
-**
-**  Revision 1.3  2005/09/16 10:10:12  lsodgf0
-**  Rework for Minix 3.  Adds kernel logs from /dev/klogd
-**
-**  $Id: syslogd.c,v 1.3 2006/04/04 14:22:40 beng Exp $
-*/
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <time.h>
-#include <sys/ioctl.h>
-#include <sys/select.h>
-#include <sys/wait.h>
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_io.h>
-#include <net/gen/netdb.h>
-
-#define SYSLOG_NAMES
-#include <syslog.h>
-#define KLOGD 1
-/** Define following values to your requirements **/
-#define	MAXLINE		512	/* maximum line length */
-#define	MAXSVLINE	256	/* maximum saved line length */
-
-#define DEFUPRI		(LOG_USER|LOG_NOTICE)
-#define DEFSPRI 	(LOG_KERN|LOG_CRIT)
-
-/* Flags to logmsg() */
-#define IGN_CONS	0x001	/* don't print on console */
-#define SYNC_FILE	0x002	/* do fsync on file after printing */
-#define ADDDATE		0x004	/* add a date to the message */
-#define MARK		0x008	/* this message is a mark */
-
-#define	CTTY		"/dev/log"	/* Minix log device (console) */
-
-#define	dprintf	if(DbgOpt!=0)printf
-#if debug == 0
-#define DEBUG(statement)
-#else
-#define DEBUG(statement) statement
-#endif
-#if !defined PIDFILE
-#define PIDFILE	"/var/run/syslogd.pid"
-#endif
-
-#define UNAMESZ		8	/* length of a login name */
-#define MAXUNAMES	20	/* maximum number of user names */
-#define MAXFNAME	200	/* max file pathname length */
-#define MAXHOSTNAMELEN 	64	/* max length of FQDN host name */
-
-/* Intervals at which we flush out "message repeated" messages,
- * in seconds after previous message is logged.  After each flush,
- * we move to the next interval until we reach the largest.  */
-#define TIMERINTVL	30	/* interval for checking flush, mark */
-#define INTERVAL1 	30
-#define INTERVAL2 	60
-#define	MAXREPEAT ((sizeof(repeatinterval)/sizeof(repeatinterval[0]))-1)
-#define	REPEATTIME(f) ((f)->f_time+repeatinterval[(f)->f_repeatcount])
-#define	BACKOFF(f) {if(++(f)->f_repeatcount>MAXREPEAT)(f)->f_repeatcount=MAXREPEAT;}
-
-/* Values for f_type */
-#define F_UNUSED 	0	/* unused entry */
-#define F_FILE 		1	/* regular file */
-#define F_TTY 		2	/* terminal */
-#define F_CONSOLE 	3	/* console terminal */
-#define F_FORW 		4	/* remote machine */
-#define F_USERS 	5	/* list of users */
-#define F_WALL 		6	/* everyone logged on */
-
-#define max(a,b) ((a)>=(b)?(a):(b))
-
-/* This structure represents the files that will have log copies printed */
-struct filed {
-  struct filed *f_next;		/* next in linked list */
-  short f_type;			/* entry type, see below */
-  short f_file;			/* file descriptor */
-  time_t f_time;		/* time this was last written */
-  char f_pmask[LOG_NFACILITIES + 1];	/* priority mask */
-  union {
-	char f_uname[MAXUNAMES][UNAMESZ + 1];
-	char f_fname[MAXFNAME];
-  } f_un;
-  char f_prevline[MAXSVLINE];	/* last message logged */
-  char f_lasttime[16];		/* time of last occurrence */
-  char f_prevhost[MAXHOSTNAMELEN + 1];	/* host from which recd. */
-  int f_prevpri;		/* pri of f_prevline */
-  int f_prevlen;		/* length of f_prevline */
-  int f_prevcount;		/* repetition cnt of prevline */
-  int f_repeatcount;		/* number of "repeated" msgs */
-  int f_flags;			/* store some additional flags */
-};
-
-static const char *const TypeNames[] =
-{
- "UNUSED", "FILE", "TTY", "CONSOLE", "FORW", "USERS", "WALL", NULL,
-};
-
-static struct filed *Files = NULL;
-static struct filed consfile;
-static int DbgOpt = 0;		/* debug flag */
-static char LocalHostName[MAXHOSTNAMELEN + 1];	/* our hostname */
-static int Initialized = 0;	/* set when we have initialized ourselves */
-static int MarkInterval = 20 * 60;	/* interval between marks in seconds */
-static int MarkSeq = 0;		/* mark sequence number */
-static time_t now;
-
-static const char *ConfFile = "/etc/syslog.conf";
-static const char *PidFile = PIDFILE;	/* "/var/run/syslogd.pid" */
-static const char ctty[] = CTTY;
-
-static const char ProgName[] = "syslogd:";
-static const char version[] = "1.3 (Minix)";
-static const char usage[] =
- /* */ "usage:\tsyslogd [-d] [-m markinterval] [-f conf-file]\n"
-       "\t\t[-p listeningport] [-v] [-?]\n" ;
-static const int repeatinterval[] =
- /* */ {INTERVAL1, INTERVAL2,};	/* # of secs before flush */
-
-/*
-**  Name:	void wallmsg(struct filed *fLog, char *message);
-**  Function:	Write the specified message to either the entire
-**		world, or a list of approved users.
-*/
-void wallmsg(struct filed * fLog, char *message)
-{
-
-  return;
-}
-
-/*
-**  Name:	void fprintlog(struct filed *fLog, int flags, char *message);
-**  Function:
-*/
-void fprintlog(struct filed * fLog, int flags, char *message)
-{
-  int len;
-  char line[MAXLINE + 1];
-  char repbuf[80];
-
-  if (message == NULL) {
-	if (fLog->f_prevcount > 1) {
-		sprintf(repbuf, "last message repeated %d times", fLog->f_prevcount);
-		message = repbuf;
-	} else
-		message = fLog->f_prevline;
-  }
-  sprintf(line, "%s %s %s", fLog->f_lasttime, fLog->f_prevhost, message);
-  DEBUG(dprintf("Logging to %s", TypeNames[fLog->f_type]);)
-  fLog->f_time = now;
-  switch (fLog->f_type) {
-      case F_UNUSED:		/* */
-	DEBUG(dprintf("\n");)
-	break;
-      case F_CONSOLE:
-	if (flags & IGN_CONS) {
-      case F_FORW:		/* */
-		DEBUG(dprintf(" (ignored)\n");)
-		break;
-	}			/* else Fall Through */
-      case F_TTY:
-      case F_FILE:
-	DEBUG(dprintf(" %s\n", fLog->f_un.f_fname);)
-	strcat(line, fLog->f_type != F_FILE ? "\r\n" : "\n");
-	len = strlen(line);
-	if (write(fLog->f_file, line, len) != len) {
-		 /* Handle errors */ ;
-	} else if (flags & SYNC_FILE)
-		sync();
-	break;
-      case F_USERS:
-      case F_WALL:
-	DEBUG(dprintf("\n");)
-	strcat(line, "\r\n");
-	wallmsg(fLog, line);
-	break;
-  }
-  fLog->f_prevcount = 0;
-  return;
-}
-
-/*
-**  Name:	void logmsg(int pri, char *msg, char *from, int flags);
-**  Function:	Log a message to the appropriate log files, users, etc.
-**		based on the priority.
-*/
-void logmsg(int pri, char *msg, char *from, int flags)
-{
-  struct filed *f;
-  int fac, prilev;
-  int omask, msglen;
-  char *timestamp;
-
-  DEBUG(dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n", pri, flags, from, msg);)
-/*
-  omask = sigblock(__sigmask(SIGHUP) | __sigmask(SIGALRM));
-*/
-  /* Check to see if msg looks non-standard. */
-  msglen = strlen(msg);
-  if (msglen < 16 || msg[3] != ' ' || msg[6] != ' ' ||
-      msg[9] != ':' || msg[12] != ':' || msg[15] != ' ')
-	flags |= ADDDATE;
-
-  time(&now);
-  if (flags & ADDDATE)
-	timestamp = ctime(&now) + 4;
-  else {
-	timestamp = msg;
-	msg += 16;
-	msglen -= 16;
-  }
-
-  /* Extract facility and priority level */
-  fac = (flags & MARK) ? LOG_NFACILITIES : LOG_FAC(pri);
-  prilev = LOG_PRI(pri);
-
-  /* Log the message to the particular outputs */
-  if (!Initialized) {
-	/* Not yet initialized. Every message goes to console */
-	f = &consfile;
-	f->f_file = open(ctty, O_WRONLY | O_NOCTTY);
-	if (f->f_file >= 0) {
-		if (!DbgOpt) setsid();
-		fprintlog(f, flags, msg);
-		close(f->f_file);
-	}
-  } else {
-	for (f = Files; f; f = f->f_next) {
-
-		/* Skip messages that are incorrect priority */
-		if (f->f_pmask[fac] < prilev || f->f_pmask[fac] == INTERNAL_NOPRI)
-			continue;
-
-		if (f->f_type == F_CONSOLE && (flags & IGN_CONS)) continue;
-
-		/* Don't output marks to recently written files */
-		if ((flags & MARK) && (now - f->f_time) < MarkInterval / 2)
-			continue;
-
-		/* Suppress duplicate lines to this file */
-		if ((flags & MARK) == 0 && msglen == f->f_prevlen &&
-		    !strcmp(msg, f->f_prevline) &&
-		    !strcmp(from, f->f_prevhost)) {
-			strncpy(f->f_lasttime, timestamp, 15);
-			f->f_prevcount += 1;
-			DEBUG(dprintf("msg repeated %d times, %ld sec of %d\n",
-				f->f_prevcount, now - f->f_time,
-				repeatinterval[f->f_repeatcount]);)
-			/* If domark would have logged this by now,
-			 * flush it now (so we don't hold isolated
-			 * messages), but back off so we'll flush
-			 * less often in the future. */
-			if (now > REPEATTIME(f)) {
-				fprintlog(f, flags, (char *) NULL);
-				BACKOFF(f);
-			}
-		} else {
-			/* New line, save it */
-			if (f->f_prevcount) fprintlog(f, 0, (char *) NULL);
-			f->f_repeatcount = 0;
-			strncpy(f->f_lasttime, timestamp, 15);
-			strncpy(f->f_prevhost, from, sizeof(f->f_prevhost));
-			if (msglen < MAXSVLINE) {
-				f->f_prevlen = msglen;
-				f->f_prevpri = pri;
-				strcpy(f->f_prevline, msg);
-				fprintlog(f, flags, (char *) NULL);
-			} else {
-				f->f_prevline[0] = 0;
-				f->f_prevlen = 0;
-				fprintlog(f, flags, msg);
-			}
-		}
-	}
-  }
-
-/*
-  sigsetmask(omask);
-*/
-  return;
-}
-
-/*
-**  Name:	void logerror(char *type);
-**  Function:	Prints syslogd errors in some place.
-*/
-void logerror(char *type)
-{
-  char buf[100];
-
-  if (errno == 0) sprintf(buf, "%s %s", ProgName, type);
-
-  else if (errno >= _NERROR)
-	sprintf(buf, "%s %s - error %d", ProgName, type, errno);
-
-  else
-	sprintf(buf, "%s %s - %s", ProgName, type, strerror(errno));
-
-  errno = 0;
-  dprintf("%s\n", buf);
-  logmsg(LOG_SYSLOG | LOG_ERR, buf, LocalHostName, ADDDATE);
-  return;
-}
-
-/*
-**  Name:	void die(int sig);
-**  Function:	Signal handler for kill signals.
-*/
-void die(int sig)
-{
-  struct filed *f;
-  char buf[100];
-
-  for (f = Files; f != NULL; f = f->f_next) {
-	/* Flush any pending output */
-	if (f->f_prevcount) fprintlog(f, 0, NULL);
-  }
-  if (sig >= 0) {
-	DEBUG(dprintf("%s exiting on signal %d\n", ProgName, sig);)
-	sprintf(buf, "exiting on signal %d", sig);
-	errno = 0;
-	logerror(buf);
-  }
-  unlink(PidFile);
-  exit(sig == (-1) ? EXIT_FAILURE : EXIT_SUCCESS);
-}
-
-/*
-**  Name:	void domark(int sig);
-**  Function:	Signal handler for alarm.
-**		Used for messages filtering and mark facility.
-*/
-void domark(int sig)
-{
-  struct filed *f;
-
-  now = time(NULL);
-  MarkSeq += TIMERINTVL;
-  if (MarkSeq >= MarkInterval) {
-	logmsg(LOG_INFO, "-- MARK --", LocalHostName, ADDDATE | MARK);
-	MarkSeq = 0;
-  }
-  for (f = Files; f; f = f->f_next) {
-	if (f->f_prevcount && now >= REPEATTIME(f)) {
-		DEBUG(dprintf("flush %s: repeated %d times, %d sec.\n",
-			TypeNames[f->f_type], f->f_prevcount,
-			repeatinterval[f->f_repeatcount]);)
-		fprintlog(f, 0, NULL);
-		BACKOFF(f);
-	}
-  }
-  signal(SIGALRM, domark);
-  alarm(TIMERINTVL);
-  return;
-}
-
-/*
-**  Name:	int decode(char *name, struct _code *codetab);
-**  Function:	Decode a symbolic name to a numeric value
-*/
-int decode(char *name, const struct _code *codetab)
-{
-  const struct _code *c;
-  char *p;
-  char buf[40];
-
-  DEBUG(dprintf("symbolic name: %s", name);)
-  if (isdigit(*name)) return (atoi(name));
-
-  strcpy(buf, name);
-  for (p = buf; *p; p += 1) {
-	if (isupper(*p)) *p = tolower(*p);
-  }
-  for (c = codetab; c->c_name; c += 1) {
-	if (!strcmp(buf, c->c_name)) {
-		DEBUG(dprintf(" ==> %d\n", c->c_val);)
-		return (c->c_val);
-	}
-  }
-  return (-1);
-}
-
-/*
-**  Name:	void cfline(char *line, struct filed *f);
-**  Function:	Parse a configuration file line
-*/
-void cfline(char *line, struct filed * fLog)
-{
-  char *p, *q, *bp;
-  int ix, pri;
-  char buf[MAXLINE];
-  char xbuf[200];
-
-  DEBUG(dprintf("cfline(%s)\n", line);)
-
-  /* Keep sys_errlist stuff out of logerror messages */
-  errno = 0;
-
-  /* Clear out file entry */
-  memset(fLog, 0, sizeof(*fLog));
-  for (ix = 0; ix <= LOG_NFACILITIES; ix += 1)	/* */
-	fLog->f_pmask[ix] = INTERNAL_NOPRI;
-
-  /* Scan through the list of selectors */
-  for (p = line; *p && *p != '\t';) {
-
-	/* Find the end of this facility name list */
-	for (q = p; *q && *q != '\t' && *q++ != '.';) continue;
-
-	/* Collect priority name */
-	for (bp = buf; *q && !strchr("\t,;", *q);) *bp++ = *q++;
-	*bp = '\0';
-
-	/* Skip cruft */
-	while (strchr(", ;", *q)) q++;
-
-	/* Decode priority name */
-	pri = decode(buf, PriNames);
-	if (pri < 0) {
-		sprintf(xbuf, "unknown priority name \"%s\"", buf);
-		logerror(xbuf);
-		return;
-	}
-
-	/* Scan facilities */
-	while (*p && !strchr("\t.;", *p)) {
-		for (bp = buf; *p && !strchr("\t,;.", *p);) *bp++ = *p++;
-		*bp = '\0';
-		if (*buf == '*') {
-			for (ix = 0; ix <= LOG_NFACILITIES; ix += 1)
-				if ((fLog->f_pmask[ix] < pri) ||
-				    (fLog->f_pmask[ix] == INTERNAL_NOPRI)) {
-					fLog->f_pmask[ix] = pri;
-				}
-		} else {
-			ix = decode(buf, FacNames);
-			if (ix < 0) {
-				sprintf(xbuf, "unknown facility name \"%s\"", buf);
-				logerror(xbuf);
-				return;
-			}
-			if ((fLog->f_pmask[ix >> 3] < pri) ||
-			(fLog->f_pmask[ix >> 3] == INTERNAL_NOPRI)) {
-				fLog->f_pmask[ix >> 3] = pri;
-			}
-		}
-		while (*p == ',' || *p == ' ') p++;
-	}
-	p = q;
-  }
-
-  /* Skip to action part */
-  while (*p == '\t' || *p == ' ') p++;
-
-  DEBUG(dprintf("leading char in action: %c\n", *p);)
-  switch (*p) {
-      case '@':			/* Logging to a remote host */
-	break;			/* NOT IMPLEMENTED */
-
-      case '/':			/* Logging to a local file/device */
-	strcpy(fLog->f_un.f_fname, p);
-	DEBUG(dprintf("filename: %s\n", p);	/* ASP */)
-	if ((fLog->f_file = open(p, O_WRONLY | O_APPEND | O_CREAT | O_NOCTTY, 0644)) < 0) {
-		fLog->f_file = F_UNUSED;
-		sprintf(xbuf, "unknown file/device (%s)", p);
-		logerror(xbuf);
-		break;
-	}
-	if (isatty(fLog->f_file)) {
-		if (!DbgOpt) setsid();
-		fLog->f_type = F_TTY;
-	} else
-		fLog->f_type = F_FILE;
-	if (strcmp(p, ctty) == 0) fLog->f_type = F_CONSOLE;
-	break;
-
-      case '*':			/* Logging to all users */
-	DEBUG(dprintf("write-all\n");)
-	fLog->f_type = F_WALL;
-	break;
-
-      default:			/* Logging to selected users */
-	DEBUG(dprintf("users: %s\n", p);	/* ASP */)
-	for (ix = 0; ix < MAXUNAMES && *p; ix += 1) {
-		for (q = p; *q && *q != ',';) q += 1;
-		strncpy(fLog->f_un.f_uname[ix], p, UNAMESZ);
-		if ((q - p) > UNAMESZ)
-			fLog->f_un.f_uname[ix][UNAMESZ] = '\0';
-		else
-			fLog->f_un.f_uname[ix][q - p] = '\0';
-		while (*q == ',' || *q == ' ') q++;
-		p = q;
-	}
-	fLog->f_type = F_USERS;
-	break;
-  }
-}
-
-/*
-**  Name:  	void printline(char *hname, char *msg);
-**  Function:	Takes a raw input line, decodes the message and
-**	  	prints the message on the appropriate log files.
-*/
-void printline(char *hname, char *msg)
-{
-  char line[MAXLINE + 1];
-  char *p = msg, *q = line;
-  int ch, pri = DEFUPRI;
-
-  /* Test for special codes */
-  if (*p == '<') {
-	pri = 0;
-	while (isdigit(*++p)) {
-		if ((*p - '0') < 8) {
-			/* Only 3 bits allocated for pri -- ASP */
-			pri = 10 * pri + (*p - '0');
-		} else
-			pri = 10 * pri + 7;
-	}
-	if (*p == '>') ++p;
-  }
-  if (pri & ~(LOG_FACMASK | LOG_PRIMASK)) pri = DEFUPRI;
-
-  /* Does not allow users to log kernel messages */
-  if (LOG_FAC(pri) == LOG_KERN) pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri));
-
-  /* Copies message to local buffer, translating control characters */
-  while ((ch = *p++ & 0177) != '\0' && q < &line[sizeof(line) - 1]) {
-	if (ch == '\n')		/* Removes newlines */
-		*q++ = ' ';
-	else if (iscntrl(ch)) {	/* Translates control characters */
-		*q++ = '^';
-		*q++ = ch ^ 0100;
-	} else
-		*q++ = ch;
-  }
-  *q = '\0';
-
-  logmsg(pri, line, hname, 0);
-  return;
-}
-
-/*
-**  Name:  	void printkline(char *hname, char *msg);
-**  Function:	Takes a raw input line from kernel and 
-**	  	prints the message on the appropriate log files.
-*/
-void printkline(char *hname, char *msg)
-{
-  char line[MAXLINE + 1];
-  char *p = msg, *q = line;
-  int ch, pri = DEFUPRI;
-
-  /* Copies message to local buffer, adding source program tag */
-  sprintf(line, "kernel: %s", msg);
-
-  logmsg(LOG_KERN | LOG_INFO, line, hname, ADDDATE);
-  return;
-}
-
-/*
-**  Name:	void init(int sig);
-**  Function:	Initialize syslogd from configuration file.
-**		Used at startup or after a SIGHUP signal.
-*/
-void init(int sig)
-{
-  int i;
-  FILE *cf;
-  struct filed *fLog, *next, **nextp;
-  char *p;
-  char cline[BUFSIZ];
-
-  DEBUG(dprintf("init\n");)
-
-  /* Close all open log files. */
-  Initialized = 0;
-  for (fLog = Files; fLog != NULL; fLog = next) {
-
-	/* Flush any pending output */
-	if (fLog->f_prevcount) fprintlog(fLog, 0, NULL);
-
-	switch (fLog->f_type) {
-	    case F_FILE:
-	    case F_TTY:
-	    case F_CONSOLE:	close(fLog->f_file);	break;
-	}
-	next = fLog->f_next;
-	free((char *) fLog);
-  }
-  Files = NULL;
-  nextp = &Files;
-
-  /* Open the configuration file */
-  if ((cf = fopen(ConfFile, "r")) != NULL) {
-	/* Foreach line in the configuration table, open that file. */
-	fLog = NULL;
-	while (fgets(cline, sizeof(cline), cf) != NULL) {
-		/* Check for end-of-section, comments, strip off
-		 * trailing spaces and newline character. */
-		for (p = cline; isspace(*p); p += 1);
-		if (*p == '\0' || *p == '#') continue;
-		for (p = strchr(cline, '\0'); isspace(*--p););
-		*++p = '\0';
-		fLog = (struct filed *) calloc(1, sizeof(*fLog));
-		*nextp = fLog;
-		nextp = &fLog->f_next;
-		cfline(cline, fLog);
-	}
-
-	/* Close the configuration file */
-	fclose(cf);
-	Initialized = 1;
-DEBUG (
-	if (DbgOpt) {
-		for (fLog = Files; fLog; fLog = fLog->f_next) {
-			for (i = 0; i <= LOG_NFACILITIES; i += 1)
-				if (fLog->f_pmask[i] == INTERNAL_NOPRI)
-					printf("X ");
-				else
-					printf("%d ", fLog->f_pmask[i]);
-			printf("%s: ", TypeNames[fLog->f_type]);
-			switch (fLog->f_type) {
-			    case F_FILE:
-			    case F_TTY:
-			    case F_CONSOLE:
-				printf("%s", fLog->f_un.f_fname);
-				break;
-			    case F_FORW:
-				break;
-			    case F_USERS:
-				for (i = 0; i < MAXUNAMES && *fLog->f_un.f_uname[i]; i += 1)
-					printf("%s, ", fLog->f_un.f_uname[i]);
-				break;
-			}
-			printf("\n");
-		}
-	}
-  )
-	logmsg(LOG_SYSLOG | LOG_INFO, "syslogd: restart", LocalHostName, ADDDATE);
-	signal(SIGHUP, init);
-	DEBUG(dprintf("%s restarted\n", ProgName);)
-  } else {
-	DEBUG(dprintf("cannot open %s\n", ConfFile);)
-	*nextp = (struct filed *) calloc(1, sizeof(*fLog));
-	cfline("*.ERR\t" CTTY, *nextp);
-	(*nextp)->f_next = (struct filed *) calloc(1, sizeof(*fLog));
-	cfline("*.PANIC\t*", (*nextp)->f_next);
-	Initialized = 1;
-  }
-  return;
-}
-
-/*
-**  Name:	void daemonize(char *line);
-**  Function:	Clone itself and becomes a daemon releasing unnecessay resources.
-*/
-void daemonize(char *line)
-{
-  int lfd, len, pid;
-
-  if ((lfd = open(PidFile, O_CREAT | O_RDWR, 0600)) > 0) {
-	len = read(lfd, line, 10);
-	line[len] = '\0';
-	close(lfd);
-	if ((kill(len = atoi(line), 0) < 0 && errno == ESRCH) || len == 0) {
-		if (!DbgOpt) {
-			/* Parent ends and child becomes a daemon */
-			if ((pid = fork()) > 0) {
-				/* Write process id. in pid file */
-				lfd = open(PidFile, O_TRUNC | O_WRONLY);
-				len = sprintf(line, "%5d", pid);
-				write(lfd, line, len);
-				close(lfd);
-
-				/* Wait for initialization to complete */
-				exit(EXIT_SUCCESS);
-			}
-			sleep(1);
-			setsid();	/* Set as session leader */
-			chdir("/");	/* Change to the root directory */
-			/* Get rid of all open files */
-			for (lfd = STDERR_FILENO + 1; lfd < OPEN_MAX; lfd += 1)
-				close(lfd);
-		}
-	} else {
-		fprintf(stderr, "\n%s already running\n", ProgName);
-		exit(EXIT_FAILURE);
-	}
-  } else {
-	fprintf(stderr, "\n%s can't open %s (%s)\n", ProgName, PidFile, strerror(errno));
-	exit(EXIT_FAILURE);
-  }
-  return;
-}
-
-/*
-**  Name:	int main(int argc, char **argv);
-**  Function:	Syslog daemon entry point
-*/
-int main(int argc, char **argv)
-{
-  char *p, *udpdev, *eol;
-  int nfd, kfd, len, fdmax;
-  int ch, port = 0;
-  fd_set fdset;
-  struct nwio_udpopt udpopt;
-  struct servent *sp;
-  char line[MAXLINE + 1];
-
-  while ((ch = getopt(argc, argv, "df:m:p:v?")) != EOF) {
-	switch ((char) ch) {
-	    case 'd':		/* Debug */
-		DbgOpt += 1;
-		break;
-	    case 'f':		/* Set configuration file */
-		ConfFile = optarg;
-		break;
-	    case 'm':		/* Set mark interval */
-		MarkInterval = atoi(optarg) * 60;
-		break;
-	    case 'p':		/* Set listening port */
-		port = atoi(optarg);
-		break;
-	    case 'v':		/* Print version */
-		fprintf(stderr, "%s version %s\n", ProgName, version);
-		return EXIT_FAILURE;
-	    case '?':		/* Help */
-	    default:
-		fprintf(stderr, usage);
-		return EXIT_FAILURE;
-	}
-  }
-  if (argc -= optind) {
-	fprintf(stderr, usage);
-	return EXIT_FAILURE;
-  }
-
-  daemonize(line);
-
-  /* Get the official name of local host. */
-  gethostname(LocalHostName, sizeof(LocalHostName) - 1);
-  if ((p = strchr(LocalHostName, '.'))) *p = '\0';
-
-  udpdev = (p = getenv("UDP_DEVICE")) ? p : UDP_DEVICE;
-  sp = getservbyname("syslog", "udp");
-
-  signal(SIGTERM, die);
-  signal(SIGINT, DbgOpt ? die : SIG_IGN);
-  signal(SIGQUIT, DbgOpt ? die : SIG_IGN);
-  signal(SIGALRM, domark);
-
-  alarm(TIMERINTVL);
-
-  /* Open UDP device */
-  nfd = open(udpdev, O_NONBLOCK | O_RDONLY);
-
-  /* Configures the UDP device */
-  udpopt.nwuo_flags = NWUO_SHARED | NWUO_LP_SET | NWUO_EN_LOC |
-	NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET |
-	NWUO_RWDATONLY | NWUO_DI_IPOPT;
-  udpopt.nwuo_locport = udpopt.nwuo_remport =
-			port == 0 ? sp->s_port : htons(port);
-  udpopt.nwuo_remaddr = udpopt.nwuo_locaddr = htonl(0x7F000001L);
-  
- if(nfd >= 0) {
-  while (ioctl(nfd, NWIOSUDPOPT, &udpopt) < 0 ||
-      ioctl(nfd, NWIOGUDPOPT, &udpopt) < 0) {
-	if (errno == EAGAIN) {
-		sleep(1);
-		continue;
-	}
-	logerror("Set/Get UDP options failed");
-	return EXIT_FAILURE;
-  }
- }
-
-  /* Open kernel log device */
-  kfd = open("/dev/klog", O_NONBLOCK | O_RDONLY);
-
-  if(kfd < 0 && nfd < 0) {
-	logerror("open /dev/klog and udp device failed - can't log anything");
-	return EXIT_FAILURE;
-  }
-
-  fdmax = max(nfd, kfd) + 1;
-
-  DEBUG(dprintf("off & running....\n");)
-  
-  init(-1);			/* Initilizes log data structures */
-
-  for (;;) {			/* Main loop */
-
-	FD_ZERO(&fdset);	/* Setup descriptors for select */
-	if(nfd >= 0) FD_SET(nfd, &fdset);
-	if(kfd >= 0) FD_SET(kfd, &fdset);
-
-	if (select(fdmax, &fdset, NULL, NULL, NULL) <= 0) {
-		sleep(1);
-		continue;
-
-	}
-	if (nfd >= 0 && FD_ISSET(nfd, &fdset)) {
-
-		/* Read a message from application programs */
-		len = read(nfd, line, MAXLINE);
-		if (len > 0) {		/* Got a message */
-			line[len] = '\0';
-			dprintf("got a message (%d, %#x)\n", nfd, len);
-			printline(LocalHostName, line);
-
-		} else if (len < 0) {	/* Got an error or signal while reading */
-			if (errno != EINTR)	/* */
-				logerror("Receive error from UDP channel");
-
-		} else {	/* (len == 0) Channel has been closed */
-			logerror("UDP channel has closed");
-			close(nfd);
-			die(-1);
-		}
-	}
-	if (kfd >= 0 && FD_ISSET(kfd, &fdset)) {
-		static char linebuf[5*1024];
-
-		/* Read a message from kernel (klog) */
-		len = read(kfd, linebuf, sizeof(linebuf)-2);
-		dprintf("got a message (%d, %#x)\n", kfd, len);
-		for (ch = 0; ch < len; ch += 1)
-			if (linebuf[ch] == '\0') linebuf[ch] = ' ';
-		if (linebuf[len - 1] == '\n') len -= 1;
-		linebuf[len] = '\n';
-		linebuf[len + 1] = '\0';
-		p = linebuf;
-		while(eol = strchr(p, '\n')) {
-			*eol = '\0';
-			printkline(LocalHostName, p);
-			p = eol+1;
-		}
-	}
-  }
-  /* Control never gets here */
-}
-
-/** syslogd.c **/
Index: trunk/minix/commands/talk/Makefile
===================================================================
--- trunk/minix/commands/talk/Makefile	(revision 9)
+++ 	(revision )
@@ -1,31 +1,0 @@
-# Makefile for talk
-#
-# 08/01/96 			Michael Temari, <temari@ix.netcom.com>
-#
-
-CFLAGS=	-O -D_MINIX -D_POSIX_SOURCE
-LDFLAGS=-i
-BINDIR=	/usr/bin
-PROG=	talk
-CC = exec cc
-
-OBJS=	talk.o screen.o net.o proto.o
-
-all:	$(PROG)
-
-$(PROG):	$(OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(OBJS) -lcurses
-	install -S 16kw $@
-
-clean:
-	rm -f $(PROG) $(OBJS)
-
-install:	$(BINDIR)/$(PROG)
-
-$(BINDIR)/$(PROG):	$(PROG)
-	install -cs -o bin $? $@
-
-talk.o:		talk.c	talk.h	proto.h	net.h	screen.h
-screen.o:	screen.c			screen.h
-net.o:		net.c	talk.h		net.h
-proto.o:	proto.c	talk.h	proto.h	net.h	screen.h
Index: trunk/minix/commands/talk/build
===================================================================
--- trunk/minix/commands/talk/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/talk/net.c
===================================================================
--- trunk/minix/commands/talk/net.c	(revision 9)
+++ 	(revision )
@@ -1,266 +1,0 @@
-/* net.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <signal.h>
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/netdb.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_io.h>
-#include <net/gen/udp_hdr.h>
-
-#include "talk.h"
-#include "net.h"
-
-_PROTOTYPE(void TimeOut, (int sig));
-
-static unsigned char buffer[8192];
-
-static int udp_ctl;
-int tcp_fd;
-
-static udpport_t ntalk_port;
-
-char luser[USER_SIZE+1], ruser[USER_SIZE+1];
-char lhost[HOST_SIZE+1], rhost[HOST_SIZE+1];
-char ltty[TTY_SIZE+1], rtty[TTY_SIZE+1];
-udpport_t ctlport;
-tcpport_t dataport;
-ipaddr_t laddr, raddr;
-
-int NetInit()
-{
-int s;
-struct servent *servent;
-char *udp_device;
-char *tcp_device;
-nwio_udpopt_t udpopt;
-nwio_tcpconf_t tcpconf;
-
-   if((udp_device = getenv("UDP_DEVICE")) == (char *)NULL)
-   	udp_device = UDP_DEVICE;
-
-   if((udp_ctl = open(udp_device, O_RDWR)) < 0) {
-   	fprintf(stderr, "talk: Could not open %s: %s\n",
-   		udp_device, strerror(errno));
-   	return(-1);
-   }
-
-   if((servent = getservbyname("ntalk", "udp")) == (struct servent *)NULL) {
-   	fprintf(stderr, "talk: Could not find ntalk udp service\n");
-   	close(udp_ctl);
-   	return(-1);
-   }
-
-   ntalk_port = (udpport_t)servent->s_port;
-
-   udpopt.nwuo_flags = NWUO_NOFLAGS;
-   udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SEL | NWUO_EN_LOC;
-   udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET;
-   udpopt.nwuo_flags |= NWUO_RWDATONLY | NWUO_DI_IPOPT;
-   udpopt.nwuo_remaddr = raddr;
-   udpopt.nwuo_remport = ntalk_port;
-
-   s = ioctl(udp_ctl, NWIOSUDPOPT, &udpopt);
-   if(s < 0) {
-   	perror("talk: ioctl NWIOSUDPOPT");
-   	close(udp_ctl);
-   	return(-1);
-   }
-
-   s = ioctl(udp_ctl, NWIOGUDPOPT, &udpopt);
-   if(s < 0) {
-   	perror("talk: ioctl NWIOGUDPOPT");
-   	close(udp_ctl);
-   	return(-1);
-   }
-   laddr = udpopt.nwuo_locaddr;
-   ctlport = udpopt.nwuo_locport;
-
-   if((tcp_device = getenv("TCP_DEVICE")) == (char *)NULL)
-   	tcp_device = TCP_DEVICE;
-
-   if((tcp_fd = open(tcp_device, O_RDWR)) < 0) {
-   	fprintf(stderr, "talk: Could not open %s: %s\n",
-   		tcp_device, strerror(errno));
-   	close(udp_ctl);
-   	return(-1);
-   }
-
-   tcpconf.nwtc_flags = NWTC_NOFLAGS;
-   tcpconf.nwtc_flags |= NWTC_LP_SEL | NWTC_SET_RA | NWTC_UNSET_RP;
-   tcpconf.nwtc_remaddr = raddr;
-
-   s = ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf);
-   if(s < 0) {
-   	perror("talk: ioctl NWIOSTCPCONF");
-   	close(udp_ctl);
-   	close(tcp_fd);
-   	return(-1);
-   }
-
-   s = ioctl(tcp_fd, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-   	perror("talk: ioctl NWIOGTCPCONF");
-   	close(udp_ctl);
-   	close(tcp_fd);
-   	return(-1);
-   }
-
-   dataport = tcpconf.nwtc_locport;
-
-   return(0);
-}
-
-int getreply(reply, timeout)
-struct talk_reply *reply;
-int timeout;
-{
-int s;
-int terrno;
-udp_io_hdr_t *udp_io_hdr;
-
-   signal(SIGALRM, TimeOut);
-   alarm(timeout);
-   s = read(udp_ctl, buffer, sizeof(buffer));
-   terrno = errno;
-   alarm(0);
-   errno = terrno;
-   if(s < 0 && errno == EINTR)
-   	return(1);
-   if(s < 0) {
-   	perror("talk: Read error in getreply");
-   	return(-1);
-   }
-
-   if(s == sizeof(struct talk_reply))
-	memcpy((char *)reply, buffer, s);
-
-   return(0);
-}
-
-int sendrequest(request, here)
-struct talk_request *request;
-int here;
-{
-int s;
-nwio_udpopt_t udpopt;
-udp_io_hdr_t *udp_io_hdr;
-
-   udpopt.nwuo_flags = NWUO_NOFLAGS;
-   udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SET | NWUO_EN_LOC;
-   udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET;
-   udpopt.nwuo_flags |= NWUO_RWDATONLY | NWUO_DI_IPOPT;
-   udpopt.nwuo_locport = ctlport;
-   if(here)
-	udpopt.nwuo_remaddr = laddr;
-   else
-	udpopt.nwuo_remaddr = raddr;
-   udpopt.nwuo_remport = ntalk_port;
-
-   s = ioctl(udp_ctl, NWIOSUDPOPT, &udpopt);
-   if(s < 0) {
-   	perror("talk: ioctl NWIOSUDPOPT");
-   	return(-1);
-   }
-
-   s = ioctl(udp_ctl, NWIOGUDPOPT, &udpopt);
-   if(s < 0) {
-   	perror("talk: ioctl NWIOGUDPOPT");
-   	return(-1);
-   }
-
-   s = write(udp_ctl, request, sizeof(struct talk_request));
-   if(s < 0) {
-   	perror("talk: write error in sendrequest");
-   	return(-1);
-   }
-
-   if(s != sizeof(struct talk_request)) {
-   	fprintf(stderr, "talk: sendrequest size mismatch %d %d\n", s, sizeof(struct talk_request));
-   	return(-1);
-   }
-
-   return(0);
-}
-
-void TimeOut(sig)
-int sig;
-{
-}
-
-int NetConnect(port)
-u16_t port;
-{
-int s;
-nwio_tcpconf_t tcpconf;
-nwio_tcpcl_t tcpcopt;
-
-   tcpconf.nwtc_flags = NWTC_NOFLAGS;
-   tcpconf.nwtc_flags |= NWTC_LP_SET | NWTC_SET_RA | NWTC_SET_RP;
-   tcpconf.nwtc_locport = dataport;
-   tcpconf.nwtc_remaddr = raddr;
-   tcpconf.nwtc_remport = port;
-
-   s = ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf);
-   if(s < 0) {
-   	perror("talk: ioctl NWIOSTCPCONF");
-   	return(-1);
-   }
-
-   s = ioctl(tcp_fd, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-   	perror("talk: ioctl NWIOGTCPCONF");
-   	return(-1);
-   }
-
-   tcpcopt.nwtcl_flags = 0;
-
-   s = ioctl(tcp_fd, NWIOTCPCONN, &tcpcopt);
-   if(s < 0 && errno == ECONNREFUSED)
-   	return(1);
-   if(s < 0) {
-   	perror("talk: ioctl NWIOTCPCONN");
-   	return(-1);
-   }
-
-   return(0);
-}
-
-int NetListen(timeout)
-int timeout;
-{
-int s;
-nwio_tcpcl_t tcplopt;
-int terrno;
-
-   tcplopt.nwtcl_flags = 0;
-
-   signal(SIGALRM, TimeOut);
-   alarm(timeout);
-   s = ioctl(tcp_fd, NWIOTCPLISTEN, &tcplopt);
-   terrno = errno;
-   alarm(0);
-   errno = terrno;
-
-   if(s < 0 && errno == EINTR)
-   	return(1);
-
-   if(s < 0) {
-   	perror("talk: ioctl NWIOTCPLISTEN");
-   	return(-1);
-   }
-
-   return(0);
-}
Index: trunk/minix/commands/talk/net.h
===================================================================
--- trunk/minix/commands/talk/net.h	(revision 9)
+++ 	(revision )
@@ -1,15 +1,0 @@
-/* net.h Copyright Michael Temari 08/01/1996 All Rights Reserved */
-
-extern char luser[], ruser[];
-extern char lhost[], rhost[];
-extern char ltty[], rtty[];
-extern udpport_t ctlport;
-extern tcpport_t dataport;
-extern ipaddr_t laddr, raddr;
-extern int tcp_fd;
-
-_PROTOTYPE(int NetInit, (void));
-_PROTOTYPE(int getreply, (struct talk_reply *reply, int timeout));
-_PROTOTYPE(int sendrequest, (struct talk_request *request, int here));
-_PROTOTYPE(int NetConnect, (U16_t port));
-_PROTOTYPE(int NetListen, (int timeout));
Index: trunk/minix/commands/talk/proto.c
===================================================================
--- trunk/minix/commands/talk/proto.c	(revision 9)
+++ 	(revision )
@@ -1,142 +1,0 @@
-/* proto.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <net/hton.h>
-#include <net/gen/socket.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-#include <net/gen/udp.h>
-
-#include "talk.h"
-#include "proto.h"
-#include "net.h"
-#include "screen.h"
-
-_PROTOTYPE(static int TalkChk, (int gotreply, struct talk_reply *reply, char *msg));
-_PROTOTYPE(static int TalkTrans, (int type, long id, struct talk_reply *reply, int here));
-
-static char *AnswerMsgs[] = {
-	"Success",
-	"User Not Logged In",
-	"Failure",
-	"Remote Does Not Know who we are",
-	"User is not accepting calls",
-	"Are request was not know",
-	"Incorrect Version",
-	"Bad Address",
-	"Bad Control Address"
-};
-
-static int TalkChk(gotreply, reply, msg)
-int gotreply;
-struct talk_reply *reply;
-char *msg;
-{
-   if(!gotreply) {
-	ScreenMsg(msg);
-	return(-1);
-   }
-   if(reply->answer == SUCCESS) return(0);
-   if(reply->answer < (sizeof(AnswerMsgs) / sizeof(AnswerMsgs[0])))
-  	ScreenMsg(AnswerMsgs[reply->answer]);
-   else
-  	ScreenMsg("Bad Answer");
-
-   return(-1);
-}
-
-static int TalkTrans(type, id, reply, here)
-int type;
-long id;
-struct talk_reply *reply;
-int here;
-{
-struct talk_request request;
-int tries;
-int gotreply;
-
-   memset(&request, 0, sizeof(request));
-
-   request.version = TALK_VERSION;
-   request.type = type;
-   request.id = id;
-   request.addr.sa_family = htons(AF_INET);
-   request.addr.sin_port = dataport;
-   request.addr.sin_addr = laddr;
-   request.ctl_addr.sa_family = htons(AF_INET);
-   request.ctl_addr.sin_port = ctlport;
-   request.ctl_addr.sin_addr = laddr;
-   request.pid = getpid();
-   strncpy(request.luser, luser, USER_SIZE);
-   strncpy(request.ruser, ruser, USER_SIZE);
-   strncpy(request.rtty,  rtty,  TTY_SIZE);
-
-   tries = 0;
-   gotreply = 0;
-   while(!ScreenDone && tries++ < 3 && !gotreply) {
-	if(!sendrequest(&request, here))
-		if(!getreply(reply, 5))
-			gotreply = 1;
-	if(!gotreply) continue;
-	if(reply->version != request.version ||
-	   reply->type    != request.type)
-	   	gotreply = 0;
-   }
-   return(gotreply);
-}
-
-int TalkInit()
-{
-struct talk_reply reply;
-long id = 0;
-long rid;
-int s;
-int ring;
-char buff[32];
-
-   /* Check if someone was calling us */
-   ScreenMsg("Initiating Talk Protocol");
-
-   /* Check is someone was calling us */
-   s = TalkTrans(LOOK_UP, ++id, &reply, 0);
-
-   /* Someone was calling us */
-   if(s && reply.answer == SUCCESS) {
-   	s = NetConnect(reply.addr.sin_port);
-   	if(s == 1) {
-   		ScreenMsg("Your party has hung up");
-   		TalkTrans(DELETE, reply.id, &reply, 0);
-   	}
-   	return(s == 0 ? 0 : -1);
-   }
-
-   ScreenMsg("Ringing User");
-
-   ring = 0;
-   while(!ScreenDone && ring++ < 5) {
-   	if(TalkChk(TalkTrans(ANNOUNCE, -1, &reply, 0),
-   			&reply, "No response to are ring"))
-   		return(-1);
-   	rid = reply.id;
-	sprintf(buff, "Ring #%d", ring);
-	ScreenMsg(buff);
-	if(ring == 1) {
-   		if(TalkChk(TalkTrans(LEAVE_INVITE, ++id, &reply, 1),
-   				&reply, "Could not leave are invitaion locally"))
-			return(-1);
-	}
-   	s = NetListen(RING_WAIT);
-   	if(s <= 0) {
-   		TalkTrans(DELETE, reply.id, &reply, 1);
-   		TalkTrans(DELETE, rid, &reply, 0);
-   		return(s);
-   	}
-   }
-
-   return(-1);
-}
Index: trunk/minix/commands/talk/proto.h
===================================================================
--- trunk/minix/commands/talk/proto.h	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-/* proto.h Copyright Michael Temari 08/01/1996 All Rights Reserved */
-
-_PROTOTYPE(int TalkInit, (void));
Index: trunk/minix/commands/talk/screen.c
===================================================================
--- trunk/minix/commands/talk/screen.c	(revision 9)
+++ 	(revision )
@@ -1,208 +1,0 @@
-/* screen.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <signal.h>
-#include <ctype.h>
-#include <string.h>
-#include <unistd.h>
-#include <curses.h>
-
-#include "screen.h"
-
-_PROTOTYPE(void gotsig, (int sig));
-_PROTOTYPE(static char *delword, (WINDOW *w));
-
-struct {
-	WINDOW *win;
-	char erase;
-	char kill;
-	char werase;
-} window[2];
-
-static char line[80+1];
-
-int ScreenDone = 0;
-
-static WINDOW *dwin;
-
-void gotsig(sig)
-int sig;
-{
-   ScreenDone = 1;
-   signal(sig, gotsig);
-}
-
-int ScreenInit()
-{
-int i;
-
-   if(initscr() == (WINDOW *)NULL) {
-   	fprintf(stderr, "talk: Could not initscr\n");
-   	return(-1);
-   }
-   signal(SIGINT, gotsig);
-   signal(SIGQUIT, gotsig);
-   signal(SIGPIPE, gotsig);
-   signal(SIGHUP, gotsig);
-   clear();
-   refresh();
-   noecho();
-   cbreak();
-
-   /* local window */
-   window[LOCALWIN].win = newwin(LINES / 2, COLS, 0, 0);
-   scrollok(window[LOCALWIN].win, TRUE);
-   wclear(window[LOCALWIN].win);
-
-   /* divider between windows */
-   dwin = newwin(1, COLS, LINES / 2, 0);
-   i = COLS;
-   while(i-- > 0)
-   	waddch(dwin, '-');
-   wrefresh(dwin);
-
-   /* remote window */
-   window[REMOTEWIN].win = newwin(LINES - (LINES / 2) - 1, COLS, LINES / 2 + 1, 0);
-   scrollok(window[REMOTEWIN].win, TRUE);
-   wclear(window[REMOTEWIN].win);
-
-   return(0);
-}
-
-void ScreenMsg(msg)
-char *msg;
-{
-WINDOW *w;
-
-   w =window[LOCALWIN].win;
-
-   wmove(w, 0, 0);
-
-   if(*msg != '\0') {
-	wprintw(w, "[%s]", msg);
-	wclrtoeol(w);
-   } else
-   	werase(w);
-
-   wrefresh(w);
-}
-
-void ScreenWho(user, host)
-char *user;
-char *host;
-{
-   if(*host != '\0') {
-   	wmove(dwin, 0, (COLS - (1 + strlen(user) + 1 + strlen(host) + 1)) / 2);
-   	wprintw(dwin, " %s@%s ", user, host);
-   } else {
-   	wmove(dwin, 0, (COLS - (1 + strlen(user) + 1)) / 2);
-   	wprintw(dwin, " %s ", user);
-   }
-   wrefresh(dwin);
-}
-
-void ScreenEdit(lcc, rcc)
-char lcc[];
-char rcc[];
-{
-   window[LOCALWIN].erase   = lcc[0];
-   window[LOCALWIN].kill    = lcc[1];
-   window[LOCALWIN].werase  = lcc[2];
-   window[REMOTEWIN].erase  = rcc[0];
-   window[REMOTEWIN].kill   = rcc[1];
-   window[REMOTEWIN].werase = rcc[2];
-}
-
-void ScreenPut(data, len, win)
-char *data;
-int len;
-int win;
-{
-WINDOW *w;
-unsigned char ch;
-int r, c;
-
-   w = window[win].win;
-
-   while(len-- > 0) {
-   	ch = *data++;
-   	/* new line CR, NL */
-   	if(ch == '\r' || ch == '\n') {
-		waddch(w, '\n');
-	} else
-	/* erase a character, BS, DEL  */
-	if(ch == 0x08 || ch == 0x7f || ch == window[win].erase) {
-		getyx(w, r, c);
-		if(c > 0)
-			c--;
-		wmove(w, r, c);
-		waddch(w, ' ');
-		wmove(w, r, c);
-	} else
-	/* erase line CTL-U */
-	if(ch == 0x15 || ch == window[win].kill) {
-		getyx(w, r, c);
-		wmove(w, r, 0);
-		wclrtoeol(w);
-	} else
-	/* refresh CTL-L */
-	if(ch == 0x0c) {
-		if(win == LOCALWIN) {
-			touchwin(w);
-			wrefresh(w);
-			touchwin(window[REMOTEWIN].win);
-			wrefresh(window[REMOTEWIN].win);
-		}
-	} else
-	/* bell CTL-G */
-	if(ch == 0x07) {
-		putchar(ch);
-	}
-	else
-	/* erase last word CTL-W */
-	if(ch == 0x17 || ch == window[win].werase) {
-		(void) delword(w);
-	} else {
-		getyx(w, r, c);
-		if(1 || isprint(ch)) {
-			if(ch != ' ' && c == (COLS - 1))
-				wprintw(w, "\n%s", delword(w));
-			waddch(w, ch);
-		}
-	}
-   }
-   wrefresh(w);
-}
-
-static char *delword(w)
-WINDOW *w;
-{
-int r, c;
-int i = 0;
-char ch;
-char *p = &line[80];
-
-   *p-- = '\0';
-   getyx(w, r, c);
-   if(c == 0) return;
-   while(c >= 0) {
-   	c--;
-   	ch = mvwinch(w, r, c);
-   	if(ch == ' ') break;
-   	*p-- = ch;
-   	i = 1;
-   	waddch(w, ' ');
-   }
-   c += i;
-   wmove(w, r, c);
-   return(++p);
-}
-
-void ScreenEnd()
-{
-   move(LINES - 1, 0);
-   refresh();
-   endwin();
-}
Index: trunk/minix/commands/talk/screen.h
===================================================================
--- trunk/minix/commands/talk/screen.h	(revision 9)
+++ 	(revision )
@@ -1,13 +1,0 @@
-/* screen.h Copyright Michael Temari 08/01/1996 All Rights Reserved */
-
-_PROTOTYPE(int ScreenInit, (void));
-_PROTOTYPE(void ScreenMsg, (char *msg));
-_PROTOTYPE(void ScreenWho, (char *user, char *host));
-_PROTOTYPE(void ScreenEdit, (char lcc[], char rcc[]));
-_PROTOTYPE(void ScreenPut, (char *data, int len, int mywin));
-_PROTOTYPE(void ScreenEnd, (void));
-
-extern int ScreenDone;
-
-#define	LOCALWIN	0
-#define	REMOTEWIN	1
Index: trunk/minix/commands/talk/talk.c
===================================================================
--- trunk/minix/commands/talk/talk.c	(revision 9)
+++ 	(revision )
@@ -1,237 +1,0 @@
-/* talk.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <utmp.h>
-#include <termios.h>
-#include <net/gen/netdb.h>
-#include <net/hton.h>
-#include <net/gen/socket.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-#include <net/gen/udp.h>
-
-#include "talk.h"
-#include "proto.h"
-#include "net.h"
-#include "screen.h"
-
-_PROTOTYPE(int main, (int argc, char *argv[]));
-_PROTOTYPE(void DoTalk, (void));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-char *p;
-struct hostent *hp;
-struct stat st;
-struct utmp utmp;
-int slot;
-FILE *fp;
-
-   if(argc < 2 || argc > 3) {
-   	fprintf(stderr, "Usage: talk user[@host] [tty]\n");
-   	return(-1);
-   }
-
-   /* get local host name */
-   if(gethostname(lhost, HOST_SIZE) < 0) {
-   	fprintf(stderr, "talk: Error getting local host name\n");
-   	return(-1);
-   }
-
-   /* get local user name and tty */
-   if((slot = ttyslot()) < 0) {
-   	fprintf(stderr, "talk: You are not on a terminal\n");
-   	return(-1);
-   }
-   if((fp = fopen(UTMP, "r")) == (FILE *)NULL) {
-   	fprintf(stderr, "talk: Could not open %s\n", UTMP);
-   	return(-1);
-   }
-   if(fseek(fp, (off_t) sizeof(utmp) * slot, SEEK_SET)) {
-   	fprintf(stderr, "talk: Could not seek %s\n", UTMP);
-   	fclose(fp);
-   	return(-1);
-   }
-   if(fread((char *)&utmp, sizeof(utmp), 1 , fp) != 1) {
-   	fprintf(stderr, "talk: Could not read %s\n", UTMP);
-   	fclose(fp);
-   	return(-1);
-   }
-   fclose(fp);
-   strncpy(luser, utmp.ut_user, USER_SIZE < sizeof(utmp.ut_user) ?
-   				USER_SIZE : sizeof(utmp.ut_user));
-   luser[USER_SIZE] = '\0';
-
-   /* get local tty */
-   if((p = ttyname(0)) == (char *)NULL) {
-   	fprintf(stderr, "talk: You are not on a terminal\n");
-   	return(-1);
-   }
-   strncpy(ltty, p+5, TTY_SIZE);
-   ltty[TTY_SIZE] = '\0';
-
-   /* check if local tty is going to be writable */
-   if(stat(p, &st) < 0) {
-   	perror("talk: Could not stat local tty");
-   	return(-1);
-   }
-   if((st.st_mode & S_IWGRP) == 0) {
-   	fprintf(stderr, "talk: Your terminal is not writable.  Use: mesg y\n");
-   	return(-1);
-   }
-
-   /* get remote user and host name */
-   if((p = strchr(argv[1], '@')) != (char *)NULL)
-   	*p++ = '\0';
-   else
-   	p = lhost;
-   strncpy(ruser, argv[1], USER_SIZE);
-   ruser[USER_SIZE] = '\0';
-   strncpy(rhost, p, HOST_SIZE);
-   rhost[HOST_SIZE] = '\0';
-
-   /* get remote tty */
-   if(argc > 2)
-   	strncpy(rtty, argv[2], TTY_SIZE);
-   else
-   	rtty[0] = '\0';
-   rtty[TTY_SIZE] = '\0';
-
-   if((hp = gethostbyname(rhost)) == (struct hostent *)NULL) {
-   	fprintf(stderr, "talk: Could not determine address of %s\n", rhost);
-   	return(-1);
-   }
-   memcpy((char *)&raddr, (char *)hp->h_addr, hp->h_length);
-
-   if(NetInit()) {
-   	fprintf(stderr, "talk: Error in NetInit\n");
-   	return(-1);
-   }
-
-   if(ScreenInit())
-   	return(-1);
-
-   if(!TalkInit())
-	DoTalk();
-
-   ScreenEnd();
-
-   return(0);
-}
-
-struct pdata {
-	int win;
-	int len;
-	char buffer[64];
-} pdata;
-
-void DoTalk()
-{
-int s;
-int s2;
-int kid;
-int pfd[2];
-int win;
-int len;
-struct termios termios;
-char lcc[3];
-char rcc[3];
-
-   ScreenMsg("");
-   ScreenWho(ruser, rhost);
-
-   /* Get and send edit characters */
-   s = tcgetattr(0, &termios);
-   if(s < 0) {
-   	perror("talk: tcgetattr");
-   	return;
-   }
-   lcc[0] = termios.c_cc[VERASE];
-   lcc[1] = termios.c_cc[VKILL];
-   lcc[2] = 0x17; /* Control - W */
-   s = write(tcp_fd, lcc, sizeof(lcc));
-   if(s != sizeof(lcc)) {
-   	ScreenMsg("Connection Closing due to error");
-   	return;
-   }
-   s = read(tcp_fd, rcc, sizeof(rcc));
-   if(s != sizeof(rcc)) {
-   	ScreenMsg("Connection Closing due to error");
-   	return;
-   }
-   ScreenEdit(lcc, rcc);
-
-   s = pipe(pfd);
-   if(s < 0) {
-   	ScreenMsg("Could not create pipes");
-   	return;
-   }
-
-   if((kid = fork()) < 0) {
-   	ScreenMsg("Could not fork");
-   	close(pfd[0]);
-   	close(pfd[1]);
-   	return;
-   }
-
-   if(kid == 0) {
-   	close(tcp_fd);
-   	close(pfd[1]);
-   	while(1) {
-   		s = read(pfd[0], &pdata, sizeof(pdata));
-   		if(s != sizeof(pdata)) {
-   			close(pfd[0]);
-   			exit(-1);
-   		}
-   		ScreenPut(pdata.buffer, pdata.len, pdata.win);
-   	}
-   }
-
-   close(pfd[0]);
-
-   if((kid = fork()) < 0) {
-   	ScreenMsg("Could not fork");
-   	close(pfd[1]);
-   	return;
-   }
-
-   if(kid == 0) {
-   	pdata.win = REMOTEWIN;
-   	while(!ScreenDone) {
-	   	s = read(tcp_fd, pdata.buffer, sizeof(pdata.buffer));
-   		if(s <= 0)
-   			break;
-   		pdata.len = s;
-		write(pfd[1], &pdata, sizeof(pdata));
-   	}
-   	close(pfd[1]);
-   	close(tcp_fd);
-	kill(getppid(), SIGINT);
-   	exit(-1);
-   }
-
-   pdata.win = LOCALWIN;
-   while(!ScreenDone) {
-	s = read(0, pdata.buffer, sizeof(pdata.buffer));
-	if(s <= 0)
-		break;
-	pdata.len = s;
-	write(pfd[1], &pdata, sizeof(pdata));
-	s2 = write(tcp_fd, pdata.buffer, s);
-	if(s2 != s)
-		break;
-   }
-   kill(kid, SIGINT);
-   close(pfd[1]);
-   close(tcp_fd);
-   return;
-}
Index: trunk/minix/commands/talk/talk.h
===================================================================
--- trunk/minix/commands/talk/talk.h	(revision 9)
+++ 	(revision )
@@ -1,57 +1,0 @@
-/* talk.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-#define	USER_SIZE	12
-#define	TTY_SIZE	16
-#define	HOST_SIZE	255
-
-struct osockaddr {
-	u16_t sa_family;
-	u16_t sin_port;
-	ipaddr_t sin_addr;
-	char junk[8];
-};
-
-struct talk_request {
-	u8_t version;
-	u8_t type;
-	u8_t answer;
-	u8_t junk;
-	u32_t id;
-	struct osockaddr addr;
-	struct osockaddr ctl_addr;
-	long pid;
-	char	luser[USER_SIZE];
-	char	ruser[USER_SIZE];
-	char	rtty[TTY_SIZE];
-};
-
-struct talk_reply {
-	u8_t version;
-	u8_t type;
-	u8_t answer;
-	u8_t junk;
-	u32_t id;
-	struct osockaddr addr;
-};
-
-#define	TALK_VERSION	1
-
-/* message type values */
-#define LEAVE_INVITE	0	/* leave invitation with server */
-#define LOOK_UP		1	/* check for invitation by callee */
-#define DELETE		2	/* delete invitation by caller */
-#define ANNOUNCE	3	/* announce invitation by caller */
-
-/* answer values */
-#define SUCCESS		0	/* operation completed properly */
-#define NOT_HERE	1	/* callee not logged in */
-#define FAILED		2	/* operation failed for unexplained reason */
-#define MACHINE_UNKNOWN	3	/* caller's machine name unknown */
-#define PERMISSION_DENIED 4	/* callee's tty doesn't permit announce */
-#define UNKNOWN_REQUEST	5	/* request has invalid type value */
-#define	BADVERSION	6	/* request has invalid protocol version */
-#define	BADADDR		7	/* request has invalid addr value */
-#define	BADCTLADDR	8	/* request has invalid ctl_addr value */
-
-#define MAX_LIFE	60	/* max time daemon saves invitations */
-#define RING_WAIT	30	/* time to wait before resending invitation */
Index: trunk/minix/commands/talkd/Makefile
===================================================================
--- trunk/minix/commands/talkd/Makefile	(revision 9)
+++ 	(revision )
@@ -1,31 +1,0 @@
-# Makefile for talkd
-#
-# 07/22/96 			Michael Temari, <temari@ix.netcom.com>
-#
-
-CFLAGS=	-O -D_MINIX -D_POSIX_SOURCE
-LDFLAGS=-i
-BINDIR=	/usr/bin
-PROG=	talkd
-CC = exec cc
-
-OBJS=	talkd.o net.o process.o finduser.o
-
-all:	$(PROG)
-
-$(PROG):	$(OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(OBJS)
-	install -S 8kw $@
-
-clean:
-	rm -f $(PROG) $(OBJS)
-
-install:	$(BINDIR)/$(PROG)
-
-$(BINDIR)/$(PROG):	$(PROG)
-	install -cs -o bin $? $@
-
-talkd.o:	talkd.c		talk.h	talkd.h	process.h net.h
-net.o:		net.c		talk.h	talkd.h	net.h
-process.o:	process.c	talk.h	talkd.h	finduser.h process.h
-finduser.o:	finduser.c	talk.h		finduser.h
Index: trunk/minix/commands/talkd/build
===================================================================
--- trunk/minix/commands/talkd/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/talkd/finduser.c
===================================================================
--- trunk/minix/commands/talkd/finduser.c	(revision 9)
+++ 	(revision )
@@ -1,44 +1,0 @@
-/* finduser.c Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <time.h>
-#include <utmp.h>
-#include <net/gen/in.h>
-
-#include "talk.h"
-#include "finduser.h"
-
-int find_user(name, tty)
-char *name;
-char *tty;
-{
-int fd;
-int ret;
-struct utmp utmp;
-
-   /* Now find out if the requested user is logged in. */
-   if((fd = open(UTMP, O_RDONLY)) < 0) {
-	perror("talkd: opening UTMP file");
-	return(FAILED);
-   }
-
-   ret = NOT_HERE;
-
-   while(read(fd, &utmp, sizeof(struct utmp)) == sizeof(struct utmp)) {
-	if(utmp.ut_type != USER_PROCESS) continue;
-	if(strncmp(utmp.ut_user, name, sizeof(utmp.ut_user))) continue;
-	if(*tty && strncmp(utmp.ut_line, tty, sizeof(utmp.ut_line))) continue;
-	strcpy(tty, utmp.ut_line);
-	ret = SUCCESS;
-	break;
-   }
-
-   close(fd);
-
-   return(ret);
-}
Index: trunk/minix/commands/talkd/finduser.h
===================================================================
--- trunk/minix/commands/talkd/finduser.h	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-/* finduser.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-_PROTOTYPE(int find_user, (char *name, char *tty));
Index: trunk/minix/commands/talkd/net.c
===================================================================
--- trunk/minix/commands/talkd/net.c	(revision 9)
+++ 	(revision )
@@ -1,188 +1,0 @@
-/* net.c Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/netdb.h>
-#include <net/gen/in.h>
-#include <net/gen/udp.h>
-#include <net/gen/udp_io.h>
-#include <net/gen/udp_hdr.h>
-
-#include "talk.h"
-#include "talkd.h"
-#include "net.h"
-
-static unsigned char buffer[8192];
-
-static int udp_in;
-static int udp_out;
-
-static udpport_t ntalk_port;
-
-int NetInit()
-{
-int s;
-struct servent *servent;
-char *udp_device;
-nwio_udpopt_t udpopt;
-
-   if((udp_device = getenv("UDP_DEVICE")) == (char *)NULL)
-   	udp_device = UDP_DEVICE;
-
-   if((udp_in = open(udp_device, O_RDWR)) < 0) {
-   	fprintf(stderr, "talkd: Could not open %s: %s\n",
-   		udp_device, strerror(errno));
-   	return(-1);
-   }
-
-   if((udp_out = open(udp_device, O_RDWR)) < 0) {
-   	fprintf(stderr, "talkd: Could not open %s: %s\n",
-   		udp_device, strerror(errno));
-   	close(udp_in);
-   	return(-1);
-   }
-
-   if((servent = getservbyname("ntalk", "udp")) == (struct servent *)NULL) {
-   	fprintf(stderr, "talkd: Could not find ntalk udp service\n");
-   	close(udp_in);
-   	close(udp_out);
-   	return(-1);
-   }
-
-   ntalk_port = (udpport_t)servent->s_port;
-
-   udpopt.nwuo_flags = NWUO_NOFLAGS;
-   udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SET | NWUO_EN_LOC;
-   udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_ANY | NWUO_RA_ANY;
-   udpopt.nwuo_flags |= NWUO_RWDATALL | NWUO_DI_IPOPT;
-   udpopt.nwuo_locport = ntalk_port;
-
-   s = ioctl(udp_in, NWIOSUDPOPT, &udpopt);
-   if(s < 0) {
-   	perror("talkd: ioctl NWIOSUDPOPT");
-   	close(udp_in);
-   	close(udp_out);
-   	return(-1);
-   }
-
-   s = ioctl(udp_in, NWIOGUDPOPT, &udpopt);
-   if(s < 0) {
-   	perror("talkd: ioctl NWIOGUDPOPT");
-   	close(udp_in);
-   	close(udp_out);
-   	return(-1);
-   }
-
-   return(0);
-}
-
-int getrequest(request)
-struct talk_request *request;
-{
-int s;
-udp_io_hdr_t *udp_io_hdr;
-
-   s = read(udp_in, buffer, sizeof(buffer));
-   if(s < 0) {
-   	perror("talkd: Read error in getrequest");
-   	return(-1);
-   }
-   if(s < sizeof(udp_io_hdr_t)) {
-	fprintf(stderr, "talkd: Packet size read %d is smaller the udp_io_hdr\n", s);
-	return(-1);
-   }
-   udp_io_hdr = (udp_io_hdr_t *)buffer;
-   s = s - sizeof(udp_io_hdr_t);
-
-   /* why is uih_data_len already in host order??? */
-
-   if(udp_io_hdr->uih_data_len != s) {
-	fprintf(stderr, "talkd: Size mismatch Packet %d  Udp Data %d\n",
-		s, udp_io_hdr->uih_data_len);
-	return(-1);
-   }
-
-   if(s != sizeof(struct talk_request)) {
-   	fprintf(stderr, "talkd: Size mismatch in request %d %d\n",
-   			s, sizeof(struct talk_request));
-   	return(-1);
-   }
-
-   memcpy((char *)request, buffer + sizeof(udp_io_hdr_t), s);
-
-   if(opt_d) {
-   	fprintf(stderr, "Request: ");
-	fprintf(stderr, "%02x %02x %02x %02x ",
-	request->version, request->type, request->answer, request->junk);
-	fprintf(stderr, "%08lx ", request->id);
-	fprintf(stderr, "%04x %08lx:%04x\n",
-		request->addr.sa_family, request->addr.sin_addr, request->addr.sin_port);
-	fprintf(stderr, "                     %08lx ", request->pid);
-	fprintf(stderr, "%04x %08lx:%04x\n",
-		request->ctl_addr.sa_family, request->ctl_addr.sin_addr, request->ctl_addr.sin_port);
-	fprintf(stderr, "          %-12.12s %-12.12s %-16.16s\n",
-		request->luser, request->ruser, request->rtty);
-   }
-
-   return(0);
-}
-
-int sendreply(request, reply)
-struct talk_request *request;
-struct talk_reply *reply;
-{
-int s;
-nwio_udpopt_t udpopt;
-udp_io_hdr_t *udp_io_hdr;
-
-   udpopt.nwuo_flags = NWUO_NOFLAGS;
-   udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SET | NWUO_EN_LOC;
-   udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET;
-   udpopt.nwuo_flags |= NWUO_RWDATONLY | NWUO_DI_IPOPT;
-   udpopt.nwuo_locport = ntalk_port;
-   udpopt.nwuo_remaddr = request->ctl_addr.sin_addr;
-   udpopt.nwuo_remport = request->ctl_addr.sin_port;
-
-   s = ioctl(udp_out, NWIOSUDPOPT, &udpopt);
-   if(s < 0) {
-   	perror("talkd: ioctl NWIOSUDPOPT");
-   	return(-1);
-   }
-
-   s = ioctl(udp_out, NWIOGUDPOPT, &udpopt);
-   if(s < 0) {
-   	perror("talkd: ioctl NWIOGUDPOPT");
-   	return(-1);
-   }
-
-   if(opt_d) {
-   	fprintf(stderr, "Reply:   ");
-	fprintf(stderr, "%02x %02x %02x %02x ",
-		reply->version, reply->type, reply->answer, reply->junk);
-	fprintf(stderr, "%08lx ", reply->id);
-	fprintf(stderr, "%04x %08lx:%04x",
-		reply->addr.sa_family, reply->addr.sin_addr, reply->addr.sin_port);
-	fprintf(stderr, "\n");
-   }
-
-   s = write(udp_out, reply, sizeof(struct talk_reply));
-   if(s < 0) {
-	perror("talkd: write");
-	return(-1);
-   }
-   if(s != sizeof(struct talk_reply)) {
-	fprintf(stderr, "talkd: write size mismatch %d %d\n",
-		s, sizeof(struct talk_reply));
-	return(-1);
-   }
-	
-   return(0);
-}
Index: trunk/minix/commands/talkd/net.h
===================================================================
--- trunk/minix/commands/talkd/net.h	(revision 9)
+++ 	(revision )
@@ -1,5 +1,0 @@
-/* net.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-_PROTOTYPE(int NetInit, (void));
-_PROTOTYPE(int getrequest, (struct talk_request *request));
-_PROTOTYPE(int sendreply, (struct talk_request *request, struct talk_reply *reply));
Index: trunk/minix/commands/talkd/process.c
===================================================================
--- trunk/minix/commands/talkd/process.c	(revision 9)
+++ 	(revision )
@@ -1,269 +1,0 @@
-/* process.c Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <time.h>
-#include <net/hton.h>
-#include <net/gen/socket.h>
-#include <net/gen/in.h>
-#include <net/gen/netdb.h>
-
-#include "talk.h"
-#include "talkd.h"
-#include "process.h"
-#include "finduser.h"
-
-struct entry {
-	struct entry *prev;
-	struct talk_request rq;
-	time_t expire;
-	struct entry *next;
-};
-
-_PROTOTYPE(static int announce, (struct talk_request *request, char *rhost));
-_PROTOTYPE(static struct talk_request *lookup, (struct talk_request *request, int type));
-_PROTOTYPE(static int addreq, (struct talk_request *request));
-_PROTOTYPE(static delete_invite, (long id));
-_PROTOTYPE(static long nextid, (void));
-_PROTOTYPE(static void delete, (struct entry *e));
-
-static struct entry *entry = (struct entry *)NULL;
-
-int processrequest(request, reply)
-struct talk_request *request;
-struct talk_reply *reply;
-{
-char *p;
-struct talk_request *rq;
-struct hostent *hp;
-
-   reply->version = TALK_VERSION;
-   reply->type = request->type;
-   reply->answer = 0;
-   reply->junk = 0;
-   reply->id = htonl(0);
-
-
-   /* check version */
-   if(request->version != TALK_VERSION) {
-   	reply->answer = BADVERSION;
-   	return(0);
-   }
-
-   /* check address family */
-   if(ntohs(request->addr.sa_family) != AF_INET) {
-   	reply->answer = BADADDR;
-   	return(0);
-   }
-
-   /* check control address family */
-   if(ntohs(request->ctl_addr.sa_family) != AF_INET) {
-   	reply->answer = BADCTLADDR;
-   	return(0);
-   }
-
-   /* check local name */
-   p = request->luser;
-   while(*p)
-   	if(!isprint(*p)) {
-   		reply->answer = FAILED;
-   		return(0);
-   	} else
-   		p++;
-
-   switch(request->type) {
-   	case ANNOUNCE:
-		reply->answer = find_user(request->ruser, request->rtty);
-		if(reply->answer != SUCCESS) break;
-		hp = gethostbyaddr((char *)&request->ctl_addr.sin_addr, sizeof(ipaddr_t), AF_INET);
-		if(hp == (struct hostent *)NULL) {
-			reply->answer = MACHINE_UNKNOWN;
-			break;
-		}
-		if((rq = lookup(request, 1)) == (struct talk_request *)NULL) {
-			reply->id = addreq(request);
-			reply->answer = announce(request, hp->h_name);
-			break;
-		}
-		if(ntohl(request->id) > ntohl(rq->id)) {
-			rq->id = nextid();
-			reply->id = rq->id;
-			reply->answer = announce(request, hp->h_name);
-		} else {
-			reply->id = rq->id;
-			reply->answer = SUCCESS;
-		}
-   		break;
-   	case LEAVE_INVITE:
-		rq = lookup(request, 1);
-		if(rq == (struct talk_request *)NULL)
-			reply->id = addreq(request);
-		else {
-			reply->id = rq->id;
-			reply->answer = SUCCESS;
-		}
-   		break;
-   	case LOOK_UP:
-		if((rq = lookup(request, 0)) == (struct talk_request *)NULL)
-			reply->answer = NOT_HERE;
-		else {
-			reply->id = rq->id;
-			memcpy((char *)&reply->addr, (char *)&rq->addr, sizeof(reply->addr));
-			reply->answer = SUCCESS;
-		}
-   		break;
-   	case DELETE:
-		reply->answer = delete_invite(request->id);
-   		break;
-   	default:
-   		reply->answer = UNKNOWN_REQUEST;
-   }
-
-   return(0);
-}
-
-static int announce(request, rhost)
-struct talk_request *request;
-char *rhost;
-{
-char tty[5+TTY_SIZE+1];
-struct stat st;
-FILE *fp;
-time_t now;
-struct tm *tm;
-
-   sprintf(tty, "/dev/%s", request->rtty);
-
-   if(stat(tty, &st) < 0)
-   	return(PERMISSION_DENIED);
-
-   if(!(st.st_mode & S_IWGRP))
-   	return(PERMISSION_DENIED);
-
-   if((fp = fopen(tty, "w")) == (FILE *)NULL)
-   	return(PERMISSION_DENIED);
-
-   (void) time(&now);
-
-   tm = localtime(&now);
-
-   fprintf(fp, "\007\007\007\rtalkd: Message from talkd@%s at %d:%02d:%02d\r\n",
-		myhostname, tm->tm_hour, tm->tm_min, tm->tm_sec);
-   fprintf(fp, "talkd: %s@%s would like to talk to you\r\n",
-   		request->luser, rhost);
-   fprintf(fp, "talkd: to answer type:  talk %s@%s\r\n",
-   		request->luser, rhost);
-
-   fclose(fp);
-
-   return(SUCCESS);
-}
-
-static struct talk_request *lookup(request, type)
-struct talk_request *request;
-int type;
-{
-time_t now;
-struct entry *e;
-
-   (void) time(&now);
-
-   for(e = entry; e != (struct entry *)NULL; e = e->next) {
-	if(now > e->expire) {
-		delete(e);
-		continue;
-	}
-	if(type == 0) {
-		if(!strncmp(request->luser, e->rq.ruser, USER_SIZE) &&
-		   !strncmp(request->ruser, e->rq.luser, USER_SIZE) &&
-		   e->rq.type == LEAVE_INVITE)
-			return(&e->rq);
-	} else {
-		if(request->type == e->rq.type &&
-	  	   request->pid == e->rq.pid &&
-		   !strncmp(request->luser, e->rq.luser, USER_SIZE) &&
-		   !strncmp(request->ruser, e->rq.ruser, USER_SIZE)) {
-			e->expire = now + MAX_LIFE;
-			return(&e->rq);
-		}
-	}
-   }
-   return((struct talk_request *)NULL);
-}
-
-static int addreq(request)
-struct talk_request *request;
-{
-time_t now;
-struct entry *e;
-
-   (void) time(&now);
-   request->id = nextid();
-   e = (struct entry *) malloc(sizeof(struct entry));
-   if(e == (struct entry *)NULL) {
-   	fprintf(stderr, "talkd: out of memory in insert table\n");
-   	exit(1);
-   }
-   e->expire = now + MAX_LIFE;
-   memcpy((char *)&e->rq, (char *)request, sizeof(struct talk_request));
-   e->next = entry;
-   if(e->next != (struct entry *)NULL)
-   	e->next->prev = e;
-   e->prev = (struct entry *)NULL;
-   entry = e;
-   return(request->id);
-}
-
-static int delete_invite(id)
-long id;
-{
-time_t now;
-struct entry *e;
-
-   (void) time(&now);
-
-   for(e = entry; e != (struct entry *)NULL; e = e->next) {
-	if(now > e->expire) {
-		delete(e);
-		continue;
-	}
-	if(e->rq.id == id) {
-		delete(e);
-		return(SUCCESS);
-	}
-   }
-   return(NOT_HERE);
-}
-
-static void delete(e)
-struct entry *e;
-{
-   if(e == (struct entry *)NULL) return;
-
-   if(entry == e)
-	entry = e->next;
-   else
-	if(e->prev != (struct entry *)NULL)
-		e->prev->next = e->next;
-
-   if(e->next != (struct entry *)NULL)
-	e->next->prev = e->prev;
-
-   free((char *)e);
-
-   return;
-}
-
-static long nextid()
-{
-static long id = 0;
-
-   id++;
-   if(id <= 0) id = 1;
-   return(htonl(id));
-}
Index: trunk/minix/commands/talkd/process.h
===================================================================
--- trunk/minix/commands/talkd/process.h	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-/* process.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-_PROTOTYPE(int processrequest, (struct talk_request *request, struct talk_reply *reply));
Index: trunk/minix/commands/talkd/talk.h
===================================================================
--- trunk/minix/commands/talkd/talk.h	(revision 9)
+++ 	(revision )
@@ -1,57 +1,0 @@
-/* talk.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-#define	USER_SIZE	12
-#define	TTY_SIZE	16
-#define	HOST_SIZE	255
-
-struct osockaddr {
-	u16_t sa_family;
-	u16_t sin_port;
-	ipaddr_t sin_addr;
-	char junk[8];
-};
-
-struct talk_request {
-	u8_t version;
-	u8_t type;
-	u8_t answer;
-	u8_t junk;
-	u32_t id;
-	struct osockaddr addr;
-	struct osockaddr ctl_addr;
-	long pid;
-	char	luser[USER_SIZE];
-	char	ruser[USER_SIZE];
-	char	rtty[TTY_SIZE];
-};
-
-struct talk_reply {
-	u8_t version;
-	u8_t type;
-	u8_t answer;
-	u8_t junk;
-	u32_t id;
-	struct osockaddr addr;
-};
-
-#define	TALK_VERSION	1
-
-/* message type values */
-#define LEAVE_INVITE	0	/* leave invitation with server */
-#define LOOK_UP		1	/* check for invitation by callee */
-#define DELETE		2	/* delete invitation by caller */
-#define ANNOUNCE	3	/* announce invitation by caller */
-
-/* answer values */
-#define SUCCESS		0	/* operation completed properly */
-#define NOT_HERE	1	/* callee not logged in */
-#define FAILED		2	/* operation failed for unexplained reason */
-#define MACHINE_UNKNOWN	3	/* caller's machine name unknown */
-#define PERMISSION_DENIED 4	/* callee's tty doesn't permit announce */
-#define UNKNOWN_REQUEST	5	/* request has invalid type value */
-#define	BADVERSION	6	/* request has invalid protocol version */
-#define	BADADDR		7	/* request has invalid addr value */
-#define	BADCTLADDR	8	/* request has invalid ctl_addr value */
-
-#define MAX_LIFE	60	/* max time daemon saves invitations */
-#define RING_WAIT	30	/* time to wait before resending invitation */
Index: trunk/minix/commands/talkd/talkd.c
===================================================================
--- trunk/minix/commands/talkd/talkd.c	(revision 9)
+++ 	(revision )
@@ -1,54 +1,0 @@
-/* talkd.c Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <net/gen/in.h>
-
-#include "talk.h"
-#include "talkd.h"
-#include "net.h"
-#include "process.h"
-
-_PROTOTYPE(int main, (int argc, char *argv[]));
-
-int opt_d = 0;
-char myhostname[HOST_SIZE+1];
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-struct talk_request request;
-struct talk_reply reply;
-
-   if(argc > 1)
-   	if(strcmp(argv[1], "-d") || argc > 2) {
-   		fprintf(stderr, "Usage: talkd [-d]\n");
-   		return(-1);
-   	} else
-		opt_d = 1;
-
-   if(getuid() != 0) {
-	fprintf(stderr, "talkd: Must be run as super user\n");
-	return(-1);
-   }
-
-   if(gethostname(myhostname, HOST_SIZE) < 0) {
-   	fprintf(stderr, "talkd: Error getting hostname\n");
-   	return(-1);
-   }
-
-   if(NetInit()) {
-   	fprintf(stderr, "talkd: Error in NetInit\n");
-   	return(-1);
-   }
-
-   while(getrequest(&request) == 0) {
-   	if(processrequest(&request, &reply)) break;
-   	if(sendreply(&request, &reply)) break;
-   }
-
-   return(-1);
-}
Index: trunk/minix/commands/talkd/talkd.h
===================================================================
--- trunk/minix/commands/talkd/talkd.h	(revision 9)
+++ 	(revision )
@@ -1,4 +1,0 @@
-/* talkd.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
-
-extern int opt_d;	/* debug option */
-extern char myhostname[];
Index: trunk/minix/commands/telnet/Makefile
===================================================================
--- trunk/minix/commands/telnet/Makefile	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-# Makefile for telnet
-
-CFLAGS=	-D_MINIX -D_POSIX_SOURCE
-LDFLAGS=-i
-CC = exec cc
-
-SRC=	ttn.c ttn_conf.c
-
-all:	ttn
-
-ttn:	$(SRC)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o ttn $(SRC)
-	install -S 4kw $@
-
-clean:
-	rm -f ttn
-
-install:	/usr/bin/telnet
-
-/usr/bin/telnet:	ttn
-	install -cs -o bin ttn $@
Index: trunk/minix/commands/telnet/build
===================================================================
--- trunk/minix/commands/telnet/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/telnet/ttn.c
===================================================================
--- trunk/minix/commands/telnet/ttn.c	(revision 9)
+++ 	(revision )
@@ -1,689 +1,0 @@
-/*
-ttn.c
-*/
-
-#ifndef _POSIX_SOURCE
-#define _POSIX_SOURCE 1
-#endif
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <termios.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <net/hton.h>
-#include <net/netlib.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/netdb.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include "ttn.h"
-
-#if __STDC__
-#define PROTOTYPE(func,args) func args
-#else
-#define PROTOTYPE(func,args) func()
-#endif
-
-static int do_read(int fd, char *buf, unsigned len);
-static void screen(void);
-static void keyboard(void);
-static void send_brk(void);
-static int process_opt (char *bp, int count);
-static void do_option (int optsrt);
-static void dont_option (int optsrt);
-static void will_option (int optsrt);
-static void wont_option (int optsrt);
-static int writeall (int fd, char *buffer, int buf_size);
-static int sb_termtype (char *sb, int count);
-static void fatal(char *fmt, ...);
-static void usage(void);
-
-#if DEBUG
-#define where() (fprintf(stderr, "%s %d:", __FILE__, __LINE__))
-#endif
-
-static char *prog_name;
-static tcp_fd;
-static char *term_env;
-static int esc_char= '~';
-static enum { LS_NORM, LS_BOL, LS_ESC } line_state= LS_BOL;
-
-int main(int argc, char *argv[])
-{
-	struct hostent *hostent;
-	struct servent *servent;
-	ipaddr_t host;
-	tcpport_t port;
-	int pid, ppid;
-	nwio_tcpconf_t tcpconf;
-	int c, r;
-	nwio_tcpcl_t tcpconnopt;
-	struct termios termios;
-	char *tcp_device, *remote_name, *port_name;
-	char *e_arg;
-
-	(prog_name=strrchr(argv[0],'/')) ? prog_name++ : (prog_name=argv[0]);
-
-	e_arg= NULL;
-	while (c= getopt(argc, argv, "?e:"), c != -1)
-	{
-		switch(c)
-		{
-		case '?': usage();
-		case 'e': e_arg= optarg; break;
-		default:
-			fatal("Optind failed: '%c'", c);
-		}
-	}
-
-	if (optind >= argc)
-		usage();
-	remote_name= argv[optind++];
-	if (optind < argc)
-		port_name= argv[optind++];
-	else
-		port_name= NULL;
-	if (optind != argc)
-		usage();
-
-	if (e_arg)
-	{
-		switch(strlen(e_arg))
-		{
-		case 0: esc_char= -1; break;
-		case 1: esc_char= e_arg[0]; break;
-		default: fatal("Invalid escape character '%s'", e_arg);
-		}
-	}
-
-	hostent= gethostbyname(remote_name);
-	if (!hostent)
-		fatal("Unknown host %s", remote_name);
-	host= *(ipaddr_t *)(hostent->h_addr);
-
-	if (!port_name)
-		port= htons(TCPPORT_TELNET);
-	else
-	{
-		servent= getservbyname (port_name, "tcp");
-		if (!servent)
-		{
-			port= htons(strtol(port_name, (char **)0, 0));
-			if (!port)
-				fatal("Unknown port %s", port_name);
-		}
-		else
-			port= (tcpport_t)(servent->s_port);
-	}
-
-	fprintf(stderr, "Connecting to %s:%u...\n",
-		inet_ntoa(host), ntohs(port));
-
-	tcp_device= getenv("TCP_DEVICE");
-	if (tcp_device == NULL)
-		tcp_device= TCP_DEVICE;
-	tcp_fd= open (tcp_device, O_RDWR);
-	if (tcp_fd == -1)
-		fatal("Unable to open %s: %s", tcp_device, strerror(errno));
-
-	tcpconf.nwtc_flags= NWTC_LP_SEL | NWTC_SET_RA | NWTC_SET_RP;
-	tcpconf.nwtc_remaddr= host;
-	tcpconf.nwtc_remport= port;
-
-	r= ioctl (tcp_fd, NWIOSTCPCONF, &tcpconf);
-	if (r == -1)
-		fatal("NWIOSTCPCONF failed: %s", strerror(errno));
-
-	tcpconnopt.nwtcl_flags= 0;
-	do
-	{
-		r= ioctl (tcp_fd, NWIOTCPCONN, &tcpconnopt);
-		if (r == -1 && errno == EAGAIN)
-		{
-			fprintf(stderr, "%s: Got EAGAIN, sleeping(1s)\n",
-				prog_name);
-			sleep(1);
-		}
-	} while (r == -1 && errno == EAGAIN);
-	if (r == -1)
-		fatal("Unable to connect: %s", strerror(errno));
-	printf("Connected\n");
-	ppid= getpid();
-	pid= fork();
-	switch(pid)
-	{
-	case 0:
-		keyboard();
-#if DEBUG
-fprintf(stderr, "killing %d with %d\r\n", ppid, SIGKILL);
-#endif
-		kill(ppid, SIGKILL);
-		break;
-	case -1:
-		fprintf(stderr, "%s: fork failed: %s\r\n", argv[0],
-			strerror(errno));
-		exit(1);
-		break;
-	default:
-		tcgetattr(0, &termios);
-		screen();
-#if DEBUG
-fprintf(stderr, "killing %d with %d\r\n", pid, SIGKILL);
-#endif
-		kill(pid, SIGKILL);
-		tcsetattr(0, TCSANOW, &termios);
-		break;
-	}
-	exit(0);
-}
-
-static int do_read(fd, buf, len)
-int fd;
-char *buf;
-unsigned len;
-{
-	nwio_tcpopt_t tcpopt;
-	int count;
-
-	for (;;)
-	{
-		count= read (fd, buf, len);
-		if (count <0)
-		{
-			if (errno == EURG || errno == ENOURG)
-			{
-				/* Toggle urgent mode. */
-				tcpopt.nwto_flags= errno == EURG ?
-					NWTO_RCV_URG : NWTO_RCV_NOTURG;
-				if (ioctl(tcp_fd, NWIOSTCPOPT, &tcpopt) == -1)
-				{
-					return -1;
-				}
-				continue;
-			}
-			return -1;
-		}
-		return count;
-	}
-}
-
-static void screen()
-{
-	char buffer[1024], *bp, *iacptr;
-	int count, optsize;
-
-	for (;;)
-	{
-		count= do_read (tcp_fd, buffer, sizeof(buffer));
-#if DEBUG && 0
- { where(); fprintf(stderr, "read %d bytes\r\n", count); }
-#endif
-		if (count <0)
-		{
-			perror ("read");
-			return;
-		}
-		if (!count)
-			return;
-		bp= buffer;
-		do
-		{
-			iacptr= memchr (bp, IAC, count);
-			if (!iacptr)
-			{
-				write(1, bp, count);
-				count= 0;
-			}
-			if (iacptr && iacptr>bp)
-			{
-#if DEBUG 
- { where(); fprintf(stderr, "iacptr-bp= %d\r\n", iacptr-bp); }
-#endif
-				write(1, bp, iacptr-bp);
-				count -= (iacptr-bp);
-				bp= iacptr;
-				continue;
-			}
-			if (iacptr)
-			{
-assert (iacptr == bp);
-				optsize= process_opt(bp, count);
-#if DEBUG && 0
- { where(); fprintf(stderr, "process_opt(...)= %d\r\n", optsize); }
-#endif
-				if (optsize<0)
-					return;
-assert (optsize);
-				bp += optsize;
-				count -= optsize;
-			}
-		} while (count);
-	}
-}
-
-static void keyboard()
-{
-	char c, buffer[1024];
-	int count;
-
-	for (;;)
-	{
-		count= read (0, buffer, 1 /* sizeof(buffer) */);
-		if (count == -1)
-			fatal("Read: %s\r\n", strerror(errno));
-		if (!count)
-			return;
-
-		if (line_state != LS_NORM)
-		{
-			c= buffer[0];
-			if (line_state == LS_BOL)
-			{
-				if (c == esc_char)
-				{
-					line_state= LS_ESC;
-					continue;
-				}
-				line_state= LS_NORM;
-			}
-			else if (line_state == LS_ESC)
-			{
-				line_state= LS_NORM;
-				if (c == '.')
-					return;
-				if (c == '#')
-				{
-					send_brk();
-					continue;
-				}
-
-				/* Not a valid command or a repeat of the
-				 * escape char
-				 */
-				if (c != esc_char)
-				{
-					c= esc_char;
-					write(tcp_fd, &c, 1);
-				}
-			}
-		}
-		if (buffer[0] == '\n')
-			write(tcp_fd, "\r", 1);
-		count= write(tcp_fd, buffer, count);
-		if (buffer[0] == '\r')
-		{
-			line_state= LS_BOL;
-			write(tcp_fd, "\0", 1);
-		}
-		if (count<0)
-		{
-			perror("write");
-			fprintf(stderr, "errno= %d\r\n", errno);
-			return;
-		}
-		if (!count)
-			return;
-	}
-}
-
-static void send_brk(void)
-{
-	int r;
-	unsigned char buffer[2];
-
-	buffer[0]= IAC;
-	buffer[1]= IAC_BRK;
-
-	r= writeall(tcp_fd, (char *)buffer, 2);
-	if (r == -1)
-		fatal("Error writing to TCP connection: %s", strerror(errno));
-}
-
-#define next_char(var) \
-	if (offset<count) { (var) = bp[offset++]; } \
-	else if (do_read(tcp_fd, (char *)&(var), 1) <= 0) \
-	{ perror ("read"); return -1; }
-
-static int process_opt (char *bp, int count)
-{
-	unsigned char iac, command, optsrt, sb_command;
-	int offset, result;	;
-#if DEBUG && 0
- { where(); fprintf(stderr, "process_opt(bp= 0x%x, count= %d)\r\n",
-	bp, count); }
-#endif
-
-	offset= 0;
-assert (count);
-	next_char(iac);
-assert (iac == IAC);
-	next_char(command);
-	switch(command)
-	{
-	case IAC_NOP:
-		break;
-	case IAC_DataMark:
-		/* Ought to flush input queue or something. */
-		break;
-	case IAC_BRK:
-fprintf(stderr, "got a BRK\r\n");
-		break;
-	case IAC_IP:
-fprintf(stderr, "got a IP\r\n");
-		break;
-	case IAC_AO:
-fprintf(stderr, "got a AO\r\n");
-		break;
-	case IAC_AYT:
-fprintf(stderr, "got a AYT\r\n");
-		break;
-	case IAC_EC:
-fprintf(stderr, "got a EC\r\n");
-		break;
-	case IAC_EL:
-fprintf(stderr, "got a EL\r\n");
-		break;
-	case IAC_GA:
-fprintf(stderr, "got a GA\r\n");
-		break;
-	case IAC_SB:
-		next_char(sb_command);
-		switch (sb_command)
-		{
-		case OPT_TERMTYPE:
-#if DEBUG && 0
-fprintf(stderr, "got SB TERMINAL-TYPE\r\n");
-#endif
-			result= sb_termtype(bp+offset, count-offset);
-			if (result<0)
-				return result;
-			else
-				return result+offset;
-		default:
-fprintf(stderr, "got an unknown SB (skiping)\r\n");
-			for (;;)
-			{
-				next_char(iac);
-				if (iac != IAC)
-					continue;
-				next_char(optsrt);
-				if (optsrt == IAC)
-					continue;
-if (optsrt != IAC_SE)
-	fprintf(stderr, "got IAC %d\r\n", optsrt);
-				break;
-			}
-		}
-		break;
-	case IAC_WILL:
-		next_char(optsrt);
-		will_option(optsrt);
-		break;
-	case IAC_WONT:
-		next_char(optsrt);
-		wont_option(optsrt);
-		break;
-	case IAC_DO:
-		next_char(optsrt);
-		do_option(optsrt);
-		break;
-	case IAC_DONT:
-		next_char(optsrt);
-		dont_option(optsrt);
-		break;
-	case IAC:
-fprintf(stderr, "got a IAC\r\n");
-		break;
-	default:
-fprintf(stderr, "got unknown command (%d)\r\n", command);
-	}
-	return offset;
-}
-
-static void do_option (int optsrt)
-{
-	unsigned char reply[3];
-	int result;
-
-	switch (optsrt)
-	{
-	case OPT_TERMTYPE:
-		if (WILL_terminal_type)
-			return;
-		if (!WILL_terminal_type_allowed)
-		{
-			reply[0]= IAC;
-			reply[1]= IAC_WONT;
-			reply[2]= optsrt;
-		}
-		else
-		{
-			WILL_terminal_type= TRUE;
-			term_env= getenv("TERM");
-			if (!term_env)
-				term_env= "unknown";
-			reply[0]= IAC;
-			reply[1]= IAC_WILL;
-			reply[2]= optsrt;
-		}
-		break;
-	default:
-#if DEBUG
-		fprintf(stderr, "got a DO (%d)\r\n", optsrt);
-		fprintf(stderr, "WONT (%d)\r\n", optsrt);
-#endif
-		reply[0]= IAC;
-		reply[1]= IAC_WONT;
-		reply[2]= optsrt;
-		break;
-	}
-	result= writeall(tcp_fd, (char *)reply, 3);
-	if (result<0)
-		perror("write");
-}
-
-static void will_option (int optsrt)
-{
-	unsigned char reply[3];
-	int result;
-
-	switch (optsrt)
-	{
-	case OPT_ECHO:
-		if (DO_echo)
-			break;
-		if (!DO_echo_allowed)
-		{
-			reply[0]= IAC;
-			reply[1]= IAC_DONT;
-			reply[2]= optsrt;
-		}
-		else
-		{
-			struct termios termios;
-
-			tcgetattr(0, &termios);
-			termios.c_iflag &= ~(ICRNL|IGNCR|INLCR|IXON|IXOFF);
-			termios.c_oflag &= ~(OPOST);
-			termios.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN|ISIG);
-			tcsetattr(0, TCSANOW, &termios);
-
-			DO_echo= TRUE;
-			reply[0]= IAC;
-			reply[1]= IAC_DO;
-			reply[2]= optsrt;
-		}
-		result= writeall(tcp_fd, (char *)reply, 3);
-		if (result<0)
-			perror("write");
-		break;
-	case OPT_SUPP_GA:
-		if (DO_suppress_go_ahead)
-			break;
-		if (!DO_suppress_go_ahead_allowed)
-		{
-			reply[0]= IAC;
-			reply[1]= IAC_DONT;
-			reply[2]= optsrt;
-		}
-		else
-		{
-			DO_suppress_go_ahead= TRUE;
-			reply[0]= IAC;
-			reply[1]= IAC_DO;
-			reply[2]= optsrt;
-		}
-		result= writeall(tcp_fd, (char *)reply, 3);
-		if (result<0)
-			perror("write");
-		break;
-	default:
-#if DEBUG
-		fprintf(stderr, "got a WILL (%d)\r\n", optsrt);
-		fprintf(stderr, "DONT (%d)\r\n", optsrt);
-#endif
-		reply[0]= IAC;
-		reply[1]= IAC_DONT;
-		reply[2]= optsrt;
-		result= writeall(tcp_fd, (char *)reply, 3);
-		if (result<0)
-			perror("write");
-		break;
-	}
-}
-
-static int writeall (fd, buffer, buf_size)
-int fd;
-char *buffer;
-int buf_size;
-{
-	int result;
-
-	while (buf_size)
-	{
-		result= write (fd, buffer, buf_size);
-		if (result <= 0)
-			return -1;
-assert (result <= buf_size);
-		buffer += result;
-		buf_size -= result;
-	}
-	return 0;
-}
-
-static void dont_option (int optsrt)
-{
-	switch (optsrt)
-	{
-	default:
-#if DEBUG
-		fprintf(stderr, "got a DONT (%d)\r\n", optsrt);
-#endif
-		break;
-	}
-}
-
-static void wont_option (int optsrt)
-{
-	switch (optsrt)
-	{
-	default:
-#if DEBUG
-		fprintf(stderr, "got a WONT (%d)\r\n", optsrt);
-#endif
-		break;
-	}
-}
-
-static int sb_termtype (char *bp, int count)
-{
-	unsigned char command, iac, optsrt;
-	unsigned char buffer[4];
-	int offset, result;
-
-	offset= 0;
-	next_char(command);
-	if (command == TERMTYPE_SEND)
-	{
-		buffer[0]= IAC;
-		buffer[1]= IAC_SB;
-		buffer[2]= OPT_TERMTYPE;
-		buffer[3]= TERMTYPE_IS;
-		result= writeall(tcp_fd, (char *)buffer,4);
-		if (result<0)
-			return result;
-		count= strlen(term_env);
-		if (!count)
-		{
-			term_env= "unknown";
-			count= strlen(term_env);
-		}
-		result= writeall(tcp_fd, term_env, count);
-		if (result<0)
-			return result;
-		buffer[0]= IAC;
-		buffer[1]= IAC_SE;
-		result= writeall(tcp_fd, (char *)buffer,2);
-		if (result<0)
-			return result;
-
-	}
-	else
-	{
-#if DEBUG
- where();
-#endif
-		fprintf(stderr, "got an unknown command (skipping)\r\n");
-	}
-	for (;;)
-	{
-		next_char(iac);
-		if (iac != IAC)
-			continue;
-		next_char(optsrt);
-		if (optsrt == IAC)
-			continue;
-		if (optsrt != IAC_SE)
-		{
-#if DEBUG
- where();
-#endif
-			fprintf(stderr, "got IAC %d\r\n", optsrt);
-		}
-		break;
-	}
-	return offset;
-}
-
-static void fatal(char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	fprintf(stderr, "%s: ", prog_name);
-	vfprintf(stderr, fmt, ap);
-	fprintf(stderr, "\n");
-	va_end(ap);
-
-	exit(1);
-}
-
-static void usage(void)
-{
-	fprintf(stderr, "Usage: %s [-e esc-char] host [port]\r\n",
-		prog_name);
-	exit(1);
-}
-
-/*
- * $PchId: ttn.c,v 1.5 2002/05/07 12:06:41 philip Exp $
- */
Index: trunk/minix/commands/telnet/ttn.h
===================================================================
--- trunk/minix/commands/telnet/ttn.h	(revision 9)
+++ 	(revision )
@@ -1,44 +1,0 @@
-/*
-ttn.h
-*/
-
-#ifndef TTN_H
-#define TTN_H
-
-#define IAC		255
-#define IAC_SE		240
-#define IAC_NOP		241
-#define IAC_DataMark	242
-#define IAC_BRK		243
-#define IAC_IP		244
-#define IAC_AO		245
-#define IAC_AYT		246
-#define IAC_EC		247
-#define IAC_EL		248
-#define IAC_GA		249
-#define IAC_SB		250
-#define IAC_WILL	251
-#define IAC_WONT	252
-#define IAC_DO		253
-#define IAC_DONT	254
-
-#define OPT_ECHO	1
-#define OPT_SUPP_GA	3
-#define OPT_TERMTYPE	24
-
-#define TERMTYPE_SEND	1
-#define TERMTYPE_IS	0
-
-#define FALSE	0
-#define TRUE	(!(FALSE))
-
-extern int DO_echo;
-extern int DO_echo_allowed;
-extern int WILL_terminal_type;
-extern int WILL_terminal_type_allowed;
-extern int DO_suppress_go_ahead;
-extern int DO_suppress_go_ahead_allowed;
-extern int WILL_suppress_go_ahead;
-extern int WILL_suppress_go_ahead_allowed;
-
-#endif /* TTN_H */
Index: trunk/minix/commands/telnet/ttn_conf.c
===================================================================
--- trunk/minix/commands/telnet/ttn_conf.c	(revision 9)
+++ 	(revision )
@@ -1,12 +1,0 @@
-/*
-ttn_conf.c
-*/
-
-#include "ttn.h"
-
-int DO_echo= FALSE;
-int DO_echo_allowed= TRUE;
-int WILL_terminal_type= FALSE;
-int WILL_terminal_type_allowed= TRUE;
-int DO_suppress_go_ahead= FALSE;
-int DO_suppress_go_ahead_allowed= TRUE;
Index: trunk/minix/commands/telnetd/Makefile
===================================================================
--- trunk/minix/commands/telnetd/Makefile	(revision 9)
+++ 	(revision )
@@ -1,32 +1,0 @@
-# Makefile for telnetd
-#
-# 01/30/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
-#
-
-CFLAGS=	-O -D_MINIX -D_POSIX_SOURCE
-LDFLAGS=-i
-BINDIR=	/usr/bin
-PROG=	in.telnetd
-CC = exec cc
-
-OBJS=	main.o telnet.o term.o pty.o wtmp.o
-
-all:	$(PROG)
-
-$(PROG):	$(OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(OBJS)
-	install -S 8kw $@
-
-clean:
-	rm -f $(PROG) $(OBJS)
-
-install:	$(BINDIR)/$(PROG)
-
-$(BINDIR)/$(PROG):	$(PROG)
-	install -cs -o bin $? $@
-
-main.o:		main.c		telnetd.h
-telnet.o:	telnet.c	telnetd.h	telnet.h
-term.o:		term.c		telnetd.h	telnet.h
-pty.o:		pty.c		telnetd.h
-wtmp.o:				telnetd.h
Index: trunk/minix/commands/telnetd/build
===================================================================
--- trunk/minix/commands/telnetd/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/telnetd/main.c
===================================================================
--- trunk/minix/commands/telnetd/main.c	(revision 9)
+++ 	(revision )
@@ -1,158 +1,0 @@
-/*
- * TNET		A server program for MINIX which implements the TCP/IP
- *		suite of networking protocols.  It is based on the
- *		TCP/IP code written by Phil Karn et al, as found in
- *		his NET package for Packet Radio communications.
- *
- *		This file contains an implementation of the "server"
- *		for the TELNET protocol.  This protocol can be used to
- *		remote-login on other systems, just like a normal TTY
- *		session.
- *
- * Usage:	telnetd [-dv]
- *
- * Version:	@(#)telnetd.c	1.00	07/26/92
- *
- * Author:	Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- *		Michael Temari, <temari@temari.ae.ge.com>
- */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/wait.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <time.h>
-#include <stdio.h>
-#include <ttyent.h>
-#include <utmp.h>
-#include <net/gen/in.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include <net/gen/socket.h>
-#include <net/gen/netdb.h>
-#include <net/gen/inet.h>
-#include "telnetd.h"
-
-static char *Version = "@(#) telnetd 1.00 (07/26/92)";
-
-int opt_d = 0;				/* debugging output flag	*/
-
-_PROTOTYPE(void usage, (void));
-_PROTOTYPE(int main, (int argc, char *argv[]));
-_PROTOTYPE(void wtmp, (int type, int linenr, char *line, pid_t pid,
-								char *host));
-
-void usage()
-{
-   fprintf(stderr, "Usage: telnetd [-dv]\n");
-
-   exit(-1);
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-char buff[128];
-register int c;
-int pty_fd;
-int tty_fd;
-pid_t pid;
-int lineno;
-char *tty_name;
-struct ttyent *ttyp;
-nwio_tcpconf_t tcpconf;
-struct hostent *hostent;
-char *hostname;
-
-   opterr = 0;
-   while ((c = getopt(argc, argv, "dv")) != EOF) switch(c) {
-	case 'd':
-	case 'v':
-		opt_d = 1;
-		break;
-	default:
-		usage();
-   }
-
-   /* No more arguments allowed. */
-   if (optind != argc) usage();
-
-   /* Obtain the name of the remote host. */
-   if (ioctl(0, NWIOGTCPCONF, &tcpconf) < 0) {
-	sprintf(buff, "Unable to obtain your IP address\r\n");
-	(void) write(1, buff, strlen(buff));
-	return(-1);
-   }
-   if ((hostent = gethostbyaddr((char *) &tcpconf.nwtc_remaddr,
-			sizeof(tcpconf.nwtc_remaddr), AF_INET)) != NULL) {
-	hostname = hostent->h_name;
-   } else {
-	hostname = inet_ntoa(tcpconf.nwtc_remaddr);
-   }
-
-   /* Try allocating a PTY. */
-   if (get_pty(&pty_fd, &tty_name) < 0) {
-	sprintf(buff, "I am sorry, but there is no free PTY left!\r\n");
-	(void) write(1, buff, strlen(buff));
-	return(-1);
-   }
-
-   /* Find the tty in the tty table. */
-   lineno = 0;
-   for (;;) {
-	if ((ttyp = getttyent()) == NULL) {
-		sprintf(buff, "Can't find %s in the tty table\r\n");
-		(void) write(1, buff, strlen(buff));
-	}
-	if (strcmp(ttyp->ty_name, tty_name+5) == 0) break;
-	lineno++;
-   }
-   endttyent();
-
-   /* Initialize the connection to an 8 bit clean channel. */
-   term_init();
-
-   /* Fork off a child process and have it execute a getty(8). */
-   if ((pid = fork()) == 0) {
-	/* Set up a new session. */
-	setsid();
-	if ((tty_fd = open(tty_name, O_RDWR)) < 0) {
-		sprintf(buff, "Can't open %s\r\n", tty_name);
-		(void) write(1, buff, strlen(buff));
-		return(-1);
-	}
-
-	close(pty_fd);
-	dup2(tty_fd, 0);
-	dup2(tty_fd, 1);
-	dup2(tty_fd, 2);
-	close(tty_fd);
-	(void) execl("/usr/sbin/getty", "getty", (char *)NULL);
-	(void) execl("/usr/bin/getty", "getty", (char *)NULL);
-	(void) execl("/usr/bin/login", "login", (char *)NULL);
-	(void) write(1, "EXEC failed!\r\n", 14);
-   } else if (pid < 0) {
-	sprintf(buff, "I am sorry, but the fork(2) call failed!\r\n");
-	(void) write(1, buff, strlen(buff));
-	(void) close(pty_fd);
-	return(-1);
-   }
-
-   wtmp(LOGIN_PROCESS, lineno, tty_name+5, pid, hostname);
-
-   term_inout(pty_fd);
-
-   (void) close(pty_fd);
-
-   wtmp(DEAD_PROCESS, lineno, tty_name+5, pid, hostname);
-
-   chown(tty_name, 0, 0);
-   chmod(tty_name, 0666);
-
-   return(0);
-}
Index: trunk/minix/commands/telnetd/pty.c
===================================================================
--- trunk/minix/commands/telnetd/pty.c	(revision 9)
+++ 	(revision )
@@ -1,78 +1,0 @@
-/*
- * TNET		A server program for MINIX which implements the TCP/IP
- *		suite of networking protocols.  It is based on the
- *		TCP/IP code written by Phil Karn et al, as found in
- *		his NET package for Packet Radio communications.
- *
- *		Handle the allocation of a PTY.
- *
- * Author:	Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- */
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdio.h>
-#include "telnetd.h"
-
-
-#define DEV_DIR		"/dev"
-
-/*
- * Allocate a PTY, by trying to open one repeatedly,
- * until all PTY channels are done.  If at that point
- * no PTY is found, go into panic mode :-(
- */
-int get_pty(pty_fdp, tty_namep)
-int *pty_fdp;
-char **tty_namep;
-{
-  char buff[128], temp[128];
-  register int i, j;
-  int pty_fd;
-  static char tty_name[128];
-
-  for(i = 'p'; i < 'w'; i++) {
-	j = 0;
-	do {
-		sprintf(buff, "%s/pty%c%c",
-			DEV_DIR, i, (j < 10) ? j + '0' : j + 'a' - 10);
-
-		if (opt_d == 1) {
-			(void) write(2, "Testing: ", 9);
-			(void) write(2, buff, strlen(buff));
-			(void) write(2, "...: ", 5);
-		}
-
-		pty_fd = open(buff, O_RDWR);
-		if (opt_d == 1) {
-			if (pty_fd < 0) sprintf(temp, "error %d\r\n", errno);
-			  else sprintf(temp, "OK\r\n");
-			(void) write(2, temp, strlen(temp));
-		}
-
-		if (pty_fd >= 0) break;
-
-		j++;
-		if (j == 16) break;
-	} while(1);
-
-	/* Did we find one? */
-	if (j < 16) break;
-  }
-  if (pty_fd < 0) return(-1);
-
-  if (opt_d == 1) {
-	sprintf(temp, "File %s, desc %d\n", buff, pty_fd);
-	(void) write(1, temp, strlen(temp));
-  }
-
-  sprintf(tty_name, "%s/tty%c%c", DEV_DIR,
-  					i, (j < 10) ? j + '0' : j + 'a' - 10);
-
-  *pty_fdp = pty_fd;
-  *tty_namep = tty_name;
-  return(0);
-}
Index: trunk/minix/commands/telnetd/telnet.c
===================================================================
--- trunk/minix/commands/telnetd/telnet.c	(revision 9)
+++ 	(revision )
@@ -1,337 +1,0 @@
-/*
- * TNET		A server program for MINIX which implements the TCP/IP
- *		suite of networking protocols.  It is based on the
- *		TCP/IP code written by Phil Karn et al, as found in
- *		his NET package for Packet Radio communications.
- *
- *		This module handles telnet option processing.
- *
- * Author:	Michael Temari, <temari@temari.ae.ge.com>  01/13/93
- *
- */
-#include <sys/types.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <termios.h>
-#include "telnetd.h"
-#include "telnet.h"
-#include <stdio.h>
-#include <sys/ioctl.h>
-
-
-#define	IN_DATA	0
-#define	IN_CR	1
-#define	IN_IAC	2
-#define	IN_IAC2	3
-#define IN_SB	4
-
-_PROTOTYPE(static void dowill, (int c));
-_PROTOTYPE(static void dowont, (int c));
-_PROTOTYPE(static void dodo, (int c));
-_PROTOTYPE(static void dodont, (int c));
-_PROTOTYPE(static void respond, (int ack, int option));
-_PROTOTYPE(static void respond_really, (int ack, int option));
-
-#define	LASTTELOPT	TELOPT_SGA
-
-static int r_winch = 0;
-
-static int TelROpts[LASTTELOPT+1];
-static int TelLOpts[LASTTELOPT+1];
-
-static int telfdout;
-
-void tel_init()
-{
-int i;
-
-   for(i = 0; i <= LASTTELOPT; i++) {
-	TelROpts[i] = 0;
-	TelLOpts[i] = 0;
-   }
-}
-
-void telopt(fdout, what, option)
-int fdout;
-int what;
-int option;
-{
-char buf[3];
-int len;
-
-   buf[0] = IAC;
-   buf[1] = what;
-   buf[2] = option;
-   len = 0;
-
-   switch(what) {
-	case DO:
-		if(option <= LASTTELOPT) {
-			TelROpts[option] = 1;
-			len = 3;
-		} else if(option == TELOPT_WINCH && !r_winch) { r_winch = 1; len = 3; } 
-		break;
-	case DONT:
-		if(option <= LASTTELOPT) {
-			TelROpts[option] = 1;
-			len = 3;
-		}
-		break;
-	case WILL:
-		if(option <= LASTTELOPT) {
-			TelLOpts[option] = 1;
-			len = 3;
-		}
-		break;
-	case WONT:
-		if(option <= LASTTELOPT) {
-			TelLOpts[option] = 1;
-			len = 3;
-		}
-		break;
-   }
-   if(len > 0)
-	(void) write(fdout, buf, len);
-}
-
-int set_winsize(int fd, unsigned int cols, unsigned int rows)
-{
-	struct winsize w;
-	memset(&w, 0, sizeof(w));
-	w.ws_col = cols;
-	w.ws_row = rows;
-	ioctl(fd, TIOCSWINSZ, (char *) &w);
-}
-
-int tel_in(fdout, telout, buffer, len)
-int fdout;
-int telout;
-char *buffer;
-int len;
-{
-static int InState = IN_DATA;
-static int ThisOpt = 0;
-char *p;
-char *p2;
-int size;
-int c;
-
-   telfdout = telout;
-   p = p2 = buffer;
-   size = 0;
-
-   while(len > 0) {
-   	c = (unsigned char)*p++; len--;
-	switch(InState) {
-   		case IN_CR:
-   			InState = IN_DATA;
-   			if(c == 0 || c == '\n')
-   				break;
-   			/* fall through */
-   		case IN_DATA:
-   			if(c == IAC) {
-   				InState = IN_IAC;
-   				break;
-   			}
-   			*p2++ = c; size++;
-   			if(c == '\r') InState = IN_CR;
-   			break;
-   		case IN_IAC:
-   			switch(c) {
-   				case IAC:
-	   				*p2++ = c; size++;
-   					InState = IN_DATA;
-   					break;
-   				case WILL:
-   				case WONT:
-   				case DO:
-   				case DONT:
-   					InState = IN_IAC2;
-   					ThisOpt = c;
-   					break;
-   				case SB:
-   				 	InState = IN_SB; 
-   					break;
-   				case EOR:
-   				case SE:
-   				case NOP:
-   				case BREAK:
-   				case IP:
-   				case AO:
-   				case AYT:
-   				case EC:
-   				case EL:
-   				case GA:
-   					break;
-   				default:
-   					break;
-   			}
-   			break;
-   		case IN_IAC2:
-   			if(size > 0) {
-   				write(fdout, buffer, size);
-   				p2 = buffer;
-   				size = 0;
-   			}
-   			InState = IN_DATA;
-   			switch(ThisOpt) {
-   				case WILL:	dowill(c);	break;
-   				case WONT:	dowont(c);	break;
-   				case DO:	dodo(c);	break;
-   				case DONT:	dodont(c);	break;
-   			}
-   			break;
-   		case IN_SB:
- 		{
-			static int winchpos = -1;
-   			/* Subnegotiation. */
-   			if(winchpos >= 0) {
-				static unsigned int winchbuf[5], iacs = 0;
-   				winchbuf[winchpos] = c;
-   				/* IAC is escaped - unescape it. */
-   				if(c == IAC) iacs++; else { iacs = 0; winchpos++; }
-   				if(iacs == 2) { winchpos++; iacs = 0; }
-   				if(winchpos >= 4) {
-   					/* End of WINCH data. */
-   					set_winsize(fdout,
-   					(winchbuf[0] << 8) | winchbuf[1],
-   					(winchbuf[2] << 8) | winchbuf[3]);
-   					winchpos = -1;
-   				}
-   			} else {
-				static int lastiac = 0;
-	   			switch(c) {
-   					case TELOPT_WINCH:
-   						/* Start listening. */
-   						winchpos = 0;
-   						break;
-   					case SE:
-   						if(lastiac) InState = IN_DATA;
-   						break;
-   					default:
-   						break;
-   				}
-   				if(c == IAC) lastiac = 1;
-   				else lastiac = 0;
-
-
-   			}
-   			break;
-   		}
-   	}
-   }
-
-   if(size > 0)
-   	write(fdout, buffer, size);
-}
-
-int tel_out(fdout, buf, size)
-int fdout;
-char *buf;
-int size;
-{
-char *p;
-int got_iac, len;
-
-   p = buf;
-   while(size > 0) {
-	buf = p;
-	got_iac = 0;
-	if((p = (char *)memchr(buf, IAC, size)) != (char *)NULL) {
-		got_iac = 1;
-		p++;
-	} else
-		p = buf + size;
-	len = p - buf;
-	if(len > 0)
-		(void) write(fdout, buf, len);
-	if(got_iac)
-		(void) write(fdout, p - 1, 1);
-	size = size - len;
-   }
-}
-
-static void dowill(c)
-int c;
-{
-int ack;
-
-   switch(c) {
-	case TELOPT_BINARY:
-	case TELOPT_ECHO:
-	case TELOPT_SGA:
-		if(TelROpts[c] == 1)
-			return;
-		TelROpts[c] = 1;
-		ack = DO;
-		break;
-	case TELOPT_WINCH:
-		if(r_winch) return;
-		r_winch = 1;
-		ack = DO;
- 		respond_really(ack, c); 
-		return;
-	default:
-		ack = DONT;
-   }
-
-   respond(ack, c);
-}
-
-static void dowont(c)
-int c;
-{
-   if(c <= LASTTELOPT) {
-	if(TelROpts[c] == 0)
-		return;
-	TelROpts[c] = 0;
-   }
-   respond(DONT, c);
-}
-
-static void dodo(c)
-int c;
-{
-int ack;
-
-   switch(c) {
-	default:
-		ack = WONT;
-   }
-   respond(ack, c);
-}
-
-static void dodont(c)
-int c;
-{
-   if(c <= LASTTELOPT) {
-	if(TelLOpts[c] == 0)
-		return;
-	TelLOpts[c] = 0;
-   }
-   respond(WONT, c);
-}
-
-static void respond(ack, option)
-int ack, option;
-{
-unsigned char c[3];
-
-   c[0] = IAC;
-   c[1] = ack;
-   c[2] = option;
-/*   write(telfdout, c, 3); */
-}
-
-static void respond_really(ack, option)
-int ack, option;
-{
-unsigned char c[3];
-
-   c[0] = IAC;
-   c[1] = ack;
-   c[2] = option;
-   write(telfdout, c, 3); 
-}
Index: trunk/minix/commands/telnetd/telnet.h
===================================================================
--- trunk/minix/commands/telnetd/telnet.h	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-/*
- * TNET		A server program for MINIX which implements the TCP/IP
- *		suite of networking protocols.  It is based on the
- *		TCP/IP code written by Phil Karn et al, as found in
- *		his NET package for Packet Radio communications.
- *
- * 		Definitions for the TELNET protocol (see RFC XXX).
- *
- * Version:	@(#)arpa/telnet.h	1.00		07/02/92
- *
- * Authors:	Original taken from BSD 4.3/TAHOE.
- *		Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- */
-#ifndef _ARPA_TELNET_H
-#define _ARPA_TELNET_H
-
-#define	IAC		255	/* interpret as command:		*/
-#define	DONT		254	/* you are not to use option		*/
-#define	DO		253	/* please, you use option		*/
-#define	WONT		252	/* I won't use option			*/
-#define	WILL		251	/* I will use option			*/
-#define	SB		250	/* interpret as subnegotiation		*/
-#define	GA		249	/* you may reverse the line		*/
-#define	EL		248	/* erase the current line		*/
-#define	EC		247	/* erase the current character		*/
-#define	AYT		246	/* are you there			*/
-#define	AO		245	/* abort output--but let prog finish	*/
-#define	IP		244	/* interrupt process--permanently	*/
-#define	BREAK		243	/* break				*/
-#define	DM		242	/* data mark--for connect. cleaning	*/
-#define	NOP		241	/* nop					*/
-#define	SE		240	/* end sub negotiation			*/
-#define EOR     	239     /* end of record (transparent mode)	*/
-
-#define SYNCH		242	/* for telfunc calls			*/
-
-/* Telnet options. */
-#define TELOPT_BINARY	0	/* 8-bit data path			*/
-#define TELOPT_ECHO	1	/* echo					*/
-#define	TELOPT_RCP	2	/* prepare to reconnect			*/
-#define	TELOPT_SGA	3	/* suppress go ahead			*/
-#define	TELOPT_NAMS	4	/* approximate message size		*/
-#define	TELOPT_STATUS	5	/* give status				*/
-#define	TELOPT_TM	6	/* timing mark				*/
-#define	TELOPT_RCTE	7	/* remote controlled transmission and echo */
-#define TELOPT_NAOL 	8	/* negotiate about output line width	*/
-#define TELOPT_NAOP 	9	/* negotiate about output page size	*/
-#define TELOPT_NAOCRD	10	/* negotiate about CR disposition	*/
-#define TELOPT_NAOHTS	11	/* negotiate about horizontal tabstops	*/
-#define TELOPT_NAOHTD	12	/* negotiate about horizontal tab disposition */
-#define TELOPT_NAOFFD	13	/* negotiate about formfeed disposition	*/
-#define TELOPT_NAOVTS	14	/* negotiate about vertical tab stops	*/
-#define TELOPT_NAOVTD	15	/* negotiate about vertical tab disposition */
-#define TELOPT_NAOLFD	16	/* negotiate about output LF disposition */
-#define TELOPT_XASCII	17	/* extended ascic character set		*/
-#define	TELOPT_LOGOUT	18	/* force logout				*/
-#define	TELOPT_BM	19	/* byte macro				*/
-#define	TELOPT_DET	20	/* data entry terminal			*/
-#define	TELOPT_SUPDUP	21	/* supdup protocol			*/
-#define	TELOPT_SUPDUPOUTPUT 22	/* supdup output			*/
-#define	TELOPT_SNDLOC	23	/* send location			*/
-#define	TELOPT_TTYPE	24	/* terminal type			*/
-#define	TELOPT_EOR	25	/* end or record			*/
-#define	TELOPT_WINCH	31	/* window size				*/
-#define TELOPT_EXOPL	255	/* extended-options-list		*/
-
-/* Sub-option qualifiers. */
-#define	TELQUAL_IS	0	/* option is...				*/
-#define	TELQUAL_SEND	1	/* send option				*/
-
-#endif /* _ARPA_TELNET_H */
Index: trunk/minix/commands/telnetd/telnetd.h
===================================================================
--- trunk/minix/commands/telnetd/telnetd.h	(revision 9)
+++ 	(revision )
@@ -1,20 +1,0 @@
-/*
- * TNET		A server program for MINIX which implements the TCP/IP
- *		suite of networking protocols.  It is based on the
- *		TCP/IP code written by Phil Karn et al, as found in
- *		his NET package for Packet Radio communications.
- *
- *		Definitions for the TELNET server.
- *
- * Author:	Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- */
-
-extern int opt_d;			/* debugging flag		*/
-
-_PROTOTYPE(int get_pty, (int *, char **));
-_PROTOTYPE(void term_init, (void));
-_PROTOTYPE(void term_inout, (int pty_fd));
-_PROTOTYPE(void tel_init, (void));
-_PROTOTYPE(void telopt, (int fdout, int what, int option));
-_PROTOTYPE(int tel_in, (int fdout, int telout, char *buffer, int len));
-_PROTOTYPE(int tel_out, (int fdout, char *buf, int size));
Index: trunk/minix/commands/telnetd/term.c
===================================================================
--- trunk/minix/commands/telnetd/term.c	(revision 9)
+++ 	(revision )
@@ -1,86 +1,0 @@
-/*
- * TNET		A server program for MINIX which implements the TCP/IP
- *		suite of networking protocols.  It is based on the
- *		TCP/IP code written by Phil Karn et al, as found in
- *		his NET package for Packet Radio communications.
- *
- *		Handle the TERMINAL module.
- *
- * Author:	Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- *              Michael Temari, <temari@temari.ae.ge.com>
- *
- * 07/29/92 MT  Telnet options hack which seems to work okay
- * 01/12/93 MT  Better telnet options processing instead of hack
- */
-#include <sys/types.h>
-#include <errno.h>
-#if 0
-#include <fcntl.h>
-#endif
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdio.h>
-#include <signal.h>
-#include "telnet.h"
-#include "telnetd.h"
-
-_PROTOTYPE(void sig_done, (int sig));
-
-static char buff[4096];
-
-void term_init()
-{
-  tel_init();
-
-  telopt(1, WILL, TELOPT_SGA);
-  telopt(1, DO,   TELOPT_SGA);
-  telopt(1, WILL, TELOPT_BINARY);
-  telopt(1, DO,   TELOPT_BINARY);
-  telopt(1, WILL, TELOPT_ECHO);
-  telopt(1, DO,   TELOPT_WINCH);
-}
-
-static int io_done = 0;
-
-void term_inout(pty_fd)
-int pty_fd;
-{
-register int i;
-pid_t pid;
-struct sigaction sa;
-
-  sigemptyset(&sa.sa_mask);
-  sa.sa_flags = 0;
-  sa.sa_handler = sig_done;
-  sigaction(SIGALRM, &sa, (struct sigaction *) NULL);
-
-  if ((pid = fork()) == -1) {
-	sprintf(buff, "telnetd: fork() failed: %s\r\n", strerror(errno));
-	(void) write(1, buff, strlen(buff));
-  }
-
-  if (pid != 0) {
-	/* network -> login process */
-	while (!io_done && (i = read(0, buff, sizeof(buff))) > 0) {
-		tel_in(pty_fd, 1, buff, i);
-	}
-	/* EOF, kill opposite number and exit. */
-	(void) kill(pid, SIGKILL);
-  } else {
-  	/* login process -> network */
-	while ((i = read(pty_fd, buff, sizeof(buff))) > 0) {
-		tel_out(1, buff, i);
-	}
-	/* EOF, alert opposite number and exit. */
-	(void) kill(getppid(), SIGALRM);
-  }
-  /* EOF. */
-}
-
-void sig_done(sig)
-int sig;
-{
-  io_done = 1;
-  alarm(1);			/* there is always a chance... */
-}
Index: trunk/minix/commands/telnetd/wtmp.c
===================================================================
--- trunk/minix/commands/telnetd/wtmp.c	(revision 9)
+++ 	(revision )
@@ -1,113 +1,0 @@
-/*
- * TNET		A server program for MINIX which implements the TCP/IP
- *		suite of networking protocols.  It is based on the
- *		TCP/IP code written by Phil Karn et al, as found in
- *		his NET package for Packet Radio communications.
- *
- *		This file contains an implementation of the "server"
- *		for the TELNET protocol.  This protocol can be used to
- *		remote-login on other systems, just like a normal TTY
- *		session.
- *
- * Usage:	telnetd [-dv]
- *
- * Version:	@(#)telnetd.c	1.00	07/26/92
- *
- * Author:	Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- *		Michael Temari, <temari@temari.ae.ge.com>
- */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <utmp.h>
-#include <time.h>
-#include <stdio.h>
-#include "telnetd.h"
-
-static char PATH_UTMP[] = "/etc/utmp";
-static char PATH_WTMP[] = "/usr/adm/wtmp";
-
-_PROTOTYPE(void wtmp, (int type, int linenr, char *line, pid_t pid,
-								char *host));
-_PROTOTYPE(void report, (char *label));
-
-void wtmp(type, linenr, line, pid, host)
-int type;			/* type of entry */
-int linenr;			/* line number in ttytab */
-char *line;			/* tty name (only good on login) */
-pid_t pid;			/* pid of process */
-char *host;			/* name of the remote host */
-{
-/* Log an event into the UTMP and WTMP files. */
-
-  struct utmp utmp;		/* UTMP/WTMP User Accounting */
-  int fd;
-
-  /* Clear the utmp record. */
-  memset((void *) &utmp, 0, sizeof(utmp));
-
-  /* Fill in utmp. */
-  switch (type) {
-  case LOGIN_PROCESS:
-  	/* A new login, fill in line and host name. */
-	strncpy(utmp.ut_line, line, sizeof(utmp.ut_line));
-	strncpy(utmp.ut_host, host, sizeof(utmp.ut_host));
-	break;
-
-  case DEAD_PROCESS:
-	/* A logout.  Use the current utmp entry, but make sure it is a
-	 * user process exiting, and not getty or login giving up.
-	 */
-	if ((fd = open(PATH_UTMP, O_RDONLY)) < 0) {
-		if (errno != ENOENT) report(PATH_UTMP);
-		return;
-	}
-	if (lseek(fd, (off_t) (linenr+1) * sizeof(utmp), SEEK_SET) == -1
-		|| read(fd, &utmp, sizeof(utmp)) == -1
-	) {
-		report(PATH_UTMP);
-		close(fd);
-		return;
-	}
-	close(fd);
-	if (utmp.ut_type != USER_PROCESS) return;
-	strncpy(utmp.ut_name, "", sizeof(utmp.ut_name));
-	break;
-  }
-
-  /* Finish new utmp entry. */
-  utmp.ut_pid = pid;
-  utmp.ut_type = type;
-  utmp.ut_time = time((time_t *) 0);
-
-  /* Write new entry to utmp. */
-  if ((fd = open(PATH_UTMP, O_WRONLY)) < 0
-	|| lseek(fd, (off_t) (linenr+1) * sizeof(utmp), SEEK_SET) == -1
-	|| write(fd, &utmp, sizeof(utmp)) == -1
-  ) {
-	if (errno != ENOENT) report(PATH_UTMP);
-  }
-  if (fd != -1) close(fd);
-
-  if (type == DEAD_PROCESS) {
-	/* Add new wtmp entry. */
-	if ((fd = open(PATH_WTMP, O_WRONLY | O_APPEND)) < 0
-		  || write(fd, &utmp, sizeof(utmp)) == -1
-	) {
-		if (errno != ENOENT) report(PATH_WTMP);
-	}
-	if (fd != -1) close(fd);
-  }
-}
-
-void report(label)
-char *label;
-{
-  char message[128];
-
-  sprintf(message, "telnetd: %s: %s\r\n", strerror(errno));
-  (void) write(1, message, strlen(message));
-}
Index: trunk/minix/commands/urlget/Makefile
===================================================================
--- trunk/minix/commands/urlget/Makefile	(revision 9)
+++ 	(revision )
@@ -1,36 +1,0 @@
-# Makefile for urlget
-#
-# 07/02/96 Initial Release	Michael Temari, <temari@ix.netcom.com>
-#
-
-CFLAGS=	-D_MINIX $(OPT)
-LDFLAGS=-fnone
-BINDIR=	/usr/bin
-PROG=	urlget
-LINK1=	httpget
-LINK2=	ftpget
-CC=exec cc
-
-OBJS=	urlget.o net.o
-
-all:	$(PROG)
-
-$(PROG):	$(OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(OBJS)
-	install -S 4kw $@
-
-clean:
-	rm -f $(PROG) $(OBJS)
-
-tar:
-	tar cvf urlget.tar Makefile urlget.c net.c net.h
-
-install:	$(BINDIR)/$(PROG) $(BINDIR)/$(LINK1) $(BINDIR)/$(LINK2)
-
-$(BINDIR)/$(PROG):	$(PROG)
-	install -c $? $@
-
-$(BINDIR)/$(LINK1) $(BINDIR)/$(LINK2):	$(BINDIR)/$(PROG)
-	install -l $? $@
-
-$(OBJS):	net.h
Index: trunk/minix/commands/urlget/build
===================================================================
--- trunk/minix/commands/urlget/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/urlget/net.c
===================================================================
--- trunk/minix/commands/urlget/net.c	(revision 9)
+++ 	(revision )
@@ -1,98 +1,0 @@
-/* net.c Copyright 2000 by Michael Temari All Rights Reserved */
-/* 04/05/2000 Michael Temari <Michael@TemWare.Com> */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-#include <time.h>
-#include <net/netlib.h>
-#include <net/hton.h>
-#include <net/gen/in.h>
-#include <net/gen/inet.h>
-#include <net/gen/tcp.h>
-#include <net/gen/tcp_io.h>
-#include <net/gen/socket.h>
-#include <net/gen/netdb.h>
-
-#include "net.h"
-
-int connect(host, port)
-char *host;
-int port;
-{
-nwio_tcpconf_t tcpconf;
-nwio_tcpcl_t tcpcopt;
-char *tcp_device;
-int netfd;
-ipaddr_t nethost;
-tcpport_t netport;
-struct hostent *hp;
-struct servent *sp;
-char *p;
-int s;
-int tries;
-
-   if((hp = gethostbyname(host)) == (struct hostent *)NULL) {
-	fprintf(stderr, "Unknown host %s!\n", host);  
-	return(-1);
-   } else
-	memcpy((char *) &nethost, (char *) hp->h_addr, hp->h_length);
-
-   netport = htons(port);
-
-   /* Connect to the host */
-   if((tcp_device = getenv("TCP_DEVICE")) == NULL)
-	tcp_device = TCP_DEVICE;
-
-   if((netfd = open(tcp_device, O_RDWR)) < 0) {
-	perror("httpget: opening tcp");
-	return(-1);
-   }
-
-   tcpconf.nwtc_flags = NWTC_LP_SEL | NWTC_SET_RA | NWTC_SET_RP;
-   tcpconf.nwtc_remaddr = nethost;
-   tcpconf.nwtc_remport = netport;
-
-   s = ioctl(netfd, NWIOSTCPCONF, &tcpconf);
-   if(s < 0) {
-	perror("httpget: NWIOSTCPCONF");
-	close(netfd);
-	return(-1);
-   }
-
-   s = ioctl(netfd, NWIOGTCPCONF, &tcpconf);
-   if(s < 0) {
-	perror("httpget: NWIOGTCPCONF");
-	close(netfd);
-	return(-1);
-   }
-
-   tcpcopt.nwtcl_flags = 0;
-
-   tries = 0;
-   do {
-	s = ioctl(netfd, NWIOTCPCONN, &tcpcopt);
-	if(s == -1 && errno == EAGAIN) {
-		if(tries++ >= 10)
-			break;
-		sleep(10);
-	} else
-		break;
-   } while(1);
-
-   if(s < 0) {
-	perror("httpget: NWIOTCPCONN");
-	close(netfd);
-	return(-1);
-   }
-
-   return(netfd);
-}
Index: trunk/minix/commands/urlget/net.h
===================================================================
--- trunk/minix/commands/urlget/net.h	(revision 9)
+++ 	(revision )
@@ -1,4 +1,0 @@
-/* net.h Copyright 2000 by Michael Temari All Rights Reserved */
-/* 04/05/2000 Michael Temari <Michael@TemWare.Com> */
-
-_PROTOTYPE(int connect, (char *host, int port));
Index: trunk/minix/commands/urlget/urlget.c
===================================================================
--- trunk/minix/commands/urlget/urlget.c	(revision 9)
+++ 	(revision )
@@ -1,629 +1,0 @@
-/* urlget.c Copyright 2000 by Michael Temari All Rights Reserved */
-/* 04/05/2000 Michael Temari <Michael@TemWare.Com> */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-#include <time.h>
-
-#include "net.h"
-
-_PROTOTYPE(char *unesc, (char *s));
-_PROTOTYPE(void encode64, (char **pp, char *s));
-_PROTOTYPE(char *auth, (char *user, char *pass));
-_PROTOTYPE(int skipit, (char *buf, int len, int *skip));
-_PROTOTYPE(int httpget, (char *host, int port, char *user, char *pass, char *path, int headers, int discard, int post));
-_PROTOTYPE(void ftppasv, (char *reply));
-_PROTOTYPE(int ftpreply, (FILE *fpr));
-_PROTOTYPE(int ftpcmd, (FILE *fpw, FILE *fpr, char *cmd, char *arg));
-_PROTOTYPE(int ftpget, (char *host, int port, char *user, char *pass, char *path, int type));
-_PROTOTYPE(int tcpget, (char *host, int port, char *user, char *pass, char *path));
-_PROTOTYPE(int main, (int argc, char *argv[]));
-
-char ftpphost[15+1];
-unsigned int ftppport;
-
-#define	SCHEME_HTTP	1
-#define	SCHEME_FTP	2
-#define	SCHEME_TCP	3
-#define	SCHEME_NNTP	4
-
-char buffer[16000];
-
-#if 0
-_PROTOTYPE(int strncasecmp, (const char *s1, const char *s2, size_t len));
-int
-strncasecmp(s1, s2, len)
-const char *s1, *s2;
-size_t len;
-{
-        int c1, c2;
-        do {
-                if (len == 0)
-                        return 0;
-                len--;
-        } while (c1= toupper(*s1++), c2= toupper(*s2++), c1 == c2 && (c1 & c2))
-                ;
-        if (c1 & c2)
-                return c1 < c2 ? -1 : 1;
-        return c1 ? 1 : (c2 ? -1 : 0);
-}
-#endif
-
-char *unesc(s)
-char *s;
-{
-char *p;
-char *p2;
-unsigned char c;
-
-   p = s;
-   p2 = s;
-   while(*p) {
-   	if(*p != '%') {
-   		*p2++ = *p++;
-   		continue;
-   	}
-   	p++;
-   	if(*p == '%') {
-   		*p2++ = *p++;
-   		continue;
-   	}
-   	if(*p >= '0' && *p <= '9') c = *p++ - '0'; else
-   	if(*p >= 'a' && *p <= 'f') c = *p++ - 'a' + 10; else
-   	if(*p >= 'A' && *p <= 'F') c = *p++ - 'A' + 10; else
-   		break;
-   	if(*p >= '0' && *p <= '9') c = c << 4 | (*p++ - '0'); else
-   	if(*p >= 'a' && *p <= 'f') c = c << 4 | (*p++ - 'a') + 10; else
-   	if(*p >= 'A' && *p <= 'F') c = c << 4 | (*p++ - 'A') + 10; else
-   		break;
-   	*p2++ = c;
-   }
-   *p2 = '\0';
-   return(s);
-}
-
-void encode64(pp, s)
-char **pp;
-char *s;
-{
-char *p;
-char c[3];
-int i;
-int len;
-static char e64[64] = {
-	'A','B','C','D','E','F','G','H','I','J','K','L','M',
-	'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
-	'a','b','c','d','e','f','g','h','i','j','k','l','m',
-	'n','o','p','q','r','s','t','u','v','w','x','y','z',
-	'0','1','2','3','4','5','6','7','8','9','+','/' };
-
-   p = *pp;
-   len = strlen(s);
-   for(i=0; i < len; i += 3) {
-   	c[0] = *s++;
-   	c[1] = *s++;
-   	c[2] = *s++;
-   	*p++ = e64[  c[0] >> 2];
-   	*p++ = e64[((c[0] << 4) & 0x30) | ((c[1] >> 4) & 0x0f)];
-   	*p++ = e64[((c[1] << 2) & 0x3c) | ((c[2] >> 6) & 0x03)];
-   	*p++ = e64[  c[2]       & 0x3f];
-   }
-   if(i == len+1)
-   	p[-1] = '=';
-   else
-   if(i == len+2) {
-   	p[-1] = '=';
-   	p[-2] = '=';
-   }
-   *p = '\0';
-   *pp = p;
-   return;
-}
-
-char *auth(user, pass)
-char *user;
-char *pass;
-{
-static char a[128];
-char up[128];
-char *p;
-
-   strcpy(a, "BASIC ");
-   p = a + 6;
-   sprintf(up, "%s:%s", user, pass);
-   encode64(&p, up);
-
-   return(a);
-}
-
-int skipit(buf, len, skip)
-char *buf;
-int len;
-int *skip;
-{
-static int lf = 0;
-static int crlf = 0;
-char *p;
-
-   p = buf;
-
-   while(--len >= 0) {
-   	if((crlf == 0 || crlf == 2) && *p == '\r')
-   		crlf++;
-   	else
-   	if((crlf == 1 || crlf == 3) && *p == '\n')
-   		crlf++;
-   	else
-   		crlf = 0;
-   	if(*p == '\n')
-   		lf++;
-   	else
-   		lf = 0;
-   	if(crlf == 4 || lf == 2) {
-   		*skip = 0;
-   		return(len);
-   	}
-   	p++;
-   }
-
-   return(0);
-}
-
-int httpget(host, port, user, pass, path, headers, discard, post)
-char *host;
-int port;
-char *user;
-char *pass;
-char *path;
-int headers;
-int discard;
-int post;
-{
-int fd;
-int skip;
-int s;
-int s2;
-char *a;
-char *qs;
-int len;
-
-   if(port == 0)
-   	port = 80;
-
-   fd = connect(host, port);
-   if(fd < 0) {
-   	fprintf(stderr, "httpget: Could not connect to %s:%d\n", host, port);
-   	return(-1);
-   }
-
-   if(post) {
-   	qs = strrchr(path, '?');
-   	if(qs != (char *)NULL) {
-   		*qs++ = '\0';
-   		len = strlen(qs);
-   	} else
-   		len = 0;
-   }
-
-   if(post && len > 0)
-	write(fd, "POST ", 5);
-   else
-	write(fd, "GET ", 4);
-   write(fd, path, strlen(path));
-   write(fd, " HTTP/1.0\r\n", 11);
-   write(fd, "User-Agent: urlget\r\n", 20);
-   write(fd, "Connection: Close\r\n", 19);
-   if(*user) {
-   	write(fd, "Authorization: ", 15);
-   	a = auth(user, pass);
-   	write(fd, a, strlen(a));
-   	write(fd, "\r\n", 2);
-   }
-   if(post && len > 0) {
-   	sprintf(buffer, "Content-Length: %u\r\n", len);
-   	write(fd, buffer, strlen(buffer));
-   }
-   write(fd, "Host: ", 6);
-   write(fd, host, strlen(host));
-   write(fd, "\r\n", 2);
-   write(fd, "\r\n", 2);
-   if(post && len > 0)
-   	write(fd, qs, len);
-
-   skip = 1;
-   while((s = read(fd, buffer, sizeof(buffer)-1)) > 0) {
-	buffer[s] = '\0';
-   	if(skip) {
-   		static int firstline = 1;
-		if(firstline) {
-			static char linebuf[1000];
-			int l = 0;
-			int c, v1, v2, e;
-			if(s >= sizeof(linebuf)-l)
-				c = sizeof(linebuf)-1-l;
-			else	c = s;
-			memcpy(linebuf+l, buffer, c);
-			linebuf[l+c] = '\0';
-			if(strchr(buffer, '\n') || strchr(buffer, '\r'))
-				firstline = 0;
-			if(sscanf(linebuf, "HTTP/%d.%d %d ", &v1, &v2, &e) == 3
-				&& e != 200) {
-				fprintf(stderr, "HTTP error %d\n", e);
-				return -1;
-			}
-		}
-
-   		s2 = skipit(buffer, s, &skip);
-   		if(headers)
-   			write(1, buffer, s - s2);
-   	} else
-   		s2 = s;
-   	if(s2 && !discard)
-		if(write(1, &buffer[s - s2], s2) != s2) {
-			perror("write");
-			return(-1);
-		}
-   }
-   if(s < 0) {
-   	fprintf(stderr, "httpget: Read error\n");
-	return(-1);
-   }
-
-   close(fd);
-
-   return(0);
-}
-
-void ftppasv(reply)
-char *reply;
-{
-char *p;
-unsigned char n[6];
-int i;
-
-   ftppport = 0;
-
-   p = reply;
-   while(*p && *p != '(') p++;
-   if(!*p) return;
-   p++;
-   i = 0;
-   while(1) {
-   	n[i++] = atoi(p);
-   	if(i == 6) break;
-   	p = strchr(p, ',');
-   	if(p == (char *)NULL) return;
-   	p++;
-   }
-   sprintf(ftpphost, "%d.%d.%d.%d", n[0], n[1], n[2], n[3]);
-   ftppport = n[4] * 256 + n[5];
-   return;
-}
-
-int ftpreply(fpr)
-FILE *fpr;
-{
-static char reply[256];
-int s;
-char code[4];
-int ft;
-
-   do {
-   	ft = 1;
-   	do {
-   		if(fgets(reply, sizeof(reply), fpr) == (char *)NULL)
-   			return(-1);
-   		if(ft) {
-   			ft = 0;
-   			strncpy(code, reply, 3);
-   			code[3] = '\0';
-   		}
-   	} while(strncmp(reply, code, 3) || reply[3] == '-');
-   	s = atoi(code);
-   } while(s < 200 && s != 125 && s != 150);
-   if(s == 227) ftppasv(reply);
-   return(s);
-}
-
-int ftpcmd(fpw, fpr, cmd, arg)
-FILE *fpw;
-FILE *fpr;
-char *cmd;
-char *arg;
-{
-   fprintf(fpw, "%s%s%s\r\n", cmd, *arg ? " " : "", arg);
-   fflush(fpw);
-   return(ftpreply(fpr));
-}
-
-int ftpget(host, port, user, pass, path, type)
-char *host;
-int port;
-char *user;
-char *pass;
-char *path;
-int type;
-{
-int fd;
-int fd2;
-FILE *fpr;
-FILE *fpw;
-int s;
-int s2;
-char *p;
-char *p2;
-char typec[2];
-
-   if(port == 0)
-   	port = 21;
-
-   if(type == '\0')
-   	type = 'i';
-
-   fd = connect(host, port);
-   if(fd < 0) {
-   	fprintf(stderr, "ftpget: Could not connect to %s:%d\n", host, port);
-   	return(-1);
-   }
-   fpr = fdopen(fd, "r");
-   fpw = fdopen(fd, "w");
-
-   s = ftpreply(fpr);
-   if(s / 100 != 2) goto error;
-   s = ftpcmd(fpw, fpr, "USER", *user ? user : "ftp");
-   if(s / 100 == 3)
-   	s = ftpcmd(fpw, fpr, "PASS", *pass ? pass : "urlget@");
-
-   if(s / 100 != 2) goto error;
-
-   p = path;
-   if(*p == '/') p++;
-   while((p2 = strchr(p, '/')) != (char *)NULL) {
-   	*p2++ = '\0';
-   	s = ftpcmd(fpw, fpr, "CWD", unesc(p));
-   	p = p2;
-   }
-   sprintf(typec, "%c", type == 'd' ? 'A' : type);
-   s = ftpcmd(fpw, fpr, "TYPE", typec);
-   if(s / 100 != 2) goto error;
-   s = ftpcmd(fpw, fpr, "PASV", "");
-   if(s != 227) goto error;
-   fd2 = connect(ftpphost, ftppport);
-   if(fd2 < 0) goto error;
-   s = ftpcmd(fpw, fpr, type == 'd' ? "NLST" : "RETR", unesc(p));
-   if(s / 100 != 1) goto error;
-   while((s = read(fd2, buffer, sizeof(buffer))) > 0) {
-   	s2 = write(1, buffer, s);
-   	if(s2 != s) break;
-   }
-   if(s2 != s && s != 0) s = -1;
-   close(fd2);
-
-   s = ftpreply(fpr);
-   if(s / 100 == 2) s = 0;
-
-error:
-   (void) ftpcmd(fpw, fpr, "QUIT", "");
-
-   fclose(fpr);
-   fclose(fpw);
-   close(fd);
-
-   return(s == 0 ? 0 : -1);
-}
-
-int tcpget(host, port, user, pass, path)
-char *host;
-int port;
-char *user;
-char *pass;
-char *path;
-{
-int fd;
-int s;
-int s2;
-
-   if(port == 0) {
-   	fprintf(stderr, "tcpget: No port specified\n");
-   	return(-1);
-   }
-
-   fd = connect(host, port);
-   if(fd < 0) {
-   	fprintf(stderr, "httpget: Could not connect to %s:%d\n", host, port);
-   	return(-1);
-   }
-   if(*path == '\/')
-   	path++;
-
-   write(fd, path, strlen(path));
-   write(fd, "\n", 1);
-   while((s = read(fd, buffer, sizeof(buffer))) > 0) {
-   	s2 = write(1, buffer, s);
-   	if(s2 != s) break;
-   }
-   close(fd);
-   return(0);
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-char *prog;
-char *url;
-char scheme;
-char user[64];
-char pass[64];
-char host[64];
-int port;
-char *path;
-int type;
-char *ps;
-char *p;
-char *at;
-int s, c;
-int opt_h = 0;
-int opt_d = 0;
-int opt_p = 0;
-
-   prog = strrchr(*argv, '/');
-   if(prog == (char *)NULL)
-   	prog = *argv;
-   argv++;
-   argc--;
-
-   while(argc && argv[0][0] == '-') {
-   	char *opt = *argv++ + 1;
-   	argc--;
-
-	if (opt[0] == '-' && opt[1] == 0) break;
-
-   	while (*opt) switch (*opt++) {
-		case 'h':	opt_h = -1;	break;
-		case 'd':	opt_d = -1;	break;
-		case 'p':	opt_p = -1;	break;
-		default:	argc = 0;	break;
-	}
-   }
-
-   if(strcmp(prog, "ftpget") == 0) {
-   	if(argc < 2 || argc > 4) {
-   		fprintf(stderr, "Usage: %s host path [user [pass]]\n", prog);
-   		return(-1);
-   	}
-   	strncpy(host, *argv++, sizeof(host));
-   	port = 21;
-   	path = *argv++;
-   	if(argc) {
-   		strncpy(user, *argv++, sizeof(user));
-   		argc++;
-   	} else
-   		*user = '\0';
-   	if(argc) {
-   		strncpy(pass, *argv++, sizeof(pass));
-   		argc++;
-   	} else
-   		*pass = '\0';
-	s = ftpget(host, port, user, path, path, 'i');
-	return(s);
-   }
-   if(strcmp(prog, "httpget") == 0) {
-   	if(argc != 2) {
-   		fprintf(stderr, "Usage: %s [-h] [-d] [-p] host path\n", prog);
-   		return(-1);
-   	}
-   	strncpy(host, *argv++, sizeof(host));
-   	port = 80;
-   	path = *argv++;
-	s = httpget(host, port, user, path, path, opt_h, opt_d, opt_p);
-	return(s);
-   }
-
-   if(argc != 1) {
-   usage:
-   	fprintf(stderr, "Usage: %s [-h] [-p] url\n", prog);
-   	return(-1);
-   }
-
-   url = *argv++;
-   argc--;
-
-   if(strncasecmp(url, "http://", 7) == 0) {
-   	scheme = SCHEME_HTTP;
-   	ps = url + 7;
-   } else
-   if(strncasecmp(url, "ftp://", 6) == 0) {
-   	scheme = SCHEME_FTP;
-   	ps = url + 6;
-   } else 
-   if(strncasecmp(url, "tcp://", 6) == 0) {
-   	scheme = SCHEME_TCP;
-   	ps = url + 6;
-   } else {
-	fprintf(stderr, "%s: I do not handle this scheme\n", prog);
-	return(-1);
-   }
-
-   user[0] = '\0';
-   pass[0] = '\0';
-   host[0] = '\0';
-   port = 0;
-
-   p = ps;
-   while(*p && *p != '/') p++;
-   path = p;
-   c = *path;
-   *path = '\0';
-
-   at = strchr(ps, '@');
-   if(at != (char *)NULL) {
-   	*at = '\0';
-   	p = ps;
-   	while(*p && *p != ':') p++;
-   	if(*p)
-   		*p++ = '\0';
-	strcpy(user, ps);
-   	strcpy(pass, p);
-   	ps = at + 1;
-   }
-
-   *path = c;
-   p = ps;
-   while(*p && *p != '/' && *p != ':') p++;
-   strncpy(host, ps, p - ps);
-   host[p - ps] = '\0';
-   if(*p == ':') {
-   	p++;
-   	ps = p;
-   	while(*p && *p != '/')
-   		port = port * 10 + (*p++ - '0');
-   }
-   if(*p == '/')
-	path = p;
-   else
-   	path = "/";
-   if(scheme == SCHEME_FTP) {
-   	p = path;
-   	while(*p && *p != ';') p++;
-   	if(*p) {
-   		*p++ = '\0';
-   		if(strncasecmp(p, "type=", 5) == 0) {
-   			p += 5;
-   			type = tolower(*p);
-   		}
-   	}
-   }
-
-#if 0
-   fprintf(stderr, "Host: %s\n", host);
-   fprintf(stderr, "Port: %d\n", port);
-   fprintf(stderr, "User: %s\n", user);
-   fprintf(stderr, "Pass: %s\n", pass);
-   fprintf(stderr, "Path: %s\n", path);
-   fprintf(stderr, "Type: %c\n", type);
-#endif
-
-   switch(scheme) {
-   	case SCHEME_HTTP:
-		s = httpget(host, port, user, pass, path, opt_h, opt_d, opt_p);
-		break;
-	case SCHEME_FTP:
-		s = ftpget(host, port, user, pass, path, type);
-		break;
-	case SCHEME_TCP:
-		s = tcpget(host, port, user, pass, path);
-		break;
-   }
-
-   return(s);
-}
Index: trunk/minix/commands/yap/Makefile
===================================================================
--- trunk/minix/commands/yap/Makefile	(revision 9)
+++ 	(revision )
@@ -1,210 +1,0 @@
-# $Header: /cvsup/minix/src/commands/yap/Makefile,v 1.2 2005/09/07 08:43:25 beng Exp $
-
-# CFLAGS : options for the C-compiler
-CFLAGS = -O -D_MINIX -D_POSIX_SOURCE -wa
-CC=exec cc
-
-# LDFLAGS : flags for the loader
-#	-i for a PDP-11 with separate I/D (not necessary)
-LDFLAGS = -i
-
-# BINDIR : where the binary will go when you type "make install"
-BINDIR = /usr/bin
-
-# LIBRARIES : -ltermcap or -ltermlib,
-#	-lPW on USG systems (System III, System V),
-# 	-ljobs on Berkeley Unix system (4.1, 2.8?, 2.9)
-LIBRARIES =
-
-HFILES= assert.h\
-	commands.h\
-	display.h\
-	getcomm.h\
-	getline.h\
-	help.h\
-	in_all.h\
-	keys.h\
-	machine.h\
-	main.h\
-	options.h\
-	output.h\
-	pattern.h\
-	process.h\
-	prompt.h\
-	term.h
-
-CFILES=	assert.c\
-	commands.c\
-	display.c\
-	getcomm.c\
-	getline.c\
-	help.c\
-	keys.c\
-	machine.c\
-	main.c\
-	options.c\
-	output.c\
-	pattern.c\
-	process.c\
-	prompt.c\
-	term.c
-
-OFILES=	assert.o\
-	commands.o\
-	display.o\
-	getcomm.o\
-	getline.o\
-	help.o\
-	keys.o\
-	machine.o\
-	main.o\
-	options.o\
-	output.o\
-	pattern.o\
-	process.o\
-	prompt.o\
-	term.o
-
-all:		yap
-
-yap:		$(OFILES)
-		$(CC) $(LDFLAGS) -o yap $(OFILES) $(LIBRARIES)
-		install -S 16kw yap
-
-install:	$(BINDIR)/yap $(BINDIR)/more
-
-$(BINDIR)/yap:	yap
-		install -cs -o bin yap $@
-
-$(BINDIR)/more:	$(BINDIR)/yap
-		install -l $? $@
-
-clean:
-		rm -f yap $(OFILES) a.out core *.bak
-
-pr:
-		pr Makefile $(HFILES) $(CFILES)
-
-lint:
-		lint $(DEFINES) $(CFILES)
-
-#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO
-assert.o:	assert.h
-assert.o:	in_all.h
-assert.o:	output.h
-assert.o:	term.h
-commands.o:	assert.h
-commands.o:	commands.h
-commands.o:	display.h
-commands.o:	getcomm.h
-commands.o:	getline.h
-commands.o:	help.h
-commands.o:	in_all.h
-commands.o:	keys.h
-commands.o:	machine.h
-commands.o:	main.h
-commands.o:	options.h
-commands.o:	output.h
-commands.o:	pattern.h
-commands.o:	process.h
-commands.o:	prompt.h
-commands.o:	term.h
-display.o:	assert.h
-display.o:	display.h
-display.o:	getline.h
-display.o:	in_all.h
-display.o:	machine.h
-display.o:	main.h
-display.o:	options.h
-display.o:	output.h
-display.o:	process.h
-display.o:	term.h
-getcomm.o:	assert.h
-getcomm.o:	commands.h
-getcomm.o:	display.h
-getcomm.o:	getcomm.h
-getcomm.o:	getline.h
-getcomm.o:	in_all.h
-getcomm.o:	keys.h
-getcomm.o:	machine.h
-getcomm.o:	main.h
-getcomm.o:	output.h
-getcomm.o:	process.h
-getcomm.o:	prompt.h
-getcomm.o:	term.h
-getline.o:	assert.h
-getline.o:	display.h
-getline.o:	getline.h
-getline.o:	in_all.h
-getline.o:	main.h
-getline.o:	options.h
-getline.o:	output.h
-getline.o:	process.h
-getline.o:	term.h
-help.o:	commands.h
-help.o:	display.h
-help.o:	help.h
-help.o:	in_all.h
-help.o:	keys.h
-help.o:	machine.h
-help.o:	main.h
-help.o:	options.h
-help.o:	output.h
-help.o:	prompt.h
-help.o:	term.h
-keys.o:	assert.h
-keys.o:	commands.h
-keys.o:	in_all.h
-keys.o:	keys.h
-keys.o:	machine.h
-keys.o:	prompt.h
-machine.o:	assert.h
-machine.o:	getline.h
-machine.o:	in_all.h
-machine.o:	machine.h
-main.o:	commands.h
-main.o:	display.h
-main.o:	in_all.h
-main.o:	main.h
-main.o:	options.h
-main.o:	output.h
-main.o:	process.h
-main.o:	prompt.h
-main.o:	term.h
-options.o:	display.h
-options.o:	in_all.h
-options.o:	options.h
-options.o:	output.h
-output.o:	in_all.h
-output.o:	main.h
-output.o:	output.h
-pattern.o:	in_all.h
-pattern.o:	pattern.h
-process.o:	commands.h
-process.o:	display.h
-process.o:	getline.h
-process.o:	in_all.h
-process.o:	main.h
-process.o:	options.h
-process.o:	output.h
-process.o:	process.h
-process.o:	prompt.h
-prompt.o:	display.h
-prompt.o:	getcomm.h
-prompt.o:	getline.h
-prompt.o:	in_all.h
-prompt.o:	main.h
-prompt.o:	options.h
-prompt.o:	output.h
-prompt.o:	process.h
-prompt.o:	prompt.h
-prompt.o:	term.h
-term.o:	display.h
-term.o:	getline.h
-term.o:	in_all.h
-term.o:	keys.h
-term.o:	machine.h
-term.o:	main.h
-term.o:	options.h
-term.o:	output.h
-term.o:	term.h
Index: trunk/minix/commands/yap/NOTICE
===================================================================
--- trunk/minix/commands/yap/NOTICE	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-$Header: /cvsup/minix/src/commands/yap/NOTICE,v 1.1.1.1 2005/04/21 14:55:38 beng Exp $
-
-The software and documentation contained within this
-directory is copyright (c) Ceriel J.H. Jacobs, 1988.
-
-Permission is granted to reproduce and distribute
-this software as long as no fee is charged and
-this notice is included.
-
-Other rights are reserved except as explicitly
-granted by written permission from the author.
-
-		Ceriel J.H. Jacobs
-		Dept. of Maths and Computer Science
-		Vrije Universiteit
-		De Boelelaan 1081
-		1081 HV	 Amsterdam
-		The Netherlands
-    email :
-	ceriel@cs.vu.nl
-
Index: trunk/minix/commands/yap/READ_ME
===================================================================
--- trunk/minix/commands/yap/READ_ME	(revision 9)
+++ 	(revision )
@@ -1,41 +1,0 @@
-$Header: /cvsup/minix/src/commands/yap/READ_ME,v 1.1.1.1 2005/04/21 14:55:38 beng Exp $
-
-This directory contains the sources of YAP, Yet Another Pager.
-It can do most of the things more(1) can, and much much more.
-
-Yap has been tested on the following systems:
-
-- DEC PDP 11/44 running V7
-- DEC PDP 11/60 running V7
-- DEC VAX 11/750 running 4.1BSD
-- IBM PC/XT running PC/IX
-- NCR Minitower running a System V
-- Several 68k systems
-- SUN-3 and SUN-4
-
-On other systems, you might have some problems getting yap to run, but then
-again, you might not. You can always ask me for help, and maybe even get it.
-If you make any changes, please
- - tell me about them
- - mark them clearly, preferably through conditional compilation.
-
-What you need to run yap:
-
-- you need termlib/termcap.
-  It probably is'nt too hard to adapt yap to terminfo.
-  It might even work unchanged, but I don't know about that. We don't have
-  terminfo or the system V curses.
-  If you adapt yap to terminfo, I would sure like to get the changes you made,
-  so please send them to me (email address at the bottom of this note);
-- you also need regex(III) (Either Berkeley style or USG will do).
-  If you do not have it, you should define NOREGEX, which gives you
-  simpleminded searches without meta-characters.
-
-How to install yap:
-
-- edit Makefile (easy)
-- edit in_all.h (easy)
-- type "make install"
-
-			Ceriel Jacobs, Vrije Universiteit Amsterdam
-			ceriel@cs.vu.nl
Index: trunk/minix/commands/yap/assert.c
===================================================================
--- trunk/minix/commands/yap/assert.c	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/assert.c,v 1.1.1.1 2005/04/21 14:55:38 beng Exp $";
-# endif
-
-# define _ASSERT_
-
-# include "in_all.h"
-# include "assert.h"
-# if DO_ASSERT
-# include "output.h"
-# include "term.h"
-
-/*
- * Assertion fails. Tell me about it.
- */
-
-VOID
-badassertion(ass,f,l) char *ass, *f; {
-
-	clrbline();
-	putline("Assertion \"");
-	putline(ass);
-	putline("\" failed ");
-	putline(f);
-	putline(", line ");
-	prnum((long) l);
-	putline(".\r\n");
-	flush();
-	resettty();
-	abort();
-}
-# endif
Index: trunk/minix/commands/yap/assert.h
===================================================================
--- trunk/minix/commands/yap/assert.h	(revision 9)
+++ 	(revision )
@@ -1,28 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/assert.h,v 1.1.1.1 2005/04/21 14:55:38 beng Exp $ */
-
-/* Assertion macro */
-
-# ifndef _ASSERT_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-#if DO_ASSERT
-#define assert(x) if(!(x)) badassertion("x",__FILE__,__LINE__)
-VOID badassertion();
-/*
- * void badassertion(ass,fn,lineno)
- * char *ass,		The assertion in string form,
- *	*fn;		The filename in which the assertion failed,
- * int lineno;		The line number of the assertion.
- *
- * Reports the assertion on standard output and then aborts with a core dump.
- */
-#else
-#define assert(x)	/* nothing */
-#endif
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/build
===================================================================
--- trunk/minix/commands/yap/build	(revision 9)
+++ 	(revision )
@@ -1,5 +1,0 @@
-#!/bin/sh
-set -e
-make clean
-make
-make install
Index: trunk/minix/commands/yap/commands.c
===================================================================
--- trunk/minix/commands/yap/commands.c	(revision 9)
+++ 	(revision )
@@ -1,706 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/commands.c,v 1.1.1.1 2005/04/21 14:55:38 beng Exp $";
-# endif
-
-# define _COMMANDS_
-
-# include "in_all.h"
-# include "commands.h"
-# include "output.h"
-# include "process.h"
-# include "help.h"
-# include "term.h"
-# include "prompt.h"
-# include "getline.h"
-# include "getcomm.h"
-# include "pattern.h"
-# include "display.h"
-# include "options.h"
-# include "machine.h"
-# include "keys.h"
-# include "main.h"
-# include "assert.h"
-# if USG_OPEN
-# include <fcntl.h>
-# include <errno.h>
-extern int errno;
-# endif
-# if BSD4_2_OPEN
-# include <sys/file.h>
-# include <errno.h>
-extern int errno;
-# endif
-# if POSIX_OPEN
-# include <sys/types.h>
-# include <fcntl.h>
-# include <errno.h>
-# endif
-
-char	*strcpy(), *strcat();
-
-static long lastcount;		/* Save last count for '.' command */
-static int lastcomm;		/* Save last command for '.' command */
-
-/*ARGSUSED*/
-STATIC int
-do_nocomm(cnt) long cnt; {	/* Do nothing */
-}
-
-/*ARGSUSED*/
-int
-do_chkm(cnt) long cnt; {	/* Change key map */
-	register struct keymap *p;
-
-	if (!(p = othermap)) {
-		error("No other keymap");
-		return;
-	}
-	othermap = currmap;
-	currmap = p;
-}
-
-static int searchdir;		/* Direction of last search */
-
-/*
- * Perform searches
- */
-
-STATIC VOID
-do_search(str,cnt,dir) char *str; long cnt; int dir; {
-	register char *p;
-	register long lineno;
-
-	if (str) {
-		/*
-		 * We have to get a pattern, which we have to prompt for
-		 * with the string "str".
-		 */
-		if ((p = readline(str)) == 0) {
-			/*
-			 * User cancelled command
-			 */
-			return;
-		}
-		if ((p = re_comp(p))) {
-			/*
-			 * There was an error in the pattern
-			 */
-			error(p);
-			return;
-		}
-		searchdir = dir;
-	}
-	if (dir < 0) lineno = scr_info.firstline;
-	else lineno = scr_info.lastline;
-	for (;;) {
-		p = 0;
-		if ((lineno += dir) > 0) p = getline(lineno, 0);
-		if (interrupt) return;
-		if (!p) {	/* End of file reached */
-			error("pattern not found");
-			return;
-		}
-		if (re_exec(p) && --cnt <= 0) {
-			/*
-			 * We found the pattern, and we found it often enough.
-			 * Pity that we still don't know where the match is.
-			 * We only know the linenumber. So, we just hope the
-			 * following will at least bring it on the screen ...
-			 */
-			(VOID) display(lineno,0,pagesize,0);
-			(VOID) scrollb(2,0);
-			redraw(0);
-			return;
-		}
-	}
-	/* NOTREACHED */
-}
-
-STATIC int
-do_fsearch(cnt) long cnt; {	/* Forward search */
-
-	do_search("/", cnt, 1);
-}
-
-STATIC int
-do_bsearch(cnt) long cnt; {	/* Backward search */
-
-	do_search("?", cnt, -1);
-}
-
-/*
- * Repeat last search in direction "dir"
- */
-
-STATIC int
-n_or_rn_search(cnt,dir) long cnt; int dir; {
-	register char *p;
-
-	if (dir == 1) {
-		p = "/\r";
-	}
-	else if (dir == -1) {
-		p = "?\r";
-	}
-	else {
-		error("No previous pattern");
-		return;
-	}
-	if (!stupid) clrbline();
-	putline(p);
-	flush();
-	do_search((char *) 0, cnt, dir);
-}
-
-STATIC int
-do_nsearch(cnt) long cnt; {	/* Repeat search in same direction */
-	
-	n_or_rn_search(cnt,searchdir);
-}
-
-STATIC int
-do_rnsearch(cnt) long cnt; {	/* Repeat search in opposite direction */
-
-	n_or_rn_search(cnt, -searchdir);
-}
-
-STATIC int shell(esc_ch, cnt) long cnt;
-{
-	register char *p;
-	static char buf[2];
-
-	buf[0] = esc_ch;
-	if (p = readline(buf)) {
-		shellescape(p, esc_ch);
-		if (cnt >= 0 && !hardcopy) {
-			p = startcomm;
-			startcomm = 0;
-			ret_to_continue();
-			putline(TI);
-			if (!p) {
-				/*
-				 * Avoid double redraw.
-				 * After a "startcomm", a redraw will
-				 * take place anyway.
-				 */
-				redraw(1);
-			}
-		}
-	}
-}
-
-STATIC int
-do_shell(cnt) long cnt; {	/* Execute a shell escape */
-	shell('!', cnt);
-}
-
-STATIC int
-do_pipe(cnt) long cnt; {	/* Execute a shell escape */
-	shell('|', cnt);
-}
-
-/*ARGSUSED*/
-STATIC int
-do_writefile(cnt) long cnt; {	/* Write input to a file */
-	register char *p;
-	int fd;
-
-	if ((p = readline("Filename: ")) == 0 || !*p) {
-		/*
-		 * No file name given
-		 */
-		return;
-	}
-# if USG_OPEN || BSD4_2_OPEN || POSIX_OPEN
-	if ((fd = open(p,O_CREAT|O_EXCL|O_WRONLY,0644)) < 0) {
-		if (errno == EEXIST) {
-			error("File exists");
-			return;
-		}
-		error("Could not open file");
-		return;
-	}
-# else
-	if (!access(p,0)) {
-		error("File exists");
-		return;
-	}
-	if ((fd = creat(p,0644)) < 0) {
-		error("Could not open file");
-		return;
-	}
-# endif
-	wrt_fd(fd);
-	(VOID) close(fd);
-}
-
-VOID
-wrt_fd(fd)
-{
-	register long l = 1;
-	register char *p = getline(l,0), *pbuf;
-	char buf[1024];
-
-	while (p) {
-		pbuf = buf;
-		while (p && pbuf < &buf[1024]) {
-			if (!*p) {
-				*pbuf++ = '\n';
-				p = getline(++l,0);
-			}
-			else *pbuf++ = *p++ & 0177;
-		}
-		if (write(fd, buf, pbuf - buf) < 0) {
-			error("Write failed");
-			break;
-		}
-	}
-}
-
-STATIC int
-do_absolute(cnt) long cnt; {	/* Go to linenumber "cnt" */
-
-	if (!getline(cnt,0)) {	/* Not there or interrupt */
-		if (!interrupt) {
-			/*
-			 * User did'nt give an interrupt, so the line number
-			 * was too high. Go to the last line.
-			 */
-			do_lline(cnt);
-		}
-		return;
-	}
-	(VOID) display(cnt,0,pagesize,1);
-}
-
-/*ARGSUSED*/
-STATIC int
-do_visit(cnt) long cnt; {	/* Visit a file */
-	register char *p;
-	static char fn[128];	/* Keep file name */
-
-	if ((p = readline("Filename: ")) == 0) {
-		return;
-	}
-	if (*p) {
-		(VOID) strcpy(fn,p);
-		visitfile(fn);
-	}
-	else {
-		/*
-		 * User typed a return. Visit the current file
-		 */
-		if (!(p = filenames[filecount])) {
-			error("No current file");
-			return;
-		}
-		visitfile(p);
-	}
-	(VOID) display(1L, 0, pagesize, 1);
-}
-
-/*ARGSUSED*/
-STATIC int
-do_error(cnt) long cnt; {	/* Called when user types wrong key sequence */
-
-	error(currmap->k_help);
-}
-
-/*
- * Interface routine for displaying previous screen,
- * depending on cflag.
- */
-
-STATIC int
-prev_screen(sz,really) int sz, really; {
-	register int retval;
-
-	retval = scrollb(sz - 1, really && cflag);
-	if (really && !cflag) {
-		/*
-		 * The previous call did not display anything, but at least we
-		 * know where to start
-		 */
-		return display(scr_info.firstline, scr_info.nf, sz, 1);
-	}
-	return retval;
-}
-
-/*
- * Interface routine for displaying the next screen,
- * dependent on cflag.
- */
-
-STATIC int
-next_screen(sz,really) int sz, really; {
-
-	register int t;
-	register struct scr_info *p = &scr_info;
-
-	if (cflag) {
-		return scrollf(sz-1,really);
-	}
-	t = p->tail->cnt - 1;
-	if (p->lastline == p->firstline) {
-		t += p->nf;
-	}
-	return display(p->lastline, t, sz, really);
-}
-
-/*ARGSUSED*/
-STATIC int
-do_redraw(cnt) long cnt; {
-
-	redraw(1);
-}
-
-STATIC int
-page_size(cnt) unsigned cnt; {
-
-	if (cnt) {
-		if (cnt > maxpagesize) return maxpagesize;
-		if (cnt < MINPAGESIZE) return MINPAGESIZE;
-		return (int) cnt;
-	}
-	return pagesize;
-}
-
-STATIC int
-do_forward(cnt) long cnt; {	/* Display next page */
-	register int i;
-
-	i = page_size((unsigned) cnt);
-	if (status & EOFILE) {
-		/*
-		 * May seem strange, but actually a visit to the next file
-		 * has already been done here
-		 */
-		(VOID) display(1L,0,i,1);
-		return;
-	}
-	(VOID) next_screen(i,1);
-}
-
-STATIC int
-do_backward(cnt) long cnt; {
-	register int i, temp;
-
-	i = page_size((unsigned) cnt);
-	if (!(status & START)) {
-		(VOID) prev_screen(i,1);
-		return;
-	}
-	if (stdf < 0) {
-		(VOID) display(1L,0,i,1);
-		return;
-	}
-	/*
-	 * The next part is a bit clumsy.
-	 * We want to display the last page of the previous file (for which
-	 * a visit has already been done), but the pagesize may temporarily
-	 * be different because the command had a count
-	 */
-	temp = pagesize;
-	pagesize = i;
-	do_lline(cnt);
-	pagesize = temp;
-}
-
-/*ARGSUSED*/
-STATIC int
-do_firstline(cnt) long cnt; {	/* Go to start of input */
-
-	do_absolute(1L);
-}
-
-STATIC int
-do_lline(cnt) long cnt; {	/* Go to end of input */
-	register int i = 0;
-	register int j = pagesize - 1;
-
-	if ((cnt = to_lastline()) < 0) {
-		/*
-		 * Interrupted by the user
-		 */
-		return;
-	}
-	/*
-	 * Display the page such that only the last line of the page is
-	 * a "~", independant of the pagesize
-	 */
-	while (!(display(cnt,i,j,0) & EOFILE)) {
-		/*
-		 * The last line could of course be very long ...
-		 */
-		i+= j;
-	}
-	(VOID) scrollb(j - scr_info.tail->cnt, 0);
-	redraw(0);
-}
-
-STATIC int
-do_lf(cnt) long cnt; {		/* Display next line, or go to line */
-
-	if (cnt) {		/* Go to line */
-		do_absolute(cnt);
-		return;
-	}
-	(VOID) scrollf(1,1);
-}
-
-STATIC int
-do_upline(cnt) long cnt; {	/* Display previous line, or go to line */
-
-	if (cnt) {		/* Go to line */
-		do_absolute(cnt);
-		return;
-	}
-	(VOID) scrollb(1,1);
-}
-
-STATIC int
-do_skiplines(cnt) long cnt; {	/* Skip lines forwards */
-
-	/* Should be interruptable ... */
-	(VOID) scrollf((int) (cnt + maxpagesize - 1), 0);
-	redraw(0);
-}
-
-STATIC int
-do_bskiplines(cnt) long cnt; {	/* Skip lines backwards */
-
-	/* Should be interruptable ... */
-	(VOID) scrollb((int) (cnt + pagesize - 1), 0);
-	redraw(0);
-}
-
-STATIC int
-do_fscreens(cnt) long cnt; {	/* Skip screens forwards */
-
-	do {
-		if ((next_screen(pagesize,0) & EOFILE) || interrupt) break;
-	} while (--cnt >= 0);
-	redraw(0);
-}
-
-STATIC int
-do_bscreens(cnt) long cnt; {	/* Skip screens backwards */
-
-	do {
-		if ((prev_screen(pagesize,0) & START) || interrupt) break;
-	} while (--cnt >= 0);
-	redraw(0);
-}
-
-STATIC int
-scro_size(cnt) unsigned cnt; {
-
-	if (cnt >= maxpagesize) return maxpagesize;
-	if (cnt) return (int) cnt;
-	return scrollsize;
-}
-
-STATIC int
-do_f_scroll(cnt) long cnt; {	/* Scroll forwards */
-
-	(VOID) scrollf(scro_size((unsigned) cnt),1);
-}
-
-STATIC int
-do_b_scroll(cnt) long cnt; {	/* Scroll backwards */
-
-	(VOID) scrollb(scro_size((unsigned) cnt),1);
-}
-
-STATIC int
-do_previousfile(cnt) long cnt; {/* Visit previous file */
-
-	if (nextfile(- (int) cnt)) {
-		error("No (Nth) previous file");
-		return;
-	}
-	redraw(0);
-}
-
-STATIC int
-do_nextfile(cnt) long cnt; {	/* Visit next file */
-
-	if (nextfile((int) cnt)) {
-		error("No (Nth) next file");
-		return;
-	}
-	redraw(0);
-}
-
-STATIC int do_lcomm();
-
-/*
- * The next array is initialized, sorted on the first element of the structs,
- * so that we can perform binary search
- */
-struct commands commands[] = {
-{"",	    0,	    do_error,	    ""},
-{"",	    0,	    do_nocomm,	    ""},
-{"bf",	    STICKY|NEEDS_COUNT,
-		    do_previousfile,"Visit previous file"},
-{"bl",	    NEEDS_SCREEN|STICKY,
-		    do_upline,	    "Scroll one line up, or go to line"},
-{"bot",	    STICKY,
-		    do_lline,	    "Go to last line of the input"},
-{"bp",	    BACK|NEEDS_SCREEN|TOPREVFILE|STICKY,
-		    do_backward,    "display previous page"},
-{"bps",	    SCREENSIZE_ADAPT|BACK|NEEDS_SCREEN|TOPREVFILE|STICKY,
-		    do_backward,    "Display previous page, set pagesize"},
-{"bs",	    BACK|NEEDS_SCREEN|STICKY,
-		    do_b_scroll,    "Scroll backwards"},
-{"bse",	    0,	    do_bsearch,	    "Search backwards for pattern"},
-{"bsl",	    BACK|NEEDS_SCREEN|STICKY|NEEDS_COUNT,
-		    do_bskiplines,  "Skip lines backwards"},
-{"bsp",	    BACK|NEEDS_SCREEN|STICKY|NEEDS_COUNT,
-		    do_bscreens,    "Skip screens backwards"},
-{"bss",	    SCROLLSIZE_ADAPT|BACK|NEEDS_SCREEN|STICKY,
-		    do_b_scroll,    "Scroll backwards, set scrollsize"},
-{"chm",	    0,	    do_chkm,	    "Switch to other keymap"},
-{"exg",	    STICKY, exgmark,	    "Exchange current page with mark"},
-{"ff",	    STICKY|NEEDS_COUNT,
-		    do_nextfile,    "Visit next file"},
-{"fl",	    NEEDS_SCREEN|STICKY,
-		    do_lf,	    "Scroll one line down, or go to line"},
-{"fp",	    TONEXTFILE|AHEAD|STICKY,
-		    do_forward,	    "Display next page"},
-{"fps",	    SCREENSIZE_ADAPT|TONEXTFILE|AHEAD|STICKY,
-		    do_forward,	    "Display next page, set pagesize"},
-{"fs",	    AHEAD|NEEDS_SCREEN|STICKY,
-		    do_f_scroll,    "Scroll forwards"},
-{"fse",	    0,	    do_fsearch,	    "Search forwards for pattern"},
-{"fsl",	    AHEAD|NEEDS_SCREEN|STICKY|NEEDS_COUNT,
-		    do_skiplines,   "Skip lines forwards"},
-{"fsp",	    AHEAD|NEEDS_SCREEN|STICKY|NEEDS_COUNT,
-		    do_fscreens,    "Skip screens forwards"},
-{"fss",	    SCROLLSIZE_ADAPT|AHEAD|NEEDS_SCREEN|STICKY,
-		    do_f_scroll,    "Scroll forwards, set scrollsize"},
-{"hlp",	    0,	    do_help,	    "Give description of all commands"},
-{"mar",	    0,	    setmark,	    "Set a mark on the current page"},
-{"nse",	    STICKY, do_nsearch,	    "Repeat the last search"},
-{"nsr",	    STICKY, do_rnsearch, "Repeat last search in other direction"},
-{"pip",     ESC,    do_pipe,	    "pipe input into shell command"},
-{"qui",	    0,	    quit,	    "Exit from yap"},
-{"red",	    0,	    do_redraw,	    "Redraw screen"},
-{"rep",	    0,	    do_lcomm,	    "Repeat last command"},
-{"shl",	    ESC,    do_shell,	    "Execute a shell escape"},
-{"tom",	    0,	    tomark,	    "Go to mark"},
-{"top",	    STICKY, do_firstline,   "Go to the first line of the input"},
-{"vis",	    0,	    do_visit,	    "Visit a file"},
-{"wrf",	    0,	    do_writefile,   "Write input to a file"},
-};
-
-/*
- * Lookup string "s" in the commands array, and return index.
- * return 0 if not found.
- */
-
-int
-lookup(s) char *s; {
-	register struct commands *l, *u, *m;
-
-	l = &commands[2];
-	u = &commands[sizeof(commands) / sizeof(*u) - 1];
-	do {
-		/*
-		 * Perform binary search
-		 */
-		m = l + (u - l) / 2;
-		if (strcmp(s, m->c_cmd) > 0) l = m + 1;
-		else u = m;
-	} while (l < u);
-	if (!strcmp(s, u->c_cmd)) return u - commands;
-	return 0;
-}
-
-/*ARGSUSED*/
-STATIC int
-do_lcomm(cnt) long cnt; {	/* Repeat last command */
-
-	if (!lastcomm) {
-		error("No previous command");
-		return;
-	}
-	do_comm(lastcomm, lastcount);
-}
-
-/*
- * Execute a command, with optional count "count".
- */
-
-VOID
-do_comm(comm, count) register int comm; register long count; {
-
-	register struct commands *pcomm;
-	register int temp;
-	register int flags;
-
-	pcomm = &commands[comm];
-	flags = pcomm->c_flags;
-
-	/*
-	 * Check the command.
-	 * If the last line of the file is displayed and the command goes
-	 * forwards and does'nt have the ability to go to the next file, it
-	 * is an error.
-	 * If the first line of the file is displayed and the command goes
-	 * backwards and does'nt have the ability to go to the previous file,
-	 * it is an error.
-	 * Also check wether we need the next or previous file. If so, get it.
-	 */
-	if ((status & EOFILE) && (flags & AHEAD)) {
-		if (qflag || !(flags & TONEXTFILE)) return;
-		if (nextfile(1)) quit();
-	}
-	if ((status & START) && (flags & BACK)) {
-		if (qflag || !(flags & TOPREVFILE)) return;
-		if (nextfile(-1)) quit();
-	}
-	/*
-	 * Does the command stick around for LASTCOMM?
-	 */
-	if (flags & STICKY) {
-		lastcomm = comm;
-		lastcount = count;
-	}
-	if (!count) {
-		if (flags & NEEDS_COUNT) count = 1;
-	}
-	else {
-		/*
-		 * Does the command adapt the screensize?
-		 */
-		if (flags & SCREENSIZE_ADAPT) {
-			temp = maxpagesize;
-			if ((unsigned) count < temp) {
-				temp = count;
-			}
-			if (temp < MINPAGESIZE) {
-				temp = MINPAGESIZE;
-			}
-			count = 0;
-			pagesize = temp;
-		}
-		/*
-		 * Does the command adapt the scrollsize?
-		 */
-		if (flags & SCROLLSIZE_ADAPT) {
-			temp = maxpagesize - 1;
-			if ((unsigned) count < temp) {
-				temp = (int) count;
-			}
-			scrollsize = temp;
-			count = 0;
-		}
-	}
-	/*
-	 * Now execute the command.
-	 */
-	(*(pcomm->c_func))(count);
-}
Index: trunk/minix/commands/yap/commands.h
===================================================================
--- trunk/minix/commands/yap/commands.h	(revision 9)
+++ 	(revision )
@@ -1,64 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/commands.h,v 1.1.1.1 2005/04/21 14:55:39 beng Exp $ */
-
-# ifndef _COMMANDS_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-/* Flags, describing properties of commands */
-
-# define SCREENSIZE_ADAPT	01	/* Can change screen size */
-# define SCROLLSIZE_ADAPT	02	/* Can change scrollsize */
-# define TONEXTFILE		04	/* to next file */
-# define AHEAD			010	/* goes ahead in the file */
-# define BACK			020	/* goes back in the file */
-# define NEEDS_SCREEN		040	/* needs screen info */
-# define TOPREVFILE		0100	/* to previous file */
-# define STICKY			0200	/* remember for lastcomm */
-# define NEEDS_COUNT		0400	/* command needs a count */
-# define ESC			01000	/* shell or pipe escape */
-
-extern struct commands {
-    char *c_cmd;		/* Short mnemonic for a command */
-    int c_flags;		/* describes command properties */
-    int (*c_func)();		/* Function executing the command */
-    char *c_descr;		/* Short command description */
-} commands[];
-
-int	do_chkm();
-/*
- * int	do_chkm(cnt)
- * long cnt;			Ignored
- *
- * Switch to other keymap
- */
-
-VOID	do_comm();
-/*
- * void do_comm(command, count)
- * int command;			Index in the commands array
- * long count;			Some commands possibly take a count
- *
- * Checks and executes commands.
- */
-
-int	lookup();
-/*
- * int lookup(str)
- * char *str;
- *
- * Searches the string "str" in the command list.
- * It returns its index if it exists, otherwise it returns 0.
- */
-
-VOID	wrt_fd();
-/*
- * void wrt_fd(fd)
- * int fd;			File descriptor
- *
- * Write input to file descriptor fd
- */
-# undef PUBLIC
Index: trunk/minix/commands/yap/display.c
===================================================================
--- trunk/minix/commands/yap/display.c	(revision 9)
+++ 	(revision )
@@ -1,547 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/display.c,v 1.1.1.1 2005/04/21 14:55:39 beng Exp $";
-# endif
-
-# define _DISPLAY_
-
-# include "in_all.h"
-# include "display.h"
-# include "assert.h"
-# include "machine.h"
-# include "term.h"
-# include "output.h"
-# include "options.h"
-# include "process.h"
-# include "getline.h"
-# include "main.h"
-
-STATIC char * do_line();
-
-/*
- * Fill n lines of the screen, each with "str".
- */
-
-STATIC VOID
-fillscr(n,str) char *str; int n; {
-
-	while (n-- > 0) {
-		putline(str);
-	}
-}
-
-/*
- * Skip "n" screenlines of line "p", and return what's left of it.
- */
-
-STATIC char *
-skiplines(p,n) char *p; int n; {
-
-	while (n-- > 0) {
-		p = do_line(p,0);
-		scr_info.currentpos--;
-	}
-	return p;
-}
-
-/*
- * Redraw screen.
- * "n" = 1 if it is a real redraw, 0 if one page must be displayed.
- * It is also called when yap receives a stop signal.
- */
-
-VOID
-redraw(n) int n; {
-	register struct scr_info *p = &scr_info;
-	register int i;
-
-	i = pagesize;
-	if (n && p->currentpos) {
-		i = p->currentpos;
-	}
-	(VOID) display(p->firstline,p->nf,i,1);
-}
-
-/*
- * Compute return value for the routines "display" and "scrollf".
- * This return value indicates wether we are at the end of file
- * or at the start, or both.
- * "s" contains that part of the last line that was not displayed.
- */
-
-STATIC int
-compretval(s) char *s; {
-	register int i;
-	register struct scr_info *p = &scr_info;
-
-	i = 0;
-	if (!s || (!*s && !getline(p->lastline+1, 1))) {
-		i = EOFILE;
-	}
-	if (p->firstline == 1 && !p->nf) {
-		i |= START;
-	}
-	status = i;
-	return i;
-}
-
-/*
- * Display nlines, starting at line n, not displaying the first
- * nd screenlines of n.
- * If reallydispl = 0, the actual displaying is not performed,
- * only the computing associated with it is done.
- */
-
-int
-display(n,nd,nlines,reallydispl)
-  long n; int nd; register int nlines; int reallydispl; {
-
-	register struct scr_info *s = &scr_info;
-	register char *p;	/* pointer to line to be displayed */
-
-	if (startcomm)	{	/* No displaying on a command from the
-				 * yap command line. In this case, displaying
-				 * will be done after executing the command,
-				 * by a redraw.
-				 */
-		reallydispl = 0;
-	}
-	if (!n) {
-		n = 1L;
-		nd = 0;
-	}
-	if (reallydispl) {	/* move cursor to starting point */
-		if (stupid) {
-			putline(currentfile);
-			putline(", line ");
-			prnum(n);
-			nlines--;
-		}
-		if (cflag) {
-			putline("\r\n");
-		}
-		else {
-			home();
-			clrscreen();
-		}
-	}
-	/*
-	 * Now, do computations and display
-	 */
-	s->currentpos = 0;
-	s->nf = nd;
-	s->head = s->tail;
-	s->tail->cnt = 0;
-	s->tail->line = n;
-	p = skiplines(getline(n,1),nd);
-	while (nlines && p) {
-		/*
-		 * While there is room,
-		 * and there is something left to display ...
-		 */
-		(s->tail->cnt)++;
-		nlines--;
-		if (*(p = do_line(p,reallydispl)) == '\0') {
-			/*
-			 * File-line finished, get next one ...
-			 */
-			p = getline(++n,1);
-			if (nlines && p) {
-				s->tail = s->tail->next;
-				s->tail->cnt = 0;
-				s->tail->line = n;
-			}
-		}
-	}
-	if (!stupid) {
-		s->currentpos += nlines;
-		if (reallydispl) {
-			fillscr(nlines, "~\r\n");
-			fillscr(maxpagesize - s->currentpos, "\r\n");
-		}
-	}
-	return compretval(p);
-}
-
-/*
- * Scroll forwards n lines.
- */
-
-int
-scrollf(n,reallydispl) int n; int reallydispl; {
-
-	register struct scr_info *s = &scr_info;
-	register char *p;
-	register long ll;
-	register int i;
-
-	/*
-	 * First, find out how many screenlines of the last line were already
-	 * on the screen, and possibly above it.
-	 */
-
-	if (n <= 0 || (status & EOFILE)) return status;
-	if (startcomm) reallydispl = 0;
-	/*
-	 * Find out where to begin displaying
-	 */
-	i = s->tail->cnt;
-	if ((ll = s->lastline) == s->firstline) i += s->nf;
-	p = skiplines(getline(ll, 1), i);
-	/*
-	 * Now, place the cursor at the first free line
-	 */
-	if (reallydispl && !stupid) {
-		clrbline();
-		mgoto(s->currentpos);
-	}
-	/*
-	 * Now display lines, keeping track of which lines are on the screen.
-	 */
-	while (n-- > 0) {	/* There are still rows to be displayed */
-		if (!*p) {	/* End of line, get next one */
-			if (!(p = getline(++ll, 1))) {
-				/*
-				 * No lines left. At end of file
-				 */
-				break;
-			}
-			s->tail = s->tail->next;
-			s->tail->cnt = 0;
-			s->tail->line = ll;
-		}
-		if (s->currentpos >= maxpagesize) {
-			/*
-			 * No room, delete first screen-line
-			 */
-			s->currentpos--;
-			s->nf++;
-			if (--(s->head->cnt) == 0) {
-				/*
-				 * The first file-line on the screen is wiped
-				 * out completely; update administration
-				 * accordingly.
-				 */
-				s->nf = 0;
-				s->head = s->head->next;
-				assert(s->head->cnt > 0);
-			}
-		}
-		s->tail->cnt++;
-		p = do_line(p, reallydispl);
-	}
-	return compretval(p);
-}
-
-/*
- * Scroll back n lines
- */
-
-int
-scrollb(n, reallydispl) int n, reallydispl; {
-
-	register struct scr_info *s = &scr_info;
-	register char *p;	/* Holds string to be displayed */
-	register int i;
-	register int count;
-	register long ln;	/* a line number */
-	register int nodispl;
-	int cannotscroll;	/* stupid or no insert-line */
-
-	/*
-	 * First, find out where to start
-	 */
-	if ((count = n) <= 0 || (status & START)) return status;
-	if (startcomm) reallydispl = 0;
-	cannotscroll = stupid || (!*AL && !*SR);
-	ln = s->firstline;
-	nodispl = s->nf;
-	while (count) { /* While scrolling back ... */
-		if (i = nodispl) {
-			/*
-			 * There were screen-lines of s->firstline that were not
-			 * displayed.
-			 * We can use them now, but only "count" of them.
-			 */
-			if (i > count) i = count;
-			s->currentpos += i;
-			nodispl -= i;
-			count -= i;
-		}
-		else {	/* Get previous line */
-			if (ln == 1) break; /* isn't there ... */
-			p = getline(--ln, 1);
-			/*
-			 * Make it the first line of the screen and compute
-			 * how many screenlines it takes. These lines are not
-			 * displayed, but nodispl is set to this count, so
-			 * that it will be nonzero next time around
-			 */
-			nodispl = 0;
-			do {	/* Find out how many screenlines */
-				nodispl++;
-				p = skiplines(p, 1);
-			} while (*p);
-		}
-	}
-	n -= count;
-	if ((i = s->currentpos) > maxpagesize) i = maxpagesize;
-	if (reallydispl && hardcopy) i = n;
-	/*
-	 * Now that we know where to start, we can use "display" to do the
-	 * rest of the computing for us, and maybe even the displaying ...
-	 */
-	i = display(ln,
-		    nodispl,
-		    i,
-		    reallydispl && cannotscroll);
-	if (cannotscroll || !reallydispl) {
-		/*
-		 * Yes, "display" did the displaying, or we did'nt have to
-		 * display at all.
-		 * I like it, but the user obviously does not.
-		 * Let him buy another (smarter) terminal ...
-		 */
-		return i;
-	}
-	/*
-	 * Now, all we have to do is the displaying. And we are dealing with
-	 * a smart terminal (it can insert lines or scroll back).
-	 */
-	home();
-	/*
-	 * Insert lines all at once
-	 */
-	for (i = n; i; i--) {
-		if (DB && *CE) {
-			/*
-			 * Grumble..., terminal retains lines below, so we have
-			 * to clear the lines that we push off the screen
-			 */
-			clrbline();
-			home();
-		}
-		if (*SR) {
-			scrollreverse();
-		}
-		else {
-# ifdef VT100_PATCH
-			insert_line(0);
-# else
-			insert_line();
-# endif
-		}
-	}
-	p = skiplines(getline(ln = s->firstline, 1), s->nf);
-	for (i = 0; i < n; i++) {
-		p = do_line(p,1);
-		s->currentpos--;
-		if (!*p) {
-			p = getline(++ln, 1);
-		}
-	}
-	return count;
-}
-
-/*
- * Process a line.
- * If reallydispl > 0 then display it.
- */
-
-STATIC char *
-do_line(str, reallydispl) register char *str; int reallydispl; {
-
-	char buf[1024];
-	register char *p = buf;
-	register int pos = COLS;
-	register int c;
-	register int c1;
-	register int do_ul = 0, do_hl = 0;
-	int lastmode = 0, lasthlmode = 0;
-	int c2;
-
-	while (*str && pos > 0) {
-		if (*str < ' ' && (c1 = match(str,&c2,sppat)) > 0) {
-			/*
-			 * We found a string that matches, and thus must be
-			 * echoed literally
-			 */
-			if ((pos - c2) <= 0) {
-				/*
-				 * It did not fit
-				 */
-				break;
-			}
-			pos -= c2;
-			str += c1;
-			if (reallydispl) {
-				c = *str;
-				*p = *str = 0;
-				cputline(p = buf);
-				putline(str - c1);
-				*str = c;
-			}
-			continue;
-		}
-		c = *str++;
-		do_hl = 0;
-		if (*str == '\b' && *(str+1) != 0
-					&& (c != '_' || *(str+2) == '\b')) {
-			while (*str == '\b' && *(str+1) != 0) {
-				str++;
-				c = *str++;
-				do_hl = 1;
-			}
-		}
-		do_ul = 1;
-		/*
-		 * Find underline sequences ...
-		 */
-		if (c == '_' && *str == '\b') {
-			str++;
-			c = *str++;
-		}
-		else {
-			if (*str == '\b' && *(str+1) == '_') {
-				str += 2;
-			}
-			else	do_ul = 0;
-		}
-		if (reallydispl && do_hl != lasthlmode) {
-			*p = 0;
-			cputline(p = buf);
-			if (do_hl) bold();
-			else end_bold();
-		}
-		lasthlmode = do_hl;
-		if (reallydispl && do_ul != lastmode) {
-			*p = 0;
-			cputline(p = buf);
-			if (do_ul) underline();
-			else end_underline();
-		}
-		lastmode = do_ul;
-		*p++ = c;
-		if (c >= ' ' && c < 0177) {
-			pos--;
-			if (reallydispl && do_ul && *UC && pos > 0) {
-				/*
-				 * Underlining apparently is done one
-				 * character at a time.
-				 */
-				*p = 0;
-				cputline(p = buf);
-				backspace();
-				underchar();
-			}
-			continue;
-		}
-		if (c == '\t') {
-			p--;
-			c1 = 8 - ((COLS - pos) & 07);
-			/*
-			 * Actually, if COLS is a multiple of 8, this can be
-			 * simplified to
-			 *     c1 = pos & 07;
-			 * But of course, we don't know that for sure.
-			 */
-			if (pos - c1 < 0) break;
-			pos -= c1;
-			if (reallydispl) {
-				if (expandtabs) {
-					/*
-					 * Expand tabs. We cannot let the
-					 * kernel take care of this
-					 * for two reasons:
-					 * 1. There can be tabs in cursor
-					 *    addressing strings,
-					 * 2. We probably do it better.
-					 */
-					while (c1-- > 0) {
-						*p++ = ' ';
-					}
-				}
-				else {
-					*p = 0;
-					cputline(p = buf);
-					givetab();
-				}
-			}
-			continue;
-		}
-		/*
-		 * Now we have a control character, which takes two positions
-		 */
-		if (pos <= 1) {
-			p--;
-			break;
-		}
-		pos -= 2;
-	}
-	if (reallydispl) {
-		*p = 0;
-		cputline(buf);
-		if (pos > 0 || (pos <= 0 && (!AM || XN))) {
-			putline("\r\n");
-		}
-		/*
-		 * The next should be here! I.e. it may not be before printing
-		 * the newline. This has to do with XN. We don't know exactly
-		 * WHEN the terminal will stop ignoring the newline.
-		 * I have for example a terminal (Ampex a230) that will
-		 * continue to ignore the newline after a clear to end of line
-		 * sequence, but not after an end_underline sequence.
-		 */
-		if (do_ul) {
-			end_underline();
-		}
-		if (do_hl) {
-			standend();
-		}
-	}
-	scr_info.currentpos++;
-	return str;
-}
-
-/* ARGSUSED */
-int
-setmark(cnt) long cnt; {	/* Set a mark on the current page */
-	register struct scr_info *p = &scr_info;
-
-	p->savfirst = p->firstline;
-	p->savnf = p->nf;
-}
-
-/* ARGSUSED */
-int
-tomark(cnt) long cnt; {		/* Go to the mark */
-	register struct scr_info *p = &scr_info;
-
-	(VOID) display(p->savfirst,p->savnf,pagesize,1);
-}
-
-/* ARGSUSED */
-int
-exgmark(cnt) long cnt; {	/* Exchange mark and current page */
-	register struct scr_info *p = &scr_info;
-	register long svfirst;
-	register int svnf;
-
-	svfirst = p->firstline;
-	svnf = p->nf;
-	tomark(0L);
-	p->savfirst = svfirst;
-	p->savnf = svnf;
-}
-
-VOID
-d_clean() {			/* Clean up */
-	register struct scr_info *p = &scr_info;
-
-	p->savnf = 0;
-	p->savfirst = 0;
-	p->head = p->tail;
-	p->head->line = 0;
-	p->currentpos = 0;
-}
Index: trunk/minix/commands/yap/display.h
===================================================================
--- trunk/minix/commands/yap/display.h	(revision 9)
+++ 	(revision )
@@ -1,124 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/display.h,v 1.1.1.1 2005/04/21 14:55:39 beng Exp $ */
-
-# ifndef _DISPLAY_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-# define MINPAGESIZE 5
-
-PUBLIC int	pagesize;	/* How many lines on a page */
-PUBLIC int	maxpagesize;	/* Maximum # of lines on a page */
-PUBLIC int	scrollsize;	/* number of lines in a scroll */
-struct scr_info {
-	struct linelist {
-	    int cnt;		/* # of screenlines for this line */
-	    long line;		/* lineno of this line */
-# define firstline head->line
-# define lastline tail->line
-	    struct linelist *next;
-	    struct linelist *prev;
-	} *tail, *head;		/* Of all lines of the input file that are
-				 * on the screen, remember how many
-				 * screenlines they occupy. Keep this
-				 * info in a doubly linked list.
-				 */
-	int	nf;		/* How many screenlines of the first line
-				 * on the screen are not on the screen?
-				 */
-	int	currentpos;	/* Y coordinate of first free line */
-	struct linelist ssaavv; /* Mark */
-# define savfirst ssaavv.line
-# define savnf ssaavv.cnt
-};
-
-PUBLIC struct scr_info scr_info;
-PUBLIC int	status;		/* EOFILE on end of file
-				 * START on start of file
-				 * logical "or" if both
-				 */
-/* Flags for status field */
-
-# define EOFILE 01
-# define START 02
-
-VOID	redraw();
-/*
- * void redraw(flag)
- * int flag;			Either 0 or 1
- *
- * Redraws the screen. If flag = 1, the screen is redrawn as precisely
- * as possible, otherwise one page is displayed (which possibly does not
- * take a whole screen.
- */
-
-int	display();
-/*
- * int display(firstline, nodispl, nlines, really)
- * long firstline;		Line with which to start
- * int nodispl;			Do not display nodispl lines of it
- * int nlines;			Number of screen lines that must be displayed
- * int really;			Either 0 or 1
- *
- * Displays nlines as a page. if "really" = 0, the actual displaying is not
- * performed. Only the computing associated with it is done.
- */
-
-int	scrollf();
-/*
- * int scrollf(nlines,really)
- * int nlines;			Number of lines to scroll
- * int really;			Either 0 or 1, see explanation above
- *
- * Scroll forwards "nlines" (screen)lines.
- */
-
-int	scrollb();
-/*
- * int scrollb(nlines,really)
- * int nlines;			Number of lines to scroll
- * int really;			Either 0 or 1, see explanation above
- *
- * Scroll backwards "nlines" (screen)lines.
- */
-
-int	tomark();
-/*
- * int tomark(cnt)
- * long cnt;			(Argument ignored)
- *
- * Display a page starting at the mark. If there was no
- * mark, display the first page of the file.
- * (There is always assumed to be a mark, the initial one is on the first page
- * of the file).
- */
-
-int	setmark();
-/*
- * int setmark(cnt)
- * long cnt;			(Argument ignored)
- *
- * Sets a mark on the current page.
- * It returns nothing (but the address is taken ...)
- */
-
-int	exgmark();
-/*
- * int exgmark(cnt)
- * long cnt;			(Argumewnt ignored)
- *
- * Sets the mark on the current page and displays the
- * previously marked page.
- */
-
-VOID	d_clean();
-/*
- * void d_clean()
- *
- * Clean up and initialize. To be called before displaying a new file
- */
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/getcomm.c
===================================================================
--- trunk/minix/commands/yap/getcomm.c	(revision 9)
+++ 	(revision )
@@ -1,313 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/*
- * Command reader, also executes shell escapes
- */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/getcomm.c,v 1.1.1.1 2005/04/21 14:55:39 beng Exp $";
-# endif
-
-# define _GETCOMM_
-
-# include <ctype.h>
-# include "in_all.h"
-# include "term.h"
-# include "process.h"
-# include "getcomm.h"
-# include "commands.h"
-# include "prompt.h"
-# include "main.h"
-# include "output.h"
-# include "getline.h"
-# include "machine.h"
-# include "keys.h"
-# include "display.h"
-# include "assert.h"
-
-#if USG_OPEN
-#include <fcntl.h>
-#endif
-#if POSIX_OPEN
-#include <sys/types.h>
-#include <fcntl.h>
-#endif
-
-char	*strcpy(),
-	*getenv();
-
-STATIC int	killchar();
-
-/*
- * Read a line from the terminal, doing line editing.
- * The parameter s contains the prompt for the line.
- */
-
-char *
-readline(s) char *s; {
-
-	static char buf[80];
-	register char *p = buf;
-	register int ch;
-	register int pos;
-
-	clrbline();
-	putline(s);
-	pos = strlen(s);
-	while ((ch = getch()) != '\n' && ch != '\r') {
-		if (ch == -1) {
-			/*
-			 * Can only occur because of an interrupted read.
-			 */
-			ch = erasech;
-			interrupt = 0;
-		}
-		if (ch == erasech) {
-			/*
-			 * Erase last char
-			 */
-			if (p == buf) {
-				/*
-				 * There was none, so return
-				 */
-				return (char *) 0;
-			}
-			pos -= killchar(*--p);
-			if (*p != '\\') continue;
-		}
-		if (ch == killch) {
-			/*
-			 * Erase the whole line
-			 */
-			if (!(p > buf && *(p-1) == '\\')) {
-				while (p > buf) {
-					pos -= killchar(*--p);
-				}
-				continue;
-			}
-			pos -= killchar(*--p);
-		}
-		if (p > &buf[78] || pos >= COLS - 2) {
-			/*
-			 * Line does not fit.
-			 * Simply refuse to make it any longer
-			 */
-			pos -= killchar(*--p);
-		}
-		*p++ = ch;
-		if (ch < ' ' || ch >= 0177) {
-			fputch('^');
-			pos++;
-			ch ^= 0100;
-		}
-		fputch(ch);
-		pos++;
-	}
-	fputch('\r');
-	*p++ = '\0';
-	flush();
-	return buf;
-}
-
-/*
- * Erase a character from the command line.
- */
-
-STATIC int
-killchar(c) {
-
-	backspace();
-	putch(' ');
-	backspace();
-	if (c < ' ' || c >= 0177) {
-		(VOID) killchar(' ');
-		return 2;
-	}
-	return 1;
-}
-
-/*
- * Do a shell escape, after expanding '%' and '!'.
- */
-
-VOID
-shellescape(p, esc_char) register char *p; {
-
-	register char *p2;	/* walks through command */
-	register int id;	/* procid of child */
-	register int cnt;	/* prevent array bound errors */
-	register int lastc = 0;	/* will contain the previous char */
-# ifdef SIGTSTP
-	VOID (*savetstp)();
-# endif
-	static char previous[256];	/* previous command */
-	char comm[256];			/* space for command */
-	int piped[2];
-
-	p2 = comm;
-	*p2++ = esc_char;
-	cnt = 253;
-	while (*p) {
-		/*
-		 * expand command
-		 */
-		switch(*p++) {
-		  case '!':
-			/*
-			 * An unescaped ! expands to the previous
-			 * command, but disappears if there is none
-			 */
-			if (lastc != '\\') {
-				if (*previous) {
-					id = strlen(previous);
-					if ((cnt -= id) <= 0) break;
-					(VOID) strcpy(p2,previous);
-					p2 += id;
-				}
-			}
-			else {
-				*(p2-1) = '!';
-			}
-			continue;
-		  case '%':
-			/*
-			 * An unescaped % will expand to the current
-			 * filename, but disappears is there is none
-			 */
-			if (lastc != '\\') {
-				if (nopipe) {
-					id = strlen(currentfile);
-					if ((cnt -= id) <= 0) break;
-					(VOID) strcpy(p2,currentfile);
-					p2 += id;
-				}
-			}
-			else {
-				*(p2-1) = '%';
-			}
-			continue;
-		  default:
-			lastc = *(p-1);
-			if (cnt-- <= 0) break;
-			*p2++ = lastc;
-			continue;
-		}
-		break;
-	}
-	clrbline();
-	*p2 = '\0';
-	if (!stupid) {
-		/*
-		 * Display expanded command
-		 */
-		cputline(comm);
-		putline("\r\n");
-	}
-	flush();
-	(VOID) strcpy(previous,comm + 1);
-	resettty();
-	if (esc_char == '|' && pipe(piped) < 0) {
-		error("Cannot create pipe");
-		return;
-	}
-	if ((id = fork()) < 0) {
-		error("Cannot fork");
-		return;
-	}
-	if (id == 0) {
-		/*
-		 * Close files, as child might need the file descriptors
-		 */
-		cls_files();
-		if (esc_char == '|') {
-			close(piped[1]);
-#if USG_OPEN || POSIX_OPEN
-			close(0);
-			fcntl(piped[0], F_DUPFD, 0);
-#else
-			dup2(piped[0], 0);
-#endif
-			close(piped[0]);
-		}
-		execl("/bin/sh", "sh", "-c", comm + 1, (char *) 0);
-		exit(1);
-	}
-	(VOID) signal(SIGINT,SIG_IGN);
-	(VOID) signal(SIGQUIT,SIG_IGN);
-# ifdef SIGTSTP
-	if ((savetstp = signal(SIGTSTP,SIG_IGN)) != SIG_IGN) {
-		(VOID) signal(SIGTSTP,SIG_DFL);
-	}
-# endif
-	if (esc_char == '|') {
-		(VOID) close(piped[0]);
-		(VOID) signal(SIGPIPE, SIG_IGN);
-		wrt_fd(piped[1]);
-		(VOID) close(piped[1]);
-	}
-	while ((lastc = wait((int *) 0)) != id && lastc >= 0)  {
-		/*
-		 * Wait for child, making sure it is the one we expected ...
-		 */
-	}
-	(VOID) signal(SIGINT,catchdel);
-	(VOID) signal(SIGQUIT,quit);
-# ifdef SIGTSTP
-	(VOID) signal(SIGTSTP, savetstp);
-# endif
-	inittty();
-}
-
-/*
- * Get all those commands ...
- */
-
-int
-getcomm (plong) long   *plong; {
-	int	c;
-	long	count;
-	char	*p;
-	int	i;
-	int	j;
-	char	buf[10];
-
-	for (;;) {
-		count = 0;
-		give_prompt();
-		while (isdigit((c = getch()))) {
-			count = count * 10 + (c - '0');
-		}
-		*plong = count;
-		p = buf;
-		for (;;) {
-			if (c == -1) {
-				/*
-				 * This should never happen, but it does,
-				 * when the user gives a TSTP signal (^Z) or
-				 * an interrupt while the program is trying
-				 * to read a character from the terminal.
-				 * In this case, the read is interrupted, so
-				 * we end up here.
-				 * Right, we will have to read again.
-				 */
-				if (interrupt) return 1;
-				break;
-			}
-			*p++ = c;
-			*p = 0;
-			if ((i = match(buf, &j, currmap->k_mach)) > 0) {
-				/*
-				 * The key sequence matched. We have a command
-				 */
-				return j;
-			}
-			if (i == 0) return 0;
-			/*
-			 * We have a prefix of a command.
-			 */
-			assert(i == FSM_ISPREFIX);
-			c = getch();
-		}
-	}
-	/* NOTREACHED */
-}
Index: trunk/minix/commands/yap/getcomm.h
===================================================================
--- trunk/minix/commands/yap/getcomm.h	(revision 9)
+++ 	(revision )
@@ -1,36 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/getcomm.h,v 1.1.1.1 2005/04/21 14:55:39 beng Exp $ */
-
-# ifndef _GETCOMM_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-int	getcomm();
-/*
- * int getcomm()
- *
- * Reads commands given by the user. The command is returned.
- */
-
-VOID	shellescape();
-/*
- * void shellescape(command)
- * char *command;		The shell command to be executed
- *
- * Expands '%' and '!' in the command "command" to the current filename
- * and the previous command respectively, and then executes "command".
- */
-
-char *	readline();
-/*
- * char * readline(prompt)
- * char *prompt;		Prompt given to the user
- *
- * Gives a prompt "prompt" and reads a line to be typed in by the user.
- * A pointer to this line is returned. Space for this line is static.
- */
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/getline.c
===================================================================
--- trunk/minix/commands/yap/getline.c	(revision 9)
+++ 	(revision )
@@ -1,722 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/getline.c,v 1.1.1.1 2005/04/21 14:55:39 beng Exp $";
-# endif
-
-# define _GETLINE_
-
-# include <errno.h>
-# include "in_all.h"
-# include "getline.h"
-# include "options.h"
-# include "process.h"
-# include "term.h"
-# include "main.h"
-# include "display.h"
-# include "output.h"
-# include "assert.h"
-
-extern int errno;
-
-# define BLOCKSIZE 2048		/* size of blocks */
-# define CHUNK 50		/* # of blockheaders allocated at a time */
-
-/*
- * The blockheaders of the blocks that are in core are kept in a linked list.
- * The last added block is indicated by b_head,
- * the tail of the list is indicated by b_tail.
- * The links go from b_tail to b_head.
- * The blockheaders are all in an array, in the order of the line numbers.
- * Also, the blockheaders must always be in core, so they have to be rather
- * small. On systems with a small address space, yap can run out of core,
- * and panic. However, this should only happen with very large files (>> 1M).
- */
-
-struct block {
-	int		b_flags;	/* Contains the following flags: */
-# define DUMPED		01		/* block dumped on temporary file */
-# define PARTLY		02		/* block not filled completely (eof) */
-	int		b_next;		/* ptr in linked list */
-	long		b_end;		/* line number of last line in block */
-	char	 *	b_info;		/* the block */
-	int      *	b_offs;		/* line offsets within the block */
-	long		b_foff;		/* offset of block in file */
-};
-
-static struct block *	blocklist,	/* beginning of the list of blocks */
-		    *	maxblocklist,	/* first free entry in the list */
-		    *	topblocklist;	/* end of allocated core for the list */
-static int	b_head,
-		b_tail;
-static int	tfdes, ifdes;		/* File descriptors for temporary's */
-static long	lastreadline;		/* lineno of last line read */
-static int	ENDseen;
-
-STATIC VOID readblock();
-STATIC VOID nextblock();
-STATIC char *re_alloc();
-
-STATIC struct block *
-new_block()
-{
-	register struct block *pblock = maxblocklist - 1;
-
-	if (!maxblocklist || !(pblock->b_flags & PARTLY)) {
-		/*
-		 * There is no last block, or it was filled completely,
-		 * so allocate a new blockheader.
-		 */
-		register int siz;
-
-		pblock = blocklist;
-		if (maxblocklist == topblocklist) {
-			/*
-			 * No blockheaders left. Allocate new ones
-			 */
-			siz = topblocklist - pblock;
-			blocklist = pblock = (struct block *)
-			re_alloc((char *) pblock,
-			(unsigned) (siz * sizeof(*pblock)),
-			(unsigned) ((siz + CHUNK) * sizeof(*pblock)));
-			pblock += siz;
-			topblocklist = pblock + CHUNK;
-			maxblocklist = pblock;
-			for (; pblock < topblocklist; pblock++) {
-				pblock->b_end = 0;
-				pblock->b_info = 0;
-				pblock->b_flags = 0;
-			}
-			if (!siz) {
-				/*
-				 * Create dummy header cell.
-				 */
-				maxblocklist++;
-			}
-		}
-		pblock = maxblocklist++;
-	}
-	nextblock(pblock);
-	return pblock;
-}
-
-/*
- * Return the block in which line 'n' of the current file can be found.
- * If "disable_interrupt" = 0, the call may be interrupted, in which
- * case it returns 0.
- */
-
-STATIC struct block *
-getblock(n, disable_interrupt) register long n; {
-	register struct block * pblock;
-
-	if (stdf < 0) {
-		/*
-		 * Not file descriptor, so return end of file
-		 */
-		return 0;
-	}
-	pblock = maxblocklist - 1;
-	if (n < lastreadline ||
-	    (n == lastreadline && !(pblock->b_flags & PARTLY))) {
-		/*
-		 * The line asked for has been read already.
-		 * Perform binary search in the blocklist to find the block
-		 * where it's in.
-		 */
-		register struct block *min, *mid;
-
-		min = blocklist + 1;
-		do {
-			mid = min + (pblock - min) / 2;
-			if (n > mid->b_end) {
-				min = mid + 1;
-			}
-			else pblock = mid;
-		} while (min < pblock);
-		/* Found, pblock is now a reference to the block wanted */
-		if (!pblock->b_info) readblock(pblock);
-		return pblock;
-	}
-
-	/*
-	 * The line was'nt read yet, so read blocks until found
-	 */
-	for (;;) {
-		if (interrupt && !disable_interrupt) return 0;
-		pblock = new_block();
-		if (pblock->b_end >= n) {
-			return pblock;
-		}
-		if (pblock->b_flags & PARTLY) {
-			/*
-			 * We did not find it, and the last block could not be
-			 * read completely, so return 0;
-			 */
-			return	0;
-		}
-	}
-	/* NOTREACHED */
-}
-
-char *
-getline(n, disable_interrupt) long n; {
-	register struct block *pblock;
-
-	if (!(pblock = getblock(n, disable_interrupt))) {
-		return (char *) 0;
-	}
-	return pblock->b_info + pblock->b_offs[n - ((pblock-1)->b_end + 1)];
-}
-
-/*
- * Find the last line of the input, and return its number
- */
-
-long
-to_lastline() {
-
-	for (;;) {
-		if (!getline(lastreadline + 1, 0)) {
-			/*
-			 * "lastreadline" always contains the linenumber of
-			 * the last line read. So, if the call to getline
-			 * succeeds, "lastreadline" is affected
-			 */
-			if (interrupt) return -1L;
-			return lastreadline;
-		}
-	}
-	/* NOTREACHED */
-}
-
-#if MAXNBLOCKS
-int nblocks;		/* Count number of large blocks */
-#endif
-
-/*
- * Allocate some memory. If unavailable, free some and try again.
- * If all fails, panic.
- */
-
-char *
-alloc(size, isblock) unsigned size; {
-
-	register char *pmem;
-	register struct block *pblock, *bllist;
-	char *malloc();
-	long lseek();
-	register long i;
-
-	bllist = blocklist;
-	while (
-#if MAXNBLOCKS
-	   (isblock && nblocks >= MAXNBLOCKS) ||
-#endif
-	   !(pmem = malloc(size))   /* No space */
-	) {
-		if (b_tail == 0) {
-			/*
-			 * Also, no blocks in core. Pity
-			 */
-			panic("No core");
-		}
-#if MAXNBLOCKS
-		nblocks--;
-#endif
-		pblock = bllist + b_tail;
-		b_tail = pblock->b_next;
-		if (!nopipe && !(pblock->b_flags & DUMPED)) {
-			/*
-			 * Dump the block on a temporary file
-			 */
-			if (!tfdes) {
-				/*
-				 * create and open temporary files
-				 */
-				tfdes = opentemp(0);
-				ifdes = opentemp(1);
-			}
-			pblock->b_flags |= DUMPED;
-			/*
-			 * Find out where to dump the block, and dump it
-			 */
-			i = (pblock-1)->b_end * sizeof(int);
-			(VOID) lseek(tfdes,
-				((long) BLOCKSIZE * (pblock - bllist)), 0);
-			if (write(tfdes, pblock->b_info, BLOCKSIZE)
-			    != BLOCKSIZE) {
-				panic("write failed");
-			}
-			/*
-			 * Also dump the offsets of the lines in the block
-			 */
-			(VOID) lseek(ifdes, i, 0);
-			i = pblock->b_end * sizeof(int) - i;
-			if (write(ifdes, (char *) pblock->b_offs, (int) i)
-			    != (int) i) {
-				panic("Write failed");
-			}
-		}
-		/*
-		 * Now that the block is dumped, the space taken by it can
-		 * be freed
-		 */
-		free((char *) pblock->b_offs);
-		free(pblock->b_info);
-		pblock->b_info = (char *) 0;
-	}
-#if MAXNBLOCKS
-	if (isblock) nblocks++;
-#endif
-	return pmem;
-}
-
-/*
- * Re-allocate the memorychunk pointed to by ptr, to let it
- * grow or shrink.
- * realloc of the standard C library is useless, as it is destructive
- * if the malloc fails.
- */
-
-STATIC char *
-re_alloc(ptr,oldsize, newsize)
-char *ptr; unsigned oldsize; unsigned newsize; {
-	register char *pmem;
-	register char *c1, *c2;
-
-	/*
-	 * We could be smarter here, by checking if newsize < oldsize, and in
-	 * that case using realloc, but this depends on realloc using the
-	 * same block if the block shrinks. The question is, wether all
-	 * reallocs in the world do this.
-	 */
-	pmem = alloc(newsize, 0);
-	if (oldsize) {
-		/*
-		 * This test makes re_alloc also work if there was no old block
-		 */
-		c1 = pmem;
-		c2 = ptr;
-		if (newsize > oldsize) {
-			newsize = oldsize;
-		}
-		while (newsize--) {
-			*c1++ = *c2++;
-		}
-		free(ptr);
-	}
-	return pmem;
-}
-
-/*
- * Append a block to the linked list of blockheaders of blocks that are
- * in core.
- */
-
-STATIC VOID
-addtolist(pblock) register struct block *pblock; {
-	register struct block *bllist = blocklist;
-
-	pblock->b_next = 0;
-	(bllist + b_head)->b_next = pblock - bllist;
-	b_head = pblock - bllist;
-	if (!b_tail) {
-		/*
-		 * The list was empty, initialize
-		 */
-		b_tail = b_head;
-	}
-}
-
-static char *saved;
-static long filldegree;
-
-/*
- * Try to read the block indicated by pblock
- */
-
-STATIC VOID
-nextblock(pblock) register struct block *pblock; {
-	register char *c,	/* Run through pblock->b_info */
-		      *c1;	/* indicate end of pblock->b_info */
-	register int *poff;	/* pointer in line-offset list */
-	register int cnt;	/* # of characters read */
-	register unsigned siz;	/* Size of allocated line-offset list */
-	static unsigned savedsiz;	/* saved "siz" */
-	static int *savedpoff;		/* saved "poff" */
-	static char *savedc1;		/* saved "c1" */
-
-	if (pblock->b_flags & PARTLY) {
-		/*
-		 * The block was already partly filled. Initialize locals
-		 * accordingly
-		 */
-		poff = savedpoff;
-		siz = savedsiz;
-		pblock->b_flags = 0;
-		c1 = savedc1;
-		if (c1 == pblock->b_info || *(c1 - 1)) {
-			/*
-			 * We had incremented "lastreadline" temporarily,
-			 * because the last line could not be completely read
-			 * last time we tried. Undo this increment
-			 */
-			poff--;
-			--lastreadline;
-		}
-	}
-	else {
-		if (nopipe) pblock->b_foff = lseek(stdf, 0L, 1);
-		if (saved) {
-			/*
-			 * There were leftovers from the previous block
-			 */
-			pblock->b_info = saved;
-			if (nopipe) pblock->b_foff -= savedc1 - saved;
-			c1 = savedc1;
-			saved = 0;
-		}
-		else {	/* Allocate new block */
-			pblock->b_info = c1 = alloc(BLOCKSIZE + 1, 1);
-		}
-		/*
-		 * Allocate some space for line-offsets
-		 */
-		pblock->b_offs = poff = (int *)
-			alloc((unsigned) (100 * sizeof(int)), 0);
-		siz = 99;
-		*poff++ = 0;
-	}
-	c = c1;
-	for (;;) {
-		/*
-		 * Read loop
-		 */
-		cnt = read(stdf, c1, BLOCKSIZE - (c1 - pblock->b_info));
-		if (cnt < 0) {
-			/*
-			 * Interrupted read
-			 */
-			if (errno == EINTR) continue;
-			error("Could not read input file");
-			cnt = 0;
-		}
-		c1 += cnt;
-		if (c1 != pblock->b_info + BLOCKSIZE) {
-			ENDseen = 1;
-			pblock->b_flags |= PARTLY;
-		}
-		break;
-	}
-	assert(c <= c1);
-	while (c < c1) {
-		/*
-		 * Now process the block
-		 */
-		*c &= 0177;	/* Most significant bit ignored */
-		if (*c == '\n') {
-			/*
-			 * Newlines are replaced by '\0', so that "getline"
-			 * can deliver one line at a time
-			 */
-			*c = 0;
-			lastreadline++;
-			/*
-			 * Remember the line-offset
-			 */
-			if (poff == pblock->b_offs + siz) {
-				/*
-				 * No space for it, allocate some more
-				 */
-				pblock->b_offs = (int *)
-					re_alloc((char *) pblock->b_offs,
-						 (siz+1) * sizeof(int),
-						 (siz + 51) * sizeof(int));
-				poff = pblock->b_offs + siz;
-				siz += 50;
-			}
-			*poff++ = c - pblock->b_info + 1;
-		}
-		else if (*c == '\0') {
-			/*
-			 * 0-bytes are replaced by 0200, because newlines are
-			 * replaced by 0, and 0200 & 0177 gives again 0 ...
-			 */
-			*c = 0200;
-		}
-		c++;
-	}
-	assert(c==c1);
-	*c = 0;
-	if (c != pblock->b_info && *(c-1) != 0) {
-		/*
-		 * The last line read does not end with a newline, so add one
-		 */
-		lastreadline++;
-		*poff++ = c - pblock->b_info + 1;
-		if (!(pblock->b_flags & PARTLY) && *(poff - 2) != 0) {
-			/*
-			 * Save the started line; it will be in the next block.
-			 * Remove the newline we added just now.
-			 */
-			saved = c1 = alloc(BLOCKSIZE + 1, 1);
-			c = pblock->b_info + *(--poff - 1);
-			while (*c) *c1++ = *c++;
-			c = pblock->b_info + *(poff - 1);
-			savedc1 = c1;
-			--lastreadline;
-		}
-	}
-	pblock->b_end = lastreadline;
-	if (pblock->b_flags & PARTLY) {
-		/*
-		 * Take care, that we can call "nextblock" again, to fill in
-		 * the rest of this block
-		 */
-		savedsiz = siz;
-		savedpoff = poff;
-		savedc1 = c;
-		if (c == pblock->b_info) {
-			lastreadline++;
-			pblock->b_end = 0;
-		}
-	}
-	else {
-		/*
-		 * Not completely read blocks are not in the linked list,
-		 * so can never be "swapped out".
-		 */
-		addtolist(pblock);
-		cnt = pblock - blocklist;
-		filldegree = ((c-pblock->b_info) + (cnt-1) * filldegree) / cnt;
-	}
-	assert(pblock->b_end - (pblock-1)->b_end <= poff - pblock->b_offs);
-}
-
-/*
- * Allocate core for the block, and read it back from
- * the temporary file.
- */
-
-STATIC VOID
-readblock(pblock) register struct block *pblock; {
-
-	register int size;
-	register long i;
-
-	/*
-	 * Find out where the block is, and read it
-	 */
-	pblock->b_info = alloc(BLOCKSIZE + 1, 1);
-	i = (pblock - 1)->b_end * sizeof(int);
-	size = (int) (pblock->b_end * sizeof(int) - i);
-	pblock->b_offs	= (int *) alloc((unsigned) size, 0);
-	if (nopipe) {
-		register char *c;
-		register int line_index;
-		int cnt;
-		long l = lseek(stdf, 0L, 1);
-
-		(VOID) lseek(stdf, pblock->b_foff, 0);
-		cnt = read(stdf, pblock->b_info, BLOCKSIZE);
-		(VOID) lseek(stdf, l, 0);
-		c = pblock->b_info;
-		pblock->b_offs[0] = 0;
-		line_index = 1;
-		size /= sizeof(int);
-		while (c < pblock->b_info + cnt) {
-			*c &= 0177;
-			if (*c == '\n') {
-				*c = '\0';
-				if (line_index < size)
-					pblock->b_offs[line_index++] =
-						(c - pblock->b_info) + 1;
-			}
-			else if (*c == '\0') *c = 0200;
-			c++;
-		}
-		*c = '\0';
-	}
-	else {
-		(VOID) lseek(tfdes, (long) ((long) BLOCKSIZE * (pblock - blocklist)),0);
-		if (read(tfdes, pblock->b_info,BLOCKSIZE) != BLOCKSIZE) {
-			panic("read error");
-		}
-		/*
-		 * Find out where the line-offset list is, and read it
-		 */
-		(VOID) lseek(ifdes, i, 0);
-		if (read(ifdes, (char *) pblock->b_offs, size) != size) {
-			panic("read error");
-		}
-		pblock->b_info[BLOCKSIZE] = '\0';
-	}
-	/*
-	 * Add this block to the list of incore blocks
-	 */
-	addtolist(pblock);
-}
-
-/*
- * Called after processing a file.
- * Free all core.
- */
-
-VOID
-do_clean() {
-
-	register struct block *pblock;
-	register char *p;
-
-	for (pblock = blocklist; pblock < maxblocklist; pblock++) {
-		if (p = pblock->b_info) {
-			free(p);
-			free((char *) pblock->b_offs);
-		}
-	}
-	if (p = (char *) blocklist) {
-		free(p);
-	}
-	blocklist = 0;
-	maxblocklist = 0;
-	topblocklist = 0;
-	lastreadline = 0;
-	filldegree = 0;
-	ENDseen = 0;
-	if (p = saved) free(p);
-	saved = 0;
-	b_head = 0;
-	b_tail = 0;
-# if MAXNBLOCKS
-	nblocks = 0;
-# endif
-}
-
-/*
- * Close a file with file-descriptor "file", if it indeed is one
- */
-
-STATIC VOID
-cls(file) {
-	if (file) (VOID) close(file);
-}
-
-/*
- * Close all files
- */
-
-VOID
-cls_files() {
-
-	cls(tfdes);
-	cls(ifdes);
-	cls(stdf);
-}
-
-/*
- * Get a character. If possible, do some workahead.
- */
-
-int
-getch() {
-# if USG_OPEN
-# include <fcntl.h>
-# include <sys/stat.h>
-
-	register int i,j;
-	struct stat buf;
-# else
-# ifdef FIONREAD
-# include <sys/stat.h>
-
-	struct stat buf;
-	long i;
-# endif
-# endif
-
-	char c;
-	int retval;
-
-	flush();
-	if (startcomm) {
-		/*
-		 * Command line option command
-		 */
-		if (*startcomm) return *startcomm++;
-		return '\n';
-	}
-# if USG_OPEN
-	if (stdf >= 0) {
-		/*
-		 * Make reads from the terminal non-blocking, so that
-		 * we can see if the user typed something
-		 */
-		i = fcntl(0,F_GETFL,0);
-		if (i != -1 && fcntl(0, F_SETFL, i|O_NDELAY) != -1) {
-			j = 0;
-			while (! ENDseen && 
-			       ((j = read(0,&c,1)) == 0
-#ifdef EWOULDBLOCK
-			        || (j < 0 && errno == EWOULDBLOCK)
-#endif
-			       )
-			       &&
-			       (nopipe || 
-				(fstat(stdf,&buf) >= 0 && buf.st_size > 0))) {
-				/*
-				 * Do some read ahead, after making sure there
-				 * is input and the user did not type a command
-				 */
-				new_block();
-			}
-			(VOID) fcntl(0,F_SETFL,i);
-			if (j < 0) {
-				/*
-				 * Could this have happened?
-				 * I'm not sure, because the read is
-				 * nonblocking. Can it be interrupted then?
-				 */
-				return -1;
-			}
-			if (j > 0) return c;
-		}
-	}
-# else
-# ifdef FIONREAD
-	if (stdf >= 0) {
-		/*
-		 * See if there are any characters waiting in the terminal input
-		 * queue. If there are not, read ahead.
-		 */
-		while (! ENDseen &&
-		       ( ioctl(0, FIONREAD, (char *) &i) >= 0 && i == 0) &&
-		       ( nopipe || fstat(stdf,&buf) >= 0 && buf.st_size > 0)) {
-			/*
-			 * While the user does'nt type anything, and there is
-			 * input to be processed, work ahead
-			 */
-			if (interrupt) return -1;
-			new_block();
-		}
-	}
-# endif
-# endif
-	if (read(0,&c,1) <= 0) retval = -1; else retval = c & 0177;
-	return retval;
-}
-
-/*
- * Get the position of line "ln" in the file.
- */
-
-long
-getpos(ln) long ln; {
-	register struct block *pblock;
-	register long i;
-
-	pblock = getblock(ln,1);
-	assert(pblock != 0);
-	i = filldegree * (pblock - blocklist);
-	return i - (filldegree - pblock->b_offs[ln - (pblock-1)->b_end]);
-}
Index: trunk/minix/commands/yap/getline.h
===================================================================
--- trunk/minix/commands/yap/getline.h	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/getline.h,v 1.1.1.1 2005/04/21 14:55:39 beng Exp $ */
-
-# ifndef _GETLINE_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-char *	getline();
-/*
- * char * getline(ln,disable_interrupt)
- * long ln;			The line number of the line to be returned
- * int disable_interrupt;	1 if interrupts must be ignored, 0 otherwise
- *
- * Returns a pointer to the line with linenumber "ln".
- * It returns 0 if
- * - there was an interrupt, and interrupts were not disabled, or
- * - there is no line with linenumber "ln".
- */
-
-char *	alloc();
-/*
- * char * alloc(size, isblock)
- * unsigned size;		The size in bytes
- * int isblock;			Flag indicating whether this is a file-text
- *				block
- *
- * Return a pointer to a block of "size" bytes.
- * Panics if no core can be found.
- */
-
-VOID	do_clean();
-/*
- * void do_clean()
- *
- * Cleans up and initializes.
- */
-
-VOID	cls_files();
-/*
- * void cls_files()
- *
- * Closes files. Useful for shell escapes.
- */
-
-int	getch();
-/*
- * int getch()
- *
- * Get a character from input or command option line (only at start up).
- * Some systems allow us to do some workahead while the user is
- * thinking/reading. Use this to get parts of the input file in core.
- */
-
-long	to_lastline();
-/*
- * long to_lastline()
- *
- * Finds the last line of the file, and returns its number.
- * This command can be interrupted, in which case it returns 0.
- */
-
-long	getpos();
-/*
- * long getpos(line);
- *
- * get offset of line "line" in the input
- */
-# undef PUBLIC
Index: trunk/minix/commands/yap/help.c
===================================================================
--- trunk/minix/commands/yap/help.c	(revision 9)
+++ 	(revision )
@@ -1,107 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-#ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/help.c,v 1.1.1.1 2005/04/21 14:55:39 beng Exp $";
-#endif
-
-#define _HELP_
-#include "in_all.h"
-#include "help.h"
-#include "machine.h"
-#include "commands.h"
-#include "keys.h"
-#include "output.h"
-#include "prompt.h"
-#include "main.h"
-#include "display.h"
-#include "term.h"
-#include "options.h"
-
-static int h_cnt;		/* Count # of lines */
-static struct state *origin;	/* Keep track of startstate */
-
-/*
- * Print a key sequence.
- * We arrived at an endstate. The s_next link in the state structure now
- * leads us from "origin" to the current state, so that we can print the key
- * sequence easily.
- */
-
-STATIC VOID
-pr_comm() {
-	register struct state *p = origin;
-	register char *pb;
-	register int c;
-	char buf[30];
-	register int i = 0;	/* How many characters printed? */
-
-	pb = buf;
-	for (;;) {
-		c = p->s_char & 0177;
-		if (c < ' ' || c == 0177) {
-			/*
-			 * Will take an extra position
-			 */
-			i++;
-		}
-		*pb++ = c;
-		i++;
-		if (!p->s_match) break;
-		p = p->s_next;
-	}
-	do {
-		*pb++ = ' ';
-	} while (++i < 12);
-	*pb = 0;
-	cputline(buf);
-}
-
-/*
- * Print out a description of the keymap. This is done, by temporarily using
- * the s_next field in the state structure indicate the state matching the
- * next character, so that we can walk from "origin" to an endstate.
- */
-
-STATIC VOID
-pr_mach(currstate, back) register struct state *currstate, *back; {
-	struct state *save;
-
-	while (currstate) {
-		if (interrupt) break;
-		if (back) {
-			save = back->s_next;	/* Save original link */
-			back->s_next = currstate;
-		}
-		if (!currstate->s_match) {
-			/*
-			 * End state, print command
-			 */
-			pr_comm();
-			putline(commands[currstate->s_cnt].c_descr);
-			putline("\r\n");
-			if (++h_cnt >= maxpagesize) {
-				ret_to_continue();
-				h_cnt = 0;
-			}
-		}
-		else pr_mach(currstate->s_match, currstate);
-		currstate = currstate->s_next;
-		if (back) back->s_next = save;	/* restore */
-		else origin = currstate;
-	}
-}
-
-/*ARGSUSED*/
-int
-do_help(i) long i; {	/* The help command */
-
-	startcomm = 0;
-	h_cnt = 2;
-	putline("\r\nSummary of yap commands:\r\n");
-	origin = currmap->k_mach;
-	pr_mach(currmap->k_mach, (struct state *) 0);
-	if (h_cnt) {
-		ret_to_continue();
-	}
-	if (!hardcopy && scr_info.currentpos) redraw(1);
-}
Index: trunk/minix/commands/yap/help.h
===================================================================
--- trunk/minix/commands/yap/help.h	(revision 9)
+++ 	(revision )
@@ -1,20 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/help.h,v 1.1.1.1 2005/04/21 14:55:39 beng Exp $ */
-
-# ifndef _HELP_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-int	do_help();
-/*
- * int do_help(cnt);
- * long cnt;			This is ignored, but a count is given
- *				to any command
- *
- * Give a summary of commands
- */
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/in_all.h
===================================================================
--- trunk/minix/commands/yap/in_all.h	(revision 9)
+++ 	(revision )
@@ -1,89 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/in_all.h,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $ */
-
-#define DO_ASSERT 0	/* define when debugging */
-# ifdef DO_ASSERT
-# define STATIC
-# else
-# define STATIC static
-# endif
-
-#define VOID void	/* preferably void, but int if your compiler does
-			   not recognize void
-			*/
-
-#if _POSIX_SOURCE
-#define POSIX_OPEN 1	/* POSIX "open" system call */
-#else
-#define USG_OPEN 0	/* USG "open" system call (include <fcntl.h>) */
-#define BSD4_2_OPEN 0 /* BSD 4.2 "open" system call (include <sys/file.h>)*/
-#endif
-
-/* Sanity check 1 */
-# if (!!USG_OPEN) + (!!BSD4_2_OPEN) + (!!POSIX_OPEN) > 1
-Oops, now why did you do that?
-O, never mind, just try it again with
-USG_OPEN = 1 or		for System III, System V etc.
-BSD4_2_OPEN = 1 or	for Berkeley 4.2, Ultrix etc.
-POSIX_OPEN = 1 or	for POSIX compliant systems.
-USG_OPEN = 0 and BSD4_2_OPEN = 0 and POSIX_OOPEN
-	for Berkeley 4.1, v7 and whatever else
-# endif
-
-#define BSD_REGEX 0	/* Berkeley style re_comp/re_exec */
-#define V8_REGEX  1	/* V8 style regexec/regcomp */
-#define USG_REGEX 0	/* USG style regex/regcmp */
-
-/* Sanity check 2 */
-# if USG_REGEX + BSD_REGEX + V8_REGEX > 1
-Select one style for the regular expressions please!
-# endif
-
-#define USG_TTY 0	/* define if you have an USG tty driver (termio) */
-			/* If you do not define this, you get either the
-			 * V7 tty driver or the BSD one.
-			 */
-#if _POSIX_SOURCE
-#define POSIX_TTY 1
-#endif
-
-#if __minix && !__minix_vmd
-#define MAXNBLOCKS 10	/* Limit the number of blocks that yap will use to keep
-			 * the input in core.
-			 * This was needed to let yap run on an IBM XT
-			 * running PC/IX. The problem is that malloc can
-			 * allocate almost all available space, leaving no
-			 * space for the stack, which causes a memory fault.
-			 * Internal yap blocks are 2K, but there is a lot of
-			 * additional information that yap keeps around. You
-			 * can also use it if you want to limit yap's maximum
-			 * size. If defined, it should be at least 3.
-			 * 10 is probably a reasonable number.
-			 */
-#endif
-/* Sanity check 3 */
-# ifdef MAXNBLOCKS
-# if MAXNBLOCKS < 3
-Read the above comment!
-# endif
-# endif
-
-#define VT100_PATCH	/* This involves a patch that will insert lines
-			 * correctly on a VT100 terminal. The termcap entry
-			 * for it contains an "al" with %-escapes. According
-			 * to the termcap-documentation this is not allowed,
-			 * but ...
-			 * If VT100_PATCH is defined, the "al" capability will
-			 * be offered to "tgoto", before "tputs"-ing it.
-			 * I don't know if there are any terminals out there
-			 * that have a % in their "al" capability. If there
-			 * are, yap will not work properly when compiled with
-			 * VT100_PATCH defined.
-			 * Also, escape sequences for standout and underline
-			 * will be tputs-ed if VT100_PATCH is defined.
-			 */
-
-#if _MINIX
-#define	LCASE	0	/* Minix doesn;t have LCASE */
-#endif
Index: trunk/minix/commands/yap/keys.c
===================================================================
--- trunk/minix/commands/yap/keys.c	(revision 9)
+++ 	(revision )
@@ -1,188 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/keys.c,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $";
-# endif
-
-# define _KEYS_
-
-# include <ctype.h>
-# include "in_all.h"
-# include "machine.h"
-# include "keys.h"
-# include "commands.h"
-# include "prompt.h"
-# include "assert.h"
-
-char defaultmap[] = "\
-bf=P:bl=k:bl=^K:bl=^[[A:bot=l:bot=$:bot=^[[Y:bp=-:bp=^[[V:bs=^B:bse=?:bsl=S:\
-bsp=F:chm=X:exg=x:ff=N:fl=^J:fl=^M:fl=j:fl=^[[B:fp= :fp=^[[U:fs=^D:fse=/:\
-fsl=s:fsp=f:hlp=h:nse=n:nsr=r:red=^L:rep=.:bps=Z:bss=b:fps=z:fss=d:shl=!:\
-tom=':top=\\^:top=^[[H:vis=e:wrf=w:qui=q:qui=Q:mar=m:pip=|";
-
-char *strcpy();
-char *strcat();
-char *getenv();
-
-/*
- * Construct an error message and return it
- */
-
-STATIC char *
-kerror(key, emess) char *key, *emess; {
-	static char ebuf[80];	/* Room for the error message */
-
-	(VOID) strcpy(ebuf, key);
-	(VOID) strcat(ebuf, emess);
-	return ebuf;
-}
-
-/*
- * Compile a keymap into commtable. Returns an error message if there
- * is one
- */
-
-STATIC char *
-compile(map, commtable)
-  register char *map; register struct keymap *commtable; {
-	register char *mark;	/* Indicates start of mnemonic */
-	register char *c;	/* Runs through buf */
-	register int temp;
-	char *escapes = commtable->k_esc;
-	char buf[10];		/* Will hold key sequence */
-
-	(VOID) strcpy(commtable->k_help,"Illegal command");
-	while (*map) {
-		c = buf;
-		mark = map;	/* Start of mnemonic */
-		while (*map && *map != '=') {
-			map++;
-		}
-		if (!*map) {
-			/*
-			 * Mnemonic should end with '='
-			 */
-			return kerror(mark, ": Syntax error");
-		}
-		*map++ = 0;
-		while (*map) {
-			/*
-			 * Get key sequence
-			 */
-			if (*map == ':') {
-				/*
-				 * end of key sequence
-				 */
-				map++;
-				break;
-			}
-			*c = *map++ & 0177;
-			if (*c == '^' || *c == '\\') {
-				if (!(temp = *map++)) {
-					/*
-					 * Escape not followed by a character
-					 */
-					return kerror(mark, ": Syntax error");
-				}
-				if (*c == '^') {
-					if (temp == '?') *c = 0177;
-					else *c = temp & 037;
-				}
-				else *c = temp & 0177;
-			}
-			setused(*c);
-			c++;
-			if (c >= &buf[9]) {
-				return kerror(mark,": Key sequence too long");
-			}
-		}
-		*c = 0;
-		if (!(temp = lookup(mark))) {
-			return kerror(mark,": Nonexistent function");
-		}
-		if (c == &buf[1] && (commands[temp].c_flags & ESC) &&
-		    escapes < &(commtable->k_esc[sizeof(commtable->k_esc)-1])) {
-			*escapes++ = buf[0] & 0177;
-		}
-		temp = addstring(buf, temp, &(commtable->k_mach));
-		if (temp == FSM_ISPREFIX) {
-			return kerror(mark,": Prefix of other key sequence");
-		}
-		if (temp == FSM_HASPREFIX) {
-			return kerror(mark,": Other key sequence is prefix");
-		}
-		assert(temp == FSM_OKE);
-		if (!strcmp(mark, "hlp")) {
-			/*
-			 * Create an error message to be given when the user
-			 * types an illegal command
-			 */
-			(VOID) strcpy(commtable->k_help, "Type ");
-			(VOID) strcat(commtable->k_help, buf);
-			(VOID) strcat(commtable->k_help, " for help");
-		}
-	}
-	*escapes = 0;
-	return (char *) 0;
-}
-
-/*
- * Initialize the keymaps
- */
-
-VOID
-initkeys() {
-	register char *p;
-	static struct keymap xx[2];
-
-	currmap = &xx[0];
-	othermap = &xx[1];
-	p = compile(defaultmap, currmap);	/* Compile default map */
-	assert(p == (char *) 0);
-	p = getenv("YAPKEYS");
-	if (p) {
-		if (!(p = compile(p, othermap))) {
-			/*
-			 * No errors in user defined keymap. So, use it
-			 */
-			do_chkm(0L);
-			return;
-		}
-		error(p);
-	}
-	othermap = 0;		       /* No other keymap */
-}
-
-int
-is_escape(c)
-{
-	register char *p = currmap->k_esc;
-
-	while (*p) {
-		if (c == *p++) return 1;
-	}
-	return 0;
-}
-
-static char keyset[16];		/* bitset indicating which keys are
-				 * used
-				 */
-/*
- * Mark key "key" as used
- */
-
-VOID
-setused(key) int key; {
-
-	keyset[(key & 0177) >> 3] |= (1 << (key & 07));
-}
-
-/*
- * return non-zero if key "key" is used in a keymap
- */
-
-int
-isused(key) int key; {
-
-	return keyset[(key & 0177) >> 3] & (1 << (key & 07));
-}
Index: trunk/minix/commands/yap/keys.h
===================================================================
--- trunk/minix/commands/yap/keys.h	(revision 9)
+++ 	(revision )
@@ -1,50 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/keys.h,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $ */
-
-# ifndef _KEYS_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-PUBLIC struct keymap {
-    char k_help[80];		/* To be printed on illegal command */
-    struct state *k_mach;	/* Finite state machine */
-    char k_esc[10];		/* escape chars */
-} *currmap,			/* pointer to current key map */
-  *othermap;			/* pointer to other keymap */
-
-VOID initkeys();
-/*
- * void initkeys();
- *
- * Initializes the keymap(s).
- */
-
-VOID setused();
-/*
- * void setused(key);
- * int key;
- *
- * Marks the key "key" as used.
- */
-
-int isused();
-/*
- * int isused(key);
- * int key;
- *
- * returns 0 if the key "key" is not used.
- * Otherwise it returns non-zero.
- */
-
-int is_escape();
-/*
- * int is_escape(c);
- * int c;
- *
- * Returns 1 if "c" is an escape char (shell or pipe) in the current
- * keymap.
- */
-# undef PUBLIC
Index: trunk/minix/commands/yap/machine.c
===================================================================
--- trunk/minix/commands/yap/machine.c	(revision 9)
+++ 	(revision )
@@ -1,137 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/machine.c,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $";
-# endif
-
-# define _MACHINE_
-
-# include <ctype.h>
-# include "in_all.h"
-# include "machine.h"
-# include "getline.h"
-# include "assert.h"
-
-/*
- * Add part of finite state machine to recognize the string s.
- */
-
-STATIC int
-addtomach(s, cnt, list) char *s; struct state **list; {
-
-	register struct state *l;
-	register int i = FSM_OKE;	/* Return value */
-	register int j;
-
-	for (;;) {
-		l = *list;
-		if (!l) {
-			/*
-			 * Create new list element
-			 */
-			*list = l = (struct state *) alloc(sizeof(*l), 0);
-			l->s_char = *s;
-			l->s_endstate = 0;
-			l->s_match = 0;
-			l->s_next = 0;
-		}
-		if (l->s_char == *s) {
-			/*
-			 * Continue with next character
-			 */
-			if (!*++s) {
-				/*
-				 * No next character
-				 */
-				j = l->s_endstate;
-				l->s_endstate = 1;
-				if (l->s_match || j) {
-					/*
-					 * If the state already was an endstate,
-					 * or has a successor, the currently
-					 * added string is a prefix of an
-					 * already recognized string
-					 */
-					return FSM_ISPREFIX;
-				}
-				l->s_cnt = cnt;
-				return i;
-			}
-			if (l->s_endstate) {
-				/*
-				 * In this case, the currently added string has
-				 * a prefix that is an already recognized
-				 * string.
-				 */
-				i = FSM_HASPREFIX;
-			}
-			list = &(l->s_match);
-			continue;
-		}
-		list = &(l->s_next);
-	}
-	/* NOTREACHED */
-}
-
-/*
- * Add a string to the FSM.
- */
-
-int
-addstring(s,cnt,machine) register char *s; struct state **machine; {
-
-	if (!s || !*s) {
-		return FSM_ISPREFIX;
-	}
-	return addtomach(s,cnt,machine);
-}
-
-/*
- * Match string s with the finite state machine.
- * If it matches, the number of characters actually matched is returned,
- * and the count is put in the word pointed to by i.
- * If the string is a prefix of a string that could be matched,
- * FSM_ISPREFIX is returned. Otherwise, 0 is returned.
- */
-
-int
-match(s,i,mach) char *s; int *i; register struct state *mach; {
-
-	register char *s1 = s;	/* Walk through string */
-	register struct state *mach1 = 0;
-				/* Keep track of previous state */
-
-	while (mach && *s1) {
-		if (mach->s_char == *s1) {
-			/*
-			 * Current character matches. Carry on with next
-			 * character and next state
-			 */
-			mach1 = mach;
-			mach = mach->s_match;
-			s1++;
-			continue;
-		}
-		mach = mach->s_next;
-	}
-	if (!mach1) {
-		/*
-		 * No characters matched
-		 */
-		return 0;
-	}
-	if (mach1->s_endstate) {
-		/*
-		 * The string matched
-		 */
-		*i = mach1->s_cnt;
-		return s1 - s;
-	}
-	if (!*s1) {
-		/*
-		 * The string matched a prefix
-		 */
-		return FSM_ISPREFIX;
-	}
-	return 0;
-}
Index: trunk/minix/commands/yap/machine.h
===================================================================
--- trunk/minix/commands/yap/machine.h	(revision 9)
+++ 	(revision )
@@ -1,60 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/machine.h,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $ */
-
-# ifndef _MACHINE_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-/*
- * Simple minded finite state machine implementation to recognize
- * strings.
- */
-
-struct state {
-    char s_char;		/* character to match with */
-    char s_endstate;		/* flag, 1 if this state is an endstate */
-    struct state *s_match;	/* new state if matched */
-    struct state *s_next;	/* other characters to match with */
-    short s_cnt;		/* if an endstate, this field is filled with
-				 * some info, dependant on the machine.
-				 */
-};
-
-# define FSM_OKE	0
-# define FSM_ISPREFIX	-1	/* Must be < 0 */
-# define FSM_HASPREFIX	1
-
-int	addstring();
-/*
- * int addstring(str,cnt,mach)
- * char *str;			The string to be recognized
- * int cnt;			Attribute of the string.
- * struct state **mach;		The finite state machine
- *
- * This routine adds a string to a finite state automaton.
- * It returns FSM_ISPREFIX if the added string is a prefix of a string already
- * in the automaton, FSM_HASPREFIX if a string, already recognized by the
- * automaton, is a prefix of the added string.
- * Otherwise it returns FSM_OKE.
- */
-
-int	match();
-/*
- * int match(str,p_int,mach)
- * char *str;			pointer to string
- * int *p_int;			Pointer to an integer
- * struct state *mach;		The finite state machine
- *
- * A match of the string indicated by "str" is tried. If a head of "str"
- * is recognized by the finite state automaton, a machine dependant number
- * is put in the integer pointed to by "p_int".
- * The number of characters that match is returned, so a return value of 0
- * means no match.
- * A return value of FSM_PREFIX means that the string "str" was a prefix of a
- * matched string.
- */
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/main.c
===================================================================
--- trunk/minix/commands/yap/main.c	(revision 9)
+++ 	(revision )
@@ -1,220 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/main.c,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $";
-# endif
-
-# define _MAIN_
-
-# include "in_all.h"
-# if USG_OPEN
-# include <fcntl.h>
-# endif
-# if BSD4_2_OPEN
-# include <sys/file.h>
-# endif
-# if POSIX_OPEN
-# include <sys/types.h>
-# include <fcntl.h>
-# endif
-# include "main.h"
-# include "term.h"
-# include "options.h"
-# include "output.h"
-# include "process.h"
-# include "commands.h"
-# include "display.h"
-# include "prompt.h"
-
-char	*strcpy();
-
-STATIC int initialize();
-# ifdef SIGTSTP
-STATIC int suspsig();
-# endif
-
-int
-main(argc,argv) register char ** argv; {
-
-	register char ** av;
-
-	if (! isatty(1)) {
-		no_tty = 1;
-	}
-	argv[argc] = 0;
-	progname = argv[0];
-	if ((av = readoptions(argv)) == (char **) 0 ||
-		initialize(*av ? 1 : 0)) {
-		if (no_tty) {
-			close(1);
-			(VOID) dup(2);
-		}
-		putline("Usage: ");
-		putline(argv[0]);
-		putline(
-" [-c] [-u] [-n] [-q] [-number] [+command] [file ... ]\n");
-		flush();
-		exit(1);
-	}
-	if (no_tty) {
-		*--av = "cat";
-		execve("/bin/cat", av, (char *) 0);
-	}
-	else	processfiles(argc-(av-argv), av);
-	(VOID) quit();
-	/* NOTREACHED */
-}
-
-char *mktemp();
-
-/*
- * Open temporary file for reading and writing.
- * Panic if it fails
- */
-
-static char indexfile[30], tempfile[30];
-
-int
-opentemp(i) {
-
-	register fildes;
-	register char *f;
-
-	f = i ? mktemp(indexfile) : mktemp(tempfile);
-# if BSD4_2_OPEN || USG_OPEN || POSIX_OPEN
-	if ((fildes = open(f,O_RDWR|O_TRUNC|O_CREAT,0600)) < 0) {
-# else
-	if ((fildes = creat(f,0600)) <= 0 || close(fildes) < 0 ||
-	    (fildes = open(f,2)) < 0) {
-# endif
-		panic("Couldn't open temporary file");
-	}
-	(VOID) unlink(f);
-	return fildes;
-}
-
-/*
- * Collect initializing stuff here.
- */
-
-STATIC int
-initialize(x) {
-
-	if (!(nopipe = x)) {
-		/*
-		 * Reading from pipe
-		 */
-		if (isatty(0)) {
-			return 1;
-		}
-		stdf = dup(0);	/* Duplicate file descriptor of input */
-		if (no_tty) return 0;
-		/*
-		 * Make sure standard input is from the terminal.
-		 */
-		(VOID) close(0);
-# if BSD4_2_OPEN || USG_OPEN || POSIX_OPEN
-		if (open("/dev/tty",O_RDONLY,0) != 0) {
-# else
-		if (open("/dev/tty",0) != 0) {
-# endif
-			putline("Couldn't open terminal\n");
-			flush();
-			exit(1);
-		}
-	}
-	if (no_tty) return 0;
-	(VOID) strcpy(tempfile,"/usr/tmp/yap_XXXXXX");
-	(VOID) strcpy(indexfile,"/usr/tmp/yap-XXXXXX");
-	/*
-	 * Handle signals.
-	 * Catch QUIT, DELETE and ^Z
-	 */
-	(VOID) signal(SIGQUIT,SIG_IGN);
-	(VOID) signal(SIGINT, catchdel);
-	ini_terminal();
-# ifdef SIGTSTP
-	if (signal(SIGTSTP,SIG_IGN) == SIG_DFL) {
-		(VOID) signal(SIGTSTP,suspsig);
-	}
-# endif
-	(VOID) signal(SIGQUIT,quit);
-	return 0;
-}
-
-int
-catchdel() {
-	(VOID) signal(SIGINT, catchdel);
-	interrupt = 1;
-}
-
-# ifdef SIGTSTP
-
-/*
- * We had a SIGTSTP signal.
- * Suspend, by a call to this routine.
- */
-
-VOID
-suspend() {
-
-	nflush();
-	resettty();
-	(VOID) signal(SIGTSTP,SIG_DFL);
-#if BSD4_2_OPEN
-	sigsetmask(sigblock(0)&~(1 << (SIGTSTP - 1)));
-#endif
-	(VOID) kill(0, SIGTSTP);
-	/*
-	 * We are not here anymore ...
-	 *
-
-	 *
-	 * But we arive here ...
-	 */
-	inittty();
-	putline(TI);
-	flush();
-	(VOID) signal(SIGTSTP,suspsig);
-}
-
-/*
- * SIGTSTP signal handler.
- * Just indicate that we had one, ignore further ones and return.
- */
-
-STATIC int
-suspsig() {
-
-	suspend();
-	if (DoneSetJmp) longjmp(SetJmpBuf, 1);
-}
-# endif
-
-/*
- * quit : called on exit.
- * I bet you guessed that much.
- */
-
-int
-quit() {
-
-	clrbline();
-	resettty();
-	flush();
-	exit(0);
-}
-
-/*
- * Exit, but nonvoluntarily.
- * At least tell the user why.
- */
-
-VOID
-panic(s) char *s; {
-
-	putline("\007\007\007\r\n");
-	putline(s);
-	putline("\r\n");
-	quit();
-}
Index: trunk/minix/commands/yap/main.h
===================================================================
--- trunk/minix/commands/yap/main.h	(revision 9)
+++ 	(revision )
@@ -1,68 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/main.h,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $ */
-
-# ifndef _MAIN_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-PUBLIC int	nopipe;		/* Not reading from pipe? */
-PUBLIC char *	progname;	/* Name of this program */
-PUBLIC int	interrupt;	/* Interrupt given? */
-PUBLIC int	no_tty;		/* output not to a terminal, behave like cat */
-
-int	main();
-/*
- * int main(argc,argv)
- * int argc;		Argument count
- * char *argv[];	The arguments
- *
- * Main program.
- */
-
-int	opentemp();
-/*
- * int opentemp(i)
- * int i;		Either 0 or 1, indicates which temporary to open
- *
- * Returns a file descriptor for the temporary file, or panics if
- * it couldn't open one.
- */
-
-int	catchdel();
-/*
- * int catchdel();
- *
- * interrupt handler. Does not return a value, but PCC has some
- * difficulty with the type pointer to function returning void.
- * This routine only sets a flag indicating that there was an interrupt.
- */
-
-int	quit();
-/*
- * int quit();
- *
- * Quit signal handler. Also used for normal exits.
- * It resets the terminal and exits
- */
-
-VOID	panic();
-/*
- * void panic(str)
- * char *str;		Reason for panic
- *
- * Panic, but at least tell the user why.
- */
-
-# ifdef SIGTSTP
-VOID	suspend();
-/*
- * void suspend()
- *
- * Suspends this process
- */
-# endif
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/options.c
===================================================================
--- trunk/minix/commands/yap/options.c	(revision 9)
+++ 	(revision )
@@ -1,88 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/options.c,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $";
-# endif
-
-# define _OPTIONS_
-
-# include "in_all.h"
-# include "options.h"
-# include "output.h"
-# include "display.h"
-# include <ctype.h>
-
-STATIC int parsopt();
-char *getenv();
-
-/*
- * Read the options. Return the argv pointer following them if there were
- * no errors, otherwise return 0.
- */
-
-char **
-readoptions(argv) char ** argv; {
-
-	register char ** av = argv+1;
-	register char *p;
-
-	if (p = getenv("YAP")) {
-		(VOID) parsopt(p);
-	}
-	while (*av && **av == '-') {
-		if (parsopt(*av)) {
-			/*
-			 * Error in option
-			 */
-			putline(*av);
-			putline(": illegal option\n");
-			return (char **) 0;
-		}
-		av++;
-	}
-	if (*av && **av == '+') {
-		/*
-		 * Command in command line
-		 */
-		startcomm = *av + 1;
-		av++;
-	}
-	return av;
-}
-
-STATIC int
-parsopt(s) register char *s; {
-	register i;
-
-	if (*s == '-') s++;
-	if (isdigit(*s)) {
-		/*
-		 * pagesize option
-		 */
-		i = 0;
-		do {
-			i = i * 10 + *s++ - '0';
-		} while (isdigit(*s));
-		if (i < MINPAGESIZE) i = MINPAGESIZE;
-		pagesize = i;
-	}
-	while (*s) {
-		switch(*s++) {
-		  case 'c' :
-			cflag++;
-			break;
-		  case 'n' :
-			nflag++;
-			break;
-		  case 'u' :
-			uflag++;
-			break;
-		  case 'q' :
-			qflag++;
-			break;
-		  default :
-			return 1;
-		}
-	}
-	return 0;
-}
Index: trunk/minix/commands/yap/options.h
===================================================================
--- trunk/minix/commands/yap/options.h	(revision 9)
+++ 	(revision )
@@ -1,26 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/options.h,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $ */
-
-# ifndef _OPTIONS_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-PUBLIC int	cflag;		/* no home before each page */
-PUBLIC int	uflag;		/* no underlining */
-PUBLIC int	nflag;		/* no pattern matching on input */
-PUBLIC int	qflag;		/* no exit on the next page command */
-PUBLIC char *	startcomm;	/* There was a command option */
-
-char ** readoptions();
-/*
- * char ** readoptions(argv)
- * char **argv;			Arguments given to yap.
- *
- * process the options from the arguments. Return 0 if there was an error,
- * otherwise return a pointer to where the filenames start.
- */
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/output.c
===================================================================
--- trunk/minix/commands/yap/output.c	(revision 9)
+++ 	(revision )
@@ -1,100 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/*
- * Handle output to screen
- */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/output.c,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $";
-# endif
-
-# define _OUTPUT_
-
-# include "in_all.h"
-# include "output.h"
-# include "main.h"
-
-# define OBUFSIZ 64*128
-
-static char _outbuf[OBUFSIZ];
-
-VOID
-flush() {			/* Flush output buffer, by writing it */
-	register char *p = _outbuf;
-
-	_ocnt = OBUFSIZ;
-	if (_optr) (VOID) write(1, p, _optr - p);
-	_optr = p;
-}
-
-VOID
-nflush() {			/* Flush output buffer, ignoring it */
-
-	_ocnt = OBUFSIZ;
-	_optr = _outbuf;
-}
-
-int
-fputch(ch) char ch; {		/* print a character */
-	putch(ch);
-}
-
-VOID
-putline(s) register char *s; {	/* Print string s */
-
-	if (!s) return;
-	while (*s) {
-		putch(*s++);
-	}
-}
-
-/*
- * A safe version of putline. All control characters are echoed as ^X
- */
-
-VOID
-cputline(s) char *s; {
-	register c;
-
-	while (c = *s++) {
-		if ((unsigned) c > 0177) c &= 0177;
-		if (c < ' ' || c == 0177) {
-			putch('^');
-			c ^= 0100;
-		}
-		putch(c);
-	}
-}
-
-/*
- * Simple minded routine to print a number
- */
-
-VOID
-prnum(n) long n; {
-
-	putline(getnum(n));
-}
-
-static char *
-fillnum(n, p)
-	long n;
-	char *p;
-{
-	if (n >= 10) {
-		p = fillnum(n / 10, p);
-	}
-	*p++ = (int) (n % 10) + '0';
-	*p = '\0';
-	return p;
-}
-
-char *
-getnum(n)
-	long n;
-{
-	static char buf[20];
-
-	fillnum(n, buf);
-	return buf;
-}
Index: trunk/minix/commands/yap/output.h
===================================================================
--- trunk/minix/commands/yap/output.h	(revision 9)
+++ 	(revision )
@@ -1,69 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/output.h,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $ */
-
-# ifndef _OUTPUT_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-PUBLIC int _ocnt;
-PUBLIC char *_optr;
-
-#define putch(ch)	if (1) {if (--_ocnt <= 0) flush(); *_optr++ = (ch);} else
-
-VOID	flush();
-/*
- * void flush()
- *
- * Write the output buffer to the screen
- */
-
-VOID	nflush();
-/*
- * void nflush()
- *
- * Clear output buffer, but do not write it
- */
-
-int	fputch();
-/*
- * int fputch(c)
- * int c;		The character to be printed
- *
- * Put character "c" in output buffer and flush if necessary.
- */
-
-VOID	putline();
-/*
- * void putline(s)
- * char *s;		The string to be printed
- *
- * Put string "s" in output buffer  etc...
- */
-
-VOID	cputline();
-/*
- * void cputline(s)
- * char *s;		The string to be handled
- *
- * Put string "s" in the output buffer, expanding control characters
- */
-
-VOID	prnum();
-/*
- * void prnum(n)
- * long n;		The number to be printed
- *
- * print the number "n", using putch.
- */
-
-char	*getnum();
-/*
- * char *getnum(n)
- * long n;		The number to be converted to a string
- *
- * Convert a number to a string and return a pointer to it.
- */
-# undef PUBLIC
Index: trunk/minix/commands/yap/pattern.c
===================================================================
--- trunk/minix/commands/yap/pattern.c	(revision 9)
+++ 	(revision )
@@ -1,160 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/pattern.c,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $";
-# endif not lint
-
-# define _PATTERN_
-
-# include "in_all.h"
-# include "pattern.h"
-# include "getline.h"
-
-# if V8_REGEX
-# include <regexp.h>
-# endif V8_REGEX
-
-/*
- * Interface to regular expression routines.
- * Also: simple minded patterns without meta-characters.
- */
-
-# if USG_REGEX
-static char *pattern;		/* Pointer to compiled pattern */
-char *regcmp(), *regex();
-# endif USG_REGEX
-# if V8_REGEX
-static struct regexp *pattern;
-static char *rc_error;
-struct regexp *regcomp();
-# endif V8_REGEX
-
-# if USG_REGEX || V8_REGEX
-/*
- * Compile a new pattern, but first free previous result.
- */
-
-char *
-re_comp(s) char *s; {
-
-	if (!*s) {
-		/*
-		 * user wants previous pattern
-		 */
-		return (char *) 0;
-	}
-	if (pattern) {
-		/*
-		 * there was a compiled pattern
-		 */
-		free(pattern);
-		pattern = 0;
-	}
-# if USG_REGEX
-	return (pattern = regcmp(s, (char *) 0)) ?
-		(char *) 0 :
-		"Error in pattern";
-# endif USG_REGEX
-# if V8_REGEX
-	pattern = regcomp(s);
-	if (pattern) return (char *) 0;
-	if (rc_error) return rc_error;
-	return "Error in pattern";
-# endif V8_REGEX
-}
-
-# if V8_REGEX
-VOID
-regerror(str) char *str; {
-	rc_error = str;
-}
-# endif V8_REGEX
-
-/*
- * Search for compiled pattern in string "s". Return 0 if not found.
- */
-
-re_exec(s) char *s; {
-
-# if USG_REGEX
-	return !(regex(pattern,s) == 0);
-# endif USG_REGEX
-# if V8_REGEX
-#  if _MINIX
-	return regexec(pattern,s,1);
-#  else
-	return regexec(pattern,s);
-#  endif
-# endif V8_REGEX
-}
-# else
-# ifndef BSD_REGEX
-/*
- * In this case, simple minded pattern search without meta-characters
- */
-
-char	*strcpy();
-
-static char *pattern;
-
-/*
- * re_comp : Just remember pattern.
- */
-
-char *
-re_comp(s) char *s; {
-
-	if (!*s) {
-		/*
-		 * User wants previous pattern
-		 */
-		if (!pattern) {
-			return "No previous regular expression";
-		}
-		return (char *) 0;
-	}
-	if (pattern) {
-		/*
-		 * Free old pattern
-		 */
-		free(pattern);
-	}
-	pattern = alloc((unsigned) (strlen(s) + 1), 0);
-	(VOID) strcpy(pattern,s);
-	return (char *) 0;
-}
-
-/*
- * re-exec : Simple minded pattern matcher
- */
-
-re_exec(s) register char *s; {
-
-	register char *ppat, *pstr;
-
-	for (; *s; s++) {
-		/*
-		 * As long as there are characters ...
-		 */
-		ppat = pattern; /* Try the pattern again */
-		pstr = s;
-		while (*ppat == *pstr) {
-			if (*++ppat == '\0') {
-				/*
-				 * The pattern matched! Report success
-				 */
-				return 1;
-			}
-			if (*++pstr == '\0') {
-				/*
-				 * Not enough characters left in the string.
-				 * Report failure
-				 */
-				return 0;
-			}
-		}
-	}
-	return 0;		/* Failure */
-}
-# endif not BSD_REGEX
-# endif
Index: trunk/minix/commands/yap/pattern.h
===================================================================
--- trunk/minix/commands/yap/pattern.h	(revision 9)
+++ 	(revision )
@@ -1,14 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/pattern.h,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $ */
-
-# ifndef _PATTERN_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-char *	re_comp();
-int	re_exec();
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/process.c
===================================================================
--- trunk/minix/commands/yap/process.c	(revision 9)
+++ 	(revision )
@@ -1,127 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/process.c,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $";
-# endif
-
-# define _PROCESS_
-
-# include "in_all.h"
-# if USG_OPEN
-# include <fcntl.h>
-# endif
-# if BSD4_2_OPEN
-# include <sys/file.h>
-# endif
-# if POSIX_OPEN
-# include <sys/types.h>
-# include <fcntl.h>
-# endif
-# include <sys/types.h>
-# include <sys/stat.h>
-# include "process.h"
-# include "commands.h"
-# include "display.h"
-# include "prompt.h"
-# include "getline.h"
-# include "main.h"
-# include "options.h"
-# include "output.h"
-
-static int nfiles;		/* Number of filenames on command line */
-
-/*
- * Visit a file, file name is "fn".
- */
-
-VOID
-visitfile(fn) char *fn; {
-	struct stat statbuf;
-
-	if (stdf > 0) {
-		/*
-		 * Close old input file
-		 */
-		(VOID) close(stdf);
-	}
-	currentfile = fn;
-# if USG_OPEN || BSD4_2_OPEN || POSIX_OPEN
-	if ((stdf = open(fn,O_RDONLY,0)) < 0) {
-# else
-	if ((stdf = open(fn,0)) < 0) {
-# endif
-		error(": could not open");
-		maxpos = 0;
-	}
-	else {	/* Get size for percentage in prompt */
-		(VOID) fstat(stdf, &statbuf);
-		maxpos = statbuf.st_size;
-	}
-	do_clean();
-	d_clean();
-}
-
-/*
- * process the input files, one by one.
- * If there is none, input is from a pipe.
- */
-
-VOID
-processfiles(n,argv) char ** argv; {
-
-	static char *dummies[3];
-	long arg;
-
-	if (!(nfiles = n)) {
-		/*
-		 * Input from pipe
-		 */
-		currentfile = "standard-input";
-		/*
-		 * Take care that *(filenames - 1) and *(filenames + 1) are 0
-		 */
-		filenames = &dummies[1];
-		d_clean();
-		do_clean();
-	}
-	else {
-		filenames = argv;
-		(VOID) nextfile(0);
-	}
-	*--argv = 0;
-	if (startcomm) {
-		n = getcomm(&arg);
-		if (commands[n].c_flags & NEEDS_SCREEN) {
-			redraw(0);
-		}
-		do_comm(n,arg);
-		startcomm = 0;
-	}
-	redraw(1);
-	if (setjmp(SetJmpBuf)) {
-		nflush();
-		redraw(1);
-	}
-	DoneSetJmp = 1;
-	for (;;) {
-		interrupt = 0;
-		n = getcomm(&arg);
-		do_comm(n, arg);
-	}
-}
-
-/*
- * Get the next file the user asks for.
- */
-
-int
-nextfile(n) {
-	register i;
-
-	if ((i = filecount + n) >= nfiles || i < 0) {
-		return 1;
-	}
-	filecount = i;
-	visitfile(filenames[i]);
-	return 0;
-}
Index: trunk/minix/commands/yap/process.h
===================================================================
--- trunk/minix/commands/yap/process.h	(revision 9)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/process.h,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $ */
-
-# ifndef _PROCESS_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-# include <setjmp.h>
-
-PUBLIC	jmp_buf	SetJmpBuf;
-PUBLIC	int DoneSetJmp;
-
-PUBLIC int	stdf;		/* input file descriptor */
-PUBLIC int	filecount;	/* index in filename table */
-PUBLIC char **	filenames;	/* the filenametable */
-PUBLIC char *	currentfile;	/* Name of current file */
-PUBLIC long	maxpos;		/* Size of file */
-
-VOID	visitfile();
-/*
- * void visitfile(fn)
- * char *fn;			name of file to be visited
- *
- * Opens the file "fn" and gives an error message if this fails.
- */
-
-VOID	processfiles();
-/*
- * void processfiles(n,argv)
- * int n;			number of files to be handled
- * char ** argv;		names of the files
- *
- * Does all the work according to the divide and conquer method
- */
-
-int	nextfile();
-/*
- * int nextfile(n)
- * int n;
- *
- * Visits n'th next file. If not there in argument list, return 1.
- * Otherwise return 0.
- */
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/prompt.c
===================================================================
--- trunk/minix/commands/yap/prompt.c	(revision 9)
+++ 	(revision )
@@ -1,193 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/prompt.c,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $";
-# endif
-
-# define _PROMPT_
-
-# include "in_all.h"
-# include "prompt.h"
-# include "term.h"
-# include "output.h"
-# include "options.h"
-# include "display.h"
-# include "process.h"
-# include "getline.h"
-# include "main.h"
-# include "getcomm.h"
-# include "keys.h"
-# include "assert.h"
-# include "commands.h"
-
-#define basename(x) x
-
-#ifndef basename
-STATIC char *	basename();
-#endif
-
-static char *errorgiven;	/* Set to error message, if there is one */
-
-char *
-copy(p, ep, s)
-	register char *p, *s;
-	char *ep;
-{
-	while (p < ep && *s) {
-		*p++ = *s++;
-	}
-	return p;
-}
-
-/*
- * display the prompt and refresh the screen.
- */
-
-VOID
-give_prompt() {
-
-	register char **name;
-	register struct scr_info *p = &scr_info;
-	char buf[256];
-	register char *pb = buf;
-
-	if (startcomm) return;
-	flush();
-	if (window()) {
-		redraw(0);
-		flush();
-	}
-	if (!stupid) {
-		/*
-		 * fancy prompt
-		 */
-		clrbline();
-		standout();
-		pb = copy(pb, &buf[255], basename(currentfile));
-		if (stdf >= 0) {
-			pb = copy(pb, &buf[255], ", ");
-			pb = copy(pb, &buf[255], getnum(p->firstline));
-			pb = copy(pb, &buf[255], "-");
-			pb = copy(pb, &buf[255], getnum(p->lastline));
-		}
-	}
-	else {
-		*pb++ = '\007';	/* Stupid terminal, stupid prompt */
-	}
-	if (errorgiven) {
-		/*
-		 * display error message
-		 */
-		pb = copy(pb, &buf[255], " ");
-		pb = copy(pb, &buf[255], errorgiven);
-		if (stupid) {
-			pb = copy(pb, &buf[255], "\r\n");
-		}
-		errorgiven = 0;
-	}
-	else if (!stupid && (status || maxpos)) {
-		pb = copy(pb, &buf[255], " (");
-		name = &filenames[filecount];
-		if (status) {
-			/*
-			 * indicate top and/or bottom
-			 */
-			if (status & START) {
-				if (!*(name - 1)) {
-					pb = copy(pb, &buf[255], "Top");
-				}
-				else {
-					pb = copy(pb, &buf[255], "Previous: ");
-					pb = copy(pb, &buf[255], basename(*(name - 1)));
-				}
-				if (status & EOFILE) {
-					pb = copy(pb, &buf[255], ", ");
-				}
-			}
-			if (status & EOFILE) {
-				if (!*(name+1)) {
-					pb = copy(pb, &buf[255], "Bottom");
-				}
-				else {
-					pb = copy(pb, &buf[255], "Next: ");
-					pb = copy(pb, &buf[255], basename(*(name + 1)));
-				}
-			}
-		}
-		else {	/* display percentage */
-			pb = copy(pb, &buf[255], getnum((100 * getpos(p->lastline))/maxpos));
-			pb = copy(pb, &buf[255], "%");
-		}
-		pb = copy(pb, &buf[255], ")");
-	}
-	*pb = '\0';
-	if (!stupid) {
-		buf[COLS-1] = 0;
-		putline(buf);
-		standend();
-	}
-	else	putline(buf);
-}
-
-/*
- * Remember error message
- */
-
-VOID
-error(str) char *str; {
-
-	errorgiven = str;
-}
-
-#ifndef basename
-STATIC char *
-basename(fn) char *fn; {	/* Return name without path */
-
-	register char *s;
-
-	s = fn;
-	while (*s++) ;		/* Search end of name */
-	for (;;) {
-		if (*--s == '/') {
-			/*
-			 * Backwards to first '/'
-			 */
-			if (*(s+1)) {
-				/*
-				 * There is a name after the '/'
-				 */
-				return s + 1;
-			}
-			*s = 0; /* No name after the '/' */
-		}
-		if (s == fn) return s;
-	}
-	/* NOTREACHED */
-}
-#endif
-
-VOID
-ret_to_continue() {		/* Obvious */
-	int c;
-	static char buf[2];
-
-	for (;;) {
-		clrbline();
-		standout();
-		if (errorgiven) {
-			putline(errorgiven);
-			putline(" ");
-			errorgiven = 0;
-		}
-		putline("[Type anything to continue]");
-		standend();
-		if (is_escape(c = getch())) {
-			buf[0] = c;
-			(VOID) match(buf, &c, currmap->k_mach);
-			assert(c > 0);
-			do_comm(c, -1L);
-		}
-		else	break;
-	}
-	clrbline();
-}
Index: trunk/minix/commands/yap/prompt.h
===================================================================
--- trunk/minix/commands/yap/prompt.h	(revision 9)
+++ 	(revision )
@@ -1,33 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/prompt.h,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $ */
-
-# ifndef _PROMPT_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-VOID	give_prompt();
-/*
- * void give_prompt()
- *
- * Displays a prompt, with possibly an error message
- */
-
-VOID	error();
-/*
- * void error(s)
- * char *s;		The error
- *
- * Takes care that there will be an error message in the next prompt.
- */
-
-VOID	ret_to_continue();
-/*
- * void ret_to_continue();
- *
- * Asks the user to type something before continuing.
- */
-
-# undef PUBLIC
Index: trunk/minix/commands/yap/term.c
===================================================================
--- trunk/minix/commands/yap/term.c	(revision 9)
+++ 	(revision )
@@ -1,487 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/*
- * Terminal handling routines, mostly initializing.
- */
-
-# ifndef lint
-static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/term.c,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $";
-# endif
-
-# define _TERM_
-
-#include "in_all.h"
-#include "term.h"
-#include "machine.h"
-#include "output.h"
-#include "display.h"
-#include "options.h"
-#include "getline.h"
-#include "keys.h"
-#include "main.h"
-
-#ifdef TIOCGWINSZ
-static struct winsize w;
-#endif
-
-char	*strcpy(),
-	*strcat(),
-	*tgoto(),
-	*tgetstr(),
-	*getenv();
-
-static char	tcbuf1[1024];	/* Holds terminal capability strings */
-static char *	ptc;		/* Pointer in it */
-static char	tcbuf[1024];	/* Another termcap buffer */
-short	ospeed;		/* Needed for tputs() */
-char	PC;		/* Needed for tputs() */
-char *	UP;		/* Needed for tgoto() */
-static char	*ll;
-
-struct linelist _X[100];	/* 100 is enough ? */
-
-# if USG_TTY
-static struct termio _tty,_svtty;
-# elif POSIX_TTY
-static struct termios _tty, _svtty;
-# else
-# ifdef TIOCSPGRP
-static int proc_id, saved_pgrpid;
-# endif
-static struct sgttyb _tty,_svtty;
-# ifdef TIOCGETC
-static struct tchars _ttyc, _svttyc;
-# endif
-# ifdef TIOCGLTC
-static int line_discipline;
-static struct ltchars _lttyc, _svlttyc;
-# endif
-# endif
-
-static VOID
-handle(c) char *c; {	/* if character *c is used, set it to undefined */
-
-	if (isused(*c)) *c = 0377;
-}
-
-/*
- * Set terminal in cbreak mode.
- * Also check if tabs need expanding.
- */
-
-VOID
-inittty() {
-# if USG_TTY
-	register struct termio *p = &_tty;
-
-	ioctl(0,TCGETA,(char *) p);
-	_svtty = *p;
-	if (p->c_oflag & TAB3) {
-		/*
-		 * We do tab expansion ourselves
-		 */
-		expandtabs = 1;
-	}
-	p->c_oflag &= ~(TAB3|OCRNL|ONLRET|ONLCR);
-	p->c_oflag |= (/*ONOCR|*/OPOST);	/* ONOCR does not seem to work
-						   very well in combination with
-						   ~ONLCR
-						*/
-	p->c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON);
-	if (isused('S'&037) || isused('Q'&037)) p->c_iflag &= ~IXON;
-	handle(&(p->c_cc[0]));	/* INTR and QUIT (mnemonics not defined ??) */
-	handle(&(p->c_cc[1]));
-	erasech = p->c_cc[VERASE];
-	killch = p->c_cc[VKILL];
-	p->c_cc[VMIN] = 1;	/* Just wait for one character */
-	p->c_cc[VTIME] = 0;
-	ospeed = p->c_cflag & CBAUD;
-	ioctl(0,TCSETAW,(char *) p);
-#elif POSIX_TTY
-	register struct termios *p = &_tty;
-
-	tcgetattr(0, p);
-	_svtty = *p;
-#ifdef _MINIX	/* Should be XTABS */
-	if (p->c_oflag & XTABS) {
-		/*
-		 * We do tab expansion ourselves
-		 */
-		expandtabs = 1;
-	}
-	p->c_oflag &= (OPOST|XTABS);
-#else
-	p->c_oflag &= ~OPOST;
-#endif
-	p->c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON);
-	if (isused('S'&037) || isused('Q'&037)) p->c_iflag &= ~IXON;
-	handle(&(p->c_cc[VINTR]));	
-	handle(&(p->c_cc[VQUIT]));
-	erasech = p->c_cc[VERASE];
-	killch = p->c_cc[VKILL];
-	p->c_cc[VMIN] = 1;	/* Just wait for one character */
-	p->c_cc[VTIME] = 0;
-	ospeed = cfgetospeed(p);
-	tcsetattr(0, TCSANOW, p);
-# else
-	register struct sgttyb *p = &_tty;
-
-# ifdef TIOCSPGRP
-	/*
-	 * If we can, we put yap in another process group, and the terminal
-	 * with it. This is done, so that interrupts given by the user
-	 * will only affect yap and not it's children (processes writing
-	 * on a pipe to yap)
-	 */
-	if (ioctl(0, TIOCSPGRP, (char *) &proc_id) != -1) {
-		setpgrp(0, proc_id);
-	}
-# endif
-	ioctl(0,TIOCGETP,(char *) p);
-	_svtty = *p;
-	erasech = p->sg_erase;
-	killch = p->sg_kill;
-	ospeed = p->sg_ospeed;
-	if (p->sg_flags & XTABS) {
-		/*
-		 * We do tab expansion ourselves
-		 */
-		expandtabs = 1;
-	}
-	p->sg_flags |= (CBREAK);
-	p->sg_flags &= ~(ECHO|XTABS|RAW|LCASE|CRMOD);
-#ifdef TIOCSETN
-	ioctl(0, TIOCSETN, (char *) p);
-#else
-	ioctl(0,TIOCSETP,(char *) p);
-#endif
-/* Bloody Sun ... */
-#undef t_startc
-#undef t_stopc
-#undef t_intrc
-#undef t_quitc
-#undef t_suspc
-#undef t_dsuspc
-#undef t_flushc
-#undef t_lnextc
-# ifdef TIOCGETC
-	{   register struct tchars *q = &_ttyc;
-
-		ioctl(0,TIOCGETC,(char *) q);
-		_svttyc = *q;
-		handle(&(q->t_intrc));
-		handle(&(q->t_quitc));
-		if (isused(q->t_startc) || isused(q->t_stopc)) {
-			q->t_startc = q->t_stopc = 0377;
-		}
-		ioctl(0,TIOCSETC, (char *) q);
-	}
-# endif
-# ifdef TIOCGLTC
-	{   register struct ltchars *q = &_lttyc;
-
-		ioctl(0,TIOCGETD,(char *) &line_discipline);
-		if (line_discipline == NTTYDISC) {
-			ioctl(0, TIOCGLTC,(char *) q);
-			_svlttyc = *q;
-			handle(&(q->t_suspc));
-			handle(&(q->t_dsuspc));
-			q->t_flushc = q->t_lnextc = 0377;
-			ioctl(0,TIOCSLTC, (char *) q);
-		}
-	}
-# endif
-# endif
-}
-
-/*
- * Reset the terminal to its original state
- */
-
-VOID
-resettty() {
-
-# if USG_TTY
-	ioctl(0,TCSETAW,(char *) &_svtty);
-# elif POSIX_TTY
-	tcsetattr(0, TCSANOW, &_svtty);
-# else
-# ifdef TIOCSPGRP
-	ioctl(0, TIOCSPGRP, (char *) &saved_pgrpid);
-	setpgrp(0, saved_pgrpid);
-# endif
-	ioctl(0,TIOCSETP,(char *) &_svtty);
-# ifdef TIOCGETC
-	ioctl(0,TIOCSETC, (char *) &_svttyc);
-# endif
-# ifdef TIOCGLTC
-	if (line_discipline == NTTYDISC) ioctl(0,TIOCSLTC, (char *) &_svlttyc);
-# endif
-# endif
-	putline(TE);
-	flush();
-}
-
-/*
- * Get terminal capability "cap".
- * If not present, return an empty string.
- */
-
-STATIC char *
-getcap(cap) char *cap; {
-	register char *s;
-
-	s = tgetstr(cap, &ptc);
-	if (!s) return "";
-	return s;
-}
-
-/*
- * Initialize some terminal-dependent stuff.
- */
-
-VOID
-ini_terminal() {
-
-	register char * s;
-	register struct linelist *lp, *lp1;
-	register i;
-	register UG, SG;
-	char tempbuf[20];
-	char *mb, *mh, *mr;	/* attributes */
-
-	initkeys();
-#if !_MINIX
-# ifdef TIOCSPGRP
-	proc_id = getpid();
-	ioctl(0,TIOCGPGRP, (char *) &saved_pgrpid);
-# endif
-#endif
-	inittty();
-	stupid = 1;
-	ptc = tcbuf1;
-	BC = "\b";
-	TA = "\t";
-	if (!(s = getenv("TERM"))) s = "dumb";
-	if (tgetent(tcbuf, s) <= 0) {
-		panic("No termcap entry");
-	}
-	stupid = 0;
-	hardcopy = tgetflag("hc");	/* Hard copy terminal?*/
-	PC = *(getcap("pc"));
-	if (*(s = getcap("bc"))) {
-		/*
-		 * Backspace if not ^H
-		 */
-		BC = s;
-	}
-	UP = getcap("up");		/* move up a line */
-	CE = getcap("ce");		/* clear to end of line */
-	CL = getcap("cl");		/* clear screen */
-	if (!*CL) cflag = 1;
-	TI = getcap("ti");		/* Initialization for CM */
-	TE = getcap("te");		/* end for CM */
-	CM = getcap("cm");		/* cursor addressing */
-	SR = getcap("sr");		/* scroll reverse */
-	AL = getcap("al");		/* Insert line */
-	SO = getcap("so");		/* standout */
-	SE = getcap("se");		/* standend */
-	SG = tgetnum("sg");		/* blanks left by SO, SE */
-	if (SG < 0) SG = 0;
-	US = getcap("us");		/* underline */
-	UE = getcap("ue");		/* end underline */
-	UG = tgetnum("ug");		/* blanks left by US, UE */
-	if (UG < 0) UG = 0;
-	UC = getcap("uc");		/* underline a character */
-	mb = getcap("mb");		/* blinking attribute */
-	MD = getcap("md");		/* bold attribute */
-	ME = getcap("me");		/* turn off attributes */
-	mh = getcap("mh");		/* half bright attribute */
-	mr = getcap("mr");		/* reversed video attribute */
-	if (!nflag) {
-		/*
-		 * Recognize special strings
-		 */
-		(VOID) addstring(SO,SG,&sppat);
-		(VOID) addstring(SE,SG,&sppat);
-		(VOID) addstring(US,UG,&sppat);
-		(VOID) addstring(UE,UG,&sppat);
-		(VOID) addstring(mb,0,&sppat);
-		(VOID) addstring(MD,0,&sppat);
-		(VOID) addstring(ME,0,&sppat);
-		(VOID) addstring(mh,0,&sppat);
-		(VOID) addstring(mr,0,&sppat);
-		if (*UC) {
-			(VOID) strcpy(tempbuf,BC);
-			(VOID) strcat(tempbuf,UC);
-			(VOID) addstring(tempbuf,0,&sppat);
-		}
-	}
-	if (UG > 0 || uflag) {
-		US = "";
-		UE = "";
-	}
-	if (*US || uflag) UC = "";
-	COLS = tgetnum("co");		/* columns on page */
-	i = tgetnum("li");		/* Lines on page */
-	AM = tgetflag("am");		/* terminal wraps automatically? */
-	XN = tgetflag("xn");		/* and then ignores next newline? */
-	DB = tgetflag("db");		/* terminal retains lines below */
-	if (!*(s = getcap("ho")) && *CM) {
-		s = tgoto(CM,0,0);	/* Another way of getting home */
-	}
-	if ((!*CE && !*AL) || !*s || hardcopy) {
-		cflag = stupid = 1;
-	}
-	(VOID) strcpy(HO,s);
-	if (*(s = getcap("ta"))) {
-		/*
-		 * Tab (other than ^I or padding)
-		 */
-		TA = s;
-	}
-       if (!*(ll = getcap("ll")) && *CM && i > 0) {
-		/*
-		 * Lower left hand corner
-		 */
-               (VOID) strcpy(BO, tgoto(CM,0,i-1));
-	}
-       else    (VOID) strcpy(BO, ll);
-	if (COLS <= 0 || COLS > 256) {
-		if ((unsigned) COLS >= 65409) {
-			/* SUN bug */
-			COLS &= 0xffff;
-			COLS -= (65409 - 128);
-		}
-		if (COLS <= 0 || COLS > 256) COLS = 80;
-	}
-	if (i <= 0) {
-		i = 24;
-		cflag = stupid = 1;
-	}
-	LINES = i;
-	maxpagesize = i - 1;
-	scrollsize = maxpagesize / 2;
-	if (scrollsize <= 0) scrollsize = 1;
-	if (!pagesize || pagesize >= i) {
-		pagesize = maxpagesize;
-	}
-
-	/*
-	 * The next part does not really belong here, but there it is ...
-	 * Initialize a circular list for the screenlines.
-	 */
-
-       scr_info.tail = lp = _X;
-       lp1 = lp + (100 - 1);
-	for (; lp <= lp1; lp++) {
-		/*
-		 * Circular doubly linked list
-		 */
-		lp->next = lp + 1;
-		lp->prev = lp - 1;
-	}
-       lp1->next = scr_info.tail;
-	lp1->next->prev = lp1;
-	if (stupid) {
-		(VOID) strcpy(BO,"\r\n");
-	}
-	putline(TI);
-	window();
-}
-
-/*
- * Place cursor at start of line n.
- */
-
-VOID
-mgoto(n) register n; {
-
-	if (n == 0) home();
-	else if (n == maxpagesize && *BO) bottom();
-	else if (*CM) {
-		/*
-		 * Cursor addressing
-		 */
-		tputs(tgoto(CM,0,n),1,fputch);
-	}
-	else if (*BO && *UP && n >= (maxpagesize >> 1)) {
-		/*
-		 * Bottom and then up
-		 */
-		bottom();
-		while (n++ < maxpagesize) putline(UP);
-	}
-	else {	/* Home, and then down */
-		home();
-		while (n--) putline("\r\n");
-	}
-}
-
-/*
- * Clear bottom line
- */
-
-VOID
-clrbline() {
-
-	if (stupid) {
-		putline("\r\n");
-		return;
-	}
-	bottom();
-	if (*CE) {
-		/*
-		 * We can clear to end of line
-		 */
-		clrtoeol();
-		return;
-	}
-# ifdef VT100_PATCH
-	insert_line(maxpagesize);
-# else
-	insert_line();
-# endif
-}
-
-# ifdef VT100_PATCH
-ins_line(l) {
-	tputs(tgoto(AL, l, 0), maxpagesize - l, fputch);
-}
-# endif
-
-VOID
-home() {
-
-	tputs(HO,1,fputch);
-}
-
-VOID
-bottom() {
-
-	tputs(BO,1,fputch);
-	if (!*BO) mgoto(maxpagesize);
-}
-
-int
-window()
-{
-#ifdef TIOCGWINSZ
-        if (ioctl(1, TIOCGWINSZ, &w) < 0) return 0;
-
-        if (w.ws_col == 0) w.ws_col = COLS;
-        if (w.ws_row == 0) w.ws_row = LINES;
-        if (w.ws_col != COLS || w.ws_row != LINES) {
-		COLS = w.ws_col;
-		LINES = w.ws_row;
-		maxpagesize = LINES - 1;
-		pagesize = maxpagesize;
-		if (! *ll) (VOID) strcpy(BO, tgoto(CM,0,maxpagesize));
-		scr_info.currentpos = 0;
-		scrollsize = maxpagesize / 2; 
-		if (scrollsize <= 0) scrollsize = 1;
-		return 1;
-        }
-#endif
-        return 0;
-}
Index: trunk/minix/commands/yap/term.h
===================================================================
--- trunk/minix/commands/yap/term.h	(revision 9)
+++ 	(revision )
@@ -1,137 +1,0 @@
-/* Copyright (c) 1985 Ceriel J.H. Jacobs */
-
-/* $Header: /cvsup/minix/src/commands/yap/term.h,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $ */
-
-/* All terminal and terminal dependent stuff */
-
-# ifndef _TERM_
-# define PUBLIC extern
-# else
-# define PUBLIC
-# endif
-
-# if USG_TTY
-# include <termio.h>
-# elif POSIX_TTY
-# include <termios.h>
-# else
-# include <sgtty.h>
-# endif
-
-#include <sys/types.h>
-#include <signal.h>
-#include <sys/ioctl.h>
-
-/* Terminal setting */
-
-PUBLIC int expandtabs;		/* Tabs need expanding? */
-PUBLIC int stupid;		/* Stupid terminal */
-PUBLIC int hardcopy;		/* Hardcopy terminal */
-
-/* termcap stuff */
-PUBLIC
-char	*CE,			/* clear to end of line */
-	*CL,			/* clear screen */
-	*SO,			/* stand out */
-	*SE,			/* stand end */
-	*US,			/* underline start */
-	*UE,			/* underline end */
-	*UC,			/* underline character */
-	*MD,			/* bold start */
-	*ME,			/* attributes (like bold) off */
-	*TI,			/* initialize for CM */
-	*TE,			/* End of CM */
-	*CM,			/* Cursor addressing */
-	*TA,			/* Tab */
-	*SR,			/* Scroll reverse */
-	*AL;			/* insert line */
-PUBLIC
-int	LINES,			/* # of lines on screen */
-	COLS,			/* # of colums */
-	AM,			/* Automatic margins */
-	XN,			/* newline ignored after wrap */
-	DB;			/* terminal retains lines below */
-PUBLIC
-char	HO[20],			/* Sequence to get to home position */
-	BO[20];			/* sequence to get to lower left hand corner */
-PUBLIC
-int	erasech,		/* users erase character */
-	killch;			/* users kill character */
-PUBLIC struct state *sppat;	/* Special patterns to be recognized */
-PUBLIC char
-	*BC;			/* Back space */
-
-#define backspace()	putline(BC)
-#define clrscreen()	tputs(CL,LINES,fputch)
-#define clrtoeol()	tputs(CE,1,fputch)
-#define scrollreverse()	tputs(SR,LINES,fputch)
-#ifdef VT100_PATCH
-#define insert_line(l)	ins_line(l)
-#define standout()	tputs(SO,1,fputch)
-#define standend()	tputs(SE,1,fputch)
-#define underline()	tputs(US,1,fputch)
-#define end_underline() tputs(UE,1,fputch)
-#define bold()		tputs(MD,1,fputch)
-#define end_bold()	tputs(ME,1,fputch)
-#define underchar()	tputs(UC,1,fputch)
-# else
-#define insert_line()	tputs(AL,LINES,fputch)
-#define standout()	putline(SO)
-#define standend()	putline(SE)
-#define underline()	putline(US)
-#define end_underline() putline(UE)
-#define bold()		putline(MD)
-#define end_bold()	putline(ME)
-#define underchar()	putline(UC)
-# endif
-#define givetab()	tputs(TA,1,fputch)
-
-VOID	inittty();
-/*
- * void inittty()
- *
- * Initialises the terminal (sets it in cbreak mode, etc)
- */
-
-VOID	resettty();
-/*
- * void resettty()
- *
- * resets the terminal to the mode in which it was before yap was invoked
- */
-
-VOID	ini_terminal();
-/*
- * void ini_terminal()
- *
- * Handles the termcap entry for your terminal. In some cases, the terminal
- * will be considered stupid.
- */
-
-VOID	mgoto();
-/*
- * void mgoto(n)
- * int n;		Line to go to
- *
- * Put the cursor at the start of the n'th screen line.
- * This can be done in several ways (of course).
- */
-
-VOID	clrbline();
-/*
- * void clrbline()
- *
- * clears the bottom line, by either clearing it to end of line,
- * or pushing it of the screen by inserting a line before it.
- */
-
-VOID	home();
-VOID	bottom();
-/*
- * Obvious
- */
-
-#ifdef WINDOW
-int	window();
-#endif
-# undef PUBLIC
Index: trunk/minix/commands/zmodem/Makefile
===================================================================
--- trunk/minix/commands/zmodem/Makefile	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-# Makefile for zmodem
-
-all: rz sz
-
-CC = exec cc
-CFLAGS= -DPOSIX -D_MINIX -D_POSIX_SOURCE -O -wo
-
-rz: rz.c rbsb.c zm.c zmodem.h
-	$(CC) $(CFLAGS) -i -o rz rz.c
-	install -S 5kw $@
-
-sz: sz.c rbsb.c zm.c zmodem.h
-	$(CC) $(CFLAGS) -i -o sz sz.c
-	install -S 5kw $@
-
-install:	/usr/bin/rz /usr/bin/sz
-
-/usr/bin/rz:	rz
-	install -cs -o bin rz $@
-
-/usr/bin/sz:	sz
-	install -cs -o bin sz $@
-
-clean:	
-	rm -f *.bak *.o core rz sz
Index: trunk/minix/commands/zmodem/build
===================================================================
--- trunk/minix/commands/zmodem/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/zmodem/crctab.c
===================================================================
--- trunk/minix/commands/zmodem/crctab.c	(revision 9)
+++ 	(revision )
@@ -1,140 +1,0 @@
-/*
- *  Crc calculation stuff
- */
-
-/* crctab calculated by Mark G. Mendel, Network Systems Corporation */
-static unsigned short crctab[256] = {
-    0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,
-    0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,
-    0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,
-    0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,
-    0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,
-    0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,
-    0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,
-    0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,
-    0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,
-    0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,
-    0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,
-    0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,
-    0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,
-    0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,
-    0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,
-    0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,
-    0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,
-    0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,
-    0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,
-    0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,
-    0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,
-    0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,
-    0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,
-    0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,
-    0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,
-    0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,
-    0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,
-    0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,
-    0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,
-    0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,
-    0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,
-    0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0
-};
-
-/*
- * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
- *  NOTE: First srgument must be in range 0 to 255.
- *        Second argument is referenced twice.
- * 
- * Programmers may incorporate any or all code into their programs, 
- * giving proper credit within the source. Publication of the 
- * source routines is permitted so long as proper credit is given 
- * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, 
- * Omen Technology.
- */
-
-#define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
-
-/*
- * Copyright (C) 1986 Gary S. Brown.  You may use this program, or
- * code or tables extracted from it, as desired without restriction.
- */
-
-/* First, the polynomial itself and its table of feedback terms.  The  */
-/* polynomial is                                                       */
-/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
-/* Note that we take it "backwards" and put the highest-order term in  */
-/* the lowest-order bit.  The X^32 term is "implied"; the LSB is the   */
-/* X^31 term, etc.  The X^0 term (usually shown as "+1") results in    */
-/* the MSB being 1.                                                    */
-
-/* Note that the usual hardware shift register implementation, which   */
-/* is what we're using (we're merely optimizing it by doing eight-bit  */
-/* chunks at a time) shifts bits into the lowest-order term.  In our   */
-/* implementation, that means shifting towards the right.  Why do we   */
-/* do it this way?  Because the calculated CRC must be transmitted in  */
-/* order from highest-order term to lowest-order term.  UARTs transmit */
-/* characters in order from LSB to MSB.  By storing the CRC this way,  */
-/* we hand it to the UART in the order low-byte to high-byte; the UART */
-/* sends each low-bit to hight-bit; and the result is transmission bit */
-/* by bit from highest- to lowest-order term without requiring any bit */
-/* shuffling on our part.  Reception works similarly.                  */
-
-/* The feedback terms table consists of 256, 32-bit entries.  Notes:   */
-/*                                                                     */
-/*     The table can be generated at runtime if desired; code to do so */
-/*     is shown later.  It might not be obvious, but the feedback      */
-/*     terms simply represent the results of eight shift/xor opera-    */
-/*     tions for all combinations of data and CRC register values.     */
-/*                                                                     */
-/*     The values must be right-shifted by eight bits by the "updcrc"  */
-/*     logic; the shift must be unsigned (bring in zeroes).  On some   */
-/*     hardware you could probably optimize the shift in assembler by  */
-/*     using byte-swap instructions.                                   */
-
-static long cr3tab[] = { /* CRC polynomial 0xedb88320 */
-0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
-0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
-0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
-0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
-0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
-0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
-0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
-0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
-0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
-0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
-0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
-0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
-0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
-0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
-0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
-0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
-0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
-0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
-0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
-0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
-0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
-0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
-0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
-0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
-0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
-0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
-0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
-0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
-0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
-0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
-0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
-0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
-};
-
-#ifdef NFGM
-long
-UPDC32(b, c)
-long c;
-{
-	return (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF));
-}
-
-#else
-
-#define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF))
-#endif
-
-/* End of crctab.c */
Index: trunk/minix/commands/zmodem/rbsb.c
===================================================================
--- trunk/minix/commands/zmodem/rbsb.c	(revision 9)
+++ 	(revision )
@@ -1,421 +1,0 @@
-/*
- *
- *  Rev 05-05-1988
- *  This file contains Unix specific code for setting terminal modes,
- *  very little is specific to ZMODEM or YMODEM per se (that code is in
- *  sz.c and rz.c).  The CRC-16 routines used by XMODEM, YMODEM, and ZMODEM
- *  are also in this file, a fast table driven macro version
- *
- *	V7/BSD HACKERS:  SEE NOTES UNDER mode(2) !!!
- *
- *   This file is #included so the main file can set parameters such as HOWMANY.
- *   See the main files (rz.c/sz.c) for compile instructions.
- */
-
-#ifdef V7
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sgtty.h>
-#define OS "V7/BSD"
-#ifdef LLITOUT
-long Locmode;		/* Saved "local mode" for 4.x BSD "new driver" */
-long Locbit = LLITOUT;	/* Bit SUPPOSED to disable output translations */
-#include <strings.h>
-#endif
-#endif
-
-#ifdef POSIX
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <termios.h>
-#define OS "POSIX"
-#endif
-
-#ifndef OS
-#ifndef USG
-#define USG
-#endif
-#endif
-
-#ifdef USG
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <termio.h>
-#include <sys/ioctl.h>
-#define OS "SYS III/V"
-#define MODE2OK
-#include <string.h>
-#endif
-
-#include "zmodem.h"
-
-_PROTOTYPE(static unsigned getspeed , (int code ));
-
-#if HOWMANY  > 255
-Howmany must be 255 or less
-#endif
-
-/*
- * return 1 iff stdout and stderr are different devices
- *  indicating this program operating with a modem on a
- *  different line
- */
-int Fromcu;		/* Were called from cu or yam */
-
-void from_cu()
-{
-	struct stat a, b;
-
-	fstat(1, &a); fstat(2, &b);
-	Fromcu = a.st_rdev != b.st_rdev;
-	return;
-}
-
-void cucheck()
-{
-	if (Fromcu)
-		fprintf(stderr,"Please read the manual page BUGS chapter!\r\n");
-}
-
-
-struct {
-	unsigned baudr;
-	int speedcode;
-} speeds[] = {
-	110,	B110,
-	300,	B300,
-#ifdef B600
-	600,	B600,
-#endif
-	1200,	B1200,
-	2400,	B2400,
-	4800,	B4800,
-	9600,	B9600,
-#ifdef EXTA
-	19200,	EXTA,
-	38400,	EXTB,
-#endif
-	0,
-};
-
-int Twostop;		/* Use two stop bits */
-
-
-#ifndef READCHECK
-#ifdef FIONREAD
-#define READCHECK
-/*
- *  Return non 0 iff something to read from io descriptor f
- */
-int rdchk(f)
-{
-	static long lf;
-
-	ioctl(f, FIONREAD, &lf);
-	return ((int) lf);
-}
-#endif
-#ifdef SV
-#define READCHECK
-#include <fcntl.h>
-
-char checked = '\0' ;
-/*
- * Nonblocking I/O is a bit different in System V, Release 2
- */
-int rdchk(f)
-{
-	int lf, savestat;
-
-	savestat = fcntl(f, F_GETFL) ;
-	fcntl(f, F_SETFL, savestat | O_NDELAY) ;
-	lf = read(f, &checked, 1) ;
-	fcntl(f, F_SETFL, savestat) ;
-	return(lf) ;
-}
-#endif
-#endif
-
-
-static unsigned
-getspeed(code)
-int code;
-{
-	register n;
-
-	for (n=0; speeds[n].baudr; ++n)
-		if (speeds[n].speedcode == code)
-			return speeds[n].baudr;
-	return 38400;	/* Assume fifo if ioctl failed */
-}
-
-
-
-#ifdef POSIX
-struct termios oldtty, tty;
-#else
-#ifdef ICANON
-struct termio oldtty, tty;
-#else
-struct sgttyb oldtty, tty;
-struct tchars oldtch, tch;
-#endif
-#endif
-
-int iofd = 0;		/* File descriptor for ioctls & reads */
-
-/*
- * mode(n)
- *  3: save old tty stat, set raw mode with flow control
- *  2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
- *  1: save old tty stat, set raw mode 
- *  0: restore original tty mode
- */
-int mode(n)
-int n;
-{
-	static did0 = FALSE;
-
-	vfile("mode:%d", n);
-	switch(n) {
-#ifdef POSIX
-	case 2:		/* Un-raw mode used by sz, sb when -g detected */
-		if(!did0)
-			(void) tcgetattr(iofd, &oldtty);
-		tty = oldtty;
-
-		tty.c_iflag = BRKINT|IXON;
-
-		tty.c_oflag = 0;	/* Transparent output */
-
-		tty.c_cflag &= ~PARENB;	/* Disable parity */
-		tty.c_cflag |= CS8;	/* Set character size = 8 */
-		if (Twostop)
-			tty.c_cflag |= CSTOPB;	/* Set two stop bits */
-
-
-		tty.c_lflag = ISIG;
-		tty.c_cc[VINTR] = Zmodem ? 03:030;	/* Interrupt char */
-		tty.c_cc[VQUIT] = -1;			/* Quit char */
-		tty.c_cc[VMIN] = 3;	 /* This many chars satisfies reads */
-		tty.c_cc[VTIME] = 1;	/* or in this many tenths of seconds */
-
-		(void) tcsetattr(iofd, TCSANOW, &tty);
-		did0 = TRUE;
-		return OK;
-	case 1:
-	case 3:
-		if(!did0)
-			(void) tcgetattr(iofd, &oldtty);
-		tty = oldtty;
-
-		tty.c_iflag = n==3 ? (IGNBRK|IXOFF) : IGNBRK;
-
-		 /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */
-		tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
-
-		tty.c_oflag = 0;	/* Transparent output */
-
-		tty.c_cflag &= ~PARENB;	/* Same baud rate, disable parity */
-		tty.c_cflag |= CS8;	/* Set character size = 8 */
-		if (Twostop)
-			tty.c_cflag |= CSTOPB;	/* Set two stop bits */
-		tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */
-		tty.c_cc[VTIME] = 1;	/* or in this many tenths of seconds */
-		(void) tcsetattr(iofd, TCSANOW, &tty);
-		did0 = TRUE;
-		Baudrate = cfgetospeed(&tty);
-		return OK;
-#endif
-#ifdef USG
-	case 2:		/* Un-raw mode used by sz, sb when -g detected */
-		if(!did0)
-			(void) ioctl(iofd, TCGETA, &oldtty);
-		tty = oldtty;
-
-		tty.c_iflag = BRKINT|IXON;
-
-		tty.c_oflag = 0;	/* Transparent output */
-
-		tty.c_cflag &= ~PARENB;	/* Disable parity */
-		tty.c_cflag |= CS8;	/* Set character size = 8 */
-		if (Twostop)
-			tty.c_cflag |= CSTOPB;	/* Set two stop bits */
-
-
-#ifdef READCHECK
-		tty.c_lflag = Zmodem ? 0 : ISIG;
-		tty.c_cc[VINTR] = Zmodem ? -1:030;	/* Interrupt char */
-#else
-		tty.c_lflag = ISIG;
-		tty.c_cc[VINTR] = Zmodem ? 03:030;	/* Interrupt char */
-#endif
-		tty.c_cc[VQUIT] = -1;			/* Quit char */
-#ifdef NFGVMIN
-		tty.c_cc[VMIN] = 1;
-#else
-		tty.c_cc[VMIN] = 3;	 /* This many chars satisfies reads */
-#endif
-		tty.c_cc[VTIME] = 1;	/* or in this many tenths of seconds */
-
-		(void) ioctl(iofd, TCSETAW, &tty);
-		did0 = TRUE;
-		return OK;
-	case 1:
-	case 3:
-		if(!did0)
-			(void) ioctl(iofd, TCGETA, &oldtty);
-		tty = oldtty;
-
-		tty.c_iflag = n==3 ? (IGNBRK|IXOFF) : IGNBRK;
-
-		 /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */
-		tty.c_lflag &= ~(ECHO | ICANON | ISIG);
-
-		tty.c_oflag = 0;	/* Transparent output */
-
-		tty.c_cflag &= ~PARENB;	/* Same baud rate, disable parity */
-		tty.c_cflag |= CS8;	/* Set character size = 8 */
-		if (Twostop)
-			tty.c_cflag |= CSTOPB;	/* Set two stop bits */
-#ifdef NFGVMIN
-		tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */
-#else
-		tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */
-#endif
-		tty.c_cc[VTIME] = 1;	/* or in this many tenths of seconds */
-		(void) ioctl(iofd, TCSETAW, &tty);
-		did0 = TRUE;
-		Baudrate = getspeed(tty.c_cflag & CBAUD);
-		return OK;
-#endif
-#ifdef V7
-	/*
-	 *  NOTE: this should transmit all 8 bits and at the same time
-	 *   respond to XOFF/XON flow control.  If no FIONREAD or other
-	 *   READCHECK alternative, also must respond to INTRRUPT char
-	 *   This doesn't work with V7.  It should work with LLITOUT,
-	 *   but LLITOUT was broken on the machine I tried it on.
-	 */
-	case 2:		/* Un-raw mode used by sz, sb when -g detected */
-		if(!did0) {
-#ifdef TIOCEXCL
-			ioctl(iofd, TIOCEXCL, 0);
-#endif
-			ioctl(iofd, TIOCGETP, &oldtty);
-			ioctl(iofd, TIOCGETC, (struct sgttyb *) &oldtch);
-#ifdef LLITOUT
-			ioctl(iofd, TIOCLGET, &Locmode);
-#endif
-		}
-		tty = oldtty;
-		tch = oldtch;
-#ifdef READCHECK
-		tch.t_intrc = Zmodem ? -1:030;	/* Interrupt char */
-#else
-		tch.t_intrc = Zmodem ? 03:030;	/* Interrupt char */
-#endif
-#ifdef ODDP
-		tty.sg_flags |= ODDP;
-#endif
-#ifdef EVENP
-		tty.sg_flags |= EVENP;
-#endif
-#ifdef CBREAK
-		tty.sg_flags |= CBREAK;
-#endif
-#ifdef ALLDELAY
-		tty.sg_flags &= ~ALLDELAY;
-#endif
-#ifdef CRMOD
-		tty.sg_flags &= ~CRMOD;
-#endif
-#ifdef ECHO
-		tty.sg_flags &= ~ECHO;
-#endif
-#ifdef LCASE
-		tty.sg_flags &= ~LCASE;
-#endif
-
-		ioctl(iofd, TIOCSETP, &tty);
-		ioctl(iofd, TIOCSETC, (struct sgttyb *) &tch);
-#ifdef LLITOUT
-		ioctl(iofd, TIOCLBIS, &Locbit);
-#endif
-		bibi(99);	/* un-raw doesn't work w/o lit out */
-		did0 = TRUE;
-		return OK;
-	case 1:
-	case 3:
-		if(!did0) {
-#ifdef TIOCEXCL
-			ioctl(iofd, TIOCEXCL, 0);
-#endif
-			ioctl(iofd, TIOCGETP, &oldtty);
-			ioctl(iofd, TIOCGETC, (struct sgttyb *) &oldtch);
-#ifdef LLITOUT
-			ioctl(iofd, TIOCLGET, &Locmode);
-#endif
-		}
-		tty = oldtty;
-		tty.sg_flags |= RAW;
-		tty.sg_flags &= ~ECHO;
-		ioctl(iofd, TIOCSETP, &tty);
-		did0 = TRUE;
-		Baudrate = getspeed(tty.sg_ospeed);
-		return OK;
-#endif
-	case 0:
-		if(!did0)
-			return ERROR;
-#ifdef POSIX
-		/* Wait for output to drain, flush input queue, restore
-		 * modes and restart output.
-		 */
-		(void) tcsetattr(iofd, TCSAFLUSH, &oldtty);
-		(void) tcflow(iofd, TCOON);
-#endif
-#ifdef USG
-		(void) ioctl(iofd, TCSBRK, 1);	/* Wait for output to drain */
-		(void) ioctl(iofd, TCFLSH, 1);	/* Flush input queue */
-		(void) ioctl(iofd, TCSETAW, &oldtty);	/* Restore modes */
-		(void) ioctl(iofd, TCXONC,1);	/* Restart output */
-#endif
-#ifdef V7
-		ioctl(iofd, TIOCSETP, &oldtty);
-		ioctl(iofd, TIOCSETC, (struct sgttyb *) &oldtch);
-#ifdef TIOCNXCL
-		ioctl(iofd, TIOCNXCL, 0);
-#endif
-#ifdef LLITOUT
-		ioctl(iofd, TIOCLSET, &Locmode);
-#endif
-#endif
-
-		return OK;
-	default:
-		return ERROR;
-	}
-}
-
-void sendbrk()
-{
-#ifdef POSIX
-	tcsendbreak(iofd, 1);
-#endif
-#ifdef V7
-#ifdef TIOCSBRK
-#define CANBREAK
-	sleep(1);
-	ioctl(iofd, TIOCSBRK, 0);
-	sleep(1);
-	ioctl(iofd, TIOCCBRK, 0);
-#endif
-#endif
-#ifdef USG
-#define CANBREAK
-	ioctl(iofd, TCSBRK, 0);
-#endif
-}
-
-/* End of rbsb.c */
Index: trunk/minix/commands/zmodem/rz.c
===================================================================
--- trunk/minix/commands/zmodem/rz.c	(revision 9)
+++ 	(revision )
@@ -1,1549 +1,0 @@
-#define VERSION "2.03 05-17-88"
-#define PUBDIR "/usr/spool/uucppublic"
-
-/*% cc -compat -M2 -Ox -K -i -DMD -DOMEN % -o rz; size rz;
-<-xtx-*> cc386 -Ox -DMD -DOMEN -DSEGMENTS=8 rz.c -o $B/rz;  size $B/rz
- *
- * rz.c By Chuck Forsberg
- *
- *	cc -O rz.c -o rz		USG (3.0) Unix
- * 	cc -O -DV7  rz.c -o rz		Unix V7, BSD 2.8 - 4.3
- *
- *	ln rz rb;  ln rz rx			For either system
- *
- *	ln rz /usr/bin/rzrmail		For remote mail.  Make this the
- *					login shell. rzrmail then calls
- *					rmail(1) to deliver mail.
- *
- * To compile on VMS:
- *
- *	define LNK$LIBRARY   SYS$LIBRARY:VAXCRTL.OLB
- *	cc rz.c
- *	cc vvmodem.c
- *	link rz,vvmodem
- *	rz :== $disk:[username.subdir]rz.exe
- *
- *
- *  Unix is a trademark of Western Electric Company
- *
- * A program for Unix to receive files and commands from computers running
- *  Professional-YAM, PowerCom, YAM, IMP, or programs supporting XMODEM.
- *  rz uses Unix buffered input to reduce wasted CPU time.
- *
- * Iff the program is invoked by rzCOMMAND, output is piped to 
- * "COMMAND filename"  (Unix only)
- *
- *  Some systems (Venix, Coherent, Regulus) may not support tty raw mode
- *  read(2) the same way as Unix. ONEREAD must be defined to force one
- *  character reads for these systems. Added 7-01-84 CAF
- *
- *  Alarm signal handling changed to work with 4.2 BSD 7-15-84 CAF 
- *
- *  BIX added 6-30-87 to support BIX(TM) upload protocol used by the
- *  Byte Information Exchange.
- *
- *  NFGVMIN Updated 2-18-87 CAF for Xenix systems where c_cc[VMIN]
- *  doesn't work properly (even though it compiles without error!),
- *
- *  SEGMENTS=n added 2-21-88 as a model for CP/M programs
- *    for CP/M-80 systems that cannot overlap modem and disk I/O.
- *
- *  VMS flavor hacks begin with rz version 2.00
- *
- *  -DMD may be added to compiler command line to compile in
- *    Directory-creating routines from Public Domain TAR by John Gilmore
- *
- *  HOWMANY may be tuned for best performance
- *
- *  USG UNIX (3.0) ioctl conventions courtesy  Jeff Martin
- */
-
-#include <sys/types.h>
-
-#ifdef vax11c
-#include <types.h>
-#include <stat.h>
-#define LOGFILE "rzlog.tmp"
-#define OS "VMS"
-#define BUFREAD
-extern int errno;
-#define SS_NORMAL SS$_NORMAL
-#else
-/* Not vax11c */
-#define SS_NORMAL 0
-#define LOGFILE "/tmp/rzlog"
-#endif
-
-#include <time.h>
-#include <ctype.h>
-#include <errno.h>
-#include <signal.h>
-#include <setjmp.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <utime.h>
-#include <stdio.h>
-
-#define OK 0
-#define FALSE 0
-#define TRUE 1
-#undef ERROR
-#define ERROR (-1)
-
-
-_PROTOTYPE(long getfree , (void));
-_PROTOTYPE(void alrm , (int sig ));
-_PROTOTYPE(int main , (int argc , char *argv []));
-_PROTOTYPE(int usage , (void));
-_PROTOTYPE(int wcreceive , (int argc , char **argp ));
-_PROTOTYPE(int wcrxpn , (char *rpn ));
-_PROTOTYPE(int wcrx , (void));
-_PROTOTYPE(int wcgetsec , (char *rxbuf , int maxtime ));
-_PROTOTYPE(int readline , (int timeout ));
-_PROTOTYPE(void purgeline , (void));
-_PROTOTYPE(int procheader , (char *name ));
-_PROTOTYPE(int make_dirs , (char *pathname ));
-_PROTOTYPE(int makedir , (char *dpath , int dmode ));
-_PROTOTYPE(int putsec , (char *buf , int n ));
-_PROTOTYPE(void sendline , (int c ));
-_PROTOTYPE(void flushmo , (void));
-_PROTOTYPE(void uncaps , (char *s ));
-_PROTOTYPE(int IsAnyLower , (char *s ));
-_PROTOTYPE(char *substr , (char *s , char *t ));
-void zperr();
-_PROTOTYPE(void canit , (void));
-_PROTOTYPE(void report , (int sct ));
-_PROTOTYPE(void chkinvok , (char *s ));
-_PROTOTYPE(void checkpath , (char *name ));
-_PROTOTYPE(int tryz , (void));
-_PROTOTYPE(int rzfiles , (void));
-_PROTOTYPE(int rzfile , (void));
-_PROTOTYPE(void zmputs , (char *s ));
-_PROTOTYPE(int closeit , (void));
-_PROTOTYPE(void ackbibi , (void));
-_PROTOTYPE(void bttyout , (int c ));
-_PROTOTYPE(int sys2 , (char *s ));
-_PROTOTYPE(void exec2 , (char *s ));
-
-/*
- * Max value for HOWMANY is 255.
- *   A larger value reduces system overhead but may evoke kernel bugs.
- *   133 corresponds to an XMODEM/CRC sector
- */
-#ifndef HOWMANY
-#define HOWMANY 133
-#endif
-
-/* Ward Christensen / CP/M parameters - Don't change these! */
-#define ENQ 005
-#define CAN ('X'&037)
-#define XOFF ('s'&037)
-#define XON ('q'&037)
-#define SOH 1
-#define STX 2
-#define EOT 4
-#define ACK 6
-#define NAK 025
-#define CPMEOF 032
-#define WANTCRC 0103	/* send C not NAK to get crc not checksum */
-#define TIMEOUT (-2)
-#define RCDO (-3)
-#define ERRORMAX 5
-#define RETRYMAX 5
-#define WCEOT (-10)
-#define PATHLEN 257	/* ready for 4.2 bsd ? */
-#define UNIXFILE 0xF000	/* The S_IFMT file mask bit for stat */
-
-int Zmodem=0;		/* ZMODEM protocol requested */
-int Nozmodem = 0;	/* If invoked as "rb" */
-unsigned Baudrate = 2400;
-
-#ifdef vax11c
-#include "vrzsz.c"	/* most of the system dependent stuff here */
-#else
-#include "rbsb.c"	/* most of the system dependent stuff here */
-#endif
-
-#include "crctab.c"
-
-FILE *fout;
-
-/*
- * Routine to calculate the free bytes on the current file system
- *  ~0 means many free bytes (unknown)
- */
-long getfree()
-{
-	return(~0L);	/* many free bytes ... */
-}
-
-int Lastrx;
-int Crcflg;
-int Firstsec;
-int Eofseen;		/* indicates cpm eof (^Z) has been received */
-int errors;
-int Restricted=0;	/* restricted; no /.. or ../ in filenames */
-#ifdef ONEREAD
-/* Sorry, Regulus and some others don't work right in raw mode! */
-int Readnum = 1;	/* Number of bytes to ask for in read() from modem */
-#else
-int Readnum = HOWMANY;	/* Number of bytes to ask for in read() from modem */
-#endif
-
-#define DEFBYTL 2000000000L	/* default rx file size */
-long Bytesleft;		/* number of bytes of incoming file left */
-long Modtime;		/* Unix style mod time for incoming file */
-int Filemode;		/* Unix style mode for incoming file */
-char Pathname[PATHLEN];
-char *Progname;		/* the name by which we were called */
-
-int Batch=0;
-int Topipe=0;
-int MakeLCPathname=TRUE;	/* make received pathname lower case */
-int Verbose=0;
-int Quiet=0;		/* overrides logic that would otherwise set verbose */
-int Nflag = 0;		/* Don't really transfer files */
-int Rxclob=FALSE;	/* Clobber existing file */
-int Rxbinary=FALSE;	/* receive all files in bin mode */
-int Rxascii=FALSE;	/* receive files in ascii (translate) mode */
-int Thisbinary;		/* current file is to be received in bin mode */
-int Blklen;		/* record length of received packets */
-
-#ifdef SEGMENTS
-int chinseg = 0;	/* Number of characters received in this data seg */
-char secbuf[1+(SEGMENTS+1)*1024];
-#else
-char secbuf[1025];
-#endif
-
-
-char linbuf[HOWMANY];
-int Lleft=0;		/* number of characters in linbuf */
-time_t timep[2];
-char Lzmanag;		/* Local file management request */
-char zconv;		/* ZMODEM file conversion request */
-char zmanag;		/* ZMODEM file management request */
-char ztrans;		/* ZMODEM file transport request */
-int Zctlesc;		/* Encode control characters */
-int Zrwindow = 1400;	/* RX window size (controls garbage count) */
-
-jmp_buf tohere;		/* For the interrupt on RX timeout */
-
-#define xsendline(c) sendline(c)
-#include "zm.c"
-
-int tryzhdrtype=ZRINIT;	/* Header type to send corresponding to Last rx close */
-
-void alrm(sig)
-int sig;
-{
-	longjmp(tohere, -1);
-}
-
-/* called by signal interrupt or terminate to clean things up */
-void bibi(n)
-int n;
-{
-	if (Zmodem)
-		zmputs(Attn);
-	canit(); mode(0);
-	fprintf(stderr, "rz: caught signal %d; exiting\n", n);
-	cucheck();
-	exit(128+n);
-}
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-	register char *cp;
-	register npats;
-	char *virgin, **patts;
-	int exitcode = 0;
-
-	Rxtimeout = 100;
-	setbuf(stderr, (char *)NULL);
-	if ((cp=getenv("SHELL")) && (substr(cp, "rsh") || substr(cp, "rksh")))
-		Restricted=TRUE;
-
-	from_cu();
-#ifdef vax11c
-	Progname = virgin = "rz";
-#else
-	chkinvok(virgin=argv[0]);	/* if called as [-]rzCOMMAND set flag */
-#endif
-	npats = 0;
-	while (--argc) {
-		cp = *++argv;
-		if (*cp == '-') {
-			while( *++cp) {
-				switch(*cp) {
-				case '\\':
-					 cp[1] = toupper(cp[1]);  continue;
-				case '+':
-					Lzmanag = ZMAPND; break;
-				case 'a':
-					Rxascii=TRUE;  break;
-				case 'b':
-					Rxbinary=TRUE; break;
-				case 'c':
-					Crcflg=TRUE; break;
-#ifndef vax11c
-				case 'D':
-					Nflag = TRUE; break;
-#endif
-				case 'e':
-					Zctlesc = 1; break;
-				case 'p':
-					Lzmanag = ZMPROT;  break;
-				case 'q':
-					Quiet=TRUE; Verbose=0; break;
-				case 't':
-					if (--argc < 1) {
-						usage();
-					}
-					Rxtimeout = atoi(*++argv);
-					if (Rxtimeout<10 || Rxtimeout>1000)
-						usage();
-					break;
-				case 'w':
-					if (--argc < 1) {
-						usage();
-					}
-					Zrwindow = atoi(*++argv);
-					break;
-				case 'u':
-					MakeLCPathname=FALSE; break;
-				case 'v':
-					++Verbose; break;
-				case 'y':
-					Rxclob=TRUE; break;
-				default:
-					usage();
-				}
-			}
-		}
-		else if ( !npats && argc>0) {
-			if (argv[0][0]) {
-				npats=argc;
-				patts=argv;
-			}
-		}
-	}
-	if (npats > 1)
-		usage();
-	if (Batch && npats)
-		usage();
-	if (Verbose) {
-		if (freopen(LOGFILE, "a", stderr)==NULL) {
-			printf("Can't open log file %s\n",LOGFILE);
-			exit(0200);
-		}
-		setbuf(stderr, (char *)NULL);
-		fprintf(stderr, "argv[0]=%s Progname=%s\n", virgin, Progname);
-	}
-	if (Fromcu && !Quiet) {
-		if (Verbose == 0)
-			Verbose = 2;
-	}
-	vfile("%s %s for %s\n", Progname, VERSION, OS);
-	mode(1);
-	if (signal(SIGINT, bibi) == SIG_IGN) {
-		signal(SIGINT, SIG_IGN); signal(SIGKILL, SIG_IGN);
-	}
-	else {
-		signal(SIGINT, bibi); signal(SIGKILL, bibi);
-	}
-	signal(SIGTERM, bibi);
-	if (wcreceive(npats, patts)==ERROR) {
-		exitcode=0200;
-		canit();
-	}
-	mode(0);
-	vfile("exitcode = %d\n",exitcode);
-	if (exitcode && !Zmodem)	/* bellow again with all thy might. */
-		canit();
-	if (exitcode)
-		cucheck();
-	if (Verbose) putc('\n', stderr);
-	exit(exitcode ? exitcode:SS_NORMAL);
-}
-
-
-int usage()
-{
-	cucheck();
-#ifdef vax11c
-	fprintf(stderr,"Usage:	rz [-abeuvy]\n");
-#else
-	fprintf(stderr,"Usage:	rz [-abeuvy]		(ZMODEM)\n");
-	fprintf(stderr,"or	rb [-abuvy]		(YMODEM)\n");
-	fprintf(stderr,"or	rx [-abcv] file	(XMODEM or XMODEM-1k)\n");
-#endif
-	fprintf(stderr,"	  -a ASCII transfer (strip CR)\n");
-	fprintf(stderr,"	  -b Binary transfer for all files\n");
-#ifndef vax11c
-	fprintf(stderr,"	  -c Use 16 bit CRC	(XMODEM)\n");
-#endif
-	fprintf(stderr,"	  -e Escape control characters	(ZMODEM)\n");
-	fprintf(stderr,"	  -v Verbose more v's give more info\n");
-	fprintf(stderr,"	  -y Yes, clobber existing file if any\n");
-	fprintf(stderr,"%s %s for %s by Chuck Forsberg, Omen Technology INC\n",
-	  Progname, VERSION, OS);
-	fprintf(stderr, "\t\t\042The High Reliability Software\042\n");
-	exit(SS_NORMAL);
-}
-/*
- *  Debugging information output interface routine
- */
-/* VARARGS1 */
-void vfile(f, a, b, c)
-register char *f,*a,*b,*c;
-
-{
-	if (Verbose > 2) {
-		fprintf(stderr, f, a, b, c);
-		fprintf(stderr, "\n");
-	}
-}
-
-/*
- * Let's receive something already.
- */
-
-char *rbmsg =
-"%s ready. To begin transfer, type \"%s file ...\" to your modem program\r\n\n";
-
-int wcreceive(argc, argp)
-int argc;
-char **argp;
-{
-	register c;
-
-	if (Batch || argc==0) {
-		Crcflg=1;
-		if ( !Quiet)
-			fprintf(stderr, rbmsg, Progname, Nozmodem?"sb":"sz");
-		if (c=tryz()) {
-			if (c == ZCOMPL)
-				return OK;
-			if (c == ERROR)
-				goto fubar;
-			c = rzfiles();
-			if (c)
-				goto fubar;
-		} else {
-			for (;;) {
-				if (wcrxpn(secbuf)== ERROR)
-					goto fubar;
-				if (secbuf[0]==0)
-					return OK;
-				if (procheader(secbuf) == ERROR)
-					goto fubar;
-				if (wcrx()==ERROR)
-					goto fubar;
-			}
-		}
-	} else {
-		Bytesleft = DEFBYTL; Filemode = 0; Modtime = 0L;
-
-		procheader(""); strcpy(Pathname, *argp); checkpath(Pathname);
-		fprintf(stderr, "\nrz: ready to receive %s\r\n", Pathname);
-		if ((fout=fopen(Pathname, "w")) == NULL)
-			return ERROR;
-		if (wcrx()==ERROR)
-			goto fubar;
-	}
-	return OK;
-fubar:
-	canit();
-#ifndef vax11c
-	if (Topipe && fout) {
-		pclose(fout);  return ERROR;
-	}
-#endif
-	if (fout)
-		fclose(fout);
-#ifndef vax11c
-	if (Restricted) {
-		unlink(Pathname);
-		fprintf(stderr, "\r\nrz: %s removed.\r\n", Pathname);
-	}
-#endif
-	return ERROR;
-}
-
-
-/*
- * Fetch a pathname from the other end as a C ctyle ASCIZ string.
- * Length is indeterminate as long as less than Blklen
- * A null string represents no more files (YMODEM)
- */
-int wcrxpn(rpn)
-char *rpn;	/* receive a pathname */
-{
-	register c;
-
-#ifdef NFGVMIN
-	readline(1);
-#else
-	purgeline();
-#endif
-
-et_tu:
-	Firstsec=TRUE;  Eofseen=FALSE;
-	sendline(Crcflg?WANTCRC:NAK);
-	Lleft=0;	/* Do read next time ... */
-	while ((c = wcgetsec(rpn, 100)) != 0) {
-		if (c == WCEOT) {
-			zperr( "Pathname fetch returned %d", c);
-			sendline(ACK);
-			Lleft=0;	/* Do read next time ... */
-			readline(1);
-			goto et_tu;
-		}
-		return ERROR;
-	}
-	sendline(ACK);
-	return OK;
-}
-
-/*
- * Adapted from CMODEM13.C, written by
- * Jack M. Wierda and Roderick W. Hart
- */
-
-int wcrx()
-{
-	register int sectnum, sectcurr;
-	register char sendchar;
-	int cblklen;			/* bytes to dump this block */
-
-	Firstsec=TRUE;sectnum=0; Eofseen=FALSE;
-	sendchar=Crcflg?WANTCRC:NAK;
-
-	for (;;) {
-		sendline(sendchar);	/* send it now, we're ready! */
-		Lleft=0;	/* Do read next time ... */
-		sectcurr=wcgetsec(secbuf, (sectnum&0177)?50:130);
-		report(sectcurr);
-		if (sectcurr==((sectnum+1) &0377)) {
-			sectnum++;
-			cblklen = Bytesleft>Blklen ? Blklen:Bytesleft;
-			if (putsec(secbuf, cblklen)==ERROR)
-				return ERROR;
-			if ((Bytesleft-=cblklen) < 0)
-				Bytesleft = 0;
-			sendchar=ACK;
-		}
-		else if (sectcurr==(sectnum&0377)) {
-			zperr( "Received dup Sector");
-			sendchar=ACK;
-		}
-		else if (sectcurr==WCEOT) {
-			if (closeit())
-				return ERROR;
-			sendline(ACK);
-			Lleft=0;	/* Do read next time ... */
-			return OK;
-		}
-		else if (sectcurr==ERROR)
-			return ERROR;
-		else {
-			zperr( "Sync Error");
-			return ERROR;
-		}
-	}
-}
-
-/*
- * Wcgetsec fetches a Ward Christensen type sector.
- * Returns sector number encountered or ERROR if valid sector not received,
- * or CAN CAN received
- * or WCEOT if eot sector
- * time is timeout for first char, set to 4 seconds thereafter
- ***************** NO ACK IS SENT IF SECTOR IS RECEIVED OK **************
- *    (Caller must do that when he is good and ready to get next sector)
- */
-
-int wcgetsec(rxbuf, maxtime)
-char *rxbuf;
-int maxtime;
-{
-	register checksum, wcj, firstch;
-	register unsigned short oldcrc;
-	register char *p;
-	int sectcurr;
-
-	for (Lastrx=errors=0; errors<RETRYMAX; errors++) {
-
-		if ((firstch=readline(maxtime))==STX) {
-			Blklen=1024; goto get2;
-		}
-		if (firstch==SOH) {
-			Blklen=128;
-get2:
-			sectcurr=readline(1);
-			if ((sectcurr+(oldcrc=readline(1)))==0377) {
-				oldcrc=checksum=0;
-				for (p=rxbuf,wcj=Blklen; --wcj>=0; ) {
-					if ((firstch=readline(1)) < 0)
-						goto bilge;
-					oldcrc=updcrc(firstch, oldcrc);
-					checksum += (*p++ = firstch);
-				}
-				if ((firstch=readline(1)) < 0)
-					goto bilge;
-				if (Crcflg) {
-					oldcrc=updcrc(firstch, oldcrc);
-					if ((firstch=readline(1)) < 0)
-						goto bilge;
-					oldcrc=updcrc(firstch, oldcrc);
-					if (oldcrc & 0xFFFF)
-						zperr( "CRC");
-					else {
-						Firstsec=FALSE;
-						return sectcurr;
-					}
-				}
-				else if (((checksum-firstch)&0377)==0) {
-					Firstsec=FALSE;
-					return sectcurr;
-				}
-				else
-					zperr( "Checksum");
-			}
-			else
-				zperr("Sector number garbled");
-		}
-		/* make sure eot really is eot and not just mixmash */
-#ifdef NFGVMIN
-		else if (firstch==EOT && readline(1)==TIMEOUT)
-			return WCEOT;
-#else
-		else if (firstch==EOT && Lleft==0)
-			return WCEOT;
-#endif
-		else if (firstch==CAN) {
-			if (Lastrx==CAN) {
-				zperr( "Sender CANcelled");
-				return ERROR;
-			} else {
-				Lastrx=CAN;
-				continue;
-			}
-		}
-		else if (firstch==TIMEOUT) {
-			if (Firstsec)
-				goto humbug;
-bilge:
-			zperr( "TIMEOUT");
-		}
-		else
-			zperr( "Got 0%o sector header", firstch);
-
-humbug:
-		Lastrx=0;
-		while(readline(1)!=TIMEOUT)
-			;
-		if (Firstsec) {
-			sendline(Crcflg?WANTCRC:NAK);
-			Lleft=0;	/* Do read next time ... */
-		} else {
-			maxtime=40; sendline(NAK);
-			Lleft=0;	/* Do read next time ... */
-		}
-	}
-	/* try to stop the bubble machine. */
-	canit();
-	return ERROR;
-}
-
-#ifndef vax11c
-/*
- * This version of readline is reasoably well suited for
- * reading many characters.
- *  (except, currently, for the Regulus version!)
- *
- * timeout is in tenths of seconds
- */
-int readline(timeout)
-int timeout;
-{
-	register n;
-	static char *cdq;	/* pointer for removing chars from linbuf */
-
-	if (--Lleft >= 0) {
-		if (Verbose > 8) {
-			fprintf(stderr, "%02x ", *cdq&0377);
-		}
-		return (*cdq++ & 0377);
-	}
-	n = timeout/10;
-	if (n < 2)
-		n = 3;
-	if (Verbose > 5)
-		fprintf(stderr, "Calling read: alarm=%d  Readnum=%d ",
-		  n, Readnum);
-	if (setjmp(tohere)) {
-#ifdef TIOCFLUSH
-/*		ioctl(iofd, TIOCFLUSH, 0); */
-#endif
-		Lleft = 0;
-		if (Verbose>1)
-			fprintf(stderr, "Readline:TIMEOUT\n");
-		return TIMEOUT;
-	}
-	signal(SIGALRM, alrm); alarm(n);
-	Lleft=read(iofd, cdq=linbuf, Readnum);
-	alarm(0);
-	if (Verbose > 5) {
-		fprintf(stderr, "Read returned %d bytes\n", Lleft);
-	}
-	if (Lleft < 1)
-		return TIMEOUT;
-	--Lleft;
-	if (Verbose > 8) {
-		fprintf(stderr, "%02x ", *cdq&0377);
-	}
-	return (*cdq++ & 0377);
-}
-
-
-
-/*
- * Purge the modem input queue of all characters
- */
-void purgeline()
-{
-	Lleft = 0;
-#ifdef USG
-	ioctl(iofd, TCFLSH, 0);
-#else
-	lseek(iofd, 0L, 2);
-#endif
-}
-#endif
-
-
-/*
- * Process incoming file information header
- */
-int procheader(name)
-char *name;
-{
-	register char *openmode, *p;
-
-	/* set default parameters and overrides */
-	openmode = "w";
-	Thisbinary = (!Rxascii) || Rxbinary;
-	if (Lzmanag)
-		zmanag = Lzmanag;
-
-	/*
-	 *  Process ZMODEM remote file management requests
-	 */
-	if (!Rxbinary && zconv == ZCNL)	/* Remote ASCII override */
-		Thisbinary = 0;
-	if (zconv == ZCBIN)	/* Remote Binary override */
-		Thisbinary = TRUE;
-	else if (zmanag == ZMAPND)
-		openmode = "a";
-
-#ifndef BIX
-	/* Check for existing file */
-	if (!Rxclob && (zmanag&ZMMASK) != ZMCLOB && (fout=fopen(name, "r"))) {
-		fclose(fout);  return ERROR;
-	}
-#endif
-
-	Bytesleft = DEFBYTL; Filemode = 0; Modtime = 0L;
-
-	p = name + 1 + strlen(name);
-	if (*p) {	/* file coming from Unix or DOS system */
-		sscanf(p, "%ld%lo%o", &Bytesleft, &Modtime, &Filemode);
-#ifndef vax11c
-		if (Filemode & UNIXFILE)
-			++Thisbinary;
-#endif
-		if (Verbose) {
-			fprintf(stderr,  "\nIncoming: %s %ld %lo %o\n",
-			  name, Bytesleft, Modtime, Filemode);
-		}
-	}
-
-#ifdef BIX
-	if ((fout=fopen("scratchpad", openmode)) == NULL)
-		return ERROR;
-	return OK;
-#else
-
-	else {		/* File coming from CP/M system */
-		for (p=name; *p; ++p)		/* change / to _ */
-			if ( *p == '/')
-				*p = '_';
-
-		if ( *--p == '.')		/* zap trailing period */
-			*p = 0;
-	}
-
-#ifndef vax11c
-	if (!Zmodem && MakeLCPathname && !IsAnyLower(name)
-	  && !(Filemode&UNIXFILE))
-		uncaps(name);
-#endif
-	if (Topipe > 0) {
-		sprintf(Pathname, "%s %s", Progname+2, name);
-		if (Verbose)
-			fprintf(stderr,  "Topipe: %s %s\n",
-			  Pathname, Thisbinary?"BIN":"ASCII");
-#ifndef vax11c
-		if ((fout=popen(Pathname, "w")) == NULL)
-			return ERROR;
-#endif
-	} else {
-		strcpy(Pathname, name);
-		if (Verbose) {
-			fprintf(stderr,  "Receiving %s %s %s\n",
-			  name, Thisbinary?"BIN":"ASCII", openmode);
-		}
-		checkpath(name);
-		if (Nflag)
-			name = "/dev/null";
-#ifndef vax11c
-#ifdef OMEN
-		if (name[0] == '!' || name[0] == '|') {
-			if ( !(fout = popen(name+1, "w"))) {
-				return ERROR;
-			}
-			Topipe = -1;  return(OK);
-		}
-#endif
-#endif
-#ifdef MD
-		fout = fopen(name, openmode);
-		if ( !fout)
-			if (make_dirs(name))
-				fout = fopen(name, openmode);
-#else
-		fout = fopen(name, openmode);
-#endif
-		if ( !fout)
-			return ERROR;
-	}
-	return OK;
-#endif /* BIX */
-}
-
-#ifdef MD
-/*
- *  Directory-creating routines from Public Domain TAR by John Gilmore
- */
-
-/*
- * After a file/link/symlink/dir creation has failed, see if
- * it's because some required directory was not present, and if
- * so, create all required dirs.
- */
-int make_dirs(pathname)
-register char *pathname;
-{
-	register char *p;		/* Points into path */
-	int madeone = 0;		/* Did we do anything yet? */
-	int save_errno = errno;		/* Remember caller's errno */
-	char *strchr();
-
-	if (errno != ENOENT)
-		return 0;		/* Not our problem */
-
-	for (p = strchr(pathname, '/'); p != NULL; p = strchr(p+1, '/')) {
-		/* Avoid mkdir of empty string, if leading or double '/' */
-		if (p == pathname || p[-1] == '/')
-			continue;
-		/* Avoid mkdir where last part of path is '.' */
-		if (p[-1] == '.' && (p == pathname+1 || p[-2] == '/'))
-			continue;
-		*p = 0;				/* Truncate the path there */
-		if ( !makedir(pathname, 0777)) {	/* Try to create it as a dir */
-			vfile("Made directory %s\n", pathname);
-			madeone++;		/* Remember if we made one */
-			*p = '/';
-			continue;
-		}
-		*p = '/';
-		if (errno == EEXIST)		/* Directory already exists */
-			continue;
-		/*
-		 * Some other error in the makedir.  We return to the caller.
-		 */
-		break;
-	}
-	errno = save_errno;		/* Restore caller's errno */
-	return madeone;			/* Tell them to retry if we made one */
-}
-
-#if (MD != 2)
-#define	TERM_SIGNAL(status)	((status) & 0x7F)
-#define TERM_COREDUMP(status)	(((status) & 0x80) != 0)
-#define TERM_VALUE(status)	((status) >> 8)
-/*
- * Make a directory.  Compatible with the mkdir() system call on 4.2BSD.
- */
-int makedir(dpath, dmode)
-char *dpath;
-int dmode;
-{
-	int cpid, status;
-	struct stat statbuf;
-
-	if (stat(dpath,&statbuf) == 0) {
-		errno = EEXIST;		/* Stat worked, so it already exists */
-		return -1;
-	}
-
-	/* If stat fails for a reason other than non-existence, return error */
-	if (errno != ENOENT) return -1; 
-
-	switch (cpid = fork()) {
-
-	case -1:			/* Error in fork() */
-		return(-1);		/* Errno is set already */
-
-	case 0:				/* Child process */
-		/*
-		 * Cheap hack to set mode of new directory.  Since this
-		 * child process is going away anyway, we zap its umask.
-		 * FIXME, this won't suffice to set SUID, SGID, etc. on this
-		 * directory.  Does anybody care?
-		 */
-		status = umask(0);	/* Get current umask */
-		status = umask(status | (0777 & ~dmode)); /* Set for mkdir */
-		execl("/bin/mkdir", "mkdir", dpath, (char *)0);
-		_exit(-1);		/* Can't exec /bin/mkdir */
-	
-	default:			/* Parent process */
-		while (cpid != wait(&status)) ;	/* Wait for kid to finish */
-	}
-
-	if (TERM_SIGNAL(status) != 0 || TERM_VALUE(status) != 0) {
-		errno = EIO;		/* We don't know why, but */
-		return -1;		/* /bin/mkdir failed */
-	}
-
-	return 0;
-}
-#endif /* MD != 2 */
-#endif /* MD */
-
-/*
- * Putsec writes the n characters of buf to receive file fout.
- *  If not in binary mode, carriage returns, and all characters
- *  starting with CPMEOF are discarded.
- */
-int putsec(buf, n)
-char *buf;
-register int n;
-{
-	register char *p;
-
-	if (n == 0)
-		return OK;
-	if (Thisbinary) {
-		for (p=buf; --n>=0; )
-			putc( *p++, fout);
-	}
-	else {
-		if (Eofseen)
-			return OK;
-		for (p=buf; --n>=0; ++p ) {
-			if ( *p == '\r')
-				continue;
-			if (*p == CPMEOF) {
-				Eofseen=TRUE; return OK;
-			}
-			putc(*p ,fout);
-		}
-	}
-	return OK;
-}
-
-#ifndef vax11c
-/*
- *  Send a character to modem.  Small is beautiful.
- */
-void sendline(c)
-int c;
-{
-	char d;
-
-	d = c;
-	if (Verbose>6)
-		fprintf(stderr, "Sendline: %x\n", c);
-	write(1, &d, 1);
-}
-
-void flushmo() {}
-#endif
-
-
-
-
-
-/* make string s lower case */
-void uncaps(s)
-register char *s;
-{
-	for ( ; *s; ++s)
-		if (isupper(*s))
-			*s = tolower(*s);
-}
-/*
- * IsAnyLower returns TRUE if string s has lower case letters.
- */
-int IsAnyLower(s)
-register char *s;
-{
-	for ( ; *s; ++s)
-		if (islower(*s))
-			return TRUE;
-	return FALSE;
-}
-
-/*
- * substr(string, token) searches for token in string s
- * returns pointer to token within string if found, NULL otherwise
- */
-char *
-substr(s, t)
-register char *s,*t;
-{
-	register char *ss,*tt;
-	/* search for first char of token */
-	for (ss=s; *s; s++)
-		if (*s == *t)
-			/* compare token with substring */
-			for (ss=s,tt=t; ;) {
-				if (*tt == 0)
-					return s;
-				if (*ss++ != *tt++)
-					break;
-			}
-	return (char *)NULL;
-}
-
-/*
- * Log an error
- */
-/*VARARGS1*/
-void zperr(s,p,u)
-char *s, *p, *u;
-{
-	if (Verbose <= 0)
-		return;
-	fprintf(stderr, "Retry %d: ", errors);
-	fprintf(stderr, s, p, u);
-	fprintf(stderr, "\n");
-}
-
-/* send cancel string to get the other end to shut up */
-void canit()
-{
-	static char canistr[] = {
-	 24,24,24,24,24,24,24,24,24,24,8,8,8,8,8,8,8,8,8,8,0
-	};
-
-#ifdef vax11c
-	raw_wbuf(strlen(canistr), canistr);
-	purgeline();
-#else
-	printf(canistr);
-	Lleft=0;	/* Do read next time ... */
-	fflush(stdout);
-#endif
-}
-
-
-void report(sct)
-int sct;
-{
-	if (Verbose>1)
-		fprintf(stderr,"%03d%c",sct,sct%10? ' ' : '\r');
-}
-
-#ifndef vax11c
-/*
- * If called as [-][dir/../]vrzCOMMAND set Verbose to 1
- * If called as [-][dir/../]rzCOMMAND set the pipe flag
- * If called as rb use YMODEM protocol
- */
-void chkinvok(s)
-char *s;
-{
-	register char *p;
-
-	p = s;
-	while (*p == '-')
-		s = ++p;
-	while (*p)
-		if (*p++ == '/')
-			s = p;
-	if (*s == 'v') {
-		Verbose=1; ++s;
-	}
-	Progname = s;
-	if (s[0]=='r' && s[1]=='z')
-		Batch = TRUE;
-	if (s[0]=='r' && s[1]=='b')
-		Batch = Nozmodem = TRUE;
-	if (s[2] && s[0]=='r' && s[1]=='b')
-		Topipe = 1;
-	if (s[2] && s[0]=='r' && s[1]=='z')
-		Topipe = 1;
-}
-#endif
-
-/*
- * Totalitarian Communist pathname processing
- */
-void checkpath(name)
-char *name;
-{
-	if (Restricted) {
-		if (fopen(name, "r") != NULL) {
-			canit();
-			fprintf(stderr, "\r\nrz: %s exists\n", name);
-			bibi(-1);
-		}
-		/* restrict pathnames to current tree or uucppublic */
-		if ( substr(name, "../")
-		 || (name[0]== '/' && strncmp(name, PUBDIR, strlen(PUBDIR))) ) {
-			canit();
-			fprintf(stderr,"\r\nrz:\tSecurity Violation\r\n");
-			bibi(-1);
-		}
-	}
-}
-
-/*
- * Initialize for Zmodem receive attempt, try to activate Zmodem sender
- *  Handles ZSINIT frame
- *  Return ZFILE if Zmodem filename received, -1 on error,
- *   ZCOMPL if transaction finished,  else 0
- */
-int tryz()
-{
-	register c, n;
-	register cmdzack1flg;
-
-	if (Nozmodem)		/* Check for "rb" program name */
-		return 0;
-
-
-	for (n=Zmodem?15:5; --n>=0; ) {
-		/* Set buffer length (0) and capability flags */
-#ifdef SEGMENTS
-		stohdr(SEGMENTS*1024L);
-#else
-		stohdr(0L);
-#endif
-#ifdef CANBREAK
-		Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO|CANBRK;
-#else
-		Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO;
-#endif
-		if (Zctlesc)
-			Txhdr[ZF0] |= TESCCTL;
-		zshhdr(tryzhdrtype, Txhdr);
-		if (tryzhdrtype == ZSKIP)	/* Don't skip too far */
-			tryzhdrtype = ZRINIT;	/* CAF 8-21-87 */
-again:
-		switch (zgethdr(Rxhdr, 0)) {
-		case ZRQINIT:
-			continue;
-		case ZEOF:
-			continue;
-		case TIMEOUT:
-			continue;
-		case ZFILE:
-			zconv = Rxhdr[ZF0];
-			zmanag = Rxhdr[ZF1];
-			ztrans = Rxhdr[ZF2];
-			tryzhdrtype = ZRINIT;
-			c = zrdata(secbuf, 1024);
-			mode(3);
-			if (c == GOTCRCW)
-				return ZFILE;
-			zshhdr(ZNAK, Txhdr);
-			goto again;
-		case ZSINIT:
-			Zctlesc = TESCCTL & Rxhdr[ZF0];
-			if (zrdata(Attn, ZATTNLEN) == GOTCRCW) {
-				stohdr(1L);
-				zshhdr(ZACK, Txhdr);
-				goto again;
-			}
-			zshhdr(ZNAK, Txhdr);
-			goto again;
-		case ZFREECNT:
-			stohdr(getfree());
-			zshhdr(ZACK, Txhdr);
-			goto again;
-		case ZCOMMAND:
-#ifdef vax11c
-			return ERROR;
-#else
-			cmdzack1flg = Rxhdr[ZF0];
-			if (zrdata(secbuf, 1024) == GOTCRCW) {
-				if (cmdzack1flg & ZCACK1)
-					stohdr(0L);
-				else
-					stohdr((long)sys2(secbuf));
-				purgeline();	/* dump impatient questions */
-				do {
-					zshhdr(ZCOMPL, Txhdr);
-				}
-				while (++errors<20 && zgethdr(Rxhdr,1) != ZFIN);
-				ackbibi();
-				if (cmdzack1flg & ZCACK1)
-					exec2(secbuf);
-				return ZCOMPL;
-			}
-			zshhdr(ZNAK, Txhdr); goto again;
-#endif
-		case ZCOMPL:
-			goto again;
-		default:
-			continue;
-		case ZFIN:
-			ackbibi(); return ZCOMPL;
-		case ZCAN:
-			return ERROR;
-		}
-	}
-	return 0;
-}
-
-/*
- * Receive 1 or more files with ZMODEM protocol
- */
-int rzfiles()
-{
-	register c;
-
-	for (;;) {
-		switch (c = rzfile()) {
-		case ZEOF:
-		case ZSKIP:
-			switch (tryz()) {
-			case ZCOMPL:
-				return OK;
-			default:
-				return ERROR;
-			case ZFILE:
-				break;
-			}
-			continue;
-		default:
-			return c;
-		case ERROR:
-			return ERROR;
-		}
-	}
-}
-
-/*
- * Receive a file with ZMODEM protocol
- *  Assumes file name frame is in secbuf
- */
-int rzfile()
-{
-	register c, n;
-	long rxbytes;
-
-	Eofseen=FALSE;
-	if (procheader(secbuf) == ERROR) {
-		return (tryzhdrtype = ZSKIP);
-	}
-
-	n = 20; rxbytes = 0l;
-
-	for (;;) {
-#ifdef SEGMENTS
-		chinseg = 0;
-#endif
-		stohdr(rxbytes);
-		zshhdr(ZRPOS, Txhdr);
-nxthdr:
-		switch (c = zgethdr(Rxhdr, 0)) {
-		default:
-			vfile("rzfile: zgethdr returned %d", c);
-			return ERROR;
-		case ZNAK:
-		case TIMEOUT:
-#ifdef SEGMENTS
-			putsec(secbuf, chinseg);
-			chinseg = 0;
-#endif
-			if ( --n < 0) {
-				vfile("rzfile: zgethdr returned %d", c);
-				return ERROR;
-			}
-		case ZFILE:
-			zrdata(secbuf, 1024);
-			continue;
-		case ZEOF:
-#ifdef SEGMENTS
-			putsec(secbuf, chinseg);
-			chinseg = 0;
-#endif
-			if (rclhdr(Rxhdr) != rxbytes) {
-				/*
-				 * Ignore eof if it's at wrong place - force
-				 *  a timeout because the eof might have gone
-				 *  out before we sent our zrpos.
-				 */
-				errors = 0;  goto nxthdr;
-			}
-			if (closeit()) {
-				tryzhdrtype = ZFERR;
-				vfile("rzfile: closeit returned <> 0");
-				return ERROR;
-			}
-			vfile("rzfile: normal EOF");
-			return c;
-		case ERROR:	/* Too much garbage in header search error */
-#ifdef SEGMENTS
-			putsec(secbuf, chinseg);
-			chinseg = 0;
-#endif
-			if ( --n < 0) {
-				vfile("rzfile: zgethdr returned %d", c);
-				return ERROR;
-			}
-			zmputs(Attn);
-			continue;
-		case ZSKIP:
-#ifdef SEGMENTS
-			putsec(secbuf, chinseg);
-			chinseg = 0;
-#endif
-			closeit();
-			vfile("rzfile: Sender SKIPPED file");
-			return c;
-		case ZDATA:
-			if (rclhdr(Rxhdr) != rxbytes) {
-				if ( --n < 0) {
-					return ERROR;
-				}
-#ifdef SEGMENTS
-				putsec(secbuf, chinseg);
-				chinseg = 0;
-#endif
-				zmputs(Attn);  continue;
-			}
-moredata:
-			if (Verbose>1)
-				fprintf(stderr, "\r%7ld ZMODEM%s    ",
-				  rxbytes, Crc32?" CRC-32":"");
-#ifdef SEGMENTS
-			if (chinseg >= (1024 * SEGMENTS)) {
-				putsec(secbuf, chinseg);
-				chinseg = 0;
-			}
-			switch (c = zrdata(secbuf+chinseg, 1024))
-#else
-			switch (c = zrdata(secbuf, 1024))
-#endif
-			{
-			case ZCAN:
-#ifdef SEGMENTS
-				putsec(secbuf, chinseg);
-				chinseg = 0;
-#endif
-				vfile("rzfile: zgethdr returned %d", c);
-				return ERROR;
-			case ERROR:	/* CRC error */
-#ifdef SEGMENTS
-				putsec(secbuf, chinseg);
-				chinseg = 0;
-#endif
-				if ( --n < 0) {
-					vfile("rzfile: zgethdr returned %d", c);
-					return ERROR;
-				}
-				zmputs(Attn);
-				continue;
-			case TIMEOUT:
-#ifdef SEGMENTS
-				putsec(secbuf, chinseg);
-				chinseg = 0;
-#endif
-				if ( --n < 0) {
-					vfile("rzfile: zgethdr returned %d", c);
-					return ERROR;
-				}
-				continue;
-			case GOTCRCW:
-				n = 20;
-#ifdef SEGMENTS
-				chinseg += Rxcount;
-				putsec(secbuf, chinseg);
-				chinseg = 0;
-#else
-				putsec(secbuf, Rxcount);
-#endif
-				rxbytes += Rxcount;
-				stohdr(rxbytes);
-				zshhdr(ZACK, Txhdr);
-				sendline(XON);
-				goto nxthdr;
-			case GOTCRCQ:
-				n = 20;
-#ifdef SEGMENTS
-				chinseg += Rxcount;
-#else
-				putsec(secbuf, Rxcount);
-#endif
-				rxbytes += Rxcount;
-				stohdr(rxbytes);
-				zshhdr(ZACK, Txhdr);
-				goto moredata;
-			case GOTCRCG:
-				n = 20;
-#ifdef SEGMENTS
-				chinseg += Rxcount;
-#else
-				putsec(secbuf, Rxcount);
-#endif
-				rxbytes += Rxcount;
-				goto moredata;
-			case GOTCRCE:
-				n = 20;
-#ifdef SEGMENTS
-				chinseg += Rxcount;
-#else
-				putsec(secbuf, Rxcount);
-#endif
-				rxbytes += Rxcount;
-				goto nxthdr;
-			}
-		}
-	}
-}
-
-/*
- * Send a string to the modem, processing for \336 (sleep 1 sec)
- *   and \335 (break signal)
- */
-void zmputs(s)
-char *s;
-{
-	register c;
-
-	while (*s) {
-		switch (c = *s++) {
-		case '\336':
-			sleep(1); continue;
-		case '\335':
-			sendbrk(); continue;
-		default:
-			sendline(c);
-		}
-	}
-}
-
-/*
- * Close the receive dataset, return OK or ERROR
- */
-int closeit()
-{
-	time_t q;
-
-#ifndef vax11c
-	if (Topipe) {
-		if (pclose(fout)) {
-			return ERROR;
-		}
-		return OK;
-	}
-#endif
-	if (fclose(fout)==ERROR) {
-		fprintf(stderr, "file close ERROR\n");
-		return ERROR;
-	}
-#ifndef vax11c
-	if (Modtime) {
-		timep[0] = time(&q);
-		timep[1] = Modtime;
-		utime(Pathname, (struct utimbuf *) timep);
-	}
-#endif
-	if ((Filemode&S_IFMT) == S_IFREG)
-		chmod(Pathname, (07777 & Filemode));
-	return OK;
-}
-
-/*
- * Ack a ZFIN packet, let byegones be byegones
- */
-void ackbibi()
-{
-	register n;
-
-	vfile("ackbibi:");
-	Readnum = 1;
-	stohdr(0L);
-	for (n=3; --n>=0; ) {
-		purgeline();
-		zshhdr(ZFIN, Txhdr);
-		switch (readline(100)) {
-		case 'O':
-			readline(1);	/* Discard 2nd 'O' */
-			vfile("ackbibi complete");
-			return;
-		case RCDO:
-			return;
-		case TIMEOUT:
-		default:
-			break;
-		}
-	}
-}
-
-
-
-/*
- * Local console output simulation
- */
-void bttyout(c)
-int c;
-{
-	if (Verbose || Fromcu)
-		putc(c, stderr);
-}
-
-#ifndef vax11c
-/*
- * Strip leading ! if present, do shell escape. 
- */
-int sys2(s)
-register char *s;
-{
-	if (*s == '!')
-		++s;
-	return system(s);
-}
-/*
- * Strip leading ! if present, do exec.
- */
-void exec2(s)
-register char *s;
-{
-	if (*s == '!')
-		++s;
-	mode(0);
-	execl("/bin/sh", "sh", "-c", s);
-}
-#endif
-/* End of rz.c */
Index: trunk/minix/commands/zmodem/sz.c
===================================================================
--- trunk/minix/commands/zmodem/sz.c	(revision 9)
+++ 	(revision )
@@ -1,1755 +1,0 @@
-#define VERSION "sz 2.12 05-29-88"
-#define PUBDIR "/usr/spool/uucppublic"
-
-/*% cc -compat -M2 -Ox -K -i -DTXBSIZE=16384  -DNFGVMIN -DREADCHECK sz.c -lx -o sz; size sz
-
-	Following is used for testing, might not be reasonable for production
-<-xtx-*> cc -Osal -DTXBSIZE=32768  -DSV sz.c -lx -o $B/sz; size $B/sz
-
- ****************************************************************************
- *
- * sz.c By Chuck Forsberg,  Omen Technology INC
- *
- ****************************************************************************
- *
- * Typical Unix/Xenix/Clone compiles:
- *
- *	cc -O sz.c -o sz		USG (SYS III/V) Unix
- *	cc -O -DSV sz.c -o sz		Sys V Release 2 with non-blocking input
- *					Define to allow reverse channel checking
- *	cc -O -DV7  sz.c -o sz		Unix Version 7, 2.8 - 4.3 BSD
- *
- *	cc -O -K -i -DNFGVMIN -DREADCHECK sz.c -lx -o sz	Classic Xenix
- *
- *	ln sz sb			**** All versions ****
- *	ln sz sx			**** All versions ****
- *
- ****************************************************************************
- *
- * Typical VMS compile and install sequence:
- *
- *		define LNK$LIBRARY   SYS$LIBRARY:VAXCRTL.OLB
- *		cc sz.c
- *		cc vvmodem.c
- *		link sz,vvmodem
- *	sz :== $disk$user2:[username.subdir]sz.exe
- *
- *  If you feel adventureous, remove the #define BADSYNC line
- *  immediately following the #ifdef vax11c line!  Some VMS
- *  systems know how to fseek, some don't.
- *
- ****************************************************************************
- *
- *
- * A program for Unix to send files and commands to computers running
- *  Professional-YAM, PowerCom, YAM, IMP, or programs supporting Y/XMODEM.
- *
- *  Sz uses buffered I/O to greatly reduce CPU time compared to UMODEM.
- *
- *  USG UNIX (3.0) ioctl conventions courtesy Jeff Martin
- *
- *  2.1x hacks to avoid VMS fseek() bogosity, allow input from pipe
- *     -DBADSEEK -DTXBSIZE=32768  
- *  2.x has mods for VMS flavor
- *
- * 1.34 implements tx backchannel garbage count and ZCRCW after ZRPOS
- * in accordance with the 7-31-87 ZMODEM Protocol Description
- */
-
-
-#include <sys/types.h>
-
-#ifdef vax11c
-#define BADSEEK
-#define TXBSIZE 32768		/* Must be power of two, < MAXINT */
-#include <types.h>
-#include <stat.h>
-#define LOGFILE "szlog.tmp"
-#define OS "VMS"
-#define READCHECK
-#define BUFWRITE
-#define iofd
-extern int errno;
-#define SS_NORMAL SS$_NORMAL
-#define xsendline(c) sendline(c)
-
-
-#else	/* vax11c */
-
-
-#define SS_NORMAL 0
-#define LOGFILE "/tmp/szlog"
-
-#define sendline(c) putchar((c) & 0377)
-#define xsendline(c) putchar(c)
-
-#endif
-
-#include <signal.h>
-#include <setjmp.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <utime.h>
-#include <stdio.h>
-
-#define PATHLEN 256
-#define OK 0
-#define FALSE 0
-#define TRUE 1
-#undef ERROR
-#define ERROR (-1)
-/* Ward Christensen / CP/M parameters - Don't change these! */
-#define ENQ 005
-#define CAN ('X'&037)
-#define XOFF ('s'&037)
-#define XON ('q'&037)
-#define SOH 1
-#define STX 2
-#define EOT 4
-#define ACK 6
-#define NAK 025
-#define CPMEOF 032
-#define WANTCRC 0103	/* send C not NAK to get crc not checksum */
-#define WANTG 0107	/* Send G not NAK to get nonstop batch xmsn */
-#define TIMEOUT (-2)
-#define RCDO (-3)
-#define RETRYMAX 10
-
-
-#define HOWMANY 2
-int Zmodem=0;		/* ZMODEM protocol requested by receiver */
-unsigned Baudrate=2400;	/* Default, should be set by first mode() call */
-unsigned Txwindow;	/* Control the size of the transmitted window */
-unsigned Txwspac;	/* Spacing between zcrcq requests */
-unsigned Txwcnt;	/* Counter used to space ack requests */
-long Lrxpos;		/* Receiver's last reported offset */
-int errors;
-
-#ifdef vax11c
-#include "vrzsz.c"	/* most of the system dependent stuff here */
-#else
-#include "rbsb.c"	/* most of the system dependent stuff here */
-#endif
-#include "crctab.c"
-
-int Filesleft;
-long Totalleft;
-
-/*
- * Attention string to be executed by receiver to interrupt streaming data
- *  when an error is detected.  A pause (0336) may be needed before the
- *  ^C (03) or after it.
- */
-#ifdef READCHECK
-char Myattn[] = { 0 };
-#else
-#ifdef USG
-char Myattn[] = { 03, 0336, 0 };
-#else
-char Myattn[] = { 0 };
-#endif
-#endif
-
-FILE *in;
-
-#ifdef BADSEEK
-int Canseek = 0;	/* 1: Can seek 0: only rewind -1: neither (pipe) */
-#ifndef TXBSIZE
-#define TXBSIZE 16384		/* Must be power of two, < MAXINT */
-#endif
-#else
-int Canseek = 1;	/* 1: Can seek 0: only rewind -1: neither (pipe) */
-#endif
-
-#ifdef TXBSIZE
-#define TXBMASK (TXBSIZE-1)
-char Txb[TXBSIZE];		/* Circular buffer for file reads */
-char *txbuf = Txb;		/* Pointer to current file segment */
-#else
-char txbuf[1024];
-#endif
-long vpos = 0;			/* Number of bytes read from file */
-
-char Lastrx;
-char Crcflg;
-int Verbose=0;
-int Modem2=0;		/* XMODEM Protocol - don't send pathnames */
-int Restricted=0;	/* restricted; no /.. or ../ in filenames */
-int Quiet=0;		/* overrides logic that would otherwise set verbose */
-int Ascii=0;		/* Add CR's for brain damaged programs */
-int Fullname=0;		/* transmit full pathname */
-int Unlinkafter=0;	/* Unlink file after it is sent */
-int Dottoslash=0;	/* Change foo.bar.baz to foo/bar/baz */
-int firstsec;
-int errcnt=0;		/* number of files unreadable */
-int blklen=128;		/* length of transmitted records */
-int Optiong;		/* Let it rip no wait for sector ACK's */
-int Eofseen;		/* EOF seen on input set by zfilbuf */
-int BEofseen;		/* EOF seen on input set by fooseek */
-int Totsecs;		/* total number of sectors this file */
-int Filcnt=0;		/* count of number of files opened */
-int Lfseen=0;
-unsigned Rxbuflen = 16384;	/* Receiver's max buffer length */
-int Tframlen = 0;	/* Override for tx frame length */
-int blkopt=0;		/* Override value for zmodem blklen */
-int Rxflags = 0;
-long bytcnt;
-int Wantfcs32 = TRUE;	/* want to send 32 bit FCS */
-char Lzconv;	/* Local ZMODEM file conversion request */
-char Lzmanag;	/* Local ZMODEM file management request */
-int Lskipnocor;
-char Lztrans;
-char zconv;		/* ZMODEM file conversion request */
-char zmanag;		/* ZMODEM file management request */
-char ztrans;		/* ZMODEM file transport request */
-int Command;		/* Send a command, then exit. */
-char *Cmdstr;		/* Pointer to the command string */
-int Cmdtries = 11;
-int Cmdack1;		/* Rx ACKs command, then do it */
-int Exitcode = 0;
-int Test;		/* 1= Force receiver to send Attn, etc with qbf. */
-			/* 2= Character transparency test */
-char *qbf="The quick brown fox jumped over the lazy dog's back 1234567890\r\n";
-long Lastsync;		/* Last offset to which we got a ZRPOS */
-int Beenhereb4;		/* How many times we've been ZRPOS'd same place */
-
-jmp_buf tohere;		/* For the interrupt on RX timeout */
-jmp_buf intrjmp;	/* For the interrupt on RX CAN */
-
-_PROTOTYPE(void onintr , (int sig ));
-_PROTOTYPE(int main , (int argc , char *argv []));
-_PROTOTYPE(int wcsend , (int argc , char *argp []));
-_PROTOTYPE(int wcs , (char *oname ));
-_PROTOTYPE(int wctxpn , (char *name ));
-_PROTOTYPE(int getnak , (void));
-_PROTOTYPE(int wctx , (long flen ));
-_PROTOTYPE(int wcputsec , (char *buf , int sectnum , int cseclen ));
-_PROTOTYPE(int filbuf , (char *buf , int count ));
-_PROTOTYPE(int zfilbuf , (void));
-_PROTOTYPE(int fooseek , (FILE *fptr , long pos , int whence ));
-_PROTOTYPE(void alrm , (int sig ));
-_PROTOTYPE(int readline , (int timeout ));
-_PROTOTYPE(void flushmo , (void));
-_PROTOTYPE(void purgeline , (void));
-_PROTOTYPE(void canit , (void));
-void zperr();
-_PROTOTYPE(char *substr , (char *s , char *t ));
-_PROTOTYPE(int usage , (void));
-_PROTOTYPE(int getzrxinit , (void));
-_PROTOTYPE(int sendzsinit , (void));
-_PROTOTYPE(int zsendfile , (char *buf , int blen ));
-_PROTOTYPE(int zsendfdata , (void));
-_PROTOTYPE(int getinsync , (int flag ));
-_PROTOTYPE(void saybibi , (void));
-_PROTOTYPE(void bttyout , (int c ));
-_PROTOTYPE(int zsendcmd , (char *buf , int blen ));
-_PROTOTYPE(void chkinvok , (char *s ));
-_PROTOTYPE(void countem , (int argc , char **argv ));
-_PROTOTYPE(void chartest , (int m ));
-
-/* called by signal interrupt or terminate to clean things up */
-void bibi(n)
-int n;
-{
-	canit(); fflush(stdout); mode(0);
-	fprintf(stderr, "sz: caught signal %d; exiting\n", n);
-	if (n == SIGQUIT)
-		abort();
-	if (n == 99)
-		fprintf(stderr, "mode(2) in rbsb.c not implemented!!\n");
-	cucheck();
-	exit(128+n);
-}
-/* Called when ZMODEM gets an interrupt (^X) */
-void onintr(sig)
-int sig;
-{
-	signal(SIGINT, SIG_IGN);
-	longjmp(intrjmp, -1);
-}
-
-int Zctlesc;	/* Encode control characters */
-int Nozmodem = 0;	/* If invoked as "sb" */
-char *Progname = "sz";
-int Zrwindow = 1400;	/* RX window size (controls garbage count) */
-#include "zm.c"
-
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-	register char *cp;
-	register npats;
-	int dm;
-	char **patts;
-	static char xXbuf[BUFSIZ];
-
-	if ((cp = getenv("ZNULLS")) && *cp)
-		Znulls = atoi(cp);
-	if ((cp=getenv("SHELL")) && (substr(cp, "rsh") || substr(cp, "rksh")))
-		Restricted=TRUE;
-	from_cu();
-	chkinvok(argv[0]);
-
-	Rxtimeout = 600;
-	npats=0;
-	if (argc<2)
-		usage();
-	setbuf(stdout, xXbuf);		
-	while (--argc) {
-		cp = *++argv;
-		if (*cp++ == '-' && *cp) {
-			while ( *cp) {
-				switch(*cp++) {
-				case '\\':
-					 *cp = toupper(*cp);  continue;
-				case '+':
-					Lzmanag = ZMAPND; break;
-#ifdef CSTOPB
-				case '2':
-					Twostop = TRUE; break;
-#endif
-				case 'a':
-					Lzconv = ZCNL;
-					Ascii = TRUE; break;
-				case 'b':
-					Lzconv = ZCBIN; break;
-				case 'C':
-					if (--argc < 1) {
-						usage();
-					}
-					Cmdtries = atoi(*++argv);
-					break;
-				case 'i':
-					Cmdack1 = ZCACK1;
-					/* **** FALL THROUGH TO **** */
-				case 'c':
-					if (--argc != 1) {
-						usage();
-					}
-					Command = TRUE;
-					Cmdstr = *++argv;
-					break;
-				case 'd':
-					++Dottoslash;
-					/* **** FALL THROUGH TO **** */
-				case 'f':
-					Fullname=TRUE; break;
-				case 'e':
-					Zctlesc = 1; break;
-				case 'k':
-					blklen=1024; break;
-				case 'L':
-					if (--argc < 1) {
-						usage();
-					}
-					blkopt = atoi(*++argv);
-					if (blkopt<24 || blkopt>1024)
-						usage();
-					break;
-				case 'l':
-					if (--argc < 1) {
-						usage();
-					}
-					Tframlen = atoi(*++argv);
-					if (Tframlen<32 || Tframlen>1024)
-						usage();
-					break;
-				case 'N':
-					Lzmanag = ZMNEWL;  break;
-				case 'n':
-					Lzmanag = ZMNEW;  break;
-				case 'o':
-					Wantfcs32 = FALSE; break;
-				case 'p':
-					Lzmanag = ZMPROT;  break;
-				case 'r':
-					Lzconv = ZCRESUM;
-				case 'q':
-					Quiet=TRUE; Verbose=0; break;
-				case 't':
-					if (--argc < 1) {
-						usage();
-					}
-					Rxtimeout = atoi(*++argv);
-					if (Rxtimeout<10 || Rxtimeout>1000)
-						usage();
-					break;
-				case 'T':
-					if (++Test > 1) {
-						chartest(1); chartest(2);
-						mode(0);  exit(0);
-					}
-					break;
-#ifndef vax11c
-				case 'u':
-					++Unlinkafter; break;
-#endif
-				case 'v':
-					++Verbose; break;
-				case 'w':
-					if (--argc < 1) {
-						usage();
-					}
-					Txwindow = atoi(*++argv);
-					if (Txwindow < 256)
-						Txwindow = 256;
-					Txwindow = (Txwindow/64) * 64;
-					Txwspac = Txwindow/4;
-					if (blkopt > Txwspac
-					 || (!blkopt && Txwspac < 1024))
-						blkopt = Txwspac;
-					break;
-				case 'X':
-					++Modem2; break;
-				case 'Y':
-					Lskipnocor = TRUE;
-					/* **** FALLL THROUGH TO **** */
-				case 'y':
-					Lzmanag = ZMCLOB; break;
-				default:
-					usage();
-				}
-			}
-		}
-		else if ( !npats && argc>0) {
-			if (argv[0][0]) {
-				npats=argc;
-				patts=argv;
-#ifndef vax11c
-				if ( !strcmp(*patts, "-"))
-					iofd = 1;
-#endif
-			}
-		}
-	}
-	if (npats < 1 && !Command && !Test) 
-		usage();
-	if (Verbose) {
-		if (freopen(LOGFILE, "a", stderr)==NULL) {
-			printf("Can't open log file %s\n",LOGFILE);
-			exit(0200);
-		}
-		setbuf(stderr, (char *)NULL);
-	}
-	if (Fromcu && !Quiet) {
-		if (Verbose == 0)
-			Verbose = 2;
-	}
-	vfile("%s %s for %s\n", Progname, VERSION, OS);
-
-	mode(1);
-
-	if (signal(SIGINT, bibi) == SIG_IGN) {
-		signal(SIGINT, SIG_IGN); signal(SIGKILL, SIG_IGN);
-	} else {
-		signal(SIGINT, bibi); signal(SIGKILL, bibi);
-	}
-	if ( !Fromcu)
-		signal(SIGQUIT, SIG_IGN);
-	signal(SIGTERM, bibi);
-
-	if ( !Modem2) {
-		if (!Nozmodem) {
-			printf("rz\r");  fflush(stdout);
-		}
-		countem(npats, patts);
-		if (!Nozmodem) {
-			stohdr(0L);
-			if (Command)
-				Txhdr[ZF0] = ZCOMMAND;
-			zshhdr(ZRQINIT, Txhdr);
-		}
-	}
-	fflush(stdout);
-
-	if (Command) {
-		if (getzrxinit()) {
-			Exitcode=0200; canit();
-		}
-		else if (zsendcmd(Cmdstr, 1+strlen(Cmdstr))) {
-			Exitcode=0200; canit();
-		}
-	} else if (wcsend(npats, patts)==ERROR) {
-		Exitcode=0200;
-		canit();
-	}
-	fflush(stdout);
-	mode(0);
-	dm = ((errcnt != 0) | Exitcode);
-	if (dm) {
-		cucheck();  exit(dm);
-	}
-	putc('\n',stderr);
-	exit(SS_NORMAL);
-	/*NOTREACHED*/
-}
-
-int wcsend(argc, argp)
-int argc;
-char *argp[];
-{
-	register int n;
-
-	Crcflg=FALSE;
-	firstsec=TRUE;
-	bytcnt = -1;
-	for (n=0; n<argc; ++n) {
-		Totsecs = 0;
-		if (wcs(argp[n])==ERROR)
-			return ERROR;
-	}
-	Totsecs = 0;
-	if (Filcnt==0) {	/* bitch if we couldn't open ANY files */
-		if ( !Modem2) {
-			Command = TRUE;
-			Cmdstr = "echo \"sz: Can't open any requested files\"";
-			if (getnak()) {
-				Exitcode=0200; canit();
-			}
-			if (!Zmodem)
-				canit();
-			else if (zsendcmd(Cmdstr, 1+strlen(Cmdstr))) {
-				Exitcode=0200; canit();
-			}
-			Exitcode = 1; return OK;
-		}
-		canit();
-		fprintf(stderr,"\r\nCan't open any requested files.\r\n");
-		return ERROR;
-	}
-	if (Zmodem)
-		saybibi();
-	else if ( !Modem2)
-		wctxpn("");
-	return OK;
-}
-
-int wcs(oname)
-char *oname;
-{
-	register c;
-	register char *p;
-	struct stat f;
-	char name[PATHLEN];
-
-	strcpy(name, oname);
-
-	if (Restricted) {
-		/* restrict pathnames to current tree or uucppublic */
-		if ( substr(name, "../")
-		 || (name[0]== '/' && strncmp(name, PUBDIR, strlen(PUBDIR))) ) {
-			canit();
-			fprintf(stderr,"\r\nsz:\tSecurity Violation\r\n");
-			return ERROR;
-		}
-	}
-
-	if ( !strcmp(oname, "-")) {
-		if ((p = getenv("ONAME")) && *p)
-			strcpy(name, p);
-		else
-			sprintf(name, "s%d.sz", getpid());
-		in = stdin;
-	}
-	else if ((in=fopen(oname, "r"))==NULL) {
-		++errcnt;
-		return OK;	/* pass over it, there may be others */
-	}
-	BEofseen = Eofseen = 0;  vpos = 0;
-	/* Check for directory or block special files */
-	fstat(fileno(in), &f);
-	c = f.st_mode & S_IFMT;
-	if (c == S_IFDIR || c == S_IFBLK) {
-		fclose(in);
-		return OK;
-	}
-
-	++Filcnt;
-	switch (wctxpn(name)) {
-	case ERROR:
-		return ERROR;
-	case ZSKIP:
-		return OK;
-	}
-	if (!Zmodem && wctx(f.st_size)==ERROR)
-		return ERROR;
-#ifndef vax11c
-	if (Unlinkafter)
-		unlink(oname);
-#endif
-	return 0;
-}
-
-/*
- * generate and transmit pathname block consisting of
- *  pathname (null terminated),
- *  file length, mode time and file mode in octal
- *  as provided by the Unix fstat call.
- *  N.B.: modifies the passed name, may extend it!
- */
-int wctxpn(name)
-char *name;
-{
-	register char *p, *q;
-	char name2[PATHLEN];
-	struct stat f;
-
-	if (Modem2) {
-		if ((in!=stdin) && *name && fstat(fileno(in), &f)!= -1) {
-			fprintf(stderr, "Sending %s, %ld blocks: ",
-			  name, f.st_size>>7);
-		}
-		fprintf(stderr, "Give your local XMODEM receive command now.\r\n");
-		return OK;
-	}
-	zperr("Awaiting pathname nak for %s", *name?name:"<END>");
-	if ( !Zmodem)
-		if (getnak())
-			return ERROR;
-
-	q = (char *) 0;
-	if (Dottoslash) {		/* change . to . */
-		for (p=name; *p; ++p) {
-			if (*p == '/')
-				q = p;
-			else if (*p == '.')
-				*(q=p) = '/';
-		}
-		if (q && strlen(++q) > 8) {	/* If name>8 chars */
-			q += 8;			/*   make it .ext */
-			strcpy(name2, q);	/* save excess of name */
-			*q = '.';
-			strcpy(++q, name2);	/* add it back */
-		}
-	}
-
-	for (p=name, q=txbuf ; *p; )
-		if ((*q++ = *p++) == '/' && !Fullname)
-			q = txbuf;
-	*q++ = 0;
-	p=q;
-	while (q < (txbuf + 1024))
-		*q++ = 0;
-	if (!Ascii && (in!=stdin) && *name && fstat(fileno(in), &f)!= -1)
-		sprintf(p, "%lu %lo %o 0 %d %ld", f.st_size, f.st_mtime,
-		  f.st_mode, Filesleft, Totalleft);
-	Totalleft -= f.st_size;
-	if (--Filesleft <= 0)
-		Totalleft = 0;
-	if (Totalleft < 0)
-		Totalleft = 0;
-
-	/* force 1k blocks if name won't fit in 128 byte block */
-	if (txbuf[125])
-		blklen=1024;
-	else {		/* A little goodie for IMP/KMD */
-		txbuf[127] = (f.st_size + 127) >>7;
-		txbuf[126] = (f.st_size + 127) >>15;
-	}
-	if (Zmodem)
-		return zsendfile(txbuf, 1+strlen(p)+(p-txbuf));
-	if (wcputsec(txbuf, 0, 128)==ERROR)
-		return ERROR;
-	return OK;
-}
-
-int getnak()
-{
-	register firstch;
-
-	Lastrx = 0;
-	for (;;) {
-		switch (firstch = readline(800)) {
-		case ZPAD:
-			if (getzrxinit())
-				return ERROR;
-			Ascii = 0;	/* Receiver does the conversion */
-			return FALSE;
-		case TIMEOUT:
-			zperr("Timeout on pathname");
-			return TRUE;
-		case WANTG:
-#ifdef MODE2OK
-			mode(2);	/* Set cbreak, XON/XOFF, etc. */
-#endif
-			Optiong = TRUE;
-			blklen=1024;
-		case WANTCRC:
-			Crcflg = TRUE;
-		case NAK:
-			return FALSE;
-		case CAN:
-			if ((firstch = readline(20)) == CAN && Lastrx == CAN)
-				return TRUE;
-		default:
-			break;
-		}
-		Lastrx = firstch;
-	}
-}
-
-
-int wctx(flen)
-long flen;
-{
-	register int thisblklen;
-	register int sectnum, attempts, firstch;
-	long charssent;
-
-	charssent = 0;  firstsec=TRUE;  thisblklen = blklen;
-	vfile("wctx:file length=%ld", flen);
-
-	while ((firstch=readline(Rxtimeout))!=NAK && firstch != WANTCRC
-	  && firstch != WANTG && firstch!=TIMEOUT && firstch!=CAN)
-		;
-	if (firstch==CAN) {
-		zperr("Receiver CANcelled");
-		return ERROR;
-	}
-	if (firstch==WANTCRC)
-		Crcflg=TRUE;
-	if (firstch==WANTG)
-		Crcflg=TRUE;
-	sectnum=0;
-	for (;;) {
-		if (flen <= (charssent + 896L))
-			thisblklen = 128;
-		if ( !filbuf(txbuf, thisblklen))
-			break;
-		if (wcputsec(txbuf, ++sectnum, thisblklen)==ERROR)
-			return ERROR;
-		charssent += thisblklen;
-	}
-	fclose(in);
-	attempts=0;
-	do {
-		purgeline();
-		sendline(EOT);
-		fflush(stdout);
-		++attempts;
-	}
-		while ((firstch=(readline(Rxtimeout)) != ACK) && attempts < RETRYMAX);
-	if (attempts == RETRYMAX) {
-		zperr("No ACK on EOT");
-		return ERROR;
-	}
-	else
-		return OK;
-}
-
-int wcputsec(buf, sectnum, cseclen)
-char *buf;
-int sectnum;
-int cseclen;	/* data length of this sector to send */
-{
-	register checksum, wcj;
-	register char *cp;
-	unsigned oldcrc;
-	int firstch;
-	int attempts;
-
-	firstch=0;	/* part of logic to detect CAN CAN */
-
-	if (Verbose>2)
-		fprintf(stderr, "Sector %3d %2dk\n", Totsecs, Totsecs/8 );
-	else if (Verbose>1)
-		fprintf(stderr, "\rSector %3d %2dk ", Totsecs, Totsecs/8 );
-	for (attempts=0; attempts <= RETRYMAX; attempts++) {
-		Lastrx= firstch;
-		sendline(cseclen==1024?STX:SOH);
-		sendline(sectnum);
-		sendline(-sectnum -1);
-		oldcrc=checksum=0;
-		for (wcj=cseclen,cp=buf; --wcj>=0; ) {
-			sendline(*cp);
-			oldcrc=updcrc((0377& *cp), oldcrc);
-			checksum += *cp++;
-		}
-		if (Crcflg) {
-			oldcrc=updcrc(0,updcrc(0,oldcrc));
-			sendline((int)oldcrc>>8);
-			sendline((int)oldcrc);
-		}
-		else
-			sendline(checksum);
-
-		if (Optiong) {
-			firstsec = FALSE; return OK;
-		}
-		firstch = readline(Rxtimeout);
-gotnak:
-		switch (firstch) {
-		case CAN:
-			if(Lastrx == CAN) {
-cancan:
-				zperr("Cancelled");  return ERROR;
-			}
-			break;
-		case TIMEOUT:
-			zperr("Timeout on sector ACK"); continue;
-		case WANTCRC:
-			if (firstsec)
-				Crcflg = TRUE;
-		case NAK:
-			zperr("NAK on sector"); continue;
-		case ACK: 
-			firstsec=FALSE;
-			Totsecs += (cseclen>>7);
-			return OK;
-		case ERROR:
-			zperr("Got burst for sector ACK"); break;
-		default:
-			zperr("Got %02x for sector ACK", firstch); break;
-		}
-		for (;;) {
-			Lastrx = firstch;
-			if ((firstch = readline(Rxtimeout)) == TIMEOUT)
-				break;
-			if (firstch == NAK || firstch == WANTCRC)
-				goto gotnak;
-			if (firstch == CAN && Lastrx == CAN)
-				goto cancan;
-		}
-	}
-	zperr("Retry Count Exceeded");
-	return ERROR;
-}
-
-/* fill buf with count chars padding with ^Z for CPM */
-int filbuf(buf, count)
-register char *buf;
-int count;
-{
-	register c, m;
-
-	if ( !Ascii) {
-		m = read(fileno(in), buf, count);
-		if (m <= 0)
-			return 0;
-		while (m < count)
-			buf[m++] = 032;
-		return count;
-	}
-	m=count;
-	if (Lfseen) {
-		*buf++ = 012; --m; Lfseen = 0;
-	}
-	while ((c=getc(in))!=EOF) {
-		if (c == 012) {
-			*buf++ = 015;
-			if (--m == 0) {
-				Lfseen = TRUE; break;
-			}
-		}
-		*buf++ =c;
-		if (--m == 0)
-			break;
-	}
-	if (m==count)
-		return 0;
-	else
-		while (--m>=0)
-			*buf++ = CPMEOF;
-	return count;
-}
-
-/* Fill buffer with blklen chars */
-int zfilbuf()
-{
-	int n;
-
-#ifdef TXBSIZE
-	/* We assume request is within buffer, or just beyond */
-	txbuf = Txb + (bytcnt & TXBMASK);
-	if (vpos <= bytcnt) {
-		n = fread(txbuf, 1, blklen, in);
-		vpos += n;
-		if (n < blklen)
-			Eofseen = 1;
-		return n;
-	}
-	if (vpos >= (bytcnt+blklen))
-		return blklen;
-	/* May be a short block if crash recovery etc. */
-	Eofseen = BEofseen;
-	return (vpos - bytcnt);
-#else
-	n = fread(txbuf, 1, blklen, in);
-	if (n < blklen)
-		Eofseen = 1;
-	return n;
-#endif
-}
-
-#ifdef TXBSIZE
-int fooseek(fptr, pos, whence)
-FILE *fptr;
-long pos;
-{
-	int m, n;
-
-	vfile("fooseek: pos =%lu vpos=%lu Canseek=%d", pos, vpos, Canseek);
-	/* Seek offset < current buffer */
-	if (pos < (vpos -TXBSIZE +1024)) {
-		BEofseen = 0;
-		if (Canseek > 0) {
-			vpos = pos & ~TXBMASK;
-			if (vpos >= pos)
-				vpos -= TXBSIZE;
-			if (fseek(fptr, vpos, 0))
-				return 1;
-		}
-		else if (Canseek == 0)
-			if (fseek(fptr, vpos = 0L, 0))
-				return 1;
-		else
-			return 1;
-		while (vpos <= pos) {
-			n = fread(Txb, 1, TXBSIZE, fptr);
-			vpos += n;
-			vfile("n=%d vpos=%ld", n, vpos);
-			if (n < TXBSIZE) {
-				BEofseen = 1;
-				break;
-			}
-		}
-		vfile("vpos=%ld", vpos);
-		return 0;
-	}
-	/* Seek offset > current buffer (crash recovery, etc.) */
-	if (pos > vpos) {
-		if (Canseek)
-			if (fseek(fptr, vpos = (pos & ~TXBMASK), 0))
-				return 1;
-		while (vpos <= pos) {
-			txbuf = Txb + (vpos & TXBMASK);
-			m = TXBSIZE - (vpos & TXBMASK);
-			n = fread(txbuf, 1, m, fptr);
-			vpos += n;
-			vfile("bo=%d n=%d vpos=%ld", txbuf-Txb, n, vpos);
-			if (m < n) {
-				BEofseen = 1;
-				break;
-			}
-		}
-		return 0;
-	}
-	/* Seek offset is within current buffer */
-	vfile("vpos=%ld", vpos);
-	return 0;
-}
-#define fseek fooseek
-#endif
-
-
-/* VARARGS1 */
-void vfile(f, a, b, c)
-register char *f,*a,*b,*c;
-{
-	if (Verbose > 2) {
-		fprintf(stderr, f, a, b, c);
-		fprintf(stderr, "\n");
-	}
-}
-
-
-void alrm(sig)
-int sig;
-{
-	longjmp(tohere, -1);
-}
-
-
-#ifndef vax11c
-/*
- * readline(timeout) reads character(s) from file descriptor 0
- * timeout is in tenths of seconds
- */
-int readline(timeout)
-int timeout;
-{
-	register int c;
-	static char byt[1];
-
-	fflush(stdout);
-	if (setjmp(tohere)) {
-		zperr("TIMEOUT");
-		return TIMEOUT;
-	}
-	c = timeout/10;
-	if (c<2)
-		c=2;
-	if (Verbose>5) {
-		fprintf(stderr, "Timeout=%d Calling alarm(%d) ", timeout, c);
-	}
-	signal(SIGALRM, alrm); alarm(c);
-	c=read(iofd, byt, 1);
-	alarm(0);
-	if (Verbose>5)
-		fprintf(stderr, "ret %x\n", byt[0]);
-	if (c<1)
-		return TIMEOUT;
-	return (byt[0]&0377);
-}
-
-void flushmo()
-{
-	fflush(stdout);
-}
-
-
-void purgeline()
-{
-#ifdef USG
-	ioctl(iofd, TCFLSH, 0);
-#else
-	lseek(iofd, 0L, 2);
-#endif
-}
-#endif
-
-/* send cancel string to get the other end to shut up */
-void canit()
-{
-	static char canistr[] = {
-	 24,24,24,24,24,24,24,24,24,24,8,8,8,8,8,8,8,8,8,8,0
-	};
-
-#ifdef vax11c
-	raw_wbuf(strlen(canistr), canistr);
-	purgeline();
-#else
-	printf(canistr);
-	fflush(stdout);
-#endif
-}
-
-
-/*
- * Log an error
- */
-/*VARARGS1*/
-void zperr(s,p,u)
-char *s, *p, *u;
-{
-	if (Verbose <= 0)
-		return;
-	fprintf(stderr, "\nRetry %d: ", errors);
-	fprintf(stderr, s, p, u);
-	fprintf(stderr, "\n");
-}
-
-/*
- * substr(string, token) searches for token in string s
- * returns pointer to token within string if found, NULL otherwise
- */
-char *
-substr(s, t)
-register char *s,*t;
-{
-	register char *ss,*tt;
-	/* search for first char of token */
-	for (ss=s; *s; s++)
-		if (*s == *t)
-			/* compare token with substring */
-			for (ss=s,tt=t; ;) {
-				if (*tt == 0)
-					return s;
-				if (*ss++ != *tt++)
-					break;
-			}
-	return (char *)NULL;
-}
-
-char *babble[] = {
-#ifdef vax11c
-	"	Send file(s) with ZMODEM Protocol",
-	"Usage:	sz [-2+abdefkLlNnquvwYy] [-] file ...",
-	"	sz [-2Ceqv] -c COMMAND",
-	"	\\ Force next option letter to upper case",
-#else
-	"Send file(s) with ZMODEM/YMODEM/XMODEM Protocol",
-	"	(Y) = Option applies to YMODEM only",
-	"	(Z) = Option applies to ZMODEM only",
-	"Usage:	sz [-2+abdefkLlNnquvwYy] [-] file ...",
-	"	sz [-2Ceqv] -c COMMAND",
-	"	sb [-2adfkquv] [-] file ...",
-	"	sx [-2akquv] [-] file",
-#endif
-#ifdef CSTOPB
-	"	2 Use 2 stop bits",
-#endif
-	"	+ Append to existing destination file (Z)",
-	"	a (ASCII) change NL to CR/LF",
-	"	b Binary file transfer override",
-	"	c send COMMAND (Z)",
-#ifndef vax11c
-	"	d Change '.' to '/' in pathnames (Y/Z)",
-#endif
-	"	e Escape all control characters (Z)",
-	"	f send Full pathname (Y/Z)",
-	"	i send COMMAND, ack Immediately (Z)",
-	"	k Send 1024 byte packets (Y)",
-	"	L N Limit subpacket length to N bytes (Z)",
-	"	l N Limit frame length to N bytes (l>=L) (Z)",
-	"	n send file if source newer (Z)",
-	"	N send file if source newer or longer (Z)",
-	"	o Use 16 bit CRC instead of 32 bit CRC (Z)",
-	"	p Protect existing destination file (Z)",
-	"	r Resume/Recover interrupted file transfer (Z)",
-	"	q Quiet (no progress reports)",
-#ifndef vax11c
-	"	u Unlink file after transmission",
-#endif
-	"	v Verbose - provide debugging information",
-	"	w N Window is N bytes (Z)",
-	"	Y Yes, overwrite existing file, skip if not present at rx (Z)",
-	"	y Yes, overwrite existing file (Z)",
-	"- as pathname sends standard input as sPID.sz or environment ONAME",
-	""
-};
-
-int usage()
-{
-	char **pp;
-
-	for (pp=babble; **pp; ++pp)
-		fprintf(stderr, "%s\n", *pp);
-	fprintf(stderr, "%s for %s by Chuck Forsberg, Omen Technology INC\n",
-	 VERSION, OS);
-	fprintf(stderr, "\t\t\042The High Reliability Software\042\n");
-	cucheck();
-	exit(SS_NORMAL);
-}
-
-/*
- * Get the receiver's init parameters
- */
-int getzrxinit()
-{
-	register n;
-	struct stat f;
-
-	for (n=10; --n>=0; ) {
-		
-		switch (zgethdr(Rxhdr, 1)) {
-		case ZCHALLENGE:	/* Echo receiver's challenge numbr */
-			stohdr(Rxpos);
-			zshhdr(ZACK, Txhdr);
-			continue;
-		case ZCOMMAND:		/* They didn't see out ZRQINIT */
-			stohdr(0L);
-			zshhdr(ZRQINIT, Txhdr);
-			continue;
-		case ZRINIT:
-			Rxflags = 0377 & Rxhdr[ZF0];
-			Txfcs32 = (Wantfcs32 && (Rxflags & CANFC32));
-			Zctlesc |= Rxflags & TESCCTL;
-			Rxbuflen = (0377 & Rxhdr[ZP0])+((0377 & Rxhdr[ZP1])<<8);
-			if ( !(Rxflags & CANFDX))
-				Txwindow = 0;
-			vfile("Rxbuflen=%d Tframlen=%d", Rxbuflen, Tframlen);
-			if ( !Fromcu)
-				signal(SIGINT, SIG_IGN);
-#ifdef MODE2OK
-			mode(2);	/* Set cbreak, XON/XOFF, etc. */
-#endif
-#ifndef READCHECK
-#ifndef USG
-			/* Use 1024 byte frames if no sample/interrupt */
-			if (Rxbuflen < 32 || Rxbuflen > 1024) {
-				Rxbuflen = 1024;
-				vfile("Rxbuflen=%d", Rxbuflen);
-			}
-#endif
-#endif
-			/* Override to force shorter frame length */
-			if (Rxbuflen && (Rxbuflen>Tframlen) && (Tframlen>=32))
-				Rxbuflen = Tframlen;
-			if ( !Rxbuflen && (Tframlen>=32) && (Tframlen<=1024))
-				Rxbuflen = Tframlen;
-			vfile("Rxbuflen=%d", Rxbuflen);
-
-#ifndef vax11c
-			/* If using a pipe for testing set lower buf len */
-			fstat(iofd, &f);
-			if ((f.st_mode & S_IFMT) != S_IFCHR) {
-				Rxbuflen = 1024;
-			}
-#endif
-#ifdef BADSEEK
-			Canseek = 0;
-			Txwindow = TXBSIZE - 1024;
-			Txwspac = TXBSIZE/4;
-#endif
-			/*
-			 * If input is not a regular file, force ACK's to
-			 *  prevent running beyond the buffer limits
-			 */
-			if ( !Command) {
-				fstat(fileno(in), &f);
-				if ((f.st_mode & S_IFMT) != S_IFREG) {
-					Canseek = -1;
-#ifdef TXBSIZE
-					Txwindow = TXBSIZE - 1024;
-					Txwspac = TXBSIZE/4;
-#else
-					return ERROR;
-#endif
-				}
-			}
-			/* Set initial subpacket length */
-			if (blklen < 1024) {	/* Command line override? */
-				if (Baudrate > 300)
-					blklen = 256;
-				if (Baudrate > 1200)
-					blklen = 512;
-				if (Baudrate > 2400)
-					blklen = 1024;
-			}
-			if (Rxbuflen && blklen>Rxbuflen)
-				blklen = Rxbuflen;
-			if (blkopt && blklen > blkopt)
-				blklen = blkopt;
-			vfile("Rxbuflen=%d blklen=%d", Rxbuflen, blklen);
-			vfile("Txwindow = %u Txwspac = %d", Txwindow, Txwspac);
-
-			return (sendzsinit());
-		case ZCAN:
-		case TIMEOUT:
-			return ERROR;
-		case ZRQINIT:
-			if (Rxhdr[ZF0] == ZCOMMAND)
-				continue;
-		default:
-			zshhdr(ZNAK, Txhdr);
-			continue;
-		}
-	}
-	return ERROR;
-}
-
-/* Send send-init information */
-int sendzsinit()
-{
-	register c;
-
-	if (Myattn[0] == '\0' && (!Zctlesc || (Rxflags & TESCCTL)))
-		return OK;
-	errors = 0;
-	for (;;) {
-		stohdr(0L);
-		if (Zctlesc) {
-			Txhdr[ZF0] |= TESCCTL; zshhdr(ZSINIT, Txhdr);
-		}
-		else
-			zsbhdr(ZSINIT, Txhdr);
-		zsdata(Myattn, 1+strlen(Myattn), ZCRCW);
-		c = zgethdr(Rxhdr, 1);
-		switch (c) {
-		case ZCAN:
-			return ERROR;
-		case ZACK:
-			return OK;
-		default:
-			if (++errors > 19)
-				return ERROR;
-			continue;
-		}
-	}
-}
-
-/* Send file name and related info */
-int zsendfile(buf, blen)
-char *buf;
-int blen;
-{
-	register c;
-	register UNSL long crc;
-
-	for (;;) {
-		Txhdr[ZF0] = Lzconv;	/* file conversion request */
-		Txhdr[ZF1] = Lzmanag;	/* file management request */
-		if (Lskipnocor)
-			Txhdr[ZF1] |= ZMSKNOLOC;
-		Txhdr[ZF2] = Lztrans;	/* file transport request */
-		Txhdr[ZF3] = 0;
-		zsbhdr(ZFILE, Txhdr);
-		zsdata(buf, blen, ZCRCW);
-again:
-		c = zgethdr(Rxhdr, 1);
-		switch (c) {
-		case ZRINIT:
-			while ((c = readline(50)) > 0)
-				if (c == ZPAD) {
-					goto again;
-				}
-			/* **** FALL THRU TO **** */
-		default:
-			continue;
-		case ZCAN:
-		case TIMEOUT:
-		case ZABORT:
-		case ZFIN:
-			return ERROR;
-		case ZCRC:
-			crc = 0xFFFFFFFFL;
-			if (Canseek >= 0) {
-				while (((c = getc(in)) != EOF) && --Rxpos)
-					crc = UPDC32(c, crc);
-				crc = ~crc;
-				clearerr(in);	/* Clear EOF */
-				fseek(in, 0L, 0);
-			}
-			stohdr(crc);
-			zsbhdr(ZCRC, Txhdr);
-			goto again;
-		case ZSKIP:
-			fclose(in); return c;
-		case ZRPOS:
-			/*
-			 * Suppress zcrcw request otherwise triggered by
-			 * lastyunc==bytcnt
-			 */
-			if (Rxpos && fseek(in, Rxpos, 0))
-				return ERROR;
-			Lastsync = (bytcnt = Txpos = Rxpos) -1;
-			return zsendfdata();
-		}
-	}
-}
-
-/* Send the data in the file */
-int zsendfdata()
-{
-	register c, e, n;
-	register int newcnt;
-	register long tcount = 0;
-	int junkcount;		/* Counts garbage chars received by TX */
-	static int tleft = 6;	/* Counter for test mode */
-
-	Lrxpos = 0;
-	junkcount = 0;
-	Beenhereb4 = FALSE;
-somemore:
-	if (setjmp(intrjmp)) {
-waitack:
-		junkcount = 0;
-		c = getinsync(0);
-gotack:
-		switch (c) {
-		default:
-		case ZCAN:
-			fclose(in);
-			return ERROR;
-		case ZSKIP:
-			fclose(in);
-			return c;
-		case ZACK:
-		case ZRPOS:
-			break;
-		case ZRINIT:
-			return OK;
-		}
-#ifdef READCHECK
-		/*
-		 * If the reverse channel can be tested for data,
-		 *  this logic may be used to detect error packets
-		 *  sent by the receiver, in place of setjmp/longjmp
-		 *  rdchk(fdes) returns non 0 if a character is available
-		 */
-		while (rdchk(iofd)) {
-#ifdef SV
-			switch (checked)
-#else
-			switch (readline(1))
-#endif
-			{
-			case CAN:
-			case ZPAD:
-				c = getinsync(1);
-				goto gotack;
-			case XOFF:		/* Wait a while for an XON */
-			case XOFF|0200:
-				readline(100);
-			}
-		}
-#endif
-	}
-
-	if ( !Fromcu)
-		signal(SIGINT, onintr);
-	newcnt = Rxbuflen;
-	Txwcnt = 0;
-	stohdr(Txpos);
-	zsbhdr(ZDATA, Txhdr);
-
-	/*
-	 * Special testing mode.  This should force receiver to Attn,ZRPOS
-	 *  many times.  Each time the signal should be caught, causing the
-	 *  file to be started over from the beginning.
-	 */
-	if (Test) {
-		if ( --tleft)
-			while (tcount < 20000) {
-				printf(qbf); fflush(stdout);
-				tcount += strlen(qbf);
-#ifdef READCHECK
-				while (rdchk(iofd)) {
-#ifdef SV
-					switch (checked)
-#else
-					switch (readline(1))
-#endif
-					{
-					case CAN:
-					case ZPAD:
-#ifdef TCFLSH
-						ioctl(iofd, TCFLSH, 1);
-#endif
-						goto waitack;
-					case XOFF:	/* Wait for XON */
-					case XOFF|0200:
-						readline(100);
-					}
-				}
-#endif
-			}
-		signal(SIGINT, SIG_IGN); canit();
-		sleep(3); purgeline(); mode(0);
-		printf("\nsz: Tcount = %ld\n", tcount);
-		if (tleft) {
-			printf("ERROR: Interrupts Not Caught\n");
-			exit(1);
-		}
-		exit(SS_NORMAL);
-	}
-
-	do {
-		n = zfilbuf();
-		if (Eofseen)
-			e = ZCRCE;
-		else if (junkcount > 3)
-			e = ZCRCW;
-		else if (bytcnt == Lastsync)
-			e = ZCRCW;
-		else if (Rxbuflen && (newcnt -= n) <= 0)
-			e = ZCRCW;
-		else if (Txwindow && (Txwcnt += n) >= Txwspac) {
-			Txwcnt = 0;  e = ZCRCQ;
-		}
-		else
-			e = ZCRCG;
-		if (Verbose>1)
-			fprintf(stderr, "\r%7ld ZMODEM%s    ",
-			  Txpos, Crc32t?" CRC-32":"");
-		zsdata(txbuf, n, e);
-		bytcnt = Txpos += n;
-		if (e == ZCRCW)
-			goto waitack;
-#ifdef READCHECK
-		/*
-		 * If the reverse channel can be tested for data,
-		 *  this logic may be used to detect error packets
-		 *  sent by the receiver, in place of setjmp/longjmp
-		 *  rdchk(fdes) returns non 0 if a character is available
-		 */
-		fflush(stdout);
-		while (rdchk(iofd)) {
-#ifdef SV
-			switch (checked)
-#else
-			switch (readline(1))
-#endif
-			{
-			case CAN:
-			case ZPAD:
-				c = getinsync(1);
-				if (c == ZACK)
-					break;
-#ifdef TCFLSH
-				ioctl(iofd, TCFLSH, 1);
-#endif
-				/* zcrce - dinna wanna starta ping-pong game */
-				zsdata(txbuf, 0, ZCRCE);
-				goto gotack;
-			case XOFF:		/* Wait a while for an XON */
-			case XOFF|0200:
-				readline(100);
-			default:
-				++junkcount;
-			}
-		}
-#endif	/* READCHECK */
-		if (Txwindow) {
-			while ((tcount = Txpos - Lrxpos) >= Txwindow) {
-				vfile("%ld window >= %u", tcount, Txwindow);
-				if (e != ZCRCQ)
-					zsdata(txbuf, 0, e = ZCRCQ);
-				c = getinsync(1);
-				if (c != ZACK) {
-#ifdef TCFLSH
-					ioctl(iofd, TCFLSH, 1);
-#endif
-					zsdata(txbuf, 0, ZCRCE);
-					goto gotack;
-				}
-			}
-			vfile("window = %ld", tcount);
-		}
-	} while (!Eofseen);
-	if ( !Fromcu)
-		signal(SIGINT, SIG_IGN);
-
-	for (;;) {
-		stohdr(Txpos);
-		zsbhdr(ZEOF, Txhdr);
-		switch (getinsync(0)) {
-		case ZACK:
-			continue;
-		case ZRPOS:
-			goto somemore;
-		case ZRINIT:
-			return OK;
-		case ZSKIP:
-			fclose(in);
-			return c;
-		default:
-			fclose(in);
-			return ERROR;
-		}
-	}
-}
-
-/*
- * Respond to receiver's complaint, get back in sync with receiver
- */
-int getinsync(flag)
-int flag;
-{
-	register int c;
-
-	for (;;) {
-		if (Test) {
-			printf("\r\n\n\n***** Signal Caught *****\r\n");
-			Rxpos = 0; c = ZRPOS;
-		} else
-			c = zgethdr(Rxhdr, 0);
-		switch (c) {
-		case ZCAN:
-		case ZABORT:
-		case ZFIN:
-		case TIMEOUT:
-			return ERROR;
-		case ZRPOS:
-			/* ************************************* */
-			/*  If sending to a buffered modem, you  */
-			/*   might send a break at this point to */
-			/*   dump the modem's buffer.		 */
-			clearerr(in);	/* In case file EOF seen */
-			if (fseek(in, Rxpos, 0))
-				return ERROR;
-			Eofseen = 0;
-			bytcnt = Lrxpos = Txpos = Rxpos;
-			if (Lastsync == Rxpos) {
-				if (++Beenhereb4 > 4)
-					if (blklen > 32)
-						blklen /= 2;
-			}
-			Lastsync = Rxpos;
-			return c;
-		case ZACK:
-			Lrxpos = Rxpos;
-			if (flag || Txpos == Rxpos)
-				return ZACK;
-			continue;
-		case ZRINIT:
-		case ZSKIP:
-			fclose(in);
-			return c;
-		case ERROR:
-		default:
-			zsbhdr(ZNAK, Txhdr);
-			continue;
-		}
-	}
-}
-
-
-/* Say "bibi" to the receiver, try to do it cleanly */
-void saybibi()
-{
-	for (;;) {
-		stohdr(0L);		/* CAF Was zsbhdr - minor change */
-		zshhdr(ZFIN, Txhdr);	/*  to make debugging easier */
-		switch (zgethdr(Rxhdr, 0)) {
-		case ZFIN:
-			sendline('O'); sendline('O'); flushmo();
-		case ZCAN:
-		case TIMEOUT:
-			return;
-		}
-	}
-}
-
-/* Local screen character display function */
-void bttyout(c)
-int c;
-{
-	if (Verbose)
-		putc(c, stderr);
-}
-
-/* Send command and related info */
-int zsendcmd(buf, blen)
-char *buf;
-int blen;
-{
-	register c;
-	long cmdnum;
-
-	cmdnum = getpid();
-	errors = 0;
-	for (;;) {
-		stohdr(cmdnum);
-		Txhdr[ZF0] = Cmdack1;
-		zsbhdr(ZCOMMAND, Txhdr);
-		zsdata(buf, blen, ZCRCW);
-listen:
-		Rxtimeout = 100;		/* Ten second wait for resp. */
-		c = zgethdr(Rxhdr, 1);
-
-		switch (c) {
-		case ZRINIT:
-			goto listen;	/* CAF 8-21-87 */
-		case ERROR:
-		case TIMEOUT:
-			if (++errors > Cmdtries)
-				return ERROR;
-			continue;
-		case ZCAN:
-		case ZABORT:
-		case ZFIN:
-		case ZSKIP:
-		case ZRPOS:
-			return ERROR;
-		default:
-			if (++errors > 20)
-				return ERROR;
-			continue;
-		case ZCOMPL:
-			Exitcode = Rxpos;
-			saybibi();
-			return OK;
-		case ZRQINIT:
-#ifdef vax11c		/* YAMP :== Yet Another Missing Primitive */
-			return ERROR;
-#else
-			vfile("******** RZ *******");
-			system("rz");
-			vfile("******** SZ *******");
-			goto listen;
-#endif
-		}
-	}
-}
-
-/*
- * If called as sb use YMODEM protocol
- */
-void chkinvok(s)
-char *s;
-{
-#ifdef vax11c
-	Progname = "sz";
-#else
-	register char *p;
-
-	p = s;
-	while (*p == '-')
-		s = ++p;
-	while (*p)
-		if (*p++ == '/')
-			s = p;
-	if (*s == 'v') {
-		Verbose=1; ++s;
-	}
-	Progname = s;
-	if (s[0]=='s' && s[1]=='b') {
-		Nozmodem = TRUE; blklen=1024;
-	}
-	if (s[0]=='s' && s[1]=='x') {
-		Modem2 = TRUE;
-	}
-#endif
-}
-
-void countem(argc, argv)
-int argc;
-register char **argv;
-{
-	register c;
-	struct stat f;
-
-	for (Totalleft = 0, Filesleft = 0; --argc >=0; ++argv) {
-		f.st_size = -1;
-		if (Verbose>2) {
-			fprintf(stderr, "\nCountem: %03d %s ", argc, *argv);
-			fflush(stderr);
-		}
-		if (access(*argv, 04) >= 0 && stat(*argv, &f) >= 0) {
-			c = f.st_mode & S_IFMT;
-			if (c != S_IFDIR && c != S_IFBLK) {
-				++Filesleft;  Totalleft += f.st_size;
-			}
-		}
-		if (Verbose>2)
-			fprintf(stderr, " %ld", f.st_size);
-	}
-	if (Verbose>2)
-		fprintf(stderr, "\ncountem: Total %d %ld\n",
-		  Filesleft, Totalleft);
-}
-
-void chartest(m)
-int m;
-{
-	register int n;
-
-	mode(m);
-	printf("\r\n\nCharacter Transparency Test Mode %d\r\n", m);
-	printf("If Pro-YAM/ZCOMM is not displaying ^M hit ALT-V NOW.\r\n");
-	printf("Hit Enter.\021");  fflush(stdout);
-	readline(500);
-
-	for (n = 0; n < 256; ++n) {
-		if (!(n%8))
-			printf("\r\n");
-		printf("%02x ", n);  fflush(stdout);
-		sendline(n);	flushmo();
-		printf("  ");  fflush(stdout);
-		if (n == 127) {
-			printf("Hit Enter.\021");  fflush(stdout);
-			readline(500);
-			printf("\r\n");  fflush(stdout);
-		}
-	}
-	printf("\021\r\nEnter Characters, echo is in hex.\r\n");
-	printf("Hit SPACE or pause 40 seconds for exit.\r\n");
-
-	while (n != TIMEOUT && n != ' ') {
-		n = readline(400);
-		printf("%02x\r\n", n);
-		fflush(stdout);
-	}
-	printf("\r\nMode %d character transparency test ends.\r\n", m);
-	fflush(stdout);
-}
-
-/* End of sz.c */
Index: trunk/minix/commands/zmodem/zm.c
===================================================================
--- trunk/minix/commands/zmodem/zm.c	(revision 9)
+++ 	(revision )
@@ -1,789 +1,0 @@
-/*
- *   Z M . C
- *    ZMODEM protocol primitives
- *    05-09-88  Chuck Forsberg Omen Technology Inc
- *
- * Entry point Functions:
- *	zsbhdr(type, hdr) send binary header
- *	zshhdr(type, hdr) send hex header
- *	zgethdr(hdr, eflag) receive header - binary or hex
- *	zsdata(buf, len, frameend) send data
- *	zrdata(buf, len) receive data
- *	stohdr(pos) store position data in Txhdr
- *	long rclhdr(hdr) recover position offset from header
- */
-
-#ifndef CANFDX
-#include "zmodem.h"
-#endif
-int Rxtimeout = 100;		/* Tenths of seconds to wait for something */
-
-#ifndef UNSL
-#define UNSL
-#endif
-
-
-/* Globals used by ZMODEM functions */
-int Rxframeind;		/* ZBIN ZBIN32, or ZHEX type of frame received */
-int Rxtype;		/* Type of header received */
-int Rxcount;		/* Count of data bytes received */
-char Rxhdr[4];		/* Received header */
-char Txhdr[4];		/* Transmitted header */
-long Rxpos;		/* Received file position */
-long Txpos;		/* Transmitted file position */
-int Txfcs32;		/* TURE means send binary frames with 32 bit FCS */
-int Crc32t;		/* Display flag indicating 32 bit CRC being sent */
-int Crc32;		/* Display flag indicating 32 bit CRC being received */
-int Znulls;		/* Number of nulls to send at beginning of ZDATA hdr */
-char Attn[ZATTNLEN+1];	/* Attention string rx sends to tx on err */
-
-static lastsent;	/* Last char we sent */
-static Not8bit;		/* Seven bits seen on header */
-
-static char *frametypes[] = {
-	"Carrier Lost",		/* -3 */
-	"TIMEOUT",		/* -2 */
-	"ERROR",		/* -1 */
-#define FTOFFSET 3
-	"ZRQINIT",
-	"ZRINIT",
-	"ZSINIT",
-	"ZACK",
-	"ZFILE",
-	"ZSKIP",
-	"ZNAK",
-	"ZABORT",
-	"ZFIN",
-	"ZRPOS",
-	"ZDATA",
-	"ZEOF",
-	"ZFERR",
-	"ZCRC",
-	"ZCHALLENGE",
-	"ZCOMPL",
-	"ZCAN",
-	"ZFREECNT",
-	"ZCOMMAND",
-	"ZSTDERR",
-	"xxxxx"
-#define FRTYPES 22	/* Total number of frame types in this array */
-			/*  not including psuedo negative entries */
-};
-
-static char badcrc[] = "Bad CRC";
-
-/* Send ZMODEM binary header hdr of type type */
-void zsbhdr(type, hdr)
-int type;
-register char *hdr;
-{
-	register int n;
-	register unsigned short crc;
-
-	vfile("zsbhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(hdr));
-	if (type == ZDATA)
-		for (n = Znulls; --n >=0; )
-			xsendline(0);
-
-	xsendline(ZPAD); xsendline(ZDLE);
-
-	if (Crc32t=Txfcs32)
-		zsbh32(hdr, type);
-	else {
-		xsendline(ZBIN); zsendline(type); crc = updcrc(type, 0);
-
-		for (n=4; --n >= 0; ++hdr) {
-			zsendline(*hdr);
-			crc = updcrc((0377& *hdr), crc);
-		}
-		crc = updcrc(0,updcrc(0,crc));
-		zsendline(crc>>8);
-		zsendline(crc);
-	}
-	if (type != ZDATA)
-		flushmo();
-}
-
-
-/* Send ZMODEM binary header hdr of type type */
-void zsbh32(hdr, type)
-register char *hdr;
-int type;
-{
-	register int n;
-	register UNSL long crc;
-
-	xsendline(ZBIN32);  zsendline(type);
-	crc = 0xFFFFFFFFL; crc = UPDC32(type, crc);
-
-	for (n=4; --n >= 0; ++hdr) {
-		crc = UPDC32((0377 & *hdr), crc);
-		zsendline(*hdr);
-	}
-	crc = ~crc;
-	for (n=4; --n >= 0;) {
-		zsendline((int)crc);
-		crc >>= 8;
-	}
-}
-
-/* Send ZMODEM HEX header hdr of type type */
-void zshhdr(type, hdr)
-int type;
-register char *hdr;
-{
-	register int n;
-	register unsigned short crc;
-
-	vfile("zshhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(hdr));
-	sendline(ZPAD); sendline(ZPAD); sendline(ZDLE); sendline(ZHEX);
-	zputhex(type);
-	Crc32t = 0;
-
-	crc = updcrc(type, 0);
-	for (n=4; --n >= 0; ++hdr) {
-		zputhex(*hdr); crc = updcrc((0377 & *hdr), crc);
-	}
-	crc = updcrc(0,updcrc(0,crc));
-	zputhex(crc>>8); zputhex(crc);
-
-	/* Make it printable on remote machine */
-	sendline(015); sendline(0212);
-	/*
-	 * Uncork the remote in case a fake XOFF has stopped data flow
-	 */
-	if (type != ZFIN && type != ZACK)
-		sendline(021);
-	flushmo();
-}
-
-/*
- * Send binary array buf of length length, with ending ZDLE sequence frameend
- */
-static char *Zendnames[] = { "ZCRCE", "ZCRCG", "ZCRCQ", "ZCRCW"};
-
-void zsdata(buf, length, frameend)
-register char *buf;
-int length;
-int frameend;
-{
-	register unsigned short crc;
-
-	vfile("zsdata: %d %s", length, Zendnames[(frameend-ZCRCE)&3]);
-	if (Crc32t)
-		zsda32(buf, length, frameend);
-	else {
-		crc = 0;
-		for (;--length >= 0; ++buf) {
-			zsendline(*buf); crc = updcrc((0377 & *buf), crc);
-		}
-		xsendline(ZDLE); xsendline(frameend);
-		crc = updcrc(frameend, crc);
-
-		crc = updcrc(0,updcrc(0,crc));
-		zsendline(crc>>8); zsendline(crc);
-	}
-	if (frameend == ZCRCW) {
-		xsendline(XON);  flushmo();
-	}
-}
-
-void zsda32(buf, length, frameend)
-register char *buf;
-int length;
-int frameend;
-{
-	register int c;
-	register UNSL long crc;
-
-	crc = 0xFFFFFFFFL;
-	for (;--length >= 0; ++buf) {
-		c = *buf & 0377;
-		if (c & 0140)
-			xsendline(lastsent = c);
-		else
-			zsendline(c);
-		crc = UPDC32(c, crc);
-	}
-	xsendline(ZDLE); xsendline(frameend);
-	crc = UPDC32(frameend, crc);
-
-	crc = ~crc;
-	for (length=4; --length >= 0;) {
-		zsendline((int)crc);  crc >>= 8;
-	}
-}
-
-/*
- * Receive array buf of max length with ending ZDLE sequence
- *  and CRC.  Returns the ending character or error code.
- *  NB: On errors may store length+1 bytes!
- */
-int zrdata(buf, length)
-register char *buf;
-int length;
-{
-	register int c;
-	register unsigned short crc;
-	register char *end;
-	register int d;
-
-	if (Rxframeind == ZBIN32)
-		return zrdat32(buf, length);
-
-	crc = Rxcount = 0;  end = buf + length;
-	while (buf <= end) {
-		if ((c = zdlread()) & ~0377) {
-crcfoo:
-			switch (c) {
-			case GOTCRCE:
-			case GOTCRCG:
-			case GOTCRCQ:
-			case GOTCRCW:
-				crc = updcrc((d=c)&0377, crc);
-				if ((c = zdlread()) & ~0377)
-					goto crcfoo;
-				crc = updcrc(c, crc);
-				if ((c = zdlread()) & ~0377)
-					goto crcfoo;
-				crc = updcrc(c, crc);
-				if (crc & 0xFFFF) {
-					zperr(badcrc);
-					return ERROR;
-				}
-				Rxcount = length - (end - buf);
-				vfile("zrdata: %d  %s", Rxcount,
-				 Zendnames[(d-GOTCRCE)&3]);
-				return d;
-			case GOTCAN:
-				zperr("Sender Canceled");
-				return ZCAN;
-			case TIMEOUT:
-				zperr("TIMEOUT");
-				return c;
-			default:
-				zperr("Bad data subpacket");
-				return c;
-			}
-		}
-		*buf++ = c;
-		crc = updcrc(c, crc);
-	}
-	zperr("Data subpacket too long");
-	return ERROR;
-}
-
-int zrdat32(buf, length)
-register char *buf;
-int length;
-{
-	register int c;
-	register UNSL long crc;
-	register char *end;
-	register int d;
-
-	crc = 0xFFFFFFFFL;  Rxcount = 0;  end = buf + length;
-	while (buf <= end) {
-		if ((c = zdlread()) & ~0377) {
-crcfoo:
-			switch (c) {
-			case GOTCRCE:
-			case GOTCRCG:
-			case GOTCRCQ:
-			case GOTCRCW:
-				d = c;  c &= 0377;
-				crc = UPDC32(c, crc);
-				if ((c = zdlread()) & ~0377)
-					goto crcfoo;
-				crc = UPDC32(c, crc);
-				if ((c = zdlread()) & ~0377)
-					goto crcfoo;
-				crc = UPDC32(c, crc);
-				if ((c = zdlread()) & ~0377)
-					goto crcfoo;
-				crc = UPDC32(c, crc);
-				if ((c = zdlread()) & ~0377)
-					goto crcfoo;
-				crc = UPDC32(c, crc);
-				if (crc != 0xDEBB20E3) {
-					zperr(badcrc);
-					return ERROR;
-				}
-				Rxcount = length - (end - buf);
-				vfile("zrdat32: %d %s", Rxcount,
-				 Zendnames[(d-GOTCRCE)&3]);
-				return d;
-			case GOTCAN:
-				zperr("Sender Canceled");
-				return ZCAN;
-			case TIMEOUT:
-				zperr("TIMEOUT");
-				return c;
-			default:
-				zperr("Bad data subpacket");
-				return c;
-			}
-		}
-		*buf++ = c;
-		crc = UPDC32(c, crc);
-	}
-	zperr("Data subpacket too long");
-	return ERROR;
-}
-
-
-/*
- * Read a ZMODEM header to hdr, either binary or hex.
- *  eflag controls local display of non zmodem characters:
- *	0:  no display
- *	1:  display printing characters only
- *	2:  display all non ZMODEM characters
- *  On success, set Zmodem to 1, set Rxpos and return type of header.
- *   Otherwise return negative on error.
- *   Return ERROR instantly if ZCRCW sequence, for fast error recovery.
- */
-int zgethdr(hdr, eflag)
-char *hdr;
-int eflag;
-{
-	register int c, n, cancount;
-
-	n = Zrwindow + Baudrate;	/* Max bytes before start of frame */
-	Rxframeind = Rxtype = 0;
-
-startover:
-	cancount = 5;
-again:
-	/* Return immediate ERROR if ZCRCW sequence seen */
-	switch (c = readline(Rxtimeout)) {
-	case RCDO:
-	case TIMEOUT:
-		goto fifi;
-	case CAN:
-gotcan:
-		if (--cancount <= 0) {
-			c = ZCAN; goto fifi;
-		}
-		switch (c = readline(1)) {
-		case TIMEOUT:
-			goto again;
-		case ZCRCW:
-			c = ERROR;
-		/* **** FALL THRU TO **** */
-		case RCDO:
-			goto fifi;
-		default:
-			break;
-		case CAN:
-			if (--cancount <= 0) {
-				c = ZCAN; goto fifi;
-			}
-			goto again;
-		}
-	/* **** FALL THRU TO **** */
-	default:
-agn2:
-		if ( --n == 0) {
-			zperr("Garbage count exceeded");
-			return(ERROR);
-		}
-		if (eflag && ((c &= 0177) & 0140))
-			bttyout(c);
-		else if (eflag > 1)
-			bttyout(c);
-#ifdef UNIX
-		fflush(stderr);
-#endif
-		goto startover;
-	case ZPAD|0200:		/* This is what we want. */
-		Not8bit = c;
-	case ZPAD:		/* This is what we want. */
-		break;
-	}
-	cancount = 5;
-splat:
-	switch (c = noxrd7()) {
-	case ZPAD:
-		goto splat;
-	case RCDO:
-	case TIMEOUT:
-		goto fifi;
-	default:
-		goto agn2;
-	case ZDLE:		/* This is what we want. */
-		break;
-	}
-
-	switch (c = noxrd7()) {
-	case RCDO:
-	case TIMEOUT:
-		goto fifi;
-	case ZBIN:
-		Rxframeind = ZBIN;  Crc32 = FALSE;
-		c =  zrbhdr(hdr);
-		break;
-	case ZBIN32:
-		Crc32 = Rxframeind = ZBIN32;
-		c =  zrbhdr32(hdr);
-		break;
-	case ZHEX:
-		Rxframeind = ZHEX;  Crc32 = FALSE;
-		c =  zrhhdr(hdr);
-		break;
-	case CAN:
-		goto gotcan;
-	default:
-		goto agn2;
-	}
-	Rxpos = hdr[ZP3] & 0377;
-	Rxpos = (Rxpos<<8) + (hdr[ZP2] & 0377);
-	Rxpos = (Rxpos<<8) + (hdr[ZP1] & 0377);
-	Rxpos = (Rxpos<<8) + (hdr[ZP0] & 0377);
-fifi:
-	switch (c) {
-	case GOTCAN:
-		c = ZCAN;
-	/* **** FALL THRU TO **** */
-	case ZNAK:
-	case ZCAN:
-	case ERROR:
-	case TIMEOUT:
-	case RCDO:
-		zperr("Got %s", frametypes[c+FTOFFSET]);
-	/* **** FALL THRU TO **** */
-	default:
-		if (c >= -3 && c <= FRTYPES)
-			vfile("zgethdr: %s %lx", frametypes[c+FTOFFSET], Rxpos);
-		else
-			vfile("zgethdr: %d %lx", c, Rxpos);
-	}
-	return c;
-}
-
-/* Receive a binary style header (type and position) */
-int zrbhdr(hdr)
-register char *hdr;
-{
-	register int c, n;
-	register unsigned short crc;
-
-	if ((c = zdlread()) & ~0377)
-		return c;
-	Rxtype = c;
-	crc = updcrc(c, 0);
-
-	for (n=4; --n >= 0; ++hdr) {
-		if ((c = zdlread()) & ~0377)
-			return c;
-		crc = updcrc(c, crc);
-		*hdr = c;
-	}
-	if ((c = zdlread()) & ~0377)
-		return c;
-	crc = updcrc(c, crc);
-	if ((c = zdlread()) & ~0377)
-		return c;
-	crc = updcrc(c, crc);
-	if (crc & 0xFFFF) {
-		zperr(badcrc);
-		return ERROR;
-	}
-#ifdef ZMODEM
-	Protocol = ZMODEM;
-#endif
-	Zmodem = 1;
-	return Rxtype;
-}
-
-/* Receive a binary style header (type and position) with 32 bit FCS */
-int zrbhdr32(hdr)
-register char *hdr;
-{
-	register int c, n;
-	register UNSL long crc;
-
-	if ((c = zdlread()) & ~0377)
-		return c;
-	Rxtype = c;
-	crc = 0xFFFFFFFFL; crc = UPDC32(c, crc);
-#ifdef DEBUGZ
-	vfile("zrbhdr32 c=%X  crc=%lX", c, crc);
-#endif
-
-	for (n=4; --n >= 0; ++hdr) {
-		if ((c = zdlread()) & ~0377)
-			return c;
-		crc = UPDC32(c, crc);
-		*hdr = c;
-#ifdef DEBUGZ
-		vfile("zrbhdr32 c=%X  crc=%lX", c, crc);
-#endif
-	}
-	for (n=4; --n >= 0;) {
-		if ((c = zdlread()) & ~0377)
-			return c;
-		crc = UPDC32(c, crc);
-#ifdef DEBUGZ
-		vfile("zrbhdr32 c=%X  crc=%lX", c, crc);
-#endif
-	}
-	if (crc != 0xDEBB20E3) {
-		zperr(badcrc);
-		return ERROR;
-	}
-#ifdef ZMODEM
-	Protocol = ZMODEM;
-#endif
-	Zmodem = 1;
-	return Rxtype;
-}
-
-
-/* Receive a hex style header (type and position) */
-int zrhhdr(hdr)
-char *hdr;
-{
-	register int c;
-	register unsigned short crc;
-	register int n;
-
-	if ((c = zgethex()) < 0)
-		return c;
-	Rxtype = c;
-	crc = updcrc(c, 0);
-
-	for (n=4; --n >= 0; ++hdr) {
-		if ((c = zgethex()) < 0)
-			return c;
-		crc = updcrc(c, crc);
-		*hdr = c;
-	}
-	if ((c = zgethex()) < 0)
-		return c;
-	crc = updcrc(c, crc);
-	if ((c = zgethex()) < 0)
-		return c;
-	crc = updcrc(c, crc);
-	if (crc & 0xFFFF) {
-		zperr(badcrc); return ERROR;
-	}
-	switch ( c = readline(1)) {
-	case 0215:
-		Not8bit = c;
-		/* **** FALL THRU TO **** */
-	case 015:
-	 	/* Throw away possible cr/lf */
-		switch (c = readline(1)) {
-		case 012:
-			Not8bit |= c;
-		}
-	}
-#ifdef ZMODEM
-	Protocol = ZMODEM;
-#endif
-	Zmodem = 1; return Rxtype;
-}
-
-/* Send a byte as two hex digits */
-void zputhex(c)
-register int c;
-{
-	static char	digits[]	= "0123456789abcdef";
-
-	if (Verbose>8)
-		vfile("zputhex: %02X", c);
-	sendline(digits[(c&0xF0)>>4]);
-	sendline(digits[(c)&0xF]);
-}
-
-/*
- * Send character c with ZMODEM escape sequence encoding.
- *  Escape XON, XOFF. Escape CR following @ (Telenet net escape)
- */
-void zsendline(c)
-int c;
-{
-
-	/* Quick check for non control characters */
-	if (c & 0140)
-		xsendline(lastsent = c);
-	else {
-		switch (c &= 0377) {
-		case ZDLE:
-			xsendline(ZDLE);
-			xsendline (lastsent = (c ^= 0100));
-			break;
-		case 015:
-		case 0215:
-			if (!Zctlesc && (lastsent & 0177) != '@')
-				goto sendit;
-		/* **** FALL THRU TO **** */
-		case 020:
-		case 021:
-		case 023:
-		case 0220:
-		case 0221:
-		case 0223:
-			xsendline(ZDLE);
-			c ^= 0100;
-	sendit:
-			xsendline(lastsent = c);
-			break;
-		default:
-			if (Zctlesc && ! (c & 0140)) {
-				xsendline(ZDLE);
-				c ^= 0100;
-			}
-			xsendline(lastsent = c);
-		}
-	}
-}
-
-/* Decode two lower case hex digits into an 8 bit byte value */
-int zgethex()
-{
-	register int c;
-
-	c = zgeth1();
-	if (Verbose>8)
-		vfile("zgethex: %02X", c);
-	return c;
-}
-int zgeth1()
-{
-	register int c, n;
-
-	if ((c = noxrd7()) < 0)
-		return c;
-	n = c - '0';
-	if (n > 9)
-		n -= ('a' - ':');
-	if (n & ~0xF)
-		return ERROR;
-	if ((c = noxrd7()) < 0)
-		return c;
-	c -= '0';
-	if (c > 9)
-		c -= ('a' - ':');
-	if (c & ~0xF)
-		return ERROR;
-	c += (n<<4);
-	return c;
-}
-
-/*
- * Read a byte, checking for ZMODEM escape encoding
- *  including CAN*5 which represents a quick abort
- */
-int zdlread()
-{
-	register int c;
-
-again:
-	/* Quick check for non control characters */
-	if ((c = readline(Rxtimeout)) & 0140)
-		return c;
-	switch (c) {
-	case ZDLE:
-		break;
-	case 023:
-	case 0223:
-	case 021:
-	case 0221:
-		goto again;
-	default:
-		if (Zctlesc && !(c & 0140)) {
-			goto again;
-		}
-		return c;
-	}
-again2:
-	if ((c = readline(Rxtimeout)) < 0)
-		return c;
-	if (c == CAN && (c = readline(Rxtimeout)) < 0)
-		return c;
-	if (c == CAN && (c = readline(Rxtimeout)) < 0)
-		return c;
-	if (c == CAN && (c = readline(Rxtimeout)) < 0)
-		return c;
-	switch (c) {
-	case CAN:
-		return GOTCAN;
-	case ZCRCE:
-	case ZCRCG:
-	case ZCRCQ:
-	case ZCRCW:
-		return (c | GOTOR);
-	case ZRUB0:
-		return 0177;
-	case ZRUB1:
-		return 0377;
-	case 023:
-	case 0223:
-	case 021:
-	case 0221:
-		goto again2;
-	default:
-		if (Zctlesc && ! (c & 0140)) {
-			goto again2;
-		}
-		if ((c & 0140) ==  0100)
-			return (c ^ 0100);
-		break;
-	}
-	if (Verbose>1)
-		zperr("Bad escape sequence %x", c);
-	return ERROR;
-}
-
-/*
- * Read a character from the modem line with timeout.
- *  Eat parity, XON and XOFF characters.
- */
-int noxrd7()
-{
-	register int c;
-
-	for (;;) {
-		if ((c = readline(Rxtimeout)) < 0)
-			return c;
-		switch (c &= 0177) {
-		case XON:
-		case XOFF:
-			continue;
-		default:
-			if (Zctlesc && !(c & 0140))
-				continue;
-		case '\r':
-		case '\n':
-		case ZDLE:
-			return c;
-		}
-	}
-}
-
-/* Store long integer pos in Txhdr */
-void stohdr(pos)
-long pos;
-{
-	Txhdr[ZP0] = pos;
-	Txhdr[ZP1] = pos>>8;
-	Txhdr[ZP2] = pos>>16;
-	Txhdr[ZP3] = pos>>24;
-}
-
-/* Recover a long integer from a header */
-long
-rclhdr(hdr)
-register char *hdr;
-{
-	register long l;
-
-	l = (hdr[ZP3] & 0377);
-	l = (l << 8) | (hdr[ZP2] & 0377);
-	l = (l << 8) | (hdr[ZP1] & 0377);
-	l = (l << 8) | (hdr[ZP0] & 0377);
-	return l;
-}
-
-/* End of zm.c */
Index: trunk/minix/commands/zmodem/zmodem.h
===================================================================
--- trunk/minix/commands/zmodem/zmodem.h	(revision 9)
+++ 	(revision )
@@ -1,161 +1,0 @@
-/*
- *   Z M O D E M . H     Manifest constants for ZMODEM
- *    application to application file transfer protocol
- *    05-23-87  Chuck Forsberg Omen Technology Inc
- */
-#define ZPAD '*'	/* 052 Padding character begins frames */
-#define ZDLE 030	/* Ctrl-X Zmodem escape - `ala BISYNC DLE */
-#define ZDLEE (ZDLE^0100)	/* Escaped ZDLE as transmitted */
-#define ZBIN 'A'	/* Binary frame indicator */
-#define ZHEX 'B'	/* HEX frame indicator */
-#define ZBIN32 'C'	/* Binary frame with 32 bit FCS */
-
-/* Frame types (see array "frametypes" in zm.c) */
-#define ZRQINIT	0	/* Request receive init */
-#define ZRINIT	1	/* Receive init */
-#define ZSINIT 2	/* Send init sequence (optional) */
-#define ZACK 3		/* ACK to above */
-#define ZFILE 4		/* File name from sender */
-#define ZSKIP 5		/* To sender: skip this file */
-#define ZNAK 6		/* Last packet was garbled */
-#define ZABORT 7	/* Abort batch transfers */
-#define ZFIN 8		/* Finish session */
-#define ZRPOS 9		/* Resume data trans at this position */
-#define ZDATA 10	/* Data packet(s) follow */
-#define ZEOF 11		/* End of file */
-#define ZFERR 12	/* Fatal Read or Write error Detected */
-#define ZCRC 13		/* Request for file CRC and response */
-#define ZCHALLENGE 14	/* Receiver's Challenge */
-#define ZCOMPL 15	/* Request is complete */
-#define ZCAN 16		/* Other end canned session with CAN*5 */
-#define ZFREECNT 17	/* Request for free bytes on filesystem */
-#define ZCOMMAND 18	/* Command from sending program */
-#define ZSTDERR 19	/* Output to standard error, data follows */
-
-/* ZDLE sequences */
-#define ZCRCE 'h'	/* CRC next, frame ends, header packet follows */
-#define ZCRCG 'i'	/* CRC next, frame continues nonstop */
-#define ZCRCQ 'j'	/* CRC next, frame continues, ZACK expected */
-#define ZCRCW 'k'	/* CRC next, ZACK expected, end of frame */
-#define ZRUB0 'l'	/* Translate to rubout 0177 */
-#define ZRUB1 'm'	/* Translate to rubout 0377 */
-
-/* zdlread return values (internal) */
-/* -1 is general error, -2 is timeout */
-#define GOTOR 0400
-#define GOTCRCE (ZCRCE|GOTOR)	/* ZDLE-ZCRCE received */
-#define GOTCRCG (ZCRCG|GOTOR)	/* ZDLE-ZCRCG received */
-#define GOTCRCQ (ZCRCQ|GOTOR)	/* ZDLE-ZCRCQ received */
-#define GOTCRCW (ZCRCW|GOTOR)	/* ZDLE-ZCRCW received */
-#define GOTCAN	(GOTOR|030)	/* CAN*5 seen */
-
-/* Byte positions within header array */
-#define ZF0	3	/* First flags byte */
-#define ZF1	2
-#define ZF2	1
-#define ZF3	0
-#define ZP0	0	/* Low order 8 bits of position */
-#define ZP1	1
-#define ZP2	2
-#define ZP3	3	/* High order 8 bits of file position */
-
-/* Bit Masks for ZRINIT flags byte ZF0 */
-#define CANFDX	01	/* Rx can send and receive true FDX */
-#define CANOVIO	02	/* Rx can receive data during disk I/O */
-#define CANBRK	04	/* Rx can send a break signal */
-#define CANCRY	010	/* Receiver can decrypt */
-#define CANLZW	020	/* Receiver can uncompress */
-#define CANFC32	040	/* Receiver can use 32 bit Frame Check */
-#define ESCCTL 0100	/* Receiver expects ctl chars to be escaped */
-#define ESC8   0200	/* Receiver expects 8th bit to be escaped */
-
-/* Parameters for ZSINIT frame */
-#define ZATTNLEN 32	/* Max length of attention string */
-/* Bit Masks for ZSINIT flags byte ZF0 */
-#define TESCCTL 0100	/* Transmitter expects ctl chars to be escaped */
-#define TESC8   0200	/* Transmitter expects 8th bit to be escaped */
-
-/* Parameters for ZFILE frame */
-/* Conversion options one of these in ZF0 */
-#define ZCBIN	1	/* Binary transfer - inhibit conversion */
-#define ZCNL	2	/* Convert NL to local end of line convention */
-#define ZCRESUM	3	/* Resume interrupted file transfer */
-/* Management include options, one of these ored in ZF1 */
-#define ZMSKNOLOC	0200	/* Skip file if not present at rx */
-/* Management options, one of these ored in ZF1 */
-#define ZMMASK	037	/* Mask for the choices below */
-#define ZMNEWL	1	/* Transfer if source newer or longer */
-#define ZMCRC	2	/* Transfer if different file CRC or length */
-#define ZMAPND	3	/* Append contents to existing file (if any) */
-#define ZMCLOB	4	/* Replace existing file */
-#define ZMNEW	5	/* Transfer if source newer */
-	/* Number 5 is alive ... */
-#define ZMDIFF	6	/* Transfer if dates or lengths different */
-#define ZMPROT	7	/* Protect destination file */
-/* Transport options, one of these in ZF2 */
-#define ZTLZW	1	/* Lempel-Ziv compression */
-#define ZTCRYPT	2	/* Encryption */
-#define ZTRLE	3	/* Run Length encoding */
-/* Extended options for ZF3, bit encoded */
-#define ZXSPARS	64	/* Encoding for sparse file operations */
-
-/* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */
-#define ZCACK1	1	/* Acknowledge, then do command */
-
-/* Globals used by ZMODEM functions */
-extern Rxframeind;	/* ZBIN ZBIN32, or ZHEX type of frame received */
-extern Rxtype;		/* Type of header received */
-extern Rxcount;		/* Count of data bytes received */
-extern Zrwindow;	/* RX window size (controls garbage count) */
-extern Rxtimeout;	/* Tenths of seconds to wait for something */
-extern char Rxhdr[4];	/* Received header */
-extern char Txhdr[4];	/* Transmitted header */
-extern long Rxpos;	/* Received file position */
-extern long Txpos;	/* Transmitted file position */
-extern Txfcs32;		/* TURE means send binary frames with 32 bit FCS */
-extern Crc32t;		/* Display flag indicating 32 bit CRC being sent */
-extern Crc32;		/* Display flag indicating 32 bit CRC being received */
-extern Znulls;		/* Number of nulls to send at beginning of ZDATA hdr */
-extern char Attn[ZATTNLEN+1];	/* Attention string rx sends to tx on err */
-
-/* crctab.c */
-
-_PROTOTYPE(long UPDC32 , (int b , long c ));
-
-/* rbsb.c */
-
-_PROTOTYPE(void from_cu , (void));
-_PROTOTYPE(void cucheck , (void));
-_PROTOTYPE(int rdchk , (int f ));
-_PROTOTYPE(int rdchk , (int f ));
-_PROTOTYPE(int mode , (int n ));
-_PROTOTYPE(void sendbrk , (void));
-
-/* zm.c */
-
-_PROTOTYPE(void zsbhdr , (int type , char *hdr ));
-_PROTOTYPE(void zsbh32 , (char *hdr , int type ));
-_PROTOTYPE(void zshhdr , (int type , char *hdr ));
-_PROTOTYPE(void zsdata , (char *buf , int length , int frameend ));
-_PROTOTYPE(void zsda32 , (char *buf , int length , int frameend ));
-_PROTOTYPE(int zrdata , (char *buf , int length ));
-_PROTOTYPE(int zrdat32 , (char *buf , int length ));
-_PROTOTYPE(int zgethdr , (char *hdr , int eflag ));
-_PROTOTYPE(int zrbhdr , (char *hdr ));
-_PROTOTYPE(int zrbhdr32 , (char *hdr ));
-_PROTOTYPE(int zrhhdr , (char *hdr ));
-_PROTOTYPE(void zputhex , (int c ));
-_PROTOTYPE(void zsendline , (int c ));
-_PROTOTYPE(int zgethex , (void));
-_PROTOTYPE(int zgeth1 , (void));
-_PROTOTYPE(int zdlread , (void));
-_PROTOTYPE(int noxrd7 , (void));
-_PROTOTYPE(void stohdr , (long pos ));
-_PROTOTYPE(long rclhdr , (char *hdr ));
-
-/* rz.c sz.c */
-
-void vfile();
-_PROTOTYPE(void bibi , (int n ));
-
-/* End of ZMODEM.H */
